From f83664929ae0953534a454d830102dc9c69f76c6 Mon Sep 17 00:00:00 2001 From: zhanghaipeng Date: Tue, 18 Jul 2023 15:33:23 +0800 Subject: [PATCH] fix(bt): Fix ble periodic advertising data length 0 error - Fixed issues about data length 0 when set ext adv data,ext scan rsp data and periodic adv data --- .../bt/host/bluedroid/bta/dm/bta_dm_api.c | 3 +- .../host/bluedroid/stack/btm/btm_ble_5_gap.c | 2 +- .../bt/host/bluedroid/stack/hcic/hciblecmds.c | 46 ++++++++----------- 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_api.c b/components/bt/host/bluedroid/bta/dm/bta_dm_api.c index 7ef64a95d4..b860f33ec5 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_api.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_api.c @@ -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); } @@ -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 { diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c b/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c index fce8e63226..331657af2d 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c @@ -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; } diff --git a/components/bt/host/bluedroid/stack/hcic/hciblecmds.c b/components/bt/host/bluedroid/stack/hcic/hciblecmds.c index f12bfb2b99..729134686e 100644 --- a/components/bt/host/bluedroid/stack/hcic/hciblecmds.c +++ b/components/bt/host/bluedroid/stack/hcic/hciblecmds.c @@ -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; - } - - UINT8_TO_STREAM (pp, data_len); - - ARRAY_TO_STREAM (pp, p_data, data_len); - } else { - return FALSE; + 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); + } + uint8_t status = btu_hcif_send_cmd_sync (LOCAL_BR_EDR_CONTROLLER_ID, p); return status; @@ -1309,16 +1308,13 @@ UINT8 btsnd_hcic_ble_set_ext_adv_scan_rsp_data(UINT8 adv_handle, memset(pp, 0, 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) { - 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); - ARRAY_TO_STREAM (pp, p_data, data_len); - } else { - return FALSE; } return btu_hcif_send_cmd_sync (LOCAL_BR_EDR_CONTROLLER_ID, p); @@ -1455,16 +1451,14 @@ UINT8 btsnd_hcic_ble_set_periodic_adv_data(UINT8 adv_handle, //memset(pp, 0, len); + if (len > HCIC_PARAM_SIZE_WRITE_PERIODIC_ADV_DATA) { + len = HCIC_PARAM_SIZE_WRITE_PERIODIC_ADV_DATA; + } + + UINT8_TO_STREAM (pp, len); + if (p_data != NULL && len > 0) { - if (len > HCIC_PARAM_SIZE_WRITE_PERIODIC_ADV_DATA) { - len = HCIC_PARAM_SIZE_WRITE_PERIODIC_ADV_DATA; - } - - UINT8_TO_STREAM (pp, len); - ARRAY_TO_STREAM (pp, p_data, len); - } else { - return FALSE; } return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);