"udp bind" and "udp send" commands use the same net context
variable and they fail early if the context is already used.
This prevents from using "udp send" after "udp bind", which
makes the commands hard to use for testing bidirectional
communication. Make "udp send" reuse the already bound
context if possible, and resort to allocating temporary one
otherwise.
Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
In enum tcp_state {}, the CLOSED state was put at the last one.
When we do Sequence & Ack validation, we will need to skip the
CLOSED, LISTEN, SYNSENT states. It is easier for coding if we
put the CLOSED to the front, e.g. if state > SYNSENT. And, in
other OSes, the state sequence is normally defined like this.
Signed-off-by: Shrek Wang <inet_eman@outlook.com>
Update the response callback function signature to allow the callback to
return an error code, which in turn will cause the HTTP client to abort
the download.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The return value can only be -1, errno value should be verified instead
for the actual error code.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
During previous commit of adding interface arg, wrongly change the
parameter count of 'wifi ap enable' to a small one. Change the value
to 47 can fix this issue and match the need of adding interface arg.
Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
Add new TLS socket option, TLS_CERT_VERIFY_CALLBACK, which allows to
register an application callback to verify certificates obtained during
the TLS handshake.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add new TLS socket option, TLS_CERT_VERIFY_RESULT, to obtain the
certificate verification result from the most recent handshake on the
socket. The option works if TLS_PEER_VERIFY_OPTIONAL was set on the
socket, in which case the handshake may succeed even if certificate
verification fails.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Don't reference `net_if_get_by_iface` if `CONFIG_NET_RAW_MODE=y`, since
`net_if.c` is not compiled in that case, leading to linker errors.
Signed-off-by: Jordan Yates <jordan@embeint.com>
In order to support working with multiple VIFs (e.g., STA + AP) add
interface as an option for all commands.
The interface can belong to same chipset or different (hypothetical).
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Useful to see what prefix is being selected for a given
IPv6 address if debugging is enabled.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Always prefer preferred IPv6 address over deprecated one
regardless of prefix length. This works now same way as in
Linux.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
According to RFC793 chapter3.5 with the 'Reset Processing' part,
"In the SYN-SENT state (a RST received in response to an initial
SYN), the RST is acceptable if the ACK field acknowledges the SYN."
So, in the net_tcp_reply_rst() we should use 'ack++' if no ACK
flag but have SYN flag.
And, all the RST packet should use net_tcp_reply_rst() instead of
tcp_out().
Signed-off-by: Shrek Wang <inet_eman@outlook.com>
Connection manager enforces non-blocking disconnect() behavior, yet in
case CONN_MGR_IF_NO_AUTO_DOWN flag is not set, it'd put the interface
down right after, disrupting the disconnect process.
As putting the interface down can be handled in the corresponding event
handler as well, when the interface is actually disconnected, remove the
conn_mgr_conn_if_auto_admin_down() call from conn_mgr_if_disconnect().
To make this work with persistence flag, introduce a new internal flag
indicating that the interface is in active disconnect.
Finally, since it isn't really necessary that disconnect() API call is
non-blocking, remove that requirement.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Fix regression introduced by #88747 that breaks linking
with zperf server enabled but TCP or UDP disabled.
Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
Add missing curly braces in if/while/for statements.
This is a style guideline we have that was not enforced in CI. All
issues fixed here were detected by sonarqube SCA.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
The NULL-pkt parameter for tcp_in() was designed for generating
a SYN packet to start the 1st TCP handshake. It is only used
in net_tcp_connect() and tp_input().
To simplify the tcp_in() code logic and make it better under-
standable, a tcp_start_handshake() is added for net_tcp_connect()
and tp_input() to use. Thus, the tcp_in() only handles the in-
coming TCP packets.
Signed-off-by: Shrek Wang <inet_eman@outlook.com>
https://github.com/zephyrproject-rtos/zephyr/actions/runs/\
15014534061/job/42189411225
We were seeing a linker error of the form
```
picolibc/x86_64-zephyr-elf/lib/32/libc.a(libc_time_time.c.o): \
in function `time':
time.c:(.text.time+0x11): undefined reference to `gettimeofday'
```
Update the dependency from CONFIG_POSIX_TIMERS to
CONFIG_XSI_SINGLE_PROCESS for gettimeofday().
Note: this is really only a workaround. The proper solution would
be to have libc functions not depend on POSIX functions.
Specifically, here
https://github.com/zephyrproject-rtos/picolibc/blob/\
51a8b32857e75345c37652a80b5cda98b28d69e5/newlib/libc/time/\
time.c#L54
and here
https://github.com/zephyrproject-rtos/zephyr/blob/\
3a4e12899c2ae5962a64055f4739f774fb7262e5/lib/libc/common/\
source/time/time.c#L17
Also mentioned in #89068
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Validate that the file descriptor is not a negative number before
writing to the `dispatch_table` `ctx` field. Setting file descriptors
to `-1` is the standard "not in use" value, and in fact the entire array
of `fds` is set to this value in `dns_resolve_init_locked`. This
resolves memory corruption of whichever variable is unfortunate to exist
just before `dispatch_table` in memory.
Signed-off-by: Jordan Yates <jordan@embeint.com>
Keep Alive timeout is represented by 2-byte unsigned integer, however
the corresponding Kconfig option was limited to UINT8_MAX only.
Also, similarly to regular MQTT, allow to disable the Keep Alive
functionality by specifying the Keep Alive value to 0.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
When PPP net_if is changed to dormant, the PPP connection
is terminated asynchronously. This is used so that the driver
can terminate the PPP connection gracefully.
Note: net_if_down() is not used as it would require synchronous
operation which would block the system workqueue thus causing
deadlock.
Signed-off-by: Markus Lassila <markus.lassila@nordicsemi.no>
Turn the MBEDTLS_RSA_FULL selects into depends on.
This is how the other MBEDTLS_KEY_EXCHANGE_* Kconfig options are defined.
This is done to avoid circular dependencies.
At the same time update uses of the affected MBEDTLS_KEY_EXCHANGE_*
Kconfig options to enable/disable the dependencies which used to be
automatically handled.
Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
Error checking of otIp6AddUnicastAddress() and
otIp6SubscribeMulticastAddress() was added recently, however it wasn't
taken into account that those APIs return an error on attempt to
register an IPv6 address that is already present on the OT interface.
Therefore, add more specific error checks, to return silently in case
address was already present.
As those two APIs are not very consistent, and otIp6AddUnicastAddress()
returns OT_ERROR_INVALID_ARGS in such cases, add an extra check if the
address is already present before attempting to register the address.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
After the PR #85000 the calculation of NUM field of
Block 1 option on CoAP Ack packet started to advance
to next packet block.
We should not update the ctx->current field because it is
used for calculating the NUM field in response packet.
It should point to beginning of the payload,
so the response is correct.
Leshan server don't seem to care about this, but Coiote does.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
There was wrong implementation in pkt frag removing and inserting.
This was causing infinite loop in either net_buf_frag_last or
net_pkt_get_len. This happened only when the pkt frag removing
and inserting was executed too fast after sending pkt before
ethernet_send calling net_pkt_get_len.
Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Set connection manager to unstable. It is now used
by multiple parts in zephyr and numerous samples.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
Add option to use the connection manager to
schedule a (re-) sync on connection and diabeling the
work, when there is no connection.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
Use connection manager to deactivate and activate
net log backend.
This removes the warnings about dropped packages
completly.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
Avoid early enabling of the syslog backend in
the the dhcpv4 options parser.
When CONFIG_NET_IPV4_ACD is enabled, the assigned ip address has
not been checked, when the other dhcpv4 options are parsed, this would
lead to the syslog backend being enabled before the src ip address
is valid, so we get lots of warnings about dropd packets, this fixes
it at least on start. We will still get the warnings, when the iface
goes down and then up later.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
MLD APIs are commonly used across the codebase to configure IPv6
multicast addresses on network interfaces. Sending MLD reports however
works only for native interfaces as it uses low-level APIs. Therefore,
in order to make the APIs at least semi-functional for offloaded
interfaces as well (i.e. allow to configure multicast address on
the interface), return early in case interface is offloaded.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
IGMP APIs are commonly used across the codebase to configure IPv4
multicast addresses on network interfaces. Sending IGMP reports however
works only for native interfaces as it uses low-level APIs. Therefore,
in order to make the APIs at least semi-functional for offloaded
interfaces as well (i.e. allow to configure multicast address on
the interface), return early in case interface is offloaded.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Use zsock_inet_ntop() instead of inet_ntop() to avoid dependency to the
POSIX subsystem in the library.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The result of the transport init() function should be propagated to the
application, otherwise the initialization could fail silently.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
UDP transport for the MQTT SN libraries depends on IGMP/MLD APIs
unconditionally (via respective setsockopt calls) and without them being
enabled transport initialization would fail. Therefore, ensure
respective multicast libraries are always enabled if MQTT SN UDP
transport is used.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Each incoming TCP packet has been completely handled in current
state. No need to do further process by 'goto next_state'.
Signed-off-by: Shrek Wang <inet_eman@outlook.com>
Many cellular modems attempt to negotiate an ACCM value of 0x00000000.
While the PPP driver rejects this by default, it does not propose an
alternative. As a result, some modems default to using 0x00000000 after
LCP negotiation. Because the PPP driver expects all control characters
to be escaped, this causes issues during decoding. This change
negotiates an ACCM value of 0xffffffff to ensure compatibility with such
modems.
Signed-off-by: Vytautas Virvičius <vytautas@virvicius.dev>
According to RFC 2131, DHCP clients should use the same xid as
received in the Offer message when sending DHCP Requests. Therefore,
when generating DHCP Request message, the xid value should not be
incremented.
One vague topic is whether the xid value should be updated when
sending Requests from Renewing or Rebinding states, however RFC makes no
exception for those states, and other implementations (dhclient, lwip)
seem to reuse the same xid in such cases, so comply with this behavior.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Pad option (option code 0) can be present in between other options for
alignment. The option has a fixed 1-byte length (i. e. no length field),
therefore it did not fall under the common processing code for
unrecognized options (which include the length field at the second
byte). Therefore, not processing this option explicitly could disturb
other options processing, as the parser would wrongly interpret the next
option code as the length field. This commit adds Pad option handling to
fix the issue.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case the received DHCP message is malformed and contains invalid
message type, the code responsible for matching message type with a
string would assert. This shouldn't be the case that external conditions
(like receiving malformed packet) trigger asserts in the system.
Therefore modify that code, to return "invalid" string in such case
instead.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Response "data_len" field needs to be set with the size of the
received data before calling the parser as it's used inside the on_body
callback, this commit fixes it.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Current clock synchronization was always stepping clock. This was
causing large offset, and discontiguous ptp hardware clock time.
For TSN hardware, discontiguous ptp hardware clock time was not
able to be used for other TSN protocols.
This patch is to convert to frequency adjustment with a basic
PI control algorithm.
Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
At the starting of ptp syncrhonization, there may be not Sync frame
TX/RX timestamps in first time link delay calculation.
So, need a check for that in case of wrong link delay calculated.
Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
According to TCP Spec. RFC793, ACK flag should be always set
after sequences of both sides are sync-ed except for RST seg-
ment. It is not necessary to send FIN only packet in the
test case, using FIN | ACK instead.
Similarly, change the tcp_out(conn, FIN | ACK) in CLOSE_WAIT.
Signed-off-by: Shrek Wang <inet_eman@outlook.com>
Move OpenThread-related code from
zephyr/subsys/net/l2/openthread/openthread.c to
zephyr/modules/openthread/platform/openthread.c.
The primary goal of this refactor is to enable the use
of OpenThread as an independent module, without the necessity
of Zephyr's networking layer.
This change is particularly beneficial for simple applications
that have their own implementation of the IEEE802.15.4 driver
and do not require a networking layer. These applications can
now disable Zephyr's L2 and IEEE802.15.4 shim layers and
directly use the OpenThread module, saving valuable kilobytes
of memory.
In this approach if the CONFIG_NET_L2_OPENTHREAD
Kconfig option is set, Zephyr's L2 and IEEE802.15.4 layers
will be used, and everything will function as before.
The main difference is the Zephyr's L2 layer now uses
the OpenThread module, no longer implementing it.
While most of the functions in include/net/openthread.h
have been deprecated, they are still available for use to
maintain backwards compatibility.
Signed-off-by: Arkadiusz Balys <arkadiusz.balys@nordicsemi.no>
Doing another init of the log_backend_net in
the net config init could lead to the
server, set during runtime, being overwritten
by the Kconfig default.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
In case HTTP client read out more data from a socket that it processed
it will indicate there is leftover data in the receive buffer available.
Make use of it at the websocket level, so that no data is lost. As we
reuse the same receive buffer in this case, it's only needed to update
the count variable to indicate how many bytes are available.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The HTTP client would read data from a socket up to the size of the
receiving buffer, however it may not process them all. This is usually
only the case if protocol switching takes place, where the data read may
belong to another protocol. Therefore we need a way to notify the caller
about any potential data that is already present in the buffer and needs
to be processed.
Introduce an new data_len member in struct http_request to provide the
information about the data already available in the receive buffer. If,
after HTTP response processing, the value is non-zero, the data will be
available in the beginning of the user provided receive buffer.
To make this possible however, we need to track how many bytes were
actually processed by the http_parser, therefore the code will no longer
ignore the http_parser_execute() return value. To simplify processing,
it's also been changed how the receive buffer is used. Instead of using
it in a ring-buffer-like way, the offset variable will track how many
bytes are available in the buffer, and in the rare occasions when not
all data from the buffer was processed by the HTTP parser, we'll
memmomve the remaining data to the beginning of the buffer.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Current clock synchronization was always stepping clock. This was
causing large offset, and discontiguous ptp hardware clock time.
For TSN hardware, discontiguous ptp hardware clock time was not
able to be used for other TSN protocols.
This patch is to convert to frequency adjustment with a basic
PI control algorithm.
Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>