Run make style to fix style
This commit is contained in:
parent
187481bb4c
commit
73dc0529fa
66 changed files with 5945 additions and 5949 deletions
|
|
@ -1,11 +1,11 @@
|
|||
/*-
|
||||
* Copyright (C) 2010, Romain Tartiere.
|
||||
*
|
||||
*
|
||||
* 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
@ -26,57 +26,58 @@ uint8_t key_data_des[8] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' };
|
|||
uint8_t key_data_3des[16] = { 'C', 'a', 'r', 'd', ' ', 'M', 'a', 's', 't', 'e', 'r', ' ', 'K', 'e', 'y', '!' };
|
||||
uint8_t key_data_aes[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
uint8_t key_data_3k3des[24] = { 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
const uint8_t key_data_aes_version = 0x42;
|
||||
|
||||
void
|
||||
mifare_desfire_auto_authenticate (FreefareTag tag, uint8_t key_no)
|
||||
mifare_desfire_auto_authenticate(FreefareTag tag, uint8_t key_no)
|
||||
{
|
||||
/* Determine which key is currently the master one */
|
||||
uint8_t key_version;
|
||||
int res = mifare_desfire_get_key_version (tag, key_no, &key_version);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_desfire_get_key_version()"));
|
||||
int res = mifare_desfire_get_key_version(tag, key_no, &key_version);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_desfire_get_key_version()"));
|
||||
|
||||
MifareDESFireKey key;
|
||||
|
||||
switch (key_version) {
|
||||
case 0x00:
|
||||
key = mifare_desfire_des_key_new_with_version (key_data_null);
|
||||
key = mifare_desfire_des_key_new_with_version(key_data_null);
|
||||
break;
|
||||
case 0x42:
|
||||
key = mifare_desfire_aes_key_new_with_version (key_data_aes, key_data_aes_version);
|
||||
key = mifare_desfire_aes_key_new_with_version(key_data_aes, key_data_aes_version);
|
||||
break;
|
||||
case 0xAA:
|
||||
key = mifare_desfire_des_key_new_with_version (key_data_des);
|
||||
key = mifare_desfire_des_key_new_with_version(key_data_des);
|
||||
break;
|
||||
case 0xC7:
|
||||
key = mifare_desfire_3des_key_new_with_version (key_data_3des);
|
||||
key = mifare_desfire_3des_key_new_with_version(key_data_3des);
|
||||
break;
|
||||
case 0x55:
|
||||
key = mifare_desfire_3k3des_key_new_with_version (key_data_3k3des);
|
||||
key = mifare_desfire_3k3des_key_new_with_version(key_data_3k3des);
|
||||
break;
|
||||
default:
|
||||
cut_fail ("Unknown master key.");
|
||||
cut_fail("Unknown master key.");
|
||||
}
|
||||
|
||||
cut_assert_not_null (key, cut_message ("Cannot allocate key"));
|
||||
cut_assert_not_null(key, cut_message("Cannot allocate key"));
|
||||
|
||||
/* Authenticate with this key */
|
||||
switch (key_version) {
|
||||
case 0x00:
|
||||
case 0xAA:
|
||||
case 0xC7:
|
||||
res = mifare_desfire_authenticate (tag, key_no, key);
|
||||
res = mifare_desfire_authenticate(tag, key_no, key);
|
||||
break;
|
||||
case 0x55:
|
||||
res = mifare_desfire_authenticate_iso (tag, key_no, key);
|
||||
res = mifare_desfire_authenticate_iso(tag, key_no, key);
|
||||
break;
|
||||
case 0x42:
|
||||
res = mifare_desfire_authenticate_aes (tag, key_no, key);
|
||||
res = mifare_desfire_authenticate_aes(tag, key_no, key);
|
||||
break;
|
||||
}
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_desfire_authenticate()"));
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_desfire_authenticate()"));
|
||||
|
||||
mifare_desfire_key_free (key);
|
||||
mifare_desfire_key_free(key);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/*-
|
||||
* Copyright (C) 2010, Romain Tartiere.
|
||||
*
|
||||
*
|
||||
* 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
@ -25,6 +25,6 @@ extern uint8_t key_data_aes[16];
|
|||
extern uint8_t key_data_3k3des[24];
|
||||
extern const uint8_t key_data_aes_version;
|
||||
|
||||
void mifare_desfire_auto_authenticate (FreefareTag tag, uint8_t key_no);
|
||||
void mifare_desfire_auto_authenticate(FreefareTag tag, uint8_t key_no);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/*-
|
||||
* Copyright (C) 2015, Romain Tartiere
|
||||
*
|
||||
*
|
||||
* 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
@ -26,52 +26,52 @@ static FreefareTag *tags = NULL;
|
|||
FreefareTag tag = NULL;
|
||||
|
||||
void
|
||||
cut_setup (void)
|
||||
cut_setup(void)
|
||||
{
|
||||
int res;
|
||||
nfc_connstring devices[8];
|
||||
size_t device_count;
|
||||
|
||||
nfc_init (&context);
|
||||
cut_assert_not_null (context, cut_message ("Unable to init libnfc (malloc)"));
|
||||
nfc_init(&context);
|
||||
cut_assert_not_null(context, cut_message("Unable to init libnfc (malloc)"));
|
||||
|
||||
device_count = nfc_list_devices (context, devices, 8);
|
||||
device_count = nfc_list_devices(context, devices, 8);
|
||||
if (device_count <= 0)
|
||||
cut_omit ("No device found");
|
||||
cut_omit("No device found");
|
||||
|
||||
for (size_t i = 0; i < device_count; i++) {
|
||||
device = nfc_open (context, devices[i]);
|
||||
if (!device)
|
||||
cut_omit ("nfc_open() failed.");
|
||||
device = nfc_open(context, devices[i]);
|
||||
if (!device)
|
||||
cut_omit("nfc_open() failed.");
|
||||
|
||||
tags = freefare_get_tags (device);
|
||||
cut_assert_not_null (tags, cut_message ("freefare_get_tags() failed"));
|
||||
tags = freefare_get_tags(device);
|
||||
cut_assert_not_null(tags, cut_message("freefare_get_tags() failed"));
|
||||
|
||||
tag = NULL;
|
||||
for (int i=0; tags[i]; i++) {
|
||||
if (freefare_get_tag_type(tags[i]) == FELICA) {
|
||||
tag = tags[i];
|
||||
return;
|
||||
}
|
||||
}
|
||||
nfc_close (device);
|
||||
device = NULL;
|
||||
freefare_free_tags (tags);
|
||||
tags = NULL;
|
||||
tag = NULL;
|
||||
for (int i = 0; tags[i]; i++) {
|
||||
if (freefare_get_tag_type(tags[i]) == FELICA) {
|
||||
tag = tags[i];
|
||||
return;
|
||||
}
|
||||
}
|
||||
nfc_close(device);
|
||||
device = NULL;
|
||||
freefare_free_tags(tags);
|
||||
tags = NULL;
|
||||
}
|
||||
cut_omit ("No FeliCa tag on NFC device");
|
||||
cut_omit("No FeliCa tag on NFC device");
|
||||
}
|
||||
|
||||
void
|
||||
cut_teardown (void)
|
||||
cut_teardown(void)
|
||||
{
|
||||
if (tags) {
|
||||
freefare_free_tags (tags);
|
||||
tags = NULL;
|
||||
freefare_free_tags(tags);
|
||||
tags = NULL;
|
||||
}
|
||||
|
||||
if (device)
|
||||
nfc_close (device);
|
||||
nfc_close(device);
|
||||
|
||||
nfc_exit (context);
|
||||
nfc_exit(context);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/*-
|
||||
* Copyright (C) 2015, Romain Tartiere.
|
||||
*
|
||||
*
|
||||
* 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/*-
|
||||
* Copyright (C) 2010, Romain Tartiere
|
||||
* Copyright (C) 2013, 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
@ -27,59 +27,59 @@ static FreefareTag *tags = NULL;
|
|||
FreefareTag tag = NULL;
|
||||
|
||||
void
|
||||
cut_setup (void)
|
||||
cut_setup(void)
|
||||
{
|
||||
int res;
|
||||
nfc_connstring devices[8];
|
||||
size_t device_count;
|
||||
|
||||
nfc_init (&context);
|
||||
cut_assert_not_null (context, cut_message ("Unable to init libnfc (malloc)"));
|
||||
nfc_init(&context);
|
||||
cut_assert_not_null(context, cut_message("Unable to init libnfc (malloc)"));
|
||||
|
||||
device_count = nfc_list_devices (context, devices, 8);
|
||||
device_count = nfc_list_devices(context, devices, 8);
|
||||
if (device_count <= 0)
|
||||
cut_omit ("No device found");
|
||||
cut_omit("No device found");
|
||||
|
||||
for (size_t i = 0; i < device_count; i++) {
|
||||
device = nfc_open (context, devices[i]);
|
||||
if (!device)
|
||||
cut_omit ("nfc_open() failed.");
|
||||
device = nfc_open(context, devices[i]);
|
||||
if (!device)
|
||||
cut_omit("nfc_open() failed.");
|
||||
|
||||
tags = freefare_get_tags (device);
|
||||
cut_assert_not_null (tags, cut_message ("freefare_get_tags() failed"));
|
||||
tags = freefare_get_tags(device);
|
||||
cut_assert_not_null(tags, cut_message("freefare_get_tags() failed"));
|
||||
|
||||
tag = NULL;
|
||||
for (int i=0; tags[i]; i++) {
|
||||
if ((freefare_get_tag_type(tags[i]) == MIFARE_CLASSIC_1K) ||
|
||||
(freefare_get_tag_type(tags[i]) == MIFARE_CLASSIC_4K)) {
|
||||
tag = tags[i];
|
||||
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);
|
||||
tags = NULL;
|
||||
tag = NULL;
|
||||
for (int i = 0; tags[i]; i++) {
|
||||
if ((freefare_get_tag_type(tags[i]) == MIFARE_CLASSIC_1K) ||
|
||||
(freefare_get_tag_type(tags[i]) == MIFARE_CLASSIC_4K)) {
|
||||
tag = tags[i];
|
||||
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);
|
||||
tags = NULL;
|
||||
}
|
||||
cut_omit ("No MIFARE Classic tag on NFC device");
|
||||
cut_omit("No MIFARE Classic tag on NFC device");
|
||||
}
|
||||
|
||||
void
|
||||
cut_teardown (void)
|
||||
cut_teardown(void)
|
||||
{
|
||||
if (tag)
|
||||
mifare_classic_disconnect (tag);
|
||||
mifare_classic_disconnect(tag);
|
||||
|
||||
if (tags) {
|
||||
freefare_free_tags (tags);
|
||||
tags = NULL;
|
||||
freefare_free_tags(tags);
|
||||
tags = NULL;
|
||||
}
|
||||
|
||||
if (device)
|
||||
nfc_close (device);
|
||||
nfc_close(device);
|
||||
|
||||
nfc_exit (context);
|
||||
nfc_exit(context);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/*-
|
||||
* Copyright (C) 2010, Romain Tartiere, 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/*-
|
||||
* Copyright (C) 2010, Romain Tartiere
|
||||
* Copyright (C) 2013, 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
@ -27,73 +27,73 @@ static FreefareTag *tags = NULL;
|
|||
FreefareTag tag = NULL;
|
||||
|
||||
void
|
||||
cut_setup (void)
|
||||
cut_setup(void)
|
||||
{
|
||||
int res;
|
||||
nfc_connstring devices[8];
|
||||
size_t device_count;
|
||||
|
||||
nfc_init (&context);
|
||||
cut_assert_not_null (context, cut_message ("Unable to init libnfc (malloc)"));
|
||||
nfc_init(&context);
|
||||
cut_assert_not_null(context, cut_message("Unable to init libnfc (malloc)"));
|
||||
|
||||
device_count = nfc_list_devices (context, devices, 8);
|
||||
device_count = nfc_list_devices(context, devices, 8);
|
||||
if (device_count <= 0)
|
||||
cut_omit ("No device found");
|
||||
cut_omit("No device found");
|
||||
|
||||
for (size_t i = 0; i < device_count; i++) {
|
||||
|
||||
device = nfc_open (context, devices[i]);
|
||||
if (!device)
|
||||
cut_omit ("nfc_open() failed.");
|
||||
device = nfc_open(context, devices[i]);
|
||||
if (!device)
|
||||
cut_omit("nfc_open() failed.");
|
||||
|
||||
tags = freefare_get_tags (device);
|
||||
cut_assert_not_null (tags, cut_message ("freefare_get_tags() failed"));
|
||||
tags = freefare_get_tags(device);
|
||||
cut_assert_not_null(tags, cut_message("freefare_get_tags() failed"));
|
||||
|
||||
tag = NULL;
|
||||
for (int i=0; tags[i]; i++) {
|
||||
if (freefare_get_tag_type(tags[i]) == MIFARE_DESFIRE) {
|
||||
tag = tags[i];
|
||||
res = mifare_desfire_connect (tag);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_desfire_connect() failed"));
|
||||
tag = NULL;
|
||||
for (int i = 0; tags[i]; i++) {
|
||||
if (freefare_get_tag_type(tags[i]) == MIFARE_DESFIRE) {
|
||||
tag = tags[i];
|
||||
res = mifare_desfire_connect(tag);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_desfire_connect() failed"));
|
||||
|
||||
struct mifare_desfire_version_info version_info;
|
||||
res = mifare_desfire_get_version (tag, &version_info);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_desfire_get_version"));
|
||||
struct mifare_desfire_version_info version_info;
|
||||
res = mifare_desfire_get_version(tag, &version_info);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_desfire_get_version"));
|
||||
|
||||
if (version_info.hardware.storage_size < 0x18) {
|
||||
cut_omit ("DESFire EV1 tests require at least a 4K card");
|
||||
}
|
||||
if (version_info.hardware.storage_size < 0x18) {
|
||||
cut_omit("DESFire EV1 tests require at least a 4K card");
|
||||
}
|
||||
|
||||
if ((version_info.hardware.version_major >= 1) &&
|
||||
(version_info.software.version_major >= 1)) {
|
||||
return;
|
||||
}
|
||||
if ((version_info.hardware.version_major >= 1) &&
|
||||
(version_info.software.version_major >= 1)) {
|
||||
return;
|
||||
}
|
||||
|
||||
mifare_desfire_disconnect (tag);
|
||||
}
|
||||
}
|
||||
nfc_close (device);
|
||||
device = NULL;
|
||||
freefare_free_tags (tags);
|
||||
tags = NULL;
|
||||
mifare_desfire_disconnect(tag);
|
||||
}
|
||||
}
|
||||
nfc_close(device);
|
||||
device = NULL;
|
||||
freefare_free_tags(tags);
|
||||
tags = NULL;
|
||||
}
|
||||
cut_omit ("No MIFARE DESFire EV1 tag on NFC device");
|
||||
cut_omit("No MIFARE DESFire EV1 tag on NFC device");
|
||||
}
|
||||
|
||||
void
|
||||
cut_teardown (void)
|
||||
cut_teardown(void)
|
||||
{
|
||||
if (tag)
|
||||
mifare_desfire_disconnect (tag);
|
||||
mifare_desfire_disconnect(tag);
|
||||
|
||||
if (tags) {
|
||||
freefare_free_tags (tags);
|
||||
tags = NULL;
|
||||
freefare_free_tags(tags);
|
||||
tags = NULL;
|
||||
}
|
||||
|
||||
if (device)
|
||||
nfc_close (device);
|
||||
nfc_close(device);
|
||||
|
||||
nfc_exit (context);
|
||||
nfc_exit(context);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/*-
|
||||
* Copyright (C) 2010, Romain Tartiere.
|
||||
*
|
||||
*
|
||||
* 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/*-
|
||||
* Copyright (C) 2010, Romain Tartiere
|
||||
* Copyright (C) 2013, 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
@ -27,68 +27,68 @@ static FreefareTag *tags = NULL;
|
|||
FreefareTag tag = NULL;
|
||||
|
||||
void
|
||||
cut_setup (void)
|
||||
cut_setup(void)
|
||||
{
|
||||
int res;
|
||||
nfc_connstring devices[8];
|
||||
size_t device_count;
|
||||
int res;
|
||||
nfc_connstring devices[8];
|
||||
size_t device_count;
|
||||
|
||||
nfc_init (&context);
|
||||
cut_assert_not_null (context, cut_message ("Unable to init libnfc (malloc)"));
|
||||
nfc_init(&context);
|
||||
cut_assert_not_null(context, cut_message("Unable to init libnfc (malloc)"));
|
||||
|
||||
device_count = nfc_list_devices (context, devices, 8);
|
||||
if (device_count <= 0)
|
||||
cut_omit ("No device found");
|
||||
device_count = nfc_list_devices(context, devices, 8);
|
||||
if (device_count <= 0)
|
||||
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 (context, devices[i]);
|
||||
if (!device)
|
||||
cut_omit ("nfc_open() failed.");
|
||||
device = nfc_open(context, devices[i]);
|
||||
if (!device)
|
||||
cut_omit("nfc_open() failed.");
|
||||
|
||||
tags = freefare_get_tags (device);
|
||||
cut_assert_not_null (tags, cut_message ("freefare_get_tags() failed"));
|
||||
tags = freefare_get_tags(device);
|
||||
cut_assert_not_null(tags, cut_message("freefare_get_tags() failed"));
|
||||
|
||||
tag = NULL;
|
||||
for (int i=0; tags[i]; i++) {
|
||||
if (freefare_get_tag_type(tags[i]) == MIFARE_DESFIRE) {
|
||||
tag = tags[i];
|
||||
res = mifare_desfire_connect (tag);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_desfire_connect() failed"));
|
||||
tag = NULL;
|
||||
for (int i = 0; tags[i]; i++) {
|
||||
if (freefare_get_tag_type(tags[i]) == MIFARE_DESFIRE) {
|
||||
tag = tags[i];
|
||||
res = mifare_desfire_connect(tag);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_desfire_connect() failed"));
|
||||
|
||||
struct mifare_desfire_version_info version_info;
|
||||
res = mifare_desfire_get_version (tag, &version_info);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_desfire_get_version"));
|
||||
struct mifare_desfire_version_info version_info;
|
||||
res = mifare_desfire_get_version(tag, &version_info);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_desfire_get_version"));
|
||||
|
||||
if (version_info.hardware.storage_size < 0x18) {
|
||||
cut_omit ("DESFire tests require at least a 4K card");
|
||||
}
|
||||
if (version_info.hardware.storage_size < 0x18) {
|
||||
cut_omit("DESFire tests require at least a 4K card");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
nfc_close(device);
|
||||
device = NULL;
|
||||
freefare_free_tags(tags);
|
||||
tags = NULL;
|
||||
}
|
||||
nfc_close (device);
|
||||
device = NULL;
|
||||
freefare_free_tags (tags);
|
||||
tags = NULL;
|
||||
}
|
||||
cut_omit ("No MIFARE DESFire tag on NFC device");
|
||||
cut_omit("No MIFARE DESFire tag on NFC device");
|
||||
}
|
||||
|
||||
void
|
||||
cut_teardown (void)
|
||||
cut_teardown(void)
|
||||
{
|
||||
if (tag)
|
||||
mifare_desfire_disconnect (tag);
|
||||
if (tag)
|
||||
mifare_desfire_disconnect(tag);
|
||||
|
||||
if (tags) {
|
||||
freefare_free_tags (tags);
|
||||
tags = NULL;
|
||||
}
|
||||
if (tags) {
|
||||
freefare_free_tags(tags);
|
||||
tags = NULL;
|
||||
}
|
||||
|
||||
if (device)
|
||||
nfc_close (device);
|
||||
if (device)
|
||||
nfc_close(device);
|
||||
|
||||
nfc_exit (context);
|
||||
nfc_exit(context);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/*-
|
||||
* Copyright (C) 2010, Romain Tartiere.
|
||||
*
|
||||
*
|
||||
* 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/*-
|
||||
* Copyright (C) 2010, Romain Tartiere
|
||||
* Copyright (C) 2013, 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
@ -27,61 +27,61 @@ static FreefareTag *tags = NULL;
|
|||
FreefareTag tag = NULL;
|
||||
|
||||
void
|
||||
cut_setup (void)
|
||||
cut_setup(void)
|
||||
{
|
||||
int res;
|
||||
nfc_connstring devices[8];
|
||||
size_t device_count;
|
||||
|
||||
nfc_init (&context);
|
||||
cut_assert_not_null (context, cut_message ("Unable to init libnfc (malloc)"));
|
||||
nfc_init(&context);
|
||||
cut_assert_not_null(context, cut_message("Unable to init libnfc (malloc)"));
|
||||
|
||||
device_count = nfc_list_devices (context, devices, 8);
|
||||
device_count = nfc_list_devices(context, devices, 8);
|
||||
if (device_count <= 0)
|
||||
cut_omit ("No device found");
|
||||
cut_omit("No device found");
|
||||
|
||||
for (size_t i = 0; i < device_count; i++) {
|
||||
|
||||
device = nfc_open (context, devices[i]);
|
||||
if (!device)
|
||||
cut_omit ("nfc_open() failed.");
|
||||
device = nfc_open(context, devices[i]);
|
||||
if (!device)
|
||||
cut_omit("nfc_open() failed.");
|
||||
|
||||
tags = freefare_get_tags (device);
|
||||
cut_assert_not_null (tags, cut_message ("freefare_get_tags() failed"));
|
||||
tags = freefare_get_tags(device);
|
||||
cut_assert_not_null(tags, cut_message("freefare_get_tags() failed"));
|
||||
|
||||
tag = NULL;
|
||||
for (int i=0; tags[i]; i++) {
|
||||
if ((freefare_get_tag_type(tags[i]) == MIFARE_ULTRALIGHT) ||
|
||||
(freefare_get_tag_type(tags[i]) == MIFARE_ULTRALIGHT_C)) {
|
||||
tag = tags[i];
|
||||
res = mifare_ultralight_connect (tag);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_ultralight_connect() failed"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
nfc_close (device);
|
||||
device = NULL;
|
||||
freefare_free_tags (tags);
|
||||
tags = NULL;
|
||||
tag = NULL;
|
||||
for (int i = 0; tags[i]; i++) {
|
||||
if ((freefare_get_tag_type(tags[i]) == MIFARE_ULTRALIGHT) ||
|
||||
(freefare_get_tag_type(tags[i]) == MIFARE_ULTRALIGHT_C)) {
|
||||
tag = tags[i];
|
||||
res = mifare_ultralight_connect(tag);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_ultralight_connect() failed"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
nfc_close(device);
|
||||
device = NULL;
|
||||
freefare_free_tags(tags);
|
||||
tags = NULL;
|
||||
}
|
||||
|
||||
cut_omit ("No MIFARE UltraLight tag on NFC device");
|
||||
cut_omit("No MIFARE UltraLight tag on NFC device");
|
||||
}
|
||||
|
||||
void
|
||||
cut_teardown (void)
|
||||
cut_teardown(void)
|
||||
{
|
||||
if (tag)
|
||||
mifare_ultralight_disconnect (tag);
|
||||
mifare_ultralight_disconnect(tag);
|
||||
|
||||
if (tags) {
|
||||
freefare_free_tags (tags);
|
||||
tags = NULL;
|
||||
freefare_free_tags(tags);
|
||||
tags = NULL;
|
||||
}
|
||||
|
||||
if (device)
|
||||
nfc_close (device);
|
||||
nfc_close(device);
|
||||
|
||||
nfc_exit (context);
|
||||
nfc_exit(context);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/*-
|
||||
* Copyright (C) 2010, Romain Tartiere.
|
||||
*
|
||||
*
|
||||
* 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@
|
|||
#include "felica_fixture.h"
|
||||
|
||||
void
|
||||
test_felica_read_without_encryption (void)
|
||||
test_felica_read_without_encryption(void)
|
||||
{
|
||||
uint8_t buffer[64];
|
||||
|
||||
int res = felica_read (tag, FELICA_SC_RO, 0x00, buffer, 16);
|
||||
cut_assert_equal_int (16, res);
|
||||
int res = felica_read(tag, FELICA_SC_RO, 0x00, buffer, 16);
|
||||
cut_assert_equal_int(16, res);
|
||||
|
||||
uint8_t blocks[] = {
|
||||
0x02,
|
||||
|
|
@ -18,12 +18,12 @@ test_felica_read_without_encryption (void)
|
|||
0x04,
|
||||
};
|
||||
|
||||
res = felica_read_ex (tag, FELICA_SC_RO, 3, blocks, buffer, 3 * 16);
|
||||
cut_assert_equal_int (3 * 16, res);
|
||||
res = felica_read_ex(tag, FELICA_SC_RO, 3, blocks, buffer, 3 * 16);
|
||||
cut_assert_equal_int(3 * 16, res);
|
||||
}
|
||||
|
||||
void
|
||||
test_felica_write_without_encryption (void)
|
||||
test_felica_write_without_encryption(void)
|
||||
{
|
||||
uint8_t buffer[16] = {
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
|
|
@ -32,7 +32,7 @@ test_felica_write_without_encryption (void)
|
|||
0x0b, 0x0c, 0x0d, 0x0e,
|
||||
};
|
||||
|
||||
int res = felica_write (tag, FELICA_SC_RW, 0x0a, buffer, sizeof (buffer));
|
||||
int res = felica_write(tag, FELICA_SC_RW, 0x0a, buffer, sizeof(buffer));
|
||||
|
||||
cut_assert_equal_int (0, res);
|
||||
cut_assert_equal_int(0, res);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,23 +4,23 @@
|
|||
#include "freefare_internal.h"
|
||||
|
||||
void
|
||||
test_is_mifare_ultralight (void)
|
||||
test_is_mifare_ultralight(void)
|
||||
{
|
||||
FreefareTag tag;
|
||||
nfc_target target;
|
||||
|
||||
tag = mifare_ultralight_tag_new (NULL, target);
|
||||
cut_assert_true (is_mifare_ultralight (tag));
|
||||
mifare_ultralight_tag_free (tag);
|
||||
tag = mifare_ultralight_tag_new(NULL, target);
|
||||
cut_assert_true(is_mifare_ultralight(tag));
|
||||
mifare_ultralight_tag_free(tag);
|
||||
}
|
||||
|
||||
void
|
||||
test_is_mifare_ultralightc (void)
|
||||
test_is_mifare_ultralightc(void)
|
||||
{
|
||||
FreefareTag tag;
|
||||
nfc_target target;
|
||||
|
||||
tag = mifare_ultralightc_tag_new (NULL, target);
|
||||
cut_assert_true (is_mifare_ultralightc (tag));
|
||||
mifare_ultralightc_tag_free (tag);
|
||||
tag = mifare_ultralightc_tag_new(NULL, target);
|
||||
cut_assert_true(is_mifare_ultralightc(tag));
|
||||
mifare_ultralightc_tag_free(tag);
|
||||
}
|
||||
|
|
|
|||
112
test/test_mad.c
112
test/test_mad.c
|
|
@ -1,11 +1,11 @@
|
|||
/*-
|
||||
* Copyright (C) 2009, 2010, Romain Tartiere, 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
@ -21,54 +21,54 @@
|
|||
#include "freefare_internal.h"
|
||||
|
||||
void
|
||||
test_mad (void)
|
||||
test_mad(void)
|
||||
{
|
||||
int res;
|
||||
|
||||
Mad mad = mad_new (1);
|
||||
cut_assert_not_null (mad, cut_message ("Can create a new MAD"));
|
||||
Mad mad = mad_new(1);
|
||||
cut_assert_not_null(mad, cut_message("Can create a new MAD"));
|
||||
|
||||
cut_assert_equal_int (1, mad_get_version (mad), cut_message ("Wrong default MAD version"));
|
||||
mad_set_version (mad, 2);
|
||||
cut_assert_equal_int (2, mad_get_version (mad), cut_message ("Can't change MAD version"));
|
||||
cut_assert_equal_int(1, mad_get_version(mad), cut_message("Wrong default MAD version"));
|
||||
mad_set_version(mad, 2);
|
||||
cut_assert_equal_int(2, mad_get_version(mad), cut_message("Can't change MAD version"));
|
||||
|
||||
cut_assert_equal_int (0, mad_get_card_publisher_sector (mad), cut_message ("Wrong default MAD publisher"));
|
||||
cut_assert_equal_int(0, mad_get_card_publisher_sector(mad), cut_message("Wrong default MAD publisher"));
|
||||
|
||||
res = mad_set_card_publisher_sector (mad, 13);
|
||||
cut_assert_equal_int (0, res, cut_message ("mad_set_card_publisher_sector() returned an error."));
|
||||
cut_assert_equal_int (13, mad_get_card_publisher_sector (mad), cut_message ("Wrong publisher sector"));
|
||||
res = mad_set_card_publisher_sector(mad, 13);
|
||||
cut_assert_equal_int(0, res, cut_message("mad_set_card_publisher_sector() returned an error."));
|
||||
cut_assert_equal_int(13, mad_get_card_publisher_sector(mad), cut_message("Wrong publisher sector"));
|
||||
|
||||
res = mad_set_card_publisher_sector (mad, 0xff);
|
||||
cut_assert_equal_int (-1, res, cut_message ("Invalid sector"));
|
||||
cut_assert_equal_int (13, mad_get_card_publisher_sector (mad), cut_message ("Previous publisher sector value"));
|
||||
res = mad_set_card_publisher_sector(mad, 0xff);
|
||||
cut_assert_equal_int(-1, res, cut_message("Invalid sector"));
|
||||
cut_assert_equal_int(13, mad_get_card_publisher_sector(mad), cut_message("Previous publisher sector value"));
|
||||
|
||||
MadAid aid = {
|
||||
.function_cluster_code = 0,
|
||||
.application_code = 0
|
||||
};
|
||||
|
||||
res = mad_get_aid (mad, 3, &aid);
|
||||
cut_assert_equal_int (0, res, cut_message ("mad_get_aid() failed"));
|
||||
cut_assert_equal_int (0, aid.function_cluster_code, cut_message ("Invalid default value"));
|
||||
cut_assert_equal_int (0, aid.application_code, cut_message ("Invalid default value"));
|
||||
res = mad_get_aid(mad, 3, &aid);
|
||||
cut_assert_equal_int(0, res, cut_message("mad_get_aid() failed"));
|
||||
cut_assert_equal_int(0, aid.function_cluster_code, cut_message("Invalid default value"));
|
||||
cut_assert_equal_int(0, aid.application_code, cut_message("Invalid default value"));
|
||||
|
||||
aid.function_cluster_code = 0xc0;
|
||||
aid.application_code = 0x42;
|
||||
res = mad_set_aid (mad, 3, aid);
|
||||
cut_assert_equal_int (0, res, cut_message ("mad_set_aid() failed"));
|
||||
res = mad_set_aid(mad, 3, aid);
|
||||
cut_assert_equal_int(0, res, cut_message("mad_set_aid() failed"));
|
||||
|
||||
res = mad_get_aid (mad, 3, &aid);
|
||||
cut_assert_equal_int (0, res, cut_message ("mad_get_aid() failed"));
|
||||
cut_assert_equal_int (0xC0, aid.function_cluster_code, cut_message ("Invalid value"));
|
||||
cut_assert_equal_int (0x42, aid.application_code, cut_message ("Invalid value"));
|
||||
res = mad_get_aid(mad, 3, &aid);
|
||||
cut_assert_equal_int(0, res, cut_message("mad_get_aid() failed"));
|
||||
cut_assert_equal_int(0xC0, aid.function_cluster_code, cut_message("Invalid value"));
|
||||
cut_assert_equal_int(0x42, aid.application_code, cut_message("Invalid value"));
|
||||
|
||||
mad_free (mad);
|
||||
mad_free(mad);
|
||||
}
|
||||
|
||||
#define CRC_PRESET 0xc7
|
||||
|
||||
void
|
||||
test_mad_crc8_basic (void)
|
||||
test_mad_crc8_basic(void)
|
||||
{
|
||||
uint8_t crc;
|
||||
const uint8_t crc_value = 0x42;
|
||||
|
|
@ -81,14 +81,14 @@ test_mad_crc8_basic (void)
|
|||
crc = CRC_PRESET;
|
||||
nxp_crc(&crc, crc_value);
|
||||
nxp_crc(&crc, save);
|
||||
cut_assert_equal_int (0x00, crc, cut_message ("CRC should verify crc(message + crc(message)) = 0"));
|
||||
cut_assert_equal_int(0x00, crc, cut_message("CRC should verify crc(message + crc(message)) = 0"));
|
||||
}
|
||||
|
||||
/*
|
||||
* The following MAD values where extracted from documentation.
|
||||
*/
|
||||
void
|
||||
test_mad_crc8_doc_example (void)
|
||||
test_mad_crc8_doc_example(void)
|
||||
{
|
||||
/* Preset */
|
||||
uint8_t crc = CRC_PRESET;
|
||||
|
|
@ -134,14 +134,14 @@ test_mad_crc8_doc_example (void)
|
|||
|
||||
/* Append zeros of augmented message */
|
||||
|
||||
cut_assert_equal_int (0x89, crc, cut_message ("Sample CRC should match"));
|
||||
cut_assert_equal_int(0x89, crc, cut_message("Sample CRC should match"));
|
||||
}
|
||||
|
||||
/*
|
||||
* The following MAD values where extracted from a MIFARE dump.
|
||||
*/
|
||||
void
|
||||
test_mad_crc8_real_example_1 (void)
|
||||
test_mad_crc8_real_example_1(void)
|
||||
{
|
||||
/* Preset */
|
||||
uint8_t crc = CRC_PRESET;
|
||||
|
|
@ -187,14 +187,14 @@ test_mad_crc8_real_example_1 (void)
|
|||
|
||||
/* Append zeros of augmented message */
|
||||
|
||||
cut_assert_equal_int (0xc4, crc, cut_message ("Read example 1 CRC should match"));
|
||||
cut_assert_equal_int(0xc4, crc, cut_message("Read example 1 CRC should match"));
|
||||
}
|
||||
|
||||
/*
|
||||
* The following MAD values where extracted from a MIFARE dump.
|
||||
*/
|
||||
void
|
||||
test_mad_crc8_real_example_2 (void)
|
||||
test_mad_crc8_real_example_2(void)
|
||||
{
|
||||
/* Preset */
|
||||
uint8_t crc = CRC_PRESET;
|
||||
|
|
@ -240,48 +240,48 @@ test_mad_crc8_real_example_2 (void)
|
|||
|
||||
/* Append zeros of augmented message */
|
||||
|
||||
cut_assert_equal_int (0xab, crc, cut_message ("Read example 1 CRC should match"));
|
||||
cut_assert_equal_int(0xab, crc, cut_message("Read example 1 CRC should match"));
|
||||
}
|
||||
|
||||
void
|
||||
test_mad_sector_0x00_crc8 (void)
|
||||
test_mad_sector_0x00_crc8(void)
|
||||
{
|
||||
int res;
|
||||
Mad mad = mad_new (1);
|
||||
cut_assert_not_null (mad, cut_message ("mad_new() failed"));
|
||||
Mad mad = mad_new(1);
|
||||
cut_assert_not_null(mad, cut_message("mad_new() failed"));
|
||||
|
||||
res = mad_set_card_publisher_sector (mad, 0x01);
|
||||
res = mad_set_card_publisher_sector(mad, 0x01);
|
||||
|
||||
/* Block 1 */
|
||||
MadAid aid1 = { 0x01, 0x08 };
|
||||
mad_set_aid (mad, 1, aid1);
|
||||
mad_set_aid (mad, 2, aid1);
|
||||
mad_set_aid (mad, 3, aid1);
|
||||
mad_set_aid(mad, 1, aid1);
|
||||
mad_set_aid(mad, 2, aid1);
|
||||
mad_set_aid(mad, 3, aid1);
|
||||
|
||||
/* Block 2 */
|
||||
MadAid empty_aid = { 0x00, 0x00 };
|
||||
mad_set_aid (mad, 4, empty_aid);
|
||||
mad_set_aid (mad, 5, empty_aid);
|
||||
mad_set_aid (mad, 6, empty_aid);
|
||||
mad_set_aid(mad, 4, empty_aid);
|
||||
mad_set_aid(mad, 5, empty_aid);
|
||||
mad_set_aid(mad, 6, empty_aid);
|
||||
MadAid aid2 = { 0x04, 0x00 };
|
||||
mad_set_aid (mad, 7, aid2);
|
||||
mad_set_aid(mad, 7, aid2);
|
||||
|
||||
/* Block 3 */
|
||||
MadAid aid3 = { 0x03, 0x10 };
|
||||
mad_set_aid (mad, 8, aid3);
|
||||
mad_set_aid (mad, 9, aid3);
|
||||
mad_set_aid(mad, 8, aid3);
|
||||
mad_set_aid(mad, 9, aid3);
|
||||
MadAid aid4 = { 0x02, 0x10 };
|
||||
mad_set_aid (mad, 10, aid4);
|
||||
mad_set_aid (mad, 11, aid4);
|
||||
mad_set_aid(mad, 10, aid4);
|
||||
mad_set_aid(mad, 11, aid4);
|
||||
|
||||
mad_set_aid (mad, 12, empty_aid);
|
||||
mad_set_aid (mad, 13, empty_aid);
|
||||
mad_set_aid (mad, 14, empty_aid);
|
||||
mad_set_aid(mad, 12, empty_aid);
|
||||
mad_set_aid(mad, 13, empty_aid);
|
||||
mad_set_aid(mad, 14, empty_aid);
|
||||
MadAid aid5 = { 0x11, 0x30 };
|
||||
mad_set_aid (mad, 15, aid5);
|
||||
mad_set_aid(mad, 15, aid5);
|
||||
|
||||
res = sector_0x00_crc8 (mad);
|
||||
cut_assert_equal_int(0x89, res, cut_message ("Sample CRC should match"));
|
||||
res = sector_0x00_crc8(mad);
|
||||
cut_assert_equal_int(0x89, res, cut_message("Sample CRC should match"));
|
||||
|
||||
mad_free (mad);
|
||||
mad_free(mad);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/*-
|
||||
* Copyright (C) 2010, Romain Tartiere, 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
@ -19,61 +19,61 @@
|
|||
#include <freefare.h>
|
||||
|
||||
void
|
||||
test_mifare_application (void)
|
||||
test_mifare_application(void)
|
||||
{
|
||||
/* Card publisher part */
|
||||
|
||||
MadAid aid = { 0x22, 0x42 };
|
||||
Mad mad = mad_new (2);
|
||||
Mad mad = mad_new(2);
|
||||
|
||||
int i;
|
||||
|
||||
cut_assert_not_null (mad, cut_message ("mad_new() failed"));
|
||||
cut_assert_not_null(mad, cut_message("mad_new() failed"));
|
||||
|
||||
MifareClassicSectorNumber *s_alloc = mifare_application_alloc (mad, aid, 3*3*16);
|
||||
cut_assert_not_null (s_alloc, cut_message ("mifare_application_alloc() failed"));
|
||||
MifareClassicSectorNumber *s_alloc = mifare_application_alloc(mad, aid, 3 * 3 * 16);
|
||||
cut_assert_not_null(s_alloc, cut_message("mifare_application_alloc() failed"));
|
||||
|
||||
MifareClassicSectorNumber *s_found = mifare_application_find (mad, aid);
|
||||
cut_assert_not_null (s_found, cut_message ("mifare_application_alloc() failed"));
|
||||
MifareClassicSectorNumber *s_found = mifare_application_find(mad, aid);
|
||||
cut_assert_not_null(s_found, cut_message("mifare_application_alloc() failed"));
|
||||
|
||||
for (i = 0; s_alloc[i]; i++) {
|
||||
cut_assert_equal_int (s_alloc[i], s_found[i], cut_message ("Allocated and found blocks don't match at position %d", i));
|
||||
cut_assert_equal_int(s_alloc[i], s_found[i], cut_message("Allocated and found blocks don't match at position %d", i));
|
||||
}
|
||||
|
||||
cut_assert_equal_int (0, s_alloc[i], cut_message ("Invalid size"));
|
||||
cut_assert_equal_int (0, s_found[i], cut_message ("Invalid size"));
|
||||
cut_assert_equal_int(0, s_alloc[i], cut_message("Invalid size"));
|
||||
cut_assert_equal_int(0, s_found[i], cut_message("Invalid size"));
|
||||
|
||||
mifare_application_free (mad, aid);
|
||||
mifare_application_free(mad, aid);
|
||||
|
||||
free (s_alloc);
|
||||
free (s_found);
|
||||
free(s_alloc);
|
||||
free(s_found);
|
||||
|
||||
s_found = mifare_application_find (mad, aid);
|
||||
cut_assert_null (s_found, cut_message ("mifare_application_free() failed"));
|
||||
s_found = mifare_application_find(mad, aid);
|
||||
cut_assert_null(s_found, cut_message("mifare_application_free() failed"));
|
||||
|
||||
s_alloc = mifare_application_alloc (mad, aid, 15*16 + 1*16 + 1);
|
||||
cut_assert_not_null (s_alloc, cut_message ("mifare_application_alloc() failed"));
|
||||
s_alloc = mifare_application_alloc(mad, aid, 15 * 16 + 1 * 16 + 1);
|
||||
cut_assert_not_null(s_alloc, cut_message("mifare_application_alloc() failed"));
|
||||
|
||||
s_found = mifare_application_find (mad, aid);
|
||||
cut_assert_not_null (s_found, cut_message ("mifare_application_alloc() failed"));
|
||||
s_found = mifare_application_find(mad, aid);
|
||||
cut_assert_not_null(s_found, cut_message("mifare_application_alloc() failed"));
|
||||
|
||||
|
||||
|
||||
for (i = 0; s_alloc[i]; i++) {
|
||||
cut_assert_equal_int (s_alloc[i], s_found[i], cut_message ("Allocated and found blocks don't match at position %d", i));
|
||||
cut_assert_equal_int(s_alloc[i], s_found[i], cut_message("Allocated and found blocks don't match at position %d", i));
|
||||
}
|
||||
|
||||
cut_assert_equal_int (0, s_alloc[i], cut_message ("Invalid size"));
|
||||
cut_assert_equal_int (0, s_found[i], cut_message ("Invalid size"));
|
||||
cut_assert_equal_int(0, s_alloc[i], cut_message("Invalid size"));
|
||||
cut_assert_equal_int(0, s_found[i], cut_message("Invalid size"));
|
||||
|
||||
|
||||
mifare_application_free (mad, aid);
|
||||
mifare_application_free(mad, aid);
|
||||
|
||||
free (s_alloc);
|
||||
free (s_found);
|
||||
free(s_alloc);
|
||||
free(s_found);
|
||||
|
||||
s_found = mifare_application_find (mad, aid);
|
||||
cut_assert_null (s_found, cut_message ("mifare_application_free() failed"));
|
||||
s_found = mifare_application_find(mad, aid);
|
||||
cut_assert_null(s_found, cut_message("mifare_application_free() failed"));
|
||||
|
||||
mad_free (mad);
|
||||
mad_free(mad);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/*-
|
||||
* Copyright (C) 2010, Romain Tartiere, 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
@ -25,86 +25,86 @@
|
|||
#include "mifare_classic_fixture.h"
|
||||
|
||||
void
|
||||
test_mifare_classic_authenticate (void)
|
||||
test_mifare_classic_authenticate(void)
|
||||
{
|
||||
int res;
|
||||
MifareClassicKey k = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
res = mifare_classic_authenticate (tag, 0x00, k, MFC_KEY_A);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed"));
|
||||
res = mifare_classic_authenticate(tag, 0x00, k, MFC_KEY_A);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_authenticate() failed"));
|
||||
}
|
||||
|
||||
void
|
||||
test_mifare_classic_get_data_block_permission (void)
|
||||
test_mifare_classic_get_data_block_permission(void)
|
||||
{
|
||||
int res;
|
||||
|
||||
MifareClassicKey k = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
res = mifare_classic_authenticate (tag, 0x04, k, MFC_KEY_A);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed"));
|
||||
res = mifare_classic_authenticate(tag, 0x04, k, MFC_KEY_A);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_authenticate() failed"));
|
||||
|
||||
cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_R, MFC_KEY_A), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_R, MFC_KEY_B), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_W, MFC_KEY_A), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_W, MFC_KEY_B), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_D, MFC_KEY_A), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_D, MFC_KEY_B), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_I, MFC_KEY_A), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_I, MFC_KEY_B), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int(1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_R, MFC_KEY_A), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_R, MFC_KEY_B), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_W, MFC_KEY_A), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_W, MFC_KEY_B), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_D, MFC_KEY_A), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_D, MFC_KEY_B), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_I, MFC_KEY_A), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_I, MFC_KEY_B), cut_message("Wrong permission"));
|
||||
|
||||
cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_KEYA, MFC_KEY_A), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_KEYA, MFC_KEY_B), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_KEYA, MFC_KEY_A), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_KEYA, MFC_KEY_B), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_ACCESS_BITS, MFC_KEY_A), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_ACCESS_BITS, MFC_KEY_B), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_ACCESS_BITS, MFC_KEY_A), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_ACCESS_BITS, MFC_KEY_B), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_KEYB, MFC_KEY_A), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_KEYB, MFC_KEY_B), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_KEYB, MFC_KEY_A), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_KEYB, MFC_KEY_B), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int(-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_KEYA, MFC_KEY_A), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_KEYA, MFC_KEY_B), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_KEYA, MFC_KEY_A), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_KEYA, MFC_KEY_B), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_ACCESS_BITS, MFC_KEY_A), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_ACCESS_BITS, MFC_KEY_B), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_ACCESS_BITS, MFC_KEY_A), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_ACCESS_BITS, MFC_KEY_B), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_KEYB, MFC_KEY_A), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_KEYB, MFC_KEY_B), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_KEYB, MFC_KEY_A), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_KEYB, MFC_KEY_B), cut_message("Wrong permission"));
|
||||
}
|
||||
|
||||
void
|
||||
test_mifare_classic_get_trailer_permission (void)
|
||||
test_mifare_classic_get_trailer_permission(void)
|
||||
{
|
||||
int res;
|
||||
|
||||
MifareClassicKey k = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
res = mifare_classic_authenticate (tag, 0x07, k, MFC_KEY_A);
|
||||
cut_assert_equal_int (res, 0, cut_message ("mifare_classic_authenticate() failed"));
|
||||
res = mifare_classic_authenticate(tag, 0x07, k, MFC_KEY_A);
|
||||
cut_assert_equal_int(res, 0, cut_message("mifare_classic_authenticate() failed"));
|
||||
|
||||
cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_R, MFC_KEY_A), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_R, MFC_KEY_B), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_W, MFC_KEY_A), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_W, MFC_KEY_B), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_D, MFC_KEY_A), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_D, MFC_KEY_B), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_I, MFC_KEY_A), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_I, MFC_KEY_B), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int(-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_R, MFC_KEY_A), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_R, MFC_KEY_B), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_W, MFC_KEY_A), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_W, MFC_KEY_B), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_D, MFC_KEY_A), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_D, MFC_KEY_B), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_I, MFC_KEY_A), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_I, MFC_KEY_B), cut_message("Wrong permission"));
|
||||
|
||||
cut_assert_equal_int (0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_KEYA, MFC_KEY_A), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_KEYA, MFC_KEY_B), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (1, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_KEYA, MFC_KEY_A), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_KEYA, MFC_KEY_B), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (1, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_ACCESS_BITS, MFC_KEY_A), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_ACCESS_BITS, MFC_KEY_B), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (1, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_ACCESS_BITS, MFC_KEY_A), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_ACCESS_BITS, MFC_KEY_B), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (1, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_KEYB, MFC_KEY_A), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_KEYB, MFC_KEY_B), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (1, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_KEYB, MFC_KEY_A), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int (0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_KEYB, MFC_KEY_B), cut_message ("Wrong permission"));
|
||||
cut_assert_equal_int(0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_KEYA, MFC_KEY_A), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_KEYA, MFC_KEY_B), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(1, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_KEYA, MFC_KEY_A), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_KEYA, MFC_KEY_B), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(1, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_ACCESS_BITS, MFC_KEY_A), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_ACCESS_BITS, MFC_KEY_B), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(1, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_ACCESS_BITS, MFC_KEY_A), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_ACCESS_BITS, MFC_KEY_B), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(1, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_KEYB, MFC_KEY_A), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_KEYB, MFC_KEY_B), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(1, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_KEYB, MFC_KEY_A), cut_message("Wrong permission"));
|
||||
cut_assert_equal_int(0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_KEYB, MFC_KEY_B), cut_message("Wrong permission"));
|
||||
}
|
||||
|
||||
void
|
||||
test_mifare_classic_format_first_sector (void)
|
||||
test_mifare_classic_format_first_sector(void)
|
||||
{
|
||||
int res;
|
||||
|
||||
MifareClassicKey k = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
res = mifare_classic_authenticate (tag, 0x00, k, MFC_KEY_A);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed"));
|
||||
res = mifare_classic_authenticate(tag, 0x00, k, MFC_KEY_A);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_authenticate() failed"));
|
||||
|
||||
MifareClassicBlock data = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
|
|
@ -112,54 +112,54 @@ test_mifare_classic_format_first_sector (void)
|
|||
};
|
||||
|
||||
MifareClassicBlock empty;
|
||||
memset (empty, '\x00', sizeof (empty));
|
||||
memset(empty, '\x00', sizeof(empty));
|
||||
|
||||
MifareClassicBlock b0;
|
||||
res = mifare_classic_read (tag, 0x00, &b0);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_read() failed"));
|
||||
res = mifare_classic_read(tag, 0x00, &b0);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_read() failed"));
|
||||
|
||||
res = mifare_classic_write (tag, 0x00, data);
|
||||
cut_assert_equal_int (-1, res, cut_message ("mifare_classic_write() succeeded"));
|
||||
res = mifare_classic_write(tag, 0x00, data);
|
||||
cut_assert_equal_int(-1, res, cut_message("mifare_classic_write() succeeded"));
|
||||
|
||||
res = mifare_classic_disconnect (tag);
|
||||
res = mifare_classic_connect (tag);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_connect() failed"));
|
||||
res = mifare_classic_authenticate (tag, 0x00, k, MFC_KEY_A);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed"));
|
||||
res = mifare_classic_disconnect(tag);
|
||||
res = mifare_classic_connect(tag);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_connect() failed"));
|
||||
res = mifare_classic_authenticate(tag, 0x00, k, MFC_KEY_A);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_authenticate() failed"));
|
||||
|
||||
res = mifare_classic_write (tag, 0x01, data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_write() failed"));
|
||||
res = mifare_classic_write (tag, 0x02, data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_write() failed"));
|
||||
res = mifare_classic_write(tag, 0x01, data);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_write() failed"));
|
||||
res = mifare_classic_write(tag, 0x02, data);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_write() failed"));
|
||||
|
||||
res = mifare_classic_format_sector (tag, 0x00);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_format_sector() failed"));
|
||||
res = mifare_classic_format_sector(tag, 0x00);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_format_sector() failed"));
|
||||
|
||||
res = mifare_classic_read (tag, 0x00, &data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_read() failed"));
|
||||
cut_assert_equal_memory (data, sizeof (data), b0, sizeof (b0), cut_message ("Data changed in first block (block 1/3)"));
|
||||
res = mifare_classic_read(tag, 0x00, &data);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_read() failed"));
|
||||
cut_assert_equal_memory(data, sizeof(data), b0, sizeof(b0), cut_message("Data changed in first block (block 1/3)"));
|
||||
|
||||
res = mifare_classic_read (tag, 0x01, &data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_read() failed"));
|
||||
cut_assert_equal_memory (data, sizeof (data), empty, sizeof (data), cut_message ("Wrong data in formatted sector (block 2/3)"));
|
||||
res = mifare_classic_read(tag, 0x01, &data);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_read() failed"));
|
||||
cut_assert_equal_memory(data, sizeof(data), empty, sizeof(data), cut_message("Wrong data in formatted sector (block 2/3)"));
|
||||
|
||||
res = mifare_classic_read (tag, 0x02, &data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_read() failed"));
|
||||
cut_assert_equal_memory (data, sizeof (data), empty, sizeof (data), cut_message ("Wrong data in formatted sector (block 3/3)"));
|
||||
res = mifare_classic_read(tag, 0x02, &data);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_read() failed"));
|
||||
cut_assert_equal_memory(data, sizeof(data), empty, sizeof(data), cut_message("Wrong data in formatted sector (block 3/3)"));
|
||||
|
||||
res = mifare_classic_read (tag, 0x03, &data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_read() failed"));
|
||||
cut_assert_equal_memory (data, sizeof (data), "\x00\x00\x00\x00\x00\x00\xff\x07\x80\x69\xff\xff\xff\xff\xff\xff", sizeof (data), cut_message ("Wrong permissions in formatted sector"));
|
||||
res = mifare_classic_read(tag, 0x03, &data);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_read() failed"));
|
||||
cut_assert_equal_memory(data, sizeof(data), "\x00\x00\x00\x00\x00\x00\xff\x07\x80\x69\xff\xff\xff\xff\xff\xff", sizeof(data), cut_message("Wrong permissions in formatted sector"));
|
||||
}
|
||||
|
||||
void
|
||||
test_mifare_classic_format (void)
|
||||
test_mifare_classic_format(void)
|
||||
{
|
||||
int res;
|
||||
|
||||
MifareClassicKey k = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
res = mifare_classic_authenticate (tag, 0x3c, k, MFC_KEY_A);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed"));
|
||||
res = mifare_classic_authenticate(tag, 0x3c, k, MFC_KEY_A);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_authenticate() failed"));
|
||||
|
||||
MifareClassicBlock data = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
|
|
@ -167,140 +167,140 @@ test_mifare_classic_format (void)
|
|||
};
|
||||
|
||||
MifareClassicBlock empty;
|
||||
memset (empty, 0, sizeof (empty));
|
||||
memset(empty, 0, sizeof(empty));
|
||||
|
||||
res = mifare_classic_write (tag, 0x3c, data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_write() failed"));
|
||||
res = mifare_classic_write (tag, 0x3d, data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_write() failed"));
|
||||
res = mifare_classic_write (tag, 0x3e, data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_write() failed"));
|
||||
res = mifare_classic_write(tag, 0x3c, data);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_write() failed"));
|
||||
res = mifare_classic_write(tag, 0x3d, data);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_write() failed"));
|
||||
res = mifare_classic_write(tag, 0x3e, data);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_write() failed"));
|
||||
|
||||
res = mifare_classic_format_sector (tag, mifare_classic_block_sector (0x3c));
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_format_sector() failed"));
|
||||
res = mifare_classic_format_sector(tag, mifare_classic_block_sector(0x3c));
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_format_sector() failed"));
|
||||
|
||||
res = mifare_classic_read (tag, 0x3c, &data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_read() failed"));
|
||||
cut_assert_equal_memory (data, sizeof (data), empty, sizeof (data), cut_message ("Wrong data in formatted sector (block 1/3)"));
|
||||
res = mifare_classic_read(tag, 0x3c, &data);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_read() failed"));
|
||||
cut_assert_equal_memory(data, sizeof(data), empty, sizeof(data), cut_message("Wrong data in formatted sector (block 1/3)"));
|
||||
|
||||
res = mifare_classic_read (tag, 0x3d, &data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_read() failed"));
|
||||
cut_assert_equal_memory (data, sizeof (data), empty, sizeof (data), cut_message ("Wrong data in formatted sector (block 2/3)"));
|
||||
res = mifare_classic_read(tag, 0x3d, &data);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_read() failed"));
|
||||
cut_assert_equal_memory(data, sizeof(data), empty, sizeof(data), cut_message("Wrong data in formatted sector (block 2/3)"));
|
||||
|
||||
res = mifare_classic_read (tag, 0x3e, &data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_read() failed"));
|
||||
cut_assert_equal_memory (data, sizeof (data), empty, sizeof (data), cut_message ("Wrong data in formatted sector (block 3/3)"));
|
||||
res = mifare_classic_read(tag, 0x3e, &data);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_read() failed"));
|
||||
cut_assert_equal_memory(data, sizeof(data), empty, sizeof(data), cut_message("Wrong data in formatted sector (block 3/3)"));
|
||||
|
||||
res = mifare_classic_read (tag, 0x3f, &data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_read() failed"));
|
||||
cut_assert_equal_memory (data, sizeof (data), "\x00\x00\x00\x00\x00\x00\xff\x07\x80\x69\xff\xff\xff\xff\xff\xff", sizeof (data), cut_message ("Wrong permissions in formatted sector"));
|
||||
res = mifare_classic_read(tag, 0x3f, &data);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_read() failed"));
|
||||
cut_assert_equal_memory(data, sizeof(data), "\x00\x00\x00\x00\x00\x00\xff\x07\x80\x69\xff\xff\xff\xff\xff\xff", sizeof(data), cut_message("Wrong permissions in formatted sector"));
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
test_mifare_classic_value_block_increment (void)
|
||||
test_mifare_classic_value_block_increment(void)
|
||||
{
|
||||
int res;
|
||||
|
||||
MifareClassicBlockNumber block = 0x04;
|
||||
MifareClassicKey k = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
res = mifare_classic_authenticate (tag, block, k, MFC_KEY_A);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed"));
|
||||
res = mifare_classic_authenticate(tag, block, k, MFC_KEY_A);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_authenticate() failed"));
|
||||
|
||||
res = mifare_classic_init_value (tag, block, 1000, 0x00);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_init_value() failed"));
|
||||
res = mifare_classic_init_value(tag, block, 1000, 0x00);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_init_value() failed"));
|
||||
|
||||
/* Initialize value block */
|
||||
|
||||
int32_t value;
|
||||
MifareClassicBlockNumber adr;
|
||||
res = mifare_classic_read_value (tag, block, &value, &adr);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_read_value() failed"));
|
||||
cut_assert_equal_int (1000, value, cut_message ("Wrong value block value"));
|
||||
cut_assert_equal_int (0x00, adr, cut_message ("Wrong value block address"));
|
||||
res = mifare_classic_read_value(tag, block, &value, &adr);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_read_value() failed"));
|
||||
cut_assert_equal_int(1000, value, cut_message("Wrong value block value"));
|
||||
cut_assert_equal_int(0x00, adr, cut_message("Wrong value block address"));
|
||||
|
||||
/* Increment by 1 */
|
||||
|
||||
res = mifare_classic_increment (tag, block, 1);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_increment() failed"));
|
||||
res = mifare_classic_increment(tag, block, 1);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_increment() failed"));
|
||||
|
||||
res = mifare_classic_transfer (tag, block);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_transfer() failed"));
|
||||
res = mifare_classic_transfer(tag, block);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_transfer() failed"));
|
||||
|
||||
res = mifare_classic_read_value (tag, block, &value, &adr);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_read_value() failed"));
|
||||
cut_assert_equal_int (1001, value, cut_message ("Wrong value block value"));
|
||||
cut_assert_equal_int (0x00, adr, cut_message ("Wrong value block address"));
|
||||
res = mifare_classic_read_value(tag, block, &value, &adr);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_read_value() failed"));
|
||||
cut_assert_equal_int(1001, value, cut_message("Wrong value block value"));
|
||||
cut_assert_equal_int(0x00, adr, cut_message("Wrong value block address"));
|
||||
|
||||
/* Increment by 10 */
|
||||
|
||||
res = mifare_classic_increment (tag, block, 10);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_increment() failed"));
|
||||
res = mifare_classic_increment(tag, block, 10);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_increment() failed"));
|
||||
|
||||
res = mifare_classic_transfer (tag, block);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_transfer() failed"));
|
||||
res = mifare_classic_transfer(tag, block);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_transfer() failed"));
|
||||
|
||||
res = mifare_classic_read_value (tag, block, &value, &adr);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_read_value() failed"));
|
||||
cut_assert_equal_int (1011, value, cut_message ("Wrong value block value"));
|
||||
cut_assert_equal_int (0x00, adr, cut_message ("Wrong value block address"));
|
||||
res = mifare_classic_read_value(tag, block, &value, &adr);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_read_value() failed"));
|
||||
cut_assert_equal_int(1011, value, cut_message("Wrong value block value"));
|
||||
cut_assert_equal_int(0x00, adr, cut_message("Wrong value block address"));
|
||||
}
|
||||
|
||||
void
|
||||
test_mifare_classic_value_block_decrement (void)
|
||||
test_mifare_classic_value_block_decrement(void)
|
||||
{
|
||||
int res;
|
||||
|
||||
MifareClassicBlockNumber block = 0x04;
|
||||
MifareClassicKey k = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
res = mifare_classic_authenticate (tag, block, k, MFC_KEY_A);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed"));
|
||||
res = mifare_classic_init_value (tag, block, 1000, 0x00);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_init_value() failed"));
|
||||
res = mifare_classic_authenticate(tag, block, k, MFC_KEY_A);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_authenticate() failed"));
|
||||
res = mifare_classic_init_value(tag, block, 1000, 0x00);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_init_value() failed"));
|
||||
|
||||
/* Initialize value block */
|
||||
|
||||
int32_t value;
|
||||
MifareClassicBlockNumber adr;
|
||||
res = mifare_classic_read_value (tag, block, &value, &adr);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_read_value() failed"));
|
||||
cut_assert_equal_int (1000, value, cut_message ("Wrong value block value"));
|
||||
cut_assert_equal_int (0x00, adr, cut_message ("Wrong value block address"));
|
||||
res = mifare_classic_read_value(tag, block, &value, &adr);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_read_value() failed"));
|
||||
cut_assert_equal_int(1000, value, cut_message("Wrong value block value"));
|
||||
cut_assert_equal_int(0x00, adr, cut_message("Wrong value block address"));
|
||||
|
||||
/* Decrement */
|
||||
|
||||
res = mifare_classic_decrement (tag, block, 1);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_decrement() failed"));
|
||||
res = mifare_classic_decrement(tag, block, 1);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_decrement() failed"));
|
||||
|
||||
res = mifare_classic_transfer (tag, block);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_transfer() failed"));
|
||||
res = mifare_classic_transfer(tag, block);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_transfer() failed"));
|
||||
|
||||
res = mifare_classic_read_value (tag, block, &value, &adr);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_read_value() failed"));
|
||||
cut_assert_equal_int (999, value, cut_message ("Wrong value block value"));
|
||||
cut_assert_equal_int (0x00, adr, cut_message ("Wrong value block address"));
|
||||
res = mifare_classic_read_value(tag, block, &value, &adr);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_read_value() failed"));
|
||||
cut_assert_equal_int(999, value, cut_message("Wrong value block value"));
|
||||
cut_assert_equal_int(0x00, adr, cut_message("Wrong value block address"));
|
||||
|
||||
res = mifare_classic_decrement (tag, block, 1000);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_decrement() failed"));
|
||||
res = mifare_classic_decrement(tag, block, 1000);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_decrement() failed"));
|
||||
|
||||
res = mifare_classic_transfer (tag, block);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_transfer() failed"));
|
||||
res = mifare_classic_transfer(tag, block);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_transfer() failed"));
|
||||
|
||||
res = mifare_classic_read_value (tag, block, &value, &adr);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_read_value() failed"));
|
||||
cut_assert_equal_int (-1, value, cut_message ("Wrong value block value"));
|
||||
cut_assert_equal_int (0x00, adr, cut_message ("Wrong value block address"));
|
||||
res = mifare_classic_read_value(tag, block, &value, &adr);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_read_value() failed"));
|
||||
cut_assert_equal_int(-1, value, cut_message("Wrong value block value"));
|
||||
cut_assert_equal_int(0x00, adr, cut_message("Wrong value block address"));
|
||||
}
|
||||
|
||||
void
|
||||
test_mifare_classic_value_block_restore (void)
|
||||
test_mifare_classic_value_block_restore(void)
|
||||
{
|
||||
int res;
|
||||
|
||||
MifareClassicBlockNumber block = 0x04;
|
||||
MifareClassicKey k = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
res = mifare_classic_authenticate (tag, block, k, MFC_KEY_A);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed"));
|
||||
res = mifare_classic_authenticate(tag, block, k, MFC_KEY_A);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_authenticate() failed"));
|
||||
|
||||
/* Restore */
|
||||
|
||||
|
|
@ -326,49 +326,49 @@ test_mifare_classic_value_block_restore (void)
|
|||
0xff
|
||||
};
|
||||
|
||||
res = mifare_classic_write (tag, block, sample);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_write() failed"));
|
||||
res = mifare_classic_write(tag, block, sample);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_write() failed"));
|
||||
|
||||
res = mifare_classic_read (tag, block, &data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_read() failed"));
|
||||
cut_assert_equal_memory (sample, sizeof (sample), data, sizeof (data), cut_message ("Wrong value block contents"));
|
||||
res = mifare_classic_read(tag, block, &data);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_read() failed"));
|
||||
cut_assert_equal_memory(sample, sizeof(sample), data, sizeof(data), cut_message("Wrong value block contents"));
|
||||
|
||||
res = mifare_classic_write (tag, block+1, nul);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_write() failed"));
|
||||
res = mifare_classic_write(tag, block + 1, nul);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_write() failed"));
|
||||
|
||||
res = mifare_classic_read (tag, block+1, &data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_read() failed"));
|
||||
cut_assert_equal_memory (nul, sizeof (sample), data, sizeof (data), cut_message ("Wrong value block contents"));
|
||||
res = mifare_classic_read(tag, block + 1, &data);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_read() failed"));
|
||||
cut_assert_equal_memory(nul, sizeof(sample), data, sizeof(data), cut_message("Wrong value block contents"));
|
||||
|
||||
res = mifare_classic_restore (tag, block);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_restore() failed"));
|
||||
res = mifare_classic_restore(tag, block);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_restore() failed"));
|
||||
|
||||
res = mifare_classic_transfer (tag, block+1);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_transfer() failed"));
|
||||
res = mifare_classic_transfer(tag, block + 1);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_transfer() failed"));
|
||||
|
||||
res = mifare_classic_read (tag, block+1, &data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_read() failed"));
|
||||
cut_assert_equal_memory (sample, sizeof (sample), data, sizeof (data), cut_message ("Wrong value block contents"));
|
||||
res = mifare_classic_read(tag, block + 1, &data);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_read() failed"));
|
||||
cut_assert_equal_memory(sample, sizeof(sample), data, sizeof(data), cut_message("Wrong value block contents"));
|
||||
}
|
||||
|
||||
void
|
||||
test_mifare_classic_get_uid (void)
|
||||
test_mifare_classic_get_uid(void)
|
||||
{
|
||||
char *uid;
|
||||
|
||||
uid = freefare_get_tag_uid (tag);
|
||||
uid = freefare_get_tag_uid(tag);
|
||||
|
||||
cut_assert_not_null (uid, cut_message ("freefare_get_tag_uid() failed"));
|
||||
cut_assert (((strlen (uid) == 8)||(strlen (uid) == 14)), cut_message ("Wrong UID length"));
|
||||
cut_assert_not_null(uid, cut_message("freefare_get_tag_uid() failed"));
|
||||
cut_assert(((strlen(uid) == 8) || (strlen(uid) == 14)), cut_message("Wrong UID length"));
|
||||
|
||||
free (uid);
|
||||
free(uid);
|
||||
}
|
||||
|
||||
void
|
||||
test_mifare_classic_get_tag_friendly_name (void)
|
||||
test_mifare_classic_get_tag_friendly_name(void)
|
||||
{
|
||||
const char *name = freefare_get_tag_friendly_name (tag);
|
||||
const char *name = freefare_get_tag_friendly_name(tag);
|
||||
|
||||
cut_assert_not_null (name, cut_message ("freefare_get_tag_friendly_name() failed"));
|
||||
cut_assert_not_null(name, cut_message("freefare_get_tag_friendly_name() failed"));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/*-
|
||||
* Copyright (C) 2010, Romain Tartiere, 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
@ -20,15 +20,15 @@
|
|||
#include <freefare.h>
|
||||
|
||||
void
|
||||
test_mifare_classic_create_trailer_block (void)
|
||||
test_mifare_classic_create_trailer_block(void)
|
||||
{
|
||||
MifareClassicBlock data;
|
||||
|
||||
MifareClassicKey key_a = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
MifareClassicKey key_b = { 0xde, 0xad, 0xbe, 0xef, 0xff, 0xff };
|
||||
|
||||
mifare_classic_trailer_block (&data, key_a, 0, 0, 0, 4, 0x42, key_b);
|
||||
mifare_classic_trailer_block(&data, key_a, 0, 0, 0, 4, 0x42, key_b);
|
||||
|
||||
cut_assert_equal_memory (data, sizeof (data), "\xff\xff\xff\xff\xff\xff\xff\x07\x80\x42\xde\xad\xbe\xef\xff\xff", sizeof (data), cut_message ("Wrong generated block"));
|
||||
cut_assert_equal_memory(data, sizeof(data), "\xff\xff\xff\xff\xff\xff\xff\x07\x80\x42\xde\xad\xbe\xef\xff\xff", sizeof(data), cut_message("Wrong generated block"));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/*-
|
||||
* Copyright (C) 2010, Romain Tartiere.
|
||||
*
|
||||
*
|
||||
* 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
@ -22,11 +22,11 @@
|
|||
#include "mifare_classic_fixture.h"
|
||||
|
||||
void
|
||||
test_mifare_classic_mad (void)
|
||||
test_mifare_classic_mad(void)
|
||||
{
|
||||
MifareClassicKey key_a_transport = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
MifareClassicKey key_b_sector_00 = { 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
|
||||
MifareClassicKey key_b_sector_10 = { 0x1a, 0x98, 0x2c, 0x7e, 0x45 ,0x9a };
|
||||
MifareClassicKey key_b_sector_10 = { 0x1a, 0x98, 0x2c, 0x7e, 0x45, 0x9a };
|
||||
MifareClassicBlock tb;
|
||||
Mad mad;
|
||||
int res;
|
||||
|
|
@ -37,21 +37,21 @@ test_mifare_classic_mad (void)
|
|||
* |_| |_/_/ \_\___/ \_/|_|
|
||||
*/
|
||||
|
||||
mad = mad_new (1);
|
||||
cut_assert_not_null (mad, cut_message ("mad_new() failed"));
|
||||
mad = mad_new(1);
|
||||
cut_assert_not_null(mad, cut_message("mad_new() failed"));
|
||||
|
||||
// Prepare sector 0x00 for writing a MAD.
|
||||
res = mifare_classic_authenticate (tag, 0x00, key_a_transport, MFC_KEY_A);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed"));
|
||||
res = mifare_classic_authenticate(tag, 0x00, key_a_transport, MFC_KEY_A);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_authenticate() failed"));
|
||||
|
||||
mifare_classic_trailer_block (&tb, key_a_transport, 00, 00, 00, 06, 0x00, key_b_sector_00);
|
||||
mifare_classic_trailer_block(&tb, key_a_transport, 00, 00, 00, 06, 0x00, key_b_sector_00);
|
||||
|
||||
res = mifare_classic_write (tag, 0x03, tb);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_write() failed"));
|
||||
res = mifare_classic_write(tag, 0x03, tb);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_write() failed"));
|
||||
|
||||
// Write the empty MAD
|
||||
res = mad_write (tag, mad, key_b_sector_00, NULL);
|
||||
cut_assert_equal_int (0, res, cut_message ("mad_write() failed"));
|
||||
res = mad_write(tag, mad, key_b_sector_00, NULL);
|
||||
cut_assert_equal_int(0, res, cut_message("mad_write() failed"));
|
||||
|
||||
|
||||
// Check the empty MAD
|
||||
|
|
@ -65,27 +65,27 @@ test_mifare_classic_mad (void)
|
|||
};
|
||||
MifareClassicBlock data;
|
||||
|
||||
res = mifare_classic_authenticate (tag, 0x01, mad_public_key_a, MFC_KEY_A);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed"));
|
||||
res = mifare_classic_authenticate(tag, 0x01, mad_public_key_a, MFC_KEY_A);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_authenticate() failed"));
|
||||
|
||||
res = mifare_classic_read (tag, 0x01, &data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mad_read() failed"));
|
||||
cut_assert_equal_memory (ref_01, sizeof (ref_01), data, sizeof (data), cut_message ("Wrong data"));
|
||||
res = mifare_classic_read(tag, 0x01, &data);
|
||||
cut_assert_equal_int(0, res, cut_message("mad_read() failed"));
|
||||
cut_assert_equal_memory(ref_01, sizeof(ref_01), data, sizeof(data), cut_message("Wrong data"));
|
||||
|
||||
res = mifare_classic_read (tag, 0x02, &data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mad_read() failed"));
|
||||
cut_assert_equal_memory (ref_02, sizeof (ref_02), data, sizeof (data), cut_message ("Wrong data"));
|
||||
res = mifare_classic_read(tag, 0x02, &data);
|
||||
cut_assert_equal_int(0, res, cut_message("mad_read() failed"));
|
||||
cut_assert_equal_memory(ref_02, sizeof(ref_02), data, sizeof(data), cut_message("Wrong data"));
|
||||
|
||||
Mad mad2 = mad_read (tag);
|
||||
cut_assert_not_null (mad2, cut_message ("mad_read() failed"));
|
||||
cut_assert_equal_memory (mad, sizeof (mad), mad2, sizeof (mad2), cut_message ("Wrong MAD"));
|
||||
Mad mad2 = mad_read(tag);
|
||||
cut_assert_not_null(mad2, cut_message("mad_read() failed"));
|
||||
cut_assert_equal_memory(mad, sizeof(mad), mad2, sizeof(mad2), cut_message("Wrong MAD"));
|
||||
|
||||
const char application_data[] = "APPLICATION DATA >> APPLICATION DATA >> APPLICATION DATA >> " \
|
||||
"APPLICATION DATA >> APPLICATION DATA >> APPLICATION DATA >> " \
|
||||
"APPLICATION DATA >> APPLICATION DATA >> APPLICATION DATA >> " \
|
||||
"APPLICATION DATA >> APPLICATION DATA >> APPLICATION DATA >> " \
|
||||
"APPLICATION DATA >> APPLICATION DATA >> APPLICATION DATA >> " \
|
||||
"APPLICATION DATA >> APPLICATION DATA >> APPLICATION DATA >> ";
|
||||
"APPLICATION DATA >> APPLICATION DATA >> APPLICATION DATA >> " \
|
||||
"APPLICATION DATA >> APPLICATION DATA >> APPLICATION DATA >> " \
|
||||
"APPLICATION DATA >> APPLICATION DATA >> APPLICATION DATA >> " \
|
||||
"APPLICATION DATA >> APPLICATION DATA >> APPLICATION DATA >> " \
|
||||
"APPLICATION DATA >> APPLICATION DATA >> APPLICATION DATA >> ";
|
||||
|
||||
MadAid aid = {
|
||||
.function_cluster_code = 0x01,
|
||||
|
|
@ -93,78 +93,78 @@ test_mifare_classic_mad (void)
|
|||
};
|
||||
|
||||
// Write some data in the application
|
||||
MifareClassicSectorNumber *sectors = mifare_application_alloc (mad, aid, sizeof (application_data));
|
||||
cut_assert_not_null (sectors, cut_message ("mifare_application_alloc() failed"));
|
||||
free (sectors);
|
||||
MifareClassicSectorNumber *sectors = mifare_application_alloc(mad, aid, sizeof(application_data));
|
||||
cut_assert_not_null(sectors, cut_message("mifare_application_alloc() failed"));
|
||||
free(sectors);
|
||||
|
||||
res = mad_write (tag, mad, key_b_sector_00, NULL);
|
||||
cut_assert_equal_int (0, res, cut_message ("mad_write() failed"));
|
||||
res = mad_write(tag, mad, key_b_sector_00, NULL);
|
||||
cut_assert_equal_int(0, res, cut_message("mad_write() failed"));
|
||||
|
||||
ssize_t s = mifare_application_write (tag, mad, aid, &application_data, sizeof (application_data), key_a_transport, MFC_KEY_A);
|
||||
cut_assert_equal_int (sizeof (application_data), s, cut_message ("mifare_application_write() failed"));
|
||||
ssize_t s = mifare_application_write(tag, mad, aid, &application_data, sizeof(application_data), key_a_transport, MFC_KEY_A);
|
||||
cut_assert_equal_int(sizeof(application_data), s, cut_message("mifare_application_write() failed"));
|
||||
|
||||
char read_buf[500];
|
||||
|
||||
// Read it again
|
||||
s = mifare_application_read (tag, mad, aid, read_buf, sizeof (application_data), key_a_transport, MFC_KEY_A);
|
||||
cut_assert_equal_int (sizeof (application_data), s, cut_message ("mifare_application_read() failed"));
|
||||
cut_assert_equal_memory (application_data, sizeof (application_data), read_buf, s, cut_message ("Wrong application data"));
|
||||
s = mifare_application_read(tag, mad, aid, read_buf, sizeof(application_data), key_a_transport, MFC_KEY_A);
|
||||
cut_assert_equal_int(sizeof(application_data), s, cut_message("mifare_application_read() failed"));
|
||||
cut_assert_equal_memory(application_data, sizeof(application_data), read_buf, s, cut_message("Wrong application data"));
|
||||
|
||||
mad_free (mad);
|
||||
mad_free (mad2);
|
||||
mad_free(mad);
|
||||
mad_free(mad2);
|
||||
|
||||
// Revert to the transport configuration
|
||||
res = mifare_classic_authenticate (tag, 0x00, key_b_sector_00, MFC_KEY_B);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed"));
|
||||
res = mifare_classic_format_sector (tag, 0x00);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_format_sector() failed"));
|
||||
res = mifare_classic_authenticate(tag, 0x00, key_b_sector_00, MFC_KEY_B);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_authenticate() failed"));
|
||||
res = mifare_classic_format_sector(tag, 0x00);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_format_sector() failed"));
|
||||
|
||||
/* __ __ _ ___ ___
|
||||
* | \/ | /_\ | \__ _|_ )
|
||||
* | |\/| |/ _ \| |) \ V // /
|
||||
* |_| |_/_/ \_\___/ \_//___|
|
||||
*/
|
||||
if (freefare_get_tag_type (tag) != MIFARE_CLASSIC_4K) {
|
||||
cut_omit ("MADv2 requires a MIFARE Classic 4K to be tested");
|
||||
if (freefare_get_tag_type(tag) != MIFARE_CLASSIC_4K) {
|
||||
cut_omit("MADv2 requires a MIFARE Classic 4K to be tested");
|
||||
}
|
||||
|
||||
mad = mad_new (2);
|
||||
cut_assert_not_null (mad, cut_message ("mad_new() failed"));
|
||||
mad = mad_new(2);
|
||||
cut_assert_not_null(mad, cut_message("mad_new() failed"));
|
||||
|
||||
// Prepare sector 0x00 for writing a MAD.
|
||||
res = mifare_classic_authenticate (tag, 0x00, key_a_transport, MFC_KEY_A);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed"));
|
||||
res = mifare_classic_authenticate(tag, 0x00, key_a_transport, MFC_KEY_A);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_authenticate() failed"));
|
||||
|
||||
mifare_classic_trailer_block (&tb, key_a_transport, 00, 00, 00, 06, 0x00, key_b_sector_00);
|
||||
mifare_classic_trailer_block(&tb, key_a_transport, 00, 00, 00, 06, 0x00, key_b_sector_00);
|
||||
|
||||
res = mifare_classic_write (tag, 0x03, tb);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_write() failed"));
|
||||
res = mifare_classic_write(tag, 0x03, tb);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_write() failed"));
|
||||
|
||||
// Prepare sector 0x10 for writing a MAD.
|
||||
res = mifare_classic_authenticate (tag, 0x40, key_a_transport, MFC_KEY_A);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed"));
|
||||
res = mifare_classic_authenticate(tag, 0x40, key_a_transport, MFC_KEY_A);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_authenticate() failed"));
|
||||
|
||||
mifare_classic_trailer_block (&tb, key_a_transport, 00, 00, 00, 06, 0x00, key_b_sector_10);
|
||||
mifare_classic_trailer_block(&tb, key_a_transport, 00, 00, 00, 06, 0x00, key_b_sector_10);
|
||||
|
||||
res = mifare_classic_write (tag, 0x43, tb);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_write() failed"));
|
||||
res = mifare_classic_write(tag, 0x43, tb);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_write() failed"));
|
||||
|
||||
// Write the empty MAD
|
||||
res = mad_write (tag, mad, key_b_sector_00, key_b_sector_10);
|
||||
cut_assert_equal_int (0, res, cut_message ("mad_write() failed"));
|
||||
res = mad_write(tag, mad, key_b_sector_00, key_b_sector_10);
|
||||
cut_assert_equal_int(0, res, cut_message("mad_write() failed"));
|
||||
|
||||
// Check the empty MAD
|
||||
|
||||
res = mifare_classic_authenticate (tag, 0x01, mad_public_key_a, MFC_KEY_A);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed"));
|
||||
res = mifare_classic_authenticate(tag, 0x01, mad_public_key_a, MFC_KEY_A);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_authenticate() failed"));
|
||||
|
||||
res = mifare_classic_read (tag, 0x01, &data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mad_read() failed"));
|
||||
cut_assert_equal_memory (ref_01, sizeof (ref_01), data, sizeof (data), cut_message ("Wrong data"));
|
||||
res = mifare_classic_read(tag, 0x01, &data);
|
||||
cut_assert_equal_int(0, res, cut_message("mad_read() failed"));
|
||||
cut_assert_equal_memory(ref_01, sizeof(ref_01), data, sizeof(data), cut_message("Wrong data"));
|
||||
|
||||
res = mifare_classic_read (tag, 0x02, &data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mad_read() failed"));
|
||||
cut_assert_equal_memory (ref_02, sizeof (ref_02), data, sizeof (data), cut_message ("Wrong data"));
|
||||
res = mifare_classic_read(tag, 0x02, &data);
|
||||
cut_assert_equal_int(0, res, cut_message("mad_read() failed"));
|
||||
cut_assert_equal_memory(ref_02, sizeof(ref_02), data, sizeof(data), cut_message("Wrong data"));
|
||||
|
||||
MifareClassicBlock ref_40 = {
|
||||
0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
|
@ -179,54 +179,54 @@ test_mifare_classic_mad (void)
|
|||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
res = mifare_classic_authenticate (tag, 0x40, mad_public_key_a, MFC_KEY_A);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed"));
|
||||
res = mifare_classic_authenticate(tag, 0x40, mad_public_key_a, MFC_KEY_A);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_authenticate() failed"));
|
||||
|
||||
res = mifare_classic_read (tag, 0x40, &data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mad_read() failed"));
|
||||
cut_assert_equal_memory (ref_40, sizeof (ref_01), data, sizeof (data), cut_message ("Wrong data"));
|
||||
res = mifare_classic_read(tag, 0x40, &data);
|
||||
cut_assert_equal_int(0, res, cut_message("mad_read() failed"));
|
||||
cut_assert_equal_memory(ref_40, sizeof(ref_01), data, sizeof(data), cut_message("Wrong data"));
|
||||
|
||||
res = mifare_classic_read (tag, 0x41, &data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mad_read() failed"));
|
||||
cut_assert_equal_memory (ref_41, sizeof (ref_02), data, sizeof (data), cut_message ("Wrong data"));
|
||||
res = mifare_classic_read(tag, 0x41, &data);
|
||||
cut_assert_equal_int(0, res, cut_message("mad_read() failed"));
|
||||
cut_assert_equal_memory(ref_41, sizeof(ref_02), data, sizeof(data), cut_message("Wrong data"));
|
||||
|
||||
res = mifare_classic_read (tag, 0x42, &data);
|
||||
cut_assert_equal_int (0, res, cut_message ("mad_read() failed"));
|
||||
cut_assert_equal_memory (ref_42, sizeof (ref_02), data, sizeof (data), cut_message ("Wrong data"));
|
||||
res = mifare_classic_read(tag, 0x42, &data);
|
||||
cut_assert_equal_int(0, res, cut_message("mad_read() failed"));
|
||||
cut_assert_equal_memory(ref_42, sizeof(ref_02), data, sizeof(data), cut_message("Wrong data"));
|
||||
|
||||
|
||||
mad2 = mad_read (tag);
|
||||
cut_assert_not_null (mad2, cut_message ("mad_read() failed"));
|
||||
cut_assert_equal_memory (mad, sizeof (mad), mad2, sizeof (mad2), cut_message ("Wrong MAD"));
|
||||
mad2 = mad_read(tag);
|
||||
cut_assert_not_null(mad2, cut_message("mad_read() failed"));
|
||||
cut_assert_equal_memory(mad, sizeof(mad), mad2, sizeof(mad2), cut_message("Wrong MAD"));
|
||||
|
||||
// Write some data in the application
|
||||
sectors = mifare_application_alloc (mad, aid, sizeof (application_data));
|
||||
cut_assert_not_null (sectors, cut_message ("mifare_application_alloc() failed"));
|
||||
free (sectors);
|
||||
sectors = mifare_application_alloc(mad, aid, sizeof(application_data));
|
||||
cut_assert_not_null(sectors, cut_message("mifare_application_alloc() failed"));
|
||||
free(sectors);
|
||||
|
||||
res = mad_write (tag, mad, key_b_sector_00, key_b_sector_10);
|
||||
cut_assert_equal_int (0, res, cut_message ("mad_write() failed"));
|
||||
res = mad_write(tag, mad, key_b_sector_00, key_b_sector_10);
|
||||
cut_assert_equal_int(0, res, cut_message("mad_write() failed"));
|
||||
|
||||
s = mifare_application_write (tag, mad, aid, &application_data, sizeof (application_data), key_a_transport, MFC_KEY_A);
|
||||
cut_assert_equal_int (sizeof (application_data), s, cut_message ("mifare_application_write() failed"));
|
||||
s = mifare_application_write(tag, mad, aid, &application_data, sizeof(application_data), key_a_transport, MFC_KEY_A);
|
||||
cut_assert_equal_int(sizeof(application_data), s, cut_message("mifare_application_write() failed"));
|
||||
|
||||
// Read it again
|
||||
s = mifare_application_read (tag, mad, aid, read_buf, sizeof (application_data), key_a_transport, MFC_KEY_A);
|
||||
cut_assert_equal_int (sizeof (application_data), s, cut_message ("mifare_application_read() failed"));
|
||||
cut_assert_equal_memory (application_data, sizeof (application_data), read_buf, s, cut_message ("Wrong application data"));
|
||||
s = mifare_application_read(tag, mad, aid, read_buf, sizeof(application_data), key_a_transport, MFC_KEY_A);
|
||||
cut_assert_equal_int(sizeof(application_data), s, cut_message("mifare_application_read() failed"));
|
||||
cut_assert_equal_memory(application_data, sizeof(application_data), read_buf, s, cut_message("Wrong application data"));
|
||||
|
||||
mad_free (mad);
|
||||
mad_free (mad2);
|
||||
mad_free(mad);
|
||||
mad_free(mad2);
|
||||
|
||||
// Revert to the transport configuration
|
||||
res = mifare_classic_authenticate (tag, 0x00, key_b_sector_00, MFC_KEY_B);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed"));
|
||||
res = mifare_classic_format_sector (tag, 0x00);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_format_sector() failed"));
|
||||
res = mifare_classic_authenticate(tag, 0x00, key_b_sector_00, MFC_KEY_B);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_authenticate() failed"));
|
||||
res = mifare_classic_format_sector(tag, 0x00);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_format_sector() failed"));
|
||||
|
||||
res = mifare_classic_authenticate (tag, 0x40, key_b_sector_10, MFC_KEY_B);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed"));
|
||||
res = mifare_classic_format_sector (tag, 0x10);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_format_sector() failed"));
|
||||
res = mifare_classic_authenticate(tag, 0x40, key_b_sector_10, MFC_KEY_B);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_authenticate() failed"));
|
||||
res = mifare_classic_format_sector(tag, 0x10);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_classic_format_sector() failed"));
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/*-
|
||||
* Copyright (C) 2010, Romain Tartiere, 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
@ -21,19 +21,19 @@
|
|||
#include "freefare_internal.h"
|
||||
|
||||
void
|
||||
test_mifare_classic_sector_boundaries (void)
|
||||
test_mifare_classic_sector_boundaries(void)
|
||||
{
|
||||
for (int i=0; i < 32; i++) {
|
||||
for (int j=0; j < 4; j++) {
|
||||
cut_assert_equal_int (4 * i, mifare_classic_sector_first_block (mifare_classic_block_sector (4 * i)), cut_message ("Wrong first block number for block %d", i));
|
||||
cut_assert_equal_int (4 * i + 3, mifare_classic_sector_last_block (mifare_classic_block_sector (4 * i + j)), cut_message ("Wrong last block number for block %d", i));
|
||||
for (int i = 0; i < 32; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
cut_assert_equal_int(4 * i, mifare_classic_sector_first_block(mifare_classic_block_sector(4 * i)), cut_message("Wrong first block number for block %d", i));
|
||||
cut_assert_equal_int(4 * i + 3, mifare_classic_sector_last_block(mifare_classic_block_sector(4 * i + j)), cut_message("Wrong last block number for block %d", i));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0; i < 8; i++) {
|
||||
for (int j=0; j < 16; j++) {
|
||||
cut_assert_equal_int (128 + 16 * i, mifare_classic_sector_first_block (mifare_classic_block_sector (128 + 16 * i)), cut_message ("Wrong last block number for block %d", i));
|
||||
cut_assert_equal_int (128 + 16 * i + 15, mifare_classic_sector_last_block (mifare_classic_block_sector (128 + 16 * i + j)), cut_message ("Wrong last block number for block %d", i));
|
||||
for (int i = 0; i < 8; i++) {
|
||||
for (int j = 0; j < 16; j++) {
|
||||
cut_assert_equal_int(128 + 16 * i, mifare_classic_sector_first_block(mifare_classic_block_sector(128 + 16 * i)), cut_message("Wrong last block number for block %d", i));
|
||||
cut_assert_equal_int(128 + 16 * i + 15, mifare_classic_sector_last_block(mifare_classic_block_sector(128 + 16 * i + j)), cut_message("Wrong last block number for block %d", i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,11 +1,11 @@
|
|||
/*-
|
||||
* Copyright (C) 2010, Romain Tartiere, 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
@ -38,7 +38,7 @@ uint8_t key_data[] = {
|
|||
|
||||
|
||||
void
|
||||
test_mifare_desfire_aes_generate_subkeys (void)
|
||||
test_mifare_desfire_aes_generate_subkeys(void)
|
||||
{
|
||||
uint8_t sk1[] = {
|
||||
0xfb, 0xee, 0xd6, 0x18,
|
||||
|
|
@ -54,23 +54,23 @@ test_mifare_desfire_aes_generate_subkeys (void)
|
|||
0xe4, 0x6d, 0x51, 0x3b
|
||||
};
|
||||
|
||||
MifareDESFireKey key = mifare_desfire_aes_key_new (key_data);
|
||||
cmac_generate_subkeys (key);
|
||||
MifareDESFireKey key = mifare_desfire_aes_key_new(key_data);
|
||||
cmac_generate_subkeys(key);
|
||||
|
||||
cut_assert_equal_memory (sk1, 16, key->cmac_sk1, 16, cut_message ("Wrong sub-key 1"));
|
||||
cut_assert_equal_memory (sk2, 16, key->cmac_sk2, 16, cut_message ("Wrong sub-key 2"));
|
||||
cut_assert_equal_memory(sk1, 16, key->cmac_sk1, 16, cut_message("Wrong sub-key 1"));
|
||||
cut_assert_equal_memory(sk2, 16, key->cmac_sk2, 16, cut_message("Wrong sub-key 2"));
|
||||
|
||||
mifare_desfire_key_free (key);
|
||||
mifare_desfire_key_free(key);
|
||||
}
|
||||
|
||||
void
|
||||
test_mifare_desfire_aes_cmac_empty (void)
|
||||
test_mifare_desfire_aes_cmac_empty(void)
|
||||
{
|
||||
MifareDESFireKey key = mifare_desfire_aes_key_new (key_data);
|
||||
cmac_generate_subkeys (key);
|
||||
MifareDESFireKey key = mifare_desfire_aes_key_new(key_data);
|
||||
cmac_generate_subkeys(key);
|
||||
|
||||
uint8_t ivect[16];
|
||||
memset (ivect, 0, sizeof (ivect));
|
||||
memset(ivect, 0, sizeof(ivect));
|
||||
|
||||
uint8_t expected_cmac[] = {
|
||||
0xbb, 0x1d, 0x69, 0x29,
|
||||
|
|
@ -80,21 +80,21 @@ test_mifare_desfire_aes_cmac_empty (void)
|
|||
};
|
||||
|
||||
uint8_t my_cmac[16];
|
||||
cmac (key, ivect, NULL, 0, my_cmac);
|
||||
cmac(key, ivect, NULL, 0, my_cmac);
|
||||
|
||||
cut_assert_equal_memory (expected_cmac, 16, my_cmac, 16, cut_message ("Wrong CMAC"));
|
||||
cut_assert_equal_memory(expected_cmac, 16, my_cmac, 16, cut_message("Wrong CMAC"));
|
||||
|
||||
mifare_desfire_key_free (key);
|
||||
mifare_desfire_key_free(key);
|
||||
}
|
||||
|
||||
void
|
||||
test_mifare_desfire_aes_cmac_128 (void)
|
||||
test_mifare_desfire_aes_cmac_128(void)
|
||||
{
|
||||
MifareDESFireKey key = mifare_desfire_aes_key_new (key_data);
|
||||
cmac_generate_subkeys (key);
|
||||
MifareDESFireKey key = mifare_desfire_aes_key_new(key_data);
|
||||
cmac_generate_subkeys(key);
|
||||
|
||||
uint8_t ivect[16];
|
||||
memset (ivect, 0, sizeof (ivect));
|
||||
memset(ivect, 0, sizeof(ivect));
|
||||
|
||||
uint8_t message[] = {
|
||||
0x6b, 0xc1, 0xbe, 0xe2,
|
||||
|
|
@ -111,21 +111,21 @@ test_mifare_desfire_aes_cmac_128 (void)
|
|||
};
|
||||
|
||||
uint8_t my_cmac[16];
|
||||
cmac (key, ivect, message, 16, my_cmac);
|
||||
cmac(key, ivect, message, 16, my_cmac);
|
||||
|
||||
cut_assert_equal_memory (expected_cmac, 16, my_cmac, sizeof (message), cut_message ("Wrong CMAC"));
|
||||
cut_assert_equal_memory(expected_cmac, 16, my_cmac, sizeof(message), cut_message("Wrong CMAC"));
|
||||
|
||||
mifare_desfire_key_free (key);
|
||||
mifare_desfire_key_free(key);
|
||||
}
|
||||
|
||||
void
|
||||
test_mifare_desfire_aes_cmac_320 (void)
|
||||
test_mifare_desfire_aes_cmac_320(void)
|
||||
{
|
||||
MifareDESFireKey key = mifare_desfire_aes_key_new (key_data);
|
||||
cmac_generate_subkeys (key);
|
||||
MifareDESFireKey key = mifare_desfire_aes_key_new(key_data);
|
||||
cmac_generate_subkeys(key);
|
||||
|
||||
uint8_t ivect[16];
|
||||
memset (ivect, 0, sizeof (ivect));
|
||||
memset(ivect, 0, sizeof(ivect));
|
||||
|
||||
uint8_t message[] = {
|
||||
0x6b, 0xc1, 0xbe, 0xe2,
|
||||
|
|
@ -148,21 +148,21 @@ test_mifare_desfire_aes_cmac_320 (void)
|
|||
};
|
||||
|
||||
uint8_t my_cmac[16];
|
||||
cmac (key, ivect, message, sizeof (message), my_cmac);
|
||||
cmac(key, ivect, message, sizeof(message), my_cmac);
|
||||
|
||||
cut_assert_equal_memory (expected_cmac, 16, my_cmac, 16, cut_message ("Wrong CMAC"));
|
||||
cut_assert_equal_memory(expected_cmac, 16, my_cmac, 16, cut_message("Wrong CMAC"));
|
||||
|
||||
mifare_desfire_key_free (key);
|
||||
mifare_desfire_key_free(key);
|
||||
}
|
||||
|
||||
void
|
||||
test_mifare_desfire_aes_cmac_512 (void)
|
||||
test_mifare_desfire_aes_cmac_512(void)
|
||||
{
|
||||
MifareDESFireKey key = mifare_desfire_aes_key_new (key_data);
|
||||
cmac_generate_subkeys (key);
|
||||
MifareDESFireKey key = mifare_desfire_aes_key_new(key_data);
|
||||
cmac_generate_subkeys(key);
|
||||
|
||||
uint8_t ivect[16];
|
||||
memset (ivect, 0, sizeof (ivect));
|
||||
memset(ivect, 0, sizeof(ivect));
|
||||
|
||||
uint8_t message[] = {
|
||||
0x6b, 0xc1, 0xbe, 0xe2,
|
||||
|
|
@ -191,9 +191,9 @@ test_mifare_desfire_aes_cmac_512 (void)
|
|||
};
|
||||
|
||||
uint8_t my_cmac[16];
|
||||
cmac (key, ivect, message, sizeof (message), my_cmac);
|
||||
cmac(key, ivect, message, sizeof(message), my_cmac);
|
||||
|
||||
cut_assert_equal_memory (expected_cmac, 16, my_cmac, 16, cut_message ("Wrong CMAC"));
|
||||
cut_assert_equal_memory(expected_cmac, 16, my_cmac, 16, cut_message("Wrong CMAC"));
|
||||
|
||||
mifare_desfire_key_free (key);
|
||||
mifare_desfire_key_free(key);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/*-
|
||||
* Copyright (C) 2010, Romain Tartiere, 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
#include "freefare_internal.h"
|
||||
|
||||
void
|
||||
test_mifare_desfire_aid (void)
|
||||
test_mifare_desfire_aid(void)
|
||||
{
|
||||
/*
|
||||
* <-- LSB MSB -->
|
||||
|
|
@ -33,17 +33,17 @@ test_mifare_desfire_aid (void)
|
|||
*
|
||||
* 0xF21438 -> 0x83412F
|
||||
*/
|
||||
MifareDESFireAID desfire_aid = mifare_desfire_aid_new (0x00f12ab8);
|
||||
MifareDESFireAID desfire_aid = mifare_desfire_aid_new(0x00f12ab8);
|
||||
MadAid mad_aid = {
|
||||
.function_cluster_code = 0x12,
|
||||
.application_code = 0xab,
|
||||
};
|
||||
MifareDESFireAID desfire_aid2 = mifare_desfire_aid_new_with_mad_aid (mad_aid, 8);
|
||||
MifareDESFireAID desfire_aid2 = mifare_desfire_aid_new_with_mad_aid(mad_aid, 8);
|
||||
|
||||
cut_assert_equal_memory (desfire_aid->data,3, desfire_aid2->data, 3, cut_message ("wrong aid"));
|
||||
cut_assert_equal_memory(desfire_aid->data, 3, desfire_aid2->data, 3, cut_message("wrong aid"));
|
||||
|
||||
cut_assert_equal_int (mifare_desfire_aid_get_aid (desfire_aid), 0x00f12ab8, cut_message ("wrong aid"));
|
||||
cut_assert_equal_int(mifare_desfire_aid_get_aid(desfire_aid), 0x00f12ab8, cut_message("wrong aid"));
|
||||
|
||||
free (desfire_aid);
|
||||
free (desfire_aid2);
|
||||
free(desfire_aid);
|
||||
free(desfire_aid2);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/*-
|
||||
* Copyright (C) 2010, Romain Tartiere.
|
||||
*
|
||||
*
|
||||
* 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
@ -20,73 +20,73 @@
|
|||
#include "freefare_internal.h"
|
||||
|
||||
void
|
||||
test_mifare_rol (void)
|
||||
test_mifare_rol(void)
|
||||
{
|
||||
uint8_t data[8] = "01234567";
|
||||
rol (data, 8);
|
||||
cut_assert_equal_memory ("12345670", 8, data, 8, cut_message ("Wrong data"));
|
||||
rol(data, 8);
|
||||
cut_assert_equal_memory("12345670", 8, data, 8, cut_message("Wrong data"));
|
||||
|
||||
uint8_t data2[16] = "0123456789abcdef";
|
||||
rol (data2, 16);
|
||||
cut_assert_equal_memory (data2, 16, "123456789abcdef0", 16, cut_message ("Wrong data"));
|
||||
rol(data2, 16);
|
||||
cut_assert_equal_memory(data2, 16, "123456789abcdef0", 16, cut_message("Wrong data"));
|
||||
}
|
||||
|
||||
void
|
||||
test_mifare_desfire_des_receive (void)
|
||||
test_mifare_desfire_des_receive(void)
|
||||
{
|
||||
uint8_t null_ivect[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
uint8_t data[8] = { 0xd6, 0x59, 0xe1, 0x70, 0x43, 0xa8, 0x40, 0x68 };
|
||||
uint8_t key_data[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
|
||||
MifareDESFireKey key = mifare_desfire_des_key_new_with_version (key_data);
|
||||
MifareDESFireKey key = mifare_desfire_des_key_new_with_version(key_data);
|
||||
|
||||
uint8_t expected_data[8] = { 0x73, 0x0d, 0xdf, 0xad, 0xa4, 0xd2, 0x07, 0x89 };
|
||||
uint8_t expected_key[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
|
||||
|
||||
mifare_cypher_blocks_chained (NULL, key, null_ivect, data, 8, MCD_RECEIVE, MCO_DECYPHER);
|
||||
mifare_cypher_blocks_chained(NULL, key, null_ivect, data, 8, MCD_RECEIVE, MCO_DECYPHER);
|
||||
|
||||
cut_assert_equal_memory (&expected_data, 8, &data, 8, cut_message ("Wrong data"));
|
||||
cut_assert_equal_memory (&expected_key, 8, key->data, 8, cut_message ("Wrong key"));
|
||||
cut_assert_equal_memory(&expected_data, 8, &data, 8, cut_message("Wrong data"));
|
||||
cut_assert_equal_memory(&expected_key, 8, key->data, 8, cut_message("Wrong key"));
|
||||
|
||||
mifare_desfire_key_free (key);
|
||||
mifare_desfire_key_free(key);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
test_mifare_desfire_des_send (void)
|
||||
test_mifare_desfire_des_send(void)
|
||||
{
|
||||
uint8_t null_ivect[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
uint8_t data[8] = { 0x73, 0x0d, 0xdf, 0xad, 0xa4, 0xd2, 0x07, 0x89 };
|
||||
uint8_t key_data[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
|
||||
MifareDESFireKey key = mifare_desfire_des_key_new_with_version (key_data);
|
||||
MifareDESFireKey key = mifare_desfire_des_key_new_with_version(key_data);
|
||||
|
||||
uint8_t expected_data[8] = { 0xd6, 0x59, 0xe1, 0x70, 0x43, 0xa8, 0x40, 0x68 };
|
||||
uint8_t expected_key[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
|
||||
|
||||
mifare_cypher_blocks_chained (NULL, key, null_ivect, data, 8, MCD_SEND, MCO_DECYPHER);
|
||||
mifare_cypher_blocks_chained(NULL, key, null_ivect, data, 8, MCD_SEND, MCO_DECYPHER);
|
||||
|
||||
cut_assert_equal_memory (&expected_data, 8, &data, 8, cut_message ("Wrong data"));
|
||||
cut_assert_equal_memory (&expected_key, 8, key->data, 8, cut_message ("Wrong key"));
|
||||
cut_assert_equal_memory(&expected_data, 8, &data, 8, cut_message("Wrong data"));
|
||||
cut_assert_equal_memory(&expected_key, 8, key->data, 8, cut_message("Wrong key"));
|
||||
|
||||
mifare_desfire_key_free (key);
|
||||
mifare_desfire_key_free(key);
|
||||
}
|
||||
|
||||
void
|
||||
test_mifare_desfire_padded_data_length (void)
|
||||
test_mifare_desfire_padded_data_length(void)
|
||||
{
|
||||
size_t res;
|
||||
|
||||
res = padded_data_length (0, 8);
|
||||
cut_assert_equal_int (res, 8, cut_message ("Invalid size"));
|
||||
res = padded_data_length (1, 8);
|
||||
cut_assert_equal_int (res, 8, cut_message ("Invalid size"));
|
||||
res = padded_data_length (8, 8);
|
||||
cut_assert_equal_int (res, 8, cut_message ("Invalid size"));
|
||||
res = padded_data_length (9, 8);
|
||||
cut_assert_equal_int (res, 16, cut_message ("Invalid size"));
|
||||
res = padded_data_length (0, 16);
|
||||
cut_assert_equal_int (res, 16, cut_message ("Invalid size"));
|
||||
res = padded_data_length (33, 16);
|
||||
cut_assert_equal_int (res, 48, cut_message ("Invalid size"));
|
||||
res = padded_data_length(0, 8);
|
||||
cut_assert_equal_int(res, 8, cut_message("Invalid size"));
|
||||
res = padded_data_length(1, 8);
|
||||
cut_assert_equal_int(res, 8, cut_message("Invalid size"));
|
||||
res = padded_data_length(8, 8);
|
||||
cut_assert_equal_int(res, 8, cut_message("Invalid size"));
|
||||
res = padded_data_length(9, 8);
|
||||
cut_assert_equal_int(res, 16, cut_message("Invalid size"));
|
||||
res = padded_data_length(0, 16);
|
||||
cut_assert_equal_int(res, 16, cut_message("Invalid size"));
|
||||
res = padded_data_length(33, 16);
|
||||
cut_assert_equal_int(res, 48, cut_message("Invalid size"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/*-
|
||||
* Copyright (C) 2010, Romain Tartiere.
|
||||
*
|
||||
*
|
||||
* 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
@ -28,128 +28,128 @@
|
|||
|
||||
#define cut_assert_success(last_command) \
|
||||
do { \
|
||||
cut_assert_equal_int (OPERATION_OK, mifare_desfire_last_picc_error (tag), cut_message ("PICC replied %s", mifare_desfire_error_lookup (mifare_desfire_last_picc_error (tag)))); \
|
||||
cut_assert_not_equal_int (-1, res, cut_message ("Wrong return value")); \
|
||||
cut_assert_equal_int (OPERATION_OK, mifare_desfire_last_picc_error (tag), cut_message ("PICC replied %s", mifare_desfire_error_lookup (mifare_desfire_last_picc_error (tag)))); \
|
||||
cut_assert_not_equal_int (-1, res, cut_message ("Wrong return value")); \
|
||||
} while (0)
|
||||
|
||||
void
|
||||
test_mifare_desfire_ev1_aes2 (void)
|
||||
test_mifare_desfire_ev1_aes2(void)
|
||||
{
|
||||
int res;
|
||||
MifareDESFireKey key;
|
||||
|
||||
mifare_desfire_auto_authenticate (tag, 0);
|
||||
mifare_desfire_auto_authenticate(tag, 0);
|
||||
|
||||
// Setup the AES key
|
||||
key = mifare_desfire_aes_key_new_with_version (key_data_aes, key_data_aes_version);
|
||||
res = mifare_desfire_change_key (tag, 0x80, key, NULL);
|
||||
cut_assert_success ("mifare_desfire_change_key");
|
||||
mifare_desfire_key_free (key);
|
||||
key = mifare_desfire_aes_key_new_with_version(key_data_aes, key_data_aes_version);
|
||||
res = mifare_desfire_change_key(tag, 0x80, key, NULL);
|
||||
cut_assert_success("mifare_desfire_change_key");
|
||||
mifare_desfire_key_free(key);
|
||||
|
||||
// Authenticate with the AES key
|
||||
key = mifare_desfire_aes_key_new_with_version (key_data_aes, key_data_aes_version);
|
||||
res = mifare_desfire_authenticate_aes (tag, 0, key);
|
||||
cut_assert_success ("mifare_desfire_authenticate");
|
||||
mifare_desfire_key_free (key);
|
||||
key = mifare_desfire_aes_key_new_with_version(key_data_aes, key_data_aes_version);
|
||||
res = mifare_desfire_authenticate_aes(tag, 0, key);
|
||||
cut_assert_success("mifare_desfire_authenticate");
|
||||
mifare_desfire_key_free(key);
|
||||
|
||||
res = mifare_desfire_format_picc (tag);
|
||||
cut_assert_success ("mifare_desfire_format_picc()");
|
||||
res = mifare_desfire_format_picc(tag);
|
||||
cut_assert_success("mifare_desfire_format_picc()");
|
||||
|
||||
key = mifare_desfire_aes_key_new_with_version (key_data_aes, key_data_aes_version);
|
||||
res = mifare_desfire_authenticate_aes (tag, 0, key);
|
||||
cut_assert_success ("mifare_desfire_authenticate");
|
||||
mifare_desfire_key_free (key);
|
||||
key = mifare_desfire_aes_key_new_with_version(key_data_aes, key_data_aes_version);
|
||||
res = mifare_desfire_authenticate_aes(tag, 0, key);
|
||||
cut_assert_success("mifare_desfire_authenticate");
|
||||
mifare_desfire_key_free(key);
|
||||
|
||||
uint32_t size;
|
||||
res = mifare_desfire_free_mem (tag, &size);
|
||||
cut_assert_success ("mifare_desfire_free_mem");
|
||||
res = mifare_desfire_free_mem(tag, &size);
|
||||
cut_assert_success("mifare_desfire_free_mem");
|
||||
|
||||
// Do some commands to check CMAC is properly handled
|
||||
res = mifare_desfire_free_mem (tag, &size);
|
||||
cut_assert_success ("mifare_desfire_free_mem");
|
||||
res = mifare_desfire_free_mem(tag, &size);
|
||||
cut_assert_success("mifare_desfire_free_mem");
|
||||
|
||||
struct mifare_desfire_version_info info;
|
||||
res = mifare_desfire_get_version (tag, &info);
|
||||
cut_assert_success ("mifare_desfire_get_version");
|
||||
res = mifare_desfire_get_version(tag, &info);
|
||||
cut_assert_success("mifare_desfire_get_version");
|
||||
|
||||
res = mifare_desfire_change_key_settings (tag, 0x0F);
|
||||
cut_assert_success ("mifare_desfire_change_key_settings");
|
||||
res = mifare_desfire_change_key_settings(tag, 0x0F);
|
||||
cut_assert_success("mifare_desfire_change_key_settings");
|
||||
|
||||
res = mifare_desfire_free_mem (tag, &size);
|
||||
cut_assert_success ("mifare_desfire_free_mem");
|
||||
res = mifare_desfire_free_mem(tag, &size);
|
||||
cut_assert_success("mifare_desfire_free_mem");
|
||||
|
||||
MifareDESFireAID aid = mifare_desfire_aid_new (0x112233);
|
||||
MifareDESFireAID aid = mifare_desfire_aid_new(0x112233);
|
||||
|
||||
mifare_desfire_delete_application (tag, aid);
|
||||
mifare_desfire_delete_application(tag, aid);
|
||||
|
||||
res = mifare_desfire_create_application (tag, aid, 0xff, 0x81);
|
||||
cut_assert_success ("mifare_desfire_create_application");
|
||||
res = mifare_desfire_create_application(tag, aid, 0xff, 0x81);
|
||||
cut_assert_success("mifare_desfire_create_application");
|
||||
|
||||
res = mifare_desfire_select_application (tag, aid);
|
||||
cut_assert_success ("mifare_desfire_select_application");
|
||||
res = mifare_desfire_select_application(tag, aid);
|
||||
cut_assert_success("mifare_desfire_select_application");
|
||||
|
||||
key = mifare_desfire_aes_key_new (key_data_aes);
|
||||
res = mifare_desfire_authenticate_aes (tag, 0, key);
|
||||
cut_assert_success ("mifare_desfire_authenticate");
|
||||
free (key);
|
||||
key = mifare_desfire_aes_key_new(key_data_aes);
|
||||
res = mifare_desfire_authenticate_aes(tag, 0, key);
|
||||
cut_assert_success("mifare_desfire_authenticate");
|
||||
free(key);
|
||||
|
||||
key = mifare_desfire_aes_key_new_with_version (key_data_aes, key_data_aes_version);
|
||||
res = mifare_desfire_change_key (tag, 0x00, key, NULL);
|
||||
cut_assert_success ("mifare_desfire_change_key");
|
||||
mifare_desfire_key_free (key);
|
||||
key = mifare_desfire_aes_key_new_with_version(key_data_aes, key_data_aes_version);
|
||||
res = mifare_desfire_change_key(tag, 0x00, key, NULL);
|
||||
cut_assert_success("mifare_desfire_change_key");
|
||||
mifare_desfire_key_free(key);
|
||||
|
||||
key = mifare_desfire_aes_key_new (key_data_aes);
|
||||
res = mifare_desfire_authenticate_aes (tag, 0, key);
|
||||
cut_assert_success ("mifare_desfire_authenticate");
|
||||
free (key);
|
||||
key = mifare_desfire_aes_key_new(key_data_aes);
|
||||
res = mifare_desfire_authenticate_aes(tag, 0, key);
|
||||
cut_assert_success("mifare_desfire_authenticate");
|
||||
free(key);
|
||||
|
||||
res = mifare_desfire_create_std_data_file (tag, 1, MDCM_MACED, 0x0000, 512);
|
||||
if ((mifare_desfire_last_picc_error (tag) != DUPLICATE_ERROR) && (mifare_desfire_last_picc_error(tag) != OPERATION_OK))
|
||||
cut_assert_success ("mifare_desfire_create_std_data_file");
|
||||
res = mifare_desfire_create_std_data_file(tag, 1, MDCM_MACED, 0x0000, 512);
|
||||
if ((mifare_desfire_last_picc_error(tag) != DUPLICATE_ERROR) && (mifare_desfire_last_picc_error(tag) != OPERATION_OK))
|
||||
cut_assert_success("mifare_desfire_create_std_data_file");
|
||||
|
||||
char sample_data[] = "Hello World! I'm a string that is probably too long "
|
||||
"to feet in a single frame. For this reason, it will be split and like"
|
||||
"ly, some failure in the algorirthm should trigger an error in this uni"
|
||||
"t test.";
|
||||
res = mifare_desfire_write_data_ex (tag, 1, 0, strlen (sample_data), sample_data, MDCM_MACED);
|
||||
cut_assert_success ("mifare_desfire_write_data");
|
||||
"to feet in a single frame. For this reason, it will be split and like"
|
||||
"ly, some failure in the algorirthm should trigger an error in this uni"
|
||||
"t test.";
|
||||
res = mifare_desfire_write_data_ex(tag, 1, 0, strlen(sample_data), sample_data, MDCM_MACED);
|
||||
cut_assert_success("mifare_desfire_write_data");
|
||||
|
||||
char buffer[1024];
|
||||
|
||||
res = mifare_desfire_read_data_ex (tag, 1, 0, 27, buffer, MDCM_MACED);
|
||||
cut_assert_success ("mifare_desfire_read_data");
|
||||
cut_assert_equal_memory (buffer, res, sample_data, 27, cut_message ("AES crypto failed"));
|
||||
res = mifare_desfire_read_data_ex(tag, 1, 0, 27, buffer, MDCM_MACED);
|
||||
cut_assert_success("mifare_desfire_read_data");
|
||||
cut_assert_equal_memory(buffer, res, sample_data, 27, cut_message("AES crypto failed"));
|
||||
|
||||
char canaries[] = "Canaries Canaries Canaries Canaries Canaries";
|
||||
|
||||
res = mifare_desfire_read_data_ex (tag, 1, 0, 1, canaries, MDCM_MACED);
|
||||
cut_assert_success ("mifare_desfire_read_data");
|
||||
cut_assert_equal_int (1, res, cut_message ("Reading 1 byte should return 1 byte"));
|
||||
cut_assert_equal_memory (canaries, 44, "Hanaries Canaries Canaries Canaries Canaries", 44, cut_message ("Canaries got smashed!"));
|
||||
res = mifare_desfire_read_data_ex(tag, 1, 0, 1, canaries, MDCM_MACED);
|
||||
cut_assert_success("mifare_desfire_read_data");
|
||||
cut_assert_equal_int(1, res, cut_message("Reading 1 byte should return 1 byte"));
|
||||
cut_assert_equal_memory(canaries, 44, "Hanaries Canaries Canaries Canaries Canaries", 44, cut_message("Canaries got smashed!"));
|
||||
|
||||
uint8_t s, c;
|
||||
res = mifare_desfire_get_key_settings (tag, &s, &c);
|
||||
cut_assert_success ("mifare_desfire_get__key_settings");
|
||||
res = mifare_desfire_get_key_settings(tag, &s, &c);
|
||||
cut_assert_success("mifare_desfire_get__key_settings");
|
||||
|
||||
res = mifare_desfire_read_data_ex (tag, 1, 27, 27, buffer, MDCM_MACED);
|
||||
cut_assert_success ("mifare_desfire_read_data");
|
||||
cut_assert_equal_memory (buffer, res, sample_data + 27, 27, cut_message ("AES crypto failed"));
|
||||
res = mifare_desfire_read_data_ex(tag, 1, 27, 27, buffer, MDCM_MACED);
|
||||
cut_assert_success("mifare_desfire_read_data");
|
||||
cut_assert_equal_memory(buffer, res, sample_data + 27, 27, cut_message("AES crypto failed"));
|
||||
|
||||
res = mifare_desfire_read_data_ex (tag, 1, 0, 0, buffer, MDCM_MACED);
|
||||
cut_assert_success ("mifare_desfire_read_data");
|
||||
cut_assert_equal_memory (buffer, strlen (buffer), sample_data, strlen (sample_data), cut_message ("AES crypto failed"));
|
||||
res = mifare_desfire_read_data_ex(tag, 1, 0, 0, buffer, MDCM_MACED);
|
||||
cut_assert_success("mifare_desfire_read_data");
|
||||
cut_assert_equal_memory(buffer, strlen(buffer), sample_data, strlen(sample_data), cut_message("AES crypto failed"));
|
||||
|
||||
// Revert to the default DES key
|
||||
res = mifare_desfire_select_application (tag, NULL);
|
||||
cut_assert_success ("mifare_desfire_select_application");
|
||||
res = mifare_desfire_select_application(tag, NULL);
|
||||
cut_assert_success("mifare_desfire_select_application");
|
||||
|
||||
key = mifare_desfire_aes_key_new_with_version (key_data_aes, key_data_aes_version);
|
||||
res = mifare_desfire_authenticate_aes (tag, 0, key);
|
||||
cut_assert_success ("mifare_desfire_authenticate");
|
||||
mifare_desfire_key_free (key);
|
||||
key = mifare_desfire_aes_key_new_with_version(key_data_aes, key_data_aes_version);
|
||||
res = mifare_desfire_authenticate_aes(tag, 0, key);
|
||||
cut_assert_success("mifare_desfire_authenticate");
|
||||
mifare_desfire_key_free(key);
|
||||
|
||||
key = mifare_desfire_des_key_new (key_data_null);
|
||||
res = mifare_desfire_change_key (tag, 0x00, key, NULL);
|
||||
cut_assert_success ("mifare_desfire_change_key");
|
||||
mifare_desfire_key_free (key);
|
||||
key = mifare_desfire_des_key_new(key_data_null);
|
||||
res = mifare_desfire_change_key(tag, 0x00, key, NULL);
|
||||
cut_assert_success("mifare_desfire_change_key");
|
||||
mifare_desfire_key_free(key);
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,11 +1,11 @@
|
|||
/*-
|
||||
* Copyright (C) 2011, Romain Tartiere.
|
||||
*
|
||||
*
|
||||
* 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
@ -25,105 +25,105 @@
|
|||
|
||||
#define cut_assert_success(last_command) \
|
||||
do { \
|
||||
cut_assert_equal_int (OPERATION_OK, mifare_desfire_last_picc_error (tag), cut_message ("PICC replied %s", mifare_desfire_error_lookup (mifare_desfire_last_picc_error (tag)))); \
|
||||
cut_assert_not_equal_int (-1, res, cut_message ("Wrong return value")); \
|
||||
cut_assert_equal_int (OPERATION_OK, mifare_desfire_last_picc_error (tag), cut_message ("PICC replied %s", mifare_desfire_error_lookup (mifare_desfire_last_picc_error (tag)))); \
|
||||
cut_assert_not_equal_int (-1, res, cut_message ("Wrong return value")); \
|
||||
} while (0)
|
||||
|
||||
void
|
||||
test_mifare_desfire_ev1_iso (void)
|
||||
test_mifare_desfire_ev1_iso(void)
|
||||
{
|
||||
int res;
|
||||
|
||||
mifare_desfire_auto_authenticate (tag, 0);
|
||||
mifare_desfire_auto_authenticate(tag, 0);
|
||||
|
||||
res = mifare_desfire_format_picc (tag);
|
||||
cut_assert_equal_int (res, 0, cut_message ("mifare_desfire_format_picc()"));
|
||||
res = mifare_desfire_format_picc(tag);
|
||||
cut_assert_equal_int(res, 0, cut_message("mifare_desfire_format_picc()"));
|
||||
|
||||
MifareDESFireDF *dfs;
|
||||
size_t count;
|
||||
res = mifare_desfire_get_df_names (tag, &dfs, &count);
|
||||
cut_assert_equal_int (res, 0, cut_message ("mifare_desfire_get_df_names()"));
|
||||
cut_assert_equal_int (count, 0, cut_message ("Wrong DF count"));
|
||||
cut_assert_null (dfs, cut_message ("DF should be NULL"));
|
||||
res = mifare_desfire_get_df_names(tag, &dfs, &count);
|
||||
cut_assert_equal_int(res, 0, cut_message("mifare_desfire_get_df_names()"));
|
||||
cut_assert_equal_int(count, 0, cut_message("Wrong DF count"));
|
||||
cut_assert_null(dfs, cut_message("DF should be NULL"));
|
||||
|
||||
MifareDESFireAID aid = mifare_desfire_aid_new (0x111110);
|
||||
res = mifare_desfire_create_application_iso (tag, aid, 0xFF, 1, 0, 0x111F, NULL, 0);
|
||||
cut_assert_success ("mifare_desfire_create_application_iso");
|
||||
free (aid);
|
||||
MifareDESFireAID aid = mifare_desfire_aid_new(0x111110);
|
||||
res = mifare_desfire_create_application_iso(tag, aid, 0xFF, 1, 0, 0x111F, NULL, 0);
|
||||
cut_assert_success("mifare_desfire_create_application_iso");
|
||||
free(aid);
|
||||
|
||||
uint8_t app2[] = "App2";
|
||||
aid = mifare_desfire_aid_new (0x222220);
|
||||
res = mifare_desfire_create_application_iso (tag, aid, 0xFF, 1, 0, 0x222F, app2, sizeof (app2));
|
||||
cut_assert_success ("mifare_desfire_create_application_iso");
|
||||
free (aid);
|
||||
aid = mifare_desfire_aid_new(0x222220);
|
||||
res = mifare_desfire_create_application_iso(tag, aid, 0xFF, 1, 0, 0x222F, app2, sizeof(app2));
|
||||
cut_assert_success("mifare_desfire_create_application_iso");
|
||||
free(aid);
|
||||
|
||||
uint8_t app3[] = "App3";
|
||||
aid = mifare_desfire_aid_new (0x333330);
|
||||
res = mifare_desfire_create_application_iso (tag, aid, 0xFF, 1, 0, 0x333F, app3, sizeof (app3));
|
||||
cut_assert_success ("mifare_desfire_create_application_iso");
|
||||
free (aid);
|
||||
aid = mifare_desfire_aid_new(0x333330);
|
||||
res = mifare_desfire_create_application_iso(tag, aid, 0xFF, 1, 0, 0x333F, app3, sizeof(app3));
|
||||
cut_assert_success("mifare_desfire_create_application_iso");
|
||||
free(aid);
|
||||
|
||||
aid = mifare_desfire_aid_new (0x444440);
|
||||
res = mifare_desfire_create_application_iso (tag, aid, 0xFF, 1, 0, 0x111F, NULL, 0);
|
||||
cut_assert_equal_int (-1, res, cut_message ("Should fail"));
|
||||
cut_assert_equal_int (DUPLICATE_ERROR, mifare_desfire_last_picc_error (tag), cut_message ("Should be a duplicate error"));
|
||||
aid = mifare_desfire_aid_new(0x444440);
|
||||
res = mifare_desfire_create_application_iso(tag, aid, 0xFF, 1, 0, 0x111F, NULL, 0);
|
||||
cut_assert_equal_int(-1, res, cut_message("Should fail"));
|
||||
cut_assert_equal_int(DUPLICATE_ERROR, mifare_desfire_last_picc_error(tag), cut_message("Should be a duplicate error"));
|
||||
|
||||
res = mifare_desfire_create_application_iso (tag, aid, 0xFF, 1, 0, 0x444F, app2, sizeof (app2));
|
||||
cut_assert_equal_int (-1, res, cut_message ("Should fail"));
|
||||
cut_assert_equal_int (DUPLICATE_ERROR, mifare_desfire_last_picc_error (tag), cut_message ("Should be a duplicate error"));
|
||||
free (aid);
|
||||
res = mifare_desfire_create_application_iso(tag, aid, 0xFF, 1, 0, 0x444F, app2, sizeof(app2));
|
||||
cut_assert_equal_int(-1, res, cut_message("Should fail"));
|
||||
cut_assert_equal_int(DUPLICATE_ERROR, mifare_desfire_last_picc_error(tag), cut_message("Should be a duplicate error"));
|
||||
free(aid);
|
||||
|
||||
|
||||
res = mifare_desfire_get_df_names (tag, &dfs, &count);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_desfire_get_df_names()"));
|
||||
cut_assert_equal_int (3, count, cut_message ("Wrong DF count"));
|
||||
cut_assert_not_null (dfs, cut_message ("DF should not be NULL"));
|
||||
res = mifare_desfire_get_df_names(tag, &dfs, &count);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_desfire_get_df_names()"));
|
||||
cut_assert_equal_int(3, count, cut_message("Wrong DF count"));
|
||||
cut_assert_not_null(dfs, cut_message("DF should not be NULL"));
|
||||
|
||||
cut_assert_equal_int (0x111110, dfs[0].aid, cut_message ("Wrong value"));
|
||||
cut_assert_equal_int (0x111F, dfs[0].fid, cut_message ("Wrong value"));
|
||||
cut_assert_equal_int (0, dfs[0].df_name_len, cut_message ("Wrong value"));
|
||||
cut_assert_equal_int(0x111110, dfs[0].aid, cut_message("Wrong value"));
|
||||
cut_assert_equal_int(0x111F, dfs[0].fid, cut_message("Wrong value"));
|
||||
cut_assert_equal_int(0, dfs[0].df_name_len, cut_message("Wrong value"));
|
||||
|
||||
cut_assert_equal_int (0x222220, dfs[1].aid, cut_message ("Wrong value"));
|
||||
cut_assert_equal_int (0x222F, dfs[1].fid, cut_message ("Wrong value"));
|
||||
cut_assert_equal_int (sizeof (app2), dfs[1].df_name_len, cut_message ("Wrong value"));
|
||||
cut_assert_equal_memory (app2, sizeof (app2), dfs[1].df_name, dfs[1].df_name_len, cut_message ("Wrong value"));
|
||||
cut_assert_equal_int(0x222220, dfs[1].aid, cut_message("Wrong value"));
|
||||
cut_assert_equal_int(0x222F, dfs[1].fid, cut_message("Wrong value"));
|
||||
cut_assert_equal_int(sizeof(app2), dfs[1].df_name_len, cut_message("Wrong value"));
|
||||
cut_assert_equal_memory(app2, sizeof(app2), dfs[1].df_name, dfs[1].df_name_len, cut_message("Wrong value"));
|
||||
|
||||
cut_assert_equal_int (0x333330, dfs[2].aid, cut_message ("Wrong value"));
|
||||
cut_assert_equal_int (0x333F, dfs[2].fid, cut_message ("Wrong value"));
|
||||
cut_assert_equal_int (sizeof (app3), dfs[2].df_name_len, cut_message ("Wrong value"));
|
||||
cut_assert_equal_memory (app3, sizeof (app3), dfs[2].df_name, dfs[2].df_name_len, cut_message ("Wrong value"));
|
||||
free (dfs);
|
||||
cut_assert_equal_int(0x333330, dfs[2].aid, cut_message("Wrong value"));
|
||||
cut_assert_equal_int(0x333F, dfs[2].fid, cut_message("Wrong value"));
|
||||
cut_assert_equal_int(sizeof(app3), dfs[2].df_name_len, cut_message("Wrong value"));
|
||||
cut_assert_equal_memory(app3, sizeof(app3), dfs[2].df_name, dfs[2].df_name_len, cut_message("Wrong value"));
|
||||
free(dfs);
|
||||
|
||||
aid = mifare_desfire_aid_new (0x555550);
|
||||
res = mifare_desfire_create_application_iso (tag, aid, 0xff, 1, 1, 0x555F, NULL, 0);
|
||||
cut_assert_success ("mifare_desfire_create_application_iso");
|
||||
aid = mifare_desfire_aid_new(0x555550);
|
||||
res = mifare_desfire_create_application_iso(tag, aid, 0xff, 1, 1, 0x555F, NULL, 0);
|
||||
cut_assert_success("mifare_desfire_create_application_iso");
|
||||
|
||||
res = mifare_desfire_select_application (tag, aid);
|
||||
cut_assert_success ("mifare_desfire_select_application");
|
||||
res = mifare_desfire_select_application(tag, aid);
|
||||
cut_assert_success("mifare_desfire_select_application");
|
||||
|
||||
res = mifare_desfire_create_std_data_file_iso (tag, 1, MDCM_PLAIN, 0xEEEE, 32, 0x1234);
|
||||
cut_assert_success ("mifare_desfire_create_std_data_file_iso");
|
||||
res = mifare_desfire_create_std_data_file_iso(tag, 1, MDCM_PLAIN, 0xEEEE, 32, 0x1234);
|
||||
cut_assert_success("mifare_desfire_create_std_data_file_iso");
|
||||
|
||||
res = mifare_desfire_create_backup_data_file_iso (tag, 2, MDCM_PLAIN, 0xEEEE, 32, 0x2345);
|
||||
cut_assert_success ("mifare_desfire_create_std_data_file_iso");
|
||||
res = mifare_desfire_create_backup_data_file_iso(tag, 2, MDCM_PLAIN, 0xEEEE, 32, 0x2345);
|
||||
cut_assert_success("mifare_desfire_create_std_data_file_iso");
|
||||
|
||||
res = mifare_desfire_create_linear_record_file_iso (tag, 3, MDCM_PLAIN, 0xEEEE, 32, 10, 0x3456);
|
||||
cut_assert_success ("mifare_desfire_create_linear_record_file_iso");
|
||||
res = mifare_desfire_create_linear_record_file_iso(tag, 3, MDCM_PLAIN, 0xEEEE, 32, 10, 0x3456);
|
||||
cut_assert_success("mifare_desfire_create_linear_record_file_iso");
|
||||
|
||||
res = mifare_desfire_create_cyclic_record_file_iso (tag, 4, MDCM_PLAIN, 0xEEEE, 32, 10, 0x4567);
|
||||
cut_assert_success ("mifare_desfire_create_cyclic_record_file_iso");
|
||||
res = mifare_desfire_create_cyclic_record_file_iso(tag, 4, MDCM_PLAIN, 0xEEEE, 32, 10, 0x4567);
|
||||
cut_assert_success("mifare_desfire_create_cyclic_record_file_iso");
|
||||
|
||||
uint16_t *ids;
|
||||
res = mifare_desfire_get_iso_file_ids (tag, &ids, &count);
|
||||
cut_assert_success ("mifare_desfire_get_iso_file_ids");
|
||||
res = mifare_desfire_get_iso_file_ids(tag, &ids, &count);
|
||||
cut_assert_success("mifare_desfire_get_iso_file_ids");
|
||||
|
||||
cut_assert_equal_int (4, count, cut_message ("Invalid file count"));
|
||||
cut_assert_equal_int (0x1234, ids[0], cut_message ("Wrong file ID"));
|
||||
cut_assert_equal_int (0x2345, ids[1], cut_message ("Wrong file ID"));
|
||||
cut_assert_equal_int (0x3456, ids[2], cut_message ("Wrong file ID"));
|
||||
cut_assert_equal_int (0x4567, ids[3], cut_message ("Wrong file ID"));
|
||||
free (ids);
|
||||
cut_assert_equal_int(4, count, cut_message("Invalid file count"));
|
||||
cut_assert_equal_int(0x1234, ids[0], cut_message("Wrong file ID"));
|
||||
cut_assert_equal_int(0x2345, ids[1], cut_message("Wrong file ID"));
|
||||
cut_assert_equal_int(0x3456, ids[2], cut_message("Wrong file ID"));
|
||||
cut_assert_equal_int(0x4567, ids[3], cut_message("Wrong file ID"));
|
||||
free(ids);
|
||||
|
||||
free (aid);
|
||||
free(aid);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/*-
|
||||
* Copyright (C) 2010, Romain Tartiere.
|
||||
*
|
||||
*
|
||||
* 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
@ -21,76 +21,76 @@
|
|||
|
||||
|
||||
void
|
||||
test_mifare_desfire_key (void)
|
||||
test_mifare_desfire_key(void)
|
||||
{
|
||||
MifareDESFireKey key;
|
||||
int version;
|
||||
|
||||
uint8_t key1_des_data[8] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 };
|
||||
|
||||
key = mifare_desfire_des_key_new (key1_des_data);
|
||||
version = mifare_desfire_key_get_version (key);
|
||||
cut_assert_equal_int (0x00, version, cut_message ("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_free (key);
|
||||
key = mifare_desfire_des_key_new(key1_des_data);
|
||||
version = mifare_desfire_key_get_version(key);
|
||||
cut_assert_equal_int(0x00, version, cut_message("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_free(key);
|
||||
|
||||
key = mifare_desfire_des_key_new_with_version (key1_des_data);
|
||||
version = mifare_desfire_key_get_version (key);
|
||||
cut_assert_equal_int (0x55, version, cut_message ("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_set_version (key, 0xaa);
|
||||
version = mifare_desfire_key_get_version (key);
|
||||
cut_assert_equal_int (0xaa, version, cut_message ("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_free (key);
|
||||
key = mifare_desfire_des_key_new_with_version(key1_des_data);
|
||||
version = mifare_desfire_key_get_version(key);
|
||||
cut_assert_equal_int(0x55, version, cut_message("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_set_version(key, 0xaa);
|
||||
version = mifare_desfire_key_get_version(key);
|
||||
cut_assert_equal_int(0xaa, version, cut_message("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_free(key);
|
||||
|
||||
|
||||
uint8_t key2_des_data[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
key = mifare_desfire_des_key_new (key2_des_data);
|
||||
version = mifare_desfire_key_get_version (key);
|
||||
cut_assert_equal_int (0x00, version, cut_message ("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_free (key);
|
||||
key = mifare_desfire_des_key_new(key2_des_data);
|
||||
version = mifare_desfire_key_get_version(key);
|
||||
cut_assert_equal_int(0x00, version, cut_message("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_free(key);
|
||||
|
||||
key = mifare_desfire_des_key_new_with_version (key2_des_data);
|
||||
version = mifare_desfire_key_get_version (key);
|
||||
cut_assert_equal_int (0x00, version, cut_message ("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_free (key);
|
||||
key = mifare_desfire_des_key_new_with_version(key2_des_data);
|
||||
version = mifare_desfire_key_get_version(key);
|
||||
cut_assert_equal_int(0x00, version, cut_message("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_free(key);
|
||||
|
||||
|
||||
uint8_t key1_3des_data[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0XEE, 0xFF };
|
||||
|
||||
key = mifare_desfire_3des_key_new (key1_3des_data);
|
||||
version = mifare_desfire_key_get_version (key);
|
||||
cut_assert_equal_int (0x00, version, cut_message ("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_free (key);
|
||||
key = mifare_desfire_3des_key_new(key1_3des_data);
|
||||
version = mifare_desfire_key_get_version(key);
|
||||
cut_assert_equal_int(0x00, version, cut_message("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_free(key);
|
||||
|
||||
key = mifare_desfire_3des_key_new_with_version (key1_3des_data);
|
||||
version = mifare_desfire_key_get_version (key);
|
||||
cut_assert_equal_int (0x55, version, cut_message ("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_set_version (key, 0xaa);
|
||||
version = mifare_desfire_key_get_version (key);
|
||||
cut_assert_equal_int (0xaa, version, cut_message ("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_free (key);
|
||||
key = mifare_desfire_3des_key_new_with_version(key1_3des_data);
|
||||
version = mifare_desfire_key_get_version(key);
|
||||
cut_assert_equal_int(0x55, version, cut_message("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_set_version(key, 0xaa);
|
||||
version = mifare_desfire_key_get_version(key);
|
||||
cut_assert_equal_int(0xaa, version, cut_message("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_free(key);
|
||||
|
||||
uint8_t key2_3des_data[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0X01, 0x00, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 };
|
||||
|
||||
key = mifare_desfire_3des_key_new (key2_3des_data);
|
||||
version = mifare_desfire_key_get_version (key);
|
||||
cut_assert_equal_int (0x00, version, cut_message ("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_free (key);
|
||||
key = mifare_desfire_3des_key_new(key2_3des_data);
|
||||
version = mifare_desfire_key_get_version(key);
|
||||
cut_assert_equal_int(0x00, version, cut_message("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_free(key);
|
||||
|
||||
key = mifare_desfire_3des_key_new_with_version (key2_3des_data);
|
||||
version = mifare_desfire_key_get_version (key);
|
||||
cut_assert_equal_int (0x02, version, cut_message ("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_free (key);
|
||||
key = mifare_desfire_3des_key_new_with_version(key2_3des_data);
|
||||
version = mifare_desfire_key_get_version(key);
|
||||
cut_assert_equal_int(0x02, version, cut_message("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_free(key);
|
||||
|
||||
uint8_t key3_3des_data[16] = { 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0X00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77 };
|
||||
|
||||
key = mifare_desfire_3des_key_new (key3_3des_data);
|
||||
version = mifare_desfire_key_get_version (key);
|
||||
cut_assert_equal_int (0x00, version, cut_message ("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_free (key);
|
||||
key = mifare_desfire_3des_key_new(key3_3des_data);
|
||||
version = mifare_desfire_key_get_version(key);
|
||||
cut_assert_equal_int(0x00, version, cut_message("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_free(key);
|
||||
|
||||
key = mifare_desfire_3des_key_new_with_version (key3_3des_data);
|
||||
version = mifare_desfire_key_get_version (key);
|
||||
cut_assert_equal_int (0x10, version, cut_message ("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_free (key);
|
||||
key = mifare_desfire_3des_key_new_with_version(key3_3des_data);
|
||||
version = mifare_desfire_key_get_version(key);
|
||||
cut_assert_equal_int(0x10, version, cut_message("Wrong MifareDESFireKey version"));
|
||||
mifare_desfire_key_free(key);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/*-
|
||||
* Copyright (C) 2010, Romain Tartiere.
|
||||
*
|
||||
*
|
||||
* 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
#include "mifare_ultralight_fixture.h"
|
||||
|
||||
void
|
||||
test_mifare_ultralight_write (void)
|
||||
test_mifare_ultralight_write(void)
|
||||
{
|
||||
int res;
|
||||
|
||||
|
|
@ -37,158 +37,158 @@ test_mifare_ultralight_write (void)
|
|||
MifareUltralightPageNumber n = 7;
|
||||
|
||||
/* Read and save current value (should be { 0x00 0x00 0x00 0x00 }) */
|
||||
res = mifare_ultralight_read (tag, n, &initial);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_ultralight_read() failed"));
|
||||
res = mifare_ultralight_read(tag, n, &initial);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_ultralight_read() failed"));
|
||||
|
||||
/* Write payload1 */
|
||||
res = mifare_ultralight_write (tag, n, payload1);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_ultralight_write() failed"));
|
||||
res = mifare_ultralight_write(tag, n, payload1);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_ultralight_write() failed"));
|
||||
|
||||
/* Check it */
|
||||
res = mifare_ultralight_read (tag, n, &page);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_ultralight_read() failed"));
|
||||
cut_assert_equal_memory (payload1, sizeof (payload1), page, sizeof (page), cut_message ("Wrong data"));
|
||||
res = mifare_ultralight_read(tag, n, &page);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_ultralight_read() failed"));
|
||||
cut_assert_equal_memory(payload1, sizeof(payload1), page, sizeof(page), cut_message("Wrong data"));
|
||||
|
||||
/* Write payload2 */
|
||||
res = mifare_ultralight_write (tag, n, payload2);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_ultralight_write() failed"));
|
||||
res = mifare_ultralight_write(tag, n, payload2);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_ultralight_write() failed"));
|
||||
|
||||
/* Check it */
|
||||
res = mifare_ultralight_read (tag, n, &page);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_ultralight_read() failed"));
|
||||
cut_assert_equal_memory (payload2, sizeof (payload2), page, sizeof (page), cut_message ("Wrong data"));
|
||||
res = mifare_ultralight_read(tag, n, &page);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_ultralight_read() failed"));
|
||||
cut_assert_equal_memory(payload2, sizeof(payload2), page, sizeof(page), cut_message("Wrong data"));
|
||||
|
||||
/* Write initial data */
|
||||
res = mifare_ultralight_write (tag, n, initial);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_ultralight_write() failed"));
|
||||
res = mifare_ultralight_write(tag, n, initial);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_ultralight_write() failed"));
|
||||
|
||||
/* While here check it (no reason to fail since the rest of the test passed) */
|
||||
res = mifare_ultralight_read (tag, n, &page);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_ultralight_read() failed"));
|
||||
cut_assert_equal_memory (initial, sizeof (initial), page, sizeof (page), cut_message ("Wrong data"));
|
||||
res = mifare_ultralight_read(tag, n, &page);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_ultralight_read() failed"));
|
||||
cut_assert_equal_memory(initial, sizeof(initial), page, sizeof(page), cut_message("Wrong data"));
|
||||
}
|
||||
|
||||
void
|
||||
test_mifare_ultralight_invalid_page (void)
|
||||
test_mifare_ultralight_invalid_page(void)
|
||||
{
|
||||
int res;
|
||||
MifareUltralightPage page = { 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
int invalid_page;
|
||||
if (is_mifare_ultralightc (tag)) {
|
||||
invalid_page = MIFARE_ULTRALIGHT_C_PAGE_COUNT;
|
||||
if (is_mifare_ultralightc(tag)) {
|
||||
invalid_page = MIFARE_ULTRALIGHT_C_PAGE_COUNT;
|
||||
} else {
|
||||
invalid_page = MIFARE_ULTRALIGHT_PAGE_COUNT;
|
||||
invalid_page = MIFARE_ULTRALIGHT_PAGE_COUNT;
|
||||
}
|
||||
res = mifare_ultralight_read (tag, invalid_page, &page);
|
||||
cut_assert_equal_int (-1, res, cut_message ("mifare_ultralight_read() succeeded"));
|
||||
cut_assert_equal_int (EINVAL, errno, cut_message ("Wrong errno value"));
|
||||
res = mifare_ultralight_read(tag, invalid_page, &page);
|
||||
cut_assert_equal_int(-1, res, cut_message("mifare_ultralight_read() succeeded"));
|
||||
cut_assert_equal_int(EINVAL, errno, cut_message("Wrong errno value"));
|
||||
|
||||
res = mifare_ultralight_write (tag, invalid_page, page);
|
||||
cut_assert_equal_int (-1, res, cut_message ("mifare_ultralight_write() succeeded"));
|
||||
cut_assert_equal_int (EINVAL, errno, cut_message ("Wrong errno value"));
|
||||
res = mifare_ultralight_write(tag, invalid_page, page);
|
||||
cut_assert_equal_int(-1, res, cut_message("mifare_ultralight_write() succeeded"));
|
||||
cut_assert_equal_int(EINVAL, errno, cut_message("Wrong errno value"));
|
||||
}
|
||||
|
||||
void
|
||||
test_mifare_ultralight_cache (void)
|
||||
test_mifare_ultralight_cache(void)
|
||||
{
|
||||
int res;
|
||||
MifareUltralightPage page;
|
||||
|
||||
res = mifare_ultralight_read (tag, 0, &page);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_ultralight_read() failed"));
|
||||
res = mifare_ultralight_read(tag, 0, &page);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_ultralight_read() failed"));
|
||||
|
||||
/* Check cached pages consistency */
|
||||
for (int i = 0; i <= 3; i++) {
|
||||
cut_assert_equal_int (1, MIFARE_ULTRALIGHT(tag)->cached_pages[i], cut_message ("Wrong page cache value for tag->cached_pages[%d]", i));
|
||||
cut_assert_equal_int(1, MIFARE_ULTRALIGHT(tag)->cached_pages[i], cut_message("Wrong page cache value for tag->cached_pages[%d]", i));
|
||||
}
|
||||
for (int i = 4; i < MIFARE_ULTRALIGHT_PAGE_COUNT; i++) {
|
||||
cut_assert_equal_int (0, MIFARE_ULTRALIGHT(tag)->cached_pages[i], cut_message ("Wrong page cache value for tag->cached_pages[%d]", i));
|
||||
cut_assert_equal_int(0, MIFARE_ULTRALIGHT(tag)->cached_pages[i], cut_message("Wrong page cache value for tag->cached_pages[%d]", i));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
test_mifare_ultralight_cache_hit (void)
|
||||
test_mifare_ultralight_cache_hit(void)
|
||||
{
|
||||
int res;
|
||||
|
||||
MifareUltralightPage page1;
|
||||
MifareUltralightPage page2;
|
||||
|
||||
res = mifare_ultralight_read (tag, 0, &page1);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_ultralight_read() failed"));
|
||||
res = mifare_ultralight_read(tag, 0, &page1);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_ultralight_read() failed"));
|
||||
|
||||
res = mifare_ultralight_read (tag, 0, &page2);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_ultralight_read() failed"));
|
||||
cut_assert_equal_memory (page1, sizeof (page1), page2, sizeof (page2), cut_message ("Wrong cached data"));
|
||||
res = mifare_ultralight_read(tag, 0, &page2);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_ultralight_read() failed"));
|
||||
cut_assert_equal_memory(page1, sizeof(page1), page2, sizeof(page2), cut_message("Wrong cached data"));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
test_mifare_ultralight_cache_wrap (void)
|
||||
test_mifare_ultralight_cache_wrap(void)
|
||||
{
|
||||
int res;
|
||||
MifareUltralightPage page;
|
||||
int last_page;
|
||||
if (is_mifare_ultralightc (tag)) {
|
||||
// Last 4 blocks are for 3DES key and cannot be read, read will wrap from 0x2b
|
||||
last_page = MIFARE_ULTRALIGHT_C_PAGE_COUNT_READ -1;
|
||||
// Actually engineering samples require auth to read above page 0x28 so we skip the test entirely
|
||||
cut_omit("mifare_ultralight_read() on last page skipped on UltralightC");
|
||||
if (is_mifare_ultralightc(tag)) {
|
||||
// Last 4 blocks are for 3DES key and cannot be read, read will wrap from 0x2b
|
||||
last_page = MIFARE_ULTRALIGHT_C_PAGE_COUNT_READ - 1;
|
||||
// Actually engineering samples require auth to read above page 0x28 so we skip the test entirely
|
||||
cut_omit("mifare_ultralight_read() on last page skipped on UltralightC");
|
||||
} else {
|
||||
last_page = MIFARE_ULTRALIGHT_PAGE_COUNT -1;
|
||||
last_page = MIFARE_ULTRALIGHT_PAGE_COUNT - 1;
|
||||
}
|
||||
res = mifare_ultralight_read (tag, last_page, &page);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_ultralight_read() failed"));
|
||||
res = mifare_ultralight_read(tag, last_page, &page);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_ultralight_read() failed"));
|
||||
|
||||
/* Check cached pages consistency */
|
||||
for (int i = 0; i <= 2; i++) {
|
||||
cut_assert_equal_int (1, MIFARE_ULTRALIGHT(tag)->cached_pages[i], cut_message ("Wrong page cache value for tag->cached_pages[%d]", i));
|
||||
cut_assert_equal_int(1, MIFARE_ULTRALIGHT(tag)->cached_pages[i], cut_message("Wrong page cache value for tag->cached_pages[%d]", i));
|
||||
}
|
||||
for (int i = 3; i < last_page; i++) {
|
||||
cut_assert_equal_int (0, MIFARE_ULTRALIGHT(tag)->cached_pages[i], cut_message ("Wrong page cache value for tag->cached_pages[%d]", i));
|
||||
cut_assert_equal_int(0, MIFARE_ULTRALIGHT(tag)->cached_pages[i], cut_message("Wrong page cache value for tag->cached_pages[%d]", i));
|
||||
}
|
||||
cut_assert_equal_int (1, MIFARE_ULTRALIGHT(tag)->cached_pages[last_page], cut_message ("Wrong page cache value for tag->cached_pages[%d]", last_page));
|
||||
cut_assert_equal_int(1, MIFARE_ULTRALIGHT(tag)->cached_pages[last_page], cut_message("Wrong page cache value for tag->cached_pages[%d]", last_page));
|
||||
}
|
||||
|
||||
void
|
||||
test_mifare_ultralight_get_uid (void)
|
||||
test_mifare_ultralight_get_uid(void)
|
||||
{
|
||||
char *uid;
|
||||
|
||||
uid = freefare_get_tag_uid (tag);
|
||||
uid = freefare_get_tag_uid(tag);
|
||||
|
||||
cut_assert_not_null (uid, cut_message ("mifare_ultralight_get_uid() failed"));
|
||||
cut_assert_equal_int (14, strlen (uid), cut_message ("Wrong UID length"));
|
||||
cut_assert_not_null(uid, cut_message("mifare_ultralight_get_uid() failed"));
|
||||
cut_assert_equal_int(14, strlen(uid), cut_message("Wrong UID length"));
|
||||
|
||||
free (uid);
|
||||
free(uid);
|
||||
}
|
||||
|
||||
void
|
||||
test_mifare_ultralight_tag_friendly_name (void)
|
||||
test_mifare_ultralight_tag_friendly_name(void)
|
||||
{
|
||||
const char *name = freefare_get_tag_friendly_name (tag);
|
||||
const char *name = freefare_get_tag_friendly_name(tag);
|
||||
|
||||
cut_assert_not_null (name, cut_message ("freefare_get_tag_friendly_name() failed"));
|
||||
cut_assert_not_null(name, cut_message("freefare_get_tag_friendly_name() failed"));
|
||||
}
|
||||
|
||||
void
|
||||
test_mifare_ultralightc_authenticate (void)
|
||||
test_mifare_ultralightc_authenticate(void)
|
||||
{
|
||||
int res;
|
||||
MifareDESFireKey key;
|
||||
|
||||
if (is_mifare_ultralightc (tag)) {
|
||||
if (is_mifare_ultralightc(tag)) {
|
||||
uint8_t key1_3des_data[16] = { 0x49, 0x45, 0x4D, 0x4B, 0x41, 0x45, 0x52, 0x42, 0x21, 0x4E, 0x41, 0x43, 0x55, 0x4F, 0x59, 0x46 };
|
||||
key = mifare_desfire_3des_key_new (key1_3des_data);
|
||||
res = mifare_ultralightc_authenticate (tag, key);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_ultralightc_authenticate() failed"));
|
||||
mifare_desfire_key_free (key);
|
||||
key = mifare_desfire_3des_key_new(key1_3des_data);
|
||||
res = mifare_ultralightc_authenticate(tag, key);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_ultralightc_authenticate() failed"));
|
||||
mifare_desfire_key_free(key);
|
||||
|
||||
MifareUltralightPage page;
|
||||
int last_page = MIFARE_ULTRALIGHT_C_PAGE_COUNT_READ -1;
|
||||
res = mifare_ultralight_read (tag, last_page, &page);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_ultralight_read() failed"));
|
||||
int last_page = MIFARE_ULTRALIGHT_C_PAGE_COUNT_READ - 1;
|
||||
res = mifare_ultralight_read(tag, last_page, &page);
|
||||
cut_assert_equal_int(0, res, cut_message("mifare_ultralight_read() failed"));
|
||||
} else {
|
||||
cut_omit("mifare_ultralightc_authenticate() skipped on Ultralight");
|
||||
}
|
||||
|
|
|
|||
142
test/test_tlv.c
142
test/test_tlv.c
|
|
@ -1,11 +1,11 @@
|
|||
/*-
|
||||
* Copyright (C) 2010, Romain Tartiere, 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
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
|
|
@ -28,120 +28,120 @@ const uint8_t eshortdata[11] = "\x03" "\x08" "elephant" "\xfe";
|
|||
* OS / compiler does not support UTF-8 ;-)
|
||||
*/
|
||||
const uint8_t longdata[660] = "Dans une terre grasse et pleine d'escargots\n" \
|
||||
"Je veux creuser moi-même une fosse profonde,\n" \
|
||||
"Où je puisse à loisir étaler mes vieux os\n" \
|
||||
"Et dormir dans l'oubli comme un requin dans l'onde.\n" \
|
||||
"Je hais les testaments et je hais les tombeaux;\n" \
|
||||
"Plutôt que d'implorer une larme du monde,\n" \
|
||||
"Vivant, j'aimerais mieux inviter les corbeaux\n" \
|
||||
"À saigner tous les bouts de ma carcasse immonde.\n" \
|
||||
"Ô vers! noirs compagnons sans oreille et sans yeux,\n" \
|
||||
"Voyez venir à vous un mort libre et joyeux;\n" \
|
||||
"Philosophes viveurs, fils de la pourriture,\n" \
|
||||
"À travers ma ruine allez donc sans remords,\n" \
|
||||
"Et dites-moi s'il est encor quelque torture\n" \
|
||||
"Pour ce vieux corps sans âme et mort parmi les morts!\n";
|
||||
"Je veux creuser moi-même une fosse profonde,\n" \
|
||||
"Où je puisse à loisir étaler mes vieux os\n" \
|
||||
"Et dormir dans l'oubli comme un requin dans l'onde.\n" \
|
||||
"Je hais les testaments et je hais les tombeaux;\n" \
|
||||
"Plutôt que d'implorer une larme du monde,\n" \
|
||||
"Vivant, j'aimerais mieux inviter les corbeaux\n" \
|
||||
"À saigner tous les bouts de ma carcasse immonde.\n" \
|
||||
"Ô vers! noirs compagnons sans oreille et sans yeux,\n" \
|
||||
"Voyez venir à vous un mort libre et joyeux;\n" \
|
||||
"Philosophes viveurs, fils de la pourriture,\n" \
|
||||
"À travers ma ruine allez donc sans remords,\n" \
|
||||
"Et dites-moi s'il est encor quelque torture\n" \
|
||||
"Pour ce vieux corps sans âme et mort parmi les morts!\n";
|
||||
|
||||
const uint8_t elongdata[665] = "\x07" "\xff\x02\x94" \
|
||||
"Dans une terre grasse et pleine d'escargots\n" \
|
||||
"Je veux creuser moi-même une fosse profonde,\n" \
|
||||
"Où je puisse à loisir étaler mes vieux os\n" \
|
||||
"Et dormir dans l'oubli comme un requin dans l'onde.\n" \
|
||||
"Je hais les testaments et je hais les tombeaux;\n" \
|
||||
"Plutôt que d'implorer une larme du monde,\n" \
|
||||
"Vivant, j'aimerais mieux inviter les corbeaux\n" \
|
||||
"À saigner tous les bouts de ma carcasse immonde.\n" \
|
||||
"Ô vers! noirs compagnons sans oreille et sans yeux,\n" \
|
||||
"Voyez venir à vous un mort libre et joyeux;\n" \
|
||||
"Philosophes viveurs, fils de la pourriture,\n" \
|
||||
"À travers ma ruine allez donc sans remords,\n" \
|
||||
"Et dites-moi s'il est encor quelque torture\n" \
|
||||
"Pour ce vieux corps sans âme et mort parmi les morts!\n"
|
||||
"\xfe";
|
||||
"Dans une terre grasse et pleine d'escargots\n" \
|
||||
"Je veux creuser moi-même une fosse profonde,\n" \
|
||||
"Où je puisse à loisir étaler mes vieux os\n" \
|
||||
"Et dormir dans l'oubli comme un requin dans l'onde.\n" \
|
||||
"Je hais les testaments et je hais les tombeaux;\n" \
|
||||
"Plutôt que d'implorer une larme du monde,\n" \
|
||||
"Vivant, j'aimerais mieux inviter les corbeaux\n" \
|
||||
"À saigner tous les bouts de ma carcasse immonde.\n" \
|
||||
"Ô vers! noirs compagnons sans oreille et sans yeux,\n" \
|
||||
"Voyez venir à vous un mort libre et joyeux;\n" \
|
||||
"Philosophes viveurs, fils de la pourriture,\n" \
|
||||
"À travers ma ruine allez donc sans remords,\n" \
|
||||
"Et dites-moi s'il est encor quelque torture\n" \
|
||||
"Pour ce vieux corps sans âme et mort parmi les morts!\n"
|
||||
"\xfe";
|
||||
|
||||
void
|
||||
test_tlv_encode_short (void)
|
||||
test_tlv_encode_short(void)
|
||||
{
|
||||
uint8_t *res;
|
||||
size_t osize;
|
||||
|
||||
res = tlv_encode (3, shortdata, sizeof (shortdata), &osize);
|
||||
cut_assert_equal_int (sizeof (eshortdata), osize, cut_message ("Wrong encoded message length."));
|
||||
cut_assert_equal_int (3, res[0], cut_message ("Wrong type"));
|
||||
cut_assert_equal_int (sizeof (shortdata), res[1], cut_message ("Wrong value length"));
|
||||
cut_assert_equal_memory (eshortdata, sizeof (eshortdata), res, osize, cut_message ("Wrong encoded value"));
|
||||
free (res);
|
||||
res = tlv_encode(3, shortdata, sizeof(shortdata), &osize);
|
||||
cut_assert_equal_int(sizeof(eshortdata), osize, cut_message("Wrong encoded message length."));
|
||||
cut_assert_equal_int(3, res[0], cut_message("Wrong type"));
|
||||
cut_assert_equal_int(sizeof(shortdata), res[1], cut_message("Wrong value length"));
|
||||
cut_assert_equal_memory(eshortdata, sizeof(eshortdata), res, osize, cut_message("Wrong encoded value"));
|
||||
free(res);
|
||||
}
|
||||
|
||||
void
|
||||
test_tlv_encode_long (void)
|
||||
test_tlv_encode_long(void)
|
||||
{
|
||||
uint8_t *res;
|
||||
size_t osize;
|
||||
|
||||
res = tlv_encode (7, longdata, sizeof (longdata), &osize);
|
||||
cut_assert_equal_int (sizeof (elongdata), osize, cut_message ("Wrong encoded message length."));
|
||||
cut_assert_equal_int (7, res[0], cut_message ("Wrong type"));
|
||||
cut_assert_equal_int (0xff, res[1], cut_message ("Wrong value length"));
|
||||
cut_assert_equal_int (0x02, res[2], cut_message ("Wrong value length"));
|
||||
cut_assert_equal_int (0x94, res[3], cut_message ("Wrong value length"));
|
||||
cut_assert_equal_memory (elongdata, sizeof (elongdata), res, osize, cut_message ("Wrong encoded value"));
|
||||
free (res);
|
||||
res = tlv_encode(7, longdata, sizeof(longdata), &osize);
|
||||
cut_assert_equal_int(sizeof(elongdata), osize, cut_message("Wrong encoded message length."));
|
||||
cut_assert_equal_int(7, res[0], cut_message("Wrong type"));
|
||||
cut_assert_equal_int(0xff, res[1], cut_message("Wrong value length"));
|
||||
cut_assert_equal_int(0x02, res[2], cut_message("Wrong value length"));
|
||||
cut_assert_equal_int(0x94, res[3], cut_message("Wrong value length"));
|
||||
cut_assert_equal_memory(elongdata, sizeof(elongdata), res, osize, cut_message("Wrong encoded value"));
|
||||
free(res);
|
||||
}
|
||||
|
||||
void
|
||||
test_tlv_decode_short (void)
|
||||
test_tlv_decode_short(void)
|
||||
{
|
||||
uint8_t *res;
|
||||
uint16_t size;
|
||||
uint8_t type;
|
||||
|
||||
res = tlv_decode (eshortdata, &type, &size);
|
||||
cut_assert_equal_int (3, type, cut_message ("Wrong type"));
|
||||
cut_assert_equal_int (sizeof (shortdata), size, cut_message ("Wrong value length"));
|
||||
cut_assert_equal_memory (shortdata, sizeof (shortdata), res, size, cut_message ("Wrong decoded value"));
|
||||
free (res);
|
||||
res = tlv_decode(eshortdata, &type, &size);
|
||||
cut_assert_equal_int(3, type, cut_message("Wrong type"));
|
||||
cut_assert_equal_int(sizeof(shortdata), size, cut_message("Wrong value length"));
|
||||
cut_assert_equal_memory(shortdata, sizeof(shortdata), res, size, cut_message("Wrong decoded value"));
|
||||
free(res);
|
||||
}
|
||||
|
||||
void
|
||||
test_tlv_decode_long (void)
|
||||
test_tlv_decode_long(void)
|
||||
{
|
||||
uint8_t *res;
|
||||
uint16_t size;
|
||||
uint8_t type;
|
||||
|
||||
res = tlv_decode (elongdata, &type, &size);
|
||||
cut_assert_equal_int (7, type, cut_message ("Wrong type"));
|
||||
cut_assert_equal_int (sizeof (longdata), size, cut_message ("Wrong value length"));
|
||||
cut_assert_equal_memory (longdata, sizeof (longdata), res, size, cut_message ("Wrong decoded value"));
|
||||
free (res);
|
||||
res = tlv_decode(elongdata, &type, &size);
|
||||
cut_assert_equal_int(7, type, cut_message("Wrong type"));
|
||||
cut_assert_equal_int(sizeof(longdata), size, cut_message("Wrong value length"));
|
||||
cut_assert_equal_memory(longdata, sizeof(longdata), res, size, cut_message("Wrong decoded value"));
|
||||
free(res);
|
||||
}
|
||||
|
||||
void
|
||||
test_tlv_rfu (void)
|
||||
test_tlv_rfu(void)
|
||||
{
|
||||
uint8_t *data = malloc (0xffff);
|
||||
cut_assert_not_null (data, cut_message ("Out of memory"));
|
||||
uint8_t *data = malloc(0xffff);
|
||||
cut_assert_not_null(data, cut_message("Out of memory"));
|
||||
|
||||
uint8_t *res = tlv_encode (7, data, 0xffff, NULL);
|
||||
cut_assert_null (res, cut_message ("Size reserved for future use"));
|
||||
uint8_t *res = tlv_encode(7, data, 0xffff, NULL);
|
||||
cut_assert_null(res, cut_message("Size reserved for future use"));
|
||||
|
||||
free (data);
|
||||
free(data);
|
||||
}
|
||||
|
||||
void
|
||||
test_tlv_append (void)
|
||||
test_tlv_append(void)
|
||||
{
|
||||
const uint8_t a[] = { 0xde, 0xad, 0xbe, 0xef };
|
||||
const uint8_t b[] = { 0x42 };
|
||||
|
||||
uint8_t ndef_ab_ref[] = { 0x03, 0x04, 0xde, 0xad, 0xbe, 0xef, 0x03, 0x01, 0x42, 0xfe };
|
||||
|
||||
uint8_t *ndef_a = tlv_encode (3, a, 4, NULL);
|
||||
uint8_t *ndef_b = tlv_encode (3, b, 1, NULL);
|
||||
ndef_a = tlv_append (ndef_a, ndef_b);
|
||||
cut_assert_equal_memory (ndef_ab_ref, sizeof (ndef_ab_ref), ndef_a, sizeof (ndef_ab_ref), cut_message ("Wrong appended data"));
|
||||
uint8_t *ndef_a = tlv_encode(3, a, 4, NULL);
|
||||
uint8_t *ndef_b = tlv_encode(3, b, 1, NULL);
|
||||
ndef_a = tlv_append(ndef_a, ndef_b);
|
||||
cut_assert_equal_memory(ndef_ab_ref, sizeof(ndef_ab_ref), ndef_a, sizeof(ndef_ab_ref), cut_message("Wrong appended data"));
|
||||
|
||||
free (ndef_a);
|
||||
free (ndef_b);
|
||||
free(ndef_a);
|
||||
free(ndef_b);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue