Skip to content

Commit

Permalink
Merge branch 'feat/add_ble50_instant_v5.3' into 'release/v5.3'
Browse files Browse the repository at this point in the history
Add support for BLE 5.0 instances in related events (v5.3)

See merge request espressif/esp-idf!31990
  • Loading branch information
jack0c committed Jul 26, 2024
2 parents 4a4d20f + c3af6db commit 1fa25ff
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 56 deletions.
18 changes: 18 additions & 0 deletions components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,10 @@ typedef uint8_t esp_ble_gap_adv_type_t;
/// Extend advertising tx power, range: [-127, +126] dBm
#define EXT_ADV_TX_PWR_NO_PREFERENCE (127) /*!< host has no preference for tx power */


/// max number of advertising sets to enable or disable
#define EXT_ADV_NUM_SETS_MAX (10) /*!< max evt instance num */

/**
* @brief ext adv parameters
*/
Expand Down Expand Up @@ -1290,72 +1294,86 @@ typedef union {
*/
struct ble_ext_adv_set_rand_addr_cmpl_evt_param {
esp_bt_status_t status; /*!< Indicate extend advertising random address set status */
uint8_t instance; /*!< extend advertising handle */
} ext_adv_set_rand_addr; /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_SET_RAND_ADDR_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_EXT_ADV_SET_PARAMS_COMPLETE_EVT
*/
struct ble_ext_adv_set_params_cmpl_evt_param {
esp_bt_status_t status; /*!< Indicate extend advertising parameters set status */
uint8_t instance; /*!< extend advertising handle */
} ext_adv_set_params; /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_SET_PARAMS_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_EXT_ADV_DATA_SET_COMPLETE_EVT
*/
struct ble_ext_adv_data_set_cmpl_evt_param {
esp_bt_status_t status; /*!< Indicate extend advertising data set status */
uint8_t instance; /*!< extend advertising handle */
} ext_adv_data_set; /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_DATA_SET_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_EXT_SCAN_RSP_DATA_SET_COMPLETE_EVT
*/
struct ble_ext_adv_scan_rsp_set_cmpl_evt_param {
esp_bt_status_t status; /*!< Indicate extend advertising scan response data set status */
uint8_t instance; /*!< extend advertising handle */
} scan_rsp_set; /*!< Event parameter of ESP_GAP_BLE_EXT_SCAN_RSP_DATA_SET_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_EXT_ADV_START_COMPLETE_EVT
*/
struct ble_ext_adv_start_cmpl_evt_param {
esp_bt_status_t status; /*!< Indicate advertising start operation success status */
uint8_t instance_num; /*!< extend advertising handle numble*/
uint8_t instance[EXT_ADV_NUM_SETS_MAX]; /*!< extend advertising handle list*/
} ext_adv_start; /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_START_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_EXT_ADV_STOP_COMPLETE_EVT
*/
struct ble_ext_adv_stop_cmpl_evt_param {
esp_bt_status_t status; /*!< Indicate advertising stop operation success status */
uint8_t instance_num; /*!< extend advertising handle numble*/
uint8_t instance[EXT_ADV_NUM_SETS_MAX]; /*!< extend advertising handle list*/
} ext_adv_stop; /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_STOP_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_EXT_ADV_SET_REMOVE_COMPLETE_EVT
*/
struct ble_ext_adv_set_remove_cmpl_evt_param {
esp_bt_status_t status; /*!< Indicate advertising stop operation success status */
uint8_t instance; /*!< extend advertising handle */
} ext_adv_remove; /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_SET_REMOVE_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_EXT_ADV_SET_CLEAR_COMPLETE_EVT
*/
struct ble_ext_adv_set_clear_cmpl_evt_param {
esp_bt_status_t status; /*!< Indicate advertising stop operation success status */
uint8_t instance; /*!< extend advertising handle */
} ext_adv_clear; /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_SET_CLEAR_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_PERIODIC_ADV_SET_PARAMS_COMPLETE_EVT
*/
struct ble_periodic_adv_set_params_cmpl_param {
esp_bt_status_t status; /*!< Indicate periodic advertisingparameters set status */
uint8_t instance; /*!< extend advertising handle */
} peroid_adv_set_params; /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_SET_PARAMS_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_PERIODIC_ADV_DATA_SET_COMPLETE_EVT
*/
struct ble_periodic_adv_data_set_cmpl_param {
esp_bt_status_t status; /*!< Indicate periodic advertising data set status */
uint8_t instance; /*!< extend advertising handle */
} period_adv_data_set; /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_DATA_SET_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_PERIODIC_ADV_START_COMPLETE_EVT
*/
struct ble_periodic_adv_start_cmpl_param {
esp_bt_status_t status; /*!< Indicate periodic advertising start status */
uint8_t instance; /*!< extend advertising handle */
} period_adv_start; /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_START_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_PERIODIC_ADV_STOP_COMPLETE_EVT
*/
struct ble_periodic_adv_stop_cmpl_param {
esp_bt_status_t status; /*!< Indicate periodic advertising stop status */
uint8_t instance; /*!< extend advertising handle */
} period_adv_stop; /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_STOP_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_PERIODIC_ADV_CREATE_SYNC_COMPLETE_EVT
Expand Down
20 changes: 19 additions & 1 deletion components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -989,34 +989,48 @@ static void btc_ble_5_gap_callback(tBTA_DM_BLE_5_GAP_EVENT event,
case BTA_DM_BLE_5_GAP_EXT_ADV_SET_RAND_ADDR_COMPLETE_EVT:
msg.act = ESP_GAP_BLE_EXT_ADV_SET_RAND_ADDR_COMPLETE_EVT;
param.ext_adv_set_rand_addr.status = btc_btm_status_to_esp_status(params->set_ext_rand_addr.status);
param.ext_adv_set_rand_addr.instance = params->set_ext_rand_addr.instance;
break;
case BTA_DM_BLE_5_GAP_EXT_ADV_SET_PARAMS_COMPLETE_EVT: {
msg.act = ESP_GAP_BLE_EXT_ADV_SET_PARAMS_COMPLETE_EVT;
param.ext_adv_set_rand_addr.status = btc_btm_status_to_esp_status(params->set_params.status);
param.ext_adv_set_params.status = btc_btm_status_to_esp_status(params->set_params.status);
param.ext_adv_set_params.instance = params->set_params.instance;
break;
}
case BTA_DM_BLE_5_GAP_EXT_ADV_DATA_SET_COMPLETE_EVT: {
msg.act = ESP_GAP_BLE_EXT_ADV_DATA_SET_COMPLETE_EVT;
param.ext_adv_data_set.status = btc_btm_status_to_esp_status(params->adv_data_set.status);
param.ext_adv_data_set.instance = params->adv_data_set.instance;
break;
}
case BTA_DM_BLE_5_GAP_EXT_SCAN_RSP_DATA_SET_COMPLETE_EVT: {
msg.act = ESP_GAP_BLE_EXT_SCAN_RSP_DATA_SET_COMPLETE_EVT;
param.scan_rsp_set.status = btc_btm_status_to_esp_status(params->scan_rsp_data_set.status);
param.scan_rsp_set.instance = params->scan_rsp_data_set.instance;
break;
}
case BTA_DM_BLE_5_GAP_EXT_ADV_START_COMPLETE_EVT: {
msg.act = ESP_GAP_BLE_EXT_ADV_START_COMPLETE_EVT;
param.ext_adv_start.status = btc_btm_status_to_esp_status(params->adv_start.status);
for (UINT8 i = 0; i < params->adv_start.instance_num; i++) {
param.ext_adv_start.instance[i] = params->adv_start.instance[i];
}

param.ext_adv_start.instance_num = params->adv_start.instance_num;
break;
}
case BTA_DM_BLE_5_GAP_EXT_ADV_STOP_COMPLETE_EVT:
msg.act = ESP_GAP_BLE_EXT_ADV_STOP_COMPLETE_EVT;
param.ext_adv_stop.status = btc_btm_status_to_esp_status(params->adv_start.status);
for (UINT8 i = 0; i < params->adv_start.instance_num; i++) {
param.ext_adv_stop.instance[i] = params->adv_start.instance[i];
}
param.ext_adv_stop.instance_num = params->adv_start.instance_num;
break;
case BTA_DM_BLE_5_GAP_EXT_ADV_SET_REMOVE_COMPLETE_EVT:
msg.act = ESP_GAP_BLE_EXT_ADV_SET_REMOVE_COMPLETE_EVT;
param.ext_adv_remove.status = btc_btm_status_to_esp_status(params->adv_start.status);
param.ext_adv_remove.instance = params->adv_start.instance[0];
break;
case BTA_DM_BLE_5_GAP_EXT_ADV_SET_CLEAR_COMPLETE_EVT:
msg.act = ESP_GAP_BLE_EXT_ADV_SET_CLEAR_COMPLETE_EVT;
Expand All @@ -1025,21 +1039,25 @@ static void btc_ble_5_gap_callback(tBTA_DM_BLE_5_GAP_EVENT event,
case BTA_DM_BLE_5_GAP_PERIODIC_ADV_SET_PARAMS_COMPLETE_EVT: {
msg.act = ESP_GAP_BLE_PERIODIC_ADV_SET_PARAMS_COMPLETE_EVT;
param.peroid_adv_set_params.status = btc_btm_status_to_esp_status(params->per_adv_set_params.status);
param.peroid_adv_set_params.instance = params->per_adv_set_params.instance;
break;
}
case BTA_DM_BLE_5_GAP_PERIODIC_ADV_DATA_SET_COMPLETE_EVT: {
msg.act = ESP_GAP_BLE_PERIODIC_ADV_DATA_SET_COMPLETE_EVT;
param.period_adv_data_set.status = btc_btm_status_to_esp_status(params->per_adv_data_set.status);
param.period_adv_data_set.instance = params->per_adv_data_set.instance;
break;
}
case BTA_DM_BLE_5_GAP_PERIODIC_ADV_START_COMPLETE_EVT: {
msg.act = ESP_GAP_BLE_PERIODIC_ADV_START_COMPLETE_EVT;
param.period_adv_start.status = btc_btm_status_to_esp_status(params->per_adv_start.status);
param.period_adv_start.instance = params->per_adv_start.instance;
break;
}
case BTA_DM_BLE_5_GAP_PERIODIC_ADV_STOP_COMPLETE_EVT: {
msg.act = ESP_GAP_BLE_PERIODIC_ADV_STOP_COMPLETE_EVT;
param.period_adv_stop.status = btc_btm_status_to_esp_status(params->per_adv_stop.status);
param.period_adv_stop.instance = params->per_adv_stop.instance;
break;
}
case BTA_DM_BLE_5_GAP_PERIODIC_ADV_CREATE_SYNC_COMPLETE_EVT: {
Expand Down
45 changes: 34 additions & 11 deletions components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ tBTM_STATUS BTM_BleSetExtendedAdvRandaddr(UINT8 instance, BD_ADDR rand_addr)
}

end:
cb_params.status = status;

cb_params.set_ext_rand_addr.status = status;
cb_params.set_ext_rand_addr.instance = instance;
BTM_ExtBleCallbackTrigger(BTM_BLE_5_GAP_EXT_ADV_SET_RAND_ADDR_COMPLETE_EVT, &cb_params);

return status;
Expand Down Expand Up @@ -420,7 +420,8 @@ tBTM_STATUS BTM_BleSetExtendedAdvParams(UINT8 instance, tBTM_BLE_GAP_EXT_ADV_PAR
BTM_UpdateAddrInfor(BLE_ADDR_RANDOM, rand_addr);
}
}
cb_params.status = status;
cb_params.set_params.status = status;
cb_params.set_params.instance = instance;
BTM_ExtBleCallbackTrigger(BTM_BLE_5_GAP_EXT_ADV_SET_PARAMS_COMPLETE_EVT, &cb_params);

return status;
Expand Down Expand Up @@ -471,7 +472,14 @@ tBTM_STATUS BTM_BleConfigExtendedAdvDataRaw(BOOLEAN is_scan_rsp, UINT8 instance,
} while (rem_len);

end:
cb_params.status = status;
if (is_scan_rsp) {
cb_params.scan_rsp_data_set.status = status;
cb_params.scan_rsp_data_set.instance = instance;
} else {
cb_params.adv_data_set.status = status;
cb_params.adv_data_set.instance = instance;
}

BTM_ExtBleCallbackTrigger(is_scan_rsp ? BTM_BLE_5_GAP_EXT_SCAN_RSP_DATA_SET_COMPLETE_EVT : BTM_BLE_5_GAP_EXT_ADV_DATA_SET_COMPLETE_EVT, &cb_params);

return status;
Expand Down Expand Up @@ -574,7 +582,12 @@ tBTM_STATUS BTM_BleStartExtAdv(BOOLEAN enable, UINT8 num, tBTM_BLE_EXT_ADV *ext_
}
}

cb_params.status = status;
cb_params.adv_start.status = status;
cb_params.adv_start.instance_num = num;
for (uint8_t i = 0; i < num; i++) {
cb_params.adv_start.instance[i] = ext_adv[i].instance;
}

BTM_ExtBleCallbackTrigger(enable ? BTM_BLE_5_GAP_EXT_ADV_START_COMPLETE_EVT : BTM_BLE_5_GAP_EXT_ADV_STOP_COMPLETE_EVT, &cb_params);

return status;
Expand Down Expand Up @@ -629,7 +642,9 @@ tBTM_STATUS BTM_BleExtAdvSetRemove(UINT8 instance)

end:

cb_params.status = status;
cb_params.adv_start.status = status;
cb_params.adv_start.instance_num = 1;
cb_params.adv_start.instance[0] = instance;

BTM_ExtBleCallbackTrigger(BTM_BLE_5_GAP_EXT_ADV_SET_REMOVE_COMPLETE_EVT, &cb_params);

Expand All @@ -655,7 +670,7 @@ tBTM_STATUS BTM_BleExtAdvSetClear(void)
}
}

