Go to the documentation of this file.
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);
void nfc_init(nfc_context **context)
Initialize libnfc. This function must be called before calling any other libnfc function.
NFC library context Struct which contains internal options, references, pointers, etc....
const char * nfc_version(void)
Returns the library version.
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.
void nfc_exit(nfc_context *context)
Deinitialize libnfc. Should be called after closing all open devices and before your application term...
NFC modulation structure.
const char * nfc_device_get_name(nfc_device *pnd)
Returns the device name.
nfc_device * nfc_open(nfc_context *context, const nfc_connstring connstring)
Open a NFC device.
int nfc_initiator_select_passive_target(nfc_device *pnd, const nfc_modulation nm, const uint8_t *pbtInitData, const size_t szInitData, nfc_target *pnt)
Select a passive or emulated tag.
void nfc_perror(const nfc_device *pnd, const char *pcString)
Display the last error occured on a nfc_device.
int nfc_initiator_init_secure_element(nfc_device *pnd)
Initialize NFC device as initiator with its secure element initiator (reader)
#define ERR(...)
Print a error message.
void nfc_close(nfc_device *pnd)
Close from a NFC device.
Provide some examples shared functions like print, parity calculation, options parsing.
int nfc_device_set_property_bool(nfc_device *pnd, const nfc_property property, const bool bEnable)
Set a device's boolean-property value.