📄 at88153.c.bak
字号:
/****************************************
* at88153.c *
* functions for 88sc153 card *
* designed by liulixun *
* last update: 04-23-2007 *
****************************************/
#include "includes.h"
#define POLL_ACK_TMO 100
// PAC addr
static unsigned char PACAddrs[4] = {0x30, 0x38, 0x34, 0x3c};
// start and polling ACK with command "cmd"
static bit At153Command(unsigned char cmd);
int At153ReadEE(unsigned char zone, unsigned char addr, unsigned char *buf, unsigned char len)
{
unsigned char i;
zone <<= 2;
zone &= 0x0c;
zone |= 0xB1;
if(!At153Command(zone))
return -1;
if(!IccSyncPutChar(addr & 0x3f))
return -2;
for(i=0; i<len-1; i++)
{
buf[i] = IccSyncGetChar(1);
}
buf[i] = IccSyncGetChar(0);
IccSyncStop();
return i+1;
}
int At153WriteEE(unsigned char zone, unsigned char addr, unsigned char *buf, unsigned char len)
{
unsigned char i, i1;
zone <<= 2;
zone &= 0x0c;
zone |= 0xB0;
for(i1=0; i1<len; addr+=8)
{
if(!At153Command(zone))
return -1;
if(!IccSyncPutChar(addr & 0x3f))
return -2;
for(i=0; (i<8) && (i1<len); i++, i1++)
{
if(!IccSyncPutChar(buf[i1]))
return -3;
}
IccSyncStop();
}
return i1;
}
int At153ReadFS(void)
{
int i;
if(!At153Command(0xbe))
return -1;
i = IccSyncGetChar(0);
IccSyncStop();
return i;
}
int At153WriteFS(unsigned char value)
{
if(!At153Command(0xba))
return -1;
if(!IccSyncPutChar(value & 0x07))
return -2;
IccSyncStop();
return 0;
}
int At153VerifyPasswd(unsigned char rp, unsigned char *buf)
{
unsigned char i, j, zone;
rp &= 0x03;
zone = rp << 2;
zone |= 0xb3;
for(i=0; i<2; i++)
{
if(!At153Command(zone))
return -1;
for(j=0; j<3; j++)
{
if(!IccSyncPutChar(buf[j]))
return -2;
}
IccSyncStop();
// polling ACK with command 0xbd to read PAC in cfg zone
if(At153ReadEE(3, PACAddrs[rp], &j, 1) < 0)
return -3;
}
return j;
}
int At153InitAuth(unsigned char *buf)
{
unsigned char i;
if(!At153Command(0xb2))
return -1;
for(i=0; i<8; i++)
{
if(!IccSyncPutChar(buf[i]))
return -2;
}
IccSyncStop();
return 0;
}
int At153VerifyAuth(unsigned char *buf)
{
unsigned char i;
if(!At153Command(0xb6))
return -1;
for(i=0; i<8; i++)
{
if(!IccSyncPutChar(buf[i]))
return -2;
}
IccSyncStop();
// read AAC
if(At153ReadEE(3, 0x20, &i, 1) < 0)
return -3;
return i;
}
// polling ACK with command "cmd" and send "cmd"
static bit At153Command(unsigned char cmd)
{
unsigned int starttime;
starttime = GetTickCount();
while(1)
{
IccSyncStart();
if(!IccSyncPutChar(cmd))
{
IccSyncStop();
if(GetTickCount() - starttime >= POLL_ACK_TMO)
return 0;
}
else
{
return 1;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -