update to use libnfc's trunk

This commit is contained in:
Audrey Diacre 2012-01-25 09:58:16 +00:00
parent 21008cda5d
commit 4f0227ddcb
20 changed files with 330 additions and 295 deletions

View file

@ -139,7 +139,7 @@ main(int argc, char *argv[])
{ {
int ch; int ch;
int error = EXIT_SUCCESS; int error = EXIT_SUCCESS;
nfc_device_t *device = NULL; nfc_device *device = NULL;
MifareTag *tags = NULL; MifareTag *tags = NULL;
while ((ch = getopt (argc, argv, "fhy")) != -1) { while ((ch = getopt (argc, argv, "fhy")) != -1) {
@ -161,25 +161,28 @@ main(int argc, char *argv[])
} }
argc -= optind; argc -= optind;
argv += optind; argv += optind;
nfc_connstring devices[8];
nfc_device_desc_t devices[8];
size_t device_count; size_t device_count;
nfc_init(NULL);
nfc_list_devices (devices, 8, &device_count); device_count = nfc_list_devices (NULL, devices, 8);
if (!device_count) if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found."); errx (EXIT_FAILURE, "No NFC device found.");
for (size_t d = 0; d < device_count; d++) { for (size_t d = 0; d < device_count; d++) {
device = nfc_connect (&(devices[d])); device = nfc_open (NULL, devices[d]);
if (!device) { if (!device) {
warnx ("nfc_connect() failed."); warnx ("nfc_open() failed.");
error = EXIT_FAILURE; error = EXIT_FAILURE;
continue; continue;
} }
tags = freefare_get_tags (device); tags = freefare_get_tags (device);
if (!tags) { if (!tags) {
nfc_disconnect (device); nfc_close (device);
errx (EXIT_FAILURE, "Error listing Mifare Classic tag."); errx (EXIT_FAILURE, "Error listing Mifare Classic tag.");
} }
@ -242,8 +245,9 @@ main(int argc, char *argv[])
} }
freefare_free_tags (tags); freefare_free_tags (tags);
nfc_disconnect (device); nfc_close (device);
} }
nfc_exit(NULL);
exit (error); exit (error);
} }

View file

@ -59,7 +59,7 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int error = 0; int error = 0;
nfc_device_t *device = NULL; nfc_device *device = NULL;
MifareTag *tags = NULL; MifareTag *tags = NULL;
Mad mad; Mad mad;
@ -102,24 +102,26 @@ main(int argc, char *argv[])
} }
} }
nfc_device_desc_t devices[8]; nfc_connstring devices[8];
size_t device_count; size_t device_count;
nfc_init(NULL);
nfc_list_devices (devices, 8, &device_count); device_count= nfc_list_devices (NULL, devices, 8);
if (!device_count) if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found."); errx (EXIT_FAILURE, "No NFC device found.");
for (size_t d = 0; d < device_count; d++) { for (size_t d = 0; d < device_count; d++) {
device = nfc_connect (&(devices[d])); device = nfc_open (NULL, devices[d]);
if (!device) { if (!device) {
warnx ("nfc_connect() failed."); warnx ("nfc_open() failed.");
error = EXIT_FAILURE; error = EXIT_FAILURE;
continue; continue;
} }
tags = freefare_get_tags (device); tags = freefare_get_tags (device);
if (!tags) { if (!tags) {
nfc_disconnect (device); nfc_close (device);
errx (EXIT_FAILURE, "Error listing MIFARE classic tag."); errx (EXIT_FAILURE, "Error listing MIFARE classic tag.");
} }
@ -206,8 +208,9 @@ error:
} }
fclose (ndef_stream); fclose (ndef_stream);
freefare_free_tags (tags); freefare_free_tags (tags);
nfc_disconnect (device); nfc_close (device);
} }
nfc_exit(NULL);
exit (error); exit (error);
} }

View file

@ -101,7 +101,7 @@ search_sector_key (MifareTag tag, MifareClassicSectorNumber sector, MifareClassi
} }
int int
fix_mad_trailer_block (nfc_device_t *device, MifareTag tag, MifareClassicSectorNumber sector, MifareClassicKey key, MifareClassicKeyType key_type) fix_mad_trailer_block (nfc_device *device, MifareTag tag, MifareClassicSectorNumber sector, MifareClassicKey key, MifareClassicKeyType key_type)
{ {
MifareClassicBlock block; MifareClassicBlock block;
mifare_classic_trailer_block (&block, mad_public_key_a, 0x0, 0x1, 0x1, 0x6, 0x00, default_keyb); mifare_classic_trailer_block (&block, mad_public_key_a, 0x0, 0x1, 0x1, 0x6, 0x00, default_keyb);
@ -128,7 +128,7 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int error = 0; int error = 0;
nfc_device_t *device = NULL; nfc_device *device = NULL;
MifareTag *tags = NULL; MifareTag *tags = NULL;
Mad mad; Mad mad;
MifareClassicKey transport_key = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; MifareClassicKey transport_key = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
@ -191,24 +191,26 @@ main(int argc, char *argv[])
err (EXIT_FAILURE, "malloc"); err (EXIT_FAILURE, "malloc");
} }
nfc_device_desc_t devices[8]; nfc_connstring devices[8];
size_t device_count; size_t device_count;
nfc_init(NULL);
nfc_list_devices (devices, 8, &device_count); device_count = nfc_list_devices (NULL, devices, 8);
if (!device_count) if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found."); errx (EXIT_FAILURE, "No NFC device found.");
for (size_t d = 0; d < device_count; d++) { for (size_t d = 0; d < device_count; d++) {
device = nfc_connect (&(devices[d])); device = nfc_open (NULL, devices[d]);
if (!device) { if (!device) {
warnx ("nfc_connect() failed."); warnx ("nfc_open() failed.");
error = EXIT_FAILURE; error = EXIT_FAILURE;
continue; continue;
} }
tags = freefare_get_tags (device); tags = freefare_get_tags (device);
if (!tags) { if (!tags) {
nfc_disconnect (device); nfc_close (device);
errx (EXIT_FAILURE, "Error listing MIFARE classic tag."); errx (EXIT_FAILURE, "Error listing MIFARE classic tag.");
} }
@ -399,10 +401,10 @@ error:
} }
freefare_free_tags (tags); freefare_free_tags (tags);
nfc_disconnect (device); nfc_close (device);
} }
free (card_write_keys); free (card_write_keys);
nfc_exit(NULL);
exit (error); exit (error);
} }

View file

@ -33,30 +33,32 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int error = EXIT_SUCCESS; int error = EXIT_SUCCESS;
nfc_device_t *device = NULL; nfc_device *device = NULL;
MifareTag *tags = NULL; MifareTag *tags = NULL;
if (argc > 1) if (argc > 1)
errx (EXIT_FAILURE, "usage: %s", argv[0]); errx (EXIT_FAILURE, "usage: %s", argv[0]);
nfc_device_desc_t devices[8]; nfc_connstring devices[8];
size_t device_count; size_t device_count;
nfc_init(NULL);
nfc_list_devices (devices, 8, &device_count); device_count = nfc_list_devices (NULL, devices, 8);
if (!device_count) if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found."); errx (EXIT_FAILURE, "No NFC device found.");
for (size_t d = 0; d < device_count; d++) { for (size_t d = 0; d < device_count; d++) {
device = nfc_connect (&(devices[d])); device = nfc_open (NULL, devices[d]);
if (!device) { if (!device) {
warnx ("nfc_connect() failed."); warnx ("nfc_open() failed.");
error = EXIT_FAILURE; error = EXIT_FAILURE;
continue; continue;
} }
tags = freefare_get_tags (device); tags = freefare_get_tags (device);
if (!tags) { if (!tags) {
nfc_disconnect (device); nfc_close (device);
errx (EXIT_FAILURE, "Error listing tags."); errx (EXIT_FAILURE, "Error listing tags.");
} }
@ -128,9 +130,9 @@ main(int argc, char *argv[])
} }
freefare_free_tags (tags); freefare_free_tags (tags);
nfc_disconnect (device); nfc_close (device);
} }
nfc_exit(NULL);
exit (error); exit (error);
} /* main() */ } /* main() */

View file

@ -53,7 +53,7 @@ main(int argc, char *argv[])
{ {
int ch; int ch;
int error = EXIT_SUCCESS; int error = EXIT_SUCCESS;
nfc_device_t *device = NULL; nfc_device *device = NULL;
MifareTag *tags = NULL; MifareTag *tags = NULL;
while ((ch = getopt (argc, argv, "hy")) != -1) { while ((ch = getopt (argc, argv, "hy")) != -1) {
@ -73,24 +73,26 @@ main(int argc, char *argv[])
argc -= optind; argc -= optind;
argv += optind; argv += optind;
nfc_device_desc_t devices[8]; nfc_connstring devices[8];
size_t device_count; size_t device_count;
nfc_init(NULL);
nfc_list_devices (devices, 8, &device_count); device_count = nfc_list_devices (NULL, devices, 8);
if (!device_count) if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found."); errx (EXIT_FAILURE, "No NFC device found.");
for (size_t d = 0; (!error) && (d < device_count); d++) { for (size_t d = 0; (!error) && (d < device_count); d++) {
device = nfc_connect (&(devices[d])); device = nfc_open (NULL, devices[d]);
if (!device) { if (!device) {
warnx ("nfc_connect() failed."); warnx ("nfc_open() failed.");
error = EXIT_FAILURE; error = EXIT_FAILURE;
continue; continue;
} }
tags = freefare_get_tags (device); tags = freefare_get_tags (device);
if (!tags) { if (!tags) {
nfc_disconnect (device); nfc_close (device);
errx (EXIT_FAILURE, "Error listing Mifare DESFire tags."); errx (EXIT_FAILURE, "Error listing Mifare DESFire tags.");
} }
@ -146,9 +148,9 @@ main(int argc, char *argv[])
} }
freefare_free_tags (tags); freefare_free_tags (tags);
nfc_disconnect (device); nfc_close (device);
} }
nfc_exit(NULL);
exit (error); exit (error);
} /* main() */ } /* main() */

View file

@ -53,7 +53,7 @@ main(int argc, char *argv[])
{ {
int ch; int ch;
int error = EXIT_SUCCESS; int error = EXIT_SUCCESS;
nfc_device_t *device = NULL; nfc_device *device = NULL;
MifareTag *tags = NULL; MifareTag *tags = NULL;
while ((ch = getopt (argc, argv, "hy")) != -1) { while ((ch = getopt (argc, argv, "hy")) != -1) {
@ -73,24 +73,26 @@ main(int argc, char *argv[])
argc -= optind; argc -= optind;
argv += optind; argv += optind;
nfc_device_desc_t devices[8]; nfc_connstring devices[8];
size_t device_count; size_t device_count;
nfc_init(NULL);
nfc_list_devices (devices, 8, &device_count); device_count = nfc_list_devices (NULL, devices, 8);
if (!device_count) if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found."); errx (EXIT_FAILURE, "No NFC device found.");
for (size_t d = 0; (!error) && (d < device_count); d++) { for (size_t d = 0; (!error) && (d < device_count); d++) {
device = nfc_connect (&(devices[d])); device = nfc_open (NULL, devices[d]);
if (!device) { if (!device) {
warnx ("nfc_connect() failed."); warnx ("nfc_open() failed.");
error = EXIT_FAILURE; error = EXIT_FAILURE;
continue; continue;
} }
tags = freefare_get_tags (device); tags = freefare_get_tags (device);
if (!tags) { if (!tags) {
nfc_disconnect (device); nfc_close (device);
errx (EXIT_FAILURE, "Error listing Mifare DESFire tags."); errx (EXIT_FAILURE, "Error listing Mifare DESFire tags.");
} }
@ -230,8 +232,8 @@ main(int argc, char *argv[])
} }
freefare_free_tags (tags); freefare_free_tags (tags);
nfc_disconnect (device); nfc_close (device);
} }
nfc_exit(NULL);
exit (error); exit (error);
} }

View file

