[Pcsclite-cvs-commit] r7002 - trunk/HandlerTest/PCSC

ludovic.rousseau at free.fr ludovic.rousseau at free.fr
Mon Sep 29 09:32:28 UTC 2014


Author: rousseau
Date: 2014-09-29 09:32:28 +0000 (Mon, 29 Sep 2014)
New Revision: 7002

Modified:
   trunk/HandlerTest/PCSC/validation.py
Log:
Add the ability to select the protocol

Some cards are dual protocol T=0 and T=1. Maybe you want to select the
protocol to be used instead of letting PC/SC selecting the protocol.

It may be useful because PC/SC on GNU/Linux prefers T=1 over T=0. But
PC/SC on Mac OS X prefers T=0 over T=1.

A code that was working on GNU/Linux failed to work on Mac OS X because
T=0 was used instdead of T=1.


Modified: trunk/HandlerTest/PCSC/validation.py
===================================================================
--- trunk/HandlerTest/PCSC/validation.py	2014-09-24 13:08:09 UTC (rev 7001)
+++ trunk/HandlerTest/PCSC/validation.py	2014-09-29 09:32:28 UTC (rev 7002)
@@ -22,6 +22,7 @@
 from smartcard.System import readers
 from smartcard.util import toBytes, toHexString
 from smartcard.CardConnectionObserver import ConsoleCardConnectionObserver
+from smartcard.CardConnection import CardConnection
 
 
 def print_error(text):
@@ -31,7 +32,8 @@
 
 
 class Validation(object):
-    def __init__(self, reader, extended=False, debug=False):
+    def __init__(self, reader, extended=False, debug=False,
+            protocol=None):
         self.reader = reader
 
         # Begining Of Line
@@ -48,12 +50,19 @@
             self.connection.addObserver(observer)
             self.BOL = ""
 
-        # connect using any protocol
-        self.connection.connect()
+        # connect using the selected protocol (if any)
+        self.connection.connect(protocol=protocol)
 
         # get the ATR
         self.ATR = self.connection.getATR()
 
+        # display used protocol
+        protocols = {
+                CardConnection.T0_protocol: "T=0",
+                CardConnection.T1_protocol: "T=1"
+                }
+        print "Using protocol:", protocols[self.connection.getProtocol()]
+
         # extended APDU
         self.extended = extended
 
@@ -274,6 +283,8 @@
   -r: reader index. By default the first reader is used
   -a: use APDU
   -d: debug mode
+  -Z: force use T=1
+  -z: force use T=0
   -t val: use val as timerequest value"""
     print "Usage: %s [arguments]" % command
     print HELP
@@ -282,7 +293,7 @@
     import sys
     import getopt
 
-    optlist, args = getopt.getopt(sys.argv[1:], "1234r:ft:aedh")
+    optlist, args = getopt.getopt(sys.argv[1:], "1234r:ft:aedhZz")
 
     case_1 = False
     case_2 = False
@@ -293,6 +304,7 @@
     time_extension = False
     extended = False
     debug = False
+    protocol = None
 
     for o, a in optlist:
         if o == "-1":
@@ -316,6 +328,10 @@
             extended = True
         elif o == "-d":
             debug = True
+        elif o == "-Z":
+            protocol = CardConnection.T1_protocol
+        elif o == "-z":
+            protocol = CardConnection.T0_protocol
         elif o == "-h":
             usage(sys.argv[0])
             sys.exit()
@@ -327,7 +343,8 @@
         reader = readers[0]
     print "Using reader:", reader
 
-    validation = Validation(reader, extended=extended, debug=debug)
+    validation = Validation(reader, extended=extended, debug=debug,
+            protocol=protocol)
     if case_1:
         validation.case_1(full)
     if case_2:




More information about the Pcsclite-cvs-commit mailing list