RC522默认键

时间:2016-08-05 09:00:08

标签: c microcontroller stm32 rfid

我在验证我的mifare卡时遇到问题。在数据表中写入默认密钥为0xFFFFFFFFFFFF但它不起作用。如果有人可以帮助我,我不知道出了什么问题。

这是我的代码,我想补充一点,检查卡是正确的,并且工作正常。

main.c中:

    #include "spi.h"
    #include <stdio.h>
    #include "oldrc522.h"


    int main(void) {

    uint8_t CARD_ID[5];

    uint8_t KEY[6]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
    uint8_t MY_CARD[5]={0x19,0x5a,0xcc,0xac,0x23};

    TM_MFRC522_Init();
    printf("INIT\n\n\n");

    while(1){

    if (TM_MFRC522_Check(CARD_ID) == MI_OK) {
                //CardID is valid

                //Check if this is my card
                if (TM_MFRC522_Compare(CARD_ID, MY_CARD) == MI_OK) {
                   printf("HELLO!\n\n");

                   if( (TM_MFRC522_Auth(PICC_AUTHENT1A,7,KEY,MY_CARD) == MI_OK))
                       printf("OK");
                   else printf("FAILED\n\n");



                } else
                    printf("INVALID CARD\n\n");


            } else {
                //Some printing to delete content
            }

    }
}

TM_MFRC522_Auth功能:

    TM_MFRC522_Status_t TM_MFRC522_Auth(uint8_t authMode, uint8_t BlockAddr, uint8_t* Sectorkey, uint8_t* serNum) {
    TM_MFRC522_Status_t status;
    uint16_t recvBits;
    uint8_t i;
    uint8_t buff[12];

    //Verify the command block address + sector + password + card serial number
    buff[0] = authMode;
    buff[1] = BlockAddr;
    for (i = 0; i < 6; i++) {
        buff[i+2] = Sectorkey[i];
    }
    for (i=0; i<4; i++) {
        buff[i+8] = serNum[i];
    }
    status = TM_MFRC522_ToCard(PCD_AUTHENT, buff, 12, buff, &recvBits);

    if ((status != MI_OK) || (!(TM_MFRC522_ReadRegister(MFRC522_REG_STATUS2) & 0x08))) {
        status = MI_ERR;
    }

    return status;
}

1 个答案:

答案 0 :(得分:0)

RFID卡的生产商通常使用6字节的0xFF或0x00作为产品的默认密钥。

我没有像rc522那样使用这些库,但试图传递这个

char keyA [6] = {0xFF,0xFf,0xFF,0xFF,0xFF,0xFF,}; 进行身份验证。

请注意,如果您在通行证扇区中写了其他内容,则说明您的卡已损坏。