Skip to content

Commit

Permalink
feat(bt/bluedroid): Support ble create sync report disable and filter…
Browse files Browse the repository at this point in the history
… duplicate
  • Loading branch information
esp-zhp committed Dec 4, 2023
1 parent 068a364 commit 633dd89
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 19 deletions.
7 changes: 7 additions & 0 deletions components/bt/host/bluedroid/Kconfig.in
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,13 @@ config BT_BLE_FEAT_PERIODIC_ADV_ENH
help
Enable the periodic advertising enhancements

config BT_BLE_FEAT_CREATE_SYNC_ENH
bool "Enable create sync enhancements(reporting disable and duplicate filtering enable support)"
depends on (BT_BLE_50_FEATURES_SUPPORTED && ((BT_CONTROLLER_ENABLED && SOC_ESP_NIMBLE_CONTROLLER) || BT_CONTROLLER_DISABLED))
default n
help
Enable the create sync enhancements

config BT_BLE_HIGH_DUTY_ADV_INTERVAL
bool "Enable BLE high duty advertising interval feature"
depends on BT_BLE_ENABLED
Expand Down
22 changes: 16 additions & 6 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 @@ -904,12 +904,22 @@ typedef struct {
* @brief periodic adv sync parameters
*/
typedef struct {
esp_ble_gap_sync_t filter_policy; /*!< periodic advertising sync filter policy */
uint8_t sid; /*!< periodic advertising sid */
esp_ble_addr_type_t addr_type; /*!< periodic advertising address type */
esp_bd_addr_t addr; /*!< periodic advertising address */
uint16_t skip; /*!< the maximum number of periodic advertising events that can be skipped */
uint16_t sync_timeout; /*!< synchronization timeout */
esp_ble_gap_sync_t filter_policy; /*!< Configures the filter policy for periodic advertising sync:
0: Use Advertising SID, Advertiser Address Type, and Advertiser Address parameters to determine the advertiser to listen to.
1: Use the Periodic Advertiser List to determine the advertiser to listen to. */
#if (CONFIG_BT_BLE_FEAT_CREATE_SYNC_ENH)
esp_ble_gap_sync_t reports_disabled; /*!< Supported only by esp32c2, esp32c6, and esp32h2; can be set by menuconfig:
0: Reporting initially enabled.
1: Reporting initially disabled. */
esp_ble_gap_sync_t filter_duplicates; /*!< Supported only by esp32c2, esp32c6, and esp32h2; can be set by menuconfig:
0: Duplicate filtering initially disabled.
1: Duplicate filtering initially enabled. */
#endif
uint8_t sid; /*!< SID of the periodic advertising */
esp_ble_addr_type_t addr_type; /*!< Address type of the periodic advertising */
esp_bd_addr_t addr; /*!< Address of the periodic advertising */
uint16_t skip; /*!< Maximum number of periodic advertising events that can be skipped */
uint16_t sync_timeout; /*!< Synchronization timeout */
} esp_ble_gap_periodic_adv_sync_params_t;

/**
Expand Down
4 changes: 4 additions & 0 deletions components/bt/host/bluedroid/bta/include/bta/bta_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,10 @@ typedef struct {

typedef struct {
UINT8 filter_policy;
#if (CONFIG_BT_BLE_FEAT_CREATE_SYNC_ENH)
UINT8 reports_disabled;
UINT8 filter_duplicates;
#endif
UINT8 sid;
tBLE_ADDR_TYPE addr_type;
BD_ADDR addr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2076,6 +2076,10 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
params.addr_type = arg_5->periodic_adv_create_sync.params.addr_type;
params.skip = arg_5->periodic_adv_create_sync.params.skip;
params.sync_timeout = arg_5->periodic_adv_create_sync.params.sync_timeout;
#if (CONFIG_BT_BLE_FEAT_CREATE_SYNC_ENH)
params.reports_disabled = arg_5->periodic_adv_create_sync.params.reports_disabled;
params.filter_duplicates = arg_5->periodic_adv_create_sync.params.filter_duplicates;
#endif

memcpy(params.addr, arg_5->periodic_adv_create_sync.params.addr, sizeof(BD_ADDR));
BTC_TRACE_DEBUG("BTC_GAP_BLE_PERIODIC_ADV_CREATE_SYNC");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@
#define UC_BT_BLE_FEAT_PERIODIC_ADV_ENH FALSE
#endif

#ifdef CONFIG_BT_BLE_FEAT_CREATE_SYNC_ENH
#define UC_BT_BLE_FEAT_CREATE_SYNC_ENH CONFIG_BT_BLE_FEAT_CREATE_SYNC_ENH
#else
#define UC_BT_BLE_FEAT_CREATE_SYNC_ENH FALSE
#endif

#ifdef CONFIG_BT_BLE_HIGH_DUTY_ADV_INTERVAL
#define UC_BT_BLE_HIGH_DUTY_ADV_INTERVAL CONFIG_BT_BLE_HIGH_DUTY_ADV_INTERVAL
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@
#define BLE_FEAT_PERIODIC_ADV_ENH FALSE
#endif

#if (UC_BT_BLE_FEAT_CREATE_SYNC_ENH == TRUE)
#define BLE_FEAT_CREATE_SYNC_ENH TRUE
#else
#define BLE_FEAT_CREATE_SYNC_ENH FALSE
#endif

#if (UC_BT_BLE_HIGH_DUTY_ADV_INTERVAL == TRUE)
#define BLE_HIGH_DUTY_ADV_INTERVAL TRUE
#else
Expand Down
23 changes: 21 additions & 2 deletions components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <string.h>
#include "l2c_int.h"
#if (BLE_50_FEATURE_SUPPORT == TRUE)
#define SET_BIT(t, n) (t |= 1UL << (n))
tBTM_BLE_EXTENDED_CB extend_adv_cb;

tBTM_BLE_5_HCI_CBACK ble_5_hci_cb;
Expand Down Expand Up @@ -788,14 +789,32 @@ tBTM_STATUS BTM_BlePeriodicAdvCreateSync(tBTM_BLE_Periodic_Sync_Params *params)
}

if ((params->sync_timeout < 0x0a || params->sync_timeout > 0x4000)
|| (params->filter_policy > 0x01) || (params->addr_type > 0x01) ||
|| (params->filter_policy > 0x01)
#if (CONFIG_BT_BLE_FEAT_CREATE_SYNC_ENH)
|| (params->reports_disabled > 0x01)
|| (params->filter_duplicates > 0x01)
#endif
|| (params->addr_type > 0x01) ||
(params->sid > 0xf) || (params->skip > 0x01F3)) {
status = BTM_ILLEGAL_VALUE;
BTM_TRACE_ERROR("%s, The sync parameters is invalid.", __func__);
goto end;
}
uint8_t option = 0x00;
if (params->filter_policy) {
SET_BIT(option, 0);
}

#if (CONFIG_BT_BLE_FEAT_CREATE_SYNC_ENH)
if (params->reports_disabled) {
SET_BIT(option, 1);
}
if (params->filter_duplicates) {
SET_BIT(option, 2);
}
#endif

if (!btsnd_hcic_ble_periodic_adv_create_sync(params->filter_policy, params->sid, params->addr_type,
if (!btsnd_hcic_ble_periodic_adv_create_sync(option, params->sid, params->addr_type,
params->addr, params->sync_timeout, 0)) {
BTM_TRACE_ERROR("LE PA CreateSync cmd failed");
status = BTM_ILLEGAL_VALUE;
Expand Down
8 changes: 4 additions & 4 deletions components/bt/host/bluedroid/stack/hcic/hciblecmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1627,22 +1627,22 @@ BOOLEAN btsnd_hcic_ble_create_ext_conn(tHCI_CreatExtConn *p_conn)

}

BOOLEAN btsnd_hcic_ble_periodic_adv_create_sync(UINT8 filter_policy, UINT8 adv_sid,
BOOLEAN btsnd_hcic_ble_periodic_adv_create_sync(UINT8 option, UINT8 adv_sid,
UINT8 adv_addr_type, BD_ADDR adv_addr,
UINT16 sync_timeout, UINT8 unused)
{
BT_HDR *p;
UINT8 *pp;
HCI_TRACE_EVENT("%s, filter_policy = %d, adv_sid = %d, adv_addr_type = %d, sync_timeout = %d, unused = %d",
__func__, filter_policy, adv_sid, adv_addr_type, sync_timeout, unused);
HCI_TRACE_EVENT("%s, option = %d, adv_sid = %d, adv_addr_type = %d, sync_timeout = %d, unused = %d",
__func__, option, adv_sid, adv_addr_type, sync_timeout, unused);

HCI_TRACE_EVENT("addr %02x %02x %02x %02x %02x %02x", adv_addr[0], adv_addr[1], adv_addr[2], adv_addr[3], adv_addr[4], adv_addr[5]);
uint16_t skip = 0;
HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_PERIODIC_ADV_CREATE_SYNC + 2);

UINT16_TO_STREAM(pp, HCI_BLE_PERIOD_ADV_CREATE_SYNC);
UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_PERIODIC_ADV_CREATE_SYNC + 2);
UINT8_TO_STREAM(pp, filter_policy);
UINT8_TO_STREAM(pp, option);
UINT8_TO_STREAM(pp, adv_sid);
UINT8_TO_STREAM(pp, adv_addr_type);
BDADDR_TO_STREAM(pp, adv_addr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,10 @@ typedef struct {

typedef struct {
UINT8 filter_policy;
#if (CONFIG_BT_BLE_FEAT_CREATE_SYNC_ENH)
UINT8 reports_disabled;
UINT8 filter_duplicates;
#endif
UINT8 sid;
tBLE_ADDR_TYPE addr_type;
BD_ADDR addr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,22 @@ same for the periodic sync:
* @brief periodic adv sync parameters
*/
typedef struct {
esp_ble_gap_sync_t filter_policy; /*!< periodic advertising sync filter policy */
uint8_t sid; /*!< periodic advertising sid */
esp_ble_addr_type_t addr_type; /*!< periodic advertising address type */
esp_bd_addr_t addr; /*!< periodic advertising address */
uint16_t skip; /*!< the maximum number of periodic advertising events t
hat can be skipped */
uint16_t sync_timeout; /*!< synchronization timeout */
esp_ble_gap_sync_t filter_policy; /*!< Configures the filter policy for periodic advertising sync:
0: Use Advertising SID, Advertiser Address Type, and Advertiser Address parameters to determine the advertiser to listen to.
1: Use the Periodic Advertiser List to determine the advertiser to listen to. */
#if (BLE_FEAT_CREATE_SYNC_ENH)
esp_ble_gap_sync_t reports_disabled; /*!< Supported only by esp32c2, esp32c6, and esp32h2; can be set by menuconfig:
0: Reporting initially enabled.
1: Reporting initially disabled. */
esp_ble_gap_sync_t filter_duplicates; /*!< Supported only by esp32c2, esp32c6, and esp32h2; can be set by menuconfig:
0: Duplicate filtering initially disabled.
1: Duplicate filtering initially enabled. */
#endif
uint8_t sid; /*!< SID of the periodic advertising */
esp_ble_addr_type_t addr_type; /*!< Address type of the periodic advertising */
esp_bd_addr_t addr; /*!< Address of the periodic advertising */
uint16_t skip; /*!< Maximum number of periodic advertising events that can be skipped */
uint16_t sync_timeout; /*!< Synchronization timeout */
} esp_ble_gap_periodic_adv_sync_params_t;
```
Expand Down

0 comments on commit 633dd89

Please sign in to comment.