Hello all,

I am having some trouble getting correct output back from my JCOP 21 card
connected to a Omnikey  CardMan 2020 USB reader.  If I initialize the card
in Eclipse [1], I see that the following APDU is being sent to it:

00 A4 04 00 07 A0 00 00 00 03 00 00 00

and the return is:

6F 19 84 08 A0 00 00 00 03 00 00 00 A5 0D 9F 6E 06 40 51 21 97 22 11 9F 65
01 FF 90 00

But if I try to send the same thing via pcsclite (using SCardConnect and
SCardTransmit), I get the following back:

61 1B

I also tried adding SCardBeginTransaction and SCardEndTransaction, but it
didn't help.
So why is the return different?  I assume that Eclipse may send the card
some other commands in order to set up the communication context, but I
don't know what these are.  Note that this problem is not isolated to one
APDU, I tried it with 3 different APDUs and every time I get something
different that Eclipse.

Can anyone suggest how I can communicate with the card properly?

Here is a code snippet of what I'm doing:

---------------------------------------
<snip>

BYTE init1[] = { 0x00, 0xA4, 0x04, 0x00, 0x08, 0xA0, 0x00, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x00 };

<snip>

printf("Connecting to card in first reader...");
rv = SCardConnect(hContext, mszReaders, SCARD_SHARE_SHARED,
      SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &hCard, &dwActiveProtocol);

if (rv != SCARD_S_SUCCESS) return error_rdisconnect(hContext, hCard);
else {
  printf("done.  Active protocol:  ");
  (dwActiveProtocol == SCARD_PROTOCOL_T0)? printf("T0\n") : printf("T1\n");
}

printf("\nSending Init1 APDU to card:\n");
rv = send_APDU(init1, sizeof(init1), hCard);
if (rv != SCARD_S_SUCCESS) return error_rdisconnect(hContext, hCard);

<snip>
//Send an APDU consisting of the data in sendBuffer
LONG send_APDU(BYTE *sendBuffer, int bufferLen, SCARDHANDLE card) {
  int i;
  LONG rv;
  SCARD_IO_REQUEST pioRecvPci;
  BYTE recvBuffer[255];
  DWORD dwRecvLength;

  printf("Transmitted value:  ");

  for (i = 0; i < bufferLen; i++) printf("%X ", sendBuffer[i]);
  printf("\n");

  printf("Returned value:  ");

  rv = SCardTransmit(card, SCARD_PCI_T0, sendBuffer, bufferLen, &pioRecvPci,
       recvBuffer, &dwRecvLength);

  if (rv != SCARD_S_SUCCESS) {
    return rv;
  }
  else {
    for (i = 0; i < dwRecvLength; i++) printf("%X ", recvBuffer[i]);
    printf("\n");
  }

  return rv;
}
------------------------------------------------------

Output:
------------------------------------------------------
<snip>
Connecting to card in first reader...done.  Active protocol:  T0

Sending Init1 APDU to card:
Transmitted value:  0 A4 4 0 8 A0 0 0 0 3 0 0 0 0
Returned value:  61 1B
<snip>
------------------------------------------------------

[1] www.eclipse.org with JCOP plugin

_______________________________________________
Muscle mailing list
[EMAIL PROTECTED]
http://lists.drizzle.com/mailman/listinfo/muscle

Reply via email to