platform/upstream/bluez.git
7 months agomonitor/intel: Fix not skipping unknown TLV types
Luiz Augusto von Dentz [Tue, 9 May 2023 20:59:42 +0000 (13:59 -0700)]
monitor/intel: Fix not skipping unknown TLV types

The code was stopping at first time it detected an unknown TLV type when
it could continue:

> HCI Event: Vendor (0xff) plen 82
        Vendor Prefix (0x8780)
      Intel Extended Telemetry (0x03)
        Extended event type (0x01): Audio Link Quality Report Type (0x05)
        Unknown extended subevent 0x81
        01 01 05 81 04 88 13 00 00 82 10 6a e6 6c 00 00  ...........j.l..
        00 00 00 4b 45 53 00 00 00 00 00 83 04 00 00 00  ...KES..........
        00 84 04 01 03 07 19 85 04 3f 08 00 00 86 08 00  .........?......
        00 00 00 00 00 00 00 87 04 00 00 00 00 88 04 00  ................
        00 00 00 89 04 00 00 00 00 8a 04 b9 49 0c 00     ............I..

So this changes it to:

> HCI Event: Vendor (0xff) plen 82
        Vendor Prefix (0x8780)
      Intel Extended Telemetry (0x03)
        Extended event type (0x01): Audio Link Quality Report Type (0x05)
        Unknown extended subevent 0x81
        88 13 00 00                                      ....
        Unknown extended subevent 0x82
        04 97 6c 00 00 00 00 00 68 44 53 00 00 00 00 00  ..l.....hDS.....
        Unknown extended subevent 0x83
        00 00 00 00                                      ....
        Unknown extended subevent 0x84
        01 03 07 19                                      ....
        Unknown extended subevent 0x85
        3a 08 00 00                                      :...
        Unknown extended subevent 0x86
        00 00 00 00 00 00 00 00                          ........
        Unknown extended subevent 0x87
        00 00 00 00                                      ....
        Unknown extended subevent 0x88
        00 00 00 00                                      ....
        Unknown extended subevent 0x89
        00 00 00 00                                      ....
        Unknown extended subevent 0x8a
        9f 1a 2f 00                                      ../.

7 months agomonitor: Fix misaligment errors
Luiz Augusto von Dentz [Fri, 5 May 2023 20:20:25 +0000 (13:20 -0700)]
monitor: Fix misaligment errors

This fixes the following errors:

monitor/packet.c:11968:27: runtime error: member access within
misaligned address 0x565448026d55 for type
'const struct monitor_l2cap_hdr', which requires 2 byte alignment
monitor/packet.c:11968:4: runtime error: member access within
misaligned address 0x565448026d55 for type
'const struct monitor_l2cap_hdr', which requires 2 byte alignment

7 months agomonitor/att: Attempt to insert discovered attributes
Luiz Augusto von Dentz [Fri, 5 May 2023 00:07:44 +0000 (17:07 -0700)]
monitor/att: Attempt to insert discovered attributes

This attempts to insert discovered attributes into monitor gatt_db
instance if their respective discover procedures are used which enables
decoding traces injected by user via unit testing:

> sudo unit/test-bap -m -s "34

= test-bap: BAP/UCL/SCC/BV-034-C [UCL SNK Config Codec, VS] - run
> test-bap: User Data RX
      ATT: Read Request (0x0a) len 2
        Handle: 0x0003 Type: Sink PAC (0x2bc9)
< test-bap: User Data TX
      ATT: Read Response (0x0b) len 8
        Handle: 0x0003 Type: Sink PAC (0x2bc9)
        Value: 01ff010001000000
          Number of PAC(s): 1
          PAC #0:
            Codec: Vendor specific (0xff)
            Codec Company ID: Nokia Mobile Phones (0x0001)
            Codec Vendor ID: 0x0001
> test-bap: User Data RX
      ATT: Read Request (0x0a) len 2
        Handle: 0x0006 Type: Sink Audio Locations (0x2bca)
< test-bap: User Data TX
      ATT: Read Response (0x0b) len 4
        Handle: 0x0006 Type: Sink Audio Locations (0x2bca)
        Value: 03000000
           Location: 0x00000003
              Front Left (0x00000001)
              Front Right (0x00000002)
> test-bap: User Data RX
      ATT: Read Request (0x0a) len 2
        Handle: 0x0009 Type: Source PAC (0x2bcb)
< test-bap: User Data TX
      ATT: Read Response (0x0b) len 8
        Handle: 0x0009 Type: Source PAC (0x2bcb)
        Value: 01ff010001000000
          Number of PAC(s): 1
          PAC #0:
            Codec: Vendor specific (0xff)
            Codec Company ID: Nokia Mobile Phones (0x0001)
            Codec Vendor ID: 0x0001
> test-bap: User Data RX
      ATT: Read Request (0x0a) len 2
        Handle: 0x000c Type: Source Audio Locations (0x2bcc)
< test-bap: User Data TX
      ATT: Read Response (0x0b) len 4
        Handle: 0x000c Type: Source Audio Locations (0x2bcc)
        Value: 03000000
           Location: 0x00000003
              Front Left (0x00000001)
              Front Right (0x00000002)
> test-bap: User Data RX
      ATT: Read Request (0x0a) len 2
        Handle: 0x000f Type: Available Audio Contexts (0x2bcd)
< test-bap: User Data TX
      ATT: Read Response (0x0b) len 4
        Handle: 0x000f Type: Available Audio Contexts (0x2bcd)
        Value: ff0f0e00
          Sink Context: 0x0fff
            Unspecified (0x0001)
            Conversational (0x0002)
            Media (0x0004)
            Game (0x0008)
            Instructional (0x0010)
            Voice Assistants (0x0020)
            Live (0x0040)
            Sound Effects (0x0080)
            Notifications (0x0100)
            Ringtone (0x0200)
            Alerts (0x0400)
            Emergency alarm (0x0800)
          Source Context: 0x000e
            Conversational (0x0002)
            Media (0x0004)
            Game (0x0008)
> test-bap: User Data RX
      ATT: Read Request (0x0a) len 2
        Handle: 0x0012 Type: Supported Audio Contexts (0x2bce)
< test-bap: User Data TX
      ATT: Read Response (0x0b) len 4
        Handle: 0x0012 Type: Supported Audio Contexts (0x2bce)
        Value: ff0f0e00
          Sink Context: 0x0fff
            Unspecified (0x0001)
            Conversational (0x0002)
            Media (0x0004)
            Game (0x0008)
            Instructional (0x0010)
            Voice Assistants (0x0020)
            Live (0x0040)
            Sound Effects (0x0080)
            Notifications (0x0100)
            Ringtone (0x0200)
            Alerts (0x0400)
            Emergency alarm (0x0800)
          Source Context: 0x000e
            Conversational (0x0002)
            Media (0x0004)
            Game (0x0008)
> test-bap: User Data RX
      ATT: Read Request (0x0a) len 2
        Handle: 0x0016 Type: Sink ASE (0x2bc4)
< test-bap: User Data TX
      ATT: Read Response (0x0b) len 2
        Handle: 0x0016 Type: Sink ASE (0x2bc4)
        Value: 0100
            ASE ID: 1
            State: Idle (0x00)
> test-bap: User Data RX
      ATT: Write Request (0x12) len 4
        Handle: 0x0017
          Data: 0100
< test-bap: User Data TX
      ATT: Write Response (0x13) len 0
> test-bap: User Data RX
      ATT: Read Request (0x0a) len 2
        Handle: 0x0019 Type: Sink ASE (0x2bc4)
< test-bap: User Data TX
      ATT: Read Response (0x0b) len 2
        Handle: 0x0019 Type: Sink ASE (0x2bc4)
        Value: 0200
            ASE ID: 2
            State: Idle (0x00)
> test-bap: User Data RX
      ATT: Write Request (0x12) len 4
        Handle: 0x001a
          Data: 0100
< test-bap: User Data TX
      ATT: Write Response (0x13) len 0
> test-bap: User Data RX
      ATT: Read Request (0x0a) len 2
        Handle: 0x001c Type: Source ASE (0x2bc5)
< test-bap: User Data TX
      ATT: Read Response (0x0b) len 2
        Handle: 0x001c Type: Source ASE (0x2bc5)
        Value: 0300
            ASE ID: 3
            State: Idle (0x00)
> test-bap: User Data RX
      ATT: Write Request (0x12) len 4
        Handle: 0x001d
          Data: 0100
< test-bap: User Data TX
      ATT: Write Response (0x13) len 0
> test-bap: User Data RX
      ATT: Read Request (0x0a) len 2
        Handle: 0x001f Type: Source ASE (0x2bc5)
< test-bap: User Data TX
      ATT: Read Response (0x0b) len 2
        Handle: 0x001f Type: Source ASE (0x2bc5)
        Value: 0400
            ASE ID: 4
            State: Idle (0x00)
> test-bap: User Data RX
      ATT: Write Request (0x12) len 4
        Handle: 0x0020
          Data: 0100
< test-bap: User Data TX
      ATT: Write Response (0x13) len 0
> test-bap: User Data RX
      ATT: Write Request (0x12) len 4
        Handle: 0x0023
          Data: 0100
< test-bap: User Data TX
      ATT: Write Response (0x13) len 0
> test-bap: User Data RX
      ATT: Write Command (0x52) len 13
        Handle: 0x0022 Type: ASE Control Point (0x2bc6)
          Data: 0101030202ff0100010000
            Opcode: Codec Configuration (0x01)
            Number of ASE(s): 1
            ASE: #0
            ASE ID: 0x03
            Target Latency: Balance Latency/Reliability (0x02)
            PHY: 0x02
            LE 2M PHY (0x02)
            Codec: Vendor specific (0xff)
            Codec Company ID: Nokia Mobile Phones (0x0001)
            Codec Vendor ID: 0x0001
< test-bap: User Data TX
      ATT: Handle Value Notification (0x1b) len 7
        Handle: 0x0022 Type: ASE Control Point (0x2bc6)
          Data: 0101030000
            Opcode: Codec Configuration (0x01)
            Number of ASE(s): 1
            ASE: #0
            ASE ID: 0x03
            ASE Response Code: Success (0x00)
            ASE Response Reason: None (0x00)
< test-bap: User Data TX
      ATT: Handle Value Notification (0x1b) len 27
        Handle: 0x001c Type: Source ASE (0x2bc5)
          Data: 03010102010a00204e00409c00204e00409c00ff0100010000
            ASE ID: 3
            State: Codec Configured (0x01)
            Framing: Unframed PDUs not supported (0x01)
            PHY: 0x02
            LE 2M PHY preffered (0x02)
            RTN: 1
            Max Transport Latency: 10
            Presentation Delay Min: 20000 us
            Presentation Delay Max: 40000 us
            Preferred Presentation Delay Min: 20000 us
            Preferred Presentation Delay Max: 40000 us
            Codec: Vendor specific (0xff)
            Codec Company ID: Nokia Mobile Phones (0x0001)
            Codec Vendor ID: 0x0001

7 months agoprofiles: Add initial code for BASS plugin
Iulia Tanasescu [Fri, 5 May 2023 08:29:43 +0000 (11:29 +0300)]
profiles: Add initial code for BASS plugin

This adds initial code for BASS plugin.

7 months agoshared/bass: Add initial code for handling BASS
Iulia Tanasescu [Fri, 5 May 2023 08:29:42 +0000 (11:29 +0300)]
shared/bass: Add initial code for handling BASS

This adds initial code for Broadcast Audio Scan Service.

7 months agoshared/util: Add iovec helpers
Iulia Tanasescu [Fri, 5 May 2023 08:29:41 +0000 (11:29 +0300)]
shared/util: Add iovec helpers

This adds iovec helper functions for handling byteorder and alignment
in place.

7 months agoshared/att-types: Add BT_ERROR_WRITE_REQUEST_REJECTED error code
Iulia Tanasescu [Fri, 5 May 2023 08:29:40 +0000 (11:29 +0300)]
shared/att-types: Add BT_ERROR_WRITE_REQUEST_REJECTED error code

This adds Write Request Rejected Common Profile and Service
Error Code.

7 months agolib/uuid: Add BASS UUIDs
Iulia Tanasescu [Fri, 5 May 2023 08:29:39 +0000 (11:29 +0300)]
lib/uuid: Add BASS UUIDs

This adds BASS UUIDs which will be used by Basic Audio Profile.

7 months agoshared/shell: Fix smatch warning
Luiz Augusto von Dentz [Mon, 1 May 2023 22:42:49 +0000 (15:42 -0700)]
shared/shell: Fix smatch warning

This fixes the following warning:

src/shared/shell.c:615:21: warning: non-ANSI function declaration of
function 'bt_shell_usage'

7 months agoshared/shell: Fix not releasing prompt
Luiz Augusto von Dentz [Mon, 1 May 2023 19:59:57 +0000 (12:59 -0700)]
shared/shell: Fix not releasing prompt

This fixes not releasing prompt when queueing a line to be executed
since it can be considered as user input if the init script is
attempting to enter it as response to prompt input.

7 months agoclient/player: Fix crash when RegisterEndpoint fails
Luiz Augusto von Dentz [Mon, 1 May 2023 19:27:20 +0000 (12:27 -0700)]
client/player: Fix crash when RegisterEndpoint fails

If RegisterEndpoint fails when there are multiple adapters it would
attempt to free the same endpoint multiple times.

7 months agoclient/player: Add support for Metadata in BAP Profile
Abhay Maheta [Thu, 29 Dec 2022 15:53:05 +0000 (21:23 +0530)]
client/player: Add support for Metadata in BAP Profile

This adds support for Metadata in BAP profile.
In order to register zero Metadata, 0 shall be
entered when prompted.

[bluetooth]# endpoint.register 00002bc9-0000-1000-8000-00805f9b34fb 0x06
[/local/endpoint/ep0] Enter Metadata (value/no): n
[/local/endpoint/ep0] Auto Accept (yes/no): y
[/local/endpoint/ep0] CIG (auto/value): a
[/local/endpoint/ep0] CIS (auto/value): a
Capabilities:
  03 01 ff 00 02 02 03 02 03 03 05 04 1e 00 f0 00  ................
Endpoint /local/endpoint/ep0 registered

7 months agotest-bap: Add SCC tests for Vendor-Specific codec
Luiz Augusto von Dentz [Thu, 27 Apr 2023 19:07:07 +0000 (12:07 -0700)]
test-bap: Add SCC tests for Vendor-Specific codec

4.8.2 Unicast Client Initiates a Config Codec Operation –
Vendor-Specific (page 42):

  Test Purpose:
  Verify that a Unicast Client IUT can initiate a Config Codec
  operation for a vendor-specific codec.

  Test Case Configuration:
  BAP/UCL/SCC/BV-033-C [UCL SRC Config Codec, VS]
  BAP/UCL/SCC/BV-034-C [UCL SNK Config Codec, VS]

  Pass verdict:
  The IUT successfully writes to the ASE Control Point characteristic
  with the opcode set to 0x01 (Config Codec) and the specified
  parameters. The Codec_ID parameter is formatted with octet 0 set to
  0xFF, octets 1–2 set to TSPX_VS_Company_ID, and octets 3–4 set to
  TSPX_VS_Codec_ID.

Test Summary
------------
BAP/UCL/SCC/BV-033-C [UCL SRC Config Codec, VS]      Passed
BAP/UCL/SCC/BV-034-C [UCL SNK Config Codec, VS]      Passed
Total: 2, Passed: 2 (100.0%), Failed: 0, Not Run: 0

7 months agoshared/util: Fix runtime error
Luiz Augusto von Dentz [Thu, 27 Apr 2023 19:02:52 +0000 (12:02 -0700)]
shared/util: Fix runtime error

This fixes the following errors:

src/shared/util.c:271:2: runtime error: null pointer passed as argument
2, which is declared to never be null

7 months agotest-bap: Introduce SCC tests for LC3
Luiz Augusto von Dentz [Tue, 25 Apr 2023 20:44:02 +0000 (13:44 -0700)]
test-bap: Introduce SCC tests for LC3

4.8.1 Unicast Client Initiates a Config Codec Operation – LC3
(Page 39):

  Test Purpose:
  Verify that a Unicast Client IUT can initiate a Config Codec
  operation for an LC3 codec.

  Test Case Configuration:
  BAP/UCL/SCC/BV-001-C [UCL SRC Config Codec, LC3 8_1]
  BAP/UCL/SCC/BV-002-C [UCL SRC Config Codec, LC3 8_2]
  BAP/UCL/SCC/BV-003-C [UCL SRC Config Codec, LC3 16_1]
  BAP/UCL/SCC/BV-004-C [UCL SRC Config Codec, LC3 16_2]
  BAP/UCL/SCC/BV-005-C [UCL SRC Config Codec, LC3 24_1]
  BAP/UCL/SCC/BV-006-C [UCL SRC Config Codec, LC3 24_2]
  BAP/UCL/SCC/BV-007-C [UCL SRC Config Codec, LC3 32_1]
  BAP/UCL/SCC/BV-008-C [UCL SRC Config Codec, LC3 32_2]
  BAP/UCL/SCC/BV-009-C [UCL SRC Config Codec, LC3 44.1_1]
  BAP/UCL/SCC/BV-010-C [UCL SRC Config Codec, LC3 44.1_2]
  BAP/UCL/SCC/BV-011-C [UCL SRC Config Codec, LC3 48_1]
  BAP/UCL/SCC/BV-012-C [UCL SRC Config Codec, LC3 48_2]
  BAP/UCL/SCC/BV-013-C [UCL SRC Config Codec, LC3 48_3]
  BAP/UCL/SCC/BV-014-C [UCL SRC Config Codec, LC3 48_4]
  BAP/UCL/SCC/BV-015-C [UCL SRC Config Codec, LC3 48_5]
  BAP/UCL/SCC/BV-016-C [UCL SRC Config Codec, LC3 48_6]
  BAP/UCL/SCC/BV-017-C [UCL SNK Config Codec, LC3 8_1]
  BAP/UCL/SCC/BV-018-C [UCL SNK Config Codec, LC3 8_2]
  BAP/UCL/SCC/BV-019-C [UCL SNK Config Codec, LC3 16_1]
  BAP/UCL/SCC/BV-020-C [UCL SNK Config Codec, LC3 16_2]
  BAP/UCL/SCC/BV-021-C [UCL SNK Config Codec, LC3 24_1]
  BAP/UCL/SCC/BV-022-C [UCL SNK Config Codec, LC3 24_2]
  BAP/UCL/SCC/BV-023-C [UCL SNK Config Codec, LC3 32_1]
  BAP/UCL/SCC/BV-024-C [UCL SNK Config Codec, LC3 32_2]
  BAP/UCL/SCC/BV-025-C [UCL SNK Config Codec, LC3 44.1_1]
  BAP/UCL/SCC/BV-026-C [UCL SNK Config Codec, LC3 44.1_2]
  BAP/UCL/SCC/BV-027-C [UCL SNK Config Codec, LC3 48_1]
  BAP/UCL/SCC/BV-028-C [UCL SNK Config Codec, LC3 48_2]
  BAP/UCL/SCC/BV-029-C [UCL SNK Config Codec, LC3 48_3]
  BAP/UCL/SCC/BV-030-C [UCL SNK Config Codec, LC3 48_4]
  BAP/UCL/SCC/BV-031-C [UCL SNK Config Codec, LC3 48_5]
  BAP/UCL/SCC/BV-032-C [UCL SNK Config Codec, LC3 48_6]

  Pass verdict:
  The IUT successfully writes to the ASE Control point with the opcode
  set to 0x01 (Config Codec) and correctly formatted parameter values
  from Table 4.9.
  The Codec_ID field is a 5-octet field with octet 0 set to the LC3
  Coding_Format value defined in Bluetooth Assigned Numbers, octets 1–4
  set to 0x0000.

Test Summary
------------
BAP/UCL/SCC/BV-001-C [UCL SRC Config Codec, LC3 8_1] Passed
BAP/UCL/SCC/BV-002-C [UCL SRC Config Codec, LC3 8_2] Passed
BAP/UCL/SCC/BV-003-C [UCL SRC Config Codec, LC3 16_1] Passed
BAP/UCL/SCC/BV-004-C [UCL SRC Config Codec, LC3 16_2] Passed
BAP/UCL/SCC/BV-005-C [UCL SRC Config Codec, LC3 24_1] Passed
BAP/UCL/SCC/BV-006-C [UCL SRC Config Codec, LC3 24_2] Passed
BAP/UCL/SCC/BV-007-C [UCL SRC Config Codec, LC3 32_1] Passed
BAP/UCL/SCC/BV-008-C [UCL SRC Config Codec, LC3 32_2] Passed
BAP/UCL/SCC/BV-009-C [UCL SRC Config Codec, LC3 44.1_1] Passed
BAP/UCL/SCC/BV-010-C [UCL SRC Config Codec, LC3 44.1_2] Passed
BAP/UCL/SCC/BV-011-C [UCL SRC Config Codec, LC3 48_1] Passed
BAP/UCL/SCC/BV-012-C [UCL SRC Config Codec, LC3 48_2] Passed
BAP/UCL/SCC/BV-013-C [UCL SRC Config Codec, LC3 48_3] Passed
BAP/UCL/SCC/BV-014-C [UCL SRC Config Codec, LC3 48_4] Passed
BAP/UCL/SCC/BV-015-C [UCL SRC Config Codec, LC3 48_5] Passed
BAP/UCL/SCC/BV-016-C [UCL SRC Config Codec, LC3 48_6] Passed
BAP/UCL/SCC/BV-017-C [UCL SNK Config Codec, LC3 8_1] Passed
BAP/UCL/SCC/BV-018-C [UCL SNK Config Codec, LC3 8_2] Passed
BAP/UCL/SCC/BV-019-C [UCL SNK Config Codec, LC3 16_1] Passed
BAP/UCL/SCC/BV-020-C [UCL SNK Config Codec, LC3 16_2] Passed
BAP/UCL/SCC/BV-021-C [UCL SNK Config Codec, LC3 24_1] Passed
BAP/UCL/SCC/BV-022-C [UCL SNK Config Codec, LC3 24_2] Passed
BAP/UCL/SCC/BV-023-C [UCL SNK Config Codec, LC3 32_1] Passed
BAP/UCL/SCC/BV-024-C [UCL SNK Config Codec, LC3 32_2] Passed
BAP/UCL/SCC/BV-025-C [UCL SNK Config Codec, LC3 44.1_1] Passed
BAP/UCL/SCC/BV-026-C [UCL SNK Config Codec, LC3 44.1_2] Passed
BAP/UCL/SCC/BV-027-C [UCL SNK Config Codec, LC3 48_1] Passed
BAP/UCL/SCC/BV-028-C [UCL SNK Config Codec, LC3 48_2] Passed
BAP/UCL/SCC/BV-029-C [UCL SNK Config Codec, LC3 48_3] Passed
BAP/UCL/SCC/BV-030-C [UCL SNK Config Codec, LC3 48_4] Passed
BAP/UCL/SCC/BV-031-C [UCL SNK Config Codec, LC3 48_5] Passed
BAP/UCL/SCC/BV-032-C [UCL SNK Config Codec, LC3 48_6] Passed
Total: 32, Passed: 32 (100.0%), Failed: 0, Not Run: 0

7 months agoshared/lc3: Update configuration to use iovec
Luiz Augusto von Dentz [Tue, 25 Apr 2023 20:40:42 +0000 (13:40 -0700)]
shared/lc3: Update configuration to use iovec

This use iovec as expected storage for capabilities and configuration
so it is inline with what bluetoothctl has been using making it simpler
to reuse these definitions.

7 months agoshared/bap: Fix typo
Luiz Augusto von Dentz [Tue, 25 Apr 2023 20:38:40 +0000 (13:38 -0700)]
shared/bap: Fix typo

Fix typo s/BT_BAP_CONFIG_LATENCY_BALACED/BT_BAP_CONFIG_LATENCY_BALANCED

7 months agoshared/tester: Add support for NULL PDUs
Luiz Augusto von Dentz [Tue, 25 Apr 2023 00:15:00 +0000 (17:15 -0700)]
shared/tester: Add support for NULL PDUs

This adds support for NULL PDUs which can be used to skip a round of
TX/RX.

7 months agoshare/bap: Fix not removing timeout on bap_free
Luiz Augusto von Dentz [Mon, 24 Apr 2023 23:30:31 +0000 (16:30 -0700)]
share/bap: Fix not removing timeout on bap_free

This fixes not removing the process_id timeout when freeing the session
which can cause the following crash:

Invalid read of size 8
  at 0x18EB39: bap_debug (bap.c:553)
  by 0x1913A8: bap_process_queue (bap.c:3542)
  by 0x1A8630: timeout_callback (timeout-glib.c:25)
Address 0x55e0650 is 128 bytes inside a block of size 160 free'd
  at 0x48480E4: free (vg_replace_malloc.c:872)

7 months agoshared/bap: Fix crash detaching streams
Luiz Augusto von Dentz [Mon, 24 Apr 2023 23:05:06 +0000 (16:05 -0700)]
shared/bap: Fix crash detaching streams

If a stream is being detached but bt_bap reference is already 0 don't
attempt to detach the stream as they would be freed anyway:

Invalid read of size 8
   at 0x19A360: bap_free (bap.c:2576)
   by 0x19A360: bt_bap_unref (bap.c:2735)
   by 0x19A360: bt_bap_unref (bap.c:2727)
   by 0x160E9A: test_teardown (test-bap.c:412)
   by 0x1A8BCA: teardown_callback (tester.c:434)
 Address 0x55e05e0 is 16 bytes inside a block of size 160 free'd
   at 0x48480E4: free (vg_replace_malloc.c:872)
   by 0x1AD5F6: queue_foreach (queue.c:207)
   by 0x19A1C5: bt_bap_detach (bap.c:3879)
   by 0x19A1C5: bt_bap_detach (bap.c:3855)
   by 0x19A33F: bap_free (bap.c:2574)

7 months agomedia: Fix not storing Preferred Delay properly
Luiz Augusto von Dentz [Mon, 24 Apr 2023 18:45:23 +0000 (11:45 -0700)]
media: Fix not storing Preferred Delay properly

Preferred Delay properties were being stored as qos->pd_* instead of
qos->ppd_*.

7 months agobap: add Location parameter to SelectProperties
Pauli Virtanen [Sat, 22 Apr 2023 17:05:57 +0000 (17:05 +0000)]
bap: add Location parameter to SelectProperties

Add relevant PACS Location field as a parameter to SelectProperties.

SelectProperties may set Audio_Channel_Allocation, which shall be chosen
from the bits set in Sink/Source Audio Locations (BAP v1.0.1 Sec. 4.4.1,
Sec 4.4.2). Hence, audio server needs to know the supported values,
which it previously could not.

7 months agoshared/bap: add function to get location from PAC
Pauli Virtanen [Sat, 22 Apr 2023 17:05:56 +0000 (17:05 +0000)]
shared/bap: add function to get location from PAC

