Skip to main content

Crate ql_qmi

Crate ql_qmi 

Expand description

Pure Rust QMI client for the Quectel AG35.

QMI services on the AG35 are reached through Qualcomm’s IPC router (AF_MSM_IPC). This crate talks to the router directly and replaces Qualcomm’s libqmi_cci.

A Client<S> sends the typed requests of service S and checks their responses. Service crates, such as ql-wds, define these types. A RawClient sends requests from raw TLVs, for example to a service without a crate.

§Example

use ql_qmi::RawClient;
use ql_qmi::codec::TlvWriter;

// MCM ril service, IDL major version 1.
let (client, connection) = RawClient::builder(0x401, 1).connect()?;
tokio::spawn(connection.run());
// Get signal strength. The request has no TLVs.
let response = client.raw_request(0x507, TlvWriter::new()).await?;
for tlv in response.iter() {
    println!("{:#04x}: {:02x?}", tlv.kind, &tlv.value[..]);
}

The client runs on tokio and needs the net and time drivers. It doesn’t spawn tasks. The caller runs the Connection.

§Reconnecting

A Connection fails once the server goes away, for example when the modem restarts. The crate doesn’t reconnect by itself because the new server has none of the state of the old one, such as registrations for indications. Wait for the service, connect again and repeat the setup:

use std::time::Duration;

use ql_qmi::{Error, RawClient, ServiceWatcher};

let mut watcher = ServiceWatcher::new()?;
loop {
    let server = watcher.wait_for(0x401, 1).await?;
    let (client, connection) = match RawClient::builder(0x401, 1).connect_to(server) {
        Ok(connected) => connected,
        Err(Error::Connect { .. }) => {
            // The server is still going away.
            tokio::time::sleep(Duration::from_millis(100)).await;
            continue;
        }
        Err(err) => return Err(err),
    };
    tokio::select! {
        result = connection.run() => {
            if let Err(err) = result {
                eprintln!("connection failed: {err}");
            }
            // Give the router time to remove the old server.
            let removed = watcher.wait_removed(server);
            if let Ok(removed) = tokio::time::timeout(Duration::from_secs(1), removed).await {
                removed?;
            }
        }
        removed = watcher.wait_removed(server) => removed?,
        // Registers for indications and handles them.
        () = serve(&client) => break,
    }
}

The watcher keeps being read, so its messages don’t pile up in the kernel.

§Permissions

Looking up, connecting and watching don’t need a permission. Sending needs a matching security rule. The kernel gives modem services a rule. Sending to one needs effective UID 0 or membership in the group of its rule. This is net_raw (3004) unless /etc/sec_config sets another group. Local services, such as MCM ril (0x401) or ql_manager (0x500), don’t get a rule if they start after irsc_util has run. Every user can send to them.

Modules§

client 🔒
codec
TLV encoding and decoding.
error 🔒
ipc 🔒
Qualcomm IPC router sockets (AF_MSM_IPC), based on linux/msm_ipc.h.
message 🔒
QMI message framing.
server 🔒
service 🔒
status
Result of core QMI responses.
watcher 🔒

Structs§

Client
Client for the QMI service S.
ClientBuilder
Builder for a Client of service S, or for the client C of a service crate.
Connection
Sends the requests of a Client and receives the responses and indications.
Indications
Indications of one type that a client receives.
Instance
Instance of a QMI service.
Message
A QMI message.
RawClient
Untyped client for one QMI service.
RawClientBuilder
Builder for a RawClient.
RequestBuilder
A request that is ready to be sent.
ResponseFuture
Waits for the response to a request.
Server
A QMI server on the IPC router.
ServiceWatcher
Watches the IPC router for QMI servers that are added or removed.

Enums§

Disconnect
Why a Connection failed.
Error
Error returned by QMI operations.
ServiceEvent
A change reported by ServiceWatcher.

Traits§

Service
A QMI service, implemented by a marker type.