Skip to content

Commit bebc7a0

Browse files
cvinayakcarlescufi
authored andcommitted
Bluetooth: Controller: Fix Sync Failed to be Established on no memory
Update implementation to generate Periodic Sync Failed to be Established when Sync Established message could not be generate due to lack of free node rx buffers and when there is sync lost before sync established message could be generated. Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent 66312b0 commit bebc7a0

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

subsys/bluetooth/controller/ll_sw/ull_sync.c

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ static void *sync_free;
8686
static struct k_sem sem_ticker_cb;
8787
#endif /* CONFIG_BT_CTLR_DF_SCAN_CTE_RX */
8888

89-
static memq_link_t link_lll_prepare;
90-
static struct mayfly mfy_lll_prepare = { 0, 0, &link_lll_prepare, NULL, lll_sync_prepare };
91-
9289
uint8_t ll_sync_create(uint8_t options, uint8_t sid, uint8_t adv_addr_type,
9390
uint8_t *adv_addr, uint16_t skip,
9491
uint16_t sync_timeout, uint8_t sync_cte_type)
@@ -720,7 +717,7 @@ void ull_sync_setup(struct ll_scan_set *scan, struct ll_scan_aux_set *aux,
720717
}
721718
ticks_slot_offset += HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_START_US);
722719

723-
mfy_lll_prepare.fp = lll_sync_create_prepare;
720+
sync->lll_sync_prepare = lll_sync_create_prepare;
724721

725722
ret = ticker_start(TICKER_INSTANCE_ID_CTLR, TICKER_USER_ID_ULL_HIGH,
726723
(TICKER_ID_SCAN_SYNC_BASE + sync_handle),
@@ -758,12 +755,14 @@ void ull_sync_setup_complete(struct ll_scan_set *scan)
758755
void ull_sync_established_report(memq_link_t *link, struct node_rx_hdr *rx)
759756
{
760757
struct node_rx_pdu *rx_establ;
761-
struct ll_sync_set *ull_sync;
758+
struct ll_sync_set *sync;
762759
struct node_rx_ftr *ftr;
763760
struct node_rx_sync *se;
764761
struct lll_sync *lll;
765762

766763
ftr = &rx->rx_ftr;
764+
lll = ftr->param;
765+
sync = HDR_LLL2ULL(lll);
767766

768767
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING)
769768
enum sync_status sync_status;
@@ -773,8 +772,6 @@ void ull_sync_established_report(memq_link_t *link, struct node_rx_hdr *rx)
773772
#else
774773
struct pdu_cte_info *rx_cte_info;
775774

776-
lll = ftr->param;
777-
778775
rx_cte_info = pdu_cte_info_get((struct pdu_adv *)((struct node_rx_pdu *)rx)->pdu);
779776
if (rx_cte_info != NULL) {
780777
sync_status = lll_sync_cte_is_allowed(lll->cte_type, lll->filter_policy,
@@ -794,15 +791,10 @@ void ull_sync_established_report(memq_link_t *link, struct node_rx_hdr *rx)
794791
if (1) {
795792
#endif /* !CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING */
796793

797-
/* Set the sync handle corresponding to the LLL context passed in the node rx
798-
* footer field.
799-
*/
800-
lll = ftr->param;
801-
ull_sync = HDR_LLL2ULL(lll);
802-
803794
/* Prepare and dispatch sync notification */
804-
rx_establ = (void *)ull_sync->node_rx_sync_estab;
795+
rx_establ = (void *)sync->node_rx_sync_estab;
805796
rx_establ->hdr.type = NODE_RX_TYPE_SYNC;
797+
rx_establ->hdr.handle = ull_sync_handle_get(sync);
806798
se = (void *)rx_establ->pdu;
807799

808800
#if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING)
@@ -812,7 +804,7 @@ void ull_sync_established_report(memq_link_t *link, struct node_rx_hdr *rx)
812804

813805
#if !defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
814806
/* Notify done event handler to terminate sync scan if required. */
815-
ull_sync->is_term = (sync_status == SYNC_STAT_TERM);
807+
sync->is_term = (sync_status == SYNC_STAT_TERM);
816808
#endif /* !CONFIG_BT_CTLR_CTEINLINE_SUPPORT */
817809
#else
818810
se->status = BT_HCI_ERR_SUCCESS;
@@ -836,8 +828,9 @@ void ull_sync_established_report(memq_link_t *link, struct node_rx_hdr *rx)
836828

837829
if (1) {
838830
#endif /* !CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING */
831+
839832
/* Switch sync event prepare function to one reposnsible for regular PDUs receive */
840-
mfy_lll_prepare.fp = lll_sync_prepare;
833+
sync->lll_sync_prepare = lll_sync_prepare;
841834

842835
/* Change node type to appropriately handle periodic
843836
* advertising PDU report.
@@ -1128,6 +1121,9 @@ static void ticker_cb(uint32_t ticks_at_expire, uint32_t ticks_drift,
11281121
uint32_t remainder, uint16_t lazy, uint8_t force,
11291122
void *param)
11301123
{
1124+
static memq_link_t link_lll_prepare;
1125+
static struct mayfly mfy_lll_prepare = {
1126+
0, 0, &link_lll_prepare, NULL, NULL};
11311127
static struct lll_prepare_param p;
11321128
struct ll_sync_set *sync = param;
11331129
struct lll_sync *lll;
@@ -1152,9 +1148,11 @@ static void ticker_cb(uint32_t ticks_at_expire, uint32_t ticks_drift,
11521148
p.force = force;
11531149
p.param = lll;
11541150
mfy_lll_prepare.param = &p;
1151+
mfy_lll_prepare.fp = sync->lll_sync_prepare;
11551152

11561153
/* Kick LLL prepare */
1157-
ret = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, TICKER_USER_ID_LLL, 0, &mfy_lll_prepare);
1154+
ret = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, TICKER_USER_ID_LLL, 0,
1155+
&mfy_lll_prepare);
11581156
LL_ASSERT(!ret);
11591157

11601158
DEBUG_RADIO_PREPARE_O(1);
@@ -1235,9 +1233,17 @@ static void ticker_stop_sync_lost_op_cb(uint32_t status, void *param)
12351233

12361234
static void sync_lost(void *param)
12371235
{
1238-
struct ll_sync_set *sync = param;
1236+
struct ll_sync_set *sync;
12391237
struct node_rx_pdu *rx;
12401238

1239+
/* sync established was not generated yet, no free node rx */
1240+
sync = param;
1241+
if (sync->lll_sync_prepare != lll_sync_prepare) {
1242+
sync_expire(param);
1243+
1244+
return;
1245+
}
1246+
12411247
/* Generate Periodic advertising sync lost */
12421248
rx = (void *)&sync->node_rx_lost;
12431249
rx->hdr.handle = ull_sync_handle_get(sync);

subsys/bluetooth/controller/ll_sw/ull_sync_types.h

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

24+
void (*lll_sync_prepare)(void *param);
25+
2426
#if defined(CONFIG_BT_CTLR_CHECK_SAME_PEER_SYNC) || \
2527
defined(CONFIG_BT_CTLR_SYNC_PERIODIC_ADI_SUPPORT)
2628
uint8_t peer_id_addr[BDADDR_SIZE];

0 commit comments

Comments
 (0)