-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scan: Add scan trigger and schedule support
Signed-off-by: Gris Ge <[email protected]>
- Loading branch information
Showing
20 changed files
with
1,016 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
use std::env::args; | ||
|
||
use anyhow::{bail, Context, Error}; | ||
use futures::stream::TryStreamExt; | ||
|
||
fn main() -> Result<(), Error> { | ||
let argv: Vec<_> = args().collect(); | ||
|
||
if argv.len() < 2 { | ||
eprintln!("Usage: nl80211_trigger_scan <interface index>"); | ||
bail!("Required arguments not given"); | ||
} | ||
|
||
let err_msg = format!("Invalid interface index value: {}", argv[1]); | ||
let index = argv[1].parse::<u32>().context(err_msg)?; | ||
|
||
let rt = tokio::runtime::Builder::new_current_thread() | ||
.enable_io() | ||
.enable_time() | ||
.build() | ||
.unwrap(); | ||
rt.block_on(dump_scan(index)); | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn dump_scan(if_index: u32) { | ||
let (connection, handle, _) = wl_nl80211::new_connection().unwrap(); | ||
tokio::spawn(connection); | ||
|
||
let attrs = wl_nl80211::Nl80211Scan::new(if_index) | ||
.duration(5000) | ||
.passive(true) | ||
.build(); | ||
|
||
let mut scan_handle = handle.scan().trigger(attrs).execute().await; | ||
|
||
let mut msgs = Vec::new(); | ||
while let Some(msg) = scan_handle.try_next().await.unwrap() { | ||
msgs.push(msg); | ||
} | ||
tokio::time::sleep(std::time::Duration::from_secs(5)).await; | ||
|
||
let mut dump = handle.scan().dump(if_index).execute().await; | ||
let mut msgs = Vec::new(); | ||
while let Some(msg) = dump.try_next().await.unwrap() { | ||
msgs.push(msg); | ||
} | ||
assert!(!msgs.is_empty()); | ||
for msg in msgs { | ||
println!("{:?}", msg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.