Skip to contentSkip to conversation

monitor: Add AD/EIR types for mesh

PATCH Superseded Luiz Augusto von Dentz 2 participants 16 messages Jul 18, 2017 – Jul 19, 2017 Bluetooth drivers

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/7 monitor: Add AD/EIR types for mesh

From: Luiz Augusto von Dentz <[email protected]>

Print out mesh type and payload:

Quoted 1 line

HCI Event: LE Meta Event (0x3e) plen 33

      LE Advertising Report (0x02)
        Num reports: 1
        Event type: Non connectable undirected - ADV_NONCONN_IND (0x03)
        Address type: Random (0x01)
        Address: 29:D0:F2:61:17:B0 (Non-Resolvable)
        Data length: 21
        Mesh Data: 59a7ddee2e1f580463521b98c40c2a3b5086c6
        RSSI: -72 dBm (0xb8)
---
 monitor/packet.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
monitor/packet.c +15 -0
index a3d188a..cc24165 100644
@@ -3259,6 +3259,9 @@ static void print_fec(uint8_t fec)
 #define BT_EIR_TRANSPORT_DISCOVERY	0x26
 #define BT_EIR_LE_SUPPORTED_FEATURES	0x27
 #define BT_EIR_CHANNEL_MAP_UPDATE_IND	0x28
+#define BT_EIR_MESH_DATA		0x29
+#define BT_EIR_MESH_PROV		0x2a
+#define BT_EIR_MESH_BEACON		0x2b
 #define BT_EIR_3D_INFO_DATA		0x3d
 #define BT_EIR_MANUFACTURER_DATA	0xff
 
@@ -3720,6 +3723,18 @@ static void print_eir(const uint8_t *eir, uint8_t eir_len, bool le)
 			print_field("  Path Loss Threshold: %d", data[1]);
 			break;
 
+		case BT_EIR_MESH_DATA:
+			print_hex_field("Mesh Data", data, data_len);
+			break;
+
+		case BT_EIR_MESH_PROV:
+			print_hex_field("Mesh Provisioning", data, data_len);
+			break;
+
+		case BT_EIR_MESH_BEACON:
+			print_hex_field("Mesh Beacon", data, data_len);
+			break;
+
 		case BT_EIR_MANUFACTURER_DATA:
 			if (data_len < 2)
 				break;
Signature · 1 line
2.9.4
author maintainer
#1 lore raw

PATCH 2/7 monitor: Add decoding of GATT Mesh Services

From: Luiz Augusto von Dentz <[email protected]>

This adds UUIDs of GATT Mesh Provisioning Service and Mesh Proxy Service.

---
 monitor/uuid.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
monitor/uuid.c +7 -1
index fb0b210..9839d03 100644
@@ -170,7 +170,9 @@ static const struct {
 	{ 0x1824, "Transport Discovery"				},
 	{ 0x1825, "Object Transfer"				},
 	{ 0x1826, "Fitness Machine"				},
-	/* 0x1827 to 0x27ff undefined */
+	{ 0x1827, "Mesh Provisioning"				},
+	{ 0x1828, "Mesh Proxy"					},
+	/* 0x1829 to 0x27ff undefined */
 	{ 0x2800, "Primary Service"				},
 	{ 0x2801, "Secondary Service"				},
 	{ 0x2802, "Include"					},
@@ -397,6 +399,10 @@ static const struct {
 	{ 0x2ad8, "Supported Power Range"			},
 	{ 0x2ad9, "Fitness Machine Control Point"		},
 	{ 0x2ada, "Fitness Machine Status"			},
+	{ 0x2adb, "Mesh Provisioning Data In"			},
+	{ 0x2adc, "Mesh Provisioning Data Out"			},
+	{ 0x2add, "Mesh Proxy Data In"				},
+	{ 0x2ade, "Mesh Proxy Data Out"				},
 	/* vendor defined */
 	{ 0xfeff, "GN Netcom"					},
 	{ 0xfefe, "GN ReSound A/S"				},
Signature · 1 line
2.9.4
author maintainer
#2 lore raw

PATCH 3/7 monitor: Filter duplicated advertisements

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This reduces the verbosity and give a precise picture of how unique each report is.

---
 monitor/intel.c  |  28 +++---
 monitor/packet.c | 277 ++++++++++++++++++++++++++++++++++++-------------------
 monitor/vendor.h |   2 +-
 3 files changed, 198 insertions(+), 109 deletions(-)
monitor/intel.c +14 -14
index 1ca9a95..9da188a 100644
@@ -499,11 +499,11 @@ const struct vendor_ocf *intel_vendor_ocf(uint16_t ocf)
 	return NULL;
 }
 
-static void startup_evt(const void *data, uint8_t size)
+static void startup_evt(uint8_t index, const void *data, uint8_t size)
 {
 }
 
-static void fatal_exception_evt(const void *data, uint8_t size)
+static void fatal_exception_evt(uint8_t index, const void *data, uint8_t size)
 {
 	uint16_t line = get_le16(data);
 	uint8_t module = get_u8(data + 2);
@@ -514,7 +514,7 @@ static void fatal_exception_evt(const void *data, uint8_t size)
 	print_field("Reason: 0x%2.2x", reason);
 }
 
-static void bootup_evt(const void *data, uint8_t size)
+static void bootup_evt(uint8_t index, const void *data, uint8_t size)
 {
 	uint8_t zero = get_u8(data);
 	uint8_t num_packets = get_u8(data + 1);
@@ -617,7 +617,7 @@ static void bootup_evt(const void *data, uint8_t size)
 	print_field("DDC status: %s (0x%2.2x)", str, ddc_status);
 }
 
-static void default_bd_data_evt(const void *data, uint8_t size)
+static void default_bd_data_evt(uint8_t index, const void *data, uint8_t size)
 {
 	uint8_t mem_status = get_u8(data);
 	const char *str;
@@ -634,7 +634,7 @@ static void default_bd_data_evt(const void *data, uint8_t size)
 	print_field("Memory status: %s (0x%2.2x)", str, mem_status);
 }
 
-static void secure_send_commands_result_evt(const void *data, uint8_t size)
+static void secure_send_commands_result_evt(uint8_t index, const void *data, uint8_t size)
 {
 	uint8_t result = get_u8(data);
 	uint16_t opcode = get_le16(data + 1);
@@ -678,7 +678,7 @@ static void secure_send_commands_result_evt(const void *data, uint8_t size)
 	print_status(status);
 }
 
-static void debug_exception_evt(const void *data, uint8_t size)
+static void debug_exception_evt(uint8_t index, const void *data, uint8_t size)
 {
 	uint16_t line = get_le16(data);
 	uint8_t module = get_u8(data + 2);
@@ -689,7 +689,7 @@ static void debug_exception_evt(const void *data, uint8_t size)
 	print_field("Reason: 0x%2.2x", reason);
 }
 
-static void le_link_established_evt(const void *data, uint8_t size)
+static void le_link_established_evt(uint8_t index, const void *data, uint8_t size)
 {
 	uint16_t handle = get_le16(data);
 	uint32_t access_addr = get_le32(data + 10);
@@ -703,7 +703,7 @@ static void le_link_established_evt(const void *data, uint8_t size)
 	packet_hexdump(data + 14, size - 14);
 }
 
-static void scan_status_evt(const void *data, uint8_t size)
+static void scan_status_evt(uint8_t index, const void *data, uint8_t size)
 {
 	uint8_t enable = get_u8(data);
 
@@ -718,14 +718,14 @@ static void scan_status_evt(const void *data, uint8_t size)
 
 }
 
-static void act_deact_traces_complete_evt(const void *data, uint8_t size)
+static void act_deact_traces_complete_evt(uint8_t index, const void *data, uint8_t size)
 {
 	uint8_t status = get_u8(data);
 
 	print_status(status);
 }
 
-static void lmp_pdu_trace_evt(const void *data, uint8_t size)
+static void lmp_pdu_trace_evt(uint8_t index, const void *data, uint8_t size)
 {
 	uint8_t type, len, id;
 	uint16_t handle, count;
@@ -819,14 +819,14 @@ static void lmp_pdu_trace_evt(const void *data, uint8_t size)
 	}
 }
 
-static void write_bd_data_complete_evt(const void *data, uint8_t size)
+static void write_bd_data_complete_evt(uint8_t index, const void *data, uint8_t size)
 {
 	uint8_t status = get_u8(data);
 
 	print_status(status);
 }
 
-static void sco_rejected_via_lmp_evt(const void *data, uint8_t size)
+static void sco_rejected_via_lmp_evt(uint8_t index, const void *data, uint8_t size)
 {
 	uint8_t reason = get_u8(data + 6);
 
@@ -834,7 +834,7 @@ static void sco_rejected_via_lmp_evt(const void *data, uint8_t size)
 	packet_print_error("Reason", reason);
 }
 
-static void ptt_switch_notification_evt(const void *data, uint8_t size)
+static void ptt_switch_notification_evt(uint8_t index, const void *data, uint8_t size)
 {
 	uint16_t handle = get_le16(data);
 	uint8_t table = get_u8(data + 2);
@@ -857,7 +857,7 @@ static void ptt_switch_notification_evt(const void *data, uint8_t size)
 	print_field("Packet type table: %s (0x%2.2x)", str, table);
 }
 
-static void system_exception_evt(const void *data, uint8_t size)
+static void system_exception_evt(uint8_t index, const void *data, uint8_t size)
 {
 	uint8_t type = get_u8(data);
 	const char *str;
monitor/packet.c +183 -94

866 lines not on this page · raw message

monitor/vendor.h +1 -1
index f5792b3..fee1353 100644
@@ -38,7 +38,7 @@ struct vendor_ocf {
 struct vendor_evt {
 	uint8_t evt;
 	const char *str;
-	void (*evt_func) (const void *data, uint8_t size);
+	void (*evt_func) (uint8_t index, const void *data, uint8_t size);
 	uint8_t evt_size;
 	bool evt_fixed;
 };
Signature · 1 line
2.9.4
author maintainer
#7 lore raw

PATCH 4/7 monitor: Add basic decoding for Mesh Beacon

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds basic decoding for Mesh Beacon packets such as:

Quoted 1 line

HCI Event: LE Meta Event (0x3e) plen 37

      LE Advertising Report (0x02)
        Num reports: 1
        Event type: Non connectable undirected - ADV_NONCONN_IND (0x03)
        Address type: Random (0x01)
        Address: 36:47:34:FC:63:DA (Non-Resolvable)
        Data length: 25
        Mesh Beacon: 00dddd0000000000000000000000000000000000000000
          Unprovisioned Device Beacon (0x00)
          Device UUID: 00dddd00000000000000000000000000
          OOB Information: 0x0000
          URI Hash: 0x0000
        RSSI: -28 dBm (0xe4)

< HCI Command: LE Set Advertising Data (0x08|0x0008) plen 32

        Length: 24
        Mesh Beacon: 0100c7005d732329eadf000000003e60e50797ef6d5c
          Secure Network Beacon (0x01)
          Flags: 0x01
          Network Id: 00c7005d732329ea
          IV Index: 0xdf000000
          Authentication Value: 003e60e50797ef6d
---
 monitor/packet.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
monitor/packet.c +69 -0
index 1ec816c..3e6382e 100644
@@ -3513,6 +3513,74 @@ static const struct {
 	{ }
 };
 
+static const struct {
+	uint8_t bit;
+	const char *str;
+} mesh_oob_table[] = {
+	{ 0, "Other"							},
+	{ 1, "Eletronic / URI"						},
+	{ 2, "2D machine-readable code"					},
+	{ 3, "Bar code"							},
+	{ 4, "Near Field Communication (NFC)"				},
+	{ 5, "Number"							},
+	{ 6, "String"							},
+	{ 11, "On box"							},
+	{ 12, "Inside box"						},
+	{ 13, "On piece of paper"					},
+	{ 14, "Inside manual"						},
+	{ 14, "On Device"						},
+	{ }
+};
+
+static void print_mesh_beacon(const uint8_t *data, uint8_t len)
+{
+	int i;
+	uint16_t oob;
+
+	if (len < 1)
+		return;
+
+	switch (data[0]) {
+	case 0x00:
+		print_field("  Unprovisioned Device Beacon (0x00)");
+		if (len < 18)
+			break;
+
+		print_hex_field("  Device UUID", data, 16);
+
+		oob = get_be16(&data[16]);
+		print_field("  OOB Information: 0x%4.4x", oob);
+
+		for (i = 0; mesh_oob_table[i].str; i++) {
+			if (oob & (1 << mesh_oob_table[i].bit))
+				print_field("    %s", mesh_oob_table[i].str);
+		}
+
+		if (len < 22)
+			break;
+
+		print_field("  URI Hash: 0x%4.4x", get_be32(&data[18]));
+		break;
+	case 0x01:
+		print_field("  Secure Network Beacon (0x01)");
+		if (len < 21)
+			break;
+
+		print_field("  Flags: 0x%2.2x", data[0]);
+
+		if (data[0] & 0x01)
+			print_field("    Key Refresh");
+
+		if (data[0] & 0x02)
+			print_field("    IV Update");
+
+		print_hex_field("  Network Id", &data[1], 8);
+		print_field("  IV Index: 0x%08x", get_be32(&data[9]));
+		print_hex_field("  Authentication Value", &data[13], 8);
+		break;
+	}
+}
+
 static void print_eir(const uint8_t *eir, uint8_t eir_len, bool le)
 {
 	uint16_t len = 0;
@@ -3747,6 +3815,7 @@ static void print_eir(const uint8_t *eir, uint8_t eir_len, bool le)
 
 		case BT_EIR_MESH_BEACON:
 			print_hex_field("Mesh Beacon", data, data_len);
+			print_mesh_beacon(data, data_len);
 			break;
 
 		case BT_EIR_MANUFACTURER_DATA:
Signature · 1 line
2.9.4
author maintainer
#10 lore raw

PATCH 5/7 monitor: Add basic decoding for Mesh Provisioning

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds basic decoding for Mesh Provisioning packets such as:

< HCI Command: LE Set Advertising Data (0x08|0x0008) plen 32

        Length: 24
        Mesh Provision: 024874cb0003dddd0000000000000000000000000000
          Link ID: 0x024874cb
          Transaction Number: 0
          Provisioning Bearer Control (0x03)
          Link Open (0x00)
          Device UUID: 03dddd00000000000000000000000000
Quoted 1 line

HCI Event: LE Meta Event (0x3e) plen 20

      LE Advertising Report (0x02)
        Num reports: 1
        Event type: Non connectable undirected - ADV_NONCONN_IND (0x03)
        Address type: Random (0x01)
        Address: 34:11:85:DC:41:39 (Non-Resolvable)
        Data length: 8
        Mesh Provision: 024874cb0007
          Link ID: 0x024874cb
          Transaction Number: 0
          Provisioning Bearer Control (0x03)
          Link Ack (0x01)
        RSSI: -28 dBm (0xe4)
---
 monitor/packet.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)
monitor/packet.c +67 -0
index 3e6382e..9655dca 100644
@@ -3581,6 +3581,72 @@ static void print_mesh_beacon(const uint8_t *data, uint8_t len)
 	}
 }
 
+static void print_mesh_prov(const uint8_t *data, uint8_t len)
+{
+	if (len < 6)
+		return;
+
+	print_field("  Link ID: 0x%08x", get_be32(&data[0]));
+	print_field("  Transaction Number: %u", data[4]);
+
+	data += 5;
+	len -= 5;
+
+	switch (data[0] & 0x03) {
+	case 0x00:
+		print_field("  Transaction Start (0x00)");
+		if (len < 5)
+			return;
+		print_field("  SeqN: %u", data[0] & 0xfc >> 2);
+		print_field("  TotalLength: %u", get_be16(&data[1]));
+		print_field("  FCS: 0x%2.2x", data[3]);
+		print_hex_field("  Data", data, len - 4);
+		break;
+	case 0x01:
+		print_field("  Transaction Acknowledgment (0x01)");
+		break;
+	case 0x02:
+		print_field("  Transaction Continuation (0x02)");
+		print_field("  SegmentIndex: %u", data[0] >> 2);
+		print_hex_field("  Data", &data[1], len - 1);
+		break;
+	case 0x03:
+		print_field("  Provisioning Bearer Control (0x03)");
+		switch (data[0] >> 2) {
+		case 0x00:
+			print_field("  Link Open (0x00)");
+			if (len < 17)
+				break;
+			print_hex_field("  Device UUID", data, 16);
+			break;
+		case 0x01:
+			print_field("  Link Ack (0x01)");
+			break;
+		case 0x02:
+			print_field("  Link Close (0x02)");
+			if (len < 2)
+				break;
+
+			switch (data[1]) {
+			case 0x00:
+				print_field("  Reason: Success (0x00)");
+				break;
+			case 0x01:
+				print_field("  Reason: Timeout (0x01)");
+				break;
+			case 0x02:
+				print_field("  Reason: Fail (0x02)");
+				break;
+			default:
+				print_field("  Reason: Unrecognized (0x%2.2x)",
+								data[1]);
+			}
+			break;
+		}
+		break;
+	}
+}
+
 static void print_eir(const uint8_t *eir, uint8_t eir_len, bool le)
 {
 	uint16_t len = 0;
@@ -3811,6 +3877,7 @@ static void print_eir(const uint8_t *eir, uint8_t eir_len, bool le)
 
 		case BT_EIR_MESH_PROV:
 			print_hex_field("Mesh Provisioning", data, data_len);
+			print_mesh_prov(data, data_len);
 			break;
 
 		case BT_EIR_MESH_BEACON:
Signature · 1 line
2.9.4
author maintainer
#11 lore raw

PATCH 6/7 monitor: Add basic decoding for Mesh Data

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds basic decoding for Mesh Data packets such as:

Quoted 1 line

HCI Event: LE Meta Event (0x3e) plen 43

      LE Advertising Report (0x02)
        Num reports: 1
        Event type: Non connectable undirected - ADV_NONCONN_IND (0x03)
        Address type: Random (0x01)
        Address: 29:3C:CE:85:C7:3D (Non-Resolvable)
        Data length: 31
        Mesh Data: 37cb3a2bdfca0783b10833cfbdc9e691b0d58b2dada00269181477c901
          IV: 1
          NID: 0x1b
        RSSI: -28 dBm (0xe4)
---
 monitor/packet.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
monitor/packet.c +10 -0
index 9655dca..678d7a7 100644
@@ -3647,6 +3647,15 @@ static void print_mesh_prov(const uint8_t *data, uint8_t len)
 	}
 }
 
+static void print_mesh_data(const uint8_t *data, uint8_t len)
+{
+	if (len < 1)
+		return;
+
+	print_field("  IV: %u", data[0] & 0x01);
+	print_field("  NID: 0x%2.2x", data[0] & 0xfe);
+}
+
 static void print_eir(const uint8_t *eir, uint8_t eir_len, bool le)
 {
 	uint16_t len = 0;
@@ -3873,6 +3882,7 @@ static void print_eir(const uint8_t *eir, uint8_t eir_len, bool le)
 
 		case BT_EIR_MESH_DATA:
 			print_hex_field("Mesh Data", data, data_len);
+			print_mesh_data(data, data_len);
 			break;
 
 		case BT_EIR_MESH_PROV:
Signature · 1 line
2.9.4
author maintainer
#12 lore raw

PATCH 7/7 monitor: Add option to show only mesh advertisements

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds -M/--mesh [nid] option to show only mesh advertisements which is very convenient when monitoring noisy environments.

---
 monitor/main.c   | 17 +++++++++++-
 monitor/packet.c | 80 ++++++++++++++++++++++++++++++++++++++++++++------------
 monitor/packet.h |  2 ++
 3 files changed, 82 insertions(+), 17 deletions(-)
monitor/main.c +16 -1
index b4e9a6a..fb7d5f5 100644
@@ -71,6 +71,7 @@ static void usage(void)
 		"\t-S, --sco              Dump SCO traffic\n"
 		"\t-A, --a2dp             Dump A2DP stream traffic\n"
 		"\t-E, --ellisys [ip]     Send Ellisys HCI Injection\n"
+		"\t-M, --mesh [nid]	  Dump Mesh traffic only\n"
 		"\t-h, --help             Show help options\n");
 }
 
