Skip to main content

Crate osdp

Crate osdp 

Source
Expand description

Pure-Rust, no_std-friendly implementation of the SIA OSDP v2.2 protocol.

§Crate features

  • std (default): enables alloc, plus desktop convenience.
  • alloc (default via std): enables alloc::vec::Vec-based codec paths.
  • secure-channel (default): enables Annex D (AES-128, MAC, encryption).
  • embedded-io / embedded-io-async: transport adapters.
  • defmt: structured logging on embedded targets.

§Layering

See architecture for a rendered diagram of how these modules relate.

  • packet — wire framing (SOM, header, SCB, MAC, trailer)
  • command / reply — typed messages
  • multipart — RFC §5.10 multi-part assembly / disassembly
  • secure — Annex D secure channel
  • transport — byte-stream abstraction
  • driver — ACU and PD state machines
  • caps — Annex B function codes

§Quick start

Drive a PD at address 0x05 through one POLL exchange. The example uses transport::VecTransport, so without a peer feeding bytes back the exchange will end in driver::acu::ExchangeOutcome::Timeout — wire it up to a real Transport (or another VecTransport, see examples/loopback_poll.rs) for a successful round-trip.

use osdp::clock::SystemClock;
use osdp::command::{Command, Poll};
use osdp::driver::acu::{Acu, ExchangeOutcome, PdState};
use osdp::reply::Reply;
use osdp::transport::VecTransport;

let mut acu = Acu::new(VecTransport::new(), SystemClock::new());
let mut pd = PdState::default();
match acu.exchange(0x05, &mut pd, &Command::Poll(Poll))? {
    ExchangeOutcome::Reply(Reply::Ack(_)) => { /* PD alive */ }
    ExchangeOutcome::Busy => { /* PD asked us to back off */ }
    ExchangeOutcome::Timeout => { /* no reply within budget */ }
    ExchangeOutcome::Offline => { /* PD declared offline */ }
    _ => {}
}

For the secure-channel walk see examples/handshake.rs; for an end-to-end loopback that exercises SQN cycling see examples/loopback_poll.rs.

§Specification cross-references

All spec citations refer to SIA OSDP v2.2 (©2020 Security Industry Association). Where an item maps directly onto a spec section it is noted in the docs as # Spec: §X.Y.

Re-exports§

pub use error::Error;
pub use error::Result;
pub use packet::Address;
pub use packet::ControlByte;
pub use packet::ParsedPacket;
pub use packet::Sqn;
pub use packet::Trailer;
pub use packet::Packet;alloc

Modules§

architecture
Crate architecture diagram.
caps
PD capability function codes.
clock
Time abstraction. Drivers take a Clock so that timing logic is testable from no_std targets without pulling in a runtime.
commandalloc
Typed OSDP commands (ACU → PD).
driveralloc
Higher-level drivers built atop the codec and transport.
error
Crate-wide error type. core::error::Error-compatible.
multipartalloc
Multi-part message engine.
packet
Packet codec — framing, header, security control block, MAC, trailer.
replyalloc
Typed OSDP replies (PD → ACU). See sibling crate::command.
securealloc and secure-channel
Secure Channel — Annex D.
transport
Transport abstraction. The driver works against any half-duplex byte stream that exposes Transport::write_all and Transport::read.

Constants§

BROADCAST_ADDR
Broadcast address.
MAX_BUS_PACKET
Maximum packet length that any device must tolerate on the wire (even if addressed elsewhere).
MAX_PD_ADDR
Largest legal PD unicast address.
MIN_RX_SIZE
Minimum receive-buffer size every PD must support.
OFFLINE_THRESHOLD_MS
Off-line declaration threshold.
REPLY_DELAY_MS
Default ACU reply-delay budget.
REPLY_FLAG
Reply flag set in Address when sent from PD to ACU.
SOM
Start of message marker — begins every OSDP packet header.