mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
bluedroid: fixed GATT multi notify and robust caching
This commit is contained in:
parent
285e86ad04
commit
3100841f64
@ -162,6 +162,7 @@ BOOLEAN bta_gatts_co_load_handle_range(UINT8 index,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#if (SMP_INCLUDED == TRUE)
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function bta_gatts_co_cl_feat_save
|
||||
@ -245,5 +246,6 @@ void bta_gatts_co_db_hash_load(BD_ADDR remote_addr, BT_OCTET16 db_hash)
|
||||
memcpy(bd_addr.address, remote_addr, BD_ADDR_LEN);
|
||||
btc_storage_get_gatt_db_hash(&bd_addr, db_hash, BT_OCTET16_LEN);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif // #if (SMP_INCLUDED == TRUE)
|
||||
#endif // #if (GATTS_INCLUDED == TRUE)
|
||||
#endif // #if (BLE_INCLUDED == TRUE)
|
||||
|
@ -924,10 +924,7 @@ int btc_storage_get_num_ble_bond_devices(void)
|
||||
|
||||
return num_dev;
|
||||
}
|
||||
#endif ///BLE_INCLUDED == TRUE
|
||||
#endif ///SMP_INCLUDED == TRUE
|
||||
|
||||
#if (BLE_INCLUDED == TRUE && GATTS_INCLUDED == TRUE)
|
||||
bt_status_t btc_storage_get_gatt_cl_supp_feat(bt_bdaddr_t *remote_bd_addr, uint8_t *value, int len)
|
||||
{
|
||||
bdstr_t bdstr;
|
||||
@ -1001,4 +998,5 @@ bt_status_t btc_storage_remove_gatt_db_hash(bt_bdaddr_t *remote_bd_addr)
|
||||
|
||||
return BT_STATUS_SUCCESS;
|
||||
}
|
||||
#endif /* BLE_INCLUDED == TRUE && GATTS_INCLUDED == TRUE */
|
||||
#endif ///BLE_INCLUDED == TRUE
|
||||
#endif ///SMP_INCLUDED == TRUE
|
||||
|
@ -2316,7 +2316,11 @@ The maximum number of payload octets that the local device can receive in a sing
|
||||
#endif
|
||||
|
||||
// TODO: add menuconfig and api for periodic adv sync transfer
|
||||
#if (BLE_50_FEATURE_SUPPORT)
|
||||
#define BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER TRUE
|
||||
#else
|
||||
#define BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER FALSE
|
||||
#endif
|
||||
|
||||
#include "common/bt_trace.h"
|
||||
|
||||
|
@ -181,8 +181,10 @@ UINT16 GATTS_CreateService (tGATT_IF gatt_if, tBT_UUID *p_svc_uuid,
|
||||
} else {
|
||||
if ( (p_svc_uuid->len == LEN_UUID_16) && (p_svc_uuid->uu.uuid16 == UUID_SERVCLASS_GATT_SERVER)) {
|
||||
s_hdl = gatt_cb.hdl_cfg.gatt_start_hdl;
|
||||
save_hdl = TRUE;
|
||||
} else if ((p_svc_uuid->len == LEN_UUID_16) && (p_svc_uuid->uu.uuid16 == UUID_SERVCLASS_GAP_SERVER)) {
|
||||
s_hdl = gatt_cb.hdl_cfg.gap_start_hdl;
|
||||
save_hdl = TRUE;
|
||||
} else {
|
||||
p_list = p_list_info->p_first;
|
||||
|
||||
|
@ -219,6 +219,9 @@ tGATT_STATUS gatt_proc_read (UINT16 conn_id, tGATTS_REQ_TYPE type, tGATT_READ_RE
|
||||
|
||||
/* handle request for reading client supported features */
|
||||
if (p_data->handle == gatt_cb.handle_of_cl_supported_feat) {
|
||||
if (tcb == NULL) {
|
||||
return GATT_INSUF_RESOURCE;
|
||||
}
|
||||
p_rsp->attr_value.len = 1;
|
||||
memcpy(p_rsp->attr_value.value, &tcb->cl_supp_feat, 1);
|
||||
status = GATT_SUCCESS;
|
||||
@ -281,7 +284,9 @@ static tGATT_STATUS gatt_sr_write_cl_supp_feat(UINT16 conn_id, tGATT_WRITE_REQ *
|
||||
}
|
||||
|
||||
p_tcb->cl_supp_feat = val_new;
|
||||
#if (SMP_INCLUDED == TRUE)
|
||||
bta_gatts_co_cl_feat_save(p_tcb->peer_bda, &p_tcb->cl_supp_feat);
|
||||
#endif
|
||||
return GATT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -736,7 +741,9 @@ BOOLEAN gatt_sr_is_cl_change_aware(tGATT_TCB *p_tcb)
|
||||
*******************************************************************************/
|
||||
void gatt_sr_init_cl_status(tGATT_TCB *p_tcb)
|
||||
{
|
||||
#if (SMP_INCLUDED == TRUE)
|
||||
bta_gatts_co_cl_feat_load(p_tcb->peer_bda, &p_tcb->cl_supp_feat);
|
||||
#endif
|
||||
|
||||
// This is used to reset bit when robust caching is disabled
|
||||
if (!GATTS_ROBUST_CACHING_ENABLED) {
|
||||
@ -745,7 +752,9 @@ void gatt_sr_init_cl_status(tGATT_TCB *p_tcb)
|
||||
|
||||
if (gatt_sr_is_cl_robust_caching_supported(p_tcb)) {
|
||||
BT_OCTET16 stored_hash = {0};
|
||||
#if (SMP_INCLUDED == TRUE)
|
||||
bta_gatts_co_db_hash_load(p_tcb->peer_bda, stored_hash);
|
||||
#endif
|
||||
p_tcb->is_robust_cache_change_aware = (memcmp(stored_hash, gatt_cb.database_hash, BT_OCTET16_LEN) == 0);
|
||||
} else {
|
||||
p_tcb->is_robust_cache_change_aware = true;
|
||||
@ -776,7 +785,9 @@ void gatt_sr_update_cl_status(tGATT_TCB *p_tcb, BOOLEAN chg_aware)
|
||||
|
||||
// only when client status is changed from unaware to aware, we should store database hash
|
||||
if (!p_tcb->is_robust_cache_change_aware && chg_aware) {
|
||||
#if (SMP_INCLUDED == TRUE)
|
||||
bta_gatts_co_db_hash_save(p_tcb->peer_bda, gatt_cb.database_hash);
|
||||
#endif
|
||||
}
|
||||
|
||||
p_tcb->is_robust_cache_change_aware = chg_aware;
|
||||
|
@ -69,39 +69,6 @@ static const UINT16 disc_type_to_uuid[GATT_DISC_MAX] = {
|
||||
// Use for GATTC discover infomation print
|
||||
#define GATT_DISC_INFO(fmt, args...) {if (gatt_cb.auto_disc == FALSE) BT_PRINT_I("BT_GATT", fmt, ## args);}
|
||||
|
||||
char *gatt_uuid_to_str(const tBT_UUID *uuid)
|
||||
{
|
||||
static char dst[48] = {0};
|
||||
const uint8_t *u8p;
|
||||
|
||||
memset(dst, 0, sizeof(dst));
|
||||
|
||||
switch (uuid->len) {
|
||||
case LEN_UUID_16:
|
||||
sprintf(dst, "0x%04x", uuid->uu.uuid16);
|
||||
break;
|
||||
case LEN_UUID_32:
|
||||
sprintf(dst, "0x%08x", uuid->uu.uuid32);
|
||||
break;
|
||||
case LEN_UUID_128:
|
||||
u8p = uuid->uu.uuid128;
|
||||
|
||||
sprintf(dst, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
|
||||
"%02x%02x%02x%02x%02x%02x",
|
||||
u8p[15], u8p[14], u8p[13], u8p[12],
|
||||
u8p[11], u8p[10], u8p[9], u8p[8],
|
||||
u8p[7], u8p[6], u8p[5], u8p[4],
|
||||
u8p[3], u8p[2], u8p[1], u8p[0]);
|
||||
break;
|
||||
default:
|
||||
dst[0] = '\0';
|
||||
break;
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function gatt_act_discovery
|
||||
@ -1187,7 +1154,8 @@ void gatt_client_handle_server_rsp (tGATT_TCB *p_tcb, UINT8 op_code,
|
||||
tGATT_CLCB *p_clcb = NULL;
|
||||
UINT8 rsp_code;
|
||||
|
||||
if (op_code != GATT_HANDLE_VALUE_IND && op_code != GATT_HANDLE_VALUE_NOTIF) {
|
||||
if (op_code != GATT_HANDLE_VALUE_IND && op_code != GATT_HANDLE_VALUE_NOTIF &&
|
||||
op_code != GATT_HANDLE_MULTI_VALUE_NOTIF) {
|
||||
p_clcb = gatt_cmd_dequeue(p_tcb, &rsp_code);
|
||||
|
||||
rsp_code = gatt_cmd_to_rsp_code(rsp_code);
|
||||
@ -1206,8 +1174,8 @@ void gatt_client_handle_server_rsp (tGATT_TCB *p_tcb, UINT8 op_code,
|
||||
/* The message has to be smaller than the agreed MTU, len does not count op_code */
|
||||
if (len >= p_tcb->payload_size) {
|
||||
GATT_TRACE_ERROR("invalid response/indicate pkt size: %d, PDU size: %d", len + 1, p_tcb->payload_size);
|
||||
if (op_code != GATT_HANDLE_VALUE_NOTIF &&
|
||||
op_code != GATT_HANDLE_VALUE_IND) {
|
||||
if (op_code != GATT_HANDLE_VALUE_NOTIF && op_code != GATT_HANDLE_VALUE_IND &&
|
||||
op_code != GATT_HANDLE_MULTI_VALUE_NOTIF) {
|
||||
gatt_end_operation(p_clcb, GATT_ERROR, NULL);
|
||||
}
|
||||
} else {
|
||||
@ -1264,11 +1232,10 @@ void gatt_client_handle_server_rsp (tGATT_TCB *p_tcb, UINT8 op_code,
|
||||
}
|
||||
}
|
||||
|
||||
if (op_code != GATT_HANDLE_VALUE_IND && op_code != GATT_HANDLE_VALUE_NOTIF) {
|
||||
if (op_code != GATT_HANDLE_VALUE_IND && op_code != GATT_HANDLE_VALUE_NOTIF &&
|
||||
op_code != GATT_HANDLE_MULTI_VALUE_NOTIF) {
|
||||
gatt_cl_send_next_cmd_inq(p_tcb);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* BLE_INCLUDED == TRUE && GATTC_INCLUDED == TRUE */
|
||||
|
@ -160,9 +160,6 @@ tGATT_STATUS gatts_calculate_datebase_hash(BT_OCTET16 hash)
|
||||
BT_OCTET16 key = {0};
|
||||
aes_cipher_msg_auth_code(key, data_buf, len, 16, hash);
|
||||
//ESP_LOG_BUFFER_HEX("db hash", hash, BT_OCTET16_LEN);
|
||||
#else
|
||||
// TODO
|
||||
GATT_TRACE_ERROR("%s SMP disabled", __func__);
|
||||
#endif
|
||||
|
||||
osi_free(data_buf);
|
||||
|
@ -1090,7 +1090,9 @@ tGATT_TCB *gatt_allocate_tcb_by_bdaddr(BD_ADDR bda, tBT_TRANSPORT transport)
|
||||
p_tcb->transport = transport;
|
||||
}
|
||||
memcpy(p_tcb->peer_bda, bda, BD_ADDR_LEN);
|
||||
#if (GATTS_INCLUDED == TRUE)
|
||||
gatt_sr_init_cl_status(p_tcb);
|
||||
#endif ///GATTS_INCLUDED == TRUE
|
||||
}
|
||||
return p_tcb;
|
||||
}
|
||||
@ -2911,4 +2913,36 @@ BOOLEAN gatt_update_listen_mode(void)
|
||||
return rt;
|
||||
|
||||
}
|
||||
|
||||
char *gatt_uuid_to_str(const tBT_UUID *uuid)
|
||||
{
|
||||
static char dst[48] = {0};
|
||||
const UINT8 *u8p;
|
||||
|
||||
memset(dst, 0, sizeof(dst));
|
||||
|
||||
switch (uuid->len) {
|
||||
case LEN_UUID_16:
|
||||
sprintf(dst, "0x%04x", uuid->uu.uuid16);
|
||||
break;
|
||||
case LEN_UUID_32:
|
||||
sprintf(dst, "0x%08x", uuid->uu.uuid32);
|
||||
break;
|
||||
case LEN_UUID_128:
|
||||
u8p = uuid->uu.uuid128;
|
||||
|
||||
sprintf(dst, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
|
||||
"%02x%02x%02x%02x%02x%02x",
|
||||
u8p[15], u8p[14], u8p[13], u8p[12],
|
||||
u8p[11], u8p[10], u8p[9], u8p[8],
|
||||
u8p[7], u8p[6], u8p[5], u8p[4],
|
||||
u8p[3], u8p[2], u8p[1], u8p[0]);
|
||||
break;
|
||||
default:
|
||||
dst[0] = '\0';
|
||||
break;
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
#endif
|
||||
|
@ -625,6 +625,7 @@ extern BOOLEAN gatt_parse_uuid_from_cmd(tBT_UUID *p_uuid, UINT16 len, UINT8 **p_
|
||||
extern UINT8 gatt_build_uuid_to_stream(UINT8 **p_dst, tBT_UUID uuid);
|
||||
extern BOOLEAN gatt_uuid_compare(tBT_UUID src, tBT_UUID tar);
|
||||
extern void gatt_convert_uuid32_to_uuid128(UINT8 uuid_128[LEN_UUID_128], UINT32 uuid_32);
|
||||
extern char *gatt_uuid_to_str(const tBT_UUID *uuid);
|
||||
extern void gatt_sr_get_sec_info(BD_ADDR rem_bda, tBT_TRANSPORT transport, UINT8 *p_sec_flag, UINT8 *p_key_size);
|
||||
extern void gatt_start_rsp_timer(UINT16 clcb_idx);
|
||||
extern void gatt_start_conf_timer(tGATT_TCB *p_tcb);
|
||||
|
Loading…
Reference in New Issue
Block a user