Commit graph

2451 commits

Author SHA1 Message Date
Anas Nashif
a08bfeb49c syscall: rename Z_OOPS -> K_OOPS
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif
ee9f278323 syscall: rename Z_SYSCALL_VERIFY -> K_SYSCALL_VERIFY
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif
9c4d881183 syscall: rename Z_SYSCALL_ to K_SYSCALL_
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif
9c1aeb5fd3 syscall: rename z_user_ to k_usermode_
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif
56fddd805a syscall: rename z_user_from_copy -> k_usermode_from_copy
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif
6ba8176e33 syscall: rename z_user_alloc_from_copy -> k_usermode_alloc_from_copy
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif
df9428991a syscall: Z_SYSCALL_MEMORY_ARRAY -> K_SYSCALL_MEMORY_ARRAY
Rename macros and do not use Z_ for internal APIs.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif
4d5d04169d syscall: rename z_is_in_user_syscall
Rename z_is_in_user_syscall -> k_is_in_user_syscall

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif
4e396174ce kernel: move syscall_handler.h to internal include directory
Move the syscall_handler.h header, used internally only to a dedicated
internal folder that should not be used outside of Zephyr.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif
a6b490073e kernel: object: rename z_object -> k_object
Do not use z_ for internal structures and rename to k_object instead.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif
d2c025dd78 kernel: objects: rename z_dynamic_object_create -> k_object_create_dynamic
Do not use z_ for internal APIs and rename z_dynamic_object_create.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Marc Lasch
73bab817a0 net: lwm2m: Remove the resource type in registration message
Do not include the resource type (rt=) in the registration message when
using the OMA JSON format. This was a workaround specifically for the
Wakaama LwM2M server which is no longer needed since the latest master
branch.

Signed-off-by: Marc Lasch <marc.lasch@husqvarnagroup.com>
2023-11-03 11:44:28 +01:00
Chaitanya Tata
d4d96b3df2 net: zperf: Fix the check for IPv6
It was typo.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-11-03 11:21:16 +01:00
Seppo Takalo
b6ab302fe8 net: lwm2m: Fix overlapping buffers from Portfolio object
Portfolio object created string buffers for Identity resources
that was overlapping on some cases.

Don't calculate pointers by hand, allow compiler to calculate it.

Fixes #64634

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-11-02 09:28:04 +01:00
Seppo Takalo
2eb804a558 net: lwm2m: Add shell support for deleting object and resource instances
Extend the previous support of creating object instances by allowing
creation of resource instances as well.
Similarly, add support for deleting.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-11-02 09:27:55 +01:00
Benedikt Schmidt
d7f0da1c78 net: fix thread function signatures
Fix thread function signatures to avoid stack corruption on thread exit.

Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
2023-10-30 12:24:34 +01:00
Jukka Rissanen
e44de3e381 net: shell: Join IPv6 mcast group if needed
If user adds IPv6 address to the network interface, check
if the address is a multicast one and add it to multicast
group if it is.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-27 10:52:48 +02:00
Jukka Rissanen
1467d7fa7b net: shell: Join IPv4 mcast group if needed
If user adds IPv4 address to the network interface, check
if the address is a multicast one and add it to multicast
group if it is.

Fixes #64389

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-27 10:52:48 +02:00
Chaitanya Tata
a1024f6aeb net: zperf: By default bind to any IP address
Default behaviour should only bind to port independent of IP, this
allows even multicast/broadcast L4 traffic to be received.

User can always specify a specific address to bind using shell or
Kconfig or API.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-10-27 10:52:19 +02:00
Chaitanya Tata
dee1f2deaa net: zperf: Set default IP addresses only if configured
If the user has not configured then we see the error prints for the
defaults always.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-10-27 10:52:19 +02:00
Chaitanya Tata
6bd47ffb10 net: zperf: Distinguish between IPv4 and IPv6 address set failures
Using a generic IP for address set failures is confusing, esp. two same
prints (one for v4 and the other for v6), so, use explicit version.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-10-27 10:52:19 +02:00
Jukka Rissanen
83c875adab hostap: Move the relevant config options away from hostap
Moving the Zephyr specific config options from
modules/hostap/Kconfig to corresponding Kconfig where the
option is specified.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-26 09:48:47 +02:00
Seppo Takalo
cf513451eb net: lwm2m: Keep user_data between blocks
CoAP reply structure user_data should be kept between
ongoing blocks, so that callbacks for LwM2M send continue
to work on blockwise transfers.

Fixes #64290

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-10-25 17:36:30 +02:00
Jukka Rissanen
8a58104396 net: shell: Add net-sockets command
The new "net sockets" command will utilize the object core
support to track and show information about BSD sockets that
are created in the system. This command is able to show info
for all network sockets (native, offloaded etc) in the system.

Example of the output of the new command:

uart:~$ net sockets
 Creator  Name       Flags  FD   Lifetime (ms) Sent  Received

    main  af_inet46  6ST    0    3260          819   498
    main  af_inet46  4ST    1    2110          469   142
    main  af_inet46  6DU    2    2110          9941  9941
    main  af_inet46  4DU    3    2110          1375  621

4 active sockets found.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-24 11:11:30 +02:00
Jukka Rissanen
7d9f2ad2ca net: sockets: Add object core support to sockets
Use the generic object core support to track network sockets
and their statistics.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-24 11:11:30 +02:00
Jukka Rissanen
5bf18e39ad net: sockets: Set writefds in case of error in select()
The writefds is typically set if there is an error while
waiting for example the connect() to finish. So check if
the user supplied the writefds and update it accordingly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-24 00:48:03 -07:00
Jukka Rissanen
b864880000 net: sockets: Add SO_ERROR socket option to SOL_SOCKET level
Return the last socket error to user.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-24 00:48:03 -07:00
Robert Lubos
c6fd2b2d44 net: shell: Fix unexpected timeout on loopback ping
In case ping is sent to own address, the request is looped back to the
stack and served before ping work had a chance to reschedule. In result,
when the final ping reply has been server, and ping operation finalized
with `ping_done()`, the work was rescheduled one last time, causing the
ping timeout to be reported. Fix this by rescheduling the work before
sending the actual request, so that the reply handler can cancel the
work properly in such case.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-10-24 09:05:20 +02:00
Jukka Rissanen
63d9c8fa06 net: shell: Print v4-mapping-to-v6 address properly
The remote address of the connection is checked whether
it is v4-mapping-to-v6 address in which case we should
print it such.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 09:57:22 -05:00
Jukka Rissanen
4f37d63ed1 net: Add support for v4-mapping-to-v6 sockets
This allows IPv4 and IPv6 share the same port space.
User can still control the behavior of the v4-mapping-to-v6
by using the IPV6_V6ONLY socket option at runtime.
Currently the IPv4 mapping to IPv6 is turned off by
default, and also the IPV6_V6ONLY is true by default which
means that IPv4 and IPv6 do not share the port space.
Only way to use v4-mapping-to-v6 is to enable the Kconfig
option and turn off the v6only socket option.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 09:57:22 -05:00
Robert Lubos
05361edb1b net: shell: Fix TCP connect behavior
Fix two issues with net tcp command:

* The `net tcp` commands are still based on net_context API. For TCP,
  the API caller (net shell) should add one extra reference to the
  allocated net context, to prevent premature context release in case of
  connection teardown. Currently that was not the case, and the context
  was released too early, resulting in missing final ACK from the Zephyr
  side on connection close.

* The net context API should not be called from the registered connect
  callback, as this creates a temporary deadlock situation. The
  net_context_connect() function blocks until the connection is
  established, or an error or timeout occurs. For that time the
  net_context mutex is being locked. In case of connection error (for
  example after receiving RST packet) the connect callback is called,
  indicating an error. If we try to call net_context API from within, a
  deadlock situation takes place, as the context mutex is still locked
  by the net_context_connect() (called from the shell thread). This
  blocks the further execution of the TCP stack and can result in an
  unexpected behavior (like for example retransmitting the SYN packet,
  which takes place from yet another thread, TCP work queue).
  Fix this, by releasing the net context not from the callback directly,
  but based on the return value from net_context_connect().

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-10-23 16:08:37 +02:00
Yong Cong Sin
1f60c1379e net: shell: fix compilation errors
`suspend.c` and `resume.c` are missing the `zephyr/pm/device.h`
add that to fix compilation warning

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-10-23 14:20:23 +01:00
Jukka Rissanen
046f00244c net: shell: vlan: Enforce arg count via shell macro
Use the SHELL_CMD_ARG() to enforce the minimum parameter
count in vlan command.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
4265fe7a93 net: shell: stats: Use generic iface idx dynamic completion
The interface number is generated automatically if one
presses <tab> when expecting the interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
10def6cac5 net: shell: Allow dynamic interface name expansion
Allow multiple commands use the same dynamic shell command
completion when expecting network interface index.

For example "net iface" and "net stats" are such commands.

The network interface expansion cannot be used in "net ipv6 add",
"net ipv4 add" and "net route" commands as they require more
data after the network interface index argument.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
5bad9680a5 net: shell: Remove the stacks command
The "net stacks" has been obsolete for a long time already
so remove it for good. It is replaced by "kernel stacks" cmd.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
34cd82e80b net: shell: Removing extra stuff that is not needed
The remaining stuff that is not used in net_shell.c can be removed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
aab371364c net: shell: Add websocket command
Move "websocket" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
d84c2572ec net: shell: Add vlan command
Move "vlan" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
82a57b9789 net: shell: Add virtual command
Move "virtual" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
7a167648eb net: shell: Add udp command
Move "udp" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
5afeade2fc net: shell: Add tcp command
Move "tcp" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
7cdc235ff5 net: shell: Add suspend command
Move "suspend" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
fdb86e89a6 net: shell: Add stats command
Move "stats" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
76eab4e440 net: shell: Add stacks command
Move "stacks" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
8b4b064a85 net: shell: Add route command
Move "route" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
cb46113df4 net: shell: Add resume command
Move "resume" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
e5534b5262 net: shell: Add ppp command
Move "ppp" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
58ad0a5c13 net: shell: Add pkt command
Move "pkt" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
a669d4aba3 net: shell: Add ping command
Move "ping" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
0c9fd96604 net: shell: Add nbr command
Move "nbr" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
5b6423dd2f net: shell: Add mem command
Move "mem" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
e0c30bc2b6 net: shell: Add ipv4 command
Move "ipv4" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
36db200c15 net: shell: Add ipv6 command
Move "ipv6" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
49012a5c6b net: shell: Add iface command
Move "iface" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
55eb526d0a net: shell: Add gptp command
Move "gptp" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
97e0609dd9 net: shell: Add events command
Move "events" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
fea7001678 net: shell: Add dns command
Move "dns" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
5a7fd25e97 net: shell: Add conn command
Move "conn" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
e03adee6e4 net: shell: Add capture command
Move "capture" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
0e3b197f84 net: shell: Add arp command
Move "arp" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
e850517a15 net: shell: Add allocs command
Move "allocs" command to a separate file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
3f36f78654 net: shell: Common header for all shell commands
Some useful APIs and macros for all net shell commands
to use.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
394a40470d net: shell: Rename current command as net_old
This is a preparation for the refactoring. The old "net" command
is renamed "net_old" so that the individual commands can be
placed into a separate .c files.
This is done like this because we need to use the
SHELL_SUBCMD_SET_CREATE() to create the sub-command and then
use the SHELL_SUBCMD_ADD() in the .c files to add the command
into the sub-command and not get conflict with the same name
sub-command.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen
56c1bb813f net: shell: Move the shell code to subsys/net/lib/shell
This is preparation commit that moves the net shell code to
subsys/net/lib/shell directory. The following commits will
then refactor the code in net_shell.c to smaller and more
manageable pieces.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Seppo Takalo
a95bafec74 net: lwm2m: Check access rights on composite operations
Composite operations need to check read/write access
rights as well.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-10-20 15:12:39 +02:00
Seppo Takalo
77ea861f12 net: lwm2m: Fix composite operations
As composite operations don't have path in CoAP packet,
it wrongly triggered a check for security object and got
denied the access.

Fixes #64012

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-10-20 15:12:39 +02:00
Seppo Takalo
bd0ad5bd66 net: lwm2m: Initialize empty string sizes correctly on objects
When objects are initialized, empty strings should be set to length of
zero, instead of length of the full buffer.

So use INIT_OBJ_RES_DATA_LEN() to give both, the buffer size and data
length.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-10-20 15:11:32 +02:00
Seppo Takalo
015b1103fb net: lwm2m: Properly initialize buffers for resource instance
When resource instances are initialized, we must calculate
beginning of the data buffer using the index and maximum
data length. Otherwise buffers would overlap with previous.

Fixes #64011

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-10-20 15:11:32 +02:00
Seppo Takalo
36d6a7257b net: lwm2m: Count null-terminator in string size
As the lwm2m_registry.c and specificly lwm2m_set()
functions already ensure null-terminator on string and
count that into string lenght, the content type handlers
should do the same.

When string is written, strlen()+1 is the data length.
When string is read, use the data length, so we don't
leak uninitialized strings. If buffer overrun have
removed the null-terminator the strlen() migh be larger
than data_len.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-10-20 15:11:32 +02:00
Juha Ylinen
1aef034126 net: coap: add support for Echo option (RFC 9175)
Resend the request with Echo option and the received Echo
option value when receiving a 4.01 (Unauthorized) response
with the Echo option.

Add missing header file kernel.h to coap_client.h.

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2023-10-20 15:09:44 +02:00
Juha Ylinen
1d9098f3f0 net: coap: Add support for request-tag (RFC 9175)
Add support for Request-Tag (RFC 9175) when doing block-wise
send.

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2023-10-20 15:09:44 +02:00
Seppo Takalo
8ffb64d46f net: lwm2m: Allow configuring update period
Add new configuration value CONFIG_LWM2M_UPDATE_PERIOD
that allows calculating update period from last update,
instead of calculating it from the lifetime.

In runtime, server is allowed to change the lifetime of the
registration which causes update perdiod to be effected.

When fixed update period is preferred, UPDATE_PERIOD
config is then used.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-10-20 14:57:38 +02:00
Jukka Rissanen
0a16d5c7c3 net: socket: mgmt: Check buf size in recvfrom()
Return EMSGSIZE if trying to copy too much data into
user supplied buffer.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-12 10:33:36 +03:00
Flavio Ceolin
e7bd10ae71 random: Rename random header
rand32.h does not make much sense, since the random subsystem
provides more APIs than just getting a random 32 bits value.

Rename it to random.h and get consistently with other
subsystems.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-10-10 14:23:50 +03:00
Juha Ylinen
22f09e9fa0 net: coap: release non-confirmable messages
Only confirmable messages need pending tracking. Non-confirmable
messages are released after sending.
Match incoming packets with token, not message ID.
Ignore responses with non-matching tokens.
Remove unused function send_reset().

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2023-10-04 11:25:16 +02:00
Robert Lubos
1b21109c2c net: lwm2m: Reset ongoing notification in case token changes
In case observation token changes (the LwM2M server re-sends
observation request to the client), the LwM2M engine should cancel any
ongoing notifications based on the old token. Otherwise, it will be
impossible to match the pending notification reply (ACK) with the
observer context anymore, causing new notifications for this
observation to stall.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-10-04 11:23:53 +02:00
Florian Grandel
630bfff65f net: lib: zperf: fix compiler warning
The compiler emits a "null where non-null expected" warning unless the
argument of strlen is non-null at compile time.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-10-03 15:21:34 +01:00
Florian Grandel
203391a378 net: l2: ieee802154: security config
The "encryption only" security level was deprecated in IEEE
802.15.4-2015. This deprecation has already been introduced in the code
but was overlooked in net config.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-09-29 16:27:31 +02:00
Rahul Singh
6ef75a26ea net: zperf: Add support for bind to host option for tcp/udp download
The current zperf tcp/udp download command doesn't provide the option
to bind the server to a specific host address. If there is more than
one interface, it will not be possible to test each interface with zperf
tcp/udp download command without building the Zpehyr.

This patch will add support for zperf tcp/udp download command to bind
server to host interface address.

Signed-off-by: Rahul Singh <rahul.singh@arm.com>
2023-09-29 16:25:26 +02:00
Juha Heiskanen
647fb4dc8f net: lwm2m: RD client Deregister event indicate
Added a new event for LWM2M_RD_CLIENT_EVENT_DEREGISTER for
indicate LwM2M client dereistartion.

Updated unit test and sample for new event type

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2023-09-29 16:53:55 +03:00
Daniel Leung
d47b1c05f3 kernel: userspace: add k_object_is_valid()
This adds a function k_object_is_valid() to check if a kernel
object exists, of certain type, and has been initialized.
This replaces the same (or very similar) code that has been
copied from kernel into the network subsystem.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-09-28 17:28:43 -04:00
Juha Ylinen
3ffa1d5550 net: coap: Fix coap client timeout
Fix bug in timeout_expired() function. Coap client was resending
pending messages after 500 ms (COAP_PERIODIC_TIMEOUT) and didn't
wait for retransmission timeout.

Use 64-bit k_uptime_get()

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2023-09-28 15:18:12 +02:00
Anas Nashif
6d23a960db lib: os: build fdtable conditionally
Stop building fdtable by default, make it conditional and build it only
when needed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-09-28 06:25:16 -04:00
Pieter De Gendt
cf8f92d73e net: lib: mdns_responder: Fallback IPv4/IPv6 address
If an IPv4 address is requested on an IPv6 interface or vice versa
use a sane default fallback address to send the response.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-09-28 10:53:53 +03:00
Jukka Rissanen
fa4e978fba net: zperf: Fix the IPv6 ping done in shell
The zperf shell sends a IPv6 ping at the start when working
with IPv6. Convert the sending of the ping to use the new API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-09-28 09:34:20 +02:00
Robert Lubos
72cf06ada4 net: config: Add DHCPv6 support
Add DHCPv6 support to the net config library. In case DHCPv6 is enabled,
net config will attempt to acquire IPv6 address and/or prefix when used.
The user can select with Kconfig whether to request address or prefix
(or both).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-09-28 09:31:20 +02:00
Flavio Ceolin
5d505c7b28 random: Fix feature dependency usage
Code using sys_csrand_get should depend on CONFIG_CSPRNG_ENABLED symbol
and not in ENTROPY_HAS_DRIVER since they are not using the entropy
device directly.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-09-27 11:55:10 -05:00
Seppo Takalo
a8f9777586 net: lwm2m: Generate new tokens for LwM2M SEND blocks
Previously each piece of LwM2M SEND was
using token length of zero. I think this was unintentional.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-09-27 15:44:30 +02:00
Seppo Takalo
1606d352e1 net: lwm2m: Append CoAP Etag to protect integrity of blockwise
To protect the integrity of outgoing block-wise transfers, append
Etag option that allows client to see if the received block is
generated from same content as it is expecting.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-09-27 15:44:30 +02:00
Seppo Takalo
ebb90c5184 net: lwm2m: Fix composite read on SenML-CBOR
Composite read was incorrectly trying to parse CoAP packet
instead of payload of the packet.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-09-27 15:44:30 +02:00
Seppo Takalo
69cd597887 net: lwm2m: Refactor blockwise SEND to support GET and FETCH
Allow blockwise-send buffers to be used with GET and FETCH
queries as well.
When outgoing packet is split into multiple blocks, don't free
it when first block is send. Keep it in memory until some other requests
come.

