diff --git a/esp-ieee802154/CHANGELOG.md b/esp-ieee802154/CHANGELOG.md index 084211a07..35a09aaea 100644 --- a/esp-ieee802154/CHANGELOG.md +++ b/esp-ieee802154/CHANGELOG.md @@ -9,10 +9,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Added board-specific consts for c6 and h2 when caluclating transmit power conversion + ### Changed +- Modified CCA threshold value to default of -60 + ### Fixed +- Fixed possible integer underflow in array access +- Fixed compile error when building binary-logs feature + ### Removed ## 0.2.0 - 2024-08-29 diff --git a/esp-ieee802154/Cargo.toml b/esp-ieee802154/Cargo.toml index 23ac3c74c..ff44d21ea 100644 --- a/esp-ieee802154/Cargo.toml +++ b/esp-ieee802154/Cargo.toml @@ -25,6 +25,8 @@ heapless = "0.8.0" ieee802154 = "0.6.1" log = "0.4.22" vcell = "0.1.3" +cfg-if = "1.0.0" + [features] esp32c6 = ["esp-hal/esp32c6", "esp-wifi-sys/esp32c6"] diff --git a/esp-ieee802154/src/compat/mod.rs b/esp-ieee802154/src/compat/mod.rs index 3b6238e18..666fd7f83 100644 --- a/esp-ieee802154/src/compat/mod.rs +++ b/esp-ieee802154/src/compat/mod.rs @@ -23,7 +23,7 @@ mod binary_logs { syslog(_format, _args); } - pub unsafe extern "C" fn syslog(format: *const u8, args: VaListImpl) { + pub unsafe extern "C" fn syslog(format: *const u8, args: core::ffi::VaListImpl) { let mut buf = [0u8; 512]; vsnprintf(&mut buf as *mut u8, 511, format, args); let res_str = core::ffi::CStr::from_ptr(core::ptr::addr_of!(buf).cast()) diff --git a/esp-ieee802154/src/lib.rs b/esp-ieee802154/src/lib.rs index 90d05c459..662cf8b6c 100644 --- a/esp-ieee802154/src/lib.rs +++ b/esp-ieee802154/src/lib.rs @@ -169,7 +169,7 @@ impl<'a> Ieee802154<'a> { let result = match maybe_decoded { Ok((decoded, _)) => { // crc is not written to rx buffer - let rssi = if raw.data[0] as usize > raw.data.len() { + let rssi = if (raw.data[0] as usize > raw.data.len()) || (raw.data[0] == 0) { raw.data[raw.data.len() - 1] as i8 } else { raw.data[raw.data[0] as usize - 1] as i8 diff --git a/esp-ieee802154/src/pib.rs b/esp-ieee802154/src/pib.rs index b60040d9f..aea77b4aa 100644 --- a/esp-ieee802154/src/pib.rs +++ b/esp-ieee802154/src/pib.rs @@ -19,7 +19,7 @@ use crate::hal::{ set_tx_enhance_ack, }; -pub(crate) const CONFIG_IEEE802154_CCA_THRESHOLD: i8 = 1; +pub(crate) const CONFIG_IEEE802154_CCA_THRESHOLD: i8 = -60; pub(crate) const IEEE802154_FRAME_EXT_ADDR_SIZE: usize = 8; const IEEE802154_MULTIPAN_0: u8 = 0; @@ -227,15 +227,26 @@ fn ieee802154_set_multipan_hal(pib: &Pib) { } } +// https://github.com/espressif/esp-idf/blob/release/v5.3/components/ieee802154/driver/esp_ieee802154_pib.c#L48 fn ieee802154_txpower_convert(txpower: i8) -> u8 { - const IEEE802154_TXPOWER_VALUE_MAX: i8 = 13; - const IEEE802154_TXPOWER_VALUE_MIN: i8 = -32; - + cfg_if::cfg_if! { + if #[cfg(feature="esp32h2")] { + // https://github.com/espressif/esp-idf/blob/release/v5.3/components/hal/esp32h2/include/hal/ieee802154_ll.h + const IEEE802154_TXPOWER_VALUE_MAX: i8 = 20; + const IEEE802154_TXPOWER_VALUE_MIN: i8 = -24; + const IEEE802154_TXPOWER_INDEX_MIN: i8 = 0; + } else if #[cfg(feature="esp32c6")]{ + // https://github.com/espressif/esp-idf/blob/release/v5.3/components/hal/esp32c6/include/hal/ieee802154_ll.h + const IEEE802154_TXPOWER_VALUE_MAX: i8 = 20; + const IEEE802154_TXPOWER_VALUE_MIN: i8 = -15; + const IEEE802154_TXPOWER_INDEX_MIN: i8 = 3; + } + } if txpower > IEEE802154_TXPOWER_VALUE_MAX { 15 - } else if txpower < IEEE802154_TXPOWER_VALUE_MIN { - 0 + } else if txpower <= IEEE802154_TXPOWER_VALUE_MIN { + IEEE802154_TXPOWER_INDEX_MIN as u8 } else { - ((txpower - IEEE802154_TXPOWER_VALUE_MIN) / 3) as u8 + (((txpower - IEEE802154_TXPOWER_VALUE_MIN) / 3) + IEEE802154_TXPOWER_INDEX_MIN) as u8 } }