Reputation: 35
I have a problem with authenticate my mifare card. In datasheet is written that default key is 0xFFFFFFFFFFFF
but it doesn't work. I don't have any idea what is wrong, if someone could help me.
Here is my code and I want to add that checking card is correct and works fine.
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 function:
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;
}
Upvotes: 0
Views: 819
Reputation: 2812
It is common that producer of RFID card uses 6 bytes of 0xFF or 0x00 as default key of the product.
I have not used these libraries as with rc522 but try to pass this
char keyA[6] = { 0xFF, 0xFf, 0xFF, 0xFF, 0xFF, 0xFF, }; to authenticate.
Note that if you write something else in pass sectors you have corrupted the card.
Upvotes: 1