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#ifndef _ZCRYPT_MSGTYPE6_H_
28#define _ZCRYPT_MSGTYPE6_H_
29
30#include <asm/zcrypt.h>
31
32#define MSGTYPE06_NAME "zcrypt_msgtype6"
33#define MSGTYPE06_VARIANT_DEFAULT 0
34#define MSGTYPE06_VARIANT_NORNG 1
35#define MSGTYPE06_VARIANT_EP11 2
36
37#define MSGTYPE06_MAX_MSG_SIZE (12*1024)
38
39
40
41
42
43
44
45
46
47struct type6_hdr {
48 unsigned char reserved1;
49 unsigned char type;
50 unsigned char reserved2[2];
51 unsigned char right[4];
52 unsigned char reserved3[2];
53 unsigned char reserved4[2];
54 unsigned char apfs[4];
55 unsigned int offset1;
56 unsigned int offset2;
57 unsigned int offset3;
58 unsigned int offset4;
59 unsigned char agent_id[16];
60
61
62
63
64
65
66 unsigned char rqid[2];
67 unsigned char reserved5[2];
68 unsigned char function_code[2];
69 unsigned char reserved6[2];
70 unsigned int ToCardLen1;
71 unsigned int ToCardLen2;
72 unsigned int ToCardLen3;
73 unsigned int ToCardLen4;
74 unsigned int FromCardLen1;
75 unsigned int FromCardLen2;
76 unsigned int FromCardLen3;
77 unsigned int FromCardLen4;
78} __packed;
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93struct type86_hdr {
94 unsigned char reserved1;
95 unsigned char type;
96 unsigned char format;
97 unsigned char reserved2;
98 unsigned char reply_code;
99 unsigned char reserved3[3];
100} __packed;
101
102#define TYPE86_RSP_CODE 0x86
103#define TYPE87_RSP_CODE 0x87
104#define TYPE86_FMT2 0x02
105
106struct type86_fmt2_ext {
107 unsigned char reserved[4];
108 unsigned char apfs[4];
109 unsigned int count1;
110 unsigned int offset1;
111 unsigned int count2;
112 unsigned int offset2;
113 unsigned int count3;
114 unsigned int offset3;
115 unsigned int count4;
116 unsigned int offset4;
117} __packed;
118
119unsigned int get_cprb_fc(struct ica_xcRB *, struct ap_message *,
120 unsigned int *, unsigned short **);
121unsigned int get_ep11cprb_fc(struct ep11_urb *, struct ap_message *,
122 unsigned int *);
123unsigned int get_rng_fc(struct ap_message *, int *, unsigned int *);
124
125#define LOW 10
126#define MEDIUM 100
127#define HIGH 500
128
129int speed_idx_cca(int);
130int speed_idx_ep11(int);
131
132
133
134
135
136
137
138static inline void rng_type6CPRB_msgX(struct ap_message *ap_msg,
139 unsigned int random_number_length,
140 unsigned int *domain)
141{
142 struct {
143 struct type6_hdr hdr;
144 struct CPRBX cprbx;
145 char function_code[2];
146 short int rule_length;
147 char rule[8];
148 short int verb_length;
149 short int key_length;
150 } __packed * msg = ap_msg->message;
151 static struct type6_hdr static_type6_hdrX = {
152 .type = 0x06,
153 .offset1 = 0x00000058,
154 .agent_id = {'C', 'A'},
155 .function_code = {'R', 'L'},
156 .ToCardLen1 = sizeof(*msg) - sizeof(msg->hdr),
157 .FromCardLen1 = sizeof(*msg) - sizeof(msg->hdr),
158 };
159 static struct CPRBX local_cprbx = {
160 .cprb_len = 0x00dc,
161 .cprb_ver_id = 0x02,
162 .func_id = {0x54, 0x32},
163 .req_parml = sizeof(*msg) - sizeof(msg->hdr) -
164 sizeof(msg->cprbx),
165 .rpl_msgbl = sizeof(*msg) - sizeof(msg->hdr),
166 };
167
168 msg->hdr = static_type6_hdrX;
169 msg->hdr.FromCardLen2 = random_number_length,
170 msg->cprbx = local_cprbx;
171 msg->cprbx.rpl_datal = random_number_length,
172 memcpy(msg->function_code, msg->hdr.function_code, 0x02);
173 msg->rule_length = 0x0a;
174 memcpy(msg->rule, "RANDOM ", 8);
175 msg->verb_length = 0x02;
176 msg->key_length = 0x02;
177 ap_msg->length = sizeof(*msg);
178 *domain = (unsigned short)msg->cprbx.domain;
179}
180
181void zcrypt_msgtype6_init(void);
182void zcrypt_msgtype6_exit(void);
183
184#endif
185