添加实验2所用仿真软件的源代码和编译结果
This commit is contained in:
357
Labs/Lab2/requirements/src/rfidsrc/PktAnalysis_ISO14443A.cpp
Normal file
357
Labs/Lab2/requirements/src/rfidsrc/PktAnalysis_ISO14443A.cpp
Normal file
@@ -0,0 +1,357 @@
|
||||
#include "PktAnalysis_ISO14443A.h"
|
||||
|
||||
CPktAnalysis_ISO14443A::CPktAnalysis_ISO14443A(int pcd )
|
||||
{
|
||||
m_nPcd = pcd;
|
||||
}
|
||||
|
||||
|
||||
CPktAnalysis_ISO14443A::~CPktAnalysis_ISO14443A(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool CPktAnalysis_ISO14443A::analysis( byte* buf, int bitLen, char *dir, char* hexdat, char *cmd, char *desp, int cmdid )
|
||||
{
|
||||
if( getOthers( buf, bitLen, dir, hexdat, cmd, cmdid ))
|
||||
{
|
||||
return getDesp( buf, bitLen, desp, cmdid);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
bool CPktAnalysis_ISO14443A::getDesp( byte *buf, int bitLen, char *desp, int cmdid )
|
||||
{
|
||||
char str[10];
|
||||
int m, n, k;
|
||||
|
||||
if( cmdid == 0 )
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
switch( cmdid )
|
||||
{
|
||||
case ISO_14443_CMD_REQA:
|
||||
#if 0
|
||||
if( buf[0] != cmdid )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( desp, "0x%02x, REQA", cmdid );
|
||||
}
|
||||
#endif
|
||||
sprintf( desp, "%02x, REQA", cmdid );
|
||||
break;
|
||||
case ISO_14443_CMD_WUPA:
|
||||
#if 0
|
||||
if( buf[0] != cmdid )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( desp, "0x%02x, WUPA", cmdid );
|
||||
}
|
||||
#endif
|
||||
sprintf( desp, "%02x, WUPA", cmdid );
|
||||
break;
|
||||
case ISO_14443_CMD_HALT:
|
||||
#if 0
|
||||
if( buf[0] != cmdid )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( desp, "5000, HALT" );
|
||||
}
|
||||
#endif
|
||||
sprintf( desp, "5000, HALT" );
|
||||
break;
|
||||
|
||||
case ISO_14443_CMD_SEL_CL1:
|
||||
case ISO_14443_CMD_SEL_CL2:
|
||||
case ISO_14443_CMD_SEL_CL3:
|
||||
char str[100];
|
||||
|
||||
// buf[0]
|
||||
if( buf[1] == 0x70 )
|
||||
{
|
||||
// SELECT.
|
||||
sprintf( desp, "%02x:SELECT, ", cmdid );
|
||||
}
|
||||
else
|
||||
{
|
||||
// 93/95/97.
|
||||
sprintf( desp, "%02x:ANTI_CL%d, ", cmdid, (cmdid-0x93)/2+1 );
|
||||
}
|
||||
|
||||
// buf[1]
|
||||
sprintf( str, "%02x:NVB,", buf[1] );
|
||||
strcat( desp, str );
|
||||
sprintf( str, "Byte num = %d, ", (buf[1] >> 4)&0x07 );
|
||||
strcat( desp, str );
|
||||
sprintf( str, "bit num = %d, ", buf[1] & 0x07 );
|
||||
strcat( desp, str );
|
||||
|
||||
// buf[2-...]
|
||||
if( buf[1] == 0x70 )
|
||||
{
|
||||
sprintf( str, "UID=%02x%02x%02x%02x",buf[2], buf[3], buf[4], buf[5] );
|
||||
strcat( desp, str );
|
||||
}
|
||||
else if( buf[1] == 0x20 )
|
||||
{
|
||||
sprintf( desp, "UID=void" );
|
||||
}
|
||||
else
|
||||
{
|
||||
int k = (( buf[1] >> 4 )&0x07) - 2;
|
||||
int m = buf[1] & 0x07; // m<><6D><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if( m == 0 )
|
||||
{
|
||||
strcat( desp, "UID=");
|
||||
for( int i = 0; i < k; i++ )
|
||||
{
|
||||
sprintf( str, "%02x", buf[2+i]);
|
||||
strcat( desp, str );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
k--;
|
||||
strcat( desp, "UID=");
|
||||
for( int i = 0; i < k; i++ )
|
||||
{
|
||||
sprintf( str, "%02x", buf[2+i]);
|
||||
strcat( desp, str );
|
||||
}
|
||||
strcat(desp,"_");
|
||||
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽڣ<D6BD><DAA3><EFBFBD>ӡ<EFBFBD>ͱ<EFBFBD><CDB1><EFBFBD>
|
||||
for( int i = m-1; i >= 0; i-- )
|
||||
{
|
||||
sprintf( str, "%d", (buf[2+k]>>i)&1);
|
||||
strcat( desp, str );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// BCC, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>BCC<43><43><EFBFBD>Ǿ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ڵ<EFBFBD>6<EFBFBD><36><EFBFBD>ֽ<EFBFBD>
|
||||
if( buf[1] == 0x70 )
|
||||
{
|
||||
sprintf(str, ", BCC=%02x", buf[6] );
|
||||
strcat( desp, str );
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>0x70<37><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CRC
|
||||
#if 0
|
||||
// CRC<52>ڽ<EFBFBD>֡ʱ<D6A1><CAB1><EFBFBD>Ѿ<EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD>ˡ<EFBFBD>
|
||||
if( buf[1] == 0x70 )
|
||||
{
|
||||
sprintf( str, ", CRC=%02x%02x", buf[7], buf[8]);
|
||||
strcat( desp, str );
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case ISO_14443_CMD_SEL_CLx:
|
||||
// <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>ײ;
|
||||
// <20><><EFBFBD>ݣ<EFBFBD>UID + BCC<43><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>bitLen % 8 != 0<><30><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽڱ<D6BD><DAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>bit.
|
||||
m = bitLen % 8;
|
||||
n = bitLen / 8;
|
||||
|
||||
strcpy( desp, "UID=" );
|
||||
if( m == 0 )
|
||||
{
|
||||
for( int i = 0; i < n-1; i++ )
|
||||
{
|
||||
sprintf( str, "%02x", buf[i] );
|
||||
strcat( desp, str );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
n++;
|
||||
for( int i = m-1; i >=0 ; i-- )
|
||||
{
|
||||
sprintf( str, "%d", ( buf[0]>> i)&1);
|
||||
strcat( desp, str );
|
||||
}
|
||||
for( int i = 0; i < 8-m; i++ )
|
||||
{
|
||||
sprintf( str, ".");
|
||||
strcat( desp, str );
|
||||
}
|
||||
sprintf( str, "_" );
|
||||
strcat( desp, str );
|
||||
for( int i = 0; i < n-2; i++ )
|
||||
{
|
||||
sprintf( str, "%02x", buf[i+1] );
|
||||
strcat( desp, str );
|
||||
}
|
||||
}
|
||||
sprintf( str, ", BCC=%02x", buf[n-1] );
|
||||
strcat( desp, str );
|
||||
|
||||
break;
|
||||
case ISO_14443_CMD_SAK:
|
||||
desp[0]=0x00;
|
||||
for( int i=0; i < 8; i++ )
|
||||
{
|
||||
sprintf( str, "%d", (buf[0]>>(7-i))&1 );
|
||||
strcat(desp, str );
|
||||
}
|
||||
if( buf[0] & 0x04 )
|
||||
{
|
||||
sprintf( str, ", b3=1, incompleted UID. continue anti" );
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( str, ", b3=0, UID OK" );
|
||||
}
|
||||
strcat( desp, str );
|
||||
break;
|
||||
case ISO_14443_CMD_ATQA:
|
||||
k = ( buf[1] >> 6 ) & 0x03;
|
||||
sprintf( desp, "bit8:7=%d%d, CL%d", (buf[1]>>7)&1, (buf[1]>>6)&1, k+1);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// <20><><EFBFBD>⣺<EFBFBD><E2A3BA><EFBFBD><EFBFBD>ANTI frame, PCD tx: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ں<DABA><F3A3ACB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>α<EFBFBD>ʾ;
|
||||
// PCD rx: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>
|
||||
//
|
||||
bool CPktAnalysis_ISO14443A::getOthers( byte *buf, int bitLen, char *dir, char* hexdat, char *cmd, int cmdid )
|
||||
{
|
||||
int k, i;
|
||||
char t[10];
|
||||
|
||||
if( cmdid == 0 )
|
||||
{
|
||||
// <20><>ȫ֪<C8AB><D6AA>cmd.
|
||||
// <20><><EFBFBD><EFBFBD>ɶ<EFBFBD><C9B6><EFBFBD><EFBFBD>ʹ<EFBFBD>ã<EFBFBD>
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch( cmdid )
|
||||
{
|
||||
///////////////////////////////////////
|
||||
// PCD<43><44><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>
|
||||
case ISO_14443_CMD_REQA:
|
||||
strcpy( dir, ( m_nPcd ? "tx":"rx") );
|
||||
strcpy( cmd, "REQA" );
|
||||
sprintf( hexdat, "%02X",cmdid );
|
||||
break;
|
||||
case ISO_14443_CMD_WUPA:
|
||||
strcpy( dir, ( m_nPcd ? "tx":"rx") );
|
||||
strcpy( cmd, "WUPA" );
|
||||
sprintf( hexdat, "%02X",cmdid );
|
||||
break;
|
||||
case ISO_14443_CMD_SEL_CL1:
|
||||
case ISO_14443_CMD_SEL_CL2:
|
||||
case ISO_14443_CMD_SEL_CL3:
|
||||
strcpy( dir, ( m_nPcd ? "tx":"rx") );
|
||||
// <20>п<EFBFBD><D0BF><EFBFBD><EFBFBD><EFBFBD>SELECT, <20><><EFBFBD><EFBFBD>NVB<56>ж<EFBFBD>
|
||||
if( buf[1] != 0x70 )
|
||||
{
|
||||
sprintf( cmd, "ANTI_CL=%02X", cmdid );
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( cmd, "SELECT_CL=%02X", cmdid );
|
||||
}
|
||||
// <20><>ӡ<EFBFBD><D3A1><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD>bitLen;
|
||||
k = bitLen/8;
|
||||
hexdat[0] = 0x00;
|
||||
for( i = 0; i < k; i++ )
|
||||
{
|
||||
sprintf(t, "%02x", buf[i]);
|
||||
strcat( hexdat, t );
|
||||
}
|
||||
|
||||
// <20>ٴ<EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><F3BCB8B8><EFBFBD><EFBFBD><EFBFBD>;
|
||||
if( bitLen % 8 )
|
||||
{
|
||||
strcat( hexdat, "_" );
|
||||
for( i = 0; i < 8-bitLen%8; i++ )
|
||||
{
|
||||
sprintf( t, "." );
|
||||
strcat( hexdat, t );
|
||||
}
|
||||
|
||||
for( i=bitLen%8-1; i >= 0; i-- )
|
||||
{
|
||||
sprintf( t, "%d", (buf[k]>>i)&1);
|
||||
strcat( hexdat, t );
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case ISO_14443_CMD_HALT:
|
||||
strcpy( dir, ( m_nPcd ? "tx":"rx") );
|
||||
strcpy( cmd, "HALT" );
|
||||
sprintf( hexdat, "5000",cmdid );
|
||||
break;
|
||||
|
||||
////////////////////////////////////////
|
||||
// PCD<43><44><EFBFBD>շ<EFBFBD><D5B7><EFBFBD>.
|
||||
case ISO_14443_CMD_SAK:
|
||||
strcpy( dir, ( m_nPcd ? "rx":"tx") );
|
||||
strcpy( cmd, "SAK" );
|
||||
sprintf( hexdat, "%02X", buf[0] );
|
||||
break;
|
||||
case ISO_14443_CMD_ATQA:
|
||||
strcpy( dir, ( m_nPcd ? "rx":"tx") );
|
||||
strcpy( cmd, "ATQA" );
|
||||
sprintf( hexdat, "%02X,%02X", buf[0], buf[1] );
|
||||
break;
|
||||
case ISO_14443_CMD_SEL_CLx:
|
||||
strcpy( dir, ( m_nPcd ? "rx":"tx") );
|
||||
strcpy( cmd, "ANTI" );
|
||||
|
||||
hexdat[0] = 0x00;
|
||||
k = bitLen / 8;
|
||||
i = 0;
|
||||
if( bitLen % 8 != 0 )
|
||||
{
|
||||
k++;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD>;
|
||||
int m = bitLen % 8;
|
||||
for( i = m-1; i >=0; i-- )
|
||||
{
|
||||
sprintf( t,"%d", (buf[0] >> i)&1 );
|
||||
strcat( hexdat, t );
|
||||
}
|
||||
for( i = 0; i < 8-m; i++ )
|
||||
{
|
||||
sprintf( t,"." );
|
||||
strcat( hexdat, t );
|
||||
}
|
||||
i = 1;
|
||||
}
|
||||
if( i != 0 )
|
||||
{
|
||||
strcat( hexdat, "_" );
|
||||
}
|
||||
for( ; i < k; i++ )
|
||||
{
|
||||
sprintf( t, "%02x", buf[i] );
|
||||
strcat( hexdat, t );
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
60
Labs/Lab2/requirements/src/rfidsrc/PktAnalysis_ISO14443A.h
Normal file
60
Labs/Lab2/requirements/src/rfidsrc/PktAnalysis_ISO14443A.h
Normal file
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
#include "rfid_def.h"
|
||||
|
||||
///////////////
|
||||
// <20><>ISO14443 frame<6D><65><EFBFBD>з<EFBFBD><D0B7><EFBFBD>
|
||||
// frame: <09><><EFBFBD><EFBFBD>short Frame: 7bits, <20><><EFBFBD>߱<EFBFBD><DFB1><EFBFBD>0
|
||||
// <09><><EFBFBD><EFBFBD>std frame: nx8bits;
|
||||
// <09><><EFBFBD><EFBFBD>ANTICOLLISION frame, bit<69><74><EFBFBD>Ȳ<EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>
|
||||
// frame<6D><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> S/E bit, old parity bit, CRC(std frame)<29><>
|
||||
// <09><><EFBFBD>У<EFBFBD> short frame<6D><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB> old parity bit, CRC(std frame)
|
||||
// frame<6D><65>bitlen<65><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽڶ<D6BD><DAB6>룬<EFBFBD><EBA3AC><EFBFBD><EFBFBD>
|
||||
// short frame: bit7<74><37>Ч;
|
||||
// ANTICOLLISION frame:
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
// <20><><EFBFBD><EFBFBD>: byte *buf <20><><EFBFBD><EFBFBD>short frame: bit7<74><37>Ч<EFBFBD><D0A7>
|
||||
// <09><><EFBFBD><EFBFBD>anti frame: ʣ<><CAA3>bit<69><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽڵĵ<DAB5>bitλ<74>ã<EFBFBD>
|
||||
//
|
||||
// int bitlen <09><>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD>: dir: <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>rx/tx<74><78>
|
||||
// <09><>cmd.
|
||||
// hexdat: hex<65><78>ʾ<EFBFBD><CABE>frame<6D><65><EFBFBD>ݣ<EFBFBD>
|
||||
// cmd: <09><><EFBFBD>REQA/WUPA/ATQA/SAK/HALT/SELECT/ANTICOLLISION
|
||||
// REQA/WUPA/HALT/SELECT, PCD: tx, PICC: rx
|
||||
// ATQA/SAK PCD<43><44>rx, PICC: tx
|
||||
// ANTICOLLISION: PCD/PICC<43><43>tx/rx<72><78>
|
||||
//
|
||||
// desp: <09><><EFBFBD><EFBFBD>;
|
||||
// cmdid: <09><><EFBFBD><EFBFBD>cmdid != 0<><30><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD>û<EFBFBD>֪<EFBFBD><D6AA><EFBFBD>Լ<EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>cmd<6D><64><EFBFBD><EFBFBD>ʱdir/hexdat<61><74><EFBFBD><EFBFBD><EFBFBD>ٴ<EFBFBD>buf<75>н<EFBFBD><D0BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>tx<74><78><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
||||
// <09><><EFBFBD><EFBFBD>cmdid == 0<><30><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>buf<75>н<EFBFBD><D0BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20>ڽ<EFBFBD><DABD>շ<EFBFBD><D5B7><EFBFBD>ʹ<EFBFBD>ã<EFBFBD>
|
||||
// <09>ڽ<EFBFBD><DABD>շ<EFBFBD><D5B7><EFBFBD><EFBFBD><EFBFBD>Э<EFBFBD><D0AD>Ҳû<D2B2>ж<EFBFBD><D0B6><EFBFBD>id: ATQA/SAK;
|
||||
//
|
||||
//
|
||||
class CPktAnalysis_ISO14443A
|
||||
{
|
||||
public:
|
||||
CPktAnalysis_ISO14443A(int pcd = 1 );
|
||||
~CPktAnalysis_ISO14443A(void);
|
||||
|
||||
public:
|
||||
bool analysis_tx( byte* buf, int bitLen, char *dir, char* hexdat, char *cmd, char *desp, int cmdid )
|
||||
{
|
||||
return analysis(buf, bitLen, dir, hexdat, cmd, desp, cmdid);
|
||||
}
|
||||
bool analysis_rx( byte* buf, int bitLen, char *dir, char* hexdat, char *cmd, char *desp )
|
||||
{
|
||||
return analysis(buf, bitLen, dir, hexdat, cmd, desp, 0);
|
||||
}
|
||||
bool analysis( byte* buf, int bitLen, char *dir, char* hexdat, char *cmd, char *desp, int cmdid = 0 );
|
||||
|
||||
protected:
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
bool getDesp( byte *buf, int bitLen, char *desp, int cmdid );
|
||||
bool getOthers( byte *buf, int bitLen, char *dir, char* hexdat, char *cmd, int cmdid );
|
||||
|
||||
protected:
|
||||
int m_nPcd; // 1<><31>PCD, 0<><30>PICC;
|
||||
};
|
||||
|
||||
BIN
Labs/Lab2/requirements/src/rfidsrc/VC中的thread.docx
Normal file
BIN
Labs/Lab2/requirements/src/rfidsrc/VC中的thread.docx
Normal file
Binary file not shown.
55
Labs/Lab2/requirements/src/rfidsrc/class/CRC16.cpp
Normal file
55
Labs/Lab2/requirements/src/rfidsrc/class/CRC16.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
|
||||
#include "CRC16.h"
|
||||
|
||||
namespace VSPR_OF_ISO14443A
|
||||
{
|
||||
CCRC16::CCRC16(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CCRC16::~CCRC16(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* CRCУ<43><D0A3>
|
||||
*
|
||||
* \input BYTE aBuf[],<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* UINT16 u16Len <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* UINT16 u16InitPrm CRC16<31><36>ֵ.
|
||||
* \ouput BYTE *pCRCMSB CRC<52><43>8bit
|
||||
* BYTE *pCRCLSB CRC<52><43>8bit
|
||||
* \return 1<>ɹ<EFBFBD><C9B9><EFBFBD><0ʧ<30><CAA7>.
|
||||
*/
|
||||
int CCRC16::GetCRC16( UINT16 u16InitValue, BYTE aBuf[], UINT16 u16Len,BYTE *pCRCMSB, BYTE *pCRCLSB )
|
||||
{
|
||||
UINT16 wCrc;
|
||||
unsigned char chBlock;
|
||||
int i;
|
||||
|
||||
wCrc = u16InitValue;
|
||||
for( i = 0; i < u16Len; i++ )
|
||||
{
|
||||
chBlock = aBuf[i];
|
||||
UpdateCrc(chBlock, &wCrc);
|
||||
}
|
||||
if( u16InitValue == 0xFFFF )
|
||||
{
|
||||
wCrc = ~wCrc; // ISO 3309
|
||||
}
|
||||
*pCRCLSB = (BYTE) (wCrc & 0xFF);
|
||||
*pCRCMSB = (BYTE) ((wCrc >> 8) & 0xFF);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
UINT16 CCRC16::UpdateCrc(BYTE ch, UINT16 *lpwCrc)
|
||||
{
|
||||
ch = (ch^(unsigned char)((*lpwCrc) & 0x00FF));
|
||||
ch = (ch^(ch<<4));
|
||||
|
||||
*lpwCrc = (*lpwCrc >> 8)^((UINT16)ch << 8)^((UINT16)ch<<3)^((UINT16)ch>>4);
|
||||
return(*lpwCrc);
|
||||
}
|
||||
}
|
||||
60
Labs/Lab2/requirements/src/rfidsrc/class/CRC16.h
Normal file
60
Labs/Lab2/requirements/src/rfidsrc/class/CRC16.h
Normal file
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
#include "..\rfid_def.h"
|
||||
|
||||
namespace VSPR_OF_ISO14443A
|
||||
{
|
||||
class CCRC16
|
||||
{
|
||||
public:
|
||||
CCRC16(void);
|
||||
~CCRC16(void);
|
||||
|
||||
/**
|
||||
* CRCУ<43><D0A3>
|
||||
*
|
||||
* \input BYTE aBuf[],<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* UINT16 u16Len <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* UINT16 u16InitPrm CRC16<31><36>ֵ.
|
||||
* \ouput BYTE *pCRCMSB CRC<52><43>8bit
|
||||
* BYTE *pCRCLSB CRC<52><43>8bit
|
||||
* \return 1<>ɹ<EFBFBD><C9B9><EFBFBD><0ʧ<30><CAA7>.
|
||||
*/
|
||||
int GetCRC16( UINT16 u16InitValue, BYTE aBuf[], UINT16 u16Len,BYTE *pCRCMSB, BYTE *pCRCLSB );
|
||||
protected:
|
||||
UINT16 UpdateCrc(BYTE ch, UINT16 *lpwCrc);
|
||||
};
|
||||
|
||||
class CCRC16of14443A : public CCRC16
|
||||
{
|
||||
public:
|
||||
CCRC16of14443A(void)
|
||||
{
|
||||
}
|
||||
~CCRC16of14443A(void)
|
||||
{
|
||||
}
|
||||
|
||||
int GetCRC16( BYTE aBuf[], UINT16 u16Len, BYTE *pCRCMSB, BYTE *pCRCLSB )
|
||||
{
|
||||
return CCRC16::GetCRC16( 0x6363, aBuf, u16Len, pCRCMSB, pCRCLSB );
|
||||
}
|
||||
};
|
||||
|
||||
class CCRC16of14443B : public CCRC16
|
||||
{
|
||||
public:
|
||||
CCRC16of14443B(void)
|
||||
{
|
||||
}
|
||||
~CCRC16of14443B(void)
|
||||
{
|
||||
}
|
||||
|
||||
int GetCRC16( BYTE aBuf[], UINT16 u16Len, BYTE *pCRCMSB, BYTE *pCRCLSB )
|
||||
{
|
||||
return CCRC16::GetCRC16( 0xFFFF, aBuf, u16Len, pCRCMSB, pCRCLSB );
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
38
Labs/Lab2/requirements/src/rfidsrc/class/OddParity.cpp
Normal file
38
Labs/Lab2/requirements/src/rfidsrc/class/OddParity.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "StdAfx.h"
|
||||
#include "OddParity.h"
|
||||
|
||||
namespace VSPR_OF_ISO14443A
|
||||
{
|
||||
COddParity::COddParity(void)
|
||||
{
|
||||
}
|
||||
|
||||
COddParity::COddParity(BYTE btDat )
|
||||
{
|
||||
m_btDat = btDat;
|
||||
}
|
||||
|
||||
COddParity::~COddParity(void)
|
||||
{
|
||||
}
|
||||
|
||||
int COddParity::GetOddParity()
|
||||
{
|
||||
int n = 0;
|
||||
for( int i = 0; i < 8; i++ )
|
||||
{
|
||||
if( (m_btDat >> i) & 0x01 )
|
||||
{
|
||||
n++;
|
||||
}
|
||||
}
|
||||
return (n % 2)?0:1;
|
||||
}
|
||||
|
||||
int COddParity::GetOddParity( BYTE byDat )
|
||||
{
|
||||
m_btDat = byDat;
|
||||
|
||||
return GetOddParity( );
|
||||
}
|
||||
}
|
||||
20
Labs/Lab2/requirements/src/rfidsrc/class/OddParity.h
Normal file
20
Labs/Lab2/requirements/src/rfidsrc/class/OddParity.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
namespace VSPR_OF_ISO14443A
|
||||
{
|
||||
class COddParity
|
||||
{
|
||||
public:
|
||||
COddParity(void);
|
||||
COddParity(BYTE btDat );
|
||||
|
||||
~COddParity(void);
|
||||
public:
|
||||
int GetOddParity( );
|
||||
int GetOddParity( BYTE btDat );
|
||||
|
||||
protected:
|
||||
BYTE m_btDat;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
137
Labs/Lab2/requirements/src/rfidsrc/class/clUSPTrans.h
Normal file
137
Labs/Lab2/requirements/src/rfidsrc/class/clUSPTrans.h
Normal file
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* \file clUSPTrans.h
|
||||
*
|
||||
* USP <20>˵<EFBFBD>transceiver.
|
||||
*/
|
||||
|
||||
#include "clVSPRCOM.h"
|
||||
|
||||
#ifndef _CLASS_USP_TRANS_H_
|
||||
#define _CLASS_USP_TRANS_H_
|
||||
|
||||
namespace VSPR_OF_ISO14443A
|
||||
{
|
||||
/**
|
||||
* <09><><EFBFBD><EFBFBD>USP<53><50>PCD/PICC֮<43><D6AE><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8>
|
||||
*
|
||||
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>USP<53><50>
|
||||
*/
|
||||
class clUSPTransceiver : public clVSPRUDPTransceiver
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* NULL<4C><4C>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>.
|
||||
*/
|
||||
clUSPTransceiver( char *szRemoteIpAddr = NULL )
|
||||
: clVSPRUDPTransceiver( szRemoteIpAddr )
|
||||
{
|
||||
}
|
||||
~clUSPTransceiver()
|
||||
{
|
||||
}
|
||||
int Init( char *szRemoteIPAddr = NULL )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
clVSPRUDPTransceiver::Init( szRemoteIPAddr );
|
||||
m_pTx = (clVSPRUDPSocket_Tx *)(new clUSPToVSPR( m_szRemoteIpAddr ));
|
||||
if( !m_pTx )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if( m_pTx->Init() < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
m_pRx = (clVSPRUDPSocket_Rx *)(new clUSPFromVSPR( ));
|
||||
if( !m_pRx )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if( m_pRx->Init() < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* <09><><EFBFBD><EFBFBD>USP<53><50>PCD/PICC֮<43><D6AE><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8>
|
||||
*
|
||||
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>VSPR<50><52>
|
||||
*/
|
||||
class clVSPRTransceiver : public clVSPRUDPTransceiver
|
||||
{
|
||||
public:
|
||||
clVSPRTransceiver( char *szRemoteIpAddr = NULL )
|
||||
: clVSPRUDPTransceiver( szRemoteIpAddr )
|
||||
{
|
||||
}
|
||||
~clVSPRTransceiver()
|
||||
{
|
||||
}
|
||||
int Init( char *szRemoteIPAddr = NULL )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
clVSPRUDPTransceiver::Init( szRemoteIPAddr );
|
||||
m_pTx = (clVSPRUDPSocket_Tx *)(new clVSPRToUSP( m_szRemoteIpAddr ));
|
||||
if( !m_pTx )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if( m_pTx->Init() < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
m_pRx = (clVSPRUDPSocket_Rx *)(new clVSPRFromUSP( ));
|
||||
if( !m_pRx )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if( m_pRx->Init() < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
#if 0
|
||||
/**
|
||||
* API<50>ӿ<EFBFBD>
|
||||
*/
|
||||
clUSPTransceiver* g_pUSPTrans = NULL;
|
||||
|
||||
int USP_To_VSPR_Init( char *vsprIp = NULL )
|
||||
{
|
||||
if( !g_pUSPTrans )
|
||||
{
|
||||
g_pUSPTrans = new clUSPTransceiver( vsprIp );
|
||||
if( !g_pUSPTrans )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if( g_pUSPTrans->Init() < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int USP_To_VSPR_Tx(UCHAR *pBuf, UINT16 u16BitLen, UCHAR ucCmd )
|
||||
{
|
||||
USP_Init();
|
||||
return g_pUSPTrans->Send( pBuf, u16BitLen, ucCmd);
|
||||
};
|
||||
|
||||
int USP_FROM_VSPR_Rx(UCHAR *pBuf, UINT16 u16BufLen, UCHAR *pucCmd )
|
||||
{
|
||||
USP_Init();
|
||||
return g_pUSPTrans->Recv( pBuf, u16BufLen, pucCmd);
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
674
Labs/Lab2/requirements/src/rfidsrc/class/clVSPRCOM.h
Normal file
674
Labs/Lab2/requirements/src/rfidsrc/class/clVSPRCOM.h
Normal file
@@ -0,0 +1,674 @@
|
||||
#include "..\rfid_def.h"
|
||||
|
||||
#ifdef _OS_WINDOWS_
|
||||
#include "winsock.h"
|
||||
#include "Winsock2.h"
|
||||
#include <afxmt.h>
|
||||
#include <io.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef _IDE_VS2010_
|
||||
#define close _close
|
||||
#endif
|
||||
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#define DEBUG
|
||||
#ifdef DEBUG
|
||||
#define VSPR_TRACE() printf("\n%s %d %s", __FILE__, __LINE__, __FUNCTION__ );
|
||||
#define VSPR_TRACE1(x) x;
|
||||
#else
|
||||
#define VSPR_TRACE()
|
||||
#define VSPR_TRACE1(x)
|
||||
#endif
|
||||
|
||||
#ifndef _CLASS_VSPR_COM_H_
|
||||
#define _CLASS_VSPR_COM_H_
|
||||
|
||||
/**
|
||||
* namespace: VSPR: visual simulation platform of RFID.
|
||||
*
|
||||
*/
|
||||
namespace VSPR_OF_ISO14443A
|
||||
{
|
||||
|
||||
/*-----------------------------------------------------------------*\
|
||||
* 定义PCD/PICC/USP的UDP侦听端口号
|
||||
*-----------------------------------------------------------------*/
|
||||
#define UDP_PORT_PCD 34566
|
||||
#define UDP_PORT_PICC 34567
|
||||
// 在环境的情况下.
|
||||
#define UDP_PORT_USP 34568
|
||||
#define UDP_PORT_VSPR 34579
|
||||
|
||||
#define BROADCAST_IP (char *)"224.0.0.1"
|
||||
#define LOCAL_IP (char *)"127.0.0.1"
|
||||
|
||||
/*-----------------------------------------------------------------*\
|
||||
* Rx方向
|
||||
*
|
||||
*-----------------------------------------------------------------*/
|
||||
|
||||
class clUDPSocket_Rx
|
||||
{
|
||||
public:
|
||||
clUDPSocket_Rx( USHORT usPort = 0 )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
m_usPortId = usPort;
|
||||
m_nSocketId = -1;
|
||||
memset( (void *)&m_stAddr, 0x00, sizeof( m_stAddr ));
|
||||
}
|
||||
|
||||
virtual ~clUDPSocket_Rx( )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
if( m_nSocketId != -1 )
|
||||
{
|
||||
closesocket( m_nSocketId );
|
||||
m_nSocketId = -1;
|
||||
}
|
||||
}
|
||||
|
||||
virtual int Init( USHORT usPort = 0 )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
{
|
||||
WSADATA wsa;
|
||||
if (WSAStartup(MAKEWORD(2,2),&wsa) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if( m_nSocketId == -1 )
|
||||
{
|
||||
m_nSocketId = socket( AF_INET, SOCK_DGRAM, 0 );
|
||||
}
|
||||
// 如果Init()传入了新的port参数,则采用这个参数。
|
||||
if( usPort != 0 )
|
||||
{
|
||||
m_usPortId = usPort;
|
||||
}
|
||||
// 如果构造和Init()都没有传入新的参数,则返回错误。
|
||||
if( m_usPortId == 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// bzero( &m_stAddr, sizeof( m_stAddr ));
|
||||
memset( &m_stAddr, 0x00, sizeof( m_stAddr ));
|
||||
|
||||
m_stAddr.sin_family = AF_INET;
|
||||
m_stAddr.sin_addr.s_addr = htonl( INADDR_ANY );
|
||||
m_stAddr.sin_port = htons( m_usPortId );
|
||||
|
||||
bind( m_nSocketId, (struct sockaddr *)&m_stAddr, sizeof( m_stAddr ));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 默认阻塞接收
|
||||
// 可以返回发送方的 ip 地址和 port
|
||||
int Recvfrom( UCHAR *pucBuf, USHORT usBufLen )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
|
||||
VSPR_TRACE1(printf("\nsocketid=%d, local udp port=%d\n", m_nSocketId, m_usPortId ));
|
||||
return recv( m_nSocketId, (char *)pucBuf, usBufLen, 0 );
|
||||
}
|
||||
|
||||
// 用于支持select操作.
|
||||
int GetSocketId( )
|
||||
{
|
||||
return m_nSocketId;
|
||||
}
|
||||
// 设置为非阻塞方式, 默认为阻塞方式
|
||||
// 默认为200ms.
|
||||
void SetUnBlock( int delayTime = 200000 )
|
||||
{
|
||||
struct timeval timeout = {0,delayTime}; // 200ms.
|
||||
setsockopt( m_nSocketId, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout,sizeof(struct timeval));
|
||||
}
|
||||
|
||||
protected:
|
||||
int m_nSocketId; // socket id.
|
||||
|
||||
USHORT m_usPortId; // UDP端口号
|
||||
struct sockaddr_in m_stAddr;
|
||||
int m_sin_len;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* 按VSPR的数据格式要求,解析Header,执行如下功能:
|
||||
* 1. 判断:方向
|
||||
* 2. 必要时,判断命令;
|
||||
*/
|
||||
class clVSPRUDPSocket_Rx : public clUDPSocket_Rx
|
||||
{
|
||||
public:
|
||||
clVSPRUDPSocket_Rx( UCHAR ucDirection = DIRECTION_UNDEFINED, USHORT usPort = 0 )
|
||||
: clUDPSocket_Rx( usPort )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
m_ucDirection = ucDirection;
|
||||
}
|
||||
|
||||
~clVSPRUDPSocket_Rx()
|
||||
{
|
||||
VSPR_TRACE();
|
||||
}
|
||||
|
||||
virtual int Init( UCHAR ucDirection = DIRECTION_UNDEFINED, USHORT usPort = 0 )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
|
||||
if( ucDirection != DIRECTION_UNDEFINED )
|
||||
{
|
||||
m_ucDirection = ucDirection;
|
||||
}
|
||||
|
||||
if( m_ucDirection == DIRECTION_UNDEFINED )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return clUDPSocket_Rx::Init( usPort );
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回接收比特长度!
|
||||
* u16BufLen: 是缓冲区 pucBuf 的字节长度
|
||||
*/
|
||||
virtual int Recv( UCHAR *pucBuf, UINT16 u16BufLen, UCHAR *pucCmd )
|
||||
{
|
||||
UINT16 u16Len;
|
||||
UINT32 u32bitLen;
|
||||
int n;
|
||||
|
||||
VSPR_TRACE();
|
||||
n = Recvfrom( m_aucRxBuf, 1024);
|
||||
#ifdef DEBUG
|
||||
printf("\nrx byte len = %d", n);
|
||||
for( int i = 0; i < n; i++ )
|
||||
{
|
||||
printf("%02x ", m_aucRxBuf[i] );
|
||||
}
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
/**
|
||||
* 接收包是否合格
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* 1.长度是否合格;
|
||||
*/
|
||||
if( n <= 8 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 取长度
|
||||
u32bitLen = *((UINT32 *)&m_aucRxBuf[4]);
|
||||
u32bitLen = ntohl(u32bitLen);
|
||||
|
||||
// payload字节长度
|
||||
u16Len = u32bitLen / 8 + ((u32bitLen % 8)?1:0);
|
||||
n -= 8 + u16Len;
|
||||
VSPR_TRACE1( printf("\nrx bitlen = %lu, n = %d", u32bitLen, n));
|
||||
// 数据包长度错误
|
||||
if( n )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 判断包头等
|
||||
if( m_aucRxBuf[0] != VSPR_HEADER_MARK )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if( m_aucRxBuf[1] != m_ucDirection )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( pucCmd )
|
||||
{
|
||||
*pucCmd = m_aucRxBuf[2];
|
||||
}
|
||||
|
||||
// 复制数据
|
||||
if( u16Len <= u16BufLen )
|
||||
{
|
||||
memcpy( pucBuf, &m_aucRxBuf[8], u16Len);
|
||||
return u32bitLen;
|
||||
}
|
||||
|
||||
// 缓冲区长度不足
|
||||
return -2;
|
||||
}
|
||||
|
||||
protected:
|
||||
UCHAR m_ucDirection;
|
||||
UCHAR m_aucRxBuf[1024];
|
||||
};
|
||||
|
||||
class clUSPFromVSPR : public clVSPRUDPSocket_Rx
|
||||
{
|
||||
public:
|
||||
clUSPFromVSPR( )
|
||||
:clVSPRUDPSocket_Rx(DIRECTION_USP_FROM_VSPR, UDP_PORT_USP)
|
||||
{
|
||||
VSPR_TRACE();
|
||||
}
|
||||
~clUSPFromVSPR( )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
}
|
||||
};
|
||||
class clVSPRFromUSP : public clVSPRUDPSocket_Rx
|
||||
{
|
||||
public:
|
||||
clVSPRFromUSP( )
|
||||
:clVSPRUDPSocket_Rx(DIRECTION_VSPR_FROM_USP, UDP_PORT_VSPR )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
}
|
||||
~clVSPRFromUSP( )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
}
|
||||
};
|
||||
|
||||
class clPCDFromPICC : public clVSPRUDPSocket_Rx
|
||||
{
|
||||
public:
|
||||
clPCDFromPICC( )
|
||||
:clVSPRUDPSocket_Rx(DIRECTION_PCD_FROM_PICC, UDP_PORT_PCD)
|
||||
{
|
||||
VSPR_TRACE();
|
||||
}
|
||||
~clPCDFromPICC( )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
}
|
||||
};
|
||||
|
||||
class clPICCFromPCD : public clVSPRUDPSocket_Rx
|
||||
{
|
||||
public:
|
||||
clPICCFromPCD( )
|
||||
:clVSPRUDPSocket_Rx( DIRECTION_PICC_FROM_PCD, UDP_PORT_PICC)
|
||||
{
|
||||
VSPR_TRACE();
|
||||
}
|
||||
~clPICCFromPCD( )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
|
||||
setsockopt(m_nSocketId, IPPROTO_IP, IP_DROP_MEMBERSHIP, (const char *)&m_stCommand, sizeof( m_stCommand ));
|
||||
}
|
||||
#ifdef PCD_TO_PICC_USE_BROAD
|
||||
/**
|
||||
* 对于PICC,其接收的是组播消息.
|
||||
*
|
||||
*/
|
||||
virtual int Init( UCHAR ucDirection = DIRECTION_UNDEFINED, USHORT usPort = 0 )
|
||||
{
|
||||
int r;
|
||||
struct ip_mreq command;
|
||||
|
||||
VSPR_TRACE();
|
||||
r = clVSPRUDPSocket_Rx::Init( ucDirection, usPort );
|
||||
// allow multiple processses to use this port.
|
||||
int loop = 1;
|
||||
setsockopt( m_nSocketId, SOL_SOCKET, SO_REUSEADDR, (const char *)&loop, sizeof(loop ));
|
||||
|
||||
// allow broadcart to this machine
|
||||
setsockopt( m_nSocketId, IPPROTO_IP, IP_MULTICAST_LOOP, (const char *)&loop, sizeof( loop ));
|
||||
|
||||
// join the broadcast group
|
||||
m_stCommand.imr_multiaddr.s_addr = inet_addr(BROADCAST_IP);
|
||||
m_stCommand.imr_interface.s_addr = htonl( INADDR_ANY );
|
||||
setsockopt( m_nSocketId, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const char *)&m_stCommand, sizeof(m_stCommand));
|
||||
}
|
||||
#endif
|
||||
protected:
|
||||
struct ip_mreq m_stCommand;
|
||||
};
|
||||
|
||||
/*-----------------------------------------------------------------*\
|
||||
* Tx方向
|
||||
*
|
||||
*-----------------------------------------------------------------*/
|
||||
|
||||
class clUDPSocket_Tx
|
||||
{
|
||||
public:
|
||||
clUDPSocket_Tx( )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
m_nSocketId = -1;
|
||||
m_usRemoteUDPPort = 0;
|
||||
m_szRemoteIpAddr[0] = 0x00;
|
||||
memset( (void *)&m_stAddr, 0x00, sizeof( m_stAddr ));
|
||||
}
|
||||
|
||||
clUDPSocket_Tx( USHORT usRemoteUDPPort, char *szRemoteIPAddr = NULL )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
m_nSocketId = -1;
|
||||
m_usRemoteUDPPort = usRemoteUDPPort;
|
||||
memset( (void *)&m_stAddr, 0x00, sizeof( m_stAddr ));
|
||||
if( szRemoteIPAddr )
|
||||
{
|
||||
strcpy_s( m_szRemoteIpAddr, szRemoteIPAddr );
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~clUDPSocket_Tx( )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
if( m_nSocketId != -1 )
|
||||
{
|
||||
closesocket( m_nSocketId );
|
||||
m_nSocketId = -1;
|
||||
}
|
||||
}
|
||||
|
||||
int Init( USHORT usRemoteUDPPort = 0, char *szRemoteIpAddr = NULL )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
|
||||
{
|
||||
WSADATA wsa;
|
||||
if (WSAStartup(MAKEWORD(2,2),&wsa) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if( m_nSocketId == -1 )
|
||||
{
|
||||
m_nSocketId = socket( AF_INET, SOCK_DGRAM, 0 );
|
||||
}
|
||||
|
||||
if( szRemoteIpAddr )
|
||||
{
|
||||
strcpy_s( m_szRemoteIpAddr, szRemoteIpAddr );
|
||||
}
|
||||
|
||||
if( m_szRemoteIpAddr[0] == 0x00 )
|
||||
{
|
||||
strcpy_s( m_szRemoteIpAddr, LOCAL_IP );
|
||||
}
|
||||
|
||||
if( usRemoteUDPPort )
|
||||
{
|
||||
m_usRemoteUDPPort = usRemoteUDPPort;
|
||||
}
|
||||
|
||||
// bzero( &m_stAddr, sizeof( m_stAddr ));
|
||||
memset( &m_stAddr, 0x00, sizeof( m_stAddr ));
|
||||
m_stAddr.sin_family = AF_INET;
|
||||
m_stAddr.sin_addr.s_addr = inet_addr( m_szRemoteIpAddr );
|
||||
m_stAddr.sin_port = htons( m_usRemoteUDPPort );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SendTo( UCHAR *pucBuf, USHORT usBufLen )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
if( m_nSocketId != -1 && m_usRemoteUDPPort != 0 )
|
||||
{
|
||||
VSPR_TRACE1( printf("\nsocketid=%d, remote udp port=%d, hostip = %s", m_nSocketId, m_usRemoteUDPPort, m_szRemoteIpAddr ));
|
||||
return sendto( m_nSocketId, (const char *)pucBuf, usBufLen, 0, (struct sockaddr *)&m_stAddr, sizeof( m_stAddr ));
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
int m_nSocketId; // socket id.
|
||||
|
||||
char m_szRemoteIpAddr[20];
|
||||
USHORT m_usRemoteUDPPort;
|
||||
|
||||
struct sockaddr_in m_stAddr;
|
||||
int m_sin_len;
|
||||
};
|
||||
|
||||
class clVSPRUDPSocket_Tx : public clUDPSocket_Tx
|
||||
{
|
||||
public:
|
||||
clVSPRUDPSocket_Tx( )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
m_ucDirection = DIRECTION_UNDEFINED;
|
||||
}
|
||||
|
||||
clVSPRUDPSocket_Tx( UCHAR ucDirection, USHORT usRemoteUDPPort, char *szRemoteIPAddr = NULL )
|
||||
: clUDPSocket_Tx( usRemoteUDPPort, szRemoteIPAddr )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
m_ucDirection = ucDirection;
|
||||
}
|
||||
|
||||
~clVSPRUDPSocket_Tx()
|
||||
{
|
||||
VSPR_TRACE();
|
||||
}
|
||||
|
||||
int Init( UCHAR ucDirection, USHORT usRemoteUDPPort, char *szRemoteIpAddr = NULL )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
m_ucDirection = ucDirection;
|
||||
m_aucTxBuf[0] = VSPR_HEADER_MARK;
|
||||
m_aucTxBuf[1] = m_ucDirection;
|
||||
return clUDPSocket_Tx::Init( usRemoteUDPPort, szRemoteIpAddr );
|
||||
}
|
||||
|
||||
int Init( )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
m_aucTxBuf[0] = VSPR_HEADER_MARK;
|
||||
m_aucTxBuf[1] = m_ucDirection;
|
||||
return clUDPSocket_Tx::Init( );
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送比特长度数据!
|
||||
*
|
||||
*/
|
||||
virtual int Send( UCHAR *pucBuf, UINT32 u32BitLen, UCHAR ucCmd = VSPR_CMD_UNSED )
|
||||
{
|
||||
UINT16 u16SendLen;
|
||||
|
||||
VSPR_TRACE();
|
||||
m_aucTxBuf[2] = ucCmd;
|
||||
m_aucTxBuf[3] = 0x00;
|
||||
|
||||
*((UINT32 *)&m_aucTxBuf[4]) = htonl(u32BitLen);
|
||||
|
||||
u16SendLen = u32BitLen / 8;
|
||||
u16SendLen += ( u32BitLen % 8 ) ? 1:0;
|
||||
|
||||
memcpy( &m_aucTxBuf[8], pucBuf, u16SendLen );
|
||||
|
||||
return SendTo( m_aucTxBuf, u16SendLen + 8 );
|
||||
}
|
||||
protected:
|
||||
UCHAR m_ucDirection;
|
||||
UCHAR m_aucTxBuf[1024];
|
||||
};
|
||||
|
||||
class clPCDToPICC : public clVSPRUDPSocket_Tx
|
||||
{
|
||||
public:
|
||||
// 如果szRemoteIPAddr
|
||||
// PCDToPICC默认采用多播方式广播,其地址为:224.0.0.1
|
||||
// NULL表示本地,否则远端主机ip地址
|
||||
#ifdef PCD_TO_PICC_USE_BROAD
|
||||
clPCDToPICC( char *szRemoteIPAddr = BROADCAST_IP )
|
||||
#else
|
||||
clPCDToPICC( char *szRemoteIPAddr = NULL )
|
||||
#endif
|
||||
: clVSPRUDPSocket_Tx( DIRECTION_PCD_TO_PICC, UDP_PORT_PICC, szRemoteIPAddr )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
}
|
||||
~clPCDToPICC()
|
||||
{
|
||||
VSPR_TRACE();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 可以继续其他类
|
||||
*/
|
||||
class clPICCToPCD : public clVSPRUDPSocket_Tx
|
||||
{
|
||||
public:
|
||||
clPICCToPCD( char *szRemoteIPAddr = NULL )
|
||||
: clVSPRUDPSocket_Tx( DIRECTION_PICC_TO_PCD, UDP_PORT_PCD, szRemoteIPAddr )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
}
|
||||
~clPICCToPCD()
|
||||
{
|
||||
VSPR_TRACE();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 可以继续其他类
|
||||
*/
|
||||
class clUSPToVSPR : public clVSPRUDPSocket_Tx
|
||||
{
|
||||
public:
|
||||
clUSPToVSPR( char *szRemoteIPAddr = NULL )
|
||||
: clVSPRUDPSocket_Tx( DIRECTION_USP_TO_VSPR, UDP_PORT_VSPR, szRemoteIPAddr )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
}
|
||||
~clUSPToVSPR()
|
||||
{
|
||||
VSPR_TRACE();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 可以继续其他类
|
||||
*/
|
||||
class clVSPRToUSP : public clVSPRUDPSocket_Tx
|
||||
{
|
||||
public:
|
||||
clVSPRToUSP( char *szRemoteIPAddr = NULL )
|
||||
: clVSPRUDPSocket_Tx( DIRECTION_VSPR_TO_USP, UDP_PORT_USP, szRemoteIPAddr )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
}
|
||||
~clVSPRToUSP()
|
||||
{
|
||||
VSPR_TRACE();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 为VSPR平台封装一个采用UDP实现的Transceiver
|
||||
* 在发送和接收方向,分别使用UDP Tx/Rx实现
|
||||
*
|
||||
*/
|
||||
class clVSPRUDPTransceiver
|
||||
{
|
||||
public:
|
||||
clVSPRUDPTransceiver( char *szRemoteIPAddr = NULL )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
m_pTx = NULL;
|
||||
m_pRx = NULL;
|
||||
|
||||
SetRemoteIpAddr( szRemoteIPAddr );
|
||||
}
|
||||
~clVSPRUDPTransceiver()
|
||||
{
|
||||
VSPR_TRACE();
|
||||
if( m_pTx )
|
||||
{
|
||||
delete m_pTx;
|
||||
m_pTx = NULL;
|
||||
}
|
||||
|
||||
if( m_pRx )
|
||||
{
|
||||
delete m_pRx;
|
||||
m_pRx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于new and init两个udp tx/rx类
|
||||
*
|
||||
*/
|
||||
virtual int Init( char *szRemoteIPAddr = NULL )
|
||||
{
|
||||
SetRemoteIpAddr( szRemoteIPAddr );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Send( UCHAR *pucBuf, UINT32 u32BitLen, UCHAR ucCmd = VSPR_CMD_UNSED )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
if( m_pTx )
|
||||
{
|
||||
return m_pTx->Send( pucBuf, u32BitLen, ucCmd );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回:接收数据长度
|
||||
*/
|
||||
int Recv( UCHAR *pucBuf, UINT16 u16BufLen, UCHAR *pucCmd = NULL )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
if( m_pRx )
|
||||
{
|
||||
return m_pRx->Recv( pucBuf, u16BufLen, pucCmd );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
protected:
|
||||
void SetRemoteIpAddr( char *szRemoteIPAddr )
|
||||
{
|
||||
if( szRemoteIPAddr )
|
||||
{
|
||||
strcpy_s( m_szRemoteIpAddr, szRemoteIPAddr );
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy_s( m_szRemoteIpAddr, LOCAL_IP );
|
||||
}
|
||||
}
|
||||
protected:
|
||||
char m_szRemoteIpAddr[10];
|
||||
clVSPRUDPSocket_Tx* m_pTx;
|
||||
clVSPRUDPSocket_Rx* m_pRx;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
171
Labs/Lab2/requirements/src/rfidsrc/class/clVSPRCmd.cpp
Normal file
171
Labs/Lab2/requirements/src/rfidsrc/class/clVSPRCmd.cpp
Normal file
@@ -0,0 +1,171 @@
|
||||
/**
|
||||
* \file clVSPRCmd.cpp
|
||||
*
|
||||
*
|
||||
*/
|
||||
#include "clVSPRCmd.h"
|
||||
|
||||
namespace VSPR_OF_ISO14443A
|
||||
{
|
||||
clVSPRCmd::clVSPRCmd( UCHAR ucHost )
|
||||
{
|
||||
m_ucHost = ucHost;
|
||||
|
||||
m_stTxHeader.ucHeaderMark = VSPR_HEADER_MARK;
|
||||
m_stTxHeader.ucCmd = VSPR_CMD_UNSED;
|
||||
m_stTxHeader.ucRsvd = 0x00;
|
||||
m_stTxHeader.nBitLen = 0;
|
||||
|
||||
m_stRxHeader.ucHeaderMark = VSPR_HEADER_MARK;
|
||||
m_stRxHeader.ucCmd = VSPR_CMD_UNSED;
|
||||
m_stRxHeader.ucRsvd = 0x00;
|
||||
m_stRxHeader.nBitLen = 0;
|
||||
|
||||
switch( m_ucHost )
|
||||
{
|
||||
case HOST_VSPR:
|
||||
m_stTxHeader.ucDirection = DIRECTION_VSPR_TO_USP;
|
||||
m_stRxHeader.ucDirection = DIRECTION_VSPR_FROM_USP;
|
||||
break;
|
||||
case HOST_USP:
|
||||
m_stTxHeader.ucDirection = DIRECTION_USP_TO_VSPR;
|
||||
m_stRxHeader.ucDirection = DIRECTION_USP_FROM_VSPR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
clVSPRCmd::~clVSPRCmd()
|
||||
{
|
||||
}
|
||||
|
||||
bool clVSPRCmd::Init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int clVSPRCmd::GetStream_CODE_1BIT_REQ(UCHAR ucPCD, UCHAR ucPreBit, UCHAR ucBit, UCHAR *streamBuf, int *pstreamBitLen )
|
||||
{
|
||||
UCHAR payloadBuf[3];
|
||||
|
||||
payloadBuf[0] = ucPCD ? 1:0;
|
||||
payloadBuf[1] = ucPreBit ? 1:0;
|
||||
payloadBuf[2] = ucBit ? 1:0;
|
||||
return GetStream( VSPR_CMD_CODE_1BIT_REQ, payloadBuf, 24, streamBuf, pstreamBitLen );
|
||||
}
|
||||
|
||||
int clVSPRCmd::GetStream_CODE_SOF_REQ( UCHAR ucPCD, UCHAR *streamBuf, int *pstreamBitLen )
|
||||
{
|
||||
UCHAR payloadBuf[1];
|
||||
|
||||
payloadBuf[0] = ucPCD ? 1:0;
|
||||
return GetStream( VSPR_CMD_CODE_SOF_REQ, payloadBuf, 8, streamBuf, pstreamBitLen );
|
||||
}
|
||||
|
||||
int clVSPRCmd::GetStream_CODE_EOF_REQ( UCHAR ucPCD, UCHAR ucPreBit, UCHAR *streamBuf, int *pstreamBitLen )
|
||||
{
|
||||
UCHAR payloadBuf[2];
|
||||
|
||||
payloadBuf[0] = ucPCD ? 1:0;
|
||||
payloadBuf[1] = ucPreBit ? 1:0;
|
||||
return GetStream( VSPR_CMD_CODE_EOF_REQ, payloadBuf, 16, streamBuf, pstreamBitLen );
|
||||
}
|
||||
|
||||
|
||||
int clVSPRCmd::GetStream_CODE_FRAME_REQ( UCHAR ucPCD, UCHAR buf[], int bufBitLen, UCHAR *streamBuf, int *pstreamBitLen )
|
||||
{
|
||||
UCHAR payloadBuf[1024];
|
||||
|
||||
payloadBuf[0] = ucPCD ? 1:0;
|
||||
memcpy( payloadBuf+1, buf, bufBitLen/8+((bufBitLen%8)?1:0));
|
||||
return GetStream( VSPR_CMD_CODE_FRAME_REQ, payloadBuf, bufBitLen+8, streamBuf, pstreamBitLen );
|
||||
}
|
||||
|
||||
|
||||
int clVSPRCmd::GetCmd_CODE_1BIT_REQ( UCHAR *streamBuf, int streamBitLen, UCHAR *pucPCD, UCHAR *Coded )
|
||||
{
|
||||
*pucPCD = streamBuf[0];
|
||||
*Coded = streamBuf[1];
|
||||
return 16;
|
||||
}
|
||||
|
||||
int clVSPRCmd::GetCmd_CODE_SOF_REQ( UCHAR *streamBuf, int streamBitLen, UCHAR *pucPCD, UCHAR *Coded )
|
||||
{
|
||||
*pucPCD = streamBuf[0];
|
||||
*Coded = streamBuf[1];
|
||||
return 16;
|
||||
}
|
||||
|
||||
int clVSPRCmd::GetCmd_CODE_EOF_REQ( UCHAR *streamBuf, int streamBitLen, UCHAR *pucPCD, UCHAR *Coded )
|
||||
{
|
||||
*pucPCD = streamBuf[0];
|
||||
*Coded = streamBuf[1];
|
||||
return 16;
|
||||
}
|
||||
|
||||
int clVSPRCmd::GetCmd_CODE_FRAME_REQ( UCHAR *streamBuf, int streamBitLen, UCHAR *pucPCD, UCHAR *pCodedBuf, int *pbufBitLen )
|
||||
{
|
||||
UCHAR ucCmdId;
|
||||
*pucPCD = streamBuf[0];
|
||||
return GetCmd(streamBuf+1,streamBitLen-8, &ucCmdId, pCodedBuf, pbufBitLen);
|
||||
}
|
||||
|
||||
int clVSPRCmd::GetStream( UCHAR cmdId, UCHAR *payloadBuf, int payloadBitLen, UCHAR *streamBuf, int *pstreamBitLen )
|
||||
{
|
||||
int len = 0, k;
|
||||
|
||||
m_stTxHeader.ucCmd = cmdId;
|
||||
m_stTxHeader.nBitLen = payloadBitLen;
|
||||
|
||||
memcpy( streamBuf, &m_stTxHeader, sizeof(m_stTxHeader));
|
||||
len += sizeof(m_stTxHeader);
|
||||
|
||||
k = payloadBitLen/8;
|
||||
memcpy( streamBuf+len, payloadBuf, k );
|
||||
len += k;
|
||||
|
||||
if( payloadBitLen%8 )
|
||||
{
|
||||
streamBuf[len] = 0x00;
|
||||
#if 0
|
||||
for( int i = 0; i <payloadBitLen%8; i++ )
|
||||
{
|
||||
streamBuf[len] |= (payloadBuf[k] >> (7-i)) & 1;
|
||||
}
|
||||
#endif
|
||||
streamBuf[len] = payloadBuf[k];
|
||||
|
||||
len++;
|
||||
}
|
||||
|
||||
*pstreamBitLen = payloadBitLen + 8 * sizeof(m_stRxHeader);
|
||||
return len;
|
||||
}
|
||||
|
||||
int clVSPRCmd::GetCmd( UCHAR *streamBuf, int streamBitLen, UCHAR *pcmdId, UCHAR *payloadBuf, int *payloadBitLen )
|
||||
{
|
||||
int len = 0, k;
|
||||
|
||||
memcpy( payloadBuf, streamBuf, sizeof(m_stRxHeader));
|
||||
len += sizeof(m_stRxHeader);
|
||||
*pcmdId = m_stRxHeader.ucCmd;
|
||||
|
||||
k = streamBitLen/8-len;
|
||||
memcpy( payloadBuf, streamBuf+len, k );
|
||||
len += k;
|
||||
|
||||
if( streamBitLen%8 )
|
||||
{
|
||||
payloadBuf[k] = 0x00;
|
||||
for( int i = (streamBitLen%8)-1; i >= 0; i-- )
|
||||
{
|
||||
streamBuf[k] |= (payloadBuf[len] >> (7-i)) & 1;
|
||||
}
|
||||
len++;
|
||||
}
|
||||
|
||||
*payloadBitLen = streamBitLen - 8 * sizeof(m_stRxHeader);
|
||||
m_stRxHeader.nBitLen = *payloadBitLen;
|
||||
|
||||
return len;
|
||||
}
|
||||
}
|
||||
100
Labs/Lab2/requirements/src/rfidsrc/class/clVSPRCmd.h
Normal file
100
Labs/Lab2/requirements/src/rfidsrc/class/clVSPRCmd.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* \file clVSPRCmd.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
#include "..\rfid_def.h"
|
||||
namespace VSPR_OF_ISO14443A
|
||||
{
|
||||
|
||||
class clVSPRCmd
|
||||
{
|
||||
public:
|
||||
clVSPRCmd( UCHAR ucHost );
|
||||
~clVSPRCmd();
|
||||
|
||||
bool Init();
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int GetStream_CODE_1BIT_REQ(UCHAR ucPCD, UCHAR ucPreBit, UCHAR ucBit, UCHAR *streamBuf, int *pstreamBitLen );
|
||||
int GetStream_CODE_SOF_REQ(UCHAR ucPCD, UCHAR *streamBuf, int *pstreamBitLen);
|
||||
int GetStream_CODE_EOF_REQ(UCHAR ucPCD, UCHAR ucPreBit, UCHAR *streamBuf, int *pstreamBitLen);
|
||||
int GetStream_CODE_FRAME_REQ(UCHAR ucPCD, UCHAR buf[], int bufBitLen, UCHAR *streamBuf, int *pstreamBitLen );
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ
|
||||
int GetCmd_CODE_1BIT_REQ( UCHAR *streamBuf, int streamBitLen, UCHAR *pucPCD, UCHAR *Coded );
|
||||
int GetCmd_CODE_SOF_REQ( UCHAR *streamBuf, int streamBitLen, UCHAR *pucPCD, UCHAR *Coded );
|
||||
int GetCmd_CODE_EOF_REQ( UCHAR *streamBuf, int streamBitLen, UCHAR *pucPCD, UCHAR *Coded );
|
||||
int GetCmd_CODE_FRAME_REQ( UCHAR *streamBuf, int streamBitLen, UCHAR *pucPCD, UCHAR *pCodedBuf, int *pbufBitLen );
|
||||
|
||||
// У<><D0A3>
|
||||
int GetStream_ODD_PARITY_REQ( UCHAR dat, UCHAR *streamBuf, int *pstreamBitLen )
|
||||
{
|
||||
return GetStream( VSPR_CMD_ODD_PARITY_REQ, &dat, 8, streamBuf, pstreamBitLen );
|
||||
}
|
||||
int GetStream_CRC16_REQ( UCHAR buf[], int bufLen, UCHAR *streamBuf, int *pstreamBitLen )
|
||||
{
|
||||
return GetStream( VSPR_CMD_CRC16_REQ, buf, bufLen*8, streamBuf, pstreamBitLen );
|
||||
}
|
||||
|
||||
int GetCmd_ODD_PARITY_REQ( UCHAR *streamBuf, int *pstreamBitLen, UCHAR *parity )
|
||||
{
|
||||
*parity = streamBuf[8];
|
||||
return 1;
|
||||
}
|
||||
|
||||
int GetCmd_CRC16_REQ( UCHAR streamBuf[], int streamBufBitLen, UCHAR *lsb, UCHAR *msb )
|
||||
{
|
||||
*lsb = streamBuf[8];
|
||||
*msb = streamBuf[9];
|
||||
return 2;
|
||||
}
|
||||
#if 0
|
||||
// <20><>֡
|
||||
#define VSPR_CMD_UNFRAME_SHORT_REQ 0x28
|
||||
#define VSPR_CMD_UNFRAME_SHORT_RSP 0xA8
|
||||
#define VSPR_CMD_UNFRAME_STD_REQ 0x29
|
||||
#define VSPR_CMD_UNFRAME_STD_RSP 0xA9
|
||||
#define VSPR_CMD_UNFRAME_ANTICOLISSION_REQ 0x2A
|
||||
#define VSPR_CMD_UNFRAME_ANTICOLISSION_RSP 0xAA
|
||||
|
||||
int Get
|
||||
#endif
|
||||
|
||||
protected:
|
||||
// <0ʧ<30><CAA7>
|
||||
// <20><><EFBFBD>룺<EFBFBD><EBA3BA><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽڵ<D6BD><DAB5><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD>ϣ<EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD>stream<61><6D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><DAB7>ͣ<EFBFBD>
|
||||
int GetStream( UCHAR cmdId, UCHAR *payloadBuf, int payloadBitLen, UCHAR *streamBuf, int *pstreamBitLen );
|
||||
|
||||
// <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݺ<EFBFBD><DDBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD>ȣ<EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽڵ<D6BD><DAB5><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD>ϣ<EFBFBD>
|
||||
int GetCmd( UCHAR *streamBuf, int streamBitLen, UCHAR *pcmdId, UCHAR *payloadBuf, int *payloadBitLen );
|
||||
protected:
|
||||
UCHAR m_ucHost;
|
||||
HeaderOfVSPRCOM m_stTxHeader;
|
||||
HeaderOfVSPRCOM m_stRxHeader;
|
||||
|
||||
};
|
||||
|
||||
class clVSPR_VSPR : public clVSPRCmd
|
||||
{
|
||||
public:
|
||||
clVSPR_VSPR( )
|
||||
: clVSPRCmd( HOST_VSPR )
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class clVSPR_USP : public clVSPRCmd
|
||||
{
|
||||
public:
|
||||
clVSPR_USP( )
|
||||
: clVSPRCmd( HOST_USP )
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
131
Labs/Lab2/requirements/src/rfidsrc/class/clVSPRTrans.h
Normal file
131
Labs/Lab2/requirements/src/rfidsrc/class/clVSPRTrans.h
Normal file
@@ -0,0 +1,131 @@
|
||||
/**
|
||||
* clVSPRTrans.h
|
||||
*
|
||||
* PCD/PICC/USP<53><50>ʹ<EFBFBD>õľ<C3B5><C4BE>з<EFBFBD><D0B7>ͺͽ<CDBA><CDBD>չ<EFBFBD><D5B9>ܵ<EFBFBD><DCB5>࣬<EFBFBD><E0A3AC><EFBFBD>ཫ<EFBFBD><E0BDAB>װTx<54><78>Rx<52><78>.
|
||||
*/
|
||||
|
||||
#include "clVSPRCOM.h"
|
||||
|
||||
#ifndef _CLASS_VSPR_TRANS_H_
|
||||
#define _CLASS_VSPR_TRANS_H_
|
||||
|
||||
namespace VSPR_OF_ISO14443A
|
||||
{
|
||||
/**
|
||||
* PCD Trans<6E><73>ʵ<EFBFBD>ֺ<EFBFBD>PICC<43><43>ͨѶ.
|
||||
*
|
||||
*/
|
||||
class clPCDTransceiver : public clVSPRUDPTransceiver
|
||||
{
|
||||
public:
|
||||
clPCDTransceiver( char *szRemoteIpAddr = NULL )
|
||||
: clVSPRUDPTransceiver( szRemoteIpAddr )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
|
||||
// PCD<43><44><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>ǹ㲥<C7B9><E3B2A5>ַ.
|
||||
if( szRemoteIpAddr == NULL )
|
||||
{
|
||||
#ifdef PCD_TO_PICC_USE_BROAD
|
||||
strcpy( m_szRemoteIpAddr, BROADCAST_IP );
|
||||
#else
|
||||
strcpy( m_szRemoteIpAddr, LOCAL_IP );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
~clPCDTransceiver()
|
||||
{
|
||||
VSPR_TRACE();
|
||||
}
|
||||
|
||||
int Init( char *szRemoteIpAddr = NULL )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
|
||||
clVSPRUDPTransceiver::Init( szRemoteIpAddr );
|
||||
if( szRemoteIpAddr == NULL )
|
||||
{
|
||||
#ifdef PCD_TO_PICC_USE_BROAD
|
||||
strcpy( m_szRemoteIpAddr, BROADCAST_IP );
|
||||
#else
|
||||
strcpy( m_szRemoteIpAddr, LOCAL_IP );
|
||||
#endif
|
||||
}
|
||||
|
||||
m_pTx = (clVSPRUDPSocket_Tx *)(new clPCDToPICC( m_szRemoteIpAddr ));
|
||||
if( !m_pTx )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if( m_pTx->Init() < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
m_pRx = (clVSPRUDPSocket_Rx *)(new clPCDFromPICC( ));
|
||||
if( !m_pRx )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if( m_pRx->Init() < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* PICC Trans<6E><73>ʵ<EFBFBD>ֺ<EFBFBD>PCD<43><44>ͨѶ.
|
||||
*
|
||||
* Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>PICC<43><43><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>unicast<73><74>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD>շ<EFBFBD><D5B7><EFBFBD>Ϊ<EFBFBD><CEAA>boradcast.
|
||||
*/
|
||||
class clPICCTransceiver : public clVSPRUDPTransceiver
|
||||
{
|
||||
public:
|
||||
clPICCTransceiver( char *szRemoteIpAddr = NULL )
|
||||
: clVSPRUDPTransceiver( szRemoteIpAddr )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
}
|
||||
~clPICCTransceiver( )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
}
|
||||
|
||||
int Init( char *szRemoteIPAddr = NULL )
|
||||
{
|
||||
VSPR_TRACE();
|
||||
clVSPRUDPTransceiver::Init( szRemoteIPAddr );
|
||||
|
||||
m_pTx = (clVSPRUDPSocket_Tx *)(new clPICCToPCD( m_szRemoteIpAddr ));
|
||||
if( !m_pTx )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if( m_pTx->Init() < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
m_pRx = (clVSPRUDPSocket_Rx *)(new clPICCFromPCD( ));
|
||||
if( !m_pRx )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if( m_pRx->Init() < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
protected:
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
59
Labs/Lab2/requirements/src/rfidsrc/pcd_thread.cpp
Normal file
59
Labs/Lab2/requirements/src/rfidsrc/pcd_thread.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include "pcd_thread.h"
|
||||
#include "rfid_com.h"
|
||||
#include "rfid_iso14443A_pcd.h"
|
||||
|
||||
|
||||
static HWND g_hWnd;
|
||||
static UINT g_uMsgId;
|
||||
extern int g_firstBitValue;
|
||||
|
||||
void pcd_updateStatus( int status )
|
||||
{
|
||||
SendMessage( g_hWnd, g_uMsgId, NULL, (LPARAM)status );
|
||||
}
|
||||
|
||||
void pcd_postMessage( UCHAR *buf, int nBufBitLen, int npcd_cmd, char *action )
|
||||
{
|
||||
PCD_Thread_Out_prm oprm;
|
||||
|
||||
oprm.buf = buf;
|
||||
oprm.nBufBitLen = nBufBitLen;
|
||||
oprm.npcd_cmd = npcd_cmd;
|
||||
oprm.action = action;
|
||||
|
||||
SendMessage( g_hWnd, g_uMsgId, (WPARAM)&oprm, (LPARAM)0 );
|
||||
}
|
||||
|
||||
bool g_bRun = true;
|
||||
|
||||
void pcd_thread( PCD_Thread_In_prm *pPrm )
|
||||
{
|
||||
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||||
PCD_Thread_In_prm wprm = *pPrm;
|
||||
int k = 0;
|
||||
|
||||
g_hWnd = wprm.hWnd;
|
||||
g_uMsgId = wprm.uMsgId;
|
||||
g_firstBitValue = wprm.nBitValue ? 1:0;
|
||||
|
||||
RFID_COM_PCD_Init( wprm.u16_pcd_rx_port, wprm.u16_picc_rx_port );
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
#if 0
|
||||
UCHAR buf[]={0x12, 0x34, 0x57, 0x78};
|
||||
RFID_Reader_Tx( 32, buf );
|
||||
#endif
|
||||
|
||||
ISO_14443A_PCD stPCD;
|
||||
while( g_bRun )
|
||||
{
|
||||
PCD_ISO14443A_run( &stPCD );
|
||||
if( stPCD.ucStatus == ISO_14443A_PCD_STATE_OK )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>PICC.
|
||||
// pcd_postMessage( 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
RFID_COM_Close();
|
||||
}
|
||||
33
Labs/Lab2/requirements/src/rfidsrc/pcd_thread.h
Normal file
33
Labs/Lab2/requirements/src/rfidsrc/pcd_thread.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef _PCD_THREAD_H_
|
||||
#define _PCD_THREAD_H_
|
||||
|
||||
#include "rfid_def.h"
|
||||
#include <atlbase.h>
|
||||
#include <atlwin.h> // for HWND<4E><44><EFBFBD><EFBFBD>
|
||||
|
||||
typedef struct tag_PCD_Thread_In_prm
|
||||
{
|
||||
HWND hWnd;
|
||||
UINT uMsgId;
|
||||
UINT16 u16_pcd_rx_port;
|
||||
UINT16 u16_picc_rx_port;
|
||||
int nBitValue;
|
||||
}PCD_Thread_In_prm;
|
||||
|
||||
// <20>漰buffer.
|
||||
// <20><><EFBFBD>ΰ<EFBFBD><CEB0><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD>ȥ: <20><><EFBFBD>߲<EFBFBD><DFB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD>
|
||||
typedef struct
|
||||
{
|
||||
UCHAR *buf;
|
||||
int nBufBitLen;
|
||||
int npcd_cmd;
|
||||
char *action;
|
||||
}PCD_Thread_Out_prm;
|
||||
|
||||
// <20>̺߳<DFB3><CCBA><EFBFBD>
|
||||
void pcd_thread( PCD_Thread_In_prm *pPrm );
|
||||
|
||||
void pcd_updateStatus( int status );
|
||||
void pcd_postMessage( UCHAR *buf, int nBufBitLen, int npcd_cmd, char *action );
|
||||
|
||||
#endif
|
||||
58
Labs/Lab2/requirements/src/rfidsrc/picc_thread.cpp
Normal file
58
Labs/Lab2/requirements/src/rfidsrc/picc_thread.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "picc_thread.h"
|
||||
#include "rfid_com.h"
|
||||
#include "rfid_iso14443A_picc.h"
|
||||
|
||||
static HWND g_hWnd;
|
||||
static UINT g_uMsgId;
|
||||
|
||||
void picc_updateStatus( int status )
|
||||
{
|
||||
SendMessage( g_hWnd, g_uMsgId, NULL, (LPARAM)status );
|
||||
}
|
||||
|
||||
void picc_postMessage( UCHAR *buf, int nBufBitLen, int npicc_status, char *action )
|
||||
{
|
||||
PICC_Thread_Out_prm oprm;
|
||||
|
||||
oprm.buf = buf;
|
||||
oprm.nBufBitLen = nBufBitLen;
|
||||
oprm.npicc_status = npicc_status;
|
||||
oprm.action = action;
|
||||
|
||||
SendMessage( g_hWnd, g_uMsgId, (WPARAM)&oprm, (LPARAM)0 );
|
||||
}
|
||||
|
||||
void picc_thread( PICC_Thread_In_prm *pPrm )
|
||||
{
|
||||
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||||
bool m_bRun = true;
|
||||
PICC_Thread_In_prm wprm = *pPrm;
|
||||
|
||||
g_hWnd = wprm.hWnd;
|
||||
g_uMsgId = wprm.uMsgId;
|
||||
|
||||
ISO_14443A_PICC stPICC;
|
||||
|
||||
stPICC.ucStatus = ISO_14443A_STATE_IDLE;
|
||||
stPICC.ucCmpBits = 0;
|
||||
switch( wprm.uc_picc_ID_Len )
|
||||
{
|
||||
case 4:
|
||||
stPICC.ucCLn = 0;
|
||||
break;
|
||||
case 7:
|
||||
stPICC.ucCLn = 1;
|
||||
break;
|
||||
case 10:
|
||||
stPICC.ucCLn = 2;
|
||||
break;
|
||||
}
|
||||
GetUIDFromString( &stPICC, wprm.sz_picc_ID );
|
||||
|
||||
RFID_COM_PICC_Init( wprm.sz_pcd_ip, wprm.u16_pcd_rx_port, wprm.u16_picc_rx_port );
|
||||
|
||||
PICC_ISO14443A_run( &stPICC );
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>SendMessage: <20><>Ϊ<EFBFBD><CEAA><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݵ<EFBFBD>ԭ<EFBFBD><D4AD>.
|
||||
// SendMessage( wprm.hWnd, wprm.uMsgId, 0, 0);
|
||||
}
|
||||
36
Labs/Lab2/requirements/src/rfidsrc/picc_thread.h
Normal file
36
Labs/Lab2/requirements/src/rfidsrc/picc_thread.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef _PICC_THREAD_H_
|
||||
#define _PICC_THREAD_H_
|
||||
#include "rfid_def.h"
|
||||
#include <atlbase.h>
|
||||
#include <atlwin.h> // for HWND<4E><44><EFBFBD><EFBFBD>
|
||||
|
||||
// to picc thread;
|
||||
// <20><><EFBFBD><EFBFBD>buffer<65><72><EFBFBD><EFBFBD>;
|
||||
typedef struct tag_PICC_Thread_In_prm
|
||||
{
|
||||
HWND hWnd;
|
||||
UINT uMsgId;
|
||||
char sz_pcd_ip[20];
|
||||
UINT16 u16_pcd_rx_port;
|
||||
UINT16 u16_picc_rx_port;
|
||||
char sz_picc_ID[21];
|
||||
UCHAR uc_picc_ID_Len;
|
||||
}PICC_Thread_In_prm;
|
||||
|
||||
// <20>漰buffer.
|
||||
// <20><><EFBFBD>ΰ<EFBFBD><CEB0><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD>ȥ: <20><><EFBFBD>߲<EFBFBD><DFB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD>
|
||||
typedef struct
|
||||
{
|
||||
UCHAR *buf;
|
||||
int nBufBitLen;
|
||||
int npicc_status;
|
||||
char *action;
|
||||
}PICC_Thread_Out_prm;
|
||||
|
||||
// <20>̺߳<DFB3><CCBA><EFBFBD>
|
||||
void picc_thread( PICC_Thread_In_prm *pPrm );
|
||||
|
||||
// PICC
|
||||
void picc_updateStatus( int status );
|
||||
void picc_postMessage( UCHAR *buf, int nBufBitLen, int npicc_status, char *action = NULL );
|
||||
#endif
|
||||
BIN
Labs/Lab2/requirements/src/rfidsrc/rfid.IAB
Normal file
BIN
Labs/Lab2/requirements/src/rfidsrc/rfid.IAB
Normal file
Binary file not shown.
BIN
Labs/Lab2/requirements/src/rfidsrc/rfid.IAD
Normal file
BIN
Labs/Lab2/requirements/src/rfidsrc/rfid.IAD
Normal file
Binary file not shown.
BIN
Labs/Lab2/requirements/src/rfidsrc/rfid.IMB
Normal file
BIN
Labs/Lab2/requirements/src/rfidsrc/rfid.IMB
Normal file
Binary file not shown.
BIN
Labs/Lab2/requirements/src/rfidsrc/rfid.IMD
Normal file
BIN
Labs/Lab2/requirements/src/rfidsrc/rfid.IMD
Normal file
Binary file not shown.
BIN
Labs/Lab2/requirements/src/rfidsrc/rfid.PFI
Normal file
BIN
Labs/Lab2/requirements/src/rfidsrc/rfid.PFI
Normal file
Binary file not shown.
BIN
Labs/Lab2/requirements/src/rfidsrc/rfid.PO
Normal file
BIN
Labs/Lab2/requirements/src/rfidsrc/rfid.PO
Normal file
Binary file not shown.
BIN
Labs/Lab2/requirements/src/rfidsrc/rfid.PR
Normal file
BIN
Labs/Lab2/requirements/src/rfidsrc/rfid.PR
Normal file
Binary file not shown.
BIN
Labs/Lab2/requirements/src/rfidsrc/rfid.PRI
Normal file
BIN
Labs/Lab2/requirements/src/rfidsrc/rfid.PRI
Normal file
Binary file not shown.
BIN
Labs/Lab2/requirements/src/rfidsrc/rfid.PS
Normal file
BIN
Labs/Lab2/requirements/src/rfidsrc/rfid.PS
Normal file
Binary file not shown.
BIN
Labs/Lab2/requirements/src/rfidsrc/rfid.WK3
Normal file
BIN
Labs/Lab2/requirements/src/rfidsrc/rfid.WK3
Normal file
Binary file not shown.
168
Labs/Lab2/requirements/src/rfidsrc/rfid_chk.cpp
Normal file
168
Labs/Lab2/requirements/src/rfidsrc/rfid_chk.cpp
Normal file
@@ -0,0 +1,168 @@
|
||||
/**
|
||||
* \file rfid_chk.c
|
||||
*
|
||||
* \brief ʵ<><CAB5>rfid<69>е<EFBFBD>У<EFBFBD>顣
|
||||
*/
|
||||
//#include "StdAfx.h"
|
||||
|
||||
#include "rfid_chk.h"
|
||||
|
||||
/**
|
||||
* CRCУ<43><D0A3>
|
||||
*
|
||||
* \input BYTE aBuf[],<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* UINT16 u16Len <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* UINT16 u16InitPrm CRC16<31><36>ֵ.
|
||||
* \ouput BYTE *pCRCMSB CRC<52><43>8bit
|
||||
* BYTE *pCRCLSB CRC<52><43>8bit
|
||||
* \return 1<>ɹ<EFBFBD><C9B9><EFBFBD><0ʧ<30><CAA7>.
|
||||
*/
|
||||
int CRC16( UINT16 u16InitPrm, BYTE aBuf[], UINT16 u16Len,BYTE *pCRCMSB, BYTE *pCRCLSB );
|
||||
|
||||
int OldParity(BYTE Dat )
|
||||
{
|
||||
int k=0;
|
||||
int i;
|
||||
|
||||
for( i = 0; i < 8; i++ )
|
||||
{
|
||||
if(( Dat >> i ) & 0x01 )
|
||||
{
|
||||
k++;
|
||||
}
|
||||
}
|
||||
return k % 2 ? 0:1;
|
||||
}
|
||||
|
||||
int ISO14443A_CRC( BYTE aBuf[], UINT16 u16Len,BYTE *pCRCMSB, BYTE *pCRCLSB )
|
||||
{
|
||||
return CRC16( 0x6363, aBuf, u16Len, pCRCMSB, pCRCLSB );
|
||||
}
|
||||
|
||||
|
||||
UINT16 UpdateCrc(BYTE ch, UINT16 *lpwCrc)
|
||||
{
|
||||
ch = (ch^(unsigned char)((*lpwCrc) & 0x00FF));
|
||||
ch = (ch^(ch<<4));
|
||||
|
||||
*lpwCrc = (*lpwCrc >> 8)^((UINT16)ch << 8)^((UINT16)ch<<3)^((UINT16)ch>>4);
|
||||
return(*lpwCrc);
|
||||
}
|
||||
|
||||
/**
|
||||
* CRCУ<43><D0A3>
|
||||
*
|
||||
* \input BYTE aBuf[],<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* UINT16 u16Len <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* UINT16 u16InitPrm CRC16<31><36>ֵ.
|
||||
* \ouput BYTE *pCRCMSB CRC<52><43>8bit
|
||||
* BYTE *pCRCLSB CRC<52><43>8bit
|
||||
* \return 1<>ɹ<EFBFBD><C9B9><EFBFBD><0ʧ<30><CAA7>.
|
||||
*/
|
||||
int CRC16( UINT16 u16InitValue, BYTE aBuf[], UINT16 u16Len,BYTE *pCRCMSB, BYTE *pCRCLSB )
|
||||
{
|
||||
UINT16 wCrc;
|
||||
unsigned char chBlock;
|
||||
int i;
|
||||
|
||||
wCrc = u16InitValue;
|
||||
for( i = 0; i < u16Len; i++ )
|
||||
{
|
||||
chBlock = aBuf[i];
|
||||
UpdateCrc(chBlock, &wCrc);
|
||||
}
|
||||
if( u16InitValue == 0xFFFF )
|
||||
{
|
||||
wCrc = ~wCrc; // ISO 3309
|
||||
}
|
||||
*pCRCLSB = (BYTE) (wCrc & 0xFF);
|
||||
*pCRCMSB = (BYTE) ((wCrc >> 8) & 0xFF);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*------------------------------------------------------------*\
|
||||
* <09><><EFBFBD><EFBFBD><EFBFBD>DZ<EFBFBD><EFBFBD>У<EFBFBD>CRC<52>ļ<EFBFBD><C4BC><EFBFBD>demo.
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define CRC_A 1
|
||||
#define CRC_B 2
|
||||
#define BYTE unsigned char
|
||||
|
||||
unsigned short UpdateCrc(unsigned char ch, unsigned short *lpwCrc)
|
||||
{
|
||||
ch = (ch^(unsigned char)((*lpwCrc) & 0x00FF));
|
||||
ch = (ch^(ch<<4));
|
||||
|
||||
*lpwCrc = (*lpwCrc >> 8)^((unsigned short)ch << 8)^((unsigned
|
||||
short)ch<<3)^((unsigned short)ch>>4);
|
||||
return(*lpwCrc);
|
||||
}
|
||||
|
||||
void ComputeCrc(int CRCType, char *Data, int Length,
|
||||
BYTE *TransmitFirst, BYTE *TransmitSecond)
|
||||
{
|
||||
unsigned char chBlock;
|
||||
unsigned short wCrc;
|
||||
|
||||
switch(CRCType) {
|
||||
case CRC_A:
|
||||
wCrc = 0x6363; // ITU-V.41
|
||||
break;
|
||||
case CRC_B:
|
||||
wCrc = 0xFFFF; // ISO 3309
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
chBlock = *Data++;
|
||||
UpdateCrc(chBlock, &wCrc);
|
||||
} while (--Length);
|
||||
if (CRCType == CRC_B)
|
||||
wCrc = ~wCrc; // ISO 3309
|
||||
*TransmitFirst = (BYTE) (wCrc & 0xFF);
|
||||
*TransmitSecond = (BYTE) ((wCrc >> 8) & 0xFF);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
BYTE BuffCRC_A[10] = {0x12, 0x34};
|
||||
BYTE BuffCRC_B[10] = {0x0A, 0x12, 0x34, 0x56};
|
||||
unsigned short Crc;
|
||||
BYTE First, Second;
|
||||
FILE *OutFd;
|
||||
int i;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("CRC-16 reference results 3-Jun-1999\n");
|
||||
|
||||
printf("by Mickey Cohen - mickey@softchip.com\n\n");
|
||||
printf("Crc-16 G(x) = x^16 + x^12 + x^5 + 1\n\n");
|
||||
|
||||
printf("CRC_A of [ ");
|
||||
for(i=0; i<2; i++) printf("%02X ",BuffCRC_A[i]);
|
||||
ComputeCrc(CRC_A, BuffCRC_A, 2, &First, &Second);
|
||||
printf("] Transmitted: %02X then %02X.\n", First, Second);
|
||||
|
||||
printf("CRC_B of [ ");
|
||||
for(i=0; i<4; i++) printf("%02X ",BuffCRC_B[i]);
|
||||
ComputeCrc(CRC_B, BuffCRC_B, 4, &First, &Second);
|
||||
printf("] Transmitted: %02X then %02X.\n", First, Second);
|
||||
|
||||
return(0);
|
||||
}
|
||||
/*------------------------------------------------------------*\
|
||||
* <09><><EFBFBD><EFBFBD><EFBFBD>DZ<EFBFBD><EFBFBD>У<EFBFBD>CRC<52>ļ<EFBFBD><C4BC><EFBFBD>demo.
|
||||
*
|
||||
*/
|
||||
|
||||
#endif
|
||||
47
Labs/Lab2/requirements/src/rfidsrc/rfid_chk.h
Normal file
47
Labs/Lab2/requirements/src/rfidsrc/rfid_chk.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* \file rfid_chk.h
|
||||
*
|
||||
* \brief ʵ<><CAB5>rfid<69>е<EFBFBD>У<EFBFBD>顣
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _RFID_CHECK_H_
|
||||
#define _RFID_CHECK_H_
|
||||
|
||||
#include "rfid_def.h"
|
||||
/**
|
||||
* \function <20><>У<EFBFBD><D0A3>
|
||||
*
|
||||
* \input <09><><EFBFBD>룺BYTE bDat: 0/1
|
||||
* \ouput
|
||||
* \return <09><><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>0<EFBFBD><30><EFBFBD><EFBFBD>1.
|
||||
*/
|
||||
int OldParity(BYTE Dat );
|
||||
|
||||
/**
|
||||
* CRCУ<43><D0A3>
|
||||
*
|
||||
* \input BYTE aBuf[],<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* UINT16 u16Len <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* \ouput BYTE *pCRCMSB CRC<52><43>8bit
|
||||
* BYTE *pCRCLSB CRC<52><43>8bit
|
||||
* \return 1<>ɹ<EFBFBD><C9B9><EFBFBD><0ʧ<30><CAA7>.
|
||||
*/
|
||||
|
||||
int ISO14443A_CRC( BYTE aBuf[], UINT16 u16Len,BYTE *pCRCMSB, BYTE *pCRCLSB );
|
||||
int ISO14443B_CRC( BYTE aBuf[], UINT16 u16Len,BYTE *pCRCMSB, BYTE *pCRCLSB );
|
||||
int ISO15693_CRC( BYTE aBuf[], UINT16 u16Len, BYTE *pCRCMSB, BYTE *pCRCLSB );
|
||||
|
||||
/**
|
||||
* ISO14443B
|
||||
*
|
||||
*
|
||||
* ÿ<><C3BF><EFBFBD>ֽڣ<D6BD>ǰ<EFBFBD><C7B0>1bit start, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1bit<69><74> stop<6F><70>1<EFBFBD><31><EFBFBD>ص<EFBFBD>egt.
|
||||
* <09><><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD>䣺<EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD>LSB<53><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>Ե<EFBFBD><D4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
|
||||
*/
|
||||
// ͬʱҪ<CAB1>Ե<EFBFBD><D4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int ISO14443B_ByteExp( BYTE byDat );
|
||||
// <20><><EFBFBD><EFBFBD>ԭʼ<D4AD>ֽ<EFBFBD>
|
||||
BYTE IOS14443B_UnByteExp( UINT16 u16Dat );
|
||||
|
||||
#endif
|
||||
531
Labs/Lab2/requirements/src/rfidsrc/rfid_com.cpp
Normal file
531
Labs/Lab2/requirements/src/rfidsrc/rfid_com.cpp
Normal file
@@ -0,0 +1,531 @@
|
||||
/**
|
||||
* \file rfid_com.c
|
||||
*
|
||||
* \biref <09><><EFBFBD><EFBFBD>rfid<69><64>ͨ<EFBFBD><CDA8>
|
||||
*/
|
||||
|
||||
//#include "stdafx.h"
|
||||
#include "rfid_com.h"
|
||||
#include <io.h>
|
||||
/**
|
||||
* <09><><EFBFBD><EFBFBD>1: <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
* <09><><EFBFBD>彻<EFBFBD><E5BDBB><EFBFBD>ļ<EFBFBD>
|
||||
* <09>ļ<EFBFBD><C4BC><EFBFBD>ʽ<EFBFBD><CABD>
|
||||
*
|
||||
* 1B: <09><><EFBFBD><EFBFBD>: 0x50 Reader->Card
|
||||
* 0x51 Card->Reader
|
||||
* 1B: reserved
|
||||
* 2B: <09><><EFBFBD>ݱ<EFBFBD><DDB1>س<EFBFBD><D8B3><EFBFBD>
|
||||
* <09><><EFBFBD><EFBFBD>.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef _RFID_COM_FILE_
|
||||
|
||||
#define RFID_COM_FILE_CARD_TO_READER "d:\\rfid\\crwap"
|
||||
#define RFID_COM_FILE_READER_TO_CARD "d:\\rfid\\rcwap"
|
||||
#else
|
||||
#ifdef _OS_WINDOWS_
|
||||
#include <winsock2.h>
|
||||
|
||||
#pragma comment(lib,"Ws2_32.lib ")
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#define RFID_CARD_UDP_PORT 10101
|
||||
#define RFID_READER_UDP_PORT 10201
|
||||
|
||||
int g_nSendSocketId = -1;
|
||||
int g_nRecvSocketId = -1;
|
||||
struct sockaddr_in g_stSendAddr;
|
||||
struct sockaddr_in g_stRecvAddr;
|
||||
|
||||
#endif
|
||||
|
||||
#define RFID_COM_CARD_LOG_NAME "d:\\rfid\\rfid_card_log.txt"
|
||||
#define RFID_COM_READER_LOG_NAME "d:\\rfid\\rfid_reader_log.txt"
|
||||
|
||||
// Direction
|
||||
#define RFID_COM_ID 0x50
|
||||
#define RFID_COM_CARD_TX 0
|
||||
#define RFID_COM_CARD_RX 1
|
||||
#define RFID_COM_READER_TX 2
|
||||
#define RFID_COM_READER_RX 3
|
||||
|
||||
int RFID_COM_LOG( UCHAR ucDirection, UINT16 u16BitLen, UCHAR *pBuf );
|
||||
|
||||
#ifdef _RFID_COM_FILE_
|
||||
char* RFID_COM_GetFileName( UCHAR ucDirection )
|
||||
{
|
||||
switch( ucDirection )
|
||||
{
|
||||
case RFID_COM_CARD_TX:
|
||||
case RFID_COM_READER_RX:
|
||||
return RFID_COM_FILE_CARD_TO_READER;
|
||||
case RFID_COM_CARD_RX:
|
||||
case RFID_COM_READER_TX:
|
||||
return RFID_COM_FILE_READER_TO_CARD;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
void RFID_COM_Init( int pcd_or_picc );
|
||||
int RFID_COM_Init( int pcd_or_picc, char *pcd_ip_addr, UINT16 u16pcd_rx_port, UINT16 u16picc_rx_port );
|
||||
|
||||
int RFID_COM_PCD_Init( UINT16 u16pcd_rx_port, UINT16 u16picc_rx_port )
|
||||
{
|
||||
return RFID_COM_Init( ISO_14443_PCD, NULL, u16pcd_rx_port, u16picc_rx_port );
|
||||
}
|
||||
|
||||
int RFID_COM_PICC_Init( char *pcd_ip_addr, UINT16 u16pcd_rx_port, UINT16 u16picc_rx_port )
|
||||
{
|
||||
return RFID_COM_Init( ISO_14443_PICC, pcd_ip_addr, u16pcd_rx_port, u16picc_rx_port );
|
||||
}
|
||||
|
||||
|
||||
void RFID_COM_Init( int pcd_or_picc )
|
||||
{
|
||||
#ifdef _RFID_COM_FILE_
|
||||
if( pcd_or_picc == ISO_14443_PCD )
|
||||
{
|
||||
char *szFileName;
|
||||
szFileName = RFID_COM_GetFileName( RFID_COM_READER_TX );
|
||||
if( access( szFileName, 0) == 0 )
|
||||
{
|
||||
unlink( szFileName );
|
||||
}
|
||||
|
||||
szFileName = RFID_COM_GetFileName( RFID_COM_READER_RX );
|
||||
if( access( szFileName, 0) == 0 )
|
||||
{
|
||||
unlink( szFileName );
|
||||
}
|
||||
}
|
||||
#else
|
||||
char str[20];
|
||||
struct timeval timeout = {0,200000}; // 200ms.
|
||||
|
||||
g_nSendSocketId = socket( AF_INET, SOCK_DGRAM, 0 );
|
||||
g_nRecvSocketId = socket( AF_INET, SOCK_DGRAM, 0 );
|
||||
|
||||
sprintf_s( str, "127.0.0.1");
|
||||
// bzero( &g_stSendAddr, sizeof( g_stSendAddr ));
|
||||
memset( &g_stSendAddr, sizeof( g_stSendAddr ), 0x00);
|
||||
g_stSendAddr.sin_family = AF_INET;
|
||||
g_stSendAddr.sin_addr.s_addr = inet_addr( str );
|
||||
|
||||
// bzero( &g_stRecvAddr, sizeof( g_stRecvAddr ));
|
||||
memset( &g_stRecvAddr, sizeof( g_stRecvAddr ),0x00);
|
||||
g_stRecvAddr.sin_family = AF_INET;
|
||||
g_stRecvAddr.sin_addr.s_addr = htonl( INADDR_ANY );
|
||||
|
||||
if( pcd_or_picc == ISO_14443_PCD )
|
||||
{
|
||||
g_stSendAddr.sin_port = htons(RFID_CARD_UDP_PORT);
|
||||
g_stRecvAddr.sin_port = htons(RFID_READER_UDP_PORT);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_stSendAddr.sin_port = htons(RFID_READER_UDP_PORT);
|
||||
g_stRecvAddr.sin_port = htons(RFID_CARD_UDP_PORT);
|
||||
}
|
||||
bind( g_nRecvSocketId, (struct sockaddr *)&g_stRecvAddr, sizeof( g_stRecvAddr ));
|
||||
setsockopt( g_nRecvSocketId, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout,sizeof(struct timeval));
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void RFID_COM_Close()
|
||||
{
|
||||
if( g_nSendSocketId != -1 )
|
||||
{
|
||||
// _close( g_nSendSocketId );
|
||||
closesocket( g_nSendSocketId );
|
||||
g_nSendSocketId = -1;
|
||||
}
|
||||
|
||||
if( g_nRecvSocketId != -1 )
|
||||
{
|
||||
// _close( g_nRecvSocketId );
|
||||
closesocket( g_nRecvSocketId );
|
||||
g_nRecvSocketId = -1;
|
||||
}
|
||||
WSACleanup();
|
||||
}
|
||||
|
||||
// PCD<43><44><EFBFBD>ù㲥<C3B9><E3B2A5>ʽ<EFBFBD><CABD>
|
||||
int RFID_COM_Init( int pcd_or_picc, char *pcd_ip_addr, UINT16 u16pcd_rx_port, UINT16 u16picc_rx_port )
|
||||
{
|
||||
// <20><><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD>timeout<75><74><EFBFBD><EFBFBD>Ϊ0.n<>룬<EFBFBD><EBA3AC><EFBFBD><EFBFBD>500msʱ<73><CAB1>û<EFBFBD><C3BB><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD>Ϊblock.
|
||||
struct timeval timeout = {1,0}; // 1s.
|
||||
|
||||
// <20>Ѿ<EFBFBD><D1BE><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if( g_nSendSocketId != -1 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 1
|
||||
WSADATA wsa;
|
||||
if (WSAStartup(MAKEWORD(2,2),&wsa) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
g_nSendSocketId = socket( AF_INET, SOCK_DGRAM, 0 );
|
||||
if( g_nSendSocketId < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
// <20><><EFBFBD>÷<EFBFBD><C3B7>ͷ<EFBFBD><CDB7><EFBFBD>
|
||||
memset( &g_stSendAddr, sizeof( g_stSendAddr ), 0x00);
|
||||
g_stSendAddr.sin_family = AF_INET;
|
||||
|
||||
if( pcd_or_picc == ISO_14443_PCD )
|
||||
{
|
||||
int opt=-1;
|
||||
int nb = setsockopt(g_nSendSocketId,SOL_SOCKET,SO_BROADCAST,(char*)&opt,sizeof(opt));
|
||||
if( nb == -1)
|
||||
{
|
||||
return -2; // ʧ<><CAA7>;
|
||||
}
|
||||
//<2F><EFBFBD><D7BD>ֵ<EFBFBD>ַΪ<D6B7>㲥<EFBFBD><E3B2A5>ַ
|
||||
g_stSendAddr.sin_addr.s_addr=htonl(INADDR_BROADCAST);
|
||||
// <20><><EFBFBD><EFBFBD>
|
||||
// g_stSendAddr.sin_addr.s_addr = inet_addr( "255.255.255.255" );
|
||||
|
||||
g_stSendAddr.sin_port = htons(u16picc_rx_port);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_stSendAddr.sin_addr.s_addr = inet_addr( pcd_ip_addr );
|
||||
g_stSendAddr.sin_port = htons(u16pcd_rx_port);
|
||||
}
|
||||
|
||||
// <20><><EFBFBD>ý<EFBFBD><C3BD>շ<EFBFBD>
|
||||
g_nRecvSocketId = socket( AF_INET, SOCK_DGRAM, 0 );
|
||||
if( g_nRecvSocketId < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if( pcd_or_picc != ISO_14443_PCD )
|
||||
{
|
||||
int opt=-1;
|
||||
int nb=setsockopt(g_nRecvSocketId,SOL_SOCKET,SO_BROADCAST,(char*)&opt,sizeof(opt));
|
||||
if( nb == -1 )
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
memset( &g_stRecvAddr, sizeof( g_stRecvAddr ),0x00);
|
||||
g_stRecvAddr.sin_family = AF_INET;
|
||||
g_stRecvAddr.sin_addr.s_addr = htonl( INADDR_ANY );
|
||||
|
||||
if( pcd_or_picc == ISO_14443_PCD )
|
||||
{
|
||||
g_stRecvAddr.sin_port = htons(u16pcd_rx_port);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_stRecvAddr.sin_port = htons(u16picc_rx_port);
|
||||
}
|
||||
bind( g_nRecvSocketId, (struct sockaddr *)&g_stRecvAddr, sizeof( g_stRecvAddr ));
|
||||
if( setsockopt( g_nRecvSocketId, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout,sizeof(struct timeval)))
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int RFID_COM_Tx( UCHAR ucDirection, UINT16 u16BitLen, UCHAR *pBuf )
|
||||
{
|
||||
#ifdef _RFID_COM_FILE_
|
||||
FILE *fp;
|
||||
UCHAR aucBuf[4]={0x00};
|
||||
char *szFileName;
|
||||
|
||||
szFileName = RFID_COM_GetFileName( ucDirection );
|
||||
// 2016/11/23
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ڣ<EFBFBD>˵<EFBFBD><CBB5><EFBFBD>Է<EFBFBD>û<EFBFBD>ж<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD>.
|
||||
while(1)
|
||||
{
|
||||
if( access( szFileName, 0) == -1 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
// access: 0<><30>ʾ<EFBFBD><CABE><EFBFBD>ڣ<EFBFBD>-1<><31>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
{
|
||||
int i, k=0;
|
||||
for( i = 0; i < 200000; i++ )
|
||||
{
|
||||
k++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fp = fopen( szFileName, "wb" );
|
||||
if( !fp )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
aucBuf[0] = RFID_COM_ID;
|
||||
*(UINT16 *)&aucBuf[2] = u16BitLen;
|
||||
|
||||
fwrite( aucBuf, 1, 4, fp );
|
||||
if( u16BitLen % 8 )
|
||||
{
|
||||
fwrite( pBuf, 1, u16BitLen/8+1, fp );
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite( pBuf, 1, u16BitLen/8, fp );
|
||||
}
|
||||
fclose( fp );
|
||||
|
||||
RFID_COM_LOG( ucDirection, u16BitLen, pBuf );
|
||||
|
||||
return u16BitLen;
|
||||
#else
|
||||
UINT16 u16BufLen;
|
||||
char aucBuf[200];
|
||||
|
||||
u16BufLen = u16BitLen/8;
|
||||
if( u16BitLen % 8 )
|
||||
{
|
||||
u16BufLen++;
|
||||
}
|
||||
|
||||
if( g_nSendSocketId != -1 )
|
||||
{
|
||||
#ifdef _RFID_DEBUG_
|
||||
int i;
|
||||
printf("\nTxLen = %d, bitLen = %d ", u16BufLen, u16BitLen );
|
||||
for( i = 0; i < u16BufLen; i++ )
|
||||
{
|
||||
printf("0x%02x ", pBuf[i]);
|
||||
}
|
||||
#endif
|
||||
aucBuf[0] = RFID_COM_ID;
|
||||
*(UINT16 *)&aucBuf[2] = u16BitLen;
|
||||
memcpy( aucBuf+4, pBuf, u16BufLen );
|
||||
|
||||
return sendto( g_nSendSocketId, aucBuf, u16BufLen+4,
|
||||
0, (struct sockaddr *)&g_stSendAddr, sizeof( g_stSendAddr ));
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int RFID_COM_Rx( UCHAR ucDirection, UINT16 u16ByteLen, UCHAR *pBuf, int block )
|
||||
{
|
||||
#ifdef _RFID_COM_FILE_
|
||||
FILE *fp;
|
||||
UCHAR aucBuf[4]={0x00};
|
||||
UINT16 u16BitLen;
|
||||
char *szFileName;
|
||||
|
||||
szFileName = RFID_COM_GetFileName( ucDirection );
|
||||
|
||||
// 2016/11/23
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ڣ<EFBFBD>˵<EFBFBD><CBB5><EFBFBD>Է<EFBFBD>û<EFBFBD>ж<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD>.
|
||||
while(1)
|
||||
{
|
||||
// access: 0<><30>ʾ<EFBFBD><CABE><EFBFBD>ڣ<EFBFBD>-1<><31>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
if( access( szFileName, 0) == 0 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
if( block == 0)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD>.
|
||||
return 0;
|
||||
}
|
||||
|
||||
// <20>ȴ<EFBFBD><C8B4><EFBFBD>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
int i, k=0;
|
||||
for( i = 0; i < 200000; i++ )
|
||||
{
|
||||
k++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// <20><><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD>û<EFBFBD><C3BB>д<EFBFBD>룬<EFBFBD><EBA3AC><EFBFBD>Եȴ<D4B5>һ<EFBFBD>ᣬȷ<E1A3AC><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>롣
|
||||
{
|
||||
int i, k=0;
|
||||
for( i = 0; i < 150000; i++ )
|
||||
{
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fp = fopen( szFileName, "rb" );
|
||||
if( !fp )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
fread( aucBuf, 1, 4, fp );
|
||||
if( aucBuf[0] != RFID_COM_ID )
|
||||
{
|
||||
fclose( fp );
|
||||
return 0;
|
||||
}
|
||||
u16BitLen = *(UINT16 *)&aucBuf[2];
|
||||
|
||||
if( u16BitLen % 8 )
|
||||
{
|
||||
fread( pBuf, 1, u16BitLen/8+1, fp );
|
||||
}
|
||||
else
|
||||
{
|
||||
fread( pBuf, 1, u16BitLen/8, fp );
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ļ<EFBFBD>û<EFBFBD><C3BB><EFBFBD>Զ<EFBFBD>ռ<EFBFBD><D5BC>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>
|
||||
fclose( fp );
|
||||
|
||||
remove( szFileName );
|
||||
|
||||
RFID_COM_LOG( ucDirection, u16BitLen, pBuf );
|
||||
return u16BitLen;
|
||||
#else
|
||||
char aucBuf[200];
|
||||
int sin_len;
|
||||
int n, k, i;
|
||||
|
||||
if( g_nRecvSocketId != -1 )
|
||||
{
|
||||
n = recv( g_nRecvSocketId, aucBuf, 200, 0 );
|
||||
if( n > 0 )
|
||||
{
|
||||
k = *(UINT16 *)&aucBuf[2];
|
||||
#ifdef _RFID_DEBUG_
|
||||
printf("\nrx dat, len = %d, bitlen = %d.", n, k);
|
||||
for( i = 0; i < n; i++ )
|
||||
{
|
||||
printf("0x%02x ", aucBuf[i]);
|
||||
}
|
||||
#endif
|
||||
memcpy( pBuf, aucBuf+4, n-4 );
|
||||
return k;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef _RFID_DEBUG_
|
||||
printf("\nrx: %d, error = %d", n, errno);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int RFID_COM_LOG( UCHAR ucDirection, UINT16 u16BitLen, UCHAR *pBuf )
|
||||
{
|
||||
#ifdef _RFID_COM_FILE_
|
||||
FILE *fp;
|
||||
int i;
|
||||
char *szBuf[] = {"CardTx", "CardRx", "ReaderTx", "ReaderRx"};
|
||||
char *szFileName = NULL;
|
||||
|
||||
if( ucDirection == RFID_COM_CARD_TX || ucDirection == RFID_COM_CARD_RX )
|
||||
{
|
||||
szFileName = RFID_COM_CARD_LOG_NAME;
|
||||
}
|
||||
else
|
||||
{
|
||||
szFileName = RFID_COM_READER_LOG_NAME;
|
||||
}
|
||||
fp = fopen( szFileName, "a+" );
|
||||
if( !fp )
|
||||
{
|
||||
fp = fopen( szFileName, "w" );
|
||||
}
|
||||
fprintf(fp, "\n\n--%10s bitlen=%3d: \n-- ", szBuf[ucDirection], u16BitLen );
|
||||
#ifdef _RFID_DEBUG_
|
||||
printf("\n--%10s bitlen=%3d:\n-- ", szBuf[ucDirection], u16BitLen );
|
||||
#endif
|
||||
for( i = 0; i < u16BitLen; i+=8 )
|
||||
{
|
||||
fprintf( fp, "%02x ", *pBuf );
|
||||
#ifdef _RFID_DEBUG_
|
||||
printf("%02x ", *pBuf );
|
||||
#endif
|
||||
pBuf++;
|
||||
}
|
||||
fclose( fp );
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
int RFID_Card_Tx( UINT16 u16BitLen, UCHAR *pBuf )
|
||||
{
|
||||
return RFID_COM_Tx( RFID_COM_CARD_TX, u16BitLen, pBuf );
|
||||
}
|
||||
|
||||
/**
|
||||
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
*
|
||||
* <09><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>
|
||||
* >0<><30>ʵ<EFBFBD><CAB5><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݵı<DDB5><C4B1>س<EFBFBD><D8B3><EFBFBD>;
|
||||
* =0, û<><C3BB><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>;
|
||||
*/
|
||||
int RFID_Card_Rx( UINT16 u16ByteLen, UCHAR *pBuf )
|
||||
{
|
||||
return RFID_COM_Rx( RFID_COM_CARD_RX, u16ByteLen, pBuf, 1 ); // wait
|
||||
}
|
||||
|
||||
/**
|
||||
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
bool g_bStep = false;
|
||||
int g_nStep = -1;
|
||||
int RFID_Reader_Tx( UINT16 u16BitLen, UCHAR *pBuf )
|
||||
{
|
||||
static int step = 0;
|
||||
|
||||
if( !g_bStep )
|
||||
{
|
||||
return RFID_COM_Tx( RFID_COM_READER_TX, u16BitLen, pBuf );
|
||||
}
|
||||
else
|
||||
{
|
||||
while( step != g_nStep )
|
||||
{
|
||||
Sleep( 1000 );
|
||||
}
|
||||
step++;
|
||||
return RFID_COM_Tx( RFID_COM_READER_TX, u16BitLen, pBuf );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
*
|
||||
* <09><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>
|
||||
* >0<><30>ʵ<EFBFBD><CAB5><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݵı<DDB5><C4B1>س<EFBFBD><D8B3><EFBFBD>;
|
||||
* =0, û<><C3BB><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>;
|
||||
*/
|
||||
int RFID_Reader_Rx( UINT16 u16ByteLen, UCHAR *pBuf )
|
||||
{
|
||||
return RFID_COM_Rx( RFID_COM_READER_RX, u16ByteLen, pBuf, 0 ); // <20><><EFBFBD><EFBFBD>
|
||||
}
|
||||
52
Labs/Lab2/requirements/src/rfidsrc/rfid_com.h
Normal file
52
Labs/Lab2/requirements/src/rfidsrc/rfid_com.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* \file RFID_com.h
|
||||
*
|
||||
* \brief <09><><EFBFBD><EFBFBD>RFIDϵͳ<CFB5>У<EFBFBD><D0A3><EFBFBD>/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>շ<EFBFBD>.
|
||||
*
|
||||
*/
|
||||
#ifndef _RFID_COM_H_
|
||||
#define _RFID_COM_H_
|
||||
|
||||
#include "rfid_def.h"
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>udp<64><70><EFBFBD><EFBFBD>ͨѶ
|
||||
// pcd->picc<63><63><EFBFBD>㲥/<2F>鲥<EFBFBD><E9B2A5><EFBFBD><EFBFBD>ip<69><70>ַ<EFBFBD>أ<DEB9>
|
||||
// picc->pcd<63><64><EFBFBD><EFBFBD><F2A3ACB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ժ<EFBFBD><D4BA><EFBFBD><EFBFBD>ӿڶ<D3BF><DAB6><EFBFBD>pcd<63><64>ip<69><70>ַ<EFBFBD><D6B7>
|
||||
// <20>Ȳ<EFBFBD><C8B2>ù㲥<C3B9><E3B2A5><EFBFBD><EFBFBD>
|
||||
|
||||
int RFID_COM_PCD_Init( UINT16 u16pcd_rx_port, UINT16 u16picc_rx_port );
|
||||
int RFID_COM_PICC_Init( char *pcd_ip_addr, UINT16 u16pcd_rx_port, UINT16 u16picc_rx_port );
|
||||
void RFID_COM_Close();
|
||||
/**
|
||||
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* <20>鲥<EFBFBD><E9B2A5><EFBFBD>㲥;
|
||||
*/
|
||||
int RFID_Card_Tx( UINT16 u16BitLen, UCHAR *pBuf );
|
||||
|
||||
/**
|
||||
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
*
|
||||
* <09><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>
|
||||
* >0<><30>ʵ<EFBFBD><CAB5><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݵı<DDB5><C4B1>س<EFBFBD><D8B3><EFBFBD>;
|
||||
* =0, û<><C3BB><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>;
|
||||
*/
|
||||
int RFID_Card_Rx( UINT16 u16ByteLen, UCHAR *pBuf );
|
||||
|
||||
/**
|
||||
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* <09><><EFBFBD><EFBFBD>
|
||||
*/
|
||||
int RFID_Reader_Tx( UINT16 u16BitLen, UCHAR *pBuf );
|
||||
|
||||
/**
|
||||
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
*
|
||||
* <09><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>
|
||||
* >0<><30>ʵ<EFBFBD><CAB5><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݵı<DDB5><C4B1>س<EFBFBD><D8B3><EFBFBD>;
|
||||
* =0, û<><C3BB><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>;
|
||||
*/
|
||||
int RFID_Reader_Rx( UINT16 u16ByteLen, UCHAR *pBuf );
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
225
Labs/Lab2/requirements/src/rfidsrc/rfid_def.h
Normal file
225
Labs/Lab2/requirements/src/rfidsrc/rfid_def.h
Normal file
@@ -0,0 +1,225 @@
|
||||
/**
|
||||
* \file rfid_def.h
|
||||
*
|
||||
* \brief 头文件定义
|
||||
*/
|
||||
#ifndef _RFID_DEF_H_
|
||||
#define _RFID_DEF_H_
|
||||
|
||||
#define _OS_WINDOWS_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <memory.h>
|
||||
|
||||
//#define _RFID_DEBUG_
|
||||
|
||||
#ifdef _OS_WINDOWS_
|
||||
// #define _RFID_COM_FILE_
|
||||
#define PCD_WAIT_TIME 2
|
||||
#else
|
||||
#define PCD_WAIT_TIME 1
|
||||
#endif
|
||||
|
||||
typedef unsigned char byte;
|
||||
typedef unsigned char BYTE;
|
||||
typedef unsigned char UCHAR;
|
||||
typedef unsigned short UINT16;
|
||||
typedef unsigned long ULONG;
|
||||
//typedef unsigned long UINT32;
|
||||
typedef unsigned short USHORT;
|
||||
typedef int BOOL;
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
/**
|
||||
* 系统最多仿10个 PICC.
|
||||
*/
|
||||
|
||||
#define MAX_PICC_NUM 10
|
||||
|
||||
/**
|
||||
* 下列宏定义,表示PCD使用broad方式向PICC发送命令
|
||||
* PICC需要加入组播组接收数据
|
||||
*/
|
||||
#define PCD_TO_PICC_USE_BROAD
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------*\
|
||||
* 定义ISO14443A命令和状态
|
||||
*
|
||||
*
|
||||
*-----------------------------------------------------------------*/
|
||||
// 实际上不存在
|
||||
#define ISO_14443A_STATE_POWEROFF 0xA0
|
||||
// 系统启动,就处于IDLE状态,相当于已经加电.
|
||||
#define ISO_14443A_STATE_IDLE 0xA1
|
||||
#define ISO_14443A_STATE_READY 0xA2
|
||||
#define ISO_14443A_STATE_ACTIVE 0xA3
|
||||
#define ISO_14443A_STATE_HALT 0xA4
|
||||
|
||||
// 定义PCD的状态机
|
||||
#define ISO_14443A_PCD_STATE_BEGIN 0xA8
|
||||
#define ISO_14443A_PCD_STATE_START 0xA9 // 开始。如果没有收到,继续发送REQA
|
||||
#define ISO_14443A_PCD_STATE_ANTI 0xAA // 收到ATQA,转入READY.开始防冲突循环?
|
||||
#define ISO_14443A_PCD_STATE_SELECT 0xAB // 收到SAK.
|
||||
|
||||
#define ISO_14443A_PCD_STATE_OK 0xAC // PCD识别出一张卡
|
||||
#define ISO_14443A_PCD_STATE_ER 0xAD // PCD识别卡过程中,错误
|
||||
|
||||
|
||||
#define ISO_14443_CMD_REQA 0x26
|
||||
#define ISO_14443_CMD_WUPA 0x52
|
||||
#define ISO_14443_CMD_SEL_CL1 0x93
|
||||
#define ISO_14443_CMD_SEL_CL2 0x95
|
||||
#define ISO_14443_CMD_SEL_CL3 0x97
|
||||
#define ISO_14443_CMD_HALT 0x50
|
||||
|
||||
#define ISO_14443_PCD 0xF0
|
||||
#define ISO_14443_PICC 0xF1
|
||||
|
||||
// ISO14443A没有定义,自己定义
|
||||
#define ISO_14443_CMD_SAK 0xC0
|
||||
#define ISO_14443_CMD_ATQA 0xC1
|
||||
#define ISO_14443_CMD_SEL_CLx 0xC2 // PICC->PCD防碰撞帧
|
||||
|
||||
int picc_main( int argc, char *argv[] );
|
||||
int pcd_main( int numofpicc );
|
||||
|
||||
/*-----------------------------------------------------------------*\
|
||||
* VSPR中,采用UDP协议仿真空口通讯。
|
||||
* 其中数据格式如下:
|
||||
* 1B: Header, 取值为:0x50
|
||||
* 1B: direction,
|
||||
* 1B: command/response
|
||||
* 1B: reserved, 0x00
|
||||
* 4B: bit length of payload
|
||||
* xx: payload
|
||||
*-----------------------------------------------------------------*/
|
||||
typedef struct tag_HeaderOfVSPRCOM
|
||||
{
|
||||
UCHAR ucHeaderMark;
|
||||
UCHAR ucDirection;
|
||||
UCHAR ucCmd;
|
||||
UCHAR ucRsvd;
|
||||
int nBitLen;
|
||||
}HeaderOfVSPRCOM;
|
||||
|
||||
/*-----------------------------------------------------------------*\
|
||||
* Header
|
||||
*-----------------------------------------------------------------*/
|
||||
#define VSPR_HEADER_MARK 0x50
|
||||
|
||||
/*-----------------------------------------------------------------*\
|
||||
* direction
|
||||
*-----------------------------------------------------------------*/
|
||||
#define DIRECTION_UNDEFINED 0xFF
|
||||
|
||||
#define DIRECTION_PCD_TO_PICC 0x51
|
||||
#define DIRECTION_PICC_FROM_PCD 0x51
|
||||
#define DIRECTION_PICC_TO_PCD 0x52
|
||||
#define DIRECTION_PCD_FROM_PICC 0x52
|
||||
|
||||
#define DIRECTION_VSPR_TO_USP 0x61
|
||||
#define DIRECTION_USP_FROM_VSPR 0x61
|
||||
#define DIRECTION_USP_TO_VSPR 0x62
|
||||
#define DIRECTION_VSPR_FROM_USP 0x62
|
||||
|
||||
#define HOST_VSPR DIRECTION_VSPR_TO_USP
|
||||
#define HOST_USP DIRECTION_USP_TO_VSPR
|
||||
#define HOST_PCD DIRECTION_PCD_TO_PICC
|
||||
#define HOST_PICC DIRECTION_PICC_TO_PCD
|
||||
|
||||
/*-----------------------------------------------------------------*\
|
||||
* command/reponse
|
||||
*-----------------------------------------------------------------*/
|
||||
#define VSPR_CMD_UNSED 0x00
|
||||
|
||||
/**
|
||||
* 编码:code
|
||||
*/
|
||||
#define VSPR_CMD_CODE_1BIT_REQ 0x01
|
||||
#define VSPR_CMD_CODE_1BIT_RSP 0x81
|
||||
#define VSPR_CMD_CODE_SOF_REQ 0x02
|
||||
#define VSPR_CMD_CODE_SOF_RSP 0x82
|
||||
#define VSPR_CMD_CODE_EOF_REQ 0x03
|
||||
#define VSPR_CMD_CODE_EOF_RSP 0x83
|
||||
#define VSPR_CMD_CODE_FRAME_REQ 0x04
|
||||
#define VSPR_CMD_CODE_FRAME_RSP 0x84
|
||||
/**
|
||||
* 解码:code
|
||||
*/
|
||||
#define VSPR_CMD_DECODE_1BIT_REQ 0x08
|
||||
#define VSPR_CMD_DECODE_1BIT_RSP 0x88
|
||||
#define VSPR_CMD_DECODE_SOF_REQ 0x09
|
||||
#define VSPR_CMD_DECODE_SOF_RSP 0x89
|
||||
#define VSPR_CMD_DECODE_EOF_REQ 0x0A
|
||||
#define VSPR_CMD_DECODE_EOF_RSP 0x8A
|
||||
#define VSPR_CMD_DECODE_FRAME_REQ 0x0B
|
||||
#define VSPR_CMD_DECODE_FRAME_RSP 0x8B
|
||||
|
||||
/**
|
||||
* 教验
|
||||
*/
|
||||
#define VSPR_CMD_ODD_PARITY_REQ 0x10
|
||||
#define VSPR_CMD_ODD_PARITY_RSP 0x90
|
||||
#define VSPR_CMD_CRC16_REQ 0x11
|
||||
#define VSPR_CMD_CRC16_RSP 0x91
|
||||
|
||||
/**
|
||||
* 成帧
|
||||
*/
|
||||
#define VSPR_CMD_FRAME_SHORT_REQ 0x20
|
||||
#define VSPR_CMD_FRAME_SHORT_RSP 0xA0
|
||||
#define VSPR_CMD_FRAME_STD_REQ 0x21
|
||||
#define VSPR_CMD_FRAME_STD_RSP 0xA1
|
||||
#define VSPR_CMD_FRAME_ANTICOLISSION_REQ 0x22
|
||||
#define VSPR_CMD_FRAME_ANTICOLISSION_RSP 0xA2
|
||||
/**
|
||||
* 解帧
|
||||
*/
|
||||
#define VSPR_CMD_UNFRAME_SHORT_REQ 0x28
|
||||
#define VSPR_CMD_UNFRAME_SHORT_RSP 0xA8
|
||||
#define VSPR_CMD_UNFRAME_STD_REQ 0x29
|
||||
#define VSPR_CMD_UNFRAME_STD_RSP 0xA9
|
||||
#define VSPR_CMD_UNFRAME_ANTICOLISSION_REQ 0x2A
|
||||
#define VSPR_CMD_UNFRAME_ANTICOLISSION_RSP 0xAA
|
||||
|
||||
/**
|
||||
* 命令
|
||||
*/
|
||||
#define VSPR_CMD_REQA_REQ 0x30
|
||||
#define VSPR_CMD_REQA_RSP 0xB0
|
||||
#define VSPR_CMD_ATRQ_REQ 0x31
|
||||
#define VSPR_CMD_ATRQ_RSP 0xB1
|
||||
#define VSPR_CMD_ANTICOLLISIONREQ_REQ 0x32
|
||||
#define VSPR_CMD_ANTICOLLISIONREQ_RSP 0xB2
|
||||
#define VSPR_CMD_ANTICOLLISIONRSP_REQ 0x33
|
||||
#define VSPR_CMD_ANTICOLLISIONRSP_RSP 0xB3
|
||||
#define VSPR_CMD_SELECT_REQ 0x34
|
||||
#define VSPR_CMD_SELECT_RSP 0xB4
|
||||
#define VSPR_CMD_SAK_REQ 0x35
|
||||
#define VSPR_CMD_SAK_RSP 0xB5
|
||||
#define VSPR_CMD_WUPA_REQ 0x36
|
||||
#define VSPR_CMD_WUPA_RSP 0xB6
|
||||
#define VSPR_CMD_HALT_REQ 0x37
|
||||
#define VSPR_CMD_HALT_RSP 0xB7
|
||||
|
||||
#define VSPR_CMD_UREQA_REQ 0x38
|
||||
#define VSPR_CMD_UREQA_RSP 0xB8
|
||||
#define VSPR_CMD_UATRQ_REQ 0x39
|
||||
#define VSPR_CMD_UATRQ_RSP 0xB9
|
||||
#define VSPR_CMD_UANTICOLLISIONREQ_REQ 0x3A
|
||||
#define VSPR_CMD_UANTICOLLISIONREQ_RSP 0xBA
|
||||
#define VSPR_CMD_UANTICOLLISIONRSP_REQ 0x3B
|
||||
#define VSPR_CMD_UANTICOLLISIONRSP_RSP 0xBB
|
||||
#define VSPR_CMD_USELECT_REQ 0x3C
|
||||
#define VSPR_CMD_USELECT_RSP 0xBC
|
||||
#define VSPR_CMD_USAK_REQ 0x3D
|
||||
#define VSPR_CMD_USAK_RSP 0xBD
|
||||
#define VSPR_CMD_UWUPA_REQ 0x3E
|
||||
#define VSPR_CMD_UWUPA_RSP 0xBE
|
||||
#define VSPR_CMD_UHALT_REQ 0x3F
|
||||
#define VSPR_CMD_UHALT_RSP 0xBF
|
||||
|
||||
#endif
|
||||
81
Labs/Lab2/requirements/src/rfidsrc/rfid_def.h.bak
Normal file
81
Labs/Lab2/requirements/src/rfidsrc/rfid_def.h.bak
Normal file
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* \file rfid_def.h
|
||||
*
|
||||
* \brief 头文件定义
|
||||
*/
|
||||
#ifndef _RFID_DEF_H_
|
||||
#define _RFID_DEF_H_
|
||||
|
||||
//#include "stdafx.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <memory.h>
|
||||
|
||||
//#define _RFID_DEBUG_
|
||||
|
||||
//#define _OS_WINDOWS_
|
||||
|
||||
#ifdef _OS_WINDOWS_
|
||||
#define _RFID_COM_FILE_
|
||||
#define PCD_WAIT_TIME 25
|
||||
#else
|
||||
#define PCD_WAIT_TIME 1
|
||||
#endif
|
||||
|
||||
typedef unsigned char BYTE;
|
||||
typedef unsigned char UCHAR;
|
||||
typedef unsigned short UINT16;
|
||||
typedef unsigned long ULONG;
|
||||
typedef unsigned long UINT32;
|
||||
typedef unsigned short USHORT;
|
||||
typedef unsigned int BOOL;
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
/**
|
||||
* 系统最多仿10个 PICC.
|
||||
*/
|
||||
|
||||
#define MAX_PICC_NUM 10
|
||||
|
||||
/**
|
||||
* 下列宏定义,表示PCD使用broad方式向PICC发送命令
|
||||
* PICC需要加入组播组接收数据
|
||||
*/
|
||||
#define PCD_TO_PICC_USE_BROAD
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------*\
|
||||
* 定义ISO14443A命令和状态
|
||||
*
|
||||
*
|
||||
*-----------------------------------------------------------------*/
|
||||
// 实际上不存在
|
||||
#define ISO_14443A_STATE_POWEROFF 0xA0
|
||||
// 系统启动,就处于IDLE状态,相当于已经加电.
|
||||
#define ISO_14443A_STATE_IDLE 0xA1
|
||||
#define ISO_14443A_STATE_READY 0xA2
|
||||
#define ISO_14443A_STATE_ACTIVE 0xA3
|
||||
#define ISO_14443A_STATE_HALT 0xA4
|
||||
|
||||
// 定义PCD的状态机
|
||||
#define ISO_14443A_PCD_STATE_OK 0xA8 // PCD识别出一张卡
|
||||
#define ISO_14443A_PCD_STATE_ER 0xA9 // PCD识别卡过程中,错误
|
||||
|
||||
#define ISO_14443A_PCD_STATE_START 0xAA // 开始。如果没有收到,继续发送REQA
|
||||
#define ISO_14443A_PCD_STATE_ANTI 0xAB // 收到ATQA,转入READY.开始防冲突循环?
|
||||
#define ISO_14443A_PCD_STATE_SELECT 0xAC // 收到SAK.
|
||||
|
||||
|
||||
#define ISO_14443_CMD_REQA 0x26
|
||||
#define ISO_14443_CMD_WUPA 0x52
|
||||
#define ISO_14443_CMD_SEL_CL1 0x93
|
||||
#define ISO_14443_CMD_SEL_CL2 0x95
|
||||
#define ISO_14443_CMD_SEL_CL3 0x97
|
||||
#define ISO_14443_CMD_HALT 0x50
|
||||
|
||||
#define ISO_14443_PCD 0xF0
|
||||
#define ISO_14443_PICC 0xF1
|
||||
|
||||
#endif
|
||||
|
||||
270
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_cmdrx.cpp
Normal file
270
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_cmdrx.cpp
Normal file
@@ -0,0 +1,270 @@
|
||||
/**
|
||||
* \file rfid_iso14443A_cmdrx.c
|
||||
*
|
||||
* \brief ISO14443A<33><41><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
*
|
||||
* <09>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD>PCD/PICC<43><43><EFBFBD>շ<EFBFBD><D5B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD>
|
||||
*
|
||||
* <09><>ͬ״̬<D7B4>£<EFBFBD>Ҫ<EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EEB2BB><CDAC><EFBFBD><EFBFBD><EFBFBD>Կ<EFBFBD><D4BF>ǵȴ<C7B5><C8B4>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD><EEA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EEA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
//#include "stdafx.h"
|
||||
#include "rfid_iso14443A_codec.h"
|
||||
#include "rfid_iso14443A_frm.h"
|
||||
|
||||
#include "rfid_iso14443A_cmdrx.h"
|
||||
/**
|
||||
*
|
||||
* PICC <09>ȴ<EFBFBD>REQA
|
||||
*/
|
||||
int ISO14443A_wait_ShortFrame( BYTE abyRxBuf[], UINT16 u16BufBitLen, BYTE *pbyCmd )
|
||||
{
|
||||
BYTE abyFrmBuf[100];
|
||||
UINT16 u16FrmBitLen;
|
||||
|
||||
// REQA<51>ı<EFBFBD><C4B1>볤<EFBFBD><EBB3A4>ȷ<EFBFBD><C8B7>Ϊ: SOF(4)+CMD(28)+EOF(4) = 36
|
||||
if( u16BufBitLen != 36 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
|
||||
if( ISO14443A_PICC_Decode( abyRxBuf, u16BufBitLen, abyFrmBuf, &u16FrmBitLen) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// <20><>֡
|
||||
if( ISO14443A_Un_ShortFraming( abyFrmBuf, u16FrmBitLen, pbyCmd ) < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ISO14443A_wait_REQA( BYTE abyRxBuf[], UINT16 u16BufBitLen )
|
||||
{ // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
BYTE byCmd;
|
||||
|
||||
if( ISO14443A_wait_ShortFrame( abyRxBuf, u16BufBitLen, &byCmd ) < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return byCmd == ISO_14443_CMD_REQA ? 1:-1;
|
||||
}
|
||||
|
||||
|
||||
int ISO14443A_wait_WUPA( BYTE abyRxBuf[], UINT16 u16BufBitLen )
|
||||
{ // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
BYTE byCmd;
|
||||
|
||||
if( ISO14443A_wait_ShortFrame( abyRxBuf, u16BufBitLen, &byCmd ) < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return byCmd == ISO_14443_CMD_WUPA ? 1:-1;
|
||||
}
|
||||
|
||||
// PCD/PICC<43><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>֡
|
||||
//
|
||||
int ISO14443A_wait_stdFrame( BOOL bPCD, UINT16 u16HopeCmdLen,
|
||||
BYTE abyRxBuf[], UINT16 u16BufBitLen,
|
||||
BYTE abyCmdBuf[], UINT16 *pu16CmdBitLen )
|
||||
{
|
||||
BYTE abyFrmBuf[100];
|
||||
UINT16 u16FrmBitLen;
|
||||
int r;
|
||||
int k;
|
||||
|
||||
// <20><>֡<D7BC>ij<EFBFBD><C4B3>ȣ<EFBFBD>(( cmdlen + 2(crc)) * 9(parity) + sof(1) + eof(1)) * 4
|
||||
k = (( u16HopeCmdLen + 2 ) * 9 + 2 ) * ISO14443A_BIT_CODEC_LEN;
|
||||
|
||||
// REQA<51>ı<EFBFBD><C4B1>볤<EFBFBD><EBB3A4>ȷ<EFBFBD><C8B7>Ϊ: SOF(4)+CMD(28)+EOF(4) = 36
|
||||
if( u16BufBitLen != k )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>
|
||||
if( bPCD )
|
||||
{
|
||||
r = ISO14443A_PCD_Decode( abyRxBuf, u16BufBitLen, abyFrmBuf, &u16FrmBitLen );
|
||||
}
|
||||
else
|
||||
{
|
||||
r = ISO14443A_PICC_Decode( abyRxBuf, u16BufBitLen, abyFrmBuf, &u16FrmBitLen );
|
||||
}
|
||||
|
||||
|
||||
if( r < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// <20><>֡
|
||||
if( ISO14443A_Un_stdFraming( abyFrmBuf, u16FrmBitLen, abyCmdBuf, pu16CmdBitLen ) < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return *pu16CmdBitLen;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD>ص<EFBFBD><D8B5><EFBFBD>Զ<EFBFBD><D4B6>4<EFBFBD>ֽڳ<D6BD><DAB3>ȵ<EFBFBD>UID.
|
||||
int ISO14443A_wait_SELECT( BYTE abyRxBuf[], UINT16 u16BufBitLen, BYTE *psel, BYTE abyUID[] )
|
||||
{
|
||||
BYTE abyCmdBuf[100], byBCC;
|
||||
UINT16 u16CmdBitLen;
|
||||
int i;
|
||||
|
||||
if( ISO14443A_wait_stdFrame( false, 7, abyRxBuf, u16BufBitLen, abyCmdBuf, &u16CmdBitLen ) < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>.
|
||||
if( abyCmdBuf[0] != ISO_14443_CMD_SEL_CL1
|
||||
&& abyCmdBuf[0] != ISO_14443_CMD_SEL_CL2
|
||||
&& abyCmdBuf[0] != ISO_14443_CMD_SEL_CL3
|
||||
)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// NVB
|
||||
if( abyCmdBuf[1] != 0x70 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>BCC.
|
||||
byBCC = 0x00;
|
||||
for( i = 2; i < 6; i++ )
|
||||
{
|
||||
byBCC = byBCC ^ abyCmdBuf[i];
|
||||
}
|
||||
if( byBCC != abyCmdBuf[6] )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
*psel = abyCmdBuf[0];
|
||||
memcpy( abyUID, &abyCmdBuf[2], 4 );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ISO14443A_wait_HALT( BYTE abyRxBuf[], UINT16 u16BufBitLen )
|
||||
{
|
||||
BYTE abyCmdBuf[100];
|
||||
UINT16 u16CmdBitLen;
|
||||
|
||||
if( ISO14443A_wait_stdFrame( false, 2, abyRxBuf, u16BufBitLen, abyCmdBuf, &u16CmdBitLen ) < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( abyCmdBuf[0] != 0x50 || abyCmdBuf[1] != 0x00 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ISO14443A_wait_SAK( BYTE abyRxBuf[], UINT16 u16BufBitLen, BYTE *pByCmd )
|
||||
{
|
||||
BYTE abyCmdBuf[100];
|
||||
UINT16 u16CmdBitLen;
|
||||
|
||||
if( ISO14443A_wait_stdFrame( true, 1, abyRxBuf, u16BufBitLen, abyCmdBuf, &u16CmdBitLen ) < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
*pByCmd = abyCmdBuf[0];
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ISO14443A_wait_ATQA( BYTE abyRxBuf[], UINT16 u16BufBitLen, BYTE *pByCLn, BYTE aByCmd[] )
|
||||
{
|
||||
BYTE abyCmdBuf[100];
|
||||
UINT16 u16CmdBitLen;
|
||||
|
||||
if( ISO14443A_wait_stdFrame( true, 2, abyRxBuf, u16BufBitLen, abyCmdBuf, &u16CmdBitLen ) < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( aByCmd )
|
||||
{
|
||||
aByCmd[0] = abyCmdBuf[0];
|
||||
aByCmd[1] = abyCmdBuf[1];
|
||||
}
|
||||
|
||||
*pByCLn = ( abyCmdBuf[1] >> 6 ) & 0x03;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ײ֡.
|
||||
int ISO14443A_wait_anticollisionFrame(
|
||||
BOOL bPCD,
|
||||
BYTE byFirstByteLen, BYTE *pFirstByte,
|
||||
BYTE abyRxBuf[], UINT16 u16BufBitLen,
|
||||
BYTE abyCmdBuf[], UINT16 *pu16CmdBitLen )
|
||||
{
|
||||
BYTE abyFrmBuf[100];
|
||||
UINT16 u16FrmBitLen;
|
||||
int r;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>
|
||||
if( bPCD )
|
||||
{
|
||||
r = ISO14443A_PCD_Decode( abyRxBuf, u16BufBitLen, abyFrmBuf, &u16FrmBitLen );
|
||||
}
|
||||
else
|
||||
{
|
||||
r = ISO14443A_PICC_Decode( abyRxBuf, u16BufBitLen, abyFrmBuf, &u16FrmBitLen );
|
||||
}
|
||||
|
||||
|
||||
if( r < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// <20><>֡
|
||||
if( ISO14443A_Un_AnticollisionFraming( byFirstByteLen, pFirstByte,
|
||||
abyFrmBuf, u16FrmBitLen, abyCmdBuf, pu16CmdBitLen ) < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return *pu16CmdBitLen;
|
||||
}
|
||||
|
||||
// req: PICC<43>˵ȴ<CBB5>
|
||||
int ISO14443A_wait_anticollisionFrame_req(
|
||||
BYTE abyRxBuf[], UINT16 u16BufBitLen,
|
||||
BYTE abyCmdBuf[], UINT16 *pu16CmdBitLen )
|
||||
{
|
||||
return ISO14443A_wait_anticollisionFrame( false, 0, NULL,
|
||||
abyRxBuf, u16BufBitLen,
|
||||
abyCmdBuf, pu16CmdBitLen );
|
||||
}
|
||||
|
||||
// rsp: PCD<43>ȴ<EFBFBD>
|
||||
int ISO14443A_wait_anticollisionFrame_rsp(
|
||||
BYTE byFirstByteLen, BYTE *pFirstByte,
|
||||
BYTE abyRxBuf[], UINT16 u16BufBitLen,
|
||||
BYTE abyCmdBuf[], UINT16 *pu16CmdBitLen )
|
||||
{
|
||||
return ISO14443A_wait_anticollisionFrame( true, byFirstByteLen, pFirstByte,
|
||||
abyRxBuf, u16BufBitLen,
|
||||
abyCmdBuf, pu16CmdBitLen );
|
||||
}
|
||||
|
||||
|
||||
48
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_cmdrx.h
Normal file
48
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_cmdrx.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* \file rfid_iso14443A_cmdrx.h
|
||||
*
|
||||
* \brief ISO14443A<33><41><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
*
|
||||
* <09>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD>PCD/PICC<43><43><EFBFBD>շ<EFBFBD><D5B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD>
|
||||
*
|
||||
* <09><>ͬ״̬<D7B4>£<EFBFBD>Ҫ<EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EEB2BB><CDAC><EFBFBD><EFBFBD><EFBFBD>Կ<EFBFBD><D4BF>ǵȴ<C7B5><C8B4>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD><EEA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EEA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
|
||||
#ifndef _RFID_ISO14443A_CMDRX_H_
|
||||
#define _RFID_ISO14443A_CMDRX_H_
|
||||
|
||||
#include "rfid_def.h"
|
||||
#include "rfid_iso14443A_codec.h"
|
||||
#include "rfid_iso14443A_frm.h"
|
||||
#include "rfid_com.h"
|
||||
|
||||
//PCD
|
||||
int ISO14443A_wait_ATQA( BYTE abyRxBuf[], UINT16 u16BufBitLen, BYTE *pByCLn );
|
||||
int ISO14443A_wait_ATQA( BYTE abyRxBuf[], UINT16 u16BufBitLen, BYTE *pByCLn, BYTE aByCmd[2] );
|
||||
int ISO14443A_wait_SAK( BYTE abyRxBuf[], UINT16 u16BufBitLen, BYTE *pbyCmd );
|
||||
int ISO14443A_wait_anticollisionFrame_rsp(
|
||||
BYTE byFirstByteLen, BYTE *pFirstByte,
|
||||
BYTE abyRxBuf[], UINT16 u16BufBitLen,
|
||||
BYTE abyCmdBuf[], UINT16 *pu16CmdBitLen );
|
||||
|
||||
//PICC
|
||||
int ISO14443A_wait_REQA( BYTE abyRxBuf[], UINT16 u16BufBitLen );
|
||||
int ISO14443A_wait_WUPA( BYTE abyRxBuf[], UINT16 u16BufBitLen );
|
||||
int ISO14443A_wait_SELECT( BYTE abyRxBuf[], UINT16 u16BufBitLen, BYTE *psel, BYTE abyUID[] );
|
||||
int ISO14443A_wait_HALT( BYTE abyRxBuf[], UINT16 u16BufBitLen );
|
||||
int ISO14443A_wait_anticollisionFrame_req(
|
||||
BYTE abyRxBuf[], UINT16 u16BufBitLen,
|
||||
BYTE abyCmdBuf[], UINT16 *pu16CmdBitLen );
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int ISO14443A_wait_ShortFrame( BYTE abyRxBuf[], UINT16 u16BufBitLen, BYTE *pbyCmd );
|
||||
int ISO14443A_wait_stdFrame( BOOL bPCD, UINT16 u16HopeCmdLen,
|
||||
BYTE abyRxBuf[], UINT16 u16BufBitLen,
|
||||
BYTE abyCmdBuf[], UINT16 *pu16CmdBitLen );
|
||||
int ISO14443A_wait_anticollisionFrame(
|
||||
BOOL bPCD,
|
||||
BYTE byFirstByteLen, BYTE *pFirstByte,
|
||||
BYTE abyRxBuf[], UINT16 u16BufBitLen,
|
||||
BYTE abyCmdBuf[], UINT16 *pu16CmdBitLen );
|
||||
|
||||
#endif
|
||||
335
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_cmdtx.cpp
Normal file
335
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_cmdtx.cpp
Normal file
@@ -0,0 +1,335 @@
|
||||
/**
|
||||
* \file rfid_iso14443A_cmdtx.c
|
||||
*
|
||||
* \brief ISO14443A<33><41><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*-------------------------------------------------------------*\
|
||||
* ISO14443A
|
||||
* 1. <20><>֡<EFBFBD><D6A1>REQA(PCD) & WUPA(PCD)
|
||||
* 2. <20><>֡<D7BC><D6A1>SELECT(PCD), HALT(PCD), ATQA(PICC), SAK(PICC)
|
||||
* 3. <20><><EFBFBD><EFBFBD>ײ֡<D7B2><D6A1>ANTICOLLISION_req(PCD)/rsp(PICC)
|
||||
*-------------------------------------------------------------*/
|
||||
|
||||
#include "rfid_iso14443A_cmdtx.h"
|
||||
#include "memory.h"
|
||||
#include "picc_thread.h"
|
||||
#include "pcd_thread.h"
|
||||
|
||||
/*--------------------------------------------------------------*\
|
||||
* <20><>֡
|
||||
\*---------------------------------------------------------------*/
|
||||
/**
|
||||
* \fun ISO14443A_REQA_req()
|
||||
* \brief PCD->PICC
|
||||
*
|
||||
* \input .
|
||||
* \return 0<>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>;
|
||||
*/
|
||||
int ISO14443A_REQA()
|
||||
{
|
||||
/**
|
||||
* REQA<51><41><EFBFBD>
|
||||
* 7bit<69><74><EFBFBD><EFBFBD>֡<EFBFBD><D6A1>ֵ<EFBFBD><D6B5>0x26.
|
||||
*/
|
||||
{
|
||||
UCHAR cmd;
|
||||
cmd = ISO_14443_CMD_REQA;
|
||||
pcd_postMessage( &cmd, 7, ISO_14443_CMD_REQA, "wait ATRQ" );
|
||||
}
|
||||
return ISO14443A_ShortFrame_req( ISO_14443_CMD_REQA );
|
||||
}
|
||||
|
||||
/**
|
||||
* \fun ISO14443A_WUPA_req()
|
||||
* \brief PCD->PICC
|
||||
*
|
||||
* \input .
|
||||
* \return 0<>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>;
|
||||
*/
|
||||
int ISO14443A_WUPA()
|
||||
{
|
||||
/**
|
||||
* WUPA<50><41><EFBFBD>
|
||||
* 7bit<69><74><EFBFBD><EFBFBD>֡<EFBFBD><D6A1>ֵ<EFBFBD><D6B5>0x52.
|
||||
*/
|
||||
{
|
||||
UCHAR cmd;
|
||||
cmd = ISO_14443_CMD_WUPA;
|
||||
pcd_postMessage( &cmd, 7, ISO_14443_CMD_WUPA, "wait ATRQ" );
|
||||
}
|
||||
|
||||
return ISO14443A_ShortFrame_req( ISO_14443_CMD_WUPA );
|
||||
}
|
||||
|
||||
// <20><>֡
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>롢<EFBFBD><EBA1A2>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD>͡<EFBFBD>
|
||||
// <20><>PCD/PICC<43>˶<EFBFBD><CBB6><EFBFBD>ͬ
|
||||
int ISO14443A_ShortFrame_req( BYTE byCmd )
|
||||
{
|
||||
BYTE abyTxBuf[100], abyFrmBuf[100];
|
||||
UINT16 u16CodedLen,u16FrmLen;
|
||||
|
||||
/**
|
||||
* 1. <20><>֡
|
||||
*/
|
||||
if( ISO14443A_ShortFraming( byCmd, abyFrmBuf, &u16FrmLen ) < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 2. <20><><EFBFBD><EFBFBD>
|
||||
* <09><>֡һ<D6A1><D2BB><EFBFBD><EFBFBD>SOF<4F><46>EOF
|
||||
*/
|
||||
if( ISO14443A_PCD_Code( abyFrmBuf, u16FrmLen, abyTxBuf, &u16CodedLen ) < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return RFID_Reader_Tx( u16CodedLen, abyTxBuf );
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------*\
|
||||
* <20><>֡
|
||||
*---------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* \fun ISO14443A_SELECT()
|
||||
* \brief PCD->PICC
|
||||
*
|
||||
* \input .
|
||||
* \return 0<>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>;
|
||||
*/
|
||||
int ISO14443A_SELECT( BYTE sel, BYTE abyUID[] )
|
||||
{
|
||||
/**
|
||||
* SELECT<43><54>CRC16.
|
||||
*/
|
||||
BYTE abyCmd[7];
|
||||
int i;
|
||||
|
||||
abyCmd[0] = sel; // SELECT: 0x93,0x95,0x97
|
||||
abyCmd[1] = 0x70; // SELECT
|
||||
abyCmd[6] = 0x00;
|
||||
for( i = 0; i < 4; i++ )
|
||||
{
|
||||
abyCmd[i+2] = abyUID[i];
|
||||
abyCmd[6] = abyCmd[6] ^ abyUID[i];
|
||||
}
|
||||
|
||||
pcd_postMessage( abyCmd, 56, sel, "wait SAK" );
|
||||
return ISO14443A_stdFrame_req( abyCmd, 56 );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \fun ISO14443A_HALT()
|
||||
* \brief PCD->PICC
|
||||
*
|
||||
* \input .
|
||||
* \return 0<>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>;
|
||||
*/
|
||||
int ISO14443A_HALT()
|
||||
{
|
||||
BYTE abyCmd[]={0x50, 0x00};
|
||||
|
||||
pcd_postMessage( abyCmd, 16, ISO_14443_CMD_HALT, NULL );
|
||||
return ISO14443A_stdFrame_req( abyCmd, 16 );
|
||||
}
|
||||
|
||||
/**
|
||||
* \fun ISO14443A_ATQA()
|
||||
* \brief PICC->PCD
|
||||
* <09><>REQA/WUKA<4B><41>Ӧ<EFBFBD><D3A6>
|
||||
* <09><>֡.
|
||||
* \input
|
||||
* \return 0<>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>;
|
||||
*/
|
||||
int ISO14443A_ATQA( BYTE byCLn )
|
||||
{
|
||||
BYTE abyCmd[2];
|
||||
|
||||
byCLn = byCLn & 0x03; // <20><><EFBFBD><EFBFBD>3λ<33><CEBB>Ч
|
||||
abyCmd[1] = (byCLn << 6) + 0x01;
|
||||
abyCmd[0] = 0x00;
|
||||
|
||||
picc_postMessage( (UCHAR *)abyCmd, 16, ISO_14443_CMD_ATQA );
|
||||
|
||||
return ISO14443A_stdFrame_rsp( abyCmd, 16 );
|
||||
}
|
||||
|
||||
/**
|
||||
* \fun ISO14443A_SAK()
|
||||
* \brief PICC->PCD
|
||||
* <09><>SELECT/ANTICOLLISION<4F><4E>Ӧ<EFBFBD><D3A6>
|
||||
*
|
||||
* \input cascade: 0/1.
|
||||
* \return 0<>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>;
|
||||
*/
|
||||
int ISO14443A_SAK( BYTE cascade )
|
||||
{
|
||||
return ISO14443A_stdFrame_rsp( &cascade, 8 );
|
||||
}
|
||||
|
||||
|
||||
// <20><>֡<D7BC><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>CRC<52><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3>
|
||||
// PCDʹ<44><CAB9>
|
||||
int ISO14443A_stdFrame_req( BYTE abyBuf[], UINT16 u16BitLen )
|
||||
{
|
||||
BYTE abyCodeBuf[1024], abyFrmBuf[1024];
|
||||
UINT16 u16CodedLen,u16FrmLen;
|
||||
|
||||
/**
|
||||
* 1. <20><>֡
|
||||
*/
|
||||
if( ISO14443A_stdFraming( abyBuf, u16BitLen, abyFrmBuf, &u16FrmLen ) < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 2. <20><><EFBFBD><EFBFBD>
|
||||
* <09><>֡һ<D6A1><D2BB><EFBFBD><EFBFBD>SOF<4F><46>EOF
|
||||
*/
|
||||
if( ISO14443A_PCD_Code( abyFrmBuf, u16FrmLen, abyCodeBuf, &u16CodedLen ) < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 3. <20><><EFBFBD><EFBFBD>
|
||||
*/
|
||||
return RFID_Reader_Tx( u16CodedLen, abyCodeBuf );
|
||||
}
|
||||
|
||||
// <20><>֡<D7BC><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>CRC<52><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3>
|
||||
// PICC<43><43>ʹ<EFBFBD><CAB9>
|
||||
int ISO14443A_stdFrame_rsp( BYTE abyBuf[], UINT16 u16BitLen )
|
||||
{
|
||||
BYTE abyCodeBuf[1024], abyFrmBuf[1024];
|
||||
UINT16 u16CodedLen,u16FrmLen;
|
||||
|
||||
/**
|
||||
* 1. <20><>֡
|
||||
*/
|
||||
if( ISO14443A_stdFraming( abyBuf, u16BitLen, abyFrmBuf, &u16FrmLen ) < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 2. <20><><EFBFBD><EFBFBD>
|
||||
* <09><>֡һ<D6A1><D2BB><EFBFBD><EFBFBD>SOF<4F><46>EOF
|
||||
*/
|
||||
if( ISO14443A_PICC_Code( abyFrmBuf, u16FrmLen, abyCodeBuf, &u16CodedLen ) < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 3. <20><><EFBFBD><EFBFBD>
|
||||
*/
|
||||
return RFID_Card_Tx( u16CodedLen, abyCodeBuf );
|
||||
}
|
||||
/*--------------------------------------------------------------*\
|
||||
* <20><><EFBFBD><EFBFBD>ײ֡
|
||||
*---------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* <09><><EFBFBD><EFBFBD>ײ֡<D7B2><D6A1><EFBFBD><EFBFBD>PCD<43><44>PICC<43>˲<EFBFBD>ͬ
|
||||
*/
|
||||
int ISO14443A_AnticollisionFrame_req(
|
||||
BYTE bySEL, BYTE abyUID[], UINT16 u16BitLen )
|
||||
{
|
||||
BYTE abyCmd[7];
|
||||
BYTE abyCodeBuf[1024], abyFrmBuf[1024];
|
||||
UINT16 u16CodedLen,u16FrmLen, u16CmdBitLen;
|
||||
int m,n,k,i;
|
||||
|
||||
abyCmd[0] = bySEL;
|
||||
|
||||
n = u16BitLen % 8;
|
||||
k = u16BitLen/8 + ((n != 0 )? 1:0);
|
||||
m = 2 + k;
|
||||
abyCmd[1] = ((m & 0x0F) << 4 )+(n & 0x0F);
|
||||
|
||||
for( i = 0; i < k; i++ )
|
||||
{
|
||||
abyCmd[i+2] = abyUID[i];
|
||||
}
|
||||
u16CmdBitLen = 16 + u16BitLen;
|
||||
|
||||
{
|
||||
pcd_postMessage( abyCmd, u16CmdBitLen, bySEL, "wait ANTI" );
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. <20><>֡
|
||||
*/
|
||||
if( ISO14443A_AnticollisionFraming( 0, 0, abyCmd, u16CmdBitLen, abyFrmBuf, &u16FrmLen ) < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 2. <20><><EFBFBD><EFBFBD>
|
||||
* <09><><EFBFBD><EFBFBD>ײ֡һ<D6A1><D2BB><EFBFBD><EFBFBD>SOF<4F><46><EFBFBD><EFBFBD>û<EFBFBD><C3BB>EOF
|
||||
*/
|
||||
if( ISO14443A_PCD_Code( abyFrmBuf, u16FrmLen, abyCodeBuf, &u16CodedLen ) < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 3. <20><><EFBFBD><EFBFBD>
|
||||
*/
|
||||
return RFID_Reader_Tx( u16CodedLen, abyCodeBuf );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// PICC<43><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>RSP.
|
||||
// BCCҪ<43><D2AA><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int ISO14443A_AnticollisionFrame_rsp(
|
||||
BYTE byBitLenofFirstByte, // <20><>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD>е<EFBFBD>bit Len<65><6E><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>ײ֡<D7B2><D6A1><EFBFBD><EFBFBD>Ҫ
|
||||
BYTE byFirstByte,
|
||||
BYTE abyUID[], UINT16 u16UIDBitLen,
|
||||
BYTE byBCC
|
||||
)
|
||||
{
|
||||
BYTE abyCmd[7];
|
||||
BYTE abyCodeBuf[1024], abyFrmBuf[1024];
|
||||
UINT16 u16CodedLen,u16FrmLen;
|
||||
int k;
|
||||
|
||||
/**
|
||||
* 1. <20><>֡
|
||||
*/
|
||||
k = u16UIDBitLen / 8;
|
||||
memcpy( abyCmd, abyUID, k );
|
||||
abyCmd[k] = byBCC;
|
||||
|
||||
if( ISO14443A_AnticollisionFraming( byBitLenofFirstByte, byFirstByte,
|
||||
abyCmd, (k+1)*8, abyFrmBuf, &u16FrmLen ) < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 2. <20><><EFBFBD><EFBFBD>
|
||||
* <09><>֡һ<D6A1><D2BB><EFBFBD><EFBFBD>SOF<4F><46>EOF
|
||||
*/
|
||||
if( ISO14443A_PICC_Code( abyFrmBuf, u16FrmLen, abyCodeBuf, &u16CodedLen ) < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 3. <20><><EFBFBD><EFBFBD>
|
||||
*/
|
||||
return RFID_Card_Tx( u16CodedLen, abyCodeBuf );
|
||||
}
|
||||
|
||||
|
||||
109
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_cmdtx.h
Normal file
109
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_cmdtx.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* \file rfid_iso14443A_cmdtx.h
|
||||
*
|
||||
* \brief ISO14443A<33><41><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
*
|
||||
*/
|
||||
#ifndef _RFID_ISO14443A_CMD_H_
|
||||
#define _RFID_ISO14443A_CMD_H_
|
||||
|
||||
#include "rfid_iso14443A_codec.h"
|
||||
#include "rfid_iso14443A_frm.h"
|
||||
#include "rfid_com.h"
|
||||
|
||||
/*-------------------------------------------------------------*\
|
||||
* ISO14443A
|
||||
* PCD<43><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*-------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* \fun ISO14443A_REQA_req()
|
||||
* \brief PCD->PICC
|
||||
*
|
||||
* \input .
|
||||
* \return 0<>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>;
|
||||
*/
|
||||
int ISO14443A_REQA();
|
||||
/**
|
||||
* \fun ISO14443A_WUPA_req()
|
||||
* \brief PCD->PICC
|
||||
*
|
||||
* \input .
|
||||
* \return 0<>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>;
|
||||
*/
|
||||
int ISO14443A_WUPA();
|
||||
/**
|
||||
* \fun ISO14443A_SELECT()
|
||||
* \brief PCD->PICC
|
||||
*
|
||||
* \input .
|
||||
* \return 0<>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>;
|
||||
*/
|
||||
int ISO14443A_SELECT( BYTE sel, BYTE abyUID[] );
|
||||
|
||||
/**
|
||||
* \fun ISO14443A_ANTICOLLISION()
|
||||
* \brief PCD->PICC
|
||||
*
|
||||
* \input .
|
||||
* \return 0<>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>;
|
||||
*/
|
||||
int ISO14443A_AnticollisionFrame_req( BYTE bySEL, BYTE abyUID[], UINT16 u16BitLen );
|
||||
|
||||
/**
|
||||
* \fun ISO14443A_HALT()
|
||||
* \brief PCD->PICC
|
||||
*
|
||||
* \input .
|
||||
* \return 0<>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>;
|
||||
*/
|
||||
int ISO14443A_HALT();
|
||||
|
||||
/*-------------------------------------------------------------*\
|
||||
* ISO14443A
|
||||
* PICC<43><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*-------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* \fun ISO14443A_ATQA()
|
||||
* \brief PCD->PICC
|
||||
* <09><>REQA/WUKA<4B><41>Ӧ<EFBFBD><D3A6>
|
||||
*
|
||||
* \input .
|
||||
* \return 0<>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>;
|
||||
*/
|
||||
int ISO14443A_ATQA( BYTE uidCLn );
|
||||
|
||||
|
||||
/**
|
||||
* \fun ISO14443A_SAK()
|
||||
* \brief PCD->PICC
|
||||
* <09><>SELECT<43><54>Ӧ<EFBFBD><D3A6>
|
||||
*
|
||||
* \input .
|
||||
* \return 0<>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>;
|
||||
*/
|
||||
int ISO14443A_SAK( BYTE cascade );
|
||||
|
||||
|
||||
/**
|
||||
* \fun ISO14443A_ANTICOLLISION()
|
||||
* \brief PCD->PICC
|
||||
* <09><>ANTICOLLISION<4F><4E>Ӧ<EFBFBD><D3A6>
|
||||
*
|
||||
* \input .
|
||||
* \return 0<>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>;
|
||||
*/
|
||||
int ISO14443A_AnticollisionFrame_rsp(
|
||||
BYTE byBitLenofFirstByte, // <20><>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD>е<EFBFBD>bit Len<65><6E><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>ײ֡<D7B2><D6A1><EFBFBD><EFBFBD>Ҫ
|
||||
BYTE byFirstByte,
|
||||
BYTE abyUID[], UINT16 u16UIDBitLen,
|
||||
BYTE byBCC
|
||||
);
|
||||
|
||||
|
||||
int ISO14443A_ShortFrame_req( BYTE byCmd );
|
||||
int ISO14443A_stdFrame_req( BYTE abyBuf[], UINT16 u16BitLen );
|
||||
int ISO14443A_stdFrame_rsp( BYTE abyBuf[], UINT16 u16BitLen );
|
||||
|
||||
#endif
|
||||
387
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_codec.cpp
Normal file
387
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_codec.cpp
Normal file
@@ -0,0 +1,387 @@
|
||||
/**
|
||||
* rfid_iso14443A_codec.c
|
||||
*
|
||||
* ISO14443<34><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* 1. <20><><EFBFBD><EFBFBD>/ȥ<><C8A5> SOF/EOF
|
||||
* 2. <20><><EFBFBD><EFBFBD>Buf: bit7 <20><><EFBFBD>ͳ<EFBFBD>.
|
||||
* 3. <20><><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD>bit7,6,...0.
|
||||
*/
|
||||
|
||||
//#include "stdafx.h"
|
||||
#include "rfid_iso14443A_codec.h"
|
||||
|
||||
int ISO14443A_PCD_Code(
|
||||
BYTE aInBuf[], UINT16 u16InBitLen,
|
||||
BYTE aoutBuf[], UINT16 *pu16OutBitLen
|
||||
)
|
||||
{
|
||||
return ISO14443A_Code(
|
||||
TRUE,
|
||||
aInBuf, u16InBitLen, aoutBuf, pu16OutBitLen
|
||||
);
|
||||
}
|
||||
|
||||
int ISO14443A_PCD_Decode(
|
||||
BYTE aInBuf[], UINT16 u16InBitLen,
|
||||
BYTE aOutBuf[], UINT16 *pu16OutBitLen
|
||||
)
|
||||
{
|
||||
return ISO14443A_Decode(
|
||||
true,
|
||||
aInBuf, u16InBitLen, aOutBuf, pu16OutBitLen
|
||||
);
|
||||
}
|
||||
|
||||
int ISO14443A_PICC_Code(
|
||||
BYTE aInBuf[], UINT16 u16InBitLen,
|
||||
BYTE aoutBuf[], UINT16 *pu16OutBitLen
|
||||
)
|
||||
{
|
||||
return ISO14443A_Code(
|
||||
FALSE,
|
||||
aInBuf, u16InBitLen, aoutBuf, pu16OutBitLen
|
||||
);
|
||||
}
|
||||
|
||||
int ISO14443A_PICC_Decode(
|
||||
BYTE aInBuf[], UINT16 u16InBitLen,
|
||||
BYTE aOutBuf[], UINT16 *pu16OutBitLen
|
||||
)
|
||||
{
|
||||
return ISO14443A_Decode(
|
||||
FALSE,
|
||||
aInBuf, u16InBitLen, aOutBuf, pu16OutBitLen
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// <20><><EFBFBD>룺
|
||||
// <20><><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>ֽڣ<D6BD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߱<EFBFBD><DFB1><EFBFBD>bit7<74><37>ʼ
|
||||
//
|
||||
// BYTE1 BYTE2 ...BYTEn
|
||||
// bit: 7,6,5,4,3,2,1,0 7,... 7,6,5.
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>飬CRC<52>ȡ<EFBFBD>
|
||||
//
|
||||
// <20><><EFBFBD>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȳ<EFBFBD><C8B3><EFBFBD>.
|
||||
int ISO14443A_Code(
|
||||
BOOL bPCD, // PCD<43><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
BYTE aInBuf[], UINT16 u16InBitLen,
|
||||
BYTE aOutBuf[], UINT16 *pu16OutBitLen
|
||||
)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD>SOF
|
||||
int bitLen, byLen, ibitLen;
|
||||
int i, j, k;
|
||||
int prebit,curbit;
|
||||
BYTE code;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>SOF
|
||||
bitLen = 0;
|
||||
byLen = 0;
|
||||
aOutBuf[byLen] = 0x00;
|
||||
|
||||
// SOF
|
||||
{
|
||||
if( bPCD )
|
||||
{
|
||||
aOutBuf[byLen] = ISO14443A_PCD_SOF << 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
aOutBuf[byLen] = ISO14443A_PICC_SOF << 4;
|
||||
}
|
||||
|
||||
bitLen++;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF>bit.
|
||||
prebit = 0; // <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ0, ֻ<><D6BB>PCD<43><44>Ч<EFBFBD><D0A7>
|
||||
i = 0;
|
||||
ibitLen = 0;
|
||||
while( ibitLen < u16InBitLen )
|
||||
{
|
||||
// ÿ<><C3BF>BYTE<54><45><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>.
|
||||
if( (u16InBitLen - ibitLen) >= 8 )
|
||||
{
|
||||
k = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
k = 8 - u16InBitLen % 8;
|
||||
}
|
||||
|
||||
// <20>ȱ<EFBFBD><C8B1><EFBFBD><EFBFBD><EFBFBD>bit
|
||||
for( j = 7; j >=k ; j-- )
|
||||
{
|
||||
curbit = ( aInBuf[i] >> j ) & 0x01;
|
||||
if( bPCD )
|
||||
{
|
||||
code = RFID_Code_Miller( prebit, curbit ) & 0x0F;
|
||||
}
|
||||
else
|
||||
{
|
||||
code = RFID_Code_Manchester( curbit );
|
||||
}
|
||||
|
||||
if( bitLen % 2 == 0 )
|
||||
{
|
||||
aOutBuf[byLen] |= code << 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
aOutBuf[byLen] |= code;
|
||||
byLen++;
|
||||
aOutBuf[byLen] = 0x00;
|
||||
}
|
||||
bitLen++;
|
||||
ibitLen++;
|
||||
prebit = curbit;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>EOF: EOFΪ<46><EFBFBD>0.
|
||||
// EOF
|
||||
{
|
||||
if( bPCD )
|
||||
{
|
||||
curbit = 0;
|
||||
code = RFID_Code_Miller( prebit, curbit ) & 0x0F;
|
||||
}
|
||||
else
|
||||
{
|
||||
code = ISO14443A_PICC_EOF;
|
||||
}
|
||||
|
||||
if( bitLen % 2 == 0 )
|
||||
{
|
||||
aOutBuf[byLen] |= code << 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
aOutBuf[byLen] |= code;
|
||||
}
|
||||
bitLen++;
|
||||
}
|
||||
*pu16OutBitLen = bitLen * ISO14443A_BIT_CODEC_LEN;
|
||||
|
||||
return *pu16OutBitLen;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>PICC<43>˵<EFBFBD><CBB5><EFBFBD>.
|
||||
// ȥ<><C8A5>SOF/EOF<4F><46>.
|
||||
// <20>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>س<EFBFBD><D8B3>ȣ<EFBFBD>-1ʧ<31>ܡ<EFBFBD>
|
||||
int ISO14443A_Decode(
|
||||
BOOL bPCD, // PCD<43><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
BYTE aInBuf[], UINT16 u16InBitLen,
|
||||
BYTE aOutBuf[], UINT16 *pu16OutBitLen )
|
||||
{
|
||||
int i, k;
|
||||
int bitLen, ibitLen;
|
||||
BYTE coded;
|
||||
int byoffset, btoffset;
|
||||
|
||||
if( u16InBitLen % 4 != 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
||||
i = 0;
|
||||
|
||||
// SOF;
|
||||
ibitLen = 0;
|
||||
// SOF
|
||||
if( u16InBitLen > 4 )
|
||||
{
|
||||
BYTE bySOF;
|
||||
bySOF = bPCD ? ISO14443A_PICC_SOF : ISO14443A_PCD_SOF;
|
||||
|
||||
coded = ( aInBuf[i] >> 4 ) & 0x0F;
|
||||
if( coded != bySOF )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
ibitLen++;
|
||||
u16InBitLen -= ISO14443A_BIT_CODEC_LEN;
|
||||
}
|
||||
|
||||
bitLen = 0;
|
||||
// <20><><EFBFBD><EFBFBD>-2;
|
||||
while( u16InBitLen > ISO14443A_BIT_CODEC_LEN)
|
||||
{
|
||||
if( ibitLen % 2 == 1 )
|
||||
{
|
||||
coded = aInBuf[i] & 0x0F;
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
coded = ( aInBuf[i] >> 4 ) & 0x0F;
|
||||
}
|
||||
|
||||
// PCD<43>࣬<EFBFBD><E0A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Manchester.
|
||||
if( !bPCD )
|
||||
{
|
||||
k = RFID_Decode_Miller( coded );
|
||||
}
|
||||
else
|
||||
{
|
||||
k = RFID_Decode_Manchester( coded );
|
||||
}
|
||||
|
||||
if( k == -1 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
byoffset = bitLen / 8;
|
||||
btoffset = bitLen % 8;
|
||||
|
||||
if( btoffset == 0 )
|
||||
{
|
||||
aOutBuf[byoffset] = 0x00;
|
||||
}
|
||||
aOutBuf[byoffset] |= k << ( 7 - btoffset);
|
||||
|
||||
bitLen++;
|
||||
ibitLen++;
|
||||
u16InBitLen -= ISO14443A_BIT_CODEC_LEN;
|
||||
}
|
||||
|
||||
// EOF
|
||||
if( u16InBitLen >= 4 )
|
||||
{
|
||||
BOOL bEOFResult;
|
||||
if( ibitLen % 2 == 1)
|
||||
{
|
||||
coded = aInBuf[i] & 0x0F;
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
coded = ( aInBuf[i] >> 4 ) & 0x0F;
|
||||
}
|
||||
|
||||
if( bPCD )
|
||||
{
|
||||
// PCD<43><44><EFBFBD>뷽<EFBFBD><EBB7BD>
|
||||
bEOFResult = ( coded == ISO14443A_PICC_EOF)?TRUE:FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
bEOFResult = ( (coded == ISO14443A_PCD_0P0) || ( coded == ISO14443A_PCD_0P1) ) ? TRUE:FALSE;
|
||||
}
|
||||
if( !bEOFResult )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
u16InBitLen -= ISO14443A_BIT_CODEC_LEN;
|
||||
}
|
||||
*pu16OutBitLen = bitLen;
|
||||
return bitLen;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------*\
|
||||
* Miller
|
||||
* ISO14443A PCD->PICC <20><>
|
||||
*-------------------------------------------------------------*/
|
||||
/**
|
||||
* <09>Ľ<EFBFBD><C4BD><EFBFBD>Miller<65><72><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>4<EFBFBD><34><EFBFBD>ر<EFBFBD><D8B1><EFBFBD>
|
||||
*
|
||||
* \input <09><><EFBFBD>룺BYTE prebit: 0/1<><31><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>ص<EFBFBD>ǰһ<C7B0><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* <09><><EFBFBD>룺BYTE bitDat: 0/1<><31><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* \ouput
|
||||
* \return bitDat=1, <20><><EFBFBD><EFBFBD>1101
|
||||
* prebit=1,bitDat=0<><30><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD>1111
|
||||
* prebit=0,bitDat=0<><30><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD>0111
|
||||
*/
|
||||
|
||||
int RFID_Code_Miller( BYTE prebit, BYTE bitDat )
|
||||
{
|
||||
bitDat &= 0x01;
|
||||
prebit &= 0x01;
|
||||
if( bitDat == 0 )
|
||||
{
|
||||
if( prebit == 0 )
|
||||
{
|
||||
return RFID_CODE_MILLER_0_p0; // 0111
|
||||
}
|
||||
else
|
||||
{
|
||||
return RFID_CODE_MILLER_0_p1; // 1111
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return RFID_CODE_MILLER_1; // 1101
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <09>Ľ<EFBFBD><C4BD><EFBFBD>Miller<65><72><EFBFBD>룺<EFBFBD><EBA3BA><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD>1.<2E><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
||||
*
|
||||
* \input <09><><EFBFBD>룺BYTE codedDat: 1101 for 1, 1111/0111 for 0
|
||||
* \ouput
|
||||
* \return 0/1
|
||||
* -1 ,<2C>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
int RFID_Decode_Miller( BYTE codedDat )
|
||||
{
|
||||
codedDat &= 0x0F;
|
||||
if( codedDat == RFID_CODE_MILLER_1 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if( codedDat == RFID_CODE_MILLER_0_p1 || codedDat == RFID_CODE_MILLER_0_p0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------*\
|
||||
* Manchester
|
||||
* ISO14443A PICC->PCD & ISO15693 VICC->VCD
|
||||
*-------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Manchester<65><72><EFBFBD>룬<EFBFBD><EBA3AC><EFBFBD><EFBFBD>4<EFBFBD><34><EFBFBD>ر<EFBFBD><D8B1><EFBFBD>
|
||||
*
|
||||
* \input <09><><EFBFBD>룺BYTE bitDat: 0/1<><31><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* \ouput
|
||||
* \return bitDat=1, <20><><EFBFBD>أ<EFBFBD>1100
|
||||
* bitDat=0<><30><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD>0011
|
||||
*/
|
||||
int RFID_Code_Manchester( BYTE bitDat )
|
||||
{
|
||||
return bitDat ? RFID_CODE_MANCHESTER_1:RFID_CODE_MANCHESTER_0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manchester<65><72><EFBFBD>룺<EFBFBD><EBA3BA><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD>1.<2E><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
||||
*
|
||||
* \input <09><><EFBFBD>룺BYTE codedDat: 1100 for 1, 0011 for 0
|
||||
* \ouput
|
||||
* \return 0/1
|
||||
* -1 ,<2C>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
int RFID_Decode_Manchester( BYTE codedDat )
|
||||
{
|
||||
if( codedDat == RFID_CODE_MANCHESTER_1 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if( codedDat == RFID_CODE_MANCHESTER_0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
137
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_codec.h
Normal file
137
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_codec.h
Normal file
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* rfid_iso14443A_codec.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _RFID_ISO14443A_CODEC_H_
|
||||
#define _RFID_ISO14443A_CODEC_H_
|
||||
|
||||
#include "rfid_def.h"
|
||||
|
||||
#define ISO14443A_PCD_X 0xD // 1101, '1'
|
||||
#define ISO14443A_PCD_Y 0xF // 1111, '0' EOF
|
||||
#define ISO14443A_PCD_Z 0x7 // 0111, '0', SOF
|
||||
|
||||
#define ISO14443A_PCD_SOF ISO14443A_PCD_Z
|
||||
// EOFΪ0, #define ISO14443A_PCD_EOF
|
||||
#define ISO14443A_PCD_1 ISO14443A_PCD_X
|
||||
#define ISO14443A_PCD_0P1 ISO14443A_PCD_Y // <20><><EFBFBD><EFBFBD>0<EFBFBD><30>ǰһ<C7B0><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ1
|
||||
#define ISO14443A_PCD_0P0 ISO14443A_PCD_Z // <20><><EFBFBD><EFBFBD>0<EFBFBD><30>ǰһ<C7B0><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ0
|
||||
#define ISO14443A_BIT_CODEC_LEN 4 // ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><D8B1>볤<EFBFBD><EBB3A4>Ϊ4
|
||||
|
||||
#define ISO14443A_PICC_D 0xC // 1100<30><30>'1', SOF
|
||||
#define ISO14443A_PICC_E 0x3 // 0011, '0'
|
||||
#define ISO14443A_PICC_F 0x0 // 0000, EOF
|
||||
|
||||
#define ISO14443A_PICC_SOF ISO14443A_PICC_D
|
||||
#define ISO14443A_PICC_EOF ISO14443A_PICC_F
|
||||
#define ISO14443A_PICC_1 ISO14443A_PICC_D
|
||||
#define ISO14443A_PICC_0 ISO14443A_PICC_E
|
||||
|
||||
// ISO/IEC 14443A, PCD->PICCʹ<43><CAB9>
|
||||
#define RFID_CODE_MILLER_1 13 // 1101
|
||||
#define RFID_CODE_MILLER_0_p1 15 // 1111
|
||||
#define RFID_CODE_MILLER_0_p0 7 // 0111
|
||||
|
||||
// ISO/IEC 14443A, PICC->PCDʹ<44><CAB9>
|
||||
#define RFID_CODE_MANCHESTER_1 12 // 1100
|
||||
#define RFID_CODE_MANCHESTER_0 3 // 0011
|
||||
|
||||
|
||||
/**
|
||||
* \function
|
||||
*
|
||||
* \input BYTE aInBuf[], <09><><EFBFBD>뻺<EFBFBD><EBBBBA><EFBFBD><EFBFBD>
|
||||
* UINT16 u16InBitLen <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>س<EFBFBD><D8B3><EFBFBD>
|
||||
* \ouput BYTE aoutBuf <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* BYTE *pu16OutBitLen <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
||||
*
|
||||
* \return -1<><31>ʧ<EFBFBD>ܣ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>س<EFBFBD><D8B3><EFBFBD>
|
||||
*/
|
||||
|
||||
int ISO14443A_PCD_Code(
|
||||
BYTE aInBuf[], UINT16 u16InBitLen,
|
||||
BYTE aOutBuf[], UINT16 *pu16OutBitLen
|
||||
);
|
||||
|
||||
int ISO14443A_PCD_Decode(
|
||||
BYTE aInBuf[], UINT16 u16InBitLen,
|
||||
BYTE aOutBuf[], UINT16 *pu16OutBitLen
|
||||
);
|
||||
|
||||
int ISO14443A_PICC_Code(
|
||||
BYTE aInBuf[], UINT16 u16InBitLen,
|
||||
BYTE aoutBuf[], UINT16 *pu16OutBitLen
|
||||
);
|
||||
|
||||
int ISO14443A_PICC_Decode(
|
||||
BYTE aInBuf[], UINT16 u16InBitLen,
|
||||
BYTE aOutBuf[], UINT16 *pu16OutBitLen
|
||||
);
|
||||
|
||||
/**
|
||||
* 1. bPCD:<3A><> <09><>PCD/PICC<43><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뷽ʽ/SOF<4F><46>EOF<4F><46><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC>
|
||||
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˸<EFBFBD><CBB8><EFBFBD><EFBFBD><EFBFBD>;
|
||||
*/
|
||||
int ISO14443A_Code(
|
||||
BOOL bPCD, // PCD<43><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
BYTE aInBuf[], UINT16 u16InBitLen,
|
||||
BYTE aoutBuf[], UINT16 *pu16OutBitLen
|
||||
);
|
||||
|
||||
int ISO14443A_Decode(
|
||||
BOOL bPCD, // PCD<43><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
BYTE aInBuf[], UINT16 u16InBitLen,
|
||||
BYTE aOutBuf[], UINT16 *pu16OutBitLen
|
||||
);
|
||||
|
||||
/*-------------------------------------------------------------*\
|
||||
* Miller
|
||||
* ISO14443A PCD->PICC <20><>
|
||||
*-------------------------------------------------------------*/
|
||||
/**
|
||||
* <09>Ľ<EFBFBD><C4BD><EFBFBD>Miller<65><72><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>4<EFBFBD><34><EFBFBD>ر<EFBFBD><D8B1><EFBFBD>
|
||||
*
|
||||
* \input <09><><EFBFBD>룺BYTE prebit: 0/1<><31><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>ص<EFBFBD>ǰһ<C7B0><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* <09><><EFBFBD>룺BYTE bitDat: 0/1<><31><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* \ouput
|
||||
* \return bitDat=1, <20><><EFBFBD><EFBFBD>1101
|
||||
* prebit=1,bitDat=0<><30><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD>1111
|
||||
* prebit=0,bitDat=0<><30><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD>0111
|
||||
*/
|
||||
int RFID_Code_Miller( BYTE prebit, BYTE bitDat );
|
||||
/**
|
||||
* <09>Ľ<EFBFBD><C4BD><EFBFBD>Miller<65><72><EFBFBD>룺<EFBFBD><EBA3BA><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD>1.<2E><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
||||
*
|
||||
* \input <09><><EFBFBD>룺BYTE codedDat: 1101 for 1, 1111/0111 for 0
|
||||
* \ouput
|
||||
* \return 0/1
|
||||
* -1 ,<2C>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
int RFID_Decode_Miller( BYTE codedDat );
|
||||
|
||||
/*-------------------------------------------------------------*\
|
||||
* Manchester
|
||||
* ISO14443A PICC->PCD
|
||||
*-------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Manchester<65><72><EFBFBD>룬<EFBFBD><EBA3AC><EFBFBD><EFBFBD>4<EFBFBD><34><EFBFBD>ر<EFBFBD><D8B1><EFBFBD>
|
||||
*
|
||||
* \input <09><><EFBFBD>룺BYTE bitDat: 0/1<><31><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* \ouput
|
||||
* \return bitDat=1, <20><><EFBFBD>أ<EFBFBD>1100
|
||||
* bitDat=0<><30><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD>0011
|
||||
*/
|
||||
int RFID_Code_Manchester( BYTE bitDat ); // bitDat=1 or 0
|
||||
/**
|
||||
* Manchester<65><72><EFBFBD>룺<EFBFBD><EBA3BA><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD>1.<2E><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
||||
*
|
||||
* \input <09><><EFBFBD>룺BYTE codedDat: 1100 for 1, 0011 for 0
|
||||
* \ouput
|
||||
* \return 0/1
|
||||
* -1 ,<2C>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
int RFID_Decode_Manchester( BYTE codedDat );
|
||||
|
||||
#endif
|
||||
307
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_frm.cpp
Normal file
307
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_frm.cpp
Normal file
@@ -0,0 +1,307 @@
|
||||
/**
|
||||
* \file rfid_frm.c
|
||||
*
|
||||
* \brief ʵ<><CAB5>rfid<69>е<EFBFBD><D0B5><EFBFBD>/<2F><>֡<EFBFBD><D6A1>
|
||||
*
|
||||
* CRC<52><43>֮ǰ<D6AE><C7B0><EFBFBD>㣬<EFBFBD><E3A3AC>Ϊ<EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>ײ֡<D7B2>У<EFBFBD>Ҫȫ<D2AA><C8AB><EFBFBD>ֽڲ<D6BD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㣬<EFBFBD><E3A3AC>ֻ<EFBFBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD>ֽڳ<D6BD>֡<EFBFBD><D6A1>
|
||||
*/
|
||||
|
||||
//#include "StdAfx.h"
|
||||
|
||||
#include "rfid_chk.h"
|
||||
#include "rfid_iso14443A_frm.h"
|
||||
#include "memory.h"
|
||||
|
||||
/**
|
||||
* <09><>
|
||||
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* <09><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD>ڵı<DAB5><C4B1><EFBFBD>˳<EFBFBD><CBB3>
|
||||
* У<><D0A3>P<EFBFBD><50>У<EFBFBD><D0A3>.
|
||||
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SOF/EOF
|
||||
*/
|
||||
|
||||
int ISO14443A_Framing(
|
||||
BYTE byBitLenofFirstByte, // <20><>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD>е<EFBFBD>bit Len<65><6E><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>ײ֡<D7B2><D6A1><EFBFBD><EFBFBD>Ҫ
|
||||
BYTE byFirstByte, // <20><>һ<EFBFBD>ֽڡ<D6BD><DAA1><EFBFBD>u16BitLenofFirstByte=0<><30><EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD>
|
||||
BYTE ainBuf[], UINT16 u16inBitLen, // <20><><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
||||
BYTE aoutBuf[], UINT16 *pu16OutBitLen
|
||||
)
|
||||
{
|
||||
int i, j, k, curbit;
|
||||
int byoffset, bitoffset;
|
||||
int bitLen = 0;
|
||||
|
||||
// <20><>0<EFBFBD><30><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>ײ֡
|
||||
byoffset = 0;
|
||||
aoutBuf[byoffset] = 0x00;
|
||||
bitoffset = 0;
|
||||
if( byBitLenofFirstByte )
|
||||
{
|
||||
for( i = 0; i < byBitLenofFirstByte; i++ )
|
||||
{
|
||||
curbit = ( byFirstByte >> i ) & 0x01;
|
||||
|
||||
byoffset = bitLen / 8;
|
||||
bitoffset = bitLen % 8;
|
||||
aoutBuf[byoffset] |= curbit << ( 7-bitoffset);
|
||||
bitLen++;
|
||||
}
|
||||
// OldParity.
|
||||
byoffset = bitLen / 8;
|
||||
bitoffset = bitLen % 8;
|
||||
aoutBuf[byoffset] |= 0 << ( 7-bitoffset);
|
||||
bitLen++;
|
||||
}
|
||||
|
||||
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
i = 0;
|
||||
while( u16inBitLen )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD> bitLen<65><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>.
|
||||
if( u16inBitLen > 8 )
|
||||
{
|
||||
k = 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
k = u16inBitLen;
|
||||
}
|
||||
|
||||
for( j = 0; j < k; j++ )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD> bitLen<65><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>.
|
||||
curbit = ( ainBuf[i] >> j ) & 0x01;
|
||||
|
||||
// <20><><EFBFBD>㵱ǰ<E3B5B1>ֽ<EFBFBD>/<2F><><EFBFBD><EFBFBD>.
|
||||
byoffset = bitLen / 8;
|
||||
bitoffset = bitLen % 8;
|
||||
if( bitoffset == 0 )
|
||||
{
|
||||
aoutBuf[byoffset] = 0x00;
|
||||
}
|
||||
aoutBuf[byoffset] |= curbit << ( 7-bitoffset);
|
||||
bitLen++;
|
||||
}
|
||||
|
||||
if( k == 8 )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽں<DABA><F3A3ACB2>м<EFBFBD>У<EFBFBD><D0A3>
|
||||
curbit = OldParity( ainBuf[i] );
|
||||
byoffset = bitLen / 8;
|
||||
bitoffset = bitLen % 8;
|
||||
if( bitoffset == 0 )
|
||||
{
|
||||
aoutBuf[byoffset] = 0x00;
|
||||
}
|
||||
aoutBuf[byoffset] |= curbit << ( 7-bitoffset);
|
||||
bitLen++;
|
||||
}
|
||||
i++;
|
||||
u16inBitLen -= k;
|
||||
}
|
||||
*pu16OutBitLen = bitLen;
|
||||
|
||||
return bitLen;
|
||||
}
|
||||
|
||||
// <20>ӿ<EFBFBD>֡
|
||||
// Ҫ<><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD>CRC<52><43>CRC<52>ڵ<EFBFBD><DAB5>øó<C3B8><C3B3><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>Ѿ<EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD><EFBFBD>.
|
||||
// <20><><EFBFBD>أ<EFBFBD>-1<><31>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
||||
int ISO14443A_unFraming(
|
||||
BYTE byBitLenofFirstByte, // <20><>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD>е<EFBFBD>bit Len<65><6E><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>ײ֡<D7B2><D6A1><EFBFBD><EFBFBD>Ҫ
|
||||
BYTE *byFirstByte, // <20><>һ<EFBFBD>ֽڡ<D6BD><DAA1><EFBFBD>u16BitLenofFirstByte=0<><30><EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD>
|
||||
BYTE ainBuf[], UINT16 u16inBitLen, // <20><><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
||||
BYTE aoutBuf[], UINT16 *pu16OutBitLen // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD><EFBFBD>*byBitLenofFirstByte
|
||||
)
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD>
|
||||
int i;
|
||||
int obitLen, obyoffset, obtoffset; // in
|
||||
int ibitLen, ibyoffset, ibtoffset; // out
|
||||
int curbit;
|
||||
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>û<EFBFBD>֪<EFBFBD><D6AA><EFBFBD>Լ<EFBFBD><D4BC>Ƿ<EFBFBD><C7B7>е<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD>
|
||||
// <20>ڷ<EFBFBD><DAB7><EFBFBD>ײʱ<D7B2><CAB1>PCD<43><44><EFBFBD>ݷ<EFBFBD><DDB7>ͣ<EFBFBD>֪<EFBFBD><D6AA><EFBFBD>Լ<EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>
|
||||
|
||||
ibitLen = 0;
|
||||
obitLen = 0;
|
||||
|
||||
// <20><>ʵ<EFBFBD><CAB5>u16inBitLen % 9 == byBitLenofFirstByte
|
||||
if( byBitLenofFirstByte )
|
||||
{
|
||||
*byFirstByte = 0;
|
||||
for( i = 0; i < byBitLenofFirstByte; i++ )
|
||||
{
|
||||
curbit = ( ainBuf[0] >> (7-i)) & 0x01;
|
||||
*byFirstByte |= curbit << i;
|
||||
ibitLen++;
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD>У<EFBFBD><D0A3>λ.
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD>У<EFBFBD><D0A3>λ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ȷ
|
||||
curbit = ainBuf[0] >> (7-byBitLenofFirstByte);
|
||||
ibitLen++;
|
||||
}
|
||||
|
||||
// <20><>ʼ<EFBFBD><CABC><EFBFBD>б<EFBFBD><D0B1><EFBFBD>
|
||||
obitLen = 0;
|
||||
obyoffset = 0;
|
||||
obtoffset = 0;
|
||||
|
||||
i = 0;
|
||||
while( ibitLen < u16inBitLen )
|
||||
{
|
||||
// ȡ<><C8A1>һbit
|
||||
ibyoffset = ibitLen / 8;
|
||||
ibtoffset = ibitLen % 8;
|
||||
curbit = ( ainBuf[ibyoffset] >> (7-ibtoffset)) & 0x01;
|
||||
|
||||
if( (i % 9) == 8 )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>飬<EFBFBD><E9A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>bit<69>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3>λ<EFBFBD><CEBB>
|
||||
// <20><><EFBFBD><EFBFBD>
|
||||
if( curbit != OldParity( aoutBuf[obyoffset]))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD>.
|
||||
obyoffset = obitLen / 8;
|
||||
obtoffset = obitLen % 8; //
|
||||
if( obtoffset == 0 )
|
||||
{
|
||||
aoutBuf[obyoffset] = 0x00;
|
||||
}
|
||||
aoutBuf[obyoffset] |= curbit << obtoffset;
|
||||
obitLen++;
|
||||
}
|
||||
i++;
|
||||
ibitLen++;
|
||||
}
|
||||
|
||||
*pu16OutBitLen = obitLen;
|
||||
|
||||
return obitLen;
|
||||
}
|
||||
|
||||
// ǰ<><C7B0><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD>0111,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD>1111
|
||||
|
||||
/**
|
||||
* ISO14443A_PCD_stFrame()
|
||||
* PCD->PICC<43><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*
|
||||
* <09><><EFBFBD>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>س<EFBFBD><D8B3>ȡ<EFBFBD>
|
||||
*/
|
||||
int ISO14443A_stdFraming( BYTE aInBuf[], UINT16 u16InBitLen, BYTE aoutBuf[], UINT16 *pu16OutBitLen )
|
||||
{
|
||||
// <20><>֡һ<D6A1><D2BB><EFBFBD><EFBFBD>CRCУ<43>飡
|
||||
BYTE abyBuf[100];
|
||||
int k;
|
||||
|
||||
k = u16InBitLen/8;
|
||||
|
||||
memcpy( abyBuf, aInBuf, k );
|
||||
// <20><><EFBFBD><EFBFBD>CRCУ<43><D0A3>
|
||||
ISO14443A_CRC( aInBuf, k, &abyBuf[k+1], &abyBuf[k]);
|
||||
|
||||
k += 2;
|
||||
|
||||
return ISO14443A_Framing( 0, 0, // <20><>֡<D7BC><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽڿ<D6BD>ʼ
|
||||
abyBuf, k*8,
|
||||
aoutBuf, pu16OutBitLen
|
||||
);
|
||||
}
|
||||
|
||||
// <20><>֡<EFBFBD>̶<EFBFBD><CCB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>γ<EFBFBD><CEB3>ȣ<EFBFBD>7<EFBFBD><37>û<EFBFBD><C3BB><EFBFBD><EFBFBD>żУ<C5BC><D0A3><EFBFBD><EFBFBD>CRCУ<43><D0A3>
|
||||
int ISO14443A_ShortFraming( BYTE byCmd, BYTE aoutBuf[], UINT16 *pu16OutBitLen )
|
||||
{
|
||||
int i;
|
||||
int curbit;
|
||||
byCmd = byCmd & 0x7F;
|
||||
|
||||
aoutBuf[0] = 0x00;
|
||||
for( i = 0; i < 7; i++ )
|
||||
{
|
||||
curbit = ( byCmd >> i ) & 0x01;
|
||||
aoutBuf[0] |= curbit << (7-i);
|
||||
}
|
||||
*pu16OutBitLen = 7;
|
||||
|
||||
return 7;
|
||||
}
|
||||
|
||||
int ISO14443A_AnticollisionFraming(
|
||||
BYTE byBitLenofFirstByte, // <20><>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD>е<EFBFBD>bit Len<65><6E><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>ײ֡<D7B2><D6A1><EFBFBD><EFBFBD>Ҫ
|
||||
BYTE byFirstByte,
|
||||
BYTE ainBuf[], UINT16 u16InBitLen,
|
||||
BYTE aoutBuf[], UINT16 *pu16OutBitLen
|
||||
)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD>ײ֡û<D6A1><C3BB>CRC.
|
||||
return ISO14443A_Framing(
|
||||
byBitLenofFirstByte, byFirstByte, // <20><>֡<D7BC><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽڿ<D6BD>ʼ
|
||||
ainBuf, u16InBitLen,
|
||||
aoutBuf, pu16OutBitLen
|
||||
);
|
||||
}
|
||||
|
||||
// <20><>֡
|
||||
// <20><><EFBFBD>룺<EFBFBD><EBA3BA><EFBFBD>س<EFBFBD><D8B3>ȣ<EFBFBD><C8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽڳ<D6BD><DAB3>ȣ<EFBFBD>
|
||||
int ISO14443A_Un_stdFraming(BYTE ainBuf[], UINT16 u16inBitLen, BYTE aoutBuf[], UINT16 *pu16OutBufLen )
|
||||
{
|
||||
BYTE abyCRC[2];
|
||||
BYTE abyBuf[1000];
|
||||
int k;
|
||||
|
||||
if( ISO14443A_unFraming( 0,0,ainBuf, u16inBitLen, abyBuf, pu16OutBufLen ) < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
k = (*pu16OutBufLen)/8;
|
||||
k -= 2;
|
||||
*pu16OutBufLen -= 16;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>CRC.
|
||||
ISO14443A_CRC( abyBuf, k, &abyCRC[1], &abyCRC[0] );
|
||||
if( abyBuf[k] != abyCRC[0] || abyBuf[k+1] != abyCRC[1] )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
memcpy( aoutBuf, abyBuf, k );
|
||||
|
||||
return k; // <20><><EFBFBD><EFBFBD><EFBFBD>ֽڳ<D6BD><DAB3><EFBFBD>
|
||||
}
|
||||
|
||||
// ֻ<><D6BB>7<EFBFBD><37><EFBFBD><EFBFBD>.
|
||||
int ISO14443A_Un_ShortFraming( BYTE aInBuf[], UINT16 u16InBitLen, BYTE *pbyCmd )
|
||||
{
|
||||
int i;
|
||||
int curbit;
|
||||
|
||||
*pbyCmd = 0x00;
|
||||
for( i = 0; i < 7; i++ )
|
||||
{
|
||||
curbit = ( aInBuf[0] >> i ) & 0x01;
|
||||
*pbyCmd |= curbit << (7-i);
|
||||
}
|
||||
|
||||
return 7;
|
||||
}
|
||||
|
||||
int ISO14443A_Un_AnticollisionFraming(
|
||||
BYTE byBitLenofFirstByte, // <20><>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD>е<EFBFBD>bit Len<65><6E><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>ײ֡<D7B2><D6A1><EFBFBD><EFBFBD>Ҫ
|
||||
BYTE *pbyFirstByte,
|
||||
BYTE aInBuf[], UINT16 u16inBitLen,
|
||||
BYTE aoutBuf[], UINT16 *pu16OutBitLen
|
||||
)
|
||||
{
|
||||
return ISO14443A_unFraming( byBitLenofFirstByte, pbyFirstByte,
|
||||
aInBuf, u16inBitLen, aoutBuf, pu16OutBitLen );
|
||||
}
|
||||
|
||||
|
||||
|
||||
61
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_frm.h
Normal file
61
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_frm.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* rfid_iso14443A_frm.h
|
||||
*
|
||||
*
|
||||
* <09><><EFBFBD>ڱ<EFBFBD>֡<D7BC><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ֡<D7B2><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>飻
|
||||
* <09><><EFBFBD>ڱ<EFBFBD>֡<D7BC><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CRC;
|
||||
* <09><><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>ײ֡<D7B2><D6A1><EFBFBD><EFBFBD>PICC->PCD<43><44><EFBFBD><EFBFBD><F2A3ACBF><EFBFBD><EFBFBD>ֽڲ<D6BD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD>
|
||||
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽڣ<D6BD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͱ<EFBFBD><CDB1>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߱<EFBFBD><DFB1>أ<EFBFBD>
|
||||
*/
|
||||
|
||||
#ifndef _RFID_ISO14443A_FRM_H_
|
||||
#define _RFID_ISO14443A_FRM_H_
|
||||
|
||||
#include "rfid_def.h"
|
||||
#include "rfid_chk.h"
|
||||
|
||||
|
||||
int ISO14443A_stdFraming( BYTE aInBuf[], UINT16 u16InBitLen, BYTE aoutBuf[], UINT16 *pu16OutBitLen );
|
||||
int ISO14443A_ShortFraming( BYTE byCmd, BYTE aoutBuf[], UINT16 *pu16OutBitLen );
|
||||
int ISO14443A_AnticollisionFraming(
|
||||
BYTE byBitLenofFirstByte, // <20><>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD>е<EFBFBD>bit Len<65><6E><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>ײ֡<D7B2><D6A1><EFBFBD><EFBFBD>Ҫ
|
||||
BYTE byFirstByte,
|
||||
BYTE ainBuf[], UINT16 u16inBitLen,
|
||||
BYTE aoutBuf[], UINT16 *pu16OutBitLen
|
||||
);
|
||||
|
||||
int ISO14443A_Un_stdFraming(BYTE ainBuf[], UINT16 u16inBitLen, BYTE aoutBuf[], UINT16 *pu16OutbyLen );
|
||||
int ISO14443A_Un_ShortFraming( BYTE ainBuf[], UINT16 u16InBitLen, BYTE *pbyCmd );
|
||||
int ISO14443A_Un_AnticollisionFraming(
|
||||
BYTE byBitLenofFirstByte, // <20><>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD>е<EFBFBD>bit Len<65><6E><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>ײ֡<D7B2><D6A1><EFBFBD><EFBFBD>Ҫ
|
||||
BYTE *pbyFirstByte,
|
||||
BYTE ainBuf[], UINT16 u16inBitLen,
|
||||
BYTE aoutBuf[], UINT16 *pu16OutBitLen
|
||||
);
|
||||
|
||||
/**
|
||||
* ISO14443A Frame
|
||||
* <09><>
|
||||
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* <09><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD>ڵı<DAB5><C4B1><EFBFBD>˳<EFBFBD><CBB3>
|
||||
* У<><D0A3>P<EFBFBD><50>У<EFBFBD><D0A3>.
|
||||
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SOF/EOF
|
||||
*/
|
||||
|
||||
int ISO14443A_Framing(
|
||||
BYTE byBitLenofFirstByte, // <20><>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD>е<EFBFBD>bit Len<65><6E><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>ײ֡<D7B2><D6A1><EFBFBD><EFBFBD>Ҫ
|
||||
BYTE byFirstByte, // <20><>һ<EFBFBD>ֽڡ<D6BD><DAA1><EFBFBD>u16BitLenofFirstByte=0<><30><EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD>
|
||||
BYTE ainBuf[], UINT16 u16inBitLen, // <20><><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
||||
BYTE aoutBuf[], UINT16 *pu16OutBitLen
|
||||
);
|
||||
|
||||
int ISO14443A_unFraming(
|
||||
BYTE byBitLenofFirstByte, // <20><>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD>е<EFBFBD>bit Len<65><6E><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>ײ֡<D7B2><D6A1><EFBFBD><EFBFBD>Ҫ
|
||||
BYTE *byFirstByte, // <20><>һ<EFBFBD>ֽڡ<D6BD><DAA1><EFBFBD>u16BitLenofFirstByte=0<><30><EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD>
|
||||
BYTE ainBuf[], UINT16 u16inBitLen, // <20><><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
||||
BYTE aoutBuf[], UINT16 *pu16OutBitLen // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD><EFBFBD>*byBitLenofFirstByte
|
||||
);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
779
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_pcd.cpp
Normal file
779
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_pcd.cpp
Normal file
@@ -0,0 +1,779 @@
|
||||
/**
|
||||
* \file rfid_iso14443A_pcd.cpp
|
||||
*
|
||||
*
|
||||
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
|
||||
//#include "stdafx.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "rfid_def.h"
|
||||
#include "memory.h"
|
||||
#include "rfid_iso14443A_cmdtx.h"
|
||||
#include "rfid_iso14443A_cmdrx.h"
|
||||
|
||||
#include "rfid_iso14443A_pcd.h"
|
||||
#include "pcd_thread.h"
|
||||
|
||||
void PCD_ISO14443A_SetSELECT( ISO_14443A_PCD *pstPCD, BYTE cmd );
|
||||
FILE *g_fpDebug = NULL;
|
||||
int g_firstBitValue = 0;
|
||||
|
||||
#if 0
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
return pcd_main( 10 );
|
||||
}
|
||||
#endif
|
||||
|
||||
int pcd_main( int numofpicc )
|
||||
{
|
||||
ISO_14443A_PCD stPCD;
|
||||
int i, k;
|
||||
|
||||
g_fpDebug = fopen("d:\\rfid\\pcddebug.txt", "w");
|
||||
|
||||
k = 0;
|
||||
while( k < numofpicc )
|
||||
{
|
||||
PCD_ISO14443A_run( &stPCD );
|
||||
if( stPCD.ucStatus == ISO_14443A_PCD_STATE_OK )
|
||||
{
|
||||
FILE *fp = fopen("d:\\rfid\\picc.txt", "a+");
|
||||
if( !fp )
|
||||
{
|
||||
fp = fopen( "d:\\rfid\\picc.txt", "w" );
|
||||
}
|
||||
if( k == 0 )
|
||||
{
|
||||
fprintf(fp, "\n--------------new test. " );
|
||||
}
|
||||
printf("\nUID[%d]: ", ++k );
|
||||
fprintf(fp, "\nUID[%d]: ", k );
|
||||
for( i = 0; i < stPCD.ucCmpBits/8; i++ )
|
||||
{
|
||||
if( stPCD.aucUID[i] != 0x88 )
|
||||
{
|
||||
printf("0x%02X.", stPCD.aucUID[i]);
|
||||
fprintf(fp, "0x%02X.", stPCD.aucUID[i]);
|
||||
}
|
||||
}
|
||||
fclose( fp );
|
||||
}
|
||||
}
|
||||
fclose( g_fpDebug );
|
||||
return 1;
|
||||
}
|
||||
|
||||
// һ<><D2BB>ֻʶ<D6BB><CAB6><EFBFBD><EFBFBD>һ<EFBFBD>ſ<EFBFBD>
|
||||
int PCD_ISO14443A_run( ISO_14443A_PCD *pstPCD )
|
||||
{
|
||||
UCHAR aucRxBuf[256];
|
||||
UINT16 u16BufLen = 256;
|
||||
int len, r, k;
|
||||
|
||||
pstPCD->ucStatus = ISO_14443A_PCD_STATE_START;
|
||||
pstPCD->ucCmpBits = 0;
|
||||
pstPCD->ucCLn = 3; // û<><C3BB><EFBFBD>յ<EFBFBD>CLn: 0,1,2.
|
||||
pstPCD->ucAntiBit = 2; // <20><><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3>ȷ<EFBFBD><C8B7><EFBFBD>0
|
||||
pstPCD->u16WaitTime = PCD_WAIT_TIME; // <20><><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD>ʱ<EFBFBD>䡣
|
||||
|
||||
if( !g_fpDebug )
|
||||
{
|
||||
g_fpDebug = fopen("d:\\rfid\\pcddebug.txt", "w");
|
||||
}
|
||||
|
||||
memset( pstPCD->aucUID, 0x00, 12 );
|
||||
len = 0;
|
||||
while( ( pstPCD->ucStatus != ISO_14443A_PCD_STATE_ER )
|
||||
&& ( pstPCD->ucStatus != ISO_14443A_PCD_STATE_OK ) )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
// len<65><6E><EFBFBD><EFBFBD>Ϊ0.
|
||||
r = PCD_ISO14443A_process( pstPCD, aucRxBuf, len );
|
||||
if( r < 0 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if( pstPCD->ucStatus == ISO_14443A_PCD_STATE_OK )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD>
|
||||
break;
|
||||
}
|
||||
|
||||
// <20>ȴ<EFBFBD>
|
||||
k = 1;
|
||||
while(k--)
|
||||
{
|
||||
len = RFID_Reader_Rx( u16BufLen, aucRxBuf );
|
||||
if( len > 0 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose( g_fpDebug );
|
||||
return r;
|
||||
}
|
||||
|
||||
// cmd: sel = 0, anti = 1;
|
||||
void PCD_ISO14443A_SetSELECT( ISO_14443A_PCD *pstPCD, BYTE cmd )
|
||||
{
|
||||
if( pstPCD->ucCmpBits < 32 )
|
||||
{
|
||||
pstPCD->ucSEL = ISO_14443_CMD_SEL_CL1;
|
||||
}
|
||||
else if( pstPCD->ucCmpBits == 32 )
|
||||
{
|
||||
pstPCD->ucSEL = ( cmd == 0 ) ? ISO_14443_CMD_SEL_CL1:ISO_14443_CMD_SEL_CL2;
|
||||
}
|
||||
else if( pstPCD->ucCmpBits < 64 )
|
||||
{
|
||||
pstPCD->ucSEL = ISO_14443_CMD_SEL_CL2;
|
||||
}
|
||||
else if( pstPCD->ucCmpBits == 64 )
|
||||
{
|
||||
pstPCD->ucSEL = ( cmd == 0 ) ? ISO_14443_CMD_SEL_CL2:ISO_14443_CMD_SEL_CL3;
|
||||
}
|
||||
else
|
||||
{
|
||||
pstPCD->ucSEL = ISO_14443_CMD_SEL_CL3;
|
||||
}
|
||||
}
|
||||
|
||||
// <20><>ͻģ<CDBB>⣺
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD>յ<EFBFBD><D5B5>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>
|
||||
int PCD_ISO14443A_CollisionEmu( ISO_14443A_PCD *pstPCD,
|
||||
BYTE byBitLenofFirstByte, BYTE firstByte,
|
||||
UCHAR aucCmdBuf[], UINT16 u16CmdBitLen )
|
||||
{
|
||||
BYTE bcc;
|
||||
int i, j, k, m, n;
|
||||
|
||||
BYTE abyRxUID[4]={0x00,0x00,0x00,0x00}; // 4<><34><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD>
|
||||
int rxUIDbitLen;
|
||||
|
||||
int ibyoffset, ibtoffset;
|
||||
int obyoffset, obtoffset;
|
||||
int curbit, bitlen;
|
||||
|
||||
// <20><>ͻģ<CDBB><C4A3>: <20><><EFBFBD><EFBFBD>PCDֻ<44>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>bits.
|
||||
// ʵ<><CAB5><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>UID<49><44><EFBFBD><EFBFBD>
|
||||
bitlen = byBitLenofFirstByte + u16CmdBitLen - 8; //
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD>0<EFBFBD><30>ʾȫ<CABE><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ.
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
if( bitlen > 1 )
|
||||
{
|
||||
rxUIDbitLen = rand() % bitlen;
|
||||
}
|
||||
else
|
||||
{
|
||||
rxUIDbitLen = 1;
|
||||
}
|
||||
// <20>ѽ<EFBFBD><D1BD>յ<EFBFBD><D5B5><EFBFBD>bitlen<65><6E><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD>rxUIDbitLen<65><6E><EFBFBD><EFBFBD>abyRxUID[]<5D><>
|
||||
//
|
||||
|
||||
// abyRxUID<49><44><EFBFBD>ֽ<EFBFBD>ƫ<EFBFBD>ƺ<EFBFBD>bit<69><74><EFBFBD><EFBFBD>
|
||||
obyoffset = 0;
|
||||
obtoffset = 0;
|
||||
// <20><><EFBFBD><EFBFBD>FirstByte.
|
||||
n = 0; // <20><>ʾ<EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>bit<69><74>.
|
||||
if( byBitLenofFirstByte > 0 )
|
||||
{
|
||||
// <20>в<EFBFBD><D0B2><EFBFBD>bit.
|
||||
if( byBitLenofFirstByte <= rxUIDbitLen )
|
||||
{
|
||||
// ȫ<><C8AB>FirstByte.
|
||||
n = byBitLenofFirstByte;
|
||||
}
|
||||
else
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD>FirstByte<74><65><EFBFBD><EFBFBD><EFBFBD>߲<EFBFBD><DFB2><EFBFBD>Ҫdrop.
|
||||
n = rxUIDbitLen;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>n<EFBFBD><6E><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD>firstByte<74><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>n<EFBFBD><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
i = n - 1;
|
||||
while( i >= 0 )
|
||||
{
|
||||
curbit = (firstByte >> i)&0x01;
|
||||
abyRxUID[obyoffset] |= curbit << ( 7 - obtoffset );
|
||||
i--;
|
||||
obtoffset++;
|
||||
}
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>.
|
||||
//
|
||||
if( rxUIDbitLen > byBitLenofFirstByte )
|
||||
{
|
||||
// <20><>aucCmdBuf<75><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>8-k<><6B><EFBFBD><EFBFBD><EFBFBD>ؾͺ<D8BE>.
|
||||
k = 8-((rxUIDbitLen - byBitLenofFirstByte)%8); //
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD>.
|
||||
m = (rxUIDbitLen - byBitLenofFirstByte)/8; // <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽڣ<D6BD>BCC.
|
||||
aucCmdBuf[m] = aucCmdBuf[m] << k;
|
||||
|
||||
j = n;
|
||||
i = 0;
|
||||
while( j < rxUIDbitLen )
|
||||
{
|
||||
ibyoffset = i / 8;
|
||||
ibtoffset = i % 8;
|
||||
curbit = ( aucCmdBuf[ibyoffset] >> ( 7-ibtoffset)) & 0x01;
|
||||
|
||||
obyoffset = j / 8;
|
||||
obtoffset = j % 8;
|
||||
abyRxUID[obyoffset] |= curbit << ( 7 - obtoffset );
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD>.
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>abyRxUID[]<5D>ڣ<EFBFBD><DAA3><EFBFBD>rxUIDbitLen<65><6E><EFBFBD><EFBFBD><EFBFBD>ء<EFBFBD>
|
||||
|
||||
// <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƴ<EFBFBD><C6B4><EFBFBD><EFBFBD>UID<49>ڡ<EFBFBD>
|
||||
bitlen = rxUIDbitLen; // bitlen<65><6E>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>.
|
||||
i = 0; // <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if( bitlen > 0 )
|
||||
{
|
||||
// <20>Ȳ<EFBFBD><C8B2>ϴε<CFB4>ȱ<EFBFBD><C8B1>
|
||||
if( pstPCD->ucCmpBits % 8)
|
||||
{
|
||||
// <20><>ȱ<EFBFBD><C8B1>:
|
||||
k = byBitLenofFirstByte; // <20><>Ҫk<D2AA><6B><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD><D8A3>ճ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD>
|
||||
if( k > rxUIDbitLen )
|
||||
{
|
||||
k = rxUIDbitLen; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ಹk<E0B2B9><6B>.
|
||||
}
|
||||
|
||||
// <20><>k<EFBFBD><6B><EFBFBD><EFBFBD>
|
||||
obyoffset = pstPCD->ucCmpBits/8;
|
||||
obtoffset = pstPCD->ucCmpBits%8;
|
||||
j = obtoffset + k - 1;
|
||||
ibyoffset = 0;
|
||||
ibtoffset = 0;
|
||||
|
||||
while( j >= obtoffset )
|
||||
{
|
||||
curbit = ( abyRxUID[ibyoffset] >> ( 7-ibtoffset)) & 0x01;
|
||||
|
||||
pstPCD->aucUID[obyoffset] |= curbit << j;
|
||||
ibtoffset++;
|
||||
j--;
|
||||
}
|
||||
bitlen -= k;
|
||||
i += k;
|
||||
pstPCD->ucCmpBits += k;
|
||||
}
|
||||
}
|
||||
|
||||
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>k<EFBFBD><6B><EFBFBD>ֽ<EFBFBD>
|
||||
if( bitlen > 0 )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>bit.
|
||||
n = ( bitlen / 8 )*8;
|
||||
|
||||
j = pstPCD->ucCmpBits;
|
||||
k = n; // <20><><EFBFBD><EFBFBD>k<EFBFBD><6B>.
|
||||
while( k-- )
|
||||
{
|
||||
ibyoffset = i / 8;
|
||||
ibtoffset = i % 8;
|
||||
curbit = ( abyRxUID[ibyoffset] >> ( 7-ibtoffset)) & 0x01;
|
||||
|
||||
obyoffset = j / 8;
|
||||
obtoffset = j % 8;
|
||||
pstPCD->aucUID[obyoffset] |= curbit << ( 7 - obtoffset );
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
bitlen -= n;
|
||||
pstPCD->ucCmpBits += n;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD>ʣ<EFBFBD><CAA3>bit<69><74><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD>ͱ<EFBFBD><CDB1><EFBFBD>λ<EFBFBD><CEBB>.
|
||||
if( bitlen > 0 )
|
||||
{
|
||||
// UIDһ<44><D2BB>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD>ֽڽ<D6BD><DABD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
obyoffset = pstPCD->ucCmpBits / 8;
|
||||
obtoffset = 0;
|
||||
|
||||
pstPCD->ucCmpBits += bitlen;
|
||||
i = rxUIDbitLen-1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ.
|
||||
while( bitlen-- )
|
||||
{
|
||||
ibyoffset = i / 8;
|
||||
ibtoffset = i % 8;
|
||||
curbit = ( abyRxUID[ibyoffset] >> ( 7-ibtoffset)) & 0x01;
|
||||
|
||||
pstPCD->aucUID[obyoffset] |= curbit << obtoffset;
|
||||
obtoffset++;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>32<33><32><EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD>鿴BCC<43>Ƿ<EFBFBD><C7B7><EFBFBD>ȷ
|
||||
if( (pstPCD->ucCmpBits != 0) && (pstPCD->ucCmpBits % 32 == 0) )
|
||||
{
|
||||
bcc = 0x00;
|
||||
k = pstPCD->ucCmpBits / 8 - 4;
|
||||
for( i = k; i < 4+k; i++ )
|
||||
{
|
||||
bcc = bcc ^ pstPCD->aucUID[i];
|
||||
}
|
||||
if( bcc != aucCmdBuf[u16CmdBitLen/8-1] )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int PCD_ISO14443A_SendSELECT( ISO_14443A_PCD *pstPCD )
|
||||
{
|
||||
int r;
|
||||
int i, byoffset, btoffset, k;
|
||||
|
||||
PCD_ISO14443A_SetSELECT( pstPCD, 0 );
|
||||
pstPCD->ucStatus = ISO_14443A_PCD_STATE_SELECT;
|
||||
pcd_updateStatus( pstPCD->ucStatus - ISO_14443A_PCD_STATE_BEGIN );
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>SELECT.
|
||||
r = (pstPCD->ucCmpBits - 32 )/8;
|
||||
r = ISO14443A_SELECT( pstPCD->ucSEL, &(pstPCD->aucUID[r]) );
|
||||
|
||||
|
||||
printf("\n\nTx SELECT, waiting SAK");
|
||||
fprintf(g_fpDebug, "\n\nTx SELECT, waiting SAK");
|
||||
|
||||
printf("\nUID[0x%02x]:", pstPCD->ucSEL);
|
||||
fprintf(g_fpDebug, "\nUID[0x%02x]:", pstPCD->ucSEL);
|
||||
k = (pstPCD->ucSEL-0x93)/2;
|
||||
for( i = k*32; i < pstPCD->ucCmpBits; i++ )
|
||||
{
|
||||
byoffset = i/8;
|
||||
btoffset = i%8;
|
||||
printf("%d", ( pstPCD->aucUID[byoffset] >> btoffset)&0x01);
|
||||
fprintf(g_fpDebug, "%d", (pstPCD->aucUID[byoffset] >> btoffset)&0x01);
|
||||
if( i%4 == 3 )
|
||||
{
|
||||
printf(".");
|
||||
fprintf(g_fpDebug,".");
|
||||
}
|
||||
}
|
||||
printf("\nwait[0x%02x]", pstPCD->ucSEL);
|
||||
fprintf(g_fpDebug, "\nwait[0x%02x]", pstPCD->ucSEL);
|
||||
return r;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>û<EFBFBD><C3BB><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>еı<D0B5><C4B1>أ<EFBFBD>
|
||||
// newbit = 0/1. <20><>һ<EFBFBD><D2BB>ȡ0.
|
||||
int PCD_ISO14443A_SendANTICOLLISION( ISO_14443A_PCD *pstPCD )
|
||||
{
|
||||
int r;
|
||||
int k;
|
||||
int i, byoffset, btoffset;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>1 bit. <20><>Ϊ<EFBFBD><CEAA>һ<EFBFBD><D2BB>ȡ0<C8A1><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ1ʱ<31><CAB1>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ȡ0û<30>з<EFBFBD><D0B7>ء<EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>ʱ<EFBFBD><CAB1>һ<EFBFBD><D2BB><EFBFBD>ǿ<EFBFBD><C7BF>Է<EFBFBD><D4B7>صģ<D8B5><C4A3><EFBFBD>û<EFBFBD>з<EFBFBD><D0B7>أ<EFBFBD><D8A3>ͽ<EFBFBD><CDBD><EFBFBD><EFBFBD>ˡ<EFBFBD>
|
||||
|
||||
if( pstPCD->ucAntiBit == g_firstBitValue )
|
||||
{
|
||||
pstPCD->ucCmpBits ++; // <20><>һ<EFBFBD>μ<EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
||||
}
|
||||
|
||||
// <20><>ucCmpBits<74><73><EFBFBD><EFBFBD>Ϊnewbit.
|
||||
byoffset = (pstPCD->ucCmpBits-1) / 8;
|
||||
btoffset = (pstPCD->ucCmpBits-1) % 8;
|
||||
|
||||
pstPCD->aucUID[byoffset] &= ~(1 << btoffset); // <20><><EFBFBD><EFBFBD>Ϊ0.
|
||||
pstPCD->aucUID[byoffset] |= pstPCD->ucAntiBit << btoffset;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>UID<49><44>.
|
||||
if( pstPCD->ucCmpBits == 32 || pstPCD->ucCmpBits == 64 || pstPCD->ucCmpBits == 96 )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>غ<D8BA><F3A3ACB3><EFBFBD>32bit<69><74><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>SELECT.
|
||||
r = PCD_ISO14443A_SendSELECT( pstPCD );
|
||||
}
|
||||
else
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>anticollision.
|
||||
PCD_ISO14443A_SetSELECT( pstPCD, 1 );
|
||||
k = ( pstPCD->ucCmpBits / 32 ) * 4;
|
||||
|
||||
r = ISO14443A_AnticollisionFrame_req( pstPCD->ucSEL, &(pstPCD->aucUID[k]), pstPCD->ucCmpBits % 32 );
|
||||
printf("\n\nTx anticollision(new bit=%d), waiting anticollision.", pstPCD->ucAntiBit);
|
||||
fprintf( g_fpDebug, "\n\nTx anticollision(new bit=%d), waiting anticollision.", pstPCD->ucAntiBit );
|
||||
|
||||
printf("\nUID[0x%02x]:", pstPCD->ucSEL);
|
||||
fprintf(g_fpDebug, "\nUID[0x%02x]: ", pstPCD->ucSEL);
|
||||
k = (pstPCD->ucSEL-0x93)/2;
|
||||
for( i = k * 32; i < pstPCD->ucCmpBits; i++ )
|
||||
{
|
||||
byoffset = i/8;
|
||||
btoffset = i%8;
|
||||
printf("%d", ( pstPCD->aucUID[byoffset] >> btoffset)&0x01);
|
||||
fprintf(g_fpDebug, "%d", (pstPCD->aucUID[byoffset] >> btoffset)&0x01);
|
||||
if( i % 4 == 3 )
|
||||
{
|
||||
printf(".");
|
||||
fprintf(g_fpDebug, ".");
|
||||
}
|
||||
}
|
||||
printf("\nwait[0x%02x]", pstPCD->ucSEL );
|
||||
fprintf(g_fpDebug, "\nwait[0x%02x]", pstPCD->ucSEL);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
// ״̬<D7B4><CCAC>
|
||||
int PCD_ISO14443A_process( ISO_14443A_PCD *pstPCD, UCHAR aucRxBuf[], UINT16 u16RxBufBitLen )
|
||||
{
|
||||
int r = 1;
|
||||
|
||||
switch( pstPCD->ucStatus )
|
||||
{
|
||||
case ISO_14443A_PCD_STATE_START:
|
||||
// <20><><EFBFBD><EFBFBD>REQA<51><41><EFBFBD>յ<EFBFBD>ATRQ<52><51><EFBFBD><EFBFBD>תΪ
|
||||
if( pstPCD->ucCLn == 3 )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD>REQA().
|
||||
pcd_updateStatus( pstPCD->ucStatus - ISO_14443A_PCD_STATE_BEGIN );
|
||||
ISO14443A_REQA();
|
||||
printf("\n\nTx REQA. waiting ATQA.");
|
||||
fprintf(g_fpDebug, "\n\nTx REQA. waiting ATQA.");
|
||||
pstPCD->u16WaitTime = PCD_WAIT_TIME;
|
||||
pstPCD->ucCLn = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD>
|
||||
BYTE CL;
|
||||
BYTE rxBuf[2];
|
||||
r = ISO14443A_wait_ATQA( aucRxBuf, u16RxBufBitLen, &CL, rxBuf );
|
||||
if( r > 0 )
|
||||
{
|
||||
pcd_postMessage( rxBuf, 16, ISO_14443_CMD_ATQA, "send ANTI" );
|
||||
|
||||
pstPCD->ucStatus = ISO_14443A_PCD_STATE_ANTI;
|
||||
pstPCD->ucCLn = CL; // 0.1.2
|
||||
pstPCD->ucSEL = ISO_14443_CMD_SEL_CL1;
|
||||
pstPCD->ucCmpBits= 0;
|
||||
pstPCD->ucAntiBit = 2; // <20>տ<EFBFBD>ʼ<EFBFBD><CABC>
|
||||
pstPCD->u16WaitTime = PCD_WAIT_TIME;
|
||||
|
||||
pcd_updateStatus( pstPCD->ucStatus - ISO_14443A_PCD_STATE_BEGIN );
|
||||
r = ISO14443A_AnticollisionFrame_req( ISO_14443_CMD_SEL_CL1, NULL, 0 );
|
||||
|
||||
printf("\nRx ATQA.");
|
||||
fprintf(g_fpDebug, "\nRx ATQA.");
|
||||
printf("\n\nTx SELECT(anticollision), waiting anticollision.\nwait");
|
||||
fprintf( g_fpDebug,"\n\nTx SELECT(anticollision), waiting anticollision.\nwait");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ISO_14443A_PCD_STATE_ANTI:
|
||||
// ִ<>з<EFBFBD><D0B7><EFBFBD>ͻѭ<CDBB><D1AD>.
|
||||
if( u16RxBufBitLen == 0 )
|
||||
{
|
||||
// if( pstPCD->ucAntiBit == 2 || pstPCD->ucAntiBit == 1 )
|
||||
if( pstPCD->ucAntiBit == 2 || pstPCD->ucAntiBit == !g_firstBitValue )
|
||||
{
|
||||
if( pstPCD->u16WaitTime )
|
||||
{
|
||||
pstPCD->u16WaitTime--;
|
||||
#ifdef _RFID_DEBUG_
|
||||
printf("\nwaitTime = %d", pstPCD->u16WaitTime );
|
||||
#else
|
||||
printf(".");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef _RFID_DEBUG_
|
||||
printf("\nwaitTime = %d. not wait.", pstPCD->u16WaitTime );
|
||||
#endif
|
||||
printf("\nTimeout. not wait." );
|
||||
return -1; // <20><><EFBFBD><EFBFBD><EFBFBD>ˡ<EFBFBD>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// ˵<><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><CDB9><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>.
|
||||
// <20>ȴ<EFBFBD><C8B4><EFBFBD>
|
||||
if( pstPCD->u16WaitTime == 1 )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD><CBA3><EFBFBD>newbit = 1;
|
||||
pstPCD->ucAntiBit = g_firstBitValue == 0 ? 1:0;
|
||||
pstPCD->u16WaitTime = PCD_WAIT_TIME;
|
||||
return PCD_ISO14443A_SendANTICOLLISION( pstPCD );
|
||||
}
|
||||
else
|
||||
{
|
||||
// <20>ȴ<EFBFBD>bit = 0<><30><EFBFBD>Ǹ<EFBFBD>
|
||||
pstPCD->u16WaitTime--;
|
||||
#ifdef _RFID_DEBUG_
|
||||
printf("\nwaitTime = %d", pstPCD->u16WaitTime );
|
||||
#else
|
||||
printf(".");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
BYTE firstByte;
|
||||
BYTE byBitLenofFirstByte;
|
||||
BYTE aucCmdBuf[100];
|
||||
UINT16 u16CmdBitLen;
|
||||
|
||||
if( pstPCD->ucCmpBits%8 )
|
||||
{
|
||||
byBitLenofFirstByte = 8 - pstPCD->ucCmpBits%8;
|
||||
}
|
||||
else
|
||||
{
|
||||
byBitLenofFirstByte = 0;
|
||||
}
|
||||
|
||||
r = ISO14443A_wait_anticollisionFrame_rsp( byBitLenofFirstByte, &firstByte,
|
||||
aucRxBuf, u16RxBufBitLen,
|
||||
aucCmdBuf, &u16CmdBitLen
|
||||
);
|
||||
if( r < 0 )
|
||||
{
|
||||
pstPCD->ucStatus = ISO_14443A_PCD_STATE_ER;
|
||||
return r;
|
||||
}
|
||||
|
||||
{
|
||||
int k = 0;
|
||||
int txLen = u16CmdBitLen + byBitLenofFirstByte;
|
||||
UCHAR txBuf[200];
|
||||
if( byBitLenofFirstByte )
|
||||
{
|
||||
txBuf[k++] = firstByte;
|
||||
}
|
||||
|
||||
for( int i = 0; i < u16CmdBitLen/8; i++ )
|
||||
{
|
||||
txBuf[k++] = aucCmdBuf[i];
|
||||
}
|
||||
|
||||
pcd_postMessage( txBuf, txLen, ISO_14443_CMD_SEL_CLx, "send ANTI" );
|
||||
}
|
||||
// <20><>ӡ<EFBFBD>յ<EFBFBD><D5B5><EFBFBD>UID
|
||||
|
||||
printf("\nRx UID: ");
|
||||
fprintf(g_fpDebug, "\nRx UID:");
|
||||
if( byBitLenofFirstByte )
|
||||
{
|
||||
int i, k;
|
||||
for( i = 0; i < byBitLenofFirstByte; i++ )
|
||||
{
|
||||
k = ( firstByte >> i ) & 0x01 ;
|
||||
printf("%d", k);
|
||||
fprintf(g_fpDebug, "%d", k);
|
||||
if( i == byBitLenofFirstByte - 5 )
|
||||
{
|
||||
printf(".");
|
||||
fprintf(g_fpDebug, ".");
|
||||
}
|
||||
}
|
||||
printf(".");
|
||||
fprintf(g_fpDebug, ".");
|
||||
}
|
||||
|
||||
if( u16CmdBitLen-8 > 0 )
|
||||
{
|
||||
int i,k;
|
||||
int btoffset, byoffset;
|
||||
|
||||
for( i = 0; i < u16CmdBitLen-8; i++ )
|
||||
{
|
||||
byoffset = i/8;
|
||||
btoffset = i%8;
|
||||
k = ( aucCmdBuf[byoffset] >> btoffset ) & 0x01;
|
||||
printf("%d", k);
|
||||
fprintf(g_fpDebug, "%d", k);
|
||||
if( i % 4 == 3 )
|
||||
{
|
||||
printf(".");
|
||||
fprintf(g_fpDebug, ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// <20><>ͻģ<CDBB><C4A3>.
|
||||
PCD_ISO14443A_CollisionEmu( pstPCD, byBitLenofFirstByte, firstByte, aucCmdBuf, u16CmdBitLen);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD><C7B2><EFBFBD><EFBFBD>dz<EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
//
|
||||
//int k = pstPCD->ucCmpBits / 8;
|
||||
//BYTE mask[] = {0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFF};
|
||||
|
||||
//if( byBitLenofFirstByte != 0 )
|
||||
//{
|
||||
// // ǰ<><C7B0><EFBFBD>ء<EFBFBD>
|
||||
// pstPCD->aucUID[k] &= mask[byBitLenofFirstByte-1];
|
||||
// firstByte &= ~mask[byBitLenofFirstByte-1];
|
||||
// pstPCD->aucUID[k] |= firstByte;
|
||||
// k++; // <20><>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD>.
|
||||
// pstPCD->ucCmpBits += byBitLenofFirstByte;
|
||||
//}
|
||||
|
||||
//j = 0;
|
||||
//for( i = k; i < 4+k; i++ )
|
||||
//{
|
||||
// pstPCD->aucUID[i] = aucCmdBuf[j++];
|
||||
// pstPCD->ucCmpBits += 8;
|
||||
//}
|
||||
|
||||
printf("\nRx anticollision.");
|
||||
fprintf( g_fpDebug, "\nRx anticollision.");
|
||||
|
||||
if( pstPCD->ucCmpBits == 32 || pstPCD->ucCmpBits == 64 || pstPCD->ucCmpBits == 96 )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>UID.
|
||||
pstPCD->ucAntiBit = 2; // <20><><EFBFBD><EFBFBD>.
|
||||
r = PCD_ISO14443A_SendSELECT(pstPCD);
|
||||
}
|
||||
else
|
||||
{
|
||||
// pstPCD->ucAntiBit = 0; // <20><><EFBFBD><EFBFBD>.
|
||||
pstPCD->ucAntiBit = g_firstBitValue; // <20><>һ<EFBFBD><D2BB>ʹ<EFBFBD>õ<EFBFBD>bit.
|
||||
r = PCD_ISO14443A_SendANTICOLLISION(pstPCD );
|
||||
}
|
||||
pstPCD->u16WaitTime = PCD_WAIT_TIME;
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD>SELECT<43><54><EFBFBD><EFBFBD>תΪACTIVE
|
||||
break;
|
||||
case ISO_14443A_PCD_STATE_SELECT:
|
||||
/**
|
||||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* 1. <20><><EFBFBD><EFBFBD>ͻѭ<CDBB><D1AD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>32bits<74><73>UID<49><44><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>SELECT<43><54><EFBFBD><EFBFBD><EFBFBD>ٸ<EFBFBD>״̬<D7B4>ȴ<EFBFBD><C8B4><EFBFBD>
|
||||
* 2. <20><><EFBFBD><EFBFBD>ͻѭ<CDBB><D1AD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD>յ<EFBFBD><D5B5>ı<EFBFBD><C4B1><EFBFBD>С<EFBFBD><D0A1>31bits<74><73>PCD<43><44><EFBFBD><EFBFBD><EFBFBD>ӱ<EFBFBD><D3B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ 0<><30>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
* 2.1<EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>л<EFBFBD>Ӧ<EFBFBD><EFBFBD>
|
||||
* 2.1.1 <20><><EFBFBD><EFBFBD>ʱ<EFBFBD>ȴ<EFBFBD> ucAntiBit <20>κ<CEBA><F3A3ACB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӱ<EFBFBD><D3B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ1<CEAA><31><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>Ȼ<EFBFBD><C8BB>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>Եȵ<D4B5><C8B5><EFBFBD>
|
||||
* 2.1.2 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>л<EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* 2.2<EFBFBD>л<EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
if( u16RxBufBitLen == 0 )
|
||||
{
|
||||
// û<>л<EFBFBD>Ӧ<EFBFBD><D3A6>
|
||||
// if( pstPCD->ucAntiBit == 2 || pstPCD->ucAntiBit == 1 )
|
||||
if( pstPCD->ucAntiBit == 2 || pstPCD->ucAntiBit == !g_firstBitValue )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SELECT<43><54>frame
|
||||
if( pstPCD->u16WaitTime )
|
||||
{
|
||||
pstPCD->u16WaitTime--;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// <20>ȹ<EFBFBD><C8B9><EFBFBD>
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// <20><>һ<EFBFBD>γ<EFBFBD><CEB3>ԣ<EFBFBD><D4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӱ<EFBFBD><D3B1><EFBFBD>Ϊ0.pstPCD->ucAntiBit == 0
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SELECT<43><54>frame
|
||||
if( pstPCD->u16WaitTime == 1)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD><CBA3><EFBFBD>newbit = 1;
|
||||
// pstPCD->ucAntiBit = 1;
|
||||
pstPCD->ucAntiBit = g_firstBitValue == 0 ? 1:0;
|
||||
pstPCD->u16WaitTime = PCD_WAIT_TIME;
|
||||
return PCD_ISO14443A_SendANTICOLLISION( pstPCD );
|
||||
}
|
||||
else if( pstPCD->u16WaitTime )
|
||||
{
|
||||
pstPCD->u16WaitTime--;
|
||||
#ifdef _RFID_DEBUG_
|
||||
printf("\nwaitTime = %d.", pstPCD->u16WaitTime );
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// <20>յ<EFBFBD>SAK.
|
||||
// <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>SAK
|
||||
r = ISO14443A_wait_SAK( aucRxBuf, u16RxBufBitLen, &pstPCD->ucSAK );
|
||||
if( r < 0 )
|
||||
{
|
||||
return r;
|
||||
}
|
||||
printf("\nRx SAK[0x%02x].", pstPCD->ucSAK);
|
||||
fprintf( g_fpDebug, "\nRx SAK[0x%02x].", pstPCD->ucSAK);
|
||||
|
||||
// <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>UID.
|
||||
if( ( pstPCD->ucSAK >> 2 ) & 0x01 )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD>UID.
|
||||
pcd_postMessage( &pstPCD->ucSAK, 8, ISO_14443_CMD_SAK, "continue anti" );
|
||||
pstPCD->ucStatus = ISO_14443A_PCD_STATE_ANTI;
|
||||
pcd_updateStatus( pstPCD->ucStatus - ISO_14443A_PCD_STATE_BEGIN );
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ANTI.
|
||||
pstPCD->ucSEL = ( pstPCD->ucCmpBits == 32 )?ISO_14443_CMD_SEL_CL2:ISO_14443_CMD_SEL_CL3;
|
||||
|
||||
r = ISO14443A_AnticollisionFrame_req( pstPCD->ucSEL, NULL, 0 );
|
||||
if( r < 0 )
|
||||
{
|
||||
return r;
|
||||
}
|
||||
printf("\n\nTx SELECT(anticollision), waiting anticollision.\nwait");
|
||||
fprintf( g_fpDebug, "\n\nTx SELECT(anticollision), waiting anticollision.\nwait");
|
||||
}
|
||||
else
|
||||
{
|
||||
// bit3=0;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>תΪEND
|
||||
// <20><><EFBFBD><EFBFBD>HALT.
|
||||
{
|
||||
char uid[200]={0};
|
||||
char t[10];
|
||||
|
||||
strcpy( uid, "uid=" );
|
||||
for( int i = pstPCD->ucCmpBits/8-1; i >=0 ; i-- )
|
||||
{
|
||||
if( pstPCD->aucUID[i] != 0x88 )
|
||||
{
|
||||
sprintf( t, "%02X.", pstPCD->aucUID[i]);
|
||||
strcat( uid, t );
|
||||
}
|
||||
}
|
||||
pcd_postMessage( &pstPCD->ucSAK, 8, ISO_14443_CMD_SAK, uid );
|
||||
}
|
||||
pstPCD->ucStatus = ISO_14443A_PCD_STATE_OK;
|
||||
pcd_updateStatus( pstPCD->ucStatus - ISO_14443A_PCD_STATE_BEGIN );
|
||||
|
||||
ISO14443A_HALT();
|
||||
|
||||
printf("\nEnd.");
|
||||
fprintf( g_fpDebug, "\nEnd." );
|
||||
}
|
||||
break;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
43
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_pcd.h
Normal file
43
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_pcd.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* \file rfid_iso14443A_pcd.h
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _RFID_ISO14443A_PCD_H_
|
||||
#define _RFID_ISO14443A_PCD_H_
|
||||
|
||||
#include "rfid_def.h"
|
||||
#include "rfid_iso14443A_cmdtx.h"
|
||||
#include "rfid_iso14443A_cmdrx.h"
|
||||
|
||||
typedef struct ISO_14443A_PCD_tag
|
||||
{
|
||||
UCHAR ucStatus;
|
||||
UCHAR ucCmpBits; // <20><>ǰ<EFBFBD>Ѿ<EFBFBD><D1BE>ͳ<EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD>ٸ<EFBFBD>bit<69>ˡ<EFBFBD>
|
||||
UCHAR ucCLn; // 0/1/2<>ֱ<EFBFBD><D6B1><EFBFBD>ʾ1/2/3<><33>UID<49><44><EFBFBD><EFBFBD>.
|
||||
UCHAR ucSEL; // <20><>ǰSEL<45><4C>ֵ.
|
||||
UCHAR ucSAK; // SAK<41><4B>ֵ
|
||||
UCHAR ucAntiBit; // <20><><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>bit<69><74>Ĭ<EFBFBD><C4AC>2<EFBFBD><32><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/û<>д<EFBFBD><D0B4>ڷ<EFBFBD><DAB7><EFBFBD>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>
|
||||
UINT16 u16WaitTime; // <20><><EFBFBD><EFBFBD><EEB7A2>ȥ<EFBFBD>ȴ<F3A3ACB5><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
UCHAR aucUID[12]; // <20><><EFBFBD><EFBFBD>10<31><30><EFBFBD>ֽ<EFBFBD>
|
||||
}ISO_14443A_PCD;
|
||||
|
||||
int PCD_ISO14443A_run( ISO_14443A_PCD *pstPCD );
|
||||
int PCD_ISO14443A_process( ISO_14443A_PCD *pstPCD, UCHAR aucRxBuf[], UINT16 u16RxBufBitLen );
|
||||
// <20><>ͻģ<CDBB>⣺
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD>յ<EFBFBD><D5B5>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>
|
||||
int PCD_ISO14443A_CollisionEmu( ISO_14443A_PCD *pstPCD,
|
||||
BYTE byBitLenofFirstByte, BYTE firstByte,
|
||||
UCHAR aucCmdBuf[], UINT16 u16CmdBitLen );
|
||||
// <20><><EFBFBD><EFBFBD>SELECT֡
|
||||
int PCD_ISO14443A_SendSELECT( ISO_14443A_PCD *pstPCD );
|
||||
// <20><><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>ײ֡<D7B2><D6A1>
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD>ء<EFBFBD>
|
||||
int PCD_ISO14443A_SendANTICOLLISION( ISO_14443A_PCD *pstPCD );
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
43
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_pcd.h.bak
Normal file
43
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_pcd.h.bak
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* \file rfid_iso14443A_pcd.h
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _RFID_ISO14443A_PCD_H_
|
||||
#define _RFID_ISO14443A_PCD_H_
|
||||
|
||||
#include "rfid_def.h"
|
||||
#include "rfid_iso14443A_cmdtx.h"
|
||||
#include "rfid_iso14443A_cmdrx.h"
|
||||
|
||||
typedef struct ISO_14443A_PCD_tag
|
||||
{
|
||||
UCHAR ucStatus;
|
||||
UCHAR ucCmpBits; // <20><>ǰ<EFBFBD>Ѿ<EFBFBD><D1BE>ͳ<EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD>ٸ<EFBFBD>bit<69>ˡ<EFBFBD>
|
||||
UCHAR ucCLn; // 0/1/2<>ֱ<EFBFBD><D6B1><EFBFBD>ʾ1/2/3<><33>UID<49><44><EFBFBD><EFBFBD>.
|
||||
UCHAR ucSEL; // <20><>ǰSEL<45><4C>ֵ.
|
||||
UCHAR ucSAK; // SAK<41><4B>ֵ
|
||||
UCHAR ucAntiBit; // <20><><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>bit<69><74>Ĭ<EFBFBD><C4AC>2<EFBFBD><32><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/û<>д<EFBFBD><D0B4>ڷ<EFBFBD><DAB7><EFBFBD>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>
|
||||
UINT16 u16WaitTime; // <20><><EFBFBD><EFBFBD><EEB7A2>ȥ<EFBFBD>ȴ<F3A3ACB5><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
UCHAR aucUID[12]; // <20><><EFBFBD><EFBFBD>10<31><30><EFBFBD>ֽ<EFBFBD>
|
||||
}ISO_14443A_PCD;
|
||||
|
||||
int PCD_ISO14443A_run( ISO_14443A_PCD *pstPCD );
|
||||
int PCD_ISO14443A_process( ISO_14443A_PCD *pstPCD, UCHAR aucRxBuf[], UINT16 u16RxBufBitLen );
|
||||
// <20><>ͻģ<CDBB>⣺
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD>յ<EFBFBD><D5B5>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>
|
||||
int PCD_ISO14443A_CollisionEmu( ISO_14443A_PCD *pstPCD,
|
||||
BYTE byBitLenofFirstByte, BYTE firstByte,
|
||||
UCHAR aucCmdBuf[], UINT16 u16CmdBitLen );
|
||||
// <20><><EFBFBD><EFBFBD>SELECT֡
|
||||
int PCD_ISO14443A_SendSELECT( ISO_14443A_PCD *pstPCD );
|
||||
// <20><><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>ײ֡<D7B2><D6A1>
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD>ء<EFBFBD>
|
||||
int PCD_ISO14443A_SendANTICOLLISION( ISO_14443A_PCD *pstPCD );
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
619
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_picc.cpp
Normal file
619
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_picc.cpp
Normal file
@@ -0,0 +1,619 @@
|
||||
/**
|
||||
* \file rfid_iso14443A_picc.c
|
||||
*
|
||||
*
|
||||
* \desp ģ<><C4A3>һ<EFBFBD>ŷ<EFBFBD><C5B7><EFBFBD>ISO14443A<33>Ŀ<EFBFBD>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "rfid_def.h"
|
||||
#include "rfid_iso14443A_picc.h"
|
||||
#include "picc_thread.h"
|
||||
|
||||
#if 0
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
return picc_main( argc, argv );
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
|
||||
* picc_14443A n xxx1 xxx2
|
||||
* n. <09><><EFBFBD>濨<EFBFBD><E6BFA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>10<31>ſ<EFBFBD>)
|
||||
* xxx1/xxx2. <09><><EFBFBD>ţ<EFBFBD>
|
||||
*/
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>и<EFBFBD>ʽ<EFBFBD><CABD>ISO14443A_PICC uidLen UID
|
||||
int picc_main(int argc, char *argv[] )
|
||||
{
|
||||
ISO_14443A_PICC stPICC;
|
||||
|
||||
if( argc == 2 )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><D0BD><EFBFBD>UID
|
||||
stPICC.ucStatus = ISO_14443A_STATE_POWEROFF;
|
||||
stPICC.ucCmpBits = 0;
|
||||
switch( strlen( argv[1] ))
|
||||
{
|
||||
case 8:
|
||||
stPICC.ucCLn = 0;
|
||||
break;
|
||||
case 14:
|
||||
stPICC.ucCLn = 1;
|
||||
break;
|
||||
case 20:
|
||||
stPICC.ucCLn = 2;
|
||||
break;
|
||||
default:
|
||||
printf("\nuid invalid.\n");
|
||||
return -1;
|
||||
}
|
||||
// stPICC.ucCLn = strlen( argv[2] ); // atoi(argv[1]);
|
||||
if( GetUIDFromString( &stPICC, argv[1] ) < 1 )
|
||||
{
|
||||
printf("\nInvalid command line.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("input: iso14443A_picc uidLen(0/1/2) uid(HEX).\n" );
|
||||
stPICC.ucStatus = ISO_14443A_STATE_POWEROFF;
|
||||
stPICC.ucCmpBits = 0;
|
||||
stPICC.ucCLn = 2; //atoi(argv[1]);
|
||||
stPICC.aucUID[0] = 0x12;
|
||||
stPICC.aucUID[1] = 0x34;
|
||||
stPICC.aucUID[2] = 0x56;
|
||||
stPICC.aucUID[3] = 0x78;
|
||||
|
||||
stPICC.aucUID[4] = 0x88;
|
||||
stPICC.aucUID[5] = 0x90;
|
||||
stPICC.aucUID[6] = 0x91;
|
||||
stPICC.aucUID[7] = 0x92;
|
||||
|
||||
stPICC.aucUID[8] = 0x88;
|
||||
stPICC.aucUID[9] = 0xA0;
|
||||
stPICC.aucUID[10] = 0xA1;
|
||||
stPICC.aucUID[11] = 0xA2;
|
||||
|
||||
//return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* <09><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
|
||||
*/
|
||||
stPICC.ucStatus = ISO_14443A_STATE_IDLE;
|
||||
|
||||
/**
|
||||
* <20><>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>PICC<43><43>Ϣ.
|
||||
*/
|
||||
{
|
||||
int l1, l2, i;
|
||||
|
||||
switch( stPICC.ucCLn )
|
||||
{
|
||||
case 0:
|
||||
l1 = 32;
|
||||
l2 = 4;
|
||||
break;
|
||||
case 1:
|
||||
l1 = 56;
|
||||
l2 = 8;
|
||||
break;
|
||||
case 2:
|
||||
l1 = 80;
|
||||
l2 = 12;
|
||||
break;
|
||||
}
|
||||
printf("\nPICC: uid length = %d, UID: ", l1/8 );
|
||||
for( i = 0; i < l2; i++ )
|
||||
{
|
||||
if( stPICC.aucUID[i] != 0x88 )
|
||||
{
|
||||
printf("0x%02X.", stPICC.aucUID[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
PICC_ISO14443A_run( &stPICC );
|
||||
printf("\n\nEnd, press 'q' to end.\n");
|
||||
|
||||
while(1)
|
||||
{
|
||||
char c = getchar();
|
||||
if( c == 'q' )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int GetUIDFromString( ISO_14443A_PICC *pstPICC, char *szUID )
|
||||
{
|
||||
int i, j, k, l;
|
||||
char c;
|
||||
|
||||
memset( pstPICC->aucUID, 0x00, 12 );
|
||||
|
||||
switch( pstPICC->ucCLn )
|
||||
{
|
||||
case 0:
|
||||
l = 4; // 0,1,2,3;
|
||||
memset( pstPICC->aucUID + 4, 0x88, 8 );
|
||||
break;
|
||||
case 1:
|
||||
l = 7;
|
||||
pstPICC->aucUID[0] = 0x88; // x 0,1,2, 3,4,5,6
|
||||
memset( pstPICC->aucUID + 8, 0x88, 4 );
|
||||
break;
|
||||
case 2:
|
||||
// x 0,1,2, x,3,4,5, 6,7,8,9
|
||||
l = 10;
|
||||
pstPICC->aucUID[0] = 0x88;
|
||||
pstPICC->aucUID[4] = 0x88;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
k = strlen( szUID );
|
||||
if( k != l * 2 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
j = k-1;
|
||||
i = 0;
|
||||
while( j >= 0 )
|
||||
{
|
||||
if( pstPICC->aucUID[i] == 0x88 )
|
||||
{
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
c = szUID[j];
|
||||
if( c >= 'A' && c <= 'F' )
|
||||
{
|
||||
c = c-'A' + 10;
|
||||
}
|
||||
else if( c >= 'a' && c <= 'f' )
|
||||
{
|
||||
c = c - 'a' + 10;
|
||||
}
|
||||
else if( c >= '0' && c <= '9' )
|
||||
{
|
||||
c = c - '0';
|
||||
}
|
||||
|
||||
if( (j % 2) == 0 )
|
||||
{
|
||||
pstPICC->aucUID[i] |= c << 4;
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
pstPICC->aucUID[i] |= c;
|
||||
}
|
||||
j--;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int PICC_ISO14443A_run(ISO_14443A_PICC *pstPICC)
|
||||
{
|
||||
UCHAR aucRxBuf[256];
|
||||
UINT16 u16BufLen = 256;
|
||||
int len, rtn;
|
||||
|
||||
printf("\nIDLE:\n\tWaiting REQA......");
|
||||
while( 1 )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD>
|
||||
len = RFID_Card_Rx( u16BufLen, aucRxBuf );
|
||||
if( len > 0 )
|
||||
{
|
||||
rtn = PICC_ISO14443A_process( pstPICC, aucRxBuf, len );
|
||||
}
|
||||
else
|
||||
{
|
||||
// sleep( 1000 );
|
||||
}
|
||||
|
||||
if( rtn == -100 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* ÿ<><C3BF>PICC<43><43>״̬<D7B4><CCAC>.
|
||||
*
|
||||
* ucPICCId: <20><>0<EFBFBD><30>ʼ<EFBFBD><CABC>
|
||||
*
|
||||
*/
|
||||
|
||||
int PICC_ISO14443A_process( ISO_14443A_PICC *pstPICC, BYTE abyRxBuf[], UINT16 u16BitLen )
|
||||
{
|
||||
UCHAR aucRxCmd[32]; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EEA3AC><EFBFBD>߷<EFBFBD><DFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
UINT16 u16RxBitLen;
|
||||
int r;
|
||||
|
||||
switch( pstPICC->ucStatus )
|
||||
{
|
||||
case ISO_14443A_STATE_POWEROFF:
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>
|
||||
break;
|
||||
case ISO_14443A_STATE_IDLE:
|
||||
/**
|
||||
* <09><><EFBFBD><EFBFBD>REQA
|
||||
*/
|
||||
// printf("\nWaiting REQA...");
|
||||
r = ISO14443A_wait_REQA( abyRxBuf, u16BitLen );
|
||||
if( r > 0 )
|
||||
{
|
||||
printf("\n\tRx REQA. Tx ATQA. ");
|
||||
picc_postMessage( abyRxBuf, u16BitLen, ISO_14443_CMD_REQA, "Rx REQA. Tx ATQA." );
|
||||
|
||||
ISO14443A_ATQA( pstPICC->ucCLn );
|
||||
pstPICC->ucStatus = ISO_14443A_STATE_READY;
|
||||
printf("\n\nREADY:\n\tWaiting SELECT(anticollision)......");
|
||||
}
|
||||
// <20><><EFBFBD>з<EFBFBD>REQA<51><41><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EEA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
break;
|
||||
case ISO_14443A_STATE_READY:
|
||||
/**
|
||||
* <09><><EFBFBD><EFBFBD>ANTICOLLISION
|
||||
*/
|
||||
//printf("\nWaiting anticollision...");
|
||||
r = ISO14443A_wait_anticollisionFrame_req( abyRxBuf, u16BitLen, aucRxCmd, &u16RxBitLen );
|
||||
if( r >= 16 ) // <20><><EFBFBD><EFBFBD>16<31><36><EFBFBD><EFBFBD>
|
||||
{
|
||||
BYTE sel, nvb;
|
||||
int m, n, l;
|
||||
|
||||
sel = aucRxCmd[0];
|
||||
// sel<65>Ƿ<EFBFBD><C7B7>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE>й<EFBFBD><D0B9>ˣ<EFBFBD><CBA3>ڴ˾Ͳ<CBBE><CDB2><EFBFBD><EFBFBD>ˡ<EFBFBD>
|
||||
if( ( sel != ISO_14443_CMD_SEL_CL1 ) && ( sel != ISO_14443_CMD_SEL_CL2 ) && ( sel != ISO_14443_CMD_SEL_CL3 ))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
nvb = aucRxCmd[1];
|
||||
|
||||
// <20><>nvb<76>ж<EFBFBD>֡<EFBFBD><D6A1>
|
||||
m = ( nvb >> 4 ) & 0x0F;
|
||||
n = nvb &0x0F;
|
||||
|
||||
l = m * 8;
|
||||
if( n != 0 )
|
||||
{
|
||||
l -= ( 8 - n );
|
||||
}
|
||||
if( aucRxCmd[1] == 0x70 )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SELECT.
|
||||
if( l != u16RxBitLen - 16 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( l != u16RxBitLen )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
// ֡û<D6A1><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
printf("\n\tRx %s", (l != u16RxBitLen) ? "SELECT":"anticollision.");
|
||||
printf("\n\t\tSEL: 0x%02X, NVB = 0x%02x.", sel, nvb );
|
||||
|
||||
// <20><>anticollision֡<6E><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if( aucRxCmd[1] == 0x70 ) // nvb.
|
||||
{
|
||||
// SELECT
|
||||
r = PICC_ISO14443A_PICC_select( pstPICC, aucRxCmd, u16RxBitLen );
|
||||
if( r < 0 )
|
||||
{
|
||||
printf(" \n\t\t------It's not my UID. do nothing." );
|
||||
picc_postMessage( aucRxCmd, u16RxBitLen, aucRxCmd[0], "Rx SELECT, not my UID. do nothing." );
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\n\t\tSELECT frame. Tx. SAK.[0x%02X]." , pstPICC->ucSAK );
|
||||
|
||||
picc_postMessage( aucRxCmd, u16RxBitLen, aucRxCmd[0], "Rx SELECT, Tx SAK" );
|
||||
picc_postMessage((UCHAR *)&pstPICC->ucSAK, 8, ISO_14443_CMD_SAK);
|
||||
|
||||
if( pstPICC->ucSAK == 0x00 )
|
||||
{
|
||||
printf("\nACTIVE: \n\tWaiting HALT...");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\n\t\tWaiting anticollision...");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\n\t\tAnticollision frame. Tx. anticollision." );
|
||||
|
||||
// r = PICC_ISO14443A_PICC_anticollision( pstPICC, aucRxCmd, u16RxBitLen );
|
||||
BYTE txBuf[200];
|
||||
int txBufBitLen;
|
||||
r = PICC_ISO14443A_PICC_anticollision( pstPICC, aucRxCmd, u16RxBitLen, txBuf, &txBufBitLen );
|
||||
|
||||
if( r < 0 )
|
||||
{
|
||||
picc_postMessage( aucRxCmd, u16RxBitLen, aucRxCmd[0], "Rx ANTI, not my UID. do nothing." );
|
||||
printf(" \n\t:It's not my UID. do nothing." );
|
||||
}
|
||||
else
|
||||
{
|
||||
picc_postMessage( aucRxCmd, u16RxBitLen, aucRxCmd[0], "Rx ANTI, Send ANTI." );
|
||||
picc_postMessage( txBuf, txBufBitLen, ISO_14443_CMD_SEL_CLx );
|
||||
printf("\n\t\tWaiting anticollision...");
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ISO_14443A_STATE_ACTIVE:
|
||||
/**
|
||||
* <09><><EFBFBD><EFBFBD>HALT<4C><54><EFBFBD><EFBFBD>
|
||||
*
|
||||
*/
|
||||
// printf("\nWaiting halt...");
|
||||
r = ISO14443A_wait_HALT( abyRxBuf, u16BitLen );
|
||||
if( r > 0 )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><CEBA><EFBFBD><EFBFBD><EFBFBD>
|
||||
printf("\n\t\tRx HALT. Tx nothing. ");
|
||||
|
||||
picc_postMessage( abyRxBuf, u16BitLen, ISO_14443_CMD_HALT, "Rx HALT. Tx nothing. ");
|
||||
pstPICC->ucStatus = ISO_14443A_STATE_HALT;
|
||||
printf("\nHALT. \n\twaiting WUPA...");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\n\t\tNot HALT cmd, continue waiting.");
|
||||
}
|
||||
break;
|
||||
case ISO_14443A_STATE_HALT:
|
||||
/**
|
||||
* <09><><EFBFBD><EFBFBD>WUPA<50><41><EFBFBD><EFBFBD>
|
||||
*
|
||||
*/
|
||||
// printf("\nWaiting WUPA...");
|
||||
r = ISO14443A_wait_WUPA( abyRxBuf, u16BitLen );
|
||||
if( r > 0 )
|
||||
{
|
||||
printf("\n\tRx WUPA, Tx ATQA.");
|
||||
picc_postMessage( abyRxBuf, u16BitLen, ISO_14443_CMD_WUPA, "Rx WUPA, Tx ATQA." );
|
||||
|
||||
ISO14443A_ATQA( pstPICC->ucCLn );
|
||||
printf("\nREADY. Waiting anticollision");
|
||||
pstPICC->ucStatus = ISO_14443A_STATE_READY;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\n\t\tNot WUPA cmd, continue waiting...");
|
||||
return -100;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
picc_updateStatus( pstPICC->ucStatus - ISO_14443A_STATE_POWEROFF );
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
// picc<63>յ<EFBFBD>SELECT.
|
||||
int PICC_ISO14443A_PICC_anticollision( ISO_14443A_PICC *pstPICC, BYTE abyRxCmd[], UINT16 u16CmdBitLen, BYTE aTxBuf[], int *pTxButBitLen )
|
||||
{
|
||||
BYTE sel, CL, bcc;
|
||||
int uidBitLen;
|
||||
int m, n;
|
||||
int i;
|
||||
int byoffset, btoffset;
|
||||
|
||||
// <20><>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD>е<EFBFBD>bit Len<65><6E><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>ײ֡<D7B2><D6A1><EFBFBD><EFBFBD>Ҫ
|
||||
BYTE byBitLenofFirstByte;
|
||||
BYTE byFirstByte;
|
||||
BYTE abyUID[4];
|
||||
UINT16 u16UIDBitLen;
|
||||
BYTE mask[]={0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF};
|
||||
|
||||
// <20><EFBFBD><F2BBAFB7><EFBFBD><EFBFBD><EFBFBD>u16CmdBitLen % 8 <20>Ƿ<EFBFBD><C7B7><EFBFBD> n <20><><EFBFBD>ȡ<EFBFBD>
|
||||
sel = abyRxCmd[0];
|
||||
|
||||
// <20><>ʼ<EFBFBD><CABC>֯<EFBFBD><D6AF><EFBFBD>ص<EFBFBD>֡.
|
||||
|
||||
// PCD<43><44><EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD><EFBFBD><EFBFBD>UID<49>ı<EFBFBD><C4B1>س<EFBFBD><D8B3><EFBFBD>.
|
||||
uidBitLen = u16CmdBitLen - 16; // sel+nvb.
|
||||
|
||||
if( sel == ISO_14443_CMD_SEL_CL1 )
|
||||
{
|
||||
CL = 0;
|
||||
}
|
||||
else if( sel == ISO_14443_CMD_SEL_CL2 )
|
||||
{
|
||||
CL = 4;
|
||||
}
|
||||
else // ISO_14443_CMD_SEL_CL3.
|
||||
{
|
||||
CL = 8;
|
||||
}
|
||||
|
||||
// <20>Ƚ<EFBFBD><C8BD>Ƿ<EFBFBD><C7B7><EFBFBD>ͬ<EFBFBD><CDAC>ͬʱ<CDAC>鷵<EFBFBD>ذ<EFBFBD>
|
||||
// <20>ȱȽ<C8B1><C8BD><EFBFBD><EFBFBD><EFBFBD>bit<69><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB>ȷ<EFBFBD>ģ<EFBFBD>
|
||||
{
|
||||
printf("\n\t\tMY UID:");
|
||||
for( i = 0; i < 32; i++ )
|
||||
{
|
||||
byoffset = i / 8;
|
||||
btoffset = i % 8;
|
||||
printf("%d", (pstPICC->aucUID[CL+byoffset] >> btoffset) & 0x01 );
|
||||
if( i % 4 == 3 )
|
||||
{
|
||||
printf(".");
|
||||
}
|
||||
}
|
||||
printf("\n\t\tRX UID:");
|
||||
for( i = 0; i < uidBitLen; i++ )
|
||||
{
|
||||
byoffset = i / 8;
|
||||
btoffset = i % 8;
|
||||
printf("%d", (abyRxCmd[2+byoffset] >> btoffset) & 0x01);
|
||||
if( i % 4 == 3 )
|
||||
{
|
||||
printf(".");
|
||||
}
|
||||
|
||||
if( ((abyRxCmd[2+byoffset] >> btoffset) & 0x01)
|
||||
!= (( pstPICC->aucUID[CL+byoffset] >> btoffset) & 0x01) )
|
||||
{
|
||||
return -1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
}
|
||||
// ǰ<><C7B0><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC>
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
// uidBitLen<65><6E><EFBFBD>ڼ<EFBFBD><DABC>㷢<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
uidBitLen = 32 - uidBitLen;
|
||||
byBitLenofFirstByte = uidBitLen % 8;
|
||||
|
||||
// <20>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
m = uidBitLen / 8; // <20>ֽ<EFBFBD><D6BD><EFBFBD>
|
||||
n = CL+3;
|
||||
u16UIDBitLen = 0;
|
||||
for( i = m-1; i >= 0; i-- )
|
||||
{
|
||||
abyUID[i] = pstPICC->aucUID[n--];
|
||||
u16UIDBitLen += 8;
|
||||
}
|
||||
if( byBitLenofFirstByte != 0 )
|
||||
{
|
||||
byFirstByte = ( pstPICC->aucUID[n] >> (8-byBitLenofFirstByte)) & mask[byBitLenofFirstByte-1]; // <20><>ʵ<EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
}
|
||||
else
|
||||
{
|
||||
byFirstByte = 0x00;
|
||||
}
|
||||
|
||||
// bcc
|
||||
bcc = 0x00;
|
||||
for( i = 0; i < 4; i++ )
|
||||
{
|
||||
bcc = bcc ^ pstPICC->aucUID[i+CL];
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int k = 0;
|
||||
int txLen = u16UIDBitLen + 8 + byBitLenofFirstByte;
|
||||
if( byBitLenofFirstByte != 0 )
|
||||
{
|
||||
aTxBuf[k++] = byFirstByte;
|
||||
}
|
||||
|
||||
for( int i = 0; i < u16UIDBitLen/8; i++ )
|
||||
{
|
||||
aTxBuf[k++] = abyUID[i];
|
||||
}
|
||||
aTxBuf[k] = bcc;
|
||||
*pTxButBitLen = txLen;
|
||||
// picc_postMessage( txBuf, txLen, ISO_14443_CMD_SEL_CLx );
|
||||
}
|
||||
return ISO14443A_AnticollisionFrame_rsp(byBitLenofFirstByte, byFirstByte, abyUID, u16UIDBitLen, bcc);
|
||||
}
|
||||
|
||||
int PICC_ISO14443A_PICC_select( ISO_14443A_PICC *pstPICC, BYTE abyRxCmd[], UINT16 u16CmdBitLen )
|
||||
{
|
||||
BYTE sel, bcc, sak;
|
||||
BYTE abyCRC[2];
|
||||
int i, CL;
|
||||
|
||||
sel = abyRxCmd[0];
|
||||
//nvb = abyRxCmd[1]; // һ<><D2BB>Ϊ0x70
|
||||
|
||||
// SELECT frame <20><><EFBFBD>ȣ<EFBFBD>SEL + NVB + UID[4] + BCC + CRC[2]
|
||||
if( u16CmdBitLen != 72 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// <20><>BCC<43>Ƿ<EFBFBD><C7B7><EFBFBD>ȷ
|
||||
bcc = 0x00;
|
||||
for( i = 2; i < 6; i++ )
|
||||
{
|
||||
bcc = bcc ^ abyRxCmd[i];
|
||||
}
|
||||
if( bcc != abyRxCmd[6] )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
// CRC<52>Ƿ<EFBFBD><C7B7><EFBFBD>ȷ
|
||||
ISO14443A_CRC( abyRxCmd, 7, &abyCRC[1], &abyCRC[0] );
|
||||
if( abyRxCmd[7] != abyCRC[0] || abyRxCmd[8] != abyCRC[1] )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7>
|
||||
|
||||
sak = 0;
|
||||
switch( sel )
|
||||
{
|
||||
case ISO_14443_CMD_SEL_CL1:
|
||||
if( pstPICC->ucCLn == 0 )
|
||||
{
|
||||
sak = 0x00;
|
||||
}
|
||||
else
|
||||
{
|
||||
sak = 1 << 2;
|
||||
}
|
||||
CL = 0;
|
||||
break;
|
||||
case ISO_14443_CMD_SEL_CL2:
|
||||
if( pstPICC->ucCLn == 1 )
|
||||
{
|
||||
sak = 0x00;
|
||||
}
|
||||
else
|
||||
{
|
||||
sak = 1 << 2;
|
||||
}
|
||||
CL = 4;
|
||||
break;
|
||||
case ISO_14443_CMD_SEL_CL3:
|
||||
sak = 0x00;
|
||||
CL = 8;
|
||||
break;
|
||||
}
|
||||
|
||||
// UID<49>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ҵ<EFBFBD>UID.
|
||||
printf("\n\t\tMY UID[RX UID]: ");
|
||||
for( i = 0; i < 4; i++ )
|
||||
{
|
||||
printf("%02x[%02x]", pstPICC->aucUID[CL+i], abyRxCmd[2+i] );
|
||||
if( abyRxCmd[2+i] != pstPICC->aucUID[CL+i] )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>SAK
|
||||
if( sak == 0x00 )
|
||||
{
|
||||
pstPICC->ucStatus = ISO_14443A_STATE_ACTIVE;
|
||||
}
|
||||
pstPICC->ucSAK = sak;
|
||||
|
||||
return ISO14443A_SAK(sak);
|
||||
}
|
||||
33
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_picc.h
Normal file
33
Labs/Lab2/requirements/src/rfidsrc/rfid_iso14443A_picc.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* \file rfid_iso14443A_picc.h
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _RFID_ISO14443A_PICC_H_
|
||||
#define _RFID_ISO14443A_PICC_H_
|
||||
|
||||
#include "rfid_def.h"
|
||||
#include "rfid_iso14443A_cmdtx.h"
|
||||
#include "rfid_iso14443A_cmdrx.h"
|
||||
|
||||
|
||||
typedef struct ISO_14443A_PICC_tag
|
||||
{
|
||||
UCHAR ucStatus;
|
||||
UCHAR ucCmpBits; // <20><>ǰ<EFBFBD>Ѿ<EFBFBD><D1BE>ͳ<EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD>ٸ<EFBFBD>bit<69>ˡ<EFBFBD>
|
||||
UCHAR ucCLn; // 0/1/2<>ֱ<EFBFBD><D6B1><EFBFBD>ʾ1/2/3<><33>UID<49><44><EFBFBD><EFBFBD>.
|
||||
UCHAR ucSAK; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>sak
|
||||
UCHAR aucUID[12]; // <20><><EFBFBD><EFBFBD>10<31><30><EFBFBD>ֽ<EFBFBD>
|
||||
}ISO_14443A_PICC;
|
||||
|
||||
int PICC_ISO14443A_run(ISO_14443A_PICC *pstPICC);
|
||||
int PICC_ISO14443A_process( ISO_14443A_PICC *pstPICC, BYTE abyRxBuf[], UINT16 u16BitLen );
|
||||
|
||||
int PICC_ISO14443A_PICC_anticollision( ISO_14443A_PICC *pstPICC, BYTE abyRxCmd[], UINT16 u16CmdBitLen );
|
||||
int PICC_ISO14443A_PICC_anticollision( ISO_14443A_PICC *pstPICC, BYTE abyRxCmd[], UINT16 u16CmdBitLen, BYTE aTxBuf[], int *pTxButBitLen );
|
||||
int PICC_ISO14443A_PICC_select( ISO_14443A_PICC *pstPICC, BYTE abyRxCmd[], UINT16 u16CmdBitLen );
|
||||
int GetUIDFromString( ISO_14443A_PICC *pstPICC, char *szUID );
|
||||
|
||||
#endif
|
||||
BIN
Labs/Lab2/requirements/src/rfidsrc/udp广播与组播.docx
Normal file
BIN
Labs/Lab2/requirements/src/rfidsrc/udp广播与组播.docx
Normal file
Binary file not shown.
BIN
Labs/Lab2/requirements/src/rfidsrc/~$p广播与组播.docx
Normal file
BIN
Labs/Lab2/requirements/src/rfidsrc/~$p广播与组播.docx
Normal file
Binary file not shown.
BIN
Labs/Lab2/requirements/src/rfidsrc/新建 Microsoft Word 文档.docx
Normal file
BIN
Labs/Lab2/requirements/src/rfidsrc/新建 Microsoft Word 文档.docx
Normal file
Binary file not shown.
Reference in New Issue
Block a user