New API function mifare_desfire_last_picc_error().
This commit is contained in:
parent
6790ad9bac
commit
07709c2835
5 changed files with 36 additions and 10 deletions
1
NEWS
1
NEWS
|
@ -3,6 +3,7 @@ Changes between 0.2.0 and 0.2.1 [xx XXX xxxx]
|
|||
*) The mifare_desfire_error_lookup() and mifare_desfire_get_last_error()
|
||||
functions were removed and replaced by the freefare_strerror(),
|
||||
freefare_strerror_r() and freefare_perror() functions.
|
||||
*) New function mifare_desfire_last_picc_error().
|
||||
*) Blok numbers in ISO14443-4 blocks are incremented according to the
|
||||
specification.
|
||||
|
||||
|
|
|
@ -244,6 +244,8 @@ typedef struct mifare_desfire_aid *MifareDESFireAID;
|
|||
MifareDESFireAID mifare_desfire_aid_new (uint32_t aid);
|
||||
MifareDESFireAID mifare_desfire_aid_new_with_mad_aid (MadAid mad_aid, uint8_t n);
|
||||
|
||||
uint8_t mifare_desfire_last_picc_error (MifareTag tag);
|
||||
|
||||
struct mifare_desfire_key;
|
||||
typedef struct mifare_desfire_key *MifareDESFireKey;
|
||||
|
||||
|
|
|
@ -27,7 +27,8 @@
|
|||
.Sh NAME
|
||||
.Nm freefare_strerror ,
|
||||
.Nm freefare_strerror_r ,
|
||||
.Nm freefare_perror
|
||||
.Nm freefare_perror ,
|
||||
.Nm mifare_desfire_last_picc_error
|
||||
.Nd Error Reporting Functions.
|
||||
.\" _ _ _
|
||||
.\" | | (_) |__ _ __ __ _ _ __ _ _
|
||||
|
@ -51,6 +52,8 @@ Mifare card manipulation library (libfreefare, \-lfreefare)
|
|||
.Fn freefare_strerror_r "MifareTag tag" "char *buffer" "size_t len"
|
||||
.Ft "void"
|
||||
.Fn freefare_strerror "MifareTag tag" "char *string"
|
||||
.Ft uint8_t
|
||||
.Fm mifare_desfire_last_picc_error "MifareTag tag"
|
||||
.\" ____ _ _ _
|
||||
.\" | _ \ ___ ___ ___ _ __(_)_ __ | |_(_) ___ _ __
|
||||
.\" | | | |/ _ \/ __|/ __| '__| | '_ \| __| |/ _ \| '_ \
|
||||
|
@ -79,6 +82,11 @@ The
|
|||
function displays the last PCD or PICC error encounred using
|
||||
.Vt tag
|
||||
to stderr.
|
||||
.Pp
|
||||
The
|
||||
.Fn mifare_desfire_last_picc_error
|
||||
function returns the error code returned by the last command run on
|
||||
.Vt tag .
|
||||
.\" ____ _ _
|
||||
.\" | _ \ ___| |_ _ _ _ __ _ __ __ ____ _| |_ _ ___ ___
|
||||
.\" | |_) / _ \ __| | | | '__| '_ \ \ \ / / _` | | | | |/ _ \/ __|
|
||||
|
@ -87,9 +95,13 @@ to stderr.
|
|||
.\"
|
||||
.Sh RETURN VALUES
|
||||
.Fn freefare_strerror
|
||||
returns the error message, while
|
||||
returns the error message,
|
||||
.Fn freefare_strerror_r
|
||||
returns 0 on success, -1 on failure.
|
||||
returns 0 on success, -1 on failure, and
|
||||
.Fn mifare_desfire_last_picc_error
|
||||
returns an error code or 0 if no error is known or
|
||||
.Vt tag
|
||||
is not a Mifare DESFire target.
|
||||
.\" ____ _
|
||||
.\" / ___| ___ ___ __ _| |___ ___
|
||||
.\" \___ \ / _ \/ _ \ / _` | / __|/ _ \
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
#include <freefare.h>
|
||||
|
||||
#include "freefare_internal.h"
|
||||
|
||||
#define EM(e) { e, #e }
|
||||
|
||||
static struct error_message {
|
||||
|
@ -67,3 +69,12 @@ mifare_desfire_error_lookup (uint8_t code)
|
|||
|
||||
return "Invalid error code";
|
||||
}
|
||||
|
||||
uint8_t
|
||||
mifare_desfire_last_picc_error (MifareTag tag)
|
||||
{
|
||||
if (tag->tag_info->type != DESFIRE)
|
||||
return 0;
|
||||
|
||||
return MIFARE_DESFIRE (tag)->last_picc_error;
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ uint8_t key_data_3des[16] = { 'C', 'a', 'r', 'd', ' ', 'M', 'a', 's', 't', 'e',
|
|||
|
||||
#define cut_assert_success(last_command) \
|
||||
do { \
|
||||
if ((res < 0) || (MIFARE_DESFIRE (tag)->last_picc_error != OPERATION_OK)) { \
|
||||
cut_fail ("%s returned %d, error: %s, errno: %s\n", last_command, res, mifare_desfire_error_lookup (MIFARE_DESFIRE (tag)->last_picc_error), strerror (errno)); \
|
||||
if ((res < 0) || (mifare_desfire_last_picc_error (tag) != OPERATION_OK)) { \
|
||||
cut_fail ("%s returned %d, error: %s, errno: %s\n", last_command, res, mifare_desfire_error_lookup (mifare_desfire_last_picc_error (tag)), strerror (errno)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
@ -197,7 +197,7 @@ test_mifare_desfire (void)
|
|||
// Try to overwrute the file
|
||||
res = mifare_desfire_write_data (tag, std_data_file_id, 20, 5, (char *)"Test!");
|
||||
cut_assert_equal_int (-1, res, cut_message ("Wrong return value"));
|
||||
cut_assert_equal_int (PERMISSION_ERROR, MIFARE_DESFIRE (tag)->last_picc_error, cut_message ("Wrong PICC error"));
|
||||
cut_assert_equal_int (PERMISSION_ERROR, mifare_desfire_last_picc_error (tag), cut_message ("Wrong PICC error"));
|
||||
|
||||
int32_t expected_value = 0;
|
||||
for (int transaction = 0; transaction < 15; transaction++) {
|
||||
|
@ -507,7 +507,7 @@ test_mifare_desfire (void)
|
|||
sprintf (data_buffer3, "Test invalid write");
|
||||
res = mifare_desfire_write_record (tag, 1, 0, strlen (data_buffer3), data_buffer3);
|
||||
cut_assert_equal_int (-1, res, cut_message ("error code"));
|
||||
cut_assert_equal_int (PERMISSION_ERROR, MIFARE_DESFIRE (tag)->last_picc_error, cut_message ("PICC error"));
|
||||
cut_assert_equal_int (PERMISSION_ERROR, mifare_desfire_last_picc_error (tag), cut_message ("PICC error"));
|
||||
|
||||
// The prebious failure has aborted the transaction, so clear
|
||||
// record again.
|
||||
|
@ -798,18 +798,18 @@ test_mifare_desfire (void)
|
|||
/* We should not be able to list applications now */
|
||||
res = mifare_desfire_get_application_ids (tag, &aids, &aid_count);
|
||||
cut_assert_equal_int (-1, res, cut_message ("Wrong return value"));
|
||||
cut_assert_equal_int (AUTHENTICATION_ERROR, MIFARE_DESFIRE (tag)->last_picc_error, cut_message ("Wrong PICC error"));
|
||||
cut_assert_equal_int (AUTHENTICATION_ERROR, mifare_desfire_last_picc_error (tag), cut_message ("Wrong PICC error"));
|
||||
|
||||
/* Deleting an application should not be possible */
|
||||
res = mifare_desfire_delete_application (tag, aid_c);
|
||||
cut_assert_equal_int (-1, res, cut_message ("Wrong return value"));
|
||||
cut_assert_equal_int (AUTHENTICATION_ERROR, MIFARE_DESFIRE (tag)->last_picc_error, cut_message ("Wrong PICC error"));
|
||||
cut_assert_equal_int (AUTHENTICATION_ERROR, mifare_desfire_last_picc_error (tag), cut_message ("Wrong PICC error"));
|
||||
|
||||
/* Creating an application should also be forbidden */
|
||||
MifareDESFireAID aid_d = mifare_desfire_aid_new (0x00DDDDDD);
|
||||
res = mifare_desfire_create_application (tag, aid_d, 0xEF, 0);
|
||||
cut_assert_equal_int (-1, res, cut_message ("Wrong return value"));
|
||||
cut_assert_equal_int (AUTHENTICATION_ERROR, MIFARE_DESFIRE (tag)->last_picc_error, cut_message ("Wrong PICC error"));
|
||||
cut_assert_equal_int (AUTHENTICATION_ERROR, mifare_desfire_last_picc_error (tag), cut_message ("Wrong PICC error"));
|
||||
|
||||
/*
|
||||
* Now we retry authenticated with the master key.
|
||||
|
|
Loading…
Reference in a new issue