Skip to content

Commit 90b5426

Browse files
Vudentzintel-lab-lkp
authored andcommitted
Bluetooth: Add support for logging host packets into monitor
This adds support for logging host (enqueued/dequeued) packets so their timing is visible in the logs: l2cap-tester[41]: < HOST Data TX: len 12 [hci0] 15:50:02.974141 l2cap-tester[41]: < ACL Data T.. flags 0x00 dlen 12 torvalds#83 [hci0] 15:50:02.974199 Channel: 64 len 8 [PSM 4097 mode Basic (0x00)] {chan 0} 01 02 03 04 05 06 07 08 ........ > ACL Data RX: Handle 42 flags 0x02 dlen 12 torvalds#170 [hci0] 15:51:43.269961 Channel: 64 len 8 [PSM 4097 mode Basic (0x00)] {chan 0} 01 02 03 04 05 06 07 08 ........ [45]: > HOST Data RX: len 8 [hci0] 15:51:43.269976 Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 9c53399 commit 90b5426

File tree

10 files changed

+54
-1
lines changed

10 files changed

+54
-1
lines changed

include/net/bluetooth/bluetooth.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,8 @@ void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status,
459459
int hci_ethtool_ts_info(unsigned int index, int sk_proto,
460460
struct kernel_ethtool_ts_info *ts_info);
461461

462+
void hci_sock_copy_creds(struct sock *sk, struct sk_buff *skb);
463+
462464
#define HCI_REQ_START BIT(0)
463465
#define HCI_REQ_SKB BIT(1)
464466

include/net/bluetooth/hci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ enum {
497497
#define HCI_ISODATA_PKT 0x05
498498
#define HCI_DIAG_PKT 0xf0
499499
#define HCI_DRV_PKT 0xf1
500+
#define HCI_HOST_PKT 0xf2
500501
#define HCI_VENDOR_PKT 0xff
501502

502503
/* HCI packet types */

include/net/bluetooth/hci_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,6 +2248,7 @@ int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen,
22482248
void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags);
22492249
void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
22502250
void hci_send_iso(struct hci_conn *conn, struct sk_buff *skb);
2251+
void hci_send_host(struct hci_dev *hdev, struct sk_buff *skb);
22512252

22522253
void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);
22532254
void *hci_recv_event_data(struct hci_dev *hdev, __u8 event);

include/net/bluetooth/hci_mon.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ struct hci_mon_hdr {
5353
#define HCI_MON_ISO_RX_PKT 19
5454
#define HCI_MON_DRV_TX_PKT 20
5555
#define HCI_MON_DRV_RX_PKT 21
56+
#define HCI_MON_SOCK_TX_PKT 22
57+
#define HCI_MON_SOCK_RX_PKT 23
5658

5759
struct hci_mon_new_index {
5860
__u8 type;

net/bluetooth/hci_core.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3269,12 +3269,26 @@ static void hci_queue_acl(struct hci_chan *chan, struct sk_buff_head *queue,
32693269
}
32703270
}
32713271

3272+
void hci_send_host(struct hci_dev *hdev, struct sk_buff *skb)
3273+
{
3274+
/* Mark as socket packet */
3275+
hci_skb_pkt_type(skb) = HCI_HOST_PKT;
3276+
3277+
/* Time stamp */
3278+
__net_timestamp(skb);
3279+
3280+
/* Send copy to monitor */
3281+
hci_send_to_monitor(hdev, skb);
3282+
}
3283+
32723284
void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags)
32733285
{
32743286
struct hci_dev *hdev = chan->conn->hdev;
32753287

32763288
BT_DBG("%s chan %p flags 0x%4.4x", hdev->name, chan, flags);
32773289

3290+
hci_send_host(hdev, skb);
3291+
32783292
hci_queue_acl(chan, &chan->data_q, skb, flags);
32793293

32803294
queue_work(hdev->workqueue, &hdev->tx_work);
@@ -3288,6 +3302,8 @@ void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb)
32883302

32893303
BT_DBG("%s len %d", hdev->name, skb->len);
32903304

