Skip to content

Commit

Permalink
Bluetooth: ISO: add TX timestamping
Browse files Browse the repository at this point in the history
Add BT_SCM_ERROR socket CMSG type.

Support TX timestamping in ISO sockets.

Support MSG_ERRQUEUE in ISO recvmsg.

If a packet from sendmsg() is fragmented, only the first ACL fragment is
timestamped.

Signed-off-by: Pauli Virtanen <pav@iki.fi>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
  • Loading branch information
Pauli Virtanen authored and Luiz Augusto von Dentz committed Mar 25, 2025
1 parent 134f4b3 commit d415ba2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/net/bluetooth/bluetooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ struct bt_voice {
#define BT_PKT_STATUS 16

#define BT_SCM_PKT_STATUS 0x03
#define BT_SCM_ERROR 0x04

#define BT_ISO_QOS 17

Expand Down
24 changes: 20 additions & 4 deletions net/bluetooth/iso.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,8 @@ static struct bt_iso_qos *iso_sock_get_qos(struct sock *sk)
return &iso_pi(sk)->qos;
}

static int iso_send_frame(struct sock *sk, struct sk_buff *skb)
static int iso_send_frame(struct sock *sk, struct sk_buff *skb,
const struct sockcm_cookie *sockc)
{
struct iso_conn *conn = iso_pi(sk)->conn;
struct bt_iso_qos *qos = iso_sock_get_qos(sk);
Expand All @@ -538,10 +539,12 @@ static int iso_send_frame(struct sock *sk, struct sk_buff *skb)
hdr->slen = cpu_to_le16(hci_iso_data_len_pack(len,
HCI_ISO_STATUS_VALID));

if (sk->sk_state == BT_CONNECTED)
if (sk->sk_state == BT_CONNECTED) {
hci_setup_tx_timestamp(skb, 1, sockc);
hci_send_iso(conn->hcon, skb);
else
} else {
len = -ENOTCONN;
}

return len;
}
Expand Down Expand Up @@ -1348,6 +1351,7 @@ static int iso_sock_sendmsg(struct socket *sock, struct msghdr *msg,
{
struct sock *sk = sock->sk;
struct sk_buff *skb, **frag;
struct sockcm_cookie sockc;
size_t mtu;
int err;

Expand All @@ -1360,6 +1364,14 @@ static int iso_sock_sendmsg(struct socket *sock, struct msghdr *msg,
if (msg->msg_flags & MSG_OOB)
return -EOPNOTSUPP;

hci_sockcm_init(&sockc, sk);

if (msg->msg_controllen) {
err = sock_cmsg_send(sk, msg, &sockc);
if (err)
return err;
}

lock_sock(sk);

if (sk->sk_state != BT_CONNECTED) {
Expand Down Expand Up @@ -1405,7 +1417,7 @@ static int iso_sock_sendmsg(struct socket *sock, struct msghdr *msg,
lock_sock(sk);

if (sk->sk_state == BT_CONNECTED)
err = iso_send_frame(sk, skb);
err = iso_send_frame(sk, skb, &sockc);
else
err = -ENOTCONN;

Expand Down Expand Up @@ -1474,6 +1486,10 @@ static int iso_sock_recvmsg(struct socket *sock, struct msghdr *msg,

BT_DBG("sk %p", sk);

if (unlikely(flags & MSG_ERRQUEUE))
return sock_recv_errqueue(sk, msg, len, SOL_BLUETOOTH,
BT_SCM_ERROR);

if (test_and_clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) {
sock_hold(sk);
lock_sock(sk);
Expand Down

0 comments on commit d415ba2

Please sign in to comment.