2017-06-13 13:18:10

by Michał Narajowski

[permalink] [raw]
Subject: [PATCH BlueZ v2 0/7] monitor: Bluetooth 5 HCI commands support

This set adds support for decoding Bluetooth 5 commands as listed below.
Changes since v1:
-squash patches as requested
-fix coding style issues and review comments
-add legacy pdu decoding


Michał Narajowski (7):
monitor: Add LE Enhanced Test commands decoding
monitor: Add LE Extended Advertising commands decoding
monitor: Add LE Set Periodic Advertising commands decoding
monitor: Add LE Extended Scan commands decoding
monitor: Add LE Periodic Advertising commands decoding
monitor: Add LE RF commands decoding
monitor: Add LE Set Privacy Mode decoding

monitor/bt.h | 253 ++++++++++
monitor/packet.c | 1383 +++++++++++++++++++++++++++++++++++++++++++++++-------
2 files changed, 1472 insertions(+), 164 deletions(-)

--
2.9.3



2017-06-13 13:18:13

by Michał Narajowski

[permalink] [raw]
Subject: [PATCH BlueZ v2 3/7] monitor: Add LE Set Periodic Advertising commands decoding

monitor: Add LE Set Periodic Advertising Parameters decoding

< HCI Command: LE Set Periodic Advertising Parameters (0x08|0x003e) plen 7
Handle: 1
Min interval: 2.50 msec (0x0002)
Max interval: 318.75 msec (0x00ff)
Properties: 0x00ff
Include TxPower
Unknown advertising properties (0x00bf)

monitor: Add LE Set Periodic Advertising Data decoding

< HCI Command: LE Set Periodic Advertising Data (0x08|0x003f) plen 7
Handle: 1
Handle: 0x01
Operation: Last fragment
Data length: 0x04
ff 00 ff 00 ....

monitor: Add LE Set Periodic Advertising Enable decoding

< HCI Command: LE Set Periodic Advertising Enable (0x08|0x0040) plen 2
Enable: Enabled
Handle: 2
---
monitor/bt.h | 21 ++++++++++++
monitor/packet.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 120 insertions(+), 3 deletions(-)

