@@ -79,6 +79,9 @@ static struct hawkbit_config {
79
79
int32_t action_id ;
80
80
#ifdef CONFIG_HAWKBIT_SET_SETTINGS_RUNTIME
81
81
char server_addr [DNS_MAX_NAME_SIZE + 1 ];
82
+ #ifdef CONFIG_HAWKBIT_USE_DOMAIN_NAME
83
+ char server_domain [CONFIG_DNS_RESOLVER_MAX_QUERY_LEN + 1 ];
84
+ #endif
82
85
char server_port [sizeof (STRINGIFY (__UINT16_MAX__ ))];
83
86
#ifndef CONFIG_HAWKBIT_DDI_NO_SECURITY
84
87
char ddi_security_token [DDI_SECURITY_TOKEN_SIZE + 1 ];
@@ -90,11 +93,18 @@ static struct hawkbit_config {
90
93
} hb_cfg ;
91
94
92
95
#ifdef CONFIG_HAWKBIT_SET_SETTINGS_RUNTIME
93
- #define HAWKBIT_SERVER hb_cfg.server_addr
96
+ #ifdef CONFIG_HAWKBIT_USE_DOMAIN_NAME
97
+ #define HAWKBIT_SERVER_DOMAIN hb_cfg.server_domain
98
+ #define HAWKBIT_SERVER_ADDR hb_cfg.server_addr
99
+ #else
100
+ #define HAWKBIT_SERVER_ADDR hb_cfg.server_addr
101
+ #define HAWKBIT_SERVER_DOMAIN hb_cfg.server_addr
102
+ #endif /* CONFIG_HAWKBIT_USE_DOMAIN_NAME */
94
103
#define HAWKBIT_PORT hb_cfg.server_port
95
104
#define HAWKBIT_PORT_INT atoi(hb_cfg.server_port)
96
105
#else
97
- #define HAWKBIT_SERVER CONFIG_HAWKBIT_SERVER
106
+ #define HAWKBIT_SERVER_ADDR CONFIG_HAWKBIT_SERVER
107
+ #define HAWKBIT_SERVER_DOMAIN CONFIG_HAWKBIT_SERVER
98
108
#define HAWKBIT_PORT STRINGIFY(CONFIG_HAWKBIT_PORT)
99
109
#define HAWKBIT_PORT_INT CONFIG_HAWKBIT_PORT
100
110
#endif /* CONFIG_HAWKBIT_SET_SETTINGS_RUNTIME */
@@ -298,6 +308,22 @@ static int hawkbit_settings_set(const char *name, size_t len, settings_read_cb r
298
308
return rc ;
299
309
}
300
310
311
+ #ifdef CONFIG_HAWKBIT_USE_DOMAIN_NAME
312
+ if (settings_name_steq (name , "server_domain" , & next ) && !next ) {
313
+ if (len != sizeof (hb_cfg .server_domain )) {
314
+ return - EINVAL ;
315
+ }
316
+
317
+ rc = read_cb (cb_arg , & hb_cfg .server_domain , sizeof (hb_cfg .server_domain ));
318
+ LOG_DBG ("<%s> = %s" , "hawkbit/server_domain" , hb_cfg .server_domain );
319
+ if (rc >= 0 ) {
320
+ return 0 ;
321
+ }
322
+
323
+ return rc ;
324
+ }
325
+ #endif /* CONFIG_HAWKBIT_USE_DOMAIN_NAME */
326
+
301
327
if (settings_name_steq (name , "server_port" , & next ) && !next ) {
302
328
if (len != sizeof (uint16_t )) {
303
329
return - EINVAL ;
@@ -336,6 +362,9 @@ static int hawkbit_settings_set(const char *name, size_t len, settings_read_cb r
336
362
}
337
363
#else /* CONFIG_HAWKBIT_SET_SETTINGS_RUNTIME */
338
364
if (settings_name_steq (name , "server_addr" , NULL ) ||
365
+ #ifdef CONFIG_HAWKBIT_USE_DOMAIN_NAME
366
+ settings_name_steq (name , "server_domain" , NULL ) ||
367
+ #endif /* CONFIG_HAWKBIT_USE_DOMAIN_NAME */
339
368
settings_name_steq (name , "server_port" , NULL ) ||
340
369
settings_name_steq (name , "ddi_token" , NULL )) {
341
370
rc = read_cb (cb_arg , NULL , 0 );
@@ -359,6 +388,9 @@ static int hawkbit_settings_export(int (*cb)(const char *name, const void *value
359
388
(void )cb ("hawkbit/action_id" , & hb_cfg .action_id , sizeof (hb_cfg .action_id ));
360
389
#ifdef CONFIG_HAWKBIT_SET_SETTINGS_RUNTIME
361
390
(void )cb ("hawkbit/server_addr" , & hb_cfg .server_addr , sizeof (hb_cfg .server_addr ));
391
+ #ifdef CONFIG_HAWKBIT_USE_DOMAIN_NAME
392
+ (void )cb ("hawkbit/server_domain" , & hb_cfg .server_domain , sizeof (hb_cfg .server_domain ));
393
+ #endif /* CONFIG_HAWKBIT_USE_DOMAIN_NAME */
362
394
uint16_t hawkbit_port = atoi (hb_cfg .server_port );
363
395
(void )cb ("hawkbit/server_port" , & hawkbit_port , sizeof (hawkbit_port ));
364
396
#ifndef CONFIG_HAWKBIT_DDI_NO_SECURITY
@@ -439,7 +471,7 @@ static bool start_http_client(int *hb_sock)
439
471
}
440
472
441
473
while (resolve_attempts -- ) {
442
- ret = zsock_getaddrinfo (HAWKBIT_SERVER , HAWKBIT_PORT , & hints , & addr );
474
+ ret = zsock_getaddrinfo (HAWKBIT_SERVER_ADDR , HAWKBIT_PORT , & hints , & addr );
443
475
if (ret == 0 ) {
444
476
break ;
445
477
}
@@ -469,8 +501,8 @@ static bool start_http_client(int *hb_sock)
469
501
goto err_sock ;
470
502
}
471
503
472
- if (zsock_setsockopt (* hb_sock , SOL_TLS , TLS_HOSTNAME , HAWKBIT_SERVER ,
473
- sizeof (CONFIG_HAWKBIT_SERVER )) < 0 ) {
504
+ if (zsock_setsockopt (* hb_sock , SOL_TLS , TLS_HOSTNAME , HAWKBIT_SERVER_DOMAIN ,
505
+ sizeof (HAWKBIT_SERVER_DOMAIN )) < 0 ) {
474
506
goto err_sock ;
475
507
}
476
508
#endif /* CONFIG_HAWKBIT_USE_TLS */
@@ -778,12 +810,27 @@ int hawkbit_default_config_data_cb(const char *device_id, uint8_t *buffer, const
778
810
#ifdef CONFIG_HAWKBIT_SET_SETTINGS_RUNTIME
779
811
int hawkbit_set_config (struct hawkbit_runtime_config * config )
780
812
{
781
- if (k_sem_take (& probe_sem , HAWKBIT_SET_SERVER_TIMEOUT ) == 0 ) {
813
+ size_t length ;
814
+
815
+ if (k_sem_take (& probe_sem , HAWKBIT_SET_SERVER_TIMEOUT ) == 0 ) {
782
816
if (config -> server_addr != NULL ) {
783
817
strncpy (hb_cfg .server_addr , config -> server_addr ,
784
818
sizeof (hb_cfg .server_addr ));
785
819
LOG_DBG ("configured %s: %s" , "hawkbit/server_addr" , hb_cfg .server_addr );
786
820
}
821
+ #ifdef CONFIG_HAWKBIT_USE_DOMAIN_NAME
822
+ if (config -> server_domain != NULL ) {
823
+ length = strnlen (config -> server_domain , CONFIG_DNS_RESOLVER_MAX_QUERY_LEN + 1 );
824
+ if (length > CONFIG_DNS_RESOLVER_MAX_QUERY_LEN ) {
825
+ LOG_ERR ("%s too long: %s" , "hawkbit/server_domain" , config -> server_domain );
826
+ return - EINVAL ;
827
+ }
828
+ strncpy (hb_cfg .server_domain , config -> server_domain ,
829
+ sizeof (hb_cfg .server_domain ));
830
+ LOG_DBG ("configured %s: %s" , "hawkbit/server_domain" ,
831
+ hb_cfg .server_domain );
832
+ }
833
+ #endif /* CONFIG_HAWKBIT_USE_DOMAIN_NAME */
787
834
if (config -> server_port != 0 ) {
788
835
snprintf (hb_cfg .server_port , sizeof (hb_cfg .server_port ), "%u" ,
789
836
config -> server_port );
@@ -817,7 +864,7 @@ int hawkbit_set_config(struct hawkbit_runtime_config *config)
817
864
struct hawkbit_runtime_config hawkbit_get_config (void )
818
865
{
819
866
struct hawkbit_runtime_config config = {
820
- .server_addr = HAWKBIT_SERVER ,
867
+ .server_addr = HAWKBIT_SERVER_ADDR ,
821
868
.server_port = HAWKBIT_PORT_INT ,
822
869
.auth_token = HAWKBIT_DDI_SECURITY_TOKEN ,
823
870
.tls_tag = HAWKBIT_CERT_TAG ,
@@ -1041,7 +1088,7 @@ static bool send_request(struct hawkbit_context *hb_context, enum hawkbit_http_r
1041
1088
#endif /* CONFIG_HAWKBIT_DDI_NO_SECURITY */
1042
1089
1043
1090
http_req .url = url_buffer ;
1044
- http_req .host = HAWKBIT_SERVER ;
1091
+ http_req .host = HAWKBIT_SERVER_DOMAIN ;
1045
1092
http_req .port = HAWKBIT_PORT ;
1046
1093
http_req .protocol = "HTTP/1.1" ;
1047
1094
http_req .response = response_cb ;
@@ -1155,7 +1202,7 @@ void hawkbit_reboot(void)
1155
1202
1156
1203
static bool check_hawkbit_server (void )
1157
1204
{
1158
- if (strlen (HAWKBIT_SERVER ) == 0 ) {
1205
+ if (strlen (HAWKBIT_SERVER_ADDR ) == 0 ) {
1159
1206
if (sizeof (CONFIG_HAWKBIT_SERVER ) > 1 ) {
1160
1207
hawkbit_set_server_addr (CONFIG_HAWKBIT_SERVER );
1161
1208
} else {
0 commit comments