Commit Graph

863 Commits

Author SHA1 Message Date
Jeroen Broersen f889c1abab net: lwm2m: Add TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 to cipher list
Add TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 to the list for use with x509
certificates. The LWM2M v1.1 specification says that a LWM2M client
which used X509 certificates must support this ciphersuite and
additional ciphersuites may be supported.

Signed-off-by: Jeroen Broersen <jbroersen@interact.nl>
2024-10-30 14:27:40 -05:00
Brandon Allen bb24c83d70 net: lib: lwm2m: lwm2m_rw_senml_cbor: only assign time on get_s64() success
Currently GCC complains that temp64 may be used uninitialized in this
 function. Adds a check to ensure time is valid before assignining
 and fixes GCC warning.

Signed-off-by: Brandon Allen <brandon.allen@exacttechnology.com>
2024-10-22 14:12:48 +02:00
Robert Lubos 6545f5148f net: lwm2m: Make CoAP pendings/replies arrays access thread safe
Make sure LwM2M context mutex is locked whenever accessing CoAP
pendings/replies arrays.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-10-17 10:49:19 -04:00
Robert Lubos 4a4e4ec7d0 net: lwm2m: Make LwM2M context lists access thread safe
System lists are not thread safe, therefore all accesses should be
protected with a mutex. Introduce a LwM2M context specific mutex,
and use it whenever lists defined per-context are acessed.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-10-17 10:49:19 -04:00
Robert Lubos 85c5cd4c6a net: lwm2m: Make CoAP block contetx allocation thread safe
Use global engine mutex to protect allocation/deallocation of the CoAP
block contexts.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-10-17 10:49:19 -04:00
Robert Lubos b8751c669b net: lwm2m: Make LwM2M message allocation thread safe
The LwM2M message allocation was not thread safe, i. e. the message was
acquired by setting the ctx pointer, and it was freed by clearing the
entire message structure.

If preemptive threads were enabled, and memset() clearing the message
content was preempted, the message structure being currently zeroed
migh've been allocated and initialized by some other thread. If the
thread releasing the message resumed work, it would continue clearing
the freshly allocated and initialized message structure.

In order to prevent this, introduce a new global mutex for the lwm2m
engine global variables. The mutex is used when LwM2M message is
allocated/deallocated. This will prevent reallocating the message
during the release process.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-10-17 10:49:19 -04:00
Robert Lubos c4803752a8 net: Deprecate CONFIG_NET_SOCKETS_POLL_MAX
CONFIG_ZVFS_POLL_MAX is now used to control the maximum number of poll()
entires. Thereby, CONFIG_NET_SOCKETS_POLL_MAX is redundant and shall
be deprecated.

Modify the defaults for NET_SOCKETS_POLL_MAX and ZVS_POLL_MAX so that
the deprecation actually makes sense instead of symbol removal. In case
the application still sets the old config, it will modify the
ZVS_POLL_MAX default.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-10-14 13:01:51 +02:00
Seppo Takalo 8068cb2567 net: lwm2m: Add shell command for listing resources
Add shell command for listing multiple objects, resources
or resource instances.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-10-04 16:35:59 +01:00
Seppo Takalo 73a3438b82 net: lwm2m: Remove hostname_verify flag from context
Use security mode (PSK or X509) to detect if we should
set the socket option to verify hostname.

PSK security mode cannot verify hostnames as this information
is coming in the certificate, so don't set the options.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-10-03 17:09:32 +01:00
Pisit Sawangvonganan af4527e131 style: subsys: adjust `return` usage in `void functions`
For code clarity, this commit adjusts the use of `return` statements
in functions with a void return type as follows:
- Transform `return foo();` into separate statements:
  `foo();`
  `return;`
- Remove unnecessary `return` statements when
  they don't affect control flow.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-09-20 11:06:55 +02:00
Simon Walz 5af3fbadfd net: lwm2m: check each block for TLV header
For composite operations, we should always check whether the TLV header
is present. Otherwise, all blocks are assigned to one resource.

