In case RST packet is received or malformed packet is received, the TCP
should not proceed with the state machine execution (which may process
the invalid packet) but rather jump directly to exit, where the
connection will be closed.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The net_mgmt subsystem offers a function which waits (blocks)
until a specified net event occurs. An event callback is
pushed to the stack, then added to the net_mgmt_event_callback
list. If the event occurs, the net_mgmt thread calls the
callback and deletes the callback from the list. However, if
the event does not occur within the timeout specified when
invoking mgmt_event_wait_call() the function will return,
corrupting the callback structure the stack is reused.
This PR fixes the issue by deleting the callback before exiting
in case the event does not occur.
Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
Modify the signature of the k_mem_slab_free() function with a new one,
replacing the old void **mem with void *mem as a parameter.
The following function:
void k_mem_slab_free(struct k_mem_slab *slab, void **mem);
has the wrong signature. mem is only used as a regular pointer, so there
is no need to use a double-pointer. The correct signature should be:
void k_mem_slab_free(struct k_mem_slab *slab, void *mem);
The issue with the current signature, although functional, is that it is
extremely confusing. I myself, a veteran Zephyr developer, was confused
by this parameter when looking at it recently.
All in-tree uses of the function have been adapted.
Fixes#61888.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
If network interface name support is enabled, print the name
when showing network interface data.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Make sure we use the network interface name (if configured)
instead of device name when binding to certain network
interface.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
If CONFIG_NET_INTERFACE_NAME is enabled (default is y), then
system will automatically set a user friendly name to the network
interface like eth0, wlan0 etc.
Application can change the interface name if needed.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The twt and ps helper functions were not namespaced (were missing
wifi_ prefix).
Also change wifi_get_twt_... to more logical wifi_twt_get...
like the other twt prefixed functions and wifi_get_ps... to
wifi_ps_get... like the other ps prefixed functions.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Add TLS_DTLS_CID socket option, which enables to use the Connection ID
extension for the DTLS session.
The option provides control of the use of CID with the `setsockopt()`
function. The value provided can disable, enable, and control whether to
provide a CID to the peer. It uses a random self CID (if told to provide
one to the peer) unless TLS_DTLS_CID_VALUE set previously.
Add TLS_DTLS_CID_VALUE to get or set the CID sent to the peer, if any.
Add TLS_DTLS_PEER_CID_VALUE to get the CID value provided by the peer,
if any.
Add TLS_DTLS_CID_STATUS to determine if CID used, and whether
bidirectional or one way.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Signed-off-by: Pete Skeggs <peter.skeggs@nordicsemi.no>
Fix few mismatched CONTAINER_OF, few missing k_work_delayable_from_work
and a missing reference to the array first element.
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
The connectivity monitoring subfeature of conn_mgr is currently also
named conn_mgr, which is confusing.
This commit renames it to conn_mgr_monitor, or conn_mgr_mon for short,
for clarity.
Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
Add a helper allowing connectivity implementations to more easily access
connectivity flags on connectivity bindings.
Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
Adds conn_mgr_binding_lock/conn_mgr_binding_unlock, which connectivity
implementations can call to lock or unlock the passed in connectivity
binding.
This allows connectivity implementations to safely make direct accesses
to binding data from outside conn_mgr_conn_api callbacks, and should
allow cleaner, more robust connectivity implementations to be written.
Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
Splits many definitions from conn_mgr_connectivity.h off into their own
header, conn_mgr_connectivity_impl.h
conn_mgr_connectivity.h now focuses solely on user/application-facing
APIs, and conn_mgr_connectivity_impl now contains all functions, utils,
definitions intended for use by connectivity implementations, including
conn_mgr_if_get_binding, which is now available for use by connectivity
implementations.
This lays the foundation for allowing connectivity implementations
easier and safer access to their internal state through internal APIs.
Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
This change allows to register additional handlers for ICMPv6 so the
user can handle some of the messages between they are handled by the
ICMPv6 module in Zephyr by returning NET_CONTINUE.
Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
There was a corner case which was not handled well in a scenario, when
listening socket was closed during an active handshake with a new
client.
When a listening socket is closed, the accept callback is cleared on the
TCP context. If this happened during a handshake with a new client, i.
e. before final ACK from the client was processed, this lead to a
context leak, as application did not take ownership of the connection
(i. e. had no means to close it).
Fix this, by proactively closing the connection at the TCP level when no
accept_cb is available. Instead of ignoring the fact that no accept_cb
is available, the TCP stack will now enter TCP_FIN_WAIT_1 state and
proceed with a graceful teardown of the connection.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
getsockname() did not work properly on bound sockets, as it verified
whether the socket has an active connection before retuning result. This
is not correct, as socket after bound may not have a connection yet.
Fix this, by verifying that local_addr on an underlying net_context is
set, to determine whether socket has a local address assigned, before
returning result.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
* Renamed 'coap_client_init_path_options' to
'coap_packet_set_path'
* Moved into 'coap.c'
* The function is public now
Signed-off-by: Georgij Cernysiov <geo.cgv@gmail.com>
Fix options initialization for path and query
when a final segment is one character long.
For example, "a/b" inits path as ["a"] instead
of expected ["a", "b"]. The same applies to
query option. The "a/abc?a&b" options won't
contain "b".
Signed-off-by: Georgij Cernysiov <geo.cgv@gmail.com>
net_iface_status is larger than scan_result, causing
net_iface events to be dropped due to info exceeding
NET_EVENT_INFO_MAX_SIZE.
Signed-off-by: Noah Luskey <LuskeyNoah@gmail.com>
The previous patch to address race condition on STREAM sockets had a
side effect on DGRAM socket, where net_context_recv() is not only
installing recv callback, but also registering a connection at net_conn
level. Doing so before setting remote address first (which is done in
net_context_connect()) had an impact on the connected DGRAM socket
operation, which now accepted packets from any remote peer, and not only
the one socket was connected to.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
ICMPv6 messages with type < 128 are error messages, where we should not
send back another error. The meaning of the code depends on the type.
Signed-off-by: Andreas Müller <andreas.mueller@husqvarnagroup.com>
When resource data length is set to zero, we still need to
ensure that string reading will return an empty string.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Changed Add to Enable in help text to convey the intended use of the
Kconfig NET_L2_WIFI_MGMT.
Signed-off-by: Sachin D Kulkarni <sachin.kulkarni@nordicsemi.no>
Add a scan command option to print the help text for the scan command.
This is to facilitate ease of using the command (since now there are
many different options added to the scan command).
Signed-off-by: Sachin D Kulkarni <sachin.kulkarni@nordicsemi.no>
Add scan extension to allow limiting the scanning to specific channels.
Only 20 MHz channel specifications are allowed presently.
Signed-off-by: Sachin D Kulkarni <sachin.kulkarni@nordicsemi.no>
Add scan extension to allow limiting the scan results to a user defined
maximum number. This parameter is intended to return results with the
best RSSI. It cannot be counted upon to limit the scan times since the
Wi-Fi chips might have to scan all the channels to find APs with the
best RSSI values across all channels.
Signed-off-by: Sachin D Kulkarni <sachin.kulkarni@nordicsemi.no>
Add scan extension to control scanning time spent on channels where
passive scanning is used.
Signed-off-by: Sachin D Kulkarni <sachin.kulkarni@nordicsemi.no>
Added scan extension to support scanning individual Wi-Fi bands or
combinations thereof.
Signed-off-by: Sachin D Kulkarni <sachin.kulkarni@nordicsemi.no>
Modify the way the scan type option is passed to the wifi scan command.
This makes it flexible to add more scan options.
Signed-off-by: Sachin D Kulkarni <sachin.kulkarni@nordicsemi.no>
There are a few structs, unions, and enums where -Wshadow would
complain. Since names being the same are intentional, we need
to tell compiler to ignore -Wshadow for those names.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
When the application closes the connection, it enters the FIN1 state.
Restructure this sequence to RST on data received after the application
has closed the socket.
Next to that deal with packets that contain both data and a FIN flag.
Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
The `ioctl()` interface is already supported by the network
subsystem but there was no `zsock_` interface available for it.
Add the `zsock_ioctl()` syscall.
Implement two somewhat commont ioctl requests for socket
file descriptors; namely
- `FIONBIO` set non-blocking I/O mode
- `FIONREAD` get the number of available bytes
In the process, added `net_pkt_ip_proto_hdr_len()`
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
In order to get a semi-accurate assessment of how many
bytes are available on a socket prior to performing a read,
BSD and POSIX systems have typically used
`ioctl(fd, FIONREAD, &avail)`
We can support this in Zephyr as well with little effort, so
add support for `socketpair()` sockets as an example.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Previously, if a net_context had multiple packets already in
the receive queue, and a call to zsock_recvfrom() was made with
a buffer large enough to receive content from multiple packets,
only the content from a single receive buffer would be received.
Since zsock_recvfrom() is a system call, which has a
non-negligible overhead, it makes sense to receive as many bytes
as possible per system call.
Add zsock_recv_stream_immediate() as a shorthand for
"fill this receive buffer with as many bytes as possible without
blocking". Allow nullable buffer parameters so that we can also
have a shorthand for "count how many bytes are immediately
available".
With minor refactoring, zsock_recv_stream_timed() is a simple
wrapper around zsock_recv_stream_immediate() that handles timing
and error conditions.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
The added function allows to check if a descriptive block
option was already added to a message.
Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
In some cases the options of a CoAP message are reused for
block transfer. Then the block header needs to be updated.
The current approach is to remove the old block option and
add an updated one.
Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
The provided function allows to remove a CoAP option in a
message. This is useful for reusing parts of a message.
Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
The reply callback doesn't need to handle the case when the
code of the reply is 'continue' (2.31). In that case the callback
is not executed until the last block is transmitted.
Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
When using block-wise transfer, call the reply callback only when
the last block arrived.
Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>