Skip to content

Commit

Permalink
UT reset_card.py: display the ATR before and after reset
Browse files Browse the repository at this point in the history
This allows to get the cold and warm ATRs.

You need to use reset_card.py with one argument to use
SCardReconnect()
  • Loading branch information
LudovicRousseau committed Dec 14, 2022
1 parent 601a3e9 commit d47fda2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions UnitaryTests/reset_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from smartcard.scard import *
from smartcard.pcsc.PCSCExceptions import *
from smartcard.util import toHexString
import sys

hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER)
Expand All @@ -37,6 +38,13 @@
SCARD_SHARE_SHARED, SCARD_PROTOCOL_ANY)
if hresult != SCARD_S_SUCCESS:
raise BaseSCardException(hresult)
hresult, reader, state, protocol, atr = SCardStatus(hcard)
if hresult != SCARD_S_SUCCESS:
raise BaseSCardException(hresult)
print("reader:", reader)
print("state:", hex(state))
print("protocol:", protocol)
print("atr:", toHexString(atr))

if len(sys.argv) > 1:
print("reset using SCardReconnect")
Expand All @@ -46,6 +54,14 @@
SCARD_SHARE_EXCLUSIVE, SCARD_PROTOCOL_ANY, SCARD_RESET_CARD)
if hresult != SCARD_S_SUCCESS:
raise BaseSCardException(hresult)

hresult, reader, state, protocol, atr = SCardStatus(hcard)
if hresult != SCARD_S_SUCCESS:
raise BaseSCardException(hresult)
print("reader:", reader)
print("state:", hex(state))
print("protocol:", protocol)
print("atr:", toHexString(atr))
else:
print("reset using SCardDisconnect")

Expand Down

0 comments on commit d47fda2

Please sign in to comment.