Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DNS server configuration + AP #87

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 41 additions & 12 deletions src/asynch/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
Ok(mac.to_be_bytes()[2..].try_into().unwrap())
}

async fn get_wifi_status(&self) -> Result<WifiStatusVal, Error> {
GustavToft marked this conversation as resolved.
Show resolved Hide resolved
pub async fn get_wifi_status(&self) -> Result<WifiStatusVal, Error> {
match (&self.at_client)
.send_retry(&GetWifiStatus {
status_id: StatusId::Status,
Expand Down Expand Up @@ -333,32 +333,56 @@
ap_config_param: AccessPointConfig::IPv4Mode(IPv4Mode::Static),
})
.await?;
}

// Network IP address
if let Some(ip) = options.ip {
(&self.at_client)
.send_retry(&SetWifiAPConfig {
ap_config_id: AccessPointId::Id0,
ap_config_param: AccessPointConfig::IPv4Address(ip),
ap_config_param: AccessPointConfig::IPv4Address(
options.ip.unwrap_or(Ipv4Addr::new(192, 168, 2, 1)),
),
})
.await?;
}
// Network Subnet mask
if let Some(subnet) = options.subnet {

(&self.at_client)
.send_retry(&SetWifiAPConfig {
ap_config_id: AccessPointId::Id0,
ap_config_param: AccessPointConfig::SubnetMask(subnet),
ap_config_param: AccessPointConfig::SubnetMask(
options.subnet.unwrap_or(Ipv4Addr::new(255, 255, 255, 0)),
),
})
.await?;

(&self.at_client)
.send_retry(&SetWifiAPConfig {
ap_config_id: AccessPointId::Id0,
ap_config_param: AccessPointConfig::DefaultGateway(
options.gateway.unwrap_or(Ipv4Addr::new(192, 168, 2, 1)),
),
})
.await?;
}
// Network Default gateway
if let Some(gateway) = options.gateway {

// Network Primary + Secondary DNS
let primary = match options.dns.as_slice() {
&[primary] => Some(primary),
&[primary, secondary] => {
(&self.at_client)
.send_retry(&SetWifiAPConfig {
ap_config_id: AccessPointId::Id0,
ap_config_param: AccessPointConfig::SecondaryDNS(secondary),
})
.await?;

Some(primary)
}
_ => None,
};

Check warning on line 379 in src/asynch/control.rs

View workflow job for this annotation

GitHub Actions / clippy

you don't need to add `&` to all patterns

warning: you don't need to add `&` to all patterns --> src/asynch/control.rs:366:23 | 366 | let primary = match options.dns.as_slice() { | _______________________^ 367 | | &[primary] => Some(primary), 368 | | &[primary, secondary] => { 369 | | (&self.at_client) ... | 378 | | _ => None, 379 | | }; | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_ref_pats = note: `#[warn(clippy::match_ref_pats)]` on by default help: instead of prefixing all patterns with `&`, you can dereference the expression | 366 ~ let primary = match *options.dns.as_slice() { 367 ~ [primary] => Some(primary), 368 ~ [primary, secondary] => { |

if let Some(primary) = primary {
(&self.at_client)
.send_retry(&SetWifiAPConfig {
ap_config_id: AccessPointId::Id0,
ap_config_param: AccessPointConfig::DefaultGateway(gateway),
ap_config_param: AccessPointConfig::PrimaryDNS(primary),
})
.await?;
}
Expand Down Expand Up @@ -445,11 +469,16 @@
})
.await?;

self.state_ch.set_should_connect(true);

Ok(())
}

/// Closes access point.
pub async fn close_ap(&self) -> Result<(), Error> {
self.state_ch.wait_for_initialized().await;
self.state_ch.set_should_connect(false);

(&self.at_client)
.send_retry(&WifiAPAction {
ap_config_id: AccessPointId::Id0,
Expand Down
89 changes: 74 additions & 15 deletions src/asynch/network.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
use core::str::FromStr as _;

use atat::{asynch::AtatClient, UrcChannel, UrcSubscription};
use core::str::FromStr as _;
use embassy_time::{with_timeout, Duration, Timer};
use embedded_hal::digital::OutputPin as _;
use no_std_net::{Ipv4Addr, Ipv6Addr};

use crate::{
command::{
network::{
responses::NetworkStatusResponse,
types::{InterfaceType, NetworkStatus, NetworkStatusParameter},
responses::{APStatusResponse, NetworkStatusResponse},
types::{APStatusParameter, InterfaceType, NetworkStatus, NetworkStatusParameter},
urc::{NetworkDown, NetworkUp},
GetNetworkStatus,
GetAPStatus, GetNetworkStatus,
},
system::{RebootDCE, StoreCurrentConfig},
wifi::{
types::DisconnectReason,
types::{AccessPointStatus, DisconnectReason},
urc::{WifiLinkConnected, WifiLinkDisconnected},
},
Urc,
Expand Down Expand Up @@ -56,22 +55,22 @@

pub async fn run(&mut self) -> Result<(), Error> {
loop {
match embassy_futures::select::select(
self.urc_subscription.next_message_pure(),
self.ch.wait_for_wifi_state_change(),
)
.await
{
embassy_futures::select::Either::First(event) => {
#[cfg(feature = "edm")]
let Some(event) = event.extract_urc() else {
continue;
};

self.handle_urc(event).await?;
}
_ => {}
}

Check warning on line 73 in src/asynch/network.rs

View workflow job for this annotation

GitHub Actions / clippy

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`

warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/asynch/network.rs:58:13 | 58 | / match embassy_futures::select::select( 59 | | self.urc_subscription.next_message_pure(), 60 | | self.ch.wait_for_wifi_state_change(), 61 | | ) ... | 72 | | _ => {} 73 | | } | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match = note: `#[warn(clippy::single_match)]` on by default help: try | 58 ~ if let embassy_futures::select::Either::First(event) = embassy_futures::select::select( 59 + self.urc_subscription.next_message_pure(), 60 + self.ch.wait_for_wifi_state_change(), 61 + ) 62 + .await { 63 + #[cfg(feature = "edm")] 64 + let Some(event) = event.extract_urc() else { 65 + continue; 66 + }; 67 + 68 + self.handle_urc(event).await?; 69 + } |

if self.ch.wifi_state(None) == WiFiState::Inactive && self.ch.connection_down(None) {
return Ok(());
Expand All @@ -88,12 +87,16 @@
connection_id: _,
bssid,
channel,
}) => self.ch.update_connection_with(|con| {
con.wifi_state = WiFiState::Connected;
con.network
.replace(WifiNetwork::new_station(bssid, channel));
}),
}) => {
info!("wifi link connected");
self.ch.update_connection_with(|con| {
con.wifi_state = WiFiState::Connected;
con.network
.replace(WifiNetwork::new_station(bssid, channel));
})
}
Urc::WifiLinkDisconnected(WifiLinkDisconnected { reason, .. }) => {
info!("Wifi link disconnected");
self.ch.update_connection_with(|con| {
con.wifi_state = match reason {
DisconnectReason::NetworkDisabled => {
Expand All @@ -109,19 +112,33 @@
}
})
}
Urc::WifiAPUp(_) => warn!("Not yet implemented [WifiAPUp]"),
Urc::WifiAPDown(_) => warn!("Not yet implemented [WifiAPDown]"),
Urc::WifiAPUp(_) => self.ch.update_connection_with(|con| {
con.wifi_state = WiFiState::Connected;
con.network.replace(WifiNetwork::new_ap());
}),
Urc::WifiAPDown(_) => self.ch.update_connection_with(|con| {
con.network.take();
con.wifi_state = WiFiState::Inactive;
}),
Urc::WifiAPStationConnected(_) => warn!("Not yet implemented [WifiAPStationConnected]"),
Urc::WifiAPStationDisconnected(_) => {
warn!("Not yet implemented [WifiAPStationDisconnected]")
}
Urc::EthernetLinkUp(_) => warn!("Not yet implemented [EthernetLinkUp]"),
Urc::EthernetLinkDown(_) => warn!("Not yet implemented [EthernetLinkDown]"),
Urc::NetworkUp(NetworkUp { interface_id }) => {
self.network_status_callback(interface_id).await?;
if interface_id > 10 {
self.ap_status_callback().await?;
} else {
self.network_status_callback(interface_id).await?;
}
}
Urc::NetworkDown(NetworkDown { interface_id }) => {
self.network_status_callback(interface_id).await?;
if interface_id > 10 {
self.ap_status_callback().await?;
} else {
self.network_status_callback(interface_id).await?;
}
}
Urc::NetworkError(_) => warn!("Not yet implemented [NetworkError]"),
_ => {}
Expand All @@ -137,6 +154,7 @@
// credentials have been restored from persistent memory. This although
// the wifi station has been started. So we assume that this type is
// also ok.
info!("Entered network_status_callback");
let NetworkStatusResponse {
status:
NetworkStatus::InterfaceType(InterfaceType::WifiStation | InterfaceType::Unknown),
Expand Down Expand Up @@ -165,12 +183,17 @@
else {
return Err(Error::Network);
};
info!(
"Network status callback ipv4: {:?}",
core::str::from_utf8(&ipv4).ok()
);

let ipv4_up = core::str::from_utf8(ipv4.as_slice())
.ok()
.and_then(|s| Ipv4Addr::from_str(s).ok())
.map(|ip| !ip.is_unspecified())
.unwrap_or_default();
info!("Network status callback ipv4: {:?}", ipv4_up);

#[cfg(feature = "ipv6")]
let ipv6_up = {
Expand Down Expand Up @@ -208,13 +231,19 @@
else {
return Err(Error::Network);
};
info!(
"Network status callback ipv6: {:?}",
core::str::from_utf8(&ipv6_link_local).ok()
);

let ipv6_link_local_up = core::str::from_utf8(ipv6_link_local.as_slice())
.ok()
.and_then(|s| Ipv6Addr::from_str(s).ok())
.map(|ip| !ip.is_unspecified())
.unwrap_or_default();

info!("Network status callback ipv6: {:?}", ipv6_link_local_up);

// Use `ipv4_addr` & `ipv6_addr` to determine link state
self.ch.update_connection_with(|con| {
con.ipv6_link_local_up = ipv6_link_local_up;
Expand All @@ -229,6 +258,36 @@
Ok(())
}

async fn ap_status_callback(&mut self) -> Result<(), Error> {
let APStatusResponse {
status_val: AccessPointStatus::Status(ap_status),
..
} = self
.at_client
.send_retry(&GetAPStatus {
status_id: APStatusParameter::Status,
})
.await?
else {
return Err(Error::Network);
};
info!("AP status callback Status: {:?}", ap_status);

let ap_status = ap_status.into();

self.ch.update_connection_with(|con| {
con.ipv6_link_local_up = ap_status;
con.ipv4_up = ap_status;

#[cfg(feature = "ipv6")]
{
con.ipv6_up = ap_status;
}
});

Ok(())
}

async fn wait_startup(&mut self, timeout: Duration) -> Result<(), Error> {
let fut = async {
loop {
Expand Down
10 changes: 10 additions & 0 deletions src/command/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ use types::*;

use super::NoResponse;

/// 7.10 Wi-Fi Acess point status +UWAPSTAT
///
/// Read status of Wi-Fi interface id.
#[derive(Clone, AtatCmd)]
#[at_cmd("+UWAPSTAT", APStatusResponse, attempts = 3, timeout_ms = 1000)]
pub struct GetAPStatus {
#[at_arg(position = 0)]
pub status_id: APStatusParameter,
}

/// 10.1 Network host name +UNHN
///
/// Sets a new host name.
Expand Down
8 changes: 8 additions & 0 deletions src/command/network/responses.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
//! Responses for Network Commands
use crate::command::wifi::types::AccessPointStatus;

use super::types::*;
use atat::atat_derive::AtatResp;

/// 7.10 WiFi AP status +UWAPSTAT
#[derive(Clone, AtatResp)]
pub struct APStatusResponse {
pub status_val: AccessPointStatus,
}

/// 10.2 Network status +UNSTAT
#[derive(Clone, AtatResp)]
pub struct NetworkStatusResponse {
Expand Down
33 changes: 33 additions & 0 deletions src/command/network/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,39 @@

use crate::command::OnOff;

#[derive(Clone, PartialEq, AtatEnum)]
pub enum APStatus {
// 0: The <status_val> is the currently used SSID.
#[at_arg(value = 0)]
SSID(String<64>),
// 1: The <status_val> is the currently used BSSID.
#[at_arg(value = 1)]
BSSID(#[at_arg(len = 20)] Bytes<20>),
// 2: The <status_val> is the currently used channel.
#[at_arg(value = 2)]
Channel(u8),
// 3: The <status_val> is the current status of the access point.
// - 0: disabled
// - 1: enabled
#[at_arg(value = 3)]
Status(OnOff),
}

#[derive(Clone, PartialEq, AtatEnum)]
#[repr(u8)]
pub enum APStatusParameter {
// 0: The <status_val> is the currently used SSID.
SSID = 0,
// 1: The <status_val> is the currently used BSSID.
BSSID = 1,
// 2: The <status_val> is the currently used channel.
Channel = 2,
// 3: The <status_val> is the current status of the access point.
// • 0: disabled
// • 1: enabled
Status = 3,
}

#[derive(Clone, PartialEq, AtatEnum)]
pub enum NetworkStatus {
/// 0: The <status_val> is the interface hardware address (displayed only if applicable).
Expand All @@ -25,7 +58,7 @@
/// - 4: PPP
/// - 5: Bridge
/// - 6: Bluetooth PAN - This interface type is supported by ODIN-W2 from software
/// version 5.0.0 onwards only.

Check warning on line 61 in src/command/network/types.rs

View workflow job for this annotation

GitHub Actions / clippy

doc list item without indentation

warning: doc list item without indentation --> src/command/network/types.rs:61:9 | 61 | /// version 5.0.0 onwards only. | ^ | = help: if this is supposed to be its own paragraph, add a blank line = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation help: indent this line | 61 | /// version 5.0.0 onwards only. | ++
#[at_arg(value = 2)]
InterfaceType(InterfaceType),
/// 101: The <status_val> is the currently used IPv4_Addr (omitted if no IP address has
Expand Down Expand Up @@ -80,7 +113,7 @@
/// - 4: PPP
/// - 5: Bridge
/// - 6: Bluetooth PAN - This interface type is supported by ODIN-W2 from software
/// version 5.0.0 onwards only.

Check warning on line 116 in src/command/network/types.rs

View workflow job for this annotation

GitHub Actions / clippy

doc list item without indentation

warning: doc list item without indentation --> src/command/network/types.rs:116:9 | 116 | /// version 5.0.0 onwards only. | ^ | = help: if this is supposed to be its own paragraph, add a blank line = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation help: indent this line | 116 | /// version 5.0.0 onwards only. | ++
InterfaceType = 2,
/// 101: The <status_val> is the currently used IPv4_Addr (omitted if no IP address has
/// been acquired).
Expand Down Expand Up @@ -159,9 +192,9 @@
/// - 2: Wi-Fi Access Point
/// - 3: Ethernet
/// - 6: Bluetooth PAN - This interface is supported by ODIN-W2 from software version
/// 6.0.0 onwards only.

Check warning on line 195 in src/command/network/types.rs

View workflow job for this annotation

GitHub Actions / clippy

doc list item without indentation

warning: doc list item without indentation --> src/command/network/types.rs:195:9 | 195 | /// 6.0.0 onwards only. | ^ | = help: if this is supposed to be its own paragraph, add a blank line = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation help: indent this line | 195 | /// 6.0.0 onwards only. | ++
/// For example, AT+UBRGC = 0,1,1,3. This adds the Wi-Fi station and Ethernet

Check warning on line 196 in src/command/network/types.rs

View workflow job for this annotation

GitHub Actions / clippy

doc list item without indentation

warning: doc list item without indentation --> src/command/network/types.rs:196:9 | 196 | /// For example, AT+UBRGC = 0,1,1,3. This adds the Wi-Fi station and Ethernet | ^ | = help: if this is supposed to be its own paragraph, add a blank line = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation help: indent this line | 196 | /// For example, AT+UBRGC = 0,1,1,3. This adds the Wi-Fi station and Ethernet | ++
/// interfaces to the bridge.

Check warning on line 197 in src/command/network/types.rs

View workflow job for this annotation

GitHub Actions / clippy

doc list item without indentation

warning: doc list item without indentation --> src/command/network/types.rs:197:9 | 197 | /// interfaces to the bridge. | ^ | = help: if this is supposed to be its own paragraph, add a blank line = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation help: indent this line | 197 | /// interfaces to the bridge. | ++
#[at_arg(value = 1)]
LinkLayerList(Option<u8>, Option<u8>, Option<u8>, Option<u8>),
/// IP interface list. This list defines the interfaces that accept IP
Expand All @@ -171,9 +204,9 @@
/// - 2: Wi-Fi Access Point
/// - 3: Ethernet
/// - 6: Bluetooth PAN - This interface is supported by ODIN-W2 from software version
/// 6.0.0 onwards only.

Check warning on line 207 in src/command/network/types.rs

View workflow job for this annotation

GitHub Actions / clippy

doc list item without indentation

warning: doc list item without indentation --> src/command/network/types.rs:207:9 | 207 | /// 6.0.0 onwards only. | ^ | = help: if this is supposed to be its own paragraph, add a blank line = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation help: indent this line | 207 | /// 6.0.0 onwards only. | ++
/// For example, AT+UBRGC = 0,2,1,3. This allows the Wi-Fi station and Ethernet

Check warning on line 208 in src/command/network/types.rs

View workflow job for this annotation

GitHub Actions / clippy

doc list item without indentation

warning: doc list item without indentation --> src/command/network/types.rs:208:9 | 208 | /// For example, AT+UBRGC = 0,2,1,3. This allows the Wi-Fi station and Ethernet | ^ | = help: if this is supposed to be its own paragraph, add a blank line = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation help: indent this line | 208 | /// For example, AT+UBRGC = 0,2,1,3. This allows the Wi-Fi station and Ethernet | ++
/// interfaces to accept IP traffic.

Check warning on line 209 in src/command/network/types.rs

View workflow job for this annotation

GitHub Actions / clippy

doc list item without indentation

warning: doc list item without indentation --> src/command/network/types.rs:209:9 | 209 | /// interfaces to accept IP traffic. | ^ | = help: if this is supposed to be its own paragraph, add a blank line = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation help: indent this line | 209 | /// interfaces to accept IP traffic. | ++
#[at_arg(value = 2)]
IPInterfaceList(Option<u8>, Option<u8>, Option<u8>, Option<u8>),
/// IPv4 Mode - <param_val1> to set the way to retrieve an IP address
Expand Down Expand Up @@ -201,8 +234,8 @@
/// <param_val> is the DHCP server configuration.
/// - 0 (default): Disable DHCP server
/// - 1: Enable DHCP server. The DHCP Server will provide addresses according to the
/// following formula - "(Static address and subnet mask) + 100". If DHCP Server is

Check warning on line 237 in src/command/network/types.rs

View workflow job for this annotation

GitHub Actions / clippy

doc list item without indentation

warning: doc list item without indentation --> src/command/network/types.rs:237:9 | 237 | /// following formula - "(Static address and subnet mask) + 100". If DHCP Server is | ^ | = help: if this is supposed to be its own paragraph, add a blank line = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation help: indent this line | 237 | /// following formula - "(Static address and subnet mask) + 100". If DHCP Server is | ++
/// enabled, the IPv4 Mode should be set to static.

Check warning on line 238 in src/command/network/types.rs

View workflow job for this annotation

GitHub Actions / clippy

doc list item without indentation

warning: doc list item without indentation --> src/command/network/types.rs:238:9 | 238 | /// enabled, the IPv4 Mode should be set to static. | ^ | = help: if this is supposed to be its own paragraph, add a blank line = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation help: indent this line | 238 | /// enabled, the IPv4 Mode should be set to static. | ++
#[at_arg(value = 106)]
DHCPServer(OnOff),
/// Address conflict detection. The factory default value is 0 (disabled). This tag is
Expand Down Expand Up @@ -230,11 +263,11 @@
Load = 2,
/// Validates and activates the configuration.
/// - When a bridge is activated, the data on all network interfaces connected to
/// the bridge is handled by the bridge. The IP configuration set in the individual

Check warning on line 266 in src/command/network/types.rs

View workflow job for this annotation

GitHub Actions / clippy

doc list item without indentation

warning: doc list item without indentation --> src/command/network/types.rs:266:9 | 266 | /// the bridge is handled by the bridge. The IP configuration set in the individual | ^ | = help: if this is supposed to be its own paragraph, add a blank line = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation help: indent this line | 266 | /// the bridge is handled by the bridge. The IP configuration set in the individual | ++
/// network interface configurations is not used while the IP configuration of the

Check warning on line 267 in src/command/network/types.rs

View workflow job for this annotation

GitHub Actions / clippy

doc list item without indentation

warning: doc list item without indentation --> src/command/network/types.rs:267:9 | 267 | /// network interface configurations is not used while the IP configuration of the | ^ | = help: if this is supposed to be its own paragraph, add a blank line = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation help: indent this line | 267 | /// network interface configurations is not used while the IP configuration of the | ++
/// bridge is used.

Check warning on line 268 in src/command/network/types.rs

View workflow job for this annotation

GitHub Actions / clippy

doc list item without indentation

warning: doc list item without indentation --> src/command/network/types.rs:268:9 | 268 | /// bridge is used. | ^ | = help: if this is supposed to be its own paragraph, add a blank line = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation help: indent this line | 268 | /// bridge is used. | ++
/// - The MAC address of the bridge will be set to the Ethernet MAC address but
/// with the U/L bit set to 1 for a locally administered address.

Check warning on line 270 in src/command/network/types.rs

View workflow job for this annotation

GitHub Actions / clippy

doc list item without indentation

warning: doc list item without indentation --> src/command/network/types.rs:270:9 | 270 | /// with the U/L bit set to 1 for a locally administered address. | ^ | = help: if this is supposed to be its own paragraph, add a blank line = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation help: indent this line | 270 | /// with the U/L bit set to 1 for a locally administered address. | ++
Activate = 3,
/// Deactivates the configuration. After deactivating a bridge
/// configuration, the network interfaces connected to the bridge must be deactivated
Expand Down
2 changes: 0 additions & 2 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,13 @@
}
}

#[allow(dead_code)]
pub fn is_station(&self) -> bool {

Check warning on line 53 in src/connection.rs

View workflow job for this annotation

GitHub Actions / clippy

methods `is_station` and `is_access_point` are never used

warning: methods `is_station` and `is_access_point` are never used --> src/connection.rs:53:12 | 41 | impl WifiConnection { | ------------------- methods in this implementation ... 53 | pub fn is_station(&self) -> bool { | ^^^^^^^^^^ ... 60 | pub fn is_access_point(&self) -> bool { | ^^^^^^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default

Check warning on line 53 in src/connection.rs

View workflow job for this annotation

GitHub Actions / Test

methods `is_station` and `is_access_point` are never used

Check warning on line 53 in src/connection.rs

View workflow job for this annotation

GitHub Actions / Test

methods `is_station` and `is_access_point` are never used
self.network
.as_ref()
.map(|n| n.mode == WifiMode::Station)
.unwrap_or_default()
}

#[allow(dead_code)]
pub fn is_access_point(&self) -> bool {
!self.is_station()
}
Expand Down
14 changes: 14 additions & 0 deletions src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ impl WifiNetwork {
mode: WifiMode::Station,
}
}

pub fn new_ap() -> Self {
Self {
bssid: Bytes::new(),
op_mode: OperationMode::Infrastructure,
ssid: String::new(),
channel: 0,
rssi: 1,
authentication_suites: 0,
unicast_ciphers: 0,
group_ciphers: 0,
mode: WifiMode::AccessPoint,
}
}
}

impl TryFrom<ScannedWifiNetwork> for WifiNetwork {
Expand Down
Loading
Loading