Commit graph

5628 commits

Author SHA1 Message Date
Noah Luskey 8e4c70750a net: don't overwrite net_if name after iface is initialized
When interface names are enabled, a default name is applied
after initialization. Unintuitively, this overwrites any name that is
set during the net_if init.

This change sets a default name first, and then allows net_if
init to overwrite that default name if it chooses to.

Signed-off-by: Noah Luskey <noah@silvertree.io>
Signed-off-by: Noah Luskey <LuskeyNoah@gmail.com>
2023-12-04 14:18:53 +01:00
Kapil Bhatt cb7b650b92 net: l2: wifi: Fix Print of SSID in WIFI status
While printing SSID in wifi status command, If the
length is maximum(32 character). It leads to buffer
overflow. It required one character for null
terminator ‘\0’. Changing the Format Specifiers to
print proper SSID.

Signed-off-by: Kapil Bhatt <kapil.bhatt@nordicsemi.no>
2023-12-01 11:03:43 +00:00
Mario Paja 6b644dff67 net: gptp: Fix announce message len
This fix addresses wrong announce message length warning message.

TLV is a variable length (4+8N) based on the 802.1AS-2011 (table 10-8). In
Zephyr TLV is fixed to 12 bytes. TLV type and length are already taken
into account in the announcement message length.

Signed-off-by: Mario Paja <mario.paja@zal.aero>
2023-12-01 11:02:57 +00:00
Chaitanya Tata eb9587596b wifi: Check WPA-PSK passphrase length
When WPA-PSK was introduced the passphrase length check was missed.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-12-01 10:57:06 +00:00
Pieter De Gendt 266181b082 net: lib: coap: Add coap_service_is_running
Add a CoAP service API function to query the running state of the
provided service.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-12-01 10:56:56 +00:00
Pieter De Gendt 4ff8080b65 net: lib: coap: Init CoAP service socket fd to -1
Set the static initialiser socket file descriptor to -1 to make sure
it is invalid before using coap_service_send.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-12-01 10:56:56 +00:00
Jukka Rissanen 5d915398a4 net: sockets: Add additional checks to recvmsg()
Add extra checks that make sure that msg_iov is set
as we cannot receive anything if receive buffers are
not set.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-12-01 10:56:34 +00:00
Robert Lubos 222fa42609 net: icmp: Fix Echo Replies with unspecified address
Fix two issues with sending ICMP Echo Reply for requests sent for
multicast address:
* Use the originator IP address instead of multicast when selecting
  source address for the reply
* In case no address match is found, drop the packet, instead of
  replying with unspecified address.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-30 10:07:45 +01:00
Pieter De Gendt 8252ec7570 net: lib: coap: Translate handler errors to CoAP response codes
The CoAP request handler returns errno codes in the following cases:
* ENOENT if no handler found; respond with 4.04
* ENOTSUP if an unknown request code received; respond with 4.00
* EPERM no handler found for the method; respond with 4.05

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-11-30 10:07:32 +01:00
Robert Lubos 37d39425ee net: tcp: Fix possible race between TCP work items and context unref
Fix the possible race between TCP work items already scheduled for
execution, and tcp_conn_unref(), by moving the actual TCP context
releasing to the workqueue itself. That way we can be certain, that when
the work items are cancelled, they won't execute. It could be the case,
that the work item was already being processed by the work queue, so
clearing the context could lead to a crash.

Remove the comments around the mutex lock in the work handlers regarding
the race, as it's not the case anymore. I've kept the locks however, as
they do make sense in those places.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-30 10:06:50 +01:00
Jukka Rissanen 1f1712a89f net: context: Add ARG_UNUSED to relevant places in opt handling
If some specific option is not enabled, then add missing
ARG_UNUSED() calls in relevant functions.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-11-30 10:05:06 +01:00
Jukka Rissanen 77e522a5a2 net: context: Refactor option setters
Set separate option setters for bool, uint8_t and uint16_t
values. Use those generic setters when storing the desired
option value.

The uint16_t option setter stores the value to uint16_t variable
and expects that user supplies int value.

For uint8_t value, it is expected that uint8_t value is supplied
instead of int.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-11-30 10:05:06 +01:00
Jukka Rissanen 55958d851f net: context: Refactor option getters
Set separate option getters for bool, uint8_t and uint16_t
values. Use those generic getters when fetching the desired
option value.

Noticed mixed usage (bool vs int) for txtime option. Changed
the code to use int type like in other options.

The uint16_t option getter gets the value from uint16_t variable
but returns int value to the caller, and also expects that user
supplies int value.

For uint8_t value, it is expected that uint8_t value is supplied
instead of int.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-11-30 10:05:06 +01:00
Konrad Derda 3c39f7efd9 net: hostname: trigger an event when the hostname changes
This commit introduces new network event that is triggered on every
change of the hostname.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2023-11-29 13:16:16 -06:00
Lukasz Majewski 25addd0984 net: ethernet: Add support for setting T1S PLCA parameters
The Zephyr's core ethernet code had to be adjusted to support setting T1S
PLCA parameters from user Zephyr programs.

Such approach allows more flexibility, as T1S network configuration;
especially PLCA node numbers, can be assigned not only via device tree
at compile time. For example user can read them from EEPROM and then
configure the network accordingly.

For now - the union in struct ethernet_t1s_param only consists of plca
structure. This can change in the future, when other T1S OA parameters -
like Receive/Transmit Cut-Through Enable (bits RXCTE/TXCTE in OA_CONFIG0
register) are made adjustable from user program.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
2023-11-29 10:06:30 +01:00
Robert Lubos afd2e9561c net: tls_credentials: Add missing include dir for PSA API
Protected credential storage makes use of the PSA API, therefore it must
be present in the library include path. This was missed during the
recent CMakeLists.txt rework of this library.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-28 15:35:00 +01:00
Pieter De Gendt 473cc03c38 net: ip: icmp: Cleanup packet on failed priority check
A network memory leak would occur if the priority check fails.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-11-27 19:59:26 +01:00
Maciej Baczmanski c2f1ff7f5f net: openthread: upmerge to 75694d2
Regular OpenThread upmerge to commit `75694d2`.

Move CONFIG_OPENTHREAD_PLATFORM_KEY_REFERENCES_ENABLE
from header file to Kconfig.

Signed-off-by: Maciej Baczmanski <maciej.baczmanski@nordicsemi.no>
2023-11-27 19:59:04 +01:00
Jukka Rissanen 1961adfb96 net: socket: Return ENOTSUP for unknown socket type in recvfrom()
If we for some reason are supplied unsupported socket type in
recvfrom(), then return ENOTSUP error to the caller instead of
silently accept it by returning 0.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-11-27 19:58:47 +01:00
Jukka Rissanen 5488e76bb2 net: socket: Add support for filling receive pktinfo data
If user has set either IP_PKTINFO (for IPv4) or
IPV6_RECVPKTINFO (for IPv6) socket options, then the system
will return relevant information in recvmsg() ancillary data.

Fixes #36415

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-11-27 19:58:47 +01:00
Jukka Rissanen 80704bb361 net: socket: Add support for setting pktinfo options
Add IP_PKTINFO or IPV6_RECVPKTINFO BSD socket options that
can be used to get extra information of received data in
the ancillary data in recvmsg() call.

For IPV6_RECVPKTINFO see RFC 3542 for details.
For IP_PKTINFO see Linux ip(7) manual page for details.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-11-27 19:58:47 +01:00
Jukka Rissanen c3acd56e27 net: context: Add support for setting receive pktinfo option
Add low level support for setting IP_PKTINFO or IPV6_RECVPKTINFO
socket options. The support is disabled by default.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-11-27 19:58:47 +01:00
Jukka Rissanen 760c2f2949 net: sockets: Remove extra check from sendmsg()
There was double "if (status < 0)" check in sendmsg(),
remove the extra check.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-11-27 19:58:47 +01:00
Jukka Rissanen 4b365fab45 net: sockets: Add recvmsg() implementation
Add support for recvmsg() function which can return data
in msghdr struct (iovec).

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-11-27 19:58:47 +01:00
Alexander Vasiliev 76276e2bd3 net: mqtt-sn: Remember incoming registered topic name
When a client uses wildcard subscription and a new message is
published to the matching topic for the first time, the gateway
sends REGISTER message to the client, containing the exact
topic name and a new topic ID.
This change fixes adding these topic ID and name to the internal
topics list.

Signed-off-by: Alexander Vasiliev <alexander.vasiliev@siemens.com>
2023-11-22 09:53:33 +01:00
Alexander Vasiliev 6caf76346a net: mqtt-sn: Add a function to get topic name by topic ID
Add a function to MQTT-SN library API to get topic name by ID
from the internal topics list.

Signed-off-by: Alexander Vasiliev <alexander.vasiliev@siemens.com>
2023-11-22 09:53:33 +01:00
Ibe Van de Veire 1d0f47b005 net: ip: igmp: add igmpv3 support
Added igmpv3 support based on the already existing structure for igmpv2.
The already existing api is not modified to prevent breaking exisiting
applications.

Signed-off-by: Ibe Van de Veire <ibe.vandeveire@basalte.be>
2023-11-21 15:50:31 +01:00
Ibe Van de Veire ca7ce90dc7 net: ip: utils: changed input arguments of igmp_checksum to net_pkt
Added igmpv3 checksum function to make it possible to calculate the
checksum of a complete igmpv3 pkt at once.

Signed-off-by: Ibe Van de Veire <ibe.vandeveire@basalte.be>
2023-11-21 15:50:31 +01:00
Declan Snyder cf42b8b2fb net: sockets: fix shadowing warning
Fix compiler local variable shadowing warning

Rename ret to bytes_sent in offending funciton

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2023-11-21 08:48:04 +00:00
Declan Snyder 7c72d4a2d6 net: Fix CMakeLists
Fix the CMakeLists of the tls_credentials and sockets folders
to link/interface to the net library instead of the zephyr library.
This fixes issues where some files are not found in the link interface
when compiling the sources in this folder.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2023-11-21 08:48:04 +00:00
Robert Lubos aa6f698d31 net: zperf: Fix TCP packet counting
Make sure we send the entire packet buffer before bumping the packet
counter, send() does not guarantee that all of the requested data will
be sent at once with STREAM socket.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-21 08:46:45 +00:00
Robert Lubos e6d90b409b net: sockets: tls: Set errno on TX waiting error
In case underlying socket reported error while waiting for TX, the
errno value was not set accordingly. This commit fixes this.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-21 08:46:45 +00:00
Robert Lubos 3a38ec1aaa net: tcp: Feed TX semaphore on connection close
Otherwise, if the application was for example blocked on poll() pending
POLLOUT, it won't be notified.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-21 08:46:45 +00:00
Robert Lubos 9976ebb24b net: tcp: Rework data queueing API
Rework how data is queued for the TCP connections:
  * net_context no longer allocates net_pkt for TCP connections. This
    was not only inefficient (net_context has no knowledge of the TX
    window size), but also error-prone in certain configuration (for
    example when IP fragmentation was enabled, net_context may attempt
    to allocate enormous packet, instead of let the data be fragmented
    for the TCP stream.
  * Instead, implement already defined `net_tcp_queue()` API, which
    takes raw buffer and length. This allows to take TX window into
    account and also better manage the allocated net_buf's (like for
    example avoid allocation if there's still room in the buffer). In
    result, the TCP stack will not only no longer exceed the TX window,
    but also prevent empty gaps in allocated net_buf's, which should
    lead to less out-of-mem issues with the stack.
  * As net_pkt-based `net_tcp_queue_data()` is no longer in use, it was
    removed.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-21 08:46:45 +00:00
Robert Lubos 16fd744c13 net: pkt: Add function for allocating buffers w/o preconditions
Add new function to allocate additional buffers for net_pkt, w/o any
additional preconditions/checks. Just allocate what was requested.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-21 08:46:45 +00:00
Henning Fleddermann 8e4c588eab net: lib: lwm2m: Use int16_t for signal quality
RSRQ is the ratio between send and received signal strength and usually
understood/expected to be represented as a ratio in dB and as such always
has a negative range. So to allow RSRQ to be represented correctly the
resource must allow negative values, but currently it's limited to unsigned
8bit integers.

Signed-off-by: Henning Fleddermann <henning.fleddermann@grandcentrix.net>
2023-11-20 13:01:23 +01:00
Robert Lubos 8a75a4b9db net: shell: Fix array indexing with dynamic iface command
Network interface numbering starts from 1, therefore when accessing
help/index array, the interface index should not be used directly, but
rather decremented by 1, to avoid out-of-bound access on those arrays.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-20 09:24:47 +01:00
Robert Lubos f0247131bf net: tftp: Ensure the error message fits into transmit buffer
Make sure that the error message does not overflow the transmit buffer
when copying the error message string.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-20 09:24:18 +01:00
Robert Lubos 59544d58ef net: tftp: Verify connect return value
Verify that connect() succeeded before reporting success.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-20 09:24:18 +01:00
Robert Lubos 69e6b3a563 net: tftp: Log transmit error
There's not really much to do when the transmission of the error reply
fails, but we can at least log the failure.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-20 09:24:18 +01:00
Robert Lubos a3362d969d net: lwm2m: Explicitly initialize path_list_size variable
To get rid of compiler warning about potential use of uninitialized
variable.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-20 09:24:11 +01:00
Robert Lubos 7f7d019b25 net: lwm2m: Add error checks for option encoding in BS registration
Add missing error checks when encoding CoAP options for Bootstrap
Register message

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-20 09:24:11 +01:00
Robert Lubos ec50e5393c net: lwm2m: shell: Add error check for string to float conversion
The result of string to float conversion in LwM2M shell write command
was not verified, which could result in incorrect data being written to
the resource.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-20 09:24:11 +01:00
Robert Lubos e702ecc8fb net: dhcpv6: Verify net_pkt_skip() return value
Verify the return value of net_pkt_skip() function, in case the parser
ignores the unrecognized options, so that in case the option was
malformed and the actual provided option length exceeds the packet
length, it is recognize (net_pkt_skip() should fail then).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-20 09:23:22 +01:00
Benjamin Cabé 79c677c0ef net: lib: coap: Fix NULL pointer dereference
As reported by Coverity, cpkt was being used before checking it's not
NULL.
Fixes #65372 / CID: 323075

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2023-11-20 09:23:12 +01:00
Henrik Brix Andersen c0c8952739 shell: do not enable subsystem/driver shell modules by default
Do not enable subsystem/driver shell modules by default and stop abusing
CONFIG_SHELL_MINIMAL, which is internal to the shell subsystem, to decide
when to enable a driver shell.

The list of shell modules has grown considerably through the
years. Enabling CONFIG_SHELL for doing e.g. an interactive debug session
leads to a large number of shell modules also being enabled unless
explicitly disabled, which again leads to non-negligible increases in
RAM/ROM usage.

This commit attempts to establish a policy of subsystem/driver shell
modules being disabled by default, requiring the user/application to
explicitly enable only those needed.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-11-20 09:21:40 +01:00
Benjamin Lindqvist 1d6d24b6ef net: lwm2m: don't load credentials on plaintext context
Since lwm2m_load_tls_credentials(ctx) will assume that the ctx has a
valid security object assigned to it, it should not be called at all
when ctx.use_dtls == false.

This solves a major bug where LwM2M comms are DTLS encrypted but FOTA is
allowed to be plain-text.

Signed-off-by: Benjamin Lindqvist <benjamin@eub.se>
2023-11-20 09:20:43 +01:00
Jukka Rissanen 5209666539 net: mdns: Fix compile error when using clang
No issues with gcc but clang gives this error for
the *v4 variable few lines below.

.../lib/dns/mdns_responder.c:712:2: error: expected expression
        struct net_context *v4;

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-11-17 12:40:33 +01:00
Jukka Rissanen 5049a049db net: mdns: Create a listener to all available network interfaces
Instead of just listening first network interface in the system,
install a multicast listener to all available network interfaces.

Fixes #18748

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-11-17 12:40:33 +01:00
Jukka Rissanen dd2a222086 net: if: Add helper to calculate number of interfaces
Add a helper macro that can be used at runtime to return
the number of network interfaces in the system.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-11-17 12:40:33 +01:00
Jukka Rissanen 3f891ced3a net: conn: Check also network interface for duplicates
When verifying if there are duplicate connections, check
also network interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-11-17 12:40:33 +01:00
Jukka Rissanen 8157b48734 net: context: Add function to bound to a network interface
Helper function that marks the net_context to bound to a
network interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-11-17 12:40:33 +01:00
Jukka Rissanen 31ee2e678d net: context: Allow binding to different interfaces
Allow user to bind to different network interface. This is
useful if binding a multicast address to a certain network
interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-11-17 12:40:33 +01:00
Seppo Takalo 8cfede8f2e net: lwm2m: Support DTLS Connection Identifier
DTLS Connection Identifier support requires DTLS stack
that supports it. MbedTLS support in Zephyr is already
ported in, also some offloaded sockets support it.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-11-17 09:23:29 +01:00
Tomasz Moń b5f4d8374a net: buf: Preserve buffer pointer in destroy callback
The use case is to have a netbuf pool that is used exclusively with
net_buf_alloc_with_data() where the destroy callback takes care of
freeing the actual data buffer pointed to by __buf.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2023-11-15 10:02:55 +01:00
Georges Oates_Larsen 9f093ab731 net: tls_credetials: Add TLS Credentials shell
Adds a shell interface for TLS Credentials, allowing management of
credentials via the Zephyr shell

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-11-14 10:40:02 +00:00
Georges Oates_Larsen f5d12102a0 net: tls_credentials: sectag iterators
Add (internal) support for sectag iterating.

Also officially marks negative sectag values as reserved for internal
use.

This will allow a prospective TLS credentials shell to iterate over all
available credentials.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-11-14 10:40:02 +00:00
Georges Oates_Larsen 16bd8a82a6 net: tls_credentials: credential_digest
Adds an internal credential_digest for generating a string digest of
credentials.

Such digests would allow users of a prospective TLS credentials shell to
verify the contents of a given credential without directly accessing
those contents.

Offloading the digest process to the underlying backend allows backends
for which private portions are not directly accessible to be eventually
supported.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-11-14 10:40:02 +00:00
Pieter De Gendt 655c72c52e net: lib: coap: coap_server: Allow clients to refresh observe requests
A CoAP client can re-issue an observe request (same endpoint and token)
to refresh it's subscription. No new observer should be registered in
this case.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-11-13 09:50:19 +01:00
Pieter De Gendt cbf9680f96 net: lib: coap: Add coap_find_observer
Add a function to the public CoAP API to find and return the unique
observer based on the address and token.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-11-13 09:50:19 +01:00
Robert Lubos 61c392c5b1 net: iface: Introduce TX mutex locking
A recent iface lock removal in ed17320c3d
exposed issues with concurrent access on TX to drivers that are not
re-entrant.

Reverting that commit does not really solve the problem, as it would
still exist if multiple Traffic Class queues are in use.

Therefore, introduce a separate mutex for TX data path, protecting the
L2/driver from concurrent transfers from several threads.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-13 09:49:57 +01:00
Robert Lubos 8aba7740b8 net: lwm2m: Fix core objects version reporting
Core objects version reporting was broken for LwM2M version 1.1, as the
default object version not necessarily matches the LwM2M version.
Therefore, implement a table with default object versions for particular
LwM2M version, which can be looked up when determining whether it's
needed to include object version or not during Registration/Discovery.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-13 09:46:06 +01:00
Pieter De Gendt e8e6d23270 net: lib: coap: Add CoAP server shell
Add shell commands that allow to start/stop CoAP services.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-11-09 11:21:42 +01:00
Pieter De Gendt ae6e0106e7 net: lib: coap: Add service support
Add CoAP services and server as a subsystem implementation.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-11-09 11:21:42 +01:00
Pieter De Gendt 5227f24815 net: lib: coap: Add support for observer event callbacks
This commit adds the option to register an event handler to CoAP
resources when observers are added/removed.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-11-09 11:21:42 +01:00
Pieter De Gendt 291743b686 net: lib: coap: coap_remove_observer result type
Change coap_remove_observer to return the result of removing the
observer if found.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-11-09 11:21:42 +01:00
Pieter De Gendt fac670e1e2 net: lib: coap: Add coap_find_observer_by_token
Add a CoAP helper function to find a matching observer by token.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-11-09 11:21:42 +01:00
Pieter De Gendt cc89338888 net: lib: coap: Add coap_packet_is_request
Add function to check if CoAP packet is a request to the public API.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-11-09 11:21:42 +01:00
Pieter De Gendt 0a4668a2f7 net: lib: coap: Add coap_uri_path_match
Add URI path matching function to public CoAP API.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-11-09 11:21:42 +01:00
Pieter De Gendt bea29cf631 net: lib: coap: Add resources length based variants
Add length variant for the well known core resource and parsing.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-11-09 11:21:42 +01:00
Chaitanya Tata ed17320c3d net: Remove unnecessary lock
The main action in this function it queueing the packet for
transmission which doesn't need a lock and interface flags use atomic
operations.

So, remove the unnecessary lock.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-11-09 10:21:13 +00:00
Seppo Takalo d69d4013d3 net: lwm2m: Fix blockwise response code
In CoAP blockwise the client is supposed to
respond with 2.31 Continue code on Ack. This was recently
broken when Block1 parsing was moved after the initialization
of reponse packet. We need separate CoAP API to modify the code
of existing CoAP packet.

Also Ack packet should contain the Block1 options, even the
last one.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-11-08 15:11:36 +00:00
Robert Lubos 83f9fc4ce2 net: ip: Add hidden Kconfig symbol for IP fragmentation
Instead of consistently checking for both, IPv4 and IPv6 fragmentation
in several places, add a hidden Kconfig symbol which indicates that some
IP fragmentation has been enabled (either IPv4 or IPv6 or both).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-08 15:09:37 +00:00
Robert Lubos c724cf99f4 net: pkt: Add explicit flag to indicate packet is IP reassembled
The current logic to determine whether a packet is IP reassembled is
flawed, as it only worked in certain conditions (which was ok, as the
conditions were satisfied for the current use case, but now it's a
public function). Therefore, add an explicit flag that indicates whether
a packet is IP reassembled or not.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-08 15:09:37 +00:00
Robert Lubos 24abc4307b net: Verify L4 checksum unconditionally for reassembled packets
In case of reassembled IP packets, we cannot rely on checksum
offloading as the drivers/HW has no means to verify L4 checksum before
the fragment is reassembled. Therefore, for such packets, verify L4
checksum in the software unconditionally.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-08 15:09:37 +00:00
Robert Lubos 76a256ea57 net: pkt: Add function to check if packet was reassembled at IP level
Move the existing code verifying that the net_pkt was reassembled at IP
level to a helper function, as it will be needed in other places as
well. Additionally, add packet family check before accessing union
fields.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-08 15:09:37 +00:00
Robert Lubos 2836d0701d net: ip: Set net_context on the final fragment
IPv4/6 fragmentation did not set the net_context pointer on the fragment
packet and in result the send callback registered on net_context was not
called. Therefore, copy the net_context pointer from the original packet
to the final fragment to ensure that the registered callback is called.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-08 15:09:37 +00:00
Robert Lubos 64e615263a net: ipv6: Set IP header length on the fragmented packet
IPv6 fragmentation code did not set the IP header field on the
fragment net_pkt.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-08 15:09:37 +00:00
Robert Lubos 0c1c939d9e net: ipv6: Remove invalid/unneeded code from fragmentation logic
Skipping both next_hdr_off and last_hdr_off and filling last_hdr
variable doesn't make much sense, as this effectively moves the packet
cursor inside/behind the last (L4) header with no particular meaning.
Plus the last_hdr variable isn't really used anywhere, which kind of
proves the point. Therefore, remove the unused variable and needless
net_pkt operations.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-08 15:09:37 +00:00
Robert Lubos 13a22e6814 net: ipv6: Calculate checksum before fragmentation
In case the stack has to fragment the IPv6 packet, calculate the
checksum before fragmentation (if haven't done so).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-08 15:09:37 +00:00
Robert Lubos 887a3a321d net: ipv4: Calculate checksum before fragmentation
In case the stack has to fragment the IPv4 packet, calculate the
checksum before fragmentation (if haven't done so).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-08 15:09:37 +00:00
Robert Lubos 08879ea7fb net: ip: Add option to force checksum calculation
Modify internal L4 protocols APIs, to allow to enforce checksum
calculation, regardless of the checksum HW offloading capability.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-08 15:09:37 +00:00
Robert Lubos eadd933607 net: Set a flag when checksum has been computed
Set checksum flag on the net_pkt, when checksum is calculated in
software.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-08 15:09:37 +00:00
Robert Lubos 98b46340f2 net: pkt: Add flag indicating checksum status
Add new net_pkt checksum, which indicate checksum status on the packet
(i. e. whether it has already been calculated or not).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-08 15:09:37 +00:00
Przemyslaw Bida 2a4350dfd2 net: openthread: Adding snoop entries kconfig.
Adding missing `CONFIG_OPENTHREAD_TMF_ADDRESS_CACHE_MAX_SNOOP_ENTRIES`
to thread kconfig file.

Signed-off-by: Przemyslaw Bida <przemyslaw.bida@nordicsemi.no>
2023-11-08 10:08:58 +01:00
Jukka Rissanen e89c9a6671 net: tcp: Fix compilation if congestion avoidance is disabled
Fix tcp.c compilation if user unsets
CONFIG_NET_TCP_CONGESTION_AVOIDANCE config option.

Fixes #64824

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-11-07 09:54:31 +01:00
Chaitanya Tata d12627e70f wifi: shell: Move defaults to beginning
This sets defaults first and then overrides if configured, easier to
read.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-11-07 09:53:39 +01:00
Chaitanya Tata 8c179870d4 wifi: shell: Fix default band value
The enum is mainly to print output of band, so, the default value is 0
which means 2.4GHz, which is not correct when using it to configure like
in connect.

Fix the default value to unknown i.e., no user preference. This way we
can use same enum for both set and get.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-11-07 09:53:39 +01:00
Seppo Takalo 8608b2dc45 tests: lwm2m: Information Reporting Interface [300-399]
Implement testcases for Information Reporting Interface [300-399]:

* LightweightM2M-1.1-int-301 - Observation and Notification of parameter
  values
* LightweightM2M-1.1-int-302 - Cancel Observations using Reset
* LightweightM2M-1.1-int-304 - Observe-Composite Operation
* LightweightM2M-1.1-int-306 – Send Operation
* LightweightM2M-1.1-int-307 – Muting Send
* LightweightM2M-1.1-int-308 - Observe-Composite and Creating
  Object Instance
* LightweightM2M-1.1-int-309 - Observe-Composite and Deleting
  Object Instance
* LightweightM2M-1.1-int-310 - Observe-Composite and modification of
  parameter values
* LightweightM2M-1.1-int-311 - Send command

303 and 305 cannot be implemented using Leshan as it only support
passive cancelling of observation.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-11-07 09:47:00 +01:00
Jukka Rissanen b0d0f60389 net: shell: Print device and wifi information for iface cmd
If the interface is WiFi one, then print information about it.
Also the device information is useful to know so print device
name corresponding to the network interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-11-06 15:51:36 -06:00
Emil Lindqvist 7f19764d9e kconfig: name choices to make changable in outside Kconfigs
This commit names a couple of choices to allow the default
value to be overridden by Kconfig files out of tree

Signed-off-by: Emil Lindqvist <emil@lindq.gr>
2023-11-06 15:33:35 -06:00
Anas Nashif a08bfeb49c syscall: rename Z_OOPS -> K_OOPS
Rename internal API to not use z_/Z_.

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

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

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

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

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

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

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

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

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

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif c91cad735a kernel: object: rename z_object_init to k_object_init
Do not use z_ for internal API and rename to k_object_init.

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

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

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

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

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

Fixes #64634

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

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

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

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

Fixes #64389

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

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

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

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

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

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

Fixes #64290

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

Example of the output of the new command:

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

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

4 active sockets found.

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

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

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-24 00:48:03 -07:00
Jukka Rissanen ec4973dd15 net: tcp: Set errno properly if connecting to non listening port
If we try to connect to a port which no socket is listening to,
we will get a packet with "ACK | RST" flags set. In this case
the errno should be ECONNREFUSED instead of ETIMEDOUT like we
used to return earlier.

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

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-24 00:48:03 -07:00
Jukka Rissanen fd1c226cd8 net: tcp: Increment ref count in initial SYN
Increase reference count already when initial SYN is sent.
This way the tcp pointer in net_context is fully valid for
the duration of the connection.

Fixes #63952

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

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-10-24 09:05:20 +02:00
Robert Lubos dcf7b1905b net: core: Set LL address on loopback packet
In case packet is looped back to the stack, set LL address information
on the packet, using the LL address set on the corresponding network
interface, so that the information can be interpreted by the SOCK_DGRAM
packet socket.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-10-24 09:05:20 +02:00
Jukka Rissanen 73896eef6c net: Set Dummy net_if as default one for tests
If we run network tests under tests/net, then set the
Dummy network interface as a default one so that it will
be picked up first.

This should solve the issue if the DUT is having a real
network interfaces like onboard Ethernet interface which
could cause the test to fail. The test might fail in this
case because the network tests assume that only simulated
network interfaces are used by the tests.

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

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 09:57:22 -05:00
Jukka Rissanen 2238baa831 net: tcp: Do not overwrite remote address in new conn
When a new incoming connection is accepted, do not overwrite
the listening remote address. The remote address for the
listening socket is the any address (like :: for IPv6)
and not the accepted socket remote address.
This only affects the "net conn" shell command which prints
the remote address incorrectly. There is no problem accepting
new connections in this case.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 09:57:22 -05:00
Jukka Rissanen e3f664dfe2 net: conn: Fix the rank value print
We should use the NET_CONN_RANK() macro when printing the
current rank value as that macro masks the rank values properly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 09:57:22 -05:00
Jukka Rissanen 1b4a76cc36 net: tcp: Fix the accepted socket address
The socket address passed in accept() call should point
to the new connection address and not the old one.
Fortunately this only affects things after the v4-mapping-to-v6
support so older code than this works fine.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 09:57:22 -05:00
Jukka Rissanen dea896f6e7 net: tcp: Set address len properly when accepting a socket
The address length of the accepted socket must reflect the
size of the address struct, so it should either be
sizeof(struct sockaddr_in) for IPv4 or sizeof(struct sockaddr_in6) for
IPv6 socket.

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

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 09:57:22 -05:00
Jukka Rissanen 256d5fac4f net: utils: Print IPv4 mapped IPv6 addresses properly
Add support for IPv4 mapped IPv6 addresses when converting
IP address to a string in inet_ntop() function.

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

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

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

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

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-10-23 14:20:23 +01:00
Jukka Rissanen 4b41f9f246 net: wifi: Fix compile error when -Werror -Wextra are set
The warning which became error looks like this

error: type qualifiers ignored on function return type
                                [-Werror=ignored-qualifiers]
  219 | const char * const wifi_ps_txt(enum wifi_ps ps_name);

It is pointless to add a const qualifier to a return value.
So remove the const pointer to avoid this warning.

Fixes #64197

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 11:06:23 +02:00
Jukka Rissanen 046f00244c net: shell: vlan: Enforce arg count via shell macro
Use the SHELL_CMD_ARG() to enforce the minimum parameter
count in vlan command.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-23 10:40:28 +02:00
Jukka Rissanen 31081d8411 net: tcp: Change FL() macro to avoid runtime overhead
Instead of strlen() use sizeof() in FL() macro. This way
all the checks are done at compile time instead of runtime.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-20 15:15:28 +02:00
Robert Lubos 4ea3d247d0 net: tcp: Add Kconfig option to enable TCP RST on unbound ports
Add Kconfig option to control TCP RST behavior on connection attempts on
unbound ports. If enabled, TCP stack will reply with RST packet (enabled
by default).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-10-20 15:13:22 +02:00
Robert Lubos 95d9543e2e net: tcp: Send RST reply for unexpected TCP packets
Send RST as a reply for unexpected TCP packets in the following
scenarios:
1) Unexpected ACK value received during handshake (connection still open
   on the peer side),
2) Unexpected data packet on a listening port (accepted connection
   closed),
3) SYN received on a closed port.

This allows the other end to detect that the connection is no longer
valid (for example due to reboot) and release the resources.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-10-20 15:13:22 +02:00
Robert Lubos a28215d028 net: tcp: Add helper function to send RST packet w/o active connection
Add a helper function which allows to send a RST packet in response to
an unexpected TCP packet, w/o associated connection or net context.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-10-20 15:13:22 +02:00
Seppo Takalo a95bafec74 net: lwm2m: Check access rights on composite operations
Composite operations need to check read/write access
rights as well.

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

Fixes #64012

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

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

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

Fixes #64011

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

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

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

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

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

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2023-10-20 15:09:44 +02:00
Ambroise Vincent 68dfd819c1 net: gptp: Create a stack size Kconfig option
The stack size was previously hardcoded in the source code, making it
difficult to change when enabling options that require a larger stack.

Signed-off-by: Ambroise Vincent <ambroise.vincent@arm.com>
2023-10-20 15:08:25 +02:00
Ambroise Vincent 357f88bb59 net: ethernet: Don't use VLAN tag on gPTP messages
According to IEEE Std 802.1AS-2011 11.3.3, gPTP messages are not
VLAN-tagged.

Remove the use of VLAN headers for gPTP messages on the TX path.
The RX path is handled by the drivers. The network drivers in Zephyr
might need to be updated as well in order to accept receiving
non-VLAN-tagged gPTP messages when the CONFIG_NET_VLAN option is
selected.

Continue sending gPTP packets with VLAN tags when CONFIG_NET_GPTP_VLAN
is enabled. Specify that this option is for testing purposes.

Signed-off-by: Ambroise Vincent <ambroise.vincent@arm.com>
2023-10-20 15:08:25 +02:00
Ambroise Vincent d0ac02a18d net: gptp: Invert priority of outgoing packets
The previous implementation was setting priority 3 (Critical
applications) for Sync, Pdelay and Pdelay_Resp messages; and priority 6
(Internetwork control) for the other PTP messages. This might have been
done under the incorrect understanding that "Critical applications" was
the highest priority.
This resulted in the Pdelay_Resp_Follow_Up getting sent before the
Pdelay_Resp message when enough TC_TX queues were being used
(NET_TC_TX_COUNT >= 2), which is an inversion compared to the intended
order.

Invert the priority of the outgoing PTP packets so that the PTP event
messages are sent with higher priority, as was originally intended.

Signed-off-by: Ambroise Vincent <ambroise.vincent@arm.com>
2023-10-20 15:08:25 +02:00
Ambroise Vincent b7df39f81f net: ip: Clarify highest priority traffic class
The priority 3 (Critical applications) was incorrectly marked as
"highest priority", which might have led to incorrect use of
NET_PRIORITY_CA in some cases.

Note that this is already correctly advertized in other places, as it
was partially fixed in af8a0b1a5d.

NET_TC_SKIP_FOR_HIGH_PRIO was previously only allowing to push priority
3 (Critical applications) packets directly to the driver, but not the
ones with a higher priority. Change it so that it is now in effect for
priority 3 and above.

Signed-off-by: Ambroise Vincent <ambroise.vincent@arm.com>
2023-10-20 15:08:25 +02:00
Seppo Takalo 8ffb64d46f net: lwm2m: Allow configuring update period
Add new configuration value CONFIG_LWM2M_UPDATE_PERIOD
that allows calculating update period from last update,
instead of calculating it from the lifetime.

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

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

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

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

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

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-10-10 14:23:50 +03:00
Jeroen van Dooren fe8d30dd42 net: ip: tcp: Fix kernel crash on idle thread
Fixing kernel crash caused by memory release
while having a scheduled work item pending.

Signed-off-by: Jeroen van Dooren <jeroen.van.dooren@nobleo.nl>
2023-10-09 10:16:05 +02:00
Wojciech Slenska dcf6327d6a net: context: set context->local for offloaded iface
Currently context->local is not set for offloaded interface.
This change move net_offload_bind call after set of context->local.

Signed-off-by: Wojciech Slenska <wsl@trackunit.com>
2023-10-04 20:29:33 +02:00
Juha Ylinen 22f09e9fa0 net: coap: release non-confirmable messages
Only confirmable messages need pending tracking. Non-confirmable
messages are released after sending.
Match incoming packets with token, not message ID.
Ignore responses with non-matching tokens.
Remove unused function send_reset().

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

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

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-10-03 15:21:34 +01:00
Kieran Tyrrell a714b42080 net: ip: fix promiscuous mode altering packets
Always clone net_pkt to pass to promiscuous queue.
Previously, net_pkt was passed to L2 before conditionally cloning.
But L2 would in some cases strip ethernet headers, so cloned
net_pkt received through promiscuous interface would be missing headers.

Signed-off-by: Kieran Tyrrell <kieran@sienda.com>
2023-10-03 15:10:57 +01:00
Andrei Emeltchenko d68db1ecfa net: dhcpv6: Fix params check
Fix params check.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-10-03 15:10:41 +01:00
Vivekananda Uppunda b0c9658029 net: l2: wifi: Fix Wi-Fi mode get command bug
The mode command operation has to be set to WIFI_MGMT_GET when the
option -g is provided. It was mistakenly set to true. Correcting the
same

This PR fixes #63424 and sets the proper value for the get command

Signed-off-by: Vivekananda Uppunda <vivekananda.uppunda@nordicsemi.no>
2023-10-03 11:30:13 +02:00
Bjarki Arge Andreasen d6a96a4b24 net: l2: ppp: Don't attempt reestablish PPP if carrier is down
This commit adds a check to prevent attempting to reestablish
the PPP session if the carrier is down. Without this check,
the PPP FSM attempts and fails to establish a PPP session
twice before giving up. The behavior is not breaking anything,
but it is not desired.

Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
2023-09-30 18:47:33 +02:00
Peter Mitsis 2f003e59e4 kernel: Re-factor k_mem_slab definition
Rearranges the k_mem_slab fields so that information that describes
how much of the memory slab is used is co-located. This will allow
easier of its statistics into the object core statistics reporting
framework.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2023-09-30 08:04:14 +03:00
Robert Lubos 51d3341066 net: icmp: Don't unref net_pkt from the registered handler
A minor overlook from the recent ICMP rework, the registered handlers
should no longer unref the processed packet as it's now the
responsibility of the ICMP module.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-09-29 18:49:43 +03:00
Florian Grandel 60ad26403b net: l2: ieee802154: only log fully assembled pkts
As we already log fragmented packets there's no need to log them again
unless they have been fully assembled and the result is to be logged.

We also want to log the final packet in all cases (after mangling LL
address) for the non-fragmented case.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-09-29 16:27:31 +02:00
Florian Grandel a5d46e7d66 net: l2: ieee802154: mgmt: NET_CONTINUE unless pkt is unrefed
It is the general rule in Zephyr's network stack that methods that
return NET_OK are expected to have "consumed" the packet, i.e. it should
not be referenced any more.

This change applies this rule to the methods in ieee802154_mgmt.* for
improved consistency with the remainder of the network stack.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-09-29 16:27:31 +02:00
Florian Grandel 203391a378 net: l2: ieee802154: security config
The "encryption only" security level was deprecated in IEEE
802.15.4-2015. This deprecation has already been introduced in the code
but was overlooked in net config.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-09-29 16:27:31 +02:00
Florian Grandel 36402b6d2a net: pkt: time: introduce ns timestamp helper
A little refactoring that simplifies dealing with nanosecond timestamp
values in packets and further decouples calling code from PTP:

Benefits:
- simplifies calling code by removing redundant conversions.
- prepares for removing PTP dependencies from net_pkt.

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

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

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

Updated unit test and sample for new event type

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2023-09-29 16:53:55 +03:00
Jukka Rissanen 6661f05daf net: ppp: Mark the PPP L2 as non-experimental
The experimental status of the PPP L2 is long overdue so
it can be removed as the component is working fine.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-09-29 10:33:50 +02:00
Daniel Leung d47b1c05f3 kernel: userspace: add k_object_is_valid()
This adds a function k_object_is_valid() to check if a kernel
object exists, of certain type, and has been initialized.
This replaces the same (or very similar) code that has been
copied from kernel into the network subsystem.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-09-28 17:28:43 -04:00
Jordan Yates 2b92598df1 net: wifi: re-add WIFI_MGMT_FORCED_PASSIVE_SCAN
Re-add the `WIFI_MGMT_FORCED_PASSIVE_SCAN` option removed in #62751.
Now that `struct wifi_scan_params` is a reasonable size, we can enforce
the passive scan request even when no parameter struct is supplied by
the user.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-09-28 15:44:01 +02:00
Jordan Yates 3b7237e6cd net: wifi: shell: update SSID argument format
Instead of providing a comma seperated list of SSIDs, provide the SSIDs
individually. This substantially simplifies the implementation.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-09-28 15:44:01 +02:00
Juha Ylinen 3ffa1d5550 net: coap: Fix coap client timeout
Fix bug in timeout_expired() function. Coap client was resending
pending messages after 500 ms (COAP_PERIODIC_TIMEOUT) and didn't
wait for retransmission timeout.

Use 64-bit k_uptime_get()

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2023-09-28 15:18:12 +02:00
Florian Grandel bd038fc743 doc: ieee802154: l2: improved docs
Hides types used in the IEEE 802.15.4 L2 sub-API and L2-internal APIs
that are of no public interest and improves documentation of the
remainder.

The changes are mostly minor as the API documentation had already been
improved and clarified in previous changes. Also includes non-visible
documentation to the subsystem-internal Frame API by adding references
to the specification.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-09-28 15:13:12 +02:00
Georges Oates_Larsen 98a506f341 net: conn_mgr: Write documentation
Write documentation for conn_mgr and its subsystems, especially
guidelines for writing connectivity implementations

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-09-28 15:11:14 +02:00
Kapil Bhatt 29bbcb1e38 net: wifi: Move function from shell to mgmt
The CONFIG_NET_L2_WIFI_SHELL isn't always enabled.
But these functions might still be used, so need to
move functions into mgmt.

Signed-off-by: Kapil Bhatt <kapil.bhatt@nordicsemi.no>
2023-09-28 12:30:29 +02:00
Anas Nashif 6d23a960db lib: os: build fdtable conditionally
Stop building fdtable by default, make it conditional and build it only
when needed.

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

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

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-09-28 09:34:20 +02:00
Jukka Rissanen 3baaa72920 net: icmp: Add offloading support
Add suitable functions that offloaded network device driver
can receive ICMP Echo-Request (ping) requests and give
ICMP responses back when it receives them from the network.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-09-28 09:34:20 +02:00
Jukka Rissanen c473626267 net: if: Add function for network interface offloading status
Add new net_if_is_offloaded(iface) that returns true if
the network interface is offloaded (either IP or socket
offloading is enabled for that interface) and false if
the interface is not offloaded.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-09-28 09:34:20 +02:00
Jukka Rissanen e3fb634e7a net: shell: Use the ICMP API for ping command
Change the ping command to use the ICMP API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-09-28 09:34:20 +02:00
Jukka Rissanen 19273087f2 net: Use the ICMP API for receiving ICMP messages
Modify the internal network stack code to use the ICMP API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-09-28 09:34:20 +02:00
Jukka Rissanen 31a25da8c2 net: icmp: Introduce new API to send ICMP messages
Allow user to send ICMP Echo Request message a.k.a pings.
The same ICMP API and framework is used for network stack
internal needs in later commits. One benefit for this new
API is that it allows sending Echo Requests to offlined
network devices.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-09-28 09:34:20 +02:00
Robert Lubos 6fb19bc7f0 net: shell: Add DHCPv6 support
Print DHCPv6 status in net shell (with "net iface" command).

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

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-09-28 09:31:20 +02:00
Robert Lubos afa5887b70 net: dhcpv6: Introduce net events for DHCPv6
Add net events for DHCPv6, in similar fashion as it's done for
DHCPv4.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-09-28 09:31:20 +02:00
Robert Lubos e73e78a550 net: dhcpv6: Add Zephyr DHCPv6 client
Add a DHCPv6 client implementation for Zephyr (RFC 8415).

The implementation allows to request IPv6 address and/or prefix from the
DHCPv6 server, and for now supports only the mandatory set of DHCPv6
options needed to achieve this. Currently the implementation supports
the following scenarios:
 * Requesting new IPv6 address/prefix with Solicit/Request exchange
 * Refreshing existing leases with Confirm, Renew or Rebind (depending
   on the context).

For now, no Information Request (the case where neither IPv6 address or
prefix are requested) is supported. No support for Reconfigure was added
either, as this is optional (the client manifests clearly to the server
that it does not support Reconfigure). Support for these can be added
later if needed.

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

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-09-27 11:55:10 -05:00
Florian Grandel a12a6ab5b9 drivers: ieee802154: introduce channel pages
Replaces the previous approach to define bands via hardware capabilities
by the standard conforming concept of channel pages.

In the short term this allows us to correctly calculate the PHY specific
symbol rate and several parameters that directly depend from the symbol
rate and were previously not being correctly calculated for some of the
drivers whose channel pages could not be represented previously:
* We now support sub-nanosecond precision symbol rates for UWB. Rounding
  errors are being minimized by switching from a divide-then-multiply
  approach to a multiply-then-divide approach.
* UWB HRP: symbol rate depends on channel page specific preamble symbol
  rate which again requires the pulse repetition value to be known
* Several MAC timings are being corrected based on the now correctly
  calculated symbol rates, namely aTurnaroundTime, aUnitBackoffPeriod,
  aBaseSuperframeDuration.

In the long term, this change unlocks such highly promising functional
areas as UWB ranging and SUN-PHY channel hopping in the SubG area (plus
of course any other PHY specific feature).

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-09-27 12:44:15 -04:00
Seppo Takalo a8f9777586 net: lwm2m: Generate new tokens for LwM2M SEND blocks
Previously each piece of LwM2M SEND was
using token length of zero. I think this was unintentional.

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

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

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

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

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

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

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

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

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

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

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

Compared to:

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

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-09-26 16:55:16 +02:00
Jukka Rissanen 0e5016e502 net: arp: Directly send the queued pkt
We must send the packet without queueing it. The pkt has already
been queued for sending, once by net_if and second time in the ARP
queue. We must not queue it twice in net_if so that the statistics
of the pkt are not counted twice and the packet filter callbacks
are only called once.

Fixes #62483

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-09-26 15:07:20 +02:00
Pieter De Gendt cb4fb765f0 net: if: Add ASSERT in net_if_ipv4/6_select_src_addr
Add an assert for the destination address provided to find the best
source address.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-09-26 12:04:03 +02:00
Jukka Rissanen 37b8dc17bc net: socket: Allow same port if different address family
It is always possible to bind to same port if the sockets
are in different address family.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-09-25 10:53:49 +02:00
Jordan Yates b54951b86e net: wifi_mgmt: linearise scan_params->chan arrays
Turn the nested arrays of `scan_params->chan` into a single array.
This adds the requirement to specify the band for each channel, but
eliminates the large amount of dead memory for unused bands. Overall,
this saves 50% of the RAM space for this variable.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-09-25 09:48:16 +02:00
Jordan Yates 6a428f19b6 net: wifi_mgmt: make number of scan channels configurable
Make the maximum number of channels that can be manually scanned
configurable by the application. The previous value of 233 was vastly
overallocating memory as the largest band only contains 60 allocated
channels.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-09-25 09:48:16 +02:00
Marcin Gasiorek c668fbc4d2 net: ip: Add cloning of missing attributes
A few attributes isn't cloned togerder with pkt.
This commit add missing part.
Additionally, because the `eof` flag in net_pkt structure is
avilable unconditionally hence `#if defined(CONFIG_NET_SOCKETS)`
guard has been removed form setter and getter functions for
this flag.

Signed-off-by: Marcin Gasiorek <marcin.gasiorek@nordicsemi.no>
2023-09-21 13:36:20 +02:00
Marcin Gasiorek 6a536f9f8c net: Deprecated and unused flags cleanup.
In net_pkt structure couple of flags are no longer used.
Flag pkt_queued can be removed permanently togeter with setter
and getter functions.
Second flag sent_or_eof has been renamed because it is still
used partially only for indicating EOF. Additionally unused setter
and getter for 'sent_' part of this flag are removed.

Signed-off-by: Marcin Gasiorek <marcin.gasiorek@nordicsemi.no>
2023-09-21 13:36:20 +02:00
Seppo Takalo 0a982c3617 net: lwm2m: Add shell command to create object instances
Some testcases might need to be able to create
object instances, so add shell command for it.

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

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

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-09-21 09:29:05 +02:00
Kapil Bhatt 4b9f5cc455 net: l2: wifi: Change arrays to functions
The header file contains mixture of functions and static arrays.
Replacing static arrays to functions.
Initialize functions in C file.

Signed-off-by: Kapil Bhatt <kapil.bhatt@nordicsemi.no>
2023-09-21 09:28:46 +02:00
Jordan Yates 5452665beb net: l2: wifi_mgmt: remove scan kconfig defaults
Remove the wifi_mgmt interface overriding default values with values
from kconfig. The defaults were only applied when a `params` struct was
provided by the application.

This is the case when the application is explicitly setting the options
it wants, why is the mgmt API changing these. When `params` is NULL and
thus modem defaults are requested, these defaults aren't applied. This
is the opposite behaviour from what seems reasonable.

In addition, these options are:
 * Undocumented
 * Using non-trivial string parsing functions (strtok)
 * Adding complexity to the API implementation by forcing support for
   ROM versions of command line arguments.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-09-20 20:21:49 +01:00
Tobias Frauenschläger dcc63120cf net: sockets: add support for SO_REUSEPORT
This commits adds support for the SO_REUSEPORT socket option.

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

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

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

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

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

Signed-off-by: Tobias Frauenschläger <t.frauenschlaeger@me.com>
2023-09-20 08:56:31 +02:00
Konrad Derda b3a3a8b3a2 net: ip: use default interface while matching LL src address
While matching source address for a given Link-Local destination the
functions iterate over interfaces and return a first result with a
valid LL-address. However, they should first try to fetch address of
the default interface as it not always the first one on the list.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2023-09-19 15:24:04 +01:00
Seppo Takalo da1463756e net: lwm2m: Allow Bootstrap server to close DTLS connection
Allow Bootstrap server to close the DTLS connection immediately
after receiving Ack to Bootstrap-Finish command.
This is not an error as either parties are allowed to tear down
the connection.

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

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

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

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

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

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

Signed-off-by: Ambroise Vincent <ambroise.vincent@arm.com>
2023-09-18 15:41:23 -04:00
Andreas Ålgård fa0bbaf66c net: promiscuous: Fix crash in promiscuous mode
When a packet can't be cloned we crash as we try to initialize the
cursor on a nullptr. We should check if we have a valid pointer,
and if we don't we drop the packet along with a warning.

Signed-off-by: Andreas Ålgård <aal@ixys.no>
2023-09-18 20:34:31 +02:00
Dominik Ermel 47396e18e1 net: Fix usage of strncpy in net_if_get_name and net_if_set_name
Replaced with memcpy.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-09-18 20:34:19 +02:00
Chaitanya Tata 40ee8791f2 net: socketpair: Fix use after free
In low memory conditions, its possible for socketpair memory allocation
to fail and then the socketpair is freed but after that the remote
semaphore is released causing a crash.

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

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-09-18 20:34:12 +02:00
Jordan Yates dd090f06b7 net: wifi_mgmt: change type of wifi_scan_params->chan
All WiFi channel numbers fit within a 8 bit number, as the maximum
allocated channel is 233. This halves the memory requirement.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-09-18 10:54:31 +01:00
Martin Jäger eae44a55d8 net: lib: sockets: sockets_tls: prefix mbedtls error with 0x
The errors are printed in hex, but no prefix was used. This could be
confused with usual errno return values. The 0x prefix makes clear
that it's a hex value.

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

Signed-off-by: Martin Jäger <martin@libre.solar>
2023-09-18 10:38:44 +01:00
Wojciech Slenska 6f3bbe19a7 net: ip: stats: changed dependency for PPP stats
NET_STATISTICS_PPP are dependend on NET_L2_PPP, not on NET_PPP.
This allows to use statistics also in modem subsys.

Signed-off-by: Wojciech Slenska <wsl@trackunit.com>
2023-09-15 15:13:06 -05:00
Donatien Garnier 185a6117c0 Bluetooth: Host: Amend existing L2CAP accept callbacks
This patch amends the existing L2CAP accept callbacks to use the new
accept signature that includes a pointer to the L2CAP server structure.

Signed-off-by: Donatien Garnier <donatien.garnier@blecon.net>
2023-09-14 14:36:34 +02:00
Vivekananda Uppunda 450dbb15ef net: l2: wifi: Add support for W-Fi mode setting and selection
This change brings in support for setting various Wi-Fi modes and
enables a specific Wi-Fi interface to be also placed into a sniffer
operation via monitor mode and promiscuous mode. A raw TX- packet
Injection mode is also introduced

Signed-off-by: Vivekananda Uppunda <vivekananda.uppunda@nordicsemi.no>
2023-09-13 11:47:28 +02:00
Chaitanya Tata 79158a777b zperf: Add support to configure context priority
This is handy in setting a custom priority for the context either
through shell or API.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-09-12 21:26:28 -04:00
Chaitanya Tata 7711d28b03 net: Add configuration option to allow any priority
This adds support to allow any priority from the user instead of
limiting to the protocol values (0-7). This is useful in conveying
custom priorities from application to the driver/chipset.

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

This is applicable for both shell and API.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-09-12 21:26:28 -04:00
Sachin D Kulkarni 85b39b8449 net: wifi: Fix crash in wifi_utils_parse_scan_ssids
wifi_utils_parse_scan_ssids could cause a crash if a constant string is
passed to it. Fix this by duplicating the input string parameter before
parsing it with strtok_r.

Also limit the range of the CONFIG_WIFI_SCAN_SSID_FILT_MAX parameter
from 1 to 4 to avoid stack overflow due to users specifying a large
value for this parameter.

Signed-off-by: Sachin D Kulkarni <sachin.kulkarni@nordicsemi.no>
2023-09-12 09:24:06 +02:00
Sachin D Kulkarni 0b92327fc3 net: wifi: Fix crash in wifi_utils_parse_scan_bands
wifi_utils_parse_scan_bands could cause a crash if a constant string is
passed to it. Fix this by duplicating the input string parameter before
parsing it with strtok_r.

Signed-off-by: Sachin D Kulkarni <sachin.kulkarni@nordicsemi.no>
2023-09-12 09:24:06 +02:00
Florian Grandel 141293ea23 net: l2: ieee802154: settings: make ACK configurable
Add a network configuration option to configure whether IEEE 802.15.4
packets are expected to be ACKed or not.

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

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

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

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-09-09 05:18:41 -04:00
Florian Grandel 5aa329cecd net: l2: ieee802154: mgmt: fix locking issue
Fixes a locking issue in the IEEE 802.15.4 net mgmt implementation.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-09-09 05:18:41 -04:00
Robert Lubos 370096e4f5 net: tcp: Fix goto condition in case of RST/packet error
In case RST packet is received or malformed packet is received, the TCP
should not proceed with the state machine execution (which may process
the invalid packet) but rather jump directly to exit, where the
connection will be closed.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-09-07 11:41:52 +02:00
Bjarki Arge Andreasen 111db23d0a net: mgmt: Fix memory corruption in wait_on_iface
The net_mgmt subsystem offers a function which waits (blocks)
until a specified net event occurs. An event callback is
pushed to the stack, then added to the net_mgmt_event_callback
list. If the event occurs, the net_mgmt thread calls the
callback and deletes the callback from the list. However, if
the event does not occur within the timeout specified when
invoking mgmt_event_wait_call() the function will return,
corrupting the callback structure the stack is reused.

This PR fixes the issue by deleting the callback before exiting
in case the event does not occur.

Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
2023-09-07 09:44:06 +02:00
Carles Cufi 8c748fd005 kernel: Modify the signature of k_mem_slab_free()
Modify the signature of the k_mem_slab_free() function with a new one,
replacing the old void **mem with void *mem as a parameter.

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

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

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

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

Fixes #61888.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2023-09-03 18:20:59 -04:00
Andrei Emeltchenko db7dced87c net: wifi_utils: Add missing break
Add missing break statement.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-09-01 16:37:34 +02:00
Jukka Rissanen 8c573d6142 net: shell: Print user friendly network interface name
If network interface name support is enabled, print the name
when showing network interface data.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-08-31 14:43:36 +02:00
Jukka Rissanen 7aa4904b5a net: socket: Change SO_BINDTODEVICE to use interface name
Make sure we use the network interface name (if configured)
instead of device name when binding to certain network
interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-08-31 14:43:36 +02:00
Jukka Rissanen 05b7eda618 net: Add name support to network interface
If CONFIG_NET_INTERFACE_NAME is enabled (default is y), then
system will automatically set a user friendly name to the network
interface like eth0, wlan0 etc.
Application can change the interface name if needed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-08-31 14:43:36 +02:00
Jukka Rissanen 7d3dabf07b net: wifi: Properly namespace public APIs
The twt and ps helper functions were not namespaced (were missing
wifi_ prefix).

Also change wifi_get_twt_... to more logical wifi_twt_get...
like the other twt prefixed functions and wifi_get_ps... to
wifi_ps_get... like the other ps prefixed functions.

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

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

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

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

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

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Signed-off-by: Pete Skeggs <peter.skeggs@nordicsemi.no>
2023-08-30 11:36:51 +02:00
Fabio Baltieri ece5380490 net: fix few mismatched CONTAINER_OF
Fix few mismatched CONTAINER_OF, few missing k_work_delayable_from_work
and a missing reference to the array first element.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-08-30 10:21:31 +02:00
Georges Oates_Larsen b25ea4742e net: conn_mgr: Rename connectivity monitor
The connectivity monitoring subfeature of conn_mgr is currently also
named conn_mgr, which is confusing.

This commit renames it to conn_mgr_monitor, or conn_mgr_mon for short,
for clarity.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-08-29 16:13:37 +02:00
Georges Oates_Larsen 2e762836d5 net: conn_mgr: binding get/set flag
Add a helper allowing connectivity implementations to more easily access
connectivity flags on connectivity bindings.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-08-29 16:13:37 +02:00
Georges Oates_Larsen 49a7798c30 net: conn_mgr: binding lock/unlock
Adds conn_mgr_binding_lock/conn_mgr_binding_unlock, which connectivity
implementations can call to lock or unlock the passed in connectivity
binding.

This allows connectivity implementations to safely make direct accesses
to binding data from outside conn_mgr_conn_api callbacks, and should
allow cleaner, more robust connectivity implementations to be written.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-08-29 16:13:37 +02:00
Georges Oates_Larsen 6d2ce0b30b net: conn_mgr: Create separate connectivity implementation API.
Splits many definitions from conn_mgr_connectivity.h off into their own
header, conn_mgr_connectivity_impl.h

conn_mgr_connectivity.h now focuses solely on user/application-facing
APIs, and conn_mgr_connectivity_impl now contains all functions, utils,
definitions intended for use by connectivity implementations, including
conn_mgr_if_get_binding, which is now available for use by connectivity
implementations.

This lays the foundation for allowing connectivity implementations
easier and safer access to their internal state through internal APIs.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-08-29 16:13:37 +02:00
Gerard Marull-Paretas 8cf63ff367 net: lib: zperf: add missing init.h
File was using SYS_INIT without including init.h.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2023-08-29 12:17:15 +01:00
Konrad Derda 1d7d4f308c net: icmpv6: allow multiple handlers
This change allows to register additional handlers for ICMPv6 so the
user can handle some of the messages between they are handled by the
ICMPv6 module in Zephyr by returning NET_CONTINUE.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2023-08-28 08:24:31 +01:00
Robert Lubos 43015032b4 net: tcp: Fix corner case with closed listener
There was a corner case which was not handled well in a scenario, when
listening socket was closed during an active handshake with a new
client.

When a listening socket is closed, the accept callback is cleared on the
TCP context. If this happened during a handshake with a new client, i.
e. before final ACK from the client was processed, this lead to a
context leak, as application did not take ownership of the connection
(i. e. had no means to close it).

Fix this, by proactively closing the connection at the TCP level when no
accept_cb is available. Instead of ignoring the fact that no accept_cb
is available, the TCP stack will now enter TCP_FIN_WAIT_1 state and
proceed with a graceful teardown of the connection.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-08-27 07:35:34 -04:00
Robert Lubos d5252cb5de net: sockets: Fix getsockname()
getsockname() did not work properly on bound sockets, as it verified
whether the socket has an active connection before retuning result. This
is not correct, as socket after bound may not have a connection yet.

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

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

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

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

Signed-off-by: Georgij Cernysiov <geo.cgv@gmail.com>
2023-08-25 13:15:12 +02:00
Noah Luskey e71840ed69 net: wifi_mgmt: Fix size calculation for net_mgmt info
net_iface_status is larger than scan_result, causing
net_iface events to be dropped due to info exceeding
NET_EVENT_INFO_MAX_SIZE.

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

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-08-25 10:31:19 +02:00
Andreas Müller d9bd2d2ff4 net: icmpv6: check for type < 128 rather than code < 128
ICMPv6 messages with type < 128 are error messages, where we should not
send back another error. The meaning of the code depends on the type.

Signed-off-by: Andreas Müller <andreas.mueller@husqvarnagroup.com>
2023-08-25 10:31:10 +02:00
Seppo Takalo 40dd0c1fa0 tests: lwm2m: Add bootstrap tests into RD client tests
Add bootstrap and few corner cases into RD client tests
to improve code coverage.

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

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-08-24 22:07:32 +01:00
YuLong Yao 716e3a17c1 net: wifi: shell: remove duplicate ap item
Remove two duplicate ap in wifi menu

Signed-off-by: YuLong Yao <feilongphone@gmail.com>
2023-08-23 16:08:51 +01:00
Sachin D Kulkarni 0467fb89ba net: wifi: Enhance help text for NET_L2_WIFI_MGMT
Changed Add to Enable in help text to convey the intended use of the
Kconfig NET_L2_WIFI_MGMT.

Signed-off-by: Sachin D Kulkarni <sachin.kulkarni@nordicsemi.no>
2023-08-23 16:05:08 +01:00
Sachin D Kulkarni 419ffa54a7 net: wifi: Validate scan parameters
Add defensive check to validate scan command parameters.

Signed-off-by: Sachin D Kulkarni <sachin.kulkarni@nordicsemi.no>
2023-08-23 16:05:08 +01:00
Sachin D Kulkarni 2c039026eb net: wifi: Add scan command option to print help
Add a scan command option to print the help text for the scan command.
This is to facilitate ease of using the command (since now there are
many different options added to the scan command).

Signed-off-by: Sachin D Kulkarni <sachin.kulkarni@nordicsemi.no>
2023-08-23 16:05:08 +01:00
Sachin D Kulkarni b572e8216a net: wifi: Add scan extension for specifying channels
Add scan extension to allow limiting the scanning to specific channels.
Only 20 MHz channel specifications are allowed presently.

Signed-off-by: Sachin D Kulkarni <sachin.kulkarni@nordicsemi.no>
2023-08-23 16:05:08 +01:00
Sachin D Kulkarni 01e167988c net: wifi: Add scan extension for limiting scan results
Add scan extension to allow limiting the scan results to a user defined
maximum number. This parameter is intended to return results with the
best RSSI. It cannot be counted upon to limit the scan times since the
Wi-Fi chips might have to scan all the channels to find APs with the
best RSSI values across all channels.

Signed-off-by: Sachin D Kulkarni <sachin.kulkarni@nordicsemi.no>
2023-08-23 16:05:08 +01:00
Sachin D Kulkarni 5c399c2d17 net: wifi: Add scan extension for filtering SSIDs
Add scan extension to scan only for specific SSIDs.

Signed-off-by: Sachin D Kulkarni <sachin.kulkarni@nordicsemi.no>
2023-08-23 16:05:08 +01:00
Sachin D Kulkarni 6328fda702 net: wifi: Add scan extension for passive channel dwell times
Add scan extension to control scanning time spent on channels where
passive scanning is used.

Signed-off-by: Sachin D Kulkarni <sachin.kulkarni@nordicsemi.no>
2023-08-23 16:05:08 +01:00
Sachin D Kulkarni 3c130b138f net: wifi: Add scan extension for active channel dwell times
Add scan extension to control time spent on active scan channels.

Signed-off-by: Sachin D Kulkarni <sachin.kulkarni@nordicsemi.no>
2023-08-23 16:05:08 +01:00
Sachin D Kulkarni ee6c81896d net: wifi: Added scan extension support for frequency bands
Added scan extension to support scanning individual Wi-Fi bands or
combinations thereof.

Signed-off-by: Sachin D Kulkarni <sachin.kulkarni@nordicsemi.no>
2023-08-23 16:05:08 +01:00
Sachin D Kulkarni add1d15bee net: wifi: Modify option and argument for scan type
Modify the way the scan type option is passed to the wifi scan command.
This makes it flexible to add more scan options.

Signed-off-by: Sachin D Kulkarni <sachin.kulkarni@nordicsemi.no>
2023-08-23 16:05:08 +01:00
Daniel Leung 842a65914f net: lwm2m: ignore -Wshadow for cbor type header file
There are a few structs, unions, and enums where -Wshadow would
complain. Since names being the same are intentional, we need
to tell compiler to ignore -Wshadow for those names.

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

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-22 11:39:58 +02:00
Sjors Hettinga a8b03b7b93 net: tcp: Restructure the close FIN sequence
When the application closes the connection, it enters the FIN1 state.
Restructure this sequence to RST on data received after the application
has closed the socket.
Next to that deal with packets that contain both data and a FIN flag.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2023-08-22 10:00:14 +02:00
Christopher Friedt 4a095bb34b net: sockets: support fionbio and fionread
The `ioctl()` interface is already supported by the network
subsystem but there was no `zsock_` interface available for it.

Add the `zsock_ioctl()` syscall.

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

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

In the process, added `net_pkt_ip_proto_hdr_len()`

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

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

`ioctl(fd, FIONREAD, &avail)`

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

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

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

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

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

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-08-22 09:59:44 +02:00
Grant Ramsay 625cd1d1e3 net: ip: Make NET_QEMU_NETWORKING a named choice
Naming this choice allows setting a default value in defconfig.

Signed-off-by: Grant Ramsay <gramsay@enphaseenergy.com>
2023-08-18 10:13:12 +02:00
Lukas Woodtli 3b4e54e39e net: coap: Add function to check for block option in message
The added function allows to check if a descriptive block
option was already added to a message.

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

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

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

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

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

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

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

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

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

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

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

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

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-08-16 10:21:46 +02:00
Tobias Frauenschläger 6a7656ba48 net: tcp: Set correct source IP address when connecting
In case a TCP connection should be established with a specific source
IP address (e.g., by calling bind() prior to connect() on the socket),
we have to actually place the address in the outgoing packet.

Signed-off-by: Tobias Frauenschläger <t.frauenschlaeger@me.com>
2023-08-15 21:54:25 +00:00
Daniel Leung 5bc08ae3c6 net: rename shadow variables
Renames shadow variables found by -Wshadow.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-10 08:14:43 +00:00
Robert Lubos cc77f2749c net: context: Remove shadowing variable in net_context_recv()
Remove the shadowing ret variable and fix a bug that was related to
its existence - the shadowing ret variable was assigned with -ETIMEDOUT
which was supposed to be retuned by the function, but was not because
the ret variable at the function scope was left intact.

Also remove the unneded goto unlock; jump (assigning the error code is
the last operation before unlocking the mutex anyway).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-08-09 20:01:39 -04:00
Jani Hirsimäki 83ea1e26a2 net: l2: ppp: ppp uart usage fixed
This fixes 3 issues that came within PR #59124 for ppp uart usage.

Earlier start/stop of ppp was done at enable() but that
was removed in PR #59124. Now putting enable/disable() back and
putting start/stop there.
Additionally, there was a double ppp carrier ON when NET_EVENT_IF_DOWN.
For that net_if_carrier_on/off is set in uart ppp.c driver.
Also, maybe worth to be mentioned that after PR #59124 there is no
ppp carrier off when lcp is disconnected, for workaround that change,
application should use ppp dead/running events.

Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>
2023-08-09 16:07:46 +00:00
YuLong Yao 959e0e829d net: wifi: shell: fix parameter description error
command `wifi ap enable` not have SSID LENGTH parameter, remove it.

Signed-off-by: YuLong Yao <feilongphone@gmail.com>
2023-08-08 13:28:12 +00:00
Daniel Mangum 775a8e8c8d net: sockets: use DTLS in NET_SOCKETS_TLS_MAX_APP_PROTOCOLS
Updates NET_SOCKETS_TLS_MAX_APP_PROTOCOLS Kconfig option description to use
DTLS instead of DTL.

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

No functional changes, just clean up of Kconfig menu.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-08-07 11:26:47 +02:00
Konrad Derda 409b15c7ce net: event: provide complete information about the prefix in events
At the moment, NET_EVENT_IPV6_PREFIX_ADD and NET_EVENT_IPV6_PREFIX_DEL
events provide provide information about an address without its length
and lifetime.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2023-08-07 11:25:40 +02:00
Sjors Hettinga 8cd5d6f267 net: tcp: Log the steps in the collision avoidance
To allow insighed into the correct functioning of the collision avoidance,
log the internal values and function calls.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2023-08-04 15:05:17 +02:00
Sjors Hettinga 5b640ec9db net: tcp: Implement TCP new Reno collision avoidance
To avoid a TCP connection from collapsing a link, implement a collision
avoidance algorithm. Initially TCP new Reno is implemented for its
simplicity.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2023-08-04 15:05:17 +02:00
Sjors Hettinga 6783848b8f net: ppp_l2: Make prio of PPP TX thread configurable
The PPP TX thread handles the transmission of packets at PPP layer.
Make it's priority configurable, so it's priority can be configured higher
then higher protocol layers.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2023-08-02 14:04:55 +02:00
Sjors Hettinga cb31883e1b net: tcp: Make priority of TCP work queue configurable
The TCP work queue is handles all TCP transmission and maintenance tasks.
Make it's priority configurable, so it can be configured to a lower
priority than the lower level network layers to avoid it consuming all
net_bufs before handing over execution to the lower layer network layers.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2023-08-02 14:04:55 +02:00
Seppo Takalo 838ab80bca net: coap: Use 64bit timestamps
Use 64bit timestamps from k_uptime_get() so they don't
roll over during the expected device lifetime.

Fixes #60826

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

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

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

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

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-07-31 14:49:05 +02:00
Sjors Hettinga 1f3cb08fdc net: tcp: Remove trigger of send_data_timer when window full
Likely this trigger of the send_data_timer was an alternative for the
function that has been filled in by the ZWP transmission.
At the moment this timer has the potential to cause spurious
retransmissions that can degrade the throughput of the network stack.
Second to that it can accelerate the retransmission process, quickly
running to the number of retransmissions, causing a connection failure.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2023-07-31 14:05:58 +02:00
Sjors Hettinga e14935ec6c net: tcp: Avoid partial ACK canceling retransmission timer
At any ack, the retransmission timer was cancelled. This means when an ACK
is only partially acknowledging pending data, followed by a packet loss,
the connection ended in a deadlock eventually timing out.
By checking if there is any pending data for transmission before canceling
the retransmission timer, there is no risk of this lock-up any more.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2023-07-31 10:09:05 +02:00
Florian Grandel a4cd5cee40 drivers: ieee802154: consistent high res timestamps
The IEEE 802.15.4 API and networking subsystem were using several
inconsistent timestamp resolutions and types. This change defines all
timestamps with nanosecond resolution and reduces the number of
available types to represent timestamps to two:
* `struct net_ptp_time` for PTP timestamps
* `net_time_t` for all other high resolution timestamps

All timestamps (including PTP timestamps) are now referred to a
"virtual" local network subsystem clock source based on the well-defined
types above. It is the responsibility of network subsystem L2/driver
implementations (notably Ethernet and IEEE 802.15.4 L2 stacks) to ensure
consistency of all timestamps and radio timer values exposed by the
driver API to such a network subsystem uptime reference clock
independent of internal implementation details.

The "virtual" network clock source may be implemented based on arbitrary
hardware peripherals (e.g. a coarse low power RTC counter during sleep
time plus a high resolution/high precision radio timer while receiving
or sending). Such implementation details must be hidden from API
clients, as if the driver used a single high resolution clock source
instead.

For IEEE 802.15.4, whenever timestamps refer to packet send or receive
times, they are measured when the end of the IEEE 802.15.4 SFD (message
timestamp point) is present at the local antenna (reference plane).

Due to its limited range of ~290 years, net_time_t timestamps (and
therefore net_pkt timestamps and times) must not be used to represent
absolute points in time referred to an external epoch independent of
system uptime (e.g.  UTC, TAI, PTP, NTP, ...).

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-28 09:06:35 +00:00
Florian Grandel 69212bb169 doc: drivers: ieee802154: radio API
Improves the documentation of the IEEE 802.15.4 radio API.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-28 09:06:35 +00:00
Robert Lubos b2314c8362 net: if: Add functions to loop over IPv4/IPv6 addresses
Add new net_if API functions which allow to loop over all valid
IPv4/IPv6 addresses assigned to the interface and execute a callback
function on them.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-07-25 14:18:54 +02:00
Robert Lubos 30382daf88 net: wifi_shell: Add user input validation for SSID and PSK
When parsing user input for "wifi connect" and "wifi ap enable"
commands, the SSID and PSK lengths were not verified. It's better to
detect invalid connect/AP enable parameters early, so that help text can
be printed, instead of letting wifi_mgmt command to fail.

For WIFI_SECURITY_TYPE_SAE, follow the Linux convention of limiting the
size to 128 bytes.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-07-25 14:16:17 +02:00
Robert Lubos a22f7e777b net: dhcpv4: Accept unicast replies
Some DHCPv4 servers do not respect BROADCAST flag set on DHCP Discover,
replying with unicast packet, making it impossible to obtain DHCP
address by Zephyr in such cases.

RFC1542 chapter 3.1.1 makes the following statement about the BROADCAST
flag:
    This addition to the protocol is a workaround for old host
    implementations.  Such implementations SHOULD be modified so
    that they may receive unicast BOOTREPLY messages, thus making
    use of this workaround unnecessary.  In general, the use of
    this mechanism is discouraged.

Making it clear that being able to process unicast replies from the DHCP
server is not only an optional behavior, but a recommended solution.

Therefore, introduce a support for unicast DHCPv4 in Zephyr. To achieve
this, add additional filtering rule at the IPv4 level - in case DHCPv4
is enabled, there is an active query and the packet is destined for the
DHCPv4 module, let it through for the DHCPv4 module to process,
regardless of the destination IP address.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-07-25 14:15:45 +02:00
Andrzej Kuros a04a059ccc net: ieee802154_radio: add attribute getter API
The `attr_get` method is added to the ieee802154_radio to allow
reading of driver specific attributes of given device.

The enum `ieee802154_attr` provides common extension pattern
allowing to extend the attribute set.

Accessor function `ieee802154_radio_attr_get` is provided.

Signed-off-by: Andrzej Kuroś <andrzej.kuros@nordicsemi.no>
2023-07-25 09:13:41 +02:00
Nicolas Pitre bd3ed97230 subsys/net: zperf_udp_uploader: Remove sys_clock_timeout_end_calc() usage
The initial goal was to remove sys_clock_timeout_end_calc(). However,
several related issues have been fixed as well.

First this:

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

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

The above condition will simply never be true.

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

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

Then this:

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

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

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

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

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

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2023-07-25 09:12:26 +02:00
Nicolas Pitre 13d68185d5 subsys/net: move to timepoint API
Remove sys_clock_timeout_end_calc() usage.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2023-07-25 09:12:26 +02:00
Nicolas Pitre 52e2f83185 kernel/timeout: introduce the timepoint API
This is meant as a substitute for sys_clock_timeout_end_calc()

Current sys_clock_timeout_end_calc() usage opens up many bug
possibilities due to the actual timeout evaluation's open-coded nature.

Issue ##50611 is one example.

- Some users store the returned value in a signed variable, others in
  an unsigned one, making the comparison with UINT64_MAX (corresponding
  to K_FOREVER) wrong in the signed case.

- Some users compute the difference and store that in a signed variable
  to compare against 0 which still doesn't work with K_FOREVER. And when
  this difference is used as a timeout argument then the K_FOREVER
  nature of the timeout is lost.

- Some users complexify their code by special-casing K_NO_WAIT and
  K_FOREVER inline which is bad for both code readability and binary
  size.

Let's introduce a better abstraction to deal with absolute timepoints
with an opaque type to be used with a well-defined API.
The word "timeout" was avoided in the naming on purpose as the timeout
namespace is quite crowded already and it is preferable to make a
distinction between relative time periods (timeouts) and absolute time
values (timepoints).

A few stacks are also adjusted as they were too tight on X86.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2023-07-25 09:12:26 +02:00
Robert Lubos 51726f3648 net: l2: ieee802154: shell: Validate address on input
Associate command handler did not validate the provided address length.
In result, if provided address string was longer than the expected
extended address size, strncpy() would not NULL terminate the buffer,
which could lead to unexpected behavior in parse_extended_address(), as
it expects NULL terminated string.

Fix this by validating the length of the provided address string before
parsing.

Additionally, make parse_extended_address() return the parsing result,
so that it can be detected when provided extended address has incorrect
format.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-07-20 10:47:39 +00:00
Chen Caidy 0635e2690e net: gptp: fix announce message byte order
Linuxptp report UTC offset is 9472 seconds, is a byte order issue,
The right value is 37. Also fixed offset_scaled_log_var byte order.

Signed-off-by: Chen Caidy <chen@caidy.cc>
2023-07-19 21:42:05 -04:00
Chen Caidy 413eceeddb net: gptp: fix follow_up message correction_field
According to IEEE802.1AS Table 11-6 and 10.6.2.2.9,
802.1AS using peer-to-peer delay mechanism, two-step clock,
Grand master clock should keep this correction_field as zero.

Signed-off-by: Chen Caidy <chen@caidy.cc>
2023-07-19 21:42:05 -04:00
Chen Caidy 762df873b4 net: gptp: fix follow_up message timestamp
According to IEEE802.1AS 11.4.4.2.1, we need fill
preciseOriginTimestamp as syncEventEgressTimestamp.

In this follow_up message, prec_orig_ts need to filled
from net_pkt_timestamp(sync) for best accuracy. state machine
is software trigger with insufficient precision.

After this change, a grand master endpoint sync accuracy
increase from 3.5ms to 580ns with mimxrt1050_evk board.

Signed-off-by: Chen Caidy <chen@caidy.cc>
2023-07-19 21:42:05 -04:00
Chaitanya Tata 7a6288a871 net: l2: wifi: Fix printing of TWT parameters
Use the macro to print to handle for cases where shell context is NULL,
this is possible because in this net management event handler shell
context is not passed.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-07-17 13:21:39 +00:00
Robert Lubos c15e3d448c net: conn_mgr: Create conn_mgr thread dynamically
Statically created threads with K_THREAD_DEFINE() are launched only
after the SYS_INIT phase. This does not play well with NET_CONFIG
library, which may block during SYS_INIT until network interface
is UP and RUNNING.

In order to be able to connect to L2 network and thus mark the
network interface as running and unblock NET_CONFIG, we need to be
able to run conn_mgr thread during SYS_INIT. This can be achieved,
by starting the thread dynamically during SYS_INIT phase, instead
of relying on static thread creation.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-07-14 09:37:37 +02:00
Robert Lubos cc81dca556 net: if: Fix if_ipv4_get_addr() locking
net_if_lock() should be called only after iface pointer is verified not
to be NULL, otherwise we can end up dereferencing NULL pointer in
certain corner cases.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-07-14 09:37:14 +02:00
Jordan Yates 83b1a983a9 net: lib: tls_credentials: earlier initialisation
The TLS credentials libraries are purely software constructs with no
external dependencies, run them immediately after the kernel setup to
allow other initialisation functions to add credentials without the
requirement to run in the back half of the `APPLICATION` priority.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-07-12 14:50:09 +02:00
Chaitanya Tata 69a144210e net: wifi: Add support to handle Wi-Fi NM's in Wi-Fi management
Check if a network interface is managed by a network manager before
falling back to offload API.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-07-11 14:55:30 +02:00
Chaitanya Tata 38fc560f21 net: wifi: Introduce Wi-Fi network managers
This introduces support for Wi-Fi network managers in Zephyr. The
motivation is for the Wi-Fi management layer to work with both
Network managers and offloaded Wi-Fi drivers. The device driver
decides which one to use.

network manager : Apps -> Wi-Fi Mgmt -> Network Manager -> Wi-Fi
interface

offloaded       : Apps -> Wi-Fi Mgmt -> Wi-Fi offloaded interface

Support for multiple network managers has been added, each device can
choose its own network manager and there can be mix and match:

  wlan0 - Offloaded
  wlan1 - Network manager 1
  wlan2 - Network manager 2

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-07-11 14:55:30 +02:00
Chaitanya Tata a132487fec net: wifi: Move Wi-Fi ops to a separate struct
Decouple interface and Wi-Fi APIs, Wi-Fi APIs are common independent of
Wi-Fi offload or implemented natively (This is preparation for
introducing Native Wi-Fi).

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-07-11 14:55:30 +02:00
Keith Packard 40bc3ec346 subsys/net: Increase management stack size for thread local storage
The management thread *barely* fits in 768 bytes of stack; when thread
local storage is in use and TLS variables are also allocated from the same
region, this stack can overflow.

Increase to 800 bytes to leave plenty of room for TLS variables.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-07-10 15:11:15 +02:00
Florian Grandel 4b66680477 net: l2: ieee802154: simplify/fix ACK procedure
Removes redundant ACK state from `struct ieee802154_context` and
simplifies the ACK procedure.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-10 09:29:10 +02:00
Florian Grandel 27bfe68204 net: l2: ieee802154: mgmt: improve association procedure spec compliance
This change introduces test coverage for association request and
response. Based on this coverage, several closely related issues were
found in the association process which cannot be split into separate
changes without breaking the build.

Most notably did the associate and disassociate net_mgmt commands send
already encoded IEEE 802.15.4 MPDUs to L3 rather than L2. L3 treated
them as payload and made L2 wrap them with another LL header/footer
which produced invalid packets.

The tests also enforce better aligment of the association process with
the IEEE 802.15.4-2020 standard:

* Association requests now ask for ACK as required by the standard. The
  fake driver was enhanced to produce ACK packages when requested.
* macPanId and macCoordinator* MAC PIB attributes are set in the right
  order for improved filtering of association responses.
* The coordinator may decide not to assign a short address to the end
  device even when associated. This is now supported.
* The coordinator may or may not use a short address. Coordinators
  choosing not to support short addresses are now supported.
* Updating the association will now remove any previously added short
  address from the hardware filter.
* The short address may no longer be changed by the user while
  associated to a PAN. Only the coordinator is allowed to allocate short
  addresses.
* Validation of outgoing and incoming association request/response
  packets is improved.

All changes are documented by pointers into the spec.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-10 09:29:10 +02:00
Florian Grandel 3d54e975a7 net: l2: ieee802154: association address parsing
Fixes an off-by-one bug in the parsing routine of the coordinator
address when associating via shell command.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-10 09:29:10 +02:00
Florian Grandel 389f6ac81a net: l2: ieee802154: endianness of PAN ID
Fixes an endianness bug in PAN ID assignment.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-10 09:29:10 +02:00
Florian Grandel d7d5a53f36 net: l2: ieee802154: mgmt: improve input validation
Input validation of some of the IEEE 802.15.4 net_mgmt commands was
incomplete and/or inconsistent. This change introduces a consistent
approach to input validation that is easier to follow.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-10 09:29:10 +02:00
Florian Grandel d452ef9863 net: l2: ieee802154: correctly calculate macResponseWaitTime
Calculates macResponseWaitTime and applies it to the association
process.

As the timing calculation re-uses symbol period calculations and other
PHY timing constants previously introduced, these are now shared as
utility functions.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-10 09:29:10 +02:00
Florian Grandel 4edf46d86c net: l2: ieee802154: radio: fix radio utils naming
The IEEE 802.15.4 stack defines radio API helpers that provide
simplified and encapsulated access to radio API features.

These helpers were missing the `_radio_` infix. This infix is introduced
to clearly distinguish between MAC and PHY concerns. While PHY features
may be shared between L2 implementations (including the functions
concerned here), this is not true for MAC features.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-10 09:29:10 +02:00
Florian Grandel 3aa668f3ca net: l2: ieee802154: introduce IEEE 802.15.4-2020 association type
The IEEE 802.15.4-2020 standard introduces an association type field to
support fast association, see sections 6.4.3 and 7.5.2. We do not yet
implement fast association but we introduce the flag to make this
obvious.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-10 09:29:10 +02:00
Florian Grandel 415351f46a net: l2: ieee802154: frag configuration
Minor simplification in the definition of IEEE 802.15.4 Kconfig packet
fragmentation configuration.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-10 09:29:10 +02:00
Marcin Gasiorek 5894bec82f net: pkt_filter: Introduce additional hooks for pkt_filter
The additional hooks provide infrastructure to construct
rules on another network stack levels. Main benefit of this
approach is packets are pre-parsed and e.g. IP filter is
easier to implement. These hooks are equivalent of prerouting
and local_in in linux's netfilter.

Signed-off-by: Marcin Gasiorek <marcin.gasiorek@nordicsemi.no>
2023-07-10 09:27:47 +02:00
Weiwei Guo 631dce5866 net: ethernet: add PTP multicast default MAC address
All except peer delay message in PTP protocol use multicast MAC
address is 01:1b:19:00:00:00

Signed-off-by: Weiwei Guo <guoweiwei@syriusrobotics.com>
2023-07-05 12:35:34 +00:00
Robert Lubos e1964b8a82 net: wifi: shell: Fix unsafe pointer casts
parse_number() helper function accepts long * pointer or the output,
however in several places, an address of a variable of incompatible
type was passed to the function (for example an address of a bool
variable was cast to (long *) and provided to the function). This
could cause memory overwrites or other unexpected behaviour.

Fix this, by defining a helper variable of type long, and use it with
the parse_number() function. Only after successful parsing, the value is
then assigned to the proper destination.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-07-05 11:17:42 +02:00
Seppo Takalo aaa9cedf18 net: lwm2m: Update next event timestamp on PMAX change
When PMAX value is changed, it should update all events.
I believe there is a bug that caused the code only to update
events that are ongoing (to be send).

Now if PMAX changes, next event timestamp is recalculated.

Fixes #59397

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-07-05 11:16:06 +02:00
Florian Grandel 0341d67625 net: l2: ieee802154: readability: one-letter names
This change replaces one letter variable names with considerable
variable spans by much more readable alternatives that ease code
maintenance and help human reviewers to catch semantic errors.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-03 14:09:32 +00:00
Florian Grandel 0d5eba7900 net: l2: ieee802154: readability: f_ctx -> frag_ctx
The f_ctx variable renamed in this change has a considerable variable
span. This makes the code hard to read as the variable name is neither
defined in the IEEE 802.15.4 standard nor can it be deduced from the
variable name.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-03 14:09:32 +00:00
Florian Grandel 805ca4dde6 net: l2: ieee802154: readability: ar -> ack_requested
The 'ar' abbreviation has a well defined meaning in IEEE 802.15.4 which
is NOT the meaning of the local "ar" variable being renamed in this
change (see the comparison to the actual MHR ar field in this change
set).

To avoid confusion, a non-abbreviated variable name is introduced
instead.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-03 14:09:32 +00:00
Florian Grandel 06df0d4a7d net: l2: ieee802154: readability: af -> address_field
The 'af' abbreviation is nowhere standardized in IEEE 802.15.4 and makes
the source code unnecessarily hard to read. It is replaced by a readable
long name.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-03 14:09:32 +00:00
Florian Grandel a7338b33d5 net: l2: ieee802154: readability: LL header length
Several distinct naming conventions existed within the IEEE 802.15.4
stack wrt header length. This change converges to a single naming
convention, the one that is less ambiguous and already most used.

The change also makes the distinction between L2 (link layer/LL) header
length and 6LoWPAN fragmentation header length to avoid confusion.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-03 14:09:32 +00:00
Florian Grandel 48456d32d5 net: l2: ieee802154: rename comp to has_pan_id
This change is in preparation for the newer frame version's more
complex compression algorithm that may compress both, the source
and the destination PAN independently.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-03 14:09:32 +00:00
Florian Grandel 0ce47c7a8d net: l2: ieee802154: readability: buf -> pkt_buf
This change renames buf to pkt_buf in one very specific instance to
distinguish the packet buffer from the frame buffer which is kept in the
same local scope. In all other instances the meaning of "buf" should be
obvious from context, not so here, though

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-03 14:09:32 +00:00
Georges Oates_Larsen ad6fdaf2c2 net: conn_mgr: Bulk convenience functions
To further reduce the need for networking boilerplate in applications,
provide bulk versions of net_if_up, net_if_down, conn_mgr_if_connect,
and conn_mgr_if_disconnect that affect all available / eligible ifaces
at once.

Since it is not intuitive whether these functions should affect ifaces
which conn_mgr is ignoring, these functions take an argument that allows
this to be specified by the application.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-06-30 16:10:23 +02:00
Georges Oates_Larsen b65613e79c net: conn_mgr: Support Auto-Down
To reduce the amount of boiler-plate needed in applications, this commit
grants conn_mgr the ability to automatically take ifaces that have given
up on connecting into the admin-down state.

Tests adjusted as appropriate.

This behavior can be disabled globally by disabling
NET_CONNECTION_MANAGER_AUTO_IF_DOWN, or disabled per-iface using the
CONN_MGR_IF_NO_AUTO_DOWN flag.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-06-30 16:10:23 +02:00
Georges Oates_Larsen f3d75c4c65 net: conn_mgr: Support Auto-Connect
To reduce the need for boilerplate in application code, conn_mgr now
supports an auto-connect feature on all ifaces with connectivity
bindings.

conn_mgr will automatically call conn_mgr_if_connect on any iface with a
connectivity binding that enters the admin-up state, unless the newly
added CONN_MGR_IF_NO_AUTO_CONNECT flag has been set for that iface.

Also adjust automated tests to account for and take advantage of this
behavior.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-06-30 16:10:23 +02:00
Georges Oates_Larsen 8785a9f424 net: conn_mgr: Minor fixes
- Add missing event sleep after taking all ifaces up in
  test_connect_disconnect.
- Add missing event sleep after resetting ifaces in conn_mgr_conn_before
- Fix typo in comment for internal state flags.
- Add missing NET_MGMT_EVENT_BIT to conn_mgr_connectivity event
  definitions.
- Missing net_mgmt.h include in conn_mgr_connectivity.h
- Split conn_mgr_conn iface reset into network and state resets, before
  and after event sleep, so that triggered events do not corrupt the
  state reset.
- Reduce SIMULATED_EVENT_DELAY to 100ms to avoid timeouts on real-time
  targets.
- Use macro for simulated event wait times.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-06-30 16:10:23 +02:00
Marcin Niestroj 40d2240226 net: context: set default offloaded iface during net_context_get()
Set default offloaded interface during net_context_get() call, so that
net_context_recv() can be called before net_context_connect(). There is
already an assumption about using default network interface, so this should
not be harmful.

Fixes: 2c75070360 ("net: sockets: tcp: Fix possible race between
  connect/recv")
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2023-06-29 21:08:05 +02:00
Ajay Parida 69fead1998 net: mgmt: Support for forced Passive scan
Default scan mode is Active. User can force the scan mode to passive
through Kconfig option or using 'passive' option from shell.
Using either of this option will override regulatory settings and
forces all scan channels to be passive only.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2023-06-29 21:05:41 +02:00
Jarno Lämsä 7ae4e24728 net: lib: lwm2m: Use int16_t for signal strength
The signal strength for the connectivity monitor was
defined as int8_t, however this was too small for
LTE RSRP values, which has range [-140,-44].

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

Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
2023-06-28 15:19:34 +02:00
Florian Vaussard 2eb7433f5b net: if: do not remove the solicited-node multicast address if used
Two different IPv6 addresses can have the same solicited node multicast
address, for example when they are derived from the same EUI-64
interface identifier during the auto-configuration process. For example,
an interface with a physical address 70:07:12:34:56:78 can have the
following:
- link-local address FE80::7207:12FF:FE34:5678
- global unicast address 2001🔢::7207:12FF:FE34:5678

Both addresses will have the same solicited-node multicast address
FF02::1:FF34:5678. Currently, if one removes the global unicast address,
the solicited-node multicast address is also removed, leaving the
link-local address out of the solicited-node multicast group. This
breaks some protocols like Neighbour Discovery.

Count how many times the solicited-node multicast address is used and
remove it only if it is not shared by any other unicast address.

Fixes #59683

Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
2023-06-28 06:51:21 +00:00
Florian Vaussard 56e0d8eef3 net: if: split the search loop of net_if_ipv6_addr_rm()
First search for a match, then perform the removal outside the loop.
There is no functional change but this prepares for some future changes.

Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
2023-06-28 06:51:21 +00:00
Florian Vaussard 59880738f5 net: if: prepare net_if_ipv6_addr_rm() for future changes
Move the creation of the multicast solicited node address outside the
loop. There is no functional change but it prepares for some future
changes.

Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
2023-06-28 06:51:21 +00:00
Tommi Kangas f124c0d06a net: lib: coap: Use zsock_ functions
Use Zephyr internal zsock_ calls to remove dependency
to NET_SOCKETS_POSIX_NAMES.

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

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-06-27 12:18:35 +00:00
Chaitanya Tata a71bff7f49 net: wifi: Fix power save timeout data type
This should be an unsigned integer. Also, add a comment to explain this
feature.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-06-27 12:17:26 +00:00
Chaitanya Tata 5aced7130d net: wifi: Use only Wi-Fi interfaces
As this is Wi-Fi shell use only Wi-Fi interfaces, if none are found
fail.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-06-26 16:12:32 +02:00
Chaitanya Tata 91b5b4424c net: wifi: Add support to get and set Wi-Fi as default interface
Add a configuration option to set Wi-Fi as default interface and also
add an API to get first available Wi-Fi interface.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-06-26 16:12:32 +02:00
Chaitanya Tata 7987098497 drivers: wifi: Register Wi-Fi architecture type
Identify the Wi-Fi capability to the networking stack and also the type
of Wi-Fi (Native vs Offloaded), this helps identifying Wi-Fi interfaces
that can be used by applications.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-06-26 16:12:32 +02:00
Chaitanya Tata 2606ba445b net: l2: Add support to identify Wi-Fi interfaces
Wi-Fi is based on L2 Ethernet, so, all drivers are registered as
Ethernet L2, but in order to distinguish true Ethernet and Wi-Fi
devices, add a L2 type within Ethernet.

Also, handle offloaded net devices that also offload Wi-Fi.

This approach is better than adding a new Wi-Fi L2 as that would mean
invasive changes which are unnecessary.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-06-26 16:12:32 +02:00
Seppo Takalo dc7fbc5d2e net: lwm2m: Fix pause and resume on non-closed sockets
Pause and resume functionality was written into assumption
that sockets are closed before resuming.

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

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

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

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-06-26 12:35:29 +00:00
Chaitanya Tata 8042218948 net: wifi: Add a message for unsolicited TWT tear down
This is for TWT tear down by AP.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-06-26 08:35:20 +00:00
Chaitanya Tata a3ab624f5d net: wifi: Add a demarcation print
This helps see the response status and details separately.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-06-26 08:35:20 +00:00
Chaitanya Tata 3be7265737 net: wifi: Fix tear down messages
TWT tear down is a synchronous call, so, once it returns the operation
is done.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-06-26 08:35:20 +00:00
Chaitanya Tata 97bd70fa05 net: wifi: Disable trigger in TWT quick setup
Most AP's are not sending proper HE triggers or stopping triggers after
sometime, so, change the default to non-triggered based TWT.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-06-26 08:35:20 +00:00
Chaitanya Tata 456859a65d net: wifi: Do TWT checks only for setup
For tear down the checks doesn't make any sense, as TWT flow is already
established.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-06-26 08:35:20 +00:00
Florian Grandel a94877b8b1 drivers: ieee802154: cc13/26xx_subg: improve CSMA/CA compliance
Switch the driver to the soft CSMA/CA algorithm as an intermediate
compromise for improved standard compliance (namely expontential
backoff) until true hardware support can be implemented by chaining
radio commands.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-23 09:20:55 +02:00
Armin Brauns 3bef10f398 net: ip: always cancel IPv6 DAD when address is removed
If the address was removed immediately after being added (e.g. because the
interface MAC address is changed on boot), it would remain in the DAD timer
list.

In one scenario, the DAD timeout would eventually fire, causing the
now-removed address to be modified, potentially causing issues that way.

In another scenario, if the interface was immediately brought back up
again with a different link-local address, this new address would reuse the
first address slot on the interface. Starting the DAD process for this new
address would lead to the same address slot being added to the DAD timer
list a second time, causing an infinite list and associated lockup during
iteration.

Always remove the address from the DAD timer list when it is removed from
the interface, not just when DAD fails.

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2023-06-21 16:07:21 +02:00
Jordan Yates 6271f2fa56 net: if: default NET_IF_LOWER_UP at compile time
The `net_if` layer should not be forcing `NET_IF_LOWER_UP` to be set on
all interfaces at runtime. Because `net_init` runs relatively late by
default, this is overriding any control the driver itself may have
performed using `net_if_carrier_on/off`.

Initialise this bit at compile-time instead. As the structure is already
being initialised, this doesn't increase any footprints.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-06-21 09:35:49 +00:00
Seppo Takalo 95cef5f3ab net: lwm2m: Ensure string termination
When writing string data to resources which are string types,
we should count in the terminating character into the data length.

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

Fixes #59196

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

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

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

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

Signed-off-by: Saravanan Sekar <saravanan@linumiz.com>
2023-06-19 09:18:45 +01:00
Florian Grandel f32fae07f2 net: l2: ieee802154: fix endianness bug
The PAN ID in IEEE 802.15.4 frames is little endian while in the
IEEE 802.15.4 context it is kept in CPU byte order.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-17 16:20:21 -04:00
Florian Grandel 267db64f39 net: l2: ieee802154: fix acknowledgment procedure
The ACK procedure had the following issues:

- MAC commands were not acknowledged.

- When the package is a broadcast package the package must not be
  acknowledged.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-17 16:20:21 -04:00
Florian Grandel 7571be3261 net: l2: ieee802154: deprecate NET_L2_IEEE802154_ACK_REPLY
Acknowledgment is mandatory if legitimately requested by the package's
"ACK requested" flag. The L2 layer will have to ensure that compliant
ACK packages will always be sent out automatically as required by the
standard.

For IEEE 802.15.4 compliance, the NET_L2_IEEE802154_ACK_REPLY option is
therefore being deprecated.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-17 16:20:21 -04:00
Florian Grandel f96b620d12 net: l2: ieee802154: properly handle TX HW capabilities
The existing calls to ieee802154_radio_send() and soft MAC ACK handling
were inconsistent and/or not properly integrated with more recent
radio driver capabilities as CSMA/CA and ACK in hardware.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-17 16:20:21 -04:00
Florian Grandel 1ee4d3ed77 net: l2: ieee802154: document L1/L2 sep. of concerns
The method ieee802154_radio_handle_ack() does not belong to the
PHY/radio layer but to the L2 layer. It is a callback called from the
radio layer into the L2 layer and to be implemented by all L2 stacks.
This is the same pattern as is used for ieee802154_init(). The
'_radio_' infix in this function is therefore confusing and
conceptually wrong.

This change fixes the naming inconsistency and extensively documents
its rationale.

It is assumed that the change can be made without prior deprecation of the
existing method as in the rare cases where users have implemented custom
radio drivers these will break in obvious ways and can easily be fixed.

Nevertheless such a rename would not be justified on its own if it were
not for an important conceptual reason:

The renamed function represents a generic "inversion-of-control" pattern
which will become important in the TSCH context: It allows for clean
separation of concerns between the PHY/radio driver layer and the
MAC/L2 layer even in situations where the radio driver needs to be
involved for performance or deterministic timing reasons. This
"inversion-of-control" pattern can be applied to negotiate timing
sensitive reception and transmission windows, it let's the L2 layer
deterministically timestamp information elements just-in-time with
internal radio timer counter values, etc.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-17 16:20:21 -04:00
Florian Grandel ffcae5f029 net: l2: ieee802154: separate CCA and retransmission
The IEEE 802.15.4 standard clearly separates clear channel assessment
from retransmission. This separation of concern was not represented in
the current channel access vs. retransmission implementation which
resulted in considerable duplication of code and logic.

This change removes the duplication of logic and encapsulates the
resulting functions in a private API that may only be used from within
Zephyr's native L2 layer.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-17 16:20:21 -04:00
Florian Grandel 5827066ca9 net: l2: ieee802154: radio: fix csma/ca algorithm
The CSMA/CA algorithm had multiple issues:

- Timing of backoff periods depends on the PHY's symbol rate and other
  PHY-specific settings. We introduce a preliminary solution that works
  with current drivers. A fully standard-compliant long-term solution
  has already been conceptualized but requires further pre-conditions,
  see #50336 (issuecomment-1251122582).

- We enforce the condition defined in the standard that macMinBe must be
  less than or equal macMaxBe.

- According to the standard a CSMA/CA failure should lead to immediate
  abortion of the transmission attempt, no matter how many
  retransmissions have been configured.

- The number of retransmissions was off by one. It is now used as
  defined in the standard algorithm.

- Retransmissions are only allowed when acknowledgement is requested in
  the packet.

- prepare_for_ack() has side effects and must be called before each
  retransmission.

We also replace variables by constants where possible.

The function was renamed as it represents unslotted CSMA/CA and does not
support other CSMA/CA modes. These may be introduced in the future.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-17 16:20:21 -04:00
Florian Grandel f08b70549f net: l2: ieee802154: radio: fix aloha algorithm
The ALOHA algorithm had two minor implementation errors:

- The number of retransmissions was off by one.

- Retransmissions are only allowed when acknowledgement is requested
  otherwise it is to be assumed that the transmission was successful.

- prepare_for_ack() has side effects and must be called before each
  retransmission.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-17 16:20:21 -04:00
Florian Grandel 6bfa52afe5 net: l2: ieee802154: fix CSMA/CA configuration ranges
The allowable ranges of several CSMA/CA-related settings were not
conforming to the standard, see IEEE 802.15.4-2020, section
8.4.3.1, table 8-94 (MAC PIB attributes). This change fixes the ranges.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-17 16:20:21 -04:00
Daniel Leung 1e1ab38bf0 net: syscalls: use zephyr_syscall_header
This adds a few line use zephyr_syscall_header() to include
headers containing syscall function prototypes.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-06-17 07:57:45 -04:00
Ajay Parida 041201b0d1 net: wifi_mgmt: Reject TWT setup till IP address is configured
If a user tries to enable TWT too early in the connection, then we might
enter TWT sleep even before DHCP is completed, this can result in packet
loss as when we wakeup we cannot receive traffic and completing DHCP
itself can take multiple intervals. Though static ip address can be
assigned too. Reject TWT till Wi-Fi interface has
a valid IP address.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2023-06-17 07:56:17 -04:00
Bjarki Arge Andreasen 22152915ab drivers/gsm_ppp: Update existing modules to use PPP L2
This commit replaces the workarounds spread around the
drivers and subsystems with the updated PPP L2
interface.

Signed-off-by: Bjarki Arge Andreasen <baa@trackunit.com>
2023-06-17 07:46:21 -04:00
Bjarki Arge Andreasen df88664864 subsys/net/ppp: Make NET L2 PPP use net_if properly
Currently, the L2 PPP subsystem is not using the network
interface subsystem appropriately. Here are the issues:

1. net_if_up hidden away internally in net L2 PPP
2. net_if_down not used at all...
3. net_if_carrier_on / off is not used, a workaround is
   used instead, which results in duplicated code
4. L2 PPP does not listen for network events, instead
   it needs the workaround callbacks from drivers.
5. The carrier_on workaround is delegated to a complex
   and broken sys work queue item.

This commit fixes all above issues. net_if_up/down and
net_if_carrier_on/off now work as expected. workaround
for carrier_on/off has been removed.

Signed-off-by: Bjarki Arge Andreasen <baa@trackunit.com>
2023-06-17 07:46:21 -04:00
Florian Grandel b224a099fd net: l2: ieee802154: standardize RSSI value
The RSSI value in net_pkt (net_pkt_cb_ieee802154.rssi) was used
inconsistently across drivers. Some drivers did cast a signed dBm value
directly to net_pkt's unsigned byte value. Others were assigning the
negative value of the signed dBm value and again others were offsetting
and stretching the signed dBm value linearly onto the full unsigned byte
range.

This change standardizes net_pkt's rssi attribute to represent RSSI on
the RX path as an unsigned integer ranging from 0 (–174 dBm) to 254 (80
dBm) and lets 255 represent an "unknown RSSI" (IEEE 802.15.4-2020,
section 6.16.2.8). On the TX path the rssi attribute will always be
zero. Out-of-range values will be truncated to max/min values.

The change also introduces conversion functions to and from signed dBm
values and introduces these consistently to all existing call sites. The
"unknown RSSI" value is represented as INT16_MIN in this case.

In some cases drivers had to be changed to calculate dBm values from
internal hardware specific representations.

The conversion functions are fully covered by unit tests.

Fixes: #58494

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-17 07:16:32 -04:00
Mingjie Shen b2c00ec032 net: utils: fix offset used before range check
This use of offset 'i' should follow the range check.

Signed-off-by: Mingjie Shen <shen497@purdue.edu>
2023-06-16 05:46:05 -04:00
Ajay Parida 6002061efe net: wifi_mgmt: Pass address instead of value as pointer
Fix for not getting expected event information at application.
net_mgmt_event_notify_with_info() expects the address
not the value as pointer.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2023-06-13 08:28:43 -04:00
Juha Heiskanen d6c85c2f59 net: coap: CoAP reply handler fix
Fix corner case when client RX request with same token than
own request where it wait responses.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2023-06-13 07:06:08 -04:00
Florian Grandel d451895907 net: l2: ieee802154: fix buffer pointer ref
The uncast reference caused a cbprintf() warning on the console.

Fixes: #59125

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-13 06:58:57 -04:00
Florian Grandel 8d8faae3e7 net: l2: ieee802154: shell: fix printing ext addr
A bug was introduced in one of my earlier commits: The shell does no
longer print the full extended address. Fixes the issue.

Fixes: #59125

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-13 06:58:57 -04:00
Florian Grandel 378f0dd29d net: lib: zperf: fix kernel panic due to invalid thread prio
Compiling an application with CONFIG_NET_ZPERF=y leaving
CONFIG_ZPERF_WORK_Q_THREAD_PRIORITY at its default value would
systematically cause a kernel panic during thread initialization.

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

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

Fixes: #59141

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-13 06:58:15 -04:00
Robert Lubos 8287e56fa3 net: context: Verify that laddr was set before use in connect
In previous patch fixing this issue, I've missed the fact that offloaded
drivers would not set the context->local address, which resulted in a
regression, where the previously introduced assert would hit in
offloaded cases. Not setting laddr is not a problem in case of
offloading, as it's only used in net_tcp_connect() which would not be
reached in this case.

Therefore I propose to remove previous patch to get rid of regression.
As an alternative fix, verify the laddr just before use, so that it is
only checked when native net stack is in use.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-06-12 14:03:04 -04:00
Robert Lubos ad33d03dce Revert "net: context: Fix ambigous pointer check in net_context_connect()"
This reverts commit 22b889e3b4.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-06-12 14:03:04 -04:00
Chaitanya Tata 1b7ef97c31 net: l2: ethernet: Fix IPv6 Kconfig
Function net_if_ipv6_addr_rm is only defined for NATIVE_IPV6.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-06-12 07:40:43 -04:00
Robert Lubos 22b889e3b4 net: context: Fix ambigous pointer check in net_context_connect()
Coverity reported, that laddr pointer used in net_context_connect()
could be passed as NULL to net_tcp_connect() where it could be
dereferenced. This is because the actual setting of laddr to a valid
address structure was only done after
net_sin/sin6_ptr(&context->local)->sin/sin6_addr verification.

In practice though, the aforementioned pointer verification would always
pass, as the bind_default() guarantee that the context->local address is
set to an unspecified address (if it hasn't been set earlier).

Therefore refactor the code a bit: replace the pointer verification
with NET_ASSERT - only to assure that we can catch regression in case
for any reason the behavior of bind_default() changes. This should also
ensure that Coverity no longer reports that laddr is NULL when reaching
net_tcp_connect().

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-06-07 19:43:20 -04:00
Robert Lubos 233524f471 net: ieee802154_mgmt: Fix memcpy to uninitialized pointer location
As since commit bff6a5c, params.dst.ext_addr is no longer assigned with
the ctx->coord_ext_addr pointer, but a endianness swap is included, it
should be assigned with a proper buffer before the memcpy.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-06-07 10:12:18 -04:00
Robert Lubos f9a818cc56 net: websockets: Fix implicit type conversion Coverity warning
Coverity reported potential issues with implicit signed/unsigned type
conversions and potential problems with this. Fix this, by casing the
byte-shifted data variable to uint64_t type explicitly.

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

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

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

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

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-06-07 10:06:29 -04:00
Robert Lubos 7deabaa77b net: tcp: Fix possible double TCP context dereferencing
In case TCP connection is being closed from the TCP stack, due to for
instance retransmission timeout, the stack should also switch the TCP
state to CLOSED. Otherwise, there was a risk of dereferencing the TCP
context twice, for example if the application was in active socket
send(), and tried to reschedule data transmission.

Additionally, make sure that the TCP_CLOSED state handling is a no-op
state - otherwise, there is a risk that if packets keep incoming before
the application dereferences the TCP context on its side, TCP stack
will incorrectly dereference the context for the second time from
within due to current TCP_CLOSED state logic.

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

Signed-off-by: Mark Oude Elberink <mark@oude-elberink.de>
2023-06-06 09:40:52 -04:00
Armin Brauns fdde5bd7ef net: tcp: populate context's local address for incoming connections
`local_addr` would only be initialized if `context->local->sin*_addr` was
non-null. However, since `context` is a fresh context object, `local_addr`
always remains at its initial value of `INADDR_ANY`, which is propagated to
the context by `net_context_bind()`.

By populating `local_addr` using the TCP endpoint, `getsockname()` now
returns the correct local address.

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2023-06-06 09:40:36 -04:00
Seppo Takalo a1cfe983b6 net: lwm2m: Allow overiding of default socket behaviour
In order to support external IP stacks that might have Connection
ID support, the LwM2M engine should allow client to bypass default
behaviour.

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

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

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

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

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

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

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

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

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

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

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-06-03 04:13:46 -04:00
Florian Grandel 4375962399 net: l2: ieee802154: document non-standard ACK feature selection
For IEEE 802.15.4 compliance, the NET_L2_IEEE802154_ACK_REPLY option must
automatically be active if the radio driver does not AUTOACK and inactive
otherwise. No user interaction is required.

Future changes will deprecate this option and replace it by a standard
compliant automatic mechanism.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-02 18:47:59 -04:00
Florian Grandel 1e2133ffa7 net: l2: ieee802154: document non-standard channel page selection
The IEEE 802.15.4 standard does not specify a "Sub-GHz" option.
Therefore this option will be deprecated in the foreseeable future.

Rationale: Selecting PHYs and frequency bands is abstracted by the
concept of channel pages (see IEEE 802.15.4-2020, 10.1.3).

Radio drivers may expose additional configuration options that
specify the low level frequency band, operating mode and other
PHY-specific parameters. Such parameters should be exposed on a driver
instance level, e.g. via devicetree or as runtime options of the driver.
PHY-specific attributes derived from driver settings (e.g. available
channels) can then be announced to L2 w/o the user having to be aware of
any implementation details of the specific PHY.

Future changes will introduce the necessary infrastructure to define
channel pages and other PHY-specific configuration options to
replace this option. New drivers should therefore not rely on this
option.

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

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-06-02 15:13:41 -04:00
Johann Fischer 02129e90d8 net: buf: fix data ref_count offset in generic_data_ref()
This patch fixes commit b70f92e570
("net: buf: keep memory alignment provided by k_heap_alloc and k_malloc").
One-line was overlooked in the above patch and may result in a
cloned net_buf using a data block that has already been freed.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2023-05-31 10:01:40 -04:00
Robert Lubos fa5b706871 net: websocket: Implement websocket_recv_msg timeout
Although websocket_recv_msg function accepts timeout parameter, the
functionality was rather limited, allowing only to either work in
non-blocking manner, or to block indefinitely. Any timeout value
other than -1 (forever) ended up in non-blocking operation.

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

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

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

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

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

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

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

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

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

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

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

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-05-26 09:05:12 -04:00
Florian Grandel a2c6bb9f1c net: l2: ieee802154: move variable declaration to start of block
Variable declarations are moved to the beginning of the block in
which they are visible to ensure consistency with the remainder
of the code base.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-24 16:41:57 +02:00
Florian Grandel 26041dc32b net: l2: ieee802154: fix typos
A few security-related constants contained typos which are
fixed in this change.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-24 16:41:57 +02:00
Florian Grandel ee079495d5 net: l2: ieee802154: enc-only security level removed from spec
The encryption-only security level has been removed from the
spec, see IEEE 802.15.4-2020, 9.4.2.2 Security Level field.

The standard provides the following explanation (ibid):

"This security level is deprecated and shall not be used in
implementation compliant with this standard. Devices that
receive frames with security level 4 shall discard them, as
described in 9.2.4. The counter mode encryption and cipher
block chaining message authentication code (CCM) used allows
trivial changes to the underlaying encrypted data unless
data authenticity is provided, thus using data confidentiality
only is not useful. In the case of TSCH mode, security level 4
allows higher security level frames to be downgraded to
security level 4 frames."

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-24 16:41:57 +02:00
Florian Grandel 0a2d8522e9 net: l2: ieee802154: simple address mode removed from spec
See IEEE 802.15.4-2020, 7.2.2.11 Source Addressing Mode field and
7.2.2.9 Destination Addressing Mode field, table 7-3: The
previously deprecated "Simple addressing mode" was removed
from the spec.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-24 16:41:57 +02:00
Florian Grandel ea6a55afad net: l2: ieee802154: zero-copy encryption
Currently the insertion of an authentication tag requires a memcpy() call
and breaks encapsulation.

This change removes the need for memcpy() and improves the encapsulation
by calculating and reserving the required headspace early on while
keeping insertion where it belongs in the outgoing security procedure.

This is also a preparation for improved standard compliance of the
outgoing security procedure which is scheduled for a later commit.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-24 16:41:57 +02:00
Florian Grandel 315394eb53 net: l2: ieee802154: consistently name authtag length
The naming of variables and arguments containing the authentication
tag length was inconsistent:

* Naming inconsistency between header "length" vs. authtag "size"
  in the same API calls
* "Tag" rather than "Auth[orization ]Tag" in external API calls
  which is too generic from a compliance and readability viewpoint.

This is in preparation to zero-copy authentication support.

Almost all call sites will be subject to required structural changes
later on so no relevant git blame noise/history loss will be introduced
by this naming change in the long run.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-24 16:41:57 +02:00
Florian Grandel 32e1213b0c net: l2: ieee802154: improve inline documentation
Over time, some non-standard concepts and extensions were introduced
into the stack (in KConfig, in drivers, in the internal API and into the
implementation) which makes introduction of additional standard-
compliant extensions like TSCH (and others) unnecessarily difficult.

To introduce extensions like TSCH it is required for the IEEE 802.15.4
stack to become more structurally aligned with the standard again which
will be the focus of some of the upcoming preparatory changes.

One way to check and prove standard compliance is to reference the
standard from within the source code. This change therefore introduces
inline references to the IEEE 802.15.4-2020 standard wherever possible.
Deviations from the standard are documented with TODO or deprecation
labels to be addressed in future changes.

In the future, new code introduced to the IEEE 802.15.4 stack should
be documented and reviewed for standard-compliance to avoid further
divergence. Most importantly:
* MAC/PHY configuration (via net mgmt, radio API, devicetree or
  KConfig) should always be directly linked to well-defined MAC/PHY
  PIB attributes if visible to the MAC API or the end user.
* Net management/shell/radio API commands should have a documented
  reference to the corresponding MLME action from the standard.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-24 16:41:57 +02:00
Nils Ruf 97c1d05dec net: allow UDP missing checksum by default
According to RFC768 UDP packets with zero checksum are allowed with IPv4.
Enable this by default.
For example, some routers use zero checksum in DHCP packets.

Signed-off-by: Nils Ruf <nils.ruf@endress.com>
2023-05-23 22:09:47 +02:00
Florian Grandel ca6d552bbb net: l2: ieee802154: fix payload handling
The current implicit MAC payload length algorithm (based on
an otherwise irrelevant footer pointer) produces invalid
(non-standard) values for beacon and command frames.

This change produces standard-conforming MAC payload length
values and simplifies access to payload length.

It would have been possible to fix the current footer pointer
based approach but there are arguments in favor of the new
approach:
- The footer pointer is used nowhere in the current code
  base and makes length calculations rather non-obvious.
- The new approach does not use more memory and is easier
  to understand and use.
- This change is a first step to support of IEEE 802.15.4
  information element (IE) support. At a later stage the
  distinction between MAC payload length and frame payload
  length will be introduced and become relevant to
  distinguish between header and payload IEs. At that point
  the current implicit length calculation algorithm will
  break down anyways.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 16:33:28 +02:00
Florian Grandel 4fcdfab7d9 net: l2: ieee802154: fix beacon filtering
The current IEEE 802.15.4 stack would not accept beacons
unless hardware filtering was active.

This change fixes the bug.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 16:33:28 +02:00
Florian Grandel c5fc0e5577 net: l2: ieee802154: shell: release event cb
The shell command calling the IEEE 802.15.4 scanning procedure
did not properly release its net management event callback.

This change fixes the memory leak.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 16:33:28 +02:00
Florian Grandel cb5ea0ec83 net: l2: ieee802154: always revert channel/pan after scan
Active and passive scanning requires the channel and PAN to
be set temporarily.

This change ensures that the temporary configuration will
be reverted even when the scan is aborted due to an error.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 16:33:28 +02:00
Florian Grandel 8eec8441cd net: l2: ieee802154: release consumed frames
Beacon and command frames are consumed by the IEEE 802.15.4
stack internally and should therefore be released before
returning control to the generic net stack.

This change fixes the resource leak.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 16:33:28 +02:00
Matthias Breithaupt d2163bc0b9 net: DHCPv4: Add option callback
In certain scenarios, it may be necessary to get values of additional
options from the application layer. With this patch, this can be
accomplished by registering a callback with the DHCP client.

This change has been tested using the posix build in qemu.

Signed-off-by: Matthias Breithaupt <m.breithaupt@vogl-electronic.com>
2023-05-22 15:25:40 +02:00
Gerard Marull-Paretas dacb3dbfeb iterable_sections: move to specific header
Until now iterable sections APIs have been part of the toolchain
(common) headers. They are not strictly related to a toolchain, they
just rely on linker providing support for sections. Most files relied on
indirect includes to access the API, now, it is included as needed.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-22 10:42:30 +02:00
Florian Grandel 51108a9ce4 net: l2: ieee802154: test: /w and /wo sockets
This change splits the IEEE 802.15.4 test into two separate
test profiles, one with and one without sockets enabled to ensure
that both configurations work correctly.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 08:06:14 +00:00
Florian Grandel e6c4109e94 net: l2: ieee802154: expose implicit frame assumption
The current IEEE 802.15.4 stack assumes that drivers will
not provide more than one fragment in incoming packages.

This change exposes and enforces the pre-existing assumption
made by the implementation.

So far this is not a limiting restriction as MPDUs with more
than 127 bytes are not supported yet. It will probably have to
be changed as soon as larger payloads (as allowed by PHYs
introduced more recently into the spec) might want to allocate
smaller fragments.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 08:06:14 +00:00
Florian Grandel 66bd007f30 net: l2: ieee802154: security: properly clean up previous session
When changing IEEE 802.15.4 security settings or setting security
to 'none' then the previous session must be cleaned up to avoid
resource leaks.

This change introduces proper clean-up of the security session.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 08:06:14 +00:00
Ajay Parida d47021b2f9 net: shell: Fix for PS timeout param type.
Param type is set to correct type for power save timeout.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2023-05-18 15:14:31 -04:00
Andrei Emeltchenko 303a0af68f net: tcp: Make sure we shift by less then bit width
Shifting "timeout <<= conn->zwp_retries" by more then 63 bits results in
undefined behaviour.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-05-17 19:26:44 +02:00
Krishna T b7cabb72fa net: wifi: Fix typo in event
Wrong macro was copied, this causes the event to fail.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2023-05-16 11:41:43 -04:00
Krishna T 2c129609d0 net: context: Set priority based on DSCP
If a socket has DSCP set then the packets from the socket should also be
marked with appropriate priority in case traffic classes are used in
networking stack.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2023-05-16 13:21:25 +02:00
Krishna T 10f3ca2e1d net: wifi: Add an event for disconnect complete
This is needed for applications that rely on WPA supplicant being
in disconnected state before issue subsequent commands (e.g., issue scan
immediately after disconnect fails, until disconnect is completed).

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2023-05-16 13:21:10 +02:00
Sjors Hettinga a28a656aa0 net: tcp: Avoid double acknowlegding retransmitted data
In the FIN_WAIT_1 any incoming data is dropped, but anknowledged. Add a
check to see if the data is already acknowleged to prevent double
acknowledging of the data and bringing the acknowlegde counter out of
sync. When the acknowledge counter gets out of sync, the connection will
never properly terminate any more.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2023-05-15 15:25:51 +02:00
Lukas Woodtli fb924e2b62 net: lwm2m: Handle CONTINUE in registration message
The continue code is not considered an error in case of
block-wise transfer.

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

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

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

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

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

Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
2023-05-15 09:18:09 +02:00
Ajay Parida e70bb70651 net: wifi_mgmt: Support to provide raw scan data
Support to provide raw beacon and probe response data
to registered application.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2023-05-12 10:50:21 +00:00
Gerard Marull-Paretas f0db892d7b toolchain: add trailing _ to iterable section name
Add a trailing _ to the section iterable name. This is useful, for
example, to implement numeric sorting like this:

SORT(.z_device_LEVEL_?_)
SORT(.z_device_LEVEL_??_)

Without the trailing _ it would not be possible to use the ?? wildcard
without triggering into trigraphs issues, because linker-defs.h header
is included in C files as well.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-12 12:01:10 +02:00
Ravi Dondaputi 0889ceaa4e net: wifi: Display MFP info in scan results
Display MFP info in scan results.

Signed-off-by: Ravi Dondaputi <ravi.dondaputi@nordicsemi.no>
2023-05-12 11:57:13 +02:00
Georges Oates_Larsen 62168b659e net: conn_mgr: connect/disconnect adjustments
Rather than raise error on connect if iface is down, just take the iface
up.

Rather than raise error on disconnect if iface is down, just ignore the
disconnection request.

Adjust tests and documentation accordingly.

This should make the API easier to use for applications and is more in
line with the original L2 agnostic connectivity RFC.

Also replace some instances of net_if_flag_is_set with
net_if_is_admin_up, which is cleaner and identical in function.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-05-11 12:15:44 +02:00
Georges Oates_Larsen 068dc8ba6f net: conn_mgr: Simplify DAD handling
The current method for handling DAD directly tracks a DAD state for each
iface.

This does not reflect the fact that each individual IP has a separate
DAD state.

This also does not align with the logic in conn_mgr_initial_state, which
instead uses net_if_ipv6_get_global_addr(NET_ADDR_PREFERRED, ...).

Thus, the current approach falsely reports IPv6 ready when DAD adds
the link_addr, and also fails to report IPv6 ready if DAD is disabled.

This commit removes DAD tracking completely, and relies solely on
net_if_ipv6_get_global_addr(NET_ADDR_PREFERRED, ...), fixing both
problems, and simplifying the event tracking.

For consistency, slight modifications to IPv4 handling as well.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-05-11 12:15:44 +02:00
Georges Oates_Larsen 74ba47bed0 net: conn_mgr: Fire events only on connectivity gain/loss
Currently, conn_mgr fires L4_CONNECTED and L4_DISCONNECTED events for
every individual iface that gains or loses connectivity.

After this commit, these events are only fired when the first iface gains
connectivity, and the last iface loses connectivity, respectively.

This is so that applications can rely on conn_mgr as a simple way to
track whether connectivity is available.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-05-11 12:15:44 +02:00
Georges Oates_Larsen b6897c211a net: conn_mgr: Ignore ifaces and L2s
Adds a flag to allow ifaces and L2s to be ignored.

This is so that applictions have better control over what ifaces they
want connectivity management for.

Enabling the flag forces conn_mgr to consider the iface
unready.

Also increase NET_CONNECTION_MANAGER_PRIORITY default value from 0 to 1
so that applications can register SYS_INIT callbacks that fire just
before conn_mgr initializes. This allows ignored ifaces to be configured
before conn_mgr starts, if needed.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-05-11 12:15:44 +02:00
Georges Oates_Larsen 6cda221c53 net: conn_mgr: refactor event logic
In preparation for altering the conditions under which conn_mgr
fires NET_EVENT_L4_CONNECTED and NET_EVENT_L4_DISCONNECTED,
refactor the event logic without changing its behavior.

These changes do not alter the behavior of conn_mgr. They merely change
how that behavior is expressed so that it is easier to understand, and so
that upcoming changes are easier to implement.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-05-11 12:15:44 +02:00
Georges Oates_Larsen 7afca97f9e net: conn_mgr: Add thread-safety
Current implementation does not prevent the net_mgmt thread from
preempting during state change handling and generating more
state changes. Add a mutex to protect internal state of conn_mgr

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-05-11 12:15:44 +02:00
Georges Oates_Larsen ad7e0d3712 net: conn_mgr: Rename flags
Rename internal flags for clarity

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-05-11 12:15:44 +02:00
Georges Oates_Larsen 41d6a9bcec net: conn_mgr: relocate if_get_binding
Relocate conn_mgr_if_get_binding to conn_mgr_private.h so that it
can be used by test suites.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-05-11 12:15:44 +02:00
Georges Oates_Larsen 716c19f7ef net: conn_mgr: Reorganize files
Since conn_mgr is a subsystem rather than a library, relocate it
directly into subsys/net rather than subsys/net/lib/

Rename header files to better match their function.

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

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

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-05-10 11:41:50 +02:00
Robert Lubos ff0fd2d7a7 net: iface: Improve thread safety of net_if_ipv*_maddr_* functions
Provide an extra struct net_if * iface parameter to
net_if_ipv*_maddr_join/leave functions, so that the corresponding
interface context, the mcast address belong to, can be locked for the
operation.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-05-10 11:06:15 +02:00
Robert Lubos 45cb3f9813 net: if: Improve LL address access thread safety
As `net_if_get_link_addr()` returns a pointer to the link layer
structure, some extra protection is needed to prevent its contents from
being changed while accessed. Using the mutex lock associated with an
interface should do the trick.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-05-10 11:06:15 +02:00
Robert Lubos 838a94288e net: if: Rework interface locking
Instead of having a single global mutex, covering, in most cases
unrelated, access to all network interfaces, introduce a separate mutex
for each network interface.

Wherever interface function operates on an individual interface context
data, use local mutex protection instead. The global mutex remains only
to protect access to shared resources (IPv4/6 context pool, timer lists
etc.).

Finally, rework the timer expiry handlers, to prevent interface
functions from being called while the global lock is held (the global
mutex has to be held when iterating over the timer list, as lists are
not thread safe). The reason for this is to avoid possible deadlock
scenario. The global mutex is sometimes being locked, while inside
interface function (protected by a local mutex), so if it was allowed
the other way as well, a deadlock could occur.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-05-10 11:06:15 +02:00
Georgij Cernysiov 464f6f6438 net: l2: ethernet: lldp: prevent slist corruption
LLDP start timer is executed when iface is up
at startup, then once more when iface up event
is received.

When iface is up before net_lldp_init call, then multiple
entries are added to the lldp_ifaces related to the
same iface.

That leads to continuous loop execution within
lldp_tx_timeout.

This commit checks if lldp tx_timer_start is set and
doesn't append new entry into the slist.
The tx_timer_start is set at startup and reset on
down event.

Signed-off-by: Georgij Cernysiov <geo.cgv@gmail.com>
2023-05-10 16:54:44 +09:00
Ajay Parida 7f9ba751e9 net: wifi_mgmt: Handle ps command error
Failure of setting ps param is handled with error string
at user/ app level.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2023-05-09 15:04:00 +02:00
Ajay Parida 49e6b0c256 net: shell: Code cleanup for ps related commands
Setting ps_mode and ps_timeout related changes handled
in single power save op.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2023-05-09 15:04:00 +02:00
Ajay Parida bdef1bad78 net: wifi_mgmt: Configure ps wakeup mode
'ps_wakeup_mode' is used to set the wake up interval
to either 'dtim or 'listen_interval'. By default the
sta wakes up every dtim interval.
With 'ps_wakeup_mode' set to 'listen_interval' sta
will wake up for every listen interval period configured.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2023-05-09 15:04:00 +02:00
Ajay Parida 68403669c6 net: wifi_mgmt: Configure listen interval
listen interval is the time periods the STAs may be in idle
without listening beacons.
By default STA wakes up for every DTIM period.
If listen interval based power save is used
STA uses configured listen interval period(default 10
beacon intervals) to wake up.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2023-05-09 15:04:00 +02:00
Ajay Parida bdec033889 net: shell: Display TWT response details
Show TWT response parameters details.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2023-05-09 09:24:30 +02:00
Krishna T 2b48c92742 net: wifi: Fix TWT interval
As we are using a generic validation function for limits, due to data
type mismatch the check for TWT interval overflow and fails.

Fix the data type and accordingly the maximum value in the help.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2023-05-09 16:24:10 +09:00
Dmitrii Golovanov 4694b15605 net: pkt: Fix possible NULL dereference at net_pkt_cursor_operate()
Fix possible NULL dereference at net_pkt_cursor_operate() and
resolve 'Dereference after null check' warnings from the Coverity
static code analysis.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2023-05-08 17:40:41 +09:00
Piotr Jasiński e010dcee5d net: update tfm dependency for psa
TFM is not the only provider for PSA API, which means
the PSA config shouldn't depend only on it.

Signed-off-by: Piotr Jasiński <piotr.jasinski@nordicsemi.no>
2023-05-08 10:23:18 +02:00
romain pelletant 75dd2c9904 net: lwm2m: use path as block context retrieval
Replace block context retrieval using object path instead of token.
Update block context structure
Fix issue #57165

Signed-off-by: romain pelletant <romain.pelletant@fullfreqs.com>
2023-05-03 10:01:37 +02:00
Robert Lubos d15f8e6337 net: shell: Print new flags with the net iface command
Print new NET_IF_IPV6_NO_ND and NET_IF_IPV6_NO_MLD flags when
the "net iface" command is used.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-04-29 12:24:49 +02:00
Robert Lubos ee1271f23c net: openthread: Disable ND/MLD for OpenThread interfaces
OpenThread networks do not use ND or MLD as they have their own set of
protocols to cover this functionality. So far, the use of OpenThread
with Zephyr relied on disabling those protocols support statically with
Kconfig, which prevented OT interfaces from being used along with other
IPv6 interfaces.

With the new network interface flags, it's now possible to disable ND
and MLD on individual interfaces, therefore disable them for OT
specifically.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-04-29 12:24:49 +02:00
Robert Lubos c349d53150 net: if: Add possibility to disable MLD per interface
Add new network interface flag, which allows to disable Multicast
Listener Discovery protocol from being used on the interface. This
allows to interfaces that do not support ND (like OpenThread) to
coexist with other IPv6 interfaces.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-04-29 12:24:49 +02:00
Robert Lubos c43c408783 net: if: Add possibility to disable ND per interface
Add new network interface flag, which allows to disable Neighbour
Discovery protocol from being used on the interface. This allows to
interfaces that do not support ND (like OpenThread) to coexist with
other IPv6 interfaces.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-04-29 12:24:49 +02:00
Krishna T 30efd04060 net: Make net_mgmt queue timeout configurable
This helps us work with low queue depth of network management queue in
case the we have high rate events.

Fixes https://github.com/zephyrproject-rtos/zephyr/issues/56595 .

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2023-04-28 10:35:27 -05:00
Ajay Parida a004a85ccf net: shell: Check connection & capabilities in any TWT operation
Connection status & AP capabilities checked before any TWT operation
is initiated.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2023-04-27 09:52:00 +02:00
Dmitrii Golovanov 560b777fa8 net: dhcpv4: Fix NULL dereference at dhcpv4_create_message()
Fix dhcpv4_create_message() dereferenced NULL return value from
net_pkt_alloc_with_buffer() in case of no memory available.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2023-04-26 20:07:04 +02:00
Dmitrii Golovanov f7331e0d66 net: ipv4: Fix fragmented packet NULL dereference possible
Fix net_ipv4_send_fragmented_pkt() dereference of NULL return value
from net_pkt_get_data() possible with non contiguous packet data.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2023-04-26 14:34:23 +02:00
Ryan McClelland b19c8fc3bc net: ip: net_shell: fix double-promotions warnings
Double promotion warnings are generated with the flag -Wdouble-promotion

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2023-04-26 12:58:36 +02:00
Kumar Gala 0090ad718a net: Fix build issues with arm-clang
The arm-clang compiler/linker does not optimize away unused function
symbols and thus will error if symbols that are referenced are not
defined.  To fix this add needed ifdef'ry.

Build various network samples that utilize ethernet but don't have
CONFIG_NET_PROMISCUOUS_MODE will get a link error for:

	Error: L6218E: Undefined symbol
	net_mgmt_NET_REQUEST_ETHERNET_SET_PROMISC_MODE
	(referred from ethernet.o).

Fix by adding ifdef protection around promisc code.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-04-25 19:59:06 +02:00
Ajay Parida 5c023fbbb9 net: wifi_shell: Updated TWT flow id range
TWT flow id is of 3 bit value(maximum mnumber of flows
supported is 8). Flow id range limited to 0 to 7.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2023-04-25 12:21:35 +02:00
Dmitrii Golovanov 6ec39dca6b net: ZWP timeout explicit type on bit shift calculation
Fix tcp_send_zwp() retransmission timeout calculation to avoid sign
extension on bit shift operation: the uint16_t value was implicitly
promoted to 32-bit signed type with sign extension to uint64_t.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2023-04-25 12:19:45 +02:00
Hein Wessels 2689e16670 net: sntp: support building without NET_SOCKETS_POSIX_NAMES
Fixes the compiler error that occurs when attempting to build
the SNTP library with CONFIG_NET_SOCKETS_POSIX_NAMES=n, while
using native_posix.

Closes #57133

Co-authored-by: Chris Friedt <cfriedt@meta.com>
Signed-off-by: Hein Wessels <heinwessels93@gmail.com>
2023-04-24 09:23:17 -04:00
Kumar Gala 301d0c4712 net: buf: cleanup net_buf_pool use of iterable section
Cleanup linker scripts for net_buf_pool section to use the linker
script related iterable section macros.

Also replace _net_buf_pool_list with macro's instead to complete
iterable section usage.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-04-20 10:50:04 +02:00
Pieter De Gendt 7de95b76a6 net: lib: dns: mdns_responder: Fix ipv4/ipv6 address handling
This commit simplifies the arguments for sending dns responses
and fixes an issue where both the ipv4 and ipv6 member of a header
union were accessed.

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

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

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

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

Signed-off-by: Wojciech Slenska <wsl@trackunit.com>
2023-04-19 17:15:12 +02:00
Gerard Marull-Paretas 1eb683a514 device: remove redundant init functions
Remove all init functions that do nothing, and provide a `NULL` to
*DEVICE*DEFINE* macros.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-19 10:00:25 +02:00
Øyvind Rønningstad 31c10f5fe1 lwm2m_senml_cbor_encode.c: Manually edit whitespace
since it crossed the 100 column cutoff, even after clang-format.

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

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

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

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

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

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

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

Signed-off-by: romain pelletant <romainp@kickmaker.net>
2023-04-17 11:29:14 +02:00
Kenny Johansson 353e5f2577 net: tcp: Fix IPv6 TCP MSS issue
Fixes #56657, incorrect TCP MSS calculation for IPv6.

Previously the supported MSS would incorrectly returned as the MTU if it
was less than the MTU, probably to account for the case where
the network interface MTU check returns 0.

New behaviour is to return the supported MSS as MTU minus header length,
using default MTU for this calculation if network interface MTU check
returns 0.

Signed-off-by: Kenny Johansson <wirehell@gmail.com>
2023-04-17 10:17:09 +02:00
Gerard Marull-Paretas 667eeb11fb shell: fix MISRA 5.7 violations on struct shell
MISRA Rule 5.7 requires uniqueness of tag identifiers. Shell is
frequently problematic because many code uses `const struct shell
*shell`. This causes CI noise every time one of these shell files is
edited, so let's update all of them with `const struct shell *sh`
instead.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-14 12:21:08 +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
Luca Fancellu e25d484b6f net: ip: Kconfig for TCP packet allocation timeout
TCP packet allocation timeout is currently 100ms, but there are cases
where it is not enough and as a side effect, the kernel internals are
printing some errors on the log before retrying again, create a
Kconfig parameter to be able to tune this value.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
2023-04-12 10:22:12 +02:00
Gerard Marull-Paretas 0ebe14beb4 sys: util: migrate all files to DIV_ROUND_UP
ceiling_fraction is deprecated, use DIV_ROUND_UP.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-11 12:00:37 +02:00
Krishna T 1e6e20f667 net: wifi: Log failure reason for AP mode
In case AP mode is not supported log the failure reason clearly.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2023-04-07 13:35:28 +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
Daniel Nejezchleb 6898094111 net: shell: Fix shell freeze
Adds clean up after failed ping from shell,
so it does not freeze the output.

Signed-off-by: Daniel Nejezchleb <dnejezchleb@hwg.cz>
2023-03-25 07:49:18 -04: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 dc8f023098 net: ipv6: Fix Kconfig dependencies when native IPv6 is disabled
In case native IPv6 is disabled, Kconfig entries related to native IPv6
stack should not be enabled. Otherwise, circular dependencies can be
created if native stack is disabled, as in case of recent changes in
NET_IPV6_RA_RDNSS option (where a dependency for a native stack module
was enabled).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-03-21 18:11:06 +00: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
Robert Lubos e67374e47a net: tcp: Rework TCP SO_RCVBUF/SO_SNDBUF option handling
SO_RCVBUF option processing at the TCP level was broken. The option
value was only checked once, when the TCP context was allocated. This
made little sense, as at this point the option would not even get a
chance to have custom value. If the user modified the option after the
socket (net_context) was created, it had no effect on the TCP operation.

This commit fixes this, by checking the option value whenever new packet
is processed, so that the configured window size is updated at the TCP
level before we report it in the TCP ACK. In order to achieve this,
introduce a new helper function, to refresh the configured window sizes,
to avoid bloating `tcp_in()` even further.

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
Georges Oates_Larsen 3c6b7dc35a net: dummy L2 for offloaded ifaces
Adds dummy link layer for offloaded ifaces, allowing
ifaces to directly receive l2_enable calls

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-03-20 09:53:25 +01:00
Krishna T 5e6c733006 net: wifi: Use a macro for TWT wake interval
Remove the magic number 255, esp. now that we support 262.144ms.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2023-03-20 09:53:02 +01:00
Krishna T 65aae9cbfb net: wifi: Use micro seconds for precision for TWT intervals
In order to take granular input use micro seconds as input for TWT
intervals, this helps us in providing inputs such as 65.28ms without the
need of using floating points.

This also expands the TWT wake interval range to 262.144ms, earlier as
we want to use uint8, limited to 256ms.

Also, remove the units from the variable names, this is unnecessary and
also avoids doing breaking changes.

Update release notes as this is a breaking change, both type and
variable names are changed.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2023-03-20 09:53:02 +01: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
Mariusz Skamra 5862c8263b net: buf: Factor out net_buf_simple to separate source file
This moves net_buf_simple related code to separate source file.
Having those in separate file makes unit testing easier as simple
network buffers do not use kernel objects, thus can be used
in unit tests without a need for adding any mocks.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-15 10:50:16 +01:00
Mariusz Skamra 4a1d0782cb net: buf: Fix using incorrect logging macro
As there is dedicated NET_BUF_SIMPLE_* logging macros set,
NET_BUF_SIMPLE_DBG shall be used in this place instead.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-15 10:50:16 +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
Ajay Parida 43bd60a13a net: wifi_mgmt: Send TWT sleep status event to app
Send TWT sleep status(sleep/awake) event to the apps registered
for event.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2023-03-14 10:49:30 +01: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
Ajay Parida ce4a809751 net: wifi_mgmt: Updated TWT setup response status
Display message updated for TWT setup response.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2023-03-08 15:33:30 +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
Ajay Parida 55ed46ff6d net: wifi_mgmt: Updated TWT setup response status
Updated TWT setup response status. Removed un-necessary
error strings, enum and values updated as per f/w.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2023-03-03 12:43:43 +01: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
Robert Lubos b6ae195390 net: dhcpv4: Fix potential packet leak in DHCPv4
Packet handlers registered with net_conn API should not use NET_CONTINUE
to report packet processing status. As they register for a specific
local port, it cannot be assumed someone else will handle the packet,
and for net_conn this status is not really handled differently from
NET_OK. Therefore, reporting NET_CONTINUE, and not freeing the packet,
can result in a packet leak.

Too short packets should not really be handled differently from other
malformed packets in DHCPv4 module, therefore report NET_DROP instead of
NET_CONTINUE.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-03-02 10:01:27 +01: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
Krishna T 50c1f857e0 net: l2: wifi: Log packet errors
Log packet errors, this is handy for debugging.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2023-02-24 11:49:41 +01:00
Robert Lubos 43a86b8138 net: tcp: Fix packet processing result reporting
TCP implementation abused the packet processing result reporting
mechanism, by reporting NET_DROP for every packet other than data
packets (which were passed to the application). This simplified the TCP
implementation a bit, as it didn't need to deal with packet releasing.
While technically it worked, it gave incorrect results when it comes to
packet statistics, as a lot of valid TCP packets were counted as
dropped.

This commit fixes this. Each packet that was properly processed by the
TCP stack is not either released at the TCP level, or passed to the
application. In both cases, NET_OK is returned to the network core,
indicating the packet has been properly processed and consumed.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-02-23 09:07:52 +01:00
Stig Bjørlykke b77c234691 net: icmpv6: Initialize dns sockaddr in RA RDNSS
Initialize struct sockaddr_in6 in RDNSS handling to avoid
uninitialized sin6_port or sin6_scope_id.

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2023-02-22 14:26:39 +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
Stig Bjørlykke cb50d49f33 net: icmpv6: Implement IPv6 RA Recursive DNS Server option
Handle RA RDNSS and use the first DNS server fetched. This is needed
when building IPv6 only without static DNS server IP addresses.

This implementation does not handle the lifetime, because the current
resolve logic does not have support for a DNS server lifetime.

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2023-02-21 10:59:18 +01:00
Ajay Parida c69731a281 net: wifi_mgmt: Display TWT setup response status
Display the TWT setup response status.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2023-02-21 10:58:40 +01:00
Jeroen van Dooren d20cceb48e net: ip: net_mgmt: Increase default queue size
There is no reason why the default size should be 2,
because an event is only a combination of

{uint32_t + void*} + info

Using 2 as default causes a high risk of loosing events,
setting the default to a more sensible value of 5 still
restricts memory usage but keeps it more safe.

Signed-off-by: Jeroen van Dooren <jeroen.van.dooren@nobleo.nl>
2023-02-21 10:58:10 +01:00
Jeroen van Dooren a63fcb67b6 net: ip: net_mgmt: Prevent loss of event
The current implementation doesn't handle
re-entrant calls correctly, causing events
to get lost.

Under specific conditions, re-entrancy happens
from event callback done by net_mgmt.c back into
'net_mgmt_event_notify_with_info' causing circular
buffer administration corruption.

These conditions are:

- llmnr_iface_event_handler
- mdns_iface_event_handler
- wifi_mgmt_raise_connect_result_event
- dhcpv4_immediate_timeout uses a workaround

Validated the fix on a Nucleo_H743ZI, using an
sample app.

Signed-off-by: Jeroen van Dooren <jeroen.van.dooren@nobleo.nl>
2023-02-21 10:58:10 +01:00
Krishna T 55802e5e86 net: l2: ethernet: Fix double free
In the case of no ARP entry, the incoming packet is added to the ARP's
pending queue, while ARP is being resolved. Here a reference is taken
by the ARP layer to the packet to avoid it being freed, but the Ethernet
immediately puts down the reference and send the ARP packet to the
driver.

If the ARP request fails for some reason, L2 returns failure to net_if
which then puts down the reference and the packet will be freed as the
reference count is now zero.

But the packet is still in the ARP's pending queue and after timeout
ARP will put down the reference causing double free bus fault (double
free message is only seen if the CONFIG_NET_PKT_LOG_LEVEL_DBG is
enabled, so, a bit hard to debug.

Fix this by clearing the ARP entry and pending queue after taking a
reference and then free ARP packet, IP packets are either freed by ARP
pending queue drain or net_if layer.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2023-02-20 19:45:28 +01:00
Robert Lubos 243af28a2f net: ipv4: Implement fallback to LL address
According to RFC3927, hosts with only IPv4 LL address should still be
able to send packets to destination w/o IPv4 LL address:

   A host with an IPv4 Link-Local address may send to a destination
   which does not have an IPv4 Link-Local address.  If the host is not
   multi-homed, the procedure is simple and unambiguous: Using ARP and
   forwarding directly to on-link destinations is the default route

This behaviour however was not possible with Zephyr, which only allowed
to use IPv4 LL source address for IPv4 LL destinations.

Fix this, by introducing a final fallback (only if IPv4 autoconf is
enabled), to select IPv4 LL address as a source address if no other
address is available.

Additionally, modify the ARP routine a bit if IPv4 LL address is in use.
There's no really point to forward the packet to gateway if IPv4 LL
address is used, as such addresses are not routable. Instead, try to
find the peer in local network in such case.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-02-20 11:19:14 +01:00
Jonathan Rico 3a9c825bab Net: Bluetooth: add enough room to user data
We need to make sure the user_data of the network buffer has enough room to
store the L2CAP metadata.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-02-20 09:53:51 +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
Jani Hirsimäki f21051b728 net: iface: bypassing IP stack with SOCK_RAW sockets
Bypass the IP stack and go directly to L2 with
SOCK_RAW/IPPROTO_RAW sockets in net_if_send_data().

Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>
2023-02-20 09:52:39 +01:00
Krishna T 92aa0e8ab6 net: shell: Log missing Ethernet errors
These error counters are helpful for data path debugging.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2023-02-20 09:51:23 +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
Ravi Dondaputi 1c547580e4 wifi: shell: Print beacon interval and DTIM period
Print beacon interval and DTIM period as part of Wi-Fi
status output.

Signed-off-by: Ravi Dondaputi <ravi.dondaputi@nordicsemi.no>
2023-02-20 09:46:34 +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 a28dba2503 net: ip: 6lo: Fix corner case with packet format after IPHC
IEEE802154 drivers expect, that a complete 802.15.4 frame fits into a
single net_buf provided in a net_pkt.

There is a corner case with header compression when this could not be
the case. If the IPv6 packet before IPHC exceeded 802.15.4 MTU, it'd
consist of several net_buf's. This was not an issue, if the IPv6 packet
after header compression still required fragmentation, as the
fragmentation module took care of formatting individual net_buf's
properly.

For short range of packet sizes however this was no the case. The IPv6
packet, after header compression, might not require fragmentation any
more. As the IPHC logic only modified the IPv6 header part, by trimming
the buffer in front of the net_buf, such a packet would still consist of
two net_bufs, even though it should fit into a single 15.4 frame. Such
packet was passed to the driver, causing the driver to send only part of
the packet, from the first net_buf.

Fix this, by using net_pkt functions to manipulate the packet, instead
of operating on net_buf directly. net_pkt_pull() will not trim the
buffer in front, but rather move the entire packet content to the front.
On the other hand, net_pkt_compact() will assure that there's no gaps in
the net_bufs. In result, packets that do not require fragmentation,
should be placed into a single net_buf, as expected by drivers.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-02-19 20:33:36 -05:00
Robert Lubos 05ca67c9ba net: ipv6: mld: Don't attempt to send a MLD query if iface is down
Simply return early returning respective error.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-02-08 11:26:42 +01:00
Robert Lubos e8803ddaae net: dhcpv4: Do not proceed with DHCPv4 when interface is down
It should be possible to configure/initialize the DHCPv4 for an
interface when the interface is down, the DHCPv4 however should not
proceed with the procedure in such case.

Add a simple check to prevent DHCPv4 from sending packets when interface
is down. As the module registers to the NET_IF_UP event, the procedure
will be restarted when the interface goes up.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-02-08 11:26:42 +01: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
Ryan Erickson d19e99b6d7 net: DHCPv4: Filter NAK during requesting state
During the requesting state, ignore NAKs from any
non-requesting server.  This gives the requesting
server a chance to ACK the request.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2023-02-08 19:05:13 +09: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
Robert Lubos f39ba57474 net: ipv4: Fix subnet mask setting when autoconf is used
When IPv4 autoconf is enabled and IPv4 LL address is configured on an
interface, the subnet mask should be updated accordingly, otherwise it
can lead to unexpected behaviour (like for example not identifying peer
LL address as a part of the same subnet).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-02-06 10:10:54 +01:00
Krishna T 8069d47c5e net: pkt: Allow zero payload for non-IPv4/v6 frames
For socket families that are niether INET/INET6 e.g., PACKET, we cannot
estimate header length, so, if the payload is zero as well, networking
stack drop the packet.

Instead, allow for zero header + payload packets and let L2 take care of
handling them, for some L2's this is still a valid frame.

E..g, In case of Wi-Fi this is sent as 802.11 Header + LLC Header
(no payload).

Add unittests for both AF_INET + Zero payload and AF_PACKET + Zero
payload.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2023-02-06 10:04:03 +01: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
Armin Brauns 22430ef8c4 net: ipv6_nbr: count outgoing ND packets as sent ICMP packets
This mirrors the behaviour of MLD packets, the only other ICMPv6 subtype
that is tracked separately.

Inbound ND packets are already counted as received ICMP packets by way of
going through the ICMP receive path.

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2023-02-03 02:25:14 +09:00
Armin Brauns abd4dd4cc5 net: ipv6_nbr: don't count incoming Neighbour Advertisements in sent stats
This caused outgoing MAC address lookups to count as one received and two
sent Neighbour Discovery packets, when it's really one sent Neighbour
Solicitation and one received Neighbour Advertisement.

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2023-02-03 02:25:14 +09:00
Robert Lubos e540a98331 net: shell: Validate pointer provided with net pkt command
The net_pkt pointer provided to net pkt commands was not validated in
any way. Therefore it was fairly easy to crash an application by
providing invalid address.

This commit adds the pointer validation. It's checked whether the
pointer provided belongs to any net_pkt pools known to the net stack,
and if the pointer offset within the slab actually points to the
beginning of the net_pkt structure.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-02-03 02:14:32 +09: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
Andrei Emeltchenko 8e72f117e3 net: ieee802154: Remove unneeded check
Fixes dead code warning. At this point we have already checked for
broadcast and it is set to false.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-01-27 10:38:49 -06:00
Andrei Emeltchenko 3c8c903a2d net: ieee802154: Fix dereference before NULL check
Fixes dereference of sec_ctx->level before checking sec_ctx for NULL.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-01-27 10:38:49 -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