Allow to connect to a device using a connection string:
- Provide a nfc_get_default_device() that allow to grab the connstring stored in LIBNFC_DEFAULT_DEVICE environnement variable or returns the first available device if not set; - nfc_connect(NULL) now takes the default device (see nfc_get_default_device()); - Removes nfc_driver_desc_t from public types - Defines nfc_connstring as char[1024] - examples/*: use nfc_connstring - examples/nfc-poll: now uses only the default device (instead of all devices availables) - Removes parse_args() from nfc-utils.[hc]
This commit is contained in:
parent
dc842a844c
commit
55daa29a7c
20 changed files with 559 additions and 380 deletions
|
|
@ -65,15 +65,10 @@ void stop_polling (int sig)
|
|||
int
|
||||
main (int argc, const char *argv[])
|
||||
{
|
||||
size_t szFound;
|
||||
size_t i;
|
||||
bool verbose = false;
|
||||
nfc_device_desc_t *pnddDevices;
|
||||
|
||||
signal (SIGINT, stop_polling);
|
||||
|
||||
pnddDevices = parse_args (argc, argv, &szFound, &verbose);
|
||||
|
||||
// Display libnfc version
|
||||
const char *acLibnfcVersion = nfc_version ();
|
||||
|
||||
|
|
@ -83,59 +78,43 @@ main (int argc, const char *argv[])
|
|||
|
||||
printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
|
||||
|
||||
if (szFound == 0) {
|
||||
if (!(pnddDevices = malloc (MAX_DEVICE_COUNT * sizeof (*pnddDevices)))) {
|
||||
fprintf (stderr, "malloc() failed\n");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
const uint8_t uiPollNr = 20;
|
||||
const uint8_t uiPeriod = 2;
|
||||
const nfc_modulation_t nmModulations[5] = {
|
||||
{ .nmt = NMT_ISO14443A, .nbr = NBR_106 },
|
||||
{ .nmt = NMT_ISO14443B, .nbr = NBR_106 },
|
||||
{ .nmt = NMT_FELICA, .nbr = NBR_212 },
|
||||
{ .nmt = NMT_FELICA, .nbr = NBR_424 },
|
||||
{ .nmt = NMT_JEWEL, .nbr = NBR_106 },
|
||||
};
|
||||
const size_t szModulations = 5;
|
||||
|
||||
nfc_target_t nt;
|
||||
bool res;
|
||||
|
||||
pnd = nfc_connect (NULL);
|
||||
|
||||
if (pnd == NULL) {
|
||||
ERR ("%s", "Unable to connect to NFC device.");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
nfc_list_devices (pnddDevices, MAX_DEVICE_COUNT, &szFound);
|
||||
nfc_initiator_init (pnd);
|
||||
|
||||
if (szFound == 0) {
|
||||
printf ("No NFC device found.\n");
|
||||
}
|
||||
|
||||
for (i = 0; i < szFound; i++) {
|
||||
const uint8_t uiPollNr = 20;
|
||||
const uint8_t uiPeriod = 2;
|
||||
const nfc_modulation_t nmModulations[5] = {
|
||||
{ .nmt = NMT_ISO14443A, .nbr = NBR_106 },
|
||||
{ .nmt = NMT_ISO14443B, .nbr = NBR_106 },
|
||||
{ .nmt = NMT_FELICA, .nbr = NBR_212 },
|
||||
{ .nmt = NMT_FELICA, .nbr = NBR_424 },
|
||||
{ .nmt = NMT_JEWEL, .nbr = NBR_106 },
|
||||
};
|
||||
const size_t szModulations = 5;
|
||||
|
||||
nfc_target_t nt;
|
||||
bool res;
|
||||
|
||||
pnd = nfc_connect (&(pnddDevices[i]));
|
||||
|
||||
if (pnd == NULL) {
|
||||
ERR ("%s", "Unable to connect to NFC device.");
|
||||
printf ("Connected to NFC reader: %s\n", pnd->acName);
|
||||
printf ("NFC device will poll during %ld ms (%u pollings of %lu ms for %zd modulations)\n", (unsigned long) uiPollNr * szModulations * uiPeriod * 150, uiPollNr, (unsigned long) uiPeriod * 150, szModulations);
|
||||
res = nfc_initiator_poll_target (pnd, nmModulations, szModulations, uiPollNr, uiPeriod, &nt);
|
||||
if (res) {
|
||||
print_nfc_target ( nt, verbose );
|
||||
} else {
|
||||
if (pnd->iLastError) {
|
||||
nfc_perror (pnd, "nfc_initiator_poll_targets");
|
||||
nfc_disconnect (pnd);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
nfc_initiator_init (pnd);
|
||||
|
||||
printf ("Connected to NFC reader: %s\n", pnd->acName);
|
||||
printf ("NFC device will poll during %ld ms (%u pollings of %lu ms for %zd modulations)\n", (unsigned long) uiPollNr * szModulations * uiPeriod * 150, uiPollNr, (unsigned long) uiPeriod * 150, szModulations);
|
||||
res = nfc_initiator_poll_target (pnd, nmModulations, szModulations, uiPollNr, uiPeriod, &nt);
|
||||
if (res) {
|
||||
print_nfc_target ( nt, verbose );
|
||||
} else {
|
||||
if (pnd->iLastError) {
|
||||
nfc_perror (pnd, "nfc_initiator_poll_targets");
|
||||
nfc_disconnect (pnd);
|
||||
exit (EXIT_FAILURE);
|
||||
} else {
|
||||
printf ("No target found.\n");
|
||||
}
|
||||
printf ("No target found.\n");
|
||||
}
|
||||
nfc_disconnect (pnd);
|
||||
}
|
||||
|
||||
free (pnddDevices);
|
||||
nfc_disconnect (pnd);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue