Check the connection from the PC (PC / SC) to Android HSE.
This time, we confirmed the operation with the following models.
--Build environment
--NFC reader
Please refer to the previous article. Android HCE Survey Memo (Part 1)
The AID is "F222222222".
For a quick check, try using python.
Add a module to operate PC / SC from python. SWING is required for pyscard, so install it in advance. SWIG
After installing SWIG, continue to add modules with the following command.
pip install pyscard
The pyscard documentation can be found at the following URL:
https://pyscard.sourceforge.io/#documentation
Create a python script.
HCE_connect.py
from smartcard.CardType import AnyCardType
from smartcard.CardConnection import CardConnection
from smartcard.CardRequest import CardRequest
from smartcard.util import toHexString
#Card connection
cardtype = AnyCardType()
cardrequest = CardRequest( timeout=1, cardType=cardtype )
cardservice = cardrequest.waitforcard()
cardservice.connection.connect( CardConnection.T1_protocol )
print ("ATR:", toHexString( cardservice.connection.getATR() ))
#Select by specifying AID
SELECT = [0x00, 0xA4, 0x04, 0x00]
CARD_AID = [0xF2, 0x22, 0x22, 0x22, 0x22 ]
LEN = [len(CARD_AID)]
#Assembling APDU
apdu = SELECT + LEN + CARD_AID
print("send apdu:", toHexString(apdu))
#Send and receive
data, sw1, sw2 = cardservice.connection.transmit(apdu)
print("SW1SW2: %x %x" % (sw1, sw2))
print("received:", toHexString(data))
#Disconnect
cardservice.connection.disconnect()
print("...disconnected.")
Launch the android-Card Emulation app on your Android. Place Android on the card reader and let it be recognized.
After confirming that HCE recognizes it, execute the script.
python HCE_connect.py
Result output
ATR: 3B 88 80 01 00 00 00 00 80 81 71 00 79
send apdu: 00 A4 04 00 05 F2 22 22 22 22
SW1SW2: 90 0
received: 30 30 30 30 30 30 30 30
...disconnected.
I was able to read it normally.
Make sure you can access it in C # as well. Android HCE Survey Memo (Part 3)
Recommended Posts