Merge branch 'refactor/bluedroid' into 'master'

Refactor/bluedroid

See merge request idf/esp-idf!4027
This commit is contained in:
Jiang Jiang Jian 2019-06-24 11:07:53 +08:00
commit 1b12e6e97d
150 changed files with 3768 additions and 2301 deletions

View File

@ -189,6 +189,7 @@ if(CONFIG_BT_ENABLED)
"bluedroid/osi/mutex.c" "bluedroid/osi/mutex.c"
"bluedroid/osi/osi.c" "bluedroid/osi/osi.c"
"bluedroid/osi/semaphore.c" "bluedroid/osi/semaphore.c"
"bluedroid/osi/thread.c"
"bluedroid/stack/a2dp/a2d_api.c" "bluedroid/stack/a2dp/a2d_api.c"
"bluedroid/stack/a2dp/a2d_sbc.c" "bluedroid/stack/a2dp/a2d_sbc.c"
"bluedroid/stack/avct/avct_api.c" "bluedroid/stack/avct/avct_api.c"

View File

@ -1,6 +1,5 @@
menu Bluetooth menu Bluetooth
config BT_ENABLED config BT_ENABLED
bool "Bluetooth" bool "Bluetooth"
help help
@ -475,9 +474,16 @@ menu Bluetooth
help help
This enables the Secure Simple Pairing. If disable this option, Bluedroid will only support Legacy Pairing 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 config BT_GATTS_ENABLE
bool "Include GATT server module(GATTS)" 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 default y
help help
This option can be disabled when the app work only on gatt client mode This option can be disabled when the app work only on gatt client mode
@ -510,21 +516,21 @@ menu Bluetooth
config BT_GATTC_ENABLE config BT_GATTC_ENABLE
bool "Include GATT client module(GATTC)" 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 default y
help help
This option can be close when the app work only on gatt server mode This option can be close when the app work only on gatt server mode
config BT_GATTC_CACHE_NVS_FLASH config BT_GATTC_CACHE_NVS_FLASH
bool "Save gattc cache data to 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 default n
help help
This select can save gattc cache data to nvs flash This select can save gattc cache data to nvs flash
config BT_BLE_SMP_ENABLE config BT_BLE_SMP_ENABLE
bool "Include BLE security module(SMP)" 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 default y
help help
This option can be close when the app not used the ble security connect. This option can be close when the app not used the ble security connect.

View File

@ -128,10 +128,12 @@ esp_err_t esp_bluedroid_init(void)
return ESP_ERR_INVALID_STATE; return ESP_ERR_INVALID_STATE;
} }
#ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG #if HEAP_MEMORY_DEBUG
osi_mem_dbg_init(); osi_mem_dbg_init();
#endif #endif
btc_init();
future_p = btc_main_get_future_p(BTC_MAIN_INIT_FUTURE); future_p = btc_main_get_future_p(BTC_MAIN_INIT_FUTURE);
*future_p = future_new(); *future_p = future_new();
if (*future_p == NULL) { if (*future_p == NULL) {
@ -139,8 +141,6 @@ esp_err_t esp_bluedroid_init(void)
return ESP_ERR_NO_MEM; return ESP_ERR_NO_MEM;
} }
btc_init();
msg.sig = BTC_SIG_API_CALL; msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_MAIN_INIT; msg.pid = BTC_PID_MAIN_INIT;
msg.act = BTC_MAIN_ACT_INIT; msg.act = BTC_MAIN_ACT_INIT;

View File

@ -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); 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) int32_t esp_hf_client_pcm_resample(void *src, uint32_t in_bytes, void *dst)
{ {
return BTA_DmPcmResample(src, in_bytes, dst); return BTA_DmPcmResample(src, in_bytes, dst);

View File

@ -23,9 +23,9 @@
#if (defined BTC_SPP_INCLUDED && BTC_SPP_INCLUDED == TRUE) #if (defined BTC_SPP_INCLUDED && BTC_SPP_INCLUDED == TRUE)
static const uint8_t UUID_SPP[16] = {0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x10, 0x00, static const uint8_t UUID_SPP[16] = {0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
}; };
static tSDP_UUID sdp_uuid; static tSDP_UUID sdp_uuid;
esp_err_t esp_spp_register_callback(esp_spp_cb_t *callback) esp_err_t esp_spp_register_callback(esp_spp_cb_t *callback)
{ {

View File

@ -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); 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 * @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. * samples. This can only be used in the case that Voice Over HCI is enabled.

View File

@ -31,24 +31,13 @@
#include "common/bt_defs.h" #include "common/bt_defs.h"
#if defined(BTA_AV_INCLUDED) && (BTA_AV_INCLUDED == TRUE) #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, #if BTA_DYNAMIC_MEMORY == FALSE
UINT32 src_samples, UINT32 dst_samples, static tBTA_AV_SBC_UPS_CB bta_av_sbc_ups_cb;
UINT32 *p_ret); #else
tBTA_AV_SBC_UPS_CB *bta_av_sbc_ups_cb_ptr;
typedef struct { #endif
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;
/******************************************************************************* /*******************************************************************************
** **

View File

@ -531,11 +531,32 @@ typedef struct {
UINT8 video_streams; /* handle mask of streaming video channels */ UINT8 video_streams; /* handle mask of streaming video channels */
} tBTA_AV_CB; } 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 ** 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 */ /* control block declaration */
#if BTA_DYNAMIC_MEMORY == FALSE #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_INCLUDED == TRUE
#endif /* BTA_AV_INT_H */ #endif /* BTA_AV_INT_H */

View File

@ -60,7 +60,9 @@ static void bta_dm_sdp_callback (UINT16 sdp_status);
#endif ///SDP_INCLUDED == TRUE #endif ///SDP_INCLUDED == TRUE
#if (SMP_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); 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); 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_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); 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 #endif ///SMP_INCLUDED == TRUE
@ -125,9 +127,12 @@ static void bta_dm_ctrl_features_rd_cmpl_cback(tBTM_STATUS result);
#if (SMP_INCLUDED == TRUE) #if (SMP_INCLUDED == TRUE)
static void bta_dm_remove_sec_dev_entry(BD_ADDR remote_bd_addr); static void bta_dm_remove_sec_dev_entry(BD_ADDR remote_bd_addr);
#endif ///SMP_INCLUDED == TRUE #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_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_cmpl_cb(void *p_result);
static void bta_dm_observe_discard_cb (uint32_t num_dis); 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); static void bta_dm_delay_role_switch_cback(TIMER_LIST_ENT *p_tle);
extern void sdpu_uuid16_to_uuid128(UINT16 uuid16, UINT8 *p_uuid128); extern void sdpu_uuid16_to_uuid128(UINT16 uuid16, UINT8 *p_uuid128);
static void bta_dm_disable_timer_cback(TIMER_LIST_ENT *p_tle); 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) #if (SMP_INCLUDED == TRUE)
const tBTM_APPL_INFO bta_security = { const tBTM_APPL_INFO bta_security = {
&bta_dm_authorize_cback, &bta_dm_authorize_cback,
#if (CLASSIC_BT_INCLUDED == TRUE)
&bta_dm_pin_cback, &bta_dm_pin_cback,
#else
NULL,
#endif
&bta_dm_new_link_key_cback, &bta_dm_new_link_key_cback,
&bta_dm_authentication_complete_cback, &bta_dm_authentication_complete_cback,
&bta_dm_bond_cancel_complete_cback, &bta_dm_bond_cancel_complete_cback,
@ -233,10 +242,12 @@ const tBTM_APPL_INFO bta_security = {
#endif ///SMP_INCLUDED == TRUE #endif ///SMP_INCLUDED == TRUE
#if (SDP_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]; UINT8 g_disc_raw_data_buf[MAX_DISC_RAW_DATA_BUF];
#else
UINT8 *g_disc_raw_data_buf;
#endif
#endif ///SDP_INCLUDED == TRUE #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); 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 btm_ble_resolving_list_cleanup (); //by TH, because cmn_ble_vsc_cb.max_filter has something mistake as btm_ble_adv_filter_cleanup
#endif #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) 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); 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) 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) { if (p_data->read_tx_power.read_tx_power_cb != NULL) {
BTM_BleReadAdvTxPower(p_data->read_tx_power.read_tx_power_cb); BTM_BleReadAdvTxPower(p_data->read_tx_power.read_tx_power_cb);
} else { } else {
APPL_TRACE_ERROR("%s(), the callback function can't be NULL.", __func__); 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) void bta_dm_ble_read_rssi(tBTA_DM_MSG *p_data)
{ {
#if (BLE_INCLUDED == TRUE)
if (p_data->rssi.read_rssi_cb != NULL) { 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); BTM_ReadRSSI(p_data->rssi.remote_addr, p_data->rssi.transport, p_data->rssi.read_rssi_cb);
} else { } else {
APPL_TRACE_ERROR("%s(), the callback function can't be NULL.", __func__); 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) void bta_dm_set_visibility(tBTA_DM_MSG *p_data)
{ {
UINT16 window, interval; UINT16 window, interval;
UINT16 le_disc_mode = BTM_BleReadDiscoverability();
UINT16 disc_mode = BTM_ReadDiscoverability(&window, &interval); UINT16 disc_mode = BTM_ReadDiscoverability(&window, &interval);
UINT16 le_conn_mode = BTM_BleReadConnectability();
UINT16 conn_mode = BTM_ReadConnectability(&window, &interval); 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 */ /* set modes for Discoverability and connectability if not ignore */
if (p_data->set_visibility.disc_mode != (BTA_DM_IGNORE | BTA_DM_LE_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) { 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 =
((p_data->set_visibility.disc_mode & ~BTA_DM_LE_IGNORE) | le_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) { 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 =
((p_data->set_visibility.disc_mode & ~BTA_DM_IGNORE) | 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, BTM_SetDiscoverability(p_data->set_visibility.disc_mode,
bta_dm_cb.inquiry_scan_window, bta_dm_cb.inquiry_scan_window,
bta_dm_cb.inquiry_scan_interval); bta_dm_cb.inquiry_scan_interval);
#endif
} }
if (p_data->set_visibility.conn_mode != (BTA_DM_IGNORE | BTA_DM_LE_IGNORE)) { 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) { 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 =
((p_data->set_visibility.conn_mode & ~BTA_DM_LE_IGNORE) | le_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) { 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 =
((p_data->set_visibility.conn_mode & ~BTA_DM_IGNORE) | 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, BTM_SetConnectability(p_data->set_visibility.conn_mode,
bta_dm_cb.page_scan_window, bta_dm_cb.page_scan_window,
bta_dm_cb.page_scan_interval); bta_dm_cb.page_scan_interval);
#endif
} }
/* Send False or True if not ignore */ /* 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) 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); 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) void bta_dm_pin_reply (tBTA_DM_MSG *p_data)
{ {
#if (CLASSIC_BT_INCLUDED == TRUE)
UINT32 trusted_mask[BTM_SEC_SERVICE_ARRAY_SIZE]; UINT32 trusted_mask[BTM_SEC_SERVICE_ARRAY_SIZE];
UINT32 *current_trusted_mask; UINT32 *current_trusted_mask;
@ -1126,7 +1156,7 @@ void bta_dm_pin_reply (tBTA_DM_MSG *p_data)
} else { } else {
BTM_PINCodeReply(p_data->pin_reply.bd_addr, BTM_NOT_AUTHORIZED, 0, NULL, trusted_mask ); BTM_PINCodeReply(p_data->pin_reply.bd_addr, BTM_NOT_AUTHORIZED, 0, NULL, trusted_mask );
} }
#endif ///CLASSIC_BT_INCLUDED == TRUE
} }
#endif ///SMP_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) 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); 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); 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); 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_data = g_disc_raw_data_buf;
bta_dm_search_cb.p_sdp_db->raw_size = MAX_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 (transport == BT_TRANSPORT_LE) {
if (bta_dm_search_cb.services_to_search & BTA_BLE_SERVICE_MASK) { if (bta_dm_search_cb.services_to_search & BTA_BLE_SERVICE_MASK) {
//set the raw data buffer here //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.p_ble_rawdata = g_disc_raw_data_buf;
bta_dm_search_cb.ble_raw_size = MAX_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) #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); bta_dm_cb.p_sec_cback(BTA_DM_PIN_REQ_EVT, &sec_event);
return BTM_CMD_STARTED; return BTM_CMD_STARTED;
} }
#endif ///CLASSIC_BT_INCLUDED == TRUE
/******************************************************************************* /*******************************************************************************
** **
@ -5795,6 +5830,7 @@ static void bta_dm_gattc_register(void)
} }
} }
#endif /* GATTC_INCLUDED == TRUE */ #endif /* GATTC_INCLUDED == TRUE */
/******************************************************************************* /*******************************************************************************
** **
** Function btm_dm_start_disc_gatt_services ** Function btm_dm_start_disc_gatt_services
@ -5804,6 +5840,7 @@ static void bta_dm_gattc_register(void)
** Parameters: ** Parameters:
** **
*******************************************************************************/ *******************************************************************************/
#if (GATTC_INCLUDED == TRUE)
static void btm_dm_start_disc_gatt_services (UINT16 conn_id) static void btm_dm_start_disc_gatt_services (UINT16 conn_id)
{ {
tBT_UUID *p_uuid = bta_dm_search_cb.p_srvc_uuid + 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 */ /* always search for all services */
BTA_GATTC_ServiceSearchRequest(conn_id, p_uuid); 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: ** Parameters:
** **
*******************************************************************************/ *******************************************************************************/
#if (GATTC_INCLUDED == TRUE)
static void bta_dm_gatt_disc_complete(UINT16 conn_id, tBTA_GATT_STATUS status) static void bta_dm_gatt_disc_complete(UINT16 conn_id, tBTA_GATT_STATUS status)
{ {
tBTA_DM_MSG *p_msg; 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; 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); bta_dm_gatt_disc_complete(bta_dm_search_cb.conn_id, (tBTA_GATT_STATUS) BTA_GATT_ERROR);
} }
#endif /* #if (GATTC_INCLUDED == TRUE) */ #endif /* #if (GATTC_INCLUDED == TRUE) */
/******************************************************************************* /*******************************************************************************
** **
** Function bta_dm_proc_open_evt ** Function bta_dm_proc_open_evt
@ -6010,6 +6051,7 @@ static void bta_dm_cancel_gatt_discovery(BD_ADDR bd_addr)
** Parameters: ** Parameters:
** **
*******************************************************************************/ *******************************************************************************/
#if (GATTC_INCLUDED == TRUE)
void bta_dm_proc_open_evt(tBTA_GATTC_OPEN *p_data) void bta_dm_proc_open_evt(tBTA_GATTC_OPEN *p_data)
{ {
UINT8 *p1; 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); bta_dm_gatt_disc_complete(BTA_GATT_INVALID_CONN_ID, p_data->status);
} }
} }
#endif /* #if (GATTC_INCLUDED == TRUE) */
/******************************************************************************* /*******************************************************************************
** **

View File

@ -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) 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; 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); bta_sys_sendmsg(p_msg);
} }
} }
#endif ///BLE_INCLUDED == TRUE
void BTA_DmBleReadRSSI(BD_ADDR remote_addr, tBTA_TRANSPORT transport, tBTA_CMPL_CB *cmpl_cb) 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); bdcpy(p_msg->bd_addr, bd_addr);
bta_sys_sendmsg(p_msg); bta_sys_sendmsg(p_msg);
} }
} }
#endif ///SMP_INCLUDED == TRUE
#if (CLASSIC_BT_INCLUDED == TRUE)
/******************************************************************************* /*******************************************************************************
** **
** Function BTA_DMSetPinType ** 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) #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 ** Returns void
** **
*******************************************************************************/ *******************************************************************************/
#if (SMP_INCLUDED == TRUE)
void BTA_DmConfirm(BD_ADDR bd_addr, BOOLEAN accept) void BTA_DmConfirm(BD_ADDR bd_addr, BOOLEAN accept)
{ {
tBTA_DM_API_CONFIRM *p_msg; 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 ///BT_SSP_INCLUDED == TRUE
#endif ///SMP_INCLUDED == TRUE
/******************************************************************************* /*******************************************************************************
** **
** Function BTA_DmAddDevice ** Function BTA_DmAddDevice
@ -705,7 +710,7 @@ tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr, tBT_TRANSPORT transport)
return BTA_SUCCESS; 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 ///SMP_INCLUDED == TRUE
#endif ///BLE_INCLUDED == TRUE
/******************************************************************************* /*******************************************************************************
@ -1207,7 +1211,7 @@ void BTA_DmSetBleAdvParamsAll (UINT16 adv_int_min, UINT16 adv_int_max,
} }
#endif #endif
} }
#endif ///BLE_INCLUDED == TRUE
/******************************************************************************* /*******************************************************************************
@ -1796,6 +1800,8 @@ void BTA_DmBleUpdateConnectionParam(BD_ADDR bd_addr, UINT16 min_int,
} }
#endif #endif
} }
#if BLE_INCLUDED == TRUE
/******************************************************************************* /*******************************************************************************
** **
** Function BTA_DmBleConfigLocalPrivacy ** Function BTA_DmBleConfigLocalPrivacy
@ -1826,7 +1832,6 @@ void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable, tBTA_SET_LOCAL_PRIVACY_
#endif #endif
} }
#if BLE_INCLUDED == TRUE
/******************************************************************************* /*******************************************************************************
** **
** Function BTA_DmBleConfigLocalIcon ** Function BTA_DmBleConfigLocalIcon

View File

@ -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 #if BLE_INCLUDED == TRUE
# define BTA_DM_NUM_PM_ENTRY 8 /* number of entries in bta_dm_pm_cfg except the first */ # 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 */ {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 #endif
tBTA_DM_PM_CFG *p_bta_dm_pm_cfg = (tBTA_DM_PM_CFG *) &bta_dm_pm_cfg; tBTA_DM_PM_CFG *const 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; tBTA_DM_PM_SPEC *const 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; 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) */ #endif /* #if (BTA_DM_PM_INCLUDED == TRUE) */

View File

@ -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_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_adv_tx_power, /* BTA_DM_API_BLE_READ_ADV_TX_POWER_EVT */
bta_dm_ble_read_rssi, /* BTA_DM_API_BLE_READ_RSSI_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 */ bta_dm_ble_update_duplicate_exceptional_list,/* BTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_EVT */
#endif
}; };

View File

@ -32,7 +32,11 @@
#include "stack/btm_api.h" #include "stack/btm_api.h"
#include "osi/allocator.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) #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); static void bta_dm_pm_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id, BD_ADDR peer_addr);

View File

@ -28,6 +28,7 @@
#include <string.h> #include <string.h>
#include "bta/bta_api.h" #include "bta/bta_api.h"
#include "bta/bta_sys.h" #include "bta/bta_sys.h"
#include "osi/allocator.h"
#if (BTM_SCO_HCI_INCLUDED == TRUE) #if (BTM_SCO_HCI_INCLUDED == TRUE)
@ -67,7 +68,7 @@ typedef struct {
UINT32 divisor; UINT32 divisor;
} tBTA_DM_PCM_RESAMPLE_CB; } 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 ** 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) 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->cur_pos = src_sps / 2;
p_cb->src_sps = src_sps; 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 ** Function BTA_DmPcmResample
** **
@ -636,14 +655,14 @@ INT32 BTA_DmPcmResample (void *p_src, UINT32 in_bytes, void *p_dst)
UINT32 out_sample; UINT32 out_sample;
#if BTA_DM_SCO_DEBUG #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 #endif
if (bta_dm_pcm_cb.can_be_filtered) { if (p_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), out_sample = (*p_bta_dm_pcm_cb->filter) (p_src, p_dst, (in_bytes / p_bta_dm_pcm_cb->divisor),
bta_dm_pcm_cb.src_sps, (INT32 *) &bta_dm_pcm_cb.cur_pos, bta_dm_pcm_cb.overlap_area); p_bta_dm_pcm_cb->src_sps, (INT32 *) &(p_bta_dm_pcm_cb->cur_pos), p_bta_dm_pcm_cb->overlap_area);
} else { } else {
out_sample = (*bta_dm_pcm_cb.nofilter) (p_src, p_dst, out_sample = (*p_bta_dm_pcm_cb->nofilter) (p_src, p_dst,
(in_bytes / bta_dm_pcm_cb.divisor), bta_dm_pcm_cb.src_sps); (in_bytes / p_bta_dm_pcm_cb->divisor), p_bta_dm_pcm_cb->src_sps);
} }
#if BTA_DM_SCO_DEBUG #if BTA_DM_SCO_DEBUG

View File

