Convert the remaining k_sched_lock() sections that guard TX-path state
to the host lock in one step: tx_processor() with get_conn_ready(),
bt_conn_data_ready() and the L2CAP raise/cancel/lower data-ready
helpers. They all mutate the bt_dev.le.conn_ready and per-connection
l2cap data-ready lists from different threads, so converting one side
alone would replace the implicit cooperative exclusion with an actual
race; converting them together makes the exclusion explicit and
correct on SMP and with preemptible callers.
The host itself never blocks under the lock: the TX processor only
performs K_NO_WAIT acquisitions. An HCI driver's send() may still block
while the lock is held, as it could while the scheduler lock was held,
which bounds the hold time by the driver's transmit time; the native
controller's synchronous re-entry of the host from send() is covered by
the mutex being recursive.
The TX pass invokes one application callback on its normal path, the
L2CAP status() notification on credit exhaustion in chan_take_credit().
It ran under the scheduler lock and runs under the host lock now, and
re-entry into the host from it is covered by the mutex being recursive;
whether it keeps a hard non-blocking contract or moves out of the TX
processor is decided with the callback contracts (#116316).
The BR/EDR L2CAP data-ready helpers, which had no serialization at all,
take the lock the same way as the LE ones.
The fatal-error recovery paths of the TX processor, where a failed
send_buf() invokes the completion callback with an error and
disconnects synchronously, run under the lock as they ran under the
scheduler lock and are left as they are: the synchronous disconnect
already cannot complete from the TX processor thread, which would wait
for a command that only it sends, and both paths are to be reworked
with the asynchronous HCI command API (#116316).
The receive path keeps its scheduler lock; it is not converted here, as
the priority receive path is to become lock-free rather than take the
host lock.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Add a recursive k_mutex to struct bt_dev, the host lock, with
bt_dev_lock()/bt_dev_unlock() helpers and a BT_DEV_LOCK_ASSERT()
ownership assertion. The lock is statically initialized because
bt_gatt_service_register() is legal before bt_enable(). It is never held
across blocking waits, and the sections converted here never hold it
across application callbacks; the priority receive path does not take
it.
Convert the k_sched_lock() sections that are independent of the TX path
to the host lock: the GATT database and service registration sections
(gatt.c), the ATT request send sections (att.c) and the ECC result
sections (ecc.c). These sections relied on cooperative scheduling for
mutual exclusion, which holds neither on SMP nor when the host is
entered from a preemptible thread; the mutex also provides priority
inheritance and survives a blocking caller. The recursive mutex is
load-bearing: the ATT send path nests the sections up to four deep.
The GATT registration/cancel and ATT request send sections keep the
scheduler lock nested inside the host lock: their RX-path counterparts
(the ATT request handlers iterating the database and att_handle_rsp()
processing the request state) do not take the host lock yet and rely on
cooperative scheduling, which excludes them only while the caller
cannot be preempted. The nesting preserves that guarantee for
preemptible callers; it goes away when those readers take the host
lock (#116316).
The ECC sections detach the registered callbacks under the lock and
invoke them without it, and the ECC request and disruption paths, which
touched the callback list, the pending state and the shared key storage
without any serialization, take the lock as well. A public key
generation runs on the preemptible long workqueue, so the disruption
path can run while one is in flight; the worker records the disruption
count when it starts and, if it has changed by the time it completes,
publishes nothing: the disruption completed the callbacks registered
with it, and any request made since has re-queued the work item.
The remaining k_sched_lock() sections (TX processor, connection and
L2CAP data-ready lists) share state across the TX path and are converted
together in a separate change.
The mutex adds 24 bytes of RAM, which no longer fits the extended
observer sample build for bbc_microbit; reduce the ISR stack in that
sample configuration to 960 bytes to make room.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
After a device-initiated Virtual Cable Unplug the initiator must
wait for the remote to tear down the L2CAP channels instead of
disconnecting them itself. The old code disconnected locally as
soon as the PDU was sent.
Change vcu_disconnect to a k_work_delayable and, on a successful send,
arm a 5S fallback timer (HID_VCU_DISCONNECT_TIMEOUT) as a safety net;
cleanup cancels it if the remote disconnects first. If the send fails,
keep disconnecting immediately since the remote may never have seen the
unplug.
Signed-off-by: Make Shi <make.shi@nxp.com>
Add support for Wi-Fi HaLow (802.11ah) frequency band Sub 1GHz
and related bandwidths (1/2/4/8MHz).
As per the 802.11ah specification, opt for S1G as the spectrum
ends at 999MHz.
Signed-off-by: Chetan Mistry <chetan.mistry@morsemicro.com>
When sending a request, modem_ubx_run_script blocks until a response
has been received or a timeout occurs. However, if no response is
expected, the function returns immediately after queuing the request
(modem_pipe_transmit is non-blocking). If modem_pipe_close is called
shortly after modem_ubx_run_script, the request may not have been
transmitted yet and is dropped (this was observed with
modem_backend_uart_async).
Make modem_ubx_run_script blocking in every case: Wait for the
MODEM_PIPE_EVENT_TRANSMIT_IDLE event to be signaled before returning
from modem_ubx_run_script if no response is expected.
Signed-off-by: Marco Widmer <marco.widmer@bytesatwork.ch>
Add PD_CTRL/DATA/EXT_MSG_COUNT enum sentinels and name lookup tables
for PD message types. Add a SEND log line, matching the existing RECV
log line, and log the human-readable message name alongside the raw
header on both SEND and RECV.
BUILD_ASSERT verifies that each lookup table remains synchronized with
its corresponding enum. The name tables are gated behind a new Kconfig
option, CONFIG_USBC_LOG_PD_MSG_NAMES, which can be disabled on
space-constrained devices.
Signed-off-by: Nicholas Cadieux <ncadieux@qti.qualcomm.com>
Ping is deprecated, so there is no need to special-case it out of the
RECV log dump. Always log the received packet content, regardless of
message type.
Signed-off-by: Nicholas Cadieux <ncadieux@qti.qualcomm.com>
Remove the `kernel log_level <module> <severity>` shell subcommand. It
has warned at runtime on every invocation since commit 8207a05304
("shell: modules: kernel_service: deprecate log_level"), first released
in Zephyr 4.1, so it is well past the two-release deprecation window.
The `log enable <severity> <module>` command from the logging command
set provides the same functionality.
The command was fully self-contained in log-level.c and registered
through KERNEL_CMD_ARG_ADD, so removing the file and its CMakeLists.txt
entry drops it entirely; no other code referenced it.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
GDB RSP packets are framed as $<payload>#<CS_hi><CS_lo>. When the
payload exceeds the receive buffer, gdb_get_packet() NACKed and
returned without consuming the two checksum bytes still in the RX
stream. Later z_gdb_getchar() calls then read those leftover bytes
instead of the expected ACK or next packet start, desynchronizing the
session.
Drain and discard the checksum before sending '-' so the stream stays
aligned with GDB framing.
Signed-off-by: Yuan Bian <bianyuan@kylinos.cn>
Always use the pe_set_data_role function to switch the datarole.
Move the notify call to this function, so that there is
always a notification when the data-role is set.
Signed-off-by: Alexander Wachter <alexander@wachter.cloud>
Add support for testing RFCOMM credit-based flow control in the SPP
shell commands.
Add new optional parameters to SPP shell commands:
- `credit_limit`: Configure custom RX credit limit per DLC
- `hold_credit`: Enable asynchronous receive completion mode
When `hold_credit` is enabled:
- Received buffers are stored in a FIFO queue
- The recv callback returns `-EINPROGRESS` to hold credits
- New `recv_complete` command allows manual completion of receive
operations to test credit refill behavior
Update all SPP shell commands (register_with_channel,
register_with_uuid, connect_by_channel, connect_by_uuid) to accept
these optional parameters for flow control testing.
Add documentation with examples demonstrating flow control testing
scenarios for both server and client roles.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Reorder function definitions in rfcomm.c to remove the declaration of
the function `rfcomm_dlc_update_credits()`.
Move `rfcomm_dlc_get_available_credits()` and
`rfcomm_dlc_update_credits()` before `rfcomm_dlc_tx_worker()` since
the worker function calls `rfcomm_dlc_update_credits()`.
Move `rfcomm_dlc_tx_worker()` and `rfcomm_dlc_connected()` before
`rfcomm_handle_sabm()` since SABM handler calls
`rfcomm_dlc_connected()`.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Add support for asynchronous receive completion to allow applications
to control when RFCOMM data reception is considered complete.
Change the `recv` callback in `bt_rfcomm_dlc_ops` to return an `int`
instead of void. Applications can now return `-EINPROGRESS` to indicate
that data processing is asynchronous and will be completed later by
calling the new `bt_rfcomm_dlc_recv_complete()` API.
When `-EINPROGRESS` is returned:
- The application takes ownership of the buffer reference
- Increment `rx_credit_inprogress` counter
- For non-CFC sessions, send MSC command with FC bit set
- RX credits are decremented immediately but not refilled until
`bt_rfcomm_dlc_recv_complete()` is called
Update all existing RFCOMM recv callbacks (HFP AG, HFP HF, GOEP, SPP
shell, etc) to return 0 to maintain current behavior.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Add support for configurable default RX credits per DLC through the
new `rx_credit_limit` field in structure `bt_rfcomm_dlc` .
Previously, all DLCs used a fixed default credit value
RFCOMM_MAX_CREDITS. This change allows applications to specify a custom
initial RX credit count for each DLC, providing better control over
credit based flow control behavior.
When `rx_credit_limit` is set to 0, the rfcomm driver uses the
internal default value. Otherwise, the specified value (the upper limit
is RFCOMM_MAX_CREDITS) is used as the maximum credit count for the
specific DLC.
Also, limit the maximum value of RFCOMM_MAX_CREDITS to 255 to avoid
overflow.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
hex2bin() returns 0 both for a malformed hex string and for a well
formed one that does not fit the destination, and the NAN argument
parsers reported either as "Invalid SSI hex string". An SSI that
exceeds CONFIG_WIFI_NAN_MAX_SSI_LEN is exactly what that option exists
to raise, so the message sent the user looking for a typo that is not
there.
Check the converted length against the buffer before calling hex2bin()
and name the limit that was hit. All four parsers carried the same
block of code, so move it into a helper rather than repeating the fix.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
bt_disable() tore down the ISO and ACL connections before resetting the
controller. The teardown returns the packets in flight to their senders
with an error, but the controller still owns those packets at that point
and keeps reporting their completion until it is reset. With an active
BIS broadcaster the Number Of Completed Packets event for such a packet
then finds the connection's pending list empty, which triggers the
"packets count mismatch" assertion in hci_num_completed_packets().
Reset the controller first, once the low-priority RX processing has been
stopped, and tear down the connections afterwards: completions reported
up to the reset are accounted for as usual, and the host only returns
what the controller no longer holds. Neither the ISO nor the connection
cleanup sends HCI commands, so they do not need the controller to be
running. A failed reset now also leaves the connections in place, in
line with the ready state it restores.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
In case due to unlucky scheduling we ended up with queued buffers either in
the HCI command or connection queues, be sure to purge those queues cleanly
in the TX processor functions.
The command queue is additionally purged by bt_disable() itself right
after it marks the transport closed, and bt_hci_cmd_send() re-checks the
transport state after queuing a command: a sender that passed the state
check just before the transport was closed either finds it closed on the
re-check and takes its command back, failing with -EHOSTDOWN, or has the
command dropped by the purge, which completes synchronous senders with an
error. Either way no command is left behind to be lost by the next
bt_enable() or sent to the next controller session.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Since the HCI command sending APIs are public, we should have a check that
the transport is actually open before attempting to queue a command for
sending. If we don't do this it'll trigger an assert due to a command
timeout, which is less friendly (and harder to debug) for users.
The public command sending APIs document the new -EHOSTDOWN return
value. The buffer parameter may be NULL, so the early return only
releases a buffer that was actually passed in.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Make a clear distinction of flags intended to protect against race
conditions related to host stack state transitions and flags intended to
indicate the current availability of the HCI transport and Bluetooth APIs
in general.
In particular, the following flags protect against state transition race
conditions: BT_DEV_ENABLING and BT_DEV_DISABLING
Whereas the following indicate the availibilty of the HCI transport and
Bluetooth APIs in general: BT_DEV_OPEN and BT_DEV_READY.
We also do an additional simplification in bt_disable() where we don't
bother doing special mapping for -ENOSYS -> -ENOTSUP since this special
error code was never documented.
The transition flags also give the enable/disable APIs a consistent
error model: -EALREADY when the requested transition is already in
progress or complete, and -EAGAIN when the opposite transition is in
progress, i.e. bt_disable() before an asynchronous bt_enable() has
completed, or bt_enable() while bt_disable() is still running. Both
APIs now document their return values.
The transition flags are kept across the flag reset performed when an
HCI_Reset completes, which happens both during initialization and in
bt_disable(): clearing ENABLING there would prevent bt_finalize_init()
from ever setting READY, and clearing DISABLING would end the RX
teardown early. The RX teardown predicate that main gained in the
meantime is converted to the DISABLING flag as part of the rebase.
The k_work_busy_get() check that bt_disable() gained for the
asynchronous bt_enable() case is replaced by the ENABLING flag, which
covers that case together with a synchronous bt_enable() running in
another thread.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
PTP port timers expire in interrupt context, while eventfd writes
acquire the file descriptor mutex. Defer timeout notifications to the
system workqueue so eventfd signaling runs from thread context.
Keep timeout bits in the ports as the source of pending events, allowing
multiple timer expiries to share a queued wakeup. Add coverage that
verifies the timeout path submits work before writing the eventfd.
Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
settings_file_save_and_compress() stored -EIO on a failed fs_close()
but then returned 0, so settings_save() reported success after a
failed compress. Unlink the leftover .cmp file when the original
settings file closed successfully, matching the rollback path.
Signed-off-by: Dhruv Menon <dhruvmenon1104@gmail.com>
Use controller/peripheral and SDO/SDI terminology in the MCUmgr SMP
SPI transport, following coding guideline rule A.2: switch to
SPI_OP_MODE_PERIPHERAL and the SPI_PERIPHERAL Kconfig dependency,
and update the transport test configuration and its bitbang overlay
to CONFIG_SPI_PERIPHERAL and the sdo-gpios/sdi-gpios properties.
Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Use controller/peripheral and SDO/SDI terminology in the remaining
SPI-using drivers (audio, auxdisplay, bluetooth HCI, dac, eeprom,
ethernet, flash, fpga, gpio, haptics, hdlc_rcp_if, ieee802154,
input, led, led_strip, lora, mfd, misc, mux, rtc, sdhc, stepper,
video, watchdog, wifi) and the ec_host_cmd SPI STM32 backend,
following coding guideline rule A.2: switch to
SPI_OP_MODE_CONTROLLER/PERIPHERAL and SPI_SDO_OVERRUN_DT, rename
Zephyr-owned identifiers (the HCI SPI header buffers, the winc1500
bus wrapper transfer parameters), and update comments, log messages
and Kconfig help prose.
Vendor and out-of-scope identifiers keep their names: STM32
LL_SPI_MODE_SLAVE in the ec_host_cmd backend, the ATWINC1500 SDK I2C
SLAVE_ADDRESS definition, and the I2S codec clock-role variable in
tlv320aic26.
Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Two-line copyright notices were wrapped in the SPDX "<text>...</text>"
construct, which is only valid in an SPDX document, not a file header.
The REUSE tool then folds the literal "<text>" into the holder name
and drops the second line from the SBOM.
Remove the markers and tag the continuation line. Holder, year and
e-mail are left unchanged; only the syntax is fixed.
Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
The maximum length of an attribute value is 512 octets (Core
Specification Vol 3, Part F, Section 3.2.9), but the GATT client
delivered notification and indication values of any length permitted by
the ATT MTU to subscribe callbacks. Subscribers that size their buffers
according to the specification limit can then be handed more data than
they have room for.
Drop notifications, indications and multiple handle value notification
tuples whose value is larger than BT_ATT_MAX_ATTRIBUTE_LEN before
delivering them. The remaining tuples of a multiple handle value
notification are still delivered, and oversized indications are still
confirmed, since the confirmation only acknowledges receipt of the PDU.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Fix several concurrency issues in the ZMS locking.
- zms_mount() re-initialized fs->zms_lock on every mount. Since a
re-mount is required after zms_clear(), remounting while another
thread still holds (or is waiting on) the mutex would reset its
owner, lock count and wait queue, silently discarding the lock and
breaking mutual exclusion. The mutex is now initialized only once,
tracked by a new fs->lock_initialized flag that survives a
clear/re-mount cycle.
- zms_read_hist() walked the ATEs and read the data without holding
the mutex. A concurrent zms_write() in another thread could trigger
garbage collection, which relocates ATEs and their data and updates
fs->ate_wra. The read could then follow stale addresses and fail
(-ENOENT/-EIO) or return corrupted data. The lookup and data read
are now performed under fs->zms_lock.
- zms_write() searched for and compared against the latest entry with
the same ID (the CONFIG_ZMS_NO_DOUBLE_WRITE path) before taking the
lock, reading fs->ate_wra and walking the ATEs unlocked. A concurrent
write could trigger garbage collection and relocate the ATE being
inspected, leading to a wrong comparison or a read of a stale address.
The lock is now taken before that block so the lookup, the "already
stored" check and the write itself are atomic with respect to other
writers.
Signed-off-by: Riadh Ghaddab <riadh.ghaddab@nordicsemi.no>
bt_sdp_discover_cancel() has been declared in sdp.h since the SDP
client API was introduced, but no implementation has ever existed: any
caller would fail to link. Without it, a profile that queues a
discovery and then hits an error on an unrelated path has no way to
take the request back, and must keep the discovery parameters object
alive and its callback armed until the discovery machinery gets around
to it.
Implement the semantics the declaration documents: a waiting request,
i.e. one queued with bt_sdp_discover() whose resolution has not yet
started, is removed from the session and its callback will not be
called. The request currently being resolved cannot be canceled
cleanly - its request PDU is out and the response may already be under
processing - so canceling it is refused with -EINPROGRESS and the
callback still fires. Requests parked for the next session round
(reqs_next) are canceled the same way as waiting ones.
The declaration took the parameters object as const, but canceling
inherently modifies it: the request node is unlinked from the
session's list. Drop the const qualifier rather than casting it away
in the implementation. Since the function never had an implementation,
no existing caller can be affected by the signature change.
For the "callback will not be called" guarantee to hold, the places
that take a request off the waiting list and act on it must do so
under the session lock so that they cannot race with the removal:
- sdp_client_discover() now marks the selected request active
(session->param) while still holding the lock, rather than after
releasing it in the per-type send functions.
- sdp_client_params_iterator() now holds the lock across the removal
of the completed request instead of only taking it afterwards.
- sdp_client_disconnected() now pops each request under the lock
before invoking its callback, instead of iterating the list
unlocked.
sdp_client_alloc_buf() additionally needs to handle an empty request
list, which can now happen when every queued request is canceled while
the channel is still being established. Returning NULL there makes
sdp_client_connected() disconnect the no-longer-needed channel; the
previous code dereferenced the head of the list unconditionally.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
When all IPv4 reassembly slots are in use, net_ipv4_handle_fragment_hdr()
drops the incoming fragments and logged this as an error. Running out of
reassembly slots under fragment-heavy load is expected behaviour, not a
fault (the sender retransmits, communication is not lost). So under heavy
load, this logging produced a flood of error messages for a recoverable
condition.
Lower the message from LOG_ERR to LOG_DBG to match the equivalent IPv6
path in ipv6_fragment.c, which already logs the same "Cannot get
reassembly slot" situation at debug level.
Signed-off-by: Raluca Bozdog <raluca.bozdog@analog.com>
bt_le_scan_start() sets up the explicit scan parameters and the scan
callback with scan_explicit_params_mutex held, but bt_le_scan_stop()
clears the callback and removes the scanner user without taking it, so
a stop running concurrently with a start can tear down the state the
start is in the middle of setting up.
Take the same lock in bt_le_scan_stop(). As in bt_le_scan_start(), the
lock is taken without waiting, so that a stop from the Bluetooth
workqueue cannot block on a start that is waiting for a command
completion.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
bt_settings_store_id() and bt_settings_store_irk() defer the actual
settings write to a work item that reads bt_dev.id_addr/bt_dev.irk with
a length derived from bt_dev.id_count at execution time.
bt_disable() resets bt_dev.id_count without waiting for those work
items. If a store is still pending at that point, the handler later
computes a zero-length record and persists an empty "bt/id" or
"bt/irk" entry, erasing the identity stored in the settings backend.
If the handler is mid-execution, it can read the identity data while
it is being reset, persisting a torn record.
Simply canceling the work items would trade one bug for another: an
identity created or updated shortly before bt_disable() would silently
never reach the settings backend, and a later bt_enable() would load
stale identity data. Instead, add bt_settings_flush(), which completes
any pending stores while the identity state is still valid, and call
it from bt_disable() before the identity state is reset.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
In timestamp_print(), when using the default format with
CONFIG_LOG_TIMESTAMP_64BIT, the seconds variable could
be truncated when assigned total_seconds.
Drop the intermediate seconds variable and use a uint64_t
hours with %llu format when CONFIG_LOG_TIMESTAMP_64BIT=y.
Tested by test_format_ts_64test_format_ts_64.
Signed-off-by: Yiren Guo <guoyr_2013@hotmail.com>
bt_avdtp_connect() sets session->br_chan.chan.conn before calling
bt_l2cap_chan_connect() in order to detect simultaneous local and
remote AVDTP signaling connection attempts. If bt_l2cap_chan_connect()
fails before the channel has been added to the connection, for example
with -ENOTCONN when the ACL is no longer connected, or through one of
the early argument and state checks in bt_l2cap_br_chan_connect(), no
disconnected callback will ever run for the channel and the marker is
never cleared. a2dp_get_connection() treats a non-NULL marker as a
session in use, so every subsequent bt_a2dp_connect() for that
connection index fails with -ENOMEM, including attempts on future ACL
connections that reuse the same connection object.
Clear the marker on the error path of bt_l2cap_chan_connect(), holding
avdtp_sem_lock like the other accesses to the marker. It is only
cleared if it still holds the value set above, since a failure that
occurs after the channel was added to the connection has already
cleared it in bt_l2cap_br_chan_del().
The accept side sets the same marker in bt_avdtp_l2cap_accept(), but
there the L2CAP server code owns the channel lifecycle after accept
returns and deletes the channel with bt_l2cap_br_chan_del() on the
failure paths, which clears the marker.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
a2dp_get_connection() wipes the whole bt_a2dp object, including the
embedded AVDTP session, with memset() when the object is not currently
associated with a connection. The session's _release_work, submitted
from bt_avdtp_l2cap_disconnected(), may still be queued at that point,
and wiping a queued work item corrupts the work queue's pending list.
Skip the reuse and return NULL while the release work is still
pending, mirroring the check on the AVDTP side in the preceding
commit. Both callers already handle a NULL return by rejecting the
connection attempt, which can be retried once the release work has
completed.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
bt_avdtp_l2cap_disconnected() submits session->_release_work to defer
the release of the session's endpoints. Both bt_avdtp_connect() and
bt_avdtp_l2cap_accept() unconditionally k_work_init() the same work
item when the session object is reused for a new connection.
Re-initializing a work item that is still queued corrupts the work
queue's pending list.
The work item cannot simply be canceled on reuse, since the deferred
endpoint release must always run. Instead, reject the session reuse
with an error while the release work is still pending; the connection
can be retried once the work has completed. The check is done under
avdtp_sem_lock, and since the session has no L2CAP connection at that
point, no new submission of the work can race with it.
A similar lifecycle issue with session->timeout_work being
re-initialized while potentially still scheduled is being addressed
separately.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
If the connection drops in the middle of reassembling a fragmented
vendor dependent response, ct->reassembly_buf is left referenced. The
buffer is only reclaimed if the same connection index later starts a
new reassembly, so in the meantime such disconnections can exhaust the
RX pool, which is only CONFIG_BT_MAX_CONN deep.
Drop the reassembly buffer on disconnection. This is the same class of
issue as the TG vendor response TX state fixed in the preceding
commit.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
avrcp_disconnected() neither cancels tg->vd_rsp_tx_work nor releases
the buffers queued in tg->vd_rsp_tx_pending. If the connection drops
in the middle of a fragmented vendor dependent response, the pending
buffer, from a pool that is only CONFIG_BT_MAX_CONN deep, is leaked
with its TX_ONGOING flag still set in the buffer user data. Since the
TG object is selected by connection index, a new connection on the
same index finds the stale buffer at the head of the pending list, and
the TX state machine remains permanently stalled with any new
responses queued behind the stale head and never sent.
Cancel the TX work and release all queued TX buffers on disconnection.
The per-buffer TX context, including the TX_ONGOING flag, lives in the
buffer user data, so releasing the buffers also resets the TX state.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Some MACs utilize ingress filters to discard packets whose DMAC does not
match that programmed into the block itself. When used with DSA, where
each user port has a MAC that differs from that of the conduit, such
MACs end up unconditionally filtering out the packet.
Add a new config option named DSA_CONDUIT_PROMISC_ON which, if set,
enables promiscuous mode on all DSA conduits during Ethernet
initialization. Since the vast majority of Ethernet drivers require
this, the option defaults to y. Systems that do not require promiscuous
mode on conduit ports may disable the option manually.
Note that enabling promiscuous mode is possible only once the
ethernet_l2_flags field in the struct ethernet_context has been
populated, hence why this is placed in dsa_ethernet_init rather than
dsa_port_initialize.
Signed-off-by: Vilhelm Engström <vilhelm.engstrom@tuta.io>
If the work dealing with the RX packet is cancelled while it is running,
there's a chance that the packet will be freed under its foot. Use
`k_work_cancel_sync` to wait the work to finish before freeing the
packet.
Assisted-by: Claude:claude-opus-4.8
Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
Updated the coredump logging backend to ensure that LOG_PROCESS()
is not called before LOG_PANIC(). This change prevents buffered
messages from being delivered while backends are still in normal
mode, aligning the logging behavior with the intended panic
notification flow.
Signed-off-by: Dhruv Menon <dhruvmenon1104@gmail.com>
Since this a "get" function that does not, and never should,
modify the provided advertising set pointer, modify it to be
const.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
smp_rx_remove_invalid() used a k_fifo living on its stack as a scratch
queue while filtering buffers. Kernel object tracking
(CONFIG_OBJ_CORE_FIFO, object tracking) registers FIFOs passed to
k_fifo_init(), leaving the tracking lists referencing dead memory once
the function returns.
Use a plain sys_slist_t with the net_buf slist helpers instead; the
scratch queue never blocks and is fully drained before returning.
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
Assisted-by: Claude:claude-fable-5
EAP-PEAP-GTC was added to the list of security types that support
optional peer certificate verification. Update the wifi_shell help
text to reflect this.
Assisted-by: WChat:Claude
Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
This commit adds a bounds check to log_output_timestamp_freq_set and
log_output_timestamp_to_us to prevent a fatal divide-by-zero hardware
exception when frequency is 0.
Signed-off-by: harshit kudhial <harshitkudhial@gmail.com>
off variable is always set in K_SPINLOCK block but still strict compiler
may complain about potential use of uninitilized variable.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
Use S8 flags when setting up Coded PHY reception.
This keeps receive timing consistent with other coded RX setup paths.
Pass selected advertising PHY flags to coded TX delay calculations.
This avoids treating S2/S8 selection as unused during delay setup.
Use unsigned zero literals for the zero-valued PHY macros.
Document the RX/TX coding flag choice in advertising paths.
Signed-off-by: Daniel Polimac <danielpolimac@gmail.com>
Replace literal Coded-PHY flags with the named S2 and S8 constants
throughout the Nordic and OpenISA controller paths.
Part of #37458
Signed-off-by: Daniel Polimac <danielpolimac@gmail.com>
Do not require the ETHERNET_HW_FILTERING capability for tracking the L2
multicast addresses of an interface. The documentation of
net_eth_mcast_addr_add() states that "a device that has no receive
filter passes the group up anyway, so the group is joined in that case
too", but ethernet_mcast_ctx() returned NULL for such a device, making
the join fail with -ENOTSUP instead.
Programming the filter already handles this case:
ethernet_mcast_filter_set() returns -ENOTSUP when the capability is
missing, which net_eth_mcast_addr_add() treats as "nothing to program"
rather than as a failure to join.
Signed-off-by: Fin Maaß <info@finmaass.de>
Write settings in chunks and introduce a configurable delay between write
operations to prevent prolonged CPU stalls during storage updates.
Signed-off-by: Tahsin Mutlugun <Tahsin.Mutlugun@analog.com>