584 lines
19 KiB
C
584 lines
19 KiB
C
//2018<31><38>2<EFBFBD><32>2<EFBFBD>ձ༭<D5B1><E0BCAD>֧<EFBFBD><D6A7>CPU<50><55>Ƭָ<C6AC><EFBFBD><EEA3AC><EFBFBD>ӷ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>
|
||
#include "../include/READER.h"
|
||
#include "../include/CPU_CARD.h"
|
||
#include <string.h>
|
||
#include "../include/READER_REG.h"
|
||
#include "../include/rfid_main.h"
|
||
|
||
|
||
#define CPU_DEBUG 0
|
||
|
||
struct CPU_CARD_STR CPU_CARD;
|
||
|
||
#if 0
|
||
unsigned char CPU_CARD_EVENT( void ){
|
||
return FAIL;
|
||
}
|
||
#else
|
||
unsigned char CPU_CARD_EVENT( void )
|
||
{
|
||
unsigned char result;
|
||
unsigned char SendBuffer[255];
|
||
unsigned char ReceiveBuffer[255];
|
||
unsigned char i;
|
||
transmission_struct APDU;
|
||
APDU.pSendBuffer = SendBuffer; /*<2A><><EFBFBD>÷<EFBFBD><C3B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||
APDU.pReceiveBuffer = ReceiveBuffer; /*<2A><><EFBFBD>ý<EFBFBD><C3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||
result = CPU_Rats( &CPU_CARD.ATS.Length, CPU_CARD.ATS.Ats_Data );
|
||
if ( result != SUCCESS )
|
||
{
|
||
SetCW( DISABLE );
|
||
printf( "-> RATS ERROR!\r\n" );
|
||
return result;
|
||
}
|
||
|
||
printf( "-> ATS = " );
|
||
for(i = 0;i < CPU_CARD.ATS.Length;i++)
|
||
printf("%02X", CPU_CARD.ATS.Ats_Data[i]);
|
||
printf( "\r\n" );
|
||
|
||
result = Ats_Process( CPU_CARD.ATS.Length, CPU_CARD.ATS.Ats_Data );
|
||
if ( result != SUCCESS )
|
||
{
|
||
SetCW( DISABLE );
|
||
printf( "-> RATS ERROR!\r\n" );
|
||
return result;
|
||
}
|
||
|
||
memcpy( APDU.pSendBuffer, "\x00\xA4\x00\x00\x02\x3F\x00", 7 );
|
||
APDU.SendLength = 7;
|
||
result = CPU_APDU( &APDU );
|
||
if ( result != SUCCESS )
|
||
{
|
||
SetCW( DISABLE );
|
||
printf( "-> APDU ERROR!\r\n" );
|
||
return result;
|
||
}
|
||
printf( "->APDU = " );
|
||
for(i=0;i<APDU.ReceiveLength;i++)
|
||
printf("%02X", APDU.pReceiveBuffer[i] );
|
||
printf( "\r\n" );
|
||
|
||
|
||
memcpy(APDU.pSendBuffer,"\x00\xA4\x04\x00\x07\xD4\x10\x00\x00\x03\x00\x01",12);
|
||
APDU.SendLength = 12;
|
||
result = CPU_APDU(&APDU);
|
||
if(result != SUCCESS)
|
||
{
|
||
SetCW(DISABLE);
|
||
printf("-> APDU ERROR!\r\n");
|
||
return result;
|
||
}
|
||
printf("-> APDU = ");
|
||
for(i=0;i<APDU.ReceiveLength;i++)
|
||
printf("%02X",APDU.pReceiveBuffer[i]);
|
||
printf("\r\n");
|
||
|
||
|
||
memcpy(APDU.pSendBuffer,"\x00\xA4\x04\x00\x0E\x32\x50\x41\x59\x2E\x53\x59\x53\x2E\x44\x44\x46\x30\x31",19);
|
||
APDU.SendLength = 19;
|
||
result = CPU_APDU(&APDU);
|
||
if(result != SUCCESS)
|
||
{
|
||
SetCW(DISABLE);
|
||
printf("-> APDU ERROR!\r\n");
|
||
return result;
|
||
}
|
||
printf("-> Response = ");
|
||
for(i=0;i<APDU.ReceiveLength;i++)
|
||
printf("%02X",APDU.pReceiveBuffer[i]);
|
||
printf("\r\n");
|
||
|
||
memcpy(APDU.pSendBuffer,"\x00\xA4\x04\x00\x08\xA0\x00\x00\x03\x33\x01\x01\x01\x00",14);
|
||
APDU.SendLength = 14;
|
||
result = CPU_APDU(&APDU);
|
||
if(result != SUCCESS)
|
||
{
|
||
SetCW(DISABLE);
|
||
printf("-> APDU ERROR!\r\n");
|
||
return result;
|
||
}
|
||
printf("-> Response = ");
|
||
for(i=0;i<APDU.ReceiveLength;i++)
|
||
printf("%02X",APDU.pReceiveBuffer[i]);
|
||
printf("\r\n");
|
||
|
||
memcpy(APDU.pSendBuffer,"\x80\xA8\x00\x00\x24\x83\x22\x28\x00\x00\x80\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x01\x56\x00\x00\x00\x00\x00\x01\x56\x13\x08\x28\x82\x12\x34\x56\x78\x00\x00",42);
|
||
APDU.SendLength = 42;
|
||
result = CPU_APDU(&APDU);
|
||
if(result != SUCCESS)
|
||
{
|
||
SetCW(DISABLE);
|
||
printf("-> APDU ERROR!\r\n");
|
||
return result;
|
||
}
|
||
printf("-> Response = ");
|
||
for(i=0;i<APDU.ReceiveLength;i++)
|
||
printf("%02X",APDU.pReceiveBuffer[i]);
|
||
printf("\r\n");
|
||
|
||
|
||
memcpy( APDU.pSendBuffer, "\x00\x84\x00\x00\x08", 5 );
|
||
APDU.SendLength = 5;
|
||
result = CPU_APDU( &APDU );
|
||
if ( result != SUCCESS )
|
||
{
|
||
SetCW( DISABLE );
|
||
printf( "-> APDU ERROR!\r\n" );
|
||
return result;
|
||
}
|
||
printf( "-> Response = " );
|
||
for(i=0;i<APDU.ReceiveLength;i++)
|
||
printf("%02X",APDU.pReceiveBuffer[i]);
|
||
printf( "\r\n" );
|
||
return result;
|
||
}
|
||
#endif
|
||
|
||
#if 0
|
||
void Write_FIFO(unsigned char length,unsigned char* buff)
|
||
{
|
||
|
||
}
|
||
#else
|
||
void Write_FIFO(unsigned char length,unsigned char* buff)
|
||
{
|
||
unsigned char i;
|
||
for(i=0;i<length;i++)
|
||
{
|
||
SetReg(REG_FIFODATA,buff[i]);
|
||
}
|
||
}
|
||
#endif
|
||
|
||
#if 0
|
||
void Read_FIFO(unsigned char length,unsigned char* buff)
|
||
{
|
||
}
|
||
#else
|
||
void Read_FIFO(unsigned char length,unsigned char* buff)
|
||
{
|
||
unsigned char i;
|
||
for(i=0;i<length;i++)
|
||
{
|
||
GetReg(REG_FIFODATA,&buff[i]);
|
||
}
|
||
}
|
||
#endif
|
||
|
||
#if 0
|
||
unsigned char FM176XX_TPDU( transmission_struct *tpdu )
|
||
{
|
||
return FAIL;
|
||
}
|
||
#else
|
||
unsigned char FM176XX_TPDU( transmission_struct *tpdu )
|
||
{
|
||
unsigned char result,irq0,irq1,error;
|
||
unsigned int i;
|
||
SetCommand(CMD_IDLE);
|
||
SetReg(REG_TXDATANUM,0x08);
|
||
SetReg(REG_IRQ0,0x7F);//Clear IRQ0
|
||
SetReg(REG_IRQ1,0x7F); //Clear IRQ1
|
||
ModifyReg(REG_FIFOCONTROL,BIT_FIFOFLUSH,ENABLE); //Clear FIFO
|
||
Write_FIFO(tpdu->SendLength,tpdu->pSendBuffer);
|
||
ModifyReg(REG_TXCRCCON, BIT_CRCEN,ENABLE);
|
||
ModifyReg(REG_RXCRCCON, BIT_CRCEN,ENABLE);
|
||
// SetTimer(tpdu->Timeout);
|
||
SetCommand(CMD_TRANSCEIVE);
|
||
for(i = 0;i < tpdu->Timeout; i++)
|
||
{
|
||
DelayMs(1);//<2F><><EFBFBD>յȴ<D5B5><C8B4><EFBFBD>ʱ
|
||
GetReg(REG_IRQ0,&irq0);
|
||
|
||
if(irq0 & BIT_RXIRQ)
|
||
{
|
||
GetReg( REG_ERROR, &error ); /*Get Error Status */
|
||
error = error & (BIT_NODATAERR | BIT_COLLDET | BIT_PROTERR | BIT_INTEGERR);
|
||
if(error != 0)
|
||
return FAIL;//<2F><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>
|
||
GetReg(REG_FIFOLENGTH,&tpdu->ReceiveLength);
|
||
if(tpdu->ReceiveLength > 0)
|
||
{
|
||
Read_FIFO(tpdu->ReceiveLength,tpdu->pReceiveBuffer);
|
||
result = SUCCESS;
|
||
return result;
|
||
}
|
||
}
|
||
GetReg(REG_IRQ1,&irq1);
|
||
|
||
// if(irq1 & BIT_TIMER1IRQ)
|
||
// {
|
||
// result = FAIL;//δ<><CEB4>timeoutʱ<74><CAB1><EFBFBD>ڽ<EFBFBD><DABD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>
|
||
// }
|
||
|
||
}
|
||
result = FAIL;//δ<><CEB4>timeoutʱ<74><CAB1><EFBFBD>ڽ<EFBFBD><DABD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>
|
||
return result;
|
||
}
|
||
#endif
|
||
|
||
|
||
/****************************************************************/
|
||
/*<2A><><EFBFBD><EFBFBD>: Rats */
|
||
/*<2A><><EFBFBD><EFBFBD>: Request for answer to select */
|
||
/*<2A><><EFBFBD><EFBFBD>: */
|
||
/* */
|
||
/*<2A><><EFBFBD>: */
|
||
/* ats_len<65><6E><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD>ATS<54><53><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD> */
|
||
/* *ats<74><73><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>ATS<54><53><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8> */
|
||
/* OK: Ӧ<><D3A6><EFBFBD><EFBFBD>ȷ */
|
||
/* ERROR: Ӧ<><D3A6><EFBFBD><EFBFBD><EFBFBD> */
|
||
/****************************************************************/
|
||
#if 0
|
||
unsigned char CPU_Rats( unsigned char *ats_len, unsigned char *ats )
|
||
{
|
||
return FAIL;
|
||
}
|
||
#else
|
||
unsigned char CPU_Rats( unsigned char *ats_len, unsigned char *ats )
|
||
{
|
||
unsigned char result;
|
||
unsigned char outbuffer[2], inbuffer[64];
|
||
transmission_struct tpdu;
|
||
tpdu.pSendBuffer = outbuffer;
|
||
tpdu.pReceiveBuffer = inbuffer;
|
||
tpdu.pSendBuffer[0] = 0xE0; /*Start byte */
|
||
tpdu.pSendBuffer[1] = 0x50; /*default = 0x50 */
|
||
tpdu.SendLength = 2;
|
||
tpdu.Timeout = 160;
|
||
//CPU_CARD.FWT = 160;//Ĭ<><C4AC><EFBFBD><EFBFBD>ʱʱ<CAB1><CAB1>
|
||
result = FM176XX_TPDU( &tpdu );
|
||
if ( result == SUCCESS )
|
||
{
|
||
*ats_len = tpdu.ReceiveLength;
|
||
memcpy( ats, tpdu.pReceiveBuffer, *ats_len );
|
||
}
|
||
return (result);
|
||
}
|
||
#endif
|
||
|
||
|
||
#if 0
|
||
unsigned char Ats_Process( unsigned char ats_len, unsigned char *ats )/* ATS<54><53><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD> */
|
||
{
|
||
return FAIL;
|
||
}
|
||
#else
|
||
unsigned char Ats_Process( unsigned char ats_len, unsigned char *ats )/* ATS<54><53><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD> */
|
||
{
|
||
unsigned char result, offset;
|
||
|
||
if ( (ats_len == ats[0]) || (ats_len > 2) )/*TL */
|
||
{
|
||
CPU_CARD.FSCI = ats[1] & 0x0F;
|
||
if ( CPU_CARD.FSCI == 0 )
|
||
CPU_CARD.FSC = 13;
|
||
if ( CPU_CARD.FSCI == 1 )
|
||
CPU_CARD.FSC = 21;
|
||
if ( CPU_CARD.FSCI == 2 )
|
||
CPU_CARD.FSC = 29;
|
||
if ( CPU_CARD.FSCI == 3 )
|
||
CPU_CARD.FSC = 37;
|
||
if ( CPU_CARD.FSCI == 4 )
|
||
CPU_CARD.FSC = 45;
|
||
if ( CPU_CARD.FSCI == 5 )
|
||
CPU_CARD.FSC = 61;
|
||
if ( CPU_CARD.FSCI == 6 )
|
||
CPU_CARD.FSC = 93;
|
||
if ( CPU_CARD.FSCI == 7 )
|
||
CPU_CARD.FSC = 125;
|
||
if ( CPU_CARD.FSCI > 7 )
|
||
CPU_CARD.FSC = 253;
|
||
//CPU_CARD.FSC = 13;
|
||
printf( "-> CPU_CARD.FSC = %02X\r\n",CPU_CARD.FSC );
|
||
}
|
||
else
|
||
{
|
||
result = FAIL;
|
||
return (result);
|
||
}
|
||
offset = 0;
|
||
result = SUCCESS;
|
||
if ( ats[1] & BIT5 ) /*TA */
|
||
{
|
||
CPU_CARD.TA = ats[2];
|
||
offset++;
|
||
}
|
||
|
||
if ( ats[1] & BIT6 ) /*TB */
|
||
{
|
||
CPU_CARD.TB = ats[2 + offset];
|
||
CPU_CARD.SFGI = CPU_CARD.TB & 0x0F;
|
||
CPU_CARD.FWI = (CPU_CARD.TB >> 4) & 0x0F;
|
||
printf( "-> CPU_CARD.SFGI = %02X\r\n",CPU_CARD.SFGI );
|
||
printf( "-> CPU_CARD.FWI = %02X\r\n",CPU_CARD.FWI);
|
||
if ( CPU_CARD.FWI < 2 )
|
||
CPU_CARD.FWT = 1;
|
||
if ( CPU_CARD.FWI == 2 )
|
||
CPU_CARD.FWT = 2;
|
||
if ( CPU_CARD.FWI == 3 )
|
||
CPU_CARD.FWT = 3;
|
||
if ( CPU_CARD.FWI == 4 )
|
||
CPU_CARD.FWT = 5;
|
||
if ( CPU_CARD.FWI == 5 )
|
||
CPU_CARD.FWT = 10;
|
||
if ( CPU_CARD.FWI == 6 )
|
||
CPU_CARD.FWT = 20;
|
||
if ( CPU_CARD.FWI == 7 )
|
||
CPU_CARD.FWT = 40;
|
||
if ( CPU_CARD.FWI == 8 )
|
||
CPU_CARD.FWT = 80;
|
||
if ( CPU_CARD.FWI == 9 )
|
||
CPU_CARD.FWT = 160;
|
||
if ( CPU_CARD.FWI == 10 )
|
||
CPU_CARD.FWT = 310;
|
||
if ( CPU_CARD.FWI == 11 )
|
||
CPU_CARD.FWT = 620;
|
||
if ( CPU_CARD.FWI == 12 )
|
||
CPU_CARD.FWT = 1240;
|
||
if ( CPU_CARD.FWI == 13 )
|
||
CPU_CARD.FWT = 2480;
|
||
if ( CPU_CARD.FWI > 13 )
|
||
CPU_CARD.FWT = 4950;
|
||
offset++;
|
||
}
|
||
|
||
if ( ats[1] & BIT7 )/*TC */
|
||
{
|
||
CPU_CARD.TC = ats[2 + offset];
|
||
offset++;
|
||
}
|
||
CPU_CARD.PCB = 0x02;/*PCB<43><42>ʼֵΪ0x02 */
|
||
return (result);
|
||
}
|
||
#endif
|
||
|
||
#if 1
|
||
//xtell 同时把CPU_TPDU 和 CPU_NAk 用空函数替换 SPi正常
|
||
unsigned char CPU_NAK( transmission_struct *tpdu ) /* <20><>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD>NAK */
|
||
{
|
||
return FAIL;
|
||
}
|
||
#else
|
||
unsigned char CPU_NAK( transmission_struct *tpdu ) /* <20><>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD>NAK */
|
||
{
|
||
unsigned char result, tpdu_send_buffer[255],tpdu_receive_buffer[255];
|
||
|
||
tpdu->pSendBuffer = tpdu_send_buffer;
|
||
tpdu->pReceiveBuffer = tpdu_receive_buffer;
|
||
|
||
tpdu->pSendBuffer [0] = 0xB0 | CPU_CARD.PCB;
|
||
tpdu->SendLength = 1;
|
||
/*printf( "NAK\r\n" );*/
|
||
|
||
result = FM176XX_TPDU( tpdu );
|
||
return (result);
|
||
}
|
||
#endif
|
||
|
||
#if 0
|
||
unsigned char CPU_TPDU( transmission_struct *tpdu )
|
||
{
|
||
return FAIL;
|
||
}
|
||
#else
|
||
unsigned char CPU_TPDU( transmission_struct *tpdu )
|
||
{
|
||
unsigned char result, i, pcb_byte;
|
||
transmission_struct nak_tpdu;
|
||
|
||
result = FM176XX_TPDU( tpdu );
|
||
|
||
for ( i = 0; i < 3; i++ )
|
||
{
|
||
if ( result != SUCCESS )
|
||
{
|
||
result = CPU_NAK( &nak_tpdu );
|
||
if(result == SUCCESS)
|
||
{
|
||
if(nak_tpdu.ReceiveLength > 0)
|
||
{
|
||
memcpy( &pcb_byte, nak_tpdu.pReceiveBuffer, 1 );
|
||
if((pcb_byte & 0xF0) == 0xA0)//R(ACK)
|
||
{
|
||
#if CPU_DEBUG
|
||
printf("...pcb_byte = %02X\r\n",pcb_byte);
|
||
printf("...CPU_CARD.PCB = %02X\r\n",CPU_CARD.PCB);
|
||
#endif
|
||
if((pcb_byte & 0x03) != CPU_CARD.PCB)
|
||
{
|
||
result = FM176XX_TPDU( tpdu );
|
||
}
|
||
else
|
||
{
|
||
tpdu->pSendBuffer[0] = tpdu->pSendBuffer[0] ^ 0x01;//
|
||
CPU_CARD.PCB = tpdu->pSendBuffer[0] & 0x03;
|
||
result = FM176XX_TPDU( tpdu );
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
return (result);
|
||
}
|
||
#endif
|
||
|
||
/****************************************************************/
|
||
/*<2A><><EFBFBD><EFBFBD>: CPU_APDU */
|
||
/*<2A><><EFBFBD><EFBFBD>: <20>ú<EFBFBD><C3BA><EFBFBD>ʵ<EFBFBD><CAB5>ת<EFBFBD><D7AA>APDU<44><55><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD> CPU card reset */
|
||
/*<2A><><EFBFBD><EFBFBD>: */
|
||
/* */
|
||
/*<2A><><EFBFBD>: */
|
||
/* ats_len<65><6E><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD> */
|
||
/* ats<74><73><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8> */
|
||
/* OK: Ӧ<><D3A6><EFBFBD><EFBFBD>ȷ */
|
||
/* ERROR: Ӧ<><D3A6><EFBFBD><EFBFBD><EFBFBD> */
|
||
/****************************************************************/
|
||
#if 1
|
||
//xtell 同时把CPU_TPDU 和 CPU_NAk 用空函数替换 SPi正常
|
||
unsigned char CPU_APDU( transmission_struct *apdu )
|
||
{
|
||
return FAIL;
|
||
}
|
||
#else
|
||
unsigned char CPU_APDU( transmission_struct *apdu )
|
||
{
|
||
unsigned char result, pcb_byte, tpdu_send_buffer[255],tpdu_receive_buffer[255], i;
|
||
unsigned char unsent_length;
|
||
transmission_struct tpdu;
|
||
tpdu.pSendBuffer = tpdu_send_buffer;
|
||
tpdu.pReceiveBuffer = tpdu_receive_buffer;
|
||
tpdu.Timeout = CPU_CARD.FWT;
|
||
apdu->ReceiveLength = 0;
|
||
unsent_length = apdu->SendLength; /*<2A><><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD> */
|
||
|
||
for ( i = 0; i < 16; i++ ) /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̣<EFBFBD><CCA3><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD>鳤<EFBFBD><E9B3A4>16<31><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>16<31><36><EFBFBD>鷢<EFBFBD><E9B7A2> */
|
||
{
|
||
#if CPU_DEBUG
|
||
printf("unsent_length = %02X\r\n",unsent_length);
|
||
#endif
|
||
if ( unsent_length < CPU_CARD.FSC )
|
||
{
|
||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD>ȣ<EFBFBD><C8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||
tpdu.pSendBuffer[0] = CPU_CARD.PCB; /*PCB<43>ֽ<EFBFBD>д<EFBFBD><D0B4>TPDU<44><55><EFBFBD><EFBFBD> */
|
||
memcpy( tpdu.pSendBuffer + 1, apdu->pSendBuffer + apdu->SendLength - unsent_length, unsent_length ); /*APDU<44><55><EFBFBD><EFBFBD>д<EFBFBD><D0B4>TPDU<44><55><EFBFBD><EFBFBD> */
|
||
tpdu.SendLength = unsent_length + 1; /*<2A><><EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1 */
|
||
#if CPU_DEBUG
|
||
printf("--> ");
|
||
for(i=0;i<tpdu.SendLength;i++)
|
||
printf("%02X",tpdu.pSendBuffer[i]);
|
||
printf("\r\n");
|
||
#endif
|
||
result = CPU_TPDU( &tpdu );
|
||
if ( (result != SUCCESS) || (tpdu.ReceiveLength == 0) )
|
||
return (result);
|
||
#if CPU_DEBUG
|
||
printf("<-- ");
|
||
for(i=0;i<tpdu.ReceiveLength;i++)
|
||
printf("%02X",tpdu.pReceiveBuffer[i]);
|
||
printf("\r\n");
|
||
#endif
|
||
unsent_length = 0; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD><EFBFBD><EFBFBD>0 */
|
||
break; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><DDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD><CCBA>˳<EFBFBD>ѭ<EFBFBD><D1AD> */
|
||
}
|
||
else
|
||
{
|
||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3>ȴ<EFBFBD><C8B4>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD>ȣ<EFBFBD><C8A3><EFBFBD><EFBFBD>鷢<EFBFBD>ͣ<EFBFBD>ÿ<EFBFBD>鷢<EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>Ϊ<EFBFBD><CEAA>CPU_CARD.FSC - 1<><31> */
|
||
tpdu.pSendBuffer[0] = CPU_CARD.PCB | 0x10; /*PCB<43>ֽ<EFBFBD>д<EFBFBD><D0B4>TPDU<44><55><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӱ<EFBFBD>ʶ */
|
||
memcpy( tpdu.pSendBuffer + 1, apdu->pSendBuffer + apdu->SendLength - unsent_length, CPU_CARD.FSC - 1 ); /*APDU<44><55><EFBFBD><EFBFBD>д<EFBFBD><D0B4>TPDU<44><55><EFBFBD><EFBFBD> */
|
||
|
||
tpdu.SendLength = CPU_CARD.FSC; /*<2A><><EFBFBD>鷢<EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD> */
|
||
#if CPU_DEBUG
|
||
printf("..--> ");
|
||
for(i=0;i<tpdu.SendLength;i++)
|
||
printf("%02X",tpdu.pSendBuffer[i]);
|
||
printf("\r\n");
|
||
#endif
|
||
result = CPU_TPDU( &tpdu );
|
||
#if CPU_DEBUG
|
||
printf("<-- ");
|
||
for(i=0;i<tpdu.ReceiveLength;i++)
|
||
printf("%02X",tpdu.pReceiveBuffer[i]);
|
||
printf("\r\n");
|
||
#endif
|
||
if ( (result != SUCCESS) && (tpdu.ReceiveLength == 1) )
|
||
return (result);
|
||
memcpy( &pcb_byte, tpdu.pReceiveBuffer, 1 ); /* */
|
||
if ( (pcb_byte == 0xA2) || (pcb_byte == 0xA3) )
|
||
{
|
||
unsent_length = unsent_length - (CPU_CARD.FSC - 1); /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD> */
|
||
CPU_CARD.PCB = (pcb_byte & 0x0F) ^ 0x01; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>PCB<43>ֽ<EFBFBD> */
|
||
#if CPU_DEBUG
|
||
printf("unsent_length = %02X\r\n",unsent_length);
|
||
#endif
|
||
|
||
}
|
||
else
|
||
return (FAIL); /* */
|
||
}
|
||
}
|
||
for ( i = 0; i < 255; i++ ) /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̣<EFBFBD><CCA3><EFBFBD><EFBFBD>֧<EFBFBD><D6A7>255<35><35>ACK<43><4B><EFBFBD><EFBFBD>WTXӦ<58><D3A6> */
|
||
{
|
||
if ( (result != SUCCESS) || (tpdu.ReceiveLength == 0) )
|
||
return (FAIL);
|
||
memcpy( &pcb_byte, tpdu.pReceiveBuffer, 1 ); /*<2A><>ȡPCB<43>ֽ<EFBFBD> */
|
||
if ( (pcb_byte == 0x02) || (pcb_byte == 0x03) )
|
||
{
|
||
CPU_CARD.PCB = pcb_byte ^ 0x01; /*<2A><><EFBFBD><EFBFBD>PCB<43>ֽ<EFBFBD> */
|
||
#if CPU_DEBUG
|
||
printf("....CPU_CARD.PCB = %02X\r\n",CPU_CARD.PCB);
|
||
#endif
|
||
memcpy( apdu->pReceiveBuffer + apdu->ReceiveLength, tpdu.pReceiveBuffer + 1, tpdu.ReceiveLength - 1 );
|
||
apdu->ReceiveLength = apdu->ReceiveLength + tpdu.ReceiveLength - 1;
|
||
return (SUCCESS); /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||
}
|
||
|
||
if ( (pcb_byte == 0x12) || (pcb_byte == 0x13) )
|
||
{
|
||
memcpy( apdu->pReceiveBuffer + apdu->ReceiveLength, tpdu.pReceiveBuffer + 1, tpdu.ReceiveLength - 1 );
|
||
apdu->ReceiveLength = apdu->ReceiveLength + tpdu.ReceiveLength - 1;
|
||
tpdu.pSendBuffer[0] = ( (pcb_byte & 0x03) | 0xA0) ^ 0x01; /*<2A>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>PCB<43>ֽ<EFBFBD> */
|
||
tpdu.SendLength = 1;
|
||
#if CPU_DEBUG
|
||
printf("...--> = ");
|
||
for(i=0;i<tpdu.SendLength;i++)
|
||
printf("%02X",tpdu.pSendBuffer[i]);
|
||
printf("\r\n");
|
||
#endif
|
||
result = CPU_TPDU( &tpdu ); /*<2A>ط<EFBFBD>ACK */
|
||
#if CPU_DEBUG
|
||
printf("<-- = ");
|
||
for(i=0;i<tpdu.ReceiveLength;i++)
|
||
printf("%02X",tpdu.pReceiveBuffer[i]);
|
||
printf("\r\n");
|
||
#endif
|
||
}
|
||
|
||
if ( (pcb_byte == 0xF2) || (pcb_byte == 0xF3) )
|
||
{
|
||
tpdu.SendLength = tpdu.ReceiveLength;
|
||
memcpy(tpdu.pSendBuffer ,tpdu.pReceiveBuffer ,tpdu.SendLength); /*<2A>յ<EFBFBD>WTX֡<58><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>PCB<43>ֽ<EFBFBD> */
|
||
#if CPU_DEBUG
|
||
printf("....--> = ");
|
||
for(i=0;i<tpdu.SendLength;i++)
|
||
printf("%02X",tpdu.pSendBuffer[i]);
|
||
printf("\r\n");
|
||
#endif
|
||
result = CPU_TPDU( &tpdu ); /*<2A>ط<EFBFBD>WTX */
|
||
#if CPU_DEBUG
|
||
printf("<-- = ");
|
||
for(i=0;i<tpdu.ReceiveLength;i++)
|
||
printf("%02X",tpdu.pReceiveBuffer[i]);
|
||
printf("\r\n");
|
||
#endif
|
||
}
|
||
}
|
||
return (FAIL); /*<2A><><EFBFBD>մ<EFBFBD><D5B4><EFBFBD> */
|
||
}
|
||
#endif |