Skip to content

Commit 6939183

Browse files
ppryga-nordiccfriedt
authored andcommitted
Bluetooth: controller: Make per adv filtering by CTE cond compilable
The filtering of periodic advertisements by scanner may be not needed in certain situations e.g. while use of periodic advertising by BT ISO. To make the code smaller and avoid execution of not needed code the functionality will be conditionally compilable. It may be enabled or disabled by use of CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING Kconfig option. Signed-off-by: Piotr Pryga <[email protected]>
1 parent 6f045c1 commit 6939183

File tree

7 files changed

+61
-21
lines changed

7 files changed

+61
-21
lines changed

include/bluetooth/hci.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,7 @@ struct bt_hci_cp_le_ext_create_conn {
14451445

14461446
#define BT_HCI_OP_LE_PER_ADV_CREATE_SYNC BT_OP(BT_OGF_LE, 0x0044)
14471447
struct bt_hci_cp_le_per_adv_create_sync {
1448-
uint8_t options;
1448+
uint8_t options;
14491449
uint8_t sid;
14501450
bt_addr_le_t addr;
14511451
uint16_t skip;

subsys/bluetooth/controller/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,14 @@ config BT_CTLR_SYNC_PERIODIC
497497
config BT_CTLR_SYNC_PERIODIC
498498
bool "LE Periodic Advertising in Synchronization State [EXPERIMENTAL]" if BT_LL_SW_SPLIT
499499

500+
config BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING
501+
bool "LE Periodic Advertiser filtering by CTE type"
502+
depends on BT_CTLR_SYNC_PERIODIC
503+
default y
504+
help
505+
Enable filtering of periodic advertisements depending on type of
506+
Constant Tone Extension.
507+
500508
config BT_CTLR_ADV_ISO
501509
bool "LE Broadcast Isochronous Channel advertising" if !BT_LL_SW_SPLIT
502510
depends on BT_BROADCASTER && BT_CTLR_ADV_ISO_SUPPORT

subsys/bluetooth/controller/hci/hci.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3287,8 +3287,13 @@ static void le_per_adv_create_sync(struct net_buf *buf, struct net_buf **evt)
32873287
skip = sys_le16_to_cpu(cmd->skip);
32883288
sync_timeout = sys_le16_to_cpu(cmd->sync_timeout);
32893289

3290+
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING)
32903291
if ((cmd->cte_type & BT_HCI_LE_PER_ADV_CREATE_SYNC_CTE_TYPE_INVALID_VALUE) != 0) {
32913292
status = BT_HCI_ERR_CMD_DISALLOWED;
3293+
#else
3294+
if (cmd->cte_type != BT_HCI_LE_PER_ADV_CREATE_SYNC_CTE_TYPE_NO_FILTERING) {
3295+
status = BT_HCI_ERR_INVALID_PARAM;
3296+
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING */
32923297
} else {
32933298
status = ll_sync_create(cmd->options, cmd->sid, cmd->addr.type, cmd->addr.a.val,
32943299
skip, sync_timeout, cmd->cte_type);

subsys/bluetooth/controller/ll_sw/lll.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,13 @@ struct event_done_extra {
404404
struct {
405405
uint16_t trx_cnt;
406406
uint8_t crc_valid:1;
407-
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC) && defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
407+
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING) && \
408+
defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
408409
/* Used to inform ULL that periodic advertising sync scan should be
409410
* terminated.
410411
*/
411412
uint8_t sync_term:1;
412-
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC && CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
413+
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING && CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
413414
#if defined(CONFIG_BT_CTLR_LE_ENC)
414415
uint8_t mic_state;
415416
#endif /* CONFIG_BT_CTLR_LE_ENC */

subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ void lll_sync_aux_prepare_cb(struct lll_sync *lll,
186186
}
187187
}
188188

189+
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING)
189190
enum sync_status lll_sync_cte_is_allowed(uint8_t cte_type_mask, uint8_t filter_policy,
190191
uint8_t rx_cte_time, uint8_t rx_cte_type)
191192
{
@@ -236,6 +237,7 @@ enum sync_status lll_sync_cte_is_allowed(uint8_t cte_type_mask, uint8_t filter_p
236237

237238
return SYNC_STAT_ALLOWED;
238239
}
240+
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING */
239241

240242
static int init_reset(void)
241243
{
@@ -745,11 +747,12 @@ static void isr_rx_adv_sync_estab(void *param)
745747
}
746748

747749
isr_rx_done:
748-
#if defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
750+
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING) && \
751+
defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
749752
isr_rx_done_cleanup(lll, crc_ok, sync_ok == SYNC_STAT_TERM);
750753
#else
751754
isr_rx_done_cleanup(lll, crc_ok, false);
752-
#endif /* CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
755+
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING && CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
753756
}
754757

