【问题标题】:HCE on Nexus 7 (2013) with PN532 communicationNexus 7 (2013) 上的 HCE 与 PN532 通信
【发布时间】:2014-04-04 12:28:10
【问题描述】:

我正在 Arduino Uno 上的 PN532 与运行 Kitkat 4.4.2 的 Nexus 7 之间进行通信,
我从这里获得的 HCE 计划: https://github.com/grundid/host-card-emulation-sample
我在 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)));}

这是我的 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>

但我无法从 Nexus 7 得到任何响应,并且从 Nexus 7 我也没有记录任何信号?有谁知道我在这里想念什么?谢谢

【问题讨论】:

  • 你在 Arduino 端使用什么库? writeCommand 和 readResponse 在做什么? PN532 是如何在发送这些命令之前激活 HCE 手机的?
  • 这是我得到的库:&lt;https://github.com/don/Ndef&gt; and &lt;https://github.com/Seeed-Studio/PN532&gt; writeCommand 是将消息缓冲区推送到其他设备,而 readResponse 是接收响应。要激活 HCE 手机,如果我尝试推送 A4 1 0 则手机响应随机 UID,但是当我运行 Hcedemo 程序时,它没有响应,所以我停止推送 A4 1 0,并推送上面的消息。

标签: android arduino nfc apdu hce


【解决方案1】:

使用Seeed-Studio PN532 library,您不需要在库中创建自己的命令(即您对uint8_t PN532::APDU () {...} 所做的操作。

相反,您可以使用已有的方法。要建立与标签/非接触式智能卡的连接(或者更确切地说是枚举可用的标签/卡),您可以从inListPassiveTarget() 开始。如果标签/智能卡支持 APDU,稍后将自动激活它以进行基于 APDU 的通信。然后你就可以使用inDataExchange()来发送和接收APDU了。

所以,如果您像这样包含 PN532 库:

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

然后你可以像这样使用这个库:

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

【讨论】:

  • 谢谢,这正在工作:) 我可以再问一个问题:此后下一条消息的 APDU 是什么?从现在开始,HCE 和 PN532 之间的命令(写入/读取数据)将基于 APDU - ISO 7816-4,对吧?
  • 这取决于如何设计你的协议。这可以是任何 APDU,只要它符合 ISO 7816-4。
猜你喜欢
  • 2013-12-05
  • 1970-01-01
  • 1970-01-01
  • 2014-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多