0

I am trying to read/write NFC NTAG using ACR 122U NFC reader. I am keep geting error in SCardTransmitreturn values junk or return code 6. I need to know what are the apdu commands values to pass in SendBuff of SCardTransmit method

I check the apdu values I found from googling but there is no clear and working solution I have found so far

I have checked many solutions on web tried different buffer values

ClearBuffers();
SendBuff[0] = 0xFF;                         // CLA
SendBuff[2] = 0x00;                         // P1: same for all source types 
SendBuff[1] = 0x00;                         // INS: for stored key input
SendBuff[3] = 0x00;                         // P2 : Memory location;  P2: for stored key input
SendBuff[4] = 0x00;                         // P3: for stored key input

I am getting 6 return value when I include all values I lastly I am getting kind of junk data in Received Buffer

Drake Wu
  • 6,927
  • 1
  • 7
  • 30
user786
  • 3,902
  • 4
  • 40
  • 72
  • Did you initialize the `SCARD_IO_REQUEST` structure, and please also provide a [minimal sample](https://stackoverflow.com/help/minimal-reproducible-example) or at least the code details where you've got the error. – Drake Wu Aug 23 '19 at 01:57
  • Does this solution work for you?https://social.msdn.microsoft.com/Forums/vstudio/en-US/d1c12d43-5218-4edf-9f27-9ddda4ea9bb2/winscarddll-scardtransmit-keeps-returning-returns-0x000006f7-1783?forum=vssmartdevicesnative – Drake Wu Aug 23 '19 at 01:59
  • @DrakeWu-MSFT Please tell how can I read SW1 and SW2 values from SCardTransmit. I only get return value of `6` from SCardTransmit call – user786 Aug 23 '19 at 05:03
  • I don't know the code details, so I cannot tell what's wrong here. But you can refer to this code sample. https://gist.github.com/im-infamou5/4681713 – Drake Wu Aug 23 '19 at 05:34
  • @DrakeWu-MSFT I have the code and its fine and functional.I am only interested in APDU command for authenticating block for NTAG 213 ISO Tags. If found soon commands for reading and writing in addition to Authenticating then its a bliss – user786 Aug 23 '19 at 05:50

1 Answers1

0

As per ISO-7816-4 The value 'FF' for CLA is invalid (see protocol and parameter selection in ISO/IEC 7816-3). However, As per manual of the ACR 122 Reader its a valid Psuedo APDU representing "Direct Transmit Command"

P3 is supposed to be length of the contactless command. Since, you specified it as 0, there is no command sent to the NTAG.

The Direct Transmit Response is expected to be 2 bytes indicating SW1 and SW2.

SCardTransmit document The order of bytes is CLA, INS, P1, P2, P3.

pbRecvBuffer - Pointer to any data returned from the card. For T=0, the receive buffer must be at least two bytes long to receive the SW1 and SW2 status bytes. pcbRecvLength - Supplies the length, in bytes, of the pbRecvBuffer parameter and receives the actual number of bytes received from the smart card.

Since you are including the contactless command, there is undefined behavior.

Read Refer to section 5.2. Accessing Mifare Ultralight Tags in manual of the ACR 122 Reader

As per this ACR 122 Contains NXP's PN532 chip

To authenticate and fast read the NTAG you can pick up APDU's from this Java Script Example

Authenticate
0xff, // Class
0x00, // Direct Transmit (see ACR122U docs)
0x00, // ...
0x00, // ...
0x07, // Length of Direct Transmit payload
// Payload (7 bytes)
0xd4, // Data Exchange Command (see PN533 docs)
0x42, // InCommunicateThru
0x1b, // PWD_AUTH
password(4 bytes),

Fast Read(NXP Proprietary, check if this reader supports)
0xff, // Class
0x00, // Direct Transmit (see ACR122U docs)
0x00, // ...
0x00, // ...
0x07, // Length of Direct Transmit payload
// Payload (7 bytes)
0xd4, // Data Exchange Command (see PN533 docs)
0x42, // InCommunicateThru
0x3a, // FAST_READ
startPage,
endPage,

Padmanabha V
  • 430
  • 4
  • 11