Library built on top of libNfc, that allows to easily send APDU commands through a terminal.
Enter the repo directory then simply :
make
This code uses libnfc
If you're on Linux, you can install libnfc simply by doing :
git clone https://github.com/nfc-tools/libnfc.git
autoreconf -vis
./configure --enable-doc
make
sudo make install
The code contains an implementation of the APDU protocol according to Wikipedia.
However, I'm not entierly sure if I implemented correctly the extended apdu protocol. The PN532
doesn't support it anyway...
Use the NfcManager
to simplify the process of detecting, opening and transceiving data.
NfcManager manager;
if(manager.open()){
if(manager.isTargetPresent()){
// do things ...
}
manager.close();
}
Once the device opened, use the APDU
class to send and receive APDUs commands.
If you want to perform a select command, you would do :
APDU apdu;
apdu.setClass(0x00);
apdu.setInstruction(0xA4);
apdu.setParams(0x04, 0x00);
apdu.setCmd(hexStringToByteArray(appId));
apdu.buildAPDU();
manager.transceive(apdu);
To know more about APDUs instruction codes etc, read the beautiful ISO standard
When manager.transceive()
ends, the APDU
object will contain the response, if any. You can get it like this :
std::vector<uint8_t> responseBytes = apdu.getRespBytes();
std::string responseString = apdu.getRespString();
That said, NfcManager
already implements the select
command, you just need to do this :
manager.selectApplication(appId, apdu);
You can find a full examples here.