Commit graph

6489 commits

Author SHA1 Message Date
Maximilian Deubel
916897f59e lib: tls_credentials: return size even if too big
The simple backend returns the size of the credential,
even if it is too big.
The secure backend should do the same,
our libraries depend on this behaviour.

Signed-off-by: Maximilian Deubel <maximilian.deubel@nordicsemi.no>
2025-03-26 16:22:28 +01:00
Jukka Rissanen
2e3f564a95 wifi: shell: Allow setting band to 0 in connect
The help text for connect says

[-b, --band] 0: any band (2:2.4GHz, 5:5GHz, 6:6GHz]

but it disallows setting band to 0. Change this and allow
band 0 option when doing normal connect. Disallow setting
the band 0 when enabling AP mode.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-03-26 16:22:01 +01:00
Jukka Rissanen
a8da7d652f wifi: shell: Map negative status code to valid status codes
The negative status code is actually the errno which we might
get returned from lower levels. For example if user sets -t
(timeout) option, the -ETIMEDOUT might be returned. In this case
map the errno value to connection timeout status value.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-03-26 16:22:01 +01:00
Jukka Rissanen
92da8cb69f wifi: shell: Return text description of connection error
If "wifi connect" fails, tell user why in textual format.
This helps debugging connectivity issues.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-03-26 16:22:01 +01:00
Tom Hughes
918ae79522 net: mdns_responder: Replace pragma with TOOLCHAIN_DISABLE macro
These macros were recently introduced and replaced everywhere (#84065),
but this was missed.

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-03-26 16:20:26 +01:00
Robert Lubos
8935579d0a net: mqtt: Improve disconnect error notification for MQTT 5.0
As MQTT 5.0 allows to specify the disconnect reason in the Disconnect
packet, use this new feature to improve error notification to the
broker, according to the error guidelines in the MQTT 5.0 spec.
For most cases, a generic arbitrary mapping between errno values and
reason codes is used, however the parser can specify the disconnect
reason code manually to better handle certain corner cases (like invalid
topic alias used).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-03-26 16:19:42 +01:00
Robert Lubos
e9da3b3e0c net: mqtt: Add support for MQTT 5.0 topic aliases
Add support for handling topic aliases received from the broker.
The MQTT client implementation will store received topic for further use
in case consecutive PUBLISH received from the broker contains no topic
but alias only.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-03-26 16:19:42 +01:00
Robert Lubos
1d743fa65a net: mqtt: Add support for MQTT 5.0 AUTH packet
Add support for a new AUTH message introduced in MQTT 5.0.
This is a new mechanism specified by MQTT 5.0, which allows clients and
brokers for enhanced authentication in between CONNECT and CONNACK
exchange. An additional MQTT event (MQTT_EVT_AUTH) was specified which
is triggered when the AUTH packet arrives from the broker.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-03-26 16:19:42 +01:00
Robert Lubos
55e1c10894 net: mqtt: Add MQTT 5.0 support for DISCONNECT
Add support for DICONNECT message specified in MQTT 5.0.
As with MQTT 5.0, the disconnect can now also be initiated by the
broker, it was needed to add decoder support for the message.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-03-26 16:19:42 +01:00
Robert Lubos
2459ffae41 net: mqtt: Add MQTT 5.0 support for SUBACK/UNSUBACK
Add support for SUBACK/UNSUBACK messaged specified in MQTT 5.0.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-03-26 16:19:42 +01:00
Robert Lubos
efd795b066 net: mqtt: Add MQTT 5.0 support for SUBSCRIBE/UNSUBSCRIBE
Add support for SUBSCRIBE/UNSUBSCRIBE messages specified in MQTT 5.0.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-03-26 16:19:42 +01:00
Robert Lubos
c21e64251b net: mqtt: Add MQTT 5.0 support for PUBLISH ACKs
Add support for PUBACK, PUBREC, PUBREL and PUBCOMP specified in MQTT
5.0. As all of these acknowledgment packets have similar format,
introduced a common encoder/decoder to handle ACK packets.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-03-26 16:19:42 +01:00
Robert Lubos
15ad90aceb net: mqtt: Add MQTT 5.0 support for PUBLISH
Add support for PUBLISH message specified in MQTT 5.0. The message
encoder and decoder were updated to support MQTT properties.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-03-26 16:19:42 +01:00
Robert Lubos
6038676b83 net: mqtt: Add MQTT 5.0 support for CONNACK
Add support for CONNACK message specified in MQTT 5.0, along with
property decoders required to decode MQTT properties. Decoded properties
are provided to the application within mqtt_connack_param structure,
accompanying the CONNACK event.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-03-26 16:19:42 +01:00
Robert Lubos
8fe2965500 net: mqtt: Add MQTT 5.0 support for CONNECT
Add support for CONNECT message specified in MQTT 5.0, along with
property encoders required to encode MQTT properties which is a new
concept in MQTT 5.0. Connect and will properties can be specified by the
application in the mqtt_client structure before connecting.

Introduce a helper function which allows to verify whether MQTT 5.0 is
used or not, so that it's still possible to use MQTT 3.1 even if MQTT
5.0 support is enabled in Kconfig.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-03-26 16:19:42 +01:00
Robert Lubos
1eb9a5c241 net: mqtt: Fix helper macro for encoded binary data length
The macro did not take into account the 2-byte binary data length
encoded before the actual binary data.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-03-26 16:19:42 +01:00
Robert Lubos
f31a45f57c net: mqtt: Add Kconfig to select maximum supported MQTT version
It should be possible to select maximum supported MQTT version, so that
for example MQTT 5.0 features can be compiled-out in case they're not
needed.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-03-26 16:19:42 +01:00
Seppo Takalo
05abdf5d0b net: lwm2m: Deprecate LWM2M_ENGINE_MESSAGE_HEADER_SIZE
Kconfig value LWM2M_ENGINE_MESSAGE_HEADER_SIZE added
an extra headroom for CoAP packet sizes so that
if CoAP Block-Wise transfer block-size is configured
to be same as LWM2M_COAP_MAX_MSG_SIZE, the full
payload block would usually fit to the datagram.

This causes too much confusion to be usable.
CoAP headers and options vary on sizes, and there is
no runtime limitations that we should check the
header size against.

Only real limitation is the CoAP packet size, which
must fit into the UDP datagram with typical DTLS headers.

Only limitation for CoAP block-size then is that
it must fit into the CoAP message with all the headers
and options. But as the option sizes, like path, vary,
it must be checked runtime.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2025-03-26 11:32:23 +01:00
Pieter De Gendt
044a94f06a net: lib: coap: coap_server: Use eventfd instead of socket pair
Convert the socket poll logic to use a more lightweight eventfd file
descriptor instead of a socket pair.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2025-03-26 08:55:45 +01:00
Jukka Rissanen
f7d37ea87c net: ipv4: Add DiffServ DSCP code point definitions
Add DSCP defines for cases where the IPv4 packets need
classification.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-03-25 11:00:33 +01:00
AbdElRahman Khalifa
b11703623c net: Add support for IPv4_MULTICAST_LOOP in net_context
Add support for the IP_MULTICAST_LOOP socket option to control
multicast packet loopback.

Signed-off-by: AbdElRahman Khalifa <abdelrahman.5alifa@gmail.com>
2025-03-24 09:54:05 +01:00
Jukka Rissanen
cc282e56e8 net: mdns_responder: Use memcpy instead of strncpy for iface name
Following warning is printed if using strncpy(), so use memcpy()
instead. Note that this is false positive as there is no error here but
in order to avoid the warning, change the copy function.

subsys/net/lib/dns/mdns_responder.c:1371:25: warning:
'strncpy' output may be truncated copying 7 bytes from a string
of length 8 [-Wstringop-truncation]
 1468 | strncpy(if_req.ifr_name, name, sizeof(if_req.ifr_name) - 1);
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

subsys/net/lib/dns/mdns_responder.c:1468:25: warning:
'strncpy' output may be truncated copying 7 bytes from a string
of length 8 [-Wstringop-truncation]
 1468 | strncpy(if_req.ifr_name, name, sizeof(if_req.ifr_name) - 1);
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-03-21 17:05:10 +01:00
Sayooj K Karun
273d60164d net: sockets: IPv6_MULTICAST_LOOP Support
Add support for the IPV6_MULTICAST_LOOP socket option.
This option allows enabling or disabling the consumption of multicast
packets by the sender. By default, the socket option will be enabled.

Co-authored-by: Pieter De Gendt <pieter.degendt@gmail.com>

Signed-off-by: Sayooj K Karun <sayooj@aerlync.com>
2025-03-21 14:19:08 +01:00
Robert Lubos
a61287e876 net: lib: tls_credentials: Rename TLS_CREDENTIAL_SERVER_CERTIFICATE
TLS_CREDENTIAL_SERVER_CERTIFICATE credential type is misleading, as in
fact it just represents a public certificate, it does not matter if the
certificate belongs to a server or a client. And actually, it was
already used in-tree for clients as well, for example in LwM2M.

Therefore rename the credential type to a more generic
TLS_CREDENTIAL_PUBLIC_CERTIFICATE and deprecate the old one.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-03-21 14:18:52 +01:00
Jukka Rissanen
82b43d50ea net: l2: dummy: Update sent statistics
Update dummy interface sent statistics as that was missing.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-03-21 14:18:25 +01:00
Jukka Rissanen
5076f5eee0 net: l2: virtual: Handle the packet if no attached interfaces
If there are no virtual interfaces attached to this virtual
interface, check if there is a RX handler for this virtual
interface and pass data to it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-03-21 14:18:25 +01:00
Cla Mattia Galliard
799742a77b net: sockets_service: Always clear old events when registering
Clear all previous events when register is called a second time. This is
the same behavior as before, if the call happens with `len` equal or
greater then the previous call but in the case if `len` is less then the
first call, now, all events are cleared. This is more predictable behavior.

Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
2025-03-21 14:18:08 +01:00
Jukka Rissanen
2f1a134f81 net: core: Free packet properly if TTL/hop limit is 0
We drop the packet if TTL or hop limit is 0, but we should
also unref the packet in this case because we return 0 to
the caller which is not then able to free the packet because
it thinks that the packet was sent properly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-03-21 09:53:44 +01:00
Jukka Rissanen
fc16c42bf7 net: core: Do IPv4/6 packet checks only for those packet types
The check_ip() in net_core.c did not check that the packet
Ethernet type is either IPv4 or IPv6. This meant that we for
example checked TTL also for ARP packets which is pointless as
those are not IPv4 packets.

Fix this by checking the link layer protocol type of the packet
to be either IPv4 or IPv6 before doing L3 checks.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-03-21 09:52:42 +01:00
Jukka Rissanen
410bd4b0be net: utils: Add helper to parse ip address string with a mask len
Adding a helper to parse one or more IPv4/6 strings with optional
netmask or prefix length.

Example of the string:

   2001:db8::1/64,192.0.2.1,2001:db8::2,192.0.2.2/24

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-03-20 17:16:10 +01:00
Jukka Rissanen
cd1091bc0a net: shell: conn: Print all connection information
All connection information was printed only if connection debugging
was enabled which then did not print information about Wireguard or
DHCP handlers. Limiting the printouts like this is not really needed
so print all connection information with "net conn" command.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-03-20 17:15:36 +01:00
Jukka Rissanen
0341d6bf0c net: shell: iface: Allow user to set the default interface
It is useful in testing to allow user to change the default
network interface by "net iface default <index>".
Also print out the default interface for "net iface" and
"net iface default" commands.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-03-20 17:15:36 +01:00
Jukka Rissanen
62963396e0 net: shell: iface: Print low level information if iface dbg is enabled
Sometimes it is useful to view low level network interface information
in the network shell. Enable such prints if network interface debugging
is enabled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-03-20 17:15:36 +01:00
Vineeta S Narkhede
fc974e36b0 net: mdns: Add support for iOS.
The query type used by iOS is HTTPS-65,
Adding HTTPS query type to support iOS.

Signed-off-by: Vineeta S Narkhede <VineetaSNarkhede@Eaton.com>
2025-03-20 12:16:43 +01:00
Maochen Wang
cb65dfbd2b net: lib: zperf: improve UDP RX throughput
The original flow of socket_service thread handling the Zperf UDP RX
packets is: zsock_poll() polls all sockets for events, if ctx->recv_q
of Zperf is not empty, it will call trigger_work() -> udp_recv_data()
-> zsock_recvfrom() to read only one UDP packet from ctx->recv_q, then
go back to zsock_poll() and run the same process again, which is
inefficient.
The alternative solution is, in udp_recv_data(), it should exhaust all
the packets in the current ctx->recv_q, and then go back to
zsock_poll() to run the same process again.
In our Wi-Fi test case, for WPA3 security mode of 5GHz, the STA UDP RX
throughput can be improved from 91.48 Mbps to 99.87 Mbps, the SAP UDP
RX throughput can be improved from 85.97 Mbps to 96.00 Mbps.

Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
2025-03-19 10:58:16 +01:00
Pieter De Gendt
1d62d835ac net: ip: Configurable IPv4 MTU
Allow to configure the initial IPv4 MTU needed to support packets without
fragmentation.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2025-03-19 03:34:26 +01:00
Robert Lubos
20faa0e114 net: l2: ppp: Make PPP L2 work with packet sockets
Currently, the L2 PPP won't work with AF_PACKET socket family as it only
supports packets from AF_INET/AF_INET6 families. Because of this, it's
not possible to use AF_PACKET RAW or DGRAm sockets with PPP interfaces,
as the packets they generate have family field set to AF_PACKET.

Fix this, by verifying the LL protocol field in the PPP L2 before
passing the packet the respective PPP driver. If the AF_PACKET packet is
received, and the protocol field is set to IP/IPv6, update the packet
family to AF_INET/AF_INET6 accordingly.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-03-18 16:45:53 +01:00
Marcin Niestroj
7290dd2a57 net: ipv6: set NET_ADDR_PREFERRED before network event if !DAD
Set NET_ADDR_PREFERRED before network event is generated, so that conn_mgr
properly generates NET_EVENT_L4_CONNECTED and NET_EVENT_L4_IPV6_CONNECTED
events.

Fixes: 1a5e13a79b ("net: if: Release the interface lock early when
  starting IPv4 ACD")
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2025-03-18 08:27:06 +01:00
Marcin Niestroj
3fcd25c8f8 net: ipv4: set NET_ADDR_PREFERRED before network event if !ACD
Set NET_ADDR_PREFERRED before network event is generated, so that conn_mgr
properly generates NET_EVENT_L4_CONNECTED and NET_EVENT_L4_IPV4_CONNECTED
events.

Fixes: 1a5e13a79b ("net: if: Release the interface lock early when
  starting IPv4 ACD")
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2025-03-18 08:27:06 +01:00
Jukka Rissanen
ac3cb9dac0 net: Change the net_linkaddr struct to not use pointers
Previously the net_linkaddr struct had pointers to the link address.
This is error prone and difficult to handle if cloning the packet as
those pointers can point to wrong place. Mitigate this issue by
allocating the space for link address in net_linkaddr struct. This will
increase the size of the net_pkt by 4 octets for IEEE 802.15.4 where the
link address length is 8, but there no increase in size if link address
is 6 bytes like in Ethernet/Wi-Fi.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-03-17 16:25:22 +01:00
Sebastian Schoch
a21ec50f5c net: lwm2m: Call the lwm2m_send_cb callback on context close
Fix that a lwm2m message is reset without executing a registered
callback on lwm2m_engine_context_close.

Signed-off-by: Sebastian Schoch <sebastian.schoch@husqvarnagroup.com>
2025-03-17 13:57:31 +01:00
Marc Lasch
8aed2a1bab net: lwm2m: Prevent client restart on bootstrap finish retransmission
Ignore bootstrap 'transition done' state transition
(ENGINE_BOOTSTRAP_TRANS_DONE) from an invalid state. The client must be
in state ENGINE_BOOTSTRAP_REG_DONE to process a bootstrap finish command
received from the server.

The LwM2M client does not implement CoAP deduplication (rfc 7252,
section 4.5) and retransmissions of the bootstrap finish command `/bs`
would restart the registration client with undesired side effects.

Signed-off-by: Marc Lasch <marc.lasch@husqvarnagroup.com>
2025-03-14 14:41:15 +01:00
Hui Bai
553b7d9bc5 wifi: shell: Show WPA2 Enterprise in scan results
For WPA2 Enterprise AP, show security type as WPA2 Enterprise
instead of EAP-TLS.

Signed-off-by: Hui Bai <hui.bai@nxp.com>
2025-03-13 16:57:15 +00:00
Vincent van der Locht
a26a222410 net: mdns: adding MDNS unicast response confirm rfc6732
Conform rfc6762  a mDNS responder should answer clients
which are not using the mDNS port in the source address
with unicast  UDP to the same port as described in chapter 6.7

Fixes: #81657

Signed-off-by: Vincent van der Locht <vincent@synchronicit.nl>
2025-03-13 16:54:24 +00:00
Nicolas Pitre
b5bc307019 net: lwm2m: encapsulate ring buffer internals
Use struct ring_buf_index as a whole, don't access its constituants.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2025-03-12 19:04:54 +01:00
Maochen Wang
1dbe1dfa1f net: lib: sockets: fix socket_service thread stuck by mistake
Use Wi-Fi connecting to Qualcomm IPQ8074 AP, and run the UDP RX traffic
with Zperf, but zperf does not return the throughput number after
traffic completion nor any session started prints. After traffic
completion, ping from STA to AP and vice versa does not work. The
socket_service thread is found blocked forever at zsock_wait_data()
after dns_dispatcher_svc_handler() is called via trigger_work().
The root cause of this issue is:
STA received one DHCPv4 packet containing DHCPV4_OPTIONS_DNS_SERVER,
it will create DNS socket and registered to socket_service. Then STA
received another IPv6 router advertisement packet containing
NET_ICMPV6_ND_OPT_RDNSS, it will close socket and change the state of
poll_events to K_POLL_STATE_CANCELLED(8), then registered to
socket_service with same fd. In socket_service thread, zsock_poll()
called zsock_poll_update_ctx() when handled ZFD_IOCTL_POLL_UPDATE, and
it checked the state of poll_events was not K_POLL_STATE_NOT_READY(0),
then it will set pfd->revents to '|= ZSOCK_POLLIN'. Finally
trigger_work() can be called as 'ctx.events[i].revents > 0' is matched.

The fix of this issue is that, in zsock_poll_update_ctx(), it should
check the state of poll_events is neither K_POLL_STATE_NOT_READY nor
K_POLL_STATE_CANCELLED before setting revents as ZSOCK_POLLIN, to avoid
trigger_work be unexpectedly called.

Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
2025-03-12 07:14:46 +01:00
Christoph Seitz
5992208605 net: ethernet: Refactor length check to accommodate VLAN header size
The ethernet header size with VLAN tag is 18 bytes,
so the length check should accommodate this.

Signed-off-by: Christoph Seitz <christoph.seitz@infineon.com>
2025-03-12 02:29:02 +01:00
Christoph Seitz
e43246b756 net: ethernet: Fix length update for unsupported packet families
Do not update packet length for unsupported packet families.
AF_PACKET family used the IPv6 length update, which breaks the
packet length if there is a payload with bytes resembling a
IPv6 length field less then 6 or a IPv4 length field less
then 46.

Signed-off-by: Christoph Seitz <christoph.seitz@infineon.com>
2025-03-12 02:29:02 +01:00
Etienne de Maricourt
16c6504ee0 net: lwm2m: Fix ifdef nesting for data cache config
Avoid a "defined but not used" warning on
`init_next_pending_timeseries_data` when
LWM2M_RESOURCE_DATA_CACHE_SUPPORT is enabled but not LWM2M_VERSION_1_1.

Signed-off-by: Etienne de Maricourt <edmecomemail@gmail.com>
2025-03-12 02:27:59 +01:00
Nicolas Pitre
c7467f0c65 ring_buffer: constify some arguments
Functions that don't modify content should have pointers to it marked
const.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2025-03-11 08:59:05 +01:00