cb_params.status = status;
cb_params.adv_start.status = status;

BTM_ExtBleCallbackTrigger(BTM_BLE_5_GAP_EXT_ADV_SET_CLEAR_COMPLETE_EVT, &cb_params);

Expand Down Expand Up @@ -693,7 +708,8 @@ tBTM_STATUS BTM_BlePeriodicAdvSetParams(UINT8 instance, tBTM_BLE_Periodic_Adv_Pa

end:

cb_params.status = status;
cb_params.per_adv_set_params.status = status;
cb_params.per_adv_set_params.instance = instance;

BTM_ExtBleCallbackTrigger(BTM_BLE_5_GAP_PERIODIC_ADV_SET_PARAMS_COMPLETE_EVT, &cb_params);

Expand Down Expand Up @@ -747,7 +763,9 @@ tBTM_STATUS BTM_BlePeriodicAdvCfgDataRaw(UINT8 instance, UINT16 len, UINT8 *data
} while(rem_len);

end:
cb_params.status = status;
cb_params.per_adv_data_set.status = status;
cb_params.per_adv_data_set.instance = instance;

BTM_ExtBleCallbackTrigger(BTM_BLE_5_GAP_PERIODIC_ADV_DATA_SET_COMPLETE_EVT, &cb_params);

return status;
Expand All @@ -771,8 +789,13 @@ tBTM_STATUS BTM_BlePeriodicAdvEnable(UINT8 instance, UINT8 enable)
}

