Safe API Framework
0.1.0 build 384e6ae
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Toggle main menu visibility
Loading...
Searching...
No Matches
rte_netlink.c
Go to the documentation of this file.
1
8
#include "
rte/oal/netlink/rte_netlink.h
"
9
#include "
rte/utils/lifecycle/rte_lifecycle.h
"
10
#include "
rte_osadapter/netlink/rte_osadapter_netlink.h
"
11
13
15
18
static
const
rte_osadapter_netlink_t
*
s_osadapter
= NULL;
19
21
23
24
26
rte_status_t
rte_osadapter_netlink_register
(
const
rte_osadapter_netlink_t
*osadapter)
27
{
28
rte_status_t
lifecycle_status;
29
30
if
(osadapter == NULL)
31
{
32
return
RTE_STATUS_INVALID_PARAM
;
33
}
34
/* REQ-LIFECYCLE-001 (ADR-026): registering an OSAdapter is a setup-only
35
* action - refuse once the application's setup phase has been locked. */
36
lifecycle_status =
rte_lifecycle_check_setup_allowed
();
37
if
(lifecycle_status !=
RTE_STATUS_OK
)
38
{
39
return
lifecycle_status;
40
}
41
s_osadapter
= osadapter;
42
return
RTE_STATUS_OK
;
43
}
44
45
rte_status_t
rte_netlink_open
(rte_netlink_storage_t *storage,
46
const
rte_netlink_config_t
*config,
47
rte_netlink_handle_t
*out_handle)
48
{
49
if
((storage == NULL) || (config == NULL) || (out_handle == NULL))
50
{
51
return
RTE_STATUS_INVALID_PARAM
;
52
}
53
if
(config->
message_size
== 0U)
54
{
55
return
RTE_STATUS_INVALID_PARAM
;
56
}
57
if
((config->
role
==
RTE_NETLINK_ROLE_CONNECT
) && (config->
host
== NULL))
58
{
59
return
RTE_STATUS_INVALID_PARAM
;
60
}
61
*out_handle = NULL;
62
if
(
s_osadapter
== NULL)
63
{
64
return
RTE_STATUS_NOT_INITIALIZED
;
65
}
66
if
(
s_osadapter
->open == NULL)
67
{
68
return
RTE_STATUS_NOT_SUPPORTED
;
69
}
70
return
s_osadapter
->open(storage, config, out_handle);
71
}
72
73
rte_status_t
rte_netlink_send
(
rte_netlink_handle_t
handle,
74
const
void
*message,
75
size_t
message_size,
76
rte_duration_ms_t
timeout_ms)
77
{
78
if
((handle == NULL) || (message == NULL) || (message_size == 0U))
79
{
80
return
RTE_STATUS_INVALID_PARAM
;
81
}
82
if
(
s_osadapter
== NULL)
83
{
84
return
RTE_STATUS_NOT_INITIALIZED
;
85
}
86
if
(
s_osadapter
->send == NULL)
87
{
88
return
RTE_STATUS_NOT_SUPPORTED
;
89
}
90
return
s_osadapter
->send(handle, message, message_size, timeout_ms);
91
}
92
93
rte_status_t
rte_netlink_receive
(
rte_netlink_handle_t
handle,
94
void
*out_message,
95
size_t
buffer_size,
96
rte_duration_ms_t
timeout_ms)
97
{
98
if
((handle == NULL) || (out_message == NULL) || (buffer_size == 0U))
99
{
100
return
RTE_STATUS_INVALID_PARAM
;
101
}
102
if
(
s_osadapter
== NULL)
103
{
104
return
RTE_STATUS_NOT_INITIALIZED
;
105
}
106
if
(
s_osadapter
->receive == NULL)
107
{
108
return
RTE_STATUS_NOT_SUPPORTED
;
109
}
110
return
s_osadapter
->receive(handle, out_message, buffer_size, timeout_ms);
111
}
112
113
rte_status_t
rte_netlink_close
(
rte_netlink_handle_t
handle)
114
{
115
if
(handle == NULL)
116
{
117
return
RTE_STATUS_INVALID_PARAM
;
118
}
119
if
(
s_osadapter
== NULL)
120
{
121
return
RTE_STATUS_NOT_INITIALIZED
;
122
}
123
if
(
s_osadapter
->close == NULL)
124
{
125
return
RTE_STATUS_NOT_SUPPORTED
;
126
}
127
return
s_osadapter
->close(handle);
128
}
rte_lifecycle_check_setup_allowed
rte_status_t rte_lifecycle_check_setup_allowed(void)
Convenience check for a setup-only constructor: call this as one of the first checks in any function ...
Definition
rte_lifecycle.c:41
rte_netlink_handle_t
struct rte_netlink_impl_s * rte_netlink_handle_t
Opaque handle to an established link, returned by rte_netlink_open().
Definition
rte_netlink.h:58
rte_netlink_open
rte_status_t rte_netlink_open(rte_netlink_storage_t *storage, const rte_netlink_config_t *config, rte_netlink_handle_t *out_handle)
Establishes a point-to-point link: binds+accepts (LISTEN) or dials (CONNECT), per config->role.
Definition
rte_netlink.c:45
rte_netlink_close
rte_status_t rte_netlink_close(rte_netlink_handle_t handle)
Closes a link.
Definition
rte_netlink.c:113
rte_netlink_send
rte_status_t rte_netlink_send(rte_netlink_handle_t handle, const void *message, size_t message_size, rte_duration_ms_t timeout_ms)
Sends one fixed-size message, blocking at most timeout_ms.
Definition
rte_netlink.c:73
rte_netlink_receive
rte_status_t rte_netlink_receive(rte_netlink_handle_t handle, void *out_message, size_t buffer_size, rte_duration_ms_t timeout_ms)
Receives one fixed-size message, blocking at most timeout_ms.
Definition
rte_netlink.c:93
RTE_NETLINK_ROLE_CONNECT
@ RTE_NETLINK_ROLE_CONNECT
Definition
rte_netlink.h:72
rte_status_t
rte_status_t
Common result/status codes.
Definition
rte_status.h:27
RTE_STATUS_OK
@ RTE_STATUS_OK
Definition
rte_status.h:28
RTE_STATUS_INVALID_PARAM
@ RTE_STATUS_INVALID_PARAM
Definition
rte_status.h:29
RTE_STATUS_NOT_SUPPORTED
@ RTE_STATUS_NOT_SUPPORTED
Definition
rte_status.h:34
RTE_STATUS_NOT_INITIALIZED
@ RTE_STATUS_NOT_INITIALIZED
Definition
rte_status.h:30
rte_duration_ms_t
uint32_t rte_duration_ms_t
Definition
rte_types.h:27
s_osadapter
static const rte_osadapter_clocksync_t * s_osadapter
Definition
rte_clocksync.c:18
rte_lifecycle.h
Process-wide application setup-phase lock (ADR-026).
rte_netlink.h
OS Abstraction Layer - Point-to-point network link service.
rte_osadapter_netlink.h
OSAdapter interface for point-to-point network links.
rte_osadapter_netlink_register
rte_status_t rte_osadapter_netlink_register(const rte_osadapter_netlink_t *adapter)
Registers the OSAdapter network link implementation.
Definition
rte_netlink.c:26
rte_netlink_config_t
Configuration for rte_netlink_open().
Definition
rte_netlink.h:77
rte_netlink_config_t::message_size
size_t message_size
Definition
rte_netlink.h:87
rte_netlink_config_t::host
const char * host
Definition
rte_netlink.h:83
rte_netlink_config_t::role
rte_netlink_role_t role
Definition
rte_netlink.h:79
rte_osadapter_netlink_t
OSAdapter network link operations vtable.
Definition
rte_osadapter_netlink.h:23
src
oal
netlink
rte_netlink.c
Generated by
1.18.0