Safe Communication Framework 0.1.0 build feea4f9
ERTMS/ETCS safe communication (Subset-037 EuroRadio, Subset-098 RBC/RBC), CENELEC EN 50128 SIL 4 oriented
Loading...
Searching...
No Matches
cfm.c
Go to the documentation of this file.
1
8#include "safecomm/cfm/cfm.h"
9
10#include <string.h>
11
13 const safecomm_transport_t *lower,
14 safecomm_cfm_t *out)
15{
16 const char *profile;
17 uint32_t u;
19
20 if ((cfg == NULL) || (lower == NULL) || (out == NULL)
21 || (lower->send == NULL) || (lower->recv == NULL))
22 {
24 }
25 (void)memset(out, 0, sizeof(*out));
26 out->lower = *lower;
27
28 profile = safecomm_config_get_str(cfg, "cfm.profile");
29 if (profile == NULL)
30 {
32 }
33 if (strcmp(profile, "euroradio") == 0)
34 {
35 out->profile = SAFECOMM_CFM_PROFILE_EURORADIO;
36 }
37 else if (strcmp(profile, "rbc_rbc") == 0)
38 {
39 out->profile = SAFECOMM_CFM_PROFILE_RBC_RBC;
40 }
41 else
42 {
44 }
45
46 {
47 const char *host = safecomm_config_get_str(cfg, "cfm.peer_host");
48 if ((host != NULL) && (strlen(host) < sizeof(out->peer_host)))
49 {
50 (void)strcpy(out->peer_host, host);
51 }
52 }
53 st = safecomm_config_get_u32(cfg, "cfm.peer_port", &u);
54 if ((st == SAFECOMM_STATUS_OK) && (u <= 0xFFFFU))
55 {
56 out->peer_port = (uint16_t)u;
57 }
58 st = safecomm_config_get_u32(cfg, "cfm.bind_port", &u);
59 if ((st == SAFECOMM_STATUS_OK) && (u <= 0xFFFFU))
60 {
61 out->bind_port = (uint16_t)u;
62 }
63 st = safecomm_config_get_u32(cfg, "cfm.retry_ms", &out->retry_ms);
64 (void)st;
65
66 /* TODO(REQ-SC-CFM-003): finish once the bearer state machine exists. */
68}
69
71{
72 if ((cfm == NULL) || (out == NULL))
73 {
75 }
76 /* TODO(REQ-SC-CFM-008): wrap cfm->lower with framing + keep-alive +
77 * reconnect and hand the SFM whole-PDU send/recv. */
79}
Communication Functional Module (CFM).
safecomm_status_t safecomm_cfm_transport(safecomm_cfm_t *cfm, safecomm_transport_t *out)
Expose the CFM to the SFM above it as a transport.
Definition cfm.c:70
safecomm_status_t safecomm_cfm_from_config(const safecomm_config_t *cfg, const safecomm_transport_t *lower, safecomm_cfm_t *out)
Build a CFM from a loaded config (cfm.* keys).
Definition cfm.c:12
@ SAFECOMM_CFM_PROFILE_EURORADIO
Definition cfm.h:38
@ SAFECOMM_CFM_PROFILE_RBC_RBC
Definition cfm.h:39
const char * safecomm_config_get_str(const safecomm_config_t *cfg, const char *key)
Raw string value for key.
Definition config.c:141
safecomm_status_t safecomm_config_get_u32(const safecomm_config_t *cfg, const char *key, uint32_t *out)
Unsigned-integer value for key.
Definition config.c:159
safecomm_status_t
Result of a Safe Communication Framework operation.
Definition status.h:17
@ SAFECOMM_STATUS_INVALID_PARAM
Definition status.h:19
@ SAFECOMM_STATUS_NOT_IMPLEMENTED
Definition status.h:29
@ SAFECOMM_STATUS_OK
Definition status.h:18
A CFM instance. Caller-allocated, opaque.
Definition cfm.h:44
safecomm_transport_t lower
Definition cfm.h:50
A loaded configuration file. Caller-allocated, opaque in use.
Definition config.h:66
A consumer-supplied bearer the SaF layer runs over.
Definition transport.h:56
safecomm_transport_send_fn send
Definition transport.h:57
safecomm_transport_recv_fn recv
Definition transport.h:58