monitor: Decode Periodic Advertising with Responses
v2 cover monitor: Decode Periodic Advertising with Responses
This series teaches btmon the HCI commands and events of Periodic Advertising with Responses (PAwR, Bluetooth 5.4). Until now they were only listed by name in the opcode table and the events were printed as unknown.
It is meant as the first step towards supporting the PAwR advertiser role in the kernel and in BlueZ, which is what an access point of the Electronic Shelf Label profile needs: being able to read the traces comes before changing anything else.
Patches 1 to 3 fix existing decoders found on the way:
- the Connection_Handle returned by the Periodic Advertising Sync Transfer commands and by LE Remove ISO Data Path was read as one octet,
- LE Periodic Advertising Report trusted Data_Length and LE Extended Create Connection trusted the number of PHY parameter blocks, so truncated packets made them decode octets outside the packet.
Patch 4 splits the LE Periodic Advertising Report decoding into helpers without changing its output, so that patch 6 can share it.
Patch 5 decodes the five commands and patch 6 the six events, including the [v2] variants of existing events.
Testing: I have no controller with PAwR support at hand yet. The commands were sent with hcitool to a controller which rejects them, so that btmon decodes what the host sent, and the events and the successful command responses were decoded from hand-made btsnoop traces, well formed and truncated ones. The output for well formed packets of the existing decoders was compared with the current tree.
v2:
- Add patches 2 and 3. The two problems Copilot found in v1 were in the [v2] decoders, but they came from the [v1] decoders they reuse, so they are fixed there.
- Patch 4 keeps the new Data_Length check in the shared helper.
Roland Schober (6):
monitor: Fix handle decoding of status_handle_rsp
monitor: Fix data length of LE PA Report decoding
monitor: Fix PHY decoding of LE Ext Create Connection
monitor: Split LE PA Report decoding into helpers
monitor: Add PAwR HCI commands decoding
monitor: Add PAwR HCI events decoding
monitor/analyze.c | 1 + monitor/bt.h | 174 ++++++++++++++++ monitor/packet.c | 510 ++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 646 insertions(+), 39 deletions(-)
Signature · 1 line
2.47.3
PATCH v2 1/6 monitor: Fix handle decoding of status_handle_rsp
status_handle_rsp() decodes the return parameters of commands which return a Status followed by a Connection_Handle, but it only reads the first octet of the two octets of the handle, so any handle above 255 is printed wrong.
With LE Periodic Advertising Set Info Transfer returning handle 3585:
Quoted 1 line
HCI Event: Command Complete (
0x0e) plen 6
LE Periodic Advertising Set Info Transfer (0x08|0x005b) ncmd 1
Status: Unknown Connection Identifier (0x02)
Connection handle: 1Read the handle as a 16-bit value:
Connection handle: 3585
--- monitor/packet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
monitor/packet.c +1 -1
@@ -4976,7 +4976,7 @@ static void status_handle_rsp(uint16_t index, const void *data, uint8_t size)uint8_t status = *((const uint8_t *) data);print_status (status); -print_field ("Connection handle: %d" ,get_u8 (data +1 )); +print_field ("Connection handle: %d" ,get_le16 (data +1 )); }static void status_bdaddr_rsp (uint16_t index,const void *data,uint8_t size)
Signature · 1 line
2.47.3
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1215777/
---Test result---
Test Summary:
CheckPatch PASS 2.03 seconds GitLint PASS 1.21 seconds BuildEll PASS 16.65 seconds BluezMake PASS 243.12 seconds MakeCheck PASS 0.81 seconds MakeDistcheck PASS 123.15 seconds CheckValgrind PASS 122.29 seconds CheckSmatch WARNING 238.85 seconds bluezmakeextell PASS 77.90 seconds TestFunctional PASS 1028.42 seconds IncrementalBuild PASS 347.80 seconds ScanBuild PASS 868.30 seconds
Details
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:monitor/packet.c: note: in included file:monitor/bt.h:4530:47: warning: array of flexible structuresmonitor/packet.c:2292:26: warning: Variable length array is used.monitor/packet.c: note: in included file:monitor/bt.h:4530:47: warning: array of flexible structuresmonitor/packet.c:2292:26: warning: Variable length array is used.monitor/packet.c: note: in included file:monitor/bt.h:4530:47: warning: array of flexible structuresmonitor/packet.c:2292:26: warning: Variable length array is used.monitor/packet.c: note: in included file:monitor/bt.h:4530:47: warning: array of flexible structuresmonitor/packet.c:2292:26: warning: Variable length array is used.monitor/bt.h:4304:52: warning: array of flexible structuresmonitor/bt.h:4292:40: warning: array of flexible structuresmonitor/bt.h:3048:52: warning: array of flexible structuresmonitor/packet.c: note: in included file:monitor/bt.h:4530:47: warning: array of flexible structuresmonitor/packet.c:2292:26: warning: Variable length array is used.monitor/bt.h:4304:52: warning: array of flexible structuresmonitor/bt.h:4292:40: warning: array of flexible structuresmonitor/bt.h:3048:52: warning: array of flexible structuresmonitor/packet.c: note: in included file:monitor/bt.h:4530:47: warning: array of flexible structuresmonitor/packet.c:2292:26: warning: Variable length array is used.
https://github.com/bluez/bluez/pull/2848
---
Regards,
Linux Bluetooth
PATCH v2 2/6 monitor: Fix data length of LE PA Report decoding
In reply to Roland SchoberThe LE Periodic Advertising Report decoder passes Data_Length from the event to the advertising data decoder without checking it against the size of the event, so a truncated event makes it decode octets which are not part of it:
Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 8
LE Periodic Advertising Report (0x0f)
...
Data length: 1
Data[1]:
00 .Report the length as invalid and dump the remaining octets instead:
Data length: 1
invalid data length
--- monitor/packet.c | 7 +++++++ 1 file changed, 7 insertions(+)
monitor/packet.c +7 -0
@@ -13957,6 +13957,13 @@ static void le_pa_report_evt(struct timeval *tv, uint16_t index,print_field ("Data status: %s%s%s" , color_on, str,COLOR_OFF );print_field ("Data length: %u" , evt->data_len); + +if (evt->data_len > size -sizeof (*evt)) { +print_text (COLOR_ERROR ,"invalid data length" ); +packet_hexdump (evt->data, size -sizeof (*evt)); +return ; + } +print_eir ("Data" , evt->data, evt->data_len, true); }
Signature · 1 line
2.47.3
PATCH v2 3/6 monitor: Fix PHY decoding of LE Ext Create Connection
In reply to Roland SchoberThe LE Extended Create Connection decoder reads one block of connection parameters for each bit set in Initiating_PHYs without checking that the command carries that many blocks, so a truncated command makes it decode octets which are not part of it:
< HCI Command: LE Extended Create Connection (0x08|0x0043) plen 10
...
Initiating PHYs: 0x01
Entry 0: LE 1M
Scan interval: 0.000 msec (0x0000)
Scan window: 0.000 msec (0x0000)
...Check the size of the command before decoding each block:
Initiating PHYs: 0x01
invalid packet size
--- monitor/packet.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
monitor/packet.c +11 -3
@@ -8816,7 +8816,8 @@ static const struct bitfield_data ext_conn_phys_table[] = { { } }; -static void print_ext_conn_phys (const void *data,uint8_t flags) +static void print_ext_conn_phys (const void *data,uint8_t size, +uint8_t flags) {const struct bt_hci_le_ext_create_conn *entry;uint8_t mask = flags;
@@ -8827,9 +8828,16 @@ static void print_ext_conn_phys(const void *data, uint8_t flags)for (i =0 ; ext_conn_phys_table[i].str; i++) {if (flags & (1 << ext_conn_phys_table[i].bit)) { - entry = data + bits_set *sizeof (*entry); mask &= ~(1 << ext_conn_phys_table[i].bit); +if ((bits_set +1 ) *sizeof (*entry) > size) { +print_text (COLOR_ERROR , +" invalid packet size" ); +break ; + } + + entry = data + bits_set *sizeof (*entry); +print_field ("Entry %d: %s" , bits_set, ext_conn_phys_table[i].str);print_slot_625 (" Scan interval" , entry->scan_interval);
@@ -8880,7 +8888,7 @@ static void le_ext_create_conn_cmd(uint16_t index, const void *data,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); -print_ext_conn_phys (cmd->data, cmd->phys); +print_ext_conn_phys (cmd->data, size -sizeof (*cmd), cmd->phys); }static const struct bitfield_data create_sync_cte_type[] = {
Signature · 1 line
2.47.3
PATCH v2 4/6 monitor: Split LE PA Report decoding into helpers
In reply to Roland SchoberMove the decoding of the reception information (handle, TX power, RSSI and CTE type) and of the data (status, length and AD structures) of the LE Periodic Advertising Report event into helpers, and the CTE type names into a function of their own.
This is a preparation for decoding the events added by Periodic Advertising with Responses, which carry the same information, and does not change the output.
--- monitor/packet.c | 80 +++++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 35 deletions(-)
monitor/packet.c +45 -35
@@ -13905,46 +13905,45 @@ static void le_pa_sync_evt(struct timeval *tv, uint16_t index,print_field ("Advertiser clock accuracy: 0x%2.2x" , evt->clock_accuracy); } -static void le_pa_report_evt (struct timeval *tv,uint16_t index, -const void *data,uint8_t size) +static const char *pa_cte_type_str (uint8_t cte_type) { -const struct bt_hci_le_pa_report *evt = data; -const char *color_on; -const char *str; - -print_field ("Sync handle: %d" , evt->handle); -print_power_level (evt->tx_power,NULL ); -if (evt->rssi ==127 ) -print_field ("RSSI: not available (0x%2.2x)" , - (uint8_t ) evt->rssi); -else if (evt->rssi >=-127 && evt->rssi <=20 ) -print_field ("RSSI: %d dBm (0x%2.2x)" , - evt->rssi, (uint8_t ) evt->rssi); -else -print_field ("RSSI: reserved (0x%2.2x)" , - (uint8_t ) evt->rssi); - -switch (evt->cte_type) { +switch (cte_type) {case 0x00 : - str ="AoA Constant Tone Extension" ; -break ; +return "AoA Constant Tone Extension" ;case 0x01 : - str ="AoA Constant Tone Extension with 1us slots" ; -break ; +return "AoA Constant Tone Extension with 1us slots" ;case 0x02 : - str ="AoD Constant Tone Extension with 2us slots" ; -break ; +return "AoD Constant Tone Extension with 2us slots" ;case 0xff : - str ="No Constant Tone Extension" ; -break ; +return "No Constant Tone Extension" ;default : - str ="Reserved" ; -break ; +return "Reserved" ; } +} -print_field ("CTE Type: %s (0x%2x)" , str, evt->cte_type); +static void print_pa_report_info (uint16_t handle,uint8_t tx_power, +int8_t rssi,uint8_t cte_type) +{ +print_field ("Sync handle: %d" , handle); +print_power_level (tx_power,NULL ); +if (rssi ==127 ) +print_field ("RSSI: not available (0x%2.2x)" , (uint8_t ) rssi); +else if (rssi >=-127 && rssi <=20 ) +print_field ("RSSI: %d dBm (0x%2.2x)" , rssi, (uint8_t ) rssi); +else +print_field ("RSSI: reserved (0x%2.2x)" , (uint8_t ) rssi); + +print_field ("CTE Type: %s (0x%2x)" ,pa_cte_type_str (cte_type), + cte_type); +} -switch (evt->data_status) { +static void print_pa_report_data (uint8_t data_status,uint8_t data_len, +const uint8_t *data,uint8_t size) +{ +const char *color_on; +const char *str; + +switch (data_status) {case 0x00 : str ="Complete" ; color_on =COLOR_GREEN ;
@@ -13964,15 +13963,26 @@ static void le_pa_report_evt(struct timeval *tv, uint16_t index, }print_field ("Data status: %s%s%s" , color_on, str,COLOR_OFF ); -print_field ("Data length: %u" , evt->data_len); +print_field ("Data length: %u" , data_len); -if (evt->data_len > size -sizeof (*evt)) { +if (data_len > size) {print_text (COLOR_ERROR ,"invalid data length" ); -packet_hexdump (evt->data, size -sizeof (*evt)); +packet_hexdump (data, size);return ; } -print_eir ("Data" , evt->data, evt->data_len, true); +print_eir ("Data" , data, data_len, true); +} + +static void le_pa_report_evt (struct timeval *tv,uint16_t index, +const void *data,uint8_t size) +{ +const struct bt_hci_le_pa_report *evt = data; + +print_pa_report_info (evt->handle, evt->tx_power, evt->rssi, + evt->cte_type); +print_pa_report_data (evt->data_status, evt->data_len, evt->data, + size -sizeof (*evt)); } static void le_pa_sync_lost_evt(struct timeval *tv, uint16_t index,
Signature · 1 line
2.47.3
PATCH v2 5/6 monitor: Add PAwR HCI commands decoding
In reply to Roland SchoberDecode the HCI commands introduced by Periodic Advertising with Responses (PAwR) in Bluetooth 5.4, which so far only had their names in the opcode table:
- LE Set Periodic Advertising Subevent Data
- LE Set Periodic Advertising Response Data
- LE Set Periodic Sync Subevent
- LE Extended Create Connection [v2]
- LE Set Periodic Advertising Parameters [v2]
The subevent data of LE Set Periodic Advertising Subevent Data is a list of elements of variable length, each with its own AD structures:
< HCI Command: LE Set Periodic Advertising Subevent.. (0x08|0x0082) plen 15
Handle: 0
Num subevents: 2
Entry 0
Subevent: 0 (0x00)
Response slot start: 0
Response slot count: 2
Data length: 5
Data[5]:
04 ff 59 00 01 ..Y..
Company: Nordic Semiconductor ASA (89)
Data[1]:
01 .
Entry 1
Subevent: 1 (0x01)
Response slot start: 0
Response slot count: 0
Data length: 0
< HCI Command: LE Set Periodic Advertising Paramet.. (0x08|0x0086) plen 12
Handle: 0
Min interval: 1000.00 msec (0x0320)
Max interval: 1000.00 msec (0x0320)
Properties: 0x0000
Num subevents: 4 (0x04)
Subevent interval: 100.00 msec (0x50)
Response slot delay: 6.25 msec (0x05)
Response slot spacing: 1.000 msec (0x08)
Num response slots: 32 (0x20)--- monitor/bt.h | 84 ++++++++++++++++++ monitor/packet.c | 223 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 302 insertions(+), 5 deletions(-)
monitor/bt.h +84 -0
@@ -3032,6 +3032,90 @@ struct bt_hci_rsp_le_read_iso_link_quality {uint32_t duplicated_packets; } __packed; +#define BT_HCI_CMD_LE_SET_PA_SUBEVENT_DATA 0x2082 +#define BT_HCI_BIT_LE_SET_PA_SUBEVENT_DATA BT_HCI_CMD_BIT(46, 5) +struct bt_hci_le_pa_subevent_data { +uint8_t subevent; +uint8_t response_slot_start; +uint8_t response_slot_count; +uint8_t data_len; +uint8_t data[]; +} __packed; + +struct bt_hci_cmd_le_set_pa_subevent_data { +uint8_t handle; +uint8_t num_subevents; +struct bt_hci_le_pa_subevent_data subevents[]; +} __packed; + +struct bt_hci_rsp_le_set_pa_subevent_data { +uint8_t status; +uint8_t handle; +} __packed; + +#define BT_HCI_CMD_LE_SET_PA_RESPONSE_DATA 0x2083 +#define BT_HCI_BIT_LE_SET_PA_RESPONSE_DATA BT_HCI_CMD_BIT(46, 6) +struct bt_hci_cmd_le_set_pa_response_data { +uint16_t sync_handle; +uint16_t request_event; +uint8_t request_subevent; +uint8_t response_subevent; +uint8_t response_slot; +uint8_t data_len; +uint8_t data[]; +} __packed; + +struct bt_hci_rsp_le_set_pa_response_data { +uint8_t status; +uint16_t sync_handle; +} __packed; + +#define BT_HCI_CMD_LE_SET_PA_SYNC_SUBEVENT 0x2084 +#define BT_HCI_BIT_LE_SET_PA_SYNC_SUBEVENT BT_HCI_CMD_BIT(46, 7) +struct bt_hci_cmd_le_set_pa_sync_subevent { +uint16_t sync_handle; +uint16_t properties; +uint8_t num_subevents; +uint8_t subevents[]; +} __packed; + +struct bt_hci_rsp_le_set_pa_sync_subevent { +uint8_t status; +uint16_t sync_handle; +} __packed; + +#define BT_HCI_CMD_LE_EXT_CREATE_CONN_V2 0x2085 +#define BT_HCI_BIT_LE_EXT_CREATE_CONN_V2 BT_HCI_CMD_BIT(47, 0) +struct bt_hci_cmd_le_ext_create_conn_v2 { +uint8_t adv_handle; +uint8_t subevent; +uint8_t filter_policy; +uint8_t own_addr_type; +uint8_t peer_addr_type; +uint8_t peer_addr[6 ]; +uint8_t phys; +uint8_t data[]; +} __packed; + +#define BT_HCI_CMD_LE_SET_PA_PARAMS_V2 0x2086 +#define BT_HCI_BIT_LE_SET_PA_PARAMS_V2 BT_HCI_CMD_BIT(47, 1) +struct bt_hci_cmd_le_set_pa_params_v2 { +uint8_t handle; +uint16_t min_interval; +uint16_t max_interval; +uint16_t properties; +uint8_t num_subevents; +uint8_t subevent_interval; +uint8_t response_slot_delay; +uint8_t response_slot_spacing; +uint8_t num_response_slots; +} __packed; + +struct bt_hci_rsp_le_set_pa_params_v2 { +uint8_t status; +uint8_t handle; +} __packed; +#define BT_HCI_CMD_LE_READ_ALL_LOCAL_FEATURES 0x2087#define BT_HCI_BIT_LE_READ_ALL_LOCAL_FEATURES BT_HCI_CMD_BIT(47, 2)struct bt_hci_rsp_le_read_all_local_features {
monitor/packet.c +218 -5
241 lines not on this page · raw message
Signature · 1 line
2.47.3
PATCH v2 6/6 monitor: Add PAwR HCI events decoding
In reply to Roland SchoberDecode the LE Meta events introduced by Periodic Advertising with Responses (PAwR) in Bluetooth 5.4:
- LE Periodic Advertising Sync Established [v2]
- LE Periodic Advertising Report [v2]
- LE Periodic Advertising Sync Transfer Received [v2]
- LE Periodic Advertising Subevent Data Request
- LE Periodic Advertising Response Report
- LE Enhanced Connection Complete [v2]
The [v2] events reuse the decoding of the events they extend, and LE Enhanced Connection Complete [v2] is tracked like [v1], both by the decoder and by the analyze mode.
Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 4
LE Periodic Advertising Subevent Data Request (0x27)
Handle: 0
Subevent start: 0 (0x00)
Subevent data count: 4 (0x04)Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 25
LE Periodic Advertising Response Report (0x28)
Handle: 0
Subevent: 2 (0x02)
TX status: AUX_SYNC_SUBEVENT_IND was transmitted (0x00)
Num responses: 2
Entry 0
TX power: 127 dBm (0x7f)
RSSI: -55 dBm (0xc9)
CTE Type: No Constant Tone Extension (0xff)
Response slot: 0 (0x00)
Data status: Complete
Data length: 5
Data[5]:
04 ff 59 00 2a ..Y.*
Company: Nordic Semiconductor ASA (89)
Data[1]:
2a *
Entry 1
TX power: 127 dBm (0x7f)
RSSI: not available (0x7f)
CTE Type: No Constant Tone Extension (0xff)
Response slot: 1 (0x01)
Data status: Failed to receive AUX_SYNC_SUBEVENT_RSP
Data length: 0--- monitor/analyze.c | 1 + monitor/bt.h | 90 +++++++++++++++++++++ monitor/packet.c | 194 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 285 insertions(+)
monitor/analyze.c +1 -0
@@ -1171,6 +1171,7 @@ static void evt_le_meta_event(struct hci_dev *dev, struct timeval *tv,evt_le_conn_complete (dev, tv, frame, &iov);break ;case BT_HCI_EVT_LE_ENHANCED_CONN_COMPLETE : +case BT_HCI_EVT_LE_ENHANCED_CONN_COMPLETE_V2 :evt_le_enh_conn_complete (dev, tv, frame, &iov);break ;case BT_HCI_EVT_LE_CIS_ESTABLISHED :
monitor/bt.h +90 -0
96 lines not on this page · raw message
monitor/packet.c +194 -0
230 lines not on this page · raw message
Signature · 1 line
2.47.3