Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn main() -> Result<(), Error> {
- [x] Loopback
- [x] Macsec
- [x] MacVLAN
- [ ] Modem
- [x] Modem
- [ ] OLPCMesh
- [ ] OVSBridge
- [ ] OVSInterface
Expand Down
3 changes: 2 additions & 1 deletion src/devices/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::IpVlanDevice;
use super::{
AdslDevice, BluetoothDevice, BondDevice, BridgeDevice, DummyDevice, EthernetDevice,
GenericDevice, InfinibandDevice, IpTunnelDevice, LoopbackDevice, LowpanDevice, MacsecDevice,
MacvlanDevice, VethDevice, WiFiDevice,
MacvlanDevice, ModemDevice, VethDevice, WiFiDevice,
};
use crate::configs::{Dhcp4Config, Dhcp6Config, Ip4Config, Ip6Config};
use crate::connection::Connection;
Expand Down Expand Up @@ -256,6 +256,7 @@ impl_any!(LowpanDevice<'a>, 'a);
impl_any!(LoopbackDevice<'a>, 'a);
impl_any!(MacsecDevice<'a>, 'a);
impl_any!(MacvlanDevice<'a>, 'a);
impl_any!(ModemDevice<'a>, 'a);
impl_any!(DummyDevice<'a>, 'a);
impl_any!(EthernetDevice<'a>, 'a);
impl_any!(GenericDevice<'a>, 'a);
Expand Down
8 changes: 8 additions & 0 deletions src/devices/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod ipvlan;
mod lowpan;
mod macsec;
mod macvlan;
mod modem;
mod veth;
mod wired;
mod wireless;
Expand All @@ -34,6 +35,7 @@ pub use self::ipvlan::IpVlan;
pub use self::lowpan::Lowpan;
pub use self::macsec::Macsec;
pub use self::macvlan::Macvlan;
pub use self::modem::Modem;
pub use self::veth::Veth;
pub use self::wired::Wired;
pub use self::wireless::Wireless;
Expand All @@ -59,6 +61,7 @@ pub enum Device<'a> {
Loopback(LoopbackDevice<'a>),
Macsec(MacsecDevice<'a>),
Macvlan(MacvlanDevice<'a>),
Modem(ModemDevice<'a>),
Ethernet(EthernetDevice<'a>),
Generic(GenericDevice<'a>),
Bridge(BridgeDevice<'a>),
Expand Down Expand Up @@ -132,6 +135,10 @@ pub struct MacvlanDevice<'a> {
dbus_accessor: DBusAccessor<'a>,
}

pub struct ModemDevice<'a> {
dbus_accessor: DBusAccessor<'a>,
}

pub struct VethDevice<'a> {
dbus_accessor: DBusAccessor<'a>,
}
Expand Down Expand Up @@ -161,6 +168,7 @@ impl<'a> Device<'a> {
DeviceType::Loopback => Ok(Device::Loopback(LoopbackDevice { dbus_accessor })),
DeviceType::Macsec => Ok(Device::Macsec(MacsecDevice { dbus_accessor })),
DeviceType::Macvlan => Ok(Device::Macvlan(MacvlanDevice { dbus_accessor })),
DeviceType::Modem => Ok(Device::Modem(ModemDevice { dbus_accessor })),
DeviceType::Veth => Ok(Device::Veth(VethDevice { dbus_accessor })),
_ => Ok(Device::UnsupportedDevice),
},
Expand Down
60 changes: 60 additions & 0 deletions src/devices/modem.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use num_traits::FromPrimitive;

use super::Error;
use super::ModemDevice;
use crate::gen::OrgFreedesktopNetworkManagerDeviceModem;
use crate::types::NMDeviceModemCapabilities;

/// Modem Device
pub trait Modem {
/// The generic family of access technologies the modem supports.
/// Not all capabilities are available at the same time however;
/// some modems require a firmware reload or other reinitialization
/// to switch between eg CDMA/EVDO and GSM/UMTS.
fn modem_capabilities(&self) -> Result<NMDeviceModemCapabilities, Error>;
/// The generic family of access technologies the modem currently
/// supports without a firmware reload or reinitialization.
fn current_capabilities(&self) -> Result<NMDeviceModemCapabilities, Error>;
/// An identifier used by the modem backend (ModemManager) that aims to
/// uniquely identify the a device. Can be used to match a connection
/// to a particular device.
fn device_id(&self) -> Result<String, Error>;
/// The MCC and MNC (concatenated) of the network the modem is connected to.
/// Blank if disconnected or not a 3GPP modem.
fn operator_code(&self) -> Result<String, Error>;
/// The access point name the modem is connected to.
/// Blank if disconnected.
fn apn(&self) -> Result<String, Error>;
}

impl<'a> Modem for ModemDevice<'a> {
fn modem_capabilities(&self) -> Result<NMDeviceModemCapabilities, Error> {
let cap = proxy!(self).modem_capabilities()?;

match FromPrimitive::from_u32(cap) {
Some(x) => Ok(x),
None => Err(Error::UnsupportedType),
}
}

fn current_capabilities(&self) -> Result<NMDeviceModemCapabilities, Error> {
let cap = proxy!(self).current_capabilities()?;

match FromPrimitive::from_u32(cap) {
Some(x) => Ok(x),
None => Err(Error::UnsupportedType),
}
}

fn device_id(&self) -> Result<String, Error> {
Ok(proxy!(self).device_id()?)
}

fn operator_code(&self) -> Result<String, Error> {
Ok(proxy!(self).operator_code()?)
}

fn apn(&self) -> Result<String, Error> {
Ok(proxy!(self).apn()?)
}
}
16 changes: 9 additions & 7 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,15 @@ pub enum NMBluetoothCapabilities {
NmBtCapabilityNap = 2,
}

// pub enum NMDeviceModemCapabilities {
// NmDeviceModemCapabilityNone = 0,
// NmDeviceModemCapabilityPots = 1,
// NmDeviceModemCapabilityCdmaEvdo = 2,
// NmDeviceModemCapabilityGsmUmts = 4,
// NmDeviceModemCapabilityLte = 8,
// }
#[derive(Debug, FromPrimitive)]
pub enum NMDeviceModemCapabilities {
NmDeviceModemCapabilityNone = 0,
NmDeviceModemCapabilityPots = 0x1,
NmDeviceModemCapabilityCdmaEvdo = 0x2,
NmDeviceModemCapabilityGsmUmts = 0x4,
NmDeviceModemCapabilityLte = 0x8,
NmDeviceModemCapability5GNR = 0x40,
}

// pub enum NMWimaxNspNetworkType {
// NmWimaxNspNetworkTypeUnknown = 0,
Expand Down
Loading