Skip to content

Commit 10c1d6f

Browse files
committed
Add support for radio stats
1 parent 3e8c21f commit 10c1d6f

File tree

6 files changed

+49
-12
lines changed

6 files changed

+49
-12
lines changed

examples/dump_nl80211_survey.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ async fn dump_survey(if_index: u32) -> Result<(), Error> {
2929
let (connection, handle, _) = wl_nl80211::new_connection()?;
3030
tokio::spawn(connection);
3131

32-
let mut survey_handle = handle.survey().dump(if_index).execute().await;
32+
let mut survey_handle = handle
33+
.survey()
34+
.dump(wl_nl80211::Nl80211Survey::new(if_index).radio(true).build())
35+
.execute()
36+
.await;
3337

3438
let mut msgs = Vec::new();
3539
while let Some(msg) = survey_handle.try_next().await? {

src/attr.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ const NL80211_ATTR_MAX_CSA_COUNTERS: u16 = 206;
339339
const NL80211_ATTR_MAC_MASK: u16 = 215;
340340
const NL80211_ATTR_WIPHY_SELF_MANAGED_REG: u16 = 216;
341341
const NL80211_ATTR_EXT_FEATURES: u16 = 217;
342-
// const NL80211_ATTR_SURVEY_RADIO_STATS:u16 = 218;
342+
const NL80211_ATTR_SURVEY_RADIO_STATS: u16 = 218;
343343
// const NL80211_ATTR_NETNS_FD:u16 = 219;
344344
const NL80211_ATTR_SCHED_SCAN_DELAY: u16 = 220;
345345
// const NL80211_ATTR_REG_INDOOR:u16 = 221;
@@ -520,6 +520,7 @@ pub enum Nl80211Attr {
520520
/// in milliseconds
521521
MaxRemainOnChannelDuration(u32),
522522
OffchannelTxOk,
523+
SurveyRadioStats,
523524
WowlanTrigersSupport(Vec<Nl80211WowlanTrigersSupport>),
524525
SoftwareIftypes(Vec<Nl80211InterfaceType>),
525526
Features(Nl80211Features),
@@ -637,6 +638,7 @@ impl Nla for Nl80211Attr {
637638
| Self::TdlsExternalSetup
638639
| Self::ControlPortEthertype
639640
| Self::OffchannelTxOk
641+
| Self::SurveyRadioStats
640642
| Self::WiphySelfManagedReg => 0,
641643
Self::CipherSuites(s) => 4 * s.len(),
642644
Self::SupportedIftypes(s) => s.as_slice().buffer_len(),
@@ -707,6 +709,7 @@ impl Nla for Nl80211Attr {
707709
Self::Ssid(_) => NL80211_ATTR_SSID,
708710
Self::StationInfo(_) => NL80211_ATTR_STA_INFO,
709711
Self::SurveyInfo(_) => NL80211_ATTR_SURVEY_INFO,
712+
Self::SurveyRadioStats => NL80211_ATTR_SURVEY_RADIO_STATS,
710713
Self::TransmitQueueStats(_) => NL80211_ATTR_TXQ_STATS,
711714
Self::TransmitQueueLimit(_) => NL80211_ATTR_TXQ_LIMIT,
712715
Self::TransmitQueueMemoryLimit(_) => NL80211_ATTR_TXQ_MEMORY_LIMIT,
@@ -839,6 +842,7 @@ impl Nla for Nl80211Attr {
839842
| Self::TdlsExternalSetup
840843
| Self::ControlPortEthertype
841844
| Self::OffchannelTxOk
845+
| Self::SurveyRadioStats
842846
| Self::WiphySelfManagedReg => (),
843847
Self::WiphyChannelType(d) => write_u32(buffer, (*d).into()),
844848
Self::ChannelWidth(d) => write_u32(buffer, (*d).into()),
@@ -1079,6 +1083,7 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for Nl80211Attr {
10791083
}
10801084
Self::SurveyInfo(nlas)
10811085
}
1086+
NL80211_ATTR_SURVEY_RADIO_STATS => Self::SurveyRadioStats,
10821087
NL80211_ATTR_TXQ_STATS => {
10831088
let err_msg = format!(
10841089
"Invalid NL80211_ATTR_TXQ_STATS value {:?}",

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ pub use self::stats::{
6565
NestedNl80211TidStats, Nl80211TidStats, Nl80211TransmitQueueStat,
6666
};
6767
pub use self::survey::{
68-
Nl80211SurveyGetRequest, Nl80211SurveyHandle, Nl80211SurveyInfo,
68+
Nl80211Survey, Nl80211SurveyGetRequest, Nl80211SurveyHandle,
69+
Nl80211SurveyInfo,
6970
};
7071
pub use self::wifi4::{
7172
Nl80211ElementHtCap, Nl80211HtAMpduPara, Nl80211HtAselCaps,

src/survey/get.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ use crate::{
1111

1212
pub struct Nl80211SurveyGetRequest {
1313
handle: Nl80211Handle,
14-
if_index: u32,
14+
attributes: Vec<Nl80211Attr>,
1515
}
1616

1717
impl Nl80211SurveyGetRequest {
18-
pub(crate) fn new(handle: Nl80211Handle, if_index: u32) -> Self {
19-
Self { handle, if_index }
18+
pub(crate) fn new(handle: Nl80211Handle, attributes: Vec<Nl80211Attr>) -> Self {
19+
Self { handle, attributes }
2020
}
2121

2222
pub async fn execute(
@@ -25,10 +25,9 @@ impl Nl80211SurveyGetRequest {
2525
{
2626
let Self {
2727
mut handle,
28-
if_index,
28+
attributes,
2929
} = self;
3030

31-
let attributes = vec![Nl80211Attr::IfIndex(if_index)];
3231
let nl80211_msg = Nl80211Message {
3332
cmd: Nl80211Command::GetSurvey,
3433
attributes,

src/survey/handle.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,45 @@
11
// SPDX-License-Identifier: MIT
22

3-
use crate::{Nl80211Handle, Nl80211SurveyGetRequest};
3+
use netlink_packet_utils::nla::Nla;
4+
5+
use crate::{
6+
Nl80211Attr, Nl80211AttrsBuilder, Nl80211Handle, Nl80211SurveyGetRequest,
7+
};
48

59
pub struct Nl80211SurveyHandle(Nl80211Handle);
610

11+
#[derive(Debug)]
12+
pub struct Nl80211Survey;
13+
14+
impl Nl80211Survey {
15+
/// Perform a survey dump
16+
pub fn new(if_index: u32) -> Nl80211AttrsBuilder<Self> {
17+
Nl80211AttrsBuilder::<Self>::new().if_index(if_index)
18+
}
19+
}
20+
21+
impl Nl80211AttrsBuilder<Nl80211Survey> {
22+
/// Request overall radio statistics to be returned along with other survey data
23+
pub fn radio(self, value: bool) -> Self {
24+
if value {
25+
self.replace(Nl80211Attr::SurveyRadioStats)
26+
} else {
27+
self.remove(Nl80211Attr::SurveyRadioStats.kind())
28+
}
29+
}
30+
}
31+
732
impl Nl80211SurveyHandle {
833
pub fn new(handle: Nl80211Handle) -> Self {
934
Self(handle)
1035
}
1136

1237
/// Retrieve the survey info
1338
/// (equivalent to `iw dev DEV survey dump`)
14-
pub fn dump(&mut self, if_index: u32) -> Nl80211SurveyGetRequest {
15-
Nl80211SurveyGetRequest::new(self.0.clone(), if_index)
39+
pub fn dump(
40+
&mut self,
41+
attributes: Vec<Nl80211Attr>,
42+
) -> Nl80211SurveyGetRequest {
43+
Nl80211SurveyGetRequest::new(self.0.clone(), attributes)
1644
}
1745
}

src/survey/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ mod handle;
55
mod survey_info;
66

77
pub use self::get::Nl80211SurveyGetRequest;
8-
pub use self::handle::Nl80211SurveyHandle;
8+
pub use self::handle::{Nl80211Survey, Nl80211SurveyHandle};
99
pub use self::survey_info::Nl80211SurveyInfo;

0 commit comments

Comments
 (0)