⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 magcard.h

📁 一个读取ic卡的读卡程序。一个读取ic卡的读卡程序一个读取ic卡的读卡程序
💻 H
📖 第 1 页 / 共 5 页
字号:
#ifndef _H_MAGCARD_INCLUDED
#define _H_MAGCARD_INCLUDED

#ifdef WIN32

#include <windows.h>

#define MCAPI FAR PASCAL

typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned int dword;

typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int int32;

#endif // WIN32

#ifndef _H_CHANNEL
#define _H_CHANNEL

#include <stdio.h>

#define HCONNECTION int
#define HCHANNEL int

#define MC900		0
#define POSPKT		1
#define POSLENPKT	2
#define FRAME		3
#define MULTI		4
#define MC920		5
#define POSLENPKT_X 6
#define POSLENPKT_T 7
#define MCSERVER	8

#define	PORT_COM1 0
#define	PORT_COM2 1
#define	PORT_COM3 2
#define	PORT_COM4 3

#define NO_HANDSHAKE 0
#define USE_HANDSHAKE 1

/* COM port RECEIVING status */
//#define OVER_RIDE	0x80	/* Over-ride happened		*/
//#define PARITY_ERR	0x40	/* Error in parity check	*/
#define OVER_TIME	0x20	/* Having waited too long	*/

/* Below is some values of status */
/* Send & Receive Process Error */
enum MC900_ReplyStatus
{
    SEND_RECEIVE_OK=0,       /* Send & Receive process is complemented */
    SEND_OVER_TIME,          /* Send buffer is not empty after
								   a period of time. This is often
								   happened when the handshake is
								   not satisfied or the transmit
								   interrupt is closed */
    RETRY_OVER_TIME,    	/* Retry over times	*/
    RECEIVE_OVER_TIME,  	/* not enough charactors receiveed
	 						in a period of time	*/
    CHANNEL_NOT_DEFINED,    /* specified channel not defined */
    MACHINE_NOT_READY       /* machine not ready */
};

struct MC900_REPLY
{
    int          status;
    unsigned int length;  
    byte answer[250];
};

#ifdef __cplusplus
extern "C" {
#endif

int MCAPI
OpenChannel(int pro, int port, unsigned long baud, int hand);

int MCAPI
CloseChannel(int port);

int MCAPI
SendPkt(int channel,byte* message,unsigned msglen,
	byte * reply);

int MCAPI
RecvPkt(int channel,byte* message,unsigned* msglen);

/*
    The functions below is added by Guo Tao.
    They are the extend of old API.
*/
HCONNECTION MCAPI
openSerialPortConnection(int port, int baud, int hand, int dataBits, int stopBits, int parity);

HCONNECTION MCAPI
openWinDataModemConnection(const char *deviceName, const char *phoneNumber);

int MCAPI
closeConnection(HCONNECTION hconnection);

int MCAPI
sendData(HCONNECTION hconnection, const byte *buffer, int length);

int MCAPI
receiveData(HCONNECTION hconnection, const byte *buffer, int maxLength);

HCHANNEL MCAPI
channelOpen(HCONNECTION hconnection, int protocolType);

int MCAPI
channelClose(HCHANNEL hchannel);

int MCAPI
channelTransfer(HCHANNEL hchannel, const char *sendBuffer, int sendLength,
	const char *receiveBuffer, int receiveLength);

#ifdef __cplusplus
	}
#endif

#endif /* _H_CHANNEL */

#ifndef _H_DES_INCLUDED
#define _H_DES_INCLUDED

#define CIPHER 0	/* MODE == encrypt */
#define DECIPHER 1	/* MODE == decrypt */

#ifdef __cplusplus
extern "C" {
#endif
 
void MCAPI
des(byte *data, const byte *key, byte *result, int option);

int MCAPI
stringdes(byte *data, int length, const byte *key, byte *result, int option);

void MCAPI
CBCEncrypt(const byte *data, const byte *key, byte *init, byte *result, int len);

void MCAPI
CBCDecrypt(const byte *data, const byte *key, byte *init, byte *result, int len);

int MCAPI
MC_Decrypt(byte *dst, const byte *src, int length, const byte *key);

int MCAPI
MC_Encrypt(byte *dst, const byte *src, int length, const byte *key);

#ifdef __cplusplus
	}
#endif

#endif // _H_DES_INCLUDED

#ifndef _MC900_H_
#define _MC900_H_     

/* General status code */
#define	OK	 0
#define	myERROR	-1
#define   MC900_ENCRYPT     0
#define   MC900_DECRYPT     1  
#define   MC900_CHAR        0
#define   MC900_ASCII       2

/* Reader status */
#define ERR_TYPE		0x10	/* Card type unrecognized	*/
#define NO_CARD   	0x08	/* No card in the reader	*/
#define ERR_WRITE		0x04	/* Error in writing the card	*/
#define ERR_READ		0x02	/* Error in reading the card	*/
#define ERR_EVEN		0x01	/* Error in parity check	*/

