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

View file

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

View file

@ -101,7 +101,7 @@ search_sector_key (MifareTag tag, MifareClassicSectorNumber sector, MifareClassi
}
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;
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[])
{
int error = 0;
nfc_device_t *device = NULL;
nfc_device *device = NULL;
MifareTag *tags = NULL;
Mad mad;
MifareClassicKey transport_key = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
@ -191,24 +191,26 @@ main(int argc, char *argv[])
err (EXIT_FAILURE, "malloc");
}
nfc_device_desc_t devices[8];
nfc_connstring devices[8];
size_t device_count;
nfc_list_devices (devices, 8, &device_count);
if (!device_count)
nfc_init(NULL);
device_count = nfc_list_devices (NULL, devices, 8);
if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found.");
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.");
warnx ("nfc_open() failed.");
error = EXIT_FAILURE;
continue;
}
tags = freefare_get_tags (device);
if (!tags) {
nfc_disconnect (device);
nfc_close (device);
errx (EXIT_FAILURE, "Error listing MIFARE classic tag.");
}
@ -399,10 +401,10 @@ error:
}
freefare_free_tags (tags);
nfc_disconnect (device);
nfc_close (device);
}
free (card_write_keys);
nfc_exit(NULL);
exit (error);
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -48,7 +48,7 @@ int
main(int argc, char *argv[])
{
int error = EXIT_SUCCESS;
nfc_device_t *device = NULL;
nfc_device *device = NULL;
MifareTag *tags = NULL;
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)
errx (EXIT_FAILURE, "usage: %s", argv[0]);
nfc_device_desc_t devices[8];
nfc_connstring devices[8];
size_t device_count;
nfc_list_devices (devices, 8, &device_count);
if (!device_count)
nfc_init(NULL);
device_count = nfc_list_devices (NULL, devices, 8);
if (device_count <= 0)
errx (EXIT_FAILURE, "No NFC device found.");
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.");
warnx ("nfc_open() failed.");
error = EXIT_FAILURE;
continue;
}
tags = freefare_get_tags (device);
if (!tags) {
nfc_disconnect (device);
nfc_close (device);
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
// 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
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
0x10, // Mapping version
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);
}
freefare_free_tags (tags);
nfc_disconnect (device);
nfc_close (device);
}
nfc_exit(NULL);
exit (error);
}

View file

@ -41,7 +41,7 @@ struct supported_tag supported_tags[] = {
* Automagically allocate a MifareTag given a device and target info.
*/
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;
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.
*/
MifareTag *
freefare_get_tags (nfc_device_t *device)
freefare_get_tags (nfc_device *device)
{
MifareTag *tags = NULL;
int tag_count = 0;
@ -118,24 +118,24 @@ freefare_get_tags (nfc_device_t *device)
nfc_initiator_init(device);
// 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
nfc_configure(device,NDO_HANDLE_CRC,true);
nfc_configure(device,NDO_HANDLE_PARITY,true);
nfc_configure(device,NDO_AUTO_ISO14443_4,true);
nfc_device_set_property_bool(device,NP_HANDLE_CRC,true);
nfc_device_set_property_bool(device,NP_HANDLE_PARITY,true);
nfc_device_set_property_bool(device,NP_AUTO_ISO14443_4,true);
// 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
nfc_target_t candidates[MAX_CANDIDATES];
nfc_target candidates[MAX_CANDIDATES];
size_t candidates_count;
nfc_modulation_t modulation = {
nfc_modulation modulation = {
.nmt = NMT_ISO14443A,
.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;
tags = malloc(sizeof (void *));
@ -216,7 +216,7 @@ const char *
freefare_strerror (MifareTag tag)
{
const char *p = "Unkown error";
if (tag->device->iLastError > 0) {
if (nfc_device_get_last_error (tag->device) < 0) {
p = nfc_strerror (tag->device);
} else {
if (tag->tag_info->type == DESFIRE) {
@ -227,7 +227,6 @@ freefare_strerror (MifareTag tag)
}
}
}
return p;
}
@ -257,7 +256,6 @@ freefare_free_tags (MifareTag *tags)
}
}
/*
* Low-level API

View file

@ -52,8 +52,8 @@ typedef struct mifare_desfire_key *MifareDESFireKey;
typedef uint8_t MifareUltralightPageNumber;
typedef unsigned char MifareUltralightPage[4];
MifareTag *freefare_get_tags (nfc_device_t *device);
MifareTag freefare_tag_new (nfc_device_t *device, nfc_iso14443a_info_t nai);
MifareTag *freefare_get_tags (nfc_device *device);
MifareTag freefare_tag_new (nfc_device *device, nfc_iso14443a_info nai);
enum mifare_tag_type freefare_get_tag_type (MifareTag tag);
const char *freefare_get_tag_friendly_name (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_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];

View file

@ -173,7 +173,7 @@ struct supported_tag {
uint8_t ATS_min_length;
uint8_t ATS_compare_length;
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.
*/
struct mifare_tag {
nfc_device_t *device;
nfc_iso14443a_info_t info;
nfc_device *device;
nfc_iso14443a_info info;
const struct supported_tag *tag_info;
int active;
};

View file

@ -89,7 +89,7 @@
do { \
errno = 0; \
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) { \
tag->active = false; \
} \
@ -228,12 +228,12 @@ mifare_classic_connect (MifareTag tag)
ASSERT_INACTIVE (tag);
ASSERT_MIFARE_CLASSIC (tag);
nfc_target_t pnti;
nfc_modulation_t modulation = {
nfc_target pnti;
nfc_modulation modulation = {
.nmt = NMT_ISO14443A,
.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;
} else {
errno = EIO;
@ -251,7 +251,7 @@ mifare_classic_disconnect (MifareTag tag)
ASSERT_ACTIVE (tag);
ASSERT_MIFARE_CLASSIC (tag);
if (nfc_initiator_deselect_target (tag->device)) {
if (nfc_initiator_deselect_target (tag->device) >= 0) {
tag->active = 0;
} else {
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_pcd_error = OPERATION_OK; \
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; \
} \
DEBUG_XFER (__res, __##res##_n, "<=== "); \
@ -276,12 +276,12 @@ mifare_desfire_connect (MifareTag tag)
ASSERT_INACTIVE (tag);
ASSERT_MIFARE_DESFIRE (tag);
nfc_target_t pnti;
nfc_modulation_t modulation = {
nfc_target pnti;
nfc_modulation modulation = {
.nmt = NMT_ISO14443A,
.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;
free (MIFARE_DESFIRE (tag)->session_key);
MIFARE_DESFIRE (tag)->session_key = NULL;
@ -308,7 +308,7 @@ mifare_desfire_disconnect (MifareTag tag)
free (MIFARE_DESFIRE (tag)->session_key);
MIFARE_DESFIRE(tag)->session_key = NULL;
if (nfc_initiator_deselect_target (tag->device)) {
if (nfc_initiator_deselect_target (tag->device) >= 0) {
tag->active = 0;
}
return 0;

View file

@ -62,7 +62,7 @@
do { \
errno = 0; \
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; \
} \
DEBUG_XFER (res, __##res##_n, "<=== "); \
@ -71,17 +71,17 @@
#define ULTRALIGHT_TRANSCEIVE_RAW(tag, msg, res) \
do { \
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; \
return -1; \
} \
DEBUG_XFER (msg, __##msg##_n, "===> "); \
if (!(nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, &__##res##_n, NULL))) { \
nfc_configure (tag->device, NDO_EASY_FRAMING, true); \
if ((nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, &__##res##_n, 0)) < 0) { \
nfc_device_set_property_bool (tag->device, NP_EASY_FRAMING, true); \
return errno = EIO, -1; \
} \
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; \
return -1; \
} \
@ -129,12 +129,12 @@ mifare_ultralight_connect (MifareTag tag)
ASSERT_INACTIVE (tag);
ASSERT_MIFARE_ULTRALIGHT (tag);
nfc_target_t pnti;
nfc_modulation_t modulation = {
nfc_target pnti;
nfc_modulation modulation = {
.nmt = NMT_ISO14443A,
.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;
for (int i = 0; i < MIFARE_ULTRALIGHT_MAX_PAGE_COUNT; i++)
MIFARE_ULTRALIGHT(tag)->cached_pages[i] = 0;
@ -154,7 +154,7 @@ mifare_ultralight_disconnect (MifareTag tag)
ASSERT_ACTIVE (tag);
ASSERT_MIFARE_ULTRALIGHT (tag);
if (nfc_initiator_deselect_target (tag->device)) {
if (nfc_initiator_deselect_target (tag->device) >= 0) {
tag->active = 0;
} else {
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.
*/
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;
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[1] = 0x00;
nfc_target_t pnti;
nfc_modulation_t modulation = {
nfc_target pnti;
nfc_modulation modulation = {
.nmt = NMT_ISO14443A,
.nbr = NBR_106
};
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;
ret = nfc_initiator_transceive_bytes (device, cmd_step1, sizeof (cmd_step1), res_step1, &n, NULL);
nfc_configure (device, NDO_EASY_FRAMING, true);
ret = nfc_initiator_transceive_bytes (device, cmd_step1, sizeof (cmd_step1), res_step1, &n, 0);
nfc_device_set_property_bool (device, NP_EASY_FRAMING, true);
nfc_initiator_deselect_target (device);
return ret;
}

View file

@ -22,7 +22,7 @@
#include "mifare_classic_fixture.h"
static nfc_device_t *device = NULL;
static nfc_device *device = NULL;
static MifareTag *tags = NULL;
MifareTag tag = NULL;
@ -30,18 +30,19 @@ void
cut_setup (void)
{
int res;
nfc_device_desc_t devices[8];
nfc_connstring devices[8];
size_t device_count;
nfc_list_devices (devices, 8, &device_count);
if (!device_count)
nfc_init(NULL);
device_count = nfc_list_devices (NULL, devices, 8);
if (device_count <= 0)
cut_omit ("No device found");
for (size_t i = 0; i < device_count; i++) {
device = nfc_connect (&(devices[i]));
device = nfc_open (NULL, devices[i]);
if (!device)
cut_omit ("nfc_connect() failed");
cut_omit ("nfc_open() failed.");
tags = freefare_get_tags (device);
cut_assert_not_null (tags, cut_message ("freefare_get_tags() failed"));
@ -56,12 +57,11 @@ cut_setup (void)
return;
}
}
nfc_disconnect (device);
nfc_close (device);
device = NULL;
freefare_free_tags (tags);
tags = NULL;
}
cut_omit ("No MIFARE Classic tag on NFC device");
}
@ -77,6 +77,8 @@ cut_teardown (void)
}
if (device)
nfc_disconnect (device);
nfc_close (device);
nfc_exit(NULL);
}

View file

@ -22,7 +22,7 @@
#include "mifare_desfire_ev1_fixture.h"
static nfc_device_t *device = NULL;
static nfc_device *device = NULL;
static MifareTag *tags = NULL;
MifareTag tag = NULL;
@ -30,18 +30,20 @@ void
cut_setup (void)
{
int res;
nfc_device_desc_t devices[8];
nfc_connstring devices[8];
size_t device_count;
nfc_list_devices (devices, 8, &device_count);
if (!device_count)
nfc_init(NULL);
device_count = nfc_list_devices (NULL, devices, 8);
if (device_count <= 0)
cut_omit ("No device found");
for (size_t i = 0; i < device_count; i++) {
device = nfc_connect (&(devices[i]));
device = nfc_open (NULL, devices[i]);
if (!device)
cut_omit ("nfc_connect() failed");
cut_omit ("nfc_open() failed.");
tags = freefare_get_tags (device);
cut_assert_not_null (tags, cut_message ("freefare_get_tags() failed"));
@ -65,12 +67,11 @@ cut_setup (void)
mifare_desfire_disconnect (tag);
}
}
nfc_disconnect (device);
nfc_close (device);
device = NULL;
freefare_free_tags (tags);
tags = NULL;
}
cut_omit ("No MIFARE DESFire EV1 tag on NFC device");
}
@ -86,6 +87,8 @@ cut_teardown (void)
}
if (device)
nfc_disconnect (device);
nfc_close (device);
nfc_exit(NULL);
}

View file

@ -22,7 +22,7 @@
#include "mifare_desfire_fixture.h"
static nfc_device_t *device = NULL;
static nfc_device *device = NULL;
static MifareTag *tags = NULL;
MifareTag tag = NULL;
@ -30,18 +30,20 @@ void
cut_setup (void)
{
int res;
nfc_device_desc_t devices[8];
nfc_connstring devices[8];
size_t device_count;
nfc_list_devices (devices, 8, &device_count);
if (!device_count)
nfc_init(NULL);
device_count = nfc_list_devices (NULL, devices, 8);
if (device_count <= 0)
cut_omit ("No device found");
for (size_t i = 0; i < device_count; i++) {
device = nfc_connect (&(devices[i]));
device = nfc_open (NULL, devices[i]);
if (!device)
cut_omit ("nfc_connect() failed");
cut_omit ("nfc_open() failed.");
tags = freefare_get_tags (device);
cut_assert_not_null (tags, cut_message ("freefare_get_tags() failed"));
@ -55,12 +57,11 @@ cut_setup (void)
return;
}
}
nfc_disconnect (device);
nfc_close (device);
device = NULL;
freefare_free_tags (tags);
tags = NULL;
}
cut_omit ("No MIFARE DESFire tag on NFC device");
}
@ -76,6 +77,8 @@ cut_teardown (void)
}
if (device)
nfc_disconnect (device);
nfc_close (device);
nfc_exit(NULL);
}

View file

@ -22,7 +22,7 @@
#include "mifare_ultralight_fixture.h"
static nfc_device_t *device = NULL;
static nfc_device *device = NULL;
static MifareTag *tags = NULL;
MifareTag tag = NULL;
@ -30,18 +30,20 @@ void
cut_setup (void)
{
int res;
nfc_device_desc_t devices[8];
nfc_connstring devices[8];
size_t device_count;
nfc_list_devices (devices, 8, &device_count);
if (!device_count)
nfc_init(NULL);
device_count = nfc_list_devices (NULL, devices, 8);
if (device_count <= 0)
cut_omit ("No device found");
for (size_t i = 0; i < device_count; i++) {
device = nfc_connect (&(devices[i]));
device = nfc_open (NULL, devices[i]);
if (!device)
cut_omit ("nfc_connect() failed");
cut_omit ("nfc_open() failed.");
tags = freefare_get_tags (device);
cut_assert_not_null (tags, cut_message ("freefare_get_tags() failed"));
@ -56,7 +58,7 @@ cut_setup (void)
return;
}
}
nfc_disconnect (device);
nfc_close (device);
device = NULL;
freefare_free_tags (tags);
tags = NULL;
@ -77,6 +79,8 @@ cut_teardown (void)
}
if (device)
nfc_disconnect (device);
nfc_close (device);
nfc_exit(NULL);
}