Merge branch 'bugfix/fix_ble_bugs' into 'master'

Fix some BLE bugs in bluedroid host

See merge request espressif/esp-idf!26448
This commit is contained in:
Zhang Hai Peng
2023-10-16 19:27:29 +08:00
10 changed files with 81 additions and 36 deletions
@@ -473,10 +473,18 @@ tBTM_STATUS btm_ble_remove_resolving_list_entry(tBTM_SEC_DEV_REC *p_dev_rec)
tBTM_STATUS st = BTM_NO_RESOURCES;
if (controller_get_interface()->supports_ble_privacy()) {
#if CONTROLLER_RPA_LIST_ENABLE
if (btsnd_hcic_ble_rm_device_resolving_list(p_dev_rec->ble.static_addr_type,
p_dev_rec->ble.static_addr)) {
st = BTM_CMD_STARTED;
}
#else
// do nothing
/* It will cause that scanner doesn't send scan request to advertiser
* which has sent IRK to us and we have stored the IRK in controller.
* It is a hardware limitation. The preliminary solution is not to
* send key to the controller, but to resolve the random address in host. */
#endif
} else {
UINT8 param[20] = {0};
UINT8 *p = param;
@@ -781,7 +781,7 @@ tGATT_STATUS GATTS_SetAttributeValue(UINT16 attr_handle, UINT16 length, UINT8 *v
**
** Function GATTS_GetAttributeValue
**
** Description This function sends to set the attribute value .
** Description This function sends to get the attribute value .
**
** Parameter attr_handle: the attribute handle
** length:the attribute value length in the database
@@ -807,6 +807,26 @@ tGATT_STATUS GATTS_GetAttributeValue(UINT16 attr_handle, UINT16 *length, UINT8 *
status = gatts_get_attribute_value(&p_decl->svc_db, attr_handle, length, value);
return status;
}
/*******************************************************************************
**
** Function GATTS_GetAttributeValueInternal
**
** Description This function sends to get the attribute value of internal gatt and gap service.
**
** Parameter attr_handle: the attribute handle
** length:the attribute value length in the database
** value: the attribute value out put
*
**
** Returns tGATT_STATUS - GATT status indicating success or failure in
** retrieving the attribute value.
**
*******************************************************************************/
tGATT_STATUS GATTS_GetAttributeValueInternal(UINT16 attr_handle, UINT16 *length, UINT8 **value)
{
return gatts_get_attr_value_internal(attr_handle, length, value);
}
#endif ///GATTS_INCLUDED == TRUE
@@ -40,7 +40,7 @@
#define BLE_GATT_CL_SUPP_FEAT_BITMASK 0x07
#define GATTP_MAX_NUM_INC_SVR 0
#define GATTP_MAX_CHAR_NUM 4
#define GATTP_MAX_CHAR_NUM 5
#define GATTP_MAX_ATTR_NUM (GATTP_MAX_CHAR_NUM * 2 + GATTP_MAX_NUM_INC_SVR + 1)
#define GATTP_MAX_CHAR_VALUE_SIZE 50
@@ -205,18 +205,6 @@ tGATT_STATUS gatt_proc_read (UINT16 conn_id, tGATTS_REQ_TYPE type, tGATT_READ_RE
p_rsp->attr_value.handle = p_data->handle;
/* handle request for reading service changed */
if (p_data->handle == gatt_cb.handle_of_h_r) {
status = GATTS_GetAttributeValue(p_data->handle, &len, &value);
if(status == GATT_SUCCESS && len > 0 && value) {
if(len > GATT_MAX_ATTR_LEN) {
len = GATT_MAX_ATTR_LEN;
}
p_rsp->attr_value.len = len;
memcpy(p_rsp->attr_value.value, value, len);
}
}
/* handle request for reading client supported features */
if (p_data->handle == gatt_cb.handle_of_cl_supported_feat) {
if (tcb == NULL) {
@@ -224,7 +212,7 @@ tGATT_STATUS gatt_proc_read (UINT16 conn_id, tGATTS_REQ_TYPE type, tGATT_READ_RE
}
p_rsp->attr_value.len = 1;
memcpy(p_rsp->attr_value.value, &tcb->cl_supp_feat, 1);
status = GATT_SUCCESS;
return GATT_SUCCESS;
}
/* handle request for reading database hash */
@@ -232,16 +220,25 @@ tGATT_STATUS gatt_proc_read (UINT16 conn_id, tGATTS_REQ_TYPE type, tGATT_READ_RE
p_rsp->attr_value.len = BT_OCTET16_LEN;
memcpy(p_rsp->attr_value.value, gatt_cb.database_hash, BT_OCTET16_LEN);
gatt_sr_update_cl_status(tcb, true);
status = GATT_SUCCESS;
return GATT_SUCCESS;
}
/* handle request for reading server supported features */
if (p_data->handle == gatt_cb.handle_of_sr_supported_feat) {
p_rsp->attr_value.len = 1;
memcpy(p_rsp->attr_value.value, &gatt_cb.gatt_sr_supported_feat_mask, 1);
status = GATT_SUCCESS;
return GATT_SUCCESS;
}
/* handle request for reading service changed des and the others */
status = GATTS_GetAttributeValue(p_data->handle, &len, &value);
if(status == GATT_SUCCESS && len > 0 && value) {
if(len > GATT_MAX_ATTR_LEN) {
len = GATT_MAX_ATTR_LEN;
}
p_rsp->attr_value.len = len;
memcpy(p_rsp->attr_value.value, value, len);
}
return status;
}
@@ -780,7 +780,7 @@ tGATT_STATUS gatts_set_attribute_value(tGATT_SVC_DB *p_db, UINT16 attr_handle,
** Returns Status of the operation.
**
*******************************************************************************/
static tGATT_STATUS gatts_get_attr_value_internal(UINT16 attr_handle, UINT16 *length, UINT8 **value)
tGATT_STATUS gatts_get_attr_value_internal(UINT16 attr_handle, UINT16 *length, UINT8 **value)
{
UINT8 i;
tGATT_READ_REQ read_req;
@@ -788,6 +788,17 @@ static tGATT_STATUS gatts_get_attr_value_internal(UINT16 attr_handle, UINT16 *le
tGATT_SR_REG *p_rcb = gatt_cb.sr_reg;
UINT8 service_uuid[LEN_UUID_128] = {0};
if (length == NULL){
GATT_TRACE_ERROR("gatts_get_attr_value_internal Fail:length is NULL.\n");
return GATT_INVALID_PDU;
}
if (value == NULL){
GATT_TRACE_ERROR("gatts_get_attr_value_internal Fail:value is NULL.\n");
*length = 0;
return GATT_INVALID_PDU;
}
// find the service by handle
for (i = 0; i < GATT_MAX_SR_PROFILES; i++, p_rcb++) {
if (p_rcb->in_use && p_rcb->s_hdl <= attr_handle && p_rcb->e_hdl >= attr_handle) {
@@ -868,10 +879,6 @@ tGATT_STATUS gatts_get_attribute_value(tGATT_SVC_DB *p_db, UINT16 attr_handle,
return GATT_INVALID_PDU;
}
if (gatts_get_attr_value_internal(attr_handle, length, value) == GATT_SUCCESS) {
return GATT_SUCCESS;
}
p_cur = (tGATT_ATTR16 *) p_db->p_attr_list;
while (p_cur != NULL) {
@@ -754,7 +754,7 @@ extern UINT16 gatts_add_char_descr (tGATT_SVC_DB *p_db, tGATT_PERM perm,
extern tGATT_STATUS gatts_set_attribute_value(tGATT_SVC_DB *p_db, UINT16 attr_handle,
UINT16 length, UINT8 *value);
extern tGATT_STATUS gatts_get_attr_value_internal(UINT16 attr_handle, UINT16 *length, UINT8 **value);
extern tGATT_STATUS gatts_get_attribute_value(tGATT_SVC_DB *p_db, UINT16 attr_handle,
UINT16 *length, UINT8 **value);
extern BOOLEAN gatts_is_auto_response(UINT16 attr_handle);
@@ -943,7 +943,7 @@ tGATT_STATUS GATTS_SetAttributeValue(UINT16 attr_handle, UINT16 length, UINT8 *v
*******************************************************************************/
tGATT_STATUS GATTS_GetAttributeValue(UINT16 attr_handle, UINT16 *length, UINT8 **value);
tGATT_STATUS GATTS_GetAttributeValueInternal(UINT16 attr_handle, UINT16 *length, UINT8 **value);
/*******************************************************************************/
/* GATT Profile Client Functions */