summaryrefslogtreecommitdiff
path: root/teeif.h
blob: 2e04ea3a233d3539cdd925587eff634f68d936ca (plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
 *
 * Samsung DisplayPort driver.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
#ifndef __EXYNOS_HDCP2_TEEIF_H__
#define __EXYNOS_HDCP2_TEEIF_H__

#include <linux/types.h>

/* SMC list for HDCP functions */
#define SMC_HDCP_INIT			((unsigned int)0x82004010)
#define SMC_HDCP_TERMINATE		((unsigned int)0x82004011)
#define SMC_HDCP_PROT_MSG		((unsigned int)0x82004012)
#define SMC_CHECK_STREAM_TYPE_FLAG	((unsigned int)0x82004022)
#define SMC_HDCP_NOTIFY_INTR_NUM	((unsigned int)0x82004023)

#define SMC_DRM_HDCP_AUTH_INFO		((unsigned int)0x82002140)
#define SMC_DRM_HDCP_FUNC_TEST		((unsigned int)0x82002141)
#define SMC_DRM_DP_CONNECT_INFO		((unsigned int)0x82002142)

/**
 * HDCP TEE service commands
 */
enum {
	HDCP_TEEI_GEN_RTX = 0x0,
	HDCP_TEEI_VERIFY_CERT,
	HDCP_TEEI_GEN_MKEY,
	HDCP_TEEI_COMPARE_AKE_HMAC,
	HDCP_TEEI_GEN_RN,
	HDCP_TEEI_COMPARE_LC_HMAC,
	HDCP_TEEI_GEN_RIV,
	HDCP_TEEI_GEN_SKEY,
	HDCP_TEEI_SET_PAIRING_INFO,
	HDCP_TEEI_GET_PAIRING_INFO,
	HDCP_TEEI_SET_RCV_ID_LIST,
	HDCP_TEEI_GEN_STREAM_MANAGE,
	HDCP_TEEI_VERIFY_M_PRIME,
	HDCP_TEEI_KSV_EXCHANGE,
	HDCP_TEEI_VERIFY_R_PRIME,
	HDCP_TEEI_VERIFY_V_PRIME,
	HDCP_TEEI_MSG_END
};

#define HCI_DISCONNECTED	0
#define HCI_CONNECTED		1

#define HDCP_WSM_SIZE	(1024)
#define AKE_INFO_SIZE	(128)

#define HDCP_BINFO_DEVS_COUNT_MAX       (0x7F)
#define HDCP_BINFO_SIZE                 (2)
#define HDCP_SHA1_SIZE                  (20)
#define HDCP_KSV_SIZE                   (5)
#define HDCP_KSV_MAX_LEN                (HDCP_KSV_SIZE * HDCP_BINFO_DEVS_COUNT_MAX)
#define HDCP_SHA1_MAX_INPUT_LEN         (HDCP_BINFO_SIZE + HDCP_KSV_MAX_LEN + HDCP_M0_SIZE)
#define HDCP_RX_MODULUS_LEN		(1024 / 8)
#define HDCP_RX_PUB_EXP_LEN		(24 / 8)
#define HDCP_AKE_ENCKEY_BYTE_LEN	(1024 / 8)
#define HDCP_AKE_MKEY_BYTE_LEN		(128 / 8)
#define HDCP_AKE_M_BYTE_LEN		HDCP_AKE_MKEY_BYTE_LEN
#define HDCP_AKE_EKH_MKEY_BYTE_LEN	HDCP_AKE_MKEY_BYTE_LEN
#define	HDCP_AKE_RTX_BYTE_LEN		(64 / 8)
#define HDCP_AKE_HMAC_APPEND		(6)
#define HDCP_STR_CTR_LEN		(4)
#define HDCP_INPUT_CTR_LEN		(8)
#define RECEIVER_ID_BYTE_LEN		(40 / 8)
#define HDCP_RRX_BYTE_LEN		(64 / 8)
#define HDCP_RTX_BYTE_LEN		HDCP_RRX_BYTE_LEN
#define HDCP_HMAC_SHA256_LEN         	(256 / 8)
#define HDCP_WRAP_APPEND_LEN		(92)
#define HDCP_RX_CERT_LEN		(522)
#define HDCP_AKE_WRAPPED_HMAC_LEN	(32)
#define HDCP_AKE_WKEY_BYTE_LEN		(32)
#define HDCP_SKE_SKEY_LEN		(128 / 8)
#define HDCP_SKE_WSKEY_BYTE_LEN		(32)
#define MKEY_LEN			(16)
#define CERT_LEN			(128)
#define HMAC_LEN			(32)
#define HDCP_RX_CERT_INFO_LEN		(138)
#define HDCP_CERT_SIGLEN		(384)
#define HDCP_RN_BYTE_LEN		(64 / 8)
#define HDCP_RIV_BYTE_LEN		(64 / 8)
#define HDCP_CAPS_BYTE_LEN		(3)
#define HDCP_VERSION_LEN		(1)
#define HDCP_CAPABILITY_MASK_LEN	(2)
#define HDCP_RP_HMAC_V_LEN		HDCP_HMAC_SHA256_LEN
#define HDCP_RP_HMAC_M_LEN		HDCP_HMAC_SHA256_LEN
#define HDCP_RP_RX_INFO_LEN		(2)
#define HDCP_RP_SEQ_NUM_V_LEN		(3)
#define HDCP_RCV_ID_LEN                 (5)
#define HDCP_RCV_DEVS_COUNT_MAX         (32)
#define HDCP_RP_RCVID_LIST_LEN		(HDCP_RCV_ID_LEN * HDCP_RCV_DEVS_COUNT_MAX)
#define HDCP_RP_SEQ_NUM_M_LEN		(3)
#define HDCP_RP_K_LEN			(2)
#define HDCP_RP_MAX_STREAMID_NUM	(63)
#define HDCP_RP_TYPE_LEN		(1)
#define HDCP_RP_STREAMID_LEN		(1)
#define HDCP_RP_STREAM_MSG_MAX_LEN	(32 * 8)
#define HDCP_RP_STREAMID_TYPE_LEN	(HDCP_RP_STREAMID_LEN + HDCP_RP_TYPE_LEN)
#define HDCP_RP_MAX_STREAMID_TYPE_LEN	(HDCP_RP_STREAMID_TYPE_LEN * HDCP_RP_MAX_STREAMID_NUM)
#define HDCP_STATIC_KEY			(16)
#define HDCP_WRAP_KEY			(16)
#define HDCP_WRAP_MAX_SIZE		(128)
#define HDCP_WRAP_AUTH_TAG		(16)
#define HDCP_RX_CAPS_LEN		(1)

/* TEEI error code */
enum hdcp_rv_t  {
	HDCP_OK				= 0x0000,
	E_HDCP_PRO_INVALID_RCV_ID	= 0x3015,
};

enum kw_mode {
        WRAP,
        UNWRAP,
};

typedef struct {
	uint32_t id;
	uint32_t len;
	uint32_t lk_type;
	uint8_t rtx[HDCP_RTX_BYTE_LEN];
	uint8_t tx_caps[HDCP_CAPS_BYTE_LEN];
} hci_genrtx_t;

typedef struct {
	uint32_t id;
	uint8_t version[HDCP_VERSION_LEN];
	uint8_t caps_mask[HDCP_CAPABILITY_MASK_LEN];
} hci_gettxinfo_t;

typedef struct {
	uint32_t id;
	uint32_t len;
	uint8_t cert[HDCP_RX_CERT_LEN];
	uint8_t rrx[HDCP_RRX_BYTE_LEN];
	uint8_t rx_caps[HDCP_CAPS_BYTE_LEN];
} hci_verifycert_t;

typedef struct {
	uint32_t id;
	uint8_t version[HDCP_VERSION_LEN];
	uint8_t caps_mask[HDCP_CAPABILITY_MASK_LEN];
} hci_setrxinfo_t;

typedef struct {
	uint32_t id;
	uint32_t lk_type;
	uint32_t emkey_len;
	uint8_t emkey[HDCP_AKE_ENCKEY_BYTE_LEN];
} hci_genmkey_t;

typedef struct {
	uint32_t id;
	uint32_t rx_hmac_len;
	uint8_t rx_hmac[HDCP_HMAC_SHA256_LEN];
} hci_comphmac_t;

typedef struct {
	uint32_t id;
	uint8_t ekh_mkey[HDCP_AKE_EKH_MKEY_BYTE_LEN];
} hci_setpairing_t;

typedef struct {
	uint32_t id;
	uint8_t ekh_mkey[HDCP_AKE_EKH_MKEY_BYTE_LEN];
	uint8_t m[HDCP_AKE_M_BYTE_LEN];
	uint8_t found;
} hci_getpairing_t;

typedef struct {
	uint32_t id;
	uint32_t len;
	uint8_t rn[HDCP_RN_BYTE_LEN];
} hci_genrn_t;

typedef struct {
	uint32_t id;
	uint32_t rx_hmac_len;
	uint8_t rx_hmac[HDCP_HMAC_SHA256_LEN];
} hci_complchmac_t;

typedef struct {
	uint32_t id;
	uint32_t len;
	uint8_t riv[HDCP_RIV_BYTE_LEN];
} hci_genriv_t;

typedef struct {
	uint32_t id;
	uint32_t lk_type;
	uint8_t eskey[HDCP_SKE_SKEY_LEN];
	uint32_t eskey_len;
	int share_skey;
} hci_genskey_t;

typedef struct {
	uint32_t id;
	uint8_t rx_info[HDCP_RP_RX_INFO_LEN];
	uint8_t seq_num_v[HDCP_RP_SEQ_NUM_V_LEN];
	uint8_t v_prime[HDCP_RP_HMAC_V_LEN / 2];
	uint8_t rcvid_lst[HDCP_RP_RCVID_LIST_LEN];
	uint8_t v[HDCP_RP_HMAC_V_LEN / 2];
} hci_setrcvlist_t;

typedef struct {
	uint32_t id;
	uint16_t stream_num;
	uint8_t streamid[HDCP_RP_MAX_STREAMID_NUM];
	uint8_t seq_num_m[HDCP_RP_SEQ_NUM_M_LEN];
	uint8_t k[HDCP_RP_K_LEN];
	uint8_t streamid_type[HDCP_RP_STREAMID_TYPE_LEN];
} hci_genstreaminfo_t;

typedef struct {
	uint32_t id;
	uint8_t m_prime[HDCP_RP_HMAC_M_LEN];
	uint8_t strmsg[HDCP_RP_STREAM_MSG_MAX_LEN];
	uint32_t str_len;
} hci_verifymprime_t;

typedef struct {
	uint32_t id;
	uint64_t bksv;
	uint64_t an;
	uint64_t aksv;
	uint32_t is_repeater;
} hci_ksvexchange_t;

typedef struct {
	uint32_t id;
	uint16_t r_prime;
} hci_verifyrprime_t;

typedef struct {
	uint32_t id;
	uint32_t ksv_len;
	uint16_t binfo;
	uint8_t ksv[HDCP_KSV_MAX_LEN];
	uint8_t v_prime[HDCP_SHA1_SIZE];
} hci_verifyvprime_t;

/* todo: define WSM message format for AKE */
struct hci_message {
	union {
		uint32_t cmd_id;
		hci_genrtx_t genrtx;
		hci_gettxinfo_t gettxinfo;
		hci_verifycert_t vfcert;
		hci_setrxinfo_t setrxinfo;
		hci_genmkey_t genmkey;
		hci_comphmac_t comphmac;
		hci_setpairing_t setpairing;
		hci_getpairing_t getpairing;
		hci_genrn_t genrn;
		hci_complchmac_t complchmac;
		hci_genriv_t genriv;
		hci_genskey_t genskey;
		hci_setrcvlist_t setrcvlist;
		hci_genstreaminfo_t genstrminfo;
		hci_verifymprime_t verifymprime;
		hci_ksvexchange_t ksvexchange;
		hci_verifyrprime_t verifyrprime;
		hci_verifyvprime_t verifyvprime;
		uint8_t data[HDCP_WSM_SIZE];
	};
};

struct hci_ctx {
	struct hci_message *msg;
	uint8_t state;
};

enum hdcp_auth_cmd {
	HDCP_CMD_AUTH_RESP = (1U << 31),
	HDCP_CMD_REINIT = 0,
	HDCP_CMD_PROTOCOL,
	HDCP_CMD_ENCRYPTION_SET,
	HDCP_CMD_ENCRYPTION_GET,
	HDCP_CMD_AUTH_MANUAL_START,
	HDCP_CMD_SESSION_SET,
	HDCP_CMD_SET_TEST_MODE,
	HDCP_CMD_CONNECT_INFO,
};

void hdcp_tee_init(void);
int hdcp_tee_open(void);
int hdcp_tee_close(void);
int hdcp_tee_enable_enc_22(void);
int hdcp_tee_enable_enc_13(void);
int hdcp_tee_disable_enc(void);
int hdcp_tee_send_cmd(uint32_t cmd);
int hdcp_tee_check_protection(int* version);
int hdcp_tee_set_test_mode(bool enable);
int hdcp_tee_connect_info(int connect_info);

/* HDCP TEE interfaces */
int teei_gen_rtx(uint32_t lk_type,
		uint8_t *rtx,
		size_t rtx_len,
		uint8_t *caps,
		uint32_t caps_len);
int teei_verify_cert(uint8_t *cert, size_t cert_len,
		uint8_t *rrx, size_t rrx_len,
		uint8_t *rx_caps, size_t rx_caps_len);
int teei_generate_master_key(uint32_t lk_type,
			uint8_t *emkey, size_t emkey_len);
int teei_compare_ake_hmac(uint8_t *hmac, size_t hamc_len);
int teei_set_pairing_info(uint8_t *ekh_mkey, size_t ekh_mkey_len);
int teei_get_pairing_info(uint8_t *ekh_mkey, size_t ekh_mkey_len,
			uint8_t *m, size_t m_len, int* found);

/* LC interface */
int teei_gen_rn(uint8_t *out, size_t len);
int teei_compare_lc_hmac(uint8_t *rx_hmac, size_t rx_hmac_len);
int teei_generate_riv(uint8_t *out, size_t len);
int teei_generate_skey(uint32_t lk_type,
		uint8_t *eskey, size_t eskey_len,
		int share_skey);

/* Repeater Auth interface */
int teei_set_rcvlist_info(uint8_t *rx_info,
		uint8_t *seq_num_v,
		uint8_t *v_prime,
		uint8_t *rcvid_list,
		uint8_t *v,
		uint8_t *valid);
int teei_gen_stream_manage(uint16_t stream_num,
		uint8_t *streamid,
		uint8_t *seq_num_m,
		uint8_t *k,
		uint8_t *streamid_type);
int teei_verify_m_prime(uint8_t *m_prime, uint8_t *input, size_t input_len);

int teei_verify_r_prime(uint16_t rprime);
int teei_ksv_exchange(uint64_t bksv, uint32_t is_repeater,
	uint64_t *aksv, uint64_t *an);
int teei_verify_v_prime(uint16_t binfo, uint8_t *ksv, uint32_t ksv_len,
	uint8_t *vprime);

#endif