dili_card_device.h
3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifndef ETRADECLIENT_HARDWARE_DILI_CARD_DEVICE_H_INCLUDED
#define ETRADECLIENT_HARDWARE_DILI_CARD_DEVICE_H_INCLUDED
/*Read & write device for the DILI card.
The APIs may throw exceptions when error happen. The caller side need to handle the exceptions.*/
/*
CPU卡读写器产品信息:
生产厂商:深圳市德卡科技有限公司
型号:D3
*/
#include <string>
#include <cstdint>
namespace DILICard
{
struct BasicInfo
{
std::string chip_num; // 卡面号
std::string device_id; // 卡片硬件标识(卡片内码, 卡序列号SN)
std::string type_code; // 卡片类型码(卡类型编码)
std::string issuer_code; // 发卡机构编码
std::string verify_code; // 校验码(安全码编码(3位数))
};
// 卡密钥代码
enum class KeyCode
{
kDCCK, // Card Mast KEY, 控制MF结构添加和删除
kF0015_DACK, // 应用主控子密钥, 控制应用区内结构添加和删除
kF0015_DEAK, // 外部认证密钥, 用于0015文件的读权限控制
kF0015_DAMK1, // 应用维护子密钥1, 用于0015文件的更新保护
};
template <KeyCode> inline std::string CardKeyCode();
template <> inline std::string CardKeyCode<KeyCode::kDCCK>() { return "0000"; }
template <> inline std::string CardKeyCode<KeyCode::kF0015_DACK>() { return "0000"; }
template <> inline std::string CardKeyCode<KeyCode::kF0015_DEAK>() { return "0001"; }
template <> inline std::string CardKeyCode<KeyCode::kF0015_DAMK1>() { return "0002"; }
class RWDevice
{
public:
RWDevice();
~RWDevice();
bool Connect() const;
void Disconnect() const;
bool FindCard() const; // If card found, card's serial number will be returned.
void ActivateCard(const std::string& card_sn,
const std::string& key_DCCK,
const std::string& key_F0015_DACK,
const std::string& key_F0015_DEAK,
const std::string& key_F0015_DAMK1) const;
void ResetCard(const std::string& key_DCCK, const std::string& key_F0015_DACK) const;
BasicInfo ReadCardBasicInfo() const;
std::string ReadCardServiceInfo(const std::string& key_F0015_DEAK) const;
void WriteCardServiceInfo(const std::string& key_F0015_DAMK1, const std::string& data) const;
bool AuthenticationKey(const std::string sKey) const;
int M1FindCard() const;
BasicInfo M1ReadBasicInfo() const;
int M1WriteBasicInfo(std::string card_num, std::string card_type_num, std::string market_id, std::string safe_code, std::string m1_type, std::string card_version);
enum KeyType
{
KT_DCCK = 0,
KT_DEAK,
KT_DAMK,
};
private:
std::string ReadCardFile(const std::string& dir,
char file_id,
uint32_t offset,
uint32_t length,
char key_id,
const std::string& key) const;
void WriteCardFile(const std::string& dir,
char file_id,
uint32_t offset,
char key_id,
const std::string& key,
const std::string& data) const;
void SetPassword(const std::string& dir,
char key_id,
const std::string& main_key,
const std::string& install_key,
KeyType emKeyType) const;
};
} // DILICard
#endif // ETRADECLIENT_HARDWARE_DILI_CARD_DEVICE_H_INCLUDED