26#ifndef AB_GP_SAF_TRAIN_H
27#define AB_GP_SAF_TRAIN_H
33#include "safecomm/saf/saf.h"
41#define AB_GP_SAF_ENVELOPE_HEADER 4U
43#define AB_GP_SAF_FRAME_MAX ((size_t)RBC_TRAIN_ENVELOPE_WIRE_SIZE - (size_t)AB_GP_SAF_ENVELOPE_HEADER)
45#define AB_GP_SAF_PDU_MAX (AB_GP_SAF_FRAME_MAX - (size_t)SAFECOMM_SAF_DATA_OVERHEAD)
47#define AB_GP_SAF_PEER_RB_SIZE (1U + SAFECOMM_MAC_RAND_LEN + SAFECOMM_MAC_RAND_LEN)
49#define AB_GP_SAF_KEYS_MAX 16U
56 uint8_t
au1[SAFECOMM_SAF_AU1_LEN];
58 uint8_t
rb_ra[SAFECOMM_MAC_RAND_LEN];
59 uint8_t
rb[SAFECOMM_MAC_RAND_LEN];
86 uint8_t
frame[SAFECOMM_SAF_AU2_LEN];
138 uint8_t *out_frame,
size_t out_cap,
size_t *out_len);
161 const uint8_t **out_frame,
size_t *out_len);
bool ab_gp_saf_envelope_decode(const uint8_t env[RBC_TRAIN_ENVELOPE_WIRE_SIZE], uint8_t *out_train_id, const uint8_t **out_frame, size_t *out_len)
Splits a received RBC_MSG_SAF_ENVELOPE relay frame.
void ab_gp_saf_keys_clear(void)
Empties the KMAC table (process-global, shared by every slot).
void ab_gp_saf_train_on_peer_rb(ab_gp_saf_train_t *s, const uint8_t *payload, size_t size, uint32_t now_ms, ab_gp_saf_result_t *out)
B only: processes A's PEER_MSG_KIND_SAF_RB payload; answers the parked AU1 when its RA matches.
bool ab_gp_saf_envelope_encode(uint8_t train_id, const uint8_t *frame, size_t frame_len, uint8_t out[RBC_TRAIN_ENVELOPE_WIRE_SIZE])
Builds an RBC_MSG_SAF_ENVELOPE relay frame (RBC_TRAIN_ENVELOPE_WIRE_SIZE bytes).
bool ab_gp_saf_train_is_connected(const ab_gp_saf_train_t *s, uint8_t train_id)
True if train slot train_id has a connection in DATA.
bool ab_gp_saf_train_wrap(ab_gp_saf_train_t *s, uint8_t train_id, const uint8_t *pdu, size_t pdu_len, uint8_t *out_frame, size_t out_cap, size_t *out_len)
Protects one outbound application PDU for train slot train_id (only in DATA).
uint32_t ab_gp_saf_train_supervise(ab_gp_saf_train_t *s, uint32_t now_ms)
Idle-link supervision of every connection in DATA (REQ-SC-004).
void ab_gp_saf_train_on_frame(ab_gp_saf_train_t *s, uint8_t train_id, const uint8_t *frame, size_t frame_len, uint32_t now_ms, ab_gp_saf_result_t *out)
Processes one SaF frame received from train slot train_id (1..RTE_EXAMPLE_MAX_TRAINS).
bool ab_gp_saf_keys_load_file(const char *path, uint32_t *out_count)
Loads KMACs from a text file: one "<etcs_id> <48 hex chars>" per line (decimal or 0x identity),...
bool ab_gp_saf_keys_install(uint32_t peer_etcs_id, const uint8_t kmac[SAFECOMM_MAC_KEY_LEN])
Installs (or replaces) the KMAC for one train ETCS identity.
void ab_gp_saf_train_init(ab_gp_saf_train_t *s, bool enabled, bool is_role_a, uint32_t rbc_etcs_id)
Resets s. enabled false makes every other call a no-op / rejection.
#define AB_GP_SAF_PDU_MAX
Largest application PDU (ERTMS codec bytes) one protected frame carries.
ab_gp_saf_action_t
What the caller must do with a processed frame.
@ AB_GP_SAF_ACTION_REJECTED
@ AB_GP_SAF_ACTION_DISCONNECTED
#define AB_GP_SAF_PEER_RB_SIZE
PEER_MSG_KIND_SAF_RB payload: train_id(1) + RA(8) + RB(8).
#define RBC_TRAIN_ENVELOPE_WIRE_SIZE
#define RTE_EXAMPLE_MAX_TRAINS
Output of ab_gp_saf_train_on_frame() / _on_peer_rb().
uint8_t app[AB_GP_SAF_PDU_MAX]
uint8_t frame[SAFECOMM_SAF_AU2_LEN]
uint8_t rb_share[AB_GP_SAF_PEER_RB_SIZE]
ab_gp_saf_action_t action
uint8_t rb_ra[SAFECOMM_MAC_RAND_LEN]
uint8_t au1[SAFECOMM_SAF_AU1_LEN]
uint8_t rb[SAFECOMM_MAC_RAND_LEN]
One channel's train-link SaF termination.
ab_gp_saf_train_slot_t slots[RTE_EXAMPLE_MAX_TRAINS]