DLCCard.h
3.12 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
/* ×÷ÕߣºÁõÒ°
*
**/
#ifndef DLC_CARD_H
#define DLC_CARD_H
#include "stdafx.h"
#include "DLCDevice.h"
enum CardManufacturer
{
kCardZXRC = 0x00,
kCardJFYT = 0x10,
kCardHS = 0x20,
kCardMTLTLD = 0x30,
kCardKDZN = 0x40,
kCardNULL = 0xff
};
enum KeyType
{
kDEAK = 0,
kDAMK = 1,
kDCCK = 2
};
enum FileType
{
kFTMF = 0,
kFTDDF = 1,
kFTADF = 2,
kFTEF = 3,
kFTKF = 4
};
class DLCCard
{
public:
DLCCard();
~DLCCard();
static DLCCard& Instance();
int ReadCardData(const unsigned char* dir, const unsigned char file_id, const unsigned int data_offset, const unsigned short data_len, const unsigned char* key, unsigned char* data) const;
int WriteCardData(const unsigned char* dir, const unsigned char file_id, const unsigned char data_offset, const unsigned short data_len, const unsigned char* key, const unsigned char* data) const;
int InstallCardKey(const unsigned char* dir, const unsigned char key_id, const unsigned char* key_main, const int key_type, const unsigned char* key) const;
int AuthenticationCardKey(const unsigned char* dir, const unsigned char key_id, const unsigned char* key) const;
int CreatCardFile(const unsigned char* parent_dir, const unsigned char* parent_key, const unsigned char* file_name, const unsigned char* file_size, const int file_type) const;
int GetRandom(unsigned char* random, const unsigned char random_len) const;
int SelectDir(const unsigned char* dir) const;
int ExternalAuthenticate(const unsigned char key_id, const unsigned char* key, const unsigned char* random) const;
int SelectCardDir(const unsigned char* dir) const;
int SOGetRandom(unsigned char* get_randam_cmd) const;
int SOAuthenticationKey(const unsigned char key_id, const unsigned char* key, const unsigned char* random, unsigned char* cmd) const;
int SOReadData(const unsigned int data_offfset, const unsigned int data_len, unsigned char* cmd) const;
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;
int SOSelectDir(const unsigned char* dir, unsigned char* cmd) const;
private:
CardManufacturer CheckCardMF() const;
int ReadData(const unsigned short data_offset, const short data_len, unsigned char* data) const;
int CalculateMac(const unsigned char* data, const short data_len, const unsigned char* random, const unsigned char* key, unsigned char* mac) const;
int InstallKey(unsigned char* cmd, unsigned char cmd_len) const;
int WriteData(unsigned char* cmd, unsigned char cmd_len, bool is_need_recv, unsigned char* recv, unsigned char* recv_len) const;
int Encrypt(const unsigned char* src, unsigned char len, const unsigned char* key, unsigned char* ciphert_text) const;
int FirstInstallKey(const unsigned char* dir_hex, const unsigned char key_id, const unsigned char key_type, const unsigned char* main_key, const unsigned char* key) const;
//DLCDevice m_cDevice;
unsigned char select_cmd_[5];
unsigned char read_cmd_[2];
unsigned char write_cmd_[2];
unsigned char get_random_[4];
unsigned char external_authenticate_[3];
unsigned char install_key_cmd_[5];
};
#endif //end DLC_CARD_H