Commit graph

5605 commits

Author SHA1 Message Date
Tomi Fontanilles 3efdbe6c0c modules: mbedtls: rename CONFIG_MBEDTLS_MAC_*_ENABLED and rm duplicates
Remove the `_MAC` part because those Kconfig options enable only hash
algorithms, nothing MAC-related, and the `_ENABLED` part to align the
naming to the Mbed TLS defines (plus we don't need such a part).

As a bonus, enabling SHA-256 does not automatically enable SHA-224
anymore.

See the migration guide entries for more details on the practical
changes.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-05-29 08:39:26 +02:00
Ravi Dondaputi 9e38bcc173 wifi: utils: Get correct channel count
When channel range is configured in scan params, get the
channel count from `chan_idx` instead of taking a difference
of start and end of the channel range. The `difference` method
fails in case of 5GHz band since channels may not be consecutive
numbers.

Signed-off-by: Ravi Dondaputi <ravi.dondaputi@nordicsemi.no>
2024-05-29 07:32:09 +02:00
Yong Cong Sin bbe5e1e6eb build: namespace the generated headers with zephyr/
Namespaced the generated headers with `zephyr` to prevent
potential conflict with other headers.

Introduce a temporary Kconfig `LEGACY_GENERATED_INCLUDE_PATH`
that is enabled by default. This allows the developers to
continue the use of the old include paths for the time being
until it is deprecated and eventually removed. The Kconfig will
generate a build-time warning message, similar to the
`CONFIG_TIMER_RANDOM_GENERATOR`.

Updated the includes path of in-tree sources accordingly.

Most of the changes here are scripted, check the PR for more
info.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-28 22:03:55 +02:00
Seppo Takalo 4049e17c62 net: lwm2m: Fix null dereference when post-write cb is set
When opaque resources have post-write callback set, but
the write is not a Block-Wise write, there is no block_ctx
and the code causes null pointer dereference when calculating
the offset of the data.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-05-28 18:54:31 +02:00
Jukka Rissanen 3f96a87d1c net: dns: Fix resolver debug print
Make sure that we are not trying to print NULL pointer string.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-28 17:49:59 +02:00
Jukka Rissanen 74f9a1c482 net: sockets_service: Add build check for using zephyr libc
Add checks to make sure that we are not trying to use the socket
service library with eventfd if CONFIG_POSIX_API is not set and if
using native_sim based board. The reason is that we should always
use zephyr libc based eventfd implementation instead of host libc one.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-28 17:49:59 +02:00
Jukka Rissanen aa458a279a Revert "net: sockets: Check eventfd errors better"
This reverts commit b56297bf16
because it is causing problems when using native_sim and not
having CONFIG_POSIX_API set.

The proper fix is to set CONFIG_POSIX_API when using eventfd
and native_sim so that picolibc is used instead of host libc.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-28 17:49:59 +02:00
Robert Lubos 87bacf378d net: l2: ethernet: arp: Fix ARP probe target HW address matching
According to RFC3927 and RFC5227, an ARP probe target HW address should
be set to all-zeroes:

"The 'target hardware address' field is ignored and
SHOULD be set to all zeroes."

Hence, we should allow the ARP probes to have all-zeroes target HW
address as well.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-05-28 17:49:03 +02:00
Jordan Yates 251ddf0ab5 net: l2: ethernet: arp: improve debug output
Improve the ARP debug output by printing:
 * Sending ARP query
 * Queuing packets due to pending ARP query
 * Receiving ARP query response

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-05-27 08:16:22 -07:00
Jukka Rissanen 2a16f4d2bc net: dns: responder: No need to double the socket count
The socket allocation count was incorrectly calculated as
we have only one socket per listened port.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-27 05:01:28 -07:00
Jukka Rissanen ecda6b190f net: dns: The DNS_EAI_ALLDONE is not an error
If DNS_EAI_ALLDONE is returned, it indicates that the request
was done and should not be considered an error.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-27 05:01:28 -07:00
Marcin Niestroj c6fd2a1ddf net: dns: don't request address in recvfrom()
Source address is not used anywhere, so don't request it with recvfrom()
API.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2024-05-24 07:48:17 -04:00
Robert Lubos 1e3f14476b net: tls_credentials: Add missing base64.h header inclusion
base64_encode() was used w/o including the base64.h header. This commit
fixes it.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-05-23 07:47:41 -04:00
Jordan Yates 0f56974c9d net: lib: dhcpv4: goto INIT on IF down, not RENEWING
When the interface goes down, the safest thing to do is to return to
the INIT state, as there is no guarantee that any state is preserved
upon the interface coming back up again.

This is particularly the case with WiFi.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-05-22 21:34:44 -04:00
Ravi Dondaputi d8c89f2b08 wifi: shell: Support configuration of timeout in connect command
Add support for configuring timeout in `wifi connect` command.

Signed-off-by: Ravi Dondaputi <ravi.dondaputi@nordicsemi.no>
2024-05-22 13:46:40 -05:00
Jean-Nicolas Graux c2f65cddfc net: gptp: fix race condition on timestamp callback
If time aware system has more than 1 gptp port, because there is only
one boolean to handle callback registering, a race condition can occur
for instance in case 2 master ports are waiting for a timestamp following
sending of sync message. More in details, callback may be unregistered
by port 1 while port 2 is waiting for timestamp event.

The issue is solved by declaring as much as boolean and struct
net_if_timestamp_cb as the number of declared ports
(=CONFIG_NET_GPTP_NUM_PORTS).

Signed-off-by: Jean-Nicolas Graux <jean-nicolas.graux@st.com>
2024-05-21 16:49:05 -04:00
Jean-Nicolas Graux 64aa577c92 net: gptp: fix rate_ratio in gptp_mi_set_ps_sync_cmss()
Setting a ration of 0 breaks the computation of scaled_rate_offset
in gptp_md_follow_up_prepare().

According to IEEE802.1AS 10.2.2.3.9, when sent by clock master
entity, rate_ratio shall be equal to gmRateRatio. But since
in gptp_md_follow_up_prepare(), in case we are the grand master
clock, we take the assumption that clock source is the local clock,
we may set this ratio to 1.0.

Signed-off-by: Jean-Nicolas Graux <jean-nicolas.graux@st.com>
2024-05-21 16:49:05 -04:00
Jean-Nicolas Graux cec4818fde net: gptp: do not run clock master sync send SM if we are not the GM clock
Without this patch, in case time aware system is grand master capable
but is not the grand master clock and behave as a bridge so that it
shall ONLY relay SYNC and FUP messages from slave port to master port(s),
SYNC and FUP are mistakenly generated by ClockMasterSyncSend state
machine.

This patch only call ClockMasterSyncSend state machine in case a Grand
Master clock is present and is this time aware system.
This check is not described by IEEE802.1AS. Instead, according to
10.2.9.3, the SiteSyncSync state machine shall not take into account
information from ClockMasterSyncSend in case this time aware system is
not grand-master capable. Current implementation of ClockMasterSyncSend
state machine sends sync indication to the PortSync entities, instead of
sending it to the SiteSyncSync entity. And the SiteSyncSync state machine
does not make any check.

Signed-off-by: Jean-Nicolas Graux <jean-nicolas.graux@st.com>
2024-05-21 16:49:05 -04:00
Jean-Nicolas Graux c2cd0fe3ed net: gptp: fix again computation of follow up correction field
Commit 413eceeddb ("net: gptp: fix follow_up message correction_field")
breaks computation of follow up correction field in case time aware system
is not the grand master clock but behave as a transparent clock which relay
sync and follow-up messages from one slave port to one or several master
port(s). In this case, according to IEEE802.AS 11.1.3 and 11.2.14.2.3,
md sync send state machine shall compute the sum of link propagation delay
and residence time, expressed in grand master time base. Then this quantity
shall be added to last received fup correction field to build value of
correction field. This patch checks whether time aware system is the grand
master clock or not, and computes value correction field accordingly.

Signed-off-by: Jean-Nicolas Graux <jean-nicolas.graux@st.com>
2024-05-21 16:49:05 -04:00
Benjamin Lindqvist ed025b2f04 net: lib: coap_client: observe-related fixes
An earlier pull request implementing observe support was merged too
hastily. It had a few issues:

1. The predicate for whether a request should be marked not ongoing was
wrong (it checked ret != 0 instead of ret < 0)
2. Without observes in mind, MID-based deduplication is not a required
feature. Deduplication was handled implicitly - the exchange would get
dropped after the first response anyway, so duplicate responses would
not get matched to anything. But with observes, there are several
responses in an exchange. This commit adds this.
3. Using coap_request_is_observe(&internal_req->request) in the response
handler requires the whole request to stay in scope for the lifetime of
the observation, which I observed was not always the case. Adding an
is_observe bool to the internal struct improved stability significantly.

With these fixes, GETs with observe option works very well.

Signed-off-by: Benjamin Lindqvist <benjamin@eub.se>
2024-05-21 16:42:38 -04:00
Robert Lubos 0874f609f1 net: ipv6: Fix DAD conflict detection
Filtering out received packets which source address matches one of our
own addresses has broken the duplicate address detection conflict
reporting.

In case Neighbor Advertisement is sent during DAD collision, the source
address of such packet might be set to the address that triggered the
collision. This address would also be set on our interface, marked as
tentative. Therefore in order to make duplicate address detection work,
we cannot filter out packets in case our own address is still in
tentative state.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-05-20 14:26:24 +03:00
Robert Lubos 62a55d03af net: ipv6: Fix RA RDNSS and DNS_RESOLVER interdependencies
A support for RDNSS option should not force DNS subsystem being enabled
in the system, especially that the option is enabled by default. It
should work the other way around - the option is supported only if DNS
was enabled by the user.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-05-20 14:25:44 +03:00
Jukka Rissanen b56297bf16 net: sockets: Check eventfd errors better
With native_sim, this error is seen a lot when socket
service API is used.

  <dbg> net_sock: get_sock_vtable: (net_socket_service):
    Invalid access on sock 3 by thread 0x807a8e0 (net_socket_service)

If we just ignore the error, then we might get into forever
loop which is not good. So if this happens, mark the eventfd
fd as not pollable to basically ignore the eventfd support in
this case.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-20 14:25:44 +03:00
Jukka Rissanen 3f1bd6b29e net: sockets: Add extra debug print for invalid socket access
Print also thread name when printing socket access error.
This helps debugging what thread caused it.
Lowering the Error to Debug as we could be missing vtable
for example for eventfd descriptors, this is easily seen when using
socket service API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-20 14:25:44 +03:00
Jukka Rissanen d5cd41a0fe net: llmnr_responder: Convert LLMNR responder to use socket service API
Instead of using net_context API directly, the LLMNR responder is
changed to use the socket service API. This allows DNS access
for offloaded sockets and can lower overall memory consumption.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-20 14:25:44 +03:00
Jukka Rissanen 94433b9ce2 net: mdns_responder: Convert mDNS responder to use socket service API
Instead of using net_context API directly, the mDNS responder is
changed to use the socket service API. This allows DNS access
for offloaded sockets and can lower overall memory consumption.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-20 14:25:44 +03:00
Jukka Rissanen 9a40066b4f net: dns: Convert resolver to use socket service API
Instead of using net_context API directly, the DNS resolver is
changed to use the socket service API. This allows DNS access
for offloaded sockets and can lower overall memory consumption.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-20 14:25:44 +03:00
Taras Zaporozhets a20e962340 net: if: Fix potential unaligned word access
The input address originates from an RX net_buf which may
be unaligned. Consequently, word access to this unaligned buffer
can trigger an unaligned access exception on certain platforms,
such as the ARMv7 Cortex-A9.

Signed-off-by: Taras Zaporozhets <zaporozhets.taras@gmail.com>
2024-05-18 15:50:37 +03:00
Pete Skeggs f04f8b2422 net: lib: coap_client: Improve cancel function
Improve coap_client_cancel_requests(). Ensure it can be
called from a callback. Report error to waiting callbacks.
Clear active flag.

This is useful when the network becomes unavailable
or prior to disconnecting in order to save power.

Signed-off-by: Pete Skeggs <peter.skeggs@nordicsemi.no>
2024-05-17 10:34:12 +02:00
Ayush Singh 56882e2d91 net: zperf: Fix upload ping timeout error
Fixes remote address for ping before upload. This caused the ping in zperf
upload to timeout as shown in the following output:

```
uart:~$ zperf udp upload 2001:db8::2 5001 10 50 1M
Remote port is 5001
Connecting to 2001:db8::2
Duration:       10.00 s
Packet size:    50 bytes
Rate:           1000 kbps
Starting...
ping 2001:db8::2 timeout
Rate:           1.00 Mbps
Packet duration 390 us
```

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

Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
2024-05-15 17:07:58 +02:00
Seppo Takalo 37f6803833 net: lwm2m: Allow Block-Wise write without callbacks
Allow Block-Wise writes to resources that have enough buffer for
the whole content. Calculate the offset before calling the
content specific write handlers when callback is not set.

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

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

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

Fixes #71351

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-05-15 14:58:15 +02:00
Jukka Rissanen 6d129b2a2d net: http_server: Add support for specifying Content-Type
Allow user to specify the Content-Type header field for the
HTTP response.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-14 20:22:58 -04:00
Robert Lubos 50c523636b net: ipv6: Clear joined flag on all mcast address when operational down
When the network inteface goes operational DOWN (for example cable
unplugged), clear "joined" flag on all registered multicast addresses,
so that MLD report is sent for them when the interface goes back up.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-05-14 18:20:56 -04:00
Robert Lubos 3e046626c1 net: ipv6: Rejoin all solicited node mcast addresses
When bringing interface down, all IPv6 multicast addresses are removed
from the interface. However, when the interface was brought back up,
rejoin_ipv6_mcast_groups() would look only for solicited node mcast
addresses already present on the interface. In result, after going back
up, the interface was missing solicited-node mcast addresses for those
unicast addresses, that were already present on the interface when
bringing up.

As net_ipv6_mld_join() does similar checks to skip MLD when not needed,
we can just skip the lookup when rejoining, and use already defined
join_mcast_nodes().

Additionally, check for IPV6 and NO_ND flags on the interface before
attempting to add the address back, those multicast addresses are not
needed if ND is disabled on the interface.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-05-14 18:20:56 -04:00
Robert Lubos d48da4cfd1 net: ipv6: Fix missing DAD for link-local address
In case a network interface is brought down and back up, DAD was not
performed for link-local unicast address.

This happens because the logic in the network interface code assumed
that DAD for link-local address is triggered when the address is added,
and it's explicitly omited when looping over IPv6 address. This wasn't
the case however when interface was brought back up, as the address was
already present on the interface, hence DAD skipped.

In Linux, the link-local address is removed from the interface when the
interface is brought down. Such approach solves the issue described,
hence implement it in a similar way in Zephyr.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-05-14 18:20:56 -04:00
Jukka Rissanen 1d7970be04 net: context: Do not check our own ports
There is no need to check our own context when going through
the used ports in the system. This prevents error when binding
in some corner cases.

Fixes #72035

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-14 18:19:54 -04:00
Jukka Rissanen 3d1b8c6116 net: shell: Add command to show HTTP server information
The new command is "net http" which shows all services and
related resources defined in the system.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-14 15:51:20 +02:00
Jordan Yates 23ca74b756 convert: use k_uptime_seconds
Replace usage of `k_uptime_get() / MSEC_PER_SEC` and
`k_uptime_get() / 1000` with dedicated function.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-05-14 09:32:01 +02:00
Jukka Rissanen 70ab0e65a5 net: websocket: Add a way to unregister a websocket connection
Doing a normal close for a websocket does not close the underlying
real socket. If we do not have fd for the real socket, then it is
not possible to fully close a websocket connection. As we are allocating
a websocket using websocket_register() in HTTP server use case,
create a websocket_unregister() that will close both the real
socket and the websocket socket.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-14 09:31:37 +02:00
Jukka Rissanen 4d9d0ee64c net: websocket: Ignore error during close if we are disconnected
No need to return an error during a close if we are already
disconnected.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-14 09:31:37 +02:00
Fin Maaß 9bd0170aad net: http: client: mark as unstable
As the http client API is currently used by two applications
(websocket and hawkbit), it should be marked as unstable, according
to the docs:
https://docs.zephyrproject.org/latest/develop/api/api_lifecycle.html

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-05-13 16:02:55 -04:00
Tomi Fontanilles 2d61db9a60 mbedtls: introduce PSA-specific Kconfig file
It is meant specifically for configuration of the PSA crypto library.

The underlying PSA configuration items are guarded by the condition
that a PSA crypto provider must be present, which is the case when
either TF-M is in use or MbedTLS's PSA core is built as part of
the application image.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-05-10 18:24:38 -04:00
Adam Matus 684a28656e net: zperf: Add periodic reporting for upload
Add option for zperf tcp upload that will enable periodic result reporting.
This is useful for monitoring performance swings during a longer session.

Signed-off-by: Adam Matus <adam.matus@nxp.com>
2024-05-10 14:45:48 -05:00
Adam Matus a6ededcc9f net: zperf: Move TCP nodelay socket option
TCP nodelay option is part of zperf upload params, but was not being
set in common zperf_prepare_upload_sock function. Move it there
to align with how other options are set.

Signed-off-by: Adam Matus <adam.matus@nxp.com>
2024-05-10 14:45:48 -05:00
Robert Lubos 0ba6a20896 net: sockets: Move TLS sockets out of experimental
TLS socket have now been in Zephyr for a few years already and are
widely adopted across the codebase. Given above, they should no longer
be considered an experimental feature.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-05-10 14:42:03 -05:00
Konrad Derda 9074c07ae7 net: ipv6: mld: use proper MLDv2 modes
According to the RFC, MODE_IS_INCLUDE/MODE_IS_EXCLUDE codes should be
used while sendling Multicast Listener Reports in response to a query.
When performing a transition between states (e.g., when joining or
leaving a multicast group) CHANGE_TO_INCLUDE_MODE/CHANGE_TO_EXCLUDE_MODE
have to be used.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-05-10 11:44:50 +02:00
Konrad Derda 7f5a481ec7 net: ipv6: mld: remove addition of unspecified source in MLDv2 report
From RFC:
* "source list" is an unordered list of zero or more unicast
addresses from which multicast reception is desired or not desired [...]

It means that there is no need to add any special address to specify
"block all" and "allow all" states explicitly. This commit removes the
unnecessary addition.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-05-10 11:44:50 +02:00
Valerio Setti d068982005 net: tcp: use PSA for SHA256 when BUILD_WITH_TFM
When BUILD_WITH_TFM is enabled we can dispatch hash computation
to TFM. This allows to remove the built-in support of SHA256 from
the non-secure side (if it's not used for any other purpose, of course).

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-05-09 10:27:30 +02:00
Valerio Setti b25f322b73 net: tcp: use CS random generators to generate ISN
Use only cryptographically secure random number generators for ISN.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-05-09 10:27:30 +02:00
Valerio Setti e6281c9d21 tls_credentials: remove TinyCrypt implementation of digest_raw
Moving toward the adoption of PSA crypto APIs, TinyCrypt is going
to be deprecated so we can remove it in favor of newer APIs.

Moreover tls_credentials is mostly meant to store data in the
protected storage meaning that there is a TFM implementation
providing this service. The same TFM can of course be used to
compute sha256 hashing thus saving memory footprint on the NS
side by removing TC.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-05-08 22:14:19 -07:00
Valerio Setti 34c4b54473 net: tls_credentials: use PSA to compute SHA256 when BUILD_WITH_TFM
When using the TLS_CREDENTIALS_BACKEND_PROTECTED_STORAGE there is
BUILD_WITH_TFM enabled which means that we can take advantage of
TFM (thorugh PSA interface) to compute the SHA256 hash.

This removes the need for the built-in implementation of
mbedtls_sha256() on the non-secure image (unless it's used somewhere
else, of course) and therefore it helps in reducing the memory
footprint.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-05-08 22:14:19 -07:00
Robert Lubos 6551e6f5ba net: arp: Add support for gratuitous ARP transmission
Add support for gratuitous ARP transmission by Zephyr network stack.
This allows to prematurely fill the peer ARP table, so there's no need
to send an explicit request when peer needs to send an actual packet.

The gratuitous ARP is send when the network interface is brought up
(joins the network) or a new IP address is added. The gratuitous ARP
request is also sent periodically, with a configurable interval time.
The gratuitous ARP should also be sent whenever MAC address of the
interface is changed, but as Zephyr only allows to do this when
interface is down, this is already covered by the first case (interface
brought up).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-05-08 16:09:31 -04:00
Jukka Rissanen f9ac565f12 net: shell: Pretty print websocket output
Fixing the websocket command output to align the fields and
printing interface index instead of a pointer value.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-08 15:02:16 -05:00
Jukka Rissanen 85e9b0b274 net: websocket: Add socket statistics collection
Add socket obj_core support to websocket so that the socket
information can be viewed by "net sockets" command.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-08 15:02:16 -05:00
Jukka Rissanen 3c9513e9cc net: http_server: Add websocket support
After upgrading the HTTP connection to websocket, call the
application registered callback to transfer the ownership of
the socket to the application.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-08 15:02:16 -05:00
Jukka Rissanen dedd30e140 net: websocket: Do not print error in closing
If the other end closes the connection, it is not exactly an
error so downgrade the print to debug level.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-08 15:02:16 -05:00
Jukka Rissanen 13118cf3c0 net: websocket: Create websocket_register() for http_server use
The http_server needs a way to bind a websocket socket to the
upgraded http connection socket. So websocket_register() is used
for that.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-08 15:02:16 -05:00
Jukka Rissanen 97caab6396 net: websocket: Do not use menuconfig
Use normal "config" in order to avoid this error from compliance
check script:

    Found pointless 'menuconfig' symbols without children.
    Use regular 'config' symbols instead.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-08 15:02:16 -05:00
Jukka Rissanen 535d4b40a8 net: lib: http_server: Upgrade from HTTP/1.1 to websocket
Allow connection to be upgraded from HTTP/1.1 to websocket.
This commit does nothing yet with the upgraded connection.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-08 15:02:16 -05:00
Jukka Rissanen 37956465e1 net: lib: http_server: Check HTTP/1.1 Upgrade field
Check what kind of upgrading we are doing and return error
if we receive upgrade that we do not support.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-08 15:02:16 -05:00
Maciej Baczmanski 479e957b79 kconfig: openthread: Fix PSA Key Ref config for RCP architecture
`OPENTHREAD_PLATFORM_KEY_REF` should not be selected for RCP
architecture, as keys are handled on host's side and passed to
device over Spinel, and therefore they cannot be exported
on platform from reference with PSA Crypto API.

Signed-off-by: Maciej Baczmanski <maciej.baczmanski@nordicsemi.no>
2024-05-08 09:25:15 -04:00
Philippe Schumacher 67db6f69f3 net: lwm2m: efficent cbor record data structure
The record data structure is better aligned. Each record saves
24 bytes.

Signed-off-by: Philippe Schumacher <philippe.schumacher@husqvarnagroup.com>
2024-05-08 12:00:57 +02:00
Pieter De Gendt db8bb9ef56 cmake: linker: Use kconfig for iterable section subalign
Replace the hard-coded 4 with the Kconfig symbol
CONFIG_LINKER_ITERABLE_SECTION_SUBALIGN .

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-05-07 18:01:37 -04:00
Seppo Takalo e2ab41b625 net: lwm2m: Fix pull-context on queue mode
Two issues fixed:
When pull-context is created, it does not have to wake up the RD
client context. Ignore the EPERM warning.

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

Fixes #71450

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-05-07 15:10:09 -05:00
Marcin Kajor b571e45d80 net: if: Extend the usage of rejoining the multicast groups
It may happen that the interface is up but not yet running
when we issue the rejoin_ipv6_mcast_groups(). This can be
fixed by calling this function again right after the iface
is set to 'running' state in the notify_iface_up handler.

Signed-off-by: Marcin Kajor <marcin.kajor@nordicsemi.no>
2024-05-07 15:07:14 -05:00
Fin Maaß afff8a16dc net: config: correct dependency of NET_CONFIG*
Corrects the dependencies of NET_CONFIG*

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-05-06 22:51:19 +01:00
Jukka Rissanen 8d077ca66d net: if: Print warning if there are no network interfaces
When calling net_if_get_default(), print a warning if no
network interfaces are found. This helps debugging mysterious
crashes.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Jukka Rissanen 17f852f3cf net: if: ipv6: Do not crash if there are no network interfaces
When trying to get IPv6 prefix, if there are no network interfaces
then the net_if_get_default() will return NULL but we should not
crash at that point but return gracefully.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Jukka Rissanen 2711e12039 net: ipv6: Tailor PE values for Zephyr
Making default preferred time much closer to default valid time
so that the served addresses are much shorter time in deprecated
state where they cannot be utilized. This is important in Zephyr
as there are limited number of IPv6 addresses that can be allocated
to the network interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Jukka Rissanen 39ab0bb002 net: sockets: Fix getsockname() for TCP
The local address used for established TCP socket needs to be
dig out from TCP internals and not from context->local.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Jukka Rissanen c6c021b1f8 net: context: Add helpers for figuring out local endpoint address
We usually cannot use context->local for established TCP connections
because the local address is not updated for TCP if we are bound to
any address. So create helper that try to figure out the end point
addresses.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Jukka Rissanen d47e0dd93e net: Add IPv6 source address selection support
Add support for IPv6 Source Address Selection defined in RFC 5014.
This commit does not add any address selection support to getaddrinfo()
as described in the RFC. The AI_EXTFLAGS symbol and also the ai_eflags
to hints is added but they are not used by the code.
The public/temporary address selection is only done internally by
the net_if_ipv6_select_src_addr_hint() according to flags set by
setsockopt().

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Jukka Rissanen bd496541d7 net: shell: Print ref count information for IPv4 and IPv6 addresses
When printing IPv4 and IPv6 address information in "net ipv4" and
"net ipv6" commands, print also reference count of the IP address.
This is useful for debugging purposes.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Jukka Rissanen f96087e257 net: Add ref counting to net_if_addr struct
Add reference counting to network interface address (for both
IPv4 and IPv6) so that the address is not removed if there are
sockets using it. If the interface address is removed while there
are sockets using it, the connectivity will fail for the said
socket.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Jukka Rissanen c69357a8b4 net: if: Remove IPv6 address when it expires
No need to keep the expired addresses around, just remove it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Jukka Rissanen a7e332dc18 net: ipv6: Add Privacy Extension events to net_mgmt
Add events to be generated when privacy extension is enabled
or disabled, or when allow/deny filter is added or deleted.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Jukka Rissanen c741c524ae net: shell: Add information about IPv6 privacy extension
When executing "net iface" command, print current status of
IPv6 privacy extension if it is enabled in config file.

The "net ipv6 ..." command prints IPv6 privacy extension
information, and can add or delete IPv6 prefix filters.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Jukka Rissanen 0d085d74c4 net: ipv6: Select proper IPv6 source address for privacy extension
If IPv6 privacy extension is enabled, then we need to select
proper public or temporary IPv6 source address when sending the
packet.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Jukka Rissanen ed9a983837 net: ipv6: Initial support for privacy extension
This creates support for IPv6 privacy extensions which is described
in RFC 8981. This will also add API that can be used to add IPv6
prefixes to a allow or deny list privacy extension filter.

The code will create temporary IPv6 addresses from prefixes that
are advertised by Router Advertisement messages. The temporary
IPv6 addresses are then expired according to lifetime and removed.

Fixes #9349

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Jukka Rissanen ce4a13ae79 net: ipv6: Generate an event for deprecated address
If IPv6 address expires and moves to deprecated state, then
send a mgmt event so that listeners can act on it.
One such action is to close a socket bound to that source address
so that the address can be released.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Konrad Derda 5c0d7390f1 net: ipv6: mcast_routing: send MLDv2 reports on changes
This commit adds transmission of MLDv2 reports whenever a multicast
routing entry is added or removed when suitable (it checks if the
given interface itself has joined the group).

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-05-06 22:50:01 +01:00
Konrad Derda 356a42587c net: ipv6: mld: add option to include multicast routes in MLDv2 reports
This commit introduces a new option CONFIG_NET_MCAST_ROUTE_MLD_REPORTS
which appends multiacst routes to MLDv2 reports. These records are
intended to inform reports' recipients about potential listeners on
the other interfaces.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-05-06 22:50:01 +01:00
Konrad Derda 486f895a54 net: ipv6: mld: allow to send unsolicited MLDv2 reports on demand
This commit exposes net_ipv6_mld_send_single() function to be used
by other modules.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-05-06 22:50:01 +01:00
Benjamin Lindqvist 0d14143926 net: coap_client: handle observe requests as intended
The coap_client lib only handled "one-shot" requests properly. This
patch allows it to keep listening for additional responses to a request,
if the request was made with the CoAP OBSERVE option appended.

An API for canceling such requests is also added.

Signed-off-by: Benjamin Lindqvist <benjamin@eub.se>
2024-05-06 17:31:19 +01:00
Jukka Rissanen aecac68179 net: Do not directly use net_buf size field
The size field in net_buf should not be used directly as then
the optional headroom will not be taken into account.
There is the net_buf_max_len() API that should be used instead.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 17:31:09 +01:00
Seppo Takalo 553e5d2e0c net: lwm2m: Move one Kconfig to engine features submenu
Kconfig option to enable object version reporting should
be moved into sub section "Engine features" so
it does not clutter up the main LwM2M menu.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-05-06 14:55:42 +01:00
Chaitanya Tata 2277451e9a hostap: Increase the stack size for net_mgmt
Due to recent changes in hostap to move few buffers from heap->stack (to
improve the reliability of allocations) this has increased the stack
size and with another recent change to increase the max polling sockets
this puts over the 4096 stack size for net_mgmt causing stack overflow.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 14:55:09 +01:00
Markus Lassila dcb3704bc7 net: l2: ppp: Fix terminate requests
When PPP moves to the 'Closing' state it sends up to configured number
of 'Terminate-Request' packets. It only moves to the 'Initial' state,
after running out of retransmits or when it receives a 'Terminate-Ack'
packet.

Signed-off-by: Markus Lassila <markus.lassila@nordicsemi.no>
2024-05-06 14:54:12 +01:00
Jukka Rissanen 4b157b9099 net: lib: http_server: Initial HTTP server support
Original code developed as a GSoC 2023 project by Emna Rekik.

Code refactored in order to provide better bisectability
as the origical commits were not bisectable.

The server supports static and dynamic resources, managed by
HTTP_SERVICE/HTTP_RESOURCE macros.

Fixes #59685
Fixes #59686
Fixes #59688
Fixes #59690
Fixes #59670
Fixes #59700
Fixes #59684
Fixes #59693
Fixes #59693
Fixes #59694
Fixes #59699
Fixes #59696
Fixes #59688
Fixes #59690
Fixes #59670
Fixes #59700
Fixes #59685
Fixes #59686
Fixes #59688
Fixes #59691

Signed-off-by: Emna Rekik <emna.rekik007@gmail.com>
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-04-30 13:25:22 +02:00
Robert Lubos 318dcb6336 net: lib: http_server: Add HPACK and Huffman code encoder/decoder
Add HTTP/2 helper libraries to encode and decode HPACK encoded headers,
according to RFC7541.

HPACK string encoding requires to support certain set of Huffman codes,
therefore implement Huffman encoder/decoder as well.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-04-30 13:25:22 +02:00
Chaitanya Tata 09048e0a16 net: ipv6: mld: Fix improper reference drop
In case of successful submission, the reference shouldn't be put down,
this only should done on error cases.

As reference is put down on success, during the buffer unref, no action
is taken due to an uint8 overflow (ref is now 255), so, the buf->frags
isn't cleared properly and the next time the frags is used and when L2
inserts a second frag, the first head frag and next frag are same (due
to buffer re-use) causing an infinite loop in either net_buf_frag_last
or net_pkt_get_len.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-04-30 11:45:38 +02:00
Ajay Parida 1542140e4e net: wifi: Unicast frames statistics
Unicast RX stats
It represents total number of unicast (any type data, action or
any other unicast frames) frames received at firmware level.
The actual frames passed to host will be different as firmware
may drop packets or some packets may be dropped because of
errors.

Unicast TX stats
Transmission side the unicast packets count states the packets
handed over to firmware. The stats taken at firmware level.
Actual packets transmission may vary depending upon various factors.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2024-04-29 12:17:18 +03:00
Jukka Rissanen 07599e3a53 net: vlan: Add a function to check if interface is VLAN one
We were missing a helper function that can be used to check
whether the given function is the virtual VLAN interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-04-25 11:06:23 +00:00
Ajay Parida 02f4e71633 net: l2: wifi: Fix for wrong return type
The function should return NULL instead of false in case of failure.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2024-04-24 09:52:48 +02:00
Ajay Parida b93002655e net: l2: wifi: Protect processing of nm data
Use lock while accessing nm data.
One of the use case is while setting regulatory, it accesses nm data,
while from some other place also it can be accessed same time.
Protected the nm data processing.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2024-04-24 09:52:48 +02:00
Jonathan Rico b08b1c21a0 net: buf: Disallow blocking allocation in syswq
Work items on the syswq should always run-to-completion.

Override the timeout value to always be K_NO_WAIT.

Allocating with K_FOREVER leads to deadlocks if the freeing also happens
from the syswq. Non-zero timeouts are also not nice for the other users
of the syswq.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-04-23 19:47:24 -04:00
Chaitanya Tata b29dff09fa net: wifi: Check for mandatory args
Even though we are passing mandatory args from the shell registration,
due to use of getopt the check can be bypassed without the hyphenated
options.

So, enforce and fail if mandatory parameters aren't passed through
getopt.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-04-23 19:46:57 -04:00
Chaitanya Tata ddf09c9f58 net: wifi: Add missing return code for failures
This is handy in debugging.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-04-23 19:46:57 -04:00
Andreas Rudolf f531afbd2c net: lwm2m: Add config to always report obj version
Adds a config that enables sending the object version for all objects.

According to LwM2M specification v1.0 and v1.1, non-core object versions
other than 1.0 'must' be provided, while all other versions 'may' be
provided. With specification v1.2, a client 'can always attach Object
Version Information'. Or in other words, it is OK to always report the
object version with all specifications.

Signed-off-by: Andreas Rudolf <andreas.rudolf@husqvarnagroup.com>
2024-04-23 21:26:39 +00:00
Peter Mitsis 02cc127475 linker: subsys: Use Z_LINK_ITERABLE_SUBALIGN
Updates the linker script fragments under 'subsys' to use
Z_LINK_ITERABLE_SUBALIGN for the subalignment instead of
a hardcoded value of 4.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2024-04-20 13:45:25 -04:00
Jukka Rissanen b864cd9053 net: if: Do not add IPv6 address lifetime timer twice to list
The IPv6 address lifetime timers are kept in a slist, but
the code that adds the entry to the list does not check
whether the item is already in the list. This will cause
problems when trying to remove the address from the list.

Normally this is not causing issues, but if the function
net_if_ipv6_addr_update_lifetime() is called multiple times
before the address expires, then the item was added to the
slist multiple times.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-04-19 17:04:17 +00:00
Ravi Dondaputi b45ff98f47 wifi: shell: Support WPA auto personal security mode
Applications need to run a scan to identify the security
mode before attempting the connection which adds to the time
taken for connection to be established.
To avoid the initial scan, support auto security mode which will
enable STA to choose between WPA, WPA2 and WPA3, based on the
network configuration.

Signed-off-by: Ravi Dondaputi <ravi.dondaputi@nordicsemi.no>
2024-04-19 16:40:29 +00:00
Ajay Parida 4d4b304e03 net: wifi_mgmt: Setting RTS threshold
Support to set RTS threshold.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2024-04-18 08:42:29 -07:00
Ravi Dondaputi 0e617a3929 net: wifi: shell: Remove redundant break
Having a `break` statement after `return` is redundant and
needs to be removed.

Signed-off-by: Ravi Dondaputi <ravi.dondaputi@nordicsemi.no>
2024-04-18 08:07:35 -07:00
Ravi Dondaputi 72c81eec3b net: wifi: shell: Correct help text for connect command
Since `NONE` is a valid option for key management in `connect`
command, we should remove the part in help text which says:
"valid only for secure SSIDs".

Signed-off-by: Ravi Dondaputi <ravi.dondaputi@nordicsemi.no>
2024-04-18 08:07:35 -07:00
Konrad Derda 701b6aed4b net: shell: print interfaces per multicast route entry
This commit change a method of printing multicast routes by showing
all interfaces per entry instead of aggregating them by interface.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-04-17 14:39:35 +02:00
Konrad Derda 61dca2b8bf net: ipv6: add multiple interfaces to multicast routing entry
In order to save memory, a single multicast routing entry now
contains configurable number of network interfaces.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-04-17 14:39:35 +02:00
Konrad Derda 97fc5ea597 net: ipv6: check if multicast packet was forwarded
This commit adds a check to determine if the packet wasn't already
forwarded to a given interface.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-04-17 14:39:35 +02:00
Konrad Derda df34742df7 net: ipv6: use ARRAY_FOR_EACH_PTR() for iteration over mcast routes
This commmit changes the way of iterating over multicast routing
entries from explicit for-loop to ARRAY_FOR_EACH_PTR().

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-04-17 14:39:35 +02:00
Brad Kemp 3e2c067010 net: wifi: shell: update wifi ap enable to use get opt parsing
The commit 8256d02d3a introduced
getopt parsing for the wifi connect command
This needs to be updated for the wifi ap enable since ap
enable also uses the same parsing as connect.
The use of getopt removes the parameter ordering restrictions

Signed-off-by: Brad Kemp <brad@beechwoods.com>
2024-04-15 12:53:47 +02:00
Robert Lubos a0f0e55668 net: tcp: Fix FIN with data handling
In case FIN packet included data bytes, Zephyr would ignore the
data. It wasn't passed to the application, and it wasn't considered
when bumping the ACK counter. This ended out in connection timing out,
instead of being properly terminated.

Fix this, by refactoring FIN processing in TCP_ESTABLISHED state.
Instead of handling FIN/FIN,ACK/FIN,ACK,PSH cases separately, have a
common handler when FIN flag is present, and when ACK flag is present
along with FIN. When FIN is present, take any potentially incoming data
into account.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-04-15 12:51:52 +02:00
Seppo Takalo 51d80a9838 net: lwm2m: Allow CoAP block size to be changed
Allow changing the CoAP Block-wise transfers block-size
for subsequent GET requests.

It looks like Leshan switches block size back to its
configured value, if it is smaller.
So even when we send block N=0 with size of 512, Leshan
seem to handle that properly but still asks N=2 with
block size 256(if that is configured).

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-04-12 09:14:36 -04:00
Adam Matus 869d4fc041 net: zperf: Improve shell upload cmd
Minor improvements to usage of zperf_shell upload.
Added common defaults for the upload commands arguments.
Print defaults in cmd help.
Throw warning when user sets baud rate for TCP upload.

Signed-off-by: Adam Matus <adam.matus@nxp.com>
2024-04-12 11:54:49 +02:00
Jukka Rissanen d40abe8c0f net: vlan: Fix net_eth_get_vlan_tag() to check correct interface
The network interface parameter for net_eth_get_vlan_tag() should
be the VLAN interface so use the search loop properly.
Earlier the main interface could be checked.

Add also test cases for this so that we can catch that the func
works properly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-04-12 11:54:33 +02:00
Robert Lubos b292a9e8b5 net: sockets: tls: Add more logging in case of errors
Add more error logs in case of (mostly) mbed TLS errors, so it's easier
to get an initial idea of what went wrong based on logs only. Getting
an information on an actual mbed TLS error code is quite helpful in such
cases.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-04-12 11:54:02 +02:00
Marco Argiolas f0212367dc net: lib: lwm2m: fix formula for expected next block
Block size is a 3-bit value mapping values [0, 6] to powers of 2 in the
range [16, 1024]. Value 7 is invalid.
The previous formula was not working in case the client's preferred size
was 4 (or more) times bigger than the server's.
This commit takes into account also the case the client's preferred size
is smaller than the server's.

Signed-off-by: Marco Argiolas <marco.argiolas@ftpsolutions.com.au>
2024-04-11 14:40:44 +02:00
Jonathan Rico e3ff993000 Network: L2: remove IPSP
Remove IPSP support from the tree.

It has no maintainers, and is regularly broken. The fact that it's
nontrivial to set-up in linux makes it hard to fix reported issues.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-04-11 12:48:50 +02:00
Jukka Rissanen cb7aae6f82 net: dns-sd: Do not use sockaddr struct directly
The "struct sockaddr" should only be used in casts and never
as a standalone variable because it might not have enough
space allocated for all the protocol specific fields.
So refactor the port_in_use() function to reflect that.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-04-10 07:42:42 -04:00
Robert Lubos f77c7a3d05 net: dhcpv4_server: Fix positive error codes returned
errno values are positive, therefore they should be negated when
assigned as return values for net_dhcpv4_server_start().

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-04-10 07:42:21 -04:00
Dominik Ermel 5a0ecb9641 flash: Move dependency on FLASH_PAGE_LAYOUT where it belongs
The commit adds dependency on Kconfig FLASH_PAGE_LAYOUT to subsystems
that really require it:
 FCB, NVS, LittleFS
and removes direct selection from '*.conf' files where no longer
needed.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2024-04-10 10:01:40 +02:00
Jukka Rissanen 85911bcfc1 net: mdns_responder: Avoid joining IPv4 mcast group if iface is down
Check if the interface is down before joining IPv4 mDNS multicast
group. This avoids warning later when the network packet cannot be sent.

Fixes #71121

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-04-10 10:00:49 +02:00
Nick Ward 17abc2743b net: lib: coap: set MAX_RETRANSMIT maximum to 100
Some application environments may need it.

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2024-04-09 20:11:21 +02:00
Robert Lubos eeb527a5da net: Restore the default networking behavior on qemu platforms
Commit e99b5228a1 changed the default
networking behavior on qemu platforms, as the SLIP_TAP driver no longer
selected Ethernet L2. In results, qemu platforms in default
configuration had no network interface to work with.

Fix this, by restoring select for NET_L2_ETHERNET, but this time in
NET_SLIP_TAP. The difference is that SLIP_TAP is a generic driver
config, which could be enabled on any platform, so not changing the
behavior here, while NET_SLIP_TAP is a config dedicated for qemu only,
so it's reasonable to enable all that's needed to get SLIP to work with
qemu by default.

As there were circular Kconfig dependencies, move the respective qemu
configs outside of NET_RAW_MODE if block (as this caused the circular
dependency with ETH_DRIVER_RAW_MODE). Also, remove dependency to
NET_L2_BT, as it made little sense there, and also caused dependency
problems.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-04-09 13:56:08 -04:00
Kapil Bhatt a087a40ac6 net: wifi: Remove constraints for dwell time
There is no limitations for dwell time. Just add
valid condition for positive value. So , it's better
to remove those constraints.

Signed-off-by: Kapil Bhatt <kapil.bhatt@nordicsemi.no>
2024-04-09 14:21:10 +02:00
Robert Lubos 837d09ed9e net: connection: Log an error when running out of contexts
Running out of connection contexts is most likely due to app
misconfiguration, therefore it's useful to get an explicit information
that context allocation failed.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-04-09 11:05:10 +02:00
Georges Oates_Larsen 7fc6ef28d3 net: lib: http: Correct http_client edge-case behavior
Correct various small edge-case behaviors that have been accidentally
introduced in the http_client.

- http_client_req no longer incorrectly returns -ETIMEDOUT on NULL HTTP
  resonse. -ETIMEDOUT is now only returned when the underlying TLS
  socket times out.
- http_client_req now returns -ECONRESET upon incomplete (but non-NULL)
  HTTP response. The request callback is no longer called in this case
  (as with any other error state).
- http_wait_data has been refactored slightly to increase clarity.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2024-04-05 13:35:22 -05:00
Declan Snyder 69e0b03ca9 net: zperf_shell: Fix IPv6 invalid warning
Fix the ipv6 invalid warning always appearing when
a valid ipv4 address is provided.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2024-04-05 18:46:58 +03:00
Jukka Rissanen 4c45884c8c net: tcp: Give a warning to user if packet cloning fails
If the packet cloning fails (can easily happen when working with
loopback interface and when having low net_buf count), then
print a warning to the user. Error could also be possible but
as the situation might correct itself in this case, the warning
should be enough.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-04-05 16:45:32 +03:00
Fin Maaß a1ea9b7351 net: use appropriate sys_randX_get()
use the appropriate sys_randX_get() instant
of always sys_rand32_get().

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-04-05 12:28:46 +02:00
Jukka Rissanen 83d879bb1a net: if: No error if mcast group join fails because iface down
If we fail to join all nodes or solicit node multicast groups
when the interface is down, then there is no need to print an
error message. The groups are automatically re-joined when the
interface comes up.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-04-05 12:19:27 +02:00
Jukka Rissanen 78a0cfbd94 net: shell: capture: Set capture device if user did not use shell
If user created the capture device using the API and not via
the shell, then the device name was not set. Use the default
capture device in this case.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-04-04 17:02:11 +02:00
Jukka Rissanen 2064306d41 net: capture: Generate events when starting / stopping capture
The event NET_EVENT_CAPTURE_STARTED is generated when the
capture is enabled, and NET_EVENT_CAPTURE_STOPPED when capture
is disabled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-04-04 17:02:11 +02:00
Jukka Rissanen 0516ce9311 net: capture: Add capture function that returns a status
The net_capture_pkt() does not return information what happened
to the net_pkt because the packet was always cloned. With cooked
capture we can avoid the cloning in which case we need to know
the capture status in order to unref the packet if needed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-04-04 17:02:11 +02:00
Jukka Rissanen 46cb5c0bd1 net: capture: Add Linux cooked mode capture support
Add support for capturing arbitrary data via the cooked mode (sll)
capture API. The actual packet capture is done using net_capture_data()
function, the packet capture infrastructure does not need any changes.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-04-04 17:02:11 +02:00
Jukka Rissanen 3bd43ea865 net: Implement pseudo a.k.a "any" interface
Allow user to create a kitchen sink pseudo a.k.a any network
interface that one is only able to write to. This might seem
unnecessary, but it is possible to attach virtual network
interfaces on top of this pseudo interface. These virtual
interfaces could then process the data for example for
packet capture purposes.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-04-04 17:02:11 +02:00
Jukka Rissanen 00502a8894 net: Add helper to print the verdict as string
For debugging purposes it would be nice to see the verdict
printed as a string instead of number.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-04-04 17:02:11 +02:00
Jukka Rissanen 9a9f6f3d96 net: dummy: Add support for receiving data
Add a recv callback to dummy API. After this it is possible to
receive data by a dummy network interface. This is only useful
if one attaches a virtual interface on top of the dummy one.
One such example is the cooked mode capture interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-04-04 17:02:11 +02:00
Konrad Derda 377756e0f9 net: ipv6: mld: fix handling of MLD queries
This commit fixes an issue where due to inverted logic (static function
returned 0 on success but the caller expected true/false) the MLDv2
reports were silently dropped.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-04-03 15:30:03 -05:00
Robert Lubos f211cd6345 net: tcp: Deprecate CONFIG_NET_TCP_ACK_TIMEOUT
Deprecate CONFIG_NET_TCP_ACK_TIMEOUT as it is redundant with the
combination of CONFIG_NET_TCP_INIT_RETRANSMISSION_TIMEOUT and
CONFIG_NET_TCP_RETRY_COUNT. The total retransmission timeout (i. e.
waiting for ACK) should depend on the individual retransmission timeout
and retry count, having separate config is simply ambiguous and
confusing for users.

Moreover, the config was currently only used during TCP handshake, and
for that purpose we could use the very same timeout that is used for the
FIN timeout. Therefore, repurpose the fin_timeout_ms to be a generic,
maximum timeout at the TCP stack.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-04-03 15:32:45 -04:00
Jukka Rissanen eff03ca071 net: shell: Add printout when hostname changes
Add hostname changed printout to event monitor. As the name
says, it is generated when the hostname of the device changes.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-04-03 15:40:16 +01:00
Reto Schneider ccc58b8ce5 net: lwm2m: device object: Fix coverage compatibility
Starting with b1d24e425c (net: lwm2m:
device object: optionally store error list in settings), it was no
longer possible to build the code with coverage enabled when the
settings subsystem was disabled.

The build would fail with an error like this:

> subsys/net/lib/lwm2m/lwm2m_obj_device.c:262: undefined reference to
> `settings_name_steq'

This fixes #70923.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
2024-04-03 15:39:49 +01:00
Marcin Gasiorek 9c0b8181f3 net: dhcpv6: Add configurable DUID buffer length
According to the `RFC8415` the length of the DUID is at least 1 octet
up to 128 octets. Now a user can choose buffer length without the need
for source code modification.

Signed-off-by: Marcin Gasiorek <marcin.gasiorek@nordicsemi.no>
2024-04-03 10:28:20 +03:00
Declan Snyder db8a0b4b0c net: ethernet: Include ethernet API in eth_stats.h
eth_stats.h is using ethernet api but not including the header,
it must be working by luck in files that include it after
something else that includes ethernet.h, fix by just including it.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2024-04-02 21:02:25 -04:00
Reto Schneider da676d2e01 net: buf: Include user data when cloning
net_buf_user_data() is supposed to copy any data, which includes the
user data.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
2024-03-29 16:00:39 -05:00
Robert Lubos 8e2722e1ca net: Provide separate configs for TX/RX memory pool for variable bufs
Instead of having a single config specifying the memory pool size for
variable-sized net buffers, have a separate one for TX and RX for better
configuration granularity when optimizing memory usage of the
application.

Deprecate the old configuration but use its value as a default (for now)
for the new configs. This will need to change when the config is
deleted.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-29 15:56:07 -05:00
Kapil Bhatt 6a0e6e4737 net: wifi: Replace numeric values with defines
There should be a particular defines which clarify the
use of that number. So, replacing numbers with defines
in wifi shell.

Signed-off-by: Kapil Bhatt <kapil.bhatt@nordicsemi.no>
2024-03-29 15:08:00 +00:00
Seppo Takalo c62dd778cd net: lwm2m: Fix socket hints for block transfer
Outgoing block-transfers now set the socket hint
to ONGOING as long as the BLOCK1/BLOCK2 header has
MORE flag set to true.
This means as only the last packet in the block-transfer
set the socket hint to LAST or ONE_RESPONSE.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-03-28 16:02:34 -05:00
Chaitanya Tata 159617c8f6 net: wifi: Fix the Wi-Fi state check
Once Wi-Fi is associated few parameters like listen interval and
power-save mode cannot be changed. The state for association is
"ASSOCIATED" and not completed. Even after state transitions to
COMPLETE, it can still go back to other states, e.g., PTK/GTK renewal.

Fix the state check.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-03-28 14:47:50 +00:00