monitor: Decode Periodic Advertising with Responses
v3 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 6 fix existing decoders which the new ones use or which were 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,
- the LE Set Periodic Advertising commands printed the advertising handle as a connection handle,
- LE Periodic Advertising Report printed an unavailable TX power as 127 dBm and named the AoD CTE type with 1 us slots AoA,
- LE PAST Received printed the handle twice and decoded the clock accuracy as a BR/EDR one.
Patch 7 splits the LE Periodic Advertising Report decoding into helpers without changing its output, so that patch 9 can share it.
Patch 8 decodes the five commands and patch 9 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. Every command and event of these traces was also fed to the decoders cut to every length, in a buffer of exactly that size, with AddressSanitizer, which found no read beyond a packet. The output for well formed packets of the existing decoders was compared with the current tree.
v3:
- Add patches 4, 5 and 6, and print the advertising handle, the TX power and the CTE type the same way in the new decoders.
- Patch 2: also report octets beyond Data_Length.
- Patch 3: report extra PHY parameter blocks, and do not report the remaining PHYs as unknown after a truncated block.
- Patch 8: reuse the [v1] decoder for LE Set Periodic Advertising Parameters [v2], print 0x00 subevent timings as none, check Response_Data_Length, and match LE Extended Create Connection [v2] with the events which complete it.
- Patch 9: Data_Status 0xff keeps its reserved meaning in the [v1] LE Periodic Advertising Report, LE Enhanced Connection Complete [v2] is matched with the command which started the connection.
- Patches 8 and 9: report a subevent data command or a response report with fewer entries than announced.
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.
- The patch which splits the LE Periodic Advertising Report decoding keeps the new Data_Length check in the shared helper.
Roland Schober (9):
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: Fix advertising handle of LE PA commands
monitor: Fix TX power and CTE Type of LE PA Report
monitor: Fix LE PAST Received decoding
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 | 585 +++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 708 insertions(+), 52 deletions(-)
Signature · 1 line
2.47.3
PATCH v3 1/9 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/1215867/
---Test result---
Test Summary:
CheckPatch PASS 4.08 seconds GitLint PASS 2.47 seconds BuildEll PASS 20.35 seconds BluezMake PASS 296.33 seconds MakeCheck PASS 0.98 seconds MakeDistcheck PASS 148.62 seconds CheckValgrind PASS 151.59 seconds CheckSmatch WARNING 303.02 seconds bluezmakeextell PASS 96.75 seconds TestFunctional PASS 1185.61 seconds IncrementalBuild PASS 476.21 seconds ScanBuild PASS 1092.29 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:2300: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:2300: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:2300: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:2300: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:2300: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:2300: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:2300: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:2300: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:2300:26: warning: Variable length array is used.
https://github.com/bluez/bluez/pull/2849
---
Regards,
Linux Bluetooth
PATCH v3 2/9 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, and octets beyond Data_Length are dropped silently:
Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 8
LE Periodic Advertising Report (0x0f)
...
Data length: 1
Data[1]:
00 .Report a length which does not match the event 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 v3 3/9 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, and report octets left over after the last block:
Initiating PHYs: 0x01
invalid packet size
--- monitor/packet.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
monitor/packet.c +22 -3
@@ -8816,10 +8816,12 @@ 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; +bool truncated = false;int bits_set =0 ;int i;
@@ -8827,9 +8829,20 @@ 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 (truncated) +continue ; + +if ((bits_set +1 ) *sizeof (*entry) > size) { +print_text (COLOR_ERROR , +" invalid packet size" ); + truncated = true; +continue ; + } + + 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);
@@ -8852,6 +8865,12 @@ static void print_ext_conn_phys(const void *data, uint8_t flags) } } +if (!truncated && bits_set *sizeof (*entry) < size) { +print_text (COLOR_ERROR ," invalid packet size" ); +packet_hexdump (data + bits_set *sizeof (*entry), + size - bits_set *sizeof (*entry)); + } +if (mask)print_text (COLOR_UNKNOWN_ADV_FLAG ," Unknown scanning PHYs" " (0x%2.2x)" , mask);
@@ -8880,7 +8899,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 v3 4/9 monitor: Fix advertising handle of LE PA commands
In reply to Roland SchoberThe decoders of LE Set Periodic Advertising Parameters, Data and Enable print the Advertising_Handle with print_handle(), which looks the value up as a connection handle. With a connection using the same handle, the advertising set is shown with the peer of that connection:
< HCI Command: LE Set Periodic Advertising Parameters (0x08|0x003e) plen 7
Handle: 0 (LE-ACL) Address: C0:11:22:33:44:55 (Static)
Print it the way the extended advertising commands do:
Handle: 0x00
--- monitor/packet.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
monitor/packet.c +3 -3
@@ -8704,7 +8704,7 @@ static void le_set_pa_params_cmd(uint16_t index, const void *data, uint8_t size) {const struct bt_hci_cmd_le_set_pa_params *cmd = data; -print_handle (cmd->handle); +print_field ("Handle: 0x%2.2x" , cmd->handle);print_slot_125 ("Min interval" , cmd->min_interval);print_slot_125 ("Max interval" , cmd->max_interval);print_pa_properties (cmd->properties);
@@ -8715,7 +8715,7 @@ static void le_set_pa_data_cmd(uint16_t index, const void *data, uint8_t size)const struct bt_hci_cmd_le_set_pa_data *cmd = data;const char *str; -print_handle (cmd->handle); +print_field ("Handle: 0x%2.2x" , cmd->handle);switch (cmd->operation) {case 0x00 :
@@ -8745,7 +8745,7 @@ static void le_set_pa_enable_cmd(uint16_t index, const void *data, uint8_t size)const struct bt_hci_cmd_le_set_pa_enable *cmd = data;print_enable ("Periodic advertising" , cmd->enable); -print_handle (cmd->handle); +print_field ("Handle: 0x%2.2x" , cmd->handle); }static const struct bitfield_data ext_scan_phys_table[] = {
Signature · 1 line
2.47.3
PATCH v3 5/9 monitor: Fix TX power and CTE Type of LE PA Report
In reply to Roland SchoberThe LE Periodic Advertising Report decoder prints TX_Power 0x7f, which means that the information is not available, as a power of 127 dBm. It names CTE_Type 0x01 an AoA Constant Tone Extension, but 0x01 is the AoD Constant Tone Extension with 1 us slots, and it pads the value with a space:
TX power: 127 dbm (0x7f)
CTE Type: AoA Constant Tone Extension with 1us slots (0x 1)Decode them as the specification defines them:
TX power: not available (0x7f)
CTE Type: AoD Constant Tone Extension with 1us slots (0x01)--- monitor/packet.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
monitor/packet.c +6 -3
@@ -13924,7 +13924,10 @@ static void le_pa_report_evt(struct timeval *tv, uint16_t index,const char *str;print_field ("Sync handle: %d" , evt->handle); -print_power_level (evt->tx_power,NULL ); +if (evt->tx_power ==127 ) +print_field ("TX power: not available (0x7f)" ); +else +print_power_level (evt->tx_power,NULL );if (evt->rssi ==127 )print_field ("RSSI: not available (0x%2.2x)" , (uint8_t ) evt->rssi);
@@ -13940,7 +13943,7 @@ static void le_pa_report_evt(struct timeval *tv, uint16_t index, str ="AoA Constant Tone Extension" ;break ;case 0x01 : - str ="AoA Constant Tone Extension with 1us slots" ; + str ="AoD Constant Tone Extension with 1us slots" ;break ;case 0x02 : str ="AoD Constant Tone Extension with 2us slots" ;
@@ -13953,7 +13956,7 @@ static void le_pa_report_evt(struct timeval *tv, uint16_t index,break ; } -print_field ("CTE Type: %s (0x%2x)" , str, evt->cte_type); +print_field ("CTE Type: %s (0x%2.2x)" , str, evt->cte_type);switch (evt->data_status) {case 0x00 :
Signature · 1 line
2.47.3
PATCH v3 6/9 monitor: Fix LE PAST Received decoding
In reply to Roland SchoberThe LE Periodic Advertising Sync Transfer Received decoder prints the connection handle twice, doubles the colon of three labels, prints the interval without a unit and decodes the 1 octet Advertiser_Clock_Accuracy as a BR/EDR clock accuracy in units of 0.3125 ms:
Handle: 3585
Connection handle: 3585
...
Address type:: Random (0x01)
Address:: C0:11:22:33:44:55 (Static)
PHY:: LE 2M (0x02)
Periodic advertising Interval: 1000.000
Accuracy: 1.5625 msec (0x0005)Decode it the way LE Periodic Advertising Sync Established is decoded:
Handle: 3585 (LE-ACL) Address: C0:11:22:33:44:55 (Static)
...
Address type: Random (0x01)
Address: C0:11:22:33:44:55 (Static)
PHY: LE 2M (0x02)
Periodic advertising interval: 1000.00 msec (0x0320)
Advertiser clock accuracy: 0x05--- monitor/packet.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
monitor/packet.c +8 -10
@@ -14058,17 +14058,15 @@ static void le_past_received_evt(struct timeval *tv, uint16_t index,const struct bt_hci_evt_le_past_recv *evt = data;print_status (evt->status); -print_field ("Handle: %d" , evt->handle); -print_field ("Connection handle: %d" , evt->handle); -print_field ("Service data: 0x%4.4x" , evt->service_data); -print_field ("Sync handle: %d" , evt->sync_handle); +print_handle (evt->handle); +print_field ("Service data: 0x%4.4x" ,le16_to_cpu (evt->service_data)); +print_field ("Sync handle: %d" ,le16_to_cpu (evt->sync_handle));print_field ("SID: 0x%2.2x" , evt->sid); -print_peer_addr_type ("Address type:" , evt->addr_type); -print_addr ("Address:" , evt->addr, evt->addr_type); -print_le_phy ("PHY:" , evt->phy); -print_field ("Periodic advertising Interval: %.3f" , -1.25 * evt->interval); -print_clock_accuracy (evt->clock_accuracy); +print_peer_addr_type ("Address type" , evt->addr_type); +print_addr ("Address" , evt->addr, evt->addr_type); +print_le_phy ("PHY" , evt->phy); +print_slot_125 ("Periodic advertising interval" , evt->interval); +print_field ("Advertiser clock accuracy: 0x%2.2x" , evt->clock_accuracy); } static void le_cis_established_evt(struct timeval *tv, uint16_t index,
Signature · 1 line
2.47.3
PATCH v3 7/9 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 TX power, the RSSI and the CTE type names into functions 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 | 100 +++++++++++++++++++++++++++++------------------ 1 file changed, 62 insertions(+), 38 deletions(-)
monitor/packet.c +62 -38
@@ -13916,49 +13916,62 @@ 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); -if (evt->tx_power ==127 ) -print_field ("TX power: not available (0x7f)" ); -else -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 ="AoD Constant Tone Extension with 1us slots" ; -break ; +return "AoD 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%2.2x)" , str, evt->cte_type); +static void print_pa_rssi (const char *prefix,int8_t rssi) +{ +if (rssi ==127 ) +print_field ("%sRSSI: not available (0x%2.2x)" , prefix, + (uint8_t ) rssi); +else if (rssi >=-127 && rssi <=20 ) +print_field ("%sRSSI: %d dBm (0x%2.2x)" , prefix, rssi, + (uint8_t ) rssi); +else +print_field ("%sRSSI: reserved (0x%2.2x)" , prefix, + (uint8_t ) rssi); +} -switch (evt->data_status) { +static void print_pa_tx_power (const char *prefix,int8_t tx_power) +{ +if (tx_power ==127 ) +print_field ("%sTX power: not available (0x7f)" , prefix); +else +print_field ("%sTX power: %d dbm (0x%2.2x)" , prefix, tx_power, + (uint8_t ) tx_power); +} + +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_pa_tx_power ("" , tx_power); +print_pa_rssi ("" , rssi); + +print_field ("CTE Type: %s (0x%2.2x)" ,pa_cte_type_str (cte_type), + cte_type); +} + +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 ;
@@ -13978,15 +13991,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 v3 8/9 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]
LE Extended Create Connection [v2] is matched with the events which complete it like [v1].
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.. (0x08|0x0082) plen 15
Handle: 0x00
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.. (0x08|0x0086) plen 12
Handle: 0x00
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 | 247 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 326 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 +242 -5
271 lines not on this page · raw message
Signature · 1 line
2.47.3
PATCH v3 9/9 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, and is matched with the LE Create Connection command which started the connection.
Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 4
LE Periodic Advertising Subevent Data Request (0x27)
Handle: 0x00
Subevent start: 0 (0x00)
Subevent data count: 4 (0x04)Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 22
LE Periodic Advertising Response Report (0x28)
Handle: 0x00
Subevent: 2 (0x02)
TX status: AUX_SYNC_SUBEVENT_IND was transmitted (0x00)
Num responses: 2
Entry 0
TX power: not available (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: not available (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 | 197 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 286 insertions(+), 2 deletions(-)
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 +195 -2
245 lines not on this page · raw message
Signature · 1 line
2.47.3
Luiz Augusto von Dentz
maintainerHi Roland,
Quoted 77 lines · Roland Schober
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 6 fix existing decoders which the new ones use or which were found on the way:
- theConnection_Handlereturned by the Periodic Advertising Sync Transfer commands and by LE Remove ISO Data Path was read as one octet,
- LE Periodic Advertising Report trustedData_Lengthand LE Extended Create Connection trusted the number of PHY parameter blocks, so truncated packets made them decode octets outside the packet,
- the LE Set Periodic Advertising commands printed the advertising handle as a connection handle,
- LE Periodic Advertising Report printed an unavailable TX power as 127 dBm and named the AoD CTE type with 1 us slots AoA,
- LE PAST Received printed the handle twice and decoded the clock accuracy as a BR/EDR one.Patch 7 splits the LE Periodic Advertising Report decoding into helpers without changing its output, so that patch 9 can share it.
Patch 8 decodes the five commands and patch 9 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. Every command and event of these traces was also fed to the decoders cut to every length, in a buffer of exactly that size, with AddressSanitizer, which found no read beyond a packet. The output for well formed packets of the existing decoders was compared with the current tree.
v3:
- Add patches 4, 5 and 6, and print the advertising handle, the TX power and the CTE type the same way in the new decoders.
- Patch 2: also report octets beyondData_Length.
- Patch 3: report extra PHY parameter blocks, and do not report the remaining PHYs as unknown after a truncated block.
- Patch 8: reuse the [v1] decoder for LE Set Periodic Advertising Parameters [v2], print0x00subevent timings as none, checkResponse_Data_Length, and match LE Extended Create Connection [v2] with the events which complete it.
- Patch 9:Data_Status0xffkeeps its reserved meaning in the [v1] LE Periodic Advertising Report, LE Enhanced Connection Complete [v2] is matched with the command which started the connection.
- Patches 8 and 9: report a subevent data command or a response report with fewer entries than announced.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.
- The patch which splits the LE Periodic Advertising Report decoding keeps the newData_Lengthcheck in the shared helper.Roland Schober (9):
monitor: Fix handle decoding ofstatus_handle_rsp
monitor: Fix data length of LE PA Report decoding
monitor: Fix PHY decoding of LE Ext Create Connection
monitor: Fix advertising handle of LE PA commands
monitor: Fix TX power and CTE Type of LE PA Report
monitor: Fix LE PAST Received decoding
monitor: Split LE PA Report decoding into helpers
monitor: Add PAwR HCI commands decoding
monitor: Add PAwR HCI events decoding
Quoted 8 lines
monitor/analyze.c | 1 + monitor/bt.h | 174 ++++++++++++++ monitor/packet.c | 585 +++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 708 insertions(+), 52 deletions(-)--
2.47.3
Copilot flagged 2 problems:
https://github.com/bluez/bluez/pull/2849#pullrequestreview-5977101363
Signature · 1 line
Luiz Augusto von Dentz