Line data Source code
1 1 : /*
2 : * Copyright (c) 2024 Vogl Electronic GmbH
3 : *
4 : * SPDX-License-Identifier: Apache-2.0
5 : */
6 :
7 : /**
8 : * @file
9 : * @brief hawkBit configuration header file
10 : */
11 :
12 : /**
13 : * @brief hawkBit configuration API.
14 : * @defgroup hawkbit_config hawkBit configuration API
15 : * @ingroup hawkbit
16 : * @{
17 : */
18 :
19 : #ifndef ZEPHYR_INCLUDE_MGMT_HAWKBIT_CONFIG_H_
20 : #define ZEPHYR_INCLUDE_MGMT_HAWKBIT_CONFIG_H_
21 :
22 : #include <stdint.h>
23 : #include <zephyr/net/tls_credentials.h>
24 :
25 : /**
26 : * @brief hawkBit configuration structure.
27 : *
28 : * @details This structure is used to store the hawkBit configuration
29 : * settings.
30 : */
31 1 : struct hawkbit_runtime_config {
32 : /**
33 : * Server address (domain name or IP address if
34 : * CONFIG_HAWKBIT_USE_DOMAIN_NAME is enabled)
35 : */
36 1 : char *server_addr;
37 : /** Server domain name */
38 1 : char *server_domain;
39 : /** Server port */
40 1 : uint16_t server_port;
41 : /** Security token */
42 1 : char *auth_token;
43 : /** TLS tag */
44 1 : sec_tag_t tls_tag;
45 : };
46 :
47 : /**
48 : * @brief Set the hawkBit server configuration settings.
49 : *
50 : * @param config Configuration settings to set.
51 : * @retval 0 on success.
52 : * @retval -EAGAIN if probe is currently running.
53 : * @retval -EINVAL if config parameters are invalid.
54 : */
55 1 : int hawkbit_set_config(struct hawkbit_runtime_config *config);
56 :
57 : /**
58 : * @brief Get the hawkBit server configuration settings.
59 : *
60 : * @return Configuration settings.
61 : */
62 1 : struct hawkbit_runtime_config hawkbit_get_config(void);
63 :
64 : /**
65 : * @brief Set the hawkBit server hostname.
66 : *
67 : * @param domain_str Server hostname to set.
68 : * @retval 0 on success.
69 : * @retval -EINVAL if string length mismatch for server_domain
70 : * @retval -EAGAIN if probe is currently running.
71 : */
72 1 : static inline int hawkbit_set_server_domain(char *domain_str)
73 : {
74 : struct hawkbit_runtime_config set_config = {
75 : .server_addr = NULL,
76 : .server_domain = domain_str,
77 : .server_port = 0,
78 : .auth_token = NULL,
79 : .tls_tag = 0,
80 : };
81 :
82 : return hawkbit_set_config(&set_config);
83 : }
84 :
85 : /**
86 : * @brief Set the hawkBit server address.
87 : *
88 : * @param addr_str Server address to set.
89 : * @retval 0 on success.
90 : * @retval -EAGAIN if probe is currently running.
91 : * @retval -EINVAL if config parameters are invalid.
92 : */
93 1 : static inline int hawkbit_set_server_addr(char *addr_str)
94 : {
95 : struct hawkbit_runtime_config set_config = {
96 : .server_addr = addr_str,
97 : .server_domain = NULL,
98 : .server_port = 0,
99 : .auth_token = NULL,
100 : .tls_tag = 0,
101 : };
102 :
103 : return hawkbit_set_config(&set_config);
104 : }
105 :
106 : /**
107 : * @brief Set the hawkBit server port.
108 : *
109 : * @param port Server port to set.
110 : * @retval 0 on success.
111 : * @retval -EAGAIN if probe is currently running.
112 : */
113 1 : static inline int hawkbit_set_server_port(uint16_t port)
114 : {
115 : struct hawkbit_runtime_config set_config = {
116 : .server_addr = NULL,
117 : .server_domain = NULL,
118 : .server_port = port,
119 : .auth_token = NULL,
120 : .tls_tag = 0,
121 : };
122 :
123 : return hawkbit_set_config(&set_config);
124 : }
125 :
126 : /**
127 : * @brief Set the hawkBit security token.
128 : *
129 : * @param token Security token to set.
130 : * @retval 0 on success.
131 : * @retval -EAGAIN if probe is currently running.
132 : */
133 1 : static inline int hawkbit_set_ddi_security_token(char *token)
134 : {
135 : struct hawkbit_runtime_config set_config = {
136 : .server_addr = NULL,
137 : .server_domain = NULL,
138 : .server_port = 0,
139 : .auth_token = token,
140 : .tls_tag = 0,
141 : };
142 :
143 : return hawkbit_set_config(&set_config);
144 : }
145 :
146 : /**
147 : * @brief Set the hawkBit TLS tag
148 : *
149 : * @param tag TLS tag to set.
150 : * @retval 0 on success.
151 : * @retval -EAGAIN if probe is currently running.
152 : */
153 1 : static inline int hawkbit_set_tls_tag(sec_tag_t tag)
154 : {
155 : struct hawkbit_runtime_config set_config = {
156 : .server_addr = NULL,
157 : .server_domain = NULL,
158 : .server_port = 0,
159 : .auth_token = NULL,
160 : .tls_tag = tag,
161 : };
162 :
163 : return hawkbit_set_config(&set_config);
164 : }
165 :
166 : /**
167 : * @brief Get the hawkBit server address.
168 : *
169 : * @return Server address.
170 : */
171 1 : static inline char *hawkbit_get_server_addr(void)
172 : {
173 : return hawkbit_get_config().server_addr;
174 : }
175 :
176 : /**
177 : * @brief Get the hawkBit server hostname.
178 : *
179 : * @return Server hostname.
180 : */
181 1 : static inline char *hawkbit_get_server_domain(void)
182 : {
183 : return hawkbit_get_config().server_domain;
184 : }
185 :
186 : /**
187 : * @brief Get the hawkBit server port.
188 : *
189 : * @return Server port.
190 : */
191 1 : static inline uint16_t hawkbit_get_server_port(void)
192 : {
193 : return hawkbit_get_config().server_port;
194 : }
195 :
196 : /**
197 : * @brief Get the hawkBit security token.
198 : *
199 : * @return Security token.
200 : */
201 1 : static inline char *hawkbit_get_ddi_security_token(void)
202 : {
203 : return hawkbit_get_config().auth_token;
204 : }
205 :
206 : /**
207 : * @brief Get the hawkBit TLS tag.
208 : *
209 : * @return TLS tag.
210 : */
211 1 : static inline sec_tag_t hawkbit_get_tls_tag(void)
212 : {
213 : return hawkbit_get_config().tls_tag;
214 : }
215 :
216 : /**
217 : * @brief Get the hawkBit action id.
218 : *
219 : * @return Action id.
220 : */
221 1 : int32_t hawkbit_get_action_id(void);
222 :
223 : /**
224 : * @brief Get the hawkBit poll interval.
225 : *
226 : * @return Poll interval.
227 : */
228 1 : uint32_t hawkbit_get_poll_interval(void);
229 :
230 : /**
231 : * @}
232 : */
233 :
234 : #endif /* ZEPHYR_INCLUDE_MGMT_HAWKBIT_CONFIG_H_ */
|