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

See ab_gp_km114_client.h. More...

#include "ab_gp_km114_client.h"
#include "ab_gp_saf_train.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "rte/oal/log/rte_log.h"
#include "km114/km114.h"
Include dependency graph for ab_gp_km114_client.c:

Go to the source code of this file.

Functions

static void handle_install_transport_key (const uint8_t *bytes, size_t len, const char *role_tag, rte_example_site_t site)
static void handle_add_authentication_key (const uint8_t *bytes, size_t len, const char *role_tag, rte_example_site_t site, ab_gp_channel_handle_t handle)
static void install_kmac (const uint8_t kmac[KM114_MAC_KEY_LEN], uint32_t snum, const char *role_tag, rte_example_site_t site, ab_gp_channel_handle_t handle)
static int km114_cross_check (const char *role_tag, rte_example_site_t site)
void ab_gp_km114_client_on_message (const uint8_t *bytes, size_t len, const char *role_tag, rte_example_site_t site, ab_gp_channel_handle_t handle)
 Processes one complete, reassembled Subset-114 message.
int ab_gp_km114_client_on_peer_digest (const uint8_t *payload, size_t size, const char *role_tag, rte_example_site_t site)
 Consumes a PEER_MSG_KIND_KM114_DIGEST frame from the A/B sibling (called from pre_execute.c's own peer-frame dispatch) and cross-checks it against this side's own most recently installed KMAC for the same serial number, in whichever order the two sides' installs and this frame arrive. Logs MATCH/MISMATCH (snum only, never the key); does nothing if size is too short.
static void install_train_link_keys (const km114_kstruct_t *ks, const uint8_t kmac[KM114_MAC_KEY_LEN], const char *role_tag, rte_example_site_t site)
static void send_km114_digest (ab_gp_channel_handle_t handle, uint32_t snum, const uint8_t kmac[KM114_MAC_KEY_LEN])

Variables

static bool s_have_ktrans = false
static uint8_t s_ktrans1 [KM114_MAC_KEY_LEN]
static uint8_t s_ktrans2 [KM114_MAC_KEY_LEN]
static bool s_have_own = false
static uint32_t s_own_snum = 0U
static uint8_t s_own_kmac [KM114_MAC_KEY_LEN]
static bool s_have_peer = false
static uint32_t s_peer_snum = 0U
static uint8_t s_peer_kmac [KM114_MAC_KEY_LEN]

Detailed Description

See ab_gp_km114_client.h.

Definition in file ab_gp_km114_client.c.

Function Documentation

◆ handle_install_transport_key()

void handle_install_transport_key ( const uint8_t * bytes,
size_t len,
const char * role_tag,
rte_example_site_t site )
static

Local function declarations

Definition at line 98 of file ab_gp_km114_client.c.

◆ handle_add_authentication_key()

void handle_add_authentication_key ( const uint8_t * bytes,
size_t len,
const char * role_tag,
rte_example_site_t site,
ab_gp_channel_handle_t handle )
static

Definition at line 147 of file ab_gp_km114_client.c.

◆ install_kmac()

void install_kmac ( const uint8_t kmac[KM114_MAC_KEY_LEN],
uint32_t snum,
const char * role_tag,
rte_example_site_t site,
ab_gp_channel_handle_t handle )
static

Definition at line 223 of file ab_gp_km114_client.c.

◆ km114_cross_check()

int km114_cross_check ( const char * role_tag,
rte_example_site_t site )
static

Compares this side's own most recently installed KMAC against whatever the A/B sibling last sent, when both are known for the SAME serial number - called after either one arrives, so the comparison happens regardless of which side's install or which side's frame gets here first. Logs MATCH/MISMATCH only (snum, never the key). A mismatch is reported, not rebooted on - a free correctness check on top of the vital data path, per the consumption design's own framing, not a new fault path in its own right.

Definition at line 198 of file ab_gp_km114_client.c.

◆ ab_gp_km114_client_on_message()

void ab_gp_km114_client_on_message ( const uint8_t * bytes,
size_t len,
const char * role_tag,
rte_example_site_t site,
ab_gp_channel_handle_t handle )

Processes one complete, reassembled Subset-114 message.

Global functions

Dispatches by the message's own header type:

  • INSTALL_TRANSPORT_KEY: MAC-verified with the library's built-in predefined key (KM114_PREDEFINED_KEY); on success, KTRANS1/KTRANS2 are held in-process for later calls.
  • ADD_AUTHENTICATION_KEY: MAC-verified with the held KTRANS1 (dropped if none is held yet - e.g. arrived before this process's own INSTALL_TRANSPORT_KEY, or after a restart); on success, the K-STRUCT's enc_kmac is decrypted with the held KTRANS2 (km114_decrypt_kmac()) and, if RTE_KM114_KMAC_OUT_FILE is set, written there as 48 lowercase hex characters (Platform_Protocol_SafeComm's own keys.kmac_file convention).
  • Any other message type: logged (type + result where applicable), not otherwise acted on - this workspace has no RBC-side use yet for REPLACE_ALL_KEYS, DELETE_ALL_KEYS, DELETE_KEY or RESPONSE_NOTIF beyond knowing they arrived.

The plaintext key is NEVER written to a log line - only its length/serial number/outcome.

On a successful ADD_AUTHENTICATION_KEY, the decoded KMAC is also cross-checked against the A/B sibling's own independently decoded result (PEER_MSG_KIND_KM114_DIGEST, sent here and consumed via ab_gp_km114_client_on_peer_digest()) - step 3 of the consumption design, a free correctness check, not a new vital-fault path: a mismatch is logged (never the key itself), not rebooted on.

Parameters
bytesThe full reassembled message.
lenIts length.
role_tagThis process's own role tag ("A"/"B"), for log lines.
siteThis process's own site, for log lines.
handleThis channel's own handle, to send the A/B cross-check frame. May be NULL (the cross-check is then skipped, e.g. from a unit test with no live channel).

Definition at line 50 of file ab_gp_km114_client.c.

◆ ab_gp_km114_client_on_peer_digest()

int ab_gp_km114_client_on_peer_digest ( const uint8_t * payload,
size_t size,
const char * role_tag,
rte_example_site_t site )

Consumes a PEER_MSG_KIND_KM114_DIGEST frame from the A/B sibling (called from pre_execute.c's own peer-frame dispatch) and cross-checks it against this side's own most recently installed KMAC for the same serial number, in whichever order the two sides' installs and this frame arrive. Logs MATCH/MISMATCH (snum only, never the key); does nothing if size is too short.

Parameters
payload4-byte snum followed by the 24-byte plaintext KMAC.
sizeLength of payload.
role_tagThis process's own role tag, for log lines.
siteThis process's own site, for log lines.
Returns
1 if this side's own KMAC for the same snum was already known and matched, -1 if it was known and differed, 0 if payload was malformed or this side has no own KMAC for that snum yet (the comparison then happens later, from install_kmac(), once this side installs its own).

Definition at line 82 of file ab_gp_km114_client.c.

◆ install_train_link_keys()

void install_train_link_keys ( const km114_kstruct_t * ks,
const uint8_t kmac[KM114_MAC_KEY_LEN],
const char * role_tag,
rte_example_site_t site )
static

Hands the decoded KMAC to the train-link SaF termination in memory (SAFE_COMM_INTEGRATION.dox, REQ-SC-005), once per entity the K-STRUCT says it is valid with - the SaF layer looks it up by the ETCS identity a train announces in AU1. Logs the count only, never the key.

Definition at line 126 of file ab_gp_km114_client.c.

◆ send_km114_digest()

void send_km114_digest ( ab_gp_channel_handle_t handle,
uint32_t snum,
const uint8_t kmac[KM114_MAC_KEY_LEN] )
static

Sends this side's own decoded KMAC to the A/B sibling for the cross-check (ab_gp_km114_client_on_peer_digest() on the receiving end) - PEER_MSG_KIND_KM114_DIGEST, immediate (not staged), same as the negotiation-level frames this link already carries (SITE_STATE, CHECKPOINT_*): a rare, one-off control event, not this cycle's own decision output.

Definition at line 176 of file ab_gp_km114_client.c.

Variable Documentation

◆ s_have_ktrans

bool s_have_ktrans = false
static

Local makros Local types declarations Local variables declarations

Definition at line 26 of file ab_gp_km114_client.c.

◆ s_ktrans1

uint8_t s_ktrans1[KM114_MAC_KEY_LEN]
static

Definition at line 27 of file ab_gp_km114_client.c.

◆ s_ktrans2

uint8_t s_ktrans2[KM114_MAC_KEY_LEN]
static

Definition at line 28 of file ab_gp_km114_client.c.

◆ s_have_own

bool s_have_own = false
static

Definition at line 33 of file ab_gp_km114_client.c.

◆ s_own_snum

uint32_t s_own_snum = 0U
static

Definition at line 34 of file ab_gp_km114_client.c.

◆ s_own_kmac

uint8_t s_own_kmac[KM114_MAC_KEY_LEN]
static

Definition at line 35 of file ab_gp_km114_client.c.

◆ s_have_peer

bool s_have_peer = false
static

Definition at line 36 of file ab_gp_km114_client.c.

◆ s_peer_snum

uint32_t s_peer_snum = 0U
static

Definition at line 37 of file ab_gp_km114_client.c.

◆ s_peer_kmac

uint8_t s_peer_kmac[KM114_MAC_KEY_LEN]
static

Definition at line 38 of file ab_gp_km114_client.c.