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