Skip to content

Commit

Permalink
Merge branch 'backport_v5.0' into 'release/v5.0'
Browse files Browse the repository at this point in the history
Fix some BLE bugs in bluedroid host(backport 5.0)

See merge request espressif/esp-idf!26168
  • Loading branch information
Isl2017 committed Oct 17, 2023
2 parents 447e970 + baf04c4 commit 467cae8
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 38 deletions.
11 changes: 5 additions & 6 deletions components/bt/controller/esp32c3/Kconfig.in
Expand Up @@ -279,20 +279,19 @@ choice BT_CTRL_SCAN_DUPL_TYPE
config BT_CTRL_SCAN_DUPL_TYPE_DEVICE
bool "Scan Duplicate By Device Address"
help
This way is to use advertiser address filtering. The adv packet of the same address is only
allowed to be reported once
Advertising packets with the same address, address type, and advertising type are reported once.

config BT_CTRL_SCAN_DUPL_TYPE_DATA
bool "Scan Duplicate By Advertising Data"
help
This way is to use advertising data filtering. All same advertising data only allow to be reported
once even though they are from different devices.
Advertising packets with identical advertising data, address type, and advertising type
are reported only once, even if they originate from different devices.

config BT_CTRL_SCAN_DUPL_TYPE_DATA_DEVICE
bool "Scan Duplicate By Device Address And Advertising Data"
help
This way is to use advertising data and device address filtering. All different adv packets with
the same address are allowed to be reported.
Advertising packets with the same address, advertising data, address type,
and advertising type are reported only once.
endchoice

config BT_CTRL_SCAN_DUPL_TYPE
Expand Down
3 changes: 1 addition & 2 deletions components/bt/host/bluedroid/api/esp_gap_ble_api.c
Expand Up @@ -470,8 +470,7 @@ esp_err_t esp_ble_gap_config_scan_rsp_data_raw(uint8_t *raw_data, uint32_t raw_d

ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);

if (raw_data == NULL
|| (raw_data_len <= 0 || raw_data_len > ESP_BLE_SCAN_RSP_DATA_LEN_MAX)) {
if ((raw_data_len != 0 && raw_data == NULL) || raw_data_len > ESP_BLE_ADV_DATA_LEN_MAX) {
return ESP_ERR_INVALID_ARG;
}

Expand Down
21 changes: 18 additions & 3 deletions components/bt/host/bluedroid/bta/gatt/bta_gatts_act.c
Expand Up @@ -495,11 +495,11 @@ void bta_gatts_add_char_descr(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_

/*******************************************************************************
**
** Function bta_gatts_add_char_descr
** Function bta_gatts_set_attr_value
**
** Description action function to add characteristic descriptor.
** Description This function is used to set the attribute value.
**
** Returns none.
** Returns None.
**
*******************************************************************************/
void bta_gatts_set_attr_value(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg)
Expand All @@ -526,8 +526,23 @@ void bta_gatts_set_attr_value(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_
}
}

/*******************************************************************************
**
** Function bta_gatts_get_attr_value
**
** Description This function retrieves the attribute value associated with
** the given attribute handle.
**
** Returns tGATT_STATUS - GATT status indicating success or failure in
** retrieving the attribute value.
**
*******************************************************************************/

tGATT_STATUS bta_gatts_get_attr_value(UINT16 attr_handle, UINT16 *length, UINT8 **value)
{
if (GATTS_GetAttributeValueInternal(attr_handle, length, value) == 0) {
return 0;
}

return GATTS_GetAttributeValue(attr_handle, length, value);
}
Expand Down
4 changes: 2 additions & 2 deletions components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c
Expand Up @@ -717,14 +717,14 @@ tBTM_STATUS BTM_BlePeriodicAdvCfgDataRaw(UINT8 instance, UINT16 len, UINT8 *data
do {
UINT8 send_data_len = (rem_len > BTM_BLE_PERIODIC_ADV_DATA_LEN_MAX) ? BTM_BLE_PERIODIC_ADV_DATA_LEN_MAX : rem_len;

if (len <= BTM_BLE_EXT_ADV_DATA_LEN_MAX) {
if (len <= BTM_BLE_PERIODIC_ADV_DATA_LEN_MAX) {
if (!only_update_did) {
operation = BTM_BLE_ADV_DATA_OP_COMPLETE;
}
} else {
if (rem_len == len) {
operation = BTM_BLE_ADV_DATA_OP_FIRST_FRAG;
} else if (rem_len <= BTM_BLE_EXT_ADV_DATA_LEN_MAX) {
} else if (rem_len <= BTM_BLE_PERIODIC_ADV_DATA_LEN_MAX) {
operation = BTM_BLE_ADV_DATA_OP_LAST_FRAG;
} else {
operation = BTM_BLE_ADV_DATA_OP_INTERMEDIATE_FRAG;
Expand Down
8 changes: 8 additions & 0 deletions components/bt/host/bluedroid/stack/btm/btm_ble_privacy.c
Expand Up @@ -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;
Expand Down
22 changes: 21 additions & 1 deletion components/bt/host/bluedroid/stack/gatt/gatt_api.c
Expand Up @@ -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
Expand All @@ -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


Expand Down
29 changes: 13 additions & 16 deletions components/bt/host/bluedroid/stack/gatt/gatt_attr.c
Expand Up @@ -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

Expand Down Expand Up @@ -205,43 +205,40 @@ 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) {
return GATT_INSUF_RESOURCE;
}
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 */
if (p_data->handle == gatt_cb.handle_of_database_hash) {
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;
}

Expand Down
17 changes: 12 additions & 5 deletions components/bt/host/bluedroid/stack/gatt/gatt_db.c
Expand Up @@ -780,14 +780,25 @@ 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;
tGATT_STATUS status = GATT_NOT_FOUND;
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) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion components/bt/host/bluedroid/stack/gatt/include/gatt_int.h
Expand Up @@ -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);
Expand Down
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion components/esp_hid/src/ble_hidd.c
Expand Up @@ -977,7 +977,7 @@ esp_err_t esp_ble_hidd_dev_init(esp_hidd_dev_t *dev_p, const esp_hid_device_conf
.queue_size = 5,
.task_name = "ble_hidd_events",
.task_priority = uxTaskPriorityGet(NULL),
.task_stack_size = 2048,
.task_stack_size = 4096,
.task_core_id = tskNO_AFFINITY
};
ret = esp_event_loop_create(&event_task_args, &s_dev->event_loop_handle);
Expand Down

0 comments on commit 467cae8

Please sign in to comment.