Add function to get the PACS Sink/Source Audio Locations field relevant
for a given PAC.

7 months agoobexd: agent: Use if-elseif instead of multi-if to check error message
Guiting Shen [Fri, 21 Apr 2023 02:47:31 +0000 (10:47 +0800)]
obexd: agent: Use if-elseif instead of multi-if to check error message

The obex agent will return only one error message at the same time.So
we should use if-elseif instead of multi-if to check error message which
maybe DEBUG_ERROR_NO_REPLY or OBEX_ERROR_REJECT in agent_reply().

7 months agoobexd: AuthorizePush: Support to return folder name for file storage
Guiting Shen [Thu, 20 Apr 2023 09:55:57 +0000 (17:55 +0800)]
obexd: AuthorizePush: Support to return folder name for file storage

The obex agent usually returns the full path by getting the default
folder and filename from the Filename property of the transfer object
which is not convenient.

The patch helps that the obex agent can return the folder name suffixed
with '/' or new full path or even null which will use the default name
if new_name is NULL and the default folder if the new_folder is NULL in
opp_chkput().

7 months agotools/iso-tester: Add Broadcast tests for encrypted BIG
Iulia Tanasescu [Wed, 19 Apr 2023 13:43:54 +0000 (16:43 +0300)]
tools/iso-tester: Add Broadcast tests for encrypted BIG

This adds the following tests for encrypted broadcast:

ISO Broadcaster Encrypted - Success
ISO Broadcaster Receiver Encrypted - Success

7 months agotools/isotest: Add BIG encryption options
Iulia Tanasescu [Wed, 19 Apr 2023 13:43:53 +0000 (16:43 +0300)]
tools/isotest: Add BIG encryption options

Add command line options for BIG encryption and broadcast code.

7 months agomonitor/packet: Fix BIG encryption decoding
Iulia Tanasescu [Wed, 19 Apr 2023 13:43:52 +0000 (16:43 +0300)]
monitor/packet: Fix BIG encryption decoding

Fix incorrect decoding of the encryption parameter when logging
the LE BIG Create Sync command.

7 months agoiso-tester: Add BAP Audio Configuration tests
Luiz Augusto von Dentz [Thu, 13 Apr 2023 00:43:51 +0000 (17:43 -0700)]
iso-tester: Add BAP Audio Configuration tests

This adds the following tests based on BAP Audio Configurations:

ISO AC 1 & 4 - Success
ISO AC 2 & 10 - Success
ISO AC 3 & 5 - Success
ISO AC 6(i) - Success
ISO AC 6(ii) - Success
ISO AC 7(i) - Success
ISO AC 7(ii) - Success
ISO AC 8(i) - Success
ISO AC 8(ii) - Success
ISO AC 9(i) - Success
ISO AC 9(ii) - Success
ISO AC 11(i) - Success
ISO AC 11(ii) - Success

7 months agobtdev: Fix not setting CIS parameters properly
Luiz Augusto von Dentz [Thu, 13 Apr 2023 00:39:03 +0000 (17:39 -0700)]
btdev: Fix not setting CIS parameters properly

The code was assuming only index 0 was to be used which doesn't work
when there are multiple CIS being programmed with different parameters.

7 months agomgmt-tester: Fix Get/Set PHY tests
Luiz Augusto von Dentz [Wed, 7 Sep 2022 23:49:00 +0000 (16:49 -0700)]
mgmt-tester: Fix Get/Set PHY tests

This fixes the following tests now that all supported PHYs are enabled
by default:

Start Discovery LE - (Ext Scan Param)   Failed
Get PHY Success                         Failed
Set PHY 1m 2m coded Succcess            Timed out

7 months agoclient/advertising: Add support for advertise.rsi command
Luiz Augusto von Dentz [Wed, 5 Apr 2023 23:04:28 +0000 (16:04 -0700)]
client/advertising: Add support for advertise.rsi command

This adds support for advertise.rsi command which can be used to request
the generation of RSI and include it as part of advertising data:

[bluetooth]# advertise.rsi --help
Show/Enable/Disable RSI to be advertised
Usage:
 rsi [on/off]
[bluetooth]# advertise.rsi
RSI: on
[bluetooth]# advertise on
...
Advertising object registered
Tx Power: off
Name: off
Appearance: off
Discoverable: on
RSI: on
[bluetooth]#

7 months agoadvertising: Add support for rsi as Includes
Luiz Augusto von Dentz [Wed, 5 Apr 2023 22:59:47 +0000 (15:59 -0700)]
advertising: Add support for rsi as Includes

This adds support for "rsi" when a SIRK has been set on main.conf, the
clients can then enable it via Includes property which will make the
daemon to automatically generate an RSI (hash+random) and include it as
part of the advertising data:

< HCI Command: LE Set Extended Advertising Data (0x08|0x0037) plen 15
        Handle: 0x01
        Operation: Complete extended advertising data (0x03)
        Fragment preference: Minimize fragmentation (0x01)
        Data length: 0x0b
        Resolvable Set Identifier: E2-4E-AA-1B-2B-61
          Hash: 0x1b2b61
          Random: 0xe24eaa
        Flags: 0x06
          LE General Discoverable Mode
          BR/EDR Not Supported

7 months agoadvertising-api: Add rsi to SupportedIncludes
Luiz Augusto von Dentz [Wed, 5 Apr 2023 22:56:11 +0000 (15:56 -0700)]
advertising-api: Add rsi to SupportedIncludes

This adds "rsi" as possible value to SupportedIncludes so when it is
available it means client and set it on its Includes property so a
proper RSI is generated and included as part of the Advertising Data.

7 months agoshared/ad: Fix bt_ad_has_data not matching when only type is passed
Luiz Augusto von Dentz [Wed, 5 Apr 2023 22:53:12 +0000 (15:53 -0700)]
shared/ad: Fix bt_ad_has_data not matching when only type is passed

bt_ad_has_data attempts to match the data portion even when not set
which is useful the user is only interested in actually mataching the
type alone.

7 months agomain.conf: Fix parsing of CSIS group
Luiz Augusto von Dentz [Wed, 5 Apr 2023 22:51:37 +0000 (15:51 -0700)]
main.conf: Fix parsing of CSIS group

There was a typo in the group name using CSIP instead of CSIS.

7 months agomonitor/att: Add decoding support for BASS
Iulia Tanasescu [Wed, 5 Apr 2023 10:54:42 +0000 (13:54 +0300)]
monitor/att: Add decoding support for BASS

This adds decoding support for BASS attributes:

> ACL Data RX: Handle 0 flags 0x02 dlen 7
      ATT: Read Request (0x0a) len 2
        Handle: 0x003a Type: Broadcast Receive State (0x2bc8)

< ACL Data TX: Handle 0 flags 0x00 dlen 45
      ATT: Read Response (0x0b) len 40
        Handle: 0x003a Type: Broadcast Receive State (0x2bc8)
        Value: 0100f2698be807c0013a6501020101000000000403020400
          Source_ID: 1
          Source_Address_Type: 0
          Source_Address: C0:07:E8:8B:69:F2
          Source_Adv_SID: 1
          Broadcast_ID: 0x01653a
          PA_Sync_State: Synchronized to PA
          BIG_Encryption: Broadcast_Code required
          Num_Subgroups: 1
          Subgroup #0:
            BIS_Sync State: 0x00000000
            Metadata #0: len 0x03 type 0x02
            Metadata: 0400

> ACL Data RX: Handle 0 flags 0x02 dlen 7
      ATT: Read Request (0x0a) len 2
        Handle: 0x003d Type: Broadcast Receive State (0x2bc8)

< ACL Data TX: Handle 0 flags 0x00 dlen 5
      ATT: Read Response (0x0b) len 0
        Handle: 0x003d Type: Broadcast Receive State (0x2bc8)
        Value:
          Empty characteristic

> ACL Data RX: Handle 0 flags 0x02 dlen 8
      ATT: Write Request (0x12) len 3
        Handle: 0x0040 Type: Broadcast Audio Scan Control Point (0x2bc7)
          Data: 00
            Opcode: Remote Scan Stopped (0x00)

< ACL Data TX: Handle 0 flags 0x00 dlen 9
      ATT: Error Response (0x01) len 4
        Write Request (0x12)
        Handle: 0x0040
        Error: Reserved (0x80)

> ACL Data RX: Handle 0 flags 0x02 dlen 8
      ATT: Write Request (0x12) len 3
        Handle: 0x0040 Type: Broadcast Audio Scan Control Point (0x2bc7)
          Data: 01
            Opcode: Remote Scan Started (0x01)

< ACL Data TX: Handle 0 flags 0x00 dlen 9
      ATT: Error Response (0x01) len 4
        Write Request (0x12)
        Handle: 0x0040
        Error: Reserved (0x80)

> ACL Data RX: Handle 0 flags 0x01 dlen 5
      ATT: Write Request (0x12) len 27
        Handle: 0x0040 Type: Broadcast Audio Scan Control Point (0x2bc7)
          Data: 0200f2698be807c0013a650100ffff01000000000403020400
            Opcode: Add Source (0x02)
            Source_Address_Type: 0
            Source_Address: C0:07:E8:8B:69:F2
            Source_Adv_SID: 1
            Broadcast_ID: 0x01653a
            PA_Sync_State: Do not synchronize to PA
            PA_Interval: 0xffff
            Num_Subgroups: 1
            Subgroup #0:
              BIS_Sync State: 0x00000000
              Metadata #0: len 0x03 type 0x02
              Metadata: 0400

