@@ -86,6 +86,9 @@ static struct hawkbit_config {
86
86
int32_t action_id ;
87
87
#ifdef CONFIG_HAWKBIT_SET_SETTINGS_RUNTIME
88
88
char server_addr [SERVER_ADDR_LEN + 1 ];
89
+ #ifdef CONFIG_HAWKBIT_USE_DOMAIN_NAME
90
+ char server_domain [CONFIG_HAWKBIT_DOMAIN_NAME_MAX_LEN + 1 ];
91
+ #endif
89
92
char server_port [sizeof (STRINGIFY (__UINT16_MAX__ ))];
90
93
#ifndef CONFIG_HAWKBIT_DDI_NO_SECURITY
91
94
char ddi_security_token [DDI_SECURITY_TOKEN_SIZE + 1 ];
@@ -97,11 +100,17 @@ static struct hawkbit_config {
97
100
} hb_cfg ;
98
101
99
102
#ifdef CONFIG_HAWKBIT_SET_SETTINGS_RUNTIME
100
- #define HAWKBIT_SERVER hb_cfg.server_addr
103
+ #ifdef CONFIG_HAWKBIT_USE_DOMAIN_NAME
104
+ #define HAWKBIT_SERVER_DOMAIN hb_cfg.server_domain
105
+ #else
106
+ #define HAWKBIT_SERVER_DOMAIN hb_cfg.server_addr
107
+ #endif /* CONFIG_HAWKBIT_USE_DOMAIN_NAME */
108
+ #define HAWKBIT_SERVER_ADDR hb_cfg.server_addr
101
109
#define HAWKBIT_PORT hb_cfg.server_port
102
110
#define HAWKBIT_PORT_INT atoi(hb_cfg.server_port)
103
111
#else
104
- #define HAWKBIT_SERVER CONFIG_HAWKBIT_SERVER
112
+ #define HAWKBIT_SERVER_ADDR CONFIG_HAWKBIT_SERVER
113
+ #define HAWKBIT_SERVER_DOMAIN CONFIG_HAWKBIT_SERVER
105
114
#define HAWKBIT_PORT STRINGIFY(CONFIG_HAWKBIT_PORT)
106
115
#define HAWKBIT_PORT_INT CONFIG_HAWKBIT_PORT
107
116
#endif /* CONFIG_HAWKBIT_SET_SETTINGS_RUNTIME */
@@ -306,6 +315,22 @@ static int hawkbit_settings_set(const char *name, size_t len, settings_read_cb r
306
315
return rc ;
307
316
}
308
317
318
+ #ifdef CONFIG_HAWKBIT_USE_DOMAIN_NAME
319
+ if (settings_name_steq (name , "server_domain" , & next ) && !next ) {
320
+ if (len != sizeof (hb_cfg .server_domain )) {
321
+ return - EINVAL ;
322
+ }
323
+
324
+ rc = read_cb (cb_arg , & hb_cfg .server_domain , sizeof (hb_cfg .server_domain ));
325
+ LOG_DBG ("<%s> = %s" , "hawkbit/server_domain" , hb_cfg .server_domain );
326
+ if (rc >= 0 ) {
327
+ return 0 ;
328
+ }
329
+
330
+ return rc ;
331
+ }
332
+ #endif /* CONFIG_HAWKBIT_USE_DOMAIN_NAME */
333
+
309
334
if (settings_name_steq (name , "server_port" , & next ) && !next ) {
310
335
if (len != sizeof (uint16_t )) {
311
336
return - EINVAL ;
@@ -344,6 +369,9 @@ static int hawkbit_settings_set(const char *name, size_t len, settings_read_cb r
344
369
}
345
370
#else /* CONFIG_HAWKBIT_SET_SETTINGS_RUNTIME */
346
371
if (settings_name_steq (name , "server_addr" , NULL ) ||
372
+ #ifdef CONFIG_HAWKBIT_USE_DOMAIN_NAME
373
+ settings_name_steq (name , "server_domain" , NULL ) ||
374
+ #endif /* CONFIG_HAWKBIT_USE_DOMAIN_NAME */
347
375
settings_name_steq (name , "server_port" , NULL ) ||
348
376
settings_name_steq (name , "ddi_token" , NULL )) {
349
377
rc = read_cb (cb_arg , NULL , 0 );
@@ -367,6 +395,9 @@ static int hawkbit_settings_export(int (*cb)(const char *name, const void *value
367
395
(void )cb ("hawkbit/action_id" , & hb_cfg .action_id , sizeof (hb_cfg .action_id ));
368
396
#ifdef CONFIG_HAWKBIT_SET_SETTINGS_RUNTIME
369
397
(void )cb ("hawkbit/server_addr" , & hb_cfg .server_addr , strlen (hb_cfg .server_addr ) + 1 );
398
+ #ifdef CONFIG_HAWKBIT_USE_DOMAIN_NAME
399
+ (void )cb ("hawkbit/server_domain" , & hb_cfg .server_domain , sizeof (hb_cfg .server_domain ));
400
+ #endif /* CONFIG_HAWKBIT_USE_DOMAIN_NAME */
370
401
uint16_t hawkbit_port = atoi (hb_cfg .server_port );
371
402
(void )cb ("hawkbit/server_port" , & hawkbit_port , sizeof (hawkbit_port ));
372
403
#ifndef CONFIG_HAWKBIT_DDI_NO_SECURITY
@@ -447,7 +478,7 @@ static bool start_http_client(int *hb_sock)
447
478
}
448
479
449
480
while (resolve_attempts -- ) {
450
- ret = zsock_getaddrinfo (HAWKBIT_SERVER , HAWKBIT_PORT , & hints , & addr );
481
+ ret = zsock_getaddrinfo (HAWKBIT_SERVER_ADDR , HAWKBIT_PORT , & hints , & addr );
451
482
if (ret == 0 ) {
452
483
break ;
453
484
}
@@ -477,8 +508,8 @@ static bool start_http_client(int *hb_sock)
477
508
goto err_sock ;
478
509
}
479
510
480
- if (zsock_setsockopt (* hb_sock , SOL_TLS , TLS_HOSTNAME , HAWKBIT_SERVER ,
481
- sizeof (CONFIG_HAWKBIT_SERVER )) < 0 ) {
511
+ if (zsock_setsockopt (* hb_sock , SOL_TLS , TLS_HOSTNAME , HAWKBIT_SERVER_DOMAIN ,
512
+ sizeof (HAWKBIT_SERVER_DOMAIN )) < 0 ) {
482
513
goto err_sock ;
483
514
}
484
515
#endif /* CONFIG_HAWKBIT_USE_TLS */
@@ -798,6 +829,20 @@ int hawkbit_set_config(struct hawkbit_runtime_config *config)
798
829
sizeof (hb_cfg .server_addr ));
799
830
LOG_DBG ("configured %s: %s" , "hawkbit/server_addr" , hb_cfg .server_addr );
800
831
}
832
+ #ifdef CONFIG_HAWKBIT_USE_DOMAIN_NAME
833
+ if (config -> server_domain != NULL ) {
834
+ if (strnlen (config -> server_domain , CONFIG_HAWKBIT_DOMAIN_NAME_MAX_LEN + 1 )
835
+ > CONFIG_HAWKBIT_DOMAIN_NAME_MAX_LEN ) {
836
+ LOG_ERR ("%s too long: %s" , "hawkbit/server_domain" ,
837
+ config -> server_domain );
838
+ return - EINVAL ;
839
+ }
840
+ strncpy (hb_cfg .server_domain , config -> server_domain ,
841
+ sizeof (hb_cfg .server_domain ));
842
+ LOG_DBG ("configured %s: %s" , "hawkbit/server_domain" ,
843
+ hb_cfg .server_domain );
844
+ }
845
+ #endif /* CONFIG_HAWKBIT_USE_DOMAIN_NAME */
801
846
if (config -> server_port != 0 ) {
802
847
snprintf (hb_cfg .server_port , sizeof (hb_cfg .server_port ), "%u" ,
803
848
config -> server_port );
@@ -831,7 +876,7 @@ int hawkbit_set_config(struct hawkbit_runtime_config *config)
831
876
struct hawkbit_runtime_config hawkbit_get_config (void )
832
877
{
833
878
struct hawkbit_runtime_config config = {
834
- .server_addr = HAWKBIT_SERVER ,
879
+ .server_addr = HAWKBIT_SERVER_ADDR ,
835
880
.server_port = HAWKBIT_PORT_INT ,
836
881
.auth_token = HAWKBIT_DDI_SECURITY_TOKEN ,
837
882
.tls_tag = HAWKBIT_CERT_TAG ,
@@ -1059,7 +1104,7 @@ static bool send_request(struct hawkbit_context *hb_context, enum hawkbit_http_r
1059
1104
#endif /* CONFIG_HAWKBIT_DDI_NO_SECURITY */
1060
1105
1061
1106
http_req .url = url_buffer ;
1062
- http_req .host = HAWKBIT_SERVER ;
1107
+ http_req .host = HAWKBIT_SERVER_DOMAIN ;
1063
1108
http_req .port = HAWKBIT_PORT ;
1064
1109
http_req .protocol = "HTTP/1.1" ;
1065
1110
http_req .response = response_cb ;
@@ -1173,7 +1218,7 @@ void hawkbit_reboot(void)
1173
1218
1174
1219
static bool check_hawkbit_server (void )
1175
1220
{
1176
- if (strlen (HAWKBIT_SERVER ) == 0 ) {
1221
+ if (strlen (HAWKBIT_SERVER_ADDR ) == 0 ) {
1177
1222
if (sizeof (CONFIG_HAWKBIT_SERVER ) > 1 ) {
1178
1223
hawkbit_set_server_addr (CONFIG_HAWKBIT_SERVER );
1179
1224
} else {
0 commit comments