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