component/bt: reduce the size of DRAM

DRAM.data:   506B -->  196B
DRAM.bss : 26857B --> 2170B
This commit is contained in:
baohongde 2018-11-06 15:34:38 +08:00
parent 21cce564ba
commit bd9fed4400
78 changed files with 1705 additions and 1036 deletions

View File

@ -132,6 +132,8 @@ esp_err_t esp_bluedroid_init(void)
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

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

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

@ -233,10 +233,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;
/*******************************************************************************
**
@ -2303,7 +2305,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 +2498,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;

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) */
@ -441,4 +441,4 @@ tBTA_DM_EIR_CONF bta_dm_eir_cfg = {
NULL
#endif /* #if (BTC_GAP_BT_INCLUDED == TRUE) */
};
tBTA_DM_EIR_CONF *p_bta_dm_eir_cfg = (tBTA_DM_EIR_CONF *) &bta_dm_eir_cfg;
tBTA_DM_EIR_CONF *const p_bta_dm_eir_cfg = (tBTA_DM_EIR_CONF *) &bta_dm_eir_cfg;

View File

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

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

@ -976,7 +976,6 @@ typedef struct {
} tBTA_DM_CONNECTED_SRVCS;
extern tBTA_DM_CONNECTED_SRVCS bta_dm_conn_srvcs;
#if (BTA_DM_PM_INCLUDED == TRUE)
@ -1150,8 +1149,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 +1191,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 +1227,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;
cache_env_t *cache_env = NULL;
static void getFilename(char *buffer, hash_key_t hash)
{
@ -108,9 +108,9 @@ static void cacheClose(BD_ADDR bda)
{
UINT8 index = 0;
if ((index = bta_gattc_co_find_addr_in_cache(bda)) != INVALID_ADDR_NUM) {
if (cache_env.cache_addr[index].is_open) {
nvs_close(cache_env.cache_addr[index].cache_fp);
cache_env.cache_addr[index].is_open = FALSE;
if (cache_env->cache_addr[index].is_open) {
nvs_close(cache_env->cache_addr[index].cache_fp);
cache_env->cache_addr[index].is_open = FALSE;
}
}
}
@ -124,18 +124,18 @@ static bool cacheOpen(BD_ADDR bda, bool to_save, UINT8 *index)
hash_key_t hash_key = {0};
if (((*index = bta_gattc_co_find_addr_in_cache(bda)) != INVALID_ADDR_NUM) ||
((assoc_addr = bta_gattc_co_cache_find_src_addr(bda, index)) != NULL)) {
if (cache_env.cache_addr[*index].is_open) {
if (cache_env->cache_addr[*index].is_open) {
return TRUE;
} else {
memcpy(hash_key, cache_env.cache_addr[*index].hash_key, sizeof(hash_key_t));
memcpy(hash_key, cache_env->cache_addr[*index].hash_key, sizeof(hash_key_t));
getFilename(fname, hash_key);
if ((status = nvs_open(fname, NVS_READWRITE, &cache_env.cache_addr[*index].cache_fp)) == ESP_OK) {
if ((status = nvs_open(fname, NVS_READWRITE, &cache_env->cache_addr[*index].cache_fp)) == ESP_OK) {
// Set the open flag to TRUE when success to open the hash file.
cache_env.cache_addr[*index].is_open = TRUE;
cache_env->cache_addr[*index].is_open = TRUE;
}
}
}
return ((status == ESP_OK) ? true : false);
}
@ -144,67 +144,67 @@ static void cacheReset(BD_ADDR bda)
char fname[255] = {0};
getFilename(fname, bda);
UINT8 index = 0;
//cache_env.cache_addr
//cache_env->cache_addr
if ((index = bta_gattc_co_find_addr_in_cache(bda)) != INVALID_ADDR_NUM) {
//clear the association address pending in the source address.
bta_gattc_co_cache_clear_assoc_addr(bda);
if (cache_env.cache_addr[index].is_open) {
nvs_erase_all(cache_env.cache_addr[index].cache_fp);
nvs_close(cache_env.cache_addr[index].cache_fp);
cache_env.cache_addr[index].is_open = FALSE;
if (cache_env->cache_addr[index].is_open) {
nvs_erase_all(cache_env->cache_addr[index].cache_fp);
nvs_close(cache_env->cache_addr[index].cache_fp);
cache_env->cache_addr[index].is_open = FALSE;
} else {
cacheOpen(bda, false, &index);
if (cache_env.cache_addr[index].is_open) {
nvs_erase_all(cache_env.cache_addr[index].cache_fp);
nvs_close(cache_env.cache_addr[index].cache_fp);
cache_env.cache_addr[index].is_open = FALSE;
if (cache_env->cache_addr[index].is_open) {
nvs_erase_all(cache_env->cache_addr[index].cache_fp);
nvs_close(cache_env->cache_addr[index].cache_fp);
cache_env->cache_addr[index].is_open = FALSE;
} else {
APPL_TRACE_ERROR("%s cacheOpen failed", __func__);
return;
}
}
if(cache_env.num_addr == 0) {
if(cache_env->num_addr == 0) {
APPL_TRACE_ERROR("%s cache addr list error", __func__);
return;
}
UINT8 num = cache_env.num_addr;
UINT8 num = cache_env->num_addr;
//delete the server_bda in the addr_info list.
for(UINT8 i = index; i < (num - 1); i++) {
memcpy(&cache_env.cache_addr[i], &cache_env.cache_addr[i+1], sizeof(cache_addr_info_t));
memcpy(&cache_env->cache_addr[i], &cache_env->cache_addr[i+1], sizeof(cache_addr_info_t));
}
//reduced the number address counter also
cache_env.num_addr--;
cache_env->num_addr--;
//update addr list to nvs flash
if(cache_env.num_addr > 0) {
if(cache_env->num_addr > 0) {
//update
UINT8 *p_buf = osi_malloc(MAX_ADDR_LIST_CACHE_BUF);
if(!p_buf) {
APPL_TRACE_ERROR("%s malloc error", __func__);
return;
APPL_TRACE_ERROR("%s malloc error", __func__);
return;
}
UINT16 length = cache_env.num_addr*(sizeof(BD_ADDR) + sizeof(hash_key_t));
for (UINT8 i = 0; i < cache_env.num_addr; i++) {
UINT16 length = cache_env->num_addr*(sizeof(BD_ADDR) + sizeof(hash_key_t));
for (UINT8 i = 0; i < cache_env->num_addr; i++) {
//copy the address to the buffer.
memcpy(p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)), cache_env.cache_addr[i].addr, sizeof(BD_ADDR));
memcpy(p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)), cache_env->cache_addr[i].addr, sizeof(BD_ADDR));
//copy the hash key to the buffer.
memcpy(p_buf + i*(sizeof(BD_ADDR) + sizeof(hash_key_t)) + sizeof(BD_ADDR),
cache_env.cache_addr[i].hash_key, sizeof(hash_key_t));
cache_env->cache_addr[i].hash_key, sizeof(hash_key_t));
}
if (cache_env.is_open) {
if (nvs_set_blob(cache_env.addr_fp, cache_key, p_buf, length) != ESP_OK) {
if (cache_env->is_open) {
if (nvs_set_blob(cache_env->addr_fp, cache_key, p_buf, length) != ESP_OK) {
APPL_TRACE_WARNING("%s, nvs set blob failed", __func__);
}
}
osi_free(p_buf);
} else {
//erase
if (cache_env.is_open) {
nvs_erase_all(cache_env.addr_fp);
nvs_close(cache_env.addr_fp);
cache_env.is_open = FALSE;
if (cache_env->is_open) {
nvs_erase_all(cache_env->addr_fp);
nvs_close(cache_env->addr_fp);
cache_env->is_open = FALSE;
} else {
APPL_TRACE_WARNING("cache_env status is error");
}
@ -267,10 +267,10 @@ 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);
#if (!CONFIG_BT_STACK_NO_LOG)
esp_err_t err_code = nvs_get_blob(cache_env->cache_addr[index].cache_fp, cache_key, attr, &length);
num_attr = length / sizeof(tBTA_GATTC_NV_ATTR);
#endif
status = (err_code == ESP_OK && length != 0) ? BTA_GATT_OK : BTA_GATT_ERROR;
@ -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,18 @@ 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);
cache_env = (cache_env_t *)osi_malloc(sizeof(cache_env_t));
if (cache_env == NULL || p_buf == NULL) {
APPL_TRACE_ERROR("%s malloc failed!", __func__);
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 +401,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 +426,14 @@ void bta_gattc_co_cache_addr_init(void)
void bta_gattc_co_cache_addr_deinit(void)
{
if(!cache_env.is_open) {
if(!cache_env->is_open) {
return;
}
nvs_close(cache_env.addr_fp);
cache_env.is_open = false;
for(UINT8 i = 0; i< cache_env.num_addr; i++) {
cache_addr_info_t *addr_info = &cache_env.cache_addr[i];
}
nvs_close(cache_env->addr_fp);
cache_env->is_open = false;
for(UINT8 i = 0; i< cache_env->num_addr; i++) {
cache_addr_info_t *addr_info = &cache_env->cache_addr[i];
if(addr_info) {
nvs_close(addr_info->cache_fp);
addr_info->is_open = false;
@ -436,13 +442,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 +464,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 +479,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 +492,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 +515,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 +562,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 +574,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 +589,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 +609,8 @@ BOOLEAN bta_gattc_co_cache_remove_assoc_addr(BD_ADDR src_addr, BD_ADDR assoc_add
UINT8* bta_gattc_co_cache_find_src_addr(BD_ADDR assoc_addr, UINT8 *index)
{
UINT8 num = cache_env.num_addr;
cache_addr_info_t *addr_info = &cache_env.cache_addr[0];
UINT8 num = cache_env->num_addr;
cache_addr_info_t *addr_info = &cache_env->cache_addr[0];
UINT8 *addr_data;
//Check the assoc_addr list is NULL or not
if (addr_info->assoc_addr == NULL) {
@ -610,7 +619,7 @@ UINT8* bta_gattc_co_cache_find_src_addr(BD_ADDR assoc_addr, UINT8 *index)
}
for (int i = 0; i < num; i++) {
for (const list_node_t *node = list_begin(addr_info->assoc_addr); node != list_end(addr_info->assoc_addr);
for (const list_node_t *node = list_begin(addr_info->assoc_addr); node != list_end(addr_info->assoc_addr);
node = list_next(node)) {
addr_data = (UINT8 *)list_node(node);
if (!memcmp(addr_data, assoc_addr, sizeof(BD_ADDR))) {
@ -635,7 +644,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 +656,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,8 +214,8 @@ void BTA_GATTS_AddIncludeService(UINT16 service_id, UINT16 included_service_id)
** Returns None
**
*******************************************************************************/
void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid,
tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property, tGATT_ATTR_VAL *attr_val,
void BTA_GATTS_AddCharacteristic (UINT16 service_id, const tBT_UUID * p_char_uuid,
tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property, tGATT_ATTR_VAL *attr_val,
tBTA_GATTS_ATTR_CONTROL *control)
{
tBTA_GATTS_API_ADD_CHAR *p_buf;
@ -270,7 +270,7 @@ void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid,
*******************************************************************************/
void BTA_GATTS_AddCharDescriptor (UINT16 service_id,
tBTA_GATT_PERM perm,
tBT_UUID *p_descr_uuid, tBTA_GATT_ATTR_VAL *attr_val,
const tBT_UUID * p_descr_uuid, tBTA_GATT_ATTR_VAL *attr_val,
tBTA_GATTS_ATTR_CONTROL *control)
{
tBTA_GATTS_API_ADD_DESCR *p_buf;

View File

@ -1809,6 +1809,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

@ -30,7 +30,6 @@
#include "osi/list.h"
#ifndef BTA_GATT_INCLUDED
#warning BTA_GATT_INCLUDED not defined
#define BTA_GATT_INCLUDED FALSE
#endif
@ -881,7 +880,7 @@ extern const tBTA_GATTC_CHARACTERISTIC* BTA_GATTC_GetCharacteristic(UINT16 conn_
*******************************************************************************/
extern const tBTA_GATTC_DESCRIPTOR* BTA_GATTC_GetDescriptor(UINT16 conn_id, UINT16 handle);
extern void BTA_GATTC_GetServiceWithUUID(UINT16 conn_id, tBT_UUID *svc_uuid,
extern void BTA_GATTC_GetServiceWithUUID(UINT16 conn_id, tBT_UUID *svc_uuid,
btgatt_db_element_t **db, int *count);
extern void BTA_GATTC_GetAllChar(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle,
@ -1234,7 +1233,7 @@ extern void BTA_GATTS_Disable(void);
** Returns None
**
*******************************************************************************/
extern void BTA_GATTS_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTS_CBACK *p_cback);
extern void BTA_GATTS_AppRegister(const tBT_UUID * p_app_uuid, tBTA_GATTS_CBACK *p_cback);
/*******************************************************************************
@ -1269,7 +1268,7 @@ extern void BTA_GATTS_AppDeregister(tBTA_GATTS_IF server_if);
** Returns void
**
*******************************************************************************/
extern void BTA_GATTS_CreateService(tBTA_GATTS_IF server_if, tBT_UUID *p_service_uuid,
extern void BTA_GATTS_CreateService(tBTA_GATTS_IF server_if, const tBT_UUID * p_service_uuid,
UINT8 inst, UINT16 num_handle, BOOLEAN is_primary);
/*******************************************************************************
@ -1304,8 +1303,8 @@ extern void BTA_GATTS_AddIncludeService(UINT16 service_id, UINT16 included_servi
** Returns None
**
*******************************************************************************/
extern void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid,
tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property, tGATT_ATTR_VAL *attr_val,
extern void BTA_GATTS_AddCharacteristic (UINT16 service_id, const tBT_UUID * p_char_uuid,
tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property, tGATT_ATTR_VAL *attr_val,
tBTA_GATTS_ATTR_CONTROL *control);
/*******************************************************************************
@ -1327,7 +1326,7 @@ extern void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_u
*******************************************************************************/
extern void BTA_GATTS_AddCharDescriptor (UINT16 service_id,
tBTA_GATT_PERM perm,
tBT_UUID *p_descr_uuid, tBTA_GATT_ATTR_VAL *attr_val,
const tBT_UUID * p_descr_uuid, tBTA_GATT_ATTR_VAL *attr_val,
tBTA_GATTS_ATTR_CONTROL *control);
/*******************************************************************************

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

@ -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

@ -774,7 +774,7 @@ static bt_status_t _btc_storage_in_fetch_bonded_ble_device(const char *remote_bd
BTC_TRACE_ERROR("%s, device_type = %x", __func__, device_type);
return BT_STATUS_FAIL;
}
string_to_bdaddr(remote_bd_addr, &bd_addr);
bdcpy(bta_bd_addr, bd_addr.address);
@ -817,7 +817,7 @@ static bt_status_t btc_storage_in_fetch_bonded_ble_devices(int add)
for (const btc_config_section_iter_t *iter = btc_config_section_begin(); iter != btc_config_section_end();
iter = btc_config_section_next(iter)) {
const char *name = btc_config_section_name(iter);
if (!string_is_bdaddr(name) ||
!btc_config_get_int(name, BTC_BLE_STORAGE_DEV_TYPE_STR, (int *)&device_type) ||
((device_type & BT_DEVICE_TYPE_BLE) != BT_DEVICE_TYPE_BLE)) {
@ -927,4 +927,4 @@ int btc_storage_get_num_ble_bond_devices(void)
return num_dev;
}
#endif ///SMP_INCLUDED == TRUE

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
/******************************************************************************
@ -131,21 +131,21 @@ static void btc_disable_bluetooth_evt(void)
#if (SMP_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 +153,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 +173,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 +183,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 +252,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);
}
@ -487,12 +486,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 +529,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 +542,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);
@ -693,9 +692,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 +702,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 +711,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 +720,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 +729,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 +738,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 +777,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 +800,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

@ -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,12 +21,14 @@
#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"
@ -38,6 +40,7 @@
#if BTC_AV_INCLUDED
#include "btc_av.h"
#include "btc_avrc.h"
#include "btc_av_co.h"
#endif /* #if BTC_AV_INCLUDED */
#if (BTC_SPP_INCLUDED == TRUE)
#include "btc_spp.h"
@ -54,7 +57,7 @@
static 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)
@ -168,6 +171,94 @@ bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg
}
#if BTC_DYNAMIC_MENDRY
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) {
return BT_STATUS_NOMEM;
}
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) {
return BT_STATUS_NOMEM;
}
memset((void *)btc_profile_cb_tab, 0, sizeof(void *) * BTC_PID_NUM);
if ((gl_bta_adv_data_ptr = (tBTA_BLE_ADV_DATA *)osi_malloc(sizeof(tBTA_BLE_ADV_DATA))) == NULL) {
return BT_STATUS_NOMEM;
}
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) {
return BT_STATUS_NOMEM;
}
memset((void *)gl_bta_scan_rsp_data_ptr, 0, sizeof(tBTA_BLE_ADV_DATA));
#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) {
return BT_STATUS_NOMEM;
}
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) {
return BT_STATUS_NOMEM;
}
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) {
return BT_STATUS_NOMEM;
}
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_vb_ptr = (btc_rc_cb_t *)osi_malloc(sizeof(btc_rc_cb_t))) == NULL) {
return BT_STATUS_NOMEM;
}
memset((void *)btc_rc_vb_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) {
return BT_STATUS_NOMEM;
}
memset((void *)bta_av_co_cb_ptr, 0, sizeof(tBTA_AV_CO_CB));
#endif
return BT_STATUS_SUCCESS;
}
static void btc_deinit_mem(void) {
osi_free(btc_dm_cb_ptr);
btc_dm_cb_ptr = NULL;
osi_free(btc_profile_cb_tab);
btc_profile_cb_tab = NULL;
osi_free(gl_bta_adv_data_ptr);
gl_bta_adv_data_ptr = NULL;
osi_free(gl_bta_scan_rsp_data_ptr);
gl_bta_scan_rsp_data_ptr = NULL;
#if GATTS_INCLUDED == TRUE && GATT_DYNAMIC_MEMORY == TRUE
osi_free(btc_creat_tab_env_ptr);
btc_creat_tab_env_ptr = NULL;
osi_free(blufi_env_ptr);
blufi_env_ptr = NULL;
#endif
#if BTC_HF_CLIENT_INCLUDED == TRUE && HFP_DYNAMIC_MEMORY == TRUE
osi_free(hf_client_local_param_ptr);
hf_client_local_param_ptr = NULL;
#endif
#if BTC_AV_INCLUDED == TRUE && AVRC_DYNAMIC_MEMORY == TRUE
osi_free(btc_rc_vb_ptr);
btc_rc_vb_ptr = NULL;
osi_free(bta_av_co_cb_ptr);
bta_av_co_cb_ptr = NULL;
#endif
}
#endif
int btc_init(void)
{
@ -176,6 +267,12 @@ int btc_init(void)
return BT_STATUS_NOMEM;
}
#if BTC_DYNAMIC_MENDRY
if (btc_init_mem() != BT_STATUS_SUCCESS){
return BT_STATUS_NOMEM;
}
#endif
btc_gap_callback_init();
#if SCAN_QUEUE_CONGEST_CHECK
btc_adv_list_init();
@ -186,8 +283,13 @@ int btc_init(void)
void btc_deinit(void)
{
#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

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

@ -55,13 +55,17 @@
#define BLUFI_HDL_NUM 6
#if GATT_DYNAMIC_MEMORY == FALSE
tBLUFI_ENV blufi_env;
#else
tBLUFI_ENV *blufi_env_ptr;
#endif
static /* const */ tBT_UUID blufi_srvc_uuid = {LEN_UUID_16, {BLUFI_SERVICE_UUID}};
static /* const */ tBT_UUID blufi_char_uuid_p2e = {LEN_UUID_16, {BLUFI_CHAR_P2E_UUID}};
static /* const */ tBT_UUID blufi_char_uuid_e2p = {LEN_UUID_16, {BLUFI_CHAR_E2P_UUID}};
static /* const */ tBT_UUID blufi_descr_uuid_e2p = {LEN_UUID_16, {BLUFI_DESCR_E2P_UUID}};
static /* const */ tBT_UUID blufi_app_uuid = {LEN_UUID_16, {BLUFI_APP_UUID}};
static const tBT_UUID blufi_srvc_uuid = {LEN_UUID_16, {BLUFI_SERVICE_UUID}};
static const tBT_UUID blufi_char_uuid_p2e = {LEN_UUID_16, {BLUFI_CHAR_P2E_UUID}};
static const tBT_UUID blufi_char_uuid_e2p = {LEN_UUID_16, {BLUFI_CHAR_E2P_UUID}};
static const tBT_UUID blufi_descr_uuid_e2p = {LEN_UUID_16, {BLUFI_DESCR_E2P_UUID}};
static const tBT_UUID blufi_app_uuid = {LEN_UUID_16, {BLUFI_APP_UUID}};
// static functions declare
static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data);
@ -189,7 +193,7 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
BTA_GATTS_SendRsp(p_data->req_data.conn_id, p_data->req_data.trans_id,
p_data->req_data.status, NULL);
}
if (p_data->req_data.p_data->write_req.handle == blufi_env.handle_char_p2e) {
btc_blufi_recv_handler(&p_data->req_data.p_data->write_req.value[0],
p_data->req_data.p_data->write_req.len);
@ -363,7 +367,7 @@ static void btc_blufi_send_notify(uint8_t *pkt, int pkt_len)
UINT16 conn_id = blufi_env.conn_id;
UINT16 attr_id = blufi_env.handle_char_e2p;
bool rsp = false;
BTA_GATTS_HandleValueIndication(conn_id, attr_id, pkt_len,
pkt, rsp);
}
@ -479,7 +483,7 @@ void btc_blufi_send_encap(uint8_t type, uint8_t *data, int total_data_len)
hdr->type = type;
hdr->fc |= BLUFI_FC_DIR_E2P;
hdr->seq = blufi_env.send_seq++;
if (BLUFI_TYPE_IS_CTRL(hdr->type)) {
if ((blufi_env.sec_mode & BLUFI_CTRL_SEC_MODE_CHECK_MASK)
&& (blufi_env.cbs && blufi_env.cbs->checksum_func)) {
@ -1052,7 +1056,7 @@ void btc_blufi_call_deep_free(btc_msg_t *msg)
case BTC_BLUFI_ACT_SEND_CUSTOM_DATA:{
uint8_t *data = arg->custom_data.data;
if(data) {
osi_free(data);
osi_free(data);
}
break;
}

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

@ -24,10 +24,10 @@ typedef struct {
/* Protocol reference */
tGATT_IF gatt_if;
UINT8 srvc_inst;
UINT16 handle_srvc;
UINT16 handle_char_p2e;
UINT16 handle_char_e2p;
UINT16 handle_descr_e2p;
UINT16 handle_srvc;
UINT16 handle_char_p2e;
UINT16 handle_char_e2p;
UINT16 handle_descr_e2p;
UINT16 conn_id;
BOOLEAN is_connected;
BD_ADDR remote_bda;
@ -68,17 +68,24 @@ struct blufi_frag_hdr {
};
typedef struct blufi_frag_hdr blufi_frag_hdr_t;
#define BLUFI_DATA_SEC_MODE_CHECK_MASK 0x01
#define BLUFI_DATA_SEC_MODE_ENC_MASK 0x02
#define BLUFI_CTRL_SEC_MODE_CHECK_MASK 0x10
#if GATT_DYNAMIC_MEMORY == FALSE
extern tBLUFI_ENV blufi_env;
#else
extern tBLUFI_ENV *blufi_env_ptr;
#define blufi_env (*blufi_env_ptr)
#endif
#define BLUFI_DATA_SEC_MODE_CHECK_MASK 0x01
#define BLUFI_DATA_SEC_MODE_ENC_MASK 0x02
#define BLUFI_CTRL_SEC_MODE_CHECK_MASK 0x10
#define BLUFI_CTRL_SEC_MODE_ENC_MASK 0x20
#define BLUFI_MAX_DATA_LEN 255
// packet type
#define BLUFI_TYPE_MASK 0x03
#define BLUFI_TYPE_SHIFT 0
#define BLUFI_TYPE_SHIFT 0
#define BLUFI_SUBTYPE_MASK 0xFC
#define BLUFI_SUBTYPE_SHIFT 2
#define BLUFI_SUBTYPE_SHIFT 2
#define BLUFI_GET_TYPE(type) ((type) & BLUFI_TYPE_MASK)
#define BLUFI_GET_SUBTYPE(type) (((type) & BLUFI_SUBTYPE_MASK) >>BLUFI_SUBTYPE_SHIFT)
@ -161,12 +168,12 @@ typedef struct blufi_frag_hdr blufi_frag_hdr_t;
#define BLUFI_FC_REQ_ACK 0x08
#define BLUFI_FC_FRAG 0x10
#define BLUFI_FC_IS_ENC(fc) ((fc) & BLUFI_FC_ENC_MASK)
#define BLUFI_FC_IS_CHECK(fc) ((fc) & BLUFI_FC_CHECK_MASK)
#define BLUFI_FC_IS_DIR_P2E(fc) ((fc) & BLUFI_FC_DIR_P2E_MASK)
#define BLUFI_FC_IS_DIR_E2P(fc) (!((fc) & BLUFI_DIR_P2E_MASK))
#define BLUFI_FC_IS_REQ_ACK(fc) ((fc) & BLUFI_FC_REQ_ACK_MASK)
#define BLUFI_FC_IS_FRAG(fc) ((fc) & BLUFI_FC_FRAG_MASK)
#define BLUFI_FC_IS_ENC(fc) ((fc) & BLUFI_FC_ENC_MASK)
#define BLUFI_FC_IS_CHECK(fc) ((fc) & BLUFI_FC_CHECK_MASK)
#define BLUFI_FC_IS_DIR_P2E(fc) ((fc) & BLUFI_FC_DIR_P2E_MASK)
#define BLUFI_FC_IS_DIR_E2P(fc) (!((fc) & BLUFI_DIR_P2E_MASK))
#define BLUFI_FC_IS_REQ_ACK(fc) ((fc) & BLUFI_FC_REQ_ACK_MASK)
#define BLUFI_FC_IS_FRAG(fc) ((fc) & BLUFI_FC_FRAG_MASK)
/* BLUFI HEADER + TOTAL(REMAIN) LENGTH + CRC + L2CAP RESERVED */
#define BLUFI_MTU_RESERVED_SIZE (sizeof(struct blufi_hdr) + 2 + 2 + 3)

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

@ -112,6 +112,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);
@ -128,11 +137,14 @@ 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 osi_thread_t *btc_aa_snk_task_hdl = NULL;
static esp_a2d_sink_data_cb_t bt_aa_snk_data_cb = NULL;
#if A2D_DYNAMIC_MEMORY == FALSE
static a2dp_sink_local_param_t a2dp_sink_local_param;
#else
static a2dp_sink_local_param_t *a2dp_sink_local_param_ptr;
#define a2dp_sink_local_param (*a2dp_sink_local_param_ptr)
#endif ///A2D_DYNAMIC_MEMORY == FALSE
void btc_a2dp_sink_reg_data_cb(esp_a2d_sink_data_cb_t callback)
{
@ -148,21 +160,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
@ -190,7 +187,7 @@ static bool btc_a2dp_sink_ctrl_post(uint32_t sig, void *param)
evt->sig = sig;
evt->param = param;
return osi_thread_post(btc_aa_snk_task_hdl, btc_a2dp_sink_ctrl_handler, evt, 0, OSI_THREAD_BLOCKING);
return osi_thread_post(a2dp_sink_local_param.btc_aa_snk_task_hdl, btc_a2dp_sink_ctrl_handler, evt, 0, OSI_THREAD_BLOCKING);
}
static void btc_a2dp_sink_ctrl_handler(void *arg)
@ -235,20 +232,18 @@ 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");
goto error_exit;
}
#endif /* BTC_SBC_DEC_DYNAMIC_MEMORY == TRUE */
btc_aa_snk_task_hdl = osi_thread_create(BTC_A2DP_SINK_TASK_NAME, BTC_A2DP_SINK_TASK_STACK_SIZE, BTC_A2DP_SINK_TASK_PRIO, BTC_A2DP_SINK_TASK_PINNED_TO_CORE, 2);
if (btc_aa_snk_task_hdl == NULL) {
a2dp_sink_local_param.btc_aa_snk_task_hdl = osi_thread_create(BTC_A2DP_SINK_TASK_NAME, BTC_A2DP_SINK_TASK_STACK_SIZE, BTC_A2DP_SINK_TASK_PRIO, BTC_A2DP_SINK_TASK_PINNED_TO_CORE, 2);
if (a2dp_sink_local_param.btc_aa_snk_task_hdl == NULL) {
goto error_exit;
}
@ -262,25 +257,15 @@ bool btc_a2dp_sink_startup(void)
error_exit:;
APPL_TRACE_ERROR("%s unable to start up media thread\n", __func__);
if (btc_aa_snk_task_hdl != NULL) {
osi_thread_free(btc_aa_snk_task_hdl);
btc_aa_snk_task_hdl = NULL;
if (a2dp_sink_local_param.btc_aa_snk_task_hdl != NULL) {
osi_thread_free(a2dp_sink_local_param.btc_aa_snk_task_hdl);
a2dp_sink_local_param.btc_aa_snk_task_hdl = 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;
}
@ -291,25 +276,19 @@ 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;
osi_thread_free(btc_aa_snk_task_hdl);
btc_aa_snk_task_hdl = NULL;
osi_thread_free(a2dp_sink_local_param.btc_aa_snk_task_hdl);
a2dp_sink_local_param.btc_aa_snk_task_hdl = 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
}
/*****************************************************************************
@ -320,7 +299,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();
@ -335,7 +314,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);
}
@ -348,14 +327,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(void)
{
osi_thread_post(btc_aa_snk_task_hdl, btc_a2dp_sink_data_ready, NULL, 1, OSI_THREAD_BLOCKING);
osi_thread_post(a2dp_sink_local_param.btc_aa_snk_task_hdl, btc_a2dp_sink_data_ready, NULL, 1, OSI_THREAD_BLOCKING);
}
/*******************************************************************************
@ -376,7 +355,7 @@ static BOOLEAN btc_a2dp_sink_clear_track(void)
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;
}
/*****************************************************************************
@ -410,20 +389,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_try_dequeue(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ);
if ( p_msg == NULL ) {
APPL_TRACE_ERROR("Insufficient data in que ");
break;
@ -463,13 +442,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);
}
@ -585,14 +564,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;
}
@ -606,7 +585,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);
@ -620,7 +599,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));
}
/*******************************************************************************
@ -634,7 +613,7 @@ 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;
}
@ -655,7 +634,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)
@ -711,13 +690,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 + ");
@ -728,13 +707,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);
fixed_queue_enqueue(a2dp_sink_local_param.btc_aa_snk_cb.RxSbcQ, p_msg);
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)
@ -761,11 +740,11 @@ static void btc_a2dp_sink_flush_q(fixed_queue_t *p_q)
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();
}
@ -778,9 +757,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

@ -165,9 +165,17 @@ typedef struct {
tBTC_AV_FEEDING_MODE feeding_mode;
tBTC_AV_MEDIA_FEEDINGS_STATE media_feeding_state;
tBTC_AV_MEDIA_FEEDINGS media_feeding;
SBC_ENC_PARAMS encoder;
osi_alarm_t *media_alarm;
} tBTC_A2DP_SOURCE_CB;
typedef struct {
tBTC_A2DP_SOURCE_CB btc_aa_src_cb;
future_t *btc_a2dp_source_future;
osi_thread_t *btc_aa_src_task_hdl;
UINT64 last_frame_us;
} a2dp_source_local_param_t;
static void btc_a2dp_source_thread_init(UNUSED_ATTR void *context);
static void btc_a2dp_source_thread_cleanup(UNUSED_ATTR void *context);
static void btc_a2dp_source_flush_q(fixed_queue_t *p_q);
@ -185,19 +193,14 @@ static void btc_a2dp_source_handle_timer(UNUSED_ATTR void *context);
static void btc_a2dp_source_encoder_init(void);
static void btc_a2dp_source_ctrl_handler(void *arg);
static tBTC_A2DP_SOURCE_CB btc_aa_src_cb;
static int btc_a2dp_source_state = BTC_A2DP_SOURCE_STATE_OFF;
static future_t *btc_a2dp_source_future = NULL;
static osi_thread_t *btc_aa_src_task_hdl = NULL;
static esp_a2d_source_data_cb_t btc_aa_src_data_cb = NULL;
static UINT64 last_frame_us = 0;
#if BTC_SBC_ENC_DYNAMIC_MEMORY == FALSE
static SBC_ENC_PARAMS btc_sbc_encoder;
#if A2D_DYNAMIC_MEMORY == FALSE
static a2dp_source_local_param_t a2dp_source_local_param;
#else
static SBC_ENC_PARAMS *btc_sbc_encoder_ptr;
#define btc_sbc_encoder (*btc_sbc_encoder_ptr)
#endif /* BTC_SBC_ENC_DYNAMIC_MEMORY == FALSE */
static a2dp_source_local_param_t *a2dp_source_local_param_ptr;
#define a2dp_source_local_param (*a2dp_source_local_param_ptr)
#endif ///A2D_DYNAMIC_MEMORY == FALSE
void btc_a2dp_src_reg_data_cb(esp_a2d_source_data_cb_t callback)
{
@ -232,7 +235,7 @@ static inline void btc_aa_cb_to_app(esp_a2d_cb_event_t event, esp_a2d_cb_param_t
bool btc_a2dp_source_is_streaming(void)
{
return btc_aa_src_cb.is_tx_timer == TRUE;
return a2dp_source_local_param.btc_aa_src_cb.is_tx_timer == TRUE;
}
bool btc_a2dp_source_is_task_shutting_down(void)
@ -251,7 +254,7 @@ static void btc_a2dp_source_ctrl_post(uint32_t sig, void *param)
evt->sig = sig;
evt->param = param;
osi_thread_post(btc_aa_src_task_hdl, btc_a2dp_source_ctrl_handler, evt, 0, OSI_THREAD_BLOCKING);
osi_thread_post(a2dp_source_local_param.btc_aa_src_task_hdl, btc_a2dp_source_ctrl_handler, evt, 0, OSI_THREAD_BLOCKING);
}
static void btc_a2dp_source_ctrl_handler(void *arg)
@ -305,18 +308,18 @@ bool btc_a2dp_source_startup(void)
return false;
}
#if A2D_DYNAMIC_MEMORY == TRUE
if ((a2dp_source_local_param_ptr = (a2dp_source_local_param_t *)osi_malloc(sizeof(a2dp_source_local_param_t))) == NULL) {
APPL_TRACE_ERROR("%s malloc failed!", __func__);
return false;
}
memset((void *)a2dp_source_local_param_ptr, 0, sizeof(a2dp_source_local_param_t));
#endif
APPL_TRACE_EVENT("## A2DP SOURCE START MEDIA THREAD ##");
#if BTC_SBC_ENC_DYNAMIC_MEMORY == TRUE
btc_sbc_encoder_ptr = osi_calloc(sizeof(SBC_ENC_PARAMS));
if (!btc_sbc_encoder_ptr) {
APPL_TRACE_ERROR("failed to allocate SBC encoder");
goto error_exit;
}
#endif /* #if BTC_SBC_ENC_DYNAMIC_MEMORY == TRUE */
btc_aa_src_task_hdl = osi_thread_create(BTC_A2DP_SOURCE_TASK_NAME, BTC_A2DP_SOURCE_TASK_STACK_SIZE, BTC_A2DP_SOURCE_TASK_PRIO, BTC_A2DP_SOURCE_TASK_PINNED_TO_CORE, 2);
if (btc_aa_src_task_hdl == NULL) {
a2dp_source_local_param.btc_aa_src_task_hdl = osi_thread_create(BTC_A2DP_SOURCE_TASK_NAME, BTC_A2DP_SOURCE_TASK_STACK_SIZE, BTC_A2DP_SOURCE_TASK_PRIO, BTC_A2DP_SOURCE_TASK_PINNED_TO_CORE, 2);
if (a2dp_source_local_param.btc_aa_src_task_hdl == NULL) {
goto error_exit;
}
@ -327,15 +330,13 @@ bool btc_a2dp_source_startup(void)
error_exit:;
APPL_TRACE_ERROR("%s unable to start up media thread\n", __func__);
osi_thread_free(btc_aa_src_task_hdl);
btc_aa_src_task_hdl = NULL;
osi_thread_free(a2dp_source_local_param.btc_aa_src_task_hdl);
a2dp_source_local_param.btc_aa_src_task_hdl = NULL;
#if (BTC_SBC_ENC_DYNAMIC_MEMORY == TRUE)
if (btc_sbc_encoder_ptr) {
osi_free(btc_sbc_encoder_ptr);
btc_sbc_encoder_ptr = NULL;
}
#endif /* #if BTC_SBC_ENC_DYNAMIC_MEMORY == TRUE */
#if A2D_DYNAMIC_MEMORY == TRUE
osi_free(a2dp_source_local_param_ptr);
a2dp_source_local_param_ptr = NULL;
#endif
return false;
}
@ -346,19 +347,19 @@ void btc_a2dp_source_shutdown(void)
// Exit thread
btc_a2dp_source_state = BTC_A2DP_SOURCE_STATE_SHUTTING_DOWN;
btc_a2dp_source_future = future_new();
assert(btc_a2dp_source_future);
a2dp_source_local_param.btc_a2dp_source_future = future_new();
assert(a2dp_source_local_param.btc_a2dp_source_future);
btc_a2dp_source_ctrl_post(BTC_MEDIA_TASK_CLEAN_UP, NULL);
future_await(btc_a2dp_source_future);
btc_a2dp_source_future = NULL;
future_await(a2dp_source_local_param.btc_a2dp_source_future);
a2dp_source_local_param.btc_a2dp_source_future = NULL;
osi_thread_free(btc_aa_src_task_hdl);
btc_aa_src_task_hdl = NULL;
osi_thread_free(a2dp_source_local_param.btc_aa_src_task_hdl);
a2dp_source_local_param.btc_aa_src_task_hdl = NULL;
#if (BTC_SBC_ENC_DYNAMIC_MEMORY == TRUE)
osi_free(btc_sbc_encoder_ptr);
btc_sbc_encoder_ptr = NULL;
#endif /* #if BTC_SBC_ENC_DYNAMIC_MEMORY == TRUE */
#if A2D_DYNAMIC_MEMORY == TRUE
osi_free(a2dp_source_local_param_ptr);
a2dp_source_local_param_ptr = NULL;
#endif
}
/*****************************************************************************
@ -391,7 +392,7 @@ void btc_a2dp_source_on_stopped(tBTA_AV_SUSPEND *p_av)
}
/* ensure tx frames are immediately suspended */
btc_aa_src_cb.tx_flush = 1;
a2dp_source_local_param.btc_aa_src_cb.tx_flush = 1;
/* request to stop media task */
btc_a2dp_source_tx_flush_req();
@ -419,7 +420,7 @@ void btc_a2dp_source_on_suspended(tBTA_AV_SUSPEND *p_av)
/* once stream is fully stopped we will ack back */
/* ensure tx frames are immediately flushed */
btc_aa_src_cb.tx_flush = 1;
a2dp_source_local_param.btc_aa_src_cb.tx_flush = 1;
/* stop timer tick */
btc_a2dp_source_stop_audio_req();
@ -427,7 +428,7 @@ void btc_a2dp_source_on_suspended(tBTA_AV_SUSPEND *p_av)
static void btc_a2dp_source_data_post(void)
{
osi_thread_post(btc_aa_src_task_hdl, btc_a2dp_source_handle_timer, NULL, 1, OSI_THREAD_BLOCKING);
osi_thread_post(a2dp_source_local_param.btc_aa_src_task_hdl, btc_a2dp_source_handle_timer, NULL, 1, OSI_THREAD_BLOCKING);
}
static UINT64 time_now_us()
@ -448,7 +449,7 @@ static void log_tstamps_us(char *comment)
static UINT64 prev_us = 0;
UINT64 now_us = time_now_us();
APPL_TRACE_DEBUG("[%s] ts %08llu, diff : %08llu, queue sz %d", comment, now_us, now_us - prev_us,
fixed_queue_length(btc_aa_src_cb.TxAaQ));
fixed_queue_length(a2dp_source_local_param.btc_aa_src_cb.TxAaQ));
prev_us = now_us;
UNUSED(prev_us);
}
@ -457,7 +458,7 @@ static void log_tstamps_us(char *comment)
void btc_a2dp_source_set_tx_flush(BOOLEAN enable)
{
APPL_TRACE_EVENT("## DROP TX %d ##", enable);
btc_aa_src_cb.tx_flush = enable;
a2dp_source_local_param.btc_aa_src_cb.tx_flush = enable;
}
/*****************************************************************************
@ -516,7 +517,7 @@ BT_HDR *btc_a2dp_source_audio_readbuf(void)
if (btc_a2dp_source_state != BTC_A2DP_SOURCE_STATE_ON){
return NULL;
}
return fixed_queue_try_dequeue(btc_aa_src_cb.TxAaQ);
return fixed_queue_try_dequeue(a2dp_source_local_param.btc_aa_src_cb.TxAaQ);
}
/*******************************************************************************
@ -776,35 +777,35 @@ static void btc_a2dp_source_enc_init(BT_HDR *p_msg)
APPL_TRACE_DEBUG("btc_a2dp_source_enc_init");
btc_aa_src_cb.timestamp = 0;
a2dp_source_local_param.btc_aa_src_cb.timestamp = 0;
/* SBC encoder config (enforced even if not used) */
btc_sbc_encoder.sbc_mode = SBC_MODE_STD;
btc_sbc_encoder.s16ChannelMode = pInitAudio->ChannelMode;
btc_sbc_encoder.s16NumOfSubBands = pInitAudio->NumOfSubBands;
btc_sbc_encoder.s16NumOfBlocks = pInitAudio->NumOfBlocks;
btc_sbc_encoder.s16AllocationMethod = pInitAudio->AllocationMethod;
btc_sbc_encoder.s16SamplingFreq = pInitAudio->SamplingFreq;
a2dp_source_local_param.btc_aa_src_cb.encoder.sbc_mode = SBC_MODE_STD;
a2dp_source_local_param.btc_aa_src_cb.encoder.s16ChannelMode = pInitAudio->ChannelMode;
a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfSubBands = pInitAudio->NumOfSubBands;
a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfBlocks = pInitAudio->NumOfBlocks;
a2dp_source_local_param.btc_aa_src_cb.encoder.s16AllocationMethod = pInitAudio->AllocationMethod;
a2dp_source_local_param.btc_aa_src_cb.encoder.s16SamplingFreq = pInitAudio->SamplingFreq;
btc_sbc_encoder.u16BitRate = btc_a2dp_source_get_sbc_rate();
a2dp_source_local_param.btc_aa_src_cb.encoder.u16BitRate = btc_a2dp_source_get_sbc_rate();
/* Default transcoding is PCM to SBC, modified by feeding configuration */
btc_aa_src_cb.TxTranscoding = BTC_MEDIA_TRSCD_PCM_2_SBC;
btc_aa_src_cb.TxAaMtuSize = ((BTC_MEDIA_AA_BUF_SIZE - BTC_MEDIA_AA_SBC_OFFSET - sizeof(BT_HDR))
a2dp_source_local_param.btc_aa_src_cb.TxTranscoding = BTC_MEDIA_TRSCD_PCM_2_SBC;
a2dp_source_local_param.btc_aa_src_cb.TxAaMtuSize = ((BTC_MEDIA_AA_BUF_SIZE - BTC_MEDIA_AA_SBC_OFFSET - sizeof(BT_HDR))
< pInitAudio->MtuSize) ? (BTC_MEDIA_AA_BUF_SIZE - BTC_MEDIA_AA_SBC_OFFSET
- sizeof(BT_HDR)) : pInitAudio->MtuSize;
APPL_TRACE_EVENT("btc_a2dp_source_enc_init mtu %d, peer mtu %d",
btc_aa_src_cb.TxAaMtuSize, pInitAudio->MtuSize);
a2dp_source_local_param.btc_aa_src_cb.TxAaMtuSize, pInitAudio->MtuSize);
APPL_TRACE_EVENT(" ch mode %d, subnd %d, nb blk %d, alloc %d, rate %d, freq %d",
btc_sbc_encoder.s16ChannelMode, btc_sbc_encoder.s16NumOfSubBands,
btc_sbc_encoder.s16NumOfBlocks,
btc_sbc_encoder.s16AllocationMethod, btc_sbc_encoder.u16BitRate,
btc_sbc_encoder.s16SamplingFreq);
a2dp_source_local_param.btc_aa_src_cb.encoder.s16ChannelMode, a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfSubBands,
a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfBlocks,
a2dp_source_local_param.btc_aa_src_cb.encoder.s16AllocationMethod, a2dp_source_local_param.btc_aa_src_cb.encoder.u16BitRate,
a2dp_source_local_param.btc_aa_src_cb.encoder.s16SamplingFreq);
/* Reset entirely the SBC encoder */
SBC_Encoder_Init(&(btc_sbc_encoder));
APPL_TRACE_DEBUG("btc_a2dp_source_enc_init bit pool %d", btc_sbc_encoder.s16BitPool);
SBC_Encoder_Init(&(a2dp_source_local_param.btc_aa_src_cb.encoder));
APPL_TRACE_DEBUG("btc_a2dp_source_enc_init bit pool %d", a2dp_source_local_param.btc_aa_src_cb.encoder.s16BitPool);
}
@ -821,7 +822,7 @@ static void btc_a2dp_source_enc_init(BT_HDR *p_msg)
static void btc_a2dp_source_enc_update(BT_HDR *p_msg)
{
tBTC_MEDIA_UPDATE_AUDIO *pUpdateAudio = (tBTC_MEDIA_UPDATE_AUDIO *) p_msg;
SBC_ENC_PARAMS *pstrEncParams = &btc_sbc_encoder;
SBC_ENC_PARAMS *pstrEncParams = &a2dp_source_local_param.btc_aa_src_cb.encoder;
UINT16 s16SamplingFreq;
SINT16 s16BitPool = 0;
SINT16 s16BitRate;
@ -832,9 +833,9 @@ static void btc_a2dp_source_enc_update(BT_HDR *p_msg)
pUpdateAudio->MinMtuSize, pUpdateAudio->MaxBitPool, pUpdateAudio->MinBitPool);
/* Only update the bitrate and MTU size while timer is running to make sure it has been initialized */
//if (btc_aa_src_cb.is_tx_timer)
//if (a2dp_source_local_param.btc_aa_src_cb.is_tx_timer)
{
btc_aa_src_cb.TxAaMtuSize = ((BTC_MEDIA_AA_BUF_SIZE -
a2dp_source_local_param.btc_aa_src_cb.TxAaMtuSize = ((BTC_MEDIA_AA_BUF_SIZE -
BTC_MEDIA_AA_SBC_OFFSET - sizeof(BT_HDR))
< pUpdateAudio->MinMtuSize) ? (BTC_MEDIA_AA_BUF_SIZE - BTC_MEDIA_AA_SBC_OFFSET
- sizeof(BT_HDR)) : pUpdateAudio->MinMtuSize;
@ -913,19 +914,19 @@ static void btc_a2dp_source_enc_update(BT_HDR *p_msg)
if (s16BitPool > pUpdateAudio->MaxBitPool) {
APPL_TRACE_DEBUG("%s computed bitpool too large (%d)", __FUNCTION__, s16BitPool);
/* Decrease bitrate */
btc_sbc_encoder.u16BitRate -= BTC_MEDIA_BITRATE_STEP;
a2dp_source_local_param.btc_aa_src_cb.encoder.u16BitRate -= BTC_MEDIA_BITRATE_STEP;
/* Record that we have decreased the bitrate */
protect |= 1;
} else if (s16BitPool < pUpdateAudio->MinBitPool) {
APPL_TRACE_WARNING("%s computed bitpool too small (%d)", __FUNCTION__, s16BitPool);
/* Increase bitrate */
UINT16 previous_u16BitRate = btc_sbc_encoder.u16BitRate;
btc_sbc_encoder.u16BitRate += BTC_MEDIA_BITRATE_STEP;
UINT16 previous_u16BitRate = a2dp_source_local_param.btc_aa_src_cb.encoder.u16BitRate;
a2dp_source_local_param.btc_aa_src_cb.encoder.u16BitRate += BTC_MEDIA_BITRATE_STEP;
/* Record that we have increased the bitrate */
protect |= 2;
/* Check over-flow */
if (btc_sbc_encoder.u16BitRate < previous_u16BitRate) {
if (a2dp_source_local_param.btc_aa_src_cb.encoder.u16BitRate < previous_u16BitRate) {
protect |= 3;
}
} else {
@ -942,10 +943,10 @@ static void btc_a2dp_source_enc_update(BT_HDR *p_msg)
pstrEncParams->s16BitPool = s16BitPool;
APPL_TRACE_DEBUG("%s final bit rate %d, final bit pool %d", __FUNCTION__,
btc_sbc_encoder.u16BitRate, btc_sbc_encoder.s16BitPool);
a2dp_source_local_param.btc_aa_src_cb.encoder.u16BitRate, a2dp_source_local_param.btc_aa_src_cb.encoder.s16BitPool);
/* make sure we reinitialize encoder with new settings */
SBC_Encoder_Init(&(btc_sbc_encoder));
SBC_Encoder_Init(&(a2dp_source_local_param.btc_aa_src_cb.encoder));
}
}
@ -976,10 +977,10 @@ static void btc_a2dp_source_pcm2sbc_init(tBTC_MEDIA_INIT_AUDIO_FEEDING *p_feedin
case 32000:
case 48000:
/* For these sampling_freq the AV connection must be 48000 */
if (btc_sbc_encoder.s16SamplingFreq != SBC_sf48000) {
if (a2dp_source_local_param.btc_aa_src_cb.encoder.s16SamplingFreq != SBC_sf48000) {
/* Reconfiguration needed at 48000 */
APPL_TRACE_DEBUG("SBC Reconfiguration needed at 48000");
btc_sbc_encoder.s16SamplingFreq = SBC_sf48000;
a2dp_source_local_param.btc_aa_src_cb.encoder.s16SamplingFreq = SBC_sf48000;
reconfig_needed = TRUE;
}
break;
@ -988,10 +989,10 @@ static void btc_a2dp_source_pcm2sbc_init(tBTC_MEDIA_INIT_AUDIO_FEEDING *p_feedin
case 22050:
case 44100:
/* For these sampling_freq the AV connection must be 44100 */
if (btc_sbc_encoder.s16SamplingFreq != SBC_sf44100) {
if (a2dp_source_local_param.btc_aa_src_cb.encoder.s16SamplingFreq != SBC_sf44100) {
/* Reconfiguration needed at 44100 */
APPL_TRACE_DEBUG("SBC Reconfiguration needed at 44100");
btc_sbc_encoder.s16SamplingFreq = SBC_sf44100;
a2dp_source_local_param.btc_aa_src_cb.encoder.s16SamplingFreq = SBC_sf44100;
reconfig_needed = TRUE;
}
break;
@ -1001,21 +1002,21 @@ static void btc_a2dp_source_pcm2sbc_init(tBTC_MEDIA_INIT_AUDIO_FEEDING *p_feedin
}
/* Some AV Headsets do not support Mono => always ask for Stereo */
if (btc_sbc_encoder.s16ChannelMode == SBC_MONO) {
if (a2dp_source_local_param.btc_aa_src_cb.encoder.s16ChannelMode == SBC_MONO) {
APPL_TRACE_DEBUG("SBC Reconfiguration needed in Stereo");
btc_sbc_encoder.s16ChannelMode = SBC_JOINT_STEREO;
a2dp_source_local_param.btc_aa_src_cb.encoder.s16ChannelMode = SBC_JOINT_STEREO;
reconfig_needed = TRUE;
}
if (reconfig_needed != FALSE) {
APPL_TRACE_DEBUG("%s :: mtu %d", __FUNCTION__, btc_aa_src_cb.TxAaMtuSize);
APPL_TRACE_DEBUG("%s :: mtu %d", __FUNCTION__, a2dp_source_local_param.btc_aa_src_cb.TxAaMtuSize);
APPL_TRACE_DEBUG("ch mode %d, nbsubd %d, nb %d, alloc %d, rate %d, freq %d",
btc_sbc_encoder.s16ChannelMode,
btc_sbc_encoder.s16NumOfSubBands, btc_sbc_encoder.s16NumOfBlocks,
btc_sbc_encoder.s16AllocationMethod, btc_sbc_encoder.u16BitRate,
btc_sbc_encoder.s16SamplingFreq);
a2dp_source_local_param.btc_aa_src_cb.encoder.s16ChannelMode,
a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfSubBands, a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfBlocks,
a2dp_source_local_param.btc_aa_src_cb.encoder.s16AllocationMethod, a2dp_source_local_param.btc_aa_src_cb.encoder.u16BitRate,
a2dp_source_local_param.btc_aa_src_cb.encoder.s16SamplingFreq);
SBC_Encoder_Init(&(btc_sbc_encoder));
SBC_Encoder_Init(&(a2dp_source_local_param.btc_aa_src_cb.encoder));
} else {
APPL_TRACE_DEBUG("%s no SBC reconfig needed", __FUNCTION__);
}
@ -1037,13 +1038,13 @@ static void btc_a2dp_source_audio_feeding_init(BT_HDR *p_msg)
APPL_TRACE_DEBUG("%s format:%d", __FUNCTION__, p_feeding->feeding.format);
/* Save Media Feeding information */
btc_aa_src_cb.feeding_mode = p_feeding->feeding_mode;
btc_aa_src_cb.media_feeding = p_feeding->feeding;
a2dp_source_local_param.btc_aa_src_cb.feeding_mode = p_feeding->feeding_mode;
a2dp_source_local_param.btc_aa_src_cb.media_feeding = p_feeding->feeding;
/* Handle different feeding formats */
switch (p_feeding->feeding.format) {
case BTC_AV_CODEC_PCM:
btc_aa_src_cb.TxTranscoding = BTC_MEDIA_TRSCD_PCM_2_SBC;
a2dp_source_local_param.btc_aa_src_cb.TxTranscoding = BTC_MEDIA_TRSCD_PCM_2_SBC;
btc_a2dp_source_pcm2sbc_init(p_feeding);
break;
@ -1067,10 +1068,10 @@ static void btc_a2dp_source_aa_tx_flush(void)
/* Flush all enqueued music buffers (encoded) */
APPL_TRACE_DEBUG("%s", __FUNCTION__);
btc_aa_src_cb.media_feeding_state.pcm.counter = 0;
btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue = 0;
a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.counter = 0;
a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue = 0;
btc_a2dp_source_flush_q(btc_aa_src_cb.TxAaQ);
btc_a2dp_source_flush_q(a2dp_source_local_param.btc_aa_src_cb.TxAaQ);
btc_aa_src_data_read(NULL, -1);
}
@ -1088,35 +1089,35 @@ static UINT8 btc_get_num_aa_frame(void)
{
UINT8 result = 0;
switch (btc_aa_src_cb.TxTranscoding) {
switch (a2dp_source_local_param.btc_aa_src_cb.TxTranscoding) {
case BTC_MEDIA_TRSCD_PCM_2_SBC: {
UINT32 pcm_bytes_per_frame = btc_sbc_encoder.s16NumOfSubBands *
btc_sbc_encoder.s16NumOfBlocks *
btc_aa_src_cb.media_feeding.cfg.pcm.num_channel *
btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample / 8;
UINT32 pcm_bytes_per_frame = a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfSubBands *
a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfBlocks *
a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.num_channel *
a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample / 8;
UINT32 us_this_tick = BTC_MEDIA_TIME_TICK_MS * 1000;
UINT64 now_us = time_now_us();
if (last_frame_us != 0) {
if (a2dp_source_local_param.last_frame_us != 0) {
#if _POSIX_TIMERS
us_this_tick = (now_us - last_frame_us);
us_this_tick = (now_us - a2dp_source_local_param.last_frame_us);
#else
// consider the case that the number of day increases and timeofday wraps around
us_this_tick = (now_us > last_frame_us) ? (now_us - last_frame_us) :
(now_us + 86400000000ull - last_frame_us);
us_this_tick = (now_us > a2dp_source_local_param.last_frame_us) ? (now_us - a2dp_source_local_param.last_frame_us) :
(now_us + 86400000000ull - a2dp_source_local_param.last_frame_us);
#endif
}
last_frame_us = now_us;
a2dp_source_local_param.last_frame_us = now_us;
btc_aa_src_cb.media_feeding_state.pcm.counter +=
btc_aa_src_cb.media_feeding_state.pcm.bytes_per_tick *
a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.counter +=
a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.bytes_per_tick *
us_this_tick / (BTC_MEDIA_TIME_TICK_MS * 1000);
/* calculate nbr of frames pending for this media tick */
result = btc_aa_src_cb.media_feeding_state.pcm.counter / pcm_bytes_per_frame;
result = a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.counter / pcm_bytes_per_frame;
/* limit the frames to be sent */
UINT32 frm_nb_threshold = MAX_OUTPUT_A2DP_SRC_FRAME_QUEUE_SZ - fixed_queue_length(btc_aa_src_cb.TxAaQ);
UINT32 frm_nb_threshold = MAX_OUTPUT_A2DP_SRC_FRAME_QUEUE_SZ - fixed_queue_length(a2dp_source_local_param.btc_aa_src_cb.TxAaQ);
if (frm_nb_threshold > MAX_PCM_FRAME_NUM_PER_TICK) {
frm_nb_threshold = MAX_PCM_FRAME_NUM_PER_TICK;
}
@ -1125,7 +1126,7 @@ static UINT8 btc_get_num_aa_frame(void)
APPL_TRACE_EVENT("Limit frms to send from %d to %d", result, frm_nb_threshold);
result = frm_nb_threshold;
}
btc_aa_src_cb.media_feeding_state.pcm.counter -= result * pcm_bytes_per_frame;
a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.counter -= result * pcm_bytes_per_frame;
BTC_TRACE_VERBOSE("WRITE %d FRAMES", result);
}
@ -1133,7 +1134,7 @@ static UINT8 btc_get_num_aa_frame(void)
default:
APPL_TRACE_ERROR("ERROR btc_get_num_aa_frame Unsupported transcoding format 0x%x",
btc_aa_src_cb.TxTranscoding);
a2dp_source_local_param.btc_aa_src_cb.TxTranscoding);
result = 0;
break;
}
@ -1153,13 +1154,13 @@ static UINT8 btc_get_num_aa_frame(void)
BOOLEAN btc_media_aa_read_feeding(void)
{
UINT16 blocm_x_subband = btc_sbc_encoder.s16NumOfSubBands * \
btc_sbc_encoder.s16NumOfBlocks;
UINT16 blocm_x_subband = a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfSubBands * \
a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfBlocks;
UINT32 read_size;
UINT16 sbc_sampling = 48000;
UINT32 src_samples;
UINT16 bytes_needed = blocm_x_subband * btc_sbc_encoder.s16NumOfChannels * \
btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample / 8;
UINT16 bytes_needed = blocm_x_subband * a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfChannels * \
a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample / 8;
static UINT16 up_sampled_buffer[SBC_MAX_NUM_FRAME * SBC_MAX_NUM_OF_BLOCKS
* SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS * 2];
static UINT16 read_buffer[SBC_MAX_NUM_FRAME * SBC_MAX_NUM_OF_BLOCKS
@ -1172,7 +1173,7 @@ BOOLEAN btc_media_aa_read_feeding(void)
UINT32 nb_byte_read = 0;
/* Get the SBC sampling rate */
switch (btc_sbc_encoder.s16SamplingFreq) {
switch (a2dp_source_local_param.btc_aa_src_cb.encoder.s16SamplingFreq) {
case SBC_sf48000:
sbc_sampling = 48000;
break;
@ -1187,19 +1188,19 @@ BOOLEAN btc_media_aa_read_feeding(void)
break;
}
if (sbc_sampling == btc_aa_src_cb.media_feeding.cfg.pcm.sampling_freq) {
read_size = bytes_needed - btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue;
if (sbc_sampling == a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.sampling_freq) {
read_size = bytes_needed - a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue;
nb_byte_read = btc_aa_src_data_read(
((uint8_t *)btc_sbc_encoder.as16PcmBuffer) +
btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue,
((uint8_t *)a2dp_source_local_param.btc_aa_src_cb.encoder.as16PcmBuffer) +
a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue,
read_size);
if (nb_byte_read == read_size) {
btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue = 0;
a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue = 0;
return TRUE;
} else {
APPL_TRACE_WARNING("### UNDERFLOW :: ONLY READ %d BYTES OUT OF %d ###",
nb_byte_read, read_size);
btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue += nb_byte_read;
a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue += nb_byte_read;
return FALSE;
}
}
@ -1208,7 +1209,7 @@ BOOLEAN btc_media_aa_read_feeding(void)
/* to read. */
/* E.g 128/6=21.3333 => read 22 and 21 and 21 => max = 2; threshold = 0*/
fract_needed = FALSE; /* Default */
switch (btc_aa_src_cb.media_feeding.cfg.pcm.sampling_freq) {
switch (a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.sampling_freq) {
case 32000:
case 8000:
fract_needed = TRUE;
@ -1224,26 +1225,26 @@ BOOLEAN btc_media_aa_read_feeding(void)
/* Compute number of sample to read from source */
src_samples = blocm_x_subband;
src_samples *= btc_aa_src_cb.media_feeding.cfg.pcm.sampling_freq;
src_samples *= a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.sampling_freq;
src_samples /= sbc_sampling;
/* The previous division may have a remainder not null */
if (fract_needed) {
if (btc_aa_src_cb.media_feeding_state.pcm.aa_feed_counter <= fract_threshold) {
if (a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_counter <= fract_threshold) {
src_samples++; /* for every read before threshold add one sample */
}
/* do nothing if counter >= threshold */
btc_aa_src_cb.media_feeding_state.pcm.aa_feed_counter++; /* one more read */
if (btc_aa_src_cb.media_feeding_state.pcm.aa_feed_counter > fract_max) {
btc_aa_src_cb.media_feeding_state.pcm.aa_feed_counter = 0;
a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_counter++; /* one more read */
if (a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_counter > fract_max) {
a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_counter = 0;
}
}
/* Compute number of bytes to read from source */
read_size = src_samples;
read_size *= btc_aa_src_cb.media_feeding.cfg.pcm.num_channel;
read_size *= (btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample / 8);
read_size *= a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.num_channel;
read_size *= (a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample / 8);
/* Read Data from data channel */
nb_byte_read = btc_aa_src_data_read((uint8_t *)read_buffer, read_size);
@ -1258,7 +1259,7 @@ BOOLEAN btc_media_aa_read_feeding(void)
return FALSE;
}
if (btc_aa_src_cb.feeding_mode == BTC_AV_FEEDING_ASYNCHRONOUS) {
if (a2dp_source_local_param.btc_aa_src_cb.feeding_mode == BTC_AV_FEEDING_ASYNCHRONOUS) {
/* Fill the unfilled part of the read buffer with silence (0) */
memset(((UINT8 *)read_buffer) + nb_byte_read, 0, read_size - nb_byte_read);
nb_byte_read = read_size;
@ -1266,34 +1267,34 @@ BOOLEAN btc_media_aa_read_feeding(void)
}
/* Initialize PCM up-sampling engine */
bta_av_sbc_init_up_sample(btc_aa_src_cb.media_feeding.cfg.pcm.sampling_freq,
sbc_sampling, btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample,
btc_aa_src_cb.media_feeding.cfg.pcm.num_channel);
bta_av_sbc_init_up_sample(a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.sampling_freq,
sbc_sampling, a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample,
a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.num_channel);
/* re-sample read buffer */
/* The output PCM buffer will be stereo, 16 bit per sample */
dst_size_used = bta_av_sbc_up_sample((UINT8 *)read_buffer,
(UINT8 *)up_sampled_buffer + btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue,
(UINT8 *)up_sampled_buffer + a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue,
nb_byte_read,
sizeof(up_sampled_buffer) - btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue,
sizeof(up_sampled_buffer) - a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue,
&src_size_used);
/* update the residue */
btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue += dst_size_used;
a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue += dst_size_used;
/* only copy the pcm sample when we have up-sampled enough PCM */
if (btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue >= bytes_needed) {
if (a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue >= bytes_needed) {
/* Copy the output pcm samples in SBC encoding buffer */
memcpy((UINT8 *)btc_sbc_encoder.as16PcmBuffer,
memcpy((UINT8 *)a2dp_source_local_param.btc_aa_src_cb.encoder.as16PcmBuffer,
(UINT8 *)up_sampled_buffer,
bytes_needed);
/* update the residue */
btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue -= bytes_needed;
a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue -= bytes_needed;
if (btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue != 0) {
if (a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue != 0) {
memcpy((UINT8 *)up_sampled_buffer,
(UINT8 *)up_sampled_buffer + bytes_needed,
btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue);
a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue);
}
return TRUE;
}
@ -1313,13 +1314,13 @@ BOOLEAN btc_media_aa_read_feeding(void)
static void btc_media_aa_prep_sbc_2_send(UINT8 nb_frame)
{
BT_HDR *p_buf;
UINT16 blocm_x_subband = btc_sbc_encoder.s16NumOfSubBands *
btc_sbc_encoder.s16NumOfBlocks;
UINT16 blocm_x_subband = a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfSubBands *
a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfBlocks;
while (nb_frame) {
if (NULL == (p_buf = osi_malloc(BTC_MEDIA_AA_BUF_SIZE))) {
APPL_TRACE_ERROR ("ERROR btc_media_aa_prep_sbc_2_send no buffer TxCnt %d ",
fixed_queue_length(btc_aa_src_cb.TxAaQ));
fixed_queue_length(a2dp_source_local_param.btc_aa_src_cb.TxAaQ));
return;
}
@ -1330,53 +1331,53 @@ static void btc_media_aa_prep_sbc_2_send(UINT8 nb_frame)
do {
/* Write @ of allocated buffer in encoder.pu8Packet */
btc_sbc_encoder.pu8Packet = (UINT8 *) (p_buf + 1) + p_buf->offset + p_buf->len;
a2dp_source_local_param.btc_aa_src_cb.encoder.pu8Packet = (UINT8 *) (p_buf + 1) + p_buf->offset + p_buf->len;
/* Fill allocated buffer with 0 */
memset(btc_sbc_encoder.as16PcmBuffer, 0, blocm_x_subband
* btc_sbc_encoder.s16NumOfChannels);
memset(a2dp_source_local_param.btc_aa_src_cb.encoder.as16PcmBuffer, 0, blocm_x_subband
* a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfChannels);
/* Read PCM data and upsample them if needed */
if (btc_media_aa_read_feeding()) {
/* SBC encode and descramble frame */
SBC_Encoder(&(btc_sbc_encoder));
SBC_Encoder(&(a2dp_source_local_param.btc_aa_src_cb.encoder));
/* Update SBC frame length */
p_buf->len += btc_sbc_encoder.u16PacketLength;
p_buf->len += a2dp_source_local_param.btc_aa_src_cb.encoder.u16PacketLength;
nb_frame--;
p_buf->layer_specific++;
} else {
APPL_TRACE_WARNING("btc_media_aa_prep_sbc_2_send underflow %d, %d",
nb_frame, btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue);
btc_aa_src_cb.media_feeding_state.pcm.counter += nb_frame *
btc_sbc_encoder.s16NumOfSubBands *
btc_sbc_encoder.s16NumOfBlocks *
btc_aa_src_cb.media_feeding.cfg.pcm.num_channel *
btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample / 8;
nb_frame, a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.aa_feed_residue);
a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.counter += nb_frame *
a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfSubBands *
a2dp_source_local_param.btc_aa_src_cb.encoder.s16NumOfBlocks *
a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.num_channel *
a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample / 8;
/* no more pcm to read */
nb_frame = 0;
/* break read loop if timer was stopped (media task stopped) */
if ( btc_aa_src_cb.is_tx_timer == FALSE ) {
if ( a2dp_source_local_param.btc_aa_src_cb.is_tx_timer == FALSE ) {
osi_free(p_buf);
return;
}
}
} while (((p_buf->len + btc_sbc_encoder.u16PacketLength) < btc_aa_src_cb.TxAaMtuSize)
} while (((p_buf->len + a2dp_source_local_param.btc_aa_src_cb.encoder.u16PacketLength) < a2dp_source_local_param.btc_aa_src_cb.TxAaMtuSize)
&& (p_buf->layer_specific < 0x0F) && nb_frame);
if (p_buf->len) {
/* timestamp of the media packet header represent the TS of the first SBC frame
i.e the timestamp before including this frame */
*((UINT32 *) (p_buf + 1)) = btc_aa_src_cb.timestamp;
*((UINT32 *) (p_buf + 1)) = a2dp_source_local_param.btc_aa_src_cb.timestamp;
btc_aa_src_cb.timestamp += p_buf->layer_specific * blocm_x_subband;
a2dp_source_local_param.btc_aa_src_cb.timestamp += p_buf->layer_specific * blocm_x_subband;
if (btc_aa_src_cb.tx_flush) {
if (a2dp_source_local_param.btc_aa_src_cb.tx_flush) {
APPL_TRACE_DEBUG("### tx suspended, discarded frame ###");
if (fixed_queue_length(btc_aa_src_cb.TxAaQ) > 0) {
btc_a2dp_source_flush_q(btc_aa_src_cb.TxAaQ);
if (fixed_queue_length(a2dp_source_local_param.btc_aa_src_cb.TxAaQ) > 0) {
btc_a2dp_source_flush_q(a2dp_source_local_param.btc_aa_src_cb.TxAaQ);
}
osi_free(p_buf);
@ -1384,7 +1385,7 @@ static void btc_media_aa_prep_sbc_2_send(UINT8 nb_frame)
}
/* Enqueue the encoded SBC frame in AA Tx Queue */
fixed_queue_enqueue(btc_aa_src_cb.TxAaQ, p_buf);
fixed_queue_enqueue(a2dp_source_local_param.btc_aa_src_cb.TxAaQ, p_buf);
} else {
osi_free(p_buf);
}
@ -1407,24 +1408,24 @@ static void btc_a2dp_source_prep_2_send(UINT8 nb_frame)
nb_frame = MAX_OUTPUT_A2DP_SRC_FRAME_QUEUE_SZ;
}
if (fixed_queue_length(btc_aa_src_cb.TxAaQ) > (MAX_OUTPUT_A2DP_SRC_FRAME_QUEUE_SZ - nb_frame)) {
if (fixed_queue_length(a2dp_source_local_param.btc_aa_src_cb.TxAaQ) > (MAX_OUTPUT_A2DP_SRC_FRAME_QUEUE_SZ - nb_frame)) {
APPL_TRACE_WARNING("TX Q overflow: %d/%d",
fixed_queue_length(btc_aa_src_cb.TxAaQ), MAX_OUTPUT_A2DP_SRC_FRAME_QUEUE_SZ - nb_frame);
fixed_queue_length(a2dp_source_local_param.btc_aa_src_cb.TxAaQ), MAX_OUTPUT_A2DP_SRC_FRAME_QUEUE_SZ - nb_frame);
}
while (fixed_queue_length(btc_aa_src_cb.TxAaQ) > (MAX_OUTPUT_A2DP_SRC_FRAME_QUEUE_SZ - nb_frame)) {
osi_free(fixed_queue_try_dequeue(btc_aa_src_cb.TxAaQ));
while (fixed_queue_length(a2dp_source_local_param.btc_aa_src_cb.TxAaQ) > (MAX_OUTPUT_A2DP_SRC_FRAME_QUEUE_SZ - nb_frame)) {
osi_free(fixed_queue_try_dequeue(a2dp_source_local_param.btc_aa_src_cb.TxAaQ));
}
// Transcode frame
switch (btc_aa_src_cb.TxTranscoding) {
switch (a2dp_source_local_param.btc_aa_src_cb.TxTranscoding) {
case BTC_MEDIA_TRSCD_PCM_2_SBC:
btc_media_aa_prep_sbc_2_send(nb_frame);
break;
default:
APPL_TRACE_ERROR("%s unsupported transcoding format 0x%x", __func__, btc_aa_src_cb.TxTranscoding);
APPL_TRACE_ERROR("%s unsupported transcoding format 0x%x", __func__, a2dp_source_local_param.btc_aa_src_cb.TxTranscoding);
break;
}
}
@ -1464,7 +1465,7 @@ static void btc_a2dp_source_handle_timer(UNUSED_ATTR void *context)
return;
}
if (btc_aa_src_cb.is_tx_timer == TRUE) {
if (a2dp_source_local_param.btc_aa_src_cb.is_tx_timer == TRUE) {
btc_a2dp_source_send_aa_frame();
} else {
APPL_TRACE_WARNING("Media task Scheduled after Suspend");
@ -1489,17 +1490,17 @@ static void btc_a2dp_source_alarm_cb(UNUSED_ATTR void *context)
static void btc_a2dp_source_feeding_state_reset(void)
{
/* By default, just clear the entire state */
memset(&btc_aa_src_cb.media_feeding_state, 0, sizeof(btc_aa_src_cb.media_feeding_state));
memset(&a2dp_source_local_param.btc_aa_src_cb.media_feeding_state, 0, sizeof(a2dp_source_local_param.btc_aa_src_cb.media_feeding_state));
if (btc_aa_src_cb.TxTranscoding == BTC_MEDIA_TRSCD_PCM_2_SBC) {
btc_aa_src_cb.media_feeding_state.pcm.bytes_per_tick =
(btc_aa_src_cb.media_feeding.cfg.pcm.sampling_freq *
btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample / 8 *
btc_aa_src_cb.media_feeding.cfg.pcm.num_channel *
if (a2dp_source_local_param.btc_aa_src_cb.TxTranscoding == BTC_MEDIA_TRSCD_PCM_2_SBC) {
a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.bytes_per_tick =
(a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.sampling_freq *
a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.bit_per_sample / 8 *
a2dp_source_local_param.btc_aa_src_cb.media_feeding.cfg.pcm.num_channel *
BTC_MEDIA_TIME_TICK_MS) / 1000;
APPL_TRACE_EVENT("pcm bytes per tick %d",
(int)btc_aa_src_cb.media_feeding_state.pcm.bytes_per_tick);
(int)a2dp_source_local_param.btc_aa_src_cb.media_feeding_state.pcm.bytes_per_tick);
}
}
@ -1515,26 +1516,26 @@ static void btc_a2dp_source_feeding_state_reset(void)
static void btc_a2dp_source_aa_start_tx(void)
{
APPL_TRACE_DEBUG("btc_a2dp_source_aa_start_tx is timer %d, feeding mode %d",
btc_aa_src_cb.is_tx_timer, btc_aa_src_cb.feeding_mode);
a2dp_source_local_param.btc_aa_src_cb.is_tx_timer, a2dp_source_local_param.btc_aa_src_cb.feeding_mode);
btc_aa_src_cb.is_tx_timer = TRUE;
last_frame_us = 0;
a2dp_source_local_param.btc_aa_src_cb.is_tx_timer = TRUE;
a2dp_source_local_param.last_frame_us = 0;
/* Reset the media feeding state */
btc_a2dp_source_feeding_state_reset();
APPL_TRACE_EVENT("starting timer %dms", BTC_MEDIA_TIME_TICK_MS);
assert(btc_aa_src_cb.media_alarm == NULL);
assert(a2dp_source_local_param.btc_aa_src_cb.media_alarm == NULL);
btc_aa_src_cb.media_alarm = osi_alarm_new("aaTx", btc_a2dp_source_alarm_cb, NULL, BTC_MEDIA_TIME_TICK_MS);
a2dp_source_local_param.btc_aa_src_cb.media_alarm = osi_alarm_new("aaTx", btc_a2dp_source_alarm_cb, NULL, BTC_MEDIA_TIME_TICK_MS);
if (!btc_aa_src_cb.media_alarm) {
if (!a2dp_source_local_param.btc_aa_src_cb.media_alarm) {
BTC_TRACE_ERROR("%s unable to allocate media alarm.", __func__);
return;
}
osi_alarm_set_periodic(btc_aa_src_cb.media_alarm, BTC_MEDIA_TIME_TICK_MS);
osi_alarm_set_periodic(a2dp_source_local_param.btc_aa_src_cb.media_alarm, BTC_MEDIA_TIME_TICK_MS);
}
/*******************************************************************************
@ -1548,17 +1549,17 @@ static void btc_a2dp_source_aa_start_tx(void)
*******************************************************************************/
static void btc_a2dp_source_aa_stop_tx(void)
{
APPL_TRACE_DEBUG("%s is_tx_timer: %d", __func__, btc_aa_src_cb.is_tx_timer);
APPL_TRACE_DEBUG("%s is_tx_timer: %d", __func__, a2dp_source_local_param.btc_aa_src_cb.is_tx_timer);
const bool send_ack = (btc_aa_src_cb.is_tx_timer != FALSE);
const bool send_ack = (a2dp_source_local_param.btc_aa_src_cb.is_tx_timer != FALSE);
/* Stop the timer first */
if (btc_aa_src_cb.media_alarm) {
osi_alarm_cancel(btc_aa_src_cb.media_alarm);
osi_alarm_free(btc_aa_src_cb.media_alarm);
if (a2dp_source_local_param.btc_aa_src_cb.media_alarm) {
osi_alarm_cancel(a2dp_source_local_param.btc_aa_src_cb.media_alarm);
osi_alarm_free(a2dp_source_local_param.btc_aa_src_cb.media_alarm);
}
btc_aa_src_cb.media_alarm = NULL;
btc_aa_src_cb.is_tx_timer = FALSE;
a2dp_source_local_param.btc_aa_src_cb.media_alarm = NULL;
a2dp_source_local_param.btc_aa_src_cb.is_tx_timer = FALSE;
/* Try to send acknowldegment once the media stream is
stopped. This will make sure that the A2DP HAL layer is
@ -1576,8 +1577,8 @@ static void btc_a2dp_source_aa_stop_tx(void)
}
/* audio engine stopped, reset tx suspended flag */
btc_aa_src_cb.tx_flush = 0;
last_frame_us = 0;
a2dp_source_local_param.btc_aa_src_cb.tx_flush = 0;
a2dp_source_local_param.last_frame_us = 0;
/* Reset the feeding state */
btc_a2dp_source_feeding_state_reset();
@ -1602,11 +1603,11 @@ static void btc_a2dp_source_flush_q(fixed_queue_t *p_q)
static void btc_a2dp_source_thread_init(UNUSED_ATTR void *context)
{
APPL_TRACE_EVENT("%s\n", __func__);
memset(&btc_aa_src_cb, 0, sizeof(btc_aa_src_cb));
memset(&a2dp_source_local_param.btc_aa_src_cb, 0, sizeof(a2dp_source_local_param.btc_aa_src_cb));
btc_a2dp_source_state = BTC_A2DP_SOURCE_STATE_ON;
btc_aa_src_cb.TxAaQ = fixed_queue_new(QUEUE_SIZE_MAX);
a2dp_source_local_param.btc_aa_src_cb.TxAaQ = fixed_queue_new(QUEUE_SIZE_MAX);
btc_a2dp_control_init();
}
@ -1619,9 +1620,9 @@ static void btc_a2dp_source_thread_cleanup(UNUSED_ATTR void *context)
btc_a2dp_control_cleanup();
fixed_queue_free(btc_aa_src_cb.TxAaQ, osi_free_func);
fixed_queue_free(a2dp_source_local_param.btc_aa_src_cb.TxAaQ, osi_free_func);
future_ready(btc_a2dp_source_future, NULL);
future_ready(a2dp_source_local_param.btc_a2dp_source_future, NULL);
}
#endif /* BTC_AV_INCLUDED */

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,9 @@ 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));
btc_rc_cb.rc_vol_label = MAX_LABEL;
btc_rc_cb.rc_volume = MAX_VOLUME;
}
}
@ -1059,7 +1031,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,14 @@
#include "osi/mutex.h"
#include "esp_bt.h"
#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;

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);
@ -106,13 +98,13 @@ void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
}
}
break;
}
case BTC_GATTS_ACT_ADD_CHAR: {
if (src->add_char.char_val.attr_value && (src->add_char.char_val.attr_len > 0)) {
dst->add_char.char_val.attr_value = (uint8_t *) osi_malloc(src->add_char.char_val.attr_len);
if (dst->add_char.char_val.attr_value) {
memcpy(dst->add_char.char_val.attr_value, src->add_char.char_val.attr_value,
memcpy(dst->add_char.char_val.attr_value, src->add_char.char_val.attr_value,
src->add_char.char_val.attr_len);
} else {
BTC_TRACE_ERROR("%s %d no mem\n", __func__, msg->act);
@ -231,7 +223,7 @@ void btc_gatts_arg_deep_free(btc_msg_t *msg)
}
static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db,
static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db,
esp_gatt_if_t gatts_if,
uint8_t max_nb_attr,
uint8_t srvc_inst_id)
@ -283,7 +275,7 @@ static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db,
esp_srvc_id.id.inst_id = srvc_inst_id;
btc_gatts_uuid_format_convert(&esp_srvc_id.id.uuid,gatts_attr_db[i].att_desc.length,
gatts_attr_db[i].att_desc.value);
btc_to_bta_srvc_id(&srvc_id, &esp_srvc_id);
if (btc_creat_tab_env.is_use_svc != true) {
BTA_GATTS_CreateService(gatts_if, &srvc_id.id.uuid,
@ -297,7 +289,7 @@ static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db,
memset(&btc_creat_tab_env, 0, sizeof(esp_btc_creat_tab_t));
return;
}
if (future_await(future_p) == FUTURE_FAIL) {
BTC_TRACE_ERROR("%s failed\n", __func__);
return;
@ -332,12 +324,12 @@ static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db,
}
case ESP_GATT_UUID_INCLUDE_SERVICE:{
esp_gatts_incl_svc_desc_t *incl_svc_desc = (esp_gatts_incl_svc_desc_t *)gatts_attr_db[i].att_desc.value;
if(incl_svc_desc!= NULL){
if(btc_creat_tab_env.svc_start_hdl != 0){
BTA_GATTS_AddIncludeService(btc_creat_tab_env.svc_start_hdl,
BTA_GATTS_AddIncludeService(btc_creat_tab_env.svc_start_hdl,
incl_svc_desc->start_hdl);
if (future_await(future_p) == FUTURE_FAIL) {
BTC_TRACE_ERROR("%s failed\n", __func__);
return;
@ -378,10 +370,10 @@ static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db,
}
}
}
break;
}
case ESP_GATT_UUID_CHAR_EXT_PROP:
case ESP_GATT_UUID_CHAR_EXT_PROP:
case ESP_GATT_UUID_CHAR_DESCRIPTION:
case ESP_GATT_UUID_CHAR_CLIENT_CONFIG:
case ESP_GATT_UUID_CHAR_SRVR_CONFIG:
@ -406,7 +398,7 @@ static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db,
btc_to_bta_uuid(&bta_char_uuid, &uuid_temp);
control.auto_rsp = gatts_attr_db[i].attr_control.auto_rsp;
BTA_GATTS_AddCharDescriptor(svc_hal, perm, &bta_char_uuid, &attr_val, &control);
if (future_await(future_p) == FUTURE_FAIL) {
BTC_TRACE_ERROR("%s failed\n", __func__);
return;
@ -419,7 +411,7 @@ static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db,
break;
}
}
param.add_attr_tab.handles = btc_creat_tab_env.handles;
@ -427,7 +419,7 @@ static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db,
param.add_attr_tab.svc_inst_id = srvc_inst_id;
btc_gatts_cb_to_app(ESP_GATTS_CREAT_ATTR_TAB_EVT, gatts_if, &param);
btc_gatts_cb_to_app(ESP_GATTS_CREAT_ATTR_TAB_EVT, gatts_if, &param);
//reset the env after sent the data to app
memset(&btc_creat_tab_env, 0, sizeof(esp_btc_creat_tab_t));
@ -504,7 +496,7 @@ static esp_gatt_status_t btc_gatts_check_valid_attr_tab(esp_gatts_attr_db_t *gat
esp_gatt_status_t btc_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, uint8_t **value)
{
return BTA_GetAttributeValue(attr_handle, length, value);
}
@ -568,14 +560,14 @@ static void btc_gatts_inter_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
{
bt_status_t status;
btc_msg_t msg;
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GATTS;
msg.act = event;
if(btc_creat_tab_env.is_tab_creat_svc && btc_creat_tab_env.complete_future) {
switch(event) {
case BTA_GATTS_CREATE_EVT: {
//save the service handle to the btc module after used
//save the service handle to the btc module after used
//the attribute table method to creat a service
bta_to_btc_uuid(&btc_creat_tab_env.svc_uuid, &p_data->create.uuid);
uint8_t index = btc_creat_tab_env.handle_idx;
@ -663,7 +655,7 @@ void btc_gatts_call_handler(btc_msg_t *msg)
btc_to_bta_uuid(&uuid, &arg->add_char.char_uuid);
BTA_GATTS_AddCharacteristic(arg->add_char.service_handle, &uuid,
arg->add_char.perm, arg->add_char.property,
arg->add_char.perm, arg->add_char.property,
(tGATT_ATTR_VAL *)&arg->add_char.char_val,
(tBTA_GATTS_ATTR_CONTROL *)&arg->add_char.attr_control);
break;
@ -672,7 +664,7 @@ void btc_gatts_call_handler(btc_msg_t *msg)
tBT_UUID uuid;
btc_to_bta_uuid(&uuid, &arg->add_descr.descr_uuid);
BTA_GATTS_AddCharDescriptor(arg->add_descr.service_handle, arg->add_descr.perm, &uuid,
(tBTA_GATT_ATTR_VAL *)&arg->add_descr.descr_val,
(tBTA_GATT_ATTR_VAL *)&arg->add_descr.descr_val,
(tBTA_GATTS_ATTR_CONTROL *)&arg->add_descr.attr_control);
break;
}
@ -700,7 +692,7 @@ void btc_gatts_call_handler(btc_msg_t *msg)
break;
}
case BTC_GATTS_ACT_SET_ATTR_VALUE:
BTA_SetAttributeValue(arg->set_attr_val.handle, arg->set_attr_val.length,
BTA_SetAttributeValue(arg->set_attr_val.handle, arg->set_attr_val.length,
arg->set_attr_val.value);
break;
case BTC_GATTS_ACT_OPEN: {
@ -785,7 +777,7 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
param.read.offset = p_data->req_data.p_data->read_req.offset;
param.read.is_long = p_data->req_data.p_data->read_req.is_long;
param.read.need_rsp = p_data->req_data.p_data->read_req.need_rsp;
param.read.need_rsp = p_data->req_data.p_data->read_req.need_rsp;
btc_gatts_cb_to_app(ESP_GATTS_READ_EVT, gatts_if, &param);
break;
}

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,7 +161,7 @@ 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 BTM_SCO_HCI_INCLUDED
data_path = ESP_SCO_DATA_PATH_HCI;
@ -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_vb.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

@ -2049,12 +2049,6 @@ The maximum number of payload octets that the local device can receive in a sing
#define HEAP_ALLOCATION_FROM_SPIRAM_FIRST FALSE
#endif
#if UC_BT_BLE_DYNAMIC_ENV_MEMORY
#define BT_BLE_DYNAMIC_ENV_MEMORY TRUE
#else
#define BT_BLE_DYNAMIC_ENV_MEMORY FALSE
#endif
#include "common/bt_trace.h"
#endif /* BT_TARGET_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,19 +95,19 @@ 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
@ -108,7 +117,7 @@ static void start_up(void)
// 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

@ -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
@ -224,10 +223,14 @@ void BTE_InitStack(void)
if ((bta_dm_di_cb_ptr = (tBTA_DM_DI_CB *)osi_malloc(sizeof(tBTA_DM_DI_CB))) == NULL) {
return;
}
if ((bta_dm_conn_srvcs_ptr = (tBTA_DM_CONNECTED_SRVCS *)osi_malloc(sizeof(tBTA_DM_CONNECTED_SRVCS))) == 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_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)
@ -251,6 +254,12 @@ void BTE_InitStack(void)
}
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) {
return;
}
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) {
return;
@ -262,6 +271,11 @@ void BTE_InitStack(void)
return;
}
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) {
return;
}
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) {
@ -322,11 +336,17 @@ void BTE_DeinitStack(void)
#if BTA_AV_INCLUDED==TRUE
osi_free(bta_av_cb_ptr);
bta_av_cb_ptr = NULL;
osi_free(bta_av_sbc_ups_cb_ptr);
bta_av_sbc_ups_cb_ptr = NULL;
#endif
#if BTA_AR_INCLUDED==TRUE
osi_free(bta_ar_cb_ptr);
bta_ar_cb_ptr = NULL;
#endif
#if SDP_INCLUDED == TRUE
osi_free(g_disc_raw_data_buf);
g_disc_raw_data_buf = NULL;
#endif
#if BTA_SDP_INCLUDED == TRUE
osi_free(bta_sdp_cb_ptr);
bta_sdp_cb_ptr = NULL;
@ -339,6 +359,8 @@ void BTE_DeinitStack(void)
osi_free(bta_hf_client_cb_ptr);
bta_hf_client_cb_ptr = NULL;
#endif
osi_free(bta_dm_conn_srvcs_ptr);
bta_dm_conn_srvcs_ptr = NULL;
osi_free(bta_dm_di_cb_ptr);
bta_dm_di_cb_ptr = NULL;
osi_free(bta_dm_search_cb_ptr);
@ -349,6 +371,10 @@ void BTE_DeinitStack(void)
bta_sys_cb_ptr = NULL;
#endif // BTA_INCLUDED == TRUE
#if (defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE)
GAP_Deinit();
#endif
#if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE && AVCT_DYNAMIC_MEMORY == TRUE)
osi_free(avct_cb_ptr);
avct_cb_ptr = NULL;
@ -366,4 +392,8 @@ void BTE_DeinitStack(void)
#if (defined(A2D_INCLUDED) && A2D_INCLUDED == TRUE)
A2D_Deinit();
#endif
#if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == TRUE)
RFCOMM_Deinit();
#endif
}

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

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

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

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

@ -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
/*******************************************************************************
**
@ -57,6 +62,10 @@ UINT8 GAP_SetTraceLevel (UINT8 new_level)
*******************************************************************************/
void GAP_Init(void)
{
#if GAP_DYNAMIC_MEMORY == TRUE
gap_cb_ptr = (tGAP_CB *)osi_malloc(sizeof(tGAP_CB));
#endif
memset (&gap_cb, 0, sizeof (tGAP_CB));
#if defined(GAP_INITIAL_TRACE_LEVEL)
@ -74,3 +83,20 @@ void GAP_Init(void)
#endif
}
/*******************************************************************************
**
** 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
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,

View File

@ -142,8 +142,13 @@ typedef struct {
#endif
} tGAP_CB;
#if GAP_DYNAMIC_MEMORY == FALSE
extern tGAP_CB gap_cb;
#else
extern tGAP_CB *gap_cb_ptr;
#define gap_cb (*gap_cb_ptr)
#endif
#if (GAP_CONN_INCLUDED == TRUE)
extern void gap_conn_init(void);
#endif

View File

@ -110,7 +110,7 @@ BOOLEAN GATTS_AddHandleRange(tGATTS_HNDL_RANGE *p_hndl_range)
** Returns TRUE if registered OK, else FALSE
**
*******************************************************************************/
BOOLEAN GATTS_NVRegister (tGATT_APPL_INFO *p_cb_info)
BOOLEAN GATTS_NVRegister (const tGATT_APPL_INFO *p_cb_info)
{
BOOLEAN status = FALSE;
if (p_cb_info) {
@ -1192,7 +1192,7 @@ void GATT_SetIdleTimeout (BD_ADDR bd_addr, UINT16 idle_tout, tBT_TRANSPORT trans
** Returns 0 for error, otherwise the index of the client registered with GATT
**
*******************************************************************************/
tGATT_IF GATT_Register (tBT_UUID *p_app_uuid128, tGATT_CBACK *p_cb_info)
tGATT_IF GATT_Register (tBT_UUID *p_app_uuid128, const tGATT_CBACK *p_cb_info)
{
tGATT_REG *p_reg;
UINT8 i_gatt_if = 0;

View File

@ -52,7 +52,7 @@ static void gatt_cl_op_cmpl_cback(UINT16 conn_id, tGATTC_OPTYPE op, tGATT_STATUS
static void gatt_cl_start_config_ccc(tGATT_PROFILE_CLCB *p_clcb);
static tGATT_CBACK gatt_profile_cback = {
static const tGATT_CBACK gatt_profile_cback = {
gatt_connect_cback,
gatt_cl_op_cmpl_cback,
gatt_disc_res_cback,
@ -308,7 +308,7 @@ static void gatt_connect_cback (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id,
p_clcb->connected = TRUE;
p_clcb->conn_id = conn_id;
}
if (!p_clcb->connected) {
/* wait for connection */
@ -348,7 +348,7 @@ void gatt_profile_db_init (void)
service_handle = GATTS_CreateService (gatt_cb.gatt_if , &uuid, 0, GATTP_MAX_ATTR_NUM, TRUE);
GATT_TRACE_DEBUG ("GATTS_CreateService: handle of service handle%x", service_handle);
/* add Service Changed characteristic
*/
uuid.uu.uuid16 = gatt_cb.gattp_attr.uuid = GATT_UUID_GATT_SRV_CHGD;

View File

@ -47,7 +47,7 @@
*********************************************************************************/
void gatt_send_prepare_write(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb);
UINT8 disc_type_to_att_opcode[GATT_DISC_MAX] = {
static const UINT8 disc_type_to_att_opcode[GATT_DISC_MAX] = {
0,
GATT_REQ_READ_BY_GRP_TYPE, /* GATT_DISC_SRVC_ALL = 1, */
GATT_REQ_FIND_TYPE_VALUE, /* GATT_DISC_SRVC_BY_UUID, */
@ -56,7 +56,7 @@ UINT8 disc_type_to_att_opcode[GATT_DISC_MAX] = {
GATT_REQ_FIND_INFO /* GATT_DISC_CHAR_DSCPT, */
};
UINT16 disc_type_to_uuid[GATT_DISC_MAX] = {
static const UINT16 disc_type_to_uuid[GATT_DISC_MAX] = {
0, /* reserved */
GATT_UUID_PRI_SERVICE, /* <service> DISC_SRVC_ALL */
GATT_UUID_PRI_SERVICE, /* <service> for DISC_SERVC_BY_UUID */

View File

@ -18,15 +18,19 @@
#ifndef DYN_MEM_H
#define DYN_MEM_H
#include "common/bt_target.h"
#if BT_BLE_DYNAMIC_ENV_MEMORY
#include "common/bt_user_config.h"
#if UC_BT_BLE_DYNAMIC_ENV_MEMORY
#define BT_BLE_DYNAMIC_ENV_MEMORY TRUE
#define BTU_DYNAMIC_MEMORY TRUE
#define BTM_DYNAMIC_MEMORY TRUE
#define L2C_DYNAMIC_MEMORY TRUE
#define GATT_DYNAMIC_MEMORY TRUE
#define SMP_DYNAMIC_MEMORY TRUE
#define BTA_DYNAMIC_MEMORY TRUE
#define BTC_DYNAMIC_MENDRY TRUE
#define SDP_DYNAMIC_MEMORY TRUE
#define GAP_DYNAMIC_MEMORY TRUE
#define RFC_DYNAMIC_MEMORY TRUE
#define TCS_DYNAMIC_MEMORY TRUE
#define BNEP_DYNAMIC_MEMORY TRUE
@ -51,11 +55,18 @@
#define SLIP_DYNAMIC_MEMORY TRUE
#define LLCP_DYNAMIC_MEMORY TRUE
#define BTC_SBC_DEC_DYNAMIC_MEMORY TRUE
#define BTC_SBC_ENC_DYNAMIC_MEMORY TRUE
#else /* #if BT_BLE_DYNAMIC_ENV_MEMORY */
#else /* #if UC_BT_BLE_DYNAMIC_ENV_MEMORY */
#define BT_BLE_DYNAMIC_ENV_MEMORY FALSE
#define BTU_DYNAMIC_MEMORY FALSE
#define BTM_DYNAMIC_MEMORY FALSE
#define L2C_DYNAMIC_MEMORY FALSE
#define GATT_DYNAMIC_MEMORY FALSE
#define SMP_DYNAMIC_MEMORY FALSE
#define BTA_DYNAMIC_MEMORY FALSE
#define BTC_DYNAMIC_MENDRY FALSE
#define SDP_DYNAMIC_MEMORY FALSE
#define GAP_DYNAMIC_MEMORY FALSE
#define RFC_DYNAMIC_MEMORY FALSE
#define TCS_DYNAMIC_MEMORY FALSE
#define BNEP_DYNAMIC_MEMORY FALSE
@ -80,9 +91,13 @@
#define SLIP_DYNAMIC_MEMORY FALSE
#define LLCP_DYNAMIC_MEMORY FALSE
#define BTC_SBC_DEC_DYNAMIC_MEMORY FALSE
#define BTC_SBC_ENC_DYNAMIC_MEMORY FALSE
#endif /* #if BT_BLE_DYNAMIC_ENV_MEMORY */
#endif /* #if UC_BT_BLE_DYNAMIC_ENV_MEMORY */
#ifndef BT_BLE_DYNAMIC_ENV_MEMORY
#define BT_BLE_DYNAMIC_ENV_MEMORY FALSE
#endif
/****************************************************************************
** Define memory usage for each CORE component (if not defined in bdroid_buildcfg.h)
** The default for each component is to use static memory allocations.
@ -99,6 +114,10 @@
#define SDP_DYNAMIC_MEMORY FALSE
#endif
#ifndef GAP_DYNAMIC_MEMORY
#define GAP_DYNAMIC_MEMORY FALSE
#endif
#ifndef L2C_DYNAMIC_MEMORY
#define L2C_DYNAMIC_MEMORY FALSE
#endif
@ -208,12 +227,15 @@
#endif
/****************************************************************************
** Define memory usage for BTA (if not defined in bdroid_buildcfg.h)
** Define memory usage for BTA and BTC (if not defined in bdroid_buildcfg.h)
** The default for each component is to use static memory allocations.
*/
#ifndef BTA_DYNAMIC_MEMORY
#define BTA_DYNAMIC_MEMORY FALSE
#endif
#endif /* #ifdef DYN_MEM_H */
#ifndef BTC_DYNAMIC_MENDRY
#define BTC_DYNAMIC_MENDRY FALSE
#endif
#endif /* #ifdef DYN_MEM_H */

View File

@ -325,6 +325,18 @@ extern UINT8 GAP_SetTraceLevel (UINT8 new_level);
*******************************************************************************/
extern void GAP_Init(void);
/*******************************************************************************
**
** Function GAP_Deinit
**
** Description This function is called to deinitialize the control block
** for this layer.
**
** Returns void
**
*******************************************************************************/
extern void GAP_Deinit(void);
#if (BLE_INCLUDED == TRUE)
/*******************************************************************************
**

View File

@ -707,7 +707,7 @@ extern BOOLEAN GATTS_AddHandleRange(tGATTS_HNDL_RANGE *p_hndl_range);
** Returns TRUE if registered OK, else FALSE
**
*******************************************************************************/
extern BOOLEAN GATTS_NVRegister (tGATT_APPL_INFO *p_cb_info);
extern BOOLEAN GATTS_NVRegister (const tGATT_APPL_INFO *p_cb_info);
/*******************************************************************************
@ -1059,7 +1059,7 @@ extern void GATT_SetIdleTimeout (BD_ADDR bd_addr, UINT16 idle_tout,
** Returns 0 for error, otherwise the index of the client registered with GATT
**
*******************************************************************************/
extern tGATT_IF GATT_Register (tBT_UUID *p_app_uuid128, tGATT_CBACK *p_cb_info);
extern tGATT_IF GATT_Register (tBT_UUID *p_app_uuid128, const tGATT_CBACK *p_cb_info);
/*******************************************************************************
**

View File

@ -623,6 +623,17 @@ extern int PORT_Test (UINT16 handle, UINT8 *p_data, UINT16 len);
*******************************************************************************/
extern void RFCOMM_Init (void);
/*******************************************************************************
**
** Function RFCOMM_Deinit
**
** Description This function is called to deinitialize the control block
** for this layer.
**
** Returns void
**
*******************************************************************************/
extern void RFCOMM_Deinit(void);
/*******************************************************************************
**

View File

@ -52,6 +52,7 @@ tL2C_CB l2cb;
tL2C_CB *l2c_cb_ptr;
#endif
#if 0 //Unused
/*******************************************************************************
**
** Function l2c_bcst_msg
@ -104,7 +105,7 @@ void l2c_bcst_msg( BT_HDR *p_buf, UINT16 psm )
bte_main_hci_send(p_buf, BT_EVT_TO_LM_HCI_ACL);
}
}
#endif
/*******************************************************************************
**

View File

@ -826,6 +826,8 @@ int PORT_FlowControl (UINT16 handle, BOOLEAN enable)
}
return (PORT_SUCCESS);
}
#if 0 //Unused
/*******************************************************************************
**
** Function PORT_FlowControl_MaxCredit
@ -839,7 +841,6 @@ int PORT_FlowControl (UINT16 handle, BOOLEAN enable)
** enable - enables data flow
**
*******************************************************************************/
int PORT_FlowControl_MaxCredit (UINT16 handle, BOOLEAN enable)
{
tPORT *p_port;
@ -896,7 +897,7 @@ int PORT_FlowControl_MaxCredit (UINT16 handle, BOOLEAN enable)
}
return (PORT_SUCCESS);
}
#endif
/*******************************************************************************
**
@ -1713,7 +1714,7 @@ int PORT_Test (UINT16 handle, UINT8 *p_data, UINT16 len)
*******************************************************************************/
void RFCOMM_Init (void)
{
#if (RFC_DYNAMIC_MEMORY)
#if RFC_DYNAMIC_MEMORY == TRUE
rfc_cb_ptr = (tRFC_CB *)osi_malloc(sizeof(tRFC_CB));
#endif /* #if (RFC_DYNAMIC_MEMORY) */
memset (&rfc_cb, 0, sizeof (tRFC_CB)); /* Init RFCOMM control block */
@ -1729,6 +1730,24 @@ void RFCOMM_Init (void)
rfcomm_l2cap_if_init ();
}
/*******************************************************************************
**
** Function RFCOMM_Deinit
**
** Description This function is called to deinitialize the control block
** for this layer.
**
** Returns void
**
*******************************************************************************/
void RFCOMM_Deinit(void)
{
#if RFC_DYNAMIC_MEMORY == TRUE
osi_free(rfc_cb_ptr);
rfc_cb_ptr = NULL;
#endif
}
/*******************************************************************************
**
** Function PORT_SetTraceLevel

View File

@ -25,6 +25,7 @@
#pragma once
#include "p_256_multprecision.h"
#include "common/bt_target.h"
typedef unsigned long DWORD;
@ -53,8 +54,16 @@ typedef struct {
} elliptic_curve_t;
#if SMP_DYNAMIC_MEMORY == FALSE
extern elliptic_curve_t curve;
extern elliptic_curve_t curve_p256;
#else
extern elliptic_curve_t *curve_ptr;
extern elliptic_curve_t *curve_p256_ptr;
#define curve (*curve_ptr)
#define curve_p256 (*curve_p256_ptr)
#endif
void ECC_PointMult_Bin_NAF(Point *q, Point *p, DWORD *n, uint32_t keyLength);

View File

@ -479,7 +479,7 @@ extern void smp_proc_pairing_cmpl(tSMP_CB *p_cb);
extern void smp_convert_string_to_tk(BT_OCTET16 tk, UINT32 passkey);
extern void smp_mask_enc_key(UINT8 loc_enc_size, UINT8 *p_data);
extern void smp_rsp_timeout(TIMER_LIST_ENT *p_tle);
extern void smp_xor_128(BT_OCTET16 a, BT_OCTET16 b);
extern void smp_xor_128(BT_OCTET16 a, const BT_OCTET16 b);
extern BOOLEAN smp_encrypt_data (UINT8 *key, UINT8 key_len,
UINT8 *plain_text, UINT8 pt_len,
tSMP_ENC *p_out);

View File

@ -26,9 +26,15 @@
#include <string.h>
#include "p_256_ecc_pp.h"
#include "p_256_multprecision.h"
#include "common/bt_target.h"
#if SMP_DYNAMIC_MEMORY == FALSE
elliptic_curve_t curve;
elliptic_curve_t curve_p256;
#else
elliptic_curve_t *curve_ptr;
elliptic_curve_t *curve_p256_ptr;
#endif
static void p_256_init_point(Point *q)
{
@ -248,7 +254,7 @@ bool ECC_CheckPointIsInElliCur_P256(Point *p)
DWORD x_x_q[KEY_LENGTH_DWORDS_P256] = {0x0};
/* x % q */
DWORD x_q[KEY_LENGTH_DWORDS_P256] = {0x0};
/* x^2, To prevent overflow, the length of the x square here needs to
/* x^2, To prevent overflow, the length of the x square here needs to
be expanded to two times the original one. */
DWORD x_x[2*KEY_LENGTH_DWORDS_P256] = {0x0};
/* y_y_q =(p->y)^2(mod q) */
@ -259,7 +265,7 @@ bool ECC_CheckPointIsInElliCur_P256(Point *p)
y^2 = (x^2 - 3)*x + b (mod q),
so we calculate the x^2 - 3 value here */
x_x[0] -= 3;
/* Using math relations. (a*b) % q = ((a%q)*(b%q)) % q ==>
/* Using math relations. (a*b) % q = ((a%q)*(b%q)) % q ==>
(x^2 - 3)*x = (((x^2 - 3) % q) * x % q) % q */
multiprecision_fast_mod_P256(x_x_q, x_x);
/* x_x = x_x_q * x_q */

View File

@ -283,6 +283,7 @@ void smp_send_confirm(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
smp_send_cmd(SMP_OPCODE_CONFIRM, p_cb);
}
#if 0 //Unused
/*******************************************************************************
** Function smp_send_init
** Description process pairing initializer to slave device
@ -292,6 +293,7 @@ void smp_send_init(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
SMP_TRACE_DEBUG("%s\n", __func__);
smp_send_cmd(SMP_OPCODE_INIT, p_cb);
}
#endif
/*******************************************************************************
** Function smp_send_rand
@ -675,6 +677,7 @@ void smp_proc_confirm(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
p_cb->flags |= SMP_PAIR_FLAGS_CMD_CONFIRM;
}
#if 0 //Unused
/*******************************************************************************
** Function smp_proc_init
** Description process pairing initializer from peer device
@ -694,6 +697,7 @@ void smp_proc_init(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
/* save the SRand for comparison */
STREAM_TO_ARRAY(p_cb->rrand, p, BT_OCTET16_LEN);
}
#endif
/*******************************************************************************
** Function smp_proc_rand

View File

@ -51,8 +51,12 @@ void SMP_Init(void)
{
#if SMP_DYNAMIC_MEMORY
smp_cb_ptr = (tSMP_CB *)osi_malloc(sizeof(tSMP_CB));
curve_ptr = (elliptic_curve_t *)osi_malloc(sizeof(elliptic_curve_t));
curve_p256_ptr = (elliptic_curve_t *)osi_malloc(sizeof(elliptic_curve_t));
#endif
memset(&smp_cb, 0, sizeof(tSMP_CB));
memset(&curve, 0, sizeof(elliptic_curve_t));
memset(&curve_p256, 0, sizeof(elliptic_curve_t));
#if defined(SMP_INITIAL_TRACE_LEVEL)
smp_cb.trace_level = SMP_INITIAL_TRACE_LEVEL;
@ -71,6 +75,8 @@ void SMP_Free(void)
memset(&smp_cb, 0, sizeof(tSMP_CB));
#if SMP_DYNAMIC_MEMORY
FREE_AND_RESET(smp_cb_ptr);
FREE_AND_RESET(curve_ptr);
FREE_AND_RESET(curve_p256_ptr);
#endif /* #if SMP_DYNAMIC_MEMORY */
}

View File

@ -42,7 +42,7 @@ typedef struct {
tCMAC_CB cmac_cb;
/* Rb for AES-128 as block cipher, LSB as [0] */
BT_OCTET16 const_Rb = {
const BT_OCTET16 const_Rb = {
0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

View File

@ -93,6 +93,7 @@ void smp_debug_print_nbyte_little_endian(UINT8 *p, const UINT8 *key_name, UINT8
#endif
}
#if 0 //Unused
void smp_debug_print_nbyte_big_endian (UINT8 *p, const UINT8 *key_name, UINT8 len)
{
#if SMP_DEBUG == TRUE
@ -115,6 +116,7 @@ void smp_debug_print_nbyte_big_endian (UINT8 *p, const UINT8 *key_name, UINT8 le
}
#endif
}
#endif
/*******************************************************************************
**

View File

@ -866,9 +866,10 @@ void smp_mask_enc_key(UINT8 loc_enc_size, UINT8 *p_data)
** Returns void
**
*******************************************************************************/
void smp_xor_128(BT_OCTET16 a, BT_OCTET16 b)
void smp_xor_128(BT_OCTET16 a, const BT_OCTET16 b)
{
UINT8 i, *aa = a, *bb = b;
UINT8 i, *aa = a;
const UINT8 *bb = b;
SMP_TRACE_EVENT("smp_xor_128\n");
for (i = 0; i < BT_OCTET16_LEN; i++) {