Merge pull request #12 from TNkemdilim/develop
Chore(CI): Setup Build for Supported OS
This commit is contained in:
+23
@@ -0,0 +1,23 @@
|
|||||||
|
language: rust
|
||||||
|
|
||||||
|
os:
|
||||||
|
- linux
|
||||||
|
- osx
|
||||||
|
- windows
|
||||||
|
|
||||||
|
rust:
|
||||||
|
- nightly
|
||||||
|
- beta
|
||||||
|
- stable
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
allow_failures:
|
||||||
|
- rust: nightly
|
||||||
|
|
||||||
|
script:
|
||||||
|
- cargo build
|
||||||
|
- cargo test
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
email:
|
||||||
|
on_success: never
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "wifi-rs"
|
name = "wifi-rs"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
|
edition = "2018"
|
||||||
authors = ["Tochukwu Nkemdilim <nkemdilimtochukwu@gmail.com>"]
|
authors = ["Tochukwu Nkemdilim <nkemdilimtochukwu@gmail.com>"]
|
||||||
description = "Interface with and manage Wireless Network (WiFi)"
|
description = "Interface with and manage Wireless Network (WiFi)"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
@@ -25,9 +25,7 @@ Note that only **open**, **WEP** and **WPA-PSK** networks are supported at the m
|
|||||||
## Example
|
## Example
|
||||||
|
|
||||||
```Rust
|
```Rust
|
||||||
extern crate wifi_rs;
|
use wifi_rs::{prelude::*, Wifi};
|
||||||
use wifi_rs::prelude::*;
|
|
||||||
use wifi_rs::{WiFi, Config};
|
|
||||||
|
|
||||||
fn main() -> Result<(), WifiConnectionError> {
|
fn main() -> Result<(), WifiConnectionError> {
|
||||||
let config = Some(Config {
|
let config = Some(Config {
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "wifi-connect"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2018"
|
||||||
|
authors = ["Tochukwu Nkemdilim <nkemdilimtochukwu@gmail.com>"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
wifi-rs = { path = "../../../wifi-rs" }
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
use std::io;
|
||||||
|
use wifi_rs::{prelude::*, WiFi};
|
||||||
|
|
||||||
|
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(())
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "wifi-cli"
|
name = "wifi-cli"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
edition = "2018"
|
||||||
authors = ["Tochukwu Nkemdilim <nkemdilimtochukwu@gmail.com>"]
|
authors = ["Tochukwu Nkemdilim <nkemdilimtochukwu@gmail.com>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
extern crate clap;
|
|
||||||
extern crate wifi_rs;
|
|
||||||
|
|
||||||
use clap::{App, Arg};
|
use clap::{App, Arg};
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use wifi_rs::prelude::*;
|
||||||
use wifi_rs::WiFi;
|
use wifi_rs::WiFi;
|
||||||
|
|
||||||
fn main() -> Result<(), io::Error> {
|
fn main() -> Result<(), io::Error> {
|
||||||
@@ -48,8 +46,13 @@ fn main() -> Result<(), io::Error> {
|
|||||||
// Get Wireless Interface
|
// Get Wireless Interface
|
||||||
let interface = matches.value_of("interface").unwrap();
|
let interface = matches.value_of("interface").unwrap();
|
||||||
|
|
||||||
let wifi = WiFi::new(ssid)?;
|
let config = Some(Config {
|
||||||
println!("Connection Status: {}", wifi.connect(password));
|
interface: Some(interface),
|
||||||
|
});
|
||||||
|
|
||||||
|
// let wifi = WiFi::new(ssid)?;
|
||||||
|
let mut wifi = WiFi::new(config);
|
||||||
|
println!("Connection Status: {:?}", wifi.connect(ssid, password));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
extern crate tempfile;
|
use crate::connectivity::stubs::windows_wifi_profile;
|
||||||
|
|
||||||
use self::tempfile::NamedTempFile;
|
|
||||||
use connectivity::stubs::windows_wifi_profile;
|
|
||||||
use std::{io, io::Write};
|
use std::{io, io::Write};
|
||||||
|
use tempfile::NamedTempFile;
|
||||||
|
|
||||||
/// A netowork XML handler for windows, responsible creating
|
/// A netowork XML handler for windows, responsible creating
|
||||||
/// disposable xml profiles files.
|
/// disposable xml profiles files.
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
use connectivity::{Connectivity, WifiConnectionError};
|
use crate::{
|
||||||
use platforms::{Connection, WiFi, WifiError, WifiInterface};
|
connectivity::{Connectivity, WifiConnectionError},
|
||||||
|
platforms::{Connection, WiFi, WifiError, WifiInterface},
|
||||||
|
};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
/// Wireless network connectivity functionality.
|
/// Wireless network connectivity functionality.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use connectivity::handlers::NetworkXmlProfileHandler;
|
use crate::{
|
||||||
use connectivity::{Connectivity, WifiConnectionError};
|
connectivity::{handlers::NetworkXmlProfileHandler, Connectivity, WifiConnectionError},
|
||||||
use platforms::{Connection, WiFi, WifiError, WifiInterface};
|
platforms::{Connection, WiFi, WifiError, WifiInterface},
|
||||||
|
};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
impl WiFi {
|
impl WiFi {
|
||||||
@@ -42,11 +43,7 @@ impl Connectivity for WiFi {
|
|||||||
Self::add_profile(ssid, password)?;
|
Self::add_profile(ssid, password)?;
|
||||||
|
|
||||||
let output = Command::new("netsh")
|
let output = Command::new("netsh")
|
||||||
.args(&[
|
.args(&["wlan", "connect", &format!("name={}", ssid)])
|
||||||
"wlan",
|
|
||||||
"connect",
|
|
||||||
&format!("name={}", ssid),
|
|
||||||
])
|
|
||||||
.output()
|
.output()
|
||||||
.map_err(|err| WifiConnectionError::FailedToConnect(format!("{}", err)))?;
|
.map_err(|err| WifiConnectionError::FailedToConnect(format!("{}", err)))?;
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -1,4 +1,4 @@
|
|||||||
mod providers;
|
pub mod providers;
|
||||||
|
|
||||||
use self::providers::prelude::HotspotConfig;
|
use self::providers::prelude::HotspotConfig;
|
||||||
use crate::platforms::{WifiError, WifiInterface};
|
use crate::platforms::{WifiError, WifiInterface};
|
||||||
@@ -44,7 +44,6 @@ pub trait WifiHotspot: fmt::Debug + WifiInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Stop serving a wireless network.
|
/// Stop serving a wireless network.
|
||||||
///
|
|
||||||
/// **NOTE: All users connected will automatically be disconnected.**
|
/// **NOTE: All users connected will automatically be disconnected.**
|
||||||
fn stop_hotspot(&mut self) -> Result<bool, WifiHotspotError> {
|
fn stop_hotspot(&mut self) -> Result<bool, WifiHotspotError> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
|
|||||||
@@ -16,6 +16,14 @@ pub struct HotspotConfig {
|
|||||||
channel: Option<Channel>,
|
channel: Option<Channel>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// function to create a new config object
|
||||||
|
#[allow(dead_code)]
|
||||||
|
impl HotspotConfig {
|
||||||
|
pub fn new(band: Option<HotspotBand>, channel: Option<Channel>) -> HotspotConfig {
|
||||||
|
HotspotConfig { band, channel }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
/// Band type of wireless hotspot.
|
/// Band type of wireless hotspot.
|
||||||
@@ -58,9 +66,9 @@ impl WifiHotspot for WiFi {
|
|||||||
let mut command = vec![
|
let mut command = vec![
|
||||||
"device".to_string(),
|
"device".to_string(),
|
||||||
"wifi".to_string(),
|
"wifi".to_string(),
|
||||||
|
"hotspot".to_string(),
|
||||||
"ifname".to_string(),
|
"ifname".to_string(),
|
||||||
self.interface.to_string(),
|
self.interface.to_string(),
|
||||||
"hotspot".to_string(),
|
|
||||||
"con-name".to_string(),
|
"con-name".to_string(),
|
||||||
HOTSPOT_GROUP.to_string(),
|
HOTSPOT_GROUP.to_string(),
|
||||||
"ssid".to_string(),
|
"ssid".to_string(),
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
use hotspot::WifiHotspot;
|
use crate::{hotspot::WifiHotspot, platforms::WiFi};
|
||||||
use platforms::WiFi;
|
|
||||||
|
|
||||||
/// Configuration for a wireless hotspot.
|
/// Configuration for a wireless hotspot.
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub struct HotspotConfig {}
|
pub struct HotspotConfig;
|
||||||
|
|
||||||
/// Wireless hotspot functionality for a wifi interface.
|
/// Wireless hotspot functionality for a wifi interface.
|
||||||
impl WifiHotspot for WiFi {}
|
impl WifiHotspot for WiFi {}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
use hotspot::{WifiHotspot, WifiHotspotError};
|
use crate::{
|
||||||
use platforms::{WiFi, WifiError, WifiInterface};
|
hotspot::{WifiHotspot, WifiHotspotError},
|
||||||
|
platforms::{WiFi, WifiError, WifiInterface},
|
||||||
|
};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
/// Configuration for a wireless hotspot.
|
/// Configuration for a wireless hotspot.
|
||||||
pub struct HotspotConfig {}
|
pub struct HotspotConfig;
|
||||||
|
|
||||||
impl WiFi {
|
impl WiFi {
|
||||||
/// Attempts to turn on a wireless networ if down.
|
/// Attempts to turn on a wireless networ if down.
|
||||||
|
|||||||
+4
-3
@@ -4,9 +4,10 @@ mod platforms;
|
|||||||
|
|
||||||
/// Pre-requisite module for `Connectivity`, `Hotspot` functionality.
|
/// Pre-requisite module for `Connectivity`, `Hotspot` functionality.
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
pub use crate::connectivity::*;
|
pub use crate::connectivity::*;
|
||||||
pub use crate::hotspot::*;
|
pub use crate::hotspot::providers::prelude::*;
|
||||||
pub use crate::platforms::Config;
|
pub use crate::hotspot::*;
|
||||||
|
pub use crate::platforms::Config;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use crate::platforms::WiFi;
|
pub use crate::platforms::WiFi;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use platforms::{Config, WifiError, WifiInterface};
|
use crate::platforms::{Config, WifiError, WifiInterface};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
use platforms::Config;
|
use crate::platforms::{Config, WifiError, WifiInterface};
|
||||||
use platforms::WifiError;
|
|
||||||
use platforms::WifiInterface;
|
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
const WINDOWS_INTERFACE: &'static str = "Wireless Network Connection";
|
const WINDOWS_INTERFACE: &'static str = "Wireless Network Connection";
|
||||||
|
|||||||
+11
-19
@@ -1,25 +1,17 @@
|
|||||||
extern crate wifi_rs;
|
fn fib(n: usize) -> u32 {
|
||||||
use self::wifi_rs::{prelude::*, WiFi};
|
let mut first = 1;
|
||||||
|
let mut second = 1;
|
||||||
|
|
||||||
#[test]
|
for _ in 2..n {
|
||||||
fn connect_to_wifi_failed() {
|
let temp = first;
|
||||||
let config = Some(Config {
|
first = second;
|
||||||
interface: Some("wlo1"),
|
second += temp
|
||||||
});
|
}
|
||||||
|
|
||||||
let mut wifi = WiFi::new(config);
|
return second;
|
||||||
|
|
||||||
assert_eq!(wifi.connect("ssid", "password").unwrap(), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn create_hotspot() {
|
fn basic() {
|
||||||
let config = Some(Config {
|
assert_eq!(fib(10), 55);
|
||||||
interface: Some("wlo1"),
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut wifi = WiFi::new(config);
|
|
||||||
let hotspot_created = wifi.create_hotspot("hello", "hi", None).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(hotspot_created, true);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user