@ -50,7 +50,7 @@ main(int argc, char *argv[])
{ {
int ch; int ch;
int error = EXIT_SUCCESS; int error = EXIT_SUCCESS;
nfc_device_t *device = NULL; nfc_device *device = NULL;
MifareTag *tags = NULL; MifareTag *tags = NULL;
while ((ch = getopt (argc, argv, "hy")) != -1) { while ((ch = getopt (argc, argv, "hy")) != -1) {
@ -70,24 +70,26 @@ main(int argc, char *argv[])
argc -= optind; argc -= optind;
argv += optind; argv += optind;
nfc_device_desc_t devices[8]; nfc_connstring devices[8];
size_t device_count; size_t device_count;
nfc_init(NULL);
nfc_list_devices (devices, 8, &device_count); device_count = nfc_list_devices (NULL, devices, 8);
if (!device_count) if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found."); errx (EXIT_FAILURE, "No NFC device found.");
for (size_t d = 0; (!error) && (d < device_count); d++) { for (size_t d = 0; (!error) && (d < device_count); d++) {
device = nfc_connect (&(devices[d])); device = nfc_open (NULL, devices[d]);
if (!device) { if (!device) {
warnx ("nfc_connect() failed."); warnx ("nfc_open() failed.");
error = EXIT_FAILURE; error = EXIT_FAILURE;
continue; continue;
} }
tags = freefare_get_tags (device); tags = freefare_get_tags (device);
if (!tags) { if (!tags) {
nfc_disconnect (device); nfc_close (device);
errx (EXIT_FAILURE, "Error listing Mifare DESFire tags."); errx (EXIT_FAILURE, "Error listing Mifare DESFire tags.");
} }
@ -182,9 +184,9 @@ main(int argc, char *argv[])
} }
freefare_free_tags (tags); freefare_free_tags (tags);
nfc_disconnect (device); nfc_close (device);
} }
nfc_exit(NULL);
exit (error); exit (error);
} /* main() */ } /* main() */

View file

@ -50,7 +50,7 @@ main(int argc, char *argv[])
{ {
int ch; int ch;
int error = EXIT_SUCCESS; int error = EXIT_SUCCESS;
nfc_device_t *device = NULL; nfc_device *device = NULL;
MifareTag *tags = NULL; MifareTag *tags = NULL;
while ((ch = getopt (argc, argv, "hy")) != -1) { while ((ch = getopt (argc, argv, "hy")) != -1) {
@ -70,24 +70,26 @@ main(int argc, char *argv[])
argc -= optind; argc -= optind;
argv += optind; argv += optind;
nfc_device_desc_t devices[8]; nfc_connstring devices[8];
size_t device_count; size_t device_count;
nfc_init(NULL);
nfc_list_devices (devices, 8, &device_count); device_count = nfc_list_devices (NULL, devices, 8);
if (!device_count) if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found."); errx (EXIT_FAILURE, "No NFC device found.");
for (size_t d = 0; (!error) && (d < device_count); d++) { for (size_t d = 0; (!error) && (d < device_count); d++) {
device = nfc_connect (&(devices[d])); device = nfc_open (NULL, devices[d]);
if (!device) { if (!device) {
warnx ("nfc_connect() failed."); warnx ("nfc_open() failed.");
error = EXIT_FAILURE; error = EXIT_FAILURE;
continue; continue;
} }
tags = freefare_get_tags (device); tags = freefare_get_tags (device);
if (!tags) { if (!tags) {
nfc_disconnect (device); nfc_close (device);
errx (EXIT_FAILURE, "Error listing Mifare DESFire tags."); errx (EXIT_FAILURE, "Error listing Mifare DESFire tags.");
} }
@ -141,9 +143,9 @@ main(int argc, char *argv[])
} }
freefare_free_tags (tags); freefare_free_tags (tags);
nfc_disconnect (device); nfc_close (device);
} }
nfc_exit(NULL);
exit (error); exit (error);
} /* main() */ } /* main() */

View file

@ -31,30 +31,32 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int error = EXIT_SUCCESS; int error = EXIT_SUCCESS;
nfc_device_t *device = NULL; nfc_device *device = NULL;
MifareTag *tags = NULL; MifareTag *tags = NULL;
if (argc > 1) if (argc > 1)
errx (EXIT_FAILURE, "usage: %s", argv[0]); errx (EXIT_FAILURE, "usage: %s", argv[0]);
nfc_device_desc_t devices[8]; nfc_connstring devices[8];
size_t device_count; size_t device_count;
nfc_init(NULL);
nfc_list_devices (devices, 8, &device_count); device_count = nfc_list_devices (NULL, devices, 8);
if (!device_count) if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found."); errx (EXIT_FAILURE, "No NFC device found.");
for (size_t d = 0; d < device_count; d++) { for (size_t d = 0; d < device_count; d++) {
device = nfc_connect (&(devices[d])); device = nfc_open (NULL, devices[d]);
if (!device) { if (!device) {
warnx ("nfc_connect() failed."); warnx ("nfc_open() failed.");
error = EXIT_FAILURE; error = EXIT_FAILURE;
continue; continue;
} }
tags = freefare_get_tags (device); tags = freefare_get_tags (device);
if (!tags) { if (!tags) {
nfc_disconnect (device); nfc_close (device);
errx (EXIT_FAILURE, "Error listing tags."); errx (EXIT_FAILURE, "Error listing tags.");
} }
@ -138,9 +140,9 @@ main(int argc, char *argv[])
} }
freefare_free_tags (tags); freefare_free_tags (tags);
nfc_disconnect (device); nfc_close (device);
} }
nfc_exit(NULL);
exit (error); exit (error);
} /* main() */ } /* main() */

View file

@ -48,7 +48,7 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int error = EXIT_SUCCESS; int error = EXIT_SUCCESS;
nfc_device_t *device = NULL; nfc_device *device = NULL;
MifareTag *tags = NULL; MifareTag *tags = NULL;
printf ("NOTE: This application turns Mifare DESFire targets into NFC Forum Type 4 Tags.\n"); printf ("NOTE: This application turns Mifare DESFire targets into NFC Forum Type 4 Tags.\n");
@ -56,24 +56,27 @@ main(int argc, char *argv[])
if (argc > 1) if (argc > 1)
errx (EXIT_FAILURE, "usage: %s", argv[0]); errx (EXIT_FAILURE, "usage: %s", argv[0]);
nfc_device_desc_t devices[8]; nfc_connstring devices[8];
size_t device_count; size_t device_count;
nfc_init(NULL);
nfc_list_devices (devices, 8, &device_count); device_count = nfc_list_devices (NULL, devices, 8);
if (!device_count) if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found."); errx (EXIT_FAILURE, "No NFC device found.");
for (size_t d = 0; d < device_count; d++) { for (size_t d = 0; d < device_count; d++) {
device = nfc_connect (&(devices[d])); device = nfc_open (NULL, devices[d]);
if (!device) {
warnx ("nfc_connect() failed."); if (!device) {
warnx ("nfc_open() failed.");
error = EXIT_FAILURE; error = EXIT_FAILURE;
continue; continue;
} }
tags = freefare_get_tags (device); tags = freefare_get_tags (device);
if (!tags) { if (!tags) {
nfc_disconnect (device); nfc_close (device);
errx (EXIT_FAILURE, "Error listing tags."); errx (EXIT_FAILURE, "Error listing tags.");
} }
@ -159,7 +162,7 @@ main(int argc, char *argv[])
// Mapping Version equal to 10h,MLe equal to 003Bh, MLc equal to 0034h, and NDEF File Control TLV // Mapping Version equal to 10h,MLe equal to 003Bh, MLc equal to 0034h, and NDEF File Control TLV
// equal to T =04h, L=06h, V=E1 04 (NDEF ISO FID=E104h) 0E E0 (NDEF File size =3808 Bytes) 00 (free read access) // equal to T =04h, L=06h, V=E1 04 (NDEF ISO FID=E104h) 0E E0 (NDEF File size =3808 Bytes) 00 (free read access)
// 00 free write access // 00 free write access
byte_t capability_container_file_content[15] = { uint8_t capability_container_file_content[15] = {
0x00, 0x0F, // CCLEN: Size of this capability container.CCLEN values are between 000Fh and FFFEh 0x00, 0x0F, // CCLEN: Size of this capability container.CCLEN values are between 000Fh and FFFEh
0x10, // Mapping version 0x10, // Mapping version
0x00, 0x3B, // MLe: Maximum data size that can be read using a single ReadBinary command. MLe = 000Fh-FFFFh 0x00, 0x3B, // MLe: Maximum data size that can be read using a single ReadBinary command. MLe = 000Fh-FFFFh
@ -193,7 +196,8 @@ main(int argc, char *argv[])
free (tag_uid); free (tag_uid);
} }
freefare_free_tags (tags); freefare_free_tags (tags);
nfc_disconnect (device); nfc_close (device);
} }
nfc_exit(NULL);
exit (error); exit (error);
} }

