Commit graph

133 commits

Author SHA1 Message Date
Marcin Niestroj 87a6df2a9b drivers: nsos: support IPV6_V6ONLY getsockopt() and setsockopt()
Handle IPV6_V6ONLY option in getsockopt() and setsockopt() APIs.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2024-05-17 11:12:43 +02:00
Marcin Niestroj d47ec4f75d drivers: nsos: support IPPROTO_TCP getsockopt() and setsockopt()
Handle IPPROTO_TCP specific options in getsockopt() and setsockopt() APIs.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2024-05-17 11:12:43 +02:00
Marcin Niestroj 736fe29349 drivers: nsos: support ioctl(FIONREAD)
This further increases compatibility with tests defined in
'tests/net/socket/udp/'.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2024-05-17 11:12:43 +02:00
Marcin Niestroj cd2c425efe drivers: nsos: support setsockopt(SO_RCVTIMEO)
Handle timeout on receive that is configured using SO_RCVTIMEO.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2024-05-17 11:12:43 +02:00
Marcin Niestroj a3f2b5f4b3 drivers: nsos: initial support for getsockopt() and setsockopt()
Add initial support for getsockopt() and setsockopt() on SOL_SOCKET level.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2024-05-17 11:12:43 +02:00
Marcin Niestroj 3111261940 drivers: nsos: fcntl: prefer Zephyr-specific macros over libc
Definitions of fcntl flags are different between native libc and Zephyr. In
order to correctly map those values to the host, include Zephyr's fcntl.h
header, instead of the one bundled with libc.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2024-05-13 14:22:46 +02:00
Marcin Niestroj bf637bf623 drivers: net: nsos: implement sendmsg()
Implement sendmsg() socket API to have increased compatibility with
components like MQTT client.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2024-04-19 10:07:42 +02:00
Marcin Niestroj 26bc2e2952 drivers: net: nsos: pass addrlen by value in sockaddr_to_nsos_mid()
There is no reason to pass addrlen by pointer, since it is a read-only in
the context of sockaddr_to_nsos_mid().

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2024-04-19 10:07:42 +02:00
Marcin Niestroj ea44e2715a drivers: net: nsos: update unwatched file descriptor with poll()
zsock_poll_internal() iterates through all fds to call
ZFD_IOCTL_POLL_UPDATE on them. In cases when -EAGAIN is returned from one
of such syscalls (which happens for example for TLS sockets when in the
middle of a TLS handshake) whole fds array is iterated once again. This
means that ZFD_IOCTL_POLL_UPDATE can be called more than once for a single
preceding ZFD_IOCTL_POLL_PREPARE operation. This resulted in error in
nsos_adapt_poll_remove() call, which was not intended to be called twice.

In case ZFD_IOCTL_POLL_UPDATE is called second time, update 'revents' just
by calling poll() syscall on the host (Linux) side with 0 timeout.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2024-04-10 11:30:04 -04:00
Marcin Niestroj 7c506fad6b drivers: net: nsos: fix error message on EPOLL_CTL_DEL error
Fix a copy-pasted error message to reference proper epoll_ctl() operation.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2024-04-10 11:30:04 -04:00
Fin Maaß 3ffad11b22 drivers: net: use sys_rand8_get
use sys_rand8_get() instant of sys_rand32_get().

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-04-05 12:28:46 +02:00
Jukka Rissanen 7fdebb5a91 drivers: net: ppp: Add packet capture support
User is able to enable packet capture for low level HDLC data
frames received from and sent to network. This data can sent to
remote system for analysis. The captured data is encapsulated
into Linux cooked mode SLL packets.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-04-04 17:02:11 +02:00
Marcin Niestroj 226f247006 drivers: net: nsos: fix compatibility with CONFIG_POSIX_API=n
Improve code consistency and fix CONFIG_POSIX_API=n compatibility with use
of ZSOCK_* and DNS_* macros.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2024-04-04 17:01:38 +02:00
Marcin Niestroj 4f9e3fa1b7 drivers: net: nsos: support blocking accept() and recvfrom()
So far only non-blocking accept() and recvfrom() were suported. This patch
implements blocking behavior, with the use of poll(fd, POLLIN) as helper
mechanism.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2024-03-22 14:39:27 +01:00
Marcin Niestroj 8487fcca5b drivers: net: nsos: implement poll() syscall
Use NSI_HW_EVENT() in order to periodically check for events in host
sockets. Whenever there is a socket event ready to be processed by Zephyr,
raise native_sim (newly introduced) CPU interrupt, so that Zephyr driver
can signal readiness with k_poll().

Maintain a list of Zephyr poll() executions in Zephyr context. Iterate
through them whenever there is some event to be processed.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2024-03-22 14:39:27 +01:00
Marcin Niestroj 483c41d209 drivers: net: nsos: add F_GETFL and F_SETFL support
This allows to use Zephyr TLS subsystem with Native Sim offloaded sockets.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2024-03-22 14:39:27 +01:00
Marcin Niestroj 4317cd4576 drivers: net: nsos: add IPv6 support
Add support for IPv6 socket offloading, next to existing IPv4 support.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2024-03-22 14:39:27 +01:00
Marcin Niestroj d1adffc123 drivers: net: nsos: add DNS offload support
Extend driver to support DNS by offloading getaddrinfo() and freeaddrinfo()
APIs.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2024-03-22 14:39:27 +01:00
Marcin Niestroj 07edc9a070 drivers: net: nsos: new driver for Native Simulator offloaded sockets
Add driver for 'native_sim' target that implements offloaded socket
networking by the use of host networking stack and wrapped BSD sockets API.

This driver has following advantages over existing networking drivers for
emulated platforms that are already in tree:
 * no TUN/TAP use means that no additional setup is required on the host
   side:
   * possible to use it within unpriviledged Docker containers, either for
     development or in CI
 * possibility to use and test offloaded sockets
   (CONFIG_NET_SOCKETS_OFFLOAD=y) with emulated target, which allows
   to increase tests coverage of this feature, without requirement of using
   hardware

Native Simulator host libc has different error codes than embedded libc
used by Zephyr. Convert between those.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2024-03-22 14:39:27 +01:00
Pieter De Gendt e99b5228a1 drivers: ethernet: Introduce ETH_DRIVER_RAW_MODE option
Add a Kconfig symbol to allow building ethernet device driver without
an L2 layer.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-03-20 08:05:55 -05:00
Jukka Rissanen 8860a81cfe drivers: Change drivers to support new IPv4 netmask setting API
Make sure that the drivers use the new IPv4 netmask setting API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-03 18:58:29 +01:00
Tomi Fontanilles 490a02fda7 drivers: net: ppp: improve CONFIG_NET_PPP_ASYNC_UART_TX_TIMEOUT
Its default value (100 ms) resulted in PDUs big enough to never make it
through on a slow enough UART (e.g. ~1152-byte PDUs on a UART@115200).
The UART TXs were silently aborted.

A no-timeout value is now allowed and made the default.
Additional warnings are logged when it is likely that a UART TX
was aborted due to a too low timeout for the used baud rate.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2023-12-18 09:29:07 +01:00
Tomi Fontanilles 9b78b4e894 drivers: net: ppp: various fixes
- Disable UART when the PPP interface is brought down.
  This prevents an error when it is next brought up.
- Change the level of certain logs to be less concerning
  and less verbose.
- Fix warnings regarding the passed parameter types of %p conversions.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2023-12-18 09:29:07 +01:00
Jukka Rissanen f9b5dc20f7 drivers: net: loopback: Do not change the original pkt
When we are sending a network pkt, do not tweak the original
packet but the cloned one. The original behavior is ok too, but
logically we should adjust the cloned packet only that is being
received by the stack. This also means that we avoid one extra
copy to tmp variable when sending the packet.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-12-13 09:42:12 +01:00
Robert Lubos c7ac921640 net: loopback: Register IPv4 netmask
A proper netmask should be set on the loopback interface, so that
source address selection work properly when there are multiple
interfaces in the system.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-15 13:53:27 +01:00
Flavio Ceolin e7bd10ae71 random: Rename random header
rand32.h does not make much sense, since the random subsystem
provides more APIs than just getting a random 32 bits value.

