Skip to content

Commit

Permalink
add method to remove all networks
Browse files Browse the repository at this point in the history
  • Loading branch information
aj-bagwell authored and lthiery committed May 22, 2024
1 parent 2274858 commit b58eb3b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/sta/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub(crate) enum Request {
SetNetwork(usize, SetNetwork, oneshot::Sender<Result>),
SaveConfig(oneshot::Sender<Result>),
RemoveNetwork(usize, oneshot::Sender<Result>),
RemoveAllNetworks(oneshot::Sender<Result>),
SelectNetwork(usize, oneshot::Sender<Result<SelectResult>>),
Shutdown,
SelectTimeout,
Expand Down Expand Up @@ -76,6 +77,9 @@ impl ShutdownSignal for Request {
Request::RemoveNetwork(_, response) => {
let _ = response.send(Err(error::Error::StartupAborted));
}
Request::RemoveAllNetworks(response) => {
let _ = response.send(Err(error::Error::StartupAborted));
}
Request::SelectNetwork(_, response) => {
let _ = response.send(Err(error::Error::StartupAborted));
}
Expand Down Expand Up @@ -181,6 +185,13 @@ impl RequestClient {
request.await?
}

pub async fn remove_all_networks(&self) -> Result {
let (response, request) = oneshot::channel();
self.send_request(Request::RemoveAllNetworks(response))
.await?;
request.await?
}

pub async fn select_network(&self, network_id: usize) -> Result<SelectResult> {
let (response, request) = oneshot::channel();
self.send_request(Request::SelectNetwork(network_id, response))
Expand Down
7 changes: 7 additions & 0 deletions src/sta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ impl WifiStation {
debug!("wpa_ctrl removed network {id}");
let _ = response.send(Ok(()));
}
Request::RemoveAllNetworks(response) => {
if let Err(e) = socket_handle.command(b"REMOVE_NETWORK all").await {
warn!("Error while removing network all: {e}");
}
debug!("wpa_ctrl removed network all");
let _ = response.send(Ok(()));
}
Request::SelectNetwork(id, response_sender) => {
let response_sender = match select_request {
None => {
Expand Down

0 comments on commit b58eb3b

Please sign in to comment.