iec61850-kit 0.8.1

IEC 61850 in Rust: GOOSE and Sampled Values on capture files and live interfaces, an MMS client and server over the full OSI stack, and SCL loading and editing. Panic-free, sans-IO, no_std-capable.
Documentation
//! IEC 61850 for the substation process bus and the station bus.
//!
//! GOOSE and Sampled Values carry protection signals and measurements over Ethernet.
//! The MMS [client] and [server] provide station-bus services over TCP or an
//! application-owned stream. The server loads its data model from SCL.
//!
//! # The shape of it
//!
//! Every protocol core in [`proto`] is *sans-IO*: it owns no socket, spawns no thread and
//! never reads a clock. It takes inputs with the caller's notion of "now", yields outputs,
//! and says when it wants to be called again.
//!
//! ```no_run
//! # // Gated so the example still compiles when the crate is built without `goose`.
//! # #[cfg(feature = "goose")]
//! # mod example {
//! # use iec61850_kit::common::Instant;
//! # use iec61850_kit::proto::goose::{Subscriber, SubscriberConfig, SubscriberEvent, SubscriptionKey};
//! # use iec61850_kit::proto::ethernet::MacAddr;
//! # pub fn run() -> iec61850_kit::Result<()> {
//! # let (frame, now) = (&[][..], Instant::ZERO);
//! let mut sub = Subscriber::new(SubscriberConfig::new(SubscriptionKey {
//!     dst: MacAddr::parse("01-0C-CD-01-00-05")?,
//!     appid: 0x0005,
//!     gocb_ref: "IED1LD0/LLN0$GO$gcbTrip".into(),
//! }));
//!
//! for event in sub.feed(now, frame) {
//!     match event {
//!         // The publisher's data changed.
//!         SubscriberEvent::NewState { st_num, values, .. } => { /* act on `values` */ }
//!         // Nothing arrived within `timeAllowedtoLive`: the inputs are no longer valid.
//!         SubscriberEvent::Expired => { /* fail safe */ }
//!         _ => {}
//!     }
//! }
//! sub.on_timeout(now);
//! let wake_at = sub.next_timeout();
//! # Ok(()) }
//! # }
//! # fn main() {}
//! ```
//!
//! The same code therefore runs under an async runtime, on a bare-metal timer, or inside a
//! deterministic simulation with no I/O at all — and builds `no_std` on an allocator alone.
//!
//! # Modules
//!
//! | Module | What it holds |
//! |---|---|
//! | [`common`] | The types every layer shares: [`UtcTime`], [`Quality`], [`ObjectReference`], [`Fc`], [`MacAddr`], [`Edition`], [`Limits`], and the IEC 61850-7-2 modelling types `TrgOps`, `OptFlds`, `ReasonCode`, [`ControlModel`](common::ControlModel) and [`ServiceType`](common::ServiceType) |
//! | [`ber`] | A panic-free BER codec for the subset IEC 61850 uses |
//! | [`proto`] | The protocol cores: Ethernet framing, MMS `Data`, GOOSE, Sampled Values |
//! | [`proto::sv::SampleLayout`] | What the octets of a sampled-value ASDU mean, read out of the engineering file |
//! | [`proto::osi`] | The OSI stack under MMS: TPKT and its stream reader, COTP class 0 and TSDU reassembly, session, presentation, ACSE (feature `mms`) |
//! | [`proto::mms`] | The MMS PDUs IEC 61850-8-1 uses, sharing their value codec with GOOSE (feature `mms`) |
//! | [`proto::mms::association`] | The association state machine over those six layers, for both roles (feature `mms`) |
//! | [`proto::mms::report`] | What an IEC 61850 report is on the wire, and what `OptFlds` decides (feature `mms`) |
//! | [`proto::mms::control`] | `Oper`, `SBOw`, `Cancel`, `LastApplError` and `AddCause` (feature `mms`) |
//! | [`proto::mms::file`] | `FileName`, `FileAttributes` and `DirectoryEntry` — the MMS file services (feature `mms`) |
//! | [`proto::mms::journal`] | What a log entry is on the wire, and the ranges `QueryLogByTime`/`QueryLogAfterEntry` map onto (feature `mms`) |
//! | [`proto::mms::typespec`] | `TypeSpecification` — what `GetVariableAccessAttributes` answers with (feature `mms`) |
//! | [`client`] | A blocking MMS client: browse, read, write, reporting, control, files, logs, setting groups (feature `client`) |
//! | [`server`] | A blocking MMS server: the SCL file is the namespace, with a report engine, the four control models, setting groups, service tracking, a sandboxed file store and logs (feature `server`) |
//! | [`model`] | The IED model a publisher takes its addresses and data sets from |
//! | [`scl`] | Reading that model out of an ICD, CID or SCD, resolving what an IED subscribes to, and checking the engineering the schema does not (feature `scl`) |
//! | [`pcap`] | Classic capture files, for replaying traffic and recording what was built (feature `pcap`) |
//!
//! # Safety and limits
//!
//! `#![forbid(unsafe_code)]` throughout, and `unwrap`, `expect`, `panic` and slice indexing
//! are denied by lint: a malformed frame becomes an [`Error`] carrying a reason and a byte
//! offset, never a panic. Decoders enforce [`Limits`] — nesting depth, data-set members,
//! primitive length, ASDUs per frame — *before* allocating, and the event queues every core
//! hands its output through are bounded and count what they drop.
//!
//! Allocation tests cover GOOSE retransmissions and steady-state Sampled Values publishing
//! and reception. A GOOSE subscriber allocates owned values on a state change.
//!
//! # Status
//!
//! Minor releases can change the API before 1.0. See the [verification guide](https://hupe1980.github.io/iec61850-kit/docs/verification/)
//! for tested peers, capture results and conformance limits.
//!
//! # Reading the comments
//!
//! Claims about a standard in this crate's documentation carry a tag saying how they were
//! checked: ✅ against a freely available text (an ITU-T recommendation, an RFC, Wireshark's
//! ASN.1 module, a public IEC preview); 🌐 against a public source such as libiec61850 or
//! Wireshark's dissector; ⚠ engineering judgement, not checked against the paywalled IEC text.

#![cfg_attr(not(feature = "std"), no_std)]
// docs.rs uses nightly to display feature requirements.
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(test, allow(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::indexing_slicing, clippy::missing_panics_doc))]
#![forbid(unsafe_code)]
#![warn(missing_docs)]

extern crate alloc;

pub mod ber;
#[cfg(feature = "client")]
pub mod client;
pub mod common;
pub mod model;
#[cfg(feature = "net")]
pub mod net;
#[cfg(feature = "pcap")]
pub mod pcap;
#[cfg(any(feature = "goose", feature = "sv", feature = "mms"))]
pub mod proto;
#[cfg(feature = "scl")]
pub mod scl;
#[cfg(feature = "server")]
pub mod server;

/// The types most callers need, re-exported at the crate root.
pub use common::{Clock, DecodeReason, Edition, Error, Fc, Instant, Limits, MacAddr, ObjectReference, Quality, Result, TimeQuality, UtcTime, Validity};