Signed-off-by: Simon Walz <simon.walz@autosen.com>
2024-09-17 17:45:17 +01:00
Simon Walz e20ef4443e net: lwm2m: check lwm2m path level while getting the block ctx
The Block1 context for composite operations is not found, as all path
levels are compared. The incoming path level should therefore always be
taken into account.

Signed-off-by: Simon Walz <simon.walz@autosen.com>
2024-09-17 17:45:17 +01:00
Robert Lubos e6f942f238 net: lwm2m: Fix enabler version reporting during bootstrap discovery
LwM2M 1.1 specification mentions that the enabler version format was
specified wrongly in LwM2M 1.0 specification, and servers only "may"
accept the old format, which no longer seems to be the case for Leshan.

The URI reference ("</>;") before the enabler version is now mandatory,
if it's missing the bootstrap discovery fails with Leshan. Another
problem are quotes around the enabler version, which seems to be
conditionally accepted only for LwM2M version 1.0. Therefore, keep the
quotes only for that version, to prevent any potential issues with other
servers.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-09-10 11:43:18 +02:00
Hyunsu Yoon db890a201a net: lwm2m: fix buffer size check for U16 resource
The lwm2m_check_buf_sizes() function was not checking resources of
type LWM2M_RES_TYPE_U16, which could lead to potential overflows
when writing larger data types into U16 resources. Add a case for
LWM2M_RES_TYPE_U16 to properly validate the buffer size.

Fixes #77016

Signed-off-by: Hyunsu Yoon <piedroconti@naver.com>
2024-09-02 12:32:50 -04:00
Øyvind Rønningstad 5a08d537fe lwm2m_senml_cbor_encode.c: Fix line lengths
clang-format made lines too long

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2024-09-02 12:32:40 -04:00
Øyvind Rønningstad 7b0e202282 lwm2m_senml_cbor: Regenerate zcbor code using zcbor 0.9.0
And update the patch file and shell script

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2024-09-02 12:32:40 -04:00
Seppo Takalo 1cd6b5f1c1 net: lwm2m: remove deprecated APIs and confs
Remove deprecated APIs and configs:
* CONFIG_LWM2M_RD_CLIENT_SUPPORT
* lwm2m_get_u64()
* lwm2m_set_u64()

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-08-14 09:14:43 -04:00
Seppo Takalo b5ac5f7eba net: lwm2m: Send is only supported on LwM2M 1.1
LwM2M SEND functionality is defined in LwM2M v1.1
So quard the condition with protocol version, not
server object version.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-08-14 10:47:24 +01:00
Reto Schneider b03fcfa0cf net: lib: lwm2m: Add name to choice symbol
Add name to choice symbol, so that default value can be changed
downstream.

Developed-by: Andreas Rudolf <andreas.rudolf@husqvarnagroup.com>

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
2024-08-14 09:40:34 +02:00
Nick Ward e738bca67f net: lwm2m: location object: make optional resources optional
Provides the user control over whether the altitude, radius,
or speed resources are in use.

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2024-08-09 08:37:25 -04:00
Seppo Takalo e3100c6f3a net: lwm2m: Allow SenML-CBOR floats decoded as int
SenML is technically a JSON based format which can
be encoded as a CBOR. SenML-CBOR specification in
RFC 8428 section 6 states that numbers can be decoded
as an integer.

Also RFC 7049 section 4.2 states that JSON numbers
without fractional part can be decoded as an integer.

I have seen with one commercial LwM2M platform that
the decoder  they use, sends floating point values as
integers, if there is no fractional part.

