RFModuleFunc.H
上传用户:shyuanyi
上传日期:2008-05-24
资源大小:69k
文件大小:12k
- #ifndef __RF_MODULE_FUNC_H__
- #define __RF_MODULE_FUNC_H__
- //Mifare函数返回值定义
- #define MI_OK 0
- #define MI_CHK_OK 0
- #define MI_CRC_ZERO 0
- #define MI_CRC_NOTZERO 1
- #define MI_NOTAGERR 1
- #define MI_CHK_FAILED 1
- #define MI_CRCERR 2
- #define MI_CHK_COMPERR 2
- #define MI_EMPTY 3
- #define MI_AUTHERR 4
- #define MI_PARITYERR 5
- #define MI_CODEERR 6
- #define MI_SERNRERR 8
- #define MI_KEYERR 9
- #define MI_NOTAUTHERR 10
- #define MI_BITCOUNTERR 11
- #define MI_BYTECOUNTERR 12
- #define MI_IDLE 13
- #define MI_TRANSERR 14
- #define MI_WRITEERR 15
- #define MI_INCRERR 16
- #define MI_DECRERR 17
- #define MI_READERR 18
- #define MI_OVFLERR 19
- #define MI_POLLING 20
- #define MI_FRAMINGERR 21
- #define MI_ACCESSERR 22
- #define MI_UNKNOWN_COMMAND 23
- #define MI_COLLERR 24
- #define MI_RESETERR 25
- #define MI_INITERR 25
- #define MI_INTERFACEERR 26
- #define MI_ACCESSTIMEOUT 27
- #define MI_NOBITWISEANTICOLL 28
- #define MI_QUIT 30
- #define MI_RECBUF_OVERFLOW 50
- #define MI_SENDBYTENR 51
-
- #define MI_SENDBUF_OVERFLOW 53
- #define MI_BAUDRATE_NOT_SUPPORTED 54
- #define MI_SAME_BAUDRATE_REQUIRED 55
- #define MI_WRONG_PARAMETER_VALUE 60
- #define MI_BREAK 99
- #define MI_NY_IMPLEMENTED 100
- #define MI_NO_MFRC 101
- #define MI_MFRC_NOTAUTH 102
- #define MI_WRONG_DES_MODE 103
- #define MI_HOST_AUTH_FAILED 104
- #define MI_WRONG_LOAD_MODE 106
- #define MI_WRONG_DESKEY 107
- #define MI_MKLOAD_FAILED 108
- #define MI_FIFOERR 109
- #define MI_WRONG_ADDR 110
- #define MI_DESKEYLOAD_FAILED 111
- #define MI_WRONG_SEL_CNT 114
- #define MI_WRONG_TEST_MODE 117
- #define MI_TEST_FAILED 118
- #define MI_TOC_ERROR 119
- #define MI_COMM_ABORT 120
- #define MI_INVALID_BASE 121
- #define MI_MFRC_RESET 122
- #define MI_WRONG_VALUE 123
- #define MI_VALERR 124
- #define MI_SAKERR 0x46 //added by robbie
- //rf Error
- #define RF_OK 0
- #define RF_ERR 255
- //常量定义
- #define ALL_CARD 1
- #define IDLE_CARD 0
- #define KEYA 0x00
- #define KEYB 0x04
- #define DECREMENT 0xc0
- #define INCREMENT 0xc1
- #define RESTORE 0xc2
- //卡类定义
- #define MIFARE_PRO 2
- #define MIFARE_ONE 4
- #define MIFARE_LIGHT 16
- //define rf_buffer
- #define SEQNR 0
- #define COMMAND 1
- #define STATUS 1
- #define LENGTH 2
- #define MODE 3
- #define BCNT 3
- #define ADR 3
- #define SERNR 3
- #define SIZE 3
- #define TIME 3
- #define TAGTYPE 3
- #define INFO 3
- #define DATA 3
- #define SECNR 4
- #define DATABYTES 4
- #define VALUE 4
- #define NKEY 5
- #define AUTHMODE 7
- #define ADRCHKWR 8
- #define DATACHKWR 9
- #define ERROR_BLOCK_VERIFY 150 //块数据校验出错
- #define ERROR_BUSINESS_INFO_INVALID 151 //交易信息数据非法,无法恢复
- #define ERROR_BUSINESS_LIMIT_INFO_INVALID 152 //交易特别限制信息非法,无法恢复
- #define ERROR_PUBLIC_MONEY_INVALID 153 //公共钱包数据非法,无法恢复
- #define ERROR_NO_COMPLITE 154 //卡操作未完成,需重刷,否则有可能多扣款
- #define ERROR_PARAMETER_INVALID 155 //参数无效
- #define ERROR_FILL_INFO_VALID 156 //充值记录无效
- //=============================结构表定义==============================
- //卡结构分配表(共16字节对应16个扇区,已划分7个扇区)
- typedef struct _CARD_STRUCT{
- unsigned char cCompanyInfoSector; //公司信息扇区地址
- unsigned char cCardholderInfoSector;//持卡人信息扇区地址
- unsigned char cPublicMoneySector; //公共钱包区地址
- unsigned char cBusinessInfoSector; //交易信息区
- unsigned char cTimeCounterSector; //计时信息区
- unsigned char cOrderDinnerSector; //订餐信息区
- unsigned char cBusinessLimitInfoSector; //交易特别限制信息区
- unsigned char cReserve8; //备用8
- unsigned char cReserve9; //备用9
- unsigned char cReserve10; //备用10
- unsigned char cReserve11; //备用11
- unsigned char cReserve12; //备用12
- unsigned char cReserve13; //备用13
- unsigned char cReserve14; //备用14
- unsigned char cReserve15; //备用15
- unsigned char cReserve16; //备用16
- }sttCardStruct;
- //公司信息结构(共15字节)
- typedef struct _COMPANY_INFO{
- unsigned char cCompanyNumber[4]; //公司编码
- unsigned char cSubCompanyNumber[5]; //子公司编码
- unsigned char cCompanyAddressNumber[6]; //公司地址编码
- }sttCompanyInfo;
- //持卡人信息结构(40字节)
- typedef struct _CARDHOLDER_INFO{
- unsigned char cNumber[10]; //持卡人编号
- unsigned char cSerialNo[3]; //发卡流水号
- unsigned char cName[16]; //持卡人姓名
- unsigned char cCardType[2]; //卡类
- unsigned char cActiveDate[3]; //启用日期 YY MM DD
- unsigned char cInvalidDate[3]; //有效日期 YY MM DD
- unsigned char cPassword[3]; //密码
- unsigned char cState; //状态
- }sttCardholderInfo;
- //充值信息结构(15字节)
- typedef struct _FILL_INFO{
- unsigned char cDateTime[6]; //充值日期时间,格式:YY MM DD HH MM SS
- long lMoney; //充值金额
- int iTimes; //充值次数
- unsigned char cDeviceNo[2]; //设备编号
- unsigned char cMode; //充值类别
- }sttFillInfo;
- //交易信息结构(29字节基本信息+15字节充值信息=44字节)
- typedef struct _BUSINESS_INFO{
- long lMoney; //货币钱包金额
- unsigned int iTimes; //次钱包值
- unsigned char cDate[3]; //交易日期 YY MM DD
- unsigned char cIndex[3]; //交易流水号
- unsigned char cDayTotalTimes; //日累计交易次数
- unsigned int iMonthTotalTimes; //月累计交易次数
- unsigned char cDayTotalMoney[3]; //日累计交易金额
- unsigned char cMonthTotalMoney[3]; //月累计交易金额
- unsigned char cLimit[8]; //8类累计交易次数
- sttFillInfo stFillInfo; //充值信息
- }sttBusinessInfo;
- //订餐信息结构(14字节)
- typedef struct _ORDER_DINNER_INFO{
- unsigned char cDateTime1[6]; //订餐时间1
- unsigned char cOrderMode1; //订餐时间1的订餐模式
- unsigned char cDateTime2[6]; //订餐时间2
- unsigned char cOrderMode2; //订餐时间2的订餐模式
- }sttOrderDinnerInfo;
- //计时消费信息结构(12字节)
- typedef struct _TIME_COUNT_INFO{
- unsigned char cStartDateTime[6]; //开始时间
- unsigned char cStopDateTime[6]; //结束时间
- }sttTimeCountInfo;
- //========================函数声明=========================
- //----------------------模块信息函数-----------------------
- //取得RfModule模块版本号
- unsigned char RfModule_GetVersion(unsigned char *Version);
- //取得模块内部信息
- unsigned char mifs_get_info(unsigned char *_Info);
- //------------------Mifare模块基本操作函数-----------------
- //RfModule初始化
- void Rf_Init(void);
- //Rf模块重新初始化(Rf模块内已经初始化,可不调用此函数)
- unsigned char mifs_config(void);
- //寻卡
- //_Mode:寻卡模式,值为IDLE_CARD或ALL_CARD
- //_TagType[2]: 返回寻到的卡类等值
- //返回:见错误代码定义
- unsigned char mifs_request(unsigned char _Mode,unsigned char *_TagType);
- //防冲突
- //_Bcnt: 值为0-32 0为找一张最安全的卡
- //_SNR[4]:返回寻到的卡系列号
- //返回:见错误代码定义
- unsigned char mifs_anticoll(unsigned char _Bcnt,unsigned char *_SNR);
- //选择卡
- //_SNR:要选取的卡系列号
- //_Size: 返回选卡结果
- //返回:见错误代码定义
- unsigned char mifs_select(unsigned char *_SNR,unsigned char *_Size);
- //开始校验密钥(密钥存在RC500内)
- //_Mode:校验模式,KEYA为校验A密钥,KEYB为校验B密钥
- //_SecNr:要较验的扇区0-15
- unsigned char mifs_authentication(unsigned char _Mode,unsigned char _SecNr);
- //直接校验密码(校验最后一次选择的卡)
- //_Mode:校验模式,KEYA为校验A密钥,KEYB为校验B密钥
- //_SecNr[4]:要校验密钥的卡系列号
- //_Key[6]: 具体密钥
- //返回:见错误代码定义
- unsigned char mifs_authKey(unsigned char _Mode,
- unsigned char _SecNr,
- unsigned char *_Key);
- //加载密码到RC500内存中
- //_Mode:密钥类别,KEYA为A密钥,KEYB为B密钥
- //_SecNr:密钥对应的扇区,值0-15
- //_Nkey[6]: 具体密钥
- //返回:见错误代码定义
- unsigned char mifs_load_key(unsigned char _Mode,
- unsigned char _SecNr,
- unsigned char *_Nkey);
- //增值操作
- //_Adr:操作数据块,值为1-62(扣除密钥块)
- //_Value: 操作值指针,C51格式,高字节在前,低字节在后
- //返回:见错误代码定义
- unsigned char mifs_increment(unsigned char _Adr,long *_Value);
- //减值操作
- //_Adr:操作数据块,值为1-62(扣除密钥块)
- //_Value: 操作值指针,C51格式,高字节在前,低字节在后
- //返回:见错误代码定义
- unsigned char mifs_decrement(unsigned char _Adr,long *_Value);
- //增减值操作
- //_Mode:操作模式,DECREMENT减值操作,INCREMENT增值操作
- //_Adr:源数据块,值为1-62(扣除密钥块)
- //_Value: 操作值指针,C51格式,高字节在前,低字节在后
- //_Trans_Adr:目标数据据块,值为1-62(扣除密钥块),
- //注:目录数据块必须同源数据块同一个扇区,可以同一个块
- //返回:见错误代码定义
- unsigned char mifs_value(unsigned char _Mode,
- unsigned char _Adr,
- long *_Value,
- unsigned char _Trans_Adr);
- //读卡
- //_Adr:要读的块,值0-63
- //_Data[16]:返回读出的数据
- //返回:见错误代码定义
- unsigned char mifs_read(unsigned char _Adr,unsigned char *_Data);
- //写卡
- //_Adr:要写的块,值1-63
- //_Data[16]:返回读出的数据
- //返回:见错误代码定义
- unsigned char mifs_write(unsigned char _Adr,unsigned char *_Data);
- //停止当前卡
- //返回:见错误代码定义
- unsigned char mifs_halt(void);
- //复位当前卡
- //_Msec:延时ms
- //返回:见错误代码定义
- unsigned char mifs_reset(unsigned char _Msec);
- //关掉RC500
- //返回:见错误代码定义
- unsigned char mifs_close(void);
- //写模块内RC500的EEPROM
- //_Adr:写入开始地址
- //_Length:写入长度
- //_Data:写入数据
- //返回:见错误代码定义
- unsigned char mifs_read_E2(unsigned char _Adr,
- unsigned char _Length,
- unsigned char *_Data);
- //读模块内RC500的EEPROM
- //_Adr:读开始地址
- //_Length:读出长度
- //_Data:读出数据
- //返回:见错误代码定义
- unsigned char mifs_write_E2(unsigned char _Adr,
- unsigned char _Length,
- unsigned char *_Data);
- char SetCardApplicationSector(sttCardStruct *pstCardStruct);
- char GetCardApplicationSector(sttCardStruct *pstCardStruct);
- char RfIsCardIn(unsigned char CardSerialNo[]);
- char ReadCompanyInfo(unsigned char CardSerialNo[],
- unsigned char AuthMode,
- unsigned char Key[],
- sttCompanyInfo *pstCompanyInfo);
- char ReadCardholderInfo(unsigned char CardSerialNo[],
- unsigned char AuthMode,
- unsigned char Key[],
- sttCardholderInfo *pstCardholderInfo);
- char ReadBusinessInfo(unsigned char CardSerialNo[],
- unsigned char AuthMode,
- unsigned char Key[],
- sttBusinessInfo *pstBusinessInfo);
- char Consume(unsigned char CardSerialNo[],
- unsigned char Date[],
- unsigned char Index,
- long lExpenditure,
- unsigned char Flag,
- sttBusinessInfo *pstBusinessInfo);
- char ReadOrderDinnerInfoSector(unsigned char CardSerialNo[],
- unsigned char AuthMode,
- unsigned char Key[],
- sttOrderDinnerInfo *pstOrderDinnerInfo);
- char WriteOrderDinnerInfo(unsigned char Index,
- unsigned char DateTime[],
- unsigned char OrderMode);
- char SetCardState(unsigned char CardSerialNo[],
- unsigned char AuthMode,
- unsigned char Key[],
- unsigned char State);
- char Fill(unsigned char CardSerialNo[],
- sttBusinessInfo *pstBusinessInfo);
- #endif