From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v2 10/12] monitor: Add connection lifecycle to analyze summary
Date: Fri, 20 Feb 2026 12:31:14 -0500 [thread overview]
Message-ID: <20260220173120.3418666-10-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20260220173120.3418666-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Record the frame number at connection and disconnection time for each
connection. Print the connected and disconnected frame numbers in the
per-connection summary produced by analyze mode so that users can
cross-reference with the btmon trace output:
Found LE-ACL connection with handle 2051
Address: 66:B0:26:F1:D3:BC (Resolvable)
RX packets: 48/48
RX Latency: 1-7604 msec (~74 msec)
RX size: 5-51 octets (~13 octets)
RX speed: ~0 Kb/s
TX packets: 39/37
TX Latency: 12-426 msec (~43 msec)
TX size: 5-97 octets (~15 octets)
TX speed: ~1 Kb/s
Connected: #52044
Disconnected: #53069
Disconnect Reason: 0x08
Also fix the TODO in conn_destroy() that was passing a hardcoded 0x00
address type by using the stored bdaddr_type from the LE connection
complete events.
---
monitor/analyze.c | 73 ++++++++++++++++++++++++++++++++++++++---------
1 file changed, 59 insertions(+), 14 deletions(-)
diff --git a/monitor/analyze.c b/monitor/analyze.c
index 2cf42f903b61..1db1e7898132 100644
--- a/monitor/analyze.c
+++ b/monitor/analyze.c
@@ -68,8 +68,12 @@ struct hci_conn {
uint16_t link;
uint8_t type;
uint8_t bdaddr[6];
+ uint8_t bdaddr_type;
bool setup_seen;
bool terminated;
+ uint8_t disconnect_reason;
+ unsigned long frame_connected;
+ unsigned long frame_disconnected;
struct queue *tx_queue;
struct timeval last_rx;
struct queue *chan_list;
@@ -241,13 +245,22 @@ static void conn_destroy(void *data)
}
printf(" Found %s connection with handle %u\n", str, conn->handle);
- /* TODO: Store address type */
- packet_print_addr("Address", conn->bdaddr, 0x00);
+ packet_print_addr("Address", conn->bdaddr, conn->bdaddr_type);
if (!conn->setup_seen)
print_field("Connection setup missing");
print_stats(&conn->rx, "RX");
print_stats(&conn->tx, "TX");
+ if (conn->setup_seen) {
+ print_field("Connected: #%lu", conn->frame_connected);
+ if (conn->terminated) {
+ print_field("Disconnected: #%lu",
+ conn->frame_disconnected);
+ print_field("Disconnect Reason: 0x%02x",
+ conn->disconnect_reason);
+ }
+ }
+
queue_destroy(conn->rx.plot, free);
queue_destroy(conn->tx.plot, free);
queue_destroy(conn->chan_list, chan_destroy);
@@ -465,6 +478,7 @@ static void command_pkt(struct timeval *tv, uint16_t index,
}
static void evt_conn_complete(struct hci_dev *dev, struct timeval *tv,
+ unsigned long frame,
const void *data, uint16_t size)
{
const struct bt_hci_evt_conn_complete *evt = data;
@@ -478,10 +492,12 @@ static void evt_conn_complete(struct hci_dev *dev, struct timeval *tv,
return;
memcpy(conn->bdaddr, evt->bdaddr, 6);
+ conn->frame_connected = frame;
conn->setup_seen = true;
}
static void evt_disconnect_complete(struct hci_dev *dev, struct timeval *tv,
+ unsigned long frame,
const void *data, uint16_t size)
{
const struct bt_hci_evt_disconnect_complete *evt = data;
@@ -494,6 +510,8 @@ static void evt_disconnect_complete(struct hci_dev *dev, struct timeval *tv,
if (!conn)
return;
+ conn->frame_disconnected = frame;
+ conn->disconnect_reason = evt->reason;
conn->terminated = true;
}
@@ -555,6 +573,7 @@ static void plot_add(struct queue *queue, struct timeval *latency,
}
static void evt_le_conn_complete(struct hci_dev *dev, struct timeval *tv,
+ unsigned long frame,
struct iovec *iov)
{
const struct bt_hci_evt_le_conn_complete *evt;
@@ -569,10 +588,13 @@ static void evt_le_conn_complete(struct hci_dev *dev, struct timeval *tv,
return;
memcpy(conn->bdaddr, evt->peer_addr, 6);
+ conn->bdaddr_type = evt->peer_addr_type;
+ conn->frame_connected = frame;
conn->setup_seen = true;
}
static void evt_le_enh_conn_complete(struct hci_dev *dev, struct timeval *tv,
+ unsigned long frame,
struct iovec *iov)
{
const struct bt_hci_evt_le_enhanced_conn_complete *evt;
@@ -587,6 +609,8 @@ static void evt_le_enh_conn_complete(struct hci_dev *dev, struct timeval *tv,
return;
memcpy(conn->bdaddr, evt->peer_addr, 6);
+ conn->bdaddr_type = evt->peer_addr_type;
+ conn->frame_connected = frame;
conn->setup_seen = true;
}
@@ -640,6 +664,7 @@ static void evt_num_completed_packets(struct hci_dev *dev, struct timeval *tv,
}
static void evt_sync_conn_complete(struct hci_dev *dev, struct timeval *tv,
+ unsigned long frame,
const void *data, uint16_t size)
{
const struct bt_hci_evt_sync_conn_complete *evt = data;
@@ -653,10 +678,12 @@ static void evt_sync_conn_complete(struct hci_dev *dev, struct timeval *tv,
return;
memcpy(conn->bdaddr, evt->bdaddr, 6);
+ conn->frame_connected = frame;
conn->setup_seen = true;
}
static void evt_le_cis_established(struct hci_dev *dev, struct timeval *tv,
+ unsigned long frame,
struct iovec *iov)
{
const struct bt_hci_evt_le_cis_established *evt;
@@ -671,6 +698,7 @@ static void evt_le_cis_established(struct hci_dev *dev, struct timeval *tv,
if (!conn)
return;
+ conn->frame_connected = frame;
conn->setup_seen = true;
link = link_lookup(dev, conn->handle);
@@ -696,6 +724,7 @@ static void evt_le_cis_req(struct hci_dev *dev, struct timeval *tv,
}
static void evt_le_big_complete(struct hci_dev *dev, struct timeval *tv,
+ unsigned long frame,
struct iovec *iov)
{
const struct bt_hci_evt_le_big_complete *evt;
@@ -713,12 +742,15 @@ static void evt_le_big_complete(struct hci_dev *dev, struct timeval *tv,
return;
conn = conn_lookup_type(dev, handle, BTMON_CONN_BIS);
- if (conn)
+ if (conn) {
conn->setup_seen = true;
+ conn->frame_connected = frame;
+ }
}
}
static void evt_le_big_sync_established(struct hci_dev *dev, struct timeval *tv,
+ unsigned long frame,
struct iovec *iov)
{
const struct bt_hci_evt_le_big_sync_estabilished *evt;
@@ -736,12 +768,15 @@ static void evt_le_big_sync_established(struct hci_dev *dev, struct timeval *tv,
return;
conn = conn_lookup_type(dev, handle, BTMON_CONN_BIS);
- if (conn)
+ if (conn) {
conn->setup_seen = true;
+ conn->frame_connected = frame;
+ }
}
}
static void evt_le_meta_event(struct hci_dev *dev, struct timeval *tv,
+ unsigned long frame,
const void *data, uint16_t size)
{
struct iovec iov = {
@@ -755,27 +790,28 @@ static void evt_le_meta_event(struct hci_dev *dev, struct timeval *tv,
switch (subevt) {
case BT_HCI_EVT_LE_CONN_COMPLETE:
- evt_le_conn_complete(dev, tv, &iov);
+ evt_le_conn_complete(dev, tv, frame, &iov);
break;
case BT_HCI_EVT_LE_ENHANCED_CONN_COMPLETE:
- evt_le_enh_conn_complete(dev, tv, &iov);
+ evt_le_enh_conn_complete(dev, tv, frame, &iov);
break;
case BT_HCI_EVT_LE_CIS_ESTABLISHED:
- evt_le_cis_established(dev, tv, &iov);
+ evt_le_cis_established(dev, tv, frame, &iov);
break;
case BT_HCI_EVT_LE_CIS_REQ:
evt_le_cis_req(dev, tv, &iov);
break;
case BT_HCI_EVT_LE_BIG_COMPLETE:
- evt_le_big_complete(dev, tv, &iov);
+ evt_le_big_complete(dev, tv, frame, &iov);
break;
case BT_HCI_EVT_LE_BIG_SYNC_ESTABILISHED:
- evt_le_big_sync_established(dev, tv, &iov);
+ evt_le_big_sync_established(dev, tv, frame, &iov);
break;
}
}
static void event_pkt(struct timeval *tv, uint16_t index,
+ unsigned long frame,
const void *data, uint16_t size)
{
const struct bt_hci_evt_hdr *hdr = data;
@@ -793,10 +829,10 @@ static void event_pkt(struct timeval *tv, uint16_t index,
switch (hdr->evt) {
case BT_HCI_EVT_CONN_COMPLETE:
- evt_conn_complete(dev, tv, data, size);
+ evt_conn_complete(dev, tv, frame, data, size);
break;
case BT_HCI_EVT_DISCONNECT_COMPLETE:
- evt_disconnect_complete(dev, tv, data, size);
+ evt_disconnect_complete(dev, tv, frame, data, size);
break;
case BT_HCI_EVT_CMD_COMPLETE:
evt_cmd_complete(dev, tv, data, size);
@@ -805,10 +841,10 @@ static void event_pkt(struct timeval *tv, uint16_t index,
evt_num_completed_packets(dev, tv, data, size);
break;
case BT_HCI_EVT_SYNC_CONN_COMPLETE:
- evt_sync_conn_complete(dev, tv, data, size);
+ evt_sync_conn_complete(dev, tv, frame, data, size);
break;
case BT_HCI_EVT_LE_META_EVENT:
- evt_le_meta_event(dev, tv, data, size);
+ evt_le_meta_event(dev, tv, frame, data, size);
break;
}
}
@@ -1047,6 +1083,7 @@ void analyze_trace(const char *path)
{
struct btsnoop *btsnoop_file;
unsigned long num_packets = 0;
+ unsigned long num_frames = 0;
uint32_t format;
btsnoop_file = btsnoop_open(path, BTSNOOP_FLAG_PKLG_SUPPORT);
@@ -1084,21 +1121,27 @@ void analyze_trace(const char *path)
del_index(&tv, index, buf, pktlen);
break;
case BTSNOOP_OPCODE_COMMAND_PKT:
+ num_frames++;
command_pkt(&tv, index, buf, pktlen);
break;
case BTSNOOP_OPCODE_EVENT_PKT:
- event_pkt(&tv, index, buf, pktlen);
+ num_frames++;
+ event_pkt(&tv, index, num_frames, buf, pktlen);
break;
case BTSNOOP_OPCODE_ACL_TX_PKT:
+ num_frames++;
acl_pkt(&tv, index, true, buf, pktlen);
break;
case BTSNOOP_OPCODE_ACL_RX_PKT:
+ num_frames++;
acl_pkt(&tv, index, false, buf, pktlen);
break;
case BTSNOOP_OPCODE_SCO_TX_PKT:
+ num_frames++;
sco_pkt(&tv, index, true, buf, pktlen);
break;
case BTSNOOP_OPCODE_SCO_RX_PKT:
+ num_frames++;
sco_pkt(&tv, index, false, buf, pktlen);
break;
case BTSNOOP_OPCODE_OPEN_INDEX:
@@ -1123,9 +1166,11 @@ void analyze_trace(const char *path)
ctrl_msg(&tv, index, buf, pktlen);
break;
case BTSNOOP_OPCODE_ISO_TX_PKT:
+ num_frames++;
iso_pkt(&tv, index, true, buf, pktlen);
break;
case BTSNOOP_OPCODE_ISO_RX_PKT:
+ num_frames++;
iso_pkt(&tv, index, false, buf, pktlen);
break;
default:
--
2.52.0
next prev parent reply other threads:[~2026-02-20 17:31 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-20 17:31 [PATCH BlueZ v2 01/12] doc/btmon: Add missing documentation Luiz Augusto von Dentz
2026-02-20 17:31 ` [PATCH BlueZ v2 02/12] doc/btmon: Add dedicate sections for timestamp and frame number Luiz Augusto von Dentz
2026-02-20 17:31 ` [PATCH BlueZ v2 03/12] doc/btmon: Add connection tracking section Luiz Augusto von Dentz
2026-02-20 17:31 ` [PATCH BlueZ v2 04/12] doc/btmon: Add a dedicated section for analyze mode Luiz Augusto von Dentz
2026-02-20 17:31 ` [PATCH BlueZ v2 05/12] doc/btmon: Add a section for automated trace analysis Luiz Augusto von Dentz
2026-02-20 17:31 ` [PATCH BlueZ v2 06/12] doc: add btsnoop protocol manpage Luiz Augusto von Dentz
2026-02-20 17:31 ` [PATCH BlueZ v2 07/12] doc/btmon: Add reference to btsnoop documention Luiz Augusto von Dentz
2026-02-20 17:31 ` [PATCH BlueZ v2 08/12] monitor: Annotate ACL/SCO/ISO data with device address Luiz Augusto von Dentz
2026-02-20 17:31 ` [PATCH BlueZ v2 09/12] monitor: Print connection type in Disconnect Complete Luiz Augusto von Dentz
2026-02-20 17:31 ` Luiz Augusto von Dentz [this message]
2026-02-20 17:31 ` [PATCH BlueZ v2 11/12] monitor: Prefix data packets with proper type Luiz Augusto von Dentz
2026-02-20 17:31 ` [PATCH BlueZ v2 12/12] doc/btmon: Update documentation to reflect lastest changes Luiz Augusto von Dentz
2026-02-20 18:25 ` [BlueZ,v2,01/12] doc/btmon: Add missing documentation bluez.test.bot
2026-02-20 20:20 ` [PATCH BlueZ v2 01/12] " patchwork-bot+bluetooth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260220173120.3418666-10-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox