Skip to content

Commit

Permalink
net: fota_download: Add event for failed connection attempt
Browse files Browse the repository at this point in the history
The errnos -ECONNREFUSED and -ECONNABORTED are most likely to
happen during connection establishment, and in particular because
of issues with the TLS handshake.

This patch attempts to distinguish between general errors from the
download_client and errors arrising from the connection establishment.

Signed-off-by: Jan Tore Guggedal <[email protected]>
  • Loading branch information
jtguggedal authored and rlubos committed Jan 16, 2024
1 parent 69df0e6 commit 2aaabac
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,10 @@ Libraries for networking

* :ref:`lib_fota_download` library:

* Added the functions :c:func:`fota_download` and :c:func:`fota_download_any` that can accept a security tag list and security tag count as arguments instead of a single security tag.
* Added:

* The functions :c:func:`fota_download` and :c:func:`fota_download_any` that can accept a security tag list and security tag count as arguments instead of a single security tag.
* :c:enumerator:`FOTA_DOWNLOAD_ERROR_CAUSE_CONNECT_FAILED` as a potential error cause in :c:enumerator:`FOTA_DOWNLOAD_EVT_ERROR` events.

Libraries for NFC
-----------------
Expand Down
4 changes: 4 additions & 0 deletions include/net/fota_download.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ enum fota_download_evt_id {
enum fota_download_error_cause {
/** No error, used when event ID is not FOTA_DOWNLOAD_EVT_ERROR. */
FOTA_DOWNLOAD_ERROR_CAUSE_NO_ERROR,
/** Connecting to the FOTA server failed. A possible reason could be wrong
* TLS credentials. A retry is unlikely to help with the same credentials.
*/
FOTA_DOWNLOAD_ERROR_CAUSE_CONNECT_FAILED,
/** Downloading the update failed. The download may be retried. */
FOTA_DOWNLOAD_ERROR_CAUSE_DOWNLOAD_FAILED,
/** The update is invalid and was rejected. Retry will not help. */
Expand Down
5 changes: 5 additions & 0 deletions subsys/net/lib/fota_download/src/fota_download.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ static int download_client_callback(const struct download_client_evt *event)
/* Fall through and return 0 below to tell
* download_client to retry
*/
} else if ((event->error == -ECONNABORTED) || (event->error == -ECONNREFUSED)) {
LOG_ERR("Download client failed to connect to server");
set_error_state(FOTA_DOWNLOAD_ERROR_CAUSE_CONNECT_FAILED);

goto error_and_close;
} else {
LOG_ERR("Download client error");
err = dfu_target_done(false);
Expand Down

0 comments on commit 2aaabac

Please sign in to comment.