Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions esp-idf-svc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Event loop: `Wait::also` / `AsyncWait::also`, for waiting on events of several sources
- Wi-Fi: `WifiDriver::set_power_save` / `get_power_save` (and on `EspWifi`), e.g. for disabling modem sleep, which delays receiving data by up to the DTIM period
- Wi-Fi: WPA2 / WPA3 Enterprise (802.1X / EAP) authentication of the station with `EnterpriseConfiguration` and `WifiDriver::enable_enterprise` / `disable_enterprise` (and on `EspWifi`); ESP-IDF v5.0.5+, v5.1.2+ and v5.2+
- HTTP client, MQTT client: `if_name` in `Configuration` / `MqttClientConfiguration`, to bind the connection to one network interface (`SO_BINDTODEVICE`) with its lwIP name, e.g. from `EspNetif::get_name` (ESP-IDF v5+)

### Fixed
- TLS: the non-blocking server handshake (`EspTls::negotiate_server_init`, `EspAsyncTls::negotiate_server`) read the ALPN list after freeing it, which failed the handshake or crashed. The list now lives as long as the session, and `alpn_protos` needs the `alloc` feature
Expand Down
9 changes: 9 additions & 0 deletions esp-idf-svc/src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ pub struct Configuration {
pub keep_alive_idle: Option<usize>,
pub keep_alive_interval: Option<usize>,
pub keep_alive_count: Option<usize>,
#[cfg(all(esp_idf_comp_lwip_enabled, not(esp_idf_version_major = "4")))]
pub if_name: Option<heapless::String<6>>,
}

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
Expand Down Expand Up @@ -203,6 +205,13 @@ impl EspHttpConnection {
}
}

#[cfg(all(esp_idf_comp_lwip_enabled, not(esp_idf_version_major = "4")))]
let mut if_name = configuration.if_name.as_deref().map(to_ifreq).transpose()?;
#[cfg(all(esp_idf_comp_lwip_enabled, not(esp_idf_version_major = "4")))]
if let Some(if_name) = if_name.as_mut() {
native_config.if_name = if_name;
}

let raw_client = unsafe { esp_http_client_init(&native_config) };
if raw_client.is_null() {
Err(EspError::from_infallible::<ESP_FAIL>())
Expand Down
13 changes: 13 additions & 0 deletions esp-idf-svc/src/mqtt/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ pub struct MqttClientConfiguration<'a> {
/// A private key kept in hardware, used instead of `private_key`
pub hw_private_key: Option<HwPrivateKey>,

#[cfg(all(esp_idf_comp_lwip_enabled, not(esp_idf_version_major = "4")))]
pub if_name: Option<&'a str>,

#[cfg(all(esp_idf_esp_tls_psk_verification, feature = "alloc"))]
pub psk: Option<Psk<'a>>,
// pub alpn_protos: &'a [&'a str],
Expand Down Expand Up @@ -165,6 +168,9 @@ impl Default for MqttClientConfiguration<'_> {

hw_private_key: None,

#[cfg(all(esp_idf_comp_lwip_enabled, not(esp_idf_version_major = "4")))]
if_name: None,

#[cfg(all(esp_idf_esp_tls_psk_verification, feature = "alloc"))]
psk: None,
}
Expand Down Expand Up @@ -551,6 +557,13 @@ impl<'a> EspMqttClient<'a> {
c_conf.credentials.authentication.ecdsa_key_efuse_blk = efuse_block;
}

#[cfg(all(esp_idf_comp_lwip_enabled, not(esp_idf_version_major = "4")))]
let mut if_name = conf.if_name.map(to_ifreq).transpose()?;
#[cfg(all(esp_idf_comp_lwip_enabled, not(esp_idf_version_major = "4")))]
if let Some(if_name) = if_name.as_mut() {
c_conf.network.if_name = if_name;
}

let raw_client = unsafe { esp_mqtt_client_init(&c_conf as *const _) };
if raw_client.is_null() {
return Err(EspError::from_infallible::<ESP_FAIL>());
Expand Down
14 changes: 13 additions & 1 deletion esp-idf-svc/src/private/cstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub use alloc::ffi::CString;
pub use core::ffi::{c_char, CStr};
use core::str::Utf8Error;

use crate::sys::{EspError, ESP_ERR_INVALID_SIZE};
use crate::sys::{EspError, ESP_ERR_INVALID_ARG, ESP_ERR_INVALID_SIZE};

pub fn set_str(buf: &mut [u8], s: &str) -> Result<(), EspError> {
if s.len() >= buf.len() {
Expand All @@ -20,6 +20,18 @@ pub fn set_str(buf: &mut [u8], s: &str) -> Result<(), EspError> {
Ok(())
}

#[cfg(all(esp_idf_comp_lwip_enabled, not(esp_idf_version_major = "4")))]
pub fn to_ifreq(if_name: &str) -> Result<crate::sys::ifreq, EspError> {
if if_name.is_empty() || !if_name.is_ascii() {
return Err(EspError::from_infallible::<ESP_ERR_INVALID_ARG>());
}

let mut ifreq = crate::sys::ifreq { ifr_name: [0; 6] };
set_str(c_char_to_u8_slice_mut(&mut ifreq.ifr_name), if_name)?;

Ok(ifreq)
}

pub fn set_str_no_termination_requirement(buf: &mut [u8], s: &str) -> Result<(), EspError> {
if s.len() > buf.len() {
return Err(EspError::from_infallible::<ESP_ERR_INVALID_SIZE>());
Expand Down
Loading