iec61850_kit/lib.rs
1//! IEC 61850 for the substation process bus and the station bus.
2//!
3//! GOOSE and Sampled Values carry protection signals and measurements over Ethernet.
4//! The MMS [client] and [server] provide station-bus services over TCP or an
5//! application-owned stream. The server loads its data model from SCL.
6//!
7//! # The shape of it
8//!
9//! Every protocol core in [`proto`] is *sans-IO*: it owns no socket, spawns no thread and
10//! never reads a clock. It takes inputs with the caller's notion of "now", yields outputs,
11//! and says when it wants to be called again.
12//!
13//! ```no_run
14//! # // Gated so the example still compiles when the crate is built without `goose`.
15//! # #[cfg(feature = "goose")]
16//! # mod example {
17//! # use iec61850_kit::common::Instant;
18//! # use iec61850_kit::proto::goose::{Subscriber, SubscriberConfig, SubscriberEvent, SubscriptionKey};
19//! # use iec61850_kit::proto::ethernet::MacAddr;
20//! # pub fn run() -> iec61850_kit::Result<()> {
21//! # let (frame, now) = (&[][..], Instant::ZERO);
22//! let mut sub = Subscriber::new(SubscriberConfig::new(SubscriptionKey {
23//! dst: MacAddr::parse("01-0C-CD-01-00-05")?,
24//! appid: 0x0005,
25//! gocb_ref: "IED1LD0/LLN0$GO$gcbTrip".into(),
26//! }));
27//!
28//! for event in sub.feed(now, frame) {
29//! match event {
30//! // The publisher's data changed.
31//! SubscriberEvent::NewState { st_num, values, .. } => { /* act on `values` */ }
32//! // Nothing arrived within `timeAllowedtoLive`: the inputs are no longer valid.
33//! SubscriberEvent::Expired => { /* fail safe */ }
34//! _ => {}
35//! }
36//! }
37//! sub.on_timeout(now);
38//! let wake_at = sub.next_timeout();
39//! # Ok(()) }
40//! # }
41//! # fn main() {}
42//! ```
43//!
44//! The same code therefore runs under an async runtime, on a bare-metal timer, or inside a
45//! deterministic simulation with no I/O at all — and builds `no_std` on an allocator alone.
46//!
47//! # Modules
48//!
49//! | Module | What it holds |
50//! |---|---|
51//! | [`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) |
52//! | [`ber`] | A panic-free BER codec for the subset IEC 61850 uses |
53//! | [`proto`] | The protocol cores: Ethernet framing, MMS `Data`, GOOSE, Sampled Values |
54//! | [`proto::sv::SampleLayout`] | What the octets of a sampled-value ASDU mean, read out of the engineering file |
55//! | [`proto::osi`] | The OSI stack under MMS: TPKT and its stream reader, COTP class 0 and TSDU reassembly, session, presentation, ACSE (feature `mms`) |
56//! | [`proto::mms`] | The MMS PDUs IEC 61850-8-1 uses, sharing their value codec with GOOSE (feature `mms`) |
57//! | [`proto::mms::association`] | The association state machine over those six layers, for both roles (feature `mms`) |
58//! | [`proto::mms::report`] | What an IEC 61850 report is on the wire, and what `OptFlds` decides (feature `mms`) |
59//! | [`proto::mms::control`] | `Oper`, `SBOw`, `Cancel`, `LastApplError` and `AddCause` (feature `mms`) |
60//! | [`proto::mms::file`] | `FileName`, `FileAttributes` and `DirectoryEntry` — the MMS file services (feature `mms`) |
61//! | [`proto::mms::journal`] | What a log entry is on the wire, and the ranges `QueryLogByTime`/`QueryLogAfterEntry` map onto (feature `mms`) |
62//! | [`proto::mms::typespec`] | `TypeSpecification` — what `GetVariableAccessAttributes` answers with (feature `mms`) |
63//! | [`client`] | A blocking MMS client: browse, read, write, reporting, control, files, logs, setting groups (feature `client`) |
64//! | [`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`) |
65//! | [`model`] | The IED model a publisher takes its addresses and data sets from |
66//! | [`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`) |
67//! | [`pcap`] | Classic capture files, for replaying traffic and recording what was built (feature `pcap`) |
68//!
69//! # Safety and limits
70//!
71//! `#![forbid(unsafe_code)]` throughout, and `unwrap`, `expect`, `panic` and slice indexing
72//! are denied by lint: a malformed frame becomes an [`Error`] carrying a reason and a byte
73//! offset, never a panic. Decoders enforce [`Limits`] — nesting depth, data-set members,
74//! primitive length, ASDUs per frame — *before* allocating, and the event queues every core
75//! hands its output through are bounded and count what they drop.
76//!
77//! Allocation tests cover GOOSE retransmissions and steady-state Sampled Values publishing
78//! and reception. A GOOSE subscriber allocates owned values on a state change.
79//!
80//! # Status
81//!
82//! Minor releases can change the API before 1.0. See the [verification guide](https://hupe1980.github.io/iec61850-kit/docs/verification/)
83//! for tested peers, capture results and conformance limits.
84//!
85//! # Reading the comments
86//!
87//! Claims about a standard in this crate's documentation carry a tag saying how they were
88//! checked: ✅ against a freely available text (an ITU-T recommendation, an RFC, Wireshark's
89//! ASN.1 module, a public IEC preview); 🌐 against a public source such as libiec61850 or
90//! Wireshark's dissector; ⚠ engineering judgement, not checked against the paywalled IEC text.
91
92#![cfg_attr(not(feature = "std"), no_std)]
93// docs.rs uses nightly to display feature requirements.
94#![cfg_attr(docsrs, feature(doc_cfg))]
95#![cfg_attr(test, allow(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::indexing_slicing, clippy::missing_panics_doc))]
96#![forbid(unsafe_code)]
97#![warn(missing_docs)]
98
99extern crate alloc;
100
101pub mod ber;
102#[cfg(feature = "client")]
103pub mod client;
104pub mod common;
105pub mod model;
106#[cfg(feature = "net")]
107pub mod net;
108#[cfg(feature = "pcap")]
109pub mod pcap;
110#[cfg(any(feature = "goose", feature = "sv", feature = "mms"))]
111pub mod proto;
112#[cfg(feature = "scl")]
113pub mod scl;
114#[cfg(feature = "server")]
115pub mod server;
116
117/// The types most callers need, re-exported at the crate root.
118pub use common::{Clock, DecodeReason, Edition, Error, Fc, Instant, Limits, MacAddr, ObjectReference, Quality, Result, TimeQuality, UtcTime, Validity};