contactlessimpl.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef LIBFRAMEWORK_CONTACTLESSCARD_IMPL_H
  2. #define LIBFRAMEWORK_CONTACTLESSCARD_IMPL_H
  3. #include "RFICClass.h"
  4. #include "cmb.h"
  5. #include "PcscCall.h"
  6. #define PCSC_SUCCESS 0 // command succeeded
  7. #define PCSC_NOT_OPEN -1 // command succeeded
  8. #define PCSC_HARDWARE_ERROR -2 // command failed because of hardware error
  9. #define PCSC_TIMEOUT -3 // wait for user interaction timed out
  10. #define PCSC_PARA_ERR -4 //
  11. #define PCSC_NOT_CONN -5 //未连接卡片
  12. #define PCSC_NO_CARD -12 //
  13. #define FILE_VERSION 1
  14. class ContactlessCardImpl : public RFICClass
  15. {
  16. public:
  17. ContactlessCardImpl();
  18. ~ContactlessCardImpl();
  19. //DeviceBaseClass
  20. virtual ErrorCodeEnum DevOpen(DWORD dwPort,DWORD dwBaudRate);
  21. virtual ErrorCodeEnum GetDevCategory(DevCategoryInfo &devCategory);
  22. virtual ErrorCodeEnum Reset();
  23. virtual ErrorCodeEnum DevClose();
  24. virtual ErrorCodeEnum GetLastErr(DevErrorInfo &devErrInfo);
  25. //
  26. // Get card reader status
  27. //
  28. virtual ErrorCodeEnum GetDevStatus(RFICReaderStatus& devStatus);
  29. //
  30. // Abort current operation.
  31. //
  32. virtual ErrorCodeEnum AbortRead();
  33. //
  34. // Active contactless card(Type A,B,Mifare)
  35. // The first,second,third activation order decided by fstType,scdType,thdType respectively
  36. // fstType,scdType,thdType can be one of 'A','B','M','0'(30H,no type)
  37. // outType indicates the type of activation result
  38. //
  39. virtual ErrorCodeEnum ActiveContactlessICCard(char fstType, char scdType, char thdType, char& outType);
  40. //
  41. // Deactivate contactless IC card
  42. //
  43. virtual ErrorCodeEnum DeactContactlessICCard();
  44. //
  45. // Warm reset card(IC)
  46. //
  47. virtual ErrorCodeEnum WarmReset();
  48. //
  49. // Mifare operation
  50. // Arguments:
  51. // - eFunType:function type as load key,authentication and so on
  52. // - return/data(hex) byte order like BIG EDIAN. ex:0x12345678 --> data[i] = 0x12,data[i+1] = 0x34,data[i+2] = 0x56,data[i+3] = 0x78
  53. // - sendBuf:[parameter(hex)][data(hex)]
  54. // - recvBuf:[status(1byte)][return data(hex)]
  55. // -- [eFunType],[parameter,data],[status(1byte),return data]
  56. // -- [CI_MIFARE_LOAD_KEY],[key select(1byte),sector num(1byte),uncoded keys(6bytes)],[status(1byte)]
  57. // -- [CI_MIFARE_AUTH],[key select(1byte),sector num(1byte)],[status(1byte)]
  58. // -- [CI_MIFARE_READ],[block num(1byte)],[status(1byte),data(16bytes)]
  59. // -- [CI_MIFARE_WRITE],[block num(1byte),data(16bytes)],[status(1byte)]
  60. // -- [CI_MIFARE_INC],[source block num(1byte),destination block num(1byte),inc value(4bytes)],[status(1byte)]
  61. // -- [CI_MIFARE_DEC],[source block num(1byte),destination block num(1byte),dec value(4bytes)],[status(1byte)]
  62. // -- key select(1byte):AKey(00h),BKey(01h)
  63. // -- status(1byte):OK(00h),other error code(!00h)
  64. virtual ErrorCodeEnum MifareCommand(MifareFuctionEnum eFunType, CmdInfo sendBuf, CmdInfo& recvBuf);
  65. //
  66. // RF Type A,B command.
  67. // APDU:Application Protocol Data Unit
  68. // Arguments:
  69. // - CmdSend.lpCmd:Command-APDU
  70. // - CmdRecv.lpData:Response-APDU
  71. //
  72. virtual ErrorCodeEnum RFTypeABCommand(CmdInfo sendBuf, CmdInfo& recvBuf);
  73. //halt card
  74. //card have been halted must move from induction zone then can be found again
  75. virtual ErrorCodeEnum HaltCard();
  76. private:
  77. ErrorCodeEnum GetErrorInfo(int iCode, char* sErr, ...);
  78. DevErrorInfo m_DevErrInfo;
  79. char m_sLibPath[260];
  80. bool m_bDevOpen;
  81. bool m_bCardConn;
  82. PcscCall m_PcscCall;
  83. };
  84. #endif //LIBFRAMEWORK_CONTACTLESSCARD_IMPL_H