使用PN5180读取mifare class 1k 验证失败:Authentication Failed!!!
使用nxp官网的库中的NfcrdlibEx4_MIFAREClassic这个demo ,UID是可以读出来的,但是就是认证失败:Authentication Failed!!!
demo中的代码如下:
/* Check for MIFARE Classic */
if (0x08 == (pDiscLoop->sTypeATargetInfo.aTypeA_I3P3[0].aSak & 0x08))
{
do
{
/* Print UID */
DEBUG_PRINTF ("\nUID: ");
phApp_Print_Buff(pDiscLoop->sTypeATargetInfo.aTypeA_I3P3[0].aUid,
pDiscLoop->sTypeATargetInfo.aTypeA_I3P3[0].bUidSize);
/* Print ATQA and SAK */
DEBUG_PRINTF("\nATQA:");
phApp_Print_Buff(pDiscLoop->sTypeATargetInfo.aTypeA_I3P3[0].aAtqa, 2);
DEBUG_PRINTF ("\nSAK: 0x%x",pDiscLoop->sTypeATargetInfo.aTypeA_I3P3[0].aSak);
/* Print Product type */
DEBUG_PRINTF("\nProduct: MIFARE Classic \n");
bUidSize = pDiscLoop->sTypeATargetInfo.aTypeA_I3P3[0].bUidSize;
memcpy(bUid, pDiscLoop->sTypeATargetInfo.aTypeA_I3P3[0].aUid, bUidSize);
/* Authenticate with the Key
* We can authenticate at any block of a sector and we will get the access to all blocks of the same sector
* For example authenticating at block 5, we will get the access to blocks 4, 5, 6 and 7.
*/
/* Send authentication for block 6 */
status = phalMfc_Authenticate(psalMFC, 6, PHHAL_HW_MFC_KEYA, 1, 0, bUid, bUidSize);
/* Check for Status */
if ((status & PH_ERR_MASK) != PH_ERR_SUCCESS)
{
/* Print Error info */
DEBUG_PRINTF("\nAuthentication Failed!!!");
DEBUG_PRINTF("\nPlease correct the used key");
DEBUG_PRINTF("\nExecution aborted!!!\n");
break;
}
通过log可以看出,输入的信息是没有问题的:
Ready to detect
UID: E4 EC 4B 52
ATQA: 04 00
SAK: 0x8
Product: MIFARE Classic
phalMfc_Sw_Authenticate:97
phalMfc_Sw_Authenticate:134
phhalHw_Pn5180_MfcAuthenticate:2456
aCmdBuffer[0]:c
aCmdBuffer[1]:ff
aCmdBuffer[2]:ff
aCmdBuffer[3]:ff
aCmdBuffer[4]:ff
aCmdBuffer[5]:ff
aCmdBuffer[6]:ff
aCmdBuffer[7]:60
aCmdBuffer[8]:6
aCmdBuffer[9]:e4
aCmdBuffer[10]:ec
aCmdBuffer[11]:4b
aCmdBuffer[12]:52
aRspBuffer:ff
phhalHw_Pn5180_Instr_MifareAuthenticate:1158
Authentication Failed!
Please correct the used key
Execution aborted!
Please Remove the Card
麻烦帮忙看一下问题出在什么地方了,万分感谢!!