Skip to content

Commit

Permalink
Add abort scan command
Browse files Browse the repository at this point in the history
  • Loading branch information
ollipa committed Oct 9, 2023
1 parent deb2cd6 commit 5cce245
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/asynchronous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ impl AsyncNlSocket {
Self::handle_ack_response(recv).await
}

pub async fn abort_scan(&mut self, if_index: u32) -> Result<()> {
let request = Nl80211Request::abort_scan(if_index);
let recv = self.send(request).await?;
Self::handle_ack_response(recv).await
}

async fn send(
&self,
request: Nl80211Request,
Expand Down
29 changes: 29 additions & 0 deletions src/netlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,33 @@ impl Nl80211Request {
),
}
}

pub fn abort_scan(if_index: u32) -> Self {
let attrs = {
let mut attrs = GenlBuffer::new();
let attr_type = AttrTypeBuilder::default()
.nla_type(Attribute::Ifindex)
.build()
.unwrap();
attrs.push(
NlattrBuilder::default()
.nla_type(attr_type)
.nla_payload(if_index)
.build()
.unwrap(),
);
attrs
};
Self {
nl_flags: NlmF::REQUEST | NlmF::ACK,
nl_payload: NlPayload::Payload(
GenlmsghdrBuilder::<Command, Attribute, NoUserHeader>::default()
.cmd(Command::AbortScan)
.version(NL80211_VERSION)
.attrs(attrs)
.build()
.unwrap(),
),
}
}
}
10 changes: 10 additions & 0 deletions src/synchronous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,22 @@ impl NlSocket {
Ok(responses)
}

/// Trigger a new scan.
pub fn trigger_scan(&mut self, if_index: u32) -> Result<()> {
let request = Nl80211Request::trigger_scan(if_index);
let recv = self.send(request)?;
Self::handle_ack_response(recv)
}

/// Stop an ongoing scan.
///
/// Returns NlError ENOENT if a scan is not running.
pub fn abort_scan(&mut self, if_index: u32) -> Result<()> {
let request = Nl80211Request::abort_scan(if_index);
let recv = self.send(request)?;
Self::handle_ack_response(recv)
}

fn send(
&self,
request: Nl80211Request,
Expand Down

0 comments on commit 5cce245

Please sign in to comment.