diff --git a/monitor/bt.h b/monitor/bt.h
index aa55579..5eb07d6 100644
--- a/monitor/bt.h
+++ b/monitor/bt.h
@@ -2253,6 +2253,27 @@ struct bt_hci_cmd_le_remove_adv_set {

#define BT_HCI_CMD_LE_CLEAR_ADV_SETS 0x203d

+#define BT_HCI_CMD_LE_SET_PERIODIC_ADV_PARAMS 0x203e
+struct bt_hci_cmd_le_set_periodic_adv_params {
+ uint8_t handle;
+ uint16_t min_interval;
+ uint16_t max_interval;
+ uint16_t properties;
+} __attribute__ ((packed));
+
+#define BT_HCI_CMD_LE_SET_PERIODIC_ADV_DATA 0x203f
+struct bt_hci_cmd_le_set_periodic_adv_data {
+ uint8_t handle;
+ uint8_t operation;
+ uint8_t data_len;
+} __attribute__ ((packed));
+
+#define BT_HCI_CMD_LE_SET_PERIODIC_ADV_ENABLE 0x2040
+struct bt_hci_cmd_le_set_periodic_adv_enable {
+ uint8_t enable;
+ uint8_t handle;
+} __attribute__ ((packed));
+
#define BT_HCI_EVT_INQUIRY_COMPLETE 0x01
struct bt_hci_evt_inquiry_complete {
uint8_t status;
diff --git a/monitor/packet.c b/monitor/packet.c
index 8827f5e..cccc69c 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -7280,6 +7280,96 @@ static void le_remove_adv_set_cmd(const void *data, uint8_t size)
print_handle(cmd->handle);
}

+static const struct {
+ uint8_t bit;
+ const char *str;
+} periodic_adv_properties_table[] = {
+ { 6, "Include TxPower" },
+ { }
+};
+
+static void print_periodic_adv_properties(uint16_t flags)
+{
+ uint16_t mask = flags;
+ int i;
+
+ print_field("Properties: 0x%4.4x", flags);
+
+ for (i = 0; periodic_adv_properties_table[i].str; i++) {
+ if (flags & (1 << periodic_adv_properties_table[i].bit)) {
+ print_field(" %s",
+ periodic_adv_properties_table[i].str);
+ mask &= ~(1 << periodic_adv_properties_table[i].bit);
+ }
+ }
+
+ if (mask)
+ print_text(COLOR_UNKNOWN_ADV_FLAG,
+ " Unknown advertising properties (0x%4.4x)",
+ mask);
+}
+
+static void le_set_periodic_adv_params_cmd(const void *data, uint8_t size)
+{
+ const struct bt_hci_cmd_le_set_periodic_adv_params *cmd = data;
+
+ print_handle(cmd->handle);
+ print_slot_125("Min interval", cmd->min_interval);
+ print_slot_125("Max interval", cmd->max_interval);
+ print_periodic_adv_properties(cmd->properties);
+}
+
+static void le_set_periodic_adv_data_cmd(const void *data, uint8_t size)
+{
+ const struct bt_hci_cmd_le_set_periodic_adv_data *cmd = data;
+ const char *str;
+
+ print_handle(cmd->handle);
+
+ print_field("Handle: 0x%2.2x", cmd->handle);
+ switch (cmd->operation) {
+ case 0x00:
+ str = "Immediate fragment";
+ break;
+ case 0x01:
+ str = "First fragment";
+ break;
+ case 0x02:
+ str = "Last fragment";
+ break;
+ case 0x03:
+ str = "Complete ext advertising data";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+ print_field("Operation: %s", str);
+ print_field("Data length: 0x%2.2x", cmd->data_len);
+ packet_hexdump(data + 3, size - 3);
+}
+
+static void le_set_periodic_adv_enable_cmd(const void *data, uint8_t size)
+{
+ const struct bt_hci_cmd_le_set_periodic_adv_enable *cmd = data;
+ const char *str;
+
+ switch (cmd->enable) {
+ case 0x00:
+ str = "Disable";
+ break;
+ case 0x01:
+ str = "Enabled";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+
+ print_field("Enable: %s", str);
+ print_handle(cmd->handle);
+}
+
struct opcode_data {
uint16_t opcode;
int bit;
@@ -8016,9 +8106,15 @@ static const struct opcode_data opcode_table[] = {
{ 0x203d, 297, "LE Clear Advertising Sets",
null_cmd, 0, true,
status_rsp, 1, true },
- { 0x203e, 298, "LE Set Periodic Advertising Parameters" },
- { 0x203f, 299, "LE Set Periodic Advertising Data" },
- { 0x2040, 300, "LE Set Periodic Advertising Enable" },
+ { 0x203e, 298, "LE Set Periodic Advertising Parameters",
+ le_set_periodic_adv_params_cmd, 7, true,
+ status_rsp, 1, true },
+ { 0x203f, 299, "LE Set Periodic Advertising Data",
+ le_set_periodic_adv_data_cmd, 3, false,
+ status_rsp, 1, true },
+ { 0x2040, 300, "LE Set Periodic Advertising Enable",
+ le_set_periodic_adv_enable_cmd, 2, true,
+ status_rsp, 1, true },
{ 0x2041, 301, "LE Set Extended Scan Parameters" },
{ 0x2042, 302, "LE Set Extended Scan Enable" },
{ 0x2043, 303, "LE Extended Create Connection" },
--
2.9.3


2017-06-13 13:18:16

by Michał Narajowski

[permalink] [raw]
Subject: [PATCH BlueZ v2 6/7] monitor: Add LE RF commands decoding

monitor: Add LE Read Transmit Power decoding

monitor: Add LE Read RF Path Compensation decoding

monitor: Add LE Write RF Path Compensation decoding

< HCI Command: LE Write RF Path Compensation (0x08|0x004d) plen 4
RF Tx Path Compensation Value: 0x0201
RF Rx Path Compensation Value: 0x0403
---
monitor/bt.h | 20 ++++++++++++++++++++
monitor/packet.c | 42 +++++++++++++++++++++++++++++++++++++++---
2 files changed, 59 insertions(+), 3 deletions(-)

diff --git a/monitor/bt.h b/monitor/bt.h
index 7fe5673..61308e9 100644
--- a/monitor/bt.h
+++ b/monitor/bt.h
@@ -2353,6 +2353,26 @@ struct bt_hci_rsp_le_read_dev_periodic_adv_list_size {
uint8_t list_size;
} __attribute__ ((packed));

+#define BT_HCI_CMD_LE_READ_TX_POWER 0x204b
+struct bt_hci_rsp_le_read_tx_power {
+ uint8_t status;
+ uint8_t min_tx_power;
+ uint8_t max_tx_power;
+} __attribute__ ((packed));
+
+#define BT_HCI_CMD_LE_READ_RF_PATH_COMPENSATION 0x204c
+struct bt_hci_rsp_le_read_rf_path_comp {
+ uint8_t status;
+ uint16_t rf_tx_path_comp;
+ uint16_t rf_rx_path_comp;
+} __attribute__ ((packed));
+
+#define BT_HCI_CMD_LE_WRITE_RF_PATH_COMPENSATION 0x204d
+struct bt_hci_cmd_le_write_rf_path_comp {
+ uint16_t rf_tx_path_comp;
+ uint16_t rf_rx_path_comp;
+} __attribute__ ((packed));
+
#define BT_HCI_EVT_INQUIRY_COMPLETE 0x01
struct bt_hci_evt_inquiry_complete {
uint8_t status;
diff --git a/monitor/packet.c b/monitor/packet.c
index 9a75e43..582320b 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -7623,6 +7623,36 @@ static void le_read_periodic_adv_list_size_rsp(const void *data, uint8_t size)
print_field("List size: 0x%2.2x", rsp->list_size);
}

+static void le_read_tx_power_rsp(const void *data, uint8_t size)
+{
+ const struct bt_hci_rsp_le_read_tx_power *rsp = data;
+
+ print_status(rsp->status);
+ print_field("Min Tx power: %d dBm", rsp->min_tx_power);
+ print_field("Max Tx power: %d dBm", rsp->max_tx_power);
+}
+
+static void le_read_rf_path_comp_rsp(const void *data, uint8_t size)
+{
+ const struct bt_hci_rsp_le_read_rf_path_comp *rsp = data;
+
+ print_status(rsp->status);
+ print_field("RF Tx Path Compensation Value: 0x%4.4x",
+ rsp->rf_tx_path_comp);
+ print_field("RF Rx Path Compensation Value: 0x%4.4x",
+ rsp->rf_rx_path_comp);
+}
+
+static void le_write_rf_path_comp_cmd(const void *data, uint8_t size)
+{
+ const struct bt_hci_cmd_le_write_rf_path_comp *cmd = data;
+
+ print_field("RF Tx Path Compensation Value: 0x%4.4x",
+ cmd->rf_tx_path_comp);
+ print_field("RF Rx Path Compensation Value: 0x%4.4x",
+ cmd->rf_rx_path_comp);
+}
+
struct opcode_data {
uint16_t opcode;
int bit;
@@ -8398,9 +8428,15 @@ static const struct opcode_data opcode_table[] = {
{ 0x204a, 310, "LE Read Periodic Advertiser List Size",
null_cmd, 0, true,
le_read_periodic_adv_list_size_rsp, 2, true },
- { 0x204b, 311, "LE Read Transmit Power" },
- { 0x204c, 312, "LE Read RF Path Compensation" },
- { 0x204d, 313, "LE Write RF Path Compensation" },
+ { 0x204b, 311, "LE Read Transmit Power",
+ null_cmd, 0, true,
+ le_read_tx_power_rsp, 3, true },
+ { 0x204c, 312, "LE Read RF Path Compensation",
+ null_cmd, 0, true,
+ le_read_rf_path_comp_rsp, 5, true },
+ { 0x204d, 313, "LE Write RF Path Compensation",
+ le_write_rf_path_comp_cmd, 4, true,
+ status_rsp, 1, true },
{ 0x204e, 314, "LE Set Privacy Mode" },
{ }
};
--
2.9.3


2017-06-13 13:18:14

by Michał Narajowski

[permalink] [raw]
Subject: [PATCH BlueZ v2 4/7] monitor: Add LE Extended Scan commands decoding

monitor: Add LE Set Extended Scan Parameters decoding

< HCI Command: LE Set Extended Scan Parameters (0x08|0x0041) plen 13
Own address type: Random (0x01)
Filter policy: Reserved (0x09)
PHYs: 0x05
LE 1M
LE Coded
Entry 0
Type: Reserved (0x03)
Interval: 491.250 msec (0x0312)
Window: 320.625 msec (0x0201)
Entry 1
Type: Active (0x01)
Interval: 0.625 msec (0x0001)
Window: 0.625 msec (0x0001)

monitor: Add LE Set Extended Scan Enable decoding

< HCI Command: LE Set Extended Scan Enable (0x08|0x0042) plen 6
Extended scan: Enabled
Filter duplicates: Disabled (0x00)
Duration: 0 msec (0x0000)
Period: 0.00 sec (0x0000)

monitor: Add LE Extended Create Connection decoding

< HCI Command: LE Extended Create Connection (0x08|0x0043) plen 24
Filter policy: White list is used (0x01)
Own address type: Public (0x02)
Peer address type: Reserved (0xff)
Peer address: 00-00-00-00-00-00
Initiating PHYs: 0x01
LE 1M
Scan interval: 1.250 msec (0x0002)
Scan window: 1601.875 msec (0x0a03)
Min connection interval: 3212.50 msec (0x0a0a)
Max connection interval: 3212.50 msec (0x0a0a)
Connection latency: 0x010a
Supervision timeout: 7700 msec (0x0302)
Min connection length: 802.500 msec (0x0504)
Max connection length: 5123.750 msec (0x2006)

monitor: Add LE Extended Advertising Report Event decoding
---
monitor/bt.h | 58 ++++++++
monitor/packet.c | 407 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 448 insertions(+), 17 deletions(-)

diff --git a/monitor/bt.h b/monitor/bt.h
index 5eb07d6..0aaa58b 100644
--- a/monitor/bt.h
+++ b/monitor/bt.h
@@ -2274,6 +2274,45 @@ struct bt_hci_cmd_le_set_periodic_adv_enable {
uint8_t handle;
} __attribute__ ((packed));

+#define BT_HCI_CMD_LE_SET_EXT_SCAN_PARAMS 0x2041
+struct bt_hci_cmd_le_set_ext_scan_params {
+ uint8_t own_addr_type;
+ uint8_t filter_policy;
+ uint8_t num_phys;
+} __attribute__ ((packed));
+struct bt_hci_le_scan_phy {
+ uint8_t type;
+ uint16_t interval;
+ uint16_t window;
+} __attribute__ ((packed));
+
+#define BT_HCI_CMD_LE_SET_EXT_SCAN_ENABLE 0x2042
+struct bt_hci_cmd_le_set_ext_scan_enable {
+ uint8_t enable;
+ uint8_t filter_dup;
+ uint16_t duration;
+ uint16_t period;
+} __attribute__ ((packed));
+
+#define BT_HCI_CMD_LE_EXT_CREATE_CONN 0x2043
+struct bt_hci_cmd_le_ext_create_conn {
+ uint8_t filter_policy;
+ uint8_t own_addr_type;
+ uint8_t peer_addr_type;
+ uint8_t peer_addr[6];
+ uint8_t phys;
+} __attribute__ ((packed));
+struct bt_hci_le_ext_create_conn {
+ uint8_t scan_interval;
+ uint16_t scan_window;
+ uint16_t min_interval;
+ uint16_t max_interval;
+ uint16_t latency;
+ uint16_t supv_timeout;
+ uint16_t min_length;
+ uint16_t max_length;
+} __attribute__ ((packed));
+
#define BT_HCI_EVT_INQUIRY_COMPLETE 0x01
struct bt_hci_evt_inquiry_complete {
uint8_t status;
@@ -2884,6 +2923,25 @@ struct bt_hci_evt_le_phy_update_complete {
uint8_t rx_phy;
} __attribute__ ((packed));

+#define BT_HCI_EVT_LE_EXT_ADV_REPORT 0x0d
+struct bt_hci_evt_le_ext_adv_report {
+ uint8_t num_reports;
+} __attribute__ ((packed));
+struct bt_hci_le_ext_adv_report {
+ uint16_t event_type;
+ uint8_t addr_type;
+ uint8_t addr[6];
+ uint8_t primary_phy;
+ uint8_t secondary_phy;
+ uint8_t sid;
+ uint8_t tx_power;
+ int8_t rssi;
+ uint16_t interval;
+ uint8_t direct_addr_type;
+ uint8_t direct_addr[6];
+ uint8_t data_len;
+} __attribute__ ((packed));
+
#define BT_HCI_EVT_LE_ADV_SET_TERM 0x12
struct bt_hci_evt_le_adv_set_term {
uint8_t status;
diff --git a/monitor/packet.c b/monitor/packet.c
index cccc69c..2a970e6 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -2304,7 +2304,7 @@ static void print_num_reports(uint8_t num_reports)
print_field("Num reports: %d", num_reports);
}

-static void print_adv_event_type(uint8_t type)
+static void print_adv_event_type(const char *label, uint8_t type)
{
const char *str;

@@ -2329,7 +2329,7 @@ static void print_adv_event_type(uint8_t type)
break;
}

- print_field("Event type: %s (0x%2.2x)", str, type);
+ print_field("%s: %s (0x%2.2x)", label, str, type);
}

static void print_rssi(int8_t rssi)
@@ -6283,12 +6283,11 @@ static void le_set_adv_enable_cmd(const void *data, uint8_t size)
print_field("Advertising: %s (0x%2.2x)", str, cmd->enable);
}

-static void le_set_scan_parameters_cmd(const void *data, uint8_t size)
+static void print_scan_type(const char *label, uint8_t type)
{
- const struct bt_hci_cmd_le_set_scan_parameters *cmd = data;
const char *str;

- switch (cmd->type) {
+ switch (type) {
case 0x00:
str = "Passive";
break;
@@ -6300,13 +6299,14 @@ static void le_set_scan_parameters_cmd(const void *data, uint8_t size)
break;
}

- print_field("Type: %s (0x%2.2x)", str, cmd->type);
+ print_field("%s: %s (0x%2.2x)", label, str, type);
+}

- print_interval(cmd->interval);
- print_window(cmd->window);
- print_own_addr_type(cmd->own_addr_type);
+static void print_scan_filter_policy(uint8_t policy)
+{
+ const char *str;

- switch (cmd->filter_policy) {
+ switch (policy) {
case 0x00:
str = "Accept all advertisement";
break;
@@ -6324,7 +6324,18 @@ static void le_set_scan_parameters_cmd(const void *data, uint8_t size)
break;
}

- print_field("Filter policy: %s (0x%2.2x)", str, cmd->filter_policy);
+ print_field("Filter policy: %s (0x%2.2x)", str, policy);
+}
+
+static void le_set_scan_parameters_cmd(const void *data, uint8_t size)
+{
+ const struct bt_hci_cmd_le_set_scan_parameters *cmd = data;
+
+ print_scan_type("Type", cmd->type);
+ print_interval(cmd->interval);
+ print_window(cmd->window);
+ print_own_addr_type(cmd->own_addr_type);
+ print_scan_filter_policy(cmd->filter_policy);
}

static void le_set_scan_enable_cmd(const void *data, uint8_t size)
@@ -7370,6 +7381,187 @@ static void le_set_periodic_adv_enable_cmd(const void *data, uint8_t size)
print_handle(cmd->handle);
}

+static const struct {
+ uint8_t bit;
+ const char *str;
+} ext_scan_phys_table[] = {
+ { 0, "LE 1M" },
+ { 2, "LE Coded" },
+ { }
+};
+
+static int print_ext_scan_phys(uint8_t flags)
+{
+ uint8_t mask = flags;
+ int bits_set = 0;
+ int i;
+
+ print_field("PHYs: 0x%2.2x", flags);
+
+ for (i = 0; ext_scan_phys_table[i].str; i++) {
+ if (flags & (1 << ext_scan_phys_table[i].bit)) {
+ print_field(" %s", ext_scan_phys_table[i].str);
+ mask &= ~(1 << ext_scan_phys_table[i].bit);
+ ++bits_set;
+ }
+ }
+
+ if (mask)
+ print_text(COLOR_UNKNOWN_ADV_FLAG, " Unknown scanning PHYs"
+ " (0x%2.2x)", mask);
+ return bits_set;
+}
+
+static void le_set_ext_scan_params_cmd(const void *data, uint8_t size)
+{
+ const struct bt_hci_cmd_le_set_ext_scan_params *cmd = data;
+ const struct bt_hci_le_scan_phy *scan_phy;
+ int num_structs;
+ int i;
+
+ print_own_addr_type(cmd->own_addr_type);
+ print_scan_filter_policy(cmd->filter_policy);
+ num_structs = print_ext_scan_phys(cmd->num_phys);
+
+ for (i = 0; i < num_structs; ++i) {
+ print_field("Entry %d", i);
+ scan_phy = data + 3 + i * sizeof(struct bt_hci_le_scan_phy);
+
+ print_scan_type(" Type", scan_phy->type);
+ print_slot_625(" Interval", scan_phy->interval);
+ print_slot_625(" Window", scan_phy->window);
+ }
+}
+
+static void print_enable(const char *label, uint8_t enable)
+{
+ const char *str;
+
+ switch (enable) {
+ case 0x00:
+ str = "Disable";
+ break;
+ case 0x01:
+ str = "Enabled";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+
+ print_field("%s: %s", label, str);
+}
+
+static void print_filter_dup(uint8_t filter_dup)
+{
+ const char *str;
+
+ switch (filter_dup) {
+ case 0x00:
+ str = "Disabled";
+ break;
+ case 0x01:
+ str = "Enabled";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+
+ print_field("Filter duplicates: %s (0x%2.2x)", str, filter_dup);
+}
+
+static void le_set_ext_scan_enable_cmd(const void *data, uint8_t size)
+{
+ const struct bt_hci_cmd_le_set_ext_scan_enable *cmd = data;
+
+ print_enable("Extended scan", cmd->enable);
+ print_filter_dup(cmd->filter_dup);
+
+ print_field("Duration: %d msec (0x%4.4x)",
+ le16_to_cpu(cmd->duration) * 10,
+ le16_to_cpu(cmd->duration));
+ print_field("Period: %.2f sec (0x%4.4x)",
+ le16_to_cpu(cmd->period) * 1.28,
+ le16_to_cpu(cmd->period));
+}
+
+static const struct {
+ uint8_t bit;
+ const char *str;
+} ext_conn_phys_table[] = {
+ { 0, "LE 1M" },
+ { 1, "LE 2M" },
+ { 2, "LE Coded" },
+ { }
+};
+
+static int print_ext_conn_phys(uint8_t flags)
+{
+ uint8_t mask = flags;
+ int bits_set = 0;
+ int i;
+
+ print_field("Initiating PHYs: 0x%2.2x", flags);
+
+ for (i = 0; ext_conn_phys_table[i].str; i++) {
+ if (flags & (1 << ext_conn_phys_table[i].bit)) {
+ print_field(" %s", ext_conn_phys_table[i].str);
+ mask &= ~(1 << ext_conn_phys_table[i].bit);
+ ++bits_set;
+ }
+ }
+
+ if (mask)
+ print_text(COLOR_UNKNOWN_ADV_FLAG, " Unknown scanning PHYs"
+ " (0x%2.2x)", mask);
+ return bits_set;
+}
+
+static void le_ext_create_conn_cmd(const void *data, uint8_t size)
+{
+ const struct bt_hci_cmd_le_ext_create_conn *cmd = data;
+ const struct bt_hci_le_ext_create_conn *entry;
+ const char *str;
+ int num_entries;
+ int i;
+
+ switch (cmd->filter_policy) {
+ case 0x00:
+ str = "White list is not used";
+ break;
+ case 0x01:
+ str = "White list is used";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+
+ print_field("Filter policy: %s (0x%2.2x)", str, cmd->filter_policy);
+
+ print_own_addr_type(cmd->own_addr_type);
+ print_peer_addr_type("Peer address type", cmd->peer_addr_type);
+ print_addr("Peer address", cmd->peer_addr, cmd->peer_addr_type);
+ num_entries = print_ext_conn_phys(cmd->phys);
+
+ for (i = 0; i < num_entries; ++i) {
+ entry = data + 10 + i * sizeof(*entry);
+
+ print_slot_625("Scan interval", entry->scan_interval);
+ print_slot_625("Scan window", entry->scan_window);
+ print_slot_125("Min connection interval", entry->min_interval);
+ print_slot_125("Max connection interval", entry->max_interval);
+ print_field("Connection latency: 0x%4.4x",
+ le16_to_cpu(entry->latency));
+ print_field("Supervision timeout: %d msec (0x%4.4x)",
+ le16_to_cpu(entry->supv_timeout) * 10,
+ le16_to_cpu(entry->supv_timeout));
+ print_slot_625("Min connection length", entry->min_length);
+ print_slot_625("Max connection length", entry->max_length);
+ }
+}
+
struct opcode_data {
uint16_t opcode;
int bit;
@@ -8115,9 +8307,15 @@ static const struct opcode_data opcode_table[] = {
{ 0x2040, 300, "LE Set Periodic Advertising Enable",
le_set_periodic_adv_enable_cmd, 2, true,
status_rsp, 1, true },
- { 0x2041, 301, "LE Set Extended Scan Parameters" },
- { 0x2042, 302, "LE Set Extended Scan Enable" },
- { 0x2043, 303, "LE Extended Create Connection" },
+ { 0x2041, 301, "LE Set Extended Scan Parameters",
+ le_set_ext_scan_params_cmd, 3, false,
+ status_rsp, 1, true },
+ { 0x2042, 302, "LE Set Extended Scan Enable",
+ le_set_ext_scan_enable_cmd, 6, true,
+ status_rsp, 1, true },
+ { 0x2043, 303, "LE Extended Create Connection",
+ le_ext_create_conn_cmd, 10, false,
+ status_rsp, 1, true },
{ 0x2044, 304, "LE Periodic Advertising Create Sync" },
{ 0x2045, 305, "LE Periodic Advertising Create Sync Cancel" },
{ 0x2046, 306, "LE Periodic Advertising Terminate Sync" },
@@ -9093,7 +9291,7 @@ static void le_adv_report_evt(const void *data, uint8_t size)
print_num_reports(evt->num_reports);

report:
- print_adv_event_type(evt->event_type);
+ print_adv_event_type("Event type", evt->event_type);
print_peer_addr_type("Address type", evt->addr_type);
print_addr("Address", evt->addr, evt->addr_type);
print_field("Data length: %d", evt->data_len);
@@ -9211,7 +9409,7 @@ static void le_direct_adv_report_evt(const void *data, uint8_t size)

print_num_reports(evt->num_reports);

- print_adv_event_type(evt->event_type);
+ print_adv_event_type("Event type", evt->event_type);
print_peer_addr_type("Address type", evt->addr_type);
print_addr("Address", evt->addr, evt->addr_type);
print_addr_type("Direct address type", evt->direct_addr_type);
@@ -9232,6 +9430,180 @@ static void le_phy_update_complete_evt(const void *data, uint8_t size)
print_le_phy("RX PHY", evt->rx_phy);
}

+static const struct {
+ uint8_t bit;
+ const char *str;
+} ext_adv_report_evt_type[] = {
+ { 0, "Connectable" },
+ { 1, "Scannable" },
+ { 2, "Directed" },
+ { 3, "Scan response" },
+ { 4, "Use legacy advertising PDUs" },
+ { }
+};
+
+static void print_ext_adv_report_evt_type(const char *indent, uint16_t flags)
+{
+ uint16_t mask = flags;
+ uint8_t data_status;
+ const char *str;
+ int i;
+
+ print_field("%sEvent type: 0x%4.4x", indent, flags);
+
+ for (i = 0; ext_adv_report_evt_type[i].str; i++) {
+ if (flags & (1 << ext_adv_report_evt_type[i].bit)) {
+ print_field("%s %s", indent,
+ ext_adv_report_evt_type[i].str);
+ mask &= ~(1 << ext_adv_report_evt_type[i].bit);
+ }
+ }
+
+ data_status = (flags >> 5) & 3;
+ mask &= ~(data_status << 5);
+
+ switch (data_status) {
+ case 0x00:
+ str = "Complete";
+ break;
+ case 0x01:
+ str = "Incomplete, more data to come";
+ break;
+ case 0x02:
+ str = "Incomplete, data truncated, no more to come";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+
+ print_field("%s Data status: %s", indent, str);
+
+ if (mask)
+ print_text(COLOR_UNKNOWN_ADV_FLAG,
+ "%s Reserved (0x%4.4x)", indent, mask);
+}
+
+static void print_legacy_adv_report_pdu(uint16_t flags)
+{
+ const char *str;
+
+ if (!(flags & (1 << 4)))
+ return;
+
+ switch (flags) {
+ case 0x10:
+ str = "ADV_NONCONN_IND";
+ break;
+ case 0x12:
+ str = "ADV_SCAN_IND";
+ break;
+ case 0x13:
+ str = "ADV_IND";
+ break;
+ case 0x15:
+ str = "ADV_DIRECT_IND";
+ break;
+ case 0x1a:
+ str = "SCAN_RSP to an ADV_IND";
+ break;
+ case 0x1b:
+ str = "SCAN_RSP to an ADV_SCAN_IND";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+
+ print_field(" Legacy PDU Type: %s (0x%4.4x)", str, flags);
+}
+
+static void le_ext_adv_report_evt(const void *data, uint8_t size)
+{
+ const struct bt_hci_evt_le_ext_adv_report *evt = data;
+ const struct bt_hci_le_ext_adv_report *report;
+ const char *str;
+ int i;
+
+ print_num_reports(evt->num_reports);
+
+ data += sizeof(evt->num_reports);
+
+ for (i = 0; i < evt->num_reports; ++i) {
+ report = data;
+ print_field("Entry %d", i);
+ print_ext_adv_report_evt_type(" ", report->event_type);
+ print_legacy_adv_report_pdu(report->event_type);
+ print_peer_addr_type(" Address type", report->addr_type);
+ print_addr(" Address", report->addr, report->addr_type);
+
+ switch (report->primary_phy) {
+ case 0x01:
+ str = "LE 1M";
+ break;
+ case 0x03:
+ str = "LE Coded";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+
+ print_field(" Primary PHY: %s", str);
+
+ switch (report->secondary_phy) {
+ case 0x00:
+ str = "No packets";
+ break;
+ case 0x01:
+ str = "LE 1M";
+ break;
+ case 0x02:
+ str = "LE 2M";
+ break;
+ case 0x03:
+ str = "LE Coded";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+
+ print_field(" Secondary PHY: %s", str);
+
+ if (report->sid == 0xff)
+ print_field(" SID: no ADI field (0x%2.2x)",
+ report->sid);
+ else if (report->sid > 0x0f)
+ print_field(" SID: Reserved (0x%2.2x)", report->sid);
+ else
+ print_field(" SID: 0x%2.2x", report->sid);
+
+ print_field(" TX power: %d dBm", report->tx_power);
+
+ if (report->rssi == 127)
+ print_field(" RSSI: not available (0x%2.2x)",
+ (uint8_t) report->rssi);
+ else if (report->rssi >= -127 && report->rssi <= 20)
+ print_field(" RSSI: %d dBm (0x%2.2x)",
+ report->rssi, (uint8_t) report->rssi);
+ else
+ print_field(" RSSI: reserved (0x%2.2x)",
+ (uint8_t) report->rssi);
+
+ print_slot_125(" Periodic advertising invteral",
+ report->interval);
+ print_peer_addr_type(" Direct address type",
+ report->direct_addr_type);
+ print_addr(" Direct address", report->direct_addr,
+ report->direct_addr_type);
+ print_field(" Data length: 0x%2.2x", report->data_len);
+ data += sizeof(struct bt_hci_le_ext_adv_report);
+ packet_hexdump(data, report->data_len);
+ data += report->data_len;
+ }
+}
+
static void le_adv_set_term_evt(const void *data, uint8_t size)
{
const struct bt_hci_evt_le_adv_set_term *evt = data;
@@ -9343,7 +9715,8 @@ static const struct subevent_data le_meta_event_table[] = {
le_direct_adv_report_evt, 1, false },
{ 0x0c, "LE PHY Update Complete",
le_phy_update_complete_evt, 5, true},
- { 0x0d, "LE Extended Advertising Report" },
+ { 0x0d, "LE Extended Advertising Report",
+ le_ext_adv_report_evt, 1, false},
{ 0x0e, "LE Periodic Advertising Sync Established" },
{ 0x0f, "LE Periodic Advertising Report" },
{ 0x10, "LE Periodic Advertising Sync Lost" },
--
2.9.3


2017-06-13 13:18:17

by Michał Narajowski

[permalink] [raw]
Subject: [PATCH BlueZ v2 7/7] monitor: Add LE Set Privacy Mode decoding

< HCI Command: LE Set Privacy Mode (0x08|0x004e) plen 8
Peer Identity address type: Random (0x01)
Peer Identity address: 07:06:05:04:03:02 (Non-Resolvable)
Privacy Mode: Reserved (0x08)
---
monitor/bt.h | 7 +++++++
monitor/packet.c | 28 +++++++++++++++++++++++++++-
2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/monitor/bt.h b/monitor/bt.h
index 61308e9..d7cb0e4 100644
--- a/monitor/bt.h
+++ b/monitor/bt.h
@@ -2373,6 +2373,13 @@ struct bt_hci_cmd_le_write_rf_path_comp {
uint16_t rf_rx_path_comp;
} __attribute__ ((packed));

+#define BT_HCI_CMD_LE_SET_PRIV_MODE 0x204e
+struct bt_hci_cmd_le_set_priv_mode {
+ uint8_t peer_id_addr_type;
+ uint8_t peer_id_addr[6];
+ uint8_t priv_mode;
+} __attribute__ ((packed));
+
#define BT_HCI_EVT_INQUIRY_COMPLETE 0x01
struct bt_hci_evt_inquiry_complete {
uint8_t status;
diff --git a/monitor/packet.c b/monitor/packet.c
index 582320b..2ea6d49 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -7653,6 +7653,30 @@ static void le_write_rf_path_comp_cmd(const void *data, uint8_t size)
cmd->rf_rx_path_comp);
}

+static void le_set_priv_mode_cmd(const void *data, uint8_t size)
+{
+ const struct bt_hci_cmd_le_set_priv_mode *cmd = data;
+ const char *str;
+
+ print_addr_type("Peer Identity address type", cmd->peer_id_addr_type);
+ print_addr("Peer Identity address", cmd->peer_id_addr,
+ cmd->peer_id_addr_type);
+
+ switch (cmd->priv_mode) {
+ case 0x00:
+ str = "Use Network Privacy";
+ break;
+ case 0x01:
+ str = "Use Device Privacy";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+
+ print_field("Privacy Mode: %s (0x%2.2x)", str, cmd->priv_mode);
+}
+
struct opcode_data {
uint16_t opcode;
int bit;
@@ -8437,7 +8461,9 @@ static const struct opcode_data opcode_table[] = {
{ 0x204d, 313, "LE Write RF Path Compensation",
le_write_rf_path_comp_cmd, 4, true,
status_rsp, 1, true },
- { 0x204e, 314, "LE Set Privacy Mode" },
+ { 0x204e, 314, "LE Set Privacy Mode",
+ le_set_priv_mode_cmd, 8, true,
+ status_rsp, 1, true },
{ }
};

--
2.9.3


2017-06-13 13:18:15

by Michał Narajowski

[permalink] [raw]
Subject: [PATCH BlueZ v2 5/7] monitor: Add LE Periodic Advertising commands decoding

monitor: Add LE Periodic Advertising Create Sync decoding

< HCI Command: LE Periodic Advertising Create Sync (0x08|0x0044) plen 14
Filter policy: Use Periodic Advertiser List (0x01)
SID: 0x02
Adv address type: Reserved (0xff)
Adv address: 00-00-00-00-00-00
Skip: 0x0201
Sync timeout: 25630 msec (0x0a03)
Unused: 0x0a

monitor: Add LE Periodic Advertising Create Sync Cancel decoding

monitor: Add LE Periodic Advertising Terminate Sync decoding

< HCI Command: LE Periodic Advertising Terminate Sync (0x08|0x0046) plen 2
Sync handle: 0x0201

monitor: Add LE Add Device To Periodic Advertiser List decoding

< HCI Command: LE Add Device To Periodic Advertiser List (0x08|0x0047) plen 8
Adv address type: Random (0x01)
Adv address: 07:06:05:04:03:02 (Non-Resolvable)
SID: 0x08

monitor: Add LE Remove Device From Periodic Advertiser List decoding

< HCI Command: LE Add Device To Periodic Advertiser List (0x08|0x0047) plen 8
Adv address type: Random (0x01)
Adv address: 07:06:05:04:03:02 (Non-Resolvable)
SID: 0x08

monitor: Add LE Clear Periodic Advertiser List decoding

monitor: Add LE Read Periodic Advertiser List Size decoding
---
monitor/bt.h | 40 +++++++++++++++++++++++++
monitor/packet.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 122 insertions(+), 7 deletions(-)

diff --git a/monitor/bt.h b/monitor/bt.h
index 0aaa58b..7fe5673 100644
--- a/monitor/bt.h
+++ b/monitor/bt.h
@@ -2313,6 +2313,46 @@ struct bt_hci_le_ext_create_conn {
uint16_t max_length;
} __attribute__ ((packed));

+#define BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC 0x2044
+struct bt_hci_cmd_le_periodic_adv_create_sync {
+ uint8_t filter_policy;
+ uint8_t sid;
+ uint8_t addr_type;
+ uint8_t addr[6];
+ uint16_t skip;
+ uint16_t sync_timeout;
+ uint8_t unused;
+} __attribute__ ((packed));
+
+#define BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC_CANCEL 0x2045
+
+#define BT_HCI_CMD_LE_PERIODIC_ADV_TERM_SYNC 0x2046
+struct bt_hci_cmd_le_periodic_adv_term_sync {
+ uint16_t sync_handle;
+} __attribute__ ((packed));
+
+#define BT_HCI_CMD_LE_ADD_DEV_PERIODIC_ADV_LIST 0x2047
+struct bt_hci_cmd_le_add_dev_periodic_adv_list {
+ uint8_t addr_type;
+ uint8_t addr[6];
+ uint8_t sid;
+} __attribute__ ((packed));
+
+#define BT_HCI_CMD_LE_REMOVE_DEV_PERIODIC_ADV_LIST 0x2048
+struct bt_hci_cmd_le_remove_dev_periodic_adv_list {
+ uint8_t addr_type;
+ uint8_t addr[6];
+ uint8_t sid;
+} __attribute__ ((packed));
+
+#define BT_HCI_CMD_LE_CLEAR_PERIODIC_ADV_LIST 0x2049
+
+#define BT_HCI_CMD_LE_READ_PERIODIC_ADV_LIST_SIZE 0x204a
+struct bt_hci_rsp_le_read_dev_periodic_adv_list_size {
+ uint8_t status;
+ uint8_t list_size;
+} __attribute__ ((packed));
+
#define BT_HCI_EVT_INQUIRY_COMPLETE 0x01
struct bt_hci_evt_inquiry_complete {
uint8_t status;
diff --git a/monitor/packet.c b/monitor/packet.c
index 2a970e6..9a75e43 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -7562,6 +7562,67 @@ static void le_ext_create_conn_cmd(const void *data, uint8_t size)
}
}

+static void le_periodic_adv_create_sync_cmd(const void *data, uint8_t size)
+{
+ const struct bt_hci_cmd_le_periodic_adv_create_sync *cmd = data;
+ const char *str;
+
+ switch (cmd->filter_policy) {
+ case 0x00:
+ str = "Use specified advertising parameters";
+ break;
+ case 0x01:
+ str = "Use Periodic Advertiser List";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+
+ print_field("Filter policy: %s (0x%2.2x)", str, cmd->filter_policy);
+ print_field("SID: 0x%2.2x", cmd->sid);
+ print_addr_type("Adv address type", cmd->addr_type);
+ print_addr("Adv address", cmd->addr, cmd->addr_type);
+ print_field("Skip: 0x%4.4x", cmd->skip);
+ print_field("Sync timeout: %d msec (0x%4.4x)",
+ le16_to_cpu(cmd->sync_timeout) * 10,
+ le16_to_cpu(cmd->sync_timeout));
+ print_field("Unused: 0x%2.2x", cmd->unused);
+}
+
+static void le_periodic_adv_term_sync_cmd(const void *data, uint8_t size)
+{
+ const struct bt_hci_cmd_le_periodic_adv_term_sync *cmd = data;
+
+ print_field("Sync handle: 0x%4.4x", cmd->sync_handle);
+}
+
+static void le_add_dev_periodic_adv_list_cmd(const void *data, uint8_t size)
+{
+ const struct bt_hci_cmd_le_add_dev_periodic_adv_list *cmd = data;
+
+ print_addr_type("Adv address type", cmd->addr_type);
+ print_addr("Adv address", cmd->addr, cmd->addr_type);
+ print_field("SID: 0x%2.2x", cmd->sid);
+}
+
+static void le_remove_dev_periodic_adv_list_cmd(const void *data, uint8_t size)
+{
+ const struct bt_hci_cmd_le_remove_dev_periodic_adv_list *cmd = data;
+
+ print_addr_type("Adv address type", cmd->addr_type);
+ print_addr("Adv address", cmd->addr, cmd->addr_type);
+ print_field("SID: 0x%2.2x", cmd->sid);
+}
+
+static void le_read_periodic_adv_list_size_rsp(const void *data, uint8_t size)
+{
+ const struct bt_hci_rsp_le_read_dev_periodic_adv_list_size *rsp = data;
+
+ print_status(rsp->status);
+ print_field("List size: 0x%2.2x", rsp->list_size);
+}
+
struct opcode_data {
uint16_t opcode;
int bit;
@@ -8316,13 +8377,27 @@ static const struct opcode_data opcode_table[] = {
{ 0x2043, 303, "LE Extended Create Connection",
le_ext_create_conn_cmd, 10, false,
status_rsp, 1, true },
- { 0x2044, 304, "LE Periodic Advertising Create Sync" },
- { 0x2045, 305, "LE Periodic Advertising Create Sync Cancel" },
- { 0x2046, 306, "LE Periodic Advertising Terminate Sync" },
- { 0x2047, 307, "LE Add Device To Periodic Advertiser List" },
- { 0x2048, 308, "LE Remove Device From Periodic Advertiser List" },
- { 0x2049, 309, "LE Clear Periodic Advertiser List" },
- { 0x204a, 310, "LE Read Periodic Advertiser List Size" },
+ { 0x2044, 304, "LE Periodic Advertising Create Sync",
+ le_periodic_adv_create_sync_cmd, 14, true,
+ status_rsp, 1, true },
+ { 0x2045, 305, "LE Periodic Advertising Create Sync Cancel",
+ null_cmd, 0, true,
+ status_rsp, 1, true },
+ { 0x2046, 306, "LE Periodic Advertising Terminate Sync",
+ le_periodic_adv_term_sync_cmd, 2, true,
+ status_rsp, 1, true },
+ { 0x2047, 307, "LE Add Device To Periodic Advertiser List",
+ le_add_dev_periodic_adv_list_cmd, 8, true,
+ status_rsp, 1, true },
+ { 0x2048, 308, "LE Remove Device From Periodic Advertiser List",
+ le_remove_dev_periodic_adv_list_cmd, 8, true,
+ status_rsp, 1, true },
+ { 0x2049, 309, "LE Clear Periodic Advertiser List",
+ null_cmd, 0, true,
+ status_rsp, 1, true },
+ { 0x204a, 310, "LE Read Periodic Advertiser List Size",
+ null_cmd, 0, true,
+ le_read_periodic_adv_list_size_rsp, 2, true },
{ 0x204b, 311, "LE Read Transmit Power" },
{ 0x204c, 312, "LE Read RF Path Compensation" },
{ 0x204d, 313, "LE Write RF Path Compensation" },
--
2.9.3


2017-06-13 13:18:12

by Michał Narajowski

[permalink] [raw]
Subject: [PATCH BlueZ v2 2/7] monitor: Add LE Extended Advertising commands decoding

monitor: Add LE Set Advertising Set Random Address decoding

< HCI Command: LE Set Advertising Set Random Address (0x08|0x0035) plen 7
Advertising handle: 0x01
Advertising random address: FF:EE:DD:CC:BB:AA (OUI FF-EE-DD)

monitor: Add LE Set Extended Advertising Parameters decoding

< HCI Command: LE Set Extended Advertising Parameters (0x08|0x0036) plen 25
Handle: 0x01
Properties: 0x001d
Connectable
Directed
High Duty Cycle Directed Connectable
Use legacy advertising PDUs: ADV_DIRECT_IND (high duty cycle)
Min advertising interval: 0.000 msec (0x0000)
Max advertising interval: 40960.000 msec (0x10000)
Channel map: 38 (0x02)
Own address type: Random (0x03)
Peer address type: Reserved (0x0a)
Peer address: 01-0A-0A-0A-0A-0A
Filter policy: Allow Scan Request from Any, Allow Connect Request from White List Only (0x02)
Tx power: 0x03
Primary PHY: Reserved (0x04)
Secondary max skip: 0x05
Secondary PHY: Reserved (0x06)
SID: 0x00
Scan request notifications: Disabled

monitor: Add LE Set Extended Advertising Data decoding

< HCI Command: LE Set Extended Advertising Data (0x08|0x0037) plen 9
Handle: 0x01
Operation: Complete extended advertising data
Fragment preference: Fragment all
Data length: 0x05
a0 a1 a2 a3 a4 .....

monitor: Add LE Set Extended Scan Response Data decoding

< HCI Command: LE Set Extended Scan Response Data (0x08|0x0038) plen 9
Handle: 0x01
Operation: Complete scan response data
Fragment preference: Fragment all
Data length: 0x05
b0 b1 b2 b3 b4 .....

monitor: Add LE Set Extended Advertising Enable decoding

< HCI Command: LE Set Extended Advertising Enable (0x08|0x0039) plen 24
Ext adv: Enabled
Number of sets: 2
Entry 0
Handle: 0xff
Duration: 0 ms (0x00)
Max ext adv events: 0
Entry 1
Handle: 0x00
Duration: 0 ms (0x00)
Max ext adv events: 1

monitor: Add LE Read Maximum Advertising Data Length decoding

monitor: Add LE Read Number of Supported Advertising Sets decoding

monitor: Add LE Remove Advertising Set decoding

< HCI Command: LE Remove Advertising Set (0x08|0x003c) plen 1
Handle: 1

monitor: Add LE Clear Advertising Sets decoding

monitor: Add LE Advertising Set Terminated Event decoding

monitor: Add LE Scan Request Received Event decoding
---
monitor/bt.h | 92 +++++++++++++
monitor/packet.c | 411 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 492 insertions(+), 11 deletions(-)

diff --git a/monitor/bt.h b/monitor/bt.h
index a877b2c..aa55579 100644
--- a/monitor/bt.h
+++ b/monitor/bt.h
@@ -2176,6 +2176,83 @@ struct bt_hci_cmd_le_enhanced_transmitter_test {
uint8_t phy;
} __attribute__((packed));

+#define BT_HCI_CMD_LE_SET_ADV_SET_RAND_ADDR 0x2035
+struct bt_hci_cmd_le_set_adv_set_rand_addr {
+ uint8_t handle;
+ uint8_t bdaddr[6];
+} __attribute__ ((packed));
+
+#define BT_HCI_CMD_LE_SET_EXT_ADV_PARAMS 0x2036
+struct bt_hci_cmd_le_set_ext_adv_params {
+ uint8_t handle;
+ uint16_t evt_properties;
+ uint8_t min_interval[3];
+ uint8_t max_interval[3];
+ uint8_t channel_map;
+ uint8_t own_addr_type;
+ uint8_t peer_addr_type;
+ uint8_t peer_addr[6];
+ uint8_t filter_policy;
+ uint8_t tx_power;
+ uint8_t primary_phy;
+ uint8_t secondary_max_skip;
+ uint8_t secondary_phy;
+ uint8_t sid;
+ uint8_t notif_enable;
+} __attribute__ ((packed));
+struct bt_hci_rsp_le_set_ext_adv_params {
+ uint8_t status;
+ uint8_t tx_power;
+} __attribute__ ((packed));
+
+#define BT_HCI_CMD_LE_SET_EXT_ADV_DATA 0x2037
+struct bt_hci_cmd_le_set_ext_adv_data {
+ uint8_t handle;
+ uint8_t operation;
+ uint8_t fragment_preference;
+ uint8_t data_len;
+ uint8_t data[0];
+} __attribute__ ((packed));
+
+#define BT_HCI_CMD_LE_SET_EXT_SCAN_RSP_DATA 0x2038
+struct bt_hci_cmd_le_set_ext_scan_rsp_data {
+ uint8_t handle;
+ uint8_t operation;
+ uint8_t fragment_preference;
+ uint8_t data_len;
+ uint8_t data[0];
+} __attribute__ ((packed));
+
+#define BT_HCI_CMD_LE_SET_EXT_ADV_ENABLE 0x2039
+struct bt_hci_cmd_le_set_ext_adv_enable {
+ uint8_t enable;
+ uint8_t num_of_sets;
+} __attribute__ ((packed));
+struct bt_hci_cmd_ext_adv_set {
+ uint8_t handle;
+ uint16_t duration;
+ uint8_t max_events;
+} __attribute__ ((packed));
+
+#define BT_HCI_CMD_LE_READ_MAX_ADV_DATA_LEN 0x203a
+struct bt_hci_rsp_le_read_max_adv_data_len {
+ uint8_t status;
+ uint16_t max_len;
+} __attribute__ ((packed));
+
+#define BT_HCI_CMD_LE_READ_NUM_SUPPORTED_ADV_SETS 0x203b
+struct bt_hci_rsp_le_read_num_supported_adv_sets {
+ uint8_t status;
+ uint8_t num_of_sets;
+} __attribute__ ((packed));
+
+#define BT_HCI_CMD_LE_REMOVE_ADV_SET 0x203c
+struct bt_hci_cmd_le_remove_adv_set {
+ uint8_t handle;
+} __attribute__ ((packed));
+
+#define BT_HCI_CMD_LE_CLEAR_ADV_SETS 0x203d
+
#define BT_HCI_EVT_INQUIRY_COMPLETE 0x01
struct bt_hci_evt_inquiry_complete {
uint8_t status;
@@ -2786,6 +2863,21 @@ struct bt_hci_evt_le_phy_update_complete {
uint8_t rx_phy;
} __attribute__ ((packed));

+#define BT_HCI_EVT_LE_ADV_SET_TERM 0x12
+struct bt_hci_evt_le_adv_set_term {
+ uint8_t status;
+ uint8_t handle;
+ uint16_t conn_handle;
+ uint8_t num_evts;
+} __attribute__ ((packed));
+
+#define BT_HCI_EVT_LE_SCAN_REQ_RECEIVED 0x13
+struct bt_hci_evt_le_scan_req_received {
+ uint8_t handle;
+ uint8_t scanner_addr_type;
+ uint8_t scanner_addr[6];
+} __attribute__ ((packed));
+
#define BT_HCI_EVT_LE_CHAN_SELECT_ALG 0x14
struct bt_hci_evt_le_chan_select_alg {
uint16_t handle;
diff --git a/monitor/packet.c b/monitor/packet.c
index f2ea610..8827f5e 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -6932,6 +6932,354 @@ static void le_enhanced_transmitter_test_cmd(const void *data, uint8_t size)
print_field("PHY: %s (0x%2.2x)", str, cmd->phy);
}

+static void le_set_adv_set_rand_addr(const void *data, uint8_t size)
+{
+ const struct bt_hci_cmd_le_set_adv_set_rand_addr *cmd = data;
+
+ print_field("Advertising handle: 0x%2.2x", cmd->handle);
+ print_addr("Advertising random address", cmd->bdaddr, 0x00);
+}
+
+static const struct {
+ uint8_t bit;
+ const char *str;
+} ext_adv_properties_table[] = {
+ { 0, "Connectable" },
+ { 1, "Scannable" },
+ { 2, "Directed" },
+ { 3, "High Duty Cycle Directed Connectable" },
+ { 4, "Use legacy advertising PDUs" },
+ { 5, "Anonymous advertising" },
+ { 6, "Include TxPower" },
+ { }
+};
+
+static const char *get_adv_pdu_desc(uint16_t flags)
+{
+ const char *str;
+
+ switch (flags) {
+ case 0x10:
+ str = "ADV_NONCONN_IND";
+ break;
+ case 0x12:
+ str = "ADV_SCAN_IND";
+ break;
+ case 0x13:
+ str = "ADV_IND";
+ break;
+ case 0x15:
+ str = "ADV_DIRECT_IND (low duty cycle)";
+ break;
+ case 0x1d:
+ str = "ADV_DIRECT_IND (high duty cycle)";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+
+ return str;
+}
+
+static void print_ext_adv_properties(uint16_t flags)
+{
+ uint16_t mask = flags;
+ const char *property;
+ int i;
+
+ print_field("Properties: 0x%4.4x", flags);
+
+ for (i = 0; ext_adv_properties_table[i].str; i++) {
+ if (flags & (1 << ext_adv_properties_table[i].bit)) {
+ property = ext_adv_properties_table[i].str;
+
+ if (ext_adv_properties_table[i].bit == 4) {
+ print_field(" %s: %s", property,
+ get_adv_pdu_desc(flags));
+ } else {
+ print_field(" %s", property);
+ }
+ mask &= ~(1 << ext_adv_properties_table[i].bit);
+ }
+ }
+
+ if (mask)
+ print_text(COLOR_UNKNOWN_ADV_FLAG,
+ " Unknown advertising properties (0x%4.4x)",
+ mask);
+}
+
+static void print_ext_slot_625(const char *label, const uint8_t value[3])
+{
+ uint32_t value_cpu = value[0];
+
+ value_cpu |= value[1] << 8;
+ value_cpu |= value[2] << 16;
+
+ print_field("%s: %.3f msec (0x%4.4x)", label,
+ value_cpu * 0.625, value_cpu);
+}
+
+static void le_set_ext_adv_params_cmd(const void *data, uint8_t size)
+{
+ const struct bt_hci_cmd_le_set_ext_adv_params *cmd = data;
+ const char *str;
+
+ print_field("Handle: 0x%2.2x", cmd->handle);
+ print_ext_adv_properties(le16_to_cpu(cmd->evt_properties));
+
+ print_ext_slot_625("Min advertising interval", cmd->min_interval);
+ print_ext_slot_625("Max advertising interval", cmd->max_interval);
+
+ switch (cmd->channel_map) {
+ case 0x01:
+ str = "37";
+ break;
+ case 0x02:
+ str = "38";
+ break;
+ case 0x03:
+ str = "37, 38";
+ break;
+ case 0x04:
+ str = "39";
+ break;
+ case 0x05:
+ str = "37, 39";
+ break;
+ case 0x06:
+ str = "38, 39";
+ break;
+ case 0x07:
+ str = "37, 38, 39";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+
+ print_field("Channel map: %s (0x%2.2x)", str, cmd->channel_map);
+
+ print_own_addr_type(cmd->own_addr_type);
+ print_peer_addr_type("Peer address type", cmd->peer_addr_type);
+ print_addr("Peer address", cmd->peer_addr, cmd->peer_addr_type);
+
+ switch (cmd->filter_policy) {
+ case 0x00:
+ str = "Allow Scan Request from Any, "
+ "Allow Connect Request from Any";
+ break;
+ case 0x01:
+ str = "Allow Scan Request from White List Only, "
+ "Allow Connect Request from Any";
+ break;
+ case 0x02:
+ str = "Allow Scan Request from Any, "
+ "Allow Connect Request from White List Only";
+ break;
+ case 0x03:
+ str = "Allow Scan Request from White List Only, "
+ "Allow Connect Request from White List Only";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+
+ print_field("Filter policy: %s (0x%2.2x)", str, cmd->filter_policy);
+ print_field("Tx power: 0x%2.2x", cmd->tx_power);
+
+ switch (cmd->primary_phy) {
+ case 0x01:
+ str = "LE 1M";
+ break;
+ case 0x03:
+ str = "LE Coded";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+
+ print_field("Primary PHY: %s (0x%2.2x)", str, cmd->primary_phy);
+ print_field("Secondary max skip: 0x%2.2x", cmd->secondary_max_skip);
+ print_le_phy("Secondary PHY", cmd->secondary_phy);
+ print_field("SID: 0x%2.2x", cmd->sid);
+
+ switch (cmd->notif_enable) {
+ case 0x00:
+ str = "Disabled";
+ break;
+ case 0x01:
+ str = "Enabled";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+ print_field("Scan request notifications: %s", str);
+}
+
+static void le_set_ext_adv_params_rsp(const void *data, uint8_t size)
+{
+ const struct bt_hci_rsp_le_set_ext_adv_params *rsp = data;
+
+ print_status(rsp->status);
+ print_field("Selected Tx power: 0x%2.2x", rsp->tx_power);
+}
+
+static void le_set_ext_adv_data_cmd(const void *data, uint8_t size)
+{
+ const struct bt_hci_cmd_le_set_ext_adv_data *cmd = data;
+ const char *str;
+
+ print_field("Handle: 0x%2.2x", cmd->handle);
+
+ switch (cmd->operation) {
+ case 0x00:
+ str = "Immediate fragment";
+ break;
+ case 0x01:
+ str = "First fragment";
+ break;
+ case 0x02:
+ str = "Last fragment";
+ break;
+ case 0x03:
+ str = "Complete extended advertising data";
+ break;
+ case 0x04:
+ str = "Unchanged data";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+ print_field("Operation: %s", str);
+
+ switch (cmd->fragment_preference) {
+ case 0x00:
+ str = "Fragment all";
+ break;
+ case 0x01:
+ str = "Minimize fragmentation";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+ print_field("Fragment preference: %s", str);
+ print_field("Data length: 0x%2.2x", cmd->data_len);
+ packet_print_ad(cmd->data, size - sizeof(*cmd));
+}
+
+static void le_set_ext_scan_rsp_data_cmd(const void *data, uint8_t size)
+{
+ const struct bt_hci_cmd_le_set_ext_scan_rsp_data *cmd = data;
+ const char *str;
+
+ print_field("Handle: 0x%2.2x", cmd->handle);
+
+ switch (cmd->operation) {
+ case 0x00:
+ str = "Immediate fragment";
+ break;
+ case 0x01:
+ str = "First fragment";
+ break;
+ case 0x02:
+ str = "Last fragment";
+ break;
+ case 0x03:
+ str = "Complete scan response data";
+ break;
+ case 0x04:
+ str = "Unchanged data";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+ print_field("Operation: %s", str);
+
+ switch (cmd->fragment_preference) {
+ case 0x00:
+ str = "Fragment all";
+ break;
+ case 0x01:
+ str = "Minimize fragmentation";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+ print_field("Fragment preference: %s", str);
+ print_field("Data length: 0x%2.2x", cmd->data_len);
+ packet_print_ad(cmd->data, size - sizeof(*cmd));
+}
+
+static void le_set_ext_adv_enable_cmd(const void *data, uint8_t size)
+{
+ const struct bt_hci_cmd_le_set_ext_adv_enable *cmd = data;
+ const struct bt_hci_cmd_ext_adv_set *adv_set;
+ const char *str;
+ int i;
+
+ switch (cmd->enable) {
+ case 0x00:
+ str = "Disable";
+ break;
+ case 0x01:
+ str = "Enabled";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+
+ print_field("Ext adv: %s", str);
+
+ if (cmd->num_of_sets == 0)
+ print_field("Number of sets: Disable all advertising sets");
+ else if (cmd->num_of_sets > 0x3f)
+ print_field("Number of sets: Reserved");
+ else
+ print_field("Number of sets: %u", cmd->num_of_sets);
+
+ for (i = 0; i < cmd->num_of_sets; ++i) {
+ adv_set = data + 2 + i * sizeof(struct bt_hci_cmd_ext_adv_set);
+ print_field("Entry %d", i);
+ print_field(" Handle: 0x%2.2x", adv_set->handle);
+ print_field(" Duration: %d ms (0x%2.2x)",
+ adv_set->duration * 10, adv_set->duration);
+ print_field(" Max ext adv events: %d", adv_set->max_events);
+ }
+}
+
+static void le_read_max_adv_data_len_rsp(const void *data, uint8_t size)
+{
+ const struct bt_hci_rsp_le_read_max_adv_data_len *rsp = data;
+
+ print_status(rsp->status);
+ print_field("Max length: %d", rsp->max_len);
+}
+
+static void le_read_num_supported_adv_sets_rsp(const void *data, uint8_t size)
+{
+ const struct bt_hci_rsp_le_read_num_supported_adv_sets *rsp = data;
+
+ print_status(rsp->status);
+ print_field("Num supported adv sets: %d", rsp->num_of_sets);
+}
+
+static void le_remove_adv_set_cmd(const void *data, uint8_t size)
+{
+ const struct bt_hci_cmd_le_remove_adv_set *cmd = data;
+
+ print_handle(cmd->handle);
+}
+
struct opcode_data {
uint16_t opcode;
int bit;
@@ -7641,15 +7989,33 @@ static const struct opcode_data opcode_table[] = {
{ 0x2034, 288, "LE Enhanced Transmitter Test",
le_enhanced_transmitter_test_cmd, 4, true,
status_rsp, 1, true },
- { 0x2035, 289, "LE Set Advertising Set Random Address" },
- { 0x2036, 290, "LE Set Extended Advertising Parameters" },
- { 0x2037, 291, "LE Set Extended Advertising Data" },
- { 0x2038, 292, "LE Set Extended Scan Response Data" },
- { 0x2039, 293, "LE Set Extended Advertising Enable" },
- { 0x203a, 294, "LE Read Maximum Advertising Data Length" },
- { 0x203b, 295, "LE Read Number of Supported Advertising Sets" },
- { 0x203c, 296, "LE Remove Advertising Set" },
- { 0x203d, 297, "LE Clear Advertising Sets" },
+ { 0x2035, 289, "LE Set Advertising Set Random Address",
+ le_set_adv_set_rand_addr, 7, true,
+ status_rsp, 1, true },
+ { 0x2036, 290, "LE Set Extended Advertising Parameters",
+ le_set_ext_adv_params_cmd, 25, true,
+ le_set_ext_adv_params_rsp, 2, true },
+ { 0x2037, 291, "LE Set Extended Advertising Data",
+ le_set_ext_adv_data_cmd, 4, false,
+ status_rsp, 1, true },
+ { 0x2038, 292, "LE Set Extended Scan Response Data",
+ le_set_ext_scan_rsp_data_cmd, 4, false,
+ status_rsp, 1, true },
+ { 0x2039, 293, "LE Set Extended Advertising Enable",
+ le_set_ext_adv_enable_cmd, 2, false,
+ status_rsp, 1, true },
+ { 0x203a, 294, "LE Read Maximum Advertising Data Length",
+ null_cmd, 0, true,
+ le_read_max_adv_data_len_rsp, 3, true },
+ { 0x203b, 295, "LE Read Number of Supported Advertising Sets",
+ null_cmd, 0, true,
+ le_read_num_supported_adv_sets_rsp, 2, true },
+ { 0x203c, 296, "LE Remove Advertising Set",
+ le_remove_adv_set_cmd, 1, true,
+ status_rsp, 1, true },
+ { 0x203d, 297, "LE Clear Advertising Sets",
+ null_cmd, 0, true,
+ status_rsp, 1, true },
{ 0x203e, 298, "LE Set Periodic Advertising Parameters" },
{ 0x203f, 299, "LE Set Periodic Advertising Data" },
{ 0x2040, 300, "LE Set Periodic Advertising Enable" },
@@ -8770,6 +9136,27 @@ static void le_phy_update_complete_evt(const void *data, uint8_t size)
print_le_phy("RX PHY", evt->rx_phy);
}

+static void le_adv_set_term_evt(const void *data, uint8_t size)
+{
+ const struct bt_hci_evt_le_adv_set_term *evt = data;
+
+ print_status(evt->status);
+ print_field("Handle: %d", evt->handle);
+ print_field("Connection handle: %d", evt->conn_handle);
+ print_field("Number of completed extended advertising events: %d",
+ evt->num_evts);
+}
+
+static void le_scan_req_received_evt(const void *data, uint8_t size)
+{
+ const struct bt_hci_evt_le_scan_req_received *evt = data;
+
+ print_field("Handle: %d", evt->handle);
+ print_peer_addr_type("Scanner ddress type", evt->scanner_addr_type);
+ print_addr("Scanner address", evt->scanner_addr,
+ evt->scanner_addr_type);
+}
+
static void le_chan_select_alg_evt(const void *data, uint8_t size)
{
const struct bt_hci_evt_le_chan_select_alg *evt = data;
@@ -8865,8 +9252,10 @@ static const struct subevent_data le_meta_event_table[] = {
{ 0x0f, "LE Periodic Advertising Report" },
{ 0x10, "LE Periodic Advertising Sync Lost" },
{ 0x11, "LE Scan Timeout" },
- { 0x12, "LE Advertising Set Terminated" },
- { 0x13, "LE Scan Request Received" },
+ { 0x12, "LE Advertising Set Terminated",
+ le_adv_set_term_evt, 5, true},
+ { 0x13, "LE Scan Request Received",
+ le_scan_req_received_evt, 8, true},
{ 0x14, "LE Channel Selection Algorithm",
le_chan_select_alg_evt, 3, true},
{ }
--
2.9.3


2017-06-13 13:18:11

by Michał Narajowski

[permalink] [raw]
Subject: [PATCH BlueZ v2 1/7] monitor: Add LE Enhanced Test commands decoding

monitor: Add LE Enhanced Receiver Test decoding

< HCI Command: LE Enhanced Receiver Test (0x08|0x0033) plen 3
RX channel: 0x01
PHY: LE 1M (0x01)
Modulation index: Stable (0x01)

monitor: Add LE Enhanced Transmitter Test decoding

< HCI Command: LE Enhanced Transmitter Test (0x08|0x0034) plen 4
TX channel frequency: 2402 MHz (0x00)
Test data length: 255 bytes
Packet payload: 0x01
PHY: LE Coded with S=8 (0x03)
---
monitor/bt.h | 15 +++++++++++++
monitor/packet.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 77 insertions(+), 2 deletions(-)

diff --git a/monitor/bt.h b/monitor/bt.h
index c2045bb..a877b2c 100644
--- a/monitor/bt.h
+++ b/monitor/bt.h
@@ -2161,6 +2161,21 @@ struct bt_hci_cmd_le_set_phy {
uint16_t phy_opts;
} __attribute__((packed));

+#define BT_HCI_CMD_LE_ENHANCED_RECEIVER_TEST 0x2033
+struct bt_hci_cmd_le_enhanced_receiver_test {
+ uint8_t rx_channel;
+ uint8_t phy;
+ uint8_t modulation_index;
+} __attribute__((packed));
+
+#define BT_HCI_CMD_LE_ENHANCED_TRANSMITTER_TEST 0x2034
+struct bt_hci_cmd_le_enhanced_transmitter_test {
+ uint8_t tx_channel;
+ uint8_t data_len;
+ uint8_t payload;
+ uint8_t phy;
+} __attribute__((packed));
+
#define BT_HCI_EVT_INQUIRY_COMPLETE 0x01
struct bt_hci_evt_inquiry_complete {
uint8_t status;
diff --git a/monitor/packet.c b/monitor/packet.c
index 7d1c5e8..f2ea610 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -6876,6 +6876,62 @@ static void le_set_phy_cmd(const void *data, uint8_t size)
print_field("PHY options preference: %s (0x%4.4x)", str, cmd->phy_opts);
}

+static void le_enhanced_receiver_test_cmd(const void *data, uint8_t size)
+{
+ const struct bt_hci_cmd_le_enhanced_receiver_test *cmd = data;
+ const char *str;
+
+ print_field("RX channel frequency: %d MHz (0x%2.2x)",
+ (cmd->rx_channel * 2) + 2402, cmd->rx_channel);
+ print_le_phy("PHY", cmd->phy);
+
+ switch (cmd->modulation_index) {
+ case 0x00:
+ str = "Standard";
+ break;
+ case 0x01:
+ str = "Stable";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+
+ print_field("Modulation index: %s (0x%2.2x)", str,
+ cmd->modulation_index);
+}
+
+static void le_enhanced_transmitter_test_cmd(const void *data, uint8_t size)
+{
+ const struct bt_hci_cmd_le_enhanced_transmitter_test *cmd = data;
+ const char *str;
+
+ print_field("TX channel frequency: %d MHz (0x%2.2x)",
+ (cmd->tx_channel * 2) + 2402, cmd->tx_channel);
+ print_field("Test data length: %d bytes", cmd->data_len);
+ print_field("Packet payload: 0x%2.2x", cmd->payload);
+
+ switch (cmd->phy) {
+ case 0x01:
+ str = "LE 1M";
+ break;
+ case 0x02:
+ str = "LE 2M";
+ break;
+ case 0x03:
+ str = "LE Coded with S=8";
+ break;
+ case 0x04:
+ str = "LE Coded with S=2";
+ break;
+ default:
+ str = "Reserved";
+ break;
+ }
+
+ print_field("PHY: %s (0x%2.2x)", str, cmd->phy);
+}
+
struct opcode_data {
uint16_t opcode;
int bit;
@@ -7579,8 +7635,12 @@ static const struct opcode_data opcode_table[] = {
status_rsp, 1, true },
{ 0x2032, 286, "LE Set PHY",
le_set_phy_cmd, 7, true},
- { 0x2033, 287, "LE Enhanced Receiver Test" },
- { 0x2034, 288, "LE Enhanced Transmitter Test" },
+ { 0x2033, 287, "LE Enhanced Receiver Test",
+ le_enhanced_receiver_test_cmd, 3, true,
+ status_rsp, 1, true },
+ { 0x2034, 288, "LE Enhanced Transmitter Test",
+ le_enhanced_transmitter_test_cmd, 4, true,
+ status_rsp, 1, true },
{ 0x2035, 289, "LE Set Advertising Set Random Address" },
{ 0x2036, 290, "LE Set Extended Advertising Parameters" },
{ 0x2037, 291, "LE Set Extended Advertising Data" },
--
2.9.3