View file

@ -41,7 +41,7 @@ struct supported_tag supported_tags[] = {
* Automagically allocate a MifareTag given a device and target info. * Automagically allocate a MifareTag given a device and target info.
*/ */
MifareTag MifareTag
freefare_tag_new (nfc_device_t *device, nfc_iso14443a_info_t nai) freefare_tag_new (nfc_device *device, nfc_iso14443a_info nai)
{ {
bool found = false; bool found = false;
struct supported_tag *tag_info; struct supported_tag *tag_info;
@ -110,7 +110,7 @@ freefare_tag_new (nfc_device_t *device, nfc_iso14443a_info_t nai)
* The list has to be freed using the freefare_free_tags() function. * The list has to be freed using the freefare_free_tags() function.
*/ */
MifareTag * MifareTag *
freefare_get_tags (nfc_device_t *device) freefare_get_tags (nfc_device *device)
{ {
MifareTag *tags = NULL; MifareTag *tags = NULL;
int tag_count = 0; int tag_count = 0;
@ -118,24 +118,24 @@ freefare_get_tags (nfc_device_t *device)
nfc_initiator_init(device); nfc_initiator_init(device);
// Drop the field for a while // Drop the field for a while
nfc_configure(device,NDO_ACTIVATE_FIELD,false); nfc_device_set_property_bool(device,NP_ACTIVATE_FIELD,false);
// Configure the CRC and Parity settings // Configure the CRC and Parity settings
nfc_configure(device,NDO_HANDLE_CRC,true); nfc_device_set_property_bool(device,NP_HANDLE_CRC,true);
nfc_configure(device,NDO_HANDLE_PARITY,true); nfc_device_set_property_bool(device,NP_HANDLE_PARITY,true);
nfc_configure(device,NDO_AUTO_ISO14443_4,true); nfc_device_set_property_bool(device,NP_AUTO_ISO14443_4,true);
// Enable field so more power consuming cards can power themselves up // Enable field so more power consuming cards can power themselves up
nfc_configure(device,NDO_ACTIVATE_FIELD,true); nfc_device_set_property_bool(device,NP_ACTIVATE_FIELD,true);
// Poll for a ISO14443A (MIFARE) tag // Poll for a ISO14443A (MIFARE) tag
nfc_target_t candidates[MAX_CANDIDATES]; nfc_target candidates[MAX_CANDIDATES];
size_t candidates_count; size_t candidates_count;
nfc_modulation_t modulation = { nfc_modulation modulation = {
.nmt = NMT_ISO14443A, .nmt = NMT_ISO14443A,
.nbr = NBR_106 .nbr = NBR_106
}; };
if (!nfc_initiator_list_passive_targets(device, modulation, candidates, MAX_CANDIDATES, &candidates_count)) if ((candidates_count = nfc_initiator_list_passive_targets(device, modulation, candidates, MAX_CANDIDATES)) < 0)
return NULL; return NULL;
tags = malloc(sizeof (void *)); tags = malloc(sizeof (void *));
@ -185,7 +185,7 @@ freefare_get_tag_uid (MifareTag tag)
{ {
char *res = malloc (2 * tag->info.szUidLen + 1); char *res = malloc (2 * tag->info.szUidLen + 1);
for (size_t i =0; i < tag->info.szUidLen; i++) for (size_t i =0; i < tag->info.szUidLen; i++)
snprintf (res + 2*i, 3, "%02x", tag->info.abtUid[i]); snprintf (res + 2*i, 3, "%02x", tag->info.abtUid[i]);
return res; return res;
} }
@ -196,19 +196,19 @@ void
freefare_free_tag (MifareTag tag) freefare_free_tag (MifareTag tag)
{ {
if (tag) { if (tag) {
switch (tag->tag_info->type) { switch (tag->tag_info->type) {
case CLASSIC_1K: case CLASSIC_1K:
case CLASSIC_4K: case CLASSIC_4K:
mifare_classic_tag_free (tag); mifare_classic_tag_free (tag);
break; break;
case DESFIRE: case DESFIRE:
mifare_desfire_tag_free (tag); mifare_desfire_tag_free (tag);
break; break;
case ULTRALIGHT: case ULTRALIGHT:
case ULTRALIGHT_C: case ULTRALIGHT_C:
mifare_ultralight_tag_free (tag); mifare_ultralight_tag_free (tag);
break; break;
} }
} }
} }
@ -216,18 +216,17 @@ const char *
freefare_strerror (MifareTag tag) freefare_strerror (MifareTag tag)
{ {
const char *p = "Unkown error"; const char *p = "Unkown error";
if (tag->device->iLastError > 0) { if (nfc_device_get_last_error (tag->device) < 0) {
p = nfc_strerror (tag->device); p = nfc_strerror (tag->device);
} else { } else {
if (tag->tag_info->type == DESFIRE) { if (tag->tag_info->type == DESFIRE) {
if (MIFARE_DESFIRE (tag)->last_pcd_error) { if (MIFARE_DESFIRE (tag)->last_pcd_error) {
p = mifare_desfire_error_lookup (MIFARE_DESFIRE (tag)->last_pcd_error); p = mifare_desfire_error_lookup (MIFARE_DESFIRE (tag)->last_pcd_error);
} else if (MIFARE_DESFIRE (tag)->last_picc_error) { } else if (MIFARE_DESFIRE (tag)->last_picc_error) {
p = mifare_desfire_error_lookup (MIFARE_DESFIRE (tag)->last_picc_error); p = mifare_desfire_error_lookup (MIFARE_DESFIRE (tag)->last_picc_error);
} }
} }
} }
return p; return p;
} }
@ -257,7 +256,6 @@ freefare_free_tags (MifareTag *tags)
} }
} }
/* /*
* Low-level API * Low-level API

View file

@ -52,8 +52,8 @@ typedef struct mifare_desfire_key *MifareDESFireKey;
typedef uint8_t MifareUltralightPageNumber; typedef uint8_t MifareUltralightPageNumber;
typedef unsigned char MifareUltralightPage[4]; typedef unsigned char MifareUltralightPage[4];
MifareTag *freefare_get_tags (nfc_device_t *device); MifareTag *freefare_get_tags (nfc_device *device);
MifareTag freefare_tag_new (nfc_device_t *device, nfc_iso14443a_info_t nai); MifareTag freefare_tag_new (nfc_device *device, nfc_iso14443a_info nai);
enum mifare_tag_type freefare_get_tag_type (MifareTag tag); enum mifare_tag_type freefare_get_tag_type (MifareTag tag);
const char *freefare_get_tag_friendly_name (MifareTag tag); const char *freefare_get_tag_friendly_name (MifareTag tag);
char *freefare_get_tag_uid (MifareTag tag); char *freefare_get_tag_uid (MifareTag tag);
@ -71,7 +71,7 @@ int mifare_ultralight_read (MifareTag tag, const MifareUltralightPageNumber pa
int mifare_ultralight_write (MifareTag tag, const MifareUltralightPageNumber page, const MifareUltralightPage data); int mifare_ultralight_write (MifareTag tag, const MifareUltralightPageNumber page, const MifareUltralightPage data);
int mifare_ultralightc_authenticate (MifareTag tag, const MifareDESFireKey key); int mifare_ultralightc_authenticate (MifareTag tag, const MifareDESFireKey key);
bool is_mifare_ultralightc_on_reader (nfc_device_t *device, nfc_iso14443a_info_t nai); bool is_mifare_ultralightc_on_reader (nfc_device *device, nfc_iso14443a_info nai);
typedef unsigned char MifareClassicBlock[16]; typedef unsigned char MifareClassicBlock[16];

View file

@ -173,7 +173,7 @@ struct supported_tag {
uint8_t ATS_min_length; uint8_t ATS_min_length;
uint8_t ATS_compare_length; uint8_t ATS_compare_length;
uint8_t ATS[5]; uint8_t ATS[5];
bool (*check_tag_on_reader) (nfc_device_t *, nfc_iso14443a_info_t); bool (*check_tag_on_reader) (nfc_device *, nfc_iso14443a_info);
}; };
/* /*
@ -185,8 +185,8 @@ struct supported_tag {
* mifare_*_connect() function. * mifare_*_connect() function.
*/ */
struct mifare_tag { struct mifare_tag {
nfc_device_t *device; nfc_device *device;
nfc_iso14443a_info_t info; nfc_iso14443a_info info;
const struct supported_tag *tag_info; const struct supported_tag *tag_info;
int active; int active;
}; };

View file

@ -89,7 +89,7 @@
do { \ do { \
errno = 0; \ errno = 0; \
DEBUG_XFER (msg, __##msg##_n, "===> "); \ DEBUG_XFER (msg, __##msg##_n, "===> "); \
if (!(nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, &__##res##_n, NULL))) { \ if ((nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, &__##res##_n, 0) < 0)) { \
if (disconnect) { \ if (disconnect) { \
tag->active = false; \ tag->active = false; \
} \ } \
@ -228,12 +228,12 @@ mifare_classic_connect (MifareTag tag)
ASSERT_INACTIVE (tag); ASSERT_INACTIVE (tag);
ASSERT_MIFARE_CLASSIC (tag); ASSERT_MIFARE_CLASSIC (tag);
nfc_target_t pnti; nfc_target pnti;
nfc_modulation_t modulation = { nfc_modulation modulation = {
.nmt = NMT_ISO14443A, .nmt = NMT_ISO14443A,
.nbr = NBR_106 .nbr = NBR_106
}; };
if (nfc_initiator_select_passive_target (tag->device, modulation, tag->info.abtUid, tag->info.szUidLen, &pnti)) { if (nfc_initiator_select_passive_target (tag->device, modulation, tag->info.abtUid, tag->info.szUidLen, &pnti) >= 0) {
tag->active = 1; tag->active = 1;
} else { } else {
errno = EIO; errno = EIO;
@ -251,7 +251,7 @@ mifare_classic_disconnect (MifareTag tag)
ASSERT_ACTIVE (tag); ASSERT_ACTIVE (tag);
ASSERT_MIFARE_CLASSIC (tag); ASSERT_MIFARE_CLASSIC (tag);
if (nfc_initiator_deselect_target (tag->device)) { if (nfc_initiator_deselect_target (tag->device) >= 0) {
tag->active = 0; tag->active = 0;
} else { } else {
errno = EIO; errno = EIO;

View file

@ -172,7 +172,7 @@ static ssize_t read_data (MifareTag tag, uint8_t command, uint8_t file_no, off_
MIFARE_DESFIRE (tag)->last_picc_error = OPERATION_OK; \ MIFARE_DESFIRE (tag)->last_picc_error = OPERATION_OK; \
MIFARE_DESFIRE (tag)->last_pcd_error = OPERATION_OK; \ MIFARE_DESFIRE (tag)->last_pcd_error = OPERATION_OK; \
DEBUG_XFER (__msg, __len, "===> "); \ DEBUG_XFER (__msg, __len, "===> "); \
if (!(nfc_initiator_transceive_bytes (tag->device, __msg, __len, __res, &__##res##_n, NULL))) { \ if ((nfc_initiator_transceive_bytes (tag->device, __msg, __len, __res, &__##res##_n, 0)) < 0) { \
return errno = EIO, -1; \ return errno = EIO, -1; \
} \ } \
DEBUG_XFER (__res, __##res##_n, "<=== "); \ DEBUG_XFER (__res, __##res##_n, "<=== "); \
@ -276,12 +276,12 @@ mifare_desfire_connect (MifareTag tag)
ASSERT_INACTIVE (tag); ASSERT_INACTIVE (tag);
ASSERT_MIFARE_DESFIRE (tag); ASSERT_MIFARE_DESFIRE (tag);
nfc_target_t pnti; nfc_target pnti;
nfc_modulation_t modulation = { nfc_modulation modulation = {
.nmt = NMT_ISO14443A, .nmt = NMT_ISO14443A,
.nbr = NBR_106 .nbr = NBR_106
}; };
if (nfc_initiator_select_passive_target (tag->device, modulation, tag->info.abtUid, tag->info.szUidLen, &pnti)) { if (nfc_initiator_select_passive_target (tag->device, modulation, tag->info.abtUid, tag->info.szUidLen, &pnti) >= 0) {
tag->active = 1; tag->active = 1;
free (MIFARE_DESFIRE (tag)->session_key); free (MIFARE_DESFIRE (tag)->session_key);
MIFARE_DESFIRE (tag)->session_key = NULL; MIFARE_DESFIRE (tag)->session_key = NULL;
@ -308,7 +308,7 @@ mifare_desfire_disconnect (MifareTag tag)
free (MIFARE_DESFIRE (tag)->session_key); free (MIFARE_DESFIRE (tag)->session_key);
MIFARE_DESFIRE(tag)->session_key = NULL; MIFARE_DESFIRE(tag)->session_key = NULL;
if (nfc_initiator_deselect_target (tag->device)) { if (nfc_initiator_deselect_target (tag->device) >= 0) {
tag->active = 0; tag->active = 0;
} }
return 0; return 0;

View file

@ -62,7 +62,7 @@
do { \ do { \
errno = 0; \ errno = 0; \
DEBUG_XFER (msg, __##msg##_n, "===> "); \ DEBUG_XFER (msg, __##msg##_n, "===> "); \
if (!(nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, &__##res##_n, NULL))) { \ if ((nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, &__##res##_n, 0)) < 0) { \
return errno = EIO, -1; \ return errno = EIO, -1; \
} \ } \
DEBUG_XFER (res, __##res##_n, "<=== "); \ DEBUG_XFER (res, __##res##_n, "<=== "); \
@ -71,17 +71,17 @@
#define ULTRALIGHT_TRANSCEIVE_RAW(tag, msg, res) \ #define ULTRALIGHT_TRANSCEIVE_RAW(tag, msg, res) \
do { \ do { \
errno = 0; \ errno = 0; \
if (!nfc_configure (tag->device, NDO_EASY_FRAMING, false)) { \ if (nfc_device_set_property_bool (tag->device, NP_EASY_FRAMING, false) < 0) { \
errno = EIO; \ errno = EIO; \
return -1; \ return -1; \
} \ } \
DEBUG_XFER (msg, __##msg##_n, "===> "); \ DEBUG_XFER (msg, __##msg##_n, "===> "); \
if (!(nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, &__##res##_n, NULL))) { \ if ((nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, &__##res##_n, 0)) < 0) { \
nfc_configure (tag->device, NDO_EASY_FRAMING, true); \ nfc_device_set_property_bool (tag->device, NP_EASY_FRAMING, true); \
return errno = EIO, -1; \ return errno = EIO, -1; \
} \ } \
DEBUG_XFER (res, __##res##_n, "<=== "); \ DEBUG_XFER (res, __##res##_n, "<=== "); \
if (!nfc_configure (tag->device, NDO_EASY_FRAMING, true)) { \ if (nfc_device_set_property_bool (tag->device, NP_EASY_FRAMING, true) < 0) { \
errno = EIO; \ errno = EIO; \
return -1; \ return -1; \
} \ } \
@ -129,12 +129,12 @@ mifare_ultralight_connect (MifareTag tag)
ASSERT_INACTIVE (tag); ASSERT_INACTIVE (tag);
ASSERT_MIFARE_ULTRALIGHT (tag); ASSERT_MIFARE_ULTRALIGHT (tag);
nfc_target_t pnti; nfc_target pnti;
nfc_modulation_t modulation = { nfc_modulation modulation = {
.nmt = NMT_ISO14443A, .nmt = NMT_ISO14443A,
.nbr = NBR_106 .nbr = NBR_106
}; };
if (nfc_initiator_select_passive_target (tag->device, modulation, tag->info.abtUid, tag->info.szUidLen, &pnti)) { if (nfc_initiator_select_passive_target (tag->device, modulation, tag->info.abtUid, tag->info.szUidLen, &pnti) >= 0) {
tag->active = 1; tag->active = 1;
for (int i = 0; i < MIFARE_ULTRALIGHT_MAX_PAGE_COUNT; i++) for (int i = 0; i < MIFARE_ULTRALIGHT_MAX_PAGE_COUNT; i++)
MIFARE_ULTRALIGHT(tag)->cached_pages[i] = 0; MIFARE_ULTRALIGHT(tag)->cached_pages[i] = 0;
@ -154,7 +154,7 @@ mifare_ultralight_disconnect (MifareTag tag)
ASSERT_ACTIVE (tag); ASSERT_ACTIVE (tag);
ASSERT_MIFARE_ULTRALIGHT (tag); ASSERT_MIFARE_ULTRALIGHT (tag);
if (nfc_initiator_deselect_target (tag->device)) { if (nfc_initiator_deselect_target (tag->device) >= 0) {
tag->active = 0; tag->active = 0;
} else { } else {
errno = EIO; errno = EIO;
@ -307,7 +307,7 @@ mifare_ultralightc_authenticate (MifareTag tag, const MifareDESFireKey key)
* Callback for freefare_tag_new to test presence of a MIFARE UltralightC on the reader. * Callback for freefare_tag_new to test presence of a MIFARE UltralightC on the reader.
*/ */
bool bool
is_mifare_ultralightc_on_reader (nfc_device_t *device, nfc_iso14443a_info_t nai) is_mifare_ultralightc_on_reader (nfc_device *device, nfc_iso14443a_info nai)
{ {
bool ret; bool ret;
uint8_t cmd_step1[2]; uint8_t cmd_step1[2];
@ -315,16 +315,16 @@ is_mifare_ultralightc_on_reader (nfc_device_t *device, nfc_iso14443a_info_t nai)
cmd_step1[0] = 0x1A; cmd_step1[0] = 0x1A;
cmd_step1[1] = 0x00; cmd_step1[1] = 0x00;
nfc_target_t pnti; nfc_target pnti;
nfc_modulation_t modulation = { nfc_modulation modulation = {
.nmt = NMT_ISO14443A, .nmt = NMT_ISO14443A,
.nbr = NBR_106 .nbr = NBR_106
}; };
nfc_initiator_select_passive_target (device, modulation, nai.abtUid, nai.szUidLen, &pnti); nfc_initiator_select_passive_target (device, modulation, nai.abtUid, nai.szUidLen, &pnti);
nfc_configure (device, NDO_EASY_FRAMING, false); nfc_device_set_property_bool (device, NP_EASY_FRAMING, false);
size_t n; size_t n;
ret = nfc_initiator_transceive_bytes (device, cmd_step1, sizeof (cmd_step1), res_step1, &n, NULL); ret = nfc_initiator_transceive_bytes (device, cmd_step1, sizeof (cmd_step1), res_step1, &n, 0);
nfc_configure (device, NDO_EASY_FRAMING, true); nfc_device_set_property_bool (device, NP_EASY_FRAMING, true);
nfc_initiator_deselect_target (device); nfc_initiator_deselect_target (device);
return ret; return ret;
} }

View file

@ -22,7 +22,7 @@
#include "mifare_classic_fixture.h" #include "mifare_classic_fixture.h"
static nfc_device_t *device = NULL; static nfc_device *device = NULL;
static MifareTag *tags = NULL; static MifareTag *tags = NULL;
MifareTag tag = NULL; MifareTag tag = NULL;
@ -30,38 +30,38 @@ void
cut_setup (void) cut_setup (void)
{ {
int res; int res;
nfc_device_desc_t devices[8]; nfc_connstring devices[8];
size_t device_count; size_t device_count;
nfc_init(NULL);
nfc_list_devices (devices, 8, &device_count); device_count = nfc_list_devices (NULL, devices, 8);
if (!device_count) if (device_count <= 0)
cut_omit ("No device found"); cut_omit ("No device found");
for (size_t i = 0; i < device_count; i++) { for (size_t i = 0; i < device_count; i++) {
device = nfc_open (NULL, devices[i]);
if (!device)
cut_omit ("nfc_open() failed.");
device = nfc_connect (&(devices[i])); tags = freefare_get_tags (device);
if (!device) cut_assert_not_null (tags, cut_message ("freefare_get_tags() failed"));
cut_omit ("nfc_connect() failed");
tags = freefare_get_tags (device); tag = NULL;
cut_assert_not_null (tags, cut_message ("freefare_get_tags() failed")); for (int i=0; tags[i]; i++) {
if ((freefare_get_tag_type(tags[i]) == CLASSIC_1K) ||
tag = NULL; (freefare_get_tag_type(tags[i]) == CLASSIC_4K)) {
for (int i=0; tags[i]; i++) { tag = tags[i];
if ((freefare_get_tag_type(tags[i]) == CLASSIC_1K) || res = mifare_classic_connect (tag);
(freefare_get_tag_type(tags[i]) == CLASSIC_4K)) { cut_assert_equal_int (0, res, cut_message ("mifare_classic_connect() failed"));
tag = tags[i]; return;
res = mifare_classic_connect (tag); }
cut_assert_equal_int (0, res, cut_message ("mifare_classic_connect() failed")); }
return; nfc_close (device);
} device = NULL;
} freefare_free_tags (tags);
nfc_disconnect (device); tags = NULL;
device = NULL;
freefare_free_tags (tags);
tags = NULL;
} }
cut_omit ("No MIFARE Classic tag on NFC device"); cut_omit ("No MIFARE Classic tag on NFC device");
} }
@ -69,14 +69,16 @@ void
cut_teardown (void) cut_teardown (void)
{ {
if (tag) if (tag)
mifare_classic_disconnect (tag); mifare_classic_disconnect (tag);
if (tags) { if (tags) {
freefare_free_tags (tags); freefare_free_tags (tags);
tags = NULL; tags = NULL;
} }
if (device) if (device)
nfc_disconnect (device); nfc_close (device);
nfc_exit(NULL);
} }

View file

@ -22,7 +22,7 @@
#include "mifare_desfire_ev1_fixture.h" #include "mifare_desfire_ev1_fixture.h"
static nfc_device_t *device = NULL; static nfc_device *device = NULL;
static MifareTag *tags = NULL; static MifareTag *tags = NULL;
MifareTag tag = NULL; MifareTag tag = NULL;
@ -30,47 +30,48 @@ void
cut_setup (void) cut_setup (void)
{ {
int res; int res;
nfc_device_desc_t devices[8]; nfc_connstring devices[8];
size_t device_count; size_t device_count;
nfc_init(NULL);
nfc_list_devices (devices, 8, &device_count); device_count = nfc_list_devices (NULL, devices, 8);
if (!device_count) if (device_count <= 0)
cut_omit ("No device found"); cut_omit ("No device found");
for (size_t i = 0; i < device_count; i++) { for (size_t i = 0; i < device_count; i++) {
device = nfc_connect (&(devices[i])); device = nfc_open (NULL, devices[i]);
if (!device) if (!device)
cut_omit ("nfc_connect() failed"); cut_omit ("nfc_open() failed.");
tags = freefare_get_tags (device); tags = freefare_get_tags (device);
cut_assert_not_null (tags, cut_message ("freefare_get_tags() failed")); cut_assert_not_null (tags, cut_message ("freefare_get_tags() failed"));
tag = NULL; tag = NULL;
for (int i=0; tags[i]; i++) { for (int i=0; tags[i]; i++) {
if (freefare_get_tag_type(tags[i]) == DESFIRE) { if (freefare_get_tag_type(tags[i]) == DESFIRE) {
tag = tags[i]; tag = tags[i];
res = mifare_desfire_connect (tag); res = mifare_desfire_connect (tag);
cut_assert_equal_int (0, res, cut_message ("mifare_desfire_connect() failed")); cut_assert_equal_int (0, res, cut_message ("mifare_desfire_connect() failed"));
struct mifare_desfire_version_info version_info; struct mifare_desfire_version_info version_info;
res = mifare_desfire_get_version (tag, &version_info); res = mifare_desfire_get_version (tag, &version_info);
cut_assert_equal_int (0, res, cut_message ("mifare_desfire_get_version")); cut_assert_equal_int (0, res, cut_message ("mifare_desfire_get_version"));
if ((version_info.hardware.version_major >= 1) && if ((version_info.hardware.version_major >= 1) &&
(version_info.software.version_major >= 1)) { (version_info.software.version_major >= 1)) {
return; return;
} }
mifare_desfire_disconnect (tag); mifare_desfire_disconnect (tag);
} }
} }
nfc_disconnect (device); nfc_close (device);
device = NULL; device = NULL;
freefare_free_tags (tags); freefare_free_tags (tags);
tags = NULL; tags = NULL;
} }
cut_omit ("No MIFARE DESFire EV1 tag on NFC device"); cut_omit ("No MIFARE DESFire EV1 tag on NFC device");
} }
@ -78,14 +79,16 @@ void
cut_teardown (void) cut_teardown (void)
{ {
if (tag) if (tag)
mifare_desfire_disconnect (tag); mifare_desfire_disconnect (tag);
if (tags) { if (tags) {
freefare_free_tags (tags); freefare_free_tags (tags);
tags = NULL; tags = NULL;
} }
if (device) if (device)
nfc_disconnect (device); nfc_close (device);
nfc_exit(NULL);
} }

View file

@ -22,60 +22,63 @@
#include "mifare_desfire_fixture.h" #include "mifare_desfire_fixture.h"
static nfc_device_t *device = NULL; static nfc_device *device = NULL;
static MifareTag *tags = NULL; static MifareTag *tags = NULL;
MifareTag tag = NULL; MifareTag tag = NULL;
void void
cut_setup (void) cut_setup (void)
{ {
int res; int res;
nfc_device_desc_t devices[8]; nfc_connstring devices[8];
size_t device_count; size_t device_count;
nfc_init(NULL);
nfc_list_devices (devices, 8, &device_count); device_count = nfc_list_devices (NULL, devices, 8);
if (!device_count) if (device_count <= 0)
cut_omit ("No device found"); cut_omit ("No device found");
for (size_t i = 0; i < device_count; i++) { for (size_t i = 0; i < device_count; i++) {
device = nfc_connect (&(devices[i])); device = nfc_open (NULL, devices[i]);
if (!device) if (!device)
cut_omit ("nfc_connect() failed"); cut_omit ("nfc_open() failed.");
tags = freefare_get_tags (device); tags = freefare_get_tags (device);
cut_assert_not_null (tags, cut_message ("freefare_get_tags() failed")); cut_assert_not_null (tags, cut_message ("freefare_get_tags() failed"));
tag = NULL; tag = NULL;
for (int i=0; tags[i]; i++) { for (int i=0; tags[i]; i++) {
if (freefare_get_tag_type(tags[i]) == DESFIRE) { if (freefare_get_tag_type(tags[i]) == DESFIRE) {
tag = tags[i]; tag = tags[i];
res = mifare_desfire_connect (tag); res = mifare_desfire_connect (tag);
cut_assert_equal_int (0, res, cut_message ("mifare_desfire_connect() failed")); cut_assert_equal_int (0, res, cut_message ("mifare_desfire_connect() failed"));
return; return;
} }
}
nfc_disconnect (device);
device = NULL;
freefare_free_tags (tags);
tags = NULL;
} }
nfc_close (device);
cut_omit ("No MIFARE DESFire tag on NFC device"); device = NULL;
freefare_free_tags (tags);
tags = NULL;
}
cut_omit ("No MIFARE DESFire tag on NFC device");
} }
void void
cut_teardown (void) cut_teardown (void)
{ {
if (tag) if (tag)
mifare_desfire_disconnect (tag); mifare_desfire_disconnect (tag);
if (tags) { if (tags) {
freefare_free_tags (tags); freefare_free_tags (tags);
tags = NULL; tags = NULL;
} }
if (device) if (device)
nfc_disconnect (device); nfc_close (device);
nfc_exit(NULL);
} }

View file

@ -22,7 +22,7 @@
#include "mifare_ultralight_fixture.h" #include "mifare_ultralight_fixture.h"
static nfc_device_t *device = NULL; static nfc_device *device = NULL;
static MifareTag *tags = NULL; static MifareTag *tags = NULL;
MifareTag tag = NULL; MifareTag tag = NULL;
@ -30,36 +30,38 @@ void
cut_setup (void) cut_setup (void)
{ {
int res; int res;
nfc_device_desc_t devices[8]; nfc_connstring devices[8];
size_t device_count; size_t device_count;
nfc_init(NULL);
nfc_list_devices (devices, 8, &device_count); device_count = nfc_list_devices (NULL, devices, 8);
if (!device_count) if (device_count <= 0)
cut_omit ("No device found"); cut_omit ("No device found");
for (size_t i = 0; i < device_count; i++) { for (size_t i = 0; i < device_count; i++) {
device = nfc_connect (&(devices[i])); device = nfc_open (NULL, devices[i]);
if (!device) if (!device)
cut_omit ("nfc_connect() failed"); cut_omit ("nfc_open() failed.");
tags = freefare_get_tags (device); tags = freefare_get_tags (device);
cut_assert_not_null (tags, cut_message ("freefare_get_tags() failed")); cut_assert_not_null (tags, cut_message ("freefare_get_tags() failed"));
tag = NULL; tag = NULL;
for (int i=0; tags[i]; i++) { for (int i=0; tags[i]; i++) {
if ((freefare_get_tag_type(tags[i]) == ULTRALIGHT) || if ((freefare_get_tag_type(tags[i]) == ULTRALIGHT) ||
(freefare_get_tag_type(tags[i]) == ULTRALIGHT_C)) { (freefare_get_tag_type(tags[i]) == ULTRALIGHT_C)) {
tag = tags[i]; tag = tags[i];
res = mifare_ultralight_connect (tag); res = mifare_ultralight_connect (tag);
cut_assert_equal_int (0, res, cut_message ("mifare_ultralight_connect() failed")); cut_assert_equal_int (0, res, cut_message ("mifare_ultralight_connect() failed"));
return; return;
} }
} }
nfc_disconnect (device); nfc_close (device);
device = NULL; device = NULL;
freefare_free_tags (tags); freefare_free_tags (tags);
tags = NULL; tags = NULL;
} }
cut_omit ("No MIFARE UltraLight tag on NFC device"); cut_omit ("No MIFARE UltraLight tag on NFC device");
@ -69,14 +71,16 @@ void
cut_teardown (void) cut_teardown (void)
{ {
if (tag) if (tag)
mifare_ultralight_disconnect (tag); mifare_ultralight_disconnect (tag);
if (tags) { if (tags) {
freefare_free_tags (tags); freefare_free_tags (tags);
tags = NULL; tags = NULL;
} }
if (device) if (device)
nfc_disconnect (device); nfc_close (device);
nfc_exit(NULL);
} }