Skip to content

Commit

Permalink
wpa-supplicant: add crate
Browse files Browse the repository at this point in the history
  • Loading branch information
TheButlah committed May 8, 2024
1 parent db62dd2 commit 9d93092
Show file tree
Hide file tree
Showing 11 changed files with 932 additions and 9 deletions.
28 changes: 28 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ members = [
"seek-camera/sys",
"seek-camera/wrapper",
"verity-tree-calc",
"wpa-supplicant",
]

[workspace.package]
Expand All @@ -36,19 +37,21 @@ rust-version = "1.77.0" # See rust-version.toml
[workspace.dependencies]
clap = { version = "4.5", features = ["derive"] }
color-eyre = "0.6.2"
eyre = "0.6.12"
libc = "0.2.153"
thiserror = "1.0.60"
nix = { version = "0.28", default-features = false, features = [] }
console-subscriber = "0.2"
data-encoding = "2.3"
derive_more = { version = "0.99", default-features = false, features = ["display", "from"] }
eyre = "0.6.12"
futures = "0.3.30"
libc = "0.2.153"
nix = { version = "0.28", default-features = false, features = [] }
reqwest = { version = "0.11", default-features = false, features = ["rustls-tls", "stream"] }
ring = "0.16"
serde = { version = "1.0.197", features = ["derive"] }
thiserror = "1.0.60"
tokio = { version = "1", features = ["full"] }
tokio-test = "0.4.4"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
alsa-sys = "0.3.1"
reqwest = { version = "0.11", default-features = false, features = ["rustls-tls", "stream"] }
zbus = { version = "4", default-features = false, features = ["tokio"] }

[workspace.dependencies.orb-messages]
Expand Down
2 changes: 1 addition & 1 deletion orb-attest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ event-listener = "*"
eyre.workspace = true
futures.workspace = true
lazy_static = "1.4"
ring = "0.16"
ring.workspace = true
secrecy = { version = "0.8.0", features = ["serde"] }
serde.workspace = true
serde_json = "~1.0"
Expand Down
2 changes: 1 addition & 1 deletion orb-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ derive_more.workspace = true
eyre.workspace = true
futures.workspace = true
orb-messages.workspace = true
orb-uart.path = "uart"
orb-sound.path = "sound"
orb-uart.path = "uart"
pid.path = "pid"
prost = "0.12.3"
serde.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion orb-ui/sound/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repository.workspace = true
rust-version.workspace = true

[dependencies]
alsa-sys.workspace = true
alsa-sys = "0.3.1"
futures.workspace = true
libc.workspace = true
riff = "2"
Expand Down
23 changes: 23 additions & 0 deletions wpa-supplicant/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "orb-wpa-supplicant"
version = "0.0.0"
authors = ["Galileo Daras <[email protected]>", "Ryan Butler <[email protected]>"]
publish = false

edition.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true

[dependencies]
zbus.workspace = true
tokio.workspace = true
data-encoding.workspace = true
eyre.workspace = true
futures.workspace = true
tracing.workspace = true
ring.workspace = true
serde.workspace = true

[dev-dependencies]
tokio-test.workspace = true
11 changes: 11 additions & 0 deletions wpa-supplicant/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# orb-wpa-supplicant

Provides a replacement for wpa_cli, by using wpa supplicant's DBUS interface.

This crate is currently unused, because talking to wpa_supplicant requires root.
This is too risky, so once we configure polkit, we will begin using this crate.

## Platform support notes

This binary builds on all targets but assumes the presence of the
wpa-supplicant daemon and the wlan0 network interface, so it is unlikely to run outside of the orb.
17 changes: 17 additions & 0 deletions wpa-supplicant/examples/info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const IFACE: &str = "wlan0";

#[tokio::main]
async fn main() {
let status = orb_wpa_supplicant::iface_status(IFACE)
.await
.expect("failed to get status");
println!("status: {status:?}");
let ssid = orb_wpa_supplicant::current_network_ssid(IFACE)
.await
.expect("failed to get ssid");
println!("ssid: {ssid:?}");
let rssi = orb_wpa_supplicant::current_network_rssi(IFACE)
.await
.expect("failed to get rssi");
println!("rssi: {rssi:?}");
}
56 changes: 56 additions & 0 deletions wpa-supplicant/src/credentials.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use std::{fmt, ops::Deref};

/// WiFi network credentials.
#[derive(Debug)]
pub struct Credentials {
/// Network SSID.
pub ssid: String,
/// Password.
pub password: Option<Password>,
/// Whether the network SSID is hidden.
pub hidden: bool,
pub auth_type: AuthType,
}

/// Authentication type.
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
pub enum AuthType {
/// WEP encryption.
Wep,
/// WPA encryption.
Wpa,
/// Pure WPA3-SAE.
Sae,
/// Unencrypted.
Nopass,
}

impl Default for AuthType {
fn default() -> Self {
Self::Nopass
}
}

/// Newtype on `String` to prevent printing in plaintext.
#[derive(Clone, Hash, Eq, PartialEq)]
pub struct Password(pub String);

impl fmt::Debug for Password {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("***")
}
}

impl Deref for Password {
type Target = str;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl PartialEq<&str> for Password {
fn eq(&self, other: &&str) -> bool {
self.0 == *other
}
}
Loading

0 comments on commit 9d93092

Please sign in to comment.