GCC gave the following warning:
mqtt_sn_transport_udp.c: In function ‘tp_udp_init’:
mqtt_sn_transport_udp.c:117:9: warning: ‘memcpy’ forming offset [12, 105]
is out of the bounds [0, 12] of object ‘mreqn’ with type ‘struct ip_mreqn’
[-Warray-bounds=]
117 | memcpy(&mreqn.imr_multiaddr, &udp->bcaddr.data[2], si...
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mqtt_sn_transport_udp.c:48:25: note: ‘mreqn’ declared here
48 | struct ip_mreqn mreqn;
| ^~~~~
And it turns out that it's right. The original code looks like it tries to
copy the IP address to imr_multiaddr in a way that works for both v4 and
v6. It ignores, that bcaddr.data may be way larger than even a v6 addr,
because it's a buffer that's big enough to hold many other structs as well.
Not only that, IP_ADD_MEMBERSHIP is for IPv4 only and imr_multiaddr can
only hold an IPv4 address anyway.
This modifies the code to have separate code paths for v4 and v6 and call
the correct APIs. This also gets rid of the memcpy, since it can be a
simple struct assignment now.
Signed-off-by: Michael Zimmermann <michael.zimmermann@sevenlab.de>
Mark pm_device_driver_init() as a boot function to support using it
for early init on devices with demand paging.
Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
The config PM_S2RAM_CUSTOM_MARKING is not an optional config for a
user to select, it is required by some soc implementations of S2RAM,
in which case it must be selected by the soc.
Refactor the configuration to be HAS_PM_S2RAM_CUSTOM_MARKING, and
make the currently only soc which needs it select it. Then update
samples which previously had to select this option for this soc.
Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
Currently it is possible to have an enabled (status="okay")
"suspend-to-ram" "zephyr,power-state" in the devicetree,
CONFIG_PM=y, but CONFIG_PM_S2RAM=n
This means the presence and state of the "suspend-to-ram" power
state in the devicetree does not match the PM_S2RAM option,
despite PM_S2RAM being dependent on the devicetree state.
This commit makes the devicetree the "source of truth" for
whether one or more s2ram power states shall be included and
supported, by enabling PM_S2RAM if any s2ram power state with
status "okay" is present in the devicetree. To disable the
s2ram power state, like with any other state, disable it by
setting its state to "disabled".
The help of the now promptless PM_S2RAM config has been
updated to reflect the new meaning. It previously held
cortex-m specific implementation details, these have been
removed as these details are already present in the file
pointed to as well (arch/arm/core/cortex_m/pm_s2ram.c
line 22)
Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
In HFP PTS, cases run fail with the log 'unsupported unsolicited
format: +BSIR=0' and 'FAIL: Expected to receive +BSIR: 0'.
Fixed issue by changing +BSIR=0 to +BSIR: 0.
Signed-off-by: Jiawei Yang <jiawei.yang_1@nxp.com>
dns_unpack_query() no longer prepends the unpacked query with extra dot,
therefore LLMNR responder needs to be aligned with this change when
parsing result and preparing response.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
dns_unpack_query() no longer prepends the unpacked query with extra dot,
therefore mDNS responder needs to be aligned with this change when
parsing result and preparing response.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
When handling packets for inputing into packet-sockets, unconditionally
forward them, so that they may be handled by the rest of the network
stack after.
Signed-off-by: Cla Mattia Galliard <clamattia@gmail.com>
Support using FUSE v3, instead of FUSE v2.
FUSE v3 has been out for a couple of years now, so most distributions
have it.
But note the FUSE library (and its v3 branch) is currently unmaintained,
and older distributions do not ship it.
Some Linux distros have transitioned their packages away from fuse2.
Which results in less atention in these distros to fuse2, and therefore
a higher likelyhood that there would be distribution issues with the
corresponding packages.
There is also some likelihood the fuse2 packages may be eventually
droped by some of these.
So let's support either version, with a kconfig adapting to either API
and their quirks.
Note that both the fuse2 and fuse3 library code have quite a few
sideeffects on the process that uses it.
By now we continue defaulting to fuse2 as it is the most common.
But users can select to use the v3 if they have an issue w v2 or want
to start trying out using v3.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Avoid a possible race between the FUSE thread and the Zephyr threads
during init.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
FUSE_INCLUDE_DIRS should be passed to the native_simulator build.
If there is several fuse libraries installed, we need to ensure the
bottom side of the driver is built with the correct include paths.
(These includes are irrelevant for the Zephyr side build)
Support having a list of include paths instead of single one.
Support having a list of libraries to link to instead of a single one.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Fix deleting a key that doesn't exist from writing a new entry to the
filesystem when `CONFIG_ZMS_NO_DOUBLE_WRITE` and
`CONFIG_ZMS_LOOKUP_CACHE` are enabled.
Signed-off-by: Jordan Yates <jordan@embeint.com>
Handle the `bt_le_create_conn_cancel` call in the deferred worker
failing due to insufficient command buffers.
Signed-off-by: Jordan Yates <jordan@embeint.com>
In Direct XIP with revert, it should be possible to block confirmation
of the non-active slot, so only a bootable binaries are marked as valid.
Signed-off-by: Tomasz Chyrowicz <tomasz.chyrowicz@nordicsemi.no>
Fix some "All if ... else if constructs shall be terminated
with an else clause" (c:M23_112) issues reported by SonarQube.
Signed-off-by: Christophe Dufaza <chris@openmarl.org>
An assertion in bt_conn_unref() accesses the connection's state
after decrementing its reference count.
This is not consistent since, if we removed the last reference,
the Bluetooth Host stack may reuse the connection object
before the assertion is checked.
Instead, retrieve the connection property tested by the assertion
before decrementing the counter, as we do for other properties.
Simplify the code path by returning early when we did not remove
the last reference.
Remind that automatic advertiser resumption is deprecated.
Signed-off-by: Christophe Dufaza <chris@openmarl.org>
In bt_conn_unref(), a local variable is used as atomic target:
atomic_val_t old = atomic_dec(&conn->ref);
/* Prevent from accessing connection object */
bool deallocated = (atomic_get(&old) == 1);
Using atomic_get() to access a non-shared local variable
cannot prevent any data race on that variable,
and only causes confusion.
Moreover, this call to atomic_get() is incorrect: the API expects
an atomic_t* argument (target), not an atomic_val_t* (value).
This compiles and /works/ only because Zephyr defines both to be
the same integer type, and thus: atomic_get(&old) == old.
The equivalent C11 code, where _Atomic(T) and T are different types,
wouldn't compile.
Signed-off-by: Christophe Dufaza <chris@openmarl.org>
The only reason to keep these would be to enable conditional compilation
of some parts of the code. However, we can't see enough benefit in doing
this, particularly since the flash driver itself will conditionally
handle certain paths depending on erase caps, so the options are
deprecated to reduce complexity.
Signed-off-by: Ludvig Jordet <ludvig.jordet@nordicsemi.no>
This fully decouples blob_io_flash from specific flash device details,
by not reading the write block size from a hard-coded device tree node,
instead pulling this from the actual flash device used.
The block write routine has been updated to be more generic and fix a
few bugs:
* The write buffer is now sized based on a KConfig option instead of
basing it off the device tree - this makes the module usable with
any flash device, not just the internal memory. The configured value
is checked during initialization, to ensure that the configured size
will fit the write block size required by the device passed to the
init function.
* The erase value used to fill the buffer when using a device with
explicit erase is now pulled from the flash parameters instead of
being hard-coded to `0xff`.
* An additional write block sized piece of buffer is allocated - the
previous buffer sizing with rounding up only worked if
`BLOB_RX_CHUNK_SIZE % WRITE_BLOCK_SIZE` was 0 or 1 (which
coincidentally worked in all testing because the chunk size defaults
to 161, and for internal flash w/write block size of 4,
`161 % 4 == 1`).
* The choice of whether to just write the chunk as-is or to
write-block align it is now based on the erase cap pulled from the
flash parameters, instead of checking the type of memory in the SOC.
This means the module dos _not_ currently support the case where
memory has to be written write-block aligned, but the memory does
_not_ use explicit erase. It uses a trick of filling the write
buffer with the erase value to avoid overwriting existing chunks,
which will not work in this case. This trick is required to support
random ordered chunks while still writing write-block aligned.
* The code has been cleaned up a bit in general.
Signed-off-by: Ludvig Jordet <ludvig.jordet@nordicsemi.no>
Only erase a page when starting the first block on that page.
This fixes a bug where, if the block size is smaller than the page size,
the entire page would be erased upon start of each block when writing,
meaning only the final block on each page would be retained. This works
because blocks are always received in order.
Signed-off-by: Ludvig Jordet <ludvig.jordet@nordicsemi.no>
This adds a Kconfig dependency on FLASH_PAGE_LAYOUT when using flash
with explicit erase, removing all code dependencies on flash
configuration from the erasure logic. This module already requires
FLASH_PAGE_LAYOUT to be set when using it with flash with explicit
erase, as a silent requirement. The current code does not work without
this option enabled except for the case where a BLOB has a size which is
a multiple of the page size (since, without it, trying to erase flash
space for the final block, which is of variable size, will fail). Also
cleans up the code a bit.
Signed-off-by: Ludvig Jordet <ludvig.jordet@nordicsemi.no>
In case FIN packed also acknowledged most recently sent data, not all
ack-related TCP context variables were updated, resulting in invalid SEQ
number values sent in consecutive packets.
Fix this by refactoring the FIN handling in TCP_ESTABLISHED state.
Instead of having a separate block strictly for FIN packet processing,
let the packet be processed by common code responsible for regular
data/ack processing. This should be less error-prone for any future
modifications or not-yet-discovered issues. Only after the common
processing of data/ack is done, we check whether FIN flag was present in
the packet, and mark the connection for closing.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
TCP context cannot operate w/o a TX packet for buffering transmitted
data. So far this net_pkt was allocated at runtime from the common
packet pool, but this created some not-obvious memory requirement on TCP
and could lead to TX packet starvation in case many TCP connections are
open in parallel. Therefore, allocate this packet structure statically,
as a part of the TCP context instead.
This increases the memory requirement of the TCP context by ~64 bytes,
however if that's a concern for the application, the maximum number of
TX packets can be lowered instead. In return, we get a clear separation
between the number of TCP connections opened, and the amount of packets
that can be transmitted.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add helper function to initialize externally allocated TX packet. It's
especially important to configure net_buf slab for the packet so that
net buffers are allocated from a correct pool for the packet.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Using net_pkt for TCP out-of-order recv queue was an overshot, as the
mechanism mostly used net_buf operations directly anyway. It can be
easily replaced with a direct net_buf pointer, so that it's not longer
needed to hog one net_pkt per TCP context anymore.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The introduced CONFIG_TASK_WDT_DUMMY Kconfig symbol allows to easily
disable the Task Watchdog by providing a dummy implementation.
The Task Watchdog can fire when a board is halted on a breakpoint during
a debugging session, so this new feature can turn useful in this case.
Signed-off-by: Adrien Ricciardi <aricciardi@baylibre.com>
The k_event event is only used if CONFIG_PM_DEVICE_RUNTIME_ASYNC is
selected, but EVENTS is selected, and the k_event included in the
struct pm_device if CONFIG_PM_DEVICE_RUNTIME is selected.
Correct to only include event and EVENTS if
CONFIG_PM_DEVICE_RUNTIME_ASYNC is selected. This saves us 1
struct event per PM DEVICE.
Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
Add missing `.key` designator.
This also fixes a compile error:
> error: either all initializer clauses should be designated or none of
them should be
Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
This aims to implement a packet forwarding mechanism between
DNS resolver and applications that install a callback, letting
DNS resolver know that received UDP packet is also required by an
application.
Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
In case STA + AP mode is enabled, then adjust the defaults to accomodate
the second interface.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Many SoCs which use PM_DEVICE_RUNTIME need every device in the system
to have PM_DEVICE_RUNTIME enabled to function. Currently, this is only
possible by adding zephyr,pm-device-runtime-auto; to every node in
every devicetree which could potentially implement device power
management. This is very error prone since its easy to miss a node,
especially if users apply overlays, where users need to know and
remember to apply or reapply this property.
This commit adds a Kconfig, disabled by default, which automatically
treats every device as if it had the zephyr,pm-device-runtime-auto
property added to every node.
Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
TCP somehow ended up with two internal headers with duplicate set of
internal function declarations. As tcp.h looks like a subset of the
tcp_internal.h header, combine the two headers into a single
tcp_internal.h and remove tcp.h. There were some differences in doxygen
API descriptions, so I've used the description that better described the
actual function purpose.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Implement TCP connection backlog for TCP server. The backlog parameter
is already specified by the listen() socket API, however it was never
implemented in Zephyr. It can be useful to limit the number of incoming
connections on the server side, and thus limit the connection flood and
resource shortage.
The backlog is implemented as a atomic counter inside the TCP context.
The counter is initialized on the listen() call (and thus no connection
can be accepted before listen() is called), and then decremented
whenever new connection is initiated. When the application accepts
the incoming connection, it should call the net_tcp_conn_accepted()
API (done automatically for sockets) to inform the TCP layer that the
backlog can be incremented. The backlog value is also incremented back
if the connection is released before the connection was passed to the
application.
For tracking the parent (listening) socket, the 'accepted_conn' pointer
on the client context has been reused. Note, that the pointer used to be
cleared before the accept_cb() call before, to prevent consecutive calls
to the callback, however this was not really needed - the TCP state is
changed anyway, and the accept_cb() is only used in TCP_SYN_RECEIVED
state. The pointer is no cleared when the application accepts the
connection (or the client or the associated parent context is closed).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
When encoding cached LwM2M 1.1 resources into SenML CBOR, the encoder
currently aborts with -ENOMEM if the number of records (minus
some CBOR delimiter elements) exceeds CONFIG_LWM2M_RW_SENML_CBOR_RECORDS.
This discards all serialized data and prevents any payload from
being sent, leaving the client stuck and caches filling up.
This patch changes the behavior: if some records were already
serialized before the buffer shortage, the CBOR output is finalized
(end marker added) and the partial payload is returned. This allows
the client to send useful data, and the upper layers can react by
reducing batch size.
Impact:
- Preserves forward progress instead of canceling the message
- Avoids cache lock-up
- No changes to the API or success path behavior
Signed-off-by: Marcel Wappler <marcel.wappler@decentlab.com>
Introduce a shell for specific cpu core about PM control,
this aligns with existing design flow where the policy decides
the state based on next event timing, locks and latency constraints,
and the system naturally enters low power through the idle thread.
New shell commands under `cpu`:
- cpu states : List supported CPU power states (from devicetree)
- cpu available : For each state/substate, show if available
- cpu lock : Lock specific low power mode
- cpu unlock : Unlock specific low power mode
- cpu idle ms : Sleep the current thread to let idle run PM
Signed-off-by: Yongxu Wang <yongxu.wang@nxp.com>
Add two helper functions to convert power management states between
enum and string:
- pm_state_to_string()
- pm_state_from_string()
Signed-off-by: Yongxu Wang <yongxu.wang@nxp.com>
Inject packets from AIL to Thread network and vice versa taking into
account packet forwarding security safeguards and multicast forwarding.
Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
As the linkaddr->addr is no longer a pointer, the original
assert check is not working as it should. So use the length
of the linkaddr to verify that it is > 0.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This commit adds a work item designated for Border Router message
parsing. A generic message structure has been proposed.
If CONFIG_NET_IPV4 is enabled, border router services will start only
after an IPV4 address has been assigned on the backbone interface.
If border router is initialized before DHCPV4 client has been assigned
an address, initial mDNS IPV4 packets will be dropped, because a source
address cannot be retrieved from that specific backbone interface.
Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
When next_ping == now, the code scheduled the workqueue for the current
time. On native_sim, this meant that the system workqueue thread was stuck
in an infinite loop because it kept processing the MQTT work over and over
again and the current timestamp could not advance anymore.
I didn't investigate why the yield inside the workqueue didn't help or why
native_sim can't advance time when one of the threads is stuck, but
changing the condition to >= inside mqtt_sn solves this issue.
I discovered this while running zephyr.exe through strace for up to 60
minutes. I guess that the performance overhead makes it more likely for the
workqueue handler to be run while next_ping == now, but I didn't verify
that, because it takes a long time to trigger the bug.
Signed-off-by: Michael Zimmermann <michael.zimmermann@sevenlab.de>