Commit 301c3abb6279718397a51b832a16205524210d03

Authored by liuye
1 parent 691a0ae0

feat(dlcm):新增m1卡操作接口

dlcm/dlcm/DLCCard.cc
@@ -858,4 +858,58 @@ int DLCCard::SelectCardDir(const unsigned char* dir) const @@ -858,4 +858,58 @@ int DLCCard::SelectCardDir(const unsigned char* dir) const
858 result = SelectDir(dir_hex); 858 result = SelectDir(dir_hex);
859 859
860 return result; 860 return result;
861 -}  
862 \ No newline at end of file 861 \ No newline at end of file
  862 +}
  863 +
  864 +int DLCCard::M1AuthenticationKey(const unsigned short section, unsigned char* key) const
  865 +{
  866 + int result = kSuccess;
  867 +
  868 + do
  869 + {
  870 + if (kSuccess != DLCDevice::Instance().M1LoadKeyHex(0, (const unsigned char*)"ffffffffffff", section))
  871 + {
  872 + result = kM1LoadKeyFailed;
  873 + break;
  874 + }
  875 +
  876 + if (kSuccess != DLCDevice::Instance().M1Authentication(0, section))
  877 + {
  878 + result = kVerifyKeyFailure;
  879 + break;
  880 + }
  881 + } while (0);
  882 +
  883 + return result;
  884 +}
  885 +
  886 +int DLCCard::M1ReadCard(const unsigned short block_num, const unsigned char* data) const
  887 +{
  888 + int result = kSuccess;
  889 +
  890 + do
  891 + {
  892 + if (kSuccess != DLCDevice::Instance().M1Read(block_num, data))
  893 + {
  894 + result = kM1ReadCardFailed;
  895 + break;
  896 + }
  897 + } while (0);
  898 +
  899 + return result;
  900 +}
  901 +
  902 +int DLCCard::M1WriteCard(const unsigned short block_num, const unsigned char* data) const
  903 +{
  904 + int result = kSuccess;
  905 +
  906 + do
  907 + {
  908 + if (kSuccess != DLCDevice::Instance().M1Write(block_num, data))
  909 + {
  910 + result = kM1WriteCardFailed;
  911 + break;
  912 + }
  913 + } while (0);
  914 +
  915 + return result;
  916 +}
dlcm/dlcm/DLCCard.h
@@ -58,6 +58,10 @@ public: @@ -58,6 +58,10 @@ public:
58 int SOWriteData(const unsigned char* write_key, const unsigned char* random, const unsigned int data_offfset, const unsigned int data_len, const unsigned char* data, unsigned char* cmd) const; 58 int SOWriteData(const unsigned char* write_key, const unsigned char* random, const unsigned int data_offfset, const unsigned int data_len, const unsigned char* data, unsigned char* cmd) const;
59 int SOSelectDir(const unsigned char* dir, unsigned char* cmd) const; 59 int SOSelectDir(const unsigned char* dir, unsigned char* cmd) const;
60 60
  61 + int M1AuthenticationKey(const unsigned short section, unsigned char* key) const;
  62 + int M1ReadCard(const unsigned short block_num, const unsigned char* data) const;
  63 + int M1WriteCard(const unsigned short block_num, const unsigned char* data) const;
  64 +
