From 2ee40d3a123593663cb639f7d8f1f7d7277b4484 Mon Sep 17 00:00:00 2001 From: Nicolas Rosset Date: Tue, 14 Nov 2023 10:46:12 +0000 Subject: [PATCH] Add wifiscanner from https://github.com/balena-os/wifi-connect/pull/492 --- Cargo.lock | 70 +++++++++++++++++++++++++++++++++++++++++++++++--- Cargo.toml | 1 + src/network.rs | 13 +++++++++- 3 files changed, 80 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e8765431..4ad4c582 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,15 @@ dependencies = [ "memchr 2.6.4", ] +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr 2.6.4", +] + [[package]] name = "ansi_term" version = "0.12.1" @@ -154,6 +163,12 @@ dependencies = [ "libdbus-sys", ] +[[package]] +name = "either" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" + [[package]] name = "env_logger" version = "0.4.3" @@ -161,7 +176,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b" dependencies = [ "log 0.3.9", - "regex", + "regex 0.2.11", ] [[package]] @@ -272,6 +287,15 @@ dependencies = [ "log 0.4.20", ] +[[package]] +name = "itertools" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.9" @@ -775,13 +799,36 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384" dependencies = [ - "aho-corasick", + "aho-corasick 0.6.10", "memchr 2.6.4", - "regex-syntax", + "regex-syntax 0.5.6", "thread_local", "utf8-ranges", ] +[[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick 1.1.2", + "memchr 2.6.4", + "regex-automata", + "regex-syntax 0.8.2", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick 1.1.2", + "memchr 2.6.4", + "regex-syntax 0.8.2", +] + [[package]] name = "regex-syntax" version = "0.5.6" @@ -791,6 +838,12 @@ dependencies = [ "ucd-util", ] +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + [[package]] name = "remove_dir_all" version = "0.5.3" @@ -1152,6 +1205,17 @@ dependencies = [ "serde_derive", "serde_json", "staticfile", + "wifiscanner", +] + +[[package]] +name = "wifiscanner" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d74e667d34abc74f1e5b509ae3d24641f56514ba2c5a64f9d733ae2061aef856" +dependencies = [ + "itertools", + "regex 1.10.2", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index af9a5232..2ba9f898 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ params = "0.8" log = "0.3" env_logger = "0.4" nix = "0.25" +wifiscanner = "0.5.1" [dependencies.error-chain] version = "0.12" diff --git a/src/network.rs b/src/network.rs index 6e747d5b..2c570122 100644 --- a/src/network.rs +++ b/src/network.rs @@ -205,7 +205,18 @@ impl NetworkCommandHandler { fn activate(&mut self) -> ExitResult { self.activated = true; - let networks = get_networks(&self.access_points); + // wifiscanner will use iw to scan which allows us to refresh access points _without_ + // needing to stop the captive portal. We'll discard its results rather than converting to + // Network since it has not implemented parsing security. + let _ = wifiscanner::scan(); + self.access_points = get_access_points(&self.device)?; + + let networks = { + let mut networks = get_networks(&self.access_points); + // Drop our portal SSID from the list of returned networks + networks.retain(|network| network.ssid != self.config.ssid); + networks + }; self.server_tx .send(NetworkCommandResponse::Networks(networks))