Expand description
Vendor-neutral client for the TR-064 device management protocol.
TR-064 (Broadband Forum) describes a device and its services in UPnP description and SCPD documents, and controls it with SOAP calls. This crate reads those documents and makes the calls. It knows nothing about specific vendors: vendor extensions are services and actions like any other.
§Example
use tr064::{Client, SecretString, Url};
let client = Client::builder(Url::parse("http://192.168.178.1:49000")?)
.credentials("user", SecretString::from("password"))
.build()?;
// The device description lists the services; SCPDs list their actions.
let description = client.description().await?;
let device_info = description.service("DeviceInfo1")?;
let scpd = client.scpd(device_info).await?;
for action in &scpd.actions {
println!("{}", action.name);
}
let out = client.call(device_info, "GetInfo", &[]).await?;
println!("{:?}", out.get("NewSoftwareVersion"));§TLS
Devices usually present a self-signed certificate, so the client does not
check it against certificate authorities. Instead it accepts exactly one
certificate, given by its SHA-256 Fingerprint. Fetch it once with
fetch_fingerprint, have someone confirm it, store it, and
pin it from then on:
use std::time::Duration;
use tr064::{Client, Url};
let url = Url::parse("https://192.168.178.1:49443")?;
let fingerprint = tr064::fetch_fingerprint(&url, Duration::from_secs(5)).await?;
println!("the device presents {fingerprint}");
let client = Client::builder(url).pin(fingerprint).build()?;Plain http works too, but sends everything except the password readable
on the network.
§Errors
The device reports failed actions as UPnP errors with a numeric code. The standard codes are below 800, vendors define their own above:
match client.call(&service, "GetGenericHostEntry", &[("NewIndex", "99")]).await {
Ok(out) => println!("{out:?}"),
Err(error) if error.upnp_code() == Some(713) => println!("no such entry"),
Err(error) => eprintln!("{error}"),
}§Logging
The client logs through tracing: one event
per request at info, the steps of the Digest authentication and the
check of the certificate at debug, and the arguments of action calls at
trace. Passwords, headers, nonces and Digest answers are never logged,
and of other documents only the size. Values of arguments and query
parameters pass a Redact hook, which hides all of them unless the
client is given another one.
The client answers HTTP Digest challenges and reuses the nonce while the
device accepts it. It never retries with credentials the device rejected
(Error::AuthenticationFailed), so that a wrong password does not lock
the account.
Structs§
- Action
- An action of a service.
- Allowed
Range - The allowed range of a numeric
StateVariable, as given in the SCPD. - Argument
- An argument of an
Action. - Arguments
- The output arguments of an action call, in the order the device sent them.
- Client
- A TR-064 client for one device.
- Client
Builder - Configures a
Client. - Device
- A device of a
DeviceDescription. - Device
Description - A parsed device description.
- Fingerprint
- The SHA-256 fingerprint of a certificate.
- Hide
Values - Hides every value: the default
Redacthook. - Scpd
- A parsed SCPD document.
- Service
- A service of a
Device. The URLs are as given in the description, usually paths relative to the address of the device. - State
Variable - A state variable of a service.
- Url
- A parsed URL record.
Enums§
Constants§
- HIDDEN
- What a hidden value is replaced with.
Traits§
- Description
Cache - Keeps the service descriptions (SCPDs) of devices, for a
Clientwith a cache. - Redact
- Decides how the values of requests and responses appear in the log.
Functions§
- fetch_
fingerprint - Connects to
urland returns the fingerprint of the certificate the device presents, to pin it on first use. Sends no credentials.
Type Aliases§
- Secret
String - Secret string type.