Following queries to next block are matched using CoAP token.
However, this required Leshan to use COAP.BLOCKWISE_REUSE_TOKEN=true
option from Californium.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-09-27 15:44:30 +02:00
Seppo Takalo
b9028bb722 net: lwm2m: Remove unneeded function pointer parameter
lwm2m_udp_receive() is only called with same function
pointer, so there no need to carry that in the parameter.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-09-27 15:44:30 +02:00
Seppo Takalo
4e97607c27 net: lwm2m: Only parse block1 option for WRITE operation
In reality, single-write is the only operation that handles
BLOCK1 operations when receiving paylod.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-09-27 15:44:30 +02:00
Seppo Takalo
f227b56792 net: lwm2m: Separate opaque content format into its own
Opaque content format is not part of clear-text, so it
should be separated into its own file.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-09-27 15:44:30 +02:00
Seppo Takalo
42ce4bbfd7 net: lwm2m: Allow content formats to support only some data types
Partial content format support is required to have a proper support
for content format OPAQUE instead of threading it as a part of
plain text format.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-09-27 15:44:30 +02:00
Seppo Takalo
ebfbf83153 net: lwm2m: Clean up shell documentation
Move commands that require parameters first into the list.

Move syntax line first, command documentation second,
flags last. This is much like Unix commands do

❯ /bin/ls --help
Usage: /bin/ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).

Compared to:

uart:~$ lwm2m
lwm2m - LwM2M commands
Subcommands:
  read    :read PATH [OPTIONS]
          Read value from LwM2M resource
          -x   Read value as hex stream (default)
          -s   Read value as string

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-09-26 16:55:16 +02:00
Seppo Takalo
0a982c3617 net: lwm2m: Add shell command to create object instances
Some testcases might need to be able to create
object instances, so add shell command for it.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-09-21 10:15:34 +02:00
Seppo Takalo
b0303f5bd3 net: lwm2m: Don't allow operations on security object
In spec:
The LwM2M Client MUST reject any LwM2M Server operation on
the Security Object (ID: 0) with an "4.01 Unauthorized" response
 code.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-09-21 09:29:16 +02:00
Seppo Takalo
d8d81a8075 net: lwm2m: Fix build warning on access-control object
With bootstrap one function is unused. Fix by changing
ifdef to if (IS_ENABLED()) so linker can drop it.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-09-21 09:29:05 +02:00
Tobias Frauenschläger
dcc63120cf net: sockets: add support for SO_REUSEPORT
This commits adds support for the SO_REUSEPORT socket option.

The implementation follows the behavior of BSD and tries to also follow
the specific additional features of linux with the following
limitations:
* SO_REUSEADDR and SO_REUSEPORT are not "the same" for client sockets,
  as we do not have a trivial way so identify a socket as "client"
  during binding. To get the Linux behavior, one has to use SO_REUSEPORT
  with Zephyr
* No prevention of "port hijacking"
* No support for the load balancing stuff for incoming
  packets/connections

There is also a new Kconfig option to control this feature, which is
enabled by default if TCP or UDP is enabled.

Signed-off-by: Tobias Frauenschläger <t.frauenschlaeger@me.com>
2023-09-20 08:56:31 +02:00
Tobias Frauenschläger
3d3a221b1e net: sockets: add support for SO_REUSEADDR
This commit adds support for the SO_REUSEADDR option to be enabled for
a socket using setsockopt(). With this option, it is possible to bind
multiple sockets to the same local IP address / port combination, when
one of the IP address is unspecified (ANY_ADDR).

The implementation strictly follows the BSD implementation and tries to
follow the Linux implementation as close as possible. However, there is
one limitation: for client sockets, the Linux implementation of
SO_REUSEADDR behaves exactly like the one for SO_REUSEPORT and enables
multiple sockets to have exactly the same specific IP address / port
combination. This behavior is not possible with this implementation, as
there is no trivial way to identify a socket to be a client socket
during the bind() call. For this behavior, one has to use the
SO_REUSEPORT option in Zephyr.

There is also a new Kconfig to control this feature similar to other
socket options: CONFIG_NET_CONTEXT_REUSEADDR. This option is enabled by
default if TCP or UDP are enabled. However, it can still be disabled
explicitly.

Signed-off-by: Tobias Frauenschläger <t.frauenschlaeger@me.com>
2023-09-20 08:56:31 +02:00
Seppo Takalo
da1463756e net: lwm2m: Allow Bootstrap server to close DTLS connection
Allow Bootstrap server to close the DTLS connection immediately
after receiving Ack to Bootstrap-Finish command.
This is not an error as either parties are allowed to tear down
the connection.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-09-19 15:23:32 +01:00
Seppo Takalo
f49309cf52 net: lwm2m: Add timeouts to state machine
Allow certain RD-client states to timeout.

As stated in LwM2M specification:
    The bootstrap procedure failed when the LwM2M Client did not
    receive the "Bootstrap-Finish" operation after the
    EXCHANGE_LIFETIME time period expired.
    The EXCHANGE_LIFETIME parameter is defined in RFC 7252

We must handle the case where Bootstrap server is not sending
information towards us.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-09-19 15:23:14 +01:00
Weiwei Guo
326d8c79fe net: mqtt-sn: Active mqtt-sn process work when buffer run out
When publish buffer run out, no thread active process work.
Fix this, by reschedule process work.

Signed-off-by: Weiwei Guo <guoweiwei@syriusrobotics.com>
2023-09-19 15:20:09 +01:00
Weiwei Guo
04bb819d20 net: mqtt-sn: Improve thread safety of publish/topic allocators
Current MQTT-SN topic and publish allocators are not thread safe.
Fix this, by using k_mem_slab instead of arrays.

Signed-off-by: Weiwei Guo <guoweiwei@syriusrobotics.com>
2023-09-19 15:20:09 +01:00
Ambroise Vincent
bb450eb26f net: sockets: Keep lock when notifying condvar
Releasing the lock before notifying condvar led to a race condition
between a thread calling k_condvar_wait to wait for a condition variable
and another thread signalling for this same condition variable. This
resulted in the waiting thread to stay pending and the handle to it
getting removed from the notifyq, meaning it couldn't get woken up
again.

Signed-off-by: Ambroise Vincent <ambroise.vincent@arm.com>
2023-09-18 15:41:23 -04:00
Chaitanya Tata
40ee8791f2 net: socketpair: Fix use after free
In low memory conditions, its possible for socketpair memory allocation
to fail and then the socketpair is freed but after that the remote
semaphore is released causing a crash.

Fix this by freeing the socketpair after releasing the semaphore. Add a
test case to induce low memory conditions (low HEAP and high socketpair
buffer size), with the fix issue is not seen.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-09-18 20:34:12 +02:00
Martin Jäger
eae44a55d8 net: lib: sockets: sockets_tls: prefix mbedtls error with 0x
The errors are printed in hex, but no prefix was used. This could be
confused with usual errno return values. The 0x prefix makes clear
that it's a hex value.

Also a missing minus sign is added to one log message.

Signed-off-by: Martin Jäger <martin@libre.solar>
2023-09-18 10:38:44 +01:00
Chaitanya Tata
79158a777b zperf: Add support to configure context priority
This is handy in setting a custom priority for the context either
through shell or API.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-09-12 21:26:28 -04:00
Chaitanya Tata
3b4c529d7e net: Add priority to ping
This is handy in testing of setting priority directly rather than
deriving from DSCP. Please note ICMP doesn't use net context.

This is applicable for both shell and API.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-09-12 21:26:28 -04:00
Florian Grandel
141293ea23 net: l2: ieee802154: settings: make ACK configurable
Add a network configuration option to configure whether IEEE 802.15.4
packets are expected to be ACKed or not.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-09-09 05:18:41 -04:00
Florian Grandel
c88e5360b1 net: l2: ieee802154: fix settings order
In the IEEE 802.15.4 area certain settings must be set before
net_if_up() may be called (e.g. the channel).

Also net_if_up() may not be called if
CONFIG_IEEE802154_NET_IF_NO_AUTO_START=y.

This fixes the set-up order and handling of
CONFIG_IEEE802154_NET_IF_NO_AUTO_START.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-09-09 05:18:41 -04:00
Carles Cufi
8c748fd005 kernel: Modify the signature of k_mem_slab_free()
Modify the signature of the k_mem_slab_free() function with a new one,
replacing the old void **mem with void *mem as a parameter.

The following function:
void k_mem_slab_free(struct k_mem_slab *slab, void **mem);

has the wrong signature. mem is only used as a regular pointer, so there
is no need to use a double-pointer. The correct signature should be:
void k_mem_slab_free(struct k_mem_slab *slab, void *mem);

The issue with the current signature, although functional, is that it is
extremely confusing. I myself, a veteran Zephyr developer, was confused
by this parameter when looking at it recently.

All in-tree uses of the function have been adapted.

Fixes #61888.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2023-09-03 18:20:59 -04:00
Jukka Rissanen
7aa4904b5a net: socket: Change SO_BINDTODEVICE to use interface name
Make sure we use the network interface name (if configured)
instead of device name when binding to certain network
interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-08-31 14:43:36 +02:00
Robert Lubos
d8a96b1be0 net: sockets: tls: Implement TLS_DTLS_CID option
Add TLS_DTLS_CID socket option, which enables to use the Connection ID
extension for the DTLS session.

The option provides control of the use of CID with the `setsockopt()`
function. The value provided can disable, enable, and control whether to
provide a CID to the peer. It uses a random self CID (if told to provide
one to the peer) unless TLS_DTLS_CID_VALUE set previously.

Add TLS_DTLS_CID_VALUE to get or set the CID sent to the peer, if any.

Add TLS_DTLS_PEER_CID_VALUE to get the CID value provided by the peer,
if any.

Add TLS_DTLS_CID_STATUS to determine if CID used, and whether
bidirectional or one way.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Signed-off-by: Pete Skeggs <peter.skeggs@nordicsemi.no>
2023-08-30 11:36:51 +02:00
Gerard Marull-Paretas
8cf63ff367 net: lib: zperf: add missing init.h
File was using SYS_INIT without including init.h.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2023-08-29 12:17:15 +01:00
Robert Lubos
d5252cb5de net: sockets: Fix getsockname()
getsockname() did not work properly on bound sockets, as it verified
whether the socket has an active connection before retuning result. This
is not correct, as socket after bound may not have a connection yet.

Fix this, by verifying that local_addr on an underlying net_context is
set, to determine whether socket has a local address assigned, before
returning result.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-08-27 07:35:34 -04:00
Georgij Cernysiov
f15508d505 net: lib: coap: refactor client init path options
* Renamed 'coap_client_init_path_options' to
  'coap_packet_set_path'
* Moved into 'coap.c'
* The function is public now

Signed-off-by: Georgij Cernysiov <geo.cgv@gmail.com>
2023-08-25 13:15:12 +02:00
Georgij Cernysiov
afbfdc5bd7 net: lib: coap: fix path and query options init
Fix options initialization for path and query
when a final segment is one character long.

For example, "a/b" inits path as ["a"] instead
of expected ["a", "b"]. The same applies to
query option. The "a/abc?a&b"  options won't
contain "b".

Signed-off-by: Georgij Cernysiov <geo.cgv@gmail.com>
2023-08-25 13:15:12 +02:00
Robert Lubos
6e1a205819 net: sockets: Fix connected datagram socket packet filtering
The previous patch to address race condition on STREAM sockets had a
side effect on DGRAM socket, where net_context_recv() is not only
installing recv callback, but also registering a connection at net_conn
level. Doing so before setting remote address first (which is done in
net_context_connect()) had an impact on the connected DGRAM socket
operation, which now accepted packets from any remote peer, and not only
the one socket was connected to.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-08-25 10:31:19 +02:00
Seppo Takalo
40dd0c1fa0 tests: lwm2m: Add bootstrap tests into RD client tests
Add bootstrap and few corner cases into RD client tests
to improve code coverage.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-08-24 22:07:32 +01:00
Seppo Takalo
37f145a2d9 net: lwm2m: Ensure string termination when reading empty data
When resource data length is set to zero, we still need to
ensure that string reading will return an empty string.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-08-24 22:07:32 +01:00
Daniel Leung
842a65914f net: lwm2m: ignore -Wshadow for cbor type header file
There are a few structs, unions, and enums where -Wshadow would
complain. Since names being the same are intentional, we need
to tell compiler to ignore -Wshadow for those names.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-22 11:39:58 +02:00
Daniel Leung
2b09426fca net: zperf: rename shadow variables
Rename shadow variables found by -Wshadow.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-22 11:39:58 +02:00
Christopher Friedt
4a095bb34b net: sockets: support fionbio and fionread
The `ioctl()` interface is already supported by the network
subsystem but there was no `zsock_` interface available for it.

Add the `zsock_ioctl()` syscall.

Implement two somewhat commont ioctl requests for socket
file descriptors; namely

- `FIONBIO` set non-blocking I/O mode
- `FIONREAD` get the number of available bytes

In the process, added `net_pkt_ip_proto_hdr_len()`

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-08-22 09:59:44 +02:00
Christopher Friedt
501c56cce7 net: socketpair: support for fionbio
Support for setting non-blocking mode via `ZFD_IOCTL_FIONBIO`.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-08-22 09:59:44 +02:00
Christopher Friedt
e0ac4eb5cd net: sockets: socketpair: support querying bytes available
In order to get a semi-accurate assessment of how many
bytes are available on a socket prior to performing a read,
BSD and POSIX systems have typically used

`ioctl(fd, FIONREAD, &avail)`

We can support this in Zephyr as well with little effort, so
add support for `socketpair()` sockets as an example.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-08-22 09:59:44 +02:00
Christopher Friedt
1fa2ea1c82 net: sockets: tcp: split recv_stream into immediate and timed
Previously, if a net_context had multiple packets already in
the receive queue, and a call to zsock_recvfrom() was made with
a buffer large enough to receive content from multiple packets,
only the content from a single receive buffer would be received.

Since zsock_recvfrom() is a system call, which has a
non-negligible overhead, it makes sense to receive as many bytes
as possible per system call.

Add zsock_recv_stream_immediate() as a shorthand for
"fill this receive buffer with as many bytes as possible without
blocking". Allow nullable buffer parameters so that we can also
have a shorthand for "count how many bytes are immediately
available".

With minor refactoring, zsock_recv_stream_timed() is a simple
wrapper around zsock_recv_stream_immediate() that handles timing
and error conditions.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-08-22 09:59:44 +02:00
Lukas Woodtli
3b4e54e39e net: coap: Add function to check for block option in message
The added function allows to check if a descriptive block
option was already added to a message.

Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
2023-08-16 17:06:41 +02:00
Lukas Woodtli
e13e90914a net: coap: Add function for removing block transfer option
In some cases the options of a CoAP message are reused for
block transfer. Then the block header needs to be updated.
The current approach is to remove the old block option and
add an updated one.

Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
2023-08-16 17:06:41 +02:00
Lukas Woodtli
6277a3904a net: coap: Add function for removing CoAP options
The provided function allows to remove a CoAP option in a
message. This is useful for reusing parts of a message.

Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
2023-08-16 17:06:41 +02:00
Lukas Woodtli
038351ad26 net: lwm2m: Cleanup unnecessary code
The reply callback doesn't need to handle the case when the
code of the reply is 'continue' (2.31). In that case the callback
is not executed until the last block is transmitted.

Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
2023-08-16 13:04:11 +02:00
Lukas Woodtli
2f6c0d7ca3 net: coap: Improve the handling of CoAP response code 'continue'
When using block-wise transfer, call the reply callback only when
the last block arrived.

Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
2023-08-16 13:04:11 +02:00
Andreas Chmielewski
7df43f1ce3 net: lwm2m: Added support Conn Monitoring object version 1.3
This adds support for Coverage Enhancement Level.

Signed-off-by: Andreas Chmielewski <andreas.chmielewski@grandcentrix.net>
2023-08-16 13:03:45 +02:00
Juha Heiskanen
be492db27b net: lwm2m: Fix race condition on Firmware object
Fix possible race conditions when state and results are written
by locking the registry, so a first write does not cause Notify
message to be send too early.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2023-08-16 13:03:07 +02:00
Sjors Hettinga
81650746f7 net: socket: Make the send timeout configurable
When the protocol layer like TCP is blocking transmission, the socket
layer will attempt and wait for a maximum amount of time before returning
with an ENOBUFS error.
This change allows to set the maximum waiting time from the configuration
file instead of using a fixed 10 second value.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2023-08-16 10:30:33 +02:00
Seppo Takalo
cb42c9b6bb net: lwm2m: Add delay also to exec callbacks
Bootstrap executable cause socket to be closed, so
it requires some delay for Ack to be send out as well.
Similarly, add small delay for Update trigger, so the
possible Ack goes out before the actual update message.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-08-16 10:21:46 +02:00
Seppo Takalo
01dab8690a net: lwm2m: Do not immediately close connection at Bootstrap
When BOOTSTRAP FINNISH message was received, it caused
engine to immediately switch to BOOTSTRAP_TRANS_DONE state
which then closed the connection.
Ack packet was still on the send-queue so it never got send before close().

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-08-16 10:21:46 +02:00
Seppo Takalo
a13af44c7a net: lwm2m: All state changes should go through set_sm_state()
Some state changes were do by directly writing into
client.engine_state variable, followed by call next_event_at(0);
This causes hard-to-find side effects.

Refactor all state transitions to use set_sm_state() to have better
control for it.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-08-16 10:21:46 +02:00
Seppo Takalo
68b1fc8478 net: lwm2m: Wake up engine on pause/resume
Engine wake-up call was missing from pause/resume APIs
which caused delay.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-08-16 10:21:46 +02:00
Daniel Leung
5bc08ae3c6 net: rename shadow variables
Renames shadow variables found by -Wshadow.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-10 08:14:43 +00:00
Daniel Mangum
775a8e8c8d net: sockets: use DTLS in NET_SOCKETS_TLS_MAX_APP_PROTOCOLS
Updates NET_SOCKETS_TLS_MAX_APP_PROTOCOLS Kconfig option description to use
DTLS instead of DTL.

Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
2023-08-07 11:27:33 +02:00
Seppo Takalo
321db8561d net: lwm2m: Restructure LwM2M Kconfig menu
* Create submenu for protocol versions.
  Like LwM2M 1.0 vs 1.1. Object versions.
* Create submenu for engine features.
  Containing all engine tweaks that are not directly from
  protocol specification.
* Create submenu for all memory tuning options.
  For example maximum number of certain objects, buffer
  sizes, etc.
* Order all objects by object ID and show the ID in
  title.
* When multiple options depend on same feature, group
  them under if <option> ... endif. Preferably directly
  after the selection itself.
* Move IPSO and uCIFI menuentries one sublevel up.
* Drop deprecated entries to bottom.

No functional changes, just clean up of Kconfig menu.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-08-07 11:26:47 +02:00
Seppo Takalo
838ab80bca net: coap: Use 64bit timestamps
Use 64bit timestamps from k_uptime_get() so they don't
roll over during the expected device lifetime.

Fixes #60826

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-08-01 15:40:04 +02:00
Seppo Takalo
518bbc1303 net: lwm2m: Refactor RD client to be tickless
Call RD client service only when there is state transitioning.
Remove periodic 500 ms timer.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-08-01 12:07:12 +02:00
Seppo Takalo
2da8844d19 net: lwm2m: Add support for non-periodic services
Engine now allows registering service callbacks that are
called only once on a given timestamp.
This allows tickless services to be developed.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-08-01 12:07:12 +02:00
Seppo Takalo
1dfa711167 net: lwm2m: Create socketpair that can wake up zsock_poll()
Allow socket-loop to wake up immediately, if there are changes,
instead of waiting for zsock_poll() to timeout.
This change makes engine more reactive and removes
hard coded timeout from zsock_poll().

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-08-01 12:07:12 +02:00
Seppo Takalo
c8ac3070cc net: sockets: socketpair: Allow statically allocated socketpairs
When the target board does not have heap by default, allows
statically reserving the space for required socketpairs.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-07-31 14:49:05 +02:00
Nicolas Pitre
bd3ed97230 subsys/net: zperf_udp_uploader: Remove sys_clock_timeout_end_calc() usage
The initial goal was to remove sys_clock_timeout_end_calc(). However,
several related issues have been fixed as well.

First this:

    int64_t print_interval = sys_clock_timeout_end_calc(K_SECONDS(1));
    /* Print log every seconds */
    int64_t print_info = print_interval - k_uptime_ticks();

    if (print_info <= 0) {
        [...]
    }

The above condition will simply never be true.

Then there is lots of back-and-forth time conversions using expensive
base-10 divisions for each loop iterations which is likely to impact
performance.

Let's do the time conversion only once outside the loop and track
everything in terms of ticks within the loop. Also the various timeouts
are open-coded based on the absolute uptime tick so to sample it only
once per round. Using sys_timepoint_calc() and sys_timepoint_timeout()
would have introduced additional uptime tick sampling which implies the
overhead of a downstream lock each time for no gain. For those reasons,
open coding those timeouts bears more benefits in this particular case
compared to using the timepoint API.

Then this:

    secs = k_ticks_to_ms_ceil32(loop_time) / 1000U;
    usecs = k_ticks_to_us_ceil32(loop_time) - secs * USEC_PER_SEC;

The above should round down not up to work accurately. And the usecs
value will become garbage past 1.2 hour of runtime due to overflows.

And no need to clamp the wait period which is on the microsec scale
using the total duration argument being on the millisec scale. That's
yet more loop overhead that can be omitted. The actual duration is
recorded at the end anyway.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2023-07-25 09:12:26 +02:00
Nicolas Pitre
7238b48182 subsys/net: zperf_tcp_uploader: move to timepoint API
Remove sys_clock_timeout_end_calc() usage.
While at it, remove dead last_print_time variable.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2023-07-25 09:12:26 +02:00
Nicolas Pitre
603cdaa032 subsys/net/lib/socket: move to timepoint API
Remove sys_clock_timeout_end_calc() usage and custom timeout_recalc().

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2023-07-25 09:12:26 +02:00
Jordan Yates
83b1a983a9 net: lib: tls_credentials: earlier initialisation
The TLS credentials libraries are purely software constructs with no
external dependencies, run them immediately after the kernel setup to
allow other initialisation functions to add credentials without the
requirement to run in the back half of the `APPLICATION` priority.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-07-12 14:50:09 +02:00
Seppo Takalo
aaa9cedf18 net: lwm2m: Update next event timestamp on PMAX change
When PMAX value is changed, it should update all events.
I believe there is a bug that caused the code only to update
events that are ongoing (to be send).

Now if PMAX changes, next event timestamp is recalculated.

Fixes #59397

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-07-05 11:16:06 +02:00
Jarno Lämsä
7ae4e24728 net: lib: lwm2m: Use int16_t for signal strength
The signal strength for the connectivity monitor was
defined as int8_t, however this was too small for
LTE RSRP values, which has range [-140,-44].

Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
2023-06-29 10:04:14 +00:00
Jarno Lämsä
419fa3ca6a net: lib: coap: CoAP client, multiple request handling
Use only single thread for handling polling of the sockets.
Each client will have only 1 active socket which to poll.
Each client can have multiple simultaneous requests ongoing.
The client only has one buffer for receiving and one buffer for sending.
Therefore the messages are reformed when resending.

Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
2023-06-28 15:19:34 +02:00
Tommi Kangas
f124c0d06a net: lib: coap: Use zsock_ functions
Use Zephyr internal zsock_ calls to remove dependency
to NET_SOCKETS_POSIX_NAMES.

Signed-off-by: Tommi Kangas <tommi.kangas@nordicsemi.no>
2023-06-28 06:49:59 +00:00
Seppo Takalo
6050a10f8b net: lwm2m: Allow setting string to zero length
Lwm2m firmware object have defined a write of zero length
string as a cancel operation.
So allow lwm2m_set_opaque(path, NULL, 0);

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-06-27 12:18:35 +00:00
Seppo Takalo
dc7fbc5d2e net: lwm2m: Fix pause and resume on non-closed sockets
Pause and resume functionality was written into assumption
that sockets are closed before resuming.

With use new options CONFIG_LWM2M_RD_CLIENT_STOP_POLLING_AT_IDLE
or CONFIG_LWM2M_RD_CLIENT_LISTEN_AT_IDLE this is not always true.
Fix the state machine, so that on those cases, sockets are not
closed and resume is always similar like from the QUEUE mode.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-06-26 12:37:13 +00:00
Seppo Takalo
5c1228770e net: lwm2m: Add support for X509 certificates
Add support for using X509 certificates.
Default settings use ECDSA certificates with SHA256 hash.

When different settings are required clients should overwrite
struct lwm2m_ctx->load_credentials() and
struct lwm2m_ctx->set_socketoptions()

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-06-26 12:35:29 +00:00
Seppo Takalo
95cef5f3ab net: lwm2m: Ensure string termination
When writing string data to resources which are string types,
we should count in the terminating character into the data length.

Corner cases exist where LwM2M resource type is opaque but
lwm2m_get_string() or lwm2m_set_string() are used to read/write
the data. We must ensure string termination on those case, but
terminating character must not be stored in the engine buffer
or counted in the data length as this might be considered
as part of the binary data.

Fixes #59196

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-06-21 10:42:31 +02:00
Luca Fancellu
38a43b0eec net: config: Add VLAN identifier as network initial configuration
Add a new Kconfig parameter NET_CONFIG_MY_VLAN_ID as initial network
configuration to enable users to set VLAN identifier at startup.

Add a new setup_vlan(...) function to setup the VLAN identifier in
the device, the call have an effect only when NET_CONFIG_MY_VLAN_ID
is above zero.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
2023-06-21 09:32:41 +02:00
Saravanan Sekar
bdb26cfe02 net: mqtt: close tcp socket after websocket_disconnect
websocket_disconnect api does not closes mqtt's tcp socket, so
tcp socket must be closed after done.

Signed-off-by: Saravanan Sekar <saravanan@linumiz.com>
2023-06-19 09:18:45 +01:00
Saravanan Sekar
3c9f3b7849 net: websockets: do not close tcp socket in websocket
The websocket_connect api expects connected tcp socket, do not close
the user supplied socket so that the caller can re-use it if needed.

Signed-off-by: Saravanan Sekar <saravanan@linumiz.com>
2023-06-19 09:18:45 +01:00
Daniel Leung
1e1ab38bf0 net: syscalls: use zephyr_syscall_header
This adds a few line use zephyr_syscall_header() to include
headers containing syscall function prototypes.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-06-17 07:57:45 -04:00
Juha Heiskanen
d6c85c2f59 net: coap: CoAP reply handler fix
Fix corner case when client RX request with same token than
own request where it wait responses.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2023-06-13 07:06:08 -04:00
Florian Grandel
378f0dd29d net: lib: zperf: fix kernel panic due to invalid thread prio
Compiling an application with CONFIG_NET_ZPERF=y leaving
CONFIG_ZPERF_WORK_Q_THREAD_PRIORITY at its default value would
systematically cause a kernel panic during thread initialization.

The Kconfig variable is NUM_PREEMPT_PRIORITIES by default. Application
threads may not define a priority lower than NUM_PREEMPT_PRIORITIES - 1,
though.

This change limits zperf's thread priority to a valid range. It does not
change the default value as it makes sense to default the thread
priority to the lowest possible value (which is NUM_PREEMPT_PRIORITIES)
but Kconfig does not allow for arithmentic. So the combination of
CLAMP() plus the Kconfig default will ensure min priority plus limit the
range to valid values no matter what has been defined as priority in
Kconfig.

Fixes: #59141

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-13 06:58:15 -04:00
Robert Lubos
f9a818cc56 net: websockets: Fix implicit type conversion Coverity warning
Coverity reported potential issues with implicit signed/unsigned type
conversions and potential problems with this. Fix this, by casing the
byte-shifted data variable to uint64_t type explicitly.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-06-07 10:11:46 -04:00
Robert Lubos
e5aa433f87 net: lwm2m: Fix pointless variable assignment
Coverity reported that assigning ret = 0 is pointless, as in any
scenario (loop continues or ends) the ret variable is overwritten
anyway, w/o using the assigned value. Therefore remove the needless
assignment.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-06-07 10:07:09 -04:00
Robert Lubos
479036165c net: lwm2m: Fix possible out-of-bound access when creating FW object
obj_inst_id should not be used directly to index the instance array, as
the instance ID is not tightly bound to the maximum instance count and
can exceed this value, causing out-of-bound access.

Therefore, perform some extra validation when choosing the array index
for the object instance to make sure we stay in the array bounds, or
return an error if there's no more room for more object instances, in a
similar way it's done for Security object.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-06-07 10:06:52 -04:00
Robert Lubos
e96f1d7b47 net: lib: coap: Fixed unchecked send return value in CoAP client
The retransmission attempt in CoAP client library did not verify the
send result.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-06-07 10:06:29 -04:00
Mark Oude Elberink
67dd58418f net: mqtt-sn: fix port in mqtt-sn debug message
The port we are connecting to is stored in network byte order,
thus, we need to convert it to the CPU's byte order before logging

Signed-off-by: Mark Oude Elberink <mark@oude-elberink.de>
2023-06-06 09:40:52 -04:00
Seppo Takalo
a1cfe983b6 net: lwm2m: Allow overiding of default socket behaviour
In order to support external IP stacks that might have Connection
ID support, the LwM2M engine should allow client to bypass default
behaviour.

New set_socketoptions() callback added into client context
that allows overriding all socket opetions. This is called
after a socket is opened, but before the connect() is
called. This cannot be combined with load_credentials() callback
on all platforms as for example nRF91 requires modem offline
when credentials are written. This would cause socket to be closed
as well.

Second change is that we allow fine tuning of what we do with
socket handle when QUEUE mode is enabled and engine enters idle
state.

First option would be to close the socket. That would cause
TLS Alert(Close Notify) to be send. This is a band choice if
LTE modem was already in PSM or eDRX power saving mode.

Second option would be to delay socket closing until we
are going to send LwM2M update. There TLS Alert is also send,
but most probably lost due to NAT mapping timed out. This
is a best choice for LTE modem with DTL session cache enabled.

Two new options are to keep socket open, and either stop listening
or just keep listening. Both of these options work fine when
we have DTLS Connection ID support.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-06-06 09:40:16 -04:00
Robert Lubos
2e0b0af44e net: lwm2m: Fix lwm2m_socket_start() error handling
In case lwm2m_socket_start() internal error, it should only do cleanup
on the socket, i. e. call lwm2m_socket_close(), not lwm2m_engine_stop().
The latter resets the entire lwm2m_context, which results in removal of
active observations.

This should not be done, as it collides with the RD client logic, where
connection resumption may skip the full registration phase, in result
not notifying the server that it should restart the observations.

At the same time, the RD client should clean the lwm2m_context when it's
done trying to update the registration and proceeds with regular
registration/bootstrap in the network error handler. In that case, only
the socket was closed, so the lwm2m_context needs to be reset
separately.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-06-06 06:51:34 -04:00
Robert Lubos
0ae7812f6b net: dns_sd: Prevent dead code in query parsing
The number of buffer provided was verified in the final else block of a
long validation sequence. It would never be executed though, as one of
the conditions before would always evaluate to true.

As the number of buffers provided verification appears to be significant
in this case, as the buffers are referenced during other validations,
move this check at the beginning of the sequence instead. This also
eliminates the dead-code problem.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-06-03 04:13:46 -04:00
Robert Lubos
16fa99a887 net: coap: Validate token length in coap_header_get_token()
In theory, coap_header_get_token() should only be used on already parsed
packets, and coap_packet_parse() would detect an invalid token length in
a packet. Coverity however complains about possible out-of-bound access,
as in theory the function can return token length up to 15. Therefore
add an extra validation of the token length within the function, to
avoid out-of-bound access due to programming errors and to make Coverity
happy.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-06-02 15:13:41 -04:00
Robert Lubos
fa5b706871 net: websocket: Implement websocket_recv_msg timeout
Although websocket_recv_msg function accepts timeout parameter, the
functionality was rather limited, allowing only to either work in
non-blocking manner, or to block indefinitely. Any timeout value
other than -1 (forever) ended up in non-blocking operation.

This PR fixes this by implementing a basic timeout mechanism, built on
top of poll(). For now on, only timeout of 0 will result in non-blocking
operation, any other timeout will make the function block for the
specified amount of time.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-05-31 11:07:10 +02:00
Robert Lubos
e6fc53b399 net: sockets: tls: Allow to interrupt blocking accept() call
In order to allow the TLS accept() call to be interrupted, it should
release the top-level TLS socket mutex before blocking. As the
underlying TCP accept() makes no use of TLS resources, and has its own
mutex protection, it should be safe to do so.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-05-29 14:34:03 -04:00
Robert Lubos
76b74f007f net: sockets: Fix accept() not being interrupted on close()
The accept() so far would block with mutex held, making it impossible to
interrupt it from another thread when the socket was closed.

Fix this, by reusing the condvar mechanism used for receiving. It's OK
to use the same routine, as underneath accept() is monitoring the same
FIFO as recv().

Additionally, simplify k_fifo_get() handling in accept() - as the
waiting now takes place on condvar, it can be used in a non-blocking
manner. Blocking accept() call should not reach this place if there's no
new incoming connection waiting on the FIFO.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-05-29 14:34:03 -04:00
Marco Argiolas
49436dc453 net: lib: lwm2m: add missing #include to lwm2m_rd_client.h
Definition for 'struct lwm2m_ctx' was missing and build warnings were
generated.

Signed-off-by: Marco Argiolas <marco.argiolas@ftpsolutions.com.au>
2023-05-29 04:57:18 -04:00
Robert Lubos
2c75070360 net: sockets: tcp: Fix possible race between connect/recv
Installing recv callback with net_context_recv() after
net_context_connect() left an opening for a possible race - in case the
server send some data immediately after establishing TCP connection, and
Zephyr did not manage to install the callback on time, the data would be
lost, corrupting the stream.

This can be avoided, by installing the recv callback before the
connection is triggered. As net_context_recv() called w/o timeout only
registers the callback function, it should have no negative impact. The
only change on the TCP side is when the connection is closed - in case
TCP is in connect stage, do not call the recv callback (before this
change it'd be NULL at that point).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-05-26 09:55:13 -04:00
Jarno Lämsä
05e0b31fa8 net: lib: coap: Add an asynchronous coap client
The coap client takes requests and provides responses
asynchronously to callback given in a request.
Currently supports only 1 request at a time.

Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
2023-05-26 09:44:50 -04:00
Robert Lubos
966eff642f net: sockets: Fix recv() not being interrupted on close()
In case recv() call was waiting for data, and the socket was closed from
another thread, the recv() call would not be interrupted, causing the
receiving thread to be blocked indefinitely.

Fix this, by signalling the condvar the recv() call is waiting on
close(). Additionally, close will now set the socket into error mode,
with EINTR as the error condition, allowing the blocked calls to
recognise that the call was interrupted, and return a proper error code
on the event.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-05-26 09:05:12 -04:00
Gerard Marull-Paretas
dacb3dbfeb iterable_sections: move to specific header
Until now iterable sections APIs have been part of the toolchain
(common) headers. They are not strictly related to a toolchain, they
just rely on linker providing support for sections. Most files relied on
indirect includes to access the API, now, it is included as needed.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-22 10:42:30 +02:00
Lukas Woodtli
fb924e2b62 net: lwm2m: Handle CONTINUE in registration message
The continue code is not considered an error in case of
block-wise transfer.

Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
2023-05-15 09:18:09 +02:00
Lukas Woodtli
73fb4e73a8 net: lwm2m: Handle CONTINUE response and send new block
After sending a CoAP block and receiving the CONTINUE response
code the next block is sent.

Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
2023-05-15 09:18:09 +02:00
Lukas Woodtli
49f8d08f98 net: lwm2m: Split message into blocks for sending
Add functionality that creates blocks from a big payload body.

Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
2023-05-15 09:18:09 +02:00
Lukas Woodtli
3707a0d229 net: lwm2m: Provide buffer for block transfer
Allow to use a buffer for the complete message body if block transfer is
enabled. This buffer is used when serializing the message. For sending
the message the body is split into blocks.

Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
2023-05-15 09:18:09 +02:00
Lukas Woodtli
12de4018ef net: coap: Add function for getting BLOCK1 option
The function gets the the BLOCK1 option from a received message
and extracts the block number, block size and has-more flag from
it.

Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
2023-05-15 09:18:09 +02:00
Lukas Woodtli
db480169a0 net: coap: Add function for inserting block option for sending
The function adds a block option to a CoAP message. If the message
is a request the BLOCK1 option is added. Otherwise (response) the
BLOCK2 option is added.

Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
2023-05-15 09:18:09 +02:00
Georges Oates_Larsen
716c19f7ef net: conn_mgr: Reorganize files
Since conn_mgr is a subsystem rather than a library, relocate it
directly into subsys/net rather than subsys/net/lib/

Rename header files to better match their function.

Remove net_ prefix from conn_mgr types, API, and files, since it is
unnecessary.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-05-11 12:15:44 +02:00
Flavio Ceolin
9b1da61d6a lwm2m: kconfig: Fix experimental feature
select EXPERIMENTAL for experimental option.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-05-10 11:41:50 +02:00
romain pelletant
75dd2c9904 net: lwm2m: use path as block context retrieval
Replace block context retrieval using object path instead of token.
Update block context structure
Fix issue #57165

Signed-off-by: romain pelletant <romain.pelletant@fullfreqs.com>
2023-05-03 10:01:37 +02:00
Robert Lubos
c43c408783 net: if: Add possibility to disable ND per interface
Add new network interface flag, which allows to disable Neighbour
Discovery protocol from being used on the interface. This allows to
interfaces that do not support ND (like OpenThread) to coexist with
other IPv6 interfaces.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-04-29 12:24:49 +02:00
Hein Wessels
2689e16670 net: sntp: support building without NET_SOCKETS_POSIX_NAMES
Fixes the compiler error that occurs when attempting to build
the SNTP library with CONFIG_NET_SOCKETS_POSIX_NAMES=n, while
using native_posix.

Closes #57133

Co-authored-by: Chris Friedt <cfriedt@meta.com>
Signed-off-by: Hein Wessels <heinwessels93@gmail.com>
2023-04-24 09:23:17 -04:00
Pieter De Gendt
7de95b76a6 net: lib: dns: mdns_responder: Fix ipv4/ipv6 address handling
This commit simplifies the arguments for sending dns responses
and fixes an issue where both the ipv4 and ipv6 member of a header
union were accessed.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-04-19 11:55:40 -04:00
Pieter De Gendt
292bb97f0d net: lib: dns: mdns_responder: Simplify setup_dns_addr
The setup_dns_addr function packet argument can be reduced to
a socket address family.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-04-19 11:55:40 -04:00
Pieter De Gendt
e5b52ac034 net: lib: dns: dns_sd: Improve debug prints
Duplicate logging prints make it hard to find the origin.
This commit does a cleanup of the debug messages printed.

Also change the level of an invalid record to debug as this
is out of our control.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-04-19 11:55:40 -04:00
Wojciech Slenska
c3575fbd2e net: sockets: fix POLLOUT for offloaded iface
For offloaded iface net_tcp_get is never called, so context->tcp
is always NULL. In that case net_tcp_tx_sem_get will return wrong pointer.
For pollout k_poll will be called with NULL semph,
which cause HardFault.

Signed-off-by: Wojciech Slenska <wsl@trackunit.com>
2023-04-19 17:15:12 +02:00
Øyvind Rønningstad
31c10f5fe1 lwm2m_senml_cbor_encode.c: Manually edit whitespace
since it crossed the 100 column cutoff, even after clang-format.

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2023-04-18 15:22:02 +02:00
Øyvind Rønningstad
d0c278af78 lwm2m_senml_cbor: Regenerate code files using zcbor 0.7.0
and the _regenerate.sh script.

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2023-04-18 15:22:02 +02:00
Øyvind Rønningstad
e9eb61bd14 lwm2m_senml_cbor: Update the regenerate script and the patch file
Do patch file application before clang-format.
Add copyright to generated files using the --file-header option in zcbor.

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2023-04-18 15:22:02 +02:00
Georges Oates_Larsen
7c4397ae79 net: conn_mgr: connectivity API
Allows L2s to declare generic association/connection routines
that can be bound by name to ifaces.

Allows L2-agnostic control over connectivity/association for
iface that support it.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-04-18 09:31:53 +02:00
Daniel Nejezchleb
663b684fea net: socket: fix hanging net contexts
Calls put instead of unref on net contexts
in the socket accept function.
Mere unref didn't subtract the reference
count of net context which leaves
it in used state. This situation happens
in case of accepting already
closed connection.

Signed-off-by: Daniel Nejezchleb <dnejezchleb@hwg.cz>
2023-04-17 15:12:41 +02:00
Daniel Nejezchleb
ee720b5412 net: socket: asynchronous connect
Added a feature of socket connect
being asynchronous. If socket is set
to nonblock with O_NONBLOCK flag,
then connect() is non-blocking aswell.
App can normally poll the socket to
test when the connection is established.

Signed-off-by: Daniel Nejezchleb <dnejezchleb@hwg.cz>
2023-04-17 11:35:20 +02:00
romain pelletant
eab19663a9 net: lwm2m: add callback for send confirmation
Issue #52328

Signed-off-by: romain pelletant <romainp@kickmaker.net>
2023-04-17 11:29:14 +02:00
Seppo Takalo
1dd9d514f1 net: lwm2m: Move utility functions from engine
Some utility functions belong to lwm2m_util.c.
Block contexts belong to lwm2m_message_handling.c

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-04-12 17:44:37 +02:00
Gerard Marull-Paretas
a5fd0d184a init: remove the need for a dummy device pointer in SYS_INIT functions
The init infrastructure, found in `init.h`, is currently used by:

- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices

They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:

```c
struct init_entry {
	int (*init)(const struct device *dev);
	/* only set by DEVICE_*, otherwise NULL */
	const struct device *dev;
}
```

As a result, we end up with such weird/ugly pattern:

```c
static int my_init(const struct device *dev)
{
	/* always NULL! add ARG_UNUSED to avoid compiler warning */
	ARG_UNUSED(dev);
	...
}
```

This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:

```c
static int my_init(void)
{
	...
}
```

This is achieved using a union:

```c
union init_function {
	/* for SYS_INIT, used when init_entry.dev == NULL */
	int (*sys)(void);
	/* for DEVICE*, used when init_entry.dev != NULL */
	int (*dev)(const struct device *dev);
};

struct init_entry {
	/* stores init function (either for SYS_INIT or DEVICE*)
	union init_function init_fn;
	/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
	 * to know which union entry to call.
	 */
	const struct device *dev;
}
```

This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.

**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

init: convert SYS_INIT functions to the new signature

Conversion scripted using scripts/utils/migrate_sys_init.py.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

manifest: update projects for SYS_INIT changes

Update modules with updated SYS_INIT calls:

- hal_ti
- lvgl
- sof
- TraceRecorderSource

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: devicetree: devices: adjust test

Adjust test according to the recently introduced SYS_INIT
infrastructure.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: kernel: threads: adjust SYS_INIT call

Adjust to the new signature: int (*init_fn)(void);

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-12 14:28:07 +00:00
Robert Lubos
afaf4cddd2 net: sockets: tls: Implement handshake timeout
Currently, the handshake operation could only be fully blocking or
non-blocking. This did not play well if SO_RCVTIMEO was set for DTLS
server, as the recv() call where the blocking handshake was used, could
block indefinitely, ignoring the timeout parameter. Fix this, by
allowing for the handshake operation to timeout.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-04-12 11:09:58 +02:00
Robert Lubos
9082d4b98e net: sockets: tls: Implement TLS/DTLS socket TX/RX timeout
As the underlying socket operations for TLS/DTLS are now non-blocking,
it's no longer possible to rely on the underlying socket timeout
handling. Instead, implement SO_RCVTIMEO/SO_SNDTIMEO at the TLS socket
layer.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-04-12 11:09:58 +02:00
Robert Lubos
81be0f6d73 net: sockets: tls: Switch DTLS to use non-blocking socket operations
As for TLS, switch to use non-blocking operations on underlying socket.
This is a bit tricker for DTLS, as there were not truly blocking bio
(binary input/output) function for DTLS, as timeout had to been
implemented. It is possible though to implement non-blocking mbedTLS bio
function instead, and handle timeout outside of mbedTLS context, which
has been done in this commit.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-04-12 11:09:58 +02:00
Robert Lubos
ee48ddc205 net: sockets: tls: Switch TLS to use non-blocking socket operations
Switch TLS sockets to use non-blocking socket operations underneath.
This allows to implement the socket blocking outside of the mbedTLS
context (using poll()), and therefore release the mutex for the time the
underlying socket is waiting for data. In result, it's now possible to
do blocking TLS RX/TX operations simultaneously from separate threads.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-04-12 11:09:58 +02:00
Robert Lubos
96e14ba91f net: sockets: tls: Implement ZFD_IOCTL_SET_LOCK handling
Implement ZFD_IOCTL_SET_LOCK so that TLS socket layer gets access to the
mutex protecting socket calls.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-04-12 11:09:58 +02:00
Seppo Takalo
1c6a853528 net: lwm2m: Default lifetime is also a minimum accepted lifetime
If server or bootstrap writes a lifetime value less than
configured default lifetime, client will automatically overwrite
the value with default one.

This gives better control for the application where client
behaviour is fine tuned on the Kconfig, but default values
from bootstrap server cannot be fine-tuned.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-04-06 14:15:04 -05:00
Seppo Takalo
3a241592b5 net: lwm2m: Remove lwm2m_path_to_string
This function had only one use in SenML CBOR formatter and it
contained some specific tweaks, so move the function to be a
static member of that module.

Fixes #53674

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-04-06 15:37:21 +02:00
Seppo Takalo
567b2510b8 net: lwm2m: Allow stopping while paused
When LwM2M engine is paused, stop functionality just
marks the intent and when we resume, it will send the
de-registration if that was requested.
Otherwise it will stay in SUSPENDED state until resumed
and then goes into ENGINE_DEREGISTERED -> IDLE.

This also removes the blocking loop from lwm2m_rd_client_stop().
It does not need to block because lwm2m_rd_client_start()
is already checking if client is in IDLE.

Fixes #56254

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-04-06 14:21:49 +02:00
Robert Lubos
162c0f64c2 tests: net: websocket: Fix test execution on 64-bit platforms
Instead of passing the test parameters to the websocket function, by
casting the pointer to integer (which may not work on 64-bit platform
due to int/pointer size mismatch), let the test allocate a file
descriptor, and initialize it with test context. The tested functions
expect a file descriptor as an argument anyway, so it's a more intuitive
approach.

The conditional test code within WS implementation can retrieve the test
context by using FD APIs to obtain the object represented by the FD.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-04-05 15:01:50 +02:00
Keith Packard
3f3224d880 subsys/net: Labels cannot be applied to declarations
C only permits labels on statements, not declarations.  Separate the
declarations from the assignments so that the labels can target
statements instead.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-04-05 10:38:34 +02:00
Kumar Gala
b9a63b805e lwm2m: fix armclang compiler warnings with is*() functions
We get compile warnings of the form:

error: converting the result of
'<<' to a boolean; did you mean
'((__aeabi_ctype_table_ + 1)[(byte)] << 28) != 0'?
 [-Werror,-Wint-in-bool-context]
                if (!isprint(byte)) {
                     ^

Since isprint (and the other is* functions) return an int, change check
to an explicit test against the return value.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-03-31 14:01:24 +02:00
Kumar Gala
19b6b1fb30 dns: fix armclang compiler warnings with is*() functions
We get compile warnings of the form:

error: converting the result of
'<<' to a boolean; did you mean
'((__aeabi_ctype_table_ + 1)[(byte)] << 28) != 0'?
 [-Werror,-Wint-in-bool-context]
                if (!isprint(byte)) {
                     ^

Since isprint (and the other is* functions) return an int, change check
to an explicit test against the return value.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-03-31 09:19:09 +02:00
Andreas Chmielewski
357181be23 net: lwm2m: Add is_suspended() routine
Add is_suspended() routine to have control over the rd client from the
outside whether it is suspended.

Signed-off-by: Andreas Chmielewski <andreas.chmielewski@grandcentrix.net>
2023-03-28 15:06:15 +02:00
Chris Friedt
ff2efd7ae5 net: socket: socketpair: remove experimental status
Socketpair functionality has matured enough to be used in a
consistent way now regardless of architecture or platform,
even on `native_posix`.

Remove the experimental status to reflect that.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-03-25 07:05:53 -04:00
Robert Lubos
66ae9153a6 net: sockets: Fix SO_SNDTIMEO handling
The TX timeout configured with SO_SNDTIMEO on a socket did not work
properly. If the timeout was set on a socket, the TX would work as if
the socket was put into non-blocking mode. This commit fixes this.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-03-20 16:54:41 +01:00
Robert Lubos
616797c429 net: sockets: Add helper function for recalculating remaining timeout
The timeout recalculation logic was duplicated across several routines,
therefore it makes sense to make a helper function out of it,
especially, that the same functionality would be needed for the send
routines.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-03-20 16:54:41 +01:00
Krishna T
36c46afbb9 net: zperf: Make Zperf worker thread stack size configurable
All stack sizes should be configurable for memory adjustements.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2023-03-20 10:20:00 +00:00
Krishna T
d6e54a417a net: zperf: Make Zperf worker thread priority configurable
This helps us test impact of scheduling on traffic.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2023-03-20 10:20:00 +00:00
Luca Fancellu
6748d588ab net: zperf: allow TCP receiver to handle multiple connections
Currently the zperf_tcp_receiver can handle only one TCP connection
each time, modify the code to poll and handle multiple connections.

Take the occasion to unify the bind and listen part of the code
between ipv4 and ipv6 part using a structure introduced to handle
the multiple connections.

Now in case the zsock_recv fails, we can't stop every connection
and fail through the error label, so just print the error message
and report the failure through the callback.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
2023-03-16 12:56:10 +01:00
Luca Fancellu
d485ef0231 net: zperf: Reduce the scope of input address variables
Reduce the scope of in4_addr_my and in6_addr_my pointer variables
that are currently global, but they are used only inside
tcp_receiver_thread.

Take the occasion to fix a typo in one error message.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
2023-03-16 12:56:10 +01:00
Jun Qing Zou
aae379f245 net: mqtt: Debug logging of pointers
Cast pointer to `void *` for `%p` parameter.
Otherwise lots of warnings in the log like below:

 `<wrn> cbprintf_package: (unsigned) char * used for %p argument.
 It's recommended to cast it to void * because it may cause
 misbehavior in certain configurations. String:"%s: (%p): >>
 length:0x%08x cur:%p, end:%p" argument:3`

Signed-off-by: Jun Qing Zou <jun.qing.zou@nordicsemi.no>
2023-03-15 15:02:47 +01:00
Stig Bjørlykke
6862fdea1a net: dns: Check existing DNS servers before reconfigure
In dns_resolve_reconfigure() check if the DNS servers already exist
before cancel all ongoing queries. This will solve an issue with
getaddrinfo() returning DNS_EAI_CANCELED when receiving a retransmitted
DHCP offer and when receiving a IPv6 Router Advertisement.

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2023-03-14 12:27:15 -04:00
Michal Ciesielski
43c08d5c3f lwm2m: Fix multi res inst, create flags and post write callback for SWMGMT
The multi resource and create flags were reversed, meaning that resources
were defined as multi resource but weren't being created by default. That
doesn't reflect the LWM2M Software Management, which specifies which
objects can be multi resource and which are mandatory.

The post write callbacks were assigned to the validate callbacks.

Signed-off-by: Michal Ciesielski <michal.m.ciesielski@voiapp.io>
2023-03-13 11:58:29 +01:00
Julien Vermillard
a9349fe74d net: lwm2m: Typo in LWM2M_IPSO_TIMER description
Changed description to "IPSO Timer Support" in place of "Light Control
Support"

Signed-off-by: Julien Vermillard <julien@vermillard.com>
2023-03-11 08:46:22 +02:00
Vidar Lillebø
ca3d0c8ee9 mbedtls: Remove dependency on MBEDTLS_BUILTIN for MBEDTLS_DEBUG
Allows using MBEDTLS_DEBUG functionality when not using MBEDTLS_BUILTIN.

Signed-off-by: Vidar Lillebø <vidar.lillebo@nordicsemi.no>
2023-03-10 09:30:32 +01:00
Sebastian Arnd
3cd58c29bf net/lib: mqtt_sn: Fix MQTT-SN IPv6 Support and assertation in Example
1. `zsock_socket()` gets the right packet familiy.
2. `inet_pton()` returns 1 on success.

This should address #55193.

Signed-off-by: Sebastian Arnd <sebastianarnd@gmail.com>
2023-03-09 09:20:53 +01:00
Chris Friedt
79d4107beb net: http: define http service and resource iterable sections
Provide a means of declaring zero or more HTTP services, each
with zero or more static HTTP resources.

Static HTTP resources are those which have fixed paths[1] which
are known prior to system initialization. Some examples of
static http resources would be

* a forwarder from '/' to '/index.html'
* a REST endpoint with fixed path '/api/foo' and detail
  pointing at some implementation-specific function
* a Javascript file in string form with fixed path '/js/util.js'
* a 'construction' image with path '/res/work.png'
* a gzip-compressed 'Hello' HTML file at '/hello.html'

Without describing in any detail how static HTTP resources are
organized or served by any given HTTP server, we can describe
what static resources exist on a system in a common way that
does not require any optional facilities (e.g. filesystem) and
relies only on addressable memory.

Additionally, for the purposes of simply allowing others
to implement custom HTTP servers in a consistent way, or
benchmarking implementations, or having a consistent testsuite
to use across multiple implementations, it is helpful to have
a common method to declare HTTP services and static resources
for Zephyr.

[1] https://en.wikipedia.org/wiki/URL

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-03-08 13:57:13 +00:00
Dave Lacerte
96c8d16986 net: lwm2m: Add IPSO voltage sensor object
Add support fot the IPSO voltage sensor object

Signed-off-by: Dave Lacerte <lacerte.dave@hydroquebec.com>
2023-03-06 12:34:22 +01:00
Marc Lasch
072a5da433 net: lwm2m: Register callback for firmware update cancel
Allow to register a callback function which is called when a firmware
update is canceled by the cancel command.

Signed-off-by: Marc Lasch <marc.lasch@husqvarnagroup.com>
2023-03-06 12:33:12 +01:00
Lucas Dietrich
c7f9eafeec net: http: Make http_client.c compile with CONFIG_NET_SOCKETS_POSIX_NAMES=n
Use internal constant ZSOCK_POLLIN instead of POLLIN to
 make the http_client source file compile without error with
CONFIG_NET_SOCKETS_POSIX_NAMES disabled.

 Fixes #55423

Signed-off-by: Lucas Dietrich <ld.adecy@gmail.com>
2023-03-05 08:51:25 -05:00
Jeroen van Dooren
1be74ac6d7 net: dns: prevent crash on nullptr as callback
When a query is done, the query isn't set to NULL.
This can cause a nullptr exception in invoke_query_callback().

Signed-off-by: Jeroen van Dooren <jeroen.van.dooren@nobleo.nl>
2023-03-02 21:58:07 -05:00
Luca Fancellu
d61dcf2f1d net: zperf: improve code quality for tcp_received function
Currently, in tcp_received function defined in zperf_tcp_receiver
module, the assignment of session->state to STATE_COMPLETED is
overwritten on the same path to STATE_NULL and a session is
considered free for both STATE_COMPLETED and STATE_NULL, so remove
the assignment to STATE_NULL.
Remove the break from the STATE_COMPLETED case handling so that it
can fallthrough, in case the same session is used after finish.
Remove also the STATE_LAST_PACKET_RECEIVED case because this state
is never reached.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
2023-02-28 18:12:52 +01:00
Luca Fancellu
7c4ea08db8 net: zperf: fix typo in error messages
Fix typo in error messages from the zperf_tcp_receiver where UDP
is written instead of TCP.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
2023-02-28 18:12:52 +01:00
Luca Fancellu
910de7f83d net: zperf: unify get_session among TCP and UDP
The modules zperf_udp_receiver and zperf_tcp_receiver use two
different functions to get a zperf session to store the
statistics, there is a TODO comment in the zperf_session module
suggesting to unify that part.
So delete the get_tcp_session function and use get_session for
both TCP and UDP receiver module.
Delete sock field from struct session because it's not used
anymore.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
2023-02-28 18:12:52 +01:00
Luca Fancellu
1a12a070eb net: zperf: add configurable for the zperf sessions number
Currently the maximum number of zperf sessions handled is hardcoded
to 4, create a Kconfig parameter, with default value 4, to make the
maximum number of sessions configurable.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
2023-02-28 18:12:52 +01:00
Jun Qing Zou
755f0b7d27 net: tftp: Add client context
Use client context to seperate buffer usage.
Use new `TFTP_EVT_DATA` event to send data to application.
Use new `TFTP_EVT_ERROR` event to report error to application.
Update `tftp_get()` and `tftp_put()` API to use the client context.

Signed-off-by: Jun Qing Zou <jun.qing.zou@nordicsemi.no>
2023-02-28 10:29:30 +01:00
Stefan Schwendeler
596a3bd996 net: lwm2m: bugfix lwm2m shell exec command with optional parameter
Actually `execute_cb` is fed with an array of char* and the size of
that array, instead of a single char* buffer and its byte size.

This fix expects a single, already joined, optional shell argument and
feeds `execute_cb` with proper arguments.

Signed-off-by: Stefan Schwendeler <Stefan.Schwendeler@husqvarnagroup.com>
2023-02-27 11:34:42 +01:00
Sjors Hettinga
c51cf4f08d net: websocket: Make sure the mbedtls_sha1 function is build in
In the header the websocket protocol needs a SHA1 hash. This is
implemented using the mbedtls_sha1 function. Select the option
MBEDTLS_MAC_SHA1_ENABLED from the Kconfig of websocket to ensure this
function is build in.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2023-02-24 18:12:14 +01:00
Seppo Takalo
abb3163d82 net: lwm2m: Clear out the timestamp when we start registration
There was a corner case that last registration timestamp was used
to detect if we can try UPDATE instead of full registration.

When timestamp was not cleared and DNS resolving failed, it might
cause engine to skip the resolving and continue retrying an UPDATE
message until timeout.

Fixes #54504

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-02-22 14:26:31 +01:00
Seppo Takalo
d8b8d53f5f net: lwm2m: Drop observations when falling back to registration
When we have establised an DTLS handshake and try LwM2M Update,
if the server rejects it, we fall back to sending full registration
but when doing so, we should also clear out any observations.

It was intentional that we don't go to ENGINE_DO_REGISTRATION
state as that would close the socket and cause DTLS handshake.

Fixes #54974

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-02-22 14:26:31 +01:00
Seppo Takalo
96a4bedd30 net: lwm2m: Don't ignore socket errors when sending
Only socket error that we should ignore is EAGAIN (EWOULDBLOCK),
others might be indicating that there are some serious errors
in network layer.
When network stack would block us, just drop the packet and
let CoAP layer handle the retrying.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-02-22 14:26:31 +01:00
Seppo Takalo
ea1eb28135 net: lwm2m: Fix build issue on time-series cache
This was only missing a variable declaration.

Fixes #55031

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-02-22 14:26:20 +01:00
Seppo Takalo
bf49540a8d net: lwm2m: Add const qualifier to many pointers
Various functions, mostly concerning time-series cache, were not
using const pointer while they still did not modify the content.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-02-22 14:26:20 +01:00
Stefan Schwendeler
4662c40888 net: lwm2m: read command uses hexdump as default print format
A default format that does always print something useful.

Signed-off-by: Stefan Schwendeler <Stefan.Schwendeler@husqvarnagroup.com>
2023-02-22 08:50:56 +01:00
Stig Bjørlykke
0f71a130ef net: sockets: getaddrinfo: Minor refactoring
Minor refactoring in getaddrinfo() to make the code easier to
read and to make handling IPv4 and IPv6 support more equal.

- Move common wait and error handling code to exec_query()
- Use the same check for CONFIG_NET_IPV4 and CONFIG_NET_IPV6
- Add extra sanity check for family before exec_query()
- Do not set errno when return DNS_EAI_ADDRFAMILY

Fix issue with setting port number for all DNS servers.

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2023-02-21 15:02:35 +01:00
Krishna T
b136676772 net: lib: zperf: Add support to disable Nagle's algorithm
This helps in benchmarking smaller packets, esp. as this is the default
behaviour of iperf.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2023-02-20 09:53:43 +01:00
Jun Qing Zou
cd79b81d4d lib: tftp_client: Add TFTP PUT function
Add tftp_put() API to support TFTP WRITE request.

Signed-off-by: Jun Qing Zou <jun.qing.zou@nordicsemi.no>
2023-02-20 09:50:23 +01:00
Jun Qing Zou
f7b0ccba0c lib: tftp_client: Receive file with arbitrary size
Add a callback for READ request to download files with arbitrary length.
Define TFTP_BLOCK_SIZE in API header for application to allocate buffer.

Signed-off-by: Jun Qing Zou <jun.qing.zou@nordicsemi.no>
2023-02-20 09:50:23 +01:00
Juha Ylinen
fdffdedc41 net: lwm2m: Add event LWM2M_RD_CLIENT_EVENT_REG_UPDATE
New event LWM2M_RD_CLIENT_EVENT_REG_UPDATE to indicate
application that engine starts registration update.

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2023-02-19 20:44:02 -05:00
Robert Lubos
004955f715 net: config: Unify the init behaviour when timeout is enabled and not
Currently, if timeout is not configured for the network initialization in
the config module, the initialization function will configure IPv4/IPv6/
DHCPv4 regardless of the interface status. This is not the case when the
timeout is set, and the interface was not brought up during the timeout
period. This lead to ambiguity in terms of interface initialization.

This commits unifies the behaviour between these two cases. The
aforementioned initializations will always take place, regardless of the
interface status. The IPv4/IPv6 and DHCPv4 routines should be prepared
to deal with interfaces that are not brought up. The only difference
now, between timeout and no timeout scenario, is that the former will
report an error in case the timeout occurs wile waiting for the expected
events.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-02-08 11:26:42 +01:00
Seppo Takalo
437bfc58d9 net: lwm2m: Fix deregistration timeout state handling
Socket faults or timeouts in CoAP deregistration messages
caused RD client state machine to restart registration.

Fixes #54136

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-02-08 11:20:00 +01:00
Chris Friedt
c093678784 net: sockets: fix fcntl.h usage
If we are using `CONFIG_ARCH_POSIX`, then include
`<fcntl.h>`. Otherwise, include `<zephyr/posix/fcntl.h>`
since there are no requirements to use `CONFIG_POSIX_API`
internally.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-02-08 19:04:25 +09:00
Chris Friedt
ac3efe70cd net: sockets: socketpair: header fixups
* include `<zephyr/posix/fcntl.h>` instead of `<fcntl.h>`
* drop unused logging header and module declaration
* reorder headers alphabetically

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-02-08 19:04:25 +09:00
Lukas Woodtli
6a5260394b net: coap: Allow insertion of an option at arbitrary position
The insertion moves the data in the message buffer to make space for
the new option.

Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
2023-02-06 10:02:19 +01:00
Robert Lubos
432ff20a72 net: websockets: Fix websocket close procedure
The websocket implementation did not comply with the RFC 6455 when it
comes to connection close. The websocket should send in such case Close
control frame. This commit fixes this behaviour.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-02-03 10:37:57 -08:00
Robert Lubos
7f0219985d net: websockets: Fix ZFD_IOCTL_SET_LOCK handling
The websocket "socket" layer did not handle ZFD_IOCTL_SET_LOCK command,
and just forwarded it to the underlying socket. This overwritten the
mutex pointer used by the underlying socket, resulting in erroneous
behaviour in certain cases.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-02-03 10:37:57 -08:00
Seppo Takalo
d0dc67a72d net: lwm2m: Fix native_posix fcntl() calls
Native POSIX target still needs to use the <fcntl.h> header
instead of <zephyr/posix/fcntl.h>

Also removed the include from various files that did not use it.

Also changed fcntl() calls to zsock_fcntl() because we directly
use zsock_* calls elsewhere.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-02-02 20:05:08 +09:00
Jared Baumann
5a62f2592f net: lib: Fix build warning for sockets_tls
Fixes issue where a build warning would be emmited for sockets_tls.c due
to usage of the deprecated fcntl.h header file.

Signed-off-by: Jared Baumann <jared.baumann8@t-mobile.com>
2023-01-28 08:01:03 -05:00
Seppo Takalo
ec8884d58f net: lwm2m: lwm2m_client: Fix fcntl header path
We don't default to POSIX_API so use Zephyr's
path for fcntl.h

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-01-27 10:41:19 -06:00
Robert Lubos
4234e801b5 net: sockets: Fix TLS_HOSTNAME option length inconsistency
The TLS_HOSTNAME socket option expects a NULL terminated string and
doesn't really care about the optlen provided. However, as the option
expects that the string is NULL terminated, the optlen value should take
NULL character into account, for consistency across the codebase.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-01-27 19:23:36 +09:00
Juha Heiskanen
1f84409b48 net: lwm2m: Trace clean
Cleaned Trace message print.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2023-01-25 15:08:07 +00:00
Andreas Chmielewski
022ff636da net: lwm2m: rd_client: added init function
To write tests it is necessary to offer init function for the RDClient
to define custom fakes before.

Signed-off-by: Andreas Chmielewski <andreas.chmielewski@grandcentrix.net>
2023-01-25 14:55:02 +00:00
Wouter Cappelle
aaefd3db7e net: http: Use poll for http timeout instead of shutdown
Change the http timeout mechanism to use poll instead of shutdown.
This should fix a problem where the shutdown will be called in a
different thread context which can lead to deadlocks on certain
driver implementations like offloaded modem drivers.
Fixes #53967

Signed-off-by: Wouter Cappelle <wouter.cappelle@crodeon.com>
2023-01-24 14:50:11 +01:00
Chris Friedt
c2a62f4ad7 net: sockets: conditionally include zephyr/posix/fcntl.h
Only include `<fcntl.h>` for `CONFIG_ARCH_POSIX`. Otherwise,
include `<zephyr/posix/fcntl.h>`.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-01-23 09:57:31 -08:00
Chris Friedt
6ac402bb3a net: socket: additional POSIX constants
The POSIX spec requires that `SO_LINGER`, `SO_RCVLOWAT`,
and `SO_SNDLOWAT`, and `SOMAXCONN` are defined in
`<sys/socket.h>`. However, most of the existing socket
options and related constants are defined in
`<zephyr/net/socket.h>`.

For now, we'll co-locate them. It would be
good to properly namespace things.

Additionally, a no-op for setsockopt for `SO_LINGER` to
make things Just Work (TM) for now.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-01-23 09:57:31 -08:00
Veijo Pesonen
f0258dbe4d net: lwm2m: Sufficient memory for resource names
Full resource names aren't as long as combined basename- and name-buffer
sizes but the compiler doesn't know it. Increasing the buffer size to
avoid the compiler warning.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2023-01-19 12:03:27 +01:00
Jarno Lämsä
abafd7e810 net: lib: lwm2m: Replace deprecated function calls
Replace calls to deprecated functions with new ones.

Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
2023-01-19 10:16:22 +01:00
Jarno Lämsä
3b3463ecba net: lib: lwm2m: Deprecate string based enable cache
Deprecate the old API and replace with new one which uses
the lwm2m_obj_path struct instead of a string.

Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
2023-01-19 10:16:22 +01:00
Jarno Lämsä
460dd6530f net: lib: lwm2m: Deprecate string based send
Deprecate send API using the string references as paths.
Replace it with one using path structs.

Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
2023-01-19 10:16:22 +01:00
Jarno Lämsä
49cf96858f net: lib: lwm2m: Deprecate buffer set get API
Deprecate old API and make new API using path structs
instead of using old string reference based paths.

Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
2023-01-19 10:16:22 +01:00
Jarno Lämsä
bca0550413 net: lib: lwm2m: Deprecate callback registration API
Deprecate old API and create new API using path structs
instead of string references to paths.

Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
2023-01-19 10:16:22 +01:00
Jarno Lämsä
a2e52c5607 net: lib: lwm2m: Deprecate observation API
Add new APIs using the lwm2m path structs instead of
string references to paths.

Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
2023-01-19 10:16:22 +01:00
Jarno Lämsä
5c80be9379 net: lib: lwm2m: Deprecate object and resource API
Deprecate old API and offer a new API for object and resource
creation and deletion. The new API uses path struct instead
of using a string as a reference to a path.

Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
2023-01-19 10:16:22 +01:00
Jarno Lämsä
15d81a8914 net: lib: lwm2m: Deprecate string based set get API
Use the lwm2m_obj_path struct instead and deprecate old.

Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
2023-01-19 10:16:22 +01:00
Pascal Brogle
6ac281887c net: lwm2m: fix observation path list ordering
under certain conditions the current implementation did not maintain
the desired sort order.

Signed-off-by: Pascal Brogle <pascal.brogle@husqvarnagroup.com>
2023-01-13 13:47:27 +01:00
Pascal Brogle
cc40bc33ba net: lwm2m: fix senml max name size
base name or name can contain up to two shorts.
(object id & object intstance or resource id & resource instance id)

Signed-off-by: Pascal Brogle <pascal.brogle@husqvarnagroup.com>
2023-01-13 12:02:07 +00:00
Pascal Brogle
b6bc324a1d net: lwm2m: rename path size define
Rename max path constant to prevent string length vs data size confusion

Signed-off-by: Pascal Brogle <pascal.brogle@husqvarnagroup.com>
2023-01-13 12:02:07 +00:00
Pascal Brogle
b178ff5246 net: lwm2m: fix senml cbor compiler warning
use size_t instead of assuming uint32_t

Signed-off-by: Pascal Brogle <pascal.brogle@husqvarnagroup.com>
2023-01-13 12:00:13 +00:00
Robert Lubos
76dd77df7e net: zperf: Fix potential build warning
A variable was defined directly after a label in two case statements,
resulting in build warning with certain compilers.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-01-10 14:07:21 +00:00
Juha Ylinen
5e4eeb104d net: lwm2m: Verify data buffer size in lwm2m_engine_set()
Check data buffer size and return error if
     * buffer size is too small for opaque or string data type
     * buffer size is not equal to res data length when data type
       is fixed size

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2023-01-05 14:39:01 +00:00
Pascal Brogle
60bf310aae net: lwm2m: fix senml cbor object link encoding
use text format instead of tlv format

Signed-off-by: Pascal Brogle <pascal.brogle@husqvarnagroup.com>
2023-01-05 12:43:24 +01:00
Juha Heiskanen
a70f420b2b net: lib: Patch file for generated code fix
Patch for generated lwm2m senml-cbor.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2023-01-05 12:43:24 +01:00
Juha Heiskanen
d939c79af1 net: lib: LwM2M SenML-Cbor regenrated files update
Patched and fixed regenerated code.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2023-01-05 12:43:24 +01:00
Juha Heiskanen
637c9bbf95 net: lib: regenerate cbor code using zcbor
with the updated cddl for object links.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2023-01-05 12:43:24 +01:00
Pascal Brogle
547c3063b9 net: lwm2m: support senml cbor object link
use "vlo" map key

Signed-off-by: Pascal Brogle <pascal.brogle@husqvarnagroup.com>
2023-01-05 12:43:24 +01:00
Juha Ylinen
eb914f45d1 net: lwm2m: Check return value from lwm2m_rd_client_pause/resume
Check return values from lwm2m_rd_client_pause() and
lwm2m_rd_client_resume() when engine thread suspend is requested.

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2023-01-05 12:43:00 +01:00
Juha Ylinen
c7a5f7fda7 net: lwm2m: Deprecate Kconfig for LwM2M RD Client
RD-Client is essential part of LwM2M specification and it can't
be disabled from LwM2M engine. This commit deprecates Kconfig
variable CONFIG_LWM2M_RD_CLIENT_SUPPORT and removes
all usages if it.

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2023-01-03 13:23:46 +01:00
Marco Argiolas
2527320848 net: lib: sntp: add support for unspecified IP-family type
`sntp_simple()` was forcing to resolve SNTP-server's URL into IPv4 address
addresses. This was not allowing sntp_init() to succeed in case the system
 did not support IPv4 addresses (returning EPFNOSUPPORT, ie. Protocol
Family error).
Now by default SNTP has unspecified family type and it relies on
`net_getaddrinfo_addr_str()` to be able to resolve literal server URLs
into the supported IP family type.

Signed-off-by: Marco Argiolas <marco.argiolas@ftpsolutions.com.au>
2023-01-03 11:03:25 +01:00
Marco Argiolas
d51182d57d net: lib: sockets: support IPv6-only use case with AF_UNSPEC
Setting `hints.ai_family` to `AF_UNSPEC` was causing
`net_getaddrinfo_addr_str()` and in turn `getaddrinfo()` to resolve the
literal SNTP SERVER first into IPv4 and then (if supported) IPv6 addresses.
 This was causing useless waste of time and memory in case IPv4 was not
supported. In addition, in case IPv4 addresses were not supported, other
system components (eg. SNTP) could fail due to the DNS returning IP
addresses with unsupported family type (ie. IPv4).
Now, if address family is not explicitly set to `AF_INET` (ie. IPv4), then
 no attempt is made to resolve SNTP server address into an IPv4 address.

Signed-off-by: Marco Argiolas <marco.argiolas@ftpsolutions.com.au>
2023-01-03 11:03:25 +01:00
Juha Ylinen
7dfa2c8a2b net: lwm2m: Add shell commands
Add shell commands to read and write native time_t value.

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2023-01-03 11:03:16 +01:00
Seppo Takalo
a33f3b6abb net: lwm2m: Add shell command to enable timeseries cache
Add shell command

  cache   :Enable data cache for resource
           cache PATH NUM
           PATH is LwM2M path
           NUM how many elements to cache

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-01-03 11:02:54 +01:00
Juha Heiskanen
1800e629e6 net: lwm2m: LwM2M times series data update
Fixed problem for matching path url with or without '/'
by change time series data structure to use struct lwm2m_obj_path.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2023-01-03 11:02:54 +01:00
Juha Heiskanen
3abd9c364a net: lwm2m: LwM2M Object path equal API
Added new API for check is 2 object path equal.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2023-01-03 11:02:54 +01:00
Juha Ylinen
16b6892294 net: lwm2m: Refactor lwm2m_information_interface_send()
Call lwm2m_send_message_async() from function
lwm2m_information_interface_send() and remove duplicate code.

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2023-01-03 11:02:44 +01:00
Juha Ylinen
1111184b74 net: lwm2m: Remove lwm2m_send_message() from public API
lwm2m_send_message() sends a message directly to the socket. Remove
the function from public API and combine the code with
socket_send_message().

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2023-01-03 11:02:44 +01:00
romain pelletant
5c14c56f2c net: lwm2m: add binaryappdatacontainer obj support
OMA LwM2M object 19 support for application specific binary data
Related issue #53340

Signed-off-by: romain pelletant <romainp@kickmaker.net>
2023-01-03 11:02:09 +01:00
Krishna T
59842531d1 net: zperf: Make shell dependency optional
Now that we a proper API, shell is just optional, so, make the
dependency optional by refactoring the code.

Also, add a build test combination in twister.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2023-01-03 11:02:01 +01:00
Juha Heiskanen
4a50f9362f net: lib: LwM2M rd client fix
Fix LwM2M rd client stop call hang when Queue client is at
RX_ON_IDLE_STATE. Added miossing connection resume for
de-register functionality.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-12-22 15:50:31 +00:00
Juha Ylinen
1827636ab6 net: lwm2m: Verify receiving buffer size in lwm2m_engine_get()
Check receiving buffer size and return error if
 * buffer size is too small for opaque or string data type
 * buffer size is not equal to data lenght when data type is
   fixed size

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2022-12-22 13:44:27 +01:00
Robert Lubos
d27ace4012 net: zperf: Simplify shell initialization
Instead of calling zperf shell initialization routine on the first
command execution, initialize it during system boot, along with other
zperf submodules.

Remove redundant IP address configuration on an interface. The default
configuration relies on NET_CONFIG module, so there's no need to set the
address manually in zperf.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-12-22 11:05:11 +01:00
Robert Lubos
7a2c8d2ab8 net: zperf: Shell cleanup
Zperf shell functionality is now encapsuled within a single file,
therefore it no longer makes sense to have a separate shell_utils
file.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-12-22 11:05:11 +01:00
Robert Lubos
dd3fb692fe net: zperf: Add shell command to stop TCP/UDP server
Add zperf shell command to stop TCP/UDP server.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-12-22 11:05:11 +01:00
Robert Lubos
87ca1c3329 net: zperf: Make UDP/TCP servers restartable
Make the TCP/UDP server functionality restartable. Provide a public API
to stop the TCP/UDP server.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-12-22 11:05:11 +01:00
Robert Lubos
cd4f7cbc61 net: zperf: Add public API to start TCP/UDP server
Add public API for zperf download functionality. The TCP/UDP server
modules are decoupled from shell, allowing to trigger download directly
from the application code. The shell submodule makes use of this new
public API.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-12-22 11:05:11 +01:00
Robert Lubos
722ed07287 net: zperf: Add shell option for asynchronous upload
Add shell option to the UDP/TCP upload command, which allows to execute
the upload asynchronously. This allows to unblock the shell for other
commands during the upload.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-12-22 11:05:11 +01:00
Robert Lubos
fde9577e24 net: zperf: Implement asynchronous upload API
Add an API which allows to perform UDP/TCP upload operations
asychronously.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-12-22 11:05:11 +01:00
Robert Lubos
812a1bc152 net: zperf: Define a public upload API for the library
This commit defines a public API for zperf upload functionality. The
UDP/TCP uploader modules are decoupled from shell, allowing to perform
uploads directly from the application code. The shell submodule makes
use of this new public API.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-12-22 11:05:11 +01:00
Erwan Gouriou
66d4c64966 all: Fix "#if IS_ENABLED(CONFIG_FOO)" occurrences
Clean up occurrences of "#if IS_ENABLED(CONFIG_FOO)" an replace
with classical "#if defined(CONFIG_FOO)".

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-12-21 10:09:23 +01:00
Grixa Yrev
2a992c65c0 net: websocket: new receiving algorithm
websocket_recv_msg() is reworked with using fsm. Now the function
return 0 when payload is empty, -ENOTCONN if socket close. Receiving
empty ping and sending empty pong were added in tests.
Fixes #52327

Signed-off-by: Grixa Yrev <grixayrev@yandex.ru>
2022-12-20 17:05:12 +00:00
Reto Schneider
c646a5576a net: zperf: Fix SO_RCVTIMEO dependency
Since 6c30c9ac47 (samples: net: zperf:
Rewrite upload part to use sockets), zperf uses SO_RCVTIMEO in UDP mode,
hence must depend on/enable support for it.

Without SO_RCVTIMEO support, zperf fails like this:
> nb_packets=47   delay=188964    adjust=-13
> setsockopt error (109)
> setsockopt error (109)
> -
> Upload completed!
> LAST PACKET NOT RECEIVED!!!
> Statistics:             server  (client)
> Duration:               0 us    (10.19 s)
> Num packets:            0       (50)
> Num packets out order:  0
> Num packets lost:       0
> Jitter:                 0 us
> Rate:                   0 Kbps  (9 Kbps)

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
2022-12-15 17:14:26 +01:00
Marco Argiolas
f8f3629efd net: lib: lwm2m: add uCIFI LPWAN object
Add support for Low Power Wide Area Network (LPWAN) Object (ID 3412)

Signed-off-by: Marco Argiolas <marco.argiolas@ftpsolutions.com.au>
2022-12-14 09:51:38 +01:00
Yanqin Wei
00cdb7afa2 net: zperf: fix incorrect statistics of zperf
The sequence id from iperf starts with 1. The commit changes the
initial value of "next_id" in zperf from 0 to 1. In addition, the
error output of "error" and "out of order" packets is corrected.

Signed-off-by: Yanqin Wei <Yanqin.Wei@arm.com>
2022-12-09 11:18:25 +01:00
Anas Nashif
cffe98d9de crc: Make the build of crc function dependent on a Kconfig
Add CONFIG_CRC for building CRC related routines.
CRC routines are now being built for each application, whether used or
not and are add in the build system unconditionally.

Keep CONFIG_CRC enabled by default for now and until all users have
converted to use the new option.

Partial fix for #50654

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-11-23 13:30:00 +01:00
Veijo Pesonen
f467410088 net: lwm2m: shell - allow leading slash
Paths should start from root.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-11-11 08:49:25 +00:00
Ryan Erickson
12b4187092 lwm2m: swmgmt: fix observations not working for resources
The pointers to resource values should not be used
directly to update the values.
This will break observations if the server is trying to
observe changes during a software update.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2022-11-10 09:27:54 +01:00
Markus Fuchs
ea17d5152d net: sockets_tls: Fix memory leak in socket
Fix file descriptor leak on unsupported socket protocols.

Signed-off-by: Markus Fuchs <markus.fuchs@ch.sauter-bc.com>
2022-11-09 10:44:44 +01:00
René Beckmann
26758117d6 net: mqtt-sn: Add MQTT-SN library
This commit adds an implementation of MQTT-SN v1.2.
The specification is available on oasis-open.org:
https://www.oasis-open.org/committees/download.php/66091/MQTT-SN_spec_v1.2.pdf

The following things are missing in this implementation:
- Pre-defined topic IDs
- QoS -1 - it's most useful with predefined topics
- Gateway discovery using ADVERTISE, SEARCHGW and GWINFO messages.
- Setting the will topic and message after the initial connect
- Forwarder Encapsulation

Signed-off-by: René Beckmann <rene.beckmann@grandcentrix.net>
2022-11-09 10:43:00 +01:00
Christoph Schnetzler
c364721796 net: sockets: Prevent compiler error if warnings being treated as errors
If gcc compiler option -Werror is used the warning,

declared inside parameter list will not be visible outside of this
definition or declaration [-Werror]

is treated as error, for

sockets_internal.h:18:28: ‘struct net_context’
sockets_internal.h:19:32: ‘struct zsock_pollfd’
fdtable.h:108:17: ‘struct k_mutex’

Signed-off-by: Christoph Schnetzler <christoph.schnetzler@husqvarnagroup.com>
2022-11-09 09:15:32 +00:00
Juha Heiskanen
efa75b5a76 net: lwm2m: Send operation registry lock update
Secured Message allocation, init and rebuild process for secure
timeseries ring buffer.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-11-04 09:59:51 +01:00
Juha Heiskanen
05a92f9258 net: lwm2m: Timeseries data cache read update
Added support for handle case when all data is not possible to
add in 1 message for Send and Observed Notification.

Notification continuous pending timeseries data is triggred
by iMIN attribute.

Send Operation generate continuous message in multiple lwm2m
message.

Normal Read by server only report back latest stored data.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-11-04 09:59:51 +01:00
Tommi Kangas
75b5eaac0f net: lwm2m: fix hanging deregistration
Fixed a deadlock in deregistration by moving mutex unlocking.

Signed-off-by: Tommi Kangas <tommi.kangas@nordicsemi.no>
2022-11-04 08:56:05 +00:00
Christoph Schnetzler
0dd14404e1 net: lwm2m: Prevent wundef warnings
If -Werror is used compilation fails due to wundef warning.

Signed-off-by: Christoph Schnetzler <christoph.schnetzler@husqvarnagroup.com>
2022-10-28 22:06:09 +09:00
Krishna T
1852e33213 net: lib: zperf: Disable prints during ongoing traffic
Prints when traffic is ongoing cost a few Mbps due to writing to UART as
observed by the profiler, so, disable them by default.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2022-10-27 15:37:41 +02:00
Veijo Pesonen
8c68e01e55 doc: lwm2m: LwM2M Shell
Describes a possible scenario where to use the LwM2M shell
and how to enable it.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-10-27 11:05:05 +02:00
Juha Heiskanen
a66970a6b8 net: lwm2m: Fix connection resume without DTLS
LwM2M connection resume was missing socket connection when
DTLS is disabled.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-10-27 11:00:46 +02:00
Marc Lasch
df68307121 net: lwm2m: Rename timer object instance create function
Rename timer object instance create funciton `timer_create` to fix a
name collision regression with a POSIX function in `timer.h`. The issue
was introduced with commit 73a637eda0 when
first including`timer.h` into `lwm2ms.h`.

Signed-off-by: Marc Lasch <mlasch@mailbox.org>
2022-10-26 12:01:27 +02:00
Tommi Kangas
c3ad5efa19 net: lwm2m: use zsock_ functions
Use Zephyr internal zsock_ calls to remove dependency
to NET_SOCKETS_POSIX_NAMES.

Signed-off-by: Tommi Kangas <tommi.kangas@nordicsemi.no>
2022-10-26 12:01:14 +02:00
Robert Lubos
caab8cb1b3 net: lwm2m: Don't assume time_t data type size
sizeof(time_t) can vary depending on architecture/libc being in use,
therefore LwM2M should not assume time_t data type size. Instead of
using magic numbers, use a proper sizeof.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-24 16:13:40 +03:00
Juha Heiskanen
4bcc880670 net: lwm2m: LwM2M engine time API update
Updated lwm2m_enigen_set/get_time API for support time_t.

Updated LwM2M engine set/get resource time to time resource support
time_t and uint32_t input.

LwM2M engine put and get time API update to use time_t.

Time series data cache entry have own type for time resource.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-10-24 10:39:03 +02:00
Juha Heiskanen
e1e2228e9c net: lwm2m: LwM2M object time resource update
Updated Timestamp resource default buffer type to time_t.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-10-24 10:39:03 +02:00
Chris Friedt
d832b04e96 net: sockets: socketpair: do not allow blocking IO in ISR context
Using a socketpair for communication in an ISR is not a great
solution, but the implementation should be robust in that case
as well.

It is not acceptible to block in ISR context, so robustness here
means to return -1 to indicate an error, setting errno to `EAGAIN`
(which is synonymous with `EWOULDBLOCK`).

Fixes #25417

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2022-10-22 02:30:04 -07:00
Robert Lubos
c27a6af712 net: zperf: Add QoS support
Improve the zperf upload/upload2 commands, by allowing to specify
DSCP/ECP fields for outgoing packets. The introduced -S option is
compatible with Linux iperf3 utility.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-19 19:03:48 +02:00
Robert Lubos
45ce047605 net: icmpv6: Allow to specify DSCP and ECN values in ping
Add support for setting DSCP/ECN values for an outgoing ping request.
Additionally, copy DSCP/ECN values from an incoming ping request into
the ping response, like Linux does.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-19 19:03:48 +02:00
Robert Lubos
618fa8d665 net: sockets: Add options to control DSCP/ECN value
Add new socket options IP_TOS and IPV6_TCLASS which allows to set
DSCP/ECN values on a socket for an outgoing packet IPv4/IPv6 headers.

The options are compatible with Linux behaviour, where both DSCP and ECN
are set with a single socket option.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-19 19:03:48 +02:00
Robert Lubos
d28a72ed9e net: sockets: Add missing break statement in setsockopt
SOL_SOCKET and IPPROTO_TCP levels were missing the break statement at
the end of their processing logic, which could cause unexpected
fallthrough on unhandled optname value.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-19 19:03:48 +02:00
Øyvind Rønningstad
1e88e7cc9b lwm2m_senml_cbor.patch: Update patch file to match current changes
File created by commiting changes and running

  git diff HEAD~1.. > lwm2m_senml_cbor.patch

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2022-10-19 16:04:56 +02:00
Øyvind Rønningstad
8b295bc58c lwm2m_senml: Regenerate cbor code using zcbor
Also do clang-format and apply patch.

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2022-10-19 16:04:56 +02:00
Øyvind Rønningstad
7b05569d49 lwm2m_senml_cbor_regenerate.sh: Fix argument order in zcbor call
zcbor 0.6.0 has changed the argument order to put code/convert/validate
first.

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2022-10-19 16:04:56 +02:00
Øyvind Rønningstad
f8d0c8a43f lwm2m_senml_cbor_regenerate.sh: Use git am instead of git apply
Since it's better at resolving conflicts.
Commit regenerated files before applying patch.

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2022-10-19 16:04:56 +02:00
Veijo Pesonen
33453e1135 lwm2m: fails if incorrect registration reply
No need to proceed if registration reply parsing fails.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-10-17 20:06:32 +02:00
Jukka Rissanen
cf24ebcc1f net: dns: Always init the resolver
If user has not specified any DNS servers in
CONFIG_DNS_SERVER_IP_ADDRESSES, then the DNS resolver will not be
initialized properly. So fix this by always calling dns_resolve_init()
so that DNS mutex get properly initialized.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2022-10-14 09:57:09 +02:00
Peter Tönz
46a59124dc net: lwm2m: Fix seg-faults if a socket was closed in the meantime
Our application (posix-naive/debug) ran into segmentaion faults,
because the socket was closed between the "wait for sockets" and the
second if in the first loop. Added the check also to line 690
and 720.
The other uses of sock_ctx[i] are already checked against NULL

Signed-off-by: Peter Tönz <peter.tonz@husqvarnagroup.com>
2022-10-12 18:42:41 +02:00
Christopher Friedt
dbe2c0d59e include: net: http: rename http_x.h http/x.h
Some minor housekeeping prior to adding an http server
implementation. There are already a number of http headers
and that number will likely increase with subsequent work.
Moving them into a common directory cleans up the
`include/net` directory a bit.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2022-10-12 09:02:21 -04:00
Peter Tönz
a868da8568 net: lwm2m: Fix buffer overflow by using CONFIG_LWM2M_VERSION_1_0
By using CONFIG_LWM2M_VERSION_1_0, the function
lwm2m_engine_get_binding() returns the binding
and the queue mode bytes. Therefore the buffer
must be tree bytes long.
The issue is caused by the two inconsistent defines:

lwm2m_registry.c:
    #define BINDING_OPT_MAX_LEN 3 /* "UQ" */
lwm2m_rd_client.c:
    #define CLIENT_BINDING_LEN sizeof("U")

Signed-off-by: Peter Tönz <peter.tonz@husqvarnagroup.com>
2022-10-12 18:45:50 +09:00
Seppo Takalo
d454cc946e net: lwm2m: Add helper macro for filling lwm2m_obj_path structs
Allows filling up struct lwm2m_obj_path by a macro.
For example:
  struct lwm2m_obj_path p1 = LWM2M_OBJ(MY_OBJ);
  struct lwm2m_obj_path p2 = LWM2M_OBJ(MY_OBJ, 0, RESOURCE);

Similarly, some function calls accept the structure, so it can
be initialized from stack and given by a pointer
  lwm2m_notify_observer_path(&LWM2M_OBJ(obj_id, 0, RESOURCE_ID));

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2022-10-11 11:14:31 +02:00
Seppo Takalo
65c084f9e5 net: lwm2m: Don't close the socket context on callbacks
I need to register a service for the pull-context so I can
safely close the socket context. Otherwise the socket loop
would crash, because context would be closed while going through
the list where it was located.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2022-10-11 11:13:56 +02:00
Seppo Takalo
d49219aede net: lwm2m: Block on semaphose waiting
Minor change, the semaphore is freed by a caller so it was always
free, but just for being correct, it should be a blocking call,
so any errors would clearly block.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2022-10-11 11:13:56 +02:00
Seppo Takalo
b72fde1f54 net: lwm2m: Remove second layer or rettrying from pull handler
CoAP layer handles retrying so having a second layer of retry
in the pull-context does not make sense. If we need more retrying
it should be done in CoAP layer.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2022-10-11 11:13:56 +02:00
Seppo Takalo
4ec698004c net: lwm2m: Set FOTA state correctly on URI write
When URI is written, we must first set the state to DOWNLOADING
so when any error happens on the initialization phase, the
result written on a callbacks are correctly reflected and the state
changes correctly IDLE -> DOWNLOADING -> IDLE (result written).

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2022-10-11 11:13:56 +02:00
Seppo Takalo
99ebcefc71 net: lib: lwm2m: Add shell commands for lock and unlock
Allowing locking the registry from commandline allows
us to test composite observation and observation of
object instances, etc. where multiple values are changed
before the notify message triggers.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2022-10-11 11:12:20 +02:00
Juha Ylinen
c8a409d7d3 net: lwm2m: Use const data pointers in lwm2m_engine_set functions
lwm2m_engine_set functions use void data pointers. Change those to
to const void

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2022-10-07 16:43:51 +00:00
Andrzej Głąbek
916e04e0ef net: lib: sockets_tls: Include zephyr_mbedtls_priv.h conditionally
This is a follow-up to commit a418ad4bb4.

Since the path to zephyr_mbedtls_priv.h is added to include directories
only when CONFIG_MBEDTLS_BUILTIN is enabled, the inclusion of the file
needs to be done under the same condition. Otherwise, an error occurs
when socket_tls.c is compiled without CONFIG_MBEDTLS_BUILTIN.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2022-10-07 13:23:18 +02:00
Juha Heiskanen
8e1ade2663 net: lwm2m: Fixed cached readtime
Added missing typecast for time read.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-10-05 14:23:32 +00:00
Juha Heiskanen
17b60d0fce net: lwm2m: LwM2M engine send operation update.
Added mutex lock for message build operation.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-10-05 14:23:32 +00:00
Juha Heiskanen
87dc170fed net: lwm2m: SenML-JSON support for Historical data
Extend SenML-JSON content format for handle cached data
timestamp API for basetime and timestamp label's.

Added support for write historical data for static resource
size's: Float (v) and Boolean (vb).

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-10-05 14:23:32 +00:00
Juha Heiskanen
60d9948b67 net: lwm2m: SenML-CBOR Encoder and CDDL update
Added support for historical data encode by adding base time (bt)
and time (t) label. New labels are needed for Encoder so Decoder
is not regenerated.

Added support for SenML-CBOR to write time series data.
Use "bt" base time and "t" timestamp labels for data cache.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-10-05 14:23:32 +00:00
Juha Heiskanen
73a637eda0 net: lwm2m: Historical data cache API update
New API for enable Historical data storage for LwM2M resource.
Data cache is only supported at resource which resource size is
static and well known.

Extend output writer for write cached data timestamp.

Enable cache support for Resource set and Read operation.

Added possibility for for drop latest or oldest data from cache.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-10-05 14:23:32 +00:00
Juha Heiskanen
8c2f5d3296 net: lwm2m: RD Client bootstrap trigger update
Accept now from bootstrap trigger from any state expect ongoing
bootstrap process.
Free also possible on going RD client message. There was a chance
that update message response change state and bootstrap proces
not started.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-10-03 10:20:13 +02:00
Juha Heiskanen
7cee4cf80c net: lwm2m: LwM2M RD client message allocate update
Updated message handler that it free possible old allocated
message. Added message free also to RD stop and idle state.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-10-03 10:20:13 +02:00
Juha Heiskanen
8279489aee net: lwm2m: RD Client update registration timeout
Renamed LWM2M_RD_CLIENT_EVENT_REG_UPDATE_FAILURE to
LWM2M_RD_CLIENT_EVENT_REG_TIMEOUT.

Changed reported event type for registration timeout to
LWM2M_RD_CLIENT_EVENT_REG_TIMEOUT from
LWM2M_RD_CLIENT_EVENT_REGISTRATION_FAILURE.
LWM2M_RD_CLIENT_EVENT_REGISTRATION_FAILURE should be only
reported case when server reject by response registration.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-10-03 10:20:13 +02:00
Sjors Gielen
c0bcff120e net: sntp: use zsock_ functions.
Now the library does not need to depend on NET_SOCKETS_POSIX_NAMES.

Signed-off-by: Sjors Gielen <sjors@sjorsgielen.nl>
2022-10-03 10:19:47 +02:00
Juha Heiskanen
b559bd818c net: lwm2m: Fix LwM2M pause and resume
Fixed unstable thread state read for detetect engine thread
state.
Fixed engine missing socket conrext add.
lwm2m resume now do update also from network error state

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-09-26 15:17:37 +00:00
Juha Heiskanen
8364715998 net: lwm2m: Fix LwM2M resume from Update registration state
If LwM2M engine was paused at ENGINE_UPDATE_SENT it was not
able to resume lwm2m engine properly. There was also missing
RD client Pending message free which could also affect a issue.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-09-26 10:55:03 +00:00
Juha Heiskanen
c9c8c467b5 net: lwm2m: LwM2M rd client Update registration Timeout fix
RD client was not closing socket socket when Update registration
timeout. It fail new connection open. There is added a flag for
detect a case when Registration state need to be re-open a socket
for new connection.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-09-26 10:55:03 +00:00
Henrico Brom
bde8c6d24f net: lwm2m: Fixed missing _CONFIG prefix
Fixed missing '_CONFIG' prefix when enabling
LWM2M_FIRMWARE_UPDATE_OBJ_SUPPORT_MULTIPLE and
CONFIG_LWM2M_FIRMWARE_UPDATE_OBJ_INSTANCE_COUNT through prj.conf

Signed-off-by: Henrico Brom <henrico.brom@vention.nl>
2022-09-21 08:56:58 +00:00
Jarno Lämsä
05b17356e2 net: lib: lwm2m: Fix lwm2m exec
The lwm2m exec erroneously checked the previous return value
instead of checking if the resource existed. This caused exec
to try to get and execute the execute callback from NULL and caused
a reboot.

Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
2022-09-19 10:33:04 +00:00
Reto Schneider
9e1b130156 net: zperf: Configurable packet size limit
Allow user to adjust (artificial) size limitation of 1024 bytes.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
2022-09-15 16:34:13 +00:00
Sjors Hettinga
452592fc9a net: websockets: Fix websocket_send_msg return code
When the websocket_prepare_and_send is called from websocket_send_msg,
the header length is subtracted to retrieve the transmitted payload length.
Make an exclutsion to prevent the return code of
websocket_prepare_and_send being modified in case of 0 or a negative
return code.
This avoid confusion with modificated error codes

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-09-13 08:49:24 +00:00
Sagar Shah
dfd897096d net: lib: coap: method_from_code() API change to return errors.
method_from_code() signature has changed to return error and
the method. In case of an invalid code it returns -EINVAL and
causes coap_handle_request() to return -ENOTSUP.

Fixes: #49498

Signed-off-by: Sagar Shah <sagar.shah@legrand.us>
2022-09-12 10:53:34 +00:00
Ola Tangen Kulseng
1df3de4e98 net: lwm2m: API for multiple resource writing
Used the registry lock in the functions lwm2m_registry_lock() and
lwm2m_registry_unlock() to make the registry lockable through a public
API. If writing to multiple resources that are composite-observed,
locking will halt the main thread until every resource is written to,
ensuring that only one notify message will be sent. Updated
the documentation in lwm2m to include this addition.

Signed-off-by: Ola Tangen Kulseng <ola.kulseng@nordicsemi.no>
2022-09-12 10:52:18 +00:00
Florian Grandel
c57650c403 net: context: clean up net_context_get()
* reduced cyclomatic complexity
* group validation by family to make the validation easier to understand
and extend
* change preprocessor markup where possible to allow for complete code
elimination when features (esp. IP) are disabled
* renamed net_context_get/set_ip_proto() to net_context_get_proto()

While the latter is formally part of the public API and might therefore
have to be deprecated rather than renamed, it is considered internal API
by the net developers, see
https://github.com/zephyrproject-rtos/zephyr/pull/48751#discussion_r942402612

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-09-05 14:35:17 +00:00
Florian Grandel
9695a022f4 net: core: clean up inbound packet handling
The net_core:process_data() and connection:net_conn_input() methods are
the central network packet reception pipeline which:

1) guide network packets through all network layers,
2) decode, validate and filter packages along the way and
3) distribute packages to connections/sockets on all layers.

