CardSwiperClass.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /////////////////////////////////////////////////////////////////////////////////
  2. /// Copyright (c) 2013 China Merchants Bank, all rights reserved ///
  3. /// Adapter Interface for Card Swiper. ///
  4. /// ///
  5. /// ///
  6. /////////////////////////////////////////////////////////////////////////////////
  7. #ifndef __CARD_SWIPER_CLASS_H
  8. #define __CARD_SWIPER_CLASS_H
  9. #include "DeviceBaseClass.h"
  10. #include "CardMix.h"
  11. //retain bin and issue hopper state
  12. struct CardSwiperStatus
  13. {
  14. CardStatusEnum eMedia; //state about card
  15. //RtBinStatusEnum eRetainBin;
  16. //DWORD dwRetainCount; //number of card retained
  17. //IssHopperStatusEnum eIssuerBin;
  18. //DWORD dwIssuerCount; //number of card issued
  19. };
  20. struct FWBStatus
  21. {
  22. DWORD BatteryCapacity; //capacity of battery(by hour) 暂未使用
  23. DWORD BatteryLeft; //0~100,剩余电量
  24. };
  25. class CardSwiperClass : public DeviceBaseClass
  26. {
  27. public:
  28. //
  29. // Connect to device and do initialization.
  30. // Make preparations for controlling the device.
  31. // Arguments:
  32. // - dwPort[in] com port number
  33. // - dwBaudRate[in] Baud rate
  34. //
  35. virtual ErrorCodeEnum DevOpen(DWORD dwPort,DWORD dwBaudRate) = 0;
  36. //
  37. // Get card issuer status
  38. //
  39. virtual ErrorCodeEnum GetDevStatus(CardSwiperStatus &devStatus) = 0;
  40. //
  41. // Abort current operation.
  42. //
  43. virtual ErrorCodeEnum AbortRead() = 0;
  44. //
  45. // Get card status:swiping card or inserted into ic slot or rf card in induction range
  46. //
  47. // dwPos: light position
  48. // CI_LIGHT_MAG = 0x1, //the magnetic stripe light flicker
  49. // CI_LIGHT_IC = 0x2, //the IC card light flicker
  50. // CI_LIGHT_CONTACTLESS = 0x4, //the contactless card light flicker
  51. // magnetic and IC light flicker :set dwPos = (CI_LIGHT_MAG | CI_LIGHT_IC)
  52. // all light flicker:set dwPos = (CI_LIGHT_MAG | CI_LIGHT_IC | CI_LIGHT_CONTACTLESS)
  53. //
  54. // iStatus:
  55. // <0 failed
  56. // 0:timeout,cannot find any card or cancel read
  57. // 1:magnetic card swiped
  58. // 2:contact card found.If has no magnetic,ATR should been put in magTracks[0].data,also set magTracks[0].size
  59. // 4:contactless card found.If has no magnetic,ATS should been put in magTracks[0].data,also set magTracks[0].size
  60. // 5: detect card in IC slot,but can't active it. the card may be don't have ic part
  61. // 6: detect ID Card
  62. // 7: magnetic card swiped,but!!!the checkcode is wrong!
  63. virtual ErrorCodeEnum QueryCardStatus(const DWORD dwPos,int &iStatus,MagTracks &magTracks) = 0;
  64. //
  65. // Read data from magnetic track(don't use for currently).
  66. //
  67. virtual ErrorCodeEnum MagRead(MagTracks &magTracks) = 0;
  68. //
  69. // Active contact IC card
  70. //
  71. virtual ErrorCodeEnum ActiveICCard() = 0;
  72. //
  73. // Active contactless IC card(Type A,B,Mifare)
  74. // The first,second,third activation order decided by fstType,scdType,thdType respectively
  75. // fstType,scdType,thdType can be one of 'A','B','M','0'(30H,no type)
  76. // outType indicates the type of activation result
  77. //
  78. virtual ErrorCodeEnum ActiveContactlessICCard(char fstType,char scdType,char thdType,char &outType) = 0;
  79. //
  80. // Move IC card to contact position
  81. //
  82. virtual ErrorCodeEnum ContactIC() = 0;
  83. //
  84. // Release IC contact
  85. //
  86. virtual ErrorCodeEnum ReleaseIC() = 0;
  87. //
  88. // Deactivate contact IC card
  89. //
  90. virtual ErrorCodeEnum DeactivateICCard() = 0;
  91. //
  92. // Deactivate contactless IC card
  93. //
  94. virtual ErrorCodeEnum DeactContactlessICCard() = 0;
  95. //
  96. // Warm reset card(IC)
  97. //
  98. virtual ErrorCodeEnum WarmReset() = 0;
  99. //
  100. // APDU:Application Protocol Data Unit
  101. // CmdSend.lpCmd:Command-APDU
  102. // CmdRecv.lpData:Response-APDU
  103. //
  104. virtual ErrorCodeEnum ICCommand(CmdInfo sendBuf,CmdInfo &recvBuf) = 0;
  105. //
  106. // Mifare operation
  107. // Arguments:
  108. // - eFunType:function type as load key,authentication and so on
  109. // - sendBuf:[parameter(hex)][data(hex)]
  110. // - recvBuf:[status(1byte)][return data(hex)]
  111. // -- [eFunType],[parameter,data],[status(1byte),return data]
  112. // -- [CI_MIFARE_LOAD_KEY],[key select(1byte),sector num(1byte),uncoded keys(6bytes)],[status(1byte)]
  113. // -- [CI_MIFARE_AUTH],[key select(1byte),sector num(1byte)],[status(1byte)]
  114. // -- [CI_MIFARE_READ],[block num(1byte)],[status(1byte),data(16bytes)]
  115. // -- [CI_MIFARE_WRITE],[block num(1byte),data(16bytes)],[status(1byte)]
  116. // -- [CI_MIFARE_INC],[source block num(1byte),destination block num(1byte),inc value(4bytes)],[status(1byte)]
  117. // -- [CI_MIFARE_DEC],[source block num(1byte),destination block num(1byte),dec value(4bytes)],[status(1byte)]
  118. virtual ErrorCodeEnum MifareCommand(MifareFuctionEnum eFunType,CmdInfo sendBuf,CmdInfo &recvBuf) = 0;
  119. //
  120. // RF Type A,B command.
  121. // APDU:Application Protocol Data Unit
  122. // Arguments:
  123. // - CmdSend.lpCmd:Command-APDU
  124. // - CmdRecv.lpData:Response-APDU
  125. //
  126. virtual ErrorCodeEnum RFTypeABCommand(CmdInfo sendBuf,CmdInfo &recvBuf) = 0;
  127. //
  128. // Get key pair.
  129. // Generate a pair of key to encrypt data(using SM2).
  130. // priKey:private key; priSize:size of private key; pubKey:public key; pubSize:size of public key
  131. // priKey&pubKey both in ASCII style of HEX. 0x123456FFAB --> "123456FFAB"
  132. //
  133. virtual ErrorCodeEnum GetKeyPair(char *&priKey,int &priSize,char *&pubKey,int &pubSize) = 0;
  134. //
  135. // Load private key to machine.
  136. //
  137. virtual ErrorCodeEnum LoadPrivateKey(const char *pKey,const int size) = 0;
  138. //
  139. // Send random number to machine.
  140. // pRandomNum:random number(16 byte currently),in ASCII(32 byte of char)
  141. // pRamChk:first 16 byte of encrypted random number using SM3,in ASCII(32 byte of char)
  142. // pData:serial number(8 byte of char,ex:"14400001")
  143. //
  144. virtual ErrorCodeEnum SendRandomNum(const char *pRandomNum,const char *pRamChk,char *&pData) = 0;
  145. //
  146. // Save working key to memory.
  147. // pWorkingKey:working key value,in ASCII style of HEX: 0x123456FFAB --> "123456FFAB"
  148. virtual ErrorCodeEnum SendWorkingKey(const char *pWorkingKey) = 0;
  149. //
  150. // Get device serial number.
  151. // 设备唯一标识,且需贴在设备外壳上
  152. virtual ErrorCodeEnum GetDeviceSN(char *&pDevSN) = 0;
  153. // 返回值Error_Succeed表示成功,其他值表示失败
  154. // iStatus 0:成功 -1:银行公钥不存在 -2:产生设备密钥故障 -x:其他厂商自定义故障
  155. // Cr1:随机数r1的密文; Cr3:随机数r3的密文,dKey:用银行公钥加密的设备公钥密文
  156. // r1,r3第16字节为数据完整性校验字节,例如r1为B1B2...B15B16,则B16=B1^B2^...^B15
  157. virtual ErrorCodeEnum TransferEnInit(int &iStatus, BYTE *&Cr1, int &lenR1, BYTE *&Cr3, int &lenR3, BYTE *&dKey, int &lenKey) = 0;
  158. // 返回值Error_Succeed表示成功,其他值表示失败
  159. // iStatus 0:成功 -x:厂商自定义故障
  160. // r2第16字节为数据完整性校验字节,例如r2为B1B2...B15B16,则B16=B1^B2^...^B15
  161. virtual ErrorCodeEnum SetR2(int &iStatus, BYTE *pCr2, int lenR2) = 0;
  162. //
  163. // 查询设备是否掉线
  164. // bOn = 1表示设备在线,bOn = 0表示设备断开(掉线),返回Error_succeed
  165. virtual ErrorCodeEnum IfDevOnline(int &bOn) = 0;
  166. //
  167. // 移动卡片,吐卡ePos取值为CI_MOVECARD_FRONT_GATE
  168. //
  169. virtual ErrorCodeEnum EjectCard(CardPosEnum ePos){return Error_Succeed;}
  170. // 调用打开设备(蓝牙版)
  171. // 1. btOpenType:设定通过哪种方式连接设备,由DevOpenType的枚举值组合。usb及蓝牙设备连接可忽略dwPort,dwBaudRate
  172. // 2.通过pDevSN来指定连接对应设备号的蓝牙多合一
  173. // 例如通过蓝牙或者usb连接设备,则btOpenType = (DEV_OPEN_TYPE_USB|DEV_OPEN_TYPE_BLUETOOTH)
  174. // 3. btType返回设备实际通过哪种方式相连,返回值参考DevOpenType
  175. virtual ErrorCodeEnum DevOpenEx(DWORD dwPort, DWORD dwBaudRate, BYTE btOpenType,const char *pDevSN, BYTE &btType){return Error_NotImpl;}
  176. // 获取多合一剩余电量(蓝牙版)
  177. // --FWBStatus.BatteryLeft:剩余电量,取值为0~100
  178. virtual ErrorCodeEnum GetBatteryStatus(FWBStatus &status){return Error_NotImpl;}
  179. };
  180. #endif //__CARD_SWIPER_CLASS_H