3305+
hci_send_host(hdev, skb);
3306+
32913307
hdr.handle = cpu_to_le16(conn->handle);
32923308
hdr.dlen = skb->len;
32933309

@@ -3365,6 +3381,8 @@ void hci_send_iso(struct hci_conn *conn, struct sk_buff *skb)
33653381

33663382
BT_DBG("%s len %d", hdev->name, skb->len);
33673383

3384+
hci_send_host(hdev, skb);
3385+
33683386
hci_queue_iso(conn, &conn->data_q, skb);
33693387

33703388
queue_work(hdev->workqueue, &hdev->tx_work);

net/bluetooth/hci_sock.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb)
265265
kfree_skb(skb_copy);
266266
}
267267

268-
static void hci_sock_copy_creds(struct sock *sk, struct sk_buff *skb)
268+
void hci_sock_copy_creds(struct sock *sk, struct sk_buff *skb)
269269
{
270270
struct scm_creds *creds;
271271

@@ -398,6 +398,12 @@ void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb)
398398
else
399399
opcode = cpu_to_le16(HCI_MON_DRV_TX_PKT);
400400
break;
401+
case HCI_HOST_PKT:
402+
if (bt_cb(skb)->incoming)
403+
opcode = cpu_to_le16(HCI_MON_SOCK_RX_PKT);
404+
else
405+
opcode = cpu_to_le16(HCI_MON_SOCK_TX_PKT);
406+
break;
401407
case HCI_DIAG_PKT:
402408
opcode = cpu_to_le16(HCI_MON_VENDOR_DIAG);
403409
break;

net/bluetooth/iso.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,13 @@ static void iso_recv_frame(struct iso_conn *conn, struct sk_buff *skb)
569569
if (sk->sk_state != BT_CONNECTED)
570570
goto drop;
571571

572+
/* Copy pid information since the skb was not allocated using the sk as
573+
* source, otherwise tools cannot decode the process that is receiving
574+
* the packet.
575+
*/
576+
hci_sock_copy_creds(sk, skb);
577+
hci_send_host(conn->hcon->hdev, skb);
578+
572579
if (!sock_queue_rcv_skb(sk, skb))
573580
return;
574581

net/bluetooth/l2cap_core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7440,6 +7440,8 @@ static int l2cap_recv_frag(struct l2cap_conn *conn, struct sk_buff *skb,
74407440
return -ENOMEM;
74417441
/* Init rx_len */
74427442
conn->rx_len = len;
7443+
/* Set rx_skb as incoming so it can be properly decoded */
7444+
bt_cb(conn->rx_skb)->incoming = 1;
74437445

74447446
skb_set_delivery_time(conn->rx_skb, skb->tstamp,
74457447
skb->tstamp_type);

net/bluetooth/l2cap_sock.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,13 @@ static int l2cap_sock_recv_cb(struct l2cap_chan *chan, struct sk_buff *skb)
15261526
goto done;
15271527
}
15281528

1529+
/* Copy pid information since the skb was not allocated using the sk as
1530+
* source, otherwise tools cannot decode the process that is receiving
1531+
* the packet.
1532+
*/
1533+
hci_sock_copy_creds(sk, skb);
1534+
hci_send_host(chan->conn->hcon->hdev, skb);
1535+
15291536
err = __sock_queue_rcv_skb(sk, skb);
15301537

15311538
l2cap_publish_rx_avail(chan);

net/bluetooth/sco.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,13 @@ static void sco_recv_frame(struct sco_conn *conn, struct sk_buff *skb)
412412
if (sk->sk_state != BT_CONNECTED)
413413
goto drop;
414414

415+
/* Copy pid information since the skb was not allocated using the sk as
416+
* source, otherwise tools cannot decode the process that is receiving
417+
* the packet.
418+
*/
419+
hci_sock_copy_creds(sk, skb);
420+
hci_send_host(conn->hcon->hdev, skb);
421+
415422
if (!sock_queue_rcv_skb(sk, skb))
416423
return;
417424

0 commit comments

Comments
 (0)