以下是密鑰驗證代碼:
status=Authentication(UID,0,TYPEA_MODE);////驗證0扇區keyA
/****************************************************************/
/*名稱: Authentication */
/*功能: 該函式實作密碼認證的程序 */
/*輸入: UID: 卡片序列號地址 */
/* SecNR: 扇區號 */
/* mode: 模式 */
/*輸出: FM1715_NOTAGERR: 無卡 */
/* FM1715_PARITYERR: 奇偶校驗錯 */
/* FM1715_CRCERR: CRC校驗錯 */
/* FM1715_OK: 應答正確 */
/* FM1715_AUTHERR: 權威認證有錯 */
/****************************************************************/
uchar Authentication(uchar idata *UID,uchar SecNR,uchar mode)
{
uchar idata i;
uchar idata temp,temp1;
CRCPresetLSB = 0x63;
CRCPresetLSB = 0x63;
CWConductance = 0x3f;
ModConductance = 0x3f;
temp1 = Control;
temp1 = temp1 & 0xf7;
Control = temp1;
if (mode == 1) //AUTHENT1
buffer[0] = RF_CMD_AUTH_LB; //61
else
buffer[0] = RF_CMD_AUTH_LA; //60
buffer[1] = SecNR * 4 + 3;
for (i = 0; i < 4; i++)
{
buffer[2 + i] = UID[i];
}
ChannelRedundancy = 0x0f; //開啟CRC,奇偶校驗校驗
temp = Command_Send(6, buffer, Authent1);
if (temp == FALSE)
{
return FM1715_NOTAGERR;
}
temp = ErrorFlag;
if ((temp & 0x02) == 0x02)
return FM1715_PARITYERR;
if((temp & 0x04) == 0x04)
return FM1715_FRAMINGERR;
if ((temp & 0x08) == 0x08)
return FM1715_CRCERR;
temp = Command_Send(0, buffer, Authent2); //AUTHENT2
if(temp == FALSE)
{
return FM1715_NOTAGERR;
}
temp = ErrorFlag;
if ((temp & 0x02) == 0x02)
return FM1715_PARITYERR;
if((temp & 0x04) == 0x04)
return FM1715_FRAMINGERR;
if ((temp & 0x08) == 0x08)
return FM1715_CRCERR;
temp1 = Control;
temp1 = temp1 & 0x08; //Crypto1on=1驗證通過
if (temp1 == 0x08)
{
return FM1715_OK;
}
return FM1715_AUTHERR;
}
目前就是密鑰驗證一直不行,試過CL1前4位元組和CL2前4位元組UID驗證都不行,那位大神能不能給指點一下?
uj5u.com熱心網友回復:
你要先確認你卡片是否是出廠設定,如果是就是后4位元組;轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/143231.html
標籤:單片機/工控
上一篇:大佬們,求助
