updates library examples to use libnfc 1.7.0 API

This commit is contained in:
Romuald Conty 2012-12-23 21:30:10 +00:00
parent 9fda402cd3
commit 3dd6edcb3a
14 changed files with 73 additions and 59 deletions

View file

@ -1,4 +1,4 @@
AC_INIT([libfreefare],[0.3.4])
AC_INIT([libfreefare],[0.3.5])
AC_CONFIG_MACRO_DIR([m4])
@ -58,7 +58,7 @@ AC_CHECK_LIB([crypto], [DES_ecb_encrypt], [], [AC_MSG_ERROR([Cannot find libcryp
AC_CHECK_HEADERS([openssl/aes.h openssl/des.h openssl/rand.h], [], [AC_MSG_ERROR([Cannot find openssl headers.])])
# Checks for pkg-config modules.
LIBNFC_REQUIRED_VERSION="1.6.0"
LIBNFC_REQUIRED_VERSION="1.7.0"
PKG_CHECK_MODULES([LIBNFC], [libnfc >= $LIBNFC_REQUIRED_VERSION], [], [AC_MSG_ERROR([libnfc >= $LIBNFC_REQUIRED_VERSION is mandatory.])])
PKG_CONFIG_REQUIRES="libnfc"

View file

@ -1,5 +1,6 @@
/*-
* Copyright (C) 2010, Romain Tartiere, Romuald Conty.
* Copyright (C) 2012, Romuald Conty.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
@ -164,15 +165,16 @@ main(int argc, char *argv[])
nfc_connstring devices[8];
size_t device_count;
nfc_init(NULL);
device_count = nfc_list_devices (NULL, devices, 8);
nfc_context *context;
nfc_init (&context);
device_count = nfc_list_devices (context, devices, 8);
if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found.");
for (size_t d = 0; d < device_count; d++) {
device = nfc_open (NULL, devices[d]);
device = nfc_open (context, devices[d]);
if (!device) {
warnx ("nfc_open() failed.");
error = EXIT_FAILURE;
@ -247,6 +249,6 @@ main(int argc, char *argv[])
nfc_close (device);
}
nfc_exit(NULL);
nfc_exit (context);
exit (error);
}

View file

@ -114,15 +114,16 @@ main(int argc, char *argv[])
nfc_connstring devices[8];
size_t device_count;
nfc_init(NULL);
device_count= nfc_list_devices (NULL, devices, 8);
nfc_context *context;
nfc_init (&context);
device_count= nfc_list_devices (context, devices, 8);
if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found.");
for (size_t d = 0; d < device_count; d++) {
device = nfc_open (NULL, devices[d]);
device = nfc_open (context, devices[d]);
if (!device) {
warnx ("nfc_open() failed.");
error = EXIT_FAILURE;
@ -228,6 +229,6 @@ error:
nfc_close (device);
}
nfc_exit(NULL);
nfc_exit (context);
exit (error);
}

View file

@ -195,14 +195,15 @@ main(int argc, char *argv[])
nfc_connstring devices[8];
size_t device_count;
nfc_init(NULL);
nfc_context *context;
nfc_init (&context);
device_count = nfc_list_devices (NULL, devices, 8);
device_count = nfc_list_devices (context, devices, 8);
if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found.");
for (size_t d = 0; d < device_count; d++) {
device = nfc_open (NULL, devices[d]);
device = nfc_open (context, devices[d]);
if (!device) {
warnx ("nfc_open() failed.");
error = EXIT_FAILURE;
@ -408,6 +409,6 @@ error:
}
free (card_write_keys);
nfc_exit(NULL);
nfc_exit (context);
exit (error);
}

View file

@ -40,15 +40,16 @@ main(int argc, char *argv[])
nfc_connstring devices[8];
size_t device_count;
nfc_init(NULL);
device_count = nfc_list_devices (NULL, devices, 8);
nfc_context *context;
nfc_init (&context);
device_count = nfc_list_devices (context, devices, 8);
if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found.");
for (size_t d = 0; d < device_count; d++) {
device = nfc_open (NULL, devices[d]);
device = nfc_open (context, devices[d]);
if (!device) {
warnx ("nfc_open() failed.");
error = EXIT_FAILURE;
@ -131,7 +132,7 @@ main(int argc, char *argv[])
freefare_free_tags (tags);
nfc_close (device);
}
nfc_exit(NULL);
nfc_exit (context);
exit (error);
} /* main() */

View file

@ -95,15 +95,16 @@ main(int argc, char *argv[])
nfc_connstring devices[8];
size_t device_count;
nfc_init(NULL);
device_count = nfc_list_devices (NULL, devices, 8);
nfc_context *context;
nfc_init (&context);
device_count = nfc_list_devices (context, devices, 8);
if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found.");
for (size_t d = 0; d < device_count; d++) {
device = nfc_open (NULL, devices[d]);
device = nfc_open (context, devices[d]);
if (!device) {
warnx ("nfc_open() failed.");
@ -310,6 +311,6 @@ main(int argc, char *argv[])
freefare_free_tags (tags);
nfc_close (device);
}
nfc_exit(NULL);
nfc_exit (context);
exit (error);
}

View file

@ -88,15 +88,16 @@ main(int argc, char *argv[])
nfc_connstring devices[8];
size_t device_count;
nfc_init(NULL);
device_count = nfc_list_devices (NULL, devices, 8);
nfc_context *context;
nfc_init (&context);
device_count = nfc_list_devices (context, devices, 8);
if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found.");
for (size_t d = 0; (!error) && (d < device_count); d++) {
device = nfc_open (NULL, devices[d]);
device = nfc_open (context, devices[d]);
if (!device) {
warnx ("nfc_open() failed.");
error = EXIT_FAILURE;
@ -174,7 +175,7 @@ main(int argc, char *argv[])
freefare_free_tags (tags);
nfc_close (device);
}
nfc_exit(NULL);
nfc_exit (context);
exit (error);
} /* main() */

View file

@ -75,14 +75,15 @@ main(int argc, char *argv[])
nfc_connstring devices[8];
size_t device_count;
nfc_init(NULL);
nfc_context *context;
nfc_init (&context);
device_count = nfc_list_devices (NULL, devices, 8);
device_count = nfc_list_devices (context, devices, 8);
if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found.");
for (size_t d = 0; (!error) && (d < device_count); d++) {
device = nfc_open (NULL, devices[d]);
device = nfc_open (context, devices[d]);
if (!device) {
warnx ("nfc_open() failed.");
error = EXIT_FAILURE;
@ -247,6 +248,6 @@ main(int argc, char *argv[])
freefare_free_tags (tags);
nfc_close (device);
}
nfc_exit(NULL);
nfc_exit (context);
exit (error);
}

View file

@ -85,14 +85,15 @@ main(int argc, char *argv[])
nfc_connstring devices[8];
size_t device_count;
nfc_init(NULL);
nfc_context *context;
nfc_init (&context);
device_count = nfc_list_devices (NULL, devices, 8);
device_count = nfc_list_devices (context, devices, 8);
if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found.");
for (size_t d = 0; (!error) && (d < device_count); d++) {
device = nfc_open (NULL, devices[d]);
device = nfc_open (context, devices[d]);
if (!device) {
warnx ("nfc_open() failed.");
error = EXIT_FAILURE;
@ -203,7 +204,7 @@ main(int argc, char *argv[])
freefare_free_tags (tags);
nfc_close (device);
}
nfc_exit(NULL);
nfc_exit (context);
exit (error);
} /* main() */

View file

@ -85,14 +85,15 @@ main(int argc, char *argv[])
nfc_connstring devices[8];
size_t device_count;
nfc_init(NULL);
nfc_context *context;
nfc_init (&context);
device_count = nfc_list_devices (NULL, devices, 8);
device_count = nfc_list_devices (context, devices, 8);
if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found.");
for (size_t d = 0; (!error) && (d < device_count); d++) {
device = nfc_open (NULL, devices[d]);
device = nfc_open (context, devices[d]);
if (!device) {
warnx ("nfc_open() failed.");
error = EXIT_FAILURE;
@ -166,7 +167,7 @@ main(int argc, char *argv[])
freefare_free_tags (tags);
nfc_close (device);
}
nfc_exit(NULL);
nfc_exit (context);
exit (error);
} /* main() */

View file

@ -39,14 +39,15 @@ main(int argc, char *argv[])
nfc_connstring devices[8];
size_t device_count;
nfc_init(NULL);
nfc_context *context;
nfc_init (&context);
device_count = nfc_list_devices (NULL, devices, 8);
device_count = nfc_list_devices (context, devices, 8);
if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found.");
for (size_t d = 0; d < device_count; d++) {
device = nfc_open (NULL, devices[d]);
device = nfc_open (context, devices[d]);
if (!device) {
warnx ("nfc_open() failed.");
error = EXIT_FAILURE;
@ -141,7 +142,7 @@ main(int argc, char *argv[])
freefare_free_tags (tags);
nfc_close (device);
}
nfc_exit(NULL);
nfc_exit (context);
exit (error);
} /* main() */

View file

@ -124,14 +124,15 @@ main(int argc, char *argv[])
nfc_connstring devices[8];
size_t device_count;
nfc_init(NULL);
nfc_context *context;
nfc_init (&context);
device_count = nfc_list_devices (NULL, devices, 8);
device_count = nfc_list_devices (context, devices, 8);
if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found.");
for (size_t d = 0; d < device_count; d++) {
device = nfc_open (NULL, devices[d]);
device = nfc_open (context, devices[d]);
if (!device) {
warnx ("nfc_open() failed.");
@ -269,6 +270,6 @@ main(int argc, char *argv[])
freefare_free_tags (tags);
nfc_close (device);
}
nfc_exit(NULL);
nfc_exit (context);
exit (error);
}

View file

@ -153,14 +153,15 @@ main(int argc, char *argv[])
nfc_connstring devices[8];
size_t device_count;
nfc_init(NULL);
nfc_context *context;
nfc_init (&context);
device_count = nfc_list_devices (NULL, devices, 8);
device_count = nfc_list_devices (context, devices, 8);
if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found.");
for (size_t d = 0; d < device_count; d++) {
device = nfc_open (NULL, devices[d]);
device = nfc_open (context, devices[d]);
if (!device) {
warnx ("nfc_open() failed.");
@ -292,6 +293,6 @@ main(int argc, char *argv[])
freefare_free_tags (tags);
nfc_close (device);
}
nfc_exit(NULL);
nfc_exit (context);
exit (error);
}

View file

@ -36,14 +36,15 @@ main (int argc, char *argv[])
nfc_connstring devices[8];
size_t device_count;
nfc_init (NULL);
nfc_context *context;
nfc_init (&context);
device_count = nfc_list_devices (NULL, devices, sizeof (devices) / sizeof (*devices));
device_count = nfc_list_devices (context, devices, sizeof (devices) / sizeof (*devices));
if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found");
for (size_t d = 0; d < device_count; d++) {
if (!(device = nfc_open (NULL, devices[d]))) {
if (!(device = nfc_open (context, devices[d]))) {
warnx ("nfc_open() failed.");
error = EXIT_FAILURE;
continue;
@ -85,6 +86,6 @@ main (int argc, char *argv[])
nfc_close (device);
}
nfc_exit (NULL);
nfc_exit (context);
exit(error);
}