[Pcsclite-git-commit] [CCID] 02/03: PowerOn: always try every possible voltage values

Ludovic Rousseau rousseau at moszumanska.debian.org
Tue Oct 4 15:35:11 UTC 2016


This is an automated email from the git hooks/post-receive script.

rousseau pushed a commit to branch master
in repository CCID.

commit df1173ee2f33ca0cf79090e4eb817b24a15c2d00
Author: Ludovic Rousseau <ludovic.rousseau at free.fr>
Date:   Tue Oct 4 15:05:40 2016 +0200

    PowerOn: always try every possible voltage values
    
    The default voltage value is 5V.
    It is possible to change the driver configuration (ifdDriverOptions in
    Info.plist) to start at 1.8V or 3V.
    
    The algorithms was to try:
    5V then fail (default)
    3V then 5V then fail
    1.8V then 3V then 5V then fail
    
    Some cards do not support 5V (like the Coolkey cards, see "Coolkey cards
    do not work in Fedora" https://bugzilla.redhat.com/show_bug.cgi?id=1380615)
    It is possible to change the driver configuration to start at 3V or 1.8V
    but then for cards that work only at 5V we will have 1 or 2 PowerOn
    commands in error before the card returns the ATR.
    
    I made some tests and the SCardConnect() call can take 0.110129 ms when
    starting at 5V and 0.216057 ms when starting at 1.8V and errors for 1.8V
    and 3V. That is "speed" factor of x1.96.
    
    00000005 ifdhandler.c:1146:IFDHPowerICC() action: PowerUp,
    usb:08e6/3437:libudev:0:/dev/bus/usb/001/041 (lun: 0)
    00000007 -> 000000 62 00 00 00 00 00 08 03 00 00
    00054697 <- 000000 80 00 00 00 00 00 08 41 FE 00
    00000014 commands.c:249:CmdPowerOn Card absent or mute
    00000005 commands.c:278:CmdPowerOn() Power up with 1.8V failed. Try with 3V.
    00000006 -> 000000 62 00 00 00 00 00 09 02 00 00
    00054723 <- 000000 80 00 00 00 00 00 09 41 FE 00
    00000015 commands.c:249:CmdPowerOn Card absent or mute
    00000004 commands.c:278:CmdPowerOn() Power up with 3V failed. Try with 5V.
    00000006 -> 000000 62 00 00 00 00 00 0A 01 00 00
    00037738 <- 000000 80 0C 00 00 00 00 0A 00 00 00 3B 29 00 80 72 A4 45 64 00 00 87 14
    
    The idea is to change the algotithm to start at 5V as that is the
    standard voltage for a smart card (according to my card collection) but
    be able to continue with 1.8V and 3V is power on failed at 5V.
    
    The default algorithm is now 5V then 1.8V then 3V then fail.
    
    It is still possible to change the initial voltage. Now, in any case, all
    the values are tried before failing.
    Other possible values are:
    1.8V then 3V then 5V then fail
    3V then 5V then 1.8V then fail
    
    Thanks to Robert Relyea for the patch, used by RedHat since 2013.
    https://git.centos.org/commitdiff/rpms!pcsc-lite-ccid/3dd85f55c8aacfa0704849e7b6cf46d4970b747b
---
 src/Info.plist.src |  4 ++--
 src/ccid.h         | 11 +++--------
 src/commands.c     | 15 ++++++++++++---
 3 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/src/Info.plist.src b/src/Info.plist.src
index e39bb0d..0d71e3d 100644
--- a/src/Info.plist.src
+++ b/src/Info.plist.src
@@ -80,8 +80,8 @@
 	0x08: free
 
 	bits 4 & 5: (values 0x00, 0x10, 0x20, 0x30)
-	 0x00: power on the card at 5V (default value)
-	 0x10: power on the card at 3V and then, if 3V fails use 5V
+	 0x00: power on the card at 5V, then 1.8V then 3V (default value)
+	 0x10: power on the card at 3V, then 5V then 1.8V
 	 0x20: power on the card at 1.8V, then 3V and then 5V
 	 0x30: let the reader decide
 
diff --git a/src/ccid.h b/src/ccid.h
index 8010c10..da0fd75 100644
--- a/src/ccid.h
+++ b/src/ccid.h
@@ -231,19 +231,14 @@ typedef struct
 /*
  * Possible values :
  * 3 -> 1.8V, 3V, 5V
- * 2 -> 3V, 5V
- * 1 -> 5V only
+ * 2 -> 3V, 5V, 1.8V
+ * 1 -> 5V, 1.8V, 3V
  * 0 -> automatic (selection made by the reader)
  */
 /*
- * The default was to start at 5V
+ * The default is to start at 5V
  * otherwise we would have to parse the ATR and get the value of TAi (i>2) when
  * in T=15
- *
- * The CCID 1.1 indicates page 105 in ch. "9.3 Voltage management"
- * that the driver should use growing voltage when supported by the
- * reader.
- * So the default is now to use the sequence 1.8V, 3V and 5V.
  */
 #define VOLTAGE_AUTO 0
 #define VOLTAGE_5V 1
diff --git a/src/commands.c b/src/commands.c
index 3d171f3..0dea038 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -104,6 +104,7 @@ RESPONSECODE CmdPowerOn(unsigned int reader_index, unsigned int * nlength,
 	status_t res;
 	int length, count = 1;
 	unsigned int atr_len;
+	int init_voltage;
 	RESPONSECODE return_value = IFD_SUCCESS;
 	_ccid_descriptor *ccid_descriptor = get_ccid_descriptor(reader_index);
 
@@ -217,6 +218,7 @@ check_again:
 			goto check_again;
 		}
 	}
+	init_voltage = voltage;
 
 again:
 	cmd[0] = 0x62; /* IccPowerOn */
@@ -265,8 +267,8 @@ again:
 				DEBUG_CRITICAL("Can't set reader in ISO mode");
 		}
 
-		/* continue with 3 volts and 5 volts */
-		if (voltage > 1)
+		/* continue with other voltage values */
+		if (voltage)
 		{
 #ifndef NO_LOG
 			const char *voltage_code[] = { "auto", "5V", "3V", "1.8V" };
@@ -275,7 +277,14 @@ again:
 			DEBUG_INFO3("Power up with %s failed. Try with %s.",
 				voltage_code[voltage], voltage_code[voltage-1]);
 			voltage--;
-			goto again;
+
+			/* loop from 5V to 1.8V */
+			if (0 == voltage)
+				voltage = 3;
+
+			/* continue until we tried every values */
+			if (voltage != init_voltage)
+				goto again;
 		}
 
 		return IFD_COMMUNICATION_ERROR;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pcsclite/CCID.git



More information about the Pcsclite-cvs-commit mailing list