tr064/lib.rs
1//! Vendor-neutral client for the TR-064 device management protocol.
2//!
3//! TR-064 (Broadband Forum) describes a device and its services in UPnP
4//! description and SCPD documents, and controls it with SOAP calls. This crate
5//! reads those documents and makes the calls. It knows nothing about specific
6//! vendors: vendor extensions are services and actions like any other.
7//!
8//! # Example
9//!
10//! ```no_run
11//! use tr064::{Client, SecretString, Url};
12//!
13//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
14//! let client = Client::builder(Url::parse("http://192.168.178.1:49000")?)
15//! .credentials("user", SecretString::from("password"))
16//! .build()?;
17//!
18//! // The device description lists the services; SCPDs list their actions.
19//! let description = client.description().await?;
20//! let device_info = description.service("DeviceInfo1")?;
21//! let scpd = client.scpd(device_info).await?;
22//! for action in &scpd.actions {
23//! println!("{}", action.name);
24//! }
25//!
26//! let out = client.call(device_info, "GetInfo", &[]).await?;
27//! println!("{:?}", out.get("NewSoftwareVersion"));
28//! # Ok(())
29//! # }
30//! ```
31//!
32//! # TLS
33//!
34//! Devices usually present a self-signed certificate, so the client does not
35//! check it against certificate authorities. Instead it accepts exactly one
36//! certificate, given by its SHA-256 [`Fingerprint`]. Fetch it once with
37//! [`fetch_fingerprint`], have someone confirm it, store it, and
38//! [pin](ClientBuilder::pin) it from then on:
39//!
40//! ```no_run
41//! use std::time::Duration;
42//! use tr064::{Client, Url};
43//!
44//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
45//! let url = Url::parse("https://192.168.178.1:49443")?;
46//! let fingerprint = tr064::fetch_fingerprint(&url, Duration::from_secs(5)).await?;
47//! println!("the device presents {fingerprint}");
48//! let client = Client::builder(url).pin(fingerprint).build()?;
49//! # Ok(())
50//! # }
51//! ```
52//!
53//! Plain `http` works too, but sends everything except the password readable
54//! on the network.
55//!
56//! # Errors
57//!
58//! The device reports failed actions as UPnP errors with a numeric code. The
59//! standard codes are below 800, vendors define their own above:
60//!
61//! ```no_run
62//! # async fn run(client: tr064::Client, service: tr064::Service) {
63//! match client.call(&service, "GetGenericHostEntry", &[("NewIndex", "99")]).await {
64//! Ok(out) => println!("{out:?}"),
65//! Err(error) if error.upnp_code() == Some(713) => println!("no such entry"),
66//! Err(error) => eprintln!("{error}"),
67//! }
68//! # }
69//! ```
70//!
71//! # Logging
72//!
73//! The client logs through [`tracing`](https://docs.rs/tracing): one event
74//! per request at `info`, the steps of the Digest authentication and the
75//! check of the certificate at `debug`, and the arguments of action calls at
76//! `trace`. Passwords, headers, nonces and Digest answers are never logged,
77//! and of other documents only the size. Values of arguments and query
78//! parameters pass a [`Redact`] hook, which hides all of them unless the
79//! client is given [another one](ClientBuilder::redact).
80//!
81//! The client answers HTTP Digest challenges and reuses the nonce while the
82//! device accepts it. It never retries with credentials the device rejected
83//! ([`Error::AuthenticationFailed`]), so that a wrong password does not lock
84//! the account.
85
86#![warn(missing_docs)]
87
88mod cache;
89mod client;
90mod description;
91mod digest;
92mod error;
93mod logging;
94mod scpd;
95mod soap;
96mod tls;
97mod xml;
98
99pub use cache::DescriptionCache;
100pub use client::{Client, ClientBuilder};
101pub use description::{Device, DeviceDescription, Service};
102pub use error::Error;
103pub use logging::{HIDDEN, HideValues, Redact};
104pub use reqwest::Url;
105pub use scpd::{Action, AllowedRange, Argument, Direction, Scpd, StateVariable};
106pub use secrecy::SecretString;
107pub use soap::Arguments;
108pub use tls::{Fingerprint, fetch_fingerprint};