Skip to content

Commit

Permalink
Merge branch 'backport_v4.4' into 'release/v4.4'
Browse files Browse the repository at this point in the history
fix(bt): Fix ble periodic advertising data length 0 error(backport v4.4)

See merge request espressif/esp-idf!25008
  • Loading branch information
jack0c committed Aug 16, 2023
2 parents ba29708 + abd4778 commit 8c1e87e
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 57 deletions.
3 changes: 2 additions & 1 deletion components/bt/host/bluedroid/bta/dm/bta_dm_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2804,7 +2804,7 @@ void BTA_DmBleGapConfigExtAdvDataRaw(BOOLEAN is_scan_rsp, UINT8 instance, UINT16
p_msg->is_scan_rsp = is_scan_rsp;
p_msg->instance = instance;
p_msg->length = length;
p_msg->data = (UINT8 *)(p_msg + 1);
p_msg->data = length != 0 ? (UINT8 *)(p_msg + 1) : NULL;
if (data) {
memcpy(p_msg->data, data, length);
}
Expand Down Expand Up @@ -2894,6 +2894,7 @@ void BTA_DmBleGapPeriodicAdvCfgDataRaw(UINT8 instance, UINT16 length,
p_msg->length = length;
p_msg->data = (UINT8 *)(p_msg + 1);
memcpy(p_msg->data, data, length);
p_msg->data = length != 0 ? (UINT8 *)(p_msg + 1) : NULL;
//start sent the msg to the bta system control moudle
bta_sys_sendmsg(p_msg);
} else {
Expand Down
2 changes: 1 addition & 1 deletion components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ static tBTM_STATUS btm_ble_ext_adv_params_validate(tBTM_BLE_GAP_EXT_ADV_PARAMS *

static tBTM_STATUS btm_ble_ext_adv_set_data_validate(UINT8 instance, UINT16 len, UINT8 *data)
{
if (!data) {
if (data == NULL && len > 0) {
BTM_TRACE_ERROR("%s, the extend adv data is NULL. line %d", __func__, __LINE__);
return BTM_ILLEGAL_VALUE;
}
Expand Down
19 changes: 0 additions & 19 deletions components/bt/host/bluedroid/stack/btm/btm_ble_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,15 +869,6 @@ BOOLEAN BTM_BleConfigPrivacy(BOOLEAN privacy_mode, tBTM_SET_LOCAL_PRIVACY_CBACK
return FALSE;
}

if (p_cb->inq_var.state != BTM_BLE_IDLE) {
BTM_TRACE_ERROR("Advertising or scaning now, can't set privacy ");
if (random_cb && random_cb->set_local_privacy_cback){
(*random_cb->set_local_privacy_cback)(BTM_SET_PRIVACY_FAIL);
random_cb->set_local_privacy_cback = NULL;
}
return FALSE;
}

#if (defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE && GATTS_INCLUDED == TRUE)
uint8_t addr_resolution = 0;
#endif /* defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE && GATTS_INCLUDED == TRUE */
Expand All @@ -886,22 +877,12 @@ BOOLEAN BTM_BleConfigPrivacy(BOOLEAN privacy_mode, tBTM_SET_LOCAL_PRIVACY_CBACK
memset(p_cb->addr_mgnt_cb.resolvale_addr, 0, BD_ADDR_LEN);
p_cb->addr_mgnt_cb.own_addr_type = BLE_ADDR_PUBLIC;
p_cb->privacy_mode = BTM_PRIVACY_NONE;
if (random_cb && random_cb->set_local_privacy_cback){
(*random_cb->set_local_privacy_cback)(BTM_SET_PRIVACY_SUCCESS);
random_cb->set_local_privacy_cback = NULL;
}
// Disable RPA function
btsnd_hcic_ble_set_addr_resolution_enable(FALSE);
} else { /* privacy is turned on*/
#if (CONTROLLER_RPA_LIST_ENABLE == FALSE)
/* always set host random address, used when privacy 1.1 or priavcy 1.2 is disabled */
btm_gen_resolvable_private_addr((void *)btm_gen_resolve_paddr_low);
#else
/* Controller generates RPA, Host don't need to set random address */
if (random_cb && random_cb->set_local_privacy_cback){
(*random_cb->set_local_privacy_cback)(BTM_SET_PRIVACY_SUCCESS);
random_cb->set_local_privacy_cback = NULL;
}
#endif

if (BTM_BleMaxMultiAdvInstanceCount() > 0) {
Expand Down
40 changes: 40 additions & 0 deletions components/bt/host/bluedroid/stack/btm/btm_ble_privacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,46 @@ void btm_ble_read_resolving_list_entry_complete(UINT8 *p, UINT16 evt_len)
btm_ble_refresh_peer_resolvable_private_addr(pseudo_bda, rra, rra_type);
}
}

/*******************************************************************************
**
** Function btm_ble_set_addr_resolution_enable_complete
**
** Description This function is called when the command to set address
** resolution enable completes.
**
** Parameters p: Pointer to the command complete event data.
** evt_len: Length of the event data.
**
** Returns void
**
*******************************************************************************/
void btm_ble_set_addr_resolution_enable_complete(UINT8 *p, UINT16 evt_len)
{
UINT8 status;

STREAM_TO_UINT8(status, p);

BTM_TRACE_DEBUG("%s status = %d", __func__, status);

tBTM_LE_RANDOM_CB *random_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb;

if (!(random_cb && random_cb->set_local_privacy_cback)) {
BTM_TRACE_ERROR("no set local privacy callback found");
return;
}

if (status == HCI_SUCCESS) {
random_cb->set_local_privacy_cback(BTM_SUCCESS);
return;
} else if (status == HCI_ERR_COMMAND_DISALLOWED) {
BTM_TRACE_ERROR("a non-connected activity is ongoing, such as advertising and scanning");
} else {
BTM_TRACE_ERROR("set local privacy failed");
}
random_cb->set_local_privacy_cback(BTM_ILLEGAL_VALUE);
}

/*******************************************************************************
VSC that implement controller based privacy
********************************************************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ BOOLEAN btm_random_pseudo_to_identity_addr(BD_ADDR random_pseudo, UINT8 *p_stati
void btm_ble_refresh_peer_resolvable_private_addr(BD_ADDR pseudo_bda, BD_ADDR rra, UINT8 rra_type);
void btm_ble_refresh_local_resolvable_private_addr(BD_ADDR pseudo_addr, BD_ADDR local_rpa);
void btm_ble_read_resolving_list_entry_complete(UINT8 *p, UINT16 evt_len) ;
void btm_ble_set_addr_resolution_enable_complete(UINT8 *p, UINT16 evt_len) ;
void btm_ble_remove_resolving_list_entry_complete(UINT8 *p, UINT16 evt_len);
void btm_ble_add_resolving_list_entry_complete(UINT8 *p, UINT16 evt_len);
void btm_ble_clear_resolving_list_complete(UINT8 *p, UINT16 evt_len);
Expand Down
3 changes: 3 additions & 0 deletions components/bt/host/bluedroid/stack/btu/btu_hcif.c
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,10 @@ static void btu_hcif_hdl_command_complete (UINT16 opcode, UINT8 *p, UINT16 evt_l
break;

case HCI_BLE_READ_RESOLVABLE_ADDR_LOCAL:
break;
case HCI_BLE_SET_ADDR_RESOLUTION_ENABLE:
btm_ble_set_addr_resolution_enable_complete(p, evt_len);
break;
case HCI_BLE_SET_RAND_PRIV_ADDR_TIMOUT:
break;
#if (BLE_50_FEATURE_SUPPORT == TRUE)
Expand Down
38 changes: 16 additions & 22 deletions components/bt/host/bluedroid/stack/hcic/hciblecmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1273,17 +1273,16 @@ UINT8 btsnd_hcic_ble_set_ext_adv_data(UINT8 adv_handle,
UINT8_TO_STREAM(pp, operation);
UINT8_TO_STREAM(pp, fragment_prefrence);

if (p_data != NULL && data_len > 0) {
if (data_len > HCIC_PARAM_SIZE_EXT_ADV_WRITE_DATA) {
data_len = HCIC_PARAM_SIZE_EXT_ADV_WRITE_DATA;
}
if (data_len > HCIC_PARAM_SIZE_EXT_ADV_WRITE_DATA) {
data_len = HCIC_PARAM_SIZE_EXT_ADV_WRITE_DATA;
}

UINT8_TO_STREAM (pp, data_len);
UINT8_TO_STREAM (pp, data_len);

if (p_data != NULL && data_len > 0){
ARRAY_TO_STREAM (pp, p_data, data_len);
} else {
return FALSE;
}

uint8_t status = btu_hcif_send_cmd_sync (LOCAL_BR_EDR_CONTROLLER_ID, p);
return status;

Expand All @@ -1309,16 +1308,13 @@ UINT8 btsnd_hcic_ble_set_ext_adv_scan_rsp_data(UINT8 adv_handle,

memset(pp, 0, data_len);

if (p_data != NULL && data_len > 0) {
if (data_len > HCIC_PARAM_SIZE_EXT_ADV_WRITE_DATA) {
data_len = HCIC_PARAM_SIZE_EXT_ADV_WRITE_DATA;
}

UINT8_TO_STREAM (pp, data_len);
if (data_len > HCIC_PARAM_SIZE_EXT_ADV_WRITE_DATA) {
data_len = HCIC_PARAM_SIZE_EXT_ADV_WRITE_DATA;
}

UINT8_TO_STREAM (pp, data_len);
if (p_data != NULL && data_len > 0) {
ARRAY_TO_STREAM (pp, p_data, data_len);
} else {
return FALSE;
}

return btu_hcif_send_cmd_sync (LOCAL_BR_EDR_CONTROLLER_ID, p);
Expand Down Expand Up @@ -1455,16 +1451,14 @@ UINT8 btsnd_hcic_ble_set_periodic_adv_data(UINT8 adv_handle,

//memset(pp, 0, len);

if (p_data != NULL && len > 0) {
if (len > HCIC_PARAM_SIZE_WRITE_PERIODIC_ADV_DATA) {
len = HCIC_PARAM_SIZE_WRITE_PERIODIC_ADV_DATA;
}
if (len > HCIC_PARAM_SIZE_WRITE_PERIODIC_ADV_DATA) {
len = HCIC_PARAM_SIZE_WRITE_PERIODIC_ADV_DATA;
}

UINT8_TO_STREAM (pp, len);
UINT8_TO_STREAM (pp, len);

if (p_data != NULL && len > 0) {
ARRAY_TO_STREAM (pp, p_data, len);
} else {
return FALSE;
}

return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
Expand Down
28 changes: 14 additions & 14 deletions components/bt/include/esp32c3/include/esp_bt.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -43,7 +43,7 @@ typedef enum {
} esp_bt_ctrl_hci_tl_t;

/**
* @breif type of BLE connection event length computation
* @brief type of BLE connection event length computation
*/
typedef enum {
ESP_BLE_CE_LEN_TYPE_ORIG = 0, /*!< original */
Expand Down Expand Up @@ -225,16 +225,16 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status);
* This structure shall be registered when HCI transport layer is UART
*/
typedef struct {
uint32_t _magic; /* Magic number */
uint32_t _version; /* version number of the defined structure */
uint32_t _reserved; /* reserved for future use */
int (* _open)(void); /* hci tl open */
void (* _close)(void); /* hci tl close */
void (* _finish_transfers)(void); /* hci tl finish trasnfers */
void (* _recv)(uint8_t *buf, uint32_t len, esp_bt_hci_tl_callback_t callback, void* arg); /* hci tl recv */
void (* _send)(uint8_t *buf, uint32_t len, esp_bt_hci_tl_callback_t callback, void* arg); /* hci tl send */
bool (* _flow_off)(void); /* hci tl flow off */
void (* _flow_on)(void); /* hci tl flow on */
uint32_t _magic; /*!< Magic number */
uint32_t _version; /*!< Version number of the defined structure */
uint32_t _reserved; /*!< Reserved for future use */
int (* _open)(void); /*!< HCI transport layer open function */
void (* _close)(void); /*!< HCI transport layer close function */
void (* _finish_transfers)(void); /*!< HCI transport layer finish transfers function */
void (* _recv)(uint8_t *buf, uint32_t len, esp_bt_hci_tl_callback_t callback, void* arg); /*!< HCI transport layer receive function */
void (* _send)(uint8_t *buf, uint32_t len, esp_bt_hci_tl_callback_t callback, void* arg); /*!< HCI transport layer send function */
bool (* _flow_off)(void); /*!< HCI transport layer flow off function */
void (* _flow_on)(void); /*!< HCI transport layer flow on function */
} esp_bt_hci_tl_t;

/**
Expand Down Expand Up @@ -271,15 +271,15 @@ typedef struct {
uint8_t txant_dft; /*!< default Tx antenna */
uint8_t rxant_dft; /*!< default Rx antenna */
uint8_t txpwr_dft; /*!< default Tx power */
uint32_t cfg_mask;
uint32_t cfg_mask; /*!< Configuration mask to set specific options */
uint8_t scan_duplicate_mode; /*!< scan duplicate mode */
uint8_t scan_duplicate_type; /*!< scan duplicate type */
uint16_t normal_adv_size; /*!< Normal adv size for scan duplicate */
uint16_t mesh_adv_size; /*!< Mesh adv size for scan duplicate */
uint8_t coex_phy_coded_tx_rx_time_limit; /*!< limit on max tx/rx time in case of connection using CODED-PHY with Wi-Fi coexistence */
uint32_t hw_target_code; /*!< hardware target */
uint8_t slave_ce_len_min; /*!< slave minimum ce length*/
uint8_t hw_recorrect_en;
uint8_t hw_recorrect_en; /*!< Hardware re-correction enabled */
uint8_t cca_thresh; /*!< cca threshold*/
uint16_t scan_backoff_upperlimitmax; /*!< scan backoff upperlimitmax value */
uint16_t dup_list_refresh_period; /*!< duplicate scan list refresh time */
Expand Down

0 comments on commit 8c1e87e

Please sign in to comment.