@@ -88,6 +89,7 @@ static const struct option main_options[] = {
 	{ "sco",     no_argument,	NULL, 'S' },
 	{ "a2dp",    no_argument,	NULL, 'A' },
 	{ "ellisys", required_argument, NULL, 'E' },
+	{ "mesh",    optional_argument, NULL, 'M' },
 	{ "todo",    no_argument,       NULL, '#' },
 	{ "version", no_argument,       NULL, 'v' },
 	{ "help",    no_argument,       NULL, 'h' },
@@ -104,6 +106,7 @@ int main(int argc, char *argv[])
 	const char *tty = NULL;
 	unsigned int tty_speed = B115200;
 	unsigned short ellisys_port = 0;
+	int mesh_nid = -1;
 	const char *str;
 	int exit_status;
 	sigset_t mask;
@@ -115,7 +118,7 @@ int main(int argc, char *argv[])
 	for (;;) {
 		int opt;
 
-		opt = getopt_long(argc, argv, "d:r:w:a:s:p:i:tTSAE:vh",
+		opt = getopt_long(argc, argv, "d:r:w:a:s:p:i:tTSAE:M::vh",
 						main_options, NULL);
 		if (opt < 0)
 			break;
@@ -176,6 +179,18 @@ int main(int argc, char *argv[])
 			ellisys_server = optarg;
 			ellisys_port = 24352;
 			break;
+		case 'M':
+			if (optarg) {
+				mesh_nid = atoi(optarg);
+				if (mesh_nid < 0 || mesh_nid > 0x7f) {
+					fprintf(stderr, "Invalid NID: %s\n",
+								optarg);
+					return EXIT_FAILURE;
+				}
+				packet_set_mesh_nid(mesh_nid);
+			}
+			filter_mask |= PACKET_FILTER_MESH_ONLY;
+			break;
 		case '#':
 			packet_todo();
 			lmp_todo();
monitor/packet.c +64 -16

143 lines not on this page · raw message

monitor/packet.h +2 -0
index a4fdcc6..e2ed233 100644
@@ -34,6 +34,7 @@
 #define PACKET_FILTER_SHOW_ACL_DATA	(1 << 4)
 #define PACKET_FILTER_SHOW_SCO_DATA	(1 << 5)
 #define PACKET_FILTER_SHOW_A2DP_STREAM	(1 << 6)
+#define PACKET_FILTER_MESH_ONLY		(1 << 7)
 
 bool packet_has_filter(unsigned long filter);
 void packet_set_filter(unsigned long filter);
@@ -42,6 +43,7 @@ void packet_del_filter(unsigned long filter);
 
 void packet_set_priority(const char *priority);
 void packet_select_index(uint16_t index);
+void packet_set_mesh_nid(uint8_t nid);
 
 void packet_hexdump(const unsigned char *buf, uint16_t len);
 void packet_print_error(const char *label, uint8_t error);
Signature · 1 line
2.9.4
maintainer
#8 lore raw

Re: [PATCH BlueZ 4/7] monitor: Add basic decoding for Mesh Beacon

In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 49 lines

This adds basic decoding for Mesh Beacon packets such as:

Quoted 1 line

HCI Event: LE Meta Event (0x3e) plen 37

     LE Advertising Report (0x02)
       Num reports: 1
       Event type: Non connectable undirected - ADV_NONCONN_IND (0x03)
       Address type: Random (0x01)
       Address: 36:47:34:FC:63:DA (Non-Resolvable)
       Data length: 25
       Mesh Beacon: 00dddd0000000000000000000000000000000000000000
         Unprovisioned Device Beacon (0x00)
         Device UUID: 00dddd00000000000000000000000000
         OOB Information: 0x0000
         URI Hash: 0x0000
       RSSI: -28 dBm (0xe4)

< HCI Command: LE Set Advertising Data (0x08|0x0008) plen 32

       Length: 24
       Mesh Beacon: 0100c7005d732329eadf000000003e60e50797ef6d5c
         Secure Network Beacon (0x01)
         Flags: 0x01
         Network Id: 00c7005d732329ea
         IV Index: 0xdf000000
         Authentication Value: 003e60e50797ef6d
---
monitor/packet.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
monitor/packet.c +13 -0
index 1ec816c..3e6382e 100644
@@ -3513,6 +3513,74 @@ static const struct {
 	{ }
 };
 
+static const struct {
+	uint8_t bit;
+	const char *str;
+} mesh_oob_table[] = {
+	{ 0, "Other"							},
+	{ 1, "Eletronic / URI"						},
+	{ 2, "2D machine-readable code"					},
+	{ 3, "Bar code"							},
+	{ 4, "Near Field Communication (NFC)"				},
+	{ 5, "Number"							},
+	{ 6, "String"							},
+	{ 11, "On box"							},
+	{ 12, "Inside box"						},

monitor/packet.c static const struct { · line 3538

Quoted 10 lines
monitor/packet.c +10 -0
+	{ 13, "On piece of paper"					},
+	{ 14, "Inside manual"						},
+	{ 14, "On Device"						},
+	{ }
+};
+
+static void print_mesh_beacon(const uint8_t *data, uint8_t len)
+{
+	int i;
+	uint16_t oob;

my preference is to have iterator variable like i last in the list.

Regards

Marcel

monitor/packet.c static const struct { · line 3541

Quoted 3 lines
monitor/packet.c +3 -0
+
+	if (len < 1)
+		return;

At least use print_hex_field here. General rule of btmon is to print the data. Silently swallowing is bad idea. This is no longer hcidump ;)

Quoted 30 lines
monitor/packet.c +30 -0
+
+	switch (data[0]) {
+	case 0x00:
+		print_field("  Unprovisioned Device Beacon (0x00)");
+		if (len < 18)
+			break;
+
+		print_hex_field("  Device UUID", data, 16);
+
+		oob = get_be16(&data[16]);
+		print_field("  OOB Information: 0x%4.4x", oob);
+
+		for (i = 0; mesh_oob_table[i].str; i++) {
+			if (oob & (1 << mesh_oob_table[i].bit))
+				print_field("    %s", mesh_oob_table[i].str);
+		}
+
+		if (len < 22)
+			break;
+
+		print_field("  URI Hash: 0x%4.4x", get_be32(&data[18]));
+		break;
+	case 0x01:
+		print_field("  Secure Network Beacon (0x01)");
+		if (len < 21)
+			break;
+
+		print_field("  Flags: 0x%2.2x", data[0]);
+
+		if (data[0] & 0x01)

monitor/packet.c static const struct { · line 3581

Quoted 10 lines
monitor/packet.c +10 -0
+			print_field("    Key Refresh");
+
+		if (data[0] & 0x02)
+			print_field("    IV Update");
+
+		print_hex_field("  Network Id", &data[1], 8);
+		print_field("  IV Index: 0x%08x", get_be32(&data[9]));
+		print_hex_field("  Authentication Value", &data[13], 8);
+		break;
+	}

And this should get a default: print_hex_field.

Regards

Marcel

maintainer
#3 lore raw

Re: [PATCH BlueZ 3/7] monitor: Filter duplicated advertisements

In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 13 lines

This reduces the verbosity and give a precise picture of how unique each report is.
---

monitor/intel.c  |  28 +++---
monitor/packet.c | 277 ++++++++++++++++++++++++++++++++++++-------------------
monitor/vendor.h |   2 +-
3 files changed, 198 insertions(+), 109 deletions(-)
monitor/intel.c +0 -0
index 1ca9a95..9da188a 100644

monitor/intel.c const struct vendor_ocf *intel_vendor_ocf(uint16_t ocf) · line 504

Quoted 7 lines
monitor/intel.c +1 -1
@@ -499,11 +499,11 @@ const struct vendor_ocf *intel_vendor_ocf(uint16_t ocf)
 	return NULL;
 }
 
-static void startup_evt(const void *data, uint8_t size)
+static void startup_evt(uint8_t index, const void *data, uint8_t size)
 {
 }

NAK. I avoid this and want to keep avoiding it. There are different ways to get the actual index number if you need it. And also FYI, the index is a uint16_t.

Regards

Marcel

maintainer
#13 lore raw

Re: [PATCH BlueZ 7/7] monitor: Add option to show only mesh advertisements

In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 46 lines

This adds -M/--mesh [nid] option to show only mesh advertisements which is very convenient when monitoring noisy environments.
---

monitor/main.c   | 17 +++++++++++-
monitor/packet.c | 80 ++++++++++++++++++++++++++++++++++++++++++++------------
monitor/packet.h |  2 ++
3 files changed, 82 insertions(+), 17 deletions(-)
monitor/main.c +4 -1
index b4e9a6a..fb7d5f5 100644
@@ -71,6 +71,7 @@ static void usage(void)
 		"\t-S, --sco              Dump SCO traffic\n"
 		"\t-A, --a2dp             Dump A2DP stream traffic\n"
 		"\t-E, --ellisys [ip]     Send Ellisys HCI Injection\n"
+		"\t-M, --mesh [nid]	  Dump Mesh traffic only\n"
 		"\t-h, --help             Show help options\n");
 }
 
@@ -88,6 +89,7 @@ static const struct option main_options[] = {
 	{ "sco",     no_argument,	NULL, 'S' },
 	{ "a2dp",    no_argument,	NULL, 'A' },
 	{ "ellisys", required_argument, NULL, 'E' },
+	{ "mesh",    optional_argument, NULL, 'M' },
 	{ "todo",    no_argument,       NULL, '#' },
 	{ "version", no_argument,       NULL, 'v' },
 	{ "help",    no_argument,       NULL, 'h' },
@@ -104,6 +106,7 @@ int main(int argc, char *argv[])
 	const char *tty = NULL;
 	unsigned int tty_speed = B115200;
 	unsigned short ellisys_port = 0;
+	int mesh_nid = -1;
 	const char *str;
 	int exit_status;
 	sigset_t mask;
@@ -115,7 +118,7 @@ int main(int argc, char *argv[])
 	for (;;) {
 		int opt;
 
-		opt = getopt_long(argc, argv, "d:r:w:a:s:p:i:tTSAE:vh",
+		opt = getopt_long(argc, argv, "d:r:w:a:s:p:i:tTSAE:M::vh",
 						main_options, NULL);
 		if (opt < 0)
 			break;

monitor/main.c int main(int argc, char *argv[]) · line 184

Quoted 6 lines
monitor/main.c +3 -0
@@ -176,6 +179,18 @@ int main(int argc, char *argv[])
 			ellisys_server = optarg;
 			ellisys_port = 24352;
 			break;
+		case 'M':
+			if (optarg) {
+				mesh_nid = atoi(optarg);

you also need to support hex input here as well.

Quoted 41 lines
monitor/main.c +9 -0
+				if (mesh_nid < 0 || mesh_nid > 0x7f) {
+					fprintf(stderr, "Invalid NID: %s\n",
+								optarg);
+					return EXIT_FAILURE;
+				}
+				packet_set_mesh_nid(mesh_nid);
+			}
+			filter_mask |= PACKET_FILTER_MESH_ONLY;
+			break;
 		case '#':
 			packet_todo();
 			lmp_todo();
monitor/packet.c +7 -0
index 678d7a7..c2ba66f 100644
@@ -111,6 +111,7 @@ static unsigned long filter_mask = 0;
 static bool index_filter = false;
 static uint16_t index_number = 0;
 static uint16_t index_current = 0;
+static int mesh_nid = -1;
 
 #define UNKNOWN_MANUFACTURER 0xffff
 
@@ -268,6 +269,11 @@ void packet_select_index(uint16_t index)
 	index_number = index;
 }
 
+void packet_set_mesh_nid(uint8_t nid)
+{
+	mesh_nid = nid;
+}
+
 #define print_space(x) printf("%*c", (x), ' ');
 
 #define MAX_INDEX 16
@@ -8850,6 +8856,25 @@ rssi:
 	}
 }
 
+static bool le_adv_report_filter(uint8_t index, const void *data, uint8_t size)

monitor/packet.c rssi: · line 8869

Quoted 10 lines
monitor/packet.c +10 -0
+{
+	const struct bt_hci_evt_le_adv_report *evt = data;
+
+	if (!packet_has_filter(PACKET_FILTER_MESH_ONLY))
+		return false;
+
+	switch (evt->data[1]) {
+	case BT_EIR_MESH_DATA:
+		if (mesh_nid > 0 && ((evt->data[2] & 0xfe) != mesh_nid))
+			return true;

fall through comment is missing and also mesh_nid > 0 is wrong. Then using uint8_t mesh_nid would be fine. Which is actually what I think we should be doing anyway in the first place. This a cryptographic hash. Chances are super slim that we get 0x00 here.

Quoted 98 lines
monitor/packet.c +42 -15
+	case BT_EIR_MESH_PROV:
+	case BT_EIR_MESH_BEACON:
+		return false;
+	}
+
+	return true;
+}
+
 static void le_conn_update_complete_evt(uint8_t index, const void *data, uint8_t size)
 {
 	const struct bt_hci_evt_le_conn_update_complete *evt = data;
@@ -8998,6 +9023,7 @@ struct subevent_data {
 	void (*func) (uint8_t index, const void *data, uint8_t size);
 	uint8_t size;
 	bool fixed;
+	bool (*filter) (uint8_t index, const void *data, uint8_t size);
 };
 
 static void print_subevent(const struct subevent_data *subevent_data,
@@ -9039,7 +9065,8 @@ static const struct subevent_data le_meta_event_table[] = {
 	{ 0x01, "LE Connection Complete",
 				le_conn_complete_evt, 18, true },
 	{ 0x02, "LE Advertising Report",
-				le_adv_report_evt, 1, false },
+				le_adv_report_evt, 1, false,
+				le_adv_report_filter },
 	{ 0x03, "LE Connection Update Complete",
 				le_conn_update_complete_evt, 9, true },
 	{ 0x04, "LE Read Remote Used Features",
@@ -9072,29 +9099,45 @@ static const struct subevent_data le_meta_event_table[] = {
 	{ }
 };
 
-static void le_meta_event_evt(uint8_t index, const void *data, uint8_t size)
+static const struct subevent_data *le_meta_event_find(uint8_t subevent)
 {
-	uint8_t subevent = *((const uint8_t *) data);
-	struct subevent_data unknown;
-	const struct subevent_data *subevent_data = &unknown;
 	int i;
 
-	unknown.subevent = subevent;
-	unknown.str = "Unknown";
-	unknown.func = NULL;
-	unknown.size = 0;
-	unknown.fixed = true;
-
 	for (i = 0; le_meta_event_table[i].str; i++) {
-		if (le_meta_event_table[i].subevent == subevent) {
-			subevent_data = &le_meta_event_table[i];
-			break;
-		}
+		if (le_meta_event_table[i].subevent == subevent)
+			return &le_meta_event_table[i];
+	}
+
+	return NULL;
+}
+
+static void le_meta_event_evt(uint8_t index, const void *data, uint8_t size)
+{
+	uint8_t subevent = *((const uint8_t *) data);
+	const struct subevent_data *subevent_data;
+
+	subevent_data = le_meta_event_find(subevent);
+	if (!subevent_data) {
+		print_indent(6, COLOR_HCI_EVENT_UNKNOWN, "", "", COLOR_OFF,
+						" (0x%2.2x)", subevent);
+		return;
 	}
 
 	print_subevent(subevent_data, index, data + 1, size - 1);
 }
 
+static bool le_meta_event_filter(uint8_t index, const void *data, uint8_t size)
+{
+	uint8_t subevent = *((const uint8_t *) data);
+	const struct subevent_data *subevent_data;
+
+	subevent_data = le_meta_event_find(subevent);
+	if (!subevent_data || !subevent_data->filter)
+		return false;
+
+	return subevent_data->filter(index, data + 1, size - 1);
+}
+
 static void vendor_evt(uint8_t index, const void *data, uint8_t size)
 {
 	uint8_t subevent = *((const uint8_t *) data);
@@ -9135,6 +9178,7 @@ struct event_data {
 	void (*func) (uint8_t index, const void *data, uint8_t size);
 	uint8_t size;
 	bool fixed;
+	bool (*filter) (uint8_t index, const void *data, uint8_t size);
 };
 
 static const struct event_data event_table[] = {

monitor/packet.c static const struct event_data event_table[] = { · line 9289

Quoted 6 lines
monitor/packet.c +2 -1
@@ -9241,7 +9285,8 @@ static const struct event_data event_table[] = {
 	{ 0x3d, "Remote Host Supported Features",
 				remote_host_features_notify_evt, 14, true },
 	{ 0x3e, "LE Meta Event",
-				le_meta_event_evt, 1, false },
+				le_meta_event_evt, 1, false,
+				le_meta_event_filter },

I really do not like this. Lets not add another function to these tables. Figure something else out. And frankly, I rather have a btmon --mesh command that focus purely on mesh advertising bearer. If not, then just leave all packets unfiltered.

Also we could just figure out on how to use BPF on the monitoring socket. Doing this outside the kernel seems pointless.

Regards

Marcel

author maintainer
#4 lore raw

Re: [PATCH BlueZ 3/7] monitor: Filter duplicated advertisements

In reply to Marcel Holtmann

Hi Marcel,

Quoted 18 lines · Marcel Holtmann

Hi Luiz,

Quoted 16 lines

This reduces the verbosity and give a precise picture of how unique each report is.
---

monitor/intel.c  |  28 +++---
monitor/packet.c | 277 ++++++++++++++++++++++++++++++++++++-------------------
monitor/vendor.h |   2 +-
3 files changed, 198 insertions(+), 109 deletions(-)
monitor/intel.c +0 -0
index 1ca9a95..9da188a 100644
@@ -499,11 +499,11 @@ const struct vendor_ocf *intel_vendor_ocf(uint16_t ocf)
      return NULL;
 }
 
Quoted 6 lines

monitor/intel.c const struct vendor_ocf *intel_vendor_ocf(uint16_t ocf) · line 504

Quoted 4 lines
monitor/intel.c +1 -1
-static void startup_evt(const void *data, uint8_t size)
+static void startup_evt(uint8_t index, const void *data, uint8_t size)
 {
 }

NAK. I avoid this and want to keep avoiding it. There are different ways to get the actual index number if you need it. And also FYI, the index is a uint16_t.

I haven't figure out any other way to pass down the index number, or do you want some like l2cap_frame so it can carry information such as the index.

Signature · 1 line
Luiz Augusto von Dentz
author maintainer
#14 lore raw

Re: [PATCH BlueZ 7/7] monitor: Add option to show only mesh advertisements

In reply to Marcel Holtmann

Hi Marcel,

On Tue, Jul 18, 2017 at 10:10 PM, Marcel Holtmann <[email protected]> wro= te:

Quoted 7 lines

Hi Luiz,

Quoted 5 lines

This adds -M/--mesh [nid] option to show only mesh advertisements which is very convenient when monitoring noisy environments.
---
monitor/main.c | 17 +++++++++++-
monitor/packet.c | 80 ++++++++++++++++++++++++++++++++++++++++++++------=

------

Quoted 35 lines
Quoted 35 lines

monitor/packet.h | 2 ++

3 files changed, 82 insertions(+), 17 deletions(-)
monitor/main.c +3 -0
index b4e9a6a..fb7d5f5 100644
@@ -71,6 +71,7 @@ static void usage(void)
              "\t-S, --sco              Dump SCO traffic\n"
              "\t-A, --a2dp             Dump A2DP stream traffic\n"
              "\t-E, --ellisys [ip]     Send Ellisys HCI Injection\n"
+             "\t-M, --mesh [nid]       Dump Mesh traffic only\n"
              "\t-h, --help             Show help options\n");
 }
 
@@ -88,6 +89,7 @@ static const struct option main_options[] =3D {
      { "sco",     no_argument,       NULL, 'S' },
      { "a2dp",    no_argument,       NULL, 'A' },
      { "ellisys", required_argument, NULL, 'E' },
+     { "mesh",    optional_argument, NULL, 'M' },
      { "todo",    no_argument,       NULL, '#' },
      { "version", no_argument,       NULL, 'v' },
      { "help",    no_argument,       NULL, 'h' },
@@ -104,6 +106,7 @@ int main(int argc, char *argv[])
      const char *tty =3D NULL;
      unsigned int tty_speed =3D B115200;
      unsigned short ellisys_port =3D 0;
+     int mesh_nid =3D -1;
      const char *str;
      int exit_status;
      sigset_t mask;
@@ -115,7 +118,7 @@ int main(int argc, char *argv[])
      for (;;) {
              int opt;
 
Quoted 2 lines

monitor/main.c int main(int argc, char *argv[]) · line 121

Quoted 2 lines
monitor/main.c +1 -1
-             opt =3D getopt_long(argc, argv, "d:r:w:a:s:p:i:tTSAE:vh",
+             opt =3D getopt_long(argc, argv, "d:r:w:a:s:p:i:tTSAE:M::vh=

",

Quoted 4 lines
Quoted 4 lines
monitor/main.c +0 -0
                                              main_options, NULL);
              if (opt < 0)
                      break;
@@ -176,6 +179,18 @@ int main(int argc, char *argv[])
Quoted 11 lines

monitor/main.c int main(int argc, char *argv[])

Quoted 6 lines
monitor/main.c +3 -0
                      ellisys_server =3D optarg;
                      ellisys_port =3D 24352;
                      break;
+             case 'M':
+                     if (optarg) {
+                             mesh_nid =3D atoi(optarg);

you also need to support hex input here as well.

Quoted 2 lines
monitor/main.c +2 -0
+                             if (mesh_nid < 0 || mesh_nid > 0x7f) {
+                                     fprintf(stderr, "Invalid NID: %s\n=

",

Quoted 33 lines
Quoted 33 lines
monitor/main.c +7 -0
+                                                             optarg);
+                                     return EXIT_FAILURE;
+                             }
+                             packet_set_mesh_nid(mesh_nid);
+                     }
+                     filter_mask |=3D PACKET_FILTER_MESH_ONLY;
+                     break;
              case '#':
                      packet_todo();
                      lmp_todo();
monitor/packet.c +6 -0
index 678d7a7..c2ba66f 100644
@@ -111,6 +111,7 @@ static unsigned long filter_mask =3D 0;
 static bool index_filter =3D false;
 static uint16_t index_number =3D 0;
 static uint16_t index_current =3D 0;
+static int mesh_nid =3D -1;
 
 #define UNKNOWN_MANUFACTURER 0xffff
 
@@ -268,6 +269,11 @@ void packet_select_index(uint16_t index)
      index_number =3D index;
 }
 
+void packet_set_mesh_nid(uint8_t nid)
+{
+     mesh_nid =3D nid;
+}
+
 #define print_space(x) printf("%*c", (x), ' ');
 
Quoted 6 lines

monitor/packet.c rssi: · line 8859

Quoted 6 lines
monitor/packet.c +1 -0
 #define MAX_INDEX 16
@@ -8850,6 +8856,25 @@ rssi:
      }
 }
 
+static bool le_adv_report_filter(uint8_t index, const void *data, uint8=

_t size)

Quoted 4 lines
Quoted 4 lines
monitor/packet.c +4 -0
+{
+     const struct bt_hci_evt_le_adv_report *evt =3D data;
+
+     if (!packet_has_filter(PACKET_FILTER_MESH_ONLY))
Quoted 8 lines

monitor/packet.c rssi: · line 8869

Quoted 6 lines
monitor/packet.c +6 -0
+             return false;
+
+     switch (evt->data[1]) {
+     case BT_EIR_MESH_DATA:
+             if (mesh_nid > 0 && ((evt->data[2] & 0xfe) !=3D mesh_nid))
+                     return true;

fall through comment is missing and also mesh_nid > 0 is wrong. Then usin=

g uint8_t mesh_nid would be fine. Which is actually what I think we should = be doing anyway in the first place. This a cryptographic hash. Chances are = super slim that we get 0x00 here.

Quoted 10 lines
Quoted 10 lines
monitor/packet.c +8 -0
+     case BT_EIR_MESH_PROV:
+     case BT_EIR_MESH_BEACON:
+             return false;
+     }
+
+     return true;
+}
+

static void le_conn_update_complete_evt(uint8_t index, const void *data,=

uint8_t size)

Quoted 11 lines

monitor/packet.c static const struct subevent_data le_meta_event_ta=

Quoted 11 lines
{
      const struct bt_hci_evt_le_conn_update_complete *evt =3D data;
monitor/packet.c +1 -0
@@ -8998,6 +9023,7 @@ struct subevent_data {
      void (*func) (uint8_t index, const void *data, uint8_t size);
      uint8_t size;
      bool fixed;
+     bool (*filter) (uint8_t index, const void *data, uint8_t size);
 };
 
 static void print_subevent(const struct subevent_data *subevent_data,
@@ -9039,7 +9065,8 @@ static const struct subevent_data le_meta_event_ta=

ble[] =3D {

Quoted 10 lines

monitor/packet.c static const struct subevent_data le_meta_event_=

Quoted 10 lines
monitor/packet.c +2 -1
      { 0x01, "LE Connection Complete",
                              le_conn_complete_evt, 18, true },
      { 0x02, "LE Advertising Report",
-                             le_adv_report_evt, 1, false },
+                             le_adv_report_evt, 1, false,
+                             le_adv_report_filter },
      { 0x03, "LE Connection Update Complete",
                              le_conn_update_complete_evt, 9, true },
      { 0x04, "LE Read Remote Used Features",
@@ -9072,29 +9099,45 @@ static const struct subevent_data le_meta_event_=

table[] =3D {

Quoted 4 lines

monitor/packet.c static const struct subevent_data le_meta_event_= · line 9075

Quoted 4 lines
monitor/packet.c +0 -1
      { }
 };
 
-static void le_meta_event_evt(uint8_t index, const void *data, uint8_t =

size)

Quoted 18 lines
Quoted 18 lines
monitor/packet.c +1 -13
+static const struct subevent_data *le_meta_event_find(uint8_t subevent)
 {
-     uint8_t subevent =3D *((const uint8_t *) data);
-     struct subevent_data unknown;
-     const struct subevent_data *subevent_data =3D &unknown;
      int i;
 
-     unknown.subevent =3D subevent;
-     unknown.str =3D "Unknown";
-     unknown.func =3D NULL;
-     unknown.size =3D 0;
-     unknown.fixed =3D true;
-
      for (i =3D 0; le_meta_event_table[i].str; i++) {
-             if (le_meta_event_table[i].subevent =3D=3D subevent) {
-                     subevent_data =3D &le_meta_event_table[i];
-                     break;
-             }
Quoted 8 lines

monitor/packet.c static const struct subevent_data le_meta_event_table[] = {

Quoted 8 lines
monitor/packet.c +8 -0
+             if (le_meta_event_table[i].subevent =3D=3D subevent)
+                     return &le_meta_event_table[i];
+     }
+
+     return NULL;
+}
+
+static void le_meta_event_evt(uint8_t index, const void *data, uint8_t =

size)

Quoted 7 lines

monitor/packet.c static const struct subevent_data le_meta_event_table[] = {

Quoted 7 lines
monitor/packet.c +7 -0
+{
+     uint8_t subevent =3D *((const uint8_t *) data);
+     const struct subevent_data *subevent_data;
+
+     subevent_data =3D le_meta_event_find(subevent);
+     if (!subevent_data) {
+             print_indent(6, COLOR_HCI_EVENT_UNKNOWN, "", "", COLOR_OFF=

,

Quoted 8 lines

monitor/packet.c static const struct subevent_data le_meta_event_table[] = {

Quoted 8 lines
monitor/packet.c +3 -0
+                                             " (0x%2.2x)", subevent);
+             return;
      }
 
      print_subevent(subevent_data, index, data + 1, size - 1);
 }
 
+static bool le_meta_event_filter(uint8_t index, const void *data, uint8=

_t size)

Quoted 21 lines
Quoted 21 lines
monitor/packet.c +12 -0
+{
+     uint8_t subevent =3D *((const uint8_t *) data);
+     const struct subevent_data *subevent_data;
+
+     subevent_data =3D le_meta_event_find(subevent);
+     if (!subevent_data || !subevent_data->filter)
+             return false;
+
+     return subevent_data->filter(index, data + 1, size - 1);
+}
+
 static void vendor_evt(uint8_t index, const void *data, uint8_t size)
 {
      uint8_t subevent =3D *((const uint8_t *) data);
@@ -9135,6 +9178,7 @@ struct event_data {
      void (*func) (uint8_t index, const void *data, uint8_t size);
      uint8_t size;
      bool fixed;
+     bool (*filter) (uint8_t index, const void *data, uint8_t size);
 };
 
Quoted 4 lines

monitor/packet.c static const struct event_data event_table[] =3D { · line 9286

Quoted 4 lines
monitor/packet.c +0 -0
 static const struct event_data event_table[] =3D {
@@ -9241,7 +9285,8 @@ static const struct event_data event_table[] =3D {
      { 0x3d, "Remote Host Supported Features",
                              remote_host_features_notify_evt, 14, true =

},

Quoted 6 lines

monitor/packet.c static const struct event_data event_table[] = { · line 9289

Quoted 4 lines
monitor/packet.c +2 -1
      { 0x3e, "LE Meta Event",
-                             le_meta_event_evt, 1, false },
+                             le_meta_event_evt, 1, false,
+                             le_meta_event_filter },

I really do not like this. Lets not add another function to these tables.=

Figure something else out. And frankly, I rather have a btmon --mesh comma=
nd that focus purely on mesh advertising bearer. If not, then just leave al= l packets unfiltered.

I thought about that too, but there could be other related packets, for example GATT proxy.

Quoted 1 line

Also we could just figure out on how to use BPF on the monitoring socket.=

Doing this outside the kernel seems pointless.

I will look into that, didn't know BPF could be used with any packet based socket, well if it does then I completely agree with you, if it doesn't then we might want something that could work with older kernels.

--=20
Luiz Augusto von Dentz

maintainer
#15 lore raw

Re: [PATCH BlueZ 7/7] monitor: Add option to show only mesh advertisements

Hi Luiz,

Quoted 216 lines
Quoted 205 lines
Quoted 46 lines

This adds -M/--mesh [nid] option to show only mesh advertisements which is very convenient when monitoring noisy environments.
---

monitor/main.c   | 17 +++++++++++-
monitor/packet.c | 80 ++++++++++++++++++++++++++++++++++++++++++++------------
monitor/packet.h |  2 ++
3 files changed, 82 insertions(+), 17 deletions(-)
monitor/main.c +4 -1
index b4e9a6a..fb7d5f5 100644
@@ -71,6 +71,7 @@ static void usage(void)
             "\t-S, --sco              Dump SCO traffic\n"
             "\t-A, --a2dp             Dump A2DP stream traffic\n"
             "\t-E, --ellisys [ip]     Send Ellisys HCI Injection\n"
+             "\t-M, --mesh [nid]       Dump Mesh traffic only\n"
             "\t-h, --help             Show help options\n");
 }
 
@@ -88,6 +89,7 @@ static const struct option main_options[] = {
     { "sco",     no_argument,       NULL, 'S' },
     { "a2dp",    no_argument,       NULL, 'A' },
     { "ellisys", required_argument, NULL, 'E' },
+     { "mesh",    optional_argument, NULL, 'M' },
     { "todo",    no_argument,       NULL, '#' },
     { "version", no_argument,       NULL, 'v' },
     { "help",    no_argument,       NULL, 'h' },
@@ -104,6 +106,7 @@ int main(int argc, char *argv[])
     const char *tty = NULL;
     unsigned int tty_speed = B115200;
     unsigned short ellisys_port = 0;
+     int mesh_nid = -1;
     const char *str;
     int exit_status;
     sigset_t mask;
@@ -115,7 +118,7 @@ int main(int argc, char *argv[])
     for (;;) {
             int opt;
 
-             opt = getopt_long(argc, argv, "d:r:w:a:s:p:i:tTSAE:vh",
+             opt = getopt_long(argc, argv, "d:r:w:a:s:p:i:tTSAE:M::vh",
                                             main_options, NULL);
             if (opt < 0)
                     break;

monitor/main.c int main(int argc, char *argv[]) · line 184

Quoted 6 lines
monitor/main.c +3 -0
@@ -176,6 +179,18 @@ int main(int argc, char *argv[])
                     ellisys_server = optarg;
                     ellisys_port = 24352;
                     break;
+             case 'M':
+                     if (optarg) {
+                             mesh_nid = atoi(optarg);

you also need to support hex input here as well.

Quoted 41 lines
monitor/main.c +9 -0
+                             if (mesh_nid < 0 || mesh_nid > 0x7f) {
+                                     fprintf(stderr, "Invalid NID: %s\n",
+                                                             optarg);
+                                     return EXIT_FAILURE;
+                             }
+                             packet_set_mesh_nid(mesh_nid);
+                     }
+                     filter_mask |= PACKET_FILTER_MESH_ONLY;
+                     break;
             case '#':
                     packet_todo();
                     lmp_todo();
monitor/packet.c +7 -0
index 678d7a7..c2ba66f 100644
@@ -111,6 +111,7 @@ static unsigned long filter_mask = 0;
 static bool index_filter = false;
 static uint16_t index_number = 0;
 static uint16_t index_current = 0;
+static int mesh_nid = -1;
 
 #define UNKNOWN_MANUFACTURER 0xffff
 
@@ -268,6 +269,11 @@ void packet_select_index(uint16_t index)
     index_number = index;
 }
 
+void packet_set_mesh_nid(uint8_t nid)
+{
+     mesh_nid = nid;
+}
+
 #define print_space(x) printf("%*c", (x), ' ');
 
 #define MAX_INDEX 16
@@ -8850,6 +8856,25 @@ rssi:
     }
 }
 
+static bool le_adv_report_filter(uint8_t index, const void *data, uint8_t size)

monitor/packet.c rssi: · line 8869

Quoted 10 lines
monitor/packet.c +10 -0
+{
+     const struct bt_hci_evt_le_adv_report *evt = data;
+
+     if (!packet_has_filter(PACKET_FILTER_MESH_ONLY))
+             return false;
+
+     switch (evt->data[1]) {
+     case BT_EIR_MESH_DATA:
+             if (mesh_nid > 0 && ((evt->data[2] & 0xfe) != mesh_nid))
+                     return true;

fall through comment is missing and also mesh_nid > 0 is wrong. Then using uint8_t mesh_nid would be fine. Which is actually what I think we should be doing anyway in the first place. This a cryptographic hash. Chances are super slim that we get 0x00 here.

Quoted 96 lines
monitor/packet.c +42 -15
+     case BT_EIR_MESH_PROV:
+     case BT_EIR_MESH_BEACON:
+             return false;
+     }
+
+     return true;
+}
+
 static void le_conn_update_complete_evt(uint8_t index, const void *data, uint8_t size)
 {
     const struct bt_hci_evt_le_conn_update_complete *evt = data;
@@ -8998,6 +9023,7 @@ struct subevent_data {
     void (*func) (uint8_t index, const void *data, uint8_t size);
     uint8_t size;
     bool fixed;
+     bool (*filter) (uint8_t index, const void *data, uint8_t size);
 };
 
 static void print_subevent(const struct subevent_data *subevent_data,
@@ -9039,7 +9065,8 @@ static const struct subevent_data le_meta_event_table[] = {
     { 0x01, "LE Connection Complete",
                             le_conn_complete_evt, 18, true },
     { 0x02, "LE Advertising Report",
-                             le_adv_report_evt, 1, false },
+                             le_adv_report_evt, 1, false,
+                             le_adv_report_filter },
     { 0x03, "LE Connection Update Complete",
                             le_conn_update_complete_evt, 9, true },
     { 0x04, "LE Read Remote Used Features",
@@ -9072,29 +9099,45 @@ static const struct subevent_data le_meta_event_table[] = {
     { }
 };
 
-static void le_meta_event_evt(uint8_t index, const void *data, uint8_t size)
+static const struct subevent_data *le_meta_event_find(uint8_t subevent)
 {
-     uint8_t subevent = *((const uint8_t *) data);
-     struct subevent_data unknown;
-     const struct subevent_data *subevent_data = &unknown;
     int i;
 
-     unknown.subevent = subevent;
-     unknown.str = "Unknown";
-     unknown.func = NULL;
-     unknown.size = 0;
-     unknown.fixed = true;
-
     for (i = 0; le_meta_event_table[i].str; i++) {
-             if (le_meta_event_table[i].subevent == subevent) {
-                     subevent_data = &le_meta_event_table[i];
-                     break;
-             }
+             if (le_meta_event_table[i].subevent == subevent)
+                     return &le_meta_event_table[i];
+     }
+
+     return NULL;
+}
+
+static void le_meta_event_evt(uint8_t index, const void *data, uint8_t size)
+{
+     uint8_t subevent = *((const uint8_t *) data);
+     const struct subevent_data *subevent_data;
+
+     subevent_data = le_meta_event_find(subevent);
+     if (!subevent_data) {
+             print_indent(6, COLOR_HCI_EVENT_UNKNOWN, "", "", COLOR_OFF,
+                                             " (0x%2.2x)", subevent);
+             return;
     }
 
     print_subevent(subevent_data, index, data + 1, size - 1);
 }
 
+static bool le_meta_event_filter(uint8_t index, const void *data, uint8_t size)
+{
+     uint8_t subevent = *((const uint8_t *) data);
+     const struct subevent_data *subevent_data;
+
+     subevent_data = le_meta_event_find(subevent);
+     if (!subevent_data || !subevent_data->filter)
+             return false;
+
+     return subevent_data->filter(index, data + 1, size - 1);
+}
+
 static void vendor_evt(uint8_t index, const void *data, uint8_t size)
 {
     uint8_t subevent = *((const uint8_t *) data);
@@ -9135,6 +9178,7 @@ struct event_data {
     void (*func) (uint8_t index, const void *data, uint8_t size);
     uint8_t size;
     bool fixed;
+     bool (*filter) (uint8_t index, const void *data, uint8_t size);
 };
 
Quoted 10 lines

monitor/packet.c static const struct event_data event_table[] = { · line 9289

Quoted 8 lines
monitor/packet.c +2 -1
 static const struct event_data event_table[] = {
@@ -9241,7 +9285,8 @@ static const struct event_data event_table[] = {
     { 0x3d, "Remote Host Supported Features",
                             remote_host_features_notify_evt, 14, true },
     { 0x3e, "LE Meta Event",
-                             le_meta_event_evt, 1, false },
+                             le_meta_event_evt, 1, false,
+                             le_meta_event_filter },

I really do not like this. Lets not add another function to these tables. Figure something else out. And frankly, I rather have a btmon --mesh command that focus purely on mesh advertising bearer. If not, then just leave all packets unfiltered.

Quoted 2 lines

I thought about that too, but there could be other related packets, for example GATT proxy.

Frankly, if you care about GATT proxy as well, then accept that you get everything.

Quoted 6 lines
Quoted 1 line

Also we could just figure out on how to use BPF on the monitoring socket. Doing this outside the kernel seems pointless.

I will look into that, didn't know BPF could be used with any packet based socket, well if it does then I completely agree with you, if it doesn't then we might want something that could work with older kernels.

I rather accept that it only works on newer kernels than hacking btmon into some complicated code base. That happened to hcidump and I have no intention to repeat it.

Regards

Marcel

maintainer
#5 lore raw

Re: [PATCH BlueZ 3/7] monitor: Filter duplicated advertisements

In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 23 lines
Quoted 16 lines
Quoted 16 lines

This reduces the verbosity and give a precise picture of how unique each report is.
---

monitor/intel.c  |  28 +++---
monitor/packet.c | 277 ++++++++++++++++++++++++++++++++++++-------------------
monitor/vendor.h |   2 +-
3 files changed, 198 insertions(+), 109 deletions(-)
monitor/intel.c +0 -0
index 1ca9a95..9da188a 100644
@@ -499,11 +499,11 @@ const struct vendor_ocf *intel_vendor_ocf(uint16_t ocf)
     return NULL;
 }
 
Quoted 6 lines

monitor/intel.c const struct vendor_ocf *intel_vendor_ocf(uint16_t ocf) · line 504

Quoted 4 lines
monitor/intel.c +1 -1
-static void startup_evt(const void *data, uint8_t size)
+static void startup_evt(uint8_t index, const void *data, uint8_t size)
 {
 }

NAK. I avoid this and want to keep avoiding it. There are different ways to get the actual index number if you need it. And also FYI, the index is a uint16_t.

Quoted 3 lines

I haven't figure out any other way to pass down the index number, or do you want some like l2cap_frame so it can carry information such as the index.

using index_current was too complicated ;)

Regards

Marcel

author maintainer
#6 lore raw

Re: [PATCH BlueZ 3/7] monitor: Filter duplicated advertisements

Hi Marcel,

Quoted 25 lines · Marcel Holtmann

Hi Luiz,

Quoted 23 lines
Quoted 22 lines
Quoted 13 lines

This reduces the verbosity and give a precise picture of how unique each report is.
---

monitor/intel.c  |  28 +++---
monitor/packet.c | 277 ++++++++++++++++++++++++++++++++++++-------------------
monitor/vendor.h |   2 +-
3 files changed, 198 insertions(+), 109 deletions(-)
monitor/intel.c +0 -0
index 1ca9a95..9da188a 100644

monitor/intel.c const struct vendor_ocf *intel_vendor_ocf(uint16_t ocf) · line 504

Quoted 7 lines
monitor/intel.c +1 -1
@@ -499,11 +499,11 @@ const struct vendor_ocf *intel_vendor_ocf(uint16_t ocf)
     return NULL;
 }
 
-static void startup_evt(const void *data, uint8_t size)
+static void startup_evt(uint8_t index, const void *data, uint8_t size)
 {
 }

NAK. I avoid this and want to keep avoiding it. There are different ways to get the actual index number if you need it. And also FYI, the index is a uint16_t.

Quoted 5 lines
Quoted 3 lines

I haven't figure out any other way to pass down the index number, or do you want some like l2cap_frame so it can carry information such as the index.

using index_current was too complicated ;)

Sure thing, I got the impression we didn't have anything pointing to the current index since we use to pass down the index in some callback, anyway will use that.

Btw, speaking about BFP it does look like we could use for index filtering as well.

Signature · 1 line
Luiz Augusto von Dentz
author maintainer
#9 lore raw

Re: [PATCH BlueZ 4/7] monitor: Add basic decoding for Mesh Beacon

In reply to Marcel Holtmann

Hi Marcel,

Quoted 66 lines · Marcel Holtmann

Hi Luiz,

Quoted 49 lines

This adds basic decoding for Mesh Beacon packets such as:

Quoted 1 line

HCI Event: LE Meta Event (0x3e) plen 37

     LE Advertising Report (0x02)
       Num reports: 1
       Event type: Non connectable undirected - ADV_NONCONN_IND (0x03)
       Address type: Random (0x01)
       Address: 36:47:34:FC:63:DA (Non-Resolvable)
       Data length: 25
       Mesh Beacon: 00dddd0000000000000000000000000000000000000000
         Unprovisioned Device Beacon (0x00)
         Device UUID: 00dddd00000000000000000000000000
         OOB Information: 0x0000
         URI Hash: 0x0000
       RSSI: -28 dBm (0xe4)

< HCI Command: LE Set Advertising Data (0x08|0x0008) plen 32

       Length: 24
       Mesh Beacon: 0100c7005d732329eadf000000003e60e50797ef6d5c
         Secure Network Beacon (0x01)
         Flags: 0x01
         Network Id: 00c7005d732329ea
         IV Index: 0xdf000000
         Authentication Value: 003e60e50797ef6d
---
monitor/packet.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
monitor/packet.c +13 -0
index 1ec816c..3e6382e 100644
@@ -3513,6 +3513,74 @@ static const struct {
      { }
 };
 
+static const struct {
+     uint8_t bit;
+     const char *str;
+} mesh_oob_table[] = {
+     { 0, "Other"                                                    },
+     { 1, "Eletronic / URI"                                          },
+     { 2, "2D machine-readable code"                                 },
+     { 3, "Bar code"                                                 },
+     { 4, "Near Field Communication (NFC)"                           },
+     { 5, "Number"                                                   },
+     { 6, "String"                                                   },
+     { 11, "On box"                                                  },
+     { 12, "Inside box"                                              },

monitor/packet.c static const struct { · line 3538

Quoted 10 lines
monitor/packet.c +10 -0
+     { 13, "On piece of paper"                                       },
+     { 14, "Inside manual"                                           },
+     { 14, "On Device"                                               },
+     { }
+};
+
+static void print_mesh_beacon(const uint8_t *data, uint8_t len)
+{
+     int i;
+     uint16_t oob;

my preference is to have iterator variable like i last in the list.

Regards

Quoted 7 lines

Marcel

monitor/packet.c static const struct { · line 3541

Quoted 3 lines
monitor/packet.c +3 -0
+
+     if (len < 1)
+             return;

At least use print_hex_field here. General rule of btmon is to print the data. Silently swallowing is bad idea. This is no longer hcidump ;)

Well if len < 1 that means there is nothing to print, packet_hexdump won't print anything either:

if (!len)
return;

Quoted 34 lines
Quoted 34 lines
monitor/packet.c +34 -0
+
+     switch (data[0]) {
+     case 0x00:
+             print_field("  Unprovisioned Device Beacon (0x00)");
+             if (len < 18)
+                     break;
+
+             print_hex_field("  Device UUID", data, 16);
+
+             oob = get_be16(&data[16]);
+             print_field("  OOB Information: 0x%4.4x", oob);
+
+             for (i = 0; mesh_oob_table[i].str; i++) {
+                     if (oob & (1 << mesh_oob_table[i].bit))
+                             print_field("    %s", mesh_oob_table[i].str);
+             }
+
+             if (len < 22)
+                     break;
+
+             print_field("  URI Hash: 0x%4.4x", get_be32(&data[18]));
+             break;
+     case 0x01:
+             print_field("  Secure Network Beacon (0x01)");
+             if (len < 21)
+                     break;
+
+             print_field("  Flags: 0x%2.2x", data[0]);
+
+             if (data[0] & 0x01)
+                     print_field("    Key Refresh");
+
+             if (data[0] & 0x02)
+                     print_field("    IV Update");
Quoted 8 lines

monitor/packet.c static const struct { · line 3581

Quoted 6 lines
monitor/packet.c +6 -0
+
+             print_hex_field("  Network Id", &data[1], 8);
+             print_field("  IV Index: 0x%08x", get_be32(&data[9]));
+             print_hex_field("  Authentication Value", &data[13], 8);
+             break;
+     }

And this should get a default: print_hex_field.

Ive added packet_dump for every case we cannot decode.

Quoted 4 lines

Regards

Marcel

Signature · 1 line
Luiz Augusto von Dentz