From 48eeb89cadc80f3e02911a4a038a47e82c974a66 Mon Sep 17 00:00:00 2001
From: Maslov Nikita <webconn@users.noreply.github.com>
Date: Tue, 27 Dec 2022 11:36:58 +0600
Subject: [PATCH] don't exit if atcab_idle failed (#22)

* don't exit if atcab_idle failed

It may mean that device watchdog has switched it already.

* more specific changelog entry
---
 atecc-asymm.c    | 6 ++----
 atecc-auth.c     | 3 +--
 atecc-config.c   | 4 +---
 atecc-data.c     | 6 ++----
 atecc-ecdh.c     | 3 +--
 atecc-hmac.c     | 3 +--
 debian/changelog | 7 +++++++
 7 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/atecc-asymm.c b/atecc-asymm.c
index 6495599..f079ed2 100644
--- a/atecc-asymm.c
+++ b/atecc-asymm.c
@@ -131,8 +131,7 @@ int do_atecc_write_private(int argc, char **argv)
     // it adds delay between ATECC init sequence in main() and this operation.
     status = atcab_idle();
     if (status != ATCA_SUCCESS) {
-        eprintf("Command atcab_idle is failed with status 0x%x\n", status);
-        return 2;
+        eprintf("Command atcab_idle is failed with status 0x%x, but let's continue\n", status);
     }
 
     ATECC_RETRY(status, atcab_priv_write(key_id, privatekey_payload, writekey_id, writekey));
@@ -359,8 +358,7 @@ int do_atecc_verify(int argc, char **argv)
     // it adds delay between ATECC init sequence in main() and this operation.
     status = atcab_idle();
     if (status != ATCA_SUCCESS) {
-        eprintf("Command atcab_idle is failed with status 0x%x\n", status);
-        return 2;
+        eprintf("Command atcab_idle is failed with status 0x%x, but let's continue\n", status);
     }
 
     if (!pubkeyfilename) {
diff --git a/atecc-auth.c b/atecc-auth.c
index 3fcdeec..29c568e 100644
--- a/atecc-auth.c
+++ b/atecc-auth.c
@@ -249,8 +249,7 @@ int do_atecc_auth_check_gendig(int argc, char **argv)
     // it adds delay between ATECC init sequence in main() and this operation.
     status = atcab_idle();
     if (status != ATCA_SUCCESS) {
-        eprintf("Command atcab_idle is failed with status 0x%x\n", status);
-        return 2;
+        eprintf("Command atcab_idle is failed with status 0x%x, but let's continue\n", status);
     }
 
     do {
diff --git a/atecc-config.c b/atecc-config.c
index cf025fb..5bec17e 100644
--- a/atecc-config.c
+++ b/atecc-config.c
@@ -202,9 +202,7 @@ int do_atecc_write_config(int argc, char **argv)
     // it adds delay between ATECC init sequence in main() and this operation.
     status = atcab_idle();
     if (status != ATCA_SUCCESS) {
-        eprintf("Command atcab_idle is failed with status 0x%x\n", status);
-        ret = 2;
-        goto _wcexit;
+        eprintf("Command atcab_idle is failed with status 0x%x, but let's continue\n", status);
     }
 
     bool is_locked;
diff --git a/atecc-data.c b/atecc-data.c
index 690925c..aa8c4ca 100644
--- a/atecc-data.c
+++ b/atecc-data.c
@@ -77,8 +77,7 @@ int do_atecc_write_data(int argc, char **argv)
     // it adds delay between ATECC init sequence in main() and this operation.
     status = atcab_idle();
     if (status != ATCA_SUCCESS) {
-        eprintf("Command atcab_idle is failed with status 0x%x\n", status);
-        return 2;
+        eprintf("Command atcab_idle is failed with status 0x%x, but let's continue\n", status);
     }
 
     /* try to write data to chip */
@@ -155,8 +154,7 @@ int do_atecc_read_data(int argc, char **argv)
     // it adds delay between ATECC init sequence in main() and this operation.
     status = atcab_idle();
     if (status != ATCA_SUCCESS) {
-        eprintf("Command atcab_idle is failed with status 0x%x\n", status);
-        return 2;
+        eprintf("Command atcab_idle is failed with status 0x%x, but let's continue\n", status);
     }
 
     /* read data from ATECC */
diff --git a/atecc-ecdh.c b/atecc-ecdh.c
index 8f08fb2..d73dfb4 100644
--- a/atecc-ecdh.c
+++ b/atecc-ecdh.c
@@ -41,8 +41,7 @@ int do_atecc_ecdh(int argc, char **argv)
     // it adds delay between ATECC init sequence in main() and this operation.
     status = atcab_idle();
     if (status != ATCA_SUCCESS) {
-        eprintf("Command atcab_idle is failed with status 0x%x\n", status);
-        return 2;
+        eprintf("Command atcab_idle is failed with status 0x%x, but let's continue\n", status);
     }
 
     ATECC_RETRY(status, atcab_ecdh(slot_id, pubkey, pms));
diff --git a/atecc-hmac.c b/atecc-hmac.c
index b6b1a4a..6a228ca 100644
--- a/atecc-hmac.c
+++ b/atecc-hmac.c
@@ -67,8 +67,7 @@ int do_atecc_hmac_write_key(int argc, char **argv)
     // it adds delay between ATECC init sequence in main() and this operation.
     status = atcab_idle();
     if (status != ATCA_SUCCESS) {
-        eprintf("Command atcab_idle is failed with status 0x%x\n", status);
-        return 2;
+        eprintf("Command atcab_idle is failed with status 0x%x, but let's continue\n", status);
     }
 
     const char *cmd;
diff --git a/debian/changelog b/debian/changelog
index 539f1aa..148fda0 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+atecc-util (0.4.10) stable; urgency=medium
+
+  * don't exit if atcab_idle failed (it may mean that
+    device watchdog has switched it to idle mode already)
+
+ -- Nikita Maslov <nikita.maslov@wirenboard.ru>  Thu, 22 Dec 2022 13:54:08 +0600
+
 atecc-util (0.4.9) stable; urgency=medium
 
   * always send ATECC to idle mode before access