Skip to content

Commit dc5cc16

Browse files
committed
scan: Add support of parsing HT(WIFI4) capability
API breakage: * `Nl80211HtMcsInfo.tx_params` changed from `u8` to `Nl80211HtTxParameter`. * Many constant of `Nl80211HtCaps` got renamed in order to fit into its actual meanings. Signed-off-by: Gris Ge <fge@redhat.com>
1 parent 3adb7b9 commit dc5cc16

File tree

5 files changed

+534
-30
lines changed

5 files changed

+534
-30
lines changed

src/bytes.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub(crate) fn write_i32(buffer: &mut [u8], value: i32) {
2626
buffer[..4].copy_from_slice(&value.to_ne_bytes())
2727
}
2828

29+
/// The `pos` is index from bit 0.
2930
pub(crate) fn get_bit(data: &[u8], pos: usize) -> bool {
3031
let index: usize = pos / 8;
3132
let bit_pos: usize = pos % 8;
@@ -38,6 +39,7 @@ pub(crate) fn get_bit(data: &[u8], pos: usize) -> bool {
3839
(data[index] & 1u8 << bit_pos) >= 1
3940
}
4041

42+
/// The `start` is index from bit 0.
4143
pub(crate) fn get_bits_as_u8(data: &[u8], start: usize, end: usize) -> u8 {
4244
if (end - start) >= 8 {
4345
panic!(

src/element.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use netlink_packet_utils::{
66
DecodeError, Emitable, Parseable,
77
};
88

9-
use crate::bytes::{parse_u16_le, write_u16_le, write_u32_le};
9+
use crate::{
10+
bytes::{parse_u16_le, write_u16_le, write_u32_le},
11+
Nl80211ElementHtCap,
12+
};
1013

1114
pub(crate) struct Nl80211Elements(Vec<Nl80211Element>);
1215

@@ -59,6 +62,7 @@ const ELEMENT_ID_SSID: u8 = 0;
5962
const ELEMENT_ID_SUPPORTED_RATES: u8 = 1;
6063
const ELEMENT_ID_CHANNEL: u8 = 3;
6164
const ELEMENT_ID_COUNTRY: u8 = 7;
65+
const ELEMENT_ID_HT_CAP: u8 = 45;
6266
const ELEMENT_ID_RSN: u8 = 48;
6367
const ELEMENT_ID_VENDOR: u8 = 221;
6468

@@ -73,6 +77,7 @@ pub enum Nl80211Element {
7377
/// Allow channel number identification for STAs.
7478
Channel(u8),
7579
Country(Nl80211ElementCountry),
80+
HtCapability(Nl80211ElementHtCap),
7681
Rsn(Nl80211ElementRsn),
7782
/// Vendor specific data.
7883
Vendor(Vec<u8>),
@@ -89,6 +94,7 @@ impl Nl80211Element {
8994
Self::Country(_) => ELEMENT_ID_COUNTRY,
9095
Self::Rsn(_) => ELEMENT_ID_RSN,
9196
Self::Vendor(_) => ELEMENT_ID_VENDOR,
97+
Self::HtCapability(_) => ELEMENT_ID_HT_CAP,
9298
Self::Other(id, _) => *id,
9399
}
94100
}
@@ -102,6 +108,7 @@ impl Nl80211Element {
102108
Self::Country(v) => v.buffer_len() as u8,
103109
Self::Rsn(v) => v.buffer_len() as u8,
104110
Self::Vendor(v) => v.len() as u8,
111+
Self::HtCapability(v) => v.buffer_len() as u8,
105112
Self::Other(_, data) => (data.len()) as u8,
106113
}
107114
}
@@ -137,6 +144,9 @@ impl<T: AsRef<[u8]> + ?Sized> Parseable<T> for Nl80211Element {
137144
}
138145
ELEMENT_ID_RSN => Self::Rsn(Nl80211ElementRsn::parse(payload)?),
139146
ELEMENT_ID_VENDOR => Self::Vendor(payload.to_vec()),
147+
ELEMENT_ID_HT_CAP => {
148+
Self::HtCapability(Nl80211ElementHtCap::parse(payload)?)
149+
}
140150
_ => Self::Other(id, payload.to_vec()),
141151
})
142152
}
@@ -166,6 +176,7 @@ impl Emitable for Nl80211Element {
166176
Self::Country(v) => v.emit(buffer),
167177
Self::Rsn(v) => v.emit(buffer),
168178
Self::Vendor(v) => buffer[..v.len()].copy_from_slice(v.as_slice()),
179+
Self::HtCapability(v) => v.emit(buffer),
169180
Self::Other(_, data) => {
170181
payload.copy_from_slice(data.as_slice());
171182
}

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ pub use self::stats::{
5656
NestedNl80211TidStats, Nl80211TidStats, Nl80211TransmitQueueStat,
5757
};
5858
pub use self::wifi4::{
59-
Nl80211HtCapabilityMask, Nl80211HtCaps, Nl80211HtMcsInfo,
59+
Nl80211ElementHtCap, Nl80211HtAMpduPara, Nl80211HtAselCaps,
60+
Nl80211HtCapabilityMask, Nl80211HtCaps, Nl80211HtExtendedCap,
61+
Nl80211HtMcsInfo, Nl80211HtTransmitBeamformingCaps, Nl80211HtTxParameter,
6062
Nl80211HtWiphyChannelType,
6163
};
6264
pub use self::wifi5::{

0 commit comments

Comments
 (0)