end:

cb_params.status = status;
if (enable) {
cb_params.per_adv_start.status = status;
cb_params.per_adv_start.instance = instance;
} else {
cb_params.per_adv_stop.status = status;
cb_params.per_adv_stop.instance = instance;
}

BTM_ExtBleCallbackTrigger(enable ? BTM_BLE_5_GAP_PERIODIC_ADV_START_COMPLETE_EVT : BTM_BLE_5_GAP_PERIODIC_ADV_STOP_COMPLETE_EVT, &cb_params);

Expand Down
6 changes: 6 additions & 0 deletions components/bt/host/bluedroid/stack/btm/btm_ble_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,12 @@ void BTM_BleUpdateAdvFilterPolicy(tBTM_BLE_AFP adv_policy)
&p_cb->adv_addr_type);
}

uint8_t null_addr[BD_ADDR_LEN] = {0};
if ((p_cb->evt_type == 0x01 || p_cb->evt_type == 0x04) && memcmp(p_addr_ptr, null_addr, BD_ADDR_LEN) == 0) {
/* directed advertising */
return;
}

btsnd_hcic_ble_write_adv_params ((UINT16)(p_cb->adv_interval_min ? p_cb->adv_interval_min :
BTM_BLE_GAP_ADV_SLOW_INT),
(UINT16)(p_cb->adv_interval_max ? p_cb->adv_interval_max :
Expand Down
12 changes: 12 additions & 0 deletions components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1100,46 +1100,58 @@ typedef struct {

typedef struct {
UINT8 status;
UINT8 instance;
} tBTM_BLE_SET_PERF_PHY_CMPL;

typedef struct {
UINT8 status;
UINT8 instance;
} tBTM_BLE_EXT_ADV_SET_RAND_ADDR_CMPL;

typedef struct {
UINT8 status;
UINT8 instance;
} tBTM_BLE_EXT_ADV_SET_PARAMS_CMPL;

typedef struct {
UINT8 status;
UINT8 instance;
} tBTM_BLE_EXT_ADV_DATA_SET_CMPL;

typedef struct {
UINT8 status;
UINT8 instance;
} tBTM_BLE_EXT_ADV_SCAN_RSP_DATA_SET_CMPL;

typedef struct {
UINT8 status;
UINT8 instance_num;
UINT8 instance[10];
} tBTM_BLE_EXT_ADV_START_CMPL;

typedef struct {
UINT8 status;
UINT8 instance;
} tBTM_BLE_EXT_ADV_STOP_CMPL;

typedef struct {
UINT8 status;
UINT8 instance;
} tBTM_BLE_PERIOD_ADV_SET_PARAMS_CMPL;

typedef struct {
UINT8 status;
UINT8 instance;
} tBTM_BLE_PERIOD_ADV_DATA_SET_CMPL;

typedef struct {
UINT8 status;
UINT8 instance;
} tBTM_BLE_PERIOD_ADV_START_CMPL;

typedef struct {
UINT8 status;
UINT8 instance;
} tBTM_BLE_PERIOD_ADV_STOP_CMPL;

typedef struct {
Expand Down
Loading

0 comments on commit 1fa25ff

Please sign in to comment.