diff --git a/examples/hotspot/Cargo.toml b/examples/hotspot/Cargo.toml new file mode 100644 index 0000000..06fb137 --- /dev/null +++ b/examples/hotspot/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "wifi-cli" +version = "0.1.0" +authors = ["Tochukwu Nkemdilim "] + +[dependencies] +wifi-rs = { path = "../../../wifi-rs" } \ No newline at end of file diff --git a/examples/hotspot/src/main.rs b/examples/hotspot/src/main.rs new file mode 100644 index 0000000..52ec701 --- /dev/null +++ b/examples/hotspot/src/main.rs @@ -0,0 +1,24 @@ +extern crate wifi_rs; + +use std::io; +use wifi_rs::WiFi; +use wifi_rs::prelude::*; + +fn main() -> Result<(), io::Error> { + let config = Some(Config { + interface: Some("wlo1"), + }); + + let mut wifi = WiFi::new(config); + let config = HotspotConfig::new(Some(HotspotBand::Bg), Some(Channel::One)); + + wifi.create_hotspot( + "test-hotspot", + "password", + Some( + &config + ) + ); + + Ok(()) +} diff --git a/examples/wifi-cli/src/main.rs b/examples/wifi-cli/src/main.rs index 42cca58..774a6cc 100644 --- a/examples/wifi-cli/src/main.rs +++ b/examples/wifi-cli/src/main.rs @@ -4,6 +4,7 @@ extern crate wifi_rs; use clap::{App, Arg}; use std::io; use wifi_rs::WiFi; +use wifi_rs::prelude::*; fn main() -> Result<(), io::Error> { let matches = App::new("Wi-Fi") @@ -48,8 +49,13 @@ fn main() -> Result<(), io::Error> { // Get Wireless Interface let interface = matches.value_of("interface").unwrap(); - let wifi = WiFi::new(ssid)?; - println!("Connection Status: {}", wifi.connect(password)); + let config = Some(Config { + interface: Some(interface), + }); + + // let wifi = WiFi::new(ssid)?; + let mut wifi = WiFi::new(config); + println!("Connection Status: {:?}", wifi.connect(ssid, password)); Ok(()) -} +} \ No newline at end of file diff --git a/src/hotspot/mod.rs b/src/hotspot/mod.rs index 815d345..f6a67e5 100644 --- a/src/hotspot/mod.rs +++ b/src/hotspot/mod.rs @@ -1,4 +1,4 @@ -mod providers; +pub mod providers; use self::providers::prelude::HotspotConfig; use crate::platforms::{WifiError, WifiInterface}; @@ -44,7 +44,6 @@ pub trait WifiHotspot: fmt::Debug + WifiInterface { } /// Stop serving a wireless network. - /// /// **NOTE: All users connected will automatically be disconnected.** fn stop_hotspot(&mut self) -> Result { unimplemented!(); diff --git a/src/hotspot/providers/linux.rs b/src/hotspot/providers/linux.rs index 3b4d97d..71fb61a 100644 --- a/src/hotspot/providers/linux.rs +++ b/src/hotspot/providers/linux.rs @@ -16,6 +16,17 @@ pub struct HotspotConfig { channel: Option, } +/// function to create a new config object +#[allow(dead_code)] +impl HotspotConfig { + pub fn new(band: Option, channel: Option) -> HotspotConfig { + HotspotConfig { + band, + channel + } + } +} + #[allow(dead_code)] #[derive(Debug)] /// Band type of wireless hotspot. @@ -58,9 +69,9 @@ impl WifiHotspot for WiFi { let mut command = vec![ "device".to_string(), "wifi".to_string(), + "hotspot".to_string(), "ifname".to_string(), self.interface.to_string(), - "hotspot".to_string(), "con-name".to_string(), HOTSPOT_GROUP.to_string(), "ssid".to_string(), diff --git a/src/lib.rs b/src/lib.rs index ec119f0..84f959f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,6 +6,7 @@ mod platforms; pub mod prelude { pub use crate::connectivity::*; pub use crate::hotspot::*; + pub use crate::hotspot::providers::prelude::*; pub use crate::platforms::Config; }