linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/6] monitor: Add AD/EIR types for mesh
@ 2017-07-20 11:36 Luiz Augusto von Dentz
  2017-07-20 11:36 ` [PATCH v3 2/6] monitor: Add decoding of GATT Mesh Services Luiz Augusto von Dentz
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2017-07-20 11:36 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Print out mesh type and payload:

> 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(+)

diff --git a/monitor/packet.c b/monitor/packet.c
index a3d188a..cc24165 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -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;
-- 
2.9.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v3 2/6] monitor: Add decoding of GATT Mesh Services
  2017-07-20 11:36 [PATCH v3 1/6] monitor: Add AD/EIR types for mesh Luiz Augusto von Dentz
@ 2017-07-20 11:36 ` Luiz Augusto von Dentz
  2017-07-20 11:36 ` [PATCH v3 3/6] monitor: Filter duplicated advertisements Luiz Augusto von Dentz
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2017-07-20 11:36 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds UUIDs of GATT Mesh Provisioning Service and Mesh Proxy
Service.
---
 monitor/uuid.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/monitor/uuid.c b/monitor/uuid.c
index fb0b210..9839d03 100644
--- a/monitor/uuid.c
+++ b/monitor/uuid.c
@@ -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"				},
-- 
2.9.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v3 3/6] monitor: Filter duplicated advertisements
  2017-07-20 11:36 [PATCH v3 1/6] monitor: Add AD/EIR types for mesh Luiz Augusto von Dentz
  2017-07-20 11:36 ` [PATCH v3 2/6] monitor: Add decoding of GATT Mesh Services Luiz Augusto von Dentz
@ 2017-07-20 11:36 ` Luiz Augusto von Dentz
  2017-07-20 11:36 ` [PATCH v3 4/6] monitor: Add basic decoding for Mesh Beacon Luiz Augusto von Dentz
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2017-07-20 11:36 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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

To be able to detect duplicates this uses a cache containing
advertisements. The cache will maintain only the last advertisement per
address which expires after a 2 seconds or if a new advertisement is
found. To minimize cache lookup overhead only a maximum of 20 entries
can exist at any given time.
---
 monitor/packet.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 106 insertions(+)

diff --git a/monitor/packet.c b/monitor/packet.c
index cc24165..aa79206 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -42,7 +42,9 @@
 #include "lib/hci.h"
 #include "lib/hci_lib.h"
 
+#include "src/shared/mainloop.h"
 #include "src/shared/util.h"
+#include "src/shared/queue.h"
 #include "src/shared/btsnoop.h"
 #include "display.h"
 #include "bt.h"
@@ -100,6 +102,9 @@
 
 #define COLOR_PHY_PACKET		COLOR_BLUE
 
+#define ADV_TIMEOUT			2000
+#define ADV_MAX_CACHE			20
+
 static time_t time_offset = ((time_t) -1);
 static int priority_level = BTSNOOP_PRIORITY_INFO;
 static unsigned long filter_mask = 0;
@@ -267,11 +272,20 @@ void packet_select_index(uint16_t index)
 
 #define MAX_INDEX 16
 
+struct adv_data {
+	struct bt_hci_evt_le_adv_report evt;
+	void *data;
+	size_t frame;
+	int timeout;
+	struct queue *cache;
+};
+
 struct index_data {
 	uint8_t  type;
 	uint8_t  bdaddr[6];
 	uint16_t manufacturer;
 	size_t	frame;
+	struct queue *adv_cache;
 };
 
 static struct index_data index_list[MAX_INDEX];
@@ -8587,12 +8601,103 @@ static void le_conn_complete_evt(const void *data, uint8_t size)
 		assign_handle(le16_to_cpu(evt->handle), 0x01);
 }
 
+static void adv_free(void *data)
+{
+	struct adv_data *adv = data;
+
+	if (adv->timeout > 0)
+		mainloop_remove_timeout(adv->timeout);
+
+	free(adv->data);
+	free(adv);
+}
+
+static bool match_adv(const void *data, const void *user_data)
+{
+	const struct adv_data *adv = data;
+	const struct bt_hci_evt_le_adv_report *evt = user_data;
+
+	if (adv->evt.addr_type != evt->addr_type)
+		return false;
+
+	return memcmp(adv->evt.addr, evt->addr, sizeof(evt->addr)) == 0;
+}
+
+static bool report_cmp(struct adv_data *adv,
+			const struct bt_hci_evt_le_adv_report *evt)
+{
+	if (memcmp(&adv->evt, evt, sizeof(*evt)))
+		return false;
+
+	return memcmp(adv->data, evt->data, evt->data_len) == 0;
+}
+
+static void adv_timeout(int id, void *data)
+{
+	struct adv_data *adv = data;
+
+	adv->timeout = 0;
+
+	/* Remove from cache (adv is freed after returning) */
+	queue_remove(adv->cache, adv);
+
+	mainloop_remove_timeout(id);
+}
+
 static void le_adv_report_evt(const void *data, uint8_t size)
 {
 	const struct bt_hci_evt_le_adv_report *evt = data;
+	struct index_data *idata = &index_list[index_current];
+	struct adv_data *match;
+	struct adv_data *adv;
 	uint8_t evt_len;
 	int8_t *rssi;
 
+	if (!idata->adv_cache)
+		idata->adv_cache = queue_new();
+
+	adv = queue_remove_if(idata->adv_cache, match_adv, (void *) evt);
+	if (adv && report_cmp(adv, evt)) {
+		/* Update cache and modify expire timeout */
+		if (mainloop_modify_timeout(adv->timeout, ADV_TIMEOUT) < 0) {
+			mainloop_remove_timeout(adv->timeout);
+			adv->timeout = mainloop_add_timeout(ADV_TIMEOUT,
+							adv_timeout, adv,
+							adv_free);
+		}
+		queue_push_head(idata->adv_cache, adv);
+		print_field("Duplicate of #%zu", adv->frame);
+		size = 0;
+		goto rssi;
+	}
+
+	if (adv)
+		adv_free(adv);
+
+	match = new0(struct adv_data, 1);
+	match->evt = *evt;
+
+	match->data = malloc(evt->data_len);
+	memcpy(match->data, evt->data, evt->data_len);
+
+	match->cache = idata->adv_cache;
+	match->frame = idata->frame;
+	match->timeout = mainloop_add_timeout(ADV_TIMEOUT, adv_timeout, match,
+						adv_free);
+	if (match->timeout <= 0) {
+		print_field("Cannot cache: %s (%d)", strerror(-match->timeout),
+							match->timeout);
+		adv_free(match);
+		goto print;
+	}
+
+	queue_push_head(idata->adv_cache, match);
+
+	if (queue_length(idata->adv_cache) > ADV_MAX_CACHE)
+		queue_remove(idata->adv_cache,
+					queue_peek_tail(idata->adv_cache));
+
+print:
 	print_num_reports(evt->num_reports);
 
 report:
@@ -8602,6 +8707,7 @@ report:
 	print_field("Data length: %d", evt->data_len);
 	print_eir(evt->data, evt->data_len, true);
 
+rssi:
 	rssi = (int8_t *) (evt->data + evt->data_len);
 	print_rssi(*rssi);
 
-- 
2.9.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v3 4/6] monitor: Add basic decoding for Mesh Beacon
  2017-07-20 11:36 [PATCH v3 1/6] monitor: Add AD/EIR types for mesh Luiz Augusto von Dentz
  2017-07-20 11:36 ` [PATCH v3 2/6] monitor: Add decoding of GATT Mesh Services Luiz Augusto von Dentz
  2017-07-20 11:36 ` [PATCH v3 3/6] monitor: Filter duplicated advertisements Luiz Augusto von Dentz
