Having tracing and instrumentation enabled at the same time causes
tracing events to have an end timestamp earlier than the instrumented
methods that were sources of these events. This works around this fact
by avoiding emitting unnecessary events during instrumentation of
tracing event handling.
Signed-off-by: Łukasz Kędziora <lkedziora@antmicro.com>
Signed-off-by: Maciej Torhan <mtorhan@antmicro.com>
acquire_mutex() evaluated k_current_get() and loaded the mutex type on
every lock operation, but both values are only needed when the calling
thread already owns the mutex (relock handling). In the common
uncontended case the owner is NULL, so short-circuit on that before
calling k_current_get() - which is a system call in userspace builds
without thread-local current - and move the type/offset lookup into the
self-owned branch.
Measured with callgrind on native_sim/native/64: uncontended
pthread_mutex_lock() drops from 241 to 229 instructions (-5%); in
userspace builds this additionally removes one syscall per uncontended
lock. No behaviour change: a NULL owner can never equal the calling
thread.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:fable-5
write_lock_acquire() unconditionally read k_uptime_get() to prorate the
caller's timeout across its two semaphore takes, but the start time is
only consumed for finite timeouts. pthread_rwlock_wrlock() (FOREVER)
and pthread_rwlock_trywrlock() (no wait) paid a 64-bit uptime read -
a spinlocked tick read plus tick-to-ms conversion, and a syscall in
userspace builds - for a value that was then discarded. The trylock
path additionally performed a second clock read to compute a remaining
timeout that is always zero.
Read the start time only when the timeout is finite and non-zero, and
skip the remaining-time computation for the zero-timeout path.
Timed-lock behaviour is unchanged: the start time is captured at the
same point as before, relative to the first semaphore take.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:fable-5
pthread_once() took the global pthread pool lock on every call for the
lifetime of the program, long after the one-time initialization
completed. Library code guarding lazy initialization with
pthread_once() therefore paid a semaphore take/give pair (a syscall
pair in userspace builds) on every call.
Return immediately when the init flag is already observed set. The
flag never transitions back to false, and the locked path already
allows a caller to observe flag == true and return while another
thread is still executing init_func() (the flag is set before
init_func() runs), so the lock provided no synchronization with the
initializer's completion that the fast path would lose.
Measured with callgrind on native_sim/native/64: pthread_once() on an
already-completed once control drops from 244 to 21 instructions
(-91%), and no longer serializes against unrelated pthread operations.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:fable-5
Add a coredump backend for the AMD ACP DSP that stores the Zephyr
coredump together with a SOF compatible DSP "oops" record in the ACP
exception buffer. The backend writes the panic code where the SOF host
driver expects it and raises a DSP-to-host interrupt so the host can
collect the dump.
Enable ARCH_SUPPORTS_COREDUMP for the acp_7_x SoC and wire the new
backend into the coredump core and build.
Signed-off-by: DineshKumar Kalva <DineshKumar.Kalva@amd.com>
Introduce RTIO CQE callback, which is an optional callback called by
an RTIO context when a CQE is submitted to it. This callback serves
a similar function to the RTIO consume sem, notifying the user when
a new CQE is available by callback rather than by unblocking.
A specific usecase for this callback is I2S streaming, where a user
wants to be notified immediately upon a submission being completed,
while not blocking a thread to do so, and while not blocking the
stream by inserting callback SQEs into the pipeline.
Note the callback and user data is not protected with a lock, even
though they can be updated at runtime. The lock is expensive and only
neccesary if a user tries to change it while a CQE is submitted. This
is documented with a warning in the API description of
rtio_set_cqe_callback()
Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
These comments claim either that C++ does not allow empty structs, or
that a size of zero is not allowed in C++. Both have it backwards: C++
allows an empty struct and gives it size 1, while ISO C does not allow
one at all, and the compilers that accept it as an extension give it
size 0. That disagreement is the reason these padding members exist.
Replace them with one wording that also records that an empty struct
is not valid C to begin with. Comments that were already accurate are
left alone.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
Refactor ASCS to use the system workqueue for the control
point notification. This is to ensure that we always send
the notification, even if we may be out of ATT buffers at
any point, but also ensures that the control point notification
is sent before any ASE notifications triggered by that control
point write.
Some refactoring was done to account for the changes when cleaning
up the ASEs.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Introduce a timing noise policy allowing the CPUFreq subsystem to disrupt
simple side-channel attacks exploiting non-constant time code execution
in a system. This policy does not defend against side-channel attacks and
at best disrupts naiive analysis of fundamentally insecure systems.
Signed-off-by: Sean Kyer <sean.actor@gmail.com>
Run a routine in interrupt context by posting a software interrupt
through the VM and letting it fire when irq_unlock() re-enables IE.
IRQ 0 is used as the trigger line: the board's DTS assigns the lowest
hardware IRQ at 0x0c, so it does not collide with a real device here.
Give the test suite a trigger_irq() for Hexagon as well, going through
the same hypercall, so the shared interrupt tests can drive a line from
software.
Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
Add THREAD_INFO_OFFSET_T_STACK_PTR for Hexagon using switch_handle,
which holds the saved stack pointer for non-current threads. Required
by GDB scripts and debugger plugins that walk the thread list.
Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
Add Hexagon DSP architecture support to Zephyr RTOS, targeting the
Qualcomm Hexagon V67+ ISA running as a guest under the H2 hypervisor.
This includes:
- Architecture scaffolding (Kconfig, CMakeLists, arch selection)
- Public headers (arch.h, thread.h, exception.h, error.h)
- Core runtime: context switch, interrupt/exception handling, idle, TLS
- Memory management stubs for flat-memory H2 guest model
- SoC support for QEMU hexagon virt machine
- CMake/LLVM toolchain integration for hexagon cross-compilation
Hexagon uses H2's GEVB (Guest Event Vector Base) for interrupt dispatch
rather than a traditional function-pointer vector table, so
GEN_IRQ_VECTOR_TABLE is disabled by default.
Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
The SID is only used for extended advertising sets. For any
legacy advertising sets, we now set the adv->sid to
BT_GAP_SID_INVALID. This is similar to how the SID for
legacy scan reports are handled in scan.c
bt_le_ext_adv_update_param could also have a new SID for the
advertising set that was never stored in adv->sid. This has
also been fixed in this commit.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
When logging parent->syntax check if parent is not null. It is
possible if remote client do not have any commands enabled that
msg->parent is null.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
Increate default timeout value. When command prints a lot of data
it can easily take much more than 100 ms.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
The image management server reports 64-byte image digests when MCUboot
uses SHA-512. The client currently accepts only 32-byte state-response
digests and encodes that fixed length in state-write requests, preventing
it from listing or selecting images on such targets.
Support both 32-byte SHA-256 and 64-byte SHA-512 digests. Store the
received digest length and add a hash length argument to
img_mgmt_client_state_write().
Update the tests to cover both digest lengths.
Assisted-by: claude:opus-4.8
Signed-off-by: Vidar Berg <vidar.berg@nordicsemi.no>
Set D0 (SetEthernetPacketFilter) in bmNetworkCapabilities of the NCM
Functional Descriptor and add the Network Capabilities bitmap values
from NCM 1.0, 5.2.1, Table 5-2 to usb_cdc.h.
The request handler already accepts SET_ETHERNET_PACKET_FILTER, but
without D0 the macOS NCM host driver refuses to enable promiscuous mode
on the interface, so Internet Sharing cannot add it to its bridge and
starts no DHCP or DNS service for it. There is no filtering on the
device side, as with commit 89e778d5b2
("usb: device_next: usbd_cdc_{ecm,ncm}: support promisc mode").
Assisted-by: Claude:claude-opus-5
Signed-off-by: Jeff Welder <Jeff.Welder@ellenbytech.com>
The class API vtable and the descriptor pointer array are never written
after initialization, but were missing a const and so ended up in
.data. Add it.
No sample or test builds this backend, so the saving was not measured.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
The class API vtable and the descriptor pointer arrays are never
written after initialization, but were missing a const and so ended up
in .data. Add it.
Saves 84 bytes of RAM in samples/subsys/pmci/mctp/usb_endpoint on
nrf52840dk/nrf52840.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
The class API vtable and the descriptor pointer arrays are never
written after initialization, but were missing a const and so ended up
in .data. Add it.
Saves 68 bytes of RAM in samples/subsys/tracing/basic on
nrf52840dk/nrf52840.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
The class API vtable and the descriptor pointer arrays are never
written after initialization, but were missing a const and so ended up
in .data. Add it.
Saves 84 bytes of RAM in samples/subsys/dap on nrf52840dk/nrf52840.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
Shell UART backend file was expecting presence of zephyr,shell-uart in DT
and the default instance was created. Add ifdefs to skip it if chosen is
not set.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
The periodic advertising report handler checks that the event header is
present and that the data fits in the reassembly buffer, but not that
the event actually carries as many data bytes as its length field
claims. With CONFIG_BT_PER_ADV_SYNC_BUF_SIZE > 0, a report with a
length field larger than the remaining event payload makes
net_buf_simple_add_mem() copy up to 255 bytes from beyond the end of
the HCI event buffer into the reassembly buffer, and the result is
passed on to the application.
Drop such reports the same way as reports that do not fit in the
reassembly buffer.
Fixes#117587
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
usbh_desc_get_next_function() sets skip_num=1 when starting from
a plain interface descriptor. usbh_desc_get_next() already advances
past the input, so an additional skip_num=1 makes the loop consume
one extra interface beyond the current one.
Devices with consecutive plain interfaces
(e.g. Quectel EG916Q-GL with 4 vendor interfaces) only get
ifaces 0 and 2 probed; 1 and 3 are silently skipped.
Drop the assignment. The IAD branch is unaffected since its skip_num
comes from bInterfaceCount, which counts interfaces grouped inside
the IAD, not the IAD descriptor itself.
Signed-off-by: Girinandha Manivelpandiyan <girinandha@linumiz.com>
Move alloc_device_address() and usbh_device_set_address()
before reading the full device descriptor.
The current sequence reads the full 18-byte device descriptor
while the device is in the Default state before transitioning
it to the Address state. This causes enumeration failure on the
Quectel EG916Q-GL, which returns bNumConfigurations=0 on the
second Get Descriptor request while in the Default state.
Reorder the sequence to transition the device to the Address
state after the initial 8-byte read, and fetch the full 18-byte
descriptor using the newly assigned address. The new order works
around devices that fail the second Get Descriptor request in the
Default state, while remaining functional on devices that
enumerate correctly with the original order (verified on ECM dongle).
Signed-off-by: Girinandha Manivelpandiyan <girinandha@linumiz.com>
Add CONFIG_SECURE_STORAGE_ITS_TRANSFORM_AEAD_CRYPT_CUSTOM to allow
for example implementations that don't handle the key material directly.
When this option is enabled, the key provider is disabled as the
crypt function is assumed to take care of the key itself, and the
AEAD scheme as well as the key size are not configurable by default
to avoid leaking Kconfig options in case the custom implementation
would not be using them.
The nonce provider remains used as is also when a custom crypt function
is provided.
Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
Remove the `_get` part from their names to make it more logical for them
to contain all the functions pertaining to their module implementations,
not just getters.
Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
In commit 15bb270 (bluetooth: classic: l2cap: Fix race condition in
config rsp handling), the channel transitions from the `CONFIG` state
to the `CONNECTED` state of L2CAP channel will be set after the
configuration response frame has been sent via the sent callback
`l2cap_br_config_rsp_sent_cb()`. The sent callback will be called by
`hci_num_completed_packets()` when the HCI event
`NUM_COMPLETED_PACKETS` is notified. However, the time duration
between the completion of the configuration response transmission
and the arrival of the `NUM_COMPLETED_PACKETS` HCI event is
indeterminate; it depends entirely on the controller.
From the peer's perspective, the L2CAP channel is successfully
established once the configuration response is received, whereas the
local side remains in the `CONFIG` state until the
`NUM_COMPLETED_PACKETS` event arrives. Consequently, it is possible
for the peer to transmit data over the established channel before the
`NUM_COMPLETED_PACKETS` event arrives. Since the local side is still
in the `CONFIG` state, this data will be discarded.
Add `L2CAP_FLAG_CONF_RSP_SENDING` flag, set before queuing the
configuration response and cleared in the sent callback. In the
receive path, attempt to complete the configuration state when this
flag is set, so that data arriving before the HCI
`NUM_COMPLETED_PACKETS` event does not get silently discarded.
The change aims to prevent the dropping of received data while waiting
for the HCI event `NUM_COMPLETED_PACKETS`.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Add a retry timeout mechanism to prevent indefinite retry attempts
when buffer allocation failures persist, ensuring the RFCOMM state
machine eventually fails gracefully instead of retrying forever.
Introduce per-DLC `retry_timeout_work` and per-session
`retry_timeout_work` timers (5 seconds) that run in parallel with
the randomized retry mechanism. When a retry timeout expires, trigger
the RTX timeout handler to tear down the connection.
Add `rfcomm_dlc_retry_timeout()` and `rfcomm_session_retry_timeout()`
handlers that reschedule the RTX work with `K_NO_WAIT` to initiate
immediate disconnect when retry attempts exceed the timeout threshold.
Schedule retry timeout when setting retry flags for:
- DLC operations: PN_REQ, PN_RSP, UA_FOR_SABM, DM, UA_FOR_DISC,
MSC_FC_CLEAR_REQ
- Session operations: FC_ON_REQ, FC_ON_RSP, FC_OFF_RSP, UA_FOR_DISC
Cancel retry timeout when operations succeed to prevent spurious
disconnects after successful recovery.
Rename `RFCOMM_RETRY_TIMEOUT` to `RFCOMM_RETRY_INTERVAL` and introduce
new `RFCOMM_RETRY_TIMEOUT` constant (5 seconds) to distinguish between
the randomized retry interval (0-100ms) and the overall retry timeout
threshold.
Update all retry scheduling calls to use `RFCOMM_RETRY_INTERVAL` for
the randomized delay and `RFCOMM_RETRY_TIMEOUT` for the timeout timer.
Cancel retry timeout work in cleanup paths:
- `rfcomm_dlc_destroy()` for DLC cleanup
- `rfcomm_disconnected()` for session cleanup
Add early return in `rfcomm_session_retry_timeout()` when the
underlying connection is already gone to handle race conditions
during cleanup.
This change complements the randomized retry mechanism by adding an
upper bound on retry duration, preventing resource exhaustion and
ensuring predictable failure behavior when buffer allocation issues
cannot be resolved within a reasonable timeframe.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Refactor RFCOMM retry mechanism to improve robustness and prevent
thundering herd issues when multiple operations fail simultaneously
due to buffer exhaustion.
Add the session-level `retry_work` supports randomized retry delays
for session-scoped operations. Convert DLC `tx_work` from `k_work`
to `k_work_delayable` to support randomized retry delays for
DLC-scoped operations.
Since the FCON and FCOFF apply to all DLCS, they should be handled at
the session-scoped rather the DLC-level. Move their handling to the
session-level `retry_work` instead of handling them per-DLC
`retry_work`. Besides, UA for DISC of DLCI0 also handled by the
session-level `retry_work`.
Introduce randomized retry timeout (0-100ms) using `sys_rand32_get()`
to prevent synchronized retries when multiple DLCs or sessions
experience buffer allocation failures concurrently.
Add session-level retry handler `rfcomm_session_retry_handler()` to
process deferred session operations (FC_ON_REQ, FC_ON_RSP, FC_OFF_RSP,
UA_FOR_SABM, UA_FOR_DISC, DISCONN_REQ) with proper flag-based state
tracking.
Add DLC-level retry handler `rfcomm_dlc_retry()` within the tx_worker
to process deferred DLC operations (PN_REQ, PN_RSP, UA_FOR_SABM, DM)
before entering the connected state. And add DLC-level retry handler
`rfcomm_dlc_reprocess_disc()` within the tx_worker to process
deferred DLC operations (UA_FOR_DISC).
Extract send operations into dedicated functions with comprehensive
error handling:
- `rfcomm_dlc_send_pn_req()` / `rfcomm_dlc_send_pn_rsp()` for PN
- `rfcomm_dlc_send_ua_for_sabm()` for SABM response
- `rfcomm_dlc_send_dm()` for security rejection
- `rfcomm_session_send_fc_on_req()` / `rfcomm_session_send_fc_on_rsp()`
- `rfcomm_session_send_fc_off_rsp()` for flow control
- `rfcomm_session_send_ua_for_disc()` for session disconnect
- `rfcomm_session_send_ua_for_sabm()` for session connect
- `rfcomm_session_disconn_req()` for session L2CAP disconnect
Add `rfcomm_dlc_process_disc()` and `rfcomm_dlc_reprocess_disc()` to
handle DISC processing with retry support for UA response failures.
Extract `rfcomm_session_control_channel_connected()` to centralize
DLC startup logic after session establishment.
Add `BT_RFCOMM_STATE_SECURITY_FAILED` state to properly track security
rejection scenarios and enable deferred DM sending.
Reorder states in the enum to group security-related states together
before CONFIG state.
Cancel session retry_work in `rfcomm_disconnected()` cleanup path.
These changes complement the previous buffer allocation error handling
by distributing retry attempts over time, reducing contention on the
buffer pool and improving overall system stability under load.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Improve the robustness of RFCOMM flow control recovery by adding
session-level FCON retry logic and retry triggers for failed credit
and MSC operations.
Add `rfcomm_dlc_update_fc_on()` to check the flag and send FCON when
buffers become available, with proper error handling that retries
on failure.
Set `RFCOMM_SESSION_FLAG_FC_ON_REQ` in `rfcomm_dlc_connected()`. And
call `rfcomm_dlc_update_fc_on()` to send FCON.
Call `rfcomm_dlc_update_fc_on()` from `rfcomm_dlc_fc_check_and_on()` so
session-level flow control will be checked and processed in the DLC TX
processing.
Trigger TX processing at the end of `rfcomm_dlc_connected()` to ensure
the deferred FCON send happens promptly if the flag
`RFCOMM_SESSION_FLAG_FC_ON_REQ` is not cleared.
Add retry triggers in `rfcomm_dlc_fc_check_and_on()` and
`rfcomm_dlc_update_credits()` when send failures occur, ensuring the
state machine recovers quickly instead of waiting for the next DLC TX
event.
These changes refine the various handling mechanisms for buffer
allocation errors from the previous submission, ensuring that flow
control operations at both the session-level (FCON) and the DLC level
(MSC, credit-based) can recover when buffer allocation fails.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
When rfcomm_send_msc() fails in rfcomm_dlc_connected(), set the
RFCOMM_FLAG_MSC_FC_CLEAR_REQ flag to ensure the MSC command will be
retried later instead of silently dropping the failure.
This complements the buffer allocation error handling introduced in the
previous commit by ensuring the flow control state machine can recover
when the initial MSC send fails due to buffer exhaustion.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Previously, the timeout `K_FOREVER` is used to allocate the net buffer
from the TX buffer pool. It causes the BT workqueue to be blocked by
the buffer allocation operations with unpredictable completion times,
preventing subsequent work handlers from executing.
Use `K_NO_WAIT` to replace `K_FOREVER`. It means that when the buffer
allocation function returns, there's no guarantee that a buffer has
been allocated. Therefore, add comprehensive error handling for
buffer allocation failures in the RFCOMM implementation.
- Add `rfcomm_create_pdu()` to wrap `bt_l2cap_create_pdu_timeout()`,
checking both the allocation result and available tailroom
before the buffer is used.
- Check the return value of every `rfcomm_send_*()` call and
propagate allocation failures up the call stack as -ENOBUFS.
- Handle send failures in the SABM, DISC, PN, UA, DM, MSC, RLS,
RPN, TEST, FCON, FCOFF and NSC paths, logging the error and, on
the disconnect paths, rescheduling the retransmission timer
immediately so the state machine still recovers instead of
waiting on the RTX timeout.
- Extract `rfcomm_dlc_connect()` and `rfcomm_dlc_disconn()` so the
connect/disconnect error handling lives in one place instead of
being duplicated at each call site.
The change prevents workqueue stalls and crashes when the L2CAP buffer
pool is exhausted.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Add the missing const (and static, where the symbol is file-local) to
the class API vtables and the per-instance arrays of descriptor
pointers, which nothing writes after initialization.
That requires usbd_class_api::get_desc() to return "const void *". The
stack walks the result as "struct usb_desc_header *const *", so the
descriptors stay writable for the bInterfaceNumber and
bEndpointAddress patching done at init. Classes outside subsys/usb
only get the new return type here.
With the previous commit, this saves 86 to 180 bytes of RAM per class
on nrf52840dk/nrf52840, with no flash increase.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
The logMessageInterval of a received Sync message was adopted unchecked.
The value ends up as a shift count in port_timer_set_timeout(), so a
timeTransmitter announcing an out of range interval made the PTP Port
arm its sync receipt timer with a nonsensical timeout.
Reject values outside the range that can be represented. IEEE 1588-2019
Table 42 only specifies the field for multicast Sync messages, so ignore
it for unicast ones and treat the value 0x7F as not applicable instead
of adopting it.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
`NET_L2_ETHERNET` can be enabled in situations that don't require more
or larger packets than the default, for example
`WIFI && WIFI_USAGE_MODE_SCAN_ONLY`. Limit the larger defaults to
configurations that require it.
Also enable the larger defaults explicitly in the few tests that don't
use proper drivers and need the extra packets to work.
Signed-off-by: Jordan Yates <jordan@embeint.com>
Add a new API to remove a previously registered Service Record from
the SDP database. This complements bt_sdp_register_service() and
follows the same pattern as bt_l2cap_br_server_unregister().
The function checks for active SDP server L2CAP channels and returns
-EBUSY if any exist, preventing unsafe removal during active
transactions. A residual race window remains between the check and
the actual removal; the caller is responsible for ensuring no new
SDP connections are established during this call.
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
The num_services counter was only used in a single condition
(state.current_svc < num_services) within the SSA response
continuation state logic. Since record indices are assigned
sequentially from 0 and state.current_svc is always set from
record->index (which is always < num_services for any valid
record), this condition is always true — making it dead code.
Remove the variable, its increment in bt_sdp_register_service(),
and the redundant condition wrapper, unconditionally entering
dry_run mode when the packet is full.
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
Commit 1de08e0b6e ("bluetooth: mesh: dfu_cli, dfu_srv: accept SUCCESS
+ APPLYING as terminal") ended the Apply step as soon as a target
answered Success with phase Applying Update. MshDFUv1.0 Section 6.2.2.4
requires the Confirm step to wait until the targets have applied, and
that retry loop was the only thing implementing the wait. Without it the
client reads the old Current Firmware ID and Table 7.3 in Section
7.1.2.9 marks the target Apply Failed. A PTS test caught this.
Repeat Firmware Update Apply while a target reports Applying Update, as
Section 7.1.2.6 permits. Once the install completes the target answers
Wrong Phase with phase Idle, which the branch above already accepts.
Keep acknowledging the self-target: a Distributor that is also a Target
defers its own apply until the Confirm step completes, so it never
leaves Applying Update on its own.
Revert the accompanying dfu_srv change, which applied the firmware on an
unacknowledged response assuming the client would not retry. Reverting
the phase to Verification Succeeded on any send error is correct now
that it does: the retry is accepted as a fresh apply per Section
6.1.3.6.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
The parser delivers one body callback per chunk when the response
uses chunked transfer encoding, so a single receive buffer can
hold several fragments separated by the chunk framing. The client
kept the start of the first fragment and the length of the last
one and reported that as one fragment, so everything in between
was lost.
Report a pending fragment to the application before starting a
new one, so the report happens before the new fragment is counted
in processed. Propagate an abort requested from that callback the
same way as from the end of buffer report, tracking it in the
internal data rather than in the response the application sees.
Assisted-by: Claude:opus-5
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
Don't leave it up to the user to remove that address,
if programming that address to the ethernet controller
fails.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
The window fields are uint16_t but tcp_rx_window and tcp_tx_window are
int, so a buffer pool that derives 65536 wraps to zero and the stack
advertises a closed window. The Kconfig knobs are already range
limited, only the derived defaults can overflow.
Add a test that fails when the advertised window is zero, and a buffer
configuration that lands on 65536.
Signed-off-by: Grace Koo <Grace@wiznet.io>
append_u8() is only called by the non-block-wise ./well-known/core
formatting code, so building with COAP_WELL_KNOWN_BLOCK_WISE enabled
leaves it unused and fails with clang under -Wunused-function -Werror.
Move the definition into the corresponding preprocessor branch, next
to its callers.
Caught by the llvm CI build of the net.coap.wellknown_blockwise
scenario; gcc does not warn about unused static inline functions.
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
Assisted-by: Claude:claude-fable-5
RFC 7959, section 2.4, recommends that a server includes an ETag
option in each block of a Block2 response, so clients can verify that
the blocks they reassemble belong to the same representation. The
block-wise ./well-known/core response regenerates the link-format
document for every block from the live resource list, but carried no
ETag, so a representation change between blocks was undetectable.
Derive a 4-byte ETag by hashing the path segments and attributes of
the resources matching the request query, with a separator between the
two lists so a string moving between them changes the ETag. Following
the pattern LwM2M uses for its outgoing block transfers, the option is
built on sys_hash32(): COAP_WELL_KNOWN_BLOCK_WISE now implies
SYS_HASH_FUNC32, so the ETag is included by default and disabling the
hash function omits the option again.
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
Assisted-by: Claude:claude-fable-5
The block-wise ./well-known/core response used a single static block
context shared across all clients and services. Two clients running
block-wise discovery concurrently corrupted each other's transfer
position, and a transfer abandoned before its last block left stale
state behind that the next request inherited.
The response is regenerated for every block, so derive the block
context from the request alone: initialize a local context per call
and take the transfer position from the request's Block2 option. A
block size negotiated below the default is re-derived from the
request's SZX field, which the shared context previously persisted.
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
Assisted-by: Claude:claude-fable-5
When a block boundary falls inside the last attribute of a resource in
a block-wise ./well-known/core response, format_attributes() truncated
the attribute correctly but fell out of its loop and reported the
transfer as finished, so the remaining bytes were never served. The
early return that keeps the transfer going only triggered when another
attribute followed the truncated one.
Detect truncation directly: append_to_coap_pkt() advances the document
offset by the full string length unless the string was cut short by
the end of the block. This also stops reporting a spurious extra block
when a block boundary coincides with the end of the last attribute.
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
Assisted-by: Claude:claude-fable-5
The oacp_ind_handler only invoked the obj_checksum_calculated
callback when the indication contained a 32-bit checksum. Error
responses to BT_GATT_OTS_OACP_PROC_CHECKSUM_CALC omit the checksum,
so the callback was never called and the application had no way to
learn that the procedure failed.
Only parse the checksum when the result code is success, and always
invoke the callback with the result code, passing a checksum of 0 for
error responses. This matches the documented behavior of the
callback.
Assisted-by: Copilot:GPT-5.6
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
tc_init() unconditionally sets the Type-C state to TC_DISABLED_STATE
and then TC_ERROR_RECOVERY_STATE. Both descend from TC_CC_OPEN_SUPER_STATE,
whose entry action opens the CC lines. Once the board boots from VBUS
and runs tc_init(), the CC lines go to open state. To the Source that
will look like a detach, so it removes VBUS and the board powers down.
Transition directly to TC_UNATTACHED_SNK_STATE instead when the port's
Type-C Port Controller reports that it applies the dead battery
terminations, so that the Rd super state takes them over without the CC
lines ever being opened. A controller that reports no dead battery
resistors, and any build that cannot act as a Sink, keeps the previous
behaviour.
Signed-off-by: Nicholas Cadieux <ncadieux@qti.qualcomm.com>
Require the character after the mount name in CONFIG_LOG_BACKEND_FS_DIR
to be '/' or NUL, matching fs_get_mnt_point(), instead of treating any
character-wise prefix as the log volume.
Signed-off-by: Dhruv Menon <dhruvmenon1104@gmail.com>
Previously, a single static `discov` variable was used to hold the
selected discovery parameters, which would be overwritten on each call.
This could lead to issues if multiple discovery operations were queued
or in progress.
The change makes `discov` a local pointer that references the
appropriate pre-defined discovery parameter structure based on the
input shell command parameters.
The change is used to align with the refactored SDP client queue-based
request handling and ensures each discovery request maintains its own
parameter context.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>