Skip to content

mmrs: model types #401

@cachebag

Description

@cachebag

define public model types for modemmanager domain.

types

modem state

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum ModemState {
    Failed,
    Unknown,
    Initializing,
    Locked,
    Disabled,
    Enabling,
    Enabled,
    Searching,
    Registered,
    Disconnecting,
    Connecting,
    Connected,
}

map from MM_MODEM_STATE_* constants.

access technology

#[derive(Debug, Clone, Copy)]
pub struct AccessTechnology(u32);

impl AccessTechnology {
    pub fn has_lte(&self) -> bool;
    pub fn has_5g(&self) -> bool;
    pub fn is_3gpp(&self) -> bool;
}

bitflags from MM_MODEM_ACCESS_TECHNOLOGY_*.

modem

#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct Modem {
    pub path: String,
    pub state: ModemState,
    pub manufacturer: String,
    pub model: String,
    pub equipment_identifier: String,  // imei
    pub access_technologies: AccessTechnology,
    pub signal_quality: u32,
    // ...
}

sim

#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct Sim {
    pub path: String,
    pub active: bool,
    pub iccid: String,
    pub imsi: String,
    pub operator_name: String,
}

bearer / bearer config

#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct Bearer {
    pub path: String,
    pub interface: String,
    pub connected: bool,
    pub ip4_config: Option<Ip4Config>,
    pub stats: BearerStats,
}

#[derive(Debug, Clone)]
pub struct BearerConfig {
    pub apn: String,
    pub ip_type: IpType,
    pub user: Option<String>,
    pub password: Option<String>,
    pub allow_roaming: bool,
}

error

#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum ModemError {
    #[error("d-bus error: {0}")]
    Dbus(#[from] zbus::Error),
    
    #[error("no modems found")]
    NoModems,
    
    #[error("sim locked: {0:?}")]
    SimLocked(SimLockState),
    
    #[error("wrong pin")]
    WrongPin,
    
    #[error("bearer creation failed: {0}")]
    BearerCreationFailed(String),
    // ...
}

files

mmrs/src/api/models/
├── mod.rs
├── modem.rs
├── sim.rs
├── bearer.rs
└── error.rs

conventions

  • #[non_exhaustive] on all public structs/enums
  • #[must_use] on builders
  • doc comments with examples

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-surfacePublic API design, re-exports, and semver-relevant changesfeatureNew feature or requestmmrsmodemmanager bindings crate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions