Skip to content

Commit

Permalink
SCardGetAttrib: add test for SCARD_ATTR_CHANNEL_ID
Browse files Browse the repository at this point in the history
  • Loading branch information
LudovicRousseau committed Apr 14, 2020
1 parent 92d7120 commit e667a43
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion UnitaryTests/SCardGetAttrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from smartcard.scard import *
from smartcard.pcsc.PCSCExceptions import *
from smartcard.util import toHexString, toASCIIString
from struct import unpack

hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER)
if hresult != SCARD_S_SUCCESS:
Expand All @@ -42,13 +43,23 @@
raise BaseSCardException(hresult)

print("reader:", reader)
for attribute in (SCARD_ATTR_VENDOR_IFD_SERIAL_NO, SCARD_ATTR_ATR_STRING):
for attribute in (SCARD_ATTR_VENDOR_IFD_SERIAL_NO,
SCARD_ATTR_ATR_STRING, SCARD_ATTR_CHANNEL_ID):
hresult, attrib = SCardGetAttrib(hcard, attribute)
print(hex(attribute), end=' ')
if hresult != SCARD_S_SUCCESS:
print(SCardGetErrorMessage(hresult))
else:
print(attrib, toHexString(attrib), toASCIIString(attrib))
if attribute is SCARD_ATTR_CHANNEL_ID:
# get the DWORD value
DDDDCCCC = unpack("i", bytearray(attrib))[0]
DDDD = DDDDCCCC >> 16
if DDDD is 0x0020:
bus = (DDDDCCCC & 0xFF00) >> 8
addr = DDDDCCCC & 0xFF
print(" USB: bus: {}, addr: {}".format(bus, addr))


hresult = SCardDisconnect(hcard, SCARD_LEAVE_CARD)
if hresult != SCARD_S_SUCCESS:
Expand Down

0 comments on commit e667a43

Please sign in to comment.