Commit Graph

971 Commits

Author SHA1 Message Date
Joseph Hwang
d89af9acb7 monitor: fix division by zero about conn->tx_pkt_med
In a connection without outgoing traffic, conn->tx_num will remain 0.
In this case, conn->tx_pkt_med should be simply 0 without calculating
"conn->tx_bytes / conn->tx_num".

This was likely to happen, for example, when "btmon -w btsnoop.log"
was launched in the middle of a LE mouse connection, and a number of
incoming ACL Data RX were received as the mouse movements.  When
running "btmon -a btsnoop.log", it would encounter this error.

Reviewed-by: Alain Michaud <alainm@chromium.org>
Reviewed-by: Yun-Hao Chung <howardchung@chromium.org>
Reviewed-by: Shuo-Peng Liao <deanliao@chromium.org>
2022-02-23 08:57:33 -08:00
Tedd Ho-Jeong An
053a1d4bdb monitor/sdp: Fixes out-of-bounds array access
This patch fixes the out-of-bounds array access caught by the ASAN.

monitor/sdp.c:497:19: runtime error: index 8 out of bounds for type
'cont_data [8]'
=================================================================
==4180==ERROR: AddressSanitizer: global-buffer-overflow on address
0x7fe2d271a542 at pc 0x7fe2d174a57d bp 0x7ffc6dcac1d0 sp 0x7ffc6dcab978
WRITE of size 9 at 0x7fe2d271a542 thread T0
    #0 0x7fe2d174a57c  (/lib/x86_64-linux-gnu/libasan.so.5+0x9b57c)
    #1 0x7fe2d23bae85 in search_attr_rsp monitor/sdp.c:692
    #2 0x7fe2d23be3f1 in sdp_packet monitor/sdp.c:771
    #3 0x7fe2d23b004c in l2cap_frame monitor/l2cap.c:3247
    #4 0x7fe2d23b3d9c in l2cap_packet monitor/l2cap.c:3312
    #5 0x7fe2d237d5c3 in packet_hci_acldata monitor/packet.c:11638
    #6 0x7fe2d2381876 in packet_monitor monitor/packet.c:3967
    #7 0x7fe2d230b285 in data_callback monitor/control.c:973
    #8 0x7fe2d2447029 in mainloop_run src/shared/mainloop.c:106
    #9 0x7fe2d2449306 in mainloop_run_with_signal src/shared/mainloop-notify.c:188
    #10 0x7fe2d230324a in main monitor/main.c:290
    #11 0x7fe2d0b440b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
    #12 0x7fe2d2303b7d in _start (/home/han1/work/dev/bluez/monitor/btmon+0x1dbb7d)

0x7fe2d271a542 is located 30 bytes to the left of global variable 'tid_list'
defined in 'monitor/sdp.c:43:24' (0x7fe2d271a560) of size 384
0x7fe2d271a542 is located 2 bytes to the right of global variable 'cont_list'
defined in 'monitor/sdp.c:424:25' (0x7fe2d271a400) of size 320
SUMMARY: AddressSanitizer: global-buffer-overflow
(/lib/x86_64-linux-gnu/libasan.so.5+0x9b57c)
...
==4180==ABORTING
2022-02-10 14:23:55 -08:00
Luiz Augusto von Dentz
e700d5526c bthost: Fix not handling ACL fragmentation
Large packets requires the support of ACL fragmentation in order to be
properly processed.
2022-02-09 15:42:45 -08:00
Luiz Augusto von Dentz
0cf3bbbf94 monitor: Fix misaligment errors when parsing BIG/CIG events
This fixes erros such as:

  monitor/packet.c:8129:2: runtime error: load of misaligned address
  0x55956a438f2d for type 'const uint16_t', which requires 2 byte
  alignment
2022-01-31 16:37:27 -08:00
Luiz Augusto von Dentz
9822898fd5 monitor/avctp: Fix parsing of GetElementAttribute
AVRCP byte order is always big endian:

Audio/Video Remote Control / Profile Specification - Page 20:

 'Transfer Octet Order; Packets shall transfer multiple-octet fields in
 standard network octet order (Big Endian), with more significant
 (high-order) octets being transferred before less-significant (low-order)
 octets.'
2022-01-14 14:02:05 -08:00
Luiz Augusto von Dentz
4a00535fa3 emulator: Add support for vendor commands
This adds support for vendor commands reserving a single opcode (0xfc10)
so it can be extended using subcommands, similar to how MSFT works.

The first subcommand (0x00) enables the emulator to generate arbitrary
events using the commands parameters:

> tools/hcitool cmd 3f 10 00 22 24 d0 d0 d0 d0 d0 d0 ff ff
< HCI Command: Vendor (0x3f|0x0010) plen 11
        00 22 24 d0 d0 d0 d0 d0 d0 ff ff
	."$........
