4242#include <soc.h>
4343#include "hal/debug.h"
4444
45- /* Periodic advertisements filtering results. */
46- enum sync_filtering_result {
47- SYNC_ALLOWED ,
48- SYNC_SCAN_CONTINUE ,
49- SYNC_SCAN_TERM
50- };
51-
5245static int init_reset (void );
5346static void prepare (void * param );
5447static int create_prepare_cb (struct lll_prepare_param * p );
@@ -67,8 +60,7 @@ static int create_iq_report(struct lll_sync *lll, uint8_t rssi_ready,
6760 uint8_t packet_status );
6861#endif /* CONFIG_BT_CTLR_DF_SCAN_CTE_RX */
6962static uint8_t data_channel_calc (struct lll_sync * lll );
70- static enum sync_filtering_result sync_filtrate_by_cte_type (uint8_t cte_type_mask ,
71- uint8_t filter_policy );
63+ static enum sync_status sync_filtrate_by_cte_type (uint8_t cte_type_mask , uint8_t filter_policy );
7264
7365static uint8_t trx_cnt ;
7466
@@ -194,6 +186,57 @@ void lll_sync_aux_prepare_cb(struct lll_sync *lll,
194186 }
195187}
196188
189+ enum sync_status lll_sync_cte_is_allowed (uint8_t cte_type_mask , uint8_t filter_policy ,
190+ uint8_t rx_cte_time , uint8_t rx_cte_type )
191+ {
192+ bool cte_ok ;
193+
194+ if (cte_type_mask == BT_HCI_LE_PER_ADV_CREATE_SYNC_CTE_TYPE_NO_FILTERING ) {
195+ return SYNC_STAT_ALLOWED ;
196+ }
197+
198+ if (rx_cte_time > 0 ) {
199+ if ((cte_type_mask & BT_HCI_LE_PER_ADV_CREATE_SYNC_CTE_TYPE_NO_CTE ) != 0 ) {
200+ cte_ok = false;
201+ } else {
202+ switch (rx_cte_type ) {
203+ case BT_HCI_LE_AOA_CTE :
204+ cte_ok = !(cte_type_mask &
205+ BT_HCI_LE_PER_ADV_CREATE_SYNC_CTE_TYPE_NO_AOA );
206+ break ;
207+ case BT_HCI_LE_AOD_CTE_1US :
208+ cte_ok = !(cte_type_mask &
209+ BT_HCI_LE_PER_ADV_CREATE_SYNC_CTE_TYPE_NO_AOD_1US );
210+ break ;
211+ case BT_HCI_LE_AOD_CTE_2US :
212+ cte_ok = !(cte_type_mask &
213+ BT_HCI_LE_PER_ADV_CREATE_SYNC_CTE_TYPE_NO_AOD_2US );
214+ break ;
215+ default :
216+ /* Unknown or forbidden CTE type */
217+ cte_ok = false;
218+ }
219+ }
220+ } else {
221+ /* If there is no CTEInfo in advertising PDU, Radio will not parse the S0 byte and
222+ * CTESTATUS register will hold zeros only.
223+ * Zero value in CTETime field of CTESTATUS may be used to distinguish between PDU
224+ * that includes CTEInfo or not. Allowed range for CTETime is 2-20.
225+ */
226+ if ((cte_type_mask & BT_HCI_LE_PER_ADV_CREATE_SYNC_CTE_TYPE_ONLY_CTE ) != 0 ) {
227+ cte_ok = false;
228+ } else {
229+ cte_ok = true;
230+ }
231+ }
232+
233+ if (!cte_ok ) {
234+ return filter_policy ? SYNC_STAT_READY_OR_CONT_SCAN : SYNC_STAT_TERM ;
235+ }
236+
237+ return SYNC_STAT_ALLOWED ;
238+ }
239+
197240static int init_reset (void )
198241{
199242 return 0 ;
@@ -630,7 +673,7 @@ static int isr_rx(struct lll_sync *lll, uint8_t node_type, uint8_t crc_ok, uint8
630673
631674static void isr_rx_adv_sync_estab (void * param )
632675{
633- enum sync_filtering_result sync_ok ;
676+ enum sync_status sync_ok ;
634677 struct lll_sync * lll ;
635678 uint8_t rssi_ready ;
636679 uint8_t trx_done ;
@@ -651,7 +694,7 @@ static void isr_rx_adv_sync_estab(void *param)
651694 /* Initiated as allowed, crc_ok takes precended during handling of PDU
652695 * reception in the situation.
653696 */
654- sync_ok = SYNC_ALLOWED ;
697+ sync_ok = SYNC_STAT_ALLOWED ;
655698 }
656699
657700 /* Clear radio rx status and events */
@@ -671,12 +714,12 @@ static void isr_rx_adv_sync_estab(void *param)
671714 radio_tmr_ready_save (radio_tmr_ready_get ());
672715
673716 /* Handle regular PDU reception if CTE type is acceptable */
674- if (sync_ok == SYNC_ALLOWED ) {
675- err = isr_rx (lll , NODE_RX_TYPE_SYNC , crc_ok , rssi_ready , SYNC_STAT_FOUND );
717+ if (sync_ok == SYNC_STAT_ALLOWED ) {
718+ err = isr_rx (lll , NODE_RX_TYPE_SYNC , crc_ok , rssi_ready , SYNC_STAT_ALLOWED );
676719 if (err == - EBUSY ) {
677720 return ;
678721 }
679- } else if (sync_ok == SYNC_SCAN_TERM ) {
722+ } else if (sync_ok == SYNC_STAT_TERM ) {
680723 struct node_rx_pdu * node_rx ;
681724
682725 /* Verify if there are free RX buffers for:
@@ -702,7 +745,11 @@ static void isr_rx_adv_sync_estab(void *param)
702745 }
703746
704747isr_rx_done :
705- isr_rx_done_cleanup (lll , crc_ok , sync_ok == SYNC_SCAN_TERM );
748+ #if defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT )
749+ isr_rx_done_cleanup (lll , crc_ok , sync_ok == SYNC_STAT_TERM );
750+ #else
751+ isr_rx_done_cleanup (lll , crc_ok , false);
752+ #endif /* CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
706753}
707754
708755static void isr_rx_adv_sync (void * param )
@@ -745,7 +792,8 @@ static void isr_rx_adv_sync(void *param)
745792 * affect sychronization even when new CTE type is not allowed by sync parameters.
746793 * Hence the SYNC_STAT_READY is set.
747794 */
748- err = isr_rx (lll , NODE_RX_TYPE_SYNC_REPORT , crc_ok , rssi_ready , SYNC_STAT_READY );
795+ err = isr_rx (lll , NODE_RX_TYPE_SYNC_REPORT , crc_ok , rssi_ready ,
796+ SYNC_STAT_READY_OR_CONT_SCAN );
749797 if (err == - EBUSY ) {
750798 return ;
751799 }
@@ -798,7 +846,8 @@ static void isr_rx_aux_chain(void *param)
798846 * affect sychronization even when new CTE type is not allowed by sync parameters.
799847 * Hence the SYNC_STAT_READY is set.
800848 */
801- err = isr_rx (lll , NODE_RX_TYPE_EXT_AUX_REPORT , crc_ok , rssi_ready , SYNC_STAT_READY );
849+ err = isr_rx (lll , NODE_RX_TYPE_EXT_AUX_REPORT , crc_ok , rssi_ready ,
850+ SYNC_STAT_READY_OR_CONT_SCAN );
802851
803852 if (err == - EBUSY ) {
804853 return ;
@@ -840,8 +889,9 @@ static void isr_rx_done_cleanup(struct lll_sync *lll, uint8_t crc_ok, bool sync_
840889 e -> type = EVENT_DONE_EXTRA_TYPE_SYNC ;
841890 e -> trx_cnt = trx_cnt ;
842891 e -> crc_valid = crc_ok ;
892+ #if defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT )
843893 e -> sync_term = sync_term ;
844-
894+ #endif /* CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
845895 if (trx_cnt ) {
846896 e -> drift .preamble_to_addr_us = addr_us_get (lll -> phy );
847897 e -> drift .start_to_address_actual_us =
@@ -935,57 +985,17 @@ static uint8_t data_channel_calc(struct lll_sync *lll)
935985 data_chan_map , data_chan_count );
936986}
937987
938- static enum sync_filtering_result sync_filtrate_by_cte_type (uint8_t cte_type_mask ,
939- uint8_t filter_policy )
988+ static enum sync_status sync_filtrate_by_cte_type (uint8_t cte_type_mask , uint8_t filter_policy )
940989{
941- if (cte_type_mask & BT_HCI_LE_PER_ADV_CREATE_SYNC_CTE_TYPE_NO_FILTERING ) {
942- return SYNC_ALLOWED ;
943- }
944-
945- #if defined(HAS_CTEINLINE_SUPPORT )
990+ #if defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT )
946991 uint8_t rx_cte_time ;
947992 uint8_t rx_cte_type ;
948- bool cte_ok ;
949993
950994 rx_cte_time = nrf_radio_cte_time_get (NRF_RADIO );
951995 rx_cte_type = nrf_radio_cte_type_get (NRF_RADIO );
952996
953- /* If there is no CTEInfo in advertising PDU, Radio will not parse the S0 byte and
954- * CTESTATUS register will hold zeros only.
955- * Zero value in CTETime field of CTESTATUS may be used to distinguish between PDU that
956- * includes CTEInfo or not. Allowed range for CTETime is 2-20.
957- */
958- if (rx_cte_time == 0 && cte_type_mask & BT_HCI_LE_PER_ADV_CREATE_SYNC_CTE_TYPE_ONLY_CTE ) {
959- cte_ok = false;
960- }
961-
962- if (rx_cte_time > 0 ) {
963- if (cte_type_mask & BT_HCI_LE_PER_ADV_CREATE_SYNC_CTE_TYPE_NO_CTE ) {
964- cte_ok = false;
965- } else {
966- switch (rx_cte_type ) {
967- case BT_HCI_LE_AOA_CTE :
968- cte_ok = !(cte_type_mask &
969- BT_HCI_LE_PER_ADV_CREATE_SYNC_CTE_TYPE_NO_AOA );
970- break ;
971- case BT_HCI_LE_AOD_CTE_1US :
972- cte_ok = !(cte_type_mask &
973- BT_HCI_LE_PER_ADV_CREATE_SYNC_CTE_TYPE_NO_AOD_1US );
974- break ;
975- case BT_HCI_LE_AOD_CTE_2US :
976- cte_ok = !(cte_type_mask &
977- BT_HCI_LE_PER_ADV_CREATE_SYNC_CTE_TYPE_NO_AOD_2US );
978- break ;
979- default :
980- /* Unknown or forbidden CTE type */
981- cte_ok = false;
982- }
983- }
984- }
997+ return lll_sync_cte_is_allowed (cte_type_mask , filter_policy , rx_cte_time , rx_cte_type );
985998
986- if (!cte_ok ) {
987- return filter_policy ? SYNC_SCAN_CONTINUE : SYNC_SCAN_TERM ;
988- }
989- #endif /* HAS_CTEINLINE_SUPPORT */
990- return SYNC_ALLOWED ;
999+ #endif /* CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
1000+ return SYNC_STAT_ALLOWED ;
9911001}
0 commit comments