huawei_dongle_api/lib.rs
1//! # Huawei LTE Dongle API
2//!
3//! A robust async Rust client library for interacting with Huawei LTE dongles and routers.
4//!
5//! This library provides a type-safe, async interface to the XML-based API used by Huawei HiLink
6//! devices such as the E3372, E5577, B525 and many others. It handles authentication, session
7//! management, and CSRF token rotation automatically.
8//!
9//! ## Features
10//!
11//! - **Async/await** - Built on tokio for efficient async I/O
12//! - **Automatic retry** - Configurable retry logic with exponential backoff
13//! - **Session management** - Automatic CSRF token handling and refresh
14//! - **Type safety** - Strongly typed requests and responses
15//! - **Error handling** - Comprehensive error types with automatic recovery
16//! - **Device compatibility** - Handles quirks across different firmware versions
17//!
18//! ## Quick Start
19//!
20//! ```no_run
21//! use huawei_dongle_api::{Client, Config};
22//!
23//! #[tokio::main]
24//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
25//! // Create a client with default config
26//! let client = Client::new(Config::default())?;
27//!
28//! // Get device information (no auth required)
29//! let device_info = client.device().information().await?;
30//! println!("Device: {}", device_info.device_name);
31//!
32//! // Check connection status (auth required - handled automatically)
33//! let status = client.monitoring().status().await?;
34//! println!("Connected: {}", status.is_connected());
35//!
36//! Ok(())
37//! }
38//! ```
39//!
40//! ## Authentication
41//!
42//! Most read operations don't require authentication, but monitoring status, SMS operations,
43//! and configuration changes do. The library handles authentication automatically if no user/password is set:
44//!
45//! ```no_run
46//! # use huawei_dongle_api::{Client, Config};
47//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
48//! let client = Client::new(Config::default())?;
49//!
50//! // Login (only needed for password-protected operations)
51//! client.auth().login("admin", "password").await?;
52//!
53//! // Now you can access protected endpoints
54//! use huawei_dongle_api::models::{SmsListRequest, SmsBoxType, SmsSortType};
55//! let request = SmsListRequest::new(1, 20, SmsBoxType::LocalInbox, SmsSortType::ByTime, false, true);
56//! let sms_list = client.sms().list(&request).await?;
57//!
58//! // Logout when done
59//! client.auth().logout().await?;
60//! # Ok(())
61//! # }
62//! ```
63//!
64//! ## Configuration
65//!
66//! The client can be configured with custom timeouts, retry policies, and base URLs:
67//!
68//! ```no_run
69//! use huawei_dongle_api::{Client, Config};
70//! use std::time::Duration;
71//!
72//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
73//! let config = Config::builder()
74//! .base_url("http://192.168.8.1")
75//! .timeout(Duration::from_secs(30))
76//! .max_retries(5)
77//! .retry_delay(Duration::from_millis(500))
78//! .build();
79//!
80//! let client = Client::new(config?)?;
81//! # Ok(())
82//! # }
83//! ```
84//!
85//! ## Error Handling
86//!
87//! The library provides detailed error types and handles common issues automatically:
88//!
89//! - CSRF token expiry - automatically refreshes and retries
90//! - Session timeout - re-authenticates if needed
91//! - Network errors - retries with exponential backoff
92//! - Device quirks - handles different response formats
93//!
94//! ## Supported APIs
95//!
96//! - **Device** - Information, reboot, power control
97//! - **Monitoring** - Connection status, signal strength, network info
98//! - **SMS** - List, send, delete messages
99//! - **Network** - Mode selection, operator info, signal details
100//! - **DHCP** - IP configuration, DNS settings
101//! - **Authentication** - Login/logout, password encoding
102
103pub mod auth;
104pub mod client;
105pub mod config;
106pub mod error;
107pub mod retry;
108pub mod session;
109
110pub mod api;
111pub mod models;
112
113pub use client::Client;
114pub use config::Config;
115pub use error::{Error, Result};