/* COM port RECEIVING status */
#define OVER_RIDE		0x80	/* Over-ride happened		*/
#define PARITY_ERR	0x40	/* Error in parity check	*/
#define OVER_TIME		0x20	/* Having waited too long	*/
#define NO_READER		0x20	/* No reader connected		*/

/* Card type definition */
enum CardType {
	SAM=1,
	SAM1=1,
	CPUCard=2,
	GPM256=3,           /*GPM 256, F256 */
	GPM416=0x44,           /*GPM416,SLE 4404,GPM 896,ATMEL1003 */
	AT2432=0x6,			/*ATMEL 2432-256*/
	AT2464=0x6,			/*ATMEL 2432-256*/
	AT24128=0x6,			/*ATMEL 2432-256*/
	AT24256=0x6,			/*ATMEL 2432-256*/
	GPM103=7,           /*GPM 103,SLE4406*/
	SLE4432=8,          /*SLE 4432,SLE 4442*/
	SLE4442=8,
	SLE4418=9,           /*SLE 4418,SLE 4428*/
	SLE4428=9,
	SLE4428B=10,
	AT101=0x0B,			/*ATMEL 88SC101*/
	AT102=0x0B,			/*ATMEL 88SC102*/
	AT153=0x0C,			/*ATMEL 88SC153*/
	AT1604=0x0E,		/*ATMEL 1604*/
	AT1604B=0x0E,		/*ATMEL 1604*/
	AT041=0x0F,			/*ATMEL AT041 */
	AT1608=0x10,        /*ATMEL 1604*/
	AT2401=0x11,		/*ATMEL 2401-16*/
	AT2402=0x11,		/*ATMEL 2401-16*/
	AT2404=0x11,		/*ATMEL 2401-16*/
	AT2408=0x11,		/*ATMEL 2401-16*/
	AT2416=0x11,		/*ATMEL 2401-16*/
	GFM2K=0x12,			/*GFM4K, GFM8K and I2C compatible cards */
	SAM2=0x13,
};

/*MC900 status definition */
enum MC900Status {
COUPLER_OK=0,
	/*Coupler is OK. No error occurs*/
COUPLER_COMMAND_UNKNOWN=0x4,
	/*Coupler command unknown. The first byte of the
		request is not a valid commmand code.	*/
COMMU_PROTOCOL_ERROR=0x9,
	/*communication protocol error. The header of a
		message is neither ACK nor NACK(60h or E0h).	*/
RESPONSE_ERROR_RESET=0x10,
	/*Response error at the card reset. The first byte
		of the response (TS) is not valid.	*/
COMMAND_ISO_HEADER_ERROR=0x11,
	/*Command ISO header error. The byte INS in the ISO header
		is not valid(6x or 9x).	*/
MESSAGE_TOO_LONG=0x12,
	/*Message too long. The coupler buffer is limited in standard to 198
		bytes of which 129 bytes are for the data exchanged with the card. */
BYTE_READ_ERROR_ASYN=0x13,
	/*Byte reading error coming from an asynchronous card.	*/
CARD_TYPE_UNKOWN=0x14,
	/*Card type unknown. The parameter T in a command "definition of
		card type" is not valid.	*/
CARD_TURNED_OFF=0x15,
	/*Card turned off. A command "Power on" must be applied to the
		card prior to any other operation.	*/
PROGRAM_VOL_NOTAVAIL=0x16,
	/*Programming voltage not available. The parameter V in a command
		"definition of card type" is not valid.	*/
COMMU_PRO_UNKOWN=0x17,
	/*Communication protocol unknown or incorrectly initialized.	*/
COMMU_PRO_INIT_WRONG=0x18,
	/*Communication protocol unknown or incorrectly initialized.	*/
ILLEGAL_ACCESS_EXT_BUS=0x19,
	/*Illegal access to external bus. This error only applies to those
		versions of couplers without an external memory.	*/
ISO_COMMAND_ERR=0x1A,
	/*Error in an ISO-formatted card command. The parameter LN in the
		ISO header does not correspond to the actual length of the data.	*/
ROS_COMMAND_ARGU_ERR=0x1B,
	/*Sending of a command to the ROS with an incorrect number of
		 arguments.	*/
UNKNOWN_SUBFUNCTION=0x1C,
	/*Unknown subfunction. This error only occurs when the command
		"Configuration" is called with an invalid SOP parameter.	*/
ERROR_TCK=0x1D,
	/*The check byte TCK of the reset response of ans asynchronous card
	 is erroreous.	*/
WRITE_EXT_MEM_FORBIDDEN=0x1E,
	/*Writing in external memory is forbidden: write protected (the error
		occurs when,for example,one tries to download code in EPROM).*/
WRITE_EXT_MEM_ERROR=0x1F,
	/*Incorrect writing in external memory (signalled at the time of write
	check during a downloading operation.)	*/
COUPLER_NO_SWITCH=0x20,
	/*The coupler does not include any mircroswtich.	*/
ERROR_IN_RESET=0xA0,
	/*Error in the card reset response(unknown exchange protocol,byte
	TA1 not recognized, etc...) The card is not supported by the coupler.
	The card reset response is nervertheless returned.	*/
DEAD_CARD=0xA2,
	/*Dead card. The card does not respond to the reset or has interrupted
		an exchange(by "timeout").	*/
PARRITY_ERROR=0xA3,
	/*Parity error(in the course of an exchange asynchronous card<->coupler).
		The error only occurs after several unsuccessful attempts at
		retransmission.	*/
INVALID_PROCEDURE_BYTE=0xE4,
	/*The card has just set to the coupler an invalid "Procedure Byte"
		(see norm ISO 7816-3).	*/
EXCHANGE_INTERRUPTED=0xE5,
	/*The card has interrupted an exchange with the coupler(the card
	sends an SW1 byte whereas the coupler has more data to send or
	receive).	*/
CARD_ERROR=0xE7,
	/*Error returned by the card. The bytes SW1 and SW2 returned by the
	card are different from 90h 00.	*/
CARD_REMOVED=0xF7,
	/*Card removed. The card has been withdrawn in the course of the
	carrying out of an instruction. Check that the card instruction is
	not partially carried out(a possibility which depends upon the card
	type an the operation).	*/
CARD_ABSEND=0xFB
	/*Card absent. There is no card in the commnector. The card may have
        been removed when powered on, but no instruction has been interrupted.*/
};

#ifdef __cplusplus
extern "C" {
#endif
 
const char * MCAPI
GetVer();

int MCAPI
GetVerMC900_32();    /* ver 3.00 and above*/

int MCAPI
TermAuth( int port, byte *data, int option, int * status, int * line );

int MCAPI
OpenCom(int port, dword baud);

int MCAPI
CloseCom(int port);

void MCAPI
myGetVersion (int com, byte *data, byte *me1,
	byte *me2,int *status, int *line);

int MCAPI
AutoPowerOn (int com, byte *data, byte *me1, byte *me2,
		int *status, int *line);

int MCAPI
IfCardExist(int com, int *status, int *line);

void MCAPI
PowerOn (int com, byte *data, byte *me1, byte *me2,
		int *status, int *line);

void MCAPI
PowerOff (int port, int *status, int *line);

void MCAPI
DefineCard(int port,enum CardType type,int *rc);

void MCAPI
OutCommand (int com, byte cla, byte ins, dword P1P2,
		 byte P3, byte *data, byte *me1,
		 byte *me2, int *status, int *line,int *olen);

void MCAPI
InCommand (int com, byte cla, byte ins, dword P1P2,
		 byte P3, byte *data, byte *me1,
		 byte *me2, int *status, int *line, int * olen,
		 int APDUtype,int le);

int MCAPI
Transact (int port, byte *in_data, int in_len,
	  byte *out_data, dword *out_len);

void MCAPI
CommonCommand (int com,
		 byte *data, unsigned int len,byte *me1,
		 byte *me2, int *status, int *line,int *olen);

void MCAPI
OutCommand_echo (int com, byte cla, byte ins, dword P1P2,
		 byte P3, byte *data, byte *me1,
		 byte *me2, int *status, int *line,int *olen);

void MCAPI
InCommand_echo (int com, byte cla, byte ins, dword P1P2,
		 byte P3, byte *data, byte *me1,
		 byte *me2, int *status, int *line, int * olen,
		 int APDUtype,int le);

int MCAPI
ASCIIToChar(byte *dest,byte *src, unsigned len);

int MCAPI
CharToASCII(byte *dest, byte *src, unsigned len);

int MCAPI
Validate( int port, int * status, int * line );

int MCAPI
Login( int port, int len, byte *password, int * status, int * line );

int MCAPI
Logout( int port, int *status, int *line );

#ifdef __cplusplus
	}
#endif

void i_to_hex (unsigned int in_int,byte * out_hex,int byte_len);

void SetOutBody (byte *out_data,int out_len,
	byte * out_body,byte * me1,byte * me2,
	int * status);

int ICread(int port, int address, int datalen,
	byte Class,byte Command,
	 byte *data,byte * me1,byte * me2,
	int * status, int *line);

int ICwrite(int port, int address, int datalen,
	byte Class,byte Command,
	 byte *data,byte * me1,byte * me2,
	int * status, int *line);
int ICreadext(int port, long address, int datalen,
	byte Class,byte Command,
	 byte *data,byte * me1,byte * me2,
	int * status, int *line);

int ICwriteext(int port, long address, int datalen,
	byte Class,byte Command,
	 byte *data,byte * me1,byte * me2,
	int * status, int *line);

#endif /* _MC900_H_ */

#ifdef USE_AT88SC1604

#ifndef _1604_H_
#define _1604_H_

#include "..\magcard.h"

/* IC Area definition */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -