6464#define BLE_LL_SYNC_SM_FLAG_HCI_TRUNCATED 0x0100
6565#define BLE_LL_SYNC_SM_FLAG_NEW_CHANMAP 0x0200
6666#define BLE_LL_SYNC_SM_FLAG_CHAIN 0x0400
67+ #define BLE_LL_SYNC_SM_FLAG_DUPLICATES 0x0800
6768
6869#define BLE_LL_SYNC_ITVL_USECS 1250
6970
@@ -121,6 +122,10 @@ struct ble_ll_sync_sm {
121122 uint16_t event_cntr_last_received ;
122123 uint8_t adv_addr_rpa [6 ];
123124#endif
125+
126+ #if MYNEWT_VAL (BLE_LL_CFG_FEAT_LL_PERIODIC_ADV_ADI_SUPPORT )
127+ uint16_t prev_adi ;
128+ #endif
124129};
125130
126131static struct ble_ll_sync_sm g_ble_ll_sync_sm [BLE_LL_SYNC_CNT ];
@@ -548,7 +553,7 @@ ble_ll_sync_rx_isr_start(uint8_t pdu_type, struct ble_mbuf_hdr *rxhdr)
548553
549554static int
550555ble_ll_sync_parse_ext_hdr (struct os_mbuf * om , uint8_t * * aux , int8_t * tx_power ,
551- uint8_t * * acad , uint8_t * acad_len )
556+ uint8_t * * acad , uint8_t * acad_len , uint16_t * * adi )
552557{
553558 uint8_t * rxbuf = om -> om_data ;
554559 uint8_t ext_hdr_flags ;
@@ -587,8 +592,10 @@ ble_ll_sync_parse_ext_hdr(struct os_mbuf *om, uint8_t **aux, int8_t *tx_power,
587592 i += BLE_LL_EXT_ADV_CTE_INFO_SIZE ;
588593 }
589594
590- /* there should be no ADI in Sync or chain, skip it */
591595 if (ext_hdr_flags & (1 << BLE_LL_EXT_ADV_DATA_INFO_BIT )) {
596+ if MYNEWT_VAL (BLE_LL_CFG_FEAT_LL_PERIODIC_ADV_ADI_SUPPORT ) {
597+ * adi = (uint16_t * ) ext_hdr + i ;
598+ }
592599 i += BLE_LL_EXT_ADV_DATA_INFO_SIZE ;
593600 }
594601
@@ -1137,10 +1144,12 @@ ble_ll_sync_rx_pkt_in(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *hdr)
11371144 uint8_t * aux = NULL ;
11381145 uint8_t * acad = NULL ;
11391146 uint8_t acad_len = 0 ;
1147+ uint16_t * adi = NULL ;
11401148 const uint8_t * biginfo = NULL ;
11411149 uint8_t biginfo_len = 0 ;
11421150 int datalen ;
11431151 bool reports_enabled ;
1152+ bool is_duplicate = false;
11441153
11451154 BLE_LL_ASSERT (sm );
11461155
@@ -1186,14 +1195,22 @@ ble_ll_sync_rx_pkt_in(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *hdr)
11861195 }
11871196
11881197 /* get ext header data */
1189- datalen = ble_ll_sync_parse_ext_hdr (rxpdu , & aux , & tx_power , & acad , & acad_len );
1198+ datalen = ble_ll_sync_parse_ext_hdr (rxpdu , & aux , & tx_power , & acad , & acad_len , & adi );
11901199 if (datalen < 0 ) {
11911200 /* we got bad packet, end event */
11921201 goto end_event ;
11931202 }
11941203
1204+ #if MYNEWT_VAL (BLE_LL_CFG_FEAT_LL_PERIODIC_ADV_ADI_SUPPORT )
1205+ if (adi != NULL ) {
1206+ is_duplicate = (sm -> flags & BLE_LL_SYNC_SM_FLAG_DUPLICATES ) && (* adi == sm -> prev_adi );
1207+ sm -> prev_adi = * adi ;
1208+ }
1209+ #endif
1210+
11951211 reports_enabled = ble_ll_hci_is_le_event_enabled (BLE_HCI_LE_SUBEV_PERIODIC_ADV_RPT ) &&
1196- !(sm -> flags & BLE_LL_SYNC_SM_FLAG_DISABLED );
1212+ !(sm -> flags & BLE_LL_SYNC_SM_FLAG_DISABLED ) &&
1213+ !is_duplicate ;
11971214
11981215 /* no need to schedule for chain if reporting is disabled */
11991216 if (reports_enabled ) {
@@ -1539,6 +1556,12 @@ ble_ll_sync_info_event(struct ble_ll_scan_addr_data *addrd,
15391556 }
15401557#endif
15411558
1559+ #if MYNEWT_VAL (BLE_LL_CFG_FEAT_LL_PERIODIC_ADV_ADI_SUPPORT )
1560+ if (g_ble_ll_sync_create_params .options & BLE_HCI_LE_PERIODIC_ADV_CREATE_SYNC_OPT_DUPLICATES ) {
1561+ sm -> flags |= BLE_LL_SYNC_SM_FLAG_DUPLICATES ;
1562+ }
1563+ #endif
1564+
15421565 sm -> flags &= ~BLE_LL_SYNC_SM_FLAG_RESERVED ;
15431566 sm -> flags |= BLE_LL_SYNC_SM_FLAG_ESTABLISHING ;
15441567 sm -> flags |= BLE_LL_SYNC_SM_FLAG_SYNC_INFO ;
@@ -1583,7 +1606,8 @@ ble_ll_sync_create(const uint8_t *cmdbuf, uint8_t len)
15831606 return BLE_ERR_INV_HCI_CMD_PARMS ;
15841607 }
15851608 if (!(cmd -> options & BLE_HCI_LE_PERIODIC_ADV_CREATE_SYNC_OPT_DISABLED ) &&
1586- (cmd -> options & BLE_HCI_LE_PERIODIC_ADV_CREATE_SYNC_OPT_DUPLICATES )) {
1609+ (cmd -> options & BLE_HCI_LE_PERIODIC_ADV_CREATE_SYNC_OPT_DUPLICATES ) &&
1610+ !MYNEWT_VAL (BLE_LL_CFG_FEAT_LL_PERIODIC_ADV_ADI_SUPPORT )) {
15871611 /* We do not support ADI in periodic advertising thus cannot enable
15881612 * duplicate filtering.
15891613 */
@@ -1870,7 +1894,8 @@ ble_ll_sync_receive_enable(const uint8_t *cmdbuf, uint8_t len)
18701894 if (MYNEWT_VAL (BLE_VERSION ) >= 53 ) {
18711895 if (cmd -> enable > 0x03 ) {
18721896 return BLE_ERR_INV_HCI_CMD_PARMS ;
1873- } else if (cmd -> enable == 0x03 ) {
1897+ } else if ((cmd -> enable == 0x03 ) &&
1898+ !MYNEWT_VAL (BLE_LL_CFG_FEAT_LL_PERIODIC_ADV_ADI_SUPPORT )) {
18741899 /* We do not support ADI in periodic advertising thus cannot enable
18751900 * duplicate filtering.
18761901 */
@@ -1898,8 +1923,14 @@ ble_ll_sync_receive_enable(const uint8_t *cmdbuf, uint8_t len)
18981923 return BLE_ERR_UNK_ADV_INDENT ;
18991924 }
19001925
1901- if (cmd -> enable ) {
1926+ if (cmd -> enable & 0x1 ) {
19021927 sm -> flags &= ~BLE_LL_SYNC_SM_FLAG_DISABLED ;
1928+
1929+ if (cmd -> enable & 0x2 ) {
1930+ sm -> flags |= BLE_LL_SYNC_SM_FLAG_DUPLICATES ;
1931+ } else {
1932+ sm -> flags &= ~BLE_LL_SYNC_SM_FLAG_DUPLICATES ;
1933+ }
19031934 } else {
19041935 sm -> flags |= BLE_LL_SYNC_SM_FLAG_DISABLED ;
19051936 }
@@ -1940,7 +1971,7 @@ ble_ll_sync_transfer_get(const uint8_t *addr, uint8_t addr_type, uint8_t sid)
19401971
19411972void
19421973ble_ll_sync_periodic_ind (struct ble_ll_conn_sm * connsm ,
1943- const uint8_t * sync_ind , bool reports_disabled ,
1974+ const uint8_t * sync_ind , uint8_t mode ,
19441975 uint16_t max_skip , uint32_t sync_timeout )
19451976{
19461977 const uint8_t * syncinfo = sync_ind + 2 ;
@@ -1966,6 +1997,10 @@ ble_ll_sync_periodic_ind(struct ble_ll_conn_sm *connsm,
19661997 uint8_t sca ;
19671998 os_sr_t sr ;
19681999
2000+ if (!mode ) {
2001+ return ;
2002+ }
2003+
19692004 phy_mode = ble_ll_ctrl_phy_from_phy_mask (sync_ind [25 ]);
19702005 itvl = get_le16 (syncinfo + 2 );
19712006 /* ignore if sync params are not valid */
@@ -2133,8 +2168,15 @@ ble_ll_sync_periodic_ind(struct ble_ll_conn_sm *connsm,
21332168 sm -> anchor_point = sm -> sch .start_time + g_ble_ll_sched_offset_ticks ;
21342169 sm -> anchor_point_usecs = sm -> sch .remainder ;
21352170
2136- if (reports_disabled ) {
2171+ switch (mode ) {
2172+ case 0x1 :
21372173 sm -> flags |= BLE_LL_SYNC_SM_FLAG_DISABLED ;
2174+ break ;
2175+ case 0x3 :
2176+ sm -> flags |= BLE_LL_SYNC_SM_FLAG_DUPLICATES ;
2177+ break ;
2178+ default :
2179+ break ;
21382180 }
21392181}
21402182
0 commit comments