diff --git a/esp-ieee802154/CHANGELOG.md b/esp-ieee802154/CHANGELOG.md index 1fc8b9b11..b73352d36 100644 --- a/esp-ieee802154/CHANGELOG.md +++ b/esp-ieee802154/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Modified CCA threshold value to default of -60 - The driver now take `RADIO_CLK` by value to avoid a collision with esp-wifi's usage (#2183) - `binary-logs` feature renamed to `sys-logs` (#2183) +- Updated PHY driver to v5.3.1 (#2239) ### Fixed diff --git a/esp-ieee802154/Cargo.toml b/esp-ieee802154/Cargo.toml index 087a8c548..352d35e91 100644 --- a/esp-ieee802154/Cargo.toml +++ b/esp-ieee802154/Cargo.toml @@ -20,7 +20,7 @@ byte = "0.2.7" critical-section = "1.1.3" document-features = "0.2.10" esp-hal = { version = "0.20.0", path = "../esp-hal" } -esp-wifi-sys = { version = "0.5.0", git = "https://github.com/esp-rs/esp-wifi-sys", rev = "83ee3bd" } +esp-wifi-sys = { version = "0.5.0", git = "https://github.com/esp-rs/esp-wifi-sys", rev = "30d43461335cf5f58317dfc78a5397f48dae2e27" } heapless = "0.8.0" ieee802154 = "0.6.1" vcell = "0.1.3" diff --git a/esp-wifi/CHANGELOG.md b/esp-wifi/CHANGELOG.md index c0b02ec73..cbeb4fea4 100644 --- a/esp-wifi/CHANGELOG.md +++ b/esp-wifi/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - esp-wifi now allocates memory from the global allocator provided by `esp-alloc` (#2099) - Renamed the `wifi-logs` feature to `sys-logs` for consistency (#2183) +- Updated drivers to v5.3.1 (#2239) ### Fixed diff --git a/esp-wifi/Cargo.toml b/esp-wifi/Cargo.toml index 08562b18a..34b876801 100644 --- a/esp-wifi/Cargo.toml +++ b/esp-wifi/Cargo.toml @@ -33,7 +33,7 @@ heapless = { version = "0.8.0", default-features = false, features = [ num-derive = { version = "0.4.2" } num-traits = { version = "0.2.19", default-features = false } no-std-net = { version = "0.6.0", optional = true } -esp-wifi-sys = { version = "0.5.0", git = "https://github.com/esp-rs/esp-wifi-sys", rev = "83ee3bd" } +esp-wifi-sys = { version = "0.5.0", git = "https://github.com/esp-rs/esp-wifi-sys", rev = "30d43461335cf5f58317dfc78a5397f48dae2e27" } embassy-sync = { version = "0.6.0", optional = true } embassy-futures = { version = "0.1.1", optional = true } embassy-net-driver = { version = "0.2.0", optional = true } diff --git a/esp-wifi/src/ble/btdm.rs b/esp-wifi/src/ble/btdm.rs index c3962c13f..14e52eab5 100644 --- a/esp-wifi/src/ble/btdm.rs +++ b/esp-wifi/src/ble/btdm.rs @@ -232,7 +232,7 @@ unsafe extern "C" fn queue_recv(queue: *const (), item: *const (), block_time_ms block_time_ms ); - let forever = block_time_ms == OSI_FUNCS_TIME_BLOCKING; + let forever = block_time_ms == crate::compat::common::OSI_FUNCS_TIME_BLOCKING; let start = crate::timer::get_systimer_count(); let block_ticks = crate::timer::millis_to_ticks(block_time_ms as u64); diff --git a/esp-wifi/src/ble/npl.rs b/esp-wifi/src/ble/npl.rs index bc94a709b..a3ae83817 100644 --- a/esp-wifi/src/ble/npl.rs +++ b/esp-wifi/src/ble/npl.rs @@ -21,7 +21,7 @@ use crate::{ #[cfg_attr(esp32h2, path = "os_adapter_esp32h2.rs")] pub(crate) mod ble_os_adapter_chip_specific; -const TIME_FOREVER: u32 = u32::MAX; +const TIME_FOREVER: u32 = crate::compat::common::OSI_FUNCS_TIME_BLOCKING; #[cfg(esp32c2)] const OS_MSYS_1_BLOCK_COUNT: i32 = 24; @@ -169,30 +169,6 @@ pub struct OsMbuf { om_databuf: u32, } -#[repr(C)] -pub struct OsMempoolExt { - mpe_mp: OsMempool, - - // Callback that is executed immediately when a block is freed. - mpe_put_cb: OsMempoolPutFn, - mpe_put_arg: *const c_void, -} - -type OsMempoolPutFn = Option< - unsafe extern "C" fn(ome: *const OsMempoolExt, data: *const c_void, arg: *const c_void) -> i32, ->; - -#[repr(C)] -pub struct BleHciTransFuncsT { - ble_hci_trans_hs_acl_tx: Option i32>, - ble_hci_trans_hs_cmd_tx: Option i32>, - ble_hci_trans_ll_acl_tx: Option i32>, - ble_hci_trans_ll_evt_tx: Option i32>, - ble_hci_trans_reset: Option i32>, - ble_hci_trans_set_acl_free_cb: - Option i32>, -} - #[cfg(esp32c2)] pub(crate) static mut OS_MSYS_INIT_1_DATA: *mut OsMembufT = core::ptr::null_mut(); #[cfg(esp32c2)] @@ -208,35 +184,66 @@ pub(crate) static mut OS_MSYS_INIT_2_MBUF_POOL: OsMbufPool = OsMbufPool::zeroed( pub(crate) static mut OS_MSYS_INIT_2_MEMPOOL: OsMempool = OsMempool::zeroed(); extern "C" { - static ble_hci_trans_funcs_ptr: &'static BleHciTransFuncsT; + // Sends ACL data from host to controller. + // + // om The ACL data packet to send. + // + // 0 on success; + // A BLE_ERR_[...] error code on failure. + pub(crate) fn r_ble_hci_trans_hs_acl_tx(om: *const OsMbuf) -> i32; + + // Sends an HCI command from the host to the controller. + // + // cmd The HCI command to send. This buffer must be + // allocated via ble_hci_trans_buf_alloc(). + // + // 0 on success; + // A BLE_ERR_[...] error code on failure. + pub(crate) fn r_ble_hci_trans_hs_cmd_tx(cmd: *const u8) -> i32; #[cfg(esp32c2)] - static mut r_ble_stub_funcs_ptr: *mut u32; - pub(crate) fn ble_controller_init(cfg: *const esp_bt_controller_config_t) -> i32; + #[cfg(not(esp32c2))] + pub(crate) fn r_ble_controller_init(cfg: *const esp_bt_controller_config_t) -> i32; + + #[cfg(esp32c2)] pub(crate) fn ble_controller_enable(mode: u8) -> i32; - pub(crate) fn esp_register_ext_funcs(funcs: *const ext_funcs_t) -> i32; + #[cfg(not(esp32c2))] + pub(crate) fn r_ble_controller_enable(mode: u8) -> i32; + + pub(crate) fn esp_register_ext_funcs(funcs: *const ExtFuncsT) -> i32; pub(crate) fn esp_register_npl_funcs(funcs: *const npl_funcs_t) -> i32; + #[cfg(esp32c2)] pub(crate) fn ble_get_npl_element_info( cfg: *const esp_bt_controller_config_t, - npl_info: *const ble_npl_count_info_t, + npl_info: *const BleNplCountInfoT, + ) -> i32; + + #[cfg(not(esp32c2))] + pub(crate) fn r_ble_get_npl_element_info( + cfg: *const esp_bt_controller_config_t, + npl_info: *const BleNplCountInfoT, ) -> i32; pub(crate) fn bt_bb_v2_init_cmplx(value: u8); pub(crate) fn r_ble_hci_trans_cfg_hs( - evt: Option, /* ble_hci_trans_rx_cmd_fn */ + evt: Option i32>, /* ble_hci_trans_rx_cmd_fn */ evt_arg: *const c_void, - acl_cb: Option, /* ble_hci_trans_rx_acl_fn */ + acl_cb: Option i32>, /* ble_hci_trans_rx_acl_fn */ acl_arg: *const c_void, ); + #[cfg(esp32c2)] pub(crate) fn esp_ble_ll_set_public_addr(addr: *const u8); + #[cfg(not(esp32c2))] + pub(crate) fn r_esp_ble_ll_set_public_addr(addr: *const u8); + #[cfg(esp32c2)] pub(crate) fn r_mem_init_mbuf_pool( mem: *const c_void, @@ -254,7 +261,7 @@ extern "C" { pub(crate) fn r_os_msys_register(mbuf_pool: *const OsMbufPool) -> i32; #[allow(unused)] - pub(crate) fn ble_osi_coex_funcs_register(coex_funcs: *const osi_coex_funcs_t) -> i32; + pub(crate) fn ble_osi_coex_funcs_register(coex_funcs: *const OsiCoexFuncsT) -> i32; pub(crate) fn r_os_msys_get_pkthdr(dsize: u16, user_hdr_len: u16) -> *mut OsMbuf; @@ -265,12 +272,10 @@ extern "C" { pub(crate) fn r_ble_hci_trans_buf_alloc(typ: i32) -> *const u8; pub(crate) fn r_ble_hci_trans_buf_free(buf: *const u8); - - static mut ble_hci_trans_env_p: u32; } #[repr(C)] -pub struct ext_funcs_t { +pub struct ExtFuncsT { ext_version: u32, esp_intr_alloc: Option< unsafe extern "C" fn( @@ -284,13 +289,19 @@ pub struct ext_funcs_t { esp_intr_free: Option i32>, malloc: Option *mut c_void>, free: Option, + #[cfg(esp32c2)] hal_uart_start_tx: Option, + #[cfg(esp32c2)] hal_uart_init_cbs: Option< unsafe extern "C" fn(i32, *const c_void, *const c_void, *const c_void, c_void) -> i32, >, + #[cfg(esp32c2)] hal_uart_config: Option i32>, + #[cfg(esp32c2)] hal_uart_close: Option i32>, + #[cfg(esp32c2)] hal_uart_blocking_tx: Option, + #[cfg(esp32c2)] hal_uart_init: Option i32>, task_create: Option< unsafe extern "C" fn( @@ -314,17 +325,27 @@ pub struct ext_funcs_t { magic: u32, } -static G_OSI_FUNCS: ext_funcs_t = ext_funcs_t { +static G_OSI_FUNCS: ExtFuncsT = ExtFuncsT { + #[cfg(not(esp32c2))] + ext_version: 0x20240422, + #[cfg(esp32c2)] ext_version: 0x20221122, + esp_intr_alloc: Some(self::ble_os_adapter_chip_specific::esp_intr_alloc), esp_intr_free: Some(esp_intr_free), malloc: Some(crate::ble::malloc), free: Some(crate::ble::free), + #[cfg(esp32c2)] hal_uart_start_tx: None, + #[cfg(esp32c2)] hal_uart_init_cbs: None, + #[cfg(esp32c2)] hal_uart_config: None, + #[cfg(esp32c2)] hal_uart_close: None, + #[cfg(esp32c2)] hal_uart_blocking_tx: None, + #[cfg(esp32c2)] hal_uart_init: None, task_create: Some(task_create), task_delete: Some(task_delete), @@ -535,7 +556,7 @@ static mut G_NPL_FUNCS: npl_funcs_t = npl_funcs_t { }; #[repr(C)] -pub struct osi_coex_funcs_t { +pub struct OsiCoexFuncsT { magic: u32, version: u32, coex_wifi_sleep_set: Option, @@ -546,7 +567,7 @@ pub struct osi_coex_funcs_t { } #[allow(unused)] -static G_COEX_FUNCS: osi_coex_funcs_t = osi_coex_funcs_t { +static G_COEX_FUNCS: OsiCoexFuncsT = OsiCoexFuncsT { magic: 0xFADEBEAD, version: 0x00010006, coex_wifi_sleep_set: Some(coex_wifi_sleep_set), @@ -974,7 +995,7 @@ unsafe extern "C" fn ble_npl_os_started() -> bool { } #[repr(C)] -pub struct ble_npl_count_info_t { +pub struct BleNplCountInfoT { evt_count: u16, evtq_count: u16, co_count: u16, @@ -1001,11 +1022,23 @@ pub(crate) fn ble_init() { let cfg = ble_os_adapter_chip_specific::BLE_CONFIG; - let res = esp_register_ext_funcs(&G_OSI_FUNCS as *const ext_funcs_t); + let res = esp_register_ext_funcs(&G_OSI_FUNCS as *const ExtFuncsT); if res != 0 { panic!("esp_register_ext_funcs returned {}", res); } + #[cfg(esp32c2)] + { + debug!("Init esp_ble_rom_func_ptr_init_all"); + extern "C" { + fn esp_ble_rom_func_ptr_init_all() -> i32; + } + let res = esp_ble_rom_func_ptr_init_all(); + if res != 0 { + panic!("esp_ble_rom_func_ptr_init_all returned {}", res); + } + } + #[cfg(coex)] { let res = crate::wifi::coex_init(); @@ -1023,16 +1056,22 @@ pub(crate) fn ble_init() { panic!("esp_register_npl_funcs returned {}", res); } - let npl_info = ble_npl_count_info_t { + let npl_info = BleNplCountInfoT { evt_count: 0, evtq_count: 0, co_count: 0, sem_count: 0, mutex_count: 0, }; + #[cfg(esp32c2)] let res = ble_get_npl_element_info( &cfg as *const esp_bt_controller_config_t, - &npl_info as *const ble_npl_count_info_t, + &npl_info as *const BleNplCountInfoT, + ); + #[cfg(not(esp32c2))] + let res = r_ble_get_npl_element_info( + &cfg as *const esp_bt_controller_config_t, + &npl_info as *const BleNplCountInfoT, ); if res != 0 { panic!("ble_get_npl_element_info returned {}", res); @@ -1057,22 +1096,35 @@ pub(crate) fn ble_init() { #[cfg(coex)] { - let rc = ble_osi_coex_funcs_register(&G_COEX_FUNCS as *const osi_coex_funcs_t); + let rc = ble_osi_coex_funcs_register(&G_COEX_FUNCS as *const OsiCoexFuncsT); if rc != 0 { panic!("ble_osi_coex_funcs_register returned {}", rc); } } + #[cfg(not(esp32c2))] + { + extern "C" { + fn esp_ble_register_bb_funcs() -> i32; + } + let res = esp_ble_register_bb_funcs(); + if res != 0 { + panic!("esp_ble_register_bb_funcs returned {}", res); + } + } + + #[cfg(esp32c2)] let res = ble_controller_init(&cfg as *const esp_bt_controller_config_t); + #[cfg(not(esp32c2))] + let res = r_ble_controller_init(&cfg as *const esp_bt_controller_config_t); if res != 0 { panic!("ble_controller_init returned {}", res); } - #[cfg(not(esp32c2))] { extern "C" { - fn esp_ble_msys_init( + fn r_esp_ble_msys_init( msys_size1: u16, msys_size2: u16, msys_cnt1: u16, @@ -1081,7 +1133,7 @@ pub(crate) fn ble_init() { ) -> i32; } - let res = esp_ble_msys_init(256, 320, 12, 24, 1); + let res = r_esp_ble_msys_init(256, 320, 12, 24, 1); if res != 0 { panic!("esp_ble_msys_init returned {}", res); } @@ -1094,7 +1146,15 @@ pub(crate) fn ble_init() { crate::common_adapter::read_mac(mac.as_mut_ptr(), 2); mac.reverse(); + #[cfg(esp32c2)] esp_ble_ll_set_public_addr(&mac as *const u8); + #[cfg(not(esp32c2))] + r_esp_ble_ll_set_public_addr(&mac as *const u8); + + extern "C" { + fn r_ble_hci_trans_init(m: u8); + } + r_ble_hci_trans_init(0); r_ble_hci_trans_cfg_hs( Some(ble_hs_hci_rx_evt), @@ -1103,30 +1163,17 @@ pub(crate) fn ble_init() { core::ptr::null(), ); + #[cfg(esp32c2)] let res = ble_controller_enable(1); // 1 = BLE + #[cfg(not(esp32c2))] + let res = r_ble_controller_enable(1); // 1 = BLE if res != 0 { panic!("ble_controller_enable returned {}", res); } - // "patch" r_ble_ll_random - it needs syscall_table_ptr - // probably long term we should rather initialize syscall_table_ptr - #[cfg(esp32c2)] - { - *(r_ble_stub_funcs_ptr.offset(0x7dc / 4)) = - self::ble_os_adapter_chip_specific::ble_ll_random_override as *const u32 as u32; - } - // this is to avoid (ASSERT r_ble_hci_ram_hs_cmd_tx:34 0 0) - // r_ble_hci_trans_cfg_ll initializes ble_hci_trans_env_p + 0x34 - // it's called by r_ble_ll_task which is run in another task - // in r_ble_hci_ram_hs_cmd_tx this is checked for non-null - while (ble_hci_trans_env_p as *const u32) - .add(0x34 / 4) - .read_volatile() - == 0 - { - // wait - } + // we wait a bit to make sure the ble task initialized everything + crate::compat::common::sleep(10); debug!("The ble_controller_init was initialized"); } @@ -1192,7 +1239,7 @@ fn os_msys_init() { } } -unsafe extern "C" fn ble_hs_hci_rx_evt(cmd: *const u8, arg: *const c_void) { +unsafe extern "C" fn ble_hs_hci_rx_evt(cmd: *const u8, arg: *const c_void) -> i32 { trace!("ble_hs_hci_rx_evt {:?} {:?}", cmd, arg); debug!("$ cmd = {:x}", *cmd); debug!("$ len = {:x}", *(cmd.offset(1))); @@ -1228,9 +1275,11 @@ unsafe extern "C" fn ble_hs_hci_rx_evt(cmd: *const u8, arg: *const c_void) { #[cfg(feature = "async")] crate::ble::controller::asynch::hci_read_data_available(); + + 0 } -unsafe extern "C" fn ble_hs_rx_data(om: *const OsMbuf, arg: *const c_void) { +unsafe extern "C" fn ble_hs_rx_data(om: *const OsMbuf, arg: *const c_void) -> i32 { trace!("ble_hs_rx_data {:?} {:?}", om, arg); let data_ptr = (*om).om_data; @@ -1261,6 +1310,8 @@ unsafe extern "C" fn ble_hs_rx_data(om: *const OsMbuf, arg: *const c_void) { #[cfg(feature = "async")] crate::ble::controller::asynch::hci_read_data_available(); + + 0 } static mut BLE_HCI_READ_DATA: [u8; 256] = [0u8; 256]; @@ -1344,7 +1395,7 @@ pub fn send_hci(data: &[u8]) { packet.len() - 1, ); - let res = unwrap!(ble_hci_trans_funcs_ptr.ble_hci_trans_hs_cmd_tx)(cmd); + let res = r_ble_hci_trans_hs_cmd_tx(cmd); if res != 0 { warn!("ble_hci_trans_hs_cmd_tx res == {}", res); @@ -1365,7 +1416,7 @@ pub fn send_hci(data: &[u8]) { // received by the other side *((*om).om_data as *mut u8).offset(1) = 0; - let res = unwrap!(ble_hci_trans_funcs_ptr.ble_hci_trans_hs_acl_tx)(om); + let res = r_ble_hci_trans_hs_acl_tx(om); if res != 0 { panic!("ble_hci_trans_hs_acl_tx returned {}", res); } diff --git a/esp-wifi/src/ble/os_adapter_esp32.rs b/esp-wifi/src/ble/os_adapter_esp32.rs index eb0309880..7b3b22a41 100644 --- a/esp-wifi/src/ble/os_adapter_esp32.rs +++ b/esp-wifi/src/ble/os_adapter_esp32.rs @@ -109,11 +109,12 @@ pub(super) struct osi_funcs_s { *mut crate::binary::c_types::c_uint, ) -> crate::binary::c_types::c_int, >, + patch_apply: Option, magic: u32, } pub(super) static G_OSI_FUNCS: osi_funcs_s = osi_funcs_s { - version: 0x00010004, + version: 0x00010005, set_isr: Some(ble_os_adapter_chip_specific::set_isr), ints_on: Some(ble_os_adapter_chip_specific::ints_on), interrupt_disable: Some(interrupt_disable), @@ -178,9 +179,24 @@ pub(super) static G_OSI_FUNCS: osi_funcs_s = osi_funcs_s { interrupt_l3_restore: Some(interrupt_l3_restore), custom_queue_create: Some(custom_queue_create), coex_version_get: Some(coex_version_get_wrapper), + patch_apply: Some(patch_apply), magic: 0xfadebead, }; +extern "C" fn patch_apply() { + trace!("patch apply"); + + extern "C" { + fn config_ble_funcs_reset(); + fn config_btdm_funcs_reset(); + } + + unsafe { + config_btdm_funcs_reset(); + config_ble_funcs_reset(); + } +} + extern "C" fn coex_version_get_wrapper(major: *mut u32, minor: *mut u32, patch: *mut u32) -> i32 { unsafe { let coex_version = unwrap!(core::ffi::CStr::from_ptr( @@ -287,7 +303,9 @@ pub(crate) fn create_ble_config() -> esp_bt_controller_config_t { pcm_polar: 0, hli: false, dup_list_refresh_period: 0, - magic: 0x20221207, + ble_scan_backoff: false, + pcm_fsyncshp: 0, + magic: 0x20240722, } } diff --git a/esp-wifi/src/ble/os_adapter_esp32c2.rs b/esp-wifi/src/ble/os_adapter_esp32c2.rs index f46445132..06307c58a 100644 --- a/esp-wifi/src/ble/os_adapter_esp32c2.rs +++ b/esp-wifi/src/ble/os_adapter_esp32c2.rs @@ -114,12 +114,3 @@ pub(super) unsafe extern "C" fn esp_reset_rpa_moudle() { unwrap!(RADIO_CLOCKS.as_mut()).reset_rpa(); } } - -pub(super) unsafe extern "C" fn ble_ll_random_override() -> u32 { - // this is not very random but good enough for now - it's not used for crypto - unsafe { - static mut VALUE: u32 = 0; - VALUE = VALUE.wrapping_add(3); - VALUE - } -} diff --git a/esp-wifi/src/ble/os_adapter_esp32c3.rs b/esp-wifi/src/ble/os_adapter_esp32c3.rs index 8cc490cd0..6d27236a5 100644 --- a/esp-wifi/src/ble/os_adapter_esp32c3.rs +++ b/esp-wifi/src/ble/os_adapter_esp32c3.rs @@ -14,11 +14,13 @@ pub(crate) static mut BT_INTERRUPT_FUNCTION8: ( pub(super) struct osi_funcs_s { magic: u32, version: u32, - interrupt_set: Option, - interrupt_clear: Option, + interrupt_alloc: Option< + unsafe extern "C" fn(i32, i32, extern "C" fn(*const ()), *const (), *mut *const ()) -> i32, + >, + interrupt_free: Option i32>, interrupt_handler_set: Option, interrupt_disable: Option, - interrupt_enable: Option, + interrupt_restore: Option, task_yield: Option, task_yield_from_isr: Option, semphr_create: Option *const ()>, @@ -67,25 +69,31 @@ pub(super) struct osi_funcs_s { btdm_sleep_exit_phase3: Option, coex_wifi_sleep_set: Option, coex_core_ble_conn_dyn_prio_get: Option i32>, + coex_schm_register_btdm_callback: Option i32>, coex_schm_status_bit_set: Option, coex_schm_status_bit_clear: Option, - interrupt_on: Option, - interrupt_off: Option, + coex_schm_interval_get: Option i32>, + coex_schm_curr_period_get: Option u8>, + coex_schm_curr_phase_get: Option *const ()>, + interrupt_on: Option i32>, + interrupt_off: Option i32>, esp_hw_power_down: Option, esp_hw_power_up: Option, ets_backup_dma_copy: Option, ets_delay_us: Option, btdm_rom_table_ready: Option, + coex_bt_wakeup_request: Option, + coex_bt_wakeup_request_end: Option, } pub(super) static G_OSI_FUNCS: osi_funcs_s = osi_funcs_s { magic: 0xfadebead, - version: 0x00010007, - interrupt_set: Some(ble_os_adapter_chip_specific::interrupt_set), - interrupt_clear: Some(ble_os_adapter_chip_specific::interrupt_clear), + version: 0x00010009, + interrupt_alloc: Some(ble_os_adapter_chip_specific::interrupt_set), + interrupt_free: Some(ble_os_adapter_chip_specific::interrupt_clear), interrupt_handler_set: Some(ble_os_adapter_chip_specific::interrupt_handler_set), interrupt_disable: Some(interrupt_disable), - interrupt_enable: Some(interrupt_enable), + interrupt_restore: Some(interrupt_enable), task_yield: Some(task_yield), task_yield_from_isr: Some(task_yield_from_isr), semphr_create: Some(semphr_create), @@ -126,8 +134,12 @@ pub(super) static G_OSI_FUNCS: osi_funcs_s = osi_funcs_s { coex_core_ble_conn_dyn_prio_get: Some( ble_os_adapter_chip_specific::coex_core_ble_conn_dyn_prio_get, ), + coex_schm_register_btdm_callback: Some(coex_schm_register_btdm_callback), coex_schm_status_bit_set: Some(coex_schm_status_bit_set), coex_schm_status_bit_clear: Some(coex_schm_status_bit_clear), + coex_schm_interval_get: Some(coex_schm_interval_get), + coex_schm_curr_period_get: Some(coex_schm_curr_period_get), + coex_schm_curr_phase_get: Some(coex_schm_curr_phase_get), interrupt_on: Some(ble_os_adapter_chip_specific::interrupt_on), interrupt_off: Some(ble_os_adapter_chip_specific::interrupt_off), esp_hw_power_down: Some(ble_os_adapter_chip_specific::esp_hw_power_down), @@ -135,8 +147,83 @@ pub(super) static G_OSI_FUNCS: osi_funcs_s = osi_funcs_s { ets_backup_dma_copy: Some(ble_os_adapter_chip_specific::ets_backup_dma_copy), ets_delay_us: Some(ets_delay_us_wrapper), btdm_rom_table_ready: Some(btdm_rom_table_ready_wrapper), + coex_bt_wakeup_request: Some(coex_bt_wakeup_request), + coex_bt_wakeup_request_end: Some(coex_bt_wakeup_request_end), }; +extern "C" fn coex_schm_register_btdm_callback(_callback: *const ()) -> i32 { + trace!("coex_schm_register_btdm_callback"); + + #[cfg(coex)] + unsafe { + // COEX_SCHM_CALLBACK_TYPE_BT + coex_schm_register_callback(1, _callback as *mut esp_wifi_sys::c_types::c_void) + } + + #[cfg(not(coex))] + 0 +} + +extern "C" fn coex_schm_interval_get() -> i32 { + trace!("coex_schm_interval_get"); + + #[cfg(coex)] + unsafe { + esp_wifi_sys::include::coex_schm_interval_get() as i32 + } + + #[cfg(not(coex))] + 0 +} + +extern "C" fn coex_schm_curr_period_get() -> u8 { + trace!("coex_schm_curr_period_get"); + + #[cfg(coex)] + unsafe { + esp_wifi_sys::include::coex_schm_curr_period_get() + } + + #[cfg(not(coex))] + 0 +} + +extern "C" fn coex_schm_curr_phase_get() -> *const () { + trace!("coex_schm_curr_phase_get"); + + #[cfg(coex)] + unsafe { + esp_wifi_sys::include::coex_schm_curr_phase_get().cast() + } + + #[cfg(not(coex))] + core::ptr::null() +} + +extern "C" fn coex_bt_wakeup_request() { + trace!("coex_bt_wakeup_request"); + + extern "C" { + fn btdm_wakeup_request(); + } + + unsafe { + btdm_wakeup_request(); + } +} + +extern "C" fn coex_bt_wakeup_request_end() { + trace!("coex_bt_wakeup_request_end"); + + extern "C" { + fn btdm_in_wakeup_requesting_set(set: bool); + } + + unsafe { + btdm_in_wakeup_requesting_set(false); + } +} + extern "C" fn ets_delay_us_wrapper(us: u32) { extern "C" { fn ets_delay_us(us: u32); @@ -162,7 +249,7 @@ extern "C" { pub(crate) fn create_ble_config() -> esp_bt_controller_config_t { esp_bt_controller_config_t { magic: 0x5a5aa5a5, - version: 0x02307120, + version: 0x02404010, controller_task_stack_size: 8192, controller_task_prio: 200, controller_task_run_cpu: 0, @@ -195,16 +282,21 @@ pub(crate) fn create_ble_config() -> esp_bt_controller_config_t { scan_backoff_upperlimitmax: 0, ble_50_feat_supp: true, // BT_CTRL_50_FEATURE_SUPPORT ble_cca_mode: 0, + + ble_chan_ass_en: 0, + ble_data_lenth_zero_aux: 0, + ble_ping_en: 0, } } -pub(crate) unsafe extern "C" fn interrupt_on(intr_num: i32) { +pub(crate) unsafe extern "C" fn interrupt_on(intr_num: i32) -> i32 { trace!("interrupt_on {}", intr_num); // NO-OP + 0 } -pub(crate) unsafe extern "C" fn interrupt_off(_intr_num: i32) { +pub(crate) unsafe extern "C" fn interrupt_off(_intr_num: i32) -> i32 { todo!(); } @@ -227,24 +319,25 @@ pub(crate) fn disable_sleep_mode() { pub(crate) unsafe extern "C" fn interrupt_set( cpu_no: i32, intr_source: i32, - interrupt_no: i32, - interrupt_prio: i32, -) { + handler: extern "C" fn(*const ()), + arg: *const (), + ret_handle: *mut *const (), +) -> i32 { trace!( - "interrupt_set {} {} {} {}", + "interrupt_set {} {} {} {} {}", cpu_no, intr_source, - interrupt_no, - interrupt_prio + handler as usize, + arg as u32, + ret_handle as usize, ); - // Set the interrupt type (Edge or Level). - // Map the CPU interrupt ID to the peripheral. + interrupt_handler_set(intr_source, handler, arg); - // NO-OP + 0 } -pub(crate) unsafe extern "C" fn interrupt_clear(_interrupt_source: i32, _interrupt_no: i32) { +pub(crate) unsafe extern "C" fn interrupt_clear(_handler: *const ()) -> i32 { todo!(); } diff --git a/esp-wifi/src/ble/os_adapter_esp32c6.rs b/esp-wifi/src/ble/os_adapter_esp32c6.rs index 713278d6d..6f90a45cf 100644 --- a/esp-wifi/src/ble/os_adapter_esp32c6.rs +++ b/esp-wifi/src/ble/os_adapter_esp32c6.rs @@ -15,7 +15,7 @@ pub(crate) static mut ISR_INTERRUPT_7: ( ) = (core::ptr::null_mut(), core::ptr::null_mut()); pub(crate) static BLE_CONFIG: esp_bt_controller_config_t = esp_bt_controller_config_t { - config_version: 0x20231124, + config_version: 0x20240422, ble_ll_resolv_list_size: 4, ble_hci_evt_hi_buf_count: 30, ble_hci_evt_lo_buf_count: 8, @@ -47,13 +47,6 @@ pub(crate) static BLE_CONFIG: esp_bt_controller_config_t = esp_bt_controller_con controller_run_cpu: 0, enable_qa_test: 0, enable_bqb_test: 0, - enable_uart_hci: 0, - ble_hci_uart_port: 0, - ble_hci_uart_baud: 0, - ble_hci_uart_data_bits: 0, - ble_hci_uart_stop_bits: 0, - ble_hci_uart_flow_ctrl: 0, - ble_hci_uart_uart_parity: 0, enable_tx_cca: 0, cca_rssi_thresh: (256 - 50) as u8, sleep_en: 0, diff --git a/esp-wifi/src/ble/os_adapter_esp32h2.rs b/esp-wifi/src/ble/os_adapter_esp32h2.rs index b2c64413d..e7acc24bc 100644 --- a/esp-wifi/src/ble/os_adapter_esp32h2.rs +++ b/esp-wifi/src/ble/os_adapter_esp32h2.rs @@ -15,7 +15,7 @@ pub(crate) static mut ISR_INTERRUPT_3: ( ) = (core::ptr::null_mut(), core::ptr::null_mut()); pub(crate) static BLE_CONFIG: esp_bt_controller_config_t = esp_bt_controller_config_t { - config_version: 0x20231124, + config_version: 0x20240422, ble_ll_resolv_list_size: 4, ble_hci_evt_hi_buf_count: 30, ble_hci_evt_lo_buf_count: 8, @@ -47,13 +47,6 @@ pub(crate) static BLE_CONFIG: esp_bt_controller_config_t = esp_bt_controller_con controller_run_cpu: 0, enable_qa_test: 0, enable_bqb_test: 0, - enable_uart_hci: 0, - ble_hci_uart_port: 0, - ble_hci_uart_baud: 0, - ble_hci_uart_data_bits: 0, - ble_hci_uart_stop_bits: 0, - ble_hci_uart_flow_ctrl: 0, - ble_hci_uart_uart_parity: 0, enable_tx_cca: 0, cca_rssi_thresh: (256 - 50) as u8, sleep_en: 0, diff --git a/esp-wifi/src/ble/os_adapter_esp32s3.rs b/esp-wifi/src/ble/os_adapter_esp32s3.rs index fd0da61f6..3ff7e5caa 100644 --- a/esp-wifi/src/ble/os_adapter_esp32s3.rs +++ b/esp-wifi/src/ble/os_adapter_esp32s3.rs @@ -15,11 +15,13 @@ pub static mut ISR_INTERRUPT_8: ( pub(super) struct osi_funcs_s { magic: u32, version: u32, - interrupt_set: Option, - interrupt_clear: Option, + interrupt_alloc: Option< + unsafe extern "C" fn(i32, i32, extern "C" fn(*const ()), *const (), *mut *const ()) -> i32, + >, + interrupt_free: Option i32>, interrupt_handler_set: Option, interrupt_disable: Option, - interrupt_enable: Option, + interrupt_restore: Option, task_yield: Option, task_yield_from_isr: Option, semphr_create: Option *const ()>, @@ -68,25 +70,31 @@ pub(super) struct osi_funcs_s { btdm_sleep_exit_phase3: Option, coex_wifi_sleep_set: Option, coex_core_ble_conn_dyn_prio_get: Option i32>, + coex_schm_register_btdm_callback: Option i32>, coex_schm_status_bit_set: Option, coex_schm_status_bit_clear: Option, - interrupt_on: Option, - interrupt_off: Option, + coex_schm_interval_get: Option i32>, + coex_schm_curr_period_get: Option u8>, + coex_schm_curr_phase_get: Option *const ()>, + interrupt_on: Option i32>, + interrupt_off: Option i32>, esp_hw_power_down: Option, esp_hw_power_up: Option, ets_backup_dma_copy: Option, ets_delay_us: Option, btdm_rom_table_ready: Option, + coex_bt_wakeup_request: Option, + coex_bt_wakeup_request_end: Option, } pub(super) static G_OSI_FUNCS: osi_funcs_s = osi_funcs_s { magic: 0xfadebead, - version: 0x00010007, - interrupt_set: Some(ble_os_adapter_chip_specific::interrupt_set), - interrupt_clear: Some(ble_os_adapter_chip_specific::interrupt_clear), + version: 0x00010009, + interrupt_alloc: Some(ble_os_adapter_chip_specific::interrupt_set), + interrupt_free: Some(ble_os_adapter_chip_specific::interrupt_clear), interrupt_handler_set: Some(ble_os_adapter_chip_specific::interrupt_handler_set), interrupt_disable: Some(interrupt_disable), - interrupt_enable: Some(interrupt_enable), + interrupt_restore: Some(interrupt_enable), task_yield: Some(task_yield), task_yield_from_isr: Some(task_yield_from_isr), semphr_create: Some(semphr_create), @@ -127,8 +135,12 @@ pub(super) static G_OSI_FUNCS: osi_funcs_s = osi_funcs_s { coex_core_ble_conn_dyn_prio_get: Some( ble_os_adapter_chip_specific::coex_core_ble_conn_dyn_prio_get, ), + coex_schm_register_btdm_callback: Some(coex_schm_register_btdm_callback), coex_schm_status_bit_set: Some(coex_schm_status_bit_set), coex_schm_status_bit_clear: Some(coex_schm_status_bit_clear), + coex_schm_interval_get: Some(coex_schm_interval_get), + coex_schm_curr_period_get: Some(coex_schm_curr_period_get), + coex_schm_curr_phase_get: Some(coex_schm_curr_phase_get), interrupt_on: Some(ble_os_adapter_chip_specific::interrupt_on), interrupt_off: Some(ble_os_adapter_chip_specific::interrupt_off), esp_hw_power_down: Some(ble_os_adapter_chip_specific::esp_hw_power_down), @@ -136,8 +148,83 @@ pub(super) static G_OSI_FUNCS: osi_funcs_s = osi_funcs_s { ets_backup_dma_copy: Some(ble_os_adapter_chip_specific::ets_backup_dma_copy), ets_delay_us: Some(ets_delay_us_wrapper), btdm_rom_table_ready: Some(btdm_rom_table_ready_wrapper), + coex_bt_wakeup_request: Some(coex_bt_wakeup_request), + coex_bt_wakeup_request_end: Some(coex_bt_wakeup_request_end), }; +extern "C" fn coex_schm_register_btdm_callback(_callback: *const ()) -> i32 { + trace!("coex_schm_register_btdm_callback"); + + #[cfg(coex)] + unsafe { + // COEX_SCHM_CALLBACK_TYPE_BT + coex_schm_register_callback(1, _callback as *mut esp_wifi_sys::c_types::c_void) + } + + #[cfg(not(coex))] + 0 +} + +extern "C" fn coex_schm_interval_get() -> i32 { + trace!("coex_schm_interval_get"); + + #[cfg(coex)] + unsafe { + esp_wifi_sys::include::coex_schm_interval_get() as i32 + } + + #[cfg(not(coex))] + 0 +} + +extern "C" fn coex_schm_curr_period_get() -> u8 { + trace!("coex_schm_curr_period_get"); + + #[cfg(coex)] + unsafe { + esp_wifi_sys::include::coex_schm_curr_period_get() + } + + #[cfg(not(coex))] + 0 +} + +extern "C" fn coex_schm_curr_phase_get() -> *const () { + trace!("coex_schm_curr_phase_get"); + + #[cfg(coex)] + unsafe { + esp_wifi_sys::include::coex_schm_curr_phase_get().cast() + } + + #[cfg(not(coex))] + core::ptr::null() +} + +extern "C" fn coex_bt_wakeup_request() { + trace!("coex_bt_wakeup_request"); + + extern "C" { + fn btdm_wakeup_request(); + } + + unsafe { + btdm_wakeup_request(); + } +} + +extern "C" fn coex_bt_wakeup_request_end() { + trace!("coex_bt_wakeup_request_end"); + + extern "C" { + fn btdm_in_wakeup_requesting_set(set: bool); + } + + unsafe { + btdm_in_wakeup_requesting_set(false); + } +} + extern "C" fn ets_delay_us_wrapper(us: u32) { extern "C" { fn ets_delay_us(us: u32); @@ -163,7 +250,7 @@ extern "C" { pub(crate) fn create_ble_config() -> esp_bt_controller_config_t { esp_bt_controller_config_t { magic: 0x5a5aa5a5, - version: 0x02307120, + version: 0x02404010, controller_task_stack_size: 8192, controller_task_prio: 200, controller_task_run_cpu: 0, @@ -196,15 +283,21 @@ pub(crate) fn create_ble_config() -> esp_bt_controller_config_t { scan_backoff_upperlimitmax: 0, ble_50_feat_supp: true, // BT_CTRL_50_FEATURE_SUPPORT ble_cca_mode: 0, + + ble_chan_ass_en: 0, + ble_data_lenth_zero_aux: 0, + ble_ping_en: 0, } } -pub(crate) unsafe extern "C" fn interrupt_on(intr_num: i32) { +pub(crate) unsafe extern "C" fn interrupt_on(intr_num: i32) -> i32 { trace!("interrupt_on {}", intr_num); - unsafe { crate::hal::xtensa_lx::interrupt::enable_mask(1 << 1) }; + + // NO-OP + 0 } -pub(crate) unsafe extern "C" fn interrupt_off(_intr_num: i32) { +pub(crate) unsafe extern "C" fn interrupt_off(_intr_num: i32) -> i32 { todo!(); } @@ -227,19 +320,25 @@ pub(crate) fn disable_sleep_mode() { pub(crate) unsafe extern "C" fn interrupt_set( cpu_no: i32, intr_source: i32, - interrupt_no: i32, - interrupt_prio: i32, -) { + handler: extern "C" fn(*const ()), + arg: *const (), + ret_handle: *mut *const (), +) -> i32 { trace!( - "interrupt_set {} {} {} {}", + "interrupt_set {} {} {} {} {}", cpu_no, intr_source, - interrupt_no, - interrupt_prio + handler as usize, + arg as u32, + ret_handle as usize, ); + + interrupt_handler_set(intr_source, handler, arg); + + 0 } -pub(crate) unsafe extern "C" fn interrupt_clear(_interrupt_source: i32, _interrupt_no: i32) { +pub(crate) unsafe extern "C" fn interrupt_clear(_handler: *const ()) -> i32 { todo!(); } diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32c2.rs b/esp-wifi/src/common_adapter/common_adapter_esp32c2.rs index 53906b025..53265bb42 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32c2.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32c2.rs @@ -42,14 +42,7 @@ pub(crate) unsafe fn phy_enable() { let init_data = &PHY_INIT_DATA_DEFAULT; - #[cfg(feature = "phy-enable-usb")] - { - extern "C" { - pub fn phy_bbpll_en_usb(param: bool); - } - - phy_bbpll_en_usb(true); - } + // DON'T CALL `phy_bbpll_en_usb` on ESP32-C2 register_chipv7_phy( init_data, diff --git a/esp-wifi/src/compat/common.rs b/esp-wifi/src/compat/common.rs index c130e1473..aa99512ff 100644 --- a/esp-wifi/src/compat/common.rs +++ b/esp-wifi/src/compat/common.rs @@ -10,15 +10,14 @@ use esp_wifi_sys::include::malloc; use super::malloc::free; use crate::{ - binary::{ - c_types::{c_int, c_void}, - include::OSI_FUNCS_TIME_BLOCKING, - }, + binary::c_types::{c_int, c_void}, memory_fence::memory_fence, preempt::current_task, timer::yield_task, }; +pub(crate) const OSI_FUNCS_TIME_BLOCKING: u32 = u32::MAX; + #[derive(Clone, Copy, Debug)] struct Mutex { locking_pid: usize, @@ -324,7 +323,7 @@ pub fn number_of_messages_in_queue(queue: *const c_void) -> u32 { /// Implementation of sleep() from newlib in esp-idf. /// components/newlib/time.c #[no_mangle] -unsafe extern "C" fn sleep( +pub(crate) unsafe extern "C" fn sleep( seconds: crate::binary::c_types::c_uint, ) -> crate::binary::c_types::c_uint { trace!("sleep"); diff --git a/esp-wifi/src/compat/timer_compat.rs b/esp-wifi/src/compat/timer_compat.rs index 507a7a1cb..b0fdd6aec 100644 --- a/esp-wifi/src/compat/timer_compat.rs +++ b/esp-wifi/src/compat/timer_compat.rs @@ -83,12 +83,18 @@ pub fn compat_timer_disarm(ets_timer: *mut ets_timer) { pub fn compat_timer_done(ets_timer: *mut ets_timer) { critical_section::with(|_| unsafe { - if let Some(timer) = TIMERS.iter_mut().find(|t| t.ets_timer == ets_timer) { + if let Some((idx, timer)) = TIMERS + .iter_mut() + .enumerate() + .find(|(_, t)| t.ets_timer == ets_timer) + { debug!("timer_done {:x}", timer.id()); timer.active = false; (*ets_timer).priv_ = core::ptr::null_mut(); (*ets_timer).expire = 0; + + TIMERS.swap_remove(idx); } else { debug!("timer_done {:x} not found", ets_timer as usize); } diff --git a/esp-wifi/src/lib.rs b/esp-wifi/src/lib.rs index 9d0cef6e3..62b4b6d35 100644 --- a/esp-wifi/src/lib.rs +++ b/esp-wifi/src/lib.rs @@ -452,7 +452,7 @@ impl From for InitializationError { /// Enable verbose logging within the WiFi driver /// Does nothing unless the `sys-logs` feature is enabled. pub fn wifi_set_log_verbose() { - #[cfg(feature = "sys-logs")] + #[cfg(all(feature = "sys-logs", not(esp32h2)))] unsafe { use crate::binary::include::{ esp_wifi_internal_set_log_level, diff --git a/esp-wifi/src/timer/timer_esp32c3.rs b/esp-wifi/src/timer/timer_esp32c3.rs index d71682d34..98be6c3ac 100644 --- a/esp-wifi/src/timer/timer_esp32c3.rs +++ b/esp-wifi/src/timer/timer_esp32c3.rs @@ -79,7 +79,7 @@ extern "C" fn RWBT() { #[no_mangle] extern "C" fn RWBLE() { unsafe { - let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::BT_INTERRUPT_FUNCTION5; + let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::BT_INTERRUPT_FUNCTION8; trace!("interrupt RWBLE {:?} {:?}", fnc, arg); @@ -96,7 +96,7 @@ extern "C" fn RWBLE() { #[no_mangle] extern "C" fn BT_BB(_trap_frame: &mut crate::hal::interrupt::TrapFrame) { unsafe { - let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::BT_INTERRUPT_FUNCTION8; + let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::BT_INTERRUPT_FUNCTION5; trace!("interrupt BT_BB {:?} {:?}", fnc, arg); diff --git a/esp-wifi/src/timer/timer_esp32s3.rs b/esp-wifi/src/timer/timer_esp32s3.rs index 1d7c33dfb..07d2bb9ec 100644 --- a/esp-wifi/src/timer/timer_esp32s3.rs +++ b/esp-wifi/src/timer/timer_esp32s3.rs @@ -51,7 +51,7 @@ extern "C" fn WIFI_PWR() { #[no_mangle] extern "C" fn RWBLE() { critical_section::with(|_| unsafe { - let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::ISR_INTERRUPT_5; + let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::ISR_INTERRUPT_8; trace!("interrupt RWBLE {:?} {:?}", fnc, arg); if !fnc.is_null() { let fnc: fn(*mut crate::binary::c_types::c_void) = core::mem::transmute(fnc); @@ -64,7 +64,7 @@ extern "C" fn RWBLE() { #[no_mangle] extern "C" fn BT_BB() { critical_section::with(|_| unsafe { - let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::ISR_INTERRUPT_8; + let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::ISR_INTERRUPT_5; trace!("interrupt RWBT {:?} {:?}", fnc, arg); if !fnc.is_null() { diff --git a/esp-wifi/src/wifi/mod.rs b/esp-wifi/src/wifi/mod.rs index 01058bb1b..6115a5f57 100644 --- a/esp-wifi/src/wifi/mod.rs +++ b/esp-wifi/src/wifi/mod.rs @@ -33,6 +33,7 @@ use esp_wifi_sys::include::{ esp_eap_fast_config, esp_wifi_sta_enterprise_enable, wifi_pkt_rx_ctrl_t, + wifi_scan_channel_bitmap_t, WIFI_PROTOCOL_11AX, WIFI_PROTOCOL_11B, WIFI_PROTOCOL_11G, @@ -830,21 +831,54 @@ pub enum WifiEvent { StaConnected, StaDisconnected, StaAuthmodeChange, + StaWpsErSuccess, StaWpsErFailed, StaWpsErTimeout, StaWpsErPin, StaWpsErPbcOverlap, + ApStart, ApStop, ApStaconnected, ApStadisconnected, ApProbereqrecved, + FtmReport, + StaBssRssiLow, ActionTxStatus, RocDone, + StaBeaconTimeout, + + ConnectionlessModuleWakeIntervalStart, // Connectionless module wake interval start + + ApWpsRgSuccess, // Soft-AP wps succeeds in registrar mode + ApWpsRgFailed, // Soft-AP wps fails in registrar mode + ApWpsRgTimeout, // Soft-AP wps timeout in registrar mode + ApWpsRgPin, // Soft-AP wps pin code in registrar mode + ApWpsRgPbcOverlap, // Soft-AP wps overlap in registrar mode + + ItwtSetup, // iTWT setup + ItwtTeardown, // iTWT teardown + ItwtProbe, // iTWT probe + ItwtSuspend, // iTWT suspend + TwtWakeup, // TWT wakeup + BtwtSetup, // bTWT setup + BtwtTeardown, // bTWT teardown + + NanStarted, // NAN Discovery has started + NanStopped, // NAN Discovery has stopped + NanSvcMatch, // NAN Service Discovery match found + NanReplied, // Replied to a NAN peer with Service Discovery match + NanReceive, // Received a Follow-up message + NdpIndication, // Received NDP Request from a NAN Peer + NdpConfirm, // NDP Confirm Indication + NdpTerminated, // NAN Datapath terminated indication + HomeChannelChange, // WiFi home channel change,doesn't occur when scanning + + StaNeighborRep, // Received Neighbor Report response } /// Error originating from the underlying drivers @@ -1141,24 +1175,24 @@ static g_wifi_osi_funcs: wifi_osi_funcs_t = wifi_osi_funcs_t { _sleep_retention_find_link_by_id: Some( os_adapter_chip_specific::sleep_retention_find_link_by_id_dummy, ), - #[cfg(esp32c6)] - _sleep_retention_entries_create: Some( - os_adapter_chip_specific::sleep_retention_entries_create_dummy, - ), - #[cfg(esp32c6)] - _sleep_retention_entries_destroy: Some( - os_adapter_chip_specific::sleep_retention_entries_destroy_dummy, - ), - _coex_schm_process_restart: Some(coex_schm_process_restart_wrapper), _coex_schm_register_cb: Some(coex_schm_register_cb_wrapper), _magic: ESP_WIFI_OS_ADAPTER_MAGIC as i32, + + _coex_schm_flexible_period_set: Some(coex_schm_flexible_period_set), + _coex_schm_flexible_period_get: Some(coex_schm_flexible_period_get), }; -const CONFIG_FEATURE_WPA3_SAE_BIT: u64 = 1 << 0; +const WIFI_ENABLE_WPA3_SAE: u64 = 1 << 0; +const WIFI_ENABLE_ENTERPRISE: u64 = 1 << 7; +// const WIFI_FTM_INITIATOR: u64 = 1 << 2; +// const WIFI_FTM_RESPONDER: u64 = 1 << 3; +// const WIFI_ENABLE_GCMP: u64 = 1 << 4; +// const WIFI_ENABLE_GMAC: u64 = 1 << 5; +// const WIFI_ENABLE_11R: u64 = 1 << 6; -const WIFI_FEATURE_CAPS: u64 = CONFIG_FEATURE_WPA3_SAE_BIT; +const WIFI_FEATURE_CAPS: u64 = WIFI_ENABLE_WPA3_SAE | WIFI_ENABLE_ENTERPRISE; #[no_mangle] static mut g_wifi_feature_caps: u64 = WIFI_FEATURE_CAPS; @@ -1220,6 +1254,9 @@ static mut G_CONFIG: wifi_init_config_t = wifi_init_config_t { sta_disconnected_pm: false, espnow_max_encrypt_num: 7, // 2 for ESP32-C2 magic: WIFI_INIT_CONFIG_MAGIC as i32, + + tx_hetb_queue_num: 3, + dump_hesigb_enable: false, }; /// Get the STA MAC address @@ -1399,16 +1436,6 @@ pub(crate) fn wifi_start() -> Result<(), WifiError> { Ok(()) } -unsafe extern "C" fn coex_register_start_cb( - _cb: Option c_types::c_int>, -) -> c_types::c_int { - #[cfg(coex)] - return include::coex_register_start_cb(_cb); - - #[cfg(not(coex))] - 0 -} - /// Configuration for active or passive scan. For details see the [WIFI Alliance FAQ](https://www.wi-fi.org/knowledge-center/faq/what-are-passive-and-active-scanning). /// /// # Comparison of active and passive scan @@ -1542,6 +1569,10 @@ pub(crate) fn wifi_start_scan( scan_type, scan_time, home_chan_dwell_time: 0, + channel_bitmap: wifi_scan_channel_bitmap_t { + ghz_2_channels: 0, + ghz_5_channels: 0, + }, }; unsafe { esp_wifi_scan_start(&scan_config, block) } @@ -2425,6 +2456,8 @@ fn apply_ap_config(config: &AccessPointConfiguration) -> Result<(), WifiError> { required: false, }, sae_pwe_h2e: 0, + csa_count: 3, + dtim_period: 2, }, }; @@ -3004,96 +3037,11 @@ mod asynch { impl WifiEvent { pub(crate) fn waker(&self) -> &'static AtomicWaker { - match self { - WifiEvent::ScanDone => { - static WAKER: AtomicWaker = AtomicWaker::new(); - &WAKER - } - WifiEvent::StaStart => { - static WAKER: AtomicWaker = AtomicWaker::new(); - &WAKER - } - WifiEvent::StaConnected => { - static WAKER: AtomicWaker = AtomicWaker::new(); - &WAKER - } - WifiEvent::StaDisconnected => { - static WAKER: AtomicWaker = AtomicWaker::new(); - &WAKER - } - WifiEvent::StaStop => { - static WAKER: AtomicWaker = AtomicWaker::new(); - &WAKER - } - WifiEvent::WifiReady => { - static WAKER: AtomicWaker = AtomicWaker::new(); - &WAKER - } - WifiEvent::StaAuthmodeChange => { - static WAKER: AtomicWaker = AtomicWaker::new(); - &WAKER - } - WifiEvent::StaWpsErSuccess => { - static WAKER: AtomicWaker = AtomicWaker::new(); - &WAKER - } - WifiEvent::StaWpsErFailed => { - static WAKER: AtomicWaker = AtomicWaker::new(); - &WAKER - } - WifiEvent::StaWpsErTimeout => { - static WAKER: AtomicWaker = AtomicWaker::new(); - &WAKER - } - WifiEvent::StaWpsErPin => { - static WAKER: AtomicWaker = AtomicWaker::new(); - &WAKER - } - WifiEvent::StaWpsErPbcOverlap => { - static WAKER: AtomicWaker = AtomicWaker::new(); - &WAKER - } - WifiEvent::ApStart => { - static WAKER: AtomicWaker = AtomicWaker::new(); - &WAKER - } - WifiEvent::ApStop => { - static WAKER: AtomicWaker = AtomicWaker::new(); - &WAKER - } - WifiEvent::ApStaconnected => { - static WAKER: AtomicWaker = AtomicWaker::new(); - &WAKER - } - WifiEvent::ApStadisconnected => { - static WAKER: AtomicWaker = AtomicWaker::new(); - &WAKER - } - WifiEvent::ApProbereqrecved => { - static WAKER: AtomicWaker = AtomicWaker::new(); - &WAKER - } - WifiEvent::FtmReport => { - static WAKER: AtomicWaker = AtomicWaker::new(); - &WAKER - } - WifiEvent::StaBssRssiLow => { - static WAKER: AtomicWaker = AtomicWaker::new(); - &WAKER - } - WifiEvent::ActionTxStatus => { - static WAKER: AtomicWaker = AtomicWaker::new(); - &WAKER - } - WifiEvent::RocDone => { - static WAKER: AtomicWaker = AtomicWaker::new(); - &WAKER - } - WifiEvent::StaBeaconTimeout => { - static WAKER: AtomicWaker = AtomicWaker::new(); - &WAKER - } - } + // for now use only one waker for all events + // if that ever becomes a problem we might want to pick some events to use their + // own + static WAKER: AtomicWaker = AtomicWaker::new(); + &WAKER } } diff --git a/esp-wifi/src/wifi/os_adapter.rs b/esp-wifi/src/wifi/os_adapter.rs index c62d2d8ea..5b13d69bf 100644 --- a/esp-wifi/src/wifi/os_adapter.rs +++ b/esp-wifi/src/wifi/os_adapter.rs @@ -1993,6 +1993,48 @@ pub unsafe extern "C" fn coex_schm_register_cb_wrapper( ) } +pub unsafe extern "C" fn coex_schm_flexible_period_set(period: u8) -> i32 { + trace!("coex_schm_flexible_period_set {}", period); + + #[cfg(coex)] + unsafe { + extern "C" { + fn coex_schm_flexible_period_set(period: u8) -> i32; + } + + coex_schm_flexible_period_set(period) + } + + #[cfg(not(coex))] + 0 +} + +pub unsafe extern "C" fn coex_schm_flexible_period_get() -> u8 { + trace!("coex_schm_flexible_period_get"); + + #[cfg(coex)] + unsafe { + extern "C" { + fn coex_schm_flexible_period_get() -> u8; + } + + coex_schm_flexible_period_get() + } + + #[cfg(not(coex))] + 0 +} + +pub unsafe extern "C" fn coex_register_start_cb( + _cb: Option esp_wifi_sys::c_types::c_int>, +) -> esp_wifi_sys::c_types::c_int { + #[cfg(coex)] + return esp_wifi_sys::include::coex_register_start_cb(_cb); + + #[cfg(not(coex))] + 0 +} + /// ************************************************************************** /// Name: esp_clk_slowclk_cal_get_wrapper /// diff --git a/esp-wifi/src/wifi/os_adapter_esp32c6.rs b/esp-wifi/src/wifi/os_adapter_esp32c6.rs index 5195f807f..767669452 100644 --- a/esp-wifi/src/wifi/os_adapter_esp32c6.rs +++ b/esp-wifi/src/wifi/os_adapter_esp32c6.rs @@ -83,21 +83,6 @@ pub(crate) unsafe extern "C" fn sleep_retention_find_link_by_id_dummy( todo!() } -pub(crate) unsafe extern "C" fn sleep_retention_entries_create_dummy( - _arg1: *const esp_wifi_sys::c_types::c_void, - _arg2: esp_wifi_sys::c_types::c_int, - _arg3: esp_wifi_sys::c_types::c_int, - _arg4: esp_wifi_sys::c_types::c_int, -) -> esp_wifi_sys::c_types::c_int { - todo!() -} - -pub(crate) unsafe extern "C" fn sleep_retention_entries_destroy_dummy( - _arg1: esp_wifi_sys::c_types::c_int, -) { - todo!() -} - /// ************************************************************************** /// Name: esp_set_isr ///