Commit graph

2451 commits

Author SHA1 Message Date
Ø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
Juha Heiskanen
6d42ded565 net: lwm2m: LwM2M message allocation update
Allocated own message buffer for RD client interface.
This helps to cover if all messages are queued and need to do
registration or update.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
(cherry picked from commit 8dca91109d73a4a697e074c58ee9430d56c01a51)
2022-06-20 09:13:41 -04:00
Juha Heiskanen
ad1960625a net: lwm2m: Fix Possible Notification send blocker
If Notification build fail there was possible that Notification
are blocked after failure.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
(cherry picked from commit 6dfa242c7d891b3458ab88df46b69b3a9621ee82)
2022-06-20 09:13:41 -04:00
Juha Heiskanen
e4ce689de2 net: lwm2m: Coap Pending clear update
Fixed couple possible place for leak Coap pending entry.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
(cherry picked from commit 3c175951383be56fa9c1451845a15b66df41ff64)
2022-06-20 09:13:41 -04:00
Seppo Takalo
4a8efbb1bc net: lwm2m: Allow longer lifetimes than uint16_t
Lifetimes are really 32 bit values, so the limitation
did not make sense, and it did not allow 24 hour lifetime.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2022-06-20 10:25:41 +02:00
Krzysztof Chruscinski
c5f2cdef09 logging: Remove logging v1 from the logging
Remove v1 implementation from log_core and all references in the tree.
Remove modules used by v1: log_list and log_msg.
Remove Kconfig v1 specific options.
Remove Kconfig flags used for distinction between v1 and v2.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-06-16 10:51:15 -04:00
Veijo Pesonen
fbef82c9c0 net: lwm2m: SenML JSON bootstrap exceptions
In bootstrap mode write to a non-exisisting optinal resource must not
cause an error.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-06-14 09:31:23 +02:00
Veijo Pesonen
a5eae6f898 net: lwm2m: adds preferred content...
...format to bootstrap registration message with LwM2M v1.1.

SenML CBOR takes precedence, followed by SenML JSON and OMA TLV.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-06-14 09:31:23 +02:00
Veijo Pesonen
db602fd81d net: lwm2m: Missing optional resource does not ...
...trigger write to the error log

Uses debug-level instead.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-06-14 09:31:23 +02:00
Veijo Pesonen
7f54aea934 net: lwm2m: SenML CBOR opaque write fixed
Write to an opaque resource failed and it has been fixed. Support for
blockwise transfer is still missing.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-06-14 09:31:23 +02:00
Veijo Pesonen
4177aa21ec net: lwm2m: SenML CBOR bootstrap exceptions
In bootstrap mode write to a non-exisisting optinal resource must not
cause an error.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-06-14 09:31:23 +02:00
Jedrzej Ciupis
adca70c0fa net: lib: openthread: use ieee802154_txpwr property
This commit aligns openthread radio platform to use `ieee802154_txpwr`
of the packet to transmit instead of setting power through a separate
API call, if possible.

Signed-off-by: Jedrzej Ciupis <jedrzej.ciupis@nordicsemi.no>
2022-06-14 09:30:43 +02:00
Andrei Emeltchenko
a4fe0edfdc net: dns: Return error code
Return ret error code instead of always returning zero causing
warnings:

...
subsys/net/lib/dns/resolve.c:975:6: warning: variable 'ret' set but
not used [-Wunused-but-set-variable]
        int ret = 0;
            ^
...

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-06-13 12:11:54 +02:00
Andrei Emeltchenko
4874910465 net: dns: Remove unused variable
Fix compilation warnings:
...
subsys/net/lib/dns/dns_pack.c:548:6: warning: variable
'remaining_size' set but not used [-Wunused-but-set-variable]
        int remaining_size;
            ^
...

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-06-13 12:11:54 +02:00
Andrei Emeltchenko
766358461c net: lwm2m: Fix NULL pointer dereference
It does make sense to goto to cleanup part.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-06-10 09:47:05 +02:00
Sjors Hettinga
e097d95c66 net: tcp: Implement Nagle's algorithm
To improve the performance with small chunks send, implement Nagle's
algorithm. Provide the option TCP_NODELAY to disable the algorithm.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-06-09 11:32:50 +02:00
Markus Rekdal
3d8f938929 net: lwm2m: Fix range of integers in SenML CBOR
This fixes a minor bug that caused an error if one attempted to encode
or decode INT64_MIN in SenML CBOR

Signed-off-by: Markus Rekdal <markus.rekdal@nordicsemi.no>
2022-06-09 11:32:01 +02:00
Markus Rekdal
0006f2c93e net: lwm2m: Fix decoding of objlnk in SenML CBOR
This fixes a bug in the decoding of objlinks. Without this the object
instance id is not retrieved correctly as it tries to read the second id
starting from the colon.

Signed-off-by: Markus Rekdal <markus.rekdal@nordicsemi.no>
2022-06-09 11:32:01 +02:00
Seppo Takalo
e0296ca0b9 net: lwm2m: Allow initializing opaque and string data to zero length
By default, any string or opaque data that LwM2M engine initializes
sets data lenght to same value as given buffer length for that
resource.

However, on run time, engine keeps track how much data is written
to each resource, so when reading from any resource, should only
return data that has been written there. But uninitialized resources
return the content of the whole buffer.

Fixed the problem by introducing macros INIT_OBJ_RES_LEN(),
INIT_OBJ_RES_MULTI_DATA_LEN() and INIT_OBJ_RES_DATA_LEN() that
allows you to give the amount of data existing in buffer when
the resource is initialized. This sets the data_len and max_data_len
variables correctly.

Also introduced new functions lwm2m_engine_get_res_buf() and
lwm2m_engine_set_res_buf() that distinct between data size and
buffer size. Deprecated the previous functions
lwm2m_engine_get_res_data() and lwm2m_engine_set_res_data()

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2022-06-09 11:30:37 +02:00
Juha Heiskanen
7ffc95c430 net: lwm2m: Composite Observation refactor
Json library parser modify data so thats why we can't parse same
data again. Now Composite observation handler parse SenML Json or
CBOR resource path which is given to new API composite Read API
which not need any new data parser.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-06-06 12:06:43 +02:00
Juha Heiskanen
2da8df8b7e net: lwm2m: Integrate JSON lib to LwM2M 1.0 JSON
Integrated updated JSON library to LwM2M 1.0 JSON.
Removed Old Json format default choice.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-06-06 12:06:43 +02:00
Juha Heiskanen
a9035ebe5e net: lwm2m: Integrate JSON lib to SenML-JSON
Integrated updated JSON library to SenML-JSON.
This integrate affect that Coap Block wise transfer is not
supported.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-06-06 12:06:43 +02:00
Berend Ozceri
a9376174cd net: websocket: Allow building with POSIX API
If the POSIX API is selected via the POSIX_API option, use the POSIX
headers instead.

Signed-off-by: Berend Ozceri <berend@recogni.com>
2022-06-05 14:48:52 +02:00
Eduardo Montoya
e6f3b8a296 net: openthread: fix wrong configuration
Fix wrong OpenThread config.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2022-06-05 14:42:33 +02:00
Markus Rekdal
cf43c49b5f net: lwm2m: Fix decoding of objlnk
This fixes a bug in the decoding of objlinks. Without  this the object
instance id is not retrieved correctly as it tries to read the second id
starting from the colon.

Signed-off-by: Markus Rekdal <markus.rekdal@nordicsemi.no>
2022-06-05 14:27:39 +02:00
Ryan Erickson
67598965fb lwm2m: software management: Fix URI value not being written
Create the URI resource when creating the object if
PULL support is enabled.

URI write callback should be post-write instead to ensure
the URI value is updated for the resource.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2022-05-27 15:45:14 -07:00
Marcin Niestroj
900137ef32 net: sockets: tls: prevent sending fragmented datagrams with sendmsg()
Fragmented data passed to sendmsg() should be sent as a single datagram in
case of datagram sockets (i.e. DTLS connection). Right now that is not
happening now, as each fragment is sent separately, which works fine only
for stream sockets.

There is no mbedTLS API for 'gather' write at this moment. This means that
implementing sendmsg() would require allocating contiguous memory area at
Zephyr TLS socket level and copying all data fragments before passing to
mbedTLS library. While this might be a good option for future, let's just
check if data passed to sendmsg() API consists of a single memory region
and can be sent using single send request. Return EMSGSIZE error if there
are more then one data fragments.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-05-25 14:20:09 +02:00
Marc Lasch
fa84da588d net: lib: lwm2m: Cancel firmware DOWNLOADED state with NULL byte
Allow to cancel a firmware update in DOWNLOADED state by writing a
NULL byte as described in the Firmware Update object version 1.1
(urn:oma:lwm2m:oma:5:1.1). Keep object version 1.0 mechanism with
an `empty string`.

Signed-off-by: Marc Lasch <marc.lasch@husqvarnagroup.com>
2022-05-23 10:17:52 +02:00
Robert Lubos
8ba5990766 net: sockets: Implement POLLOUT for stream sockets
Implement POLLOUT for stream sockets, based on newly introduced tx_sem
functionality of the TCP stack.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-05-18 11:09:17 +02:00
Robert Lubos
86105fb795 net: sockets: Monitor TCP transmit state with semaphore
Utilize the TCP semaphore monitoring transmit status at the socket
layer. This allows to resume transfer as soon as possible instead of
waiting blindly.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-05-18 11:09:17 +02:00
Veijo Pesonen
b18f93dbc4 net: lwm2m: Fix SenML CBOR input basename length
Server might send the whole path in the basename when doing composite
write.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-05-13 10:15:27 -05:00
Veijo Pesonen
082fe9733c net: lwm2m: Adds missing SenML CBOR range check
Adds a check that number of records to be encoded does not exceed the
maximum limit configured through Kconfig.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-05-13 10:15:27 -05:00
Robert Lubos
78e8e0da42 net: sockets: Make use of the status field reported by TCP
Make use of the status field, reported by TCP, in the socket receive
callback. This allows to differentiate a graceful connection shutdown
from actual errors at TCP level (transmission timeout or RST received).
In case of error reported from TCP layer, set a new SOCK_ERROR flag on
the socket, and store the error code in the net_context user_data.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-05-13 15:42:01 +02:00
Eduardo Montoya
78a2d237d0 net: openthread: add support for PSA MAC keys
Get actual keys from references when PSA crypto is enabled.
A more secure method should be implemented once 802.15.4 platforms
support other than clear text keys.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2022-05-13 13:27:04 +02:00
Eduardo Montoya
ef30cf58c1 net: openthread: implement otPlatRadioGetCslUncertainty
Implement the OpenThread API to retrieve the platforms CSL
Uncertainty.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2022-05-13 13:22:48 +02:00
Gerard Marull-Paretas
5113c1418d subsystems: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all subsystems code to
the new prefix <zephyr/...>. Note that the conversion has been scripted,
refer to zephyrproject-rtos#45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-09 12:07:35 +02:00
Robert Lubos
5cefcf80e9 net: sockets: Move offloading out of experimental
Socket offloading has been in the tree for a while and improved a lot
over time (from a simple define-based API override to a complex
vtable-based solution, supporting mutliple offloaded interfaces). As the
feature is heavily used by certain vendors (Nordic and its nRF Connect
SDK), I propose to move it out of experimental phase.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-05-06 11:30:22 +02:00
Juha Heiskanen
9b7a36099f net: lwm2m: LwM2M timeout recovery
LwM2M engine is blocking new notification send.
Notification or Send timeout trig Reconnect and registration state.
Send/Notification  message is blocked if client is not connected.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-05-04 09:50:28 -05:00
Jarno Lamsa
ffa222725d net: lib: lwm2m: Don't create server object in bootstrap
When bootstrap is used, the server object shouldn't be autocreated.
Automatically creating object may cause problems after bootstrap
has been done and bootstrap server deletes and creates instances
for server object. In the next boot the auto-created server object
may have clashing server_id with the server object that the
bootstrap-server has created.
Also lifetime wasn't properly added to the registration message from
the server object.

Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
2022-05-04 09:46:10 -05:00
Juha Heiskanen
3bf30ef292 net: lwm2m: LwM2M RD client start and stop update
Added return code for for lwm2m_rd_client_start() & lwm2m_rd_client_stop().

lwm2m_rd_client_start() return -EINPROGRESS when start is in progress and
0 for success.

lwm2m_rd_client_stop() return -EPERM when context is unknown and
0 for success.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-05-04 09:44:29 -05:00
Veijo Pesonen
d8b7449b52 net: lwm2m: SenML CBOR key ordering
Keys' order - bn, n - might differ from the default due to
Length-First Map Key Ordering rules.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-29 16:10:43 +02:00
Veijo Pesonen
975d170792 net: lwm2m: use stack for SenML CBOR data
Formatter data are is shared between different threads.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-29 16:10:43 +02:00
Veijo Pesonen
a1bd90646e net: lwm2m: adds README
Includes instructions for generating the SenML CBOR encoder and
decoder.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-29 16:10:43 +02:00
Veijo Pesonen
98b22a1850 net: lwm2m: SenML CBOR optimisations
Regenerates the encoder and decoder. Treats integers and floating-point
values as separate entities instead of saying that those are numerical
values. Brings some memory savings.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-29 16:10:43 +02:00
Veijo Pesonen
b78dd2498a net: lwm2m: Sets ct to registration msg
Tells the server which content format is preferred in a registration
message.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-29 16:10:43 +02:00
Veijo Pesonen
4f76b194a4 net: lwm2m: empty CBOR array support
Makes possible to write an empty CBOR array if there are no SenML CBOR
records that needs to be written. This came up when trying to delete a
portfolio object instance.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-29 16:10:43 +02:00
Veijo Pesonen
60eaafe293 net: lwm2m: SenML CBOR gencode adaption
Generated code needs some modifications for it to work correctly.

Adds license information.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-29 16:10:43 +02:00
Veijo Pesonen
0562de9fbe net: lwm2m: SenML CBOR RW support
* LwM2M v1.1 SenML CBOR content format support.
* Composite operations
* SEND functionality

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-29 16:10:43 +02:00
Juha Heiskanen
1b10f8345e net: lwm2m: LwM2M RD client registration update failure fix
Client jump to full registration state if registration update fail.
Update keep already opened DTLS session.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-04-29 08:57:30 +02:00
Juha Heiskanen
f20eeebbd1 net: lwm2m: DTLS session cache enable and queue mode update
Enabled DTLS session cache for support session resume.
Fixed LwM2M queue mode for close connection and reconnect automatically.
Re-connect will do Registration update before it send queued data.
Session resume is helping a case when NAT change address and cause less
network traffic.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-04-29 08:57:30 +02:00
Juha Heiskanen
5249e43e54 net: coap: Coap pending allocation fix
When sending 2 or more confirmable message before first one is
writed to socket all messages use same coap pending structure.
Now coap_pending_init() set data pointer which lock allocation
by each call.

Using data pointer for detecting free is more stable than timeout.
Timeout is initialized only before first socket send. Queued packet
may be triggered later than other and may cause that same block is
allocated multiple time.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-04-29 08:57:30 +02:00
Robert Lubos
7ad2e604bb net: sockets: tls: Add options to control session caching on a socket
Introduce TLS socket options, which allow to configure session caching
on a socket.

The cache can be enabled on a socket with TLS_SESSION_CACHE option.
Once cache is enabled on a socket, the session will be stored for re-use
after a sucessfull handshake. If a socket is attempting to connect to a
host for which session is stored, the session will be resumed and mbed
TLS will attempt to use a simplified handshake procedure.
The server-side management of sessions is fully controlled by mbed TLS
after session caching is enabled on a socket.

The other TLS_SESSION_CACHE_PURGE option allows to clear all of the
cache entries, releasing the memory allocated for sessions.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-04-28 11:31:07 +02:00
Pete Skeggs
fb2a966128 net: sockets: tls: use cipherlist set by user
The function setsockopt() option TLS_CIPHERSUITE_LIST
allows the user to set a specific list of ciphersuites
when using the Zephyr native + Mbed TLS stack.  However, the
list provided was not actually being used later for
handshaking.

This adds the missing calls to mbedtls_ssl_conf_ciphersuites()
to use the list provided.  If none was provided, fall back
to the default list as determined by Mbed TLS from Kconfig
values.

Signed-off-by: Pete Skeggs <peter.skeggs@nordicsemi.no>
2022-04-26 15:54:32 -04:00
Veijo Pesonen
cfcc891d3d net: lwm2m: makes CBOR as one of the default...
...content formats

In case that SenML CBOR or SenML JSON are both disabled there is need to
use plain CBOR as backup.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-22 09:44:36 +02:00
Veijo Pesonen
11b8b4e7ba net: lwm2m: enables CBOR content format
With LwM2M v1.1 the content format is enabled by default.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-22 09:44:36 +02:00
Veijo Pesonen
8fd283a788 net: lwm2m: Single instance read&write with CBOR
Raw CBOR content format support.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-22 09:44:36 +02:00
Robert Lubos
e2fe8e7307 net: socket: Add option to create native TLS sock with offloaded TCP
In some cases (for examples when offloaded socket implementation does
not implement TLS functionality) it could be desired to create a native
TLS socket with an underlying offloaded socket.