@ -157,7 +157,9 @@ enum {
BTA_DM_API_UPDATE_WHITE_LIST_EVT, BTA_DM_API_UPDATE_WHITE_LIST_EVT,
BTA_DM_API_BLE_READ_ADV_TX_POWER_EVT, BTA_DM_API_BLE_READ_ADV_TX_POWER_EVT,
BTA_DM_API_BLE_READ_RSSI_EVT, BTA_DM_API_BLE_READ_RSSI_EVT,
#if BLE_INCLUDED == TRUE
BTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_EVT, BTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_EVT,
#endif
BTA_DM_MAX_EVT BTA_DM_MAX_EVT
}; };
@ -203,6 +205,7 @@ typedef struct {
UINT8 data[]; UINT8 data[];
}tBTA_DM_API_CONFIG_EIR; }tBTA_DM_API_CONFIG_EIR;
#if (BLE_INCLUDED == TRUE)
typedef struct { typedef struct {
BT_HDR hdr; BT_HDR hdr;
BOOLEAN add_remove; BOOLEAN add_remove;
@ -223,6 +226,7 @@ typedef struct {
BT_HDR hdr; BT_HDR hdr;
tBTA_CMPL_CB *read_tx_power_cb; tBTA_CMPL_CB *read_tx_power_cb;
}tBTA_DM_API_READ_ADV_TX_POWER; }tBTA_DM_API_READ_ADV_TX_POWER;
#endif ///BLE_INCLUDED == TRUE
typedef struct { typedef struct {
BT_HDR hdr; BT_HDR hdr;
@ -402,8 +406,8 @@ typedef struct {
UINT8 hci_status; UINT8 hci_status;
#if BLE_INCLUDED == TRUE #if BLE_INCLUDED == TRUE
UINT16 handle; UINT16 handle;
tBT_TRANSPORT transport;
#endif #endif
tBT_TRANSPORT transport;
} tBTA_DM_ACL_CHANGE; } tBTA_DM_ACL_CHANGE;
#if (BTA_DM_PM_INCLUDED == TRUE) #if (BTA_DM_PM_INCLUDED == TRUE)
@ -801,9 +805,12 @@ typedef union {
tBTA_DM_API_SET_NAME set_name; tBTA_DM_API_SET_NAME set_name;
tBTA_DM_API_CONFIG_EIR config_eir; tBTA_DM_API_CONFIG_EIR config_eir;
#if (BLE_INCLUDED == TRUE)
tBTA_DM_API_UPDATE_WHITE_LIST white_list; tBTA_DM_API_UPDATE_WHITE_LIST white_list;
tBTA_DM_API_READ_ADV_TX_POWER read_tx_power; tBTA_DM_API_READ_ADV_TX_POWER read_tx_power;
tBTA_DM_API_READ_RSSI rssi; tBTA_DM_API_READ_RSSI rssi;
#endif ///BLE_INCLUDED == TRUE
tBTA_DM_API_SET_VISIBILITY set_visibility; tBTA_DM_API_SET_VISIBILITY set_visibility;
tBTA_DM_API_ADD_DEVICE add_dev; tBTA_DM_API_ADD_DEVICE add_dev;
@ -939,8 +946,8 @@ typedef struct {
BOOLEAN remove_dev_pending; BOOLEAN remove_dev_pending;
#if BLE_INCLUDED == TRUE #if BLE_INCLUDED == TRUE
UINT16 conn_handle; UINT16 conn_handle;
tBT_TRANSPORT transport;
#endif #endif
tBT_TRANSPORT transport;
} tBTA_DM_PEER_DEVICE; } tBTA_DM_PEER_DEVICE;
@ -976,7 +983,6 @@ typedef struct {
} tBTA_DM_CONNECTED_SRVCS; } tBTA_DM_CONNECTED_SRVCS;
extern tBTA_DM_CONNECTED_SRVCS bta_dm_conn_srvcs;
#if (BTA_DM_PM_INCLUDED == TRUE) #if (BTA_DM_PM_INCLUDED == TRUE)
@ -1032,6 +1038,8 @@ typedef struct {
BOOLEAN disable_pair_mode; /* disable pair mode or not */ BOOLEAN disable_pair_mode; /* disable pair mode or not */
BOOLEAN conn_paired_only; /* allow connectable to paired device only or not */ BOOLEAN conn_paired_only; /* allow connectable to paired device only or not */
tBTA_DM_API_SEARCH search_msg; tBTA_DM_API_SEARCH search_msg;
#if (CLASSIC_BT_INCLUDED == TRUE)
UINT16 page_scan_interval; UINT16 page_scan_interval;
UINT16 page_scan_window; UINT16 page_scan_window;
UINT16 inquiry_scan_interval; UINT16 inquiry_scan_interval;
@ -1041,8 +1049,10 @@ typedef struct {
BD_ADDR pin_bd_addr; BD_ADDR pin_bd_addr;
DEV_CLASS pin_dev_class; DEV_CLASS pin_dev_class;
tBTA_DM_SEC_EVT pin_evt; tBTA_DM_SEC_EVT pin_evt;
UINT32 num_val; /* the numeric value for comparison. If just_works, do not show this number to UI */ 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 */ BOOLEAN just_works; /* TRUE, if "Just Works" association model */
#endif
#if ( BTA_EIR_CANNED_UUID_LIST != TRUE ) #if ( BTA_EIR_CANNED_UUID_LIST != TRUE )
/* store UUID list for EIR */ /* store UUID list for EIR */
TIMER_LIST_ENT app_ready_timer; TIMER_LIST_ENT app_ready_timer;
@ -1150,8 +1160,8 @@ typedef struct {
} tBTA_DM_RM ; } tBTA_DM_RM ;
extern tBTA_DM_CFG *p_bta_dm_cfg; extern tBTA_DM_CFG *const p_bta_dm_cfg;
extern tBTA_DM_RM *p_bta_dm_rm_cfg; extern tBTA_DM_RM *const p_bta_dm_rm_cfg;
typedef struct { typedef struct {
@ -1192,11 +1202,11 @@ typedef struct {
} tBTA_DM_LMP_VER_INFO; } tBTA_DM_LMP_VER_INFO;
#if (BTA_DM_PM_INCLUDED == TRUE) #if (BTA_DM_PM_INCLUDED == TRUE)
extern tBTA_DM_PM_CFG *p_bta_dm_pm_cfg; extern tBTA_DM_PM_CFG *const p_bta_dm_pm_cfg;
extern tBTA_DM_PM_SPEC *p_bta_dm_pm_spec; extern tBTA_DM_PM_SPEC *const p_bta_dm_pm_spec;
extern tBTM_PM_PWR_MD *p_bta_dm_pm_md; extern tBTM_PM_PWR_MD *const p_bta_dm_pm_md;
#if (BTM_SSR_INCLUDED == TRUE) #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
#endif /* #if (BTA_DM_PM_INCLUDED == TRUE) */ #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) #define bta_dm_di_cb (*bta_dm_di_cb_ptr)
#endif #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 BOOLEAN bta_dm_sm_execute(BT_HDR *p_msg);
extern void bta_dm_sm_disable( void ); extern void bta_dm_sm_disable( void );
extern void bta_dm_sm_deinit(void); extern void bta_dm_sm_deinit(void);

View File

@ -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 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 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_conn_cback,
bta_gattc_cmpl_cback, bta_gattc_cmpl_cback,
bta_gattc_disc_res_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 */ /* 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_READ_EVT,
BTA_GATTC_API_WRITE_EVT, BTA_GATTC_API_WRITE_EVT,
BTA_GATTC_API_EXEC_EVT, BTA_GATTC_API_EXEC_EVT,

View File

@ -26,6 +26,7 @@
#include "common/bt_target.h" #include "common/bt_target.h"
#if defined(GATTC_INCLUDED) && (GATTC_INCLUDED == TRUE) #if defined(GATTC_INCLUDED) && (GATTC_INCLUDED == TRUE)
//#if( defined GATTC_CACHE_NVS ) && (GATTC_CACHE_NVS == TRUE)
#include <string.h> #include <string.h>
#include "bta/utl.h" #include "bta/utl.h"
@ -2190,5 +2191,7 @@ void bta_gattc_cache_reset(BD_ADDR server_bda)
bta_gattc_co_cache_reset(server_bda); bta_gattc_co_cache_reset(server_bda);
//unlink(fname); //unlink(fname);
} }
//#endif /* GATTC_CACHE_NVS */
#endif /* BTA_GATT_INCLUDED */ #endif /* BTA_GATT_INCLUDED */

View File

@ -33,6 +33,7 @@
#if( defined BLE_INCLUDED ) && (BLE_INCLUDED == TRUE) #if( defined BLE_INCLUDED ) && (BLE_INCLUDED == TRUE)
#if( defined BTA_GATT_INCLUDED ) && (GATTC_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 GATT_CACHE_PREFIX "gatt_"
#define INVALID_ADDR_NUM 0xff #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_key = "gattc_cache_key";
static const char *cache_addr = "cache_addr_tab"; static const char *cache_addr = "cache_addr_tab";
nvs_handle_t nvs_fp;
typedef struct { typedef struct {
//save the service data in the list according to the address //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_addr_info_t cache_addr[MAX_DEVICE_IN_CACHE];
}cache_env_t; }cache_env_t;
cache_env_t cache_env; static cache_env_t *cache_env = NULL;
static void getFilename(char *buffer, hash_key_t hash) static void getFilename(char *buffer, hash_key_t hash)
{ {
@ -108,9 +108,9 @@ static void cacheClose(BD_ADDR bda)
{ {
UINT8 index = 0; UINT8 index = 0;
if ((index = bta_gattc_co_find_addr_in_cache(bda)) != INVALID_ADDR_NUM) { if ((index = bta_gattc_co_find_addr_in_cache(bda)) != INVALID_ADDR_NUM) {
if (cache_env.cache_addr[index].is_open) { if (cache_env->cache_addr[index].is_open) {
nvs_close(cache_env.cache_addr[index].cache_fp); nvs_close(cache_env->cache_addr[index].cache_fp);
cache_env.cache_addr[index].is_open = FALSE; cache_env->cache_addr[index].is_open = FALSE;
} }
} }
} }
@ -124,14 +124,14 @@ static bool cacheOpen(BD_ADDR bda, bool to_save, UINT8 *index)
hash_key_t hash_key = {0}; hash_key_t hash_key = {0};
if (((*index = bta_gattc_co_find_addr_in_cache(bda)) != INVALID_ADDR_NUM) || 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)) { ((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; return TRUE;
} else { } 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); 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. // 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;
} }
} }
} }
@ -144,56 +144,56 @@ static void cacheReset(BD_ADDR bda)
char fname[255] = {0}; char fname[255] = {0};
getFilename(fname, bda); getFilename(fname, bda);
UINT8 index = 0; UINT8 index = 0;
//cache_env.cache_addr //cache_env->cache_addr
if ((index = bta_gattc_co_find_addr_in_cache(bda)) != INVALID_ADDR_NUM) { if ((index = bta_gattc_co_find_addr_in_cache(bda)) != INVALID_ADDR_NUM) {
//clear the association address pending in the source address. //clear the association address pending in the source address.
bta_gattc_co_cache_clear_assoc_addr(bda); bta_gattc_co_cache_clear_assoc_addr(bda);
if (cache_env.cache_addr[index].is_open) { if (cache_env->cache_addr[index].is_open) {
nvs_erase_all(cache_env.cache_addr[index].cache_fp); nvs_erase_all(cache_env->cache_addr[index].cache_fp);
nvs_close(cache_env.cache_addr[index].cache_fp); nvs_close(cache_env->cache_addr[index].cache_fp);
cache_env.cache_addr[index].is_open = FALSE; cache_env->cache_addr[index].is_open = FALSE;
} else { } else {
cacheOpen(bda, false, &index); cacheOpen(bda, false, &index);
if (cache_env.cache_addr[index].is_open) { if (cache_env->cache_addr[index].is_open) {
nvs_erase_all(cache_env.cache_addr[index].cache_fp); nvs_erase_all(cache_env->cache_addr[index].cache_fp);
nvs_close(cache_env.cache_addr[index].cache_fp); nvs_close(cache_env->cache_addr[index].cache_fp);
cache_env.cache_addr[index].is_open = FALSE; cache_env->cache_addr[index].is_open = FALSE;
} else { } else {
APPL_TRACE_ERROR("%s cacheOpen failed", __func__); APPL_TRACE_ERROR("%s cacheOpen failed", __func__);
return; return;
} }
} }
if(cache_env.num_addr == 0) { if(cache_env->num_addr == 0) {
APPL_TRACE_ERROR("%s cache addr list error", __func__); APPL_TRACE_ERROR("%s cache addr list error", __func__);
return; return;
} }
UINT8 num = cache_env.num_addr; UINT8 num = cache_env->num_addr;
//delete the server_bda in the addr_info list. //delete the server_bda in the addr_info list.
for(UINT8 i = index; i < (num - 1); i++) { 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 //reduced the number address counter also
cache_env.num_addr--; cache_env->num_addr--;
//update addr list to nvs flash //update addr list to nvs flash
if(cache_env.num_addr > 0) { if(cache_env->num_addr > 0) {
//update //update
UINT8 *p_buf = osi_malloc(MAX_ADDR_LIST_CACHE_BUF); UINT8 *p_buf = osi_malloc(MAX_ADDR_LIST_CACHE_BUF);
if(!p_buf) { if(!p_buf) {
APPL_TRACE_ERROR("%s malloc error", __func__); APPL_TRACE_ERROR("%s malloc error", __func__);
return; return;
} }
UINT16 length = cache_env.num_addr*(sizeof(BD_ADDR) + sizeof(hash_key_t)); UINT16 length = cache_env->num_addr*(sizeof(BD_ADDR) + sizeof(hash_key_t));
for (UINT8 i = 0; i < cache_env.num_addr; i++) { for (UINT8 i = 0; i < cache_env->num_addr; i++) {
//copy the address to the buffer. //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. //copy the hash key to the buffer.
memcpy(p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)) + sizeof(BD_ADDR), 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 (cache_env->is_open) {
if (nvs_set_blob(cache_env.addr_fp, cache_key, p_buf, length) != ESP_OK) { if (nvs_set_blob(cache_env->addr_fp, cache_key, p_buf, length) != ESP_OK) {
APPL_TRACE_WARNING("%s, nvs set blob failed", __func__); APPL_TRACE_WARNING("%s, nvs set blob failed", __func__);
} }
} }
@ -201,10 +201,10 @@ static void cacheReset(BD_ADDR bda)
} else { } else {
//erase //erase
if (cache_env.is_open) { if (cache_env->is_open) {
nvs_erase_all(cache_env.addr_fp); nvs_erase_all(cache_env->addr_fp);
nvs_close(cache_env.addr_fp); nvs_close(cache_env->addr_fp);
cache_env.is_open = FALSE; cache_env->is_open = FALSE;
} else { } else {
APPL_TRACE_WARNING("cache_env status is error"); 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; tBTA_GATT_STATUS status = BTA_GATT_ERROR;
size_t length = 0; size_t length = 0;
// Read the size of memory space required for blob // 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 // 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) #if (!CONFIG_BT_STACK_NO_LOG)
num_attr = length / sizeof(tBTA_GATTC_NV_ATTR); num_attr = length / sizeof(tBTA_GATTC_NV_ATTR);
#endif #endif
@ -288,7 +288,7 @@ size_t bta_gattc_get_cache_attr_length(UINT8 index)
} }
// Read the size of memory space required for blob // 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; 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); bta_gattc_co_cache_addr_save(server_bda, hash_key);
if (cacheOpen(server_bda, TRUE, &index)) { 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); p_attr_list, sizeof(tBTA_GATTC_NV_ATTR)*num_attr);
status = (err_code == ESP_OK) ? BTA_GATT_OK : BTA_GATT_ERROR; status = (err_code == ESP_OK) ? BTA_GATT_OK : BTA_GATT_ERROR;
} else { } else {
@ -380,12 +380,23 @@ void bta_gattc_co_cache_addr_init(void)
nvs_handle_t fp; nvs_handle_t fp;
esp_err_t err_code; esp_err_t err_code;
UINT8 num_addr; UINT8 num_addr;
UINT8 *p_buf = osi_malloc(MAX_ADDR_LIST_CACHE_BUF);
size_t length = 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) { if ((err_code = nvs_open(cache_addr, NVS_READWRITE, &fp)) == ESP_OK) {
cache_env.addr_fp = fp; cache_env->addr_fp = fp;
cache_env.is_open = TRUE; cache_env->is_open = TRUE;
// Read previously saved blob if available // Read previously saved blob if available
if ((err_code = nvs_get_blob(fp, cache_key, p_buf, &length)) != ESP_OK) { if ((err_code = nvs_get_blob(fp, cache_key, p_buf, &length)) != ESP_OK) {
if(err_code != ESP_ERR_NVS_NOT_FOUND) { if(err_code != ESP_ERR_NVS_NOT_FOUND) {
@ -395,18 +406,18 @@ void bta_gattc_co_cache_addr_init(void)
return; return;
} }
num_addr = length / (sizeof(BD_ADDR) + sizeof(hash_key_t)); 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. //read the address from nvs flash to cache address list.
for (UINT8 i = 0; i < num_addr; i++) { 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].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].hash_key,
p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)) + sizeof(BD_ADDR), sizeof(hash_key_t)); 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], 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]); 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], 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]); 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); bta_gattc_co_cache_new_assoc_list(cache_env->cache_addr[i].addr, i);
} }
} else { } else {
APPL_TRACE_ERROR("%s, Line = %d, nvs flash open fail, err_code = %x", __func__, __LINE__, err_code); 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) void bta_gattc_co_cache_addr_deinit(void)
{ {
if(!cache_env.is_open) { if(!cache_env->is_open) {
return; return;
} }
nvs_close(cache_env.addr_fp); nvs_close(cache_env->addr_fp);
cache_env.is_open = false; cache_env->is_open = false;
for(UINT8 i = 0; i< cache_env.num_addr; i++) { for(UINT8 i = 0; i< cache_env->num_addr; i++) {
cache_addr_info_t *addr_info = &cache_env.cache_addr[i]; cache_addr_info_t *addr_info = &cache_env->cache_addr[i];
if(addr_info) { if(addr_info) {
nvs_close(addr_info->cache_fp); nvs_close(addr_info->cache_fp);
addr_info->is_open = false; 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) BOOLEAN bta_gattc_co_addr_in_cache(BD_ADDR bda)
{ {
UINT8 addr_index = 0; UINT8 addr_index = 0;
UINT8 num = cache_env.num_addr; UINT8 num = cache_env->num_addr;
cache_addr_info_t *addr_info = &cache_env.cache_addr[0]; cache_addr_info_t *addr_info = &cache_env->cache_addr[0];
for (addr_index = 0; addr_index < num; addr_index++) { for (addr_index = 0; addr_index < num; addr_index++) {
if (!memcmp(addr_info->addr, bda, sizeof(BD_ADDR))) { if (!memcmp(addr_info->addr, bda, sizeof(BD_ADDR))) {
return TRUE; 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 bta_gattc_co_find_addr_in_cache(BD_ADDR bda)
{ {
UINT8 addr_index = 0; UINT8 addr_index = 0;
UINT8 num = cache_env.num_addr; UINT8 num = cache_env->num_addr;
cache_addr_info_t *addr_info = &cache_env.cache_addr[0]; cache_addr_info_t *addr_info = &cache_env->cache_addr[0];
for (addr_index = 0; addr_index < num; addr_index++, addr_info++) { for (addr_index = 0; addr_index < num; addr_index++, addr_info++) {
if (!memcmp(addr_info->addr, bda, sizeof(BD_ADDR))) { 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 bta_gattc_co_find_hash_in_cache(hash_key_t hash_key)
{ {
UINT8 index = 0; UINT8 index = 0;
UINT8 num = cache_env.num_addr; UINT8 num = cache_env->num_addr;
cache_addr_info_t *addr_info = &cache_env.cache_addr[0]; cache_addr_info_t *addr_info = &cache_env->cache_addr[0];
for (index = 0; index < num; index++) { for (index = 0; index < num; index++) {
if (!memcmp(addr_info->hash_key, hash_key, sizeof(hash_key_t))) { if (!memcmp(addr_info->hash_key, hash_key, sizeof(hash_key_t))) {
return index; 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) 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) 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++) { 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) void bta_gattc_co_cache_addr_save(BD_ADDR bd_addr, hash_key_t hash_key)
{ {
esp_err_t err_code; esp_err_t err_code;
UINT8 num = ++cache_env.num_addr; UINT8 num = ++cache_env->num_addr;
UINT8 index = 0; UINT8 index = 0;
UINT8 *p_buf = osi_malloc(MAX_ADDR_LIST_CACHE_BUF); UINT8 *p_buf = osi_malloc(MAX_ADDR_LIST_CACHE_BUF);
// check the address list has the same hash key or not // 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) { 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); 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. //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].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].hash_key, hash_key, sizeof(hash_key_t));
} else { } else {
//if the bd_addr didn't in the address list, added the bd_addr to the last of the address list. //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].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].addr, bd_addr, sizeof(BD_ADDR));
} }
} else { } else {
APPL_TRACE_DEBUG("%s(), num = %d", __func__, num); 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].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].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)); UINT16 length = num*(sizeof(BD_ADDR) + sizeof(hash_key_t));
for (UINT8 i = 0; i < num; i++) { for (UINT8 i = 0; i < num; i++) {
//copy the address to the buffer. //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. //copy the hash key to the buffer.
memcpy(p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)) + sizeof(BD_ADDR), 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 (cache_env->is_open) {
if ((err_code = nvs_set_blob(cache_env.addr_fp, cache_key, p_buf, length)) != ESP_OK) { 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); APPL_TRACE_WARNING("%s(), nvs set blob fail, err %d", __func__, err_code);
} }
} else { } else {
if ((err_code = nvs_open(cache_addr, NVS_READWRITE , fp)) == ESP_OK) { if ((err_code = nvs_open(cache_addr, NVS_READWRITE , fp)) == ESP_OK) {
cache_env.is_open = true; cache_env->is_open = true;
if (( err_code = nvs_set_blob(cache_env.addr_fp, cache_key, p_buf, length)) != ESP_OK) { 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); APPL_TRACE_WARNING("%s(), nvs set blob fail, err %d", __func__, err_code);
} }
} else { } 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) 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); addr_info->assoc_addr = list_new(osi_free_func);
return (addr_info->assoc_addr != NULL ? TRUE : FALSE); 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)); UINT8 *p_assoc_buf = osi_malloc(sizeof(BD_ADDR));
memcpy(p_assoc_buf, assoc_addr, 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) { 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) { if (addr_info->assoc_addr == NULL) {
addr_info->assoc_addr =list_new(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; UINT8 addr_index = 0;
cache_addr_info_t *addr_info; cache_addr_info_t *addr_info;
if ((addr_index = bta_gattc_co_find_addr_in_cache(src_addr)) != INVALID_ADDR_NUM) { 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) { if (addr_info->assoc_addr != NULL) {
for (list_node_t *sn = list_begin(addr_info->assoc_addr); for (list_node_t *sn = list_begin(addr_info->assoc_addr);
sn != list_end(addr_info->assoc_addr); sn = list_next(sn)) { 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* bta_gattc_co_cache_find_src_addr(BD_ADDR assoc_addr, UINT8 *index)
{ {
UINT8 num = cache_env.num_addr; UINT8 num = cache_env->num_addr;
cache_addr_info_t *addr_info = &cache_env.cache_addr[0]; cache_addr_info_t *addr_info = &cache_env->cache_addr[0];
UINT8 *addr_data; UINT8 *addr_data;
//Check the assoc_addr list is NULL or not //Check the assoc_addr list is NULL or not
if (addr_info->assoc_addr == NULL) { if (addr_info->assoc_addr == NULL) {
@ -635,7 +649,7 @@ BOOLEAN bta_gattc_co_cache_clear_assoc_addr(BD_ADDR src_addr)
UINT8 addr_index = 0; UINT8 addr_index = 0;
cache_addr_info_t *addr_info; cache_addr_info_t *addr_info;
if ((addr_index = bta_gattc_co_find_addr_in_cache(src_addr)) != INVALID_ADDR_NUM) { 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) { if (addr_info->assoc_addr != NULL) {
list_clear(addr_info->assoc_addr); list_clear(addr_info->assoc_addr);
} else { } else {
@ -647,6 +661,7 @@ BOOLEAN bta_gattc_co_cache_clear_assoc_addr(BD_ADDR src_addr)
return FALSE; return FALSE;
} }
// #endif /* #if( defined GATTC_CACHE_NVS ) && (GATTC_CACHE_NVS == TRUE) */
#endif /* #if( defined BLE_INCLUDED ) && (BLE_INCLUDED == TRUE) */ #endif /* #if( defined BLE_INCLUDED ) && (BLE_INCLUDED == TRUE) */
#endif /* #if( defined BTA_GATT_INCLUDED ) && (BTA_GATT_INCLUDED == TRUE) */ #endif /* #if( defined BTA_GATT_INCLUDED ) && (BTA_GATT_INCLUDED == TRUE) */

View File

@ -49,7 +49,7 @@ static void bta_gatts_send_request_cback (UINT16 conn_id,
tGATTS_REQ_TYPE req_type, tGATTS_DATA *p_data); tGATTS_REQ_TYPE req_type, tGATTS_DATA *p_data);
static void bta_gatts_cong_cback (UINT16 conn_id, BOOLEAN congested); 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, bta_gatts_conn_cback,
NULL, NULL,
NULL, NULL,
@ -59,7 +59,7 @@ static tGATT_CBACK bta_gatts_cback = {
bta_gatts_cong_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_save_cback,
bta_gatts_nv_srv_chg_cback bta_gatts_nv_srv_chg_cback
}; };

View File

@ -82,7 +82,7 @@ void BTA_GATTS_Disable(void)
** Returns None ** 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; tBTA_GATTS_API_REG *p_buf;
@ -149,7 +149,7 @@ void BTA_GATTS_AppDeregister(tBTA_GATTS_IF server_if)
** Returns void ** 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) UINT16 num_handle, BOOLEAN is_primary)
{ {
tBTA_GATTS_API_CREATE_SRVC *p_buf; tBTA_GATTS_API_CREATE_SRVC *p_buf;
@ -214,7 +214,7 @@ void BTA_GATTS_AddIncludeService(UINT16 service_id, UINT16 included_service_id)
** Returns None ** Returns None
** **
*******************************************************************************/ *******************************************************************************/
void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid, 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_GATT_PERM perm, tBTA_GATT_CHAR_PROP property, tGATT_ATTR_VAL *attr_val,
tBTA_GATTS_ATTR_CONTROL *control) tBTA_GATTS_ATTR_CONTROL *control)
{ {
@ -270,7 +270,7 @@ void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid,
*******************************************************************************/ *******************************************************************************/
void BTA_GATTS_AddCharDescriptor (UINT16 service_id, void BTA_GATTS_AddCharDescriptor (UINT16 service_id,
tBTA_GATT_PERM perm, 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_ATTR_CONTROL *control)
{ {
tBTA_GATTS_API_ADD_DESCR *p_buf; tBTA_GATTS_API_ADD_DESCR *p_buf;

View File

@ -31,9 +31,9 @@
// #include "uipc_msg.h" // #include "uipc_msg.h"
#include "stack/sdp_api.h" #include "stack/sdp_api.h"
#if BLE_INCLUDED == TRUE // #if BLE_INCLUDED == TRUE
#include "stack/btm_ble_api.h" #include "stack/btm_ble_api.h"
#endif // #endif
/***************************************************************************** /*****************************************************************************
** Constants and data types ** Constants and data types
@ -323,7 +323,7 @@ typedef struct {
tBTA_DM_CONFIG_EIR_CBACK *config_eir_callback; /* callback */ tBTA_DM_CONFIG_EIR_CBACK *config_eir_callback; /* callback */
} tBTA_DM_EIR_CONF; } tBTA_DM_EIR_CONF;
#if BLE_INCLUDED == TRUE // #if BLE_INCLUDED == TRUE
/* ADV data flag bit definition used for BTM_BLE_AD_TYPE_FLAG */ /* 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_LIMIT_DISC_FLAG BTM_BLE_LIMIT_DISC_FLAG
#define BTA_BLE_GEN_DISC_FLAG BTM_BLE_GEN_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_BATCH_SCAN_EVT tBTA_BLE_BATCH_SCAN_EVT;
typedef tBTM_BLE_TRACK_ADV_ACTION tBTA_BLE_TRACK_ADV_ACTION; typedef tBTM_BLE_TRACK_ADV_ACTION tBTA_BLE_TRACK_ADV_ACTION;
#endif // #endif
/* BLE customer specific feature function type definitions */ /* BLE customer specific feature function type definitions */
/* data type used on customer specific feature for RSSI monitoring */ /* 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); 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_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); 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); 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); 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 ** Function BTA_DmPcmResample
** **

View File

@ -25,6 +25,7 @@
#define BTA_DM_CO_H #define BTA_DM_CO_H
#include "bta/bta_sys.h" #include "bta/bta_sys.h"
#include "esp_err.h"
/***************************************************************************** /*****************************************************************************
** Function Declarations ** Function Declarations

View File

@ -30,7 +30,6 @@
#include "osi/list.h" #include "osi/list.h"
#ifndef BTA_GATT_INCLUDED #ifndef BTA_GATT_INCLUDED
#warning BTA_GATT_INCLUDED not defined
#define BTA_GATT_INCLUDED FALSE #define BTA_GATT_INCLUDED FALSE
#endif #endif
@ -1234,7 +1233,7 @@ extern void BTA_GATTS_Disable(void);
** Returns None ** 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 ** 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); UINT8 inst, UINT16 num_handle, BOOLEAN is_primary);
/******************************************************************************* /*******************************************************************************
@ -1304,7 +1303,7 @@ extern void BTA_GATTS_AddIncludeService(UINT16 service_id, UINT16 included_servi
** Returns None ** Returns None
** **
*******************************************************************************/ *******************************************************************************/
extern void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid, 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_GATT_PERM perm, tBTA_GATT_CHAR_PROP property, tGATT_ATTR_VAL *attr_val,
tBTA_GATTS_ATTR_CONTROL *control); 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, extern void BTA_GATTS_AddCharDescriptor (UINT16 service_id,
tBTA_GATT_PERM perm, 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_ATTR_CONTROL *control);
/******************************************************************************* /*******************************************************************************

View File

@ -96,6 +96,19 @@ extern "C"
*******************************************************************************/ *******************************************************************************/
extern tBTA_SDP_STATUS BTA_SdpEnable(tBTA_SDP_DM_CBACK *p_cback); 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 ** Function BTA_SdpSearch

View File

@ -215,7 +215,7 @@ extern "C" {
extern void bta_sys_init(void); extern void bta_sys_init(void);
extern void bta_sys_free(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_set_trace_level(UINT8 level);
extern void bta_sys_register(UINT8 id, const tBTA_SYS_REG *p_reg); extern void bta_sys_register(UINT8 id, const tBTA_SYS_REG *p_reg);
extern void bta_sys_deregister(UINT8 id); extern void bta_sys_deregister(UINT8 id);

View File

@ -67,8 +67,17 @@ tBTA_JV_STATUS BTA_JvEnable(tBTA_JV_DM_CBACK *p_cback)
tBTA_JV_STATUS status = BTA_JV_FAILURE; tBTA_JV_STATUS status = BTA_JV_FAILURE;
tBTA_JV_API_ENABLE *p_buf; tBTA_JV_API_ENABLE *p_buf;
int i; int i;
APPL_TRACE_API( "BTA_JvEnable"); 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)) { if (p_cback && FALSE == bta_sys_is_register(BTA_ID_JV)) {
memset(&bta_jv_cb, 0, sizeof(tBTA_JV_CB)); memset(&bta_jv_cb, 0, sizeof(tBTA_JV_CB));
/* set handle to invalid value by default */ /* set handle to invalid value by default */
@ -110,6 +119,14 @@ void BTA_JvDisable(void)
p_buf->event = BTA_JV_API_DISABLE_EVT; p_buf->event = BTA_JV_API_DISABLE_EVT;
bta_sys_sendmsg(p_buf); 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
} }
/******************************************************************************* /*******************************************************************************

View File

@ -43,15 +43,22 @@
* between BTA_JvEnable and BTA_JvDisable * between BTA_JvEnable and BTA_JvDisable
* p_bta_jv_cfg->p_sdp_raw_data can be allocated before calling BTA_JvStartDiscovery * 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 */ * 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 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]; static UINT8 __attribute__ ((aligned(4))) bta_jv_sdp_db_data[BTA_JV_SDP_DB_SIZE];
#endif
/* JV configuration structure */ /* 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_RAW_DATA_SIZE, /* The size of p_sdp_raw_data */
BTA_JV_SDP_DB_SIZE, /* The size of p_sdp_db_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 */ 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 */ (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; tBTA_JV_CFG *p_bta_jv_cfg = (tBTA_JV_CFG *) &bta_jv_cfg;

View File

@ -35,6 +35,8 @@
#if BTA_DYNAMIC_MEMORY == FALSE #if BTA_DYNAMIC_MEMORY == FALSE
tBTA_JV_CB bta_jv_cb; tBTA_JV_CB bta_jv_cb;
#else
tBTA_JV_CB *bta_jv_cb_ptr;
#endif #endif
/* state machine action enumeration list */ /* state machine action enumeration list */

View File

@ -61,6 +61,15 @@ tBTA_SDP_STATUS BTA_SdpEnable(tBTA_SDP_DM_CBACK *p_cback)
tBTA_SDP_API_ENABLE *p_buf; tBTA_SDP_API_ENABLE *p_buf;
APPL_TRACE_API("%s\n", __FUNCTION__); 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)) { if (p_cback && FALSE == bta_sys_is_register(BTA_ID_SDP)) {
memset(&bta_sdp_cb, 0, sizeof(tBTA_SDP_CB)); 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); 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 ** Function BTA_SdpSearch

View File

@ -30,12 +30,18 @@
#define BTA_SDP_DB_SIZE 1500 #define BTA_SDP_DB_SIZE 1500
#endif #endif
#if BTA_DYNAMIC_MEMORY == FALSE
static UINT8 __attribute__ ((aligned(4))) bta_sdp_db_data[BTA_SDP_DB_SIZE]; static UINT8 __attribute__ ((aligned(4))) bta_sdp_db_data[BTA_SDP_DB_SIZE];
#endif
/* SDP configuration structure */ /* SDP configuration structure */
const tBTA_SDP_CFG bta_sdp_cfg = { tBTA_SDP_CFG bta_sdp_cfg = {
BTA_SDP_DB_SIZE, BTA_SDP_DB_SIZE,
#if BTA_DYNAMIC_MEMORY == FALSE
(tSDP_DISCOVERY_DB *)bta_sdp_db_data /* The data buffer to keep SDP database */ (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; tBTA_SDP_CFG *p_bta_sdp_cfg = (tBTA_SDP_CFG *) &bta_sdp_cfg;

View File

@ -29,6 +29,7 @@
#include "osi/alarm.h" #include "osi/alarm.h"
#include "osi/thread.h" #include "osi/thread.h"
#include "stack/btm_api.h" #include "stack/btm_api.h"
#include "stack/btu.h"
#include "bta/bta_api.h" #include "bta/bta_api.h"
#include "bta/bta_sys.h" #include "bta/bta_sys.h"
#include "bta_sys_int.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 ** 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; UINT8 id;
BOOLEAN freebuf = TRUE; 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 // 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 // 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. // 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); osi_free(p_msg);
} }
} }
@ -591,7 +594,7 @@ void bta_alarm_cb(void *data)
assert(data != NULL); assert(data != NULL);
TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data; 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) void bta_sys_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, INT32 timeout_ms)

View File

@ -96,6 +96,7 @@ void btc_storage_save(void)
btc_config_unlock(); btc_config_unlock();
} }
#if (BLE_INCLUDED == TRUE)
static bt_status_t _btc_storage_add_ble_bonding_key(bt_bdaddr_t *remote_bd_addr, static bt_status_t _btc_storage_add_ble_bonding_key(bt_bdaddr_t *remote_bd_addr,
char *key, char *key,
uint8_t key_type, 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; 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) 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; 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, 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) const uint8_t addr_type, const bool add_key, bool *device_added, bool *key_found)
{ {
@ -926,5 +929,6 @@ int btc_storage_get_num_ble_bond_devices(void)
return num_dev; return num_dev;
} }
#endif ///BLE_INCLUDED == TRUE
#endif ///SMP_INCLUDED == TRUE #endif ///SMP_INCLUDED == TRUE

View File

@ -337,4 +337,3 @@ void btc_config_unlock(void)
{ {
osi_mutex_unlock(&lock); osi_mutex_unlock(&lock);
} }

View File

@ -41,10 +41,10 @@
/****************************************************************************** /******************************************************************************
** Static variables ** Static variables
******************************************************************************/ ******************************************************************************/
static tBTA_SERVICE_MASK btc_enabled_services = 0; #if BTC_DYNAMIC_MENDRY == FALSE
#if (SMP_INCLUDED == TRUE) btc_dm_cb_t btc_dm_cb = {0};
static btc_dm_pairing_cb_t pairing_cb; #else
static btc_dm_local_key_cb_t ble_local_key_cb; btc_dm_cb_t *btc_dm_cb_ptr;
#endif #endif
/****************************************************************************** /******************************************************************************
@ -129,23 +129,24 @@ static void btc_disable_bluetooth_evt(void)
} }
#if (SMP_INCLUDED == TRUE) #if (SMP_INCLUDED == TRUE)
#if (BLE_INCLUDED == TRUE)
void btc_dm_load_ble_local_keys(void) 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) { 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__ ); 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 )&& 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)&& 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)) { 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__); 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, 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) tBTA_BLE_LOCAL_ID_KEYS *p_id_keys)
{ {
if (ble_local_key_cb.is_er_rcvd ) { if (btc_dm_cb.ble_local_key_cb.is_er_rcvd ) {
memcpy(&er[0], &ble_local_key_cb.er[0], sizeof(BT_OCTET16)); memcpy(&er[0], &btc_dm_cb.ble_local_key_cb.er[0], sizeof(BT_OCTET16));
*p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ER; *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ER;
} }
if (ble_local_key_cb.is_id_keys_rcvd) { if (btc_dm_cb.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->ir[0], &btc_dm_cb.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->irk[0], &btc_dm_cb.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)); 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; *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ID;
} }
BTC_TRACE_DEBUG("%s *p_key_mask=0x%02x",__func__, *p_key_mask); 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; bt_bdaddr_t bd_addr;
BTC_TRACE_DEBUG("%s\n",__func__); 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_remote_addr_type(&bd_addr, false);
btc_storage_remove_ble_dev_auth_mode(&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) 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 || 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 ||
pairing_cb.ble.is_lenc_key_rcvd || pairing_cb.ble.is_lcsrk_key_rcvd || pairing_cb.ble.is_lidk_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 ; return ;
} }
bt_bdaddr_t bd_addr; 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_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); 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 (pairing_cb.ble.is_penc_key_rcvd) { if (btc_dm_cb.pairing_cb.ble.is_penc_key_rcvd) {
btc_storage_add_ble_bonding_key(&bd_addr, 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, BTM_LE_KEY_PENC,
sizeof(tBTM_LE_PENC_KEYS)); 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, 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, BTM_LE_KEY_PID,
sizeof(tBTM_LE_PID_KEYS)); 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, 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, BTM_LE_KEY_PCSRK,
sizeof(tBTM_LE_PCSRK_KEYS)); 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, 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, BTM_LE_KEY_LENC,
sizeof(tBTM_LE_LENC_KEYS)); 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, 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, BTM_LE_KEY_LCSRK,
sizeof(tBTM_LE_LCSRK_KEYS)); 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, btc_storage_add_ble_bonding_key(&bd_addr,
NULL, NULL,
BTM_LE_KEY_LID, BTM_LE_KEY_LID,
0); 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; int addr_type;
bt_bdaddr_t bdaddr; bt_bdaddr_t bdaddr;
bdcpy(bdaddr.address, p_auth_cmpl->bd_addr); 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) { if (p_auth_cmpl->success) {
status = BT_STATUS_SUCCESS; status = BT_STATUS_SUCCESS;
BTC_TRACE_DEBUG ("%s, - p_auth_cmpl->bd_addr: %08x%04x", __func__, 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[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]); (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 // Check if need to save BLE keys
if((p_auth_cmpl->auth_mode & SMP_AUTH_GEN_BOND) == 0) { if((p_auth_cmpl->auth_mode & SMP_AUTH_GEN_BOND) == 0) {
return; return;
} }
if (btc_storage_get_remote_addr_type(&bdaddr, &addr_type) != BT_STATUS_SUCCESS) { 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); 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; return;
} }
#endif ///BLE_INCLUDED == TRUE
#endif ///SMP_INCLUDED == TRUE #endif ///SMP_INCLUDED == TRUE
static void btc_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl) 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) 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) 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, 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; 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); 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; 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); 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(); btc_clear_services_mask();
#if (SMP_INCLUDED == TRUE) #if (SMP_INCLUDED == TRUE)
btc_storage_load_bonded_devices(); btc_storage_load_bonded_devices();
#if (BLE_INCLUDED == TRUE)
//load the bonding device to the btm layer //load the bonding device to the btm layer
btc_storage_load_bonded_ble_devices(); btc_storage_load_bonded_ble_devices();
#endif ///BLE_INCLUDED == TRUE
#endif ///SMP_INCLUDED == TRUE #endif ///SMP_INCLUDED == TRUE
/* Set initial device name, it can be overwritten later */ /* 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) */ #endif /* #if (SMP_INCLUDED == TRUE) */
break; break;
} }
#if (BLE_INCLUDED == TRUE)
case BTA_DM_BLE_DEV_UNPAIRED_EVT: { case BTA_DM_BLE_DEV_UNPAIRED_EVT: {
#if (SMP_INCLUDED == TRUE) #if (SMP_INCLUDED == TRUE)
bt_bdaddr_t bd_addr; bt_bdaddr_t bd_addr;
@ -655,6 +659,7 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
#endif /* #if (SMP_INCLUDED == TRUE) */ #endif /* #if (SMP_INCLUDED == TRUE) */
break; break;
} }
#endif ///BLE_INCLUDED == TRUE
case BTA_DM_BUSY_LEVEL_EVT: case BTA_DM_BUSY_LEVEL_EVT:
#if (BTC_GAP_BT_INCLUDED == TRUE) #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: case BTA_DM_HW_ERROR_EVT:
BTC_TRACE_DEBUG( "btc_dm_sec_cback : unhandled event (%d)\n", msg->act ); BTC_TRACE_DEBUG( "btc_dm_sec_cback : unhandled event (%d)\n", msg->act );
break; 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: { case BTA_DM_BLE_AUTH_CMPL_EVT: {
rsp_app = true; rsp_app = true;
ble_msg.act = ESP_GAP_BLE_AUTH_CMPL_EVT; 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) { switch (p_data->ble_key.key_type) {
case BTM_LE_KEY_PENC: { case BTM_LE_KEY_PENC: {
BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_PENC"); BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_PENC");
pairing_cb.ble.is_penc_key_rcvd = TRUE; btc_dm_cb.pairing_cb.ble.is_penc_key_rcvd = TRUE;
pairing_cb.ble.penc_key = p_data->ble_key.p_key_value->penc_key; btc_dm_cb.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, memcpy(&btc_dm_cb.pairing_cb.ble.penc_key, &p_data->ble_key.p_key_value->penc_key,
sizeof(tBTM_LE_PENC_KEYS)); sizeof(tBTM_LE_PENC_KEYS));
memcpy(&param.ble_security.ble_key.p_key_value.penc_key, memcpy(&param.ble_security.ble_key.p_key_value.penc_key,
&p_data->ble_key.p_key_value->penc_key, sizeof(tBTM_LE_PENC_KEYS)); &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: { case BTM_LE_KEY_PID: {
BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_PID"); BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_PID");
pairing_cb.ble.is_pid_key_rcvd = TRUE; btc_dm_cb.pairing_cb.ble.is_pid_key_rcvd = TRUE;
memcpy(&pairing_cb.ble.pid_key, &p_data->ble_key.p_key_value->pid_key, memcpy(&btc_dm_cb.pairing_cb.ble.pid_key, &p_data->ble_key.p_key_value->pid_key,
sizeof(tBTM_LE_PID_KEYS)); sizeof(tBTM_LE_PID_KEYS));
memcpy(&param.ble_security.ble_key.p_key_value.pid_key, memcpy(&param.ble_security.ble_key.p_key_value.pid_key,
&p_data->ble_key.p_key_value->pid_key, sizeof(tBTM_LE_PID_KEYS)); &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: { case BTM_LE_KEY_PCSRK: {
BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_PCSRK"); BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_PCSRK");
pairing_cb.ble.is_pcsrk_key_rcvd = TRUE; btc_dm_cb.pairing_cb.ble.is_pcsrk_key_rcvd = TRUE;
memcpy(&pairing_cb.ble.pcsrk_key, &p_data->ble_key.p_key_value->pcsrk_key, memcpy(&btc_dm_cb.pairing_cb.ble.pcsrk_key, &p_data->ble_key.p_key_value->pcsrk_key,
sizeof(tBTM_LE_PCSRK_KEYS)); sizeof(tBTM_LE_PCSRK_KEYS));
memcpy(&param.ble_security.ble_key.p_key_value.pcsrk_key, memcpy(&param.ble_security.ble_key.p_key_value.pcsrk_key,
&p_data->ble_key.p_key_value->pcsrk_key, sizeof(tBTM_LE_PCSRK_KEYS)); &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: { case BTM_LE_KEY_LENC: {
BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_LENC"); BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_LENC");
pairing_cb.ble.is_lenc_key_rcvd = TRUE; btc_dm_cb.pairing_cb.ble.is_lenc_key_rcvd = TRUE;
memcpy(&pairing_cb.ble.lenc_key, &p_data->ble_key.p_key_value->lenc_key, memcpy(&btc_dm_cb.pairing_cb.ble.lenc_key, &p_data->ble_key.p_key_value->lenc_key,
sizeof(tBTM_LE_LENC_KEYS)); sizeof(tBTM_LE_LENC_KEYS));
memcpy(&param.ble_security.ble_key.p_key_value.lenc_key, memcpy(&param.ble_security.ble_key.p_key_value.lenc_key,
&p_data->ble_key.p_key_value->lenc_key, sizeof(tBTM_LE_LENC_KEYS)); &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: { case BTM_LE_KEY_LCSRK: {
BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_LCSRK"); BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_LCSRK");
pairing_cb.ble.is_lcsrk_key_rcvd = TRUE; btc_dm_cb.pairing_cb.ble.is_lcsrk_key_rcvd = TRUE;
memcpy(&pairing_cb.ble.lcsrk_key, &p_data->ble_key.p_key_value->lcsrk_key, memcpy(&btc_dm_cb.pairing_cb.ble.lcsrk_key, &p_data->ble_key.p_key_value->lcsrk_key,
sizeof(tBTM_LE_LCSRK_KEYS)); sizeof(tBTM_LE_LCSRK_KEYS));
memcpy(&param.ble_security.ble_key.p_key_value.lcsrk_key, memcpy(&param.ble_security.ble_key.p_key_value.lcsrk_key,
&p_data->ble_key.p_key_value->lcsrk_key, sizeof(tBTM_LE_LCSRK_KEYS)); &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: { case BTM_LE_KEY_LID: {
BTC_TRACE_DEBUG("Rcv BTA_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; break;
} }
default: default:
@ -778,20 +783,20 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
ble_msg.act = ESP_GAP_BLE_LOCAL_IR_EVT; ble_msg.act = ESP_GAP_BLE_LOCAL_IR_EVT;
memcpy(&param.ble_security.ble_id_keys, &p_data->ble_id_keys, sizeof(tBTA_BLE_LOCAL_ID_KEYS)); memcpy(&param.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. "); BTC_TRACE_DEBUG("BTA_DM_BLE_LOCAL_IR_EVT. ");
ble_local_key_cb.is_id_keys_rcvd = TRUE; btc_dm_cb.ble_local_key_cb.is_id_keys_rcvd = TRUE;
memcpy(&ble_local_key_cb.id_keys.irk[0], memcpy(&btc_dm_cb.ble_local_key_cb.id_keys.irk[0],
&p_data->ble_id_keys.irk[0], sizeof(BT_OCTET16)); &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)); &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)); &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, BTC_LE_LOCAL_KEY_IRK,
BT_OCTET16_LEN); 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, BTC_LE_LOCAL_KEY_IR,
BT_OCTET16_LEN); 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, BTC_LE_LOCAL_KEY_DHK,
BT_OCTET16_LEN); BT_OCTET16_LEN);
break; break;
@ -801,9 +806,9 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
ble_msg.act = ESP_GAP_BLE_LOCAL_ER_EVT; ble_msg.act = ESP_GAP_BLE_LOCAL_ER_EVT;
memcpy(&param.ble_security.ble_id_keys, &p_data->ble_id_keys, sizeof(tBTA_BLE_LOCAL_ID_KEYS)); memcpy(&param.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. "); BTC_TRACE_DEBUG("BTA_DM_BLE_LOCAL_ER_EVT. ");
ble_local_key_cb.is_er_rcvd = TRUE; btc_dm_cb.ble_local_key_cb.is_er_rcvd = TRUE;
memcpy(&ble_local_key_cb.er[0], &p_data->ble_er[0], sizeof(BT_OCTET16)); 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 *)&ble_local_key_cb.er[0], btc_storage_add_ble_local_key( (char *)&btc_dm_cb.ble_local_key_cb.er[0],
BTC_LE_LOCAL_KEY_ER, BTC_LE_LOCAL_KEY_ER,
BT_OCTET16_LEN); BT_OCTET16_LEN);
break; break;

View File

@ -64,15 +64,20 @@ static void btc_init_bluetooth(void)
bte_main_boot_entry(btc_init_callback); bte_main_boot_entry(btc_init_callback);
#if (SMP_INCLUDED) #if (SMP_INCLUDED)
btc_config_init(); btc_config_init();
#if (BLE_INCLUDED == TRUE)
//load the ble local key which has been stored in the flash //load the ble local key which has been stored in the flash
btc_dm_load_ble_local_keys(); btc_dm_load_ble_local_keys();
#endif ///BLE_INCLUDED == TRUE
#endif /* #if (SMP_INCLUDED) */ #endif /* #if (SMP_INCLUDED) */
} }
static void btc_deinit_bluetooth(void) static void btc_deinit_bluetooth(void)
{ {
#if (BLE_INCLUDED == TRUE)
btc_gap_ble_deinit(); btc_gap_ble_deinit();
#endif ///BLE_INCLUDED == TRUE
bta_dm_sm_deinit(); bta_dm_sm_deinit();
#if (GATTC_INCLUDED) #if (GATTC_INCLUDED)
bta_gattc_deinit(); bta_gattc_deinit();

View File

@ -19,7 +19,11 @@
#include "esp_bt_defs.h" #include "esp_bt_defs.h"
#include "esp_gatt_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) void esp_profile_cb_reset(void)
{ {

View File

@ -21,16 +21,18 @@
#include "common/bt_defs.h" #include "common/bt_defs.h"
#include "osi/allocator.h" #include "osi/allocator.h"
#include "btc/btc_main.h" #include "btc/btc_main.h"
#include "btc/btc_manage.h"
#include "btc/btc_dev.h" #include "btc/btc_dev.h"
#include "btc_gatts.h" #include "btc_gatts.h"
#include "btc_gattc.h" #include "btc_gattc.h"
#include "btc_gatt_common.h" #include "btc_gatt_common.h"
#include "btc_gap_ble.h" #include "btc_gap_ble.h"
#include "btc_blufi_prf.h" #include "btc_blufi_prf.h"
#include "blufi_int.h"
#include "btc/btc_dm.h" #include "btc/btc_dm.h"
#include "btc/btc_alarm.h" #include "btc/btc_alarm.h"
#include "bta/bta_gatt_api.h" #include "bta/bta_gatt_api.h"
#if CONFIG_BT_CLASSIC_ENABLED #if CLASSIC_BT_INCLUDED
#include "btc/btc_profile_queue.h" #include "btc/btc_profile_queue.h"
#if (BTC_GAP_BT_INCLUDED == TRUE) #if (BTC_GAP_BT_INCLUDED == TRUE)
#include "btc_gap_bt.h" #include "btc_gap_bt.h"
@ -38,20 +40,24 @@
#if BTC_AV_INCLUDED #if BTC_AV_INCLUDED
#include "btc_av.h" #include "btc_av.h"
#include "btc_avrc.h" #include "btc_avrc.h"
#include "btc_av_co.h"
#endif /* #if BTC_AV_INCLUDED */ #endif /* #if BTC_AV_INCLUDED */
#if CONFIG_BT_SPP_ENABLED #if (BTC_SPP_INCLUDED == TRUE)
#include "btc_spp.h" #include "btc_spp.h"
#endif /* #if CONFIG_BT_SPP_ENABLED */ #endif /* #if (BTC_SPP_INCLUDED == TRUE) */
#if BTC_HF_CLIENT_INCLUDED #if BTC_HF_CLIENT_INCLUDED
#include "btc_hf_client.h" #include "btc_hf_client.h"
#endif /* #if BTC_HF_CLIENT_INCLUDED */ #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; osi_thread_t *btc_thread;
static xQueueHandle xBtcQueue = 0;
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_MAIN_INIT] = {btc_main_call_handler, NULL },
[BTC_PID_DEV] = {btc_dev_call_handler, NULL }, [BTC_PID_DEV] = {btc_dev_call_handler, NULL },
#if (GATTS_INCLUDED == TRUE) #if (GATTS_INCLUDED == TRUE)
@ -63,7 +69,11 @@ static btc_func_t profile_tab[BTC_PID_NUM] = {
#if (GATTS_INCLUDED == TRUE || GATTC_INCLUDED == TRUE) #if (GATTS_INCLUDED == TRUE || GATTC_INCLUDED == TRUE)
[BTC_PID_GATT_COMMON] = {btc_gatt_com_call_handler, NULL }, [BTC_PID_GATT_COMMON] = {btc_gatt_com_call_handler, NULL },
#endif //GATTC_INCLUDED == TRUE || GATTS_INCLUDED == TRUE #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 }, [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_BLE_HID] = {NULL, NULL},
[BTC_PID_SPPLIKE] = {NULL, NULL}, [BTC_PID_SPPLIKE] = {NULL, NULL},
#if (GATTS_INCLUDED == TRUE) #if (GATTS_INCLUDED == TRUE)
@ -71,7 +81,7 @@ static btc_func_t profile_tab[BTC_PID_NUM] = {
#endif ///GATTS_INCLUDED == TRUE #endif ///GATTS_INCLUDED == TRUE
[BTC_PID_DM_SEC] = {NULL, btc_dm_sec_cb_handler }, [BTC_PID_DM_SEC] = {NULL, btc_dm_sec_cb_handler },
[BTC_PID_ALARM] = {btc_alarm_handler, NULL }, [BTC_PID_ALARM] = {btc_alarm_handler, NULL },
#if CONFIG_BT_CLASSIC_ENABLED #if CLASSIC_BT_INCLUDED
#if (BTC_GAP_BT_INCLUDED == TRUE) #if (BTC_GAP_BT_INCLUDED == TRUE)
[BTC_PID_GAP_BT] = {btc_gap_bt_call_handler, btc_gap_bt_cb_handler }, [BTC_PID_GAP_BT] = {btc_gap_bt_call_handler, btc_gap_bt_cb_handler },
#endif /* (BTC_GAP_BT_INCLUDED == TRUE) */ #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_CT] = {btc_avrc_ct_call_handler, NULL },
[BTC_PID_AVRC_TG] = {btc_avrc_tg_call_handler, NULL }, [BTC_PID_AVRC_TG] = {btc_avrc_tg_call_handler, NULL },
#endif /* #if BTC_AV_INCLUDED */ #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 }, [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 #if BTC_HF_CLIENT_INCLUDED
[BTC_PID_HF_CLIENT] = {btc_hf_client_call_handler, btc_hf_client_cb_handler}, [BTC_PID_HF_CLIENT] = {btc_hf_client_call_handler, btc_hf_client_cb_handler},
#endif /* #if BTC_HF_CLIENT_INCLUDED */ #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. ** 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 (;;) { BTC_TRACE_DEBUG("%s msg %u %u %u %p\n", __func__, msg->sig, msg->pid, msg->act, msg->arg);
if (pdTRUE == xQueueReceive(xBtcQueue, &msg, (portTickType)portMAX_DELAY)) { switch (msg->sig) {
BTC_TRACE_DEBUG("%s msg %u %u %u %p\n", __func__, msg.sig, msg.pid, msg.act, msg.arg); case BTC_SIG_API_CALL:
switch (msg.sig) { profile_tab[msg->pid].btc_call(msg);
case BTC_SIG_API_CALL: break;
profile_tab[msg.pid].btc_call(&msg); case BTC_SIG_API_CB:
break; profile_tab[msg->pid].btc_cb(msg);
case BTC_SIG_API_CB: break;
profile_tab[msg.pid].btc_cb(&msg); default:
break; break;
default:
break;
}
if (msg.arg) {
osi_free(msg.arg);
}
}
} }
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) { btc_msg_t *lmsg;
return BT_STATUS_PARM_INVALID;
lmsg = (btc_msg_t *)osi_malloc(sizeof(btc_msg_t));
if (lmsg == NULL) {
return BT_STATUS_NOMEM;
} }
if (xQueueSend(xBtcQueue, msg, timeout) != pdTRUE) { memcpy(lmsg, msg, sizeof(btc_msg_t));
BTC_TRACE_ERROR("Btc Post failed\n");
if (osi_thread_post(btc_thread, btc_thread_handler, lmsg, 2, timeout) == false) {
return BT_STATUS_BUSY; 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; 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) int btc_init(void)
{ {
xBtcQueue = xQueueCreate(BTC_TASK_QUEUE_LEN, sizeof(btc_msg_t)); btc_thread = osi_thread_create("BTC_TASK", BTC_TASK_STACK_SIZE, BTC_TASK_PRIO, BTC_TASK_PINNED_TO_CORE, 3);
xTaskCreatePinnedToCore(btc_task, "Btc_task", BTC_TASK_STACK_SIZE, NULL, BTC_TASK_PRIO, &xBtcTaskHandle, BTC_TASK_PINNED_TO_CORE); if (btc_thread == NULL) {
if (xBtcTaskHandle == NULL || xBtcQueue == 0){
return BT_STATUS_NOMEM; 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(); btc_gap_callback_init();
#endif ///BLE_INCLUDED == TRUE
#if SCAN_QUEUE_CONGEST_CHECK #if SCAN_QUEUE_CONGEST_CHECK
btc_adv_list_init(); btc_adv_list_init();
#endif #endif
@ -180,20 +318,23 @@ int btc_init(void)
void btc_deinit(void) void btc_deinit(void)
{ {
vTaskDelete(xBtcTaskHandle); #if BTC_DYNAMIC_MENDRY
vQueueDelete(xBtcQueue); btc_deinit_mem();
#endif
osi_thread_free(btc_thread);
btc_thread = NULL;
#if SCAN_QUEUE_CONGEST_CHECK #if SCAN_QUEUE_CONGEST_CHECK
btc_adv_list_deinit(); btc_adv_list_deinit();
#endif #endif
xBtcTaskHandle = NULL;
xBtcQueue = 0;
} }
bool btc_check_queue_is_congest(void) bool btc_check_queue_is_congest(void)
{ {
UBaseType_t wait_size = uxQueueMessagesWaiting(xBtcQueue); if (osi_thread_queue_wait_size(btc_thread, 2) >= QUEUE_CONGEST_SIZE) {
if(wait_size >= QUEUE_CONGEST_SIZE) {
return true; return true;
} }
return false; return false;
} }

View File

@ -66,7 +66,21 @@ typedef struct
btc_dm_local_key_id_t id_keys; /* ID kyes */ btc_dm_local_key_id_t id_keys; /* ID kyes */
} btc_dm_local_key_cb_t; } 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_call_handler(btc_msg_t *msg);
void btc_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *data); void btc_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *data);

View File

@ -19,6 +19,11 @@
#include "btc/btc_task.h" #include "btc/btc_task.h"
#include "esp_bt_defs.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 */ /* reset gatt callback table */
void esp_profile_cb_reset(void); void esp_profile_cb_reset(void);

View File

@ -53,17 +53,17 @@ typedef enum {
BTC_PID_BLUFI, BTC_PID_BLUFI,
BTC_PID_DM_SEC, BTC_PID_DM_SEC,
BTC_PID_ALARM, BTC_PID_ALARM,
#if CONFIG_BT_CLASSIC_ENABLED #if (CLASSIC_BT_INCLUDED == TRUE)
BTC_PID_GAP_BT, BTC_PID_GAP_BT,
BTC_PID_PRF_QUE, BTC_PID_PRF_QUE,
BTC_PID_A2DP, BTC_PID_A2DP,
BTC_PID_AVRC_CT, BTC_PID_AVRC_CT,
BTC_PID_AVRC_TG, BTC_PID_AVRC_TG,
BTC_PID_SPP, BTC_PID_SPP,
#if BTC_HF_CLIENT_INCLUDED #if (BTC_HF_CLIENT_INCLUDED == TRUE)
BTC_PID_HF_CLIENT, BTC_PID_HF_CLIENT,
#endif /* BTC_HF_CLIENT_INCLUDED */ #endif /* BTC_HF_CLIENT_INCLUDED */
#endif /* CONFIG_BT_CLASSIC_ENABLED */ #endif /* CLASSIC_BT_INCLUDED */
BTC_PID_NUM, BTC_PID_NUM,
} btc_pid_t; //btc profile id } btc_pid_t; //btc profile id

View File

@ -55,13 +55,17 @@
#define BLUFI_HDL_NUM 6 #define BLUFI_HDL_NUM 6
#if GATT_DYNAMIC_MEMORY == FALSE
tBLUFI_ENV blufi_env; 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_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_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_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_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_app_uuid = {LEN_UUID_16, {BLUFI_APP_UUID}};
// static functions declare // static functions declare
static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data); static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data);

View File

@ -36,7 +36,7 @@
//#include "esp_wifi.h" //#include "esp_wifi.h"
#if (GATTS_INCLUDED == TRUE) #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) void btc_blufi_protocol_handler(uint8_t type, uint8_t *data, int len)
{ {

View File

@ -68,6 +68,13 @@ struct blufi_frag_hdr {
}; };
typedef struct blufi_frag_hdr blufi_frag_hdr_t; typedef struct blufi_frag_hdr blufi_frag_hdr_t;
#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_CHECK_MASK 0x01
#define BLUFI_DATA_SEC_MODE_ENC_MASK 0x02 #define BLUFI_DATA_SEC_MODE_ENC_MASK 0x02
#define BLUFI_CTRL_SEC_MODE_CHECK_MASK 0x10 #define BLUFI_CTRL_SEC_MODE_CHECK_MASK 0x10

View File

@ -105,58 +105,12 @@ const tA2D_SBC_CIE btc_av_sbc_default_config = {
A2D_SBC_IE_MIN_BITPOOL /* min_bitpool */ 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 */ /* 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 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); 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 */ /* 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_init,
bta_av_co_audio_disc_res, bta_av_co_audio_disc_res,
bta_av_co_audio_getconfig, bta_av_co_audio_getconfig,

View File

@ -45,6 +45,8 @@
#if (BTC_AV_SINK_INCLUDED == TRUE) #if (BTC_AV_SINK_INCLUDED == TRUE)
extern osi_thread_t *btc_thread;
/***************************************************************************** /*****************************************************************************
** Constants ** Constants
*****************************************************************************/ *****************************************************************************/
@ -64,10 +66,6 @@ enum {
BTC_A2DP_SINK_STATE_SHUTTING_DOWN = 2 BTC_A2DP_SINK_STATE_SHUTTING_DOWN = 2
}; };
enum {
BTC_A2DP_SINK_DATA_EVT = 0,
};
/* /*
* CONGESTION COMPENSATION CTRL :: * 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 */ /* 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) #define MAX_OUTPUT_A2DP_SNK_FRAME_QUEUE_SZ (18)
typedef struct {
uint32_t sig;
void *param;
} a2dp_sink_task_evt_t;
typedef struct { typedef struct {
UINT16 num_frames_to_be_processed; UINT16 num_frames_to_be_processed;
UINT16 len; UINT16 len;
@ -104,6 +107,15 @@ typedef struct {
UINT32 sample_rate; UINT32 sample_rate;
} tBTC_A2DP_SINK_CB; } 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_init(UNUSED_ATTR void *context);
static void btc_a2dp_sink_thread_cleanup(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); 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_decoder_reset(tBTC_MEDIA_SINK_CFG_UPDATE *p_msg);
static void btc_a2dp_sink_handle_clear_track(void); static void btc_a2dp_sink_handle_clear_track(void);
static BOOLEAN btc_a2dp_sink_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 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; 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) 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 ** 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 ** 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) { if (evt == NULL) {
return; return false;
} }
evt->sig = sig; evt->sig = sig;
evt->par = par; evt->param = param;
if (xQueueSend(btc_aa_snk_ctrl_queue, &evt, portMAX_DELAY) != pdTRUE) { return osi_thread_post(a2dp_sink_local_param.btc_aa_snk_task_hdl, btc_a2dp_sink_ctrl_handler, evt, 0, OSI_THREAD_MAX_TIMEOUT);
APPL_TRACE_WARNING("btc_aa_snk_ctrl_queue failed, sig 0x%x\n", sig);
}
} }
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) { if (e == NULL) {
return; return;
} }
switch (e->sig) { switch (e->sig) {
case BTC_MEDIA_TASK_SINK_INIT: case BTC_MEDIA_TASK_SINK_INIT:
btc_a2dp_sink_thread_init(NULL); 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); btc_a2dp_sink_thread_cleanup(NULL);
break; break;
case BTC_MEDIA_AUDIO_SINK_CFG_UPDATE: case BTC_MEDIA_AUDIO_SINK_CFG_UPDATE:
btc_a2dp_sink_handle_decoder_reset(e->par); btc_a2dp_sink_handle_decoder_reset(e->param);
break; break;
case BTC_MEDIA_AUDIO_SINK_CLEAR_TRACK: case BTC_MEDIA_AUDIO_SINK_CLEAR_TRACK:
btc_a2dp_sink_handle_clear_track(); btc_a2dp_sink_handle_clear_track();
@ -213,29 +212,12 @@ static void btc_a2dp_sink_ctrl_handler(BtTaskEvt_t *e)
default: default:
APPL_TRACE_WARNING("media task unhandled evt: 0x%x\n", e->sig); 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) if (e->param != NULL) {
{ osi_free(e->param);
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);
}
} }
osi_free(e);
} }
bool btc_a2dp_sink_startup(void) bool btc_a2dp_sink_startup(void)
@ -245,38 +227,21 @@ bool btc_a2dp_sink_startup(void)
return false; 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 ##"); APPL_TRACE_EVENT("## A2DP SINK START MEDIA THREAD ##");
#if (BTC_SBC_DEC_DYNAMIC_MEMORY == TRUE) a2dp_sink_local_param.btc_aa_snk_task_hdl = btc_thread;
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)); if (btc_a2dp_sink_ctrl_post(BTC_MEDIA_TASK_SINK_INIT, NULL) == false) {
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");
goto error_exit; 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"); APPL_TRACE_EVENT("## A2DP SINK MEDIA THREAD STARTED ##\n");
@ -284,38 +249,12 @@ bool btc_a2dp_sink_startup(void)
error_exit:; error_exit:;
APPL_TRACE_ERROR("%s unable to start up media thread\n", __func__); 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) { #if A2D_DYNAMIC_MEMORY == TRUE
vTaskDelete(btc_aa_snk_task_hdl); osi_free(a2dp_sink_local_param_ptr);
btc_aa_snk_task_hdl = NULL; a2dp_sink_local_param_ptr = NULL;
} #endif
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 */
return false; return false;
} }
@ -326,34 +265,18 @@ void btc_a2dp_sink_shutdown(void)
// Exit thread // Exit thread
btc_a2dp_sink_state = BTC_A2DP_SINK_STATE_SHUTTING_DOWN; btc_a2dp_sink_state = BTC_A2DP_SINK_STATE_SHUTTING_DOWN;
btc_a2dp_sink_future = future_new(); a2dp_sink_local_param.btc_a2dp_sink_future = future_new();
assert(btc_a2dp_sink_future); assert(a2dp_sink_local_param.btc_a2dp_sink_future);
btc_a2dp_sink_ctrl_post(BTC_MEDIA_TASK_SINK_CLEAN_UP, NULL); btc_a2dp_sink_ctrl_post(BTC_MEDIA_TASK_SINK_CLEAN_UP, NULL);
future_await(btc_a2dp_sink_future); future_await(a2dp_sink_local_param.btc_a2dp_sink_future);
btc_a2dp_sink_future = NULL; a2dp_sink_local_param.btc_a2dp_sink_future = NULL;
vTaskDelete(btc_aa_snk_task_hdl); a2dp_sink_local_param.btc_aa_snk_task_hdl = NULL;
btc_aa_snk_task_hdl = NULL;
vQueueDelete(btc_aa_snk_data_queue); #if A2D_DYNAMIC_MEMORY == TRUE
btc_aa_snk_data_queue = NULL; osi_free(a2dp_sink_local_param_ptr);
a2dp_sink_local_param_ptr = NULL;
vQueueDelete(btc_aa_snk_ctrl_queue); #endif
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 */
} }
/***************************************************************************** /*****************************************************************************
@ -364,7 +287,7 @@ void btc_a2dp_sink_shutdown(void)
void btc_a2dp_sink_on_idle(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_rx_flush_req();
btc_a2dp_sink_clear_track(); 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) 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_sink_rx_flush_req();
btc_a2dp_control_set_datachnl_stat(FALSE); 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) 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(); btc_a2dp_sink_rx_flush_req();
return; 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) { osi_thread_post(a2dp_sink_local_param.btc_aa_snk_task_hdl, btc_a2dp_sink_data_ready, NULL, 1, OSI_THREAD_MAX_TIMEOUT);
APPL_TRACE_DEBUG("Media data Q filled\n");
}
} }
/******************************************************************************* /*******************************************************************************
@ -415,15 +336,14 @@ static void btc_a2dp_sink_data_post(int32_t data_type)
*******************************************************************************/ *******************************************************************************/
static BOOLEAN btc_a2dp_sink_clear_track(void) static BOOLEAN btc_a2dp_sink_clear_track(void)
{ {
btc_a2dp_sink_ctrl_post(BTC_MEDIA_AUDIO_SINK_CLEAR_TRACK, NULL); return btc_a2dp_sink_ctrl_post(BTC_MEDIA_AUDIO_SINK_CLEAR_TRACK, NULL);
return TRUE;
} }
/* when true media task discards any rx frames */ /* when true media task discards any rx frames */
void btc_a2dp_sink_set_rx_flush(BOOLEAN enable) void btc_a2dp_sink_set_rx_flush(BOOLEAN enable)
{ {
APPL_TRACE_EVENT("## DROP RX %d ##\n", 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; 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 "); APPL_TRACE_DEBUG(" QUE EMPTY ");
} else { } else {
if (btc_aa_snk_cb.rx_flush == TRUE) { if (a2dp_sink_local_param.btc_aa_snk_cb.rx_flush == TRUE) {
btc_a2dp_sink_flush_q(btc_aa_snk_cb.RxSbcQ); btc_a2dp_sink_flush_q(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ);
return; 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){ if (btc_a2dp_sink_state != BTC_A2DP_SINK_STATE_ON){
return; return;
} }
btc_a2dp_sink_handle_inc_media(p_msg); 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 ) { if ( p_msg == NULL ) {
APPL_TRACE_ERROR("Insufficient data in que "); APPL_TRACE_ERROR("Insufficient data in que ");
break; break;
@ -510,13 +430,13 @@ static void btc_a2dp_sink_handle_decoder_reset(tBTC_MEDIA_SINK_CFG_UPDATE *p_msg
return; return;
} }
btc_aa_snk_cb.sample_rate = btc_a2dp_sink_get_track_frequency(sbc_cie.samp_freq); a2dp_sink_local_param.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.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"); APPL_TRACE_EVENT("Reset to sink role");
status = OI_CODEC_SBC_DecoderReset(&btc_sbc_decoder_context, btc_sbc_decoder_context_data, status = OI_CODEC_SBC_DecoderReset(&a2dp_sink_local_param.context, a2dp_sink_local_param.contextData,
BTC_SBC_DEC_CONTEXT_DATA_LEN * sizeof(OI_UINT32), 2, 2, FALSE, FALSE); sizeof(a2dp_sink_local_param.contextData), 2, 2, FALSE, FALSE);
if (!OI_SUCCESS(status)) { if (!OI_SUCCESS(status)) {
APPL_TRACE_ERROR("OI_CODEC_SBC_DecoderReset failed with error code %d\n", 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); UINT8 *sbc_start_frame = ((UINT8 *)(p_msg + 1) + p_msg->offset + 1);
int count; int count;
UINT32 pcmBytes, availPcmBytes; 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; OI_STATUS status;
int num_sbc_frames = p_msg->num_frames_to_be_processed; int num_sbc_frames = p_msg->num_frames_to_be_processed;
UINT32 sbc_frame_len = p_msg->len - 1; 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 */ /* 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 "); APPL_TRACE_DEBUG(" State Changed happened in this tick ");
return; 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 ++) { for (count = 0; count < num_sbc_frames && sbc_frame_len != 0; count ++) {
pcmBytes = availPcmBytes; 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_UINT32 *)&sbc_frame_len,
(OI_INT16 *)pcmDataPointer, (OI_INT16 *)pcmDataPointer,
(OI_UINT32 *)&pcmBytes); (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; 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) 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; return TRUE;
} }
btc_a2dp_sink_ctrl_post(BTC_MEDIA_FLUSH_AA_RX, NULL); return btc_a2dp_sink_ctrl_post(BTC_MEDIA_FLUSH_AA_RX, NULL);
return TRUE;
} }
/******************************************************************************* /*******************************************************************************
@ -703,7 +622,7 @@ static void btc_a2dp_sink_rx_flush(void)
/* Flush all enqueued SBC buffers (encoded) */ /* Flush all enqueued SBC buffers (encoded) */
APPL_TRACE_DEBUG("btc_a2dp_sink_rx_flush"); 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) 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; return 0;
} }
if (btc_aa_snk_cb.rx_flush == TRUE) { /* Flush enabled, do not enque*/ if (a2dp_sink_local_param.btc_aa_snk_cb.rx_flush == TRUE) { /* Flush enabled, do not enque*/
return fixed_queue_length(btc_aa_snk_cb.RxSbcQ); 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"); 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 + "); 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)); 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; 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); 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); fixed_queue_enqueue(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ, p_msg, FIXED_QUEUE_MAX_TIMEOUT);
btc_a2dp_sink_data_post(BTC_A2DP_SINK_DATA_EVT); btc_a2dp_sink_data_post();
} else { } else {
/* let caller deal with a failed allocation */ /* let caller deal with a failed allocation */
APPL_TRACE_WARNING("btc_a2dp_sink_enque_buf No Buffer left - "); 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) 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) static void btc_a2dp_sink_flush_q(fixed_queue_t *p_q)
{ {
while (! fixed_queue_is_empty(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) static void btc_a2dp_sink_thread_init(UNUSED_ATTR void *context)
{ {
APPL_TRACE_EVENT("%s\n", __func__); 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_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(); btc_a2dp_control_init();
} }
@ -826,9 +745,9 @@ static void btc_a2dp_sink_thread_cleanup(UNUSED_ATTR void *context)
btc_a2dp_control_cleanup(); 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 */ #endif /* BTC_AV_SINK_INCLUDED */

View File

@ -79,6 +79,9 @@ typedef struct {
UINT8 flags; UINT8 flags;
tBTA_AV_EDR edr; tBTA_AV_EDR edr;
UINT8 peer_sep; /* sep type of peer device */ 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; } btc_av_cb_t;
typedef struct { typedef struct {
@ -89,11 +92,12 @@ typedef struct {
/***************************************************************************** /*****************************************************************************
** Static variables ** Static variables
******************************************************************************/ ******************************************************************************/
#if A2D_DYNAMIC_MEMORY == FALSE
static btc_av_cb_t btc_av_cb = {0}; static btc_av_cb_t btc_av_cb = {0};
#else
#if BTC_AV_SRC_INCLUDED static btc_av_cb_t *btc_av_cb_ptr = NULL;
static osi_alarm_t *tle_av_open_on_rc = NULL; #define btc_av_cb (*btc_av_cb_ptr)
#endif /* BTC_AV_SRC_INCLUDED */ #endif ///A2D_DYNAMIC_MEMORY == FALSE
/* both interface and media task needs to be ready to alloc incoming request */ /* both interface and media task needs to be ready to alloc incoming request */
#define CHECK_BTAV_INIT() do \ #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 #if BTC_AV_SRC_INCLUDED
BTC_TRACE_DEBUG("BTA_AV_RC_OPEN_EVT received w/o AV"); 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); 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(tle_av_open_on_rc, 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 */ #endif /* BTC_AV_SRC_INCLUDED */
btc_rc_handler(event, p_data); btc_rc_handler(event, p_data);
break; 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: case BTA_AV_RC_CLOSE_EVT:
#if BTC_AV_SRC_INCLUDED #if BTC_AV_SRC_INCLUDED
if (tle_av_open_on_rc) { if (btc_av_cb.tle_av_open_on_rc) {
osi_alarm_free(tle_av_open_on_rc); osi_alarm_free(btc_av_cb.tle_av_open_on_rc);
tle_av_open_on_rc = NULL; btc_av_cb.tle_av_open_on_rc = NULL;
} }
#endif /* BTC_AV_SRC_INCLUDED */ #endif /* BTC_AV_SRC_INCLUDED */
btc_rc_handler(event, p_data); 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) 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) { if (btc_av_cb.sm_handle == NULL) {
btc_av_cb.service_id = service_id; btc_av_cb.service_id = service_id;
bool stat = false; bool stat = false;
@ -975,6 +992,10 @@ static bt_status_t btc_av_init(int service_id)
} }
if (!stat) { if (!stat) {
#if A2D_DYNAMIC_MEMORY == TRUE
osi_free(btc_av_cb_ptr);
btc_av_cb_ptr = NULL;
#endif
return BT_STATUS_FAIL; return BT_STATUS_FAIL;
} }
@ -1034,9 +1055,9 @@ static void clean_up(int service_id)
if (service_id == BTA_A2DP_SOURCE_SERVICE_ID) { if (service_id == BTA_A2DP_SOURCE_SERVICE_ID) {
#if BTC_AV_SRC_INCLUDED #if BTC_AV_SRC_INCLUDED
btc_a2dp_source_shutdown(); btc_a2dp_source_shutdown();
if (tle_av_open_on_rc) { if (btc_av_cb.tle_av_open_on_rc) {
osi_alarm_free(tle_av_open_on_rc); osi_alarm_free(btc_av_cb.tle_av_open_on_rc);
tle_av_open_on_rc = NULL; btc_av_cb.tle_av_open_on_rc = NULL;
} }
#endif /* BTC_AV_SRC_INCLUDED */ #endif /* BTC_AV_SRC_INCLUDED */
} }
@ -1056,6 +1077,11 @@ static void clean_up(int service_id)
btc_a2dp_sink_shutdown(); btc_a2dp_sink_shutdown();
#endif /* BTC_AV_SINK_INCLUDED */ #endif /* BTC_AV_SINK_INCLUDED */
} }
#if A2D_DYNAMIC_MEMORY == TRUE
osi_free(btc_av_cb_ptr);
btc_av_cb_ptr = NULL;
#endif
} }
/******************************************************************************* /*******************************************************************************

View File

@ -16,6 +16,7 @@
#define __BTC_AV_CO_H__ #define __BTC_AV_CO_H__
#include "btc_a2dp.h" #include "btc_a2dp.h"
#include "bta/bta_av_co.h"
#if (BTA_AV_INCLUDED == TRUE) #if (BTA_AV_INCLUDED == TRUE)
/******************************************************************************* /*******************************************************************************
@ -28,7 +29,62 @@ enum {
BTC_SV_AV_AA_SEP_INDEX /* Last index */ 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 ** Functions
********************************************************************************/ ********************************************************************************/

View File

@ -35,40 +35,6 @@
#if BTC_AV_INCLUDED #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 UINT8 opcode_from_pdu(UINT8 pdu);
static void send_reject_response (UINT8 rc_handle, UINT8 label, UINT8 pdu, UINT8 status); 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); 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_ct_init;
static uint32_t s_rc_tg_init; static uint32_t s_rc_tg_init;
#if AVRC_DYNAMIC_MEMORY == FALSE
static btc_rc_cb_t btc_rc_cb; 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] = { const static uint16_t cs_psth_allowed_cmd[8] = {
0x0000, /* bit mask: 0=SELECT, 1=UP, 2=DOWN, 3=LEFT, 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 /// initialize CT-TG shared resources
if (s_rc_tg_init != BTC_RC_TG_INIT_MAGIC) { 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 /// deinit CT-TG shared resources
if (s_rc_tg_init != BTC_RC_TG_INIT_MAGIC) { 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__); BTC_TRACE_API("## %s ## completed", __FUNCTION__);

View File

@ -31,8 +31,15 @@
#include "osi/mutex.h" #include "osi/mutex.h"
#include "esp_bt.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_adv_data;
static tBTA_BLE_ADV_DATA gl_bta_scan_rsp_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 #if SCAN_QUEUE_CONGEST_CHECK
static list_t *adv_filter_list; static list_t *adv_filter_list;
static osi_mutex_t adv_list_lock; static osi_mutex_t adv_list_lock;
@ -1366,3 +1373,4 @@ void btc_adv_list_unlock(void)
osi_mutex_unlock(&adv_list_lock); osi_mutex_unlock(&adv_list_lock);
} }
#endif #endif
#endif ///BLE_INCLUDED == TRUE

View File

@ -20,7 +20,7 @@
#define GATTC_READ_VALUE_TYPE_VALUE 0x0000 /* Attribute value itself */ #define GATTC_READ_VALUE_TYPE_VALUE 0x0000 /* Attribute value itself */
#define GATTC_READ_VALUE_TYPE_AGG_FORMAT 0x2905 /* Characteristic Aggregate Format*/ #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, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}; };

View File

@ -30,19 +30,11 @@
#define A2C_GATTS_EVT(_bta_event) (_bta_event) //BTA TO BTC EVT #define A2C_GATTS_EVT(_bta_event) (_bta_event) //BTA TO BTC EVT
#define C2A_GATTS_EVT(_btc_event) (_btc_event) //BTC TO BTA EVT #define C2A_GATTS_EVT(_btc_event) (_btc_event) //BTC TO BTA EVT
typedef struct { #if GATT_DYNAMIC_MEMORY == FALSE
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;
static esp_btc_creat_tab_t btc_creat_tab_env; 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, static esp_gatt_status_t btc_gatts_check_valid_attr_tab(esp_gatts_attr_db_t *gatts_attr_db,
uint8_t max_nb_attr); uint8_t max_nb_attr);

View File

@ -61,42 +61,31 @@
BTA_HF_CLIENT_FEAT_CODEC) BTA_HF_CLIENT_FEAT_CODEC)
#endif #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 ** Static variables
************************************************************************************/ ************************************************************************************/
const char *btc_hf_client_version = "1.6"; 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; #if HFP_DYNAMIC_MEMORY == FALSE
static esp_hf_client_incoming_data_cb_t btc_hf_client_incoming_data_cb = NULL; static hf_client_local_param_t hf_client_local_param;
static esp_hf_client_outgoing_data_cb_t btc_hf_client_outgoing_data_cb = NULL; #else
hf_client_local_param_t *hf_client_local_param_ptr;
#endif
/************************************************************************************ /************************************************************************************
** Static functions ** Static functions
************************************************************************************/ ************************************************************************************/
#define CHECK_HF_CLIENT_INIT() do { \ #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; \ return BT_STATUS_NOT_READY; \
} \ } \
} while (0) } while (0)
#define CHECK_HF_CLIENT_SLC_CONNECTED() do { \ #define CHECK_HF_CLIENT_SLC_CONNECTED() do { \
if (! btc_hf_client_cb.initialized || \ if (! hf_client_local_param.btc_hf_client_cb.initialized || \
btc_hf_client_cb.state != ESP_HF_CLIENT_CONNECTION_STATE_SLC_CONNECTED) { \ hf_client_local_param.btc_hf_client_cb.state != ESP_HF_CLIENT_CONNECTION_STATE_SLC_CONNECTED) { \
return BT_STATUS_NOT_READY; \ return BT_STATUS_NOT_READY; \
} \ } \
} while (0) } 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) 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) static BOOLEAN is_connected(bt_bdaddr_t *bd_addr)
{ {
if (((btc_hf_client_cb.state == ESP_HF_CLIENT_CONNECTION_STATE_CONNECTED) || if (((hf_client_local_param.btc_hf_client_cb.state == ESP_HF_CLIENT_CONNECTION_STATE_CONNECTED) ||
(btc_hf_client_cb.state == ESP_HF_CLIENT_CONNECTION_STATE_SLC_CONNECTED))&& (hf_client_local_param.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))) ((bd_addr == NULL) || (bdcmp(bd_addr->address, hf_client_local_param.btc_hf_client_cb.connected_bda.address) == 0)))
return TRUE; return TRUE;
return FALSE; 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, void btc_hf_client_reg_data_cb(esp_hf_client_incoming_data_cb_t recv,
esp_hf_client_outgoing_data_cb_t send) esp_hf_client_outgoing_data_cb_t send)
{ {
btc_hf_client_incoming_data_cb = recv; hf_client_local_param.btc_hf_client_incoming_data_cb = recv;
btc_hf_client_outgoing_data_cb = send; 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) void btc_hf_client_incoming_data_cb_to_app(const uint8_t *data, uint32_t len)
{ {
// todo: critical section protection // todo: critical section protection
if (btc_hf_client_incoming_data_cb) { if (hf_client_local_param.btc_hf_client_incoming_data_cb) {
btc_hf_client_incoming_data_cb(data, len); 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) uint32_t btc_hf_client_outgoing_data_cb_to_app(uint8_t *data, uint32_t len)
{ {
// todo: critical section protection // todo: critical section protection
if (btc_hf_client_outgoing_data_cb) { if (hf_client_local_param.btc_hf_client_outgoing_data_cb) {
return btc_hf_client_outgoing_data_cb(data, len); return hf_client_local_param.btc_hf_client_outgoing_data_cb(data, len);
} else { } else {
return 0; return 0;
} }
@ -172,9 +161,9 @@ bt_status_t btc_hf_client_init(void)
clear_state(); 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; data_path = ESP_SCO_DATA_PATH_HCI;
#else #else
data_path = ESP_SCO_DATA_PATH_PCM; 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; return BT_STATUS_BUSY;
} }
btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_CONNECTING; hf_client_local_param.btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_CONNECTING;
bdcpy(btc_hf_client_cb.connected_bda.address, bd_addr->address); 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); BTC_HF_CLIENT_SECURITY);
return BT_STATUS_SUCCESS; return BT_STATUS_SUCCESS;
@ -232,7 +221,7 @@ void btc_hf_client_deinit( void )
btc_dm_disable_service(BTA_HFP_HS_SERVICE_ID); 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)) 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; 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 (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 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 */ /* 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; esp_hf_client_cb_param_t param;
memset(&param, 0, sizeof(esp_hf_client_cb_param_t)); memset(&param, 0, sizeof(esp_hf_client_cb_param_t));
param.audio_stat.state = ESP_HF_CLIENT_AUDIO_STATE_CONNECTING; 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, &param); btc_hf_client_cb_to_app(ESP_HF_CLIENT_AUDIO_STATE_EVT, &param);
} while (0); } while (0);
@ -311,7 +300,7 @@ bt_status_t btc_hf_client_disconnect_audio( bt_bdaddr_t *bd_addr )
if (is_connected(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; return BT_STATUS_SUCCESS;
} }
@ -331,9 +320,9 @@ static bt_status_t btc_hf_client_start_voice_recognition(void)
{ {
CHECK_HF_CLIENT_SLC_CONNECTED(); 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; return BT_STATUS_SUCCESS;
} }
@ -355,9 +344,9 @@ static bt_status_t btc_hf_client_stop_voice_recognition(void)
{ {
CHECK_HF_CLIENT_SLC_CONNECTED(); 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; 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) switch (type)
{ {
case ESP_HF_VOLUME_CONTROL_TARGET_SPK: 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; break;
case ESP_HF_VOLUME_CONTROL_TARGET_MIC: 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; break;
default: default:
return BT_STATUS_UNSUPPORTED; return BT_STATUS_UNSUPPORTED;
@ -408,11 +397,11 @@ static bt_status_t btc_hf_client_dial(const char *number)
if (strlen(number) != 0) 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 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; return BT_STATUS_SUCCESS;
@ -431,7 +420,7 @@ static bt_status_t btc_hf_client_dial_memory(int location)
{ {
CHECK_HF_CLIENT_SLC_CONNECTED(); 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; 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) switch (type)
{ {
case ESP_HF_CHLD_TYPE_REL: 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; break;
} }
return BT_STATUS_UNSUPPORTED; return BT_STATUS_UNSUPPORTED;
case ESP_HF_CHLD_TYPE_REL_ACC: case ESP_HF_CHLD_TYPE_REL_ACC:
// CHLD 1 is mandatory for 3 way calling // 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; break;
} }
return BT_STATUS_UNSUPPORTED; return BT_STATUS_UNSUPPORTED;
case ESP_HF_CHLD_TYPE_HOLD_ACC: case ESP_HF_CHLD_TYPE_HOLD_ACC:
// CHLD 2 is mandatory for 3 way calling // 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; break;
} }
return BT_STATUS_UNSUPPORTED; return BT_STATUS_UNSUPPORTED;
case ESP_HF_CHLD_TYPE_MERGE: 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; break;
} }
return BT_STATUS_UNSUPPORTED; return BT_STATUS_UNSUPPORTED;
case ESP_HF_CHLD_TYPE_MERGE_DETACH: 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; break;
} }
return BT_STATUS_UNSUPPORTED; return BT_STATUS_UNSUPPORTED;
case ESP_HF_CHLD_TYPE_REL_X: 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) if (idx < 1)
{ {
return BT_STATUS_FAIL; 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; break;
} }
return BT_STATUS_UNSUPPORTED; return BT_STATUS_UNSUPPORTED;
case ESP_HF_CHLD_TYPE_PRIV_X: 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) if (idx < 1)
{ {
return BT_STATUS_FAIL; 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; break;
} }
return BT_STATUS_UNSUPPORTED; 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) { switch (btrh) {
case ESP_HF_BTRH_CMD_HOLD: 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; break;
case ESP_HF_BTRH_CMD_ACCEPT: 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; break;
case ESP_HF_BTRH_CMD_REJECT: 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; break;
default: default:
return BT_STATUS_FAIL; 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) static bt_status_t btc_hf_client_answer_call(void)
{ {
CHECK_HF_CLIENT_SLC_CONNECTED(); 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; return BT_STATUS_SUCCESS;
} }
static bt_status_t btc_hf_client_reject_call(void) static bt_status_t btc_hf_client_reject_call(void)
{ {
CHECK_HF_CLIENT_SLC_CONNECTED(); 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; return BT_STATUS_SUCCESS;
} }
@ -554,9 +543,9 @@ static bt_status_t btc_hf_client_query_current_calls(void)
{ {
CHECK_HF_CLIENT_SLC_CONNECTED(); 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; 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(); 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; return BT_STATUS_SUCCESS;
} }
@ -595,7 +584,7 @@ static bt_status_t btc_hf_client_retrieve_subscriber_info(void)
{ {
CHECK_HF_CLIENT_SLC_CONNECTED(); 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; return BT_STATUS_SUCCESS;
} }
@ -613,7 +602,7 @@ static bt_status_t btc_hf_client_send_dtmf(char code)
{ {
CHECK_HF_CLIENT_SLC_CONNECTED(); 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; 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(); 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; return BT_STATUS_SUCCESS;
} }
@ -694,17 +683,17 @@ bt_status_t btc_hf_client_execute_service(BOOLEAN b_enable)
else else
{ {
BTC_TRACE_EVENT("No Codec Nego Supported"); BTC_TRACE_EVENT("No Codec Nego Supported");
btc_hf_client_features = BTC_HF_CLIENT_FEATURES; hf_client_local_param.btc_hf_client_features = BTC_HF_CLIENT_FEATURES;
btc_hf_client_features = btc_hf_client_features & (~BTA_HF_CLIENT_FEAT_CODEC); hf_client_local_param.btc_hf_client_features = hf_client_local_param.btc_hf_client_features & (~BTA_HF_CLIENT_FEAT_CODEC);
BTC_TRACE_EVENT("btc_hf_client_features is %d", btc_hf_client_features); 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, btc_hf_client_features, BTA_HfClientRegister(BTC_HF_CLIENT_SECURITY, hf_client_local_param.btc_hf_client_features,
BTC_HF_CLIENT_SERVICE_NAME); BTC_HF_CLIENT_SERVICE_NAME);
} }
} }
else else
{ {
BTA_HfClientDeregister(btc_hf_client_cb.handle); BTA_HfClientDeregister(hf_client_local_param.btc_hf_client_cb.handle);
BTA_HfClientDisable(); BTA_HfClientDisable();
} }
return BT_STATUS_SUCCESS; return BT_STATUS_SUCCESS;
@ -769,44 +758,43 @@ void btc_hf_client_cb_handler(btc_msg_t *msg)
case BTA_HF_CLIENT_DISABLE_EVT: case BTA_HF_CLIENT_DISABLE_EVT:
break; break;
case BTA_HF_CLIENT_REGISTER_EVT: 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; break;
case BTA_HF_CLIENT_OPEN_EVT: case BTA_HF_CLIENT_OPEN_EVT:
if (p_data->open.status == BTA_HF_CLIENT_SUCCESS) if (p_data->open.status == BTA_HF_CLIENT_SUCCESS)
{ {
bdcpy(btc_hf_client_cb.connected_bda.address, p_data->open.bd_addr); bdcpy(hf_client_local_param.btc_hf_client_cb.connected_bda.address, p_data->open.bd_addr);
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_CONNECTED;
btc_hf_client_cb.peer_feat = 0; hf_client_local_param.btc_hf_client_cb.peer_feat = 0;
btc_hf_client_cb.chld_feat = 0; hf_client_local_param.btc_hf_client_cb.chld_feat = 0;
//clear_phone_state(); //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 else
{ {
BTC_TRACE_WARNING("%s: HF CLient open failed, but another device connected. status=%d state=%d connected device=%s", 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); UNUSED(bdstr);
break; break;
} }
do { do {
memset(&param, 0, sizeof(esp_hf_client_cb_param_t)); memset(&param, 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.peer_feat = 0;
param.conn_stat.chld_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)); sizeof(esp_bd_addr_t));
btc_hf_client_cb_to_app(ESP_HF_CLIENT_CONNECTION_STATE_EVT, &param); btc_hf_client_cb_to_app(ESP_HF_CLIENT_CONNECTION_STATE_EVT, &param);
} while (0); } while (0);
if (btc_hf_client_cb.state == ESP_HF_CLIENT_CONNECTION_STATE_DISCONNECTED) { if (hf_client_local_param.btc_hf_client_cb.state == ESP_HF_CLIENT_CONNECTION_STATE_DISCONNECTED)
bdsetany(btc_hf_client_cb.connected_bda.address); bdsetany(hf_client_local_param.btc_hf_client_cb.connected_bda.address);
}
if (p_data->open.status != BTA_HF_CLIENT_SUCCESS) { if (p_data->open.status != BTA_HF_CLIENT_SUCCESS) {
btc_queue_advance(); btc_queue_advance();
@ -815,24 +803,24 @@ void btc_hf_client_cb_handler(btc_msg_t *msg)
break; break;
case BTA_HF_CLIENT_CONN_EVT: case BTA_HF_CLIENT_CONN_EVT:
btc_hf_client_cb.peer_feat = p_data->conn.peer_feat; hf_client_local_param.btc_hf_client_cb.peer_feat = p_data->conn.peer_feat;
btc_hf_client_cb.chld_feat = p_data->conn.chld_feat; hf_client_local_param.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.state = ESP_HF_CLIENT_CONNECTION_STATE_SLC_CONNECTED;
do { do {
memset(&param, 0, sizeof(esp_hf_client_cb_param_t)); memset(&param, 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 = btc_hf_client_cb.peer_feat; param.conn_stat.peer_feat = hf_client_local_param.btc_hf_client_cb.peer_feat;
param.conn_stat.chld_feat = btc_hf_client_cb.chld_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)); sizeof(esp_bd_addr_t));
btc_hf_client_cb_to_app(ESP_HF_CLIENT_CONNECTION_STATE_EVT, &param); btc_hf_client_cb_to_app(ESP_HF_CLIENT_CONNECTION_STATE_EVT, &param);
} while (0); } while (0);
/* Inform the application about in-band ringtone */ /* 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 { do {
memset(&param, 0, sizeof(esp_hf_client_cb_param_t)); memset(&param, 0, sizeof(esp_hf_client_cb_param_t));
@ -845,22 +833,22 @@ void btc_hf_client_cb_handler(btc_msg_t *msg)
break; break;
case BTA_HF_CLIENT_CLOSE_EVT: 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 { do {
memset(&param, 0, sizeof(esp_hf_client_cb_param_t)); memset(&param, 0, sizeof(esp_hf_client_cb_param_t));
param.conn_stat.state = ESP_HF_CLIENT_CONNECTION_STATE_DISCONNECTED; param.conn_stat.state = ESP_HF_CLIENT_CONNECTION_STATE_DISCONNECTED;
param.conn_stat.peer_feat = 0; param.conn_stat.peer_feat = 0;
param.conn_stat.chld_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)); sizeof(esp_bd_addr_t));
btc_hf_client_cb_to_app(ESP_HF_CLIENT_CONNECTION_STATE_EVT, &param); btc_hf_client_cb_to_app(ESP_HF_CLIENT_CONNECTION_STATE_EVT, &param);
} while (0); } while (0);
bdsetany(btc_hf_client_cb.connected_bda.address); bdsetany(hf_client_local_param.btc_hf_client_cb.connected_bda.address);
btc_hf_client_cb.peer_feat = 0; hf_client_local_param.btc_hf_client_cb.peer_feat = 0;
btc_hf_client_cb.chld_feat = 0; hf_client_local_param.btc_hf_client_cb.chld_feat = 0;
btc_queue_advance(); btc_queue_advance();
break; break;
case BTA_HF_CLIENT_IND_EVT: case BTA_HF_CLIENT_IND_EVT:
@ -983,7 +971,7 @@ void btc_hf_client_cb_handler(btc_msg_t *msg)
do { do {
memset(&param, 0, sizeof(esp_hf_client_cb_param_t)); memset(&param, 0, sizeof(esp_hf_client_cb_param_t));
param.audio_stat.state = ESP_HF_CLIENT_AUDIO_STATE_CONNECTED; 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)); sizeof(esp_bd_addr_t));
btc_hf_client_cb_to_app(ESP_HF_CLIENT_AUDIO_STATE_EVT, &param); btc_hf_client_cb_to_app(ESP_HF_CLIENT_AUDIO_STATE_EVT, &param);
} while (0); } while (0);
@ -992,7 +980,7 @@ void btc_hf_client_cb_handler(btc_msg_t *msg)
do { do {
memset(&param, 0, sizeof(esp_hf_client_cb_param_t)); memset(&param, 0, sizeof(esp_hf_client_cb_param_t));
param.audio_stat.state = ESP_HF_CLIENT_AUDIO_STATE_CONNECTED_MSBC; 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)); sizeof(esp_bd_addr_t));
btc_hf_client_cb_to_app(ESP_HF_CLIENT_AUDIO_STATE_EVT, &param); btc_hf_client_cb_to_app(ESP_HF_CLIENT_AUDIO_STATE_EVT, &param);
} while (0); } while (0);
@ -1001,7 +989,7 @@ void btc_hf_client_cb_handler(btc_msg_t *msg)
do { do {
memset(&param, 0, sizeof(esp_hf_client_cb_param_t)); memset(&param, 0, sizeof(esp_hf_client_cb_param_t));
param.audio_stat.state = ESP_HF_CLIENT_AUDIO_STATE_DISCONNECTED; 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)); sizeof(esp_bd_addr_t));
btc_hf_client_cb_to_app(ESP_HF_CLIENT_AUDIO_STATE_EVT, &param); btc_hf_client_cb_to_app(ESP_HF_CLIENT_AUDIO_STATE_EVT, &param);
} while (0); } while (0);

View File

@ -86,6 +86,50 @@ typedef enum {
BTC_AVRC_TG_API_SEND_RN_RSP_EVT, BTC_AVRC_TG_API_SEND_RN_RSP_EVT,
} btc_avrc_tg_act_t; } 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 { typedef struct {
esp_avrc_rn_event_ids_t event_id; esp_avrc_rn_event_ids_t event_id;
esp_avrc_rn_rsp_t rsp; esp_avrc_rn_rsp_t rsp;

View File

@ -18,6 +18,14 @@
#include "esp_bt_defs.h" #include "esp_bt_defs.h"
#include "esp_gap_ble_api.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)) #define BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == ESP_BLE_CONN_PARAM_UNDEF))
typedef enum { typedef enum {

View File

@ -19,6 +19,7 @@
#include "esp_bt_defs.h" #include "esp_bt_defs.h"
#include "esp_gatt_defs.h" #include "esp_gatt_defs.h"
#include "esp_gatts_api.h" #include "esp_gatts_api.h"
#include "osi/future.h"
typedef enum { typedef enum {
BTC_GATTS_ACT_APP_REGISTER = 0, BTC_GATTS_ACT_APP_REGISTER = 0,
@ -150,6 +151,21 @@ typedef union {
} btc_ble_gatts_args_t; } 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_call_handler(btc_msg_t *msg);
void btc_gatts_cb_handler(btc_msg_t *msg); void btc_gatts_cb_handler(btc_msg_t *msg);

View File

@ -112,6 +112,34 @@ typedef union {
} reg_data_cb; } reg_data_cb;
} btc_hf_client_args_t; } 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 ** BTC HF AG API
********************************************************************************/ ********************************************************************************/

View File

@ -55,13 +55,20 @@ typedef struct {
char service_name[ESP_SPP_SERVER_NAME_MAX + 1]; char service_name[ESP_SPP_SERVER_NAME_MAX + 1];
} spp_slot_t; } spp_slot_t;
static struct spp_local_param_t { typedef struct {
spp_slot_t *spp_slots[BTA_JV_MAX_RFC_SR_SESSION + 1]; spp_slot_t *spp_slots[BTA_JV_MAX_RFC_SR_SESSION + 1];
uint32_t spp_slot_id; uint32_t spp_slot_id;
esp_spp_mode_t spp_mode; esp_spp_mode_t spp_mode;
osi_mutex_t spp_slot_mutex; osi_mutex_t spp_slot_mutex;
esp_vfs_id_t spp_vfs_id; 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) 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) 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) { if (osi_mutex_new(&spp_local_param.spp_slot_mutex) != 0) {
BTC_TRACE_ERROR("%s osi_mutex_new failed\n", __func__); BTC_TRACE_ERROR("%s osi_mutex_new failed\n", __func__);
return; return;
@ -349,6 +365,11 @@ static void btc_spp_uninit(void)
BTA_JvDisable(); BTA_JvDisable();
osi_mutex_unlock(&spp_local_param.spp_slot_mutex); osi_mutex_unlock(&spp_local_param.spp_slot_mutex);
osi_mutex_free(&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) static void btc_spp_start_discovery(btc_spp_args_t *arg)

View File

@ -34,17 +34,25 @@
#include "bdroid_buildcfg.h" #include "bdroid_buildcfg.h"
#endif #endif
#include "sdkconfig.h" #include "bt_user_config.h"
#include "stack/bt_types.h" /* This must be defined AFTER buildcfg.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 */ #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 ** Classic BT features
** **
******************************************************************************/ ******************************************************************************/
#if CONFIG_BT_CLASSIC_ENABLED #if (UC_BT_CLASSIC_ENABLED == TRUE)
#define CLASSIC_BT_INCLUDED TRUE #define CLASSIC_BT_INCLUDED TRUE
#define BTC_SM_INCLUDED TRUE #define BTC_SM_INCLUDED TRUE
#define BTC_PRF_QUEUE_INCLUDED TRUE #define BTC_PRF_QUEUE_INCLUDED TRUE
@ -53,7 +61,7 @@
#define BTA_DM_PM_INCLUDED TRUE #define BTA_DM_PM_INCLUDED TRUE
#define SDP_INCLUDED TRUE #define SDP_INCLUDED TRUE
#if CONFIG_BT_A2DP_ENABLE #if (UC_BT_A2DP_ENABLED == TRUE)
#define BTA_AR_INCLUDED TRUE #define BTA_AR_INCLUDED TRUE
#define BTA_AV_INCLUDED TRUE #define BTA_AV_INCLUDED TRUE
#define AVDT_INCLUDED TRUE #define AVDT_INCLUDED TRUE
@ -66,15 +74,15 @@
#define SBC_DEC_INCLUDED TRUE #define SBC_DEC_INCLUDED TRUE
#define BTC_AV_SRC_INCLUDED TRUE #define BTC_AV_SRC_INCLUDED TRUE
#define SBC_ENC_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 RFCOMM_INCLUDED TRUE
#define BTA_JV_INCLUDED TRUE #define BTA_JV_INCLUDED TRUE
#define BTC_SPP_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 BTC_HF_CLIENT_INCLUDED TRUE
#define BTA_HF_INCLUDED TRUE #define BTA_HF_INCLUDED TRUE
#define PLC_INCLUDED TRUE #define PLC_INCLUDED TRUE
@ -87,96 +95,91 @@
#ifndef BTM_MAX_SCO_LINKS #ifndef BTM_MAX_SCO_LINKS
#define BTM_MAX_SCO_LINKS (1) #define BTM_MAX_SCO_LINKS (1)
#endif #endif
#ifndef SBC_DEC_INCLUDED #ifndef SBC_DEC_INCLUDED
#define SBC_DEC_INCLUDED TRUE #define SBC_DEC_INCLUDED TRUE
#endif #endif
#ifndef SBC_ENC_INCLUDED #ifndef SBC_ENC_INCLUDED
#define SBC_ENC_INCLUDED TRUE #define SBC_ENC_INCLUDED TRUE
#endif #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 #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 #ifndef CLASSIC_BT_INCLUDED
#define CLASSIC_BT_INCLUDED FALSE #define CLASSIC_BT_INCLUDED FALSE
#endif /* CLASSIC_BT_INCLUDED */ #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 ** 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 #define GATTS_INCLUDED TRUE
#else #else
#define GATTS_INCLUDED FALSE #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 #define GATTC_INCLUDED TRUE
#else #else
#define GATTC_INCLUDED FALSE #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) #if (UC_BT_GATTC_ENABLE && UC_BT_GATTC_CACHE_NVS_FLASH_ENABLED)
#define GATTC_CACHE_NVS TRUE #define GATTC_CACHE_NVS TRUE
#else #else
#define GATTC_CACHE_NVS FALSE #define GATTC_CACHE_NVS FALSE
#endif /* CONFIG_BT_GATTC_CACHE_NVS_FLASH */ #endif /* UC_BT_GATTC_ENABLE && UC_BT_GATTC_CACHE_NVS_FLASH_ENABLED */
#if (CONFIG_BT_SMP_ENABLE) #if (UC_BT_SMP_ENABLE)
#define SMP_INCLUDED TRUE #define SMP_INCLUDED TRUE
#define BLE_PRIVACY_SPT TRUE #if (BLE_INCLUDED == TRUE)
#define BLE_PRIVACY_SPT TRUE
#else #else
#define SMP_INCLUDED FALSE #define BLE_PRIVACY_SPT FALSE
#define BLE_PRIVACY_SPT FALSE #endif /*BLE_INCLUDED*/
#endif /* CONFIG_BT_SMP_ENABLE */ #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(UC_BT_SMP_SLAVE_CON_PARAMS_UPD_ENABLE)
#if(CONFIG_BT_SMP_SLAVE_CON_PARAMS_UPD_ENABLE) #define SMP_SLAVE_CON_PARAMS_UPD_ENABLE TRUE
#define SMP_SLAVE_CON_PARAMS_UPD_ENABLE TRUE
#else #else
#define SMP_SLAVE_CON_PARAMS_UPD_ENABLE FALSE #define SMP_SLAVE_CON_PARAMS_UPD_ENABLE FALSE
#endif #endif /* UC_BT_SMP_SLAVE_CON_PARAMS_UPD_ENABLE */
#else
#define SMP_SLAVE_CON_PARAMS_UPD_ENABLE FALSE
#endif
#ifndef CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP #ifdef UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP
#define BLE_ADV_REPORT_FLOW_CONTROL FALSE #define BLE_ADV_REPORT_FLOW_CONTROL UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP
#else #endif /* UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP */
#define BLE_ADV_REPORT_FLOW_CONTROL CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP
#endif /* CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP */
#ifndef CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM #ifdef UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM
#define BLE_ADV_REPORT_FLOW_CONTROL_NUM 100 #define BLE_ADV_REPORT_FLOW_CONTROL_NUM UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM
#else #endif /* UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM */
#define BLE_ADV_REPORT_FLOW_CONTROL_NUM CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM
#endif /* CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM */
#ifndef CONFIG_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD #ifdef UC_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD
#define BLE_ADV_REPORT_DISCARD_THRSHOLD 20 #define BLE_ADV_REPORT_DISCARD_THRSHOLD UC_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD
#else #endif /* UC_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD */
#define BLE_ADV_REPORT_DISCARD_THRSHOLD CONFIG_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD
#endif /* CONFIG_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD */
#if (CONFIG_BT_ACL_CONNECTIONS) #ifdef UC_BT_ACL_CONNECTIONS
#define MAX_ACL_CONNECTIONS CONFIG_BT_ACL_CONNECTIONS #define MAX_ACL_CONNECTIONS UC_BT_ACL_CONNECTIONS
#define GATT_MAX_PHY_CHANNEL CONFIG_BT_ACL_CONNECTIONS #define GATT_MAX_PHY_CHANNEL UC_BT_ACL_CONNECTIONS
#endif /* CONFIG_BT_ACL_CONNECTIONS */ #endif /* UC_BT_ACL_CONNECTIONS */
#if(CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT) #ifdef UC_BT_BLE_ESTAB_LINK_CONN_TOUT
#define BLE_ESTABLISH_LINK_CONNECTION_TIMEOUT CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT #define BLE_ESTABLISH_LINK_CONNECTION_TIMEOUT UC_BT_BLE_ESTAB_LINK_CONN_TOUT
#else
#define BLE_ESTABLISH_LINK_CONNECTION_TIMEOUT 30
#endif #endif
//------------------Added from bdroid_buildcfg.h--------------------- //------------------Added from bdroid_buildcfg.h---------------------
@ -333,7 +336,7 @@
#endif #endif
#ifndef BTA_AVRCP_FF_RW_SUPPORT #ifndef BTA_AVRCP_FF_RW_SUPPORT
#define BTA_AVRCP_FF_RW_SUPPORT FALSE//TRUE #define BTA_AVRCP_FF_RW_SUPPORT FALSE
#endif #endif
#ifndef BTA_AG_SCO_PKT_TYPES #ifndef BTA_AG_SCO_PKT_TYPES
@ -349,34 +352,30 @@
#endif #endif
#ifndef BTA_AV_CO_CP_SCMS_T #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 #endif
#ifndef QUEUE_CONGEST_SIZE #ifndef QUEUE_CONGEST_SIZE
#define QUEUE_CONGEST_SIZE 40 #define QUEUE_CONGEST_SIZE 40
#endif #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 #define SCAN_QUEUE_CONGEST_CHECK FALSE
#else
#define SCAN_QUEUE_CONGEST_CHECK CONFIG_BT_BLE_HOST_QUEUE_CONG_CHECK
#endif #endif
#ifndef CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MODE #ifdef UC_BT_GATTS_SEND_SERVICE_CHANGE_MODE
#define GATTS_SEND_SERVICE_CHANGE_MODE GATTS_SEND_SERVICE_CHANGE_AUTO #define GATTS_SEND_SERVICE_CHANGE_MODE UC_BT_GATTS_SEND_SERVICE_CHANGE_MODE
#else
#define GATTS_SEND_SERVICE_CHANGE_MODE CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MODE
#endif #endif
#ifndef 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 FALSE #define BTM_BLE_ACTIVE_SCAN_REPORT_ADV_SCAN_RSP_INDIVIDUALLY UC_BT_BLE_ACT_SCAN_REP_ADV_SCAN
#else
#define BTM_BLE_ACTIVE_SCAN_REPORT_ADV_SCAN_RSP_INDIVIDUALLY CONFIG_BT_BLE_ACT_SCAN_REP_ADV_SCAN
#endif #endif
/* This feature is used to eanble interleaved scan*/ /* This feature is used to eanble interleaved scan*/
#ifndef BTA_HOST_INTERLEAVE_SEARCH #ifndef BTA_HOST_INTERLEAVE_SEARCH
#define BTA_HOST_INTERLEAVE_SEARCH FALSE//FALSE #define BTA_HOST_INTERLEAVE_SEARCH FALSE
#endif #endif
#ifndef BT_USE_TRACES #ifndef BT_USE_TRACES
@ -404,7 +403,7 @@
#endif #endif
#ifndef BTIF_DM_OOB_TEST #ifndef BTIF_DM_OOB_TEST
#define BTIF_DM_OOB_TEST FALSE//TRUE #define BTIF_DM_OOB_TEST FALSE
#endif #endif
// How long to wait before activating sniff mode after entering the // How long to wait before activating sniff mode after entering the
@ -589,11 +588,11 @@
/* Includes SCO if TRUE */ /* Includes SCO if TRUE */
#ifndef BTM_SCO_HCI_INCLUDED #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 */ #define BTM_SCO_HCI_INCLUDED TRUE /* TRUE includes SCO over HCI code */
#else #else
#define BTM_SCO_HCI_INCLUDED FALSE #define BTM_SCO_HCI_INCLUDED FALSE
#endif /* CONFIG_BT_HFP_AUDIO_DATA_PATH_HCI */ #endif /* UC_HFP_AUDIO_DATA_PATH_HCI */
#endif #endif
/* Includes WBS if TRUE */ /* Includes WBS if TRUE */
@ -1035,7 +1034,7 @@
******************************************************************************/ ******************************************************************************/
#ifndef BLE_INCLUDED #ifndef BLE_INCLUDED
#define BLE_INCLUDED TRUE #define BLE_INCLUDED FALSE
#endif #endif
#ifndef BLE_ANDROID_CONTROLLER_SCAN_FILTER #ifndef BLE_ANDROID_CONTROLLER_SCAN_FILTER
@ -1127,7 +1126,7 @@
#endif #endif
#ifndef ATT_DEBUG #ifndef ATT_DEBUG
#define ATT_DEBUG FALSE//TRUE #define ATT_DEBUG FALSE
#endif #endif
#ifndef BLE_PERIPHERAL_MODE_SUPPORT #ifndef BLE_PERIPHERAL_MODE_SUPPORT
@ -1192,12 +1191,6 @@
#endif #endif
#endif #endif
#if SMP_INCLUDED == TRUE && BLE_INCLUDED == FALSE
#error "can't have SMP without BLE"
#endif
/****************************************************************************** /******************************************************************************
** **
** SMP ** SMP
@ -1211,10 +1204,6 @@
#endif #endif
#endif #endif
#if SMP_INCLUDED == TRUE && BLE_INCLUDED == FALSE
#error "can't have SMP without BLE"
#endif
#ifndef SMP_DEBUG #ifndef SMP_DEBUG
#define SMP_DEBUG FALSE #define SMP_DEBUG FALSE
#endif #endif
@ -1529,12 +1518,12 @@ Range: 2 octets
******************************************************************************/ ******************************************************************************/
#ifndef BNEP_INCLUDED #ifndef BNEP_INCLUDED
#define BNEP_INCLUDED FALSE//TRUE #define BNEP_INCLUDED FALSE
#endif #endif
/* BNEP status API call is used mainly to get the L2CAP handle */ /* BNEP status API call is used mainly to get the L2CAP handle */
#ifndef BNEP_SUPPORTS_STATUS_API #ifndef BNEP_SUPPORTS_STATUS_API
#define BNEP_SUPPORTS_STATUS_API FALSE//TRUE #define BNEP_SUPPORTS_STATUS_API FALSE
#endif #endif
/* /*
@ -1542,7 +1531,7 @@ Range: 2 octets
** we will do an authentication check again on the new role ** we will do an authentication check again on the new role
*/ */
#ifndef BNEP_DO_AUTH_FOR_ROLE_SWITCH #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 #endif
@ -1655,22 +1644,22 @@ Range: 2 octets
/* This will enable the PANU role */ /* This will enable the PANU role */
#ifndef PAN_SUPPORTS_ROLE_PANU #ifndef PAN_SUPPORTS_ROLE_PANU
#define PAN_SUPPORTS_ROLE_PANU FALSE//TRUE #define PAN_SUPPORTS_ROLE_PANU FALSE
#endif #endif
/* This will enable the GN role */ /* This will enable the GN role */
#ifndef PAN_SUPPORTS_ROLE_GN #ifndef PAN_SUPPORTS_ROLE_GN
#define PAN_SUPPORTS_ROLE_GN FALSE//TRUE #define PAN_SUPPORTS_ROLE_GN FALSE
#endif #endif
/* This will enable the NAP role */ /* This will enable the NAP role */
#ifndef PAN_SUPPORTS_ROLE_NAP #ifndef PAN_SUPPORTS_ROLE_NAP
#define PAN_SUPPORTS_ROLE_NAP FALSE//TRUE #define PAN_SUPPORTS_ROLE_NAP FALSE
#endif #endif
/* This is just for debugging purposes */ /* This is just for debugging purposes */
#ifndef PAN_SUPPORTS_DEBUG_DUMP #ifndef PAN_SUPPORTS_DEBUG_DUMP
#define PAN_SUPPORTS_DEBUG_DUMP FALSE//TRUE #define PAN_SUPPORTS_DEBUG_DUMP FALSE
#endif #endif
/* Maximum number of PAN connections allowed */ /* 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 #ifndef HCILP_INCLUDED
#define HCILP_INCLUDED FALSE//TRUE #define HCILP_INCLUDED FALSE
#endif #endif
/****************************************************************************** /******************************************************************************
@ -2034,7 +2023,7 @@ The maximum number of payload octets that the local device can receive in a sing
#endif #endif
#ifndef BTA_DM_AVOID_A2DP_ROLESWITCH_ON_INQUIRY #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 #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 */ /* Enable/disable BTSnoop memory logging */
#ifndef BTSNOOP_MEM #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 #endif
#include "common/bt_trace.h" #include "common/bt_trace.h"

View File

@ -19,17 +19,16 @@
#ifndef _BT_TRACE_H_ #ifndef _BT_TRACE_H_
#define _BT_TRACE_H_ #define _BT_TRACE_H_
#include "sdkconfig.h"
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include "bt_user_config.h"
#include "stack/bt_types.h" #include "stack/bt_types.h"
#ifndef LOG_LOCAL_LEVEL #ifndef LOG_LOCAL_LEVEL
#ifndef BOOTLOADER_BUILD #ifndef BOOTLOADER_BUILD
#define LOG_LOCAL_LEVEL CONFIG_LOG_DEFAULT_LEVEL #define LOG_LOCAL_LEVEL UC_LOG_DEFAULT_LEVEL
#else #else
#define LOG_LOCAL_LEVEL CONFIG_BOOTLOADER_LOG_LEVEL #define LOG_LOCAL_LEVEL UC_BOOTLOADER_LOG_LEVEL
#endif #endif
#endif #endif
@ -217,135 +216,31 @@ inline void trc_dump_buffer(const char *prefix, uint8_t *data, uint16_t len)
// btla-specific ++ // btla-specific ++
/* Core Stack default trace levels */ /* Core Stack default trace levels */
#ifdef CONFIG_BT_LOG_HCI_TRACE_LEVEL #define HCI_INITIAL_TRACE_LEVEL UC_BT_LOG_HCI_TRACE_LEVEL
#define HCI_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_HCI_TRACE_LEVEL #define BTM_INITIAL_TRACE_LEVEL UC_BT_LOG_BTM_TRACE_LEVEL
#else #define L2CAP_INITIAL_TRACE_LEVEL UC_BT_LOG_L2CAP_TRACE_LEVEL
#define HCI_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING #define RFCOMM_INITIAL_TRACE_LEVEL UC_BT_LOG_RFCOMM_TRACE_LEVEL
#endif #define SDP_INITIAL_TRACE_LEVEL UC_BT_LOG_SDP_TRACE_LEVEL
#define GAP_INITIAL_TRACE_LEVEL UC_BT_LOG_GAP_TRACE_LEVEL
#ifdef CONFIG_BT_LOG_BTM_TRACE_LEVEL #define BNEP_INITIAL_TRACE_LEVEL UC_BT_LOG_BNEP_TRACE_LEVEL
#define BTM_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_BTM_TRACE_LEVEL #define PAN_INITIAL_TRACE_LEVEL UC_BT_LOG_PAN_TRACE_LEVEL
#else #define A2D_INITIAL_TRACE_LEVEL UC_BT_LOG_A2D_TRACE_LEVEL
#define BTM_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING #define AVDT_INITIAL_TRACE_LEVEL UC_BT_LOG_AVDT_TRACE_LEVEL
#endif #define AVCT_INITIAL_TRACE_LEVEL UC_BT_LOG_AVCT_TRACE_LEVEL
#define AVRC_INITIAL_TRACE_LEVEL UC_BT_LOG_AVRC_TRACE_LEVEL
#ifdef CONFIG_BT_LOG_L2CAP_TRACE_LEVEL #define MCA_INITIAL_TRACE_LEVEL UC_BT_LOG_MCA_TRACE_LEVEL
#define L2CAP_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_L2CAP_TRACE_LEVEL #define HID_INITIAL_TRACE_LEVEL UC_BT_LOG_HID_TRACE_LEVEL
#else #define APPL_INITIAL_TRACE_LEVEL UC_BT_LOG_APPL_TRACE_LEVEL
#define L2CAP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING #define GATT_INITIAL_TRACE_LEVEL UC_BT_LOG_GATT_TRACE_LEVEL
#endif #define SMP_INITIAL_TRACE_LEVEL UC_BT_LOG_SMP_TRACE_LEVEL
#define BTIF_INITIAL_TRACE_LEVEL UC_BT_LOG_BTIF_TRACE_LEVEL
#ifdef CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL #define BTC_INITIAL_TRACE_LEVEL UC_BT_LOG_BTC_TRACE_LEVEL
#define RFCOMM_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL #define OSI_INITIAL_TRACE_LEVEL UC_BT_LOG_OSI_TRACE_LEVEL
#else #define BLUFI_INITIAL_TRACE_LEVEL UC_BT_LOG_BLUFI_TRACE_LEVEL
#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
// btla-specific -- // 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_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_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__); } #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_EVENT(fmt, args...)
#define BLUFI_TRACE_DEBUG(fmt, args...) #define BLUFI_TRACE_DEBUG(fmt, args...)
#define BLUFI_TRACE_VERBOSE(fmt, args...) #define BLUFI_TRACE_VERBOSE(fmt, args...)
#endif ///CONFIG_BT_STACK_NO_LOG #endif ///!UC_BT_STACK_NO_LOG
/* Simplified Trace Helper Macro /* Simplified Trace Helper Macro

View File

@ -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__ */

View File

@ -46,38 +46,47 @@ const uint8_t SCO_HOST_BUFFER_SIZE = 0xff;
#define BLE_SUPPORTED_STATES_SIZE 8 #define BLE_SUPPORTED_STATES_SIZE 8
#define BLE_SUPPORTED_FEATURES_SIZE 8 #define BLE_SUPPORTED_FEATURES_SIZE 8
static const hci_t *hci; typedef struct {
static const hci_packet_factory_t *packet_factory; const hci_t *hci;
static const hci_packet_parser_t *packet_parser; const hci_packet_factory_t *packet_factory;
const hci_packet_parser_t *packet_parser;
static bt_bdaddr_t address; bt_version_t bt_version;
static bt_version_t bt_version; bt_bdaddr_t address;
static uint8_t supported_commands[HCI_SUPPORTED_COMMANDS_ARRAY_SIZE]; uint8_t supported_commands[HCI_SUPPORTED_COMMANDS_ARRAY_SIZE];
static bt_device_features_t features_classic[MAX_FEATURES_CLASSIC_PAGE_COUNT]; uint8_t last_features_classic_page_index;
static 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; uint16_t acl_data_size_classic;
static uint16_t acl_data_size_ble; uint16_t acl_data_size_ble;
static uint16_t acl_buffer_count_classic; uint16_t acl_buffer_count_classic;
static uint8_t acl_buffer_count_ble; uint8_t acl_buffer_count_ble;
static uint8_t sco_data_size; uint8_t sco_data_size;
static uint16_t sco_buffer_count; uint16_t sco_buffer_count;
static uint8_t ble_white_list_size; uint8_t ble_white_list_size;
static uint8_t ble_resolving_list_max_size; uint8_t ble_resolving_list_max_size;
static uint8_t ble_supported_states[BLE_SUPPORTED_STATES_SIZE]; uint8_t ble_supported_states[BLE_SUPPORTED_STATES_SIZE];
static bt_device_features_t features_ble; bt_device_features_t features_ble;
static uint16_t ble_suggested_default_data_length; uint16_t ble_suggested_default_data_length;
static uint16_t ble_suggested_default_data_txtime; uint16_t ble_suggested_default_data_txtime;
static bool readable; bool readable;
static bool ble_supported; bool ble_supported;
static bool simple_pairing_supported; bool simple_pairing_supported;
static bool secure_connections_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 // Module lifecycle functions
@ -86,29 +95,29 @@ static void start_up(void)
BT_HDR *response; BT_HDR *response;
// Send the initial reset command // Send the initial reset command
response = AWAIT_COMMAND(packet_factory->make_reset()); response = AWAIT_COMMAND(controller_param.packet_factory->make_reset());
packet_parser->parse_generic_command_complete(response); controller_param.packet_parser->parse_generic_command_complete(response);
// Request the classic buffer size next // Request the classic buffer size next
response = AWAIT_COMMAND(packet_factory->make_read_buffer_size()); response = AWAIT_COMMAND(controller_param.packet_factory->make_read_buffer_size());
packet_parser->parse_read_buffer_size_response( controller_param.packet_parser->parse_read_buffer_size_response(
response, &acl_data_size_classic, &acl_buffer_count_classic, response, &controller_param.acl_data_size_classic, &controller_param.acl_buffer_count_classic,
&sco_data_size, &sco_buffer_count); &controller_param.sco_data_size, &controller_param.sco_buffer_count);
#if (C2H_FLOW_CONTROL_INCLUDED == TRUE) #if (C2H_FLOW_CONTROL_INCLUDED == TRUE)
// Enable controller to host flow control // Enable controller to host flow control
response = AWAIT_COMMAND(packet_factory->make_set_c2h_flow_control(HCI_HOST_FLOW_CTRL_ACL_ON)); response = AWAIT_COMMAND(controller_param.packet_factory->make_set_c2h_flow_control(HCI_HOST_FLOW_CTRL_ACL_ON));
packet_parser->parse_generic_command_complete(response); controller_param.packet_parser->parse_generic_command_complete(response);
#endif ///C2H_FLOW_CONTROL_INCLUDED == TRUE #endif ///C2H_FLOW_CONTROL_INCLUDED == TRUE
#if (BLE_ADV_REPORT_FLOW_CONTROL == TRUE) #if (BLE_ADV_REPORT_FLOW_CONTROL == TRUE)
// Enable adv flow control // 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)); 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));
packet_parser->parse_generic_command_complete(response); controller_param.packet_parser->parse_generic_command_complete(response);
#endif #endif
// Tell the controller about our buffer sizes and buffer counts next // 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? // TODO(zachoverflow): factor this out. eww l2cap contamination. And why just a hardcoded 10?
response = AWAIT_COMMAND( response = AWAIT_COMMAND(
packet_factory->make_host_buffer_size( controller_param.packet_factory->make_host_buffer_size(
L2CAP_MTU_SIZE, L2CAP_MTU_SIZE,
SCO_HOST_BUFFER_SIZE, SCO_HOST_BUFFER_SIZE,
L2CAP_HOST_FC_ACL_BUFS, 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 // Read the local version info off the controller next, including
// information such as manufacturer and supported HCI version // information such as manufacturer and supported HCI version
response = AWAIT_COMMAND(packet_factory->make_read_local_version_info()); response = AWAIT_COMMAND(controller_param.packet_factory->make_read_local_version_info());
packet_parser->parse_read_local_version_info_response(response, &bt_version); controller_param.packet_parser->parse_read_local_version_info_response(response, &controller_param.bt_version);
// Read the bluetooth address off the controller next // Read the bluetooth address off the controller next
response = AWAIT_COMMAND(packet_factory->make_read_bd_addr()); response = AWAIT_COMMAND(controller_param.packet_factory->make_read_bd_addr());
packet_parser->parse_read_bd_addr_response(response, &address); controller_param.packet_parser->parse_read_bd_addr_response(response, &controller_param.address);
// Request the controller's supported commands next // Request the controller's supported commands next
response = AWAIT_COMMAND(packet_factory->make_read_local_supported_commands()); response = AWAIT_COMMAND(controller_param.packet_factory->make_read_local_supported_commands());
packet_parser->parse_read_local_supported_commands_response( controller_param.packet_parser->parse_read_local_supported_commands_response(
response, response,
supported_commands, controller_param.supported_commands,
HCI_SUPPORTED_COMMANDS_ARRAY_SIZE HCI_SUPPORTED_COMMANDS_ARRAY_SIZE
); );
// Read page 0 of the controller features next // Read page 0 of the controller features next
uint8_t page_number = 0; uint8_t page_number = 0;
response = AWAIT_COMMAND(packet_factory->make_read_local_extended_features(page_number)); response = AWAIT_COMMAND(controller_param.packet_factory->make_read_local_extended_features(page_number));
packet_parser->parse_read_local_extended_features_response( controller_param.packet_parser->parse_read_local_extended_features_response(
response, response,
&page_number, &page_number,
&last_features_classic_page_index, &controller_param.last_features_classic_page_index,
features_classic, controller_param.features_classic,
MAX_FEATURES_CLASSIC_PAGE_COUNT 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 // next page, because the controller's response for page 1 may be
// dependent on what we configure from page 0 // dependent on what we configure from page 0
#if (BT_SSP_INCLUDED == TRUE) #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 #else
simple_pairing_supported = false; controller_param.simple_pairing_supported = false;
#endif #endif
if (simple_pairing_supported) {
response = AWAIT_COMMAND(packet_factory->make_write_simple_pairing_mode(HCI_SP_MODE_ENABLED)); if (controller_param.simple_pairing_supported) {
packet_parser->parse_generic_command_complete(response); 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 (BLE_INCLUDED == TRUE)
if (HCI_LE_SPT_SUPPORTED(features_classic[0].as_array)) { if (HCI_LE_SPT_SUPPORTED(controller_param.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; 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( 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 #endif
// Done telling the controller about what page 0 features we support // Done telling the controller about what page 0 features we support
// Request the remaining feature pages // 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) { page_number < MAX_FEATURES_CLASSIC_PAGE_COUNT) {
response = AWAIT_COMMAND(packet_factory->make_read_local_extended_features(page_number)); response = AWAIT_COMMAND(controller_param.packet_factory->make_read_local_extended_features(page_number));
packet_parser->parse_read_local_extended_features_response( controller_param.packet_parser->parse_read_local_extended_features_response(
response, response,
&page_number, &page_number,
&last_features_classic_page_index, &controller_param.last_features_classic_page_index,
features_classic, controller_param.features_classic,
MAX_FEATURES_CLASSIC_PAGE_COUNT MAX_FEATURES_CLASSIC_PAGE_COUNT
); );
@ -191,299 +201,297 @@ static void start_up(void)
} }
#if (SC_MODE_INCLUDED == TRUE) #if (SC_MODE_INCLUDED == TRUE)
secure_connections_supported = HCI_SC_CTRLR_SUPPORTED(features_classic[2].as_array); controller_param.secure_connections_supported = HCI_SC_CTRLR_SUPPORTED(controller_param.features_classic[2].as_array);
if (secure_connections_supported) { if (controller_param.secure_connections_supported) {
response = AWAIT_COMMAND(packet_factory->make_write_secure_connections_host_support(HCI_SC_MODE_ENABLED)); response = AWAIT_COMMAND(controller_param.packet_factory->make_write_secure_connections_host_support(HCI_SC_MODE_ENABLED));
packet_parser->parse_generic_command_complete(response); controller_param.packet_parser->parse_generic_command_complete(response);
} }
#endif #endif
#if (BLE_INCLUDED == TRUE) #if (BLE_INCLUDED == TRUE)
ble_supported = last_features_classic_page_index >= 1 && HCI_LE_HOST_SUPPORTED(features_classic[1].as_array); controller_param.ble_supported = controller_param.last_features_classic_page_index >= 1 && HCI_LE_HOST_SUPPORTED(controller_param.features_classic[1].as_array);
if (ble_supported) { if (controller_param.ble_supported) {
// Request the ble white list size next // Request the ble white list size next
response = AWAIT_COMMAND(packet_factory->make_ble_read_white_list_size()); response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_read_white_list_size());
packet_parser->parse_ble_read_white_list_size_response(response, &ble_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 // Request the ble buffer size next
response = AWAIT_COMMAND(packet_factory->make_ble_read_buffer_size()); response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_read_buffer_size());
packet_parser->parse_ble_read_buffer_size_response( controller_param.packet_parser->parse_ble_read_buffer_size_response(
response, response,
&acl_data_size_ble, &controller_param.acl_data_size_ble,
&acl_buffer_count_ble &controller_param.acl_buffer_count_ble
); );
// Response of 0 indicates ble has the same buffer size as classic // Response of 0 indicates ble has the same buffer size as classic
if (acl_data_size_ble == 0) { if (controller_param.acl_data_size_ble == 0) {
acl_data_size_ble = acl_data_size_classic; controller_param.acl_data_size_ble = controller_param.acl_data_size_classic;
} }
// Request the ble supported states next // Request the ble supported states next
response = AWAIT_COMMAND(packet_factory->make_ble_read_supported_states()); response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_read_supported_states());
packet_parser->parse_ble_read_supported_states_response( controller_param.packet_parser->parse_ble_read_supported_states_response(
response, response,
ble_supported_states, controller_param.ble_supported_states,
sizeof(ble_supported_states) sizeof(controller_param.ble_supported_states)
); );
// Request the ble supported features next // Request the ble supported features next
response = AWAIT_COMMAND(packet_factory->make_ble_read_local_supported_features()); response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_read_local_supported_features());
packet_parser->parse_ble_read_local_supported_features_response( controller_param.packet_parser->parse_ble_read_local_supported_features_response(
response, response,
&features_ble &controller_param.features_ble
); );
if (HCI_LE_ENHANCED_PRIVACY_SUPPORTED(features_ble.as_array)) { if (HCI_LE_ENHANCED_PRIVACY_SUPPORTED(controller_param.features_ble.as_array)) {
response = AWAIT_COMMAND(packet_factory->make_ble_read_resolving_list_size()); response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_read_resolving_list_size());
packet_parser->parse_ble_read_resolving_list_size_response( controller_param.packet_parser->parse_ble_read_resolving_list_size_response(
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 */ /* 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)); 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));
packet_parser->parse_generic_command_complete(response); controller_param.packet_parser->parse_generic_command_complete(response);
response = AWAIT_COMMAND(packet_factory->make_ble_read_suggested_default_data_length()); response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_read_suggested_default_data_length());
packet_parser->parse_ble_read_suggested_default_data_length_response( controller_param.packet_parser->parse_ble_read_suggested_default_data_length_response(
response, response,
&ble_suggested_default_data_length, &controller_param.ble_suggested_default_data_length,
&ble_suggested_default_data_txtime); &controller_param.ble_suggested_default_data_txtime);
} }
// Set the ble event mask next // Set the ble event mask next
response = AWAIT_COMMAND(packet_factory->make_ble_set_event_mask(&BLE_EVENT_MASK)); response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_set_event_mask(&BLE_EVENT_MASK));
packet_parser->parse_generic_command_complete(response); controller_param.packet_parser->parse_generic_command_complete(response);
} }
#endif #endif
response = AWAIT_COMMAND(controller_param.packet_factory->make_set_event_mask(&CLASSIC_EVENT_MASK));
response = AWAIT_COMMAND(packet_factory->make_set_event_mask(&CLASSIC_EVENT_MASK)); controller_param.packet_parser->parse_generic_command_complete(response);
packet_parser->parse_generic_command_complete(response);
#if (BTM_SCO_HCI_INCLUDED == TRUE) #if (BTM_SCO_HCI_INCLUDED == TRUE)
response = AWAIT_COMMAND(packet_factory->make_write_sync_flow_control_enable(1)); response = AWAIT_COMMAND(controller_param.packet_factory->make_write_sync_flow_control_enable(1));
packet_parser->parse_generic_command_complete(response); controller_param.packet_parser->parse_generic_command_complete(response);
response = AWAIT_COMMAND(packet_factory->make_write_default_erroneous_data_report(1)); response = AWAIT_COMMAND(controller_param.packet_factory->make_write_default_erroneous_data_report(1));
packet_parser->parse_generic_command_complete(response); controller_param.packet_parser->parse_generic_command_complete(response);
#endif #endif
readable = true; controller_param.readable = true;
// return future_new_immediate(FUTURE_SUCCESS); // return future_new_immediate(FUTURE_SUCCESS);
return; return;
} }
static void shut_down(void) static void shut_down(void)
{ {
readable = false; controller_param.readable = false;
} }
static bool get_is_ready(void) static bool get_is_ready(void)
{ {
return readable; return controller_param.readable;
} }
static const bt_bdaddr_t *get_address(void) static const bt_bdaddr_t *get_address(void)
{ {
assert(readable); assert(controller_param.readable);
return &address; return &controller_param.address;
} }
static const bt_version_t *get_bt_version(void) static const bt_version_t *get_bt_version(void)
{ {
assert(readable); assert(controller_param.readable);
return &bt_version; return &controller_param.bt_version;
} }
// TODO(zachoverflow): hide inside, move decoder inside too // TODO(zachoverflow): hide inside, move decoder inside too
static const bt_device_features_t *get_features_classic(int index) static const bt_device_features_t *get_features_classic(int index)
{ {
assert(readable); assert(controller_param.readable);
assert(index < MAX_FEATURES_CLASSIC_PAGE_COUNT); 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) static uint8_t get_last_features_classic_index(void)
{ {
assert(readable); assert(controller_param.readable);
return last_features_classic_page_index; return controller_param.last_features_classic_page_index;
} }
static const bt_device_features_t *get_features_ble(void) static const bt_device_features_t *get_features_ble(void)
{ {
assert(readable); assert(controller_param.readable);
assert(ble_supported); assert(controller_param.ble_supported);
return &features_ble; return &controller_param.features_ble;
} }
static const uint8_t *get_ble_supported_states(void) static const uint8_t *get_ble_supported_states(void)
{ {
assert(readable); assert(controller_param.readable);
assert(ble_supported); assert(controller_param.ble_supported);
return ble_supported_states; return controller_param.ble_supported_states;
} }
static bool supports_simple_pairing(void) static bool supports_simple_pairing(void)
{ {
assert(readable); assert(controller_param.readable);
return simple_pairing_supported; return controller_param.simple_pairing_supported;
} }
static bool supports_secure_connections(void) static bool supports_secure_connections(void)
{ {
assert(readable); assert(controller_param.readable);
return secure_connections_supported; return controller_param.secure_connections_supported;
} }
static bool supports_simultaneous_le_bredr(void) static bool supports_simultaneous_le_bredr(void)
{ {
assert(readable); assert(controller_param.readable);
return HCI_SIMUL_LE_BREDR_SUPPORTED(features_classic[0].as_array); return HCI_SIMUL_LE_BREDR_SUPPORTED(controller_param.features_classic[0].as_array);
} }
static bool supports_reading_remote_extended_features(void) static bool supports_reading_remote_extended_features(void)
{ {
assert(readable); assert(controller_param.readable);
return HCI_READ_REMOTE_EXT_FEATURES_SUPPORTED(supported_commands); return HCI_READ_REMOTE_EXT_FEATURES_SUPPORTED(controller_param.supported_commands);
} }
static bool supports_interlaced_inquiry_scan(void) static bool supports_interlaced_inquiry_scan(void)
{ {
assert(readable); assert(controller_param.readable);
return HCI_LMP_INTERLACED_INQ_SCAN_SUPPORTED(features_classic[0].as_array); return HCI_LMP_INTERLACED_INQ_SCAN_SUPPORTED(controller_param.features_classic[0].as_array);
} }
static bool supports_rssi_with_inquiry_results(void) static bool supports_rssi_with_inquiry_results(void)
{ {
assert(readable); assert(controller_param.readable);
return HCI_LMP_INQ_RSSI_SUPPORTED(features_classic[0].as_array); return HCI_LMP_INQ_RSSI_SUPPORTED(controller_param.features_classic[0].as_array);
} }
static bool supports_extended_inquiry_response(void) static bool supports_extended_inquiry_response(void)
{ {
assert(readable); assert(controller_param.readable);
return HCI_EXT_INQ_RSP_SUPPORTED(features_classic[0].as_array); return HCI_EXT_INQ_RSP_SUPPORTED(controller_param.features_classic[0].as_array);
} }
static bool supports_master_slave_role_switch(void) static bool supports_master_slave_role_switch(void)
{ {
assert(readable); assert(controller_param.readable);
return HCI_SWITCH_SUPPORTED(features_classic[0].as_array); return HCI_SWITCH_SUPPORTED(controller_param.features_classic[0].as_array);
} }
static bool supports_ble(void) static bool supports_ble(void)
{ {
assert(readable); assert(controller_param.readable);
return ble_supported; return controller_param.ble_supported;
} }
static bool supports_ble_privacy(void) static bool supports_ble_privacy(void)
{ {
assert(readable); assert(controller_param.readable);
assert(ble_supported); assert(controller_param.ble_supported);
return HCI_LE_ENHANCED_PRIVACY_SUPPORTED(features_ble.as_array); return HCI_LE_ENHANCED_PRIVACY_SUPPORTED(controller_param.features_ble.as_array);
} }
static bool supports_ble_packet_extension(void) static bool supports_ble_packet_extension(void)
{ {
assert(readable); assert(controller_param.readable);
assert(ble_supported); assert(controller_param.ble_supported);
return HCI_LE_DATA_LEN_EXT_SUPPORTED(features_ble.as_array); return HCI_LE_DATA_LEN_EXT_SUPPORTED(controller_param.features_ble.as_array);
} }
static bool supports_ble_connection_parameters_request(void) static bool supports_ble_connection_parameters_request(void)
{ {
assert(readable); assert(controller_param.readable);
assert(ble_supported); assert(controller_param.ble_supported);
return HCI_LE_CONN_PARAM_REQ_SUPPORTED(features_ble.as_array); return HCI_LE_CONN_PARAM_REQ_SUPPORTED(controller_param.features_ble.as_array);
} }
static uint16_t get_acl_data_size_classic(void) static uint16_t get_acl_data_size_classic(void)
{ {
assert(readable); assert(controller_param.readable);
return acl_data_size_classic; return controller_param.acl_data_size_classic;
} }
static uint16_t get_acl_data_size_ble(void) static uint16_t get_acl_data_size_ble(void)
{ {
assert(readable); assert(controller_param.readable);
assert(ble_supported); assert(controller_param.ble_supported);
return acl_data_size_ble; return controller_param.acl_data_size_ble;
} }
static uint16_t get_acl_packet_size_classic(void) static uint16_t get_acl_packet_size_classic(void)
{ {
assert(readable); assert(controller_param.readable);
return acl_data_size_classic + HCI_DATA_PREAMBLE_SIZE; return controller_param.acl_data_size_classic + HCI_DATA_PREAMBLE_SIZE;
} }
static uint16_t get_acl_packet_size_ble(void) static uint16_t get_acl_packet_size_ble(void)
{ {
assert(readable); assert(controller_param.readable);
return acl_data_size_ble + HCI_DATA_PREAMBLE_SIZE; return controller_param.acl_data_size_ble + HCI_DATA_PREAMBLE_SIZE;
} }
static uint16_t get_ble_suggested_default_data_length(void) static uint16_t get_ble_suggested_default_data_length(void)
{ {
assert(readable); assert(controller_param.readable);
assert(ble_supported); assert(controller_param.ble_supported);
return ble_suggested_default_data_length; return controller_param.ble_suggested_default_data_length;
} }
static uint16_t get_ble_suggested_default_data_txtime(void) static uint16_t get_ble_suggested_default_data_txtime(void)
{ {
assert(readable); assert(controller_param.readable);
assert(ble_supported); assert(controller_param.ble_supported);
return ble_suggested_default_data_txtime; return controller_param.ble_suggested_default_data_txtime;
} }
static uint16_t get_acl_buffer_count_classic(void) static uint16_t get_acl_buffer_count_classic(void)
{ {
assert(readable); assert(controller_param.readable);
return acl_buffer_count_classic; return controller_param.acl_buffer_count_classic;
} }
static uint8_t get_acl_buffer_count_ble(void) static uint8_t get_acl_buffer_count_ble(void)
{ {
assert(readable); assert(controller_param.readable);
assert(ble_supported); assert(controller_param.ble_supported);
return acl_buffer_count_ble; return controller_param.acl_buffer_count_ble;
} }
static uint8_t get_ble_white_list_size(void) static uint8_t get_ble_white_list_size(void)
{ {
assert(readable); assert(controller_param.readable);
assert(ble_supported); assert(controller_param.ble_supported);
return ble_white_list_size; return controller_param.ble_white_list_size;
} }
static uint8_t get_ble_resolving_list_max_size(void) static uint8_t get_ble_resolving_list_max_size(void)
{ {
assert(readable); assert(controller_param.readable);
assert(ble_supported); assert(controller_param.ble_supported);
return ble_resolving_list_max_size; return controller_param.ble_resolving_list_max_size;
} }
static void set_ble_resolving_list_max_size(int resolving_list_max_size) static void set_ble_resolving_list_max_size(int resolving_list_max_size)
{ {
assert(readable); assert(controller_param.readable);
assert(ble_supported); assert(controller_param.ble_supported);
ble_resolving_list_max_size = resolving_list_max_size; controller_param.ble_resolving_list_max_size = resolving_list_max_size;
} }
#if (BTM_SCO_HCI_INCLUDED == TRUE) #if (BTM_SCO_HCI_INCLUDED == TRUE)
static uint8_t get_sco_data_size(void) static uint8_t get_sco_data_size(void)
{ {
assert(readable); assert(controller_param.readable);
return sco_data_size; return controller_param.sco_data_size;
} }
static uint8_t get_sco_buffer_count(void) static uint8_t get_sco_buffer_count(void)
{ {
assert(readable); assert(controller_param.readable);
return sco_buffer_count; return controller_param.sco_buffer_count;
} }
#endif /* (BTM_SCO_HCI_INCLUDED == TRUE) */ #endif /* (BTM_SCO_HCI_INCLUDED == TRUE) */
@ -541,10 +549,13 @@ const controller_t *controller_get_interface()
static bool loaded = false; static bool loaded = false;
if (!loaded) { if (!loaded) {
loaded = true; loaded = true;
#if BT_BLE_DYNAMIC_ENV_MEMORY == TRUE
hci = hci_layer_get_interface(); controller_param_ptr = (controller_local_param_t *)osi_calloc(sizeof(controller_local_param_t));
packet_factory = hci_packet_factory_get_interface(); assert(controller_param_ptr);
packet_parser = hci_packet_parser_get_interface(); #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; return &interface;

View File

@ -26,6 +26,7 @@
#include <string.h> #include <string.h>
#include "sbc_encoder.h" #include "sbc_encoder.h"
#include "sbc_enc_func_declare.h" #include "sbc_enc_func_declare.h"
#include "osi/allocator.h"
/*#include <math.h>*/ /*#include <math.h>*/
#if (defined(SBC_ENC_INCLUDED) && SBC_ENC_INCLUDED == TRUE) #if (defined(SBC_ENC_INCLUDED) && SBC_ENC_INCLUDED == TRUE)
@ -158,9 +159,16 @@
#if (SBC_USE_ARM_PRAGMA==TRUE) #if (SBC_USE_ARM_PRAGMA==TRUE)
#pragma arm section zidata = "sbc_s32_analysis_section" #pragma arm section zidata = "sbc_s32_analysis_section"
#endif #endif
#if BT_BLE_DYNAMIC_ENV_MEMORY == FALSE
static SINT32 s32DCTY[16] = {0}; static SINT32 s32DCTY[16] = {0};
static SINT32 s32X[ENC_VX_BUFFER_SIZE / 2]; static SINT32 s32X[ENC_VX_BUFFER_SIZE / 2];
static SINT16 *s16X = (SINT16 *) s32X; /* s16X must be 32 bits aligned cf SHIFTUP_X8_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) #if (SBC_USE_ARM_PRAGMA==TRUE)
#pragma arm section zidata #pragma arm section zidata
#endif #endif
@ -1076,6 +1084,19 @@ void SbcAnalysisFilter8 (SBC_ENC_PARAMS *pstrEncParams)
void SbcAnalysisInit (void) 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)); memset(s16X, 0, ENC_VX_BUFFER_SIZE * sizeof(SINT16));
ShiftCounter = 0; ShiftCounter = 0;
} }

View File

@ -30,6 +30,7 @@
#if (C2H_FLOW_CONTROL_INCLUDED == TRUE) #if (C2H_FLOW_CONTROL_INCLUDED == TRUE)
#include "l2c_int.h" #include "l2c_int.h"
#endif ///C2H_FLOW_CONTROL_INCLUDED == TRUE #endif ///C2H_FLOW_CONTROL_INCLUDED == TRUE
#include "stack/hcimsgs.h"
#define HCI_HAL_SERIAL_BUFFER_SIZE 1026 #define HCI_HAL_SERIAL_BUFFER_SIZE 1026
#define HCI_BLE_EVENT 0x3e #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_t interface;
static const hci_hal_callbacks_t *callbacks; static const hci_hal_callbacks_t *callbacks;
static const esp_vhci_host_callback_t vhci_host_cb; static const esp_vhci_host_callback_t vhci_host_cb;
static osi_thread_t *hci_h4_thread;
static xTaskHandle xHciH4TaskHandle;
static xQueueHandle xHciH4Queue;
static void host_send_pkt_available_cb(void); static void host_send_pkt_available_cb(void);
static int host_recv_pkt_cb(uint8_t *data, uint16_t len); 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; 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(upper_callbacks != NULL);
assert(task_thread != NULL);
callbacks = upper_callbacks; callbacks = upper_callbacks;
#if (BLE_ADV_REPORT_FLOW_CONTROL == TRUE) #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 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); hci_hal_env_init(HCI_HAL_SERIAL_BUFFER_SIZE, QUEUE_SIZE_MAX);
#endif #endif
xHciH4Queue = xQueueCreate(HCI_H4_QUEUE_LEN, sizeof(BtTaskEvt_t)); hci_h4_thread = (osi_thread_t *)task_thread;
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);
//register vhci host cb //register vhci host cb
if (esp_vhci_host_register_callback(&vhci_host_cb) != ESP_OK) { if (esp_vhci_host_register_callback(&vhci_host_cb) != ESP_OK) {
@ -125,9 +125,7 @@ static void hal_close()
{ {
hci_hal_env_deinit(); hci_hal_env_deinit();
/* delete task and queue */ hci_h4_thread = NULL;
vTaskDelete(xHciH4TaskHandle);
vQueueDelete(xHciH4Queue);
} }
/** /**
@ -169,30 +167,12 @@ static uint16_t transmit_data(serial_data_type_t type,
// Internal functions // Internal functions
static void hci_hal_h4_rx_handler(void *arg) static void hci_hal_h4_rx_handler(void *arg)
{ {
BtTaskEvt_t e; fixed_queue_process(hci_hal_env.rx_q);
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);
}
}
}
} }
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; return osi_thread_post(hci_h4_thread, hci_hal_h4_rx_handler, NULL, 1, timeout);
evt.sig = SIG_HCI_HAL_RECV_PACKET;
evt.par = 0;
if (xQueueSend(xHciH4Queue, &evt, timeout) != pdTRUE) {
return TASK_POST_SUCCESS;
}
return TASK_POST_FAIL;
} }
#if (C2H_FLOW_CONTROL_INCLUDED == TRUE) #if (C2H_FLOW_CONTROL_INCLUDED == TRUE)
@ -334,7 +314,7 @@ static void event_uart_has_bytes(fixed_queue_t *queue)
{ {
BT_HDR *packet; BT_HDR *packet;
while (!fixed_queue_is_empty(queue)) { 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); 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 //Controller rx cache buffer is ready for receiving new host packet
//Just Call Host main thread task to process pending packets. //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) 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->len = len;
pkt->layer_specific = 0; pkt->layer_specific = 0;
memcpy(pkt->data, data, len); 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); hci_hal_h4_task_post(0);
BTTRC_DUMP_BUFFER("Recv Pkt", pkt->data, len); BTTRC_DUMP_BUFFER("Recv Pkt", pkt->data, len);
return 0; return 0;

View File

@ -21,6 +21,7 @@
#include "common/bt_trace.h" #include "common/bt_trace.h"
#include "stack/hcidefs.h" #include "stack/hcidefs.h"
#include "stack/hcimsgs.h" #include "stack/hcimsgs.h"
#include "stack/btu.h"
#include "common/bt_vendor_lib.h" #include "common/bt_vendor_lib.h"
#include "hci/hci_internals.h" #include "hci/hci_internals.h"
#include "hci/hci_hal.h" #include "hci/hci_hal.h"
@ -33,6 +34,11 @@
#include "osi/mutex.h" #include "osi/mutex.h"
#include "osi/fixed_queue.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 { typedef struct {
uint16_t opcode; uint16_t opcode;
future_t *complete_future; future_t *complete_future;
@ -70,10 +76,7 @@ static const uint32_t COMMAND_PENDING_TIMEOUT = 8000;
static bool interface_created; static bool interface_created;
static hci_t interface; static hci_t interface;
static hci_host_env_t hci_host_env; static hci_host_env_t hci_host_env;
static osi_thread_t *hci_host_thread;
static xTaskHandle xHciHostTaskHandle;
static xQueueHandle xHciHostQueue;
static bool hci_host_startup_flag; static bool hci_host_startup_flag;
// Modules we import and callbacks we export // Modules we import and callbacks we export
@ -102,11 +105,13 @@ int hci_start_up(void)
goto error; goto error;
} }
xHciHostQueue = xQueueCreate(HCI_HOST_QUEUE_LEN, sizeof(BtTaskEvt_t)); 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);
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); if (hci_host_thread == NULL) {
return -2;
}
packet_fragmenter->init(&packet_fragmenter_callbacks); packet_fragmenter->init(&packet_fragmenter_callbacks);
hal->open(&hal_callbacks); hal->open(&hal_callbacks, hci_host_thread);
hci_host_startup_flag = true; hci_host_startup_flag = true;
return 0; return 0;
@ -124,28 +129,15 @@ void hci_shut_down(void)
//low_power_manager->cleanup(); //low_power_manager->cleanup();
hal->close(); 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; return osi_thread_post(hci_host_thread, hci_host_thread_handler, NULL, 0, timeout);
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;
} }
static int hci_layer_init_env(void) 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 * All packets will be directly copied to single queue in driver layer with
* H4 type header added (1 byte). * H4 type header added (1 byte).
*/ */
if (esp_vhci_host_check_send_available()) {
BtTaskEvt_t e; /*Now Target only allowed one packet per TX*/
BT_HDR *pkt = packet_fragmenter->fragment_current_packet();
for (;;) { if (pkt != NULL) {
if (pdTRUE == xQueueReceive(xHciHostQueue, &e, (portTickType)portMAX_DELAY)) { packet_fragmenter->fragment_and_dispatch(pkt);
} else {
if (e.sig == SIG_HCI_HOST_SEND_AVAILABLE) { if (!fixed_queue_is_empty(hci_host_env.command_queue) &&
if (esp_vhci_host_check_send_available()) { hci_host_env.command_credits > 0) {
/*Now Target only allowed one packet per TX*/ fixed_queue_process(hci_host_env.command_queue);
BT_HDR *pkt = packet_fragmenter->fragment_current_packet(); } else if (!fixed_queue_is_empty(hci_host_env.packet_queue)) {
if (pkt != NULL) { fixed_queue_process(hci_host_env.packet_queue);
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); HCI_TRACE_DEBUG("HCI Enqueue Comamnd opcode=0x%x\n", wait_entry->opcode);
BTTRC_DUMP_BUFFER(NULL, command->data + command->offset, command->len); BTTRC_DUMP_BUFFER(NULL, command->data + command->offset, command->len);
fixed_queue_enqueue(hci_host_env.command_queue, wait_entry); fixed_queue_enqueue(hci_host_env.command_queue, wait_entry, FIXED_QUEUE_MAX_TIMEOUT);
hci_host_task_post(TASK_POST_BLOCKING); 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 // in case the upper layer didn't already
command->event = MSG_STACK_TO_HC_HCI_CMD; command->event = MSG_STACK_TO_HC_HCI_CMD;
fixed_queue_enqueue(hci_host_env.command_queue, wait_entry); fixed_queue_enqueue(hci_host_env.command_queue, wait_entry, FIXED_QUEUE_MAX_TIMEOUT);
hci_host_task_post(TASK_POST_BLOCKING); hci_host_task_post(OSI_THREAD_MAX_TIMEOUT);
return future; return future;
} }
@ -302,10 +284,10 @@ static void transmit_downward(uint16_t type, void *data)
transmit_command((BT_HDR *)data, NULL, NULL, NULL); transmit_command((BT_HDR *)data, NULL, NULL, NULL);
HCI_TRACE_WARNING("%s legacy transmit of command. Use transmit_command instead.\n", __func__); HCI_TRACE_WARNING("%s legacy transmit of command. Use transmit_command instead.\n", __func__);
} else { } 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; waiting_command_t *wait_entry = NULL;
command_waiting_response_t *cmd_wait_q = &hci_host_env.cmd_waiting_q; 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(wait_entry->opcode == HCI_HOST_NUM_PACKETS_DONE
#if (BLE_ADV_REPORT_FLOW_CONTROL == TRUE) #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) 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 // The queue may be the command queue or the packet queue, we don't care
packet_fragmenter->fragment_and_dispatch(packet); packet_fragmenter->fragment_and_dispatch(packet);
@ -479,7 +461,7 @@ intercepted:
/*Tell HCI Host Task to continue TX Pending commands*/ /*Tell HCI Host Task to continue TX Pending commands*/
if (hci_host_env.command_credits && if (hci_host_env.command_credits &&
!fixed_queue_is_empty(hci_host_env.command_queue)) { !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) { if (wait_entry) {
@ -507,7 +489,7 @@ static void dispatch_reassembled(BT_HDR *packet)
{ {
// Events should already have been dispatched before this point // Events should already have been dispatched before this point
//Tell Up-layer received packet. //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); osi_free(packet);
} }
} }

View File

@ -51,7 +51,7 @@ typedef struct hci_hal_t {
//bool (*init)(const hci_hal_callbacks_t *upper_callbacks); //bool (*init)(const hci_hal_callbacks_t *upper_callbacks);
// Connect to the underlying hardware, and let data start flowing. // 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. // Disconnect from the underlying hardware, and close the HAL.
// "Daisy, Daisy..." // "Daisy, Daisy..."
void (*close)(void); void (*close)(void);

View File

@ -23,6 +23,8 @@
#include "osi/allocator.h" #include "osi/allocator.h"
#include "osi/osi.h" #include "osi/osi.h"
#include "osi/future.h" #include "osi/future.h"
#include "osi/thread.h"
///// LEGACY DEFINITIONS ///// ///// LEGACY DEFINITIONS /////
/* Message event mask across Host/Controller lib and stack */ /* 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); int hci_start_up(void);
void hci_shut_down(void); void hci_shut_down(void);
bool hci_host_task_post(uint32_t timeout);
#endif /* _HCI_LAYER_H_ */ #endif /* _HCI_LAYER_H_ */

View File

@ -116,7 +116,6 @@
#if BTA_JV_INCLUDED==TRUE #if BTA_JV_INCLUDED==TRUE
#include "bta_jv_int.h" #include "bta_jv_int.h"
tBTA_JV_CB *bta_jv_cb_ptr = NULL;
#endif #endif
#if BTA_HL_INCLUDED == TRUE #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 * ** 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 ** Function BTE_DeinitStack
@ -308,55 +160,101 @@ void BTE_DeinitStack(void)
//BTA Modules //BTA Modules
#if (BTA_INCLUDED == TRUE && BTA_DYNAMIC_MEMORY == TRUE) #if (BTA_INCLUDED == TRUE && BTA_DYNAMIC_MEMORY == TRUE)
#if GATTS_INCLUDED == TRUE #if GATTS_INCLUDED == TRUE
osi_free(bta_gatts_cb_ptr); if (bta_gatts_cb_ptr){
bta_gatts_cb_ptr = NULL; osi_free(bta_gatts_cb_ptr);
bta_gatts_cb_ptr = NULL;
}
#endif #endif
#if GATTC_INCLUDED==TRUE #if GATTC_INCLUDED==TRUE
osi_free(bta_gattc_cb_ptr); if (bta_gattc_cb_ptr){
bta_gattc_cb_ptr = NULL; osi_free(bta_gattc_cb_ptr);
bta_gattc_cb_ptr = NULL;
}
#endif #endif
#if BTA_HH_INCLUDED==TRUE #if BTA_HH_INCLUDED==TRUE
osi_free(bta_hh_cb_ptr); if (bta_hh_cb_ptr){
bta_hh_cb_ptr = NULL; osi_free(bta_hh_cb_ptr);
bta_hh_cb_ptr = NULL;
}
#endif #endif
#if BTA_AV_INCLUDED==TRUE #if BTA_AV_INCLUDED==TRUE
osi_free(bta_av_cb_ptr); if (bta_av_cb_ptr){
bta_av_cb_ptr = NULL; 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 #endif
#if BTA_AR_INCLUDED==TRUE #if BTA_AR_INCLUDED==TRUE
osi_free(bta_ar_cb_ptr); if (bta_ar_cb_ptr){
bta_ar_cb_ptr = NULL; 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 #endif
#if BTA_SDP_INCLUDED == TRUE #if BTA_SDP_INCLUDED == TRUE
osi_free(bta_sdp_cb_ptr); if (bta_sdp_cb_ptr){
bta_sdp_cb_ptr = NULL; osi_free(bta_sdp_cb_ptr);
bta_sdp_cb_ptr = NULL;
}
#endif #endif
#if (defined BTA_JV_INCLUDED && BTA_JV_INCLUDED == TRUE) #if (defined BTA_JV_INCLUDED && BTA_JV_INCLUDED == TRUE)
osi_free(bta_jv_cb_ptr); if (bta_jv_cb_ptr){
bta_jv_cb_ptr = NULL; osi_free(bta_jv_cb_ptr);
bta_jv_cb_ptr = NULL;
}
#endif //JV #endif //JV
#if (defined BTA_HF_INCLUDED && BTA_HF_INCLUDED == TRUE) #if (defined BTA_HF_INCLUDED && BTA_HF_INCLUDED == TRUE)
osi_free(bta_hf_client_cb_ptr); if (bta_hf_client_cb_ptr){
bta_hf_client_cb_ptr = NULL; osi_free(bta_hf_client_cb_ptr);
bta_hf_client_cb_ptr = NULL;
}
#endif #endif
osi_free(bta_dm_di_cb_ptr); if (bta_dm_conn_srvcs_ptr){
bta_dm_di_cb_ptr = NULL; osi_free(bta_dm_conn_srvcs_ptr);
osi_free(bta_dm_search_cb_ptr); bta_dm_conn_srvcs_ptr = NULL;
bta_dm_search_cb_ptr = NULL; }
osi_free(bta_dm_cb_ptr); if (bta_dm_di_cb_ptr){
bta_dm_cb_ptr = NULL; osi_free(bta_dm_di_cb_ptr);
osi_free(bta_sys_cb_ptr); bta_dm_di_cb_ptr = NULL;
bta_sys_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 #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) #if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE && AVCT_DYNAMIC_MEMORY == TRUE)
osi_free(avct_cb_ptr); if (avct_cb_ptr){
avct_cb_ptr = NULL; osi_free(avct_cb_ptr);
avct_cb_ptr = NULL;
}
#endif #endif
#if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE && AVDT_DYNAMIC_MEMORY == TRUE) #if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE && AVDT_DYNAMIC_MEMORY == TRUE)
osi_free(avdt_cb_ptr); if (avdt_cb_ptr){
avdt_cb_ptr = NULL; osi_free(avdt_cb_ptr);
avdt_cb_ptr = NULL;
}
#endif #endif
#if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE) #if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE)
@ -366,4 +264,184 @@ void BTE_DeinitStack(void)
#if (defined(A2D_INCLUDED) && A2D_INCLUDED == TRUE) #if (defined(A2D_INCLUDED) && A2D_INCLUDED == TRUE)
A2D_Deinit(); A2D_Deinit();
#endif #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;
} }

View File

@ -44,7 +44,11 @@ enum {
static osi_mutex_t alarm_mutex; static osi_mutex_t alarm_mutex;
static int alarm_state; static int alarm_state;
#if BT_BLE_DYNAMIC_ENV_MEMORY == FALSE
static struct alarm_t alarm_cbs[ALARM_CBS_NUM]; 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_free(osi_alarm_t *alarm);
static osi_alarm_err_t alarm_set(osi_alarm_t *alarm, period_ms_t timeout, bool is_periodic); 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); OSI_TRACE_WARNING("%s, invalid state %d\n", __func__, alarm_state);
goto end; 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; alarm_state = ALARM_STATE_OPEN;
end: end:
@ -100,6 +111,12 @@ void osi_alarm_deinit(void)
alarm_free(&alarm_cbs[i]); 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; alarm_state = ALARM_STATE_IDLE;
end: end:

View File

@ -24,7 +24,8 @@
extern void *pvPortZalloc(size_t size); extern void *pvPortZalloc(size_t size);
extern void vPortFree(void *pv); extern void vPortFree(void *pv);
#ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG
#if HEAP_MEMORY_DEBUG
#define OSI_MEM_DBG_INFO_MAX 1024*3 #define OSI_MEM_DBG_INFO_MAX 1024*3
typedef struct { typedef struct {
@ -35,8 +36,16 @@ typedef struct {
} osi_mem_dbg_info_t; } osi_mem_dbg_info_t;
static uint32_t mem_dbg_count = 0; 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 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) void osi_mem_dbg_init(void)
{ {
@ -49,7 +58,13 @@ void osi_mem_dbg_init(void)
mem_dbg_info[i].line = 0; mem_dbg_info[i].line = 0;
} }
mem_dbg_count = 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) 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) { if (i >= OSI_MEM_DBG_INFO_MAX) {
OSI_TRACE_ERROR("%s full %s %d !!\n", __func__, func, line); 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) 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++) { for (i = 0; i < OSI_MEM_DBG_INFO_MAX; i++) {
if (mem_dbg_info[i].p == p) { 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].p = NULL;
mem_dbg_info[i].size = 0; mem_dbg_info[i].size = 0;
mem_dbg_info[i].func = NULL; 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("--> 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 #endif
@ -130,47 +213,47 @@ char *osi_strdup(const char *str)
void *osi_malloc_func(size_t size) void *osi_malloc_func(size_t size)
{ {
#ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG #if HEAP_MEMORY_DEBUG
void *p; 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); p = heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL);
#else #else
p = malloc(size); 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__); osi_mem_dbg_record(p, size, __func__, __LINE__);
return p; return p;
#else #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); return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL);
#else #else
return malloc(size); return malloc(size);
#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */ #endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */
#endif /* #ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG */ #endif /* #if HEAP_MEMORY_DEBUG */
} }
void *osi_calloc_func(size_t size) void *osi_calloc_func(size_t size)
{ {
#ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG #if HEAP_MEMORY_DEBUG
void *p; 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); p = heap_caps_calloc_prefer(1, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL);
#else #else
p = calloc(1, size); 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__); osi_mem_dbg_record(p, size, __func__, __LINE__);
return p; return p;
#else #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); return heap_caps_calloc_prefer(1, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL);
#else #else
return calloc(1, size); return calloc(1, size);
#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */ #endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */
#endif /* #ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG */ #endif /* #if HEAP_MEMORY_DEBUG */
} }
void osi_free_func(void *ptr) void osi_free_func(void *ptr)
{ {
#ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG #if HEAP_MEMORY_DEBUG
osi_mem_dbg_clean(ptr, __func__, __LINE__); osi_mem_dbg_clean(ptr, __func__, __LINE__);
#endif #endif
free(ptr); free(ptr);

View File

@ -129,45 +129,12 @@ size_t fixed_queue_capacity(fixed_queue_t *queue)
return queue->capacity; 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(queue != NULL);
assert(data != NULL); assert(data != NULL);
osi_sem_take(&queue->enqueue_sem, OSI_SEM_MAX_TIMEOUT); if (osi_sem_take(&queue->enqueue_sem, timeout) != 0) {
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) {
return false; return false;
} }
@ -181,15 +148,13 @@ bool fixed_queue_try_enqueue(fixed_queue_t *queue, void *data)
return true; 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; void *ret = NULL;
if (queue == NULL) { assert(queue != NULL);
return NULL;
}
if (osi_sem_take(queue->dequeue_sem, 0) != 0) { if (osi_sem_take(queue->dequeue_sem, timeout) != 0) {
return NULL; return NULL;
} }

View File

@ -22,7 +22,6 @@
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include "esp_heap_caps.h" #include "esp_heap_caps.h"
#include "sdkconfig.h"
char *osi_strdup(const char *str); 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_calloc_func(size_t size);
void osi_free_func(void *ptr); 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_init(void);
void osi_mem_dbg_record(void *p, int size, const char *func, int line); 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_clean(void *p, const char *func, int line);
void osi_mem_dbg_show(void); 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) \ #define osi_malloc(size) \
({ \ ({ \
void *p; \ void *p; \
@ -68,15 +72,15 @@ void osi_mem_dbg_show(void);
(void *)p; \ (void *)p; \
}) })
#define osi_calloc(size) \ #define osi_calloc(size) \
({ \ ({ \
void *p; \ void *p; \
p = calloc(1, (size)); \ p = calloc(1, (size)); \
osi_mem_dbg_record(p, size, __func__, __LINE__); \ osi_mem_dbg_record(p, size, __func__, __LINE__); \
(void *)p; \ (void *)p; \
}) })
#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */ #endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */
#if 0 #if 0
@ -84,11 +88,11 @@ void osi_mem_dbg_show(void);
do { \ do { \
void *p; \ 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); \ p = heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); \
#else \ #else \
p = malloc((size)); \ 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__); \ osi_mem_dbg_record(p, size, __func__, __LINE__); \
(void *)p; \ (void *)p; \
}while(0) }while(0)
@ -97,13 +101,13 @@ do { \
do { \ do { \
void *p; \ void *p; \
\ \
#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST \ #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST \
p = heap_caps_calloc_prefer(1, size, 2, \ p = heap_caps_calloc_prefer(1, size, 2, \
MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, \ MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, \
MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); \ MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); \
#else \ #else \
p = calloc(1, (size)); \ 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__); \ osi_mem_dbg_record(p, size, __func__, __LINE__); \
(void *)p; \ (void *)p; \
} while(0) } while(0)
@ -118,16 +122,16 @@ do { \
#else #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_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) #define osi_calloc(size) heap_caps_calloc_prefer(1, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL)
#else #else
#define osi_malloc(size) malloc((size)) #define osi_malloc(size) malloc((size))
#define osi_calloc(size) calloc(1, (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)) #define osi_free(p) free((p))
#endif /* CONFIG_BT_BLUEDROID_MEM_DEBUG */ #endif /* HEAP_MEMORY_DEBUG */
#define FREE_AND_RESET(a) \ #define FREE_AND_RESET(a) \
do { \ do { \

View File

@ -21,11 +21,14 @@
#include <stdbool.h> #include <stdbool.h>
#include "osi/list.h" #include "osi/list.h"
#include "osi/semaphore.h"
#ifndef QUEUE_SIZE_MAX #ifndef QUEUE_SIZE_MAX
#define QUEUE_SIZE_MAX 254 #define QUEUE_SIZE_MAX 254
#endif #endif
#define FIXED_QUEUE_MAX_TIMEOUT OSI_SEM_MAX_TIMEOUT
struct fixed_queue_t; struct fixed_queue_t;
typedef struct fixed_queue_t 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. // not be NULL.
size_t fixed_queue_capacity(fixed_queue_t *queue); size_t fixed_queue_capacity(fixed_queue_t *queue);
// Enqueues the given |data| into the |queue|. The caller will be blocked // 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 nore more space is available in the queue. Neither |queue| nor |data| // If enqueue failed, it will return false, otherwise return true
// may be NULL. bool fixed_queue_enqueue(fixed_queue_t *queue, void *data, uint32_t timeout);
void fixed_queue_enqueue(fixed_queue_t *queue, void *data);
// Dequeues the next element from |queue|. If the queue is currently empty, // Dequeues the next element from |queue|. If the queue is currently empty,
// this function will block the caller until an item is enqueued. This // this function will block the caller until an item is enqueued or immediately return or wait for timeout according to the parameter timeout.
// function will never return NULL. |queue| may not be NULL. // If dequeue failed, it will return NULL, otherwise return a point.
void *fixed_queue_dequeue(fixed_queue_t *queue); void *fixed_queue_dequeue(fixed_queue_t *queue, uint32_t timeout);
// 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);
// Returns the first element from |queue|, if present, without dequeuing it. // Returns the first element from |queue|, if present, without dequeuing it.
// This function will never block the caller. Returns NULL if there are no // This function will never block the caller. Returns NULL if there are no

View File

@ -23,9 +23,9 @@
#include "freertos/task.h" #include "freertos/task.h"
#include "freertos/queue.h" #include "freertos/queue.h"
#include "freertos/semphr.h" #include "freertos/semphr.h"
#include "osi/semaphore.h"
#define OSI_MUTEX_MAX_TIMEOUT OSI_SEM_MAX_TIMEOUT
#define OSI_MUTEX_MAX_TIMEOUT 0xffffffffUL
#define osi_mutex_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE ) #define osi_mutex_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE )
#define osi_mutex_set_invalid( x ) ( ( *x ) = NULL ) #define osi_mutex_set_invalid( x ) ( ( *x ) = NULL )

View File

@ -22,94 +22,71 @@
#include "freertos/task.h" #include "freertos/task.h"
#include "esp_task.h" #include "esp_task.h"
#include "common/bt_defs.h" #include "common/bt_defs.h"
#include "osi/semaphore.h"
#define portBASE_TYPE int #define portBASE_TYPE int
struct bt_task_evt { #define OSI_THREAD_MAX_TIMEOUT OSI_SEM_MAX_TIMEOUT
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;
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 { typedef enum {
SIG_HCI_HAL_RECV_PACKET = 0, OSI_THREAD_CORE_0 = 0,
SIG_HCI_HAL_NUM, OSI_THREAD_CORE_1,
} SIG_HCI_HAL_t; 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, * brief: Destroy a thread or task
SIG_HCI_HOST_NUM, * param thread: point of thread handler
} SIG_HCI_HOST_t; */
void osi_thread_free(osi_thread_t *thread);
typedef enum { /*
SIG_BTU_START_UP = 0, * brief: Post an msg to a thread and told the thread call the function
SIG_BTU_HCI_MSG, * param thread: point of thread handler
SIG_BTU_BTA_MSG, * param func: callback function that called by target thread
SIG_BTU_BTA_ALARM, * param context: argument of callback function
SIG_BTU_GENERAL_ALARM, * param queue_idx: the queue which the msg send to
SIG_BTU_ONESHOT_ALARM, * param timeout: post timeout, OSI_THREAD_MAX_TIMEOUT means blocking forever, 0 means never blocking, others means block millisecond
SIG_BTU_L2CAP_ALARM, * return : if post successfully, return true, otherwise return false
SIG_BTU_NUM, */
} SIG_BTU_t; 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) /* brief: Get thread name
#define HCI_HOST_TASK_STACK_SIZE (2048 + BT_TASK_EXTRA_STACK_SIZE) * param thread: point of thread handler
#define HCI_HOST_TASK_PRIO (configMAX_PRIORITIES - 3) * return: constant point of thread name
#define HCI_HOST_TASK_NAME "hciHostT" */
#define HCI_HOST_QUEUE_LEN 40 const char *osi_thread_name(osi_thread_t *thread);
#define HCI_H4_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE) /* brief: Get the size of the specified queue
#define HCI_H4_TASK_STACK_SIZE (2048 + BT_TASK_EXTRA_STACK_SIZE) * param thread: point of thread handler
#define HCI_H4_TASK_PRIO (configMAX_PRIORITIES - 4) * param wq_idx: the queue index of the thread
#define HCI_H4_TASK_NAME "hciH4T" * return: queue size
#define HCI_H4_QUEUE_LEN 1 */
int osi_thread_queue_wait_size(osi_thread_t *thread, int wq_idx);
#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);
#endif /* __THREAD_H__ */ #endif /* __THREAD_H__ */

View File

@ -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 <string.h>
#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]);
}

View File

@ -372,13 +372,16 @@ UINT8 A2D_BitsSet(UINT8 num)
** other API functions for this layer. It is typically called ** other API functions for this layer. It is typically called
** once during the start up of the stack. ** 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) #if (A2D_DYNAMIC_MEMORY)
a2d_cb_ptr = (tA2D_CB *)osi_malloc(sizeof(tA2D_CB)); a2d_cb_ptr = (tA2D_CB *)osi_malloc(sizeof(tA2D_CB));
if (!a2d_cb_ptr) {
return BT_STATUS_NOMEM;
}
#endif /* #if (A2D_DYNAMIC_MEMORY) */ #endif /* #if (A2D_DYNAMIC_MEMORY) */
memset(&a2d_cb, 0, sizeof(tA2D_CB)); memset(&a2d_cb, 0, sizeof(tA2D_CB));
@ -389,6 +392,7 @@ void A2D_Init(void)
#else #else
a2d_cb.trace_level = BT_TRACE_LEVEL_NONE; a2d_cb.trace_level = BT_TRACE_LEVEL_NONE;
#endif #endif
return BT_STATUS_SUCCESS;
} }
/******************************************************************************* /*******************************************************************************
@ -404,8 +408,10 @@ void A2D_Init(void)
void A2D_Deinit(void) void A2D_Deinit(void)
{ {
#if (A2D_DYNAMIC_MEMORY) #if (A2D_DYNAMIC_MEMORY)
osi_free(a2d_cb_ptr); if (a2d_cb_ptr) {
a2d_cb_ptr = NULL; osi_free(a2d_cb_ptr);
a2d_cb_ptr = NULL;
}
#endif /* #if (A2D_DYNAMIC_MEMORY) */ #endif /* #if (A2D_DYNAMIC_MEMORY) */
} }

View File

@ -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)) if (p_lcb->cong == FALSE && !fixed_queue_is_empty(p_lcb->tx_q))
{ {
while (!p_lcb->cong && 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) 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) { 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 */ /* send message to L2CAP */

View File

@ -68,7 +68,7 @@ static void avdt_ccb_clear_ccb(tAVDT_CCB *p_ccb)
} }
/* clear out response queue */ /* 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); 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); avdt_ccb_cmd_fail(p_ccb, (tAVDT_CCB_EVT *) &err_code);
/* set up next message */ /* 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); } 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 ** 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_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 */ /* make a copy of buffer in p_curr_cmd */
if ((p_ccb->p_curr_cmd = (BT_HDR *) osi_malloc(AVDT_CMD_BUF_SIZE)) != NULL) { 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)); 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 */ /* do we have responses to send? send them */
else if (!fixed_queue_is_empty(p_ccb->rsp_q)) { 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) { if (avdt_msg_send(p_ccb, p_msg) == TRUE) {
/* break out if congested */ /* break out if congested */
break; break;

View File

@ -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; p_ccb->label = (p_ccb->label + 1) % 16;
/* queue message and trigger ccb to send it */ /* 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); 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); AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_RSP, p_params->hdr.label);
/* queue message and trigger ccb to send it */ /* 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); 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); AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_REJ, p_params->hdr.label);
/* queue message and trigger ccb to send it */ /* 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); 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"); AVDT_TRACE_DEBUG("avdt_msg_send_grej");
/* queue message and trigger ccb to send it */ /* 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); avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL);
} }

View File

@ -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 */ /* this shouldn't be happening */
AVDT_TRACE_WARNING("*** Dropped media packet; congested"); AVDT_TRACE_WARNING("*** Dropped media packet; congested");
BT_HDR *p_frag; 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); 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 */ /* clean fragments queue */
BT_HDR *p_frag; 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); osi_free(p_frag);
} }
p_scb->frag_off = 0; 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 #if AVDT_MULTIPLEXING == TRUE
/* clean fragments queue */ /* clean fragments queue */
BT_HDR *p_frag; 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); osi_free(p_frag);
} }
#endif #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"); AVDT_TRACE_DEBUG("Dropped fragments queue");
/* clean fragments queue */ /* clean fragments queue */
BT_HDR *p_frag; 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); osi_free(p_frag);
} }
p_scb->frag_off = 0; 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), 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); L2CAP_FLUSH_CHANS_GET);
#endif #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; sent = TRUE;
AVDT_TRACE_DEBUG("Send fragment len=%d\n", p_pkt->len); AVDT_TRACE_DEBUG("Send fragment len=%d\n", p_pkt->len);
/* fragments queue contains fragment to send */ /* 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 ); UINT16_TO_BE_STREAM(p, p_frag->layer_specific );
} }
/* put fragment into gueue */ /* 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--; num_frag--;
} }
} }

View File

@ -340,13 +340,16 @@ UINT8 AVRC_SetTraceLevel (UINT8 new_level)
** control block (if using dynamic memory), and initializes the ** control block (if using dynamic memory), and initializes the
** control block and tracing level. ** control block and tracing level.
** **
** Returns void ** Returns status
** **
*******************************************************************************/ *******************************************************************************/
void AVRC_Init(void) bt_status_t AVRC_Init(void)
{ {
#if AVRC_DYNAMIC_MEMORY #if AVRC_DYNAMIC_MEMORY
avrc_cb_ptr = (tAVRC_CB *)osi_malloc(sizeof(tAVRC_CB)); avrc_cb_ptr = (tAVRC_CB *)osi_malloc(sizeof(tAVRC_CB));
if (!avrc_cb_ptr) {
return BT_STATUS_NOMEM;
}
#endif /* #if AVRC_DYNAMIC_MEMORY */ #endif /* #if AVRC_DYNAMIC_MEMORY */
memset(&avrc_cb, 0, sizeof(tAVRC_CB)); memset(&avrc_cb, 0, sizeof(tAVRC_CB));
@ -355,6 +358,7 @@ void AVRC_Init(void)
#else #else
avrc_cb.trace_level = BT_TRACE_LEVEL_NONE; avrc_cb.trace_level = BT_TRACE_LEVEL_NONE;
#endif #endif
return BT_STATUS_SUCCESS;
} }
/******************************************************************************* /*******************************************************************************
@ -371,8 +375,10 @@ void AVRC_Init(void)
void AVRC_Deinit(void) void AVRC_Deinit(void)
{ {
#if AVRC_DYNAMIC_MEMORY #if AVRC_DYNAMIC_MEMORY
osi_free(avrc_cb_ptr); if (avrc_cb_ptr){
avrc_cb_ptr = NULL; osi_free(avrc_cb_ptr);
avrc_cb_ptr = NULL;
}
#endif /* #if AVRC_DYNAMIC_MEMORY */ #endif /* #if AVRC_DYNAMIC_MEMORY */
} }

View File

@ -2038,6 +2038,8 @@ tBTM_STATUS BTM_ReadTxPower (BD_ADDR remote_bda, tBT_TRANSPORT transport, tBTM_C
/* If here, no BD Addr found */ /* If here, no BD Addr found */
return (BTM_UNKNOWN_ADDR); return (BTM_UNKNOWN_ADDR);
} }
#if (BLE_INCLUDED == TRUE)
tBTM_STATUS BTM_BleReadAdvTxPower(tBTM_CMPL_CB *p_cb) tBTM_STATUS BTM_BleReadAdvTxPower(tBTM_CMPL_CB *p_cb)
{ {
BOOLEAN ret; BOOLEAN ret;
@ -2074,6 +2076,7 @@ void BTM_BleGetWhiteListSize(uint16_t *length)
*length = p_cb->white_list_avail_size; *length = p_cb->white_list_avail_size;
return; return;
} }
#endif ///BLE_INCLUDED == TRUE
/******************************************************************************* /*******************************************************************************
** **
@ -2361,7 +2364,7 @@ void btm_acl_resubmit_page (void)
BD_ADDR bda; BD_ADDR bda;
BTM_TRACE_DEBUG ("btm_acl_resubmit_page\n"); BTM_TRACE_DEBUG ("btm_acl_resubmit_page\n");
/* If there were other page request schedule can start the next one */ /* 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 /* skip 3 (2 bytes opcode and 1 byte len) to get to the bd_addr
* for both create_conn and rmt_name */ * for both create_conn and rmt_name */
pp = (UINT8 *)(p_buf + 1) + p_buf->offset + 3; pp = (UINT8 *)(p_buf + 1) + p_buf->offset + 3;
@ -2392,7 +2395,7 @@ void btm_acl_reset_paging (void)
BT_HDR *p; BT_HDR *p;
BTM_TRACE_DEBUG ("btm_acl_reset_paging\n"); BTM_TRACE_DEBUG ("btm_acl_reset_paging\n");
/* If we sent reset we are definitely not paging any more */ /* 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); 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]); (bda[0] << 16) + (bda[1] << 8) + bda[2], (bda[3] << 16) + (bda[4] << 8) + bda[5]);
if (btm_cb.discing) { if (btm_cb.discing) {
btm_cb.paging = TRUE; 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 { } else {
if (!BTM_ACL_IS_CONNECTED (bda)) { if (!BTM_ACL_IS_CONNECTED (bda)) {
BTM_TRACE_DEBUG ("connecting_bda: %06x%06x\n", 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]); btm_cb.connecting_bda[5]);
if (btm_cb.paging && if (btm_cb.paging &&
memcmp (bda, btm_cb.connecting_bda, BD_ADDR_LEN) != 0) { 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 { } else {
p_dev_rec = btm_find_or_alloc_dev (bda); p_dev_rec = btm_find_or_alloc_dev (bda);
memcpy (btm_cb.connecting_bda, p_dev_rec->bd_addr, BD_ADDR_LEN); memcpy (btm_cb.connecting_bda, p_dev_rec->bd_addr, BD_ADDR_LEN);

View File

@ -24,8 +24,6 @@
******************************************************************************/ ******************************************************************************/
#include "common/bt_target.h" #include "common/bt_target.h"
#if BLE_INCLUDED == TRUE
#include <string.h> #include <string.h>
#include "stack/bt_types.h" #include "stack/bt_types.h"
@ -41,7 +39,7 @@
//#define LOG_TAG "bt_btm_ble" //#define LOG_TAG "bt_btm_ble"
//#include "osi/include/log.h" //#include "osi/include/log.h"
#if BLE_INCLUDED == TRUE
#if SMP_INCLUDED == TRUE #if SMP_INCLUDED == TRUE
// The temp variable to pass parameter between functions when in the connected event callback. // The temp variable to pass parameter between functions when in the connected event callback.
static BOOLEAN temp_enhanced = FALSE; 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); 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; return FALSE;
} }
#if (BLE_INCLUDED == TRUE)
if (transport == BT_TRANSPORT_LE) { if (transport == BT_TRANSPORT_LE) {
memcpy(remote_bda, p_dev_rec->ble.pseudo_addr, BD_ADDR_LEN); 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) { 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; return FALSE;
} }
} }
#endif ///BLE_INCLUDED == TRUE
return FALSE; return FALSE;
} }
#if (BLE_INCLUDED == TRUE)
/******************************************************************************* /*******************************************************************************
** **
** Function BTM_BleReceiverTest ** 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 ///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 (SMP_INCLUDED == TRUE)
#if (BLE_INCLUDED == TRUE)
BOOLEAN btm_ble_get_enc_key_type(BD_ADDR bd_addr, UINT8 *p_key_types) BOOLEAN btm_ble_get_enc_key_type(BD_ADDR bd_addr, UINT8 *p_key_types)
{ {
tBTM_SEC_DEV_REC *p_dev_rec; 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; return status;
} }
/******************************************************************************* /*******************************************************************************
** **
** Function btm_sec_save_le_key ** 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 #endif ///SMP_INCLUDED == TRUE
#if (BLE_INCLUDED == TRUE)
/******************************************************************************* /*******************************************************************************
** **
** Function btm_ble_set_encryption ** 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 #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_state,
btm_cb.pairing_flags, btm_cb.pairing_flags);
btm_cb.pin_code_len );
BTM_TRACE_DEBUG ("btm_cb.pairing_bda %02x:%02x:%02x:%02x:%02x:%02x", 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[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]); btm_cb.pairing_bda[3], btm_cb.pairing_bda[4], btm_cb.pairing_bda[5]);

View File

@ -48,8 +48,16 @@
#define BTM_BLE_PF_BIT_TO_MASK(x) (UINT16)(1 << (x)) #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_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 const BD_ADDR na_bda = {0};
static UINT8 btm_ble_cs_update_pf_counter(tBTM_BLE_SCAN_COND_OP action, 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; tBTM_STATUS st = BTM_SUCCESS;
#if BLE_VND_INCLUDED == TRUE #if BLE_VND_INCLUDED == TRUE
BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb); BTM_BleGetVendorCapabilities(&cmn_ble_adv_vsc_cb);
if (0 == cmn_ble_vsc_cb.max_filter) { if (0 == cmn_ble_adv_vsc_cb.max_filter) {
st = BTM_MODE_UNSUPPORTED; st = BTM_MODE_UNSUPPORTED;
return st; return st;
} }
#else #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 #endif
return st; 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]; 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 && if (p_addr_filter->in_use &&
memcmp(p_le_bda->bda, p_addr_filter->bd_addr, BD_ADDR_LEN) == 0) { memcmp(p_le_bda->bda, p_addr_filter->bd_addr, BD_ADDR_LEN) == 0) {
return p_addr_filter; return p_addr_filter;
@ -390,7 +398,7 @@ tBTM_BLE_PF_COUNT *btm_ble_alloc_addr_filter_counter(BD_ADDR bd_addr)
UINT8 i; UINT8 i;
tBTM_BLE_PF_COUNT *p_addr_filter = &btm_ble_adv_filt_cb.p_addr_filter_count[1]; 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) { if (memcmp(na_bda, p_addr_filter->bd_addr, BD_ADDR_LEN) == 0) {
memcpy(p_addr_filter->bd_addr, bd_addr, BD_ADDR_LEN); memcpy(p_addr_filter->bd_addr, bd_addr, BD_ADDR_LEN);
p_addr_filter->in_use = TRUE; 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)); 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 || if ((p_addr_filter->in_use) && (NULL == p_bd_addr ||
(NULL != p_bd_addr && (NULL != p_bd_addr &&
memcmp(p_bd_addr->bda, p_addr_filter->bd_addr, BD_ADDR_LEN) == 0))) { 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", 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]; return p_counter[cond_type];
} }
} else { } else {
@ -1052,12 +1060,12 @@ tBTM_STATUS BTM_BleAdvFilterParamSetup(int action, tBTM_BLE_PF_FILT_INDEX filt_i
/* set onlost timeout */ /* set onlost timeout */
UINT16_TO_STREAM(p, p_filt_params->lost_timeout); UINT16_TO_STREAM(p, p_filt_params->lost_timeout);
/* set num_of_track_entries for firmware greater than L-release version */ /* 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); 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; len = BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_ADV_FILT_FEAT_SELN_LEN;
} else { } else {
len = BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_ADV_FILT_FEAT_SELN_LEN + 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) 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()) { if (BTM_SUCCESS != btm_ble_obtain_vsc_details()) {
return; 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 = 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); osi_free(btm_ble_adv_filt_cb.p_addr_filter_count);
btm_ble_adv_filt_cb.p_addr_filter_count = NULL; 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 #endif

View File

@ -30,9 +30,15 @@
#if (BLE_INCLUDED == TRUE) #if (BLE_INCLUDED == TRUE)
tBTM_BLE_BATCH_SCAN_CB ble_batchscan_cb; #if BTM_DYNAMIC_MEMORY == FALSE
tBTM_BLE_ADV_TRACK_CB ble_advtrack_cb; 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 */ /* length of each batch scan command */
#define BTM_BLE_BATCH_SCAN_STORAGE_CFG_LEN 4 #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) 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"); BTM_TRACE_EVENT (" btm_ble_batchscan_init");
memset(&ble_batchscan_cb, 0, sizeof(tBTM_BLE_BATCH_SCAN_CB)); memset(&ble_batchscan_cb, 0, sizeof(tBTM_BLE_BATCH_SCAN_CB));
memset(&ble_advtrack_cb, 0, sizeof(tBTM_BLE_ADV_TRACK_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_batchscan_cb, 0, sizeof(tBTM_BLE_BATCH_SCAN_CB));
memset(&ble_advtrack_cb, 0, sizeof(tBTM_BLE_ADV_TRACK_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 #endif

View File

@ -785,7 +785,7 @@ void btm_ble_enqueue_direct_conn_req(void *p_param)
p->p_param = 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; tBTM_BLE_CONN_REQ *p_req;
BOOLEAN rt = FALSE; 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) { if (p_req != NULL) {
rt = l2cble_init_direct_conn((tL2C_LCB *)(p_req->p_param)); rt = l2cble_init_direct_conn((tL2C_LCB *)(p_req->p_param));

View File

@ -57,7 +57,12 @@
#define MIN_ADV_LENGTH 2 #define MIN_ADV_LENGTH 2
#define BTM_VSC_CHIP_CAPABILITY_RSP_LEN_L_RELEASE 9 #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 #if BLE_VND_INCLUDED == TRUE
static tBTM_BLE_CTRL_FEATURES_CBACK *p_ctrl_le_feature_rd_cmpl_cback = NULL; 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_enable_status = 0;
uint8_t scan_param_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_enable_lock);
osi_mutex_new(&adv_data_lock); osi_mutex_new(&adv_data_lock);
@ -250,7 +255,7 @@ void btm_lock_init(void)
osi_mutex_new(&scan_param_lock); 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_enable_lock);
osi_mutex_free(&adv_data_lock); osi_mutex_free(&adv_data_lock);
@ -259,7 +264,7 @@ void btm_lock_free(void)
osi_mutex_free(&scan_param_lock); 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_enable_sem, 1, 0);
osi_sem_new(&adv_data_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); 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_enable_sem);
osi_sem_free(&adv_data_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); btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN);
#endif #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, btsnd_hcic_ble_set_scan_params(p_inq->scan_type, (UINT16)scan_interval,
(UINT16)scan_window, (UINT16)scan_window,
btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, 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) void btm_ble_init (void)
{ {
tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
BTM_TRACE_DEBUG("%s", __func__); 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->obs_timer_ent);
btu_free_timer(&p_cb->scan_timer_ent); btu_free_timer(&p_cb->scan_timer_ent);
btu_free_timer(&p_cb->inq_var.fast_adv_timer); btu_free_timer(&p_cb->inq_var.fast_adv_timer);
@ -4340,6 +4353,11 @@ void btm_ble_free (void)
BTM_TRACE_DEBUG("%s", __func__); BTM_TRACE_DEBUG("%s", __func__);
fixed_queue_free(p_cb->conn_pending_q, osi_free_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
} }
/******************************************************************************* /*******************************************************************************

View File

@ -45,8 +45,15 @@
/************************************************************************************ /************************************************************************************
** Static variables ** Static variables
************************************************************************************/ ************************************************************************************/
tBTM_BLE_MULTI_ADV_CB btm_multi_adv_cb; #if BTM_DYNAMIC_MEMORY == FALSE
tBTM_BLE_MULTI_ADV_INST_IDX_Q btm_multi_adv_idx_q; 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 ** Externs
@ -764,6 +771,15 @@ void btm_ble_multi_adv_vse_cback(UINT8 len, UINT8 *p)
*******************************************************************************/ *******************************************************************************/
void btm_ble_multi_adv_init() 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; UINT8 i = 0;
memset(&btm_multi_adv_cb, 0, sizeof(tBTM_BLE_MULTI_ADV_CB)); 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)); 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; 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
} }
/******************************************************************************* /*******************************************************************************

View File

@ -882,6 +882,7 @@ void btm_ble_enable_resolving_list(UINT8 rl_mask)
} }
} }
#if 0 //Unused
/******************************************************************************* /*******************************************************************************
** **
** Function btm_ble_resolving_list_empty ** 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() == return (controller_get_interface()->get_ble_resolving_list_max_size() ==
btm_cb.ble_ctr_cb.resolving_list_avail_size); btm_cb.ble_ctr_cb.resolving_list_avail_size);
} }
#endif
/******************************************************************************* /*******************************************************************************
** **

View File

@ -190,9 +190,9 @@ static void reset_complete(void)
l2c_link_processs_ble_num_bufs(controller->get_acl_buffer_count_ble()); l2c_link_processs_ble_num_bufs(controller->get_acl_buffer_count_ble());
} }
#endif #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); 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++) { 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); 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, void btm_vsc_complete (UINT8 *p, UINT16 opcode, UINT16 evt_len,
tBTM_CMPL_CB *p_vsc_cplt_cback) tBTM_CMPL_CB *p_vsc_cplt_cback)
{ {
#if (BLE_INCLUDED == TRUE)
tBTM_BLE_CB *ble_cb = &btm_cb.ble_ctr_cb; tBTM_BLE_CB *ble_cb = &btm_cb.ble_ctr_cb;
switch(opcode) { switch(opcode) {
case HCI_VENDOR_BLE_LONG_ADV_DATA: 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; vcs_cplt_params.p_param_buf = p;
(*p_vsc_cplt_cback)(&vcs_cplt_params); /* Call the VSC complete callback function */ (*p_vsc_cplt_cback)(&vcs_cplt_params); /* Call the VSC complete callback function */
} }
#endif
} }
/******************************************************************************* /*******************************************************************************

View File

@ -75,8 +75,10 @@ void btm_init (void)
#endif #endif
btm_dev_init(); /* Device Manager Structures & HCI_Reset */ btm_dev_init(); /* Device Manager Structures & HCI_Reset */
btm_lock_init(); #if BLE_INCLUDED == TRUE
btm_sem_init(); btm_ble_lock_init();
btm_ble_sem_init();
#endif
} }
@ -96,6 +98,8 @@ void btm_free(void)
#if BTM_DYNAMIC_MEMORY #if BTM_DYNAMIC_MEMORY
FREE_AND_RESET(btm_cb_ptr); FREE_AND_RESET(btm_cb_ptr);
#endif #endif
btm_lock_free(); #if BLE_INCLUDED == TRUE
btm_sem_free(); btm_ble_lock_free();
btm_ble_sem_free();
#endif
} }

