|
发表于 2011-9-20 12:44:28
|
显示全部楼层
/* 函数错误代码定义 ERR CODE */
#define FM1702_OK 0 /* 正确 */
#define FM1702_NOTAGERR 1 /* 无卡 */
#define FM1702_CRCERR 2 /* 卡片CRC校验错误 */
#define FM1702_EMPTY 3 /* 数值溢出错误 */
#define FM1702_AUTHERR 4 /* 验证不成功 */
#define FM1702_PARITYERR 5 /* 卡片奇偶校验错误 */
#define FM1702_CODEERR 6 /* 通讯错误(BCC校验错) */
#define FM1702_SERNRERR 8 /* 卡片序列号错误(anti-collision 错误) */
#define FM1702_SELECTERR 9 /* 卡片数据长度字节错误(SELECT错误) */
#define FM1702_NOTAUTHERR 10 /* 卡片没有通过验证 */
#define FM1702_BITCOUNTERR 11 /* 从卡片接收到的位数错误 */
#define FM1702_BYTECOUNTERR 12 /* 从卡片接收到的字节数错误仅读函数有效 */
#define FM1702_RESTERR 13 /* 调用restore函数出错 */
#define FM1702_TRANSERR 14 /* 调用transfer函数出错 */
#define FM1702_WRITEERR 15 /* 调用write函数出错 */
#define FM1702_INCRERR 16 /* 调用increment函数出错 */
#define FM1702_DECRERR 17 /* 调用decrement函数出错 */
#define FM1702_READERR 18 /* 调用read函数出错 */
#define FM1702_LOADKEYERR 19 /* 调用LOADKEY函数出错 */
#define FM1702_FRAMINGERR 20 /* FM1702帧错误 */
#define FM1702_REQERR 21 /* 调用req函数出错 */
#define FM1702_SELERR 22 /* 调用sel函数出错 */
#define FM1702_ANTICOLLERR 23 /* 调用anticoll函数出错 */
#define FM1702_INTIVALERR 24 /* 调用初始化函数出错 */
#define FM1702_READVALERR 25 /* 调用高级读块值函数出错 */
#define FM1702_DESELECTERR 26
#define FM1702_CMD_ERR 42 /* 命令错误 */
/****************************************************************/
/*名称: Authentication */
/*功能: 该函数实现密码认证的过程*/
/*输入: UID: 卡片序列号地址*/
/* SecNR: 扇区号*/
/* mode: 模式*/
/*输出: FM1702_NOTAGERR: 无卡*/
/* FM1702_PARITYERR: 奇偶校验错*/
/* FM1702_CRCERR: CRC校验错*/
/* FM1702_OK: 应答正确*/
/* FM1702_AUTHERR: 权威认证有错*/
/****************************************************************/
uchar Authentication(uchar idata *UID, uchar SecNR, uchar mode)
{
uchar idata i;
uchar idata temp, temp1;
uchar temp0;
if(SecNR >= 0x20)
{
temp0 = SecNR -0x20;
SecNR = 0x20 + temp0 * 4;
}
SPIWrite(CRCPresetLSB,0x63);
SPIWrite(CWConductance,0x3f);
// SPIWrite(ModConductance,0X3f);
// temp1 = SPIRead(Control);
// temp1 = temp1 & 0xf7;
// SPIWrite(Control,temp1);
if(mode == RF_CMD_AUTH_LB)
RevBuffer[0] = RF_CMD_AUTH_LB;
else
RevBuffer[0] = RF_CMD_AUTH_LA;
RevBuffer[1] = SecNR * 4 + 3;
for(i = 0; i < 4; i++)
{
RevBuffer[2 + i] = UID;
}
SPIWrite(ChannelRedundancy,0x0f);
temp = Command_Send(6, RevBuffer, Authent1);
if(temp == FALSE)
{
return 0x99;
}
temp = SPIRead(ErrorFlag); //ErrorFlag address is 0x0A.
if((temp & 0x02) == 0x02) return FM1702_PARITYERR;
if((temp & 0x04) == 0x04) return FM1702_FRAMINGERR;
if((temp & 0x08) == 0x08) return FM1702_CRCERR;
temp = Command_Send(0, RevBuffer, Authent2);
if(temp == FALSE)
{
return 0x88;
}
temp = SPIRead(ErrorFlag);
if((temp & 0x02) == 0x02) return FM1702_PARITYERR;
if((temp & 0x04) == 0x04) return FM1702_FRAMINGERR;
if((temp & 0x08) == 0x08) return FM1702_CRCERR;
temp1 = SPIRead(Control);
temp1 = temp1 & 0x08;
if(temp1 == 0x08)
{
return FM1702_OK;
}
return FM1702_AUTHERR;
}
然后就看不懂了~ |
|