This code seems to have grown complex and rather cluttered over time as
all protocols, layers and socket implementations meet there in one single
place.

The code also reveals its origin as a pure IP stack which makes it hard
to introduce non-IP protocols and their supporting socket infrastructure
in a modularized way.

For an outside contributor it seems almost impossible to add another
protocol, protocol layer, filter rule or socket implementation without
breaking things.

This change doesn't try to solve all issues at once. It focuses
exclusively on aspects that maintain backwards compatibility:

* Improve modularization and encapsulation on implementation level by
disentangling code that mixes up layers, protocols and socket
implementations.

* Make IP just one protocol among others by removing assymmetry in
protocol handling logic and introduce preprocessor markup so that
IP-specific code can be eliminated by the preprocessor if not needed.

* Use preprocessor markup to delineate hook points for future
modularization or expansion without introducing structural changes (as
this would almost certainly break the API).

* Reduce cyclomatic complexity, use positive rather than negative logic,
improve variable naming, replace if/elseif/else blocks with switches,
reduce variable span, introduce inline comments where code does not
speak for itself, etc. as much as possible to make the code overall
more human-friendly.

Background: These are preparative steps for the introduction of IEEE
802.15.RAW sockets, DGRAM sockets and sockets bound to PAN IDs and device
addresses similar to what the Linux kernel does.

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-09-05 14:35:17 +00:00
Florian Grandel
228526e0db net: lib: sockets: improve scalability through a hidden var
Introducing additional socket implementations is rather involved right
now due to some more or less convoluted code that had grown over time.

