Skip to content

Commit e73f032

Browse files
committed
Add reader reconnect after GET_VERSION failure to fix NTAG detection
On some readers (ACR1552 on Windows), GET_VERSION command returning non-9000 status (e.g., 6300) corrupts the reader state. Subsequent commands fail with "smart card removed" errors, causing CC detection to fail and NTAG215/213 cards to be misdetected as MIFARE Ultralight. Adding a reconnect with ResetCard disposition immediately after GET_VERSION failure resets the reader state, allowing CC detection to proceed correctly and identify NTAG cards by their CC size byte.
1 parent 740c421 commit e73f032

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

internal/core/card.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,20 @@ func detectCardType(card *scard.Card, cardInfo *Card) (confident bool) {
461461
}
462462
}
463463

464+
// Reset reader state after GET_VERSION failures.
465+
// GET_VERSION returning non-9000 status (e.g., 6300) on some readers (ACR1552 on Windows)
466+
// can leave the reader in a corrupted state where subsequent commands fail with
467+
// "card removed" errors. Reconnecting with ResetCard clears this state.
468+
if !getVersionSucceeded {
469+
if err := card.Reconnect(scard.ShareShared, scard.ProtocolAny, scard.ResetCard); err != nil {
470+
logging.Debug(logging.CatCard, "Reader reconnect after GET_VERSION failed", map[string]any{
471+
"error": err.Error(),
472+
})
473+
} else {
474+
logging.Debug(logging.CatCard, "Reader reconnected after GET_VERSION failure", nil)
475+
}
476+
}
477+
464478
// Method 2a: Try reading pages 1-4 (works on ACR1252U where direct page 3 read fails)
465479
// Page 3 contains the capability container at offset 8 in this 16-byte response
466480
readCmd1 := []byte{0xFF, 0xB0, 0x00, 0x01, 0x10} // Read 16 bytes from page 1

0 commit comments

Comments
 (0)