In #90652 we removed phy related config from eth api,
unfortunatly ETHERNET_CONFIG_TYPE_T1S_PARAM was forgotten
to be removed.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
Fix copy and paste mistakes in shell outputs. Remove unnecessary
shell_error() in device descriptor command.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Add mount_flags to zms_fs structure to be able to control the mount
operation.
If ZMS_MOUNT_FLAG_NO_FORMAT flag is enabled, no header will be added to
an erased memory and it will return -ENOTSUP error.
Signed-off-by: Riadh Ghaddab <riadh.ghaddab@nordicsemi.no>
Fix a race condition in RFCOMM session disconnection when both local
and peer devices initiate disconnection simultaneously.
Add state check in `rfcomm_session_disconnected()` to only transition
to `DISCONNECTED` state if the session is not already in
`DISCONNECTING` state. This prevents the race condition where both
sides set the session to disconnected, causing the disconnection
process to not complete properly and leaving the L2CAP connection
unreleased.
Without this check, subsequent RFCOMM channel connection requests
would fail due to the invalid session state (the expected state is
`IDLE`, while the actual state is `DISCONNECTED`).
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
The technology values defined in tbs.h are actually defined
in assigned numbers under the HFP. They have been moved to
the assigned_numbers.h file, and name to match the placement
in Assigned Numbers. They have been defined in an enum instead
of multiple #define's, to more easily refer to them.
The callback for reading technology was likewise updated to use
the new enum.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Add SPP test shell commands, support client and server features.
include register, connect, send and disconnect.
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
The two reference counts in the net_buf library -- the per-header
`buf->ref` and the per-data-block `*ref_count` byte at the start of
each variable-data allocation -- were manipulated with plain non-atomic
C operators (`++`, `--`, `if (--rc)`, `if (!rc)`).
The documented contract says otherwise. The Network Buffers chapter of
the Zephyr docs (`doc/services/net_buf/index.rst`) states:
"The buffers have native support for being passed through k_fifo
kernel objects. Use k_fifo_put and k_fifo_get to pass buffer from
one thread to another."
"The reference count can be incremented with net_buf_ref() or
decremented with net_buf_unref(). When the count drops to zero the
buffer is automatically placed back to the free buffers pool."
There is no requirement for callers to hold a higher-level lock around
ref/unref. The API is documented as self-synchronizing, and existing
users (notably zbus's msg-subscriber path) rely on exactly that:
a producer clones a buffer N times and hands the clones off to N
subscriber threads via their FIFOs, after which the N+1 holders
independently call `net_buf_unref()` with no surrounding lock.
With non-atomic decrement-and-test, two CPUs can concurrently observe
the same prior value (e.g. 1), both decrement, and both conclude they
were the last reference. Concrete failure modes:
* `mem_pool_data_unref`: both CPUs call `k_heap_free(pool, ref_count)`
on the same block. `k_heap_free` is internally serialized, so the
duplicate free typically corrupts heap metadata silently.
* `heap_data_unref`: both CPUs call `k_free(ref_count)` on the same
block. `k_free` reads the owning `struct k_heap *` from the 8 bytes
immediately preceding `ref_count`. The first call frees the block
and the heap-hardening fill replaces those 8 bytes with the poison
pattern (0xcfdfdfdfdfdfdfcf). The second call then dereferences a
poisoned pointer and faults inside `k_spin_lock` (translation
fault on the bogus heap address).
* `net_buf_unref`: two CPUs racing the per-header decrement-and-test
can both decide "I am the last reference," both proceed to
`net_buf_destroy()`, and the buffer is returned to the pool's LIFO
twice -- silently corrupting the free list.
Fix: use atomic operations on both reference counts.
The per-data-block refcount changes from `uint8_t` to `atomic_t`. This
fits inside the existing `GET_ALIGN(pool)` reservation (>= sizeof(void
*)) at no memory cost.
The per-header `buf->ref` is overlaid in a union with three small
adjacent uint8_t fields (`flags`, `pool_id`, `user_data_size`) and an
`atomic_t ref_word` view of the same storage:
union {
atomic_t ref_word;
struct {
uint8_t ref;
uint8_t flags;
uint8_t pool_id;
uint8_t user_data_size;
};
};
(Byte order conditional on endianness so `ref` is always the LSB of
`ref_word`; on big-endian 64-bit, the byte struct is shifted by 4
bytes of padding for the same reason.)
Net_buf internals issue `atomic_inc(&buf->ref_word)` /
`atomic_dec(&buf->ref_word)` and narrow the returned word value to
`uint8_t` to extract the ref byte. Because the ref count is bounded
to 254 (already implicit in its uint8_t domain), atomic_inc/dec
adjusts only the LSB; the other three bytes are untouched. Plain
uint8_t reads of `buf->ref` from non-atomic call sites continue to
work, so the change is transparent to the dozens of consumers that
read it for diagnostics.
`flags`, `pool_id` and `user_data_size` are written exactly once at
allocation time on a single thread (or, for `flags`, from a context
that owns the buf exclusively such as bt_buf_make_view on a fresh
view), so there are no concurrent byte writes that could conflict
with the atomic word update. struct net_buf does not grow on either
32-bit or 64-bit: on 32-bit the four bytes are exactly `sizeof(long)`,
on 64-bit they fit in alignment padding the next field already
required.
A BUILD_ASSERT in lib/net_buf/buf.c documents the
`atomic_t == long` assumption that the conditional padding relies on.
In `net_buf_unref`, the per-header refcount and the fields needed for
the debug log (`buf->pool_id`) are captured into local variables
*before* the atomic decrement -- once the reference is dropped, another
CPU may immediately free the buffer, so the buffer must not be read
again. The post-decrement diagnostic log uses the value returned by
`atomic_dec` rather than re-reading `buf->ref`. The `pool->avail_count`
sanity check uses the value returned by `atomic_inc` to avoid a
follow-up `atomic_get` of memory another CPU may have changed.
`net_pkt_frag_unref()` previously had the racy
`if (frag->ref == 1U) alloc_del(); net_buf_unref();` pattern; it is
restructured to do the atomic decrement here and slot the tracker call
in atomically with the "I'm the last reference" decision, with
`net_pkt_frag_del()` routed through it.
This bug had been latent. On real SMP hardware the race window is very
small and the typical net_buf consumers (Bluetooth, networking) tend
to use fixed-data pools (`fixed_data_unref` is a no-op). The race
manifests reliably under FVP, where the FastModel's quantum-based
execution model can schedule N threads to all reach the unref point in
the same simulated moment. We discovered it through the zbus
`msg_subscriber_dynamic_isolated` sample, which exchanges shared data
buffers among 16+ subscribers running on 4 SMP cores.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Replace CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN with the new
CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN and CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN
options across all in-tree .conf files, hostap Kconfig defaults, and
socket subsystem help text.
This completes the deprecation of MBEDTLS_SSL_MAX_CONTENT_LEN in favor
of independent incoming/outgoing buffer size control.
Signed-off-by: Rithic Chellaram Hariharan <gr8rithic@gmail.com>
Add bt_conn_br_set_sniff_subrating() API to configure sniff subrating
parameters for BR/EDR connections. Sniff subrating allows further
power savings by reducing the number of sniff anchor points the
device needs to listen on.
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
Handle NewSessionTicket in poll() syscall (via tls_update_pollin() and
tls_data_check()) similar as it is handled in recv() / read() syscall (via
recv_tls()).
This event is semantically the same as "want read" and "want write", since
it does not contain any application data or error. This means that we just
want to proceed with reading and not treat that as error.
Fixes: 6be57aaedf ("net: sockets_tls: add support for TLS 1.3")
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
Introduce struct bt_conn_br_cb to group all BR/EDR specific connection
callbacks (role_changed, mode_changed) into a dedicated sub-struct
within bt_conn_cb. This replaces the previously scattered callbacks
that were individually guarded by CONFIG_BT_CLASSIC or
CONFIG_BT_POWER_MODE_CONTROL.
Application code now uses the .br. accessor:
.br.role_changed = my_role_changed_cb,
.br.mode_changed = my_mode_changed_cb,
The br_ prefix is dropped from callback names since the struct
hierarchy already conveys the BR/EDR scope, aligning with the
pattern suggested during review.
Also fix bt_conn_notify_mode_changed() to use
BT_CONN_CB_DYNAMIC_FOREACH instead of SYS_SLIST_FOR_EACH_CONTAINER
for consistency with other callback notification functions.
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
The per-session channel table size is a spec-mandated property of
the region (EU868: 16, US915/AU915: 72, CN470: 96, ...) and is
not a user preference: a region needs exactly as many slots as its
channel plan defines, no more, no less.
Replace the hardcoded #define with a hidden Kconfig in the region
subdirectory.
Signed-off-by: Carlo Caione <ccaione@baylibre.com>
Refactor mac_build_data_frame() so uplink frames can carry MAC
commands in the FOpts region between FHDR and FPort, and set the
FCtrl.ADR bit when lorawan_enable_adr() has been called.
Signed-off-by: Carlo Caione <ccaione@baylibre.com>
Widen the get_tx_params() region op to accept a TX power index and
compute the effective dBm from it.
Signed-off-by: Carlo Caione <ccaione@baylibre.com>
Add three region-ops function pointers needed by the upcoming MAC
command framework to validate and apply parameters from LinkADRReq:
- validate_dr: is a datarate index defined in this region?
- validate_tx_power: is a TX power index defined in this region?
- apply_channel_mask: apply a ChMaskCntl + ChMask pair to the
channel table, atomically (no partial mutation on failure).
Implement them for EU868.
Signed-off-by: Carlo Caione <ccaione@baylibre.com>
The lwm2m registry time series elements were previously stored in a
ring buffer which added complexity to the code when adding and removing
elements from the buffer. This commit changes the implementation to use
the sys_ringq instead, simplifying the code and making it easier to
maintain over time.
Signed-off-by: Måns Ansgariusson <mansgariusson@gmail.com>
When building MQTT with MQTT_LIB_WEBSOCKET,
compilation fails due to implicit declaration of function 'NET_ERR'.
Add include for zephyr/net/net_log.h to pull in declaration.
Signed-off-by: Jacob Schloss <jacob.schloss@suburbanmarine.io>
Fixes a few occurrences of "maybe uninitialized" variables that are
flagged when -Wmaybe-uninitialized is enabled. Seen when running e.g.
./scripts/twister -p mps2/an385 -T tests/net/lib/coap_server/common
in "--coverage" mode.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Give the PTP transport protocol choice a symbol name so tests and
application fragments can override its default through Kconfig.
Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
dns_unpack_answer() validated only the fixed RR header size and
accepted any rdlength, even one extending past the end of the packet.
TXT and SRV consumers in resolve.c then read up to rdlength bytes from
the message buffer, causing an out-of-bounds read on a truncated or
crafted response.
Reject any RR whose declared rdata extends past dns_msg->msg_size at
the single chokepoint in dns_unpack_answer(), so all current and
future RR consumers are covered.
Signed-off-by: Flavio Ceolin <flavio@hubblenetwork.com>
The VOCS discover callback may call vcp_vol_ctlr_discover_complete()
with a NULL vol_ctlr when lookup_vcp_by_vocs() fails.
This leads to a potential NULL pointer dereference as
vcp_vol_ctlr_discover_complete() unconditionally accesses
vol_ctlr->flags.
Fix this by returning early when vol_ctlr is NULL.
Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
Add option for remote shell client. Remote shell client is an
implementation of shell on the client core which supports
IPC communication with host shell implementation. It allows
to use host shell backends to execute commands on the remote
client. The remote client implementation takes much less
memory than the normal shell implementation.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
In preparation for remote shell support, move hexdump printing to
the shell_utils.c file. Main shell.c file is not compiled for remote
shell client.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
Do not compile shell_help() implementation if CONFIG_SHELL_HELP=n.
In that case, empty inline function is implemented in the shell
header and it may fail to compile.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
When input buffer is written, notify the shell. It will wake the
shell thread which will process the input buffer.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
Core spec defines the range of adv intervals for extended advertising to
0x0020 to 0xFFFFFF, but the code currently only allows up to 0x4000.
This change enables the full range of intervals for extended advertising
Signed-off-by: Kyra Lengfeld <kyra.lengfeld@nordicsemi.no>
The checks validating RA, NS and NA packets content on input were not
correct - packets should be dropped in case any of those checks failed,
however current logic was invalid, causing other checks to be ignored as
long as the ICMPv6 code was correct (i. e. 0).
Apart from fixing the logic, split the single convoluted if condition
into separate if checks for better readability.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Replace EALREADY return values of the functions that modify or set USB
device attributes to EBUSY. EBUSY seems to be more appropriate for the
case when a user tries to change the attributes of an operational
device.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Remove the logic that silently clamps the MTU to valid ranges and
instead return an error if the configured MTU is below the minimum
required size.
The MTU is now always set to the maximum value that the configuration
can support, rather than conditionally using a default only when
set to 0.
Change log level from WRN to ERR for the minimum MTU check since
this now represents a fatal configuration error.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
ISO connections basically have 2 connection states:
1 for the `bt_iso_chan`, and one for the underlying
`bt_conn`. Due to how hci_disconn_complete_prio works,
these may be out of sync while disconnecting, and
bt_iso_chan_send could return 0 after we have received
a disconnect event from the controller. In this case
the number of pending SDUs in the host for the ISO
channel could be non-0, which could cause issues.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The first issue is that the query offset was not properly updated.
The second issue is more complex and relates to the use of message
compression in domain names
(https://datatracker.ietf.org/doc/html/rfc1035#section-4.1.4). The
pointers can be nested (i.e. a first pointer pointing to a label with
another pointer)
For example: _http._tcp.local can be represented via:
'_http' + (pointer to a '_tcp' label + (pointer to a 'local' label).
This was not properly implemented, only single-pointers were supported.
Signed-off-by: Sebastiaan Merckx <sebastiaan.merckx@verhaert.com>
Add NULL checks for iface and addr in IPv4/IPv6 maddr add/rm
to prevent potential dereferences.
Signed-off-by: Muhammad Waleed Badar <walid.badar@gmail.com>
Make the Coordinated Set Size, Set Member Lock and Set Member Rank
characteristic optional by adding three new Kconfig options
BT_CSIP_SET_MEMBER_SIZE_SUPPORT, BT_CSIP_SET_MEMBER_LOCK_SUPPORT and
BT_CSIP_SET_MEMBER_RANK_SUPPORT. Also updates the existing examples
and tests to compile correctly.
Signed-off-by: Maximilian Zimmermann <gitmz@posteo.de>
Reorder some of the large and complex shell command
functions, to make each function simpler to follow.
This also makes the code pass the Sonarcloud complexity
rule.
This also contain a few other various fixes and updates.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Instead of defining the same arguments in all 3 CAP files,
we declare them in audio.h and initiate them in either
the initiator or commander, depending on their use.
The reason for this change, is that the CAP Handover API
require several of the parameter to be globally/statically
allocated, and cannot just rely on stack allocated parameters.
By doing this, we can use the same argument among the
CAP shell modules, while keeping the memory usage down.
This has the additional postive effect that we do not allocate
some of these arrays, which can be quite larger, on the stack.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Implement the shell command for handing over broadcast to
unicast. The command supports various configurations.
It is currently limited to cases with
- 1 connection and multiple streams
- Multiple connections and 1 stream
- Equal amount of streams and connections
Cases with e.g. 3 connections and 2 streams,
or vice versa, are not support given the complexity
of these cases.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Display raw packet socket statistics (recv, sent, drop, bytes) in the
"net stats" shell command output. This follows the same display format
as the existing UDP and TCP statistics sections.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Assisted-by: Cursor:opus-4.6
Add statistics tracking for raw/packet sockets (AF_PACKET), following
the same pattern as existing UDP and TCP statistics. This tracks packet
counts (sent, received, dropped) and byte counts for raw socket traffic.
The new CONFIG_NET_STATISTICS_RAW Kconfig option is enabled by default
when CONFIG_NET_SOCKETS_PACKET is active. Statistics are updated in the
AF_PACKET send path (net_context.c) and the packet socket delivery path
(connection.c).
Includes NET_MGMT user API support, periodic output, and Prometheus
metrics integration.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Assisted-by: Cursor:opus-4.6
The two cached handles did not provide anything useful
and can be removed, thus freeing up some memory.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Instead of allocating a generic uuid and copying the BASS UUID
to it for each discovery, we can just use declare and use it
as a constant as it won't change.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Fix insufficient buffer length validation in bt_sdp_parse_attribute().
The original check only verified space for the type byte and attribute
ID, but did not account for the type variable itself that is read from
the buffer immediately after the check.
This could lead to a buffer over-read if the buffer contains exactly
sizeof(uint8_t) + sizeof(attr->id) bytes but not enough for the
additional type field.
Add sizeof(type) to the length check to ensure all required data is
present before parsing.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Add checks to verify the valid length of broadcast names
in codec_cfg and codec_cap, both in terms of size in octets,
but also in terms of length in characters.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Add checks to verify the valid length of broadcast names
in codec_cfg and codec_cap, both in terms of size in octets,
but also in terms of length in characters.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
MISRA-C requires essentially boolean type in control flow.
Convert all if/while conditions using err or ret
as implicit booleans to explicit comparisons:
- if (err) -> if (err != 0)
- Same rules applied to while statements and ret variable
Assisted-by: GitHub Copilot
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>