diff --git a/NEWS b/NEWS index 7c044a6..f25839d 100644 --- a/NEWS +++ b/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. + *) The library reports errors other that the ones returned by the PICC. *) The MDAD_KEYx macro where renamed MDAR_KEYx for consistency. *) The MDCM_MACING macro was renamed MDCM_MACED. *) The MDCM_FULLDES macro was renamed MDCM_ENCIPHERED. diff --git a/libfreefare/freefare.c b/libfreefare/freefare.c index 9952bc7..a7af1f4 100644 --- a/libfreefare/freefare.c +++ b/libfreefare/freefare.c @@ -214,10 +214,17 @@ const char * freefare_strerror (MifareTag tag) { const char *p = "Unkown error"; - if (tag->device->iLastError > 0) + 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); + } else { + if (tag->tag_info->type == DESFIRE) { + if (MIFARE_DESFIRE (tag)->last_pcd_error) { + p = mifare_desfire_error_lookup (MIFARE_DESFIRE (tag)->last_pcd_error); + } else if (MIFARE_DESFIRE (tag)->last_picc_error) { + p = mifare_desfire_error_lookup (MIFARE_DESFIRE (tag)->last_picc_error); + } + } + } return p; } diff --git a/libfreefare/freefare_internal.h b/libfreefare/freefare_internal.h index 9401d80..61192da 100644 --- a/libfreefare/freefare_internal.h +++ b/libfreefare/freefare_internal.h @@ -183,7 +183,7 @@ struct mifare_desfire_tag { struct mifare_tag __tag; uint8_t last_picc_error; - char *last_pcd_error; + uint8_t last_pcd_error; MifareDESFireKey session_key; uint8_t authenticated_key_no; uint8_t ivect[MAX_CRYPTO_BLOCK_SIZE]; diff --git a/libfreefare/mifare_desfire.c b/libfreefare/mifare_desfire.c index 4f03f4b..6bc0fe9 100644 --- a/libfreefare/mifare_desfire.c +++ b/libfreefare/mifare_desfire.c @@ -243,7 +243,7 @@ mifare_desfire_tag_new (void) MifareTag tag; if ((tag= malloc (sizeof (struct mifare_desfire_tag)))) { MIFARE_DESFIRE (tag)->last_picc_error = OPERATION_OK; - MIFARE_DESFIRE (tag)->last_pcd_error = NULL; + MIFARE_DESFIRE (tag)->last_pcd_error = OPERATION_OK; MIFARE_DESFIRE (tag)->session_key = NULL; MIFARE_DESFIRE (tag)->crypto_buffer = NULL; MIFARE_DESFIRE (tag)->crypto_buffer_size = 0; @@ -258,7 +258,6 @@ void mifare_desfire_tag_free (MifareTag tag) { free (MIFARE_DESFIRE (tag)->session_key); - free (MIFARE_DESFIRE (tag)->last_pcd_error); free (MIFARE_DESFIRE (tag)->crypto_buffer); free (tag); } @@ -291,7 +290,7 @@ mifare_desfire_connect (MifareTag tag) free (MIFARE_DESFIRE (tag)->session_key); MIFARE_DESFIRE (tag)->session_key = NULL; MIFARE_DESFIRE (tag)->last_picc_error = OPERATION_OK; - MIFARE_DESFIRE (tag)->last_pcd_error = NULL; + MIFARE_DESFIRE (tag)->last_pcd_error = OPERATION_OK; MIFARE_DESFIRE (tag)->authenticated_key_no = NOT_YET_AUTHENTICATED; MIFARE_DESFIRE (tag)->block_number = 0; } else {