This cannot be achieved with SO_BINDTODEVICE option only, as TLS socket
type is not really associated with a particular interface - it either
has to be offloaded, or a fully native socket is created (native TLS on
a native interface).

In order to address the problem, introduce TLS_NATIVE socket option.
This option instructs the socket dispatcher layer to create a native TLS
socket. As with the socket dispatcher the underlying socket
implementation is not decided during TLS socket creation, therefore it's
possible to use SO_BINDTODEVICE to choose either native or offloaded
interface for the underlying socket.

Additionally remove NET_SOCKETS_OFFLOAD_TLS Kconfig option, as it's no
longer needed with an runtime option to select whether to offload TLS or
not.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-04-20 11:27:05 +02:00
Robert Lubos
641b2a0d93 net: sockets: Add socket dispatcher
Add an intermediate socket implementation called socket dispatcher. This
layer can be used along with the socket offloading, to postpone the
actual socket creation until a first operation on a socket is executed.

This approach leaves an opening to bind a socket to a particular
offloaded network interface, and thus offloaded socket implementation,
using SO_BINDTODEVICE socket option. Thanks to this, it is now possible
to use multiple offloaded sockets implementations along with native
sockets, and easily select which socket should use with network
interface (even if it's an offloaded interface).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-04-20 11:27:05 +02:00
Juha Heiskanen
53fbf40227 net: lwm2m: SenML Json fix RW Time
Added missing get_time and put_time for fixing crash.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-04-20 11:10:12 +02:00
Marin Jurjević
0ab6bc6626 net: lwm2m: update client tx timestamp before sending message
Update client tx timestamp right after message is added to list
of outgoing messages. Delay between when message is generated and
sent is negligible. This will prevents bugs that appear when using
queue mode, where internal engine logic depends on timestamp being
updated when message is generated.

Signed-off-by: Marin Jurjević <marin.jurjevic@hotmail.com>
2022-04-13 13:59:58 -07:00
Veijo Pesonen
1105017ce0 net: lwm2m: Makes OMA TLV content fmt conditional
With LwM2M v1.1 usage of the OMA TLV content format is discouraged.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-13 13:28:34 -07:00
Veijo Pesonen
d1751cafd3 net: lwm2m: adds LwM2M specific shell command
First available subcommand is for doing a send operation. Send operation
is supported by the LwM2M version 1.1.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-12 09:57:20 +02:00
Mohan Kumar Kumar
f105ea6ef5 net: add sndbuf socket option
Introduce set/get SO_SNDBUF option using the setsockopt
function. In addition, for TCP, check the sndbuf value
before queuing data.

Signed-off-by: Mohan Kumar Kumar <mohankm@fb.com>
2022-04-11 10:23:31 +02:00
Marcin Niestroj
5d07c53118 net: sockets: do not unconstify 'optval' in setsockopt()
'optval' in setsockopt(..., SO_BINDTODEVICE, ...) was casted explicitly
from 'const void *' to 'struct ifreq *'. Rely on C implicit casting from
'const void *' to 'const struct ifreq *' and simply update variable
type. This prevents unwanted modification of ifreq value in the future.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-04-08 15:51:38 -07:00
Eduardo Montoya
7ab43a7cc9 net: openthread: update otPlatSettingsInit
API has been modified.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2022-04-08 15:50:53 -07:00
Marcin Niestroj
cf75f01a71 net: sockets: introduce NET_SOCKETS_OFFLOAD_PRIORITY option
This option will be used as default socket priority by offloaded socket
drivers.

Describe how to prioritize native TLS over offloaded TLS (and vice
versa) using sockets priorities.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2022-04-08 15:50:11 -07:00
Jordan Yates
04d29c4eb4 net: mqtt: remove custom logging macros
Remove the custom MQTT logging macros and just use the NET macros
directly. The custom macros provide no additional functionality and the
non-standard naming can cause confusion.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-04-06 17:41:06 +02:00
Eduardo Montoya
ed89142661 net: openthread: add Time Sync support
Implement `otPlatTimeGetXtalAccuracy` which is missing when Time
Sync is enabled.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2022-04-06 11:23:41 +02:00
Gerard Marull-Paretas
c925b5991a include: remove unnecessary autoconf.h includes
The autoconf.h header is not required because the definitions present in
the file are exposed using the compiler `-imacros` flag.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-04-05 11:18:20 +02:00
Seppo Takalo
43c988d43e net: lwm2m: Clean up context on stop
When lwm2m_rd_client_stop() was called and immediately
followed by lwm2m_rd_client_start() it leaked the file
handle for existing socket.

Problem can be fixed when rd_client_stop() does not
move state machine to IDLE, but instead DEREGISTER
and then allow state machine to move forward.

I added a blocking wait for rd_client_stop() because
it needs to wait for proper clean up.

I also move couple of lwm2m_engine_context_close() to
set_sm_state() event handler or similarly in lwm2m_engine.c
there was couple of places where context was not properly
cleaned.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2022-04-05 11:16:58 +02:00
Juha Heiskanen
ba2354a277 net: lwm2m: Support for "Mute Server" resource
Added support for server Mute send operation.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-04-04 10:29:07 -05:00
Juha Heiskanen
d75b986151 net: lwm2m: SenML Json Base compare fix
Fixed wrong initialized base name objed id.
Base name was added to every object instance.
Fix will save message size.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-04-04 10:28:01 -05:00
Juha Heiskanen
164680d696 net: lwm2m: Senml Opaque BASE64URL support and fix padding
LwM2M specification is only mentioning BASE64 encoding but SenML-JSON
specification is talking about BASE64URL encoding.
This change is silently accepting both formats and automatically pads the
data if padding is dropped.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-04-04 11:16:26 +02:00
Lukasz Maciejonczyk
5dd5128345 net: openthread: align platform time with radio time
On dual-core architecture the platform time can be not aligned with
radio time. This happens e.g. for nRF53 devices. Unaligned times imply
mulfunction in CSL windows scheduling.
This PR fixes it by adding/subtracting the time offset in functions
which return the plaform time. The changes have no impact on platforms
where the times are the same.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2022-04-01 12:41:12 -05:00
Mohan Kumar Kumar
5d37de8551 net: add rcvbuf socket option
Introduce set/get SO_RCVBUF option using the setsockopt
function. In addition, use the rcvbuf value to set the
tcp recv window.

Signed-off-by: Mohan Kumar Kumar <mohankm@fb.com>
2022-04-01 13:30:09 +02:00
Benjamin Bigler
28e368de59 net: lwm2m: Fix missing context_close
Added missing lwm2m_context_close if set TLS_HOSTNAME failed

Signed-off-by: Benjamin Bigler <benjamin.bigler@securiton.ch>
2022-03-31 14:33:04 -05:00
Benjamin Bigler
6807d75e16 net: lwm2m: Fix TLS_HOSTNAME is always set
LWM2M Client Sample with DTLS enabled fails because TLS_HOSTNAME is set
but MBEDTLS_X509_CRT_PARSE_C is disabled which leads to error
'net_lwm2m_engine: Failed to set TLS_HOSTNAME option: 109'
Add new field hostname_verify to let the application decide if hostname
should be checked.

Signed-off-by: Benjamin Bigler <benjamin.bigler@securiton.ch>
2022-03-31 14:33:04 -05:00
Benjamin Bigler
493b940248 net: lwm2m: Fix address length at connect
If NET_IPV4 and NET_SOCKETS_PACKET is enabled, NET_SOCKADDR_MAX_SIZE will
be bigger than the ipv4 address length.
This is a problem when DTLS is used as the address comparison will fail
because of the different length of the received and the stored address.
This is also a problem if NET_IPV6 and NET_IPV4 is enabled and the remote
address is a ipv4 address

Signed-off-by: Benjamin Bigler <benjamin.bigler@securiton.ch>
2022-03-31 10:31:01 +02:00
Andreas Pettersson
df59335541 net: lib: lwm2m: Use defines for update state and result pathstrs
Use defines instead of hardcoded strings to avoid future errors if the
values would change.

Signed-off-by: Andreas Pettersson <andreaspettersson95@gmail.com>
2022-03-31 10:30:40 +02:00
Emil Gydesen
ae55dae454 sys: util: Change return type of ARRAY_SIZE to size_t
The ARRAY_SIZE macro uses sizeof and thus the return
type should be an unsigned value. size_t is typically
the type used for sizeof and fits well for the
ARRAY_SIZE macro as well.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-03-23 14:09:23 +01:00
Marin Jurjević
683868f3d2 net: lwm2m: fix potential invalid pointer dereference in reset message
Sometimes message is being reset from multiple locations in code.
If message has already been reset, pointer to context is invalid.

Signed-off-by: Marin Jurjević <marin.jurjevic@hotmail.com>
2022-03-22 12:33:31 +01:00
Juha Heiskanen
0c6ea8eec4 net: lwm2m: Fix Read operation for /object
Read operation must return empty payload when read /object_id
if there is no created object instances.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-03-22 12:32:45 +01:00
Sjors Hettinga
1165bd667f net: http: Allow a content_len of 4GB
Instead of maximally 99999 bytes allow a content_len of 4GB.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-03-21 10:16:21 +01:00
Nazar Kazakov
f483b1bc4c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-18 13:24:08 -04:00
Robert Lubos
ffdc621f1b net: http_client: Fix http_client_req() return value
http_client_req() was supposed to return the number of bytes sent as a
HTTP request. The return value was not riht however due to some bugs in
helper functions:
* http_send_data() returned the current buffer position istead of the
  number of bytes actually sent. This could result in counting the same
  data into the total request size several times. A helper variable was
  added to track how many bytes were actually sent to the network.
* http_flush_data() forwarded the return value of sendall() helper
  function. That function however did not return number of bytes sent,
  but 0 or a negative error code.

Additionally, change the return type of sendall() function - according
to standard the ssize_t type is only capable of holding -1 negative
value, but the function could return the full range of negative errno
values. Use int instead.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-03-18 11:14:24 +01:00
Juha Heiskanen
9777ba7354 net: lwm2m: SenML JSON dynamic Resource instance allocation
Integrated dynamic resouce instance allocation to SenML JSON.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-03-17 11:41:42 +01:00
Robert Lubos
08752aed0f net: sockets: Fix userspace accept() verification
The verification function for accept() did not take into account that
addr and addrlen pointers provided could be NULL.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-03-16 16:23:16 +01:00
Robert Lubos
546267ab3b net: sockets: Implement getpeername() function
Implement getpeername() function.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-03-16 16:23:16 +01:00
Juha Heiskanen
6cb662a495 net: lwm2m: Composite Observation update
Added support for Composite observation for LwM2M v1.1.
Updated current Observation node to support linked path list.
Rename typos lwm_ to lwm2m_.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-03-16 10:26:01 +01:00
Juha Heiskanen
6970addc12 net: lwm2m: Observation pmin and pmax refactor
Removed to store pmin and pmax at oberservation node structure and
use attribute list store for calculate time for next Notification.
Observation class use timestamp for triggering notification based on
resource update which use pmin and default pmax behaviour.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-03-16 10:26:01 +01:00
Robert Lubos
6a0df63ea0 net: sockets: Retry net_context_sendmsg if EAGAIN is reported
TCP module can report EAGAIN in case TX window is full. This should not
be forwarded to the application, as blocking socket is not supposed to
return EAGAIN.

Fix this for sendmsg by implementing the same mechanism for handling TX
errors as for regular send/sendto operations.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-03-15 09:50:21 -07:00
Marin Jurjević
2a4e47a912 net: lwm2m: fix registration update event in queue mode
When queue mode is enabled, state machine will enter state
ENGINE_REGISTRATION_DONE_RX_OFF. This state needs to be
taken into account during registration update to send
correct event.

Signed-off-by: Marin Jurjević <marin.jurjevic@hotmail.com>
2022-03-15 10:06:22 +01:00
Yong Cong Sin
ce3e1e7e29 net: http: Calculate body_frag_len
Calculate the body_frag_length if any part of the body is found
in the http response.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-03-15 10:05:21 +01:00
Yong Cong Sin
49c2d8a635 net: http: Rename body_start to body_frag_start
Following #42026, the body_start pointer now points to the
start of the body fragment in the recv_buffer as long as there
is body in it, either entirely or partially.

Rename the body_start to body_frag_start to better reflect
what it represents.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-03-15 10:05:21 +01:00
Juha Heiskanen
0b38be9d3a net: lwm2m: Inteagrate LwM2M new API's
Remove local path to string and string to path functionality
and use utility library API.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-03-14 22:04:32 -04:00
Juha Heiskanen
c95dd9a9c5 net: lwm2m: lwm2m utility API update
New API's
- lwm2m_string_to_path
- lwm2m_path_to_string
- lwm2m_atou16

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-03-14 22:04:32 -04:00
Juha Heiskanen
6d624e5e18 net: lwm2m: Senml Json Base name dynamical update
SenML Json support dynamical basename for composite operation.
Changes simplify base name generation and compres message better.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-03-14 11:29:13 +01:00
Gerard Marull-Paretas
7a0026a5c1 net: lib: openthread: obtain entropy device using DEVICE_DT_GET
The device can be obtained at compile time. Note that now the readiness
is checked on every call, but it's a fast operation anyway.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-11 15:27:05 -08:00
Lukasz Maciejonczyk
245457649b net: openthread: fix check for unsuccessful wipe
ot_setting_delete_subtree returns the information if the subtree
had been found in the persistent storage or not before removing.
This has matter for otPlatSettingsGet. In other uses cases
the return value shoud be ignored.
The right place for the check if deletion succeded is in
settings_load_subtree_direct and its callback.
Currently "ot factoryreset" causes an assert if there is no
OpenThread dataset stored in the persistent memory.
This PR fixes it.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2022-03-11 11:26:34 -08:00
Gerard Marull-Paretas
95fb0ded6b kconfig: remove Enable from boolean prompts
According to Kconfig guidelines, boolean prompts must not start with
"Enable...". The following command has been used to automate the changes
in this patch:

sed -i "s/bool \"[Ee]nables\? \(\w\)/bool \"\U\1/g" **/Kconfig*

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-09 15:35:54 +01:00
Przemyslaw Bida
c9645f4d36 openthread: net: implementing of otPlatRadioSetChannelMaxTransmitPower
This commit adds implementation of otPlatRadioSetChannelMaxTransmitPower
This function is responsible for setting maximum allowed power on
IEEE 802.15.4 channels.

Signed-off-by: Przemyslaw Bida <przemyslaw.bida@nordicsemi.no>
2022-03-08 09:21:48 -06:00
Krzysztof Chruscinski
47ae656cc1 all: Deprecate UTIL_LISTIFY and replace with LISTIFY
UTIL_LISTIFY is deprecated. Replacing it with LISTIFY.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-03-08 11:03:30 +01:00
Georges Oates_Larsen
303c42e70a net: http_client: Add official null response behavior
Adds an official behavior in response to null response from HTTP
endpoint.

Fixes #42988

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2022-03-07 09:18:50 -06:00
Juha Heiskanen
3d44738b19 net: lwm2m: Fix SenML Json Name parser
Bug fix for case when base name is not included at message.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-03-07 10:54:57 +01:00
Eduardo Montoya
e05c966992 net: openthread: remove CONFIG_OPENTHREAD_CSL_SAMPLE_WINDOW
Remove obsolete configuration option.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2022-03-07 10:54:30 +01:00
Veijo Pesonen
0032f0bcff net: lwm2m: obj inst processing per formatter
It depends from a content formatter is there need to put constructs
with a path level deeper than object instance. In other words with
resource- or resource-instance-level.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-03-07 10:52:58 +01:00
Marcin Niestroj
ab2f616641 net: http: use shutdown(..., SHUT_RD) in receive timeout handler
So far close() was called on underlying socket when timeout has expired.
This is wrong in several ways. First of all POSIX specification of
close() does not specify what should happen on blocking recv() call and
different systems have different behaviors (e.g. Linux does not wake up
recv() caller if there was no new incoming data, while other systems
might wakeup recv() caller immediately). Another (and much more severe)
problem is that HTTP client user does not know whether underlying socket
was already closed or not after HTTP request has finished. As a result
it was not clear whether close() should be called by HTTP client user.

Use shutdown(..., SHUT_RD) in internal HTTP client implementation, so
that recv() is woken up immediately with 0 as result (which means EOF).
This will allow to gracefully handle timeouts and make it clear that it
is application responsibility to always call close() after HTTP
request (successful or not).

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2022-03-02 10:05:09 -08:00
Marcin Niestroj
084ca91a73 net: sockets: tls: implement shutdown() method for TLS sockets
Add basic shutdown() implementation of TLS sockets, which basically
calls shutdown() on underlying wrapped sockets.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2022-03-02 10:05:09 -08:00
Marcin Niestroj
f54dee6531 net: sockets: implement shutdown() method for net_context sockets
Add basic shutdown() implementation for net_context sockets, which
handles only SHUT_RD as 'how' parameter and returns -ENOTSUP for SHUT_WR
and SHUT_RDWR. The main use case to cover is to allow race-free wakeup
of threads calling recv() on the same socket.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2022-03-02 10:05:09 -08:00
Marcin Niestroj
8eb2565dbf net: sockets: add shutdown() support in vtable
So far shutdown() implementation was a noop and just resulted in warning
logs. Add shutdown() method into socket vtable. Call it if provided and
fallback into returning -ENOTSUP if not.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2022-03-02 10:05:09 -08:00
Eduardo Montoya
166fd0dc9e net: openthread: bring back LOG_MODE_MINIMAL support
A previous commit fixed OpenThread logging when `LOG=n`, but
introduced regression when `LOG_MODE_MINIMAL=y`. This commit
fixes the latest.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2022-03-01 12:49:36 +01:00
Lukasz Duda
0c94817b55 openthread: platform: implement otPlatCryptoRand API
This commit utilizes psa_crypto_get function to fetch cryptographically
secure pseudorandom numbers.

Signed-off-by: Lukasz Duda <lukasz.duda@nordicsemi.no>
2022-03-01 12:49:36 +01:00
Veijo Pesonen
2231287e27 net: lwm2m: Resource Instance level read access.
Makes possible to read a single resource instance at a time with
plaint text, JSON and TLV content formats.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-02-25 10:12:23 -08:00
Lukasz Maciejonczyk
c5afc2e1f2 net: openthread: add assert which checks settings wipe failure
If settings wipe fails we are not informed about this what can lead to
bugs which are hard to investigate.
This commit adds log and/or assert which is triggered by this failure.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2022-02-24 08:33:30 -06:00
Juha Heiskanen
6904915a35 net: lwm2m: LwM2M engine default content format select
LwM2M version 1.1 will select SenML Json for default content format.
Version 1.0 will use TLV format.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-23 17:25:36 +01:00
Juha Heiskanen
312dd7f887 net: lwm2m: Composite Observe operation placeholder
Added detetction for Composite Observervation request and cancel.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-23 17:25:36 +01:00
Juha Heiskanen
98cd71eef2 net: lwm2m2: LwM2M Composite-Write operation
CoAP method iPATCH enable LwM2M Composite-Write operation.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-23 17:25:36 +01:00
Juha Heiskanen
3bec5de0fb net: lwm2m: LwM2M Composite read support
Adeed enabler for composite read to LwM2M engine.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-23 17:25:36 +01:00
Juha Heiskanen
906feebb33 net: lwm2m: Added LwM2M Send operation support
LwM2M engine Send operation support /dp.
Send operation based on Composite Read functionality
which is not enabled at engine side like composite write.
Added Kconfig configurable for composite read path list size.
Created generic Read object instance which is shared between
general read and Composite Read operation.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-23 17:25:36 +01:00
Juha Heiskanen
a9c1b8d0f2 net: lwm2m: Added SenML JSON support for Read & Write
LwM2M SenML JSON contain format support for Read / Write operation.
Added Kconfig configurable for enable SenML JSON format.
LwM2m read validate read operation and report out of memory.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-23 17:25:36 +01:00
Robert Lubos
9ac83be650 net: lwm2m: Add proper resource-level discovery attribute handling
In case an individual resource is being discovered, the LwM2M client
should not only fill the attributes assinged at the resource level, but
also the ones inherited from the object and object instance levels.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-22 10:12:27 -08:00
Robert Lubos
ac8881f170 net: lwm2m: Allow to write attributes for resource instances
LwM2M 1.1 allows to write attributes for resource instances as well.

Resource instance level attributes need also to be taken into
consideration when adding/updating observers.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-22 10:12:27 -08:00
Robert Lubos
3e861c04e9 net: lwm2m: Add LwM2M 1.1 discovery support
LwM2M adds Resource Instance reporting in Discovery response, along with
attributes assinged at the Resource Instance level.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-22 10:12:27 -08:00
Robert Lubos
74bc876bf5 net: tcp: Implement receive window handling
Add implementation of net_tcp_update_recv_wnd() function.

Move the window deacreasing code to the tcp module - receive window
has to be decreased before sending ACK, which was not possible when
window was decreased in the receive callback function.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-22 10:09:45 -08:00
Eduardo Montoya
be742f925e net: openthread: fix received frame flags
Uninitialized memory would report wrong value for
`mAckedWithSecEnhAck` flag in the received frame, making the
OpenThread stack to update the frame counter for the neighbor
wrongly.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2022-02-22 10:33:23 -05:00
Seppo Takalo
f1e0b5413c net: lwm2m: Allow changing the protocol version to 1.1
This is a bare minimal changes to tell the server that we are using
LwM2M 1.1 version. Queue-mode parameter has changed between 1.0 and
1.1 so it must be changed in the same time.

Other 1.1 features may follow on separate commits. This is still
an experimental feature that allows developing and testing of
1.1 features.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2022-02-21 22:18:34 -05:00
Veijo Pesonen
37b9bb87f0 net: lwm2m: Adds semantics for handling time
This far time values have been synonymous to integer values. Content
formats like CBOR do use different representation.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-02-21 22:07:01 -05:00
Juha Heiskanen
3e04783bbb net: lwm2m: LwM2M Portfolio object id support
Added support for Portfolio object support because LwM2M v1.1 conformance
test requirement that. This object is only for conformance test purposing.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-21 22:02:44 -05:00
Andreas Chmielewski
b52f1cdb59 net: lwm2m: fixed "LwM2M message is invalid"
Do not retransmit a message that just has been send successfully.

This case can in particular happen quite frequently if the modem
connection/throughput is quite bad and so there is a high latency.

A message that has to be acknowledged is scheduled for retransmission.
Before retransmission a ack for this message is received that will
cause a reset of the original message. In this case you see a
"LwM2M message is invalid" error message.

Signed-off-by: Andreas Chmielewski <andreas.chmielewski@grandcentrix.net>
2022-02-21 21:59:59 -05:00
Juha Heiskanen
dde5c16709 net: lwm2m: JSON dynamic Resource instance allocation
Integrated dynamic resouce instance allocation to JSON.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-21 21:53:48 -05:00
Juha Heiskanen
7b3a1f31fe net: lwm2m: Plain Text dynamic Resource instance allocation
Integrated dynamic resouce instance allocation to Plain text.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-21 21:53:48 -05:00
Juha Heiskanen
fcbf84b5d7 net: lwm2m: OMA TLV dynamic Resource instance allocation
Integrated dynamic resouce instance allocation to OMA TLV.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-21 21:53:48 -05:00
Juha Heiskanen
1d2f5b471e net: lwm2m: Resource instance dynamic allocation
Added support for allocate dynamically resource instance.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-21 21:53:48 -05:00
Juha Heiskanen
60088b18d4 net: lwm2m: Fix Read operation for /object
Read operation must return empty payload when read /object_id
if there is no created object instances.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-21 21:01:23 -05:00
Juha Heiskanen
392088ea13 net: lwm2m: OMA TLV Multi Resource TLV update
Added support for handle Multi Resource TLV for Write and Create operation.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-21 21:00:36 -05:00
Robert Lubos
3ebd581467 net: sockets: Allow to build CAN sockets with offloading enabled
There is no releavnce between CAN sockets and offloading that would
prevent one from working with another, therefore it's not right to
allow CAN sockets to be build only if offloading is disabled. Fix the
wrong dependency in socket CMakeLists.txt file.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-21 20:52:38 -05:00
Henning Fleddermann
7eb25df526 net: lib: lwm2m: add lwm2m_engine_is_observed function
add helper function to check wether a specific lwm2m
path is observed

Signed-off-by: Henning Fleddermann <henning.fleddermann@grandcentrix.net>
2022-02-21 20:50:52 -05:00
Eduardo Montoya
a0093eeda0 net: openthread: fix handling tx done to report all kind of errors
Fix bug in radio implementation that reported any transmit error
as `OT_ERROR_NO_ACK` to OpenThread.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2022-02-21 20:49:20 -05:00
Henning Fleddermann
3018279c30 net: lib: lwm2m: make pathstr parameter const correct
many functions in the lwm2m librarys api take a pathstr argument
that is never written to, so make it const

Signed-off-by: Henning Fleddermann <henning.fleddermann@grandcentrix.net>
2022-02-08 07:27:30 -05:00
Jarno Lamsa
98f99a37a2 net: lib: lwm2m: Use snprintk instead of snprintf
Use kernel print function to reduce the memory impact.

Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
2022-02-07 17:22:38 +01:00
Jarno Lamsa
c2550d56c8 net: lib: lwm2m: Correct path for update result
The path was erroneously pointing to update state
resource instead of update result causing a wrong
resource value to be updated.

Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
2022-02-07 17:22:38 +01:00
Marin Jurjević
2f4ab97168 net: lwm2m: add missing optional resource to firmware object
Firmware Update Protocol Support resource initialization
has been left out in #41402.
Initialise the resource in object creation function.

Signed-off-by: Marin Jurjević <marin.jurjevic@hotmail.com>
2022-02-04 11:19:07 +01:00
Yong Cong Sin
731241f8d0 kernel: workq: Fix type errors in delayable work handlers
A common pattern here was to take the work item as the subfield of a
containing object. But the contained field is not a k_work, it's a
k_work_delayable.

Things were working only because the work field was first, so the
pointers had the same value. Do things right and fix things to
produce correct code if/when that field ever moves within delayable.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-02 18:43:12 -05:00
Marin Jurjević
57a66648ae net: lwm2m: fix context close race condition
Calling lwm2m_rd_client_stop causes the client context to be closed.
Doing this from arbitrary thread other than internal lwm2m engine thread
causes racing condition on lwm2m engine context pointers.

Fixes #42358

Signed-off-by: Marin Jurjević <marin.jurjevic@hotmail.com>
2022-02-02 08:58:40 -05:00
Juha Heiskanen
a03deb8ef3 net: lwm2m: Fix Server Object SSID access
Server Object SSID should only have Read access.
LightweightM2M-1.1-int-256 confirmance test validate
that write operation to SSID should return error.
Overwrite SSID affect dead block for lwm2m engine and
only reset will heal.

Fix by adding bootstrap overwrite access for Security and
Server object when bootstrap is active.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-02 11:18:53 +01:00
Robert Lubos
9c8d30f099 net: lwm2m: Prevent snprintk warnings on different platforms
Use explicit casting to long long within `snprintk()` and logger
functions to prevent compiler warnings with different
platforms/toolchins (as 64-bit integer can be either represented
as ld or lld depending on platform).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos
486e0a8ff6 net: lwm2m: Fix lwm2m_parse_peerinfo misuse
`lwm2m_parse_peerinfo()` expects a boolean value, not a pointer.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos
21e5cc7a31 tests: net: lwm2m: Add link-format content writer tests
Add unit tests for LwM2M link-format content encoder/decoder.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos
735fd86c0e tests: net: lwm2m: Add OMA TLV content writer tests
Add unit tests for LwM2M OMA TLV conent encoder/decoder.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos
e42c1ed924 net: lwm2m: Fix OMA TLV objlnk encoding
At some point OMA TLV integer encoding was optimised to use the smallest
size possible. This broke the objlnk encoding, which internally used
`put_s32()`, but should always be 4 bytes long. In case the result
32-bit integer would fit into 16 or 8 bytes, it'd get optimized.

Fix this, by creating and writing TLV manually for objlnk instead of
relying on int32 encoder.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos
3595a7cdb5 net: lwm2m: Fix lwm2m_atof for integer input
In case a string with an integer was provided to the function (no
decimal point), the function did not update the output pointer value.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos
cb6c5f37ca net: lwm2m: Improve content writers error handling in engine
Verify the restult of the content writer functions and return an error
if content writer fails to read/write field in the message.

This solves an issue when for example malformed packet was sent to the
server if the payload did not fit in the message.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos
1a727b8571 net: lwm2m: Improve JSON content encoder/decoder error handling
It's now possible to return an error code instead of 0 where
appropriate.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos
9e2bf49103 net: lwm2m: Improve TLV content encoder/decoder error handling
It's now possible to return an error code instead of 0 where
appropriate.

Make `buf_read()` return -ENODATA instead of -ENOMEM if there's not
enough data in the packet to serve the request, which is more meaningful
for this scenario.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos
f1d86a0cd2 net: lwm2m: Improve plain-text content encoder/decoder error handling
It's now possible to return an error code instead of 0 where
appropriate.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos
1c3dbd5af3 net: lwm2m: Improve link-format content encoder error handling
It's now possible to return an error code instead of 0 where
appropriate.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos
54ddf70945 net: lwm2m: Allow to return error codes by content encoders/decoders
Rework the content encoder/decoder API to allow to return negative
values as well. This allows a proper error reporting and error handling,
as it's now possible to differentiate when there is no content to write
(retuned 0) or and error occured, and further processing should be
aborted.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Efrain Calderon
6b936c0315 net: coap: Update coap context using payload length
When a file is download, `ctc->current` is increaed by the block
size, which is correct for all the blocks except the last one.

 Once the download is compelted, ctx->current must match
`ctx->total_size`.

Signed-off-by: Efrain Calderon <efrain.calderon@aquarobur.com>
2022-02-02 11:10:57 +01:00
Daniel Nejezchleb
d3a9e7c29a net: sockets: Fixes net_pkt leak in accept
Fix net_pkt leak by increasing net_context the reference count earlier
in the zsock_accepted_cb() with instalment of the
zsock_received_cb() callback.

And consequently flushing recv_q and decrement net_context
reference count if zsock_accept_ctx() fails.

Signed-off-by: Daniel Nejezchleb <dnejezchleb@hwg.cz>
2022-02-01 14:22:37 -06:00
Robert Lubos
0755a7f057 net: sockets: getaddrinfo: Fix possible crash when callback is delayed
In case system workqueue processing is delayed for any reason, and
resolver callback is executed after getaddrinfo() call already timed
out, the system would crash as the callback makes use of the user data
allocated on the stack within getaddrinfo() function.

Prevent that, by cancelling the DNS request explicitly from the
getaddrinfo() context, therefore preventing the resolver callback
from being executed after the getaddrinfo() call ends.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-01 14:18:33 -06:00
Jarno Lamsa
a1c80e7374 net: lib: lwm2m: Add missing function declarations
Get-function declarations for fw update state and result were
missing from the engine header.

Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
2022-02-01 14:14:29 -06:00
Robert Lubos
f4a18e471b net: sockets: tls: Fix ZSOCK_POLLHUP detection
The previous approach to detect if the underlying transport was closed
(by checking the return value of `mbedtls_ssl_read()` was not right,
since the function call does not request any data - therefore 0 as a
return value is perfectly fine.

Instead, rely on the underlying transport ZSOCK_POLLHUP event - if it
reports that the connection ended, forward the event to the application.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-01-31 17:20:55 +01:00
Robert Lubos
f8751629c7 net: sockets: Report ZSOCK_POLLHUP when socket is in EOF state
Report ZSOCK_POLLHUP event if peer closed the connection, and thus the
socket is in EOF state.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-01-31 17:20:55 +01:00
Robert Lubos
4da1a75a6c net: llmnr: Rejoin IPv4 multicast group when iface is brought up
When network interface is brought up, rejoin the IPv4 multicast group
used by LLMNR service.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-01-26 10:50:24 +01:00
Robert Lubos
6f19b6e59e net: mdns: Rejoin IPv4 multicast group when iface is brought up
When network interface is brought up, rejoin the IPv4 multicast group
used by mDNS service.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-01-26 10:50:24 +01:00
Ryan Erickson
c6ace45a6c net: lwm2m: add uCIFI Battery object (3411)
Add the uCIFI Battery object to support
monitoring a devices battery.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2022-01-21 11:32:08 -05:00
Robert Lubos
4557d183b9 net: http_client: Set body_start pointer unconditionally
Set `body_start` pointer regardless of the body position in the recv
buffer. In result, the pointer shall indicate correctly position of the
body for each fragment, it's also explicit now that if the pointer is
not set for a fragment, there's no body in that particular fragment.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-01-21 11:31:49 -05:00
Robert Lubos
d002f8a524 net: lwm2m: Fix attribute sanity check
Validate the respective attribute parameters only if both are provided
at given level. This prevents from comparing for instance unset pmax
value (equal to 0) with some new pmin value sent by the server.

Additionally, fix the sanity check for the `pmax` value set on observer,
after fetching the attribute value at all levels (including the default
value at from the server object). Instead of using wrong max(pmin, pmax)
formula, set the pmax value only if it's a valid one (>= pmin),
otherwise ignore the value and set it to 0. This makes the notification
engine ignore the pmax value set for observation.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-01-21 11:31:20 -05:00
Eduardo Montoya
587d77a637 net: openthread: blank otPlatLog when logging is disabled
Implement an empty `otPlatLog` function when `CONFIG_LOG` is not
enabled. This also fixes the issue with `log_count_args` not being
available when logging is disabled.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2022-01-19 14:15:57 -05:00
Gerard Marull-Paretas
35b9b20764 net: lib: capture: drop DEV_DATA/DEV_CFG usage
Stop using redundant DEV_DATA/DEV_CFG macros and use dev->data and
dev->config instead.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-19 18:16:02 +01:00
Andrew Hedin
7f004f1b35 net: lwm2m: Add LwM2M gateway object
Add support for the gateway object [EXPERIMENTAL] used by the
MG100, BT510, and BT610 LwM2M demo.

Signed-off-by: Andrew Hedin <andrew.hedin@lairdconnect.com>
2022-01-18 13:19:12 -05:00
Przemyslaw Bida
00ef3d2fa7 net: openthread: Add openthread CSL clock uncert
This commit adds OPENTHREAD_PLATFORM_CSL_UNCERToption to Kconfig.
This option will allow user to configure openthreads CSL clock
uncertianity during build time.

Signed-off-by: Przemyslaw Bida <przemyslaw.bida@nordicsemi.no>
2022-01-18 13:11:08 -05:00
Jarno Lamsa
8f4a1fd906 net: lwm2m: Instance specific callbacks
Provide possibility to have instance specific callbacks
for writing the FW image and executing the update

Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
2022-01-13 10:34:25 +01:00
Jarno Lamsa
eedbbdc61a net: lwm2m: Provide backwards compatibility for single object 5
Previously the object 5 was only single instance object. Provide
backwards compatibility, so it can be continued to use with single
instance.

Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
2022-01-13 10:34:25 +01:00
Veijo Pesonen
9782f86450 net: lwm2m: separate FW update object instances - /5/*
This is a proof-of-concept implementation.

A device might have multiple firmware images which needs to be updated
separately. For example a single device might have

	* A bootloader image
	* An application image
	* External firmware image

Instead of pushing all these updates through the object instance 0 -
/5/0 - here a split to multiple has been made possible.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-01-13 10:34:25 +01:00
Daniel Leung
8d8369204f net: remove @return doc for void functions
For functions returning nothing, there is no need to document
with @return, as Doxgen complains about "documented empty
return type of ...".

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-01-12 16:02:16 -05:00
Andreas Chmielewski
fbae13122f net: lwm2m: enable monitoring of fw update state/result
The intention behind this patch is to know the current state/result
of a firmware update process in the application code. It makes it
possible to use pre/post_write_callbacks to get the proper value
of state (5/0/3) and result (5/0/5) resource.

Signed-off-by: Andreas Chmielewski <andreas.chmielewski@grandcentrix.net>
2022-01-11 11:52:50 +01:00
Eduardo Montoya
c6e31a888f net: openthread: disable CLI prompt
Avoid printing OpenThread prompt in Zephyr.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2022-01-07 12:48:27 -05:00
Eduardo Montoya
e9245a6198 net: openthread: revert CLI prompt workaround
`OPENTHREAD_CONFIG_CLI_PROMPT_ENABLE` can be used now.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2022-01-07 12:48:27 -05:00
Eduardo Montoya
48a5d42313 net: openthread: remove obsolete define
Remove `OPENTHREAD_CONFIG_PLAT_LOG_MACRO_NAME` which has been
deprecated in OpenThread.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2022-01-07 12:48:27 -05:00
Jarno Lamsa
5c3fd79bdc net: lwm2m: Security object resource correct type
Changed resource IDs 11 and 12 of the security object to use
signed integer as they are defined in the OMA specification.

Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
2022-01-04 09:08:55 -05:00
Jarno Lamsa
60160fb82f net: lwm2m: Update security object to 1.1
Add 1.1 version of the LWM2M security object.

Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
2022-01-04 09:08:55 -05:00
Jarno Lamsa
50ebb0e233 net: lwm2m: Update connectivity monitor object
Update the connectivity monitor object to version 1.2.
OMA core specification for the object adds 2 optional
resources.

Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
2022-01-04 09:08:38 -05:00
Ramiro Merello
4d5eee05f1 net: sockets_tls: Reset mbedtls session on handshake errors
According to MbedTLS API documentation, its session must be reset if
mbedtls_ssl_handshake returns something other than:
 - 0
 - MBEDTLS_ERR_SSL_WANT_READ
 - MBEDTLS_ERR_SSL_WANT_WRITE
 - MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS
 - MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS

In MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS and
MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS cases the function must be called
again when operation is ready. These cases now return -EAGIN or
continue to retry if it's a blocking call.

Signed-off-by: Ramiro Merello <rmerello@itba.edu.ar>
2022-01-04 09:07:21 -05:00
Michal Ciesielski
8b3d7f2a43 net: lwm2m: Add LWM2M object 9 software management
Adds support for LWM2M object 9 Software management.
This is implemented according to this release:
http://openmobilealliance.org/release/LWM2M_SWMGMT/V1_0_1-20200616-A/

Note that the XML is lacking some resources and for that reason those
resources are not included. This is a known problem by OMA and will be
fixed in a later releases.

This uses the lwm2m_pull_context to pull binaries in case
FIRMWARE_PULL_SUPPORT is enabled

Signed-off-by: Michal Ciesielski <michal.m.ciesielski@voiapp.io>
2021-12-21 13:36:50 +01:00
Michal Ciesielski
06b0a9c59d net: lwm2m: Make lwm2m_pull_context reusable
Add a semaphore to control that no collisions occur when multiple
sources want to use the pull_context

Add struct firmware_pull_context *ctx as an argument to the result_cb of
the context. This allows the receiver to do some kind of differentiation
on the source.

Signed-off-by: Michal Ciesielski <michal.m.ciesielski@voiapp.io>
2021-12-21 13:36:50 +01:00
Michal Ciesielski
2f046da6a1 net: lwm2m: FW Pull separate generic pull logic
Make it possible to reuse the pull logic from firmware_pull.c by
separating it to a separate file.

The firmware_pull_context is still owned and statically allocated in
firmware_pull.c and is being passed into lwm2m_pull_context.c as a
pointer.

In other words, pull_context, does not keep any state except for a
pointer to the context currently in use.

Signed-off-by: Michal Ciesielski <michal.m.ciesielski@voiapp.io>
2021-12-21 13:36:50 +01:00
Hou Zhiqiang
2fafd8559f net: socket: packet: Add EtherCAT protocol support
Add EtherCAT protocol support, now applications can
transmit/receive EtherCAT packets via RAW socket.

Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
2021-12-20 17:49:10 +01:00
Juha Heiskanen
87f4210450 net: lwm2m: Update LwM2m server object to v1.1
Added Kconfig configurable choise option for enable Server
object version 1.0 or 1.1.

Server Object v1.1 enable by default server initiated bootstrap
trigger when CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP is enabled.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2021-12-20 17:00:28 +01:00
Lukasz Maciejonczyk
4dc0353bcd net: openthread: store settings in RAM if there is no flash driver
This commit adds an option to store OpenThread settings in RAM for the
case where the flash driver is not available. This can be useful
for testing openthread on new platforms which are still under
development.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2021-12-09 11:04:49 -06:00
Robert Lubos
5110629ac1 net: mqtt: Fix SOCKS5 setsockopt error handling
Transports should close the socket in case of `setsockopt()` failure,
otherwise we end up with a leaked socket, as it won't be closed
elsewhere.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-12-01 13:54:30 -06:00
Robert Lubos
a0c669e7e6 net: sockets: Simplify common getsockname() implementation
Simplify common `getsockname()` implementation by using VTABLE_CALL()
macro, in the same way as other socket calls do. This additionally
allows to cover the case, when `getsockname()` is not implemnented by
particular socket implementation, preventing the crash.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-11-29 16:30:29 +01:00
Jair Jack
0b06a06814 net: lwm2m: Supported Protocol to pull firmware update must be optional
The supported protocol must be delivered to the firmware update object
as optional, then configured in the application.

This information is device/server dependent so does not can be fixed
in library.

Signed-off-by: Jair Jack <jack@icatorze.com.br>
2021-11-26 10:26:32 -05:00
Robert Lubos
666e9f80d6 net: ipv6: Remove in6_addr from packed net_ipv6_hdr struct
Replace unpacked in6_addr structures with raw buffers in net_ipv6_hdr
struct, to prevent compiler warnings about unaligned access.

Remove __packed parameter from `struct net_6lo_context` since the
structure isn't really serialized.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-11-25 10:46:35 -05:00
Robert Lubos
064200b420 net: ipv4: Remove in_addr from packed net_ipv4_hdr struct
Replace unpacked in_addr structures with raw buffers in net_ipv4_hdr
struct, to prevent compiler warnings about unaligned access.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-11-25 10:46:35 -05:00
Maik Vermeulen
f2ca6a8c22 net: lwm2m: Add observe callback for observe and notification events
Added an observe callback so that the application can register to
receive events like observer added/deleted, and notification acked/
timed out. The notifications can be traced back to the exact data
contained within them by use of the user_data pointer.

Fixes #38531.

Signed-off-by: Maik Vermeulen <maik.vermeulen@innotractor.com>
2021-11-25 10:45:36 -05:00
Lucas Dietrich
0a0e9079c3 net: mqtt: Add support for TLS option TLS_CERT_NOCOPY
Add an option in MQTT client context to take advantage of the
"TLS_CERT_NOCOPY" option when using  TLS socket transport.

Signed-off-by: Lucas Dietrich <ld.adecy@gmail.com>
2021-11-25 10:44:17 -05:00
Lucas Dietrich
4e103bcb20 net: sockets: tls: Support for DER cert chain and NOCOPY optimisation
Add TLS socket option "TLS_CERT_NOCOPY" to prevent the copy of
certificates to mbedTLS heap if possible.

Add support to provide a chain of DER certificates by registering
them with multiple tags.

Signed-off-by: Lucas Dietrich <ld.adecy@gmail.com>
2021-11-25 10:44:17 -05:00
Jordan Yates
df327eeb58 net: buf: POOL_FIXED_DEFINE explicit user data
Update the macro prototype to explicitly require the length of the
desired user data. Update all in-tree usage of this macro.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-11-24 16:04:50 +02:00
Jordan Yates
8236b600f7 net: buf: POOL_VAR_DEFINE explicit user data
Update the macro prototype to explicitly require the length of the
desired user data. Update all in-tree usage of this macro.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-11-24 16:04:50 +02:00
Robert Lubos
5ff1022fa1 net: websockets: Fix send with large payload
In case the payload and header size exceeded the network MTU size,
`websocket_send_msg()` would only send a part of the payload,
effectively leading to erronous results if called again to send the
rest. Fix the issue, by calling `sendmsg()` in a loop internally in case
it did not manage to send the entire websocket message in a single call.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-11-23 13:21:09 -05:00
Robert Lubos
8ac11b9b6f net: openthread: Fix for OT prompt in the Zephyr shell
OpenThread has changed it's behaviour in terms of prompt printing in the
CLI module. Previously it was only printed on the UART CLI backend, now
it's printed on every CLI backend. This results in a double prompt being
printed when combined with Zephyr shell (one from OT and other form
Zephyr).

This commit adds a temporary fix to prevent OT prompt from being printed
in Zehpyr shell. As a long term solution we should add an option to
OpenThread to allow to disable prompt on the output.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-11-10 16:36:18 +02:00
Andrew Hedin
a6f831fea6 net: lwm2m: Add IPSO filling sensor object
Add support for the filling sensor object used by the MG100
and BT610 LwM2M demo.

Signed-off-by: Andrew Hedin <andrew.hedin@lairdconnect.com>
2021-11-09 11:19:12 +01:00
Lukasz Maciejonczyk
2d7328af99 net: openthread: fix setting mac keys during stack reset in RCP
During stack reset in RCP, the mac keys are resseting my calling
otPlatRadioSetMacKey with aKeyId == 0. aKeyId == 0 was not handling
properly since it is not valid for mac keys. This commit fixes it.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2021-11-09 11:18:31 +01:00
Andrew Hedin
e0715556e7 net: lwm2m: Add IPSO current sensor object
Add support for the current sensor object used by the MG100
and BT610 LwM2M demo.

Signed-off-by: Andrew Hedin <andrew.hedin@lairdconnect.com>
2021-11-08 11:01:22 -05:00
David Brown
28d2ee6af7 net: sockets: tls: Clarify missing entropy warning
Change the wording of the warning printed when there is no entropy to
hopefully remove any doubt that there might be security in TLS without
an entropy source.  TLS connections with insufficient entropy are
trivially decodable, and should not be relied on for any type of
security.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-11-08 10:56:04 -05:00
Jair Jack
5b5417a1dd net: lwm2m: Way to pass a destination hostname to socket
net: lwm2m: When mbedtls CONFIG_MBEDTLS_SERVER_NAME_INDICATION is
enabled, a destination hostname must be passed to socket to properly
connect do lwm2m server.

Passing lwm2m context to lwm2m_parse_peerinfo

Signed-off-by: Jair Jack <jack@icatorze.com.br>
2021-11-06 21:37:12 -04:00
Sebastian Salveter
4d2e46ddd6 net: lwm2m: Add option to configure device service period
The device service creates a notification of the current time resource
every 10s. This commit adds the possibility to change this timer to a
different value thus giving more control over the way the device object
is notified.

Signed-off-by: Sebastian Salveter <sebastian.salveter@grandcentrix.net>
2021-11-04 07:30:29 -04:00
Marin Jurjević
b6ffd3cac8 net: lwm2m: add missing resources to Firmware Update object
Firmware Update object did not initialise resources PkgName,
PkgVersion and Firmware Update Protocol Support. Initialise
Firmware Update Protocol Support on creation and report CoAP
as default transfer protocol.

Signed-off-by: Marin Jurjević <marin.jurjevic@hotmail.com>
2021-11-03 15:34:15 +01:00
Robert Lubos
96b8ed85ad net: lwm2m: Fix removed engine_observer_list usage
`engine_remove_observer_by_path()` was not updated during some recent
LwM2M observer changes, still using the `engine_observer_list` which got
moved into the `lwm2m_context` structure. Update the function to align
with these changes.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-11-03 11:19:40 +01:00
Robert Lubos
e8f09b471e net: sockets: tls: Fix TCP disconnect detection in poll()
`ztls_socket_data_check()` function ignored a fact when
`mbedtls_ssl_read()` indicated that the underlying TCP connection was
closed. Fix this by returning `-ENOTCONN` in such case, allowing
`poll()` to detect such event.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-11-02 13:26:25 +01:00
Paul Gautreaux
50913bd6c8 net: lib: config: Fix the timeout when waiting on network
Loop by LOOP_DIVIDER counts instead of the number of seconds
specified in the timeout.

Fixes #39672

Signed-off-by: Paul Gautreaux <paulgautreaux@fb.com>
2021-11-02 13:23:10 +01:00
Robert Lubos
3a7016d99e net: lwm2m: Fix meaningless operant result coverity issue
There is no need to veirfy the result value of the strtol() operation,
as we copy the result to a 64 bit buffer anyway.

CID: 240696

Fixes #39810

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-10-31 15:31:05 -04:00
Pieter De Gendt
421ecb77a3 net: coap: Add coap_next_block_for_option function
Add a function to update the coap block context from a
packet, according to the block option enum provided.

The existing coap_next_block does not handle block1 transfers
properly because we need to inspect the block1 option
returned by the server. This function is reworked to make use
of the newly introduced one.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2021-10-27 13:46:19 -04:00
Pieter De Gendt
b966ba16a9 net: coap: Fix size1 for block1 transfers
According to RFC-7959:
When uploading with coap block1 requests the server may respond
with a size1 option (together with the response code 4.13).
This to indicate the maximum size the server is able and willing
to handle.

This commit changes the total_size in the current block context
being handled to the optional size1 option value from the server.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2021-10-27 13:46:19 -04:00
Pieter De Gendt
c89d5c5e45 net: openthread: Fix alarm timers reference calculation
The OpenThread stack uses uint32_t to calculate expiry time for
alarms, while comparing to zephyr's uint64_t uptime.

This commit fixes broken milliseconds alarms after ~49.7 days of
uptime.

Fixes #39704

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2021-10-26 09:28:27 -04:00
Veijo Pesonen
d3f4ae20cf net: coap: adds PATCH and iPATCH methods
Based on on RFC 8132 -
PATCH and FETCH Methods for the Constrained Application Protocol (CoAP)

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2021-10-25 13:26:19 +03:00
Veijo Pesonen
3071e97a3a net: coap: adds FETCH method
Based on on RFC 8132 -
PATCH and FETCH Methods for the Constrained Application Protocol (CoAP)

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2021-10-25 13:26:19 +03:00
Torsten Rasmussen
36f5600387 kconfig: net: experimental settings now uses select EXPERIMENTAL
With the introduction of `EXPERIMENTAL` and `WARN_EXPERIMENTAL` in
Zephyr all subsys/net and drivers/ethernet/Kconfig.e1000 settings
having `[EXPERIMENTAL]` in their prompt has has been updated to include
`select EXPERIMENTAL` so that developers can enable warnings when
experimental features are enabled.

The following settings has EXPERIMENTAL removed as they are considered
mature:
- NET_OFFLOAD
- NET_PROMISCUOUS_MODE

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-10-25 10:46:48 +02:00
Caspar Friedrich
c3ca5ada1a net: mqtt: Return meaningful error code from mqtt_init()
The condition checks whether the connection was established or not. The
return value should reflect that.

Signed-off-by: Caspar Friedrich <c.s.w.friedrich@gmail.com>
2021-10-21 10:56:32 -04:00
Damian Krolik
726656dda5 net: openthread: Add crypto backend based on PSA API
OpenThread has lately got an option to provide a custom
crypto backend that replaces the default, based on mbedTLS
API. Implement a backend based on ARM PSA crypto API that
is better suited for applications willing to take advantage
of the ARM trust zone technology.

Add Kconfig option: OPENTHREAD_CRYPTO_PSA_ENABLE which
enables that backend.

Also, another Kconfig option:
OPENTHREAD_PLATFORM_KEY_REFERENCES_ENABLE, implied by the
former, which enables usage of key references instead of
literal keys in OpenThread. It will eventually allow
OpenThread applications to keep sensitive data such as
encryption keys in the secure storage, accessible from the
secure world only.

Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
2021-10-17 11:51:38 -04:00
Tjerand Bjornsen
938e0e4966 net: lwm2m: Add default firmware update port
If a firmware update is fetched from a server, and no port number is set
in the URI (e.g. coap://example.com/fw_update), the client will try
to connect on the port specified by CONFIG_LWM2M_PEER_PORT.
If a port different from the peer port is to be used for firmware
update, this has to be set explicitly in the URI:
coap://example.com:5683/fw_update.

This fix adds CONFIG_LWM2M_FIRMWARE_PORT, which will be used when
fetching a firmware update without specifying the port number in the
URI.

Signed-off-by: Tjerand Bjornsen <tjerand.bjornsen@nordicsemi.no>
2021-10-14 16:34:48 -04:00
Robert Lubos
875c75c4f9 net: lwm2m: Replace float32_value_t with double
Replace the custom float32_value_t LwM2M type with native double, to
facilitate LwM2M API and improve floating point precission.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-10-13 10:13:32 -04:00
Nicolas Pitre
cf49699b0d net: sockets: socketpair: fix locking
The irq_lock() usage here is incompatible with SMP systems, and one's
first reaction might be to convert it to a spinlock.

But are those irq_lock() instances really necessary?

Commit 6161ea2542 ("net: socket: socketpair: mitigate possible race
condition") doesn't say much:

> There was a possible race condition between sock_is_nonblock()
> and k_sem_take() in spair_read() and spair_write() that was
> mitigated.

A possible race without the irq_lock would be:

thread A                thread B
|                       |
+ spair_write():        |
+   is_nonblock = sock_is_nonblock(spair); [false]
*   [preemption here]   |
|                       + spair_ioctl():
|                       +   res = k_sem_take(&spair->sem, K_FOREVER);
|                       +   [...]
|                       +   spair->flags |= SPAIR_FLAG_NONBLOCK;
|                       *   [preemption here]
+   res = k_sem_take(&spair->sem, K_NO_WAIT); [-1]
+   if (res < 0) {      |
+     if (is_nonblock) { [skipped] }
*     res = k_sem_take(&spair->sem, K_FOREVER); [blocks here]
|                       +   [...]

But the version with irq_lock() isn't much better:

thread A                thread B
|                       |
|                       + spair_ioctl():
|                       +   res = k_sem_take(&spair->sem, K_FOREVER);
|                       +   [...]
|                       *   [preemption here]
+ spair_write():        |
+   irq_lock();         |
+   is_nonblock = sock_is_nonblock(spair); [false]
+   res = k_sem_take(&spair->sem, K_NO_WAIT); [-1]
+   irq_unlock();       |
*   [preemption here]   |
|                       +   spair->flags |= SPAIR_FLAG_NONBLOCK;
|                       +   [...]
|                       +   k_sem_give(&spair->sem);
|                       + spair_read():
|                       +   res = k_sem_take(&spair->sem, K_NO_WAIT);
|                       *   [preemption here]
+   if (res < 0) {      |
+     if (is_nonblock) { [skipped] }
*     res = k_sem_take(&spair->sem, K_FOREVER); [blocks here]

In both cases the last k_sem_take(K_FOREVER) will block despite
SPAIR_FLAG_NONBLOCK being set at that moment. Other race scenarios
exist too, and on SMP they are even more likely.

The only guarantee provided by the irq_lock() is to make sure that
whenever the semaphore is acquired then the is_nonblock value is always
current. A better way to achieve that and be SMP compatible is to simply
move the initial sock_is_nonblock() *after* the k_sem_take() and remove
those irq_locks().

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2021-10-11 21:00:41 -04:00
Christopher Friedt
65b1c207f2 net: mdns + dns_sd: fix regression that breaks ptr queries
While adding support for service type enumeration, a regression was
introduced which prevented mDNS ptr query responses.

1. There was an off-by-one error with label size checking
2. Valid queries were failing to match in `dns_rec_match()` due to
   not checking for either NULL or 0 "wildcard" port

Fixes #39284

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2021-10-11 08:50:45 -04:00
Tjerand Bjornsen
872f560981 net: lwm2m: Fix device obj missing error code ri
From the OMA LwM2M Object and Resource Registry: "When the single Device
Object Instance is initiated, there is only one error code Resource
Instance whose value is equal to 0 that means no error."

This fix creates that initial error code resource instance, and makes
sure that it doesn't get deleted by the Reset Error Code resource.

Signed-off-by: Tjerand Bjornsen <tjerand.bjornsen@nordicsemi.no>
2021-10-07 15:44:46 -04:00
David Brown
fc3f4a627e net: sockets: tls: Use better error code
Mbed TLS 3.0 removes the definition for MBED_ERR_SSL_PEER_VERIFY_FAILED,
since non of its code ever returns that value.  Since there isn't really
a perfect response, instead return a somewhat generic response
indicating this was unexpected.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-10-07 14:02:40 -05:00
Flavio Ceolin
b78b7d5264 net: websocket: s/mbedtls_sha1_ret/mbedtls_sha1/
sha1 function signature changed in mbedTLS 3.0.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-10-07 14:02:40 -05:00
Flavio Ceolin
1cdc5034e1 net: sockets_tls: Fix mbedTLS usage
mbedtls_pk_parse_key signature has changed and requires an entropy
source.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-10-07 14:02:40 -05:00
Flavio Ceolin
4edcf48e05 sockets: tls: Enable access to mbedtls private fields
Several fields of structures in mbedTLS 3.0 are now private. To access
them directly is necessary to define MBEDTLS_ALLOW_PRIVATE_ACCESS.

That is a temporary fix, the proper solution is not access directly
but using proper API.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-10-07 14:02:40 -05:00
Mateusz Karlic
3844b79e96 net: sockets: sockets_can: Allow parallel receive/send
Implements mechanism similar to the one available in net/lib/sockets.c
(since the merge of #27054) in sockets_can to enable parallel rx/tx.

Fixes #38698

Signed-off-by: Mateusz Karlic <mkarlic@internships.antmicro.com>
2021-10-06 22:22:43 -04:00
Ryan Erickson
f7208bbb62 net: lwm2m: Add option to force close the connection
Add an option to force close the LwM2M connection
instead of always trying to deregister.
If on a cellular connection and the connection is dropped,
deregistering will never complete and take a long time
before retries fail. This option allows the app to close the
socket and quickly re-establish the connection when the
network connection is available again.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-10-05 19:23:59 -04:00
Veijo Pesonen
b3bc827366 net: lwm2m: Decouple CoAP message- and block size
If blockwise transfer is not in use it must be possible to send bigger
CoAP messages than what is the block size used with blockwise transfers.

To compensate for the increased memory usage number of in-flight packets
allowed could be decreased.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2021-10-05 19:22:54 -04:00
Veijo Pesonen
32b4ec44fe net: lwm2m: Fix Kconfig help about allowed...
...range for LWM2M_COAP_BLOCK_SIZE.

The range has been set to start from 64 bytes and now the help text has
been brought up to date.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2021-10-05 19:22:54 -04:00
Christopher Friedt
fa26dc0988 net: dns_sd, mdns: support service type enumeration
Support DNS-SD Service Type Enumeration in the dns_sd library
and mdns_responder sample application.

For more information, please see Section 9, "Service Type
Enumeration" in RFC 6763.

https://datatracker.ietf.org/doc/html/rfc6763

Fixes #38673

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2021-10-01 20:11:50 -04:00
Eduardo Montoya
b945d7aee4 openthread: align platform code to ARM PSA changes
Align `otPlatRadioSetMacKey` with latest upstream changes.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-10-01 11:37:38 +02:00
Robert Lubos
45e07dbbb3 net: sockets: tls: Ignore empty iovec entries in sendmsg
According to `sendmsg()` man pages, the `struct msghdr` can contain
empty records (iov_len equal to 0). Ignore them in TLS `sendmsg()`
implementation to avoid unnecessary calls to mbed TLS.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-29 11:08:40 +02:00
Robert Lubos
f0ec61ef70 net: mqtt: Handle incomplete zsock_sendmsg write
In case zsock_sendmsg did not send all of the data requested, update the
`struct msghdr` content and retry.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-29 11:08:40 +02:00
Robert Lubos
0dbdcc770d net: sockets: Add socket processing priority
When creating a socket, all of the registered socket implementation are
processed in a sequence, allowing to find appropriate socket
implementation for specified family/type/protocol. So far however,
the order of processing was not clearly defined, leaving ambiguity if
multiple implmentations supported the same set of parameters.

Fix this, by registering socket priority along with implementation. This
makes the processing order of particular socket implementations
explicit, giving more flexibility to the user, for example when it's
neeed to prioritze one implementation over another if they support the
same set of parameters.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-28 20:11:26 -04:00
Robert Lubos
8b851af02a net: sockets: Register native TCP/UDP like any other socket type
This will allow to assing priority to a native TCP/UDP socket
implementation as well.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-28 20:11:26 -04:00
Markus Fuchs
fb082a6923 net: dns: Make mdns and llmnr responders join their multicast groups
As with IPv6, the mdns and llmnr responders should join their multicast
groups for IPv4 instead of just adding the multicast address to the
interface.

Signed-off-by: Markus Fuchs <markus.fuchs@ch.sauter-bc.com>
2021-09-28 20:04:49 -04:00
Robert Lubos
2160e0fc36 net: lwm2m: Fix Registration failue reporting
In case LwM2M server or bootstrap server rejected
Registration/Registration Update/Deregsitration attempt, there were no
reasonable notification to the application. Fix this by reporting
LWM2M_RD_CLIENT_EVENT_*_FAILURE in such case.

Addtitionaly, remove pointless ENGINE_DEREGISTER_FAILED event, which
have no use in the state machine.

Finally, simplify the response code logging to prevent code duplication.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-21 09:32:31 -05:00
Robert Lubos
88c06aeb24 net: lwm2m: Fix IPSO Push Button counter incrementation
The Counter resource in the IPSO Push Button object was incremented
silently by the post write handler of the State resource. This prevented
the resource from being marked as updated, effectively preventing
the engine from sending notifications to observers.

Fix this, by setting the new counter value with `lwm2m_engine_set_u64()`
instead. This will update the resource value, and trigger the engine to
send notifications if needed.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-20 05:59:28 -04:00
Robert Lubos
be7faf7c08 net: http: Fix HTTP_DATA_FINAL notification
HTTP_DATA_FINAL was incorrectly notified in case Content Length field
was present in the HTTP respone - in such case it was set for every
response fragment, not only the last one.

Fix this by relying on `message_complete` flag instead of
`http_should_keep_alive()` function to determine whether to notify
HTTP_DATA_FINAL or not. As the HTTP parser calls the
`on_message_complete()` callback in either case (response is chunked or
not), this seems to be a more reasonable apporach to determine whether
the fragment is final or not.

Additinally, instead of calling response callback for
`on_body`/`on_message_complete` separately, call it directly from
`http_wait_data()` function, after the parsing round. This fixes the
case when headers were not reported correctly when the provided buffer
was smaller than the total headers length, resulting in corrupted data
being reported to the user.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-17 08:12:00 -04:00
Robert Lubos
81595ed4db net: lwm2m: Fix binary to float32_value_t conversion
The helper function to conver 32-bit binary float value to
float32_value_t incorrectly identified the "hidden" bit, resulting in
invalid conversion when TLV encoding was used to write a resource
(the output value was divided by 2).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-16 19:04:52 -04:00
Robert Lubos
36a72dd101 net: lwm2m: Fix JSON write handling
There were several issues preventing JSON format writes to work
correctly:

1. The formatter wrongly assumed that Base Name and Relative Name values
   read from the message are NULL terminated, which in result could give
   invalid results when combining them.
2. The formatter wrongly assumed that Relative Name is always present,
   which is not always the case. In result, it failed to parse messages,
   which contained full path in their Base Name Field
3. There were no boundaries check when reading JSON variable name/value,
   which could lead to buffer overflow in case malformed data was
   received.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-16 19:04:52 -04:00
Robert Lubos
a98d47b8eb net: lwm2m: Fix JSON floating point handling
Just like plain text, JSON parser ignored leading zeros after decimal
point, giving invalid results. Fix this in a similar way as for the
plain text.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-16 19:04:52 -04:00
Robert Lubos
20a4d181e1 net: lwm2m: Fix plain text floating point handling
Floating point parser for plain text format was parsing floats wrongly,
ignoring leading zeros after decimal points.

Fix this, by reusing atof32() function, already avaialbe in a different
part of the engine, which did the parsing correctly.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-16 19:04:52 -04:00
Robert Lubos
b6f69a6df1 net: lwm2m: Align float handling with specification
According to the specificaion, resources are not predefined to use 32 or
64 bit floating point numbers, but should rather accept any of them (as
indicated by the size of the TLV in the message). This lead to issues
for instance with Eclipse Leshan LWM2M server, where Leshan sent 64-bit
value, while Zephyr expected 32-bit, making it impossible to write
the resource.

Therefore, unify the float usage to 32-bit float representation and fix
the TLV parsing functions, to accept values sent as either 32 or 64 bit
float.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-16 19:04:52 -04:00
Robert Lubos
9cdc1bb944 net: sockets: tls: Fix TLS POLLHUP notification
The `poll()` function did not report POLLHUP if the peer ended the DTLS
session, making it impossible to detect such event on the application
side.

On the other hand, TLS erroneusely reported POLLHUP along with each
POLLIN event, as the 0 returned by the `recv()` socket call was
wrongly interpreted (it was expected to get 0 in return as 0 bytes were
requested).

Fix this by introducing a helper function to process the mbedtls context
and verify if new application data is pendingi or session has ended.
Use this new function in the poll handler, instead of a socket `recv()`
call, to remove any ambiguity in the usage, for both TLS and DTLS.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-16 18:14:33 -04:00
Robert Lubos
d0affeff69 net: sockets: tls: Return ENOTCONN when DTLS client session ends
Notify the application when DTLS client session ends by returning
ENOTCONN on such event. Additionally, reset the mbed TLS session
structures, allowing to reinstante the session on the next send() call.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-16 18:14:33 -04:00
Robert Lubos
b999c47424 net: sockets: tls: Fix incorrectly used errno codes
ECONNABORTED was returned in case tls_mbedtls_reset() function for
resetting session failed, which can be caused by memory shortage. Return
ENOMEM instead.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-16 18:14:33 -04:00
Robert Lubos
083f3065b4 net: lwm2m: Remove LWM2M_RES_TYPE_U64 type
Since it's not possible to encode full range of 64-bit unsigned integer,
remove this type from the LwM2M implementation, and replace its uses
with 64-bit signed integer.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-10 11:04:41 +02:00
Robert Lubos
b474e0a8c3 net: lwm2m: Fix unsigned integers ecoding in TLV
As the resource values represented by the unsigned integers were casted
to integers of a corresponding size in the read handler, they were not
ecoded properly if the unsigned value was larger than the maximum
integer value of the corresponding size (i.e. they were encoded as
negative values).

Fix this by casting the unsinged value to a wider integer type, to
prevent incorrect interpratetion of the data provided. The TLV encoding
functions take care of the optimization (i. e. encoding integers on the
minimum number of bytes needed), so it should prevent bandwith waste if
the unsigned value would actually fit into the integer of the
corresponding size.

Similar case is for the write hander, where unsigned integers encoded at
8 bytes were not processed correctly. Fix this by using wider decoder as
well.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-10 11:04:41 +02:00
Benedikt Schmidt
a8b7caa58d net: http: switch to zsock_ for http_client
Using zsock_ in http_client instead of the POSIX API versions of the
functions allows the usage of http_client in combination with
CONFIG_POSIX_API.

Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
2021-09-09 21:16:28 -04:00
Marcin Niestroj
02fa7be52d net: mqtt: check mqtt_abort() function parameters before locking
Function parameters can be checked without MQTT instance lock being
held. Additionally if NULL parameter would be passed (which this check
tries to handle), then function would return without releasing lock.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2021-09-02 19:36:03 -04:00
Pavlo Hamov
6975d92324 net: socket: fix significant buffer tls send
Sending of > 2k buffers leads to split socket writes.
Current implementation is not checking for full buffer size.
ztls_sendmsg_ctx proceeds to next iov on sucessful write.

Solution: Add loop into ztls_sendmsg_ctx to process whole buffer
before proceeding to next iov.

Signed-off-by: Pavlo Hamov <pasha.gamov@gmail.com>
2021-09-02 19:35:50 -04:00
Eduardo Montoya
36459a95ea net: openthread: allow to enable/disable TCP
Allow to enable/disable the OpenThread TCP implementation. Disable
it by default.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-09-01 10:37:41 +02:00
Johann Fischer
f460848002 net: ot: rework NCP interface configuration
Rework NCP interface configuration and NCP sample. Remove
CONFIG_OPENTHREAD_COPROCESSOR_SPINEL_ON_UART_DEV_NAME and
CONFIG_OPENTHREAD_COPROCESSOR_SPINEL_ON_UART_ACM Kconfig
options in favor of chosen node zephyr,ot-uart usage.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-23 18:53:47 -04:00
Fabio Baltieri
f88a420d69 toolchain: migrate iterable sections calls to the external API
This migrates all the current iterable section usages to the external
API, dropping the "Z_" prefix:

Z_ITERABLE_SECTION_ROM
Z_ITERABLE_SECTION_ROM_GC_ALLOWED
Z_ITERABLE_SECTION_RAM
Z_ITERABLE_SECTION_RAM_GC_ALLOWED
Z_STRUCT_SECTION_ITERABLE
Z_STRUCT_SECTION_ITERABLE_ALTERNATE
Z_STRUCT_SECTION_FOREACH

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2021-08-12 17:47:04 -04:00
Eduardo Montoya
4b4e298914 net: openthread: propagate security and header updated flags
When transmitting a frame, inform the radio driver whether
security processing and/or header updates are needed or not.

When a frame was transmitted, inform back to OpenThread whether
the security procedure and/or header updates were completed for
the frame or not.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-08-11 11:29:36 -04:00
Przemyslaw Bida
678a170925 net: openthread: Add capability to disable properly CSL.
This commit adds capability to disable CSL sampling by setting
CSL period to 0.

Signed-off-by: Przemyslaw Bida <przemyslaw.bida@nordicsemi.no>
2021-08-07 20:27:25 -04:00
Emil Lindqvist
dab4616e45 net: socket: fix regression causing corrupted poll timeout
k_timeout_t was converted to ticks using a nonsense function
causing poll timeout corruption for offloaded sockets; this
commit uses ticks directly from the struct instead.

Fixes #37472

Signed-off-by: Emil Lindqvist <emil@lindq.gr>
2021-08-06 19:20:48 -04:00
Emil Lindqvist
f9023d2c41 net: sockets: dtls: reset mbedtls session on timed out handshake
According to MbedTLS API documentation, its session must be
reset if mbedtls_ssl_handshake returns timeout error. This
commit resets the session for said return value, and that
allows us to call send() multiple times even if handshake
times out for previous calls.

Fixes #35711

Signed-off-by: Emil Lindqvist <emil@lindq.gr>
2021-08-06 19:19:26 -04:00
Lukasz Maciejonczyk
53531a7682 openthread: implement missing time service functionality
Add missing otPlatTimeGet implementation which is needed for proper
calculation the time offset in host-RCP communication.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2021-08-05 16:14:24 +02:00
Eduardo Montoya
3872812ffc net: openthread: fix error codes for TX done
Fix potential bug when returning error codes not handled by
OpenThread in `otPlatRadioTxDone`.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-08-05 11:26:27 +02:00
Robert Lubos
bbc6c66ed8 net: websocket: Fix poll handling for offloaded sockets
ZFD_IOCTL_POLL_OFFLOAD operation needed special handling, as it needed
to modify the fds table for the offloaded implementation, overwriting
websocket file descriptors with the underlying offloaded ones. This is
only needed for the offloaded sockets, as the native implmentation use
POLL_PREPARE/UPDATE operations instead.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-08-04 16:58:15 +02:00
Robert Lubos
a6a9d7a368 net: websocket: Fix ioctl implementation for websocket
The websocket implementation of ioctl wrongly passed websocket context
to the undrelying `ioctl` implementation instead of the context of the
underlying socket.

Additionally, currentl implementation used the vtable of the native
socket implementation unconditionally, making it unusable with an
offloaded underlying socket.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-08-04 16:58:15 +02:00
Maik Vermeulen
7a2a28b9d5 net: lwm2m: Synchronized functions mutating the RD client's state
A mutex is used to syncrhonize the start, stop and service() functions
of the RD client. Previously it could happen that while service() was
working on e.g. bootstrapping, a stop() call by another thread would
close the socket. Then the bootstrapping process would detect it as a
network error, and restart the process.

Fixes #37170.

Signed-off-by: Maik Vermeulen <maik.vermeulen@innotractor.com>
2021-08-03 10:22:10 -04:00
Pieter De Gendt
4192c8b83e net: coap: coap_next_token single sys_rand_get call
Improve coap_next_token by using a single sys_rand_get call.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2021-07-29 11:47:51 -04:00
Eduardo Montoya
cf57b86363 net: openthread: add three configuration options
Enable to configure:
- `OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH`
- `OPENTHREAD_CONFIG_IP6_MAX_EXT_UCAST_ADDRS`
- `OPENTHREAD_CONFIG_IP6_MAX_EXT_MCAST_ADDRS`

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-07-29 11:00:19 -04:00
Fabio Baltieri
532a85ccd9 tests: net: dns-sd: add a test case for setup_dst_addr
Add a test case for mdns setup_dst_addr.

Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
2021-07-26 10:46:50 -04:00
Fabio Baltieri
c25b04bfd3 net: mdns: set the correct type of dst addr
Check for the address family of the packet when setting the multicast
destination address used in the response. Current code checks either the
query type or the stack configuration, which can result in setting the
wrong type of address for the frame.

Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
2021-07-26 10:46:50 -04:00
Fabio Baltieri
1d500f075c net: dns_sd, mdns: add few missing strdup
Add few missing log_strdup found when running the mdns code with
debugging enabled.

Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
2021-07-26 10:46:50 -04:00
Robert Lubos
0722e1d896 net: lwm2m: Prevent notifications on non-readable resources
In case a non-readable resource gets updated (either by the server or
with an API), it makes no sense to send a notification in such case, as
no such resources are not included in notifications anyway.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-07-20 13:33:22 +02:00
Jedrzej Ciupis
25ebb42bd9 net: pkt: remove ieee802154_frame_retry flag
Flag that indicates if a given packet is being retransmitted has become
obsolete since more detailed flags were added. This commit removes the
flag and references to it altogether.

Signed-off-by: Jedrzej Ciupis <jedrzej.ciupis@nordicsemi.no>
2021-07-19 18:15:56 +03:00
Robert Lubos
8a4e489739 net: sockets: dtls: Fix handshake with socket offloading
Fix `poll()` handling for DTLS clients when the underlying socket is an
offloaded socket. As in this case no `k_poll()` is used underneath, it's
not possible to monitor the handhshake status with `tls_established`
semaphore. Instead, do the following:

1. If no handhshake is in progress yet, just drop the incoming data -
   it's the client who should initiate the handshake, any data incoming
   before that should not be processed.
2. If handshake is currently in progress, lift the `POLLIN` flag and add
   small delay to allow the other thread to proceed with the handshake.
3. Otherwise, just proceed as usual.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-07-16 22:09:58 -04:00
Robert Lubos
b4366a8732 net: sockets: tls: Fix handshake on non blocking sockets
The TLS/DTLS handshake in most cases is a blocking process, therefore
the underlying socket should be in a blocking mode to prevent busy
looping in the handshake thread. Fix this by clearing the O_NONBLOCK
flag on the underlying socket before the handshake, and restoring it
afterards.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-07-16 22:09:04 -04:00
Pieter De Gendt
de13034502 net: openthread: add Kconfig options for periodic parent search
The openthread has enhanced features for periodic parent search,
this commit adds kconfig options to enable and configure these.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2021-07-15 15:16:32 +02:00
Eduardo Montoya
72cc39d843 net: openthread: handle NONE level logs
`OT_LOG_LEVEL_NONE` has some uses within OpenThread but it is not
hanled in the Zephyr's platform implementation. This commit makes
use of those logs as `LOG_LEVEL_ERR` level.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-07-14 13:14:59 -04:00
Chih Hung Yu
a927ae39ed net: lib: sockets: Fix assertion failure when zsock_close()
When zsock_close() is called, socket is freed before the mutex for the
socket is unlocked. If the freed socket is given to another thread
immediately, the mutex for the socket will be initialized by the new
socket owner, while the mutex is still locked by the thread calling
zosck_close().

Fixes #36568

Signed-off-by: Chih Hung Yu <chyu313@gmail.com>
2021-07-12 20:16:37 -04:00
Damian Krolik
bf3c6e7ba4 manifest: update openthread
Regular OpenThread upmerge to bring in a fix for a possible
infinite loop and support for DNS service subtypes.

Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
2021-07-07 07:47:52 -05:00
Robert Lubos
b369156e28 net: lwm2m: Fix how payload offset is calculated
Instead of manually computing payload offset, let the CoAP library do
the work, and use the payload pointer returned by the
`coap_packet_get_payload()` function instead.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-07-07 07:40:55 -05:00
Robert Lubos
0bc4e7619b net: coap: Fix coap_packet_get_payload function
The function did not work correct for packets generated with Zephyr
APIs, as `max_len` holds the entire buffer size, not the actual packet
size.

Additionally, unify how Payload Marker is handled in the calculation -
currently the coap parsing function adds it to the `opt_len` field,
which is counter-intuitive.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-07-07 07:40:55 -05:00
Robert Lubos
78e84eb3e7 net: coap: Adjust offset value after packet parsing
It is important that offset is set in the same manner, regardless of the
origin packet - it should indicate the final packet length in both
cases, when the packet is generated on the Zephyr side with CoAP APIs,
and when it's parsed from the UDP datagram. This allows for functions
like `coap_packet_get_payload()` to work correcty in both cases.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-07-07 07:40:55 -05:00
Robert Lubos
6d366093c8 net: sockets: socketpair: Rename read/write signals
Rename `write_signal` to `readable` and `read_signal` to `writeable`
which are more meaningful to the actual states they represent, and make
the code analysis easier.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-07-02 22:22:42 -04:00
Robert Lubos
e415518f5f net: sockets: socketpair: Fix poll signalling
In case read or write were called before the actual poll() call, the
poll() function was not signalled correctly about such events, which in
order could lead to a deadlock if the poll() was called with infinite
timeout.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-07-02 22:22:42 -04:00
Markus Rekdal
3221a1e8e7 net: lwm2m: Fix handling of multi instance resources with one instance
This will fix a bug caused by creating a multi instance resource with
only a single resource. Previously this was treated as a single instance
resource. This is now properly treated as a multi instance resource with
one instance
Signed-off-by: Markus Rekdal <markus.rekdal@nordicsemi.no>
2021-07-02 08:30:28 -04:00
Pieter De Gendt
13d5894e46 net: openthread: Implement otPlatAssertFail
Add a platform implementation for OpenThread's otPlatAssertFail
and enable it by default.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2021-07-01 13:22:01 -04:00
Vlad Tuhut
7580623a36 net: mqtt: Add custom transport type
Add new custom transport type.
This allows user defined transport for MQTT communication.
The user must implement the transport procedure.

Fixes **#27015**

Signed-off-by: Vlad Tuhut <vlad.tuhut@raptor-technologies.ro>
2021-06-29 11:34:57 -04:00
Pieter De Gendt
cdf7d314fe net: coap: Fix coap client observe out-of-order messages
coap_response_received returned NULL if the observe option was out of
order, however it makes more sense to return the coap_reply handler
without actually calling it.

Additionally the reorder check has been modified to partially match
the RFC.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2021-06-29 10:27:22 -04:00
Piotr Mienkowski
ccc0999b80 net: refactor tftp library
- bugfix: Accept initial tftp server reply from a port different than
  the one used to establish the connection (typically 69) as mandated
  by RFC 1350. Previous implementation was not standard compliant.
- bugfix: close socket in case of error or timeout.
- bugfix: Reset retransmit counter after receipt of a good packet.
- bugfix: Use CONFIG_TFTP_LOG_LEVEL to set log level.
- api: upon successful receipt of the file set `client.user_buf_size`
  to the size of the file received.
- Restructure the code, comments.
- Limit usage of global variables.
- Limit usage of `goto`.

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2021-06-29 09:15:55 -04:00
Eduardo Montoya
0f73fbdbfe drivers: ieee802154: add CSL receiver for nRF5
Implement CSL receiver functionality in nRF5 radio driver.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-06-24 11:31:24 -04:00
John Power
3138d89fd9 net: lwm2m: notify timeout handling
Added notify_timeout_cb to struct lwm2m_ctx to allow application to
 handle notify timeout
Added lwm2m_rd_client_update to lwm2m.h to allow application to
 trigger registration update
Added notify_message_timeout_cb which calls notify_timeout_cb from
 struct lwm2m_ctx and logs an error message

Fixes #31499

Signed-off-by: John Power <john.power@xylem.com>
2021-06-23 08:02:06 -04:00
Przemyslaw Bida
976c413d75 openthread: fix not working ot diag repeat command
This commit fixes diag repeat command port by fixing issue with
incorrectly handled repeat timer.

Signed-off-by: Przemyslaw Bida <przemyslaw.bida@nordicsemi.no>
2021-06-22 08:21:41 -04:00
Jukka Rissanen
703233e115 net: socket: Allow microsecond accuracy in zsock_select()
Allow caller to specify microsecond accuracy and not convert
to milliseconds.

Fixes #36072

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-06-17 15:23:13 +03:00
Jukka Rissanen
1b025c8d64 net: socket: Make zsock_select() a syscall
Make zsock_select() a syscall so that the following commit
can call the internal poll implementation directly. This is
needed as zsock_select() will not call zsock_poll() directly
in order to allow select to use microsecond timeout accuracy.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-06-17 15:23:13 +03:00
Kiril Petrov
613677daf8 net: lwm2m: fix build with bootstrap enabled
After lwm2m async io was introduced with 32989a38f0,
one instance of function lwm2m_send_message() was left unchanged,
and makes build to fail when boostrap support is enabled.

Signed-off-by: Kiril Petrov <retfie@gmail.com>
2021-06-14 14:10:36 +03:00
Kiril Petrov
a0fd010455 net: lwm2m: code clean-up after switch to async socket io
Three is no need to check return code as lwm2m_send_message_async()
never fails.

Signed-off-by: Kiril Petrov <retfie@gmail.com>
2021-06-14 14:10:36 +03:00
Dominik Dess
f55c473a06 net: lwm2m: lwm2m stops sending messages after encountering signals on send
Fixed issue that caused message to be not correctly reset even after
 it is consumed after send sets errno to EAGAIN or EWOULDBLOCK

Signed-off-by: Dominik Dess <dominik.dess@grandcentrix.net>
2021-06-12 08:51:08 -05:00
Pawel Dunaj
1286c8d105 net: depend dns resolver on native net
DNS resolver won't work for offloaded stack.

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2021-06-10 17:44:51 +03:00
Rafał Kuźnia
24b2ef4590 net: openthread: set ieee802154_frame_retry flag
The ieee802154_frame_retry will be set by the OpenThread integration
layer in the event of frame retransmission.

Signed-off-by: Rafał Kuźnia <rafal.kuznia@nordicsemi.no>
2021-06-10 11:03:40 +03:00
Eug Krashtan
86fc962a48 net: coap: Keep user data inside message
Keeping user data in the CoAP packet

Signed-off-by: Eug Krashtan <eug.krashtan@gmail.com>
2021-06-09 18:41:42 +03:00
Eduardo Montoya
ae44b30b41 drivers: ieee802154: include timestamp in acks
Fill the ACK timestamp field in nRF5 driver. This is required by
OpenThread for the proper CSL transmitter functioning.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-06-08 04:54:38 -05:00
Ievgen Glinchuk
1ce8d6fae4 net: dns: Fix multiple IP DNS resolution
Fixed mutli-IP DNS resolution as previously the same IP address was
used to populate all AI entries and added DNS_RESOLVER_AI_MAX_ENTRIES
config entry to define max number of IP addresses per DNS name to be
handled.

Signed-off-by: Ievgen Glinchuk <john.iceblink@gmail.com>
2021-06-07 23:54:55 -04:00
Lukasz Maciejonczyk
1f0b783bbb drivers: ieee802154: replace enh ack probing with generic IE conf
Use IE variable of ieee802154 MAC frame instead of Thread specific
configuration call for configuring injection of vendor specific
data into enh ack.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2021-06-07 10:41:07 +03:00
Henning Fleddermann
05b2018ffa lwm2m: keep track of observations per client
this has a number of advantages:
- allows to only create notifications for each client if there are no
  messages already waiting to be send, in practice prioritizing the
  memory for messages for answers, thus staying more "responsive".
- saves a fair bit of memory by eliminationg now redundant client_ctx
  pointer per observer.
- fixes a potential subtle bug: previously, an observer reset would've
  stopped the first observation found with a matching token, which
  might've belonged to a differen client.

Signed-off-by: Henning Fleddermann <henning.fleddermann@grandcentrix.net>
2021-06-07 10:39:37 +03:00
Henning Fleddermann
32989a38f0 lwm2m: use asynchronous socket io
This restructures the lwm2m_engine to use a non-blocking socket access
instead of the previously used blocking style, and eliminates any
socket-access from outside of the main work loop.

The main motivation behind this is an issue within nordics
nrf_modem_lib/modem-fw on nrf9160, that leads to socket send() calls to
block indefinitely when the shared memory used for
rpc-communication with the modem is already exhausted because of
incoming data.

This lead to the lwm2m_engine locking up on send calls when there is
also a large amount of incoming data.

This works around this issue, by only issuing send calls when poll
reports the socket to be ready for sending, and (more importantly) by
always receiving all buffered incoming data before sending anything.

There might still be a (perhaps academic) possibility where this
situation might be triggered, when  the scheduler interrupts the lwm2m
thread in-between receiving and sending, but for now we have not yet
observed this.

Besides working around the aforementioned issue, this also simplifies
the way resends are handled as they are no longer send from the main
system-workqueue, and limits all interaction with the sockets to a
single thread.

Signed-off-by: Henning Fleddermann <henning.fleddermann@grandcentrix.net>
2021-06-07 10:39:37 +03:00
Hubert Miś
b39537d151 drivers: ieee802154: make keys management API generic
Keys management API for IEEE 802.15.4 drivers was specific for Thread
protocol. With this change API is more generic and aligned with Thread
needs.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-06-07 10:39:14 +03:00
Robert Lubos
34fb892fb5 net: sockets: tls: Use secure random generator from Zephyr
Zephyr has introduced secure random generator API after the TLS sockets
were implemented. Use this new API in TLS sockets implementation,
instead of implementing secure RNG with mbedTLS in the module itself.
This facilitates integration of the HW RNG accelerators with the TLS
sockets module.

Signed-off-by: Frank Audun Kvamtrø <frank.kvamtro@nordicsemi.no>
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-06-04 16:27:17 -05:00
Lukasz Maciejonczyk
8b12311bdf net: openthread: add option to configure software transmission security
If radio driver supports transmission security we need an option
to disable transmission security which by default is done by OT stack
for Thread v1.2

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2021-06-04 16:19:16 -05:00
Eduardo Montoya
9c6895105d drivers: ieee802154: fix ACK length handling
OpenThread expects the FCS field at the end of the ACK frame to be
passed with `otPlatRadioTxDone`.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-05-27 12:59:06 -05:00
Emil Lindqvist
91177eebc1 net: sockets: tls: check return code from fcntl
Not checking return code in fcntl can result in interpreting -1 as
flags, and cause unexpected behaviour.

Fixes #35541

Signed-off-by: Emil Lindqvist <emil@lindq.gr>
2021-05-27 15:44:03 +02:00
Jukka Rissanen
c53d483b6d net: sockets: Do not hijack k_fifo API name
The k_fifo_ prefix is meant for kernel API functions, and
not to our socket helper. So remove the k_ prefix in order
to avoid confusion.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-05-24 23:30:18 -04:00
Jukka Rissanen
20a51b49a0 net: sockets: Release the socket lock if needed
If we are waiting all the data i.e., the MSG_WAITALL flag is set,
then if we have not yet received all the data at the end of the
receive loop. We must use the condition variable to get the signal
when the data is ready to be received. Otherwise the receive loop
will not release the socket lock and receive_cb will not be able
to indicate that data is received.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-05-24 23:30:18 -04:00
Jukka Rissanen
1184089d54 net: sockets: Add locking to receive callback
Fix a regression when application is waiting data but does
not notice that because socket layer is not woken up.

This could happen because application was waiting condition
variable but the signal to wake the condvar came before the
wait started. Normally if there is constant flow of incoming
data to the socket, the signal would be given later. But if
the peer is waiting that Zephyr replies, there might be a
timeout at peer.

The solution is to add locking in socket receive callback so
that we only signal the condition variable after we have made
sure that the condition variable is actually waiting the data.

Fixes #34964

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-05-24 23:30:18 -04:00
Benjamin Lindqvist
f0f1a4d724 net: lwm2m: no duplicate device error codes
The resource description on the OMA LwM2M registry states that only the
first instance of a particular error should trigger creation of a new
error code instance.

Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
2021-05-21 04:55:26 -05:00
Eduardo Montoya
68626227a3 net: openthread: fix CSL API
A couple of fixes on the OpenThread radio implementation.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-05-18 11:24:40 -05:00
Justin Morton
e3517e5080 net: http: update status if no status text is provided
Call on_status if the Reason-Phrase is not provided.
This allows for the numeric status code to be set.
Also, ensure the numeric status code is always set
in on_status, not just if the specific callback is set.

Signed-off-by: Justin Morton <justin.morton@nordicsemi.no>
2021-05-18 11:23:59 -05:00
Jan Buenker
6815ef4a46 net: lwm2m: Only parse TLV from the first block
This was already implemented for firmware update packages.
For other opaque resources it failed to determine the target resource
id, which is now stored in the block_context.

Signed-off-by: Jan Buenker <jan.buenker@grandcentrix.net>
2021-05-13 22:07:25 -04:00
Damian Krolik
643eb2080b openthread: shell: Do not execute OT commands when OT is not ready
OpenThread shell tries to execute commands without checking
if the shell has already been initialized. As a result, we
may hit an assertion in the OpenThread CLI code. It's
particularly painful in automated tests which spawn commands
very early in the firmware boot process.

Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
2021-05-12 08:31:08 -05:00
Lukasz Maciejonczyk
977aba6d02 net: openthread: Fix multiple Kconfig enablers for Link Metrics
Remove duplicated enabler for Link Metrics feature.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2021-05-11 09:53:29 +03:00
Robert Lubos
eaeac46720 net: openthread: Fix OT shell crash
After the recent OpenThread upmerge, OpenThread changed its behaviour in
terms of CLI handling during commissioning procedure. OpenThread will
now call the registered CLI callback when it recieves the Discovery
message.

This resulted in a crash if no CLI command was executed by the user
before, because the `shell_p` pointer was only set in the command
handler. As it was not set to the actual shell backend instance, it
caused a crash (or assert if enabled) in the `shell_vfprintf()`
function.

Fix this by verifying the `shell_p` pointer in the
`otConsoleOutputCallback()` function before use. Additionally, set the
pointer to the most common UART shell backed (if enabled) in the
initialization function so that the initial messages from OpenThread are
not dropped.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-05-11 09:53:12 +03:00
David Brown
aa5187ecde tls: Change some external symbols from Mbed TLS
In Mbed TLS:
    commit eccd88871767e2fba5f3a079cfdfcb77c376cf20
    Author: Gilles Peskine <Gilles.Peskine@arm.com>
    Date:   Tue Mar 10 12:19:08 2020 +0100

        Rename identifiers containing double-underscore

changes the name of a symbol we use.  As part of upgrading to newer
versions of Mbed TLS, change the name of the symbol we use.

A better fix would be to not use this symbol at all, and perhaps define
our own symbol the same way this internal symbol is defined within the
library.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-05-09 09:59:22 -05:00
Lukasz Maciejonczyk
103b516a3c net: openthread: add Link Metrics API
This commit implements the OpenThread APIs to configure Enhanced-ACK
Based Probing in radio for a specific Initiator. This is needed for
Link Metrics functionality.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2021-05-06 09:57:15 -05:00
Eduardo Montoya
93fda9356f net: openthread: complete CSL receiver API
This commit implements the missing OpenThread APIs related to CSL
receiver configuration.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-05-06 07:47:10 -05:00
Robert Lubos
126da28620 net: lwm2m: Trigger registration update only when registered
Add extra check for the LwM2M client state, to allow triggering of the
Registration Update message only when registered.

This fixes an issue, when the `trigger_update` flag could be set during
the bootstrap procedure (when the value of the Lifetime resource was
set), which resulted in an uneccessary Registration Update message just
after the successful registration.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-05-05 14:04:41 -05:00
Eduardo Montoya
121a164ec0 net: openthread: add CSL receiver API
This commit implements the OpenThread APIs to configure a radio
reception slot at a specific time. This is needed for the correct
functioning of a CSL receiver.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-05-05 14:04:14 -05:00
Eduardo Montoya
a47677da06 net: openthread: add CSL transmitter API
This commit implements the OpenThread APIs to pass MAC keys and
frame counter to the radio layer in order to process the
transmission security. This is needed for the correct functioning
of a CSL transmitter.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-05-05 14:33:47 +02:00
Lukasz Maciejonczyk
4500862af1 net: openthread: Init NCP after USB communication is established
The device has sent RESET_POWER_UP message before the communication
with the host hadn't been established. It could be observed with
pyspinel which displayed `Framing error`.

This commit fixes the bug by initializing NCP after the host stated
is ready to communicate.

This commit reverts initialization the USB stack into function
otPlatUartEnable to be consistent with others OpenThread platforms.
OpenThread co-processor samples are not affected by #27071 as they use
USB for SPINEL communication with host and not for UART console.

Note:
When co-processor communicates by USB CDC ACM and it is hard reset
(what is happening in current Zephyr OpenThread platform)
the connection needs to be properly handled by the host.

For posix platform used together with RCP it was implemented in:
https://github.com/openthread/openthread/pull/6454

and for NCP:
https://github.com/openthread/wpantund/pull/492 .

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2021-04-30 12:58:31 -05:00
Robert Lubos
39aee39cf9 net: openthread: Align with the new NCP API
OpenThread modified its NCP API, so we need to align with these changes
in Zephyr.

One of the major changes was removal of UART from the platform APIs.
`openthread/platform/uart.h` header file was moved to
`examples/platforms/util/uart.h` so we need to use the new location in
Zephyr. This means that OpenThread no longer impose the UART API but for
the simplicity of the upmerge I've kept the UART APIs as they are for
now.

The NCP initialization function have now to register a send handler,
and the appropriate transport driver have to call NCP callbacks when
transmission/reception is done. For now, re-use the existing code of
the UART driver, just as the upstream NCP application does.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-04-30 12:55:02 -05:00
Robert Lubos
c2ad0dff72 net: openthread: Use OT mutex in OT shell
Use OpenThread mutex in order to protect OT CLI API call instead of
halting the OpenThread thread.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-04-30 12:55:02 -05:00
Robert Lubos
983ee8b088 net: openthread: Align with the new CLI API
The OpenThread CLI API has changed therefore it's needed to align
OpenThread Shell implementation in Zephyr with these changes.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-04-30 12:55:02 -05:00
Robert Lubos
0d1577f7fe net: lwm2m: Add API function to delete object instance
Since the API already has a function to create an LwM2M object instance,
it makes sense to add a corresponding delete funtion, allowing the
application to delete created objects.

Additionally, for the remote delete set the Registration Update trigger
only when not in bootstrap mode.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-04-29 09:51:54 -04:00
Robert Lubos
66c5fdc984 net: lwm2m: Fix Registration Update send on object creation
The Registration Update message should be sent whenever an object
instance is created or deleted. Currently this was only the case when an
object instance was created by the server and not by the application.
Fix this by triggerng the Registration Update from the API function
as well.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-04-29 09:51:54 -04:00
Marcin Niestroj
71c31c45c7 net: dns: add dns_resolve_reconfigure() API
So far there was no dedicated mechanism for replacing DNS servers with
new list. Add dns_resolve_reconfigure() API that allows to achieve that
in a thread-safe manner.

Introduce 3rd state in DNS context lifetime by converting from 'bool
is_used' to 'enum dns_resolve_context_state state'. This new
DEACTIVATING state allows to mark a DNS context as busy and safely close
context without holding lock. Closing DNS context with released lock
prevents deadlock in case net_context_close() has to synchronize with a
separate thread executing handler passed to net_context_recv() (which is
the case for example with ESP-AT WiFi driver).

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-04-29 08:00:09 -04:00
Marcin Niestroj
83e5953783 net: dns: protect 'is_used' with mutex
ctx->is_used member seemed to be used sometimes within a mutex acquired
block, sometimes not. Make it consistent by always using it with
acquired mutex.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-04-29 08:00:09 -04:00
Gerard Marull-Paretas
f163bdb280 power: move reboot functionality to os lib
Reboot functionality has nothing to do with PM, so move it out to the
subsys/os folder.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-04-28 20:34:00 -04:00
Robert Lubos
653c987762 net: lwm2m: Fix lwm2m_path_log_strdup buffer usage
Currently the lwm2m_path_log_strdup allocates a temporary buffer on a
stack, and then passes it to the log_strdup function to create a copy
of the string for the logger. log_strdup however will not copy the
string if for instance immediate logging is used, therefore the logging
function will still use the memory address of the already invalid buffer
allocated within lwm2m_path_log_strdup.

Fix this by passing an addittional `buf` parameter to the
lwm2m_path_log_strdup function, therefore allowing the user to provide
the buffer within a valid scope.

CID: 220536
Fixes #34005

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-04-28 19:30:09 +02:00
Chih Hung Yu
5cebdf5fd3 net: lib: sockets: Fix zsock_select
zsock_select() cannot poll file descriptors with number >= 32.

When a whole word in FD_SET was skipped due to being empty,
corresponding fd number was not updated, leading to wrong
fd's being passed to poll().

Fixes #34563

Signed-off-by: Chih Hung Yu <chyu313@gmail.com>
2021-04-28 20:01:31 +03:00
Gerard Marull-Paretas
3daf9f2d97 net: remove usage of device_pm_control_nop
If device PM is not implemented just use NULL.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-04-27 16:28:49 -04:00
Jukka Rissanen
bd03493fdc net: pkt: Have separate create time for net_pkt
This value is used to measure the RX/TX statistics. The previous
use of the timestamp field did not work in RX path as the timestamp
value could be overwritten by the driver if gPTP timestamping
is enabled. So to fix the RX statistics, use a separate field
for the create time.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-27 12:02:19 +03:00
Eduardo Montoya
8ff12f3ace net: openthread: enable CSL delayed transmissions
Add support for delayed transmission of frames for the CSL
Transmitter OpenThread function.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-04-26 13:40:43 +02:00
Jukka Rissanen
9f2fa87e05 net: Remove support for CONFIG_NET_CONTEXT_TIMESTAMP option
This option was only able to collect statistics of transmitted
data. The same functionality is available if one sets the
CONFIG_NET_PKT_RXTIME_STATS and/or CONFIG_NET_PKT_TXTIME_STATS
options.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-26 10:46:43 +03:00
Jukka Rissanen
a7f1c2821a net: sockets: RX statistics were not properly compiled in
The RX statistics might not get updated properly because the used
ifdef was referring the TX options.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-26 10:46:43 +03:00
Marcin Niestroj
d98911d712 net: dns: add 10ms delay when rescheduling query timeout handler
Query timeout handler is rescheduled if DNS context mutex is locked. So
far there was no timeout used, which means that work is simply put at
the end of system workqueue. This solves cases when mutex is locked by
any higher priority cooperative threads.

If however mutex was locked in application code within lower priority
thread (which is very likely) and query timeout has expired in the
meantime, then system workqueue is busy looping by calling query timeout
handler and trying to acquire DNS context lock.

Reschedule query timeout handler with 10ms delay, so that all
threads, including those with lower priorities, have a chance to move
forward and release DNS context lock.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-04-23 15:05:41 -05:00
Maik Vermeulen
ae4c5193a3 net: coap: coap_find_options() now returns 0 when options empty
coap_find_options() now first checks if there is actual payload
to parse.

Fixes #34463.

Signed-off-by: Maik Vermeulen <maik.vermeulen@innotractor.com>
2021-04-22 19:34:11 +03:00
Paul Sokolovsky
01014a2c05 net: sntp: Depend on NET_SOCKETS_POSIX_NAMES || POSIX_API
This library is coded with standard POSIX names for socket functions,
so make that requirement explicit.

Also, switch it from select'ing NET_SOCKETS, to depend'ing on it. This
follows the general approach of avoiding unneeded select's in Zephyr,
which lead to conflicting dependencies and make debugging dependencies
complex overall. In this particular case, it's fair (for a user) to
expect that "simple network time protocol" requires networking API,
namely sockets, and have that explicitly on in their app configuration,
giving better overview of their app config overall.

Fixes: #34165

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2021-04-22 13:41:33 +03:00
Krzysztof Chruscinski
320f7c3808 net: lib: openthread: logging: Refactor logging function
Refactor logging function to avoid multiple macro calls.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-04-19 10:59:23 -04:00
Maik Vermeulen
4d85426688 net: lwm2m: Made pmin and pmax attributes optional
Made the LwM2M engine checks for pmin and pmax optional to adhere to
the LwM2M specificattion. We now first check that pmin and pmax are
actually set. Also changed the default CONFIG values for the attributes
pmin and pmax to 0 to indicate that they are not active by default.

Fixes #34329.

Signed-off-by: Maik Vermeulen <maik.vermeulen@innotractor.com>
2021-04-16 15:32:04 -04:00
Jukka Rissanen
dde03c6770 net: socket: Add locking to prevent concurrent access
The BSD API calls were not thread safe. Add locking to fix this.

Fixes #27032

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-15 07:16:51 -05:00
Robert Lubos
19e7451c34 net: lwm2m: Fix unitialized variable error in Link Format writer
The `init_string` array could have been used uninitialized, fix this
by initializing it as an empty string, which is a desired content in
case it's not overwritten.

CID: 220302
Fixes #33839

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-04-14 14:36:35 -05:00
Justin Morton
35f598ba93 net: http: add numeric http status code to response struct
Add numeric http status code to the response struct to allow for
easier processing by the caller.   Textual status already exists.

Signed-off-by: Justin Morton <justin.morton@nordicsemi.no>
2021-04-14 18:46:47 +03:00
Eduardo Montoya
4289e46ae7 net: openthread: switch radio off when stopping diags
This commit puts the radio in sleep mode when the diagnostics are
stopped.

This fixes an assert on MAC code when `ot diag stop` command is
issued while `ot diag send` is still ongoing.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-04-14 17:38:27 +03:00
Peter Bigot
188cb2cb7c net: Conversion of k_work API
Replace all existing deprecated API with the recommended alternative.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-14 07:07:40 -04:00
Paul Sokolovsky
471afe5ddc net: sockets: Make NET_SOCKETS_POSIX_NAMES be on by default
Zephyr socket subsystem has come a long way since initial experimental
alternative to internal Zephyr networking API. Its configuration also
mirrors the usual conservative approach, where a user needs to
explicitly enable options to get "more" features. And as an
experimental API, socket subsystem was initially developed as
namespaced API, where all functions/structures are prefixed with
"zsock_", and to get standard names, CONFIG_NET_SOCKETS_POSIX_NAMES
needs to be set (or alternatively, CONFIG_POSIX_API needs to be, which
enabled full POSIX subsys overall).

However, a few years later, sockets are the standard networking API,
and in majority of cases its used under the standard POSIX names.
Necessity to explicitly set an option to achieve this effects, and
confusion which results from it - are just unneeded chores for users.

So, switch CONFIG_NET_SOCKETS_POSIX_NAMES to be on by default (unless
CONFIG_POSIX_API is already defined). It still can be explicitly
disabled if needed (but usecases for that would be peculiar and rare).

Addresses #34165

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2021-04-13 13:00:53 -04:00
Eduardo Montoya
1d668d4b7c net: openthread: add microseconds timer API
Add OpenThread API to handle microseconds timer, to be used initially
by CSL receiver.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-04-12 17:01:14 +03:00
Jukka Rissanen
e917d80473 net: capture: Add support for network packet capturing
Add infrastructure to allow user to configure the system so that
all the network packets, that are sent to or received from a specific
network interface, are sent to remote system for analysis.
The captured network packets are placed as a payload in UDP packet,
which is then sent inside a tunnel to a remote host. The host can
then receive the packets and for example show them in wireshark.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-02 07:24:06 -04:00
Robert Lubos
814fb71bf3 net: socket: Implement SO_BINDTODEVICE socket option
Implement SO_BINDTODEVICE socket option which allows to bind an open
socket to a particular network interface. Once bound, the socket will
only send and receive packets through that interface.

For the TX path, simply avoid overwriting the interface pointer by
net_context_bind() in case it's already bound to an interface with an
option. For the RX path, drop the packet in case the connection handler
detects that the net_context associated with that connection is bound to
a different interface that the packet origin interface.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-04-02 07:23:17 -04:00
Emil Lindqvist
3115610558 net: socket: dtls: add sockopt to set & get dtls handshake timeout
An option has been added which can be passed to setsockopt
which allows the user to set & get the dtls handshake timeout,
either before first handshake or online.

Signed-off-by: Emil Lindqvist <emil@lindq.gr>
2021-04-01 20:02:59 +03:00
Jani Hirsimäki
bd40cb48d9 net: socket: packet: using pckt sckt for passing the PPP dialup data
With these changes, dial up Zephyr application/driver can use
socket(AF_PACKET, SOCK_RAW, IPPROTO_RAW) for creating
a socket for sending/receiving data to/from ppp net link, i.e.
packet is going to/from PPP L2.

Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>
2021-04-01 09:43:56 +03:00
Benjamin Lindqvist
e3f8757b70 net: lwm2m: Allow cancel-observe to match path
The specification states that the server can cancel observations "at any
moment, by sendinga GET request with Observe option=1, the LwM2M Server
cancancel an “Observe”operation on a specified Resource, or specified
Object Instance(s)."

It does not mention any token matching requirement, but RFC 7641 does.
The correct interpretation is not obvious. The EMQx LwM2M implementation
uses a new token for instance, which does not work with Zephyrs token
matching cancel-observe.

This commit introduces cancel-observe via path matching as a Kconfig
option. This could hypothetically introduce problems when we are
connected to multiple peers simultaneously, but since that is not likely
to be supported for a long time (if ever), this change should be fairly
uncontroversial since path matching is only used as a fallback.

Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
2021-04-01 09:42:56 +03:00
Robert Lubos
bed1dc26f1 net: sockets: tls: Fix poll() handling during the handshake
Current implementation of poll prepare/update could end up busy looping
if `poll()` function was called before/during DTLS client handshake
(i. e. `poll()` called before an initial `send()`).

Fix this, by monitoring the handshake semaphore, already available in
the tls_context structure for DTLS client instead of underlying socket.
After the handshake is complete, switch to monitoring the underlying
socket instead.

For DTLS server this is not needed, since the handshake is initiated in
the `recv()` function, therefore any incoming data should trigger the
handshake.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-31 08:06:30 -04:00
Robert Lubos
539e4edcc6 net: lwm2m: Remove obsolete LWM2M_IPSO_TIMESTAMP_EXTENSIONS option
All IPSO objects that utilized the non-standard timestamp extension now
implement their model in version 1.1, which contains the Timestamp
resource. As it's no longer needed to add timestamp in a non-standard
way, simply remove LWM2M_IPSO_TIMESTAMP_EXTENSIONS option.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-29 13:42:11 -04:00
Robert Lubos
1efc8e7353 net: lwm2m: Add IPSO Buzzer object in version 1.1
Update IPSO Buzzer object implementation to support object model
version 1.1.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-29 13:42:11 -04:00
Robert Lubos
885dd5ff1f net: lwm2m: Add IPSO Push Button object in version 1.1
Update IPSO Push Button object implementation to support object model
version 1.1.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-29 13:42:11 -04:00
Robert Lubos
8853730dec net: lwm2m: Add IPSO On/Off Switch object in version 1.1
Update IPSO On/Off Switch object implementation to support object model
version 1.1.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-29 13:42:11 -04:00
Robert Lubos
9b1f0e3da0 net: lwm2m: Add IPSO Accelerometer object in version 1.1
Update IPSO Accelerometer object implementation to support object model
version 1.1.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-29 13:42:11 -04:00
Robert Lubos
ca21c03e8c net: lwm2m: Add IPSO Pressure Sensor object in ver. 1.1
Update IPSO Pressure Sensor object implementation to support object
model version 1.1.

Add missing optional resources for the object model version 1.0.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-29 13:42:11 -04:00
Robert Lubos
7546c5bf29 net: lwm2m: Add IPSO Humidity Sensor object in ver. 1.1
Update IPSO Humidity Sensor object implementation to support object
model version 1.1.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-29 13:42:11 -04:00
Robert Lubos
1bd6e5bde3 net: lwm2m: Add IPSO Generic Sensor object in version 1.1
Update IPSO Generic Sensor object implementation to support object model
version 1.1.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-29 13:42:11 -04:00
Robert Lubos
c83fca2784 net: lwm2m: Add IPSO Temperature object in version 1.1
Update IPSO Temperature object implementation to support object model
version 1.1.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-29 13:42:11 -04:00
Robert Lubos
49b0e2cc76 net: lwm2m: Unify reusable resources creation
Some of the objects redefined reusable resources IDs, while others used
a common header which defines resource IDs. Unify the approach and use
the header in every object.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-29 13:42:11 -04:00
Robert Lubos
c9f5337a91 net: lwm2m: Add support for object versioning
Each object now have to specify the object version it implements.
Based on this information the LwM2M engine can decide whether it's
needed to report the object version during Registration/Discovery
operations or not.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-29 13:42:11 -04:00
Jukka Rissanen
362591810f net: config: Try to only use auto started interface
If the first network interface is down when the net config init
is run, then the IP addresses etc would be set to wrong network
interface. So when initializing the network, try to first find
a network interface that is auto started and use that to configure
IP addresses etc.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-03-29 07:40:24 -04:00
Flavio Ceolin
9fd4ea91b7 coccinelle: Remove extra semicolon
coccicheck --mode=patch --cocci=semicolon.cocci

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-03-25 11:35:30 -05:00
Robert Lubos
02a1168475 net: sockets: tls: Implement MSG_TRUNC flag
Add implementation of MSG_TRUNC `recv()` flag for DTLS sockets.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-23 13:16:30 +02:00
Robert Lubos
833517f994 net: sockets: Implement MSG_TRUNC flag
Add implementation of MSG_TRUNC `recv()` flag for UDP sockets.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-23 13:16:30 +02:00
Anas Nashif
5d6c219210 drivers: device: do not reuse tag name 'device'
Do not reuse tag name (misra rule 5.7).

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-03-22 19:48:14 -04:00
Anas Nashif
a518f48796 clock: renmae z_timeout_end_calc -> sys_clock_timeout_end_calc
Do not use z_ for internal APIs, z_ is for private APIs within one
subsystem only.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-03-19 11:22:17 -04:00
Anas Nashif
fe0872c0ab clocks: rename z_tick_get -> sys_clock_tick_get
Do not use z_ for internal APIs, z_ is for private APIs within one
subsystem only.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-03-19 11:22:17 -04:00
Robert Lubos
c50c0f6d07 net: lwm2m: Use link_format writer for Register/Update
The payload of the Register/Register Update message is also formatted as
application/link-format. Therefore it's reasonable to reuse the new
content writer instead of filling the payload manually.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-18 10:18:57 +01:00
Robert Lubos
b17555eb9e net: lwm2m: Add application/link-format content writer
This commit adds a new content writer, application/link-format, which
can be used during the Discovery procedure, to fill the content of the
response payload.

Introducing this new content writer, which encapsulates some of the
details like attribute handling which is different for bootstrap/regular
discovery, allows to unify the discovery handler in the lwm2m_engine,
thus it's no longer needed to have spearate handler functions for
bootstrap/regular discovery.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-18 10:18:57 +01:00
Robert Lubos
6ba362b11b net: lwm2m: Remove .well-known/core handling
`.well-known/core` resource is described by the CoAP RFC as an optional
method of resource discovery. The LwM2M specification though makes no
mentionon about this mechanism and provides an alternative method of
resource discovery instead (Device Management Discover, sec 5.4.2, and
Bootstrap Discovery, sec 5.2.7.3).

Since LwM2M does not require to implement `.well-known/core` resource
and it complicates the existing Discovery mechanism (and likely cause a
security concern) remove its handling from the LwM2M implementation.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-18 10:18:57 +01:00
Robert Lubos
d53fb5700d net: lwm2m: Introduce attribute handling helper functions
Introduce LwM2M engine helper functions that allows to work with LwM2M
attributes outside of lwm2m_engine.c.

This is a groundwork for application/lwm2m-format content writer.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-18 10:18:57 +01:00
Marcin Niestroj
9f12dbba5d net: sockets: improve DGRAM recvfrom() on NET_OFFLOAD iface
When recvfrom() was called with src_addr != NULL, then source address
was fetched from beginning of net_pkt. This works with native IP stack
obviously. However with offloaded IP stack there is no IP header, so
trying to parse missing IP header results in undefined behavior.

Check if network interface has offloaded IP stack. If positive, then
figure out if there is assigned remote address to network context on
which packet was received. Return this remote address, which SHOULD be
the source address of received packet. Otherwise, return an error.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2021-03-17 20:00:42 +02:00
Peter Bigot
1c7bf96019 net: dns: update to new k_work API
Switch to the new API for delayed work related to DNS queries.

In the previous solution it was assumed that the work item could be
immediately cancelled at the point the query slot was released.  This
is not true.  We need a secondary condition to record the fact that
the query was completed while the work item was still pending, and an
additional check to detect when the work item completed and the slot
reclaimed.

Also annotate functions to indicate when they require the lock on
query content to be held, add some helpers that abstract core
operations like invoking a callback or releasing a query slot, and fix
some more cases where query slot content was accessed outside of the
new lock infrastructure.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-03-15 17:19:54 +02:00
Jukka Rissanen
ee2e3dd9fc net: sockets: Provide close method for packet sockets
There was no close method implemented for AF_PACKET type
sockets. This meant that calling close() on packet socket
caused NULL pointer access.

This will allow #32949 issue to work properly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-03-15 15:17:52 +02:00
Lukasz Maciejonczyk
1b7755e62a net: openthread: Fix otPlatUartSend
Make sure data for transmission do not overlap each other.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2021-03-15 13:46:36 +02:00
Lukasz Maciejonczyk
4acaae1b1b net: openthread: Fix UART platform callback
OpenThread UART tx callback has been processed even if it was not
triggered by OpenThread otPlatUartSend function.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2021-03-15 13:46:36 +02:00
Robert Lubos
a670c84530 net: sockets: tls: Implement MSG_WAITALL flag
Add MSG_WAITALL flag implmentation for secure sockets.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-12 13:57:11 -05:00
Robert Lubos
d47e803976 net: sockets: Implement MSG_WAITALL recv flag
Implement MSG_WAITALL flag for stream sockets. Setting this flag on
`recv()` call will make it wait until the requested amount of data is
received.

In case both, MSG_WAITALL all is set and SO_RCVTIMEO option configured
on a socket, follow the Linux behavior, i. e. when the requested amount
of data is not received until the timeout expires, return the data
received so far w/o an error.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-12 13:57:11 -05:00
Jukka Rissanen
8353225ce0 net: dns: Add locking to prevent concurrent access
Add mutex locks to avoid concurrent access to DNS context.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-03-12 11:26:16 -05:00
Krzysztof Chruscinski
7e125fe7e4 logging: Add backend parameter to the init function
Added backend parameter to the backend init interface function.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-03-12 09:24:54 -05:00
Robert Lubos
6a90baa21a net: lwm2m: Make validation cb support optional
Add option to disable validation callback support by setting the
validation buffer size to 0, which allows to save some memory in case
it's not needed.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-10 14:55:22 -05:00
Robert Lubos
31e5ec79b8 net: lwm2m: Add data validation callback
Add a data validation callback to the resource structure, which can be
registered by an application. It allows to verify the data before
actually modifying the resource data.

If the callback is registered for a resource, the data is decoded into a
temporary buffer first, and only copied into the actual resource buffer
if the validation is successfull. If no validation is required (and thus
no callback registered) the resource value is decoded directly into the
resource buffer, as it used to be.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-10 14:55:22 -05:00
Robert Lubos
64c836d5e2 net: lwm2m: Check return value of option encoding on deregistration
Verify the result of option encoding while forming Deregister message
instead of silently ignoring it.

Coverity ID: 215373
Fixes #33096

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-09 09:23:48 -05:00
James Harris
6fd147b612 net: config: ensure counter k_sem init'd before reset
check_interface resets the counter semaphore, but
net_config_init_by_iface first calls check_interface, then inits
the semaphore.

Initialize the semaphore up front to allow the k_sem_reset call
to work properly.

Signed-off-by: James Harris <james.harris@intel.com>
2021-03-06 07:39:43 -05:00
James Harris
b10428163a kernel: sem: add K_SEM_MAX_LIMIT
Currently there is no way to distinguish between a caller
explicitly asking for a semaphore with a limit that
happens to be `UINT_MAX` and a semaphore that just
has a limit "as large as possible".

Add `K_SEM_MAX_LIMIT`, currently defined to `UINT_MAX`, and akin
to `K_FOREVER` versus just passing some very large wait time.

In addition, the `k_sem_*` APIs were type-confused, where
the internal data structure was `uint32_t`, but the APIs took
and returned `unsigned int`. This changes the underlying data
structure to also use `unsigned int`, as changing the APIs
would be a (potentially) breaking change.

These changes are backwards-compatible, but it is strongly suggested
to take a quick scan for `k_sem_init` and `K_SEM_DEFINE` calls with
`UINT_MAX` (or `UINT32_MAX`) and replace them with `K_SEM_MAX_LIMIT`
where appropriate.

Signed-off-by: James Harris <james.harris@intel.com>
2021-03-05 08:13:53 -06:00
Pete Skeggs
e0de4ff227 net: mqtt: log struct mqtt_utf8 with hexdump
Add NET_HEXDUMP_DBG/ERR/WARN/INFO macros, then use them for new
MQTT_HEXDUMP_TRC/ERR/WARN/INFO macros.

Log struct mqtt_utf8 using MQTT_HEXDUMP_TRC. One cannot safely log
mqtt_utf8 strings due to no guarantee of a NULL terminator being
present.  Also, logging without log_strdup() as if it were a NULL
terminated string asserts when CONFIG_LOG_IMMEDIATE=n. This solves
both issues.

Signed-off-by: Pete Skeggs <peter.skeggs@nordicsemi.no>
2021-03-05 12:49:22 +02:00
Peter Bigot
7b8bce898f net: openthread: radio: switch to new API for k_work_pending
Uses of k_work_pending are to be replaced by k_work_is_pending which
conforms to current proposed naming guidelines.

Switch to the new function.

Also initialize the private work structure at build time, rather than
on each iteration (it is not permitted to invoke work API on an
uninitialized work item).

The implementation here is racy: that a work item is pending does not
mean changes since it was first submitted are guaranteed to be seen
when the work item begins (began) executing.

A better solution would be to have transmit_message be able to
determine whether there is unprocessed work.  Then the work item can
be submitted unconditionally.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-03-04 18:00:56 -05:00