1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//! IEC 61850 for the substation process bus and the station bus.
//!
//! The **process bus** protocols carry protection signals and instrument-transformer
//! measurements between intelligent electronic devices: **GOOSE** (IEC 61850-8-1) and
//! **Sampled Values** (IEC 61850-9-2, the 9-2LE guideline, and IEC 61869-9). Both run as
//! multicast frames directly over Ethernet, with no transport layer beneath them to absorb a
//! mistake.
//!
//! The **station bus** carries **MMS** (ISO 9506), which IEC 61850-8-1 maps ACSI onto — and
//! the six OSI layers it needs underneath: TPKT, COTP class 0, session, presentation and
//! ACSE. Those are codecs here ([`proto::osi`], [`proto::mms`]), the association state
//! machine over them is [`proto::mms::association`], and there are blocking ends on both
//! sides of it: [`client`] browses, reads, writes, takes decoded and reassembled reports, runs
//! all four control models, pulls files, reads logs and edits setting groups; [`server`] does
//! the other half of every one of those, straight from an SCL file.
//!
//! # 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.
//!
//! Once running, the publishers and the receive path allocate nothing: buffers are cleared
//! and rewritten, never regrown. That is asserted by a counting allocator, not claimed.
//!
//! # Status
//!
//! Pre-1.0. The process bus is tested against real substation captures and, with the `net`
//! feature, on live Linux and macOS interfaces; on the station bus, the six OSI layers, the
//! association over them and both ends above it are verified against a real capture, against
//! `tshark`, against each other over a socket, and against libiec61850's client and server.
//! Applications can supply an established TLS stream to the blocking MMS adapters.
//! Not included: a built-in IEC 62351-3 TLS profile and the IEC 62351-6 authentication extension. The API changes between
//! minor versions, and nothing here has been through a conformance laboratory.
//!
//! The guide at <https://hupe1980.github.io/iec61850-kit/> covers the protocols themselves,
//! and is explicit about what is verified and what is not.
//!
//! # 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.
// docs.rs builds with every feature and on nightly, so each gated item can carry the
// feature that unlocks it. Answering "which feature do I need for this?" from the page
// itself is worth one nightly-only attribute.
extern crate alloc;
/// The types most callers need, re-exported at the crate root.
pub use ;