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 struct hawkbit_runtime_config {
32 	/** Server address */
33 	char *server_addr;
34 	/** Server port */
35 	uint16_t server_port;
36 	/** Security token */
37 	char *auth_token;
38 	/** TLS tag */
39 	sec_tag_t tls_tag;
40 };
41 
42 /**
43  * @brief Set the hawkBit server configuration settings.
44  *
45  * @param config Configuration settings to set.
46  * @retval 0 on success.
47  * @retval -EAGAIN if probe is currently running.
48  */
49 int hawkbit_set_config(struct hawkbit_runtime_config *config);
50 
51 /**
52  * @brief Get the hawkBit server configuration settings.
53  *
54  * @return Configuration settings.
55  */
56 struct hawkbit_runtime_config hawkbit_get_config(void);
57 
58 /**
59  * @brief Set the hawkBit server address.
60  *
61  * @param addr_str Server address to set.
62  * @retval 0 on success.
63  * @retval -EAGAIN if probe is currently running.
64  */
hawkbit_set_server_addr(char * addr_str)65 static inline int hawkbit_set_server_addr(char *addr_str)
66 {
67 	struct hawkbit_runtime_config set_config = {
68 		.server_addr = addr_str,
69 		.server_port = 0,
70 		.auth_token = NULL,
71 		.tls_tag = 0,
72 	};
73 
74 	return hawkbit_set_config(&set_config);
75 }
76 
77 /**
78  * @brief Set the hawkBit server port.
79  *
80  * @param port Server port to set.
81  * @retval 0 on success.
82  * @retval -EAGAIN if probe is currently running.
83  */
hawkbit_set_server_port(uint16_t port)84 static inline int hawkbit_set_server_port(uint16_t port)
85 {
86 	struct hawkbit_runtime_config set_config = {
87 		.server_addr = NULL,
88 		.server_port = port,
89 		.auth_token = NULL,
90 		.tls_tag = 0,
91 	};
92 
93 	return hawkbit_set_config(&set_config);
94 }
95 
96 /**
97  * @brief Set the hawkBit security token.
98  *
99  * @param token Security token to set.
100  * @retval 0 on success.
101  * @retval -EAGAIN if probe is currently running.
102  */
hawkbit_set_ddi_security_token(char * token)103 static inline int hawkbit_set_ddi_security_token(char *token)
104 {
105 	struct hawkbit_runtime_config set_config = {
106 		.server_addr = NULL,
107 		.server_port = 0,
108 		.auth_token = token,
109 		.tls_tag = 0,
110 	};
111 
112 	return hawkbit_set_config(&set_config);
113 }
114 
115 /**
116  * @brief Set the hawkBit TLS tag
117  *
118  * @param tag TLS tag to set.
119  * @retval 0 on success.
120  * @retval -EAGAIN if probe is currently running.
121  */
hawkbit_set_tls_tag(sec_tag_t tag)122 static inline int hawkbit_set_tls_tag(sec_tag_t tag)
123 {
124 	struct hawkbit_runtime_config set_config = {
125 		.server_addr = NULL,
126 		.server_port = 0,
127 		.auth_token = NULL,
128 		.tls_tag = tag,
129 	};
130 
131 	return hawkbit_set_config(&set_config);
132 }
133 
134 /**
135  * @brief Get the hawkBit server address.
136  *
137  * @return Server address.
138  */
hawkbit_get_server_addr(void)139 static inline char *hawkbit_get_server_addr(void)
140 {
141 	return hawkbit_get_config().server_addr;
142 }
143 
144 /**
145  * @brief Get the hawkBit server port.
146  *
147  * @return Server port.
148  */
hawkbit_get_server_port(void)149 static inline uint16_t hawkbit_get_server_port(void)
150 {
151 	return hawkbit_get_config().server_port;
152 }
153 
154 /**
155  * @brief Get the hawkBit security token.
156  *
157  * @return Security token.
158  */
hawkbit_get_ddi_security_token(void)159 static inline char *hawkbit_get_ddi_security_token(void)
160 {
161 	return hawkbit_get_config().auth_token;
162 }
163 
164 /**
165  * @brief Get the hawkBit TLS tag.
166  *
167  * @return TLS tag.
168  */
hawkbit_get_tls_tag(void)169 static inline sec_tag_t hawkbit_get_tls_tag(void)
170 {
171 	return hawkbit_get_config().tls_tag;
172 }
173 
174 /**
175  * @brief Get the hawkBit action id.
176  *
177  * @return Action id.
178  */
179 int32_t hawkbit_get_action_id(void);
180 
181 /**
182  * @brief Get the hawkBit poll interval.
183  *
184  * @return Poll interval.
185  */
186 uint32_t hawkbit_get_poll_interval(void);
187 
188 /**
189  * @}
190  */
191 
192 #endif /* ZEPHYR_INCLUDE_MGMT_HAWKBIT_CONFIG_H_ */
193