61 private: 65 private:
62 66
63 CardManufacturer CheckCardMF() const; 67 CardManufacturer CheckCardMF() const;
dlcm/dlcm/DLCCardManager.cc
@@ -77,4 +77,20 @@ int __stdcall DLCSOWriteData(const unsigned char* write_key, const unsigned char @@ -77,4 +77,20 @@ int __stdcall DLCSOWriteData(const unsigned char* write_key, const unsigned char
77 int __stdcall DLCSOSelectDir(const unsigned char* dir, unsigned char* cmd) 77 int __stdcall DLCSOSelectDir(const unsigned char* dir, unsigned char* cmd)
78 { 78 {
79 return DLCCard::Instance().SOSelectDir(dir, cmd); 79 return DLCCard::Instance().SOSelectDir(dir, cmd);
  80 +}
  81 +
  82 +//for m1
  83 +DL_DLL_API int __stdcall DLCM1AuthenticationKey(const unsigned short section, unsigned char* key)
  84 +{
  85 + return DLCCard::Instance().M1AuthenticationKey(section, key);
  86 +}
  87 +
  88 +DL_DLL_API int __stdcall DLCM1ReadCard(const unsigned short block_num, const unsigned char* data)
  89 +{
  90 + return DLCCard::Instance().M1ReadCard(block_num, data);
  91 +}
  92 +
  93 +DL_DLL_API int __stdcall DLCM1WriteCard(const unsigned short block_num, const unsigned char* data)
  94 +{
  95 + return DLCCard::Instance().M1WriteCard(block_num, data);
80 } 96 }
81 \ No newline at end of file 97 \ No newline at end of file
dlcm/dlcm/DLCDevice.cc
@@ -54,6 +54,7 @@ int DLCDevice::FindAndResetCard() @@ -54,6 +54,7 @@ int DLCDevice::FindAndResetCard()
54 54
55 if (!dc_card(dev_, 0, &snr)) 55 if (!dc_card(dev_, 0, &snr))
56 { 56 {
  57 + result = kSuccessFindCard;
57 if (!dc_pro_reset(dev_, recv_data_len, recv_data)) 58 if (!dc_pro_reset(dev_, recv_data_len, recv_data))
58 { 59 {
59 result = kSuccess; 60 result = kSuccess;
@@ -107,3 +108,24 @@ int DLCDevice::FindCard() @@ -107,3 +108,24 @@ int DLCDevice::FindCard()
107 { 108 {
108 return FindAndResetCard(); 109 return FindAndResetCard();
109 } 110 }
  111 +
  112 +
  113 +int DLCDevice::M1Authentication(const unsigned char mode, const unsigned short section)
  114 +{
  115 + return dc_authentication(dev_, mode, section);
  116 +}
  117 +
  118 +int DLCDevice::M1LoadKeyHex(const unsigned char mode, const unsigned char* key, const unsigned char section)
  119 +{
  120 + return dc_load_key_hex(dev_, mode, section, (char*)key);
  121 +}
  122 +
  123 +int DLCDevice::M1Read(const unsigned char adr, const unsigned char* data)
  124 +{
  125 + return dc_read(dev_, adr, (unsigned char*)data);
  126 +}
  127 +
  128 +int DLCDevice::M1Write(const unsigned char adr, const unsigned char* data)
  129 +{
  130 + return dc_write(dev_, adr, (unsigned char*)data);
  131 +}
110 \ No newline at end of file 132 \ No newline at end of file
dlcm/dlcm/DLCDevice.h
@@ -19,6 +19,10 @@ public: @@ -19,6 +19,10 @@ public:
19 int DisconnectDevice(); 19 int DisconnectDevice();
20 int FindCard(); 20 int FindCard();
21 int SendCommand(unsigned char* send_cmd, const unsigned char send_cmd_len, unsigned char* recv_data, unsigned char& recv_data_len); 21 int SendCommand(unsigned char* send_cmd, const unsigned char send_cmd_len, unsigned char* recv_data, unsigned char& recv_data_len);
  22 + int M1Authentication(const unsigned char mode, const unsigned short section);
  23 + int M1LoadKeyHex(const unsigned char mode, const unsigned char* key, const unsigned char section);
  24 + int M1Read(const unsigned char adr, const unsigned char* data);
  25 + int M1Write(const unsigned char adr, const unsigned char* data);
22 26
23 private: 27 private:
24 int Connect(); 28 int Connect();
dlcm/dlcm/DLCardManager.h
@@ -94,4 +94,20 @@ int __stdcall DLCSOWriteData(const unsigned char* write_key, const unsigned char @@ -94,4 +94,20 @@ int __stdcall DLCSOWriteData(const unsigned char* write_key, const unsigned char
94 **/ 94 **/
95 int __stdcall DLCSOSelectDir(const unsigned char* dir, unsigned char* cmd); 95 int __stdcall DLCSOSelectDir(const unsigned char* dir, unsigned char* cmd);
96 96
  97 +
  98 +//m1卡api
  99 +/*输入section扇区编号,长度为12的16进制秘钥key
  100 + **/
  101 +DL_DLL_API int __stdcall DLCM1AuthenticationKey(const unsigned short section, unsigned char* key);
  102 +
  103 +/*读取m1卡
  104 + *输入block_num数据块编号,返回16字节数据块
  105 + */
  106 +DL_DLL_API int __stdcall DLCM1ReadCard(const unsigned short block_num, const unsigned char* data);
  107 +
  108 +/*写入m1卡
  109 + *输入block_num数据块编号,返回16字节数据块
  110 + **/
  111 +DL_DLL_API int __stdcall DLCM1WriteCard(const unsigned short block_num, const unsigned char* data);
  112 +
97 #endif //end DL_CARD_MANAGER_H 113 #endif //end DL_CARD_MANAGER_H
98 \ No newline at end of file 114 \ No newline at end of file
dlcm/dlcm/stdafx.h
@@ -46,5 +46,9 @@ const int kCardDoNotSupport = 2006; //卡片不支持 @@ -46,5 +46,9 @@ const int kCardDoNotSupport = 2006; //卡片不支持
46 const int kCreateKeyFileFailed = 2007; //创建秘钥文件失败 46 const int kCreateKeyFileFailed = 2007; //创建秘钥文件失败
47 const int kVerifyKeyFailure = 2008; //验证秘钥失败 47 const int kVerifyKeyFailure = 2008; //验证秘钥失败
48 const int kParameterIsNull = 2009; //参数为空 48 const int kParameterIsNull = 2009; //参数为空
  49 +const int kSuccessFindCard = 2010; //dc_card执行成功,dc_pro_reset失败
  50 +const int kM1LoadKeyFailed = 2011; //m1卡装载秘钥失败
  51 +const int kM1ReadCardFailed = 2018; //m1卡读取失败
  52 +const int kM1WriteCardFailed = 2019; //m1卡写入失败
49 53
50 #endif //end DL_STDAFX_H 54 #endif //end DL_STDAFX_H
51 \ No newline at end of file 55 \ No newline at end of file