Commit graph

53 commits

Author SHA1 Message Date
Jukka Rissanen
5a9a39caf3 net: mgmt: Convert the mgmt API to use 64-bit masks
Instead of using 32 bit enum values for event numbers, convert
the code to use 64 bit long bit fields. This means that the
user API is changed to use 64 bit event values instead of 32
bit event values.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-06-18 10:54:44 +02:00
Keith Packard
ec38e9ef64 wifi/esp32: Fix overflow in SSID copy
In the previous code, strnlen could have returned WIFI_SSID_MAX_LEN, and
the following statement ensuring NUL termination would have written one
past the end of the array.

Replace this with code that ensures a NUL termination within the bounds
of the array and then use strlen to compute the length.

Signed-off-by: Keith Packard <keithp@keithp.com>
2025-06-17 16:06:21 +02:00
Gregor Copoix
3da78086ae driver: wifi: esp32: fix send data for AP_STA mode
Fixes the check for connected interface if CONFIG_ESP32_WIFI_AP_STA_MODE=y
(different data objects for STA (esp32_data) and AP (esp32_ap_sta_data)).
As the correct data object is linked to device object, we can check for
ESP32_STA_CONNECTED or ESP32_AP_CONNECTED in dev->data.
This fixes AP mode in samples/net/wifi/apsta_mode if STA WIFI_SSID/WIFI_PSK
are invalid and no STA connection can be established before
(samples/net/wifi/apsta_mode/src/main.c#L28-L29) for all ESP32 derivates.

Fixes false check from 183b74c558

Signed-off-by: Gregor Copoix <gregor.copoix@ithinx.io>
2025-05-13 22:20:29 -04:00
Sylvio Alves
183b74c558 driver: wifi: esp32: fix send event when not connected
Make sure send event returns error when device is not connected
into STA or have AP mode in place.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2025-03-06 08:35:29 +00:00
Oskari Seppä
de91ecdc5f drivers: wifi: esp32: Fix AP-STA mode interface init order
Wi-Fi AP-STA mode fails on ESP32 due to incorrect interface
initialization. In AP-STA mode, esp32_wifi_init first sets the driver's AP
interface, followed by the STA interface. However, the driver initializes
them in reverse order, causing both to read incorrect device data and
resulting in a "Wi-Fi not in station mode" error.
This fix handles STA and AP initialization in separate functions and
checks for correct mode in esp32_wifi_status.
Tested on a custom ESP32-S3-WROOM-1-N4R2 board, where both STA and AP
can connect, send, and receive data.

Signed-off-by: Oskari Seppä <seppaoskari@gmail.com>
2025-02-18 18:37:49 +01:00
Eric Holmberg
de3ce03319 drivers: wifi: esp32: connect to highest signal AP
The station-mode channel scan method is currently set to WIFI_FAST_SCAN
which ignores the signal strength and connects to the first channel found
which may result in poor WiFi bandwidth.

Change the scan mode to scan all channels and connect to the channel with
the highest RSSI.

Fixes #84488

Signed-off-by: Eric Holmberg <eric.holmberg@northriversystems.co.nz>
2025-01-29 22:30:42 +01:00
Pisit Sawangvonganan
60a2888d0b wifi: esp32: enhance handling of AP connect events
This commit aims to improve the integration of `esp_wifi_drv` by
providing the link mode information to `wifi_mgmt` when a station device
is connected to the AP.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-12-16 13:10:29 +01:00
Sylvio Alves
b5c53d6ac4 wifi: esp32: move kconfig to driver area
Make sure all kconfig related to Wi-Fi is
in its driver area.
This commit also removes esp_timer_init() call
from Wi-Fi driver.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2024-10-27 20:53:48 -05:00
James Roy
b443929f49 drivers: esp32: Fix esp_wifi_drv strncpy warning
Add '\0' to the end of the ssid to prevent warnings
or segmentation errors.

Signed-off-by: James Roy <rruuaanng@outlook.com>
2024-10-25 08:53:26 +02:00
Sylvio Alves
882ac1d088 drivers: esp32: wifi/bt: modify init call return error
Update both Wi-FI and BLE init codes to return proper
error code and logging when it is missing heap.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2024-10-17 09:45:02 +02:00
Marcio Ribeiro
c20e43caaf drivers: wifi: esp32: adc2 init code calibration
Add call to adc2_init_code_calibration during wifi initialization on
esp32s2 and esp32c3

Signed-off-by: Marcio Ribeiro <marcio.ribeiro@espressif.com>
2024-10-09 09:43:58 +02:00
Sylvio Alves
b4117f97d3 drivers: wifi: fix esp32 build error
There is a regression caused by #76177, which
causes build to fail due to missing includes and others.
This wraps it with proper checks and fixes wifi scan call.

This also remove unused variable present in the same driver.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2024-09-11 20:14:07 -04:00
Sylvio Alves
8233b70ece espressif: clean up unused code
Remove all entries that as not being used.
This also update hal to re-enable warning flags
as such as -Wno-unused-variable.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2024-09-09 13:55:39 -04:00
Muhammad Haziq
91b688a666 driver: wifi: esp32: add APSTA support
The ESP32 Wi-Fi driver previously did not support APSTA mode,
enabling AP mode would disable STA mode and vice versa.
Support for APSTA has been added by introducing additional
network interface: one for STA (Interface 2) and one for
AP (Interface 1). The CONFIG_ESP32_WIFI_AP_STA_MODE option in
Kconfig now allows enabling or disabling this support.

Signed-off-by: Muhammad Haziq <muhammad.haziq@zintechnologies.com>
2024-09-06 11:28:15 -04:00
Pisit Sawangvonganan
9347887b33 wifi: esp32: update link_mode to reflect actual negotiated PHY mode
Updated `link_mode` assignment to reflect the actual negotiated PHY mode
by using `esp_wifi_sta_get_negotiated_phymode`.

Since `ap_info.phy_11b` ... `ap_info.phy_11ax` represent the access point
capabilities and not the actual current link mode.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-08-16 16:29:36 +01:00
Sylvio Alves
6ade0cf715 wifi: esp32: fix memory leak
In case where the system is overloaded, net stack buffer
could fail to allocate next packet. That scenario requires
wifi internal Wi-Fi driver to free current rx buffer. This is
currently not being called. This fixes it by making sure
esp_wifi_internal_free_rx_buffer() is called in all scenarios.

Fixes #63043

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2024-07-08 20:41:16 -04:00
barry batsbak
2b7a39e83c drivers: wifi: add bssid/mac to wifi_scan result
copy bssid in wifi scan result if set

Signed-off-by: barry batsbak <sonofviking@protonmail.com>
2024-06-13 17:50:08 +02:00
Lucas Tamborrino
fe57a12cf2 drivers: esp32: update to hal_espressif v5.1
Modify necessary drivers to meet updated hal.

Signed-off-by: Lucas Tamborrino <lucas.tamborrino@espressif.com>
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2024-04-05 13:39:53 +02:00
Jordan Yates
ef21569ac9 wifi: conn_mgr connectivity bindings
Bind WiFi network devices to the generic WiFi connectivity backend if
the appropriate option is set.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2024-01-30 18:51:46 -05:00
Keith Packard
07943eae86 drivers/wifi/esp32: Remove _POSIX_C_SOURCE define as unneeded
This driver doesn't use any APIs outside of the Zephyr C library list, so
it doesn't need this _POSIX_C_SOURCE define.

Signed-off-by: Keith Packard <keithp@keithp.com>
2024-01-26 07:48:55 -05:00
Sylvio Alves
b8d887f0e1 net: wifi: esp32: disable automatic reconnection on leaving
Automatic Wi-Fi station reconnection is forced even when
application requests disconnection. This PR adds a check
in the disconnection event reason to decide whether or not
perform the reconnection.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2023-12-11 09:57:02 +01:00
Marc Lasch
afa1bd842c drivers: wifi: esp32: Mute implicit function declaration warning
Mute the function declaration warning, the compiler was emitting when
compiling the esp32 Wi-Fi driver with IPv4 disabled. The
net_dhcpv4_start() function was visible during compile time, even when
IPv4 was disabled.

Signed-off-by: Marc Lasch <mlasch@mailbox.org>
2023-12-05 10:22:30 +00:00
Marek Matej
d5a1a8bf04 drivers: wifi: esp32: Fix compilation error
Fix function declaration.

Signed-off-by: Marek Matej <marek.matej@espressif.com>
2023-11-05 20:05:51 +01:00
Benedikt Schmidt
a03f1010b8 drivers: fix thread function signatures
Fix thread function signatures to avoid stack corruption on thread exit.

Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
2023-10-30 12:24:34 +01:00
YuLong Yao
0ad0dea200 driver: wifi: esp32: fix esp32_wifi_send not work in ap mode
use `ESP_IF_WIFI_AP` when call esp32_wifi_send in ap mode

Signed-off-by: YuLong Yao <feilongphone@gmail.com>
2023-08-16 14:56:27 +02:00
YuLong Yao
af0583d87d driver: wifi: esp32: enable iface when enable ap mode
when ap mode is enable,
we don't enable iface by `net_eth_carrier_on` before,
this will cause wifi tx error.

this patch fix this issues.

Signed-off-by: YuLong Yao <feilongphone@gmail.com>
2023-08-09 08:34:56 +00:00
YuLong Yao
28f5366e0e drivers: wifi: esp32: choose channel 0 by default
When channel set to WIFI_CHANNEL_ANY, ap will not work.
This patch choose channel 0 when channel is WIFI_CHANNEL_ANY.

Signed-off-by: YuLong Yao <feilongphone@gmail.com>
2023-08-09 08:32:39 +00:00
Chaitanya Tata
a132487fec net: wifi: Move Wi-Fi ops to a separate struct
Decouple interface and Wi-Fi APIs, Wi-Fi APIs are common independent of
Wi-Fi offload or implemented natively (This is preparation for
introducing Native Wi-Fi).

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-07-11 14:55:30 +02:00
Marek Matej
6e72e401f2 drivers: wifi: Fix esp32 driver
Fix compilation issue on esp_wifi_drv.

Signed-off-by: Marek Matej <marek.matej@espressif.com>
2023-07-04 15:28:03 +02:00
Ajay Parida
69fead1998 net: mgmt: Support for forced Passive scan
Default scan mode is Active. User can force the scan mode to passive
through Kconfig option or using 'passive' option from shell.
Using either of this option will override regulatory settings and
forces all scan channels to be passive only.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2023-06-29 21:05:41 +02:00
Chaitanya Tata
7987098497 drivers: wifi: Register Wi-Fi architecture type
Identify the Wi-Fi capability to the networking stack and also the type
of Wi-Fi (Native vs Offloaded), this helps identifying Wi-Fi interfaces
that can be used by applications.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-06-26 16:12:32 +02:00
Sylvio Alves
cc3ba0cd1a driver: wifi: esp32: add wifi statistics info
Adds Wi-Fi statistics feature.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2023-05-11 10:05:04 +02:00
Sylvio Alves
0b32c1f851 driver: wifi: esp32: add status information
Adds Wi-Fi driver connection status details.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2023-05-11 10:05:04 +02:00
Marcin Niestroj
a2e5d1dcd2 drivers: wifi: esp32: register rxcb after wifi init
Move esp_wifi_internal_reg_rxcb() after esp_wifi_init(), so that
wifi_connect() is successful.

Fixes: 690f65dbd9 ("drivers: wifi: esp32: fix possible interface null
  pointer")
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2023-03-20 11:43:49 +01:00
Sylvio Alves
690f65dbd9 drivers: wifi: esp32: fix possible interface null pointer
esp32_wifi_dev_init() currently starts Wi-Fi stack before
the interface is properly configured, which happens in function
esp32_wifi_init(). This can trigger a ESP32_WIFI_EVENT_STA_START event
before interface initialization, causing a crash.
Moving esp_wifi_start() to esp32_wifi_init() will guarantee that
this won't happen.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2023-03-06 16:44:45 +01:00
Sylvio Alves
b7b8830c7c driver: wifi: esp32: remove build warning
Removes strnlen implicit declaration when newlibc
is enabled.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2022-11-30 13:40:10 +01:00
Robert Lubos
b279bfd2dd net: ethernet: Align Ethernet drivers/L2 with iface state upgrade
Align Ethernet/Wi-Fi drivers/L2 with interface state handling update.

For drivers, that did not support carrier detection, no changes are
needed.

Driver that did support carrier detection, are updated to set the
carrier state to OFF by default, instead of setting the
NET_IF_NO_AUTO_START flag. This allows to postopne the actual
NET_EVENT_IF_UP notification until driver detects that carrier is ready.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-20 10:00:31 +02:00
Marcin Niestroj
35ba982d84 wifi: esp32: make ethernet carrier on after ESP32_WIFI_EVENT_STA_START
Driver is not ready to handle NET_REQUEST_WIFI_CONNECT wifi_mgmt events
before ESP32_WIFI_EVENT_STA_START event is received. Revert back to setting
NET_IF_NO_AUTO_START flag for interface and call net_eth_carrier_on() after
ESP32_WIFI_EVENT_STA_START event is received. This makes it possible for an
application to wait for network interface to be ready, e.g. with:

  while (!net_if_is_up(iface)) {
     k_sleep(K_MSEC(100));
  }

before making a connect request with:

  net_mgmt(NET_REQUEST_WIFI_CONNECT, iface ...).

Fixes: 7d9edc8bf0 ("wifi: esp32: add support to wifi api mgmt")
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-09-26 07:58:09 +00:00
Thomas Stranger
5521c53848 drivers: wifi: esp32: sp32_wifi_ap_enable: fix ret value overwritten
The return values of esp_wifi_set_mode(), and esp_wifi_set_config() were
overwritten once esp_wifi_start() is executed.

This commit fixes that by ORing the return value to the others.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2022-09-15 17:26:31 +01:00
Sylvio Alves
7fdde112d1 wifi: esp32: update enum naming reference
Due to Zephyr's WiFi updates, common private
enums used in `hal_espressif` are now being used.

This updates private internal values to meet hal_espressif
changes.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2022-09-05 15:32:34 +00:00
Sylvio Alves
a8cacfa530 wifi: esp32: add config to enable automatic DHCPV4 negotiation
ESP32 wifi connection uses Zephyr's net stack. Once WiFi connects
in station mode, is requires the application to handle DHCPv4
negotiation. This PR adds support to automatic negotiation by
handling the dhcpv4 calls in driver layer.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2022-09-05 15:32:34 +00:00
Sylvio Alves
7d9edc8bf0 wifi: esp32: add support to wifi api mgmt
Moved all MBEDTLS dependencies from prj.conf
to Kconfig as WiFi depends on it.

Update esp32 wifi driver to enable `samples/net/wifi`
to work. Commands as such as `wifi connect` and `wifi scan` are now
available.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2022-09-05 15:32:34 +00:00
Sylvio Alves
4928a69a06 drivers: wifi: esp32: remove supplicant init call
Supplicant start call is part of esp_wifi_init, which
would become duplicated if kept in here.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2022-09-01 21:48:18 +00:00
Sylvio Alves
20c3256016 net: wifi: Allow to use offloaded wifi_mgmt API with native stack
wifi drivers that depends on native ethernet stack cannot perform
wifi API calls missing availability. This changes adds the ethernet_api
interface in wifi_mgmt so that it becomes possible.

Naming "offload" in "struct net_wifi_mgmt_offload" is kept because
Zephyr still has no supplicant to handle a full non-offloaded driver.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2022-08-29 17:31:17 +02:00
Gerard Marull-Paretas
fb60aab245 drivers: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all drivers to the new
prefix <zephyr/...>. Note that the conversion has been scripted, refer
to #45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 19:58:21 +02:00
Gerard Marull-Paretas
ba8f7a2dd8 drivers: wifi: drop DEV_DATA/DEV_CFG usage
Stop using redundant DEV_DATA/DEV_CFG macros and use dev->data
and dev->config instead.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-19 18:16:02 +01:00
Pavlo Hamov
18f26b843c drivers: wifi: esp32: fix memmory corruption
Size of data pointer for event revival must be at least sizeof
event queue item.
Update to send whole event (id + event)

Signed-off-by: Pavlo Hamov <p.hamov@venstar.com>
2021-10-14 16:35:17 -04:00
Sylvio Alves
4d37aa828a driver: wifi: add esp event task name
When enabling shell and retrieving thread information,
esp wifi event task name was empty.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2021-07-16 18:59:57 -04:00
Sylvio Alves
4303cfdb3c hal: esp32: driver changes to allow HAL update
hal_espressif repository was updated from esp-idf v4.2
to esp-idf v4.3 to allow latest Espressif chips integration.
As a consequence, it added a few changes in drivers
and peripherals. To maintain bisectability, changes in this
PR cannot be split. Here are some details:

wifi: update linker script by adding libphy and new attributes.

spi: update some APIs and fixed missing wait_idle check

west.yml: esp32: update hal to new version

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2021-07-07 15:01:16 -04:00
Marcin Niestroj
0b59257d93 drivers: wifi: esp32: create event handling thread in runtime
Commit 95b916d104 ("drivers: wifi: esp32: fix reconnect issue")
switched from thread created at runtime to statically defined thread.
The difference is mainly visible for simple applications that use
CONFIG_NET_CONFIG_AUTO_INIT=y, where networking setup code is executed
before main() and any statically defined threads. All ESP32 events are
just queued and never handled, so conditions enforced by
CONFIG_NET_CONFIG_NEED_IPV4=y are never met (e.g. Zephyr networking
layer is never informed about being connected).

Switch back to thread created at runtime, which starts at the moment
when k_thread_create() is invoked. This allows ESP32 event processing to
happen just after ESP32 WiFi driver gets initialized and before Zephyr
network auto initialization code (CONFIG_NET_CONFIG_AUTO_INIT=y).

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2021-06-08 11:15:38 -05:00