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/osi.c"
"bluedroid/osi/semaphore.c"
"bluedroid/osi/thread.c"
"bluedroid/stack/a2dp/a2d_api.c"
"bluedroid/stack/a2dp/a2d_sbc.c"
"bluedroid/stack/avct/avct_api.c"

View File

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

View File

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

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

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);
/**
* @brief Deinitialize the down sampling converter.
*/
void esp_hf_client_pcm_resample_deinit(void);
/**
* @brief Down sampling utility to convert high sampling rate into 8K/16bits 1-channel mode PCM
* samples. This can only be used in the case that Voice Over HCI is enabled.

View File

@ -31,24 +31,13 @@
#include "common/bt_defs.h"
#if defined(BTA_AV_INCLUDED) && (BTA_AV_INCLUDED == TRUE)
#include "bta_av_int.h"
typedef int (tBTA_AV_SBC_ACT)(void *p_src, void *p_dst,
UINT32 src_samples, UINT32 dst_samples,
UINT32 *p_ret);
typedef struct {
INT32 cur_pos; /* current position */
UINT32 src_sps; /* samples per second (source audio data) */
UINT32 dst_sps; /* samples per second (converted audio data) */
tBTA_AV_SBC_ACT *p_act; /* the action function to do the conversion */
UINT16 bits; /* number of bits per pcm sample */
UINT16 n_channels; /* number of channels (i.e. mono(1), stereo(2)...) */
INT16 worker1;
INT16 worker2;
UINT8 div;
} tBTA_AV_SBC_UPS_CB;
tBTA_AV_SBC_UPS_CB bta_av_sbc_ups_cb;
#if BTA_DYNAMIC_MEMORY == FALSE
static tBTA_AV_SBC_UPS_CB bta_av_sbc_ups_cb;
#else
tBTA_AV_SBC_UPS_CB *bta_av_sbc_ups_cb_ptr;
#endif
/*******************************************************************************
**

View File

@ -531,11 +531,32 @@ typedef struct {
UINT8 video_streams; /* handle mask of streaming video channels */
} tBTA_AV_CB;
/* type for dealing with SBC data frames and codec capabilities functions */
typedef int (tBTA_AV_SBC_ACT)(void *p_src, void *p_dst,
UINT32 src_samples, UINT32 dst_samples,
UINT32 *p_ret);
/* type for AV up sample control block */
typedef struct {
INT32 cur_pos; /* current position */
UINT32 src_sps; /* samples per second (source audio data) */
UINT32 dst_sps; /* samples per second (converted audio data) */
tBTA_AV_SBC_ACT *p_act; /* the action function to do the conversion */
UINT16 bits; /* number of bits per pcm sample */
UINT16 n_channels; /* number of channels (i.e. mono(1), stereo(2)...) */
INT16 worker1;
INT16 worker2;
UINT8 div;
} tBTA_AV_SBC_UPS_CB;
/*****************************************************************************
** Global data
*****************************************************************************/
/* control block declaration up sample */
#if BTA_DYNAMIC_MEMORY == TRUE
extern tBTA_AV_SBC_UPS_CB *bta_av_sbc_ups_cb_ptr;
#define bta_av_sbc_ups_cb (*bta_av_sbc_ups_cb_ptr)
#endif
/* control block declaration */
#if BTA_DYNAMIC_MEMORY == FALSE
@ -670,3 +691,4 @@ extern void bta_av_reg_vdp (tAVDT_CS *p_cs, char *p_service_name, void *p_data);
#endif ///BTA_AV_INCLUDED == TRUE
#endif /* BTA_AV_INT_H */

View File

@ -60,7 +60,9 @@ static void bta_dm_sdp_callback (UINT16 sdp_status);
#endif ///SDP_INCLUDED == TRUE
#if (SMP_INCLUDED == TRUE)
static UINT8 bta_dm_authorize_cback (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name, UINT8 *service_name, UINT8 service_id, BOOLEAN is_originator);
#if (CLASSIC_BT_INCLUDED == TRUE)
static UINT8 bta_dm_pin_cback (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name, BOOLEAN min_16_digit);
#endif /// CLASSIC_BT_INCLUDED == TRUE
static UINT8 bta_dm_new_link_key_cback(BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name, LINK_KEY key, UINT8 key_type);
static UINT8 bta_dm_authentication_complete_cback(BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name, int result);
#endif ///SMP_INCLUDED == TRUE
@ -125,9 +127,12 @@ static void bta_dm_ctrl_features_rd_cmpl_cback(tBTM_STATUS result);
#if (SMP_INCLUDED == TRUE)
static void bta_dm_remove_sec_dev_entry(BD_ADDR remote_bd_addr);
#endif ///SMP_INCLUDED == TRUE
#if (BLE_INCLUDED == TRUE)
static void bta_dm_observe_results_cb(tBTM_INQ_RESULTS *p_inq, UINT8 *p_eir);
static void bta_dm_observe_cmpl_cb(void *p_result);
static void bta_dm_observe_discard_cb (uint32_t num_dis);
#endif ///BLE_INCLUDED == TRUE
static void bta_dm_delay_role_switch_cback(TIMER_LIST_ENT *p_tle);
extern void sdpu_uuid16_to_uuid128(UINT16 uuid16, UINT8 *p_uuid128);
static void bta_dm_disable_timer_cback(TIMER_LIST_ENT *p_tle);
@ -215,7 +220,11 @@ const UINT32 bta_service_id_to_btm_srv_id_lkup_tbl [BTA_MAX_SERVICE_ID] = {
#if (SMP_INCLUDED == TRUE)
const tBTM_APPL_INFO bta_security = {
&bta_dm_authorize_cback,
#if (CLASSIC_BT_INCLUDED == TRUE)
&bta_dm_pin_cback,
#else
NULL,
#endif
&bta_dm_new_link_key_cback,
&bta_dm_authentication_complete_cback,
&bta_dm_bond_cancel_complete_cback,
@ -233,10 +242,12 @@ const tBTM_APPL_INFO bta_security = {
#endif ///SMP_INCLUDED == TRUE
#if (SDP_INCLUDED == TRUE)
#define MAX_DISC_RAW_DATA_BUF (1024)
#if BTA_DYNAMIC_MEMORY == FALSE
UINT8 g_disc_raw_data_buf[MAX_DISC_RAW_DATA_BUF];
#else
UINT8 *g_disc_raw_data_buf;
#endif
#endif ///SDP_INCLUDED == TRUE
extern DEV_CLASS local_device_default_class;
/*******************************************************************************
**
@ -579,7 +590,7 @@ void bta_dm_disable (tBTA_DM_MSG *p_data)
bta_sys_start_timer(&bta_dm_cb.disable_timer, 0, 5000);
}
#if BLE_PRIVACY_SPT == TRUE
#if BLE_INCLUDED == TRUE && BLE_PRIVACY_SPT == TRUE
btm_ble_resolving_list_cleanup (); //by TH, because cmn_ble_vsc_cb.max_filter has something mistake as btm_ble_adv_filter_cleanup
#endif
@ -696,25 +707,31 @@ void bta_dm_config_eir (tBTA_DM_MSG *p_data)
void bta_dm_update_white_list(tBTA_DM_MSG *p_data)
{
#if (BLE_INCLUDED == TRUE)
BTM_BleUpdateAdvWhitelist(p_data->white_list.add_remove, p_data->white_list.remote_addr, p_data->white_list.addr_type, p_data->white_list.add_wl_cb);
#endif ///BLE_INCLUDED == TRUE
}
void bta_dm_ble_read_adv_tx_power(tBTA_DM_MSG *p_data)
{
#if (BLE_INCLUDED == TRUE)
if (p_data->read_tx_power.read_tx_power_cb != NULL) {
BTM_BleReadAdvTxPower(p_data->read_tx_power.read_tx_power_cb);
} else {
APPL_TRACE_ERROR("%s(), the callback function can't be NULL.", __func__);
}
#endif ///BLE_INCLUDED == TRUE
}
void bta_dm_ble_read_rssi(tBTA_DM_MSG *p_data)
{
#if (BLE_INCLUDED == TRUE)
if (p_data->rssi.read_rssi_cb != NULL) {
BTM_ReadRSSI(p_data->rssi.remote_addr, p_data->rssi.transport, p_data->rssi.read_rssi_cb);
} else {
APPL_TRACE_ERROR("%s(), the callback function can't be NULL.", __func__);
}
#endif ///BLE_INCLUDED == TRUE
}
/*******************************************************************************
@ -730,42 +747,52 @@ void bta_dm_ble_read_rssi(tBTA_DM_MSG *p_data)
void bta_dm_set_visibility(tBTA_DM_MSG *p_data)
{
UINT16 window, interval;
UINT16 le_disc_mode = BTM_BleReadDiscoverability();
UINT16 disc_mode = BTM_ReadDiscoverability(&window, &interval);
UINT16 le_conn_mode = BTM_BleReadConnectability();
UINT16 conn_mode = BTM_ReadConnectability(&window, &interval);
#if (BLE_INCLUDED == TRUE)
UINT16 le_disc_mode = BTM_BleReadDiscoverability();
UINT16 le_conn_mode = BTM_BleReadConnectability();
#endif ///BLE_INCLUDED == TRUE
/* set modes for Discoverability and connectability if not ignore */
if (p_data->set_visibility.disc_mode != (BTA_DM_IGNORE | BTA_DM_LE_IGNORE)) {
#if (BLE_INCLUDED == TRUE)
if ((p_data->set_visibility.disc_mode & BTA_DM_LE_IGNORE) == BTA_DM_LE_IGNORE) {
p_data->set_visibility.disc_mode =
((p_data->set_visibility.disc_mode & ~BTA_DM_LE_IGNORE) | le_disc_mode);
}
#endif ///BLE_INCLUDED == TRUE
if ((p_data->set_visibility.disc_mode & BTA_DM_IGNORE) == BTA_DM_IGNORE) {
p_data->set_visibility.disc_mode =
((p_data->set_visibility.disc_mode & ~BTA_DM_IGNORE) | disc_mode);
}
#if (CLASSIC_BT_INCLUDED == TRUE)
BTM_SetDiscoverability(p_data->set_visibility.disc_mode,
bta_dm_cb.inquiry_scan_window,
bta_dm_cb.inquiry_scan_interval);
#endif
}
if (p_data->set_visibility.conn_mode != (BTA_DM_IGNORE | BTA_DM_LE_IGNORE)) {
#if (BLE_INCLUDED == TRUE)
if ((p_data->set_visibility.conn_mode & BTA_DM_LE_IGNORE) == BTA_DM_LE_IGNORE) {
p_data->set_visibility.conn_mode =
((p_data->set_visibility.conn_mode & ~BTA_DM_LE_IGNORE) | le_conn_mode);
}
#endif ///BLE_INCLUDED == TRUE
if ((p_data->set_visibility.conn_mode & BTA_DM_IGNORE) == BTA_DM_IGNORE) {
p_data->set_visibility.conn_mode =
((p_data->set_visibility.conn_mode & ~BTA_DM_IGNORE) | conn_mode);
}
#if (CLASSIC_BT_INCLUDED == TRUE)
BTM_SetConnectability(p_data->set_visibility.conn_mode,
bta_dm_cb.page_scan_window,
bta_dm_cb.page_scan_interval);
#endif
}
/* Send False or True if not ignore */
@ -1094,7 +1121,9 @@ void bta_dm_bond_cancel (tBTA_DM_MSG *p_data)
*******************************************************************************/
void bta_dm_set_pin_type (tBTA_DM_MSG *p_data)
{
#if (CLASSIC_BT_INCLUDED == TRUE)
BTM_SetPinType (p_data->set_pin_type.pin_type, p_data->set_pin_type.p_pin, p_data->set_pin_type.pin_len);
#endif ///CLASSIC_BT_INCLUDED == TRUE
}
/*******************************************************************************
@ -1109,6 +1138,7 @@ void bta_dm_set_pin_type (tBTA_DM_MSG *p_data)
*******************************************************************************/
void bta_dm_pin_reply (tBTA_DM_MSG *p_data)
{
#if (CLASSIC_BT_INCLUDED == TRUE)
UINT32 trusted_mask[BTM_SEC_SERVICE_ARRAY_SIZE];
UINT32 *current_trusted_mask;
@ -1126,7 +1156,7 @@ void bta_dm_pin_reply (tBTA_DM_MSG *p_data)
} else {
BTM_PINCodeReply(p_data->pin_reply.bd_addr, BTM_NOT_AUTHORIZED, 0, NULL, trusted_mask );
}
#endif ///CLASSIC_BT_INCLUDED == TRUE
}
#endif ///SMP_INCLUDED == TRUE
@ -1268,7 +1298,9 @@ void bta_dm_loc_oob(tBTA_DM_MSG *p_data)
*******************************************************************************/
void bta_dm_oob_reply(tBTA_DM_MSG *p_data)
{
#if (BLE_INCLUDED)
BTM_BleOobDataReply(p_data->oob_reply.bd_addr, BTM_SUCCESS, p_data->oob_reply.len, p_data->oob_reply.value);
#endif
}
/*******************************************************************************
@ -2303,7 +2335,7 @@ static void bta_dm_find_services ( BD_ADDR bd_addr)
APPL_TRACE_DEBUG("%s search UUID = %04x", __func__, uuid.uu.uuid16);
SDP_InitDiscoveryDb (bta_dm_search_cb.p_sdp_db, BTA_DM_SDP_DB_SIZE, 1, &uuid, 0, NULL);
memset(g_disc_raw_data_buf, 0, sizeof(g_disc_raw_data_buf));
memset(g_disc_raw_data_buf, 0, MAX_DISC_RAW_DATA_BUF);
bta_dm_search_cb.p_sdp_db->raw_data = g_disc_raw_data_buf;
bta_dm_search_cb.p_sdp_db->raw_size = MAX_DISC_RAW_DATA_BUF;
@ -2496,7 +2528,7 @@ static void bta_dm_discover_device(BD_ADDR remote_bd_addr)
if (transport == BT_TRANSPORT_LE) {
if (bta_dm_search_cb.services_to_search & BTA_BLE_SERVICE_MASK) {
//set the raw data buffer here
memset(g_disc_raw_data_buf, 0, sizeof(g_disc_raw_data_buf));
memset(g_disc_raw_data_buf, 0, MAX_DISC_RAW_DATA_BUF);
bta_dm_search_cb.p_ble_rawdata = g_disc_raw_data_buf;
bta_dm_search_cb.ble_raw_size = MAX_DISC_RAW_DATA_BUF;
@ -2790,6 +2822,8 @@ static UINT8 bta_dm_authorize_cback (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NA
}
}
#if (CLASSIC_BT_INCLUDED == TRUE)
#if (BT_SSP_INCLUDED == TRUE)
/*******************************************************************************
**
@ -2876,6 +2910,7 @@ static UINT8 bta_dm_pin_cback (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_
bta_dm_cb.p_sec_cback(BTA_DM_PIN_REQ_EVT, &sec_event);
return BTM_CMD_STARTED;
}
#endif ///CLASSIC_BT_INCLUDED == TRUE
/*******************************************************************************
**
@ -5795,6 +5830,7 @@ static void bta_dm_gattc_register(void)
}
}
#endif /* GATTC_INCLUDED == TRUE */
/*******************************************************************************
**
** Function btm_dm_start_disc_gatt_services
@ -5804,6 +5840,7 @@ static void bta_dm_gattc_register(void)
** Parameters:
**
*******************************************************************************/
#if (GATTC_INCLUDED == TRUE)
static void btm_dm_start_disc_gatt_services (UINT16 conn_id)
{
tBT_UUID *p_uuid = bta_dm_search_cb.p_srvc_uuid +
@ -5815,6 +5852,7 @@ static void btm_dm_start_disc_gatt_services (UINT16 conn_id)
/* always search for all services */
BTA_GATTC_ServiceSearchRequest(conn_id, p_uuid);
}
#endif /* GATTC_INCLUDED == TRUE */
/*******************************************************************************
**
@ -5875,6 +5913,7 @@ static void bta_dm_gatt_disc_result(tBTA_GATT_ID service_id)
** Parameters:
**
*******************************************************************************/
#if (GATTC_INCLUDED == TRUE)
static void bta_dm_gatt_disc_complete(UINT16 conn_id, tBTA_GATT_STATUS status)
{
tBTA_DM_MSG *p_msg;
@ -5932,6 +5971,7 @@ static void bta_dm_gatt_disc_complete(UINT16 conn_id, tBTA_GATT_STATUS status)
bta_dm_search_cb.gatt_disc_active = FALSE;
}
}
#endif /* #if (GATTC_INCLUDED == TRUE) */
/*******************************************************************************
**
@ -6001,6 +6041,7 @@ static void bta_dm_cancel_gatt_discovery(BD_ADDR bd_addr)
bta_dm_gatt_disc_complete(bta_dm_search_cb.conn_id, (tBTA_GATT_STATUS) BTA_GATT_ERROR);
}
#endif /* #if (GATTC_INCLUDED == TRUE) */
/*******************************************************************************
**
** Function bta_dm_proc_open_evt
@ -6010,6 +6051,7 @@ static void bta_dm_cancel_gatt_discovery(BD_ADDR bd_addr)
** Parameters:
**
*******************************************************************************/
#if (GATTC_INCLUDED == TRUE)
void bta_dm_proc_open_evt(tBTA_GATTC_OPEN *p_data)
{
UINT8 *p1;
@ -6040,6 +6082,7 @@ void bta_dm_proc_open_evt(tBTA_GATTC_OPEN *p_data)
bta_dm_gatt_disc_complete(BTA_GATT_INVALID_CONN_ID, p_data->status);
}
}
#endif /* #if (GATTC_INCLUDED == TRUE) */
/*******************************************************************************
**

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)
{
tBTA_DM_API_UPDATE_WHITE_LIST *p_msg;
@ -248,6 +249,7 @@ void BTA_DmBleReadAdvTxPower(tBTA_CMPL_CB *cmpl_cb)
bta_sys_sendmsg(p_msg);
}
}
#endif ///BLE_INCLUDED == TRUE
void BTA_DmBleReadRSSI(BD_ADDR remote_addr, tBTA_TRANSPORT transport, tBTA_CMPL_CB *cmpl_cb)
{
@ -475,10 +477,10 @@ void BTA_DmBondCancel(BD_ADDR bd_addr)
bdcpy(p_msg->bd_addr, bd_addr);
bta_sys_sendmsg(p_msg);
}
}
#endif ///SMP_INCLUDED == TRUE
#if (CLASSIC_BT_INCLUDED == TRUE)
/*******************************************************************************
**
** Function BTA_DMSetPinType
@ -529,6 +531,7 @@ void BTA_DmPinReply(BD_ADDR bd_addr, BOOLEAN accept, UINT8 pin_len, UINT8 *p_pin
}
}
#endif ///CLASSIC_BT_INCLUDED == TRUE
#if (BTM_OOB_INCLUDED == TRUE && SMP_INCLUDED == TRUE)
/*******************************************************************************
@ -594,6 +597,7 @@ void BTA_DmOobReply(BD_ADDR bd_addr, UINT8 len, UINT8 *p_value)
** Returns void
**
*******************************************************************************/
#if (SMP_INCLUDED == TRUE)
void BTA_DmConfirm(BD_ADDR bd_addr, BOOLEAN accept)
{
tBTA_DM_API_CONFIRM *p_msg;
@ -629,6 +633,7 @@ void BTA_DmPasskeyReqReply(BOOLEAN accept, BD_ADDR bd_addr, UINT32 passkey)
}
}
#endif ///BT_SSP_INCLUDED == TRUE
#endif ///SMP_INCLUDED == TRUE
/*******************************************************************************
**
** Function BTA_DmAddDevice
@ -705,7 +710,7 @@ tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr, tBT_TRANSPORT transport)
return BTA_SUCCESS;
}
#endif ///SMP_INCLUDED == TRUE
// #endif ///SMP_INCLUDED == TRUE
/*******************************************************************************
**
@ -989,7 +994,6 @@ void BTA_DmBleSecurityGrant(BD_ADDR bd_addr, tBTA_DM_BLE_SEC_GRANT res)
}
}
#endif ///SMP_INCLUDED == TRUE
#endif ///BLE_INCLUDED == TRUE
/*******************************************************************************
@ -1207,7 +1211,7 @@ void BTA_DmSetBleAdvParamsAll (UINT16 adv_int_min, UINT16 adv_int_max,
}
#endif
}
#endif ///BLE_INCLUDED == TRUE
/*******************************************************************************
@ -1796,6 +1800,8 @@ void BTA_DmBleUpdateConnectionParam(BD_ADDR bd_addr, UINT16 min_int,
}
#endif
}
#if BLE_INCLUDED == TRUE
/*******************************************************************************
**
** Function BTA_DmBleConfigLocalPrivacy
@ -1826,7 +1832,6 @@ void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable, tBTA_SET_LOCAL_PRIVACY_
#endif
}
#if BLE_INCLUDED == TRUE
/*******************************************************************************
**
** Function BTA_DmBleConfigLocalIcon

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
# define BTA_DM_NUM_PM_ENTRY 8 /* number of entries in bta_dm_pm_cfg except the first */
@ -375,12 +375,12 @@ tBTA_DM_SSR_SPEC bta_dm_ssr_spec[] = {
{360, 160, 2} /* BTA_DM_PM_SSR3 - HD */
};
tBTA_DM_SSR_SPEC *p_bta_dm_ssr_spec = (tBTA_DM_SSR_SPEC *) &bta_dm_ssr_spec;
tBTA_DM_SSR_SPEC *const p_bta_dm_ssr_spec = (tBTA_DM_SSR_SPEC *) &bta_dm_ssr_spec;
#endif
tBTA_DM_PM_CFG *p_bta_dm_pm_cfg = (tBTA_DM_PM_CFG *) &bta_dm_pm_cfg;
tBTA_DM_PM_SPEC *p_bta_dm_pm_spec = (tBTA_DM_PM_SPEC *) &bta_dm_pm_spec;
tBTM_PM_PWR_MD *p_bta_dm_pm_md = (tBTM_PM_PWR_MD *) &bta_dm_pm_md;
tBTA_DM_PM_CFG *const p_bta_dm_pm_cfg = (tBTA_DM_PM_CFG *) &bta_dm_pm_cfg;
tBTA_DM_PM_SPEC *const p_bta_dm_pm_spec = (tBTA_DM_PM_SPEC *) &bta_dm_pm_spec;
tBTM_PM_PWR_MD *const p_bta_dm_pm_md = (tBTM_PM_PWR_MD *) &bta_dm_pm_md;
#endif /* #if (BTA_DM_PM_INCLUDED == TRUE) */

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_ble_read_adv_tx_power, /* BTA_DM_API_BLE_READ_ADV_TX_POWER_EVT */
bta_dm_ble_read_rssi, /* BTA_DM_API_BLE_READ_RSSI_EVT */
#if BLE_INCLUDED == TRUE
bta_dm_ble_update_duplicate_exceptional_list,/* BTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_EVT */
#endif
};

View File

@ -32,7 +32,11 @@
#include "stack/btm_api.h"
#include "osi/allocator.h"
#if BTA_DYNAMIC_MEMORY == FALSE
tBTA_DM_CONNECTED_SRVCS bta_dm_conn_srvcs;
#else
tBTA_DM_CONNECTED_SRVCS *bta_dm_conn_srvcs_ptr;
#endif
#if (BTA_DM_PM_INCLUDED == TRUE)
static void bta_dm_pm_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id, BD_ADDR peer_addr);

View File

