Merge branch 'for-linus' into next
[linux-2.6-microblaze.git] / drivers / gpu / drm / amd / display / modules / hdcp / hdcp_psp.c
1 /*
2  * Copyright 2018 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 #define MAX_NUM_DISPLAYS 24
27
28
29 #include "hdcp.h"
30
31 #include "amdgpu.h"
32 #include "hdcp_psp.h"
33
34 static void hdcp2_message_init(struct mod_hdcp *hdcp,
35                                struct ta_hdcp_cmd_hdcp2_process_prepare_authentication_message_input_v2 *in)
36 {
37         in->session_handle = hdcp->auth.id;
38         in->prepare.msg1_id = TA_HDCP_HDCP2_MSG_ID__NULL_MESSAGE;
39         in->prepare.msg2_id = TA_HDCP_HDCP2_MSG_ID__NULL_MESSAGE;
40         in->process.msg1_desc.msg_id = TA_HDCP_HDCP2_MSG_ID__NULL_MESSAGE;
41         in->process.msg1_desc.msg_size = 0;
42         in->process.msg2_desc.msg_id = TA_HDCP_HDCP2_MSG_ID__NULL_MESSAGE;
43         in->process.msg2_desc.msg_size = 0;
44         in->process.msg3_desc.msg_id = TA_HDCP_HDCP2_MSG_ID__NULL_MESSAGE;
45         in->process.msg3_desc.msg_size = 0;
46 }
47 enum mod_hdcp_status mod_hdcp_remove_display_from_topology(
48                 struct mod_hdcp *hdcp, uint8_t index)
49  {
50         struct psp_context *psp = hdcp->config.psp.handle;
51         struct ta_dtm_shared_memory *dtm_cmd;
52         struct mod_hdcp_display *display =
53                         get_active_display_at_index(hdcp, index);
54
55         dtm_cmd = (struct ta_dtm_shared_memory *)psp->dtm_context.dtm_shared_buf;
56
57         if (!display || !is_display_added(display))
58                 return MOD_HDCP_STATUS_DISPLAY_NOT_FOUND;
59
60         memset(dtm_cmd, 0, sizeof(struct ta_dtm_shared_memory));
61
62         dtm_cmd->cmd_id = TA_DTM_COMMAND__TOPOLOGY_UPDATE_V2;
63         dtm_cmd->dtm_in_message.topology_update_v2.display_handle = display->index;
64         dtm_cmd->dtm_in_message.topology_update_v2.is_active = 0;
65         dtm_cmd->dtm_status = TA_DTM_STATUS__GENERIC_FAILURE;
66
67         psp_dtm_invoke(psp, dtm_cmd->cmd_id);
68
69         if (dtm_cmd->dtm_status != TA_DTM_STATUS__SUCCESS)
70                 return MOD_HDCP_STATUS_UPDATE_TOPOLOGY_FAILURE;
71
72         display->state = MOD_HDCP_DISPLAY_ACTIVE;
73         HDCP_TOP_REMOVE_DISPLAY_TRACE(hdcp, display->index);
74  
75         return MOD_HDCP_STATUS_SUCCESS;
76  
77 }
78 enum mod_hdcp_status mod_hdcp_add_display_to_topology(struct mod_hdcp *hdcp,
79                                                       uint8_t index)
80 {
81         struct psp_context *psp = hdcp->config.psp.handle;
82         struct ta_dtm_shared_memory *dtm_cmd;
83         struct mod_hdcp_display *display =
84                         get_active_display_at_index(hdcp, index);
85         struct mod_hdcp_link *link = &hdcp->connection.link;
86
87         if (!psp->dtm_context.dtm_initialized) {
88                 DRM_ERROR("Failed to add display topology, DTM TA is not initialized.");
89                 return MOD_HDCP_STATUS_FAILURE;
90         }
91
92         if (!display || is_display_added(display))
93                 return MOD_HDCP_STATUS_UPDATE_TOPOLOGY_FAILURE;
94
95         dtm_cmd = (struct ta_dtm_shared_memory *)psp->dtm_context.dtm_shared_buf;
96
97         memset(dtm_cmd, 0, sizeof(struct ta_dtm_shared_memory));
98
99         dtm_cmd->cmd_id = TA_DTM_COMMAND__TOPOLOGY_UPDATE_V2;
100         dtm_cmd->dtm_in_message.topology_update_v2.display_handle = display->index;
101         dtm_cmd->dtm_in_message.topology_update_v2.is_active = 1;
102         dtm_cmd->dtm_in_message.topology_update_v2.controller = display->controller;
103         dtm_cmd->dtm_in_message.topology_update_v2.ddc_line = link->ddc_line;
104         dtm_cmd->dtm_in_message.topology_update_v2.dig_be = link->dig_be;
105         dtm_cmd->dtm_in_message.topology_update_v2.dig_fe = display->dig_fe;
106         if (is_dp_hdcp(hdcp))
107                 dtm_cmd->dtm_in_message.topology_update_v2.is_assr = link->dp.assr_supported;
108
109         dtm_cmd->dtm_in_message.topology_update_v2.dp_mst_vcid = display->vc_id;
110         dtm_cmd->dtm_in_message.topology_update_v2.max_hdcp_supported_version =
111                         TA_DTM_HDCP_VERSION_MAX_SUPPORTED__2_2;
112         dtm_cmd->dtm_status = TA_DTM_STATUS__GENERIC_FAILURE;
113
114         psp_dtm_invoke(psp, dtm_cmd->cmd_id);
115
116         if (dtm_cmd->dtm_status != TA_DTM_STATUS__SUCCESS)
117                 return MOD_HDCP_STATUS_UPDATE_TOPOLOGY_FAILURE;
118
119         display->state = MOD_HDCP_DISPLAY_ACTIVE_AND_ADDED;
120         HDCP_TOP_ADD_DISPLAY_TRACE(hdcp, display->index);
121
122         return MOD_HDCP_STATUS_SUCCESS;
123 }
124
125 enum mod_hdcp_status mod_hdcp_hdcp1_create_session(struct mod_hdcp *hdcp)
126 {
127
128         struct psp_context *psp = hdcp->config.psp.handle;
129         struct mod_hdcp_display *display = get_first_added_display(hdcp);
130         struct ta_hdcp_shared_memory *hdcp_cmd;
131
132         if (!psp->hdcp_context.hdcp_initialized) {
133                 DRM_ERROR("Failed to create hdcp session. HDCP TA is not initialized.");
134                 return MOD_HDCP_STATUS_FAILURE;
135         }
136
137         hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.hdcp_shared_buf;
138         memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
139
140         hdcp_cmd->in_msg.hdcp1_create_session.display_handle = display->index;
141         hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP1_CREATE_SESSION;
142
143         psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
144
145         hdcp->auth.id = hdcp_cmd->out_msg.hdcp1_create_session.session_handle;
146
147         if (hdcp_cmd->hdcp_status != TA_HDCP_STATUS__SUCCESS)
148                 return MOD_HDCP_STATUS_HDCP1_CREATE_SESSION_FAILURE;
149
150         hdcp->auth.msg.hdcp1.ainfo = hdcp_cmd->out_msg.hdcp1_create_session.ainfo_primary;
151         memcpy(hdcp->auth.msg.hdcp1.aksv, hdcp_cmd->out_msg.hdcp1_create_session.aksv_primary,
152                 sizeof(hdcp->auth.msg.hdcp1.aksv));
153         memcpy(hdcp->auth.msg.hdcp1.an, hdcp_cmd->out_msg.hdcp1_create_session.an_primary,
154                 sizeof(hdcp->auth.msg.hdcp1.an));
155
156         return MOD_HDCP_STATUS_SUCCESS;
157 }
158
159 enum mod_hdcp_status mod_hdcp_hdcp1_destroy_session(struct mod_hdcp *hdcp)
160 {
161
162         struct psp_context *psp = hdcp->config.psp.handle;
163         struct ta_hdcp_shared_memory *hdcp_cmd;
164         uint8_t i = 0;
165
166         hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.hdcp_shared_buf;
167         memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
168
169         hdcp_cmd->in_msg.hdcp1_destroy_session.session_handle = hdcp->auth.id;
170         hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP1_DESTROY_SESSION;
171
172         psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
173
174         if (hdcp_cmd->hdcp_status != TA_HDCP_STATUS__SUCCESS)
175                 return MOD_HDCP_STATUS_HDCP1_DESTROY_SESSION_FAILURE;
176
177         HDCP_TOP_HDCP1_DESTROY_SESSION_TRACE(hdcp);
178         for (i = 0; i < MAX_NUM_OF_DISPLAYS; i++)
179                 if (is_display_encryption_enabled(
180                                 &hdcp->displays[i])) {
181                         hdcp->displays[i].state =
182                                         MOD_HDCP_DISPLAY_ACTIVE_AND_ADDED;
183                         HDCP_HDCP1_DISABLED_TRACE(hdcp,
184                                         hdcp->displays[i].index);
185                 }
186
187         return MOD_HDCP_STATUS_SUCCESS;
188 }
189
190 enum mod_hdcp_status mod_hdcp_hdcp1_validate_rx(struct mod_hdcp *hdcp)
191 {
192         struct psp_context *psp = hdcp->config.psp.handle;
193         struct ta_hdcp_shared_memory *hdcp_cmd;
194
195         hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.hdcp_shared_buf;
196         memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
197
198         hdcp_cmd->in_msg.hdcp1_first_part_authentication.session_handle = hdcp->auth.id;
199
200         memcpy(hdcp_cmd->in_msg.hdcp1_first_part_authentication.bksv_primary, hdcp->auth.msg.hdcp1.bksv,
201                 TA_HDCP__HDCP1_KSV_SIZE);
202
203         hdcp_cmd->in_msg.hdcp1_first_part_authentication.r0_prime_primary = hdcp->auth.msg.hdcp1.r0p;
204         hdcp_cmd->in_msg.hdcp1_first_part_authentication.bcaps = hdcp->auth.msg.hdcp1.bcaps;
205         hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP1_FIRST_PART_AUTHENTICATION;
206
207         psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
208
209         if (hdcp_cmd->hdcp_status != TA_HDCP_STATUS__SUCCESS)
210                 return MOD_HDCP_STATUS_HDCP1_VALIDATE_RX_FAILURE;
211
212         if (hdcp_cmd->out_msg.hdcp1_first_part_authentication.authentication_status ==
213             TA_HDCP_AUTHENTICATION_STATUS__HDCP1_FIRST_PART_COMPLETE) {
214                 /* needs second part of authentication */
215                 hdcp->connection.is_repeater = 1;
216         } else if (hdcp_cmd->out_msg.hdcp1_first_part_authentication.authentication_status ==
217                    TA_HDCP_AUTHENTICATION_STATUS__HDCP1_AUTHENTICATED) {
218                 hdcp->connection.is_repeater = 0;
219         } else if (hdcp_cmd->out_msg.hdcp1_first_part_authentication.authentication_status ==
220                    TA_HDCP_AUTHENTICATION_STATUS__HDCP1_KSV_REVOKED) {
221                 hdcp->connection.is_hdcp1_revoked = 1;
222                 return MOD_HDCP_STATUS_HDCP1_BKSV_REVOKED;
223         } else
224                 return MOD_HDCP_STATUS_HDCP1_VALIDATE_RX_FAILURE;
225
226
227         return MOD_HDCP_STATUS_SUCCESS;
228 }
229
230 enum mod_hdcp_status mod_hdcp_hdcp1_enable_encryption(struct mod_hdcp *hdcp)
231 {
232         struct psp_context *psp = hdcp->config.psp.handle;
233         struct ta_hdcp_shared_memory *hdcp_cmd;
234         struct mod_hdcp_display *display = get_first_added_display(hdcp);
235
236         hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.hdcp_shared_buf;
237         memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
238
239         hdcp_cmd->in_msg.hdcp1_enable_encryption.session_handle = hdcp->auth.id;
240         hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP1_ENABLE_ENCRYPTION;
241
242         psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
243
244         if (hdcp_cmd->hdcp_status != TA_HDCP_STATUS__SUCCESS)
245                 return MOD_HDCP_STATUS_HDCP1_ENABLE_ENCRYPTION;
246
247         if (!is_dp_mst_hdcp(hdcp)) {
248                 display->state = MOD_HDCP_DISPLAY_ENCRYPTION_ENABLED;
249                 HDCP_HDCP1_ENABLED_TRACE(hdcp, display->index);
250         }
251         return MOD_HDCP_STATUS_SUCCESS;
252 }
253
254 enum mod_hdcp_status mod_hdcp_hdcp1_validate_ksvlist_vp(struct mod_hdcp *hdcp)
255 {
256         struct psp_context *psp = hdcp->config.psp.handle;
257         struct ta_hdcp_shared_memory *hdcp_cmd;
258         enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
259
260         hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.hdcp_shared_buf;
261         memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
262
263         hdcp_cmd->in_msg.hdcp1_second_part_authentication.session_handle = hdcp->auth.id;
264
265         hdcp_cmd->in_msg.hdcp1_second_part_authentication.ksv_list_size = hdcp->auth.msg.hdcp1.ksvlist_size;
266         memcpy(hdcp_cmd->in_msg.hdcp1_second_part_authentication.ksv_list, hdcp->auth.msg.hdcp1.ksvlist,
267                hdcp->auth.msg.hdcp1.ksvlist_size);
268
269         memcpy(hdcp_cmd->in_msg.hdcp1_second_part_authentication.v_prime, hdcp->auth.msg.hdcp1.vp,
270                sizeof(hdcp->auth.msg.hdcp1.vp));
271
272         hdcp_cmd->in_msg.hdcp1_second_part_authentication.bstatus_binfo =
273                 is_dp_hdcp(hdcp) ? hdcp->auth.msg.hdcp1.binfo_dp : hdcp->auth.msg.hdcp1.bstatus;
274         hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP1_SECOND_PART_AUTHENTICATION;
275
276         psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
277
278         if (hdcp_cmd->hdcp_status == TA_HDCP_STATUS__SUCCESS &&
279             hdcp_cmd->out_msg.hdcp1_second_part_authentication.authentication_status ==
280                     TA_HDCP_AUTHENTICATION_STATUS__HDCP1_AUTHENTICATED) {
281                 status = MOD_HDCP_STATUS_SUCCESS;
282         } else if (hdcp_cmd->out_msg.hdcp1_second_part_authentication.authentication_status ==
283                    TA_HDCP_AUTHENTICATION_STATUS__HDCP1_KSV_REVOKED) {
284                 hdcp->connection.is_hdcp1_revoked = 1;
285                 status = MOD_HDCP_STATUS_HDCP1_KSV_LIST_REVOKED;
286         } else {
287                 status = MOD_HDCP_STATUS_HDCP1_VALIDATE_KSV_LIST_FAILURE;
288         }
289
290         return status;
291 }
292
293 enum mod_hdcp_status mod_hdcp_hdcp1_enable_dp_stream_encryption(struct mod_hdcp *hdcp)
294 {
295
296         struct psp_context *psp = hdcp->config.psp.handle;
297         struct ta_hdcp_shared_memory *hdcp_cmd;
298         int i = 0;
299
300         hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.hdcp_shared_buf;
301
302         for (i = 0; i < MAX_NUM_OF_DISPLAYS; i++) {
303
304                 if (hdcp->displays[i].state != MOD_HDCP_DISPLAY_ACTIVE_AND_ADDED ||
305                     hdcp->displays[i].adjust.disable)
306                         continue;
307
308                 memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
309
310                 hdcp_cmd->in_msg.hdcp1_enable_dp_stream_encryption.session_handle = hdcp->auth.id;
311                 hdcp_cmd->in_msg.hdcp1_enable_dp_stream_encryption.display_handle = hdcp->displays[i].index;
312                 hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP1_ENABLE_DP_STREAM_ENCRYPTION;
313
314                 psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
315
316                 if (hdcp_cmd->hdcp_status != TA_HDCP_STATUS__SUCCESS)
317                         return MOD_HDCP_STATUS_HDCP1_ENABLE_STREAM_ENCRYPTION_FAILURE;
318
319                 hdcp->displays[i].state = MOD_HDCP_DISPLAY_ENCRYPTION_ENABLED;
320                 HDCP_HDCP1_ENABLED_TRACE(hdcp, hdcp->displays[i].index);
321         }
322
323         return MOD_HDCP_STATUS_SUCCESS;
324 }
325
326 enum mod_hdcp_status mod_hdcp_hdcp1_link_maintenance(struct mod_hdcp *hdcp)
327 {
328         struct psp_context *psp = hdcp->config.psp.handle;
329         struct ta_hdcp_shared_memory *hdcp_cmd;
330
331         hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.hdcp_shared_buf;
332
333         memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
334
335         hdcp_cmd->in_msg.hdcp1_get_encryption_status.session_handle = hdcp->auth.id;
336
337         hdcp_cmd->out_msg.hdcp1_get_encryption_status.protection_level = 0;
338         hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP1_GET_ENCRYPTION_STATUS;
339
340         psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
341
342         if (hdcp_cmd->hdcp_status != TA_HDCP_STATUS__SUCCESS)
343                 return MOD_HDCP_STATUS_HDCP1_LINK_MAINTENANCE_FAILURE;
344
345         return (hdcp_cmd->out_msg.hdcp1_get_encryption_status.protection_level == 1)
346                        ? MOD_HDCP_STATUS_SUCCESS
347                        : MOD_HDCP_STATUS_HDCP1_LINK_MAINTENANCE_FAILURE;
348 }
349
350 enum mod_hdcp_status mod_hdcp_hdcp1_get_link_encryption_status(struct mod_hdcp *hdcp,
351                                                                enum mod_hdcp_encryption_status *encryption_status)
352 {
353         *encryption_status = MOD_HDCP_ENCRYPTION_STATUS_HDCP_OFF;
354
355         if (mod_hdcp_hdcp1_link_maintenance(hdcp) != MOD_HDCP_STATUS_SUCCESS)
356                 return MOD_HDCP_STATUS_FAILURE;
357
358         *encryption_status = MOD_HDCP_ENCRYPTION_STATUS_HDCP1_ON;
359
360         return MOD_HDCP_STATUS_SUCCESS;
361 }
362
363 enum mod_hdcp_status mod_hdcp_hdcp2_create_session(struct mod_hdcp *hdcp)
364 {
365         struct psp_context *psp = hdcp->config.psp.handle;
366         struct ta_hdcp_shared_memory *hdcp_cmd;
367         struct mod_hdcp_display *display = get_first_added_display(hdcp);
368
369         if (!psp->hdcp_context.hdcp_initialized) {
370                 DRM_ERROR("Failed to create hdcp session, HDCP TA is not initialized");
371                 return MOD_HDCP_STATUS_FAILURE;
372         }
373
374         hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.hdcp_shared_buf;
375         memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
376
377         if (!display)
378                 return MOD_HDCP_STATUS_DISPLAY_NOT_FOUND;
379
380         hdcp_cmd->in_msg.hdcp2_create_session_v2.display_handle = display->index;
381
382         if (hdcp->connection.link.adjust.hdcp2.force_type == MOD_HDCP_FORCE_TYPE_0)
383                 hdcp_cmd->in_msg.hdcp2_create_session_v2.negotiate_content_type =
384                         TA_HDCP2_CONTENT_TYPE_NEGOTIATION_TYPE__FORCE_TYPE0;
385         else if (hdcp->connection.link.adjust.hdcp2.force_type == MOD_HDCP_FORCE_TYPE_1)
386                 hdcp_cmd->in_msg.hdcp2_create_session_v2.negotiate_content_type =
387                         TA_HDCP2_CONTENT_TYPE_NEGOTIATION_TYPE__FORCE_TYPE1;
388         else if (hdcp->connection.link.adjust.hdcp2.force_type == MOD_HDCP_FORCE_TYPE_MAX)
389                 hdcp_cmd->in_msg.hdcp2_create_session_v2.negotiate_content_type =
390                         TA_HDCP2_CONTENT_TYPE_NEGOTIATION_TYPE__MAX_SUPPORTED;
391
392         hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP2_CREATE_SESSION_V2;
393
394         psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
395
396         if (hdcp_cmd->hdcp_status != TA_HDCP_STATUS__SUCCESS)
397                 return MOD_HDCP_STATUS_HDCP2_CREATE_SESSION_FAILURE;
398
399         hdcp->auth.id = hdcp_cmd->out_msg.hdcp2_create_session_v2.session_handle;
400
401         return MOD_HDCP_STATUS_SUCCESS;
402 }
403
404 enum mod_hdcp_status mod_hdcp_hdcp2_destroy_session(struct mod_hdcp *hdcp)
405 {
406         struct psp_context *psp = hdcp->config.psp.handle;
407         struct ta_hdcp_shared_memory *hdcp_cmd;
408         uint8_t i = 0;
409
410         hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.hdcp_shared_buf;
411         memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
412
413         hdcp_cmd->in_msg.hdcp2_destroy_session.session_handle = hdcp->auth.id;
414         hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP2_DESTROY_SESSION;
415
416         psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
417
418         if (hdcp_cmd->hdcp_status != TA_HDCP_STATUS__SUCCESS)
419                 return MOD_HDCP_STATUS_HDCP2_DESTROY_SESSION_FAILURE;
420
421         HDCP_TOP_HDCP2_DESTROY_SESSION_TRACE(hdcp);
422         for (i = 0; i < MAX_NUM_OF_DISPLAYS; i++)
423                 if (is_display_encryption_enabled(
424                                 &hdcp->displays[i])) {
425                         hdcp->displays[i].state =
426                                         MOD_HDCP_DISPLAY_ACTIVE_AND_ADDED;
427                         HDCP_HDCP2_DISABLED_TRACE(hdcp,
428                                         hdcp->displays[i].index);
429                 }
430
431         return MOD_HDCP_STATUS_SUCCESS;
432 }
433
434 enum mod_hdcp_status mod_hdcp_hdcp2_prepare_ake_init(struct mod_hdcp *hdcp)
435 {
436         struct psp_context *psp = hdcp->config.psp.handle;
437         struct ta_hdcp_shared_memory *hdcp_cmd;
438         struct ta_hdcp_cmd_hdcp2_process_prepare_authentication_message_input_v2 *msg_in;
439         struct ta_hdcp_cmd_hdcp2_process_prepare_authentication_message_output_v2 *msg_out;
440
441         hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.hdcp_shared_buf;
442         memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
443
444         msg_in = &hdcp_cmd->in_msg.hdcp2_prepare_process_authentication_message_v2;
445         msg_out = &hdcp_cmd->out_msg.hdcp2_prepare_process_authentication_message_v2;
446
447         hdcp2_message_init(hdcp, msg_in);
448
449         hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP2_PREPARE_PROCESS_AUTHENTICATION_MSG_V2;
450         msg_in->prepare.msg1_id = TA_HDCP_HDCP2_MSG_ID__AKE_INIT;
451
452         psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
453
454         if (hdcp_cmd->hdcp_status != TA_HDCP_STATUS__SUCCESS)
455                 return MOD_HDCP_STATUS_HDCP2_PREP_AKE_INIT_FAILURE;
456
457         memcpy(&hdcp->auth.msg.hdcp2.ake_init[0], &msg_out->prepare.transmitter_message[0],
458                sizeof(hdcp->auth.msg.hdcp2.ake_init));
459
460         return MOD_HDCP_STATUS_SUCCESS;
461 }
462
463 enum mod_hdcp_status mod_hdcp_hdcp2_validate_ake_cert(struct mod_hdcp *hdcp)
464 {
465         struct psp_context *psp = hdcp->config.psp.handle;
466         struct ta_hdcp_shared_memory *hdcp_cmd;
467         struct ta_hdcp_cmd_hdcp2_process_prepare_authentication_message_input_v2 *msg_in;
468         struct ta_hdcp_cmd_hdcp2_process_prepare_authentication_message_output_v2 *msg_out;
469
470         hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.hdcp_shared_buf;
471         memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
472
473         msg_in = &hdcp_cmd->in_msg.hdcp2_prepare_process_authentication_message_v2;
474         msg_out = &hdcp_cmd->out_msg.hdcp2_prepare_process_authentication_message_v2;
475
476         hdcp2_message_init(hdcp, msg_in);
477
478         msg_in->process.msg1_desc.msg_id = TA_HDCP_HDCP2_MSG_ID__AKE_SEND_CERT;
479         msg_in->process.msg1_desc.msg_size = TA_HDCP_HDCP2_MSG_ID_MAX_SIZE__AKE_SEND_CERT;
480
481         memcpy(&msg_in->process.receiver_message[0], hdcp->auth.msg.hdcp2.ake_cert,
482                sizeof(hdcp->auth.msg.hdcp2.ake_cert));
483
484         msg_in->prepare.msg1_id = TA_HDCP_HDCP2_MSG_ID__AKE_NO_STORED_KM;
485         msg_in->prepare.msg2_id = TA_HDCP_HDCP2_MSG_ID__AKE_STORED_KM;
486
487         hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP2_PREPARE_PROCESS_AUTHENTICATION_MSG_V2;
488
489         psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
490
491         if (hdcp_cmd->hdcp_status != TA_HDCP_STATUS__SUCCESS)
492                 return MOD_HDCP_STATUS_HDCP2_VALIDATE_AKE_CERT_FAILURE;
493
494         memcpy(hdcp->auth.msg.hdcp2.ake_no_stored_km, &msg_out->prepare.transmitter_message[0],
495                sizeof(hdcp->auth.msg.hdcp2.ake_no_stored_km));
496
497         memcpy(hdcp->auth.msg.hdcp2.ake_stored_km,
498                &msg_out->prepare.transmitter_message[sizeof(hdcp->auth.msg.hdcp2.ake_no_stored_km)],
499                sizeof(hdcp->auth.msg.hdcp2.ake_stored_km));
500
501         if (msg_out->process.msg1_status == TA_HDCP2_MSG_AUTHENTICATION_STATUS__SUCCESS) {
502                 hdcp->connection.is_km_stored = msg_out->process.is_km_stored ? 1 : 0;
503                 hdcp->connection.is_repeater = msg_out->process.is_repeater ? 1 : 0;
504                 return MOD_HDCP_STATUS_SUCCESS;
505         } else if (msg_out->process.msg1_status == TA_HDCP2_MSG_AUTHENTICATION_STATUS__RECEIVERID_REVOKED) {
506                 hdcp->connection.is_hdcp2_revoked = 1;
507                 return MOD_HDCP_STATUS_HDCP2_AKE_CERT_REVOKED;
508         }
509
510         return MOD_HDCP_STATUS_HDCP2_VALIDATE_AKE_CERT_FAILURE;
511 }
512
513 enum mod_hdcp_status mod_hdcp_hdcp2_validate_h_prime(struct mod_hdcp *hdcp)
514 {
515         struct psp_context *psp = hdcp->config.psp.handle;
516         struct ta_hdcp_shared_memory *hdcp_cmd;
517         struct ta_hdcp_cmd_hdcp2_process_prepare_authentication_message_input_v2 *msg_in;
518         struct ta_hdcp_cmd_hdcp2_process_prepare_authentication_message_output_v2 *msg_out;
519
520         hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.hdcp_shared_buf;
521         memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
522
523         msg_in = &hdcp_cmd->in_msg.hdcp2_prepare_process_authentication_message_v2;
524         msg_out = &hdcp_cmd->out_msg.hdcp2_prepare_process_authentication_message_v2;
525
526         hdcp2_message_init(hdcp, msg_in);
527
528         msg_in->process.msg1_desc.msg_id = TA_HDCP_HDCP2_MSG_ID__AKE_SEND_H_PRIME;
529         msg_in->process.msg1_desc.msg_size = TA_HDCP_HDCP2_MSG_ID_MAX_SIZE__AKE_SEND_H_PRIME;
530
531         memcpy(&msg_in->process.receiver_message[0], hdcp->auth.msg.hdcp2.ake_h_prime,
532                sizeof(hdcp->auth.msg.hdcp2.ake_h_prime));
533
534         if (!hdcp->connection.is_km_stored) {
535                 msg_in->process.msg2_desc.msg_id = TA_HDCP_HDCP2_MSG_ID__AKE_SEND_PAIRING_INFO;
536                 msg_in->process.msg2_desc.msg_size = TA_HDCP_HDCP2_MSG_ID_MAX_SIZE__AKE_SEND_PAIRING_INFO;
537                 memcpy(&msg_in->process.receiver_message[sizeof(hdcp->auth.msg.hdcp2.ake_h_prime)],
538                        hdcp->auth.msg.hdcp2.ake_pairing_info, sizeof(hdcp->auth.msg.hdcp2.ake_pairing_info));
539         }
540
541         hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP2_PREPARE_PROCESS_AUTHENTICATION_MSG_V2;
542
543         psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
544
545         if (hdcp_cmd->hdcp_status != TA_HDCP_STATUS__SUCCESS)
546                 return MOD_HDCP_STATUS_HDCP2_VALIDATE_H_PRIME_FAILURE;
547
548         if (msg_out->process.msg1_status != TA_HDCP2_MSG_AUTHENTICATION_STATUS__SUCCESS)
549                 return MOD_HDCP_STATUS_HDCP2_VALIDATE_H_PRIME_FAILURE;
550         else if (!hdcp->connection.is_km_stored &&
551                  msg_out->process.msg2_status != TA_HDCP2_MSG_AUTHENTICATION_STATUS__SUCCESS)
552                 return MOD_HDCP_STATUS_HDCP2_VALIDATE_PAIRING_INFO_FAILURE;
553
554
555         return MOD_HDCP_STATUS_SUCCESS;
556 }
557
558 enum mod_hdcp_status mod_hdcp_hdcp2_prepare_lc_init(struct mod_hdcp *hdcp)
559 {
560         struct psp_context *psp = hdcp->config.psp.handle;
561         struct ta_hdcp_shared_memory *hdcp_cmd;
562         struct ta_hdcp_cmd_hdcp2_process_prepare_authentication_message_input_v2 *msg_in;
563         struct ta_hdcp_cmd_hdcp2_process_prepare_authentication_message_output_v2 *msg_out;
564
565         hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.hdcp_shared_buf;
566         memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
567
568         msg_in = &hdcp_cmd->in_msg.hdcp2_prepare_process_authentication_message_v2;
569         msg_out = &hdcp_cmd->out_msg.hdcp2_prepare_process_authentication_message_v2;
570
571         hdcp2_message_init(hdcp, msg_in);
572
573         msg_in->prepare.msg1_id = TA_HDCP_HDCP2_MSG_ID__LC_INIT;
574
575         hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP2_PREPARE_PROCESS_AUTHENTICATION_MSG_V2;
576
577         psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
578
579         if (hdcp_cmd->hdcp_status != TA_HDCP_STATUS__SUCCESS)
580                 return MOD_HDCP_STATUS_HDCP2_PREP_LC_INIT_FAILURE;
581
582         memcpy(hdcp->auth.msg.hdcp2.lc_init, &msg_out->prepare.transmitter_message[0],
583                sizeof(hdcp->auth.msg.hdcp2.lc_init));
584
585         return MOD_HDCP_STATUS_SUCCESS;
586 }
587
588 enum mod_hdcp_status mod_hdcp_hdcp2_validate_l_prime(struct mod_hdcp *hdcp)
589 {
590         struct psp_context *psp = hdcp->config.psp.handle;
591         struct ta_hdcp_shared_memory *hdcp_cmd;
592         struct ta_hdcp_cmd_hdcp2_process_prepare_authentication_message_input_v2 *msg_in;
593         struct ta_hdcp_cmd_hdcp2_process_prepare_authentication_message_output_v2 *msg_out;
594
595         hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.hdcp_shared_buf;
596         memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
597
598         msg_in = &hdcp_cmd->in_msg.hdcp2_prepare_process_authentication_message_v2;
599         msg_out = &hdcp_cmd->out_msg.hdcp2_prepare_process_authentication_message_v2;
600
601         hdcp2_message_init(hdcp, msg_in);
602
603         msg_in->process.msg1_desc.msg_id = TA_HDCP_HDCP2_MSG_ID__LC_SEND_L_PRIME;
604         msg_in->process.msg1_desc.msg_size = TA_HDCP_HDCP2_MSG_ID_MAX_SIZE__LC_SEND_L_PRIME;
605
606         memcpy(&msg_in->process.receiver_message[0], hdcp->auth.msg.hdcp2.lc_l_prime,
607                sizeof(hdcp->auth.msg.hdcp2.lc_l_prime));
608
609         hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP2_PREPARE_PROCESS_AUTHENTICATION_MSG_V2;
610
611         psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
612
613         if (hdcp_cmd->hdcp_status != TA_HDCP_STATUS__SUCCESS)
614                 return MOD_HDCP_STATUS_HDCP2_VALIDATE_L_PRIME_FAILURE;
615
616         if (msg_out->process.msg1_status != TA_HDCP2_MSG_AUTHENTICATION_STATUS__SUCCESS)
617                 return MOD_HDCP_STATUS_HDCP2_VALIDATE_L_PRIME_FAILURE;
618
619         return MOD_HDCP_STATUS_SUCCESS;
620 }
621
622 enum mod_hdcp_status mod_hdcp_hdcp2_prepare_eks(struct mod_hdcp *hdcp)
623 {
624         struct psp_context *psp = hdcp->config.psp.handle;
625         struct ta_hdcp_shared_memory *hdcp_cmd;
626         struct ta_hdcp_cmd_hdcp2_process_prepare_authentication_message_input_v2 *msg_in;
627         struct ta_hdcp_cmd_hdcp2_process_prepare_authentication_message_output_v2 *msg_out;
628
629         hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.hdcp_shared_buf;
630         memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
631
632         msg_in = &hdcp_cmd->in_msg.hdcp2_prepare_process_authentication_message_v2;
633         msg_out = &hdcp_cmd->out_msg.hdcp2_prepare_process_authentication_message_v2;
634
635         hdcp2_message_init(hdcp, msg_in);
636
637         msg_in->prepare.msg1_id = TA_HDCP_HDCP2_MSG_ID__SKE_SEND_EKS;
638
639         if (is_dp_hdcp(hdcp))
640                 msg_in->prepare.msg2_id = TA_HDCP_HDCP2_MSG_ID__SIGNAL_CONTENT_STREAM_TYPE_DP;
641
642         hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP2_PREPARE_PROCESS_AUTHENTICATION_MSG_V2;
643         psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
644
645         if (hdcp_cmd->hdcp_status != TA_HDCP_STATUS__SUCCESS)
646                 return MOD_HDCP_STATUS_HDCP2_PREP_EKS_FAILURE;
647
648         memcpy(hdcp->auth.msg.hdcp2.ske_eks, &msg_out->prepare.transmitter_message[0],
649                sizeof(hdcp->auth.msg.hdcp2.ske_eks));
650         msg_out->prepare.msg1_desc.msg_size = sizeof(hdcp->auth.msg.hdcp2.ske_eks);
651
652         if (is_dp_hdcp(hdcp)) {
653                 memcpy(hdcp->auth.msg.hdcp2.content_stream_type_dp,
654                        &msg_out->prepare.transmitter_message[sizeof(hdcp->auth.msg.hdcp2.ske_eks)],
655                        sizeof(hdcp->auth.msg.hdcp2.content_stream_type_dp));
656         }
657
658         return MOD_HDCP_STATUS_SUCCESS;
659 }
660
661 enum mod_hdcp_status mod_hdcp_hdcp2_enable_encryption(struct mod_hdcp *hdcp)
662 {
663         struct psp_context *psp = hdcp->config.psp.handle;
664         struct ta_hdcp_shared_memory *hdcp_cmd;
665         struct mod_hdcp_display *display = get_first_added_display(hdcp);
666
667         hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.hdcp_shared_buf;
668         memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
669
670         if (!display)
671                 return MOD_HDCP_STATUS_DISPLAY_NOT_FOUND;
672
673         hdcp_cmd->in_msg.hdcp2_set_encryption.session_handle = hdcp->auth.id;
674
675         hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP2_SET_ENCRYPTION;
676         psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
677
678         if (hdcp_cmd->hdcp_status != TA_HDCP_STATUS__SUCCESS)
679                 return MOD_HDCP_STATUS_HDCP2_ENABLE_ENCRYPTION_FAILURE;
680
681         if (!is_dp_mst_hdcp(hdcp)) {
682                 display->state = MOD_HDCP_DISPLAY_ENCRYPTION_ENABLED;
683                 HDCP_HDCP2_ENABLED_TRACE(hdcp, display->index);
684         }
685
686         return MOD_HDCP_STATUS_SUCCESS;
687 }
688
689 enum mod_hdcp_status mod_hdcp_hdcp2_validate_rx_id_list(struct mod_hdcp *hdcp)
690 {
691         struct psp_context *psp = hdcp->config.psp.handle;
692         struct ta_hdcp_shared_memory *hdcp_cmd;
693         struct ta_hdcp_cmd_hdcp2_process_prepare_authentication_message_input_v2 *msg_in;
694         struct ta_hdcp_cmd_hdcp2_process_prepare_authentication_message_output_v2 *msg_out;
695
696         hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.hdcp_shared_buf;
697         memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
698
699         msg_in = &hdcp_cmd->in_msg.hdcp2_prepare_process_authentication_message_v2;
700         msg_out = &hdcp_cmd->out_msg.hdcp2_prepare_process_authentication_message_v2;
701
702         hdcp2_message_init(hdcp, msg_in);
703
704         msg_in->process.msg1_desc.msg_id = TA_HDCP_HDCP2_MSG_ID__REPEATERAUTH_SEND_RECEIVERID_LIST;
705         msg_in->process.msg1_desc.msg_size = sizeof(hdcp->auth.msg.hdcp2.rx_id_list);
706         memcpy(&msg_in->process.receiver_message[0], hdcp->auth.msg.hdcp2.rx_id_list,
707                sizeof(hdcp->auth.msg.hdcp2.rx_id_list));
708
709         msg_in->prepare.msg1_id = TA_HDCP_HDCP2_MSG_ID__REPEATERAUTH_SEND_ACK;
710
711         hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP2_PREPARE_PROCESS_AUTHENTICATION_MSG_V2;
712
713         psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
714
715         if (hdcp_cmd->hdcp_status != TA_HDCP_STATUS__SUCCESS)
716                 return MOD_HDCP_STATUS_HDCP2_VALIDATE_RX_ID_LIST_FAILURE;
717
718         memcpy(hdcp->auth.msg.hdcp2.repeater_auth_ack, &msg_out->prepare.transmitter_message[0],
719                sizeof(hdcp->auth.msg.hdcp2.repeater_auth_ack));
720
721         if (msg_out->process.msg1_status == TA_HDCP2_MSG_AUTHENTICATION_STATUS__SUCCESS) {
722                 hdcp->connection.is_km_stored = msg_out->process.is_km_stored ? 1 : 0;
723                 hdcp->connection.is_repeater = msg_out->process.is_repeater ? 1 : 0;
724                 return MOD_HDCP_STATUS_SUCCESS;
725         } else if (msg_out->process.msg1_status == TA_HDCP2_MSG_AUTHENTICATION_STATUS__RECEIVERID_REVOKED) {
726                 hdcp->connection.is_hdcp2_revoked = 1;
727                 return MOD_HDCP_STATUS_HDCP2_RX_ID_LIST_REVOKED;
728         }
729
730
731         return MOD_HDCP_STATUS_HDCP2_VALIDATE_RX_ID_LIST_FAILURE;
732 }
733
734 enum mod_hdcp_status mod_hdcp_hdcp2_enable_dp_stream_encryption(struct mod_hdcp *hdcp)
735 {
736         struct psp_context *psp = hdcp->config.psp.handle;
737         struct ta_hdcp_shared_memory *hdcp_cmd;
738         struct ta_hdcp_cmd_hdcp2_process_prepare_authentication_message_input_v2 *msg_in;
739         uint8_t i;
740
741         hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.hdcp_shared_buf;
742         memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
743
744         msg_in = &hdcp_cmd->in_msg.hdcp2_prepare_process_authentication_message_v2;
745
746         hdcp2_message_init(hdcp, msg_in);
747
748
749         for (i = 0; i < MAX_NUM_OF_DISPLAYS; i++) {
750                 if (hdcp->displays[i].state != MOD_HDCP_DISPLAY_ACTIVE_AND_ADDED ||
751                     hdcp->displays[i].adjust.disable)
752                         continue;
753                 hdcp_cmd->in_msg.hdcp2_enable_dp_stream_encryption.display_handle = hdcp->displays[i].index;
754                 hdcp_cmd->in_msg.hdcp2_enable_dp_stream_encryption.session_handle = hdcp->auth.id;
755
756                 hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP2_ENABLE_DP_STREAM_ENCRYPTION;
757                 psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
758
759                 if (hdcp_cmd->hdcp_status != TA_HDCP_STATUS__SUCCESS)
760                         break;
761
762                 hdcp->displays[i].state = MOD_HDCP_DISPLAY_ENCRYPTION_ENABLED;
763                 HDCP_HDCP2_ENABLED_TRACE(hdcp, hdcp->displays[i].index);
764         }
765
766         return (hdcp_cmd->hdcp_status == TA_HDCP_STATUS__SUCCESS) ? MOD_HDCP_STATUS_SUCCESS
767                                                                   : MOD_HDCP_STATUS_HDCP2_ENABLE_STREAM_ENCRYPTION;
768 }
769
770 enum mod_hdcp_status mod_hdcp_hdcp2_prepare_stream_management(struct mod_hdcp *hdcp)
771 {
772
773         struct psp_context *psp = hdcp->config.psp.handle;
774         struct ta_hdcp_shared_memory *hdcp_cmd;
775         struct ta_hdcp_cmd_hdcp2_process_prepare_authentication_message_input_v2 *msg_in;
776         struct ta_hdcp_cmd_hdcp2_process_prepare_authentication_message_output_v2 *msg_out;
777
778         hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.hdcp_shared_buf;
779         memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
780
781         msg_in = &hdcp_cmd->in_msg.hdcp2_prepare_process_authentication_message_v2;
782         msg_out = &hdcp_cmd->out_msg.hdcp2_prepare_process_authentication_message_v2;
783
784         hdcp2_message_init(hdcp, msg_in);
785
786         msg_in->prepare.msg1_id = TA_HDCP_HDCP2_MSG_ID__REPEATERAUTH_STREAM_MANAGE;
787
788
789         hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP2_PREPARE_PROCESS_AUTHENTICATION_MSG_V2;
790         psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
791
792         if (hdcp_cmd->hdcp_status != TA_HDCP_STATUS__SUCCESS)
793                 return MOD_HDCP_STATUS_HDCP2_PREPARE_STREAM_MANAGEMENT_FAILURE;
794
795         hdcp->auth.msg.hdcp2.stream_manage_size = msg_out->prepare.msg1_desc.msg_size;
796
797         memcpy(hdcp->auth.msg.hdcp2.repeater_auth_stream_manage, &msg_out->prepare.transmitter_message[0],
798                sizeof(hdcp->auth.msg.hdcp2.repeater_auth_stream_manage));
799
800         return MOD_HDCP_STATUS_SUCCESS;
801 }
802
803 enum mod_hdcp_status mod_hdcp_hdcp2_validate_stream_ready(struct mod_hdcp *hdcp)
804 {
805         struct psp_context *psp = hdcp->config.psp.handle;
806         struct ta_hdcp_shared_memory *hdcp_cmd;
807         struct ta_hdcp_cmd_hdcp2_process_prepare_authentication_message_input_v2 *msg_in;
808         struct ta_hdcp_cmd_hdcp2_process_prepare_authentication_message_output_v2 *msg_out;
809
810         hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.hdcp_shared_buf;
811         memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
812
813         msg_in = &hdcp_cmd->in_msg.hdcp2_prepare_process_authentication_message_v2;
814         msg_out = &hdcp_cmd->out_msg.hdcp2_prepare_process_authentication_message_v2;
815
816         hdcp2_message_init(hdcp, msg_in);
817
818         msg_in->process.msg1_desc.msg_id = TA_HDCP_HDCP2_MSG_ID__REPEATERAUTH_STREAM_READY;
819
820         msg_in->process.msg1_desc.msg_size = sizeof(hdcp->auth.msg.hdcp2.repeater_auth_stream_ready);
821
822         memcpy(&msg_in->process.receiver_message[0], hdcp->auth.msg.hdcp2.repeater_auth_stream_ready,
823                sizeof(hdcp->auth.msg.hdcp2.repeater_auth_stream_ready));
824
825         hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP2_PREPARE_PROCESS_AUTHENTICATION_MSG_V2;
826         psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
827
828         return (hdcp_cmd->hdcp_status == TA_HDCP_STATUS__SUCCESS) &&
829                                (msg_out->process.msg1_status == TA_HDCP2_MSG_AUTHENTICATION_STATUS__SUCCESS)
830                        ? MOD_HDCP_STATUS_SUCCESS
831                        : MOD_HDCP_STATUS_HDCP2_VALIDATE_STREAM_READY_FAILURE;
832 }
833
834 enum mod_hdcp_status mod_hdcp_hdcp2_get_link_encryption_status(struct mod_hdcp *hdcp,
835                                                                enum mod_hdcp_encryption_status *encryption_status)
836 {
837         struct psp_context *psp = hdcp->config.psp.handle;
838         struct ta_hdcp_shared_memory *hdcp_cmd;
839
840         hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.hdcp_shared_buf;
841
842         memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
843
844         hdcp_cmd->in_msg.hdcp2_get_encryption_status.session_handle = hdcp->auth.id;
845         hdcp_cmd->out_msg.hdcp2_get_encryption_status.protection_level = 0;
846         hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP2_GET_ENCRYPTION_STATUS;
847         *encryption_status = MOD_HDCP_ENCRYPTION_STATUS_HDCP_OFF;
848
849         psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
850
851         if (hdcp_cmd->hdcp_status != TA_HDCP_STATUS__SUCCESS)
852                 return MOD_HDCP_STATUS_FAILURE;
853
854         if (hdcp_cmd->out_msg.hdcp2_get_encryption_status.protection_level == 1) {
855                 if (hdcp_cmd->out_msg.hdcp2_get_encryption_status.hdcp2_type == TA_HDCP2_CONTENT_TYPE__TYPE1)
856                         *encryption_status = MOD_HDCP_ENCRYPTION_STATUS_HDCP2_TYPE1_ON;
857                 else
858                         *encryption_status = MOD_HDCP_ENCRYPTION_STATUS_HDCP2_TYPE0_ON;
859         }
860
861         return MOD_HDCP_STATUS_SUCCESS;
862 }