1 /*
2  * Copyright 2019 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: AMD
23  *
24  */
25 
26 #include "hdcp.h"
27 
28 #define MIN(a, b) ((a) < (b) ? (a) : (b))
29 #define HDCP_I2C_ADDR 0x3a	/* 0x74 >> 1*/
30 #define KSV_READ_SIZE 0xf	/* 0x6803b - 0x6802c */
31 #define HDCP_MAX_AUX_TRANSACTION_SIZE 16
32 
33 enum mod_hdcp_ddc_message_id {
34 	MOD_HDCP_MESSAGE_ID_INVALID = -1,
35 
36 	/* HDCP 1.4 */
37 
38 	MOD_HDCP_MESSAGE_ID_READ_BKSV = 0,
39 	MOD_HDCP_MESSAGE_ID_READ_RI_R0,
40 	MOD_HDCP_MESSAGE_ID_WRITE_AKSV,
41 	MOD_HDCP_MESSAGE_ID_WRITE_AINFO,
42 	MOD_HDCP_MESSAGE_ID_WRITE_AN,
43 	MOD_HDCP_MESSAGE_ID_READ_VH_X,
44 	MOD_HDCP_MESSAGE_ID_READ_VH_0,
45 	MOD_HDCP_MESSAGE_ID_READ_VH_1,
46 	MOD_HDCP_MESSAGE_ID_READ_VH_2,
47 	MOD_HDCP_MESSAGE_ID_READ_VH_3,
48 	MOD_HDCP_MESSAGE_ID_READ_VH_4,
49 	MOD_HDCP_MESSAGE_ID_READ_BCAPS,
50 	MOD_HDCP_MESSAGE_ID_READ_BSTATUS,
51 	MOD_HDCP_MESSAGE_ID_READ_KSV_FIFO,
52 	MOD_HDCP_MESSAGE_ID_READ_BINFO,
53 
54 	/* HDCP 2.2 */
55 
56 	MOD_HDCP_MESSAGE_ID_HDCP2VERSION,
57 	MOD_HDCP_MESSAGE_ID_RX_CAPS,
58 	MOD_HDCP_MESSAGE_ID_WRITE_AKE_INIT,
59 	MOD_HDCP_MESSAGE_ID_READ_AKE_SEND_CERT,
60 	MOD_HDCP_MESSAGE_ID_WRITE_AKE_NO_STORED_KM,
61 	MOD_HDCP_MESSAGE_ID_WRITE_AKE_STORED_KM,
62 	MOD_HDCP_MESSAGE_ID_READ_AKE_SEND_H_PRIME,
63 	MOD_HDCP_MESSAGE_ID_READ_AKE_SEND_PAIRING_INFO,
64 	MOD_HDCP_MESSAGE_ID_WRITE_LC_INIT,
65 	MOD_HDCP_MESSAGE_ID_READ_LC_SEND_L_PRIME,
66 	MOD_HDCP_MESSAGE_ID_WRITE_SKE_SEND_EKS,
67 	MOD_HDCP_MESSAGE_ID_READ_REPEATER_AUTH_SEND_RECEIVERID_LIST,
68 	MOD_HDCP_MESSAGE_ID_WRITE_REPEATER_AUTH_SEND_ACK,
69 	MOD_HDCP_MESSAGE_ID_WRITE_REPEATER_AUTH_STREAM_MANAGE,
70 	MOD_HDCP_MESSAGE_ID_READ_REPEATER_AUTH_STREAM_READY,
71 	MOD_HDCP_MESSAGE_ID_READ_RXSTATUS,
72 	MOD_HDCP_MESSAGE_ID_WRITE_CONTENT_STREAM_TYPE,
73 
74 	MOD_HDCP_MESSAGE_ID_MAX
75 };
76 
77 static const uint8_t hdcp_i2c_offsets[] = {
78 	[MOD_HDCP_MESSAGE_ID_READ_BKSV] = 0x0,
79 	[MOD_HDCP_MESSAGE_ID_READ_RI_R0] = 0x8,
80 	[MOD_HDCP_MESSAGE_ID_WRITE_AKSV] = 0x10,
81 	[MOD_HDCP_MESSAGE_ID_WRITE_AINFO] = 0x15,
82 	[MOD_HDCP_MESSAGE_ID_WRITE_AN] = 0x18,
83 	[MOD_HDCP_MESSAGE_ID_READ_VH_X] = 0x20,
84 	[MOD_HDCP_MESSAGE_ID_READ_VH_0] = 0x20,
85 	[MOD_HDCP_MESSAGE_ID_READ_VH_1] = 0x24,
86 	[MOD_HDCP_MESSAGE_ID_READ_VH_2] = 0x28,
87 	[MOD_HDCP_MESSAGE_ID_READ_VH_3] = 0x2C,
88 	[MOD_HDCP_MESSAGE_ID_READ_VH_4] = 0x30,
89 	[MOD_HDCP_MESSAGE_ID_READ_BCAPS] = 0x40,
90 	[MOD_HDCP_MESSAGE_ID_READ_BSTATUS] = 0x41,
91 	[MOD_HDCP_MESSAGE_ID_READ_KSV_FIFO] = 0x43,
92 	[MOD_HDCP_MESSAGE_ID_READ_BINFO] = 0xFF,
93 	[MOD_HDCP_MESSAGE_ID_HDCP2VERSION] = 0x50,
94 	[MOD_HDCP_MESSAGE_ID_WRITE_AKE_INIT] = 0x60,
95 	[MOD_HDCP_MESSAGE_ID_READ_AKE_SEND_CERT] = 0x80,
96 	[MOD_HDCP_MESSAGE_ID_WRITE_AKE_NO_STORED_KM] = 0x60,
97 	[MOD_HDCP_MESSAGE_ID_WRITE_AKE_STORED_KM] = 0x60,
98 	[MOD_HDCP_MESSAGE_ID_READ_AKE_SEND_H_PRIME] = 0x80,
99 	[MOD_HDCP_MESSAGE_ID_READ_AKE_SEND_PAIRING_INFO] = 0x80,
100 	[MOD_HDCP_MESSAGE_ID_WRITE_LC_INIT] = 0x60,
101 	[MOD_HDCP_MESSAGE_ID_READ_LC_SEND_L_PRIME] = 0x80,
102 	[MOD_HDCP_MESSAGE_ID_WRITE_SKE_SEND_EKS] = 0x60,
103 	[MOD_HDCP_MESSAGE_ID_READ_REPEATER_AUTH_SEND_RECEIVERID_LIST] = 0x80,
104 	[MOD_HDCP_MESSAGE_ID_WRITE_REPEATER_AUTH_SEND_ACK] = 0x60,
105 	[MOD_HDCP_MESSAGE_ID_WRITE_REPEATER_AUTH_STREAM_MANAGE] = 0x60,
106 	[MOD_HDCP_MESSAGE_ID_READ_REPEATER_AUTH_STREAM_READY] = 0x80,
107 	[MOD_HDCP_MESSAGE_ID_READ_RXSTATUS] = 0x70,
108 	[MOD_HDCP_MESSAGE_ID_WRITE_CONTENT_STREAM_TYPE] = 0x0
109 };
110 
111 static const uint32_t hdcp_dpcd_addrs[] = {
112 	[MOD_HDCP_MESSAGE_ID_READ_BKSV] = 0x68000,
113 	[MOD_HDCP_MESSAGE_ID_READ_RI_R0] = 0x68005,
114 	[MOD_HDCP_MESSAGE_ID_WRITE_AKSV] = 0x68007,
115 	[MOD_HDCP_MESSAGE_ID_WRITE_AINFO] = 0x6803B,
116 	[MOD_HDCP_MESSAGE_ID_WRITE_AN] = 0x6800c,
117 	[MOD_HDCP_MESSAGE_ID_READ_VH_X] = 0x68014,
118 	[MOD_HDCP_MESSAGE_ID_READ_VH_0] = 0x68014,
119 	[MOD_HDCP_MESSAGE_ID_READ_VH_1] = 0x68018,
120 	[MOD_HDCP_MESSAGE_ID_READ_VH_2] = 0x6801c,
121 	[MOD_HDCP_MESSAGE_ID_READ_VH_3] = 0x68020,
122 	[MOD_HDCP_MESSAGE_ID_READ_VH_4] = 0x68024,
123 	[MOD_HDCP_MESSAGE_ID_READ_BCAPS] = 0x68028,
124 	[MOD_HDCP_MESSAGE_ID_READ_BSTATUS] = 0x68029,
125 	[MOD_HDCP_MESSAGE_ID_READ_KSV_FIFO] = 0x6802c,
126 	[MOD_HDCP_MESSAGE_ID_READ_BINFO] = 0x6802a,
127 	[MOD_HDCP_MESSAGE_ID_RX_CAPS] = 0x6921d,
128 	[MOD_HDCP_MESSAGE_ID_WRITE_AKE_INIT] = 0x69000,
129 	[MOD_HDCP_MESSAGE_ID_READ_AKE_SEND_CERT] = 0x6900b,
130 	[MOD_HDCP_MESSAGE_ID_WRITE_AKE_NO_STORED_KM] = 0x69220,
131 	[MOD_HDCP_MESSAGE_ID_WRITE_AKE_STORED_KM] = 0x692a0,
132 	[MOD_HDCP_MESSAGE_ID_READ_AKE_SEND_H_PRIME] = 0x692c0,
133 	[MOD_HDCP_MESSAGE_ID_READ_AKE_SEND_PAIRING_INFO] = 0x692e0,
134 	[MOD_HDCP_MESSAGE_ID_WRITE_LC_INIT] = 0x692f0,
135 	[MOD_HDCP_MESSAGE_ID_READ_LC_SEND_L_PRIME] = 0x692f8,
136 	[MOD_HDCP_MESSAGE_ID_WRITE_SKE_SEND_EKS] = 0x69318,
137 	[MOD_HDCP_MESSAGE_ID_READ_REPEATER_AUTH_SEND_RECEIVERID_LIST] = 0x69330,
138 	[MOD_HDCP_MESSAGE_ID_WRITE_REPEATER_AUTH_SEND_ACK] = 0x693e0,
139 	[MOD_HDCP_MESSAGE_ID_WRITE_REPEATER_AUTH_STREAM_MANAGE] = 0x693f0,
140 	[MOD_HDCP_MESSAGE_ID_READ_REPEATER_AUTH_STREAM_READY] = 0x69473,
141 	[MOD_HDCP_MESSAGE_ID_READ_RXSTATUS] = 0x69493,
142 	[MOD_HDCP_MESSAGE_ID_WRITE_CONTENT_STREAM_TYPE] = 0x69494
143 };
144 
145 static enum mod_hdcp_status read(struct mod_hdcp *hdcp,
146 		enum mod_hdcp_ddc_message_id msg_id,
147 		uint8_t *buf,
148 		uint32_t buf_len)
149 {
150 	bool success = true;
151 	uint32_t cur_size = 0;
152 	uint32_t data_offset = 0;
153 
154 	if (is_dp_hdcp(hdcp)) {
155 		while (buf_len > 0) {
156 			cur_size = MIN(buf_len, HDCP_MAX_AUX_TRANSACTION_SIZE);
157 			success = hdcp->config.ddc.funcs.read_dpcd(hdcp->config.ddc.handle,
158 					hdcp_dpcd_addrs[msg_id] + data_offset,
159 					buf + data_offset,
160 					cur_size);
161 
162 			if (!success)
163 				break;
164 
165 			buf_len -= cur_size;
166 			data_offset += cur_size;
167 		}
168 	} else {
169 		success = hdcp->config.ddc.funcs.read_i2c(
170 				hdcp->config.ddc.handle,
171 				HDCP_I2C_ADDR,
172 				hdcp_i2c_offsets[msg_id],
173 				buf,
174 				(uint32_t)buf_len);
175 	}
176 
177 	return success ? MOD_HDCP_STATUS_SUCCESS : MOD_HDCP_STATUS_DDC_FAILURE;
178 }
179 
180 static enum mod_hdcp_status read_repeatedly(struct mod_hdcp *hdcp,
181 		enum mod_hdcp_ddc_message_id msg_id,
182 		uint8_t *buf,
183 		uint32_t buf_len,
184 		uint8_t read_size)
185 {
186 	enum mod_hdcp_status status = MOD_HDCP_STATUS_DDC_FAILURE;
187 	uint32_t cur_size = 0;
188 	uint32_t data_offset = 0;
189 
190 	while (buf_len > 0) {
191 		cur_size = MIN(buf_len, read_size);
192 		status = read(hdcp, msg_id, buf + data_offset, cur_size);
193 
194 		if (status != MOD_HDCP_STATUS_SUCCESS)
195 			break;
196 
197 		buf_len -= cur_size;
198 		data_offset += cur_size;
199 	}
200 
201 	return status;
202 }
203 
204 static enum mod_hdcp_status write(struct mod_hdcp *hdcp,
205 		enum mod_hdcp_ddc_message_id msg_id,
206 		uint8_t *buf,
207 		uint32_t buf_len)
208 {
209 	bool success = true;
210 	uint32_t cur_size = 0;
211 	uint32_t data_offset = 0;
212 
213 	if (is_dp_hdcp(hdcp)) {
214 		while (buf_len > 0) {
215 			cur_size = MIN(buf_len, HDCP_MAX_AUX_TRANSACTION_SIZE);
216 			success = hdcp->config.ddc.funcs.write_dpcd(
217 					hdcp->config.ddc.handle,
218 					hdcp_dpcd_addrs[msg_id] + data_offset,
219 					buf + data_offset,
220 					cur_size);
221 
222 			if (!success)
223 				break;
224 
225 			buf_len -= cur_size;
226 			data_offset += cur_size;
227 		}
228 	} else {
229 		hdcp->buf[0] = hdcp_i2c_offsets[msg_id];
230 		memmove(&hdcp->buf[1], buf, buf_len);
231 		success = hdcp->config.ddc.funcs.write_i2c(
232 				hdcp->config.ddc.handle,
233 				HDCP_I2C_ADDR,
234 				hdcp->buf,
235 				(uint32_t)(buf_len+1));
236 	}
237 
238 	return success ? MOD_HDCP_STATUS_SUCCESS : MOD_HDCP_STATUS_DDC_FAILURE;
239 }
240 
241 enum mod_hdcp_status mod_hdcp_read_bksv(struct mod_hdcp *hdcp)
242 {
243 	return read(hdcp, MOD_HDCP_MESSAGE_ID_READ_BKSV,
244 			hdcp->auth.msg.hdcp1.bksv,
245 			sizeof(hdcp->auth.msg.hdcp1.bksv));
246 }
247 
248 enum mod_hdcp_status mod_hdcp_read_bcaps(struct mod_hdcp *hdcp)
249 {
250 	return read(hdcp, MOD_HDCP_MESSAGE_ID_READ_BCAPS,
251 			&hdcp->auth.msg.hdcp1.bcaps,
252 			sizeof(hdcp->auth.msg.hdcp1.bcaps));
253 }
254 
255 enum mod_hdcp_status mod_hdcp_read_bstatus(struct mod_hdcp *hdcp)
256 {
257 	enum mod_hdcp_status status;
258 
259 	if (is_dp_hdcp(hdcp))
260 		status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_BSTATUS,
261 					(uint8_t *)&hdcp->auth.msg.hdcp1.bstatus,
262 					1);
263 	else
264 		status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_BSTATUS,
265 				(uint8_t *)&hdcp->auth.msg.hdcp1.bstatus,
266 				sizeof(hdcp->auth.msg.hdcp1.bstatus));
267 	return status;
268 }
269 
270 enum mod_hdcp_status mod_hdcp_read_r0p(struct mod_hdcp *hdcp)
271 {
272 	return read(hdcp, MOD_HDCP_MESSAGE_ID_READ_RI_R0,
273 			(uint8_t *)&hdcp->auth.msg.hdcp1.r0p,
274 			sizeof(hdcp->auth.msg.hdcp1.r0p));
275 }
276 
277 /* special case, reading repeatedly at the same address, don't use read() */
278 enum mod_hdcp_status mod_hdcp_read_ksvlist(struct mod_hdcp *hdcp)
279 {
280 	enum mod_hdcp_status status;
281 
282 	if (is_dp_hdcp(hdcp))
283 		status = read_repeatedly(hdcp, MOD_HDCP_MESSAGE_ID_READ_KSV_FIFO,
284 				hdcp->auth.msg.hdcp1.ksvlist,
285 				hdcp->auth.msg.hdcp1.ksvlist_size,
286 				KSV_READ_SIZE);
287 	else
288 		status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_KSV_FIFO,
289 				(uint8_t *)&hdcp->auth.msg.hdcp1.ksvlist,
290 				hdcp->auth.msg.hdcp1.ksvlist_size);
291 	return status;
292 }
293 
294 enum mod_hdcp_status mod_hdcp_read_vp(struct mod_hdcp *hdcp)
295 {
296 	enum mod_hdcp_status status;
297 
298 	status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_VH_0,
299 			&hdcp->auth.msg.hdcp1.vp[0], 4);
300 	if (status != MOD_HDCP_STATUS_SUCCESS)
301 		goto out;
302 
303 	status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_VH_1,
304 			&hdcp->auth.msg.hdcp1.vp[4], 4);
305 	if (status != MOD_HDCP_STATUS_SUCCESS)
306 		goto out;
307 
308 	status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_VH_2,
309 			&hdcp->auth.msg.hdcp1.vp[8], 4);
310 	if (status != MOD_HDCP_STATUS_SUCCESS)
311 		goto out;
312 
313 	status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_VH_3,
314 			&hdcp->auth.msg.hdcp1.vp[12], 4);
315 	if (status != MOD_HDCP_STATUS_SUCCESS)
316 		goto out;
317 
318 	status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_VH_4,
319 			&hdcp->auth.msg.hdcp1.vp[16], 4);
320 out:
321 	return status;
322 }
323 
324 enum mod_hdcp_status mod_hdcp_read_binfo(struct mod_hdcp *hdcp)
325 {
326 	enum mod_hdcp_status status;
327 
328 	if (is_dp_hdcp(hdcp))
329 		status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_BINFO,
330 				(uint8_t *)&hdcp->auth.msg.hdcp1.binfo_dp,
331 				sizeof(hdcp->auth.msg.hdcp1.binfo_dp));
332 	else
333 		status = MOD_HDCP_STATUS_INVALID_OPERATION;
334 
335 	return status;
336 }
337 
338 enum mod_hdcp_status mod_hdcp_write_aksv(struct mod_hdcp *hdcp)
339 {
340 	return write(hdcp, MOD_HDCP_MESSAGE_ID_WRITE_AKSV,
341 			hdcp->auth.msg.hdcp1.aksv,
342 			sizeof(hdcp->auth.msg.hdcp1.aksv));
343 }
344 
345 enum mod_hdcp_status mod_hdcp_write_ainfo(struct mod_hdcp *hdcp)
346 {
347 	return write(hdcp, MOD_HDCP_MESSAGE_ID_WRITE_AINFO,
348 			&hdcp->auth.msg.hdcp1.ainfo,
349 			sizeof(hdcp->auth.msg.hdcp1.ainfo));
350 }
351 
352 enum mod_hdcp_status mod_hdcp_write_an(struct mod_hdcp *hdcp)
353 {
354 	return write(hdcp, MOD_HDCP_MESSAGE_ID_WRITE_AN,
355 			hdcp->auth.msg.hdcp1.an,
356 			sizeof(hdcp->auth.msg.hdcp1.an));
357 }
358 
359 enum mod_hdcp_status mod_hdcp_read_hdcp2version(struct mod_hdcp *hdcp)
360 {
361 	enum mod_hdcp_status status;
362 
363 	if (is_dp_hdcp(hdcp))
364 		status = MOD_HDCP_STATUS_INVALID_OPERATION;
365 	else
366 		status = read(hdcp, MOD_HDCP_MESSAGE_ID_HDCP2VERSION,
367 				&hdcp->auth.msg.hdcp2.hdcp2version_hdmi,
368 				sizeof(hdcp->auth.msg.hdcp2.hdcp2version_hdmi));
369 
370 	return status;
371 }
372 
373 enum mod_hdcp_status mod_hdcp_read_rxcaps(struct mod_hdcp *hdcp)
374 {
375 	enum mod_hdcp_status status;
376 
377 	if (!is_dp_hdcp(hdcp))
378 		status = MOD_HDCP_STATUS_INVALID_OPERATION;
379 	else
380 		status = read(hdcp, MOD_HDCP_MESSAGE_ID_RX_CAPS,
381 				hdcp->auth.msg.hdcp2.rxcaps_dp,
382 				sizeof(hdcp->auth.msg.hdcp2.rxcaps_dp));
383 
384 	return status;
385 }
386 
387 enum mod_hdcp_status mod_hdcp_read_rxstatus(struct mod_hdcp *hdcp)
388 {
389 	enum mod_hdcp_status status;
390 
391 	if (is_dp_hdcp(hdcp)) {
392 		status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_RXSTATUS,
393 				&hdcp->auth.msg.hdcp2.rxstatus_dp,
394 				1);
395 	} else {
396 		status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_RXSTATUS,
397 					(uint8_t *)&hdcp->auth.msg.hdcp2.rxstatus,
398 					sizeof(hdcp->auth.msg.hdcp2.rxstatus));
399 	}
400 	return status;
401 }
402 
403 enum mod_hdcp_status mod_hdcp_read_ake_cert(struct mod_hdcp *hdcp)
404 {
405 	enum mod_hdcp_status status;
406 
407 	if (is_dp_hdcp(hdcp)) {
408 		hdcp->auth.msg.hdcp2.ake_cert[0] = 3;
409 		status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_AKE_SEND_CERT,
410 				hdcp->auth.msg.hdcp2.ake_cert+1,
411 				sizeof(hdcp->auth.msg.hdcp2.ake_cert)-1);
412 
413 	} else {
414 		status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_AKE_SEND_CERT,
415 					hdcp->auth.msg.hdcp2.ake_cert,
416 					sizeof(hdcp->auth.msg.hdcp2.ake_cert));
417 	}
418 	return status;
419 }
420 
421 enum mod_hdcp_status mod_hdcp_read_h_prime(struct mod_hdcp *hdcp)
422 {
423 	enum mod_hdcp_status status;
424 
425 	if (is_dp_hdcp(hdcp)) {
426 		hdcp->auth.msg.hdcp2.ake_h_prime[0] = 7;
427 		status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_AKE_SEND_H_PRIME,
428 				hdcp->auth.msg.hdcp2.ake_h_prime+1,
429 				sizeof(hdcp->auth.msg.hdcp2.ake_h_prime)-1);
430 
431 	} else {
432 		status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_AKE_SEND_H_PRIME,
433 				hdcp->auth.msg.hdcp2.ake_h_prime,
434 				sizeof(hdcp->auth.msg.hdcp2.ake_h_prime));
435 	}
436 	return status;
437 }
438 
439 enum mod_hdcp_status mod_hdcp_read_pairing_info(struct mod_hdcp *hdcp)
440 {
441 	enum mod_hdcp_status status;
442 
443 	if (is_dp_hdcp(hdcp)) {
444 		hdcp->auth.msg.hdcp2.ake_pairing_info[0] = 8;
445 		status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_AKE_SEND_PAIRING_INFO,
446 				hdcp->auth.msg.hdcp2.ake_pairing_info+1,
447 				sizeof(hdcp->auth.msg.hdcp2.ake_pairing_info)-1);
448 
449 	} else {
450 		status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_AKE_SEND_PAIRING_INFO,
451 				hdcp->auth.msg.hdcp2.ake_pairing_info,
452 				sizeof(hdcp->auth.msg.hdcp2.ake_pairing_info));
453 	}
454 	return status;
455 }
456 
457 enum mod_hdcp_status mod_hdcp_read_l_prime(struct mod_hdcp *hdcp)
458 {
459 	enum mod_hdcp_status status;
460 
461 	if (is_dp_hdcp(hdcp)) {
462 		hdcp->auth.msg.hdcp2.lc_l_prime[0] = 10;
463 		status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_LC_SEND_L_PRIME,
464 				hdcp->auth.msg.hdcp2.lc_l_prime+1,
465 				sizeof(hdcp->auth.msg.hdcp2.lc_l_prime)-1);
466 
467 	} else {
468 		status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_LC_SEND_L_PRIME,
469 				hdcp->auth.msg.hdcp2.lc_l_prime,
470 				sizeof(hdcp->auth.msg.hdcp2.lc_l_prime));
471 	}
472 	return status;
473 }
474 
475 enum mod_hdcp_status mod_hdcp_read_rx_id_list(struct mod_hdcp *hdcp)
476 {
477 	enum mod_hdcp_status status;
478 
479 	if (is_dp_hdcp(hdcp)) {
480 		hdcp->auth.msg.hdcp2.rx_id_list[0] = 12;
481 		status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_REPEATER_AUTH_SEND_RECEIVERID_LIST,
482 				hdcp->auth.msg.hdcp2.rx_id_list+1,
483 				sizeof(hdcp->auth.msg.hdcp2.rx_id_list)-1);
484 
485 	} else {
486 		status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_REPEATER_AUTH_SEND_RECEIVERID_LIST,
487 				hdcp->auth.msg.hdcp2.rx_id_list,
488 				hdcp->auth.msg.hdcp2.rx_id_list_size);
489 	}
490 	return status;
491 }
492 
493 enum mod_hdcp_status mod_hdcp_read_stream_ready(struct mod_hdcp *hdcp)
494 {
495 	enum mod_hdcp_status status;
496 
497 	if (is_dp_hdcp(hdcp)) {
498 		hdcp->auth.msg.hdcp2.repeater_auth_stream_ready[0] = 17;
499 		status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_REPEATER_AUTH_STREAM_READY,
500 				hdcp->auth.msg.hdcp2.repeater_auth_stream_ready+1,
501 				sizeof(hdcp->auth.msg.hdcp2.repeater_auth_stream_ready)-1);
502 
503 	} else {
504 		status = read(hdcp, MOD_HDCP_MESSAGE_ID_READ_REPEATER_AUTH_STREAM_READY,
505 				hdcp->auth.msg.hdcp2.repeater_auth_stream_ready,
506 				sizeof(hdcp->auth.msg.hdcp2.repeater_auth_stream_ready));
507 	}
508 	return status;
509 }
510 
511 enum mod_hdcp_status mod_hdcp_write_ake_init(struct mod_hdcp *hdcp)
512 {
513 	enum mod_hdcp_status status;
514 
515 	if (is_dp_hdcp(hdcp))
516 		status = write(hdcp, MOD_HDCP_MESSAGE_ID_WRITE_AKE_INIT,
517 				hdcp->auth.msg.hdcp2.ake_init+1,
518 				sizeof(hdcp->auth.msg.hdcp2.ake_init)-1);
519 	else
520 		status = write(hdcp, MOD_HDCP_MESSAGE_ID_WRITE_AKE_INIT,
521 					hdcp->auth.msg.hdcp2.ake_init,
522 					sizeof(hdcp->auth.msg.hdcp2.ake_init));
523 	return status;
524 }
525 
526 enum mod_hdcp_status mod_hdcp_write_no_stored_km(struct mod_hdcp *hdcp)
527 {
528 	enum mod_hdcp_status status;
529 
530 	if (is_dp_hdcp(hdcp))
531 		status = write(hdcp, MOD_HDCP_MESSAGE_ID_WRITE_AKE_NO_STORED_KM,
532 				hdcp->auth.msg.hdcp2.ake_no_stored_km+1,
533 				sizeof(hdcp->auth.msg.hdcp2.ake_no_stored_km)-1);
534 	else
535 		status = write(hdcp, MOD_HDCP_MESSAGE_ID_WRITE_AKE_NO_STORED_KM,
536 			hdcp->auth.msg.hdcp2.ake_no_stored_km,
537 			sizeof(hdcp->auth.msg.hdcp2.ake_no_stored_km));
538 	return status;
539 }
540 
541 enum mod_hdcp_status mod_hdcp_write_stored_km(struct mod_hdcp *hdcp)
542 {
543 	enum mod_hdcp_status status;
544 
545 	if (is_dp_hdcp(hdcp))
546 		status = write(hdcp, MOD_HDCP_MESSAGE_ID_WRITE_AKE_STORED_KM,
547 				hdcp->auth.msg.hdcp2.ake_stored_km+1,
548 				sizeof(hdcp->auth.msg.hdcp2.ake_stored_km)-1);
549 	else
550 		status = write(hdcp, MOD_HDCP_MESSAGE_ID_WRITE_AKE_STORED_KM,
551 				hdcp->auth.msg.hdcp2.ake_stored_km,
552 				sizeof(hdcp->auth.msg.hdcp2.ake_stored_km));
553 	return status;
554 }
555 
556 enum mod_hdcp_status mod_hdcp_write_lc_init(struct mod_hdcp *hdcp)
557 {
558 	enum mod_hdcp_status status;
559 
560 	if (is_dp_hdcp(hdcp))
561 		status = write(hdcp, MOD_HDCP_MESSAGE_ID_WRITE_LC_INIT,
562 				hdcp->auth.msg.hdcp2.lc_init+1,
563 				sizeof(hdcp->auth.msg.hdcp2.lc_init)-1);
564 	else
565 		status = write(hdcp, MOD_HDCP_MESSAGE_ID_WRITE_LC_INIT,
566 				hdcp->auth.msg.hdcp2.lc_init,
567 				sizeof(hdcp->auth.msg.hdcp2.lc_init));
568 	return status;
569 }
570 
571 enum mod_hdcp_status mod_hdcp_write_eks(struct mod_hdcp *hdcp)
572 {
573 	enum mod_hdcp_status status;
574 
575 	if (is_dp_hdcp(hdcp))
576 		status = write(hdcp,
577 				MOD_HDCP_MESSAGE_ID_WRITE_SKE_SEND_EKS,
578 				hdcp->auth.msg.hdcp2.ske_eks+1,
579 				sizeof(hdcp->auth.msg.hdcp2.ske_eks)-1);
580 	else
581 		status = write(hdcp,
582 			MOD_HDCP_MESSAGE_ID_WRITE_SKE_SEND_EKS,
583 			hdcp->auth.msg.hdcp2.ske_eks,
584 			sizeof(hdcp->auth.msg.hdcp2.ske_eks));
585 	return status;
586 }
587 
588 enum mod_hdcp_status mod_hdcp_write_repeater_auth_ack(struct mod_hdcp *hdcp)
589 {
590 	enum mod_hdcp_status status;
591 
592 	if (is_dp_hdcp(hdcp))
593 		status = write(hdcp, MOD_HDCP_MESSAGE_ID_WRITE_REPEATER_AUTH_SEND_ACK,
594 				hdcp->auth.msg.hdcp2.repeater_auth_ack+1,
595 				sizeof(hdcp->auth.msg.hdcp2.repeater_auth_ack)-1);
596 	else
597 		status = write(hdcp, MOD_HDCP_MESSAGE_ID_WRITE_REPEATER_AUTH_SEND_ACK,
598 				hdcp->auth.msg.hdcp2.repeater_auth_ack,
599 				sizeof(hdcp->auth.msg.hdcp2.repeater_auth_ack));
600 	return status;
601 }
602 
603 enum mod_hdcp_status mod_hdcp_write_stream_manage(struct mod_hdcp *hdcp)
604 {
605 	enum mod_hdcp_status status;
606 
607 	if (is_dp_hdcp(hdcp))
608 		status = write(hdcp,
609 				MOD_HDCP_MESSAGE_ID_WRITE_REPEATER_AUTH_STREAM_MANAGE,
610 				hdcp->auth.msg.hdcp2.repeater_auth_stream_manage+1,
611 				hdcp->auth.msg.hdcp2.stream_manage_size-1);
612 	else
613 		status = write(hdcp,
614 				MOD_HDCP_MESSAGE_ID_WRITE_REPEATER_AUTH_STREAM_MANAGE,
615 				hdcp->auth.msg.hdcp2.repeater_auth_stream_manage,
616 				hdcp->auth.msg.hdcp2.stream_manage_size);
617 	return status;
618 }
619 
620 enum mod_hdcp_status mod_hdcp_write_content_type(struct mod_hdcp *hdcp)
621 {
622 	enum mod_hdcp_status status;
623 
624 	if (is_dp_hdcp(hdcp))
625 		status = write(hdcp, MOD_HDCP_MESSAGE_ID_WRITE_CONTENT_STREAM_TYPE,
626 				hdcp->auth.msg.hdcp2.content_stream_type_dp+1,
627 				sizeof(hdcp->auth.msg.hdcp2.content_stream_type_dp)-1);
628 	else
629 		status = MOD_HDCP_STATUS_INVALID_OPERATION;
630 	return status;
631 }
632