@ -28,6 +28,7 @@
#include <string.h>
#include "bta/bta_api.h"
#include "bta/bta_sys.h"
#include "osi/allocator.h"
#if (BTM_SCO_HCI_INCLUDED == TRUE)
@ -67,7 +68,7 @@ typedef struct {
UINT32 divisor;
} tBTA_DM_PCM_RESAMPLE_CB;
tBTA_DM_PCM_RESAMPLE_CB bta_dm_pcm_cb;
static tBTA_DM_PCM_RESAMPLE_CB* p_bta_dm_pcm_cb;
/*****************************************************************************
** Macro Definition
@ -560,7 +561,11 @@ INT32 Convert_16S_ToBT_NoFilter (void *pSrc, void *pDst, UINT32 dwSrcSamples, UI
*******************************************************************************/
void BTA_DmPcmInitSamples (UINT32 src_sps, UINT32 bits, UINT32 n_channels)
{
tBTA_DM_PCM_RESAMPLE_CB *p_cb = &bta_dm_pcm_cb;
if ((p_bta_dm_pcm_cb = (tBTA_DM_PCM_RESAMPLE_CB *)osi_malloc(sizeof(tBTA_DM_PCM_RESAMPLE_CB))) == NULL) {
APPL_TRACE_ERROR("%s malloc failed!", __func__);
return;
}
tBTA_DM_PCM_RESAMPLE_CB *p_cb = p_bta_dm_pcm_cb;
p_cb->cur_pos = src_sps / 2;
p_cb->src_sps = src_sps;
@ -615,6 +620,20 @@ void BTA_DmPcmInitSamples (UINT32 src_sps, UINT32 bits, UINT32 n_channels)
}
/*******************************************************************************
**
** Function BTA_DmPcmDeinitSamples
**
** Description Deinitialize the down sample converter.
**
** Returns none
**
*******************************************************************************/
void BTA_DmPcmDeinitSamples(void) {
osi_free(p_bta_dm_pcm_cb);
p_bta_dm_pcm_cb = NULL;
}
/**************************************************************************************
** Function BTA_DmPcmResample
**
@ -636,14 +655,14 @@ INT32 BTA_DmPcmResample (void *p_src, UINT32 in_bytes, void *p_dst)
UINT32 out_sample;
#if BTA_DM_SCO_DEBUG
APPL_TRACE_DEBUG("bta_pcm_resample : insamples %d", (in_bytes / bta_dm_pcm_cb.divisor));
APPL_TRACE_DEBUG("bta_pcm_resample : insamples %d", (in_bytes / p_bta_dm_pcm_cb->divisor));
#endif
if (bta_dm_pcm_cb.can_be_filtered) {
out_sample = (*bta_dm_pcm_cb.filter) (p_src, p_dst, (in_bytes / bta_dm_pcm_cb.divisor),
bta_dm_pcm_cb.src_sps, (INT32 *) &bta_dm_pcm_cb.cur_pos, bta_dm_pcm_cb.overlap_area);
if (p_bta_dm_pcm_cb->can_be_filtered) {
out_sample = (*p_bta_dm_pcm_cb->filter) (p_src, p_dst, (in_bytes / p_bta_dm_pcm_cb->divisor),
p_bta_dm_pcm_cb->src_sps, (INT32 *) &(p_bta_dm_pcm_cb->cur_pos), p_bta_dm_pcm_cb->overlap_area);
} else {
out_sample = (*bta_dm_pcm_cb.nofilter) (p_src, p_dst,
(in_bytes / bta_dm_pcm_cb.divisor), bta_dm_pcm_cb.src_sps);
out_sample = (*p_bta_dm_pcm_cb->nofilter) (p_src, p_dst,
(in_bytes / p_bta_dm_pcm_cb->divisor), p_bta_dm_pcm_cb->src_sps);
}
#if BTA_DM_SCO_DEBUG

View File

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

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 tBTA_GATTC_FIND_SERVICE_CB bta_gattc_register_service_change_notify(UINT16 conn_id, BD_ADDR remote_bda);
static tGATT_CBACK bta_gattc_cl_cback = {
static const tGATT_CBACK bta_gattc_cl_cback = {
bta_gattc_conn_cback,
bta_gattc_cmpl_cback,
bta_gattc_disc_res_cback,
@ -79,7 +79,7 @@ static tGATT_CBACK bta_gattc_cl_cback = {
};
/* opcode(tGATTC_OPTYPE) order has to be comply with internal event order */
static UINT16 bta_gattc_opcode_to_int_evt[] = {
static const UINT16 bta_gattc_opcode_to_int_evt[] = {
BTA_GATTC_API_READ_EVT,
BTA_GATTC_API_WRITE_EVT,
BTA_GATTC_API_EXEC_EVT,

View File

@ -26,6 +26,7 @@
#include "common/bt_target.h"
#if defined(GATTC_INCLUDED) && (GATTC_INCLUDED == TRUE)
//#if( defined GATTC_CACHE_NVS ) && (GATTC_CACHE_NVS == TRUE)
#include <string.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);
//unlink(fname);
}
//#endif /* GATTC_CACHE_NVS */
#endif /* BTA_GATT_INCLUDED */

View File

@ -33,6 +33,7 @@
#if( defined BLE_INCLUDED ) && (BLE_INCLUDED == TRUE)
#if( defined BTA_GATT_INCLUDED ) && (GATTC_INCLUDED == TRUE)
// #if( defined GATTC_CACHE_NVS ) && (GATTC_CACHE_NVS == TRUE)
#define GATT_CACHE_PREFIX "gatt_"
#define INVALID_ADDR_NUM 0xff
@ -77,7 +78,6 @@ static void cacheReset(BD_ADDR bda)
static const char *cache_key = "gattc_cache_key";
static const char *cache_addr = "cache_addr_tab";
nvs_handle_t nvs_fp;
typedef struct {
//save the service data in the list according to the address
@ -96,7 +96,7 @@ typedef struct {
cache_addr_info_t cache_addr[MAX_DEVICE_IN_CACHE];
}cache_env_t;
cache_env_t cache_env;
static cache_env_t *cache_env = NULL;
static void getFilename(char *buffer, hash_key_t hash)
{
@ -108,9 +108,9 @@ static void cacheClose(BD_ADDR bda)
{
UINT8 index = 0;
if ((index = bta_gattc_co_find_addr_in_cache(bda)) != INVALID_ADDR_NUM) {
if (cache_env.cache_addr[index].is_open) {
nvs_close(cache_env.cache_addr[index].cache_fp);
cache_env.cache_addr[index].is_open = FALSE;
if (cache_env->cache_addr[index].is_open) {
nvs_close(cache_env->cache_addr[index].cache_fp);
cache_env->cache_addr[index].is_open = FALSE;
}
}
}
@ -124,14 +124,14 @@ static bool cacheOpen(BD_ADDR bda, bool to_save, UINT8 *index)
hash_key_t hash_key = {0};
if (((*index = bta_gattc_co_find_addr_in_cache(bda)) != INVALID_ADDR_NUM) ||
((assoc_addr = bta_gattc_co_cache_find_src_addr(bda, index)) != NULL)) {
if (cache_env.cache_addr[*index].is_open) {
if (cache_env->cache_addr[*index].is_open) {
return TRUE;
} else {
memcpy(hash_key, cache_env.cache_addr[*index].hash_key, sizeof(hash_key_t));
memcpy(hash_key, cache_env->cache_addr[*index].hash_key, sizeof(hash_key_t));
getFilename(fname, hash_key);
if ((status = nvs_open(fname, NVS_READWRITE, &cache_env.cache_addr[*index].cache_fp)) == ESP_OK) {
if ((status = nvs_open(fname, NVS_READWRITE, &cache_env->cache_addr[*index].cache_fp)) == ESP_OK) {
// Set the open flag to TRUE when success to open the hash file.
cache_env.cache_addr[*index].is_open = TRUE;
cache_env->cache_addr[*index].is_open = TRUE;
}
}
}
@ -144,56 +144,56 @@ static void cacheReset(BD_ADDR bda)
char fname[255] = {0};
getFilename(fname, bda);
UINT8 index = 0;
//cache_env.cache_addr
//cache_env->cache_addr
if ((index = bta_gattc_co_find_addr_in_cache(bda)) != INVALID_ADDR_NUM) {
//clear the association address pending in the source address.
bta_gattc_co_cache_clear_assoc_addr(bda);
if (cache_env.cache_addr[index].is_open) {
nvs_erase_all(cache_env.cache_addr[index].cache_fp);
nvs_close(cache_env.cache_addr[index].cache_fp);
cache_env.cache_addr[index].is_open = FALSE;
if (cache_env->cache_addr[index].is_open) {
nvs_erase_all(cache_env->cache_addr[index].cache_fp);
nvs_close(cache_env->cache_addr[index].cache_fp);
cache_env->cache_addr[index].is_open = FALSE;
} else {
cacheOpen(bda, false, &index);
if (cache_env.cache_addr[index].is_open) {
nvs_erase_all(cache_env.cache_addr[index].cache_fp);
nvs_close(cache_env.cache_addr[index].cache_fp);
cache_env.cache_addr[index].is_open = FALSE;
if (cache_env->cache_addr[index].is_open) {
nvs_erase_all(cache_env->cache_addr[index].cache_fp);
nvs_close(cache_env->cache_addr[index].cache_fp);
cache_env->cache_addr[index].is_open = FALSE;
} else {
APPL_TRACE_ERROR("%s cacheOpen failed", __func__);
return;
}
}
if(cache_env.num_addr == 0) {
if(cache_env->num_addr == 0) {
APPL_TRACE_ERROR("%s cache addr list error", __func__);
return;
}
UINT8 num = cache_env.num_addr;
UINT8 num = cache_env->num_addr;
//delete the server_bda in the addr_info list.
for(UINT8 i = index; i < (num - 1); i++) {
memcpy(&cache_env.cache_addr[i], &cache_env.cache_addr[i+1], sizeof(cache_addr_info_t));
memcpy(&cache_env->cache_addr[i], &cache_env->cache_addr[i+1], sizeof(cache_addr_info_t));
}
//reduced the number address counter also
cache_env.num_addr--;
cache_env->num_addr--;
//update addr list to nvs flash
if(cache_env.num_addr > 0) {
if(cache_env->num_addr > 0) {
//update
UINT8 *p_buf = osi_malloc(MAX_ADDR_LIST_CACHE_BUF);
if(!p_buf) {
APPL_TRACE_ERROR("%s malloc error", __func__);
return;
}
UINT16 length = cache_env.num_addr*(sizeof(BD_ADDR) + sizeof(hash_key_t));
for (UINT8 i = 0; i < cache_env.num_addr; i++) {
UINT16 length = cache_env->num_addr*(sizeof(BD_ADDR) + sizeof(hash_key_t));
for (UINT8 i = 0; i < cache_env->num_addr; i++) {
//copy the address to the buffer.
memcpy(p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)), cache_env.cache_addr[i].addr, sizeof(BD_ADDR));
memcpy(p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)), cache_env->cache_addr[i].addr, sizeof(BD_ADDR));
//copy the hash key to the buffer.
memcpy(p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)) + sizeof(BD_ADDR),
cache_env.cache_addr[i].hash_key, sizeof(hash_key_t));
cache_env->cache_addr[i].hash_key, sizeof(hash_key_t));
}
if (cache_env.is_open) {
if (nvs_set_blob(cache_env.addr_fp, cache_key, p_buf, length) != ESP_OK) {
if (cache_env->is_open) {
if (nvs_set_blob(cache_env->addr_fp, cache_key, p_buf, length) != ESP_OK) {
APPL_TRACE_WARNING("%s, nvs set blob failed", __func__);
}
}
@ -201,10 +201,10 @@ static void cacheReset(BD_ADDR bda)
} else {
//erase
if (cache_env.is_open) {
nvs_erase_all(cache_env.addr_fp);
nvs_close(cache_env.addr_fp);
cache_env.is_open = FALSE;
if (cache_env->is_open) {
nvs_erase_all(cache_env->addr_fp);
nvs_close(cache_env->addr_fp);
cache_env->is_open = FALSE;
} else {
APPL_TRACE_WARNING("cache_env status is error");
}
@ -267,9 +267,9 @@ tBTA_GATT_STATUS bta_gattc_co_cache_load(tBTA_GATTC_NV_ATTR *attr, UINT8 index)
tBTA_GATT_STATUS status = BTA_GATT_ERROR;
size_t length = 0;
// Read the size of memory space required for blob
nvs_get_blob(cache_env.cache_addr[index].cache_fp, cache_key, NULL, &length);
nvs_get_blob(cache_env->cache_addr[index].cache_fp, cache_key, NULL, &length);
// Read previously saved blob if available
esp_err_t err_code = nvs_get_blob(cache_env.cache_addr[index].cache_fp, cache_key, attr, &length);
esp_err_t err_code = nvs_get_blob(cache_env->cache_addr[index].cache_fp, cache_key, attr, &length);
#if (!CONFIG_BT_STACK_NO_LOG)
num_attr = length / sizeof(tBTA_GATTC_NV_ATTR);
#endif
@ -288,7 +288,7 @@ size_t bta_gattc_get_cache_attr_length(UINT8 index)
}
// Read the size of memory space required for blob
nvs_get_blob(cache_env.cache_addr[index].cache_fp, cache_key, NULL, &length);
nvs_get_blob(cache_env->cache_addr[index].cache_fp, cache_key, NULL, &length);
return length;
}
@ -320,7 +320,7 @@ void bta_gattc_co_cache_save (BD_ADDR server_bda, UINT16 num_attr,
bta_gattc_co_cache_addr_save(server_bda, hash_key);
if (cacheOpen(server_bda, TRUE, &index)) {
esp_err_t err_code = nvs_set_blob(cache_env.cache_addr[index].cache_fp, cache_key,
esp_err_t err_code = nvs_set_blob(cache_env->cache_addr[index].cache_fp, cache_key,
p_attr_list, sizeof(tBTA_GATTC_NV_ATTR)*num_attr);
status = (err_code == ESP_OK) ? BTA_GATT_OK : BTA_GATT_ERROR;
} else {
@ -380,12 +380,23 @@ void bta_gattc_co_cache_addr_init(void)
nvs_handle_t fp;
esp_err_t err_code;
UINT8 num_addr;
UINT8 *p_buf = osi_malloc(MAX_ADDR_LIST_CACHE_BUF);
size_t length = MAX_ADDR_LIST_CACHE_BUF;
UINT8 *p_buf = osi_malloc(MAX_ADDR_LIST_CACHE_BUF);
if (p_buf == NULL) {
APPL_TRACE_ERROR("%s malloc failed!", __func__);
return;
}
cache_env = (cache_env_t *)osi_malloc(sizeof(cache_env_t));
if (cache_env == NULL) {
APPL_TRACE_ERROR("%s malloc failed!", __func__);
osi_free(p_buf);
return;
}
if ((err_code = nvs_open(cache_addr, NVS_READWRITE, &fp)) == ESP_OK) {
cache_env.addr_fp = fp;
cache_env.is_open = TRUE;
cache_env->addr_fp = fp;
cache_env->is_open = TRUE;
// Read previously saved blob if available
if ((err_code = nvs_get_blob(fp, cache_key, p_buf, &length)) != ESP_OK) {
if(err_code != ESP_ERR_NVS_NOT_FOUND) {
@ -395,18 +406,18 @@ void bta_gattc_co_cache_addr_init(void)
return;
}
num_addr = length / (sizeof(BD_ADDR) + sizeof(hash_key_t));
cache_env.num_addr = num_addr;
cache_env->num_addr = num_addr;
//read the address from nvs flash to cache address list.
for (UINT8 i = 0; i < num_addr; i++) {
memcpy(cache_env.cache_addr[i].addr, p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)), sizeof(BD_ADDR));
memcpy(cache_env.cache_addr[i].hash_key,
memcpy(cache_env->cache_addr[i].addr, p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)), sizeof(BD_ADDR));
memcpy(cache_env->cache_addr[i].hash_key,
p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)) + sizeof(BD_ADDR), sizeof(hash_key_t));
APPL_TRACE_DEBUG("cache_addr[%x] = %x:%x:%x:%x:%x:%x", i, cache_env.cache_addr[i].addr[0], cache_env.cache_addr[i].addr[1], cache_env.cache_addr[i].addr[2],
cache_env.cache_addr[i].addr[3], cache_env.cache_addr[i].addr[4], cache_env.cache_addr[i].addr[5]);
APPL_TRACE_DEBUG("hash_key[%x] = %x%x%x%x", i, cache_env.cache_addr[i].hash_key[0], cache_env.cache_addr[i].hash_key[1],
cache_env.cache_addr[i].hash_key[2], cache_env.cache_addr[i].hash_key[3]);
bta_gattc_co_cache_new_assoc_list(cache_env.cache_addr[i].addr, i);
APPL_TRACE_DEBUG("cache_addr[%x] = %x:%x:%x:%x:%x:%x", i, cache_env->cache_addr[i].addr[0], cache_env->cache_addr[i].addr[1], cache_env->cache_addr[i].addr[2],
cache_env->cache_addr[i].addr[3], cache_env->cache_addr[i].addr[4], cache_env->cache_addr[i].addr[5]);
APPL_TRACE_DEBUG("hash_key[%x] = %x%x%x%x", i, cache_env->cache_addr[i].hash_key[0], cache_env->cache_addr[i].hash_key[1],
cache_env->cache_addr[i].hash_key[2], cache_env->cache_addr[i].hash_key[3]);
bta_gattc_co_cache_new_assoc_list(cache_env->cache_addr[i].addr, i);
}
} else {
APPL_TRACE_ERROR("%s, Line = %d, nvs flash open fail, err_code = %x", __func__, __LINE__, err_code);
@ -420,14 +431,14 @@ void bta_gattc_co_cache_addr_init(void)
void bta_gattc_co_cache_addr_deinit(void)
{
if(!cache_env.is_open) {
if(!cache_env->is_open) {
return;
}
nvs_close(cache_env.addr_fp);
cache_env.is_open = false;
nvs_close(cache_env->addr_fp);
cache_env->is_open = false;
for(UINT8 i = 0; i< cache_env.num_addr; i++) {
cache_addr_info_t *addr_info = &cache_env.cache_addr[i];
for(UINT8 i = 0; i< cache_env->num_addr; i++) {
cache_addr_info_t *addr_info = &cache_env->cache_addr[i];
if(addr_info) {
nvs_close(addr_info->cache_fp);
addr_info->is_open = false;
@ -436,13 +447,16 @@ void bta_gattc_co_cache_addr_deinit(void)
}
}
}
osi_free(cache_env);
cache_env = NULL;
}
BOOLEAN bta_gattc_co_addr_in_cache(BD_ADDR bda)
{
UINT8 addr_index = 0;
UINT8 num = cache_env.num_addr;
cache_addr_info_t *addr_info = &cache_env.cache_addr[0];
UINT8 num = cache_env->num_addr;
cache_addr_info_t *addr_info = &cache_env->cache_addr[0];
for (addr_index = 0; addr_index < num; addr_index++) {
if (!memcmp(addr_info->addr, bda, sizeof(BD_ADDR))) {
return TRUE;
@ -455,8 +469,8 @@ BOOLEAN bta_gattc_co_addr_in_cache(BD_ADDR bda)
UINT8 bta_gattc_co_find_addr_in_cache(BD_ADDR bda)
{
UINT8 addr_index = 0;
UINT8 num = cache_env.num_addr;
cache_addr_info_t *addr_info = &cache_env.cache_addr[0];
UINT8 num = cache_env->num_addr;
cache_addr_info_t *addr_info = &cache_env->cache_addr[0];
for (addr_index = 0; addr_index < num; addr_index++, addr_info++) {
if (!memcmp(addr_info->addr, bda, sizeof(BD_ADDR))) {
@ -470,8 +484,8 @@ UINT8 bta_gattc_co_find_addr_in_cache(BD_ADDR bda)
UINT8 bta_gattc_co_find_hash_in_cache(hash_key_t hash_key)
{
UINT8 index = 0;
UINT8 num = cache_env.num_addr;
cache_addr_info_t *addr_info = &cache_env.cache_addr[0];
UINT8 num = cache_env->num_addr;
cache_addr_info_t *addr_info = &cache_env->cache_addr[0];
for (index = 0; index < num; index++) {
if (!memcmp(addr_info->hash_key, hash_key, sizeof(hash_key_t))) {
return index;
@ -483,21 +497,21 @@ UINT8 bta_gattc_co_find_hash_in_cache(hash_key_t hash_key)
UINT8 bta_gattc_co_get_addr_num(void)
{
return cache_env.num_addr;
return cache_env->num_addr;
}
void bta_gattc_co_get_addr_list(BD_ADDR *addr_list)
{
UINT8 num = cache_env.num_addr;
UINT8 num = cache_env->num_addr;
for (UINT8 i = 0; i < num; i++) {
memcpy(addr_list[i], cache_env.cache_addr[i].addr, sizeof(BD_ADDR));
memcpy(addr_list[i], cache_env->cache_addr[i].addr, sizeof(BD_ADDR));
}
}
void bta_gattc_co_cache_addr_save(BD_ADDR bd_addr, hash_key_t hash_key)
{
esp_err_t err_code;
UINT8 num = ++cache_env.num_addr;
UINT8 num = ++cache_env->num_addr;
UINT8 index = 0;
UINT8 *p_buf = osi_malloc(MAX_ADDR_LIST_CACHE_BUF);
// check the address list has the same hash key or not
@ -506,39 +520,39 @@ void bta_gattc_co_cache_addr_save(BD_ADDR bd_addr, hash_key_t hash_key)
if ((index = bta_gattc_co_find_addr_in_cache(bd_addr)) != INVALID_ADDR_NUM) {
APPL_TRACE_DEBUG("%s(), the hash bd_addr already in the cache list, index = %x", __func__, index);
//if the bd_addr already in the address list, update the hash key in it.
memcpy(cache_env.cache_addr[index].addr, bd_addr, sizeof(BD_ADDR));
memcpy(cache_env.cache_addr[index].hash_key, hash_key, sizeof(hash_key_t));
memcpy(cache_env->cache_addr[index].addr, bd_addr, sizeof(BD_ADDR));
memcpy(cache_env->cache_addr[index].hash_key, hash_key, sizeof(hash_key_t));
} else {
//if the bd_addr didn't in the address list, added the bd_addr to the last of the address list.
memcpy(cache_env.cache_addr[num - 1].hash_key, hash_key, sizeof(hash_key_t));
memcpy(cache_env.cache_addr[num - 1].addr, bd_addr, sizeof(BD_ADDR));
memcpy(cache_env->cache_addr[num - 1].hash_key, hash_key, sizeof(hash_key_t));
memcpy(cache_env->cache_addr[num - 1].addr, bd_addr, sizeof(BD_ADDR));
}
} else {
APPL_TRACE_DEBUG("%s(), num = %d", __func__, num);
memcpy(cache_env.cache_addr[num - 1].addr, bd_addr, sizeof(BD_ADDR));
memcpy(cache_env.cache_addr[num - 1].hash_key, hash_key, sizeof(hash_key_t));
memcpy(cache_env->cache_addr[num - 1].addr, bd_addr, sizeof(BD_ADDR));
memcpy(cache_env->cache_addr[num - 1].hash_key, hash_key, sizeof(hash_key_t));
}
nvs_handle_t *fp = &cache_env.addr_fp;
nvs_handle_t *fp = &cache_env->addr_fp;
UINT16 length = num*(sizeof(BD_ADDR) + sizeof(hash_key_t));
for (UINT8 i = 0; i < num; i++) {
//copy the address to the buffer.
memcpy(p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)), cache_env.cache_addr[i].addr, sizeof(BD_ADDR));
memcpy(p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)), cache_env->cache_addr[i].addr, sizeof(BD_ADDR));
//copy the hash key to the buffer.
memcpy(p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)) + sizeof(BD_ADDR),
cache_env.cache_addr[i].hash_key, sizeof(hash_key_t));
cache_env->cache_addr[i].hash_key, sizeof(hash_key_t));
}
if (cache_env.is_open) {
if ((err_code = nvs_set_blob(cache_env.addr_fp, cache_key, p_buf, length)) != ESP_OK) {
if (cache_env->is_open) {
if ((err_code = nvs_set_blob(cache_env->addr_fp, cache_key, p_buf, length)) != ESP_OK) {
APPL_TRACE_WARNING("%s(), nvs set blob fail, err %d", __func__, err_code);
}
} else {
if ((err_code = nvs_open(cache_addr, NVS_READWRITE , fp)) == ESP_OK) {
cache_env.is_open = true;
if (( err_code = nvs_set_blob(cache_env.addr_fp, cache_key, p_buf, length)) != ESP_OK) {
cache_env->is_open = true;
if (( err_code = nvs_set_blob(cache_env->addr_fp, cache_key, p_buf, length)) != ESP_OK) {
APPL_TRACE_WARNING("%s(), nvs set blob fail, err %d", __func__, err_code);
}
} else {
@ -553,7 +567,7 @@ void bta_gattc_co_cache_addr_save(BD_ADDR bd_addr, hash_key_t hash_key)
BOOLEAN bta_gattc_co_cache_new_assoc_list(BD_ADDR src_addr, UINT8 index)
{
cache_addr_info_t *addr_info = &cache_env.cache_addr[index];
cache_addr_info_t *addr_info = &cache_env->cache_addr[index];
addr_info->assoc_addr = list_new(osi_free_func);
return (addr_info->assoc_addr != NULL ? TRUE : FALSE);
}
@ -565,7 +579,7 @@ BOOLEAN bta_gattc_co_cache_append_assoc_addr(BD_ADDR src_addr, BD_ADDR assoc_add
UINT8 *p_assoc_buf = osi_malloc(sizeof(BD_ADDR));
memcpy(p_assoc_buf, assoc_addr, sizeof(BD_ADDR));
if ((addr_index = bta_gattc_co_find_addr_in_cache(src_addr)) != INVALID_ADDR_NUM) {
addr_info = &cache_env.cache_addr[addr_index];
addr_info = &cache_env->cache_addr[addr_index];
if (addr_info->assoc_addr == NULL) {
addr_info->assoc_addr =list_new(NULL);
}
@ -580,7 +594,7 @@ BOOLEAN bta_gattc_co_cache_remove_assoc_addr(BD_ADDR src_addr, BD_ADDR assoc_add
UINT8 addr_index = 0;
cache_addr_info_t *addr_info;
if ((addr_index = bta_gattc_co_find_addr_in_cache(src_addr)) != INVALID_ADDR_NUM) {
addr_info = &cache_env.cache_addr[addr_index];
addr_info = &cache_env->cache_addr[addr_index];
if (addr_info->assoc_addr != NULL) {
for (list_node_t *sn = list_begin(addr_info->assoc_addr);
sn != list_end(addr_info->assoc_addr); sn = list_next(sn)) {
@ -600,8 +614,8 @@ BOOLEAN bta_gattc_co_cache_remove_assoc_addr(BD_ADDR src_addr, BD_ADDR assoc_add
UINT8* bta_gattc_co_cache_find_src_addr(BD_ADDR assoc_addr, UINT8 *index)
{
UINT8 num = cache_env.num_addr;
cache_addr_info_t *addr_info = &cache_env.cache_addr[0];
UINT8 num = cache_env->num_addr;
cache_addr_info_t *addr_info = &cache_env->cache_addr[0];
UINT8 *addr_data;
//Check the assoc_addr list is NULL or not
if (addr_info->assoc_addr == NULL) {
@ -635,7 +649,7 @@ BOOLEAN bta_gattc_co_cache_clear_assoc_addr(BD_ADDR src_addr)
UINT8 addr_index = 0;
cache_addr_info_t *addr_info;
if ((addr_index = bta_gattc_co_find_addr_in_cache(src_addr)) != INVALID_ADDR_NUM) {
addr_info = &cache_env.cache_addr[addr_index];
addr_info = &cache_env->cache_addr[addr_index];
if (addr_info->assoc_addr != NULL) {
list_clear(addr_info->assoc_addr);
} else {
@ -647,6 +661,7 @@ BOOLEAN bta_gattc_co_cache_clear_assoc_addr(BD_ADDR src_addr)
return FALSE;
}
// #endif /* #if( defined GATTC_CACHE_NVS ) && (GATTC_CACHE_NVS == TRUE) */
#endif /* #if( defined BLE_INCLUDED ) && (BLE_INCLUDED == TRUE) */
#endif /* #if( defined BTA_GATT_INCLUDED ) && (BTA_GATT_INCLUDED == TRUE) */

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);
static void bta_gatts_cong_cback (UINT16 conn_id, BOOLEAN congested);
static tGATT_CBACK bta_gatts_cback = {
static const tGATT_CBACK bta_gatts_cback = {
bta_gatts_conn_cback,
NULL,
NULL,
@ -59,7 +59,7 @@ static tGATT_CBACK bta_gatts_cback = {
bta_gatts_cong_cback
};
tGATT_APPL_INFO bta_gatts_nv_cback = {
const tGATT_APPL_INFO bta_gatts_nv_cback = {
bta_gatts_nv_save_cback,
bta_gatts_nv_srv_chg_cback
};

View File

@ -82,7 +82,7 @@ void BTA_GATTS_Disable(void)
** Returns None
**
*******************************************************************************/
void BTA_GATTS_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTS_CBACK *p_cback)
void BTA_GATTS_AppRegister(const tBT_UUID * p_app_uuid, tBTA_GATTS_CBACK *p_cback)
{
tBTA_GATTS_API_REG *p_buf;
@ -149,7 +149,7 @@ void BTA_GATTS_AppDeregister(tBTA_GATTS_IF server_if)
** Returns void
**
*******************************************************************************/
void BTA_GATTS_CreateService(tBTA_GATTS_IF server_if, tBT_UUID *p_service_uuid, UINT8 inst,
void BTA_GATTS_CreateService(tBTA_GATTS_IF server_if, const tBT_UUID * p_service_uuid, UINT8 inst,
UINT16 num_handle, BOOLEAN is_primary)
{
tBTA_GATTS_API_CREATE_SRVC *p_buf;
@ -214,7 +214,7 @@ void BTA_GATTS_AddIncludeService(UINT16 service_id, UINT16 included_service_id)
** Returns None
**
*******************************************************************************/
void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid,
void BTA_GATTS_AddCharacteristic (UINT16 service_id, const tBT_UUID * p_char_uuid,
tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property, tGATT_ATTR_VAL *attr_val,
tBTA_GATTS_ATTR_CONTROL *control)
{
@ -270,7 +270,7 @@ void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid,
*******************************************************************************/
void BTA_GATTS_AddCharDescriptor (UINT16 service_id,
tBTA_GATT_PERM perm,
tBT_UUID *p_descr_uuid, tBTA_GATT_ATTR_VAL *attr_val,
const tBT_UUID * p_descr_uuid, tBTA_GATT_ATTR_VAL *attr_val,
tBTA_GATTS_ATTR_CONTROL *control)
{
tBTA_GATTS_API_ADD_DESCR *p_buf;

View File

@ -31,9 +31,9 @@
// #include "uipc_msg.h"
#include "stack/sdp_api.h"
#if BLE_INCLUDED == TRUE
// #if BLE_INCLUDED == TRUE
#include "stack/btm_ble_api.h"
#endif
// #endif
/*****************************************************************************
** Constants and data types
@ -323,7 +323,7 @@ typedef struct {
tBTA_DM_CONFIG_EIR_CBACK *config_eir_callback; /* callback */
} tBTA_DM_EIR_CONF;
#if BLE_INCLUDED == TRUE
// #if BLE_INCLUDED == TRUE
/* ADV data flag bit definition used for BTM_BLE_AD_TYPE_FLAG */
#define BTA_BLE_LIMIT_DISC_FLAG BTM_BLE_LIMIT_DISC_FLAG
#define BTA_BLE_GEN_DISC_FLAG BTM_BLE_GEN_DISC_FLAG
@ -510,7 +510,7 @@ enum {
typedef tBTM_BLE_BATCH_SCAN_EVT tBTA_BLE_BATCH_SCAN_EVT;
typedef tBTM_BLE_TRACK_ADV_ACTION tBTA_BLE_TRACK_ADV_ACTION;
#endif
// #endif
/* BLE customer specific feature function type definitions */
/* data type used on customer specific feature for RSSI monitoring */
@ -1473,9 +1473,11 @@ extern void BTA_DmSetDeviceName(const char *p_name);
*******************************************************************************/
extern void BTA_DmConfigEir(tBTA_DM_EIR_CONF *eir_config);
#if (BLE_INCLUDED == TRUE)
extern void BTA_DmUpdateWhiteList(BOOLEAN add_remove, BD_ADDR remote_addr, tBLE_ADDR_TYPE addr_type, tBTA_ADD_WHITELIST_CBACK *add_wl_cb);
extern void BTA_DmBleReadAdvTxPower(tBTA_CMPL_CB *cmpl_cb);
#endif ///BLE_INCLUDED == TRUE
extern void BTA_DmBleReadRSSI(BD_ADDR remote_addr, tBTA_TRANSPORT transport, tBTA_CMPL_CB *cmpl_cb);
@ -1809,6 +1811,17 @@ extern void bta_dmexecutecallback (tBTA_DM_EXEC_CBACK *p_callback, void *p_param
*******************************************************************************/
extern void BTA_DmPcmInitSamples (UINT32 src_sps, UINT32 bits, UINT32 n_channels);
/*******************************************************************************
**
** Function BTA_DmPcmDeinitSamples
**
** Description Deinitialize the down sample converter.
**
** Returns none
**
*******************************************************************************/
extern void BTA_DmPcmDeinitSamples(void);
/**************************************************************************************
** Function BTA_DmPcmResample
**

View File

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

View File

@ -30,7 +30,6 @@
#include "osi/list.h"
#ifndef BTA_GATT_INCLUDED
#warning BTA_GATT_INCLUDED not defined
#define BTA_GATT_INCLUDED FALSE
#endif
@ -1234,7 +1233,7 @@ extern void BTA_GATTS_Disable(void);
** Returns None
**
*******************************************************************************/
extern void BTA_GATTS_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTS_CBACK *p_cback);
extern void BTA_GATTS_AppRegister(const tBT_UUID * p_app_uuid, tBTA_GATTS_CBACK *p_cback);
/*******************************************************************************
@ -1269,7 +1268,7 @@ extern void BTA_GATTS_AppDeregister(tBTA_GATTS_IF server_if);
** Returns void
**
*******************************************************************************/
extern void BTA_GATTS_CreateService(tBTA_GATTS_IF server_if, tBT_UUID *p_service_uuid,
extern void BTA_GATTS_CreateService(tBTA_GATTS_IF server_if, const tBT_UUID * p_service_uuid,
UINT8 inst, UINT16 num_handle, BOOLEAN is_primary);
/*******************************************************************************
@ -1304,7 +1303,7 @@ extern void BTA_GATTS_AddIncludeService(UINT16 service_id, UINT16 included_servi
** Returns None
**
*******************************************************************************/
extern void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid,
extern void BTA_GATTS_AddCharacteristic (UINT16 service_id, const tBT_UUID * p_char_uuid,
tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property, tGATT_ATTR_VAL *attr_val,
tBTA_GATTS_ATTR_CONTROL *control);
@ -1327,7 +1326,7 @@ extern void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_u
*******************************************************************************/
extern void BTA_GATTS_AddCharDescriptor (UINT16 service_id,
tBTA_GATT_PERM perm,
tBT_UUID *p_descr_uuid, tBTA_GATT_ATTR_VAL *attr_val,
const tBT_UUID * p_descr_uuid, tBTA_GATT_ATTR_VAL *attr_val,
tBTA_GATTS_ATTR_CONTROL *control);
/*******************************************************************************

View File

@ -96,6 +96,19 @@ extern "C"
*******************************************************************************/
extern tBTA_SDP_STATUS BTA_SdpEnable(tBTA_SDP_DM_CBACK *p_cback);
/*******************************************************************************
**
** Function BTA_SdpDisable
**
** Description Disable the SDP search I/F service.
** Free buffer for SDP configuration structure.
**
** Returns BTA_SDP_SUCCESS if successful.
** BTA_SDP_FAIL if internal failure.
**
*******************************************************************************/
extern tBTA_SDP_STATUS BTA_SdpDisable(void);
/*******************************************************************************
**
** Function BTA_SdpSearch

View File

@ -215,7 +215,7 @@ extern "C" {
extern void bta_sys_init(void);
extern void bta_sys_free(void);
extern void bta_sys_event(BT_HDR *p_msg);
extern void bta_sys_event(void * param);
extern void bta_sys_set_trace_level(UINT8 level);
extern void bta_sys_register(UINT8 id, const tBTA_SYS_REG *p_reg);
extern void bta_sys_deregister(UINT8 id);

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_API_ENABLE *p_buf;
int i;
APPL_TRACE_API( "BTA_JvEnable");
#if BTA_DYNAMIC_MEMORY == TRUE
/* Malloc buffer for JV configuration structure */
p_bta_jv_cfg->p_sdp_raw_data = (UINT8 *)osi_malloc(p_bta_jv_cfg->sdp_raw_size);
p_bta_jv_cfg->p_sdp_db = (tSDP_DISCOVERY_DB *)osi_malloc(p_bta_jv_cfg->sdp_db_size);
if (p_bta_jv_cfg->p_sdp_raw_data == NULL || p_bta_jv_cfg->p_sdp_db == NULL) {
return BTA_JV_NO_DATA;
}
#endif
if (p_cback && FALSE == bta_sys_is_register(BTA_ID_JV)) {
memset(&bta_jv_cb, 0, sizeof(tBTA_JV_CB));
/* set handle to invalid value by default */
@ -110,6 +119,14 @@ void BTA_JvDisable(void)
p_buf->event = BTA_JV_API_DISABLE_EVT;
bta_sys_sendmsg(p_buf);
}
#if BTA_DYNAMIC_MEMORY == TRUE
/* Free buffer for JV configuration structure */
osi_free(p_bta_jv_cfg->p_sdp_raw_data);
osi_free(p_bta_jv_cfg->p_sdp_db);
p_bta_jv_cfg->p_sdp_raw_data = NULL;
p_bta_jv_cfg->p_sdp_db = NULL;
#endif
}
/*******************************************************************************

View File

@ -43,15 +43,22 @@
* between BTA_JvEnable and BTA_JvDisable
* p_bta_jv_cfg->p_sdp_raw_data can be allocated before calling BTA_JvStartDiscovery
* it can be de-allocated after the last call to access the database */
#if BTA_DYNAMIC_MEMORY == FALSE
static UINT8 bta_jv_sdp_raw_data[BTA_JV_SDP_RAW_DATA_SIZE];
static UINT8 __attribute__ ((aligned(4))) bta_jv_sdp_db_data[BTA_JV_SDP_DB_SIZE];
#endif
/* JV configuration structure */
const tBTA_JV_CFG bta_jv_cfg = {
/*const */tBTA_JV_CFG bta_jv_cfg = {
BTA_JV_SDP_RAW_DATA_SIZE, /* The size of p_sdp_raw_data */
BTA_JV_SDP_DB_SIZE, /* The size of p_sdp_db_data */
#if BTA_DYNAMIC_MEMORY == FALSE
bta_jv_sdp_raw_data, /* The data buffer to keep raw data */
(tSDP_DISCOVERY_DB *)bta_jv_sdp_db_data /* The data buffer to keep SDP database */
#else
NULL,
NULL
#endif
};
tBTA_JV_CFG *p_bta_jv_cfg = (tBTA_JV_CFG *) &bta_jv_cfg;

View File

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

View File

@ -61,6 +61,15 @@ tBTA_SDP_STATUS BTA_SdpEnable(tBTA_SDP_DM_CBACK *p_cback)
tBTA_SDP_API_ENABLE *p_buf;
APPL_TRACE_API("%s\n", __FUNCTION__);
#if BTA_DYNAMIC_MEMORY == TRUE
/* Malloc buffer for SDP configuration structure */
p_bta_sdp_cfg->p_sdp_db = (tSDP_DISCOVERY_DB *)osi_malloc(p_bta_sdp_cfg->sdp_db_size);
if (p_bta_sdp_cfg->p_sdp_db == NULL) {
return BTA_SDP_FAILURE;
}
#endif
if (p_cback && FALSE == bta_sys_is_register(BTA_ID_SDP)) {
memset(&bta_sdp_cb, 0, sizeof(tBTA_SDP_CB));
@ -78,6 +87,29 @@ tBTA_SDP_STATUS BTA_SdpEnable(tBTA_SDP_DM_CBACK *p_cback)
return (status);
}
/*******************************************************************************
**
** Function BTA_SdpDisable
**
** Description Disable the SDP search I/F service.
** Free buffer for SDP configuration structure.
**
** Returns BTA_SDP_SUCCESS if successful.
** BTA_SDP_FAIL if internal failure.
**
*******************************************************************************/
tBTA_SDP_STATUS BTA_SdpDisable(void)
{
tBTA_SDP_STATUS status = BTA_SDP_SUCCESS;
#if BTA_DYNAMIC_MEMORY == TRUE
/* Free buffer for SDP configuration structure */
osi_free(p_bta_sdp_cfg->p_sdp_db);
p_bta_sdp_cfg->p_sdp_db = NULL;
#endif
return (status);
}
/*******************************************************************************
**
** Function BTA_SdpSearch

View File

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

View File

@ -29,6 +29,7 @@
#include "osi/alarm.h"
#include "osi/thread.h"
#include "stack/btm_api.h"
#include "stack/btu.h"
#include "bta/bta_api.h"
#include "bta/bta_sys.h"
#include "bta_sys_int.h"
@ -481,8 +482,10 @@ void bta_sys_hw_evt_stack_enabled(tBTA_SYS_HW_MSG *p_sys_hw_msg)
** Returns void
**
*******************************************************************************/
void bta_sys_event(BT_HDR *p_msg)
void bta_sys_event(void * param)
{
BT_HDR *p_msg = (BT_HDR *)param;
UINT8 id;
BOOLEAN freebuf = TRUE;
@ -571,7 +574,7 @@ void bta_sys_sendmsg(void *p_msg)
// there is a procedure in progress that can schedule a task via this
// message queue. This causes |btu_bta_msg_queue| to get cleaned up before
// it gets used here; hence we check for NULL before using it.
if (btu_task_post(SIG_BTU_BTA_MSG, p_msg, TASK_POST_BLOCKING) != TASK_POST_SUCCESS) {
if (btu_task_post(SIG_BTU_BTA_MSG, p_msg, OSI_THREAD_MAX_TIMEOUT) == false) {
osi_free(p_msg);
}
}
@ -591,7 +594,7 @@ void bta_alarm_cb(void *data)
assert(data != NULL);
TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data;
btu_task_post(SIG_BTU_BTA_ALARM, p_tle, TASK_POST_BLOCKING);
btu_task_post(SIG_BTU_BTA_ALARM, p_tle, OSI_THREAD_MAX_TIMEOUT);
}
void bta_sys_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, INT32 timeout_ms)

View File

@ -96,6 +96,7 @@ void btc_storage_save(void)
btc_config_unlock();
}
#if (BLE_INCLUDED == TRUE)
static bt_status_t _btc_storage_add_ble_bonding_key(bt_bdaddr_t *remote_bd_addr,
char *key,
uint8_t key_type,
@ -552,6 +553,7 @@ bt_status_t btc_storage_remove_ble_dev_type(bt_bdaddr_t *remote_bd_addr, bool fl
return ret;
}
#endif ///BLE_INCLUDED == TRUE
static bt_status_t _btc_storage_set_ble_dev_auth_mode(bt_bdaddr_t *remote_bd_addr, uint8_t auth_mode, bool flush)
{
@ -725,6 +727,7 @@ bt_status_t btc_storage_get_remote_addr_type(bt_bdaddr_t *remote_bd_addr,
return ret;
}
#if (BLE_INCLUDED == TRUE)
static void _btc_read_le_key(const uint8_t key_type, const size_t key_len, bt_bdaddr_t bd_addr,
const uint8_t addr_type, const bool add_key, bool *device_added, bool *key_found)
{
@ -926,5 +929,6 @@ int btc_storage_get_num_ble_bond_devices(void)
return num_dev;
}
#endif ///BLE_INCLUDED == TRUE
#endif ///SMP_INCLUDED == TRUE

View File

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

View File

@ -41,10 +41,10 @@
/******************************************************************************
** Static variables
******************************************************************************/
static tBTA_SERVICE_MASK btc_enabled_services = 0;
#if (SMP_INCLUDED == TRUE)
static btc_dm_pairing_cb_t pairing_cb;
static btc_dm_local_key_cb_t ble_local_key_cb;
#if BTC_DYNAMIC_MENDRY == FALSE
btc_dm_cb_t btc_dm_cb = {0};
#else
btc_dm_cb_t *btc_dm_cb_ptr;
#endif
/******************************************************************************
@ -129,23 +129,24 @@ static void btc_disable_bluetooth_evt(void)
}
#if (SMP_INCLUDED == TRUE)
#if (BLE_INCLUDED == TRUE)
void btc_dm_load_ble_local_keys(void)
{
memset(&ble_local_key_cb, 0, sizeof(btc_dm_local_key_cb_t));
memset(&btc_dm_cb.ble_local_key_cb, 0, sizeof(btc_dm_local_key_cb_t));
if (btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_ER,(char*)&ble_local_key_cb.er[0],
if (btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_ER,(char*)&btc_dm_cb.ble_local_key_cb.er[0],
BT_OCTET16_LEN)== BT_STATUS_SUCCESS) {
ble_local_key_cb.is_er_rcvd = TRUE;
btc_dm_cb.ble_local_key_cb.is_er_rcvd = TRUE;
BTC_TRACE_DEBUG("%s BLE ER key loaded",__func__ );
}
if ((btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_IR,(char*)&ble_local_key_cb.id_keys.ir[0],
if ((btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_IR,(char*)&btc_dm_cb.ble_local_key_cb.id_keys.ir[0],
BT_OCTET16_LEN)== BT_STATUS_SUCCESS )&&
(btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_IRK, (char*)&ble_local_key_cb.id_keys.irk[0],
(btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_IRK, (char*)&btc_dm_cb.ble_local_key_cb.id_keys.irk[0],
BT_OCTET16_LEN)== BT_STATUS_SUCCESS)&&
(btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_DHK,(char*)&ble_local_key_cb.id_keys.dhk[0],
(btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_DHK,(char*)&btc_dm_cb.ble_local_key_cb.id_keys.dhk[0],
BT_OCTET16_LEN)== BT_STATUS_SUCCESS)) {
ble_local_key_cb.is_id_keys_rcvd = TRUE;
btc_dm_cb.ble_local_key_cb.is_id_keys_rcvd = TRUE;
BTC_TRACE_DEBUG("%s BLE ID keys loaded", __func__);
}
@ -153,15 +154,15 @@ void btc_dm_load_ble_local_keys(void)
void btc_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er,
tBTA_BLE_LOCAL_ID_KEYS *p_id_keys)
{
if (ble_local_key_cb.is_er_rcvd ) {
memcpy(&er[0], &ble_local_key_cb.er[0], sizeof(BT_OCTET16));
if (btc_dm_cb.ble_local_key_cb.is_er_rcvd ) {
memcpy(&er[0], &btc_dm_cb.ble_local_key_cb.er[0], sizeof(BT_OCTET16));
*p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ER;
}
if (ble_local_key_cb.is_id_keys_rcvd) {
memcpy(&p_id_keys->ir[0], &ble_local_key_cb.id_keys.ir[0], sizeof(BT_OCTET16));
memcpy(&p_id_keys->irk[0], &ble_local_key_cb.id_keys.irk[0], sizeof(BT_OCTET16));
memcpy(&p_id_keys->dhk[0], &ble_local_key_cb.id_keys.dhk[0], sizeof(BT_OCTET16));
if (btc_dm_cb.ble_local_key_cb.is_id_keys_rcvd) {
memcpy(&p_id_keys->ir[0], &btc_dm_cb.ble_local_key_cb.id_keys.ir[0], sizeof(BT_OCTET16));
memcpy(&p_id_keys->irk[0], &btc_dm_cb.ble_local_key_cb.id_keys.irk[0], sizeof(BT_OCTET16));
memcpy(&p_id_keys->dhk[0], &btc_dm_cb.ble_local_key_cb.id_keys.dhk[0], sizeof(BT_OCTET16));
*p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ID;
}
BTC_TRACE_DEBUG("%s *p_key_mask=0x%02x",__func__, *p_key_mask);
@ -173,7 +174,7 @@ static void btc_dm_remove_ble_bonding_keys(void)
bt_bdaddr_t bd_addr;
BTC_TRACE_DEBUG("%s\n",__func__);
bdcpy(bd_addr.address, pairing_cb.bd_addr);
bdcpy(bd_addr.address, btc_dm_cb.pairing_cb.bd_addr);
btc_storage_remove_remote_addr_type(&bd_addr, false);
btc_storage_remove_ble_dev_auth_mode(&bd_addr, false);
@ -183,64 +184,64 @@ static void btc_dm_remove_ble_bonding_keys(void)
static void btc_dm_save_ble_bonding_keys(void)
{
if (!(pairing_cb.ble.is_penc_key_rcvd || pairing_cb.ble.is_pid_key_rcvd || pairing_cb.ble.is_pcsrk_key_rcvd ||
pairing_cb.ble.is_lenc_key_rcvd || pairing_cb.ble.is_lcsrk_key_rcvd || pairing_cb.ble.is_lidk_key_rcvd)) {
if (!(btc_dm_cb.pairing_cb.ble.is_penc_key_rcvd || btc_dm_cb.pairing_cb.ble.is_pid_key_rcvd || btc_dm_cb.pairing_cb.ble.is_pcsrk_key_rcvd ||
btc_dm_cb.pairing_cb.ble.is_lenc_key_rcvd || btc_dm_cb.pairing_cb.ble.is_lcsrk_key_rcvd || btc_dm_cb.pairing_cb.ble.is_lidk_key_rcvd)) {
return ;
}
bt_bdaddr_t bd_addr;
bdcpy(bd_addr.address, pairing_cb.bd_addr);
bdcpy(bd_addr.address, btc_dm_cb.pairing_cb.bd_addr);
btc_storage_set_ble_dev_type(&bd_addr, false);
BTC_TRACE_DEBUG("%s, penc = %d, pid = %d", __func__, pairing_cb.ble.is_penc_key_rcvd, pairing_cb.ble.is_pid_key_rcvd);
if (pairing_cb.ble.is_penc_key_rcvd) {
BTC_TRACE_DEBUG("%s, penc = %d, pid = %d", __func__, btc_dm_cb.pairing_cb.ble.is_penc_key_rcvd, btc_dm_cb.pairing_cb.ble.is_pid_key_rcvd);
if (btc_dm_cb.pairing_cb.ble.is_penc_key_rcvd) {
btc_storage_add_ble_bonding_key(&bd_addr,
(char *) &pairing_cb.ble.penc_key,
(char *) &btc_dm_cb.pairing_cb.ble.penc_key,
BTM_LE_KEY_PENC,
sizeof(tBTM_LE_PENC_KEYS));
pairing_cb.ble.is_penc_key_rcvd = false;
btc_dm_cb.pairing_cb.ble.is_penc_key_rcvd = false;
}
if (pairing_cb.ble.is_pid_key_rcvd) {
if (btc_dm_cb.pairing_cb.ble.is_pid_key_rcvd) {
btc_storage_add_ble_bonding_key(&bd_addr,
(char *) &pairing_cb.ble.pid_key,
(char *) &btc_dm_cb.pairing_cb.ble.pid_key,
BTM_LE_KEY_PID,
sizeof(tBTM_LE_PID_KEYS));
pairing_cb.ble.is_pid_key_rcvd = false;
btc_dm_cb.pairing_cb.ble.is_pid_key_rcvd = false;
}
if (pairing_cb.ble.is_pcsrk_key_rcvd) {
if (btc_dm_cb.pairing_cb.ble.is_pcsrk_key_rcvd) {
btc_storage_add_ble_bonding_key(&bd_addr,
(char *) &pairing_cb.ble.pcsrk_key,
(char *) &btc_dm_cb.pairing_cb.ble.pcsrk_key,
BTM_LE_KEY_PCSRK,
sizeof(tBTM_LE_PCSRK_KEYS));
pairing_cb.ble.is_pcsrk_key_rcvd = false;
btc_dm_cb.pairing_cb.ble.is_pcsrk_key_rcvd = false;
}
if (pairing_cb.ble.is_lenc_key_rcvd) {
if (btc_dm_cb.pairing_cb.ble.is_lenc_key_rcvd) {
btc_storage_add_ble_bonding_key(&bd_addr,
(char *) &pairing_cb.ble.lenc_key,
(char *) &btc_dm_cb.pairing_cb.ble.lenc_key,
BTM_LE_KEY_LENC,
sizeof(tBTM_LE_LENC_KEYS));
pairing_cb.ble.is_lenc_key_rcvd = false;
btc_dm_cb.pairing_cb.ble.is_lenc_key_rcvd = false;
}
if (pairing_cb.ble.is_lcsrk_key_rcvd) {
if (btc_dm_cb.pairing_cb.ble.is_lcsrk_key_rcvd) {
btc_storage_add_ble_bonding_key(&bd_addr,
(char *) &pairing_cb.ble.lcsrk_key,
(char *) &btc_dm_cb.pairing_cb.ble.lcsrk_key,
BTM_LE_KEY_LCSRK,
sizeof(tBTM_LE_LCSRK_KEYS));
pairing_cb.ble.is_lcsrk_key_rcvd = false;
btc_dm_cb.pairing_cb.ble.is_lcsrk_key_rcvd = false;
}
if (pairing_cb.ble.is_lidk_key_rcvd) {
if (btc_dm_cb.pairing_cb.ble.is_lidk_key_rcvd) {
btc_storage_add_ble_bonding_key(&bd_addr,
NULL,
BTM_LE_KEY_LID,
0);
pairing_cb.ble.is_lidk_key_rcvd = false;
btc_dm_cb.pairing_cb.ble.is_lidk_key_rcvd = false;
}
}
@ -252,20 +253,19 @@ static void btc_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
int addr_type;
bt_bdaddr_t bdaddr;
bdcpy(bdaddr.address, p_auth_cmpl->bd_addr);
bdcpy(pairing_cb.bd_addr, p_auth_cmpl->bd_addr);
bdcpy(btc_dm_cb.pairing_cb.bd_addr, p_auth_cmpl->bd_addr);
if (p_auth_cmpl->success) {
status = BT_STATUS_SUCCESS;
BTC_TRACE_DEBUG ("%s, - p_auth_cmpl->bd_addr: %08x%04x", __func__,
(p_auth_cmpl->bd_addr[0] << 24) + (p_auth_cmpl->bd_addr[1] << 16) + (p_auth_cmpl->bd_addr[2] << 8) + p_auth_cmpl->bd_addr[3],
(p_auth_cmpl->bd_addr[4] << 8) + p_auth_cmpl->bd_addr[5]);
BTC_TRACE_DEBUG ("%s, - pairing_cb.bd_addr: %08x%04x", __func__,
(pairing_cb.bd_addr[0] << 24) + (pairing_cb.bd_addr[1] << 16) + (pairing_cb.bd_addr[2] << 8) + pairing_cb.bd_addr[3],
(pairing_cb.bd_addr[4] << 8) + pairing_cb.bd_addr[5]);
// Check if need to save BLE keys
if((p_auth_cmpl->auth_mode & SMP_AUTH_GEN_BOND) == 0) {
return;
}
if (btc_storage_get_remote_addr_type(&bdaddr, &addr_type) != BT_STATUS_SUCCESS) {
btc_storage_set_remote_addr_type(&bdaddr, p_auth_cmpl->addr_type, true);
}
@ -297,6 +297,7 @@ static void btc_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
return;
}
#endif ///BLE_INCLUDED == TRUE
#endif ///SMP_INCLUDED == TRUE
static void btc_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
@ -487,12 +488,12 @@ static void btc_dm_sp_key_req_evt(tBTA_DM_SP_KEY_REQ *p_key_req)
tBTA_SERVICE_MASK btc_get_enabled_services_mask(void)
{
return btc_enabled_services;
return btc_dm_cb.btc_enabled_services;
}
void btc_clear_services_mask(void)
{
btc_enabled_services = 0;
btc_dm_cb.btc_enabled_services = 0;
}
static bt_status_t btc_in_execute_service_request(tBTA_SERVICE_ID service_id,
@ -530,9 +531,9 @@ bt_status_t btc_dm_enable_service(tBTA_SERVICE_ID service_id)
{
tBTA_SERVICE_ID *p_id = &service_id;
btc_enabled_services |= (1 << service_id);
btc_dm_cb.btc_enabled_services |= (1 << service_id);
BTC_TRACE_DEBUG("%s: current services:0x%x", __FUNCTION__, btc_enabled_services);
BTC_TRACE_DEBUG("%s: current services:0x%x", __FUNCTION__, btc_dm_cb.btc_enabled_services);
btc_dm_execute_service_request(TRUE, (char *)p_id);
@ -543,9 +544,9 @@ bt_status_t btc_dm_disable_service(tBTA_SERVICE_ID service_id)
{
tBTA_SERVICE_ID *p_id = &service_id;
btc_enabled_services &= (tBTA_SERVICE_MASK)(~(1 << service_id));
btc_dm_cb.btc_enabled_services &= (tBTA_SERVICE_MASK)(~(1 << service_id));
BTC_TRACE_DEBUG("%s: Current Services:0x%x", __FUNCTION__, btc_enabled_services);
BTC_TRACE_DEBUG("%s: Current Services:0x%x", __FUNCTION__, btc_dm_cb.btc_enabled_services);
btc_dm_execute_service_request(FALSE, (char *)p_id);
@ -570,8 +571,10 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
btc_clear_services_mask();
#if (SMP_INCLUDED == TRUE)
btc_storage_load_bonded_devices();
#if (BLE_INCLUDED == TRUE)
//load the bonding device to the btm layer
btc_storage_load_bonded_ble_devices();
#endif ///BLE_INCLUDED == TRUE
#endif ///SMP_INCLUDED == TRUE
/* Set initial device name, it can be overwritten later */
@ -634,6 +637,7 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
#endif /* #if (SMP_INCLUDED == TRUE) */
break;
}
#if (BLE_INCLUDED == TRUE)
case BTA_DM_BLE_DEV_UNPAIRED_EVT: {
#if (SMP_INCLUDED == TRUE)
bt_bdaddr_t bd_addr;
@ -655,6 +659,7 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
#endif /* #if (SMP_INCLUDED == TRUE) */
break;
}
#endif ///BLE_INCLUDED == TRUE
case BTA_DM_BUSY_LEVEL_EVT:
#if (BTC_GAP_BT_INCLUDED == TRUE)
{
@ -669,7 +674,7 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
case BTA_DM_HW_ERROR_EVT:
BTC_TRACE_DEBUG( "btc_dm_sec_cback : unhandled event (%d)\n", msg->act );
break;
#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE) && (SMP_INCLUDED == TRUE))
#if ((BLE_INCLUDED == TRUE) && (SMP_INCLUDED == TRUE))
case BTA_DM_BLE_AUTH_CMPL_EVT: {
rsp_app = true;
ble_msg.act = ESP_GAP_BLE_AUTH_CMPL_EVT;
@ -693,9 +698,9 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
switch (p_data->ble_key.key_type) {
case BTM_LE_KEY_PENC: {
BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_PENC");
pairing_cb.ble.is_penc_key_rcvd = TRUE;
pairing_cb.ble.penc_key = p_data->ble_key.p_key_value->penc_key;
memcpy(&pairing_cb.ble.penc_key, &p_data->ble_key.p_key_value->penc_key,
btc_dm_cb.pairing_cb.ble.is_penc_key_rcvd = TRUE;
btc_dm_cb.pairing_cb.ble.penc_key = p_data->ble_key.p_key_value->penc_key;
memcpy(&btc_dm_cb.pairing_cb.ble.penc_key, &p_data->ble_key.p_key_value->penc_key,
sizeof(tBTM_LE_PENC_KEYS));
memcpy(&param.ble_security.ble_key.p_key_value.penc_key,
&p_data->ble_key.p_key_value->penc_key, sizeof(tBTM_LE_PENC_KEYS));
@ -703,8 +708,8 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
}
case BTM_LE_KEY_PID: {
BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_PID");
pairing_cb.ble.is_pid_key_rcvd = TRUE;
memcpy(&pairing_cb.ble.pid_key, &p_data->ble_key.p_key_value->pid_key,
btc_dm_cb.pairing_cb.ble.is_pid_key_rcvd = TRUE;
memcpy(&btc_dm_cb.pairing_cb.ble.pid_key, &p_data->ble_key.p_key_value->pid_key,
sizeof(tBTM_LE_PID_KEYS));
memcpy(&param.ble_security.ble_key.p_key_value.pid_key,
&p_data->ble_key.p_key_value->pid_key, sizeof(tBTM_LE_PID_KEYS));
@ -712,8 +717,8 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
}
case BTM_LE_KEY_PCSRK: {
BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_PCSRK");
pairing_cb.ble.is_pcsrk_key_rcvd = TRUE;
memcpy(&pairing_cb.ble.pcsrk_key, &p_data->ble_key.p_key_value->pcsrk_key,
btc_dm_cb.pairing_cb.ble.is_pcsrk_key_rcvd = TRUE;
memcpy(&btc_dm_cb.pairing_cb.ble.pcsrk_key, &p_data->ble_key.p_key_value->pcsrk_key,
sizeof(tBTM_LE_PCSRK_KEYS));
memcpy(&param.ble_security.ble_key.p_key_value.pcsrk_key,
&p_data->ble_key.p_key_value->pcsrk_key, sizeof(tBTM_LE_PCSRK_KEYS));
@ -721,8 +726,8 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
}
case BTM_LE_KEY_LENC: {
BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_LENC");
pairing_cb.ble.is_lenc_key_rcvd = TRUE;
memcpy(&pairing_cb.ble.lenc_key, &p_data->ble_key.p_key_value->lenc_key,
btc_dm_cb.pairing_cb.ble.is_lenc_key_rcvd = TRUE;
memcpy(&btc_dm_cb.pairing_cb.ble.lenc_key, &p_data->ble_key.p_key_value->lenc_key,
sizeof(tBTM_LE_LENC_KEYS));
memcpy(&param.ble_security.ble_key.p_key_value.lenc_key,
&p_data->ble_key.p_key_value->lenc_key, sizeof(tBTM_LE_LENC_KEYS));
@ -730,8 +735,8 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
}
case BTM_LE_KEY_LCSRK: {
BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_LCSRK");
pairing_cb.ble.is_lcsrk_key_rcvd = TRUE;
memcpy(&pairing_cb.ble.lcsrk_key, &p_data->ble_key.p_key_value->lcsrk_key,
btc_dm_cb.pairing_cb.ble.is_lcsrk_key_rcvd = TRUE;
memcpy(&btc_dm_cb.pairing_cb.ble.lcsrk_key, &p_data->ble_key.p_key_value->lcsrk_key,
sizeof(tBTM_LE_LCSRK_KEYS));
memcpy(&param.ble_security.ble_key.p_key_value.lcsrk_key,
&p_data->ble_key.p_key_value->lcsrk_key, sizeof(tBTM_LE_LCSRK_KEYS));
@ -739,7 +744,7 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
}
case BTM_LE_KEY_LID: {
BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_LID");
pairing_cb.ble.is_lidk_key_rcvd = TRUE;
btc_dm_cb.pairing_cb.ble.is_lidk_key_rcvd = TRUE;
break;
}
default:
@ -778,20 +783,20 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
ble_msg.act = ESP_GAP_BLE_LOCAL_IR_EVT;
memcpy(&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. ");
ble_local_key_cb.is_id_keys_rcvd = TRUE;
memcpy(&ble_local_key_cb.id_keys.irk[0],
btc_dm_cb.ble_local_key_cb.is_id_keys_rcvd = TRUE;
memcpy(&btc_dm_cb.ble_local_key_cb.id_keys.irk[0],
&p_data->ble_id_keys.irk[0], sizeof(BT_OCTET16));
memcpy(&ble_local_key_cb.id_keys.ir[0],
memcpy(&btc_dm_cb.ble_local_key_cb.id_keys.ir[0],
&p_data->ble_id_keys.ir[0], sizeof(BT_OCTET16));
memcpy(&ble_local_key_cb.id_keys.dhk[0],
memcpy(&btc_dm_cb.ble_local_key_cb.id_keys.dhk[0],
&p_data->ble_id_keys.dhk[0], sizeof(BT_OCTET16));
btc_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.irk[0],
btc_storage_add_ble_local_key( (char *)&btc_dm_cb.ble_local_key_cb.id_keys.irk[0],
BTC_LE_LOCAL_KEY_IRK,
BT_OCTET16_LEN);
btc_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.ir[0],
btc_storage_add_ble_local_key( (char *)&btc_dm_cb.ble_local_key_cb.id_keys.ir[0],
BTC_LE_LOCAL_KEY_IR,
BT_OCTET16_LEN);
btc_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.dhk[0],
btc_storage_add_ble_local_key( (char *)&btc_dm_cb.ble_local_key_cb.id_keys.dhk[0],
BTC_LE_LOCAL_KEY_DHK,
BT_OCTET16_LEN);
break;
@ -801,9 +806,9 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
ble_msg.act = ESP_GAP_BLE_LOCAL_ER_EVT;
memcpy(&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. ");
ble_local_key_cb.is_er_rcvd = TRUE;
memcpy(&ble_local_key_cb.er[0], &p_data->ble_er[0], sizeof(BT_OCTET16));
btc_storage_add_ble_local_key( (char *)&ble_local_key_cb.er[0],
btc_dm_cb.ble_local_key_cb.is_er_rcvd = TRUE;
memcpy(&btc_dm_cb.ble_local_key_cb.er[0], &p_data->ble_er[0], sizeof(BT_OCTET16));
btc_storage_add_ble_local_key( (char *)&btc_dm_cb.ble_local_key_cb.er[0],
BTC_LE_LOCAL_KEY_ER,
BT_OCTET16_LEN);
break;

View File

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

View File

@ -19,7 +19,11 @@
#include "esp_bt_defs.h"
#include "esp_gatt_defs.h"
static void *btc_profile_cb_tab[BTC_PID_NUM] = {};
#if BTC_DYNAMIC_MENDRY == FALSE
void *btc_profile_cb_tab[BTC_PID_NUM] = {};
#else
void **btc_profile_cb_tab;
#endif
void esp_profile_cb_reset(void)
{

View File

@ -21,16 +21,18 @@
#include "common/bt_defs.h"
#include "osi/allocator.h"
#include "btc/btc_main.h"
#include "btc/btc_manage.h"
#include "btc/btc_dev.h"
#include "btc_gatts.h"
#include "btc_gattc.h"
#include "btc_gatt_common.h"
#include "btc_gap_ble.h"
#include "btc_blufi_prf.h"
#include "blufi_int.h"
#include "btc/btc_dm.h"
#include "btc/btc_alarm.h"
#include "bta/bta_gatt_api.h"
#if CONFIG_BT_CLASSIC_ENABLED
#if CLASSIC_BT_INCLUDED
#include "btc/btc_profile_queue.h"
#if (BTC_GAP_BT_INCLUDED == TRUE)
#include "btc_gap_bt.h"
@ -38,20 +40,24 @@
#if BTC_AV_INCLUDED
#include "btc_av.h"
#include "btc_avrc.h"
#include "btc_av_co.h"
#endif /* #if BTC_AV_INCLUDED */
#if CONFIG_BT_SPP_ENABLED
#if (BTC_SPP_INCLUDED == TRUE)
#include "btc_spp.h"
#endif /* #if CONFIG_BT_SPP_ENABLED */
#endif /* #if (BTC_SPP_INCLUDED == TRUE) */
#if BTC_HF_CLIENT_INCLUDED
#include "btc_hf_client.h"
#endif /* #if BTC_HF_CLIENT_INCLUDED */
#endif /* #if CONFIG_BT_CLASSIC_ENABLED */
#endif /* #if CLASSIC_BT_INCLUDED */
#define BTC_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE)
#define BTC_TASK_STACK_SIZE (BT_BTC_TASK_STACK_SIZE + BT_TASK_EXTRA_STACK_SIZE) //by menuconfig
#define BTC_TASK_NAME "btcT"
#define BTC_TASK_PRIO (BT_TASK_MAX_PRIORITIES - 6)
static xTaskHandle xBtcTaskHandle = NULL;
static xQueueHandle xBtcQueue = 0;
osi_thread_t *btc_thread;
static btc_func_t profile_tab[BTC_PID_NUM] = {
static const btc_func_t profile_tab[BTC_PID_NUM] = {
[BTC_PID_MAIN_INIT] = {btc_main_call_handler, NULL },
[BTC_PID_DEV] = {btc_dev_call_handler, NULL },
#if (GATTS_INCLUDED == TRUE)
@ -63,7 +69,11 @@ static btc_func_t profile_tab[BTC_PID_NUM] = {
#if (GATTS_INCLUDED == TRUE || GATTC_INCLUDED == TRUE)
[BTC_PID_GATT_COMMON] = {btc_gatt_com_call_handler, NULL },
#endif //GATTC_INCLUDED == TRUE || GATTS_INCLUDED == TRUE
#if (BLE_INCLUDED == TRUE)
[BTC_PID_GAP_BLE] = {btc_gap_ble_call_handler, btc_gap_ble_cb_handler },
#else
[BTC_PID_GAP_BLE] = {NULL, NULL},
#endif ///BLE_INCLUDED == TRUE
[BTC_PID_BLE_HID] = {NULL, NULL},
[BTC_PID_SPPLIKE] = {NULL, NULL},
#if (GATTS_INCLUDED == TRUE)
@ -71,7 +81,7 @@ static btc_func_t profile_tab[BTC_PID_NUM] = {
#endif ///GATTS_INCLUDED == TRUE
[BTC_PID_DM_SEC] = {NULL, btc_dm_sec_cb_handler },
[BTC_PID_ALARM] = {btc_alarm_handler, NULL },
#if CONFIG_BT_CLASSIC_ENABLED
#if CLASSIC_BT_INCLUDED
#if (BTC_GAP_BT_INCLUDED == TRUE)
[BTC_PID_GAP_BT] = {btc_gap_bt_call_handler, btc_gap_bt_cb_handler },
#endif /* (BTC_GAP_BT_INCLUDED == TRUE) */
@ -81,13 +91,13 @@ static btc_func_t profile_tab[BTC_PID_NUM] = {
[BTC_PID_AVRC_CT] = {btc_avrc_ct_call_handler, NULL },
[BTC_PID_AVRC_TG] = {btc_avrc_tg_call_handler, NULL },
#endif /* #if BTC_AV_INCLUDED */
#if CONFIG_BT_SPP_ENABLED
#if (BTC_SPP_INCLUDED == TRUE)
[BTC_PID_SPP] = {btc_spp_call_handler, btc_spp_cb_handler },
#endif /* #if CONFIG_BT_SPP_ENABLED */
#endif /* #if (BTC_SPP_INCLUDED == TRUE) */
#if BTC_HF_CLIENT_INCLUDED
[BTC_PID_HF_CLIENT] = {btc_hf_client_call_handler, btc_hf_client_cb_handler},
#endif /* #if BTC_HF_CLIENT_INCLUDED */
#endif /* #if CONFIG_BT_CLASSIC_ENABLED */
#endif /* #if CLASSIC_BT_INCLUDED */
};
/*****************************************************************************
@ -96,38 +106,40 @@ static btc_func_t profile_tab[BTC_PID_NUM] = {
**
** Description Process profile Task Thread.
******************************************************************************/
static void btc_task(void *arg)
static void btc_thread_handler(void *arg)
{
btc_msg_t msg;
btc_msg_t *msg = (btc_msg_t *)arg;
for (;;) {
if (pdTRUE == xQueueReceive(xBtcQueue, &msg, (portTickType)portMAX_DELAY)) {
BTC_TRACE_DEBUG("%s msg %u %u %u %p\n", __func__, msg.sig, msg.pid, msg.act, msg.arg);
switch (msg.sig) {
BTC_TRACE_DEBUG("%s msg %u %u %u %p\n", __func__, msg->sig, msg->pid, msg->act, msg->arg);
switch (msg->sig) {
case BTC_SIG_API_CALL:
profile_tab[msg.pid].btc_call(&msg);
profile_tab[msg->pid].btc_call(msg);
break;
case BTC_SIG_API_CB:
profile_tab[msg.pid].btc_cb(&msg);
profile_tab[msg->pid].btc_cb(msg);
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) {
return BT_STATUS_PARM_INVALID;
btc_msg_t *lmsg;
lmsg = (btc_msg_t *)osi_malloc(sizeof(btc_msg_t));
if (lmsg == NULL) {
return BT_STATUS_NOMEM;
}
if (xQueueSend(xBtcQueue, msg, timeout) != pdTRUE) {
BTC_TRACE_ERROR("Btc Post failed\n");
memcpy(lmsg, msg, sizeof(btc_msg_t));
if (osi_thread_post(btc_thread, btc_thread_handler, lmsg, 2, timeout) == false) {
return BT_STATUS_BUSY;
}
@ -159,18 +171,144 @@ bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg
lmsg.arg = NULL;
}
return btc_task_post(&lmsg, TASK_POST_BLOCKING);
return btc_task_post(&lmsg, OSI_THREAD_MAX_TIMEOUT);
}
#if BTC_DYNAMIC_MENDRY
static void btc_deinit_mem(void) {
if (btc_dm_cb_ptr) {
osi_free(btc_dm_cb_ptr);
btc_dm_cb_ptr = NULL;
}
if (btc_profile_cb_tab) {
osi_free(btc_profile_cb_tab);
btc_profile_cb_tab = NULL;
}
#if (BLE_INCLUDED == TRUE)
if (gl_bta_adv_data_ptr) {
osi_free(gl_bta_adv_data_ptr);
gl_bta_adv_data_ptr = NULL;
}
if (gl_bta_scan_rsp_data_ptr) {
osi_free(gl_bta_scan_rsp_data_ptr);
gl_bta_scan_rsp_data_ptr = NULL;
}
#endif ///BLE_INCLUDED == TRUE
#if GATTS_INCLUDED == TRUE && GATT_DYNAMIC_MEMORY == TRUE
if (btc_creat_tab_env_ptr) {
osi_free(btc_creat_tab_env_ptr);
btc_creat_tab_env_ptr = NULL;
}
if (blufi_env_ptr) {
osi_free(blufi_env_ptr);
blufi_env_ptr = NULL;
}
#endif
#if BTC_HF_CLIENT_INCLUDED == TRUE && HFP_DYNAMIC_MEMORY == TRUE
if (hf_client_local_param_ptr) {
osi_free(hf_client_local_param_ptr);
hf_client_local_param_ptr = NULL;
}
#endif
#if BTC_AV_INCLUDED == TRUE && AVRC_DYNAMIC_MEMORY == TRUE
if (btc_rc_cb_ptr) {
osi_free(btc_rc_cb_ptr);
btc_rc_cb_ptr = NULL;
}
if (bta_av_co_cb_ptr) {
osi_free(bta_av_co_cb_ptr);
bta_av_co_cb_ptr = NULL;
}
#endif
}
static bt_status_t btc_init_mem(void) {
if ((btc_dm_cb_ptr = (btc_dm_cb_t *)osi_malloc(sizeof(btc_dm_cb_t))) == NULL) {
goto error_exit;
}
memset((void *)btc_dm_cb_ptr, 0, sizeof(btc_dm_cb_t));
if ((btc_profile_cb_tab = (void **)osi_malloc(sizeof(void *) * BTC_PID_NUM)) == NULL) {
goto error_exit;
}
memset((void *)btc_profile_cb_tab, 0, sizeof(void *) * BTC_PID_NUM);
#if (BLE_INCLUDED == TRUE)
if ((gl_bta_adv_data_ptr = (tBTA_BLE_ADV_DATA *)osi_malloc(sizeof(tBTA_BLE_ADV_DATA))) == NULL) {
goto error_exit;
}
memset((void *)gl_bta_adv_data_ptr, 0, sizeof(tBTA_BLE_ADV_DATA));
if ((gl_bta_scan_rsp_data_ptr = (tBTA_BLE_ADV_DATA *)osi_malloc(sizeof(tBTA_BLE_ADV_DATA))) == NULL) {
goto error_exit;
}
memset((void *)gl_bta_scan_rsp_data_ptr, 0, sizeof(tBTA_BLE_ADV_DATA));
#endif ///BLE_INCLUDED == TRUE
#if GATTS_INCLUDED == TRUE && GATT_DYNAMIC_MEMORY == TRUE
if ((btc_creat_tab_env_ptr = (esp_btc_creat_tab_t *)osi_malloc(sizeof(esp_btc_creat_tab_t))) == NULL) {
goto error_exit;
}
memset((void *)btc_creat_tab_env_ptr, 0, sizeof(esp_btc_creat_tab_t));
if ((blufi_env_ptr = (tBLUFI_ENV *)osi_malloc(sizeof(tBLUFI_ENV))) == NULL) {
goto error_exit;
}
memset((void *)blufi_env_ptr, 0, sizeof(tBLUFI_ENV));
#endif
#if BTC_HF_CLIENT_INCLUDED == TRUE && HFP_DYNAMIC_MEMORY == TRUE
if ((hf_client_local_param_ptr = (hf_client_local_param_t *)osi_malloc(sizeof(hf_client_local_param_t))) == NULL) {
goto error_exit;
}
memset((void *)hf_client_local_param_ptr, 0, sizeof(hf_client_local_param_t));
#endif
#if BTC_AV_INCLUDED == TRUE && AVRC_DYNAMIC_MEMORY == TRUE
if ((btc_rc_cb_ptr = (btc_rc_cb_t *)osi_malloc(sizeof(btc_rc_cb_t))) == NULL) {
goto error_exit;
}
memset((void *)btc_rc_cb_ptr, 0, sizeof(btc_rc_cb_t));
if ((bta_av_co_cb_ptr = (tBTA_AV_CO_CB *)osi_malloc(sizeof(tBTA_AV_CO_CB))) == NULL) {
goto error_exit;
}
memset((void *)bta_av_co_cb_ptr, 0, sizeof(tBTA_AV_CO_CB));
#endif
return BT_STATUS_SUCCESS;
error_exit:;
btc_deinit_mem();
return BT_STATUS_NOMEM;
}
#endif ///BTC_DYNAMIC_MENDRY
int btc_init(void)
{
xBtcQueue = xQueueCreate(BTC_TASK_QUEUE_LEN, sizeof(btc_msg_t));
xTaskCreatePinnedToCore(btc_task, "Btc_task", BTC_TASK_STACK_SIZE, NULL, BTC_TASK_PRIO, &xBtcTaskHandle, BTC_TASK_PINNED_TO_CORE);
if (xBtcTaskHandle == NULL || xBtcQueue == 0){
btc_thread = osi_thread_create("BTC_TASK", BTC_TASK_STACK_SIZE, BTC_TASK_PRIO, BTC_TASK_PINNED_TO_CORE, 3);
if (btc_thread == NULL) {
return BT_STATUS_NOMEM;
}
#if BTC_DYNAMIC_MENDRY
if (btc_init_mem() != BT_STATUS_SUCCESS){
return BT_STATUS_NOMEM;
}
#endif
#if (BLE_INCLUDED == TRUE)
btc_gap_callback_init();
#endif ///BLE_INCLUDED == TRUE
#if SCAN_QUEUE_CONGEST_CHECK
btc_adv_list_init();
#endif
@ -180,20 +318,23 @@ int btc_init(void)
void btc_deinit(void)
{
vTaskDelete(xBtcTaskHandle);
vQueueDelete(xBtcQueue);
#if BTC_DYNAMIC_MENDRY
btc_deinit_mem();
#endif
osi_thread_free(btc_thread);
btc_thread = NULL;
#if SCAN_QUEUE_CONGEST_CHECK
btc_adv_list_deinit();
#endif
xBtcTaskHandle = NULL;
xBtcQueue = 0;
}
bool btc_check_queue_is_congest(void)
{
UBaseType_t wait_size = uxQueueMessagesWaiting(xBtcQueue);
if(wait_size >= QUEUE_CONGEST_SIZE) {
if (osi_thread_queue_wait_size(btc_thread, 2) >= QUEUE_CONGEST_SIZE) {
return true;
}
return false;
}

View File

@ -66,7 +66,21 @@ typedef struct
btc_dm_local_key_id_t id_keys; /* ID kyes */
} btc_dm_local_key_cb_t;
typedef struct
{
tBTA_SERVICE_MASK btc_enabled_services;
#if (SMP_INCLUDED == TRUE)
btc_dm_pairing_cb_t pairing_cb;
btc_dm_local_key_cb_t ble_local_key_cb;
#endif
} btc_dm_cb_t;
#if BTC_DYNAMIC_MENDRY == FALSE
extern btc_dm_cb_t btc_dm_cb;
#else
extern btc_dm_cb_t *btc_dm_cb_ptr;
#define btc_dm_cb (*btc_dm_cb_ptr)
#endif
// void btc_dm_call_handler(btc_msg_t *msg);
void btc_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *data);

View File

@ -19,6 +19,11 @@
#include "btc/btc_task.h"
#include "esp_bt_defs.h"
#if BTC_DYNAMIC_MENDRY == FALSE
extern void *btc_profile_cb_tab[BTC_PID_NUM];
#else
extern void **btc_profile_cb_tab;
#endif
/* reset gatt callback table */
void esp_profile_cb_reset(void);

View File

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

View File

@ -55,13 +55,17 @@
#define BLUFI_HDL_NUM 6
#if GATT_DYNAMIC_MEMORY == FALSE
tBLUFI_ENV blufi_env;
#else
tBLUFI_ENV *blufi_env_ptr;
#endif
static /* const */ tBT_UUID blufi_srvc_uuid = {LEN_UUID_16, {BLUFI_SERVICE_UUID}};
static /* const */ tBT_UUID blufi_char_uuid_p2e = {LEN_UUID_16, {BLUFI_CHAR_P2E_UUID}};
static /* const */ tBT_UUID blufi_char_uuid_e2p = {LEN_UUID_16, {BLUFI_CHAR_E2P_UUID}};
static /* const */ tBT_UUID blufi_descr_uuid_e2p = {LEN_UUID_16, {BLUFI_DESCR_E2P_UUID}};
static /* const */ tBT_UUID blufi_app_uuid = {LEN_UUID_16, {BLUFI_APP_UUID}};
static const tBT_UUID blufi_srvc_uuid = {LEN_UUID_16, {BLUFI_SERVICE_UUID}};
static const tBT_UUID blufi_char_uuid_p2e = {LEN_UUID_16, {BLUFI_CHAR_P2E_UUID}};
static const tBT_UUID blufi_char_uuid_e2p = {LEN_UUID_16, {BLUFI_CHAR_E2P_UUID}};
static const tBT_UUID blufi_descr_uuid_e2p = {LEN_UUID_16, {BLUFI_DESCR_E2P_UUID}};
static const tBT_UUID blufi_app_uuid = {LEN_UUID_16, {BLUFI_APP_UUID}};
// static functions declare
static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data);

View File

@ -36,7 +36,7 @@
//#include "esp_wifi.h"
#if (GATTS_INCLUDED == TRUE)
extern tBLUFI_ENV blufi_env;
// extern tBLUFI_ENV blufi_env;
void btc_blufi_protocol_handler(uint8_t type, uint8_t *data, int len)
{

View File

@ -68,6 +68,13 @@ struct blufi_frag_hdr {
};
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_ENC_MASK 0x02
#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 */
};
/*****************************************************************************
** Local data
*****************************************************************************/
typedef struct {
UINT8 sep_info_idx; /* local SEP index (in BTA tables) */
UINT8 seid; /* peer SEP index (in peer tables) */
UINT8 codec_type; /* peer SEP codec type */
UINT8 codec_caps[AVDT_CODEC_SIZE]; /* peer SEP codec capabilities */
UINT8 num_protect; /* peer SEP number of CP elements */
UINT8 protect_info[BTA_AV_CP_INFO_LEN]; /* peer SEP content protection info */
} tBTA_AV_CO_SINK;
typedef struct {
BD_ADDR addr; /* address of audio/video peer */
tBTA_AV_CO_SINK snks[BTC_SV_AV_AA_SEP_INDEX]; /* array of supported sinks */
tBTA_AV_CO_SINK srcs[BTC_SV_AV_AA_SEP_INDEX]; /* array of supported srcs */
UINT8 num_snks; /* total number of sinks at peer */
UINT8 num_srcs; /* total number of srcs at peer */
UINT8 num_seps; /* total number of seids at peer */
UINT8 num_rx_snks; /* number of received sinks */
UINT8 num_rx_srcs; /* number of received srcs */
UINT8 num_sup_snks; /* number of supported sinks in the snks array */
UINT8 num_sup_srcs; /* number of supported srcs in the srcs array */
tBTA_AV_CO_SINK *p_snk; /* currently selected sink */
tBTA_AV_CO_SINK *p_src; /* currently selected src */
UINT8 codec_cfg[AVDT_CODEC_SIZE]; /* current codec configuration */
BOOLEAN cp_active; /* current CP configuration */
BOOLEAN acp; /* acceptor */
BOOLEAN recfg_needed; /* reconfiguration is needed */
BOOLEAN opened; /* opened */
UINT16 mtu; /* maximum transmit unit size */
UINT16 uuid_to_connect; /* uuid of peer device */
} tBTA_AV_CO_PEER;
typedef struct {
BOOLEAN active;
UINT8 flag;
} tBTA_AV_CO_CP;
typedef struct {
/* Connected peer information */
tBTA_AV_CO_PEER peers[BTA_AV_NUM_STRS];
/* Current codec configuration - access to this variable must be protected */
tBTC_AV_CODEC_INFO codec_cfg;
tBTC_AV_CODEC_INFO codec_cfg_setconfig; /* remote peer setconfig preference */
tBTA_AV_CO_CP cp;
} tBTA_AV_CO_CB;
/* Control block instance */
static tBTA_AV_CO_CB bta_av_co_cb;
#if AVRC_DYNAMIC_MEMORY == FALSE
tBTA_AV_CO_CB bta_av_co_cb;
#else
tBTA_AV_CO_CB *bta_av_co_cb_ptr;
#endif
static BOOLEAN bta_av_co_audio_codec_build_config(const UINT8 *p_codec_caps, UINT8 *p_codec_cfg);
static void bta_av_co_audio_peer_reset_config(tBTA_AV_CO_PEER *p_peer);
@ -1735,7 +1689,7 @@ BOOLEAN bta_av_co_get_remote_bitpool_pref(UINT8 *min, UINT8 *max)
}
/* the call out functions for audio stream */
tBTA_AV_CO_FUNCTS bta_av_a2d_cos = {
const tBTA_AV_CO_FUNCTS bta_av_a2d_cos = {
bta_av_co_audio_init,
bta_av_co_audio_disc_res,
bta_av_co_audio_getconfig,

View File

@ -45,6 +45,8 @@
#if (BTC_AV_SINK_INCLUDED == TRUE)
extern osi_thread_t *btc_thread;
/*****************************************************************************
** Constants
*****************************************************************************/
@ -64,10 +66,6 @@ enum {
BTC_A2DP_SINK_STATE_SHUTTING_DOWN = 2
};
enum {
BTC_A2DP_SINK_DATA_EVT = 0,
};
/*
* CONGESTION COMPENSATION CTRL ::
*
@ -90,6 +88,11 @@ enum {
/* 18 frames is equivalent to 6.89*18*2.9 ~= 360 ms @ 44.1 khz, 20 ms mediatick */
#define MAX_OUTPUT_A2DP_SNK_FRAME_QUEUE_SZ (18)
typedef struct {
uint32_t sig;
void *param;
} a2dp_sink_task_evt_t;
typedef struct {
UINT16 num_frames_to_be_processed;
UINT16 len;
@ -104,6 +107,15 @@ typedef struct {
UINT32 sample_rate;
} tBTC_A2DP_SINK_CB;
typedef struct {
tBTC_A2DP_SINK_CB btc_aa_snk_cb;
future_t *btc_a2dp_sink_future;
osi_thread_t *btc_aa_snk_task_hdl;
OI_CODEC_SBC_DECODER_CONTEXT context;
OI_UINT32 contextData[CODEC_DATA_WORDS(2, SBC_CODEC_FAST_FILTER_BUFFERS)];
OI_INT16 pcmData[15 * SBC_MAX_SAMPLES_PER_FRAME * SBC_MAX_CHANNELS];
} a2dp_sink_local_param_t;
static void btc_a2dp_sink_thread_init(UNUSED_ATTR void *context);
static void btc_a2dp_sink_thread_cleanup(UNUSED_ATTR void *context);
static void btc_a2dp_sink_flush_q(fixed_queue_t *p_q);
@ -115,19 +127,19 @@ static void btc_a2dp_sink_handle_inc_media(tBT_SBC_HDR *p_msg);
static void btc_a2dp_sink_handle_decoder_reset(tBTC_MEDIA_SINK_CFG_UPDATE *p_msg);
static void btc_a2dp_sink_handle_clear_track(void);
static BOOLEAN btc_a2dp_sink_clear_track(void);
static void btc_a2dp_sink_task_handler(void *arg);
static void btc_a2dp_sink_data_ready(UNUSED_ATTR void *context);
static void btc_a2dp_sink_ctrl_handler(void *arg);
static void btc_a2dp_sink_data_ready(void *context);
static tBTC_A2DP_SINK_CB btc_aa_snk_cb;
static int btc_a2dp_sink_state = BTC_A2DP_SINK_STATE_OFF;
static future_t *btc_a2dp_sink_future = NULL;
static xTaskHandle btc_aa_snk_task_hdl = NULL;
static QueueHandle_t btc_aa_snk_data_queue = NULL;
static QueueHandle_t btc_aa_snk_ctrl_queue = NULL;
static QueueSetHandle_t btc_aa_snk_queue_set;
static esp_a2d_sink_data_cb_t bt_aa_snk_data_cb = NULL;
#if A2D_DYNAMIC_MEMORY == FALSE
static a2dp_sink_local_param_t a2dp_sink_local_param;
#else
static a2dp_sink_local_param_t *a2dp_sink_local_param_ptr;
#define a2dp_sink_local_param (*a2dp_sink_local_param_ptr)
#endif ///A2D_DYNAMIC_MEMORY == FALSE
void btc_a2dp_sink_reg_data_cb(esp_a2d_sink_data_cb_t callback)
{
@ -143,21 +155,6 @@ static inline void btc_a2d_data_cb_to_app(const uint8_t *data, uint32_t len)
}
}
#define BTC_SBC_DEC_CONTEXT_DATA_LEN (CODEC_DATA_WORDS(2, SBC_CODEC_FAST_FILTER_BUFFERS))
#define BTC_SBC_DEC_PCM_DATA_LEN (15 * SBC_MAX_SAMPLES_PER_FRAME * SBC_MAX_CHANNELS)
#if BTC_SBC_DEC_DYNAMIC_MEMORY == FALSE
static OI_CODEC_SBC_DECODER_CONTEXT btc_sbc_decoder_context;
static OI_UINT32 btc_sbc_decoder_context_data[BTC_SBC_DEC_CONTEXT_DATA_LEN];
static OI_INT16 btc_sbc_pcm_data[BTC_SBC_DEC_PCM_DATA_LEN];
#else
static OI_CODEC_SBC_DECODER_CONTEXT *btc_sbc_decoder_context_ptr;
static OI_UINT32 *btc_sbc_decoder_context_data;
static OI_INT16 *btc_sbc_pcm_data;
#define btc_sbc_decoder_context (*btc_sbc_decoder_context_ptr)
#endif /* BTC_SBC_DEC_DYNAMIC_MEMORY == FALSE */
/*****************************************************************************
** Misc helper functions
@ -174,26 +171,28 @@ static inline void btc_a2d_cb_to_app(esp_a2d_cb_event_t event, esp_a2d_cb_param_
** BTC ADAPTATION
*****************************************************************************/
static void btc_a2dp_sink_ctrl_post(uint32_t sig, void *par)
static bool btc_a2dp_sink_ctrl_post(uint32_t sig, void *param)
{
BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t));
a2dp_sink_task_evt_t *evt = (a2dp_sink_task_evt_t *)osi_malloc(sizeof(a2dp_sink_task_evt_t));
if (evt == NULL) {
return;
return false;
}
evt->sig = sig;
evt->par = par;
evt->param = param;
if (xQueueSend(btc_aa_snk_ctrl_queue, &evt, portMAX_DELAY) != pdTRUE) {
APPL_TRACE_WARNING("btc_aa_snk_ctrl_queue failed, sig 0x%x\n", sig);
}
return osi_thread_post(a2dp_sink_local_param.btc_aa_snk_task_hdl, btc_a2dp_sink_ctrl_handler, evt, 0, OSI_THREAD_MAX_TIMEOUT);
}
static void btc_a2dp_sink_ctrl_handler(BtTaskEvt_t *e)
static void btc_a2dp_sink_ctrl_handler(void *arg)
{
a2dp_sink_task_evt_t *e = (a2dp_sink_task_evt_t *)arg;
if (e == NULL) {
return;
}
switch (e->sig) {
case BTC_MEDIA_TASK_SINK_INIT:
btc_a2dp_sink_thread_init(NULL);
@ -202,7 +201,7 @@ static void btc_a2dp_sink_ctrl_handler(BtTaskEvt_t *e)
btc_a2dp_sink_thread_cleanup(NULL);
break;
case BTC_MEDIA_AUDIO_SINK_CFG_UPDATE:
btc_a2dp_sink_handle_decoder_reset(e->par);
btc_a2dp_sink_handle_decoder_reset(e->param);
break;
case BTC_MEDIA_AUDIO_SINK_CLEAR_TRACK:
btc_a2dp_sink_handle_clear_track();
@ -213,29 +212,12 @@ static void btc_a2dp_sink_ctrl_handler(BtTaskEvt_t *e)
default:
APPL_TRACE_WARNING("media task unhandled evt: 0x%x\n", e->sig);
}
if (e->par != NULL) {
osi_free(e->par);
}
}
static void btc_a2dp_sink_task_handler(void *arg)
{
QueueSetMemberHandle_t xActivatedMember;
BtTaskEvt_t *e = NULL;
for (;;) {
xActivatedMember = xQueueSelectFromSet(btc_aa_snk_queue_set, portMAX_DELAY);
if (xActivatedMember == btc_aa_snk_data_queue) {
int32_t data_evt;
xQueueReceive(xActivatedMember, &data_evt, 0);
if (data_evt == BTC_A2DP_SINK_DATA_EVT) {
btc_a2dp_sink_data_ready(NULL);
if (e->param != NULL) {
osi_free(e->param);
}
} else if (xActivatedMember == btc_aa_snk_ctrl_queue) {
xQueueReceive(xActivatedMember, &e, 0);
btc_a2dp_sink_ctrl_handler(e);
osi_free(e);
}
}
}
bool btc_a2dp_sink_startup(void)
@ -245,38 +227,21 @@ bool btc_a2dp_sink_startup(void)
return false;
}
#if A2D_DYNAMIC_MEMORY == TRUE
if ((a2dp_sink_local_param_ptr = (a2dp_sink_local_param_t *)osi_malloc(sizeof(a2dp_sink_local_param_t))) == NULL) {
APPL_TRACE_ERROR("%s malloc failed!", __func__);
return false;
}
memset((void *)a2dp_sink_local_param_ptr, 0, sizeof(a2dp_sink_local_param_t));
#endif
APPL_TRACE_EVENT("## A2DP SINK START MEDIA THREAD ##");
#if (BTC_SBC_DEC_DYNAMIC_MEMORY == TRUE)
btc_sbc_decoder_context_ptr = osi_calloc(sizeof(OI_CODEC_SBC_DECODER_CONTEXT));
btc_sbc_decoder_context_data = osi_calloc(BTC_SBC_DEC_CONTEXT_DATA_LEN * sizeof(OI_UINT32));
btc_sbc_pcm_data = osi_calloc(BTC_SBC_DEC_PCM_DATA_LEN * sizeof(OI_INT16));
if (!btc_sbc_decoder_context_ptr || !btc_sbc_decoder_context_data || !btc_sbc_pcm_data) {
APPL_TRACE_ERROR("failed to allocate SBC decoder");
a2dp_sink_local_param.btc_aa_snk_task_hdl = btc_thread;
if (btc_a2dp_sink_ctrl_post(BTC_MEDIA_TASK_SINK_INIT, NULL) == false) {
goto error_exit;
}
#endif /* BTC_SBC_DEC_DYNAMIC_MEMORY == TRUE */
btc_aa_snk_queue_set = xQueueCreateSet(BTC_A2DP_SINK_TASK_QUEUE_SET_LEN);
configASSERT(btc_aa_snk_queue_set);
btc_aa_snk_data_queue = xQueueCreate(BTC_A2DP_SINK_DATA_QUEUE_LEN, sizeof(int32_t));
configASSERT(btc_aa_snk_data_queue);
xQueueAddToSet(btc_aa_snk_data_queue, btc_aa_snk_queue_set);
btc_aa_snk_ctrl_queue = xQueueCreate(BTC_A2DP_SINK_CTRL_QUEUE_LEN, sizeof(void *));
configASSERT(btc_aa_snk_ctrl_queue);
xQueueAddToSet(btc_aa_snk_ctrl_queue, btc_aa_snk_queue_set);
if (!btc_aa_snk_data_queue || !btc_aa_snk_ctrl_queue || !btc_aa_snk_queue_set ) {
goto error_exit;
}
xTaskCreatePinnedToCore(btc_a2dp_sink_task_handler, BTC_A2DP_SINK_TASK_NAME, BTC_A2DP_SINK_TASK_STACK_SIZE, NULL, BTC_A2DP_SINK_TASK_PRIO, &btc_aa_snk_task_hdl, BTC_A2DP_SINK_TASK_PINNED_TO_CORE);
if (btc_aa_snk_task_hdl == NULL) {
goto error_exit;
}
btc_a2dp_sink_ctrl_post(BTC_MEDIA_TASK_SINK_INIT, NULL);
APPL_TRACE_EVENT("## A2DP SINK MEDIA THREAD STARTED ##\n");
@ -284,38 +249,12 @@ bool btc_a2dp_sink_startup(void)
error_exit:;
APPL_TRACE_ERROR("%s unable to start up media thread\n", __func__);
a2dp_sink_local_param.btc_aa_snk_task_hdl = NULL;
if (btc_aa_snk_task_hdl != NULL) {
vTaskDelete(btc_aa_snk_task_hdl);
btc_aa_snk_task_hdl = NULL;
}
if (btc_aa_snk_data_queue) {
vQueueDelete(btc_aa_snk_data_queue);
btc_aa_snk_data_queue = NULL;
}
if (btc_aa_snk_ctrl_queue) {
vQueueDelete(btc_aa_snk_ctrl_queue);
btc_aa_snk_ctrl_queue = NULL;
}
if (btc_aa_snk_queue_set) {
vQueueDelete(btc_aa_snk_queue_set);
btc_aa_snk_queue_set = NULL;
}
#if (BTC_SBC_DEC_DYNAMIC_MEMORY == TRUE)
if (btc_sbc_decoder_context_ptr) {
osi_free(btc_sbc_decoder_context_ptr);
btc_sbc_decoder_context_ptr = NULL;
}
if (btc_sbc_decoder_context_data) {
osi_free(btc_sbc_decoder_context_data);
btc_sbc_decoder_context_data = NULL;
}
if (btc_sbc_pcm_data) {
osi_free(btc_sbc_pcm_data);
btc_sbc_pcm_data = NULL;
}
#endif /* BTC_SBC_DEC_DYNAMIC_MEMORY == TRUE */
#if A2D_DYNAMIC_MEMORY == TRUE
osi_free(a2dp_sink_local_param_ptr);
a2dp_sink_local_param_ptr = NULL;
#endif
return false;
}
@ -326,34 +265,18 @@ void btc_a2dp_sink_shutdown(void)
// Exit thread
btc_a2dp_sink_state = BTC_A2DP_SINK_STATE_SHUTTING_DOWN;
btc_a2dp_sink_future = future_new();
assert(btc_a2dp_sink_future);
a2dp_sink_local_param.btc_a2dp_sink_future = future_new();
assert(a2dp_sink_local_param.btc_a2dp_sink_future);
btc_a2dp_sink_ctrl_post(BTC_MEDIA_TASK_SINK_CLEAN_UP, NULL);
future_await(btc_a2dp_sink_future);
btc_a2dp_sink_future = NULL;
future_await(a2dp_sink_local_param.btc_a2dp_sink_future);
a2dp_sink_local_param.btc_a2dp_sink_future = NULL;
vTaskDelete(btc_aa_snk_task_hdl);
btc_aa_snk_task_hdl = NULL;
a2dp_sink_local_param.btc_aa_snk_task_hdl = NULL;
vQueueDelete(btc_aa_snk_data_queue);
btc_aa_snk_data_queue = NULL;
vQueueDelete(btc_aa_snk_ctrl_queue);
btc_aa_snk_ctrl_queue = NULL;
vQueueDelete(btc_aa_snk_queue_set);
btc_aa_snk_queue_set = NULL;
#if (BTC_SBC_DEC_DYNAMIC_MEMORY == TRUE)
osi_free(btc_sbc_decoder_context_ptr);
btc_sbc_decoder_context_ptr = NULL;
osi_free(btc_sbc_decoder_context_data);
btc_sbc_decoder_context_data = NULL;
osi_free(btc_sbc_pcm_data);
btc_sbc_pcm_data = NULL;
#endif /* BTC_SBC_DEC_DYNAMIC_MEMORY == TRUE */
#if A2D_DYNAMIC_MEMORY == TRUE
osi_free(a2dp_sink_local_param_ptr);
a2dp_sink_local_param_ptr = NULL;
#endif
}
/*****************************************************************************
@ -364,7 +287,7 @@ void btc_a2dp_sink_shutdown(void)
void btc_a2dp_sink_on_idle(void)
{
btc_aa_snk_cb.rx_flush = TRUE;
a2dp_sink_local_param.btc_aa_snk_cb.rx_flush = TRUE;
btc_a2dp_sink_rx_flush_req();
btc_a2dp_sink_clear_track();
@ -379,7 +302,7 @@ void btc_a2dp_sink_on_idle(void)
void btc_a2dp_sink_on_stopped(tBTA_AV_SUSPEND *p_av)
{
btc_aa_snk_cb.rx_flush = TRUE;
a2dp_sink_local_param.btc_aa_snk_cb.rx_flush = TRUE;
btc_a2dp_sink_rx_flush_req();
btc_a2dp_control_set_datachnl_stat(FALSE);
}
@ -392,16 +315,14 @@ void btc_a2dp_sink_on_stopped(tBTA_AV_SUSPEND *p_av)
void btc_a2dp_sink_on_suspended(tBTA_AV_SUSPEND *p_av)
{
btc_aa_snk_cb.rx_flush = TRUE;
a2dp_sink_local_param.btc_aa_snk_cb.rx_flush = TRUE;
btc_a2dp_sink_rx_flush_req();
return;
}
static void btc_a2dp_sink_data_post(int32_t data_type)
static void btc_a2dp_sink_data_post(void)
{
if (xQueueSend(btc_aa_snk_data_queue, &data_type, 0) != pdTRUE) {
APPL_TRACE_DEBUG("Media data Q filled\n");
}
osi_thread_post(a2dp_sink_local_param.btc_aa_snk_task_hdl, btc_a2dp_sink_data_ready, NULL, 1, OSI_THREAD_MAX_TIMEOUT);
}
/*******************************************************************************
@ -415,15 +336,14 @@ static void btc_a2dp_sink_data_post(int32_t data_type)
*******************************************************************************/
static BOOLEAN btc_a2dp_sink_clear_track(void)
{
btc_a2dp_sink_ctrl_post(BTC_MEDIA_AUDIO_SINK_CLEAR_TRACK, NULL);
return TRUE;
return btc_a2dp_sink_ctrl_post(BTC_MEDIA_AUDIO_SINK_CLEAR_TRACK, NULL);
}
/* when true media task discards any rx frames */
void btc_a2dp_sink_set_rx_flush(BOOLEAN enable)
{
APPL_TRACE_EVENT("## DROP RX %d ##\n", enable);
btc_aa_snk_cb.rx_flush = enable;
a2dp_sink_local_param.btc_aa_snk_cb.rx_flush = enable;
}
/*****************************************************************************
@ -457,20 +377,20 @@ static void btc_a2dp_sink_data_ready(UNUSED_ATTR void *context)
{
tBT_SBC_HDR *p_msg;
if (fixed_queue_is_empty(btc_aa_snk_cb.RxSbcQ)) {
if (fixed_queue_is_empty(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ)) {
APPL_TRACE_DEBUG(" QUE EMPTY ");
} else {
if (btc_aa_snk_cb.rx_flush == TRUE) {
btc_a2dp_sink_flush_q(btc_aa_snk_cb.RxSbcQ);
if (a2dp_sink_local_param.btc_aa_snk_cb.rx_flush == TRUE) {
btc_a2dp_sink_flush_q(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ);
return;
}
while ((p_msg = (tBT_SBC_HDR *)fixed_queue_try_peek_first(btc_aa_snk_cb.RxSbcQ)) != NULL ) {
while ((p_msg = (tBT_SBC_HDR *)fixed_queue_try_peek_first(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ)) != NULL ) {
if (btc_a2dp_sink_state != BTC_A2DP_SINK_STATE_ON){
return;
}
btc_a2dp_sink_handle_inc_media(p_msg);
p_msg = (tBT_SBC_HDR *)fixed_queue_try_dequeue(btc_aa_snk_cb.RxSbcQ);
p_msg = (tBT_SBC_HDR *)fixed_queue_dequeue(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ, 0);
if ( p_msg == NULL ) {
APPL_TRACE_ERROR("Insufficient data in que ");
break;
@ -510,13 +430,13 @@ static void btc_a2dp_sink_handle_decoder_reset(tBTC_MEDIA_SINK_CFG_UPDATE *p_msg
return;
}
btc_aa_snk_cb.sample_rate = btc_a2dp_sink_get_track_frequency(sbc_cie.samp_freq);
btc_aa_snk_cb.channel_count = btc_a2dp_sink_get_track_channel_count(sbc_cie.ch_mode);
a2dp_sink_local_param.btc_aa_snk_cb.sample_rate = btc_a2dp_sink_get_track_frequency(sbc_cie.samp_freq);
a2dp_sink_local_param.btc_aa_snk_cb.channel_count = btc_a2dp_sink_get_track_channel_count(sbc_cie.ch_mode);
btc_aa_snk_cb.rx_flush = FALSE;
a2dp_sink_local_param.btc_aa_snk_cb.rx_flush = FALSE;
APPL_TRACE_EVENT("Reset to sink role");
status = OI_CODEC_SBC_DecoderReset(&btc_sbc_decoder_context, btc_sbc_decoder_context_data,
BTC_SBC_DEC_CONTEXT_DATA_LEN * sizeof(OI_UINT32), 2, 2, FALSE, FALSE);
status = OI_CODEC_SBC_DecoderReset(&a2dp_sink_local_param.context, a2dp_sink_local_param.contextData,
sizeof(a2dp_sink_local_param.contextData), 2, 2, FALSE, FALSE);
if (!OI_SUCCESS(status)) {
APPL_TRACE_ERROR("OI_CODEC_SBC_DecoderReset failed with error code %d\n", status);
}
@ -632,14 +552,14 @@ static void btc_a2dp_sink_handle_inc_media(tBT_SBC_HDR *p_msg)
UINT8 *sbc_start_frame = ((UINT8 *)(p_msg + 1) + p_msg->offset + 1);
int count;
UINT32 pcmBytes, availPcmBytes;
OI_INT16 *pcmDataPointer = btc_sbc_pcm_data; /*Will be overwritten on next packet receipt*/
OI_INT16 *pcmDataPointer = a2dp_sink_local_param.pcmData; /*Will be overwritten on next packet receipt*/
OI_STATUS status;
int num_sbc_frames = p_msg->num_frames_to_be_processed;
UINT32 sbc_frame_len = p_msg->len - 1;
availPcmBytes = BTC_SBC_DEC_PCM_DATA_LEN * sizeof(OI_INT16);
availPcmBytes = sizeof(a2dp_sink_local_param.pcmData);
/* XXX: Check if the below check is correct, we are checking for peer to be sink when we are sink */
if (btc_av_get_peer_sep() == AVDT_TSEP_SNK || (btc_aa_snk_cb.rx_flush)) {
if (btc_av_get_peer_sep() == AVDT_TSEP_SNK || (a2dp_sink_local_param.btc_aa_snk_cb.rx_flush)) {
APPL_TRACE_DEBUG(" State Changed happened in this tick ");
return;
}
@ -653,7 +573,7 @@ static void btc_a2dp_sink_handle_inc_media(tBT_SBC_HDR *p_msg)
for (count = 0; count < num_sbc_frames && sbc_frame_len != 0; count ++) {
pcmBytes = availPcmBytes;
status = OI_CODEC_SBC_DecodeFrame(&btc_sbc_decoder_context, (const OI_BYTE **)&sbc_start_frame,
status = OI_CODEC_SBC_DecodeFrame(&a2dp_sink_local_param.context, (const OI_BYTE **)&sbc_start_frame,
(OI_UINT32 *)&sbc_frame_len,
(OI_INT16 *)pcmDataPointer,
(OI_UINT32 *)&pcmBytes);
@ -667,7 +587,7 @@ static void btc_a2dp_sink_handle_inc_media(tBT_SBC_HDR *p_msg)
p_msg->len = sbc_frame_len + 1;
}
btc_a2d_data_cb_to_app((uint8_t *)btc_sbc_pcm_data, (BTC_SBC_DEC_PCM_DATA_LEN * sizeof(OI_INT16) - availPcmBytes));
btc_a2d_data_cb_to_app((uint8_t *)a2dp_sink_local_param.pcmData, (sizeof(a2dp_sink_local_param.pcmData) - availPcmBytes));
}
/*******************************************************************************
@ -681,12 +601,11 @@ static void btc_a2dp_sink_handle_inc_media(tBT_SBC_HDR *p_msg)
*******************************************************************************/
BOOLEAN btc_a2dp_sink_rx_flush_req(void)
{
if (fixed_queue_is_empty(btc_aa_snk_cb.RxSbcQ) == TRUE) { /* Que is already empty */
if (fixed_queue_is_empty(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ) == TRUE) { /* Que is already empty */
return TRUE;
}
btc_a2dp_sink_ctrl_post(BTC_MEDIA_FLUSH_AA_RX, NULL);
return TRUE;
return btc_a2dp_sink_ctrl_post(BTC_MEDIA_FLUSH_AA_RX, NULL);
}
/*******************************************************************************
@ -703,7 +622,7 @@ static void btc_a2dp_sink_rx_flush(void)
/* Flush all enqueued SBC buffers (encoded) */
APPL_TRACE_DEBUG("btc_a2dp_sink_rx_flush");
btc_a2dp_sink_flush_q(btc_aa_snk_cb.RxSbcQ);
btc_a2dp_sink_flush_q(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ);
}
static int btc_a2dp_sink_get_track_frequency(UINT8 frequency)
@ -759,13 +678,13 @@ UINT8 btc_a2dp_sink_enque_buf(BT_HDR *p_pkt)
return 0;
}
if (btc_aa_snk_cb.rx_flush == TRUE) { /* Flush enabled, do not enque*/
return fixed_queue_length(btc_aa_snk_cb.RxSbcQ);
if (a2dp_sink_local_param.btc_aa_snk_cb.rx_flush == TRUE) { /* Flush enabled, do not enque*/
return fixed_queue_length(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ);
}
if (fixed_queue_length(btc_aa_snk_cb.RxSbcQ) >= MAX_OUTPUT_A2DP_SNK_FRAME_QUEUE_SZ) {
if (fixed_queue_length(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ) >= MAX_OUTPUT_A2DP_SNK_FRAME_QUEUE_SZ) {
APPL_TRACE_WARNING("Pkt dropped\n");
return fixed_queue_length(btc_aa_snk_cb.RxSbcQ);
return fixed_queue_length(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ);
}
APPL_TRACE_DEBUG("btc_a2dp_sink_enque_buf + ");
@ -776,13 +695,13 @@ UINT8 btc_a2dp_sink_enque_buf(BT_HDR *p_pkt)
memcpy(p_msg, p_pkt, (sizeof(BT_HDR) + p_pkt->offset + p_pkt->len));
p_msg->num_frames_to_be_processed = (*((UINT8 *)(p_msg + 1) + p_msg->offset)) & 0x0f;
APPL_TRACE_VERBOSE("btc_a2dp_sink_enque_buf %d + \n", p_msg->num_frames_to_be_processed);
fixed_queue_enqueue(btc_aa_snk_cb.RxSbcQ, p_msg);
btc_a2dp_sink_data_post(BTC_A2DP_SINK_DATA_EVT);
fixed_queue_enqueue(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ, p_msg, FIXED_QUEUE_MAX_TIMEOUT);
btc_a2dp_sink_data_post();
} else {
/* let caller deal with a failed allocation */
APPL_TRACE_WARNING("btc_a2dp_sink_enque_buf No Buffer left - ");
}
return fixed_queue_length(btc_aa_snk_cb.RxSbcQ);
return fixed_queue_length(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ);
}
static void btc_a2dp_sink_handle_clear_track (void)
@ -802,18 +721,18 @@ static void btc_a2dp_sink_handle_clear_track (void)
static void btc_a2dp_sink_flush_q(fixed_queue_t *p_q)
{
while (! fixed_queue_is_empty(p_q)) {
osi_free(fixed_queue_try_dequeue(p_q));
osi_free(fixed_queue_dequeue(p_q, 0));
}
}
static void btc_a2dp_sink_thread_init(UNUSED_ATTR void *context)
{
APPL_TRACE_EVENT("%s\n", __func__);
memset(&btc_aa_snk_cb, 0, sizeof(btc_aa_snk_cb));
memset(&a2dp_sink_local_param.btc_aa_snk_cb, 0, sizeof(a2dp_sink_local_param.btc_aa_snk_cb));
btc_a2dp_sink_state = BTC_A2DP_SINK_STATE_ON;
btc_aa_snk_cb.RxSbcQ = fixed_queue_new(QUEUE_SIZE_MAX);
a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ = fixed_queue_new(QUEUE_SIZE_MAX);
btc_a2dp_control_init();
}
@ -826,9 +745,9 @@ static void btc_a2dp_sink_thread_cleanup(UNUSED_ATTR void *context)
btc_a2dp_control_cleanup();
fixed_queue_free(btc_aa_snk_cb.RxSbcQ, osi_free_func);
fixed_queue_free(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ, osi_free_func);
future_ready(btc_a2dp_sink_future, NULL);
future_ready(a2dp_sink_local_param.btc_a2dp_sink_future, NULL);
}
#endif /* BTC_AV_SINK_INCLUDED */

View File

@ -79,6 +79,9 @@ typedef struct {
UINT8 flags;
tBTA_AV_EDR edr;
UINT8 peer_sep; /* sep type of peer device */
#if BTC_AV_SRC_INCLUDED
osi_alarm_t *tle_av_open_on_rc;
#endif /* BTC_AV_SRC_INCLUDED */
} btc_av_cb_t;
typedef struct {
@ -89,11 +92,12 @@ typedef struct {
/*****************************************************************************
** Static variables
******************************************************************************/
#if A2D_DYNAMIC_MEMORY == FALSE
static btc_av_cb_t btc_av_cb = {0};
#if BTC_AV_SRC_INCLUDED
static osi_alarm_t *tle_av_open_on_rc = NULL;
#endif /* BTC_AV_SRC_INCLUDED */
#else
static btc_av_cb_t *btc_av_cb_ptr = NULL;
#define btc_av_cb (*btc_av_cb_ptr)
#endif ///A2D_DYNAMIC_MEMORY == FALSE
/* both interface and media task needs to be ready to alloc incoming request */
#define CHECK_BTAV_INIT() do \
@ -337,8 +341,8 @@ static BOOLEAN btc_av_state_idle_handler(btc_sm_event_t event, void *p_data)
#if BTC_AV_SRC_INCLUDED
BTC_TRACE_DEBUG("BTA_AV_RC_OPEN_EVT received w/o AV");
tle_av_open_on_rc = osi_alarm_new("AVconn", btc_initiate_av_open_tmr_hdlr, NULL, BTC_TIMEOUT_AV_OPEN_ON_RC_SECS * 1000);
osi_alarm_set(tle_av_open_on_rc, BTC_TIMEOUT_AV_OPEN_ON_RC_SECS * 1000);
btc_av_cb.tle_av_open_on_rc = osi_alarm_new("AVconn", btc_initiate_av_open_tmr_hdlr, NULL, BTC_TIMEOUT_AV_OPEN_ON_RC_SECS * 1000);
osi_alarm_set(btc_av_cb.tle_av_open_on_rc, BTC_TIMEOUT_AV_OPEN_ON_RC_SECS * 1000);
#endif /* BTC_AV_SRC_INCLUDED */
btc_rc_handler(event, p_data);
break;
@ -353,9 +357,9 @@ static BOOLEAN btc_av_state_idle_handler(btc_sm_event_t event, void *p_data)
case BTA_AV_RC_CLOSE_EVT:
#if BTC_AV_SRC_INCLUDED
if (tle_av_open_on_rc) {
osi_alarm_free(tle_av_open_on_rc);
tle_av_open_on_rc = NULL;
if (btc_av_cb.tle_av_open_on_rc) {
osi_alarm_free(btc_av_cb.tle_av_open_on_rc);
btc_av_cb.tle_av_open_on_rc = NULL;
}
#endif /* BTC_AV_SRC_INCLUDED */
btc_rc_handler(event, p_data);
@ -961,6 +965,19 @@ static void btc_av_event_free_data(btc_sm_event_t event, void *p_data)
static bt_status_t btc_av_init(int service_id)
{
#if A2D_DYNAMIC_MEMORY == TRUE
if (btc_av_cb_ptr != NULL) {
return BT_STATUS_FAIL;
}
if ((btc_av_cb_ptr = (btc_av_cb_t *)osi_malloc(sizeof(btc_av_cb_t))) == NULL) {
APPL_TRACE_ERROR("%s malloc failed!", __func__);
return BT_STATUS_NOMEM;
}
memset((void *)btc_av_cb_ptr, 0, sizeof(btc_av_cb_t));
#endif
if (btc_av_cb.sm_handle == NULL) {
btc_av_cb.service_id = service_id;
bool stat = false;
@ -975,6 +992,10 @@ static bt_status_t btc_av_init(int service_id)
}
if (!stat) {
#if A2D_DYNAMIC_MEMORY == TRUE
osi_free(btc_av_cb_ptr);
btc_av_cb_ptr = NULL;
#endif
return BT_STATUS_FAIL;
}
@ -1034,9 +1055,9 @@ static void clean_up(int service_id)
if (service_id == BTA_A2DP_SOURCE_SERVICE_ID) {
#if BTC_AV_SRC_INCLUDED
btc_a2dp_source_shutdown();
if (tle_av_open_on_rc) {
osi_alarm_free(tle_av_open_on_rc);
tle_av_open_on_rc = NULL;
if (btc_av_cb.tle_av_open_on_rc) {
osi_alarm_free(btc_av_cb.tle_av_open_on_rc);
btc_av_cb.tle_av_open_on_rc = NULL;
}
#endif /* BTC_AV_SRC_INCLUDED */
}
@ -1056,6 +1077,11 @@ static void clean_up(int service_id)
btc_a2dp_sink_shutdown();
#endif /* BTC_AV_SINK_INCLUDED */
}
#if A2D_DYNAMIC_MEMORY == TRUE
osi_free(btc_av_cb_ptr);
btc_av_cb_ptr = NULL;
#endif
}
/*******************************************************************************

View File

@ -16,6 +16,7 @@
#define __BTC_AV_CO_H__
#include "btc_a2dp.h"
#include "bta/bta_av_co.h"
#if (BTA_AV_INCLUDED == TRUE)
/*******************************************************************************
@ -28,7 +29,62 @@ enum {
BTC_SV_AV_AA_SEP_INDEX /* Last index */
};
/*****************************************************************************
** Local data
*****************************************************************************/
typedef struct {
UINT8 sep_info_idx; /* local SEP index (in BTA tables) */
UINT8 seid; /* peer SEP index (in peer tables) */
UINT8 codec_type; /* peer SEP codec type */
UINT8 codec_caps[AVDT_CODEC_SIZE]; /* peer SEP codec capabilities */
UINT8 num_protect; /* peer SEP number of CP elements */
UINT8 protect_info[BTA_AV_CP_INFO_LEN]; /* peer SEP content protection info */
} tBTA_AV_CO_SINK;
typedef struct {
BD_ADDR addr; /* address of audio/video peer */
tBTA_AV_CO_SINK snks[BTC_SV_AV_AA_SEP_INDEX]; /* array of supported sinks */
tBTA_AV_CO_SINK srcs[BTC_SV_AV_AA_SEP_INDEX]; /* array of supported srcs */
UINT8 num_snks; /* total number of sinks at peer */
UINT8 num_srcs; /* total number of srcs at peer */
UINT8 num_seps; /* total number of seids at peer */
UINT8 num_rx_snks; /* number of received sinks */
UINT8 num_rx_srcs; /* number of received srcs */
UINT8 num_sup_snks; /* number of supported sinks in the snks array */
UINT8 num_sup_srcs; /* number of supported srcs in the srcs array */
tBTA_AV_CO_SINK *p_snk; /* currently selected sink */
tBTA_AV_CO_SINK *p_src; /* currently selected src */
UINT8 codec_cfg[AVDT_CODEC_SIZE]; /* current codec configuration */
BOOLEAN cp_active; /* current CP configuration */
BOOLEAN acp; /* acceptor */
BOOLEAN recfg_needed; /* reconfiguration is needed */
BOOLEAN opened; /* opened */
UINT16 mtu; /* maximum transmit unit size */
UINT16 uuid_to_connect; /* uuid of peer device */
} tBTA_AV_CO_PEER;
typedef struct {
BOOLEAN active;
UINT8 flag;
} tBTA_AV_CO_CP;
typedef struct {
/* Connected peer information */
tBTA_AV_CO_PEER peers[BTA_AV_NUM_STRS];
/* Current codec configuration - access to this variable must be protected */
tBTC_AV_CODEC_INFO codec_cfg;
tBTC_AV_CODEC_INFO codec_cfg_setconfig; /* remote peer setconfig preference */
tBTA_AV_CO_CP cp;
} tBTA_AV_CO_CB;
/* Control block instance */
#if AVRC_DYNAMIC_MEMORY == FALSE
extern tBTA_AV_CO_CB bta_av_co_cb;
#else
extern tBTA_AV_CO_CB *bta_av_co_cb_ptr;
#define bta_av_co_cb (*bta_av_co_cb_ptr)
#endif
/*******************************************************************************
** Functions
********************************************************************************/

View File

@ -35,40 +35,6 @@
#if BTC_AV_INCLUDED
/*****************************************************************************
** Constants & Macros
******************************************************************************/
#define BTC_RC_CT_INIT_MAGIC 0x20181128
#define BTC_RC_TG_INIT_MAGIC 0x20181129
#define MAX_RC_NOTIFICATIONS (13) // refer to ESP_AVRC_RN_MAX_EVT
#define CHECK_ESP_RC_CONNECTED do { \
BTC_TRACE_DEBUG("## %s ##", __FUNCTION__); \
if (btc_rc_cb.rc_connected == FALSE) { \
BTC_TRACE_WARNING("Function %s() called when RC is not connected", __FUNCTION__); \
return ESP_ERR_INVALID_STATE; \
} \
} while (0)
/*****************************************************************************
** Local type definitions
******************************************************************************/
typedef struct {
BOOLEAN registered;
UINT8 label;
} btc_rc_reg_ntf_t;
typedef struct {
BOOLEAN rc_connected;
UINT8 rc_handle;
tBTA_AV_FEAT rc_features;
UINT16 rc_ct_features;
UINT16 rc_tg_features;
BD_ADDR rc_addr;
btc_rc_reg_ntf_t rc_ntf[MAX_RC_NOTIFICATIONS];
} btc_rc_cb_t;
static UINT8 opcode_from_pdu(UINT8 pdu);
static void send_reject_response (UINT8 rc_handle, UINT8 label, UINT8 pdu, UINT8 status);
static void handle_rc_connect (tBTA_AV_RC_OPEN *p_rc_open);
@ -86,7 +52,11 @@ static void btc_rc_upstreams_evt(UINT16 event, tAVRC_COMMAND *pavrc_cmd, UINT8 c
static uint32_t s_rc_ct_init;
static uint32_t s_rc_tg_init;
#if AVRC_DYNAMIC_MEMORY == FALSE
static btc_rc_cb_t btc_rc_cb;
#else
btc_rc_cb_t *btc_rc_cb_ptr;
#endif ///AVRC_DYNAMIC_MEMORY == FALSE
const static uint16_t cs_psth_allowed_cmd[8] = {
0x0000, /* bit mask: 0=SELECT, 1=UP, 2=DOWN, 3=LEFT,
@ -1031,7 +1001,7 @@ static void btc_avrc_ct_init(void)
/// initialize CT-TG shared resources
if (s_rc_tg_init != BTC_RC_TG_INIT_MAGIC) {
memset (&btc_rc_cb, 0, sizeof(btc_rc_cb));
memset (&btc_rc_cb, 0, sizeof(btc_rc_cb_t));
}
}
@ -1059,7 +1029,7 @@ static void btc_avrc_ct_deinit(void)
/// deinit CT-TG shared resources
if (s_rc_tg_init != BTC_RC_TG_INIT_MAGIC) {
memset (&btc_rc_cb, 0, sizeof(btc_rc_cb));
memset (&btc_rc_cb, 0, sizeof(btc_rc_cb_t));
}
BTC_TRACE_API("## %s ## completed", __FUNCTION__);

View File

@ -31,8 +31,15 @@
#include "osi/mutex.h"
#include "esp_bt.h"
#if (BLE_INCLUDED == TRUE)
#if BTC_DYNAMIC_MENDRY == FALSE
static tBTA_BLE_ADV_DATA gl_bta_adv_data;
static tBTA_BLE_ADV_DATA gl_bta_scan_rsp_data;
#else
tBTA_BLE_ADV_DATA *gl_bta_adv_data_ptr;
tBTA_BLE_ADV_DATA *gl_bta_scan_rsp_data_ptr;
#endif
#if SCAN_QUEUE_CONGEST_CHECK
static list_t *adv_filter_list;
static osi_mutex_t adv_list_lock;
@ -1366,3 +1373,4 @@ void btc_adv_list_unlock(void)
osi_mutex_unlock(&adv_list_lock);
}
#endif
#endif ///BLE_INCLUDED == TRUE

View File

@ -20,7 +20,7 @@
#define GATTC_READ_VALUE_TYPE_VALUE 0x0000 /* Attribute value itself */
#define GATTC_READ_VALUE_TYPE_AGG_FORMAT 0x2905 /* Characteristic Aggregate Format*/
static unsigned char BASE_UUID[16] = {
static const unsigned char BASE_UUID[16] = {
0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

View File

@ -30,19 +30,11 @@
#define A2C_GATTS_EVT(_bta_event) (_bta_event) //BTA TO BTC EVT
#define C2A_GATTS_EVT(_btc_event) (_btc_event) //BTC TO BTA EVT
typedef struct {
future_t *complete_future;
uint16_t svc_start_hdl;
esp_bt_uuid_t svc_uuid;
bool is_tab_creat_svc;
bool is_use_svc;
uint8_t num_handle;
uint8_t handle_idx;
uint16_t handles[ESP_GATT_ATTR_HANDLE_MAX];
} esp_btc_creat_tab_t;
#if GATT_DYNAMIC_MEMORY == FALSE
static esp_btc_creat_tab_t btc_creat_tab_env;
#else
esp_btc_creat_tab_t *btc_creat_tab_env_ptr;
#endif
static esp_gatt_status_t btc_gatts_check_valid_attr_tab(esp_gatts_attr_db_t *gatts_attr_db,
uint8_t max_nb_attr);

View File

@ -61,42 +61,31 @@
BTA_HF_CLIENT_FEAT_CODEC)
#endif
/************************************************************************************
** Local type definitions
************************************************************************************/
/* BTC-HF control block to map bdaddr to BTA handle */
typedef struct
{
bool initialized;
UINT16 handle;
bt_bdaddr_t connected_bda;
esp_hf_client_connection_state_t state;
esp_hf_vr_state_t vr_state;
tBTA_HF_CLIENT_PEER_FEAT peer_feat;
tBTA_HF_CLIENT_CHLD_FEAT chld_feat;
} btc_hf_client_cb_t;
/************************************************************************************
** Static variables
************************************************************************************/
const char *btc_hf_client_version = "1.6";
static UINT32 btc_hf_client_features = 0;
static btc_hf_client_cb_t btc_hf_client_cb;
static esp_hf_client_incoming_data_cb_t btc_hf_client_incoming_data_cb = NULL;
static esp_hf_client_outgoing_data_cb_t btc_hf_client_outgoing_data_cb = NULL;
#if HFP_DYNAMIC_MEMORY == FALSE
static hf_client_local_param_t hf_client_local_param;
#else
hf_client_local_param_t *hf_client_local_param_ptr;
#endif
/************************************************************************************
** Static functions
************************************************************************************/
#define CHECK_HF_CLIENT_INIT() do { \
if (! btc_hf_client_cb.initialized) { \
if (! hf_client_local_param.btc_hf_client_cb.initialized) { \
return BT_STATUS_NOT_READY; \
} \
} while (0)
#define CHECK_HF_CLIENT_SLC_CONNECTED() do { \
if (! btc_hf_client_cb.initialized || \
btc_hf_client_cb.state != ESP_HF_CLIENT_CONNECTION_STATE_SLC_CONNECTED) { \
if (! hf_client_local_param.btc_hf_client_cb.initialized || \
hf_client_local_param.btc_hf_client_cb.state != ESP_HF_CLIENT_CONNECTION_STATE_SLC_CONNECTED) { \
return BT_STATUS_NOT_READY; \
} \
} while (0)
@ -111,14 +100,14 @@ static inline void btc_hf_client_cb_to_app(esp_hf_client_cb_event_t event, esp_h
static void clear_state(void)
{
memset(&btc_hf_client_cb, 0, sizeof(btc_hf_client_cb_t));
memset(&hf_client_local_param.btc_hf_client_cb, 0, sizeof(btc_hf_client_cb_t));
}
static BOOLEAN is_connected(bt_bdaddr_t *bd_addr)
{
if (((btc_hf_client_cb.state == ESP_HF_CLIENT_CONNECTION_STATE_CONNECTED) ||
(btc_hf_client_cb.state == ESP_HF_CLIENT_CONNECTION_STATE_SLC_CONNECTED))&&
((bd_addr == NULL) || (bdcmp(bd_addr->address, btc_hf_client_cb.connected_bda.address) == 0)))
if (((hf_client_local_param.btc_hf_client_cb.state == ESP_HF_CLIENT_CONNECTION_STATE_CONNECTED) ||
(hf_client_local_param.btc_hf_client_cb.state == ESP_HF_CLIENT_CONNECTION_STATE_SLC_CONNECTED))&&
((bd_addr == NULL) || (bdcmp(bd_addr->address, hf_client_local_param.btc_hf_client_cb.connected_bda.address) == 0)))
return TRUE;
return FALSE;
}
@ -126,23 +115,23 @@ static BOOLEAN is_connected(bt_bdaddr_t *bd_addr)
void btc_hf_client_reg_data_cb(esp_hf_client_incoming_data_cb_t recv,
esp_hf_client_outgoing_data_cb_t send)
{
btc_hf_client_incoming_data_cb = recv;
btc_hf_client_outgoing_data_cb = send;
hf_client_local_param.btc_hf_client_incoming_data_cb = recv;
hf_client_local_param.btc_hf_client_outgoing_data_cb = send;
}
void btc_hf_client_incoming_data_cb_to_app(const uint8_t *data, uint32_t len)
{
// todo: critical section protection
if (btc_hf_client_incoming_data_cb) {
btc_hf_client_incoming_data_cb(data, len);
if (hf_client_local_param.btc_hf_client_incoming_data_cb) {
hf_client_local_param.btc_hf_client_incoming_data_cb(data, len);
}
}
uint32_t btc_hf_client_outgoing_data_cb_to_app(uint8_t *data, uint32_t len)
{
// todo: critical section protection
if (btc_hf_client_outgoing_data_cb) {
return btc_hf_client_outgoing_data_cb(data, len);
if (hf_client_local_param.btc_hf_client_outgoing_data_cb) {
return hf_client_local_param.btc_hf_client_outgoing_data_cb(data, len);
} else {
return 0;
}
@ -172,9 +161,9 @@ bt_status_t btc_hf_client_init(void)
clear_state();
btc_hf_client_cb.initialized = true;
hf_client_local_param.btc_hf_client_cb.initialized = true;
#if CONFIG_BT_HFP_AUDIO_DATA_PATH_HCI
#if BTM_SCO_HCI_INCLUDED
data_path = ESP_SCO_DATA_PATH_HCI;
#else
data_path = ESP_SCO_DATA_PATH_PCM;
@ -199,10 +188,10 @@ static bt_status_t connect_int( bt_bdaddr_t *bd_addr, uint16_t uuid )
return BT_STATUS_BUSY;
}
btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_CONNECTING;
bdcpy(btc_hf_client_cb.connected_bda.address, bd_addr->address);
hf_client_local_param.btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_CONNECTING;
bdcpy(hf_client_local_param.btc_hf_client_cb.connected_bda.address, bd_addr->address);
BTA_HfClientOpen(btc_hf_client_cb.handle, btc_hf_client_cb.connected_bda.address,
BTA_HfClientOpen(hf_client_local_param.btc_hf_client_cb.handle, hf_client_local_param.btc_hf_client_cb.connected_bda.address,
BTC_HF_CLIENT_SECURITY);
return BT_STATUS_SUCCESS;
@ -232,7 +221,7 @@ void btc_hf_client_deinit( void )
btc_dm_disable_service(BTA_HFP_HS_SERVICE_ID);
btc_hf_client_cb.initialized = false;
hf_client_local_param.btc_hf_client_cb.initialized = false;
}
/*******************************************************************************
@ -250,7 +239,7 @@ bt_status_t btc_hf_client_disconnect( bt_bdaddr_t *bd_addr )
if (is_connected(bd_addr))
{
BTA_HfClientClose(btc_hf_client_cb.handle);
BTA_HfClientClose(hf_client_local_param.btc_hf_client_cb.handle);
return BT_STATUS_SUCCESS;
}
@ -272,13 +261,13 @@ bt_status_t btc_hf_client_connect_audio( bt_bdaddr_t *bd_addr )
if (is_connected(bd_addr))
{
if (btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_CODEC)
if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_CODEC)
{
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BCC, 0, 0, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BCC, 0, 0, NULL);
}
else
{
BTA_HfClientAudioOpen(btc_hf_client_cb.handle);
BTA_HfClientAudioOpen(hf_client_local_param.btc_hf_client_cb.handle);
}
/* Inform the application that the audio connection has been initiated successfully */
@ -286,7 +275,7 @@ bt_status_t btc_hf_client_connect_audio( bt_bdaddr_t *bd_addr )
esp_hf_client_cb_param_t param;
memset(&param, 0, sizeof(esp_hf_client_cb_param_t));
param.audio_stat.state = ESP_HF_CLIENT_AUDIO_STATE_CONNECTING;
memcpy(param.audio_stat.remote_bda, &btc_hf_client_cb.connected_bda, sizeof(esp_bd_addr_t));
memcpy(param.audio_stat.remote_bda, &hf_client_local_param.btc_hf_client_cb.connected_bda, sizeof(esp_bd_addr_t));
btc_hf_client_cb_to_app(ESP_HF_CLIENT_AUDIO_STATE_EVT, &param);
} while (0);
@ -311,7 +300,7 @@ bt_status_t btc_hf_client_disconnect_audio( bt_bdaddr_t *bd_addr )
if (is_connected(bd_addr))
{
BTA_HfClientAudioClose(btc_hf_client_cb.handle);
BTA_HfClientAudioClose(hf_client_local_param.btc_hf_client_cb.handle);
return BT_STATUS_SUCCESS;
}
@ -331,9 +320,9 @@ static bt_status_t btc_hf_client_start_voice_recognition(void)
{
CHECK_HF_CLIENT_SLC_CONNECTED();
if (btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_FEAT_VREC)
if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_FEAT_VREC)
{
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BVRA, 1, 0, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BVRA, 1, 0, NULL);
return BT_STATUS_SUCCESS;
}
@ -355,9 +344,9 @@ static bt_status_t btc_hf_client_stop_voice_recognition(void)
{
CHECK_HF_CLIENT_SLC_CONNECTED();
if (btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_FEAT_VREC)
if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_FEAT_VREC)
{
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BVRA, 0, 0, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BVRA, 0, 0, NULL);
return BT_STATUS_SUCCESS;
}
@ -381,10 +370,10 @@ static bt_status_t btc_hf_client_volume_update(esp_hf_volume_control_target_t ty
switch (type)
{
case ESP_HF_VOLUME_CONTROL_TARGET_SPK:
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_VGS, volume, 0, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_VGS, volume, 0, NULL);
break;
case ESP_HF_VOLUME_CONTROL_TARGET_MIC:
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_VGM, volume, 0, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_VGM, volume, 0, NULL);
break;
default:
return BT_STATUS_UNSUPPORTED;
@ -408,11 +397,11 @@ static bt_status_t btc_hf_client_dial(const char *number)
if (strlen(number) != 0)
{
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_ATD, 0, 0, number);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_ATD, 0, 0, number);
}
else
{
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BLDN, 0, 0, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BLDN, 0, 0, NULL);
}
return BT_STATUS_SUCCESS;
@ -431,7 +420,7 @@ static bt_status_t btc_hf_client_dial_memory(int location)
{
CHECK_HF_CLIENT_SLC_CONNECTED();
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_ATD, location, 0, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_ATD, location, 0, NULL);
return BT_STATUS_SUCCESS;
}
@ -443,61 +432,61 @@ static bt_status_t btc_hf_client_send_chld_cmd(esp_hf_chld_type_t type, int idx)
switch (type)
{
case ESP_HF_CHLD_TYPE_REL:
if (btc_hf_client_cb.chld_feat & BTA_HF_CLIENT_CHLD_REL)
if (hf_client_local_param.btc_hf_client_cb.chld_feat & BTA_HF_CLIENT_CHLD_REL)
{
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 0, 0, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 0, 0, NULL);
break;
}
return BT_STATUS_UNSUPPORTED;
case ESP_HF_CHLD_TYPE_REL_ACC:
// CHLD 1 is mandatory for 3 way calling
if (btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_FEAT_3WAY)
if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_FEAT_3WAY)
{
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 1, 0, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 1, 0, NULL);
break;
}
return BT_STATUS_UNSUPPORTED;
case ESP_HF_CHLD_TYPE_HOLD_ACC:
// CHLD 2 is mandatory for 3 way calling
if (btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_FEAT_3WAY)
if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_FEAT_3WAY)
{
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 2, 0, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 2, 0, NULL);
break;
}
return BT_STATUS_UNSUPPORTED;
case ESP_HF_CHLD_TYPE_MERGE:
if (btc_hf_client_cb.chld_feat & BTA_HF_CLIENT_CHLD_MERGE)
if (hf_client_local_param.btc_hf_client_cb.chld_feat & BTA_HF_CLIENT_CHLD_MERGE)
{
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 3, 0, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 3, 0, NULL);
break;
}
return BT_STATUS_UNSUPPORTED;
case ESP_HF_CHLD_TYPE_MERGE_DETACH:
if (btc_hf_client_cb.chld_feat & BTA_HF_CLIENT_CHLD_MERGE_DETACH)
if (hf_client_local_param.btc_hf_client_cb.chld_feat & BTA_HF_CLIENT_CHLD_MERGE_DETACH)
{
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 4, 0, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 4, 0, NULL);
break;
}
return BT_STATUS_UNSUPPORTED;
case ESP_HF_CHLD_TYPE_REL_X:
if (btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_ECC)
if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_ECC)
{
if (idx < 1)
{
return BT_STATUS_FAIL;
}
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 1, idx, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 1, idx, NULL);
break;
}
return BT_STATUS_UNSUPPORTED;
case ESP_HF_CHLD_TYPE_PRIV_X:
if (btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_ECC)
if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_ECC)
{
if (idx < 1)
{
return BT_STATUS_FAIL;
}
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 2, idx, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHLD, 2, idx, NULL);
break;
}
return BT_STATUS_UNSUPPORTED;
@ -512,13 +501,13 @@ static bt_status_t btc_hf_client_send_btrh_cmd(esp_hf_btrh_cmd_t btrh)
switch (btrh) {
case ESP_HF_BTRH_CMD_HOLD:
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BTRH, 0, 0, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BTRH, 0, 0, NULL);
break;
case ESP_HF_BTRH_CMD_ACCEPT:
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BTRH, 1, 0, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BTRH, 1, 0, NULL);
break;
case ESP_HF_BTRH_CMD_REJECT:
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BTRH, 2, 0, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BTRH, 2, 0, NULL);
break;
default:
return BT_STATUS_FAIL;
@ -530,14 +519,14 @@ static bt_status_t btc_hf_client_send_btrh_cmd(esp_hf_btrh_cmd_t btrh)
static bt_status_t btc_hf_client_answer_call(void)
{
CHECK_HF_CLIENT_SLC_CONNECTED();
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_ATA, 0, 0, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_ATA, 0, 0, NULL);
return BT_STATUS_SUCCESS;
}
static bt_status_t btc_hf_client_reject_call(void)
{
CHECK_HF_CLIENT_SLC_CONNECTED();
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHUP, 0, 0, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CHUP, 0, 0, NULL);
return BT_STATUS_SUCCESS;
}
@ -554,9 +543,9 @@ static bt_status_t btc_hf_client_query_current_calls(void)
{
CHECK_HF_CLIENT_SLC_CONNECTED();
if (btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_ECS)
if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_ECS)
{
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CLCC, 0, 0, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CLCC, 0, 0, NULL);
return BT_STATUS_SUCCESS;
}
@ -577,7 +566,7 @@ static bt_status_t btc_hf_client_query_current_operator_name(void)
{
CHECK_HF_CLIENT_SLC_CONNECTED();
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_COPS, 0, 0, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_COPS, 0, 0, NULL);
return BT_STATUS_SUCCESS;
}
@ -595,7 +584,7 @@ static bt_status_t btc_hf_client_retrieve_subscriber_info(void)
{
CHECK_HF_CLIENT_SLC_CONNECTED();
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CNUM, 0, 0, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_CNUM, 0, 0, NULL);
return BT_STATUS_SUCCESS;
}
@ -613,7 +602,7 @@ static bt_status_t btc_hf_client_send_dtmf(char code)
{
CHECK_HF_CLIENT_SLC_CONNECTED();
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_VTS, code, 0, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_VTS, code, 0, NULL);
return BT_STATUS_SUCCESS;
}
@ -631,9 +620,9 @@ static bt_status_t btc_hf_client_request_last_voice_tag_number(void)
{
CHECK_HF_CLIENT_SLC_CONNECTED();
if (btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_VTAG)
if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_VTAG)
{
BTA_HfClientSendAT(btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BINP, 1, 0, NULL);
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_BINP, 1, 0, NULL);
return BT_STATUS_SUCCESS;
}
@ -694,17 +683,17 @@ bt_status_t btc_hf_client_execute_service(BOOLEAN b_enable)
else
{
BTC_TRACE_EVENT("No Codec Nego Supported");
btc_hf_client_features = BTC_HF_CLIENT_FEATURES;
btc_hf_client_features = btc_hf_client_features & (~BTA_HF_CLIENT_FEAT_CODEC);
BTC_TRACE_EVENT("btc_hf_client_features is %d", btc_hf_client_features);
BTA_HfClientRegister(BTC_HF_CLIENT_SECURITY, btc_hf_client_features,
hf_client_local_param.btc_hf_client_features = BTC_HF_CLIENT_FEATURES;
hf_client_local_param.btc_hf_client_features = hf_client_local_param.btc_hf_client_features & (~BTA_HF_CLIENT_FEAT_CODEC);
BTC_TRACE_EVENT("hf_client_local_param.btc_hf_client_features is %d", hf_client_local_param.btc_hf_client_features);
BTA_HfClientRegister(BTC_HF_CLIENT_SECURITY, hf_client_local_param.btc_hf_client_features,
BTC_HF_CLIENT_SERVICE_NAME);
}
}
else
{
BTA_HfClientDeregister(btc_hf_client_cb.handle);
BTA_HfClientDeregister(hf_client_local_param.btc_hf_client_cb.handle);
BTA_HfClientDisable();
}
return BT_STATUS_SUCCESS;
@ -769,44 +758,43 @@ void btc_hf_client_cb_handler(btc_msg_t *msg)
case BTA_HF_CLIENT_DISABLE_EVT:
break;
case BTA_HF_CLIENT_REGISTER_EVT:
btc_hf_client_cb.handle = p_data->reg.handle;
hf_client_local_param.btc_hf_client_cb.handle = p_data->reg.handle;
break;
case BTA_HF_CLIENT_OPEN_EVT:
if (p_data->open.status == BTA_HF_CLIENT_SUCCESS)
{
bdcpy(btc_hf_client_cb.connected_bda.address, p_data->open.bd_addr);
btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_CONNECTED;
btc_hf_client_cb.peer_feat = 0;
btc_hf_client_cb.chld_feat = 0;
bdcpy(hf_client_local_param.btc_hf_client_cb.connected_bda.address, p_data->open.bd_addr);
hf_client_local_param.btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_CONNECTED;
hf_client_local_param.btc_hf_client_cb.peer_feat = 0;
hf_client_local_param.btc_hf_client_cb.chld_feat = 0;
//clear_phone_state();
}
else if (btc_hf_client_cb.state == ESP_HF_CLIENT_CONNECTION_STATE_CONNECTING)
else if (hf_client_local_param.btc_hf_client_cb.state == ESP_HF_CLIENT_CONNECTION_STATE_CONNECTING)
{
btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_DISCONNECTED;
hf_client_local_param.btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_DISCONNECTED;
}
else
{
BTC_TRACE_WARNING("%s: HF CLient open failed, but another device connected. status=%d state=%d connected device=%s",
__FUNCTION__, p_data->open.status, btc_hf_client_cb.state, bdaddr_to_string(&btc_hf_client_cb.connected_bda, bdstr, sizeof(bdstr)));
__FUNCTION__, p_data->open.status, hf_client_local_param.btc_hf_client_cb.state, bdaddr_to_string(&hf_client_local_param.btc_hf_client_cb.connected_bda, bdstr, sizeof(bdstr)));
UNUSED(bdstr);
break;
}
do {
memset(&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.chld_feat = 0;
memcpy(param.conn_stat.remote_bda, &btc_hf_client_cb.connected_bda,
memcpy(param.conn_stat.remote_bda, &hf_client_local_param.btc_hf_client_cb.connected_bda,
sizeof(esp_bd_addr_t));
btc_hf_client_cb_to_app(ESP_HF_CLIENT_CONNECTION_STATE_EVT, &param);
} while (0);
if (btc_hf_client_cb.state == ESP_HF_CLIENT_CONNECTION_STATE_DISCONNECTED) {
bdsetany(btc_hf_client_cb.connected_bda.address);
}
if (hf_client_local_param.btc_hf_client_cb.state == ESP_HF_CLIENT_CONNECTION_STATE_DISCONNECTED)
bdsetany(hf_client_local_param.btc_hf_client_cb.connected_bda.address);
if (p_data->open.status != BTA_HF_CLIENT_SUCCESS) {
btc_queue_advance();
@ -815,24 +803,24 @@ void btc_hf_client_cb_handler(btc_msg_t *msg)
break;
case BTA_HF_CLIENT_CONN_EVT:
btc_hf_client_cb.peer_feat = p_data->conn.peer_feat;
btc_hf_client_cb.chld_feat = p_data->conn.chld_feat;
btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_SLC_CONNECTED;
hf_client_local_param.btc_hf_client_cb.peer_feat = p_data->conn.peer_feat;
hf_client_local_param.btc_hf_client_cb.chld_feat = p_data->conn.chld_feat;
hf_client_local_param.btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_SLC_CONNECTED;
do {
memset(&param, 0, sizeof(esp_hf_client_cb_param_t));
param.conn_stat.state = btc_hf_client_cb.state;
param.conn_stat.peer_feat = btc_hf_client_cb.peer_feat;
param.conn_stat.chld_feat = btc_hf_client_cb.chld_feat;
param.conn_stat.state = hf_client_local_param.btc_hf_client_cb.state;
param.conn_stat.peer_feat = hf_client_local_param.btc_hf_client_cb.peer_feat;
param.conn_stat.chld_feat = hf_client_local_param.btc_hf_client_cb.chld_feat;
memcpy(param.conn_stat.remote_bda, &btc_hf_client_cb.connected_bda,
memcpy(param.conn_stat.remote_bda, &hf_client_local_param.btc_hf_client_cb.connected_bda,
sizeof(esp_bd_addr_t));
btc_hf_client_cb_to_app(ESP_HF_CLIENT_CONNECTION_STATE_EVT, &param);
} while (0);
/* Inform the application about in-band ringtone */
if (btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_INBAND)
if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_INBAND)
{
do {
memset(&param, 0, sizeof(esp_hf_client_cb_param_t));
@ -845,22 +833,22 @@ void btc_hf_client_cb_handler(btc_msg_t *msg)
break;
case BTA_HF_CLIENT_CLOSE_EVT:
btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_DISCONNECTED;
hf_client_local_param.btc_hf_client_cb.state = ESP_HF_CLIENT_CONNECTION_STATE_DISCONNECTED;
do {
memset(&param, 0, sizeof(esp_hf_client_cb_param_t));
param.conn_stat.state = ESP_HF_CLIENT_CONNECTION_STATE_DISCONNECTED;
param.conn_stat.peer_feat = 0;
param.conn_stat.chld_feat = 0;
memcpy(param.conn_stat.remote_bda, &btc_hf_client_cb.connected_bda,
memcpy(param.conn_stat.remote_bda, &hf_client_local_param.btc_hf_client_cb.connected_bda,
sizeof(esp_bd_addr_t));
btc_hf_client_cb_to_app(ESP_HF_CLIENT_CONNECTION_STATE_EVT, &param);
} while (0);
bdsetany(btc_hf_client_cb.connected_bda.address);
btc_hf_client_cb.peer_feat = 0;
btc_hf_client_cb.chld_feat = 0;
bdsetany(hf_client_local_param.btc_hf_client_cb.connected_bda.address);
hf_client_local_param.btc_hf_client_cb.peer_feat = 0;
hf_client_local_param.btc_hf_client_cb.chld_feat = 0;
btc_queue_advance();
break;
case BTA_HF_CLIENT_IND_EVT:
@ -983,7 +971,7 @@ void btc_hf_client_cb_handler(btc_msg_t *msg)
do {
memset(&param, 0, sizeof(esp_hf_client_cb_param_t));
param.audio_stat.state = ESP_HF_CLIENT_AUDIO_STATE_CONNECTED;
memcpy(param.audio_stat.remote_bda, &btc_hf_client_cb.connected_bda,
memcpy(param.audio_stat.remote_bda, &hf_client_local_param.btc_hf_client_cb.connected_bda,
sizeof(esp_bd_addr_t));
btc_hf_client_cb_to_app(ESP_HF_CLIENT_AUDIO_STATE_EVT, &param);
} while (0);
@ -992,7 +980,7 @@ void btc_hf_client_cb_handler(btc_msg_t *msg)
do {
memset(&param, 0, sizeof(esp_hf_client_cb_param_t));
param.audio_stat.state = ESP_HF_CLIENT_AUDIO_STATE_CONNECTED_MSBC;
memcpy(param.audio_stat.remote_bda, &btc_hf_client_cb.connected_bda,
memcpy(param.audio_stat.remote_bda, &hf_client_local_param.btc_hf_client_cb.connected_bda,
sizeof(esp_bd_addr_t));
btc_hf_client_cb_to_app(ESP_HF_CLIENT_AUDIO_STATE_EVT, &param);
} while (0);
@ -1001,7 +989,7 @@ void btc_hf_client_cb_handler(btc_msg_t *msg)
do {
memset(&param, 0, sizeof(esp_hf_client_cb_param_t));
param.audio_stat.state = ESP_HF_CLIENT_AUDIO_STATE_DISCONNECTED;
memcpy(param.audio_stat.remote_bda, &btc_hf_client_cb.connected_bda,
memcpy(param.audio_stat.remote_bda, &hf_client_local_param.btc_hf_client_cb.connected_bda,
sizeof(esp_bd_addr_t));
btc_hf_client_cb_to_app(ESP_HF_CLIENT_AUDIO_STATE_EVT, &param);
} while (0);

View File

@ -86,6 +86,50 @@ typedef enum {
BTC_AVRC_TG_API_SEND_RN_RSP_EVT,
} btc_avrc_tg_act_t;
/*****************************************************************************
** Constants & Macros
******************************************************************************/
/* for AVRC 1.4 need to change this */
#define BTC_RC_CT_INIT_MAGIC 0x20181128
#define BTC_RC_TG_INIT_MAGIC 0x20181129
#define MAX_RC_NOTIFICATIONS (13) // refer to ESP_AVRC_RN_MAX_EVT
#define CHECK_ESP_RC_CONNECTED do { \
BTC_TRACE_DEBUG("## %s ##", __FUNCTION__); \
if (btc_rc_cb.rc_connected == FALSE) { \
BTC_TRACE_WARNING("Function %s() called when RC is not connected", __FUNCTION__); \
return ESP_ERR_INVALID_STATE; \
} \
} while (0)
/*****************************************************************************
** Local type definitions
******************************************************************************/
typedef struct {
BOOLEAN registered;
UINT8 label;
} btc_rc_reg_ntf_t;
typedef struct {
BOOLEAN rc_connected;
UINT8 rc_handle;
tBTA_AV_FEAT rc_features;
UINT16 rc_ct_features;
UINT16 rc_tg_features;
BD_ADDR rc_addr;
btc_rc_reg_ntf_t rc_ntf[MAX_RC_NOTIFICATIONS];
} btc_rc_cb_t;
/*****************************************************************************
** Static variables
******************************************************************************/
#if AVRC_DYNAMIC_MEMORY == TRUE
extern btc_rc_cb_t *btc_rc_cb_ptr;
#define btc_rc_cb (*btc_rc_cb_ptr)
#endif ///AVRC_DYNAMIC_MEMORY == FALSE
typedef struct {
esp_avrc_rn_event_ids_t event_id;
esp_avrc_rn_rsp_t rsp;

View File

@ -18,6 +18,14 @@
#include "esp_bt_defs.h"
#include "esp_gap_ble_api.h"
#if BTC_DYNAMIC_MENDRY == TRUE
#include "bta/bta_api.h"
extern tBTA_BLE_ADV_DATA *gl_bta_adv_data_ptr;
extern tBTA_BLE_ADV_DATA *gl_bta_scan_rsp_data_ptr;
#define gl_bta_adv_data (*gl_bta_adv_data_ptr)
#define gl_bta_scan_rsp_data (*gl_bta_scan_rsp_data_ptr)
#endif
#define BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == ESP_BLE_CONN_PARAM_UNDEF))
typedef enum {

View File

@ -19,6 +19,7 @@
#include "esp_bt_defs.h"
#include "esp_gatt_defs.h"
#include "esp_gatts_api.h"
#include "osi/future.h"
typedef enum {
BTC_GATTS_ACT_APP_REGISTER = 0,
@ -150,6 +151,21 @@ typedef union {
} btc_ble_gatts_args_t;
typedef struct {
future_t *complete_future;
uint16_t svc_start_hdl;
esp_bt_uuid_t svc_uuid;
bool is_tab_creat_svc;
bool is_use_svc;
uint8_t num_handle;
uint8_t handle_idx;
uint16_t handles[ESP_GATT_ATTR_HANDLE_MAX];
} esp_btc_creat_tab_t;
#if GATT_DYNAMIC_MEMORY == TRUE
extern esp_btc_creat_tab_t *btc_creat_tab_env_ptr;
#define btc_creat_tab_env (*btc_creat_tab_env_ptr)
#endif
void btc_gatts_call_handler(btc_msg_t *msg);
void btc_gatts_cb_handler(btc_msg_t *msg);

View File

@ -112,6 +112,34 @@ typedef union {
} reg_data_cb;
} btc_hf_client_args_t;
/************************************************************************************
** Local type definitions
************************************************************************************/
/* BTC-HF control block to map bdaddr to BTA handle */
typedef struct
{
bool initialized;
UINT16 handle;
bt_bdaddr_t connected_bda;
esp_hf_client_connection_state_t state;
esp_hf_vr_state_t vr_state;
tBTA_HF_CLIENT_PEER_FEAT peer_feat;
tBTA_HF_CLIENT_CHLD_FEAT chld_feat;
} btc_hf_client_cb_t;
typedef struct
{
UINT32 btc_hf_client_features;
btc_hf_client_cb_t btc_hf_client_cb;
esp_hf_client_incoming_data_cb_t btc_hf_client_incoming_data_cb;
esp_hf_client_outgoing_data_cb_t btc_hf_client_outgoing_data_cb;
}hf_client_local_param_t;
#if HFP_DYNAMIC_MEMORY == TRUE
extern hf_client_local_param_t *hf_client_local_param_ptr;
#define hf_client_local_param (*hf_client_local_param_ptr)
#endif
/*******************************************************************************
** BTC HF AG API
********************************************************************************/

View File

@ -55,13 +55,20 @@ typedef struct {
char service_name[ESP_SPP_SERVER_NAME_MAX + 1];
} spp_slot_t;
static struct spp_local_param_t {
typedef struct {
spp_slot_t *spp_slots[BTA_JV_MAX_RFC_SR_SESSION + 1];
uint32_t spp_slot_id;
esp_spp_mode_t spp_mode;
osi_mutex_t spp_slot_mutex;
esp_vfs_id_t spp_vfs_id;
} spp_local_param;
} spp_local_param_t;
#if SPP_DYNAMIC_MEMORY == FALSE
static spp_local_param_t spp_local_param;
#else
static spp_local_param_t *spp_local_param_ptr;
#define spp_local_param (*spp_local_param_ptr)
#endif
static void spp_osi_free(void *p)
{
@ -313,6 +320,15 @@ static void btc_spp_dm_inter_cb(tBTA_JV_EVT event, tBTA_JV *p_data, void *user_d
static void btc_spp_init(btc_spp_args_t *arg)
{
#if SPP_DYNAMIC_MEMORY == TRUE
if ((spp_local_param_ptr = (spp_local_param_t *)osi_malloc(sizeof(spp_local_param_t))) == NULL) {
BTC_TRACE_ERROR("%s malloc failed\n", __func__);
return;
}
memset((void *)spp_local_param_ptr, 0, sizeof(spp_local_param_t));
#endif
if (osi_mutex_new(&spp_local_param.spp_slot_mutex) != 0) {
BTC_TRACE_ERROR("%s osi_mutex_new failed\n", __func__);
return;
@ -349,6 +365,11 @@ static void btc_spp_uninit(void)
BTA_JvDisable();
osi_mutex_unlock(&spp_local_param.spp_slot_mutex);
osi_mutex_free(&spp_local_param.spp_slot_mutex);
#if SPP_DYNAMIC_MEMORY == TRUE
osi_free(spp_local_param_ptr);
spp_local_param_ptr = NULL;
#endif
}
static void btc_spp_start_discovery(btc_spp_args_t *arg)

View File

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

View File

@ -19,17 +19,16 @@
#ifndef _BT_TRACE_H_
#define _BT_TRACE_H_
#include "sdkconfig.h"
#include <assert.h>
#include <stdio.h>
#include "bt_user_config.h"
#include "stack/bt_types.h"
#ifndef LOG_LOCAL_LEVEL
#ifndef BOOTLOADER_BUILD
#define LOG_LOCAL_LEVEL CONFIG_LOG_DEFAULT_LEVEL
#define LOG_LOCAL_LEVEL UC_LOG_DEFAULT_LEVEL
#else
#define LOG_LOCAL_LEVEL CONFIG_BOOTLOADER_LOG_LEVEL
#define LOG_LOCAL_LEVEL UC_BOOTLOADER_LOG_LEVEL
#endif
#endif
@ -217,135 +216,31 @@ inline void trc_dump_buffer(const char *prefix, uint8_t *data, uint16_t len)
// btla-specific ++
/* Core Stack default trace levels */
#ifdef CONFIG_BT_LOG_HCI_TRACE_LEVEL
#define HCI_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_HCI_TRACE_LEVEL
#else
#define HCI_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif
#ifdef CONFIG_BT_LOG_BTM_TRACE_LEVEL
#define BTM_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_BTM_TRACE_LEVEL
#else
#define BTM_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif
#ifdef CONFIG_BT_LOG_L2CAP_TRACE_LEVEL
#define L2CAP_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_L2CAP_TRACE_LEVEL
#else
#define L2CAP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif
#ifdef CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL
#define RFCOMM_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL
#else
#define RFCOMM_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif
#ifdef CONFIG_SDP_INITIAL_TRACE_LEVEL
#define SDP_INITIAL_TRACE_LEVEL CONFIG_SDP_INITIAL_TRACE_LEVEL
#else
#define SDP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif
#ifdef CONFIG_BT_LOG_GAP_TRACE_LEVEL
#define GAP_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_GAP_TRACE_LEVEL
#else
#define GAP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif
#ifdef CONFIG_BT_LOG_BNEP_TRACE_LEVEL
#define BNEP_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_BNEP_TRACE_LEVEL
#else
#define BNEP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif
#ifdef CONFIG_BT_LOG_PAN_TRACE_LEVEL
#define PAN_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_PAN_TRACE_LEVEL
#else
#define PAN_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif
#ifdef CONFIG_BT_LOG_A2D_TRACE_LEVEL
#define A2D_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_A2D_TRACE_LEVEL
#else
#define A2D_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif
#ifdef CONFIG_BT_LOG_AVDT_TRACE_LEVEL
#define AVDT_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_AVDT_TRACE_LEVEL
#else
#define AVDT_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif
#ifdef CONFIG_BT_LOG_AVCT_TRACE_LEVEL
#define AVCT_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_AVCT_TRACE_LEVEL
#else
#define AVCT_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif
#ifdef CONFIG_BT_LOG_AVRC_TRACE_LEVEL
#define AVRC_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_AVRC_TRACE_LEVEL
#else
#define AVRC_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif
#ifdef CONFIG_BT_LOG_MCA_TRACE_LEVEL
#define MCA_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_MCA_TRACE_LEVEL
#else
#define MCA_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif
#ifdef CONFIG_BT_LOG_HID_TRACE_LEVEL
#define HID_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_HID_TRACE_LEVEL
#else
#define HID_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif
#ifdef CONFIG_BT_LOG_APPL_TRACE_LEVEL
#define APPL_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_APPL_TRACE_LEVEL
#else
#define APPL_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif
#ifdef CONFIG_BT_LOG_GATT_TRACE_LEVEL
#define GATT_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_GATT_TRACE_LEVEL
#else
#define GATT_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif
#ifdef CONFIG_BT_LOG_SMP_TRACE_LEVEL
#define SMP_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_SMP_TRACE_LEVEL
#else
#define SMP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif
#ifdef CONFIG_BT_LOG_BTIF_TRACE_LEVEL
#define BTIF_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_BTIF_TRACE_LEVEL
#else
#define BTIF_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif
#ifdef CONFIG_BT_LOG_BTC_TRACE_LEVEL
#define BTC_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_BTC_TRACE_LEVEL
#else
#define BTC_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif
#ifdef CONFIG_BT_LOG_OSI_TRACE_LEVEL
#define OSI_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_OSI_TRACE_LEVEL
#else
#define OSI_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif
#ifdef CONFIG_BT_LOG_BLUFI_TRACE_LEVEL
#define BLUFI_INITIAL_TRACE_LEVEL CONFIG_BT_LOG_BLUFI_TRACE_LEVEL
#else
#define BLUFI_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif
#define HCI_INITIAL_TRACE_LEVEL UC_BT_LOG_HCI_TRACE_LEVEL
#define BTM_INITIAL_TRACE_LEVEL UC_BT_LOG_BTM_TRACE_LEVEL
#define L2CAP_INITIAL_TRACE_LEVEL UC_BT_LOG_L2CAP_TRACE_LEVEL
#define RFCOMM_INITIAL_TRACE_LEVEL UC_BT_LOG_RFCOMM_TRACE_LEVEL
#define SDP_INITIAL_TRACE_LEVEL UC_BT_LOG_SDP_TRACE_LEVEL
#define GAP_INITIAL_TRACE_LEVEL UC_BT_LOG_GAP_TRACE_LEVEL
#define BNEP_INITIAL_TRACE_LEVEL UC_BT_LOG_BNEP_TRACE_LEVEL
#define PAN_INITIAL_TRACE_LEVEL UC_BT_LOG_PAN_TRACE_LEVEL
#define A2D_INITIAL_TRACE_LEVEL UC_BT_LOG_A2D_TRACE_LEVEL
#define AVDT_INITIAL_TRACE_LEVEL UC_BT_LOG_AVDT_TRACE_LEVEL
#define AVCT_INITIAL_TRACE_LEVEL UC_BT_LOG_AVCT_TRACE_LEVEL
#define AVRC_INITIAL_TRACE_LEVEL UC_BT_LOG_AVRC_TRACE_LEVEL
#define MCA_INITIAL_TRACE_LEVEL UC_BT_LOG_MCA_TRACE_LEVEL
#define HID_INITIAL_TRACE_LEVEL UC_BT_LOG_HID_TRACE_LEVEL
#define APPL_INITIAL_TRACE_LEVEL UC_BT_LOG_APPL_TRACE_LEVEL
#define GATT_INITIAL_TRACE_LEVEL UC_BT_LOG_GATT_TRACE_LEVEL
#define SMP_INITIAL_TRACE_LEVEL UC_BT_LOG_SMP_TRACE_LEVEL
#define BTIF_INITIAL_TRACE_LEVEL UC_BT_LOG_BTIF_TRACE_LEVEL
#define BTC_INITIAL_TRACE_LEVEL UC_BT_LOG_BTC_TRACE_LEVEL
#define OSI_INITIAL_TRACE_LEVEL UC_BT_LOG_OSI_TRACE_LEVEL
#define BLUFI_INITIAL_TRACE_LEVEL UC_BT_LOG_BLUFI_TRACE_LEVEL
// btla-specific --
#if !CONFIG_BT_STACK_NO_LOG
#if !UC_BT_STACK_NO_LOG
#define LOG_ERROR(format, ... ) {if (LOG_LOCAL_LEVEL >= ESP_LOG_ERROR) esp_log_write(ESP_LOG_ERROR, "BT_LOG", LOG_FORMAT(E, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__); }
#define LOG_WARN(format, ... ) {if (LOG_LOCAL_LEVEL >= ESP_LOG_WARN) esp_log_write(ESP_LOG_WARN, "BT_LOG", LOG_FORMAT(W, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__); }
#define LOG_INFO(format, ... ) {if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) esp_log_write(ESP_LOG_INFO, "BT_LOG", LOG_FORMAT(I, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__); }
@ -695,7 +590,7 @@ extern UINT8 btif_trace_level;
#define BLUFI_TRACE_EVENT(fmt, args...)
#define BLUFI_TRACE_DEBUG(fmt, args...)
#define BLUFI_TRACE_VERBOSE(fmt, args...)
#endif ///CONFIG_BT_STACK_NO_LOG
#endif ///!UC_BT_STACK_NO_LOG
/* Simplified Trace Helper Macro

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

View File

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

View File

@ -30,6 +30,7 @@
#if (C2H_FLOW_CONTROL_INCLUDED == TRUE)
#include "l2c_int.h"
#endif ///C2H_FLOW_CONTROL_INCLUDED == TRUE
#include "stack/hcimsgs.h"
#define HCI_HAL_SERIAL_BUFFER_SIZE 1026
#define HCI_BLE_EVENT 0x3e
@ -63,9 +64,7 @@ static hci_hal_env_t hci_hal_env;
static const hci_hal_t interface;
static const hci_hal_callbacks_t *callbacks;
static const esp_vhci_host_callback_t vhci_host_cb;
static xTaskHandle xHciH4TaskHandle;
static xQueueHandle xHciH4Queue;
static osi_thread_t *hci_h4_thread;
static void host_send_pkt_available_cb(void);
static int host_recv_pkt_cb(uint8_t *data, uint16_t len);
@ -100,9 +99,11 @@ static void hci_hal_env_deinit(void)
hci_hal_env.rx_q = NULL;
}
static bool hal_open(const hci_hal_callbacks_t *upper_callbacks)
static bool hal_open(const hci_hal_callbacks_t *upper_callbacks, void *task_thread)
{
assert(upper_callbacks != NULL);
assert(task_thread != NULL);
callbacks = upper_callbacks;
#if (BLE_ADV_REPORT_FLOW_CONTROL == TRUE)
hci_hal_env_init(HCI_HAL_SERIAL_BUFFER_SIZE, BLE_ADV_REPORT_FLOW_CONTROL_NUM + L2CAP_HOST_FC_ACL_BUFS + QUEUE_SIZE_MAX); // adv flow control num + ACL flow control num + hci cmd numeber
@ -110,8 +111,7 @@ static bool hal_open(const hci_hal_callbacks_t *upper_callbacks)
hci_hal_env_init(HCI_HAL_SERIAL_BUFFER_SIZE, QUEUE_SIZE_MAX);
#endif
xHciH4Queue = xQueueCreate(HCI_H4_QUEUE_LEN, sizeof(BtTaskEvt_t));
xTaskCreatePinnedToCore(hci_hal_h4_rx_handler, HCI_H4_TASK_NAME, HCI_H4_TASK_STACK_SIZE, NULL, HCI_H4_TASK_PRIO, &xHciH4TaskHandle, HCI_H4_TASK_PINNED_TO_CORE);
hci_h4_thread = (osi_thread_t *)task_thread;
//register vhci host cb
if (esp_vhci_host_register_callback(&vhci_host_cb) != ESP_OK) {
@ -125,9 +125,7 @@ static void hal_close()
{
hci_hal_env_deinit();
/* delete task and queue */
vTaskDelete(xHciH4TaskHandle);
vQueueDelete(xHciH4Queue);
hci_h4_thread = NULL;
}
/**
@ -169,30 +167,12 @@ static uint16_t transmit_data(serial_data_type_t type,
// Internal functions
static void hci_hal_h4_rx_handler(void *arg)
{
BtTaskEvt_t e;
for (;;) {
if (pdTRUE == xQueueReceive(xHciH4Queue, &e, (portTickType)portMAX_DELAY)) {
if (e.sig == SIG_HCI_HAL_RECV_PACKET) {
fixed_queue_process(hci_hal_env.rx_q);
}
}
}
}
task_post_status_t hci_hal_h4_task_post(task_post_t timeout)
bool hci_hal_h4_task_post(uint32_t timeout)
{
BtTaskEvt_t evt;
evt.sig = SIG_HCI_HAL_RECV_PACKET;
evt.par = 0;
if (xQueueSend(xHciH4Queue, &evt, timeout) != pdTRUE) {
return TASK_POST_SUCCESS;
}
return TASK_POST_FAIL;
return osi_thread_post(hci_h4_thread, hci_hal_h4_rx_handler, NULL, 1, timeout);
}
#if (C2H_FLOW_CONTROL_INCLUDED == TRUE)
@ -334,7 +314,7 @@ static void event_uart_has_bytes(fixed_queue_t *queue)
{
BT_HDR *packet;
while (!fixed_queue_is_empty(queue)) {
packet = fixed_queue_dequeue(queue);
packet = fixed_queue_dequeue(queue, FIXED_QUEUE_MAX_TIMEOUT);
hci_hal_h4_hdl_rx_packet(packet);
}
}
@ -343,7 +323,7 @@ static void host_send_pkt_available_cb(void)
{
//Controller rx cache buffer is ready for receiving new host packet
//Just Call Host main thread task to process pending packets.
hci_host_task_post(TASK_POST_BLOCKING);
hci_host_task_post(OSI_THREAD_MAX_TIMEOUT);
}
static int host_recv_pkt_cb(uint8_t *data, uint16_t len)
@ -367,9 +347,10 @@ static int host_recv_pkt_cb(uint8_t *data, uint16_t len)
pkt->len = len;
pkt->layer_specific = 0;
memcpy(pkt->data, data, len);
fixed_queue_enqueue(hci_hal_env.rx_q, pkt);
fixed_queue_enqueue(hci_hal_env.rx_q, pkt, FIXED_QUEUE_MAX_TIMEOUT);
hci_hal_h4_task_post(0);
BTTRC_DUMP_BUFFER("Recv Pkt", pkt->data, len);
return 0;

View File

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

View File

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

View File

@ -23,6 +23,8 @@
#include "osi/allocator.h"
#include "osi/osi.h"
#include "osi/future.h"
#include "osi/thread.h"
///// LEGACY DEFINITIONS /////
/* Message event mask across Host/Controller lib and stack */
@ -95,5 +97,6 @@ const hci_t *hci_layer_get_interface();
int hci_start_up(void);
void hci_shut_down(void);
bool hci_host_task_post(uint32_t timeout);
#endif /* _HCI_LAYER_H_ */

View File

@ -116,7 +116,6 @@
#if BTA_JV_INCLUDED==TRUE
#include "bta_jv_int.h"
tBTA_JV_CB *bta_jv_cb_ptr = NULL;
#endif
#if BTA_HL_INCLUDED == TRUE
@ -144,153 +143,6 @@ tBTA_JV_CB *bta_jv_cb_ptr = NULL;
** F U N C T I O N S *
******************************************************************************/
/*****************************************************************************
**
** Function BTE_InitStack
**
** Description Initialize control block memory for each component.
**
** Note: The core stack components must be called
** before creating the BTU Task. The rest of the
** components can be initialized at a later time if desired
** as long as the component's init function is called
** before accessing any of its functions.
**
** Returns void
**
******************************************************************************/
void BTE_InitStack(void)
{
#if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == TRUE)
//Initialize the optional stack components
RFCOMM_Init();
#endif
//BNEP and its profiles
#if (defined(BNEP_INCLUDED) && BNEP_INCLUDED == TRUE)
BNEP_Init();
#if (defined(PAN_INCLUDED) && PAN_INCLUDED == TRUE)
PAN_Init();
#endif // PAN
#endif // BNEP Included
//AVDT and its profiles
#if (defined(A2D_INCLUDED) && A2D_INCLUDED == TRUE)
A2D_Init();
#endif // AADP
#if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE)
AVRC_Init();
#endif
#if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE && AVDT_DYNAMIC_MEMORY == TRUE)
if ((avdt_cb_ptr = (tAVDT_CB *)osi_malloc(sizeof(tAVDT_CB))) == NULL) {
return;
}
memset((void *)avdt_cb_ptr, 0, sizeof(tAVDT_CB));
#endif
#if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE && AVCT_DYNAMIC_MEMORY == TRUE)
if ((avct_cb_ptr = (tAVCT_CB *)osi_malloc(sizeof(tAVCT_CB))) == NULL) {
return;
}
memset((void *)avct_cb_ptr, 0, sizeof(tAVCT_CB));
#endif
#if (defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE)
GAP_Init();
#endif
#if (defined(HID_HOST_INCLUDED) && HID_HOST_INCLUDED == TRUE)
HID_HostInit();
#endif
#if (defined(MCA_INCLUDED) && MCA_INCLUDED == TRUE)
MCA_Init();
#endif
//BTA Modules
#if (BTA_INCLUDED == TRUE && BTA_DYNAMIC_MEMORY == TRUE)
if ((bta_sys_cb_ptr = (tBTA_SYS_CB *)osi_malloc(sizeof(tBTA_SYS_CB))) == NULL) {
return;
}
if ((bta_dm_cb_ptr = (tBTA_DM_CB *)osi_malloc(sizeof(tBTA_DM_CB))) == NULL) {
return;
}
if ((bta_dm_search_cb_ptr = (tBTA_DM_SEARCH_CB *)osi_malloc(sizeof(tBTA_DM_SEARCH_CB))) == NULL) {
return;
}
if ((bta_dm_di_cb_ptr = (tBTA_DM_DI_CB *)osi_malloc(sizeof(tBTA_DM_DI_CB))) == NULL) {
return;
}
memset((void *)bta_sys_cb_ptr, 0, sizeof(tBTA_SYS_CB));
memset((void *)bta_dm_cb_ptr, 0, sizeof(tBTA_DM_CB));
memset((void *)bta_dm_search_cb_ptr, 0, sizeof(tBTA_DM_SEARCH_CB));
memset((void *)bta_dm_di_cb_ptr, 0, sizeof(tBTA_DM_DI_CB));
//memset((void *)bta_prm_cb_ptr, 0, sizeof(tBTA_PRM_CB));
#if (defined BTA_HF_INCLUDED && BTA_HF_INCLUDED == TRUE)
if ((bta_hf_client_cb_ptr = (tBTA_HF_CLIENT_CB *)osi_malloc(sizeof(tBTA_HF_CLIENT_CB))) == NULL) {
return;
}
memset((void *)bta_hf_client_cb_ptr, 0, sizeof(tBTA_HF_CLIENT_CB));
#endif
#if (defined BTA_JV_INCLUDED && BTA_JV_INCLUDED == TRUE)
if ((bta_jv_cb_ptr = (tBTA_JV_CB *)osi_malloc(sizeof(tBTA_JV_CB))) == NULL) {
return;
}
memset((void *)bta_jv_cb_ptr, 0, sizeof(tBTA_JV_CB));
#endif //JV
#if BTA_HS_INCLUDED == TRUE
memset((void *)bta_hs_cb_ptr, 0, sizeof(tBTA_HS_CB));
#endif
#if BTA_SDP_INCLUDED == TRUE
if ((bta_sdp_cb_ptr = (tBTA_SDP_CB *)osi_malloc(sizeof(tBTA_SDP_CB))) == NULL) {
return;
}
memset((void *)bta_sdp_cb_ptr, 0, sizeof(tBTA_SDP_CB));
#endif
#if BTA_AR_INCLUDED==TRUE
if ((bta_ar_cb_ptr = (tBTA_AR_CB *)osi_malloc(sizeof(tBTA_AR_CB))) == NULL) {
return;
}
memset((void *)bta_ar_cb_ptr, 0, sizeof(tBTA_AR_CB));
#endif
#if BTA_AV_INCLUDED==TRUE
if ((bta_av_cb_ptr = (tBTA_AV_CB *)osi_malloc(sizeof(tBTA_AV_CB))) == NULL) {
return;
}
memset((void *)bta_av_cb_ptr, 0, sizeof(tBTA_AV_CB));
#endif
#if BTA_HH_INCLUDED==TRUE
if ((bta_hh_cb_ptr = (tBTA_HH_CB *)osi_malloc(sizeof(tBTA_HH_CB))) == NULL) {
return;
}
memset((void *)bta_hh_cb_ptr, 0, sizeof(tBTA_HH_CB));
#endif
#if BTA_HL_INCLUDED==TRUE
memset((void *)bta_hl_cb_ptr, 0, sizeof(tBTA_HL_CB));
#endif
#if GATTC_INCLUDED==TRUE
if ((bta_gattc_cb_ptr = (tBTA_GATTC_CB *)osi_malloc(sizeof(tBTA_GATTC_CB))) == NULL) {
return;
}
memset((void *)bta_gattc_cb_ptr, 0, sizeof(tBTA_GATTC_CB));
#endif
#if GATTS_INCLUDED == TRUE
if ((bta_gatts_cb_ptr = (tBTA_GATTS_CB *)osi_malloc(sizeof(tBTA_GATTS_CB))) == NULL) {
return;
}
memset((void *)bta_gatts_cb_ptr, 0, sizeof(tBTA_GATTS_CB));
#endif
#if BTA_PAN_INCLUDED==TRUE
memset((void *)bta_pan_cb_ptr, 0, sizeof(tBTA_PAN_CB));
#endif
#endif // BTA_INCLUDED == TRUE
}
/*****************************************************************************
**
** Function BTE_DeinitStack
@ -308,55 +160,101 @@ void BTE_DeinitStack(void)
//BTA Modules
#if (BTA_INCLUDED == TRUE && BTA_DYNAMIC_MEMORY == TRUE)
#if GATTS_INCLUDED == TRUE
if (bta_gatts_cb_ptr){
osi_free(bta_gatts_cb_ptr);
bta_gatts_cb_ptr = NULL;
}
#endif
#if GATTC_INCLUDED==TRUE
if (bta_gattc_cb_ptr){
osi_free(bta_gattc_cb_ptr);
bta_gattc_cb_ptr = NULL;
}
#endif
#if BTA_HH_INCLUDED==TRUE
if (bta_hh_cb_ptr){
osi_free(bta_hh_cb_ptr);
bta_hh_cb_ptr = NULL;
}
#endif
#if BTA_AV_INCLUDED==TRUE
if (bta_av_cb_ptr){
osi_free(bta_av_cb_ptr);
bta_av_cb_ptr = NULL;
}
if (bta_av_sbc_ups_cb_ptr){
osi_free(bta_av_sbc_ups_cb_ptr);
bta_av_sbc_ups_cb_ptr = NULL;
}
#endif
#if BTA_AR_INCLUDED==TRUE
if (bta_ar_cb_ptr){
osi_free(bta_ar_cb_ptr);
bta_ar_cb_ptr = NULL;
}
#endif
#if SDP_INCLUDED == TRUE
if (g_disc_raw_data_buf){
osi_free(g_disc_raw_data_buf);
g_disc_raw_data_buf = NULL;
}
#endif
#if BTA_SDP_INCLUDED == TRUE
if (bta_sdp_cb_ptr){
osi_free(bta_sdp_cb_ptr);
bta_sdp_cb_ptr = NULL;
}
#endif
#if (defined BTA_JV_INCLUDED && BTA_JV_INCLUDED == TRUE)
if (bta_jv_cb_ptr){
osi_free(bta_jv_cb_ptr);
bta_jv_cb_ptr = NULL;
}
#endif //JV
#if (defined BTA_HF_INCLUDED && BTA_HF_INCLUDED == TRUE)
if (bta_hf_client_cb_ptr){
osi_free(bta_hf_client_cb_ptr);
bta_hf_client_cb_ptr = NULL;
}
#endif
if (bta_dm_conn_srvcs_ptr){
osi_free(bta_dm_conn_srvcs_ptr);
bta_dm_conn_srvcs_ptr = NULL;
}
if (bta_dm_di_cb_ptr){
osi_free(bta_dm_di_cb_ptr);
bta_dm_di_cb_ptr = NULL;
}
if (bta_dm_search_cb_ptr){
osi_free(bta_dm_search_cb_ptr);
bta_dm_search_cb_ptr = NULL;
}
if (bta_dm_cb_ptr){
osi_free(bta_dm_cb_ptr);
bta_dm_cb_ptr = NULL;
}
if (bta_sys_cb_ptr){
osi_free(bta_sys_cb_ptr);
bta_sys_cb_ptr = NULL;
}
#endif // BTA_INCLUDED == TRUE
#if (defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE)
GAP_Deinit();
#endif
#if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE && AVCT_DYNAMIC_MEMORY == TRUE)
if (avct_cb_ptr){
osi_free(avct_cb_ptr);
avct_cb_ptr = NULL;
}
#endif
#if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE && AVDT_DYNAMIC_MEMORY == TRUE)
if (avdt_cb_ptr){
osi_free(avdt_cb_ptr);
avdt_cb_ptr = NULL;
}
#endif
#if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE)
@ -366,4 +264,184 @@ void BTE_DeinitStack(void)
#if (defined(A2D_INCLUDED) && A2D_INCLUDED == TRUE)
A2D_Deinit();
#endif
#if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == TRUE)
RFCOMM_Deinit();
#endif
}
/*****************************************************************************
**
** Function BTE_InitStack
**
** Description Initialize control block memory for each component.
**
** Note: The core stack components must be called
** before creating the BTU Task. The rest of the
** components can be initialized at a later time if desired
** as long as the component's init function is called
** before accessing any of its functions.
**
** Returns status
**
******************************************************************************/
bt_status_t BTE_InitStack(void)
{
#if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == TRUE)
//Initialize the optional stack components
if (RFCOMM_Init() != BT_STATUS_SUCCESS) {
goto error_exit;
}
#endif
//BNEP and its profiles
#if (defined(BNEP_INCLUDED) && BNEP_INCLUDED == TRUE)
BNEP_Init();
#if (defined(PAN_INCLUDED) && PAN_INCLUDED == TRUE)
PAN_Init();
#endif // PAN
#endif // BNEP Included
//AVDT and its profiles
#if (defined(A2D_INCLUDED) && A2D_INCLUDED == TRUE)
if (A2D_Init() != BT_STATUS_SUCCESS) {
goto error_exit;
}
#endif // AADP
#if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE)
if (AVRC_Init() != BT_STATUS_SUCCESS) {
goto error_exit;
}
#endif
#if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE && AVDT_DYNAMIC_MEMORY == TRUE)
if ((avdt_cb_ptr = (tAVDT_CB *)osi_malloc(sizeof(tAVDT_CB))) == NULL) {
goto error_exit;
}
memset((void *)avdt_cb_ptr, 0, sizeof(tAVDT_CB));
#endif
#if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE && AVCT_DYNAMIC_MEMORY == TRUE)
if ((avct_cb_ptr = (tAVCT_CB *)osi_malloc(sizeof(tAVCT_CB))) == NULL) {
goto error_exit;
}
memset((void *)avct_cb_ptr, 0, sizeof(tAVCT_CB));
#endif
#if (defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE)
if (GAP_Init() != BT_STATUS_SUCCESS) {
goto error_exit;
}
#endif
#if (defined(HID_HOST_INCLUDED) && HID_HOST_INCLUDED == TRUE)
HID_HostInit();
#endif
#if (defined(MCA_INCLUDED) && MCA_INCLUDED == TRUE)
MCA_Init();
#endif
//BTA Modules
#if (BTA_INCLUDED == TRUE && BTA_DYNAMIC_MEMORY == TRUE)
if ((bta_sys_cb_ptr = (tBTA_SYS_CB *)osi_malloc(sizeof(tBTA_SYS_CB))) == NULL) {
goto error_exit;
}
if ((bta_dm_cb_ptr = (tBTA_DM_CB *)osi_malloc(sizeof(tBTA_DM_CB))) == NULL) {
goto error_exit;
}
if ((bta_dm_search_cb_ptr = (tBTA_DM_SEARCH_CB *)osi_malloc(sizeof(tBTA_DM_SEARCH_CB))) == NULL) {
goto error_exit;
}
if ((bta_dm_di_cb_ptr = (tBTA_DM_DI_CB *)osi_malloc(sizeof(tBTA_DM_DI_CB))) == NULL) {
goto error_exit;
}
if ((bta_dm_conn_srvcs_ptr = (tBTA_DM_CONNECTED_SRVCS *)osi_malloc(sizeof(tBTA_DM_CONNECTED_SRVCS))) == NULL) {
goto error_exit;
}
memset((void *)bta_sys_cb_ptr, 0, sizeof(tBTA_SYS_CB));
memset((void *)bta_dm_cb_ptr, 0, sizeof(tBTA_DM_CB));
memset((void *)bta_dm_search_cb_ptr, 0, sizeof(tBTA_DM_SEARCH_CB));
memset((void *)bta_dm_di_cb_ptr, 0, sizeof(tBTA_DM_DI_CB));
memset((void *)bta_dm_conn_srvcs_ptr, 0, sizeof(tBTA_DM_CONNECTED_SRVCS));
//memset((void *)bta_prm_cb_ptr, 0, sizeof(tBTA_PRM_CB));
#if (defined BTA_HF_INCLUDED && BTA_HF_INCLUDED == TRUE)
if ((bta_hf_client_cb_ptr = (tBTA_HF_CLIENT_CB *)osi_malloc(sizeof(tBTA_HF_CLIENT_CB))) == NULL) {
goto error_exit;
}
memset((void *)bta_hf_client_cb_ptr, 0, sizeof(tBTA_HF_CLIENT_CB));
#endif
#if (defined BTA_JV_INCLUDED && BTA_JV_INCLUDED == TRUE)
if ((bta_jv_cb_ptr = (tBTA_JV_CB *)osi_malloc(sizeof(tBTA_JV_CB))) == NULL) {
goto error_exit;
}
memset((void *)bta_jv_cb_ptr, 0, sizeof(tBTA_JV_CB));
#endif //JV
#if BTA_HS_INCLUDED == TRUE
memset((void *)bta_hs_cb_ptr, 0, sizeof(tBTA_HS_CB));
#endif
#if BTA_SDP_INCLUDED == TRUE
if ((bta_sdp_cb_ptr = (tBTA_SDP_CB *)osi_malloc(sizeof(tBTA_SDP_CB))) == NULL) {
goto error_exit;
}
memset((void *)bta_sdp_cb_ptr, 0, sizeof(tBTA_SDP_CB));
#endif
#if SDP_INCLUDED == TRUE
if ((g_disc_raw_data_buf = (UINT8 *)osi_malloc(MAX_DISC_RAW_DATA_BUF)) == NULL) {
goto error_exit;
}
memset((void *)g_disc_raw_data_buf, 0, MAX_DISC_RAW_DATA_BUF);
#endif
#if BTA_AR_INCLUDED==TRUE
if ((bta_ar_cb_ptr = (tBTA_AR_CB *)osi_malloc(sizeof(tBTA_AR_CB))) == NULL) {
goto error_exit;
}
memset((void *)bta_ar_cb_ptr, 0, sizeof(tBTA_AR_CB));
#endif
#if BTA_AV_INCLUDED==TRUE
if ((bta_av_cb_ptr = (tBTA_AV_CB *)osi_malloc(sizeof(tBTA_AV_CB))) == NULL) {
goto error_exit;
}
memset((void *)bta_av_cb_ptr, 0, sizeof(tBTA_AV_CB));
if ((bta_av_sbc_ups_cb_ptr = (tBTA_AV_SBC_UPS_CB *)osi_malloc(sizeof(tBTA_AV_SBC_UPS_CB))) == NULL) {
goto error_exit;
}
memset((void *)bta_av_sbc_ups_cb_ptr, 0, sizeof(tBTA_AV_SBC_UPS_CB));
#endif
#if BTA_HH_INCLUDED==TRUE
if ((bta_hh_cb_ptr = (tBTA_HH_CB *)osi_malloc(sizeof(tBTA_HH_CB))) == NULL) {
goto error_exit;
}
memset((void *)bta_hh_cb_ptr, 0, sizeof(tBTA_HH_CB));
#endif
#if BTA_HL_INCLUDED==TRUE
memset((void *)bta_hl_cb_ptr, 0, sizeof(tBTA_HL_CB));
#endif
#if GATTC_INCLUDED==TRUE
if ((bta_gattc_cb_ptr = (tBTA_GATTC_CB *)osi_malloc(sizeof(tBTA_GATTC_CB))) == NULL) {
goto error_exit;
}
memset((void *)bta_gattc_cb_ptr, 0, sizeof(tBTA_GATTC_CB));
#endif
#if GATTS_INCLUDED == TRUE
if ((bta_gatts_cb_ptr = (tBTA_GATTS_CB *)osi_malloc(sizeof(tBTA_GATTS_CB))) == NULL) {
goto error_exit;
}
memset((void *)bta_gatts_cb_ptr, 0, sizeof(tBTA_GATTS_CB));
#endif
#if BTA_PAN_INCLUDED==TRUE
memset((void *)bta_pan_cb_ptr, 0, sizeof(tBTA_PAN_CB));
#endif
#endif // BTA_INCLUDED == TRUE
return BT_STATUS_SUCCESS;
error_exit:;
LOG_ERROR("%s failed due to no memory", __func__);
BTE_DeinitStack();
return BT_STATUS_NOMEM;
}

View File

@ -44,7 +44,11 @@ enum {
static osi_mutex_t alarm_mutex;
static int alarm_state;
#if BT_BLE_DYNAMIC_ENV_MEMORY == FALSE
static struct alarm_t alarm_cbs[ALARM_CBS_NUM];
#else
static struct alarm_t *alarm_cbs;
#endif
static osi_alarm_err_t alarm_free(osi_alarm_t *alarm);
static osi_alarm_err_t alarm_set(osi_alarm_t *alarm, period_ms_t timeout, bool is_periodic);
@ -78,7 +82,14 @@ void osi_alarm_init(void)
OSI_TRACE_WARNING("%s, invalid state %d\n", __func__, alarm_state);
goto end;
}
memset(alarm_cbs, 0x00, sizeof(alarm_cbs));
#if BT_BLE_DYNAMIC_ENV_MEMORY == TRUE
if ((alarm_cbs = (osi_alarm_t *)osi_malloc(sizeof(osi_alarm_t) * ALARM_CBS_NUM)) == NULL) {
OSI_TRACE_ERROR("%s, malloc failed\n", __func__);
goto end;
}
#endif
memset(alarm_cbs, 0x00, sizeof(osi_alarm_t) * ALARM_CBS_NUM);
alarm_state = ALARM_STATE_OPEN;
end:
@ -100,6 +111,12 @@ void osi_alarm_deinit(void)
alarm_free(&alarm_cbs[i]);
}
}
#if BT_BLE_DYNAMIC_ENV_MEMORY == TRUE
osi_free(alarm_cbs);
alarm_cbs = NULL;
#endif
alarm_state = ALARM_STATE_IDLE;
end:

View File

@ -24,7 +24,8 @@
extern void *pvPortZalloc(size_t size);
extern void vPortFree(void *pv);
#ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG
#if HEAP_MEMORY_DEBUG
#define OSI_MEM_DBG_INFO_MAX 1024*3
typedef struct {
@ -35,8 +36,16 @@ typedef struct {
} osi_mem_dbg_info_t;
static uint32_t mem_dbg_count = 0;
static uint32_t mem_dbg_count2 = 0;
static osi_mem_dbg_info_t mem_dbg_info[OSI_MEM_DBG_INFO_MAX];
static uint32_t mem_dbg_current_size = 0;
static uint32_t mem_dbg_max_size = 0;
#define OSI_MEM_DBG_MAX_SECTION_NUM 5
typedef struct {
bool used;
uint32_t max_size;
} osi_mem_dbg_max_size_section_t;
static osi_mem_dbg_max_size_section_t mem_dbg_max_size_section[OSI_MEM_DBG_MAX_SECTION_NUM];
void osi_mem_dbg_init(void)
{
@ -49,7 +58,13 @@ void osi_mem_dbg_init(void)
mem_dbg_info[i].line = 0;
}
mem_dbg_count = 0;
mem_dbg_count2 = 0;
mem_dbg_current_size = 0;
mem_dbg_max_size = 0;
for (i = 0; i < OSI_MEM_DBG_MAX_SECTION_NUM; i++){
mem_dbg_max_size_section[i].used = false;
mem_dbg_max_size_section[i].max_size = 0;
}
}
void osi_mem_dbg_record(void *p, int size, const char *func, int line)
@ -75,6 +90,19 @@ void osi_mem_dbg_record(void *p, int size, const char *func, int line)
if (i >= OSI_MEM_DBG_INFO_MAX) {
OSI_TRACE_ERROR("%s full %s %d !!\n", __func__, func, line);
}
mem_dbg_current_size += size;
if(mem_dbg_max_size < mem_dbg_current_size) {
mem_dbg_max_size = mem_dbg_current_size;
}
for (i = 0; i < OSI_MEM_DBG_MAX_SECTION_NUM; i++){
if (mem_dbg_max_size_section[i].used) {
if(mem_dbg_max_size_section[i].max_size < mem_dbg_current_size) {
mem_dbg_max_size_section[i].max_size = mem_dbg_current_size;
}
}
}
}
void osi_mem_dbg_clean(void *p, const char *func, int line)
@ -88,6 +116,7 @@ void osi_mem_dbg_clean(void *p, const char *func, int line)
for (i = 0; i < OSI_MEM_DBG_INFO_MAX; i++) {
if (mem_dbg_info[i].p == p) {
mem_dbg_current_size -= mem_dbg_info[i].size;
mem_dbg_info[i].p = NULL;
mem_dbg_info[i].size = 0;
mem_dbg_info[i].func = NULL;
@ -112,6 +141,60 @@ void osi_mem_dbg_show(void)
}
}
OSI_TRACE_ERROR("--> count %d\n", mem_dbg_count);
OSI_TRACE_ERROR("--> size %dB\n--> max size %dB\n", mem_dbg_current_size, mem_dbg_max_size);
}
uint32_t osi_mem_dbg_get_max_size(void)
{
return mem_dbg_max_size;
}
uint32_t osi_mem_dbg_get_current_size(void)
{
return mem_dbg_current_size;
}
void osi_men_dbg_set_section_start(uint8_t index)
{
if (index >= OSI_MEM_DBG_MAX_SECTION_NUM) {
OSI_TRACE_ERROR("Then range of index should be between 0 and %d, current index is %d.\n",
OSI_MEM_DBG_MAX_SECTION_NUM - 1, index);
return;
}
if (mem_dbg_max_size_section[index].used) {
OSI_TRACE_WARNING("This index(%d) has been started, restart it.\n", index);
}
mem_dbg_max_size_section[index].used = true;
mem_dbg_max_size_section[index].max_size = mem_dbg_current_size;
}
void osi_men_dbg_set_section_end(uint8_t index)
{
if (index >= OSI_MEM_DBG_MAX_SECTION_NUM) {
OSI_TRACE_ERROR("Then range of index should be between 0 and %d, current index is %d.\n",
OSI_MEM_DBG_MAX_SECTION_NUM - 1, index);
return;
}
if (!mem_dbg_max_size_section[index].used) {
OSI_TRACE_ERROR("This index(%d) has not been started.\n", index);
return;
}
mem_dbg_max_size_section[index].used = false;
}
uint32_t osi_mem_dbg_get_max_size_section(uint8_t index)
{
if (index >= OSI_MEM_DBG_MAX_SECTION_NUM){
OSI_TRACE_ERROR("Then range of index should be between 0 and %d, current index is %d.\n",
OSI_MEM_DBG_MAX_SECTION_NUM - 1, index);
return 0;
}
return mem_dbg_max_size_section[index].max_size;
}
#endif
@ -130,47 +213,47 @@ char *osi_strdup(const char *str)
void *osi_malloc_func(size_t size)
{
#ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG
#if HEAP_MEMORY_DEBUG
void *p;
#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST
#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST
p = heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL);
#else
p = malloc(size);
#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */
#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */
osi_mem_dbg_record(p, size, __func__, __LINE__);
return p;
#else
#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST
#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST
return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL);
#else
return malloc(size);
#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */
#endif /* #ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG */
#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */
#endif /* #if HEAP_MEMORY_DEBUG */
}
void *osi_calloc_func(size_t size)
{
#ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG
#if HEAP_MEMORY_DEBUG
void *p;
#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST
#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST
p = heap_caps_calloc_prefer(1, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL);
#else
p = calloc(1, size);
#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */
#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */
osi_mem_dbg_record(p, size, __func__, __LINE__);
return p;
#else
#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST
#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST
return heap_caps_calloc_prefer(1, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL);
#else
return calloc(1, size);
#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */
#endif /* #ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG */
#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */
#endif /* #if HEAP_MEMORY_DEBUG */
}
void osi_free_func(void *ptr)
{
#ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG
#if HEAP_MEMORY_DEBUG
osi_mem_dbg_clean(ptr, __func__, __LINE__);
#endif
free(ptr);

View File

@ -129,45 +129,12 @@ size_t fixed_queue_capacity(fixed_queue_t *queue)
return queue->capacity;
}
void fixed_queue_enqueue(fixed_queue_t *queue, void *data)
bool fixed_queue_enqueue(fixed_queue_t *queue, void *data, uint32_t timeout)
{
assert(queue != NULL);
assert(data != NULL);
osi_sem_take(&queue->enqueue_sem, OSI_SEM_MAX_TIMEOUT);
osi_mutex_lock(&queue->lock, OSI_MUTEX_MAX_TIMEOUT);
list_append(queue->list, data);
osi_mutex_unlock(&queue->lock);
osi_sem_give(&queue->dequeue_sem);
}
void *fixed_queue_dequeue(fixed_queue_t *queue)
{
void *ret = NULL;
assert(queue != NULL);
osi_sem_take(&queue->dequeue_sem, OSI_SEM_MAX_TIMEOUT);
osi_mutex_lock(&queue->lock, OSI_MUTEX_MAX_TIMEOUT);
ret = list_front(queue->list);
list_remove(queue->list, ret);
osi_mutex_unlock(&queue->lock);
osi_sem_give(&queue->enqueue_sem);
return ret;
}
bool fixed_queue_try_enqueue(fixed_queue_t *queue, void *data)
{
assert(queue != NULL);
assert(data != NULL);
if (osi_sem_take(&queue->enqueue_sem, 0) != 0) {
if (osi_sem_take(&queue->enqueue_sem, timeout) != 0) {
return false;
}
@ -181,15 +148,13 @@ bool fixed_queue_try_enqueue(fixed_queue_t *queue, void *data)
return true;
}
void *fixed_queue_try_dequeue(fixed_queue_t *queue)
void *fixed_queue_dequeue(fixed_queue_t *queue, uint32_t timeout)
{
void *ret = NULL;
if (queue == NULL) {
return NULL;
}
assert(queue != NULL);
if (osi_sem_take(queue->dequeue_sem, 0) != 0) {
if (osi_sem_take(queue->dequeue_sem, timeout) != 0) {
return NULL;
}

View File

@ -22,7 +22,6 @@
#include <stddef.h>
#include <stdlib.h>
#include "esp_heap_caps.h"
#include "sdkconfig.h"
char *osi_strdup(const char *str);
@ -30,14 +29,19 @@ void *osi_malloc_func(size_t size);
void *osi_calloc_func(size_t size);
void osi_free_func(void *ptr);
#ifdef CONFIG_BT_BLUEDROID_MEM_DEBUG
#if HEAP_MEMORY_DEBUG
void osi_mem_dbg_init(void);
void osi_mem_dbg_record(void *p, int size, const char *func, int line);
void osi_mem_dbg_clean(void *p, const char *func, int line);
void osi_mem_dbg_show(void);
uint32_t osi_mem_dbg_get_max_size(void);
uint32_t osi_mem_dbg_get_current_size(void);
void osi_men_dbg_set_section_start(uint8_t index);
void osi_men_dbg_set_section_end(uint8_t index);
uint32_t osi_mem_dbg_get_max_size_section(uint8_t index);
#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST
#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST
#define osi_malloc(size) \
({ \
void *p; \
@ -76,7 +80,7 @@ void osi_mem_dbg_show(void);
(void *)p; \
})
#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */
#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */
#if 0
@ -84,11 +88,11 @@ void osi_mem_dbg_show(void);
do { \
void *p; \
\
#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST \
#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST \
p = heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); \
#else \
p = malloc((size)); \
#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */ \
#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */ \
osi_mem_dbg_record(p, size, __func__, __LINE__); \
(void *)p; \
}while(0)
@ -97,13 +101,13 @@ do { \
do { \
void *p; \
\
#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST \
#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST \
p = heap_caps_calloc_prefer(1, size, 2, \
MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, \
MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); \
#else \
p = calloc(1, (size)); \
#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */ \
#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */ \
osi_mem_dbg_record(p, size, __func__, __LINE__); \
(void *)p; \
} while(0)
@ -118,16 +122,16 @@ do { \
#else
#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST
#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST
#define osi_malloc(size) heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL)
#define osi_calloc(size) heap_caps_calloc_prefer(1, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL)
#else
#define osi_malloc(size) malloc((size))
#define osi_calloc(size) calloc(1, (size))
#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */
#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */
#define osi_free(p) free((p))
#endif /* CONFIG_BT_BLUEDROID_MEM_DEBUG */
#endif /* HEAP_MEMORY_DEBUG */
#define FREE_AND_RESET(a) \
do { \

View File

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

View File

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

View File

@ -22,94 +22,71 @@
#include "freertos/task.h"
#include "esp_task.h"
#include "common/bt_defs.h"
#include "osi/semaphore.h"
#define portBASE_TYPE int
struct bt_task_evt {
uint32_t sig; //task sig
void *par; //point to task param
void *cb; //point to function cb
void *arg; //point to function arg
};
typedef struct bt_task_evt BtTaskEvt_t;
#define OSI_THREAD_MAX_TIMEOUT OSI_SEM_MAX_TIMEOUT
typedef bt_status_t (* BtTaskCb_t)(void *arg);
struct osi_thread;
typedef struct osi_thread osi_thread_t;
typedef void (*osi_thread_func_t)(void *context);
typedef enum {
SIG_HCI_HAL_RECV_PACKET = 0,
SIG_HCI_HAL_NUM,
} SIG_HCI_HAL_t;
OSI_THREAD_CORE_0 = 0,
OSI_THREAD_CORE_1,
OSI_THREAD_CORE_AFFINITY,
} osi_thread_core_t;
/*
* brief: Create a thread or task
* param name: thread name
* param stack_size: thread stack size
* param priority: thread priority
* param core: the CPU core which this thread run, OSI_THREAD_CORE_AFFINITY means unspecific CPU core
* param work_queue_num: speicify queue number, the queue[0] has highest priority, and the priority is decrease by index
* return : if create successfully, return thread handler; otherwise return NULL.
*/
osi_thread_t *osi_thread_create(const char *name, size_t stack_size, int priority, osi_thread_core_t core, uint8_t work_queue_num);
typedef enum {
SIG_HCI_HOST_SEND_AVAILABLE = 0,
SIG_HCI_HOST_NUM,
} SIG_HCI_HOST_t;
/*
* brief: Destroy a thread or task
* param thread: point of thread handler
*/
void osi_thread_free(osi_thread_t *thread);
typedef enum {
SIG_BTU_START_UP = 0,
SIG_BTU_HCI_MSG,
SIG_BTU_BTA_MSG,
SIG_BTU_BTA_ALARM,
SIG_BTU_GENERAL_ALARM,
SIG_BTU_ONESHOT_ALARM,
SIG_BTU_L2CAP_ALARM,
SIG_BTU_NUM,
} SIG_BTU_t;
/*
* brief: Post an msg to a thread and told the thread call the function
* param thread: point of thread handler
* param func: callback function that called by target thread
* param context: argument of callback function
* param queue_idx: the queue which the msg send to
* param timeout: post timeout, OSI_THREAD_MAX_TIMEOUT means blocking forever, 0 means never blocking, others means block millisecond
* return : if post successfully, return true, otherwise return false
*/
bool osi_thread_post(osi_thread_t *thread, osi_thread_func_t func, void *context, int queue_idx, uint32_t timeout);
#define TASK_PINNED_TO_CORE (CONFIG_BT_BLUEDROID_PINNED_TO_CORE < portNUM_PROCESSORS ? CONFIG_BT_BLUEDROID_PINNED_TO_CORE : tskNO_AFFINITY)
/*
* brief: Set the priority of thread
* param thread: point of thread handler
* param priority: priority
* return : if set successfully, return true, otherwise return false
*/
bool osi_thread_set_priority(osi_thread_t *thread, int priority);
#define HCI_HOST_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE)
#define HCI_HOST_TASK_STACK_SIZE (2048 + BT_TASK_EXTRA_STACK_SIZE)
#define HCI_HOST_TASK_PRIO (configMAX_PRIORITIES - 3)
#define HCI_HOST_TASK_NAME "hciHostT"
#define HCI_HOST_QUEUE_LEN 40
/* brief: Get thread name
* param thread: point of thread handler
* return: constant point of thread name
*/
const char *osi_thread_name(osi_thread_t *thread);
#define HCI_H4_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE)
#define HCI_H4_TASK_STACK_SIZE (2048 + BT_TASK_EXTRA_STACK_SIZE)
#define HCI_H4_TASK_PRIO (configMAX_PRIORITIES - 4)
#define HCI_H4_TASK_NAME "hciH4T"
#define HCI_H4_QUEUE_LEN 1
#define BTU_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE)
#define BTU_TASK_STACK_SIZE (CONFIG_BT_BTU_TASK_STACK_SIZE + BT_TASK_EXTRA_STACK_SIZE)
#define BTU_TASK_PRIO (configMAX_PRIORITIES - 5)
#define BTU_TASK_NAME "btuT"
#define BTU_QUEUE_LEN 50
#define BTC_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE)
#define BTC_TASK_STACK_SIZE (CONFIG_BT_BTC_TASK_STACK_SIZE + BT_TASK_EXTRA_STACK_SIZE) //by menuconfig
#define BTC_TASK_NAME "btcT"
#define BTC_TASK_PRIO (configMAX_PRIORITIES - 6)
#define BTC_TASK_QUEUE_LEN 60
#define BTC_A2DP_SINK_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE)
#define BTC_A2DP_SINK_TASK_STACK_SIZE (CONFIG_BT_A2DP_SINK_TASK_STACK_SIZE + BT_TASK_EXTRA_STACK_SIZE) // by menuconfig
#define BTC_A2DP_SINK_TASK_NAME "BtA2dSinkT"
#define BTC_A2DP_SINK_TASK_PRIO (configMAX_PRIORITIES - 3)
#define BTC_A2DP_SINK_DATA_QUEUE_LEN (3)
#define BTC_A2DP_SINK_CTRL_QUEUE_LEN (5)
#define BTC_A2DP_SINK_TASK_QUEUE_SET_LEN (BTC_A2DP_SINK_DATA_QUEUE_LEN + BTC_A2DP_SINK_CTRL_QUEUE_LEN)
#define BTC_A2DP_SOURCE_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE)
#define BTC_A2DP_SOURCE_TASK_STACK_SIZE (CONFIG_BT_A2DP_SOURCE_TASK_STACK_SIZE + BT_TASK_EXTRA_STACK_SIZE) // by menuconfig
#define BTC_A2DP_SOURCE_TASK_NAME "BtA2dSourceT"
#define BTC_A2DP_SOURCE_TASK_PRIO (configMAX_PRIORITIES - 3)
#define BTC_A2DP_SOURCE_DATA_QUEUE_LEN (1)
#define BTC_A2DP_SOURCE_CTRL_QUEUE_LEN (5)
#define BTC_A2DP_SOURCE_TASK_QUEUE_SET_LEN (BTC_A2DP_SOURCE_DATA_QUEUE_LEN + BTC_A2DP_SOURCE_CTRL_QUEUE_LEN)
#define TASK_POST_NON_BLOCKING (0)
#define TASK_POST_BLOCKING (portMAX_DELAY)
typedef uint32_t task_post_t; /* Timeout of task post return, unit TICK */
typedef enum {
TASK_POST_SUCCESS = 0,
TASK_POST_FAIL,
} task_post_status_t;
task_post_status_t btu_task_post(uint32_t sig, void *param, task_post_t timeout);
task_post_status_t hci_host_task_post(task_post_t timeout);
task_post_status_t hci_hal_h4_task_post(task_post_t timeout);
/* brief: Get the size of the specified queue
* param thread: point of thread handler
* param wq_idx: the queue index of the thread
* return: queue size
*/
int osi_thread_queue_wait_size(osi_thread_t *thread, int wq_idx);
#endif /* __THREAD_H__ */

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
** once during the start up of the stack.
**
** Returns void
** Returns status
**
*******************************************************************************/
void A2D_Init(void)
bt_status_t A2D_Init(void)
{
#if (A2D_DYNAMIC_MEMORY)
a2d_cb_ptr = (tA2D_CB *)osi_malloc(sizeof(tA2D_CB));
if (!a2d_cb_ptr) {
return BT_STATUS_NOMEM;
}
#endif /* #if (A2D_DYNAMIC_MEMORY) */
memset(&a2d_cb, 0, sizeof(tA2D_CB));
@ -389,6 +392,7 @@ void A2D_Init(void)
#else
a2d_cb.trace_level = BT_TRACE_LEVEL_NONE;
#endif
return BT_STATUS_SUCCESS;
}
/*******************************************************************************
@ -404,8 +408,10 @@ void A2D_Init(void)
void A2D_Deinit(void)
{
#if (A2D_DYNAMIC_MEMORY)
if (a2d_cb_ptr) {
osi_free(a2d_cb_ptr);
a2d_cb_ptr = NULL;
}
#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))
{
while (!p_lcb->cong &&
(p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_lcb->tx_q)) != NULL)
(p_buf = (BT_HDR *)fixed_queue_dequeue(p_lcb->tx_q, 0)) != NULL)
{
if (L2CA_DataWrite(p_lcb->ch_lcid, p_buf) == L2CAP_DW_CONGESTED)
{
@ -569,7 +569,7 @@ void avct_lcb_send_msg(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data)
}
if (p_lcb->cong == TRUE) {
fixed_queue_enqueue(p_lcb->tx_q, p_buf);
fixed_queue_enqueue(p_lcb->tx_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT);
}
/* send message to L2CAP */

View File

@ -68,7 +68,7 @@ static void avdt_ccb_clear_ccb(tAVDT_CCB *p_ccb)
}
/* clear out response queue */
while ((p_buf = (BT_HDR *) fixed_queue_try_dequeue(p_ccb->rsp_q)) != NULL) {
while ((p_buf = (BT_HDR *) fixed_queue_dequeue(p_ccb->rsp_q, 0)) != NULL) {
osi_free(p_buf);
}
}
@ -659,7 +659,7 @@ void avdt_ccb_clear_cmds(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
avdt_ccb_cmd_fail(p_ccb, (tAVDT_CCB_EVT *) &err_code);
/* set up next message */
p_ccb->p_curr_cmd = (BT_HDR *) fixed_queue_try_dequeue(p_ccb->cmd_q);
p_ccb->p_curr_cmd = (BT_HDR *) fixed_queue_dequeue(p_ccb->cmd_q, 0);
} while (p_ccb->p_curr_cmd != NULL);
@ -812,7 +812,7 @@ void avdt_ccb_snd_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
** not congested, not sending fragment, not waiting for response
*/
if ((!p_ccb->cong) && (p_ccb->p_curr_msg == NULL) && (p_ccb->p_curr_cmd == NULL)) {
if ((p_msg = (BT_HDR *) fixed_queue_try_dequeue(p_ccb->cmd_q)) != NULL) {
if ((p_msg = (BT_HDR *) fixed_queue_dequeue(p_ccb->cmd_q, 0)) != NULL) {
/* make a copy of buffer in p_curr_cmd */
if ((p_ccb->p_curr_cmd = (BT_HDR *) osi_malloc(AVDT_CMD_BUF_SIZE)) != NULL) {
memcpy(p_ccb->p_curr_cmd, p_msg, (sizeof(BT_HDR) + p_msg->offset + p_msg->len));
@ -846,7 +846,7 @@ void avdt_ccb_snd_msg(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
}
/* do we have responses to send? send them */
else if (!fixed_queue_is_empty(p_ccb->rsp_q)) {
while ((p_msg = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->rsp_q)) != NULL) {
while ((p_msg = (BT_HDR *)fixed_queue_dequeue(p_ccb->rsp_q, 0)) != NULL) {
if (avdt_msg_send(p_ccb, p_msg) == TRUE) {
/* break out if congested */
break;

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;
/* queue message and trigger ccb to send it */
fixed_queue_enqueue(p_ccb->cmd_q, p_buf);
fixed_queue_enqueue(p_ccb->cmd_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT);
avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL);
}
@ -1487,7 +1487,7 @@ void avdt_msg_send_rsp(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params)
AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_RSP, p_params->hdr.label);
/* queue message and trigger ccb to send it */
fixed_queue_enqueue(p_ccb->rsp_q, p_buf);
fixed_queue_enqueue(p_ccb->rsp_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT);
avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL);
}
@ -1547,7 +1547,7 @@ void avdt_msg_send_rej(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params)
AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_REJ, p_params->hdr.label);
/* queue message and trigger ccb to send it */
fixed_queue_enqueue(p_ccb->rsp_q, p_buf);
fixed_queue_enqueue(p_ccb->rsp_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT);
avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL);
}
@ -1591,7 +1591,7 @@ void avdt_msg_send_grej(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params)
AVDT_TRACE_DEBUG("avdt_msg_send_grej");
/* queue message and trigger ccb to send it */
fixed_queue_enqueue(p_ccb->rsp_q, p_buf);
fixed_queue_enqueue(p_ccb->rsp_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT);
avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL);
}

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 */
AVDT_TRACE_WARNING("*** Dropped media packet; congested");
BT_HDR *p_frag;
while ((p_frag = (BT_HDR*)fixed_queue_try_dequeue(p_scb->frag_q)) != NULL)
while ((p_frag = (BT_HDR*)fixed_queue_dequeue(p_scb->frag_q, 0)) != NULL)
osi_free(p_frag);
}
@ -1397,7 +1397,7 @@ void avdt_scb_snd_stream_close(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
/* clean fragments queue */
BT_HDR *p_frag;
while ((p_frag = (BT_HDR*)fixed_queue_try_dequeue(p_scb->frag_q)) != NULL) {
while ((p_frag = (BT_HDR*)fixed_queue_dequeue(p_scb->frag_q, 0)) != NULL) {
osi_free(p_frag);
}
p_scb->frag_off = 0;
@ -1824,7 +1824,7 @@ void avdt_scb_free_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
#if AVDT_MULTIPLEXING == TRUE
/* clean fragments queue */
BT_HDR *p_frag;
while ((p_frag = (BT_HDR*)fixed_queue_try_dequeue(p_scb->frag_q)) != NULL) {
while ((p_frag = (BT_HDR*)fixed_queue_dequeue(p_scb->frag_q, 0)) != NULL) {
osi_free(p_frag);
}
#endif
@ -1880,7 +1880,7 @@ void avdt_scb_clr_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
AVDT_TRACE_DEBUG("Dropped fragments queue");
/* clean fragments queue */
BT_HDR *p_frag;
while ((p_frag = (BT_HDR*)fixed_queue_try_dequeue(p_scb->frag_q)) != NULL) {
while ((p_frag = (BT_HDR*)fixed_queue_dequeue(p_scb->frag_q, 0)) != NULL) {
osi_free(p_frag);
}
p_scb->frag_off = 0;
@ -1933,7 +1933,7 @@ void avdt_scb_chk_snd_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
L2CA_FlushChannel(avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_scb->p_ccb)][avdt_ad_type_to_tcid(AVDT_CHAN_MEDIA, p_scb)].lcid),
L2CAP_FLUSH_CHANS_GET);
#endif
while ((p_pkt = (BT_HDR*)fixed_queue_try_dequeue(p_scb->frag_q)) != NULL) {
while ((p_pkt = (BT_HDR*)fixed_queue_dequeue(p_scb->frag_q, 0)) != NULL) {
sent = TRUE;
AVDT_TRACE_DEBUG("Send fragment len=%d\n", p_pkt->len);
/* fragments queue contains fragment to send */
@ -2096,7 +2096,7 @@ void avdt_scb_queue_frags(tAVDT_SCB *p_scb, UINT8 **pp_data, UINT32 *p_data_len,
UINT16_TO_BE_STREAM(p, p_frag->layer_specific );
}
/* put fragment into gueue */
fixed_queue_enqueue(p_scb->frag_q, p_frag);
fixed_queue_enqueue(p_scb->frag_q, p_frag, FIXED_QUEUE_MAX_TIMEOUT);
num_frag--;
}
}

View File

@ -340,13 +340,16 @@ UINT8 AVRC_SetTraceLevel (UINT8 new_level)
** control block (if using dynamic memory), and initializes the
** control block and tracing level.
**
** Returns void
** Returns status
**
*******************************************************************************/
void AVRC_Init(void)
bt_status_t AVRC_Init(void)
{
#if AVRC_DYNAMIC_MEMORY
avrc_cb_ptr = (tAVRC_CB *)osi_malloc(sizeof(tAVRC_CB));
if (!avrc_cb_ptr) {
return BT_STATUS_NOMEM;
}
#endif /* #if AVRC_DYNAMIC_MEMORY */
memset(&avrc_cb, 0, sizeof(tAVRC_CB));
@ -355,6 +358,7 @@ void AVRC_Init(void)
#else
avrc_cb.trace_level = BT_TRACE_LEVEL_NONE;
#endif
return BT_STATUS_SUCCESS;
}
/*******************************************************************************
@ -371,8 +375,10 @@ void AVRC_Init(void)
void AVRC_Deinit(void)
{
#if AVRC_DYNAMIC_MEMORY
if (avrc_cb_ptr){
osi_free(avrc_cb_ptr);
avrc_cb_ptr = NULL;
}
#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 */
return (BTM_UNKNOWN_ADDR);
}
#if (BLE_INCLUDED == TRUE)
tBTM_STATUS BTM_BleReadAdvTxPower(tBTM_CMPL_CB *p_cb)
{
BOOLEAN ret;
@ -2074,6 +2076,7 @@ void BTM_BleGetWhiteListSize(uint16_t *length)
*length = p_cb->white_list_avail_size;
return;
}
#endif ///BLE_INCLUDED == TRUE
/*******************************************************************************
**
@ -2361,7 +2364,7 @@ void btm_acl_resubmit_page (void)
BD_ADDR bda;
BTM_TRACE_DEBUG ("btm_acl_resubmit_page\n");
/* If there were other page request schedule can start the next one */
if ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(btm_cb.page_queue)) != NULL) {
if ((p_buf = (BT_HDR *)fixed_queue_dequeue(btm_cb.page_queue, 0)) != NULL) {
/* skip 3 (2 bytes opcode and 1 byte len) to get to the bd_addr
* for both create_conn and rmt_name */
pp = (UINT8 *)(p_buf + 1) + p_buf->offset + 3;
@ -2392,7 +2395,7 @@ void btm_acl_reset_paging (void)
BT_HDR *p;
BTM_TRACE_DEBUG ("btm_acl_reset_paging\n");
/* If we sent reset we are definitely not paging any more */
while ((p = (BT_HDR *)fixed_queue_try_dequeue(btm_cb.page_queue)) != NULL) {
while ((p = (BT_HDR *)fixed_queue_dequeue(btm_cb.page_queue, 0)) != NULL) {
osi_free (p);
}
@ -2416,7 +2419,7 @@ void btm_acl_paging (BT_HDR *p, BD_ADDR bda)
(bda[0] << 16) + (bda[1] << 8) + bda[2], (bda[3] << 16) + (bda[4] << 8) + bda[5]);
if (btm_cb.discing) {
btm_cb.paging = TRUE;
fixed_queue_enqueue(btm_cb.page_queue, p);
fixed_queue_enqueue(btm_cb.page_queue, p, FIXED_QUEUE_MAX_TIMEOUT);
} else {
if (!BTM_ACL_IS_CONNECTED (bda)) {
BTM_TRACE_DEBUG ("connecting_bda: %06x%06x\n",
@ -2426,7 +2429,7 @@ void btm_acl_paging (BT_HDR *p, BD_ADDR bda)
btm_cb.connecting_bda[5]);
if (btm_cb.paging &&
memcmp (bda, btm_cb.connecting_bda, BD_ADDR_LEN) != 0) {
fixed_queue_enqueue(btm_cb.page_queue, p);
fixed_queue_enqueue(btm_cb.page_queue, p, FIXED_QUEUE_MAX_TIMEOUT);
} else {
p_dev_rec = btm_find_or_alloc_dev (bda);
memcpy (btm_cb.connecting_bda, p_dev_rec->bd_addr, BD_ADDR_LEN);

View File

@ -24,8 +24,6 @@
******************************************************************************/
#include "common/bt_target.h"
#if BLE_INCLUDED == TRUE
#include <string.h>
#include "stack/bt_types.h"
@ -41,7 +39,7 @@
//#define LOG_TAG "bt_btm_ble"
//#include "osi/include/log.h"
#if BLE_INCLUDED == TRUE
#if SMP_INCLUDED == TRUE
// The temp variable to pass parameter between functions when in the connected event callback.
static BOOLEAN temp_enhanced = FALSE;
@ -667,7 +665,7 @@ void BTM_ReadDevInfo (BD_ADDR remote_bda, tBT_DEVICE_TYPE *p_dev_type, tBLE_ADDR
BTM_TRACE_DEBUG ("btm_find_dev_type - device_type = %d addr_type = %d", *p_dev_type , *p_addr_type);
}
#endif ///BLE_INCLUDED == TRUE
/*******************************************************************************
**
@ -703,7 +701,7 @@ BOOLEAN BTM_ReadConnectedTransportAddress(BD_ADDR remote_bda, tBT_TRANSPORT tran
}
return FALSE;
}
#if (BLE_INCLUDED == TRUE)
if (transport == BT_TRANSPORT_LE) {
memcpy(remote_bda, p_dev_rec->ble.pseudo_addr, BD_ADDR_LEN);
if (btm_bda_to_acl(p_dev_rec->ble.pseudo_addr, transport) != NULL) {
@ -712,10 +710,11 @@ BOOLEAN BTM_ReadConnectedTransportAddress(BD_ADDR remote_bda, tBT_TRANSPORT tran
return FALSE;
}
}
#endif ///BLE_INCLUDED == TRUE
return FALSE;
}
#if (BLE_INCLUDED == TRUE)
/*******************************************************************************
**
** Function BTM_BleReceiverTest
@ -1104,6 +1103,7 @@ void btm_ble_increment_sign_ctr(BD_ADDR bd_addr, BOOLEAN is_local )
}
}
#endif ///SMP_INCLUDED == TRUE
#endif ///BLE_INCLUDED == TRUE
/*******************************************************************************
**
@ -1116,6 +1116,7 @@ void btm_ble_increment_sign_ctr(BD_ADDR bd_addr, BOOLEAN is_local )
**
*******************************************************************************/
#if (SMP_INCLUDED == TRUE)
#if (BLE_INCLUDED == TRUE)
BOOLEAN btm_ble_get_enc_key_type(BD_ADDR bd_addr, UINT8 *p_key_types)
{
tBTM_SEC_DEV_REC *p_dev_rec;
@ -1160,7 +1161,6 @@ BOOLEAN btm_get_local_div (BD_ADDR bd_addr, UINT16 *p_div)
return status;
}
/*******************************************************************************
**
** Function btm_sec_save_le_key
@ -1420,9 +1420,10 @@ void btm_ble_link_sec_check(BD_ADDR bd_addr, tBTM_LE_AUTH_REQ auth_req, tBTM_BLE
}
#endif ///BLE_INCLUDED == TRUE
#endif ///SMP_INCLUDED == TRUE
#if (BLE_INCLUDED == TRUE)
/*******************************************************************************
**
** Function btm_ble_set_encryption
@ -2113,10 +2114,9 @@ UINT8 btm_proc_smp_cback(tSMP_EVT event, BD_ADDR bd_addr, tSMP_EVT_DATA *p_data)
}
#endif
BTM_TRACE_DEBUG ("btm_cb pairing_state=%x pairing_flags=%x pin_code_len=%x",
BTM_TRACE_DEBUG ("btm_cb pairing_state=%x pairing_flags=%x",
btm_cb.pairing_state,
btm_cb.pairing_flags,
btm_cb.pin_code_len );
btm_cb.pairing_flags);
BTM_TRACE_DEBUG ("btm_cb.pairing_bda %02x:%02x:%02x:%02x:%02x:%02x",
btm_cb.pairing_bda[0], btm_cb.pairing_bda[1], btm_cb.pairing_bda[2],
btm_cb.pairing_bda[3], btm_cb.pairing_bda[4], btm_cb.pairing_bda[5]);

View File

@ -48,8 +48,16 @@
#define BTM_BLE_PF_BIT_TO_MASK(x) (UINT16)(1 << (x))
#if BTM_DYNAMIC_MEMORY == FALSE
tBTM_BLE_ADV_FILTER_CB btm_ble_adv_filt_cb;
tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
tBTM_BLE_VSC_CB cmn_ble_adv_vsc_cb;
#else
tBTM_BLE_ADV_FILTER_CB *btm_ble_adv_filt_cb_ptr;
tBTM_BLE_VSC_CB *cmn_ble_adv_vsc_cb_ptr;
#define btm_ble_adv_filt_cb (*btm_ble_adv_filt_cb_ptr)
#define cmn_ble_adv_vsc_cb (*cmn_ble_adv_vsc_cb_ptr)
#endif
static const BD_ADDR na_bda = {0};
static UINT8 btm_ble_cs_update_pf_counter(tBTM_BLE_SCAN_COND_OP action,
@ -87,13 +95,13 @@ tBTM_STATUS btm_ble_obtain_vsc_details()
tBTM_STATUS st = BTM_SUCCESS;
#if BLE_VND_INCLUDED == TRUE
BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb);
if (0 == cmn_ble_vsc_cb.max_filter) {
BTM_BleGetVendorCapabilities(&cmn_ble_adv_vsc_cb);
if (0 == cmn_ble_adv_vsc_cb.max_filter) {
st = BTM_MODE_UNSUPPORTED;
return st;
}
#else
cmn_ble_vsc_cb.max_filter = BTM_BLE_MAX_FILTER_COUNTER;
cmn_ble_adv_vsc_cb.max_filter = BTM_BLE_MAX_FILTER_COUNTER;
#endif
return st;
}
@ -367,7 +375,7 @@ tBTM_BLE_PF_COUNT *btm_ble_find_addr_filter_counter(tBLE_BD_ADDR *p_le_bda)
return &btm_ble_adv_filt_cb.p_addr_filter_count[0];
}
for (i = 0; i < cmn_ble_vsc_cb.max_filter; i ++, p_addr_filter ++) {
for (i = 0; i < cmn_ble_adv_vsc_cb.max_filter; i ++, p_addr_filter ++) {
if (p_addr_filter->in_use &&
memcmp(p_le_bda->bda, p_addr_filter->bd_addr, BD_ADDR_LEN) == 0) {
return p_addr_filter;
@ -390,7 +398,7 @@ tBTM_BLE_PF_COUNT *btm_ble_alloc_addr_filter_counter(BD_ADDR bd_addr)
UINT8 i;
tBTM_BLE_PF_COUNT *p_addr_filter = &btm_ble_adv_filt_cb.p_addr_filter_count[1];
for (i = 0; i < cmn_ble_vsc_cb.max_filter; i ++, p_addr_filter ++) {
for (i = 0; i < cmn_ble_adv_vsc_cb.max_filter; i ++, p_addr_filter ++) {
if (memcmp(na_bda, p_addr_filter->bd_addr, BD_ADDR_LEN) == 0) {
memcpy(p_addr_filter->bd_addr, bd_addr, BD_ADDR_LEN);
p_addr_filter->in_use = TRUE;
@ -418,7 +426,7 @@ BOOLEAN btm_ble_dealloc_addr_filter_counter(tBLE_BD_ADDR *p_bd_addr, UINT8 filte
memset(&btm_ble_adv_filt_cb.p_addr_filter_count[0], 0, sizeof(tBTM_BLE_PF_COUNT));
}
for (i = 0; i < cmn_ble_vsc_cb.max_filter; i ++, p_addr_filter ++) {
for (i = 0; i < cmn_ble_adv_vsc_cb.max_filter; i ++, p_addr_filter ++) {
if ((p_addr_filter->in_use) && (NULL == p_bd_addr ||
(NULL != p_bd_addr &&
memcmp(p_bd_addr->bda, p_addr_filter->bd_addr, BD_ADDR_LEN) == 0))) {
@ -682,7 +690,7 @@ UINT8 btm_ble_cs_update_pf_counter(tBTM_BLE_SCAN_COND_OP action,
}
BTM_TRACE_DEBUG("counter = %d, maxfilt = %d, num_avbl=%d",
p_counter[cond_type], cmn_ble_vsc_cb.max_filter, num_available);
p_counter[cond_type], cmn_ble_adv_vsc_cb.max_filter, num_available);
return p_counter[cond_type];
}
} else {
@ -1052,12 +1060,12 @@ tBTM_STATUS BTM_BleAdvFilterParamSetup(int action, tBTM_BLE_PF_FILT_INDEX filt_i
/* set onlost timeout */
UINT16_TO_STREAM(p, p_filt_params->lost_timeout);
/* set num_of_track_entries for firmware greater than L-release version */
if (cmn_ble_vsc_cb.version_supported > BTM_VSC_CHIP_CAPABILITY_L_VERSION) {
if (cmn_ble_adv_vsc_cb.version_supported > BTM_VSC_CHIP_CAPABILITY_L_VERSION) {
UINT16_TO_STREAM(p, p_filt_params->num_of_tracking_entries);
}
}
if (cmn_ble_vsc_cb.version_supported == BTM_VSC_CHIP_CAPABILITY_L_VERSION) {
if (cmn_ble_adv_vsc_cb.version_supported == BTM_VSC_CHIP_CAPABILITY_L_VERSION) {
len = BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_ADV_FILT_FEAT_SELN_LEN;
} else {
len = BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_ADV_FILT_FEAT_SELN_LEN +
@ -1248,14 +1256,24 @@ tBTM_STATUS BTM_BleCfgFilterCondition(tBTM_BLE_SCAN_COND_OP action,
*******************************************************************************/
void btm_ble_adv_filter_init(void)
{
memset(&btm_ble_adv_filt_cb, 0, sizeof(tBTM_BLE_MULTI_ADV_CB));
#if BTM_DYNAMIC_MEMORY == TRUE
btm_ble_adv_filt_cb_ptr = (tBTM_BLE_ADV_FILTER_CB *)osi_malloc(sizeof(tBTM_BLE_ADV_FILTER_CB));
cmn_ble_adv_vsc_cb_ptr = (tBTM_BLE_VSC_CB *)osi_malloc(sizeof(tBTM_BLE_VSC_CB));
if (btm_ble_adv_filt_cb_ptr == NULL || cmn_ble_adv_vsc_cb_ptr == NULL) {
BTM_TRACE_ERROR("%s malloc failed", __func__);
return;
}
memset((void *)btm_ble_adv_filt_cb_ptr, 0, sizeof(tBTM_BLE_ADV_FILTER_CB));
memset((void *)cmn_ble_adv_vsc_cb_ptr, 0, sizeof(tBTM_BLE_VSC_CB));
#endif
memset(&btm_ble_adv_filt_cb, 0, sizeof(tBTM_BLE_ADV_FILTER_CB));
if (BTM_SUCCESS != btm_ble_obtain_vsc_details()) {
return;
}
if (cmn_ble_vsc_cb.max_filter > 0) {
if (cmn_ble_adv_vsc_cb.max_filter > 0) {
btm_ble_adv_filt_cb.p_addr_filter_count =
(tBTM_BLE_PF_COUNT *) osi_malloc( sizeof(tBTM_BLE_PF_COUNT) * cmn_ble_vsc_cb.max_filter);
(tBTM_BLE_PF_COUNT *) osi_malloc( sizeof(tBTM_BLE_PF_COUNT) * cmn_ble_adv_vsc_cb.max_filter);
}
}
@ -1276,6 +1294,13 @@ void btm_ble_adv_filter_cleanup(void)
osi_free(btm_ble_adv_filt_cb.p_addr_filter_count);
btm_ble_adv_filt_cb.p_addr_filter_count = NULL;
}
#if BTM_DYNAMIC_MEMORY == TRUE
osi_free(btm_ble_adv_filt_cb_ptr);
btm_ble_adv_filt_cb_ptr = NULL;
osi_free(cmn_ble_adv_vsc_cb_ptr);
cmn_ble_adv_vsc_cb_ptr = NULL;
#endif
}
#endif

View File

@ -30,9 +30,15 @@
#if (BLE_INCLUDED == TRUE)
#if BTM_DYNAMIC_MEMORY == FALSE
tBTM_BLE_BATCH_SCAN_CB ble_batchscan_cb;
tBTM_BLE_ADV_TRACK_CB ble_advtrack_cb;
#else
tBTM_BLE_BATCH_SCAN_CB *ble_batchscan_cb_ptr;
tBTM_BLE_ADV_TRACK_CB *ble_advtrack_cb_ptr;
#define ble_batchscan_cb (*ble_batchscan_cb_ptr)
#define ble_advtrack_cb (*ble_advtrack_cb_ptr)
#endif
/* length of each batch scan command */
#define BTM_BLE_BATCH_SCAN_STORAGE_CFG_LEN 4
@ -896,6 +902,14 @@ tBTM_STATUS BTM_BleTrackAdvertiser(tBTM_BLE_TRACK_ADV_CBACK *p_track_cback,
*******************************************************************************/
void btm_ble_batchscan_init(void)
{
#if BTM_DYNAMIC_MEMORY == TRUE
ble_batchscan_cb_ptr = (tBTM_BLE_BATCH_SCAN_CB *)osi_malloc(sizeof(tBTM_BLE_BATCH_SCAN_CB));
ble_advtrack_cb_ptr = (tBTM_BLE_ADV_TRACK_CB *)osi_malloc(sizeof(tBTM_BLE_ADV_TRACK_CB));
if (ble_batchscan_cb_ptr == NULL || ble_advtrack_cb_ptr == NULL) {
BTM_TRACE_ERROR("%s malloc failed", __func__);
return;
}
#endif
BTM_TRACE_EVENT (" btm_ble_batchscan_init");
memset(&ble_batchscan_cb, 0, sizeof(tBTM_BLE_BATCH_SCAN_CB));
memset(&ble_advtrack_cb, 0, sizeof(tBTM_BLE_ADV_TRACK_CB));
@ -927,6 +941,13 @@ void btm_ble_batchscan_cleanup(void)
memset(&ble_batchscan_cb, 0, sizeof(tBTM_BLE_BATCH_SCAN_CB));
memset(&ble_advtrack_cb, 0, sizeof(tBTM_BLE_ADV_TRACK_CB));
#if BTM_DYNAMIC_MEMORY == TRUE
osi_free(ble_batchscan_cb_ptr);
osi_free(ble_advtrack_cb_ptr);
ble_batchscan_cb_ptr = NULL;
ble_advtrack_cb_ptr = NULL;
#endif
}
#endif

View File

@ -785,7 +785,7 @@ void btm_ble_enqueue_direct_conn_req(void *p_param)
p->p_param = p_param;
fixed_queue_enqueue(btm_cb.ble_ctr_cb.conn_pending_q, p);
fixed_queue_enqueue(btm_cb.ble_ctr_cb.conn_pending_q, p, FIXED_QUEUE_MAX_TIMEOUT);
}
/*******************************************************************************
**
@ -801,7 +801,7 @@ BOOLEAN btm_send_pending_direct_conn(void)
tBTM_BLE_CONN_REQ *p_req;
BOOLEAN rt = FALSE;
p_req = (tBTM_BLE_CONN_REQ*)fixed_queue_try_dequeue(btm_cb.ble_ctr_cb.conn_pending_q);
p_req = (tBTM_BLE_CONN_REQ*)fixed_queue_dequeue(btm_cb.ble_ctr_cb.conn_pending_q, 0);
if (p_req != NULL) {
rt = l2cble_init_direct_conn((tL2C_LCB *)(p_req->p_param));

View File

@ -57,7 +57,12 @@
#define MIN_ADV_LENGTH 2
#define BTM_VSC_CHIP_CAPABILITY_RSP_LEN_L_RELEASE 9
static tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
#if BTM_DYNAMIC_MEMORY == FALSE
static tBTM_BLE_VSC_CB cmn_ble_gap_vsc_cb;
#else
static tBTM_BLE_VSC_CB *cmn_ble_gap_vsc_cb_ptr;
#define cmn_ble_gap_vsc_cb (*cmn_ble_gap_vsc_cb_ptr)
#endif
#if BLE_VND_INCLUDED == TRUE
static tBTM_BLE_CTRL_FEATURES_CBACK *p_ctrl_le_feature_rd_cmpl_cback = NULL;
@ -241,7 +246,7 @@ uint8_t adv_param_status = 0;
uint8_t scan_enable_status = 0;
uint8_t scan_param_status = 0;
void btm_lock_init(void)
void btm_ble_lock_init(void)
{
osi_mutex_new(&adv_enable_lock);
osi_mutex_new(&adv_data_lock);
@ -250,7 +255,7 @@ void btm_lock_init(void)
osi_mutex_new(&scan_param_lock);
}
void btm_lock_free(void)
void btm_ble_lock_free(void)
{
osi_mutex_free(&adv_enable_lock);
osi_mutex_free(&adv_data_lock);
@ -259,7 +264,7 @@ void btm_lock_free(void)
osi_mutex_free(&scan_param_lock);
}
void btm_sem_init(void)
void btm_ble_sem_init(void)
{
osi_sem_new(&adv_enable_sem, 1, 0);
osi_sem_new(&adv_data_sem, 1, 0);
@ -268,7 +273,7 @@ void btm_sem_init(void)
osi_sem_new(&scan_param_sem, 1, 0);
}
void btm_sem_free(void)
void btm_ble_sem_free(void)
{
osi_sem_free(&adv_enable_sem);
osi_sem_free(&adv_data_sem);
@ -447,7 +452,7 @@ tBTM_STATUS BTM_BleObserve(BOOLEAN start, UINT32 duration,
btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN);
#endif
if (cmn_ble_vsc_cb.extended_scan_support == 0) {
if (cmn_ble_gap_vsc_cb.extended_scan_support == 0) {
btsnd_hcic_ble_set_scan_params(p_inq->scan_type, (UINT16)scan_interval,
(UINT16)scan_window,
btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type,
@ -4292,10 +4297,18 @@ BOOLEAN btm_ble_update_mode_operation(UINT8 link_role, BD_ADDR bd_addr, UINT8 st
*******************************************************************************/
void btm_ble_init (void)
{
tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
BTM_TRACE_DEBUG("%s", __func__);
#if BTM_DYNAMIC_MEMORY == TRUE
cmn_ble_gap_vsc_cb_ptr = (tBTM_BLE_VSC_CB *)osi_malloc(sizeof(tBTM_BLE_VSC_CB));
if (cmn_ble_gap_vsc_cb_ptr == NULL) {
BTM_TRACE_ERROR("%s malloc failed", __func__);
return;
}
#endif
tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
btu_free_timer(&p_cb->obs_timer_ent);
btu_free_timer(&p_cb->scan_timer_ent);
btu_free_timer(&p_cb->inq_var.fast_adv_timer);
@ -4340,6 +4353,11 @@ void btm_ble_free (void)
BTM_TRACE_DEBUG("%s", __func__);
fixed_queue_free(p_cb->conn_pending_q, osi_free_func);
#if BTM_DYNAMIC_MEMORY == TRUE
osi_free(cmn_ble_gap_vsc_cb_ptr);
cmn_ble_gap_vsc_cb_ptr = NULL;
#endif
}
/*******************************************************************************

View File

@ -45,8 +45,15 @@
/************************************************************************************
** Static variables
************************************************************************************/
#if BTM_DYNAMIC_MEMORY == FALSE
tBTM_BLE_MULTI_ADV_CB btm_multi_adv_cb;
tBTM_BLE_MULTI_ADV_INST_IDX_Q btm_multi_adv_idx_q;
#else
tBTM_BLE_MULTI_ADV_CB *btm_multi_adv_cb_ptr;
tBTM_BLE_MULTI_ADV_INST_IDX_Q *btm_multi_adv_idx_q_ptr;
#define btm_multi_adv_cb (*btm_multi_adv_cb_ptr)
#define btm_multi_adv_idx_q (*btm_multi_adv_idx_q_ptr)
#endif
/************************************************************************************
** Externs
@ -764,6 +771,15 @@ void btm_ble_multi_adv_vse_cback(UINT8 len, UINT8 *p)
*******************************************************************************/
void btm_ble_multi_adv_init()
{
#if BTM_DYNAMIC_MEMORY == TRUE
btm_multi_adv_cb_ptr = (tBTM_BLE_MULTI_ADV_CB *)osi_malloc(sizeof(tBTM_BLE_MULTI_ADV_CB));
btm_multi_adv_idx_q_ptr = (tBTM_BLE_MULTI_ADV_INST_IDX_Q *)osi_malloc(sizeof(tBTM_BLE_MULTI_ADV_INST_IDX_Q));
if (btm_multi_adv_cb_ptr == NULL || btm_multi_adv_idx_q_ptr == NULL) {
BTM_TRACE_ERROR("%s malloc failed", __func__);
return;
}
#endif
UINT8 i = 0;
memset(&btm_multi_adv_cb, 0, sizeof(tBTM_BLE_MULTI_ADV_CB));
memset (&btm_multi_adv_idx_q, 0, sizeof (tBTM_BLE_MULTI_ADV_INST_IDX_Q));
@ -823,6 +839,12 @@ void btm_ble_multi_adv_cleanup(void)
btm_multi_adv_cb.op_q.p_inst_id = NULL;
}
#if BTM_DYNAMIC_MEMORY == TRUE
osi_free(btm_multi_adv_cb_ptr);
osi_free(btm_multi_adv_idx_q_ptr);
btm_multi_adv_cb_ptr = NULL;
btm_multi_adv_idx_q_ptr = NULL;
#endif
}
/*******************************************************************************

View File

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

View File

@ -190,9 +190,9 @@ static void reset_complete(void)
l2c_link_processs_ble_num_bufs(controller->get_acl_buffer_count_ble());
}
#endif
#if (SMP_INCLUDED == TRUE)
#if (SMP_INCLUDED == TRUE && CLASSIC_BT_INCLUDED == TRUE)
BTM_SetPinType (btm_cb.cfg.pin_type, btm_cb.cfg.pin_code, btm_cb.cfg.pin_code_len);
#endif ///SMP_INCLUDED == TRUE
#endif ///SMP_INCLUDED == TRUE && CLASSIC_BT_INCLUDED == TRUE
for (int i = 0; i <= controller->get_last_features_classic_index(); i++) {
btm_decode_ext_features_page(i, controller->get_features_classic(i)->as_array);
}
@ -693,6 +693,7 @@ tBTM_STATUS BTM_VendorSpecificCommand(UINT16 opcode, UINT8 param_len,
void btm_vsc_complete (UINT8 *p, UINT16 opcode, UINT16 evt_len,
tBTM_CMPL_CB *p_vsc_cplt_cback)
{
#if (BLE_INCLUDED == TRUE)
tBTM_BLE_CB *ble_cb = &btm_cb.ble_ctr_cb;
switch(opcode) {
case HCI_VENDOR_BLE_LONG_ADV_DATA:
@ -721,6 +722,7 @@ void btm_vsc_complete (UINT8 *p, UINT16 opcode, UINT16 evt_len,
vcs_cplt_params.p_param_buf = p;
(*p_vsc_cplt_cback)(&vcs_cplt_params); /* Call the VSC complete callback function */
}
#endif
}
/*******************************************************************************

View File

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

View File

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

View File

@ -35,6 +35,7 @@
#include "l2c_int.h"
#include "osi/fixed_queue.h"
#include "osi/alarm.h"
#include "stack/btm_ble_api.h"
#if (BT_USE_TRACES == TRUE && BT_TRACE_VERBOSE == FALSE)
/* needed for sprintf() */
@ -368,6 +369,7 @@ BOOLEAN BTM_GetSecurityFlagsByTransport (BD_ADDR bd_addr, UINT8 *p_sec_flags,
return (FALSE);
}
#if (CLASSIC_BT_INCLUDED == TRUE)
/*******************************************************************************
**
** Function BTM_SetPinType
@ -392,6 +394,7 @@ void BTM_SetPinType (UINT8 pin_type, PIN_CODE pin_code, UINT8 pin_code_len)
btm_cb.cfg.pin_code_len = pin_code_len;
memcpy (btm_cb.cfg.pin_code, pin_code, pin_code_len);
}
#endif ///CLASSIC_BT_INCLUDED == TRUE
/*******************************************************************************
**
@ -824,6 +827,7 @@ void btm_sec_clr_temp_auth_service (BD_ADDR bda)
**
*******************************************************************************/
#if (SMP_INCLUDED == TRUE)
#if (CLASSIC_BT_INCLUDED == TRUE)
void BTM_PINCodeReply (BD_ADDR bd_addr, UINT8 res, UINT8 pin_len, UINT8 *p_pin, UINT32 trusted_mask[])
{
tBTM_SEC_DEV_REC *p_dev_rec;
@ -930,6 +934,7 @@ void BTM_PINCodeReply (BD_ADDR bd_addr, UINT8 res, UINT8 pin_len, UINT8 *p_pin,
#endif
btsnd_hcic_pin_code_req_reply (bd_addr, pin_len, p_pin);
}
#endif ///CLASSIC_BT_INCLUDED == TRUE
#endif ///SMP_INCLUDED == TRUE
@ -995,12 +1000,14 @@ tBTM_STATUS btm_sec_bond_by_transport (BD_ADDR bd_addr, tBT_TRANSPORT transport,
return (BTM_NO_RESOURCES);
}
#if (CLASSIC_BT_INCLUDED == TRUE)
/* Save the PIN code if we got a valid one */
if (p_pin && (pin_len <= PIN_CODE_LEN) && (pin_len != 0)) {
btm_cb.pin_code_len = pin_len;
p_dev_rec->pin_code_length = pin_len;
memcpy (btm_cb.pin_code, p_pin, PIN_CODE_LEN);
}
#endif ///CLASSIC_BT_INCLUDED == TRUE
memcpy (btm_cb.pairing_bda, bd_addr, BD_ADDR_LEN);
@ -1034,6 +1041,8 @@ tBTM_STATUS btm_sec_bond_by_transport (BD_ADDR bd_addr, tBT_TRANSPORT transport,
BTM_TRACE_DEBUG ("after update sec_flags=0x%x\n", p_dev_rec->sec_flags);
#if (CLASSIC_BT_INCLUDED == TRUE)
if (!controller_get_interface()->supports_simple_pairing()) {
/* The special case when we authenticate keyboard. Set pin type to fixed */
/* It would be probably better to do it from the application, but it is */
@ -1045,6 +1054,7 @@ tBTM_STATUS btm_sec_bond_by_transport (BD_ADDR bd_addr, tBT_TRANSPORT transport,
btsnd_hcic_write_pin_type (HCI_PIN_TYPE_FIXED);
}
}
#endif ///CLASSIC_BT_INCLUDED == TRUE
for (ii = 0; ii <= HCI_EXT_FEATURES_PAGE_MAX; ii++) {
#if (!CONFIG_BT_STACK_NO_LOG)
@ -1133,6 +1143,7 @@ tBTM_STATUS btm_sec_bond_by_transport (BD_ADDR bd_addr, tBT_TRANSPORT transport,
tBTM_STATUS BTM_SecBondByTransport (BD_ADDR bd_addr, tBT_TRANSPORT transport,
UINT8 pin_len, UINT8 *p_pin, UINT32 trusted_mask[])
{
#if (BLE_INCLUDED == TRUE)
tBT_DEVICE_TYPE dev_type;
tBLE_ADDR_TYPE addr_type;
@ -1142,6 +1153,8 @@ tBTM_STATUS BTM_SecBondByTransport (BD_ADDR bd_addr, tBT_TRANSPORT transport,
(transport == BT_TRANSPORT_BR_EDR && (dev_type & BT_DEVICE_TYPE_BREDR) == 0)) {
return BTM_ILLEGAL_ACTION;
}
#endif ///BLE_INCLUDED == TRUE
return btm_sec_bond_by_transport(bd_addr, transport, pin_len, p_pin, trusted_mask);
}
#endif ///SMP_INCLUDED == TRUE
@ -1165,9 +1178,11 @@ tBTM_STATUS BTM_SecBondByTransport (BD_ADDR bd_addr, tBT_TRANSPORT transport,
tBTM_STATUS BTM_SecBond (BD_ADDR bd_addr, UINT8 pin_len, UINT8 *p_pin, UINT32 trusted_mask[])
{
tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR;
#if (BLE_INCLUDED == TRUE)
if (BTM_UseLeLink(bd_addr)) {
transport = BT_TRANSPORT_LE;
}
#endif ///BLE_INCLUDED == TRUE
return btm_sec_bond_by_transport(bd_addr, transport, pin_len, p_pin, trusted_mask);
}
/*******************************************************************************
@ -1789,53 +1804,6 @@ UINT16 BTM_BuildOobData(UINT8 *p_data, UINT16 max_len, BT_OCTET16 c,
return len;
}
/*******************************************************************************
**
** Function BTM_BothEndsSupportSecureConnections
**
** Description This function is called to check if both the local device and the peer device
** specified by bd_addr support BR/EDR Secure Connections.
**
** Parameters: bd_addr - address of the peer
**
** Returns TRUE if BR/EDR Secure Connections are supported by both local
** and the remote device.
** else FALSE.
**
*******************************************************************************/
BOOLEAN BTM_BothEndsSupportSecureConnections(BD_ADDR bd_addr)
{
return ((controller_get_interface()->supports_secure_connections()) &&
(BTM_PeerSupportsSecureConnections(bd_addr)));
}
/*******************************************************************************
**
** Function BTM_PeerSupportsSecureConnections
**
** Description This function is called to check if the peer supports
** BR/EDR Secure Connections.
**
** Parameters: bd_addr - address of the peer
**
** Returns TRUE if BR/EDR Secure Connections are supported by the peer,
** else FALSE.
**
*******************************************************************************/
BOOLEAN BTM_PeerSupportsSecureConnections(BD_ADDR bd_addr)
{
tBTM_SEC_DEV_REC *p_dev_rec;
if ((p_dev_rec = btm_find_dev(bd_addr)) == NULL) {
BTM_TRACE_WARNING("%s: unknown BDA: %08x%04x\n", __FUNCTION__,
(bd_addr[0] << 24) + (bd_addr[1] << 16) + (bd_addr[2] << 8) + bd_addr[3],
(bd_addr[4] << 8) + bd_addr[5]);
return FALSE;
}
return (p_dev_rec->remote_supports_secure_connections);
}
/*******************************************************************************
**
** Function BTM_ReadOobData
@ -1899,6 +1867,54 @@ UINT8 *BTM_ReadOobData(UINT8 *p_data, UINT8 eir_tag, UINT8 *p_len)
}
#endif ///BTM_OOB_INCLUDED == TRUE && SMP_INCLUDED == TRUE
#if (CLASSIC_BT_INCLUDED == TRUE)
/*******************************************************************************
**
** Function BTM_BothEndsSupportSecureConnections
**
** Description This function is called to check if both the local device and the peer device
** specified by bd_addr support BR/EDR Secure Connections.
**
** Parameters: bd_addr - address of the peer
**
** Returns TRUE if BR/EDR Secure Connections are supported by both local
** and the remote device.
** else FALSE.
**
*******************************************************************************/
BOOLEAN BTM_BothEndsSupportSecureConnections(BD_ADDR bd_addr)
{
return ((controller_get_interface()->supports_secure_connections()) &&
(BTM_PeerSupportsSecureConnections(bd_addr)));
}
/*******************************************************************************
**
** Function BTM_PeerSupportsSecureConnections
**
** Description This function is called to check if the peer supports
** BR/EDR Secure Connections.
**
** Parameters: bd_addr - address of the peer
**
** Returns TRUE if BR/EDR Secure Connections are supported by the peer,
** else FALSE.
**
*******************************************************************************/
BOOLEAN BTM_PeerSupportsSecureConnections(BD_ADDR bd_addr)
{
tBTM_SEC_DEV_REC *p_dev_rec;
if ((p_dev_rec = btm_find_dev(bd_addr)) == NULL) {
BTM_TRACE_WARNING("%s: unknown BDA: %08x%04x\n", __FUNCTION__,
(bd_addr[0] << 24) + (bd_addr[1] << 16) + (bd_addr[2] << 8) + bd_addr[3],
(bd_addr[4] << 8) + bd_addr[5]);
return FALSE;
}
return (p_dev_rec->remote_supports_secure_connections);
}
/*******************************************************************************
**
** Function BTM_SetOutService
@ -1913,7 +1929,6 @@ UINT8 *BTM_ReadOobData(UINT8 *p_data, UINT8 eir_tag, UINT8 *p_len)
** Returns void
**
*******************************************************************************/
#if (CLASSIC_BT_INCLUDED == TRUE)
void BTM_SetOutService(BD_ADDR bd_addr, UINT8 service_id, UINT32 mx_chan_id)
{
tBTM_SEC_DEV_REC *p_dev_rec;
@ -2776,7 +2791,7 @@ void btm_sec_check_pending_reqs (void)
btm_cb.sec_pending_q = fixed_queue_new(QUEUE_SIZE_MAX);
while ((p_e = (tBTM_SEC_QUEUE_ENTRY *)fixed_queue_try_dequeue(bq)) != NULL) {
while ((p_e = (tBTM_SEC_QUEUE_ENTRY *)fixed_queue_dequeue(bq, 0)) != NULL) {
/* Check that the ACL is still up before starting security procedures */
if (btm_bda_to_acl(p_e->bd_addr, p_e->transport) != NULL) {
if (p_e->psm != 0) {
@ -4117,8 +4132,10 @@ void btm_sec_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable)
if (p_dev_rec->no_smp_on_br) {
BTM_TRACE_DEBUG ("%s NO SM over BR/EDR\n", __func__);
} else {
#if (CLASSIC_BT_INCLUDED == TRUE)
BTM_TRACE_DEBUG ("%s start SM over BR/EDR\n", __func__);
SMP_BR_PairWith(p_dev_rec->bd_addr);
#endif ///CLASSIC_BT_INCLUDED == TRUE
}
}
} else {
@ -4924,6 +4941,7 @@ static void btm_sec_pairing_timeout (TIMER_LIST_ENT *p_tle)
}
}
#if (CLASSIC_BT_INCLUDED == TRUE)
/*******************************************************************************
**
** Function btm_sec_pin_code_request
@ -5061,6 +5079,7 @@ void btm_sec_pin_code_request (UINT8 *p_bda)
}
return;
}
#endif ///CLASSIC_BT_INCLUDED == TRUE
#endif ///SMP_INCLUDED == TRUE
@ -5589,10 +5608,12 @@ static void btm_restore_mode(void)
btsnd_hcic_write_auth_enable ((UINT8)(btm_cb.security_mode == BTM_SEC_MODE_LINK));
}
#if (CLASSIC_BT_INCLUDED == TRUE)
if (btm_cb.pin_type_changed) {
btm_cb.pin_type_changed = FALSE;
btsnd_hcic_write_pin_type (btm_cb.cfg.pin_type);
}
#endif ///CLASSIC_BT_INCLUDED == TRUE
}
#endif ///SMP_INCLUDED == TRUE
@ -5644,7 +5665,9 @@ static void btm_sec_change_pairing_state (tBTM_PAIRING_STATE new_state)
btu_stop_timer (&btm_cb.pairing_tle);
btm_cb.pairing_flags = 0;
#if (CLASSIC_BT_INCLUDED == TRUE)
btm_cb.pin_code_len = 0;
#endif ///CLASSIC_BT_INCLUDED == TRUE
/* Make sure the the lcb shows we are not bonding */
l2cu_update_lcb_4_bonding (btm_cb.pairing_bda, FALSE);
@ -5761,7 +5784,7 @@ static BOOLEAN btm_sec_queue_mx_request (BD_ADDR bd_addr, UINT16 psm, BOOLEAN
BTM_TRACE_EVENT ("%s() PSM: 0x%04x Is_Orig: %u mx_proto_id: %u mx_chan_id: %u\n",
__func__, psm, is_orig, mx_proto_id, mx_chan_id);
fixed_queue_enqueue(btm_cb.sec_pending_q, p_e);
fixed_queue_enqueue(btm_cb.sec_pending_q, p_e, FIXED_QUEUE_MAX_TIMEOUT);
return (TRUE);
}
@ -5770,9 +5793,11 @@ static BOOLEAN btm_sec_queue_mx_request (BD_ADDR bd_addr, UINT16 psm, BOOLEAN
}
static BOOLEAN btm_sec_check_prefetch_pin (tBTM_SEC_DEV_REC *p_dev_rec)
{
BOOLEAN rv = FALSE;
#if (CLASSIC_BT_INCLUDED == TRUE)
UINT8 major = (UINT8)(p_dev_rec->dev_class[1] & BTM_COD_MAJOR_CLASS_MASK);
UINT8 minor = (UINT8)(p_dev_rec->dev_class[2] & BTM_COD_MINOR_CLASS_MASK);
BOOLEAN rv = FALSE;
rv = TRUE;
if ((major == BTM_COD_MAJOR_AUDIO)
&& ((minor == BTM_COD_MINOR_CONFM_HANDSFREE) || (minor == BTM_COD_MINOR_CAR_AUDIO)) ) {
@ -5810,7 +5835,8 @@ static BOOLEAN btm_sec_check_prefetch_pin (tBTM_SEC_DEV_REC *p_dev_rec)
rv = TRUE;
}
#endif ///CLASSIC_BT_INCLUDED == TRUE
#
return rv;
}
@ -5857,7 +5883,7 @@ static BOOLEAN btm_sec_queue_encrypt_request (BD_ADDR bd_addr, tBT_TRANSPORT tra
*(UINT8 *)p_e->p_ref_data = *(UINT8 *)(p_ref_data);
p_e->transport = transport;
memcpy(p_e->bd_addr, bd_addr, BD_ADDR_LEN);
fixed_queue_enqueue(btm_cb.sec_pending_q, p_e);
fixed_queue_enqueue(btm_cb.sec_pending_q, p_e, FIXED_QUEUE_MAX_TIMEOUT);
return TRUE;
}
@ -5993,6 +6019,7 @@ static UINT16 btm_sec_set_serv_level4_flags(UINT16 cur_security, BOOLEAN is_orig
return cur_security | sec_level4_flags;
}
#endif ///SMP_INCLUDED == TRUE
/*******************************************************************************
**
** Function btm_sec_clear_ble_keys
@ -6004,6 +6031,7 @@ static UINT16 btm_sec_set_serv_level4_flags(UINT16 cur_security, BOOLEAN is_orig
** Returns void
**
*******************************************************************************/
#if (BLE_INCLUDED == TRUE)
void btm_sec_clear_ble_keys (tBTM_SEC_DEV_REC *p_dev_rec)
{
@ -6017,7 +6045,7 @@ void btm_sec_clear_ble_keys (tBTM_SEC_DEV_REC *p_dev_rec)
#endif
#endif
}
#endif ///BLE_INCLUDED == TRUE
/*******************************************************************************
**
** Function btm_sec_is_a_bonded_dev
@ -6034,7 +6062,7 @@ BOOLEAN btm_sec_is_a_bonded_dev (BD_ADDR bda)
BOOLEAN is_bonded = FALSE;
if (p_dev_rec &&
#if (SMP_INCLUDED == TRUE)
#if (SMP_INCLUDED == TRUE && BLE_INCLUDED == TRUE)
((p_dev_rec->ble.key_type && (p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_KNOWN)) ||
#else
(
@ -6057,10 +6085,10 @@ BOOLEAN btm_sec_is_a_bonded_dev (BD_ADDR bda)
*******************************************************************************/
BOOLEAN btm_sec_is_le_capable_dev (BD_ADDR bda)
{
tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bda);
BOOLEAN le_capable = FALSE;
#if (BLE_INCLUDED== TRUE)
tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bda);
if (p_dev_rec && (p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) == BT_DEVICE_TYPE_BLE) {
le_capable = TRUE;
}
@ -6077,6 +6105,7 @@ BOOLEAN btm_sec_is_le_capable_dev (BD_ADDR bda)
** Returns TRUE - found a bonded device
**
*******************************************************************************/
#if (BLE_INCLUDED == TRUE)
BOOLEAN btm_sec_find_bonded_dev (UINT8 start_idx, UINT8 *p_found_idx, tBTM_SEC_DEV_REC **p_rec)
{
BOOLEAN found = FALSE;
@ -6101,7 +6130,7 @@ BOOLEAN btm_sec_find_bonded_dev (UINT8 start_idx, UINT8 *p_found_idx, tBTM_SEC_D
#endif
return (found);
}
#endif ///BLE_INCLUDED == TRUE
/*******************************************************************************
**
** Function btm_sec_use_smp_br_chnl

View File

@ -32,13 +32,14 @@
#include "stack/rfcdefs.h"
#include "stack/btm_api.h"
#include "osi/fixed_queue.h"
#if (BLE_INCLUDED == TRUE)
#include "btm_ble_int.h"
#endif
#if (SMP_INCLUDED == TRUE)
#include "stack/smp_api.h"
#endif
#endif
#if BTM_MAX_LOC_BD_NAME_LEN > 0
typedef char tBTM_LOC_BD_NAME[BTM_MAX_LOC_BD_NAME_LEN + 1];
@ -855,9 +856,12 @@ typedef struct {
BOOLEAN pairing_disabled;
BOOLEAN connect_only_paired;
BOOLEAN security_mode_changed; /* mode changed during bonding */
BOOLEAN pin_type_changed; /* pin type changed during bonding */
BOOLEAN sec_req_pending; /* TRUE if a request is pending */
#if (CLASSIC_BT_INCLUDED == TRUE)
BOOLEAN pin_type_changed; /* pin type changed during bonding */
#endif ///CLASSIC_BT_INCLUDED == TRUE
#if (SMP_INCLUDED == TRUE)
#if (CLASSIC_BT_INCLUDED == TRUE)
// btla-specific ++
#ifdef PORCHE_PAIRING_CONFLICT
UINT8 pin_code_len_saved; /* for legacy devices */
@ -866,12 +870,14 @@ typedef struct {
UINT8 pin_code_len; /* for legacy devices */
PIN_CODE pin_code; /* for legacy devices */
UINT8 disc_reason; /* for legacy devices */
UINT16 disc_handle; /* for legacy devices */
#endif ///CLASSIC_BT_INCLUDED == TRUE
tBTM_PAIRING_STATE pairing_state; /* The current pairing state */
UINT8 pairing_flags; /* The current pairing flags */
BD_ADDR pairing_bda; /* The device currently pairing */
TIMER_LIST_ENT pairing_tle; /* Timer for pairing process */
UINT16 disc_handle; /* for legacy devices */
UINT8 disc_reason; /* for legacy devices */
#endif ///SMP_INCLUDED == TRUE
#if SMP_INCLUDED == TRUE || CLASSIC_BT_INCLUDED == TRUE
tBTM_SEC_SERV_REC sec_serv_rec[BTM_SEC_MAX_SERVICE_RECORDS];
@ -1122,10 +1128,10 @@ BOOLEAN btm_sec_is_le_capable_dev (BD_ADDR bda);
BOOLEAN btm_ble_init_pseudo_addr (tBTM_SEC_DEV_REC *p_dev_rec, BD_ADDR new_pseudo_addr);
extern BOOLEAN btm_ble_start_sec_check(BD_ADDR bd_addr, UINT16 psm, BOOLEAN is_originator,
tBTM_SEC_CALLBACK *p_callback, void *p_ref_data);
extern tBTM_SEC_SERV_REC *btm_sec_find_first_serv (CONNECTION_TYPE conn_type, UINT16 psm);
#endif /* BLE_INCLUDED */
extern tBTM_SEC_SERV_REC *btm_sec_find_first_serv (CONNECTION_TYPE conn_type, UINT16 psm);
tINQ_DB_ENT *btm_inq_db_new (BD_ADDR p_bda);
#if BTM_OOB_INCLUDED == TRUE
@ -1142,13 +1148,13 @@ void btm_acl_paging (BT_HDR *p, BD_ADDR dest);
UINT8 btm_sec_clr_service_by_psm (UINT16 psm);
void btm_sec_clr_temp_auth_service (BD_ADDR bda);
void btm_lock_init(void);
void btm_ble_lock_init(void);
void btm_sem_init(void);
void btm_ble_sem_init(void);
void btm_sem_free(void);
void btm_ble_sem_free(void);
void btm_lock_free(void);
void btm_ble_lock_free(void);
/*
#ifdef __cplusplus

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;
btu_task_post(SIG_BTU_HCI_MSG, event, TASK_POST_BLOCKING);
btu_task_post(SIG_BTU_HCI_MSG, event, OSI_THREAD_MAX_TIMEOUT);
}
@ -1291,7 +1291,7 @@ static void btu_hcif_command_status_evt(uint8_t status, BT_HDR *command, void *c
event->event = BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK;
btu_task_post(SIG_BTU_HCI_MSG, event, TASK_POST_BLOCKING);
btu_task_post(SIG_BTU_HCI_MSG, event, OSI_THREAD_MAX_TIMEOUT);
}
/*******************************************************************************
@ -1436,6 +1436,7 @@ static void btu_hcif_ssr_evt (UINT8 *p, UINT16 evt_len)
#if (SMP_INCLUDED == TRUE)
static void btu_hcif_pin_code_request_evt (UINT8 *p)
{
#if (CLASSIC_BT_INCLUDED == TRUE)
BD_ADDR bda;
STREAM_TO_BDADDR (bda, p);
@ -1445,6 +1446,7 @@ static void btu_hcif_pin_code_request_evt (UINT8 *p)
l2c_pin_code_request (bda);
btm_sec_pin_code_request (bda);
#endif ///CLASSIC_BT_INCLUDED == TRUE
}

View File

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

View File

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

View File

@ -21,8 +21,13 @@
#include "common/bt_target.h"
//#include "bt_utils.h"
#include "gap_int.h"
#include "osi/allocator.h"
#if GAP_DYNAMIC_MEMORY == FALSE
tGAP_CB gap_cb;
#else
tGAP_CB *gap_cb_ptr;
#endif
/*******************************************************************************
**
@ -52,11 +57,18 @@ UINT8 GAP_SetTraceLevel (UINT8 new_level)
** This routine should not be called except once per
** stack invocation.
**
** Returns Nothing
** Returns status
**
*******************************************************************************/
void GAP_Init(void)
bt_status_t GAP_Init(void)
{
#if GAP_DYNAMIC_MEMORY == TRUE
gap_cb_ptr = (tGAP_CB *)osi_malloc(sizeof(tGAP_CB));
if (!gap_cb_ptr) {
return BT_STATUS_NOMEM;
}
#endif
memset (&gap_cb, 0, sizeof (tGAP_CB));
#if defined(GAP_INITIAL_TRACE_LEVEL)
@ -72,5 +84,26 @@ void GAP_Init(void)
#if BLE_INCLUDED == TRUE && GATTS_INCLUDED == TRUE
gap_attr_db_init();
#endif
return BT_STATUS_SUCCESS;
}
/*******************************************************************************
**
** Function GAP_Deinit
**
** Description This function is called to deinitialize the control block
** for this layer.
**
** Returns void
**
*******************************************************************************/
void GAP_Deinit(void)
{
#if GAP_DYNAMIC_MEMORY == TRUE
if (gap_cb_ptr) {
osi_free(gap_cb_ptr);
gap_cb_ptr = NULL;
}
#endif
}

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);
static void gap_ble_c_cmpl_cback (UINT16 conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE *p_data);
static tGATT_CBACK gap_cback = {
static const tGATT_CBACK gap_cback = {
gap_ble_c_connect_cback,
gap_ble_c_cmpl_cback,
NULL,
@ -145,7 +145,7 @@ void gap_ble_dealloc_clcb(tGAP_CLCB *p_clcb)
{
tGAP_BLE_REQ *p_q;
while ((p_q = (tGAP_BLE_REQ *)fixed_queue_try_dequeue(p_clcb->pending_req_q)) != NULL) {
while ((p_q = (tGAP_BLE_REQ *)fixed_queue_dequeue(p_clcb->pending_req_q, 0)) != NULL) {
/* send callback to all pending requests if being removed*/
if (p_q->p_cback != NULL) {
(*p_q->p_cback)(FALSE, p_clcb->bda, 0, NULL);
@ -173,7 +173,7 @@ BOOLEAN gap_ble_enqueue_request (tGAP_CLCB *p_clcb, UINT16 uuid, tGAP_BLE_CMPL_C
if (p_q != NULL) {
p_q->p_cback = p_cback;
p_q->uuid = uuid;
fixed_queue_enqueue(p_clcb->pending_req_q, p_q);
fixed_queue_enqueue(p_clcb->pending_req_q, p_q, FIXED_QUEUE_MAX_TIMEOUT);
return TRUE;
}
@ -190,7 +190,7 @@ BOOLEAN gap_ble_enqueue_request (tGAP_CLCB *p_clcb, UINT16 uuid, tGAP_BLE_CMPL_C
*******************************************************************************/
BOOLEAN gap_ble_dequeue_request (tGAP_CLCB *p_clcb, UINT16 *p_uuid, tGAP_BLE_CMPL_CBACK **p_cback)
{
tGAP_BLE_REQ *p_q = (tGAP_BLE_REQ *)fixed_queue_try_dequeue(p_clcb->pending_req_q);;
tGAP_BLE_REQ *p_q = (tGAP_BLE_REQ *)fixed_queue_dequeue(p_clcb->pending_req_q, 0);;
if (p_q != NULL) {
*p_cback = p_q->p_cback;

View File

@ -332,7 +332,7 @@ UINT16 GAP_ConnReadData (UINT16 gap_handle, UINT8 *p_data, UINT16 max_len, UINT1
p_buf->len -= copy_len;
break;
}
osi_free(fixed_queue_try_dequeue(p_ccb->rx_queue));
osi_free(fixed_queue_dequeue(p_ccb->rx_queue, 0));
}
p_ccb->rx_queue_size -= *p_len;
@ -404,7 +404,7 @@ UINT16 GAP_ConnBTRead (UINT16 gap_handle, BT_HDR **pp_buf)
return (GAP_ERR_BAD_HANDLE);
}
p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->rx_queue);
p_buf = (BT_HDR *)fixed_queue_dequeue(p_ccb->rx_queue, 0);
if (p_buf) {
*pp_buf = p_buf;
@ -451,7 +451,7 @@ UINT16 GAP_ConnBTWrite (UINT16 gap_handle, BT_HDR *p_buf)
return (GAP_ERR_BUF_OFFSET);
}
fixed_queue_enqueue(p_ccb->tx_queue, p_buf);
fixed_queue_enqueue(p_ccb->tx_queue, p_buf, FIXED_QUEUE_MAX_TIMEOUT);
if (p_ccb->is_congested) {
return (BT_PASS);
@ -461,7 +461,7 @@ UINT16 GAP_ConnBTWrite (UINT16 gap_handle, BT_HDR *p_buf)
#if (GAP_CONN_POST_EVT_INCLUDED == TRUE)
gap_send_event (gap_handle);
#else
while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->tx_queue)) != NULL) {
while ((p_buf = (BT_HDR *)fixed_queue_dequeue(p_ccb->tx_queue, 0)) != NULL) {
UINT8 status = L2CA_DATA_WRITE (p_ccb->connection_id, p_buf);
if (status == L2CAP_DW_CONGESTED) {
@ -532,7 +532,7 @@ UINT16 GAP_ConnWriteData (UINT16 gap_handle, UINT8 *p_data, UINT16 max_len, UINT
GAP_TRACE_EVENT ("GAP_WriteData %d bytes", p_buf->len);
fixed_queue_enqueue(p_ccb->tx_queue, p_buf);
fixed_queue_enqueue(p_ccb->tx_queue, p_buf, FIXED_QUEUE_MAX_TIMEOUT);
}
if (p_ccb->is_congested) {
@ -543,7 +543,7 @@ UINT16 GAP_ConnWriteData (UINT16 gap_handle, UINT8 *p_data, UINT16 max_len, UINT
#if (GAP_CONN_POST_EVT_INCLUDED == TRUE)
gap_send_event (gap_handle);
#else
while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->tx_queue)) != NULL)
while ((p_buf = (BT_HDR *)fixed_queue_dequeue(p_ccb->tx_queue, 0)) != NULL)
{
UINT8 status = L2CA_DATA_WRITE (p_ccb->connection_id, p_buf);
@ -989,7 +989,7 @@ static void gap_data_ind (UINT16 l2cap_cid, BT_HDR *p_msg)
}
if (p_ccb->con_state == GAP_CCB_STATE_CONNECTED) {
fixed_queue_enqueue(p_ccb->rx_queue, p_msg);
fixed_queue_enqueue(p_ccb->rx_queue, p_msg, FIXED_QUEUE_MAX_TIMEOUT);
p_ccb->rx_queue_size += p_msg->len;
/*
@ -1033,7 +1033,7 @@ static void gap_congestion_ind (UINT16 lcid, BOOLEAN is_congested)
p_ccb->p_callback (p_ccb->gap_handle, event);
if (!is_congested) {
while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->tx_queue)) != NULL) {
while ((p_buf = (BT_HDR *)fixed_queue_dequeue(p_ccb->tx_queue, 0)) != NULL) {
status = L2CA_DATA_WRITE (p_ccb->connection_id, p_buf);
if (status == L2CAP_DW_CONGESTED) {
@ -1154,13 +1154,13 @@ static void gap_release_ccb (tGAP_CCB *p_ccb)
p_ccb->rx_queue_size = 0;
while (!fixed_queue_is_empty(p_ccb->rx_queue)) {
osi_free(fixed_queue_try_dequeue(p_ccb->rx_queue));
osi_free(fixed_queue_dequeue(p_ccb->rx_queue, 0));
}
fixed_queue_free(p_ccb->rx_queue, NULL);
p_ccb->rx_queue = NULL;
while (!fixed_queue_is_empty(p_ccb->tx_queue)) {
osi_free(fixed_queue_try_dequeue(p_ccb->tx_queue));
osi_free(fixed_queue_dequeue(p_ccb->tx_queue, 0));
}
fixed_queue_free(p_ccb->tx_queue, NULL);
p_ccb->tx_queue = NULL;

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