Hi!

I'm trying to use the secure PIN entry with
a SPR 532. pcsclite version is 1.4.102, CCID
version is 1.3.8 (newest versions as of yesterday).

I do a SCardControl with SCARD_CTL_CODE(3400). The
SPR 532 can do a Verify Direct and a Modify Direct
command. After sending the Verify Direct command
the reader beeps, I can enter my PIN, the reader
acknowledges my PIN and the yellow LED will be on
permanently.

But the SCardControl call does not return immediately
after I pressed the OK-Button on my reader. Instead it
will wait for about 30 seconds and will then fail
with return code 80100016 which means:
"An attempt was made to end a non-existent transaction."
I have no idea why this happens. It happens with
other readers too.

I have attached a short test-program and full
pcscd-debug log. Maybe Ludovic knows what I'm
doing wrong.

By the way: This program works as expected under
windows.

Peter Koch


#include <stdlib.h>
#include <stdio.h>
#include <reader.h>
#include <winscard.h>

int main(){
        SCARDCONTEXT hContext;
        SCARDHANDLE hCard;
        LONG ret;
        DWORD i, ol, dw, spe_ctl_direct, state, proto, buflen, atrlen;
        BYTE obuf[100], atr[32];
        char buf[1000];
        // char *reader="Cherry SmartTerminal ST-2XXX (00000096) 00 00";
        char *reader="SCM SPR 532 (54000669) 00 00";
#pragma pack(1)
        struct {
                BYTE  bTimeOut;
                BYTE  bTimeOut2;
                BYTE  bmFormatString;
                BYTE  bmPINBlockString;
                BYTE  bmPINLengthFormat;
                WORD  wPINMaxExtraDigit;
                BYTE  bEntryValidationCondition;
                BYTE  bNumberMessage;
                WORD  wLangID;
                BYTE  bMsgIndex;
                BYTE  bTeoPrologue[3];
                DWORD ulDataLength;
                BYTE  abData[200];
        } data;
#pragma pack()
        
        ret=SCardEstablishContext(SCARD_SCOPE_USER, NULL, NULL, &hContext);
        printf("SCardEstablishContext()=%lX\n", ret);

        ret=SCardConnect(hContext, reader, SCARD_SHARE_SHARED, 
SCARD_PROTOCOL_T1, &hCard, &dw);
        printf("SCardConnect()=%lX, hCard=%lX\n", ret, hCard);

        ret=SCardControl(hCard,SCARD_CTL_CODE(3400), NULL,0, 
obuf,sizeof(obuf),&ol);
        printf("SCardControl()=%lX, ol=%lu\n", ret, ol);
        for(i=spe_ctl_direct=0;i+5<ol && obuf[i+1]==4;i+=6){
                dw=(obuf[i+2]<<24l) | (obuf[i+3]<<16l) | (obuf[i+4]<<8l) | 
obuf[i+5];
                if(obuf[i]==0x06) spe_ctl_direct=dw;
        }
        printf("SPE Direct: Ctl=%lX\n", spe_ctl_direct);

        data.bTimeOut =20;
        data.bTimeOut2=20;
        data.bmFormatString=0x82; // 1.0.0.10
                                  // Bit   7: Unit: 0=Bits, 1=Bytes
                                  // Bit 6-3: PIN position in APDU after Lc
                                  // Bit   2: PIN-Justification: 0=Left 1=Right
                                  // Bit 1-0: PIN-Format: 00=binary 01=BCD 
10=Ascii
        data.bmPINBlockString=0;  // 0.0
                                  // Bit 7-4: Size of PIN-length in Bits (0=>no 
PIN-length insertion)
                                  // Bit 3-0: Size of PIN-Block in byte
        data.bmPINLengthFormat=0; // 000.0.0
                                  // Bit 7-5: RFU
                                  // Bit   4: Unit: 0=Bits, 1=Bytes
                                  // Bit 3-0: PIN-length position in APDU after 
