Lines Matching full:sync

73  * indicate that a sync is established. And is used to check for sync being
83 static void sync_ticker_cleanup(struct ll_sync_set *sync, ticker_op_func stop_op_cb);
121 struct ll_sync_set *sync; in ll_sync_create() local
126 if (!scan || scan->periodic.sync) { in ll_sync_create()
132 if (!scan_coded || scan_coded->periodic.sync) { in ll_sync_create()
138 /* Do not sync twice to the same peer and same SID */ in ll_sync_create()
148 sync = ull_sync_create(sid, sync_timeout, skip, sync_cte_type, rx_enable, nodups); in ll_sync_create()
149 if (!sync) { in ll_sync_create()
165 sync->peer_id_addr_type = adv_addr_type; in ll_sync_create()
166 (void)memcpy(sync->peer_id_addr, adv_addr, BDADDR_SIZE); in ll_sync_create()
172 * address on sync setup when privacy is enabled. in ll_sync_create()
175 sync->peer_id_addr_type = adv_addr_type; in ll_sync_create()
176 (void)memcpy(sync->peer_id_addr, adv_addr, in ll_sync_create()
177 sizeof(sync->peer_id_addr)); in ll_sync_create()
182 sync->lll.filter_policy = scan->periodic.filter_policy; in ll_sync_create()
185 /* Enable scanner to create sync */ in ll_sync_create()
186 scan->periodic.sync = sync; in ll_sync_create()
192 scan_coded->periodic.sync = sync; in ll_sync_create()
204 struct ll_sync_set *sync, struct pdu_adv_sync_info *si, in ull_sync_setup_from_sync_transfer() argument
226 lll = &sync->lll; in ull_sync_setup_from_sync_transfer()
242 /* Ignore sync setup, invalid available channel count */ in ull_sync_setup_from_sync_transfer()
255 if (sync->timeout != 0 && interval_us != 0) { in ull_sync_setup_from_sync_transfer()
256 sync->timeout_reload = RADIO_SYNC_EVENTS((sync->timeout * 10U * in ull_sync_setup_from_sync_transfer()
270 if (sync->timeout_reload > CONN_ESTAB_COUNTDOWN) { in ull_sync_setup_from_sync_transfer()
271 uint16_t skip_max = sync->timeout_reload - CONN_ESTAB_COUNTDOWN; in ull_sync_setup_from_sync_transfer()
273 if (sync->skip > skip_max) { in ull_sync_setup_from_sync_transfer()
274 sync->skip = skip_max; in ull_sync_setup_from_sync_transfer()
278 sync->sync_expire = CONN_ESTAB_COUNTDOWN; in ull_sync_setup_from_sync_transfer()
304 /* Prepare Periodic Advertising Sync Transfer Received event (dispatched later) */ in ull_sync_setup_from_sync_transfer()
305 sync_handle = ull_sync_handle_get(sync); in ull_sync_setup_from_sync_transfer()
306 rx = (void *)sync->node_rx_sync_estab; in ull_sync_setup_from_sync_transfer()
309 rx->rx_ftr.param = sync; in ull_sync_setup_from_sync_transfer()
315 se_past->rx_sync.phy = sync->lll.phy; in ull_sync_setup_from_sync_transfer()
322 /* Calculate offset and schedule sync radio events */ in ull_sync_setup_from_sync_transfer()
326 /* offs_adjust may be 1 only if sync setup by LL_PERIODIC_SYNC_IND */ in ull_sync_setup_from_sync_transfer()
396 sync->ull.ticks_active_to_start = 0U; in ull_sync_setup_from_sync_transfer()
397 sync->ull.ticks_prepare_to_start = in ull_sync_setup_from_sync_transfer()
399 sync->ull.ticks_preempt_to_start = in ull_sync_setup_from_sync_transfer()
401 sync->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(slot_us); in ull_sync_setup_from_sync_transfer()
403 ticks_slot_offset = MAX(sync->ull.ticks_active_to_start, in ull_sync_setup_from_sync_transfer()
404 sync->ull.ticks_prepare_to_start); in ull_sync_setup_from_sync_transfer()
412 sync->lll_sync_prepare = lll_sync_create_prepare; in ull_sync_setup_from_sync_transfer()
430 (sync->ull.ticks_slot + ticks_slot_overhead), in ull_sync_setup_from_sync_transfer()
431 ticker_cb, sync, in ull_sync_setup_from_sync_transfer()
446 struct ll_sync_set *sync; in ll_sync_create_cancel() local
450 if (!scan || !scan->periodic.sync) { in ll_sync_create_cancel()
456 if (!scan_coded || !scan_coded->periodic.sync) { in ll_sync_create_cancel()
461 /* Check for race condition where in sync is established when sync in ll_sync_create_cancel()
465 * requested in the thread context. Checking `scan->periodic.sync` for in ll_sync_create_cancel()
474 sync = scan->periodic.sync; in ll_sync_create_cancel()
475 if (!sync) { in ll_sync_create_cancel()
479 /* node_rx_sync_estab is assigned when Host calls create sync and cleared when sync is in ll_sync_create_cancel()
480 * established. timeout_reload is set when sync is found and setup. It is non-zero until in ll_sync_create_cancel()
481 * sync is terminated. Together they give information about current sync state: in ll_sync_create_cancel()
482 * - node_rx_sync_estab == NULL && timeout_reload != 0 => sync is established in ll_sync_create_cancel()
483 * - node_rx_sync_estab == NULL && timeout_reload == 0 => sync is terminated in ll_sync_create_cancel()
484 * - node_rx_sync_estab != NULL && timeout_reload == 0 => sync is created in ll_sync_create_cancel()
485 * - node_rx_sync_estab != NULL && timeout_reload != 0 => sync is waiting to be established in ll_sync_create_cancel()
487 if (!sync->node_rx_sync_estab) { in ll_sync_create_cancel()
488 /* There is no sync to be cancelled */ in ll_sync_create_cancel()
492 sync->is_stop = 1U; in ll_sync_create_cancel()
495 if (sync->timeout_reload != 0U) { in ll_sync_create_cancel()
496 uint16_t sync_handle = ull_sync_handle_get(sync); in ll_sync_create_cancel()
500 /* Sync is not established yet, so stop sync ticker */ in ll_sync_create_cancel()
504 sync, &sync->lll); in ll_sync_create_cancel()
508 } /* else: sync was created but not yet setup, there is no sync ticker yet. */ in ll_sync_create_cancel()
511 * set, sync is_stop flag was set and sync has not been established. in ll_sync_create_cancel()
513 ull_sync_setup_reset(sync); in ll_sync_create_cancel()
515 /* Mark the sync context as sync create cancelled */ in ll_sync_create_cancel()
517 sync->timeout = 0U; in ll_sync_create_cancel()
520 node_rx = sync->node_rx_sync_estab; in ll_sync_create_cancel()
522 link_sync_lost = sync->node_rx_lost.rx.hdr.link; in ll_sync_create_cancel()
528 /* Clear the node after release to mark the sync establish as being completed. in ll_sync_create_cancel()
529 * In this case the completion reason is sync cancelled by Host. in ll_sync_create_cancel()
531 sync->node_rx_sync_estab = NULL; in ll_sync_create_cancel()
533 node_rx = (void *)&sync->node_rx_lost; in ll_sync_create_cancel()
544 * pass ULL sync context as parameter. in ll_sync_create_cancel()
546 node_rx->rx_ftr.param = sync; in ll_sync_create_cancel()
557 struct ll_sync_set *sync; in ll_sync_terminate() local
560 sync = ull_sync_is_enabled_get(handle); in ll_sync_terminate()
561 if (!sync) { in ll_sync_terminate()
566 sync->is_stop = 1U; in ll_sync_terminate()
569 /* Stop periodic sync ticker timeouts */ in ll_sync_terminate()
571 sync, &sync->lll); in ll_sync_terminate()
578 lll_aux = sync->lll.lll_aux; in ll_sync_terminate()
581 err = ull_scan_aux_stop(&sync->lll); in ll_sync_terminate()
599 if (sync->node_rx_sync_estab) { in ll_sync_terminate()
603 node_rx = (void *)sync->node_rx_sync_estab; in ll_sync_terminate()
609 sync->node_rx_sync_estab = NULL; in ll_sync_terminate()
613 link_sync_lost = sync->node_rx_lost.rx.hdr.link; in ll_sync_terminate()
616 /* Mark sync context not sync established */ in ll_sync_terminate()
617 sync->timeout_reload = 0U; in ll_sync_terminate()
619 ull_sync_release(sync); in ll_sync_terminate()
637 struct ll_sync_set *sync; in ll_sync_recv_enable() local
639 sync = ull_sync_is_enabled_get(handle); in ll_sync_recv_enable()
640 if (!sync) { in ll_sync_recv_enable()
645 sync->rx_enable = (enable & BT_HCI_LE_SET_PER_ADV_RECV_ENABLE_ENABLE) ? in ll_sync_recv_enable()
649 sync->nodups = (enable & BT_HCI_LE_SET_PER_ADV_RECV_ENABLE_FILTER_DUPLICATE) ? in ll_sync_recv_enable()
658 * Advertising Sync Transfer command.
671 struct ll_sync_set *sync; in ll_sync_transfer() local
680 sync = ull_sync_is_enabled_get(sync_handle); in ll_sync_transfer()
681 if (!sync) { in ll_sync_transfer()
686 return ull_cp_periodic_sync(conn, sync, NULL, service_data); in ll_sync_transfer()
692 * Advertising Sync Transfer Parameters command.
733 * Advertising Sync Transfer Parameters command.
804 struct ll_sync_set *sync; in ull_sync_is_enabled_get() local
806 sync = ull_sync_set_get(handle); in ull_sync_is_enabled_get()
807 if (!sync || !sync->timeout_reload) { in ull_sync_is_enabled_get()
811 return sync; in ull_sync_is_enabled_get()
814 struct ll_sync_set *ull_sync_is_valid_get(struct ll_sync_set *sync) in ull_sync_is_valid_get() argument
816 if (((uint8_t *)sync < (uint8_t *)ll_sync_pool) || in ull_sync_is_valid_get()
817 ((uint8_t *)sync > ((uint8_t *)ll_sync_pool + in ull_sync_is_valid_get()
822 return sync; in ull_sync_is_valid_get()
827 struct ll_sync_set *sync; in ull_sync_lll_is_valid_get() local
829 sync = HDR_LLL2ULL(lll); in ull_sync_lll_is_valid_get()
830 sync = ull_sync_is_valid_get(sync); in ull_sync_lll_is_valid_get()
831 if (sync) { in ull_sync_lll_is_valid_get()
832 return &sync->lll; in ull_sync_lll_is_valid_get()
838 uint16_t ull_sync_handle_get(struct ll_sync_set *sync) in ull_sync_handle_get() argument
840 return mem_index_get(sync, ll_sync_pool, sizeof(struct ll_sync_set)); in ull_sync_handle_get()
848 void ull_sync_release(struct ll_sync_set *sync) in ull_sync_release() argument
851 struct lll_sync *lll = &sync->lll; in ull_sync_release()
870 /* Mark the sync context as sync create cancelled */ in ull_sync_release()
872 sync->timeout = 0U; in ull_sync_release()
877 sync->data_len = 0U; in ull_sync_release()
880 mem_release(sync, &sync_free); in ull_sync_release()
883 void ull_sync_setup_addr_check(struct ll_sync_set *sync, struct ll_scan_set *scan, in ull_sync_setup_addr_check() argument
892 * SID in Sync Info in ull_sync_setup_addr_check()
894 sync->peer_id_addr_type = addr_type; in ull_sync_setup_addr_check()
895 (void)memcpy(sync->peer_id_addr, addr, in ull_sync_setup_addr_check()
904 sync->peer_id_addr)) { in ull_sync_setup_addr_check()
906 * SID in Sync Info in ull_sync_setup_addr_check()
908 sync->peer_id_addr_type = addr_type; in ull_sync_setup_addr_check()
911 sync->peer_addr_resolved = 1U; in ull_sync_setup_addr_check()
918 } else if ((addr_type == sync->peer_id_addr_type) && in ull_sync_setup_addr_check()
919 !memcmp(addr, sync->peer_id_addr, BDADDR_SIZE)) { in ull_sync_setup_addr_check()
927 if ((addr_type == sync->peer_id_addr_type) && in ull_sync_setup_addr_check()
928 !memcmp(addr, sync->peer_id_addr, BDADDR_SIZE)) { in ull_sync_setup_addr_check()
930 sync->peer_addr_resolved = 1U; in ull_sync_setup_addr_check()
938 bool ull_sync_setup_sid_match(struct ll_sync_set *sync, struct ll_scan_set *scan, uint8_t sid) in ull_sync_setup_sid_match() argument
943 ull_filter_ull_pal_match(sync->peer_id_addr_type, in ull_sync_setup_sid_match()
944 sync->peer_id_addr, sid)) || in ull_sync_setup_sid_match()
946 (sid == sync->sid))); in ull_sync_setup_sid_match()
954 struct ll_sync_set *sync; in ull_sync_setup() local
973 sync = scan->periodic.sync; in ull_sync_setup()
974 lll = &sync->lll; in ull_sync_setup()
990 /* Ignore sync setup, invalid available channel count */ in ull_sync_setup()
1006 sync->interval = interval; in ull_sync_setup()
1010 sync->timeout_reload = RADIO_SYNC_EVENTS((sync->timeout * 10U * in ull_sync_setup()
1023 if (sync->timeout_reload > CONN_ESTAB_COUNTDOWN) { in ull_sync_setup()
1024 uint16_t skip_max = sync->timeout_reload - CONN_ESTAB_COUNTDOWN; in ull_sync_setup()
1026 if (sync->skip > skip_max) { in ull_sync_setup()
1027 sync->skip = skip_max; in ull_sync_setup()
1030 sync->skip = 0U; in ull_sync_setup()
1033 sync->sync_expire = CONN_ESTAB_COUNTDOWN; in ull_sync_setup()
1061 /* Set the state to sync create */ in ull_sync_setup()
1077 sync_handle = ull_sync_handle_get(sync); in ull_sync_setup()
1079 /* Prepare sync notification, dispatch only on successful AUX_SYNC_IND in ull_sync_setup()
1082 rx = (void *)sync->node_rx_sync_estab; in ull_sync_setup()
1085 rx->rx_ftr.param = sync; in ull_sync_setup()
1091 /* Calculate offset and schedule sync radio events */ in ull_sync_setup()
1100 /* offs_adjust may be 1 only if sync setup by LL_PERIODIC_SYNC_IND */ in ull_sync_setup()
1135 sync->ull.ticks_active_to_start = 0U; in ull_sync_setup()
1136 sync->ull.ticks_prepare_to_start = in ull_sync_setup()
1138 sync->ull.ticks_preempt_to_start = in ull_sync_setup()
1140 sync->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(slot_us); in ull_sync_setup()
1142 ticks_slot_offset = MAX(sync->ull.ticks_active_to_start, in ull_sync_setup()
1143 sync->ull.ticks_prepare_to_start); in ull_sync_setup()
1151 sync->lll_sync_prepare = lll_sync_create_prepare; in ull_sync_setup()
1160 (sync->ull.ticks_slot + ticks_slot_overhead), in ull_sync_setup()
1161 ticker_cb, sync, in ull_sync_setup()
1167 void ull_sync_setup_reset(struct ll_sync_set *sync) in ull_sync_setup_reset() argument
1171 /* Remove the sync context from being associated with scan contexts */ in ull_sync_setup_reset()
1174 scan->periodic.sync = NULL; in ull_sync_setup_reset()
1183 scan->periodic.sync = NULL; in ull_sync_setup_reset()
1194 struct ll_sync_set *sync; local
1201 sync = HDR_LLL2ULL(lll);
1203 /* Do nothing if sync is cancelled or lost. */
1204 if (unlikely(sync->is_stop || !sync->timeout_reload)) {
1226 * advertising sync in case the CTE is not allowed.
1231 sync->is_term = ((sync_status == SYNC_STAT_TERM) || (sync_status == SYNC_STAT_CONT_SCAN));
1234 /* Send periodic advertisement sync established report when sync has correct CTE type
1243 /* Prepare and dispatch sync notification */
1244 rx_establ = (void *)sync->node_rx_sync_estab;
1245 rx_establ->hdr.handle = ull_sync_handle_get(sync);
1247 /* Clear the node to mark the sync establish as being completed.
1248 * In this case the completion reason is sync being established.
1250 sync->node_rx_sync_estab = NULL;
1260 /* NOTE: footer param has already been populated during sync
1269 * the sync was found or was established in the past. The report is not send if
1278 /* Switch sync event prepare function to one responsible for regular PDUs receive */
1279 sync->lll_sync_prepare = lll_sync_prepare;
1294 struct ll_sync_set *sync; local
1297 sync = CONTAINER_OF(done->param, struct ll_sync_set, ull);
1299 /* Do nothing if local terminate requested or sync lost */
1300 if (unlikely(sync->is_stop || !sync->timeout_reload)) {
1308 if (sync->is_term) {
1315 * Stop periodic advertising sync ticker and clear variables informing the
1316 * sync is pending. That is a step to completely terminate the synchronization.
1320 sync_ticker_cleanup(sync, NULL);
1333 lll = &sync->lll;
1338 /* Sync drift compensation and new skip calculation */
1346 lll->skip_event = sync->skip;
1348 /* Reset failed to establish sync countdown */
1349 sync->sync_expire = 0U;
1356 sync->timeout_expire = 0U;
1359 /* check sync failed to establish */
1360 else if (sync->sync_expire) {
1361 if (sync->sync_expire > elapsed_event) {
1362 sync->sync_expire -= elapsed_event;
1364 sync_ticker_cleanup(sync, ticker_stop_sync_expire_op_cb);
1370 /* If anchor point not sync-ed, start timeout countdown, and break skip if any */
1371 else if (!sync->timeout_expire) {
1372 sync->timeout_expire = sync->timeout_reload;
1378 if (sync->timeout_expire) {
1379 if (sync->timeout_expire > elapsed_event) {
1380 sync->timeout_expire -= elapsed_event;
1385 if (sync->timeout_expire <= 6U) {
1393 sync_ticker_cleanup(sync, ticker_stop_sync_lost_op_cb);
1407 /* Update Sync ticker instance */
1409 uint16_t sync_handle = ull_sync_handle_get(sync);
1413 * condition where in the periodic sync role is being
1415 * periodic sync event that gets into close state.
1416 * Accept failure when periodic sync role is being
1427 ticker_update_op_cb, sync);
1430 ((void *)sync == ull_disable_mark_get()));
1438 struct ll_sync_set *sync; local
1444 sync = ull_sync_set_get(sync_handle);
1445 LL_ASSERT(sync);
1446 lll = &sync->lll;
1504 /* @brief Function updates periodic sync slot duration.
1506 * @param[in] sync Pointer to sync instance
1511 * @retval -ENOENT Ticker node related with provided sync is already stopped.
1515 int ull_sync_slot_update(struct ll_sync_set *sync, uint32_t slot_plus_us, argument
1525 ull_sync_handle_get(sync)),
1558 /* Initialize sync pool. */
1582 struct ll_sync_set *sync; local
1604 sync = sync_acquire();
1605 if (!sync) {
1613 sync->peer_addr_resolved = 0U;
1615 /* Initialize sync context */
1617 sync->node_rx_lost.rx.hdr.link = link_sync_lost;
1620 * mark when sync establishment is in progress.
1622 LL_ASSERT(!sync->node_rx_sync_estab);
1623 sync->node_rx_sync_estab = node_rx;
1626 sync->rx_enable = rx_enable;
1629 sync->nodups = nodups;
1631 sync->skip = skip;
1632 sync->is_stop = 0U;
1635 sync->enc = 0U;
1638 /* NOTE: Use timeout not zero to represent sync context used for sync
1641 sync->timeout = timeout;
1643 /* NOTE: Use timeout_reload not zero to represent sync established. */
1644 sync->timeout_reload = 0U;
1645 sync->timeout_expire = 0U;
1648 sync->sid = sid;
1651 /* Reset Broadcast Isochronous Group Sync Establishment */
1652 sync->iso.sync_iso = NULL;
1655 /* Initialize sync LLL context */
1656 lll = &sync->lll;
1658 lll->is_rx_enabled = sync->rx_enable;
1673 ull_hdr_init(&sync->ull);
1674 lll_hdr_init(lll, sync);
1676 return sync;
1679 static void sync_ticker_cleanup(struct ll_sync_set *sync, ticker_op_func stop_op_cb) argument
1681 uint16_t sync_handle = ull_sync_handle_get(sync);
1684 /* Stop Periodic Sync Ticker */
1686 TICKER_ID_SCAN_SYNC_BASE + sync_handle, stop_op_cb, (void *)sync);
1690 /* Mark sync context not sync established */
1691 sync->timeout_reload = 0U;
1702 struct ll_sync_set *sync = param; local
1709 lll = &sync->lll;
1712 lll->is_rx_enabled = sync->rx_enable;
1715 ref = ull_ref_inc(&sync->ull);
1725 mfy_lll_prepare.fp = sync->lll_sync_prepare;
1764 struct ll_sync_set *sync = param; local
1768 /* Generate Periodic advertising sync failed to establish */
1769 rx = (void *)sync->node_rx_sync_estab;
1772 /* Clear the node to mark the sync establish as being completed.
1773 * In this case the completion reason is sync expire.
1775 sync->node_rx_sync_estab = NULL;
1783 /* NOTE: footer param has already been populated during sync setup */
1785 /* Enqueue the sync failed to established towards ULL context */
1796 * sync lost scenario, do not generate the sync lost node rx from here
1813 struct ll_sync_set *sync; local
1816 /* sync established was not generated yet, no free node rx */
1817 sync = param;
1818 if (sync->lll_sync_prepare != lll_sync_prepare) {
1824 /* Generate Periodic advertising sync lost */
1825 rx = (void *)&sync->node_rx_lost;
1826 rx->hdr.handle = ull_sync_handle_get(sync);
1828 rx->rx_ftr.param = sync;
1830 /* Enqueue the sync lost towards ULL context */
1834 if (sync->iso.sync_iso) {
1838 sync_iso = sync->iso.sync_iso;
1846 /* Enqueue the sync iso lost towards ULL context */
1855 struct ll_sync_set *sync; local
1857 sync = ull_sync_set_get(handle);
1858 if (!sync || !sync->timeout) {
1862 return sync;
1872 struct ll_sync_set *sync = sync_is_create_get(handle); local
1874 if (sync &&
1875 (sync->peer_id_addr_type == peer_id_addr_type) &&
1876 !memcmp(sync->peer_id_addr, peer_id_addr, BDADDR_SIZE) &&
1877 (sync->sid == sid)) {
1925 struct ll_sync_set *sync; local
1938 /* Do not sync twice to the same peer and same SID */
1947 sync = ull_sync_create(sid, conn->past.timeout, conn->past.skip, conn->past.cte_type,
1949 if (!sync) {
1955 sync->lll.filter_policy = 0U;
1958 sync->peer_id_addr_type = addr_type;
1959 sync->peer_addr_resolved = addr_resolved;
1960 memcpy(sync->peer_id_addr, adv_addr, BDADDR_SIZE);
1961 sync->lll.phy = phy;
1968 ull_sync_setup_from_sync_transfer(conn, service_data, sync, si,