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
transport.c
Go to the documentation of this file.
1
12
13#ifdef SAFECOMM_HAVE_FRAMEWORK
14#include "rte/redundancy/channel_service/rte_channel_service.h"
15
16static safecomm_status_t map_status(rte_status_t status)
17{
18 switch (status)
19 {
20 case RTE_STATUS_OK:
21 return SAFECOMM_STATUS_OK;
22 case RTE_STATUS_TIMEOUT:
24 default:
26 }
27}
28
29static safecomm_status_t channel_send(void *user, const uint8_t *buf, size_t len)
30{
32 rte_status_t status;
33
34 if ((ctx == NULL) || (buf == NULL) || (len == 0U))
35 {
37 }
38 status = rte_channel_service_send((rte_channel_service_t *)ctx->channel, buf, len,
39 (rte_duration_ms_t)ctx->recv_timeout_ms);
40 return map_status(status);
41}
42
43static safecomm_status_t channel_recv(void *user, uint8_t *buf, size_t cap, size_t *out_len)
44{
46 rte_status_t status;
47
48 if ((ctx == NULL) || (buf == NULL) || (cap == 0U) || (out_len == NULL))
49 {
51 }
52 status = rte_channel_service_read_ex((rte_channel_service_t *)ctx->channel, buf, cap,
53 (rte_duration_ms_t)ctx->recv_timeout_ms, out_len);
54 return map_status(status);
55}
56
57static void channel_close(void *user)
58{
59 /* Deliberate no-op: the caller owns and closes the underlying channel - see this
60 * function's own header doc comment. */
61 (void)user;
62}
63
66 void *channel,
67 uint32_t recv_timeout_ms)
68{
69 if ((out == NULL) || (ctx == NULL) || (channel == NULL))
70 {
72 }
73 ctx->channel = channel;
74 ctx->recv_timeout_ms = recv_timeout_ms;
75 out->send = channel_send;
76 out->recv = channel_recv;
77 out->close = channel_close;
78 out->user = ctx;
79 return SAFECOMM_STATUS_OK;
80}
81
82#else /* !SAFECOMM_HAVE_FRAMEWORK */
83
86 void *channel,
87 uint32_t recv_timeout_ms)
88{
89 (void)recv_timeout_ms;
90 if ((out == NULL) || (ctx == NULL) || (channel == NULL))
91 {
93 }
95}
96
97#endif /* SAFECOMM_HAVE_FRAMEWORK */
98
100 const char *host, uint16_t port,
101 uint32_t recv_timeout_ms)
102{
103 (void)port;
104 (void)recv_timeout_ms;
105 if ((out == NULL) || (host == NULL))
106 {
108 }
109 /* TODO(REQ-SC-TRANSPORT-004): open a safeAPIFreamwork channel and wire
110 * send/recv/close/user to it. Genuinely different from
111 * safecomm_transport_from_channel_service() above: this one opens its own bearer from a
112 * host/port, for a peer this library dials itself (e.g. a direct Subset-098 fixed-IP link)
113 * rather than wrapping a channel the caller already manages. */
115}
safecomm_status_t
Result of a Safe Communication Framework operation.
Definition status.h:17
@ SAFECOMM_STATUS_INVALID_PARAM
Definition status.h:19
@ SAFECOMM_STATUS_TIMEOUT
Definition status.h:22
@ SAFECOMM_STATUS_NOT_IMPLEMENTED
Definition status.h:29
@ SAFECOMM_STATUS_OK
Definition status.h:18
@ SAFECOMM_STATUS_TRANSPORT
Definition status.h:23
Caller-owned storage for safecomm_transport_from_channel_service. No dynamic memory (MISRA): the call...
Definition transport.h:84
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
safecomm_transport_close_fn close
Definition transport.h:59
Transport abstraction for the Safe Communication Framework.
safecomm_status_t safecomm_transport_oal_tcp(safecomm_transport_t *out, const char *host, uint16_t port, uint32_t recv_timeout_ms)
Populate out with an OAL/TCP transport built on safeAPIFreamwork.
Definition transport.c:99
safecomm_status_t safecomm_transport_from_channel_service(safecomm_transport_t *out, safecomm_transport_channel_ctx_t *ctx, void *channel, uint32_t recv_timeout_ms)
Populate out with a transport that runs over an already-open, caller-owned Platform_RTE named channel...
Definition transport.c:84