Reading the TCP/UDP port fields via UNALIGNED_GET(&tcphdr->src_port)
takes the address of a packed struct member, which trips Clang's
-Waddress-of-packed-member warning.
Since net_tcp_hdr and net_udp_hdr are already __packed structs, the
compiler emits correct unaligned accesses for direct member reads, so
read the port fields directly instead. This is consistent with how the
rest of the file already accesses these members.
Assisted-by: Cursor:opus-4.8
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Replaced the manual string parsing to parse mixed array JSON messages
with the native mixed array JSON support in JSON library
Signed-off-by: Sanjay Vallimanalan <sanjay@linumiz.com>
Add iptables shell cmd to add and del iptable rules.
Iptable rules are used to allow specific packets to
be forwarded through interfaces and subnets.
Example usage:
net iptable add -i 1 -o 2 -s 192.168.2.2 -S 255.255.255.0
-d 192.168.1.1 -D 255.255.255.0 -p 1 -P 1 -t 60 -T 300
net iptable del 0
Signed-off-by: Fengming Ye <frank.ye@nxp.com>
Add ipv4 NAT (Network Address Translation) to allow packets to
hop between interfaces.
Add iptable rules to filter packets that can be forwarded.
There are mainly 3 parts. Iptable, connection track and NAT.
1. Iptable rules can be added. And packets from original interface
that match these rules, will generate a new connection track.
2. The connection track will record the tuples of both directions.
And it will age out after inactive for some time.
3. When packet matches a connection track, NAT will update the packet
header to let it route in the other interface.
Will do SNAT (Src NAT) for packets from input interface and forward
it to output interface.
Will do DNAT (Dst NAT) for packets from output interface and forward
it to input interface.
Signed-off-by: Fengming Ye <frank.ye@nxp.com>
When using zms_find_ate_with_id it starts searching for the ATE in a
position that has not been writen yet.
This can return an old deleted ATE if it exists in that position.
Fix this by detecting if the start address is exactly the current write
address and compute its previous one.
fixes: #88373
Signed-off-by: Riadh Ghaddab <riadh.ghaddab@nordicsemi.no>
the buffer doesn't need to be zero initialized.
therefore we don't need to use K_calloc.
It can already be seen, when we need to increase the
buffer we do it with k_realloc, which doesn't set the
additional space to zeros.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
Replace the local PDU access macros in net.c with static helper
functions.
Using functions avoids preprocessor namespace pollution from common
macro names such as SRC while preserving the same behavior. The
functions are local to net.c and are expected to be inlined by the
compiler, resulting in no functional change.
Fixes#109401
Signed-off-by: Gobi M <gobi@aerlync.com>
subnet_keys_destroy() guarded the destroy of keys->priv_beacon with
#if defined(CONFIG_BT_MESH_V1d1), while net_keys_create() guards the
matching import with #if defined(CONFIG_BT_MESH_PRIV_BEACONS).
Commit 981c79b7ce ("Bluetooth: Mesh: Drop explicit support for
Bluetooth Mesh 1.0.1") removed the CONFIG_BT_MESH_V1d1 Kconfig but
left this stray reference behind. With V1d1 gone, the destroy branch
is permanently dead code, so every successful net_keys_create() leaks
one PSA key slot.
In a long-running test that repeatedly provisions and resets a node
(no persistent settings, in-RAM CDB only), the leak accumulates one
PSA volatile-key slot per provisioning round. With the default
CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT=16, bt_mesh_private_beacon_key()
fails after ~12 rounds with:
<err> bt_mesh_net_keys: Unable to generate private beacon key
<err> bt_mesh_net: Failed creating subnet
<err> bt_mesh_main: Failed to create network
Align the destroy guard with the import guard so the leak goes away.
Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
Initialize new QUIC streams with sock set to -1 and only reparent
stream sockets that already have an instantiated file descriptor when
moving pending streams from a listening context to an accepted child
context.
A peer-created stream can arrive before the server application accepts
the connection socket. In that case the stream has not been accepted
yet and does not have a valid fd, so freeing or reallocating one during
migration can trigger invalid fd-table access under ASan.
Add a regression test that delays server-side connection accept until
after the client opens and uses a stream, so the pending peer stream is
migrated through the fixed path.
Assisted-by: Copilot:gpt-5.4
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The S-frame should only be sent when there are no I-frames to be sent,
as I-frames have higher priority. Previously, the S-frame flag was
checked in the same condition as other flags, which could cause S-frames
to be sent even when I-frames were available.
Fix by moving the S-frame check to a separate condition that first
verifies no I-frames are pending via `l2cap_br_send_i_frame()`. Also
move the clearing of `L2CAP_FLAG_SEND_S_FRAME` to the end of the
function to ensure it is cleared after any frame is sent, not just
when an S-frame is explicitly sent.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Introduce the helper macros `BT_GOEP_INIT_V1` and `BT_GOEP_INIT_V2`
to simplify and standardize GOEP and GOEP transport initialization for
the upper layer.
Add two new initialization macros that encapsulate the repetitive
pattern of setting up mutual back-pointers between `bt_goep` instances
and related GOEP version-specific transport structures:
- `BT_GOEP_INIT_V1`: Initializes GOEP v1 (RFCOMM) transport by setting
the back-pointer from transport to GOEP, assigning the v1 pointer,
and clearing the v2 pointer.
- `BT_GOEP_INIT_V2`: Initializes GOEP v2 (L2CAP) transport by setting
the back-pointer from transport to GOEP, assigning the v2 pointer,
and clearing the v1 pointer.
And adding type checking via `BUILD_ASSERT` and `SAME_TYPE` in these
two macros to ensure type consistent in building time.
Update all GOEP-based profiles (BIP, PBAP, MAP) and shell code to use
these new added macros.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Introduce a unified `bt_goep_transport` structure to simplify GOEP
transport handling across all profiles.
The added new `bt_goep_transport` structure contains both `v1` and
`v2` transport instances. The upper layer profiles could include the
structure instead of requiring separate structure members when both
GOEP V1.1 and V2 transport are required at the same time.
Update all GOEP-based profiles (BIP, PBAP, MAP) and shell code to use
the unified `goep_transport` structure member instead of separate
`goep_transport_v1` and `goep_transport_v2` members. This reduces code
duplication and provides a consistent pattern across all profiles.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Add explicit GOEP v1 and v2 transport structures to PBAP instances
to support the refactored GOEP transport version handling.
Add `bt_goep_transport_v1` and `bt_goep_transport_v2` structure
members to both PBAP client (PCE) and server (PSE) instance types to
align with the refactored GOEP transport handling that uses explicit
version pointers instead of a boolean flag and union.
Initialize the appropriate v1 or v2 structure and set the
corresponding pointer in the parent GOEP instance based on the
transport type (RFCOMM for v1, L2CAP for v2) during connection
establishment and accept operations.
Add NULL parameter validation in PSE accept functions to prevent
potential null pointer dereferences before initializing the GOEP
transport structures.
The change completes the PBAP integration with the new GOEP transport
architecture.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Add explicit GOEP v1 and v2 transport structures to MAP instances
to support the refactored GOEP transport version handling.
Add `bt_goep_transport_v1` and `bt_goep_transport_v2` structure
members to all MAP instance types (MCE MAS, MCE MNS, MSE MAS, MSE
MNS) to align with the refactored GOEP transport handling that uses
explicit version pointers instead of a boolean flag and union.
Initialize the appropriate v1 or v2 structure and set the
corresponding pointer in the parent GOEP instance based on the
transport type (RFCOMM for v1, L2CAP for v2) during connection
establishment and accept operations.
The change completes the MAP integration with the new GOEP transport
architecture.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Refactor GOEP transport version handling to use explicit v1/v2
structure pointers instead of a boolean flag and union.
Replace the `_goep_v2` boolean flag and `_transport` union in
`struct bt_goep` with explicit `v1` and `v2` pointers to new
`bt_goep_transport_v1` and `bt_goep_transport_v2` structures. This
improves code clarity and type safety by making the transport version
explicit and avoiding union-based type punning.
The new structures contain:
- `bt_goep_transport_v1`: RFCOMM DLC and back-pointer to parent GOEP
- `bt_goep_transport_v2`: L2CAP channel and back-pointer to parent GOEP
Update all transport operations to use CONTAINER_OF to retrieve
the version-specific structure, then access the parent GOEP
instance through the back-pointer.
Update BIP and shell code to allocate and initialize both v1 and
v2 structures, setting the appropriate pointer based on the
transport type being used.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Replace implicit NULL and zero checks with explicit comparisons to
improve code readability and follow coding standards.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
RFC 6455 section 4.2.2 requires a server that accepts a WebSocket
upgrade to echo back exactly one of the subprotocols the client
offered in its Sec-WebSocket-Protocol request header. Some clients
treat a missing Sec-WebSocket-Protocol header in the 101 Switching
Protocols response as the server rejecting all protocols and
abort the connection.
Capture the first comma-separated token from the client's
Sec-WebSocket-Protocol header in the HTTP/1 parser, then echo it
back in the upgrade response. If the client offered no
subprotocol the header is omitted as before.
Signed-off-by: Jonathan E. Peace <jep@alphabetiq.com>
Assisted-by: Claude:claude-opus-4-7
IPv6 addresses with more than one collapsed group of consecutive zeroes are
not valid, inet_pton should reject input on this form. Added negative test
cases for inet_pton to test the new behaviour.
Signed-off-by: Jonas Mårtensson <jonas@kafva.one>
Replace sizeof(name) with ARRAY_SIZE(name) in DHCPv4 and DHCPv6 state
and message type name lookup functions. sizeof returns the total byte
size of the pointer array not the element count, making the bounds check
wrong.
Signed-off-by: Flavio Ceolin <flavio@hubblenetwork.com>
It was deprecated for Zephyr v4.4.0 (by
b92d516907) but not in a proper way.
Its implementation was removed and it was made identical to
CONFIG_PSA_CSPRNG_GENERATOR which is deceiving.
In addition, it appears first in the choice, which means the
build system defaults to using this deprecated option instead of
CONFIG_PSA_CSPRNG_GENERATOR.
Removing it now is the best course of action to avoid deceiving users
any longer or defaulting to a deprecated option.
Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
When a characteristic declaration is passed instead of a value
attribute, ensure the associated characteristic value attribute
permissions are checked before sending notifications, indications
or multiple notifications.
Signed-off-by: Yuan Ye <1275552818@qq.com>
kernel.h implies kernel_structs.h via kernel_includes.h, making
explicit inclusion of kernel_structs.h unnecessary whenever kernel.h
is already included in the same translation unit.
Remove the redundant includes across arch, boards, drivers, kernel,
lib, samples, subsys, and tests trees.
in include/zephyr/kernel_structs.h:
* 2. kernel.h shall imply kernel_structs.h, such that it shall not be
* necessary to include kernel_structs.h explicitly when kernel.h is
* included.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Extended advertising reports as of
https://github.com/zephyrproject-rtos/zephyr/pull/106374 use the
discardable event pool so fragmented chains can be dropped without. That
raised the default discardable buffer size to BT_BUF_EVT_RX_SIZE to fit
general ext-adv reassembly.
Mesh does not need that headroom. The advertising bearer uses
ADV_NONCONN_IND PDUs (Mesh Protocol v1.1 3.3.1), which are legacy
primary-channel advertisements, not fragmented extended advertising
chains. Mesh scan only accepts BT_GAP_ADV_TYPE_ADV_NONCONN_IND, and
legacy reports fit in 58 bytes, the minimum when BT_EXT_ADV is enabled.
Default to 58 for BT_MESH to save RAM.
Signed-off-by: Håvard Reierstad <haavard.reierstad@nordicsemi.no>
Enterprise auth can fail while provisioning runtime credentials, but the
connect path continued and reported a later generic connect error.
Treat enterprise credential setup failure as a hard error and return
immediately with an explicit shell message.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Assisted-by: Cursor:Auto
When wifi shell falls back to the default interface, iface_index remains
-1 and nm validation logs become misleading.
Log the resolved net_if index instead so invalid iface/type errors point
to the actual interface under validation.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Assisted-by: Cursor:Auto
Introduce a new header file for ASCS as a step
towards decoupling ASCS and BAP.
BAP has a depdendencey on ASCS, but ASCS does not have one
for BAP, and the code should reflect that.
This is a first step that simply removes the requirement
of the BAP Unicast Server in ASCS with minimal changes.
Tasks to follow up with:
- Remove any depedency on bap.h from ascs.c
- Rename everything from ascs.h from bt_bap to bt_ascs where
applicable
- Add unit tests specific for BAP unicast server
- Move any BAP-only requirements from ASCS to the BAP unicast
server implementation.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
There was a race condition where the att_buf could be used for a
write request before the att_buf, containing the result of a long
read, was properly handled first.
Now the unicast client is only marked as not busy after the buffer
has been parsed.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Add a check to validate that the buffer has sufficient headroom
(BT_L2CAP_CHAN_SEND_RESERVE) before attempting to send data over
a classic L2CAP channel.
Without this validation, buffers allocated with insufficient headroom
could cause buffer corruption when `net_buf_push()` is called to add
the L2CAP header. In the case, the application will be asserted if
the assert is enabled.
The change ensures that callers properly reserve headroom when
allocating buffers for `bt_l2cap_chan_send()`.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Replace `strncmp()` with `memcmp()` for Bluetooth Classic part,
including in AT command parsing and HFP protocol handlers.
Due to the passed `n` of `memcmp()` has been checked and ensured to be
minimum size of the passed two memory blocks, the data of memory block
being compared is not necessarily null-terminated, making `memcmp()`
the more appropriate choice for binary-safe comparisons.
In addition, this change ensures that there are no type mismatch
warnings when using the function `strncmp()`.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Replace atomic_ptr_clear() with net_buf_take() to atomically
transfer ownership of the sent command buffer.
Signed-off-by: Dharun krithik k <dharunkrithik@aerlync.com>
Use net_buf_take() when moving completed SDU buffer from channel
to local variable in LE receive path.
Signed-off-by: Dharun krithik k <dharunkrithik@aerlync.com>
Replace manual pointer transfer with net_buf_take() when moving
completed L2CAP frame from connection rx buffer.
Signed-off-by: Dharun krithik k <dharunkrithik@aerlync.com>
Use net_buf_take() when moving completed SDU buffer from channel
to local variable, replacing manual pointer operations.
Signed-off-by: Dharun krithik k <dharunkrithik@aerlync.com>
Replace manual buf assignment and NULL setting with net_buf_take()
when releasing buffer to bt_l2cap_send_cb.
Signed-off-by: Dharun krithik k <dharunkrithik@aerlync.com>
Move OPENAMP_VENDOR_RSC_TABLE_FILE just below OPEN_AMP_VENDOR_RSC_TABLE
who it depends on. This improves identation in menuconfig for other
config items.
Signed-off-by: Andre Heinemans <andre.heinemans@nxp.com>
The menu items that are depending on OPENAMP_RSC_TABLE are bundled
within an if-statement. The 'depends on' fields are therefore not
required anymore.
OPENAMP_VRING_ALIGNMENT mistakenly did not have the 'depends on' and is
added to the if-statement as well. This fixes identation in the menu.
Signed-off-by: Andre Heinemans <andre.heinemans@nxp.com>
Route handling can legitimately resend a packet on the same
interface when a route lookup or on-link lookup keeps the
original egress interface. Those packets are routed, but they
must not be treated as forwarded traffic.
Set net_pkt_forwarding() only when the matching IPv4 or IPv6
forwarding option is enabled and the selected egress interface
differs from the ingress interface. Apply the same rule in the
generic net_route_packet_if() path so the forwarding flag stays
consistent for both explicit-route and on-link routing cases.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Checking `params->value` instead of `params->value_handle` is
a more straightforward and less brittle way to determine if a
ccc write response callback is performed due to a subscription
or unsubscription.
Signed-off-by: Sam Friedman <sam@golioth.io>
Add cpu_load support for Xtensa.
Fix an issue in Xtensa tracing where sys_trace_idle_exit
was not called, causing idle time to be collected incorrectly.
Signed-off-by: Frank Li <lgl88911@163.com>
Instead of relaying on the dynamic_get() callback initializing the whole
struct shell_static_entry *entry,
pre-initialize it to 0, so previous garbage in the stack does not cause
random behaviour.
The issue can be seen when running with valgrind, for example:
```
twister -p native_sim -T tests/drivers/comparator/shell/ --enable-valgrind
cmake -GNinja -DBOARD=native_sim ../tests/drivers/comparator/shell/
ninja
valgrind zephyr/zephyr.exe
```
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This performs a check of target code using it as index to
retrieve target string via the target code string array.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
Problem:
When fs_open() is called with FS_O_TRUNC, the FS backend
opens the underlying file via mp->fs->open() before the
truncate is attempted. If mp->fs->truncate() then fails,
the previous code cleared zfp->mp and returned right away,
which causes two issues:
- the backend's close hook is never invoked, so the
resources allocated during open (file slab entries,
internal caches, backend-specific structures such as
lfs_file, etc.) stay permanently allocated;
- a follow-up fs_close(zfp) cannot recover them either,
because zfp->mp has already been NULL'd and fs_close()
returns early.
The leak is reproducible on every backend (LittleFS, FAT,
...) and accumulates one slot per failed call until the
file slab is exhausted.
Solution:
Close the backend file explicitly in the truncate failure
path, before clearing zfp->mp, so the FS-specific close
hook can release everything it allocated during open().
If close itself fails, log the secondary error but still
return the original truncate error code, since that is
the root cause callers diagnose against.
Signed-off-by: Shuai Ma <malin719426@gmail.com>
Remove the use of printk, and replace with bt_shell_print
Remove any excess `\n` that seem to have been leftovers
from a previous fix.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This reverts commit 9401406e6a.
This patch was reverted due to regressions reported in #109814 (cached
timeseries data loss).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>