21
21
#include <zephyr/mgmt/hawkbit/hawkbit.h>
22
22
#include <zephyr/mgmt/hawkbit/config.h>
23
23
#include <zephyr/mgmt/hawkbit/event.h>
24
- #include <zephyr/net/dns_resolve.h>
25
24
#include <zephyr/net/http/client.h>
26
25
#include <zephyr/net/net_ip.h>
27
26
#include <zephyr/net/net_mgmt.h>
@@ -75,10 +74,19 @@ static bool hawkbit_initialized;
75
74
76
75
#endif /* CONFIG_HAWKBIT_DDI_NO_SECURITY */
77
76
77
+ #ifdef CONFIG_DNS_RESOLVER_MAX_QUERY_LEN
78
+ #define SERVER_DOMAIN_LEN CONFIG_DNS_RESOLVER_MAX_QUERY_LEN
79
+ #else
80
+ #define SERVER_DOMAIN_LEN 255
81
+ #endif
82
+
78
83
static struct hawkbit_config {
79
84
int32_t action_id ;
80
85
#ifdef CONFIG_HAWKBIT_SET_SETTINGS_RUNTIME
81
86
char server_addr [DNS_MAX_NAME_SIZE + 1 ];
87
+ #ifdef CONFIG_HAWKBIT_USE_DOMAIN_NAME
88
+ char server_domain [SERVER_DOMAIN_LEN + 1 ];
89
+ #endif
82
90
char server_port [sizeof (STRINGIFY (__UINT16_MAX__ ))];
83
91
#ifndef CONFIG_HAWKBIT_DDI_NO_SECURITY
84
92
char ddi_security_token [DDI_SECURITY_TOKEN_SIZE + 1 ];
@@ -90,11 +98,17 @@ static struct hawkbit_config {
90
98
} hb_cfg ;
91
99
92
100
#ifdef CONFIG_HAWKBIT_SET_SETTINGS_RUNTIME
93
- #define HAWKBIT_SERVER hb_cfg.server_addr
101
+ #ifdef CONFIG_HAWKBIT_USE_DOMAIN_NAME
102
+ #define HAWKBIT_SERVER_DOMAIN hb_cfg.server_domain
103
+ #else
104
+ #define HAWKBIT_SERVER_DOMAIN hb_cfg.server_addr
105
+ #endif /* CONFIG_HAWKBIT_USE_DOMAIN_NAME */
106
+ #define HAWKBIT_SERVER_ADDR hb_cfg.server_addr
94
107
#define HAWKBIT_PORT hb_cfg.server_port
95
108
#define HAWKBIT_PORT_INT atoi(hb_cfg.server_port)
96
109
#else
97
- #define HAWKBIT_SERVER CONFIG_HAWKBIT_SERVER
110
+ #define HAWKBIT_SERVER_ADDR CONFIG_HAWKBIT_SERVER
111
+ #define HAWKBIT_SERVER_DOMAIN CONFIG_HAWKBIT_SERVER
98
112
#define HAWKBIT_PORT STRINGIFY(CONFIG_HAWKBIT_PORT)
99
113
#define HAWKBIT_PORT_INT CONFIG_HAWKBIT_PORT
100
114
#endif /* CONFIG_HAWKBIT_SET_SETTINGS_RUNTIME */
@@ -298,6 +312,22 @@ static int hawkbit_settings_set(const char *name, size_t len, settings_read_cb r
298
312
return rc ;
299
313
}
300
314
315
+ #ifdef CONFIG_HAWKBIT_USE_DOMAIN_NAME
316
+ if (settings_name_steq (name , "server_domain" , & next ) && !next ) {
317
+ if (len != sizeof (hb_cfg .server_domain )) {
318
+ return - EINVAL ;
319
+ }
320
+
321
+ rc = read_cb (cb_arg , & hb_cfg .server_domain , sizeof (hb_cfg .server_domain ));
322
+ LOG_DBG ("<%s> = %s" , "hawkbit/server_domain" , hb_cfg .server_domain );
323
+ if (rc >= 0 ) {
324
+ return 0 ;
325
+ }
326
+
327
+ return rc ;
328
+ }
329
+ #endif /* CONFIG_HAWKBIT_USE_DOMAIN_NAME */
330
+
301
331
if (settings_name_steq (name , "server_port" , & next ) && !next ) {
302
332
if (len != sizeof (uint16_t )) {
303
333
return - EINVAL ;
@@ -336,6 +366,9 @@ static int hawkbit_settings_set(const char *name, size_t len, settings_read_cb r
336
366
}
337
367
#else /* CONFIG_HAWKBIT_SET_SETTINGS_RUNTIME */
338
368
if (settings_name_steq (name , "server_addr" , NULL ) ||
369
+ #ifdef CONFIG_HAWKBIT_USE_DOMAIN_NAME
370
+ settings_name_steq (name , "server_domain" , NULL ) ||
371
+ #endif /* CONFIG_HAWKBIT_USE_DOMAIN_NAME */
339
372
settings_name_steq (name , "server_port" , NULL ) ||
340
373
settings_name_steq (name , "ddi_token" , NULL )) {
341
374
rc = read_cb (cb_arg , NULL , 0 );
@@ -359,6 +392,9 @@ static int hawkbit_settings_export(int (*cb)(const char *name, const void *value
359
392
(void )cb ("hawkbit/action_id" , & hb_cfg .action_id , sizeof (hb_cfg .action_id ));
360
393
#ifdef CONFIG_HAWKBIT_SET_SETTINGS_RUNTIME
361
394
(void )cb ("hawkbit/server_addr" , & hb_cfg .server_addr , sizeof (hb_cfg .server_addr ));
395
+ #ifdef CONFIG_HAWKBIT_USE_DOMAIN_NAME
396
+ (void )cb ("hawkbit/server_domain" , & hb_cfg .server_domain , sizeof (hb_cfg .server_domain ));
397
+ #endif /* CONFIG_HAWKBIT_USE_DOMAIN_NAME */
362
398
uint16_t hawkbit_port = atoi (hb_cfg .server_port );
363
399
(void )cb ("hawkbit/server_port" , & hawkbit_port , sizeof (hawkbit_port ));
364
400
#ifndef CONFIG_HAWKBIT_DDI_NO_SECURITY
@@ -439,7 +475,7 @@ static bool start_http_client(int *hb_sock)
439
475
}
440
476
441
477
while (resolve_attempts -- ) {
442
- ret = zsock_getaddrinfo (HAWKBIT_SERVER , HAWKBIT_PORT , & hints , & addr );
478
+ ret = zsock_getaddrinfo (HAWKBIT_SERVER_ADDR , HAWKBIT_PORT , & hints , & addr );
443
479
if (ret == 0 ) {
444
480
break ;
445
481
}
@@ -469,8 +505,8 @@ static bool start_http_client(int *hb_sock)
469
505
goto err_sock ;
470
506
}
471
507
472
- if (zsock_setsockopt (* hb_sock , SOL_TLS , TLS_HOSTNAME , HAWKBIT_SERVER ,
473
- sizeof (CONFIG_HAWKBIT_SERVER )) < 0 ) {
508
+ if (zsock_setsockopt (* hb_sock , SOL_TLS , TLS_HOSTNAME , HAWKBIT_SERVER_DOMAIN ,
509
+ sizeof (HAWKBIT_SERVER_DOMAIN )) < 0 ) {
474
510
goto err_sock ;
475
511
}
476
512
#endif /* CONFIG_HAWKBIT_USE_TLS */
@@ -778,12 +814,27 @@ int hawkbit_default_config_data_cb(const char *device_id, uint8_t *buffer, const
778
814
#ifdef CONFIG_HAWKBIT_SET_SETTINGS_RUNTIME
779
815
int hawkbit_set_config (struct hawkbit_runtime_config * config )
780
816
{
817
+ size_t length ;
818
+
781
819
if (k_sem_take (& probe_sem , HAWKBIT_SET_SERVER_TIMEOUT ) == 0 ) {
782
820
if (config -> server_addr != NULL ) {
783
821
strncpy (hb_cfg .server_addr , config -> server_addr ,
784
822
sizeof (hb_cfg .server_addr ));
785
823
LOG_DBG ("configured %s: %s" , "hawkbit/server_addr" , hb_cfg .server_addr );
786
824
}
825
+ #ifdef CONFIG_HAWKBIT_USE_DOMAIN_NAME
826
+ if (config -> server_domain != NULL ) {
827
+ length = strnlen (config -> server_domain , CONFIG_DNS_RESOLVER_MAX_QUERY_LEN + 1 );
828
+ if (length > CONFIG_DNS_RESOLVER_MAX_QUERY_LEN ) {
829
+ LOG_ERR ("%s too long: %s" , "hawkbit/server_domain" , config -> server_domain );
830
+ return - EINVAL ;
831
+ }
832
+ strncpy (hb_cfg .server_domain , config -> server_domain ,
833
+ sizeof (hb_cfg .server_domain ));
834
+ LOG_DBG ("configured %s: %s" , "hawkbit/server_domain" ,
835
+ hb_cfg .server_domain );
836
+ }
837
+ #endif /* CONFIG_HAWKBIT_USE_DOMAIN_NAME */
787
838
if (config -> server_port != 0 ) {
788
839
snprintf (hb_cfg .server_port , sizeof (hb_cfg .server_port ), "%u" ,
789
840
config -> server_port );
@@ -817,7 +868,7 @@ int hawkbit_set_config(struct hawkbit_runtime_config *config)
817
868
struct hawkbit_runtime_config hawkbit_get_config (void )
818
869
{
819
870
struct hawkbit_runtime_config config = {
820
- .server_addr = HAWKBIT_SERVER ,
871
+ .server_addr = HAWKBIT_SERVER_ADDR ,
821
872
.server_port = HAWKBIT_PORT_INT ,
822
873
.auth_token = HAWKBIT_DDI_SECURITY_TOKEN ,
823
874
.tls_tag = HAWKBIT_CERT_TAG ,
@@ -1041,7 +1092,7 @@ static bool send_request(struct hawkbit_context *hb_context, enum hawkbit_http_r
1041
1092
#endif /* CONFIG_HAWKBIT_DDI_NO_SECURITY */
1042
1093
1043
1094
http_req .url = url_buffer ;
1044
- http_req .host = HAWKBIT_SERVER ;
1095
+ http_req .host = HAWKBIT_SERVER_DOMAIN ;
1045
1096
http_req .port = HAWKBIT_PORT ;
1046
1097
http_req .protocol = "HTTP/1.1" ;
1047
1098
http_req .response = response_cb ;
@@ -1155,7 +1206,7 @@ void hawkbit_reboot(void)
1155
1206
1156
1207
static bool check_hawkbit_server (void )
1157
1208
{
1158
- if (strlen (HAWKBIT_SERVER ) == 0 ) {
1209
+ if (strlen (HAWKBIT_SERVER_ADDR ) == 0 ) {
1159
1210
if (sizeof (CONFIG_HAWKBIT_SERVER ) > 1 ) {
1160
1211
hawkbit_set_server_addr (CONFIG_HAWKBIT_SERVER );
1161
1212
} else {
0 commit comments