So LwM2M engine cannot assume from the path that
the incomming number is either float or int. Accept both.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-08-08 15:37:56 +02:00
Seppo Takalo b68477b372 net: lwm2m: Reset retry counter on update
On a successful update we should reset the retry counter, similarly
like we do on successful registration.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-08-06 17:16:46 -04:00
Seppo Takalo e7b06e1c86 net: lwm2m: send REGISTRATION_TIMEOUT event on error
When socket errors call sm_handle_timeout_state() we might be
in a state where application assumes we are in registered state
but we are dropping it.
Therefore we must ensure that all registration states emit either
REGISTRATION_TIMEOUT event for application to indicate that
we have lost the connection to server.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-08-06 17:16:46 -04:00
Robert Lubos 5f43388308 net: coap: Parse more flag in coap_get_block2_option()
Parse the more flag in coap_get_block2_option(), so that the function
can be used not only with requests but also with replies (where the more
flag should not be ignored).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-08-02 22:12:47 -05:00
Robert Lubos 3902a990e5 net: coap: Fix underlying type for block number
The block number in block1/2 options can be encoded on up to 20 bits
according to RFC 7959, therefore the underlying type used in helper
functions to retrieve the block number should be large enough to hold
the result. Therefore, replace the container for block number with
uint32_t instead of uint8_t.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-08-02 22:12:47 -05:00
Seppo Takalo e86bdf952d net: lwm2m: Always emit DISCONNECTED event
When LwM2M engine is requested to stop,
emit the disconnected event unconditionally.
There is really no reason to skip the event
on network error, or if we have never been registered.

Fixes #76422

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-08-01 12:35:53 +02:00
Nick Ward c8526bc53f net: lwm2m: shell: add observations cmd
Outputs observation configurations.

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2024-07-29 14:18:10 +02:00
Nick Ward 0645609b0b net: lwm2m: observations: add attr type to str
Allows strings used to be exposed outside of file.

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2024-07-29 14:18:10 +02:00
Pieter De Gendt ad63ca284e kconfig: replace known integer constants with variables
Make the intent of the value clear and avoid invalid ranges with typos.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-07-27 20:49:15 +03:00
Pisit Sawangvonganan 1100393b79 net: lwm2m: optimize `socket_loop` by using local variables
Changes include:
- Introducing a local `ctx` variable to replace multiple
  `sock_ctx[i]` references.
- Using a local `revents` variable to simplify repeated
  `sock_fds[i].revents` checks.
- Consolidating conditional checks for socket events
  (ZSOCK_POLLERR, ZSOCK_POLLNVAL, and ZSOCK_POLLHUP) as they are
  individual bit definitions, allowing them to be checked simultaneously.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-07-27 10:47:58 +03:00
Seppo Takalo 6addba5698 net: lwm2m: Verify X509 hostname when URI contains valid name
Enable hostname verification in DTLS handshake when server URI contains
valid hostname.
When URI is given just as IP address, don't fill up the
ctx->desthosname or enable hostname verification.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-07-27 10:44:27 +03:00
Pisit Sawangvonganan d1781da2ba net: lwm2m: fix typo
Utilize a code spell-checking tool to scan for and correct spelling errors
in all files within the `subsys/net/lib/lwm2m` directory.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-07-12 09:33:20 -04:00
Jordan Yates 91f8c1aea9 everywhere: replace `#if IS_ENABLED()` as per docs
Replace `#if IS_ENABLED()` with `#if defined()` as recommended by the
documentation of `IS_ENABLED`.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-06-28 07:20:32 -04:00
Robert Lubos 0ca2a3cce0 net: lib: lwm2m: Fix expected block calculation
Coverity reported that a formula used to calculate the next expected
block in case the block size from the request differs our own block size
has a bug. The expression used to calculate the block size diff would
evaluate to an unsigned integer, giving (wrongly) enormous results in
case block size from the request is smaller than the Zephyr's default.

It turns out however, that this formula is no longer needed at all.
Since commit d3081e2f30, Zephyr's LwM2M
implementation will no longer negotiate the block size in case of write
operation, but simply comply with the block size included in the
request. This means that calculating the diff makes no longer sense and
can be safely removed - the next expected block number should be simply
increased by 1.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-26 08:59:56 -04:00
Yong Cong Sin 3c0aae8415 net: lwm2m: replace deprecated lwm2m_engine_get_resource
`lwm2m_engine_get_resource()` has been mark for deprecation for
more than 2 releases, but we are still using it in tree now,
because the `__deprecated` marker was probably forgotten in the
initial deprecation commit.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-18 14:32:56 -04:00
Yong Cong Sin 94e12d595e net: lwm2m: remove deprecated functions & definition
These functions have been deprecated for more than 2 releases,
remove them:

- lwm2m_engine_update_observer_min_period
- lwm2m_engine_update_observer_max_period
- lwm2m_engine_create_obj_inst
- lwm2m_engine_delete_obj_inst
- lwm2m_engine_set_opaque
- lwm2m_engine_set_string
- lwm2m_engine_set_u8
- lwm2m_engine_set_u16
- lwm2m_engine_set_u32
- lwm2m_engine_set_u64
- lwm2m_engine_set_s8
- lwm2m_engine_set_s16
- lwm2m_engine_set_s32
- lwm2m_engine_set_s64
- lwm2m_engine_set_bool
- lwm2m_engine_set_float
- lwm2m_engine_set_objlnk
- lwm2m_engine_set_time
- lwm2m_engine_get_opaque
- lwm2m_engine_get_string
- lwm2m_engine_get_u8
- lwm2m_engine_get_u16
- lwm2m_engine_get_u32
- lwm2m_engine_get_u64
- lwm2m_engine_get_s8
- lwm2m_engine_get_s16
- lwm2m_engine_get_s32
- lwm2m_engine_get_s64
- lwm2m_engine_get_bool
- lwm2m_engine_get_float
- lwm2m_engine_get_objlnk
- lwm2m_engine_get_time
- lwm2m_engine_register_read_callback
- lwm2m_engine_register_pre_write_callback
- lwm2m_engine_register_validate_callback
- lwm2m_engine_register_post_write_callback
- lwm2m_engine_register_exec_callback
- lwm2m_engine_register_create_callback
- lwm2m_engine_register_delete_callback
- lwm2m_engine_set_res_buf
- lwm2m_engine_set_res_data
- lwm2m_engine_set_res_data_len
- lwm2m_engine_get_res_buf
- lwm2m_engine_get_res_data
- lwm2m_engine_create_res_inst
- lwm2m_engine_delete_res_inst
- lwm2m_engine_path_is_observed
- lwm2m_engine_send
- lwm2m_send
- lwm2m_engine_enable_cache

And additionally, the following definition:
- LWM2M_RD_CLIENT_EVENT_REG_UPDATE_FAILURE

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-18 14:32:56 -04:00
Seppo Takalo 35cc774aa5 net: lwm2m: Retry DTLS handshake before dropping to bootstrap
Allow DTLS handshake to be retried before the engine
drops into bootstrap. Otherwise any termporary failure,
for example DNS failure might drop us into bootstrap
without retrying.

Now all the retry logic should be in sm_do_network_error().
sm_do_registration() should only fall back to bootstrap
if there is configuration error.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-06-14 15:34:39 +02:00
Seppo Takalo 441d970417 net: lwm2m: Bypass send_queue when sending empty Ack
In case we want to immediately send empty Ack to server,
we should bypass all send queues.

This is required when we try to send Ack from callbacks
that happen from socket-loop context. On those cases
the Ack would have not been send because the callback
might be blocking the socket-loop while processing
a request (like write callbacks).

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-06-12 12:50:46 -04:00
Seppo Takalo d3081e2f30 net: lwm2m: On write, use server selected block size
When we receive CoAP packets, it is in input buffer
that is size of NET_IPV6_MTU.
So in reality, we can handle bigger Block-Wise writes
than CONFIG_LWM2M_COAP_BLOCK_SIZE.

So if parsing of CoAP packet has passed, continue
with the same block-size instead of going to default.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-06-05 14:43:14 +01:00
Chris Friedt 4a5c4e5f73 posix: timers: deprecate CONFIG_POSIX_CLOCK and TIMER
The POSIX_CLOCK option does not correspond to any standard
option. It was used to active features of several distinct
POSIX Options and Option Groups, which complicated API and
application configuration as a result.

POSIX_CLOCK is being deprecated in order to ensure that Zephyr's
POSIX Kconfig variables correspond to those defined in the
specification, as of IEEE 1003.1-2017.

Additionally, CONFIG_TIMER is being deprecated because it does
not match the corresponding POSIX Option (_POSIX_TIMERS).