@ 2017-07-20 11:36 ` Luiz Augusto von Dentz
  2017-07-20 11:36 ` [PATCH v3 5/6] monitor: Add basic decoding for Mesh Provisioning Luiz Augusto von Dentz
  2017-07-20 11:36 ` [PATCH v3 6/6] monitor: Add basic decoding for Mesh Data Luiz Augusto von Dentz
  4 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2017-07-20 11:36 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds basic decoding for Mesh Beacon packets such as:

> 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: dddd00000000000000000000000000
          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 | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 82 insertions(+), 1 deletion(-)

diff --git a/monitor/packet.c b/monitor/packet.c
index aa79206..345a7da 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -3513,6 +3513,87 @@ static const struct {
 	{ }
 };
 
+static const struct {
+	uint8_t bit;
+	const char *str;
+} mesh_oob_table[] = {
+	{ 0, "Other"							},
+	{ 1, "Electronic / 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)
+{
+	uint16_t oob;
+	int i;
+
+	print_hex_field("Mesh Beacon", data, len);
+
+	if (len < 1)
+		return;
+
+	switch (data[0]) {
+	case 0x00:
+		print_field("  Unprovisioned Device Beacon (0x00)");
+		if (len < 18) {
+			packet_hexdump(data + 1, len - 1);
+			break;
+		}
+
+		print_hex_field("  Device UUID", data + 1, 16);
+
+		oob = get_be16(data + 17);
+		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 < 23) {
+			packet_hexdump(data + 18, len - 18);
+			break;
+		}
+
+		print_field("  URI Hash: 0x%4.4x", get_be32(data + 19));
+		packet_hexdump(data + 23, len - 23);
+		break;
+	case 0x01:
+		print_field("  Secure Network Beacon (0x01)");
+		if (len < 22) {
+			packet_hexdump(data + 1, len - 1);
+			break;
+		}
+
+		print_field("  Flags: 0x%2.2x", data[0]);
+
+		if (data[1] & 0x01)
+			print_field("    Key Refresh");
+
+		if (data[1] & 0x02)
+			print_field("    IV Update");
+
+		print_hex_field("  Network Id", data + 2, 8);
+		print_field("  IV Index: 0x%08x", get_be32(data + 10));
+		print_hex_field("  Authentication Value", data + 14, 8);
+		packet_hexdump(data + 22, len - 22);
+		break;
+	default:
+		print_field("  Invalid Beacon (0x%02x)", data[0]);
+		packet_hexdump(data, len);
+	}
+}
+
 static void print_eir(const uint8_t *eir, uint8_t eir_len, bool le)
 {
 	uint16_t len = 0;
@@ -3746,7 +3827,7 @@ static void print_eir(const uint8_t *eir, uint8_t eir_len, bool le)
 			break;
 
 		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:
-- 
2.9.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v3 5/6] monitor: Add basic decoding for Mesh Provisioning
  2017-07-20 11:36 [PATCH v3 1/6] monitor: Add AD/EIR types for mesh Luiz Augusto von Dentz
                   ` (2 preceding siblings ...)
  2017-07-20 11:36 ` [PATCH v3 4/6] monitor: Add basic decoding for Mesh Beacon Luiz Augusto von Dentz
@ 2017-07-20 11:36 ` Luiz Augusto von Dentz
  2017-07-20 18:20   ` Marcel Holtmann
  2017-07-20 11:36 ` [PATCH v3 6/6] monitor: Add basic decoding for Mesh Data Luiz Augusto von Dentz
  4 siblings, 1 reply; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2017-07-20 11:36 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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

> 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 | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 92 insertions(+), 1 deletion(-)

diff --git a/monitor/packet.c b/monitor/packet.c
index 345a7da..3906eee 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -3594,6 +3594,97 @@ static void print_mesh_beacon(const uint8_t *data, uint8_t len)
 	}
 }
 
+static void print_mesh_prov(const uint8_t *data, uint8_t len)
+{
+	print_hex_field("Mesh Provisioning", data, len);
+
+	if (len < 6) {
+		packet_hexdump(data, len);
+		return;
+	}
+
+	print_field("  Link ID: 0x%08x", get_be32(data));
+	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) {
+			packet_hexdump(data + 1, len - 1);
+			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 + 4, len - 4);
+		packet_hexdump(data + 5, len - 5);
+		break;
+	case 0x01:
+		print_field("  Transaction Acknowledgment (0x01)");
+		packet_hexdump(data + 1, len - 1);
+		break;
+	case 0x02:
+		print_field("  Transaction Continuation (0x02)");
+		print_field("  SegmentIndex: %u", data[0] >> 2);
+		if (len < 2) {
+			packet_hexdump(data + 1, len - 1);
+			return;
+		}
+		print_hex_field("  Data", data + 1, len - 1);
+		packet_hexdump(data + 2, len - 2);
+		break;
+	case 0x03:
+		print_field("  Provisioning Bearer Control (0x03)");
+		switch (data[0] >> 2) {
+		case 0x00:
+			print_field("  Link Open (0x00)");
+			if (len < 17) {
+				packet_hexdump(data + 1, len - 1);
+				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) {
+				packet_hexdump(data + 1, len - 1);
+				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]);
+			}
+			packet_hexdump(data + 2, len - 2);
+			break;
+		default:
+			packet_hexdump(data + 1, len - 1);
+			break;
+		}
+		break;
+	default:
+		print_field("  Invalid Command (0x%02x)", data[0]);
+		packet_hexdump(data, len);
+		break;
+	}
+}
+
 static void print_eir(const uint8_t *eir, uint8_t eir_len, bool le)
 {
 	uint16_t len = 0;
@@ -3823,7 +3914,7 @@ static void print_eir(const uint8_t *eir, uint8_t eir_len, bool le)
 			break;
 
 		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:
-- 
2.9.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v3 6/6] monitor: Add basic decoding for Mesh Data
  2017-07-20 11:36 [PATCH v3 1/6] monitor: Add AD/EIR types for mesh Luiz Augusto von Dentz
                   ` (3 preceding siblings ...)
  2017-07-20 11:36 ` [PATCH v3 5/6] monitor: Add basic decoding for Mesh Provisioning Luiz Augusto von Dentz
@ 2017-07-20 11:36 ` Luiz Augusto von Dentz
  4 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2017-07-20 11:36 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds basic decoding for Mesh Data packets such as:

> 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 | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/monitor/packet.c b/monitor/packet.c
index 3906eee..9bac689 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -3685,6 +3685,18 @@ static void print_mesh_prov(const uint8_t *data, uint8_t len)
 	}
 }
 
+static void print_mesh_data(const uint8_t *data, uint8_t len)
+{
+	print_hex_field("Mesh Data", data, len);
+
+	if (len < 1)
+		return;
+
+	print_field("  IV: %u", data[0] & 0x01);
+	print_field("  NID: 0x%2.2x", data[0] & 0xfe);
+	packet_hexdump(data + 1, len - 1);
+}
+
 static void print_eir(const uint8_t *eir, uint8_t eir_len, bool le)
 {
 	uint16_t len = 0;
@@ -3910,7 +3922,7 @@ static void print_eir(const uint8_t *eir, uint8_t eir_len, bool le)
 			break;
 
 		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:
-- 
2.9.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 5/6] monitor: Add basic decoding for Mesh Provisioning
  2017-07-20 11:36 ` [PATCH v3 5/6] monitor: Add basic decoding for Mesh Provisioning Luiz Augusto von Dentz
@ 2017-07-20 18:20   ` Marcel Holtmann
  0 siblings, 0 replies; 7+ messages in thread
From: Marcel Holtmann @ 2017-07-20 18:20 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth

Hi Luiz,

> 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
> 
>> 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 | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 92 insertions(+), 1 deletion(-)
> 
> diff --git a/monitor/packet.c b/monitor/packet.c
> index 345a7da..3906eee 100644
> --- a/monitor/packet.c
> +++ b/monitor/packet.c
> @@ -3594,6 +3594,97 @@ static void print_mesh_beacon(const uint8_t *data, uint8_t len)
> 	}
> }
> 
> +static void print_mesh_prov(const uint8_t *data, uint8_t len)
> +{
> +	print_hex_field("Mesh Provisioning", data, len);
> +
> +	if (len < 6) {
> +		packet_hexdump(data, len);
> +		return;
> +	}
> +
> +	print_field("  Link ID: 0x%08x", get_be32(data));
> +	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) {
> +			packet_hexdump(data + 1, len - 1);
> +			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 + 4, len - 4);
> +		packet_hexdump(data + 5, len - 5);
> +		break;
> +	case 0x01:
> +		print_field("  Transaction Acknowledgment (0x01)");
> +		packet_hexdump(data + 1, len - 1);
> +		break;
> +	case 0x02:
> +		print_field("  Transaction Continuation (0x02)");
> +		print_field("  SegmentIndex: %u", data[0] >> 2);
> +		if (len < 2) {
> +			packet_hexdump(data + 1, len - 1);
> +			return;
> +		}
> +		print_hex_field("  Data", data + 1, len - 1);
> +		packet_hexdump(data + 2, len - 2);
> +		break;
> +	case 0x03:
> +		print_field("  Provisioning Bearer Control (0x03)");
> +		switch (data[0] >> 2) {
> +		case 0x00:
> +			print_field("  Link Open (0x00)");
> +			if (len < 17) {
> +				packet_hexdump(data + 1, len - 1);
> +				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) {
> +				packet_hexdump(data + 1, len - 1);
> +				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]);

look default: labels also deserve a break.

Regards

Marcel


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-07-20 18:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-20 11:36 [PATCH v3 1/6] monitor: Add AD/EIR types for mesh Luiz Augusto von Dentz
2017-07-20 11:36 ` [PATCH v3 2/6] monitor: Add decoding of GATT Mesh Services Luiz Augusto von Dentz
2017-07-20 11:36 ` [PATCH v3 3/6] monitor: Filter duplicated advertisements Luiz Augusto von Dentz
2017-07-20 11:36 ` [PATCH v3 4/6] monitor: Add basic decoding for Mesh Beacon Luiz Augusto von Dentz
2017-07-20 11:36 ` [PATCH v3 5/6] monitor: Add basic decoding for Mesh Provisioning Luiz Augusto von Dentz
2017-07-20 18:20   ` Marcel Holtmann
2017-07-20 11:36 ` [PATCH v3 6/6] monitor: Add basic decoding for Mesh Data Luiz Augusto von Dentz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).