Commit Graph

637 Commits

Author SHA1 Message Date
Bastien Nocera
0b52ecca60 sdp: Fix mismatched int casting 2024-07-08 10:19:20 -04:00
Bastien Nocera
0de4b9f71e sdp: Fix possible null dereference
From the BlueZ scanbot:
lib/sdp.c:586:12: warning: Access to field 'attrId' results in a dereference of a null pointer (loaded from variable 'd')
        d->attrId = attr;
        ~         ^
lib/sdp.c:967:10: warning: Access to field 'dtd' results in a dereference of a null pointer (loaded from variable 'd')
        switch (d->dtd) {
                ^~~~~~
2024-07-08 10:18:17 -04:00
Bastien Nocera
1707a83622 sdp: Check memory allocation in sdp_copy_seq()
Fix a potential null-dereference if sdp_data_alloc_with_length() fails,
as is done in other similar functions.
2024-07-03 10:37:52 -04:00
Bastien Nocera
5dcc52a486 sdp: Fix memory leak in sdp_data_alloc*()
Make sure to free already allocated memory if we run out of memory
before the end of the loop.

Error: RESOURCE_LEAK (CWE-772): [#def8] [important]
lib/sdp.c:542:4: alloc_fn: Storage is returned from allocation function "sdp_data_alloc".
lib/sdp.c:542:4: var_assign: Assigning: "data" = storage returned from "sdp_data_alloc(dtd, values[i])".
lib/sdp.c:550:4: var_assign: Assigning: "seq" = "data".
lib/sdp.c:552:3: var_assign: Assigning: "curr" = "data".
lib/sdp.c:553:2: out_of_scope: Variable "data" goes out of scope.
lib/sdp.c:552:3: overwrite_var: Overwriting "curr" in "curr = data".
lib/sdp.c:545:4: leaked_storage: Variable "seq" going out of scope leaks the storage it points to.
543|
544|		if (!data)
545|->			return NULL;
546|
547|		if (curr)
2024-07-03 10:37:38 -04:00
Arun Raghavan
8e4bece63c src/shared: Add initial implementation for an ASHA profile
This implements the server role for the Audio Streaming for Hearing Aid
specification[1]. Includes basic ability to probe the ASHA GATT service,
as well as starting/stopping streaming.

[1] https://source.android.com/docs/core/connect/bluetooth/asha

Resolves: https://github.com/bluez/bluez/issues/481
2024-06-13 11:51:28 -04:00
Bastien Nocera
bd954700e6 sdp: Fix ineffective error guard
The return value from gen_attridseq_pdu() can be -ENOMEM or the always
positive return value from sdp_gen_pdu(), but we only guard against a
single negative return value "-1" (-EPERM).

Check for all negative values to avoid manipulating a negative length as
a valid one.

Error: INTEGER_OVERFLOW (CWE-190): [#def10] [important]
lib/sdp.c:4097:2: overflow_sink:
"t->reqsize + cstate_len", which might have underflowed, is passed to
"sdp_send_req(session, t->reqbuf, t->reqsize + cstate_len)".
4095|		reqhdr->plen = htons((t->reqsize + cstate_len) - sizeof(sdp_pdu_hdr_t));
4096|
4097|->		if (sdp_send_req(session, t->reqbuf, t->reqsize + cstate_len) < 0) {
4098|			SDPERR("Error sending data:%m");
4099|			t->err = errno;

Error: INTEGER_OVERFLOW (CWE-190): [#def11] [important]
lib/sdp.c:4492:3: overflow_sink:
"reqsize", which might have underflowed, is passed to
"sdp_send_req_w4_rsp(session, reqbuf, rspbuf, reqsize, &rspsize)".
4490|			reqhdr->plen = htons(reqsize - sizeof(sdp_pdu_hdr_t));
4491|			rsphdr = (sdp_pdu_hdr_t *) rspbuf;
4492|->			status = sdp_send_req_w4_rsp(session, reqbuf, rspbuf, reqsize, &rspsize);
4493|			if (rspsize < sizeof(sdp_pdu_hdr_t)) {
4494|				SDPERR("Unexpected end of packet");
2024-06-03 15:06:36 -04:00
Bastien Nocera
dc60ce0b46 sdp: Fix use of uninitialised memory
Error: UNINIT (CWE-457): [#def10] [important]
lib/sdp.c:2302:2: alloc_fn: Calling "malloc" which returns uninitialized memory.
lib/sdp.c:2302:2: assign: Assigning: "seqDTDs" = "malloc(seqlen * 8UL)", which points to uninitialized data.
lib/sdp.c:2355:2: uninit_use_in_call: Using uninitialized value "*seqDTDs" when calling "sdp_seq_alloc".
2353|			}
2354|		}
2355|->		seq = sdp_seq_alloc(seqDTDs, seqs, seqlen);
2356|		free(seqDTDs);
2357|		free(seqs);
2024-05-10 11:29:09 -04:00
Pauli Virtanen
138e97020d lib: add BT_POLL_ERRQUEUE socket option
Add new (experimental) socket option.
2024-04-10 12:31:46 -04:00
Pauli Virtanen
b3bfe2110b lib: add BT_SCM_ERROR
Add new CMSG type used in new kernel TX timestamping support.
2024-04-04 14:46:32 -04:00
Luiz Augusto von Dentz
aa7a814690 bluetooth: Add BT_ISO_SYNC_TIMEOUT
This defines BT_ISO_SYNC_TIMEOUT(20 sec) which shall be considered the
default sync_timeout and make all instance previously hardcoding a
value to use it.
2024-03-08 11:11:49 -05:00
Ajay KV
93d88ecd07 lib/uuid: Add support to compare 16bit uuids 2024-02-13 15:41:06 -05:00
Ajay KV
24d97e35fc lib/uuid: Add GTBS UUIDs for Call Control Profile 2024-02-13 15:27:29 -05:00
Emil Velikov
c8b518daa9 lib: const annotate tupla instances and API 2024-01-19 15:46:12 -05:00
Emil Velikov
af552cd906 lib: const annotate hci_map instances and related API 2024-01-19 15:45:07 -05:00
Mahesh Talewad
c89ebba80f uuid: Add AICS UUIDs
This adds AISCS related UUIDs.
2023-12-18 15:37:52 -05:00
Jonas Dreßler
b978f97967 lib/sdp: Pass size_t to sdp_get_string_attr()
We're currently type-casting the output of strlen(sdpdata->val.str) into
an int, which is somewhat problematic given that strlen() can return
values larger than sizeof(int).

We can do better here and use size_t instead, so let's do that.

While at it, also add a comment explaining why the check here is "smaller
than" instead of "smaller than or equal".

Co-developed-by: Zander Brown <zbrown@gnome.org>
2023-11-13 13:57:03 -05:00
Jonas Dreßler
5afa25c95e lib/sdp: Use correct string length in sdp_copy_seq()
sdp_data_t->unitSize for strings in the SDP record is
`sizeof(uint8_t) + strlen(str)`.

The "length" argument of sdp_data_alloc_with_length() is expected to be
only the length of the string (so `sdp_data_t->unitSize - sizeof(uint8_t)`).

Since the last commit, in sdp_copy_seq() we're allocating one byte too much
for strings now, because the `sizeof(uint8_t)` is not subtracted from unitSize
there.

Fix this by making use of the length returned by sdp_data_value() and pass
that on to sdp_data_alloc_with_length().

Co-developed-by: Zander Brown <zbrown@gnome.org>
2023-11-13 13:29:56 -05:00
Jonas Dreßler
cfcc6346a9 lib/sdp: Don't assume uint8_t has size 1
Assuming the size of of uint8_t is bad practice, we use
sizeof(uint8_t) everywhere else and the use of sizeof makes it clear
we're accounting for the descriptor here rather than just randomly
subtracting 1, so change that.

Co-developed-by: Zander Brown <zbrown@gnome.org>
2023-11-13 13:29:55 -05:00
Jonas Dreßler
fdb5ba2cbf lib/sdp: Allocate strings in sdp_data_t with NULL termination
In extract_str() we create sdp_data_t with strings and allocate
sdp_data_t->val.str an extra 0-byte as NULL termination. In
sdp_data_alloc_with_length() we're missing this, and strlen() in
sdp_get_string_attr() ends up overrunning the sdpdata->val.str buffer
looking for the NULL termination.

Allocate the extra 0-byte for sdp_data_t->val.str to ensure this
overrun can't happen.

Co-developed-by: Zander Brown <zbrown@gnome.org>
2023-11-13 13:29:54 -05:00
Marcel Holtmann
5f0297f131 lib: Add Bluetooth 5.3 and Bluetooth 5.4 into the version table 2023-10-04 08:08:33 +02:00
Luiz Augusto von Dentz
771b19e196 transport: Implement QoS property
This implements Transport.QoS as a dict instead of listing each field as
a individual property.
2023-09-28 17:25:43 -07:00
Nitin Jadhav
94ea14917f lib/uuid.h: Add UUID(s)
Add MICS characteristic uuid(s)
2023-09-05 10:58:42 -07:00
Silviu Florian Barbulescu
1dbd9ba1f1 Rename BAA_SERVICE to BCAA_SERVICE add BAA_SERVICE(0x1851)
Rename BAA_SERVICE to BCAA_SERVICE and added BAA_SERVICE(0x1851)
as UUID for the broadcast sink.
2023-07-31 10:33:25 -07:00
Claudia Draghicescu
f9557931ad monitor: Add decoding support for Sync Receiver events
This commit adds decoding support for PA Sync Established,
BIG Sync Established and BIG Sync Lost events.
2023-07-05 10:48:31 -07:00
Luiz Augusto von Dentz
c8235156c3 adapter: Handle Device Found Event with Scan Response flag
This handles recently introduced Scan Response flag since that
shouldn't affect connectable flag the device would be considered
connectable but it shall not create a new device by itself.
2023-06-20 13:37:53 -07:00
Nitin Jadhav
0735ca179f lib/uuid.h: Add VOCS characteristic uuid(s) 2023-06-13 13:32:22 -07:00
Silviu Florian Barbulescu
07c6d9b110 lib: Add macro definitions for BAP broadcast source support
This adds macro definitions for BAP broadcast source support.
2023-05-26 15:20:44 -07:00
Iulia Tanasescu
4e549cf48b lib/uuid: Add BASS UUIDs
This adds BASS UUIDs which will be used by Basic Audio Profile.
2023-05-05 10:55:02 -07:00
Iulia Tanasescu
c4d9b99db5 Split bt_iso_qos into dedicated structures
Split bt_iso_qos into dedicated unicast and broadcast
structures and add additional broadcast parameters.
2023-03-31 14:33:28 -07:00
Simon Mikuda
54601cbcf2 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.
2023-03-28 13:49:35 -07:00
Luiz Augusto von Dentz
5d63ee2a58 mgmt: Use BIT macro when defining bitfields
This makes use of BIT macro when defining bitfields which makes it
clearer what bit it is toggling.
2023-02-13 18:15:31 -08:00
Pauli Virtanen
c35d32b199 lib: Add defines for MGMT setting bits for CIS feature support 2023-02-13 12:56:00 -08:00
Sathish Narasimman
b709058c60 lib/uuid: Add CSIS UUIDs
This adds Coordinated Set Identification Service UUIDs which will
be used by Coordinated Set Identification Profile.
2022-12-20 15:14:00 -08:00
Abhay Maheta
d3a204b8a2 lib/uuid: Add GMCS UUIDs
This adds GMCS UUIDs which will be used by Media Control Profile.
2022-10-18 12:52:16 -07:00
Brian Gix
721d5a8ae8 lib: Add defines of new MGMT opcodes and events
Populated new opcodes and events into static mgmt_ev and mgmt_op string
arrays.
2022-09-22 14:09:09 -07:00
Sathish Narasimman
af1bfbb470 lib/uuid: Add VCS UUIDs
This adds Volume Control Service UUIDs which will be used by
Volume Control Profile.
2022-09-15 14:11:36 -07:00
Brian Gix
4f452c7753 lib: Add mgmt opcodes and events for Mesh 2022-09-01 11:52:06 -07:00
Luiz Augusto von Dentz
d7b78586af lib/uuid: Add PACS/ASCS UUIDs
This adds PACS/ASCS UUIDs which will be used by Basic Audio Profile.
2022-08-29 12:41:50 -07:00
Luiz Augusto von Dentz
b031e4dc8c lib: Add definitions for ISO socket 2022-07-22 13:31:42 -07:00
Luiz Augusto von Dentz
0da5c68413 advertising: Fix attempting to set scan_rsp
BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E page 2450

  • If extended advertising PDU types are being used (bit 4 = 0) then:
  The advertisement shall not be both connectable and scannable.

So instead this attempts to set name as part of Advertising Data rather
then setting it as Scan Response:

bluetoothctl> advertise.secondary 2M
bluetoothctl> advertise.name Intel-3
bluetoothctl> advertise on

< HCI Command: LE Set Extended Advertising Parameters (0x08|0x0036) plen 25
        Handle: 0x01
        Properties: 0x0001
          Connectable
        Min advertising interval: 1280.000 msec (0x0800)
        Max advertising interval: 1280.000 msec (0x0800)
        Channel map: 37, 38, 39 (0x07)
        Own address type: Public (0x00)
        Peer address type: Public (0x00)
        Peer address: 00:00:00:00:00:00 (OUI 00-00-00)
        Filter policy: Allow Scan Request from Any, Allow Connect Request from Any (0x00)
        TX power: Host has no preference (0x7f)
        Primary PHY: LE 1M (0x01)
        Secondary max skip: 0x00
        Secondary PHY: LE 2M (0x02)
        SID: 0x00
        Scan request notifications: Disabled (0x00)
> HCI Event: Command Complete (0x0e) plen 5
      LE Set Extended Advertising Parameters (0x08|0x0036) ncmd 1
        Status: Success (0x00)
        TX power (selected): 7 dbm (0x07)
< HCI Command: LE Set Extended Advertising Data (0x08|0x0037) plen 4
        Handle: 0x01
        Operation: Complete extended advertising data (0x03)
        Fragment preference: Minimize fragmentation (0x01)
        Data length: 0x00
@ MGMT Event: Command Complete (0x0001) plen 7
      Add Extended Advertising Parameters (0x0054) plen 4
        Status: Success (0x00)
        Instance: 1
        TX power: 7 dbm (0x07)
        Available adv data len: 31
        Available scan rsp data len: 31
> HCI Event: Command Complete (0x0e) plen 4
      LE Set Extended Advertising Data (0x08|0x0037) ncmd 1
        Status: Success (0x00)
@ MGMT Command: Add Extended Advertising Data (0x0055) plen 23
        Instance: 1
        Advertising data length: 12
        Name (complete): Intel-3
        Flags: 0x06
          LE General Discoverable Mode
          BR/EDR Not Supported
        Scan response length: 0
< HCI Command: LE Set Extended Advertising Data (0x08|0x0037) plen 16
        Handle: 0x01
        Operation: Complete extended advertising data (0x03)
        Fragment preference: Minimize fragmentation (0x01)
        Data length: 0x0c
        Name (complete): Intel-3
        Flags: 0x06
          LE General Discoverable Mode
          BR/EDR Not Supported
> HCI Event: Command Complete (0x0e) plen 4
      LE Set Extended Advertising Data (0x08|0x0037) ncmd 1
        Status: Success (0x00)
< HCI Command: LE Set Extended Scan Response Data (0x08|0x0038) plen 4
        Handle: 0x01
        Operation: Complete scan response data (0x03)
        Fragment preference: Minimize fragmentation (0x01)
        Data length: 0x00
> HCI Event: Command Complete (0x0e) plen 4
      LE Set Extended Scan Response Data (0x08|0x0038) ncmd 1
        Status: Success (0x00)
< HCI Command: LE Set Extended Advertising Enable (0x08|0x0039) plen 6
        Extended advertising: Enabled (0x01)
        Number of sets: 1 (0x01)
        Entry 0
          Handle: 0x01
          Duration: 0 ms (0x00)
          Max ext adv events: 0
> HCI Event: Command Complete (0x0e) plen 4
      LE Set Extended Advertising Enable (0x08|0x0039) ncmd 2
        Status: Success (0x00)
@ MGMT Event: Command Complete (0x0001) plen 4
      Add Extended Advertising Data (0x0055) plen 1
        Status: Success (0x00)
        Instance: 1
2022-06-14 13:29:09 -07:00
Luiz Augusto von Dentz
ba32b25a61 monitor/att: Add decoding support for ASE Sink/Source
This adds decoding support for ASE Sink/Source attributes:

> ACL Data RX: Handle 42 flags 0x02 dlen 9
      Channel: 65 len 5 sdu 3 [PSM 39 mode Enhanced Credit (0x81)] {chan 0}
      ATT: Read Request (0x0a) len 2
        Handle: 0x002a Type: Sink ASE (0x2bc4)
< ACL Data TX: Handle 42 flags 0x00 dlen 9
      Channel: 64 len 5 sdu 3 [PSM 39 mode Enhanced Credit (0x81)] {chan 0}
      ATT: Read Response (0x0b) len 2
        Value: 0300
            ASE ID: 1
            State: Idle (0x00)
< ACL Data TX: Handle 42 flags 0x00 dlen 55
      Channel: 64 len 51 sdu 49 [PSM 39 mode Enhanced Credit (0x81)] {chan 0}
      ATT: Handle Multiple Value Notification (0x23) len 48
        Length: 0x0023
        Handle: 0x0024 Type: Sink ASE (0x2bc4)
          Data: 01010000000a00204e00409c00204e00409c0006000000000a02010302020103042800
            ASE ID: 1
            State: Codec Configured (0x01)
            Framing: Unframed PDUs supported (0x00)
            PHY: 0x00
            RTN: 0
            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: LC3 (0x06)
            Codec Specific Configuration #0: len 0x02 type 0x01
            Codec Specific Configuration: 03
            Codec Specific Configuration #1: len 0x02 type 0x02
            Codec Specific Configuration: 01
            Codec Specific Configuration #2: len 0x03 type 0x04
            Codec Specific Configuration: 2800
< ACL Data TX: Handle 42 flags 0x00 dlen 37
      Channel: 64 len 33 sdu 31 [PSM 39 mode Enhanced Credit (0x81)] {chan 0}
      ATT: Handle Multiple Value Notification (0x23) len 30
        Length: 0x0011
        Handle: 0x0024 Type: Sink ASE (0x2bc4)
          Data: 0102000010270000022800020a00409c00
            ASE ID: 1
            State: QoS Configured (0x02)
            CIG ID: 0x00
            CIS ID: 0x00
            SDU Interval: 10000 usec
            Framing: Unframed (0x00)
            PHY: 0x02
            LE 2M PHY (0x02)
            Max SDU: 40
            RTN: 2
            Max Transport Latency: 10
            Presentation Delay: 40000 us
< ACL Data TX: Handle 42 flags 0x00 dlen 33
      Channel: 64 len 29 sdu 27 [PSM 39 mode Enhanced Credit (0x81)] {chan 0}
      ATT: Handle Multiple Value Notification (0x23) len 26
        Length: 0x000d
        Handle: 0x002a Type: Source ASE (0x2bc5)
          Data: 03030000060304030202000000
            ASE ID: 3
            State: Enabling (0x03)
            CIG ID: 0x00
            CIS ID: 0x00
            Metadata #0: len 0x03 type 0x04
            Metadata: 0302
            Metadata #1: len 0x02 type 0x00
< ACL Data TX: Handle 42 flags 0x00 dlen 39
      Channel: 64 len 35 sdu 33 [PSM 39 mode Enhanced Credit (0x81)] {chan 0}
      ATT: Handle Multiple Value Notification (0x23) len 32
        Length: 0x000d
        Handle: 0x002a Type: Source ASE (0x2bc5)
          Data: 03040000060304030202000000
            ASE ID: 3
            State: Streaming (0x04)
            CIG ID: 0x00
            CIS ID: 0x00
            Metadata #0: len 0x03 type 0x04
            Metadata: 0302
            Metadata #1: len 0x02 type 0x00
< ACL Data TX: Handle 42 flags 0x00 dlen 33
      Channel: 64 len 29 sdu 27 [PSM 39 mode Enhanced Credit (0x81)] {chan 0}
      ATT: Handle Multiple Value Notification (0x23) len 26
        Length: 0x000d
        Handle: 0x002a Type: Source ASE (0x2bc5)
          Data: 03050000060304030202000000
            ASE ID: 3
            State: Disabling (0x05)
            CIG ID: 0x00
            CIS ID: 0x00
            Metadata #0: len 0x03 type 0x04
            Metadata: 0302
            Metadata #1: len 0x02 type 0x00
2022-05-26 13:57:50 -07:00
Yun-Hao Chung
b5ff08b267 lib: fix hci_strtolm crash
|str| can be NULL in the case of reading lm value. Calling strcasestr
could lead to a crash.

Reviewed-by: Archie Pusaka <apusaka@chromium.org>
2022-02-15 13:31:42 -08:00
Luiz Augusto von Dentz
f3ddc74442 uuid: Fix crashing if a NULL string is passed to bt_string_to_uuid
bt_string_to_uuid shall chack if the string is valid before attempting
to access its contents.
2022-02-09 16:03:45 -08:00
Archie Pusaka
db31aecae0 mgmt: Add NAME_REQUEST_FAILED flag for device_found event
Report failure when resolving remote name to userspace. This is useful
so the userspace can make an informed decision when to retry name
resolving procedure.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
2021-11-29 09:43:41 -08:00
Manish Mandlik
37caf622b8 lib: Add definitions of the Adv Monitor Device Found/Lost events
This patch adds definitions of the new Advertisement Monitor Device
Found and Device Lost events to indicate that the controller has
started/stopped tracking a particular device.

Reviewed-by: Miao-chen Chou <mcchou@google.com>
2021-11-22 14:25:04 -08:00
Luiz Augusto von Dentz
37be50d679 adapter: Set Device Privacy Mode
This adds support for setting Device Privacy flag when enabled in
main.conf via Privacy = device,limited-device.
2021-11-09 14:45:51 -08:00
Luiz Augusto von Dentz
023492834d lib: Fix HCI_MAX_ACL_SIZE
HCI_MAX_ACL_SIZE actually includes the maximum frames in AMP controller
so this changes it to properly define the max ACL frames on non-AMP
controllers and introduces a dedicated define for AMP controller as
HCI_MAX_AMP_SIZE.
2021-09-22 14:32:38 -07: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
Peter A. Bigot
86e7b3e768 lib: Fix variable-length array declarations in hci structures
Use of zero as the size for arrays as the last element of a structure
is a GNU C extension, which as of GCC 10 produces diagnostics when
values in the extended array are referenced.  Switch to the C99
standard idiom for flexible array members, already in use in a few
other headers.
2021-09-17 12:55:23 -07:00
Kiran K
984e364d57 tools/sco-tester: add test cases to get offload codecs
Add a test case to query offload codecs supported over sco
2021-09-07 15:06:54 -07:00