Fixes two bugs:
* When a notify is executed before any observers are added, the age is
incremented from 0 to 1. When an observer is registered, the age is not 0
as expected, causing the age to be 1 instead of the expected 2
* The check if a message is newer than the last received one is described
in RFC7641, section 3.4. Simply incrementing age will not comply to what
the RFC describes once the value wraps around. This is now fixed
Signed-off-by: Sibert Declercq <sibert.declercq@basalte.be>
Convert various networking subsystem files to use ARRAY_FOR_EACH
macro to make the looping more robust.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Convert various array loops in the net_if.c to use the
ARRAY_FOR_EACH() macro. This makes the code more robust
as we do not need to keep track of the separate define
that tells the array size.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This commit deprecates these legacy netmask get/set routines
net_if_ipv4_set_netmask()
net_if_ipv4_set_netmask_by_index()
net_if_ipv4_get_netmask()
as they do not work well if there are multiple IPv4 address
assigned to the network interface.
User should use these functions instead
net_if_ipv4_set_netmask_by_addr()
net_if_ipv4_set_netmask_by_addr_by_index()
net_if_ipv4_get_netmask_by_addr()
as they make sure the netmask it bound to correct IPv4 address.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The netmask should be tied to the IPv4 address instead of being
global for the network interface.
If there is only one IPv4 address specified to the network interface,
nothing changes from user point of view. But if there are more than
one IPv4 address / network interface, the netmask must be specified
to each address separately.
This means that net_if_ipv4_get_netmask() and net_if_ipv4_set_netmask()
functions should not be used as they only work reliably if there is
only one IPv4 address in the network interface.
The new net_if_ipv4_get_netmask_by_addr() and
net_if_ipv4_set_netmask_by_addr() functions should be used as they make
sure that the netmask is tied to correct IPv4 address in the network
interface.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Set a thread name for net conn_mgr, so that e.g. thread listings
within the shell are easier to look at.
Signed-off-by: Florian La Roche <Florian.LaRoche@gmail.com>
This is not used by anyone, and is unlikely to be useful actually.
Helps to save 4 bytes for each instance of struct net_nbr also (removing
a 2 bytes attributes, which was anyway generating a 4bytes loss due to
structure misalignment).
Removing relevant useless functions related to it as well.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
As noted in net_if.c:net_if_ipv6_addr_add() IPv6 ND needs MLD.
It is not selected during test, as the combination of ND without DAD/MLD
breaks (something to study/fix further it seems).
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Net MGMT uses layer identifiers that are meaningful only for itself, but
for users it requires a trivial operation to show the real layer value.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Net MGMT mask should be fully configured first, prior to be used to
initialize and add the callback.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
As for adding an ipv6 address, removing one should return the same error
code when the network interface is not found.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
It's an optional support, and it should not select it by default.
Improving information message in case such support is disabled.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
The zperf received or sent bytes length and duration are in 32bits,
if running long-duration zperf test more than 20min, the value will
overflow, and the test result is wrong. Change it to 64bits can fix
this issue.
Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
When the zperf command is called with '-S' option which means IP_TOS
for IPv4 and IPV6_TCLASS for IPv6, an error is printed and the
setting does not work. The socket option handling was changed by
commit 77e522a5a243('net: context: Refactor option setters'), but the
callers of option setters were not changed. This causes the IP_TOS
or IPV6_TCLASS option failed to set. The fix is to use uint8_t to
store the value of the -S option.
Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
Allow the use of the NTP server address, set by
dhcpv4 option, by the net_init_clock_via_sntp function.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
It was an overlook to return 0 on TLS send() call, after detecting that
TLS session has been closed by peer, such a behavior is only valid for
recv(). Instead, an error should be returned.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Return error to the caller if no data was received or there
was some other error. Earlier we did not check the error
condition properly.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This makes it possible to set the minimum IPv6 packet size that
can be sent without fragmentation. The default value is 1280 bytes.
This commit allows user to set the IPv6 MTU value within reasonable
limits [1280, 1500].
Fixes#61587
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
We select sockets service API in Kconfig but should select also
sockets API so that user does not need to set the sockets API separately.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The "net sockets" command did not print network management
socket information properly but claimed that the socket
was IPv4 one which it is not.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The net_mgmt socket does not support poll() or fcntl(), so
return EOPNOTSUPP error if user tries to use those functions
for AF_NET_MGMT type socket.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Check the value of net_dhcpv4_add_option_callback()
and net_dhcpv4_remove_option_callback() explicitly.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
This ensures that the configured link address is
at least as big as the part of it that is used.
Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
This commit extends Zephyr's networking API to allow higher layers to
report on neighbor reachability.
Signed-off-by: Łukasz Duda <lukasz.duda@nordicsemi.no>
Apply ranges to DHCPv4 server timeout Kconfig options, so that it cannot
be set to a negative value by mistake.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case conflict is detected (either due to receiving Decline message or
due to ICMP probe getting reply), the conflicting address becomes
blocked for further use.
Although the RFC is not specific about how long should the address be
blocked, it make sense to implement some fallback mechanisms to reuse
blocked addresses in the server, otherwise, after longer period of
operation, it may run out of usable address.
This commit adds a timeout for declined addresses, so that by default
the address is marked back as "free" after 24 hrs (default lease time).
It also implements a mechanism, which allows to re-use the oldest
declined entry in case the server runs out of fresh addresses to assign.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Since PR, PR_SHELL, PR_ERROR, PR_INFO, and PR_WARNING already have
an embedded `sh` NULL check, we can remove the change from PR #68809.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
It is possible that the `sh` was not set before use.
This change adds a NULL check for `sh` in the following macros:
PR, PR_SHELL, PR_ERROR, PR_INFO, and PR_WARNING.
In case `sh` is NULL, the above macros will call `printk` instead.
Fixes#68793
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
Add traffic class priority custom option to customize traffic class
priority base for throughput performace.
Wi-Fi traffic performance depends on cooperation between net threads
and Wi-Fi driver threads. So we want traffic class threads priority
to be more flexible to fit more vendors.
Eg: when traffic class tx thread priority is higher than driver tx
thread, it will consume much more cpu time and send packets until driver
queue full.
When traffic class tx thread priority is lower than driver tx thread,
it will become serial transmition, also affecting throughput.
Signed-off-by: Fengming Ye <frank.ye@nxp.com>
This change reduces the memory footprint by changing the data type of
`valid_5g_chans_20mhz` from `uint16_t` to `uint8_t`.
Additionally, since the maximum channel number for 5GHz Wi-Fi is 177,
it can fit within the `uint8_t` range.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
Add a command `net ipv4 gateway` that allows
setting IPv4 gateway for an interface from net shell.
Signed-off-by: Mateusz Karlic <mkarlic@antmicro.com>
Add CONFIG_NET_SOCKETS_DTLS_MAX_FRAGMENT_LENGTH for limiting
the Maximum Fragment Length (MFL) for DTLS with Mbed TLS.
This is needed when MBEDTLS_SSL_OUT_CONTENT_LEN and
MBEDTLS_SSL_IN_CONTENT_LEN are set to larger values than the MTU
of the network and IP fragmentation is not supported.
Signed-off-by: Markus Lassila <markus.lassila@nordicsemi.no>
This flag indicates that only passive transmissions are allowed in that
channel for that regulatory domain.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Make sure that socket service is started earlier than
config library. This is enforced in config libs init.c
but set the default value here too.
The reason for this is that the config library might need
to start dhcpv4 server which needs socket service to work,
so the ordering is important here.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
We must make sure that IPv6 configuration pointer is valid
so that the hop limit can be set for a given interface.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
We must make sure that IPv4 configuration pointer is valid
so that the TTL can be set for a given interface.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
As the interface init function might configure the system
such a way that would affect the naming of the network
interface, we need to call the init before setting the name.
This is mostly needed by Wifi where the Wifi driver needs
to mark its network interface as Wifi interface as by default
the Wifi interface will look like Ethernet one.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Fix the dead lock between rx_q and tx_q thread.
When tx_q thread prepares to send ARP packet, it might get
the net_if_tx_lock in net_if_tx(), then in net_arp_prepare(),
it will try to get the arp_mutex.
At the same time, if the rx_q thread receives an ARP reply
packet, in arp_update(), it will get the arp_mutex first,
and flush the packets in arp pending_queue and try to get
the net_if_tx_lock. Then the dead lock occurs, two threads
stuck and all the packcets can't be freed.
In arp_update(), taking the net_if_tx_lock first then taking
the arp_mutex can fix this issue.
Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
If the CONFIG_NET_SOCKETS_POLL_MAX is smaller than what is needed
for the socket service API to work properly, then we should not
start the service thread as the service API cannot work and might
cause memory overwrite in ctx.events[] array.
Fixes#69233
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
There's not much to be done in case waking up the server thread with
socketpair send() fails, but at least we can log an error on such event
(to please coverity).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The Imax_abs value should be printed using %u instead of %d
as it can be large and should be printed as positive value.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Add COAP_RESPONSE_CODE_TOO_MANY_REQUESTS to coap_header_get_code(). CoAP
4.29 response code for "Too many requests" is defined in coap.h but was
missing from the list of cases, resulting in a 0 being returned instead
of the proper code.
Signed-off-by: Mike Szczys <mike@golioth.io>
By default variable context.sh is set to NULL. If any net_mgmt
event will be called when the variable has default value, there
will be a system exception.
Signed-off-by: Wojciech Slenska <wsl@trackunit.com>
Currently, the only thread-safe part of the IPv6 Neighbor processing
implementation are stale_counter related operation.
Fix this, by extending the mutex protection over all of the module, so
that message handlers, timers and API functions do not interfere with
each other.
As IPv6 Neighbor cache is tightly coupled with the Routing module, use
the same mutex to protect both, neighbor and routing tables, to prevent
deadlocks.
Also, replace the semaphore used with a mutex, as it seems more fit for
this particular job.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit implements simple rate-limiting for Neighbor Reachability
Hints in TCP module to prevent the potentially costly process of
frequent neighbor searches in the table, enhancing system performance.
Signed-off-by: Łukasz Duda <lukasz.duda@nordicsemi.no>
Changed poll to perform incoming data check with connected
DTLS connections. This allows the CONFIG_NET_SOCKETS_DTLS_TIMEOUT
to timeout the connections to server socket if there is no
incoming data.
Previously, if the remote client closed the DTLS connection without
close notify, the timeout of the ongoing connection only happened
when next connection was taken to the server socket. Depending on
the timeouts, this could prevent the next connection from succeeding.
Signed-off-by: Markus Lassila <markus.lassila@nordicsemi.no>
WIFI scan result shows junk character in SSID because of
the length of ssid is maximum(32 character) which leads
to buffer overflow. It required one character for null
terminator ‘\0’.
Signed-off-by: Kapil Bhatt <kapil.bhatt@nordicsemi.no>
Previously, there was no way to determine maximum number of bytes
that can be allocated using only net_buf structure. This commit
introduces such field.
Moreover, this commit fixes an issue where allocation of less than
maximum number of bytes from a fixed buffer pool would set buffer's
size to this number instead of the whole buffer size.
Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
As defined in IEEE802.1AS-2020 ch. 10.2.12.2.1, the port identity
of an MDSyncSend structure sent from a port shall be set to the
port identity of the sending port according to and ch. 8.5.2.
This commit replaces the port identity before forwarding a sync.
Fixes#68385
Signed-off-by: Manuel Schappacher <manuel.schappacher@hs-offenburg.de>
If recvmsg() does not update control data, then it must
set msg_controllen length to 0 so that the caller can
understand this.
Fixes#68352
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
In case zperf session was aborted by the user (by for instance stopping
it from shell), or practically in case of any other
communication-related error, the zperf session could end up in a state
other than NULL or COMPLETED, with no way to recover. This made the
session no longer usable and eventually could lead to zperf being not
able to start a new session anymore.
Fix this by introducing zperf_session_reset() function, which resets the
session state back to defaults. The function is called when the zperf
receiver service is stopped.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The issues found for UDP receiver were also identified for TCP receiver,
this commit applies practically the same set of changes as in case of
UDP.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit fixes restarting of UDP receiver service, along with some
other minor cleanups:
* The core issue was udp_server_running flag not being cleared when
service was stopped. Fix this by introducing udp_receiver_cleanup()
which does all of the required cleanups when receiver service is
stopped. The function is called either when the application stopped
the service with zperf_udp_download_stop(), or when the service was
stopped due to error.
* net_socket_service_unregister() was not called on
zperf_udp_download_stop(), but only from the service callback - that
would not work in case there's no active communication.
* at the same time, net_socket_service_unregister() would be called from
the service callback in case of errors. Fix this, by making
udp_recv_data() only return an error, and let the service callback to
do the cleanup.
* Remove no longer used udp_server_run semaphore
* Remove udp_server_stop - with socket services it seems no longer
needed.
* zperf_udp_receiver_init() now returns an error, so that we don't
mark the service as running in case of socket/services error.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add sockaddr member in struct net_pkt to store peer address if offloaded
network inteface is used. This enables recvfrom() to fill in src_addr if
socket type is UDP and offloaded interface driver supports it.
Signed-off-by: John Johnson <john.filip.johnson@gmail.com>
DHCPv4 server will send an ICMP probe (echo request) for the requested
address before replying with DHCP Offer, unless probing is disabled in
Kconfig.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Additionally, replace the local print(sh, level, fmt, ...) macros
with PR, PR_ERROR, and PR_WARNING macros.
Then remove the print(sh, level, fmt, ...) macros.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
Replaced direct shell_fprintf calls with PR, PR_ERROR, PR_INFO
and PR_WARNING macros.
This change simplifies the code by using predefined macros.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
Moved 'scan_result' from a standalone variable into the 'context' struct
to enhance code optimization.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
This commit introduces a local variable 'sh' to store 'context.sh' for
use with the 'shell_fprintf' function.
By doing so, we avoid the repeated dereferencing of 'context.sh',
thereby reducing the code footprint.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
This commit introduces a new IPv6 API for positive reachability
confirmation, as specified in RFC 4861, Section 7.3.1. This feature aims
to enhance the effectiveness of the Neighbor Discovery mechanism, by
enabling upper-layer protocols to signal that the connection makes a
"forward progress".
The implementation within TCP serves as a reference. Compliance with
RFC 4861, especially Appendix E.1, was ensured by focusing on reliable
handshake and acknowledgment of new data transmissions.
Though initially integrated with TCP, the API is designed for broader
applicability. For example, it might be used by some UDP-based protocols
that can indicate two-way communication progress.
Signed-off-by: Łukasz Duda <lukasz.duda@nordicsemi.no>
We cannot always start the service monitor thread statically
because the static threads are started after the application
level. This means that when config library wants to start
dhcpv4 server which uses socket services, there would be a
deadlock. Simplest solution is to start the service thread
directly from socket service init function.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Not only check if the address pool belongs to the same subnet as the
server, but also that it does not overlap with the server address -
otherwise the server might end up assigning its own address.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
As connectivity backends need to be bound in the same file that the
`net_if` is created in, define a common backend type for WiFi modems.
All WiFi modems should be controllable through the `wifi_mgmt` API, so
there should be no need for dedicated context.
When enabled, the particular implementation to be used is chosen through
`CONNECTIVITY_WIFI_MGMT_IMPL`. For now, the only choice is an
application defined backend.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
For a Wi-Fi station the connect API supports both band and channel
configuration, but for a shell command either channel or band makes
sense, so, overload the channel field to support band.
Rejig the band and channel validation to support all modes.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Adds an option to disable the automatic initialization of the default
dns_context. This lets applications use the default context, while also
managing the `init` and `close` functions.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
ICMPv4/6 modules print error when ICMP message handling fails, which
includes no message handler registered. This is a bit problematic, as
there are many ICMP messages that Zephyr does not process, and every
time such a message is received, an error log is printed (which wasn't
the case before ICMP rework).
Restore the old behavior (no log on unrecognized ICMP message) by
explicitly filtering out ENOENT error code from printing error. That
way, log will only be printed if an error occured within the actual
message handler.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
As discussed during DHCPv4 server integration, group DHCPv4 client files
with DHCPv4 server in a single lib directory.
Renamed internal "dhcpv4.h" header to "dhcpv4_internal.h" so that it's
not confused with the public "dhcpv4.h" header.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The net-shell printed virtual interface name so that it got
the impression it was the network interface name which is not
correct. Now the name is printed as "Virtual name" which is
unambiguous.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
If IPv6 is not enabled for the interface, then do not try to
join the IPv6 solicited multicast address.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The ratio between mbps and kbps, kbps and bps should be 1000, instead of
1024, as common sense.
The wrong ratio will decrease the Zperf throughput result.
Signed-off-by: Fengming Ye <frank.ye@nxp.com>
Make sure that scan band string is properly terminated when
parsing user supplied string.
Fixes: #67944
Coverity-CID: 342930
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
When ENABLED flag is used, we generate 32 byte DTLS
Connection Identifier and include that in our
DTLS Client HELO. This has no benefit as client only
has one connection toward the server, it does not need
any identification.
When SUPPORTED flag is used, we just include
zero length Connection Identifier in the handshake,
which tell server that we support Connection Identifier
and server can generate one for it.
We then use the CID in the packets that we send towards
server, but response packets don't contain any CID.
This gives all the benefit of CID as server is able to
identify us even when NAT mapping have changed.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Add command to query to WiFi driver/firmware revision. The API is expected
to return the firmware revision and driver version as a string, and can be
used by the user to determine what revision of the WiFi driver is in use.
Signed-off-by: Sandip Dalvi <sandip.dalvi@nxp.com>
Instead of relaying on those macros having been defined
somewhere else let's define them for this file.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Now that we are using the shell macro to enforce argument count check,
both mandatory and optional arguments, these additions checks are
unnecessary.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Add macro that allows registration of initialization functions that
are called when LwM2M engine starts.
On LwM2M engine starts up, it first executes all initialization
functions in following priority order:
1. LWM2M_PRIO_ENGINE
2. LWM2M_PRIO_CORE, this is where all LwM2M core objects are initialized
3. LWM2M_PRIO_OBJ, this is where all other objects are initialized
4. LwM2M_PRIO_APP, application initialization.
Now on the initialization phase, we could rely that certain objects have
already been registered.
For example custom objects can register callbacks to core objects.
On application phase, we can initialize sensor objects and register
their callbacks because objects have already been initialized.
This LWM2M_ON_INIT() should replace all use of SYS_INIT()
with the default CONFIG_KERNEL_INIT_PRIORITY_DEFAULT.
Priority order is actually just alphabetical order of names, so
the order is set on a linkin phase, and we don't need any
runtime checking for it.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Remove TX-Injection and Promiscuous mode setting from Wi-Fi mode shell
command. These commands are being moved to ethernet l2 layer
Signed-off-by: Vivekananda Uppunda <vivekananda.uppunda@nordicsemi.no>
This set of changes brings in raw packet tx injection mode
feature to ethernet and removes it from being a Wi-Fi only feature.
It was earlier envisaged as Wi-Fi net management feature only.
Signed-off-by: Vivekananda Uppunda <vivekananda.uppunda@nordicsemi.no>
If bootstrap fails, RD client will call lwm2m_engine_stop()
which will close the context.
The socket loop, however still contains a call to
hint_socket_state(context, NULL) which has a null pointer now.
Fix the segfault by allowing nullpointer on hint_socket_state().
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Implement DHCPv4 shell module, which allows to start/stop DHCPv4 server
operation, and print server status (address leases).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Increase socket services thread default stack size when DHCPv4 server is
enabled, as it uses synchronous processing.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
So that it's possible to register ARP entries manually. Needed for DHCP
server implementation, which in unicast mode needs to reply to an IP
address that is not registered on the peer interface yet (hence no ARP
reply will be sent). It's needed to add an ARP entry manually in that
case, as hardware address is already known at that point.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add new kconfig CONFIG_LWM2M_QUEUE_MODE_NO_MSG_BUFFERING.
When enabled and device is sleeping, Reqistration Update
message is skipped and messages from send operation and
notifications are sent right away.
Reqistration update message is also skipped when
lwm2m_engine resumes from pause state.
Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
L2 PPP is not able to handle the carrier being lost gracefully,
nor is it able to gracefully close the PPP connection when
net_if_down() is called.
This patch refactors the L2 PPP module to use the carrier state
to either properly close or simply terminate the PPP connection.
Additionally, it ensures that the PPP session is closed properly
before calling ppp->stop().
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Get TLS_DTLS_CID_STATUS and TLS_DTLS_PEER_CID_VALUE utilize
mbedtls_ssl_get_peer_cid, which expects that mbedtls_ssl_setup
has been done.
Signed-off-by: Markus Lassila <markus.lassila@nordicsemi.no>
User is able to tweak the socket service dispatcher thread
priority in order to get better performance from the system
if needed. By default the dispatcher thread runs in lowest
application thread priority (K_LOWEST_APPLICATION_THREAD_PRIO).
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The thread name output field was a bit too short in "net sockets"
command, so make it 25 char long.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The "net sockets" command was not checking if there is any
sockets in the system before trying to access them.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The channel extraction from string directly uses the end variable with
limited data type, this causes issue if an invalid channel that exceeds
the data is given as an input e.g., 300, which would end up as a valid
channel 44.
Use an intermediate variable with type that can hold all possible
combinations (valid and invalid) and only after validation assign that
to the end type.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
For none and WPA-PSK MFP isn't applicable, it was only introduced in
WPA2-PSK (RSN) and later.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Various network shell commands like ping need floating
point support from libc so select the CONFIG_REQUIRES_FLOAT_PRINTF
option for it.
Fixes#67601
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The place where TF-M places its non-secure api header files has changed
Therefore changing it for for all applications that use it.
Signed-off-by: Markus Swarowsky <markus.swarowsky@nordicsemi.no>
This commit adds a function that updates the hostname displayed by the
net backend. It is called by the network stack when the hostname is
updated.
Signed-off-by: Gerhard Jörges <joerges@metratec.com>
If user has not supplied address pointer when calling accept(),
then we would not be able to figure out the used socket domain
properly. But as there is now SO_DOMAIN option supported, use
that to get the correct socket domain.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The getsockopt() will return the address domain of the given
socket like AF_INET or AF_INET6.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Made the definition of in_addr all_routers conditional to remove
compiler warning:
warning: 'all_routers' defined but not used [-Wunused-const-variable=]
The warning occurs when igmpv3 is enabled.
Signed-off-by: Ibe Van de Veire <ibe.vandeveire@basalte.be>
This commit adds a new function the net_buf's API that allow an user
to match the net_buf's content with a data without copying it to a
temporary buffer.
Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
gcc prints this warning message
'strncat' specified bound 1 equals source length [-Wstringop-overflow=]
58 | strncat(fd, "C", 1);
There was no error in the code but avoid the warning by not using
strncat().
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The socket service provides a similar functionality as what
initd provides in Linux. It listens user registered sockets
for any activity and then launches a k_work for it. This way
each application does not need to create a thread to listen
a blocking socket.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
According to the POSIX specification, null pointer
is a valid value for the `address` argument
of the `accept` function.
This commit adds a check to prevent a null pointer
dereference inside `z_impl_zsock_accept`.
Signed-off-by: Mirko Covizzi <mirko.covizzi@nordicsemi.no>
A problem occurred while running PTP on a multi-port target
(RENESAS RZT2M) with two ports enabled. Announce messages on the
switched devices master port always contained local clock information
instead information from received on the slave port from the better
GM clock. Depending on the BMCA config this turned into having more
than one GM in the system.
Sending always the locally stored GM information helped to overcome
this issue.
Signed-off-by: Manuel Schappacher <manuel.schappacher@hs-offenburg.de>
Provision of configurable parameter for generating unblock event
ahead of TWT slot. Host application depending upon latencies can
configure this to wakeup rpu ahead of the TWT slot.
Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
ARM GCC version 12.2.0 (Zephyr SDK 0.16.4) generates the following build
warning from the strncpy call in "wifi_utils_parse_scan_bands":
warning: '__builtin_strncpy' output truncated before terminating nul
copying as many bytes from a string as its length
To resolve this warning, pass the maximum length of the temporary
parse_str buffer to strncpy. This also has the benefit of correctly null
terminating parse_str, since we already verify the
scan_bands_str is properly null terminated with the strlen() check in
this function. We can therefore remove the line adding a null terminator
to parse_str as well.
Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
This was missed in earlier that tried to fix all string comparisons to
use case insensitive comparison.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
The help text was incorrect, we return -ETIMEDOUT instead
of -ECONNRESET when retransmission timeout occurs.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
In AP mode maintain the database of connected stations based on the
Wi-Fi management events and dump the list.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
These are helpful to track clients being added and deleted.
Applications can actions based on these events.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
These events communicate the status of AP mode operations (enable or
disable) with few pre-defined enumerations.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Update the example of scan -c argument.
Default value for max channels is set to 3,
So, update the example according to that.
Add closing bracket in -s.
Signed-off-by: Kapil Bhatt <kapil.bhatt@nordicsemi.no>
Adding a callback for handling lwm2m messages with prefixed paths defined
by the gateway object. If CONFIG_LWM2M_GATEWAY_OBJ_SUPPORT is set,
each path is checked for the prefix stored in the object instances of the
gateway object 25. If prefixes match the msg is passed to the gw_msg_cb.
Signed-off-by: Simon Walz <simon.walz@autosen.com>
__bswap_ in zephyr/sys/byteorder.h conflicts with __bswap_ in host's
byteswap.h. byteswap.h from host compiler used in posix_native_64 boards
causes a compilation issue.
This commit renames __bswap_ to BSWAP_ to prevent collision.
Before this commit a compilation error can be created by adding #include
<byteswap.h> to samples/net/sockets/echo/src/socket_echo.c
This does not change external API to byteorder.h, but does change
internal implementation which some other source files depend on.
Replaced manual byteswap operations in devmem_service.c with APIs from
byteorder.h which automatically converts to CPU endianess when necessary.
Fixes#44324
Signed-off-by: Jonathan Hamberg <jonathanhamberg@gmail.com>
Add a function callback that is called when the TCP connection
is closed. This is only available if doing network tests.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The FIN timer was not set when we entered the FIN_WAIT_1 state.
This could cause issues if we did not receive proper packets
from peer. With this fix, the connection is always terminated
even if peer does not respond.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
If we are in a passive close state, then it is possible that
the ack we are waiting is lost or we do not accept the one peer
sent to us because of some earlier out of memory issue.
So install a timer (using by default the FIN timer value) to
close the connection if the last ack is not received on time.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The help text uses the capital case as its an acronym, but passing
capital case fails. Also extend that to others as well.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
For better readability, below rules will help:
* Each command should be separated by a newline
* Each command should end with a full stop (intermediate statements
shouldn't have full stops)
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
We are using standard notation to differentiate optional and mandatory,
so, no need for a heading.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
lwm2m_engine_pause() caused deadlock if it was called within
engine thread.
Remove while loop from lwm2m_engine_resume().
Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
Add short delay before triggering registration update. This allows
postponing the update from application side if needed.
Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
DTLS socket is not really connection-less as UDP, as it required the
DTLS handshake to take place before the socket is usable. Therefore,
align the DTLS connect() behavior with regular TLS.
The change is backward compatible. connect() call is still optional for
DTLS socket (the handshake can still take place from send()/recv()) and
a socket option was provided to disable DTLS handshake on connect().
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
When using DTLS socket, the application may choose to monitor socket
with poll() before handshake has been complete. This could lead to
potential crash (as the TLS context may have been left uninitialized)
and unexpected POLLIN reports (while handshake was still not complete).
This commit fixes the above - POLLIN will only be reported once
handshake is complete and data is available
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case a socket error was caused by TLS layer, it was not reported with
POLLERR. This commit fixes this.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case TLS session is closed at the TLS level (and thus recv() reports
0 to the application) a certain race occurs between consecutive recv()
call, and TCP session teardown. As mbedtls_ssl_read() only reports
session close upon receiving CLOSE alert, consecutive non-blocking
recv() calls would report EAGAIN instead of connection closed, if called
before underlying TCP connection was closed.
Fix this, by storing the information that TLS session has ended at TLS
socket level. The new flag will be checked before attempting further
mbed TLS actions, so that connection status is reported correctly.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
If we receive a IPv4 packet to v4 mapped address, the relevant
net_context is bound to IPv6. This causes issues if we try
to get the family from the context struct in sendto.
Fix this by checking if the destination address is IPv4 but
the socket is bound to IPv6 and v4 mapping is enabled.
If all these criterias are set, then set the family of the
packet separately and do not get it from net_context.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Make sure iovec is initialized to a value so that there
is no possibility that it is accessed uninitialized.
Fixes: #66838
Coverity-CID: 334911
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The original idea was to check that we have enough network
interfaces in the system. The check needs to verify max IPv4
and IPv6 supported interfaces instead of always checking
IPv6 one.
Fixes: #66843
Coverity-CID: 334899
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Refactored the socket state indication into its own function
that checks the state of TX queues as well as number of
pending CoAP responses.
Check the state after receiving a packet, as it might
have been a last Ack packet we have been waiting.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Deprecate lwm2m_set_u64() and lwm2m_get_u64 as only
LWM2M_RES_TYPE_S64 exist. Unsigned variant is not defined.
Technically these might have worked OK, but it is undefined
what happens to large unsigned values when those are
converted to various payload formats (like CBOR) that might
decode numbers differently depending of their signedness.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Any received address is no longer valid once the interface goes down.
Leaving the address assigned results in the L4 interface transitioning
through the following on reconnection:
UP: Interface is connected
DOWN: Old address is removed by DHCP
UP: New address is re-added by DHCP
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
Networking events are masks of bits, which are almost impossible to read
as decimal, and trivial to read as hex. Also unifies the format string
across multiple outputs for some flash savings.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
If we receive a packet where the source address is our own
address, then we should drop it.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
If we receive a packet from non localhost interface, then
drop it if either source or destination address is a localhost
address.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Allow engine to give hints about ongoing CoAP transmissions.
This information can be used to control various power saving
modes for network interfaces. For example cellular networks might
support release assist indicator.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
In slow networks, like Nb-IOT, when using queue mode,
there might be significant delay between the time we
put the packet into a transmission queue and the time
we actually start transmitting.
This might cause QUEUE_RX_OFF state to be triggered earlier
than expected. Remedy the issue by updating the timestamp on the
moment where packet is accepted by zsock_send().
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
In case a waiting TLS socket reports an error in the underlying poll
call, try to read the actual error from the socket, instead of blindly
returning -EIO in all cases.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
There are several subsystems and boards which require a relatively large
system heap (used by k_malloc()) to function properly. This became even
more notable with the recent introduction of the ACPICA library, which
causes ACPI-using boards to require a system heap of up to several
megabytes in size.
Until now, subsystems and boards have tried to solve this by having
Kconfig overlays which modify the default value of HEAP_MEM_POOL_SIZE.
This works ok, except when applications start explicitly setting values
in their prj.conf files:
$ git grep CONFIG_HEAP_MEM_POOL_SIZE= tests samples|wc -l
157
The vast majority of values set by current sample or test applications
is much too small for subsystems like ACPI, which results in the
application not being able to run on such boards.
To solve this situation, we introduce support for subsystems to specify
their own custom system heap size requirement. Subsystems do
this by defining Kconfig options with the prefix HEAP_MEM_POOL_ADD_SIZE_.
The final value of the system heap is the sum of the custom
minimum requirements, or the value existing HEAP_MEM_POOL_SIZE option,
whichever is greater.
We also introduce a new HEAP_MEM_POOL_IGNORE_MIN Kconfig option which
applications can use to force a lower value than what subsystems have
specficied, however this behavior is disabled by default.
Whenever the minimum is greater than the requested value a CMake warning
will be issued in the build output.
This patch ends up modifying several places outside of kernel code,
since the presence of the system heap is no longer detected using a
non-zero CONFIG_HEAP_MEM_POOL_SIZE value, rather it's now detected using
a new K_HEAP_MEM_POOL_SIZE value that's evaluated at build.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This reverts commit 6b644dff67.
Reason: breaks Peer-to-Peer gPTP connection. A better solution should be
found to handle the optional TLV on the announce message (chapter 10.5.1
IEEE 802.1AS-2011)
Signed-off-by: Mario Paja <mario.paja@zal.aero>
Zephyr does not support MLDv1 (which has a shorter header than MLDv2),
and this resulted in log errors being printed on header access if MLDv1
queries were received. Since receiving such packet is not really an
error, just drop it silently.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Update coap_service_send and coap_resource_send to take an optional
pointer argument to the newly introduced coap_transmission_parameters.
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
AP enable takes the same parameters as connect, so, update the help and
also fix the optional parameter count when security is involved.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
In case one of the networking shell backends is enabled, net arp command
could potentially trigger a deadlock, as it locks the ARP mutex before
TCP connection mutex, while TCP stack could do this in reverse order
(for instance when sending ACK or retransmission).
Mitigate this, by forcing a separate TX thread in such case, so that ARP
mutex is no longer accessed with TCP mutex locked.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Replace function parameter 'retries' with pointer to structure
holding coap transmission parameters. This allows setting the
retransmission parameters individually for each pending request.
Add coap transmission parameters to coap_pending structure.
Update migration guide and release notes.
Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
The dummy L2 layer does not implement any L2 functionality
but it does not mean that it should not implement start/stop
functions that are called when the related network interface
is brought up or taken down.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
It is pointless to take net interface up if the underlaying
device is not ready. Set also the interface status properly
in this case.
Fixes#65423
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Use correct format specifier for LOG_ERR in lwm2m_obj_device.c. The
previously used format specifier of %u was correct for 32 bit systems
but would produce a build warning for 64 bit systems.
Fixes#66441
Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
As the common.h is only meant to be used by the network
shell files, rename it to be more descriptive in order to
avoid possible conflicts with any other common.h file.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Calling the registered receive callback when releasing TCP context
doesn't make sense, as at that point the application should've already
closed the associated socket (that's one of the conditions for the
context to be released). Therefore, remove the pointless receive
callback call, while keeping the loop to unref any leftover data packets
(although again, I don' think there should be any packets left at that
point, as they're all consumed in tcp_in()).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
While improving thread safety of the TCP stack I've introduced a
possible deadlock scenario, when calling tcp_conn_close() in tcp_in().
This function shall not be called with connection mutex locked, as it
calls registered recv callback internally, which could lead to deadlock
between TCP/socket mutexes.
This commit moves the tcp_conn_close() back where it was originally
called. I've verified that the thread safety is still solid with the
test apps used originally.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add empty macro for net_if_mon functions if they are not otherwise
defined, like the other functions in the net_if.c file have.
Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
Add new functions to the public CoAP API to configure CoAP packet
retransmission settings. Application may need to re-configure the
settings for example when cellular modem changes connection from
LTE-M to NB-IoT or vice versa.
Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>