Android的主机卡仿真与Arduino的 [英] Android Host Card Emulation with Arduino

查看:394
本文介绍了Android的主机卡仿真与Arduino的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立我的Nexus4 HCE和Arduino的PN532芯片之间的通信。上的Arduino的串口监视器,我可以看到一些数据,交易发生。但在Andorid的一面,我得到

I am trying to build a communication between my Nexus4 HCE and Arduino PN532 Chip. on The Serial Monitor of Arduino,I could see some data transaction happening. But on ANdorid side, I get

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>

下面是我的Arduino侧面code

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

下面是Arduino的串行监视器日志

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 

参考:许多SOF的答案/ https://github.com/grundid/host-卡仿真样品

所有灯将高度有所帮助。

Any lights will highly help.

推荐答案

使用的Andr​​oid HCE您模拟一个ISO 14443-4(ISO-DEP)接触式智能卡。这种智能卡只能识别ISO 7816-4 APDU命令。所以,你的Andr​​oid应用某些艾滋病(智能卡应用DF名称)注册。为了与您的应用程序进行通信,需要通过为这些艾滋病的一个发出SELECT [DF通过名称] APDU选择您的应用程序。此SELECT命令后,所有格式正确的APDU命令将被转发到你的应用程序的HCE服务,直到另一个AID与新鲜的选择[按DF名]命令选择。

With Android HCE you emulate an ISO 14443-4 (ISO-DEP) contactless smartcard. This smartcard only understands ISO 7816-4 APDU commands. So your Android app registers for certain AIDs (smartcard application DF names). In order to communicate with your app, you need to select your app by issuing a SELECT [by DF name] APDU for one of these AIDs. After this SELECT command, all properly formatted APDU commands will be forwarded to your app's HCE service until another AID is selected with a fresh SELECT [by DF name] command.

您的Arduino的应用程序,但是,试图访问MIFARE经典卡(即,它会发出认证,读写命令)。 MIFARE经典使用不同的协议(既不符合ISO 14443-4,也不使用ISO 7816-4的APDU),所以这个协议不能用于使用Android HCE仿真智能卡进行交互。

Your Arduino application, however, tries to access a MIFARE Classic card (i.e. it issues authenticate, write and read commands). MIFARE Classic uses a different protocol (neither compliant to ISO 14443-4 nor using ISO 7816-4 APDUs), so this protocol cannot be used to interact with an Android HCE emulated smartcard.

据我所知,Arduino的库为NFC盾有curently没有实现ISO-DEP的沟通,所以你需要实现自己的PN532的那个协议和操作模式。

As far as I know, the Arduino library for the NFC shield curently does not implement ISO-DEP communication, so you would need to implement that protocol and operation mode of the PN532 on your own.

这篇关于Android的主机卡仿真与Arduino的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