Compare the actual values of the codec configuration
or qos configuration when in the codec configured state,
the QoS configured state or the enabling state.
In the case that the stream is one of the these states
and the parameters to set differ from what is already there,
the appropriate actions should be taken to set the right
values, even if it does not mean an actual state change.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit fixes 2 bugs:
1) Bad/missing err return from bt_bap_stream_reconfig
2) Missing handle of codec_cfg fields that are not part of the
ASCS notifcations: path_id, ctlr_transcode, target_latency and
target_phy.
To be able to set these, we need to store them somewhere, and it
makes sense to attach the ep->codec_cfg earlier so that we can store
them in there.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Instead of using the "regular" BAP codec capabilities for GMAP,
`gmap init` will now register its own capabilities.
This makes it more clear that for the gaming context we only
support the frequencies and frame sizes defined by GMAP
(e.g. no 8KHz for gaming audio, or 155 frame sizes).
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Use the unicast_to_broadcast_created callback to properly handle
the creation and potentional deletion of the broadcast source.
Additionally since this exposes the broadcast source before
the procedure is completed, additional checks for whether
the handover is in progress has been added.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
MISRRA 14.2 does not allow modifying the iterator inside
for loops. Modify the loops to while where appropriate
and add or modify additional checks for length before
incrementing the iterator.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit fixes 2 things:
1) If an advertising set is not enabled, the rpa_expired callback
is no longer called. Since we pause the adv set to update the RPA
we need to use BT_ADV_RPA_UPDATE instead of BT_ADV_ENABLED to check
whether it is "active".
2) If we do not have an active advertising set, not scanning or
not initiating a connection, the RPA timer is stopped. The
timer is started again whenever any action that uses RPA is
started again.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Providing a number of objects as decimal (e.g. 48) is
more intuitive than hex (e.g. 0x30) for humans.
Additionally the max number of objects when the directory
listing object is support has also been changed to more
accurate depict the actual maximal number of objects based on
CONFIG_BT_OTS_OBJ_MAX_NAME_LEN instead of using the absolute
max value. Since Kconfig does not support such calculations,
this maximum has been moved to a BUILD_ASSERT.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The command did not count correctly in the unicast_streams
array, and the number of streams support did not match the
audio configuration.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
When a stream that is currently being used for incoming
data and sends that data to the USB host disconnects or
otherwise stops, we now clear any data that may be stored
for that stream.
The reason for this is that if another stream takes it place
we should start from a clean slate to avoid any issues with
mixing audio data.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Move PACS out from CONFIG_BT_BAP_UNICAST_SERVER as the broadcast
sink shall also register PACS.
Modified the code for PACS a bit to clean it up and collect it in
one place.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The gmap_reset function also reset the gmap_cli->flags
which made the atomic_test_and_set_bit for
GMAP_CLIENT_FLAG_BUSY useless.
Modified the reset function to not clear that flag.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Move the ECDH P-256 key generation during mesh provisioning from the
system workqueue to the dedicated long workqueue (bt_long_wq). The ECDH
computation can take several seconds on platforms with software ECC,
blocking all other system workqueue users for the duration.
Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
Move the long workqueue implementation (long_wq.c, long_wq.h) and its
Kconfig options from subsys/bluetooth/host/ to subsys/bluetooth/common/.
This makes the dedicated workqueue API available to other Bluetooth
subsystems beyond the host, such as Bluetooth Mesh, without relying on
internal host headers.
Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
Fix the 'l2cap metrics' command argument definition.
It accepts a single parameter ("metrics") to print throughput,
but was incorrectly set to require two arguments, preventing output.
Update SHELL_CMD_ARG to min=1 and max=1 to allow enabling,
disabling, and printing throughput metrics.
Signed-off-by: Sohan Kumar <sohan.kumar@nxp.com>
If we had a bond with a device and the flags were non-zero,
and we power cycled but where bt_has_register was not called
before the bonded device reconnected then in the
security_changed we would call notify_work_reschedule which
would then notify_work_handler would access uninitialized values
like hearing_aid_features_attr or the other attributes (they would
be NULL), causing an assert when calling bt_gatt_is_subscribed.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Add a specific check for getting the broadcast streaming
context, and log the individual values for unicast and
broadcast if they differ.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
There is a test case for the shell to build with
CONFIG_BT_CONN_DYNAMIC_CALLBACKS=n. Registering the conn
callbacks dynamically in the cmd_bap_scan_delegator_init
fails that test.
Change to use BT_CONN_CB_DEFINE.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Add validation to prevent sending additional OBEX requests if the
SRM has been enabled after the final bit has been set in PUT or GET
operations on the Client side.
When the SRM has been enabled Without the waiting flag, if the final
bit of the request has been set in the last packet in a multi-packet
operation, the following request packet should not be set.
This ensures proper OBEX protocol sequencing by preventing clients
from sending additional requests if the SRM has been enabled once
they have indicated the final request in a multi-packet operation.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Check Single Response Mode (SRM) and SRM Parameters (SRMP) for
OBEX PUT and GET operations on the Server side to avoid the responses
that violate the GOEP specification.
Changes include:
- Add BT_OBEX_REQ_RECV and BT_OBEX_REQ_F_BIT flag definitions for
tracking request reception and final bit state
- Implement obex_server_parse_srm() for parsing and validating SRM
headers in both requests and responses
- Add obex_server_parse_req_srm() and obex_server_parse_rsp_srm()
to handle SRM headers with first request tracking
- Implement obex_server_parse_srmp() for parsing and validating SRMP
headers with proper sequencing checks
- Add obex_server_rsp_check() to validate response sequencing when
SRM is enabled, ensuring responses are only sent when required
- Update obex_server_put_common() and obex_server_get_common() to
parse SRM/SRMP headers and track request state
- Enhance bt_obex_put_rsp() and bt_obex_get_rsp() to validate
response conditions, parse SRM/SRMP headers, and handle state
rollback on failure
- Move opcode validation before buffer allocation to prevent
resource leaks
- Improve error handling with proper flag restoration on failure
This implementation ensures the server properly validates SRM/SRMP
headers and enforces protocol rules for when responses must be sent,
complementing the existing client-side SRM/SRMP support.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Check Single Response Mode (SRM) and SRM Parameters (SRMP) for
OBEX PUT and GET operations on the Client side to avoid the requests
that violate the GOEP specification.
Changes include:
- Parse and validate SRM/SRMP headers in client requests and responses
- Track SRM/SRMP state using client flags (BT_OBEX_REQ_1ST,
BT_OBEX_REQ_SRM, BT_OBEX_REQ_SRMP, BT_OBEX_RSP_SRM, BT_OBEX_RSP_SRMP,
BT_OBEX_RSP_RECV)
- Add request validation to ensure proper sequencing when SRM is
enabled or disabled
- Refactor client request completion handling into
obex_client_req_complete(), add obex_client_save_last_operation(),
and obex_client_clear_active_state() helper
- Add obex_client_req_check() to validate request state before sending
- Restore client state on error in PUT and GET operations
- Move bt_obex flags enum from header to implementation file
SRM allows multiple requests to be sent without waiting for responses,
while SRMP provides flow control when the receiver needs the sender to
wait. This implementation ensures proper validation of SRM/SRMP headers
and enforces protocol rules for when responses must be received.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Standardize pointer and error code comparisons throughout the OBEX
implementation to follow Zephyr coding guidelines:
- Replace implicit pointer checks (!ptr) with explicit NULL
comparisons (ptr == NULL)
- Replace implicit error checks (!err) with explicit zero
comparisons (err != 0 or err == 0)
- Update length checks to use explicit comparisons (len > 0
instead of len, len == 0 instead of !len)
This improves code readability and consistency across the obex.c file
with the project's coding standards without changing any functional
behavior.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
bt_conn_ref can return NULL if the application passes a stale conn
pointer. Check the return value in all public LE Audio discover APIs
and return -ENOTCONN on failure.
Signed-off-by: Rishav Chakraborty <reshav01@gmail.com>
The get_progress() function in the BLOB shell had two bugs:
1. The loop iterated over byte count (DIV_ROUND_UP(total_blocks, 8))
instead of total block count, and the bit indexing used i % 8
for both the byte index and bit position, meaning it only ever
inspected the first byte of the missing_blocks array.
2. The final calculation (total_blocks - blocks_not_rxed) / total_blocks
performed integer division without scaling, always yielding 0 or 1
instead of a percentage.
Fix the loop to iterate over all block bits using proper byte/bit
indexing, and multiply the numerator by 100 to produce a correct
0-100 percentage result.
Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
Remove `$(ZEPHYR_BASE)` from `source "<file>"`.
Source is always relative to ZEPHYR_BASE, so no need to specify it.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Use buf->len (actual data length) instead of buf->size (buffer
capacity) when calculating the number of chunks to allocate in
bt_mesh_delayable_msg_manage(). Using buf->size causes over-allocation
when the buffer capacity is much larger than the payload, starving
the chunk pool for other delayable messages.
Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
BT_LONG_WQ was enabled for BT_GATT_CACHING through a "default y if" on the
option itself, but for BT_ECC through an "imply BT_LONG_WQ" on BT_ECC.
Use a consistent mechanism for both by replacing the implication with a
"default y if BT_ECC" on BT_LONG_WQ.
Besides being more consistent, this makes the BT_ECC driven enablement
overridable through a configdefault: an "imply" sets a weak reverse
dependency that a (config)default cannot turn off, whereas a plain default
can. This allows platforms to disable the long workqueue (and fall back to
running the long-running operations on the system workqueue) via a
configdefault in their Kconfig.defconfig, which a subsequent change makes
use of on nRF51.
This change has no functional effect on its own: BT_ECC continues to enable
BT_LONG_WQ by default.
Assisted-by: Claude:claude-opus-4.8
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
When the LPN terminates a friendship by sending Friend Clear, the
Confirm was never received due to two issues:
1. The Friend's immediate Confirm was enqueued into the Friend
Queue and then purged by friend_clear(). Fixed by calling
friend_clear() before sending.
2. The Confirm advertisement completed before the LPN finished
its own retransmissions and started scanning. Fixed by delaying
the Confirm send based on network transmit parameters.
Additionally, bypass the LPN transport filter during the CLEAR
state so the Confirm is not dropped on arrival.
The clear procedure and Confirm contexts share a union since they
are mutually exclusive for the same Friend slot.
Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
The "dfd receivers-get" shell command prints the firmware distribution
progress under the JSON "progress" key, but first divides
bt_mesh_dfu_cli_progress() by two.
bt_mesh_dfu_cli_progress() is documented to return "the progress of the
current transfer in percent", i.e. a 0-100 value. The division mirrors
the on-wire encoding of the Transfer Progress field in the Firmware
Distribution Receivers List message, which is expressed in 2% increments
(0-50, see handle_receivers_get() in dfd_srv.c). That encoding is correct
for the over-the-air field, but applying it to a human-facing diagnostic
command is misleading: the command reports half of the actual percentage
(e.g. 25 while the transfer is at 50%).
It is also inconsistent with the Firmware Update Client shell command:
cmd_dfu_tx_progress() in shell/dfu.c prints bt_mesh_dfu_cli_progress()
directly as "DFU progress: %u %%", i.e. a 0-100 percentage.
Drop the division so the dfd shell reports the 0-100 percentage that the
API returns, aligning it with the dfu cli command. The on-wire encoding
in dfd_srv.c is intentionally left unchanged.
Signed-off-by: Francesco Vatteroni <francescov.90@gmail.com>
Instead of logging based on the bap stats interval, the USB
part will not just use a flat rate limit of 30 seconds.
Since the bap_stats_interval and USB rates are used for 2 very different
things, and since USB will likely be trigger way more often, it did
not make a lot of sense to use the same value for both.
30 seconds was chosen as it still provides information to
the user on a reasonable interval, without filling up the
shell console too fast.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Add command to loop through known receive states and print
their content. This also adds the request BIS sync value for
comparison to the currently synced value.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Change the order of the pa_interval and bis_sync arguments for
the add_src command. The reason is that the user will generally
care more about setting the right bis_sync value (e.g. to 0x01)
rather than the PA interval which may be set to "unknown" in
any case. With this change the user can set the bis_sync without
the pa_interval and just defer to the "unknown" PA interval value.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The do_plc applies to the entire PLC, and not the individual frames,
so we should not clear it after doing PLC on the first frame.
Additionally this will now also do a memset after k_mem_slab_alloc
to avoid having to clearing data manually before free'ing it.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Since update_usb_streams rely on the sh_stream->rx to determine
whether to update the streams, we shall not clear that before calling
update_usb_streams
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Add calls to print_codec_cfg whenever the codec configuration
data or metadata may be changed.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Suffix the LOCATION and CONTEXT macros with DEFAULT to make it
clearer that these are just the default value, since both the
location and context are configurable at runtime.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
There's a for loop in parse_read_std_char_desc() that'll go on forever if
rsp->len is 0. Add a minimum length check to the beginning of it to avoid
this issue.
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
This workaround addresses an assert that appears when nRF52 hardware
running as central connects to a peripheral with certain connection
parameters.
Fixes#106450
Signed-off-by: Xudong Zheng <7pkvm5aw@slicealias.com>
The relasing state can go to IDLE or CODEC_CONFIGURED but
was defined to only allow IDLE or QOS_CONFIGURED.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The `err` variable was overwritten by the k_mutex functions
before being logged, so it did not log the actual error.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>