Skip to content

Commit 3cad4b1

Browse files
committed
Bluetooth: Controller: Fix LLCP event_counter value used during prepare
Fix LLCP to use event_counter value used during prepare to compare instant to be the value as when in prepare and not incorrectly use a stale value (when two radio events overlap). Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
1 parent b3ccee4 commit 3cad4b1

File tree

6 files changed

+46
-16
lines changed

6 files changed

+46
-16
lines changed

subsys/bluetooth/controller/ll_sw/ull_conn.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2177,6 +2177,11 @@ void ull_conn_resume_rx_data(struct ll_conn *conn)
21772177
}
21782178
#endif /* CONFIG_BT_CTLR_LE_ENC */
21792179

2180+
uint16_t ull_conn_event_counter_at_prepare(const struct ll_conn *conn)
2181+
{
2182+
return conn->lll.event_counter + conn->lll.latency_prepare + conn->llcp.prep.lazy;
2183+
}
2184+
21802185
uint16_t ull_conn_event_counter(struct ll_conn *conn)
21812186
{
21822187
struct lll_conn *lll;
@@ -2204,6 +2209,7 @@ uint16_t ull_conn_event_counter(struct ll_conn *conn)
22042209

22052210
return event_counter;
22062211
}
2212+
22072213
static void ull_conn_update_ticker(struct ll_conn *conn,
22082214
uint32_t ticks_win_offset,
22092215
uint32_t ticks_slot_overhead,
@@ -2281,7 +2287,7 @@ void ull_conn_update_parameters(struct ll_conn *conn, uint8_t is_cu_proc, uint8_
22812287
lll = &conn->lll;
22822288

22832289
/* Calculate current event counter */
2284-
event_counter = ull_conn_event_counter(conn);
2290+
event_counter = ull_conn_event_counter_at_prepare(conn);
22852291

22862292
instant_latency = (event_counter - instant) & 0xFFFF;
22872293

subsys/bluetooth/controller/ll_sw/ull_conn_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ static inline void cpr_active_reset(void)
8484
void ull_conn_past_sender_offset_request(struct ll_conn *conn);
8585
#endif /* CONFIG_BT_CTLR_SYNC_TRANSFER_SENDER */
8686

87+
uint16_t ull_conn_event_counter_at_prepare(const struct ll_conn *conn);
8788
uint16_t ull_conn_event_counter(struct ll_conn *conn);
8889

8990
void ull_conn_update_parameters(struct ll_conn *conn, uint8_t is_cu_proc,

subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ enum {
130130
RP_CC_EVT_UNKNOWN,
131131
};
132132

133-
static void rp_cc_check_instant(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt,
134-
void *param);
133+
static void rp_cc_check_instant_rx_cis_ind(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt,
134+
void *param);
135135

136136
/*
137137
* LLCP Remote Procedure FSM
@@ -485,7 +485,7 @@ static void rp_cc_state_wait_rx_cis_ind(struct ll_conn *conn, struct proc_ctx *c
485485
llcp_rx_node_retain(ctx);
486486

487487
/* Check if this connection event is where we need to start the CIS */
488-
rp_cc_check_instant(conn, ctx, evt, param);
488+
rp_cc_check_instant_rx_cis_ind(conn, ctx, evt, param);
489489
break;
490490
}
491491
/* If we get to here the CIG_ID referred in req/acquire has become void/invalid */
@@ -523,13 +523,11 @@ static void rp_cc_state_wait_ntf_avail(struct ll_conn *conn, struct proc_ctx *ct
523523
}
524524

525525

526-
static void rp_cc_check_instant(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt,
527-
void *param)
526+
static void rp_cc_check_instant_by_counter(struct ll_conn *conn, struct proc_ctx *ctx,
527+
uint16_t event_counter, uint8_t evt, void *param)
528528
{
529529
uint16_t start_event_count;
530-
uint16_t event_counter;
531530

532-
event_counter = ull_conn_event_counter(conn);
533531
start_event_count = ctx->data.cis_create.conn_event_count;
534532

535533
if (is_instant_reached_or_passed(start_event_count, event_counter)) {
@@ -546,6 +544,26 @@ static void rp_cc_check_instant(struct ll_conn *conn, struct proc_ctx *ctx, uint
546544
}
547545
}
548546

547+
static void rp_cc_check_instant(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt,
548+
void *param)
549+
{
550+
uint16_t event_counter;
551+
552+
event_counter = ull_conn_event_counter_at_prepare(conn);
553+
554+
rp_cc_check_instant_by_counter(conn, ctx, event_counter, evt, param);
555+
}
556+
557+
static void rp_cc_check_instant_rx_cis_ind(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt,
558+
void *param)
559+
{
560+
uint16_t event_counter;
561+
562+
event_counter = ull_conn_event_counter(conn);
563+
564+
rp_cc_check_instant_by_counter(conn, ctx, event_counter, evt, param);
565+
}
566+
549567
static void rp_cc_state_wait_reply(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt,
550568
void *param)
551569
{
@@ -1078,7 +1096,7 @@ static void lp_cc_check_instant(struct ll_conn *conn, struct proc_ctx *ctx, uint
10781096
uint16_t instant_latency;
10791097
uint16_t event_counter;
10801098

1081-
event_counter = ull_conn_event_counter(conn);
1099+
event_counter = ull_conn_event_counter_at_prepare(conn);
10821100
start_event_count = ctx->data.cis_create.conn_event_count;
10831101

10841102
instant_latency = (event_counter - start_event_count) & 0xffff;

subsys/bluetooth/controller/ll_sw/ull_llcp_chmu.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ static void lp_chmu_send_channel_map_update_ind(struct ll_conn *conn, struct pro
118118
} else {
119119
llcp_rr_set_incompat(conn, INCOMPAT_RESOLVABLE);
120120

121-
ctx->data.chmu.instant = ull_conn_event_counter(conn) + CHMU_INSTANT_DELTA;
121+
ctx->data.chmu.instant = ull_conn_event_counter(conn) + conn->lll.latency +
122+
CHMU_INSTANT_DELTA;
122123

123124
lp_chmu_tx(conn, ctx);
124125

@@ -142,7 +143,7 @@ static void lp_chmu_st_wait_tx_chan_map_ind(struct ll_conn *conn, struct proc_ct
142143
static void lp_chmu_check_instant(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt,
143144
void *param)
144145
{
145-
uint16_t event_counter = ull_conn_event_counter(conn);
146+
uint16_t event_counter = ull_conn_event_counter_at_prepare(conn);
146147

147148
if (is_instant_reached_or_passed(ctx->data.chmu.instant, event_counter)) {
148149
llcp_rr_set_incompat(conn, INCOMPAT_NO_COLLISION);
@@ -257,7 +258,7 @@ static void rp_chmu_st_wait_rx_channel_map_update_ind(struct ll_conn *conn, stru
257258
static void rp_chmu_check_instant(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt,
258259
void *param)
259260
{
260-
uint16_t event_counter = ull_conn_event_counter(conn);
261+
uint16_t event_counter = ull_conn_event_counter_at_prepare(conn);
261262

262263
if (((event_counter - ctx->data.chmu.instant) & 0xFFFF) <= 0x7FFF) {
263264
rp_chmu_complete(conn, ctx, evt, param);

subsys/bluetooth/controller/ll_sw/ull_llcp_conn_upd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ static void lp_cu_st_wait_rx_conn_update_ind(struct ll_conn *conn, struct proc_c
637637
static void lp_cu_check_instant(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt,
638638
void *param)
639639
{
640-
uint16_t event_counter = ull_conn_event_counter(conn);
640+
uint16_t event_counter = ull_conn_event_counter_at_prepare(conn);
641641

642642
if (is_instant_reached_or_passed(ctx->data.cu.instant, event_counter)) {
643643
bool notify;
@@ -1222,7 +1222,7 @@ static void rp_cu_st_wait_tx_conn_update_ind(struct ll_conn *conn, struct proc_c
12221222
static void rp_cu_check_instant(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt,
12231223
void *param)
12241224
{
1225-
uint16_t event_counter = ull_conn_event_counter(conn);
1225+
uint16_t event_counter = ull_conn_event_counter_at_prepare(conn);
12261226

12271227
if (is_instant_reached_or_passed(ctx->data.cu.instant, event_counter)) {
12281228
bool notify;

subsys/bluetooth/controller/ll_sw/ull_llcp_phy.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,9 @@ static void lp_pu_st_wait_rx_phy_update_ind(struct ll_conn *conn, struct proc_ct
770770
static void lp_pu_check_instant(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt,
771771
void *param)
772772
{
773-
if (is_instant_reached_or_passed(ctx->data.pu.instant, ull_conn_event_counter(conn))) {
773+
uint16_t event_counter = ull_conn_event_counter_at_prepare(conn);
774+
775+
if (is_instant_reached_or_passed(ctx->data.pu.instant, event_counter)) {
774776
const uint8_t phy_changed = pu_apply_phy_update(conn, ctx);
775777
#if defined(CONFIG_BT_CTLR_DATA_LENGTH)
776778
if (phy_changed) {
@@ -1191,7 +1193,9 @@ static void rp_pu_st_wait_rx_phy_update_ind(struct ll_conn *conn, struct proc_ct
11911193
static void rp_pu_check_instant(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt,
11921194
void *param)
11931195
{
1194-
if (is_instant_reached_or_passed(ctx->data.pu.instant, ull_conn_event_counter(conn))) {
1196+
uint16_t event_counter = ull_conn_event_counter_at_prepare(conn);
1197+
1198+
if (is_instant_reached_or_passed(ctx->data.pu.instant, event_counter)) {
11951199
ctx->data.pu.error = BT_HCI_ERR_SUCCESS;
11961200
const uint8_t phy_changed = pu_apply_phy_update(conn, ctx);
11971201
#if defined(CONFIG_BT_CTLR_DATA_LENGTH)

0 commit comments

Comments
 (0)