绿萝瀑布 2022-11-21 11:07 采纳率: 100%
浏览 52
已结题

使用PN5180读取mifare class 1k 验证失败:Authentication Failed

使用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
麻烦帮忙看一下问题出在什么地方了,万分感谢!!

  • 写回答

1条回答 默认 最新

  • 觉皇嵌入式 嵌入式领域优质创作者 2022-11-21 12:21
    关注

    这是认证时候的校验问题,我的最新代码已经成功读写,开源代码见:https://gitee.com/jhuangBTT/HAL_STM32_PN5180_SPI_DEMO,能帮助到你的话我的CSDN点个关注,谢谢。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 3月28日
  • 已采纳回答 3月20日
  • 创建了问题 11月21日

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失