diff --git a/brmdoor_nfc.cpp b/brmdoor_nfc.cpp index 8f48fb9..c5ce1c2 100644 --- a/brmdoor_nfc.cpp +++ b/brmdoor_nfc.cpp @@ -35,12 +35,28 @@ NFCDevice::NFCDevice() NFCDevice::~NFCDevice() { + //nfc_close(_nfcDevice); nfc_exit(_nfcContext); } std::string NFCDevice::scanUID() { - return "1234"; + int res; + nfc_target nt; + + res = nfc_initiator_poll_target(_nfcDevice, _modulations, _modulationsLen, pollNr, pollPeriod, &nt); + if (res < 0) { + throw NFCError("NFC polling error"); + } + + // we are not interested in non-ISO-14443A cards + if (nt.nm.nmt != NMT_ISO14443A) { + return ""; + } + + const nfc_iso14443a_info& nai = nt.nti.nai; + + return string((const char*)nai.abtUid, nai.szUidLen); } const nfc_modulation NFCDevice::_modulations[5] = { diff --git a/runme.py b/runme.py index d317839..0b09a9e 100755 --- a/runme.py +++ b/runme.py @@ -1,5 +1,6 @@ #!/usr/bin/env python from brmdoor_nfc import NFCDevice +from binascii import hexlify nfc = NFCDevice() -print nfc.scanUID() +print hexlify(nfc.scanUID())