contactlessimpl.h 3.5 KB

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