46 #endif // HAVE_CONFIG_H
56 #include "libnfc/chips/pn53x.h"
58 #define MAX_FRAME_LEN 264
59 #define TIMEOUT 60 // secs.
69 while (secs < TIMEOUT) {
80 main(
int argc,
const char *argv[])
87 if (context == NULL) {
88 ERR(
"Unable to init libnfc (malloc)");
94 printf(
"%s uses libnfc %s\n", argv[0], acLibnfcVersion);
101 ERR(
"%s",
"Unable to open NFC device.");
109 printf(
"\nSelect the communication mode:\n");
110 printf(
"[1] Virtual card mode.\n");
111 printf(
"[2] Wired card mode.\n");
112 printf(
"[3] Dual card mode.\n");
116 char input = getchar();
118 if ((input <
'1') || (input >
'3')) {
119 ERR(
"%s",
"Invalid selection.");
130 int iMode = input -
'0' + 0x01;
131 pn532_sam_mode mode = iMode;
136 case PSM_VIRTUAL_CARD: {
138 if (pn532_SAMConfiguration(pnd, mode, 0) < 0) {
144 printf(
"Now the SAM is readable for 1 minute from an external reader.\n");
149 case PSM_WIRED_CARD: {
152 nfc_perror(pnd,
"nfc_initiator_init_secure_element");
160 nfc_perror(pnd,
"nfc_device_set_property_bool");
167 .nmt = NMT_ISO14443A,
174 nfc_perror(pnd,
"nfc_initiator_select_passive_target");
178 }
else if (res == 0) {
179 ERR(
"No SAM found.");
183 }
else if (res == 1) {
184 printf(
"The following ISO14443A tag (SAM) was found:\n");
185 print_nfc_target(&nt,
true);
187 ERR(
"%s",
"More than one ISO14442 tag found as SAM.");
195 case PSM_DUAL_CARD: {
197 if (pn532_SAMConfiguration(pnd, mode, 0) < 0) {
203 uint8_t abtRx[MAX_FRAME_LEN];
207 .nmt = NMT_ISO14443A,
208 .nbr = NBR_UNDEFINED,
212 .abtAtqa = { 0x04, 0x00 },
213 .abtUid = { 0x08, 0xad, 0xbe, 0xef },
220 printf(
"Now both, NFC device (configured as target) and SAM are readables from an external NFC initiator.\n");
221 printf(
"Please note that NFC device (configured as target) stay in target mode until it receive RATS, ATR_REQ or proprietary command.\n");
237 pn532_SAMConfiguration(pnd, PSM_NORMAL, -1);