Lc
        data.wPINMaxExtraDigit=256*1+16; // min.max
        data.bEntryValidationCondition=0x02; // 00000.0.1.0
                                       // Bit 7-3: RFU
                                       // Bit   2: Timout occurred
                                       // Bit   1: Validation Key pressed
                                       // Bit   0: Max size reached
        data.bNumberMessage =0xFF;
        data.wLangID        =0x0904;
        data.bMsgIndex      =0;
        data.bTeoPrologue[0]=0;
        data.bTeoPrologue[1]=0;
        data.bTeoPrologue[2]=0;

        data.ulDataLength=0;
        data.abData[data.ulDataLength++]=0x00;
        data.abData[data.ulDataLength++]=0x20;
        data.abData[data.ulDataLength++]=0x00;
        data.abData[data.ulDataLength++]=0x00;

        dw= (data.abData-&data.bTimeOut) + data.ulDataLength;
        printf("Data"); for(i=0; i<dw; ++i) printf(":%02X",((BYTE*)&data)[i]); 
printf("\n");
        ret=SCardControl(hCard, spe_ctl_direct, &data,dw, 
obuf,sizeof(obuf),&ol);
        printf("SCardControl(%lu bytes)=%lX, ol=%lu, SW=%02X%02X\n", dw, ret, 
ol, obuf[0], obuf[1]);

        SCardReleaseContext(hContext);
        return 0;
}

Output of test-program:

SCardEstablishContext()=0
SCardConnect()=0, hCard=1FD60
SCardControl()=0, ol=12
SPE Direct: Ctl=42330006
Data:14:14:82:00:00:10:01:02:FF:04:09:00:00:00:00:04:00:00:00:00:20:00:00
> Here I enter my PIN, then nothing happens for about 30 seconds
SCardControl(23 bytes)=80100016, ol=0, SW=0604

