#ifndef _READER_H_
#define _READER_H_

//包含库文件
#include "winscard.h"
#pragma comment(lib, "winscard.lib")

//Buffer
#define NUMBER_OF_READERS		4
#define NAME_LENGTH				100
#define MAX_RESPONSE			600
#define MAX_APDU_BUFFER			1024

//Error
#define ERROR_GENERAL			0xFFFE
#define SUCCESS					0x9000

//Get Data 类型
#define GET_MIFAREONE			0x0000
#define GET_TYPEA_SMART_CARD	0x0100
#define GET_ULTRALIGHT			0x0200
#define GET_MIFAREPLUS_L0		0x0300
#define GET_MIFAREPLUS_L1		0x0301
#define GET_MIFAREPLUS_L2		0x0302
#define GET_MIFAREPLUS_L3		0x0303
#define GET_MIFAREPLUS_L0S		0x0304
#define GET_TYPEB_SMART_CARD	0x2000
#define GET_SR176				0x2100
#define GET_SRIX4K				0x2200
#define GET_AT88F020			0x2300
#define GET_SRI512				0X2200
#define GET_ISO15693			0x4000
#define GET_SAM_1				0x6000
#define GET_SAM_2				0x6001
#define GET_SAM_3				0x6002
#define GET_SAM_4				0x6003 

extern long m_bProtocolType;							//PC/SC Reader 当前协议
extern unsigned int m_bReaderCounter;					//Reader 个数
extern unsigned int m_bActiveNO;						//当前激活的Reader是哪一个
extern BOOL m_bActiveFlag;								//是否有激活Reader
extern char ReaderName[NUMBER_OF_READERS][NAME_LENGTH];//所有Reader名字

//Function decleare
int UpdataReader(void);
BOOL ConnectReader(unsigned int ReaderNO);
BOOL DisconnectReader(void);
int APDUCommand(PBYTE APDU, unsigned int iLen, PBYTE cReceiveData, unsigned int *iReceiveLen);
int Authentication(unsigned int iBlockAddr, unsigned char cKeyType, unsigned char cKeyCofig, unsigned char *cpKeyData);
int ReadBinaryBlock(unsigned int iBlockAddr, unsigned char *cReceiveData, unsigned int *iReceiveLen);
int UpdataBinaryBlock(unsigned int iBlockAddr, unsigned char *cSendData, unsigned int iDataLen);
int ValueBlockOperation(unsigned int iBlockAddr, unsigned char cOperateType, long iValue);
int ReadValueBlock(unsigned int iBlockAddr, long *iValue);
int RestoreValueBlock(unsigned int iSrcAddr, unsigned int iTargetAddr);
int GetData(unsigned int iCardType, unsigned char *cReceiveData, unsigned int *iReceiveLen);
int TypeA_Halt(void);

#endif