-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
station: add station get command and dump example
- Loading branch information
1 parent
40cc282
commit 19d03a5
Showing
7 changed files
with
141 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// 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: dump_nl80211_station <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() | ||
.build() | ||
.unwrap(); | ||
rt.block_on(dump_station(index)); | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn dump_station(if_index: u32) { | ||
let (connection, handle, _) = wl_nl80211::new_connection().unwrap(); | ||
tokio::spawn(connection); | ||
|
||
let mut sta_handle = handle.station().dump(if_index).execute().await; | ||
|
||
let mut msgs = Vec::new(); | ||
while let Some(msg) = sta_handle.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
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
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,50 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
use futures::TryStream; | ||
use netlink_packet_generic::GenlMessage; | ||
|
||
use crate::{ | ||
nl80211_execute, Nl80211Attr, Nl80211Error, Nl80211Handle, Nl80211Message, | ||
}; | ||
|
||
const ETH_ALEN: usize = 6; | ||
|
||
pub struct Nl80211StationGetRequest { | ||
handle: Nl80211Handle, | ||
if_index: u32, | ||
mac_address: Option<[u8; ETH_ALEN]>, | ||
} | ||
|
||
impl Nl80211StationGetRequest { | ||
pub(crate) fn new( | ||
handle: Nl80211Handle, | ||
if_index: u32, | ||
mac_address: Option<[u8; ETH_ALEN]>, | ||
) -> Self { | ||
Nl80211StationGetRequest { | ||
handle, | ||
if_index, | ||
mac_address, | ||
} | ||
} | ||
|
||
pub async fn execute( | ||
self, | ||
) -> impl TryStream<Ok = GenlMessage<Nl80211Message>, Error = Nl80211Error> | ||
{ | ||
let Nl80211StationGetRequest { | ||
mut handle, | ||
if_index, | ||
mac_address, | ||
} = self; | ||
|
||
let mut nlas = vec![Nl80211Attr::IfIndex(if_index)]; | ||
if let Some(arr) = mac_address { | ||
nlas.push(Nl80211Attr::Mac(arr)) | ||
} | ||
|
||
let nl80211_msg = Nl80211Message::new_station_get(nlas); | ||
|
||
nl80211_execute(&mut handle, nl80211_msg).await | ||
} | ||
} |
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,17 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
use crate::{Nl80211Handle, Nl80211StationGetRequest}; | ||
|
||
pub struct Nl80211StationHandle(Nl80211Handle); | ||
|
||
impl Nl80211StationHandle { | ||
pub fn new(handle: Nl80211Handle) -> Self { | ||
Nl80211StationHandle(handle) | ||
} | ||
|
||
/// Retrieve the stations | ||
/// (equivalent to `iw dev DEV station dump`) | ||
pub fn dump(&mut self, if_index: u32) -> Nl80211StationGetRequest { | ||
Nl80211StationGetRequest::new(self.0.clone(), if_index, None) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,11 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
mod get; | ||
mod handle; | ||
mod rate_info; | ||
mod station_info; | ||
|
||
pub use get::Nl80211StationGetRequest; | ||
pub use handle::Nl80211StationHandle; | ||
pub use rate_info::Nl80211RateInfo; | ||
pub use station_info::Nl80211StationInfo; |