Enhance error reporting.
Now that the libnfc has error handling, report errors triggered in the libnfc and add support for errors triggered in libfreefare.
This commit is contained in:
parent
18982d360f
commit
9a2a07ea53
9 changed files with 73 additions and 28 deletions
3
NEWS
3
NEWS
|
@ -1,5 +1,8 @@
|
||||||
Changes between 0.2.0 and 0.2.1 [xx XXX xxxx]
|
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.
|
||||||
*) Blok numbers in ISO14443-4 blocks are incremented according to the
|
*) Blok numbers in ISO14443-4 blocks are incremented according to the
|
||||||
specification.
|
specification.
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
res = mifare_desfire_get_version (tags[i], &info);
|
res = mifare_desfire_get_version (tags[i], &info);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
warnx ("Can't get Mifare DESFire version information.");
|
freefare_perror (tags[i], "mifare_desfire_get_version");
|
||||||
error = 1;
|
error = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ main(int argc, char *argv[])
|
||||||
uint8_t max_keys;
|
uint8_t max_keys;
|
||||||
res = mifare_desfire_get_key_settings (tags[i], &settings, &max_keys);
|
res = mifare_desfire_get_key_settings (tags[i], &settings, &max_keys);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
warnx ("Cant' get Mifare DESFire Master Key settings: %s", mifare_desfire_error_lookup (mifare_desfire_get_last_error (tags[i])));
|
freefare_perror (tags[i], "mifare_desfire_get_key_settings");
|
||||||
error = 1;
|
error = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,12 +32,12 @@ libfreefare_la_HEADERS = freefare.h
|
||||||
libfreefare_ladir = $(includedir)
|
libfreefare_ladir = $(includedir)
|
||||||
|
|
||||||
man_MANS = freefare.3 \
|
man_MANS = freefare.3 \
|
||||||
|
freefare_error.3 \
|
||||||
mad.3 \
|
mad.3 \
|
||||||
mifare_application.3 \
|
mifare_application.3 \
|
||||||
mifare_classic.3 \
|
mifare_classic.3 \
|
||||||
mifare_desfire.3 \
|
mifare_desfire.3 \
|
||||||
mifare_desfire_aid.3 \
|
mifare_desfire_aid.3 \
|
||||||
mifare_desfire_error.3 \
|
|
||||||
mifare_desfire_key.3 \
|
mifare_desfire_key.3 \
|
||||||
mifare_ultralight.3 \
|
mifare_ultralight.3 \
|
||||||
tlv.3
|
tlv.3
|
||||||
|
@ -48,6 +48,9 @@ linkedman = \
|
||||||
freefare.3 freefare_get_tag_type.3 \
|
freefare.3 freefare_get_tag_type.3 \
|
||||||
freefare.3 freefare_get_tag_uid.3 \
|
freefare.3 freefare_get_tag_uid.3 \
|
||||||
freefare.3 freefare_get_tags.3 \
|
freefare.3 freefare_get_tags.3 \
|
||||||
|
freefare_error.3 freefare_strerror.3 \
|
||||||
|
freefare_error.3 freefare_strerror_r.3 \
|
||||||
|
freefare_error.3 freefare_perror.3 \
|
||||||
mad.3 mad_free.3 \
|
mad.3 mad_free.3 \
|
||||||
mad.3 mad_get_aid.3 \
|
mad.3 mad_get_aid.3 \
|
||||||
mad.3 mad_get_card_publisher_sector.3 \
|
mad.3 mad_get_card_publisher_sector.3 \
|
||||||
|
@ -123,7 +126,6 @@ linkedman = \
|
||||||
mifare_desfire.3 mifare_desfire_write_record_ex.3 \
|
mifare_desfire.3 mifare_desfire_write_record_ex.3 \
|
||||||
mifare_desfire_aid.3 mifare_desfire_aid_new.3 \
|
mifare_desfire_aid.3 mifare_desfire_aid_new.3 \
|
||||||
mifare_desfire_aid.3 mifare_desfire_aid_new_with_mad_aid.3 \
|
mifare_desfire_aid.3 mifare_desfire_aid_new_with_mad_aid.3 \
|
||||||
mifare_desfire_error.3 mifare_desfire_error_lookup.3 \
|
|
||||||
mifare_desfire_key.3 mifare_desfire_3des_key_new.3 \
|
mifare_desfire_key.3 mifare_desfire_3des_key_new.3 \
|
||||||
mifare_desfire_key.3 mifare_desfire_3des_key_new_with_version.3 \
|
mifare_desfire_key.3 mifare_desfire_3des_key_new_with_version.3 \
|
||||||
mifare_desfire_key.3 mifare_desfire_des_key_new.3 \
|
mifare_desfire_key.3 mifare_desfire_des_key_new.3 \
|
||||||
|
|
|
@ -203,6 +203,30 @@ freefare_free_tag (MifareTag tag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
freefare_strerror (MifareTag tag)
|
||||||
|
{
|
||||||
|
const char *p = "Unkown error";
|
||||||
|
if (tag->device->iLastError > 0)
|
||||||
|
p = nfc_strerror (tag->device);
|
||||||
|
else if (tag->tag_info->type == DESFIRE)
|
||||||
|
p = mifare_desfire_error_lookup (MIFARE_DESFIRE (tag)->last_picc_error);
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
freefare_strerror_r (MifareTag tag, char *buffer, size_t len)
|
||||||
|
{
|
||||||
|
return (snprintf (buffer, len, "%s", freefare_strerror (tag)) < 0) ? -1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
freefare_perror (MifareTag tag, const char *string)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s: %s\n", string, freefare_strerror (tag));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Free the provided tag list.
|
* Free the provided tag list.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -56,6 +56,10 @@ char *freefare_get_tag_uid (MifareTag tag);
|
||||||
void freefare_free_tag (MifareTag tag);
|
void freefare_free_tag (MifareTag tag);
|
||||||
void freefare_free_tags (MifareTag *tags);
|
void freefare_free_tags (MifareTag *tags);
|
||||||
|
|
||||||
|
const char *freefare_strerror (MifareTag tag);
|
||||||
|
int freefare_strerror_r (MifareTag tag, char *buffer, size_t len);
|
||||||
|
void freefare_perror (MifareTag tag, const char *string);
|
||||||
|
|
||||||
int mifare_ultralight_connect (MifareTag tag);
|
int mifare_ultralight_connect (MifareTag tag);
|
||||||
int mifare_ultralight_disconnect (MifareTag tag);
|
int mifare_ultralight_disconnect (MifareTag tag);
|
||||||
|
|
||||||
|
@ -295,7 +299,6 @@ struct mifare_desfire_file_settings {
|
||||||
|
|
||||||
int mifare_desfire_connect (MifareTag tag);
|
int mifare_desfire_connect (MifareTag tag);
|
||||||
int mifare_desfire_disconnect (MifareTag tag);
|
int mifare_desfire_disconnect (MifareTag tag);
|
||||||
uint8_t mifare_desfire_get_last_error (MifareTag tag);
|
|
||||||
|
|
||||||
int mifare_desfire_authenticate (MifareTag tag, uint8_t key_no, MifareDESFireKey key);
|
int mifare_desfire_authenticate (MifareTag tag, uint8_t key_no, MifareDESFireKey key);
|
||||||
int mifare_desfire_change_key_settings (MifareTag tag, uint8_t settings);
|
int mifare_desfire_change_key_settings (MifareTag tag, uint8_t settings);
|
||||||
|
@ -347,8 +350,6 @@ uint8_t mifare_desfire_key_get_version (MifareDESFireKey key);
|
||||||
void mifare_desfire_key_set_version (MifareDESFireKey key, uint8_t version);
|
void mifare_desfire_key_set_version (MifareDESFireKey key, uint8_t version);
|
||||||
void mifare_desfire_key_free (MifareDESFireKey key);
|
void mifare_desfire_key_free (MifareDESFireKey key);
|
||||||
|
|
||||||
const char *mifare_desfire_error_lookup (uint8_t error);
|
|
||||||
|
|
||||||
uint8_t *tlv_encode (const uint8_t type, const uint8_t *istream, uint16_t isize, size_t *osize);
|
uint8_t *tlv_encode (const uint8_t type, const uint8_t *istream, uint16_t isize, size_t *osize);
|
||||||
uint8_t *tlv_decode (const uint8_t *istream, uint8_t *type, uint16_t *size);
|
uint8_t *tlv_decode (const uint8_t *istream, uint8_t *type, uint16_t *size);
|
||||||
uint8_t *tlv_append (uint8_t *a, uint8_t *b);
|
uint8_t *tlv_append (uint8_t *a, uint8_t *b);
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
.\"
|
.\"
|
||||||
.\" $Id: mifare_desfire.3 495 2010-07-26 21:48:18Z rtartiere@il4p.fr $
|
.\" $Id: mifare_desfire.3 495 2010-07-26 21:48:18Z rtartiere@il4p.fr $
|
||||||
.\"
|
.\"
|
||||||
.Dd September 3, 2010
|
.Dd September 28, 2010
|
||||||
.Dt MIFARE_DESFIRE_ERROR 3
|
.Dt FREEFARE_ERROR 3
|
||||||
.Os
|
.Os
|
||||||
.\" _ _
|
.\" _ _
|
||||||
.\" | \ | | __ _ _ __ ___ ___
|
.\" | \ | | __ _ _ __ ___ ___
|
||||||
|
@ -25,8 +25,10 @@
|
||||||
.\" |_| \_|\__,_|_| |_| |_|\___|
|
.\" |_| \_|\__,_|_| |_| |_|\___|
|
||||||
.\"
|
.\"
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm mifare_desfire_error_lookup
|
.Nm freefare_strerror ,
|
||||||
.Nd Mifare DESFire Error Management Functions.
|
.Nm freefare_strerror_r ,
|
||||||
|
.Nm freefare_perror
|
||||||
|
.Nd Error Reporting Functions.
|
||||||
.\" _ _ _
|
.\" _ _ _
|
||||||
.\" | | (_) |__ _ __ __ _ _ __ _ _
|
.\" | | (_) |__ _ __ __ _ _ __ _ _
|
||||||
.\" | | | | '_ \| '__/ _` | '__| | | |
|
.\" | | | | '_ \| '__/ _` | '__| | | |
|
||||||
|
@ -44,7 +46,11 @@ Mifare card manipulation library (libfreefare, \-lfreefare)
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In freefare.h
|
.In freefare.h
|
||||||
.Ft "const char *"
|
.Ft "const char *"
|
||||||
.Fn mifare_desfire_error_lookup "uint8_t code"
|
.Fn freefare_strerror "MifareTag tag"
|
||||||
|
.Ft "int"
|
||||||
|
.Fn freefare_strerror_r "MifareTag tag" "char *buffer" "size_t len"
|
||||||
|
.Ft "void"
|
||||||
|
.Fn freefare_strerror "MifareTag tag" "char *string"
|
||||||
.\" ____ _ _ _
|
.\" ____ _ _ _
|
||||||
.\" | _ \ ___ ___ ___ _ __(_)_ __ | |_(_) ___ _ __
|
.\" | _ \ ___ ___ ___ _ __(_)_ __ | |_(_) ___ _ __
|
||||||
.\" | | | |/ _ \/ __|/ __| '__| | '_ \| __| |/ _ \| '_ \
|
.\" | | | |/ _ \/ __|/ __| '__| | '_ \| __| |/ _ \| '_ \
|
||||||
|
@ -53,9 +59,26 @@ Mifare card manipulation library (libfreefare, \-lfreefare)
|
||||||
.\" |_|
|
.\" |_|
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
.Fn mifare_desfire_error_lookup
|
.Fn freefare_strerror
|
||||||
functions returns the error string corresponding to the provided error
|
functions returns the error string corresponding to the last PCD or PICC error
|
||||||
.Vt code .
|
encounred using
|
||||||
|
.Vt tag .
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn freefare_strerror_r
|
||||||
|
functions does the same as
|
||||||
|
.Fn freefare_strerror
|
||||||
|
but the error message is copied into
|
||||||
|
.Vt buffer
|
||||||
|
for a maximum size of
|
||||||
|
.Vt len
|
||||||
|
chars.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn freefare_strerror
|
||||||
|
function displays the last PCD or PICC error encounred using
|
||||||
|
.Vt tag
|
||||||
|
to stderr.
|
||||||
.\" ____ _ _
|
.\" ____ _ _
|
||||||
.\" | _ \ ___| |_ _ _ _ __ _ __ __ ____ _| |_ _ ___ ___
|
.\" | _ \ ___| |_ _ _ _ __ _ __ __ ____ _| |_ _ ___ ___
|
||||||
.\" | |_) / _ \ __| | | | '__| '_ \ \ \ / / _` | | | | |/ _ \/ __|
|
.\" | |_) / _ \ __| | | | '__| '_ \ \ \ / / _` | | | | |/ _ \/ __|
|
||||||
|
@ -63,8 +86,10 @@ functions returns the error string corresponding to the provided error
|
||||||
.\" |_| \_\___|\__|\__,_|_| |_| |_| \_/ \__,_|_|\__,_|\___||___/
|
.\" |_| \_\___|\__|\__,_|_| |_| |_| \_/ \__,_|_|\__,_|\___||___/
|
||||||
.\"
|
.\"
|
||||||
.Sh RETURN VALUES
|
.Sh RETURN VALUES
|
||||||
The functions always succeeds. If an invalid error code is provided, a
|
.Fn freefare_strerror
|
||||||
corresponding message is returned.
|
returns the error message, while
|
||||||
|
.Fn freefare_strerror_r
|
||||||
|
returns 0 on success, -1 on failure.
|
||||||
.\" ____ _
|
.\" ____ _
|
||||||
.\" / ___| ___ ___ __ _| |___ ___
|
.\" / ___| ___ ___ __ _| |___ ___
|
||||||
.\" \___ \ / _ \/ _ \ / _` | / __|/ _ \
|
.\" \___ \ / _ \/ _ \ / _` | / __|/ _ \
|
||||||
|
@ -73,7 +98,6 @@ corresponding message is returned.
|
||||||
.\"
|
.\"
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr freefare 3 ,
|
.Xr freefare 3 ,
|
||||||
.Xr mifare_desfire 3
|
|
||||||
.\" _ _ _
|
.\" _ _ _
|
||||||
.\" / \ _ _| |_| |__ ___ _ __ ___
|
.\" / \ _ _| |_| |__ ___ _ __ ___
|
||||||
.\" / _ \| | | | __| '_ \ / _ \| '__/ __|
|
.\" / _ \| | | | __| '_ \ / _ \| '__/ __|
|
|
@ -189,6 +189,7 @@ struct mifare_desfire_tag {
|
||||||
};
|
};
|
||||||
|
|
||||||
MifareDESFireKey mifare_desfire_session_key_new (uint8_t rnda[8], uint8_t rndb[8], MifareDESFireKey authentication_key);
|
MifareDESFireKey mifare_desfire_session_key_new (uint8_t rnda[8], uint8_t rndb[8], MifareDESFireKey authentication_key);
|
||||||
|
const char *mifare_desfire_error_lookup (uint8_t error);
|
||||||
|
|
||||||
struct mifare_ultralight_tag {
|
struct mifare_ultralight_tag {
|
||||||
struct mifare_tag __tag;
|
struct mifare_tag __tag;
|
||||||
|
|
|
@ -94,8 +94,6 @@ Mifare card manipulation library (libfreefare, \-lfreefare)
|
||||||
.Fn mifare_desfire_connect "MifareTag tag"
|
.Fn mifare_desfire_connect "MifareTag tag"
|
||||||
.Ft int
|
.Ft int
|
||||||
.Fn mifare_desfire_disconnect "MifareTag tag"
|
.Fn mifare_desfire_disconnect "MifareTag tag"
|
||||||
.\".Ft uint8_t
|
|
||||||
.\".Fn mifare_desfire_get_last_error "MifareTag tag"
|
|
||||||
.Ft int
|
.Ft int
|
||||||
.Fn mifare_desfire_authenticate "MifareTag tag" "uint8_t key_no" "MifareDESFireKey key"
|
.Fn mifare_desfire_authenticate "MifareTag tag" "uint8_t key_no" "MifareDESFireKey key"
|
||||||
.Ft int
|
.Ft int
|
||||||
|
|
|
@ -338,14 +338,6 @@ mifare_desfire_disconnect (MifareTag tag)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t
|
|
||||||
mifare_desfire_get_last_error (MifareTag tag)
|
|
||||||
{
|
|
||||||
return MIFARE_DESFIRE (tag)->last_picc_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
mifare_desfire_authenticate (MifareTag tag, uint8_t key_no, MifareDESFireKey key)
|
mifare_desfire_authenticate (MifareTag tag, uint8_t key_no, MifareDESFireKey key)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue