Commit graph

8508 commits

Author SHA1 Message Date
Jonathan Rico
792ae68165 Bluetooth: host: Use correct user_data size for hci_rx_pool
`struct acl_data` is used even when Host flow control is not enabled.
It is written to through the `acl(buf)` accessor in `conn.c:hci_acl()`.

Hopefully no netbufs were harmed by that :/

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-07-13 10:25:31 -04:00
Emil Gydesen
1751a7f190 Bluetooth: TBS: Add missing documentation in tbs.h
Add missing documentation for some defintions in tbs.h
Moved some internal definitions to tbs_internal.h

Removed invalid TBS technology BT_TBS_TECHNOLOGY_IP that
doesn't exist.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-07-12 06:24:39 -04:00
Rubin Gerritsen
85eadcfddc Bluetooth: Mark bt_<type>_err_to_str() APIs experimental
It was pointed out in a future PR that they should have
a corresponding experimental Kconfig entry.

See PR #73795.

This updates the APIs added in PR #73826 and PR #74295.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-07-11 13:11:59 -04:00
Mark Wang
64f38fc348 Bluetooth: A2DP: Fix mistake parameter
After configuration, the stream instance is valid and stream's
local_ep valid. bt_a2dp_stream_establish's parameter is stream
too. So in bt_a2dp_stream_establish, stream->local_ep should be
used to tell lower level (AVDTP) the sep.
set_config_param is used by copy-paste mistake.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2024-07-11 16:16:09 +02:00
Lyle Zhu
f3a1cf2782 Bluetooth: SDP: Fix stack override issue
Check the remaining space of the local variable
`filter` to avoid stack override issue.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-07-11 16:15:53 +02:00
Emil Gydesen
c4840462bf Bluetooth: BAP: Scan delegator: Add log if actionable CBs are not set
If the callbacks are not set, then we cannot do the requested actions
from the broadcast assistant. Since this is a significant issue,
that may prevent the role from working as intended,
LOG_WRN is used other LOG_DBG.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-07-11 16:13:55 +02:00
Emil Gydesen
2761204957 Bluetooth: BAP: Fix notifying recv state for bonded devices
The scan_delegator_security_changed function had a few issues
that were addressed:
1) It used an internal field to check level rather than the
   value provided by the API
2) It did not treat bt_addr_le_is_bonded as a boolean return value
3) It did not properly truncate the recv state (fixed by using the
   proper function bass_notify_receive_state)

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-07-11 12:40:21 +02:00
Jonathan Rico
4afe745a1d Bluetooth: host: Add lower bound for CONFIG_BT_BUF_ACL_RX_COUNT
See comment above assert for more.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-07-10 11:47:26 -04:00
Emil Gydesen
bbf599a3de Bluetooth: TBS: Remove BT_TBS_TECHNOLOGY_IP
BT_TBS_TECHNOLOGY_IP is not a valid technology value
for TBS since it's not defined by the spec.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-07-09 19:06:29 +02:00
Pisit Sawangvonganan
9b2ab20f23 bluetooth: fix typo in (include/zephyr/bluetooth, subsys/bluetooth/)
Utilize a code spell-checking tool to scan for and correct spelling errors
in all files within the `include/zephyr/bluetooth` and `subsys/bluetooth`

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-07-09 17:20:38 +02:00
Zihao Gao
6ebb65d163 Bluetooth: fix compiling issue when either A2DP SRC or SNK are not enabled
Some of the A2DP interfaces are not defined if the corresponding feature
is not enabled, and therefore shall not be initialized.
This patchs include the interfaces/variables by the configurations to
go through the compiling stage.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2024-07-09 14:03:07 +02:00
Emil Gydesen
5901dcbaa7 Bluetooth: Kconfig: Increase BT_HCI_TX_STACK_SIZE for ISO_BROADCAST
When using an encrypted broadcast, the previous value is no
longer enough and caused a stack overflow.

Slightly increased the value.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-07-08 16:03:21 +02:00
Emil Gydesen
c46b2e086b Bluetooth: Kconfig: Add dependency on BT_CONN for PAST
PAST only works if you have a connection, so the PAST
feature should depend on that.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-07-08 09:27:11 +02:00
Emil Gydesen
711b42ae16 Bluetooth: Host: Fix recv_enabled field for PAST
When syncing to a PA using PAST then the sync_info.recv_enabled
was always just set to true, regardless of what mode was set
during the subscribe parameters.

The mode(s) are now stored in an array (with the default value
as well) so that we can retrieve that information when the PA
has synced via PAST.

It was considered to put the `mode` value into the `bt_conn`
struct, but that would require an API change as the `bt_conn`
parameter for the subcribe function uses `const`.

This commit also modifies the guard for PAST to be the more
correct value CONFIG_BT_PER_ADV_SYNC_TRANSFER_RECEIVER instead
of just CONFIG_BT_CONN.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-07-08 09:27:11 +02:00
Emil Gydesen
03d07950aa Bluetooth: OTS: Fix issue with callbacks not being set
The checks for callbacks in bt_ots_init did not correctly take the
ots_init->features.oacp into account for all callbacks, which
caused some issues.

Slightly optimized the check for ots->cb->obj_read by moving the check
and reducing the number of places the code calls oacp_read_proc_cb.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-07-06 17:02:23 +02:00
Jonathan Rico
be61ae4c9c Bluetooth: host: disallow scan with timeout when BT_PRIVACY=y
See comment in code.

Fixes #73634

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-07-05 18:43:40 +02:00
Jonathan Rico
a7c5fb7065 Bluetooth: GATT: factor out notify callback
- De-duplicate code
- Add `LOG_WRN` on unsubscribe error

Fixes #74720
Fixes #74721

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-07-05 18:38:17 +02:00
Lyle Zhu
c9708ff951 Bluetooth: A2DP: Check the pointer before using
Check the pointer `sep` before using it.

Fixes #74734.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-07-05 12:33:38 +02:00
Lyle Zhu
8276d4f79a Bluetooth: A2DP: Fix NULL pointer references issue
The opposite logic is used to determine if a
pointer is valid.

Correct the judgment logic.

Fixes #74728.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-07-05 12:32:41 +02:00
Lyle Zhu
6fad658569 Bluetooth: A2DP: Fix NULL pointer references issue
The opposite logic is used to determine if a
pointer is valid.

Correct the judgment logic.

Fixes #74732.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-07-05 12:32:05 +02:00
Lyle Zhu
9be685eefe Bluetooth: A2DP: Access pointer if it is valid
Only access if the pointer `stream` is valid.

Fixes #74735
Fixes #74740

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-07-05 12:28:45 +02:00
Emil Gydesen
19fe0673f9 Bluetooth: ISO: Tone down some dbg logs
Several log statements were using the regualar LOG_DBG,
but when ISO is actually used, those were called every TX
which at 10ms SDU intervals would fill up the log really fast
and not provided much value outside of some specific debugging.

Modified those logs to use BT_ISO_DATA_DBG which is another
log level for ISO data.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-07-05 12:28:01 +02:00
Jonathan Rico
ac37d6483a Bluetooth: Host: Remove conn param update checks
The rationale behind that change is that the Application can use the
`bt_conn_le_param_update()` API to signal the controller to reschedule
the link.

Even if the new connection params are within the old ones, the
controller would be free to choose an e.g. smaller interval. The host
API should not prevent this usage.

Fixes https://github.com/zephyrproject-rtos/zephyr/issues/74292

Co-authored-by: Knut Eldhuset <knut.eldhuset@nordicsemi.no>
Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-07-04 18:00:35 -04:00
Emil Gydesen
b413b505ee Bluetooth: BAP: Broadcast: Fix state checks
The existing state checks for both the broadcast sink
and broadcast source only ever checked the first BIS.
This sort of made sense, since they are all linked by HCI
(i.e. they share the same state), but there is a race condition
in the ISO and BAP callbacks that could allow applications
to delete sinks and sources before all the ISO callbacks
had been handled.

By treating the sink and source states as the highest value
of the BIS, then we better treat all BIS the same.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-07-03 15:28:17 +02:00
Jonathan Rico
85c57c2da3 Bluetooth: host: ensure ownership of conn on TX path
This is a bug-fix:

When upper layers want to send something, they add a `conn` object to a
list. They do so by adding a node on `struct conn` rather than the object
itself.

We forgot to increase the reference count of the connection object when
doing so. This means that there can be a scenario where the conn object is
destroyed and re-used while still being on the TX list/queue.

This is bad for obvious reasons.

This patch fixes that by:
- increasing the refcount when putting on the TX list
- decreasing the refcount *only* when popping off the TX list
- passing a new reference from `get_conn_ready` into `bt_conn_tx_processor`

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-07-02 14:18:23 +02:00
Emil Gydesen
fa447948d2 Bluetooth: BAP: Scan del: Overwrite metadata if len == 0
If the metadata length is 0 in the mod source operation,
we set the length to 0 and memset the stored value.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-07-01 18:14:14 +02:00
Flavio Ceolin
bb56c3898c bluetooth: host/classic: Fix possible buffer overflow
Fix possible buffer overflow in rfcomm. Check the buffer len
before read it.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2024-07-01 09:13:22 +02:00
Emil Gydesen
1159c2adda Bluetooth: OTS: Add return validation of bt_uuid_create for client
The OTS client did not validate the return value of bt_uuid_create.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-28 07:50:30 -04:00
Emil Gydesen
7b0784c1f6 Bluetooth: ASCS: Validate num_ases in CP requests
Add validation of the number of ASEs in control point
write requests.

This validates that the number of ASEs
in the control point is not greater than the total number
of ASEs we support.

This also validates that the GATT MTU is large enough to
hold all the responses from the write since those can only be
sent as notifications and never be truncated.

Finally this validates and updates the size of the buffer used to
hold the responses, which may be an optimization for some builds.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-28 07:20:47 -04:00
Jordan Yates
91f8c1aea9 everywhere: replace #if IS_ENABLED() as per docs
Replace `#if IS_ENABLED()` with `#if defined()` as recommended by the
documentation of `IS_ENABLED`.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-06-28 07:20:32 -04:00
Jordan Yates
cf870e8350 bluetooth: correct bt_le_scan_param scan type
The `type` parameter of `struct bt_le_scan_param` is documented as
taking a `BT_LE_SCAN_TYPE_*` value, not a `BT_HCI_LE_SCAN_*` value.

In practice this makes no difference as the values are defined as the
same integer, but does result in `<zephyr/bluetooth/hci.h>` not needing
to be included.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-06-28 11:34:36 +02:00
Emil Gydesen
044f8aaeb3 Bluetooth: OTS: Add len validation in olcp_ind_handler
Verify the length of the indication before we pull from the
buffer.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-27 08:49:20 -04:00
Babak Arisian
0c611d01a7 Bluetooth: Audio: Dereference null return value in cap_initiator.c
Null pointer dereferences in functions:
  bt_cap_initiator_unicast_audio_update (Line 1478)
  bt_cap_initiator_unicast_audio_stop (Line 1693)

Fixes #74729 and #74739

Signed-off-by: Babak Arisian <bbaa@demant.com>
2024-06-27 08:48:46 -04:00
Babak Arisian
a895abab86 Bluetooth: Audio: Unchecked return value in audio.h
Unchecked return value in functions: print_ltv_array (Line 287)

Fixes #74733

Signed-off-by: Babak Arisian <bbaa@demant.com>
2024-06-27 08:48:18 -04:00
Lyle Zhu
1d1dc7a875 Bluetooth: Classic: HF_AG: Fix unexpected return
When `buf->len` is 0, the function of the while-loop
will be returned with error code `-ENOTSUP`.
The code block after while-loop cannot be reached
event though it is a correct command.

Use `buf->len` as the end condition of the while-loop.

Fixes #74730.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-06-27 10:53:17 +02:00
Lyle Zhu
a3a08b93ed Bluetooth: Classic: HF_AG: Fix incorrect status judgment
Wrong condition of AG status is used for status
checking.

Fixes #74727.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-06-27 10:53:05 +02:00
Lyle Zhu
599812281b Bluetooth: Classic: HF_AG: Fix incorrect status judgment
Wrong condition of AG status is used for status
checking.

Fixes #74726.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-06-27 10:52:56 +02:00
Jordan Yates
40eededf01 bluetooth: bt_le_ext_adv_start_param is const
`bt_le_ext_adv_start` does not modify the `param` argument, which can
therefore be marked as `const`. This allows the struct to exist purely
in ROM.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-06-26 13:05:14 -04:00
Emil Gydesen
68a0741d4f Bluetooth: ISO: Allow 0 interval and latency in CIG for unused dir
If the CIG only contains C to P CISes, then we should allow
setting the P to C interval and latency to 0, and vice versa.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-26 09:01:53 -04:00
Johan Hedberg
63d97c1556 Bluetooth: shell: Fix missing check for buffer allocation
In practice this allocation is very unlikely to fail, however being
consistent with checking for a failure keeps Coverity happy.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2024-06-26 05:59:15 -04:00
Pisit Sawangvonganan
07994ab5d7 bluetooth: fix typo in (common, crypto, services, shell)
Utilize a code spell-checking tool to scan for and correct spelling errors
in all files within the subsys/bluetooth/(common, crypto, service, shell).

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-06-25 10:27:23 -04:00
Pisit Sawangvonganan
0df7fd68a7 bluetooth: mesh: fix typo
Utilize a code spell-checking tool to scan for and correct spelling errors
in all files within the subsys/bluetooth/mesh directory.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-06-25 10:27:23 -04:00
Pisit Sawangvonganan
521b9e2c04 bluetooth: host: fix typo
Utilize a code spell-checking tool to scan for and correct spelling errors
in all files within the subsys/bluetooth/host directory.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-06-25 10:27:23 -04:00
Pisit Sawangvonganan
9b305d5d72 bluetooth: controller: fix typo
Utilize a code spell-checking tool to scan for and correct spelling errors
in all files within the subsys/bluetooth/controller directory.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-06-25 10:27:23 -04:00
Pisit Sawangvonganan
110574f532 bluetooth: audio: fix typo
Utilize a code spell-checking tool to scan for and correct spelling errors
in all files within the subsys/bluetooth/audio directory.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-06-25 10:27:23 -04:00
Sebastian Panceac
9ce338d416 Bluetooth: Fix CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY build warnings
This commit fixes compilation warnings that are present when compiling
with CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY as can be seen in this
compiler log:

"""
In file included from /zephyr-sdk-0.16.1/arm-zephyr-eabi/picolibc/
include/string.h:215,
                 from /zephyr/subsys/bluetooth/host/smp.c:15:
In function '__memcpy_ichk',
    inlined from 'sc_send_public_key' at /zephyr/subsys/bluetooth/host/
smp.c:3006:2:
/zephyr-sdk-0.16.1/arm-zephyr-eabi/picolibc/include/ssp/string.h:83:1:
warning: argument 2 null where non-null expected [-Wnonnull]
   83 | __ssp_bos_icheck3_restrict(memcpy, void *, const void *)
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~
/zephyr-sdk-0.16.1/arm-zephyr-eabi/picolibc/include/ssp/string.h:83:1:
note: in a call to built-in function '__builtin_memcpy'
/zephyr/subsys/bluetooth/host/smp.c: In function 'smp_public_key':
/zephyr/subsys/bluetooth/host/smp.c:4214:21: warning: argument 2
null where non-null expected [-Wnonnull]
 4214 | memcmp(smp->pkey, sc_public_key, BT_PUB_KEY_COORD_LEN) == 0) {
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/zephyr-sdk-0.16.1/arm-zephyr-eabi/picolibc/include/string.h:62:10: note:
in a call to function 'memcmp' declared 'nonnull'
   62 | int memcmp (const void *, const void *, size_t);
      |     ^~~~~~
"""

The warning is caused by the potential use of NULL "sc_public_key"
global pointer that is not assigned a value in "smp_init()" if
CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY is enabled. This commit
conditionally changes the behavior of function "smp_public_key()"
if CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY is activated to simply return
and not use the "sc_public_key" variable. Other functions that are not
called anymore by "smp_public_key()" are also conditionally
deactivated when CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY is enabled

Signed-off-by: Sebastian Panceac <sebastian.panceac@ext.grandcentrix.net>
2024-06-25 10:26:41 -04:00
Eunkyu Lee
e491f220d8 Bluetooth: Host: Add missing buffer length check
Modified to check the length of the remaining data in buffer
before processing the next report. The length check is missing
in the cont routine.

Signed-off-by: Eunkyu Lee <mochaccino.00.00@gmail.com>
2024-06-25 06:06:06 -04:00
Lingao Meng
302422ad9d everywhere: replace double words
import os
import re

common_words = set([
    'about', 'after', 'all', 'also', 'an', 'and',
     'any', 'are', 'as', 'at',
    'be', 'because', 'but', 'by', 'can', 'come',
    'could', 'day', 'do', 'even',
    'first', 'for', 'get', 'give', 'go', 'has',
    'have', 'he', 'her',
    'him', 'his', 'how', 'I', 'in', 'into', 'it',
    'its', 'just',
    'know', 'like', 'look', 'make', 'man', 'many',
    'me', 'more', 'my', 'new',
    'no', 'not', 'now', 'of', 'one', 'only', 'or',
    'other', 'our', 'out',
    'over', 'people', 'say', 'see', 'she', 'so',
    'some', 'take', 'tell', 'than',
    'their', 'them', 'then', 'there', 'these',
    'they', 'think',
    'this', 'time', 'two', 'up', 'use', 'very',
    'want', 'was', 'way',
    'we', 'well', 'what', 'when', 'which', 'who',
    'will', 'with', 'would',
    'year', 'you', 'your'
])

valid_extensions = set([
    'c', 'h', 'yaml', 'cmake', 'conf', 'txt', 'overlay',
    'rst', 'dtsi',
    'Kconfig', 'dts', 'defconfig', 'yml', 'ld', 'sh', 'py',
    'soc', 'cfg'
])

def filter_repeated_words(text):
    # Split the text into lines
    lines = text.split('\n')

    # Combine lines into a single string with unique separator
    combined_text = '/*sep*/'.join(lines)

    # Replace repeated words within a line
    def replace_within_line(match):
        return match.group(1)

    # Regex for matching repeated words within a line
    within_line_pattern =
	re.compile(r'\b(' +
		'|'.join(map(re.escape, common_words)) +
		r')\b\s+\b\1\b')
    combined_text = within_line_pattern.
		sub(replace_within_line, combined_text)

    # Replace repeated words across line boundaries
    def replace_across_lines(match):
        return match.group(1) + match.group(2)

    # Regex for matching repeated words across line boundaries
    across_lines_pattern = re.
		compile(r'\b(' + '|'.join(
			map(re.escape, common_words)) +
			r')\b(\s*[*\/\n\s]*)\b\1\b')
    combined_text = across_lines_pattern.
		sub(replace_across_lines, combined_text)

    # Split the text back into lines
    filtered_text = combined_text.split('/*sep*/')

    return '\n'.join(filtered_text)

def process_file(file_path):
    with open(file_path, 'r', encoding='utf-8') as file:
        text = file.read()

    new_text = filter_repeated_words(text)

    with open(file_path, 'w', encoding='utf-8') as file:
        file.write(new_text)

def process_directory(directory_path):
    for root, dirs, files in os.walk(directory_path):
        dirs[:] = [d for d in dirs if not d.startswith('.')]
        for file in files:
            # Filter out hidden files
            if file.startswith('.'):
                continue
            file_extension = file.split('.')[-1]
            if
	file_extension in valid_extensions:  # 只处理指定后缀的文件
                file_path = os.path.join(root, file)
                print(f"Processed file: {file_path}")
                process_file(file_path)

directory_to_process = "/home/mi/works/github/zephyrproject/zephyr"
process_directory(directory_to_process)

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2024-06-25 06:05:35 -04:00
Lyle Zhu
37d62c6a16 Bluetooth: RFCOMM: check the validity of received frame
Check whether the received frame is complete by
comparing the length of the received data with
the frame data.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-06-25 09:03:44 +02:00
Ali Hozhabri
3b726dee53 Bluetooth: Host: Fix HCI command timeout usage
Fix Bluetooth initialization problem caused by PR#72090
for at least ST boards that are using BlueNRG BLE modules.

For more information, please refer to issue #74528.

Signed-off-by: Ali Hozhabri <ali.hozhabri@st.com>
2024-06-24 14:48:25 -04:00