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
Toggle main menu visibility
Loading...
Searching...
No Matches
transport.c
Go to the documentation of this file.
1
11
#include "
safecomm/transport/transport.h
"
12
13
#ifdef SAFECOMM_HAVE_FRAMEWORK
14
#include "rte/redundancy/channel_service/rte_channel_service.h"
15
16
static
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:
23
return
SAFECOMM_STATUS_TIMEOUT
;
24
default
:
25
return
SAFECOMM_STATUS_TRANSPORT
;
26
}
27
}
28
29
static
safecomm_status_t
channel_send(
void
*user,
const
uint8_t *buf,
size_t
len)
30
{
31
safecomm_transport_channel_ctx_t
*ctx = (
safecomm_transport_channel_ctx_t
*)user;
32
rte_status_t status;
33
34
if
((ctx == NULL) || (buf == NULL) || (len == 0U))
35
{
36
return
SAFECOMM_STATUS_INVALID_PARAM
;
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
43
static
safecomm_status_t
channel_recv(
void
*user, uint8_t *buf,
size_t
cap,
size_t
*out_len)
44
{
45
safecomm_transport_channel_ctx_t
*ctx = (
safecomm_transport_channel_ctx_t
*)user;
46
rte_status_t status;
47
48
if
((ctx == NULL) || (buf == NULL) || (cap == 0U) || (out_len == NULL))
49
{
50
return
SAFECOMM_STATUS_INVALID_PARAM
;
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
57
static
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
64
safecomm_status_t
safecomm_transport_from_channel_service
(
safecomm_transport_t
*out,
65
safecomm_transport_channel_ctx_t
*ctx,
66
void
*channel,
67
uint32_t recv_timeout_ms)
68
{
69
if
((out == NULL) || (ctx == NULL) || (channel == NULL))
70
{
71
return
SAFECOMM_STATUS_INVALID_PARAM
;
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
84
safecomm_status_t
safecomm_transport_from_channel_service
(
safecomm_transport_t
*out,
85
safecomm_transport_channel_ctx_t
*ctx,
86
void
*channel,
87
uint32_t recv_timeout_ms)
88
{
89
(void)recv_timeout_ms;
90
if
((out == NULL) || (ctx == NULL) || (channel == NULL))
91
{
92
return
SAFECOMM_STATUS_INVALID_PARAM
;
93
}
94
return
SAFECOMM_STATUS_NOT_IMPLEMENTED
;
95
}
96
97
#endif
/* SAFECOMM_HAVE_FRAMEWORK */
98
99
safecomm_status_t
safecomm_transport_oal_tcp
(
safecomm_transport_t
*out,
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
{
107
return
SAFECOMM_STATUS_INVALID_PARAM
;
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. */
114
return
SAFECOMM_STATUS_NOT_IMPLEMENTED
;
115
}
safecomm_status_t
safecomm_status_t
Result of a Safe Communication Framework operation.
Definition
status.h:17
SAFECOMM_STATUS_INVALID_PARAM
@ SAFECOMM_STATUS_INVALID_PARAM
Definition
status.h:19
SAFECOMM_STATUS_TIMEOUT
@ SAFECOMM_STATUS_TIMEOUT
Definition
status.h:22
SAFECOMM_STATUS_NOT_IMPLEMENTED
@ SAFECOMM_STATUS_NOT_IMPLEMENTED
Definition
status.h:29
SAFECOMM_STATUS_OK
@ SAFECOMM_STATUS_OK
Definition
status.h:18
SAFECOMM_STATUS_TRANSPORT
@ SAFECOMM_STATUS_TRANSPORT
Definition
status.h:23
safecomm_transport_channel_ctx_t
Caller-owned storage for safecomm_transport_from_channel_service. No dynamic memory (MISRA): the call...
Definition
transport.h:84
safecomm_transport_channel_ctx_t::channel
void * channel
Definition
transport.h:85
safecomm_transport_channel_ctx_t::recv_timeout_ms
uint32_t recv_timeout_ms
Definition
transport.h:86
safecomm_transport_t
A consumer-supplied bearer the SaF layer runs over.
Definition
transport.h:56
safecomm_transport_t::send
safecomm_transport_send_fn send
Definition
transport.h:57
safecomm_transport_t::recv
safecomm_transport_recv_fn recv
Definition
transport.h:58
safecomm_transport_t::user
void * user
Definition
transport.h:60
safecomm_transport_t::close
safecomm_transport_close_fn close
Definition
transport.h:59
transport.h
Transport abstraction for the Safe Communication Framework.
safecomm_transport_oal_tcp
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_transport_from_channel_service
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
src
transport
transport.c
Generated by
1.18.0