< ACL Data TX: Handle 0 flags 0x00 dlen 9
      ATT: Error Response (0x01) len 4
        Write Request (0x12)
        Handle: 0x0040
        Error: Reserved (0x80)

> ACL Data RX: Handle 0 flags 0x02 dlen 22
      ATT: Write Request (0x12) len 17
        Handle: 0x0040 Type: Broadcast Audio Scan Control Point (0x2bc7)
          Data: 030102780001000000000403040400
            Opcode: Modify Source (0x03)
            Source_ID: 1
            PA_Sync_State: Synchronize to PA - PAST not available
            PA_Interval: 0x0078
            Num_Subgroups: 1
            Subgroup #0:
              BIS_Sync State: 0x00000000
              Metadata #0: len 0x03 type 0x04
              Metadata: 0400

< ACL Data TX: Handle 0 flags 0x00 dlen 9
      ATT: Error Response (0x01) len 4
        Write Request (0x12)
        Handle: 0x0040
        Error: Reserved (0x80)

> ACL Data RX: Handle 0 flags 0x02 dlen 25
      ATT: Write Request (0x12) len 20
        Handle: 0x0040 Type: Broadcast Audio Scan Control Point (0x2bc7)
          Data: 0401b803eac6afbb65a25a41f15305680201
            Opcode: Set Broadcast_Code (0x04)
            Source_ID: 1
            Broadcast_Code: b803eac6afbb65a25a41f15305680201

< ACL Data TX: Handle 0 flags 0x00 dlen 5
      ATT: Write Response (0x13) len 0

< ACL Data TX: Handle 0 flags 0x00 dlen 33
      ATT: Handle Multiple Value Notification (0x23) len 28
        Length: 0x0018
        Handle: 0x003a Type: Broadcast Receive State (0x2bc8)
          Data: 0100f2698be807c0013a6501020201000000000403020400
          Source_ID: 1
          Source_Address_Type: 0
          Source_Address: C0:07:E8:8B:69:F2
          Source_Adv_SID: 1
          Broadcast_ID: 0x01653a
          PA_Sync_State: Synchronized to PA
          BIG_Encryption: Decrypting
          Num_Subgroups: 1
          Subgroup #0:
            BIS_Sync State: 0x00000000
            Metadata #0: len 0x03 type 0x02
            Metadata: 0400

> ACL Data RX: Handle 0 flags 0x02 dlen 9
      ATT: Write Request (0x12) len 4
        Handle: 0x0040 Type: Broadcast Audio Scan Control Point (0x2bc7)
          Data: 0501
            Opcode: Remove Source (0x05)
            Source_ID: 1

< ACL Data TX: Handle 0 flags 0x00 dlen 9
      ATT: Error Response (0x01) len 4
        Write Request (0x12)
        Handle: 0x0040
        Error: Reserved (0x80)

7 months agoset: Fix not attempt to connect devices with RSI
Luiz Augusto von Dentz [Mon, 3 Apr 2023 18:50:36 +0000 (11:50 -0700)]
set: Fix not attempt to connect devices with RSI

If a device advertising with RSI is only found later after the set was
already create we shall still attempt to connect to it.

7 months agomesh: Tighten IO and fix out-of-bounds array access
Inga Stotland [Sat, 1 Apr 2023 00:16:02 +0000 (17:16 -0700)]
mesh: Tighten IO and fix out-of-bounds array access

This fixes the out-of-bounds array access in mesh-io-mgmt.c caught
by address sanitizer. Similar fixes were applied earlier to
generic and unit IOs. With this patch, the common code is factored
into a centralized location.

7 months agoadapter: Use regular discovery for filters which only have discoverable set
Hans de Goede [Fri, 31 Mar 2023 20:03:29 +0000 (22:03 +0200)]
adapter: Use regular discovery for filters which only have discoverable set

discovery_filter_to_mgmt_cp() does not add discovery_filter.discoverable
to the created mgmt_cp_start_service_discovery struct.

Instead update_discovery_filter() separately checks
client->discovery_filter->discoverable for all clients.

This means that for discovery-filters which only have the discoverable
flag set, to put the adapter in discoverable mode while discovering,
the created mgmt_cp_start_service_discovery struct is empty.

This empty mgmt_cp_start_service_discovery struct then gets sent
to the kernel as part of a MGMT_OP_START_SERVICE_DISCOVERY msg
by start_discovery_timeout().

This use of an empty filter with MGMT_OP_START_SERVICE_DISCOVERY
causes some bluetooth devices to not get seen with some (most?)
Broadcom bluetooth adapters. This problem has been observed with
the following Broadcom models: BCM4343A0, BCM43430A1, BCM43341B0 .

On these models the following 2 devices were not being discovered
when starting a scan with a filter with just discoverable set
in the filter (as gnome-bluetooth does):

Device 09:02:01:03:0F:87 (public)
        Name: Bluetooth 3.0 Keyboard
        Alias: Bluetooth 3.0 Keyboard
        Class: 0x00000540
        Icon: input-keyboard
        Paired: yes
        Bonded: yes
        Trusted: yes
        Blocked: no
        Connected: yes
        WakeAllowed: yes
        LegacyPairing: yes
        UUID: Service Discovery Serve.. (00001000-0000-1000-8000-00805f9b34fb)
        UUID: Human Interface Device... (00001124-0000-1000-8000-00805f9b34fb)
        UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
        Modalias: bluetooth:v05ACp022Cd011B

Device 00:60:D1:00:00:34 (public)
        Name: Bluetooth Mouse
        Alias: Bluetooth Mouse
        Class: 0x00002580
        Icon: input-mouse
        Paired: yes
        Bonded: yes
        Trusted: yes
        Blocked: no
        Connected: yes
        WakeAllowed: yes
        LegacyPairing: no
        UUID: Human Interface Device... (00001124-0000-1000-8000-00805f9b34fb)
        UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
        Modalias: usb:v0103p0204d001E

Since setting the discoverable flag on a filter only is a way to
automatically put the adapter in discoverable mode itself while
it is discovering; and since this does not any device filtering
at all; modify merge_discovery_filters() to treat discovery with
such filters as regular unfiltered discovery.

This results in start_discovery_timeout() starting regular
discovery through a MGMT_OP_START_DISCOVERY message and this
fixes these 2 example devices not getting discovered by the
mentioned Broadcom BT adapter models.

Link: https://gitlab.gnome.org/GNOME/gnome-bluetooth/-/merge_requests/163
Reviewed-by: Bastien Nocera <hadess@hadess.net>
7 months agoSplit bt_iso_qos into dedicated structures
Iulia Tanasescu [Fri, 31 Mar 2023 15:39:27 +0000 (18:39 +0300)]
Split bt_iso_qos into dedicated structures

Split bt_iso_qos into dedicated unicast and broadcast
structures and add additional broadcast parameters.

7 months agoavrcp: Fix crash while handling unsupported events
Luiz Augusto von Dentz [Wed, 22 Mar 2023 18:34:24 +0000 (11:34 -0700)]
avrcp: Fix crash while handling unsupported events

The following crash can be observed if the remote peer send and
unsupported event:

ERROR: AddressSanitizer: heap-use-after-free on address 0x60b000148f11
 at pc 0x559644552088 bp 0x7ffe28b3c7b0 sp 0x7ffe28b3c7a0
 WRITE of size 1 at 0x60b000148f11 thread T0
     #0 0x559644552087 in avrcp_handle_event profiles/audio/avrcp.c:3907
     #1 0x559644536c22 in control_response profiles/audio/avctp.c:939
     #2 0x5596445379ab in session_cb profiles/audio/avctp.c:1108
     #3 0x7fbcb3e51c43 in g_main_context_dispatch (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x55c43)
     #4 0x7fbcb3ea66c7  (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0xaa6c7)
     #5 0x7fbcb3e512b2 in g_main_loop_run (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x552b2)
     #6 0x559644754ab6 in mainloop_run src/shared/mainloop-glib.c:66
     #7 0x559644755606 in mainloop_run_with_signal src/shared/mainloop-notify.c:188
     #8 0x5596445bb963 in main src/main.c:1289
     #9 0x7fbcb3bafd8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
     #10 0x7fbcb3bafe3f in __libc_start_main_impl ../csu/libc-start.c:392
     #11 0x5596444e8224 in _start (/usr/local/libexec/bluetooth/bluetoothd+0xf0224)

7 months agomgmt-tester: Add devcoredump tests
Manish Mandlik [Thu, 30 Mar 2023 06:08:03 +0000 (23:08 -0700)]
mgmt-tester: Add devcoredump tests

Add mgmt-tester tests for hci devcoredump. These testa trigger the
devcoredump with a test data and verifies the generated devcoredump
file for the test data and correct devcoredump header fields.