With this deprecation, we introduce the following Kconfig
options that map directly to standard POSIX Option Groups by
simply removing "CONFIG_":

* CONFIG_POSIX_TIMERS

Similarly, we introduce the following Kconfig options that
map directly to standard POSIX Options by simply removing
"CONFIG":

* CONFIG_POSIX_CLOCK_SELECTION
* CONFIG_POSIX_CPUTIME
* CONFIG_POSIX_DELAYTIMER_MAX
* CONFIG_POSIX_MONOTONIC_CLOCK
* CONFIG_POSIX_TIMEOUTS
* CONFIG_POSIX_TIMER_MAX

In order to maintain parity with the current feature set, we
introduce the following Kconfig options that map directly to
standard POSIX Option Groups by simply removing "CONFIG_":

* CONFIG_POSIX_MULTI_PROCESS - sleep()

Similarly, in order to maintain parity with the current feature
set, we introduce the following additional Kconfig options that
map directly to standard POSIX Options by simply removing
"CONFIG":

* CONFIG_XSI_SINGLE_PROCESS - gettimeofday()

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Seppo Takalo 9e615429d5 net: lwm2m: Block-Wise response NUM field fix
When calculating the offset for blockwise writes,
we should not advance the block_ctx->current field
past the block boundary.
It causes CoAP layer to reply with the next NUM field
instead of the current one being processed.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-06-03 15:37:21 +02:00
Seppo Takalo b76683e4cb net: lwm2m: Allow setting RD context without starting
When tests control the LwM2M client entirely through
shell, we should be able to set the RD client context
from the application without causing RD client to
start registration.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-05-29 10:47:57 -07:00
Seppo Takalo 4049e17c62 net: lwm2m: Fix null dereference when post-write cb is set
When opaque resources have post-write callback set, but
the write is not a Block-Wise write, there is no block_ctx
and the code causes null pointer dereference when calculating
the offset of the data.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-05-28 18:54:31 +02:00
Seppo Takalo 37f6803833 net: lwm2m: Allow Block-Wise write without callbacks
Allow Block-Wise writes to resources that have enough buffer for
the whole content. Calculate the offset before calling the
content specific write handlers when callback is not set.

Previously only resources with post-write callback were able to
assemble the content.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-05-15 14:58:15 +02:00
Seppo Takalo a9e91af375 test: lwm2m: Add tests for Block-Wise transfers
Block-Wise GET, PUT and SEND

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-05-15 14:58:15 +02:00
Seppo Takalo 01b57b4999 net: lwm2m: Add offset to post-write callback
When Block-Wise transfer restarts, the post-write callback should
receive some indication that the block is actually a beginning of new,
instead of part of previous transfer.

Fixes #71351

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-05-15 14:58:15 +02:00
Jordan Yates 23ca74b756 convert: use `k_uptime_seconds`
Replace usage of `k_uptime_get() / MSEC_PER_SEC` and
`k_uptime_get() / 1000` with dedicated function.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-05-14 09:32:01 +02:00
Philippe Schumacher 67db6f69f3 net: lwm2m: efficent cbor record data structure
The record data structure is better aligned. Each record saves
24 bytes.

Signed-off-by: Philippe Schumacher <philippe.schumacher@husqvarnagroup.com>
2024-05-08 12:00:57 +02:00
Seppo Takalo e2ab41b625 net: lwm2m: Fix pull-context on queue mode
Two issues fixed:
When pull-context is created, it does not have to wake up the RD
client context. Ignore the EPERM warning.

When new pull-context creates a new socket, sometimes socket-loop
gets to recvfrom() before we have set O_NONBLOCK on the socket.
So use ZSOCK_MSG_DONTWAIT on zsock_recvfrom() so it does not
block the socket loop.

Fixes #71450

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-05-07 15:10:09 -05:00
Seppo Takalo 553e5d2e0c net: lwm2m: Move one Kconfig to engine features submenu
Kconfig option to enable object version reporting should
be moved into sub section "Engine features" so
it does not clutter up the main LwM2M menu.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-05-06 14:55:42 +01:00