Commit 6939183a authored by Piotr Pryga's avatar Piotr Pryga Committed by Christopher Friedt
Browse files

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: default avatarPiotr Pryga <piotr.pryga@nordicsemi.no>
parent 6f045c11
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -497,6 +497,14 @@ config BT_CTLR_SYNC_PERIODIC
config BT_CTLR_SYNC_PERIODIC
	bool "LE Periodic Advertising in Synchronization State [EXPERIMENTAL]" if BT_LL_SW_SPLIT

config BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING
	bool "LE Periodic Advertiser filtering by CTE type"
	depends on BT_CTLR_SYNC_PERIODIC
	default y
	help
	  Enable filtering of periodic advertisements depending on type of
	  Constant Tone Extension.

config BT_CTLR_ADV_ISO
	bool "LE Broadcast Isochronous Channel advertising" if !BT_LL_SW_SPLIT
	depends on BT_BROADCASTER && BT_CTLR_ADV_ISO_SUPPORT
+5 −0
Original line number Diff line number Diff line
@@ -3287,8 +3287,13 @@ static void le_per_adv_create_sync(struct net_buf *buf, struct net_buf **evt)
	skip = sys_le16_to_cpu(cmd->skip);
	sync_timeout = sys_le16_to_cpu(cmd->sync_timeout);

#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING)
	if ((cmd->cte_type & BT_HCI_LE_PER_ADV_CREATE_SYNC_CTE_TYPE_INVALID_VALUE) != 0) {
		status = BT_HCI_ERR_CMD_DISALLOWED;
#else
	if (cmd->cte_type != BT_HCI_LE_PER_ADV_CREATE_SYNC_CTE_TYPE_NO_FILTERING) {
		status = BT_HCI_ERR_INVALID_PARAM;
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING */
	} else {
		status = ll_sync_create(cmd->options, cmd->sid, cmd->addr.type, cmd->addr.a.val,
					skip, sync_timeout, cmd->cte_type);
+3 −2
Original line number Diff line number Diff line
@@ -404,12 +404,13 @@ struct event_done_extra {
		struct {
			uint16_t trx_cnt;
			uint8_t  crc_valid:1;
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC) && defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING) && \
	defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
			/* Used to inform ULL that periodic advertising sync scan should be
			 * terminated.
			 */
			uint8_t  sync_term:1;
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC && CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING && CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
#if defined(CONFIG_BT_CTLR_LE_ENC)
			uint8_t  mic_state;
#endif /* CONFIG_BT_CTLR_LE_ENC */
+11 −6
Original line number Diff line number Diff line
@@ -186,6 +186,7 @@ void lll_sync_aux_prepare_cb(struct lll_sync *lll,
	}
}

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

	return SYNC_STAT_ALLOWED;
}
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING */

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

isr_rx_done:
#if defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING) && \
	defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
	isr_rx_done_cleanup(lll, crc_ok, sync_ok == SYNC_STAT_TERM);
#else
	isr_rx_done_cleanup(lll, crc_ok, false);
#endif /* CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING && CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
}

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_
	e->type = EVENT_DONE_EXTRA_TYPE_SYNC;
	e->trx_cnt = trx_cnt;
	e->crc_valid = crc_ok;
#if defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING) && \
	defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
	e->sync_term = sync_term;
#endif /* CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING && CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
	if (trx_cnt) {
		e->drift.preamble_to_addr_us = addr_us_get(lll->phy);
		e->drift.start_to_address_actual_us =
@@ -987,7 +991,8 @@ static uint8_t data_channel_calc(struct lll_sync *lll)

static enum sync_status sync_filtrate_by_cte_type(uint8_t cte_type_mask, uint8_t filter_policy)
{
#if defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING) && \
	defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
	uint8_t rx_cte_time;
	uint8_t rx_cte_type;

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

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

#endif /* CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING && CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
	return SYNC_STAT_ALLOWED;
}
+30 −10
Original line number Diff line number Diff line
@@ -59,9 +59,10 @@ static void ticker_op_cb(uint32_t status, void *param);
static void ticker_update_sync_op_cb(uint32_t status, void *param);
static void ticker_stop_op_cb(uint32_t status, void *param);
static void sync_lost(void *param);
#if !defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING) && \
	!defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
static struct pdu_cte_info *pdu_cte_info_get(struct pdu_adv *pdu);
#endif /* CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING && !CONFIG_BT_CTLR_CTEINLINE_SUPPORT */

#if defined(CONFIG_BT_CTLR_DF_SCAN_CTE_RX)
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,
	lll_sync->skip_event = 0U;
	lll_sync->window_widening_prepare_us = 0U;
	lll_sync->window_widening_event_us = 0U;
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING)
	lll_sync->cte_type = sync_cte_type;
	lll_sync->filter_policy = scan->per_scan.filter_policy;
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING */

	/* Reporting initially enabled/disabled */
	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,

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

	ftr = &rx->rx_ftr;

#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING)
	enum sync_status sync_status;

#if defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
	sync_status = ftr->sync_status;
#else
@@ -562,35 +567,46 @@ void ull_sync_established_report(memq_link_t *link, struct node_rx_hdr *rx)
	 * or the CTE type is incorrect and filter policy doesn't allow to continue scanning.
	 */
	if (sync_status != SYNC_STAT_READY_OR_CONT_SCAN) {
#else
	if (1) {
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING */

		/* Set the sync handle corresponding to the LLL context passed in the node rx
		 * footer field.
		 */
#if defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
		lll = ftr->param;
#endif /* CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
		ull_sync = HDR_LLL2ULL(lll);

		/* Prepare and dispatch sync notification */
		rx_establ = (void *)ull_sync->node_rx_sync_estab;
		rx_establ->hdr.type = NODE_RX_TYPE_SYNC;
		se = (void *)rx_establ->pdu;

#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING)
		se->status = (ftr->sync_status == SYNC_STAT_TERM) ?
					   BT_HCI_ERR_UNSUPP_REMOTE_FEATURE :
					   BT_HCI_ERR_SUCCESS;

		/* Notify done event handler to terminate sync scan */
#if !defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
		/* Notify done event handler to terminate sync scan if required. */
		ull_sync->sync_term = sync_status == SYNC_STAT_TERM;
#endif /* CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
#endif /* !CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
#else
		se->status = BT_HCI_ERR_SUCCESS;
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING */
		ll_rx_put(rx_establ->hdr.link, rx_establ);
		ll_rx_sched();
	}

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

@@ -615,6 +631,7 @@ void ull_sync_done(struct node_rx_event_done *done)
	sync = CONTAINER_OF(done->param, struct ll_sync_set, ull);
	lll = &sync->lll;

#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING)
#if defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
	if (done->extra.sync_term) {
#else
@@ -622,7 +639,9 @@ void ull_sync_done(struct node_rx_event_done *done)
#endif /* CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
		/* Stop periodic advertising scan ticker */
		sync_ticker_cleanup(sync, NULL);
	} else {
	} else
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING */
	{
		/* Events elapsed used in timeout checks below */
		skip_event = lll->skip_event;
		elapsed_event = skip_event + 1;
@@ -930,7 +949,8 @@ static void ticker_update_op_status_give(uint32_t status, void *param)
}
#endif /* CONFIG_BT_CTLR_DF_SCAN_CTE_RX */

#if !defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING) && \
	!defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
static struct pdu_cte_info *pdu_cte_info_get(struct pdu_adv *pdu)
{
	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)

	return (struct pdu_cte_info *)hdr->data;
}
#endif /* CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
#endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING && !CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
Loading