755758
static void isr_rx_adv_sync(void *param)
@@ -889,9 +892,10 @@ static void isr_rx_done_cleanup(struct lll_sync *lll, uint8_t crc_ok, bool sync_
889892
e->type = EVENT_DONE_EXTRA_TYPE_SYNC;
890893
e->trx_cnt = trx_cnt;
891894
e->crc_valid = crc_ok;
892-
#if defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
895+
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING) && \
896+
defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
893897
e->sync_term = sync_term;
894-
#endif /* CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
898+
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING && CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
895899
if (trx_cnt) {
896900
e->drift.preamble_to_addr_us = addr_us_get(lll->phy);
897901
e->drift.start_to_address_actual_us =
@@ -987,7 +991,8 @@ static uint8_t data_channel_calc(struct lll_sync *lll)
987991

988992
static enum sync_status sync_filtrate_by_cte_type(uint8_t cte_type_mask, uint8_t filter_policy)
989993
{
990-
#if defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
994+
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING) && \
995+
defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
991996
uint8_t rx_cte_time;
992997
uint8_t rx_cte_type;
993998

@@ -996,6 +1001,6 @@ static enum sync_status sync_filtrate_by_cte_type(uint8_t cte_type_mask, uint8_t
9961001

9971002
return lll_sync_cte_is_allowed(cte_type_mask, filter_policy, rx_cte_time, rx_cte_type);
9981003

999-
#endif /* CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
1004+
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING && CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
10001005
return SYNC_STAT_ALLOWED;
10011006
}

subsys/bluetooth/controller/ll_sw/ull_sync.c

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ static void ticker_op_cb(uint32_t status, void *param);
5959
static void ticker_update_sync_op_cb(uint32_t status, void *param);
6060
static void ticker_stop_op_cb(uint32_t status, void *param);
6161
static void sync_lost(void *param);
62-
#if !defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
62+
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING) && \
63+
!defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
6364
static struct pdu_cte_info *pdu_cte_info_get(struct pdu_adv *pdu);
64-
#endif /* CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
65+
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING && !CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
6566

6667
#if defined(CONFIG_BT_CTLR_DF_SCAN_CTE_RX)
6768
static void ticker_update_op_status_give(uint32_t status, void *param);
@@ -173,8 +174,10 @@ uint8_t ll_sync_create(uint8_t options, uint8_t sid, uint8_t adv_addr_type,
173174
lll_sync->skip_event = 0U;
174175
lll_sync->window_widening_prepare_us = 0U;
175176
lll_sync->window_widening_event_us = 0U;
177+
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING)
176178
lll_sync->cte_type = sync_cte_type;
177179
lll_sync->filter_policy = scan->per_scan.filter_policy;
180+
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING */
178181

