Skip to content

Commit 906ae35

Browse files
cvinayakdleach02
authored andcommitted
Bluetooth: Controller: Fix ISO Sync Receiver BIS payload dereferencing
Fix incorrect use of BIS indices to dereference the payload array, instead correctly use synchronised stream indices. Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent 26603ce commit 906ae35

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ static void isr_rx(void *param)
526526
uint16_t data_chan_id;
527527
uint8_t data_chan_use;
528528
uint8_t crc_init[3];
529+
uint8_t stream_curr;
529530
uint8_t rssi_ready;
530531
uint32_t start_us;
531532
uint8_t new_burst;
@@ -553,6 +554,9 @@ static void isr_rx(void *param)
553554
/* BIS index */
554555
bis_idx = lll->bis_curr - 1U;
555556

557+
/* Current stream */
558+
stream_curr = lll->stream_curr;
559+
556560
goto isr_rx_done;
557561
}
558562

@@ -587,6 +591,9 @@ static void isr_rx(void *param)
587591
/* BIS index */
588592
bis_idx = lll->bis_curr - 1U;
589593

594+
/* Current stream */
595+
stream_curr = lll->stream_curr;
596+
590597
/* Check CRC and generate ISO Data PDU */
591598
if (crc_ok) {
592599
struct lll_sync_iso_stream *sync_stream;
@@ -648,14 +655,14 @@ static void isr_rx(void *param)
648655
}
649656

650657
/* Get reference to stream context */
651-
stream_handle = lll->stream_handle[lll->stream_curr];
658+
stream_handle = lll->stream_handle[stream_curr];
652659
sync_stream = ull_sync_iso_lll_stream_get(stream_handle);
653660

654661
/* Store the received PDU if selected stream and not already
655662
* received (say in previous event as pre-transmitted PDU.
656663
*/
657664
if ((lll->bis_curr == sync_stream->bis_index) && pdu->len &&
658-
!lll->payload[bis_idx][payload_index]) {
665+
!lll->payload[stream_curr][payload_index]) {
659666
uint16_t handle;
660667

661668
if (IS_ENABLED(CONFIG_BT_CTLR_BROADCAST_ISO_ENC) &&
@@ -679,7 +686,7 @@ static void isr_rx(void *param)
679686
handle = LL_BIS_SYNC_HANDLE_FROM_IDX(stream_handle);
680687
isr_rx_iso_data_valid(lll, handle, node_rx);
681688

682-
lll->payload[bis_idx][payload_index] = node_rx;
689+
lll->payload[stream_curr][payload_index] = node_rx;
683690
}
684691
}
685692

@@ -724,7 +731,7 @@ static void isr_rx(void *param)
724731
}
725732

726733
/* Check if (bn_curr)th Rx PDU has been received */
727-
if (!lll->payload[bis_idx][payload_index]) {
734+
if (!lll->payload[stream_curr][payload_index]) {
728735
/* Receive the (bn_curr)th Rx PDU of bis_curr */
729736
bis = lll->bis_curr;
730737

@@ -767,7 +774,7 @@ static void isr_rx(void *param)
767774
/* Check if (irc_curr)th bn = 1 Rx PDU has been
768775
* received.
769776
*/
770-
if (!lll->payload[bis_idx][payload_index]) {
777+
if (!lll->payload[stream_curr][payload_index]) {
771778
/* Receive the (irc_curr)th bn = 1 Rx PDU of
772779
* bis_curr.
773780
*/
@@ -816,14 +823,13 @@ static void isr_rx(void *param)
816823

817824
/* Next BIS */
818825
if (lll->bis_curr < lll->num_bis) {
819-
const uint8_t stream_curr = lll->stream_curr + 1U;
820826
struct lll_sync_iso_stream *sync_stream;
821827
uint16_t stream_handle;
822828

823829
/* Next selected stream */
824-
if (stream_curr < lll->stream_count) {
825-
lll->stream_curr = stream_curr;
826-
stream_handle = lll->stream_handle[lll->stream_curr];
830+
if ((lll->stream_curr + 1U) < lll->stream_count) {
831+
stream_curr = ++lll->stream_curr;
832+
stream_handle = lll->stream_handle[stream_curr];
827833
sync_stream = ull_sync_iso_lll_stream_get(stream_handle);
828834
if (sync_stream->bis_index <= lll->num_bis) {
829835
uint32_t payload_offset;
@@ -859,7 +865,7 @@ static void isr_rx(void *param)
859865
/* Check if (irc_curr)th bn = 1 Rx PDU has been
860866
* received.
861867
*/
862-
if (!lll->payload[bis_idx_new][payload_index]) {
868+
if (!lll->payload[stream_curr][payload_index]) {
863869
/* bn = 1 Rx PDU not received */
864870
skipped = (bis_idx_new - bis_idx) *
865871
((lll->bn * lll->irc) +
@@ -1165,14 +1171,16 @@ static void isr_rx_done(void *param)
11651171
/* Catchup with ISO event latencies */
11661172
latency_event = lll->latency_event;
11671173
do {
1168-
lll->stream_curr = 0U;
1174+
uint8_t stream_curr;
1175+
1176+
stream_curr = 0U;
11691177
for (bis_idx = 0U; bis_idx < lll->num_bis; bis_idx++) {
11701178
struct lll_sync_iso_stream *stream;
1171-
uint8_t payload_tail;
1172-
uint8_t stream_curr;
1179+
uint8_t stream_curr_inc;
11731180
uint16_t stream_handle;
1181+
uint8_t payload_tail;
11741182

1175-
stream_handle = lll->stream_handle[lll->stream_curr];
1183+
stream_handle = lll->stream_handle[stream_curr];
11761184
stream = ull_sync_iso_lll_stream_get(stream_handle);
11771185
/* Skip BIS indices not synchronized. bis_index is 0x01 to 0x1F,
11781186
* where as bis_idx is 0 indexed.
@@ -1184,9 +1192,9 @@ static void isr_rx_done(void *param)
11841192
payload_tail = lll->payload_tail;
11851193
bn = lll->bn;
11861194
while (bn--) {
1187-
if (lll->payload[bis_idx][payload_tail]) {
1188-
node_rx = lll->payload[bis_idx][payload_tail];
1189-
lll->payload[bis_idx][payload_tail] = NULL;
1195+
if (lll->payload[stream_curr][payload_tail]) {
1196+
node_rx = lll->payload[stream_curr][payload_tail];
1197+
lll->payload[stream_curr][payload_tail] = NULL;
11901198

11911199
iso_rx_put(node_rx->hdr.link, node_rx);
11921200
} else {
@@ -1221,9 +1229,9 @@ static void isr_rx_done(void *param)
12211229
payload_tail = payload_index;
12221230
}
12231231

1224-
stream_curr = lll->stream_curr + 1U;
1225-
if (stream_curr < lll->stream_count) {
1226-
lll->stream_curr = stream_curr;
1232+
stream_curr_inc = stream_curr + 1U;
1233+
if (stream_curr_inc < lll->stream_count) {
1234+
stream_curr = stream_curr_inc;
12271235
}
12281236
}
12291237
lll->payload_tail = payload_index;

0 commit comments

Comments
 (0)