7 months agovhci: Add support to trigger devcoredump and read the dump file
Manish Mandlik [Thu, 30 Mar 2023 06:08:02 +0000 (23:08 -0700)]
vhci: Add support to trigger devcoredump and read the dump file

Add vhci support to trigger the hci devcoredump by writing to
force_devcoredump debugfs entry and read the generated devcoredump
file.

7 months agodevice: Fix not setting initiator flag when auto-connecting
Luiz Augusto von Dentz [Wed, 29 Mar 2023 20:27:05 +0000 (13:27 -0700)]
device: Fix not setting initiator flag when auto-connecting

If the device is marked as auto-connect the kernel may initiate the
connection spontaneously causing new connections to not have set the
state->initiator flag properly.

7 months agobap: Mark devices to auto-connect
Luiz Augusto von Dentz [Wed, 29 Mar 2023 19:55:16 +0000 (12:55 -0700)]
bap: Mark devices to auto-connect

This makes devices with BAP support to auto-connect once they start
advertising.

7 months agol2test: Fix setting mode for BR/EDR l2cap socket
Simon Mikuda [Tue, 28 Mar 2023 05:26:19 +0000 (07:26 +0200)]
l2test: Fix setting mode for BR/EDR l2cap socket

BT_MODE_* enums are used only for socket SOL_BLUETOOTH, option BT_MODE
Otherwise we should use L2CAP_MODE_* enums.

7 months agol2test: Enable hex input for PSM
Simon Mikuda [Tue, 28 Mar 2023 05:26:18 +0000 (07:26 +0200)]
l2test: Enable hex input for PSM

7 months agomonitor: Cache IRK being parsed
Luiz Augusto von Dentz [Fri, 24 Mar 2023 23:38:56 +0000 (16:38 -0700)]
monitor: Cache IRK being parsed

This caches any IRK being parsed so they can be used to resolve
addresses later which fixes the problem of only being able to resolve
addresses if the monitor happens to be active while SMP exchange the
keys.

7 months agomonitor/att: Fix not loading gatt_db for devices using RPA
Luiz Augusto von Dentz [Fri, 24 Mar 2023 23:38:55 +0000 (16:38 -0700)]
monitor/att: Fix not loading gatt_db for devices using RPA

Device using RPA have its storage using its identity address so this
uses keys_resolve_identity to attempt to resolve the destination
address instead of always using the connection address.

7 months agomonitor/att: Print value when printing descriptors
Luiz Augusto von Dentz [Fri, 24 Mar 2023 23:38:54 +0000 (16:38 -0700)]
monitor/att: Print value when printing descriptors

This prints the value attribute information when print attribute
descriptors:

< ACL Data TX: Handle 3585 flags 0x00 dlen 9
      ATT: Write Request (0x12) len 4
        Handle: 0x002c Type: Client Characteristic Configuration (0x2902)
        Value Handle: 0x002b Type: Battery Level (0x2a19)
          Data: 0100
            Notification (0x01)

7 months agoshared/gatt-db: Make gatt_db_attribute_get_value public
Luiz Augusto von Dentz [Fri, 24 Mar 2023 23:38:53 +0000 (16:38 -0700)]
shared/gatt-db: Make gatt_db_attribute_get_value public

This makes gatt_db_attribute_get_value public so it can be used by the
likes of btmon.

7 months agoclient: Add samples init scripts
Luiz Augusto von Dentz [Wed, 22 Mar 2023 01:13:49 +0000 (18:13 -0700)]
client: Add samples init scripts

This adds sample init scripts that can be passed to bluetoothctl for
testing.

7 months agoshared/shell: Add support for -i/--init-script
Luiz Augusto von Dentz [Wed, 22 Mar 2023 01:13:48 +0000 (18:13 -0700)]
shared/shell: Add support for -i/--init-script

This adds support for -i/--init-script which can be used to provide a
file with commands to be initialized, the commands are then run in
sequence after completing:

client/bluetoothctl -i client/power-on-off.bt
Agent registered
Changing power on succeeded
[CHG] Controller A8:7E:EA:56:87:D5 Pairable: yes
[CHG] Controller 98:8D:46:EE:6D:16 Pairable: yes
[CHG] Controller 98:8D:46:EE:6D:16 PowerState: on-disabling
AdvertisementMonitor path registered

7 months agobap: Fix not continue selecting if endpoint respond with an error
Luiz Augusto von Dentz [Fri, 17 Mar 2023 16:14:18 +0000 (09:14 -0700)]
bap: Fix not continue selecting if endpoint respond with an error

If the endpoint respond with an error we shall decrement selecting
counter and proceed to check if there is any stream that can be
configured.

7 months agomonitor: Fix printing Signed Write Command
Simon Mikuda [Thu, 23 Mar 2023 10:28:58 +0000 (11:28 +0100)]
monitor: Fix printing Signed Write Command

Data field were print twice (1 time incorrectly):
> ACL Data RX: Handle 64 flags 0x02 dlen 19
      ATT: Signed Write Command (0xd2) len 14
        Handle: 0x006f Type: Vendor specific (f7debc9a-7856-3412-7856-341278563412)
          Data: 0800000087f303c224516133
          Data:
          Signature: 0800000087f303c224516133

7 months agomonitor: Fix crash when there is no write handler
Simon Mikuda [Thu, 23 Mar 2023 10:28:57 +0000 (11:28 +0100)]
monitor: Fix crash when there is no write handler

7 months agoobexd: reject to accept file when replying reject message
Aaron_shen [Wed, 15 Mar 2023 10:04:35 +0000 (18:04 +0800)]
obexd: reject to accept file when replying reject message

It will accept file when obex agent replied any message
event though the message is org.bluez.obex.Error.Rejected.
The patch helps to reject a Bluetooth object push request if
user replied "org.bluez.obex.Error.Rejected" message according
to the doc/obex-agent-api.txt.

7 months agoaudio/transport: Propagate errors from avrcp_set_volume to DBus
Marijn Suijten [Sat, 11 Mar 2023 01:12:02 +0000 (02:12 +0100)]
audio/transport: Propagate errors from avrcp_set_volume to DBus

Any error while setting absolute volume on the peer, or notifying the
peer of changes was previously going completely unnoticed.  Propagate it
to the logs and back to the DBus "Volume" property setter so that they
aren't misled into thinking that the AVRCP command succeeded.

Note that an error is mostly harmless when the setter of the property is
an audio sink and the peer the audio source: in this case we're only
_notifying_ the peer of the change when it has already been applied on
the sink.

Also improve the other two error messages to more closely describe what
was "invalid" about the argument.

7 months agomesh: On exit free timer for filtering duplicates
Inga Stotland [Mon, 20 Mar 2023 05:06:18 +0000 (22:06 -0700)]
mesh: On exit free timer for filtering duplicates

This frees resources associated with duplicate filter timer
when destroying management IO.

7 months agotools/mesh-cfgclient: Auto request own composition data
Inga Stotland [Thu, 16 Mar 2023 21:33:12 +0000 (14:33 -0700)]
tools/mesh-cfgclient: Auto request own composition data

When attaching a local provisioner node, always request own
composition data to accommodate functional consolidation of
regular and remote provisioning mechanisms.
The knowledge of the own node composition is necessary for
provisioning initiation and self configuration.

7 months agotools/mesh-cfgclient: Prevent storing duplicate models
Inga Stotland [Thu, 16 Mar 2023 21:33:11 +0000 (14:33 -0700)]
tools/mesh-cfgclient: Prevent storing duplicate models

This fixes the situation when subsequent requests to get a node
composition result in appending element's model list with duplicate models.
This adds a check for a presence of a model on an element when attempting
to add a new model ID to a model list on this element.

7 months agodoc: describe new ISO Transport properties
Pauli Virtanen [Wed, 15 Mar 2023 22:16:39 +0000 (22:16 +0000)]
doc: describe new ISO Transport properties

Document the currently undocumented transport QoS properties.

7 months agotransport: add CIG/CIS/PHY properties, don't show unset QoS properties
Pauli Virtanen [Wed, 15 Mar 2023 22:16:38 +0000 (22:16 +0000)]
transport: add CIG/CIS/PHY properties, don't show unset QoS properties

Add CIG, CIS, and PHY properties to BAP transport.  The other QoS
properties are there, and these may also be useful to clients, e.g.  to
manage CIG/CIS allocation as client.

Hide transport QoS properties when they are not configured.

7 months agoshared/gatt-client: Fix not creating a request for notifications
Luiz Augusto von Dentz [Thu, 16 Mar 2023 19:32:58 +0000 (12:32 -0700)]
shared/gatt-client: Fix not creating a request for notifications

Notifications were using bt_att_send directly instead of
bt_gatt_client_write_value thus it wouldn't create a request which
causes the instance to not be able to track it which in turn may cause
the client to trigger its idle callback too early.

Fixes: https://github.com/bluez/bluez/issues/490

7 months agomesh: Don't send Prov Failed on non-existant links
Brian Gix [Wed, 15 Mar 2023 20:56:37 +0000 (13:56 -0700)]
mesh: Don't send Prov Failed on non-existant links

If remote device does not respond to a Prov Link Open request, then the
callbacks do not get established, and attempting to send Failure
messages on the non-existent link rersult in seg fault.

