@@ -179,6 +179,7 @@ static int prepare_cb_common(struct lll_prepare_param *p)
179
179
uint32_t ticks_at_start ;
180
180
uint16_t event_counter ;
181
181
uint8_t access_addr [4 ];
182
+ uint64_t payload_count ;
182
183
uint16_t data_chan_id ;
183
184
uint8_t data_chan_use ;
184
185
uint8_t crc_init [3 ];
@@ -198,8 +199,9 @@ static int prepare_cb_common(struct lll_prepare_param *p)
198
199
/* Calculate the current event counter value */
199
200
event_counter = (lll -> payload_count / lll -> bn ) + lll -> latency_event ;
200
201
201
- /* Update BIS packet counter to next value */
202
+ /* Update BIS payload counter to next value */
202
203
lll -> payload_count += (lll -> latency_prepare * lll -> bn );
204
+ payload_count = lll -> payload_count - lll -> bn ;
203
205
204
206
/* Reset accumulated latencies */
205
207
lll -> latency_prepare = 0U ;
@@ -240,7 +242,6 @@ static int prepare_cb_common(struct lll_prepare_param *p)
240
242
241
243
phy = lll -> phy ;
242
244
radio_phy_set (phy , lll -> phy_flags );
243
- radio_pkt_configure (RADIO_PKT_CONF_LENGTH_8BIT , lll -> max_pdu , RADIO_PKT_CONF_PHY (phy ));
244
245
radio_aa_set (access_addr );
245
246
radio_crc_configure (PDU_CRC_POLYNOMIAL , sys_get_le24 (crc_init ));
246
247
lll_chan_set (data_chan_use );
@@ -250,7 +251,6 @@ static int prepare_cb_common(struct lll_prepare_param *p)
250
251
struct lll_adv_iso_stream * stream ;
251
252
memq_link_t * link = NULL ;
252
253
struct node_tx_iso * tx ;
253
- uint64_t payload_count ;
254
254
uint16_t stream_handle ;
255
255
uint16_t handle ;
256
256
uint8_t bis_idx ;
@@ -262,8 +262,6 @@ static int prepare_cb_common(struct lll_prepare_param *p)
262
262
stream = ull_adv_iso_lll_stream_get (stream_handle );
263
263
LL_ASSERT (stream );
264
264
265
- payload_count = lll -> payload_count - lll -> bn ;
266
-
267
265
do {
268
266
link = memq_peek (stream -> memq_tx .head ,
269
267
stream -> memq_tx .tail , (void * * )& tx );
@@ -312,11 +310,11 @@ static int prepare_cb_common(struct lll_prepare_param *p)
312
310
pdu -> payload [2 ] = lll -> ptc_curr ;
313
311
pdu -> payload [3 ] = lll -> bis_curr ;
314
312
315
- pdu -> payload [4 ] = lll -> payload_count ;
316
- pdu -> payload [5 ] = lll -> payload_count >> 8 ;
317
- pdu -> payload [6 ] = lll -> payload_count >> 16 ;
318
- pdu -> payload [7 ] = lll -> payload_count >> 24 ;
319
- pdu -> payload [8 ] = lll -> payload_count >> 32 ;
313
+ pdu -> payload [4 ] = payload_count ;
314
+ pdu -> payload [5 ] = payload_count >> 8 ;
315
+ pdu -> payload [6 ] = payload_count >> 16 ;
316
+ pdu -> payload [7 ] = payload_count >> 24 ;
317
+ pdu -> payload [8 ] = payload_count >> 32 ;
320
318
#endif /* TEST_WITH_DUMMY_PDU */
321
319
322
320
/* Initialize reserve bit */
@@ -347,8 +345,33 @@ static int prepare_cb_common(struct lll_prepare_param *p)
347
345
}
348
346
pdu -> cssn = lll -> cssn ;
349
347
350
- radio_pkt_tx_set (pdu );
348
+ /* Encryption */
349
+ if (pdu -> len && lll -> enc ) {
350
+ uint8_t pkt_flags ;
351
351
352
+ lll -> ccm_tx .counter = payload_count ;
353
+
354
+ (void )memcpy (lll -> ccm_tx .iv , lll -> giv , 4U );
355
+ mem_xor_32 (lll -> ccm_tx .iv , lll -> ccm_tx .iv , access_addr );
356
+
357
+ pkt_flags = RADIO_PKT_CONF_FLAGS (RADIO_PKT_CONF_PDU_TYPE_BIS ,
358
+ phy ,
359
+ RADIO_PKT_CONF_CTE_DISABLED );
360
+ radio_pkt_configure (RADIO_PKT_CONF_LENGTH_8BIT ,
361
+ (lll -> max_pdu + PDU_MIC_SIZE ), pkt_flags );
362
+ radio_pkt_tx_set (radio_ccm_tx_pkt_set (& lll -> ccm_tx , pdu ));
363
+ } else {
364
+ uint8_t pkt_flags ;
365
+
366
+ pkt_flags = RADIO_PKT_CONF_FLAGS (RADIO_PKT_CONF_PDU_TYPE_BIS ,
367
+ phy ,
368
+ RADIO_PKT_CONF_CTE_DISABLED );
369
+ radio_pkt_configure (RADIO_PKT_CONF_LENGTH_8BIT , lll -> max_pdu ,
370
+ pkt_flags );
371
+ radio_pkt_tx_set (pdu );
372
+ }
373
+
374
+ /* Setup radio IFS switching */
352
375
if ((lll -> bn_curr == lll -> bn ) &&
353
376
(lll -> irc_curr == lll -> irc ) &&
354
377
(lll -> ptc_curr == lll -> ptc ) &&
@@ -358,9 +381,11 @@ static int prepare_cb_common(struct lll_prepare_param *p)
358
381
} else {
359
382
uint16_t iss_us ;
360
383
384
+ /* Calculate next subevent start based on previous PDU length */
361
385
iss_us = lll -> sub_interval -
362
- PDU_BIS_US (pdu -> len , lll -> enc , lll -> phy ,
363
- lll -> phy_flags );
386
+ PDU_BIS_US (pdu -> len , ((pdu -> len ) ? lll -> enc : 0U ),
387
+ lll -> phy , lll -> phy_flags );
388
+
364
389
radio_tmr_tifs_set (iss_us );
365
390
radio_switch_complete_and_b2b_tx (lll -> phy , lll -> phy_flags ,
366
391
lll -> phy , lll -> phy_flags );
@@ -427,6 +452,7 @@ static void isr_tx_common(void *param,
427
452
struct pdu_bis * pdu = NULL ;
428
453
struct lll_adv_iso * lll ;
429
454
uint8_t access_addr [4 ];
455
+ uint64_t payload_count ;
430
456
uint16_t data_chan_id ;
431
457
uint8_t data_chan_use ;
432
458
uint8_t crc_init [3 ];
@@ -442,9 +468,8 @@ static void isr_tx_common(void *param,
442
468
bis = lll -> bis_curr ;
443
469
444
470
} else if (lll -> irc_curr < lll -> irc ) {
445
- lll -> bn_curr = 0U ;
446
471
/* transmit the (bn_curr)th Tx PDU of bis_curr */
447
- lll -> bn_curr ++ ; /* post increment */
472
+ lll -> bn_curr = 1U ;
448
473
lll -> irc_curr ++ ; /* post increment */
449
474
450
475
bis = lll -> bis_curr ;
@@ -459,9 +484,8 @@ static void isr_tx_common(void *param,
459
484
lll -> bis_curr ++ ;
460
485
lll -> ptc_curr = 0U ;
461
486
lll -> irc_curr = 1U ;
462
- lll -> bn_curr = 0U ;
463
487
/* transmit the (bn_curr)th PDU of bis_curr */
464
- lll -> bn_curr ++ ; /* post increment */
488
+ lll -> bn_curr = 1U ;
465
489
466
490
bis = lll -> bis_curr ;
467
491
@@ -486,6 +510,7 @@ static void isr_tx_common(void *param,
486
510
487
511
/* control subevent to use bis = 0 and se_n = 1 */
488
512
bis = 0U ;
513
+ payload_count = lll -> payload_count - lll -> bn ;
489
514
data_chan_use = lll -> ctrl_chan_use ;
490
515
491
516
} else if (((lll -> chm_req - lll -> chm_ack ) & CHM_STATE_MASK ) ==
@@ -509,6 +534,7 @@ static void isr_tx_common(void *param,
509
534
510
535
/* control subevent to use bis = 0 and se_n = 1 */
511
536
bis = 0U ;
537
+ payload_count = lll -> payload_count - lll -> bn ;
512
538
data_chan_use = lll -> ctrl_chan_use ;
513
539
514
540
} else {
@@ -571,22 +597,22 @@ static void isr_tx_common(void *param,
571
597
572
598
/* Get ISO data PDU, not control subevent */
573
599
if (!pdu ) {
600
+ uint8_t payload_index ;
601
+
602
+ payload_index = (lll -> bn_curr - 1U ) +
603
+ (lll -> ptc_curr * lll -> pto );
604
+ payload_count = lll -> payload_count + payload_index - lll -> bn ;
605
+
574
606
#if !TEST_WITH_DUMMY_PDU
575
607
struct lll_adv_iso_stream * stream ;
576
- uint64_t payload_count ;
577
608
uint16_t stream_handle ;
578
609
struct node_tx_iso * tx ;
579
- uint8_t payload_index ;
580
610
memq_link_t * link ;
581
611
582
612
stream_handle = lll -> stream_handle [lll -> bis_curr - 1U ];
583
613
stream = ull_adv_iso_lll_stream_get (stream_handle );
584
614
LL_ASSERT (stream );
585
615
586
- payload_index = (lll -> bn_curr - 1U ) +
587
- (lll -> ptc_curr * lll -> pto );
588
- payload_count = lll -> payload_count + payload_index - lll -> bn ;
589
-
590
616
link = memq_peek_n (stream -> memq_tx .head , stream -> memq_tx .tail ,
591
617
payload_index , (void * * )& tx );
592
618
if (!link || (tx -> payload_count != payload_count )) {
@@ -624,6 +650,12 @@ static void isr_tx_common(void *param,
624
650
pdu -> payload [1 ] = lll -> irc_curr ;
625
651
pdu -> payload [2 ] = lll -> ptc_curr ;
626
652
pdu -> payload [3 ] = lll -> bis_curr ;
653
+
654
+ pdu -> payload [4 ] = payload_count ;
655
+ pdu -> payload [5 ] = payload_count >> 8 ;
656
+ pdu -> payload [6 ] = payload_count >> 16 ;
657
+ pdu -> payload [7 ] = payload_count >> 24 ;
658
+ pdu -> payload [8 ] = payload_count >> 32 ;
627
659
#endif /* TEST_WITH_DUMMY_PDU */
628
660
629
661
data_chan_use = lll -> next_chan_use ;
@@ -632,7 +664,17 @@ static void isr_tx_common(void *param,
632
664
633
665
lll_chan_set (data_chan_use );
634
666
635
- radio_pkt_tx_set (pdu );
667
+ /* Encryption */
668
+ if (pdu -> len && lll -> enc ) {
669
+ lll -> ccm_tx .counter = payload_count ;
670
+
671
+ (void )memcpy (lll -> ccm_tx .iv , lll -> giv , 4U );
672
+ mem_xor_32 (lll -> ccm_tx .iv , lll -> ccm_tx .iv , access_addr );
673
+
674
+ radio_pkt_tx_set (radio_ccm_tx_pkt_set (& lll -> ccm_tx , pdu ));
675
+ } else {
676
+ radio_pkt_tx_set (pdu );
677
+ }
636
678
637
679
/* Control subevent, then complete subevent and close radio use */
638
680
if (!bis ) {
@@ -644,8 +686,8 @@ static void isr_tx_common(void *param,
644
686
645
687
/* Calculate next subevent start based on previous PDU length */
646
688
iss_us = lll -> sub_interval -
647
- PDU_BIS_US (pdu -> len , lll -> enc , lll -> phy ,
648
- lll -> phy_flags );
689
+ PDU_BIS_US (pdu -> len , (( pdu -> len ) ? lll -> enc : 0U ) ,
690
+ lll -> phy , lll -> phy_flags );
649
691
650
692
radio_tmr_tifs_set (iss_us );
651
693
radio_switch_complete_and_b2b_tx (lll -> phy , lll -> phy_flags ,
0 commit comments