47 #endif // HAVE_CONFIG_H
57 #include "libnfc/chips/pn53x.h"
59 #define MAX_FRAME_LEN 264
60 #define TIMEOUT 60 // secs.
70 while (secs < TIMEOUT) {
81 main(
int argc,
const char *argv[])
88 if (context == NULL) {
89 ERR(
"Unable to init libnfc (malloc)");
95 printf(
"%s uses libnfc %s\n", argv[0], acLibnfcVersion);
102 ERR(
"%s",
"Unable to open NFC device.");
110 printf(
"\nSelect the communication mode:\n");
111 printf(
"[1] Virtual card mode.\n");
112 printf(
"[2] Wired card mode.\n");
113 printf(
"[3] Dual card mode.\n");
117 int input = getchar();
119 if ((input <
'1') || (input >
'3')) {
120 ERR(
"%s",
"Invalid selection.");
131 int iMode = input -
'0' + 0x01;
132 pn532_sam_mode mode = iMode;
137 case PSM_VIRTUAL_CARD: {
139 if (pn532_SAMConfiguration(pnd, mode, 0) < 0) {
145 printf(
"Now the SAM is readable for 1 minute from an external reader.\n");
150 case PSM_WIRED_CARD: {
153 nfc_perror(pnd,
"nfc_initiator_init_secure_element");
161 nfc_perror(pnd,
"nfc_device_set_property_bool");
168 .nmt = NMT_ISO14443A,
175 nfc_perror(pnd,
"nfc_initiator_select_passive_target");
179 }
else if (res == 0) {
180 ERR(
"No SAM found.");
184 }
else if (res == 1) {
185 printf(
"The following ISO14443A tag (SAM) was found:\n");
186 print_nfc_target(&nt,
true);
188 ERR(
"%s",
"More than one ISO14442 tag found as SAM.");
196 case PSM_DUAL_CARD: {
198 if (pn532_SAMConfiguration(pnd, mode, 0) < 0) {
204 uint8_t abtRx[MAX_FRAME_LEN];
208 .nmt = NMT_ISO14443A,
209 .nbr = NBR_UNDEFINED,
213 .abtAtqa = { 0x04, 0x00 },
214 .abtUid = { 0x08, 0xad, 0xbe, 0xef },
221 printf(
"Now both, NFC device (configured as target) and SAM are readables from an external NFC initiator.\n");
222 printf(
"Please note that NFC device (configured as target) stay in target mode until it receive RATS, ATR_REQ or proprietary command.\n");
238 pn532_SAMConfiguration(pnd, PSM_NORMAL, -1);