Skip to main content

wifi_ctrl/
lib.rs

1//! Tokio-based runtimes for communicating with hostapd and wpa-supplicant.
2//!
3//! Use [`sta`] to run a WiFi station (network client) against `wpa_supplicant`,
4//! and [`ap`] to run an access point against `hostapd`.
5//!
6//! # Quick Start
7//!
8//! ```no_run
9//! use wifi_ctrl::sta;
10//!
11//! #[tokio::main]
12//! async fn main() -> wifi_ctrl::Result {
13//!     let mut setup = sta::WifiSetup::new();
14//!     setup.set_socket_path("/var/run/wpa_supplicant/wlan0");
15//!     let requester = setup.get_request_client();
16//!     let mut runtime = setup.complete();
17//!     tokio::spawn(async move { runtime.run().await });
18//!
19//!     let scan = requester.get_scan().await?;
20//!     for network in scan.iter() {
21//!         println!("{} {}", network.signal, network.name);
22//!     }
23//!     requester.shutdown().await
24//! }
25//! ```
26//!
27//! See the examples [on Github](https://github.com/novalabsxyz/wifi-ctrl) for
28//! complete station and access-point programs.
29
30#![doc(
31    html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
32    html_favicon_url = "https://www.rust-lang.org/favicon.ico",
33    html_root_url = "https://docs.rs/wifi-ctrl/"
34)]
35#![doc(test(attr(allow(unused_variables), deny(warnings))))]
36
37use std::str::FromStr;
38use std::sync::Arc;
39use tokio::sync::{broadcast, mpsc, oneshot};
40
41/// WiFi Access Point runtime and types
42pub mod ap;
43/// Crate-wide error types
44pub mod error;
45/// WiFi Station (network client) runtime and types
46pub mod sta;
47
48pub(crate) mod config;
49pub(crate) mod socket_handle;
50
51use socket_handle::SocketHandle;
52pub type Result<T = ()> = std::result::Result<T, error::ClientError>;
53pub type SocketResult<T = ()> = std::result::Result<T, error::SocketError>;
54pub type ParseResult<T = ()> = std::result::Result<T, error::ParseError>;
55
56use log::{debug, info, warn};
57
58pub(crate) trait ShutdownSignal {
59    fn is_shutdown(&self) -> bool;
60}