View File

@ -86,7 +86,7 @@ void btm_sco_flush_sco_data(UINT16 sco_inx)
if (sco_inx < BTM_MAX_SCO_LINKS) { if (sco_inx < BTM_MAX_SCO_LINKS) {
p = &btm_cb.sco_cb.sco_db[sco_inx]; 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); osi_free(p_buf);
} }
} }
@ -292,7 +292,7 @@ void btm_sco_check_send_pkts (UINT16 sco_inx)
BT_HDR *p_buf; BT_HDR *p_buf;
while (p_cb->xmit_window_size != 0) 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; break;
} }
#if BTM_SCO_HCI_DEBUG #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; p_buf->len += HCI_SCO_PREAMBLE_SIZE;
if (fixed_queue_length(p_ccb->xmit_data_q) < BTM_SCO_XMIT_QUEUE_THRS) { 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); btm_sco_check_send_pkts (sco_inx);
} else { } else {
BTM_TRACE_WARNING ("SCO xmit Q overflow, pkt dropped"); BTM_TRACE_WARNING ("SCO xmit Q overflow, pkt dropped");

View File

@ -35,6 +35,7 @@
#include "l2c_int.h" #include "l2c_int.h"
#include "osi/fixed_queue.h" #include "osi/fixed_queue.h"
#include "osi/alarm.h" #include "osi/alarm.h"
#include "stack/btm_ble_api.h"
#if (BT_USE_TRACES == TRUE && BT_TRACE_VERBOSE == FALSE) #if (BT_USE_TRACES == TRUE && BT_TRACE_VERBOSE == FALSE)
/* needed for sprintf() */ /* needed for sprintf() */
@ -368,6 +369,7 @@ BOOLEAN BTM_GetSecurityFlagsByTransport (BD_ADDR bd_addr, UINT8 *p_sec_flags,
return (FALSE); return (FALSE);
} }
#if (CLASSIC_BT_INCLUDED == TRUE)
/******************************************************************************* /*******************************************************************************
** **
** Function BTM_SetPinType ** 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; btm_cb.cfg.pin_code_len = pin_code_len;
memcpy (btm_cb.cfg.pin_code, pin_code, 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 (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[]) 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; 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 #endif
btsnd_hcic_pin_code_req_reply (bd_addr, pin_len, p_pin); btsnd_hcic_pin_code_req_reply (bd_addr, pin_len, p_pin);
} }
#endif ///CLASSIC_BT_INCLUDED == TRUE
#endif ///SMP_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); return (BTM_NO_RESOURCES);
} }
#if (CLASSIC_BT_INCLUDED == TRUE)
/* Save the PIN code if we got a valid one */ /* Save the PIN code if we got a valid one */
if (p_pin && (pin_len <= PIN_CODE_LEN) && (pin_len != 0)) { if (p_pin && (pin_len <= PIN_CODE_LEN) && (pin_len != 0)) {
btm_cb.pin_code_len = pin_len; btm_cb.pin_code_len = pin_len;
p_dev_rec->pin_code_length = pin_len; p_dev_rec->pin_code_length = pin_len;
memcpy (btm_cb.pin_code, p_pin, PIN_CODE_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); 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); 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()) { if (!controller_get_interface()->supports_simple_pairing()) {
/* The special case when we authenticate keyboard. Set pin type to fixed */ /* 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 */ /* 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); btsnd_hcic_write_pin_type (HCI_PIN_TYPE_FIXED);
} }
} }
#endif ///CLASSIC_BT_INCLUDED == TRUE
for (ii = 0; ii <= HCI_EXT_FEATURES_PAGE_MAX; ii++) { for (ii = 0; ii <= HCI_EXT_FEATURES_PAGE_MAX; ii++) {
#if (!CONFIG_BT_STACK_NO_LOG) #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, tBTM_STATUS BTM_SecBondByTransport (BD_ADDR bd_addr, tBT_TRANSPORT transport,
UINT8 pin_len, UINT8 *p_pin, UINT32 trusted_mask[]) UINT8 pin_len, UINT8 *p_pin, UINT32 trusted_mask[])
{ {
#if (BLE_INCLUDED == TRUE)
tBT_DEVICE_TYPE dev_type; tBT_DEVICE_TYPE dev_type;
tBLE_ADDR_TYPE addr_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)) { (transport == BT_TRANSPORT_BR_EDR && (dev_type & BT_DEVICE_TYPE_BREDR) == 0)) {
return BTM_ILLEGAL_ACTION; return BTM_ILLEGAL_ACTION;
} }
#endif ///BLE_INCLUDED == TRUE
return btm_sec_bond_by_transport(bd_addr, transport, pin_len, p_pin, trusted_mask); return btm_sec_bond_by_transport(bd_addr, transport, pin_len, p_pin, trusted_mask);
} }
#endif ///SMP_INCLUDED == TRUE #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[]) tBTM_STATUS BTM_SecBond (BD_ADDR bd_addr, UINT8 pin_len, UINT8 *p_pin, UINT32 trusted_mask[])
{ {
tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR;
#if (BLE_INCLUDED == TRUE)
if (BTM_UseLeLink(bd_addr)) { if (BTM_UseLeLink(bd_addr)) {
transport = BT_TRANSPORT_LE; transport = BT_TRANSPORT_LE;
} }
#endif ///BLE_INCLUDED == TRUE
return btm_sec_bond_by_transport(bd_addr, transport, pin_len, p_pin, trusted_mask); 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; 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 ** 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 #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 ** Function BTM_SetOutService
@ -1913,7 +1929,6 @@ UINT8 *BTM_ReadOobData(UINT8 *p_data, UINT8 eir_tag, UINT8 *p_len)
** Returns void ** Returns void
** **
*******************************************************************************/ *******************************************************************************/
#if (CLASSIC_BT_INCLUDED == TRUE)
void BTM_SetOutService(BD_ADDR bd_addr, UINT8 service_id, UINT32 mx_chan_id) void BTM_SetOutService(BD_ADDR bd_addr, UINT8 service_id, UINT32 mx_chan_id)
{ {
tBTM_SEC_DEV_REC *p_dev_rec; 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); 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 */ /* 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 (btm_bda_to_acl(p_e->bd_addr, p_e->transport) != NULL) {
if (p_e->psm != 0) { 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) { if (p_dev_rec->no_smp_on_br) {
BTM_TRACE_DEBUG ("%s NO SM over BR/EDR\n", __func__); BTM_TRACE_DEBUG ("%s NO SM over BR/EDR\n", __func__);
} else { } else {
#if (CLASSIC_BT_INCLUDED == TRUE)
BTM_TRACE_DEBUG ("%s start SM over BR/EDR\n", __func__); BTM_TRACE_DEBUG ("%s start SM over BR/EDR\n", __func__);
SMP_BR_PairWith(p_dev_rec->bd_addr); SMP_BR_PairWith(p_dev_rec->bd_addr);
#endif ///CLASSIC_BT_INCLUDED == TRUE
} }
} }
} else { } 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 ** Function btm_sec_pin_code_request
@ -5061,6 +5079,7 @@ void btm_sec_pin_code_request (UINT8 *p_bda)
} }
return; return;
} }
#endif ///CLASSIC_BT_INCLUDED == TRUE
#endif ///SMP_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)); 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) { if (btm_cb.pin_type_changed) {
btm_cb.pin_type_changed = FALSE; btm_cb.pin_type_changed = FALSE;
btsnd_hcic_write_pin_type (btm_cb.cfg.pin_type); btsnd_hcic_write_pin_type (btm_cb.cfg.pin_type);
} }
#endif ///CLASSIC_BT_INCLUDED == TRUE
} }
#endif ///SMP_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); btu_stop_timer (&btm_cb.pairing_tle);
btm_cb.pairing_flags = 0; btm_cb.pairing_flags = 0;
#if (CLASSIC_BT_INCLUDED == TRUE)
btm_cb.pin_code_len = 0; btm_cb.pin_code_len = 0;
#endif ///CLASSIC_BT_INCLUDED == TRUE
/* Make sure the the lcb shows we are not bonding */ /* Make sure the the lcb shows we are not bonding */
l2cu_update_lcb_4_bonding (btm_cb.pairing_bda, FALSE); 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", 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); __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); 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) 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 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); 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) if ((major == BTM_COD_MAJOR_AUDIO)
&& ((minor == BTM_COD_MINOR_CONFM_HANDSFREE) || (minor == BTM_COD_MINOR_CAR_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; rv = TRUE;
} }
#endif ///CLASSIC_BT_INCLUDED == TRUE
#
return rv; 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); *(UINT8 *)p_e->p_ref_data = *(UINT8 *)(p_ref_data);
p_e->transport = transport; p_e->transport = transport;
memcpy(p_e->bd_addr, bd_addr, BD_ADDR_LEN); 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; 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; return cur_security | sec_level4_flags;
} }
#endif ///SMP_INCLUDED == TRUE #endif ///SMP_INCLUDED == TRUE
/******************************************************************************* /*******************************************************************************
** **
** Function btm_sec_clear_ble_keys ** 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 ** Returns void
** **
*******************************************************************************/ *******************************************************************************/
#if (BLE_INCLUDED == TRUE)
void btm_sec_clear_ble_keys (tBTM_SEC_DEV_REC *p_dev_rec) 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 #endif
} }
#endif ///BLE_INCLUDED == TRUE
/******************************************************************************* /*******************************************************************************
** **
** Function btm_sec_is_a_bonded_dev ** 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; BOOLEAN is_bonded = FALSE;
if (p_dev_rec && 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)) || ((p_dev_rec->ble.key_type && (p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_KNOWN)) ||
#else #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) 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; BOOLEAN le_capable = FALSE;
#if (BLE_INCLUDED== TRUE) #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) { if (p_dev_rec && (p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) == BT_DEVICE_TYPE_BLE) {
le_capable = TRUE; le_capable = TRUE;
} }
@ -6077,6 +6105,7 @@ BOOLEAN btm_sec_is_le_capable_dev (BD_ADDR bda)
** Returns TRUE - found a bonded device ** 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 btm_sec_find_bonded_dev (UINT8 start_idx, UINT8 *p_found_idx, tBTM_SEC_DEV_REC **p_rec)
{ {
BOOLEAN found = FALSE; BOOLEAN found = FALSE;
@ -6101,7 +6130,7 @@ BOOLEAN btm_sec_find_bonded_dev (UINT8 start_idx, UINT8 *p_found_idx, tBTM_SEC_D
#endif #endif
return (found); return (found);
} }
#endif ///BLE_INCLUDED == TRUE
/******************************************************************************* /*******************************************************************************
** **
** Function btm_sec_use_smp_br_chnl ** Function btm_sec_use_smp_br_chnl

View File

@ -32,13 +32,14 @@
#include "stack/rfcdefs.h" #include "stack/rfcdefs.h"
#include "stack/btm_api.h" #include "stack/btm_api.h"
#include "osi/fixed_queue.h"
#if (BLE_INCLUDED == TRUE) #if (BLE_INCLUDED == TRUE)
#include "btm_ble_int.h" #include "btm_ble_int.h"
#endif
#if (SMP_INCLUDED == TRUE) #if (SMP_INCLUDED == TRUE)
#include "stack/smp_api.h" #include "stack/smp_api.h"
#endif #endif
#endif
#if BTM_MAX_LOC_BD_NAME_LEN > 0 #if BTM_MAX_LOC_BD_NAME_LEN > 0
typedef char tBTM_LOC_BD_NAME[BTM_MAX_LOC_BD_NAME_LEN + 1]; typedef char tBTM_LOC_BD_NAME[BTM_MAX_LOC_BD_NAME_LEN + 1];
@ -855,9 +856,12 @@ typedef struct {
BOOLEAN pairing_disabled; BOOLEAN pairing_disabled;
BOOLEAN connect_only_paired; BOOLEAN connect_only_paired;
BOOLEAN security_mode_changed; /* mode changed during bonding */ 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 */ 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 (SMP_INCLUDED == TRUE)
#if (CLASSIC_BT_INCLUDED == TRUE)
// btla-specific ++ // btla-specific ++
#ifdef PORCHE_PAIRING_CONFLICT #ifdef PORCHE_PAIRING_CONFLICT
UINT8 pin_code_len_saved; /* for legacy devices */ UINT8 pin_code_len_saved; /* for legacy devices */
@ -866,12 +870,14 @@ typedef struct {
UINT8 pin_code_len; /* for legacy devices */ UINT8 pin_code_len; /* for legacy devices */
PIN_CODE pin_code; /* 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 */ tBTM_PAIRING_STATE pairing_state; /* The current pairing state */
UINT8 pairing_flags; /* The current pairing flags */ UINT8 pairing_flags; /* The current pairing flags */
BD_ADDR pairing_bda; /* The device currently pairing */ BD_ADDR pairing_bda; /* The device currently pairing */
TIMER_LIST_ENT pairing_tle; /* Timer for pairing process */ 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 #endif ///SMP_INCLUDED == TRUE
#if SMP_INCLUDED == TRUE || CLASSIC_BT_INCLUDED == TRUE #if SMP_INCLUDED == TRUE || CLASSIC_BT_INCLUDED == TRUE
tBTM_SEC_SERV_REC sec_serv_rec[BTM_SEC_MAX_SERVICE_RECORDS]; 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); 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, 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); 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 */ #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); tINQ_DB_ENT *btm_inq_db_new (BD_ADDR p_bda);
#if BTM_OOB_INCLUDED == TRUE #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); UINT8 btm_sec_clr_service_by_psm (UINT16 psm);
void btm_sec_clr_temp_auth_service (BD_ADDR bda); 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 #ifdef __cplusplus

