简体   繁体   中英

Android NFC Card Emulation try to emulate a card

I'm trying to use NFC to emulate a card.

What I expect is that when I pass the phone on an NFC reader the reader reads the data (this data then I would modify in the future).

Passing the phone on the reader, for what I understand, the entry point should be in the Java class CardService.java . But the method processCommandApdu is never called (I have tried to insert a breakpoint there and even a toast, but that code is never called).

So at the moment the main thing that I can not understand is: Did I do something wrong? This thing can be done?

In order for the method processCommandApdu() to be called for incoming APDU commands, the reader needs to select your application first. Selection is done using the SELECT (by AID / DF name) command according to ISO/IEC 8716-4:

00 A4 04 00  <Lc>  <AID>  00

Where <Lc> is the length of <AID> and <AID> is the application identifier registered for your app.

The ISO/IEC 8716-4 application structure (ie application selection through a SELECT (by AID) command) is the only way Android allows to start interaction with an app over HCE. Consequently, it's not possible to emulate cards (card applications) that use different mechanisms. (At least not without modifying the Android system itself; eg though a customized ROM or through Xposed.)

AIDs for the CardEmulation sample app are registered through a file named res/xml/aid_list.xml in the example project. In this file you register AID groups, which in turn contain AID filter entries:

<aid-group android:description="@string/card_title" android:category="other">
    <aid-filter android:name="F222222222"/>
</aid-group>

Therefore, the default AID that is registered in the example app is F222222222 . Hence, you can use the following SELECT (byte AID) command to select the application:

00 A4 04 00  05  F2 22 22 22 22  00

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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