7 months agomesh: Make MGMT mesh-io less noisy
Brian Gix [Wed, 15 Mar 2023 17:24:52 +0000 (10:24 -0700)]
mesh: Make MGMT mesh-io less noisy

Remove excessive logging traffic

7 months agomesh: Filter originated Provisioning Data packets
Brian Gix [Wed, 15 Mar 2023 15:05:43 +0000 (08:05 -0700)]
mesh: Filter originated Provisioning Data packets

The mesh daemon can process incoming mesh packets on more than one
controller, but if a Provisioning data packet that originated from the
local daemon is received by a different controller, it must be filtered
and disregarded, or it will break the provisioning protocol.

7 months agomesh: Loopback unprovisioned beacons
Brian Gix [Thu, 9 Mar 2023 20:17:49 +0000 (12:17 -0800)]
mesh: Loopback unprovisioned beacons

Because the daemon explicitly supports multiple nodes, we need
local Config Clients to be able to see local unprovisioned devices.

This loops the unprovisioned beacon, so that local Provisioning servers
can see it.

Fixes Issue: https://github.com/bluez/bluez/issues/341

7 months agomesh: Fix uninitialized memory usage
Brian Gix [Mon, 13 Mar 2023 18:48:42 +0000 (11:48 -0700)]
mesh: Fix uninitialized memory usage

When attempting to cancel an unknown Scan request structure must be
NULL initialized.

7 months agoshared/gatt-client: Fix crash on bt_gatt_client_idle_unregister
Luiz Augusto von Dentz [Tue, 14 Mar 2023 19:23:25 +0000 (12:23 -0700)]
shared/gatt-client: Fix crash on bt_gatt_client_idle_unregister

This fixes the following crash:

Invalid read of size 8
   at 0x1E1E0B: bt_gatt_client_idle_unregister (gatt-client.c:3812)
   by 0x1EB6BD: bt_bap_detach (bap.c:3821)
   by 0x1EB6BD: bt_bap_detach (bap.c:3808)
   by 0x1D5631: queue_foreach (queue.c:207)
   by 0x1DCAA3: disconnect_cb (att.c:713)
   by 0x1F4404: watch_callback (io-glib.c:157)
   by 0x48BBC7E: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.7400.6)
   by 0x4912117: ??? (in /usr/lib64/libglib-2.0.so.0.7400.6)
   by 0x48BB24E: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.7400.6)
   by 0x1F4A54: mainloop_run (mainloop-glib.c:66)
   by 0x1F4E21: mainloop_run_with_signal (mainloop-notify.c:188)
   by 0x1304B4: main (main.c:1428)
 Address 0x28 is not stack'd, malloc'd or (recently) free'd

7 months agobtmon: Fix decoding truncated data
Łukasz Rymanowski [Sat, 11 Mar 2023 23:36:40 +0000 (00:36 +0100)]
btmon: Fix decoding truncated data

Some platforms use different filtering and for this purpose,
some of the ACL/SCO/ISO/SDP data is truncated.

In such a case, included length is smaller than the original size.
Without this fix, btmon stops working after first truncated packet.

7 months agoshared/bap: fix Locations, Context to be PACS not PAC properties
Pauli Virtanen [Tue, 14 Mar 2023 18:04:27 +0000 (18:04 +0000)]
shared/bap: fix Locations, Context to be PACS not PAC properties

Audio Locations and Contexts are properties of the PACS service, not of
individual PAC, as these are device-wide bitmaps and a single
characteristic may exist on PACS server (PACS v1.0 Sec 3).

Move the attributes out from bt_bap_pac to bt_bap_pacs, and actually
keep track of the values.

7 months agodevice: Fix crash attempting to read Sets property
Luiz Augusto von Dentz [Mon, 13 Mar 2023 18:31:21 +0000 (11:31 -0700)]
device: Fix crash attempting to read Sets property

The following set can be observed when a sirk is exists but it is
encrypted leading to info->set to not be set:

Invalid read of size 8
   at 0x1ACDF0: append_set (device.c:1662)
   by 0x1FFEFFF7DF: ???
   by 0x1D4461: queue_foreach (queue.c:207)
   by 0x1AC8DE: dev_property_get_set (device.c:1700)
   by 0x1CF3E2: append_property (object.c:498)
   by 0x1CFA91: append_properties (object.c:527)
   by 0x1CFAFD: append_interface (object.c:542)
   by 0x48D7CEF: g_slist_foreach (gslist.c:887)
   by 0x1CF5A7: append_interfaces (object.c:1104)
   by 0x1CF5A7: append_object (object.c:1119)
   by 0x48D7CEF: g_slist_foreach (gslist.c:887)
   by 0x1CF5D0: append_object (object.c:1122)
   by 0x48D7CEF: g_slist_foreach (gslist.c:887)
 Address 0x8 is not stack'd, malloc'd or (recently) free'd

7 months agoshared/csip: Fix crash on bt_csip_get_sirk
Luiz Augusto von Dentz [Mon, 13 Mar 2023 22:51:50 +0000 (15:51 -0700)]
shared/csip: Fix crash on bt_csip_get_sirk

This fixes the following trace:

Invalid read of size 1
   at 0x1F4282: bt_csip_get_sirk (csip.c:812)
   by 0x176B21: csip_ready (csip.c:259)
   by 0x1F3C74: csip_notify_ready (csip.c:578)
   by 0x1F3C74: csip_idle (csip.c:659)
   by 0x1DCDCC: idle_notify (gatt-client.c:171)
   by 0x1D579A: queue_remove_if (queue.c:279)
   by 0x1D584F: queue_remove_all (queue.c:321)
   by 0x1E036F: notify_client_idle (gatt-client.c:180)
   by 0x1E036F: request_unref (gatt-client.c:199)
   by 0x1DC60D: destroy_att_send_op (att.c:211)
   by 0x1DC60D: handle_rsp (att.c:874)
   by 0x1DC60D: can_read_data (att.c:1064)
   by 0x1F43F4: watch_callback (io-glib.c:157)
   by 0x48BBC7E: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.7400.6)
   by 0x4912117: ??? (in /usr/lib64/libglib-2.0.so.0.7400.6)
   by 0x48BB24E: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.7400.6)
 Address 0x0 is not stack'd, malloc'd or (recently) free'd

7 months agoshared/gatt-client: Introduce bt_gatt_client_ref_safe
Luiz Augusto von Dentz [Mon, 13 Mar 2023 22:51:49 +0000 (15:51 -0700)]
shared/gatt-client: Introduce bt_gatt_client_ref_safe

This introduces bt_gatt_client_ref_save which ensures the instaces
which are being destroyed, e.g. ref_count = 0, do not attempt to reach
callbacks.

7 months agoshared/csip: Fix not unregistering idle callback on detach
Luiz Augusto von Dentz [Mon, 13 Mar 2023 22:51:48 +0000 (15:51 -0700)]
shared/csip: Fix not unregistering idle callback on detach

This make sure idle callback is unregistered before bt_gatt_client is
unref.

7 months agoshared/bap: Fix not unregistering idle callback on detach
Luiz Augusto von Dentz [Mon, 13 Mar 2023 22:51:47 +0000 (15:51 -0700)]
shared/bap: Fix not unregistering idle callback on detach

This make sure idle callback is unregistered before bt_gatt_client is
unref.

7 months agomesh: Fix node when loading from storage
Inga Stotland [Fri, 10 Mar 2023 01:35:12 +0000 (17:35 -0800)]
mesh: Fix node when loading from storage

This fixes adding mandatory models (config server, remote provisioner)
to a node whose configuration is being loaded from storage:
mesh_model_add() was called with a wrong argument.

Was:     mesh_model_add(..., PRIMARY_ELE_IDX, ...);
Correct: mesh_model_add(..., ele->models, ...);

7 months agoclient: Use AdvertisingFlags when available
Luiz Augusto von Dentz [Tue, 7 Mar 2023 00:48:43 +0000 (16:48 -0800)]
client: Use AdvertisingFlags when available

This prints devices not discoverable in grey so the user are able to
distict when for example set members are actually visible.

7 months agoclient: Add support for DeviceSet proxy
Luiz Augusto von Dentz [Fri, 3 Mar 2023 22:07:14 +0000 (14:07 -0800)]
client: Add support for DeviceSet proxy

7 months agotools: Add support to generate RSI using SIRK
Sathish Narasimman [Tue, 22 Nov 2022 10:12:32 +0000 (15:42 +0530)]
tools: Add support to generate RSI using SIRK

The patch helps to generate Resolvable set identifier adv data.
which can be used as ADV data during advertisement.
It will be used to identify the device as part of setmember for
Coordinated set identification profile.
Example:
$<path to advtest/>advtest -i "761FAE703ED681F0C50B34155B6434FB"
SIRK: 761FAE703ED681F0C50B34155B6434FB
  RSI:  0x71 0xcb 0xbc 0x7e 0x01 0x84
    Random: bccb71
    Hash:   84017e

7 months agoprofiles: Add initial code for csip plugin
Sathish Narasimman [Tue, 22 Nov 2022 10:12:30 +0000 (15:42 +0530)]
profiles: Add initial code for csip plugin

