Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于Arduino的Android主机卡仿真_Android_Arduino_Nfc_Apdu_Hce - Fatal编程技术网

基于Arduino的Android主机卡仿真

基于Arduino的Android主机卡仿真,android,arduino,nfc,apdu,hce,Android,Arduino,Nfc,Apdu,Hce,我正在尝试在我的Nexus4 HCE和Arduino PN532芯片之间建立通信。在Arduino的串行监视器上,我可以看到一些数据事务正在发生。但在安道尔这边,我明白了 CET4T: Unsupported Class byte (0x60) CET4T: Unsupported Class byte (0xA0) BrcmNfcNfa﹕ UICC[0x0] is not activated 下面是我的apduservice.xml <host-apdu-service xmlns

我正在尝试在我的Nexus4 HCE和Arduino PN532芯片之间建立通信。在Arduino的串行监视器上,我可以看到一些数据事务正在发生。但在安道尔这边,我明白了

CET4T: Unsupported Class byte (0x60)

CET4T: Unsupported Class byte (0xA0)

BrcmNfcNfa﹕ UICC[0x0] is not activated
下面是我的apduservice.xml

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

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

</host-apdu-service>
参考文献:许多SOF答案/


任何灯光都会很有帮助

使用Android HCE,您可以模拟ISO 14443-4(ISO-DEP)非接触式智能卡。此智能卡仅理解ISO 7816-4 APDU命令。因此,您的Android应用程序注册某些辅助工具(智能卡应用程序DF名称)。为了与您的应用程序通信,您需要为这些辅助工具之一发出select[by DF name]APDU来选择您的应用程序。执行此选择命令后,所有格式正确的APDU命令将转发到应用程序的HCE服务,直到使用新的SELECT[按DF名称]命令选择另一个AID

但是,您的Arduino应用程序尝试访问MIFARE Classic卡(即,它发出身份验证、写入和读取命令)。MIFARE Classic使用不同的协议(既不符合ISO 14443-4,也不使用ISO 7816-4 APDU),因此此协议不能用于与Android HCE模拟智能卡交互


据我所知,NFC屏蔽的Arduino库目前没有实现ISO-DEP通信,因此您需要自己实现PN532的协议和操作模式。

使用Android HCE,您可以模拟ISO 14443-4(ISO-DEP)非接触式智能卡。此智能卡仅理解ISO 7816-4 APDU命令。因此,您的Android应用程序注册某些辅助工具(智能卡应用程序DF名称)。为了与您的应用程序通信,您需要为这些辅助工具之一发出select[by DF name]APDU来选择您的应用程序。执行此选择命令后,所有格式正确的APDU命令将转发到应用程序的HCE服务,直到使用新的SELECT[按DF名称]命令选择另一个AID

但是,您的Arduino应用程序尝试访问MIFARE Classic卡(即,它发出身份验证、写入和读取命令)。MIFARE Classic使用不同的协议(既不符合ISO 14443-4,也不使用ISO 7816-4 APDU),因此此协议不能用于与Android HCE模拟智能卡交互

据我所知,NFC屏蔽的Arduino库目前没有实现ISO-DEP通信,因此您需要自己实现PN532的协议和操作模式

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

/*Chip select pin can be connected to D10 or D9 which is hareware optional*/
/*if you the version of NFC Shield from SeeedStudio is v2.0.*/
#define PN532_CS 10
PN532 nfc(PN532_CS);

uint8_t written=0;
#define  NFC_DEMO_DEBUG 1

void setup(void) {
#ifdef NFC_DEMO_DEBUG
  Serial.begin(9600);
  Serial.println("Hello!");
#endif
  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
#ifdef NFC_DEMO_DEBUG
    Serial.print("Didn't find PN53x board");
#endif
    while (1); // halt
  }
#ifdef NFC_DEMO_DEBUG
  // 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);
  Serial.print("Supports "); 
  Serial.println(versiondata & 0xFF, HEX);
#endif
  // configure board to read RFID tags and cards
  nfc.SAMConfig();
}

void loop(void) 
{
  uint32_t id;
  // look for MiFare type cards
  id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);

  if (id != 0) 
  {
#ifdef NFC_DEMO_DEBUG
    Serial.print("Read card #"); 
    Serial.println(id);
    Serial.println();
#endif
    uint8_t keys[] = {
    0x00, /* CLA */
    0xA4, /* INS */
    0x04, /* P1  */
    0x00, /* P2  */
    0x08, /* Lc  */
    0x4C, 0x65, 0x6C, 0x61, 0x6E, 0x74, 0x6F, 0x73,
    0x00  /* Le  */ };
    uint8_t writeBuffer[16];
    for(uint8_t i = 0;i < 16;i ++)
    { 
      writeBuffer[i]=i; //Fill buffer with 0,1,2....F
    }
    if(nfc.authenticateBlock(1, id ,0x08,KEY_A,keys)) //authenticate block 0x08
    {
      //if authentication successful

      if(written == 0) //Not written
      {
        written = nfc.writeMemoryBlock(1,0x08,writeBuffer); // Write writeBuffer[] to block 0x08
        if(written)
#ifdef NFC_DEMO_DEBUG
          Serial.println("Write Successful");   
#endif
      }


      uint8_t block[16];
      //read memory block 0x08
      if(nfc.readMemoryBlock(1,0x08,block))
      {
#ifdef NFC_DEMO_DEBUG
        Serial.println("Read block 0x08:"); 
        //if read operation is successful
        for(uint8_t i=0;i<16;i++)
        {
          //print memory block
          Serial.print(block[i],HEX);
          Serial.print(" ");
        }
        Serial.println();
#endif
      }
    }
  }

  delay(500);
}
Hello!
Found chip PN532
Firmware ver. 1.6
Supports 7
Found 1 tags
Sens Response: 0x4
Sel Response: 0x60
 0x8 0x1B 0x14 0x83Read card #135992451

Write Successful
Read block 0x08:
6E 0 7C 0 AA AA AA AA AA AA AA AA AA AA AA AA 
Found 1 tags
Sens Response: 0x4
Sel Response: 0x60
 0x8 0x26 0x40 0x85Read card #136724613

Read block 0x08:
6E 0 7C 0 AA AA AA AA AA AA AA AA AA AA AA AA