Implemented option to select reader
git-svn-id: svn+ssh://localhost/home/henryk/svn/cyberflex-shell/trunk@44 f711b948-2313-0410-aaa9-d29f33439f0b
This commit is contained in:
parent
31225977e2
commit
df4e90ea9e
|
@ -24,9 +24,12 @@ class Card:
|
|||
'63C?': lambda SW1,SW2: "The counter has reached the value '%i'" % (SW2%16)
|
||||
}
|
||||
|
||||
def __init__(self, card = None):
|
||||
def __init__(self, card = None, reader = None):
|
||||
if card is None:
|
||||
self.card = pycsc.pycsc(protocol = pycsc.SCARD_PROTOCOL_ANY)
|
||||
if reader is None:
|
||||
self.card = pycsc.pycsc(protocol = pycsc.SCARD_PROTOCOL_ANY)
|
||||
else:
|
||||
self.card = pycsc.pycsc(protocol = pycsc.SCARD_PROTOCOL_ANY, reader = reader)
|
||||
else:
|
||||
self.card = card
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: iso-8859-1 -*-
|
||||
|
||||
import pycsc, utils, cards, os, re, binascii, sys, exceptions, traceback
|
||||
import pycsc, utils, cards, os, re, binascii, sys, exceptions, traceback, getopt
|
||||
from shell import Shell
|
||||
print_backtrace = True
|
||||
|
||||
|
@ -13,9 +13,40 @@ COMMANDS = {
|
|||
"atr": cmd_atr
|
||||
}
|
||||
|
||||
def list_readers():
|
||||
for index, name in enumerate(pycsc.listReader()):
|
||||
print "%i: %s" % (index, name)
|
||||
|
||||
|
||||
OPTIONS = "r:l"
|
||||
LONG_OPTIONS = ["reader=", "list-readers"]
|
||||
reader = 0
|
||||
exit_now = False
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
readerName = pycsc.listReader()[0]
|
||||
(options, arguments) = getopt.gnu_getopt(sys.argv[1:], OPTIONS, LONG_OPTIONS)
|
||||
|
||||
for (option, value) in options:
|
||||
if option in ("-r","--reader"):
|
||||
if value.isdigit():
|
||||
reader = int(value)
|
||||
else:
|
||||
reader = value
|
||||
if option in ("-l","--list-readers"):
|
||||
list_readers()
|
||||
exit_now = True
|
||||
|
||||
if exit_now:
|
||||
sys.exit()
|
||||
del exit_now
|
||||
|
||||
if isinstance(reader, int):
|
||||
readerName = pycsc.listReader()[reader]
|
||||
else:
|
||||
readerName = reader
|
||||
del reader
|
||||
|
||||
newState = pycsc.getStatusChange(ReaderStates=[{'Reader': readerName, 'CurrentState':pycsc.SCARD_STATE_UNAWARE}])
|
||||
|
||||
print "Cyberflex shell"
|
||||
|
@ -37,7 +68,7 @@ if __name__ == "__main__":
|
|||
|
||||
print "ATR: %s" % utils.hexdump(newState[0]['Atr'], short = True)
|
||||
|
||||
pycsc_card = pycsc.pycsc(protocol = pycsc.SCARD_PROTOCOL_ANY)
|
||||
pycsc_card = pycsc.pycsc(reader = readerName, protocol = pycsc.SCARD_PROTOCOL_ANY)
|
||||
card = cards.new_card_object(pycsc_card)
|
||||
|
||||
shell = Shell("cyberflex-shell")
|
||||
|
|
5
utils.py
5
utils.py
|
@ -164,7 +164,8 @@ class APDU:
|
|||
else:
|
||||
raise ValueError, "Invalid APDU, impossible"
|
||||
|
||||
for (kw, arg) in kwargs.items():
|
||||
for (kw_orig, arg) in kwargs.items():
|
||||
kw = kw_orig.lower()
|
||||
if kw == "cla":
|
||||
self.cla = arg
|
||||
elif kw == "ins":
|
||||
|
@ -181,7 +182,7 @@ class APDU:
|
|||
elif kw == "content":
|
||||
self.content = arg
|
||||
else:
|
||||
raise TypeError, "Got an unexpected keyword argument '%s'" % kw
|
||||
raise TypeError, "Got an unexpected keyword argument '%s'" % kw_orig
|
||||
|
||||
if not lc_was_set:
|
||||
self.lc = len(self.content)
|
||||
|
|
Loading…
Reference in New Issue