61 #define MAX_FRAME_LEN (264)
62 #define SAK_ISO14443_4_COMPLIANT 0x20
64 static uint8_t abtRx[MAX_FRAME_LEN];
68 static bool quiet_output =
false;
69 static bool init_mfc_auth =
false;
75 printf(
"\nQuitting...\n");
85 target_io(
nfc_target *pnt,
const uint8_t *pbtInput,
const size_t szInput, uint8_t *pbtOutput,
size_t *pszOutput)
93 print_hex(pbtInput, szInput);
96 switch (pbtInput[0]) {
100 strcpy((
char *)pbtOutput,
"You read block ");
101 pbtOutput[15] = pbtInput[1];
105 printf(
"Initiator HLTA me. Bye!\n");
116 init_mfc_auth =
true;
120 *pszOutput = pnt->nti.nai.szAtsLen + 1;
121 pbtOutput[0] = pnt->nti.nai.szAtsLen + 1;
122 if (pnt->nti.nai.szAtsLen) {
123 memcpy(pbtOutput + 1, pnt->nti.nai.abtAts, pnt->nti.nai.szAtsLen);
128 printf(
"Initiator DESELECT me. Bye!\n");
134 printf(
"Unknown frame, emulated target abort.\n");
140 if ((!quiet_output) && *pszOutput) {
142 print_hex(pbtOutput, *pszOutput);
151 uint8_t abtTx[MAX_FRAME_LEN];
160 loop = target_io(pnt, abtRx, (
size_t) szRx, abtTx, &szTx);
175 init_mfc_auth =
false;
187 main(
int argc,
char *argv[])
190 const char *acLibnfcVersion;
193 signal(SIGINT, (
void (__cdecl *)(
int)) intr_hdlr);
195 signal(SIGINT, intr_hdlr);
199 if (context == NULL) {
200 ERR(
"Unable to init libnfc (malloc)");
206 printf(
"%s uses libnfc %s\n", argv[0], acLibnfcVersion);
212 ERR(
"Unable to open NFC device");
231 .nmt = NMT_ISO14443A,
232 .nbr = NBR_UNDEFINED,
236 .abtAtqa = { 0x00, 0x04 },
237 .abtUid = { 0x08, 0xab, 0xcd, 0xef },
280 printf(
"%s will emulate this ISO14443-A tag:\n", argv[0]);
281 print_nfc_target(&nt,
true);
290 printf(
"NFC device (configured as target) is now emulating the tag, please touch it with a second NFC device (initiator)\n");
291 if (!nfc_target_emulate_tag(pnd, &nt)) {
const char * nfc_device_get_name(nfc_device *pnd)
Returns the device name.
void nfc_close(nfc_device *pnd)
Close from a NFC device.
nfc_device * nfc_open(nfc_context *context, const nfc_connstring connstring)
Open a NFC device.
int nfc_abort_command(nfc_device *pnd)
Abort current running command.
void nfc_perror(const nfc_device *pnd, const char *pcString)
Display the last error occured on a nfc_device.
void nfc_exit(nfc_context *context)
Deinitialize libnfc. Should be called after closing all open devices and before your application term...
void nfc_init(nfc_context **context)
Initialize libnfc. This function must be called before calling any other libnfc function.
const char * nfc_version(void)
Returns the library version.
int nfc_device_set_property_bool(nfc_device *pnd, const nfc_property property, const bool bEnable)
Set a device's boolean-property value.
int nfc_target_send_bytes(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout)
Send bytes and APDU frames.
int nfc_target_init(nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRx, int timeout)
Initialize NFC device as an emulated tag.
int nfc_target_receive_bytes(nfc_device *pnd, uint8_t *pbtRx, const size_t szRx, int timeout)
Receive bytes and APDU frames.
Provide some examples shared functions like print, parity calculation, options parsing.
#define ERR(...)
Print a error message.
NFC library context Struct which contains internal options, references, pointers, etc....