If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

[RESOLVED] ScardTransmit returning junk value

Hi,

I am trying to read data from a smartcard using scardTransmit.
But the data read is always 6D 00 CC CC (Be it for name, expiry date or any other data, always the same.)
This is probably some junk data? Am I missing something or have I done something incorrectly? Please help me.

SCardEstablishContext and SCardConnect are succesful.
Prints for pbRead in getCPRFirstNameEn() is : 6D 00 CC CC
Note : I have edited the above to include actual code.
I have also tried sending different APDU commands (for getting second name, expiry date etc) , but the print for all is the same.

To receive n>0 bytes of data from the card, the send and receive buffers must be formatted as follows.
The first four bytes of the pbSendBuffer buffer contain the CLA, INS, P1, and P2 values for the T=0 operation. The fifth byte must be set to n: the size, in bytes, of the data to be transferred from the card. If 256 bytes are to be transferred from the card, then this byte must be set to zero.
The cbSendLength parameter must be set to five, the size of the T=0 header information.
The pbRecvBuffer will receive the data returned from the card, immediately followed by the SW1 and SW2 status codes from the operation.
The pcbRecvLength should be at least n+2 and will be set to n+2 upon return.

Yes, it is the same SCardTransmit that MSDN describes.
I had missed out the size of data in the send buffer. I am expecting it to return 32 bytes of first name, so i have replaced it with :

Code:

BYTE pbGetFirstNameEn[] = { 0x00,0xB0,0x00,0x09,0x32}; // Get English First Name

But it still returns the same data.
Also, the number of CC in the pbRead buffer depends on the size assigned to it. If I declare it as pbRead[34] , then it prints as :
6D 00 CC CC CC CC ... {CC 32 times}.

Re: ScardTransmit returning junk value

Originally Posted by VictorN

Well, I have no udea what these first 4 bytes you are trying to send:mean, but what I do know is your fitth byte (0x32) is wrong!
0x32 is exactly decimal 50 while your buffer size for received data is 34.

Oh, then it shud be :

Code:

BYTE pbGetFirstNameEn[] = { 0x00,0xB0,0x00,0x09,0x22}; // Get English First Name

However, this returns the same output. The first 4 bytes are part of the APDU commands provided in the documentation of the card reader. So, i am sure that it is correct.
But I am wondering if there is anything i have missed . For connecting to a smart card, would i have missed something other than sCardEstablish,sCardConnect and sCardTransmit.