Skip to content

Commit

Permalink
Merge branch 'bugfix/support_periodic_adv_len_0' into 'master'
Browse files Browse the repository at this point in the history
fix(bt): Fix ble periodic advertising data length 0 error

See merge request espressif/esp-idf!24853
  • Loading branch information
esp-zhp committed Jul 26, 2023
2 parents f7ef577 + f836649 commit 47ae2c2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 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 @@ -2853,7 +2853,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 @@ -2943,6 +2943,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 @@ -1081,7 +1081,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
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

0 comments on commit 47ae2c2

Please sign in to comment.