Skip to main content

Crate ql_uim

Crate ql_uim 

Expand description

Rust client for Qualcomm’s QMI User Identity Module Service (UIM).

UIM (QMI service 0x0B) reports the state of the SIM cards and reads their files. This crate covers the card status with its indication, and reading transparent files. Iccid and Imsi decode the two files that identify a SIM.

EVA and EVD firmware share these messages. The crate only uses fields that both have. EVA has IDL version 1.61 and EVD has 1.86.

§Example

use std::error::Error;

use ql_uim::{Client, Slot};

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn Error>> {
    let (client, connection) = Client::builder().connect()?;
    tokio::spawn(connection.run());
    let status = client.card_status().await?;
    println!("{:?}", status.primary_gw_app());
    println!("ICCID: {}", client.read_iccid(Slot::One).await?);
    println!("IMSI: {}", client.read_imsi().await?);
    Ok(())
}

Client has a method for every request of this crate. Each request method returns the request, so you can set a timeout with .timeout() before you await it. Client::qmi returns the typed ql_qmi::Client for custom requests. Client::read_imsi sends two requests and uses the client timeout for both.

§Indications

Client::event_reg makes the modem send a StatusChange when the card status changes. Client::events receives them. Subscribe before you enable them, otherwise the first ones are lost. Other UIM indications are not decoded.

use std::error::Error;

use ql_uim::{Client, EventReg};

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn Error>> {
    let (client, connection) = Client::builder().connect()?;
    tokio::spawn(connection.run());
    let mut events = client.events()?;
    client.event_reg(&EventReg { card_status: true }).await?;
    loop {
        let change = events.next().await?;
        println!("{:?}", change.card_status);
    }
}

§Card state

The modem can report a card as absent while it doesn’t know the state of the card. Card::status_known is then Some(false).

§Sessions and paths

A file read specifies a session. The ICCID is read with the card session of the slot, because it doesn’t need an application. The IMSI is read with the primary GSM or UMTS provisioning session. Files are addressed by an ID and the path of directory IDs that lead to them. A path ID is a 16-bit word. 0x3F00 is the master file.

The client runs on tokio. See ql_qmi for the runtime and permission requirements.

Modules§

card 🔒
client 🔒
ef 🔒
error 🔒
event 🔒
event_reg 🔒
read 🔒
types 🔒

Structs§

App
An application on a card (app_info_type_v01).
AppIndex
Position of an application in a CardStatus.
AppState
State of an application (uim_app_state_enum_v01).
AppType
Type of an application on the card (uim_app_type_enum_v01).
Card
A card slot (card_info_type_v01).
CardErrorCode
Reason a card is not usable (uim_card_error_code_enum_v01).
CardResult
Status word of a card command (uim_card_result_type_v01).
CardState
State of a card slot (uim_card_state_enum_v01).
CardStatus
Card status (uim_card_status_type_v01).
Client
Client of the UIM service.
EventReg
Sets which indications the modem sends (QMI_UIM_EVENT_REG).
File
File to access (uim_file_id_type_v01).
GetCardStatus
Reads the status of all card slots (QMI_UIM_GET_CARD_STATUS).
Iccid
ICCID of a SIM card.
Imsi
IMSI of a SIM application.
PersoFeature
Personalization feature (uim_perso_feature_status_enum_v01).
PersoState
Personalization state of an application (uim_perso_state_enum_v01).
PinInfo
State and retry counters of a PIN (uim_pin_info_type_v01).
PinState
State of a PIN (uim_pin_state_enum_v01).
ReadTransparent
Reads a transparent file (QMI_UIM_READ_TRANSPARENT).
RegisteredEvents
Indications that the modem enabled.
Session
Session of a request (uim_session_information_type_v01).
SessionType
Kind of session (uim_session_type_enum_v01).
StatusChange
A card status change (QMI_UIM_STATUS_CHANGE_IND).
Transparent
Content of a transparent file.
Uim
Marker of the UIM service for ql_qmi::Client.
UnivPin
Whether the universal PIN replaces PIN1 (uim_univ_pin_enum_v01).

Enums§

EfError
Error from decoding the content of an elementary file.
Error
Error returned by UIM operations.
Slot
SIM card slot.