I am working on SCM Contactless RFID Card Reader using the Microsoft SmartCard APIs.
The usual process to ineract with the smart card, what I have understood, is:
1. Establish the Context using SCardEstablishContext()
2. List all the readers attached to the system using SCardListReaders()
3. Select a reader and wait for a card to be inserted into it.
4. Once a card is detected the function SCardGetStatusChange() returns.
5. Connect to the card through the selected reader using SCardConnect()
6. Talk to the card using SCardTransmit()
All the steps till 5 is working fine which means that I got the correct card handle. The card can be verified further by issuing SCardStatus() function which returns the negotiated protocol and the card's ATR, which is also correct. But when I am trying to send any APDU command using SCardTransmit() it returns an error (error code 14, which I guess is SCARD_E_CANT_DISPOSE).
I have no clue what is going wrong or what is missing. I tried different APDUs for e.g. the very basic APDU to read the card UID by issuing {0xFF, 0xCA, 0x00, 0x00, 0x00}. I verified this APDU using the SCM TestResMan debug tool and it returns me the correct UID of the card. I am using a MiFARE 1k card and SCM Contactless SCL011 Reader.
Please find the SCardTransmit() code snippet below (All the previous functions returned success).
SCARD_IO_REQUEST sioreq;
sioreq.dwProtocol = 2; // SCARD_PROTOCOL_T1
sioreq.cbPciLength = 8;
SCARD_IO_REQUEST rioreq;
rioreq.dwProtocol = 2; // SCARD_PROTOCOL_T1
rioreq.cbPciLength = 8;
byte sendbuffer[256], receivebuffer[256];
ULONG sendbufferLen, receivebufferLen, sizeofUID;
sendbuffer[0] = 0xFF; // CLA - Instruction Class
sendbuffer[1] = 0xCA; // Instruction code
sendbuffer[2] = 0x00; // P1 - 1st parameter
sendbuffer[3] = 0x00; // P2 - 2nd parameter
sendbuffer[4] = 0x00;
sendbufferLen = 0x05;
retval = objScWrapper->SCardTransmit(hCardHandle, &sioreq, sendbuffer,
sendbufferLen, NULL, receivebuffer,
&receivebufferLen);
Please let me know if anyone has any clue or pointers...
TIA !!