CONFIG_NET_SOCKETS_SERVICE_STACK_SIZE already bumps its default to
2048 when NET_ZPERF_IPERF3 && NET_ZPERF_SERVER are both set, but
zperf's plain (non-IPERF3) TCP download server drives the exact same
socket-service dispatch thread and was left at the 1200-byte generic
default.
Reproduced on a real ESP32-S3 devkit: with CONFIG_NET_ZPERF_SERVER=y
and CONFIG_NET_ZPERF_IPERF3 unset, running `zperf tcp download` and
pushing 3 concurrent real TCP connections at it (plain iperf2 client,
no TLS) pegs net_socket_service's stack at 1200/1200 bytes used, 0
bytes unused -- a confirmed, repeatable zero-margin condition, not a
worst-case estimate. Bumping the stack to 2048 (matching the existing
IPERF3 case) and repeating the identical test leaves a comfortable
816 bytes free at the same peak usage (~1230 bytes), confirming both
the fix and that the actual code path depth doesn't depend on which
zperf protocol variant is in use.
Scope the existing default to any NET_ZPERF_SERVER build instead of
just the IPERF3 one, since both variants poll sockets through the
same thread and the deeper of the two call paths isn't IPERF3-
specific.
Assisted-by: Claude:claude-sonnet-5
Signed-off-by: Henry Zhang <henryzhang62@gmail.com>
When allocating or enqueuing the response-ready interrupt IN buffer
fails in ec_host_cmd_backend_send(), the error messages refer to an
"INT OUT" endpoint, and the allocation failure log prints ret, which is
always 0 from the preceding bulk IN enqueue. Fix both messages to refer
to the IN INT endpoint, matching ec_host_cmd_signal_event().
Signed-off-by: Firas Sammoura <fsammoura@google.com>
ec_host_cmd_signal_event() allocates the interrupt IN buffer with
net_buf_alloc() via ec_host_cmd_buf_alloc_int(), and frees it with
usbd_ep_buf_free() if usbd_ep_enqueue() fails. Because the buffer was
never queued to the USB stack, release it with net_buf_unref() instead,
matching the other usbd_ep_enqueue() failure paths in this file, and
drop the unused uds_ctx variable.
Signed-off-by: Firas Sammoura <fsammoura@google.com>
net_icmpv4_send_error() must not send an error about an ICMP error
message. The check read the ICMP header with net_pkt_get_data() at
the start of the packet without moving the cursor past the IPv4
header, so it compared the TOS byte against 8 instead of looking at
the ICMP type. With TOS 0 no error was ever sent about an ICMP
datagram, and with a non-zero DSCP an error was sent about ICMP
error messages, which RFC 1122 section 3.2.2 forbids.
Skip the IPv4 header including its options, read the ICMP type and
suppress the error only for the error message types listed in
RFC 1122 section 3.2.2: Destination Unreachable, Source Quench,
Redirect, Time Exceeded and Parameter Problem. Errors about ICMP
query messages such as Echo Request are allowed. If the datagram is
too short to hold the ICMP type, no error is sent.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
A raw IPv4 socket sends the header supplied by the application. The
header length from that header was used for the options length without
checking it against the amount of data written, and a header length
below 20 bytes was sent unchanged.
Fail the send with -EINVAL when the header length is shorter than the
fixed IPv4 header or longer than the data, as other raw socket
implementations do.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
net_calc_chksum_ipv4() summed the IPv4 header and options straight from
the first buffer of the packet. It did not check that the first buffer
holds that many bytes, so when the options continue in the next buffer
or the header length is larger than the packet, the sum included bytes
past the end of the buffer data.
Sum the header from the first buffer when it is all there, which is the
common case, and walk the buffer chain otherwise. Return -EINVAL when
the packet is shorter than the header. All callers already handle an
error return.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
net_ipv4_input() checked that the header length is at least 20 bytes
and that the total length fits in the received data, but not that the
total length covers the header length. A datagram with a total length
of 20 and a header length of 60 was trimmed to 20 bytes, and the header
checksum check and the forwarding TTL update then summed 40 bytes that
are no longer part of the packet. Such a datagram was also forwarded.
RFC 1812 section 5.2.2 requires the total length to be large enough to
hold the header and the datagram to be discarded otherwise. Drop it
before anything reads the header options.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The tools array of a tools/list response was built in a fixed 1024-byte
buffer, so a server with more than a few tools (with descriptions and
input schemas) failed with "Buffer overflow adding tool" whatever
CONFIG_MCP_MAX_MESSAGE_SIZE was. Size it from CONFIG_MCP_MAX_MESSAGE_SIZE,
which bounds the whole response anyway. The structure still fits a block
of the large slab.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5.5
With BT_TICKER_EXT_EXPIRE_INFO, periodic advertising and remainder
support, the aux ticker callback computes the SyncInfo offset by
converting its own remainder with hal_ticker_add_jitter(), which
rewrites the remainder in place from the ticker's unit to microseconds.
The same variable is then passed to the aux prepare as p.remainder,
where the LLL reads it in the ticker's unit (radio_tmr_start() on
Nordic converts it with hal_ticker_remove_jitter()). The aux event
therefore starts without its sub-tick part: up to one ticker tick late
against the AuxPtr the primary channel PDUs announce, as a sawtooth
that follows the aux ticker's remainder.
Convert a copy for the SyncInfo offset and pass the remainder unchanged.
With the AuxPtr timing check added to the advx ticker expire info test
on nrf52_bsim/native: without this fix 105 of 480 auxiliary packets of
a set with periodic advertising start outside the window the AuxPtr
allows; with it, none.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Kent Hauser <kent@khauser.net>
Revive https://github.com/zephyrproject-rtos/zephyr/pull/113182
Building getentropy() when there is no configured entropy device and
the architecture does not provide an entropy source
lead to a missing device link error.
In that case, getentropy() should shortcircuit out.
Signed-off-by: Tom Burdick <thomas.burdick@infineon.com>
The volatile backend stores only the pointer passed to
tls_credential_add() and does not copy the data. Document that the
buffer must stay valid while the tag is in use, in the API description
and in the backend Kconfig help.
Assisted-by: Claude:claude-sonnet-5.5
Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
A completed request is sent as a header followed by its data. With
Nagle's algorithm, the data is held until the header is acknowledged,
and a client that delays its acknowledgment cannot complete the URB
without the data meanwhile. The endpoint is then polled again only that
much later, which can be too late for a device with a small buffer,
such as a serial converter.
Set TCP_NODELAY on accepted connections.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5.5
Use defines for the ticker node state values, i.e. the difference of
the node's req and ack counts, instead of numeric literals.
No functional change.
Assisted-by: Cursor:Claude Opus 5.5
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Defer ticker yield_abs operation on an expired ticker node until
the ticker job bottom half has processed the expiry.
The bottom half assigns the expired node's slot reservation, hence
a yield applied before it is lost and the full slot remains
reserved. Auxiliary PDU reception tickers started in the yielded
time space are then skipped as collisions, and the scan aux context
is flushed without receiving the auxiliary PDUs.
This happens when ULL_LOW has lower priority than ULL_HIGH and the
ticker job is delayed beyond the ULL_HIGH processing of the PDU
received in the expired ticker's radio event.
Assisted-by: Cursor:Claude Opus 5.5
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Fix ticker_job_list_inquire() to traverse the user operation queue
only up to the operations that ticker_job_list_manage() and
ticker_job_list_insert() have processed, i.e. up to user->middle.
When ticker job executes in a lower priority than a ticker user,
the user can preempt the ticker job and enqueue new operations after
the list manage step. The inquire step traversing up to user->last
then consumed these operations without processing them. A ticker
start was hence never inserted nor its operation callback invoked,
as observed for the scan auxiliary PDU reception ticker started in
ULL_HIGH while ticker job in a lower priority ULL_LOW was preempted,
leaking the scan aux context.
Assisted-by: Cursor:Claude Opus 5.5
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
If a ethernet controller supports checksum offloading,
and requires that the checksum in the packet is zeroed
before, that should be done in the ethernet driver and
not here in the openthread boarder router code.
Also this implementation is specific for the nxp_enet,
other controllers like the Synopsys ones don't need this
done for udp and tcp.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
prov_link_close() set link.tx.timeout to CLOSING_TIMEOUT (3 s). On the
device side reset_adv_link() does not reset this field, and
provisionee.c does not re-accept the PB-ADV bearer after a PB-ADV link
closes, so prov_link_accept() never restores TRANSACTION_TIMEOUT. After
one device-initiated close (transaction or protocol timeout), every
transaction on later PB-ADV links was abandoned after 3 s instead of
the 30 s acknowledgment timer required by MshPRT v1.1, section 5.3.3,
until reboot.
Since commit 534177b2ca ("Bluetooth: Mesh: Fix regression in PB-ADV")
Link Close is sent as an unacked PDU repeated
CONFIG_BT_MESH_PB_ADV_LINK_CLOSE_RETRANSMIT_COUNT times, so the closing
timeout is no longer read while closing. Remove the assignment and the
unused CLOSING_TIMEOUT define.
Assisted-by: Claude:claude-opus-5.5
Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
A late OFFER with the current transaction ID can replace the gateway,
selected server, DNS and lease parameters in REQUESTING or BOUND,
because option parsing happens before the state handlers reject it.
An ignored NAK or duplicate ACK can also change lease configuration.
Read the message type without applying options or invoking callbacks,
then check the existing reply acceptance rules under the DHCP mutex.
Only parse options with side effects after accepting the reply for the
current state. Preserve NAK handling in INIT-REBOOT, where the client
may not have a selected server yet.
Scan the complete option list so the message type can follow other
options, and reject missing, duplicate or malformed message types.
Extend the existing DHCP client tests with late offers with and without
a router in REQUESTING and BOUND, a NAK from another server, and
duplicate ACK/NAK replies in BOUND. Deliver them through the real DHCP
connection and verify that lease configuration and state are unchanged.
Assisted-by: Codex:gpt-6
Signed-off-by: Dmitrii Sidin <rus084@bk.ru>
With CONFIG_NO_OPTIMIZATIONS=y on 32-bit Arm, the TX processor
overflows its 1024-byte default stack in bt_enable(), and the Bluetooth
workqueue its 1200 bytes once a connection is established. The long
workqueue already has a NO_OPTIMIZATIONS default; these two do not.
Unoptimized peaks, optimized in parentheses: TX processor 1168 (404) in
tests/bluetooth/host_disable on qemu_cortex_m3 and 1320 (392) in
samples/bluetooth/peripheral_hr on nrf52dk/nrf52832; Bluetooth
workqueue 2192 (856) in peripheral_hr with pairing and notifications.
Default to 2048 and 4096 bytes, the latter as for the long workqueue.
ARM64 keeps its values and BT_HCI_RAW its 768.
Tested with stack overflow detection only: host_disable on
qemu_cortex_m3 and mps2/an385 and peripheral_hr on nrf52dk overflow
without this change and run with it, with the main, system workqueue
and test helper stacks raised, and on nrf52dk the Controller's RX
thread stacks as well. Optimized .config files are unchanged.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
randomize_bt_addr() was an empty stub whose TODO stated that the AdvA
could not be refreshed. Remove it and its call in enc_id_adv().
Private Network Identity and Private Node Identity advertising
regenerates the Random field before every advertising start, and
starts the advertiser with BT_LE_ADV_OPT_USE_NRPA, for which the host
generates a new NRPA on every start with both legacy and extended
advertising. This already meets MshPRTv1.1 sections 7.2.2.2.4 and
7.2.2.2.5, which require the AdvA to be regenerated whenever the
Random field is regenerated.
The comment in enc_id_adv() now documents where the AdvA comes from.
Assisted-by: Copilot:claude-opus-4.7
Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
The raw and Linux-style timestamps print a 32-bit log_timestamp_t
(uint32_t is unsigned int on every Zephyr target) with %lu. On 64-bit
targets that reads an unsigned long the caller never passed. RV64 keeps
32-bit values sign-extended in registers, so once k_cycle_get_32()
passes 2^31 (about 215 s on qemu_riscv64) a raw timestamp of
2147483648 prints as 18446744071562067968, 20 digits wide.
Use %u for the 32-bit values, and mark print_formatted() with
__printf_like() so the compiler checks every format string in the file.
That check reports exactly these two lines and nothing else.
Signed-off-by: harshit kudhial <harshitkudhial@gmail.com>
pkt_alloc_buffer() first asks the pool for each fragment without
waiting and only blocks when the pool is empty, so that the common path
does not read the clock. The deadline for those waits was still taken
on entry, though, and sys_timepoint_calc() reads the clock for every
relative timeout. So every packet allocated with a timeout still paid
for one clock read, although no allocation waited.
Take the deadline the first time an allocation has to wait instead.
All later waits in the same call are still measured against that one
deadline. A call can now take longer than the timeout by the time the
non-blocking allocations before the first wait took, which do not
block.
On the zperf loopback self-test under QEMU icount, which measures
instructions per payload byte, throughput went up by 1.1 to 1.5% on
qemu_x86 and 0.6 to 1.0% on qemu_x86_64, for both UDP and TCP.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The recv() callback of a periodic advertising sync is documented to get
a NULL buffer when the Controller failed to receive a subevent of
Periodic Advertising with Responses. The Host did this only with
CONFIG_BT_PER_ADV_SYNC_BUF_SIZE > 0, so with the default size of 0 the
application never learned about a failed subevent.
Handle the failed subevent before reassembly, as it carries no data.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
IPv4 source selection can choose an address from 127/8 for a
non-loopback destination when it has the longest matching prefix.
Exclude loopback sources for external unicast destinations. Preserve
selection for loopback destinations and for an unspecified destination,
which is used to choose an interface when binding a wildcard socket.
Also preserve multicast explicitly scoped to an interface, without
selecting loopback during an unscoped multicast address scan.
Exclude loopback entries from global address lookup and continue
searching for a non-loopback address. This also prevents the source
selection fallback from reintroducing a loopback source. Document the
exclusion alongside the existing link-local exclusion.
net_if_ipv4_get_global_addr() no longer returns an address from 127/8.
The connection manager uses it to determine IPv4 connectivity, so the
loopback interface no longer counts as connected. A system with only
the loopback interface therefore does not report NET_EVENT_L4_CONNECTED.
An SSH server configured to bind to the loopback interface address now
fails to start with -EINVAL, as that interface has no global address.
Extend the existing IP address tests to cover global address lookup,
source and interface selection, scoped and unscoped multicast,
wildcard binding, and loopback destinations.
Assisted-by: Codex:gpt-6
Signed-off-by: Dmitrii Sidin <rus084@bk.ru>
The ATT code reads and writes the fields of the embedded LE L2CAP
channel directly in about 50 places: the RX/TX MTU, the TX CID, the
connection and the generic channel object. Several of these go
through BT_L2CAP_LE_CHAN() only to print the CID or fetch the
connection.
Add small static accessors for the channel, connection, TX CID and
RX/TX MTU, and use them everywhere except the fixed channel send in
chan_send(), which is LE specific. This keeps knowledge of the bearer
channel type in one place so a bearer that is not an LE channel can
be added without touching the protocol handlers.
No functional change. Built for native_sim (tests/bluetooth/shell,
tests/bluetooth/init) and ran the ATT, GATT and L2CAP ECRED bsim
tests on nrf52_bsim.
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
rpa_timeout() stops the RPA timer when no advertiser, initiator or
active scanner uses the RPA, but only with CONFIG_BT_CENTRAL. In other
builds the timer runs, and the Host regenerates the RPA, for as long as
Bluetooth is enabled, so that advertising sets keep getting the
rpa_expired callback while inactive (see #118322).
An Observer-only build has no advertising sets, and a passive scanner
does not send its address, so it gains nothing from the timer. Stop it
there too. The next active scan creates a new RPA, which restarts the
timer.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Aric Radzin <aric.radzin@gmail.com>
CONFIG_BT_PRIVACY was defined inside the BT_SMP block, which is inside
the BT_CONN block, so Broadcaster- and Observer-only builds could not
enable it. Setting it there only gave a Kconfig warning, and such builds
by default advertised and actively scanned with an NRPA that the Host
did not rotate. GAP defines the privacy feature for these roles without
bonding (Core v6.3, Vol 3, Part C, Table 10.3), and generating RPAs
does not need SMP.
Move CONFIG_BT_PRIVACY and its sub-options out of both blocks. It
depends on BT_BROADCASTER or BT_OBSERVER, and still on BT_SMP when
BT_CONN is enabled, since Table 10.3 makes bonding mandatory for a
Peripheral or Central that supports privacy. It selects BT_RPA for
bt_rpa_create(), which so far only BT_SMP selected.
Without SMP there are no peer keys, so bt_id_reset_irk() skips the bond
check, and bt_addr_le_rpa_resolve(), which looks them up, is only built
with SMP. bt_rpa_irk_matches() is also built with privacy, as the
host_id tests check the generated RPAs with it.
The bluetooth.host_id.privacy.no_smp test now builds with privacy and
runs the IRK tests.
Fixes#122737
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Aric Radzin <aric.radzin@gmail.com>
bt_setup_public_id_addr() and bt_setup_random_id_addr() derive the
identity IRK from the IR with bt_smp_irk_get(). It is defined in smp.c,
which is only built with CONFIG_BT_SMP, and nothing else uses it.
The derivation only needs AES, which privacy already needs to generate
RPAs. Move it to id.c as irk_from_ir() so that it builds without SMP.
No functional change.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Aric Radzin <aric.radzin@gmail.com>
Previously, redrawing the prompt after log output, hitting Ctrl-L, or
cycling through the history using Up/Down or Ctrl-P/Ctrl-N in the shell
would print the user command input regardless of the obscured input
setting.
This can expose e.g. entered login information.
Therefore, z_shell_print_cmd now only prints '*' when the obscure flag is
active.
Signed-off-by: Nils Ruf <nils.ruf@endress.com>
mmc_set_hs_timing() switches the card and the host to high speed but
leaves card->card_speed alone, and nothing else sets MMC_HS_TIMING.
When high speed is the fastest timing the card and the host share,
card_speed stays at MMC_LEGACY_TIMING: the MMC stack test reports
"Card timing: Legacy MMC" for a card that runs at 52 MHz.
Record MMC_HS_TIMING once the host follows the card to high speed.
HS200 and HS400 still overwrite it after their own switch.
Signed-off-by: Piter Zhang <zhangtdvip@163.com>
The echo API is used for qualification testing, through the tester and
the shell, and has no other known user. Make it available only with
CONFIG_BT_TESTING, like the other APIs needed only for testing. Echo
Requests are still answered in other builds, by the stack.
Update the shell, whose echo commands now need CONFIG_BT_TESTING and are
built by a new scenario, the tests and the documentation, and describe
the change in the migration guide.
Assisted-by: Kiro:claude-opus-5.5
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
Since the echo API was added, a received Echo Request has only been
answered by a registered req callback calling bt_l2cap_br_echo_rsp().
Without such a callback, which is the case for most applications, the
request was left unanswered, while an L2CAP entity shall respond to a
valid Echo Request with an Echo Response (Core 6.3, Vol 3, Part A,
4.8).
Answer the Echo Request with an Echo Response without data when no req
callback is registered, which the response may carry (Core 6.3, Vol 3,
Part A, 4.9). As for the other responses the stack sends, reserve the
buffer for it before the request is processed, so that a request
received while no buffer is available is kept and processed again
later instead of being dropped.
Assisted-by: Kiro:claude-opus-5.5
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
The Echo Request used the signaling channel identifier and RTX timer,
which also track the Information Request. This had several effects:
- bt_l2cap_br_echo_req() returned -EBUSY while an Information Request
was outstanding, such as right after the ACL connection is made.
- An Information Response arriving after its request timed out, while
an Echo Request was outstanding, cleared the Echo Request identifier,
so the Echo Response was dropped.
- An Echo Response with a mismatching identifier ended the outstanding
Echo Request, so the matching response was dropped.
- A Command Reject for the Echo Request was taken as one for a dynamic
channel and disconnected the signaling channel.
- The echo RTX timer was not canceled on disconnection.
Keep the Echo Request identifier and RTX timer in the signaling context.
Ignore Echo Responses that do not match the outstanding request, end
the request on a matching Command Reject, and cancel the timer when the
signaling channel is disconnected. The identifier is cleared before the
response callbacks run, so they can send the next request, and the RTX
timer is started before the request is sent, so that a response that
comes before the send returns cancels it.
Update the test that set the signaling channel identifier to stand for
an outstanding Echo Request, so that it sends an Echo Request instead.
Assisted-by: Kiro:claude-opus-5.5
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
A multishot iteration re-queued the submission before posting its own
completion. The resubmit gives the submission back to the iodev, so the
next iteration, or the -ECANCELED of a cancel that lands in between, can
reach the completion queue first and the data read here is lost.
Post the completion before the queue push.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Tom Burdick <thomas.burdick@infineon.com>
Cancelling a submission produced no completion, so a thread waiting in
rtio_submit() for one that was then canceled waited forever.
rtio_sqe_cancel() documented the opposite.
Complete a canceled submission like any other failure, with -ECANCELED
and its userdata. Only RTIO_SQE_NO_RESPONSE suppresses it. A multishot
canceled mid-iteration reports -ECANCELED too, unless the iteration
also failed, since the error says more. Document the rule where a
reader looks for it: every submission reaches the completion queue
unless it is flagged otherwise.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Tom Burdick <thomas.burdick@infineon.com>
fs_opendir("/") opens a file system mounted at the root itself when
one exists, instead of unconditionally enumerating mount points via
the virtual root directory.
Co-authored-by: Chris Friedt <chris@fr4.co>
Assisted-by: Claude:claude-opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
The handlers were only compiled for three sys_rand_get backends and the
csrand verifier was gated on CSPRNG_ENABLED, which the PSA and test
CSPRNG backends do not set, so user threads hit handler_no_syscall().
Signed-off-by: Flavio Ceolin <flavio@hubble.com>
The timeout iodev uses a single kernel timeout, armed for the earliest
pending delay. Three places arm it:
- submit, when the new delay becomes the earliest one;
- cancel, when the cancelled delay was the earliest one;
- the expiry handler, after completing the expired delays.
The handler arms it with z_add_timeout(), which requires the timeout
not to be queued. That breaks if a submit or cancel queues it after it
fired but before the handler took data->lock:
CPU0: timeout fires, handler dispatched
(submit runs here: timeout not queued, so it queues it)
CPU0: handler takes data->lock, z_add_timeout() on a queued timeout
Submit and cancel tried to prevent this by retrying while
z_try_abort_timeout() returned -EAGAIN (handler in flight on another
CPU). That covers a call from another CPU, but not one from an
interrupt taken on the CPU running the handler: there the abort returns
-EINVAL, so the timeout gets queued and the handler then links it a
second time.
Fix this by having all three places abort the timeout before arming
it. The handler then simply replaces whatever a submit or cancel armed
in the meantime, and those no longer need to wait for an in-flight
handler.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Allow the user to provide PSK as PSA key. This ensures that the plaintext
format never leaves PSA.
In terms of contraints on tls_credential PSK_PSA follows the same that
PSK have. The only new one is that, of course, for a given tag there
can only be one between PSK and PSK_PSA defined, not both.
Tests are also extended in this commit to cover newly added code and
checks.
Signed-off-by: Valerio Setti <vsetti@baylibre.com>
The PSA key is provided through a tls_credential and the function performs
some basic checks:
1. Check that the size of the credential is valid for a PSA key ID;
2. Check that the PSA key really exists by getting its attributes. If it
really exists, then pass the attributes back to the caller for more
specific checks.
Currently this helper is only used for private asymmetric keys, but in the
future it will be used also for PSK.
Signed-off-by: Valerio Setti <vsetti@baylibre.com>
Slightly improve the way PSK and PSK_ID credentials are checked in
socket_tls. Given a list of tags only one couple of (PSK, PSK_ID) is
allowed, as it was before. The main difference is that a standalone
PSK_ID without PSK is now a failure whereas previously this was silently
ignored. The opposite, i.e. PSK with PSK_ID, is still a failure as it
was before.
PSK is also checked in "tls_check_credentials" for not being longer than
CONFIG_MBEDTLS_PSK_MAX_LEN.
Tests are updated accordingly. A new test case named
"test_tls_psk_tag_list" has been added to group all the checks on
PSK/PSK_ID.
Signed-off-by: Valerio Setti <vsetti@baylibre.com>
The correct guard for PSA API support would have been
MBEDTLS_PSA_CRYPTO_CLIENT; MBEDTLS_PSA_CRYPTO_C enabled the Mbed TLS
implementation for it, but this is a "detail" the client shouldn't care.
Kconfig-wise indeed CONFIG_MBEDTLS depends on CONFIG_PSA_CRYPTO and the
latter can be provided by either TF-M or Mbed TLS
(CONFIG_MBEDTLS_PSA_CRYPTO_C).
However starting from Mbed TLS 4 PSA Crypto API is the only supported
crypto backend for TLS/X.509 so MBEDTLS_PSA_CRYPTO_CLIENT is also
superfluous.
This commit simplifies the code by removing both guards.
Signed-off-by: Valerio Setti <vsetti@baylibre.com>
The MCS server has to handle a Track Title that does not fit in a
single ATT operation: a notification of the value is truncated to
ATT_MTU-3 bytes, and a Read Long that continues at an offset after the
value has changed is rejected with the Value Changed During Read Long
error. The MCS qualification test cases GMCS/SR/SPN/BV-02-C verify
this behavior. They need a Track Title that does not fit in a single
ATT operation both before and after the update.
The titles of the tracks in the first group were 9 bytes long. With the
default ATT MTU of 23, at most 20 bytes fit in a single read or
notification, so the Track Title always fit and the server behavior
above could not be exercised. The test cases could not pass.
Change the titles of the tracks in the first group to
"Track 1.x with a very long name" (31 characters), which still fits in
the default CONFIG_BT_MPL_TRACK_TITLE_MAX of 40. The media player
starts on the first track, so with the default ATT MTU of 23 the
initial Track Title is 31 bytes, which does not fit in a single read.
Moving to the next track changes the Track Title to a different 31 byte
value, which triggers the notification. The test case can then check
that the notification is truncated to 20 bytes, that a Read Long at that
offset returns Value Changed During Read Long, and that a new Read Long
from offset 0 returns the full updated title.
This only works with the default ATT MTU of 23. If a different ATT MTU
is exchanged, for example the 65 bytes that BAP requires to be
supported, a 31 byte Track Title fits in a single read or notification
and the test case does not exercise this behavior.
Signed-off-by: Alex Ciascai <alexandru.ciascai@nordicsemi.no>
The shell thread sent with a blocking call while holding tx_lock, and the
socket layer holds the descriptor lock for the whole call as well, so a
client that stopped reading made the socket service thread wait behind
that send when it had to close the session. Command replies blocked the
service thread the same way.
Send without blocking and wait with tx_lock released when the send cannot
proceed, for at most as long as the blocking send would have waited: for
POLLOUT when the window is full, with a growing pause when the stack is
out of buffers. A session counter, bumped under tx_lock on every accept
and close, tells whether the send may resume afterwards; a close, an
abort-output command or a new client in between drops the pending output
quietly. The send work leaves the line buffer alone while the shell thread
writes, as a delayed reschedule issued during a cancel is still armed.
Command replies are sent without blocking too. One that cannot start is
dropped; one that has partly left is completed under tx_lock within a
short bounded wait, so the option sequence never gets interleaved with
output.
Assisted-by: Claude:claude-fable-5.1
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
All cancels of the send work shared one k_work_sync, so two threads ending
the same session at once queued the same canceller node twice on the
kernel's pending cancel list and corrupted it. The send work handler also
cancelled itself synchronously on a send error and so could never return.
Give every cancel its own k_work_sync and make the handler only cancel
further submissions instead of waiting for itself.
Assisted-by: Claude:claude-fable-5.1
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The socket error was logged uninitialized when the SO_ERROR query itself
failed, for example on a descriptor that is no longer open. Use the query
error instead.
Assisted-by: Claude:claude-fable-5.1
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The send work handler cancelled its own work synchronously when a send
failed, which blocks the system work queue for good: the cancel waits for
the handler to return. All cancels also shared one k_work_sync, so the next
cancel from another thread queued the canceller node a second time while
it was still on the kernel's pending cancel list. That made the list
circular, and the next work queue to finalize a cancel spun forever with
the work lock held and stopped the whole system.
Let only the socket service thread close the client socket. A failed send
on another thread stops the output and shuts the socket down for reading,
which wakes the service thread with EOF whatever the error was, so the
close always follows. Give every cancel its own k_work_sync and run sends,
cancels and the close under one mutex: the descriptor cannot be closed and
reused while a send is in progress, and no two threads ever wait for the
same cancel. The server restart path uses the same close.
Assisted-by: Claude:claude-fable-5.1
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Introduce a helper Kconfig symbol for libraries that need random number
generation through the `sys_rand*_get` functions. Communicating this
dependency is currently non-trivial.
Signed-off-by: Jordan Yates <jordan@embeint.com>