Bluetooth: hci0: Malformed HCI Event: 0x22
> HCI Event: Inquiry Result with R.. (0x22) plen 9
        Num responses: 36
        Page scan repetition mode: Reserved (0xff)
        Page period mode: Reserved (0xff)
        Class: 0xffffd0
          Major class: Uncategorized, specific device code not specified
          Minor class: 0x34
          Limited Discoverable Mode
          invalid service class
        Clock offset: 0x6368
        RSSI: 105 dBm (0x69)
> HCI Event: Command Complete (0x0e) plen 4
      Vendor (0x3f|0x0010) ncmd 1
        Status: Success (0x00)
2022-01-05 15:06:40 -08:00
Luiz Augusto von Dentz
2be2b945e2 build: Fix build when sanitizer are enabled
This fixes various issues found when sanitizers are enabled.
2021-12-23 11:45:31 -08:00
Tedd Ho-Jeong An
9a79c9b74a monitor: Fix uninitiailzed scalar variable
This patch fixes the uninitiailzed varialble(CWE-457) reported by
the Coverity scan.
2021-11-15 13:07:07 -08:00
Luiz Augusto von Dentz
72c562e4e4 monitor: Add support for Device Privacy Mode flag
This adds proper decoding for Device Privacy Mode flag:

@ MGMT Command: Set Device... (0x0050) plen 11  {0x0001}
        LE Address: BC:9A:78:56:34:12 (OUI BC-9A-78)
        Current Flags: 0x00000002
          Device Privacy Mode
@ MGMT Event: Device Flags... (0x002a) plen 15  {0x0002}
        LE Address: BC:9A:78:56:34:12 (OUI BC-9A-78)
        Supported Flags: 0x00000003
          Remote Wakeup
          Device Privacy Mode
        Current Flags: 0x00000002
          Device Privacy Mode
2021-11-09 14:45:51 -08:00
Luiz Augusto von Dentz
47be9d4056 monitor: Enable decoding of MSFT extension with emulator
This enables decoding MSFT extension with emulator instances since it
shall be the only one using Linux Foundation as manufacturer.
2021-10-21 11:32:23 -07:00
Luiz Augusto von Dentz
5226a2d359 monitor/msft: Add feature bits definition
This adds the feature bits definition used in
HCI_VS_MSFT_Read_Supported_Features.
2021-10-21 11:32:20 -07:00
Luiz Augusto von Dentz
46ee5feb55 monitor/msft: Fix uuid.u128 format
128 bits are actually 16 octecs not 8.
2021-10-21 11:32:20 -07:00
Luiz Augusto von Dentz
beb5cc05e8 monitor: Make use of MSFT packet definitions
This make use of the packet definitions for MSFT extension.
2021-10-18 13:04:21 -07:00
Luiz Augusto von Dentz
7d49b158ba monitor: Add packet definitions for MSFT extension
This adds proper packet definitions for command and response of MSFT
extension.
2021-10-18 13:03:31 -07:00
Archie Pusaka
7582f36071 monitor: Inclusive language changes
BT core spec 5.3 promotes the usage of inclusive languages.
This CL replaces some terms with the more appropriate counterparts,
such as "central", "peripheral", "link key", and "accept list"

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2021-09-21 10:51:54 +02:00
Archie Pusaka
b7d6a7d256 lib: Inclusive language changes
BT core spec 5.3 promotes the usage of inclusive languages.
This CL replaces some terms with the more appropriate counterparts,
such as "central", "peripheral", and "accept list".

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2021-09-21 10:51:53 +02:00
Luiz Augusto von Dentz
8891babcf4 monitor: Fix calculation of RFCOMM length
Byte order is assumed to be big endian instead of little endian.
2021-09-02 17:08:18 -07:00
Marcel Holtmann
039888b697 monitor: Track PSM for L2CAP analyze function 2021-08-17 13:11:16 +02:00
Mariusz Skamra
214278a37f monitor: Fix logging of CIG Test SDU Interval param
This fixes log of SDU interval in StoM direction.
2021-08-16 10:43:36 -07:00
Mariusz Skamra
d26a711113 monitor: Fix Maximum PDU type in CIS Test Param
The Maximum PDU in CIS Test parameters is 2 byte value.
2021-08-16 10:43:36 -07:00
Marcel Holtmann
f90e7e1a4e monitor: Track L2CAP packets for analyze function 2021-08-16 18:35:25 +02:00
Marcel Holtmann
7a6b68050f monitor: Store MSFT extension event prefix 2021-08-16 17:36:00 +02:00
Luiz Augusto von Dentz
6fb2f1aa5f monitor: Make --analyze print address OUI
This makes analyze.c use packet_print_addr which does take care of
decoding OUI portion of the address.
2021-08-09 15:47:18 -07:00
Luiz Augusto von Dentz
34d44262d7 monitor: Make --analyze output latencies in msec
Milisecconds is probably the best unit to have since it is unlikely that
the controller can respond in under 1 msec as well as most time
sensitive connection e.g. A2DP, HFP, etc, also don't expect the
latencies to be over 1 sec.
2021-08-09 15:01:29 -07:00
Luiz Augusto von Dentz
7dc659cde0 monitor: Fix not accouting for multiple outstanding packets
Analyze code was not accounting for the fact that multiple outstanding
packets could be pending which will cause the last_tx to be overwritten
but its latency would be calculated against the very first packet
complete.
2021-08-09 15:01:29 -07:00
Luiz Augusto von Dentz
52c7d16865 monitor: Fix minimun packet latency
It seems timer_sub can produce negative values leading to median packet
latency to be negative e.g conn->last_tx_compl is ahead of
conn->last_tx, in which case it should be discarded.
2021-08-09 15:01:29 -07:00
Luiz Augusto von Dentz
ea224edbd0 monitor: Fix median packet size
Calculating the median packet based on the current median + size / 2
does not account for last packet could smaller e.g. opp transfer could
end with just 1 byte which would cut the median in a half, so this
switch to more traditional means of calculating by doing total bytes
sent / num of packets so each an every packet has the same weight.
2021-08-09 15:01:29 -07:00
Tedd Ho-Jeong An
e098cad155 monitor: Add support for tlv based version format for Intel vendor
Some Intel device supports two different formats of the
HCI_Intel_Read_Version command depends on the command parameter and this
patch parses the command and response parameters depends on the format.
2021-08-06 14:47:19 -07:00
Marcel Holtmann
8867c39108 monitor: Add further stats to analzye functionality 2021-08-06 16:15:30 +02:00
Mariusz Skamra
1b5abf42bc monitor: Fix truncated server socket path parameter
This fixes the issue of --server <socket> parameter
last character was dropped. There is no need to use
strncpy, as the length is already checked, and it is
known that the destination buffer is big enough
2021-08-04 16:50:55 +02:00
Marcel Holtmann
97c4d64f66 monitor: Track connections for analyze function 2021-08-03 23:28:55 +02:00
Marcel Holtmann
5ddd8cd51c monitor: Remove unneeded fprintf for new devices 2021-08-03 21:55:00 +02:00
Marcel Holtmann
f9b8fac243 monitor: Count number of control messages 2021-08-03 17:04:47 +02:00
Marcel Holtmann
30a4fdcbfe monitor: Add ISO packets to analyze option 2021-08-03 16:58:41 +02:00
Marcel Holtmann
f722367376 monitor: Remove unneeded fprintf for unknown opcodes 2021-08-03 16:54:03 +02:00
Sonny Sasaka
8e53124d49 monitor: Print EIR of Extended Advertisement Report
It's useful to be able to see Extended Adv's EIR flags just like the
legacy Adv.
2021-07-29 13:55:19 -07:00
Joseph Hwang
de6c0c77e5 monitor: add new Intel extended telemetry events
This patch adds new Intel extended telemetry events for both ACL and
SCO/eSCO audio link quality reports.

For SCO/eSCO audio link quality report, it shows something like
> HCI Event: Vendor (0xff) plen 190  #120 [hci0] 2021-05-31 20:27:50.257
        Vendor Prefix (0x8780)
      Intel Extended Telemetry (0x87)
        Extended Telemetry (0x80): SubOpcode (0x03)
        Extended event type (0x01): Audio Link Quality Report Type(0x05)
        SCO/eSCO connection handle (0x6a): 0x0101
        Packets from host (0x6b): 399
        Tx packets (0x6c): 403
        Rx payload lost (0x6d): 3
        Tx payload lost (0x6e): 0
        Rx No SYNC errors (0x6f): 3 2 3 3 0
        Rx HEC errors (0x70): 0 0 0 0 0
        Rx CRC errors (0x71): 2 0 0 0 0
        Rx NAK errors (0x72): 6 0 0 0 0
        Failed Tx due to Wifi coex (0x73): 6 0 0 0 0
        Failed Rx due to Wifi coex (0x74): 0 0 0 0 0
        Late samples inserted based on CDC (0x75): 0
        Samples dropped (0x76): 0
        Mute samples sent at initial connection (0x77): 0
        PLC injection data (0x78): 0

