Skip to content

Commit 437b27e

Browse files
committed
subsys: mgmt: hawkbit: change hawkbit interface to support ip addresses
Previously, hawkbit interface only supported a url/hostname and a port, and internally it resolves to an IP address. This does not work for network layers that rely on NAT64, like OpenThread. Zephyr's implementation of `getaddrinfo` is not aware of NAT64. DNS will resolve an IPV4 address that needs to be converted to IPV6 with the NAT64 prefix. Instead, this commit alters the Hawkbit interface to allow providing an IP address and hostname as a string, so an application can provide an already resolved IP address if desired. This commit also changes the usage of `hawkbit_runtime_config.server_addr` to point to an IP address, and uses a new variable `hawkbit_runtime_config.server_hostname` for the URL. If `server_addr` is not provided, hawkbit will resolve `server_hostname`. This commit also adds a check for hostname strings that are too long. Previously, hawkbit would simply truncate the hostname and quietly fail to connect. Now it returns an error to the application. This commit also changes how the controllerId is generated based on device id, and disentangles the two. The controllerId is what hawkbit uses to uniquely identify a device, and is not necessarily the same as the device id, and should be fully customizeable by the user if needed. Previously, all custom device ids were being prepended with `CONFIG_BOARD`. When a user selects `CONFIG_HAWKBIT_CUSTOM_DEVICE_ID`, they should be able to specify the full controllerId used with hawkbit. Signed-off-by: Neal Jackson [email protected]
1 parent 78b8733 commit 437b27e

File tree

5 files changed

+131
-54
lines changed

5 files changed

+131
-54
lines changed

include/zephyr/mgmt/hawkbit/config.h

+39-1
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
* settings.
3030
*/
3131
struct hawkbit_runtime_config {
32-
/** Server address */
32+
/** Server ip address */
3333
char *server_addr;
34+
/** Server hostname*/
35+
char *server_hostname;
3436
/** Server port */
3537
uint16_t server_port;
3638
/** Security token */
@@ -44,6 +46,7 @@ struct hawkbit_runtime_config {
4446
*
4547
* @param config Configuration settings to set.
4648
* @retval 0 on success.
49+
* @retval -EINVAL if string length mismatch for server_hostname
4750
* @retval -EAGAIN if probe is currently running.
4851
*/
4952
int hawkbit_set_config(struct hawkbit_runtime_config *config);
@@ -55,6 +58,27 @@ int hawkbit_set_config(struct hawkbit_runtime_config *config);
5558
*/
5659
struct hawkbit_runtime_config hawkbit_get_config(void);
5760

61+
/**
62+
* @brief Set the hawkBit server hostname.
63+
*
64+
* @param hostname_str Server hostname to set.
65+
* @retval 0 on success.
66+
* @retval -EINVAL if string length mismatch for server_hostname
67+
* @retval -EAGAIN if probe is currently running.
68+
*/
69+
static inline int hawkbit_set_server_hostname(char *hostname_str)
70+
{
71+
struct hawkbit_runtime_config set_config = {
72+
.server_addr = NULL,
73+
.server_hostname = hostname_str,
74+
.server_port = 0,
75+
.auth_token = NULL,
76+
.tls_tag = 0,
77+
};
78+
79+
return hawkbit_set_config(&set_config);
80+
}
81+
5882
/**
5983
* @brief Set the hawkBit server address.
6084
*
@@ -66,6 +90,7 @@ static inline int hawkbit_set_server_addr(char *addr_str)
6690
{
6791
struct hawkbit_runtime_config set_config = {
6892
.server_addr = addr_str,
93+
.server_hostname = NULL,
6994
.server_port = 0,
7095
.auth_token = NULL,
7196
.tls_tag = 0,
@@ -85,6 +110,7 @@ static inline int hawkbit_set_server_port(uint16_t port)
85110
{
86111
struct hawkbit_runtime_config set_config = {
87112
.server_addr = NULL,
113+
.server_hostname = NULL,
88114
.server_port = port,
89115
.auth_token = NULL,
90116
.tls_tag = 0,
@@ -104,6 +130,7 @@ static inline int hawkbit_set_ddi_security_token(char *token)
104130
{
105131
struct hawkbit_runtime_config set_config = {
106132
.server_addr = NULL,
133+
.server_hostname = NULL,
107134
.server_port = 0,
108135
.auth_token = token,
109136
.tls_tag = 0,
@@ -123,6 +150,7 @@ static inline int hawkbit_set_tls_tag(sec_tag_t tag)
123150
{
124151
struct hawkbit_runtime_config set_config = {
125152
.server_addr = NULL,
153+
.server_hostname = NULL,
126154
.server_port = 0,
127155
.auth_token = NULL,
128156
.tls_tag = tag,
@@ -141,6 +169,16 @@ static inline char *hawkbit_get_server_addr(void)
141169
return hawkbit_get_config().server_addr;
142170
}
143171

172+
/**
173+
* @brief Get the hawkBit server hostname.
174+
*
175+
* @return Server hostname.
176+
*/
177+
static inline char *hawkbit_get_server_hostname(void)
178+
{
179+
return hawkbit_get_config().server_hostname;
180+
}
181+
144182
/**
145183
* @brief Get the hawkBit server port.
146184
*

samples/subsys/mgmt/hawkbit/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ int main(void)
108108
}
109109

110110
#ifdef CONFIG_HAWKBIT_SET_SETTINGS_RUNTIME
111-
hawkbit_set_server_addr(CONFIG_HAWKBIT_SERVER);
111+
hawkbit_set_server_hostname(CONFIG_HAWKBIT_SERVER);
112112
hawkbit_set_server_port(CONFIG_HAWKBIT_PORT);
113113
#endif
114114

0 commit comments

Comments
 (0)