-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhotspot.rs
40 lines (35 loc) · 1.04 KB
/
hotspot.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use pnet::datalink::{self, NetworkInterface};
use wifi_rs::{prelude::*, WiFi};
pub struct Hotspot {
wifi: WiFi,
interface: String,
}
impl Default for Hotspot {
fn default() -> Self {
let interface = datalink::interfaces()
.into_iter()
.filter(|iface: &NetworkInterface| iface.name.starts_with("w"))
.last()
.unwrap();
let config = Some(Config {
interface: Some(&interface.name),
});
Hotspot {
wifi: WiFi::new(config),
interface: interface.name,
}
}
}
impl Hotspot {
pub fn start(&mut self) {
let config = HotspotConfig::new(Some(HotspotBand::Bg), Some(Channel::Three));
self.wifi
.create_hotspot("ornithology-pi", "ornithology", Some(&config))
.unwrap();
println!("started hotspot on interface {}", self.interface)
}
pub fn stop(&mut self) {
self.wifi.stop_hotspot().unwrap();
println!("stopped hotspot on interface {}", self.interface)
}
}