View File

@ -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; 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; 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) #if (SMP_INCLUDED == TRUE)
static void btu_hcif_pin_code_request_evt (UINT8 *p) static void btu_hcif_pin_code_request_evt (UINT8 *p)
{ {
#if (CLASSIC_BT_INCLUDED == TRUE)
BD_ADDR bda; BD_ADDR bda;
STREAM_TO_BDADDR (bda, p); STREAM_TO_BDADDR (bda, p);
@ -1445,6 +1446,7 @@ static void btu_hcif_pin_code_request_evt (UINT8 *p)
l2c_pin_code_request (bda); l2c_pin_code_request (bda);
btm_sec_pin_code_request (bda); btm_sec_pin_code_request (bda);
#endif ///CLASSIC_BT_INCLUDED == TRUE
} }

View File

@ -44,6 +44,11 @@
#endif #endif
#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; hash_map_t *btu_general_alarm_hash_map;
osi_mutex_t btu_general_alarm_lock; osi_mutex_t btu_general_alarm_lock;
static const size_t BTU_GENERAL_ALARM_HASH_MAP_SIZE = 34; 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; osi_mutex_t btu_l2cap_alarm_lock;
static const size_t BTU_L2CAP_ALARM_HASH_MAP_SIZE = 34; static const size_t BTU_L2CAP_ALARM_HASH_MAP_SIZE = 34;
//thread_t *bt_workqueue_thread; osi_thread_t *btu_thread = NULL;
//static const char *BT_WORKQUEUE_NAME = "bt_workqueue";
xTaskHandle xBtuTaskHandle = NULL;
xQueueHandle xBtuQueue = 0;
extern void PLATFORM_DisableHciTransport(UINT8 bDisable); extern void PLATFORM_DisableHciTransport(UINT8 bDisable);
extern void btu_task_thread_handler(void *arg); 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); void btu_task_shut_down(void);
/***************************************************************************** /*****************************************************************************
** V A R I A B L E S * ** V A R I A B L E S *
******************************************************************************/ ******************************************************************************/
@ -178,10 +181,14 @@ void BTU_StartUp(void)
osi_mutex_new(&btu_l2cap_alarm_lock); osi_mutex_new(&btu_l2cap_alarm_lock);
xBtuQueue = xQueueCreate(BTU_QUEUE_LEN, sizeof(BtTaskEvt_t)); btu_thread = osi_thread_create(BTU_TASK_NAME, BTU_TASK_STACK_SIZE, BTU_TASK_PRIO, BTU_TASK_PINNED_TO_CORE, 1);
xTaskCreatePinnedToCore(btu_task_thread_handler, BTU_TASK_NAME, BTU_TASK_STACK_SIZE, NULL, BTU_TASK_PRIO, &xBtuTaskHandle, BTU_TASK_PINNED_TO_CORE); 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; return;
@ -190,6 +197,15 @@ error_exit:;
BTU_ShutDown(); BTU_ShutDown();
} }
/*****************************************************************************
**
** Function BTU_ShutDown
**
** Description Deinitializes the BTU control block.
**
** Returns void
**
******************************************************************************/
void BTU_ShutDown(void) void BTU_ShutDown(void)
{ {
#if BTU_DYNAMIC_MEMORY #if BTU_DYNAMIC_MEMORY
@ -206,17 +222,14 @@ void BTU_ShutDown(void)
hash_map_free(btu_l2cap_alarm_hash_map); hash_map_free(btu_l2cap_alarm_hash_map);
osi_mutex_free(&btu_l2cap_alarm_lock); osi_mutex_free(&btu_l2cap_alarm_lock);
vTaskDelete(xBtuTaskHandle); if (btu_thread) {
vQueueDelete(xBtuQueue); osi_thread_free(btu_thread);
btu_thread = NULL;
}
btu_general_alarm_hash_map = NULL; btu_general_alarm_hash_map = NULL;
btu_oneshot_alarm_hash_map = NULL; btu_oneshot_alarm_hash_map = NULL;
btu_l2cap_alarm_hash_map = NULL; btu_l2cap_alarm_hash_map = NULL;
xBtuTaskHandle = NULL;
xBtuQueue = 0;
} }
/***************************************************************************** /*****************************************************************************
@ -236,13 +249,14 @@ UINT16 BTU_BleAclPktSize(void)
return 0; return 0;
#endif #endif
} }
#if SCAN_QUEUE_CONGEST_CHECK #if SCAN_QUEUE_CONGEST_CHECK
bool BTU_check_queue_is_congest(void) bool BTU_check_queue_is_congest(void)
{ {
UBaseType_t wait_size = uxQueueMessagesWaiting(xBtuQueue); if (osi_thread_queue_wait_size(btu_thread, 0) >= QUEUE_CONGEST_SIZE) {
if(wait_size >= QUEUE_CONGEST_SIZE ) {
return true; return true;
} }
return false; return false;
} }
#endif #endif

View File

@ -81,11 +81,16 @@ extern void avdt_rcv_sync_info (BT_HDR *p_buf);
#include "btm_ble_int.h" #include "btm_ble_int.h"
#endif #endif
typedef struct {
uint32_t sig;
void *param;
} btu_thread_evt_t;
//#if (defined(BT_APP_DEMO) && BT_APP_DEMO == TRUE) //#if (defined(BT_APP_DEMO) && BT_APP_DEMO == TRUE)
//#include "bt_app_common.h" //#include "bt_app_common.h"
//#endif //#endif
extern void BTE_InitStack(void); extern bt_status_t BTE_InitStack(void);
extern void BTE_DeinitStack(void); extern void BTE_DeinitStack(void);
/* Define BTU storage area /* 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 hash_map_t *btu_l2cap_alarm_hash_map;
extern osi_mutex_t btu_l2cap_alarm_lock; extern osi_mutex_t btu_l2cap_alarm_lock;
extern xTaskHandle xBtuTaskHandle; extern void *btu_thread;
extern xQueueHandle xBtuQueue;
extern bluedroid_init_done_cb_t bluedroid_init_done_cb; extern bluedroid_init_done_cb_t bluedroid_init_done_cb;
/* Define a function prototype to allow a generic timeout handler */ /* Define a function prototype to allow a generic timeout handler */
typedef void (tUSER_TIMEOUT_FUNC) (TIMER_LIST_ENT *p_tle); typedef void (tUSER_TIMEOUT_FUNC) (TIMER_LIST_ENT *p_tle);
static void btu_l2cap_alarm_process(TIMER_LIST_ENT *p_tle); static void btu_l2cap_alarm_process(void *param);
static void btu_general_alarm_process(TIMER_LIST_ENT *p_tle); static void btu_general_alarm_process(void *param);
static void btu_hci_msg_process(BT_HDR *p_msg); static void btu_hci_msg_process(void *param);
#if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE) #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 #endif
static void btu_hci_msg_process(BT_HDR *p_msg) static void btu_hci_msg_process(void *param)
{ {
/* Determine the input message type. */ /* Determine the input message type. */
BT_HDR *p_msg = (BT_HDR *)param;
switch (p_msg->event & BT_EVT_MASK) { switch (p_msg->event & BT_EVT_MASK) {
case BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK: // TODO(zachoverflow): remove this 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) #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 // call timer callback
if (p_tle->p_cback) { if (p_tle->p_cback) {
(*p_tle->p_cback)(p_tle); (*p_tle->p_cback)(p_tle);
@ -208,70 +216,42 @@ static void btu_bta_alarm_process(TIMER_LIST_ENT *p_tle)
} }
#endif #endif
/***************************************************************************** bool btu_task_post(uint32_t sig, void *param, uint32_t timeout)
**
** Function btu_task_thread_handler
**
** Description Process BTU Task Thread.
******************************************************************************/
void btu_task_thread_handler(void *arg)
{ {
BtTaskEvt_t e; bool status = false;
for (;;) { switch (sig) {
if (pdTRUE == xQueueReceive(xBtuQueue, &e, (portTickType)portMAX_DELAY)) { case SIG_BTU_START_UP:
status = osi_thread_post(btu_thread, btu_task_start_up, param, 0, timeout);
switch (e.sig) { break;
case SIG_BTU_START_UP: case SIG_BTU_HCI_MSG:
btu_task_start_up(); status = osi_thread_post(btu_thread, btu_hci_msg_process, param, 0, timeout);
break; break;
case SIG_BTU_HCI_MSG:
btu_hci_msg_process((BT_HDR *)e.par);
break;
#if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE) #if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE)
case SIG_BTU_BTA_MSG: case SIG_BTU_BTA_MSG:
bta_sys_event((BT_HDR *)e.par); status = osi_thread_post(btu_thread, bta_sys_event, param, 0, timeout);
break; break;
case SIG_BTU_BTA_ALARM: case SIG_BTU_BTA_ALARM:
btu_bta_alarm_process((TIMER_LIST_ENT *)e.par); status = osi_thread_post(btu_thread, btu_bta_alarm_process, param, 0, timeout);
break; break;
#endif #endif
case SIG_BTU_GENERAL_ALARM: case SIG_BTU_GENERAL_ALARM:
btu_general_alarm_process((TIMER_LIST_ENT *)e.par); case SIG_BTU_ONESHOT_ALARM:
break; status = osi_thread_post(btu_thread, btu_general_alarm_process, param, 0, timeout);
case SIG_BTU_ONESHOT_ALARM: { break;
TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)e.par; case SIG_BTU_L2CAP_ALARM:
btu_general_alarm_process(p_tle); status = osi_thread_post(btu_thread, btu_l2cap_alarm_process, param, 0, timeout);
break; break;
} default:
case SIG_BTU_L2CAP_ALARM: break;
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;
} }
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 /* Initialize the mandatory core stack control blocks
(BTU, BTM, L2CAP, and SDP) (BTU, BTM, L2CAP, and SDP)
*/ */
@ -314,8 +294,9 @@ void btu_task_shut_down(void)
** Returns 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); assert(p_tle != NULL);
switch (p_tle->event) { switch (p_tle->event) {
@ -426,7 +407,7 @@ void btu_general_alarm_cb(void *data)
assert(data != NULL); assert(data != NULL);
TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data; 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) 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 ** 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); assert(p_tle != NULL);
switch (p_tle->event) { switch (p_tle->event) {
@ -540,7 +522,7 @@ static void btu_l2cap_alarm_cb(void *data)
assert(data != NULL); assert(data != NULL);
TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data; 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) 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_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);
} }
/* /*

View File

@ -21,8 +21,13 @@
#include "common/bt_target.h" #include "common/bt_target.h"
//#include "bt_utils.h" //#include "bt_utils.h"
#include "gap_int.h" #include "gap_int.h"
#include "osi/allocator.h"
#if GAP_DYNAMIC_MEMORY == FALSE
tGAP_CB gap_cb; 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 ** This routine should not be called except once per
** stack invocation. ** 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)); memset (&gap_cb, 0, sizeof (tGAP_CB));
#if defined(GAP_INITIAL_TRACE_LEVEL) #if defined(GAP_INITIAL_TRACE_LEVEL)
@ -72,5 +84,26 @@ void GAP_Init(void)
#if BLE_INCLUDED == TRUE && GATTS_INCLUDED == TRUE #if BLE_INCLUDED == TRUE && GATTS_INCLUDED == TRUE
gap_attr_db_init(); gap_attr_db_init();
#endif #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
}

View File

@ -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); 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 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_connect_cback,
gap_ble_c_cmpl_cback, gap_ble_c_cmpl_cback,
NULL, NULL,
@ -145,7 +145,7 @@ void gap_ble_dealloc_clcb(tGAP_CLCB *p_clcb)
{ {
tGAP_BLE_REQ *p_q; 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*/ /* send callback to all pending requests if being removed*/
if (p_q->p_cback != NULL) { if (p_q->p_cback != NULL) {
(*p_q->p_cback)(FALSE, p_clcb->bda, 0, 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) { if (p_q != NULL) {
p_q->p_cback = p_cback; p_q->p_cback = p_cback;
p_q->uuid = uuid; 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; 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) 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) { if (p_q != NULL) {
*p_cback = p_q->p_cback; *p_cback = p_q->p_cback;

Some files were not shown because too many files have changed in this diff Show More