APDU-Library
APDU-Library copied to clipboard
Library built on top of libNfc to easily send APDU commands.
APDU Library
Library built on top of libNfc, that allows to easily send APDU commands through a terminal.
Compile
Enter the repo directory then simply :
make
Dependency : Libnfc
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
Notice
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...
How to use
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);
Examples
You can find a full examples here.