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.c File Reference

Train link SaF termination in A/B - see ab_gp_saf_train.h. More...

#include "ab_gp_saf_train.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "rte/oal/random/rte_random.h"
#include "safecomm/euroradio/euroradio.h"
#include "../../common/rbc_wire_types.h"
Include dependency graph for ab_gp_saf_train.c:

Go to the source code of this file.

Data Structures

struct  saf_key_t

Macros

#define AB_GP_SAF_ETY_RBC   1U

Functions

static safecomm_status_t no_send (void *user, const uint8_t *buf, size_t len)
static safecomm_status_t no_recv (void *user, uint8_t *buf, size_t cap, size_t *out_len)
static const saf_key_t * key_lookup (uint32_t peer_etcs_id)
static ab_gp_saf_train_slot_t * slot_of (ab_gp_saf_train_t *s, uint8_t train_id)
static void reject (ab_gp_saf_result_t *out, safecomm_status_t status)
static void respond_au1 (ab_gp_saf_train_t *s, ab_gp_saf_train_slot_t *slot, const uint8_t *au1, const uint8_t *rb, uint32_t now_ms, ab_gp_saf_result_t *out)
void ab_gp_saf_keys_clear (void)
 Empties the KMAC table (process-global, shared by every slot).
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.
static int hex_nibble (char c)
static bool parse_key_line (char *line, uint32_t *out_id, uint8_t out_kmac[SAFECOMM_MAC_KEY_LEN])
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), '#' comments and blank lines ignored - the same format the train simulator reads. A provisioning path for test environments and tools; in service the KM114 client installs keys (REQ-SC-005: no key compiled in).
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.
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).
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_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).
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_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_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.

Variables

static saf_key_t s_keys [AB_GP_SAF_KEYS_MAX]

Detailed Description

Train link SaF termination in A/B - see ab_gp_saf_train.h.

Definition in file ab_gp_saf_train.c.

Macro Definition Documentation

◆ AB_GP_SAF_ETY_RBC

#define AB_GP_SAF_ETY_RBC   1U

Subset-037-2 Table 8: ETCS ID type of an RBC.

Definition at line 16 of file ab_gp_saf_train.c.

Function Documentation

◆ no_send()

safecomm_status_t no_send ( void * user,
const uint8_t * buf,
size_t len )
static

Definition at line 27 of file ab_gp_saf_train.c.

◆ no_recv()

safecomm_status_t no_recv ( void * user,
uint8_t * buf,
size_t cap,
size_t * out_len )
static

Definition at line 35 of file ab_gp_saf_train.c.

◆ key_lookup()

const saf_key_t * key_lookup ( uint32_t peer_etcs_id)
static

Definition at line 44 of file ab_gp_saf_train.c.

◆ slot_of()

ab_gp_saf_train_slot_t * slot_of ( ab_gp_saf_train_t * s,
uint8_t train_id )
static

Definition at line 62 of file ab_gp_saf_train.c.

◆ reject()

void reject ( ab_gp_saf_result_t * out,
safecomm_status_t status )
static

Definition at line 71 of file ab_gp_saf_train.c.

◆ respond_au1()

void respond_au1 ( ab_gp_saf_train_t * s,
ab_gp_saf_train_slot_t * slot,
const uint8_t * au1,
const uint8_t * rb,
uint32_t now_ms,
ab_gp_saf_result_t * out )
static

Definition at line 78 of file ab_gp_saf_train.c.

◆ ab_gp_saf_keys_clear()

void ab_gp_saf_keys_clear ( void )

Empties the KMAC table (process-global, shared by every slot).

Definition at line 122 of file ab_gp_saf_train.c.

◆ ab_gp_saf_keys_install()

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.

Returns
false if the table is full or kmac is NULL.

Definition at line 127 of file ab_gp_saf_train.c.

◆ hex_nibble()

int hex_nibble ( char c)
static

Definition at line 160 of file ab_gp_saf_train.c.

◆ parse_key_line()

bool parse_key_line ( char * line,
uint32_t * out_id,
uint8_t out_kmac[SAFECOMM_MAC_KEY_LEN] )
static

Definition at line 178 of file ab_gp_saf_train.c.

◆ ab_gp_saf_keys_load_file()

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), '#' comments and blank lines ignored - the same format the train simulator reads. A provisioning path for test environments and tools; in service the KM114 client installs keys (REQ-SC-005: no key compiled in).

Parameters
pathfile to read. Non-NULL.
out_countreceives the number of keys installed. Non-NULL.
Returns
false if the file cannot be opened, any line is malformed, or the table is full (keys read before the failing line stay installed; the caller treats false as a fatal configuration error).

Definition at line 211 of file ab_gp_saf_train.c.

◆ ab_gp_saf_train_init()

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.

Definition at line 258 of file ab_gp_saf_train.c.

◆ ab_gp_saf_train_on_frame()

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).

Parameters
now_msmonotonic milliseconds (the channel's cycle clock) for the connect budget and supervision.

Definition at line 270 of file ab_gp_saf_train.c.

◆ ab_gp_saf_train_on_peer_rb()

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.

Definition at line 377 of file ab_gp_saf_train.c.

◆ ab_gp_saf_train_wrap()

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).

Returns
true with the frame in out_frame; false if there is no connection in DATA or the PDU does not fit - the caller must then not send the message unprotected.

Definition at line 414 of file ab_gp_saf_train.c.

◆ ab_gp_saf_train_supervise()

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).

Returns
bit (train_id - 1) set for each train whose link was declared lost by this call.

Definition at line 431 of file ab_gp_saf_train.c.

◆ ab_gp_saf_train_is_connected()

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.

Definition at line 456 of file ab_gp_saf_train.c.

◆ ab_gp_saf_envelope_encode()

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).

Returns
false if frame_len exceeds AB_GP_SAF_FRAME_MAX or an argument is invalid.

Definition at line 466 of file ab_gp_saf_train.c.

◆ ab_gp_saf_envelope_decode()

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.

Returns
false if the kind, train slot or length is invalid.

Definition at line 482 of file ab_gp_saf_train.c.

Variable Documentation

◆ s_keys

saf_key_t s_keys[AB_GP_SAF_KEYS_MAX]
static

Definition at line 25 of file ab_gp_saf_train.c.