0

私は現在、シードされた NFC Shield V 2.0 を搭載した arduino uno デバイスで HCE を実行しようとしています。

https://github.com/Seeed-Studio/PN532/blob/master/PN532/examples/android_hce/android_hce.inoのサンプルコードを使用しています

#include <SPI.h>
#include <PN532_SPI.h>
#include <PN532Interface.h>
#include <PN532.h>

PN532_SPI pn532spi(SPI, 10);
PN532 nfc(pn532spi);


void setup()
{
    Serial.begin(115200);
    Serial.println("-------Peer to Peer HCE--------");

    nfc.begin();

    uint32_t versiondata = nfc.getFirmwareVersion();
    if (! versiondata) {
      Serial.print("Didn't find PN53x board");
      while (1); // halt
    }

    // Got ok data, print it out!
    Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
    Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
    Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);

    // Set the max number of retry attempts to read from a card
    // This prevents us from waiting forever for a card, which is
    // the default behaviour of the PN532.
    //nfc.setPassiveActivationRetries(0xFF);

    // configure board to read RFID tags
    nfc.SAMConfig();
}

void loop()
{
  bool success;

  uint8_t responseLength = 32;

  Serial.println("Waiting for an ISO14443A card");

  // set shield to inListPassiveTarget
  success = nfc.inListPassiveTarget();

  if(success) {

     Serial.println("Found something!");

    uint8_t selectApdu[] = { 0x00, /* CLA */
                              0xA4, /* INS */
                              0x04, /* P1  */
                              0x00, /* P2  */
                              0x07, /* Length of AID  */
                              0xF0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, /* AID defined on Android App */
                              0x00  /* Le  */ };

    uint8_t response[32];

    success = nfc.inDataExchange(selectApdu, sizeof(selectApdu), response, &responseLength);

    if(success) {

      Serial.print("responseLength: "); Serial.println(responseLength);

      nfc.PrintHexChar(response, responseLength);

      do {
        uint8_t apdu[] = "Hello from Arduino";
        uint8_t back[32];
        uint8_t length = 32;

        success = nfc.inDataExchange(apdu, sizeof(apdu), back, &length);

        if(success) {

          Serial.print("responseLength: "); Serial.println(length);

          nfc.PrintHexChar(back, length);
        }
        else {

          Serial.println("Broken connection?");
        }
      }
      while(success);
    }
    else {

      Serial.println("Failed sending SELECT AID");
    }
  }
  else {

    Serial.println("Didn't find anything!");
  }

  delay(1000);
}

void printResponse(uint8_t *response, uint8_t responseLength) {

   String respBuffer;

    for (int i = 0; i < responseLength; i++) {

      if (response[i] < 0x10)
        respBuffer = respBuffer + "0"; //Adds leading zeros if hex value is smaller than 0x10

      respBuffer = respBuffer + String(response[i], HEX) + " ";
    }

    Serial.print("response: "); Serial.println(respBuffer);
}

void setupNFC() {

  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }

  // Got ok data, print it out!
  Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
  Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
  Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);

  // configure board to read RFID tags
  nfc.SAMConfig();
}

私のAndroidコードはHCE開発ガイドから取得され、コード形式も試しましたhttps://github.com/grundid/host-card-emulation-sample

私の問題は、arduino コードがタグを認識さえしないことです。だから私が得ているのは次のとおりです:

Waiting for an ISO14443A card
Didn't find anything!
Waiting for an ISO14443A card
Didn't find anything!
Waiting for an ISO14443A card 

実際のところ、Android 側ではパケットを受信せず、ファンシーな NFC サウンドも再生されません。これは通常、少なくとも何かが起こっていることを示しています。だから私の質問は、誰かがHCEサポートとともにcyanogenmod 10でGalaxy S3を使用しようとしたかということです. 私は本当にアイデアがありません.コードをトリプルチェックし、ここSOで多くの質問を読みましたが、少なくともNFCシールドから何かを受け取りました.

「通常」モードでNFCを使用するアプリケーションがあるため、一般的なNFCモードが正常に機能することを知っています。この NFC プロトコルを arduino で実行すると、すべてのアプリケーションがパケットを受信します (ただし、adpu パケットではないため、正しくルーティングできません)。

4

2 に答える 2

3

Android 4.4 HCE は、NXP チップを搭載した Samsung Galaxy S3 では動作しません。Galaxy Nexus、Nexus 7(2012)、Galaxy S3 の両方でテストしました。これら 3 つのデバイスはすべて、Kitkat で HCE を実行できません。

デバイスの HCE サポートを確認できます。

boolean isHceSupported = getPackageManager().hasSystemFeature("android.hardware.nfc.hce");

于 2014-07-21T10:31:48.783 に答える
2

Android HCE ( Android 4.4 HCE APIによって提供される) は、CyanogenMod 10.* ではサポートされていません。その API は CyanogenMod 11 以降でのみ使用できますが、それでも Android HCE API の CyanogenMod 実装が NXP チップセット (Galaxy S3 など) を搭載したデバイスで動作するかどうかはわかりません。

CyanogenMod 10.* には別の HCE API があります。その API の使用方法の例については、 Nikolay のブログを参照してください。

IsoPcdA基本的に、Arduino プログラムが機能するには、テクノロジーに基づいて HCE を実装する必要があります。

Also note that if you ever switch from CyanogenMod HCE to Android HCE, you have to use ISO 7816-4 compliant APDUs. Thus, an "APDU" like you use it in your code above,

apdu[] = "Hello from Arduino";

would not work. CyanogenMod HCE, however, does not require the use of ISO 7816-4 APDUs on top of the ISO 14443-4 transport protocol and will, therefore, happily accept this string instead of an APDU.

于 2014-03-27T17:00:54.007 に答える