@@ -47,6 +47,12 @@ static const char *dl_host;
4747static const char * dl_file ;
4848static uint32_t dl_host_hash ;
4949static uint32_t dl_file_hash ;
50+ static uint32_t dl_proxy_uri_hash ;
51+ /* Set by fota_download_with_host_cfg() to signal that the caller populated the
52+ * transport-specific fields of dl_host_cfg (proxy_uri, cid, auth_cb). Cleared after
53+ * each download is started so that the next non-proxy entry point resets them.
54+ */
55+ static bool dl_host_cfg_provided ;
5056
5157static struct downloader dl ;
5258static int downloader_callback (const struct downloader_evt * event );
@@ -311,6 +317,7 @@ static int downloader_callback(const struct downloader_evt *event)
311317 /* Download completed, clear hashes to prevent resuming on the next download */
312318 dl_host_hash = 0 ;
313319 dl_file_hash = 0 ;
320+ dl_proxy_uri_hash = 0 ;
314321
315322 atomic_clear_bit (& flags , FLAG_DOWNLOADING );
316323 atomic_set_bit (& flags , FLAG_STOPPED );
@@ -530,21 +537,26 @@ static void set_host_and_file(char const *const host, char const *const file)
530537{
531538 uint32_t host_hash ;
532539 uint32_t file_hash ;
540+ uint32_t proxy_uri_hash = 0 ;
533541
534542 host_hash = sys_hash32 (host , strlen (host ));
535543 file_hash = sys_hash32 (file , strlen (file ));
536544
537- LOG_DBG ("URI checksums %d,%d,%d,%d\r\n" , host_hash , file_hash , dl_host_hash , dl_file_hash );
545+ if (dl_host_cfg .proxy_uri != NULL ) {
546+ proxy_uri_hash = sys_hash32 (dl_host_cfg .proxy_uri , strlen (dl_host_cfg .proxy_uri ));
547+ }
538548
539549 /* Verify if the URI is same as last time, if not, prevent resuming. */
540- if (dl_host_hash != host_hash || dl_file_hash != file_hash ) {
550+ if (dl_host_hash != host_hash || dl_file_hash != file_hash ||
551+ dl_proxy_uri_hash != proxy_uri_hash ) {
541552 atomic_set_bit (& flags , FLAG_NEW_URI );
542553 } else {
543554 atomic_clear_bit (& flags , FLAG_NEW_URI );
544555 }
545556
546557 dl_host_hash = host_hash ;
547558 dl_file_hash = file_hash ;
559+ dl_proxy_uri_hash = proxy_uri_hash ;
548560
549561 dl_host = host ;
550562 dl_file = file ;
@@ -556,6 +568,7 @@ int fota_download_with_host_cfg(const char *host, const char *file,
556568 const struct downloader_host_cfg * host_cfg )
557569{
558570 dl_host_cfg = * host_cfg ;
571+ dl_host_cfg_provided = true;
559572 LOG_DBG ("Downloading %s/%s" , host , file );
560573 return fota_download_start_with_image_type (host , file , sec_tag ,
561574 pdn_id , fragment_size , expected_type );
@@ -566,6 +579,13 @@ int fota_download(const char *host, const char *file,
566579 const enum dfu_target_image_type expected_type )
567580{
568581
582+ /* Consume the flag unconditionally so a rejected call below can't leave it set for the
583+ * next download.
584+ */
585+ bool host_cfg_provided = dl_host_cfg_provided ;
586+
587+ dl_host_cfg_provided = false;
588+
569589 if (host == NULL || file == NULL || callback == NULL ) {
570590 return - EINVAL ;
571591 }
@@ -576,6 +596,19 @@ int fota_download(const char *host, const char *file,
576596
577597 int err ;
578598 static int sec_tag_list_copy [CONFIG_FOTA_DOWNLOAD_SEC_TAG_LIST_SIZE_MAX ];
599+
600+ /* Non-proxy entry points don't populate the transport-specific fields of dl_host_cfg.
601+ * Reset them to a known baseline so a previous fota_download_with_host_cfg() call can't
602+ * leave a stale proxy_uri that corrupts the resume decision in set_host_and_file(), nor
603+ * leak CoAP-only state (proxy_uri/cid/auth_cb) into a subsequent non-proxy download.
604+ * Persisted fields set elsewhere (if_name, set_native_tls) are left untouched.
605+ */
606+ if (!host_cfg_provided ) {
607+ dl_host_cfg .proxy_uri = NULL ;
608+ dl_host_cfg .cid = false;
609+ dl_host_cfg .auth_cb = NULL ;
610+ }
611+
579612 dl_host_cfg .pdn_id = pdn_id ;
580613 dl_host_cfg .range_override = fragment_size ;
581614
0 commit comments