Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions subsys/bluetooth/controller/ll_sw/lll_scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ struct lll_scan {
uint8_t adv_addr[BDADDR_SIZE];
uint32_t conn_win_offset_us;
uint16_t conn_timeout;

#if defined(CONFIG_BT_CTLR_SCHED_ADVANCED)
/* Stores prepare parameters for deferred mayfly execution.
* This prevents use-after-release issues by ensuring the parameters
* remain valid until execution.
*/
struct lll_prepare_param prepare_param;
#endif /* CONFIG_BT_CTLR_SCHED_ADVANCED */
#endif /* CONFIG_BT_CENTRAL */

uint8_t state:1;
Expand Down
16 changes: 11 additions & 5 deletions subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,13 +509,19 @@ static int common_prepare_cb(struct lll_prepare_param *p, bool is_resume)
static memq_link_t link;
static struct mayfly mfy_after_cen_offset_get = {
0U, 0U, &link, NULL, ull_sched_mfy_after_cen_offset_get};
uint32_t retval;
struct lll_prepare_param *prepare_param;

mfy_after_cen_offset_get.param = p;
/* Copy the required values to calculate the offsets */
prepare_param = &lll->prepare_param;
prepare_param->ticks_at_expire = p->ticks_at_expire;
prepare_param->remainder = p->remainder;
prepare_param->param = lll;

retval = mayfly_enqueue(TICKER_USER_ID_LLL, TICKER_USER_ID_ULL_LOW, 1U,
&mfy_after_cen_offset_get);
LL_ASSERT_ERR(!retval);
mfy_after_cen_offset_get.param = prepare_param;

ret = mayfly_enqueue(TICKER_USER_ID_LLL, TICKER_USER_ID_ULL_LOW, 1U,
&mfy_after_cen_offset_get);
LL_ASSERT_ERR(!ret);
}
#endif /* CONFIG_BT_CENTRAL && CONFIG_BT_CTLR_SCHED_ADVANCED */

Expand Down
13 changes: 10 additions & 3 deletions subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,12 +607,19 @@ static int prepare_cb(struct lll_prepare_param *p)
static memq_link_t link;
static struct mayfly mfy_after_cen_offset_get = {
0U, 0U, &link, NULL, ull_sched_mfy_after_cen_offset_get};
struct lll_prepare_param *prepare_param;

/* NOTE: LLL scan instance passed, as done when
/* Copy the required values to calculate the offsets
*
* NOTE: LLL scan instance passed, as done when
* establishing legacy connections.
*/
p->param = lll;
mfy_after_cen_offset_get.param = p;
prepare_param = &lll->prepare_param;
prepare_param->ticks_at_expire = p->ticks_at_expire;
prepare_param->remainder = p->remainder;
prepare_param->param = lll;

mfy_after_cen_offset_get.param = prepare_param;

ret = mayfly_enqueue(TICKER_USER_ID_LLL, TICKER_USER_ID_ULL_LOW, 1U,
&mfy_after_cen_offset_get);
Expand Down