简体   繁体   English

Nexus 7(2013)上的HCE与PN532通信

[英]HCE on Nexus 7 (2013) with PN532 communication

I am communicating between PN532 on Arduino Uno with Nexus 7 running Kitkat 4.4.2, 我正在Arduino Uno上的PN532与运行Kitkat 4.4.2的Nexus 7之间进行通信,
The HCE program I had from here: https://github.com/grundid/host-card-emulation-sample 我从这里获得的HCE程序: 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: 我在Nexus 7上运行示例程序,在Arduino上我尝试发送APDU命令:

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 这是我的APDU服务文件: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? 但我无法从Nexus 7得到任何回应,而从Nexus 7也没有记录任何信号? Does anyone know what I am missing here? 有人知道我在这里想念的吗? Thanks 谢谢

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 () {...} . 使用Seeed-Studio PN532库 ,您无需在该库中创建自己的命令(即,使用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() . 要与标签/非接触式智能卡建立连接(或者枚举可用的标签/卡),您将从inListPassiveTarget()开始。 If the tag/smartcard supports APDUs, it will later automatically be activated for APDU-based communcation. 如果标签/智能卡支持APDU,则稍后会自动将其激活以进行基于APDU的通信。 Then you can use inDataExchange() to send and receive APDUs. 然后,您可以使用inDataExchange()发送和接收APDU。

So, if you included the PN532 library like this: 因此,如果您包括这样的PN532库:

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)
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM