diff --git a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst index 45da6e64140..6bf2b9dbf80 100644 --- a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst +++ b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst @@ -595,6 +595,12 @@ Libraries for networking * The :kconfig:option:`CONFIG_DOWNLOAD_CLIENT_MAX_HOSTNAME_SIZE` Kconfig option's default value to ``255``. * The :kconfig:option:`CONFIG_DOWNLOAD_CLIENT_MAX_FILENAME_SIZE` Kconfig option's default value to ``255``. +* :ref:`lib_fota_download` library: + + * Updated: + + * The library now verifies whether the download started with the same URI and resumes the interrupted download. + Libraries for NFC ----------------- diff --git a/subsys/net/lib/fota_download/Kconfig b/subsys/net/lib/fota_download/Kconfig index 468a7376bef..c4e76c44474 100644 --- a/subsys/net/lib/fota_download/Kconfig +++ b/subsys/net/lib/fota_download/Kconfig @@ -8,6 +8,7 @@ menuconfig FOTA_DOWNLOAD bool "FOTA Download" depends on DOWNLOAD_CLIENT depends on DFU_TARGET + select SYS_HASH_FUNC32 imply FW_INFO if (FOTA_DOWNLOAD) diff --git a/subsys/net/lib/fota_download/src/fota_download.c b/subsys/net/lib/fota_download/src/fota_download.c index c0e71cd8345..bf90c3a3b72 100644 --- a/subsys/net/lib/fota_download/src/fota_download.c +++ b/subsys/net/lib/fota_download/src/fota_download.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -29,6 +30,8 @@ LOG_MODULE_REGISTER(fota_download, CONFIG_FOTA_DOWNLOAD_LOG_LEVEL); static fota_download_callback_t callback; static const char *dl_host; static const char *dl_file; +static uint32_t dl_host_hash; +static uint32_t dl_file_hash; static struct download_client dlc; static struct k_work_delayable dlc_with_offset_work; static int socket_retries_left; @@ -415,6 +418,8 @@ int fota_download_start_with_image_type(const char *host, const char *file, const enum dfu_target_image_type expected_type) { static int sec_tag_list[1]; + uint32_t host_hash = 0; + uint32_t file_hash = 0; int err = -1; struct download_client_cfg config = { @@ -434,12 +439,19 @@ int fota_download_start_with_image_type(const char *host, const char *file, atomic_clear_bit(&flags, FLAG_RESUME); set_error_state(FOTA_DOWNLOAD_ERROR_CAUSE_NO_ERROR); + host_hash = sys_hash32(host, strlen(host)); + file_hash = sys_hash32(file, strlen(file)); + LOG_DBG("URI checksums %d,%d,%d,%d\r\n", host_hash, file_hash, + dl_host_hash, dl_file_hash); + /* Verify if the URI is same as last time, if not, prevent resuming. */ - if ((!dl_host || strcmp(dl_host, host) != 0) || (!dl_file || strcmp(dl_file, file) != 0)) { + if (dl_host_hash != host_hash || dl_file_hash != file_hash) { atomic_set_bit(&flags, FLAG_NEW_URI); } else { atomic_clear_bit(&flags, FLAG_NEW_URI); } + dl_host_hash = host_hash; + dl_file_hash = file_hash; dl_host = host; dl_file = file; diff --git a/tests/subsys/net/lib/fota_download/prj.conf b/tests/subsys/net/lib/fota_download/prj.conf index 8a4b52b2eb6..5bae8469dfc 100644 --- a/tests/subsys/net/lib/fota_download/prj.conf +++ b/tests/subsys/net/lib/fota_download/prj.conf @@ -8,3 +8,4 @@ CONFIG_ZTEST_NEW_API=y CONFIG_FLASH=y CONFIG_FW_INFO=y CONFIG_TFM_BUILD_NS=y # In order to mock tfm_platform_s0_active +CONFIG_SYS_HASH_FUNC32=y