Error sending APDU commands with Arduino. Change the module context

895 views Asked by At

I try to send APDU commands using Arduino Uno and PN532. PN532 finds the EMV card, but when I try to send the command I get:

Status code indicates error

The response dump shows this result (the first 8 bytes):

0x00 0x00 0xFF 0x03 0xFD 0xD5 0x41 0x27

The command I send(SELECT PPSE):

00 A4 04 00 0E 32 50 41 59 2E 53 59 53 2E 44 44 46 30 31 00

According to the documentation, the code 0x27 (8 byte) means:

This command is not acceptable due to the current context of the PN532 (Initiator vs. Target, unknown target number, Target not in the good state, ...)

How do I change the context to the one I need for sending commands?

My code:

void loop(void) {
  uint8_t success;
  uint8_t uid[] = {0, 0, 0, 0, 0, 0, 0};
  uint8_t uidLength;

  // EMV card
  bool apdusuccess;
  uint8_t apdu[255];
  uint8_t berBuffer[255];
  uint8_t berLength = 255;

  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, & uidLength);

  if (success && uid && (uidLength == 4)) {
    uint8_t apdu[] = {0x00, 0xA4, 0x04, 0x00, 0x0e, 0x32, 0x50, 0x41, 0x59, 0x2e, 0x53, 0x59, 0x53, 0x2e, 0x44, 0x44, 0x46, 0x30, 0x31, 0x00};
    apdusuccess = nfc.inDataExchange(apdu, sizeof(apdu), berBuffer, &berLength);
    Serial.print("APDU Success: ");
    Serial.println(apdusuccess);
  }  
}
1

There are 1 answers

1
NTP On

I found a solution and it worked with inListPassiveTarget:

void loop(void) {
  uint8_t success;
  uint8_t uid[] = {0, 0, 0, 0, 0, 0, 0};
  uint8_t uidLength;

  // EMV card
  bool apdusuccess;
  uint8_t apdu[255];
  uint8_t berBuffer[255];
  uint8_t berLength = 255;

  success = nfc.inListPassiveTarget();

  if (success) {
    uint8_t apdu[] = {0x00, 0xA4, 0x04, 0x00, 0x0e, 0x32, 0x50, 0x41, 0x59, 0x2e, 0x53, 0x59, 0x53, 0x2e, 0x44, 0x44, 0x46, 0x30, 0x31, 0x00};
    apdusuccess = nfc.inDataExchange(apdu, sizeof(apdu), berBuffer, &berLength);
    Serial.print("APDU Success: ");
    Serial.println(apdusuccess);
  }  
}