This adds initial code for csip plugin which handles Coordinated
set identification Profile and Coordinated Set Identification
Service.

7 months agoshared/csip: Add initial code for handling CSIP
Sathish Narasimman [Tue, 22 Nov 2022 10:12:29 +0000 (15:42 +0530)]
shared/csip: Add initial code for handling CSIP

This adds initial code for Coordinated Set Identification Profile.

7 months agomain.conf: Add CSIP profile configurable options
Sathish Narasimman [Tue, 22 Nov 2022 10:12:28 +0000 (15:42 +0530)]
main.conf: Add CSIP profile configurable options

This introduces option to configure main.conf that can be used to
configure co-ordinated set identification profile.

7 months agocore: Check if device has RSI
Luiz Augusto von Dentz [Wed, 22 Feb 2023 22:06:05 +0000 (14:06 -0800)]
core: Check if device has RSI

This checks if device is advertising an RSI and if so disregards if it
is not discoverable since other members can be.

7 months agocore: Add initial implementation of DeviceSet interface
Luiz Augusto von Dentz [Fri, 3 Mar 2023 01:10:07 +0000 (17:10 -0800)]
core: Add initial implementation of DeviceSet interface

This adds the initial implementation of DeviceSet interface as
documented in doc/set-api.rst.

7 months agodevice-api: Add Set property
Luiz Augusto von Dentz [Sat, 4 Mar 2023 00:04:26 +0000 (16:04 -0800)]
device-api: Add Set property

This adds Set property so clients are able to identify when a device
belongs to a set.

7 months agodoc: Add set-api
Luiz Augusto von Dentz [Fri, 3 Mar 2023 01:03:26 +0000 (17:03 -0800)]
doc: Add set-api

This adds set-api.rst which documents DeviceSet interface.

7 months agoshared/ad: Add RSI data type
Luiz Augusto von Dentz [Thu, 2 Mar 2023 22:16:07 +0000 (14:16 -0800)]
shared/ad: Add RSI data type

This adds BT_AD_CSIP_RSI advertising data type.

7 months agoshared/crypto: Add bt_crypto_sirk
Luiz Augusto von Dentz [Thu, 2 Mar 2023 21:47:44 +0000 (13:47 -0800)]
shared/crypto: Add bt_crypto_sirk

This adds bt_crypto_sirk which attempts to generate a unique SIRK using
the following steps:

 - Generate a hash (k) using the str as input
 - Generate a hash (sirk) using vendor, product, version and source as input
 - Encrypt sirk using k as LTK with sef function.

7 months agoclient/player: Update High Reliability presets
Luiz Augusto von Dentz [Fri, 10 Mar 2023 21:18:45 +0000 (13:18 -0800)]
client/player: Update High Reliability presets

This updates High Reliability presets as published in BAP 1.0.1:

https://www.bluetooth.com/specifications/bap-1-0-1/

7 months agoiso-tester: Update High Reliability presets
Luiz Augusto von Dentz [Fri, 10 Mar 2023 21:17:22 +0000 (13:17 -0800)]
iso-tester: Update High Reliability presets

This updates High Reliability presets as published in BAP 1.0.1:

https://www.bluetooth.com/specifications/bap-1-0-1/

7 months agol2cap-tester: Add server tests for Ext-Flowctl
Luiz Augusto von Dentz [Wed, 8 Mar 2023 23:30:46 +0000 (15:30 -0800)]
l2cap-tester: Add server tests for Ext-Flowctl

This adds the following tests:

L2CAP Ext-Flowctl Server - Success
L2CAP Ext-Flowctl Server - Nval SCID
L2CAP LE EATT Client - Success
L2CAP LE EATT Server - Success
L2CAP LE EATT Server - Reject

7 months agogatt: Use DEFER_SETUP for EATT channels
Luiz Augusto von Dentz [Thu, 9 Mar 2023 22:20:17 +0000 (14:20 -0800)]
gatt: Use DEFER_SETUP for EATT channels

This makes use of DEFER_SETUP mechanism to do the following checks
before accepting the connection:

 - Checks a valid device object exits
 - Checks if initiator/central as if the peripheral start connecting it
   may cause collisions.
 - Checks if the limit of allowed connections has been reached.

7 months agomain: Disable EATT by default
Luiz Augusto von Dentz [Thu, 9 Mar 2023 18:51:46 +0000 (10:51 -0800)]
main: Disable EATT by default

EATT is causing some problem with some platforms as they also attempt to
configure it may cause a connection collision which needs to be handled
by the kernel.

7 months agogatt: Fix creating duplicated objects
Luiz Augusto von Dentz [Wed, 8 Mar 2023 00:49:38 +0000 (16:49 -0800)]
gatt: Fix creating duplicated objects

This checks cid before attempting to create device, if the device is
using an RPA it could be that the MGMT event has not been processed yet
which would lead to create a second copy of the same device using its
identity address.

7 months agodevice: Fix not always storing device info
Luiz Augusto von Dentz [Wed, 8 Mar 2023 00:47:33 +0000 (16:47 -0800)]
device: Fix not always storing device info

When updating the device address check if the device is marked as
temporary before attempting to call store_device_info otherwise it will
have no effect and instead btd_device_set_temporary must be called.

7 months agoshared/att: Always queue BT_ATT_OP_MTU_REQ on the fixed channel
Luiz Augusto von Dentz [Tue, 7 Mar 2023 21:00:22 +0000 (13:00 -0800)]
shared/att: Always queue BT_ATT_OP_MTU_REQ on the fixed channel

BT_ATT_OP_MTU_REQ shall only be sent on the so called fixed channel
since EATT channels shall use L2CAP procedure to update its MTU.

7 months agobap: Fix crash on unexpected disconnect
Luiz Augusto von Dentz [Thu, 2 Mar 2023 19:56:36 +0000 (11:56 -0800)]
bap: Fix crash on unexpected disconnect

If an unexpected disconnect happens while bt_bap_config is pending the
following trace can be observed, to fix it bt_bap_config is reworked so
it no longer attempts to create and config the stream in place, instead
it just return the new stream and the function is renamed to
bt_bap_stream_new:

Invalid write of size 4
   at 0x3980D8: config_cb (bap.c:395)
   by 0x4DF5A3: bap_req_complete (bap.c:3471)
   by 0x4E9D33: bap_req_detach (bap.c:3807)
   by 0x4E9D33: bt_bap_detach (bap.c:3819)
   by 0x4E9D33: bt_bap_detach (bap.c:3810)
   by 0x397AA9: bap_disconnect (bap.c:1342)
   by 0x4223E0: btd_service_disconnect (service.c:305)
   by 0x4974D8F: g_slist_foreach (in /usr/lib64/libglib-2.0.so.0.7200.3)
   by 0x438FC3: att_disconnected_cb (device.c:5160)
   by 0x49A6C6: queue_foreach (queue.c:207)
   by 0x4B463B: disconnect_cb (att.c:701)
   by 0x5054DF: watch_callback (io-glib.c:157)
   by 0x495BFAE: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.7200.3)
   by 0x49B12C7: ??? (in /usr/lib64/libglib-2.0.so.0.7200.3)
 Address 0x6576940 is 96 bytes inside a block of size 112 free'd
   at 0x48480E4: free (vg_replace_malloc.c:872)
   by 0x48F78D: remove_interface (object.c:660)
   by 0x490489: g_dbus_unregister_interface (object.c:1394)
   by 0x397BA8: ep_remove (bap.c:1330)
   by 0x49ACF4: queue_remove_if (queue.c:279)
   by 0x49B0AC: queue_remove_all (queue.c:321)
   by 0x397A7C: bap_disconnect (bap.c:1339)
   by 0x4223E0: btd_service_disconnect (service.c:305)
   by 0x4974D8F: g_slist_foreach (in /usr/lib64/libglib-2.0.so.0.7200.3)
   by 0x438FC3: att_disconnected_cb (device.c:5160)
   by 0x49A6C6: queue_foreach (queue.c:207)
   by 0x4B463B: disconnect_cb (att.c:701)
 Block was alloc'd at
   at 0x484586F: malloc (vg_replace_malloc.c:381)
   by 0x49B432: util_malloc (util.c:43)
   by 0x39A1D9: ep_register (bap.c:563)
   by 0x39A1D9: pac_found (bap.c:664)
   by 0x4E5FEA: bap_foreach_pac (bap.c:3980)
   by 0x4EA437: bap_notify_ready (bap.c:2736)
   by 0x4EA437: bap_idle (bap.c:3711)
   by 0x4B52F0: idle_notify (gatt-client.c:171)
   by 0x49ACF4: queue_remove_if (queue.c:279)
   by 0x49B0AC: queue_remove_all (queue.c:321)
   by 0x4C092C: notify_client_idle (gatt-client.c:180)
   by 0x4C092C: request_unref (gatt-client.c:199)
   by 0x4AACB5: destroy_att_send_op (att.c:209)
   by 0x4B2B88: handle_rsp (att.c:862)
   by 0x4B2B88: can_read_data (att.c:1052)
   by 0x5054DF: watch_callback (io-glib.c:157)