|
25 | 25 |
|
26 | 26 | LOG_MODULE_REGISTER(fota_download, CONFIG_FOTA_DOWNLOAD_LOG_LEVEL); |
27 | 27 |
|
28 | | -#if defined(CONFIG_FOTA_DOWNLOAD_EXTERNAL_DL) |
29 | | -static size_t ext_file_sz; |
30 | | -static size_t ext_rcvd_sz; |
31 | | -#endif |
32 | | - |
33 | 28 | static fota_download_callback_t callback; |
34 | 29 | static const char *dl_host; |
35 | 30 | static const char *dl_file; |
@@ -105,15 +100,6 @@ static void send_progress(int progress) |
105 | 100 | #endif |
106 | 101 | } |
107 | 102 |
|
108 | | -static void send_ext_resume(const size_t offset) |
109 | | -{ |
110 | | -#if defined(CONFIG_FOTA_DOWNLOAD_EXTERNAL_DL) |
111 | | - const struct fota_download_evt evt = { .id = FOTA_DOWNLOAD_EVT_RESUME_OFFSET, |
112 | | - .resume_offset = offset }; |
113 | | - callback(&evt); |
114 | | -#endif |
115 | | -} |
116 | | - |
117 | 103 | static void stopped(void) |
118 | 104 | { |
119 | 105 | atomic_clear_bit(&flags, FLAG_DOWNLOADING); |
@@ -143,27 +129,16 @@ static void dfu_target_callback_handler(enum dfu_target_evt_id evt) |
143 | 129 |
|
144 | 130 | static size_t file_size_get(size_t *size) |
145 | 131 | { |
146 | | -#if defined(CONFIG_FOTA_DOWNLOAD_EXTERNAL_DL) |
147 | | - *size = ext_file_sz; |
148 | | - return 0; |
149 | | -#endif |
150 | 132 | return downloader_file_size_get(&dl, size); |
151 | 133 | } |
152 | 134 |
|
153 | 135 | static size_t downloaded_size_get(size_t *size) |
154 | 136 | { |
155 | | -#if defined(CONFIG_FOTA_DOWNLOAD_EXTERNAL_DL) |
156 | | - *size = ext_rcvd_sz; |
157 | | - return 0; |
158 | | -#endif |
159 | 137 | return downloader_downloaded_size_get(&dl, size); |
160 | 138 | } |
161 | 139 |
|
162 | 140 | static int dl_cancel(void) |
163 | 141 | { |
164 | | -#if defined(CONFIG_FOTA_DOWNLOAD_EXTERNAL_DL) |
165 | | - return 0; |
166 | | -#endif |
167 | 142 | return downloader_cancel(&dl); |
168 | 143 | } |
169 | 144 |
|
@@ -264,10 +239,6 @@ static int downloader_callback(const struct downloader_evt *event) |
264 | 239 | } |
265 | 240 | } |
266 | 241 |
|
267 | | -#if defined(CONFIG_FOTA_DOWNLOAD_EXTERNAL_DL) |
268 | | - ext_rcvd_sz += event->fragment.len; |
269 | | -#endif |
270 | | - |
271 | 242 | err = dfu_target_write(event->fragment.buf, event->fragment.len); |
272 | 243 | if (err && err == -EINVAL) { |
273 | 244 | LOG_INF("Image refused"); |
@@ -321,7 +292,8 @@ static int downloader_callback(const struct downloader_evt *event) |
321 | 292 | /* In case of socket errors we can return 0 to retry/continue, |
322 | 293 | * or non-zero to stop |
323 | 294 | */ |
324 | | - if ((socket_retries_left) && (event->error == -ECONNRESET)) { |
| 295 | + if ((socket_retries_left) |
| 296 | + && ((event->error == -ECONNRESET) || (event->error == -EAGAIN))) { |
325 | 297 | LOG_WRN("Download socket error. %d retries left...", |
326 | 298 | socket_retries_left); |
327 | 299 | socket_retries_left--; |
@@ -371,11 +343,6 @@ static int downloader_callback(const struct downloader_evt *event) |
371 | 343 |
|
372 | 344 | static int get_from_offset(const size_t offset) |
373 | 345 | { |
374 | | - if (IS_ENABLED(CONFIG_FOTA_DOWNLOAD_EXTERNAL_DL)) { |
375 | | - send_ext_resume(offset); |
376 | | - return 0; |
377 | | - } |
378 | | - |
379 | 346 | int err = downloader_get_with_host_and_file(&dl, &dl_host_cfg, dl_host, dl_file, offset); |
380 | 347 |
|
381 | 348 | if (err != 0) { |
@@ -533,47 +500,21 @@ static void set_host_and_file(char const *const host, char const *const file) |
533 | 500 | dl_file = file; |
534 | 501 | } |
535 | 502 |
|
536 | | -#if defined(CONFIG_FOTA_DOWNLOAD_EXTERNAL_DL) |
537 | | -int fota_download_external_evt_handle(struct downloader_evt const *const evt) |
538 | | -{ |
539 | | - return downloader_callback(evt); |
540 | | -} |
541 | | - |
542 | | -int fota_download_external_start(const char *host, const char *file, |
543 | | - const enum dfu_target_image_type expected_type, |
544 | | - const size_t image_size) |
| 503 | +int fota_download_with_host_cfg(const char *host, const char *file, |
| 504 | + int sec_tag, uint8_t pdn_id, size_t fragment_size, |
| 505 | + const enum dfu_target_image_type expected_type, |
| 506 | + const struct downloader_host_cfg *host_cfg) |
545 | 507 | { |
546 | | - if (host == NULL || file == NULL || callback == NULL || image_size == 0) { |
547 | | - return -EINVAL; |
548 | | - } |
549 | | - |
550 | | - if (atomic_test_and_set_bit(&flags, FLAG_DOWNLOADING)) { |
551 | | - return -EALREADY; |
552 | | - } |
553 | | - |
554 | | - atomic_clear_bit(&flags, FLAG_STOPPED); |
555 | | - atomic_clear_bit(&flags, FLAG_RESUME); |
556 | | - set_error_state(FOTA_DOWNLOAD_ERROR_CAUSE_NO_ERROR); |
557 | | - |
558 | | - set_host_and_file(host, file); |
559 | | - |
560 | | - socket_retries_left = CONFIG_FOTA_SOCKET_RETRIES; |
561 | | - |
562 | | - img_type_expected = expected_type; |
563 | | - ext_file_sz = image_size; |
564 | | - ext_rcvd_sz = 0; |
565 | | - |
566 | | - atomic_set_bit(&flags, FLAG_FIRST_FRAGMENT); |
567 | | - |
568 | | - return 0; |
| 508 | + dl_host_cfg = *host_cfg; |
| 509 | + LOG_DBG("Downloading %s/%s", host, file); |
| 510 | + return fota_download_start_with_image_type(host, file, sec_tag, |
| 511 | + pdn_id, fragment_size, expected_type); |
569 | 512 | } |
570 | | -#endif /* CONFIG_FOTA_DOWNLOAD_EXTERNAL_DL */ |
571 | 513 |
|
572 | 514 | int fota_download(const char *host, const char *file, |
573 | 515 | const int *sec_tag_list, uint8_t sec_tag_count, uint8_t pdn_id, size_t fragment_size, |
574 | 516 | const enum dfu_target_image_type expected_type) |
575 | 517 | { |
576 | | - __ASSERT_NO_MSG(!IS_ENABLED(CONFIG_FOTA_DOWNLOAD_EXTERNAL_DL)); |
577 | 518 |
|
578 | 519 | if (host == NULL || file == NULL || callback == NULL) { |
579 | 520 | return -EINVAL; |
|
0 commit comments