Skip to content

Commit d9082bc

Browse files
authored
Merge pull request #161 from shellrow/feat/linux-wwan-detection
feat: add WWAN interface detection
2 parents 20af861 + b0f2385 commit d9082bc

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

src/interface/types.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ pub enum InterfaceType {
6363
HighPerformanceSerialBus,
6464
/// Mobile broadband interface for WiMAX devices.
6565
Wman,
66+
/// Wireless wide area network interface, such as a mobile broadband or cellular modem.
67+
Wwan,
6668
/// Mobile broadband interface for GSM-based devices.
6769
Wwanpp,
6870
/// Mobile broadband interface for CDMA-based devices.
@@ -208,6 +210,7 @@ impl InterfaceType {
208210
InterfaceType::HighPerformanceSerialBus => String::from("High Performance Serial Bus"),
209211
InterfaceType::Bridge => String::from("Bridge"),
210212
InterfaceType::Wman => String::from("WMAN"),
213+
InterfaceType::Wwan => String::from("WWAN"),
211214
InterfaceType::Wwanpp => String::from("WWANPP"),
212215
InterfaceType::Wwanpp2 => String::from("WWANPP2"),
213216
InterfaceType::Can => String::from("CAN"),

src/os/linux/sysfs.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,37 @@ fn is_wifi_interface(ifname: &str) -> bool {
1717
let base = PathBuf::from("/sys/class/net").join(ifname);
1818

1919
// 1) Check uevent file for DEVTYPE=wlan
20-
if let Some(ue) = read_trimmed(base.join("uevent")) {
21-
if ue.lines().any(|l| l.trim() == "DEVTYPE=wlan") {
22-
return true;
23-
}
20+
if let Some(ue) = read_trimmed(base.join("uevent"))
21+
&& ue.lines().any(|l| l.trim() == "DEVTYPE=wlan")
22+
{
23+
return true;
2424
}
2525

2626
// 2) Check for wireless or phy80211 directories
2727
exists(base.join("wireless")) || exists(base.join("phy80211"))
2828
}
2929

30+
/// Check if the interface is a WWAN/mobile broadband interface.
31+
fn is_wwan_interface(ifname: &str) -> bool {
32+
let base = PathBuf::from("/sys/class/net").join(ifname);
33+
34+
if let Some(uevent) = read_trimmed(base.join("uevent"))
35+
&& uevent.lines().any(|line| line.trim() == "DEVTYPE=wwan")
36+
{
37+
return true;
38+
}
39+
40+
is_wwan_name(ifname)
41+
}
42+
43+
fn is_wwan_name(ifname: &str) -> bool {
44+
ifname == "wwan"
45+
|| ifname.starts_with("wwan")
46+
|| ifname.starts_with("wwp")
47+
|| ifname.starts_with("rmnet")
48+
|| ifname.starts_with("ccmni")
49+
}
50+
3051
/// Check if the interface is a virtual interface.
3152
pub fn is_virtual_interface(ifname: &str) -> bool {
3253
let dev_link = PathBuf::from("/sys/class/net").join(ifname).join("device");
@@ -52,6 +73,11 @@ pub fn get_interface_type(ifname: &str) -> InterfaceType {
5273
if is_wifi_interface(ifname) {
5374
return InterfaceType::Wireless80211;
5475
}
76+
77+
if is_wwan_interface(ifname) {
78+
return InterfaceType::Wwan;
79+
}
80+
5581
// Read the type from sysfs
5682
let p = PathBuf::from("/sys/class/net").join(ifname).join("type");
5783
let ty = match read_trimmed(&p).and_then(|s| s.parse::<u32>().ok()) {

0 commit comments

Comments
 (0)