RTE RBC 2oo2 Reference Application 0.1.0 build 0006685
SIL 4 2oo2 Dual-Site Fault-Tolerant ERTMS Radio Block Centre Reference Architecture
Loading...
Searching...
No Matches
ab_gp_saf_train.h
Go to the documentation of this file.
1
26#ifndef AB_GP_SAF_TRAIN_H
27#define AB_GP_SAF_TRAIN_H
28
29#include <stdbool.h>
30#include <stddef.h>
31#include <stdint.h>
32
33#include "safecomm/saf/saf.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
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
50
52typedef struct
53{
54 safecomm_saf_conn_t conn;
56 uint8_t au1[SAFECOMM_SAF_AU1_LEN];
57 bool rb_parked;
58 uint8_t rb_ra[SAFECOMM_MAC_RAND_LEN];
59 uint8_t rb[SAFECOMM_MAC_RAND_LEN];
61
70
80
82typedef struct
83{
85 safecomm_status_t status;
86 uint8_t frame[SAFECOMM_SAF_AU2_LEN];
87 size_t frame_len;
89 size_t app_len;
90 bool share_rb;
93
95void ab_gp_saf_keys_clear(void);
96
101bool ab_gp_saf_keys_install(uint32_t peer_etcs_id, const uint8_t kmac[SAFECOMM_MAC_KEY_LEN]);
102
112bool ab_gp_saf_keys_load_file(const char *path, uint32_t *out_count);
113
117void ab_gp_saf_train_init(ab_gp_saf_train_t *s, bool enabled, bool is_role_a, uint32_t rbc_etcs_id);
118
123void ab_gp_saf_train_on_frame(ab_gp_saf_train_t *s, uint8_t train_id, const uint8_t *frame, size_t frame_len,
124 uint32_t now_ms, ab_gp_saf_result_t *out);
125
129void ab_gp_saf_train_on_peer_rb(ab_gp_saf_train_t *s, const uint8_t *payload, size_t size, uint32_t now_ms,
130 ab_gp_saf_result_t *out);
131
137bool ab_gp_saf_train_wrap(ab_gp_saf_train_t *s, uint8_t train_id, const uint8_t *pdu, size_t pdu_len,
138 uint8_t *out_frame, size_t out_cap, size_t *out_len);
139
144uint32_t ab_gp_saf_train_supervise(ab_gp_saf_train_t *s, uint32_t now_ms);
145
147bool ab_gp_saf_train_is_connected(const ab_gp_saf_train_t *s, uint8_t train_id);
148
153bool ab_gp_saf_envelope_encode(uint8_t train_id, const uint8_t *frame, size_t frame_len,
154 uint8_t out[RBC_TRAIN_ENVELOPE_WIRE_SIZE]);
155
160bool ab_gp_saf_envelope_decode(const uint8_t env[RBC_TRAIN_ENVELOPE_WIRE_SIZE], uint8_t *out_train_id,
161 const uint8_t **out_frame, size_t *out_len);
162
163#ifdef __cplusplus
164}
165#endif
166
167#endif /* AB_GP_SAF_TRAIN_H */
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_APP
@ AB_GP_SAF_ACTION_REPLY
@ AB_GP_SAF_ACTION_DISCONNECTED
@ AB_GP_SAF_ACTION_NONE
#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().
safecomm_status_t status
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
Per-train-slot state.
uint8_t rb_ra[SAFECOMM_MAC_RAND_LEN]
uint8_t au1[SAFECOMM_SAF_AU1_LEN]
safecomm_saf_conn_t conn
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]