esp-rs / esp-hal

no_std Hardware Abstraction Layers for ESP32 microcontrollers
https://docs.esp-rs.org/esp-hal/
Apache License 2.0
622 stars 167 forks source link

Intended Interface for WPA2-Enterprise #1608

Open raphaelhetzel opened 8 months ago

raphaelhetzel commented 8 months ago

Do you have an interface in mind for integrating WPA2 Enterprise? In the IDF/driver this is handled using a completely separate API (esp_wifi_sta_wpa2_ent_set_username, esp_wifi_sta_wpa2_ent_enable) but given the way the interface is configured here, I would expect that to happen in the background when using the normal set_configuration method with auth_method set to the enterprise variant.

bjoernQ commented 8 months ago

I would expect that to happen in the background when using the normal set_configuration method with auth_method set to the enterprise variant

I guess that would be the way to go, yes

raphaelhetzel commented 8 months ago

Okay, might try to add this like that then once I find the capacity.

gustavowd commented 2 months ago

Hi, anyone was able to connect with a WPA2 enterprise network using Rust?

I'm trying with this code, but not luck by now: unsafe { let ret1 = esp_idf_sys::esp_eap_client_set_ca_cert(CA_CERT.as_ptr(), CA_CERT.len() as i32); let ret2 = esp_idf_sys::esp_eap_client_set_identity(EAP_ID.as_ptr(), EAP_ID.len() as i32); let ret3 = esp_idf_sys::esp_eap_client_set_username(EAP_USERNAME.as_ptr(), EAP_USERNAME.len() as i32); let ret4 = esp_idf_sys::esp_eap_client_set_password(EAP_PASSWORD.as_ptr(), EAP_PASSWORD.len() as i32); let ret5 = esp_idf_sys::esp_eap_client_set_certificate_and_key(CLIENT_CERT.as_ptr(), CLIENT_CERT.len() as i32, CLIENT_KEY.as_ptr(), CLIENT_KEY.len() as i32, std::ptr::null(), 0); info!("Wifi Enterprise: {}:{}:{}:{}:{}", ret1, ret2, ret3, ret4, ret5); esp_idf_sys::esp_wifi_sta_enterprise_enable(); }

wifi.set_configuration(&Configuration::Client(
    ClientConfiguration {
        ssid: SSID.try_into().unwrap(),
        password: PASS.try_into().unwrap(),
        auth_method: AuthMethod::WPA2Enterprise,
        channel,
        ..Default::default()
    }
))?;

info!("Connecting wifi...");

wifi.connect()?;
gustavowd commented 2 months ago

Full log:

I (691) rust_esp32_c3_demo::wifi_wpa2: Starting wifi... I (693) phy_init: phy_version 1150,7c3c08f,Jan 24 2024,17:32:21 I (736) wifi:mode : sta (7c:df:a1:b1:58:0c) I (737) wifi:enable tsf I (741) rust_esp32_c3_demo::wifi_wpa2: Scanning... I (5845) rust_esp32_c3_demo::wifi_wpa2: Found configured access point UTFPR-SERVIDOR on channel 1 I (5846) rust_esp32_c3_demo::wifi_wpa2: Wifi Enterprise: 0:0:0:0:0 I (5854) rust_esp32_c3_demo::wifi_wpa2: Connecting wifi... I (8270) wifi:new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1 I (8538) wifi:state: init -> auth (b0) I (9539) wifi:state: auth -> init (200) I (9541) wifi:new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1 I (9542) wifi:new:<6,0>, old:<1,0>, ap:<255,255>, sta:<6,0>, prof:1 I (9546) wifi:state: init -> auth (b0) I (9557) wifi:state: auth -> assoc (0) I (9573) wifi:state: assoc -> run (10) I (20862) wifi:state: run -> init (0) I (20864) wifi:new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1 I (20865) wifi:new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1 I (20868) wifi:state: init -> auth (b0) I (20943) wifi:flush txq I (20943) wifi:stop sw txq I (20944) wifi:lmac stop hw txq I (20946) esp_idf_svc::wifi: EspWifi dropped I (20947) esp_idf_svc::netif: Dropped I (20949) esp_idf_svc::netif: Dropped I (20955) wifi:Deinit lldesc rx mblock:10 I (20959) esp_idf_svc::nvs: NvsDefault dropped I (20963) esp_idf_svc::eventloop: System event loop dropped Error: ESP_ERR_TIMEOUT I (20971) main_task: Returned from app_main() E (21871) wifi:timeout when WiFi un-init, type=11

bjoernQ commented 2 months ago

From the code and the logs it seems you are trying to use esp-wifi on esp-idf/Rust std. That's not supported (it's for bare-metal Rust). You probably want to use https://crates.io/crates/esp-idf-svc which offers the same functionality (and more) for Rust-Std on esp-idf

gustavowd commented 2 months ago

From the code and the logs it seems you are trying to use esp-wifi on esp-idf/Rust std. That's not supported (it's for bare-metal Rust). You probably want to use https://crates.io/crates/esp-idf-svc which offers the same functionality (and more) for Rust-Std on esp-idf

@bjoernQ, I believe that i'm using the esp-idf-svc on esp-idf/Rust std. These are my dependencies:

Esp32:

esp-idf-svc = { version = "0.48", features = ["std"]} esp-idf-hal = { version="0.43.1"} esp-idf-sys = { version = "0.34.1"} embedded-svc = { version = "0.27.1"}

And i am using this crates like this: use esp_idf_svc::wifi::{AuthMethod, AsyncWifi, ClientConfiguration, Configuration, EspWifi}; use esp_idf_hal::peripheral::Peripheral; use esp_idf_svc::timer::{EspTimerService, Task}; use esp_idf_svc::eventloop::EspSystemEventLoop; use esp_idf_svc::ping::EspPing; use esp_idf_svc::nvs::EspNvsPartition; use esp_idf_svc::nvs::NvsDefault;

The problem is that dispate of esp-idf-svc has the auth method WPA2 Enterprise, there are no functions to define the enterprise client, password and certificates. This is why i'm using the esp-idf-sys functions.

let wifi_configuration: Configuration = Configuration::Client(ClientConfiguration {
    ssid: ssid_name,
    auth_method: AuthMethod::WPA2Enterprise,
    ..Default::default()
});
bjoernQ commented 2 months ago

@gustavowd Thanks for clarification. In that case https://github.com/esp-rs/esp-idf-svc would be the correct repository to raise this issue

Whatever their solution will look like might be helpful for esp-wifi however

MabezDev commented 2 months ago

(Sorry for the noise, I though this was a separate issue :sweat_smile: )