From 8cef2d582287159bca1f2f2f38b1ee81efe23779 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 27 Aug 2026 09:37:18 +0200 Subject: [PATCH] fix reinitialization of sim module --- armsrc/sam_picopass.c | 13 +++++++++++++ armsrc/sam_seos.c | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/armsrc/sam_picopass.c b/armsrc/sam_picopass.c index c79d2329f..d79dfe4b4 100644 --- a/armsrc/sam_picopass.c +++ b/armsrc/sam_picopass.c @@ -641,6 +641,19 @@ int sam_picopass_get_pacs(PacketCommandNG *c) { set_tracing(true); StartTicks(); + // Resetting the module resets the card, which then sends an ATR nobody + // asked for. Read it here rather than letting the first SAM APDU collide + // with it, and take the chance to say plainly when the slot holds + // something that is not a SAM. + smart_card_atr_t card; + if (GetATR(&card, false) == false) { + if (g_dbglevel >= DBG_ERROR) { + DbpString("SAM: no ATR - is a SAM in the slot?"); + } + res = PM3_ECARDEXCHANGE; + goto err; + } + // step 1: ping SAM sam_get_version(info); diff --git a/armsrc/sam_seos.c b/armsrc/sam_seos.c index c1ddfcc8b..f0ff823fc 100644 --- a/armsrc/sam_seos.c +++ b/armsrc/sam_seos.c @@ -296,6 +296,19 @@ int sam_seos_get_pacs(PacketCommandNG *c) { set_tracing(true); StartTicks(); + // Resetting the module resets the card, which then sends an ATR nobody + // asked for. Read it here rather than letting the first SAM APDU collide + // with it, and take the chance to say plainly when the slot holds + // something that is not a SAM. + smart_card_atr_t card; + if (GetATR(&card, false) == false) { + if (g_dbglevel >= DBG_ERROR) { + DbpString("SAM: no ATR - is a SAM in the slot?"); + } + res = PM3_ECARDEXCHANGE; + goto err; + } + // step 1: ping SAM sam_get_version(false);