Rename it to random.h and get consistently with other
subsystems.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-10-10 14:23:50 +03:00
Fabio Baltieri 2a2b314fc4 drivers: fix few mismatched CONTAINER_OF
Fix few mismatched CONTAINER_OF, one missing k_work_delayable_from_work
conversion and few cases where the target should be pointing at the
first element explicitly.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-08-30 10:21:23 +02:00
Fabio Baltieri ec71be5d9d drivers,subsys: fix few missing k_work_delayable_from_work
Fix few instances of delayable work handlers using the k_work pointer
directly in a CONTAINER_OF pointing to a k_work_delayable.

This is harmless since the k_work is the first element in
k_work_delayable, but using k_work_delayable_from_work is the right way
of handling it.

Change a couple of explicit CONTAINER_OF doing the same work as the
macro in the process.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-08-28 10:12:21 +02:00
Daniel Leung 5bc08ae3c6 net: rename shadow variables
Renames shadow variables found by -Wshadow.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-10 08:14:43 +00:00
Jani Hirsimäki 83ea1e26a2 net: l2: ppp: ppp uart usage fixed
This fixes 3 issues that came within PR #59124 for ppp uart usage.

Earlier start/stop of ppp was done at enable() but that
was removed in PR #59124. Now putting enable/disable() back and
putting start/stop there.
Additionally, there was a double ppp carrier ON when NET_EVENT_IF_DOWN.
For that net_if_carrier_on/off is set in uart ppp.c driver.
Also, maybe worth to be mentioned that after PR #59124 there is no
ppp carrier off when lcp is disconnected, for workaround that change,
application should use ppp dead/running events.

Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>
2023-08-09 16:07:46 +00:00
Bjarki Arge Andreasen 22152915ab drivers/gsm_ppp: Update existing modules to use PPP L2
This commit replaces the workarounds spread around the
drivers and subsystems with the updated PPP L2
interface.

