@@ -52,6 +52,8 @@ struct tx_meta {
52
52
* continuations).
53
53
*/
54
54
bool is_cont ;
55
+ /* Indicates whether the ISO PDU contains a timestamp */
56
+ bool iso_has_ts ;
55
57
};
56
58
57
59
BUILD_ASSERT (sizeof (struct tx_meta ) == CONFIG_BT_CONN_TX_USER_DATA_SIZE ,
@@ -410,6 +412,24 @@ static struct bt_conn_tx *conn_tx_alloc(void)
410
412
return k_fifo_get (& free_tx , K_FOREVER );
411
413
}
412
414
415
+ int bt_conn_send_iso_cb (struct bt_conn * conn , struct net_buf * buf ,
416
+ bt_conn_tx_cb_t cb , bool has_ts )
417
+ {
418
+ int err = bt_conn_send_cb (conn , buf , cb , NULL );
419
+
420
+ if (err ) {
421
+ return err ;
422
+ }
423
+
424
+ /* Necessary for setting the TS_Flag bit when we pop the buffer from the
425
+ * send queue.
426
+ * Size check for the user_data is already done in `bt_conn_send_cb`.
427
+ */
428
+ tx_data (buf )-> iso_has_ts = has_ts ;
429
+
430
+ return 0 ;
431
+ }
432
+
413
433
int bt_conn_send_cb (struct bt_conn * conn , struct net_buf * buf ,
414
434
bt_conn_tx_cb_t cb , void * user_data )
415
435
{
@@ -419,7 +439,9 @@ int bt_conn_send_cb(struct bt_conn *conn, struct net_buf *buf,
419
439
user_data );
420
440
421
441
if (buf -> user_data_size < CONFIG_BT_CONN_TX_USER_DATA_SIZE ) {
422
- LOG_ERR ("not enough room in user_data" );
442
+ LOG_ERR ("not enough room in user_data %d < %d" ,
443
+ buf -> user_data_size ,
444
+ CONFIG_BT_CONN_TX_USER_DATA_SIZE );
423
445
return - EINVAL ;
424
446
}
425
447
@@ -493,6 +515,7 @@ static int send_acl(struct bt_conn *conn, struct net_buf *buf, uint8_t flags)
493
515
static int send_iso (struct bt_conn * conn , struct net_buf * buf , uint8_t flags )
494
516
{
495
517
struct bt_hci_iso_hdr * hdr ;
518
+ bool ts ;
496
519
497
520
switch (flags ) {
498
521
case FRAG_START :
@@ -512,8 +535,12 @@ static int send_iso(struct bt_conn *conn, struct net_buf *buf, uint8_t flags)
512
535
}
513
536
514
537
hdr = net_buf_push (buf , sizeof (* hdr ));
515
- hdr -> handle = sys_cpu_to_le16 (bt_iso_handle_pack (conn -> handle , flags ,
516
- 0 ));
538
+
539
+ ts = tx_data (buf )-> iso_has_ts &&
540
+ (flags == BT_ISO_START || flags == BT_ISO_SINGLE );
541
+
542
+ hdr -> handle = sys_cpu_to_le16 (bt_iso_handle_pack (conn -> handle , flags , ts ));
543
+
517
544
hdr -> len = sys_cpu_to_le16 (buf -> len - sizeof (* hdr ));
518
545
519
546
bt_buf_set_type (buf , BT_BUF_ISO_OUT );
@@ -621,6 +648,21 @@ static int do_send_frag(struct bt_conn *conn, struct net_buf *buf, uint8_t flags
621
648
return err ;
622
649
}
623
650
651
+ static size_t iso_hdr_len (struct net_buf * buf , struct bt_conn * conn )
652
+ {
653
+ #if defined(CONFIG_BT_ISO )
654
+ if (conn -> type == BT_CONN_TYPE_ISO ) {
655
+ if (tx_data (buf )-> iso_has_ts ) {
656
+ return BT_HCI_ISO_TS_DATA_HDR_SIZE ;
657
+ } else {
658
+ return BT_HCI_ISO_DATA_HDR_SIZE ;
659
+ }
660
+ }
661
+ #endif
662
+
663
+ return 0 ;
664
+ }
665
+
624
666
static int send_frag (struct bt_conn * conn ,
625
667
struct net_buf * buf , struct net_buf * frag ,
626
668
uint8_t flags )
@@ -633,7 +675,9 @@ static int send_frag(struct bt_conn *conn,
633
675
634
676
/* Add the data to the buffer */
635
677
if (frag ) {
636
- uint16_t frag_len = MIN (conn_mtu (conn ), net_buf_tailroom (frag ));
678
+ size_t iso_hdr = flags == FRAG_START ? iso_hdr_len (buf , conn ) : 0 ;
679
+ uint16_t frag_len = MIN (conn_mtu (conn ) + iso_hdr ,
680
+ net_buf_tailroom (frag ));
637
681
638
682
net_buf_add_mem (frag , buf -> data , frag_len );
639
683
net_buf_pull (buf , frag_len );
@@ -681,6 +725,11 @@ static struct net_buf *create_frag(struct bt_conn *conn, struct net_buf *buf)
681
725
return frag ;
682
726
}
683
727
728
+ static bool fits_single_ctlr_buf (struct net_buf * buf , struct bt_conn * conn )
729
+ {
730
+ return buf -> len - iso_hdr_len (buf , conn ) <= conn_mtu (conn );
731
+ }
732
+
684
733
static int send_buf (struct bt_conn * conn , struct net_buf * buf )
685
734
{
686
735
struct net_buf * frag ;
@@ -690,7 +739,7 @@ static int send_buf(struct bt_conn *conn, struct net_buf *buf)
690
739
LOG_DBG ("conn %p buf %p len %u" , conn , buf , buf -> len );
691
740
692
741
/* Send directly if the packet fits the ACL MTU */
693
- if (buf -> len <= conn_mtu ( conn ) && !tx_data (buf )-> is_cont ) {
742
+ if (fits_single_ctlr_buf ( buf , conn ) && !tx_data (buf )-> is_cont ) {
694
743
LOG_DBG ("send single" );
695
744
return send_frag (conn , buf , NULL , FRAG_SINGLE );
696
745
}
0 commit comments