179182
/* Reporting initially enabled/disabled */
180183
lll_sync->is_rx_enabled = options & BIT(1);
@@ -532,7 +535,6 @@ void ull_sync_setup(struct ll_scan_set *scan, struct ll_scan_aux_set *aux,
532535

533536
void ull_sync_established_report(memq_link_t *link, struct node_rx_hdr *rx)
534537
{
535-
enum sync_status sync_status;
536538
struct node_rx_pdu *rx_establ;
537539
struct ll_sync_set *ull_sync;
538540
struct node_rx_ftr *ftr;
@@ -541,6 +543,9 @@ void ull_sync_established_report(memq_link_t *link, struct node_rx_hdr *rx)
541543

542544
ftr = &rx->rx_ftr;
543545

546+
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING)
547+
enum sync_status sync_status;
548+
544549
#if defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
545550
sync_status = ftr->sync_status;
546551
#else
@@ -562,35 +567,46 @@ void ull_sync_established_report(memq_link_t *link, struct node_rx_hdr *rx)
562567
* or the CTE type is incorrect and filter policy doesn't allow to continue scanning.
563568
*/
564569
if (sync_status != SYNC_STAT_READY_OR_CONT_SCAN) {
570+
#else
571+
if (1) {
572+
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING */
573+
565574
/* Set the sync handle corresponding to the LLL context passed in the node rx
566575
* footer field.
567576
*/
568-
#if defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
569577
lll = ftr->param;
570-
#endif /* CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
571578
ull_sync = HDR_LLL2ULL(lll);
572579

573580
/* Prepare and dispatch sync notification */
574581
rx_establ = (void *)ull_sync->node_rx_sync_estab;
575582
rx_establ->hdr.type = NODE_RX_TYPE_SYNC;
576583
se = (void *)rx_establ->pdu;
584+
585+
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING)
577586
se->status = (ftr->sync_status == SYNC_STAT_TERM) ?
578587
BT_HCI_ERR_UNSUPP_REMOTE_FEATURE :
579588
BT_HCI_ERR_SUCCESS;
580589

581-
/* Notify done event handler to terminate sync scan */
582590
#if !defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
591+
/* Notify done event handler to terminate sync scan if required. */
583592
ull_sync->sync_term = sync_status == SYNC_STAT_TERM;
584-
#endif /* CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
593+
#endif /* !CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
594+
#else
595+
se->status = BT_HCI_ERR_SUCCESS;
596+
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING */
585597
ll_rx_put(rx_establ->hdr.link, rx_establ);
586598
ll_rx_sched();
587599
}
588600

601+
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING)
589602
/* Handle periodic advertising PDU and send periodic advertising scan report when
590603
* the sync was found or was established in the past. The report is not send if
591604
* scanning is terminated due to wrong CTE type.
592605
*/
593606
if (sync_status != SYNC_STAT_TERM) {
607+
#else
608+
if (1) {
609+
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING */
594610
/* Switch sync event prepare function to one reposnsible for regular PDUs receive */
595611
mfy_lll_prepare.fp = lll_sync_prepare;
596612

@@ -615,14 +631,17 @@ void ull_sync_done(struct node_rx_event_done *done)
615631
sync = CONTAINER_OF(done->param, struct ll_sync_set, ull);
616632
lll = &sync->lll;
617633

634+
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING)
618635
#if defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
619636
if (done->extra.sync_term) {
620637
#else
621638
if (sync->sync_term) {
622639
#endif /* CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
623640
/* Stop periodic advertising scan ticker */
624641
sync_ticker_cleanup(sync, NULL);
625-
} else {
642+
} else
643+
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING */
644+
{
626645
/* Events elapsed used in timeout checks below */
627646
skip_event = lll->skip_event;
628647
elapsed_event = skip_event + 1;
@@ -930,7 +949,8 @@ static void ticker_update_op_status_give(uint32_t status, void *param)
930949
}
931950
#endif /* CONFIG_BT_CTLR_DF_SCAN_CTE_RX */
932951

933-
#if !defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
952+
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING) && \
953+
!defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
934954
static struct pdu_cte_info *pdu_cte_info_get(struct pdu_adv *pdu)
935955
{
936956
struct pdu_adv_com_ext_adv *com_hdr;
@@ -953,4 +973,4 @@ static struct pdu_cte_info *pdu_cte_info_get(struct pdu_adv *pdu)
953973

954974
return (struct pdu_cte_info *)hdr->data;
955975
}
956-
#endif /* CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
976+
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING && !CONFIG_BT_CTLR_CTEINLINE_SUPPORT */

subsys/bluetooth/controller/ll_sw/ull_sync_types.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ struct ll_sync_set {
2121
uint16_t volatile timeout_reload; /* Non-zero when sync established */
2222
uint16_t timeout_expire;
2323

24-
#if !defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
24+
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING) && \
25+
!defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
2526
/* Member used to notify event done handler to terminate sync scanning.
2627
* Used only when no HW support for parsing PDU for CTEInfo.
2728
*/
2829
uint8_t sync_term:1;
29-
#endif /* CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
30+
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING && !CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
3031

3132
/* node rx type with memory aligned storage for sync lost reason.
3233
* HCI will reference the value using the pdu member of

0 commit comments

Comments
 (0)