Signed-off-by: Bjarki Arge Andreasen <baa@trackunit.com>
2023-06-17 07:46:21 -04:00
Henrik Brix Andersen c41dd36de2 drivers: kconfig: unify menuconfig title strings
Unify the drivers/*/Kconfig menuconfig title strings to the format
"<class> [(acronym)] [bus] drivers".

Including both the full name of the driver class and an acronym makes
menuconfig more user friendly as some of the acronyms are less well-known
than others. It also improves Kconfig search, both via menuconfig and via
the generated Kconfig documentation.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-03-28 15:06:06 +02:00
Robert Lubos 16a0e314ea drivers: net: Move Ethernet device definition for SLIP to ethernet
Currently, if CONFIG_SLIP_TAP is enabled (default for QEMU), and no
other Ethernet driver is enabled, the following warning is printed by
CMake:
    No SOURCES given to Zephyr library: drivers__ethernet

This happens because SLIP_TAP enabled Ethernet L2, but has no actual
sources in drivers/ethernet. This commit fixes this, by moving the
actual definition of the SLIP TAP Ethernet interface into a separate
file, within drivers/ethernet. Technically, in that configuration SLIP
defines a Ethernet device, implementing Ethernet API, so such a change
is justifiable, and prevents unwanted warning from being generated.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-02-20 10:52:20 +01:00
Jani Hirsimäki e92b067b7f net: ip: net_context: AF_PACKET/SOCK_RAW/IPPROTO_RAW: set pkt family
Setting a detected packet family (ipv4 or ipv6) in net_context level
instead in lower layers for AF_PACKET/SOCK_RAW/IPPROTO_RAW type sockets
when sending data.

Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>
2023-01-09 19:21:18 +01:00
Erwan Gouriou 66d4c64966 all: Fix "#if IS_ENABLED(CONFIG_FOO)" occurrences
Clean up occurrences of "#if IS_ENABLED(CONFIG_FOO)" an replace
with classical "#if defined(CONFIG_FOO)".

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-12-21 10:09:23 +01:00
Anas Nashif cffe98d9de crc: Make the build of crc function dependent on a Kconfig
Add CONFIG_CRC for building CRC related routines.
CRC routines are now being built for each application, whether used or
not and are add in the build system unconditionally.

Keep CONFIG_CRC enabled by default for now and until all users have
converted to use the new option.

Partial fix for #50654

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-11-23 13:30:00 +01:00
Robert Lubos 387a66131e net: pkt: Introduce minimum length requirement to net_pkt_get_frag()
net_pkt_get_frag() and a few other functions did not specify the
allocated fragment length, incorrectly assuming that fixed-sized
buffers are always used.

In order to make the function work properly also with variable-sized
buffers, extend the function argument list with minimum expected
fragment length parameter. This allows to use net_buf_alloc_len()
allocator in variable buffer length configuration, as well as verify if
the fixed-sized buffer is large enough to satisfy the requirements
otherwise.

Update the existing codebase to provide the expected fragment length,
based on the context.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-11-19 07:39:32 -05:00
Robert Lubos 1d7a077e11 net: ppp: Revert interface management changes
This reverts changes introduced in commit
dd535f611d, as they broke the gsm_ppp
driver integration with PPP L2. Apparently, a more thorough
refactoring is needed to use the new interface management scheme with
PPP.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-11-16 11:21:24 +01:00
Keith Packard c0d95492fc drivers/net: Increase recv_cb buffer to prevent snprintk overflow
While the 'count' value "should" never be larger than two digits,
increase the size of the snprintk buffer to be large enough to hold
the longest possible value.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-10-26 12:00:04 +02:00
Krishna T 3cc1a6e9b2 drivers: net: loopback: Optimize packet drop
If we are dropping packets, then drop then early without the clone, this
improves zperf performance.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2022-10-21 13:15:05 +02:00
Krishna T 3b2243dd0c drivers: net: loopback: Fix typo
Fix a typo in the comment.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2022-10-21 13:15:05 +02:00
Krishna T c23823a996 drivers: net: loopback: Make MTU configurable
This is useful to test higher packet sizes to simulate L2
Ethernet/Wi-Fi.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2022-10-21 13:15:05 +02:00
Robert Lubos dd535f611d net: ppp: Align PPP driver/L2 with iface state upgrade
Align PPP drivers/L2 with interface state handling update. Use the
carrier on/off notification instead of bringing the interface up/down to
update the interface state.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-20 10:00:31 +02:00
Florian Grandel e608e92112 net: context: properly namespace can-related methods
The net_context_set/get_filter_id() methods are CAN specific and should
say so.

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-09-05 14:35:17 +00:00
Henrik Brix Andersen d1d48e8304 net: socketcan: rename SocketCAN header from socket_can.h to socketcan.h
Rename the SocketCAN header from socket_can.h to socketcan.h to better
match the naming of the functionality.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-18 10:19:29 +02:00
Henrik Brix Andersen 13c75417ba drivers: can: remove z prefix from public CAN API types
Remove the "z" prefix from the public CAN controller API types as this
makes them appear as internal APIs.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-18 10:19:29 +02:00
Henrik Brix Andersen d22a9909a1 drivers: net: canbus: move CAN bus network driver to drivers/net
Move the CAN bus network driver from drivers/can to drivers/net as it
implements a network driver, not a CAN controller driver.

Use a separate Kconfig for enabling the CAN bus network driver instead of
piggybacking on the SocketCAN Kconfig. This allows for other
(e.g. out-of-tree) SocketCAN transports.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-07-13 10:34:51 +02:00
Pieter De Gendt aba4c4ea3e uart_pipe: move driver from console to serial
The uart_pipe driver is not dependent on any console driver,
however a serial driver is required.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2022-07-07 09:59:49 +02:00
Kumar Gala 82c65315d3 drivers: ppp: Move to DTS for uart device
Move from using Kconfig NET_PPP_UART_NAME to a devicetree chosen
property ("zephyr,ppp-uart").  This is similar to a number of other
functions like "zephyr,shell-uart" or "zephyr,bt-uart".

As part of this we rework the init code a little to use
DEVICE_DT_GET for the modem gsm-ppp case.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-07-04 12:43:23 +02:00
Sjors Hettinga ae31773ddd drivers: net: loopback: Add counting of number of dropped packets
When the loopback drops driver packets, the number of dropped
packets is counted and can be requested externally.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-05-16 16:55:51 +02:00