36#define SAFECOMM_SAF_MAX_PDU 1024U
39#define SAFECOMM_SAF_AU1_LEN 13U
40#define SAFECOMM_SAF_AU2_LEN 21U
41#define SAFECOMM_SAF_AU3_LEN 9U
42#define SAFECOMM_SAF_AR_LEN 9U
44#define SAFECOMM_SAF_DATA_OVERHEAD 13U
49 SAFECOMM_SAF_FRAME_UNKNOWN = 0,
50 SAFECOMM_SAF_FRAME_AU1,
51 SAFECOMM_SAF_FRAME_AU2,
52 SAFECOMM_SAF_FRAME_AU3,
53 SAFECOMM_SAF_FRAME_DATA,
54 SAFECOMM_SAF_FRAME_DISCONNECT,
68 SAFECOMM_SAF_STATE_IDLE = 0,
69 SAFECOMM_SAF_STATE_WAIT_AU2,
70 SAFECOMM_SAF_STATE_WAIT_AU3,
71 SAFECOMM_SAF_STATE_DATA,
72 SAFECOMM_SAF_STATE_DISCONNECTING
103 bool supervision_armed;
140 const uint8_t *pdu,
size_t pdu_len);
156 uint8_t *out,
size_t out_cap,
size_t *out_len);
206 uint8_t *out_au2,
size_t out_cap,
size_t *out_len);
221 uint8_t *out_ar,
size_t out_cap,
size_t *out_len);
229 uint8_t *out,
size_t out_cap,
size_t *out_len);
240#define SAFECOMM_SAF_DI_LEN 3U
292 uint32_t seq_rx_last_accepted;
296 uint32_t etcs_id_self;
297 uint32_t etcs_id_peer;
329 const uint8_t *pdu,
size_t pdu_len,
330 uint8_t *out_frame,
size_t out_frame_cap,
331 size_t *out_frame_len);
341 const uint8_t *frame,
size_t frame_len);
Message Authentication Code and session-key derivation (ERTMS/ETCS Subset-037-2 §6....
#define SAFECOMM_MAC_RAND_LEN
#define SAFECOMM_MAC_KEY_LEN
safecomm_status_t safecomm_saf_commit_send(safecomm_saf_conn_t *conn, const uint8_t *frame, size_t frame_len)
Transmit an already prepared and cross-compared Sa-DATA frame.
void safecomm_saf_set_time(safecomm_saf_conn_t *conn, uint32_t now_ms)
Orderly Sa-DISCONNECT, then return the object to IDLE.
safecomm_saf_frame_kind_t
Frame kind by its header MTI, for a caller that routes received frames itself.
safecomm_status_t safecomm_saf_connect(safecomm_saf_conn_t *conn)
Run the AU1/AU2/AU3 handshake to completion (blocking).
safecomm_status_t safecomm_saf_responder_on_au3(safecomm_saf_conn_t *conn, const uint8_t *au3, size_t au3_len, uint8_t *out_ar, size_t out_cap, size_t *out_len)
Responder: verify AU3 and build the AR confirmation; the connection enters DATA.
safecomm_status_t safecomm_saf_responder_on_au1(safecomm_saf_conn_t *conn, const uint8_t *au1, size_t au1_len, const uint8_t rb[SAFECOMM_MAC_RAND_LEN], uint8_t *out_au2, size_t out_cap, size_t *out_len)
Responder: accept AU1, derive the session key from RA and the caller's rb, and build AU2.
safecomm_saf_state_t safecomm_saf_state(const safecomm_saf_conn_t *conn)
Current state (for logging / tests). Returns IDLE for NULL.
safecomm_saf_state_t
SaF state-machine state (observable, for logging / tests).
safecomm_status_t safecomm_saf_send(safecomm_saf_conn_t *conn, const uint8_t *pdu, size_t pdu_len)
Send one user PDU as a MAC-protected, sequence-numbered Sa-DATA.
safecomm_status_t safecomm_saf_recv(safecomm_saf_conn_t *conn, uint8_t *out, size_t out_cap, size_t *out_len)
Receive and verify one Sa-DATA PDU (blocking).
safecomm_status_t safecomm_saf_accept_frame(safecomm_saf_conn_t *conn, const uint8_t *frame, size_t frame_len, uint8_t *out, size_t out_cap, size_t *out_len)
Verify one received Sa-DATA or Sa-DISCONNECT frame (the checks of safecomm_saf_recv(),...
safecomm_status_t safecomm_saf_supervise(safecomm_saf_conn_t *conn)
Idle-link supervision (EN 50159 delay and loss): in DATA, if no valid frame arrived for cfg....
safecomm_status_t safecomm_saf_disconnect_frame(safecomm_saf_role_t role, uint8_t *out, size_t out_cap, size_t *out_len)
Build a Sa-DISCONNECT (reason 0, sub-reason 0) for a side of the given role, without any connection s...
safecomm_status_t safecomm_saf_prepare_send(safecomm_saf_conn_t *conn, const uint8_t *pdu, size_t pdu_len, uint8_t *out_frame, size_t out_frame_cap, size_t *out_frame_len)
Prepare and MAC-protect one Sa-DATA frame without transmitting it (for 2oo2 cross-checking).
safecomm_status_t safecomm_saf_au1_fields(const uint8_t *au1, size_t au1_len, uint32_t *out_peer_id, uint8_t out_ra[SAFECOMM_MAC_RAND_LEN])
Read the caller's ETCS identity and initiator random RA out of an AU1 frame (no MAC exists on AU1)....
safecomm_saf_frame_kind_t safecomm_saf_frame_kind(const uint8_t *frame, size_t frame_len)
Classify a received frame by its header MTI (no MAC check).
safecomm_status_t safecomm_saf_frame_sent(safecomm_saf_conn_t *conn)
Record that the caller transmitted the frame from safecomm_saf_prepare_send() itself: advances the se...
safecomm_saf_role_t
SaF connection role.
@ SAFECOMM_SAF_ROLE_RESPONDER
@ SAFECOMM_SAF_ROLE_INITIATOR
safecomm_status_t safecomm_saf_import_session_state(safecomm_saf_conn_t *conn, const safecomm_session_vital_state_t *in_state)
Import vital session state upon warm-standby takeover or channel resynchronization.
safecomm_status_t safecomm_saf_export_session_state(const safecomm_saf_conn_t *conn, safecomm_session_vital_state_t *out_state)
Export vital session state for warm/hot standby synchronization.
safecomm_status_t safecomm_saf_init(safecomm_saf_conn_t *conn, const safecomm_saf_config_t *cfg, const safecomm_transport_t *transport)
Initialise a SaF connection object (no I/O yet).
Common status codes for the Safe Communication Framework.
safecomm_status_t
Result of a Safe Communication Framework operation.
Immutable session-key material for one SaF connection.
Static configuration for one SaF connection.
uint8_t kmac[SAFECOMM_MAC_KEY_LEN]
uint32_t t_supervision_ms
SaF connection object. Caller-allocated, zero-initialised, opaque in practice — fields are not part o...
uint32_t connect_start_ms
Vital session state for 2oo2 hot redundancy and active/warm-standby failover.
A consumer-supplied bearer the SaF layer runs over.
Transport abstraction for the Safe Communication Framework.