libese-hw: tweak pn80t reset
This changes reset behavior in two ways:
- Perform a hard reset anytime there isn't a
request by the chip to stay powered.
- Clear the libese error state on reset.
- Perform a hard reset any time the special APDU
is sent.
Test: built; looks good. Pending alt test.
Bug: none
Change-Id: Ie517772ae3bbafe1f817ac950639c7ebeb18fbae
diff --git a/libese-hw/nxp/pn80t/common.c b/libese-hw/nxp/pn80t/common.c
index b2b4abd..823c92b 100644
--- a/libese-hw/nxp/pn80t/common.c
+++ b/libese-hw/nxp/pn80t/common.c
@@ -97,10 +97,16 @@
const struct Pn80tPlatform *platform = ese->ops->opts;
struct NxpState *ns = NXP_PN80T_STATE(ese);
- /* Attempt a soft reset, but if it fails, then do a hard reset. */
+ /* If there is no error, perform a soft reset.
+ * If there is no cooldown time associated, go ahead and do a real
+ * reset as there is no other interface to trigger a hard reset.
+ *
+ * This avoids pulling the power when a cooldown is in progress
+ * if it is at all possible to avoid.
+ */
if (!ese_error(ese)) {
const uint32_t cooldownSec = nxp_pn80t_send_cooldown(ese, false);
- if (!ese_error(ese)) {
+ if (!ese_error(ese) && cooldownSec > 0) {
return 0;
}
}
@@ -113,6 +119,9 @@
ese_set_error(ese, kNxpPn80tErrorResetToggle);
return -1;
}
+
+ /* Start fresh with the reset. */
+ ese->error.is_err = false;
return 0;
}
@@ -255,6 +264,8 @@
switch (buf[1]) {
case kResetCommand:
ALOGI("interface command received: reset");
+ /* Force a hard reset by setting an error on the hw. */
+ ese_set_error(ese, 0);
if (nxp_pn80t_reset(ese) < 0) {
/* Warning, state unchanged error. */
ok[0] = 0x62;