When handling CoAP Confirmable requests, there is a common
Acknowledgement initialization procedure that repeats for each
response packet initialization. This patch adds a function that
simplifies Acknowledgement initialization procedure encapsulating
repeating code.
Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
Generated device and driver names have changed with commits [1] and [2],
but net offload drivers missed the conversion. Update net offload DT
device macros now.
[1] commit 8c1bef535b ("device: support generating defines from
devicetree nodes with no label")
[2] commit f91e9fba51 ("device: fix potential truncation of DT-derived
device names")
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
RFC 7252 (CoAP) specifies value of the Version (Ver) field in the
protocol header to value 1. This patch defines value of the Version
field to make packet initialization easier. All samples and tests
are updated to use the new COAP_VERSION_1 field when initializing
a CoAP packet.
Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
Token and payload are appended from data buffers to a CoAP packet
being encoded. Keyword const was missing for parameters in functions
appending these parts to a packet.
Now token and paylod can be copied to CoAP packet from constant
buffers, that can be stored in ROM.
Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
This patch introduces COAP_TOKEN_MAX_LEN definition in coap.h file.
This definition replaces magic number across CoAP protocol
implementation and CoAP samples.
Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
While using the encoded path to a device tree node guarantees a unique
identifier for the corresponding device there is a limit on the number
of characters of that name that can be captured when looking up a
device by name from user mode, and the path can exceed that limit.
Synthesize a unique name from the node dependency ordinal instead, and
update the gen_defines script to record the name associated with the
full path in the extern declaration.
Add a build-time check that no device is created with a name that
violates the user mode requirement.
Also update the network device DTS helper functions to use the same
inference for dev_name and label that the real one does, since they
bypass the real one.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This enables to use net_buf_append_bytes without passing an allocator in
which case the code would attempt to use the net_buf_pool of the
original buffer.
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Starting brace was missing in the socket_select.h file so adding
it back
#ifdef __cplusplus
extern "C" {
#endif
Fixes#31444
Signed-off-by: Pablo Garrido <pablogs9@gmail.com>
CoAP protocol defines registry of Content-Format option values.
This patch adds this enumeration to coap header file to make it
available to all applications using CoAP protocol. It modifies
code using CoAP service to use new enumeration.
Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
Add Kconfig option to randomize the initial ACK timeout, as specified in
RFC 7252. The option is enabled by default.
Additionally, finetune the default value of COAP_INIT_ACK_TIMEOUT_MS
option, to match the default ACK_TIMEOUT value specified by the RFC
7252. The RFC does not specify the minimum/maximum value of the
ACK_TIMEOUT parameter, but only suggests it should be no lower than 1
second, so adjust the option range to reflect this.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Introduce retransmission counter to the coap_pending structure. This
allows to simplify the retransmission logic and allows to keep track of
the number of remaining retranmissions.
Additionally, extend the `coap_pending_init()` function with `retries`
parameter, which allows to set the retransmission count individually for
each confirmable transaction.
Fixes#28117
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The net_timeout structure is documented to exist because of behavior
that is no longer true, i.e. that `k_delayed_work_submit()` supports
only delays up to INT32_MAX milliseconds. Nonetheless, use of 32-bit
timestamps within the work handlers mean the restriction is still
present.
This infrastructure is currently used for two timers with long
durations:
* address for IPv6 addresses
* prefix for IPv6 prefixes
The handling of rollover was subtly different between these: address
wraps reset the start time while prefix wraps did not.
The calculation of remaining time in ipv6_nbr was incorrect when the
original requested time in seconds was a multiple of
NET_TIMEOUT_MAX_VALUE: the remainder value would be zero while the
wrap counter was positive, causing the calculation to indicate no time
remained.
The maximum value was set to allow a 100 ms latency between elapse of
the deadline and assessment of a given timer, but detection of
rollover assumed that the captured time in the work handler was
precisely the expected deadline, which is unlikely to be true. Use of
the shared system work queue also risks observed latency exceeding 100
ms. These calculations could produce delays to next event that
exceeded the maximum delay, which introduced special cases.
Refactor so all operations that use this structure are encapsulated
into API that is documented and has a full-coverage unit test. Switch
to the standard mechanism of detecting completed deadlines by
calculating the signed difference between the deadline and the current
time, which eliminates some special cases.
Uniformly rely on the scanning the set of timers to determine the next
deadline, rather than assuming that the most recent update is always
next.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Swap the `net_buf_*` -> `net_buf_simple_*` conversion `#define`s to
`static inline` functions. This is to provide better type checking on
the use of these functions.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
Adds a new family of `struct net_buf` operations that remove data from
the end of the buffer.
The semantics of `net_buf_remove_mem` have been chosen to match those of
`net_buf_pull_mem`, i.e. the return value is a pointer to the memory
that was removed.
The opposite of this function, `net_buf_remove`, would need to return
the old end of the data buffer to be useful. However this value is
always an invalid target for reading or writing data to (It points to
the middle of unused data).The existance of the function would be
misleading, therefore it is not implemented.
Fixes#31069.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
Document limitations on the FIFO queuing functions when fragments are
used. Namely that the `get` functions are not thread-safe when fragments
are present.
This is due to multiple independent calls to `k_fifo_get/sys_slist_get`.
A second thread can interrupt the retrieval before all fragments have
been removed. The second thread can then read from the FIFO, obtaining
the trailing fragments as a 'new' `net_buf`. The first thread will then
either assert or pull in the next `net_buf` on the queue as part of the
first `net_buf`.
Fixes#28355
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
The proper usage of @param in callbacks is currently unsupported by
Doxygen so not warnings are generated. The issues fixed with this commit
where found while adding support to Doxygen for validating @param in
callbacks like it currently does for functions.
Signed-off-by: Fabio Utzig <fabio.utzig@nordicsemi.no>
Provide versions of ETH_NET_DEVICE_INIT that are both devicetree
node and instance aware. We use the _DEFINE suffix for the DT
versions to match the naming convention in device.h
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Provide versions of NET_DEVICE_INIT, NET_DEVICE_INIT_INSTANCE, and
NET_DEVICE_OFFLOAD_INIT that are both devicetree node and instance
aware. We use the _DEFINE suffix for the DT versions to match the
naming convention in device.h
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
A dedicated LwM2M execute callback type has been implemented which
supports execute arguments. The lwm2m engine, lwm2m_client sample and
lwm2m objects have been updated accordingly. Also the API change has
been documented, and the lwm2m engine reference has been updated.
Fixes#30551.
Signed-off-by: Maik Vermeulen <maik.vermeulen@innotractor.com>
In mqtt_keepalive_time_left(), return -1 if keep alive messages are
disabled by setting CONFIG_MQTT_KEEPALIVE=0.
This allows to use mqtt_keepalive_time_left() directly as an input
for poll(). If no keep-alive is expected, -1 would indicate
that poll() can block until new data is available on the socket.
Signed-off-by: Simen S. Røstad <simen.rostad@nordicsemi.no>
Use the core k_heap API pervasively within our tree instead of the
z_mem_pool wrapper that provided compatibility with the older mempool
implementation.
Almost all of this is straightforward swapping of one alloc/free call
for another. In a few cases where code was holding onto an old-style
"mem_block" a local compatibility struct with a single field has been
swapped in to keep the invasiveness of the changes down.
Note that not all the relevant changes in this patch have in-tree test
coverage, though I validated that it all builds.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
Mark all k_mem_pool APIs deprecated for future code. Remaining
internal usage now uses equivalent "z_mem_pool" symbols instead.
Fixes#24358
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
LwM2M engine by default sends piggybacked responses for requests after
all callbacks are executed. This approach however isn't good enough if
the application callback executes some lenghty operations (for instance
during FW update). Delaying the ACK may result in unnecessary
retransmissions.
This commits adds an API function which allows to send an early empty
ACK from the application callback. This prevents further retransmissions
from the server side. After all callbacks are executed, the LwM2M engine
will send the response as a separate CON message.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Currently zsock_timeval implementation uses long type for both
tv_sec and tv_usec fields. In the select method timeval type is
directly casted on zsock_timeval, but in some cases (e.g. when
using CONFIG_POSIX_API and some specific libc version) both types
have fields of different sizes, what may lead to assigning them
incorrect values.
Using types declared by the used libc in the CONFIG_POSIX_API=y
case will let to keep timeval and zsock_timeval types compatible.
Signed-off-by: Kamil Kasperczyk <kamil.kasperczyk@nordicsemi.no>
Add a macro in public header that represents maximum hostname string
length without terminating NULL character. This will allow other
modules, such as offloaded network drivers, to know how much space is
needed to allocate in order to fit whole hostname.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
The alignment is needed when using CMSG_DATA() to access a uint64_t
when an object of type struct cmsghdr is allocated on the stack.
Also update the ALIGN_H and ALIGN_D macros to better match the
description in RFC 3542:
"The macros ALIGN_H() and ALIGN_D(), which are implementation
dependent, round their arguments up to the next even multiple of
whatever alignment is required for the start of the cmsghdr structure
and the data, respectively."
This commit makes the following test pass on qemu_leon3:
- net.socket.udp. It previously generated an unaligned data access
exception when a uint64_t value was accessed via CMSG_DATA().
Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
This commit allows the net_ipv6_addr_create_iid() argument addr to
have relaxed alignment.
This commit makes the following tests pass on qemu_leon3:
- net.6lo
Details:
sparc-zephyr-elf-gcc 9.2.0 compiles the beginning of
net_ipv6_addr_create_iid(),
addr->s6_addr[0] = 0xfe;
addr->s6_addr[1] = 0x8e;
UNALIGNED_PUT(0, &addr->s6_addr16[1]);
UNALIGNED_PUT(0, &addr->s6_addr32[1]);
into
400089d4 <net_ipv6_addr_create_iid>:
400089d4: 9d e3 bf a0 save %sp, -96, %sp
400089d8: 03 3f a0 00 sethi %hi(0xfe800000), %g1
400089dc: c0 2e 20 04 clrb [ %i0 + 4 ]
400089e0: c2 26 00 00 st %g1, [ %i0 ]
400089e4: c0 2e 20 05 clrb [ %i0 + 5 ]
400089e8: c0 2e 20 06 clrb [ %i0 + 6 ]
400089ec: c0 2e 20 07 clrb [ %i0 + 7 ]
%i0 is the function argument "addr". %g1 is prepared with the value
0xfe800000. The "clrb" instruction sets a single byte in memory to
0 and has no alignment restriction.
We get an unaligned exception on PC 400089e0 when %i0 ("addr") is
not a multiple of 4. The instruction "st" stores the full 32-bit
register %g1 to memory address in %i0. The effective address (%i0)
of the 32-bit register store is required to be naturally aligned by
the architecture.
The compiler assumes that "addr" is aligned according to its type
and has knowledge about the data representation.
Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
Currently, the Zephyr LwM2M code base is littered with hard-coded
object- and resource IDs, such as
/* Mark 1st instance of security object as a bootstrap server */
lwm2m_engine_set_u8("0/0/1", 1);
The purpose of this LoC is extremely opaque without the accompanying
comment. Each use of a resource path requires constantly checking
headers or the object registry to ensure you're not misremembering IDs.
To alleviate this, this commit introduces a variadic LwM2M path
expansion macro which performs preprocessor stringification on each
argument. For instance, "0/0/1" can now be written as
LWM2M_PATH(LWM2M_OBJECT_SECURITY_ID, 0, SECURITY_BOOTSTRAP_FLAG_ID)
which, while albeit lengthier, avoids the use of hard-coded string
literals, thus making the code much more immediately understandable.
Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
This change adds support for DNS Service Discovery (DNS-SD)
as described in RFC 6763.
Fixes#29099
Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
This change adds net_context_port_in_use(), which is a simple
wrapper around net_context_check_port() and is used to check
if a particular socket is bound to a given IP address.
Fixes#29649
Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
This change adds IEEE 802.15.4g (Sub GHz) support for the
cc1352r.
The 2.4 GHz radio and the Sub GHz radio are capable of
operating simultaneously.
Fixes#26315
Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
Track the number of dropped TCP data segments and number of dropped
TCP packets in network statistics. It is useful to see these
numbers separately.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Add a simple backoff mechanism between consecutive registration attempts
in case of registration failures. Finally, notify the application in
case the registration failed several times.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Currently, when socket errors occur during receive, the LwM2M engine
restarts the state machine and registers again to the server. While this
works in simple use case (only RD client socket open), it's not a valid
approach when more sockets are open (FW update socket).
Fix this by introducing socket fault callback, which is registered by
the LwM2M engine users. This way, a proper socket owner is notified on
error and can pertake appropriate action.
For RD socket errors the behaviour remains the same - the state machine
is reset and the client registers again to the server. For FW update
socket, handle the error by reopening the socket and retransmitting the
last request. This allows to resume the download from the point the
error occured, w/o a need to start from scratch.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
It shouldn't be optional to handle separate response, as it's a
mandatory requirement according to the RFC7252:
"The protocol leaves the decision whether to
piggyback a response or not (i.e., send a separate response) to
the server. The client MUST be prepared to receive either."
Therefore, remove the flag as separate responses are handled now
properly.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
using CONFIG_NET_BUF_POOL_USAGE monitor avail_count,
this variable should be protect.
Protecting it by using atomic variable
Signed-off-by: Ehud Naim <ehudn@marvell.com>
Adds the socket option TLS_ALPN_LIST for SOL_TLS sockets
Passes the configured alpn list to the mbedtls config
on mbedtls init
Signed-off-by: Emil Hammarstrom <emil.hammarstrom@assaabloy.com>
Existing openthread_api_mutex_lock()/unlock() functions are
crucial to assure thread safety of an application which
needs to use OT API directly, but some applications may also
require a non-blocking version of the former for less critical
OT-related tasks.
Add openthread_api_mutex_try_lock() which never waits and
exits immediately if the mutex is held by another thread.
Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
Thread implements couple of counters that require notification of failed
frame reception.
Implemented RX failed notification.
Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
Modified net_ipv4_is_addr_mcast() to not wrongly classify an IPv4
broadcast address as a multicast address.
Signed-off-by: Oliver Hitz <oliver@net-track.ch>
The message type flag will be set to
0x11(WEBSOCKET_FLAG_FINAL(0x01) | WEBSOCKET_FLAG_PING(0x10)) when
receiv PING with final fragment, it conficts with
WEBSOCKET_FLAG_PONG(0x11)
The WEBSOCKET_FLAG_PONG should be 0x20
Signed-off-by: Jackie Ja <qazq.jackie@gmail.com>
Currently, after `CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP` is enabled,
the LwM2M engine will initiate bootstrap procedure on each run. This
approach limits the flexibility of the application, as it's not always
necessary to go over the bootstrap procedure (for instance, the
application may decide to store the security object obtained during the
bootstrap in flash, and restore it on boot).
Fix this by introducing an additional `flags` parameter to the
`lwm2m_rd_client_start()` function, which provides information whether
to run bootstrap in the current session or not.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>