Hi,
I got the same problem.
I'm using a chip drive driver, a SLE 4428 as a smart card and
towitoko2.0.2, and pcsc-lite-0.8.4.
I always got the response 6E 00 when i wanted to select the Master File
(3F00).
(And even if i change the instruction code or whatever)
However the tester provided with towitoko get the right answer (90 00).
After searching for 3 days i manage to get the right answer using
pcsc-lite.
Code generating wrong answer :
file sc_filesystem.c
-------------
LONG SCSelectFile(SCARDHANDLE hCard, BYTE fileId1, BYTE fileId2)
{
LONG rv; //The response status
DWORD dwLength = 2;
BYTE bufToRecv[50]={0}; //unsigned char * bufToRecv
BYTE cmdToSend[7]={1};
SCARD_IO_REQUEST sRecvPci;
SCARD_IO_REQUEST sSendPci;
//sRecvPci.dwProtocol = 0;
//sSendPci.dwProtocol = 0;
sRecvPci.dwProtocol = SCARD_PROTOCOL_RAW;
sSendPci.dwProtocol = SCARD_PROTOCOL_RAW;
cmdToSend[0] = 0xC0; // Class (Same result with 0x00)
cmdToSend[1] = 0xa4; // INS : Select APDU
cmdToSend[2] = 0x00; // P1 : 00 (Select by file id)
cmdToSend[3] = 0x00; // P2 : 00 (Return the FCI)
cmdToSend[4] = 0x02; // Length of the data field (Here 2 bytes)
cmdToSend[5] = fileId1; // 1st byte of the fileId.
cmdToSend[6] = fileId2; // 2nd byte of the fileId.
//cmdToSend[7] = 0x00; // Return up to 256 or 65536 response byte.
//cmdToSend[7] Empty
rv = SCardTransmit(hCard, &sSendPci, cmdToSend, 7, &sRecvPci,
bufToRecv, &dwLength);
if (rv == SCARD_S_SUCCESS && dwLength == 2)
{
int i;
printf("PCSC OK: %s\n", pcsc_stringify_error(rv));
for(i = 0; i < dwLength; i++)
{
printf("Result APDU : %x\n", bufToRecv[i]);
}
return rv;
}
else
{
printf("PCSC ERROR: %s\n", pcsc_stringify_error(rv));
return rv;
}
}
Now testLib.c
----------
dwShareMode = SCARD_SHARE_SHARED;
//dwPreferredProtocols = SCARD_PROTOCOL_T0;
printf("Test SCardConnect ... \n");
rv = SCardConnect(hContext, szReader, dwShareMode,
SCARD_PROTOCOL_RAW,
&hCard, &dwActiveProtocol);
if ( rv != SCARD_S_SUCCESS )
{
printf("PCSC ERROR: %s\n", pcsc_stringify_error(rv));
return 1;
}
printf("Connection to the Card Successful ...\n");
printf("Protocol in used : %li ...\n", dwActiveProtocol);
printf("Testing SCSelectFile ... \n");
rv = SCSelectFile(hCard, fileId[0], fileId[1]);
if ( rv != SCARD_S_SUCCESS )
{
printf("PCSC ERROR: %s\n", pcsc_stringify_error(rv));
return 1;
}
----------------------------------------------------------------
When i used this piece of code i always got 6e 00.
I noticed that the value of dwActiveProtocol was equal to 0, whatever
SCARD_PROTOCOL_xxx
i used in the SCardCONNECT function.
So i did this few changes in the SCSelectFile function
{
sRecvPci.dwProtocol = 0;
sSendPci.dwProtocol = 0;
//sRecvPci.dwProtocol = SCARD_PROTOCOL_RAW;
//sSendPci.dwProtocol = SCARD_PROTOCOL_RAW;
}
I just replace SCARD_PROTOCOL_RAW by 0 and now everything is working
fine.
What i would like to know is why this behavior ?
Is there a cleaner way to fix that ?
Thanks.
--------------------------------------
Christian Jean
Software Engineer
Celestix Networks PTE LTD : http://www.celestix.com
---------------------------------------
***************************************************************
Linux Smart Card Developers - M.U.S.C.L.E.
(Movement for the Use of Smart Cards in a Linux Environment)
http://www.linuxnet.com/smartcard/index.html
***************************************************************