This change introduces an additional configuration variable in preparation
for additional socket API drivers. The idea is to reduce redundant code
and make existing code more readable by better exposing its actual intent.

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-09-05 14:35:17 +00:00
Florian Grandel
e9a433cd8f net: introduce NET_IP config to efficiently mark conditional code
The code contained several repeated composite IPv4/v6 and UDP/TCP
preprocessor statements that can be simplified by introducing a hidden
NET_IP preprocessor constant that captures what probably is actually
"meant" by this code.

While we were on it we also used the new constant to further isolate
IP-specific code from non-IP specific generics.

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-09-05 14:35:17 +00:00
Florian Grandel
e608e92112 net: context: properly namespace can-related methods
The net_context_set/get_filter_id() methods are CAN specific and should
say so.

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-09-05 14:35:17 +00:00
Gerard Marull-Paretas
79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00
Sagar Shah
7973483649 net: lib: coap: coap_packet_parse() returns different error values
coap_packet_parse() returns different values depending on error.
It now returns
-EINVAL for invalid input arguments,
-EBADMSG for malformed coap header,
-EILSEQ for malformed options error.

Fixes: #48960

Signed-off-by: Sagar Shah <sagar.shah@legrand.us>
2022-09-02 11:02:38 +00:00
Florian Grandel
ed0060f5a0 net: l2: ieee802154: AF_PACKET support for IEEE 802.15.4
This change makes the packet socket and ieee802154 l2 drivers aware of
AF_PACKET sockets, see https://github.com/linux-wpan/wpan-tools/tree/master/examples
for examples which inspired this change.

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-08-31 21:52:37 +00:00
Gerard Marull-Paretas
0cd311c4a1 include: fix files using legacy include paths
Some files were still using the already deprecated include path, fix
this.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-31 06:49:00 -04:00
Ola Tangen Kulseng
00aa80bb8c net: lwm2m: thread safety in the rd client
Used the mutex in the client to protect the state transitions of
client.state.

Signed-off-by: Ola Tangen Kulseng <ola.kulseng@nordicsemi.no>
2022-08-31 10:42:02 +02:00
Ola Tangen Kulseng
0a87c2d0d0 net: lwm2m: Thread safe lwm2m registry
Created the mutex registry_lock to:
- protect read and write operations
- protect the registry.
Only partially finished as the functions like lwm2m_engine_get_obj
warrants a larger refactoring to completely thread safe the registry.

Signed-off-by: Ola Tangen Kulseng <ola.kulseng@nordicsemi.no>
2022-08-31 10:42:02 +02:00
Juha Heiskanen
534c7f2246 net: lwm2m: Fixed LwM2M message wrong error response
LwM2M was not reported properly case when message "Accept"
coap option was not not supported. In that case LwM2M transport
specification define 4.06 "Not Accepted"

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-08-31 10:41:49 +02:00
Ola Tangen Kulseng
24a84ae743 net: lwm2m: Documentation of the lwm2m engine
I've provided documentation for the API's
- lwm2m_registry.h
- lwm2m_engine.h

Signed-off-by: Ola Tangen Kulseng <ola.kulseng@nordicsemi.no>
2022-08-30 14:19:05 +00:00
Veijo Pesonen
862cabc48c net: lwm2m: Fixes FOTA update result code
The update result is supposed to indicate success only after a firmware
update has been applied. The bug here was that the success was reported
already when the update image download was done.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-08-29 11:38:53 +02:00
Gerard Marull-Paretas
a202341958 devices: constify device pointers initialized at compile time
Many device pointers are initialized at compile and never changed. This
means that the device pointer can be constified (immutable).

Automated using:

```
perl -i -pe 's/const struct device \*(?!const)(.*)= DEVICE/const struct
device *const $1= DEVICE/g' **/*.c
```

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-22 17:08:26 +02:00
Neil Armstrong
fe7ffcf2e8 tls_credentials: add Trusted Credential storage backend
This adds a Trusted Credential storage backend using the PSA
Protected Storage API, permitting storage of the credentials
offering a trusted long-term storage with integrity checks.

This implementation tries to fit the actual tls_credentials
implementation, with some slight differences:
- the buffer pointer returned by credetial_get & credential_next_get
  is dynamically allocated and differs from the one given to
  tls_credential_add since it's extracted from the storage at runtime.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2022-08-18 12:33:07 +02:00
Henrik Brix Andersen
27eb12ed48 net: socketcan: decouple SocketCAN and CAN controller headers
Decouple the zephyr/net/socketcan.h and zephyr/drivers/can.h header files
by moving the SocketCAN utilities to their own header.

This is preparation for including the SocketCAN types defined in
socketcan.h in a native posix (Linux) SocketCAN driver context without name
clashes.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-18 10:19:29 +02:00
Henrik Brix Andersen
d1d48e8304 net: socketcan: rename SocketCAN header from socket_can.h to socketcan.h
Rename the SocketCAN header from socket_can.h to socketcan.h to better
match the naming of the functionality.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-18 10:19:29 +02:00
Henrik Brix Andersen
b40a8cb9fd net: socket: can: rename utility functions
Rename the SocketCAN utility functions to reflect the new naming of the CAN
controller API and SocketCAN API data types.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-18 10:19:29 +02:00
Henrik Brix Andersen
13c75417ba drivers: can: remove z prefix from public CAN API types
Remove the "z" prefix from the public CAN controller API types as this
makes them appear as internal APIs.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-18 10:19:29 +02:00
Henrik Brix Andersen
d159947443 net: socket: can: prepend SocketCAN data types with socketcan
Rename the SocketCAN data types to "socketcan_*" in preparation of renaming
the low-level CAN controller API data types.

This breaks the naming compatibility with the similar SocketCAN data types
from the Linux kernel, but Zephyr and Linux SocketCAN are not 100%
compatible anyways (only the structure fields are compatible, extended
functionality such filtering, error reporting etc. are not).

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-18 10:19:29 +02:00
Juha Heiskanen
b0c794305c net: lwm2m: Fix to Queue update process triggering
Fix that broken Queue client for stop looping
"ENGINE_REGISTRATION_DONE_RX_OFF" state.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-08-18 10:19:11 +02:00
Peter Mitsis
f86027ffb7 kernel: pipes: rewrite pipes implementation
This new implementation of pipes has a number of advantages over the
previous.
  1. The schedule locking is eliminated both making it safer for SMP
     and allowing for pipes to be used from ISR context.
  2. The code used to be structured to have separate code for copying
     to/from a wating thread's buffer and the pipe buffer. This had
     unnecessary duplication that has been replaced with a simpler
     scatter-gather copy model.
  3. The manner in which the "working list" is generated has also been
     simplified. It no longer tries to use the thread's queuing node.
     Instead, the k_pipe_desc structure (whose instances are on the
     part of the k_thread structure) has been extended to contain
     additional fields including a node for use with a linked list. As
     this impacts the k_thread structure, pipes are now configurable
     in the kernel via CONFIG_PIPES.