For ACL audio link quality report, it shows something like
> HCI Event: Vendor (0xff) plen 142  #120 [hci0] 2021-05-31 20:27:50.261
        Vendor Prefix (0x8780)
      Intel Extended Telemetry (0x87)
        Extended Telemetry (0x80): SubOpcode (0x03)
        Extended event type (0x01): Audio Link Quality Report Type(0x05)
        ACL connection handle (0x4a): 0x0100
        Rx HEC errors (0x4b): 0
        Rx CRC errors (0x4c): 0
        Packets from host (0x4d): 100
        Tx packets (0x4e): 101
        Tx packets 0 retries (0x4f): 89
        Tx packets 1 retries (0x50): 11
        Tx packets 2 retries (0x51): 1
        Tx packets 3 retries (0x52): 0
        Tx packets 4 retries and more (0x53): 0
        Tx DH1 packets (0x54): 0
        Tx DH3 packets (0x55): 0
        Tx DH5 packets (0x56): 0
        Tx 2DH1 packets (0x57): 0
        Tx 2DH3 packets (0x58): 0
        Tx 2DH5 packets (0x59): 0
        Tx 3DH1 packets (0x5a): 6
        Tx 3DH3 packets (0x5b): 0
        Tx 3DH5 packets (0x5c): 94
        Rx packets (0x5d): 272
        ACL link throughput (KBps) (0x5e): 343815
        ACL max packet latency (ms) (0x5f): 20625
        ACL avg packet latency (ms) (0x60): 12

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
2021-07-20 10:59:05 -07:00
Luiz Augusto von Dentz
d9979f26e6 emulator/btdev: Add support HCI LE Adv Set Terminated event
This patch adds support the HCI_LE_Advertising_Set_Terminated event in
btdev.
2021-06-23 11:51:10 -07:00
Tedd Ho-Jeong An
5145b1ea2e emulator/btdev: Add support multiple instance of extended advertising
This patch adds support multiple instance of extended advertising.
2021-06-23 11:51:10 -07:00
Alain Michaud
dda85ae73f monitor: Adding missing device found flag in the parser
A new flag was added to the kernel implementation of the Device Found
event, but had not been added to the parser leading to an "Unknown device
flag" error in btmon.

Reviewed-by: Yu Liu <yudiliu@google.com>
2021-06-16 15:33:39 -07:00
Luiz Augusto von Dentz
c3db40eee8 monitor: Fix typos
This fixes interval typos.
2021-06-15 15:30:44 -07:00
Marcel Holtmann
f7a568d722 monitor: Decode MSFT LE Monitor Advertisement 2021-05-20 00:40:53 +02:00
Luiz Augusto von Dentz
52de2520ff btmon: Use bt_uuid128_to_str when printing UUIDs of 128 bits
This ensures that know UUIDs names are printed including those used by
experimental features.
2021-05-18 11:36:20 -07:00
Yun-Hao Chung
d6fc849fbd monitor: Fix possible crash of rfcomm packet
When RFCOMM_TEST_EA returns false, btmon assumes packet data has at
least 5 bytes long. If that assumption fails, btmon could crash when
trying to read the next byte.
This patch fix it by checking the remaining size before reading the last
byte.

Reviewed-by: apusaka@chromium.org
2021-05-13 14:13:20 -07:00
Tedd Ho-Jeong An
fa57cb68e1 monitor: Remove Pygments dependency from manpage
This patch removes the Pygments dependency from btmon .rst file.
When the code-block type is specified, the rst2man throws a warning
asking for Pygments package.
2021-05-10 11:13:02 -07:00
Luiz Augusto von Dentz
6a4248bebc monitor/avdtp: Fix decoding of reject type
Reject type was not being decoded, so this remove the early return and
leave the callback to decode it:

< ACL Data TX: Handle 42 flags 0x00 dlen 8
      Channel: 64 len 4 [PSM 25 mode Basic (0x00)] {chan 1}
      AVDTP: Set Configuration (0x03) Response Reject (0x03) type 0x00 label 2 nosp 0
        Service Category: Reserved (0x00)
        Error code: BAD_ACP_SEID (0x12)
2021-05-04 16:56:18 -07:00
Tedd Ho-Jeong An
b66f406e1e monitor: Convert manpage to rst format
This patch adds support to convert reStructuredText formatted btmon
manpage to manpage with rst2man tool.
2021-05-04 16:49:01 -07:00
Tedd Ho-Jeong An
cfeaa68713 monitor: Add Intel read supported features command
< HCI Command: Intel Read Supported Features (0x3f|0x00a6) plen 1
        Page: 0x01
> HCI Event: Command Complete (0x0e) plen 22
      Intel Read Supported Features (0x3f|0x00a6) ncmd 1
        Status: Success (0x00)
        Page: 0x01
        Max Pages: 0x02
        Supported Features:
        1f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
2021-04-20 13:24:26 -07:00
Marcel Holtmann
45dd827674 monitor: Update RSSI printing function 2021-04-02 07:42:09 +02:00
Marcel Holtmann
3d9ff9d52e monitor: Add basic decoding for MSFT extension 2021-03-19 20:29:51 +01:00