00000000 pcscdaemon.c:280:main() pcscd set to foreground with debug send to 
stderr
00000063 debuglog.c:239:DebugLogSetLevel() debug level=debug
00000035 debuglog.c:268:DebugLogSetCategory() Debug options: APDU
00000755 pcscdaemon.c:498:main() pcsc-lite 1.4.102 daemon ready.
00118633 hotplug_libusb.c:476:HPAddHotPluggable() Adding USB device: 003:003
00005129 readerfactory.c:1082:RFInitializeReader() Attempting startup of SCM 
SPR 532 (54000669) 00 00 using 
/usr/pcsc/drivers/ifd-ccid.bundle/Contents/Linux/libccid.so
00000214 readerfactory.c:949:RFBindFunctions() Loading IFD Handler 3.0
00000074 ifdhandler.c:1323:init_driver() Driver version: 1.3.8
00000290 ifdhandler.c:1336:init_driver() LogLevel: 0x0003
00000038 ifdhandler.c:1346:init_driver() LogLevel from LIBCCID_ifdLogLevel: 
0x0007
00000271 ifdhandler.c:1356:init_driver() DriverOptions: 0x0000
00000040 ifdhandler.c:81:IFDHCreateChannelByName() lun: 0, device: 
usb:04e6/e003:libusb:003:003
00000067 ccid_usb.c:158:OpenUSBByName() Reader index: 0, Device: 
usb:04e6/e003:libusb:003:003
00000493 ccid_usb.c:236:OpenUSBByName() Manufacturer: Ludovic Rousseau ([EMAIL 
PROTECTED])
00000275 ccid_usb.c:246:OpenUSBByName() ProductString: Generic CCID driver
00000320 ccid_usb.c:252:OpenUSBByName() Copyright: This driver is protected by 
terms of the GNU Lesser General Public License version 2.1, or (at your option) 
any later version.
00015691 ccid_usb.c:311:OpenUSBByName() Checking device: 003/003
00000037 ccid_usb.c:361:OpenUSBByName() Trying to open USB bus/device: 003/003
00000059 ccid_usb.c:408:OpenUSBByName() Found Vendor/Product: 04E6/E003 (SCM 
SPR 532)
00000034 ccid_usb.c:410:OpenUSBByName() Using USB bus/device: 003/003
00000067 ccid_usb.c:836:ControlUSB() request: 0x03
00002028 receive:
00000037 ccid_usb.c:780:get_data_rates() IFD does not support GET_DATA_RATES 
request: Broken pipe
02003953 ccid_usb.c:526:ReadUSB() usb_bulk_read(003/003): Resource temporarily 
unavailable
00006286 ifdhandler.c:307:IFDHGetCapabilities() lun: 0, tag: 0xFB0
00000036 readerfactory.c:267:RFAddReader() Using the pcscd polling thread
00008675 ifdhandler.c:924:IFDHPowerICC() lun: 0, action: PowerUp
00000048 -> 000000 62 00 00 00 00 00 05 00 00 00
00047244 <- 000000 80 18 00 00 00 00 05 00 00 00 3B BF 96 00 81 31 FE 5D 00 64 
04 11 03 01 31 C0 73 F7 01 D0 00 90 00 7D
00000060 Card ATR: 3B BF 96 00 81 31 FE 5D 00 64 04 11 03 01 31 C0 73 F7 01 D0 
00 90 00 7D
00000337 ifdhandler.c:307:IFDHGetCapabilities() lun: 0, tag: 0xFAE
00000036 ifdhandler.c:353:IFDHGetCapabilities() Reader supports 1 slot(s)
00000038 hotplug_libusb.c:402:HPEstablishUSBNotifications() Driver 
ifd-ccid.bundle does not support IFD_GENERATE_HOTPLUG. Using active polling 
instead.
00000034 hotplug_libusb.c:411:HPEstablishUSBNotifications() Polling forced 
every 1 second(s)
> Here I start my test-program
10826768 winscard_msg_srv.c:217:SHMProcessEventsServer() Common channel packet 
arrival
00000030 winscard_msg_srv.c:226:SHMProcessEventsServer() 
SHMProcessCommonChannelRequest detects: 6
00000007 pcscdaemon.c:160:SVCServiceRunLoop() A new context thread creation is 
requested: 6
00000034 winscard_svc.c:132:ContextThread() Thread is started: 6
00000024 winscard_msg_srv.c:287:SHMProcessEventsContext() correctly processed 
client: 6
00000006 winscard_svc.c:188:ContextThread() Client is protocol version 3:0
00000043 winscard_msg_srv.c:287:SHMProcessEventsContext() correctly processed 
client: 6
00000026 winscard.c:239:SCardEstablishContext() Establishing Context: 16980751
00000073 winscard_msg_srv.c:287:SHMProcessEventsContext() correctly processed 
client: 6
00000007 winscard.c:296:SCardConnect() Attempting Connect to SCM SPR 532 
(54000669) 00 00 using protocol: 2
00000012 prothandler.c:128:PHSetProtocol() Attempting PTS to T=1
00000007 ifdhandler.c:488:IFDHSetProtocolParameters() lun: 0, protocol T=1
00000020 ifdhandler.c:611:IFDHSetProtocolParameters() Set speed to 250000 bauds
00000008 ifdhandler.c:765:IFDHSetProtocolParameters() BWI/CWI (TB3) present: 
0x5D
00000006 ifdhandler.c:784:IFDHSetProtocolParameters() IFSC (TA3) present: 254
00000006 ifdhandler.c:791:IFDHSetProtocolParameters() Timeout: 12 seconds
00000006 commands.c:1947:SetParameters() length: 7 bytes
00000014 -> 000000 61 07 00 00 00 00 21 01 00 00 96 10 00 5D 00 FE 00
00036628 <- 000000 82 07 00 00 00 00 21 00 00 01 96 10 00 5D 00 FE 00
00000008 ifdhandler.c:851:IFDHSetProtocolParameters() IFSC (TA3) present: 254
00000006 ifdhandler.c:862:IFDHSetProtocolParameters() Negociate IFSD at 254
00000019 sending: 00 C1 01 FE 3E
00000014 -> 000000 6F 05 00 00 00 00 22 00 00 00 00 C1 01 FE 3E
00003404 <- 000000 80 05 00 00 00 00 22 00 00 00 00 E1 01 FE 1E
00000009 received: 00 E1 01 FE 1E
00000005 ifdhandler.c:868:IFDHSetProtocolParameters() T=1: IFSC=254, IFSD=254
00000006 winscard.c:428:SCardConnect() Active Protocol: T=1
00000007 winscard.c:438:SCardConnect() hCard Identity: 13a46
00000489 winscard_msg_srv.c:287:SHMProcessEventsContext() correctly processed 
client: 6
00000011 ifdhandler.c:1073:IFDHControl() lun: 0, ControlCode: 0x42000D48
00000004 Control TxBuffer:
00000017 Control RxBuffer: 06 04 42 33 00 06 07 04 42 33 00 07
00000118 winscard_msg_srv.c:287:SHMProcessEventsContext() correctly processed 
client: 6
00000008 ifdhandler.c:1073:IFDHControl() lun: 0, ControlCode: 0x42330006
00000013 Control TxBuffer: 14 14 82 00 00 10 01 02 FF 04 09 00 00 00 00 04 00 
00 00 00 20 00 00
00000009 openct/proto-t1.c:581:t1_build() more bit: 0
00000015 -> 000000 6B 03 00 00 00 00 24 00 00 00 80 02 00
00001288 <- 000000 83 00 00 00 00 00 24 00 00 00
00000017 -> 000000 69 13 00 00 00 00 23 00 00 00 00 14 82 00 00 10 01 02 FF 04 
09 00 00 00 04 00 20 00 00
> Here I enter my PIN and hit the OK-Button on my reader
08562730 <- 000000 80 06 00 00 00 00 23 00 00 00 00 00 02 90 00 92
00000014 ccid_usb.c:548:ReadUSB() Duplicate frame detected
> At this pint nothing happens for about 30 seconds
30002149 ccid_usb.c:526:ReadUSB() usb_bulk_read(003/003): Resource temporarily 
unavailable
00000062 Control RxBuffer:
00000037 ifdwrapper.c:664:IFDControl() Card not transacted: 612
00000266 winscard_msg_srv.c:287:SHMProcessEventsContext() correctly processed 
client: 6
00000037 winscard.c:250:SCardReleaseContext() Releasing Context: 16980751
00000035 winscard.c:845:SCardDisconnect() Active Contexts: 1
00000681 winscard_msg_srv.c:276:SHMProcessEventsContext() Client has 
disappeared: 6
00000038 winscard_svc.c:145:ContextThread() Client die: 6
> At this point my program has finished and I hit CTRL-C
24954634 pcscdaemon.c:563:signal_trap() Preparing for suicide
00911458 hotplug_libusb.c:376:HPRescanUsbBus() Hotplug stopped
00091823 readerfactory.c:1348:RFCleanupReaders() entering cleaning function
00000009 readerfactory.c:1357:RFCleanupReaders() Stopping reader: SCM SPR 532 
(54000669) 00 00
00000007 eventhandler.c:124:EHDestroyEventHandler() Stomping thread.
00000006 ifdhandler.c:307:IFDHGetCapabilities() lun: 0, tag: 0xFB1
00000006 eventhandler.c:137:EHDestroyEventHandler() Waiting polling thread
00307978 eventhandler.c:496:EHStatusHandlerThread() Die
00000029 eventhandler.c:161:EHDestroyEventHandler() Thread stomped.
00000007 readerfactory.c:1133:RFUnInitializeReader() Attempting shutdown of SCM 
SPR 532 (54000669) 00 00.
00000009 ifdhandler.c:226:IFDHCloseChannel() lun: 0
00000014 -> 000000 63 00 00 00 00 00 66 00 00 00
00002787 <- 000000 81 00 00 00 00 00 66 01 00 01
00000013 ccid_usb.c:569:CloseUSB() Closing USB device: 003/003
00000005 ccid_usb.c:584:CloseUSB() Last slot closed. Release resources
00001988 readerfactory.c:994:RFUnloadReader() Unloading reader driver.
00000046 pcscdaemon.c:523:at_exit() cleaning /var/run/pcscd

_______________________________________________
opensc-devel mailing list
opensc-devel@lists.opensc-project.org
http://www.opensc-project.org/mailman/listinfo/opensc-devel

Reply via email to