Skip to content

Commit d415ba2

Browse files
pvVudentz
authored andcommitted
Bluetooth: ISO: add TX timestamping
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>
1 parent 134f4b3 commit d415ba2

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

include/net/bluetooth/bluetooth.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ struct bt_voice {
156156
#define BT_PKT_STATUS 16
157157

158158
#define BT_SCM_PKT_STATUS 0x03
159+
#define BT_SCM_ERROR 0x04
159160

160161
#define BT_ISO_QOS 17
161162

net/bluetooth/iso.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,8 @@ static struct bt_iso_qos *iso_sock_get_qos(struct sock *sk)
518518
return &iso_pi(sk)->qos;
519519
}
520520

521-
static int iso_send_frame(struct sock *sk, struct sk_buff *skb)
521+
static int iso_send_frame(struct sock *sk, struct sk_buff *skb,
522+
const struct sockcm_cookie *sockc)
522523
{
523524
struct iso_conn *conn = iso_pi(sk)->conn;
524525
struct bt_iso_qos *qos = iso_sock_get_qos(sk);
@@ -538,10 +539,12 @@ static int iso_send_frame(struct sock *sk, struct sk_buff *skb)
538539
hdr->slen = cpu_to_le16(hci_iso_data_len_pack(len,
539540
HCI_ISO_STATUS_VALID));
540541

541-
if (sk->sk_state == BT_CONNECTED)
542+
if (sk->sk_state == BT_CONNECTED) {
543+
hci_setup_tx_timestamp(skb, 1, sockc);
542544
hci_send_iso(conn->hcon, skb);
543-
else
545+
} else {
544546
len = -ENOTCONN;
547+
}
545548

546549
return len;
547550
}
@@ -1348,6 +1351,7 @@ static int iso_sock_sendmsg(struct socket *sock, struct msghdr *msg,
13481351
{
13491352
struct sock *sk = sock->sk;
13501353
struct sk_buff *skb, **frag;
1354+
struct sockcm_cookie sockc;
13511355
size_t mtu;
13521356
int err;
13531357

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

1367+
hci_sockcm_init(&sockc, sk);
1368+
1369+
if (msg->msg_controllen) {
1370+
err = sock_cmsg_send(sk, msg, &sockc);
1371+
if (err)
1372+
return err;
1373+
}
1374+
13631375
lock_sock(sk);
13641376

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

14071419
if (sk->sk_state == BT_CONNECTED)
1408-
err = iso_send_frame(sk, skb);
1420+
err = iso_send_frame(sk, skb, &sockc);
14091421
else
14101422
err = -ENOTCONN;
14111423

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

14751487
BT_DBG("sk %p", sk);
14761488

1489+
if (unlikely(flags & MSG_ERRQUEUE))
1490+
return sock_recv_errqueue(sk, msg, len, SOL_BLUETOOTH,
1491+
BT_SCM_ERROR);
1492+
14771493
if (test_and_clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) {
14781494
sock_hold(sk);
14791495
lock_sock(sk);

0 commit comments

Comments
 (0)