diff --git a/sphinx-key/Cargo.lock b/sphinx-key/Cargo.lock index 62bb909..971db3f 100644 --- a/sphinx-key/Cargo.lock +++ b/sphinx-key/Cargo.lock @@ -100,12 +100,6 @@ dependencies = [ "stable_deref_trait", ] -[[package]] -name = "async-task" -version = "4.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae" - [[package]] name = "atomic-polyfill" version = "0.1.11" @@ -533,18 +527,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "edge-executor" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc1d66feda51959c8bb07b752c20f1d061eceb178bc91b793a0b32c792c631cf" -dependencies = [ - "async-task", - "heapless", - "log", - "waker-fn", -] - [[package]] name = "either" version = "1.8.1" @@ -557,6 +539,18 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47e5367165d347c039360f784812f493b001583ab6a3dd8622f4ce9c30374ec3" +[[package]] +name = "embassy-sync" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0525b466ca3ace30b57f2db868a35215dfaecd038d8668cb2db03feb7c069a0" +dependencies = [ + "cfg-if", + "critical-section", + "futures-util", + "heapless", +] + [[package]] name = "embedded-can" version = "0.4.1" @@ -578,54 +572,60 @@ dependencies = [ [[package]] name = "embedded-hal" -version = "1.0.0-alpha.10" +version = "1.0.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f65c4d073f5d91c66e629b216818a4c9747eeda0debedf2deda9a0a947e4e93b" +checksum = "2894bc2f0457b8ca3d6b8ab8aad64d9337583672494013457f86c5a9146c0e22" [[package]] name = "embedded-hal-nb" -version = "1.0.0-alpha.2" +version = "1.0.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1465fffd56a95bbc105c17965bca1c1d5815027b1cc6bb183bc05d04563d065c" +checksum = "257e3bb0163c69195acb0ebe0083b017b963235861d5ea9741626abdc55f39c9" dependencies = [ - "embedded-hal 1.0.0-alpha.10", + "embedded-hal 1.0.0-rc.1", "nb 1.1.0", ] [[package]] name = "embedded-io" -version = "0.4.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" +checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" + +[[package]] +name = "embedded-io-async" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de03527d6fb488b2d7c7a4dc81dfb6a657efe264256bfc70bb899746821666b1" dependencies = [ - "futures", + "embedded-io", ] [[package]] name = "embedded-svc" -version = "0.25.3" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adb928fd4f8e71dee7628bbab86b25df74c503fc5209cfeeb174a9806bb4fd11" +checksum = "15b1a857f242e7cfeaeae173f8618750b496de21f43ac3e8963404a17498e2e1" dependencies = [ - "anyhow", "atomic-waker", "defmt", "embedded-io", + "embedded-io-async", "enumset", "heapless", "log", "no-std-net", "num_enum", "serde", - "strum 0.23.0", - "strum_macros 0.23.1", + "strum 0.25.0", + "strum_macros 0.25.3", ] [[package]] name = "embuild" -version = "0.31.2" +version = "0.31.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ad838e9b86748e477f1d882c41777978947ca3a1f0cdde572234bc7dc68ed3d" +checksum = "781ccceeeb5ec01843b78b12b39cab4c90d6dbf853e1e8c2536cdb16e9da642a" dependencies = [ "anyhow", "bindgen", @@ -705,47 +705,48 @@ dependencies = [ [[package]] name = "esp-idf-hal" -version = "0.41.2" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea0ed6e41edf280787a5325aae0c82d39b1fb5ae3199871cd164ae1a650704d6" +checksum = "19d73423bcc800c4045bfe8a67283338cfea0756c238802efd44c8da77b5b714" dependencies = [ - "anyhow", "atomic-waker", - "edge-executor", + "embassy-sync", "embedded-can", "embedded-hal 0.2.7", - "embedded-hal 1.0.0-alpha.10", + "embedded-hal 1.0.0-rc.1", "embedded-hal-nb", + "embedded-io", "embuild", "enumset", "esp-idf-sys", "heapless", + "log", "nb 1.1.0", + "num_enum", ] [[package]] name = "esp-idf-svc" -version = "0.46.0" +version = "0.47.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "665233a26567d141f1bab603b9a868dc28bb8bea1188e7d927bab44329b84d63" +checksum = "08bc6a63b023585d3ccad0a1cf22531495a45b6554c051c3a14b71879da12827" dependencies = [ - "anyhow", "embassy-futures", "embedded-svc", "embuild", "enumset", "esp-idf-hal", - "esp-idf-sys", "heapless", "log", + "num_enum", "uncased", ] [[package]] name = "esp-idf-sys" -version = "0.33.1" +version = "0.33.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d793b605e8037907f0e6697b0995a355238f065f321dd389fdf866aa9f8d140" +checksum = "0ee72f44dbf6e77ccaee0c6f0a0e4f2ccfad184ef4ccb678491b4f4570c2c1d4" dependencies = [ "anyhow", "bindgen", @@ -758,6 +759,7 @@ dependencies = [ "regex", "serde", "strum 0.24.1", + "which", ] [[package]] @@ -820,48 +822,12 @@ dependencies = [ "thiserror", ] -[[package]] -name = "futures" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" -dependencies = [ - "futures-core", - "futures-sink", -] - [[package]] name = "futures-core" version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" -[[package]] -name = "futures-io" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" - -[[package]] -name = "futures-sink" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" - [[package]] name = "futures-task" version = "0.3.28" @@ -874,15 +840,10 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" dependencies = [ - "futures-channel", "futures-core", - "futures-io", - "futures-sink", "futures-task", - "memchr", "pin-project-lite", "pin-utils", - "slab", ] [[package]] @@ -981,15 +942,6 @@ dependencies = [ "stable_deref_trait", ] -[[package]] -name = "heck" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "heck" version = "0.4.1" @@ -1322,23 +1274,23 @@ dependencies = [ [[package]] name = "num_enum" -version = "0.5.11" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f646caf906c20226733ed5b1374287eb97e3c2a5c227ce668c1f2ce20ae57c9" +checksum = "70bf6736f74634d299d00086f02986875b3c2d924781a6a2cb6c201e73da0ceb" dependencies = [ "num_enum_derive", ] [[package]] name = "num_enum_derive" -version = "0.5.11" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcbff9bc912032c62bf65ef1d5aea88983b420f4f839db1e9b0c281a25c9c799" +checksum = "56ea360eafe1022f7cc56cd7b869ed57330fb2453d0c7831d99b74c65d2f5597" dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.25", ] [[package]] @@ -1771,15 +1723,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" -[[package]] -name = "slab" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" -dependencies = [ - "autocfg", -] - [[package]] name = "smallvec" version = "0.6.14" @@ -1831,12 +1774,10 @@ version = "0.1.0" dependencies = [ "anyhow", "bitflags", - "embedded-hal 1.0.0-alpha.10", + "embedded-hal 1.0.0-rc.1", "embedded-svc", "embuild", - "esp-idf-hal", "esp-idf-svc", - "esp-idf-sys", "hex", "log", "lss-connector", @@ -1895,15 +1836,6 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" -[[package]] -name = "strum" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cae14b91c7d11c9a851d3fbc80a963198998c2a64eec840477fa92d8ce9b70bb" -dependencies = [ - "strum_macros 0.23.1", -] - [[package]] name = "strum" version = "0.24.1" @@ -1914,16 +1846,12 @@ dependencies = [ ] [[package]] -name = "strum_macros" -version = "0.23.1" +name = "strum" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb0dc7ee9c15cea6199cde9a127fa16a4c5819af85395457ad72d68edc85a38" +checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" dependencies = [ - "heck 0.3.3", - "proc-macro2", - "quote", - "rustversion", - "syn 1.0.109", + "strum_macros 0.25.3", ] [[package]] @@ -1932,13 +1860,26 @@ version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" dependencies = [ - "heck 0.4.1", + "heck", "proc-macro2", "quote", "rustversion", "syn 1.0.109", ] +[[package]] +name = "strum_macros" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.25", +] + [[package]] name = "subtle" version = "2.5.0" @@ -2091,12 +2032,6 @@ dependencies = [ "smallvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - [[package]] name = "unicode-xid" version = "0.2.4" @@ -2198,12 +2133,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" -[[package]] -name = "waker-fn" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" - [[package]] name = "walkdir" version = "2.3.3" diff --git a/sphinx-key/Cargo.toml b/sphinx-key/Cargo.toml index 78fa681..42e0700 100644 --- a/sphinx-key/Cargo.toml +++ b/sphinx-key/Cargo.toml @@ -31,11 +31,9 @@ sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs.git", optional = anyhow = { version = "1", features = ["backtrace"] } bitflags = "1.3.2" -embedded-hal = "=1.0.0-alpha.10" -embedded-svc = "0.25.0" -esp-idf-hal = "0.41.1" -esp-idf-svc = { version = "0.46.0", features = ["experimental", "alloc"] } -esp-idf-sys = { version = "0.33.1", features = ["binstart"] } +embedded-hal = "=1.0.0-rc.1" +embedded-svc = "0.26.1" +esp-idf-svc = { version = "0.47.1", features = ["experimental", "alloc", "binstart"] } log = "0.4.17" [build-dependencies] diff --git a/sphinx-key/build.rs b/sphinx-key/build.rs index ccb6e75..112ec3f 100644 --- a/sphinx-key/build.rs +++ b/sphinx-key/build.rs @@ -1,6 +1,3 @@ -// Necessary because of this issue: https://github.com/rust-lang/cargo/issues/9641 -fn main() -> Result<(), Box> { - embuild::build::CfgArgs::output_propagated("ESP_IDF")?; - embuild::build::LinkArgs::output_propagated("ESP_IDF")?; - Ok(()) +fn main() { + embuild::espidf::sysenv::output(); } diff --git a/sphinx-key/src/btn.rs b/sphinx-key/src/btn.rs index 6ded5e8..9a5b292 100644 --- a/sphinx-key/src/btn.rs +++ b/sphinx-key/src/btn.rs @@ -5,14 +5,14 @@ mod periph; mod status; pub use crate::core::control::FlashPersister; -use esp_idf_hal::gpio::Gpio0; -use esp_idf_hal::gpio::Gpio9; -use esp_idf_hal::peripheral::Peripheral; -use esp_idf_hal::peripherals::Peripherals; +use esp_idf_svc::hal::gpio::Gpio0; +use esp_idf_svc::hal::gpio::Gpio9; +use esp_idf_svc::hal::peripheral::Peripheral; +use esp_idf_svc::hal::peripherals::Peripherals; use esp_idf_svc::nvs::EspDefaultNvsPartition; use esp_idf_svc::nvs::EspNvs; use esp_idf_svc::nvs::*; -use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported +use esp_idf_svc::sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported use log; use status::Status; use std::sync::mpsc; @@ -23,7 +23,7 @@ use std::time::Duration; const ID_LEN: usize = 16; fn main() -> anyhow::Result<()> { - esp_idf_sys::link_patches(); + esp_idf_svc::sys::link_patches(); esp_idf_svc::log::EspLogger::initialize_default(); thread::sleep(Duration::from_secs(1)); let mut peripherals = Peripherals::take().unwrap(); diff --git a/sphinx-key/src/clear.rs b/sphinx-key/src/clear.rs index 4d34f67..a9dc99a 100644 --- a/sphinx-key/src/clear.rs +++ b/sphinx-key/src/clear.rs @@ -7,7 +7,7 @@ mod status; #[allow(unused_imports)] use crate::periph::sd::mount_sd_card; -use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported +use esp_idf_svc as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported // use embedded_svc::storage::StorageBase; // use esp_idf_svc::nvs::EspNvs; diff --git a/sphinx-key/src/conn/http.rs b/sphinx-key/src/conn/http.rs index 9813db8..0814a8a 100644 --- a/sphinx-key/src/conn/http.rs +++ b/sphinx-key/src/conn/http.rs @@ -1,17 +1,12 @@ use crate::core::config::{decrypt_seed, ecdh_keypair, ConfigDTO}; -use sphinx_signer::sphinx_glyph::control::Config; - +use anyhow::Result; +use esp_idf_svc::http::server::HandlerError; +use esp_idf_svc::http::server::{Configuration, EspHttpServer}; +use esp_idf_svc::http::Method; use serde::Deserialize; +use sphinx_signer::sphinx_glyph::control::Config; use std::sync::{Arc, Condvar, Mutex}; -// use embedded_svc::http::server::registry::Registry; -// use embedded_svc::http::server::*; -#[allow(deprecated)] -use embedded_svc::httpd::registry::Registry; -use embedded_svc::httpd::Result; - -use esp_idf_svc::httpd as idf; - #[derive(Clone, Debug, Deserialize)] pub struct Ecdh { pub pubkey: String, @@ -21,42 +16,37 @@ pub struct Params { pub config: String, } -#[allow(unused_variables, deprecated)] pub fn config_server( mutex: Arc<(Mutex)>>, Condvar)>, has_stored_seed: bool, -) -> Result { +) -> Result> { let (sk1, pk1) = ecdh_keypair(); - let server = idf::ServerRegistry::new() - .at("/ecdh") - .get(move |_| { - Ok( - format!("{{\"pubkey\":\"{}\"}}", hex::encode(pk1.serialize())) - .to_owned() - .into(), - ) + let mut server = EspHttpServer::new(&Configuration::default()).unwrap(); + server + .fn_handler("/ecdh", Method::Get, move |request| { + let mut response = request.into_ok_response()?; + response.write( + &format!("{{\"pubkey\":\"{}\"}}", hex::encode(pk1.serialize())).into_bytes(), + )?; + response.flush()?; + Ok(()) })? - .at("/config") - .post(move |request| { - let bod = &request - .query_string() - .ok_or(anyhow::anyhow!("failed to parse query string"))?; - println!("bod {:?}", bod); - let params = serde_urlencoded::from_str::(bod)?; - + .fn_handler("/config", Method::Post, move |request| { + let params = + serde_urlencoded::from_str::(request.uri().split_once("?").unwrap().1)?; let dto = serde_json::from_str::(¶ms.config)?; - let conf_seed_tuple = decrypt_seed(dto, sk1)?; if !has_stored_seed && conf_seed_tuple.1.is_none() { - return Err(anyhow::anyhow!("seed required")); + return Err(HandlerError::new("seed required")); } - let mut wait = mutex.0.lock().unwrap(); *wait = Some(conf_seed_tuple); mutex.1.notify_one(); - Ok("{\"success\":true}".to_owned().into()) + let mut response = request.into_ok_response()?; + response.write("{\"success\":true}".as_bytes())?; + response.flush()?; + Ok(()) })?; - - server.start(&Default::default()) + Ok(server) } diff --git a/sphinx-key/src/conn/mqtt.rs b/sphinx-key/src/conn/mqtt.rs index 823152b..85dbc6d 100644 --- a/sphinx-key/src/conn/mqtt.rs +++ b/sphinx-key/src/conn/mqtt.rs @@ -2,14 +2,10 @@ use crate::core::events::Event as CoreEvent; use sphinx_signer::sphinx_glyph::topics; use anyhow::Result; -use embedded_svc::mqtt::client::Details; -use embedded_svc::mqtt::client::{Connection, Event, Message as MqttMessage, MessageImpl, QoS}; -use embedded_svc::utils::mqtt::client::ConnState; // use embedded_svc::utils::mqtt::client::Connection as MqttConnection; // use embedded_svc::utils::mutex::Condvar; use esp_idf_svc::mqtt::client::*; -use esp_idf_sys::EspError; -use esp_idf_sys::{self}; +use esp_idf_svc::sys::EspError; use log::*; use std::sync::mpsc; use std::thread; @@ -22,7 +18,7 @@ pub fn make_client( username: &str, password: &str, tx: mpsc::Sender, -) -> Result>> { +) -> Result>> { let client_id = hex::encode(signer_id); log::info!("make_client with id {}", client_id); @@ -36,7 +32,7 @@ pub fn make_client( }; if cfg!(feature = "tls") { - conf.crt_bundle_attach = Some(esp_idf_sys::esp_crt_bundle_attach); + conf.crt_bundle_attach = Some(esp_idf_svc::sys::esp_crt_bundle_attach); } let mut mqtturl = broker.to_string(); diff --git a/sphinx-key/src/conn/wifi.rs b/sphinx-key/src/conn/wifi.rs index 20cdeaf..cb33c46 100644 --- a/sphinx-key/src/conn/wifi.rs +++ b/sphinx-key/src/conn/wifi.rs @@ -1,16 +1,17 @@ -use embedded_svc::httpd::Result; -use embedded_svc::ipv4; -use embedded_svc::wifi::*; -use esp_idf_hal::peripheral; +use anyhow::Result; use esp_idf_svc::eventloop::EspSystemEventLoop; +use esp_idf_svc::hal::peripheral; +use esp_idf_svc::ipv4::Ipv4Addr; use esp_idf_svc::nvs::EspDefaultNvsPartition; -use esp_idf_svc::ping; -use esp_idf_svc::wifi::*; +use esp_idf_svc::ping::EspPing; +use esp_idf_svc::wifi::{ + AccessPointConfiguration, AuthMethod, BlockingWifi, ClientConfiguration, Configuration, EspWifi, +}; use log::*; use sphinx_signer::sphinx_glyph::control::Config; pub fn start_client( - modem: impl peripheral::Peripheral

+ 'static, + modem: impl peripheral::Peripheral

+ 'static, default_nvs: EspDefaultNvsPartition, config: &Config, ) -> Result>> { @@ -72,7 +73,7 @@ fn try_connection(wifi: &mut BlockingWifi>) -> Result<()> { } pub fn start_access_point( - modem: impl peripheral::Peripheral

+ 'static, + modem: impl peripheral::Peripheral

+ 'static, default_nvs: EspDefaultNvsPartition, ) -> Result>> { let sysloop = EspSystemEventLoop::take()?; @@ -121,15 +122,14 @@ pub fn start_access_point( Ok(wifi) } -fn _ping(ip_settings: &ipv4::ClientSettings) -> Result<()> { - info!("About to do some pings for {:?}", ip_settings); +fn _ping(ip_addr: Ipv4Addr) -> Result<()> { + info!("About to do some pings for {}", ip_addr); - let ping_summary = - ping::EspPing::default().ping(ip_settings.subnet.gateway, &Default::default())?; + let ping_summary = EspPing::default().ping(ip_addr, &Default::default())?; if ping_summary.transmitted != ping_summary.received { return Err(anyhow::anyhow!( "Pinging gateway {} resulted in timeouts", - ip_settings.subnet.gateway + ip_addr )); } diff --git a/sphinx-key/src/core/config.rs b/sphinx-key/src/core/config.rs index e0772e2..2a8d192 100644 --- a/sphinx-key/src/core/config.rs +++ b/sphinx-key/src/core/config.rs @@ -9,7 +9,7 @@ use std::time::Duration; use esp_idf_svc::nvs::*; use esp_idf_svc::wifi::*; -use esp_idf_hal::peripheral; +use esp_idf_svc::hal::peripheral; use sphinx_crypter::chacha::{decrypt, PAYLOAD_LEN}; use sphinx_crypter::ecdh::{derive_shared_secret_from_slice, PUBLIC_KEY_LEN}; @@ -41,7 +41,7 @@ arp -a */ pub fn start_wifi_client( - modem: impl peripheral::Peripheral

+ 'static, + modem: impl peripheral::Peripheral

+ 'static, default_nvs: EspDefaultNvsPartition, config: &Config, ) -> Result> { @@ -81,7 +81,7 @@ pub fn decrypt_seed(dto: ConfigDTO, sk1: SecretKey) -> Result<(Config, Option<[u } pub fn start_config_server_and_wait( - modem: impl peripheral::Peripheral

+ 'static, + modem: impl peripheral::Peripheral

+ 'static, default_nvs: EspDefaultNvsPartition, has_stored_seed: bool, ) -> Result<(BlockingWifi>, Config, Option<[u8; 32]>)> { diff --git a/sphinx-key/src/core/events.rs b/sphinx-key/src/core/events.rs index 5560823..9815e82 100644 --- a/sphinx-key/src/core/events.rs +++ b/sphinx-key/src/core/events.rs @@ -11,7 +11,7 @@ use lss_connector::secp256k1::PublicKey; use sphinx_signer::approver::SphinxApprover; use sphinx_signer::lightning_signer::bitcoin::Network; //use sphinx_signer::lightning_signer::persist::DummyPersister; -use sphinx_signer::kvv::{CloudKVVStore, FsKVVStore, KVVStore}; +use sphinx_signer::kvv::{CloudKVVStore, FsKVVStore}; use sphinx_signer::lightning_signer::persist::Persist; use sphinx_signer::root::VlsHandlerError; use sphinx_signer::sphinx_glyph as glyph; @@ -20,13 +20,9 @@ use std::sync::mpsc; use std::sync::Arc; use std::thread; -use embedded_svc::httpd::Result; // use embedded_svc::mqtt::client::Client; -use embedded_svc::mqtt::client::MessageImpl; -use embedded_svc::utils::mqtt::client::ConnState; use esp_idf_svc::mqtt::client::*; -use esp_idf_sys; -use esp_idf_sys::EspError; +use esp_idf_svc::sys::EspError; #[derive(Debug)] pub enum Event { @@ -78,7 +74,7 @@ pub fn make_event_loop( mut ctrlr: Controller, signer_id: &[u8; 16], node_id: &PublicKey, -) -> Result<()> { +) { let client_id = hex::encode(signer_id); while let Ok(event) = rx.recv() { @@ -137,7 +133,7 @@ pub fn make_event_loop( Ok(rl) => rl, Err(e) => { log::error!("failed to init lss {:?}", e); - unsafe { esp_idf_sys::esp_restart() }; + unsafe { esp_idf_svc::sys::esp_restart() }; } }; @@ -149,6 +145,8 @@ pub fn make_event_loop( let flash_db = ctrlr.persister(); let mut expected_sequence = None; while let Ok(event) = rx.recv() { + log::info!("new event loop!"); + check_memory(); match event { Event::Connected => { log::info!("GOT A Event::Connected msg!"); @@ -184,22 +182,22 @@ pub fn make_event_loop( // and commit if let Err(e) = root_handler.node().get_persister().commit() { log::error!("LOCAL COMMIT ERROR! {:?}", e); - unsafe { esp_idf_sys::esp_restart() }; + unsafe { esp_idf_svc::sys::esp_restart() }; } restart_esp_if_memory_low(); } expected_sequence = Some(sequence + 1); } Err(e) => match e { - VlsHandlerError::BadSequence(current, expected) => unsafe { + VlsHandlerError::BadSequence(current, expected) => { log::info!( "caught a badsequence error, current: {}, expected: {}", current, expected ); log::info!("restarting esp!"); - unsafe { esp_idf_sys::esp_restart() }; - }, + unsafe { esp_idf_svc::sys::esp_restart() }; + } _ => { let err_msg = GlyphError::new(1, &e.to_string()); log::error!("HANDLE FAILED {:?}", e); @@ -228,13 +226,13 @@ pub fn make_event_loop( // and commit if let Err(e) = root_handler.node().get_persister().commit() { log::error!("LOCAL COMMIT ERROR AFTER LSS! {:?}", e); - unsafe { esp_idf_sys::esp_restart() }; + unsafe { esp_idf_svc::sys::esp_restart() }; } restart_esp_if_memory_low(); } if ret_topic == topics::LSS_CONFLICT_RES { log::error!("LSS PUT CONFLICT! RESTART..."); - unsafe { esp_idf_sys::esp_restart() }; + unsafe { esp_idf_svc::sys::esp_restart() }; } } Err(e) => { @@ -259,14 +257,12 @@ pub fn make_event_loop( } } } - - Ok(()) } -fn restart_esp_if_memory_low() { +pub(crate) fn restart_esp_if_memory_low() { unsafe { - let size = esp_idf_sys::heap_caps_get_free_size(4); - let block = esp_idf_sys::heap_caps_get_largest_free_block(4); + let size = esp_idf_svc::sys::heap_caps_get_free_size(4); + let block = esp_idf_svc::sys::heap_caps_get_largest_free_block(4); let threshold = 25000; log::info!( "Available DRAM: {}, Max block: {}, Restart Threshold: {}", @@ -276,11 +272,19 @@ fn restart_esp_if_memory_low() { ); if block < threshold { log::info!("Restarting esp!"); - esp_idf_sys::esp_restart(); + esp_idf_svc::sys::esp_restart(); } } } +pub(crate) fn check_memory() { + unsafe { + let size = esp_idf_svc::sys::heap_caps_get_free_size(4); + let block = esp_idf_svc::sys::heap_caps_get_largest_free_block(4); + log::info!("CHECK: Available DRAM: {}, Max block: {}", size, block,); + } +} + fn handle_control_response( root_handler: &RootHandler, approver: &SphinxApprover, @@ -331,7 +335,7 @@ fn handle_control_response( log::error!("OTA update failed {:?}", e.to_string()); } else { log::info!("OTA flow complete, restarting esp..."); - unsafe { esp_idf_sys::esp_restart() }; + unsafe { esp_idf_svc::sys::esp_restart() }; } }) .unwrap(); diff --git a/sphinx-key/src/core/lss.rs b/sphinx-key/src/core/lss.rs index 4ecdda1..d2c965a 100644 --- a/sphinx-key/src/core/lss.rs +++ b/sphinx-key/src/core/lss.rs @@ -1,10 +1,10 @@ use crate::conn::mqtt::QOS; use crate::core::events::Event; use anyhow::{anyhow, Result}; -use embedded_svc::mqtt::client::MessageImpl; -use embedded_svc::utils::mqtt::client::ConnState; +use esp_idf_svc::mqtt::client::ConnState; use esp_idf_svc::mqtt::client::EspMqttClient; -use esp_idf_sys::EspError; +use esp_idf_svc::mqtt::client::MessageImpl; +use esp_idf_svc::sys::EspError; use lss_connector::{secp256k1::PublicKey, BrokerMutations, LssSigner, Msg as LssMsg}; use sphinx_signer::sphinx_glyph::topics; use sphinx_signer::{self, RootHandler, RootHandlerBuilder}; diff --git a/sphinx-key/src/main.rs b/sphinx-key/src/main.rs index 9d47094..466d5dd 100644 --- a/sphinx-key/src/main.rs +++ b/sphinx-key/src/main.rs @@ -11,13 +11,13 @@ use crate::periph::led::led_control_loop; #[allow(unused_imports)] use crate::periph::sd::{mount_sd_card, simple_fs_test}; use crate::status::Status; - use anyhow::Result; -use esp_idf_hal::gpio::{Gpio0, Gpio9}; -use esp_idf_hal::peripheral::Peripheral; -use esp_idf_hal::peripherals::Peripherals; +use esp_idf_svc::hal::gpio::{Gpio0, Gpio9}; +use esp_idf_svc::hal::peripheral::Peripheral; +use esp_idf_svc::hal::peripherals::Peripherals; use esp_idf_svc::nvs::EspDefaultNvsPartition; -use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported +#[allow(unused_imports)] +use esp_idf_svc::sys as _; use sphinx_signer::lightning_signer::bitcoin::Network; use sphinx_signer::sphinx_glyph::control::{Config, ControlPersist, Policy, Velocity}; use std::sync::{mpsc, Arc, Mutex}; @@ -30,7 +30,7 @@ const ID_LEN: usize = 16; fn main() -> Result<()> { // Temporary. Will disappear once ESP-IDF 4.4 is released, but for now it is necessary to call this function once, // or else some patches to the runtime implemented by esp-idf-sys might not link properly. - esp_idf_sys::link_patches(); + esp_idf_svc::sys::link_patches(); esp_idf_svc::log::EspLogger::initialize_default(); thread::sleep(Duration::from_secs(1)); let mut peripherals = Peripherals::take().unwrap(); @@ -82,7 +82,7 @@ fn main() -> Result<()> { Err(e) => { log::error!("Could not setup wifi: {}", e); log::info!("Restarting esp!"); - unsafe { esp_idf_sys::esp_restart() }; + unsafe { esp_idf_svc::sys::esp_restart() }; } }; @@ -90,7 +90,7 @@ fn main() -> Result<()> { if let Err(e) = conn::sntp::sync_time_timeout() { log::error!("Could not setup sntp: {}", e); log::info!("Restarting esp!"); - unsafe { esp_idf_sys::esp_restart() }; + unsafe { esp_idf_svc::sys::esp_restart() }; } let now = SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) @@ -142,7 +142,7 @@ fn main() -> Result<()> { drop(flash); println!("CONFIG SAVED"); thread::sleep(Duration::from_secs(2)); - unsafe { esp_idf_sys::esp_restart() }; + unsafe { esp_idf_svc::sys::esp_restart() }; } Err(msg) => { log::error!("{}", msg); @@ -204,7 +204,7 @@ fn make_and_launch_client( ctrlr, &signer_id, &pubkey, - )?; + ); Ok(()) } diff --git a/sphinx-key/src/ota.rs b/sphinx-key/src/ota.rs index 023eb82..41a17a4 100644 --- a/sphinx-key/src/ota.rs +++ b/sphinx-key/src/ota.rs @@ -1,7 +1,6 @@ use crate::status::Status; use anyhow::{anyhow, Result}; use embedded_svc::http::client::Client; - use esp_idf_svc::http::client::Configuration; use esp_idf_svc::http::client::EspHttpConnection; use esp_idf_svc::http::client::FollowRedirectsPolicy::FollowNone; diff --git a/sphinx-key/src/periph/button.rs b/sphinx-key/src/periph/button.rs index 7f23fba..ef3117b 100644 --- a/sphinx-key/src/periph/button.rs +++ b/sphinx-key/src/periph/button.rs @@ -1,8 +1,8 @@ use crate::core::FlashPersister; use crate::status::Status; use anyhow::Result; -use esp_idf_hal::gpio; -use esp_idf_hal::gpio::*; +use esp_idf_svc::hal::gpio; +use esp_idf_svc::hal::gpio::*; use sphinx_signer::sphinx_glyph::control::ControlPersist; use std::sync::{mpsc, Arc, Mutex}; use std::thread; @@ -37,7 +37,7 @@ pub fn button_loop( } else { log::info!("restarting esp!"); drop(flash); - unsafe { esp_idf_sys::esp_restart() }; + unsafe { esp_idf_svc::sys::esp_restart() }; } } thread::sleep(Duration::from_millis(PAUSE.into())); diff --git a/sphinx-key/src/periph/led.rs b/sphinx-key/src/periph/led.rs index baa482a..79bd290 100644 --- a/sphinx-key/src/periph/led.rs +++ b/sphinx-key/src/periph/led.rs @@ -1,8 +1,8 @@ use crate::status::Status; use anyhow::Result; -use esp_idf_hal::rmt::config::TransmitConfig; -use esp_idf_hal::rmt::{FixedLengthSignal, PinState, Pulse, TxRmtDriver}; -use esp_idf_hal::{gpio, rmt}; +use esp_idf_svc::hal::rmt::config::TransmitConfig; +use esp_idf_svc::hal::rmt::{FixedLengthSignal, PinState, Pulse, TxRmtDriver}; +use esp_idf_svc::hal::{gpio, rmt}; use std::collections::BTreeMap; use std::sync::{mpsc, Arc, Mutex}; use std::thread; diff --git a/sphinx-key/src/periph/sd.rs b/sphinx-key/src/periph/sd.rs index d08ce20..cd7d781 100644 --- a/sphinx-key/src/periph/sd.rs +++ b/sphinx-key/src/periph/sd.rs @@ -1,7 +1,7 @@ use bitflags::bitflags; -// use esp_idf_sys::c_types::c_char; +// use esp_idf_svc::sys::c_types::c_char; use core::ffi::c_char; -use esp_idf_sys::{ +use esp_idf_svc::sys::{ esp, esp_vfs_fat_sdmmc_mount_config_t, esp_vfs_fat_sdspi_mount, gpio_num_t, sdmmc_card_t, sdmmc_host_t, sdspi_device_config_t, spi_bus_config_t, spi_bus_initialize, spi_host_device_t, spi_host_device_t_SPI2_HOST, @@ -64,15 +64,15 @@ pub fn mount_sd_card() -> anyhow::Result<()> { let mut card: *mut sdmmc_card_t = ptr::null_mut(); let bus_cfg = spi_bus_config_t { - __bindgen_anon_1: esp_idf_sys::spi_bus_config_t__bindgen_ty_1 { + __bindgen_anon_1: esp_idf_svc::sys::spi_bus_config_t__bindgen_ty_1 { mosi_io_num: SPI_GPIO_MOSI, }, - __bindgen_anon_2: esp_idf_sys::spi_bus_config_t__bindgen_ty_2 { + __bindgen_anon_2: esp_idf_svc::sys::spi_bus_config_t__bindgen_ty_2 { miso_io_num: SPI_GPIO_MISO, }, sclk_io_num: SPI_GPIO_CLK, - __bindgen_anon_3: esp_idf_sys::spi_bus_config_t__bindgen_ty_3 { quadwp_io_num: -1 }, - __bindgen_anon_4: esp_idf_sys::spi_bus_config_t__bindgen_ty_4 { quadhd_io_num: -1 }, + __bindgen_anon_3: esp_idf_svc::sys::spi_bus_config_t__bindgen_ty_3 { quadwp_io_num: -1 }, + __bindgen_anon_4: esp_idf_svc::sys::spi_bus_config_t__bindgen_ty_4 { quadhd_io_num: -1 }, data4_io_num: -1, data5_io_num: -1, data6_io_num: -1, @@ -86,7 +86,7 @@ pub fn mount_sd_card() -> anyhow::Result<()> { spi_bus_initialize( SPI_HOST_SLOT as u32, &bus_cfg, - esp_idf_sys::spi_common_dma_t_SPI_DMA_CH_AUTO, + esp_idf_svc::sys::spi_common_dma_t_SPI_DMA_CH_AUTO, ) }) { if error.code() != 259 { @@ -109,17 +109,17 @@ pub fn mount_sd_card() -> anyhow::Result<()> { slot: SPI_HOST_SLOT as i32, max_freq_khz: SDMMCFreq::Default as i32, //SDMMC_FREQ_DEFAULT, io_voltage: 3.3f32, - init: Some(esp_idf_sys::sdspi_host_init), + init: Some(esp_idf_svc::sys::sdspi_host_init), set_bus_width: None, get_bus_width: None, set_bus_ddr_mode: None, - set_card_clk: Some(esp_idf_sys::sdspi_host_set_card_clk), - do_transaction: Some(esp_idf_sys::sdspi_host_do_transaction), - __bindgen_anon_1: esp_idf_sys::sdmmc_host_t__bindgen_ty_1 { - deinit_p: Some(esp_idf_sys::sdspi_host_remove_device), + set_card_clk: Some(esp_idf_svc::sys::sdspi_host_set_card_clk), + do_transaction: Some(esp_idf_svc::sys::sdspi_host_do_transaction), + __bindgen_anon_1: esp_idf_svc::sys::sdmmc_host_t__bindgen_ty_1 { + deinit_p: Some(esp_idf_svc::sys::sdspi_host_remove_device), }, - io_int_enable: Some(esp_idf_sys::sdspi_host_io_int_enable), - io_int_wait: Some(esp_idf_sys::sdspi_host_io_int_wait), + io_int_enable: Some(esp_idf_svc::sys::sdspi_host_io_int_enable), + io_int_wait: Some(esp_idf_svc::sys::sdspi_host_io_int_wait), command_timeout_ms: 0, }; diff --git a/sphinx-key/src/test.rs b/sphinx-key/src/test.rs index 2d3bfaf..2323a48 100644 --- a/sphinx-key/src/test.rs +++ b/sphinx-key/src/test.rs @@ -1,9 +1,9 @@ -use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported +use esp_idf_svc::sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported fn main() { // Temporary. Will disappear once ESP-IDF 4.4 is released, but for now it is necessary to call this function once, // or else some patches to the runtime implemented by esp-idf-sys might not link properly. - esp_idf_sys::link_patches(); + esp_idf_svc::sys::link_patches(); println!("Hello, world!"); } diff --git a/tester/src/config.rs b/tester/src/config.rs index 6eb6a01..2b42ff8 100644 --- a/tester/src/config.rs +++ b/tester/src/config.rs @@ -68,7 +68,9 @@ async fn main() -> anyhow::Result<()> { .header("Content-Type", "application/json") .send() .await?; + println!("Response: {:?}", res); let their_ecdh: EcdhBody = res.json().await?; + println!("Received pubkey from signer"); let their_pk = hex::decode(their_ecdh.pubkey)?; let their_pk_bytes: [u8; PUBLIC_KEY_LEN] = their_pk[..PUBLIC_KEY_LEN].try_into()?; @@ -99,16 +101,15 @@ async fn main() -> anyhow::Result<()> { }; let conf_encoded = urlencoding::encode(&conf_string).to_owned(); - + println!("Posting seed"); let res2 = client .post(format!("{}/{}={}", url, "config?config", conf_encoded)) .send() .await?; let conf_res: ConfigResponse = res2.json().await?; - + println!("Got response"); if conf_res.success { println!("SUCCESS!") } - Ok(()) }