diff --git a/components/bt/CMakeLists.txt b/components/bt/CMakeLists.txt index e1d1fef01c..73f6879039 100644 --- a/components/bt/CMakeLists.txt +++ b/components/bt/CMakeLists.txt @@ -189,6 +189,7 @@ if(CONFIG_BT_ENABLED) "bluedroid/osi/mutex.c" "bluedroid/osi/osi.c" "bluedroid/osi/semaphore.c" + "bluedroid/osi/thread.c" "bluedroid/stack/a2dp/a2d_api.c" "bluedroid/stack/a2dp/a2d_sbc.c" "bluedroid/stack/avct/avct_api.c" diff --git a/components/bt/Kconfig b/components/bt/Kconfig index a15bd7dc2f..d292e66c20 100644 --- a/components/bt/Kconfig +++ b/components/bt/Kconfig @@ -1,6 +1,5 @@ menu Bluetooth - config BT_ENABLED bool "Bluetooth" help @@ -475,9 +474,16 @@ menu Bluetooth help This enables the Secure Simple Pairing. If disable this option, Bluedroid will only support Legacy Pairing + config BT_BLE_ENABLED + bool "Bluetooth Low Energy" + depends on BT_BLUEDROID_ENABLED + default y + help + This enables Bluetooth Low Energy + config BT_GATTS_ENABLE bool "Include GATT server module(GATTS)" - depends on BT_BLUEDROID_ENABLED && (BTDM_CTRL_MODE_BTDM || BTDM_CTRL_MODE_BLE_ONLY) + depends on BT_BLE_ENABLED default y help This option can be disabled when the app work only on gatt client mode @@ -510,21 +516,21 @@ menu Bluetooth config BT_GATTC_ENABLE bool "Include GATT client module(GATTC)" - depends on BT_BLUEDROID_ENABLED && (BTDM_CTRL_MODE_BTDM || BTDM_CTRL_MODE_BLE_ONLY) + depends on BT_BLE_ENABLED default y help This option can be close when the app work only on gatt server mode config BT_GATTC_CACHE_NVS_FLASH bool "Save gattc cache data to nvs flash" - depends on BT_GATTC_ENABLE && (BTDM_CTRL_MODE_BTDM || BTDM_CTRL_MODE_BLE_ONLY) + depends on BT_GATTC_ENABLE default n help This select can save gattc cache data to nvs flash config BT_BLE_SMP_ENABLE bool "Include BLE security module(SMP)" - depends on BT_BLUEDROID_ENABLED && (BTDM_CTRL_MODE_BTDM || BTDM_CTRL_MODE_BLE_ONLY) + depends on BT_BLE_ENABLED default y help This option can be close when the app not used the ble security connect. diff --git a/components/bt/bluedroid/api/esp_bt_main.c b/components/bt/bluedroid/api/esp_bt_main.c index 1620ae9d80..8097956d10 100644 --- a/components/bt/bluedroid/api/esp_bt_main.c +++ b/components/bt/bluedroid/api/esp_bt_main.c @@ -128,10 +128,12 @@ esp_err_t esp_bluedroid_init(void) return ESP_ERR_INVALID_STATE; } -#ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG +#if HEAP_MEMORY_DEBUG osi_mem_dbg_init(); #endif + btc_init(); + future_p = btc_main_get_future_p(BTC_MAIN_INIT_FUTURE); *future_p = future_new(); if (*future_p == NULL) { @@ -139,8 +141,6 @@ esp_err_t esp_bluedroid_init(void) return ESP_ERR_NO_MEM; } - btc_init(); - msg.sig = BTC_SIG_API_CALL; msg.pid = BTC_PID_MAIN_INIT; msg.act = BTC_MAIN_ACT_INIT; diff --git a/components/bt/bluedroid/api/esp_hf_client_api.c b/components/bt/bluedroid/api/esp_hf_client_api.c index fbc5d475cc..7db990206a 100644 --- a/components/bt/bluedroid/api/esp_hf_client_api.c +++ b/components/bt/bluedroid/api/esp_hf_client_api.c @@ -466,6 +466,11 @@ void esp_hf_client_pcm_resample_init(uint32_t src_sps, uint32_t bits, uint32_t c BTA_DmPcmInitSamples(src_sps, bits, channels); } +void esp_hf_client_pcm_resample_deinit(void) +{ + BTA_DmPcmDeinitSamples(); +} + int32_t esp_hf_client_pcm_resample(void *src, uint32_t in_bytes, void *dst) { return BTA_DmPcmResample(src, in_bytes, dst); diff --git a/components/bt/bluedroid/api/esp_spp_api.c b/components/bt/bluedroid/api/esp_spp_api.c index 46878d659e..57c2e317ae 100644 --- a/components/bt/bluedroid/api/esp_spp_api.c +++ b/components/bt/bluedroid/api/esp_spp_api.c @@ -23,9 +23,9 @@ #if (defined BTC_SPP_INCLUDED && BTC_SPP_INCLUDED == TRUE) -static const uint8_t UUID_SPP[16] = {0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x10, 0x00, - 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB - }; +static const uint8_t UUID_SPP[16] = {0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x10, 0x00, + 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB + }; static tSDP_UUID sdp_uuid; esp_err_t esp_spp_register_callback(esp_spp_cb_t *callback) { diff --git a/components/bt/bluedroid/api/include/api/esp_hf_client_api.h b/components/bt/bluedroid/api/include/api/esp_hf_client_api.h index dfc06ed5d1..8e3dc956b7 100644 --- a/components/bt/bluedroid/api/include/api/esp_hf_client_api.h +++ b/components/bt/bluedroid/api/include/api/esp_hf_client_api.h @@ -615,6 +615,11 @@ void esp_hf_client_outgoing_data_ready(void); */ void esp_hf_client_pcm_resample_init(uint32_t src_sps, uint32_t bits, uint32_t channels); +/** + * @brief Deinitialize the down sampling converter. + */ +void esp_hf_client_pcm_resample_deinit(void); + /** * @brief Down sampling utility to convert high sampling rate into 8K/16bits 1-channel mode PCM * samples. This can only be used in the case that Voice Over HCI is enabled. diff --git a/components/bt/bluedroid/bta/av/bta_av_sbc.c b/components/bt/bluedroid/bta/av/bta_av_sbc.c index 30f178efb3..4e034c4246 100644 --- a/components/bt/bluedroid/bta/av/bta_av_sbc.c +++ b/components/bt/bluedroid/bta/av/bta_av_sbc.c @@ -31,24 +31,13 @@ #include "common/bt_defs.h" #if defined(BTA_AV_INCLUDED) && (BTA_AV_INCLUDED == TRUE) +#include "bta_av_int.h" -typedef int (tBTA_AV_SBC_ACT)(void *p_src, void *p_dst, - UINT32 src_samples, UINT32 dst_samples, - UINT32 *p_ret); - -typedef struct { - INT32 cur_pos; /* current position */ - UINT32 src_sps; /* samples per second (source audio data) */ - UINT32 dst_sps; /* samples per second (converted audio data) */ - tBTA_AV_SBC_ACT *p_act; /* the action function to do the conversion */ - UINT16 bits; /* number of bits per pcm sample */ - UINT16 n_channels; /* number of channels (i.e. mono(1), stereo(2)...) */ - INT16 worker1; - INT16 worker2; - UINT8 div; -} tBTA_AV_SBC_UPS_CB; - -tBTA_AV_SBC_UPS_CB bta_av_sbc_ups_cb; +#if BTA_DYNAMIC_MEMORY == FALSE +static tBTA_AV_SBC_UPS_CB bta_av_sbc_ups_cb; +#else +tBTA_AV_SBC_UPS_CB *bta_av_sbc_ups_cb_ptr; +#endif /******************************************************************************* ** diff --git a/components/bt/bluedroid/bta/av/include/bta_av_int.h b/components/bt/bluedroid/bta/av/include/bta_av_int.h index 16a70f3ef3..9fb6c06c52 100644 --- a/components/bt/bluedroid/bta/av/include/bta_av_int.h +++ b/components/bt/bluedroid/bta/av/include/bta_av_int.h @@ -531,11 +531,32 @@ typedef struct { UINT8 video_streams; /* handle mask of streaming video channels */ } tBTA_AV_CB; +/* type for dealing with SBC data frames and codec capabilities functions */ +typedef int (tBTA_AV_SBC_ACT)(void *p_src, void *p_dst, + UINT32 src_samples, UINT32 dst_samples, + UINT32 *p_ret); +/* type for AV up sample control block */ +typedef struct { + INT32 cur_pos; /* current position */ + UINT32 src_sps; /* samples per second (source audio data) */ + UINT32 dst_sps; /* samples per second (converted audio data) */ + tBTA_AV_SBC_ACT *p_act; /* the action function to do the conversion */ + UINT16 bits; /* number of bits per pcm sample */ + UINT16 n_channels; /* number of channels (i.e. mono(1), stereo(2)...) */ + INT16 worker1; + INT16 worker2; + UINT8 div; +} tBTA_AV_SBC_UPS_CB; /***************************************************************************** ** Global data *****************************************************************************/ +/* control block declaration up sample */ +#if BTA_DYNAMIC_MEMORY == TRUE +extern tBTA_AV_SBC_UPS_CB *bta_av_sbc_ups_cb_ptr; +#define bta_av_sbc_ups_cb (*bta_av_sbc_ups_cb_ptr) +#endif /* control block declaration */ #if BTA_DYNAMIC_MEMORY == FALSE @@ -670,3 +691,4 @@ extern void bta_av_reg_vdp (tAVDT_CS *p_cs, char *p_service_name, void *p_data); #endif ///BTA_AV_INCLUDED == TRUE #endif /* BTA_AV_INT_H */ + diff --git a/components/bt/bluedroid/bta/dm/bta_dm_act.c b/components/bt/bluedroid/bta/dm/bta_dm_act.c index 49cce8749a..acb6f6291f 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_act.c @@ -60,7 +60,9 @@ static void bta_dm_sdp_callback (UINT16 sdp_status); #endif ///SDP_INCLUDED == TRUE #if (SMP_INCLUDED == TRUE) static UINT8 bta_dm_authorize_cback (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name, UINT8 *service_name, UINT8 service_id, BOOLEAN is_originator); +#if (CLASSIC_BT_INCLUDED == TRUE) static UINT8 bta_dm_pin_cback (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name, BOOLEAN min_16_digit); +#endif /// CLASSIC_BT_INCLUDED == TRUE static UINT8 bta_dm_new_link_key_cback(BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name, LINK_KEY key, UINT8 key_type); static UINT8 bta_dm_authentication_complete_cback(BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name, int result); #endif ///SMP_INCLUDED == TRUE @@ -125,9 +127,12 @@ static void bta_dm_ctrl_features_rd_cmpl_cback(tBTM_STATUS result); #if (SMP_INCLUDED == TRUE) static void bta_dm_remove_sec_dev_entry(BD_ADDR remote_bd_addr); #endif ///SMP_INCLUDED == TRUE +#if (BLE_INCLUDED == TRUE) static void bta_dm_observe_results_cb(tBTM_INQ_RESULTS *p_inq, UINT8 *p_eir); static void bta_dm_observe_cmpl_cb(void *p_result); static void bta_dm_observe_discard_cb (uint32_t num_dis); +#endif ///BLE_INCLUDED == TRUE + static void bta_dm_delay_role_switch_cback(TIMER_LIST_ENT *p_tle); extern void sdpu_uuid16_to_uuid128(UINT16 uuid16, UINT8 *p_uuid128); static void bta_dm_disable_timer_cback(TIMER_LIST_ENT *p_tle); @@ -215,7 +220,11 @@ const UINT32 bta_service_id_to_btm_srv_id_lkup_tbl [BTA_MAX_SERVICE_ID] = { #if (SMP_INCLUDED == TRUE) const tBTM_APPL_INFO bta_security = { &bta_dm_authorize_cback, +#if (CLASSIC_BT_INCLUDED == TRUE) &bta_dm_pin_cback, +#else + NULL, +#endif &bta_dm_new_link_key_cback, &bta_dm_authentication_complete_cback, &bta_dm_bond_cancel_complete_cback, @@ -233,10 +242,12 @@ const tBTM_APPL_INFO bta_security = { #endif ///SMP_INCLUDED == TRUE #if (SDP_INCLUDED == TRUE) -#define MAX_DISC_RAW_DATA_BUF (1024) +#if BTA_DYNAMIC_MEMORY == FALSE UINT8 g_disc_raw_data_buf[MAX_DISC_RAW_DATA_BUF]; +#else +UINT8 *g_disc_raw_data_buf; +#endif #endif ///SDP_INCLUDED == TRUE -extern DEV_CLASS local_device_default_class; /******************************************************************************* ** @@ -579,7 +590,7 @@ void bta_dm_disable (tBTA_DM_MSG *p_data) bta_sys_start_timer(&bta_dm_cb.disable_timer, 0, 5000); } -#if BLE_PRIVACY_SPT == TRUE +#if BLE_INCLUDED == TRUE && BLE_PRIVACY_SPT == TRUE btm_ble_resolving_list_cleanup (); //by TH, because cmn_ble_vsc_cb.max_filter has something mistake as btm_ble_adv_filter_cleanup #endif @@ -696,25 +707,31 @@ void bta_dm_config_eir (tBTA_DM_MSG *p_data) void bta_dm_update_white_list(tBTA_DM_MSG *p_data) { +#if (BLE_INCLUDED == TRUE) BTM_BleUpdateAdvWhitelist(p_data->white_list.add_remove, p_data->white_list.remote_addr, p_data->white_list.addr_type, p_data->white_list.add_wl_cb); +#endif ///BLE_INCLUDED == TRUE } void bta_dm_ble_read_adv_tx_power(tBTA_DM_MSG *p_data) { +#if (BLE_INCLUDED == TRUE) if (p_data->read_tx_power.read_tx_power_cb != NULL) { BTM_BleReadAdvTxPower(p_data->read_tx_power.read_tx_power_cb); } else { APPL_TRACE_ERROR("%s(), the callback function can't be NULL.", __func__); } +#endif ///BLE_INCLUDED == TRUE } void bta_dm_ble_read_rssi(tBTA_DM_MSG *p_data) { +#if (BLE_INCLUDED == TRUE) if (p_data->rssi.read_rssi_cb != NULL) { BTM_ReadRSSI(p_data->rssi.remote_addr, p_data->rssi.transport, p_data->rssi.read_rssi_cb); } else { APPL_TRACE_ERROR("%s(), the callback function can't be NULL.", __func__); } +#endif ///BLE_INCLUDED == TRUE } /******************************************************************************* @@ -730,42 +747,52 @@ void bta_dm_ble_read_rssi(tBTA_DM_MSG *p_data) void bta_dm_set_visibility(tBTA_DM_MSG *p_data) { UINT16 window, interval; - UINT16 le_disc_mode = BTM_BleReadDiscoverability(); UINT16 disc_mode = BTM_ReadDiscoverability(&window, &interval); - UINT16 le_conn_mode = BTM_BleReadConnectability(); UINT16 conn_mode = BTM_ReadConnectability(&window, &interval); +#if (BLE_INCLUDED == TRUE) + UINT16 le_disc_mode = BTM_BleReadDiscoverability(); + UINT16 le_conn_mode = BTM_BleReadConnectability(); +#endif ///BLE_INCLUDED == TRUE /* set modes for Discoverability and connectability if not ignore */ if (p_data->set_visibility.disc_mode != (BTA_DM_IGNORE | BTA_DM_LE_IGNORE)) { +#if (BLE_INCLUDED == TRUE) if ((p_data->set_visibility.disc_mode & BTA_DM_LE_IGNORE) == BTA_DM_LE_IGNORE) { p_data->set_visibility.disc_mode = ((p_data->set_visibility.disc_mode & ~BTA_DM_LE_IGNORE) | le_disc_mode); } +#endif ///BLE_INCLUDED == TRUE if ((p_data->set_visibility.disc_mode & BTA_DM_IGNORE) == BTA_DM_IGNORE) { p_data->set_visibility.disc_mode = ((p_data->set_visibility.disc_mode & ~BTA_DM_IGNORE) | disc_mode); } +#if (CLASSIC_BT_INCLUDED == TRUE) BTM_SetDiscoverability(p_data->set_visibility.disc_mode, bta_dm_cb.inquiry_scan_window, bta_dm_cb.inquiry_scan_interval); +#endif } if (p_data->set_visibility.conn_mode != (BTA_DM_IGNORE | BTA_DM_LE_IGNORE)) { +#if (BLE_INCLUDED == TRUE) if ((p_data->set_visibility.conn_mode & BTA_DM_LE_IGNORE) == BTA_DM_LE_IGNORE) { p_data->set_visibility.conn_mode = ((p_data->set_visibility.conn_mode & ~BTA_DM_LE_IGNORE) | le_conn_mode); } +#endif ///BLE_INCLUDED == TRUE if ((p_data->set_visibility.conn_mode & BTA_DM_IGNORE) == BTA_DM_IGNORE) { p_data->set_visibility.conn_mode = ((p_data->set_visibility.conn_mode & ~BTA_DM_IGNORE) | conn_mode); } +#if (CLASSIC_BT_INCLUDED == TRUE) BTM_SetConnectability(p_data->set_visibility.conn_mode, bta_dm_cb.page_scan_window, bta_dm_cb.page_scan_interval); +#endif } /* Send False or True if not ignore */ @@ -1094,7 +1121,9 @@ void bta_dm_bond_cancel (tBTA_DM_MSG *p_data) *******************************************************************************/ void bta_dm_set_pin_type (tBTA_DM_MSG *p_data) { +#if (CLASSIC_BT_INCLUDED == TRUE) BTM_SetPinType (p_data->set_pin_type.pin_type, p_data->set_pin_type.p_pin, p_data->set_pin_type.pin_len); +#endif ///CLASSIC_BT_INCLUDED == TRUE } /******************************************************************************* @@ -1109,6 +1138,7 @@ void bta_dm_set_pin_type (tBTA_DM_MSG *p_data) *******************************************************************************/ void bta_dm_pin_reply (tBTA_DM_MSG *p_data) { +#if (CLASSIC_BT_INCLUDED == TRUE) UINT32 trusted_mask[BTM_SEC_SERVICE_ARRAY_SIZE]; UINT32 *current_trusted_mask; @@ -1126,7 +1156,7 @@ void bta_dm_pin_reply (tBTA_DM_MSG *p_data) } else { BTM_PINCodeReply(p_data->pin_reply.bd_addr, BTM_NOT_AUTHORIZED, 0, NULL, trusted_mask ); } - +#endif ///CLASSIC_BT_INCLUDED == TRUE } #endif ///SMP_INCLUDED == TRUE @@ -1268,7 +1298,9 @@ void bta_dm_loc_oob(tBTA_DM_MSG *p_data) *******************************************************************************/ void bta_dm_oob_reply(tBTA_DM_MSG *p_data) { +#if (BLE_INCLUDED) BTM_BleOobDataReply(p_data->oob_reply.bd_addr, BTM_SUCCESS, p_data->oob_reply.len, p_data->oob_reply.value); +#endif } /******************************************************************************* @@ -2303,7 +2335,7 @@ static void bta_dm_find_services ( BD_ADDR bd_addr) APPL_TRACE_DEBUG("%s search UUID = %04x", __func__, uuid.uu.uuid16); SDP_InitDiscoveryDb (bta_dm_search_cb.p_sdp_db, BTA_DM_SDP_DB_SIZE, 1, &uuid, 0, NULL); - memset(g_disc_raw_data_buf, 0, sizeof(g_disc_raw_data_buf)); + memset(g_disc_raw_data_buf, 0, MAX_DISC_RAW_DATA_BUF); bta_dm_search_cb.p_sdp_db->raw_data = g_disc_raw_data_buf; bta_dm_search_cb.p_sdp_db->raw_size = MAX_DISC_RAW_DATA_BUF; @@ -2496,7 +2528,7 @@ static void bta_dm_discover_device(BD_ADDR remote_bd_addr) if (transport == BT_TRANSPORT_LE) { if (bta_dm_search_cb.services_to_search & BTA_BLE_SERVICE_MASK) { //set the raw data buffer here - memset(g_disc_raw_data_buf, 0, sizeof(g_disc_raw_data_buf)); + memset(g_disc_raw_data_buf, 0, MAX_DISC_RAW_DATA_BUF); bta_dm_search_cb.p_ble_rawdata = g_disc_raw_data_buf; bta_dm_search_cb.ble_raw_size = MAX_DISC_RAW_DATA_BUF; @@ -2790,6 +2822,8 @@ static UINT8 bta_dm_authorize_cback (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NA } } + +#if (CLASSIC_BT_INCLUDED == TRUE) #if (BT_SSP_INCLUDED == TRUE) /******************************************************************************* ** @@ -2876,6 +2910,7 @@ static UINT8 bta_dm_pin_cback (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_ bta_dm_cb.p_sec_cback(BTA_DM_PIN_REQ_EVT, &sec_event); return BTM_CMD_STARTED; } +#endif ///CLASSIC_BT_INCLUDED == TRUE /******************************************************************************* ** @@ -5795,6 +5830,7 @@ static void bta_dm_gattc_register(void) } } #endif /* GATTC_INCLUDED == TRUE */ + /******************************************************************************* ** ** Function btm_dm_start_disc_gatt_services @@ -5804,6 +5840,7 @@ static void bta_dm_gattc_register(void) ** Parameters: ** *******************************************************************************/ +#if (GATTC_INCLUDED == TRUE) static void btm_dm_start_disc_gatt_services (UINT16 conn_id) { tBT_UUID *p_uuid = bta_dm_search_cb.p_srvc_uuid + @@ -5815,6 +5852,7 @@ static void btm_dm_start_disc_gatt_services (UINT16 conn_id) /* always search for all services */ BTA_GATTC_ServiceSearchRequest(conn_id, p_uuid); } +#endif /* GATTC_INCLUDED == TRUE */ /******************************************************************************* ** @@ -5875,6 +5913,7 @@ static void bta_dm_gatt_disc_result(tBTA_GATT_ID service_id) ** Parameters: ** *******************************************************************************/ +#if (GATTC_INCLUDED == TRUE) static void bta_dm_gatt_disc_complete(UINT16 conn_id, tBTA_GATT_STATUS status) { tBTA_DM_MSG *p_msg; @@ -5932,6 +5971,7 @@ static void bta_dm_gatt_disc_complete(UINT16 conn_id, tBTA_GATT_STATUS status) bta_dm_search_cb.gatt_disc_active = FALSE; } } +#endif /* #if (GATTC_INCLUDED == TRUE) */ /******************************************************************************* ** @@ -6001,6 +6041,7 @@ static void bta_dm_cancel_gatt_discovery(BD_ADDR bd_addr) bta_dm_gatt_disc_complete(bta_dm_search_cb.conn_id, (tBTA_GATT_STATUS) BTA_GATT_ERROR); } #endif /* #if (GATTC_INCLUDED == TRUE) */ + /******************************************************************************* ** ** Function bta_dm_proc_open_evt @@ -6010,6 +6051,7 @@ static void bta_dm_cancel_gatt_discovery(BD_ADDR bd_addr) ** Parameters: ** *******************************************************************************/ +#if (GATTC_INCLUDED == TRUE) void bta_dm_proc_open_evt(tBTA_GATTC_OPEN *p_data) { UINT8 *p1; @@ -6040,6 +6082,7 @@ void bta_dm_proc_open_evt(tBTA_GATTC_OPEN *p_data) bta_dm_gatt_disc_complete(BTA_GATT_INVALID_CONN_ID, p_data->status); } } +#endif /* #if (GATTC_INCLUDED == TRUE) */ /******************************************************************************* ** diff --git a/components/bt/bluedroid/bta/dm/bta_dm_api.c b/components/bt/bluedroid/bta/dm/bta_dm_api.c index 927257733f..141d9ce2dd 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_api.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_api.c @@ -225,6 +225,7 @@ void BTA_DmConfigEir(tBTA_DM_EIR_CONF *eir_config) } } +#if (BLE_INCLUDED == TRUE) void BTA_DmUpdateWhiteList(BOOLEAN add_remove, BD_ADDR remote_addr, tBLE_ADDR_TYPE addr_type, tBTA_ADD_WHITELIST_CBACK *add_wl_cb) { tBTA_DM_API_UPDATE_WHITE_LIST *p_msg; @@ -248,6 +249,7 @@ void BTA_DmBleReadAdvTxPower(tBTA_CMPL_CB *cmpl_cb) bta_sys_sendmsg(p_msg); } } +#endif ///BLE_INCLUDED == TRUE void BTA_DmBleReadRSSI(BD_ADDR remote_addr, tBTA_TRANSPORT transport, tBTA_CMPL_CB *cmpl_cb) { @@ -475,10 +477,10 @@ void BTA_DmBondCancel(BD_ADDR bd_addr) bdcpy(p_msg->bd_addr, bd_addr); bta_sys_sendmsg(p_msg); } - - } +#endif ///SMP_INCLUDED == TRUE +#if (CLASSIC_BT_INCLUDED == TRUE) /******************************************************************************* ** ** Function BTA_DMSetPinType @@ -529,6 +531,7 @@ void BTA_DmPinReply(BD_ADDR bd_addr, BOOLEAN accept, UINT8 pin_len, UINT8 *p_pin } } +#endif ///CLASSIC_BT_INCLUDED == TRUE #if (BTM_OOB_INCLUDED == TRUE && SMP_INCLUDED == TRUE) /******************************************************************************* @@ -594,6 +597,7 @@ void BTA_DmOobReply(BD_ADDR bd_addr, UINT8 len, UINT8 *p_value) ** Returns void ** *******************************************************************************/ +#if (SMP_INCLUDED == TRUE) void BTA_DmConfirm(BD_ADDR bd_addr, BOOLEAN accept) { tBTA_DM_API_CONFIRM *p_msg; @@ -629,6 +633,7 @@ void BTA_DmPasskeyReqReply(BOOLEAN accept, BD_ADDR bd_addr, UINT32 passkey) } } #endif ///BT_SSP_INCLUDED == TRUE +#endif ///SMP_INCLUDED == TRUE /******************************************************************************* ** ** Function BTA_DmAddDevice @@ -705,7 +710,7 @@ tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr, tBT_TRANSPORT transport) return BTA_SUCCESS; } -#endif ///SMP_INCLUDED == TRUE +// #endif ///SMP_INCLUDED == TRUE /******************************************************************************* ** @@ -989,7 +994,6 @@ void BTA_DmBleSecurityGrant(BD_ADDR bd_addr, tBTA_DM_BLE_SEC_GRANT res) } } #endif ///SMP_INCLUDED == TRUE -#endif ///BLE_INCLUDED == TRUE /******************************************************************************* @@ -1207,7 +1211,7 @@ void BTA_DmSetBleAdvParamsAll (UINT16 adv_int_min, UINT16 adv_int_max, } #endif } - +#endif ///BLE_INCLUDED == TRUE /******************************************************************************* @@ -1796,6 +1800,8 @@ void BTA_DmBleUpdateConnectionParam(BD_ADDR bd_addr, UINT16 min_int, } #endif } + +#if BLE_INCLUDED == TRUE /******************************************************************************* ** ** Function BTA_DmBleConfigLocalPrivacy @@ -1826,7 +1832,6 @@ void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable, tBTA_SET_LOCAL_PRIVACY_ #endif } -#if BLE_INCLUDED == TRUE /******************************************************************************* ** ** Function BTA_DmBleConfigLocalIcon diff --git a/components/bt/bluedroid/bta/dm/bta_dm_cfg.c b/components/bt/bluedroid/bta/dm/bta_dm_cfg.c index 14462e4409..6769e7141e 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_cfg.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_cfg.c @@ -112,9 +112,9 @@ const tBTA_DM_RM bta_dm_rm_cfg[] = { }; -tBTA_DM_CFG *p_bta_dm_cfg = (tBTA_DM_CFG *) &bta_dm_cfg; +tBTA_DM_CFG *const p_bta_dm_cfg = (tBTA_DM_CFG *) &bta_dm_cfg; -tBTA_DM_RM *p_bta_dm_rm_cfg = (tBTA_DM_RM *) &bta_dm_rm_cfg; +tBTA_DM_RM *const p_bta_dm_rm_cfg = (tBTA_DM_RM *) &bta_dm_rm_cfg; #if BLE_INCLUDED == TRUE # define BTA_DM_NUM_PM_ENTRY 8 /* number of entries in bta_dm_pm_cfg except the first */ @@ -375,12 +375,12 @@ tBTA_DM_SSR_SPEC bta_dm_ssr_spec[] = { {360, 160, 2} /* BTA_DM_PM_SSR3 - HD */ }; -tBTA_DM_SSR_SPEC *p_bta_dm_ssr_spec = (tBTA_DM_SSR_SPEC *) &bta_dm_ssr_spec; +tBTA_DM_SSR_SPEC *const p_bta_dm_ssr_spec = (tBTA_DM_SSR_SPEC *) &bta_dm_ssr_spec; #endif -tBTA_DM_PM_CFG *p_bta_dm_pm_cfg = (tBTA_DM_PM_CFG *) &bta_dm_pm_cfg; -tBTA_DM_PM_SPEC *p_bta_dm_pm_spec = (tBTA_DM_PM_SPEC *) &bta_dm_pm_spec; -tBTM_PM_PWR_MD *p_bta_dm_pm_md = (tBTM_PM_PWR_MD *) &bta_dm_pm_md; +tBTA_DM_PM_CFG *const p_bta_dm_pm_cfg = (tBTA_DM_PM_CFG *) &bta_dm_pm_cfg; +tBTA_DM_PM_SPEC *const p_bta_dm_pm_spec = (tBTA_DM_PM_SPEC *) &bta_dm_pm_spec; +tBTM_PM_PWR_MD *const p_bta_dm_pm_md = (tBTM_PM_PWR_MD *) &bta_dm_pm_md; #endif /* #if (BTA_DM_PM_INCLUDED == TRUE) */ diff --git a/components/bt/bluedroid/bta/dm/bta_dm_main.c b/components/bt/bluedroid/bta/dm/bta_dm_main.c index 3b9a7cc4ce..d62974ea2e 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_main.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_main.c @@ -160,7 +160,9 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = { bta_dm_update_white_list, /* BTA_DM_API_UPDATE_WHITE_LIST_EVT */ bta_dm_ble_read_adv_tx_power, /* BTA_DM_API_BLE_READ_ADV_TX_POWER_EVT */ bta_dm_ble_read_rssi, /* BTA_DM_API_BLE_READ_RSSI_EVT */ +#if BLE_INCLUDED == TRUE bta_dm_ble_update_duplicate_exceptional_list,/* BTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_EVT */ +#endif }; diff --git a/components/bt/bluedroid/bta/dm/bta_dm_pm.c b/components/bt/bluedroid/bta/dm/bta_dm_pm.c index cf55b1c341..5b0978bf59 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_pm.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_pm.c @@ -32,7 +32,11 @@ #include "stack/btm_api.h" #include "osi/allocator.h" -tBTA_DM_CONNECTED_SRVCS bta_dm_conn_srvcs; +#if BTA_DYNAMIC_MEMORY == FALSE +tBTA_DM_CONNECTED_SRVCS bta_dm_conn_srvcs; +#else +tBTA_DM_CONNECTED_SRVCS *bta_dm_conn_srvcs_ptr; +#endif #if (BTA_DM_PM_INCLUDED == TRUE) static void bta_dm_pm_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id, BD_ADDR peer_addr); diff --git a/components/bt/bluedroid/bta/dm/bta_dm_sco.c b/components/bt/bluedroid/bta/dm/bta_dm_sco.c index 9acfa9544a..df91799a87 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_sco.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_sco.c @@ -28,6 +28,7 @@ #include #include "bta/bta_api.h" #include "bta/bta_sys.h" +#include "osi/allocator.h" #if (BTM_SCO_HCI_INCLUDED == TRUE) @@ -67,7 +68,7 @@ typedef struct { UINT32 divisor; } tBTA_DM_PCM_RESAMPLE_CB; -tBTA_DM_PCM_RESAMPLE_CB bta_dm_pcm_cb; +static tBTA_DM_PCM_RESAMPLE_CB* p_bta_dm_pcm_cb; /***************************************************************************** ** Macro Definition @@ -560,7 +561,11 @@ INT32 Convert_16S_ToBT_NoFilter (void *pSrc, void *pDst, UINT32 dwSrcSamples, UI *******************************************************************************/ void BTA_DmPcmInitSamples (UINT32 src_sps, UINT32 bits, UINT32 n_channels) { - tBTA_DM_PCM_RESAMPLE_CB *p_cb = &bta_dm_pcm_cb; + if ((p_bta_dm_pcm_cb = (tBTA_DM_PCM_RESAMPLE_CB *)osi_malloc(sizeof(tBTA_DM_PCM_RESAMPLE_CB))) == NULL) { + APPL_TRACE_ERROR("%s malloc failed!", __func__); + return; + } + tBTA_DM_PCM_RESAMPLE_CB *p_cb = p_bta_dm_pcm_cb; p_cb->cur_pos = src_sps / 2; p_cb->src_sps = src_sps; @@ -615,6 +620,20 @@ void BTA_DmPcmInitSamples (UINT32 src_sps, UINT32 bits, UINT32 n_channels) } +/******************************************************************************* +** +** Function BTA_DmPcmDeinitSamples +** +** Description Deinitialize the down sample converter. +** +** Returns none +** +*******************************************************************************/ +void BTA_DmPcmDeinitSamples(void) { + osi_free(p_bta_dm_pcm_cb); + p_bta_dm_pcm_cb = NULL; +} + /************************************************************************************** ** Function BTA_DmPcmResample ** @@ -636,14 +655,14 @@ INT32 BTA_DmPcmResample (void *p_src, UINT32 in_bytes, void *p_dst) UINT32 out_sample; #if BTA_DM_SCO_DEBUG - APPL_TRACE_DEBUG("bta_pcm_resample : insamples %d", (in_bytes / bta_dm_pcm_cb.divisor)); + APPL_TRACE_DEBUG("bta_pcm_resample : insamples %d", (in_bytes / p_bta_dm_pcm_cb->divisor)); #endif - if (bta_dm_pcm_cb.can_be_filtered) { - out_sample = (*bta_dm_pcm_cb.filter) (p_src, p_dst, (in_bytes / bta_dm_pcm_cb.divisor), - bta_dm_pcm_cb.src_sps, (INT32 *) &bta_dm_pcm_cb.cur_pos, bta_dm_pcm_cb.overlap_area); + if (p_bta_dm_pcm_cb->can_be_filtered) { + out_sample = (*p_bta_dm_pcm_cb->filter) (p_src, p_dst, (in_bytes / p_bta_dm_pcm_cb->divisor), + p_bta_dm_pcm_cb->src_sps, (INT32 *) &(p_bta_dm_pcm_cb->cur_pos), p_bta_dm_pcm_cb->overlap_area); } else { - out_sample = (*bta_dm_pcm_cb.nofilter) (p_src, p_dst, - (in_bytes / bta_dm_pcm_cb.divisor), bta_dm_pcm_cb.src_sps); + out_sample = (*p_bta_dm_pcm_cb->nofilter) (p_src, p_dst, + (in_bytes / p_bta_dm_pcm_cb->divisor), p_bta_dm_pcm_cb->src_sps); } #if BTA_DM_SCO_DEBUG diff --git a/components/bt/bluedroid/bta/dm/include/bta_dm_int.h b/components/bt/bluedroid/bta/dm/include/bta_dm_int.h index 2c21b0c574..c87708e358 100644 --- a/components/bt/bluedroid/bta/dm/include/bta_dm_int.h +++ b/components/bt/bluedroid/bta/dm/include/bta_dm_int.h @@ -157,7 +157,9 @@ enum { BTA_DM_API_UPDATE_WHITE_LIST_EVT, BTA_DM_API_BLE_READ_ADV_TX_POWER_EVT, BTA_DM_API_BLE_READ_RSSI_EVT, +#if BLE_INCLUDED == TRUE BTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_EVT, +#endif BTA_DM_MAX_EVT }; @@ -203,6 +205,7 @@ typedef struct { UINT8 data[]; }tBTA_DM_API_CONFIG_EIR; +#if (BLE_INCLUDED == TRUE) typedef struct { BT_HDR hdr; BOOLEAN add_remove; @@ -223,6 +226,7 @@ typedef struct { BT_HDR hdr; tBTA_CMPL_CB *read_tx_power_cb; }tBTA_DM_API_READ_ADV_TX_POWER; +#endif ///BLE_INCLUDED == TRUE typedef struct { BT_HDR hdr; @@ -402,8 +406,8 @@ typedef struct { UINT8 hci_status; #if BLE_INCLUDED == TRUE UINT16 handle; - tBT_TRANSPORT transport; #endif + tBT_TRANSPORT transport; } tBTA_DM_ACL_CHANGE; #if (BTA_DM_PM_INCLUDED == TRUE) @@ -801,9 +805,12 @@ typedef union { tBTA_DM_API_SET_NAME set_name; tBTA_DM_API_CONFIG_EIR config_eir; +#if (BLE_INCLUDED == TRUE) tBTA_DM_API_UPDATE_WHITE_LIST white_list; tBTA_DM_API_READ_ADV_TX_POWER read_tx_power; tBTA_DM_API_READ_RSSI rssi; +#endif ///BLE_INCLUDED == TRUE + tBTA_DM_API_SET_VISIBILITY set_visibility; tBTA_DM_API_ADD_DEVICE add_dev; @@ -939,8 +946,8 @@ typedef struct { BOOLEAN remove_dev_pending; #if BLE_INCLUDED == TRUE UINT16 conn_handle; - tBT_TRANSPORT transport; #endif + tBT_TRANSPORT transport; } tBTA_DM_PEER_DEVICE; @@ -976,7 +983,6 @@ typedef struct { } tBTA_DM_CONNECTED_SRVCS; -extern tBTA_DM_CONNECTED_SRVCS bta_dm_conn_srvcs; #if (BTA_DM_PM_INCLUDED == TRUE) @@ -1032,6 +1038,8 @@ typedef struct { BOOLEAN disable_pair_mode; /* disable pair mode or not */ BOOLEAN conn_paired_only; /* allow connectable to paired device only or not */ tBTA_DM_API_SEARCH search_msg; + +#if (CLASSIC_BT_INCLUDED == TRUE) UINT16 page_scan_interval; UINT16 page_scan_window; UINT16 inquiry_scan_interval; @@ -1041,8 +1049,10 @@ typedef struct { BD_ADDR pin_bd_addr; DEV_CLASS pin_dev_class; tBTA_DM_SEC_EVT pin_evt; - UINT32 num_val; /* the numeric value for comparison. If just_works, do not show this number to UI */ - BOOLEAN just_works; /* TRUE, if "Just Works" association model */ + UINT32 num_val; /* the numeric value for comparison. If just_works, do not show this number to UI */ + BOOLEAN just_works; /* TRUE, if "Just Works" association model */ +#endif + #if ( BTA_EIR_CANNED_UUID_LIST != TRUE ) /* store UUID list for EIR */ TIMER_LIST_ENT app_ready_timer; @@ -1150,8 +1160,8 @@ typedef struct { } tBTA_DM_RM ; -extern tBTA_DM_CFG *p_bta_dm_cfg; -extern tBTA_DM_RM *p_bta_dm_rm_cfg; +extern tBTA_DM_CFG *const p_bta_dm_cfg; +extern tBTA_DM_RM *const p_bta_dm_rm_cfg; typedef struct { @@ -1192,11 +1202,11 @@ typedef struct { } tBTA_DM_LMP_VER_INFO; #if (BTA_DM_PM_INCLUDED == TRUE) -extern tBTA_DM_PM_CFG *p_bta_dm_pm_cfg; -extern tBTA_DM_PM_SPEC *p_bta_dm_pm_spec; -extern tBTM_PM_PWR_MD *p_bta_dm_pm_md; +extern tBTA_DM_PM_CFG *const p_bta_dm_pm_cfg; +extern tBTA_DM_PM_SPEC *const p_bta_dm_pm_spec; +extern tBTM_PM_PWR_MD *const p_bta_dm_pm_md; #if (BTM_SSR_INCLUDED == TRUE) -extern tBTA_DM_SSR_SPEC *p_bta_dm_ssr_spec; +extern tBTA_DM_SSR_SPEC *const p_bta_dm_ssr_spec; #endif #endif /* #if (BTA_DM_PM_INCLUDED == TRUE) */ @@ -1228,6 +1238,19 @@ extern tBTA_DM_DI_CB *bta_dm_di_cb_ptr; #define bta_dm_di_cb (*bta_dm_di_cb_ptr) #endif +#if BTA_DYNAMIC_MEMORY == FALSE +extern tBTA_DM_CONNECTED_SRVCS bta_dm_conn_srvcs; +#else +extern tBTA_DM_CONNECTED_SRVCS *bta_dm_conn_srvcs_ptr; +#define bta_dm_conn_srvcs (*bta_dm_conn_srvcs_ptr) +#endif + +/* Discovery raw data buffer */ +#define MAX_DISC_RAW_DATA_BUF (1024) +#if BTA_DYNAMIC_MEMORY == TRUE +extern UINT8 *g_disc_raw_data_buf; +#endif + extern BOOLEAN bta_dm_sm_execute(BT_HDR *p_msg); extern void bta_dm_sm_disable( void ); extern void bta_dm_sm_deinit(void); diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_act.c b/components/bt/bluedroid/bta/gatt/bta_gattc_act.c index e6df3e5189..9f8f2b5198 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_act.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_act.c @@ -68,7 +68,7 @@ static void bta_gattc_cong_cback (UINT16 conn_id, BOOLEAN congested); static void bta_gattc_req_cback (UINT16 conn_id, UINT32 trans_id, tGATTS_REQ_TYPE type, tGATTS_DATA *p_data); static tBTA_GATTC_FIND_SERVICE_CB bta_gattc_register_service_change_notify(UINT16 conn_id, BD_ADDR remote_bda); -static tGATT_CBACK bta_gattc_cl_cback = { +static const tGATT_CBACK bta_gattc_cl_cback = { bta_gattc_conn_cback, bta_gattc_cmpl_cback, bta_gattc_disc_res_cback, @@ -79,7 +79,7 @@ static tGATT_CBACK bta_gattc_cl_cback = { }; /* opcode(tGATTC_OPTYPE) order has to be comply with internal event order */ -static UINT16 bta_gattc_opcode_to_int_evt[] = { +static const UINT16 bta_gattc_opcode_to_int_evt[] = { BTA_GATTC_API_READ_EVT, BTA_GATTC_API_WRITE_EVT, BTA_GATTC_API_EXEC_EVT, diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_cache.c b/components/bt/bluedroid/bta/gatt/bta_gattc_cache.c index 355d619a09..1da1000ae7 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_cache.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_cache.c @@ -26,6 +26,7 @@ #include "common/bt_target.h" #if defined(GATTC_INCLUDED) && (GATTC_INCLUDED == TRUE) +//#if( defined GATTC_CACHE_NVS ) && (GATTC_CACHE_NVS == TRUE) #include #include "bta/utl.h" @@ -2190,5 +2191,7 @@ void bta_gattc_cache_reset(BD_ADDR server_bda) bta_gattc_co_cache_reset(server_bda); //unlink(fname); } + +//#endif /* GATTC_CACHE_NVS */ #endif /* BTA_GATT_INCLUDED */ diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_co.c b/components/bt/bluedroid/bta/gatt/bta_gattc_co.c index c11fb95895..a336c23147 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_co.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_co.c @@ -33,6 +33,7 @@ #if( defined BLE_INCLUDED ) && (BLE_INCLUDED == TRUE) #if( defined BTA_GATT_INCLUDED ) && (GATTC_INCLUDED == TRUE) +// #if( defined GATTC_CACHE_NVS ) && (GATTC_CACHE_NVS == TRUE) #define GATT_CACHE_PREFIX "gatt_" #define INVALID_ADDR_NUM 0xff @@ -77,7 +78,6 @@ static void cacheReset(BD_ADDR bda) static const char *cache_key = "gattc_cache_key"; static const char *cache_addr = "cache_addr_tab"; -nvs_handle_t nvs_fp; typedef struct { //save the service data in the list according to the address @@ -96,7 +96,7 @@ typedef struct { cache_addr_info_t cache_addr[MAX_DEVICE_IN_CACHE]; }cache_env_t; -cache_env_t cache_env; +static cache_env_t *cache_env = NULL; static void getFilename(char *buffer, hash_key_t hash) { @@ -108,9 +108,9 @@ static void cacheClose(BD_ADDR bda) { UINT8 index = 0; if ((index = bta_gattc_co_find_addr_in_cache(bda)) != INVALID_ADDR_NUM) { - if (cache_env.cache_addr[index].is_open) { - nvs_close(cache_env.cache_addr[index].cache_fp); - cache_env.cache_addr[index].is_open = FALSE; + if (cache_env->cache_addr[index].is_open) { + nvs_close(cache_env->cache_addr[index].cache_fp); + cache_env->cache_addr[index].is_open = FALSE; } } } @@ -124,18 +124,18 @@ static bool cacheOpen(BD_ADDR bda, bool to_save, UINT8 *index) hash_key_t hash_key = {0}; if (((*index = bta_gattc_co_find_addr_in_cache(bda)) != INVALID_ADDR_NUM) || ((assoc_addr = bta_gattc_co_cache_find_src_addr(bda, index)) != NULL)) { - if (cache_env.cache_addr[*index].is_open) { + if (cache_env->cache_addr[*index].is_open) { return TRUE; } else { - memcpy(hash_key, cache_env.cache_addr[*index].hash_key, sizeof(hash_key_t)); + memcpy(hash_key, cache_env->cache_addr[*index].hash_key, sizeof(hash_key_t)); getFilename(fname, hash_key); - if ((status = nvs_open(fname, NVS_READWRITE, &cache_env.cache_addr[*index].cache_fp)) == ESP_OK) { + if ((status = nvs_open(fname, NVS_READWRITE, &cache_env->cache_addr[*index].cache_fp)) == ESP_OK) { // Set the open flag to TRUE when success to open the hash file. - cache_env.cache_addr[*index].is_open = TRUE; + cache_env->cache_addr[*index].is_open = TRUE; } } } - + return ((status == ESP_OK) ? true : false); } @@ -144,67 +144,67 @@ static void cacheReset(BD_ADDR bda) char fname[255] = {0}; getFilename(fname, bda); UINT8 index = 0; - //cache_env.cache_addr + //cache_env->cache_addr if ((index = bta_gattc_co_find_addr_in_cache(bda)) != INVALID_ADDR_NUM) { //clear the association address pending in the source address. bta_gattc_co_cache_clear_assoc_addr(bda); - if (cache_env.cache_addr[index].is_open) { - nvs_erase_all(cache_env.cache_addr[index].cache_fp); - nvs_close(cache_env.cache_addr[index].cache_fp); - cache_env.cache_addr[index].is_open = FALSE; + if (cache_env->cache_addr[index].is_open) { + nvs_erase_all(cache_env->cache_addr[index].cache_fp); + nvs_close(cache_env->cache_addr[index].cache_fp); + cache_env->cache_addr[index].is_open = FALSE; } else { cacheOpen(bda, false, &index); - if (cache_env.cache_addr[index].is_open) { - nvs_erase_all(cache_env.cache_addr[index].cache_fp); - nvs_close(cache_env.cache_addr[index].cache_fp); - cache_env.cache_addr[index].is_open = FALSE; + if (cache_env->cache_addr[index].is_open) { + nvs_erase_all(cache_env->cache_addr[index].cache_fp); + nvs_close(cache_env->cache_addr[index].cache_fp); + cache_env->cache_addr[index].is_open = FALSE; } else { APPL_TRACE_ERROR("%s cacheOpen failed", __func__); return; } } - if(cache_env.num_addr == 0) { + if(cache_env->num_addr == 0) { APPL_TRACE_ERROR("%s cache addr list error", __func__); return; } - UINT8 num = cache_env.num_addr; + UINT8 num = cache_env->num_addr; //delete the server_bda in the addr_info list. for(UINT8 i = index; i < (num - 1); i++) { - memcpy(&cache_env.cache_addr[i], &cache_env.cache_addr[i+1], sizeof(cache_addr_info_t)); + memcpy(&cache_env->cache_addr[i], &cache_env->cache_addr[i+1], sizeof(cache_addr_info_t)); } //reduced the number address counter also - cache_env.num_addr--; + cache_env->num_addr--; //update addr list to nvs flash - if(cache_env.num_addr > 0) { + if(cache_env->num_addr > 0) { //update UINT8 *p_buf = osi_malloc(MAX_ADDR_LIST_CACHE_BUF); if(!p_buf) { - APPL_TRACE_ERROR("%s malloc error", __func__); - return; + APPL_TRACE_ERROR("%s malloc error", __func__); + return; } - UINT16 length = cache_env.num_addr*(sizeof(BD_ADDR) + sizeof(hash_key_t)); - for (UINT8 i = 0; i < cache_env.num_addr; i++) { + UINT16 length = cache_env->num_addr*(sizeof(BD_ADDR) + sizeof(hash_key_t)); + for (UINT8 i = 0; i < cache_env->num_addr; i++) { //copy the address to the buffer. - memcpy(p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)), cache_env.cache_addr[i].addr, sizeof(BD_ADDR)); + memcpy(p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)), cache_env->cache_addr[i].addr, sizeof(BD_ADDR)); //copy the hash key to the buffer. memcpy(p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)) + sizeof(BD_ADDR), - cache_env.cache_addr[i].hash_key, sizeof(hash_key_t)); + cache_env->cache_addr[i].hash_key, sizeof(hash_key_t)); } - if (cache_env.is_open) { - if (nvs_set_blob(cache_env.addr_fp, cache_key, p_buf, length) != ESP_OK) { + if (cache_env->is_open) { + if (nvs_set_blob(cache_env->addr_fp, cache_key, p_buf, length) != ESP_OK) { APPL_TRACE_WARNING("%s, nvs set blob failed", __func__); } } osi_free(p_buf); - + } else { //erase - if (cache_env.is_open) { - nvs_erase_all(cache_env.addr_fp); - nvs_close(cache_env.addr_fp); - cache_env.is_open = FALSE; + if (cache_env->is_open) { + nvs_erase_all(cache_env->addr_fp); + nvs_close(cache_env->addr_fp); + cache_env->is_open = FALSE; } else { APPL_TRACE_WARNING("cache_env status is error"); } @@ -267,9 +267,9 @@ tBTA_GATT_STATUS bta_gattc_co_cache_load(tBTA_GATTC_NV_ATTR *attr, UINT8 index) tBTA_GATT_STATUS status = BTA_GATT_ERROR; size_t length = 0; // Read the size of memory space required for blob - nvs_get_blob(cache_env.cache_addr[index].cache_fp, cache_key, NULL, &length); + nvs_get_blob(cache_env->cache_addr[index].cache_fp, cache_key, NULL, &length); // Read previously saved blob if available - esp_err_t err_code = nvs_get_blob(cache_env.cache_addr[index].cache_fp, cache_key, attr, &length); + esp_err_t err_code = nvs_get_blob(cache_env->cache_addr[index].cache_fp, cache_key, attr, &length); #if (!CONFIG_BT_STACK_NO_LOG) num_attr = length / sizeof(tBTA_GATTC_NV_ATTR); #endif @@ -288,7 +288,7 @@ size_t bta_gattc_get_cache_attr_length(UINT8 index) } // Read the size of memory space required for blob - nvs_get_blob(cache_env.cache_addr[index].cache_fp, cache_key, NULL, &length); + nvs_get_blob(cache_env->cache_addr[index].cache_fp, cache_key, NULL, &length); return length; } @@ -320,7 +320,7 @@ void bta_gattc_co_cache_save (BD_ADDR server_bda, UINT16 num_attr, bta_gattc_co_cache_addr_save(server_bda, hash_key); if (cacheOpen(server_bda, TRUE, &index)) { - esp_err_t err_code = nvs_set_blob(cache_env.cache_addr[index].cache_fp, cache_key, + esp_err_t err_code = nvs_set_blob(cache_env->cache_addr[index].cache_fp, cache_key, p_attr_list, sizeof(tBTA_GATTC_NV_ATTR)*num_attr); status = (err_code == ESP_OK) ? BTA_GATT_OK : BTA_GATT_ERROR; } else { @@ -380,12 +380,23 @@ void bta_gattc_co_cache_addr_init(void) nvs_handle_t fp; esp_err_t err_code; UINT8 num_addr; - UINT8 *p_buf = osi_malloc(MAX_ADDR_LIST_CACHE_BUF); size_t length = MAX_ADDR_LIST_CACHE_BUF; + UINT8 *p_buf = osi_malloc(MAX_ADDR_LIST_CACHE_BUF); + if (p_buf == NULL) { + APPL_TRACE_ERROR("%s malloc failed!", __func__); + return; + } + + cache_env = (cache_env_t *)osi_malloc(sizeof(cache_env_t)); + if (cache_env == NULL) { + APPL_TRACE_ERROR("%s malloc failed!", __func__); + osi_free(p_buf); + return; + } if ((err_code = nvs_open(cache_addr, NVS_READWRITE, &fp)) == ESP_OK) { - cache_env.addr_fp = fp; - cache_env.is_open = TRUE; + cache_env->addr_fp = fp; + cache_env->is_open = TRUE; // Read previously saved blob if available if ((err_code = nvs_get_blob(fp, cache_key, p_buf, &length)) != ESP_OK) { if(err_code != ESP_ERR_NVS_NOT_FOUND) { @@ -395,18 +406,18 @@ void bta_gattc_co_cache_addr_init(void) return; } num_addr = length / (sizeof(BD_ADDR) + sizeof(hash_key_t)); - cache_env.num_addr = num_addr; + cache_env->num_addr = num_addr; //read the address from nvs flash to cache address list. for (UINT8 i = 0; i < num_addr; i++) { - memcpy(cache_env.cache_addr[i].addr, p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)), sizeof(BD_ADDR)); - memcpy(cache_env.cache_addr[i].hash_key, + memcpy(cache_env->cache_addr[i].addr, p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)), sizeof(BD_ADDR)); + memcpy(cache_env->cache_addr[i].hash_key, p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)) + sizeof(BD_ADDR), sizeof(hash_key_t)); - APPL_TRACE_DEBUG("cache_addr[%x] = %x:%x:%x:%x:%x:%x", i, cache_env.cache_addr[i].addr[0], cache_env.cache_addr[i].addr[1], cache_env.cache_addr[i].addr[2], - cache_env.cache_addr[i].addr[3], cache_env.cache_addr[i].addr[4], cache_env.cache_addr[i].addr[5]); - APPL_TRACE_DEBUG("hash_key[%x] = %x%x%x%x", i, cache_env.cache_addr[i].hash_key[0], cache_env.cache_addr[i].hash_key[1], - cache_env.cache_addr[i].hash_key[2], cache_env.cache_addr[i].hash_key[3]); - bta_gattc_co_cache_new_assoc_list(cache_env.cache_addr[i].addr, i); + APPL_TRACE_DEBUG("cache_addr[%x] = %x:%x:%x:%x:%x:%x", i, cache_env->cache_addr[i].addr[0], cache_env->cache_addr[i].addr[1], cache_env->cache_addr[i].addr[2], + cache_env->cache_addr[i].addr[3], cache_env->cache_addr[i].addr[4], cache_env->cache_addr[i].addr[5]); + APPL_TRACE_DEBUG("hash_key[%x] = %x%x%x%x", i, cache_env->cache_addr[i].hash_key[0], cache_env->cache_addr[i].hash_key[1], + cache_env->cache_addr[i].hash_key[2], cache_env->cache_addr[i].hash_key[3]); + bta_gattc_co_cache_new_assoc_list(cache_env->cache_addr[i].addr, i); } } else { APPL_TRACE_ERROR("%s, Line = %d, nvs flash open fail, err_code = %x", __func__, __LINE__, err_code); @@ -420,14 +431,14 @@ void bta_gattc_co_cache_addr_init(void) void bta_gattc_co_cache_addr_deinit(void) { - if(!cache_env.is_open) { + if(!cache_env->is_open) { return; - } - nvs_close(cache_env.addr_fp); - cache_env.is_open = false; - - for(UINT8 i = 0; i< cache_env.num_addr; i++) { - cache_addr_info_t *addr_info = &cache_env.cache_addr[i]; + } + nvs_close(cache_env->addr_fp); + cache_env->is_open = false; + + for(UINT8 i = 0; i< cache_env->num_addr; i++) { + cache_addr_info_t *addr_info = &cache_env->cache_addr[i]; if(addr_info) { nvs_close(addr_info->cache_fp); addr_info->is_open = false; @@ -436,13 +447,16 @@ void bta_gattc_co_cache_addr_deinit(void) } } } + + osi_free(cache_env); + cache_env = NULL; } BOOLEAN bta_gattc_co_addr_in_cache(BD_ADDR bda) { UINT8 addr_index = 0; - UINT8 num = cache_env.num_addr; - cache_addr_info_t *addr_info = &cache_env.cache_addr[0]; + UINT8 num = cache_env->num_addr; + cache_addr_info_t *addr_info = &cache_env->cache_addr[0]; for (addr_index = 0; addr_index < num; addr_index++) { if (!memcmp(addr_info->addr, bda, sizeof(BD_ADDR))) { return TRUE; @@ -455,8 +469,8 @@ BOOLEAN bta_gattc_co_addr_in_cache(BD_ADDR bda) UINT8 bta_gattc_co_find_addr_in_cache(BD_ADDR bda) { UINT8 addr_index = 0; - UINT8 num = cache_env.num_addr; - cache_addr_info_t *addr_info = &cache_env.cache_addr[0]; + UINT8 num = cache_env->num_addr; + cache_addr_info_t *addr_info = &cache_env->cache_addr[0]; for (addr_index = 0; addr_index < num; addr_index++, addr_info++) { if (!memcmp(addr_info->addr, bda, sizeof(BD_ADDR))) { @@ -470,8 +484,8 @@ UINT8 bta_gattc_co_find_addr_in_cache(BD_ADDR bda) UINT8 bta_gattc_co_find_hash_in_cache(hash_key_t hash_key) { UINT8 index = 0; - UINT8 num = cache_env.num_addr; - cache_addr_info_t *addr_info = &cache_env.cache_addr[0]; + UINT8 num = cache_env->num_addr; + cache_addr_info_t *addr_info = &cache_env->cache_addr[0]; for (index = 0; index < num; index++) { if (!memcmp(addr_info->hash_key, hash_key, sizeof(hash_key_t))) { return index; @@ -483,21 +497,21 @@ UINT8 bta_gattc_co_find_hash_in_cache(hash_key_t hash_key) UINT8 bta_gattc_co_get_addr_num(void) { - return cache_env.num_addr; + return cache_env->num_addr; } void bta_gattc_co_get_addr_list(BD_ADDR *addr_list) { - UINT8 num = cache_env.num_addr; + UINT8 num = cache_env->num_addr; for (UINT8 i = 0; i < num; i++) { - memcpy(addr_list[i], cache_env.cache_addr[i].addr, sizeof(BD_ADDR)); + memcpy(addr_list[i], cache_env->cache_addr[i].addr, sizeof(BD_ADDR)); } } void bta_gattc_co_cache_addr_save(BD_ADDR bd_addr, hash_key_t hash_key) { esp_err_t err_code; - UINT8 num = ++cache_env.num_addr; + UINT8 num = ++cache_env->num_addr; UINT8 index = 0; UINT8 *p_buf = osi_malloc(MAX_ADDR_LIST_CACHE_BUF); // check the address list has the same hash key or not @@ -506,39 +520,39 @@ void bta_gattc_co_cache_addr_save(BD_ADDR bd_addr, hash_key_t hash_key) if ((index = bta_gattc_co_find_addr_in_cache(bd_addr)) != INVALID_ADDR_NUM) { APPL_TRACE_DEBUG("%s(), the hash bd_addr already in the cache list, index = %x", __func__, index); //if the bd_addr already in the address list, update the hash key in it. - memcpy(cache_env.cache_addr[index].addr, bd_addr, sizeof(BD_ADDR)); - memcpy(cache_env.cache_addr[index].hash_key, hash_key, sizeof(hash_key_t)); + memcpy(cache_env->cache_addr[index].addr, bd_addr, sizeof(BD_ADDR)); + memcpy(cache_env->cache_addr[index].hash_key, hash_key, sizeof(hash_key_t)); } else { //if the bd_addr didn't in the address list, added the bd_addr to the last of the address list. - memcpy(cache_env.cache_addr[num - 1].hash_key, hash_key, sizeof(hash_key_t)); - memcpy(cache_env.cache_addr[num - 1].addr, bd_addr, sizeof(BD_ADDR)); + memcpy(cache_env->cache_addr[num - 1].hash_key, hash_key, sizeof(hash_key_t)); + memcpy(cache_env->cache_addr[num - 1].addr, bd_addr, sizeof(BD_ADDR)); } } else { APPL_TRACE_DEBUG("%s(), num = %d", __func__, num); - memcpy(cache_env.cache_addr[num - 1].addr, bd_addr, sizeof(BD_ADDR)); - memcpy(cache_env.cache_addr[num - 1].hash_key, hash_key, sizeof(hash_key_t)); + memcpy(cache_env->cache_addr[num - 1].addr, bd_addr, sizeof(BD_ADDR)); + memcpy(cache_env->cache_addr[num - 1].hash_key, hash_key, sizeof(hash_key_t)); } - nvs_handle_t *fp = &cache_env.addr_fp; + nvs_handle_t *fp = &cache_env->addr_fp; UINT16 length = num*(sizeof(BD_ADDR) + sizeof(hash_key_t)); for (UINT8 i = 0; i < num; i++) { //copy the address to the buffer. - memcpy(p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)), cache_env.cache_addr[i].addr, sizeof(BD_ADDR)); + memcpy(p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)), cache_env->cache_addr[i].addr, sizeof(BD_ADDR)); //copy the hash key to the buffer. memcpy(p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)) + sizeof(BD_ADDR), - cache_env.cache_addr[i].hash_key, sizeof(hash_key_t)); + cache_env->cache_addr[i].hash_key, sizeof(hash_key_t)); } - if (cache_env.is_open) { - if ((err_code = nvs_set_blob(cache_env.addr_fp, cache_key, p_buf, length)) != ESP_OK) { + if (cache_env->is_open) { + if ((err_code = nvs_set_blob(cache_env->addr_fp, cache_key, p_buf, length)) != ESP_OK) { APPL_TRACE_WARNING("%s(), nvs set blob fail, err %d", __func__, err_code); } } else { if ((err_code = nvs_open(cache_addr, NVS_READWRITE , fp)) == ESP_OK) { - cache_env.is_open = true; - if (( err_code = nvs_set_blob(cache_env.addr_fp, cache_key, p_buf, length)) != ESP_OK) { + cache_env->is_open = true; + if (( err_code = nvs_set_blob(cache_env->addr_fp, cache_key, p_buf, length)) != ESP_OK) { APPL_TRACE_WARNING("%s(), nvs set blob fail, err %d", __func__, err_code); } } else { @@ -553,7 +567,7 @@ void bta_gattc_co_cache_addr_save(BD_ADDR bd_addr, hash_key_t hash_key) BOOLEAN bta_gattc_co_cache_new_assoc_list(BD_ADDR src_addr, UINT8 index) { - cache_addr_info_t *addr_info = &cache_env.cache_addr[index]; + cache_addr_info_t *addr_info = &cache_env->cache_addr[index]; addr_info->assoc_addr = list_new(osi_free_func); return (addr_info->assoc_addr != NULL ? TRUE : FALSE); } @@ -565,7 +579,7 @@ BOOLEAN bta_gattc_co_cache_append_assoc_addr(BD_ADDR src_addr, BD_ADDR assoc_add UINT8 *p_assoc_buf = osi_malloc(sizeof(BD_ADDR)); memcpy(p_assoc_buf, assoc_addr, sizeof(BD_ADDR)); if ((addr_index = bta_gattc_co_find_addr_in_cache(src_addr)) != INVALID_ADDR_NUM) { - addr_info = &cache_env.cache_addr[addr_index]; + addr_info = &cache_env->cache_addr[addr_index]; if (addr_info->assoc_addr == NULL) { addr_info->assoc_addr =list_new(NULL); } @@ -580,7 +594,7 @@ BOOLEAN bta_gattc_co_cache_remove_assoc_addr(BD_ADDR src_addr, BD_ADDR assoc_add UINT8 addr_index = 0; cache_addr_info_t *addr_info; if ((addr_index = bta_gattc_co_find_addr_in_cache(src_addr)) != INVALID_ADDR_NUM) { - addr_info = &cache_env.cache_addr[addr_index]; + addr_info = &cache_env->cache_addr[addr_index]; if (addr_info->assoc_addr != NULL) { for (list_node_t *sn = list_begin(addr_info->assoc_addr); sn != list_end(addr_info->assoc_addr); sn = list_next(sn)) { @@ -600,8 +614,8 @@ BOOLEAN bta_gattc_co_cache_remove_assoc_addr(BD_ADDR src_addr, BD_ADDR assoc_add UINT8* bta_gattc_co_cache_find_src_addr(BD_ADDR assoc_addr, UINT8 *index) { - UINT8 num = cache_env.num_addr; - cache_addr_info_t *addr_info = &cache_env.cache_addr[0]; + UINT8 num = cache_env->num_addr; + cache_addr_info_t *addr_info = &cache_env->cache_addr[0]; UINT8 *addr_data; //Check the assoc_addr list is NULL or not if (addr_info->assoc_addr == NULL) { @@ -610,7 +624,7 @@ UINT8* bta_gattc_co_cache_find_src_addr(BD_ADDR assoc_addr, UINT8 *index) } for (int i = 0; i < num; i++) { - for (const list_node_t *node = list_begin(addr_info->assoc_addr); node != list_end(addr_info->assoc_addr); + for (const list_node_t *node = list_begin(addr_info->assoc_addr); node != list_end(addr_info->assoc_addr); node = list_next(node)) { addr_data = (UINT8 *)list_node(node); if (!memcmp(addr_data, assoc_addr, sizeof(BD_ADDR))) { @@ -635,7 +649,7 @@ BOOLEAN bta_gattc_co_cache_clear_assoc_addr(BD_ADDR src_addr) UINT8 addr_index = 0; cache_addr_info_t *addr_info; if ((addr_index = bta_gattc_co_find_addr_in_cache(src_addr)) != INVALID_ADDR_NUM) { - addr_info = &cache_env.cache_addr[addr_index]; + addr_info = &cache_env->cache_addr[addr_index]; if (addr_info->assoc_addr != NULL) { list_clear(addr_info->assoc_addr); } else { @@ -647,6 +661,7 @@ BOOLEAN bta_gattc_co_cache_clear_assoc_addr(BD_ADDR src_addr) return FALSE; } +// #endif /* #if( defined GATTC_CACHE_NVS ) && (GATTC_CACHE_NVS == TRUE) */ #endif /* #if( defined BLE_INCLUDED ) && (BLE_INCLUDED == TRUE) */ #endif /* #if( defined BTA_GATT_INCLUDED ) && (BTA_GATT_INCLUDED == TRUE) */ diff --git a/components/bt/bluedroid/bta/gatt/bta_gatts_act.c b/components/bt/bluedroid/bta/gatt/bta_gatts_act.c index 95cb668c6b..4dd804a47a 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gatts_act.c +++ b/components/bt/bluedroid/bta/gatt/bta_gatts_act.c @@ -49,7 +49,7 @@ static void bta_gatts_send_request_cback (UINT16 conn_id, tGATTS_REQ_TYPE req_type, tGATTS_DATA *p_data); static void bta_gatts_cong_cback (UINT16 conn_id, BOOLEAN congested); -static tGATT_CBACK bta_gatts_cback = { +static const tGATT_CBACK bta_gatts_cback = { bta_gatts_conn_cback, NULL, NULL, @@ -59,7 +59,7 @@ static tGATT_CBACK bta_gatts_cback = { bta_gatts_cong_cback }; -tGATT_APPL_INFO bta_gatts_nv_cback = { +const tGATT_APPL_INFO bta_gatts_nv_cback = { bta_gatts_nv_save_cback, bta_gatts_nv_srv_chg_cback }; diff --git a/components/bt/bluedroid/bta/gatt/bta_gatts_api.c b/components/bt/bluedroid/bta/gatt/bta_gatts_api.c index 87e559ab72..aefe62d65a 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gatts_api.c +++ b/components/bt/bluedroid/bta/gatt/bta_gatts_api.c @@ -82,7 +82,7 @@ void BTA_GATTS_Disable(void) ** Returns None ** *******************************************************************************/ -void BTA_GATTS_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTS_CBACK *p_cback) +void BTA_GATTS_AppRegister(const tBT_UUID * p_app_uuid, tBTA_GATTS_CBACK *p_cback) { tBTA_GATTS_API_REG *p_buf; @@ -149,7 +149,7 @@ void BTA_GATTS_AppDeregister(tBTA_GATTS_IF server_if) ** Returns void ** *******************************************************************************/ -void BTA_GATTS_CreateService(tBTA_GATTS_IF server_if, tBT_UUID *p_service_uuid, UINT8 inst, +void BTA_GATTS_CreateService(tBTA_GATTS_IF server_if, const tBT_UUID * p_service_uuid, UINT8 inst, UINT16 num_handle, BOOLEAN is_primary) { tBTA_GATTS_API_CREATE_SRVC *p_buf; @@ -214,8 +214,8 @@ void BTA_GATTS_AddIncludeService(UINT16 service_id, UINT16 included_service_id) ** Returns None ** *******************************************************************************/ -void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid, - tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property, tGATT_ATTR_VAL *attr_val, +void BTA_GATTS_AddCharacteristic (UINT16 service_id, const tBT_UUID * p_char_uuid, + tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property, tGATT_ATTR_VAL *attr_val, tBTA_GATTS_ATTR_CONTROL *control) { tBTA_GATTS_API_ADD_CHAR *p_buf; @@ -270,7 +270,7 @@ void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid, *******************************************************************************/ void BTA_GATTS_AddCharDescriptor (UINT16 service_id, tBTA_GATT_PERM perm, - tBT_UUID *p_descr_uuid, tBTA_GATT_ATTR_VAL *attr_val, + const tBT_UUID * p_descr_uuid, tBTA_GATT_ATTR_VAL *attr_val, tBTA_GATTS_ATTR_CONTROL *control) { tBTA_GATTS_API_ADD_DESCR *p_buf; diff --git a/components/bt/bluedroid/bta/include/bta/bta_api.h b/components/bt/bluedroid/bta/include/bta/bta_api.h index a7dc0185f3..c9349e80ec 100644 --- a/components/bt/bluedroid/bta/include/bta/bta_api.h +++ b/components/bt/bluedroid/bta/include/bta/bta_api.h @@ -31,9 +31,9 @@ // #include "uipc_msg.h" #include "stack/sdp_api.h" -#if BLE_INCLUDED == TRUE +// #if BLE_INCLUDED == TRUE #include "stack/btm_ble_api.h" -#endif +// #endif /***************************************************************************** ** Constants and data types @@ -323,7 +323,7 @@ typedef struct { tBTA_DM_CONFIG_EIR_CBACK *config_eir_callback; /* callback */ } tBTA_DM_EIR_CONF; -#if BLE_INCLUDED == TRUE +// #if BLE_INCLUDED == TRUE /* ADV data flag bit definition used for BTM_BLE_AD_TYPE_FLAG */ #define BTA_BLE_LIMIT_DISC_FLAG BTM_BLE_LIMIT_DISC_FLAG #define BTA_BLE_GEN_DISC_FLAG BTM_BLE_GEN_DISC_FLAG @@ -510,7 +510,7 @@ enum { typedef tBTM_BLE_BATCH_SCAN_EVT tBTA_BLE_BATCH_SCAN_EVT; typedef tBTM_BLE_TRACK_ADV_ACTION tBTA_BLE_TRACK_ADV_ACTION; -#endif +// #endif /* BLE customer specific feature function type definitions */ /* data type used on customer specific feature for RSSI monitoring */ @@ -1473,9 +1473,11 @@ extern void BTA_DmSetDeviceName(const char *p_name); *******************************************************************************/ extern void BTA_DmConfigEir(tBTA_DM_EIR_CONF *eir_config); +#if (BLE_INCLUDED == TRUE) extern void BTA_DmUpdateWhiteList(BOOLEAN add_remove, BD_ADDR remote_addr, tBLE_ADDR_TYPE addr_type, tBTA_ADD_WHITELIST_CBACK *add_wl_cb); extern void BTA_DmBleReadAdvTxPower(tBTA_CMPL_CB *cmpl_cb); +#endif ///BLE_INCLUDED == TRUE extern void BTA_DmBleReadRSSI(BD_ADDR remote_addr, tBTA_TRANSPORT transport, tBTA_CMPL_CB *cmpl_cb); @@ -1809,6 +1811,17 @@ extern void bta_dmexecutecallback (tBTA_DM_EXEC_CBACK *p_callback, void *p_param *******************************************************************************/ extern void BTA_DmPcmInitSamples (UINT32 src_sps, UINT32 bits, UINT32 n_channels); +/******************************************************************************* +** +** Function BTA_DmPcmDeinitSamples +** +** Description Deinitialize the down sample converter. +** +** Returns none +** +*******************************************************************************/ +extern void BTA_DmPcmDeinitSamples(void); + /************************************************************************************** ** Function BTA_DmPcmResample ** diff --git a/components/bt/bluedroid/bta/include/bta/bta_dm_co.h b/components/bt/bluedroid/bta/include/bta/bta_dm_co.h index b9e98b4653..3ef102c5aa 100644 --- a/components/bt/bluedroid/bta/include/bta/bta_dm_co.h +++ b/components/bt/bluedroid/bta/include/bta/bta_dm_co.h @@ -25,6 +25,7 @@ #define BTA_DM_CO_H #include "bta/bta_sys.h" +#include "esp_err.h" /***************************************************************************** ** Function Declarations diff --git a/components/bt/bluedroid/bta/include/bta/bta_gatt_api.h b/components/bt/bluedroid/bta/include/bta/bta_gatt_api.h index cb69110b60..664536ddd1 100644 --- a/components/bt/bluedroid/bta/include/bta/bta_gatt_api.h +++ b/components/bt/bluedroid/bta/include/bta/bta_gatt_api.h @@ -30,7 +30,6 @@ #include "osi/list.h" #ifndef BTA_GATT_INCLUDED -#warning BTA_GATT_INCLUDED not defined #define BTA_GATT_INCLUDED FALSE #endif @@ -881,7 +880,7 @@ extern const tBTA_GATTC_CHARACTERISTIC* BTA_GATTC_GetCharacteristic(UINT16 conn_ *******************************************************************************/ extern const tBTA_GATTC_DESCRIPTOR* BTA_GATTC_GetDescriptor(UINT16 conn_id, UINT16 handle); -extern void BTA_GATTC_GetServiceWithUUID(UINT16 conn_id, tBT_UUID *svc_uuid, +extern void BTA_GATTC_GetServiceWithUUID(UINT16 conn_id, tBT_UUID *svc_uuid, btgatt_db_element_t **db, int *count); extern void BTA_GATTC_GetAllChar(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, @@ -1234,7 +1233,7 @@ extern void BTA_GATTS_Disable(void); ** Returns None ** *******************************************************************************/ -extern void BTA_GATTS_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTS_CBACK *p_cback); +extern void BTA_GATTS_AppRegister(const tBT_UUID * p_app_uuid, tBTA_GATTS_CBACK *p_cback); /******************************************************************************* @@ -1269,7 +1268,7 @@ extern void BTA_GATTS_AppDeregister(tBTA_GATTS_IF server_if); ** Returns void ** *******************************************************************************/ -extern void BTA_GATTS_CreateService(tBTA_GATTS_IF server_if, tBT_UUID *p_service_uuid, +extern void BTA_GATTS_CreateService(tBTA_GATTS_IF server_if, const tBT_UUID * p_service_uuid, UINT8 inst, UINT16 num_handle, BOOLEAN is_primary); /******************************************************************************* @@ -1304,8 +1303,8 @@ extern void BTA_GATTS_AddIncludeService(UINT16 service_id, UINT16 included_servi ** Returns None ** *******************************************************************************/ -extern void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid, - tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property, tGATT_ATTR_VAL *attr_val, +extern void BTA_GATTS_AddCharacteristic (UINT16 service_id, const tBT_UUID * p_char_uuid, + tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property, tGATT_ATTR_VAL *attr_val, tBTA_GATTS_ATTR_CONTROL *control); /******************************************************************************* @@ -1327,7 +1326,7 @@ extern void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_u *******************************************************************************/ extern void BTA_GATTS_AddCharDescriptor (UINT16 service_id, tBTA_GATT_PERM perm, - tBT_UUID *p_descr_uuid, tBTA_GATT_ATTR_VAL *attr_val, + const tBT_UUID * p_descr_uuid, tBTA_GATT_ATTR_VAL *attr_val, tBTA_GATTS_ATTR_CONTROL *control); /******************************************************************************* diff --git a/components/bt/bluedroid/bta/include/bta/bta_sdp_api.h b/components/bt/bluedroid/bta/include/bta/bta_sdp_api.h index b88c0c263c..1d32b9204f 100644 --- a/components/bt/bluedroid/bta/include/bta/bta_sdp_api.h +++ b/components/bt/bluedroid/bta/include/bta/bta_sdp_api.h @@ -96,6 +96,19 @@ extern "C" *******************************************************************************/ extern tBTA_SDP_STATUS BTA_SdpEnable(tBTA_SDP_DM_CBACK *p_cback); +/******************************************************************************* +** +** Function BTA_SdpDisable +** +** Description Disable the SDP search I/F service. +** Free buffer for SDP configuration structure. +** +** Returns BTA_SDP_SUCCESS if successful. +** BTA_SDP_FAIL if internal failure. +** +*******************************************************************************/ +extern tBTA_SDP_STATUS BTA_SdpDisable(void); + /******************************************************************************* ** ** Function BTA_SdpSearch diff --git a/components/bt/bluedroid/bta/include/bta/bta_sys.h b/components/bt/bluedroid/bta/include/bta/bta_sys.h index a58773de73..a466028b95 100644 --- a/components/bt/bluedroid/bta/include/bta/bta_sys.h +++ b/components/bt/bluedroid/bta/include/bta/bta_sys.h @@ -215,7 +215,7 @@ extern "C" { extern void bta_sys_init(void); extern void bta_sys_free(void); -extern void bta_sys_event(BT_HDR *p_msg); +extern void bta_sys_event(void * param); extern void bta_sys_set_trace_level(UINT8 level); extern void bta_sys_register(UINT8 id, const tBTA_SYS_REG *p_reg); extern void bta_sys_deregister(UINT8 id); diff --git a/components/bt/bluedroid/bta/jv/bta_jv_api.c b/components/bt/bluedroid/bta/jv/bta_jv_api.c index 5430d36bcb..98465701db 100644 --- a/components/bt/bluedroid/bta/jv/bta_jv_api.c +++ b/components/bt/bluedroid/bta/jv/bta_jv_api.c @@ -67,8 +67,17 @@ tBTA_JV_STATUS BTA_JvEnable(tBTA_JV_DM_CBACK *p_cback) tBTA_JV_STATUS status = BTA_JV_FAILURE; tBTA_JV_API_ENABLE *p_buf; int i; - APPL_TRACE_API( "BTA_JvEnable"); + +#if BTA_DYNAMIC_MEMORY == TRUE + /* Malloc buffer for JV configuration structure */ + p_bta_jv_cfg->p_sdp_raw_data = (UINT8 *)osi_malloc(p_bta_jv_cfg->sdp_raw_size); + p_bta_jv_cfg->p_sdp_db = (tSDP_DISCOVERY_DB *)osi_malloc(p_bta_jv_cfg->sdp_db_size); + if (p_bta_jv_cfg->p_sdp_raw_data == NULL || p_bta_jv_cfg->p_sdp_db == NULL) { + return BTA_JV_NO_DATA; + } +#endif + if (p_cback && FALSE == bta_sys_is_register(BTA_ID_JV)) { memset(&bta_jv_cb, 0, sizeof(tBTA_JV_CB)); /* set handle to invalid value by default */ @@ -110,6 +119,14 @@ void BTA_JvDisable(void) p_buf->event = BTA_JV_API_DISABLE_EVT; bta_sys_sendmsg(p_buf); } + +#if BTA_DYNAMIC_MEMORY == TRUE + /* Free buffer for JV configuration structure */ + osi_free(p_bta_jv_cfg->p_sdp_raw_data); + osi_free(p_bta_jv_cfg->p_sdp_db); + p_bta_jv_cfg->p_sdp_raw_data = NULL; + p_bta_jv_cfg->p_sdp_db = NULL; +#endif } /******************************************************************************* diff --git a/components/bt/bluedroid/bta/jv/bta_jv_cfg.c b/components/bt/bluedroid/bta/jv/bta_jv_cfg.c index f617dfc513..9020efb8ab 100644 --- a/components/bt/bluedroid/bta/jv/bta_jv_cfg.c +++ b/components/bt/bluedroid/bta/jv/bta_jv_cfg.c @@ -43,15 +43,22 @@ * between BTA_JvEnable and BTA_JvDisable * p_bta_jv_cfg->p_sdp_raw_data can be allocated before calling BTA_JvStartDiscovery * it can be de-allocated after the last call to access the database */ +#if BTA_DYNAMIC_MEMORY == FALSE static UINT8 bta_jv_sdp_raw_data[BTA_JV_SDP_RAW_DATA_SIZE]; static UINT8 __attribute__ ((aligned(4))) bta_jv_sdp_db_data[BTA_JV_SDP_DB_SIZE]; +#endif /* JV configuration structure */ -const tBTA_JV_CFG bta_jv_cfg = { +/*const */tBTA_JV_CFG bta_jv_cfg = { BTA_JV_SDP_RAW_DATA_SIZE, /* The size of p_sdp_raw_data */ BTA_JV_SDP_DB_SIZE, /* The size of p_sdp_db_data */ +#if BTA_DYNAMIC_MEMORY == FALSE bta_jv_sdp_raw_data, /* The data buffer to keep raw data */ (tSDP_DISCOVERY_DB *)bta_jv_sdp_db_data /* The data buffer to keep SDP database */ +#else + NULL, + NULL +#endif }; tBTA_JV_CFG *p_bta_jv_cfg = (tBTA_JV_CFG *) &bta_jv_cfg; diff --git a/components/bt/bluedroid/bta/jv/bta_jv_main.c b/components/bt/bluedroid/bta/jv/bta_jv_main.c index 9523d6e893..b09ebcd469 100644 --- a/components/bt/bluedroid/bta/jv/bta_jv_main.c +++ b/components/bt/bluedroid/bta/jv/bta_jv_main.c @@ -35,6 +35,8 @@ #if BTA_DYNAMIC_MEMORY == FALSE tBTA_JV_CB bta_jv_cb; +#else +tBTA_JV_CB *bta_jv_cb_ptr; #endif /* state machine action enumeration list */ diff --git a/components/bt/bluedroid/bta/sdp/bta_sdp_api.c b/components/bt/bluedroid/bta/sdp/bta_sdp_api.c index 1d027cb79e..e26f93910c 100644 --- a/components/bt/bluedroid/bta/sdp/bta_sdp_api.c +++ b/components/bt/bluedroid/bta/sdp/bta_sdp_api.c @@ -61,6 +61,15 @@ tBTA_SDP_STATUS BTA_SdpEnable(tBTA_SDP_DM_CBACK *p_cback) tBTA_SDP_API_ENABLE *p_buf; APPL_TRACE_API("%s\n", __FUNCTION__); + +#if BTA_DYNAMIC_MEMORY == TRUE + /* Malloc buffer for SDP configuration structure */ + p_bta_sdp_cfg->p_sdp_db = (tSDP_DISCOVERY_DB *)osi_malloc(p_bta_sdp_cfg->sdp_db_size); + if (p_bta_sdp_cfg->p_sdp_db == NULL) { + return BTA_SDP_FAILURE; + } +#endif + if (p_cback && FALSE == bta_sys_is_register(BTA_ID_SDP)) { memset(&bta_sdp_cb, 0, sizeof(tBTA_SDP_CB)); @@ -78,6 +87,29 @@ tBTA_SDP_STATUS BTA_SdpEnable(tBTA_SDP_DM_CBACK *p_cback) return (status); } + +/******************************************************************************* +** +** Function BTA_SdpDisable +** +** Description Disable the SDP search I/F service. +** Free buffer for SDP configuration structure. +** +** Returns BTA_SDP_SUCCESS if successful. +** BTA_SDP_FAIL if internal failure. +** +*******************************************************************************/ +tBTA_SDP_STATUS BTA_SdpDisable(void) +{ + tBTA_SDP_STATUS status = BTA_SDP_SUCCESS; +#if BTA_DYNAMIC_MEMORY == TRUE + /* Free buffer for SDP configuration structure */ + osi_free(p_bta_sdp_cfg->p_sdp_db); + p_bta_sdp_cfg->p_sdp_db = NULL; +#endif + return (status); +} + /******************************************************************************* ** ** Function BTA_SdpSearch diff --git a/components/bt/bluedroid/bta/sdp/bta_sdp_cfg.c b/components/bt/bluedroid/bta/sdp/bta_sdp_cfg.c index fff5e321a2..322b25caec 100644 --- a/components/bt/bluedroid/bta/sdp/bta_sdp_cfg.c +++ b/components/bt/bluedroid/bta/sdp/bta_sdp_cfg.c @@ -30,12 +30,18 @@ #define BTA_SDP_DB_SIZE 1500 #endif +#if BTA_DYNAMIC_MEMORY == FALSE static UINT8 __attribute__ ((aligned(4))) bta_sdp_db_data[BTA_SDP_DB_SIZE]; +#endif /* SDP configuration structure */ -const tBTA_SDP_CFG bta_sdp_cfg = { +tBTA_SDP_CFG bta_sdp_cfg = { BTA_SDP_DB_SIZE, +#if BTA_DYNAMIC_MEMORY == FALSE (tSDP_DISCOVERY_DB *)bta_sdp_db_data /* The data buffer to keep SDP database */ +#else + NULL +#endif }; tBTA_SDP_CFG *p_bta_sdp_cfg = (tBTA_SDP_CFG *) &bta_sdp_cfg; diff --git a/components/bt/bluedroid/bta/sys/bta_sys_main.c b/components/bt/bluedroid/bta/sys/bta_sys_main.c index e3b8c77fa9..1ea2ccd702 100644 --- a/components/bt/bluedroid/bta/sys/bta_sys_main.c +++ b/components/bt/bluedroid/bta/sys/bta_sys_main.c @@ -29,6 +29,7 @@ #include "osi/alarm.h" #include "osi/thread.h" #include "stack/btm_api.h" +#include "stack/btu.h" #include "bta/bta_api.h" #include "bta/bta_sys.h" #include "bta_sys_int.h" @@ -481,8 +482,10 @@ void bta_sys_hw_evt_stack_enabled(tBTA_SYS_HW_MSG *p_sys_hw_msg) ** Returns void ** *******************************************************************************/ -void bta_sys_event(BT_HDR *p_msg) +void bta_sys_event(void * param) { + BT_HDR *p_msg = (BT_HDR *)param; + UINT8 id; BOOLEAN freebuf = TRUE; @@ -571,7 +574,7 @@ void bta_sys_sendmsg(void *p_msg) // there is a procedure in progress that can schedule a task via this // message queue. This causes |btu_bta_msg_queue| to get cleaned up before // it gets used here; hence we check for NULL before using it. - if (btu_task_post(SIG_BTU_BTA_MSG, p_msg, TASK_POST_BLOCKING) != TASK_POST_SUCCESS) { + if (btu_task_post(SIG_BTU_BTA_MSG, p_msg, OSI_THREAD_MAX_TIMEOUT) == false) { osi_free(p_msg); } } @@ -591,7 +594,7 @@ void bta_alarm_cb(void *data) assert(data != NULL); TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data; - btu_task_post(SIG_BTU_BTA_ALARM, p_tle, TASK_POST_BLOCKING); + btu_task_post(SIG_BTU_BTA_ALARM, p_tle, OSI_THREAD_MAX_TIMEOUT); } void bta_sys_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, INT32 timeout_ms) diff --git a/components/bt/bluedroid/btc/core/btc_ble_storage.c b/components/bt/bluedroid/btc/core/btc_ble_storage.c index c8590ce803..ecbe709364 100644 --- a/components/bt/bluedroid/btc/core/btc_ble_storage.c +++ b/components/bt/bluedroid/btc/core/btc_ble_storage.c @@ -96,6 +96,7 @@ void btc_storage_save(void) btc_config_unlock(); } +#if (BLE_INCLUDED == TRUE) static bt_status_t _btc_storage_add_ble_bonding_key(bt_bdaddr_t *remote_bd_addr, char *key, uint8_t key_type, @@ -552,6 +553,7 @@ bt_status_t btc_storage_remove_ble_dev_type(bt_bdaddr_t *remote_bd_addr, bool fl return ret; } +#endif ///BLE_INCLUDED == TRUE static bt_status_t _btc_storage_set_ble_dev_auth_mode(bt_bdaddr_t *remote_bd_addr, uint8_t auth_mode, bool flush) { @@ -725,6 +727,7 @@ bt_status_t btc_storage_get_remote_addr_type(bt_bdaddr_t *remote_bd_addr, return ret; } +#if (BLE_INCLUDED == TRUE) static void _btc_read_le_key(const uint8_t key_type, const size_t key_len, bt_bdaddr_t bd_addr, const uint8_t addr_type, const bool add_key, bool *device_added, bool *key_found) { @@ -774,7 +777,7 @@ static bt_status_t _btc_storage_in_fetch_bonded_ble_device(const char *remote_bd BTC_TRACE_ERROR("%s, device_type = %x", __func__, device_type); return BT_STATUS_FAIL; } - + string_to_bdaddr(remote_bd_addr, &bd_addr); bdcpy(bta_bd_addr, bd_addr.address); @@ -817,7 +820,7 @@ static bt_status_t btc_storage_in_fetch_bonded_ble_devices(int add) for (const btc_config_section_iter_t *iter = btc_config_section_begin(); iter != btc_config_section_end(); iter = btc_config_section_next(iter)) { const char *name = btc_config_section_name(iter); - + if (!string_is_bdaddr(name) || !btc_config_get_int(name, BTC_BLE_STORAGE_DEV_TYPE_STR, (int *)&device_type) || ((device_type & BT_DEVICE_TYPE_BLE) != BT_DEVICE_TYPE_BLE)) { @@ -926,5 +929,6 @@ int btc_storage_get_num_ble_bond_devices(void) return num_dev; } +#endif ///BLE_INCLUDED == TRUE #endif ///SMP_INCLUDED == TRUE - + diff --git a/components/bt/bluedroid/btc/core/btc_config.c b/components/bt/bluedroid/btc/core/btc_config.c index b987a32e0c..fdababfe08 100644 --- a/components/bt/bluedroid/btc/core/btc_config.c +++ b/components/bt/bluedroid/btc/core/btc_config.c @@ -336,5 +336,4 @@ void btc_config_lock(void) void btc_config_unlock(void) { osi_mutex_unlock(&lock); -} - +} \ No newline at end of file diff --git a/components/bt/bluedroid/btc/core/btc_dm.c b/components/bt/bluedroid/btc/core/btc_dm.c index f3b9caeb42..011d1ff93d 100644 --- a/components/bt/bluedroid/btc/core/btc_dm.c +++ b/components/bt/bluedroid/btc/core/btc_dm.c @@ -41,10 +41,10 @@ /****************************************************************************** ** Static variables ******************************************************************************/ -static tBTA_SERVICE_MASK btc_enabled_services = 0; -#if (SMP_INCLUDED == TRUE) -static btc_dm_pairing_cb_t pairing_cb; -static btc_dm_local_key_cb_t ble_local_key_cb; +#if BTC_DYNAMIC_MENDRY == FALSE +btc_dm_cb_t btc_dm_cb = {0}; +#else +btc_dm_cb_t *btc_dm_cb_ptr; #endif /****************************************************************************** @@ -129,23 +129,24 @@ static void btc_disable_bluetooth_evt(void) } #if (SMP_INCLUDED == TRUE) +#if (BLE_INCLUDED == TRUE) void btc_dm_load_ble_local_keys(void) { - memset(&ble_local_key_cb, 0, sizeof(btc_dm_local_key_cb_t)); + memset(&btc_dm_cb.ble_local_key_cb, 0, sizeof(btc_dm_local_key_cb_t)); - if (btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_ER,(char*)&ble_local_key_cb.er[0], + if (btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_ER,(char*)&btc_dm_cb.ble_local_key_cb.er[0], BT_OCTET16_LEN)== BT_STATUS_SUCCESS) { - ble_local_key_cb.is_er_rcvd = TRUE; + btc_dm_cb.ble_local_key_cb.is_er_rcvd = TRUE; BTC_TRACE_DEBUG("%s BLE ER key loaded",__func__ ); } - if ((btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_IR,(char*)&ble_local_key_cb.id_keys.ir[0], + if ((btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_IR,(char*)&btc_dm_cb.ble_local_key_cb.id_keys.ir[0], BT_OCTET16_LEN)== BT_STATUS_SUCCESS )&& - (btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_IRK, (char*)&ble_local_key_cb.id_keys.irk[0], + (btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_IRK, (char*)&btc_dm_cb.ble_local_key_cb.id_keys.irk[0], BT_OCTET16_LEN)== BT_STATUS_SUCCESS)&& - (btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_DHK,(char*)&ble_local_key_cb.id_keys.dhk[0], + (btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_DHK,(char*)&btc_dm_cb.ble_local_key_cb.id_keys.dhk[0], BT_OCTET16_LEN)== BT_STATUS_SUCCESS)) { - ble_local_key_cb.is_id_keys_rcvd = TRUE; + btc_dm_cb.ble_local_key_cb.is_id_keys_rcvd = TRUE; BTC_TRACE_DEBUG("%s BLE ID keys loaded", __func__); } @@ -153,15 +154,15 @@ void btc_dm_load_ble_local_keys(void) void btc_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er, tBTA_BLE_LOCAL_ID_KEYS *p_id_keys) { - if (ble_local_key_cb.is_er_rcvd ) { - memcpy(&er[0], &ble_local_key_cb.er[0], sizeof(BT_OCTET16)); + if (btc_dm_cb.ble_local_key_cb.is_er_rcvd ) { + memcpy(&er[0], &btc_dm_cb.ble_local_key_cb.er[0], sizeof(BT_OCTET16)); *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ER; } - if (ble_local_key_cb.is_id_keys_rcvd) { - memcpy(&p_id_keys->ir[0], &ble_local_key_cb.id_keys.ir[0], sizeof(BT_OCTET16)); - memcpy(&p_id_keys->irk[0], &ble_local_key_cb.id_keys.irk[0], sizeof(BT_OCTET16)); - memcpy(&p_id_keys->dhk[0], &ble_local_key_cb.id_keys.dhk[0], sizeof(BT_OCTET16)); + if (btc_dm_cb.ble_local_key_cb.is_id_keys_rcvd) { + memcpy(&p_id_keys->ir[0], &btc_dm_cb.ble_local_key_cb.id_keys.ir[0], sizeof(BT_OCTET16)); + memcpy(&p_id_keys->irk[0], &btc_dm_cb.ble_local_key_cb.id_keys.irk[0], sizeof(BT_OCTET16)); + memcpy(&p_id_keys->dhk[0], &btc_dm_cb.ble_local_key_cb.id_keys.dhk[0], sizeof(BT_OCTET16)); *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ID; } BTC_TRACE_DEBUG("%s *p_key_mask=0x%02x",__func__, *p_key_mask); @@ -173,7 +174,7 @@ static void btc_dm_remove_ble_bonding_keys(void) bt_bdaddr_t bd_addr; BTC_TRACE_DEBUG("%s\n",__func__); - bdcpy(bd_addr.address, pairing_cb.bd_addr); + bdcpy(bd_addr.address, btc_dm_cb.pairing_cb.bd_addr); btc_storage_remove_remote_addr_type(&bd_addr, false); btc_storage_remove_ble_dev_auth_mode(&bd_addr, false); @@ -183,64 +184,64 @@ static void btc_dm_remove_ble_bonding_keys(void) static void btc_dm_save_ble_bonding_keys(void) { - if (!(pairing_cb.ble.is_penc_key_rcvd || pairing_cb.ble.is_pid_key_rcvd || pairing_cb.ble.is_pcsrk_key_rcvd || - pairing_cb.ble.is_lenc_key_rcvd || pairing_cb.ble.is_lcsrk_key_rcvd || pairing_cb.ble.is_lidk_key_rcvd)) { + if (!(btc_dm_cb.pairing_cb.ble.is_penc_key_rcvd || btc_dm_cb.pairing_cb.ble.is_pid_key_rcvd || btc_dm_cb.pairing_cb.ble.is_pcsrk_key_rcvd || + btc_dm_cb.pairing_cb.ble.is_lenc_key_rcvd || btc_dm_cb.pairing_cb.ble.is_lcsrk_key_rcvd || btc_dm_cb.pairing_cb.ble.is_lidk_key_rcvd)) { return ; } bt_bdaddr_t bd_addr; - bdcpy(bd_addr.address, pairing_cb.bd_addr); + bdcpy(bd_addr.address, btc_dm_cb.pairing_cb.bd_addr); btc_storage_set_ble_dev_type(&bd_addr, false); - BTC_TRACE_DEBUG("%s, penc = %d, pid = %d", __func__, pairing_cb.ble.is_penc_key_rcvd, pairing_cb.ble.is_pid_key_rcvd); - if (pairing_cb.ble.is_penc_key_rcvd) { + BTC_TRACE_DEBUG("%s, penc = %d, pid = %d", __func__, btc_dm_cb.pairing_cb.ble.is_penc_key_rcvd, btc_dm_cb.pairing_cb.ble.is_pid_key_rcvd); + if (btc_dm_cb.pairing_cb.ble.is_penc_key_rcvd) { btc_storage_add_ble_bonding_key(&bd_addr, - (char *) &pairing_cb.ble.penc_key, + (char *) &btc_dm_cb.pairing_cb.ble.penc_key, BTM_LE_KEY_PENC, sizeof(tBTM_LE_PENC_KEYS)); - pairing_cb.ble.is_penc_key_rcvd = false; + btc_dm_cb.pairing_cb.ble.is_penc_key_rcvd = false; } - if (pairing_cb.ble.is_pid_key_rcvd) { + if (btc_dm_cb.pairing_cb.ble.is_pid_key_rcvd) { btc_storage_add_ble_bonding_key(&bd_addr, - (char *) &pairing_cb.ble.pid_key, + (char *) &btc_dm_cb.pairing_cb.ble.pid_key, BTM_LE_KEY_PID, sizeof(tBTM_LE_PID_KEYS)); - pairing_cb.ble.is_pid_key_rcvd = false; + btc_dm_cb.pairing_cb.ble.is_pid_key_rcvd = false; } - if (pairing_cb.ble.is_pcsrk_key_rcvd) { + if (btc_dm_cb.pairing_cb.ble.is_pcsrk_key_rcvd) { btc_storage_add_ble_bonding_key(&bd_addr, - (char *) &pairing_cb.ble.pcsrk_key, + (char *) &btc_dm_cb.pairing_cb.ble.pcsrk_key, BTM_LE_KEY_PCSRK, sizeof(tBTM_LE_PCSRK_KEYS)); - pairing_cb.ble.is_pcsrk_key_rcvd = false; + btc_dm_cb.pairing_cb.ble.is_pcsrk_key_rcvd = false; } - if (pairing_cb.ble.is_lenc_key_rcvd) { + if (btc_dm_cb.pairing_cb.ble.is_lenc_key_rcvd) { btc_storage_add_ble_bonding_key(&bd_addr, - (char *) &pairing_cb.ble.lenc_key, + (char *) &btc_dm_cb.pairing_cb.ble.lenc_key, BTM_LE_KEY_LENC, sizeof(tBTM_LE_LENC_KEYS)); - pairing_cb.ble.is_lenc_key_rcvd = false; + btc_dm_cb.pairing_cb.ble.is_lenc_key_rcvd = false; } - if (pairing_cb.ble.is_lcsrk_key_rcvd) { + if (btc_dm_cb.pairing_cb.ble.is_lcsrk_key_rcvd) { btc_storage_add_ble_bonding_key(&bd_addr, - (char *) &pairing_cb.ble.lcsrk_key, + (char *) &btc_dm_cb.pairing_cb.ble.lcsrk_key, BTM_LE_KEY_LCSRK, sizeof(tBTM_LE_LCSRK_KEYS)); - pairing_cb.ble.is_lcsrk_key_rcvd = false; + btc_dm_cb.pairing_cb.ble.is_lcsrk_key_rcvd = false; } - if (pairing_cb.ble.is_lidk_key_rcvd) { + if (btc_dm_cb.pairing_cb.ble.is_lidk_key_rcvd) { btc_storage_add_ble_bonding_key(&bd_addr, NULL, BTM_LE_KEY_LID, 0); - pairing_cb.ble.is_lidk_key_rcvd = false; + btc_dm_cb.pairing_cb.ble.is_lidk_key_rcvd = false; } } @@ -252,20 +253,19 @@ static void btc_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl) int addr_type; bt_bdaddr_t bdaddr; bdcpy(bdaddr.address, p_auth_cmpl->bd_addr); - bdcpy(pairing_cb.bd_addr, p_auth_cmpl->bd_addr); + bdcpy(btc_dm_cb.pairing_cb.bd_addr, p_auth_cmpl->bd_addr); if (p_auth_cmpl->success) { status = BT_STATUS_SUCCESS; BTC_TRACE_DEBUG ("%s, - p_auth_cmpl->bd_addr: %08x%04x", __func__, (p_auth_cmpl->bd_addr[0] << 24) + (p_auth_cmpl->bd_addr[1] << 16) + (p_auth_cmpl->bd_addr[2] << 8) + p_auth_cmpl->bd_addr[3], (p_auth_cmpl->bd_addr[4] << 8) + p_auth_cmpl->bd_addr[5]); - BTC_TRACE_DEBUG ("%s, - pairing_cb.bd_addr: %08x%04x", __func__, - (pairing_cb.bd_addr[0] << 24) + (pairing_cb.bd_addr[1] << 16) + (pairing_cb.bd_addr[2] << 8) + pairing_cb.bd_addr[3], - (pairing_cb.bd_addr[4] << 8) + pairing_cb.bd_addr[5]); + // Check if need to save BLE keys if((p_auth_cmpl->auth_mode & SMP_AUTH_GEN_BOND) == 0) { return; } + if (btc_storage_get_remote_addr_type(&bdaddr, &addr_type) != BT_STATUS_SUCCESS) { btc_storage_set_remote_addr_type(&bdaddr, p_auth_cmpl->addr_type, true); } @@ -297,6 +297,7 @@ static void btc_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl) return; } +#endif ///BLE_INCLUDED == TRUE #endif ///SMP_INCLUDED == TRUE static void btc_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl) @@ -487,12 +488,12 @@ static void btc_dm_sp_key_req_evt(tBTA_DM_SP_KEY_REQ *p_key_req) tBTA_SERVICE_MASK btc_get_enabled_services_mask(void) { - return btc_enabled_services; + return btc_dm_cb.btc_enabled_services; } void btc_clear_services_mask(void) { - btc_enabled_services = 0; + btc_dm_cb.btc_enabled_services = 0; } static bt_status_t btc_in_execute_service_request(tBTA_SERVICE_ID service_id, @@ -530,9 +531,9 @@ bt_status_t btc_dm_enable_service(tBTA_SERVICE_ID service_id) { tBTA_SERVICE_ID *p_id = &service_id; - btc_enabled_services |= (1 << service_id); + btc_dm_cb.btc_enabled_services |= (1 << service_id); - BTC_TRACE_DEBUG("%s: current services:0x%x", __FUNCTION__, btc_enabled_services); + BTC_TRACE_DEBUG("%s: current services:0x%x", __FUNCTION__, btc_dm_cb.btc_enabled_services); btc_dm_execute_service_request(TRUE, (char *)p_id); @@ -543,9 +544,9 @@ bt_status_t btc_dm_disable_service(tBTA_SERVICE_ID service_id) { tBTA_SERVICE_ID *p_id = &service_id; - btc_enabled_services &= (tBTA_SERVICE_MASK)(~(1 << service_id)); + btc_dm_cb.btc_enabled_services &= (tBTA_SERVICE_MASK)(~(1 << service_id)); - BTC_TRACE_DEBUG("%s: Current Services:0x%x", __FUNCTION__, btc_enabled_services); + BTC_TRACE_DEBUG("%s: Current Services:0x%x", __FUNCTION__, btc_dm_cb.btc_enabled_services); btc_dm_execute_service_request(FALSE, (char *)p_id); @@ -570,8 +571,10 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg) btc_clear_services_mask(); #if (SMP_INCLUDED == TRUE) btc_storage_load_bonded_devices(); +#if (BLE_INCLUDED == TRUE) //load the bonding device to the btm layer btc_storage_load_bonded_ble_devices(); +#endif ///BLE_INCLUDED == TRUE #endif ///SMP_INCLUDED == TRUE /* Set initial device name, it can be overwritten later */ @@ -634,6 +637,7 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg) #endif /* #if (SMP_INCLUDED == TRUE) */ break; } +#if (BLE_INCLUDED == TRUE) case BTA_DM_BLE_DEV_UNPAIRED_EVT: { #if (SMP_INCLUDED == TRUE) bt_bdaddr_t bd_addr; @@ -655,6 +659,7 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg) #endif /* #if (SMP_INCLUDED == TRUE) */ break; } +#endif ///BLE_INCLUDED == TRUE case BTA_DM_BUSY_LEVEL_EVT: #if (BTC_GAP_BT_INCLUDED == TRUE) { @@ -669,7 +674,7 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg) case BTA_DM_HW_ERROR_EVT: BTC_TRACE_DEBUG( "btc_dm_sec_cback : unhandled event (%d)\n", msg->act ); break; -#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE) && (SMP_INCLUDED == TRUE)) +#if ((BLE_INCLUDED == TRUE) && (SMP_INCLUDED == TRUE)) case BTA_DM_BLE_AUTH_CMPL_EVT: { rsp_app = true; ble_msg.act = ESP_GAP_BLE_AUTH_CMPL_EVT; @@ -693,9 +698,9 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg) switch (p_data->ble_key.key_type) { case BTM_LE_KEY_PENC: { BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_PENC"); - pairing_cb.ble.is_penc_key_rcvd = TRUE; - pairing_cb.ble.penc_key = p_data->ble_key.p_key_value->penc_key; - memcpy(&pairing_cb.ble.penc_key, &p_data->ble_key.p_key_value->penc_key, + btc_dm_cb.pairing_cb.ble.is_penc_key_rcvd = TRUE; + btc_dm_cb.pairing_cb.ble.penc_key = p_data->ble_key.p_key_value->penc_key; + memcpy(&btc_dm_cb.pairing_cb.ble.penc_key, &p_data->ble_key.p_key_value->penc_key, sizeof(tBTM_LE_PENC_KEYS)); memcpy(¶m.ble_security.ble_key.p_key_value.penc_key, &p_data->ble_key.p_key_value->penc_key, sizeof(tBTM_LE_PENC_KEYS)); @@ -703,8 +708,8 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg) } case BTM_LE_KEY_PID: { BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_PID"); - pairing_cb.ble.is_pid_key_rcvd = TRUE; - memcpy(&pairing_cb.ble.pid_key, &p_data->ble_key.p_key_value->pid_key, + btc_dm_cb.pairing_cb.ble.is_pid_key_rcvd = TRUE; + memcpy(&btc_dm_cb.pairing_cb.ble.pid_key, &p_data->ble_key.p_key_value->pid_key, sizeof(tBTM_LE_PID_KEYS)); memcpy(¶m.ble_security.ble_key.p_key_value.pid_key, &p_data->ble_key.p_key_value->pid_key, sizeof(tBTM_LE_PID_KEYS)); @@ -712,8 +717,8 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg) } case BTM_LE_KEY_PCSRK: { BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_PCSRK"); - pairing_cb.ble.is_pcsrk_key_rcvd = TRUE; - memcpy(&pairing_cb.ble.pcsrk_key, &p_data->ble_key.p_key_value->pcsrk_key, + btc_dm_cb.pairing_cb.ble.is_pcsrk_key_rcvd = TRUE; + memcpy(&btc_dm_cb.pairing_cb.ble.pcsrk_key, &p_data->ble_key.p_key_value->pcsrk_key, sizeof(tBTM_LE_PCSRK_KEYS)); memcpy(¶m.ble_security.ble_key.p_key_value.pcsrk_key, &p_data->ble_key.p_key_value->pcsrk_key, sizeof(tBTM_LE_PCSRK_KEYS)); @@ -721,8 +726,8 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg) } case BTM_LE_KEY_LENC: { BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_LENC"); - pairing_cb.ble.is_lenc_key_rcvd = TRUE; - memcpy(&pairing_cb.ble.lenc_key, &p_data->ble_key.p_key_value->lenc_key, + btc_dm_cb.pairing_cb.ble.is_lenc_key_rcvd = TRUE; + memcpy(&btc_dm_cb.pairing_cb.ble.lenc_key, &p_data->ble_key.p_key_value->lenc_key, sizeof(tBTM_LE_LENC_KEYS)); memcpy(¶m.ble_security.ble_key.p_key_value.lenc_key, &p_data->ble_key.p_key_value->lenc_key, sizeof(tBTM_LE_LENC_KEYS)); @@ -730,8 +735,8 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg) } case BTM_LE_KEY_LCSRK: { BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_LCSRK"); - pairing_cb.ble.is_lcsrk_key_rcvd = TRUE; - memcpy(&pairing_cb.ble.lcsrk_key, &p_data->ble_key.p_key_value->lcsrk_key, + btc_dm_cb.pairing_cb.ble.is_lcsrk_key_rcvd = TRUE; + memcpy(&btc_dm_cb.pairing_cb.ble.lcsrk_key, &p_data->ble_key.p_key_value->lcsrk_key, sizeof(tBTM_LE_LCSRK_KEYS)); memcpy(¶m.ble_security.ble_key.p_key_value.lcsrk_key, &p_data->ble_key.p_key_value->lcsrk_key, sizeof(tBTM_LE_LCSRK_KEYS)); @@ -739,7 +744,7 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg) } case BTM_LE_KEY_LID: { BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_LID"); - pairing_cb.ble.is_lidk_key_rcvd = TRUE; + btc_dm_cb.pairing_cb.ble.is_lidk_key_rcvd = TRUE; break; } default: @@ -778,20 +783,20 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg) ble_msg.act = ESP_GAP_BLE_LOCAL_IR_EVT; memcpy(¶m.ble_security.ble_id_keys, &p_data->ble_id_keys, sizeof(tBTA_BLE_LOCAL_ID_KEYS)); BTC_TRACE_DEBUG("BTA_DM_BLE_LOCAL_IR_EVT. "); - ble_local_key_cb.is_id_keys_rcvd = TRUE; - memcpy(&ble_local_key_cb.id_keys.irk[0], + btc_dm_cb.ble_local_key_cb.is_id_keys_rcvd = TRUE; + memcpy(&btc_dm_cb.ble_local_key_cb.id_keys.irk[0], &p_data->ble_id_keys.irk[0], sizeof(BT_OCTET16)); - memcpy(&ble_local_key_cb.id_keys.ir[0], + memcpy(&btc_dm_cb.ble_local_key_cb.id_keys.ir[0], &p_data->ble_id_keys.ir[0], sizeof(BT_OCTET16)); - memcpy(&ble_local_key_cb.id_keys.dhk[0], + memcpy(&btc_dm_cb.ble_local_key_cb.id_keys.dhk[0], &p_data->ble_id_keys.dhk[0], sizeof(BT_OCTET16)); - btc_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.irk[0], + btc_storage_add_ble_local_key( (char *)&btc_dm_cb.ble_local_key_cb.id_keys.irk[0], BTC_LE_LOCAL_KEY_IRK, BT_OCTET16_LEN); - btc_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.ir[0], + btc_storage_add_ble_local_key( (char *)&btc_dm_cb.ble_local_key_cb.id_keys.ir[0], BTC_LE_LOCAL_KEY_IR, BT_OCTET16_LEN); - btc_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.dhk[0], + btc_storage_add_ble_local_key( (char *)&btc_dm_cb.ble_local_key_cb.id_keys.dhk[0], BTC_LE_LOCAL_KEY_DHK, BT_OCTET16_LEN); break; @@ -801,9 +806,9 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg) ble_msg.act = ESP_GAP_BLE_LOCAL_ER_EVT; memcpy(¶m.ble_security.ble_id_keys, &p_data->ble_id_keys, sizeof(tBTA_BLE_LOCAL_ID_KEYS)); BTC_TRACE_DEBUG("BTA_DM_BLE_LOCAL_ER_EVT. "); - ble_local_key_cb.is_er_rcvd = TRUE; - memcpy(&ble_local_key_cb.er[0], &p_data->ble_er[0], sizeof(BT_OCTET16)); - btc_storage_add_ble_local_key( (char *)&ble_local_key_cb.er[0], + btc_dm_cb.ble_local_key_cb.is_er_rcvd = TRUE; + memcpy(&btc_dm_cb.ble_local_key_cb.er[0], &p_data->ble_er[0], sizeof(BT_OCTET16)); + btc_storage_add_ble_local_key( (char *)&btc_dm_cb.ble_local_key_cb.er[0], BTC_LE_LOCAL_KEY_ER, BT_OCTET16_LEN); break; diff --git a/components/bt/bluedroid/btc/core/btc_main.c b/components/bt/bluedroid/btc/core/btc_main.c index 75a2cd45cf..c91aedfb18 100644 --- a/components/bt/bluedroid/btc/core/btc_main.c +++ b/components/bt/bluedroid/btc/core/btc_main.c @@ -64,15 +64,20 @@ static void btc_init_bluetooth(void) bte_main_boot_entry(btc_init_callback); #if (SMP_INCLUDED) btc_config_init(); + +#if (BLE_INCLUDED == TRUE) //load the ble local key which has been stored in the flash btc_dm_load_ble_local_keys(); +#endif ///BLE_INCLUDED == TRUE #endif /* #if (SMP_INCLUDED) */ } static void btc_deinit_bluetooth(void) { +#if (BLE_INCLUDED == TRUE) btc_gap_ble_deinit(); +#endif ///BLE_INCLUDED == TRUE bta_dm_sm_deinit(); #if (GATTC_INCLUDED) bta_gattc_deinit(); diff --git a/components/bt/bluedroid/btc/core/btc_manage.c b/components/bt/bluedroid/btc/core/btc_manage.c index 81ecad4103..08afcb7543 100644 --- a/components/bt/bluedroid/btc/core/btc_manage.c +++ b/components/bt/bluedroid/btc/core/btc_manage.c @@ -19,7 +19,11 @@ #include "esp_bt_defs.h" #include "esp_gatt_defs.h" -static void *btc_profile_cb_tab[BTC_PID_NUM] = {}; +#if BTC_DYNAMIC_MENDRY == FALSE +void *btc_profile_cb_tab[BTC_PID_NUM] = {}; +#else +void **btc_profile_cb_tab; +#endif void esp_profile_cb_reset(void) { diff --git a/components/bt/bluedroid/btc/core/btc_task.c b/components/bt/bluedroid/btc/core/btc_task.c index 86d2b4a63e..df1e1ddfdc 100644 --- a/components/bt/bluedroid/btc/core/btc_task.c +++ b/components/bt/bluedroid/btc/core/btc_task.c @@ -21,16 +21,18 @@ #include "common/bt_defs.h" #include "osi/allocator.h" #include "btc/btc_main.h" +#include "btc/btc_manage.h" #include "btc/btc_dev.h" #include "btc_gatts.h" #include "btc_gattc.h" #include "btc_gatt_common.h" #include "btc_gap_ble.h" #include "btc_blufi_prf.h" +#include "blufi_int.h" #include "btc/btc_dm.h" #include "btc/btc_alarm.h" #include "bta/bta_gatt_api.h" -#if CONFIG_BT_CLASSIC_ENABLED +#if CLASSIC_BT_INCLUDED #include "btc/btc_profile_queue.h" #if (BTC_GAP_BT_INCLUDED == TRUE) #include "btc_gap_bt.h" @@ -38,20 +40,24 @@ #if BTC_AV_INCLUDED #include "btc_av.h" #include "btc_avrc.h" +#include "btc_av_co.h" #endif /* #if BTC_AV_INCLUDED */ -#if CONFIG_BT_SPP_ENABLED +#if (BTC_SPP_INCLUDED == TRUE) #include "btc_spp.h" -#endif /* #if CONFIG_BT_SPP_ENABLED */ +#endif /* #if (BTC_SPP_INCLUDED == TRUE) */ #if BTC_HF_CLIENT_INCLUDED #include "btc_hf_client.h" #endif /* #if BTC_HF_CLIENT_INCLUDED */ -#endif /* #if CONFIG_BT_CLASSIC_ENABLED */ +#endif /* #if CLASSIC_BT_INCLUDED */ +#define BTC_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE) +#define BTC_TASK_STACK_SIZE (BT_BTC_TASK_STACK_SIZE + BT_TASK_EXTRA_STACK_SIZE) //by menuconfig +#define BTC_TASK_NAME "btcT" +#define BTC_TASK_PRIO (BT_TASK_MAX_PRIORITIES - 6) -static xTaskHandle xBtcTaskHandle = NULL; -static xQueueHandle xBtcQueue = 0; +osi_thread_t *btc_thread; -static btc_func_t profile_tab[BTC_PID_NUM] = { +static const btc_func_t profile_tab[BTC_PID_NUM] = { [BTC_PID_MAIN_INIT] = {btc_main_call_handler, NULL }, [BTC_PID_DEV] = {btc_dev_call_handler, NULL }, #if (GATTS_INCLUDED == TRUE) @@ -63,7 +69,11 @@ static btc_func_t profile_tab[BTC_PID_NUM] = { #if (GATTS_INCLUDED == TRUE || GATTC_INCLUDED == TRUE) [BTC_PID_GATT_COMMON] = {btc_gatt_com_call_handler, NULL }, #endif //GATTC_INCLUDED == TRUE || GATTS_INCLUDED == TRUE +#if (BLE_INCLUDED == TRUE) [BTC_PID_GAP_BLE] = {btc_gap_ble_call_handler, btc_gap_ble_cb_handler }, +#else + [BTC_PID_GAP_BLE] = {NULL, NULL}, +#endif ///BLE_INCLUDED == TRUE [BTC_PID_BLE_HID] = {NULL, NULL}, [BTC_PID_SPPLIKE] = {NULL, NULL}, #if (GATTS_INCLUDED == TRUE) @@ -71,7 +81,7 @@ static btc_func_t profile_tab[BTC_PID_NUM] = { #endif ///GATTS_INCLUDED == TRUE [BTC_PID_DM_SEC] = {NULL, btc_dm_sec_cb_handler }, [BTC_PID_ALARM] = {btc_alarm_handler, NULL }, -#if CONFIG_BT_CLASSIC_ENABLED +#if CLASSIC_BT_INCLUDED #if (BTC_GAP_BT_INCLUDED == TRUE) [BTC_PID_GAP_BT] = {btc_gap_bt_call_handler, btc_gap_bt_cb_handler }, #endif /* (BTC_GAP_BT_INCLUDED == TRUE) */ @@ -81,13 +91,13 @@ static btc_func_t profile_tab[BTC_PID_NUM] = { [BTC_PID_AVRC_CT] = {btc_avrc_ct_call_handler, NULL }, [BTC_PID_AVRC_TG] = {btc_avrc_tg_call_handler, NULL }, #endif /* #if BTC_AV_INCLUDED */ -#if CONFIG_BT_SPP_ENABLED +#if (BTC_SPP_INCLUDED == TRUE) [BTC_PID_SPP] = {btc_spp_call_handler, btc_spp_cb_handler }, -#endif /* #if CONFIG_BT_SPP_ENABLED */ +#endif /* #if (BTC_SPP_INCLUDED == TRUE) */ #if BTC_HF_CLIENT_INCLUDED [BTC_PID_HF_CLIENT] = {btc_hf_client_call_handler, btc_hf_client_cb_handler}, #endif /* #if BTC_HF_CLIENT_INCLUDED */ -#endif /* #if CONFIG_BT_CLASSIC_ENABLED */ +#endif /* #if CLASSIC_BT_INCLUDED */ }; /***************************************************************************** @@ -96,38 +106,40 @@ static btc_func_t profile_tab[BTC_PID_NUM] = { ** ** Description Process profile Task Thread. ******************************************************************************/ -static void btc_task(void *arg) +static void btc_thread_handler(void *arg) { - btc_msg_t msg; + btc_msg_t *msg = (btc_msg_t *)arg; - for (;;) { - if (pdTRUE == xQueueReceive(xBtcQueue, &msg, (portTickType)portMAX_DELAY)) { - BTC_TRACE_DEBUG("%s msg %u %u %u %p\n", __func__, msg.sig, msg.pid, msg.act, msg.arg); - switch (msg.sig) { - case BTC_SIG_API_CALL: - profile_tab[msg.pid].btc_call(&msg); - break; - case BTC_SIG_API_CB: - profile_tab[msg.pid].btc_cb(&msg); - break; - default: - break; - } - if (msg.arg) { - osi_free(msg.arg); - } - } + BTC_TRACE_DEBUG("%s msg %u %u %u %p\n", __func__, msg->sig, msg->pid, msg->act, msg->arg); + switch (msg->sig) { + case BTC_SIG_API_CALL: + profile_tab[msg->pid].btc_call(msg); + break; + case BTC_SIG_API_CB: + profile_tab[msg->pid].btc_cb(msg); + break; + default: + break; } + + if (msg->arg) { + osi_free(msg->arg); + } + osi_free(msg); } -static bt_status_t btc_task_post(btc_msg_t *msg, task_post_t timeout) +static bt_status_t btc_task_post(btc_msg_t *msg, uint32_t timeout) { - if (msg == NULL) { - return BT_STATUS_PARM_INVALID; + btc_msg_t *lmsg; + + lmsg = (btc_msg_t *)osi_malloc(sizeof(btc_msg_t)); + if (lmsg == NULL) { + return BT_STATUS_NOMEM; } - if (xQueueSend(xBtcQueue, msg, timeout) != pdTRUE) { - BTC_TRACE_ERROR("Btc Post failed\n"); + memcpy(lmsg, msg, sizeof(btc_msg_t)); + + if (osi_thread_post(btc_thread, btc_thread_handler, lmsg, 2, timeout) == false) { return BT_STATUS_BUSY; } @@ -159,18 +171,144 @@ bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg lmsg.arg = NULL; } - return btc_task_post(&lmsg, TASK_POST_BLOCKING); + return btc_task_post(&lmsg, OSI_THREAD_MAX_TIMEOUT); + } +#if BTC_DYNAMIC_MENDRY + +static void btc_deinit_mem(void) { + if (btc_dm_cb_ptr) { + osi_free(btc_dm_cb_ptr); + btc_dm_cb_ptr = NULL; + } + + if (btc_profile_cb_tab) { + osi_free(btc_profile_cb_tab); + btc_profile_cb_tab = NULL; + } + +#if (BLE_INCLUDED == TRUE) + if (gl_bta_adv_data_ptr) { + osi_free(gl_bta_adv_data_ptr); + gl_bta_adv_data_ptr = NULL; + } + + if (gl_bta_scan_rsp_data_ptr) { + osi_free(gl_bta_scan_rsp_data_ptr); + gl_bta_scan_rsp_data_ptr = NULL; + } +#endif ///BLE_INCLUDED == TRUE + +#if GATTS_INCLUDED == TRUE && GATT_DYNAMIC_MEMORY == TRUE + if (btc_creat_tab_env_ptr) { + osi_free(btc_creat_tab_env_ptr); + btc_creat_tab_env_ptr = NULL; + } + + if (blufi_env_ptr) { + osi_free(blufi_env_ptr); + blufi_env_ptr = NULL; + } +#endif + +#if BTC_HF_CLIENT_INCLUDED == TRUE && HFP_DYNAMIC_MEMORY == TRUE + if (hf_client_local_param_ptr) { + osi_free(hf_client_local_param_ptr); + hf_client_local_param_ptr = NULL; + } +#endif + +#if BTC_AV_INCLUDED == TRUE && AVRC_DYNAMIC_MEMORY == TRUE + if (btc_rc_cb_ptr) { + osi_free(btc_rc_cb_ptr); + btc_rc_cb_ptr = NULL; + } + if (bta_av_co_cb_ptr) { + osi_free(bta_av_co_cb_ptr); + bta_av_co_cb_ptr = NULL; + } +#endif +} + +static bt_status_t btc_init_mem(void) { + if ((btc_dm_cb_ptr = (btc_dm_cb_t *)osi_malloc(sizeof(btc_dm_cb_t))) == NULL) { + goto error_exit; + } + memset((void *)btc_dm_cb_ptr, 0, sizeof(btc_dm_cb_t)); + + if ((btc_profile_cb_tab = (void **)osi_malloc(sizeof(void *) * BTC_PID_NUM)) == NULL) { + goto error_exit; + } + memset((void *)btc_profile_cb_tab, 0, sizeof(void *) * BTC_PID_NUM); + +#if (BLE_INCLUDED == TRUE) + if ((gl_bta_adv_data_ptr = (tBTA_BLE_ADV_DATA *)osi_malloc(sizeof(tBTA_BLE_ADV_DATA))) == NULL) { + goto error_exit; + } + memset((void *)gl_bta_adv_data_ptr, 0, sizeof(tBTA_BLE_ADV_DATA)); + + if ((gl_bta_scan_rsp_data_ptr = (tBTA_BLE_ADV_DATA *)osi_malloc(sizeof(tBTA_BLE_ADV_DATA))) == NULL) { + goto error_exit; + } + memset((void *)gl_bta_scan_rsp_data_ptr, 0, sizeof(tBTA_BLE_ADV_DATA)); +#endif ///BLE_INCLUDED == TRUE + +#if GATTS_INCLUDED == TRUE && GATT_DYNAMIC_MEMORY == TRUE + if ((btc_creat_tab_env_ptr = (esp_btc_creat_tab_t *)osi_malloc(sizeof(esp_btc_creat_tab_t))) == NULL) { + goto error_exit; + } + memset((void *)btc_creat_tab_env_ptr, 0, sizeof(esp_btc_creat_tab_t)); + + if ((blufi_env_ptr = (tBLUFI_ENV *)osi_malloc(sizeof(tBLUFI_ENV))) == NULL) { + goto error_exit; + } + memset((void *)blufi_env_ptr, 0, sizeof(tBLUFI_ENV)); +#endif + +#if BTC_HF_CLIENT_INCLUDED == TRUE && HFP_DYNAMIC_MEMORY == TRUE + if ((hf_client_local_param_ptr = (hf_client_local_param_t *)osi_malloc(sizeof(hf_client_local_param_t))) == NULL) { + goto error_exit; + } + memset((void *)hf_client_local_param_ptr, 0, sizeof(hf_client_local_param_t)); +#endif + +#if BTC_AV_INCLUDED == TRUE && AVRC_DYNAMIC_MEMORY == TRUE + if ((btc_rc_cb_ptr = (btc_rc_cb_t *)osi_malloc(sizeof(btc_rc_cb_t))) == NULL) { + goto error_exit; + } + memset((void *)btc_rc_cb_ptr, 0, sizeof(btc_rc_cb_t)); + if ((bta_av_co_cb_ptr = (tBTA_AV_CO_CB *)osi_malloc(sizeof(tBTA_AV_CO_CB))) == NULL) { + goto error_exit; + } + memset((void *)bta_av_co_cb_ptr, 0, sizeof(tBTA_AV_CO_CB)); +#endif + + return BT_STATUS_SUCCESS; + +error_exit:; + btc_deinit_mem(); + return BT_STATUS_NOMEM; +} +#endif ///BTC_DYNAMIC_MENDRY int btc_init(void) { - xBtcQueue = xQueueCreate(BTC_TASK_QUEUE_LEN, sizeof(btc_msg_t)); - xTaskCreatePinnedToCore(btc_task, "Btc_task", BTC_TASK_STACK_SIZE, NULL, BTC_TASK_PRIO, &xBtcTaskHandle, BTC_TASK_PINNED_TO_CORE); - if (xBtcTaskHandle == NULL || xBtcQueue == 0){ + btc_thread = osi_thread_create("BTC_TASK", BTC_TASK_STACK_SIZE, BTC_TASK_PRIO, BTC_TASK_PINNED_TO_CORE, 3); + if (btc_thread == NULL) { return BT_STATUS_NOMEM; } + +#if BTC_DYNAMIC_MENDRY + if (btc_init_mem() != BT_STATUS_SUCCESS){ + return BT_STATUS_NOMEM; + } +#endif + +#if (BLE_INCLUDED == TRUE) btc_gap_callback_init(); +#endif ///BLE_INCLUDED == TRUE + #if SCAN_QUEUE_CONGEST_CHECK btc_adv_list_init(); #endif @@ -180,20 +318,23 @@ int btc_init(void) void btc_deinit(void) { - vTaskDelete(xBtcTaskHandle); - vQueueDelete(xBtcQueue); +#if BTC_DYNAMIC_MENDRY + btc_deinit_mem(); +#endif + + osi_thread_free(btc_thread); + btc_thread = NULL; + #if SCAN_QUEUE_CONGEST_CHECK btc_adv_list_deinit(); #endif - xBtcTaskHandle = NULL; - xBtcQueue = 0; } bool btc_check_queue_is_congest(void) { - UBaseType_t wait_size = uxQueueMessagesWaiting(xBtcQueue); - if(wait_size >= QUEUE_CONGEST_SIZE) { + if (osi_thread_queue_wait_size(btc_thread, 2) >= QUEUE_CONGEST_SIZE) { return true; } + return false; } diff --git a/components/bt/bluedroid/btc/include/btc/btc_dm.h b/components/bt/bluedroid/btc/include/btc/btc_dm.h index b6e7741ef6..1accc3970b 100644 --- a/components/bt/bluedroid/btc/include/btc/btc_dm.h +++ b/components/bt/bluedroid/btc/include/btc/btc_dm.h @@ -66,7 +66,21 @@ typedef struct btc_dm_local_key_id_t id_keys; /* ID kyes */ } btc_dm_local_key_cb_t; +typedef struct +{ + tBTA_SERVICE_MASK btc_enabled_services; +#if (SMP_INCLUDED == TRUE) + btc_dm_pairing_cb_t pairing_cb; + btc_dm_local_key_cb_t ble_local_key_cb; +#endif +} btc_dm_cb_t; +#if BTC_DYNAMIC_MENDRY == FALSE +extern btc_dm_cb_t btc_dm_cb; +#else +extern btc_dm_cb_t *btc_dm_cb_ptr; +#define btc_dm_cb (*btc_dm_cb_ptr) +#endif // void btc_dm_call_handler(btc_msg_t *msg); void btc_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *data); diff --git a/components/bt/bluedroid/btc/include/btc/btc_manage.h b/components/bt/bluedroid/btc/include/btc/btc_manage.h index 46f746e8df..bd031a0e89 100644 --- a/components/bt/bluedroid/btc/include/btc/btc_manage.h +++ b/components/bt/bluedroid/btc/include/btc/btc_manage.h @@ -19,6 +19,11 @@ #include "btc/btc_task.h" #include "esp_bt_defs.h" +#if BTC_DYNAMIC_MENDRY == FALSE +extern void *btc_profile_cb_tab[BTC_PID_NUM]; +#else +extern void **btc_profile_cb_tab; +#endif /* reset gatt callback table */ void esp_profile_cb_reset(void); diff --git a/components/bt/bluedroid/btc/include/btc/btc_task.h b/components/bt/bluedroid/btc/include/btc/btc_task.h index 2ea76c1772..0ed02d911a 100644 --- a/components/bt/bluedroid/btc/include/btc/btc_task.h +++ b/components/bt/bluedroid/btc/include/btc/btc_task.h @@ -53,17 +53,17 @@ typedef enum { BTC_PID_BLUFI, BTC_PID_DM_SEC, BTC_PID_ALARM, -#if CONFIG_BT_CLASSIC_ENABLED +#if (CLASSIC_BT_INCLUDED == TRUE) BTC_PID_GAP_BT, BTC_PID_PRF_QUE, BTC_PID_A2DP, BTC_PID_AVRC_CT, BTC_PID_AVRC_TG, BTC_PID_SPP, -#if BTC_HF_CLIENT_INCLUDED +#if (BTC_HF_CLIENT_INCLUDED == TRUE) BTC_PID_HF_CLIENT, #endif /* BTC_HF_CLIENT_INCLUDED */ -#endif /* CONFIG_BT_CLASSIC_ENABLED */ +#endif /* CLASSIC_BT_INCLUDED */ BTC_PID_NUM, } btc_pid_t; //btc profile id diff --git a/components/bt/bluedroid/btc/profile/esp/blufi/blufi_prf.c b/components/bt/bluedroid/btc/profile/esp/blufi/blufi_prf.c index 45c220b3ba..25ebba40d8 100644 --- a/components/bt/bluedroid/btc/profile/esp/blufi/blufi_prf.c +++ b/components/bt/bluedroid/btc/profile/esp/blufi/blufi_prf.c @@ -55,13 +55,17 @@ #define BLUFI_HDL_NUM 6 +#if GATT_DYNAMIC_MEMORY == FALSE tBLUFI_ENV blufi_env; +#else +tBLUFI_ENV *blufi_env_ptr; +#endif -static /* const */ tBT_UUID blufi_srvc_uuid = {LEN_UUID_16, {BLUFI_SERVICE_UUID}}; -static /* const */ tBT_UUID blufi_char_uuid_p2e = {LEN_UUID_16, {BLUFI_CHAR_P2E_UUID}}; -static /* const */ tBT_UUID blufi_char_uuid_e2p = {LEN_UUID_16, {BLUFI_CHAR_E2P_UUID}}; -static /* const */ tBT_UUID blufi_descr_uuid_e2p = {LEN_UUID_16, {BLUFI_DESCR_E2P_UUID}}; -static /* const */ tBT_UUID blufi_app_uuid = {LEN_UUID_16, {BLUFI_APP_UUID}}; +static const tBT_UUID blufi_srvc_uuid = {LEN_UUID_16, {BLUFI_SERVICE_UUID}}; +static const tBT_UUID blufi_char_uuid_p2e = {LEN_UUID_16, {BLUFI_CHAR_P2E_UUID}}; +static const tBT_UUID blufi_char_uuid_e2p = {LEN_UUID_16, {BLUFI_CHAR_E2P_UUID}}; +static const tBT_UUID blufi_descr_uuid_e2p = {LEN_UUID_16, {BLUFI_DESCR_E2P_UUID}}; +static const tBT_UUID blufi_app_uuid = {LEN_UUID_16, {BLUFI_APP_UUID}}; // static functions declare static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data); @@ -189,7 +193,7 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) BTA_GATTS_SendRsp(p_data->req_data.conn_id, p_data->req_data.trans_id, p_data->req_data.status, NULL); } - + if (p_data->req_data.p_data->write_req.handle == blufi_env.handle_char_p2e) { btc_blufi_recv_handler(&p_data->req_data.p_data->write_req.value[0], p_data->req_data.p_data->write_req.len); @@ -363,7 +367,7 @@ static void btc_blufi_send_notify(uint8_t *pkt, int pkt_len) UINT16 conn_id = blufi_env.conn_id; UINT16 attr_id = blufi_env.handle_char_e2p; bool rsp = false; - + BTA_GATTS_HandleValueIndication(conn_id, attr_id, pkt_len, pkt, rsp); } @@ -479,7 +483,7 @@ void btc_blufi_send_encap(uint8_t type, uint8_t *data, int total_data_len) hdr->type = type; hdr->fc |= BLUFI_FC_DIR_E2P; hdr->seq = blufi_env.send_seq++; - + if (BLUFI_TYPE_IS_CTRL(hdr->type)) { if ((blufi_env.sec_mode & BLUFI_CTRL_SEC_MODE_CHECK_MASK) && (blufi_env.cbs && blufi_env.cbs->checksum_func)) { @@ -1052,7 +1056,7 @@ void btc_blufi_call_deep_free(btc_msg_t *msg) case BTC_BLUFI_ACT_SEND_CUSTOM_DATA:{ uint8_t *data = arg->custom_data.data; if(data) { - osi_free(data); + osi_free(data); } break; } diff --git a/components/bt/bluedroid/btc/profile/esp/blufi/blufi_protocol.c b/components/bt/bluedroid/btc/profile/esp/blufi/blufi_protocol.c index b962d10051..ab81eac507 100644 --- a/components/bt/bluedroid/btc/profile/esp/blufi/blufi_protocol.c +++ b/components/bt/bluedroid/btc/profile/esp/blufi/blufi_protocol.c @@ -36,7 +36,7 @@ //#include "esp_wifi.h" #if (GATTS_INCLUDED == TRUE) -extern tBLUFI_ENV blufi_env; +// extern tBLUFI_ENV blufi_env; void btc_blufi_protocol_handler(uint8_t type, uint8_t *data, int len) { diff --git a/components/bt/bluedroid/btc/profile/esp/blufi/include/blufi_int.h b/components/bt/bluedroid/btc/profile/esp/blufi/include/blufi_int.h index 08be6703f5..cd6f5a200b 100644 --- a/components/bt/bluedroid/btc/profile/esp/blufi/include/blufi_int.h +++ b/components/bt/bluedroid/btc/profile/esp/blufi/include/blufi_int.h @@ -24,10 +24,10 @@ typedef struct { /* Protocol reference */ tGATT_IF gatt_if; UINT8 srvc_inst; - UINT16 handle_srvc; - UINT16 handle_char_p2e; - UINT16 handle_char_e2p; - UINT16 handle_descr_e2p; + UINT16 handle_srvc; + UINT16 handle_char_p2e; + UINT16 handle_char_e2p; + UINT16 handle_descr_e2p; UINT16 conn_id; BOOLEAN is_connected; BD_ADDR remote_bda; @@ -68,17 +68,24 @@ struct blufi_frag_hdr { }; typedef struct blufi_frag_hdr blufi_frag_hdr_t; -#define BLUFI_DATA_SEC_MODE_CHECK_MASK 0x01 -#define BLUFI_DATA_SEC_MODE_ENC_MASK 0x02 -#define BLUFI_CTRL_SEC_MODE_CHECK_MASK 0x10 +#if GATT_DYNAMIC_MEMORY == FALSE +extern tBLUFI_ENV blufi_env; +#else +extern tBLUFI_ENV *blufi_env_ptr; +#define blufi_env (*blufi_env_ptr) +#endif + +#define BLUFI_DATA_SEC_MODE_CHECK_MASK 0x01 +#define BLUFI_DATA_SEC_MODE_ENC_MASK 0x02 +#define BLUFI_CTRL_SEC_MODE_CHECK_MASK 0x10 #define BLUFI_CTRL_SEC_MODE_ENC_MASK 0x20 #define BLUFI_MAX_DATA_LEN 255 // packet type #define BLUFI_TYPE_MASK 0x03 -#define BLUFI_TYPE_SHIFT 0 +#define BLUFI_TYPE_SHIFT 0 #define BLUFI_SUBTYPE_MASK 0xFC -#define BLUFI_SUBTYPE_SHIFT 2 +#define BLUFI_SUBTYPE_SHIFT 2 #define BLUFI_GET_TYPE(type) ((type) & BLUFI_TYPE_MASK) #define BLUFI_GET_SUBTYPE(type) (((type) & BLUFI_SUBTYPE_MASK) >>BLUFI_SUBTYPE_SHIFT) @@ -161,12 +168,12 @@ typedef struct blufi_frag_hdr blufi_frag_hdr_t; #define BLUFI_FC_REQ_ACK 0x08 #define BLUFI_FC_FRAG 0x10 -#define BLUFI_FC_IS_ENC(fc) ((fc) & BLUFI_FC_ENC_MASK) -#define BLUFI_FC_IS_CHECK(fc) ((fc) & BLUFI_FC_CHECK_MASK) -#define BLUFI_FC_IS_DIR_P2E(fc) ((fc) & BLUFI_FC_DIR_P2E_MASK) -#define BLUFI_FC_IS_DIR_E2P(fc) (!((fc) & BLUFI_DIR_P2E_MASK)) -#define BLUFI_FC_IS_REQ_ACK(fc) ((fc) & BLUFI_FC_REQ_ACK_MASK) -#define BLUFI_FC_IS_FRAG(fc) ((fc) & BLUFI_FC_FRAG_MASK) +#define BLUFI_FC_IS_ENC(fc) ((fc) & BLUFI_FC_ENC_MASK) +#define BLUFI_FC_IS_CHECK(fc) ((fc) & BLUFI_FC_CHECK_MASK) +#define BLUFI_FC_IS_DIR_P2E(fc) ((fc) & BLUFI_FC_DIR_P2E_MASK) +#define BLUFI_FC_IS_DIR_E2P(fc) (!((fc) & BLUFI_DIR_P2E_MASK)) +#define BLUFI_FC_IS_REQ_ACK(fc) ((fc) & BLUFI_FC_REQ_ACK_MASK) +#define BLUFI_FC_IS_FRAG(fc) ((fc) & BLUFI_FC_FRAG_MASK) /* BLUFI HEADER + TOTAL(REMAIN) LENGTH + CRC + L2CAP RESERVED */ #define BLUFI_MTU_RESERVED_SIZE (sizeof(struct blufi_hdr) + 2 + 2 + 3) diff --git a/components/bt/bluedroid/btc/profile/std/a2dp/bta_av_co.c b/components/bt/bluedroid/btc/profile/std/a2dp/bta_av_co.c index 2e72bd8cba..a3250cdac5 100644 --- a/components/bt/bluedroid/btc/profile/std/a2dp/bta_av_co.c +++ b/components/bt/bluedroid/btc/profile/std/a2dp/bta_av_co.c @@ -105,58 +105,12 @@ const tA2D_SBC_CIE btc_av_sbc_default_config = { A2D_SBC_IE_MIN_BITPOOL /* min_bitpool */ }; - -/***************************************************************************** -** Local data -*****************************************************************************/ -typedef struct { - UINT8 sep_info_idx; /* local SEP index (in BTA tables) */ - UINT8 seid; /* peer SEP index (in peer tables) */ - UINT8 codec_type; /* peer SEP codec type */ - UINT8 codec_caps[AVDT_CODEC_SIZE]; /* peer SEP codec capabilities */ - UINT8 num_protect; /* peer SEP number of CP elements */ - UINT8 protect_info[BTA_AV_CP_INFO_LEN]; /* peer SEP content protection info */ -} tBTA_AV_CO_SINK; - -typedef struct { - BD_ADDR addr; /* address of audio/video peer */ - tBTA_AV_CO_SINK snks[BTC_SV_AV_AA_SEP_INDEX]; /* array of supported sinks */ - tBTA_AV_CO_SINK srcs[BTC_SV_AV_AA_SEP_INDEX]; /* array of supported srcs */ - UINT8 num_snks; /* total number of sinks at peer */ - UINT8 num_srcs; /* total number of srcs at peer */ - UINT8 num_seps; /* total number of seids at peer */ - UINT8 num_rx_snks; /* number of received sinks */ - UINT8 num_rx_srcs; /* number of received srcs */ - UINT8 num_sup_snks; /* number of supported sinks in the snks array */ - UINT8 num_sup_srcs; /* number of supported srcs in the srcs array */ - tBTA_AV_CO_SINK *p_snk; /* currently selected sink */ - tBTA_AV_CO_SINK *p_src; /* currently selected src */ - UINT8 codec_cfg[AVDT_CODEC_SIZE]; /* current codec configuration */ - BOOLEAN cp_active; /* current CP configuration */ - BOOLEAN acp; /* acceptor */ - BOOLEAN recfg_needed; /* reconfiguration is needed */ - BOOLEAN opened; /* opened */ - UINT16 mtu; /* maximum transmit unit size */ - UINT16 uuid_to_connect; /* uuid of peer device */ -} tBTA_AV_CO_PEER; - -typedef struct { - BOOLEAN active; - UINT8 flag; -} tBTA_AV_CO_CP; - -typedef struct { - /* Connected peer information */ - tBTA_AV_CO_PEER peers[BTA_AV_NUM_STRS]; - /* Current codec configuration - access to this variable must be protected */ - tBTC_AV_CODEC_INFO codec_cfg; - tBTC_AV_CODEC_INFO codec_cfg_setconfig; /* remote peer setconfig preference */ - - tBTA_AV_CO_CP cp; -} tBTA_AV_CO_CB; - /* Control block instance */ -static tBTA_AV_CO_CB bta_av_co_cb; +#if AVRC_DYNAMIC_MEMORY == FALSE +tBTA_AV_CO_CB bta_av_co_cb; +#else +tBTA_AV_CO_CB *bta_av_co_cb_ptr; +#endif static BOOLEAN bta_av_co_audio_codec_build_config(const UINT8 *p_codec_caps, UINT8 *p_codec_cfg); static void bta_av_co_audio_peer_reset_config(tBTA_AV_CO_PEER *p_peer); @@ -1735,7 +1689,7 @@ BOOLEAN bta_av_co_get_remote_bitpool_pref(UINT8 *min, UINT8 *max) } /* the call out functions for audio stream */ -tBTA_AV_CO_FUNCTS bta_av_a2d_cos = { +const tBTA_AV_CO_FUNCTS bta_av_a2d_cos = { bta_av_co_audio_init, bta_av_co_audio_disc_res, bta_av_co_audio_getconfig, diff --git a/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_sink.c b/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_sink.c index a5d09b2ca1..1a65fbbdcf 100644 --- a/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_sink.c +++ b/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_sink.c @@ -45,6 +45,8 @@ #if (BTC_AV_SINK_INCLUDED == TRUE) +extern osi_thread_t *btc_thread; + /***************************************************************************** ** Constants *****************************************************************************/ @@ -64,10 +66,6 @@ enum { BTC_A2DP_SINK_STATE_SHUTTING_DOWN = 2 }; -enum { - BTC_A2DP_SINK_DATA_EVT = 0, -}; - /* * CONGESTION COMPENSATION CTRL :: * @@ -90,6 +88,11 @@ enum { /* 18 frames is equivalent to 6.89*18*2.9 ~= 360 ms @ 44.1 khz, 20 ms mediatick */ #define MAX_OUTPUT_A2DP_SNK_FRAME_QUEUE_SZ (18) +typedef struct { + uint32_t sig; + void *param; +} a2dp_sink_task_evt_t; + typedef struct { UINT16 num_frames_to_be_processed; UINT16 len; @@ -104,6 +107,15 @@ typedef struct { UINT32 sample_rate; } tBTC_A2DP_SINK_CB; +typedef struct { + tBTC_A2DP_SINK_CB btc_aa_snk_cb; + future_t *btc_a2dp_sink_future; + osi_thread_t *btc_aa_snk_task_hdl; + OI_CODEC_SBC_DECODER_CONTEXT context; + OI_UINT32 contextData[CODEC_DATA_WORDS(2, SBC_CODEC_FAST_FILTER_BUFFERS)]; + OI_INT16 pcmData[15 * SBC_MAX_SAMPLES_PER_FRAME * SBC_MAX_CHANNELS]; +} a2dp_sink_local_param_t; + static void btc_a2dp_sink_thread_init(UNUSED_ATTR void *context); static void btc_a2dp_sink_thread_cleanup(UNUSED_ATTR void *context); static void btc_a2dp_sink_flush_q(fixed_queue_t *p_q); @@ -115,19 +127,19 @@ static void btc_a2dp_sink_handle_inc_media(tBT_SBC_HDR *p_msg); static void btc_a2dp_sink_handle_decoder_reset(tBTC_MEDIA_SINK_CFG_UPDATE *p_msg); static void btc_a2dp_sink_handle_clear_track(void); static BOOLEAN btc_a2dp_sink_clear_track(void); -static void btc_a2dp_sink_task_handler(void *arg); -static void btc_a2dp_sink_data_ready(UNUSED_ATTR void *context); +static void btc_a2dp_sink_ctrl_handler(void *arg); + +static void btc_a2dp_sink_data_ready(void *context); -static tBTC_A2DP_SINK_CB btc_aa_snk_cb; static int btc_a2dp_sink_state = BTC_A2DP_SINK_STATE_OFF; -static future_t *btc_a2dp_sink_future = NULL; -static xTaskHandle btc_aa_snk_task_hdl = NULL; -static QueueHandle_t btc_aa_snk_data_queue = NULL; -static QueueHandle_t btc_aa_snk_ctrl_queue = NULL; -static QueueSetHandle_t btc_aa_snk_queue_set; - static esp_a2d_sink_data_cb_t bt_aa_snk_data_cb = NULL; +#if A2D_DYNAMIC_MEMORY == FALSE +static a2dp_sink_local_param_t a2dp_sink_local_param; +#else +static a2dp_sink_local_param_t *a2dp_sink_local_param_ptr; +#define a2dp_sink_local_param (*a2dp_sink_local_param_ptr) +#endif ///A2D_DYNAMIC_MEMORY == FALSE void btc_a2dp_sink_reg_data_cb(esp_a2d_sink_data_cb_t callback) { @@ -143,21 +155,6 @@ static inline void btc_a2d_data_cb_to_app(const uint8_t *data, uint32_t len) } } -#define BTC_SBC_DEC_CONTEXT_DATA_LEN (CODEC_DATA_WORDS(2, SBC_CODEC_FAST_FILTER_BUFFERS)) -#define BTC_SBC_DEC_PCM_DATA_LEN (15 * SBC_MAX_SAMPLES_PER_FRAME * SBC_MAX_CHANNELS) - -#if BTC_SBC_DEC_DYNAMIC_MEMORY == FALSE -static OI_CODEC_SBC_DECODER_CONTEXT btc_sbc_decoder_context; -static OI_UINT32 btc_sbc_decoder_context_data[BTC_SBC_DEC_CONTEXT_DATA_LEN]; -static OI_INT16 btc_sbc_pcm_data[BTC_SBC_DEC_PCM_DATA_LEN]; -#else -static OI_CODEC_SBC_DECODER_CONTEXT *btc_sbc_decoder_context_ptr; -static OI_UINT32 *btc_sbc_decoder_context_data; -static OI_INT16 *btc_sbc_pcm_data; -#define btc_sbc_decoder_context (*btc_sbc_decoder_context_ptr) -#endif /* BTC_SBC_DEC_DYNAMIC_MEMORY == FALSE */ - - /***************************************************************************** ** Misc helper functions @@ -174,26 +171,28 @@ static inline void btc_a2d_cb_to_app(esp_a2d_cb_event_t event, esp_a2d_cb_param_ ** BTC ADAPTATION *****************************************************************************/ -static void btc_a2dp_sink_ctrl_post(uint32_t sig, void *par) +static bool btc_a2dp_sink_ctrl_post(uint32_t sig, void *param) { - BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t)); + a2dp_sink_task_evt_t *evt = (a2dp_sink_task_evt_t *)osi_malloc(sizeof(a2dp_sink_task_evt_t)); + if (evt == NULL) { - return; + return false; } evt->sig = sig; - evt->par = par; + evt->param = param; - if (xQueueSend(btc_aa_snk_ctrl_queue, &evt, portMAX_DELAY) != pdTRUE) { - APPL_TRACE_WARNING("btc_aa_snk_ctrl_queue failed, sig 0x%x\n", sig); - } + return osi_thread_post(a2dp_sink_local_param.btc_aa_snk_task_hdl, btc_a2dp_sink_ctrl_handler, evt, 0, OSI_THREAD_MAX_TIMEOUT); } -static void btc_a2dp_sink_ctrl_handler(BtTaskEvt_t *e) +static void btc_a2dp_sink_ctrl_handler(void *arg) { + a2dp_sink_task_evt_t *e = (a2dp_sink_task_evt_t *)arg; + if (e == NULL) { return; } + switch (e->sig) { case BTC_MEDIA_TASK_SINK_INIT: btc_a2dp_sink_thread_init(NULL); @@ -202,7 +201,7 @@ static void btc_a2dp_sink_ctrl_handler(BtTaskEvt_t *e) btc_a2dp_sink_thread_cleanup(NULL); break; case BTC_MEDIA_AUDIO_SINK_CFG_UPDATE: - btc_a2dp_sink_handle_decoder_reset(e->par); + btc_a2dp_sink_handle_decoder_reset(e->param); break; case BTC_MEDIA_AUDIO_SINK_CLEAR_TRACK: btc_a2dp_sink_handle_clear_track(); @@ -213,29 +212,12 @@ static void btc_a2dp_sink_ctrl_handler(BtTaskEvt_t *e) default: APPL_TRACE_WARNING("media task unhandled evt: 0x%x\n", e->sig); } - if (e->par != NULL) { - osi_free(e->par); - } -} -static void btc_a2dp_sink_task_handler(void *arg) -{ - QueueSetMemberHandle_t xActivatedMember; - BtTaskEvt_t *e = NULL; - for (;;) { - xActivatedMember = xQueueSelectFromSet(btc_aa_snk_queue_set, portMAX_DELAY); - if (xActivatedMember == btc_aa_snk_data_queue) { - int32_t data_evt; - xQueueReceive(xActivatedMember, &data_evt, 0); - if (data_evt == BTC_A2DP_SINK_DATA_EVT) { - btc_a2dp_sink_data_ready(NULL); - } - } else if (xActivatedMember == btc_aa_snk_ctrl_queue) { - xQueueReceive(xActivatedMember, &e, 0); - btc_a2dp_sink_ctrl_handler(e); - osi_free(e); - } + if (e->param != NULL) { + osi_free(e->param); } + + osi_free(e); } bool btc_a2dp_sink_startup(void) @@ -245,38 +227,21 @@ bool btc_a2dp_sink_startup(void) return false; } +#if A2D_DYNAMIC_MEMORY == TRUE + if ((a2dp_sink_local_param_ptr = (a2dp_sink_local_param_t *)osi_malloc(sizeof(a2dp_sink_local_param_t))) == NULL) { + APPL_TRACE_ERROR("%s malloc failed!", __func__); + return false; + } + memset((void *)a2dp_sink_local_param_ptr, 0, sizeof(a2dp_sink_local_param_t)); +#endif + APPL_TRACE_EVENT("## A2DP SINK START MEDIA THREAD ##"); -#if (BTC_SBC_DEC_DYNAMIC_MEMORY == TRUE) - btc_sbc_decoder_context_ptr = osi_calloc(sizeof(OI_CODEC_SBC_DECODER_CONTEXT)); - btc_sbc_decoder_context_data = osi_calloc(BTC_SBC_DEC_CONTEXT_DATA_LEN * sizeof(OI_UINT32)); - btc_sbc_pcm_data = osi_calloc(BTC_SBC_DEC_PCM_DATA_LEN * sizeof(OI_INT16)); - if (!btc_sbc_decoder_context_ptr || !btc_sbc_decoder_context_data || !btc_sbc_pcm_data) { - APPL_TRACE_ERROR("failed to allocate SBC decoder"); + a2dp_sink_local_param.btc_aa_snk_task_hdl = btc_thread; + + if (btc_a2dp_sink_ctrl_post(BTC_MEDIA_TASK_SINK_INIT, NULL) == false) { goto error_exit; } -#endif /* BTC_SBC_DEC_DYNAMIC_MEMORY == TRUE */ - - btc_aa_snk_queue_set = xQueueCreateSet(BTC_A2DP_SINK_TASK_QUEUE_SET_LEN); - configASSERT(btc_aa_snk_queue_set); - btc_aa_snk_data_queue = xQueueCreate(BTC_A2DP_SINK_DATA_QUEUE_LEN, sizeof(int32_t)); - configASSERT(btc_aa_snk_data_queue); - xQueueAddToSet(btc_aa_snk_data_queue, btc_aa_snk_queue_set); - - btc_aa_snk_ctrl_queue = xQueueCreate(BTC_A2DP_SINK_CTRL_QUEUE_LEN, sizeof(void *)); - configASSERT(btc_aa_snk_ctrl_queue); - xQueueAddToSet(btc_aa_snk_ctrl_queue, btc_aa_snk_queue_set); - - if (!btc_aa_snk_data_queue || !btc_aa_snk_ctrl_queue || !btc_aa_snk_queue_set ) { - goto error_exit; - } - - xTaskCreatePinnedToCore(btc_a2dp_sink_task_handler, BTC_A2DP_SINK_TASK_NAME, BTC_A2DP_SINK_TASK_STACK_SIZE, NULL, BTC_A2DP_SINK_TASK_PRIO, &btc_aa_snk_task_hdl, BTC_A2DP_SINK_TASK_PINNED_TO_CORE); - if (btc_aa_snk_task_hdl == NULL) { - goto error_exit; - } - - btc_a2dp_sink_ctrl_post(BTC_MEDIA_TASK_SINK_INIT, NULL); APPL_TRACE_EVENT("## A2DP SINK MEDIA THREAD STARTED ##\n"); @@ -284,38 +249,12 @@ bool btc_a2dp_sink_startup(void) error_exit:; APPL_TRACE_ERROR("%s unable to start up media thread\n", __func__); + a2dp_sink_local_param.btc_aa_snk_task_hdl = NULL; - if (btc_aa_snk_task_hdl != NULL) { - vTaskDelete(btc_aa_snk_task_hdl); - btc_aa_snk_task_hdl = NULL; - } - - if (btc_aa_snk_data_queue) { - vQueueDelete(btc_aa_snk_data_queue); - btc_aa_snk_data_queue = NULL; - } - if (btc_aa_snk_ctrl_queue) { - vQueueDelete(btc_aa_snk_ctrl_queue); - btc_aa_snk_ctrl_queue = NULL; - } - if (btc_aa_snk_queue_set) { - vQueueDelete(btc_aa_snk_queue_set); - btc_aa_snk_queue_set = NULL; - } -#if (BTC_SBC_DEC_DYNAMIC_MEMORY == TRUE) - if (btc_sbc_decoder_context_ptr) { - osi_free(btc_sbc_decoder_context_ptr); - btc_sbc_decoder_context_ptr = NULL; - } - if (btc_sbc_decoder_context_data) { - osi_free(btc_sbc_decoder_context_data); - btc_sbc_decoder_context_data = NULL; - } - if (btc_sbc_pcm_data) { - osi_free(btc_sbc_pcm_data); - btc_sbc_pcm_data = NULL; - } -#endif /* BTC_SBC_DEC_DYNAMIC_MEMORY == TRUE */ +#if A2D_DYNAMIC_MEMORY == TRUE + osi_free(a2dp_sink_local_param_ptr); + a2dp_sink_local_param_ptr = NULL; +#endif return false; } @@ -326,34 +265,18 @@ void btc_a2dp_sink_shutdown(void) // Exit thread btc_a2dp_sink_state = BTC_A2DP_SINK_STATE_SHUTTING_DOWN; - btc_a2dp_sink_future = future_new(); - assert(btc_a2dp_sink_future); + a2dp_sink_local_param.btc_a2dp_sink_future = future_new(); + assert(a2dp_sink_local_param.btc_a2dp_sink_future); btc_a2dp_sink_ctrl_post(BTC_MEDIA_TASK_SINK_CLEAN_UP, NULL); - future_await(btc_a2dp_sink_future); - btc_a2dp_sink_future = NULL; + future_await(a2dp_sink_local_param.btc_a2dp_sink_future); + a2dp_sink_local_param.btc_a2dp_sink_future = NULL; - vTaskDelete(btc_aa_snk_task_hdl); - btc_aa_snk_task_hdl = NULL; + a2dp_sink_local_param.btc_aa_snk_task_hdl = NULL; - vQueueDelete(btc_aa_snk_data_queue); - btc_aa_snk_data_queue = NULL; - - vQueueDelete(btc_aa_snk_ctrl_queue); - btc_aa_snk_ctrl_queue = NULL; - - vQueueDelete(btc_aa_snk_queue_set); - btc_aa_snk_queue_set = NULL; - -#if (BTC_SBC_DEC_DYNAMIC_MEMORY == TRUE) - osi_free(btc_sbc_decoder_context_ptr); - btc_sbc_decoder_context_ptr = NULL; - - osi_free(btc_sbc_decoder_context_data); - btc_sbc_decoder_context_data = NULL; - - osi_free(btc_sbc_pcm_data); - btc_sbc_pcm_data = NULL; -#endif /* BTC_SBC_DEC_DYNAMIC_MEMORY == TRUE */ +#if A2D_DYNAMIC_MEMORY == TRUE + osi_free(a2dp_sink_local_param_ptr); + a2dp_sink_local_param_ptr = NULL; +#endif } /***************************************************************************** @@ -364,7 +287,7 @@ void btc_a2dp_sink_shutdown(void) void btc_a2dp_sink_on_idle(void) { - btc_aa_snk_cb.rx_flush = TRUE; + a2dp_sink_local_param.btc_aa_snk_cb.rx_flush = TRUE; btc_a2dp_sink_rx_flush_req(); btc_a2dp_sink_clear_track(); @@ -379,7 +302,7 @@ void btc_a2dp_sink_on_idle(void) void btc_a2dp_sink_on_stopped(tBTA_AV_SUSPEND *p_av) { - btc_aa_snk_cb.rx_flush = TRUE; + a2dp_sink_local_param.btc_aa_snk_cb.rx_flush = TRUE; btc_a2dp_sink_rx_flush_req(); btc_a2dp_control_set_datachnl_stat(FALSE); } @@ -392,16 +315,14 @@ void btc_a2dp_sink_on_stopped(tBTA_AV_SUSPEND *p_av) void btc_a2dp_sink_on_suspended(tBTA_AV_SUSPEND *p_av) { - btc_aa_snk_cb.rx_flush = TRUE; + a2dp_sink_local_param.btc_aa_snk_cb.rx_flush = TRUE; btc_a2dp_sink_rx_flush_req(); return; } -static void btc_a2dp_sink_data_post(int32_t data_type) +static void btc_a2dp_sink_data_post(void) { - if (xQueueSend(btc_aa_snk_data_queue, &data_type, 0) != pdTRUE) { - APPL_TRACE_DEBUG("Media data Q filled\n"); - } + osi_thread_post(a2dp_sink_local_param.btc_aa_snk_task_hdl, btc_a2dp_sink_data_ready, NULL, 1, OSI_THREAD_MAX_TIMEOUT); } /******************************************************************************* @@ -415,15 +336,14 @@ static void btc_a2dp_sink_data_post(int32_t data_type) *******************************************************************************/ static BOOLEAN btc_a2dp_sink_clear_track(void) { - btc_a2dp_sink_ctrl_post(BTC_MEDIA_AUDIO_SINK_CLEAR_TRACK, NULL); - return TRUE; + return btc_a2dp_sink_ctrl_post(BTC_MEDIA_AUDIO_SINK_CLEAR_TRACK, NULL); } /* when true media task discards any rx frames */ void btc_a2dp_sink_set_rx_flush(BOOLEAN enable) { APPL_TRACE_EVENT("## DROP RX %d ##\n", enable); - btc_aa_snk_cb.rx_flush = enable; + a2dp_sink_local_param.btc_aa_snk_cb.rx_flush = enable; } /***************************************************************************** @@ -457,20 +377,20 @@ static void btc_a2dp_sink_data_ready(UNUSED_ATTR void *context) { tBT_SBC_HDR *p_msg; - if (fixed_queue_is_empty(btc_aa_snk_cb.RxSbcQ)) { + if (fixed_queue_is_empty(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ)) { APPL_TRACE_DEBUG(" QUE EMPTY "); } else { - if (btc_aa_snk_cb.rx_flush == TRUE) { - btc_a2dp_sink_flush_q(btc_aa_snk_cb.RxSbcQ); + if (a2dp_sink_local_param.btc_aa_snk_cb.rx_flush == TRUE) { + btc_a2dp_sink_flush_q(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ); return; } - while ((p_msg = (tBT_SBC_HDR *)fixed_queue_try_peek_first(btc_aa_snk_cb.RxSbcQ)) != NULL ) { + while ((p_msg = (tBT_SBC_HDR *)fixed_queue_try_peek_first(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ)) != NULL ) { if (btc_a2dp_sink_state != BTC_A2DP_SINK_STATE_ON){ return; } btc_a2dp_sink_handle_inc_media(p_msg); - p_msg = (tBT_SBC_HDR *)fixed_queue_try_dequeue(btc_aa_snk_cb.RxSbcQ); + p_msg = (tBT_SBC_HDR *)fixed_queue_dequeue(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ, 0); if ( p_msg == NULL ) { APPL_TRACE_ERROR("Insufficient data in que "); break; @@ -510,13 +430,13 @@ static void btc_a2dp_sink_handle_decoder_reset(tBTC_MEDIA_SINK_CFG_UPDATE *p_msg return; } - btc_aa_snk_cb.sample_rate = btc_a2dp_sink_get_track_frequency(sbc_cie.samp_freq); - btc_aa_snk_cb.channel_count = btc_a2dp_sink_get_track_channel_count(sbc_cie.ch_mode); + a2dp_sink_local_param.btc_aa_snk_cb.sample_rate = btc_a2dp_sink_get_track_frequency(sbc_cie.samp_freq); + a2dp_sink_local_param.btc_aa_snk_cb.channel_count = btc_a2dp_sink_get_track_channel_count(sbc_cie.ch_mode); - btc_aa_snk_cb.rx_flush = FALSE; + a2dp_sink_local_param.btc_aa_snk_cb.rx_flush = FALSE; APPL_TRACE_EVENT("Reset to sink role"); - status = OI_CODEC_SBC_DecoderReset(&btc_sbc_decoder_context, btc_sbc_decoder_context_data, - BTC_SBC_DEC_CONTEXT_DATA_LEN * sizeof(OI_UINT32), 2, 2, FALSE, FALSE); + status = OI_CODEC_SBC_DecoderReset(&a2dp_sink_local_param.context, a2dp_sink_local_param.contextData, + sizeof(a2dp_sink_local_param.contextData), 2, 2, FALSE, FALSE); if (!OI_SUCCESS(status)) { APPL_TRACE_ERROR("OI_CODEC_SBC_DecoderReset failed with error code %d\n", status); } @@ -632,14 +552,14 @@ static void btc_a2dp_sink_handle_inc_media(tBT_SBC_HDR *p_msg) UINT8 *sbc_start_frame = ((UINT8 *)(p_msg + 1) + p_msg->offset + 1); int count; UINT32 pcmBytes, availPcmBytes; - OI_INT16 *pcmDataPointer = btc_sbc_pcm_data; /*Will be overwritten on next packet receipt*/ + OI_INT16 *pcmDataPointer = a2dp_sink_local_param.pcmData; /*Will be overwritten on next packet receipt*/ OI_STATUS status; int num_sbc_frames = p_msg->num_frames_to_be_processed; UINT32 sbc_frame_len = p_msg->len - 1; - availPcmBytes = BTC_SBC_DEC_PCM_DATA_LEN * sizeof(OI_INT16); + availPcmBytes = sizeof(a2dp_sink_local_param.pcmData); /* XXX: Check if the below check is correct, we are checking for peer to be sink when we are sink */ - if (btc_av_get_peer_sep() == AVDT_TSEP_SNK || (btc_aa_snk_cb.rx_flush)) { + if (btc_av_get_peer_sep() == AVDT_TSEP_SNK || (a2dp_sink_local_param.btc_aa_snk_cb.rx_flush)) { APPL_TRACE_DEBUG(" State Changed happened in this tick "); return; } @@ -653,7 +573,7 @@ static void btc_a2dp_sink_handle_inc_media(tBT_SBC_HDR *p_msg) for (count = 0; count < num_sbc_frames && sbc_frame_len != 0; count ++) { pcmBytes = availPcmBytes; - status = OI_CODEC_SBC_DecodeFrame(&btc_sbc_decoder_context, (const OI_BYTE **)&sbc_start_frame, + status = OI_CODEC_SBC_DecodeFrame(&a2dp_sink_local_param.context, (const OI_BYTE **)&sbc_start_frame, (OI_UINT32 *)&sbc_frame_len, (OI_INT16 *)pcmDataPointer, (OI_UINT32 *)&pcmBytes); @@ -667,7 +587,7 @@ static void btc_a2dp_sink_handle_inc_media(tBT_SBC_HDR *p_msg) p_msg->len = sbc_frame_len + 1; } - btc_a2d_data_cb_to_app((uint8_t *)btc_sbc_pcm_data, (BTC_SBC_DEC_PCM_DATA_LEN * sizeof(OI_INT16) - availPcmBytes)); + btc_a2d_data_cb_to_app((uint8_t *)a2dp_sink_local_param.pcmData, (sizeof(a2dp_sink_local_param.pcmData) - availPcmBytes)); } /******************************************************************************* @@ -681,12 +601,11 @@ static void btc_a2dp_sink_handle_inc_media(tBT_SBC_HDR *p_msg) *******************************************************************************/ BOOLEAN btc_a2dp_sink_rx_flush_req(void) { - if (fixed_queue_is_empty(btc_aa_snk_cb.RxSbcQ) == TRUE) { /* Que is already empty */ + if (fixed_queue_is_empty(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ) == TRUE) { /* Que is already empty */ return TRUE; } - btc_a2dp_sink_ctrl_post(BTC_MEDIA_FLUSH_AA_RX, NULL); - return TRUE; + return btc_a2dp_sink_ctrl_post(BTC_MEDIA_FLUSH_AA_RX, NULL); } /******************************************************************************* @@ -703,7 +622,7 @@ static void btc_a2dp_sink_rx_flush(void) /* Flush all enqueued SBC buffers (encoded) */ APPL_TRACE_DEBUG("btc_a2dp_sink_rx_flush"); - btc_a2dp_sink_flush_q(btc_aa_snk_cb.RxSbcQ); + btc_a2dp_sink_flush_q(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ); } static int btc_a2dp_sink_get_track_frequency(UINT8 frequency) @@ -759,13 +678,13 @@ UINT8 btc_a2dp_sink_enque_buf(BT_HDR *p_pkt) return 0; } - if (btc_aa_snk_cb.rx_flush == TRUE) { /* Flush enabled, do not enque*/ - return fixed_queue_length(btc_aa_snk_cb.RxSbcQ); + if (a2dp_sink_local_param.btc_aa_snk_cb.rx_flush == TRUE) { /* Flush enabled, do not enque*/ + return fixed_queue_length(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ); } - if (fixed_queue_length(btc_aa_snk_cb.RxSbcQ) >= MAX_OUTPUT_A2DP_SNK_FRAME_QUEUE_SZ) { + if (fixed_queue_length(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ) >= MAX_OUTPUT_A2DP_SNK_FRAME_QUEUE_SZ) { APPL_TRACE_WARNING("Pkt dropped\n"); - return fixed_queue_length(btc_aa_snk_cb.RxSbcQ); + return fixed_queue_length(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ); } APPL_TRACE_DEBUG("btc_a2dp_sink_enque_buf + "); @@ -776,13 +695,13 @@ UINT8 btc_a2dp_sink_enque_buf(BT_HDR *p_pkt) memcpy(p_msg, p_pkt, (sizeof(BT_HDR) + p_pkt->offset + p_pkt->len)); p_msg->num_frames_to_be_processed = (*((UINT8 *)(p_msg + 1) + p_msg->offset)) & 0x0f; APPL_TRACE_VERBOSE("btc_a2dp_sink_enque_buf %d + \n", p_msg->num_frames_to_be_processed); - fixed_queue_enqueue(btc_aa_snk_cb.RxSbcQ, p_msg); - btc_a2dp_sink_data_post(BTC_A2DP_SINK_DATA_EVT); + fixed_queue_enqueue(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ, p_msg, FIXED_QUEUE_MAX_TIMEOUT); + btc_a2dp_sink_data_post(); } else { /* let caller deal with a failed allocation */ APPL_TRACE_WARNING("btc_a2dp_sink_enque_buf No Buffer left - "); } - return fixed_queue_length(btc_aa_snk_cb.RxSbcQ); + return fixed_queue_length(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ); } static void btc_a2dp_sink_handle_clear_track (void) @@ -802,18 +721,18 @@ static void btc_a2dp_sink_handle_clear_track (void) static void btc_a2dp_sink_flush_q(fixed_queue_t *p_q) { while (! fixed_queue_is_empty(p_q)) { - osi_free(fixed_queue_try_dequeue(p_q)); + osi_free(fixed_queue_dequeue(p_q, 0)); } } static void btc_a2dp_sink_thread_init(UNUSED_ATTR void *context) { APPL_TRACE_EVENT("%s\n", __func__); - memset(&btc_aa_snk_cb, 0, sizeof(btc_aa_snk_cb)); + memset(&a2dp_sink_local_param.btc_aa_snk_cb, 0, sizeof(a2dp_sink_local_param.btc_aa_snk_cb)); btc_a2dp_sink_state = BTC_A2DP_SINK_STATE_ON; - btc_aa_snk_cb.RxSbcQ = fixed_queue_new(QUEUE_SIZE_MAX); + a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ = fixed_queue_new(QUEUE_SIZE_MAX); btc_a2dp_control_init(); } @@ -826,9 +745,9 @@ static void btc_a2dp_sink_thread_cleanup(UNUSED_ATTR void *context) btc_a2dp_control_cleanup(); - fixed_queue_free(btc_aa_snk_cb.RxSbcQ, osi_free_func); + fixed_queue_free(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ, osi_free_func); - future_ready(btc_a2dp_sink_future, NULL); + future_ready(a2dp_sink_local_param.btc_a2dp_sink_future, NULL); } #endif /* BTC_AV_SINK_INCLUDED */ diff --git a/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_source.c b/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_source.c index 64e563b440..7f1ef366be 100644 --- a/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_source.c +++ b/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_source.c @@ -50,6 +50,8 @@ #if BTC_AV_SRC_INCLUDED +extern osi_thread_t *btc_thread; + /***************************************************************************** ** Constants *****************************************************************************/ @@ -72,9 +74,6 @@ enum { BTC_A2DP_SOURCE_STATE_SHUTTING_DOWN = 2 }; -enum { - BTC_A2DP_SOURCE_DATA_EVT = 1, -}; /* Media task tick in milliseconds, must be set to multiple of (1000/TICKS_PER_SEC) */ @@ -127,6 +126,11 @@ enum { #define MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ (5) #define MAX_OUTPUT_A2DP_SRC_FRAME_QUEUE_SZ (27) // 18 for 20ms tick +typedef struct { + uint32_t sig; + void *param; +} a2dp_src_task_evt_t; + typedef struct { UINT16 num_frames_to_be_processed; UINT16 len; @@ -156,9 +160,17 @@ typedef struct { tBTC_AV_FEEDING_MODE feeding_mode; tBTC_AV_MEDIA_FEEDINGS_STATE media_feeding_state; tBTC_AV_MEDIA_FEEDINGS media_feeding; + SBC_ENC_PARAMS encoder; osi_alarm_t *media_alarm; } tBTC_A2DP_SOURCE_CB; +typedef struct { + tBTC_A2DP_SOURCE_CB btc_aa_src_cb; + future_t *btc_a2dp_source_future; + osi_thread_t *btc_aa_src_task_hdl; + UINT64 last_frame_us; +} a2dp_source_local_param_t; + static void btc_a2dp_source_thread_init(UNUSED_ATTR void *context); static void btc_a2dp_source_thread_cleanup(UNUSED_ATTR void *context); static void btc_a2dp_source_flush_q(fixed_queue_t *p_q); @@ -174,24 +186,16 @@ static void btc_a2dp_source_aa_tx_flush(void); static void btc_a2dp_source_prep_2_send(UINT8 nb_frame); static void btc_a2dp_source_handle_timer(UNUSED_ATTR void *context); static void btc_a2dp_source_encoder_init(void); +static void btc_a2dp_source_ctrl_handler(void *arg); -static tBTC_A2DP_SOURCE_CB btc_aa_src_cb; static int btc_a2dp_source_state = BTC_A2DP_SOURCE_STATE_OFF; -static future_t *btc_a2dp_source_future = NULL; -static xTaskHandle btc_aa_src_task_hdl = NULL; -static QueueHandle_t btc_aa_src_data_queue = NULL; -static QueueHandle_t btc_aa_src_ctrl_queue = NULL; -static QueueSetHandle_t btc_aa_src_queue_set; - static esp_a2d_source_data_cb_t btc_aa_src_data_cb = NULL; -static UINT64 last_frame_us = 0; - -#if BTC_SBC_ENC_DYNAMIC_MEMORY == FALSE -static SBC_ENC_PARAMS btc_sbc_encoder; +#if A2D_DYNAMIC_MEMORY == FALSE +static a2dp_source_local_param_t a2dp_source_local_param; #else -static SBC_ENC_PARAMS *btc_sbc_encoder_ptr; -#define btc_sbc_encoder (*btc_sbc_encoder_ptr) -#endif /* BTC_SBC_ENC_DYNAMIC_MEMORY == FALSE */ +static a2dp_source_local_param_t *a2dp_source_local_param_ptr; +#define a2dp_source_local_param (*a2dp_source_local_param_ptr) +#endif ///A2D_DYNAMIC_MEMORY == FALSE void btc_a2dp_src_reg_data_cb(esp_a2d_source_data_cb_t callback) { @@ -226,7 +230,7 @@ static inline void btc_aa_cb_to_app(esp_a2d_cb_event_t event, esp_a2d_cb_param_t bool btc_a2dp_source_is_streaming(void) { - return btc_aa_src_cb.is_tx_timer == TRUE; + return a2dp_source_local_param.btc_aa_src_cb.is_tx_timer == TRUE; } bool btc_a2dp_source_is_task_shutting_down(void) @@ -234,26 +238,28 @@ bool btc_a2dp_source_is_task_shutting_down(void) return btc_a2dp_source_state == BTC_A2DP_SOURCE_STATE_SHUTTING_DOWN; } -static void btc_a2dp_source_ctrl_post(uint32_t sig, void *par) +static bool btc_a2dp_source_ctrl_post(uint32_t sig, void *param) { - BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t)); + a2dp_src_task_evt_t *evt = (a2dp_src_task_evt_t *)osi_malloc(sizeof(a2dp_src_task_evt_t)); + if (evt == NULL) { - return; + return false; } evt->sig = sig; - evt->par = par; + evt->param = param; - if (xQueueSend(btc_aa_src_ctrl_queue, &evt, portMAX_DELAY) != pdTRUE) { - APPL_TRACE_WARNING("btc_aa_src_ctrl_queue failed, sig 0x%x\n", sig); - } + return osi_thread_post(a2dp_source_local_param.btc_aa_src_task_hdl, btc_a2dp_source_ctrl_handler, evt, 0, OSI_THREAD_MAX_TIMEOUT); } -static void btc_a2dp_source_ctrl_handler(BtTaskEvt_t *e) +static void btc_a2dp_source_ctrl_handler(void *arg) { + a2dp_src_task_evt_t *e = (a2dp_src_task_evt_t *)arg; + if (e == NULL) { return; } + switch (e->sig) { case BTC_MEDIA_TASK_INIT: btc_a2dp_source_thread_init(NULL); @@ -268,13 +274,13 @@ static void btc_a2dp_source_ctrl_handler(BtTaskEvt_t *e) btc_a2dp_source_aa_stop_tx(); break; case BTC_MEDIA_SBC_ENC_INIT: - btc_a2dp_source_enc_init(e->par); + btc_a2dp_source_enc_init(e->param); break; case BTC_MEDIA_SBC_ENC_UPDATE: - btc_a2dp_source_enc_update(e->par); + btc_a2dp_source_enc_update(e->param); break; case BTC_MEDIA_AUDIO_FEEDING_INIT: - btc_a2dp_source_audio_feeding_init(e->par); + btc_a2dp_source_audio_feeding_init(e->param); break; case BTC_MEDIA_FLUSH_AA_TX: btc_a2dp_source_aa_tx_flush(); @@ -282,29 +288,12 @@ static void btc_a2dp_source_ctrl_handler(BtTaskEvt_t *e) default: APPL_TRACE_WARNING("media task unhandled evt: 0x%x\n", e->sig); } - if (e->par != NULL) { - osi_free(e->par); - } -} -static void btc_a2dp_source_task_handler(void *arg) -{ - QueueSetMemberHandle_t xActivatedMember; - BtTaskEvt_t *e = NULL; - for (;;) { - xActivatedMember = xQueueSelectFromSet(btc_aa_src_queue_set, portMAX_DELAY); - if (xActivatedMember == btc_aa_src_data_queue) { - int32_t data_evt; - xQueueReceive(xActivatedMember, &data_evt, 0); - if (data_evt == BTC_A2DP_SOURCE_DATA_EVT) { - btc_a2dp_source_handle_timer(NULL); - } - } else if (xActivatedMember == btc_aa_src_ctrl_queue) { - xQueueReceive(xActivatedMember, &e, 0); - btc_a2dp_source_ctrl_handler(e); - osi_free(e); - } + if (e->param != NULL) { + osi_free(e->param); } + + osi_free(e); } bool btc_a2dp_source_startup(void) @@ -314,36 +303,21 @@ bool btc_a2dp_source_startup(void) return false; } +#if A2D_DYNAMIC_MEMORY == TRUE + if ((a2dp_source_local_param_ptr = (a2dp_source_local_param_t *)osi_malloc(sizeof(a2dp_source_local_param_t))) == NULL) { + APPL_TRACE_ERROR("%s malloc failed!", __func__); + return false; + } + memset((void *)a2dp_source_local_param_ptr, 0, sizeof(a2dp_source_local_param_t)); +#endif + APPL_TRACE_EVENT("## A2DP SOURCE START MEDIA THREAD ##"); -#if BTC_SBC_ENC_DYNAMIC_MEMORY == TRUE - btc_sbc_encoder_ptr = osi_calloc(sizeof(SBC_ENC_PARAMS)); - if (!btc_sbc_encoder_ptr) { - APPL_TRACE_ERROR("failed to allocate SBC encoder"); + a2dp_source_local_param.btc_aa_src_task_hdl = btc_thread; + + if (btc_a2dp_source_ctrl_post(BTC_MEDIA_TASK_INIT, NULL) == false) { goto error_exit; } -#endif /* #if BTC_SBC_ENC_DYNAMIC_MEMORY == TRUE */ - - btc_aa_src_queue_set = xQueueCreateSet(BTC_A2DP_SOURCE_TASK_QUEUE_SET_LEN); - configASSERT(btc_aa_src_queue_set); - btc_aa_src_data_queue = xQueueCreate(BTC_A2DP_SOURCE_DATA_QUEUE_LEN, sizeof(void *)); - configASSERT(btc_aa_src_data_queue); - xQueueAddToSet(btc_aa_src_data_queue, btc_aa_src_queue_set); - - btc_aa_src_ctrl_queue = xQueueCreate(BTC_A2DP_SOURCE_CTRL_QUEUE_LEN, sizeof(void *)); - configASSERT(btc_aa_src_ctrl_queue); - xQueueAddToSet(btc_aa_src_ctrl_queue, btc_aa_src_queue_set); - - if (!btc_aa_src_data_queue || !btc_aa_src_ctrl_queue || !btc_aa_src_queue_set ) { - goto error_exit; - } - - xTaskCreatePinnedToCore(btc_a2dp_source_task_handler, BTC_A2DP_SOURCE_TASK_NAME, BTC_A2DP_SOURCE_TASK_STACK_SIZE, NULL, BTC_A2DP_SOURCE_TASK_PRIO, &btc_aa_src_task_hdl, BTC_A2DP_SOURCE_TASK_PINNED_TO_CORE); - if (btc_aa_src_task_hdl == NULL) { - goto error_exit; - } - - btc_a2dp_source_ctrl_post(BTC_MEDIA_TASK_INIT, NULL); APPL_TRACE_EVENT("## A2DP SOURCE MEDIA THREAD STARTED ##\n"); @@ -351,30 +325,13 @@ bool btc_a2dp_source_startup(void) error_exit:; APPL_TRACE_ERROR("%s unable to start up media thread\n", __func__); + a2dp_source_local_param.btc_aa_src_task_hdl = NULL; - if (btc_aa_src_task_hdl != NULL) { - vTaskDelete(btc_aa_src_task_hdl); - btc_aa_src_task_hdl = NULL; - } +#if A2D_DYNAMIC_MEMORY == TRUE + osi_free(a2dp_source_local_param_ptr); + a2dp_source_local_param_ptr = NULL; +#endif - if (btc_aa_src_data_queue) { - vQueueDelete(btc_aa_src_data_queue); - btc_aa_src_data_queue = NULL; - } - if (btc_aa_src_ctrl_queue) { - vQueueDelete(btc_aa_src_ctrl_queue); - btc_aa_src_ctrl_queue = NULL; - } - if (btc_aa_src_queue_set) { - vQueueDelete(btc_aa_src_queue_set); - btc_aa_src_queue_set = NULL; - } -#if (BTC_SBC_ENC_DYNAMIC_MEMORY == TRUE) - if (btc_sbc_encoder_ptr) { - osi_free(btc_sbc_encoder_ptr); - btc_sbc_encoder_ptr = NULL; - } -#endif /* #if BTC_SBC_ENC_DYNAMIC_MEMORY == TRUE */ return false; } @@ -384,28 +341,18 @@ void btc_a2dp_source_shutdown(void) // Exit thread btc_a2dp_source_state = BTC_A2DP_SOURCE_STATE_SHUTTING_DOWN; - btc_a2dp_source_future = future_new(); - assert(btc_a2dp_source_future); + a2dp_source_local_param.btc_a2dp_source_future = future_new(); + assert(a2dp_source_local_param.btc_a2dp_source_future); btc_a2dp_source_ctrl_post(BTC_MEDIA_TASK_CLEAN_UP, NULL); - future_await(btc_a2dp_source_future); - btc_a2dp_source_future = NULL; + future_await(a2dp_source_local_param.btc_a2dp_source_future); + a2dp_source_local_param.btc_a2dp_source_future = NULL; - vTaskDelete(btc_aa_src_task_hdl); - btc_aa_src_task_hdl = NULL; + a2dp_source_local_param.btc_aa_src_task_hdl = NULL; - vQueueDelete(btc_aa_src_data_queue); - btc_aa_src_data_queue = NULL; - - vQueueDelete(btc_aa_src_ctrl_queue); - btc_aa_src_ctrl_queue = NULL; - - vQueueDelete(btc_aa_src_queue_set); - btc_aa_src_queue_set = NULL; - -#if (BTC_SBC_ENC_DYNAMIC_MEMORY == TRUE) - osi_free(btc_sbc_encoder_ptr); - btc_sbc_encoder_ptr = NULL; -#endif /* #if BTC_SBC_ENC_DYNAMIC_MEMORY == TRUE */ +#if A2D_DYNAMIC_MEMORY == TRUE + osi_free(a2dp_source_local_param_ptr); + a2dp_source_local_param_ptr = NULL; +#endif } /***************************************************************************** @@ -438,7 +385,7 @@ void btc_a2dp_source_on_stopped(tBTA_AV_SUSPEND *p_av) } /* ensure tx frames are immediately suspended */ - btc_aa_src_cb.tx_flush = 1; + a2dp_source_local_param.btc_aa_src_cb.tx_flush = 1; /* request to stop media task */ btc_a2dp_source_tx_flush_req(); @@ -466,17 +413,15 @@ void btc_a2dp_source_on_suspended(tBTA_AV_SUSPEND *p_av) /* once stream is fully stopped we will ack back */ /* ensure tx frames are immediately flushed */ - btc_aa_src_cb.tx_flush = 1; + a2dp_source_local_param.btc_aa_src_cb.tx_flush = 1; /* stop timer tick */ btc_a2dp_source_stop_audio_req(); } -static void btc_a2dp_source_data_post(int32_t data_type) +static void btc_a2dp_source_data_post(void) { - if (xQueueSend(btc_aa_src_data_queue, &data_type, 0) != pdTRUE) { - APPL_TRACE_DEBUG("Media data Q filled\n"); - } + osi_thread_post(a2dp_source_local_param.btc_aa_src_task_hdl, btc_a2dp_source_handle_timer, NULL, 1, OSI_THREAD_MAX_TIMEOUT); } static UINT64 time_now_us() @@ -497,7 +442,7 @@ static void log_tstamps_us(char *comment) static UINT64 prev_us = 0; UINT64 now_us = time_now_us(); APPL_TRACE_DEBUG("[%s] ts %08llu, diff : %08llu, queue sz %d", comment, now_us, now_us - prev_us, - fixed_queue_length(btc_aa_src_cb.TxAaQ)); + fixed_queue_length(a2dp_source_local_param.btc_aa_src_cb.TxAaQ)); prev_us = now_us; UNUSED(prev_us); } @@ -506,7 +451,7 @@ static void log_tstamps_us(char *comment) void btc_a2dp_source_set_tx_flush(BOOLEAN enable) { APPL_TRACE_EVENT("## DROP TX %d ##", enable); - btc_aa_src_cb.tx_flush = enable; + a2dp_source_local_param.btc_aa_src_cb.tx_flush = enable; } /***************************************************************************** @@ -565,7 +510,7 @@ BT_HDR *btc_a2dp_source_audio_readbuf(void) if (btc_a2dp_source_state != BTC_A2DP_SOURCE_STATE_ON){ return NULL; } - return fixed_queue_try_dequeue(btc_aa_src_cb.TxAaQ); + return fixed_queue_dequeue(a2dp_source_local_param.btc_aa_src_cb.TxAaQ, 0); } /******************************************************************************* @@ -604,9 +549,13 @@ BOOLEAN btc_a2dp_source_stop_audio_req(void) * the "cleanup() -> btc_a2dp_stop_media_task()" processing during * the shutdown of the Bluetooth stack. */ +#if 0 if (btc_aa_src_ctrl_queue != NULL) { +#endif btc_a2dp_source_ctrl_post(BTC_MEDIA_STOP_AA_TX, NULL); +#if 0 } +#endif return TRUE; } @@ -696,9 +645,13 @@ BOOLEAN btc_a2dp_source_tx_flush_req(void) * the "cleanup() -> btc_a2dp_stop_media_task()" processing during * the shutdown of the Bluetooth stack. */ +#if 0 if (btc_aa_src_ctrl_queue != NULL) { +#endif btc_a2dp_source_ctrl_post(BTC_MEDIA_FLUSH_AA_TX, NULL); +#if 0 } +#endif return TRUE; } @@ -817,35 +770,35 @@ static void btc_a2dp_source_enc_init(BT_HDR *p_msg) APPL_TRACE_DEBUG("btc_a2dp_source_enc_init"); - btc_aa_src_cb.timestamp = 0; + a2dp_source_local_param.btc_aa_src_cb.timestamp = 0; /* SBC encoder config (enforced even if not used) */ - btc_sbc_encoder.sbc_mode = SBC_MODE_STD; - btc_sbc_encoder.s16ChannelMode = pInitAudio->ChannelMode; - btc_sbc_encoder.s16NumOfSubBands = pInitAudio->NumOfSubBands; - btc_sbc_encoder.s16NumOfBlocks = pInitAudio->NumOfBlocks; - btc_sbc_encoder.s16AllocationMethod = pInitAudio->AllocationMethod; - btc_sbc_encoder.s16SamplingFreq = pInitAudio->SamplingFreq; + a2dp_source_local_param.btc_aa_src_cb.encoder.sbc_mode = SBC_MODE_STD; + a2dp_source_local_param.btc_aa_src_cb.encoder.s16ChannelMode = pInitAudio->ChannelMode; + a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfSubBands = pInitAudio->NumOfSubBands; + a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfBlocks = pInitAudio->NumOfBlocks; + a2dp_source_local_param.btc_aa_src_cb.encoder.s16AllocationMethod = pInitAudio->AllocationMethod; + a2dp_source_local_param.btc_aa_src_cb.encoder.s16SamplingFreq = pInitAudio->SamplingFreq; - btc_sbc_encoder.u16BitRate = btc_a2dp_source_get_sbc_rate(); + a2dp_source_local_param.btc_aa_src_cb.encoder.u16BitRate = btc_a2dp_source_get_sbc_rate(); /* Default transcoding is PCM to SBC, modified by feeding configuration */ - btc_aa_src_cb.TxTranscoding = BTC_MEDIA_TRSCD_PCM_2_SBC; - btc_aa_src_cb.TxAaMtuSize = ((BTC_MEDIA_AA_BUF_SIZE - BTC_MEDIA_AA_SBC_OFFSET - sizeof(BT_HDR)) + a2dp_source_local_param.btc_aa_src_cb.TxTranscoding = BTC_MEDIA_TRSCD_PCM_2_SBC; + a2dp_source_local_param.btc_aa_src_cb.TxAaMtuSize = ((BTC_MEDIA_AA_BUF_SIZE - BTC_MEDIA_AA_SBC_OFFSET - sizeof(BT_HDR)) < pInitAudio->MtuSize) ? (BTC_MEDIA_AA_BUF_SIZE - BTC_MEDIA_AA_SBC_OFFSET - sizeof(BT_HDR)) : pInitAudio->MtuSize; APPL_TRACE_EVENT("btc_a2dp_source_enc_init mtu %d, peer mtu %d", - btc_aa_src_cb.TxAaMtuSize, pInitAudio->MtuSize); + a2dp_source_local_param.btc_aa_src_cb.TxAaMtuSize, pInitAudio->MtuSize); APPL_TRACE_EVENT(" ch mode %d, subnd %d, nb blk %d, alloc %d, rate %d, freq %d", - btc_sbc_encoder.s16ChannelMode, btc_sbc_encoder.s16NumOfSubBands, - btc_sbc_encoder.s16NumOfBlocks, - btc_sbc_encoder.s16AllocationMethod, btc_sbc_encoder.u16BitRate, - btc_sbc_encoder.s16SamplingFreq); + a2dp_source_local_param.btc_aa_src_cb.encoder.s16ChannelMode, a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfSubBands, + a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfBlocks, + a2dp_source_local_param.btc_aa_src_cb.encoder.s16AllocationMethod, a2dp_source_local_param.btc_aa_src_cb.encoder.u16BitRate, + a2dp_source_local_param.btc_aa_src_cb.encoder.s16SamplingFreq); /* Reset entirely the SBC encoder */ - SBC_Encoder_Init(&(btc_sbc_encoder)); - APPL_TRACE_DEBUG("btc_a2dp_source_enc_init bit pool %d", btc_sbc_encoder.s16BitPool); + SBC_Encoder_Init(&(a2dp_source_local_param.btc_aa_src_cb.encoder)); + APPL_TRACE_DEBUG("btc_a2dp_source_enc_init bit pool %d", a2dp_source_local_param.btc_aa_src_cb.encoder.s16BitPool); } @@ -862,7 +815,7 @@ static void btc_a2dp_source_enc_init(BT_HDR *p_msg) static void btc_a2dp_source_enc_update(BT_HDR *p_msg) { tBTC_MEDIA_UPDATE_AUDIO *pUpdateAudio = (tBTC_MEDIA_UPDATE_AUDIO *) p_msg; - SBC_ENC_PARAMS *pstrEncParams = &btc_sbc_encoder; + SBC_ENC_PARAMS *pstrEncParams = &a2dp_source_local_param.btc_aa_src_cb.encoder; UINT16 s16SamplingFreq; SINT16 s16BitPool = 0; SINT16 s16BitRate; @@ -873,9 +826,9 @@ static void btc_a2dp_source_enc_update(BT_HDR *p_msg) pUpdateAudio->MinMtuSize, pUpdateAudio->MaxBitPool, pUpdateAudio->MinBitPool); /* Only update the bitrate and MTU size while timer is running to make sure it has been initialized */ - //if (btc_aa_src_cb.is_tx_timer) + //if (a2dp_source_local_param.btc_aa_src_cb.is_tx_timer) { - btc_aa_src_cb.TxAaMtuSize = ((BTC_MEDIA_AA_BUF_SIZE - + a2dp_source_local_param.btc_aa_src_cb.TxAaMtuSize = ((BTC_MEDIA_AA_BUF_SIZE - BTC_MEDIA_AA_SBC_OFFSET - sizeof(BT_HDR)) < pUpdateAudio->MinMtuSize) ? (BTC_MEDIA_AA_BUF_SIZE - BTC_MEDIA_AA_SBC_OFFSET - sizeof(BT_HDR)) : pUpdateAudio->MinMtuSize; @@ -954,19 +907,19 @@ static void btc_a2dp_source_enc_update(BT_HDR *p_msg) if (s16BitPool > pUpdateAudio->MaxBitPool) { APPL_TRACE_DEBUG("%s computed bitpool too large (%d)", __FUNCTION__, s16BitPool); /* Decrease bitrate */ - btc_sbc_encoder.u16BitRate -= BTC_MEDIA_BITRATE_STEP; + a2dp_source_local_param.btc_aa_src_cb.encoder.u16BitRate -= BTC_MEDIA_BITRATE_STEP; /* Record that we have decreased the bitrate */ protect |= 1; } else if (s16BitPool < pUpdateAudio->MinBitPool) { APPL_TRACE_WARNING("%s computed bitpool too small (%d)", __FUNCTION__, s16BitPool); /* Increase bitrate */ - UINT16 previous_u16BitRate = btc_sbc_encoder.u16BitRate; - btc_sbc_encoder.u16BitRate += BTC_MEDIA_BITRATE_STEP; + UINT16 previous_u16BitRate = a2dp_source_local_param.btc_aa_src_cb.encoder.u16BitRate; + a2dp_source_local_param.btc_aa_src_cb.encoder.u16BitRate += BTC_MEDIA_BITRATE_STEP; /* Record that we have increased the bitrate */ protect |= 2; /* Check over-flow */ - if (btc_sbc_encoder.u16BitRate < previous_u16BitRate) { + if (a2dp_source_local_param.btc_aa_src_cb.encoder.u16BitRate < previous_u16BitRate) { protect |= 3; } } else { @@ -983,10 +936,10 @@ static void btc_a2dp_source_enc_update(BT_HDR *p_msg) pstrEncParams->s16BitPool = s16BitPool; APPL_TRACE_DEBUG("%s final bit rate %d, final bit pool %d", __FUNCTION__, - btc_sbc_encoder.u16BitRate, btc_sbc_encoder.s16BitPool); + a2dp_source_local_param.btc_aa_src_cb.encoder.u16BitRate, a2dp_source_local_param.btc_aa_src_cb.encoder.s16BitPool); /* make sure we reinitialize encoder with new settings */ - SBC_Encoder_Init(&(btc_sbc_encoder)); + SBC_Encoder_Init(&(a2dp_source_local_param.btc_aa_src_cb.encoder)); } } @@ -1017,10 +970,10 @@ static void btc_a2dp_source_pcm2sbc_init(tBTC_MEDIA_INIT_AUDIO_FEEDING *p_feedin case 32000: case 48000: /* For these sampling_freq the AV connection must be 48000 */ - if (btc_sbc_encoder.s16SamplingFreq != SBC_sf48000) { + if (a2dp_source_local_param.btc_aa_src_cb.encoder.s16SamplingFreq != SBC_sf48000) { /* Reconfiguration needed at 48000 */ APPL_TRACE_DEBUG("SBC Reconfiguration needed at 48000"); - btc_sbc_encoder.s16SamplingFreq = SBC_sf48000; + a2dp_source_local_param.btc_aa_src_cb.encoder.s16SamplingFreq = SBC_sf48000; reconfig_needed = TRUE; } break; @@ -1029,10 +982,10 @@ static void btc_a2dp_source_pcm2sbc_init(tBTC_MEDIA_INIT_AUDIO_FEEDING *p_feedin case 22050: case 44100: /* For these sampling_freq the AV connection must be 44100 */ - if (btc_sbc_encoder.s16SamplingFreq != SBC_sf44100) { + if (a2dp_source_local_param.btc_aa_src_cb.encoder.s16SamplingFreq != SBC_sf44100) { /* Reconfiguration needed at 44100 */ APPL_TRACE_DEBUG("SBC Reconfiguration needed at 44100"); - btc_sbc_encoder.s16SamplingFreq = SBC_sf44100; + a2dp_source_local_param.btc_aa_src_cb.encoder.s16SamplingFreq = SBC_sf44100; reconfig_needed = TRUE; } break; @@ -1042,21 +995,21 @@ static void btc_a2dp_source_pcm2sbc_init(tBTC_MEDIA_INIT_AUDIO_FEEDING *p_feedin } /* Some AV Headsets do not support Mono => always ask for Stereo */ - if (btc_sbc_encoder.s16ChannelMode == SBC_MONO) { + if (a2dp_source_local_param.btc_aa_src_cb.encoder.s16ChannelMode == SBC_MONO) { APPL_TRACE_DEBUG("SBC Reconfiguration needed in Stereo"); - btc_sbc_encoder.s16ChannelMode = SBC_JOINT_STEREO; + a2dp_source_local_param.btc_aa_src_cb.encoder.s16ChannelMode = SBC_JOINT_STEREO; reconfig_needed = TRUE; } if (reconfig_needed != FALSE) { - APPL_TRACE_DEBUG("%s :: mtu %d", __FUNCTION__, btc_aa_src_cb.TxAaMtuSize); + APPL_TRACE_DEBUG("%s :: mtu %d", __FUNCTION__, a2dp_source_local_param.btc_aa_src_cb.TxAaMtuSize); APPL_TRACE_DEBUG("ch mode %d, nbsubd %d, nb %d, alloc %d, rate %d, freq %d", - btc_sbc_encoder.s16ChannelMode, - btc_sbc_encoder.s16NumOfSubBands, btc_sbc_encoder.s16NumOfBlocks, - btc_sbc_encoder.s16AllocationMethod, btc_sbc_encoder.u16BitRate, - btc_sbc_encoder.s16SamplingFreq); + a2dp_source_local_param.btc_aa_src_cb.encoder.s16ChannelMode, + a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfSubBands, a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfBlocks, + a2dp_source_local_param.btc_aa_src_cb.encoder.s16AllocationMethod, a2dp_source_local_param.btc_aa_src_cb.encoder.u16BitRate, + a2dp_source_local_param.btc_aa_src_cb.encoder.s16SamplingFreq); - SBC_Encoder_Init(&(btc_sbc_encoder)); + SBC_Encoder_Init(&(a2dp_source_local_param.btc_aa_src_cb.encoder)); } else { APPL_TRACE_DEBUG("%s no SBC reconfig needed", __FUNCTION__); } @@ -1078,13 +1031,13 @@ static void btc_a2dp_source_audio_feeding_init(BT_HDR *p_msg) APPL_TRACE_DEBUG("%s format:%d", __FUNCTION__, p_feeding->feeding.format); /* Save Media Feeding information */ - btc_aa_src_cb.feeding_mode = p_feeding->feeding_mode; - btc_aa_src_cb.media_feeding = p_feeding->feeding; + a2dp_source_local_param.btc_aa_src_cb.feeding_mode = p_feeding->feeding_mode; + a2dp_source_local_param.btc_aa_src_cb.media_feeding = p_feeding->feeding; /* Handle different feeding formats */ switch (p_feeding->feeding.format) { case BTC_AV_CODEC_PCM: - btc_aa_src_cb.TxTranscoding = BTC_MEDIA_TRSCD_PCM_2_SBC; + a2dp_source_local_param.btc_aa_src_cb.TxTranscoding = BTC_MEDIA_TRSCD_PCM_2_SBC; btc_a2dp_source_pcm2sbc_init(p_feeding); break; @@ -1108,10 +1061,10 @@ static void btc_a2dp_source_aa_tx_flush(void) /* Flush all enqueued music buffers (encoded) */ APPL_TRACE_DEBUG("%s", __FUNCTION__); - btc_aa_src_cb.media_feeding_state.pcm.counter = 0; - btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue = 0; + a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.counter = 0; + a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue = 0; - btc_a2dp_source_flush_q(btc_aa_src_cb.TxAaQ); + btc_a2dp_source_flush_q(a2dp_source_local_param.btc_aa_src_cb.TxAaQ); btc_aa_src_data_read(NULL, -1); } @@ -1129,35 +1082,35 @@ static UINT8 btc_get_num_aa_frame(void) { UINT8 result = 0; - switch (btc_aa_src_cb.TxTranscoding) { + switch (a2dp_source_local_param.btc_aa_src_cb.TxTranscoding) { case BTC_MEDIA_TRSCD_PCM_2_SBC: { - UINT32 pcm_bytes_per_frame = btc_sbc_encoder.s16NumOfSubBands * - btc_sbc_encoder.s16NumOfBlocks * - btc_aa_src_cb.media_feeding.cfg.pcm.num_channel * - btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample / 8; + UINT32 pcm_bytes_per_frame = a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfSubBands * + a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfBlocks * + a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.num_channel * + a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample / 8; UINT32 us_this_tick = BTC_MEDIA_TIME_TICK_MS * 1000; UINT64 now_us = time_now_us(); - if (last_frame_us != 0) { + if (a2dp_source_local_param.last_frame_us != 0) { #if _POSIX_TIMERS - us_this_tick = (now_us - last_frame_us); + us_this_tick = (now_us - a2dp_source_local_param.last_frame_us); #else // consider the case that the number of day increases and timeofday wraps around - us_this_tick = (now_us > last_frame_us) ? (now_us - last_frame_us) : - (now_us + 86400000000ull - last_frame_us); + us_this_tick = (now_us > a2dp_source_local_param.last_frame_us) ? (now_us - a2dp_source_local_param.last_frame_us) : + (now_us + 86400000000ull - a2dp_source_local_param.last_frame_us); #endif } - last_frame_us = now_us; + a2dp_source_local_param.last_frame_us = now_us; - btc_aa_src_cb.media_feeding_state.pcm.counter += - btc_aa_src_cb.media_feeding_state.pcm.bytes_per_tick * + a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.counter += + a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.bytes_per_tick * us_this_tick / (BTC_MEDIA_TIME_TICK_MS * 1000); /* calculate nbr of frames pending for this media tick */ - result = btc_aa_src_cb.media_feeding_state.pcm.counter / pcm_bytes_per_frame; + result = a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.counter / pcm_bytes_per_frame; /* limit the frames to be sent */ - UINT32 frm_nb_threshold = MAX_OUTPUT_A2DP_SRC_FRAME_QUEUE_SZ - fixed_queue_length(btc_aa_src_cb.TxAaQ); + UINT32 frm_nb_threshold = MAX_OUTPUT_A2DP_SRC_FRAME_QUEUE_SZ - fixed_queue_length(a2dp_source_local_param.btc_aa_src_cb.TxAaQ); if (frm_nb_threshold > MAX_PCM_FRAME_NUM_PER_TICK) { frm_nb_threshold = MAX_PCM_FRAME_NUM_PER_TICK; } @@ -1166,7 +1119,7 @@ static UINT8 btc_get_num_aa_frame(void) APPL_TRACE_EVENT("Limit frms to send from %d to %d", result, frm_nb_threshold); result = frm_nb_threshold; } - btc_aa_src_cb.media_feeding_state.pcm.counter -= result * pcm_bytes_per_frame; + a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.counter -= result * pcm_bytes_per_frame; BTC_TRACE_VERBOSE("WRITE %d FRAMES", result); } @@ -1174,7 +1127,7 @@ static UINT8 btc_get_num_aa_frame(void) default: APPL_TRACE_ERROR("ERROR btc_get_num_aa_frame Unsupported transcoding format 0x%x", - btc_aa_src_cb.TxTranscoding); + a2dp_source_local_param.btc_aa_src_cb.TxTranscoding); result = 0; break; } @@ -1194,13 +1147,13 @@ static UINT8 btc_get_num_aa_frame(void) BOOLEAN btc_media_aa_read_feeding(void) { - UINT16 blocm_x_subband = btc_sbc_encoder.s16NumOfSubBands * \ - btc_sbc_encoder.s16NumOfBlocks; + UINT16 blocm_x_subband = a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfSubBands * \ + a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfBlocks; UINT32 read_size; UINT16 sbc_sampling = 48000; UINT32 src_samples; - UINT16 bytes_needed = blocm_x_subband * btc_sbc_encoder.s16NumOfChannels * \ - btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample / 8; + UINT16 bytes_needed = blocm_x_subband * a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfChannels * \ + a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample / 8; static UINT16 up_sampled_buffer[SBC_MAX_NUM_FRAME * SBC_MAX_NUM_OF_BLOCKS * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS * 2]; static UINT16 read_buffer[SBC_MAX_NUM_FRAME * SBC_MAX_NUM_OF_BLOCKS @@ -1213,7 +1166,7 @@ BOOLEAN btc_media_aa_read_feeding(void) UINT32 nb_byte_read = 0; /* Get the SBC sampling rate */ - switch (btc_sbc_encoder.s16SamplingFreq) { + switch (a2dp_source_local_param.btc_aa_src_cb.encoder.s16SamplingFreq) { case SBC_sf48000: sbc_sampling = 48000; break; @@ -1228,19 +1181,19 @@ BOOLEAN btc_media_aa_read_feeding(void) break; } - if (sbc_sampling == btc_aa_src_cb.media_feeding.cfg.pcm.sampling_freq) { - read_size = bytes_needed - btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue; + if (sbc_sampling == a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.sampling_freq) { + read_size = bytes_needed - a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue; nb_byte_read = btc_aa_src_data_read( - ((uint8_t *)btc_sbc_encoder.as16PcmBuffer) + - btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue, + ((uint8_t *)a2dp_source_local_param.btc_aa_src_cb.encoder.as16PcmBuffer) + + a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue, read_size); if (nb_byte_read == read_size) { - btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue = 0; + a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue = 0; return TRUE; } else { APPL_TRACE_WARNING("### UNDERFLOW :: ONLY READ %d BYTES OUT OF %d ###", nb_byte_read, read_size); - btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue += nb_byte_read; + a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue += nb_byte_read; return FALSE; } } @@ -1249,7 +1202,7 @@ BOOLEAN btc_media_aa_read_feeding(void) /* to read. */ /* E.g 128/6=21.3333 => read 22 and 21 and 21 => max = 2; threshold = 0*/ fract_needed = FALSE; /* Default */ - switch (btc_aa_src_cb.media_feeding.cfg.pcm.sampling_freq) { + switch (a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.sampling_freq) { case 32000: case 8000: fract_needed = TRUE; @@ -1265,26 +1218,26 @@ BOOLEAN btc_media_aa_read_feeding(void) /* Compute number of sample to read from source */ src_samples = blocm_x_subband; - src_samples *= btc_aa_src_cb.media_feeding.cfg.pcm.sampling_freq; + src_samples *= a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.sampling_freq; src_samples /= sbc_sampling; /* The previous division may have a remainder not null */ if (fract_needed) { - if (btc_aa_src_cb.media_feeding_state.pcm.aa_feed_counter <= fract_threshold) { + if (a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_counter <= fract_threshold) { src_samples++; /* for every read before threshold add one sample */ } /* do nothing if counter >= threshold */ - btc_aa_src_cb.media_feeding_state.pcm.aa_feed_counter++; /* one more read */ - if (btc_aa_src_cb.media_feeding_state.pcm.aa_feed_counter > fract_max) { - btc_aa_src_cb.media_feeding_state.pcm.aa_feed_counter = 0; + a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_counter++; /* one more read */ + if (a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_counter > fract_max) { + a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_counter = 0; } } /* Compute number of bytes to read from source */ read_size = src_samples; - read_size *= btc_aa_src_cb.media_feeding.cfg.pcm.num_channel; - read_size *= (btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample / 8); + read_size *= a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.num_channel; + read_size *= (a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample / 8); /* Read Data from data channel */ nb_byte_read = btc_aa_src_data_read((uint8_t *)read_buffer, read_size); @@ -1299,7 +1252,7 @@ BOOLEAN btc_media_aa_read_feeding(void) return FALSE; } - if (btc_aa_src_cb.feeding_mode == BTC_AV_FEEDING_ASYNCHRONOUS) { + if (a2dp_source_local_param.btc_aa_src_cb.feeding_mode == BTC_AV_FEEDING_ASYNCHRONOUS) { /* Fill the unfilled part of the read buffer with silence (0) */ memset(((UINT8 *)read_buffer) + nb_byte_read, 0, read_size - nb_byte_read); nb_byte_read = read_size; @@ -1307,34 +1260,34 @@ BOOLEAN btc_media_aa_read_feeding(void) } /* Initialize PCM up-sampling engine */ - bta_av_sbc_init_up_sample(btc_aa_src_cb.media_feeding.cfg.pcm.sampling_freq, - sbc_sampling, btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample, - btc_aa_src_cb.media_feeding.cfg.pcm.num_channel); + bta_av_sbc_init_up_sample(a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.sampling_freq, + sbc_sampling, a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample, + a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.num_channel); /* re-sample read buffer */ /* The output PCM buffer will be stereo, 16 bit per sample */ dst_size_used = bta_av_sbc_up_sample((UINT8 *)read_buffer, - (UINT8 *)up_sampled_buffer + btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue, + (UINT8 *)up_sampled_buffer + a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue, nb_byte_read, - sizeof(up_sampled_buffer) - btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue, + sizeof(up_sampled_buffer) - a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue, &src_size_used); /* update the residue */ - btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue += dst_size_used; + a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue += dst_size_used; /* only copy the pcm sample when we have up-sampled enough PCM */ - if (btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue >= bytes_needed) { + if (a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue >= bytes_needed) { /* Copy the output pcm samples in SBC encoding buffer */ - memcpy((UINT8 *)btc_sbc_encoder.as16PcmBuffer, + memcpy((UINT8 *)a2dp_source_local_param.btc_aa_src_cb.encoder.as16PcmBuffer, (UINT8 *)up_sampled_buffer, bytes_needed); /* update the residue */ - btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue -= bytes_needed; + a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue -= bytes_needed; - if (btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue != 0) { + if (a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue != 0) { memcpy((UINT8 *)up_sampled_buffer, (UINT8 *)up_sampled_buffer + bytes_needed, - btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue); + a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue); } return TRUE; } @@ -1354,13 +1307,13 @@ BOOLEAN btc_media_aa_read_feeding(void) static void btc_media_aa_prep_sbc_2_send(UINT8 nb_frame) { BT_HDR *p_buf; - UINT16 blocm_x_subband = btc_sbc_encoder.s16NumOfSubBands * - btc_sbc_encoder.s16NumOfBlocks; + UINT16 blocm_x_subband = a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfSubBands * + a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfBlocks; while (nb_frame) { if (NULL == (p_buf = osi_malloc(BTC_MEDIA_AA_BUF_SIZE))) { APPL_TRACE_ERROR ("ERROR btc_media_aa_prep_sbc_2_send no buffer TxCnt %d ", - fixed_queue_length(btc_aa_src_cb.TxAaQ)); + fixed_queue_length(a2dp_source_local_param.btc_aa_src_cb.TxAaQ)); return; } @@ -1371,53 +1324,53 @@ static void btc_media_aa_prep_sbc_2_send(UINT8 nb_frame) do { /* Write @ of allocated buffer in encoder.pu8Packet */ - btc_sbc_encoder.pu8Packet = (UINT8 *) (p_buf + 1) + p_buf->offset + p_buf->len; + a2dp_source_local_param.btc_aa_src_cb.encoder.pu8Packet = (UINT8 *) (p_buf + 1) + p_buf->offset + p_buf->len; /* Fill allocated buffer with 0 */ - memset(btc_sbc_encoder.as16PcmBuffer, 0, blocm_x_subband - * btc_sbc_encoder.s16NumOfChannels); + memset(a2dp_source_local_param.btc_aa_src_cb.encoder.as16PcmBuffer, 0, blocm_x_subband + * a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfChannels); /* Read PCM data and upsample them if needed */ if (btc_media_aa_read_feeding()) { /* SBC encode and descramble frame */ - SBC_Encoder(&(btc_sbc_encoder)); + SBC_Encoder(&(a2dp_source_local_param.btc_aa_src_cb.encoder)); /* Update SBC frame length */ - p_buf->len += btc_sbc_encoder.u16PacketLength; + p_buf->len += a2dp_source_local_param.btc_aa_src_cb.encoder.u16PacketLength; nb_frame--; p_buf->layer_specific++; } else { APPL_TRACE_WARNING("btc_media_aa_prep_sbc_2_send underflow %d, %d", - nb_frame, btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue); - btc_aa_src_cb.media_feeding_state.pcm.counter += nb_frame * - btc_sbc_encoder.s16NumOfSubBands * - btc_sbc_encoder.s16NumOfBlocks * - btc_aa_src_cb.media_feeding.cfg.pcm.num_channel * - btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample / 8; + nb_frame, a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue); + a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.counter += nb_frame * + a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfSubBands * + a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfBlocks * + a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.num_channel * + a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample / 8; /* no more pcm to read */ nb_frame = 0; /* break read loop if timer was stopped (media task stopped) */ - if ( btc_aa_src_cb.is_tx_timer == FALSE ) { + if ( a2dp_source_local_param.btc_aa_src_cb.is_tx_timer == FALSE ) { osi_free(p_buf); return; } } - } while (((p_buf->len + btc_sbc_encoder.u16PacketLength) < btc_aa_src_cb.TxAaMtuSize) + } while (((p_buf->len + a2dp_source_local_param.btc_aa_src_cb.encoder.u16PacketLength) < a2dp_source_local_param.btc_aa_src_cb.TxAaMtuSize) && (p_buf->layer_specific < 0x0F) && nb_frame); if (p_buf->len) { /* timestamp of the media packet header represent the TS of the first SBC frame i.e the timestamp before including this frame */ - *((UINT32 *) (p_buf + 1)) = btc_aa_src_cb.timestamp; + *((UINT32 *) (p_buf + 1)) = a2dp_source_local_param.btc_aa_src_cb.timestamp; - btc_aa_src_cb.timestamp += p_buf->layer_specific * blocm_x_subband; + a2dp_source_local_param.btc_aa_src_cb.timestamp += p_buf->layer_specific * blocm_x_subband; - if (btc_aa_src_cb.tx_flush) { + if (a2dp_source_local_param.btc_aa_src_cb.tx_flush) { APPL_TRACE_DEBUG("### tx suspended, discarded frame ###"); - if (fixed_queue_length(btc_aa_src_cb.TxAaQ) > 0) { - btc_a2dp_source_flush_q(btc_aa_src_cb.TxAaQ); + if (fixed_queue_length(a2dp_source_local_param.btc_aa_src_cb.TxAaQ) > 0) { + btc_a2dp_source_flush_q(a2dp_source_local_param.btc_aa_src_cb.TxAaQ); } osi_free(p_buf); @@ -1425,7 +1378,7 @@ static void btc_media_aa_prep_sbc_2_send(UINT8 nb_frame) } /* Enqueue the encoded SBC frame in AA Tx Queue */ - fixed_queue_enqueue(btc_aa_src_cb.TxAaQ, p_buf); + fixed_queue_enqueue(a2dp_source_local_param.btc_aa_src_cb.TxAaQ, p_buf, FIXED_QUEUE_MAX_TIMEOUT); } else { osi_free(p_buf); } @@ -1448,24 +1401,24 @@ static void btc_a2dp_source_prep_2_send(UINT8 nb_frame) nb_frame = MAX_OUTPUT_A2DP_SRC_FRAME_QUEUE_SZ; } - if (fixed_queue_length(btc_aa_src_cb.TxAaQ) > (MAX_OUTPUT_A2DP_SRC_FRAME_QUEUE_SZ - nb_frame)) { + if (fixed_queue_length(a2dp_source_local_param.btc_aa_src_cb.TxAaQ) > (MAX_OUTPUT_A2DP_SRC_FRAME_QUEUE_SZ - nb_frame)) { APPL_TRACE_WARNING("TX Q overflow: %d/%d", - fixed_queue_length(btc_aa_src_cb.TxAaQ), MAX_OUTPUT_A2DP_SRC_FRAME_QUEUE_SZ - nb_frame); + fixed_queue_length(a2dp_source_local_param.btc_aa_src_cb.TxAaQ), MAX_OUTPUT_A2DP_SRC_FRAME_QUEUE_SZ - nb_frame); } - while (fixed_queue_length(btc_aa_src_cb.TxAaQ) > (MAX_OUTPUT_A2DP_SRC_FRAME_QUEUE_SZ - nb_frame)) { - osi_free(fixed_queue_try_dequeue(btc_aa_src_cb.TxAaQ)); + while (fixed_queue_length(a2dp_source_local_param.btc_aa_src_cb.TxAaQ) > (MAX_OUTPUT_A2DP_SRC_FRAME_QUEUE_SZ - nb_frame)) { + osi_free(fixed_queue_dequeue(a2dp_source_local_param.btc_aa_src_cb.TxAaQ, 0)); } // Transcode frame - switch (btc_aa_src_cb.TxTranscoding) { + switch (a2dp_source_local_param.btc_aa_src_cb.TxTranscoding) { case BTC_MEDIA_TRSCD_PCM_2_SBC: btc_media_aa_prep_sbc_2_send(nb_frame); break; default: - APPL_TRACE_ERROR("%s unsupported transcoding format 0x%x", __func__, btc_aa_src_cb.TxTranscoding); + APPL_TRACE_ERROR("%s unsupported transcoding format 0x%x", __func__, a2dp_source_local_param.btc_aa_src_cb.TxTranscoding); break; } } @@ -1505,7 +1458,7 @@ static void btc_a2dp_source_handle_timer(UNUSED_ATTR void *context) return; } - if (btc_aa_src_cb.is_tx_timer == TRUE) { + if (a2dp_source_local_param.btc_aa_src_cb.is_tx_timer == TRUE) { btc_a2dp_source_send_aa_frame(); } else { APPL_TRACE_WARNING("Media task Scheduled after Suspend"); @@ -1515,7 +1468,7 @@ static void btc_a2dp_source_handle_timer(UNUSED_ATTR void *context) static void btc_a2dp_source_alarm_cb(UNUSED_ATTR void *context) { - btc_a2dp_source_data_post(BTC_A2DP_SOURCE_DATA_EVT); + btc_a2dp_source_data_post(); } /******************************************************************************* @@ -1530,17 +1483,17 @@ static void btc_a2dp_source_alarm_cb(UNUSED_ATTR void *context) static void btc_a2dp_source_feeding_state_reset(void) { /* By default, just clear the entire state */ - memset(&btc_aa_src_cb.media_feeding_state, 0, sizeof(btc_aa_src_cb.media_feeding_state)); + memset(&a2dp_source_local_param.btc_aa_src_cb.media_feeding_state, 0, sizeof(a2dp_source_local_param.btc_aa_src_cb.media_feeding_state)); - if (btc_aa_src_cb.TxTranscoding == BTC_MEDIA_TRSCD_PCM_2_SBC) { - btc_aa_src_cb.media_feeding_state.pcm.bytes_per_tick = - (btc_aa_src_cb.media_feeding.cfg.pcm.sampling_freq * - btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample / 8 * - btc_aa_src_cb.media_feeding.cfg.pcm.num_channel * + if (a2dp_source_local_param.btc_aa_src_cb.TxTranscoding == BTC_MEDIA_TRSCD_PCM_2_SBC) { + a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.bytes_per_tick = + (a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.sampling_freq * + a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample / 8 * + a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.num_channel * BTC_MEDIA_TIME_TICK_MS) / 1000; APPL_TRACE_EVENT("pcm bytes per tick %d", - (int)btc_aa_src_cb.media_feeding_state.pcm.bytes_per_tick); + (int)a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.bytes_per_tick); } } @@ -1556,26 +1509,26 @@ static void btc_a2dp_source_feeding_state_reset(void) static void btc_a2dp_source_aa_start_tx(void) { APPL_TRACE_DEBUG("btc_a2dp_source_aa_start_tx is timer %d, feeding mode %d", - btc_aa_src_cb.is_tx_timer, btc_aa_src_cb.feeding_mode); + a2dp_source_local_param.btc_aa_src_cb.is_tx_timer, a2dp_source_local_param.btc_aa_src_cb.feeding_mode); - btc_aa_src_cb.is_tx_timer = TRUE; - last_frame_us = 0; + a2dp_source_local_param.btc_aa_src_cb.is_tx_timer = TRUE; + a2dp_source_local_param.last_frame_us = 0; /* Reset the media feeding state */ btc_a2dp_source_feeding_state_reset(); APPL_TRACE_EVENT("starting timer %dms", BTC_MEDIA_TIME_TICK_MS); - assert(btc_aa_src_cb.media_alarm == NULL); + assert(a2dp_source_local_param.btc_aa_src_cb.media_alarm == NULL); - btc_aa_src_cb.media_alarm = osi_alarm_new("aaTx", btc_a2dp_source_alarm_cb, NULL, BTC_MEDIA_TIME_TICK_MS); + a2dp_source_local_param.btc_aa_src_cb.media_alarm = osi_alarm_new("aaTx", btc_a2dp_source_alarm_cb, NULL, BTC_MEDIA_TIME_TICK_MS); - if (!btc_aa_src_cb.media_alarm) { + if (!a2dp_source_local_param.btc_aa_src_cb.media_alarm) { BTC_TRACE_ERROR("%s unable to allocate media alarm.", __func__); return; } - osi_alarm_set_periodic(btc_aa_src_cb.media_alarm, BTC_MEDIA_TIME_TICK_MS); + osi_alarm_set_periodic(a2dp_source_local_param.btc_aa_src_cb.media_alarm, BTC_MEDIA_TIME_TICK_MS); } /******************************************************************************* @@ -1589,17 +1542,17 @@ static void btc_a2dp_source_aa_start_tx(void) *******************************************************************************/ static void btc_a2dp_source_aa_stop_tx(void) { - APPL_TRACE_DEBUG("%s is_tx_timer: %d", __func__, btc_aa_src_cb.is_tx_timer); + APPL_TRACE_DEBUG("%s is_tx_timer: %d", __func__, a2dp_source_local_param.btc_aa_src_cb.is_tx_timer); - const bool send_ack = (btc_aa_src_cb.is_tx_timer != FALSE); + const bool send_ack = (a2dp_source_local_param.btc_aa_src_cb.is_tx_timer != FALSE); /* Stop the timer first */ - if (btc_aa_src_cb.media_alarm) { - osi_alarm_cancel(btc_aa_src_cb.media_alarm); - osi_alarm_free(btc_aa_src_cb.media_alarm); + if (a2dp_source_local_param.btc_aa_src_cb.media_alarm) { + osi_alarm_cancel(a2dp_source_local_param.btc_aa_src_cb.media_alarm); + osi_alarm_free(a2dp_source_local_param.btc_aa_src_cb.media_alarm); } - btc_aa_src_cb.media_alarm = NULL; - btc_aa_src_cb.is_tx_timer = FALSE; + a2dp_source_local_param.btc_aa_src_cb.media_alarm = NULL; + a2dp_source_local_param.btc_aa_src_cb.is_tx_timer = FALSE; /* Try to send acknowldegment once the media stream is stopped. This will make sure that the A2DP HAL layer is @@ -1617,8 +1570,8 @@ static void btc_a2dp_source_aa_stop_tx(void) } /* audio engine stopped, reset tx suspended flag */ - btc_aa_src_cb.tx_flush = 0; - last_frame_us = 0; + a2dp_source_local_param.btc_aa_src_cb.tx_flush = 0; + a2dp_source_local_param.last_frame_us = 0; /* Reset the feeding state */ btc_a2dp_source_feeding_state_reset(); @@ -1636,18 +1589,18 @@ static void btc_a2dp_source_aa_stop_tx(void) static void btc_a2dp_source_flush_q(fixed_queue_t *p_q) { while (! fixed_queue_is_empty(p_q)) { - osi_free(fixed_queue_try_dequeue(p_q)); + osi_free(fixed_queue_dequeue(p_q, 0)); } } static void btc_a2dp_source_thread_init(UNUSED_ATTR void *context) { APPL_TRACE_EVENT("%s\n", __func__); - memset(&btc_aa_src_cb, 0, sizeof(btc_aa_src_cb)); + memset(&a2dp_source_local_param.btc_aa_src_cb, 0, sizeof(a2dp_source_local_param.btc_aa_src_cb)); btc_a2dp_source_state = BTC_A2DP_SOURCE_STATE_ON; - btc_aa_src_cb.TxAaQ = fixed_queue_new(QUEUE_SIZE_MAX); + a2dp_source_local_param.btc_aa_src_cb.TxAaQ = fixed_queue_new(QUEUE_SIZE_MAX); btc_a2dp_control_init(); } @@ -1660,9 +1613,9 @@ static void btc_a2dp_source_thread_cleanup(UNUSED_ATTR void *context) btc_a2dp_control_cleanup(); - fixed_queue_free(btc_aa_src_cb.TxAaQ, osi_free_func); + fixed_queue_free(a2dp_source_local_param.btc_aa_src_cb.TxAaQ, osi_free_func); - future_ready(btc_a2dp_source_future, NULL); + future_ready(a2dp_source_local_param.btc_a2dp_source_future, NULL); } #endif /* BTC_AV_INCLUDED */ diff --git a/components/bt/bluedroid/btc/profile/std/a2dp/btc_av.c b/components/bt/bluedroid/btc/profile/std/a2dp/btc_av.c index f428150bae..be1f1f9628 100644 --- a/components/bt/bluedroid/btc/profile/std/a2dp/btc_av.c +++ b/components/bt/bluedroid/btc/profile/std/a2dp/btc_av.c @@ -79,6 +79,9 @@ typedef struct { UINT8 flags; tBTA_AV_EDR edr; UINT8 peer_sep; /* sep type of peer device */ +#if BTC_AV_SRC_INCLUDED + osi_alarm_t *tle_av_open_on_rc; +#endif /* BTC_AV_SRC_INCLUDED */ } btc_av_cb_t; typedef struct { @@ -89,11 +92,12 @@ typedef struct { /***************************************************************************** ** Static variables ******************************************************************************/ +#if A2D_DYNAMIC_MEMORY == FALSE static btc_av_cb_t btc_av_cb = {0}; - -#if BTC_AV_SRC_INCLUDED -static osi_alarm_t *tle_av_open_on_rc = NULL; -#endif /* BTC_AV_SRC_INCLUDED */ +#else +static btc_av_cb_t *btc_av_cb_ptr = NULL; +#define btc_av_cb (*btc_av_cb_ptr) +#endif ///A2D_DYNAMIC_MEMORY == FALSE /* both interface and media task needs to be ready to alloc incoming request */ #define CHECK_BTAV_INIT() do \ @@ -337,8 +341,8 @@ static BOOLEAN btc_av_state_idle_handler(btc_sm_event_t event, void *p_data) #if BTC_AV_SRC_INCLUDED BTC_TRACE_DEBUG("BTA_AV_RC_OPEN_EVT received w/o AV"); - tle_av_open_on_rc = osi_alarm_new("AVconn", btc_initiate_av_open_tmr_hdlr, NULL, BTC_TIMEOUT_AV_OPEN_ON_RC_SECS * 1000); - osi_alarm_set(tle_av_open_on_rc, BTC_TIMEOUT_AV_OPEN_ON_RC_SECS * 1000); + btc_av_cb.tle_av_open_on_rc = osi_alarm_new("AVconn", btc_initiate_av_open_tmr_hdlr, NULL, BTC_TIMEOUT_AV_OPEN_ON_RC_SECS * 1000); + osi_alarm_set(btc_av_cb.tle_av_open_on_rc, BTC_TIMEOUT_AV_OPEN_ON_RC_SECS * 1000); #endif /* BTC_AV_SRC_INCLUDED */ btc_rc_handler(event, p_data); break; @@ -353,9 +357,9 @@ static BOOLEAN btc_av_state_idle_handler(btc_sm_event_t event, void *p_data) case BTA_AV_RC_CLOSE_EVT: #if BTC_AV_SRC_INCLUDED - if (tle_av_open_on_rc) { - osi_alarm_free(tle_av_open_on_rc); - tle_av_open_on_rc = NULL; + if (btc_av_cb.tle_av_open_on_rc) { + osi_alarm_free(btc_av_cb.tle_av_open_on_rc); + btc_av_cb.tle_av_open_on_rc = NULL; } #endif /* BTC_AV_SRC_INCLUDED */ btc_rc_handler(event, p_data); @@ -961,6 +965,19 @@ static void btc_av_event_free_data(btc_sm_event_t event, void *p_data) static bt_status_t btc_av_init(int service_id) { + +#if A2D_DYNAMIC_MEMORY == TRUE + if (btc_av_cb_ptr != NULL) { + return BT_STATUS_FAIL; + } + + if ((btc_av_cb_ptr = (btc_av_cb_t *)osi_malloc(sizeof(btc_av_cb_t))) == NULL) { + APPL_TRACE_ERROR("%s malloc failed!", __func__); + return BT_STATUS_NOMEM; + } + memset((void *)btc_av_cb_ptr, 0, sizeof(btc_av_cb_t)); +#endif + if (btc_av_cb.sm_handle == NULL) { btc_av_cb.service_id = service_id; bool stat = false; @@ -975,6 +992,10 @@ static bt_status_t btc_av_init(int service_id) } if (!stat) { +#if A2D_DYNAMIC_MEMORY == TRUE + osi_free(btc_av_cb_ptr); + btc_av_cb_ptr = NULL; +#endif return BT_STATUS_FAIL; } @@ -1034,9 +1055,9 @@ static void clean_up(int service_id) if (service_id == BTA_A2DP_SOURCE_SERVICE_ID) { #if BTC_AV_SRC_INCLUDED btc_a2dp_source_shutdown(); - if (tle_av_open_on_rc) { - osi_alarm_free(tle_av_open_on_rc); - tle_av_open_on_rc = NULL; + if (btc_av_cb.tle_av_open_on_rc) { + osi_alarm_free(btc_av_cb.tle_av_open_on_rc); + btc_av_cb.tle_av_open_on_rc = NULL; } #endif /* BTC_AV_SRC_INCLUDED */ } @@ -1056,6 +1077,11 @@ static void clean_up(int service_id) btc_a2dp_sink_shutdown(); #endif /* BTC_AV_SINK_INCLUDED */ } + +#if A2D_DYNAMIC_MEMORY == TRUE + osi_free(btc_av_cb_ptr); + btc_av_cb_ptr = NULL; +#endif } /******************************************************************************* diff --git a/components/bt/bluedroid/btc/profile/std/a2dp/include/btc_av_co.h b/components/bt/bluedroid/btc/profile/std/a2dp/include/btc_av_co.h index cacaa01d8f..a7943b70cb 100644 --- a/components/bt/bluedroid/btc/profile/std/a2dp/include/btc_av_co.h +++ b/components/bt/bluedroid/btc/profile/std/a2dp/include/btc_av_co.h @@ -16,6 +16,7 @@ #define __BTC_AV_CO_H__ #include "btc_a2dp.h" +#include "bta/bta_av_co.h" #if (BTA_AV_INCLUDED == TRUE) /******************************************************************************* @@ -28,7 +29,62 @@ enum { BTC_SV_AV_AA_SEP_INDEX /* Last index */ }; +/***************************************************************************** +** Local data +*****************************************************************************/ +typedef struct { + UINT8 sep_info_idx; /* local SEP index (in BTA tables) */ + UINT8 seid; /* peer SEP index (in peer tables) */ + UINT8 codec_type; /* peer SEP codec type */ + UINT8 codec_caps[AVDT_CODEC_SIZE]; /* peer SEP codec capabilities */ + UINT8 num_protect; /* peer SEP number of CP elements */ + UINT8 protect_info[BTA_AV_CP_INFO_LEN]; /* peer SEP content protection info */ +} tBTA_AV_CO_SINK; +typedef struct { + BD_ADDR addr; /* address of audio/video peer */ + tBTA_AV_CO_SINK snks[BTC_SV_AV_AA_SEP_INDEX]; /* array of supported sinks */ + tBTA_AV_CO_SINK srcs[BTC_SV_AV_AA_SEP_INDEX]; /* array of supported srcs */ + UINT8 num_snks; /* total number of sinks at peer */ + UINT8 num_srcs; /* total number of srcs at peer */ + UINT8 num_seps; /* total number of seids at peer */ + UINT8 num_rx_snks; /* number of received sinks */ + UINT8 num_rx_srcs; /* number of received srcs */ + UINT8 num_sup_snks; /* number of supported sinks in the snks array */ + UINT8 num_sup_srcs; /* number of supported srcs in the srcs array */ + tBTA_AV_CO_SINK *p_snk; /* currently selected sink */ + tBTA_AV_CO_SINK *p_src; /* currently selected src */ + UINT8 codec_cfg[AVDT_CODEC_SIZE]; /* current codec configuration */ + BOOLEAN cp_active; /* current CP configuration */ + BOOLEAN acp; /* acceptor */ + BOOLEAN recfg_needed; /* reconfiguration is needed */ + BOOLEAN opened; /* opened */ + UINT16 mtu; /* maximum transmit unit size */ + UINT16 uuid_to_connect; /* uuid of peer device */ +} tBTA_AV_CO_PEER; + +typedef struct { + BOOLEAN active; + UINT8 flag; +} tBTA_AV_CO_CP; + +typedef struct { + /* Connected peer information */ + tBTA_AV_CO_PEER peers[BTA_AV_NUM_STRS]; + /* Current codec configuration - access to this variable must be protected */ + tBTC_AV_CODEC_INFO codec_cfg; + tBTC_AV_CODEC_INFO codec_cfg_setconfig; /* remote peer setconfig preference */ + + tBTA_AV_CO_CP cp; +} tBTA_AV_CO_CB; + +/* Control block instance */ +#if AVRC_DYNAMIC_MEMORY == FALSE +extern tBTA_AV_CO_CB bta_av_co_cb; +#else +extern tBTA_AV_CO_CB *bta_av_co_cb_ptr; +#define bta_av_co_cb (*bta_av_co_cb_ptr) +#endif /******************************************************************************* ** Functions ********************************************************************************/ diff --git a/components/bt/bluedroid/btc/profile/std/avrc/btc_avrc.c b/components/bt/bluedroid/btc/profile/std/avrc/btc_avrc.c index 6e204be482..28ecb85e63 100644 --- a/components/bt/bluedroid/btc/profile/std/avrc/btc_avrc.c +++ b/components/bt/bluedroid/btc/profile/std/avrc/btc_avrc.c @@ -35,40 +35,6 @@ #if BTC_AV_INCLUDED -/***************************************************************************** -** Constants & Macros -******************************************************************************/ -#define BTC_RC_CT_INIT_MAGIC 0x20181128 -#define BTC_RC_TG_INIT_MAGIC 0x20181129 - -#define MAX_RC_NOTIFICATIONS (13) // refer to ESP_AVRC_RN_MAX_EVT - -#define CHECK_ESP_RC_CONNECTED do { \ - BTC_TRACE_DEBUG("## %s ##", __FUNCTION__); \ - if (btc_rc_cb.rc_connected == FALSE) { \ - BTC_TRACE_WARNING("Function %s() called when RC is not connected", __FUNCTION__); \ - return ESP_ERR_INVALID_STATE; \ - } \ - } while (0) - -/***************************************************************************** -** Local type definitions -******************************************************************************/ -typedef struct { - BOOLEAN registered; - UINT8 label; -} btc_rc_reg_ntf_t; - -typedef struct { - BOOLEAN rc_connected; - UINT8 rc_handle; - tBTA_AV_FEAT rc_features; - UINT16 rc_ct_features; - UINT16 rc_tg_features; - BD_ADDR rc_addr; - btc_rc_reg_ntf_t rc_ntf[MAX_RC_NOTIFICATIONS]; -} btc_rc_cb_t; - static UINT8 opcode_from_pdu(UINT8 pdu); static void send_reject_response (UINT8 rc_handle, UINT8 label, UINT8 pdu, UINT8 status); static void handle_rc_connect (tBTA_AV_RC_OPEN *p_rc_open); @@ -86,7 +52,11 @@ static void btc_rc_upstreams_evt(UINT16 event, tAVRC_COMMAND *pavrc_cmd, UINT8 c static uint32_t s_rc_ct_init; static uint32_t s_rc_tg_init; +#if AVRC_DYNAMIC_MEMORY == FALSE static btc_rc_cb_t btc_rc_cb; +#else +btc_rc_cb_t *btc_rc_cb_ptr; +#endif ///AVRC_DYNAMIC_MEMORY == FALSE const static uint16_t cs_psth_allowed_cmd[8] = { 0x0000, /* bit mask: 0=SELECT, 1=UP, 2=DOWN, 3=LEFT, @@ -1031,7 +1001,7 @@ static void btc_avrc_ct_init(void) /// initialize CT-TG shared resources if (s_rc_tg_init != BTC_RC_TG_INIT_MAGIC) { - memset (&btc_rc_cb, 0, sizeof(btc_rc_cb)); + memset (&btc_rc_cb, 0, sizeof(btc_rc_cb_t)); } } @@ -1059,7 +1029,7 @@ static void btc_avrc_ct_deinit(void) /// deinit CT-TG shared resources if (s_rc_tg_init != BTC_RC_TG_INIT_MAGIC) { - memset (&btc_rc_cb, 0, sizeof(btc_rc_cb)); + memset (&btc_rc_cb, 0, sizeof(btc_rc_cb_t)); } BTC_TRACE_API("## %s ## completed", __FUNCTION__); diff --git a/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c b/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c index ffac0c35f6..3355a5924b 100644 --- a/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c +++ b/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c @@ -31,8 +31,15 @@ #include "osi/mutex.h" #include "esp_bt.h" +#if (BLE_INCLUDED == TRUE) +#if BTC_DYNAMIC_MENDRY == FALSE static tBTA_BLE_ADV_DATA gl_bta_adv_data; static tBTA_BLE_ADV_DATA gl_bta_scan_rsp_data; +#else +tBTA_BLE_ADV_DATA *gl_bta_adv_data_ptr; +tBTA_BLE_ADV_DATA *gl_bta_scan_rsp_data_ptr; +#endif + #if SCAN_QUEUE_CONGEST_CHECK static list_t *adv_filter_list; static osi_mutex_t adv_list_lock; @@ -1366,3 +1373,4 @@ void btc_adv_list_unlock(void) osi_mutex_unlock(&adv_list_lock); } #endif +#endif ///BLE_INCLUDED == TRUE \ No newline at end of file diff --git a/components/bt/bluedroid/btc/profile/std/gatt/btc_gatt_util.c b/components/bt/bluedroid/btc/profile/std/gatt/btc_gatt_util.c index 8653f60561..37497a8afc 100644 --- a/components/bt/bluedroid/btc/profile/std/gatt/btc_gatt_util.c +++ b/components/bt/bluedroid/btc/profile/std/gatt/btc_gatt_util.c @@ -20,7 +20,7 @@ #define GATTC_READ_VALUE_TYPE_VALUE 0x0000 /* Attribute value itself */ #define GATTC_READ_VALUE_TYPE_AGG_FORMAT 0x2905 /* Characteristic Aggregate Format*/ -static unsigned char BASE_UUID[16] = { +static const unsigned char BASE_UUID[16] = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c b/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c index e93fc937ea..117b6b8614 100644 --- a/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c +++ b/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c @@ -30,19 +30,11 @@ #define A2C_GATTS_EVT(_bta_event) (_bta_event) //BTA TO BTC EVT #define C2A_GATTS_EVT(_btc_event) (_btc_event) //BTC TO BTA EVT -typedef struct { - future_t *complete_future; - uint16_t svc_start_hdl; - esp_bt_uuid_t svc_uuid; - bool is_tab_creat_svc; - bool is_use_svc; - uint8_t num_handle; - uint8_t handle_idx; - uint16_t handles[ESP_GATT_ATTR_HANDLE_MAX]; -} esp_btc_creat_tab_t; - +#if GATT_DYNAMIC_MEMORY == FALSE static esp_btc_creat_tab_t btc_creat_tab_env; - +#else +esp_btc_creat_tab_t *btc_creat_tab_env_ptr; +#endif static esp_gatt_status_t btc_gatts_check_valid_attr_tab(esp_gatts_attr_db_t *gatts_attr_db, uint8_t max_nb_attr); @@ -106,13 +98,13 @@ void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) } } break; - + } case BTC_GATTS_ACT_ADD_CHAR: { if (src->add_char.char_val.attr_value && (src->add_char.char_val.attr_len > 0)) { dst->add_char.char_val.attr_value = (uint8_t *) osi_malloc(src->add_char.char_val.attr_len); if (dst->add_char.char_val.attr_value) { - memcpy(dst->add_char.char_val.attr_value, src->add_char.char_val.attr_value, + memcpy(dst->add_char.char_val.attr_value, src->add_char.char_val.attr_value, src->add_char.char_val.attr_len); } else { BTC_TRACE_ERROR("%s %d no mem\n", __func__, msg->act); @@ -231,7 +223,7 @@ void btc_gatts_arg_deep_free(btc_msg_t *msg) } -static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db, +static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db, esp_gatt_if_t gatts_if, uint8_t max_nb_attr, uint8_t srvc_inst_id) @@ -283,7 +275,7 @@ static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db, esp_srvc_id.id.inst_id = srvc_inst_id; btc_gatts_uuid_format_convert(&esp_srvc_id.id.uuid,gatts_attr_db[i].att_desc.length, gatts_attr_db[i].att_desc.value); - + btc_to_bta_srvc_id(&srvc_id, &esp_srvc_id); if (btc_creat_tab_env.is_use_svc != true) { BTA_GATTS_CreateService(gatts_if, &srvc_id.id.uuid, @@ -297,7 +289,7 @@ static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db, memset(&btc_creat_tab_env, 0, sizeof(esp_btc_creat_tab_t)); return; } - + if (future_await(future_p) == FUTURE_FAIL) { BTC_TRACE_ERROR("%s failed\n", __func__); return; @@ -332,12 +324,12 @@ static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db, } case ESP_GATT_UUID_INCLUDE_SERVICE:{ esp_gatts_incl_svc_desc_t *incl_svc_desc = (esp_gatts_incl_svc_desc_t *)gatts_attr_db[i].att_desc.value; - + if(incl_svc_desc!= NULL){ if(btc_creat_tab_env.svc_start_hdl != 0){ - BTA_GATTS_AddIncludeService(btc_creat_tab_env.svc_start_hdl, + BTA_GATTS_AddIncludeService(btc_creat_tab_env.svc_start_hdl, incl_svc_desc->start_hdl); - + if (future_await(future_p) == FUTURE_FAIL) { BTC_TRACE_ERROR("%s failed\n", __func__); return; @@ -378,10 +370,10 @@ static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db, } } } - + break; } - case ESP_GATT_UUID_CHAR_EXT_PROP: + case ESP_GATT_UUID_CHAR_EXT_PROP: case ESP_GATT_UUID_CHAR_DESCRIPTION: case ESP_GATT_UUID_CHAR_CLIENT_CONFIG: case ESP_GATT_UUID_CHAR_SRVR_CONFIG: @@ -406,7 +398,7 @@ static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db, btc_to_bta_uuid(&bta_char_uuid, &uuid_temp); control.auto_rsp = gatts_attr_db[i].attr_control.auto_rsp; BTA_GATTS_AddCharDescriptor(svc_hal, perm, &bta_char_uuid, &attr_val, &control); - + if (future_await(future_p) == FUTURE_FAIL) { BTC_TRACE_ERROR("%s failed\n", __func__); return; @@ -419,7 +411,7 @@ static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db, break; } - + } param.add_attr_tab.handles = btc_creat_tab_env.handles; @@ -427,7 +419,7 @@ static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db, param.add_attr_tab.svc_inst_id = srvc_inst_id; - btc_gatts_cb_to_app(ESP_GATTS_CREAT_ATTR_TAB_EVT, gatts_if, ¶m); + btc_gatts_cb_to_app(ESP_GATTS_CREAT_ATTR_TAB_EVT, gatts_if, ¶m); //reset the env after sent the data to app memset(&btc_creat_tab_env, 0, sizeof(esp_btc_creat_tab_t)); @@ -504,7 +496,7 @@ static esp_gatt_status_t btc_gatts_check_valid_attr_tab(esp_gatts_attr_db_t *gat esp_gatt_status_t btc_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, uint8_t **value) { - + return BTA_GetAttributeValue(attr_handle, length, value); } @@ -568,14 +560,14 @@ static void btc_gatts_inter_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) { bt_status_t status; btc_msg_t msg; - + msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_GATTS; msg.act = event; if(btc_creat_tab_env.is_tab_creat_svc && btc_creat_tab_env.complete_future) { switch(event) { case BTA_GATTS_CREATE_EVT: { - //save the service handle to the btc module after used + //save the service handle to the btc module after used //the attribute table method to creat a service bta_to_btc_uuid(&btc_creat_tab_env.svc_uuid, &p_data->create.uuid); uint8_t index = btc_creat_tab_env.handle_idx; @@ -663,7 +655,7 @@ void btc_gatts_call_handler(btc_msg_t *msg) btc_to_bta_uuid(&uuid, &arg->add_char.char_uuid); BTA_GATTS_AddCharacteristic(arg->add_char.service_handle, &uuid, - arg->add_char.perm, arg->add_char.property, + arg->add_char.perm, arg->add_char.property, (tGATT_ATTR_VAL *)&arg->add_char.char_val, (tBTA_GATTS_ATTR_CONTROL *)&arg->add_char.attr_control); break; @@ -672,7 +664,7 @@ void btc_gatts_call_handler(btc_msg_t *msg) tBT_UUID uuid; btc_to_bta_uuid(&uuid, &arg->add_descr.descr_uuid); BTA_GATTS_AddCharDescriptor(arg->add_descr.service_handle, arg->add_descr.perm, &uuid, - (tBTA_GATT_ATTR_VAL *)&arg->add_descr.descr_val, + (tBTA_GATT_ATTR_VAL *)&arg->add_descr.descr_val, (tBTA_GATTS_ATTR_CONTROL *)&arg->add_descr.attr_control); break; } @@ -700,7 +692,7 @@ void btc_gatts_call_handler(btc_msg_t *msg) break; } case BTC_GATTS_ACT_SET_ATTR_VALUE: - BTA_SetAttributeValue(arg->set_attr_val.handle, arg->set_attr_val.length, + BTA_SetAttributeValue(arg->set_attr_val.handle, arg->set_attr_val.length, arg->set_attr_val.value); break; case BTC_GATTS_ACT_OPEN: { @@ -785,7 +777,7 @@ void btc_gatts_cb_handler(btc_msg_t *msg) param.read.offset = p_data->req_data.p_data->read_req.offset; param.read.is_long = p_data->req_data.p_data->read_req.is_long; - param.read.need_rsp = p_data->req_data.p_data->read_req.need_rsp; + param.read.need_rsp = p_data->req_data.p_data->read_req.need_rsp; btc_gatts_cb_to_app(ESP_GATTS_READ_EVT, gatts_if, ¶m); break; } diff --git a/components/bt/bluedroid/btc/profile/std/hf_client/btc_hf_client.c b/components/bt/bluedroid/btc/profile/std/hf_client/btc_hf_client.c index 3ae296cf0f..d3ccd66997 100644 --- a/components/bt/bluedroid/btc/profile/std/hf_client/btc_hf_client.c +++ b/components/bt/bluedroid/btc/profile/std/hf_client/btc_hf_client.c @@ -61,42 +61,31 @@ BTA_HF_CLIENT_FEAT_CODEC) #endif -/************************************************************************************ -** Local type definitions -************************************************************************************/ -/* BTC-HF control block to map bdaddr to BTA handle */ -typedef struct -{ - bool initialized; - UINT16 handle; - bt_bdaddr_t connected_bda; - esp_hf_client_connection_state_t state; - esp_hf_vr_state_t vr_state; - tBTA_HF_CLIENT_PEER_FEAT peer_feat; - tBTA_HF_CLIENT_CHLD_FEAT chld_feat; -} btc_hf_client_cb_t; + /************************************************************************************ ** Static variables ************************************************************************************/ const char *btc_hf_client_version = "1.6"; -static UINT32 btc_hf_client_features = 0; -static btc_hf_client_cb_t btc_hf_client_cb; -static esp_hf_client_incoming_data_cb_t btc_hf_client_incoming_data_cb = NULL; -static esp_hf_client_outgoing_data_cb_t btc_hf_client_outgoing_data_cb = NULL; + +#if HFP_DYNAMIC_MEMORY == FALSE +static hf_client_local_param_t hf_client_local_param; +#else +hf_client_local_param_t *hf_client_local_param_ptr; +#endif /************************************************************************************ ** Static functions ************************************************************************************/ #define CHECK_HF_CLIENT_INIT() do { \ -if (! btc_hf_client_cb.initialized) { \ +if (! hf_client_local_param.btc_hf_client_cb.initialized) { \ return BT_STATUS_NOT_READY; \ } \ } while (0) #define CHECK_HF_CLIENT_SLC_CONNECTED() do { \ -if (! btc_hf_client_cb.initialized || \ - btc_hf_client_cb.state != ESP_HF_CLIENT_CONNECTION_STATE_SLC_CONNECTED) { \ +if (! hf_client_local_param.btc_hf_client_cb.initialized || \ + hf_client_local_param.btc_hf_client_cb.state != ESP_HF_CLIENT_CONNECTION_STATE_SLC_CONNECTED) { \ return BT_STATUS_NOT_READY; \ } \ } while (0) @@ -111,14 +100,14 @@ static inline void btc_hf_client_cb_to_app(esp_hf_client_cb_event_t event, esp_h static void clear_state(void) { - memset(&btc_hf_client_cb, 0, sizeof(btc_hf_client_cb_t)); + memset(&hf_client_local_param.btc_hf_client_cb, 0, sizeof(btc_hf_client_cb_t)); } static BOOLEAN is_connected(bt_bdaddr_t *bd_addr) { - if (((btc_hf_client_cb.state == ESP_HF_CLIENT_CONNECTION_STATE_CONNECTED) || - (btc_hf_client_cb.state == ESP_HF_CLIENT_CONNECTION_STATE_SLC_CONNECTED))&& - ((bd_addr == NULL) || (bdcmp(bd_addr->address, btc_hf_client_cb.connected_bda.address) == 0))) + if (((hf_client_local_param.btc_hf_client_cb.state == ESP_HF_CLIENT_CONNECTION_STATE_CONNECTED) || + (hf_client_local_param.btc_hf_client_cb.state == ESP_HF_CLIENT_CONNECTION_STATE_SLC_CONNECTED))&& + ((bd_addr == NULL) || (bdcmp(bd_addr->address, hf_client_local_param.btc_hf_client_cb.connected_bda.address) == 0))) return TRUE; return FALSE; } @@ -126,23 +115,23 @@ static BOOLEAN is_connected(bt_bdaddr_t *bd_addr) void btc_hf_client_reg_data_cb(esp_hf_client_incoming_data_cb_t recv, esp_hf_client_outgoing_data_cb_t send) { - btc_hf_client_incoming_data_cb = recv; - btc_hf_client_outgoing_data_cb = send; + hf_client_local_param.btc_hf_client_incoming_data_cb = recv; + hf_client_local_param.btc_hf_client_outgoing_data_cb = send; } void btc_hf_client_incoming_data_cb_to_app(const uint8_t *data, uint32_t len) { // todo: critical section protection - if (btc_hf_client_incoming_data_cb) { - btc_hf_client_incoming_data_cb(data, len); + if (hf_client_local_param.btc_hf_client_incoming_data_cb) { + hf_client_local_param.btc_hf_client_incoming_data_cb(data, len); } } uint32_t btc_hf_client_outgoing_data_cb_to_app(uint8_t *data, uint32_t len) { // todo: critical section protection - if (btc_hf_client_outgoing_data_cb) { - return btc_hf_client_outgoing_data_cb(data, len); + if (hf_client_local_param.btc_hf_client_outgoing_data_cb) { + return hf_client_local_param.btc_hf_client_outgoing_data_cb(data, len); } else { return 0; } @@ -172,9 +161,9 @@ bt_status_t btc_hf_client_init(void) clear_state(); - btc_hf_client_cb.initialized = true; + hf_client_local_param.btc_hf_client_cb.initialized = true; -#if CONFIG_BT_HFP_AUDIO_DATA_PATH_HCI +#if BTM_SCO_HCI_INCLUDED data_path = ESP_SCO_DATA_PATH_HCI; #else data_path = ESP_SCO_DATA_PATH_PCM; @@ -199,10 +188,10 @@ static bt_status_t connect_int( bt_bdaddr_t *bd_addr, uint16_t uuid ) return BT_STATUS_BUSY; } - btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_CONNECTING; - bdcpy(btc_hf_client_cb.connected_bda.address, bd_addr->address); + hf_client_local_param.btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_CONNECTING; + bdcpy(hf_client_local_param.btc_hf_client_cb.connected_bda.address, bd_addr->address); - BTA_HfClientOpen(btc_hf_client_cb.handle, btc_hf_client_cb.connected_bda.address, + BTA_HfClientOpen(hf_client_local_param.btc_hf_client_cb.handle, hf_client_local_param.btc_hf_client_cb.connected_bda.address, BTC_HF_CLIENT_SECURITY); return BT_STATUS_SUCCESS; @@ -232,7 +221,7 @@ void btc_hf_client_deinit( void ) btc_dm_disable_service(BTA_HFP_HS_SERVICE_ID); - btc_hf_client_cb.initialized = false; + hf_client_local_param.btc_hf_client_cb.initialized = false; } /******************************************************************************* @@ -250,7 +239,7 @@ bt_status_t btc_hf_client_disconnect( bt_bdaddr_t *bd_addr ) if (is_connected(bd_addr)) { - BTA_HfClientClose(btc_hf_client_cb.handle); + BTA_HfClientClose(hf_client_local_param.btc_hf_client_cb.handle); return BT_STATUS_SUCCESS; } @@ -272,13 +261,13 @@ bt_status_t btc_hf_client_connect_audio( bt_bdaddr_t *bd_addr ) if (is_connected(bd_addr)) { - if (btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_CODEC) + if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_CODEC) { - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BCC, 0, 0, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BCC, 0, 0, NULL); } else { - BTA_HfClientAudioOpen(btc_hf_client_cb.handle); + BTA_HfClientAudioOpen(hf_client_local_param.btc_hf_client_cb.handle); } /* Inform the application that the audio connection has been initiated successfully */ @@ -286,7 +275,7 @@ bt_status_t btc_hf_client_connect_audio( bt_bdaddr_t *bd_addr ) esp_hf_client_cb_param_t param; memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.audio_stat.state = ESP_HF_CLIENT_AUDIO_STATE_CONNECTING; - memcpy(param.audio_stat.remote_bda, &btc_hf_client_cb.connected_bda, sizeof(esp_bd_addr_t)); + memcpy(param.audio_stat.remote_bda, &hf_client_local_param.btc_hf_client_cb.connected_bda, sizeof(esp_bd_addr_t)); btc_hf_client_cb_to_app(ESP_HF_CLIENT_AUDIO_STATE_EVT, ¶m); } while (0); @@ -311,7 +300,7 @@ bt_status_t btc_hf_client_disconnect_audio( bt_bdaddr_t *bd_addr ) if (is_connected(bd_addr)) { - BTA_HfClientAudioClose(btc_hf_client_cb.handle); + BTA_HfClientAudioClose(hf_client_local_param.btc_hf_client_cb.handle); return BT_STATUS_SUCCESS; } @@ -331,9 +320,9 @@ static bt_status_t btc_hf_client_start_voice_recognition(void) { CHECK_HF_CLIENT_SLC_CONNECTED(); - if (btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_FEAT_VREC) + if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_FEAT_VREC) { - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BVRA, 1, 0, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BVRA, 1, 0, NULL); return BT_STATUS_SUCCESS; } @@ -355,9 +344,9 @@ static bt_status_t btc_hf_client_stop_voice_recognition(void) { CHECK_HF_CLIENT_SLC_CONNECTED(); - if (btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_FEAT_VREC) + if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_FEAT_VREC) { - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BVRA, 0, 0, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BVRA, 0, 0, NULL); return BT_STATUS_SUCCESS; } @@ -381,10 +370,10 @@ static bt_status_t btc_hf_client_volume_update(esp_hf_volume_control_target_t ty switch (type) { case ESP_HF_VOLUME_CONTROL_TARGET_SPK: - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_VGS, volume, 0, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_VGS, volume, 0, NULL); break; case ESP_HF_VOLUME_CONTROL_TARGET_MIC: - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_VGM, volume, 0, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_VGM, volume, 0, NULL); break; default: return BT_STATUS_UNSUPPORTED; @@ -408,11 +397,11 @@ static bt_status_t btc_hf_client_dial(const char *number) if (strlen(number) != 0) { - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_ATD, 0, 0, number); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_ATD, 0, 0, number); } else { - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BLDN, 0, 0, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BLDN, 0, 0, NULL); } return BT_STATUS_SUCCESS; @@ -431,7 +420,7 @@ static bt_status_t btc_hf_client_dial_memory(int location) { CHECK_HF_CLIENT_SLC_CONNECTED(); - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_ATD, location, 0, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_ATD, location, 0, NULL); return BT_STATUS_SUCCESS; } @@ -443,61 +432,61 @@ static bt_status_t btc_hf_client_send_chld_cmd(esp_hf_chld_type_t type, int idx) switch (type) { case ESP_HF_CHLD_TYPE_REL: - if (btc_hf_client_cb.chld_feat & BTA_HF_CLIENT_CHLD_REL) + if (hf_client_local_param.btc_hf_client_cb.chld_feat & BTA_HF_CLIENT_CHLD_REL) { - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 0, 0, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 0, 0, NULL); break; } return BT_STATUS_UNSUPPORTED; case ESP_HF_CHLD_TYPE_REL_ACC: // CHLD 1 is mandatory for 3 way calling - if (btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_FEAT_3WAY) + if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_FEAT_3WAY) { - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 1, 0, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 1, 0, NULL); break; } return BT_STATUS_UNSUPPORTED; case ESP_HF_CHLD_TYPE_HOLD_ACC: // CHLD 2 is mandatory for 3 way calling - if (btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_FEAT_3WAY) + if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_FEAT_3WAY) { - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 2, 0, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 2, 0, NULL); break; } return BT_STATUS_UNSUPPORTED; case ESP_HF_CHLD_TYPE_MERGE: - if (btc_hf_client_cb.chld_feat & BTA_HF_CLIENT_CHLD_MERGE) + if (hf_client_local_param.btc_hf_client_cb.chld_feat & BTA_HF_CLIENT_CHLD_MERGE) { - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 3, 0, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 3, 0, NULL); break; } return BT_STATUS_UNSUPPORTED; case ESP_HF_CHLD_TYPE_MERGE_DETACH: - if (btc_hf_client_cb.chld_feat & BTA_HF_CLIENT_CHLD_MERGE_DETACH) + if (hf_client_local_param.btc_hf_client_cb.chld_feat & BTA_HF_CLIENT_CHLD_MERGE_DETACH) { - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 4, 0, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 4, 0, NULL); break; } return BT_STATUS_UNSUPPORTED; case ESP_HF_CHLD_TYPE_REL_X: - if (btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_ECC) + if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_ECC) { if (idx < 1) { return BT_STATUS_FAIL; } - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 1, idx, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 1, idx, NULL); break; } return BT_STATUS_UNSUPPORTED; case ESP_HF_CHLD_TYPE_PRIV_X: - if (btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_ECC) + if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_ECC) { if (idx < 1) { return BT_STATUS_FAIL; } - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 2, idx, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 2, idx, NULL); break; } return BT_STATUS_UNSUPPORTED; @@ -512,13 +501,13 @@ static bt_status_t btc_hf_client_send_btrh_cmd(esp_hf_btrh_cmd_t btrh) switch (btrh) { case ESP_HF_BTRH_CMD_HOLD: - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BTRH, 0, 0, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BTRH, 0, 0, NULL); break; case ESP_HF_BTRH_CMD_ACCEPT: - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BTRH, 1, 0, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BTRH, 1, 0, NULL); break; case ESP_HF_BTRH_CMD_REJECT: - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BTRH, 2, 0, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BTRH, 2, 0, NULL); break; default: return BT_STATUS_FAIL; @@ -530,14 +519,14 @@ static bt_status_t btc_hf_client_send_btrh_cmd(esp_hf_btrh_cmd_t btrh) static bt_status_t btc_hf_client_answer_call(void) { CHECK_HF_CLIENT_SLC_CONNECTED(); - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_ATA, 0, 0, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_ATA, 0, 0, NULL); return BT_STATUS_SUCCESS; } static bt_status_t btc_hf_client_reject_call(void) { CHECK_HF_CLIENT_SLC_CONNECTED(); - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHUP, 0, 0, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHUP, 0, 0, NULL); return BT_STATUS_SUCCESS; } @@ -554,9 +543,9 @@ static bt_status_t btc_hf_client_query_current_calls(void) { CHECK_HF_CLIENT_SLC_CONNECTED(); - if (btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_ECS) + if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_ECS) { - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CLCC, 0, 0, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CLCC, 0, 0, NULL); return BT_STATUS_SUCCESS; } @@ -577,7 +566,7 @@ static bt_status_t btc_hf_client_query_current_operator_name(void) { CHECK_HF_CLIENT_SLC_CONNECTED(); - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_COPS, 0, 0, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_COPS, 0, 0, NULL); return BT_STATUS_SUCCESS; } @@ -595,7 +584,7 @@ static bt_status_t btc_hf_client_retrieve_subscriber_info(void) { CHECK_HF_CLIENT_SLC_CONNECTED(); - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CNUM, 0, 0, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CNUM, 0, 0, NULL); return BT_STATUS_SUCCESS; } @@ -613,7 +602,7 @@ static bt_status_t btc_hf_client_send_dtmf(char code) { CHECK_HF_CLIENT_SLC_CONNECTED(); - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_VTS, code, 0, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_VTS, code, 0, NULL); return BT_STATUS_SUCCESS; } @@ -631,9 +620,9 @@ static bt_status_t btc_hf_client_request_last_voice_tag_number(void) { CHECK_HF_CLIENT_SLC_CONNECTED(); - if (btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_VTAG) + if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_VTAG) { - BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BINP, 1, 0, NULL); + BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BINP, 1, 0, NULL); return BT_STATUS_SUCCESS; } @@ -694,17 +683,17 @@ bt_status_t btc_hf_client_execute_service(BOOLEAN b_enable) else { BTC_TRACE_EVENT("No Codec Nego Supported"); - btc_hf_client_features = BTC_HF_CLIENT_FEATURES; - btc_hf_client_features = btc_hf_client_features & (~BTA_HF_CLIENT_FEAT_CODEC); - BTC_TRACE_EVENT("btc_hf_client_features is %d", btc_hf_client_features); - BTA_HfClientRegister(BTC_HF_CLIENT_SECURITY, btc_hf_client_features, + hf_client_local_param.btc_hf_client_features = BTC_HF_CLIENT_FEATURES; + hf_client_local_param.btc_hf_client_features = hf_client_local_param.btc_hf_client_features & (~BTA_HF_CLIENT_FEAT_CODEC); + BTC_TRACE_EVENT("hf_client_local_param.btc_hf_client_features is %d", hf_client_local_param.btc_hf_client_features); + BTA_HfClientRegister(BTC_HF_CLIENT_SECURITY, hf_client_local_param.btc_hf_client_features, BTC_HF_CLIENT_SERVICE_NAME); } } else { - BTA_HfClientDeregister(btc_hf_client_cb.handle); + BTA_HfClientDeregister(hf_client_local_param.btc_hf_client_cb.handle); BTA_HfClientDisable(); } return BT_STATUS_SUCCESS; @@ -769,44 +758,43 @@ void btc_hf_client_cb_handler(btc_msg_t *msg) case BTA_HF_CLIENT_DISABLE_EVT: break; case BTA_HF_CLIENT_REGISTER_EVT: - btc_hf_client_cb.handle = p_data->reg.handle; + hf_client_local_param.btc_hf_client_cb.handle = p_data->reg.handle; break; case BTA_HF_CLIENT_OPEN_EVT: if (p_data->open.status == BTA_HF_CLIENT_SUCCESS) { - bdcpy(btc_hf_client_cb.connected_bda.address, p_data->open.bd_addr); - btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_CONNECTED; - btc_hf_client_cb.peer_feat = 0; - btc_hf_client_cb.chld_feat = 0; + bdcpy(hf_client_local_param.btc_hf_client_cb.connected_bda.address, p_data->open.bd_addr); + hf_client_local_param.btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_CONNECTED; + hf_client_local_param.btc_hf_client_cb.peer_feat = 0; + hf_client_local_param.btc_hf_client_cb.chld_feat = 0; //clear_phone_state(); } - else if (btc_hf_client_cb.state == ESP_HF_CLIENT_CONNECTION_STATE_CONNECTING) + else if (hf_client_local_param.btc_hf_client_cb.state == ESP_HF_CLIENT_CONNECTION_STATE_CONNECTING) { - btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_DISCONNECTED; + hf_client_local_param.btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_DISCONNECTED; } else { BTC_TRACE_WARNING("%s: HF CLient open failed, but another device connected. status=%d state=%d connected device=%s", - __FUNCTION__, p_data->open.status, btc_hf_client_cb.state, bdaddr_to_string(&btc_hf_client_cb.connected_bda, bdstr, sizeof(bdstr))); + __FUNCTION__, p_data->open.status, hf_client_local_param.btc_hf_client_cb.state, bdaddr_to_string(&hf_client_local_param.btc_hf_client_cb.connected_bda, bdstr, sizeof(bdstr))); UNUSED(bdstr); break; } do { memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); - param.conn_stat.state = btc_hf_client_cb.state; + param.conn_stat.state = hf_client_local_param.btc_hf_client_cb.state; param.conn_stat.peer_feat = 0; param.conn_stat.chld_feat = 0; - memcpy(param.conn_stat.remote_bda, &btc_hf_client_cb.connected_bda, + memcpy(param.conn_stat.remote_bda, &hf_client_local_param.btc_hf_client_cb.connected_bda, sizeof(esp_bd_addr_t)); btc_hf_client_cb_to_app(ESP_HF_CLIENT_CONNECTION_STATE_EVT, ¶m); } while (0); - if (btc_hf_client_cb.state == ESP_HF_CLIENT_CONNECTION_STATE_DISCONNECTED) { - bdsetany(btc_hf_client_cb.connected_bda.address); - } + if (hf_client_local_param.btc_hf_client_cb.state == ESP_HF_CLIENT_CONNECTION_STATE_DISCONNECTED) + bdsetany(hf_client_local_param.btc_hf_client_cb.connected_bda.address); if (p_data->open.status != BTA_HF_CLIENT_SUCCESS) { btc_queue_advance(); @@ -815,24 +803,24 @@ void btc_hf_client_cb_handler(btc_msg_t *msg) break; case BTA_HF_CLIENT_CONN_EVT: - btc_hf_client_cb.peer_feat = p_data->conn.peer_feat; - btc_hf_client_cb.chld_feat = p_data->conn.chld_feat; - btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_SLC_CONNECTED; + hf_client_local_param.btc_hf_client_cb.peer_feat = p_data->conn.peer_feat; + hf_client_local_param.btc_hf_client_cb.chld_feat = p_data->conn.chld_feat; + hf_client_local_param.btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_SLC_CONNECTED; do { memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); - param.conn_stat.state = btc_hf_client_cb.state; - param.conn_stat.peer_feat = btc_hf_client_cb.peer_feat; - param.conn_stat.chld_feat = btc_hf_client_cb.chld_feat; + param.conn_stat.state = hf_client_local_param.btc_hf_client_cb.state; + param.conn_stat.peer_feat = hf_client_local_param.btc_hf_client_cb.peer_feat; + param.conn_stat.chld_feat = hf_client_local_param.btc_hf_client_cb.chld_feat; - memcpy(param.conn_stat.remote_bda, &btc_hf_client_cb.connected_bda, + memcpy(param.conn_stat.remote_bda, &hf_client_local_param.btc_hf_client_cb.connected_bda, sizeof(esp_bd_addr_t)); btc_hf_client_cb_to_app(ESP_HF_CLIENT_CONNECTION_STATE_EVT, ¶m); } while (0); /* Inform the application about in-band ringtone */ - if (btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_INBAND) + if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_INBAND) { do { memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); @@ -845,22 +833,22 @@ void btc_hf_client_cb_handler(btc_msg_t *msg) break; case BTA_HF_CLIENT_CLOSE_EVT: - btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_DISCONNECTED; + hf_client_local_param.btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_DISCONNECTED; do { memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.conn_stat.state = ESP_HF_CLIENT_CONNECTION_STATE_DISCONNECTED; param.conn_stat.peer_feat = 0; param.conn_stat.chld_feat = 0; - memcpy(param.conn_stat.remote_bda, &btc_hf_client_cb.connected_bda, + memcpy(param.conn_stat.remote_bda, &hf_client_local_param.btc_hf_client_cb.connected_bda, sizeof(esp_bd_addr_t)); btc_hf_client_cb_to_app(ESP_HF_CLIENT_CONNECTION_STATE_EVT, ¶m); } while (0); - bdsetany(btc_hf_client_cb.connected_bda.address); - btc_hf_client_cb.peer_feat = 0; - btc_hf_client_cb.chld_feat = 0; + bdsetany(hf_client_local_param.btc_hf_client_cb.connected_bda.address); + hf_client_local_param.btc_hf_client_cb.peer_feat = 0; + hf_client_local_param.btc_hf_client_cb.chld_feat = 0; btc_queue_advance(); break; case BTA_HF_CLIENT_IND_EVT: @@ -983,7 +971,7 @@ void btc_hf_client_cb_handler(btc_msg_t *msg) do { memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.audio_stat.state = ESP_HF_CLIENT_AUDIO_STATE_CONNECTED; - memcpy(param.audio_stat.remote_bda, &btc_hf_client_cb.connected_bda, + memcpy(param.audio_stat.remote_bda, &hf_client_local_param.btc_hf_client_cb.connected_bda, sizeof(esp_bd_addr_t)); btc_hf_client_cb_to_app(ESP_HF_CLIENT_AUDIO_STATE_EVT, ¶m); } while (0); @@ -992,7 +980,7 @@ void btc_hf_client_cb_handler(btc_msg_t *msg) do { memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.audio_stat.state = ESP_HF_CLIENT_AUDIO_STATE_CONNECTED_MSBC; - memcpy(param.audio_stat.remote_bda, &btc_hf_client_cb.connected_bda, + memcpy(param.audio_stat.remote_bda, &hf_client_local_param.btc_hf_client_cb.connected_bda, sizeof(esp_bd_addr_t)); btc_hf_client_cb_to_app(ESP_HF_CLIENT_AUDIO_STATE_EVT, ¶m); } while (0); @@ -1001,7 +989,7 @@ void btc_hf_client_cb_handler(btc_msg_t *msg) do { memset(¶m, 0, sizeof(esp_hf_client_cb_param_t)); param.audio_stat.state = ESP_HF_CLIENT_AUDIO_STATE_DISCONNECTED; - memcpy(param.audio_stat.remote_bda, &btc_hf_client_cb.connected_bda, + memcpy(param.audio_stat.remote_bda, &hf_client_local_param.btc_hf_client_cb.connected_bda, sizeof(esp_bd_addr_t)); btc_hf_client_cb_to_app(ESP_HF_CLIENT_AUDIO_STATE_EVT, ¶m); } while (0); diff --git a/components/bt/bluedroid/btc/profile/std/include/btc_avrc.h b/components/bt/bluedroid/btc/profile/std/include/btc_avrc.h index 7eaabecc17..ec98c5ee56 100644 --- a/components/bt/bluedroid/btc/profile/std/include/btc_avrc.h +++ b/components/bt/bluedroid/btc/profile/std/include/btc_avrc.h @@ -86,6 +86,50 @@ typedef enum { BTC_AVRC_TG_API_SEND_RN_RSP_EVT, } btc_avrc_tg_act_t; +/***************************************************************************** +** Constants & Macros +******************************************************************************/ +/* for AVRC 1.4 need to change this */ +#define BTC_RC_CT_INIT_MAGIC 0x20181128 +#define BTC_RC_TG_INIT_MAGIC 0x20181129 + +#define MAX_RC_NOTIFICATIONS (13) // refer to ESP_AVRC_RN_MAX_EVT + + +#define CHECK_ESP_RC_CONNECTED do { \ + BTC_TRACE_DEBUG("## %s ##", __FUNCTION__); \ + if (btc_rc_cb.rc_connected == FALSE) { \ + BTC_TRACE_WARNING("Function %s() called when RC is not connected", __FUNCTION__); \ + return ESP_ERR_INVALID_STATE; \ + } \ + } while (0) + +/***************************************************************************** +** Local type definitions +******************************************************************************/ +typedef struct { + BOOLEAN registered; + UINT8 label; +} btc_rc_reg_ntf_t; + +typedef struct { + BOOLEAN rc_connected; + UINT8 rc_handle; + tBTA_AV_FEAT rc_features; + UINT16 rc_ct_features; + UINT16 rc_tg_features; + BD_ADDR rc_addr; + btc_rc_reg_ntf_t rc_ntf[MAX_RC_NOTIFICATIONS]; +} btc_rc_cb_t; + +/***************************************************************************** +** Static variables +******************************************************************************/ +#if AVRC_DYNAMIC_MEMORY == TRUE +extern btc_rc_cb_t *btc_rc_cb_ptr; +#define btc_rc_cb (*btc_rc_cb_ptr) +#endif ///AVRC_DYNAMIC_MEMORY == FALSE + typedef struct { esp_avrc_rn_event_ids_t event_id; esp_avrc_rn_rsp_t rsp; diff --git a/components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h b/components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h index be818269b2..b5e2effe7e 100644 --- a/components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h +++ b/components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h @@ -18,6 +18,14 @@ #include "esp_bt_defs.h" #include "esp_gap_ble_api.h" +#if BTC_DYNAMIC_MENDRY == TRUE +#include "bta/bta_api.h" +extern tBTA_BLE_ADV_DATA *gl_bta_adv_data_ptr; +extern tBTA_BLE_ADV_DATA *gl_bta_scan_rsp_data_ptr; +#define gl_bta_adv_data (*gl_bta_adv_data_ptr) +#define gl_bta_scan_rsp_data (*gl_bta_scan_rsp_data_ptr) +#endif + #define BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == ESP_BLE_CONN_PARAM_UNDEF)) typedef enum { diff --git a/components/bt/bluedroid/btc/profile/std/include/btc_gatts.h b/components/bt/bluedroid/btc/profile/std/include/btc_gatts.h index cad973a8a6..5cf1e84161 100644 --- a/components/bt/bluedroid/btc/profile/std/include/btc_gatts.h +++ b/components/bt/bluedroid/btc/profile/std/include/btc_gatts.h @@ -19,6 +19,7 @@ #include "esp_bt_defs.h" #include "esp_gatt_defs.h" #include "esp_gatts_api.h" +#include "osi/future.h" typedef enum { BTC_GATTS_ACT_APP_REGISTER = 0, @@ -150,6 +151,21 @@ typedef union { } btc_ble_gatts_args_t; +typedef struct { + future_t *complete_future; + uint16_t svc_start_hdl; + esp_bt_uuid_t svc_uuid; + bool is_tab_creat_svc; + bool is_use_svc; + uint8_t num_handle; + uint8_t handle_idx; + uint16_t handles[ESP_GATT_ATTR_HANDLE_MAX]; +} esp_btc_creat_tab_t; + +#if GATT_DYNAMIC_MEMORY == TRUE +extern esp_btc_creat_tab_t *btc_creat_tab_env_ptr; +#define btc_creat_tab_env (*btc_creat_tab_env_ptr) +#endif void btc_gatts_call_handler(btc_msg_t *msg); void btc_gatts_cb_handler(btc_msg_t *msg); diff --git a/components/bt/bluedroid/btc/profile/std/include/btc_hf_client.h b/components/bt/bluedroid/btc/profile/std/include/btc_hf_client.h index 6500b9d878..04226e72a2 100644 --- a/components/bt/bluedroid/btc/profile/std/include/btc_hf_client.h +++ b/components/bt/bluedroid/btc/profile/std/include/btc_hf_client.h @@ -112,6 +112,34 @@ typedef union { } reg_data_cb; } btc_hf_client_args_t; +/************************************************************************************ +** Local type definitions +************************************************************************************/ +/* BTC-HF control block to map bdaddr to BTA handle */ +typedef struct +{ + bool initialized; + UINT16 handle; + bt_bdaddr_t connected_bda; + esp_hf_client_connection_state_t state; + esp_hf_vr_state_t vr_state; + tBTA_HF_CLIENT_PEER_FEAT peer_feat; + tBTA_HF_CLIENT_CHLD_FEAT chld_feat; +} btc_hf_client_cb_t; + +typedef struct +{ + UINT32 btc_hf_client_features; + btc_hf_client_cb_t btc_hf_client_cb; + esp_hf_client_incoming_data_cb_t btc_hf_client_incoming_data_cb; + esp_hf_client_outgoing_data_cb_t btc_hf_client_outgoing_data_cb; +}hf_client_local_param_t; + +#if HFP_DYNAMIC_MEMORY == TRUE +extern hf_client_local_param_t *hf_client_local_param_ptr; +#define hf_client_local_param (*hf_client_local_param_ptr) +#endif + /******************************************************************************* ** BTC HF AG API ********************************************************************************/ diff --git a/components/bt/bluedroid/btc/profile/std/spp/btc_spp.c b/components/bt/bluedroid/btc/profile/std/spp/btc_spp.c index bc2d62427d..93636ef71c 100644 --- a/components/bt/bluedroid/btc/profile/std/spp/btc_spp.c +++ b/components/bt/bluedroid/btc/profile/std/spp/btc_spp.c @@ -55,13 +55,20 @@ typedef struct { char service_name[ESP_SPP_SERVER_NAME_MAX + 1]; } spp_slot_t; -static struct spp_local_param_t { +typedef struct { spp_slot_t *spp_slots[BTA_JV_MAX_RFC_SR_SESSION + 1]; uint32_t spp_slot_id; esp_spp_mode_t spp_mode; osi_mutex_t spp_slot_mutex; esp_vfs_id_t spp_vfs_id; -} spp_local_param; +} spp_local_param_t; + +#if SPP_DYNAMIC_MEMORY == FALSE +static spp_local_param_t spp_local_param; +#else +static spp_local_param_t *spp_local_param_ptr; +#define spp_local_param (*spp_local_param_ptr) +#endif static void spp_osi_free(void *p) { @@ -313,6 +320,15 @@ static void btc_spp_dm_inter_cb(tBTA_JV_EVT event, tBTA_JV *p_data, void *user_d static void btc_spp_init(btc_spp_args_t *arg) { + +#if SPP_DYNAMIC_MEMORY == TRUE + if ((spp_local_param_ptr = (spp_local_param_t *)osi_malloc(sizeof(spp_local_param_t))) == NULL) { + BTC_TRACE_ERROR("%s malloc failed\n", __func__); + return; + } + memset((void *)spp_local_param_ptr, 0, sizeof(spp_local_param_t)); +#endif + if (osi_mutex_new(&spp_local_param.spp_slot_mutex) != 0) { BTC_TRACE_ERROR("%s osi_mutex_new failed\n", __func__); return; @@ -349,6 +365,11 @@ static void btc_spp_uninit(void) BTA_JvDisable(); osi_mutex_unlock(&spp_local_param.spp_slot_mutex); osi_mutex_free(&spp_local_param.spp_slot_mutex); + +#if SPP_DYNAMIC_MEMORY == TRUE + osi_free(spp_local_param_ptr); + spp_local_param_ptr = NULL; +#endif } static void btc_spp_start_discovery(btc_spp_args_t *arg) diff --git a/components/bt/bluedroid/common/include/common/bt_target.h b/components/bt/bluedroid/common/include/common/bt_target.h index 8b504e0010..6adf32a9f5 100644 --- a/components/bt/bluedroid/common/include/common/bt_target.h +++ b/components/bt/bluedroid/common/include/common/bt_target.h @@ -34,17 +34,25 @@ #include "bdroid_buildcfg.h" #endif -#include "sdkconfig.h" +#include "bt_user_config.h" #include "stack/bt_types.h" /* This must be defined AFTER buildcfg.h */ #include "stack/dyn_mem.h" /* defines static and/or dynamic memory for components */ + +/* OS Configuration from User config (eg: sdkconfig) */ +#define TASK_PINNED_TO_CORE UC_TASK_PINNED_TO_CORE +#define BT_TASK_MAX_PRIORITIES configMAX_PRIORITIES +#define BT_BTC_TASK_STACK_SIZE UC_BTC_TASK_STACK_SIZE +#define A2DP_SINK_TASK_STACK_SIZE UC_A2DP_SINK_TASK_STACK_SIZE +#define A2DP_SOURCE_TASK_STACK_SIZE UC_A2DP_SOURCE_TASK_STACK_SIZE + /****************************************************************************** ** ** Classic BT features ** ******************************************************************************/ -#if CONFIG_BT_CLASSIC_ENABLED +#if (UC_BT_CLASSIC_ENABLED == TRUE) #define CLASSIC_BT_INCLUDED TRUE #define BTC_SM_INCLUDED TRUE #define BTC_PRF_QUEUE_INCLUDED TRUE @@ -53,7 +61,7 @@ #define BTA_DM_PM_INCLUDED TRUE #define SDP_INCLUDED TRUE -#if CONFIG_BT_A2DP_ENABLE +#if (UC_BT_A2DP_ENABLED == TRUE) #define BTA_AR_INCLUDED TRUE #define BTA_AV_INCLUDED TRUE #define AVDT_INCLUDED TRUE @@ -66,15 +74,15 @@ #define SBC_DEC_INCLUDED TRUE #define BTC_AV_SRC_INCLUDED TRUE #define SBC_ENC_INCLUDED TRUE -#endif /* CONFIG_BT_A2DP_ENABLE */ +#endif /* UC_BT_A2DP_ENABLED */ -#if CONFIG_BT_SPP_ENABLED +#if (UC_BT_SPP_ENABLED == TRUE) #define RFCOMM_INCLUDED TRUE #define BTA_JV_INCLUDED TRUE #define BTC_SPP_INCLUDED TRUE -#endif /* CONFIG_BT_SPP_ENABLED */ +#endif /* UC_BT_SPP_ENABLED */ -#if CONFIG_BT_HFP_CLIENT_ENABLE +#if (UC_BT_HFP_CLIENT_ENABLED == TRUE) #define BTC_HF_CLIENT_INCLUDED TRUE #define BTA_HF_INCLUDED TRUE #define PLC_INCLUDED TRUE @@ -87,96 +95,91 @@ #ifndef BTM_MAX_SCO_LINKS #define BTM_MAX_SCO_LINKS (1) #endif + #ifndef SBC_DEC_INCLUDED #define SBC_DEC_INCLUDED TRUE #endif #ifndef SBC_ENC_INCLUDED #define SBC_ENC_INCLUDED TRUE #endif -#endif /* CONFIG_HFP_HF_ENABLE */ +#endif /* UC_BT_HFP_CLIENT_ENABLED */ -#if CONFIG_BT_SSP_ENABLED +#if UC_BT_SSP_ENABLED #define BT_SSP_INCLUDED TRUE -#endif /* CONFIG_BT_SSP_ENABLED */ +#endif /* UC_BT_SSP_ENABLED */ -#endif /* #if CONFIG_BT_CLASSIC_ENABLED */ +#endif /* UC_BT_CLASSIC_ENABLED */ #ifndef CLASSIC_BT_INCLUDED #define CLASSIC_BT_INCLUDED FALSE #endif /* CLASSIC_BT_INCLUDED */ -#ifndef CONFIG_BT_GATTC_CACHE_NVS_FLASH -#define CONFIG_BT_GATTC_CACHE_NVS_FLASH FALSE -#endif /* CONFIG_BT_GATTC_CACHE_NVS_FLASH */ - /****************************************************************************** ** ** BLE features ** ******************************************************************************/ -#if (CONFIG_BT_GATTS_ENABLE) +#if (UC_BT_BLE_ENABLED ==TRUE) +#define BLE_INCLUDED TRUE +#else +#define BLE_INCLUDED FALSE +#endif /* UC_BT_BLE_ENABLED */ + +#if (UC_BT_GATTS_ENABLE) #define GATTS_INCLUDED TRUE #else #define GATTS_INCLUDED FALSE -#endif /* CONFIG_BT_GATTS_ENABLE */ +#endif /* UC_BT_GATTS_ENABLE */ -#if (CONFIG_BT_GATTC_ENABLE) +#if (UC_BT_GATTC_ENABLE) #define GATTC_INCLUDED TRUE #else #define GATTC_INCLUDED FALSE -#endif /* CONFIG_BT_GATTC_ENABLE */ +#endif /* UC_BT_GATTC_ENABLE */ -#if (CONFIG_BT_GATTC_ENABLE && CONFIG_BT_GATTC_CACHE_NVS_FLASH) -#define GATTC_CACHE_NVS TRUE +#if (UC_BT_GATTC_ENABLE && UC_BT_GATTC_CACHE_NVS_FLASH_ENABLED) +#define GATTC_CACHE_NVS TRUE #else -#define GATTC_CACHE_NVS FALSE -#endif /* CONFIG_BT_GATTC_CACHE_NVS_FLASH */ +#define GATTC_CACHE_NVS FALSE +#endif /* UC_BT_GATTC_ENABLE && UC_BT_GATTC_CACHE_NVS_FLASH_ENABLED */ -#if (CONFIG_BT_SMP_ENABLE) -#define SMP_INCLUDED TRUE -#define BLE_PRIVACY_SPT TRUE +#if (UC_BT_SMP_ENABLE) +#define SMP_INCLUDED TRUE +#if (BLE_INCLUDED == TRUE) +#define BLE_PRIVACY_SPT TRUE #else -#define SMP_INCLUDED FALSE -#define BLE_PRIVACY_SPT FALSE -#endif /* CONFIG_BT_SMP_ENABLE */ +#define BLE_PRIVACY_SPT FALSE +#endif /*BLE_INCLUDED*/ +#else +#define SMP_INCLUDED FALSE +#define BLE_PRIVACY_SPT FALSE +#endif /* UC_BT_SMP_ENABLE */ -#ifdef CONFIG_BT_SMP_SLAVE_CON_PARAMS_UPD_ENABLE -#if(CONFIG_BT_SMP_SLAVE_CON_PARAMS_UPD_ENABLE) -#define SMP_SLAVE_CON_PARAMS_UPD_ENABLE TRUE +#if(UC_BT_SMP_SLAVE_CON_PARAMS_UPD_ENABLE) +#define SMP_SLAVE_CON_PARAMS_UPD_ENABLE TRUE #else -#define SMP_SLAVE_CON_PARAMS_UPD_ENABLE FALSE -#endif -#else -#define SMP_SLAVE_CON_PARAMS_UPD_ENABLE FALSE -#endif +#define SMP_SLAVE_CON_PARAMS_UPD_ENABLE FALSE +#endif /* UC_BT_SMP_SLAVE_CON_PARAMS_UPD_ENABLE */ -#ifndef CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP -#define BLE_ADV_REPORT_FLOW_CONTROL FALSE -#else -#define BLE_ADV_REPORT_FLOW_CONTROL CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP -#endif /* CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP */ +#ifdef UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP +#define BLE_ADV_REPORT_FLOW_CONTROL UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP +#endif /* UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP */ -#ifndef CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM -#define BLE_ADV_REPORT_FLOW_CONTROL_NUM 100 -#else -#define BLE_ADV_REPORT_FLOW_CONTROL_NUM CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM -#endif /* CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM */ +#ifdef UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM +#define BLE_ADV_REPORT_FLOW_CONTROL_NUM UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM +#endif /* UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM */ -#ifndef CONFIG_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD -#define BLE_ADV_REPORT_DISCARD_THRSHOLD 20 -#else -#define BLE_ADV_REPORT_DISCARD_THRSHOLD CONFIG_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD -#endif /* CONFIG_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD */ +#ifdef UC_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD +#define BLE_ADV_REPORT_DISCARD_THRSHOLD UC_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD +#endif /* UC_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD */ -#if (CONFIG_BT_ACL_CONNECTIONS) -#define MAX_ACL_CONNECTIONS CONFIG_BT_ACL_CONNECTIONS -#define GATT_MAX_PHY_CHANNEL CONFIG_BT_ACL_CONNECTIONS -#endif /* CONFIG_BT_ACL_CONNECTIONS */ +#ifdef UC_BT_ACL_CONNECTIONS +#define MAX_ACL_CONNECTIONS UC_BT_ACL_CONNECTIONS +#define GATT_MAX_PHY_CHANNEL UC_BT_ACL_CONNECTIONS +#endif /* UC_BT_ACL_CONNECTIONS */ -#if(CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT) -#define BLE_ESTABLISH_LINK_CONNECTION_TIMEOUT CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT -#else -#define BLE_ESTABLISH_LINK_CONNECTION_TIMEOUT 30 +#ifdef UC_BT_BLE_ESTAB_LINK_CONN_TOUT +#define BLE_ESTABLISH_LINK_CONNECTION_TIMEOUT UC_BT_BLE_ESTAB_LINK_CONN_TOUT #endif //------------------Added from bdroid_buildcfg.h--------------------- @@ -333,7 +336,7 @@ #endif #ifndef BTA_AVRCP_FF_RW_SUPPORT -#define BTA_AVRCP_FF_RW_SUPPORT FALSE//TRUE +#define BTA_AVRCP_FF_RW_SUPPORT FALSE #endif #ifndef BTA_AG_SCO_PKT_TYPES @@ -349,34 +352,30 @@ #endif #ifndef BTA_AV_CO_CP_SCMS_T -#define BTA_AV_CO_CP_SCMS_T FALSE//FALSE +#define BTA_AV_CO_CP_SCMS_T FALSE #endif #ifndef QUEUE_CONGEST_SIZE #define QUEUE_CONGEST_SIZE 40 #endif -#ifndef CONFIG_BT_BLE_HOST_QUEUE_CONG_CHECK +#if UC_BT_BLE_HOST_QUEUE_CONGESTION_CHECK +#define SCAN_QUEUE_CONGEST_CHECK TRUE +#else #define SCAN_QUEUE_CONGEST_CHECK FALSE -#else -#define SCAN_QUEUE_CONGEST_CHECK CONFIG_BT_BLE_HOST_QUEUE_CONG_CHECK #endif -#ifndef CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MODE -#define GATTS_SEND_SERVICE_CHANGE_MODE GATTS_SEND_SERVICE_CHANGE_AUTO -#else -#define GATTS_SEND_SERVICE_CHANGE_MODE CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MODE +#ifdef UC_BT_GATTS_SEND_SERVICE_CHANGE_MODE +#define GATTS_SEND_SERVICE_CHANGE_MODE UC_BT_GATTS_SEND_SERVICE_CHANGE_MODE #endif -#ifndef CONFIG_BT_BLE_ACT_SCAN_REP_ADV_SCAN -#define BTM_BLE_ACTIVE_SCAN_REPORT_ADV_SCAN_RSP_INDIVIDUALLY FALSE -#else -#define BTM_BLE_ACTIVE_SCAN_REPORT_ADV_SCAN_RSP_INDIVIDUALLY CONFIG_BT_BLE_ACT_SCAN_REP_ADV_SCAN +#ifdef UC_BT_BLE_ACT_SCAN_REP_ADV_SCAN +#define BTM_BLE_ACTIVE_SCAN_REPORT_ADV_SCAN_RSP_INDIVIDUALLY UC_BT_BLE_ACT_SCAN_REP_ADV_SCAN #endif /* This feature is used to eanble interleaved scan*/ #ifndef BTA_HOST_INTERLEAVE_SEARCH -#define BTA_HOST_INTERLEAVE_SEARCH FALSE//FALSE +#define BTA_HOST_INTERLEAVE_SEARCH FALSE #endif #ifndef BT_USE_TRACES @@ -404,7 +403,7 @@ #endif #ifndef BTIF_DM_OOB_TEST -#define BTIF_DM_OOB_TEST FALSE//TRUE +#define BTIF_DM_OOB_TEST FALSE #endif // How long to wait before activating sniff mode after entering the @@ -589,11 +588,11 @@ /* Includes SCO if TRUE */ #ifndef BTM_SCO_HCI_INCLUDED -#if CONFIG_BT_HFP_AUDIO_DATA_PATH_HCI +#if UC_BT_HFP_AUDIO_DATA_PATH_HCI #define BTM_SCO_HCI_INCLUDED TRUE /* TRUE includes SCO over HCI code */ #else #define BTM_SCO_HCI_INCLUDED FALSE -#endif /* CONFIG_BT_HFP_AUDIO_DATA_PATH_HCI */ +#endif /* UC_HFP_AUDIO_DATA_PATH_HCI */ #endif /* Includes WBS if TRUE */ @@ -1035,7 +1034,7 @@ ******************************************************************************/ #ifndef BLE_INCLUDED -#define BLE_INCLUDED TRUE +#define BLE_INCLUDED FALSE #endif #ifndef BLE_ANDROID_CONTROLLER_SCAN_FILTER @@ -1127,7 +1126,7 @@ #endif #ifndef ATT_DEBUG -#define ATT_DEBUG FALSE//TRUE +#define ATT_DEBUG FALSE #endif #ifndef BLE_PERIPHERAL_MODE_SUPPORT @@ -1192,12 +1191,6 @@ #endif #endif - -#if SMP_INCLUDED == TRUE && BLE_INCLUDED == FALSE -#error "can't have SMP without BLE" -#endif - - /****************************************************************************** ** ** SMP @@ -1211,10 +1204,6 @@ #endif #endif -#if SMP_INCLUDED == TRUE && BLE_INCLUDED == FALSE -#error "can't have SMP without BLE" -#endif - #ifndef SMP_DEBUG #define SMP_DEBUG FALSE #endif @@ -1529,12 +1518,12 @@ Range: 2 octets ******************************************************************************/ #ifndef BNEP_INCLUDED -#define BNEP_INCLUDED FALSE//TRUE +#define BNEP_INCLUDED FALSE #endif /* BNEP status API call is used mainly to get the L2CAP handle */ #ifndef BNEP_SUPPORTS_STATUS_API -#define BNEP_SUPPORTS_STATUS_API FALSE//TRUE +#define BNEP_SUPPORTS_STATUS_API FALSE #endif /* @@ -1542,7 +1531,7 @@ Range: 2 octets ** we will do an authentication check again on the new role */ #ifndef BNEP_DO_AUTH_FOR_ROLE_SWITCH -#define BNEP_DO_AUTH_FOR_ROLE_SWITCH FALSE//TRUE +#define BNEP_DO_AUTH_FOR_ROLE_SWITCH FALSE #endif @@ -1655,22 +1644,22 @@ Range: 2 octets /* This will enable the PANU role */ #ifndef PAN_SUPPORTS_ROLE_PANU -#define PAN_SUPPORTS_ROLE_PANU FALSE//TRUE +#define PAN_SUPPORTS_ROLE_PANU FALSE #endif /* This will enable the GN role */ #ifndef PAN_SUPPORTS_ROLE_GN -#define PAN_SUPPORTS_ROLE_GN FALSE//TRUE +#define PAN_SUPPORTS_ROLE_GN FALSE #endif /* This will enable the NAP role */ #ifndef PAN_SUPPORTS_ROLE_NAP -#define PAN_SUPPORTS_ROLE_NAP FALSE//TRUE +#define PAN_SUPPORTS_ROLE_NAP FALSE #endif /* This is just for debugging purposes */ #ifndef PAN_SUPPORTS_DEBUG_DUMP -#define PAN_SUPPORTS_DEBUG_DUMP FALSE//TRUE +#define PAN_SUPPORTS_DEBUG_DUMP FALSE #endif /* Maximum number of PAN connections allowed */ @@ -1992,7 +1981,7 @@ The maximum number of payload octets that the local device can receive in a sing ******************************************************************************/ #ifndef HCILP_INCLUDED -#define HCILP_INCLUDED FALSE//TRUE +#define HCILP_INCLUDED FALSE #endif /****************************************************************************** @@ -2034,7 +2023,7 @@ The maximum number of payload octets that the local device can receive in a sing #endif #ifndef BTA_DM_AVOID_A2DP_ROLESWITCH_ON_INQUIRY -#define BTA_DM_AVOID_A2DP_ROLESWITCH_ON_INQUIRY FALSE//TRUE +#define BTA_DM_AVOID_A2DP_ROLESWITCH_ON_INQUIRY FALSE #endif /****************************************************************************** @@ -2045,7 +2034,19 @@ The maximum number of payload octets that the local device can receive in a sing /* Enable/disable BTSnoop memory logging */ #ifndef BTSNOOP_MEM -#define BTSNOOP_MEM FALSE//TRUE +#define BTSNOOP_MEM FALSE +#endif + +#if UC_BT_BLUEDROID_MEM_DEBUG +#define HEAP_MEMORY_DEBUG TRUE +#else +#define HEAP_MEMORY_DEBUG FALSE +#endif + +#if UC_HEAP_ALLOCATION_FROM_SPIRAM_FIRST +#define HEAP_ALLOCATION_FROM_SPIRAM_FIRST TRUE +#else +#define HEAP_ALLOCATION_FROM_SPIRAM_FIRST FALSE #endif #include "common/bt_trace.h" diff --git a/components/bt/bluedroid/common/include/common/bt_trace.h b/components/bt/bluedroid/common/include/common/bt_trace.h index a0dbf9bc72..920cfa7134 100644 --- a/components/bt/bluedroid/common/include/common/bt_trace.h +++ b/components/bt/bluedroid/common/include/common/bt_trace.h @@ -19,17 +19,16 @@ #ifndef _BT_TRACE_H_ #define _BT_TRACE_H_ -#include "sdkconfig.h" - #include #include +#include "bt_user_config.h" #include "stack/bt_types.h" #ifndef LOG_LOCAL_LEVEL #ifndef BOOTLOADER_BUILD -#define LOG_LOCAL_LEVEL CONFIG_LOG_DEFAULT_LEVEL +#define LOG_LOCAL_LEVEL UC_LOG_DEFAULT_LEVEL #else -#define LOG_LOCAL_LEVEL CONFIG_BOOTLOADER_LOG_LEVEL +#define LOG_LOCAL_LEVEL UC_BOOTLOADER_LOG_LEVEL #endif #endif @@ -217,135 +216,31 @@ inline void trc_dump_buffer(const char *prefix, uint8_t *data, uint16_t len) // btla-specific ++ /* Core Stack default trace levels */ -#ifdef CONFIG_BT_LOG_HCI_TRACE_LEVEL -#define HCI_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_HCI_TRACE_LEVEL -#else -#define HCI_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif - -#ifdef CONFIG_BT_LOG_BTM_TRACE_LEVEL -#define BTM_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_BTM_TRACE_LEVEL -#else -#define BTM_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif - -#ifdef CONFIG_BT_LOG_L2CAP_TRACE_LEVEL -#define L2CAP_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_L2CAP_TRACE_LEVEL -#else -#define L2CAP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif - -#ifdef CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL -#define RFCOMM_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL -#else -#define RFCOMM_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif - -#ifdef CONFIG_SDP_INITIAL_TRACE_LEVEL -#define SDP_INITIAL_TRACE_LEVEL CONFIG_SDP_INITIAL_TRACE_LEVEL -#else -#define SDP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif - -#ifdef CONFIG_BT_LOG_GAP_TRACE_LEVEL -#define GAP_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_GAP_TRACE_LEVEL -#else -#define GAP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif - -#ifdef CONFIG_BT_LOG_BNEP_TRACE_LEVEL -#define BNEP_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_BNEP_TRACE_LEVEL -#else -#define BNEP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif - -#ifdef CONFIG_BT_LOG_PAN_TRACE_LEVEL -#define PAN_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_PAN_TRACE_LEVEL -#else -#define PAN_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif - -#ifdef CONFIG_BT_LOG_A2D_TRACE_LEVEL -#define A2D_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_A2D_TRACE_LEVEL -#else -#define A2D_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif - -#ifdef CONFIG_BT_LOG_AVDT_TRACE_LEVEL -#define AVDT_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_AVDT_TRACE_LEVEL -#else -#define AVDT_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif - -#ifdef CONFIG_BT_LOG_AVCT_TRACE_LEVEL -#define AVCT_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_AVCT_TRACE_LEVEL -#else -#define AVCT_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif - -#ifdef CONFIG_BT_LOG_AVRC_TRACE_LEVEL -#define AVRC_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_AVRC_TRACE_LEVEL -#else -#define AVRC_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif - -#ifdef CONFIG_BT_LOG_MCA_TRACE_LEVEL -#define MCA_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_MCA_TRACE_LEVEL -#else -#define MCA_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif - -#ifdef CONFIG_BT_LOG_HID_TRACE_LEVEL -#define HID_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_HID_TRACE_LEVEL -#else -#define HID_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif - -#ifdef CONFIG_BT_LOG_APPL_TRACE_LEVEL -#define APPL_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_APPL_TRACE_LEVEL -#else -#define APPL_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif - -#ifdef CONFIG_BT_LOG_GATT_TRACE_LEVEL -#define GATT_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_GATT_TRACE_LEVEL -#else -#define GATT_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif - -#ifdef CONFIG_BT_LOG_SMP_TRACE_LEVEL -#define SMP_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_SMP_TRACE_LEVEL -#else -#define SMP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif - -#ifdef CONFIG_BT_LOG_BTIF_TRACE_LEVEL -#define BTIF_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_BTIF_TRACE_LEVEL -#else -#define BTIF_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif - -#ifdef CONFIG_BT_LOG_BTC_TRACE_LEVEL -#define BTC_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_BTC_TRACE_LEVEL -#else -#define BTC_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif - -#ifdef CONFIG_BT_LOG_OSI_TRACE_LEVEL -#define OSI_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_OSI_TRACE_LEVEL -#else -#define OSI_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif - -#ifdef CONFIG_BT_LOG_BLUFI_TRACE_LEVEL -#define BLUFI_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_BLUFI_TRACE_LEVEL -#else -#define BLUFI_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif +#define HCI_INITIAL_TRACE_LEVEL UC_BT_LOG_HCI_TRACE_LEVEL +#define BTM_INITIAL_TRACE_LEVEL UC_BT_LOG_BTM_TRACE_LEVEL +#define L2CAP_INITIAL_TRACE_LEVEL UC_BT_LOG_L2CAP_TRACE_LEVEL +#define RFCOMM_INITIAL_TRACE_LEVEL UC_BT_LOG_RFCOMM_TRACE_LEVEL +#define SDP_INITIAL_TRACE_LEVEL UC_BT_LOG_SDP_TRACE_LEVEL +#define GAP_INITIAL_TRACE_LEVEL UC_BT_LOG_GAP_TRACE_LEVEL +#define BNEP_INITIAL_TRACE_LEVEL UC_BT_LOG_BNEP_TRACE_LEVEL +#define PAN_INITIAL_TRACE_LEVEL UC_BT_LOG_PAN_TRACE_LEVEL +#define A2D_INITIAL_TRACE_LEVEL UC_BT_LOG_A2D_TRACE_LEVEL +#define AVDT_INITIAL_TRACE_LEVEL UC_BT_LOG_AVDT_TRACE_LEVEL +#define AVCT_INITIAL_TRACE_LEVEL UC_BT_LOG_AVCT_TRACE_LEVEL +#define AVRC_INITIAL_TRACE_LEVEL UC_BT_LOG_AVRC_TRACE_LEVEL +#define MCA_INITIAL_TRACE_LEVEL UC_BT_LOG_MCA_TRACE_LEVEL +#define HID_INITIAL_TRACE_LEVEL UC_BT_LOG_HID_TRACE_LEVEL +#define APPL_INITIAL_TRACE_LEVEL UC_BT_LOG_APPL_TRACE_LEVEL +#define GATT_INITIAL_TRACE_LEVEL UC_BT_LOG_GATT_TRACE_LEVEL +#define SMP_INITIAL_TRACE_LEVEL UC_BT_LOG_SMP_TRACE_LEVEL +#define BTIF_INITIAL_TRACE_LEVEL UC_BT_LOG_BTIF_TRACE_LEVEL +#define BTC_INITIAL_TRACE_LEVEL UC_BT_LOG_BTC_TRACE_LEVEL +#define OSI_INITIAL_TRACE_LEVEL UC_BT_LOG_OSI_TRACE_LEVEL +#define BLUFI_INITIAL_TRACE_LEVEL UC_BT_LOG_BLUFI_TRACE_LEVEL // btla-specific -- -#if !CONFIG_BT_STACK_NO_LOG +#if !UC_BT_STACK_NO_LOG #define LOG_ERROR(format, ... ) {if (LOG_LOCAL_LEVEL >= ESP_LOG_ERROR) esp_log_write(ESP_LOG_ERROR, "BT_LOG", LOG_FORMAT(E, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__); } #define LOG_WARN(format, ... ) {if (LOG_LOCAL_LEVEL >= ESP_LOG_WARN) esp_log_write(ESP_LOG_WARN, "BT_LOG", LOG_FORMAT(W, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__); } #define LOG_INFO(format, ... ) {if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) esp_log_write(ESP_LOG_INFO, "BT_LOG", LOG_FORMAT(I, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__); } @@ -695,7 +590,7 @@ extern UINT8 btif_trace_level; #define BLUFI_TRACE_EVENT(fmt, args...) #define BLUFI_TRACE_DEBUG(fmt, args...) #define BLUFI_TRACE_VERBOSE(fmt, args...) -#endif ///CONFIG_BT_STACK_NO_LOG +#endif ///!UC_BT_STACK_NO_LOG /* Simplified Trace Helper Macro diff --git a/components/bt/bluedroid/common/include/common/bt_user_config.h b/components/bt/bluedroid/common/include/common/bt_user_config.h new file mode 100644 index 0000000000..7fa8ed5c51 --- /dev/null +++ b/components/bt/bluedroid/common/include/common/bt_user_config.h @@ -0,0 +1,375 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// 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. + +#ifndef __BT_USER_CONFIG_H__ +#define __BT_USER_CONFIG_H__ + +/* All the configuration from SDK defined here */ + +#include "sdkconfig.h" +#include "esp_task.h" + + +/********************************************************** + * Thread/Task reference + **********************************************************/ +#ifdef CONFIG_BLUEDROID_PINNED_TO_CORE +#define UC_TASK_PINNED_TO_CORE (CONFIG_BLUEDROID_PINNED_TO_CORE < portNUM_PROCESSORS ? CONFIG_BLUEDROID_PINNED_TO_CORE : tskNO_AFFINITY) +#else +#define UC_TASK_PINNED_TO_CORE (0) +#endif + +#ifdef CONFIG_BTC_TASK_STACK_SIZE +#define UC_BTC_TASK_STACK_SIZE CONFIG_BTC_TASK_STACK_SIZE +#else +#define UC_BTC_TASK_STACK_SIZE 3072 +#endif + +#ifdef CONFIG_A2DP_SINK_TASK_STACK_SIZE +#define UC_A2DP_SINK_TASK_STACK_SIZE CONFIG_A2DP_SINK_TASK_STACK_SIZE +#else +#define UC_A2DP_SINK_TASK_STACK_SIZE 2048 +#endif +#ifdef CONFIG_A2DP_SOURCE_TASK_STACK_SIZE +#define UC_A2DP_SOURCE_TASK_STACK_SIZE CONFIG_A2DP_SOURCE_TASK_STACK_SIZE +#else +#define UC_A2DP_SOURCE_TASK_STACK_SIZE 2048 +#endif + +/********************************************************** + * Profile reference + **********************************************************/ +//Classic BT reference +#ifdef CONFIG_BT_CLASSIC_ENABLED +#define UC_BT_CLASSIC_ENABLED CONFIG_BT_CLASSIC_ENABLED +#else +#define UC_BT_CLASSIC_ENABLED FALSE +#endif + +//A2DP +#ifdef CONFIG_BT_A2DP_ENABLE +#define UC_BT_A2DP_ENABLED CONFIG_BT_A2DP_ENABLE +#else +#define UC_BT_A2DP_ENABLED FALSE +#endif + +//SPP +#ifdef CONFIG_BT_SPP_ENABLED +#define UC_BT_SPP_ENABLED CONFIG_BT_SPP_ENABLED +#else +#define UC_BT_SPP_ENABLED FALSE +#endif + +//HFP +#ifdef CONFIG_BT_HFP_CLIENT_ENABLE +#define UC_BT_HFP_CLIENT_ENABLED CONFIG_BT_HFP_CLIENT_ENABLE +#else +#define UC_BT_HFP_CLIENT_ENABLED FALSE +#endif + +//SSP +#ifdef CONFIG_BT_SSP_ENABLED +#define UC_BT_SSP_ENABLED CONFIG_BT_SSP_ENABLED +#else +#define UC_BT_SSP_ENABLED FALSE +#endif + +//BLE +#ifdef CONFIG_BT_BLE_ENABLED +#define UC_BT_BLE_ENABLED CONFIG_BT_BLE_ENABLED +#else +#define UC_BT_BLE_ENABLED FALSE +#endif + +//GATTS +#ifdef CONFIG_BT_GATTS_ENABLE +#define UC_BT_GATTS_ENABLE CONFIG_BT_GATTS_ENABLE +#else +#define UC_BT_GATTS_ENABLE FALSE +#endif + +//GATTC +#ifdef CONFIG_BT_GATTC_ENABLE +#define UC_BT_GATTC_ENABLE CONFIG_BT_GATTC_ENABLE +#else +#define UC_BT_GATTC_ENABLE FALSE +#endif + +//GATTC CACHE +#ifdef CONFIG_BT_GATTC_CACHE_NVS_FLASH +#define UC_BT_GATTC_CACHE_NVS_FLASH_ENABLED CONFIG_BT_GATTC_CACHE_NVS_FLASH +#else +#define UC_BT_GATTC_CACHE_NVS_FLASH_ENABLED FALSE +#endif + +//SMP +#ifdef CONFIG_BT_SMP_ENABLE +#define UC_BT_SMP_ENABLE CONFIG_BT_SMP_ENABLE +#else +#define UC_BT_SMP_ENABLE FALSE +#endif + +//SMP_SLAVE_CON_PARAMS_UPD_ENABLE +#ifdef CONFIG_BT_SMP_SLAVE_CON_PARAMS_UPD_ENABLE +#define UC_BT_SMP_SLAVE_CON_PARAMS_UPD_ENABLE CONFIG_BT_SMP_SLAVE_CON_PARAMS_UPD_ENABLE +#else +#define UC_BT_SMP_SLAVE_CON_PARAMS_UPD_ENABLE FALSE +#endif + +//BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP +#ifdef CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP +#define UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP +#else +#define UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP FALSE +#endif + +//SMP_SLAVE_CON_PARAMS_UPD_ENABLE +#ifdef CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM +#define UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM +#else +#define UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM 100 +#endif + +//BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP +#ifdef CONFIG_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD +#define UC_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD CONFIG_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD +#else +#define UC_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD 20 +#endif + +//BT ACL CONNECTIONS +#ifdef CONFIG_BT_ACL_CONNECTIONS +#define UC_BT_ACL_CONNECTIONS CONFIG_BT_ACL_CONNECTIONS +#else +#define UC_BT_ACL_CONNECTIONS 5 +#endif + +//BT_BLE_ESTAB_LINK_CONN_TOUT +#ifdef CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT +#define UC_BT_BLE_ESTAB_LINK_CONN_TOUT CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT +#else +#define UC_BT_BLE_ESTAB_LINK_CONN_TOUT 30 +#endif + + +//HOST QUEUE CONGEST CHECK +#ifdef CONFIG_BT_BLE_HOST_QUEUE_CONGESTION_CHECK +#define UC_BT_BLE_HOST_QUEUE_CONGESTION_CHECK CONFIG_BT_BLE_HOST_QUEUE_CONGESTION_CHECK +#else +#define UC_BT_BLE_HOST_QUEUE_CONGESTION_CHECK FALSE +#endif + +#ifdef CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MODE +#define UC_BT_GATTS_SEND_SERVICE_CHANGE_MODE CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MODE +#else +#define UC_BT_GATTS_SEND_SERVICE_CHANGE_MODE 0 +#endif + +#ifdef CONFIG_BT_BLE_ACT_SCAN_REP_ADV_SCAN +#define UC_BT_BLE_ACT_SCAN_REP_ADV_SCAN CONFIG_BT_BLE_ACT_SCAN_REP_ADV_SCAN +#else +#define UC_BT_BLE_ACT_SCAN_REP_ADV_SCAN FALSE +#endif + +//SCO VOICE OVER HCI +#ifdef CONFIG_BT_HFP_AUDIO_DATA_PATH_HCI +#define UC_BT_HFP_AUDIO_DATA_PATH_HCI CONFIG_BT_HFP_AUDIO_DATA_PATH_HCI +#else +#define UC_BT_HFP_AUDIO_DATA_PATH_HCI FALSE +#endif + + +/********************************************************** + * Memory reference + **********************************************************/ +//DYNAMIC ENV ALLOCATOR +#ifdef CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY +#define UC_BT_BLE_DYNAMIC_ENV_MEMORY CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY +#else +#define UC_BT_BLE_DYNAMIC_ENV_MEMORY FALSE +#endif + +//MEMORY ALLOCATOR +#ifdef CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST +#define UC_HEAP_ALLOCATION_FROM_SPIRAM_FIRST CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST +#else +#define UC_HEAP_ALLOCATION_FROM_SPIRAM_FIRST FALSE +#endif + +//MEMORY DEBUG +#ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG +#define UC_BT_BLUEDROID_MEM_DEBUG CONFIG_BT_BLUEDROID_MEM_DEBUG +#else +#define UC_BT_BLUEDROID_MEM_DEBUG FALSE +#endif + + +/********************************************************** + * Trace reference + **********************************************************/ +#ifdef CONFIG_LOG_DEFAULT_LEVEL +#define UC_LOG_DEFAULT_LEVEL CONFIG_LOG_DEFAULT_LEVEL +#else +#define UC_LOG_DEFAULT_LEVEL 3 +#endif +#ifdef CONFIG_BOOTLOADER_LOG_LEVEL +#define UC_BOOTLOADER_LOG_LEVEL CONFIG_BOOTLOADER_LOG_LEVEL +#else +#define UC_BOOTLOADER_LOG_LEVEL 3 +#endif + +#ifdef CONFIG_BT_STACK_NO_LOG +#define UC_BT_STACK_NO_LOG CONFIG_BT_STACK_NO_LOG +#else +#define UC_BT_STACK_NO_LOG FALSE +#endif + +#define UC_TRACE_LEVEL_NONE 0 /* No trace messages to be generated */ +#define UC_TRACE_LEVEL_ERROR 1 /* Error condition trace messages */ +#define UC_TRACE_LEVEL_WARNING 2 /* Warning condition trace messages */ +#define UC_TRACE_LEVEL_API 3 /* API traces */ +#define UC_TRACE_LEVEL_EVENT 4 /* Debug messages for events */ +#define UC_TRACE_LEVEL_DEBUG 5 /* Full debug messages */ +#define UC_TRACE_LEVEL_VERBOSE 6 /* Verbose debug messages */ + +#ifdef CONFIG_BT_LOG_HCI_TRACE_LEVEL +#define UC_BT_LOG_HCI_TRACE_LEVEL CONFIG_BT_LOG_HCI_TRACE_LEVEL +#else +#define UC_BT_LOG_HCI_TRACE_LEVEL UC_TRACE_LEVEL_WARNING +#endif + +#ifdef CONFIG_BT_LOG_BTM_TRACE_LEVEL +#define UC_BT_LOG_BTM_TRACE_LEVEL CONFIG_BT_LOG_BTM_TRACE_LEVEL +#else +#define UC_BT_LOG_BTM_TRACE_LEVEL UC_TRACE_LEVEL_WARNING +#endif + +#ifdef CONFIG_BT_LOG_L2CAP_TRACE_LEVEL +#define UC_BT_LOG_L2CAP_TRACE_LEVEL CONFIG_BT_LOG_L2CAP_TRACE_LEVEL +#else +#define UC_BT_LOG_L2CAP_TRACE_LEVEL UC_TRACE_LEVEL_WARNING +#endif + +#ifdef CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL +#define UC_BT_LOG_RFCOMM_TRACE_LEVEL CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL +#else +#define UC_BT_LOG_RFCOMM_TRACE_LEVEL UC_TRACE_LEVEL_WARNING +#endif + +#ifdef CONFIG_BT_LOG_SDP_TRACE_LEVEL +#define UC_BT_LOG_SDP_TRACE_LEVEL CONFIG_BT_LOG_SDP_TRACE_LEVEL +#else +#define UC_BT_LOG_SDP_TRACE_LEVEL UC_TRACE_LEVEL_WARNING +#endif + +#ifdef CONFIG_BT_LOG_GAP_TRACE_LEVEL +#define UC_BT_LOG_GAP_TRACE_LEVEL CONFIG_BT_LOG_GAP_TRACE_LEVEL +#else +#define UC_BT_LOG_GAP_TRACE_LEVEL UC_TRACE_LEVEL_WARNING +#endif + +#ifdef CONFIG_BT_LOG_BNEP_TRACE_LEVEL +#define UC_BT_LOG_BNEP_TRACE_LEVEL CONFIG_BT_LOG_BNEP_TRACE_LEVEL +#else +#define UC_BT_LOG_BNEP_TRACE_LEVEL UC_TRACE_LEVEL_WARNING +#endif + +#ifdef CONFIG_BT_LOG_PAN_TRACE_LEVEL +#define UC_BT_LOG_PAN_TRACE_LEVEL CONFIG_BT_LOG_PAN_TRACE_LEVEL +#else +#define UC_BT_LOG_PAN_TRACE_LEVEL UC_TRACE_LEVEL_WARNING +#endif + +#ifdef CONFIG_BT_LOG_A2D_TRACE_LEVEL +#define UC_BT_LOG_A2D_TRACE_LEVEL CONFIG_BT_LOG_A2D_TRACE_LEVEL +#else +#define UC_BT_LOG_A2D_TRACE_LEVEL UC_TRACE_LEVEL_WARNING +#endif + +#ifdef CONFIG_BT_LOG_AVDT_TRACE_LEVEL +#define UC_BT_LOG_AVDT_TRACE_LEVEL CONFIG_BT_LOG_AVDT_TRACE_LEVEL +#else +#define UC_BT_LOG_AVDT_TRACE_LEVEL UC_TRACE_LEVEL_WARNING +#endif + +#ifdef CONFIG_BT_LOG_AVCT_TRACE_LEVEL +#define UC_BT_LOG_AVCT_TRACE_LEVEL CONFIG_BT_LOG_AVCT_TRACE_LEVEL +#else +#define UC_BT_LOG_AVCT_TRACE_LEVEL UC_TRACE_LEVEL_WARNING +#endif + +#ifdef CONFIG_BT_LOG_AVRC_TRACE_LEVEL +#define UC_BT_LOG_AVRC_TRACE_LEVEL CONFIG_BT_LOG_AVRC_TRACE_LEVEL +#else +#define UC_BT_LOG_AVRC_TRACE_LEVEL UC_TRACE_LEVEL_WARNING +#endif + +#ifdef CONFIG_BT_LOG_MCA_TRACE_LEVEL +#define UC_BT_LOG_MCA_TRACE_LEVEL CONFIG_BT_LOG_MCA_TRACE_LEVEL +#else +#define UC_BT_LOG_MCA_TRACE_LEVEL UC_TRACE_LEVEL_WARNING +#endif + +#ifdef CONFIG_BT_LOG_HID_TRACE_LEVEL +#define UC_BT_LOG_HID_TRACE_LEVEL CONFIG_BT_LOG_HID_TRACE_LEVEL +#else +#define UC_BT_LOG_HID_TRACE_LEVEL UC_TRACE_LEVEL_WARNING +#endif + +#ifdef CONFIG_BT_LOG_APPL_TRACE_LEVEL +#define UC_BT_LOG_APPL_TRACE_LEVEL CONFIG_BT_LOG_APPL_TRACE_LEVEL +#else +#define UC_BT_LOG_APPL_TRACE_LEVEL UC_TRACE_LEVEL_WARNING +#endif + +#ifdef CONFIG_BT_LOG_GATT_TRACE_LEVEL +#define UC_BT_LOG_GATT_TRACE_LEVEL CONFIG_BT_LOG_GATT_TRACE_LEVEL +#else +#define UC_BT_LOG_GATT_TRACE_LEVEL UC_TRACE_LEVEL_WARNING +#endif + +#ifdef CONFIG_BT_LOG_SMP_TRACE_LEVEL +#define UC_BT_LOG_SMP_TRACE_LEVEL CONFIG_BT_LOG_SMP_TRACE_LEVEL +#else +#define UC_BT_LOG_SMP_TRACE_LEVEL UC_TRACE_LEVEL_WARNING +#endif + +#ifdef CONFIG_BT_LOG_BTIF_TRACE_LEVEL +#define UC_BT_LOG_BTIF_TRACE_LEVEL CONFIG_BT_LOG_BTIF_TRACE_LEVEL +#else +#define UC_BT_LOG_BTIF_TRACE_LEVEL UC_TRACE_LEVEL_WARNING +#endif + +#ifdef CONFIG_BT_LOG_BTC_TRACE_LEVEL +#define UC_BT_LOG_BTC_TRACE_LEVEL CONFIG_BT_LOG_BTC_TRACE_LEVEL +#else +#define UC_BT_LOG_BTC_TRACE_LEVEL UC_TRACE_LEVEL_WARNING +#endif + +#ifdef CONFIG_BT_LOG_OSI_TRACE_LEVEL +#define UC_BT_LOG_OSI_TRACE_LEVEL CONFIG_BT_LOG_OSI_TRACE_LEVEL +#else +#define UC_BT_LOG_OSI_TRACE_LEVEL UC_TRACE_LEVEL_WARNING +#endif + +#ifdef CONFIG_BT_LOG_BLUFI_TRACE_LEVEL +#define UC_BT_LOG_BLUFI_TRACE_LEVEL CONFIG_BT_LOG_BLUFI_TRACE_LEVEL +#else +#define UC_BT_LOG_BLUFI_TRACE_LEVEL UC_TRACE_LEVEL_WARNING +#endif + +#endif /* __BT_USER_CONFIG_H__ */ + + + diff --git a/components/bt/bluedroid/device/controller.c b/components/bt/bluedroid/device/controller.c index 45ef4ea504..84d6f59737 100644 --- a/components/bt/bluedroid/device/controller.c +++ b/components/bt/bluedroid/device/controller.c @@ -46,38 +46,47 @@ const uint8_t SCO_HOST_BUFFER_SIZE = 0xff; #define BLE_SUPPORTED_STATES_SIZE 8 #define BLE_SUPPORTED_FEATURES_SIZE 8 -static const hci_t *hci; -static const hci_packet_factory_t *packet_factory; -static const hci_packet_parser_t *packet_parser; +typedef struct { + const hci_t *hci; + const hci_packet_factory_t *packet_factory; + const hci_packet_parser_t *packet_parser; -static bt_bdaddr_t address; -static bt_version_t bt_version; + bt_version_t bt_version; + bt_bdaddr_t address; -static uint8_t supported_commands[HCI_SUPPORTED_COMMANDS_ARRAY_SIZE]; -static bt_device_features_t features_classic[MAX_FEATURES_CLASSIC_PAGE_COUNT]; -static uint8_t last_features_classic_page_index; + uint8_t supported_commands[HCI_SUPPORTED_COMMANDS_ARRAY_SIZE]; + uint8_t last_features_classic_page_index; + bt_device_features_t features_classic[MAX_FEATURES_CLASSIC_PAGE_COUNT]; -static uint16_t acl_data_size_classic; -static uint16_t acl_data_size_ble; -static uint16_t acl_buffer_count_classic; -static uint8_t acl_buffer_count_ble; + uint16_t acl_data_size_classic; + uint16_t acl_data_size_ble; + uint16_t acl_buffer_count_classic; + uint8_t acl_buffer_count_ble; -static uint8_t sco_data_size; -static uint16_t sco_buffer_count; + uint8_t sco_data_size; + uint16_t sco_buffer_count; -static uint8_t ble_white_list_size; -static uint8_t ble_resolving_list_max_size; -static uint8_t ble_supported_states[BLE_SUPPORTED_STATES_SIZE]; -static bt_device_features_t features_ble; -static uint16_t ble_suggested_default_data_length; -static uint16_t ble_suggested_default_data_txtime; + uint8_t ble_white_list_size; + uint8_t ble_resolving_list_max_size; + uint8_t ble_supported_states[BLE_SUPPORTED_STATES_SIZE]; + bt_device_features_t features_ble; + uint16_t ble_suggested_default_data_length; + uint16_t ble_suggested_default_data_txtime; -static bool readable; -static bool ble_supported; -static bool simple_pairing_supported; -static bool secure_connections_supported; + bool readable; + bool ble_supported; + bool simple_pairing_supported; + bool secure_connections_supported; +} controller_local_param_t; -#define AWAIT_COMMAND(command) future_await(hci->transmit_command_futured(command)) +#if BT_BLE_DYNAMIC_ENV_MEMORY == FALSE +static controller_local_param_t controller_param; +#else +static controller_local_param_t *controller_param_ptr; +#define controller_param (*controller_param_ptr) +#endif + +#define AWAIT_COMMAND(command) future_await(controller_param.hci->transmit_command_futured(command)) // Module lifecycle functions @@ -86,29 +95,29 @@ static void start_up(void) BT_HDR *response; // Send the initial reset command - response = AWAIT_COMMAND(packet_factory->make_reset()); - packet_parser->parse_generic_command_complete(response); + response = AWAIT_COMMAND(controller_param.packet_factory->make_reset()); + controller_param.packet_parser->parse_generic_command_complete(response); // Request the classic buffer size next - response = AWAIT_COMMAND(packet_factory->make_read_buffer_size()); - packet_parser->parse_read_buffer_size_response( - response, &acl_data_size_classic, &acl_buffer_count_classic, - &sco_data_size, &sco_buffer_count); + response = AWAIT_COMMAND(controller_param.packet_factory->make_read_buffer_size()); + controller_param.packet_parser->parse_read_buffer_size_response( + response, &controller_param.acl_data_size_classic, &controller_param.acl_buffer_count_classic, + &controller_param.sco_data_size, &controller_param.sco_buffer_count); #if (C2H_FLOW_CONTROL_INCLUDED == TRUE) // Enable controller to host flow control - response = AWAIT_COMMAND(packet_factory->make_set_c2h_flow_control(HCI_HOST_FLOW_CTRL_ACL_ON)); - packet_parser->parse_generic_command_complete(response); + response = AWAIT_COMMAND(controller_param.packet_factory->make_set_c2h_flow_control(HCI_HOST_FLOW_CTRL_ACL_ON)); + controller_param.packet_parser->parse_generic_command_complete(response); #endif ///C2H_FLOW_CONTROL_INCLUDED == TRUE #if (BLE_ADV_REPORT_FLOW_CONTROL == TRUE) // Enable adv flow control - response = AWAIT_COMMAND(packet_factory->make_set_adv_report_flow_control(HCI_HOST_FLOW_CTRL_ADV_REPORT_ON, (uint16_t)BLE_ADV_REPORT_FLOW_CONTROL_NUM, (uint16_t)BLE_ADV_REPORT_DISCARD_THRSHOLD)); - packet_parser->parse_generic_command_complete(response); + response = AWAIT_COMMAND(controller_param.packet_factory->make_set_adv_report_flow_control(HCI_HOST_FLOW_CTRL_ADV_REPORT_ON, (uint16_t)BLE_ADV_REPORT_FLOW_CONTROL_NUM, (uint16_t)BLE_ADV_REPORT_DISCARD_THRSHOLD)); + controller_param.packet_parser->parse_generic_command_complete(response); #endif // Tell the controller about our buffer sizes and buffer counts next // TODO(zachoverflow): factor this out. eww l2cap contamination. And why just a hardcoded 10? response = AWAIT_COMMAND( - packet_factory->make_host_buffer_size( + controller_param.packet_factory->make_host_buffer_size( L2CAP_MTU_SIZE, SCO_HOST_BUFFER_SIZE, L2CAP_HOST_FC_ACL_BUFS, @@ -116,33 +125,33 @@ static void start_up(void) ) ); - packet_parser->parse_generic_command_complete(response); + controller_param.packet_parser->parse_generic_command_complete(response); // Read the local version info off the controller next, including // information such as manufacturer and supported HCI version - response = AWAIT_COMMAND(packet_factory->make_read_local_version_info()); - packet_parser->parse_read_local_version_info_response(response, &bt_version); + response = AWAIT_COMMAND(controller_param.packet_factory->make_read_local_version_info()); + controller_param.packet_parser->parse_read_local_version_info_response(response, &controller_param.bt_version); // Read the bluetooth address off the controller next - response = AWAIT_COMMAND(packet_factory->make_read_bd_addr()); - packet_parser->parse_read_bd_addr_response(response, &address); + response = AWAIT_COMMAND(controller_param.packet_factory->make_read_bd_addr()); + controller_param.packet_parser->parse_read_bd_addr_response(response, &controller_param.address); // Request the controller's supported commands next - response = AWAIT_COMMAND(packet_factory->make_read_local_supported_commands()); - packet_parser->parse_read_local_supported_commands_response( + response = AWAIT_COMMAND(controller_param.packet_factory->make_read_local_supported_commands()); + controller_param.packet_parser->parse_read_local_supported_commands_response( response, - supported_commands, + controller_param.supported_commands, HCI_SUPPORTED_COMMANDS_ARRAY_SIZE ); // Read page 0 of the controller features next uint8_t page_number = 0; - response = AWAIT_COMMAND(packet_factory->make_read_local_extended_features(page_number)); - packet_parser->parse_read_local_extended_features_response( + response = AWAIT_COMMAND(controller_param.packet_factory->make_read_local_extended_features(page_number)); + controller_param.packet_parser->parse_read_local_extended_features_response( response, &page_number, - &last_features_classic_page_index, - features_classic, + &controller_param.last_features_classic_page_index, + controller_param.features_classic, MAX_FEATURES_CLASSIC_PAGE_COUNT ); @@ -154,36 +163,37 @@ static void start_up(void) // next page, because the controller's response for page 1 may be // dependent on what we configure from page 0 #if (BT_SSP_INCLUDED == TRUE) - simple_pairing_supported = HCI_SIMPLE_PAIRING_SUPPORTED(features_classic[0].as_array); + controller_param.simple_pairing_supported = HCI_SIMPLE_PAIRING_SUPPORTED(controller_param.features_classic[0].as_array); #else - simple_pairing_supported = false; + controller_param.simple_pairing_supported = false; #endif - if (simple_pairing_supported) { - response = AWAIT_COMMAND(packet_factory->make_write_simple_pairing_mode(HCI_SP_MODE_ENABLED)); - packet_parser->parse_generic_command_complete(response); + + if (controller_param.simple_pairing_supported) { + response = AWAIT_COMMAND(controller_param.packet_factory->make_write_simple_pairing_mode(HCI_SP_MODE_ENABLED)); + controller_param.packet_parser->parse_generic_command_complete(response); } #if (BLE_INCLUDED == TRUE) - if (HCI_LE_SPT_SUPPORTED(features_classic[0].as_array)) { - uint8_t simultaneous_le_host = HCI_SIMUL_LE_BREDR_SUPPORTED(features_classic[0].as_array) ? BTM_BLE_SIMULTANEOUS_HOST : 0; + if (HCI_LE_SPT_SUPPORTED(controller_param.features_classic[0].as_array)) { + uint8_t simultaneous_le_host = HCI_SIMUL_LE_BREDR_SUPPORTED(controller_param.features_classic[0].as_array) ? BTM_BLE_SIMULTANEOUS_HOST : 0; response = AWAIT_COMMAND( - packet_factory->make_ble_write_host_support(BTM_BLE_HOST_SUPPORT, simultaneous_le_host) + controller_param.packet_factory->make_ble_write_host_support(BTM_BLE_HOST_SUPPORT, simultaneous_le_host) ); - packet_parser->parse_generic_command_complete(response); + controller_param.packet_parser->parse_generic_command_complete(response); } #endif // Done telling the controller about what page 0 features we support // Request the remaining feature pages - while (page_number <= last_features_classic_page_index && + while (page_number <= controller_param.last_features_classic_page_index && page_number < MAX_FEATURES_CLASSIC_PAGE_COUNT) { - response = AWAIT_COMMAND(packet_factory->make_read_local_extended_features(page_number)); - packet_parser->parse_read_local_extended_features_response( + response = AWAIT_COMMAND(controller_param.packet_factory->make_read_local_extended_features(page_number)); + controller_param.packet_parser->parse_read_local_extended_features_response( response, &page_number, - &last_features_classic_page_index, - features_classic, + &controller_param.last_features_classic_page_index, + controller_param.features_classic, MAX_FEATURES_CLASSIC_PAGE_COUNT ); @@ -191,299 +201,297 @@ static void start_up(void) } #if (SC_MODE_INCLUDED == TRUE) - secure_connections_supported = HCI_SC_CTRLR_SUPPORTED(features_classic[2].as_array); - if (secure_connections_supported) { - response = AWAIT_COMMAND(packet_factory->make_write_secure_connections_host_support(HCI_SC_MODE_ENABLED)); - packet_parser->parse_generic_command_complete(response); + controller_param.secure_connections_supported = HCI_SC_CTRLR_SUPPORTED(controller_param.features_classic[2].as_array); + if (controller_param.secure_connections_supported) { + response = AWAIT_COMMAND(controller_param.packet_factory->make_write_secure_connections_host_support(HCI_SC_MODE_ENABLED)); + controller_param.packet_parser->parse_generic_command_complete(response); } #endif #if (BLE_INCLUDED == TRUE) - ble_supported = last_features_classic_page_index >= 1 && HCI_LE_HOST_SUPPORTED(features_classic[1].as_array); - if (ble_supported) { + controller_param.ble_supported = controller_param.last_features_classic_page_index >= 1 && HCI_LE_HOST_SUPPORTED(controller_param.features_classic[1].as_array); + if (controller_param.ble_supported) { // Request the ble white list size next - response = AWAIT_COMMAND(packet_factory->make_ble_read_white_list_size()); - packet_parser->parse_ble_read_white_list_size_response(response, &ble_white_list_size); + response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_read_white_list_size()); + controller_param.packet_parser->parse_ble_read_white_list_size_response(response, &controller_param.ble_white_list_size); // Request the ble buffer size next - response = AWAIT_COMMAND(packet_factory->make_ble_read_buffer_size()); - packet_parser->parse_ble_read_buffer_size_response( + response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_read_buffer_size()); + controller_param.packet_parser->parse_ble_read_buffer_size_response( response, - &acl_data_size_ble, - &acl_buffer_count_ble + &controller_param.acl_data_size_ble, + &controller_param.acl_buffer_count_ble ); // Response of 0 indicates ble has the same buffer size as classic - if (acl_data_size_ble == 0) { - acl_data_size_ble = acl_data_size_classic; + if (controller_param.acl_data_size_ble == 0) { + controller_param.acl_data_size_ble = controller_param.acl_data_size_classic; } // Request the ble supported states next - response = AWAIT_COMMAND(packet_factory->make_ble_read_supported_states()); - packet_parser->parse_ble_read_supported_states_response( + response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_read_supported_states()); + controller_param.packet_parser->parse_ble_read_supported_states_response( response, - ble_supported_states, - sizeof(ble_supported_states) + controller_param.ble_supported_states, + sizeof(controller_param.ble_supported_states) ); // Request the ble supported features next - response = AWAIT_COMMAND(packet_factory->make_ble_read_local_supported_features()); - packet_parser->parse_ble_read_local_supported_features_response( + response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_read_local_supported_features()); + controller_param.packet_parser->parse_ble_read_local_supported_features_response( response, - &features_ble + &controller_param.features_ble ); - if (HCI_LE_ENHANCED_PRIVACY_SUPPORTED(features_ble.as_array)) { - response = AWAIT_COMMAND(packet_factory->make_ble_read_resolving_list_size()); - packet_parser->parse_ble_read_resolving_list_size_response( + if (HCI_LE_ENHANCED_PRIVACY_SUPPORTED(controller_param.features_ble.as_array)) { + response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_read_resolving_list_size()); + controller_param.packet_parser->parse_ble_read_resolving_list_size_response( response, - &ble_resolving_list_max_size); + &controller_param.ble_resolving_list_max_size); } - if (HCI_LE_DATA_LEN_EXT_SUPPORTED(features_ble.as_array)) { + if (HCI_LE_DATA_LEN_EXT_SUPPORTED(controller_param.features_ble.as_array)) { /* set default tx data length to MAX 251 */ - response = AWAIT_COMMAND(packet_factory->make_ble_write_suggested_default_data_length(BTM_BLE_DATA_SIZE_MAX, BTM_BLE_DATA_TX_TIME_MAX)); - packet_parser->parse_generic_command_complete(response); + response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_write_suggested_default_data_length(BTM_BLE_DATA_SIZE_MAX, BTM_BLE_DATA_TX_TIME_MAX)); + controller_param.packet_parser->parse_generic_command_complete(response); - response = AWAIT_COMMAND(packet_factory->make_ble_read_suggested_default_data_length()); - packet_parser->parse_ble_read_suggested_default_data_length_response( + response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_read_suggested_default_data_length()); + controller_param.packet_parser->parse_ble_read_suggested_default_data_length_response( response, - &ble_suggested_default_data_length, - &ble_suggested_default_data_txtime); + &controller_param.ble_suggested_default_data_length, + &controller_param.ble_suggested_default_data_txtime); } // Set the ble event mask next - response = AWAIT_COMMAND(packet_factory->make_ble_set_event_mask(&BLE_EVENT_MASK)); - packet_parser->parse_generic_command_complete(response); + response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_set_event_mask(&BLE_EVENT_MASK)); + controller_param.packet_parser->parse_generic_command_complete(response); } #endif - - response = AWAIT_COMMAND(packet_factory->make_set_event_mask(&CLASSIC_EVENT_MASK)); - packet_parser->parse_generic_command_complete(response); - + response = AWAIT_COMMAND(controller_param.packet_factory->make_set_event_mask(&CLASSIC_EVENT_MASK)); + controller_param.packet_parser->parse_generic_command_complete(response); #if (BTM_SCO_HCI_INCLUDED == TRUE) - response = AWAIT_COMMAND(packet_factory->make_write_sync_flow_control_enable(1)); - packet_parser->parse_generic_command_complete(response); + response = AWAIT_COMMAND(controller_param.packet_factory->make_write_sync_flow_control_enable(1)); + controller_param.packet_parser->parse_generic_command_complete(response); - response = AWAIT_COMMAND(packet_factory->make_write_default_erroneous_data_report(1)); - packet_parser->parse_generic_command_complete(response); + response = AWAIT_COMMAND(controller_param.packet_factory->make_write_default_erroneous_data_report(1)); + controller_param.packet_parser->parse_generic_command_complete(response); #endif - readable = true; + controller_param.readable = true; // return future_new_immediate(FUTURE_SUCCESS); return; } static void shut_down(void) { - readable = false; + controller_param.readable = false; } static bool get_is_ready(void) { - return readable; + return controller_param.readable; } static const bt_bdaddr_t *get_address(void) { - assert(readable); - return &address; + assert(controller_param.readable); + return &controller_param.address; } static const bt_version_t *get_bt_version(void) { - assert(readable); - return &bt_version; + assert(controller_param.readable); + return &controller_param.bt_version; } // TODO(zachoverflow): hide inside, move decoder inside too static const bt_device_features_t *get_features_classic(int index) { - assert(readable); + assert(controller_param.readable); assert(index < MAX_FEATURES_CLASSIC_PAGE_COUNT); - return &features_classic[index]; + return &controller_param.features_classic[index]; } static uint8_t get_last_features_classic_index(void) { - assert(readable); - return last_features_classic_page_index; + assert(controller_param.readable); + return controller_param.last_features_classic_page_index; } static const bt_device_features_t *get_features_ble(void) { - assert(readable); - assert(ble_supported); - return &features_ble; + assert(controller_param.readable); + assert(controller_param.ble_supported); + return &controller_param.features_ble; } static const uint8_t *get_ble_supported_states(void) { - assert(readable); - assert(ble_supported); - return ble_supported_states; + assert(controller_param.readable); + assert(controller_param.ble_supported); + return controller_param.ble_supported_states; } static bool supports_simple_pairing(void) { - assert(readable); - return simple_pairing_supported; + assert(controller_param.readable); + return controller_param.simple_pairing_supported; } static bool supports_secure_connections(void) { - assert(readable); - return secure_connections_supported; + assert(controller_param.readable); + return controller_param.secure_connections_supported; } static bool supports_simultaneous_le_bredr(void) { - assert(readable); - return HCI_SIMUL_LE_BREDR_SUPPORTED(features_classic[0].as_array); + assert(controller_param.readable); + return HCI_SIMUL_LE_BREDR_SUPPORTED(controller_param.features_classic[0].as_array); } static bool supports_reading_remote_extended_features(void) { - assert(readable); - return HCI_READ_REMOTE_EXT_FEATURES_SUPPORTED(supported_commands); + assert(controller_param.readable); + return HCI_READ_REMOTE_EXT_FEATURES_SUPPORTED(controller_param.supported_commands); } static bool supports_interlaced_inquiry_scan(void) { - assert(readable); - return HCI_LMP_INTERLACED_INQ_SCAN_SUPPORTED(features_classic[0].as_array); + assert(controller_param.readable); + return HCI_LMP_INTERLACED_INQ_SCAN_SUPPORTED(controller_param.features_classic[0].as_array); } static bool supports_rssi_with_inquiry_results(void) { - assert(readable); - return HCI_LMP_INQ_RSSI_SUPPORTED(features_classic[0].as_array); + assert(controller_param.readable); + return HCI_LMP_INQ_RSSI_SUPPORTED(controller_param.features_classic[0].as_array); } static bool supports_extended_inquiry_response(void) { - assert(readable); - return HCI_EXT_INQ_RSP_SUPPORTED(features_classic[0].as_array); + assert(controller_param.readable); + return HCI_EXT_INQ_RSP_SUPPORTED(controller_param.features_classic[0].as_array); } static bool supports_master_slave_role_switch(void) { - assert(readable); - return HCI_SWITCH_SUPPORTED(features_classic[0].as_array); + assert(controller_param.readable); + return HCI_SWITCH_SUPPORTED(controller_param.features_classic[0].as_array); } static bool supports_ble(void) { - assert(readable); - return ble_supported; + assert(controller_param.readable); + return controller_param.ble_supported; } static bool supports_ble_privacy(void) { - assert(readable); - assert(ble_supported); - return HCI_LE_ENHANCED_PRIVACY_SUPPORTED(features_ble.as_array); + assert(controller_param.readable); + assert(controller_param.ble_supported); + return HCI_LE_ENHANCED_PRIVACY_SUPPORTED(controller_param.features_ble.as_array); } static bool supports_ble_packet_extension(void) { - assert(readable); - assert(ble_supported); - return HCI_LE_DATA_LEN_EXT_SUPPORTED(features_ble.as_array); + assert(controller_param.readable); + assert(controller_param.ble_supported); + return HCI_LE_DATA_LEN_EXT_SUPPORTED(controller_param.features_ble.as_array); } static bool supports_ble_connection_parameters_request(void) { - assert(readable); - assert(ble_supported); - return HCI_LE_CONN_PARAM_REQ_SUPPORTED(features_ble.as_array); + assert(controller_param.readable); + assert(controller_param.ble_supported); + return HCI_LE_CONN_PARAM_REQ_SUPPORTED(controller_param.features_ble.as_array); } static uint16_t get_acl_data_size_classic(void) { - assert(readable); - return acl_data_size_classic; + assert(controller_param.readable); + return controller_param.acl_data_size_classic; } static uint16_t get_acl_data_size_ble(void) { - assert(readable); - assert(ble_supported); - return acl_data_size_ble; + assert(controller_param.readable); + assert(controller_param.ble_supported); + return controller_param.acl_data_size_ble; } static uint16_t get_acl_packet_size_classic(void) { - assert(readable); - return acl_data_size_classic + HCI_DATA_PREAMBLE_SIZE; + assert(controller_param.readable); + return controller_param.acl_data_size_classic + HCI_DATA_PREAMBLE_SIZE; } static uint16_t get_acl_packet_size_ble(void) { - assert(readable); - return acl_data_size_ble + HCI_DATA_PREAMBLE_SIZE; + assert(controller_param.readable); + return controller_param.acl_data_size_ble + HCI_DATA_PREAMBLE_SIZE; } static uint16_t get_ble_suggested_default_data_length(void) { - assert(readable); - assert(ble_supported); - return ble_suggested_default_data_length; + assert(controller_param.readable); + assert(controller_param.ble_supported); + return controller_param.ble_suggested_default_data_length; } static uint16_t get_ble_suggested_default_data_txtime(void) { - assert(readable); - assert(ble_supported); - return ble_suggested_default_data_txtime; + assert(controller_param.readable); + assert(controller_param.ble_supported); + return controller_param.ble_suggested_default_data_txtime; } static uint16_t get_acl_buffer_count_classic(void) { - assert(readable); - return acl_buffer_count_classic; + assert(controller_param.readable); + return controller_param.acl_buffer_count_classic; } static uint8_t get_acl_buffer_count_ble(void) { - assert(readable); - assert(ble_supported); - return acl_buffer_count_ble; + assert(controller_param.readable); + assert(controller_param.ble_supported); + return controller_param.acl_buffer_count_ble; } static uint8_t get_ble_white_list_size(void) { - assert(readable); - assert(ble_supported); - return ble_white_list_size; + assert(controller_param.readable); + assert(controller_param.ble_supported); + return controller_param.ble_white_list_size; } static uint8_t get_ble_resolving_list_max_size(void) { - assert(readable); - assert(ble_supported); - return ble_resolving_list_max_size; + assert(controller_param.readable); + assert(controller_param.ble_supported); + return controller_param.ble_resolving_list_max_size; } static void set_ble_resolving_list_max_size(int resolving_list_max_size) { - assert(readable); - assert(ble_supported); - ble_resolving_list_max_size = resolving_list_max_size; + assert(controller_param.readable); + assert(controller_param.ble_supported); + controller_param.ble_resolving_list_max_size = resolving_list_max_size; } #if (BTM_SCO_HCI_INCLUDED == TRUE) static uint8_t get_sco_data_size(void) { - assert(readable); - return sco_data_size; + assert(controller_param.readable); + return controller_param.sco_data_size; } static uint8_t get_sco_buffer_count(void) { - assert(readable); - return sco_buffer_count; + assert(controller_param.readable); + return controller_param.sco_buffer_count; } #endif /* (BTM_SCO_HCI_INCLUDED == TRUE) */ @@ -541,10 +549,13 @@ const controller_t *controller_get_interface() static bool loaded = false; if (!loaded) { loaded = true; - - hci = hci_layer_get_interface(); - packet_factory = hci_packet_factory_get_interface(); - packet_parser = hci_packet_parser_get_interface(); +#if BT_BLE_DYNAMIC_ENV_MEMORY == TRUE + controller_param_ptr = (controller_local_param_t *)osi_calloc(sizeof(controller_local_param_t)); + assert(controller_param_ptr); +#endif + controller_param.hci = hci_layer_get_interface(); + controller_param.packet_factory = hci_packet_factory_get_interface(); + controller_param.packet_parser = hci_packet_parser_get_interface(); } return &interface; diff --git a/components/bt/bluedroid/external/sbc/encoder/srce/sbc_analysis.c b/components/bt/bluedroid/external/sbc/encoder/srce/sbc_analysis.c index 12878f3156..a2d6db43c8 100644 --- a/components/bt/bluedroid/external/sbc/encoder/srce/sbc_analysis.c +++ b/components/bt/bluedroid/external/sbc/encoder/srce/sbc_analysis.c @@ -26,6 +26,7 @@ #include #include "sbc_encoder.h" #include "sbc_enc_func_declare.h" +#include "osi/allocator.h" /*#include */ #if (defined(SBC_ENC_INCLUDED) && SBC_ENC_INCLUDED == TRUE) @@ -158,9 +159,16 @@ #if (SBC_USE_ARM_PRAGMA==TRUE) #pragma arm section zidata = "sbc_s32_analysis_section" #endif +#if BT_BLE_DYNAMIC_ENV_MEMORY == FALSE static SINT32 s32DCTY[16] = {0}; static SINT32 s32X[ENC_VX_BUFFER_SIZE / 2]; static SINT16 *s16X = (SINT16 *) s32X; /* s16X must be 32 bits aligned cf SHIFTUP_X8_2*/ +#else +static SINT32 *s32DCTY; +static SINT32 *s32X; +static SINT16 *s16X; /* s16X must be 32 bits aligned cf SHIFTUP_X8_2*/ +#endif //BT_BLE_DYNAMIC_ENV_MEMORY == FALSE + #if (SBC_USE_ARM_PRAGMA==TRUE) #pragma arm section zidata #endif @@ -1076,6 +1084,19 @@ void SbcAnalysisFilter8 (SBC_ENC_PARAMS *pstrEncParams) void SbcAnalysisInit (void) { + static bool loaded = false; + if (!loaded) { + loaded = true; +#if BT_BLE_DYNAMIC_ENV_MEMORY == TRUE + s32X = (SINT32 *)osi_malloc(sizeof(SINT32) * (ENC_VX_BUFFER_SIZE / 2)); + s32DCTY = (SINT32 *)osi_malloc(sizeof(SINT32) * 16); + assert(s32X); + assert(s32DCTY); + memset(s32X, 0, sizeof(SINT16) * ENC_VX_BUFFER_SIZE); + memset(s32DCTY, 0, sizeof(SINT32) * 16); + s16X = (SINT16 *) s32X; +#endif + } memset(s16X, 0, ENC_VX_BUFFER_SIZE * sizeof(SINT16)); ShiftCounter = 0; } diff --git a/components/bt/bluedroid/hci/hci_hal_h4.c b/components/bt/bluedroid/hci/hci_hal_h4.c index 89fba87b5d..67bb83438f 100644 --- a/components/bt/bluedroid/hci/hci_hal_h4.c +++ b/components/bt/bluedroid/hci/hci_hal_h4.c @@ -30,6 +30,7 @@ #if (C2H_FLOW_CONTROL_INCLUDED == TRUE) #include "l2c_int.h" #endif ///C2H_FLOW_CONTROL_INCLUDED == TRUE +#include "stack/hcimsgs.h" #define HCI_HAL_SERIAL_BUFFER_SIZE 1026 #define HCI_BLE_EVENT 0x3e @@ -63,9 +64,7 @@ static hci_hal_env_t hci_hal_env; static const hci_hal_t interface; static const hci_hal_callbacks_t *callbacks; static const esp_vhci_host_callback_t vhci_host_cb; - -static xTaskHandle xHciH4TaskHandle; -static xQueueHandle xHciH4Queue; +static osi_thread_t *hci_h4_thread; static void host_send_pkt_available_cb(void); static int host_recv_pkt_cb(uint8_t *data, uint16_t len); @@ -100,9 +99,11 @@ static void hci_hal_env_deinit(void) hci_hal_env.rx_q = NULL; } -static bool hal_open(const hci_hal_callbacks_t *upper_callbacks) +static bool hal_open(const hci_hal_callbacks_t *upper_callbacks, void *task_thread) { assert(upper_callbacks != NULL); + assert(task_thread != NULL); + callbacks = upper_callbacks; #if (BLE_ADV_REPORT_FLOW_CONTROL == TRUE) hci_hal_env_init(HCI_HAL_SERIAL_BUFFER_SIZE, BLE_ADV_REPORT_FLOW_CONTROL_NUM + L2CAP_HOST_FC_ACL_BUFS + QUEUE_SIZE_MAX); // adv flow control num + ACL flow control num + hci cmd numeber @@ -110,8 +111,7 @@ static bool hal_open(const hci_hal_callbacks_t *upper_callbacks) hci_hal_env_init(HCI_HAL_SERIAL_BUFFER_SIZE, QUEUE_SIZE_MAX); #endif - xHciH4Queue = xQueueCreate(HCI_H4_QUEUE_LEN, sizeof(BtTaskEvt_t)); - xTaskCreatePinnedToCore(hci_hal_h4_rx_handler, HCI_H4_TASK_NAME, HCI_H4_TASK_STACK_SIZE, NULL, HCI_H4_TASK_PRIO, &xHciH4TaskHandle, HCI_H4_TASK_PINNED_TO_CORE); + hci_h4_thread = (osi_thread_t *)task_thread; //register vhci host cb if (esp_vhci_host_register_callback(&vhci_host_cb) != ESP_OK) { @@ -125,9 +125,7 @@ static void hal_close() { hci_hal_env_deinit(); - /* delete task and queue */ - vTaskDelete(xHciH4TaskHandle); - vQueueDelete(xHciH4Queue); + hci_h4_thread = NULL; } /** @@ -169,30 +167,12 @@ static uint16_t transmit_data(serial_data_type_t type, // Internal functions static void hci_hal_h4_rx_handler(void *arg) { - BtTaskEvt_t e; - - for (;;) { - if (pdTRUE == xQueueReceive(xHciH4Queue, &e, (portTickType)portMAX_DELAY)) { - if (e.sig == SIG_HCI_HAL_RECV_PACKET) { - fixed_queue_process(hci_hal_env.rx_q); - - } - } - } + fixed_queue_process(hci_hal_env.rx_q); } -task_post_status_t hci_hal_h4_task_post(task_post_t timeout) +bool hci_hal_h4_task_post(uint32_t timeout) { - BtTaskEvt_t evt; - - evt.sig = SIG_HCI_HAL_RECV_PACKET; - evt.par = 0; - - if (xQueueSend(xHciH4Queue, &evt, timeout) != pdTRUE) { - return TASK_POST_SUCCESS; - } - - return TASK_POST_FAIL; + return osi_thread_post(hci_h4_thread, hci_hal_h4_rx_handler, NULL, 1, timeout); } #if (C2H_FLOW_CONTROL_INCLUDED == TRUE) @@ -334,7 +314,7 @@ static void event_uart_has_bytes(fixed_queue_t *queue) { BT_HDR *packet; while (!fixed_queue_is_empty(queue)) { - packet = fixed_queue_dequeue(queue); + packet = fixed_queue_dequeue(queue, FIXED_QUEUE_MAX_TIMEOUT); hci_hal_h4_hdl_rx_packet(packet); } } @@ -343,7 +323,7 @@ static void host_send_pkt_available_cb(void) { //Controller rx cache buffer is ready for receiving new host packet //Just Call Host main thread task to process pending packets. - hci_host_task_post(TASK_POST_BLOCKING); + hci_host_task_post(OSI_THREAD_MAX_TIMEOUT); } static int host_recv_pkt_cb(uint8_t *data, uint16_t len) @@ -367,9 +347,10 @@ static int host_recv_pkt_cb(uint8_t *data, uint16_t len) pkt->len = len; pkt->layer_specific = 0; memcpy(pkt->data, data, len); - fixed_queue_enqueue(hci_hal_env.rx_q, pkt); + fixed_queue_enqueue(hci_hal_env.rx_q, pkt, FIXED_QUEUE_MAX_TIMEOUT); hci_hal_h4_task_post(0); + BTTRC_DUMP_BUFFER("Recv Pkt", pkt->data, len); return 0; diff --git a/components/bt/bluedroid/hci/hci_layer.c b/components/bt/bluedroid/hci/hci_layer.c index c2b6223ce7..6c285339cc 100644 --- a/components/bt/bluedroid/hci/hci_layer.c +++ b/components/bt/bluedroid/hci/hci_layer.c @@ -21,6 +21,7 @@ #include "common/bt_trace.h" #include "stack/hcidefs.h" #include "stack/hcimsgs.h" +#include "stack/btu.h" #include "common/bt_vendor_lib.h" #include "hci/hci_internals.h" #include "hci/hci_hal.h" @@ -33,6 +34,11 @@ #include "osi/mutex.h" #include "osi/fixed_queue.h" +#define HCI_HOST_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE) +#define HCI_HOST_TASK_STACK_SIZE (2048 + BT_TASK_EXTRA_STACK_SIZE) +#define HCI_HOST_TASK_PRIO (BT_TASK_MAX_PRIORITIES - 3) +#define HCI_HOST_TASK_NAME "hciT" + typedef struct { uint16_t opcode; future_t *complete_future; @@ -70,10 +76,7 @@ static const uint32_t COMMAND_PENDING_TIMEOUT = 8000; static bool interface_created; static hci_t interface; static hci_host_env_t hci_host_env; - -static xTaskHandle xHciHostTaskHandle; -static xQueueHandle xHciHostQueue; - +static osi_thread_t *hci_host_thread; static bool hci_host_startup_flag; // Modules we import and callbacks we export @@ -102,11 +105,13 @@ int hci_start_up(void) goto error; } - xHciHostQueue = xQueueCreate(HCI_HOST_QUEUE_LEN, sizeof(BtTaskEvt_t)); - xTaskCreatePinnedToCore(hci_host_thread_handler, HCI_HOST_TASK_NAME, HCI_HOST_TASK_STACK_SIZE, NULL, HCI_HOST_TASK_PRIO, &xHciHostTaskHandle, HCI_HOST_TASK_PINNED_TO_CORE); + hci_host_thread = osi_thread_create(HCI_HOST_TASK_NAME, HCI_HOST_TASK_STACK_SIZE, HCI_HOST_TASK_PRIO, HCI_HOST_TASK_PINNED_TO_CORE, 2); + if (hci_host_thread == NULL) { + return -2; + } packet_fragmenter->init(&packet_fragmenter_callbacks); - hal->open(&hal_callbacks); + hal->open(&hal_callbacks, hci_host_thread); hci_host_startup_flag = true; return 0; @@ -124,28 +129,15 @@ void hci_shut_down(void) //low_power_manager->cleanup(); hal->close(); - vTaskDelete(xHciHostTaskHandle); - vQueueDelete(xHciHostQueue); + + osi_thread_free(hci_host_thread); + hci_host_thread = NULL; } -task_post_status_t hci_host_task_post(task_post_t timeout) +bool hci_host_task_post(uint32_t timeout) { - BtTaskEvt_t evt; - - if (hci_host_startup_flag == false) { - return TASK_POST_FAIL; - } - - evt.sig = SIG_HCI_HOST_SEND_AVAILABLE; - evt.par = 0; - - if (xQueueSend(xHciHostQueue, &evt, timeout) != pdTRUE) { - HCI_TRACE_ERROR("xHciHostQueue failed\n"); - return TASK_POST_FAIL; - } - - return TASK_POST_SUCCESS; + return osi_thread_post(hci_host_thread, hci_host_thread_handler, NULL, 0, timeout); } static int hci_layer_init_env(void) @@ -218,27 +210,17 @@ static void hci_host_thread_handler(void *arg) * All packets will be directly copied to single queue in driver layer with * H4 type header added (1 byte). */ - - BtTaskEvt_t e; - - for (;;) { - if (pdTRUE == xQueueReceive(xHciHostQueue, &e, (portTickType)portMAX_DELAY)) { - - if (e.sig == SIG_HCI_HOST_SEND_AVAILABLE) { - if (esp_vhci_host_check_send_available()) { - /*Now Target only allowed one packet per TX*/ - BT_HDR *pkt = packet_fragmenter->fragment_current_packet(); - if (pkt != NULL) { - packet_fragmenter->fragment_and_dispatch(pkt); - } else { - if (!fixed_queue_is_empty(hci_host_env.command_queue) && - hci_host_env.command_credits > 0) { - fixed_queue_process(hci_host_env.command_queue); - } else if (!fixed_queue_is_empty(hci_host_env.packet_queue)) { - fixed_queue_process(hci_host_env.packet_queue); - } - } - } + if (esp_vhci_host_check_send_available()) { + /*Now Target only allowed one packet per TX*/ + BT_HDR *pkt = packet_fragmenter->fragment_current_packet(); + if (pkt != NULL) { + packet_fragmenter->fragment_and_dispatch(pkt); + } else { + if (!fixed_queue_is_empty(hci_host_env.command_queue) && + hci_host_env.command_credits > 0) { + fixed_queue_process(hci_host_env.command_queue); + } else if (!fixed_queue_is_empty(hci_host_env.packet_queue)) { + fixed_queue_process(hci_host_env.packet_queue); } } } @@ -270,8 +252,8 @@ static void transmit_command( HCI_TRACE_DEBUG("HCI Enqueue Comamnd opcode=0x%x\n", wait_entry->opcode); BTTRC_DUMP_BUFFER(NULL, command->data + command->offset, command->len); - fixed_queue_enqueue(hci_host_env.command_queue, wait_entry); - hci_host_task_post(TASK_POST_BLOCKING); + fixed_queue_enqueue(hci_host_env.command_queue, wait_entry, FIXED_QUEUE_MAX_TIMEOUT); + hci_host_task_post(OSI_THREAD_MAX_TIMEOUT); } @@ -291,8 +273,8 @@ static future_t *transmit_command_futured(BT_HDR *command) // in case the upper layer didn't already command->event = MSG_STACK_TO_HC_HCI_CMD; - fixed_queue_enqueue(hci_host_env.command_queue, wait_entry); - hci_host_task_post(TASK_POST_BLOCKING); + fixed_queue_enqueue(hci_host_env.command_queue, wait_entry, FIXED_QUEUE_MAX_TIMEOUT); + hci_host_task_post(OSI_THREAD_MAX_TIMEOUT); return future; } @@ -302,10 +284,10 @@ static void transmit_downward(uint16_t type, void *data) transmit_command((BT_HDR *)data, NULL, NULL, NULL); HCI_TRACE_WARNING("%s legacy transmit of command. Use transmit_command instead.\n", __func__); } else { - fixed_queue_enqueue(hci_host_env.packet_queue, data); + fixed_queue_enqueue(hci_host_env.packet_queue, data, FIXED_QUEUE_MAX_TIMEOUT); } - hci_host_task_post(TASK_POST_BLOCKING); + hci_host_task_post(OSI_THREAD_MAX_TIMEOUT); } @@ -315,7 +297,7 @@ static void event_command_ready(fixed_queue_t *queue) waiting_command_t *wait_entry = NULL; command_waiting_response_t *cmd_wait_q = &hci_host_env.cmd_waiting_q; - wait_entry = fixed_queue_dequeue(queue); + wait_entry = fixed_queue_dequeue(queue, FIXED_QUEUE_MAX_TIMEOUT); if(wait_entry->opcode == HCI_HOST_NUM_PACKETS_DONE #if (BLE_ADV_REPORT_FLOW_CONTROL == TRUE) @@ -341,7 +323,7 @@ static void event_command_ready(fixed_queue_t *queue) static void event_packet_ready(fixed_queue_t *queue) { - BT_HDR *packet = (BT_HDR *)fixed_queue_dequeue(queue); + BT_HDR *packet = (BT_HDR *)fixed_queue_dequeue(queue, FIXED_QUEUE_MAX_TIMEOUT); // The queue may be the command queue or the packet queue, we don't care packet_fragmenter->fragment_and_dispatch(packet); @@ -479,7 +461,7 @@ intercepted: /*Tell HCI Host Task to continue TX Pending commands*/ if (hci_host_env.command_credits && !fixed_queue_is_empty(hci_host_env.command_queue)) { - hci_host_task_post(TASK_POST_BLOCKING); + hci_host_task_post(OSI_THREAD_MAX_TIMEOUT); } if (wait_entry) { @@ -507,7 +489,7 @@ static void dispatch_reassembled(BT_HDR *packet) { // Events should already have been dispatched before this point //Tell Up-layer received packet. - if (btu_task_post(SIG_BTU_HCI_MSG, packet, TASK_POST_BLOCKING) != TASK_POST_SUCCESS) { + if (btu_task_post(SIG_BTU_HCI_MSG, packet, OSI_THREAD_MAX_TIMEOUT) == false) { osi_free(packet); } } diff --git a/components/bt/bluedroid/hci/include/hci/hci_hal.h b/components/bt/bluedroid/hci/include/hci/hci_hal.h index 2928f29ad3..daf3dfb81a 100644 --- a/components/bt/bluedroid/hci/include/hci/hci_hal.h +++ b/components/bt/bluedroid/hci/include/hci/hci_hal.h @@ -51,7 +51,7 @@ typedef struct hci_hal_t { //bool (*init)(const hci_hal_callbacks_t *upper_callbacks); // Connect to the underlying hardware, and let data start flowing. - bool (*open)(const hci_hal_callbacks_t *upper_callbacks); + bool (*open)(const hci_hal_callbacks_t *upper_callbacks, void *task_thread); // Disconnect from the underlying hardware, and close the HAL. // "Daisy, Daisy..." void (*close)(void); diff --git a/components/bt/bluedroid/hci/include/hci/hci_layer.h b/components/bt/bluedroid/hci/include/hci/hci_layer.h index 4b1018098b..8fa5165e9f 100644 --- a/components/bt/bluedroid/hci/include/hci/hci_layer.h +++ b/components/bt/bluedroid/hci/include/hci/hci_layer.h @@ -23,6 +23,8 @@ #include "osi/allocator.h" #include "osi/osi.h" #include "osi/future.h" +#include "osi/thread.h" + ///// LEGACY DEFINITIONS ///// /* Message event mask across Host/Controller lib and stack */ @@ -95,5 +97,6 @@ const hci_t *hci_layer_get_interface(); int hci_start_up(void); void hci_shut_down(void); +bool hci_host_task_post(uint32_t timeout); #endif /* _HCI_LAYER_H_ */ diff --git a/components/bt/bluedroid/main/bte_init.c b/components/bt/bluedroid/main/bte_init.c index 38cfc812fb..7f3723ae55 100644 --- a/components/bt/bluedroid/main/bte_init.c +++ b/components/bt/bluedroid/main/bte_init.c @@ -116,7 +116,6 @@ #if BTA_JV_INCLUDED==TRUE #include "bta_jv_int.h" -tBTA_JV_CB *bta_jv_cb_ptr = NULL; #endif #if BTA_HL_INCLUDED == TRUE @@ -144,153 +143,6 @@ tBTA_JV_CB *bta_jv_cb_ptr = NULL; ** 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 -** -******************************************************************************/ -void BTE_InitStack(void) -{ -#if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == TRUE) - //Initialize the optional stack components - RFCOMM_Init(); -#endif - - //BNEP and its profiles -#if (defined(BNEP_INCLUDED) && BNEP_INCLUDED == TRUE) - BNEP_Init(); - -#if (defined(PAN_INCLUDED) && PAN_INCLUDED == TRUE) - PAN_Init(); -#endif // PAN -#endif // BNEP Included - - //AVDT and its profiles -#if (defined(A2D_INCLUDED) && A2D_INCLUDED == TRUE) - A2D_Init(); -#endif // AADP - -#if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE) - AVRC_Init(); -#endif - -#if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE && AVDT_DYNAMIC_MEMORY == TRUE) - if ((avdt_cb_ptr = (tAVDT_CB *)osi_malloc(sizeof(tAVDT_CB))) == NULL) { - return; - } - memset((void *)avdt_cb_ptr, 0, sizeof(tAVDT_CB)); -#endif - -#if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE && AVCT_DYNAMIC_MEMORY == TRUE) - if ((avct_cb_ptr = (tAVCT_CB *)osi_malloc(sizeof(tAVCT_CB))) == NULL) { - return; - } - memset((void *)avct_cb_ptr, 0, sizeof(tAVCT_CB)); -#endif - -#if (defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE) - GAP_Init(); -#endif - -#if (defined(HID_HOST_INCLUDED) && HID_HOST_INCLUDED == TRUE) - HID_HostInit(); -#endif - -#if (defined(MCA_INCLUDED) && MCA_INCLUDED == TRUE) - MCA_Init(); -#endif - - //BTA Modules -#if (BTA_INCLUDED == TRUE && BTA_DYNAMIC_MEMORY == TRUE) - if ((bta_sys_cb_ptr = (tBTA_SYS_CB *)osi_malloc(sizeof(tBTA_SYS_CB))) == NULL) { - return; - } - if ((bta_dm_cb_ptr = (tBTA_DM_CB *)osi_malloc(sizeof(tBTA_DM_CB))) == NULL) { - return; - } - if ((bta_dm_search_cb_ptr = (tBTA_DM_SEARCH_CB *)osi_malloc(sizeof(tBTA_DM_SEARCH_CB))) == NULL) { - return; - } - if ((bta_dm_di_cb_ptr = (tBTA_DM_DI_CB *)osi_malloc(sizeof(tBTA_DM_DI_CB))) == NULL) { - return; - } - 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 (defined BTA_HF_INCLUDED && BTA_HF_INCLUDED == TRUE) - if ((bta_hf_client_cb_ptr = (tBTA_HF_CLIENT_CB *)osi_malloc(sizeof(tBTA_HF_CLIENT_CB))) == NULL) { - return; - } - memset((void *)bta_hf_client_cb_ptr, 0, sizeof(tBTA_HF_CLIENT_CB)); -#endif -#if (defined BTA_JV_INCLUDED && BTA_JV_INCLUDED == TRUE) - if ((bta_jv_cb_ptr = (tBTA_JV_CB *)osi_malloc(sizeof(tBTA_JV_CB))) == NULL) { - return; - } - memset((void *)bta_jv_cb_ptr, 0, sizeof(tBTA_JV_CB)); -#endif //JV -#if BTA_HS_INCLUDED == TRUE - memset((void *)bta_hs_cb_ptr, 0, sizeof(tBTA_HS_CB)); -#endif -#if BTA_SDP_INCLUDED == TRUE - if ((bta_sdp_cb_ptr = (tBTA_SDP_CB *)osi_malloc(sizeof(tBTA_SDP_CB))) == NULL) { - return; - } - memset((void *)bta_sdp_cb_ptr, 0, sizeof(tBTA_SDP_CB)); -#endif -#if BTA_AR_INCLUDED==TRUE - if ((bta_ar_cb_ptr = (tBTA_AR_CB *)osi_malloc(sizeof(tBTA_AR_CB))) == NULL) { - return; - } - memset((void *)bta_ar_cb_ptr, 0, sizeof(tBTA_AR_CB)); -#endif -#if BTA_AV_INCLUDED==TRUE - if ((bta_av_cb_ptr = (tBTA_AV_CB *)osi_malloc(sizeof(tBTA_AV_CB))) == NULL) { - return; - } - memset((void *)bta_av_cb_ptr, 0, sizeof(tBTA_AV_CB)); -#endif -#if BTA_HH_INCLUDED==TRUE - if ((bta_hh_cb_ptr = (tBTA_HH_CB *)osi_malloc(sizeof(tBTA_HH_CB))) == NULL) { - return; - } - memset((void *)bta_hh_cb_ptr, 0, sizeof(tBTA_HH_CB)); -#endif -#if BTA_HL_INCLUDED==TRUE - memset((void *)bta_hl_cb_ptr, 0, sizeof(tBTA_HL_CB)); -#endif -#if GATTC_INCLUDED==TRUE - if ((bta_gattc_cb_ptr = (tBTA_GATTC_CB *)osi_malloc(sizeof(tBTA_GATTC_CB))) == NULL) { - return; - } - memset((void *)bta_gattc_cb_ptr, 0, sizeof(tBTA_GATTC_CB)); -#endif -#if GATTS_INCLUDED == TRUE - if ((bta_gatts_cb_ptr = (tBTA_GATTS_CB *)osi_malloc(sizeof(tBTA_GATTS_CB))) == NULL) { - return; - } - 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 -} - /***************************************************************************** ** ** Function BTE_DeinitStack @@ -308,55 +160,101 @@ void BTE_DeinitStack(void) //BTA Modules #if (BTA_INCLUDED == TRUE && BTA_DYNAMIC_MEMORY == TRUE) #if GATTS_INCLUDED == TRUE - osi_free(bta_gatts_cb_ptr); - bta_gatts_cb_ptr = NULL; + if (bta_gatts_cb_ptr){ + osi_free(bta_gatts_cb_ptr); + bta_gatts_cb_ptr = NULL; + } #endif #if GATTC_INCLUDED==TRUE - osi_free(bta_gattc_cb_ptr); - bta_gattc_cb_ptr = NULL; + if (bta_gattc_cb_ptr){ + osi_free(bta_gattc_cb_ptr); + bta_gattc_cb_ptr = NULL; + } #endif #if BTA_HH_INCLUDED==TRUE - osi_free(bta_hh_cb_ptr); - bta_hh_cb_ptr = NULL; + if (bta_hh_cb_ptr){ + osi_free(bta_hh_cb_ptr); + bta_hh_cb_ptr = NULL; + } #endif #if BTA_AV_INCLUDED==TRUE - osi_free(bta_av_cb_ptr); - bta_av_cb_ptr = NULL; + if (bta_av_cb_ptr){ + osi_free(bta_av_cb_ptr); + bta_av_cb_ptr = NULL; + } + if (bta_av_sbc_ups_cb_ptr){ + osi_free(bta_av_sbc_ups_cb_ptr); + bta_av_sbc_ups_cb_ptr = NULL; + } #endif #if BTA_AR_INCLUDED==TRUE - osi_free(bta_ar_cb_ptr); - bta_ar_cb_ptr = NULL; + if (bta_ar_cb_ptr){ + osi_free(bta_ar_cb_ptr); + bta_ar_cb_ptr = NULL; + } +#endif +#if SDP_INCLUDED == TRUE + if (g_disc_raw_data_buf){ + osi_free(g_disc_raw_data_buf); + g_disc_raw_data_buf = NULL; + } #endif #if BTA_SDP_INCLUDED == TRUE - osi_free(bta_sdp_cb_ptr); - bta_sdp_cb_ptr = NULL; + if (bta_sdp_cb_ptr){ + osi_free(bta_sdp_cb_ptr); + bta_sdp_cb_ptr = NULL; + } #endif #if (defined BTA_JV_INCLUDED && BTA_JV_INCLUDED == TRUE) - osi_free(bta_jv_cb_ptr); - bta_jv_cb_ptr = NULL; + if (bta_jv_cb_ptr){ + osi_free(bta_jv_cb_ptr); + bta_jv_cb_ptr = NULL; + } #endif //JV #if (defined BTA_HF_INCLUDED && BTA_HF_INCLUDED == TRUE) - osi_free(bta_hf_client_cb_ptr); - bta_hf_client_cb_ptr = NULL; + if (bta_hf_client_cb_ptr){ + osi_free(bta_hf_client_cb_ptr); + bta_hf_client_cb_ptr = NULL; + } #endif - osi_free(bta_dm_di_cb_ptr); - bta_dm_di_cb_ptr = NULL; - osi_free(bta_dm_search_cb_ptr); - bta_dm_search_cb_ptr = NULL; - osi_free(bta_dm_cb_ptr); - bta_dm_cb_ptr = NULL; - osi_free(bta_sys_cb_ptr); - bta_sys_cb_ptr = NULL; + if (bta_dm_conn_srvcs_ptr){ + osi_free(bta_dm_conn_srvcs_ptr); + bta_dm_conn_srvcs_ptr = NULL; + } + if (bta_dm_di_cb_ptr){ + osi_free(bta_dm_di_cb_ptr); + bta_dm_di_cb_ptr = NULL; + } + if (bta_dm_search_cb_ptr){ + osi_free(bta_dm_search_cb_ptr); + bta_dm_search_cb_ptr = NULL; + } + if (bta_dm_cb_ptr){ + osi_free(bta_dm_cb_ptr); + bta_dm_cb_ptr = NULL; + } + if (bta_sys_cb_ptr){ + osi_free(bta_sys_cb_ptr); + bta_sys_cb_ptr = NULL; + } #endif // BTA_INCLUDED == TRUE +#if (defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE) + GAP_Deinit(); +#endif + #if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE && AVCT_DYNAMIC_MEMORY == TRUE) - osi_free(avct_cb_ptr); - avct_cb_ptr = NULL; + if (avct_cb_ptr){ + osi_free(avct_cb_ptr); + avct_cb_ptr = NULL; + } #endif #if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE && AVDT_DYNAMIC_MEMORY == TRUE) - osi_free(avdt_cb_ptr); - avdt_cb_ptr = NULL; + if (avdt_cb_ptr){ + osi_free(avdt_cb_ptr); + avdt_cb_ptr = NULL; + } #endif #if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE) @@ -366,4 +264,184 @@ void BTE_DeinitStack(void) #if (defined(A2D_INCLUDED) && A2D_INCLUDED == TRUE) A2D_Deinit(); #endif + +#if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == TRUE) + RFCOMM_Deinit(); +#endif +} + +/***************************************************************************** +** +** 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 status +** +******************************************************************************/ +bt_status_t BTE_InitStack(void) +{ +#if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == TRUE) + //Initialize the optional stack components + if (RFCOMM_Init() != BT_STATUS_SUCCESS) { + goto error_exit; + } +#endif + + //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) + if (A2D_Init() != BT_STATUS_SUCCESS) { + goto error_exit; + } +#endif // AADP + +#if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE) + if (AVRC_Init() != BT_STATUS_SUCCESS) { + goto error_exit; + } +#endif + +#if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE && AVDT_DYNAMIC_MEMORY == TRUE) + if ((avdt_cb_ptr = (tAVDT_CB *)osi_malloc(sizeof(tAVDT_CB))) == NULL) { + goto error_exit; + } + memset((void *)avdt_cb_ptr, 0, sizeof(tAVDT_CB)); +#endif + +#if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE && AVCT_DYNAMIC_MEMORY == TRUE) + if ((avct_cb_ptr = (tAVCT_CB *)osi_malloc(sizeof(tAVCT_CB))) == NULL) { + goto error_exit; + } + memset((void *)avct_cb_ptr, 0, sizeof(tAVCT_CB)); +#endif + +#if (defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE) + if (GAP_Init() != BT_STATUS_SUCCESS) { + goto error_exit; + } +#endif + +#if (defined(HID_HOST_INCLUDED) && HID_HOST_INCLUDED == TRUE) + HID_HostInit(); +#endif + +#if (defined(MCA_INCLUDED) && MCA_INCLUDED == TRUE) + MCA_Init(); +#endif + + //BTA Modules +#if (BTA_INCLUDED == TRUE && BTA_DYNAMIC_MEMORY == TRUE) + if ((bta_sys_cb_ptr = (tBTA_SYS_CB *)osi_malloc(sizeof(tBTA_SYS_CB))) == NULL) { + goto error_exit; + } + if ((bta_dm_cb_ptr = (tBTA_DM_CB *)osi_malloc(sizeof(tBTA_DM_CB))) == NULL) { + goto error_exit; + } + if ((bta_dm_search_cb_ptr = (tBTA_DM_SEARCH_CB *)osi_malloc(sizeof(tBTA_DM_SEARCH_CB))) == NULL) { + goto error_exit; + } + if ((bta_dm_di_cb_ptr = (tBTA_DM_DI_CB *)osi_malloc(sizeof(tBTA_DM_DI_CB))) == NULL) { + goto error_exit; + } + if ((bta_dm_conn_srvcs_ptr = (tBTA_DM_CONNECTED_SRVCS *)osi_malloc(sizeof(tBTA_DM_CONNECTED_SRVCS))) == NULL) { + goto error_exit; + } + 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_dm_conn_srvcs_ptr, 0, sizeof(tBTA_DM_CONNECTED_SRVCS)); + //memset((void *)bta_prm_cb_ptr, 0, sizeof(tBTA_PRM_CB)); + +#if (defined BTA_HF_INCLUDED && BTA_HF_INCLUDED == TRUE) + if ((bta_hf_client_cb_ptr = (tBTA_HF_CLIENT_CB *)osi_malloc(sizeof(tBTA_HF_CLIENT_CB))) == NULL) { + goto error_exit; + } + memset((void *)bta_hf_client_cb_ptr, 0, sizeof(tBTA_HF_CLIENT_CB)); +#endif +#if (defined BTA_JV_INCLUDED && BTA_JV_INCLUDED == TRUE) + if ((bta_jv_cb_ptr = (tBTA_JV_CB *)osi_malloc(sizeof(tBTA_JV_CB))) == NULL) { + goto error_exit; + } + memset((void *)bta_jv_cb_ptr, 0, sizeof(tBTA_JV_CB)); +#endif //JV +#if BTA_HS_INCLUDED == TRUE + memset((void *)bta_hs_cb_ptr, 0, sizeof(tBTA_HS_CB)); +#endif +#if BTA_SDP_INCLUDED == TRUE + if ((bta_sdp_cb_ptr = (tBTA_SDP_CB *)osi_malloc(sizeof(tBTA_SDP_CB))) == NULL) { + goto error_exit; + } + memset((void *)bta_sdp_cb_ptr, 0, sizeof(tBTA_SDP_CB)); +#endif +#if SDP_INCLUDED == TRUE + if ((g_disc_raw_data_buf = (UINT8 *)osi_malloc(MAX_DISC_RAW_DATA_BUF)) == NULL) { + goto error_exit; + } + memset((void *)g_disc_raw_data_buf, 0, MAX_DISC_RAW_DATA_BUF); +#endif +#if BTA_AR_INCLUDED==TRUE + if ((bta_ar_cb_ptr = (tBTA_AR_CB *)osi_malloc(sizeof(tBTA_AR_CB))) == NULL) { + goto error_exit; + } + memset((void *)bta_ar_cb_ptr, 0, sizeof(tBTA_AR_CB)); +#endif +#if BTA_AV_INCLUDED==TRUE + if ((bta_av_cb_ptr = (tBTA_AV_CB *)osi_malloc(sizeof(tBTA_AV_CB))) == NULL) { + goto error_exit; + } + memset((void *)bta_av_cb_ptr, 0, sizeof(tBTA_AV_CB)); + + if ((bta_av_sbc_ups_cb_ptr = (tBTA_AV_SBC_UPS_CB *)osi_malloc(sizeof(tBTA_AV_SBC_UPS_CB))) == NULL) { + goto error_exit; + } + memset((void *)bta_av_sbc_ups_cb_ptr, 0, sizeof(tBTA_AV_SBC_UPS_CB)); +#endif +#if BTA_HH_INCLUDED==TRUE + if ((bta_hh_cb_ptr = (tBTA_HH_CB *)osi_malloc(sizeof(tBTA_HH_CB))) == NULL) { + goto error_exit; + } + memset((void *)bta_hh_cb_ptr, 0, sizeof(tBTA_HH_CB)); +#endif +#if BTA_HL_INCLUDED==TRUE + memset((void *)bta_hl_cb_ptr, 0, sizeof(tBTA_HL_CB)); +#endif +#if GATTC_INCLUDED==TRUE + if ((bta_gattc_cb_ptr = (tBTA_GATTC_CB *)osi_malloc(sizeof(tBTA_GATTC_CB))) == NULL) { + goto error_exit; + } + memset((void *)bta_gattc_cb_ptr, 0, sizeof(tBTA_GATTC_CB)); +#endif +#if GATTS_INCLUDED == TRUE + if ((bta_gatts_cb_ptr = (tBTA_GATTS_CB *)osi_malloc(sizeof(tBTA_GATTS_CB))) == NULL) { + goto error_exit; + } + 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 + return BT_STATUS_SUCCESS; + +error_exit:; + LOG_ERROR("%s failed due to no memory", __func__); + BTE_DeinitStack(); + return BT_STATUS_NOMEM; } diff --git a/components/bt/bluedroid/osi/alarm.c b/components/bt/bluedroid/osi/alarm.c index 5307010590..21241b96da 100644 --- a/components/bt/bluedroid/osi/alarm.c +++ b/components/bt/bluedroid/osi/alarm.c @@ -44,7 +44,11 @@ enum { static osi_mutex_t alarm_mutex; static int alarm_state; +#if BT_BLE_DYNAMIC_ENV_MEMORY == FALSE static struct alarm_t alarm_cbs[ALARM_CBS_NUM]; +#else +static struct alarm_t *alarm_cbs; +#endif static osi_alarm_err_t alarm_free(osi_alarm_t *alarm); static osi_alarm_err_t alarm_set(osi_alarm_t *alarm, period_ms_t timeout, bool is_periodic); @@ -78,7 +82,14 @@ void osi_alarm_init(void) OSI_TRACE_WARNING("%s, invalid state %d\n", __func__, alarm_state); goto end; } - memset(alarm_cbs, 0x00, sizeof(alarm_cbs)); +#if BT_BLE_DYNAMIC_ENV_MEMORY == TRUE + if ((alarm_cbs = (osi_alarm_t *)osi_malloc(sizeof(osi_alarm_t) * ALARM_CBS_NUM)) == NULL) { + OSI_TRACE_ERROR("%s, malloc failed\n", __func__); + goto end; + } +#endif + + memset(alarm_cbs, 0x00, sizeof(osi_alarm_t) * ALARM_CBS_NUM); alarm_state = ALARM_STATE_OPEN; end: @@ -100,6 +111,12 @@ void osi_alarm_deinit(void) alarm_free(&alarm_cbs[i]); } } + +#if BT_BLE_DYNAMIC_ENV_MEMORY == TRUE + osi_free(alarm_cbs); + alarm_cbs = NULL; +#endif + alarm_state = ALARM_STATE_IDLE; end: diff --git a/components/bt/bluedroid/osi/allocator.c b/components/bt/bluedroid/osi/allocator.c index 866ccc2e26..569bb5f021 100644 --- a/components/bt/bluedroid/osi/allocator.c +++ b/components/bt/bluedroid/osi/allocator.c @@ -24,7 +24,8 @@ extern void *pvPortZalloc(size_t size); extern void vPortFree(void *pv); -#ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG + +#if HEAP_MEMORY_DEBUG #define OSI_MEM_DBG_INFO_MAX 1024*3 typedef struct { @@ -35,8 +36,16 @@ typedef struct { } osi_mem_dbg_info_t; static uint32_t mem_dbg_count = 0; -static uint32_t mem_dbg_count2 = 0; static osi_mem_dbg_info_t mem_dbg_info[OSI_MEM_DBG_INFO_MAX]; +static uint32_t mem_dbg_current_size = 0; +static uint32_t mem_dbg_max_size = 0; + +#define OSI_MEM_DBG_MAX_SECTION_NUM 5 +typedef struct { + bool used; + uint32_t max_size; +} osi_mem_dbg_max_size_section_t; +static osi_mem_dbg_max_size_section_t mem_dbg_max_size_section[OSI_MEM_DBG_MAX_SECTION_NUM]; void osi_mem_dbg_init(void) { @@ -49,7 +58,13 @@ void osi_mem_dbg_init(void) mem_dbg_info[i].line = 0; } mem_dbg_count = 0; - mem_dbg_count2 = 0; + mem_dbg_current_size = 0; + mem_dbg_max_size = 0; + + for (i = 0; i < OSI_MEM_DBG_MAX_SECTION_NUM; i++){ + mem_dbg_max_size_section[i].used = false; + mem_dbg_max_size_section[i].max_size = 0; + } } void osi_mem_dbg_record(void *p, int size, const char *func, int line) @@ -75,6 +90,19 @@ void osi_mem_dbg_record(void *p, int size, const char *func, int line) if (i >= OSI_MEM_DBG_INFO_MAX) { OSI_TRACE_ERROR("%s full %s %d !!\n", __func__, func, line); } + + mem_dbg_current_size += size; + if(mem_dbg_max_size < mem_dbg_current_size) { + mem_dbg_max_size = mem_dbg_current_size; + } + + for (i = 0; i < OSI_MEM_DBG_MAX_SECTION_NUM; i++){ + if (mem_dbg_max_size_section[i].used) { + if(mem_dbg_max_size_section[i].max_size < mem_dbg_current_size) { + mem_dbg_max_size_section[i].max_size = mem_dbg_current_size; + } + } + } } void osi_mem_dbg_clean(void *p, const char *func, int line) @@ -88,6 +116,7 @@ void osi_mem_dbg_clean(void *p, const char *func, int line) for (i = 0; i < OSI_MEM_DBG_INFO_MAX; i++) { if (mem_dbg_info[i].p == p) { + mem_dbg_current_size -= mem_dbg_info[i].size; mem_dbg_info[i].p = NULL; mem_dbg_info[i].size = 0; mem_dbg_info[i].func = NULL; @@ -112,6 +141,60 @@ void osi_mem_dbg_show(void) } } OSI_TRACE_ERROR("--> count %d\n", mem_dbg_count); + OSI_TRACE_ERROR("--> size %dB\n--> max size %dB\n", mem_dbg_current_size, mem_dbg_max_size); +} + +uint32_t osi_mem_dbg_get_max_size(void) +{ + return mem_dbg_max_size; +} + +uint32_t osi_mem_dbg_get_current_size(void) +{ + return mem_dbg_current_size; +} + +void osi_men_dbg_set_section_start(uint8_t index) +{ + if (index >= OSI_MEM_DBG_MAX_SECTION_NUM) { + OSI_TRACE_ERROR("Then range of index should be between 0 and %d, current index is %d.\n", + OSI_MEM_DBG_MAX_SECTION_NUM - 1, index); + return; + } + + if (mem_dbg_max_size_section[index].used) { + OSI_TRACE_WARNING("This index(%d) has been started, restart it.\n", index); + } + + mem_dbg_max_size_section[index].used = true; + mem_dbg_max_size_section[index].max_size = mem_dbg_current_size; +} + +void osi_men_dbg_set_section_end(uint8_t index) +{ + if (index >= OSI_MEM_DBG_MAX_SECTION_NUM) { + OSI_TRACE_ERROR("Then range of index should be between 0 and %d, current index is %d.\n", + OSI_MEM_DBG_MAX_SECTION_NUM - 1, index); + return; + } + + if (!mem_dbg_max_size_section[index].used) { + OSI_TRACE_ERROR("This index(%d) has not been started.\n", index); + return; + } + + mem_dbg_max_size_section[index].used = false; +} + +uint32_t osi_mem_dbg_get_max_size_section(uint8_t index) +{ + if (index >= OSI_MEM_DBG_MAX_SECTION_NUM){ + OSI_TRACE_ERROR("Then range of index should be between 0 and %d, current index is %d.\n", + OSI_MEM_DBG_MAX_SECTION_NUM - 1, index); + return 0; + } + + return mem_dbg_max_size_section[index].max_size; } #endif @@ -130,48 +213,48 @@ char *osi_strdup(const char *str) void *osi_malloc_func(size_t size) { -#ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG +#if HEAP_MEMORY_DEBUG void *p; -#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST +#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST p = heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); #else p = malloc(size); -#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */ +#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */ osi_mem_dbg_record(p, size, __func__, __LINE__); return p; #else -#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST +#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); #else return malloc(size); -#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */ -#endif /* #ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG */ +#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */ +#endif /* #if HEAP_MEMORY_DEBUG */ } void *osi_calloc_func(size_t size) { -#ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG +#if HEAP_MEMORY_DEBUG void *p; -#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST +#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST p = heap_caps_calloc_prefer(1, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); #else p = calloc(1, size); -#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */ +#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */ osi_mem_dbg_record(p, size, __func__, __LINE__); return p; #else -#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST +#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST return heap_caps_calloc_prefer(1, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); #else return calloc(1, size); -#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */ -#endif /* #ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG */ +#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */ +#endif /* #if HEAP_MEMORY_DEBUG */ } void osi_free_func(void *ptr) { -#ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG - osi_mem_dbg_clean(ptr, __func__, __LINE__); +#if HEAP_MEMORY_DEBUG + osi_mem_dbg_clean(ptr, __func__, __LINE__); #endif free(ptr); } diff --git a/components/bt/bluedroid/osi/fixed_queue.c b/components/bt/bluedroid/osi/fixed_queue.c index 30290060aa..0b21dd8be1 100644 --- a/components/bt/bluedroid/osi/fixed_queue.c +++ b/components/bt/bluedroid/osi/fixed_queue.c @@ -129,45 +129,12 @@ size_t fixed_queue_capacity(fixed_queue_t *queue) return queue->capacity; } -void fixed_queue_enqueue(fixed_queue_t *queue, void *data) +bool fixed_queue_enqueue(fixed_queue_t *queue, void *data, uint32_t timeout) { assert(queue != NULL); assert(data != NULL); - osi_sem_take(&queue->enqueue_sem, OSI_SEM_MAX_TIMEOUT); - - osi_mutex_lock(&queue->lock, OSI_MUTEX_MAX_TIMEOUT); - - list_append(queue->list, data); - osi_mutex_unlock(&queue->lock); - - osi_sem_give(&queue->dequeue_sem); -} - -void *fixed_queue_dequeue(fixed_queue_t *queue) -{ - void *ret = NULL; - - assert(queue != NULL); - - osi_sem_take(&queue->dequeue_sem, OSI_SEM_MAX_TIMEOUT); - - osi_mutex_lock(&queue->lock, OSI_MUTEX_MAX_TIMEOUT); - ret = list_front(queue->list); - list_remove(queue->list, ret); - osi_mutex_unlock(&queue->lock); - - osi_sem_give(&queue->enqueue_sem); - - return ret; -} - -bool fixed_queue_try_enqueue(fixed_queue_t *queue, void *data) -{ - assert(queue != NULL); - assert(data != NULL); - - if (osi_sem_take(&queue->enqueue_sem, 0) != 0) { + if (osi_sem_take(&queue->enqueue_sem, timeout) != 0) { return false; } @@ -181,15 +148,13 @@ bool fixed_queue_try_enqueue(fixed_queue_t *queue, void *data) return true; } -void *fixed_queue_try_dequeue(fixed_queue_t *queue) +void *fixed_queue_dequeue(fixed_queue_t *queue, uint32_t timeout) { void *ret = NULL; - if (queue == NULL) { - return NULL; - } + assert(queue != NULL); - if (osi_sem_take(queue->dequeue_sem, 0) != 0) { + if (osi_sem_take(queue->dequeue_sem, timeout) != 0) { return NULL; } diff --git a/components/bt/bluedroid/osi/include/osi/allocator.h b/components/bt/bluedroid/osi/include/osi/allocator.h index 3be366e76a..579f2b2bb6 100644 --- a/components/bt/bluedroid/osi/include/osi/allocator.h +++ b/components/bt/bluedroid/osi/include/osi/allocator.h @@ -22,7 +22,6 @@ #include #include #include "esp_heap_caps.h" -#include "sdkconfig.h" char *osi_strdup(const char *str); @@ -30,14 +29,19 @@ void *osi_malloc_func(size_t size); void *osi_calloc_func(size_t size); void osi_free_func(void *ptr); -#ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG +#if HEAP_MEMORY_DEBUG void osi_mem_dbg_init(void); void osi_mem_dbg_record(void *p, int size, const char *func, int line); void osi_mem_dbg_clean(void *p, const char *func, int line); void osi_mem_dbg_show(void); +uint32_t osi_mem_dbg_get_max_size(void); +uint32_t osi_mem_dbg_get_current_size(void); +void osi_men_dbg_set_section_start(uint8_t index); +void osi_men_dbg_set_section_end(uint8_t index); +uint32_t osi_mem_dbg_get_max_size_section(uint8_t index); -#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST +#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST #define osi_malloc(size) \ ({ \ void *p; \ @@ -68,15 +72,15 @@ void osi_mem_dbg_show(void); (void *)p; \ }) -#define osi_calloc(size) \ -({ \ - void *p; \ +#define osi_calloc(size) \ +({ \ + void *p; \ p = calloc(1, (size)); \ osi_mem_dbg_record(p, size, __func__, __LINE__); \ (void *)p; \ }) -#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */ +#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */ #if 0 @@ -84,11 +88,11 @@ void osi_mem_dbg_show(void); do { \ void *p; \ \ -#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST \ +#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST \ p = heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); \ #else \ p = malloc((size)); \ -#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */ \ +#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */ \ osi_mem_dbg_record(p, size, __func__, __LINE__); \ (void *)p; \ }while(0) @@ -97,13 +101,13 @@ do { \ do { \ void *p; \ \ -#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST \ +#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST \ p = heap_caps_calloc_prefer(1, size, 2, \ MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, \ MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); \ #else \ p = calloc(1, (size)); \ -#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */ \ +#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */ \ osi_mem_dbg_record(p, size, __func__, __LINE__); \ (void *)p; \ } while(0) @@ -118,16 +122,16 @@ do { \ #else -#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST +#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST #define osi_malloc(size) heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL) #define osi_calloc(size) heap_caps_calloc_prefer(1, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL) #else #define osi_malloc(size) malloc((size)) #define osi_calloc(size) calloc(1, (size)) -#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */ +#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */ #define osi_free(p) free((p)) -#endif /* CONFIG_BT_BLUEDROID_MEM_DEBUG */ +#endif /* HEAP_MEMORY_DEBUG */ #define FREE_AND_RESET(a) \ do { \ diff --git a/components/bt/bluedroid/osi/include/osi/fixed_queue.h b/components/bt/bluedroid/osi/include/osi/fixed_queue.h index 5ec0c07498..a25e60393c 100644 --- a/components/bt/bluedroid/osi/include/osi/fixed_queue.h +++ b/components/bt/bluedroid/osi/include/osi/fixed_queue.h @@ -21,11 +21,14 @@ #include #include "osi/list.h" +#include "osi/semaphore.h" #ifndef QUEUE_SIZE_MAX #define QUEUE_SIZE_MAX 254 #endif +#define FIXED_QUEUE_MAX_TIMEOUT OSI_SEM_MAX_TIMEOUT + struct fixed_queue_t; typedef struct fixed_queue_t fixed_queue_t; @@ -56,27 +59,14 @@ size_t fixed_queue_length(fixed_queue_t *queue); // not be NULL. size_t fixed_queue_capacity(fixed_queue_t *queue); -// Enqueues the given |data| into the |queue|. The caller will be blocked -// if nore more space is available in the queue. Neither |queue| nor |data| -// may be NULL. -void fixed_queue_enqueue(fixed_queue_t *queue, void *data); +// Enqueues the given |data| into the |queue|. The caller will be blocked or immediately return or wait for timeout according to the parameter timeout. +// If enqueue failed, it will return false, otherwise return true +bool fixed_queue_enqueue(fixed_queue_t *queue, void *data, uint32_t timeout); // Dequeues the next element from |queue|. If the queue is currently empty, -// this function will block the caller until an item is enqueued. This -// function will never return NULL. |queue| may not be NULL. -void *fixed_queue_dequeue(fixed_queue_t *queue); - -// Tries to enqueue |data| into the |queue|. This function will never block -// the caller. If the queue capacity would be exceeded by adding one more -// element, this function returns false immediately. Otherwise, this function -// returns true. Neither |queue| nor |data| may be NULL. -bool fixed_queue_try_enqueue(fixed_queue_t *queue, void *data); - -// Tries to dequeue an element from |queue|. This function will never block -// the caller. If the queue is empty, this function returns NULL immediately. -// Otherwise, the next element in the queue is returned. |queue| may not be -// NULL. -void *fixed_queue_try_dequeue(fixed_queue_t *queue); +// this function will block the caller until an item is enqueued or immediately return or wait for timeout according to the parameter timeout. +// If dequeue failed, it will return NULL, otherwise return a point. +void *fixed_queue_dequeue(fixed_queue_t *queue, uint32_t timeout); // Returns the first element from |queue|, if present, without dequeuing it. // This function will never block the caller. Returns NULL if there are no diff --git a/components/bt/bluedroid/osi/include/osi/mutex.h b/components/bt/bluedroid/osi/include/osi/mutex.h index 65180a7850..1b9784d62b 100644 --- a/components/bt/bluedroid/osi/include/osi/mutex.h +++ b/components/bt/bluedroid/osi/include/osi/mutex.h @@ -23,9 +23,9 @@ #include "freertos/task.h" #include "freertos/queue.h" #include "freertos/semphr.h" +#include "osi/semaphore.h" - -#define OSI_MUTEX_MAX_TIMEOUT 0xffffffffUL +#define OSI_MUTEX_MAX_TIMEOUT OSI_SEM_MAX_TIMEOUT #define osi_mutex_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE ) #define osi_mutex_set_invalid( x ) ( ( *x ) = NULL ) diff --git a/components/bt/bluedroid/osi/include/osi/thread.h b/components/bt/bluedroid/osi/include/osi/thread.h index bad1e48809..7f4c46aedf 100644 --- a/components/bt/bluedroid/osi/include/osi/thread.h +++ b/components/bt/bluedroid/osi/include/osi/thread.h @@ -22,94 +22,71 @@ #include "freertos/task.h" #include "esp_task.h" #include "common/bt_defs.h" +#include "osi/semaphore.h" #define portBASE_TYPE int -struct bt_task_evt { - uint32_t sig; //task sig - void *par; //point to task param - void *cb; //point to function cb - void *arg; //point to function arg -}; -typedef struct bt_task_evt BtTaskEvt_t; +#define OSI_THREAD_MAX_TIMEOUT OSI_SEM_MAX_TIMEOUT -typedef bt_status_t (* BtTaskCb_t)(void *arg); +struct osi_thread; + +typedef struct osi_thread osi_thread_t; + +typedef void (*osi_thread_func_t)(void *context); typedef enum { - SIG_HCI_HAL_RECV_PACKET = 0, - SIG_HCI_HAL_NUM, -} SIG_HCI_HAL_t; + OSI_THREAD_CORE_0 = 0, + OSI_THREAD_CORE_1, + OSI_THREAD_CORE_AFFINITY, +} osi_thread_core_t; +/* + * brief: Create a thread or task + * param name: thread name + * param stack_size: thread stack size + * param priority: thread priority + * param core: the CPU core which this thread run, OSI_THREAD_CORE_AFFINITY means unspecific CPU core + * param work_queue_num: speicify queue number, the queue[0] has highest priority, and the priority is decrease by index + * return : if create successfully, return thread handler; otherwise return NULL. + */ +osi_thread_t *osi_thread_create(const char *name, size_t stack_size, int priority, osi_thread_core_t core, uint8_t work_queue_num); -typedef enum { - SIG_HCI_HOST_SEND_AVAILABLE = 0, - SIG_HCI_HOST_NUM, -} SIG_HCI_HOST_t; +/* + * brief: Destroy a thread or task + * param thread: point of thread handler + */ +void osi_thread_free(osi_thread_t *thread); -typedef enum { - SIG_BTU_START_UP = 0, - SIG_BTU_HCI_MSG, - SIG_BTU_BTA_MSG, - SIG_BTU_BTA_ALARM, - SIG_BTU_GENERAL_ALARM, - SIG_BTU_ONESHOT_ALARM, - SIG_BTU_L2CAP_ALARM, - SIG_BTU_NUM, -} SIG_BTU_t; +/* + * brief: Post an msg to a thread and told the thread call the function + * param thread: point of thread handler + * param func: callback function that called by target thread + * param context: argument of callback function + * param queue_idx: the queue which the msg send to + * param timeout: post timeout, OSI_THREAD_MAX_TIMEOUT means blocking forever, 0 means never blocking, others means block millisecond + * return : if post successfully, return true, otherwise return false + */ +bool osi_thread_post(osi_thread_t *thread, osi_thread_func_t func, void *context, int queue_idx, uint32_t timeout); -#define TASK_PINNED_TO_CORE (CONFIG_BT_BLUEDROID_PINNED_TO_CORE < portNUM_PROCESSORS ? CONFIG_BT_BLUEDROID_PINNED_TO_CORE : tskNO_AFFINITY) +/* + * brief: Set the priority of thread + * param thread: point of thread handler + * param priority: priority + * return : if set successfully, return true, otherwise return false + */ +bool osi_thread_set_priority(osi_thread_t *thread, int priority); -#define HCI_HOST_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE) -#define HCI_HOST_TASK_STACK_SIZE (2048 + BT_TASK_EXTRA_STACK_SIZE) -#define HCI_HOST_TASK_PRIO (configMAX_PRIORITIES - 3) -#define HCI_HOST_TASK_NAME "hciHostT" -#define HCI_HOST_QUEUE_LEN 40 +/* brief: Get thread name + * param thread: point of thread handler + * return: constant point of thread name + */ +const char *osi_thread_name(osi_thread_t *thread); -#define HCI_H4_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE) -#define HCI_H4_TASK_STACK_SIZE (2048 + BT_TASK_EXTRA_STACK_SIZE) -#define HCI_H4_TASK_PRIO (configMAX_PRIORITIES - 4) -#define HCI_H4_TASK_NAME "hciH4T" -#define HCI_H4_QUEUE_LEN 1 - -#define BTU_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE) -#define BTU_TASK_STACK_SIZE (CONFIG_BT_BTU_TASK_STACK_SIZE + BT_TASK_EXTRA_STACK_SIZE) -#define BTU_TASK_PRIO (configMAX_PRIORITIES - 5) -#define BTU_TASK_NAME "btuT" -#define BTU_QUEUE_LEN 50 - -#define BTC_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE) -#define BTC_TASK_STACK_SIZE (CONFIG_BT_BTC_TASK_STACK_SIZE + BT_TASK_EXTRA_STACK_SIZE) //by menuconfig -#define BTC_TASK_NAME "btcT" -#define BTC_TASK_PRIO (configMAX_PRIORITIES - 6) -#define BTC_TASK_QUEUE_LEN 60 - -#define BTC_A2DP_SINK_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE) -#define BTC_A2DP_SINK_TASK_STACK_SIZE (CONFIG_BT_A2DP_SINK_TASK_STACK_SIZE + BT_TASK_EXTRA_STACK_SIZE) // by menuconfig -#define BTC_A2DP_SINK_TASK_NAME "BtA2dSinkT" -#define BTC_A2DP_SINK_TASK_PRIO (configMAX_PRIORITIES - 3) -#define BTC_A2DP_SINK_DATA_QUEUE_LEN (3) -#define BTC_A2DP_SINK_CTRL_QUEUE_LEN (5) -#define BTC_A2DP_SINK_TASK_QUEUE_SET_LEN (BTC_A2DP_SINK_DATA_QUEUE_LEN + BTC_A2DP_SINK_CTRL_QUEUE_LEN) - -#define BTC_A2DP_SOURCE_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE) -#define BTC_A2DP_SOURCE_TASK_STACK_SIZE (CONFIG_BT_A2DP_SOURCE_TASK_STACK_SIZE + BT_TASK_EXTRA_STACK_SIZE) // by menuconfig -#define BTC_A2DP_SOURCE_TASK_NAME "BtA2dSourceT" -#define BTC_A2DP_SOURCE_TASK_PRIO (configMAX_PRIORITIES - 3) -#define BTC_A2DP_SOURCE_DATA_QUEUE_LEN (1) -#define BTC_A2DP_SOURCE_CTRL_QUEUE_LEN (5) -#define BTC_A2DP_SOURCE_TASK_QUEUE_SET_LEN (BTC_A2DP_SOURCE_DATA_QUEUE_LEN + BTC_A2DP_SOURCE_CTRL_QUEUE_LEN) - -#define TASK_POST_NON_BLOCKING (0) -#define TASK_POST_BLOCKING (portMAX_DELAY) -typedef uint32_t task_post_t; /* Timeout of task post return, unit TICK */ - -typedef enum { - TASK_POST_SUCCESS = 0, - TASK_POST_FAIL, -} task_post_status_t; - -task_post_status_t btu_task_post(uint32_t sig, void *param, task_post_t timeout); -task_post_status_t hci_host_task_post(task_post_t timeout); -task_post_status_t hci_hal_h4_task_post(task_post_t timeout); +/* brief: Get the size of the specified queue + * param thread: point of thread handler + * param wq_idx: the queue index of the thread + * return: queue size + */ +int osi_thread_queue_wait_size(osi_thread_t *thread, int wq_idx); #endif /* __THREAD_H__ */ diff --git a/components/bt/bluedroid/osi/thread.c b/components/bt/bluedroid/osi/thread.c new file mode 100644 index 0000000000..04583061c3 --- /dev/null +++ b/components/bt/bluedroid/osi/thread.c @@ -0,0 +1,278 @@ +/****************************************************************************** + * + * 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. + * + ******************************************************************************/ + +#include + +#include "osi/allocator.h" +#include "osi/fixed_queue.h" +#include "osi/semaphore.h" +#include "osi/thread.h" + +struct osi_thread { + void *thread_handle; /*!< Store the thread object */ + int thread_id; /*!< May for some OS, such as Linux */ + bool stop; + uint8_t work_queue_num; /*!< Work queue number */ + fixed_queue_t **work_queues; /*!< Point to queue array, and the priority inverse array index */ + osi_sem_t work_sem; + osi_sem_t stop_sem; +}; + +struct osi_thread_start_arg { + osi_thread_t *thread; + osi_sem_t start_sem; + int error; +}; + +typedef struct { + osi_thread_func_t func; + void *context; +} work_item_t; + +static const size_t DEFAULT_WORK_QUEUE_CAPACITY = 100; + +static void osi_thread_run(void *arg) +{ + struct osi_thread_start_arg *start = (struct osi_thread_start_arg *)arg; + osi_thread_t *thread = start->thread; + + osi_sem_give(&start->start_sem); + + while (1) { + int idx = 0; + + osi_sem_take(&thread->work_sem, OSI_SEM_MAX_TIMEOUT); + + if (thread->stop) { + break; + } + + while (!thread->stop && idx < thread->work_queue_num) { + work_item_t *item = fixed_queue_dequeue(thread->work_queues[idx], 0); + if (item) { + item->func(item->context); + osi_free(item); + idx = 0; + continue; + } else { + idx++; + } + } + } + + thread->thread_handle = NULL; + osi_sem_give(&thread->stop_sem); + + vTaskDelete(NULL); +} + +static int osi_thread_join(osi_thread_t *thread, uint32_t wait_ms) +{ + assert(thread != NULL); + return osi_sem_take(&thread->stop_sem, wait_ms); +} + +static void osi_thread_stop(osi_thread_t *thread) +{ + int ret; + + assert(thread != NULL); + + //stop the thread + thread->stop = true; + osi_sem_give(&thread->work_sem); + + //join + ret = osi_thread_join(thread, 1000); //wait 1000ms + + //if join failed, delete the task here + if (ret != 0 && thread->thread_handle) { + vTaskDelete(thread->thread_handle); + } +} + +//in linux, the stack_size, priority and core may not be set here, the code will be ignore the arguments +osi_thread_t *osi_thread_create(const char *name, size_t stack_size, int priority, osi_thread_core_t core, uint8_t work_queue_num) +{ + int ret; + osi_thread_t *thread; + struct osi_thread_start_arg start_arg = {0}; + + if (stack_size <= 0 || + core < OSI_THREAD_CORE_0 || core > OSI_THREAD_CORE_AFFINITY || + work_queue_num <= 0) { + return NULL; + } + + thread = (osi_thread_t *)osi_malloc(sizeof(osi_thread_t)); + if (thread == NULL) { + goto _err; + } + + thread->stop = false; + thread->work_queue_num = work_queue_num; + thread->work_queues = (fixed_queue_t **)osi_malloc(sizeof(fixed_queue_t *) * work_queue_num); + if (thread->work_queues == NULL) { + goto _err; + } + + for (int i = 0; i < thread->work_queue_num; i++) { + thread->work_queues[i] = fixed_queue_new(DEFAULT_WORK_QUEUE_CAPACITY); + if (thread->work_queues[i] == NULL) { + goto _err; + } + } + + ret = osi_sem_new(&thread->work_sem, 1, 0); + if (ret != 0) { + goto _err; + } + + ret = osi_sem_new(&thread->stop_sem, 1, 0); + if (ret != 0) { + goto _err; + } + + start_arg.thread = thread; + ret = osi_sem_new(&start_arg.start_sem, 1, 0); + if (ret != 0) { + goto _err; + } + + if (xTaskCreatePinnedToCore(osi_thread_run, name, stack_size, &start_arg, priority, &thread->thread_handle, core) != pdPASS) { + goto _err; + } + + osi_sem_take(&start_arg.start_sem, OSI_SEM_MAX_TIMEOUT); + osi_sem_free(&start_arg.start_sem); + + return thread; + +_err: + + if (thread) { + if (start_arg.start_sem) { + osi_sem_free(&start_arg.start_sem); + } + + if (thread->thread_handle) { + vTaskDelete(thread->thread_handle); + } + + for (int i = 0; i < thread->work_queue_num; i++) { + if (thread->work_queues[i]) { + fixed_queue_free(thread->work_queues[i], osi_free_func); + } + } + + if (thread->work_queues) { + osi_free(thread->work_queues); + } + + if (thread->work_sem) { + osi_sem_free(&thread->work_sem); + } + + if (thread->stop_sem) { + osi_sem_free(&thread->stop_sem); + } + + osi_free(thread); + } + + return NULL; +} + +void osi_thread_free(osi_thread_t *thread) +{ + if (!thread) + return; + + osi_thread_stop(thread); + + for (int i = 0; i < thread->work_queue_num; i++) { + if (thread->work_queues[i]) { + fixed_queue_free(thread->work_queues[i], osi_free_func); + } + } + + if (thread->work_queues) { + osi_free(thread->work_queues); + } + + if (thread->work_sem) { + osi_sem_free(&thread->work_sem); + } + + if (thread->stop_sem) { + osi_sem_free(&thread->stop_sem); + } + + + osi_free(thread); +} + +bool osi_thread_post(osi_thread_t *thread, osi_thread_func_t func, void *context, int queue_idx, uint32_t timeout) +{ + assert(thread != NULL); + assert(func != NULL); + + if (queue_idx >= thread->work_queue_num) { + return false; + } + + work_item_t *item = (work_item_t *)osi_malloc(sizeof(work_item_t)); + if (item == NULL) { + return false; + } + item->func = func; + item->context = context; + + if (fixed_queue_enqueue(thread->work_queues[queue_idx], item, timeout) == false) { + osi_free(item); + return false; + } + + osi_sem_give(&thread->work_sem); + + return true; +} + +bool osi_thread_set_priority(osi_thread_t *thread, int priority) +{ + assert(thread != NULL); + + vTaskPrioritySet(thread->thread_handle, priority); + return true; +} + +const char *osi_thread_name(osi_thread_t *thread) +{ + assert(thread != NULL); + + return pcTaskGetTaskName(thread->thread_handle); +} + +int osi_thread_queue_wait_size(osi_thread_t *thread, int wq_idx) +{ + if (wq_idx < 0 || wq_idx >= thread->work_queue_num) { + return -1; + } + + return fixed_queue_length(thread->work_queues[wq_idx]); +} diff --git a/components/bt/bluedroid/stack/a2dp/a2d_api.c b/components/bt/bluedroid/stack/a2dp/a2d_api.c index 937e46b1e1..8adb200dcd 100644 --- a/components/bt/bluedroid/stack/a2dp/a2d_api.c +++ b/components/bt/bluedroid/stack/a2dp/a2d_api.c @@ -372,13 +372,16 @@ UINT8 A2D_BitsSet(UINT8 num) ** other API functions for this layer. It is typically called ** once during the start up of the stack. ** -** Returns void +** Returns status ** *******************************************************************************/ -void A2D_Init(void) +bt_status_t A2D_Init(void) { #if (A2D_DYNAMIC_MEMORY) a2d_cb_ptr = (tA2D_CB *)osi_malloc(sizeof(tA2D_CB)); + if (!a2d_cb_ptr) { + return BT_STATUS_NOMEM; + } #endif /* #if (A2D_DYNAMIC_MEMORY) */ memset(&a2d_cb, 0, sizeof(tA2D_CB)); @@ -389,6 +392,7 @@ void A2D_Init(void) #else a2d_cb.trace_level = BT_TRACE_LEVEL_NONE; #endif + return BT_STATUS_SUCCESS; } /******************************************************************************* @@ -404,8 +408,10 @@ void A2D_Init(void) void A2D_Deinit(void) { #if (A2D_DYNAMIC_MEMORY) - osi_free(a2d_cb_ptr); - a2d_cb_ptr = NULL; + if (a2d_cb_ptr) { + osi_free(a2d_cb_ptr); + a2d_cb_ptr = NULL; + } #endif /* #if (A2D_DYNAMIC_MEMORY) */ } diff --git a/components/bt/bluedroid/stack/avct/avct_lcb_act.c b/components/bt/bluedroid/stack/avct/avct_lcb_act.c index 02ac96039b..b83219dceb 100644 --- a/components/bt/bluedroid/stack/avct/avct_lcb_act.c +++ b/components/bt/bluedroid/stack/avct/avct_lcb_act.c @@ -449,7 +449,7 @@ void avct_lcb_cong_ind(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) if (p_lcb->cong == FALSE && !fixed_queue_is_empty(p_lcb->tx_q)) { while (!p_lcb->cong && - (p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_lcb->tx_q)) != NULL) + (p_buf = (BT_HDR *)fixed_queue_dequeue(p_lcb->tx_q, 0)) != NULL) { if (L2CA_DataWrite(p_lcb->ch_lcid, p_buf) == L2CAP_DW_CONGESTED) { @@ -569,7 +569,7 @@ void avct_lcb_send_msg(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) } if (p_lcb->cong == TRUE) { - fixed_queue_enqueue(p_lcb->tx_q, p_buf); + fixed_queue_enqueue(p_lcb->tx_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT); } /* send message to L2CAP */ diff --git a/components/bt/bluedroid/stack/avdt/avdt_ccb_act.c b/components/bt/bluedroid/stack/avdt/avdt_ccb_act.c index 9f7b0ee9d0..7d7e7c6e77 100644 --- a/components/bt/bluedroid/stack/avdt/avdt_ccb_act.c +++ b/components/bt/bluedroid/stack/avdt/avdt_ccb_act.c @@ -68,7 +68,7 @@ static void avdt_ccb_clear_ccb(tAVDT_CCB *p_ccb) } /* clear out response queue */ - while ((p_buf = (BT_HDR *) fixed_queue_try_dequeue(p_ccb->rsp_q)) != NULL) { + while ((p_buf = (BT_HDR *) fixed_queue_dequeue(p_ccb->rsp_q, 0)) != NULL) { osi_free(p_buf); } } @@ -659,7 +659,7 @@ void avdt_ccb_clear_cmds(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) avdt_ccb_cmd_fail(p_ccb, (tAVDT_CCB_EVT *) &err_code); /* set up next message */ - p_ccb->p_curr_cmd = (BT_HDR *) fixed_queue_try_dequeue(p_ccb->cmd_q); + p_ccb->p_curr_cmd = (BT_HDR *) fixed_queue_dequeue(p_ccb->cmd_q, 0); } while (p_ccb->p_curr_cmd != NULL); @@ -812,7 +812,7 @@ void avdt_ccb_snd_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) ** not congested, not sending fragment, not waiting for response */ if ((!p_ccb->cong) && (p_ccb->p_curr_msg == NULL) && (p_ccb->p_curr_cmd == NULL)) { - if ((p_msg = (BT_HDR *) fixed_queue_try_dequeue(p_ccb->cmd_q)) != NULL) { + if ((p_msg = (BT_HDR *) fixed_queue_dequeue(p_ccb->cmd_q, 0)) != NULL) { /* make a copy of buffer in p_curr_cmd */ if ((p_ccb->p_curr_cmd = (BT_HDR *) osi_malloc(AVDT_CMD_BUF_SIZE)) != NULL) { memcpy(p_ccb->p_curr_cmd, p_msg, (sizeof(BT_HDR) + p_msg->offset + p_msg->len)); @@ -846,7 +846,7 @@ void avdt_ccb_snd_msg(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) } /* do we have responses to send? send them */ else if (!fixed_queue_is_empty(p_ccb->rsp_q)) { - while ((p_msg = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->rsp_q)) != NULL) { + while ((p_msg = (BT_HDR *)fixed_queue_dequeue(p_ccb->rsp_q, 0)) != NULL) { if (avdt_msg_send(p_ccb, p_msg) == TRUE) { /* break out if congested */ break; diff --git a/components/bt/bluedroid/stack/avdt/avdt_msg.c b/components/bt/bluedroid/stack/avdt/avdt_msg.c index 91e993233d..4ebca9a063 100644 --- a/components/bt/bluedroid/stack/avdt/avdt_msg.c +++ b/components/bt/bluedroid/stack/avdt/avdt_msg.c @@ -1440,7 +1440,7 @@ void avdt_msg_send_cmd(tAVDT_CCB *p_ccb, void *p_scb, UINT8 sig_id, tAVDT_MSG *p p_ccb->label = (p_ccb->label + 1) % 16; /* queue message and trigger ccb to send it */ - fixed_queue_enqueue(p_ccb->cmd_q, p_buf); + fixed_queue_enqueue(p_ccb->cmd_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT); avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL); } @@ -1487,7 +1487,7 @@ void avdt_msg_send_rsp(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params) AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_RSP, p_params->hdr.label); /* queue message and trigger ccb to send it */ - fixed_queue_enqueue(p_ccb->rsp_q, p_buf); + fixed_queue_enqueue(p_ccb->rsp_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT); avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL); } @@ -1547,7 +1547,7 @@ void avdt_msg_send_rej(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params) AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_REJ, p_params->hdr.label); /* queue message and trigger ccb to send it */ - fixed_queue_enqueue(p_ccb->rsp_q, p_buf); + fixed_queue_enqueue(p_ccb->rsp_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT); avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL); } @@ -1591,7 +1591,7 @@ void avdt_msg_send_grej(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params) AVDT_TRACE_DEBUG("avdt_msg_send_grej"); /* queue message and trigger ccb to send it */ - fixed_queue_enqueue(p_ccb->rsp_q, p_buf); + fixed_queue_enqueue(p_ccb->rsp_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT); avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL); } diff --git a/components/bt/bluedroid/stack/avdt/avdt_scb_act.c b/components/bt/bluedroid/stack/avdt/avdt_scb_act.c index b4bbcec066..4cdc5a2e36 100644 --- a/components/bt/bluedroid/stack/avdt/avdt_scb_act.c +++ b/components/bt/bluedroid/stack/avdt/avdt_scb_act.c @@ -1232,7 +1232,7 @@ void avdt_scb_hdl_write_req_frag(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) /* this shouldn't be happening */ AVDT_TRACE_WARNING("*** Dropped media packet; congested"); BT_HDR *p_frag; - while ((p_frag = (BT_HDR*)fixed_queue_try_dequeue(p_scb->frag_q)) != NULL) + while ((p_frag = (BT_HDR*)fixed_queue_dequeue(p_scb->frag_q, 0)) != NULL) osi_free(p_frag); } @@ -1397,7 +1397,7 @@ void avdt_scb_snd_stream_close(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) /* clean fragments queue */ BT_HDR *p_frag; - while ((p_frag = (BT_HDR*)fixed_queue_try_dequeue(p_scb->frag_q)) != NULL) { + while ((p_frag = (BT_HDR*)fixed_queue_dequeue(p_scb->frag_q, 0)) != NULL) { osi_free(p_frag); } p_scb->frag_off = 0; @@ -1824,7 +1824,7 @@ void avdt_scb_free_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) #if AVDT_MULTIPLEXING == TRUE /* clean fragments queue */ BT_HDR *p_frag; - while ((p_frag = (BT_HDR*)fixed_queue_try_dequeue(p_scb->frag_q)) != NULL) { + while ((p_frag = (BT_HDR*)fixed_queue_dequeue(p_scb->frag_q, 0)) != NULL) { osi_free(p_frag); } #endif @@ -1880,7 +1880,7 @@ void avdt_scb_clr_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) AVDT_TRACE_DEBUG("Dropped fragments queue"); /* clean fragments queue */ BT_HDR *p_frag; - while ((p_frag = (BT_HDR*)fixed_queue_try_dequeue(p_scb->frag_q)) != NULL) { + while ((p_frag = (BT_HDR*)fixed_queue_dequeue(p_scb->frag_q, 0)) != NULL) { osi_free(p_frag); } p_scb->frag_off = 0; @@ -1933,7 +1933,7 @@ void avdt_scb_chk_snd_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) L2CA_FlushChannel(avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_scb->p_ccb)][avdt_ad_type_to_tcid(AVDT_CHAN_MEDIA, p_scb)].lcid), L2CAP_FLUSH_CHANS_GET); #endif - while ((p_pkt = (BT_HDR*)fixed_queue_try_dequeue(p_scb->frag_q)) != NULL) { + while ((p_pkt = (BT_HDR*)fixed_queue_dequeue(p_scb->frag_q, 0)) != NULL) { sent = TRUE; AVDT_TRACE_DEBUG("Send fragment len=%d\n", p_pkt->len); /* fragments queue contains fragment to send */ @@ -2096,7 +2096,7 @@ void avdt_scb_queue_frags(tAVDT_SCB *p_scb, UINT8 **pp_data, UINT32 *p_data_len, UINT16_TO_BE_STREAM(p, p_frag->layer_specific ); } /* put fragment into gueue */ - fixed_queue_enqueue(p_scb->frag_q, p_frag); + fixed_queue_enqueue(p_scb->frag_q, p_frag, FIXED_QUEUE_MAX_TIMEOUT); num_frag--; } } diff --git a/components/bt/bluedroid/stack/avrc/avrc_sdp.c b/components/bt/bluedroid/stack/avrc/avrc_sdp.c index d3616f3233..11a994d7ac 100644 --- a/components/bt/bluedroid/stack/avrc/avrc_sdp.c +++ b/components/bt/bluedroid/stack/avrc/avrc_sdp.c @@ -340,13 +340,16 @@ UINT8 AVRC_SetTraceLevel (UINT8 new_level) ** control block (if using dynamic memory), and initializes the ** control block and tracing level. ** -** Returns void +** Returns status ** *******************************************************************************/ -void AVRC_Init(void) +bt_status_t AVRC_Init(void) { #if AVRC_DYNAMIC_MEMORY avrc_cb_ptr = (tAVRC_CB *)osi_malloc(sizeof(tAVRC_CB)); + if (!avrc_cb_ptr) { + return BT_STATUS_NOMEM; + } #endif /* #if AVRC_DYNAMIC_MEMORY */ memset(&avrc_cb, 0, sizeof(tAVRC_CB)); @@ -355,6 +358,7 @@ void AVRC_Init(void) #else avrc_cb.trace_level = BT_TRACE_LEVEL_NONE; #endif + return BT_STATUS_SUCCESS; } /******************************************************************************* @@ -371,8 +375,10 @@ void AVRC_Init(void) void AVRC_Deinit(void) { #if AVRC_DYNAMIC_MEMORY - osi_free(avrc_cb_ptr); - avrc_cb_ptr = NULL; + if (avrc_cb_ptr){ + osi_free(avrc_cb_ptr); + avrc_cb_ptr = NULL; + } #endif /* #if AVRC_DYNAMIC_MEMORY */ } diff --git a/components/bt/bluedroid/stack/btm/btm_acl.c b/components/bt/bluedroid/stack/btm/btm_acl.c index e42724f235..d15fc6c7d6 100644 --- a/components/bt/bluedroid/stack/btm/btm_acl.c +++ b/components/bt/bluedroid/stack/btm/btm_acl.c @@ -2038,6 +2038,8 @@ tBTM_STATUS BTM_ReadTxPower (BD_ADDR remote_bda, tBT_TRANSPORT transport, tBTM_C /* If here, no BD Addr found */ return (BTM_UNKNOWN_ADDR); } + +#if (BLE_INCLUDED == TRUE) tBTM_STATUS BTM_BleReadAdvTxPower(tBTM_CMPL_CB *p_cb) { BOOLEAN ret; @@ -2074,6 +2076,7 @@ void BTM_BleGetWhiteListSize(uint16_t *length) *length = p_cb->white_list_avail_size; return; } +#endif ///BLE_INCLUDED == TRUE /******************************************************************************* ** @@ -2361,7 +2364,7 @@ void btm_acl_resubmit_page (void) BD_ADDR bda; BTM_TRACE_DEBUG ("btm_acl_resubmit_page\n"); /* If there were other page request schedule can start the next one */ - if ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(btm_cb.page_queue)) != NULL) { + if ((p_buf = (BT_HDR *)fixed_queue_dequeue(btm_cb.page_queue, 0)) != NULL) { /* skip 3 (2 bytes opcode and 1 byte len) to get to the bd_addr * for both create_conn and rmt_name */ pp = (UINT8 *)(p_buf + 1) + p_buf->offset + 3; @@ -2392,7 +2395,7 @@ void btm_acl_reset_paging (void) BT_HDR *p; BTM_TRACE_DEBUG ("btm_acl_reset_paging\n"); /* If we sent reset we are definitely not paging any more */ - while ((p = (BT_HDR *)fixed_queue_try_dequeue(btm_cb.page_queue)) != NULL) { + while ((p = (BT_HDR *)fixed_queue_dequeue(btm_cb.page_queue, 0)) != NULL) { osi_free (p); } @@ -2416,7 +2419,7 @@ void btm_acl_paging (BT_HDR *p, BD_ADDR bda) (bda[0] << 16) + (bda[1] << 8) + bda[2], (bda[3] << 16) + (bda[4] << 8) + bda[5]); if (btm_cb.discing) { btm_cb.paging = TRUE; - fixed_queue_enqueue(btm_cb.page_queue, p); + fixed_queue_enqueue(btm_cb.page_queue, p, FIXED_QUEUE_MAX_TIMEOUT); } else { if (!BTM_ACL_IS_CONNECTED (bda)) { BTM_TRACE_DEBUG ("connecting_bda: %06x%06x\n", @@ -2426,7 +2429,7 @@ void btm_acl_paging (BT_HDR *p, BD_ADDR bda) btm_cb.connecting_bda[5]); if (btm_cb.paging && memcmp (bda, btm_cb.connecting_bda, BD_ADDR_LEN) != 0) { - fixed_queue_enqueue(btm_cb.page_queue, p); + fixed_queue_enqueue(btm_cb.page_queue, p, FIXED_QUEUE_MAX_TIMEOUT); } else { p_dev_rec = btm_find_or_alloc_dev (bda); memcpy (btm_cb.connecting_bda, p_dev_rec->bd_addr, BD_ADDR_LEN); diff --git a/components/bt/bluedroid/stack/btm/btm_ble.c b/components/bt/bluedroid/stack/btm/btm_ble.c index 2b62cde415..78accb1a4c 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble.c +++ b/components/bt/bluedroid/stack/btm/btm_ble.c @@ -24,8 +24,6 @@ ******************************************************************************/ #include "common/bt_target.h" -#if BLE_INCLUDED == TRUE - #include #include "stack/bt_types.h" @@ -41,7 +39,7 @@ //#define LOG_TAG "bt_btm_ble" //#include "osi/include/log.h" - +#if BLE_INCLUDED == TRUE #if SMP_INCLUDED == TRUE // The temp variable to pass parameter between functions when in the connected event callback. static BOOLEAN temp_enhanced = FALSE; @@ -667,7 +665,7 @@ void BTM_ReadDevInfo (BD_ADDR remote_bda, tBT_DEVICE_TYPE *p_dev_type, tBLE_ADDR BTM_TRACE_DEBUG ("btm_find_dev_type - device_type = %d addr_type = %d", *p_dev_type , *p_addr_type); } - +#endif ///BLE_INCLUDED == TRUE /******************************************************************************* ** @@ -703,7 +701,7 @@ BOOLEAN BTM_ReadConnectedTransportAddress(BD_ADDR remote_bda, tBT_TRANSPORT tran } return FALSE; } - +#if (BLE_INCLUDED == TRUE) if (transport == BT_TRANSPORT_LE) { memcpy(remote_bda, p_dev_rec->ble.pseudo_addr, BD_ADDR_LEN); if (btm_bda_to_acl(p_dev_rec->ble.pseudo_addr, transport) != NULL) { @@ -712,10 +710,11 @@ BOOLEAN BTM_ReadConnectedTransportAddress(BD_ADDR remote_bda, tBT_TRANSPORT tran return FALSE; } } - +#endif ///BLE_INCLUDED == TRUE return FALSE; } +#if (BLE_INCLUDED == TRUE) /******************************************************************************* ** ** Function BTM_BleReceiverTest @@ -1104,6 +1103,7 @@ void btm_ble_increment_sign_ctr(BD_ADDR bd_addr, BOOLEAN is_local ) } } #endif ///SMP_INCLUDED == TRUE +#endif ///BLE_INCLUDED == TRUE /******************************************************************************* ** @@ -1116,6 +1116,7 @@ void btm_ble_increment_sign_ctr(BD_ADDR bd_addr, BOOLEAN is_local ) ** *******************************************************************************/ #if (SMP_INCLUDED == TRUE) +#if (BLE_INCLUDED == TRUE) BOOLEAN btm_ble_get_enc_key_type(BD_ADDR bd_addr, UINT8 *p_key_types) { tBTM_SEC_DEV_REC *p_dev_rec; @@ -1160,7 +1161,6 @@ BOOLEAN btm_get_local_div (BD_ADDR bd_addr, UINT16 *p_div) return status; } - /******************************************************************************* ** ** Function btm_sec_save_le_key @@ -1420,9 +1420,10 @@ void btm_ble_link_sec_check(BD_ADDR bd_addr, tBTM_LE_AUTH_REQ auth_req, tBTM_BLE } +#endif ///BLE_INCLUDED == TRUE #endif ///SMP_INCLUDED == TRUE - +#if (BLE_INCLUDED == TRUE) /******************************************************************************* ** ** Function btm_ble_set_encryption @@ -2113,10 +2114,9 @@ UINT8 btm_proc_smp_cback(tSMP_EVT event, BD_ADDR bd_addr, tSMP_EVT_DATA *p_data) } #endif - BTM_TRACE_DEBUG ("btm_cb pairing_state=%x pairing_flags=%x pin_code_len=%x", + BTM_TRACE_DEBUG ("btm_cb pairing_state=%x pairing_flags=%x", btm_cb.pairing_state, - btm_cb.pairing_flags, - btm_cb.pin_code_len ); + btm_cb.pairing_flags); BTM_TRACE_DEBUG ("btm_cb.pairing_bda %02x:%02x:%02x:%02x:%02x:%02x", btm_cb.pairing_bda[0], btm_cb.pairing_bda[1], btm_cb.pairing_bda[2], btm_cb.pairing_bda[3], btm_cb.pairing_bda[4], btm_cb.pairing_bda[5]); @@ -2737,7 +2737,7 @@ void btm_ble_set_keep_rfu_in_auth_req(BOOLEAN keep_rfu) ** Function btm_get_current_conn_params ** ** Description This function is called to get current connection parameters -** information of the device +** information of the device ** ** Returns TRUE if the information is geted, else FALSE ** @@ -2758,7 +2758,7 @@ BOOLEAN btm_get_current_conn_params(BD_ADDR bda, UINT16 *interval, UINT16 *laten return TRUE; } BTM_TRACE_WARNING("%s Device is not connected", __func__); - + return FALSE; } diff --git a/components/bt/bluedroid/stack/btm/btm_ble_adv_filter.c b/components/bt/bluedroid/stack/btm/btm_ble_adv_filter.c index 578e2c5dbc..438485359f 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_adv_filter.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_adv_filter.c @@ -48,8 +48,16 @@ #define BTM_BLE_PF_BIT_TO_MASK(x) (UINT16)(1 << (x)) +#if BTM_DYNAMIC_MEMORY == FALSE tBTM_BLE_ADV_FILTER_CB btm_ble_adv_filt_cb; -tBTM_BLE_VSC_CB cmn_ble_vsc_cb; +tBTM_BLE_VSC_CB cmn_ble_adv_vsc_cb; +#else +tBTM_BLE_ADV_FILTER_CB *btm_ble_adv_filt_cb_ptr; +tBTM_BLE_VSC_CB *cmn_ble_adv_vsc_cb_ptr; +#define btm_ble_adv_filt_cb (*btm_ble_adv_filt_cb_ptr) +#define cmn_ble_adv_vsc_cb (*cmn_ble_adv_vsc_cb_ptr) +#endif + static const BD_ADDR na_bda = {0}; static UINT8 btm_ble_cs_update_pf_counter(tBTM_BLE_SCAN_COND_OP action, @@ -87,13 +95,13 @@ tBTM_STATUS btm_ble_obtain_vsc_details() tBTM_STATUS st = BTM_SUCCESS; #if BLE_VND_INCLUDED == TRUE - BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb); - if (0 == cmn_ble_vsc_cb.max_filter) { + BTM_BleGetVendorCapabilities(&cmn_ble_adv_vsc_cb); + if (0 == cmn_ble_adv_vsc_cb.max_filter) { st = BTM_MODE_UNSUPPORTED; return st; } #else - cmn_ble_vsc_cb.max_filter = BTM_BLE_MAX_FILTER_COUNTER; + cmn_ble_adv_vsc_cb.max_filter = BTM_BLE_MAX_FILTER_COUNTER; #endif return st; } @@ -367,7 +375,7 @@ tBTM_BLE_PF_COUNT *btm_ble_find_addr_filter_counter(tBLE_BD_ADDR *p_le_bda) return &btm_ble_adv_filt_cb.p_addr_filter_count[0]; } - for (i = 0; i < cmn_ble_vsc_cb.max_filter; i ++, p_addr_filter ++) { + for (i = 0; i < cmn_ble_adv_vsc_cb.max_filter; i ++, p_addr_filter ++) { if (p_addr_filter->in_use && memcmp(p_le_bda->bda, p_addr_filter->bd_addr, BD_ADDR_LEN) == 0) { return p_addr_filter; @@ -390,7 +398,7 @@ tBTM_BLE_PF_COUNT *btm_ble_alloc_addr_filter_counter(BD_ADDR bd_addr) UINT8 i; tBTM_BLE_PF_COUNT *p_addr_filter = &btm_ble_adv_filt_cb.p_addr_filter_count[1]; - for (i = 0; i < cmn_ble_vsc_cb.max_filter; i ++, p_addr_filter ++) { + for (i = 0; i < cmn_ble_adv_vsc_cb.max_filter; i ++, p_addr_filter ++) { if (memcmp(na_bda, p_addr_filter->bd_addr, BD_ADDR_LEN) == 0) { memcpy(p_addr_filter->bd_addr, bd_addr, BD_ADDR_LEN); p_addr_filter->in_use = TRUE; @@ -418,7 +426,7 @@ BOOLEAN btm_ble_dealloc_addr_filter_counter(tBLE_BD_ADDR *p_bd_addr, UINT8 filte memset(&btm_ble_adv_filt_cb.p_addr_filter_count[0], 0, sizeof(tBTM_BLE_PF_COUNT)); } - for (i = 0; i < cmn_ble_vsc_cb.max_filter; i ++, p_addr_filter ++) { + for (i = 0; i < cmn_ble_adv_vsc_cb.max_filter; i ++, p_addr_filter ++) { if ((p_addr_filter->in_use) && (NULL == p_bd_addr || (NULL != p_bd_addr && memcmp(p_bd_addr->bda, p_addr_filter->bd_addr, BD_ADDR_LEN) == 0))) { @@ -682,7 +690,7 @@ UINT8 btm_ble_cs_update_pf_counter(tBTM_BLE_SCAN_COND_OP action, } BTM_TRACE_DEBUG("counter = %d, maxfilt = %d, num_avbl=%d", - p_counter[cond_type], cmn_ble_vsc_cb.max_filter, num_available); + p_counter[cond_type], cmn_ble_adv_vsc_cb.max_filter, num_available); return p_counter[cond_type]; } } else { @@ -1052,12 +1060,12 @@ tBTM_STATUS BTM_BleAdvFilterParamSetup(int action, tBTM_BLE_PF_FILT_INDEX filt_i /* set onlost timeout */ UINT16_TO_STREAM(p, p_filt_params->lost_timeout); /* set num_of_track_entries for firmware greater than L-release version */ - if (cmn_ble_vsc_cb.version_supported > BTM_VSC_CHIP_CAPABILITY_L_VERSION) { + if (cmn_ble_adv_vsc_cb.version_supported > BTM_VSC_CHIP_CAPABILITY_L_VERSION) { UINT16_TO_STREAM(p, p_filt_params->num_of_tracking_entries); } } - if (cmn_ble_vsc_cb.version_supported == BTM_VSC_CHIP_CAPABILITY_L_VERSION) { + if (cmn_ble_adv_vsc_cb.version_supported == BTM_VSC_CHIP_CAPABILITY_L_VERSION) { len = BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_ADV_FILT_FEAT_SELN_LEN; } else { len = BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_ADV_FILT_FEAT_SELN_LEN + @@ -1248,14 +1256,24 @@ tBTM_STATUS BTM_BleCfgFilterCondition(tBTM_BLE_SCAN_COND_OP action, *******************************************************************************/ void btm_ble_adv_filter_init(void) { - memset(&btm_ble_adv_filt_cb, 0, sizeof(tBTM_BLE_MULTI_ADV_CB)); +#if BTM_DYNAMIC_MEMORY == TRUE + btm_ble_adv_filt_cb_ptr = (tBTM_BLE_ADV_FILTER_CB *)osi_malloc(sizeof(tBTM_BLE_ADV_FILTER_CB)); + cmn_ble_adv_vsc_cb_ptr = (tBTM_BLE_VSC_CB *)osi_malloc(sizeof(tBTM_BLE_VSC_CB)); + if (btm_ble_adv_filt_cb_ptr == NULL || cmn_ble_adv_vsc_cb_ptr == NULL) { + BTM_TRACE_ERROR("%s malloc failed", __func__); + return; + } + memset((void *)btm_ble_adv_filt_cb_ptr, 0, sizeof(tBTM_BLE_ADV_FILTER_CB)); + memset((void *)cmn_ble_adv_vsc_cb_ptr, 0, sizeof(tBTM_BLE_VSC_CB)); +#endif + memset(&btm_ble_adv_filt_cb, 0, sizeof(tBTM_BLE_ADV_FILTER_CB)); if (BTM_SUCCESS != btm_ble_obtain_vsc_details()) { return; } - if (cmn_ble_vsc_cb.max_filter > 0) { + if (cmn_ble_adv_vsc_cb.max_filter > 0) { btm_ble_adv_filt_cb.p_addr_filter_count = - (tBTM_BLE_PF_COUNT *) osi_malloc( sizeof(tBTM_BLE_PF_COUNT) * cmn_ble_vsc_cb.max_filter); + (tBTM_BLE_PF_COUNT *) osi_malloc( sizeof(tBTM_BLE_PF_COUNT) * cmn_ble_adv_vsc_cb.max_filter); } } @@ -1276,6 +1294,13 @@ void btm_ble_adv_filter_cleanup(void) osi_free(btm_ble_adv_filt_cb.p_addr_filter_count); btm_ble_adv_filt_cb.p_addr_filter_count = NULL; } + +#if BTM_DYNAMIC_MEMORY == TRUE + osi_free(btm_ble_adv_filt_cb_ptr); + btm_ble_adv_filt_cb_ptr = NULL; + osi_free(cmn_ble_adv_vsc_cb_ptr); + cmn_ble_adv_vsc_cb_ptr = NULL; +#endif } #endif diff --git a/components/bt/bluedroid/stack/btm/btm_ble_batchscan.c b/components/bt/bluedroid/stack/btm/btm_ble_batchscan.c index d9af18d5e1..5b0fcd8ff0 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_batchscan.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_batchscan.c @@ -30,9 +30,15 @@ #if (BLE_INCLUDED == TRUE) -tBTM_BLE_BATCH_SCAN_CB ble_batchscan_cb; -tBTM_BLE_ADV_TRACK_CB ble_advtrack_cb; - +#if BTM_DYNAMIC_MEMORY == FALSE +tBTM_BLE_BATCH_SCAN_CB ble_batchscan_cb; +tBTM_BLE_ADV_TRACK_CB ble_advtrack_cb; +#else +tBTM_BLE_BATCH_SCAN_CB *ble_batchscan_cb_ptr; +tBTM_BLE_ADV_TRACK_CB *ble_advtrack_cb_ptr; +#define ble_batchscan_cb (*ble_batchscan_cb_ptr) +#define ble_advtrack_cb (*ble_advtrack_cb_ptr) +#endif /* length of each batch scan command */ #define BTM_BLE_BATCH_SCAN_STORAGE_CFG_LEN 4 @@ -896,6 +902,14 @@ tBTM_STATUS BTM_BleTrackAdvertiser(tBTM_BLE_TRACK_ADV_CBACK *p_track_cback, *******************************************************************************/ void btm_ble_batchscan_init(void) { +#if BTM_DYNAMIC_MEMORY == TRUE + ble_batchscan_cb_ptr = (tBTM_BLE_BATCH_SCAN_CB *)osi_malloc(sizeof(tBTM_BLE_BATCH_SCAN_CB)); + ble_advtrack_cb_ptr = (tBTM_BLE_ADV_TRACK_CB *)osi_malloc(sizeof(tBTM_BLE_ADV_TRACK_CB)); + if (ble_batchscan_cb_ptr == NULL || ble_advtrack_cb_ptr == NULL) { + BTM_TRACE_ERROR("%s malloc failed", __func__); + return; + } +#endif BTM_TRACE_EVENT (" btm_ble_batchscan_init"); memset(&ble_batchscan_cb, 0, sizeof(tBTM_BLE_BATCH_SCAN_CB)); memset(&ble_advtrack_cb, 0, sizeof(tBTM_BLE_ADV_TRACK_CB)); @@ -927,6 +941,13 @@ void btm_ble_batchscan_cleanup(void) memset(&ble_batchscan_cb, 0, sizeof(tBTM_BLE_BATCH_SCAN_CB)); memset(&ble_advtrack_cb, 0, sizeof(tBTM_BLE_ADV_TRACK_CB)); + +#if BTM_DYNAMIC_MEMORY == TRUE + osi_free(ble_batchscan_cb_ptr); + osi_free(ble_advtrack_cb_ptr); + ble_batchscan_cb_ptr = NULL; + ble_advtrack_cb_ptr = NULL; +#endif } #endif diff --git a/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c b/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c index 0766715480..3721471f80 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c @@ -785,7 +785,7 @@ void btm_ble_enqueue_direct_conn_req(void *p_param) p->p_param = p_param; - fixed_queue_enqueue(btm_cb.ble_ctr_cb.conn_pending_q, p); + fixed_queue_enqueue(btm_cb.ble_ctr_cb.conn_pending_q, p, FIXED_QUEUE_MAX_TIMEOUT); } /******************************************************************************* ** @@ -801,7 +801,7 @@ BOOLEAN btm_send_pending_direct_conn(void) tBTM_BLE_CONN_REQ *p_req; BOOLEAN rt = FALSE; - p_req = (tBTM_BLE_CONN_REQ*)fixed_queue_try_dequeue(btm_cb.ble_ctr_cb.conn_pending_q); + p_req = (tBTM_BLE_CONN_REQ*)fixed_queue_dequeue(btm_cb.ble_ctr_cb.conn_pending_q, 0); if (p_req != NULL) { rt = l2cble_init_direct_conn((tL2C_LCB *)(p_req->p_param)); diff --git a/components/bt/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/bluedroid/stack/btm/btm_ble_gap.c index cbf349ded1..5a7f60da94 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_gap.c @@ -57,7 +57,12 @@ #define MIN_ADV_LENGTH 2 #define BTM_VSC_CHIP_CAPABILITY_RSP_LEN_L_RELEASE 9 -static tBTM_BLE_VSC_CB cmn_ble_vsc_cb; +#if BTM_DYNAMIC_MEMORY == FALSE +static tBTM_BLE_VSC_CB cmn_ble_gap_vsc_cb; +#else +static tBTM_BLE_VSC_CB *cmn_ble_gap_vsc_cb_ptr; +#define cmn_ble_gap_vsc_cb (*cmn_ble_gap_vsc_cb_ptr) +#endif #if BLE_VND_INCLUDED == TRUE static tBTM_BLE_CTRL_FEATURES_CBACK *p_ctrl_le_feature_rd_cmpl_cback = NULL; @@ -241,7 +246,7 @@ uint8_t adv_param_status = 0; uint8_t scan_enable_status = 0; uint8_t scan_param_status = 0; -void btm_lock_init(void) +void btm_ble_lock_init(void) { osi_mutex_new(&adv_enable_lock); osi_mutex_new(&adv_data_lock); @@ -250,7 +255,7 @@ void btm_lock_init(void) osi_mutex_new(&scan_param_lock); } -void btm_lock_free(void) +void btm_ble_lock_free(void) { osi_mutex_free(&adv_enable_lock); osi_mutex_free(&adv_data_lock); @@ -259,7 +264,7 @@ void btm_lock_free(void) osi_mutex_free(&scan_param_lock); } -void btm_sem_init(void) +void btm_ble_sem_init(void) { osi_sem_new(&adv_enable_sem, 1, 0); osi_sem_new(&adv_data_sem, 1, 0); @@ -268,7 +273,7 @@ void btm_sem_init(void) osi_sem_new(&scan_param_sem, 1, 0); } -void btm_sem_free(void) +void btm_ble_sem_free(void) { osi_sem_free(&adv_enable_sem); osi_sem_free(&adv_data_sem); @@ -447,7 +452,7 @@ tBTM_STATUS BTM_BleObserve(BOOLEAN start, UINT32 duration, btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN); #endif - if (cmn_ble_vsc_cb.extended_scan_support == 0) { + if (cmn_ble_gap_vsc_cb.extended_scan_support == 0) { btsnd_hcic_ble_set_scan_params(p_inq->scan_type, (UINT16)scan_interval, (UINT16)scan_window, btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, @@ -4292,10 +4297,18 @@ BOOLEAN btm_ble_update_mode_operation(UINT8 link_role, BD_ADDR bd_addr, UINT8 st *******************************************************************************/ void btm_ble_init (void) { - tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; - BTM_TRACE_DEBUG("%s", __func__); +#if BTM_DYNAMIC_MEMORY == TRUE + cmn_ble_gap_vsc_cb_ptr = (tBTM_BLE_VSC_CB *)osi_malloc(sizeof(tBTM_BLE_VSC_CB)); + if (cmn_ble_gap_vsc_cb_ptr == NULL) { + BTM_TRACE_ERROR("%s malloc failed", __func__); + return; + } +#endif + + tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; + btu_free_timer(&p_cb->obs_timer_ent); btu_free_timer(&p_cb->scan_timer_ent); btu_free_timer(&p_cb->inq_var.fast_adv_timer); @@ -4340,6 +4353,11 @@ void btm_ble_free (void) BTM_TRACE_DEBUG("%s", __func__); fixed_queue_free(p_cb->conn_pending_q, osi_free_func); + +#if BTM_DYNAMIC_MEMORY == TRUE + osi_free(cmn_ble_gap_vsc_cb_ptr); + cmn_ble_gap_vsc_cb_ptr = NULL; +#endif } /******************************************************************************* diff --git a/components/bt/bluedroid/stack/btm/btm_ble_multi_adv.c b/components/bt/bluedroid/stack/btm/btm_ble_multi_adv.c index 5457324130..a3ad604437 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_multi_adv.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_multi_adv.c @@ -45,8 +45,15 @@ /************************************************************************************ ** Static variables ************************************************************************************/ -tBTM_BLE_MULTI_ADV_CB btm_multi_adv_cb; -tBTM_BLE_MULTI_ADV_INST_IDX_Q btm_multi_adv_idx_q; +#if BTM_DYNAMIC_MEMORY == FALSE +tBTM_BLE_MULTI_ADV_CB btm_multi_adv_cb; +tBTM_BLE_MULTI_ADV_INST_IDX_Q btm_multi_adv_idx_q; +#else +tBTM_BLE_MULTI_ADV_CB *btm_multi_adv_cb_ptr; +tBTM_BLE_MULTI_ADV_INST_IDX_Q *btm_multi_adv_idx_q_ptr; +#define btm_multi_adv_cb (*btm_multi_adv_cb_ptr) +#define btm_multi_adv_idx_q (*btm_multi_adv_idx_q_ptr) +#endif /************************************************************************************ ** Externs @@ -764,6 +771,15 @@ void btm_ble_multi_adv_vse_cback(UINT8 len, UINT8 *p) *******************************************************************************/ void btm_ble_multi_adv_init() { +#if BTM_DYNAMIC_MEMORY == TRUE + btm_multi_adv_cb_ptr = (tBTM_BLE_MULTI_ADV_CB *)osi_malloc(sizeof(tBTM_BLE_MULTI_ADV_CB)); + btm_multi_adv_idx_q_ptr = (tBTM_BLE_MULTI_ADV_INST_IDX_Q *)osi_malloc(sizeof(tBTM_BLE_MULTI_ADV_INST_IDX_Q)); + if (btm_multi_adv_cb_ptr == NULL || btm_multi_adv_idx_q_ptr == NULL) { + BTM_TRACE_ERROR("%s malloc failed", __func__); + return; + } +#endif + UINT8 i = 0; memset(&btm_multi_adv_cb, 0, sizeof(tBTM_BLE_MULTI_ADV_CB)); memset (&btm_multi_adv_idx_q, 0, sizeof (tBTM_BLE_MULTI_ADV_INST_IDX_Q)); @@ -823,6 +839,12 @@ void btm_ble_multi_adv_cleanup(void) btm_multi_adv_cb.op_q.p_inst_id = NULL; } +#if BTM_DYNAMIC_MEMORY == TRUE + osi_free(btm_multi_adv_cb_ptr); + osi_free(btm_multi_adv_idx_q_ptr); + btm_multi_adv_cb_ptr = NULL; + btm_multi_adv_idx_q_ptr = NULL; +#endif } /******************************************************************************* diff --git a/components/bt/bluedroid/stack/btm/btm_ble_privacy.c b/components/bt/bluedroid/stack/btm/btm_ble_privacy.c index 71f06eb82f..0ec69d953e 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_privacy.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_privacy.c @@ -882,6 +882,7 @@ void btm_ble_enable_resolving_list(UINT8 rl_mask) } } +#if 0 //Unused /******************************************************************************* ** ** Function btm_ble_resolving_list_empty @@ -896,6 +897,7 @@ BOOLEAN btm_ble_resolving_list_empty(void) return (controller_get_interface()->get_ble_resolving_list_max_size() == btm_cb.ble_ctr_cb.resolving_list_avail_size); } +#endif /******************************************************************************* ** diff --git a/components/bt/bluedroid/stack/btm/btm_devctl.c b/components/bt/bluedroid/stack/btm/btm_devctl.c index dfd2c3bf60..437a3cd1a3 100644 --- a/components/bt/bluedroid/stack/btm/btm_devctl.c +++ b/components/bt/bluedroid/stack/btm/btm_devctl.c @@ -190,9 +190,9 @@ static void reset_complete(void) l2c_link_processs_ble_num_bufs(controller->get_acl_buffer_count_ble()); } #endif -#if (SMP_INCLUDED == TRUE) +#if (SMP_INCLUDED == TRUE && CLASSIC_BT_INCLUDED == TRUE) BTM_SetPinType (btm_cb.cfg.pin_type, btm_cb.cfg.pin_code, btm_cb.cfg.pin_code_len); -#endif ///SMP_INCLUDED == TRUE +#endif ///SMP_INCLUDED == TRUE && CLASSIC_BT_INCLUDED == TRUE for (int i = 0; i <= controller->get_last_features_classic_index(); i++) { btm_decode_ext_features_page(i, controller->get_features_classic(i)->as_array); } @@ -693,6 +693,7 @@ tBTM_STATUS BTM_VendorSpecificCommand(UINT16 opcode, UINT8 param_len, void btm_vsc_complete (UINT8 *p, UINT16 opcode, UINT16 evt_len, tBTM_CMPL_CB *p_vsc_cplt_cback) { +#if (BLE_INCLUDED == TRUE) tBTM_BLE_CB *ble_cb = &btm_cb.ble_ctr_cb; switch(opcode) { case HCI_VENDOR_BLE_LONG_ADV_DATA: @@ -721,6 +722,7 @@ void btm_vsc_complete (UINT8 *p, UINT16 opcode, UINT16 evt_len, vcs_cplt_params.p_param_buf = p; (*p_vsc_cplt_cback)(&vcs_cplt_params); /* Call the VSC complete callback function */ } +#endif } /******************************************************************************* diff --git a/components/bt/bluedroid/stack/btm/btm_main.c b/components/bt/bluedroid/stack/btm/btm_main.c index b6b853d5c6..cf950f21a9 100644 --- a/components/bt/bluedroid/stack/btm/btm_main.c +++ b/components/bt/bluedroid/stack/btm/btm_main.c @@ -75,8 +75,10 @@ void btm_init (void) #endif btm_dev_init(); /* Device Manager Structures & HCI_Reset */ - btm_lock_init(); - btm_sem_init(); +#if BLE_INCLUDED == TRUE + btm_ble_lock_init(); + btm_ble_sem_init(); +#endif } @@ -96,6 +98,8 @@ void btm_free(void) #if BTM_DYNAMIC_MEMORY FREE_AND_RESET(btm_cb_ptr); #endif - btm_lock_free(); - btm_sem_free(); +#if BLE_INCLUDED == TRUE + btm_ble_lock_free(); + btm_ble_sem_free(); +#endif } diff --git a/components/bt/bluedroid/stack/btm/btm_sco.c b/components/bt/bluedroid/stack/btm/btm_sco.c index 661caba638..25d8c4183c 100644 --- a/components/bt/bluedroid/stack/btm/btm_sco.c +++ b/components/bt/bluedroid/stack/btm/btm_sco.c @@ -86,7 +86,7 @@ void btm_sco_flush_sco_data(UINT16 sco_inx) if (sco_inx < BTM_MAX_SCO_LINKS) { p = &btm_cb.sco_cb.sco_db[sco_inx]; - while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p->xmit_data_q)) != NULL) { + while ((p_buf = (BT_HDR *)fixed_queue_dequeue(p->xmit_data_q, 0)) != NULL) { osi_free(p_buf); } } @@ -292,7 +292,7 @@ void btm_sco_check_send_pkts (UINT16 sco_inx) BT_HDR *p_buf; while (p_cb->xmit_window_size != 0) { - if ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->xmit_data_q)) == NULL) { + if ((p_buf = (BT_HDR *)fixed_queue_dequeue(p_ccb->xmit_data_q, 0)) == NULL) { break; } #if BTM_SCO_HCI_DEBUG @@ -441,7 +441,7 @@ tBTM_STATUS BTM_WriteScoData (UINT16 sco_inx, BT_HDR *p_buf) p_buf->len += HCI_SCO_PREAMBLE_SIZE; if (fixed_queue_length(p_ccb->xmit_data_q) < BTM_SCO_XMIT_QUEUE_THRS) { - fixed_queue_enqueue(p_ccb->xmit_data_q, p_buf); + fixed_queue_enqueue(p_ccb->xmit_data_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT); btm_sco_check_send_pkts (sco_inx); } else { BTM_TRACE_WARNING ("SCO xmit Q overflow, pkt dropped"); diff --git a/components/bt/bluedroid/stack/btm/btm_sec.c b/components/bt/bluedroid/stack/btm/btm_sec.c index 1ad3cfce3b..fc711d9180 100644 --- a/components/bt/bluedroid/stack/btm/btm_sec.c +++ b/components/bt/bluedroid/stack/btm/btm_sec.c @@ -35,6 +35,7 @@ #include "l2c_int.h" #include "osi/fixed_queue.h" #include "osi/alarm.h" +#include "stack/btm_ble_api.h" #if (BT_USE_TRACES == TRUE && BT_TRACE_VERBOSE == FALSE) /* needed for sprintf() */ @@ -368,6 +369,7 @@ BOOLEAN BTM_GetSecurityFlagsByTransport (BD_ADDR bd_addr, UINT8 *p_sec_flags, return (FALSE); } +#if (CLASSIC_BT_INCLUDED == TRUE) /******************************************************************************* ** ** Function BTM_SetPinType @@ -392,6 +394,7 @@ void BTM_SetPinType (UINT8 pin_type, PIN_CODE pin_code, UINT8 pin_code_len) btm_cb.cfg.pin_code_len = pin_code_len; memcpy (btm_cb.cfg.pin_code, pin_code, pin_code_len); } +#endif ///CLASSIC_BT_INCLUDED == TRUE /******************************************************************************* ** @@ -824,6 +827,7 @@ void btm_sec_clr_temp_auth_service (BD_ADDR bda) ** *******************************************************************************/ #if (SMP_INCLUDED == TRUE) +#if (CLASSIC_BT_INCLUDED == TRUE) void BTM_PINCodeReply (BD_ADDR bd_addr, UINT8 res, UINT8 pin_len, UINT8 *p_pin, UINT32 trusted_mask[]) { tBTM_SEC_DEV_REC *p_dev_rec; @@ -930,6 +934,7 @@ void BTM_PINCodeReply (BD_ADDR bd_addr, UINT8 res, UINT8 pin_len, UINT8 *p_pin, #endif btsnd_hcic_pin_code_req_reply (bd_addr, pin_len, p_pin); } +#endif ///CLASSIC_BT_INCLUDED == TRUE #endif ///SMP_INCLUDED == TRUE @@ -995,12 +1000,14 @@ tBTM_STATUS btm_sec_bond_by_transport (BD_ADDR bd_addr, tBT_TRANSPORT transport, return (BTM_NO_RESOURCES); } +#if (CLASSIC_BT_INCLUDED == TRUE) /* Save the PIN code if we got a valid one */ if (p_pin && (pin_len <= PIN_CODE_LEN) && (pin_len != 0)) { btm_cb.pin_code_len = pin_len; p_dev_rec->pin_code_length = pin_len; memcpy (btm_cb.pin_code, p_pin, PIN_CODE_LEN); } +#endif ///CLASSIC_BT_INCLUDED == TRUE memcpy (btm_cb.pairing_bda, bd_addr, BD_ADDR_LEN); @@ -1034,6 +1041,8 @@ tBTM_STATUS btm_sec_bond_by_transport (BD_ADDR bd_addr, tBT_TRANSPORT transport, BTM_TRACE_DEBUG ("after update sec_flags=0x%x\n", p_dev_rec->sec_flags); + +#if (CLASSIC_BT_INCLUDED == TRUE) if (!controller_get_interface()->supports_simple_pairing()) { /* The special case when we authenticate keyboard. Set pin type to fixed */ /* It would be probably better to do it from the application, but it is */ @@ -1045,6 +1054,7 @@ tBTM_STATUS btm_sec_bond_by_transport (BD_ADDR bd_addr, tBT_TRANSPORT transport, btsnd_hcic_write_pin_type (HCI_PIN_TYPE_FIXED); } } +#endif ///CLASSIC_BT_INCLUDED == TRUE for (ii = 0; ii <= HCI_EXT_FEATURES_PAGE_MAX; ii++) { #if (!CONFIG_BT_STACK_NO_LOG) @@ -1133,6 +1143,7 @@ tBTM_STATUS btm_sec_bond_by_transport (BD_ADDR bd_addr, tBT_TRANSPORT transport, tBTM_STATUS BTM_SecBondByTransport (BD_ADDR bd_addr, tBT_TRANSPORT transport, UINT8 pin_len, UINT8 *p_pin, UINT32 trusted_mask[]) { +#if (BLE_INCLUDED == TRUE) tBT_DEVICE_TYPE dev_type; tBLE_ADDR_TYPE addr_type; @@ -1142,6 +1153,8 @@ tBTM_STATUS BTM_SecBondByTransport (BD_ADDR bd_addr, tBT_TRANSPORT transport, (transport == BT_TRANSPORT_BR_EDR && (dev_type & BT_DEVICE_TYPE_BREDR) == 0)) { return BTM_ILLEGAL_ACTION; } +#endif ///BLE_INCLUDED == TRUE + return btm_sec_bond_by_transport(bd_addr, transport, pin_len, p_pin, trusted_mask); } #endif ///SMP_INCLUDED == TRUE @@ -1165,9 +1178,11 @@ tBTM_STATUS BTM_SecBondByTransport (BD_ADDR bd_addr, tBT_TRANSPORT transport, tBTM_STATUS BTM_SecBond (BD_ADDR bd_addr, UINT8 pin_len, UINT8 *p_pin, UINT32 trusted_mask[]) { tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; +#if (BLE_INCLUDED == TRUE) if (BTM_UseLeLink(bd_addr)) { transport = BT_TRANSPORT_LE; } +#endif ///BLE_INCLUDED == TRUE return btm_sec_bond_by_transport(bd_addr, transport, pin_len, p_pin, trusted_mask); } /******************************************************************************* @@ -1789,53 +1804,6 @@ UINT16 BTM_BuildOobData(UINT8 *p_data, UINT16 max_len, BT_OCTET16 c, return len; } -/******************************************************************************* -** -** Function BTM_BothEndsSupportSecureConnections -** -** Description This function is called to check if both the local device and the peer device -** specified by bd_addr support BR/EDR Secure Connections. -** -** Parameters: bd_addr - address of the peer -** -** Returns TRUE if BR/EDR Secure Connections are supported by both local -** and the remote device. -** else FALSE. -** -*******************************************************************************/ -BOOLEAN BTM_BothEndsSupportSecureConnections(BD_ADDR bd_addr) -{ - return ((controller_get_interface()->supports_secure_connections()) && - (BTM_PeerSupportsSecureConnections(bd_addr))); -} - -/******************************************************************************* -** -** Function BTM_PeerSupportsSecureConnections -** -** Description This function is called to check if the peer supports -** BR/EDR Secure Connections. -** -** Parameters: bd_addr - address of the peer -** -** Returns TRUE if BR/EDR Secure Connections are supported by the peer, -** else FALSE. -** -*******************************************************************************/ -BOOLEAN BTM_PeerSupportsSecureConnections(BD_ADDR bd_addr) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - - if ((p_dev_rec = btm_find_dev(bd_addr)) == NULL) { - BTM_TRACE_WARNING("%s: unknown BDA: %08x%04x\n", __FUNCTION__, - (bd_addr[0] << 24) + (bd_addr[1] << 16) + (bd_addr[2] << 8) + bd_addr[3], - (bd_addr[4] << 8) + bd_addr[5]); - return FALSE; - } - - return (p_dev_rec->remote_supports_secure_connections); -} - /******************************************************************************* ** ** Function BTM_ReadOobData @@ -1899,6 +1867,54 @@ UINT8 *BTM_ReadOobData(UINT8 *p_data, UINT8 eir_tag, UINT8 *p_len) } #endif ///BTM_OOB_INCLUDED == TRUE && SMP_INCLUDED == TRUE +#if (CLASSIC_BT_INCLUDED == TRUE) +/******************************************************************************* +** +** Function BTM_BothEndsSupportSecureConnections +** +** Description This function is called to check if both the local device and the peer device +** specified by bd_addr support BR/EDR Secure Connections. +** +** Parameters: bd_addr - address of the peer +** +** Returns TRUE if BR/EDR Secure Connections are supported by both local +** and the remote device. +** else FALSE. +** +*******************************************************************************/ +BOOLEAN BTM_BothEndsSupportSecureConnections(BD_ADDR bd_addr) +{ + return ((controller_get_interface()->supports_secure_connections()) && + (BTM_PeerSupportsSecureConnections(bd_addr))); +} + +/******************************************************************************* +** +** Function BTM_PeerSupportsSecureConnections +** +** Description This function is called to check if the peer supports +** BR/EDR Secure Connections. +** +** Parameters: bd_addr - address of the peer +** +** Returns TRUE if BR/EDR Secure Connections are supported by the peer, +** else FALSE. +** +*******************************************************************************/ +BOOLEAN BTM_PeerSupportsSecureConnections(BD_ADDR bd_addr) +{ + tBTM_SEC_DEV_REC *p_dev_rec; + + if ((p_dev_rec = btm_find_dev(bd_addr)) == NULL) { + BTM_TRACE_WARNING("%s: unknown BDA: %08x%04x\n", __FUNCTION__, + (bd_addr[0] << 24) + (bd_addr[1] << 16) + (bd_addr[2] << 8) + bd_addr[3], + (bd_addr[4] << 8) + bd_addr[5]); + return FALSE; + } + + return (p_dev_rec->remote_supports_secure_connections); +} + /******************************************************************************* ** ** Function BTM_SetOutService @@ -1913,7 +1929,6 @@ UINT8 *BTM_ReadOobData(UINT8 *p_data, UINT8 eir_tag, UINT8 *p_len) ** Returns void ** *******************************************************************************/ -#if (CLASSIC_BT_INCLUDED == TRUE) void BTM_SetOutService(BD_ADDR bd_addr, UINT8 service_id, UINT32 mx_chan_id) { tBTM_SEC_DEV_REC *p_dev_rec; @@ -2776,7 +2791,7 @@ void btm_sec_check_pending_reqs (void) btm_cb.sec_pending_q = fixed_queue_new(QUEUE_SIZE_MAX); - while ((p_e = (tBTM_SEC_QUEUE_ENTRY *)fixed_queue_try_dequeue(bq)) != NULL) { + while ((p_e = (tBTM_SEC_QUEUE_ENTRY *)fixed_queue_dequeue(bq, 0)) != NULL) { /* Check that the ACL is still up before starting security procedures */ if (btm_bda_to_acl(p_e->bd_addr, p_e->transport) != NULL) { if (p_e->psm != 0) { @@ -4117,8 +4132,10 @@ void btm_sec_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable) if (p_dev_rec->no_smp_on_br) { BTM_TRACE_DEBUG ("%s NO SM over BR/EDR\n", __func__); } else { +#if (CLASSIC_BT_INCLUDED == TRUE) BTM_TRACE_DEBUG ("%s start SM over BR/EDR\n", __func__); SMP_BR_PairWith(p_dev_rec->bd_addr); +#endif ///CLASSIC_BT_INCLUDED == TRUE } } } else { @@ -4924,6 +4941,7 @@ static void btm_sec_pairing_timeout (TIMER_LIST_ENT *p_tle) } } +#if (CLASSIC_BT_INCLUDED == TRUE) /******************************************************************************* ** ** Function btm_sec_pin_code_request @@ -5061,6 +5079,7 @@ void btm_sec_pin_code_request (UINT8 *p_bda) } return; } +#endif ///CLASSIC_BT_INCLUDED == TRUE #endif ///SMP_INCLUDED == TRUE @@ -5589,10 +5608,12 @@ static void btm_restore_mode(void) btsnd_hcic_write_auth_enable ((UINT8)(btm_cb.security_mode == BTM_SEC_MODE_LINK)); } +#if (CLASSIC_BT_INCLUDED == TRUE) if (btm_cb.pin_type_changed) { btm_cb.pin_type_changed = FALSE; btsnd_hcic_write_pin_type (btm_cb.cfg.pin_type); } +#endif ///CLASSIC_BT_INCLUDED == TRUE } #endif ///SMP_INCLUDED == TRUE @@ -5644,7 +5665,9 @@ static void btm_sec_change_pairing_state (tBTM_PAIRING_STATE new_state) btu_stop_timer (&btm_cb.pairing_tle); btm_cb.pairing_flags = 0; +#if (CLASSIC_BT_INCLUDED == TRUE) btm_cb.pin_code_len = 0; +#endif ///CLASSIC_BT_INCLUDED == TRUE /* Make sure the the lcb shows we are not bonding */ l2cu_update_lcb_4_bonding (btm_cb.pairing_bda, FALSE); @@ -5761,7 +5784,7 @@ static BOOLEAN btm_sec_queue_mx_request (BD_ADDR bd_addr, UINT16 psm, BOOLEAN BTM_TRACE_EVENT ("%s() PSM: 0x%04x Is_Orig: %u mx_proto_id: %u mx_chan_id: %u\n", __func__, psm, is_orig, mx_proto_id, mx_chan_id); - fixed_queue_enqueue(btm_cb.sec_pending_q, p_e); + fixed_queue_enqueue(btm_cb.sec_pending_q, p_e, FIXED_QUEUE_MAX_TIMEOUT); return (TRUE); } @@ -5770,9 +5793,11 @@ static BOOLEAN btm_sec_queue_mx_request (BD_ADDR bd_addr, UINT16 psm, BOOLEAN } static BOOLEAN btm_sec_check_prefetch_pin (tBTM_SEC_DEV_REC *p_dev_rec) { + BOOLEAN rv = FALSE; +#if (CLASSIC_BT_INCLUDED == TRUE) UINT8 major = (UINT8)(p_dev_rec->dev_class[1] & BTM_COD_MAJOR_CLASS_MASK); UINT8 minor = (UINT8)(p_dev_rec->dev_class[2] & BTM_COD_MINOR_CLASS_MASK); - BOOLEAN rv = FALSE; + rv = TRUE; if ((major == BTM_COD_MAJOR_AUDIO) && ((minor == BTM_COD_MINOR_CONFM_HANDSFREE) || (minor == BTM_COD_MINOR_CAR_AUDIO)) ) { @@ -5810,7 +5835,8 @@ static BOOLEAN btm_sec_check_prefetch_pin (tBTM_SEC_DEV_REC *p_dev_rec) rv = TRUE; } - +#endif ///CLASSIC_BT_INCLUDED == TRUE +# return rv; } @@ -5857,7 +5883,7 @@ static BOOLEAN btm_sec_queue_encrypt_request (BD_ADDR bd_addr, tBT_TRANSPORT tra *(UINT8 *)p_e->p_ref_data = *(UINT8 *)(p_ref_data); p_e->transport = transport; memcpy(p_e->bd_addr, bd_addr, BD_ADDR_LEN); - fixed_queue_enqueue(btm_cb.sec_pending_q, p_e); + fixed_queue_enqueue(btm_cb.sec_pending_q, p_e, FIXED_QUEUE_MAX_TIMEOUT); return TRUE; } @@ -5993,6 +6019,7 @@ static UINT16 btm_sec_set_serv_level4_flags(UINT16 cur_security, BOOLEAN is_orig return cur_security | sec_level4_flags; } #endif ///SMP_INCLUDED == TRUE + /******************************************************************************* ** ** Function btm_sec_clear_ble_keys @@ -6004,6 +6031,7 @@ static UINT16 btm_sec_set_serv_level4_flags(UINT16 cur_security, BOOLEAN is_orig ** Returns void ** *******************************************************************************/ +#if (BLE_INCLUDED == TRUE) void btm_sec_clear_ble_keys (tBTM_SEC_DEV_REC *p_dev_rec) { @@ -6017,7 +6045,7 @@ void btm_sec_clear_ble_keys (tBTM_SEC_DEV_REC *p_dev_rec) #endif #endif } - +#endif ///BLE_INCLUDED == TRUE /******************************************************************************* ** ** Function btm_sec_is_a_bonded_dev @@ -6034,7 +6062,7 @@ BOOLEAN btm_sec_is_a_bonded_dev (BD_ADDR bda) BOOLEAN is_bonded = FALSE; if (p_dev_rec && -#if (SMP_INCLUDED == TRUE) +#if (SMP_INCLUDED == TRUE && BLE_INCLUDED == TRUE) ((p_dev_rec->ble.key_type && (p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_KNOWN)) || #else ( @@ -6057,10 +6085,10 @@ BOOLEAN btm_sec_is_a_bonded_dev (BD_ADDR bda) *******************************************************************************/ BOOLEAN btm_sec_is_le_capable_dev (BD_ADDR bda) { - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bda); BOOLEAN le_capable = FALSE; #if (BLE_INCLUDED== TRUE) + tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bda); if (p_dev_rec && (p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) == BT_DEVICE_TYPE_BLE) { le_capable = TRUE; } @@ -6077,6 +6105,7 @@ BOOLEAN btm_sec_is_le_capable_dev (BD_ADDR bda) ** Returns TRUE - found a bonded device ** *******************************************************************************/ +#if (BLE_INCLUDED == TRUE) BOOLEAN btm_sec_find_bonded_dev (UINT8 start_idx, UINT8 *p_found_idx, tBTM_SEC_DEV_REC **p_rec) { BOOLEAN found = FALSE; @@ -6101,7 +6130,7 @@ BOOLEAN btm_sec_find_bonded_dev (UINT8 start_idx, UINT8 *p_found_idx, tBTM_SEC_D #endif return (found); } - +#endif ///BLE_INCLUDED == TRUE /******************************************************************************* ** ** Function btm_sec_use_smp_br_chnl diff --git a/components/bt/bluedroid/stack/btm/include/btm_int.h b/components/bt/bluedroid/stack/btm/include/btm_int.h index 455ce7ca36..4ef7285084 100644 --- a/components/bt/bluedroid/stack/btm/include/btm_int.h +++ b/components/bt/bluedroid/stack/btm/include/btm_int.h @@ -32,13 +32,14 @@ #include "stack/rfcdefs.h" #include "stack/btm_api.h" +#include "osi/fixed_queue.h" #if (BLE_INCLUDED == TRUE) #include "btm_ble_int.h" +#endif #if (SMP_INCLUDED == TRUE) #include "stack/smp_api.h" #endif -#endif #if BTM_MAX_LOC_BD_NAME_LEN > 0 typedef char tBTM_LOC_BD_NAME[BTM_MAX_LOC_BD_NAME_LEN + 1]; @@ -855,9 +856,12 @@ typedef struct { BOOLEAN pairing_disabled; BOOLEAN connect_only_paired; BOOLEAN security_mode_changed; /* mode changed during bonding */ - BOOLEAN pin_type_changed; /* pin type changed during bonding */ BOOLEAN sec_req_pending; /* TRUE if a request is pending */ +#if (CLASSIC_BT_INCLUDED == TRUE) + BOOLEAN pin_type_changed; /* pin type changed during bonding */ +#endif ///CLASSIC_BT_INCLUDED == TRUE #if (SMP_INCLUDED == TRUE) +#if (CLASSIC_BT_INCLUDED == TRUE) // btla-specific ++ #ifdef PORCHE_PAIRING_CONFLICT UINT8 pin_code_len_saved; /* for legacy devices */ @@ -866,12 +870,14 @@ typedef struct { UINT8 pin_code_len; /* for legacy devices */ PIN_CODE pin_code; /* for legacy devices */ + UINT8 disc_reason; /* for legacy devices */ + UINT16 disc_handle; /* for legacy devices */ +#endif ///CLASSIC_BT_INCLUDED == TRUE tBTM_PAIRING_STATE pairing_state; /* The current pairing state */ UINT8 pairing_flags; /* The current pairing flags */ BD_ADDR pairing_bda; /* The device currently pairing */ TIMER_LIST_ENT pairing_tle; /* Timer for pairing process */ - UINT16 disc_handle; /* for legacy devices */ - UINT8 disc_reason; /* for legacy devices */ + #endif ///SMP_INCLUDED == TRUE #if SMP_INCLUDED == TRUE || CLASSIC_BT_INCLUDED == TRUE tBTM_SEC_SERV_REC sec_serv_rec[BTM_SEC_MAX_SERVICE_RECORDS]; @@ -1122,10 +1128,10 @@ BOOLEAN btm_sec_is_le_capable_dev (BD_ADDR bda); BOOLEAN btm_ble_init_pseudo_addr (tBTM_SEC_DEV_REC *p_dev_rec, BD_ADDR new_pseudo_addr); extern BOOLEAN btm_ble_start_sec_check(BD_ADDR bd_addr, UINT16 psm, BOOLEAN is_originator, tBTM_SEC_CALLBACK *p_callback, void *p_ref_data); -extern tBTM_SEC_SERV_REC *btm_sec_find_first_serv (CONNECTION_TYPE conn_type, UINT16 psm); - #endif /* BLE_INCLUDED */ +extern tBTM_SEC_SERV_REC *btm_sec_find_first_serv (CONNECTION_TYPE conn_type, UINT16 psm); + tINQ_DB_ENT *btm_inq_db_new (BD_ADDR p_bda); #if BTM_OOB_INCLUDED == TRUE @@ -1142,13 +1148,13 @@ void btm_acl_paging (BT_HDR *p, BD_ADDR dest); UINT8 btm_sec_clr_service_by_psm (UINT16 psm); void btm_sec_clr_temp_auth_service (BD_ADDR bda); -void btm_lock_init(void); +void btm_ble_lock_init(void); -void btm_sem_init(void); +void btm_ble_sem_init(void); -void btm_sem_free(void); +void btm_ble_sem_free(void); -void btm_lock_free(void); +void btm_ble_lock_free(void); /* #ifdef __cplusplus diff --git a/components/bt/bluedroid/stack/btu/btu_hcif.c b/components/bt/bluedroid/stack/btu/btu_hcif.c index 7f0395a5b3..de7693ee84 100644 --- a/components/bt/bluedroid/stack/btu/btu_hcif.c +++ b/components/bt/bluedroid/stack/btu/btu_hcif.c @@ -1086,7 +1086,7 @@ static void btu_hcif_command_complete_evt(BT_HDR *response, void *context) event->event = BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK; - btu_task_post(SIG_BTU_HCI_MSG, event, TASK_POST_BLOCKING); + btu_task_post(SIG_BTU_HCI_MSG, event, OSI_THREAD_MAX_TIMEOUT); } @@ -1291,7 +1291,7 @@ static void btu_hcif_command_status_evt(uint8_t status, BT_HDR *command, void *c event->event = BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK; - btu_task_post(SIG_BTU_HCI_MSG, event, TASK_POST_BLOCKING); + btu_task_post(SIG_BTU_HCI_MSG, event, OSI_THREAD_MAX_TIMEOUT); } /******************************************************************************* @@ -1436,6 +1436,7 @@ static void btu_hcif_ssr_evt (UINT8 *p, UINT16 evt_len) #if (SMP_INCLUDED == TRUE) static void btu_hcif_pin_code_request_evt (UINT8 *p) { +#if (CLASSIC_BT_INCLUDED == TRUE) BD_ADDR bda; STREAM_TO_BDADDR (bda, p); @@ -1445,6 +1446,7 @@ static void btu_hcif_pin_code_request_evt (UINT8 *p) l2c_pin_code_request (bda); btm_sec_pin_code_request (bda); +#endif ///CLASSIC_BT_INCLUDED == TRUE } diff --git a/components/bt/bluedroid/stack/btu/btu_init.c b/components/bt/bluedroid/stack/btu/btu_init.c index 7014cfde00..617bb5de66 100644 --- a/components/bt/bluedroid/stack/btu/btu_init.c +++ b/components/bt/bluedroid/stack/btu/btu_init.c @@ -44,6 +44,11 @@ #endif #endif +#define BTU_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE) +#define BTU_TASK_STACK_SIZE (4096 + BT_TASK_EXTRA_STACK_SIZE) +#define BTU_TASK_PRIO (BT_TASK_MAX_PRIORITIES - 5) +#define BTU_TASK_NAME "btuT" + hash_map_t *btu_general_alarm_hash_map; osi_mutex_t btu_general_alarm_lock; static const size_t BTU_GENERAL_ALARM_HASH_MAP_SIZE = 34; @@ -56,16 +61,14 @@ hash_map_t *btu_l2cap_alarm_hash_map; osi_mutex_t btu_l2cap_alarm_lock; static const size_t BTU_L2CAP_ALARM_HASH_MAP_SIZE = 34; -//thread_t *bt_workqueue_thread; -//static const char *BT_WORKQUEUE_NAME = "bt_workqueue"; -xTaskHandle xBtuTaskHandle = NULL; -xQueueHandle xBtuQueue = 0; +osi_thread_t *btu_thread = NULL; extern void PLATFORM_DisableHciTransport(UINT8 bDisable); extern void btu_task_thread_handler(void *arg); -void btu_task_start_up(void); +void btu_task_start_up(void * param); void btu_task_shut_down(void); + /***************************************************************************** ** V A R I A B L E S * ******************************************************************************/ @@ -178,10 +181,14 @@ void BTU_StartUp(void) osi_mutex_new(&btu_l2cap_alarm_lock); - xBtuQueue = xQueueCreate(BTU_QUEUE_LEN, sizeof(BtTaskEvt_t)); - xTaskCreatePinnedToCore(btu_task_thread_handler, BTU_TASK_NAME, BTU_TASK_STACK_SIZE, NULL, BTU_TASK_PRIO, &xBtuTaskHandle, BTU_TASK_PINNED_TO_CORE); + btu_thread = osi_thread_create(BTU_TASK_NAME, BTU_TASK_STACK_SIZE, BTU_TASK_PRIO, BTU_TASK_PINNED_TO_CORE, 1); + if (btu_thread == NULL) { + goto error_exit; + } - btu_task_post(SIG_BTU_START_UP, NULL, TASK_POST_BLOCKING); + if (btu_task_post(SIG_BTU_START_UP, NULL, OSI_THREAD_MAX_TIMEOUT) == false) { + goto error_exit; + } return; @@ -190,6 +197,15 @@ error_exit:; BTU_ShutDown(); } +/***************************************************************************** +** +** Function BTU_ShutDown +** +** Description Deinitializes the BTU control block. +** +** Returns void +** +******************************************************************************/ void BTU_ShutDown(void) { #if BTU_DYNAMIC_MEMORY @@ -206,17 +222,14 @@ void BTU_ShutDown(void) hash_map_free(btu_l2cap_alarm_hash_map); osi_mutex_free(&btu_l2cap_alarm_lock); - vTaskDelete(xBtuTaskHandle); - vQueueDelete(xBtuQueue); + if (btu_thread) { + osi_thread_free(btu_thread); + btu_thread = NULL; + } btu_general_alarm_hash_map = NULL; - btu_oneshot_alarm_hash_map = NULL; - btu_l2cap_alarm_hash_map = NULL; - - xBtuTaskHandle = NULL; - xBtuQueue = 0; } /***************************************************************************** @@ -236,13 +249,14 @@ UINT16 BTU_BleAclPktSize(void) return 0; #endif } + #if SCAN_QUEUE_CONGEST_CHECK bool BTU_check_queue_is_congest(void) { - UBaseType_t wait_size = uxQueueMessagesWaiting(xBtuQueue); - if(wait_size >= QUEUE_CONGEST_SIZE ) { + if (osi_thread_queue_wait_size(btu_thread, 0) >= QUEUE_CONGEST_SIZE) { return true; } + return false; } #endif diff --git a/components/bt/bluedroid/stack/btu/btu_task.c b/components/bt/bluedroid/stack/btu/btu_task.c index 644731504d..3e73cbb85c 100644 --- a/components/bt/bluedroid/stack/btu/btu_task.c +++ b/components/bt/bluedroid/stack/btu/btu_task.c @@ -81,11 +81,16 @@ extern void avdt_rcv_sync_info (BT_HDR *p_buf); #include "btm_ble_int.h" #endif +typedef struct { + uint32_t sig; + void *param; +} btu_thread_evt_t; + //#if (defined(BT_APP_DEMO) && BT_APP_DEMO == TRUE) //#include "bt_app_common.h" //#endif -extern void BTE_InitStack(void); +extern bt_status_t BTE_InitStack(void); extern void BTE_DeinitStack(void); /* Define BTU storage area @@ -107,24 +112,26 @@ extern osi_mutex_t btu_oneshot_alarm_lock; extern hash_map_t *btu_l2cap_alarm_hash_map; extern osi_mutex_t btu_l2cap_alarm_lock; -extern xTaskHandle xBtuTaskHandle; -extern xQueueHandle xBtuQueue; +extern void *btu_thread; + extern bluedroid_init_done_cb_t bluedroid_init_done_cb; /* Define a function prototype to allow a generic timeout handler */ typedef void (tUSER_TIMEOUT_FUNC) (TIMER_LIST_ENT *p_tle); -static void btu_l2cap_alarm_process(TIMER_LIST_ENT *p_tle); -static void btu_general_alarm_process(TIMER_LIST_ENT *p_tle); -static void btu_hci_msg_process(BT_HDR *p_msg); +static void btu_l2cap_alarm_process(void *param); +static void btu_general_alarm_process(void *param); +static void btu_hci_msg_process(void *param); #if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE) -static void btu_bta_alarm_process(TIMER_LIST_ENT *p_tle); +static void btu_bta_alarm_process(void *param); #endif -static void btu_hci_msg_process(BT_HDR *p_msg) +static void btu_hci_msg_process(void *param) { /* Determine the input message type. */ + BT_HDR *p_msg = (BT_HDR *)param; + switch (p_msg->event & BT_EVT_MASK) { case BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK: // TODO(zachoverflow): remove this { @@ -191,8 +198,9 @@ static void btu_hci_msg_process(BT_HDR *p_msg) } #if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE) -static void btu_bta_alarm_process(TIMER_LIST_ENT *p_tle) +static void btu_bta_alarm_process(void *param) { + TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)param; // call timer callback if (p_tle->p_cback) { (*p_tle->p_cback)(p_tle); @@ -208,70 +216,42 @@ static void btu_bta_alarm_process(TIMER_LIST_ENT *p_tle) } #endif -/***************************************************************************** -** -** Function btu_task_thread_handler -** -** Description Process BTU Task Thread. -******************************************************************************/ -void btu_task_thread_handler(void *arg) +bool btu_task_post(uint32_t sig, void *param, uint32_t timeout) { - BtTaskEvt_t e; + bool status = false; - for (;;) { - if (pdTRUE == xQueueReceive(xBtuQueue, &e, (portTickType)portMAX_DELAY)) { - - switch (e.sig) { - case SIG_BTU_START_UP: - btu_task_start_up(); - break; - case SIG_BTU_HCI_MSG: - btu_hci_msg_process((BT_HDR *)e.par); - break; + switch (sig) { + case SIG_BTU_START_UP: + status = osi_thread_post(btu_thread, btu_task_start_up, param, 0, timeout); + break; + case SIG_BTU_HCI_MSG: + status = osi_thread_post(btu_thread, btu_hci_msg_process, param, 0, timeout); + break; #if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE) - case SIG_BTU_BTA_MSG: - bta_sys_event((BT_HDR *)e.par); - break; - case SIG_BTU_BTA_ALARM: - btu_bta_alarm_process((TIMER_LIST_ENT *)e.par); - break; + case SIG_BTU_BTA_MSG: + status = osi_thread_post(btu_thread, bta_sys_event, param, 0, timeout); + break; + case SIG_BTU_BTA_ALARM: + status = osi_thread_post(btu_thread, btu_bta_alarm_process, param, 0, timeout); + break; #endif - case SIG_BTU_GENERAL_ALARM: - btu_general_alarm_process((TIMER_LIST_ENT *)e.par); - break; - case SIG_BTU_ONESHOT_ALARM: { - TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)e.par; - btu_general_alarm_process(p_tle); - break; - } - case SIG_BTU_L2CAP_ALARM: - btu_l2cap_alarm_process((TIMER_LIST_ENT *)e.par); - break; - default: - break; - } - } - } -} - - -task_post_status_t btu_task_post(uint32_t sig, void *param, task_post_t timeout) -{ - BtTaskEvt_t evt; - - evt.sig = sig; - evt.par = param; - - if (xQueueSend(xBtuQueue, &evt, timeout) != pdTRUE) { - HCI_TRACE_ERROR("xBtuQueue failed\n"); - return TASK_POST_FAIL; + case SIG_BTU_GENERAL_ALARM: + case SIG_BTU_ONESHOT_ALARM: + status = osi_thread_post(btu_thread, btu_general_alarm_process, param, 0, timeout); + break; + case SIG_BTU_L2CAP_ALARM: + status = osi_thread_post(btu_thread, btu_l2cap_alarm_process, param, 0, timeout); + break; + default: + break; } - return TASK_POST_SUCCESS; + return status; } -void btu_task_start_up(void) +void btu_task_start_up(void *param) { + UNUSED(param); /* Initialize the mandatory core stack control blocks (BTU, BTM, L2CAP, and SDP) */ @@ -314,8 +294,9 @@ void btu_task_shut_down(void) ** Returns void ** *******************************************************************************/ -static void btu_general_alarm_process(TIMER_LIST_ENT *p_tle) +static void btu_general_alarm_process(void *param) { + TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)param; assert(p_tle != NULL); switch (p_tle->event) { @@ -426,7 +407,7 @@ void btu_general_alarm_cb(void *data) assert(data != NULL); TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data; - btu_task_post(SIG_BTU_GENERAL_ALARM, p_tle, TASK_POST_BLOCKING); + btu_task_post(SIG_BTU_GENERAL_ALARM, p_tle, OSI_THREAD_MAX_TIMEOUT); } void btu_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_sec) @@ -520,8 +501,9 @@ void btu_free_timer(TIMER_LIST_ENT *p_tle) ** Returns void ** *******************************************************************************/ -static void btu_l2cap_alarm_process(TIMER_LIST_ENT *p_tle) +static void btu_l2cap_alarm_process(void *param) { + TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)param; assert(p_tle != NULL); switch (p_tle->event) { @@ -540,7 +522,7 @@ static void btu_l2cap_alarm_cb(void *data) assert(data != NULL); TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data; - btu_task_post(SIG_BTU_L2CAP_ALARM, p_tle, TASK_POST_BLOCKING); + btu_task_post(SIG_BTU_L2CAP_ALARM, p_tle, OSI_THREAD_MAX_TIMEOUT); } void btu_start_quick_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_ticks) @@ -623,7 +605,7 @@ void btu_oneshot_alarm_cb(void *data) btu_stop_timer_oneshot(p_tle); - btu_task_post(SIG_BTU_ONESHOT_ALARM, p_tle, TASK_POST_BLOCKING); + btu_task_post(SIG_BTU_ONESHOT_ALARM, p_tle, OSI_THREAD_MAX_TIMEOUT); } /* diff --git a/components/bt/bluedroid/stack/gap/gap_api.c b/components/bt/bluedroid/stack/gap/gap_api.c index 305eadee0a..b4e7c1b4fb 100644 --- a/components/bt/bluedroid/stack/gap/gap_api.c +++ b/components/bt/bluedroid/stack/gap/gap_api.c @@ -21,8 +21,13 @@ #include "common/bt_target.h" //#include "bt_utils.h" #include "gap_int.h" +#include "osi/allocator.h" +#if GAP_DYNAMIC_MEMORY == FALSE tGAP_CB gap_cb; +#else +tGAP_CB *gap_cb_ptr; +#endif /******************************************************************************* ** @@ -52,11 +57,18 @@ UINT8 GAP_SetTraceLevel (UINT8 new_level) ** This routine should not be called except once per ** stack invocation. ** -** Returns Nothing +** Returns status ** *******************************************************************************/ -void GAP_Init(void) +bt_status_t GAP_Init(void) { +#if GAP_DYNAMIC_MEMORY == TRUE + gap_cb_ptr = (tGAP_CB *)osi_malloc(sizeof(tGAP_CB)); + if (!gap_cb_ptr) { + return BT_STATUS_NOMEM; + } +#endif + memset (&gap_cb, 0, sizeof (tGAP_CB)); #if defined(GAP_INITIAL_TRACE_LEVEL) @@ -72,5 +84,26 @@ void GAP_Init(void) #if BLE_INCLUDED == TRUE && GATTS_INCLUDED == TRUE gap_attr_db_init(); #endif + + return BT_STATUS_SUCCESS; } +/******************************************************************************* +** +** Function GAP_Deinit +** +** Description This function is called to deinitialize the control block +** for this layer. +** +** Returns void +** +*******************************************************************************/ +void GAP_Deinit(void) +{ +#if GAP_DYNAMIC_MEMORY == TRUE + if (gap_cb_ptr) { + osi_free(gap_cb_ptr); + gap_cb_ptr = NULL; + } +#endif +} \ No newline at end of file diff --git a/components/bt/bluedroid/stack/gap/gap_ble.c b/components/bt/bluedroid/stack/gap/gap_ble.c index bb5db8c1b1..5aab51fc1b 100644 --- a/components/bt/bluedroid/stack/gap/gap_ble.c +++ b/components/bt/bluedroid/stack/gap/gap_ble.c @@ -49,7 +49,7 @@ static void gap_ble_c_connect_cback (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn tGATT_DISCONN_REASON reason, tGATT_TRANSPORT transport); static void gap_ble_c_cmpl_cback (UINT16 conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE *p_data); -static tGATT_CBACK gap_cback = { +static const tGATT_CBACK gap_cback = { gap_ble_c_connect_cback, gap_ble_c_cmpl_cback, NULL, @@ -145,7 +145,7 @@ void gap_ble_dealloc_clcb(tGAP_CLCB *p_clcb) { tGAP_BLE_REQ *p_q; - while ((p_q = (tGAP_BLE_REQ *)fixed_queue_try_dequeue(p_clcb->pending_req_q)) != NULL) { + while ((p_q = (tGAP_BLE_REQ *)fixed_queue_dequeue(p_clcb->pending_req_q, 0)) != NULL) { /* send callback to all pending requests if being removed*/ if (p_q->p_cback != NULL) { (*p_q->p_cback)(FALSE, p_clcb->bda, 0, NULL); @@ -173,7 +173,7 @@ BOOLEAN gap_ble_enqueue_request (tGAP_CLCB *p_clcb, UINT16 uuid, tGAP_BLE_CMPL_C if (p_q != NULL) { p_q->p_cback = p_cback; p_q->uuid = uuid; - fixed_queue_enqueue(p_clcb->pending_req_q, p_q); + fixed_queue_enqueue(p_clcb->pending_req_q, p_q, FIXED_QUEUE_MAX_TIMEOUT); return TRUE; } @@ -190,7 +190,7 @@ BOOLEAN gap_ble_enqueue_request (tGAP_CLCB *p_clcb, UINT16 uuid, tGAP_BLE_CMPL_C *******************************************************************************/ BOOLEAN gap_ble_dequeue_request (tGAP_CLCB *p_clcb, UINT16 *p_uuid, tGAP_BLE_CMPL_CBACK **p_cback) { - tGAP_BLE_REQ *p_q = (tGAP_BLE_REQ *)fixed_queue_try_dequeue(p_clcb->pending_req_q);; + tGAP_BLE_REQ *p_q = (tGAP_BLE_REQ *)fixed_queue_dequeue(p_clcb->pending_req_q, 0);; if (p_q != NULL) { *p_cback = p_q->p_cback; diff --git a/components/bt/bluedroid/stack/gap/gap_conn.c b/components/bt/bluedroid/stack/gap/gap_conn.c index 671ffa7427..db9065de81 100644 --- a/components/bt/bluedroid/stack/gap/gap_conn.c +++ b/components/bt/bluedroid/stack/gap/gap_conn.c @@ -332,7 +332,7 @@ UINT16 GAP_ConnReadData (UINT16 gap_handle, UINT8 *p_data, UINT16 max_len, UINT1 p_buf->len -= copy_len; break; } - osi_free(fixed_queue_try_dequeue(p_ccb->rx_queue)); + osi_free(fixed_queue_dequeue(p_ccb->rx_queue, 0)); } p_ccb->rx_queue_size -= *p_len; @@ -404,7 +404,7 @@ UINT16 GAP_ConnBTRead (UINT16 gap_handle, BT_HDR **pp_buf) return (GAP_ERR_BAD_HANDLE); } - p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->rx_queue); + p_buf = (BT_HDR *)fixed_queue_dequeue(p_ccb->rx_queue, 0); if (p_buf) { *pp_buf = p_buf; @@ -451,7 +451,7 @@ UINT16 GAP_ConnBTWrite (UINT16 gap_handle, BT_HDR *p_buf) return (GAP_ERR_BUF_OFFSET); } - fixed_queue_enqueue(p_ccb->tx_queue, p_buf); + fixed_queue_enqueue(p_ccb->tx_queue, p_buf, FIXED_QUEUE_MAX_TIMEOUT); if (p_ccb->is_congested) { return (BT_PASS); @@ -461,7 +461,7 @@ UINT16 GAP_ConnBTWrite (UINT16 gap_handle, BT_HDR *p_buf) #if (GAP_CONN_POST_EVT_INCLUDED == TRUE) gap_send_event (gap_handle); #else - while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->tx_queue)) != NULL) { + while ((p_buf = (BT_HDR *)fixed_queue_dequeue(p_ccb->tx_queue, 0)) != NULL) { UINT8 status = L2CA_DATA_WRITE (p_ccb->connection_id, p_buf); if (status == L2CAP_DW_CONGESTED) { @@ -532,7 +532,7 @@ UINT16 GAP_ConnWriteData (UINT16 gap_handle, UINT8 *p_data, UINT16 max_len, UINT GAP_TRACE_EVENT ("GAP_WriteData %d bytes", p_buf->len); - fixed_queue_enqueue(p_ccb->tx_queue, p_buf); + fixed_queue_enqueue(p_ccb->tx_queue, p_buf, FIXED_QUEUE_MAX_TIMEOUT); } if (p_ccb->is_congested) { @@ -543,7 +543,7 @@ UINT16 GAP_ConnWriteData (UINT16 gap_handle, UINT8 *p_data, UINT16 max_len, UINT #if (GAP_CONN_POST_EVT_INCLUDED == TRUE) gap_send_event (gap_handle); #else - while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->tx_queue)) != NULL) + while ((p_buf = (BT_HDR *)fixed_queue_dequeue(p_ccb->tx_queue, 0)) != NULL) { UINT8 status = L2CA_DATA_WRITE (p_ccb->connection_id, p_buf); @@ -989,7 +989,7 @@ static void gap_data_ind (UINT16 l2cap_cid, BT_HDR *p_msg) } if (p_ccb->con_state == GAP_CCB_STATE_CONNECTED) { - fixed_queue_enqueue(p_ccb->rx_queue, p_msg); + fixed_queue_enqueue(p_ccb->rx_queue, p_msg, FIXED_QUEUE_MAX_TIMEOUT); p_ccb->rx_queue_size += p_msg->len; /* @@ -1033,7 +1033,7 @@ static void gap_congestion_ind (UINT16 lcid, BOOLEAN is_congested) p_ccb->p_callback (p_ccb->gap_handle, event); if (!is_congested) { - while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->tx_queue)) != NULL) { + while ((p_buf = (BT_HDR *)fixed_queue_dequeue(p_ccb->tx_queue, 0)) != NULL) { status = L2CA_DATA_WRITE (p_ccb->connection_id, p_buf); if (status == L2CAP_DW_CONGESTED) { @@ -1154,13 +1154,13 @@ static void gap_release_ccb (tGAP_CCB *p_ccb) p_ccb->rx_queue_size = 0; while (!fixed_queue_is_empty(p_ccb->rx_queue)) { - osi_free(fixed_queue_try_dequeue(p_ccb->rx_queue)); + osi_free(fixed_queue_dequeue(p_ccb->rx_queue, 0)); } fixed_queue_free(p_ccb->rx_queue, NULL); p_ccb->rx_queue = NULL; while (!fixed_queue_is_empty(p_ccb->tx_queue)) { - osi_free(fixed_queue_try_dequeue(p_ccb->tx_queue)); + osi_free(fixed_queue_dequeue(p_ccb->tx_queue, 0)); } fixed_queue_free(p_ccb->tx_queue, NULL); p_ccb->tx_queue = NULL; diff --git a/components/bt/bluedroid/stack/gap/include/gap_int.h b/components/bt/bluedroid/stack/gap/include/gap_int.h index e278141184..8a3ae0e2f0 100644 --- a/components/bt/bluedroid/stack/gap/include/gap_int.h +++ b/components/bt/bluedroid/stack/gap/include/gap_int.h @@ -142,8 +142,13 @@ typedef struct { #endif } tGAP_CB; - +#if GAP_DYNAMIC_MEMORY == FALSE extern tGAP_CB gap_cb; +#else +extern tGAP_CB *gap_cb_ptr; +#define gap_cb (*gap_cb_ptr) +#endif + #if (GAP_CONN_INCLUDED == TRUE) extern void gap_conn_init(void); #endif diff --git a/components/bt/bluedroid/stack/gatt/gatt_api.c b/components/bt/bluedroid/stack/gatt/gatt_api.c index 7f360d52db..d093d2b9d4 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_api.c +++ b/components/bt/bluedroid/stack/gatt/gatt_api.c @@ -110,7 +110,7 @@ BOOLEAN GATTS_AddHandleRange(tGATTS_HNDL_RANGE *p_hndl_range) ** Returns TRUE if registered OK, else FALSE ** *******************************************************************************/ -BOOLEAN GATTS_NVRegister (tGATT_APPL_INFO *p_cb_info) +BOOLEAN GATTS_NVRegister (const tGATT_APPL_INFO *p_cb_info) { BOOLEAN status = FALSE; if (p_cb_info) { @@ -1192,7 +1192,7 @@ void GATT_SetIdleTimeout (BD_ADDR bd_addr, UINT16 idle_tout, tBT_TRANSPORT trans ** Returns 0 for error, otherwise the index of the client registered with GATT ** *******************************************************************************/ -tGATT_IF GATT_Register (tBT_UUID *p_app_uuid128, tGATT_CBACK *p_cb_info) +tGATT_IF GATT_Register (tBT_UUID *p_app_uuid128, const tGATT_CBACK *p_cb_info) { tGATT_REG *p_reg; UINT8 i_gatt_if = 0; diff --git a/components/bt/bluedroid/stack/gatt/gatt_attr.c b/components/bt/bluedroid/stack/gatt/gatt_attr.c index 5036241317..3a67a8bf25 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_attr.c +++ b/components/bt/bluedroid/stack/gatt/gatt_attr.c @@ -52,7 +52,7 @@ static void gatt_cl_op_cmpl_cback(UINT16 conn_id, tGATTC_OPTYPE op, tGATT_STATUS static void gatt_cl_start_config_ccc(tGATT_PROFILE_CLCB *p_clcb); -static tGATT_CBACK gatt_profile_cback = { +static const tGATT_CBACK gatt_profile_cback = { gatt_connect_cback, gatt_cl_op_cmpl_cback, gatt_disc_res_cback, @@ -308,7 +308,7 @@ static void gatt_connect_cback (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id, p_clcb->connected = TRUE; p_clcb->conn_id = conn_id; } - + if (!p_clcb->connected) { /* wait for connection */ @@ -348,7 +348,7 @@ void gatt_profile_db_init (void) service_handle = GATTS_CreateService (gatt_cb.gatt_if , &uuid, 0, GATTP_MAX_ATTR_NUM, TRUE); GATT_TRACE_DEBUG ("GATTS_CreateService: handle of service handle%x", service_handle); - + /* add Service Changed characteristic */ uuid.uu.uuid16 = gatt_cb.gattp_attr.uuid = GATT_UUID_GATT_SRV_CHGD; diff --git a/components/bt/bluedroid/stack/gatt/gatt_auth.c b/components/bt/bluedroid/stack/gatt/gatt_auth.c index e233ea0cad..b72cb6faee 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_auth.c +++ b/components/bt/bluedroid/stack/gatt/gatt_auth.c @@ -176,7 +176,7 @@ void gatt_enc_cmpl_cback(BD_ADDR bd_addr, tBT_TRANSPORT transport, void *p_ref_d return; } tGATT_PENDING_ENC_CLCB *p_buf = - (tGATT_PENDING_ENC_CLCB *)fixed_queue_try_dequeue(p_tcb->pending_enc_clcb); + (tGATT_PENDING_ENC_CLCB *)fixed_queue_dequeue(p_tcb->pending_enc_clcb, 0); if (p_buf != NULL) { if (result == BTM_SUCCESS) { if (gatt_get_sec_act(p_tcb) == GATT_SEC_ENCRYPT_MITM ) { @@ -194,7 +194,7 @@ void gatt_enc_cmpl_cback(BD_ADDR bd_addr, tBT_TRANSPORT transport, void *p_ref_d /* start all other pending operation in queue */ for (size_t count = fixed_queue_length(p_tcb->pending_enc_clcb); count > 0; count--) { - p_buf = (tGATT_PENDING_ENC_CLCB *)fixed_queue_try_dequeue(p_tcb->pending_enc_clcb); + p_buf = (tGATT_PENDING_ENC_CLCB *)fixed_queue_dequeue(p_tcb->pending_enc_clcb, 0); if (p_buf != NULL) { gatt_security_check_start(p_buf->p_clcb); osi_free(p_buf); @@ -238,7 +238,7 @@ void gatt_notify_enc_cmpl(BD_ADDR bd_addr) size_t count = fixed_queue_length(p_tcb->pending_enc_clcb); for (; count > 0; count--) { tGATT_PENDING_ENC_CLCB *p_buf = - (tGATT_PENDING_ENC_CLCB *)fixed_queue_try_dequeue(p_tcb->pending_enc_clcb); + (tGATT_PENDING_ENC_CLCB *)fixed_queue_dequeue(p_tcb->pending_enc_clcb, 0); if (p_buf != NULL) { gatt_security_check_start(p_buf->p_clcb); osi_free(p_buf); diff --git a/components/bt/bluedroid/stack/gatt/gatt_cl.c b/components/bt/bluedroid/stack/gatt/gatt_cl.c index daa911e8c2..4ffd7ca5a0 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_cl.c +++ b/components/bt/bluedroid/stack/gatt/gatt_cl.c @@ -47,7 +47,7 @@ *********************************************************************************/ void gatt_send_prepare_write(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb); -UINT8 disc_type_to_att_opcode[GATT_DISC_MAX] = { +static const UINT8 disc_type_to_att_opcode[GATT_DISC_MAX] = { 0, GATT_REQ_READ_BY_GRP_TYPE, /* GATT_DISC_SRVC_ALL = 1, */ GATT_REQ_FIND_TYPE_VALUE, /* GATT_DISC_SRVC_BY_UUID, */ @@ -56,7 +56,7 @@ UINT8 disc_type_to_att_opcode[GATT_DISC_MAX] = { GATT_REQ_FIND_INFO /* GATT_DISC_CHAR_DSCPT, */ }; -UINT16 disc_type_to_uuid[GATT_DISC_MAX] = { +static const UINT16 disc_type_to_uuid[GATT_DISC_MAX] = { 0, /* reserved */ GATT_UUID_PRI_SERVICE, /* DISC_SRVC_ALL */ GATT_UUID_PRI_SERVICE, /* for DISC_SERVC_BY_UUID */ diff --git a/components/bt/bluedroid/stack/gatt/gatt_db.c b/components/bt/bluedroid/stack/gatt/gatt_db.c index 8a05117482..a860e19e09 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_db.c +++ b/components/bt/bluedroid/stack/gatt/gatt_db.c @@ -1383,7 +1383,7 @@ static BOOLEAN allocate_svc_db_buf(tGATT_SVC_DB *p_db) p_db->p_free_mem = (UINT8 *) p_buf; p_db->mem_free = GATT_DB_BUF_SIZE; - fixed_queue_enqueue(p_db->svc_buffer, p_buf); + fixed_queue_enqueue(p_db->svc_buffer, p_buf, FIXED_QUEUE_MAX_TIMEOUT); return TRUE; diff --git a/components/bt/bluedroid/stack/gatt/gatt_sr.c b/components/bt/bluedroid/stack/gatt/gatt_sr.c index eccc9ec979..6bad33b5c8 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_sr.c +++ b/components/bt/bluedroid/stack/gatt/gatt_sr.c @@ -140,7 +140,7 @@ void gatt_dequeue_sr_cmd (tGATT_TCB *p_tcb) if (p_tcb->sr_cmd.multi_rsp_q) { while (!fixed_queue_is_empty(p_tcb->sr_cmd.multi_rsp_q)) { - osi_free(fixed_queue_try_dequeue(p_tcb->sr_cmd.multi_rsp_q)); + osi_free(fixed_queue_dequeue(p_tcb->sr_cmd.multi_rsp_q, 0)); } fixed_queue_free(p_tcb->sr_cmd.multi_rsp_q, NULL); } @@ -178,7 +178,7 @@ static BOOLEAN process_read_multi_rsp (tGATT_SR_CMD *p_cmd, tGATT_STATUS status, } memcpy((void *)p_buf, (const void *)p_msg, sizeof(tGATTS_RSP)); - fixed_queue_enqueue(p_cmd->multi_rsp_q, p_buf); + fixed_queue_enqueue(p_cmd->multi_rsp_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT); p_cmd->status = status; if (status == GATT_SUCCESS) { @@ -418,7 +418,7 @@ void gatt_process_exec_write_req (tGATT_TCB *p_tcb, UINT8 op_code, UINT16 len, U //dequeue prepare write data while(fixed_queue_try_peek_first(prepare_record->queue)) { - queue_data = fixed_queue_dequeue(prepare_record->queue); + queue_data = fixed_queue_dequeue(prepare_record->queue, FIXED_QUEUE_MAX_TIMEOUT); if (is_prepare_write_valid){ if((queue_data->p_attr->p_value != NULL) && (queue_data->p_attr->p_value->attr_val.attr_val != NULL)){ if(is_first) { @@ -1291,7 +1291,7 @@ void gatt_attr_process_prepare_write (tGATT_TCB *p_tcb, UINT8 i_rcb, UINT16 hand if (prepare_record->queue == NULL) { prepare_record->queue = fixed_queue_new(QUEUE_SIZE_MAX); } - fixed_queue_enqueue(prepare_record->queue, queue_data); + fixed_queue_enqueue(prepare_record->queue, queue_data, FIXED_QUEUE_MAX_TIMEOUT); } } diff --git a/components/bt/bluedroid/stack/gatt/gatt_utils.c b/components/bt/bluedroid/stack/gatt/gatt_utils.c index 2455f746f3..8f9303f0bb 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_utils.c +++ b/components/bt/bluedroid/stack/gatt/gatt_utils.c @@ -97,7 +97,7 @@ void gatt_free_pending_ind(tGATT_TCB *p_tcb) /* release all queued indications */ while (!fixed_queue_is_empty(p_tcb->pending_ind_q)) { - osi_free(fixed_queue_try_dequeue(p_tcb->pending_ind_q)); + osi_free(fixed_queue_dequeue(p_tcb->pending_ind_q, 0)); } fixed_queue_free(p_tcb->pending_ind_q, NULL); p_tcb->pending_ind_q = NULL; @@ -121,7 +121,7 @@ void gatt_free_pending_enc_queue(tGATT_TCB *p_tcb) /* release all queued indications */ while (!fixed_queue_is_empty(p_tcb->pending_enc_clcb)) { - osi_free(fixed_queue_try_dequeue(p_tcb->pending_enc_clcb)); + osi_free(fixed_queue_dequeue(p_tcb->pending_enc_clcb, 0)); } fixed_queue_free(p_tcb->pending_enc_clcb, NULL); p_tcb->pending_enc_clcb = NULL; @@ -143,7 +143,7 @@ void gatt_free_pending_prepare_write_queue(tGATT_TCB *p_tcb) if (p_tcb->prepare_write_record.queue) { /* release all queued prepare write packets */ while (!fixed_queue_is_empty(p_tcb->prepare_write_record.queue)) { - osi_free(fixed_queue_dequeue(p_tcb->prepare_write_record.queue)); + osi_free(fixed_queue_dequeue(p_tcb->prepare_write_record.queue, FIXED_QUEUE_MAX_TIMEOUT)); } fixed_queue_free(p_tcb->prepare_write_record.queue, NULL); p_tcb->prepare_write_record.queue = NULL; @@ -265,7 +265,7 @@ tGATT_VALUE *gatt_add_pending_ind(tGATT_TCB *p_tcb, tGATT_VALUE *p_ind) if ((p_buf = (tGATT_VALUE *)osi_malloc((UINT16)sizeof(tGATT_VALUE))) != NULL) { GATT_TRACE_DEBUG ("enqueue a pending indication"); memcpy(p_buf, p_ind, sizeof(tGATT_VALUE)); - fixed_queue_enqueue(p_tcb->pending_ind_q, p_buf); + fixed_queue_enqueue(p_tcb->pending_ind_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT); } return p_buf; } @@ -288,7 +288,7 @@ tGATTS_PENDING_NEW_SRV_START *gatt_add_pending_new_srv_start(tGATTS_HNDL_RANGE * if ((p_buf = (tGATTS_PENDING_NEW_SRV_START *)osi_malloc((UINT16)sizeof(tGATTS_PENDING_NEW_SRV_START))) != NULL) { GATT_TRACE_DEBUG ("enqueue a new pending new srv start"); p_buf->p_new_srv_start = p_new_srv_start; - fixed_queue_enqueue(gatt_cb.pending_new_srv_start_q, p_buf); + fixed_queue_enqueue(gatt_cb.pending_new_srv_start_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT); } return p_buf; } @@ -310,7 +310,7 @@ tGATTS_SRV_CHG *gatt_add_srv_chg_clt(tGATTS_SRV_CHG *p_srv_chg) if ((p_buf = (tGATTS_SRV_CHG *)osi_malloc((UINT16)sizeof(tGATTS_SRV_CHG))) != NULL) { GATT_TRACE_DEBUG ("enqueue a srv chg client"); memcpy(p_buf, p_srv_chg, sizeof(tGATTS_SRV_CHG)); - fixed_queue_enqueue(gatt_cb.srv_chg_clt_q, p_buf); + fixed_queue_enqueue(gatt_cb.srv_chg_clt_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT); } return p_buf; @@ -469,7 +469,7 @@ void gatt_free_hdl_buffer(tGATT_HDL_LIST_ELEM *p) if (p) { while (!fixed_queue_is_empty(p->svc_db.svc_buffer)) { - osi_free(fixed_queue_try_dequeue(p->svc_db.svc_buffer)); + osi_free(fixed_queue_dequeue(p->svc_db.svc_buffer, 0)); } fixed_queue_free(p->svc_db.svc_buffer, NULL); memset(p, 0, sizeof(tGATT_HDL_LIST_ELEM)); @@ -495,7 +495,7 @@ void gatt_free_srvc_db_buffer_app_id(tBT_UUID *p_app_id) if (memcmp(p_app_id, &p_elem->asgn_range.app_uuid128, sizeof(tBT_UUID)) == 0) { gatt_free_attr_value_buffer(p_elem); while (!fixed_queue_is_empty(p_elem->svc_db.svc_buffer)) { - osi_free(fixed_queue_try_dequeue(p_elem->svc_db.svc_buffer)); + osi_free(fixed_queue_dequeue(p_elem->svc_db.svc_buffer, 0)); } fixed_queue_free(p_elem->svc_db.svc_buffer, NULL); p_elem->svc_db.svc_buffer = NULL; @@ -2733,7 +2733,7 @@ tGATT_PENDING_ENC_CLCB *gatt_add_pending_enc_channel_clcb(tGATT_TCB *p_tcb, tGAT if ((p_buf = (tGATT_PENDING_ENC_CLCB *)osi_malloc((UINT16)sizeof(tGATT_PENDING_ENC_CLCB))) != NULL) { GATT_TRACE_DEBUG ("enqueue a new pending encryption channel clcb"); p_buf->p_clcb = p_clcb; - fixed_queue_enqueue(p_tcb->pending_enc_clcb, p_buf); + fixed_queue_enqueue(p_tcb->pending_enc_clcb, p_buf, FIXED_QUEUE_MAX_TIMEOUT); } return p_buf; } diff --git a/components/bt/bluedroid/stack/include/stack/a2d_api.h b/components/bt/bluedroid/stack/include/stack/a2d_api.h index 7509544fb5..466f9fad72 100644 --- a/components/bt/bluedroid/stack/include/stack/a2d_api.h +++ b/components/bt/bluedroid/stack/include/stack/a2d_api.h @@ -23,6 +23,7 @@ ******************************************************************************/ #ifndef A2D_API_H #define A2D_API_H +#include "common/bt_defs.h" #include "stack/sdp_api.h" #if (A2D_INCLUDED == TRUE) /***************************************************************************** @@ -250,7 +251,7 @@ extern UINT8 A2D_BitsSet(UINT8 num); ** Returns void ** *******************************************************************************/ -extern void A2D_Init(void); +extern bt_status_t A2D_Init(void); extern void A2D_Deinit(void); #endif ///A2D_INCLUDED #endif /* A2D_API_H */ diff --git a/components/bt/bluedroid/stack/include/stack/avrc_api.h b/components/bt/bluedroid/stack/include/stack/avrc_api.h index 85e8db1b2e..cbbb4b1c69 100644 --- a/components/bt/bluedroid/stack/include/stack/avrc_api.h +++ b/components/bt/bluedroid/stack/include/stack/avrc_api.h @@ -24,6 +24,7 @@ #ifndef AVRC_API_H #define AVRC_API_H #include "common/bt_target.h" +#include "common/bt_defs.h" #include "stack/avct_api.h" #include "stack/sdp_api.h" #include "stack/avrc_defs.h" @@ -549,10 +550,10 @@ extern UINT8 AVRC_SetTraceLevel (UINT8 new_level); ** control block (if using dynamic memory), and initializes the ** control block and tracing level. ** -** Returns void +** Returns status ** *******************************************************************************/ -extern void AVRC_Init(void); +extern bt_status_t AVRC_Init(void); /******************************************************************************* ** diff --git a/components/bt/bluedroid/stack/include/stack/btm_api.h b/components/bt/bluedroid/stack/include/stack/btm_api.h index bf2b033bc0..b51ecb0069 100644 --- a/components/bt/bluedroid/stack/include/stack/btm_api.h +++ b/components/bt/bluedroid/stack/include/stack/btm_api.h @@ -645,8 +645,8 @@ typedef struct { INT8 rssi; /* Set to BTM_INQ_RES_IGNORE_RSSI if not valid */ UINT32 eir_uuid[BTM_EIR_SERVICE_ARRAY_SIZE]; BOOLEAN eir_complete_list; -#if (BLE_INCLUDED == TRUE) tBT_DEVICE_TYPE device_type; +#if (BLE_INCLUDED == TRUE) UINT8 inq_result_type; UINT8 ble_addr_type; tBTM_BLE_EVT_TYPE ble_evt_type; @@ -1394,12 +1394,12 @@ typedef UINT8 tBTM_SP_EVT; #define BTM_IO_CAP_IO 1 /* DisplayYesNo */ #define BTM_IO_CAP_IN 2 /* KeyboardOnly */ #define BTM_IO_CAP_NONE 3 /* NoInputNoOutput */ -#if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE +// #if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE #define BTM_IO_CAP_KBDISP 4 /* Keyboard display */ #define BTM_IO_CAP_MAX 5 -#else -#define BTM_IO_CAP_MAX 4 -#endif +// #else +// #define BTM_IO_CAP_MAX 4 +// #endif typedef UINT8 tBTM_IO_CAP; diff --git a/components/bt/bluedroid/stack/include/stack/btu.h b/components/bt/bluedroid/stack/include/stack/btu.h index 449b18da7e..fd5d1c989d 100644 --- a/components/bt/bluedroid/stack/include/stack/btu.h +++ b/components/bt/bluedroid/stack/include/stack/btu.h @@ -29,6 +29,7 @@ #include "common/bt_target.h" #include "common/bt_defs.h" +#include "osi/thread.h" // HACK(zachoverflow): temporary dark magic #define BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK 0x1700 // didn't look used in bt_types...here goes nothing @@ -163,6 +164,17 @@ typedef void (*tBTU_EVENT_CALLBACK)(BT_HDR *p_hdr); #define BTU_TTYPE_UCD_TO 108 #define BTU_TTYPE_BLE_SCAN 109 +/* BTU Task Signal */ +typedef enum { + SIG_BTU_START_UP = 0, + SIG_BTU_HCI_MSG, + SIG_BTU_BTA_MSG, + SIG_BTU_BTA_ALARM, + SIG_BTU_GENERAL_ALARM, + SIG_BTU_ONESHOT_ALARM, + SIG_BTU_L2CAP_ALARM, + SIG_BTU_NUM, +} SIG_BTU_t; /* This is the inquiry response information held by BTU, and available ** to applications. @@ -271,11 +283,13 @@ void btu_free_core(void); void BTU_StartUp(void); void BTU_ShutDown(void); -void btu_task_start_up(void); +void btu_task_start_up(void *param); void btu_task_shut_down(void); UINT16 BTU_BleAclPktSize(void); +bool btu_task_post(uint32_t sig, void *param, uint32_t timeout); + /* #ifdef __cplusplus } diff --git a/components/bt/bluedroid/stack/include/stack/dyn_mem.h b/components/bt/bluedroid/stack/include/stack/dyn_mem.h index f3f33537ca..1241c3a85a 100644 --- a/components/bt/bluedroid/stack/include/stack/dyn_mem.h +++ b/components/bt/bluedroid/stack/include/stack/dyn_mem.h @@ -18,15 +18,19 @@ #ifndef DYN_MEM_H #define DYN_MEM_H -#include "sdkconfig.h" -#if CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY +#include "common/bt_user_config.h" + +#if UC_BT_BLE_DYNAMIC_ENV_MEMORY +#define BT_BLE_DYNAMIC_ENV_MEMORY TRUE #define BTU_DYNAMIC_MEMORY TRUE #define BTM_DYNAMIC_MEMORY TRUE #define L2C_DYNAMIC_MEMORY TRUE #define GATT_DYNAMIC_MEMORY TRUE #define SMP_DYNAMIC_MEMORY TRUE #define BTA_DYNAMIC_MEMORY TRUE +#define BTC_DYNAMIC_MENDRY TRUE #define SDP_DYNAMIC_MEMORY TRUE +#define GAP_DYNAMIC_MEMORY TRUE #define RFC_DYNAMIC_MEMORY TRUE #define TCS_DYNAMIC_MEMORY TRUE #define BNEP_DYNAMIC_MEMORY TRUE @@ -51,11 +55,18 @@ #define SLIP_DYNAMIC_MEMORY TRUE #define LLCP_DYNAMIC_MEMORY TRUE #define BTC_SBC_DEC_DYNAMIC_MEMORY TRUE -#define BTC_SBC_ENC_DYNAMIC_MEMORY TRUE - -#else /* #if CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY */ +#else /* #if UC_BT_BLE_DYNAMIC_ENV_MEMORY */ +#define BT_BLE_DYNAMIC_ENV_MEMORY FALSE +#define BTU_DYNAMIC_MEMORY FALSE +#define BTM_DYNAMIC_MEMORY FALSE +#define L2C_DYNAMIC_MEMORY FALSE +#define GATT_DYNAMIC_MEMORY FALSE +#define SMP_DYNAMIC_MEMORY FALSE +#define BTA_DYNAMIC_MEMORY FALSE +#define BTC_DYNAMIC_MENDRY FALSE #define SDP_DYNAMIC_MEMORY FALSE +#define GAP_DYNAMIC_MEMORY FALSE #define RFC_DYNAMIC_MEMORY FALSE #define TCS_DYNAMIC_MEMORY FALSE #define BNEP_DYNAMIC_MEMORY FALSE @@ -80,9 +91,13 @@ #define SLIP_DYNAMIC_MEMORY FALSE #define LLCP_DYNAMIC_MEMORY FALSE #define BTC_SBC_DEC_DYNAMIC_MEMORY FALSE -#define BTC_SBC_ENC_DYNAMIC_MEMORY FALSE -#endif /* #if CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY */ +#endif /* #if UC_BT_BLE_DYNAMIC_ENV_MEMORY */ + +#ifndef BT_BLE_DYNAMIC_ENV_MEMORY +#define BT_BLE_DYNAMIC_ENV_MEMORY FALSE +#endif + /**************************************************************************** ** Define memory usage for each CORE component (if not defined in bdroid_buildcfg.h) ** The default for each component is to use static memory allocations. @@ -99,6 +114,10 @@ #define SDP_DYNAMIC_MEMORY FALSE #endif +#ifndef GAP_DYNAMIC_MEMORY +#define GAP_DYNAMIC_MEMORY FALSE +#endif + #ifndef L2C_DYNAMIC_MEMORY #define L2C_DYNAMIC_MEMORY FALSE #endif @@ -208,12 +227,15 @@ #endif /**************************************************************************** -** Define memory usage for BTA (if not defined in bdroid_buildcfg.h) +** Define memory usage for BTA and BTC (if not defined in bdroid_buildcfg.h) ** The default for each component is to use static memory allocations. */ #ifndef BTA_DYNAMIC_MEMORY #define BTA_DYNAMIC_MEMORY FALSE #endif -#endif /* #ifdef DYN_MEM_H */ +#ifndef BTC_DYNAMIC_MENDRY +#define BTC_DYNAMIC_MENDRY FALSE +#endif +#endif /* #ifdef DYN_MEM_H */ diff --git a/components/bt/bluedroid/stack/include/stack/gap_api.h b/components/bt/bluedroid/stack/include/stack/gap_api.h index 5d8d87645d..62062d2f21 100644 --- a/components/bt/bluedroid/stack/include/stack/gap_api.h +++ b/components/bt/bluedroid/stack/include/stack/gap_api.h @@ -320,10 +320,22 @@ extern UINT8 GAP_SetTraceLevel (UINT8 new_level); ** This routine should not be called except once per ** stack invocation. ** -** Returns Nothing +** Returns status ** *******************************************************************************/ -extern void GAP_Init(void); +extern bt_status_t GAP_Init(void); + +/******************************************************************************* +** +** Function GAP_Deinit +** +** Description This function is called to deinitialize the control block +** for this layer. +** +** Returns void +** +*******************************************************************************/ +extern void GAP_Deinit(void); #if (BLE_INCLUDED == TRUE) /******************************************************************************* diff --git a/components/bt/bluedroid/stack/include/stack/gatt_api.h b/components/bt/bluedroid/stack/include/stack/gatt_api.h index b2cecb0578..c250f9a3c1 100644 --- a/components/bt/bluedroid/stack/include/stack/gatt_api.h +++ b/components/bt/bluedroid/stack/include/stack/gatt_api.h @@ -707,7 +707,7 @@ extern BOOLEAN GATTS_AddHandleRange(tGATTS_HNDL_RANGE *p_hndl_range); ** Returns TRUE if registered OK, else FALSE ** *******************************************************************************/ -extern BOOLEAN GATTS_NVRegister (tGATT_APPL_INFO *p_cb_info); +extern BOOLEAN GATTS_NVRegister (const tGATT_APPL_INFO *p_cb_info); /******************************************************************************* @@ -1059,7 +1059,7 @@ extern void GATT_SetIdleTimeout (BD_ADDR bd_addr, UINT16 idle_tout, ** Returns 0 for error, otherwise the index of the client registered with GATT ** *******************************************************************************/ -extern tGATT_IF GATT_Register (tBT_UUID *p_app_uuid128, tGATT_CBACK *p_cb_info); +extern tGATT_IF GATT_Register (tBT_UUID *p_app_uuid128, const tGATT_CBACK *p_cb_info); /******************************************************************************* ** diff --git a/components/bt/bluedroid/stack/include/stack/l2c_api.h b/components/bt/bluedroid/stack/include/stack/l2c_api.h index 147ed6c74c..33abaec7b3 100644 --- a/components/bt/bluedroid/stack/include/stack/l2c_api.h +++ b/components/bt/bluedroid/stack/include/stack/l2c_api.h @@ -1210,6 +1210,7 @@ extern BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable); ** *******************************************************************************/ extern UINT8 L2CA_GetBleConnRole (BD_ADDR bd_addr); +#endif /* (BLE_INCLUDED == TRUE) */ /******************************************************************************* ** @@ -1228,7 +1229,6 @@ extern UINT16 L2CA_GetDisconnectReason (BD_ADDR remote_bda, tBT_TRANSPORT transp extern BOOLEAN L2CA_CheckIsCongest(UINT16 fixed_cid, UINT16 handle); -#endif /* (BLE_INCLUDED == TRUE) */ #ifdef __cplusplus } diff --git a/components/bt/bluedroid/stack/include/stack/port_api.h b/components/bt/bluedroid/stack/include/stack/port_api.h index 10b0378681..145ef22889 100644 --- a/components/bt/bluedroid/stack/include/stack/port_api.h +++ b/components/bt/bluedroid/stack/include/stack/port_api.h @@ -25,6 +25,7 @@ #define PORT_API_H #include "common/bt_target.h" +#include "common/bt_defs.h" /***************************************************************************** ** Constants and Types @@ -621,8 +622,19 @@ extern int PORT_Test (UINT16 handle, UINT8 *p_data, UINT16 len); ** Description This function is called to initialize RFCOMM layer ** *******************************************************************************/ -extern void RFCOMM_Init (void); +extern bt_status_t RFCOMM_Init (void); +/******************************************************************************* +** +** Function RFCOMM_Deinit +** +** Description This function is called to deinitialize the control block +** for this layer. +** +** Returns void +** +*******************************************************************************/ +extern void RFCOMM_Deinit(void); /******************************************************************************* ** diff --git a/components/bt/bluedroid/stack/include/stack/smp_api.h b/components/bt/bluedroid/stack/include/stack/smp_api.h index 390f6209e6..1064237c8d 100644 --- a/components/bt/bluedroid/stack/include/stack/smp_api.h +++ b/components/bt/bluedroid/stack/include/stack/smp_api.h @@ -29,7 +29,7 @@ #define SMP_PIN_CODE_LEN_MAX PIN_CODE_LEN #define SMP_PIN_CODE_LEN_MIN 6 -#if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE +// #if SMP_INCLUDED == TRUE /* SMP command code */ #define SMP_OPCODE_PAIRING_REQ 0x01 #define SMP_OPCODE_PAIRING_RSP 0x02 @@ -48,7 +48,7 @@ #define SMP_OPCODE_MAX SMP_OPCODE_PAIR_KEYPR_NOTIF #define SMP_OPCODE_MIN SMP_OPCODE_PAIRING_REQ #define SMP_OPCODE_PAIR_COMMITM 0x0F -#endif +// #endif /* SMP event type */ #define SMP_IO_CAP_REQ_EVT 1 /* IO capability request event */ diff --git a/components/bt/bluedroid/stack/l2cap/l2c_api.c b/components/bt/bluedroid/stack/l2cap/l2c_api.c index 906b961d20..4074cef841 100644 --- a/components/bt/bluedroid/stack/l2cap/l2c_api.c +++ b/components/bt/bluedroid/stack/l2cap/l2c_api.c @@ -1301,6 +1301,7 @@ UINT8 L2CA_GetChnlFcrMode (UINT16 lcid) #endif ///CLASSIC_BT_INCLUDED == TRUE +#if (BLE_INCLUDED == TRUE) /******************************************************************************* ** ** Function L2CA_RegisterLECoc @@ -1610,8 +1611,7 @@ BOOLEAN L2CA_GetPeerLECocConfig (UINT16 lcid, tL2CAP_LE_CFG_INFO* peer_cfg) return TRUE; } - - +#endif ///BLE_INCLUDED == TRUE #if (L2CAP_NUM_FIXED_CHNLS > 0) /******************************************************************************* @@ -2221,7 +2221,7 @@ UINT16 L2CA_FlushChannel (UINT16 lcid, UINT16 num_to_flush) /* If needed, flush buffers in the CCB xmit hold queue */ while ( (num_to_flush != 0) && (!fixed_queue_is_empty(p_ccb->xmit_hold_q))) { - BT_HDR *p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->xmit_hold_q); + BT_HDR *p_buf = (BT_HDR *)fixed_queue_dequeue(p_ccb->xmit_hold_q, 0); if (p_buf) { osi_free (p_buf); } diff --git a/components/bt/bluedroid/stack/l2cap/l2c_ble.c b/components/bt/bluedroid/stack/l2cap/l2c_ble.c index 9a26969fac..300acefe8a 100644 --- a/components/bt/bluedroid/stack/l2cap/l2c_ble.c +++ b/components/bt/bluedroid/stack/l2cap/l2c_ble.c @@ -223,28 +223,6 @@ UINT8 L2CA_GetBleConnRole (BD_ADDR bd_addr) return role; } -/******************************************************************************* -** -** Function L2CA_GetDisconnectReason -** -** Description This function returns the disconnect reason code. -** -** Returns disconnect reason -** -*******************************************************************************/ -UINT16 L2CA_GetDisconnectReason (BD_ADDR remote_bda, tBT_TRANSPORT transport) -{ - tL2C_LCB *p_lcb; - UINT16 reason = 0; - - if ((p_lcb = l2cu_find_lcb_by_bd_addr (remote_bda, transport)) != NULL) { - reason = p_lcb->disc_reason; - } - - L2CAP_TRACE_DEBUG ("L2CA_GetDisconnectReason=%d ", reason); - - return reason; -} /******************************************************************************* ** @@ -1383,7 +1361,7 @@ void l2cble_sec_comp(BD_ADDR p_bda, tBT_TRANSPORT transport, void *p_ref_data, if (!fixed_queue_is_empty(p_lcb->le_sec_pending_q)) { - p_buf = (tL2CAP_SEC_DATA*) fixed_queue_dequeue(p_lcb->le_sec_pending_q); + p_buf = (tL2CAP_SEC_DATA*) fixed_queue_dequeue(p_lcb->le_sec_pending_q, FIXED_QUEUE_MAX_TIMEOUT); if (!p_buf) { L2CAP_TRACE_WARNING ("%s Security complete for request not initiated from L2CAP", @@ -1428,7 +1406,7 @@ void l2cble_sec_comp(BD_ADDR p_bda, tBT_TRANSPORT transport, void *p_ref_data, while (!fixed_queue_is_empty(p_lcb->le_sec_pending_q)) { - p_buf = (tL2CAP_SEC_DATA*) fixed_queue_dequeue(p_lcb->le_sec_pending_q); + p_buf = (tL2CAP_SEC_DATA*) fixed_queue_dequeue(p_lcb->le_sec_pending_q, FIXED_QUEUE_MAX_TIMEOUT); if (status != BTM_SUCCESS) { (*(p_buf->p_callback))(p_bda, BT_TRANSPORT_LE, p_buf->p_ref_data, status); @@ -1484,10 +1462,32 @@ BOOLEAN l2ble_sec_access_req(BD_ADDR bd_addr, UINT16 psm, BOOLEAN is_originator, p_buf->is_originator = is_originator; p_buf->p_callback = p_callback; p_buf->p_ref_data = p_ref_data; - fixed_queue_enqueue(p_lcb->le_sec_pending_q, p_buf); + fixed_queue_enqueue(p_lcb->le_sec_pending_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT); status = btm_ble_start_sec_check(bd_addr, psm, is_originator, &l2cble_sec_comp, p_ref_data); return status; } #endif /* #if (SMP_INCLUDED == TRUE) */ #endif /* (BLE_INCLUDED == TRUE) */ +/******************************************************************************* +** +** Function L2CA_GetDisconnectReason +** +** Description This function returns the disconnect reason code. +** +** Returns disconnect reason +** +*******************************************************************************/ +UINT16 L2CA_GetDisconnectReason (BD_ADDR remote_bda, tBT_TRANSPORT transport) +{ + tL2C_LCB *p_lcb; + UINT16 reason = 0; + + if ((p_lcb = l2cu_find_lcb_by_bd_addr (remote_bda, transport)) != NULL) { + reason = p_lcb->disc_reason; + } + + L2CAP_TRACE_DEBUG ("L2CA_GetDisconnectReason=%d ", reason); + + return reason; +} \ No newline at end of file diff --git a/components/bt/bluedroid/stack/l2cap/l2c_csm.c b/components/bt/bluedroid/stack/l2cap/l2c_csm.c index ddfe53dba3..ff7fbb0ec0 100644 --- a/components/bt/bluedroid/stack/l2cap/l2c_csm.c +++ b/components/bt/bluedroid/stack/l2cap/l2c_csm.c @@ -1243,7 +1243,7 @@ void l2c_enqueue_peer_data (tL2C_CCB *p_ccb, BT_HDR *p_buf) UINT16_TO_STREAM (p, p_ccb->remote_cid); } - fixed_queue_enqueue(p_ccb->xmit_hold_q, p_buf); + fixed_queue_enqueue(p_ccb->xmit_hold_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT); l2cu_check_channel_congestion (p_ccb); diff --git a/components/bt/bluedroid/stack/l2cap/l2c_fcr.c b/components/bt/bluedroid/stack/l2cap/l2c_fcr.c index 3a7085c803..ecf0bd6c68 100644 --- a/components/bt/bluedroid/stack/l2cap/l2c_fcr.c +++ b/components/bt/bluedroid/stack/l2cap/l2c_fcr.c @@ -752,7 +752,7 @@ void l2c_fcr_proc_pdu (tL2C_CCB *p_ccb, BT_HDR *p_buf) fixed_queue_t *temp_q = p_ccb->fcrb.srej_rcv_hold_q; p_ccb->fcrb.srej_rcv_hold_q = fixed_queue_new(QUEUE_SIZE_MAX); - while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(temp_q)) != NULL) { + while ((p_buf = (BT_HDR *)fixed_queue_dequeue(temp_q, 0)) != NULL) { if (p_ccb->in_use && (p_ccb->chnl_state == CST_OPEN)) { /* Get the control word */ p = ((UINT8 *)(p_buf + 1)) + p_buf->offset - L2CAP_FCR_OVERHEAD; @@ -921,7 +921,7 @@ static BOOLEAN process_reqseq (tL2C_CCB *p_ccb, UINT16 ctrl_word) #endif for (xx = 0; xx < num_bufs_acked; xx++) { - BT_HDR *p_tmp = (BT_HDR *)fixed_queue_try_dequeue(p_fcrb->waiting_for_ack_q); + BT_HDR *p_tmp = (BT_HDR *)fixed_queue_dequeue(p_fcrb->waiting_for_ack_q, 0); ls = p_tmp->layer_specific & L2CAP_FCR_SAR_BITS; if ( (ls == L2CAP_FCR_UNSEG_SDU) || (ls == L2CAP_FCR_END_SDU) ) { @@ -1118,7 +1118,7 @@ static void process_i_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, UINT16 ctrl_word, B num_lost, tx_seq, p_fcrb->next_seq_expected, p_fcrb->rej_sent); p_buf->layer_specific = tx_seq; - fixed_queue_enqueue(p_fcrb->srej_rcv_hold_q, p_buf); + fixed_queue_enqueue(p_fcrb->srej_rcv_hold_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT); } else { L2CAP_TRACE_WARNING ("process_i_frame() CID: 0x%04x frame dropped in Srej Sent next_srej:%u hold_q.count:%u win_sz:%u", p_ccb->local_cid, next_srej, fixed_queue_length(p_fcrb->srej_rcv_hold_q), p_ccb->our_cfg.fcr.tx_win_sz); @@ -1147,7 +1147,7 @@ static void process_i_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, UINT16 ctrl_word, B p_ccb->local_cid, tx_seq, fixed_queue_length(p_fcrb->srej_rcv_hold_q)); } p_buf->layer_specific = tx_seq; - fixed_queue_enqueue(p_fcrb->srej_rcv_hold_q, p_buf); + fixed_queue_enqueue(p_fcrb->srej_rcv_hold_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT); p_fcrb->srej_sent = TRUE; l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_SREJ, 0); } @@ -1471,7 +1471,7 @@ static BOOLEAN retransmit_i_frames (tL2C_CCB *p_ccb, UINT8 tx_seq) /* Also flush our retransmission queue */ while (!fixed_queue_is_empty(p_ccb->fcrb.retrans_q)) { - osi_free(fixed_queue_try_dequeue(p_ccb->fcrb.retrans_q)); + osi_free(fixed_queue_dequeue(p_ccb->fcrb.retrans_q, 0)); } if (list_ack != NULL) { @@ -1490,7 +1490,7 @@ static BOOLEAN retransmit_i_frames (tL2C_CCB *p_ccb, UINT8 tx_seq) { p_buf2->layer_specific = p_buf->layer_specific; - fixed_queue_enqueue(p_ccb->fcrb.retrans_q, p_buf2); + fixed_queue_enqueue(p_ccb->fcrb.retrans_q, p_buf2, FIXED_QUEUE_MAX_TIMEOUT); } if ( (tx_seq != L2C_FCR_RETX_ALL_PKTS) || (p_buf2 == NULL) ) { @@ -1534,7 +1534,7 @@ BT_HDR *l2c_fcr_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, UINT16 max_packet_length /* If there is anything in the retransmit queue, that goes first */ - p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->fcrb.retrans_q); + p_buf = (BT_HDR *)fixed_queue_dequeue(p_ccb->fcrb.retrans_q, 0); if (p_buf != NULL) { /* Update Rx Seq and FCS if we acked some packets while this one was queued */ prepare_I_frame (p_ccb, p_buf, TRUE); @@ -1586,7 +1586,7 @@ BT_HDR *l2c_fcr_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, UINT16 max_packet_length return (NULL); } } else { /* Use the original buffer if no segmentation, or the last segment */ - p_xmit = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->xmit_hold_q); + p_xmit = (BT_HDR *)fixed_queue_dequeue(p_ccb->xmit_hold_q, 0); if (p_xmit->event != 0) { last_seg = TRUE; @@ -1647,7 +1647,7 @@ BT_HDR *l2c_fcr_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, UINT16 max_packet_length } /* Pretend we sent it and it got lost */ - fixed_queue_enqueue(p_ccb->fcrb.waiting_for_ack_q, p_xmit); + fixed_queue_enqueue(p_ccb->fcrb.waiting_for_ack_q, p_xmit, FIXED_QUEUE_MAX_TIMEOUT); return (NULL); } else { #if (L2CAP_ERTM_STATS == TRUE) @@ -1661,7 +1661,7 @@ BT_HDR *l2c_fcr_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, UINT16 max_packet_length } p_wack->layer_specific = p_xmit->layer_specific; - fixed_queue_enqueue(p_ccb->fcrb.waiting_for_ack_q, p_wack); + fixed_queue_enqueue(p_ccb->fcrb.waiting_for_ack_q, p_wack, FIXED_QUEUE_MAX_TIMEOUT); } #if (L2CAP_ERTM_STATS == TRUE) diff --git a/components/bt/bluedroid/stack/l2cap/l2c_link.c b/components/bt/bluedroid/stack/l2cap/l2c_link.c index 15de6060b1..1117a0abae 100644 --- a/components/bt/bluedroid/stack/l2cap/l2c_link.c +++ b/components/bt/bluedroid/stack/l2cap/l2c_link.c @@ -357,7 +357,9 @@ BOOLEAN l2c_link_hci_disc_comp (UINT16 handle, UINT8 reason) p_lcb = l2cu_find_lcb_by_handle (handle); /* If we don't have one, maybe an SCO link. Send to MM */ if (!p_lcb) { +#if (BLE_INCLUDED == TRUE) BTM_Recovery_Pre_State(); +#endif ///BLE_INCLUDED == TRUE status = FALSE; } else { /* There can be a case when we rejected PIN code authentication */ @@ -1026,8 +1028,10 @@ void l2c_link_check_send_pkts (tL2C_LCB *p_lcb, tL2C_CCB *p_ccb, BT_HDR *p_buf) /* Loop through, starting at the next */ for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_lcb++) { - /* If controller window is full, nothing to do */ +#if (BLE_INCLUDED == TRUE) L2CAP_TRACE_DEBUG("window = %d,robin_unacked = %d,robin_quota=%d",l2cb.controller_le_xmit_window,l2cb.ble_round_robin_unacked,l2cb.ble_round_robin_quota); +#endif ///BLE_INCLUDED == TRUE + /* If controller window is full, nothing to do */ if (((l2cb.controller_xmit_window == 0 || (l2cb.round_robin_unacked >= l2cb.round_robin_quota)) #if (BLE_INCLUDED == TRUE) @@ -1038,7 +1042,7 @@ void l2c_link_check_send_pkts (tL2C_LCB *p_lcb, tL2C_CCB *p_ccb, BT_HDR *p_buf) l2cb.controller_le_xmit_window == 0 ))) #else )) -#endif +#endif ///BLE_INCLUDED == TRUE break; diff --git a/components/bt/bluedroid/stack/l2cap/l2c_main.c b/components/bt/bluedroid/stack/l2cap/l2c_main.c index 1035b44c6a..e50e59dceb 100644 --- a/components/bt/bluedroid/stack/l2cap/l2c_main.c +++ b/components/bt/bluedroid/stack/l2cap/l2c_main.c @@ -52,6 +52,7 @@ tL2C_CB l2cb; tL2C_CB *l2c_cb_ptr; #endif +#if 0 //Unused /******************************************************************************* ** ** Function l2c_bcst_msg @@ -104,7 +105,7 @@ void l2c_bcst_msg( BT_HDR *p_buf, UINT16 psm ) bte_main_hci_send(p_buf, BT_EVT_TO_LM_HCI_ACL); } } - +#endif /******************************************************************************* ** @@ -294,7 +295,9 @@ void l2c_rcv_acl_data (BT_HDR *p_msg) /* we have received credits more than max coc credits, * so disconnecting the Le Coc Channel */ +#if (BLE_INCLUDED == TRUE) l2cble_send_peer_disc_req (p_ccb); +#endif ///BLE_INCLUDED == TRUE } else { p_ccb->peer_conn_cfg.credits += credit; l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, NULL); @@ -925,6 +928,7 @@ void l2c_process_timeout (TIMER_LIST_ENT *p_tle) l2c_info_timeout((tL2C_LCB *)p_tle->param); break; case BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS: { +#if (BLE_INCLUDED == TRUE) UINT8 status = HCI_ERR_HOST_TIMEOUT; tL2C_LCB *p_lcb = (tL2C_LCB *)p_tle->param; if (p_lcb){ @@ -932,6 +936,7 @@ void l2c_process_timeout (TIMER_LIST_ENT *p_tle) p_lcb->conn_update_mask &= ~L2C_BLE_UPDATE_PARAM_FULL; } l2c_send_update_conn_params_cb(p_lcb, status); +#endif ///BLE_INCLUDED == TRUE break; } } diff --git a/components/bt/bluedroid/stack/l2cap/l2c_ucd.c b/components/bt/bluedroid/stack/l2cap/l2c_ucd.c index 8618042c5b..2b130c3490 100644 --- a/components/bt/bluedroid/stack/l2cap/l2c_ucd.c +++ b/components/bt/bluedroid/stack/l2cap/l2c_ucd.c @@ -596,13 +596,13 @@ void l2c_ucd_delete_sec_pending_q(tL2C_LCB *p_lcb) { /* clean up any security pending UCD */ while (p_lcb->ucd_out_sec_pending_q.p_first) { - osi_free(fixed_queue_try_dequeue(p_lcb->ucd_out_sec_pending_q)); + osi_free(fixed_queue_dequeue(p_lcb->ucd_out_sec_pending_q, 0)); } fixed_queue_free(p_lcb->ucd_out_sec_pending_q, NULL); p_lcb->ucd_out_sec_pending_q = NULL; while (! fixed_queue_is_empty(p_lcb->ucd_in_sec_pending_q)) { - osi_free(fixed_queue_try_dequeue(p_lcb->ucd_in_sec_pending_q)); + osi_free(fixed_queue_dequeue(p_lcb->ucd_in_sec_pending_q, 0)); } fixed_queue_free(p_lcb->ucd_in_sec_pending_q); p_lcb->ucd_in_sec_pending_q = NULL; @@ -683,7 +683,7 @@ BOOLEAN l2c_ucd_check_pending_info_req(tL2C_CCB *p_ccb) *******************************************************************************/ void l2c_ucd_enqueue_pending_out_sec_q(tL2C_CCB *p_ccb, void *p_data) { - fixed_queue_enqueue(p_ccb->p_lcb->ucd_out_sec_pending_q, p_data); + fixed_queue_enqueue(p_ccb->p_lcb->ucd_out_sec_pending_q, p_data, FIXED_QUEUE_MAX_TIMEOUT); l2cu_check_channel_congestion (p_ccb); } @@ -727,7 +727,7 @@ BOOLEAN l2c_ucd_check_pending_out_sec_q(tL2C_CCB *p_ccb) *******************************************************************************/ void l2c_ucd_send_pending_out_sec_q(tL2C_CCB *p_ccb) { - BT_HDR *p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->p_lcb->ucd_out_sec_pending_q); + BT_HDR *p_buf = (BT_HDR*)fixed_queue_dequeue(p_ccb->p_lcb->ucd_out_sec_pending_q, 0); if (p_buf != NULL) { l2c_enqueue_peer_data (p_ccb, (BT_HDR *)p_buf); @@ -747,7 +747,7 @@ void l2c_ucd_send_pending_out_sec_q(tL2C_CCB *p_ccb) *******************************************************************************/ void l2c_ucd_discard_pending_out_sec_q(tL2C_CCB *p_ccb) { - BT_HDR *p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->p_lcb->ucd_out_sec_pending_q); + BT_HDR *p_buf = (BT_HDR*)fixed_queue_dequeue(p_ccb->p_lcb->ucd_out_sec_pending_q, 0); /* we may need to report to application */ @@ -767,7 +767,7 @@ void l2c_ucd_discard_pending_out_sec_q(tL2C_CCB *p_ccb) *******************************************************************************/ BOOLEAN l2c_ucd_check_pending_in_sec_q(tL2C_CCB *p_ccb) { - BT_HDR *p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->p_lcb->ucd_in_sec_pending_q); + BT_HDR *p_buf = (BT_HDR*)fixed_queue_dequeue(p_ccb->p_lcb->ucd_in_sec_pending_q, 0); if (p_buf != NULL) { UINT16 psm; @@ -795,7 +795,7 @@ BOOLEAN l2c_ucd_check_pending_in_sec_q(tL2C_CCB *p_ccb) *******************************************************************************/ void l2c_ucd_send_pending_in_sec_q(tL2C_CCB *p_ccb) { - BT_HDR *p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->p_lcb->ucd_in_sec_pending_q) + BT_HDR *p_buf = (BT_HDR*)fixed_queue_dequeue(p_ccb->p_lcb->ucd_in_sec_pending_q, 0) if (p_buf != NULL) { p_ccb->p_rcb->ucd.cb_info.pL2CA_UCD_Data_Cb(p_ccb->p_lcb->remote_bd_addr, (BT_HDR *)p_buf); @@ -814,7 +814,7 @@ void l2c_ucd_send_pending_in_sec_q(tL2C_CCB *p_ccb) *******************************************************************************/ void l2c_ucd_discard_pending_in_sec_q(tL2C_CCB *p_ccb) { - BT_HDR *p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->p_lcb->ucd_in_sec_pending_q); + BT_HDR *p_buf = (BT_HDR*)fixed_queue_dequeue(p_ccb->p_lcb->ucd_in_sec_pending_q, 0); if (p_buf) { osi_free (p_buf); @@ -898,7 +898,7 @@ BOOLEAN l2c_ucd_process_event(tL2C_CCB *p_ccb, UINT16 event, void *p_data) break; case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ - fixed_queue_enqueue(p_ccb->p_lcb->ucd_in_sec_pending_q, p_data); + fixed_queue_enqueue(p_ccb->p_lcb->ucd_in_sec_pending_q, p_data, FIXED_QUEUE_MAX_TIMEOUT); break; case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ @@ -958,7 +958,7 @@ BOOLEAN l2c_ucd_process_event(tL2C_CCB *p_ccb, UINT16 event, void *p_data) break; case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ - fixed_queue_enqueue(p_ccb->p_lcb->ucd_in_sec_pending_q, p_data); + fixed_queue_enqueue(p_ccb->p_lcb->ucd_in_sec_pending_q, p_data, FIXED_QUEUE_MAX_TIMEOUT); break; case L2CEVT_L2CAP_INFO_RSP: @@ -1006,7 +1006,7 @@ BOOLEAN l2c_ucd_process_event(tL2C_CCB *p_ccb, UINT16 event, void *p_data) break; case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ - fixed_queue_enqueue(p_ccb->p_lcb->ucd_in_sec_pending_q, p_data); + fixed_queue_enqueue(p_ccb->p_lcb->ucd_in_sec_pending_q, p_data, FIXED_QUEUE_MAX_TIMEOUT); break; case L2CEVT_SEC_RE_SEND_CMD: /* BTM has enough info to proceed */ @@ -1033,7 +1033,7 @@ BOOLEAN l2c_ucd_process_event(tL2C_CCB *p_ccb, UINT16 event, void *p_data) /* stop idle timer of UCD */ btu_stop_timer (&p_ccb->timer_entry); - fixed_queue_enqueue(p_ccb->p_lcb->ucd_in_sec_pending_q, p_data); + fixed_queue_enqueue(p_ccb->p_lcb->ucd_in_sec_pending_q, p_data, FIXED_QUEUE_MAX_TIMEOUT); l2c_ucd_check_pending_in_sec_q (p_ccb); break; diff --git a/components/bt/bluedroid/stack/l2cap/l2c_utils.c b/components/bt/bluedroid/stack/l2cap/l2c_utils.c index 4768d8808a..841e510a9a 100644 --- a/components/bt/bluedroid/stack/l2cap/l2c_utils.c +++ b/components/bt/bluedroid/stack/l2cap/l2c_utils.c @@ -243,12 +243,13 @@ void l2cu_release_lcb (tL2C_LCB *p_lcb) (*p_cb) (L2CAP_PING_RESULT_NO_LINK); } +#if (BLE_INCLUDED == TRUE) /* Check and release all the LE COC connections waiting for security */ if (p_lcb->le_sec_pending_q) { while (!fixed_queue_is_empty(p_lcb->le_sec_pending_q)) { - tL2CAP_SEC_DATA *p_buf = (tL2CAP_SEC_DATA*) fixed_queue_dequeue(p_lcb->le_sec_pending_q); + tL2CAP_SEC_DATA *p_buf = (tL2CAP_SEC_DATA*) fixed_queue_dequeue(p_lcb->le_sec_pending_q, FIXED_QUEUE_MAX_TIMEOUT); if (p_buf->p_callback) { p_buf->p_callback(p_lcb->remote_bd_addr, p_lcb->transport, p_buf->p_ref_data, BTM_DEV_RESET); } @@ -257,6 +258,7 @@ void l2cu_release_lcb (tL2C_LCB *p_lcb) fixed_queue_free(p_lcb->le_sec_pending_q, NULL); p_lcb->le_sec_pending_q = NULL; } +#endif ///BLE_INCLUDED == TRUE #if (C2H_FLOW_CONTROL_INCLUDED == TRUE) p_lcb->completed_packets = 0; @@ -928,7 +930,7 @@ void l2cu_send_peer_disc_req (tL2C_CCB *p_ccb) layer checks that all buffers are sent before disconnecting. */ if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_BASIC_MODE) { - while ((p_buf2 = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->xmit_hold_q)) != NULL) { + while ((p_buf2 = (BT_HDR *)fixed_queue_dequeue(p_ccb->xmit_hold_q, 0)) != NULL) { l2cu_set_acl_hci_header (p_buf2, p_ccb); l2c_link_check_send_pkts (p_ccb->p_lcb, p_ccb, p_buf2); } @@ -1765,6 +1767,7 @@ tL2C_RCB *l2cu_allocate_rcb (UINT16 psm) return (NULL); } +#if (BLE_INCLUDED == TRUE) /******************************************************************************* ** ** Function l2cu_allocate_ble_rcb @@ -1796,6 +1799,7 @@ tL2C_RCB *l2cu_allocate_ble_rcb (UINT16 psm) /* If here, no free RCB found */ return (NULL); } +#endif ///BLE_INCLUDED == TRUE /******************************************************************************* ** @@ -1867,6 +1871,7 @@ tL2C_RCB *l2cu_find_rcb_by_psm (UINT16 psm) return (NULL); } +#if (BLE_INCLUDED == TRUE) /******************************************************************************* ** ** Function l2cu_find_ble_rcb_by_psm @@ -1892,7 +1897,7 @@ tL2C_RCB *l2cu_find_ble_rcb_by_psm (UINT16 psm) /* If here, no match found */ return (NULL); } - +#endif ///BLE_INCLUDED == TRUE /******************************************************************************* @@ -3483,7 +3488,7 @@ BT_HDR *l2cu_get_next_buffer_to_send (tL2C_LCB *p_lcb) } else { if (!fixed_queue_is_empty(p_ccb->xmit_hold_q)) { - p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->xmit_hold_q); + p_buf = (BT_HDR *)fixed_queue_dequeue(p_ccb->xmit_hold_q, 0); if (NULL == p_buf) { L2CAP_TRACE_ERROR("l2cu_get_buffer_to_send: No data to be sent"); return (NULL); @@ -3520,7 +3525,7 @@ BT_HDR *l2cu_get_next_buffer_to_send (tL2C_LCB *p_lcb) } } else { - p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->xmit_hold_q); + p_buf = (BT_HDR *)fixed_queue_dequeue(p_ccb->xmit_hold_q, 0); if (NULL == p_buf) { L2CAP_TRACE_ERROR("l2cu_get_buffer_to_send() #2: No data to be sent"); return (NULL); diff --git a/components/bt/bluedroid/stack/rfcomm/port_api.c b/components/bt/bluedroid/stack/rfcomm/port_api.c index fd8246c53d..dacf544b9b 100644 --- a/components/bt/bluedroid/stack/rfcomm/port_api.c +++ b/components/bt/bluedroid/stack/rfcomm/port_api.c @@ -826,6 +826,8 @@ int PORT_FlowControl (UINT16 handle, BOOLEAN enable) } return (PORT_SUCCESS); } + +#if 0 //Unused /******************************************************************************* ** ** Function PORT_FlowControl_MaxCredit @@ -839,7 +841,6 @@ int PORT_FlowControl (UINT16 handle, BOOLEAN enable) ** enable - enables data flow ** *******************************************************************************/ - int PORT_FlowControl_MaxCredit (UINT16 handle, BOOLEAN enable) { tPORT *p_port; @@ -896,7 +897,7 @@ int PORT_FlowControl_MaxCredit (UINT16 handle, BOOLEAN enable) } return (PORT_SUCCESS); } - +#endif /******************************************************************************* ** @@ -1097,7 +1098,7 @@ int PORT_Purge (UINT16 handle, UINT8 purge_flags) count = fixed_queue_length(p_port->rx.queue); - while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_port->rx.queue)) != NULL) { + while ((p_buf = (BT_HDR *)fixed_queue_dequeue(p_port->rx.queue, 0)) != NULL) { osi_free (p_buf); } @@ -1114,7 +1115,7 @@ int PORT_Purge (UINT16 handle, UINT8 purge_flags) if (purge_flags & PORT_PURGE_TXCLEAR) { osi_mutex_global_lock(); /* to prevent tx.queue_size from being negative */ - while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_port->tx.queue)) != NULL) { + while ((p_buf = (BT_HDR *)fixed_queue_dequeue(p_port->tx.queue, 0)) != NULL) { osi_free (p_buf); } @@ -1217,7 +1218,7 @@ int PORT_ReadData (UINT16 handle, char *p_data, UINT16 max_len, UINT16 *p_len) p_data += p_buf->len; } - osi_free(fixed_queue_try_dequeue(p_port->rx.queue)); + osi_free(fixed_queue_dequeue(p_port->rx.queue, 0)); osi_mutex_global_unlock(); @@ -1273,7 +1274,7 @@ int PORT_Read (UINT16 handle, BT_HDR **pp_buf) osi_mutex_global_lock(); - p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_port->rx.queue); + p_buf = (BT_HDR *)fixed_queue_dequeue(p_port->rx.queue, 0); if (p_buf) { p_port->rx.queue_size -= p_buf->len; @@ -1339,7 +1340,7 @@ static int port_write (tPORT *p_port, BT_HDR *p_buf) p_port->rfc.state, p_port->port_ctrl); - fixed_queue_enqueue(p_port->tx.queue, p_buf); + fixed_queue_enqueue(p_port->tx.queue, p_buf, FIXED_QUEUE_MAX_TIMEOUT); p_port->tx.queue_size += p_buf->len; return (PORT_CMD_PENDING); @@ -1710,11 +1711,16 @@ int PORT_Test (UINT16 handle, UINT8 *p_data, UINT16 len) ** ** Description This function is called to initialize RFCOMM layer ** +** Returns status +** *******************************************************************************/ -void RFCOMM_Init (void) +bt_status_t RFCOMM_Init (void) { -#if (RFC_DYNAMIC_MEMORY) +#if RFC_DYNAMIC_MEMORY == TRUE rfc_cb_ptr = (tRFC_CB *)osi_malloc(sizeof(tRFC_CB)); + if (rfc_cb_ptr == NULL) { + return BT_STATUS_NOMEM; + } #endif /* #if (RFC_DYNAMIC_MEMORY) */ memset (&rfc_cb, 0, sizeof (tRFC_CB)); /* Init RFCOMM control block */ @@ -1727,6 +1733,27 @@ void RFCOMM_Init (void) #endif rfcomm_l2cap_if_init (); + return BT_STATUS_SUCCESS; +} + +/******************************************************************************* +** +** Function RFCOMM_Deinit +** +** Description This function is called to deinitialize the control block +** for this layer. +** +** Returns void +** +*******************************************************************************/ +void RFCOMM_Deinit(void) +{ +#if RFC_DYNAMIC_MEMORY == TRUE + if (rfc_cb_ptr){ + osi_free(rfc_cb_ptr); + rfc_cb_ptr = NULL; + } +#endif } /******************************************************************************* diff --git a/components/bt/bluedroid/stack/rfcomm/port_rfc.c b/components/bt/bluedroid/stack/rfcomm/port_rfc.c index 46b3e07116..4a47fb46ca 100644 --- a/components/bt/bluedroid/stack/rfcomm/port_rfc.c +++ b/components/bt/bluedroid/stack/rfcomm/port_rfc.c @@ -869,7 +869,7 @@ void PORT_DataInd (tRFC_MCB *p_mcb, UINT8 dlci, BT_HDR *p_buf) osi_mutex_global_lock(); - fixed_queue_enqueue(p_port->rx.queue, p_buf); + fixed_queue_enqueue(p_port->rx.queue, p_buf, FIXED_QUEUE_MAX_TIMEOUT); p_port->rx.queue_size += p_buf->len; osi_mutex_global_unlock(); @@ -976,7 +976,7 @@ UINT32 port_rfc_send_tx_data (tPORT *p_port) /* get data from tx queue and send it */ osi_mutex_global_lock(); - if ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_port->tx.queue)) != NULL) { + if ((p_buf = (BT_HDR *)fixed_queue_dequeue(p_port->tx.queue, 0)) != NULL) { p_port->tx.queue_size -= p_buf->len; osi_mutex_global_unlock(); diff --git a/components/bt/bluedroid/stack/rfcomm/port_utils.c b/components/bt/bluedroid/stack/rfcomm/port_utils.c index 0da8b3d76b..0b08c0f1f3 100644 --- a/components/bt/bluedroid/stack/rfcomm/port_utils.c +++ b/components/bt/bluedroid/stack/rfcomm/port_utils.c @@ -210,13 +210,13 @@ void port_release_port (tPORT *p_port) osi_mutex_global_lock(); RFCOMM_TRACE_DEBUG("port_release_port, p_port:%p", p_port); - while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_port->rx.queue)) != NULL) { + while ((p_buf = (BT_HDR *)fixed_queue_dequeue(p_port->rx.queue, 0)) != NULL) { osi_free (p_buf); } p_port->rx.queue_size = 0; - while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_port->tx.queue)) != NULL) { + while ((p_buf = (BT_HDR *)fixed_queue_dequeue(p_port->tx.queue, 0)) != NULL) { osi_free (p_buf); } diff --git a/components/bt/bluedroid/stack/rfcomm/rfc_mx_fsm.c b/components/bt/bluedroid/stack/rfcomm/rfc_mx_fsm.c index 6d1bf3c93a..dd2af3b803 100644 --- a/components/bt/bluedroid/stack/rfcomm/rfc_mx_fsm.c +++ b/components/bt/bluedroid/stack/rfcomm/rfc_mx_fsm.c @@ -488,7 +488,7 @@ void rfc_mx_sm_state_disc_wait_ua (tRFC_MCB *p_mcb, UINT16 event, void *p_data) rfc_save_lcid_mcb (p_mcb, p_mcb->lcid); /* clean up before reuse it */ - while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_mcb->cmd_q)) != NULL) { + while ((p_buf = (BT_HDR *)fixed_queue_dequeue(p_mcb->cmd_q, 0)) != NULL) { osi_free(p_buf); } diff --git a/components/bt/bluedroid/stack/rfcomm/rfc_utils.c b/components/bt/bluedroid/stack/rfcomm/rfc_utils.c index 8b1e043116..0d1fbdcb39 100644 --- a/components/bt/bluedroid/stack/rfcomm/rfc_utils.c +++ b/components/bt/bluedroid/stack/rfcomm/rfc_utils.c @@ -492,12 +492,12 @@ void rfc_check_send_cmd(tRFC_MCB *p_mcb, BT_HDR *p_buf) __func__, p_mcb, p_mcb->lcid, rfc_find_lcid_mcb(p_mcb->lcid)); } - fixed_queue_enqueue(p_mcb->cmd_q, p_buf); + fixed_queue_enqueue(p_mcb->cmd_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT); } /* handle queue if L2CAP not congested */ while (p_mcb->l2cap_congested == FALSE) { - if ((p = (BT_HDR *)fixed_queue_try_dequeue(p_mcb->cmd_q)) == NULL) { + if ((p = (BT_HDR *)fixed_queue_dequeue(p_mcb->cmd_q, 0)) == NULL) { break; } diff --git a/components/bt/bluedroid/stack/smp/include/p_256_ecc_pp.h b/components/bt/bluedroid/stack/smp/include/p_256_ecc_pp.h index f91d6056b2..172dd24f10 100644 --- a/components/bt/bluedroid/stack/smp/include/p_256_ecc_pp.h +++ b/components/bt/bluedroid/stack/smp/include/p_256_ecc_pp.h @@ -25,6 +25,7 @@ #pragma once #include "p_256_multprecision.h" +#include "common/bt_target.h" typedef unsigned long DWORD; @@ -53,8 +54,16 @@ typedef struct { } elliptic_curve_t; +#if SMP_DYNAMIC_MEMORY == FALSE extern elliptic_curve_t curve; extern elliptic_curve_t curve_p256; +#else +extern elliptic_curve_t *curve_ptr; +extern elliptic_curve_t *curve_p256_ptr; +#define curve (*curve_ptr) +#define curve_p256 (*curve_p256_ptr) +#endif + void ECC_PointMult_Bin_NAF(Point *q, Point *p, DWORD *n, uint32_t keyLength); diff --git a/components/bt/bluedroid/stack/smp/include/smp_int.h b/components/bt/bluedroid/stack/smp/include/smp_int.h index a261e14cba..d8fb55c381 100644 --- a/components/bt/bluedroid/stack/smp/include/smp_int.h +++ b/components/bt/bluedroid/stack/smp/include/smp_int.h @@ -24,7 +24,7 @@ #ifndef SMP_INT_H #define SMP_INT_H -#if (BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE) +// #if (SMP_INCLUDED == TRUE) #include "stack/btu.h" #include "stack/btm_ble_api.h" @@ -479,7 +479,7 @@ extern void smp_proc_pairing_cmpl(tSMP_CB *p_cb); extern void smp_convert_string_to_tk(BT_OCTET16 tk, UINT32 passkey); extern void smp_mask_enc_key(UINT8 loc_enc_size, UINT8 *p_data); extern void smp_rsp_timeout(TIMER_LIST_ENT *p_tle); -extern void smp_xor_128(BT_OCTET16 a, BT_OCTET16 b); +extern void smp_xor_128(BT_OCTET16 a, const BT_OCTET16 b); extern BOOLEAN smp_encrypt_data (UINT8 *key, UINT8 key_len, UINT8 *plain_text, UINT8 pt_len, tSMP_ENC *p_out); @@ -537,6 +537,6 @@ extern BOOLEAN aes_cipher_msg_auth_code(BT_OCTET16 key, UINT8 *input, UINT16 len UINT16 tlen, UINT8 *p_signature); extern void print128(BT_OCTET16 x, const UINT8 *key_name); -#endif ///BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE +// #endif ///BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE #endif /* SMP_INT_H */ diff --git a/components/bt/bluedroid/stack/smp/p_256_ecc_pp.c b/components/bt/bluedroid/stack/smp/p_256_ecc_pp.c index 0f7ab3ec41..aceb0b209a 100644 --- a/components/bt/bluedroid/stack/smp/p_256_ecc_pp.c +++ b/components/bt/bluedroid/stack/smp/p_256_ecc_pp.c @@ -26,9 +26,15 @@ #include #include "p_256_ecc_pp.h" #include "p_256_multprecision.h" +#include "common/bt_target.h" +#if SMP_DYNAMIC_MEMORY == FALSE elliptic_curve_t curve; elliptic_curve_t curve_p256; +#else +elliptic_curve_t *curve_ptr; +elliptic_curve_t *curve_p256_ptr; +#endif static void p_256_init_point(Point *q) { @@ -248,7 +254,7 @@ bool ECC_CheckPointIsInElliCur_P256(Point *p) DWORD x_x_q[KEY_LENGTH_DWORDS_P256] = {0x0}; /* x % q */ DWORD x_q[KEY_LENGTH_DWORDS_P256] = {0x0}; - /* x^2, To prevent overflow, the length of the x square here needs to + /* x^2, To prevent overflow, the length of the x square here needs to be expanded to two times the original one. */ DWORD x_x[2*KEY_LENGTH_DWORDS_P256] = {0x0}; /* y_y_q =(p->y)^2(mod q) */ @@ -259,7 +265,7 @@ bool ECC_CheckPointIsInElliCur_P256(Point *p) y^2 = (x^2 - 3)*x + b (mod q), so we calculate the x^2 - 3 value here */ x_x[0] -= 3; - /* Using math relations. (a*b) % q = ((a%q)*(b%q)) % q ==> + /* Using math relations. (a*b) % q = ((a%q)*(b%q)) % q ==> (x^2 - 3)*x = (((x^2 - 3) % q) * x % q) % q */ multiprecision_fast_mod_P256(x_x_q, x_x); /* x_x = x_x_q * x_q */ diff --git a/components/bt/bluedroid/stack/smp/smp_act.c b/components/bt/bluedroid/stack/smp/smp_act.c index d11506e650..487dadf62c 100644 --- a/components/bt/bluedroid/stack/smp/smp_act.c +++ b/components/bt/bluedroid/stack/smp/smp_act.c @@ -46,10 +46,17 @@ const UINT8 smp_association_table[2][SMP_IO_CAP_MAX][SMP_IO_CAP_MAX] = { #define SMP_KEY_DIST_TYPE_MAX 4 const tSMP_ACT smp_distribute_act [] = { +#if (BLE_INCLUDED == TRUE) smp_generate_ltk, smp_send_id_info, smp_generate_csrk, smp_set_derive_link_key +#else + NULL, + NULL, + NULL, + NULL +#endif ///BLE_INCLUDED == TRUE }; extern UINT8 bta_dm_co_ble_get_accept_auth_enable(void); @@ -191,7 +198,7 @@ void smp_send_app_cback(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) smp_sm_event(p_cb, SMP_IO_RSP_EVT, NULL); break; - +#if (CLASSIC_BT_INCLUDED == TRUE) case SMP_BR_KEYS_REQ_EVT: p_cb->loc_enc_size = cb_data.io_req.max_key_size; p_cb->local_i_key = cb_data.io_req.init_keys; @@ -206,6 +213,7 @@ void smp_send_app_cback(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) smp_br_state_machine_event(p_cb, SMP_BR_KEYS_RSP_EVT, NULL); break; +#endif ///CLASSIC_BT_INCLUDED == TRUE } } } @@ -241,13 +249,15 @@ void smp_send_pair_fail(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) *******************************************************************************/ void smp_send_pair_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) { - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (p_cb->pairing_bda); SMP_TRACE_DEBUG("%s\n", __func__); +#if (BLE_INCLUDED == TRUE) + tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (p_cb->pairing_bda); /* erase all keys when master sends pairing req*/ if (p_dev_rec) { btm_sec_clear_ble_keys(p_dev_rec); } +#endif ///BLE_INCLUDED == TRUE /* do not manipulate the key, let app decide, leave out to BTM to mandate key distribution for bonding case */ smp_send_cmd(SMP_OPCODE_PAIRING_REQ, p_cb); @@ -261,6 +271,7 @@ void smp_send_pair_rsp(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) { SMP_TRACE_DEBUG("%s\n", __func__); +#if (BLE_INCLUDED == TRUE) p_cb->local_i_key &= p_cb->peer_i_key; p_cb->local_r_key &= p_cb->peer_r_key; @@ -271,6 +282,7 @@ void smp_send_pair_rsp(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) smp_decide_association_model(p_cb, NULL); } } +#endif ///BLE_INCLUDED == TRUE } /******************************************************************************* @@ -283,6 +295,7 @@ void smp_send_confirm(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) smp_send_cmd(SMP_OPCODE_CONFIRM, p_cb); } +#if 0 //Unused /******************************************************************************* ** Function smp_send_init ** Description process pairing initializer to slave device @@ -292,6 +305,7 @@ void smp_send_init(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) SMP_TRACE_DEBUG("%s\n", __func__); smp_send_cmd(SMP_OPCODE_INIT, p_cb); } +#endif /******************************************************************************* ** Function smp_send_rand @@ -363,6 +377,7 @@ void smp_send_enc_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) le_key.key_size = p_cb->loc_enc_size; le_key.sec_level = p_cb->sec_level; +#if (BLE_INCLUDED == TRUE) if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && (p_cb->loc_auth_req & SMP_AUTH_BOND)) { btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LENC, (tBTM_LE_KEY_VALUE *)&le_key, TRUE); @@ -371,6 +386,7 @@ void smp_send_enc_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) SMP_TRACE_DEBUG ("%s\n", __func__); smp_key_distribution(p_cb, NULL); +#endif ///BLE_INCLUDED == TRUE } /******************************************************************************* @@ -379,21 +395,24 @@ void smp_send_enc_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) *******************************************************************************/ void smp_send_id_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) { - tBTM_LE_KEY_VALUE le_key; SMP_TRACE_DEBUG("%s\n", __func__); smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ID, FALSE); smp_send_cmd(SMP_OPCODE_IDENTITY_INFO, p_cb); smp_send_cmd(SMP_OPCODE_ID_ADDR, p_cb); +#if (BLE_INCLUDED == TRUE) + tBTM_LE_KEY_VALUE le_key; if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && (p_cb->loc_auth_req & SMP_AUTH_BOND)) { btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LID, &le_key, TRUE); } +#endif ///BLE_INCLUDED == TRUE smp_key_distribution_by_transport(p_cb, NULL); } +#if (BLE_INCLUDED == TRUE) /******************************************************************************* ** Function smp_send_csrk_info ** Description send CSRK command. @@ -439,7 +458,6 @@ void smp_proc_sec_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) SMP_TRACE_DEBUG("%s auth_req=0x%x", __func__, auth_req); p_cb->cb_evt = 0; - btm_ble_link_sec_check(p_cb->pairing_bda, auth_req, &sec_req_act); SMP_TRACE_DEBUG("%s sec_req_act=0x%x", __func__, sec_req_act); @@ -476,6 +494,7 @@ void smp_proc_sec_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) break; } } +#endif ///BLE_INCLUDED == TRUE /******************************************************************************* ** Function smp_proc_sec_grant @@ -530,6 +549,7 @@ uint16_t smp_get_auth_mode (tSMP_ASSO_MODEL model) return auth; } +#if (BLE_INCLUDED == TRUE) /******************************************************************************* ** Function smp_proc_pair_cmd ** Description Process the SMP pairing request/response from peer device @@ -650,6 +670,7 @@ void smp_proc_pair_cmd(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) } } } +#endif ///BLE_INCLUDED == TRUE /******************************************************************************* ** Function smp_proc_confirm @@ -675,6 +696,7 @@ void smp_proc_confirm(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) p_cb->flags |= SMP_PAIR_FLAGS_CMD_CONFIRM; } +#if 0 //Unused /******************************************************************************* ** Function smp_proc_init ** Description process pairing initializer from peer device @@ -694,6 +716,7 @@ void smp_proc_init(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) /* save the SRand for comparison */ STREAM_TO_ARRAY(p_cb->rrand, p, BT_OCTET16_LEN); } +#endif /******************************************************************************* ** Function smp_proc_rand @@ -819,6 +842,7 @@ void smp_process_keypress_notification(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) p_cb->cb_evt = SMP_PEER_KEYPR_NOT_EVT; } +#if (CLASSIC_BT_INCLUDED == TRUE) /******************************************************************************* ** Function smp_br_process_pairing_command ** Description Process the SMP pairing request/response from peer device via @@ -838,10 +862,12 @@ void smp_br_process_pairing_command(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) return; } +#if (BLE_INCLUDED == TRUE) /* erase all keys if it is slave proc pairing req*/ if (p_dev_rec && (p_cb->role == HCI_ROLE_SLAVE)) { btm_sec_clear_ble_keys(p_dev_rec); } +#endif ///BLE_INCLUDED == TRUE p_cb->flags |= SMP_PAIR_FLAG_ENC_AFTER_PAIR; @@ -962,7 +988,9 @@ void smp_br_select_next_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) } } } +#endif ///CLASSIC_BT_INCLUDED == TRUE +#if (BLE_INCLUDED == TRUE) /******************************************************************************* ** Function smp_proc_enc_info ** Description process encryption information from peer device @@ -976,6 +1004,8 @@ void smp_proc_enc_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) smp_key_distribution(p_cb, NULL); } +#endif ///BLE_INCLUDED == TRUE + /******************************************************************************* ** Function smp_proc_master_id ** Description process master ID from slave device @@ -997,6 +1027,7 @@ void smp_proc_master_id(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) le_key.sec_level = p_cb->sec_level; le_key.key_size = p_cb->loc_enc_size; +#if (BLE_INCLUDED == TRUE) if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && (p_cb->loc_auth_req & SMP_AUTH_BOND)) { btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_PENC, @@ -1004,6 +1035,7 @@ void smp_proc_master_id(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) } smp_key_distribution(p_cb, NULL); +#endif ///BLE_INCLUDED == TRUE } /******************************************************************************* @@ -1040,11 +1072,14 @@ void smp_proc_id_addr(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) p_cb->id_addr_type = pid_key.addr_type; memcpy(p_cb->id_addr, pid_key.static_addr, BD_ADDR_LEN); +#if (BLE_INCLUDED == TRUE) /* store the ID key from peer device */ if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && (p_cb->loc_auth_req & SMP_AUTH_BOND)) { btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_PID, (tBTM_LE_KEY_VALUE *)&pid_key, TRUE); } +#endif ///BLE_INCLUDED == TRUE + smp_key_distribution_by_transport(p_cb, NULL); } @@ -1054,6 +1089,7 @@ void smp_proc_id_addr(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) *******************************************************************************/ void smp_proc_srk_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) { +#if (BLE_INCLUDED == TRUE) tBTM_LE_PCSRK_KEYS le_key; SMP_TRACE_DEBUG("%s", __func__); @@ -1069,6 +1105,8 @@ void smp_proc_srk_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) BTM_LE_KEY_PCSRK, (tBTM_LE_KEY_VALUE *)&le_key, TRUE); } + +#endif ///BLE_INCLUDED == TRUE smp_key_distribution_by_transport(p_cb, NULL); } @@ -1103,6 +1141,7 @@ void smp_proc_compare(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) } } +#if (BLE_INCLUDED == TRUE) /******************************************************************************* ** Function smp_proc_sl_key ** Description process key ready events. @@ -1143,6 +1182,7 @@ void smp_start_enc(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); } } +#endif ///BLE_INCLUDED == TRUE /******************************************************************************* ** Function smp_proc_discard @@ -1242,7 +1282,7 @@ void smp_key_pick_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) while (i < SMP_KEY_DIST_TYPE_MAX) { SMP_TRACE_DEBUG("key to send = %02x, i = %d\n", key_to_dist, i); - if (key_to_dist & (1 << i)) { + if (key_to_dist & (1 << i) && smp_distribute_act[i] != NULL) { SMP_TRACE_DEBUG("smp_distribute_act[%d]\n", i); (* smp_distribute_act[i])(p_cb, p_data); break; @@ -1250,6 +1290,8 @@ void smp_key_pick_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) i ++; } } + +#if (BLE_INCLUDED == TRUE) /******************************************************************************* ** Function smp_key_distribution ** Description start key distribution if required. @@ -1413,6 +1455,7 @@ void smp_process_io_response(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) smp_send_pair_rsp(p_cb, NULL); } } +#endif ///BLE_INCLUDED == TRUE /******************************************************************************* ** Function smp_br_process_slave_keys_response @@ -1477,6 +1520,7 @@ void smp_idle_terminate(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) } } +#if (BLE_INCLUDED == TRUE) /******************************************************************************* ** Function smp_fast_conn_param ** Description apply default connection parameter for pairing process @@ -1702,6 +1746,7 @@ void smp_process_peer_nonce(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) SMP_TRACE_DEBUG("%s end\n ", __FUNCTION__); } +#endif ///BLE_INCLUDED == TRUE /******************************************************************************* ** Function smp_match_dhkey_checks @@ -1789,6 +1834,7 @@ void smp_wait_for_both_public_keys(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) } } +#if (BLE_INCLUDED == TRUE) /******************************************************************************* ** Function smp_start_passkey_verification ** Description Starts SC passkey entry verification. @@ -2055,7 +2101,9 @@ void smp_derive_link_key_from_long_term_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data return; } } +#endif ///BLE_INCLUDED == TRUE +#if (CLASSIC_BT_INCLUDED == TRUE) /******************************************************************************* ** ** Function smp_br_process_link_key @@ -2083,6 +2131,7 @@ void smp_br_process_link_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ENC, FALSE); smp_br_select_next_key(p_cb, NULL); } +#endif ///CLASSIC_BT_INCLUDED == TRUE /******************************************************************************* ** Function smp_key_distribution_by_transport @@ -2093,9 +2142,13 @@ void smp_key_distribution_by_transport(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) { SMP_TRACE_DEBUG("%s\n", __func__); if (p_cb->smp_over_br) { +#if (CLASSIC_BT_INCLUDED == TRUE) smp_br_select_next_key(p_cb, NULL); +#endif ///CLASSIC_BT_INCLUDED == TRUE } else { +#if (BLE_INCLUDED == TRUE) smp_key_distribution(p_cb, NULL); +#endif ///BLE_INCLUDED == TRUE } } diff --git a/components/bt/bluedroid/stack/smp/smp_api.c b/components/bt/bluedroid/stack/smp/smp_api.c index 8c3c3d8bc7..89a32308e5 100644 --- a/components/bt/bluedroid/stack/smp/smp_api.c +++ b/components/bt/bluedroid/stack/smp/smp_api.c @@ -51,8 +51,12 @@ void SMP_Init(void) { #if SMP_DYNAMIC_MEMORY smp_cb_ptr = (tSMP_CB *)osi_malloc(sizeof(tSMP_CB)); + curve_ptr = (elliptic_curve_t *)osi_malloc(sizeof(elliptic_curve_t)); + curve_p256_ptr = (elliptic_curve_t *)osi_malloc(sizeof(elliptic_curve_t)); #endif memset(&smp_cb, 0, sizeof(tSMP_CB)); + memset(&curve, 0, sizeof(elliptic_curve_t)); + memset(&curve_p256, 0, sizeof(elliptic_curve_t)); #if defined(SMP_INITIAL_TRACE_LEVEL) smp_cb.trace_level = SMP_INITIAL_TRACE_LEVEL; @@ -71,6 +75,8 @@ void SMP_Free(void) memset(&smp_cb, 0, sizeof(tSMP_CB)); #if SMP_DYNAMIC_MEMORY FREE_AND_RESET(smp_cb_ptr); + FREE_AND_RESET(curve_ptr); + FREE_AND_RESET(curve_p256_ptr); #endif /* #if SMP_DYNAMIC_MEMORY */ } @@ -177,6 +183,7 @@ tSMP_STATUS SMP_Pair (BD_ADDR bd_addr) ** Returns SMP_STARTED if pairing started, otherwise reason for failure. ** *******************************************************************************/ +#if (CLASSIC_BT_INCLUDED == TRUE) tSMP_STATUS SMP_BR_PairWith (BD_ADDR bd_addr) { tSMP_CB *p_cb = &smp_cb; @@ -206,6 +213,7 @@ tSMP_STATUS SMP_BR_PairWith (BD_ADDR bd_addr) return SMP_STARTED; } +#endif ///CLASSIC_BT_INCLUDED == TRUE /******************************************************************************* ** @@ -252,6 +260,7 @@ void SMP_SecurityGrant(BD_ADDR bd_addr, UINT8 res) { SMP_TRACE_EVENT ("SMP_SecurityGrant "); +#if (CLASSIC_BT_INCLUDED == TRUE) if (smp_cb.smp_over_br) { if (smp_cb.br_state != SMP_BR_STATE_WAIT_APP_RSP || smp_cb.cb_evt != SMP_SEC_REQUEST_EVT || @@ -265,6 +274,7 @@ void SMP_SecurityGrant(BD_ADDR bd_addr, UINT8 res) smp_br_state_machine_event(&smp_cb, SMP_BR_API_SEC_GRANT_EVT, &res); return; } +#endif ///CLASSIC_BT_INCLUDED == TRUE if (smp_cb.state != SMP_STATE_WAIT_APP_RSP || smp_cb.cb_evt != SMP_SEC_REQUEST_EVT || diff --git a/components/bt/bluedroid/stack/smp/smp_br_main.c b/components/bt/bluedroid/stack/smp/smp_br_main.c index ba2eb97456..5ef7a7c694 100644 --- a/components/bt/bluedroid/stack/smp/smp_br_main.c +++ b/components/bt/bluedroid/stack/smp/smp_br_main.c @@ -21,7 +21,7 @@ #include #include "smp_int.h" -#if (BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE) +#if ( CLASSIC_BT_INCLUDED== TRUE && SMP_INCLUDED == TRUE) const char *const smp_br_state_name [SMP_BR_STATE_MAX + 1] = { "SMP_BR_STATE_IDLE", diff --git a/components/bt/bluedroid/stack/smp/smp_cmac.c b/components/bt/bluedroid/stack/smp/smp_cmac.c index 753c5188f2..0e7bab02c1 100644 --- a/components/bt/bluedroid/stack/smp/smp_cmac.c +++ b/components/bt/bluedroid/stack/smp/smp_cmac.c @@ -42,7 +42,7 @@ typedef struct { tCMAC_CB cmac_cb; /* Rb for AES-128 as block cipher, LSB as [0] */ -BT_OCTET16 const_Rb = { +const BT_OCTET16 const_Rb = { 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/components/bt/bluedroid/stack/smp/smp_keys.c b/components/bt/bluedroid/stack/smp/smp_keys.c index 4c523787c1..4c39635d9f 100644 --- a/components/bt/bluedroid/stack/smp/smp_keys.c +++ b/components/bt/bluedroid/stack/smp/smp_keys.c @@ -23,7 +23,7 @@ ******************************************************************************/ #include "common/bt_target.h" -#if SMP_INCLUDED == TRUE +#if (BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE) #if SMP_DEBUG == TRUE #include #endif @@ -93,6 +93,7 @@ void smp_debug_print_nbyte_little_endian(UINT8 *p, const UINT8 *key_name, UINT8 #endif } +#if 0 //Unused void smp_debug_print_nbyte_big_endian (UINT8 *p, const UINT8 *key_name, UINT8 len) { #if SMP_DEBUG == TRUE @@ -115,6 +116,7 @@ void smp_debug_print_nbyte_big_endian (UINT8 *p, const UINT8 *key_name, UINT8 le } #endif } +#endif /******************************************************************************* ** @@ -378,10 +380,13 @@ void smp_generate_ltk(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) BOOLEAN div_status; SMP_TRACE_DEBUG ("%s\n", __FUNCTION__); +#if (CLASSIC_BT_INCLUDED == TRUE) if (smp_get_br_state() == SMP_BR_STATE_BOND_PENDING) { smp_br_process_link_key(p_cb, NULL); return; - } else if (p_cb->le_secure_connections_mode_is_used) { + } +#endif ///CLASSIC_BT_INCLUDED == TRUE + if (p_cb->le_secure_connections_mode_is_used) { smp_process_secure_connection_long_term_key(); return; } @@ -430,7 +435,9 @@ void smp_compute_csrk(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) if (!SMP_Encrypt(er, BT_OCTET16_LEN, buffer, 4, &output)) { SMP_TRACE_ERROR("smp_generate_csrk failed\n"); if (p_cb->smp_over_br) { +#if (CLASSIC_BT_INCLUDED == TRUE) smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &status); +#endif ///CLASSIC_BT_INCLUDED == TRUE } else { smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status); } diff --git a/components/bt/bluedroid/stack/smp/smp_l2c.c b/components/bt/bluedroid/stack/smp/smp_l2c.c index a3ac356aca..67dd1ac5ae 100644 --- a/components/bt/bluedroid/stack/smp/smp_l2c.c +++ b/components/bt/bluedroid/stack/smp/smp_l2c.c @@ -35,10 +35,12 @@ static void smp_tx_complete_callback(UINT16 cid, UINT16 num_pkt); +#if (BLE_INCLUDED == TRUE) static void smp_connect_callback(UINT16 channel, BD_ADDR bd_addr, BOOLEAN connected, UINT16 reason, tBT_TRANSPORT transport); static void smp_data_received(UINT16 channel, BD_ADDR bd_addr, BT_HDR *p_buf); +#endif ///BLE_INCLUDED == TRUE #if (CLASSIC_BT_INCLUDED == TRUE) static void smp_br_connect_callback(UINT16 channel, BD_ADDR bd_addr, BOOLEAN connected, UINT16 reason, tBT_TRANSPORT transport); @@ -64,8 +66,6 @@ void smp_l2cap_if_init (void) fixed_reg.fixed_chnl_opts.mps = 0; fixed_reg.fixed_chnl_opts.tx_win_sz = 0; - fixed_reg.pL2CA_FixedConn_Cb = smp_connect_callback; - fixed_reg.pL2CA_FixedData_Cb = smp_data_received; fixed_reg.pL2CA_FixedTxComplete_Cb = smp_tx_complete_callback; fixed_reg.pL2CA_FixedCong_Cb = NULL; /* do not handle congestion on this channel */ @@ -75,7 +75,12 @@ void smp_l2cap_if_init (void) will cause the disconnect event to go back up for a long time. Set to 0 will be disconnected directly, and it will come up pairing failure, so it will not cause adverse effects. */ +#if (BLE_INCLUDED == TRUE) + fixed_reg.pL2CA_FixedConn_Cb = smp_connect_callback; + fixed_reg.pL2CA_FixedData_Cb = smp_data_received; L2CA_RegisterFixedChannel (L2CAP_SMP_CID, &fixed_reg); +#endif ///BLE_INCLUDED == TRUE + #if (CLASSIC_BT_INCLUDED == TRUE) fixed_reg.pL2CA_FixedConn_Cb = smp_br_connect_callback; fixed_reg.pL2CA_FixedData_Cb = smp_br_data_received; @@ -84,6 +89,7 @@ void smp_l2cap_if_init (void) #endif ///CLASSIC_BT_INCLUDED == TRUE } +#if (BLE_INCLUDED == TRUE) /******************************************************************************* ** ** Function smp_connect_callback @@ -107,7 +113,7 @@ static void smp_connect_callback (UINT16 channel, BD_ADDR bd_addr, BOOLEAN conne } if(!connected && &p_cb->rsp_timer_ent) { //free timer - btu_free_timer(&p_cb->rsp_timer_ent); + btu_free_timer(&p_cb->rsp_timer_ent); } if (memcmp(bd_addr, p_cb->pairing_bda, BD_ADDR_LEN) == 0) { SMP_TRACE_EVENT ("%s() for pairing BDA: %08x%04x Event: %s\n", @@ -200,6 +206,7 @@ static void smp_data_received(UINT16 channel, BD_ADDR bd_addr, BT_HDR *p_buf) osi_free (p_buf); } +#endif ///BLE_INCLUDED == TRUE /******************************************************************************* ** @@ -223,7 +230,9 @@ static void smp_tx_complete_callback (UINT16 cid, UINT16 num_pkt) if (cid == L2CAP_SMP_CID) { smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); } else { +#if (CLASSIC_BT_INCLUDED == TRUE) smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &reason); +#endif ///CLASSIC_BT_INCLUDED == TRUE } } } diff --git a/components/bt/bluedroid/stack/smp/smp_main.c b/components/bt/bluedroid/stack/smp/smp_main.c index 0880fe910f..1becb36f01 100644 --- a/components/bt/bluedroid/stack/smp/smp_main.c +++ b/components/bt/bluedroid/stack/smp/smp_main.c @@ -163,7 +163,8 @@ enum { SMP_SM_NO_ACTION }; -static const tSMP_ACT smp_sm_action[] = { +#if (BLE_INCLUDED == TRUE) +static const tSMP_ACT smp_sm_action[SMP_SM_NO_ACTION] = { smp_proc_sec_req, smp_send_pair_req, smp_send_pair_rsp, @@ -226,6 +227,9 @@ static const tSMP_ACT smp_sm_action[] = { smp_idle_terminate, smp_fast_conn_param }; +#else +static const tSMP_ACT smp_sm_action[SMP_SM_NO_ACTION] = {NULL}; +#endif ///BLE_INCLUDED == TRUE /************ SMP Master FSM State/Event Indirection Table **************/ static const UINT8 smp_master_entry_map[][SMP_STATE_MAX] = { @@ -766,7 +770,7 @@ void smp_sm_event(tSMP_CB *p_cb, tSMP_EVENT event, void *p_data) /* execute action */ /* execute action functions */ for (i = 0; i < SMP_NUM_ACTIONS; i++) { - if ((action = state_table[entry - 1][i]) != SMP_SM_NO_ACTION) { + if ((action = state_table[entry - 1][i]) != SMP_SM_NO_ACTION && smp_sm_action[action] != NULL) { (*smp_sm_action[action])(p_cb, (tSMP_INT_DATA *)p_data); } else { break; diff --git a/components/bt/bluedroid/stack/smp/smp_utils.c b/components/bt/bluedroid/stack/smp/smp_utils.c index 19c2cde99b..165b11a2a3 100644 --- a/components/bt/bluedroid/stack/smp/smp_utils.c +++ b/components/bt/bluedroid/stack/smp/smp_utils.c @@ -367,7 +367,9 @@ BOOLEAN smp_send_cmd(UINT8 cmd_code, tSMP_CB *p_cb) if (!sent) { if (p_cb->smp_over_br) { +#if (CLASSIC_BT_INCLUDED == TRUE) smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &failure); +#endif ///CLASSIC_BT_INCLUDED == TRUE } else { smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure); } @@ -393,7 +395,9 @@ void smp_rsp_timeout(TIMER_LIST_ENT *p_tle) SMP_TRACE_EVENT("%s state:%d br_state:%d", __FUNCTION__, p_cb->state, p_cb->br_state); if (p_cb->smp_over_br) { +#if (CLASSIC_BT_INCLUDED == TRUE) smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &failure); +#endif ///CLASSIC_BT_INCLUDED == TRUE } else { smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure); } @@ -550,6 +554,7 @@ static BT_HDR *smp_build_master_id_cmd(UINT8 cmd_code, tSMP_CB *p_cb) static BT_HDR *smp_build_identity_info_cmd(UINT8 cmd_code, tSMP_CB *p_cb) { BT_HDR *p_buf = NULL ; +#if (BLE_INCLUDED == TRUE) UINT8 *p; BT_OCTET16 irk; UNUSED(cmd_code); @@ -568,6 +573,7 @@ static BT_HDR *smp_build_identity_info_cmd(UINT8 cmd_code, tSMP_CB *p_cb) p_buf->len = SMP_ID_INFO_SIZE; } +#endif ///BLE_INCLUDED == TRUE return p_buf; } @@ -590,13 +596,16 @@ static BT_HDR *smp_build_id_addr_cmd(UINT8 cmd_code, tSMP_CB *p_cb) p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET; UINT8_TO_STREAM (p, SMP_OPCODE_ID_ADDR); - /* Identity Address Information is used in the Transport Specific Key Distribution phase to distribute + /* Identity Address Information is used in the Transport Specific Key Distribution phase to distribute its public device address or static random address. if slave using static random address is encrypted, it should distribute its static random address */ +#if (BLE_INCLUDED == TRUE) if(btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type == BLE_ADDR_RANDOM && memcmp(btm_cb.ble_ctr_cb.addr_mgnt_cb.static_rand_addr, btm_cb.ble_ctr_cb.addr_mgnt_cb.private_addr,6) == 0) { UINT8_TO_STREAM (p, 0x01); BDADDR_TO_STREAM (p, btm_cb.ble_ctr_cb.addr_mgnt_cb.static_rand_addr); - } else { + } else +#endif ///BLE_INCLUDED == TRUE + { UINT8_TO_STREAM (p, 0); BDADDR_TO_STREAM (p, controller_get_interface()->get_address()->address); } @@ -866,9 +875,10 @@ void smp_mask_enc_key(UINT8 loc_enc_size, UINT8 *p_data) ** Returns void ** *******************************************************************************/ -void smp_xor_128(BT_OCTET16 a, BT_OCTET16 b) +void smp_xor_128(BT_OCTET16 a, const BT_OCTET16 b) { - UINT8 i, *aa = a, *bb = b; + UINT8 i, *aa = a; + const UINT8 *bb = b; SMP_TRACE_EVENT("smp_xor_128\n"); for (i = 0; i < BT_OCTET16_LEN; i++) { @@ -964,13 +974,14 @@ void smp_proc_pairing_cmpl(tSMP_CB *p_cb) tSMP_EVT_DATA evt_data = {0}; tSMP_CALLBACK *p_callback = p_cb->p_callback; BD_ADDR pairing_bda; - tBTM_SEC_DEV_REC *p_rec = btm_find_dev (p_cb->pairing_bda); SMP_TRACE_DEBUG ("smp_proc_pairing_cmpl \n"); evt_data.cmplt.reason = p_cb->status; evt_data.cmplt.smp_over_br = p_cb->smp_over_br; evt_data.cmplt.auth_mode = 0; +#if (BLE_INCLUDED == TRUE) + tBTM_SEC_DEV_REC *p_rec = btm_find_dev (p_cb->pairing_bda); if (p_cb->status == SMP_SUCCESS) { evt_data.cmplt.sec_level = p_cb->sec_level; if (p_cb->auth_mode) { // the first encryption @@ -982,6 +993,12 @@ void smp_proc_pairing_cmpl(tSMP_CB *p_cb) evt_data.cmplt.auth_mode = p_rec->ble.auth_mode; } } +#else + if (p_cb->status == SMP_SUCCESS) { + evt_data.cmplt.sec_level = p_cb->sec_level; + evt_data.cmplt.auth_mode = p_cb->auth_mode; + } +#endif evt_data.cmplt.is_pair_cancel = FALSE; @@ -996,6 +1013,7 @@ void smp_proc_pairing_cmpl(tSMP_CB *p_cb) memcpy (pairing_bda, p_cb->pairing_bda, BD_ADDR_LEN); +#if (BLE_INCLUDED == TRUE) #if (SMP_SLAVE_CON_PARAMS_UPD_ENABLE == TRUE) if (p_cb->role == HCI_ROLE_SLAVE) { if(p_rec && p_rec->ble.skip_update_conn_param) { @@ -1005,7 +1023,10 @@ void smp_proc_pairing_cmpl(tSMP_CB *p_cb) L2CA_EnableUpdateBleConnParams(p_cb->pairing_bda, TRUE); } } + #endif +#endif ///BLE_INCLUDED == TRUE + smp_reset_control_value(p_cb); if (p_callback) { @@ -1404,7 +1425,7 @@ void smp_collect_peer_io_capabilities(UINT8 *iocap, tSMP_CB *p_cb) iocap[1] = p_cb->peer_oob_flag; iocap[2] = p_cb->peer_auth_req; } - +#if (BLE_INCLUDED == TRUE) /******************************************************************************* ** Function smp_collect_local_ble_address ** @@ -1557,7 +1578,7 @@ BOOLEAN smp_calculate_f5_mackey_and_long_term_key(tSMP_CB *p_cb) SMP_TRACE_EVENT ("%s is completed\n", __func__); return TRUE; } - +#endif ///BLE_INCLUDED == TRUE /******************************************************************************* ** ** Function smp_request_oob_data diff --git a/examples/bluetooth/a2dp_sink/sdkconfig.defaults b/examples/bluetooth/a2dp_sink/sdkconfig.defaults index 132f512cb2..e27427a3bd 100644 --- a/examples/bluetooth/a2dp_sink/sdkconfig.defaults +++ b/examples/bluetooth/a2dp_sink/sdkconfig.defaults @@ -8,6 +8,4 @@ CONFIG_BT_BLUEDROID_ENABLED=y CONFIG_BT_CLASSIC_ENABLED=y CONFIG_BT_A2DP_ENABLE=y CONFIG_BT_SPP_ENABLED=n -CONFIG_BT_GATTS_ENABLE=n -CONFIG_BT_GATTC_ENABLE=n -CONFIG_BT_BLE_SMP_ENABLE=n +CONFIG_BT_BLE_ENABLED=n diff --git a/examples/bluetooth/a2dp_source/sdkconfig.defaults b/examples/bluetooth/a2dp_source/sdkconfig.defaults index fbee626500..c7adef6a5f 100644 --- a/examples/bluetooth/a2dp_source/sdkconfig.defaults +++ b/examples/bluetooth/a2dp_source/sdkconfig.defaults @@ -8,6 +8,4 @@ CONFIG_BT_BLUEDROID_ENABLED=y CONFIG_BT_CLASSIC_ENABLED=y CONFIG_BT_A2DP_ENABLE=y CONFIG_BT_SPP_ENABLED=n -CONFIG_BT_GATTS_ENABLE=n -CONFIG_BT_GATTC_ENABLE=n -CONFIG_BT_BLE_SMP_ENABLE=n +CONFIG_BT_BLE_ENABLED=n diff --git a/examples/bluetooth/bt_discovery/sdkconfig.defaults b/examples/bluetooth/bt_discovery/sdkconfig.defaults index af5b5d9d66..00e3d9971e 100644 --- a/examples/bluetooth/bt_discovery/sdkconfig.defaults +++ b/examples/bluetooth/bt_discovery/sdkconfig.defaults @@ -6,6 +6,4 @@ CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=y CONFIG_BTDM_CTRL_MODE_BTDM= CONFIG_BT_CLASSIC_ENABLED=y CONFIG_BT_A2DP_ENABLE=n -CONFIG_BT_GATTS_ENABLE=n -CONFIG_BT_GATTC_ENABLE=n -CONFIG_BT_BLE_SMP_ENABLE=n +CONFIG_BT_BLE_ENABLED=n diff --git a/examples/bluetooth/bt_spp_acceptor/sdkconfig.defaults b/examples/bluetooth/bt_spp_acceptor/sdkconfig.defaults index 7320428221..ea64364f53 100644 --- a/examples/bluetooth/bt_spp_acceptor/sdkconfig.defaults +++ b/examples/bluetooth/bt_spp_acceptor/sdkconfig.defaults @@ -7,3 +7,4 @@ CONFIG_BTDM_CTRL_MODE_BTDM= CONFIG_BT_CLASSIC_ENABLED=y CONFIG_WIFI_ENABLED=n CONFIG_BT_SPP_ENABLED=y +CONFIG_BT_BLE_ENABLED=n diff --git a/examples/bluetooth/bt_spp_initiator/sdkconfig.defaults b/examples/bluetooth/bt_spp_initiator/sdkconfig.defaults index 7320428221..ea64364f53 100644 --- a/examples/bluetooth/bt_spp_initiator/sdkconfig.defaults +++ b/examples/bluetooth/bt_spp_initiator/sdkconfig.defaults @@ -7,3 +7,4 @@ CONFIG_BTDM_CTRL_MODE_BTDM= CONFIG_BT_CLASSIC_ENABLED=y CONFIG_WIFI_ENABLED=n CONFIG_BT_SPP_ENABLED=y +CONFIG_BT_BLE_ENABLED=n diff --git a/examples/bluetooth/bt_spp_vfs_acceptor/sdkconfig.defaults b/examples/bluetooth/bt_spp_vfs_acceptor/sdkconfig.defaults index 7320428221..ea64364f53 100644 --- a/examples/bluetooth/bt_spp_vfs_acceptor/sdkconfig.defaults +++ b/examples/bluetooth/bt_spp_vfs_acceptor/sdkconfig.defaults @@ -7,3 +7,4 @@ CONFIG_BTDM_CTRL_MODE_BTDM= CONFIG_BT_CLASSIC_ENABLED=y CONFIG_WIFI_ENABLED=n CONFIG_BT_SPP_ENABLED=y +CONFIG_BT_BLE_ENABLED=n diff --git a/examples/bluetooth/bt_spp_vfs_initiator/sdkconfig.defaults b/examples/bluetooth/bt_spp_vfs_initiator/sdkconfig.defaults index 7320428221..ea64364f53 100644 --- a/examples/bluetooth/bt_spp_vfs_initiator/sdkconfig.defaults +++ b/examples/bluetooth/bt_spp_vfs_initiator/sdkconfig.defaults @@ -7,3 +7,4 @@ CONFIG_BTDM_CTRL_MODE_BTDM= CONFIG_BT_CLASSIC_ENABLED=y CONFIG_WIFI_ENABLED=n CONFIG_BT_SPP_ENABLED=y +CONFIG_BT_BLE_ENABLED=n