Skip to content

Commit 21896a4

Browse files
committed
Replace Nl80211Cmd with Nl80211Command
API breakage: * Replaced `Nl80211Cmd` by `Nl80211Command`. * Removed these `Nl80211Message` functions: * `new_interface_get()` * `new_station_get()` * `new_wiphy_get()` * `new_scan_get()` Signed-off-by: Gris Ge <[email protected]>
1 parent dc5cc16 commit 21896a4

File tree

9 files changed

+759
-827
lines changed

9 files changed

+759
-827
lines changed

src/command.rs

Lines changed: 714 additions & 0 deletions
Large diffs are not rendered by default.

src/iface/get.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
use futures::TryStream;
44
use netlink_packet_generic::GenlMessage;
55

6-
use crate::{nl80211_execute, Nl80211Error, Nl80211Handle, Nl80211Message};
6+
use crate::{
7+
nl80211_execute, Nl80211Command, Nl80211Error, Nl80211Handle,
8+
Nl80211Message,
9+
};
710

811
pub struct Nl80211InterfaceGetRequest {
912
handle: Nl80211Handle,
@@ -20,7 +23,10 @@ impl Nl80211InterfaceGetRequest {
2023
{
2124
let Nl80211InterfaceGetRequest { mut handle } = self;
2225

23-
let nl80211_msg = Nl80211Message::new_interface_get();
26+
let nl80211_msg = Nl80211Message {
27+
cmd: Nl80211Command::GetInterface,
28+
attributes: vec![],
29+
};
2430
nl80211_execute(&mut handle, nl80211_msg).await
2531
}
2632
}

src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
mod attr;
44
mod channel;
5+
mod command;
56
mod connection;
67
mod element;
78
mod error;
@@ -26,6 +27,7 @@ pub(crate) mod bytes;
2627

2728
pub use self::attr::Nl80211Attr;
2829
pub use self::channel::Nl80211ChannelWidth;
30+
pub use self::command::Nl80211Command;
2931
#[cfg(feature = "tokio_socket")]
3032
pub use self::connection::new_connection;
3133
pub use self::connection::new_connection_with_socket;
@@ -42,7 +44,7 @@ pub use self::iface::{
4244
Nl80211IfaceCombLimitAttribute, Nl80211InterfaceGetRequest,
4345
Nl80211InterfaceHandle, Nl80211InterfaceType,
4446
};
45-
pub use self::message::{Nl80211Cmd, Nl80211Message};
47+
pub use self::message::Nl80211Message;
4648
pub use self::mlo::Nl80211MloLink;
4749
pub use self::scan::{
4850
Nl80211BssCapabilities, Nl80211BssInfo, Nl80211BssUseFor,
@@ -75,10 +77,9 @@ pub use self::wifi7::{
7577
};
7678
pub use self::wiphy::{
7779
Nl80211Band, Nl80211BandInfo, Nl80211BandType, Nl80211BandTypes,
78-
Nl80211CipherSuit, Nl80211Command, Nl80211Frequency, Nl80211FrequencyInfo,
79-
Nl80211IfMode, Nl80211WiphyGetRequest, Nl80211WiphyHandle,
80-
Nl80211WowlanTcpTrigerSupport, Nl80211WowlanTrigerPatternSupport,
81-
Nl80211WowlanTrigersSupport,
80+
Nl80211CipherSuit, Nl80211Frequency, Nl80211FrequencyInfo, Nl80211IfMode,
81+
Nl80211WiphyGetRequest, Nl80211WiphyHandle, Nl80211WowlanTcpTrigerSupport,
82+
Nl80211WowlanTrigerPatternSupport, Nl80211WowlanTrigersSupport,
8283
};
8384

8485
pub(crate) use self::element::Nl80211Elements;

src/message.rs

Lines changed: 5 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,11 @@ use netlink_packet_utils::{
66
nla::NlasIterator, DecodeError, Emitable, Parseable, ParseableParametrized,
77
};
88

9-
use crate::attr::Nl80211Attr;
10-
11-
const NL80211_CMD_GET_WIPHY: u8 = 1;
12-
const NL80211_CMD_NEW_WIPHY: u8 = 3;
13-
const NL80211_CMD_GET_INTERFACE: u8 = 5;
14-
const NL80211_CMD_NEW_INTERFACE: u8 = 7;
15-
const NL80211_CMD_GET_STATION: u8 = 17;
16-
const NL80211_CMD_NEW_STATION: u8 = 19;
17-
const NL80211_CMD_GET_SCAN: u8 = 32;
18-
const NL80211_CMD_NEW_SCAN_RESULTS: u8 = 34;
19-
20-
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
21-
pub enum Nl80211Cmd {
22-
InterfaceGet,
23-
InterfaceNew,
24-
StationGet,
25-
StationNew,
26-
WiphyGet,
27-
WiphyNew,
28-
ScanGet,
29-
}
30-
31-
impl From<Nl80211Cmd> for u8 {
32-
fn from(cmd: Nl80211Cmd) -> Self {
33-
match cmd {
34-
Nl80211Cmd::InterfaceGet => NL80211_CMD_GET_INTERFACE,
35-
Nl80211Cmd::InterfaceNew => NL80211_CMD_NEW_INTERFACE,
36-
Nl80211Cmd::StationGet => NL80211_CMD_GET_STATION,
37-
Nl80211Cmd::StationNew => NL80211_CMD_NEW_STATION,
38-
Nl80211Cmd::WiphyGet => NL80211_CMD_GET_WIPHY,
39-
Nl80211Cmd::WiphyNew => NL80211_CMD_NEW_WIPHY,
40-
Nl80211Cmd::ScanGet => NL80211_CMD_GET_SCAN,
41-
}
42-
}
43-
}
9+
use crate::{Nl80211Attr, Nl80211Command};
4410

4511
#[derive(Debug, PartialEq, Eq, Clone)]
4612
pub struct Nl80211Message {
47-
pub cmd: Nl80211Cmd,
13+
pub cmd: Nl80211Command,
4814
pub attributes: Vec<Nl80211Attr>,
4915
}
5016

@@ -62,36 +28,6 @@ impl GenlFamily for Nl80211Message {
6228
}
6329
}
6430

65-
impl Nl80211Message {
66-
pub fn new_interface_get() -> Self {
67-
Nl80211Message {
68-
cmd: Nl80211Cmd::InterfaceGet,
69-
attributes: vec![],
70-
}
71-
}
72-
73-
pub fn new_station_get(attributes: Vec<Nl80211Attr>) -> Self {
74-
Nl80211Message {
75-
cmd: Nl80211Cmd::StationGet,
76-
attributes,
77-
}
78-
}
79-
80-
pub fn new_wiphy_get() -> Self {
81-
Nl80211Message {
82-
cmd: Nl80211Cmd::WiphyGet,
83-
attributes: vec![Nl80211Attr::SplitWiphyDump],
84-
}
85-
}
86-
87-
pub fn new_scan_get(attributes: Vec<Nl80211Attr>) -> Self {
88-
Self {
89-
cmd: Nl80211Cmd::ScanGet,
90-
attributes,
91-
}
92-
}
93-
}
94-
9531
impl Emitable for Nl80211Message {
9632
fn buffer_len(&self) -> usize {
9733
self.attributes.as_slice().buffer_len()
@@ -117,33 +53,8 @@ impl ParseableParametrized<[u8], GenlHeader> for Nl80211Message {
11753
buffer: &[u8],
11854
header: GenlHeader,
11955
) -> Result<Self, DecodeError> {
120-
Ok(match header.cmd {
121-
NL80211_CMD_NEW_INTERFACE => Self {
122-
cmd: Nl80211Cmd::InterfaceNew,
123-
attributes: parse_nlas(buffer)?,
124-
},
125-
NL80211_CMD_GET_STATION => Self {
126-
cmd: Nl80211Cmd::StationGet,
127-
attributes: parse_nlas(buffer)?,
128-
},
129-
NL80211_CMD_NEW_STATION => Self {
130-
cmd: Nl80211Cmd::StationNew,
131-
attributes: parse_nlas(buffer)?,
132-
},
133-
NL80211_CMD_NEW_WIPHY => Self {
134-
cmd: Nl80211Cmd::WiphyNew,
135-
attributes: parse_nlas(buffer)?,
136-
},
137-
NL80211_CMD_NEW_SCAN_RESULTS => Self {
138-
cmd: Nl80211Cmd::ScanGet,
139-
attributes: parse_nlas(buffer)?,
140-
},
141-
cmd => {
142-
return Err(DecodeError::from(format!(
143-
"Unsupported nl80211 reply command: {}",
144-
cmd
145-
)))
146-
}
147-
})
56+
let cmd = Nl80211Command::from(header.cmd);
57+
let attributes = parse_nlas(buffer)?;
58+
Ok(Self { cmd, attributes })
14859
}
14960
}

src/scan/get.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use futures::TryStream;
44
use netlink_packet_generic::GenlMessage;
55

66
use crate::{
7-
nl80211_execute, Nl80211Attr, Nl80211Error, Nl80211Handle, Nl80211Message,
7+
nl80211_execute, Nl80211Attr, Nl80211Command, Nl80211Error, Nl80211Handle,
8+
Nl80211Message,
89
};
910

1011
pub struct Nl80211ScanGetRequest {
@@ -26,8 +27,11 @@ impl Nl80211ScanGetRequest {
2627
if_index,
2728
} = self;
2829

29-
let nlas = vec![Nl80211Attr::IfIndex(if_index)];
30-
let nl80211_msg = Nl80211Message::new_scan_get(nlas);
30+
let attributes = vec![Nl80211Attr::IfIndex(if_index)];
31+
let nl80211_msg = Nl80211Message {
32+
cmd: Nl80211Command::GetScan,
33+
attributes,
34+
};
3135

3236
nl80211_execute(&mut handle, nl80211_msg).await
3337
}

src/station/get.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use futures::TryStream;
44
use netlink_packet_generic::GenlMessage;
55

66
use crate::{
7-
nl80211_execute, Nl80211Attr, Nl80211Error, Nl80211Handle, Nl80211Message,
7+
nl80211_execute, Nl80211Attr, Nl80211Command, Nl80211Error, Nl80211Handle,
8+
Nl80211Message,
89
};
910

1011
const ETH_ALEN: usize = 6;
@@ -38,12 +39,15 @@ impl Nl80211StationGetRequest {
3839
mac_address,
3940
} = self;
4041

41-
let mut nlas = vec![Nl80211Attr::IfIndex(if_index)];
42+
let mut attributes = vec![Nl80211Attr::IfIndex(if_index)];
4243
if let Some(arr) = mac_address {
43-
nlas.push(Nl80211Attr::Mac(arr))
44+
attributes.push(Nl80211Attr::Mac(arr))
4445
}
4546

46-
let nl80211_msg = Nl80211Message::new_station_get(nlas);
47+
let nl80211_msg = Nl80211Message {
48+
cmd: Nl80211Command::GetStation,
49+
attributes,
50+
};
4751

4852
nl80211_execute(&mut handle, nl80211_msg).await
4953
}

0 commit comments

Comments
 (0)