Question

I am communicating between PN532 on Arduino Uno with Nexus 7 running Kitkat 4.4.2,
The HCE program I had from here: https://github.com/grundid/host-card-emulation-sample
I run the sample program on Nexus 7, and on Arduino I try to send APDU command:

uint8_t PN532::APDU ()
{
uint8_t message[] = {
0x00, /* CLA */
0xA4, /* INS */
0x04, /* P1  */
0x00, /* P2  */
0x07, /* Lc  */
0xF0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
0x00  /* Le  */ };

/* Prepare the first command */

/* Send the command */
if (HAL(writeCommand)(message, 13)) {
    Serial.println(F("Go here 1"));
    return 0;
}
Serial.println(F("Go here 2"));
/* Read the response packet */
return (0 < HAL(readResponse)(message, sizeof(message)));}

Here is my APDU service file: apduservice.html

<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
android:description="@string/servicedesc"
android:requireDeviceUnlock="false" >

<aid-group
    android:category="other"
    android:description="@string/aiddescription" >
    <aid-filter android:name="F0010203040506" />
</aid-group>

but I cannot get any response from the Nexus 7, and from Nexus 7 I also didn't record any signals? Does anyone know what I am missing here? Thanks

Was it helpful?

Solution

Using the Seeed-Studio PN532 library, you shouldn't need to create your own commands within the library (ie. what you did with uint8_t PN532::APDU () {...}.

Instead, you can use the methods that are already there. To establish a connection with a tag/contactless smartcard (or rather to enumerate the available tags/cards), you would start with inListPassiveTarget(). If the tag/smartcard supports APDUs, it will later automatically be activated for APDU-based communcation. Then you can use inDataExchange() to send and receive APDUs.

So, if you included the PN532 library like this:

PN532_xxx pn532hal(...);
PN532 nfc(pn532hal);

You could then use the library like this:

bool success = nfc.inListPassiveTarget();
if (success) {
    uint8_t apdu = {
        0x00, /* CLA */
        0xA4, /* INS */
        0x04, /* P1  */
        0x00, /* P2  */
        0x07, /* Lc  */
        0xF0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
        0x00  /* Le  */
    };
    uint8_t response[255];
    uint8_t responseLength = 255;
    success = nfc.inDataExchange(apdu, sizeof(apdu), response, &responseLength);
    if (success) {
        // response should now contain the R-APDU you received in response to the above C-APDU (responseLength data bytes)
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top