Fixes #47061

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2022-08-17 19:31:25 +02:00
Marcin Niestroj
6653fd945f modules: mbedtls: set mbedTLS debug threshold during module initialization
mbedTLS library threshold initialization was done in native TLS socket
implementation (which tends to use mbedTLS now) and inside mbedTLS
benchmark test. Move that to mbedTLS module initialization, as this is a
global setting.

Update description of CONFIG_MBEDTLS_DEBUG_LEVEL to clarify when
mbedtls_debug_set_threshold() is called.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-08-17 12:03:52 +02:00
Marcin Niestroj
a418ad4bb4 modules: mbedtls: move debug log hook implementation to modules/mbedtls/
So far there was a debug log hook installed in TLS socket implementation.
However, mbedTLS (with debug enabled) might be used outside from TLS socket
and even outside from networking context.

Add new module, which implements debug log hook and makes it available
whenever CONFIG_MBEDTLS_DEBUG is enabled.

Note that debug hook needs to be installed for each mbedTLS context
separately, which means that this requires action from mbedTLS users, such
as TLS sockets implementation.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-08-17 12:03:52 +02:00
Juha Heiskanen
cec0ea0dce net: lwm2m: Fix Update registration issue
Client Registration update process may be reject by server
and this commit fix a case that it will jump to new state
which send registration message. Earlier RD client try
allocate message before only possible one was released.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-08-11 12:16:56 +02:00
Juha Heiskanen
6bfebe5fc3 net: lwm2m: Fix Queued data buffer send at wakeup from idle
Queue mode without TLS cache was loosing buffered messages at
wake-up process from idle state. Now client context linked list
are initialized at rd client start process only 1 time.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-08-11 12:16:56 +02:00
Gerard Marull-Paretas
b74a22924e net: lib: config: remove NET_CONFIG_IEEE802154_DEV_NAME
Remove NET_CONFIG_IEEE802154_DEV_NAME in favor of DT based choice using
zephyr,ieee802154.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-10 11:57:34 +02:00
Gerard Marull-Paretas
e2bea3b008 net: lib: config: ieee802154: use zephyr,ieee802154
Use DT choice zephyr,ieee802154 as CONFIG_NET_CONFIG_IEEE802154_DEV_NAME
is being phased out.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-10 11:57:34 +02:00
Robert Lubos
d18cdad2fc net: zperf: Use zsock_* API instead of POSIX socket API
In order to make the zperf to work regardless of the POSIX configuration
in the system, convert the socket API usage into Zephyr's native
zsock_* API.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-08-10 11:15:21 +02:00
Robert Lubos
2091b34820 net: zperf: Extract zperf into library
Make a library out of the zperf shell sample. This makes to enable the
module in any application, not only the dedicated sample.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-08-10 11:15:21 +02:00
Stephanos Ioannidis
8fe855f166 net: dns: Check query index in dns_read
This commit adds a check, in the `dns_read` function, before
dereferencing the query index returned by the `dns_validate_msg`
function.

This fixes the warnings generated by the GCC 12 such as:

  error: array subscript -1 is below array bounds of
  'struct dns_pending_query[5]' [-Werror=array-bounds]

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-08-09 14:20:28 +02:00
Seppo Takalo
eafc4f875b net: lwm2m: Allow string and opaque data types to be empty
When string and opaque types are uninitialized, we should
allow their data length to be zero. However, most content
formatters seem to calculate the string length separately
so replace the pointer of empty data into a static string
that is guaranteed to be empty.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2022-08-08 11:27:16 +02:00
Andreas Chmielewski
7532a23dc9 net: lwm2m: Try to reuse registration in case of a network error
For most of the times it is not necessary to do a full registration
once a connection is established after a network error. This is in
particular not needed if lifetime is not yet expired and the server
does not refuse a registration update.

Signed-off-by: Andreas Chmielewski <andreas.chmielewski@grandcentrix.net>
2022-08-08 06:55:49 +01:00
Andreas Chmielewski
74a56b05a9 net: lwm2m: separate closing context from closing socket
Separate closing lwm2m context from closing socket. This patch is required
for the rd client to take more control over lwm2m context and the socket.
The goal is to close the socket and to keep the lwm2m context if this is
needed.

Signed-off-by: Andreas Chmielewski <andreas.chmielewski@grandcentrix.net>
2022-08-08 06:55:49 +01:00
Andreas Chmielewski
3cdff65eb0 net: lwm2m: Update registration only in good path
Registration should only be updated if update of the registration was
succesful.

Signed-off-by: Andreas Chmielewski <andreas.chmielewski@grandcentrix.net>
2022-08-08 06:55:49 +01:00
Florian Grandel
2e5e761074 net: l2: ieee802154: decouple L2/L3 concerns
This change decouples the IEEE 802.15.4 (L2) layer from all IPv6 (L3)
concerns.

Applications may now choose to set CONFIG_NET_6LO=n and
CONFIG_NET_L2_IEEE802154=y at the same time.

Setting CONFIG_NET_6LO=n will build a vanilla IEEE 802.15.4-2006 specs
compliant L2 layer without any reference to 6LoWPAN or IPv6. This allows
application developers to design custom non-IP protocols on top of
IEEE 802.15.4-2006 and thereby makes the L2 layer much more re-usable.

Fixes #48585.

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-08-04 13:44:06 +02:00
Juha Heiskanen
ca20462bcc net: lwm2m: Shell helper for pause and resume
Helper commit for test pause and resume.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-08-04 13:42:55 +02:00
Juha Heiskanen
ed5f3cdf06 net: lwm2m: LwM2M Pause and resume support
New API for suspend and resume LwM2M engine.
New event LWM2M_RD_CLIENT_EVENT_ENGINE_SUSPENDED for indicate
application that engine is suspended.

Simplify stack suspend and resume state same time for queue mode.

New CONFIG_LWM2M_RD_CLIENT_SUSPEND_SOCKET_AT_IDLE for enable skip socket
close at RX_OFF_IDDLE state that socket is only suspended and close is
called only when connection is resumed.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-08-04 13:42:55 +02:00
Veijo Pesonen
0b57ba8dcb net: lwm2m: remove EXPERIMENTAL-label from v1.1
Version 1.1 support is not experimental anymore.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-08-03 11:20:50 +02:00
Seppo Takalo
c3302d5f41 net: lwm2m: Allow observing of object instances and objects
Code was limiting observations to resources and
resource instances without any reason.
Also if resource is written, and the whole object is observer
it should trigger. Path does not have to be matching on the
same level, if parent is observed.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2022-08-01 18:12:33 +01:00
Robert Lubos
bead038ba2 net: sockets: Fill the address structure provided in recvfrom()
The packet socket implementation did not fill the address structure
provided by the application. This commit fixes this.

Note, that the implementation needs to cover two cases: SOCK_RAW and
SOCK_DGRAM. In the first case, the information is extracted directly
from the L2 header (curently only Ethernet supported). In latter case,
the header is already removed from the packet as the L2 has already
processed the packet, so the information is obtained from the net_pkt
structure.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-08-01 18:02:20 +02:00
Stephanos Ioannidis
532d2671be net: coap: Remove resource pointer NULL check
This commit removes the resource pointer NULL check inside the resource
enumeration loop of the `coap_well_known_core_get` function because the
expression `(resource + 1)` will never evaluate to NULL (aka. 0).

This fixes the "comparison will always evaluate as ‘true’ for the
pointer operand" warning generated by the GCC 12.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-08-01 10:47:23 +02:00
Seppo Takalo
b10f2c13ed net: lwm2m: Remove two useless macros
These two macros just change the name of function call
* NOTIFY_OBSERVER
* NOTIFY_OBSERVER_PATH

I don't see any benefit of those, so I dropped them.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2022-07-26 23:23:34 +00:00
Robert Lubos
78c871ab86 net: sockets: Fix potential deadlock during TCP send
There is a potential, corner case scenario, where a deadlock can occur
between TCP and socket layers, when both ends of the connection transmit
data.

The scenario is as follows:
 * Both ends of the connection transmit data,
 * Zephyr side send() call gets blocked due to filing the TX window
 * The next incoming packet is data packet, not updating the RX window
   on the peer side or acknowledging new data. The TCP layer will
   attepmt to notify the new data to the socket layer, by calling the
   registered callback. This will block the RX thread processing the TCP
   layer, as the socket mutex is already acquired by the blocked send()
   call.
 * No further packets are processed until the socket mutex is freed,
   which does not happen as the only way to unblock send() is process
   a new ACK, either updating window size or a acknowledging data.
   The connection stalls until send() times out.

The deadlock is not permament, as both threads get unlocked once send()
times out. It effectively breaks the active connection though.

Fix this, by unlocking the socket mutex for the time the send() call is
idle. Once the TCP layer notifies that the window is available again,
the mutex is acquired back.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-07-18 08:36:09 -07:00
Ola Tangen Kulseng
1563d4a0c3 net: lwm2m: Default ssid
Created the variable CONFIG_LWM2M_SERVER_DEFAULT_SSID to be
the default ssid when not using bootstrap. Needed for access control.

Signed-off-by: Ola Tangen Kulseng <ola.kulseng@nordicsemi.no>
2022-07-15 10:10:16 +02:00
Ola Tangen Kulseng
e05bcefedb net: lwm2m: Access control object
Implementation of the access control object. Core object (obj_id 2).
If used without bootstrap, the default value in
CONFIG_LWM2M_SERVER_DEFAULT_SSID will be used as access control owner.
Enable/disable ac control with CONFIG_LWM2M_ACCESS_CONTROL_ENABLE.

Signed-off-by: Ola Tangen Kulseng <ola.kulseng@nordicsemi.no>
2022-07-15 10:10:16 +02:00
Henrik Brix Andersen
d22a9909a1 drivers: net: canbus: move CAN bus network driver to drivers/net
Move the CAN bus network driver from drivers/can to drivers/net as it
implements a network driver, not a CAN controller driver.

Use a separate Kconfig for enabling the CAN bus network driver instead of
piggybacking on the SocketCAN Kconfig. This allows for other
(e.g. out-of-tree) SocketCAN transports.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-07-13 10:34:51 +02:00
romain pelletant
3908b9dc74 net: lwm2m: Add Event Log object
Event Log object (ID:20) from OMA LwM2M support added

Signed-off-by: romain pelletant <romainp@kickmaker.net>
2022-07-13 10:19:26 +02:00
Kiril Petrov
a4557a46b8 net: lwm2m: Pass client_ctx to observe callback
In case LWM2M cient wants to change attrs of observed obj,
it needs pointer to client_ctx.

For example:
On observer add, wants to change pmin for some obj path to 1s:

static void observe_cb(enum lwm2m_observe_event event,
		struct lwm2m_obj_path *path, void *user_data)
{
	struct lwm2m_ctx *ctx = (struct lwm2m_ctx *) user_data;

	switch (event) {
	case LWM2M_OBSERVE_EVENT_OBSERVER_ADDED:
		lwm2m_engine_update_observer_min_period(ctx, "3347", 1);
	...
}

Signed-off-by: Kiril Petrov <retfie@gmail.com>
2022-07-11 09:32:18 +00:00
Simen S. Røstad
92eb309918 net: lib: lwm2m: Give Kconfig choices symbol names
Give Kconfig choices symbols names so that they can be redefined in
applications that wants to alter the choice's default value without
setting it in the project configuration.

Signed-off-by: Simen S. Røstad <simen.rostad@nordicsemi.no>
2022-07-11 11:03:41 +02:00
Robert Lubos
815ebc316e net: openthread: Move glue code into module directory
Move OpenThread's glue code along with the Kconfig files that configure
OpenThread stack itself into module directory.

Update the maintainers file to reflect this change.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-07-11 11:00:12 +02:00
Anas Nashif
0aefa654da net: add mising braces to single line if statements
Following zephyr's style guideline, all if statements, including single
line statements shall have braces.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-06 11:00:45 -04:00
Juha Heiskanen
d4bf2ad6cc net: lwm2m: Fix socket offload and native TLS conflict
Removed auto select from LWM2M_DTLS_SUPPORT
* TLS_CREDENTIALS
* NET_SOCKETS_SOCKOPT_TLS
* NET_SOCKETS_ENABLE_DTLS

LwM2M stack shouldn't enforce these options as they
are not needed with socket offloading.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-07-06 11:28:19 +02:00
Andreas Chmielewski
363e2f3014 net: coap: make coap vars configurable
COAP_DEFAULT_MAX_RETRANSMIT and COAP_DEFAULT_ACK_RANDOM_FACTOR
should be configurable to determine the max transmission
timeout of a CoAP packet.

Signed-off-by: Andreas Chmielewski <andreas.chmielewski@grandcentrix.net>
2022-07-05 21:56:34 +00:00
Juha Heiskanen
ad5492721a net: lwm2m: Fixed crash at LwM2M registration timeout
LwM2M context close moved to thread safe place when RD client
run state machine.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-07-05 14:19:24 +02:00
Ola Tangen Kulseng
9be4fd0bbb net: lwm2m: Refactor of engine, message handling
Created the file lwm2m_message_handling.c, to include all
code pertaining to CoAP and allocation and deletion of messages
in general.

Signed-off-by: Ola Tangen Kulseng <ola.kulseng@nordicsemi.no>
2022-07-05 13:50:26 +02:00
Ola Tangen Kulseng
365efa0f6a net: lwm2m: Refactoring of engine, observation
Created the file lwm2m_observation.c, to include
all code maintaining observations and parameter handling.

Signed-off-by: Ola Tangen Kulseng <ola.kulseng@nordicsemi.no>
2022-07-05 13:50:26 +02:00
Ola Tangen Kulseng
02fed0b22e net: lwm2m: Refactoring of lwm2m_engine.c
Created the file lwm2m_registry.c to include the
getters and setters of values and the creation
and deletion of all lwm2m objects, resources
and instances. Refactored the registry part
of lwm2m_engine.h into lwm2m_registry.h.

Signed-off-by: Ola Tangen Kulseng <ola.kulseng@nordicsemi.no>
2022-07-05 13:50:26 +02:00
Veijo Pesonen
94b81664e4 net: lwm2m: default stack size with SenML CBOR
SenML CBOR data is stored statically in RAM and does not use process
stack.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-07-04 16:20:03 +02:00
Øyvind Rønningstad
c1a9866c86 west.yml: Update zcbor to v. 0.5.1
lwm2m: Regenerate lwm2m_senml code from the CDDL description.
Reapply manual changes.
Create a sh script to perform the regeneration.

tests: zcbor_bulk: Adapt to zcbor 0.5.1
zcbor_new_decode_state() now has no return value.

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2022-07-04 15:13:42 +02:00
Andrei Emeltchenko
8dda6b8c37 net: coap: Remove unneeded statement
Assignment is not needed.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-06-30 10:34:40 +02:00
Veijo Pesonen
9bf570eaba net: lwm2m: Fixes SenML CBOR composite read
Path list was replaced accidentally with free list during refactoring.
This change does fix the issue.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-06-29 10:29:27 +02:00
Sjors Hettinga
3bcd8d1ee1 net: socket: Use exponential backoff in case of polling errors
Some errors can occur in the sending process that have to be handled
in a polling fasion instead of blocking using semaphores. In this case
apply an exponentially growing backoff time. This will allow for fast
reactions in most situations and prevents high system loads in case
resolving the situation takes a little longer.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-06-29 10:28:11 +02:00
Ulf Lilleengen
61f4513750 net: improve error message on not supported op
When an operation on the socket is not supported by the implementation,
which is the case for some drivers, set errno to a value that reflects
this situation rather than signalling an error with the file descriptor.

Signed-off-by: Ulf Lilleengen <lulf@redhat.com>
2022-06-27 14:14:53 +02:00
Lukasz Maciejonczyk
80eca5f7b4 net: openthread: align otPlatSettingsSet with new interface contract
The new interface contract guarantees that OpenThread stack uses
otPlatSettingsSet only for aKey which has at most one value at time.
This implies the simplification for key name used by settings subsystem
and decreases the count of records written each time when the value
for specific key is updated. In result non-volatile memory can be used
more efficiently.

It relates to zephyrproject-rtos/openthread commit: ed665e9 .

We still need to make sure that old entries are being removed for the
case with DFU.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2022-06-27 12:47:36 +02:00
Andrei Emeltchenko
ce76beecc3 net: lwm2m: Remove unused variable
Remove unused variable.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-06-23 15:43:59 -05:00
Krzysztof Chruscinski
041f0e5379 all: logging: Remove log_strdup function
Logging v1 has been removed and log_strdup wrapper function is no
longer needed. Removing the function and its use in the tree.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-06-23 13:42:23 +02:00
Robert Lubos
41bbb51412 net: sockets: Fix uninitialized variable use in accept userspace check
Prevent local "addrlen_copy" variable from being used uninitialized in
accept() userspace verification function.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-06-23 09:11:29 +02:00
Andrei Emeltchenko
b970c4daef net: capture: Remove unneeded variable
Remove unused remote_addr_len variable.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-06-22 12:28:35 +02:00
Ola Tangen Kulseng
38628f409e net: lwm2m: Add LwM2M shell commands for start&stop
Added start, stop and update to the shell.
Refactored the event_cb of the rd_client_info struct into the ctx,
as it was needed in the shell script.

Signed-off-by: Ola Tangen Kulseng <ola.kulseng@nordicsemi.no>
2022-06-22 12:17:52 +02:00
Ola Tangen Kulseng
3e50624e39 net: lwm2m: Added commands to the lwm2m_client shell
Added read, write and execute commands to the shell.

Signed-off-by: Ola Tangen Kulseng <ola.kulseng@nordicsemi.no>
2022-06-22 12:17:52 +02:00