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 27 #include "hdcp.h" 28 29 void mod_hdcp_dump_binary_message(uint8_t *msg, uint32_t msg_size, 30 uint8_t *buf, uint32_t buf_size) 31 { 32 const uint8_t bytes_per_line = 16, 33 byte_size = 3, 34 newline_size = 1, 35 terminator_size = 1; 36 uint32_t line_count = msg_size / bytes_per_line, 37 trailing_bytes = msg_size % bytes_per_line; 38 uint32_t target_size = (byte_size * bytes_per_line + newline_size) * line_count + 39 byte_size * trailing_bytes + newline_size + terminator_size; 40 uint32_t buf_pos = 0; 41 uint32_t i = 0; 42 43 if (buf_size >= target_size) { 44 for (i = 0; i < msg_size; i++) { 45 if (i % bytes_per_line == 0) 46 buf[buf_pos++] = '\n'; 47 sprintf(&buf[buf_pos], "%02X ", msg[i]); 48 buf_pos += byte_size; 49 } 50 buf[buf_pos++] = '\0'; 51 } 52 } 53 54 char *mod_hdcp_status_to_str(int32_t status) 55 { 56 switch (status) { 57 case MOD_HDCP_STATUS_SUCCESS: 58 return "MOD_HDCP_STATUS_SUCCESS"; 59 case MOD_HDCP_STATUS_FAILURE: 60 return "MOD_HDCP_STATUS_FAILURE"; 61 case MOD_HDCP_STATUS_RESET_NEEDED: 62 return "MOD_HDCP_STATUS_RESET_NEEDED"; 63 case MOD_HDCP_STATUS_DISPLAY_OUT_OF_BOUND: 64 return "MOD_HDCP_STATUS_DISPLAY_OUT_OF_BOUND"; 65 case MOD_HDCP_STATUS_DISPLAY_NOT_FOUND: 66 return "MOD_HDCP_STATUS_DISPLAY_NOT_FOUND"; 67 case MOD_HDCP_STATUS_INVALID_STATE: 68 return "MOD_HDCP_STATUS_INVALID_STATE"; 69 case MOD_HDCP_STATUS_NOT_IMPLEMENTED: 70 return "MOD_HDCP_STATUS_NOT_IMPLEMENTED"; 71 case MOD_HDCP_STATUS_INTERNAL_POLICY_FAILURE: 72 return "MOD_HDCP_STATUS_INTERNAL_POLICY_FAILURE"; 73 case MOD_HDCP_STATUS_UPDATE_TOPOLOGY_FAILURE: 74 return "MOD_HDCP_STATUS_UPDATE_TOPOLOGY_FAILURE"; 75 case MOD_HDCP_STATUS_CREATE_PSP_SERVICE_FAILURE: 76 return "MOD_HDCP_STATUS_CREATE_PSP_SERVICE_FAILURE"; 77 case MOD_HDCP_STATUS_DESTROY_PSP_SERVICE_FAILURE: 78 return "MOD_HDCP_STATUS_DESTROY_PSP_SERVICE_FAILURE"; 79 case MOD_HDCP_STATUS_HDCP1_CREATE_SESSION_FAILURE: 80 return "MOD_HDCP_STATUS_HDCP1_CREATE_SESSION_FAILURE"; 81 case MOD_HDCP_STATUS_HDCP1_DESTROY_SESSION_FAILURE: 82 return "MOD_HDCP_STATUS_HDCP1_DESTROY_SESSION_FAILURE"; 83 case MOD_HDCP_STATUS_HDCP1_VALIDATE_ENCRYPTION_FAILURE: 84 return "MOD_HDCP_STATUS_HDCP1_VALIDATE_ENCRYPTION_FAILURE"; 85 case MOD_HDCP_STATUS_HDCP1_NOT_HDCP_REPEATER: 86 return "MOD_HDCP_STATUS_HDCP1_NOT_HDCP_REPEATER"; 87 case MOD_HDCP_STATUS_HDCP1_NOT_CAPABLE: 88 return "MOD_HDCP_STATUS_HDCP1_NOT_CAPABLE"; 89 case MOD_HDCP_STATUS_HDCP1_R0_PRIME_PENDING: 90 return "MOD_HDCP_STATUS_HDCP1_R0_PRIME_PENDING"; 91 case MOD_HDCP_STATUS_HDCP1_VALIDATE_RX_FAILURE: 92 return "MOD_HDCP_STATUS_HDCP1_VALIDATE_RX_FAILURE"; 93 case MOD_HDCP_STATUS_HDCP1_BKSV_REVOKED: 94 return "MOD_HDCP_STATUS_HDCP1_BKSV_REVOKED"; 95 case MOD_HDCP_STATUS_HDCP1_KSV_LIST_NOT_READY: 96 return "MOD_HDCP_STATUS_HDCP1_KSV_LIST_NOT_READY"; 97 case MOD_HDCP_STATUS_HDCP1_VALIDATE_KSV_LIST_FAILURE: 98 return "MOD_HDCP_STATUS_HDCP1_VALIDATE_KSV_LIST_FAILURE"; 99 case MOD_HDCP_STATUS_HDCP1_KSV_LIST_REVOKED: 100 return "MOD_HDCP_STATUS_HDCP1_KSV_LIST_REVOKED"; 101 case MOD_HDCP_STATUS_HDCP1_ENABLE_ENCRYPTION_FAILURE: 102 return "MOD_HDCP_STATUS_HDCP1_ENABLE_ENCRYPTION_FAILURE"; 103 case MOD_HDCP_STATUS_HDCP1_ENABLE_STREAM_ENCRYPTION_FAILURE: 104 return "MOD_HDCP_STATUS_HDCP1_ENABLE_STREAM_ENCRYPTION_FAILURE"; 105 case MOD_HDCP_STATUS_HDCP1_MAX_CASCADE_EXCEEDED_FAILURE: 106 return "MOD_HDCP_STATUS_HDCP1_MAX_CASCADE_EXCEEDED_FAILURE"; 107 case MOD_HDCP_STATUS_HDCP1_MAX_DEVS_EXCEEDED_FAILURE: 108 return "MOD_HDCP_STATUS_HDCP1_MAX_DEVS_EXCEEDED_FAILURE"; 109 case MOD_HDCP_STATUS_HDCP1_DEVICE_COUNT_MISMATCH_FAILURE: 110 return "MOD_HDCP_STATUS_HDCP1_DEVICE_COUNT_MISMATCH_FAILURE"; 111 case MOD_HDCP_STATUS_HDCP1_LINK_INTEGRITY_FAILURE: 112 return "MOD_HDCP_STATUS_HDCP1_LINK_INTEGRITY_FAILURE"; 113 case MOD_HDCP_STATUS_HDCP1_REAUTH_REQUEST_ISSUED: 114 return "MOD_HDCP_STATUS_HDCP1_REAUTH_REQUEST_ISSUED"; 115 case MOD_HDCP_STATUS_HDCP1_LINK_MAINTENANCE_FAILURE: 116 return "MOD_HDCP_STATUS_HDCP1_LINK_MAINTENANCE_FAILURE"; 117 case MOD_HDCP_STATUS_HDCP1_INVALID_BKSV: 118 return "MOD_HDCP_STATUS_HDCP1_INVALID_BKSV"; 119 case MOD_HDCP_STATUS_DDC_FAILURE: 120 return "MOD_HDCP_STATUS_DDC_FAILURE"; 121 case MOD_HDCP_STATUS_INVALID_OPERATION: 122 return "MOD_HDCP_STATUS_INVALID_OPERATION"; 123 case MOD_HDCP_STATUS_HDCP2_NOT_CAPABLE: 124 return "MOD_HDCP_STATUS_HDCP2_NOT_CAPABLE"; 125 case MOD_HDCP_STATUS_HDCP2_CREATE_SESSION_FAILURE: 126 return "MOD_HDCP_STATUS_HDCP2_CREATE_SESSION_FAILURE"; 127 case MOD_HDCP_STATUS_HDCP2_DESTROY_SESSION_FAILURE: 128 return "MOD_HDCP_STATUS_HDCP2_DESTROY_SESSION_FAILURE"; 129 case MOD_HDCP_STATUS_HDCP2_PREP_AKE_INIT_FAILURE: 130 return "MOD_HDCP_STATUS_HDCP2_PREP_AKE_INIT_FAILURE"; 131 case MOD_HDCP_STATUS_HDCP2_AKE_CERT_PENDING: 132 return "MOD_HDCP_STATUS_HDCP2_AKE_CERT_PENDING"; 133 case MOD_HDCP_STATUS_HDCP2_H_PRIME_PENDING: 134 return "MOD_HDCP_STATUS_HDCP2_H_PRIME_PENDING"; 135 case MOD_HDCP_STATUS_HDCP2_PAIRING_INFO_PENDING: 136 return "MOD_HDCP_STATUS_HDCP2_PAIRING_INFO_PENDING"; 137 case MOD_HDCP_STATUS_HDCP2_VALIDATE_AKE_CERT_FAILURE: 138 return "MOD_HDCP_STATUS_HDCP2_VALIDATE_AKE_CERT_FAILURE"; 139 case MOD_HDCP_STATUS_HDCP2_AKE_CERT_REVOKED: 140 return "MOD_HDCP_STATUS_HDCP2_AKE_CERT_REVOKED"; 141 case MOD_HDCP_STATUS_HDCP2_VALIDATE_H_PRIME_FAILURE: 142 return "MOD_HDCP_STATUS_HDCP2_VALIDATE_H_PRIME_FAILURE"; 143 case MOD_HDCP_STATUS_HDCP2_VALIDATE_PAIRING_INFO_FAILURE: 144 return "MOD_HDCP_STATUS_HDCP2_VALIDATE_PAIRING_INFO_FAILURE"; 145 case MOD_HDCP_STATUS_HDCP2_PREP_LC_INIT_FAILURE: 146 return "MOD_HDCP_STATUS_HDCP2_PREP_LC_INIT_FAILURE"; 147 case MOD_HDCP_STATUS_HDCP2_L_PRIME_PENDING: 148 return "MOD_HDCP_STATUS_HDCP2_L_PRIME_PENDING"; 149 case MOD_HDCP_STATUS_HDCP2_VALIDATE_L_PRIME_FAILURE: 150 return "MOD_HDCP_STATUS_HDCP2_VALIDATE_L_PRIME_FAILURE"; 151 case MOD_HDCP_STATUS_HDCP2_PREP_EKS_FAILURE: 152 return "MOD_HDCP_STATUS_HDCP2_PREP_EKS_FAILURE"; 153 case MOD_HDCP_STATUS_HDCP2_ENABLE_ENCRYPTION_FAILURE: 154 return "MOD_HDCP_STATUS_HDCP2_ENABLE_ENCRYPTION_FAILURE"; 155 case MOD_HDCP_STATUS_HDCP2_VALIDATE_RX_ID_LIST_FAILURE: 156 return "MOD_HDCP_STATUS_HDCP2_VALIDATE_RX_ID_LIST_FAILURE"; 157 case MOD_HDCP_STATUS_HDCP2_RX_ID_LIST_REVOKED: 158 return "MOD_HDCP_STATUS_HDCP2_RX_ID_LIST_REVOKED"; 159 case MOD_HDCP_STATUS_HDCP2_RX_ID_LIST_NOT_READY: 160 return "MOD_HDCP_STATUS_HDCP2_RX_ID_LIST_NOT_READY"; 161 case MOD_HDCP_STATUS_HDCP2_ENABLE_STREAM_ENCRYPTION_FAILURE: 162 return "MOD_HDCP_STATUS_HDCP2_ENABLE_STREAM_ENCRYPTION_FAILURE"; 163 case MOD_HDCP_STATUS_HDCP2_STREAM_READY_PENDING: 164 return "MOD_HDCP_STATUS_HDCP2_STREAM_READY_PENDING"; 165 case MOD_HDCP_STATUS_HDCP2_VALIDATE_STREAM_READY_FAILURE: 166 return "MOD_HDCP_STATUS_HDCP2_VALIDATE_STREAM_READY_FAILURE"; 167 case MOD_HDCP_STATUS_HDCP2_PREPARE_STREAM_MANAGEMENT_FAILURE: 168 return "MOD_HDCP_STATUS_HDCP2_PREPARE_STREAM_MANAGEMENT_FAILURE"; 169 case MOD_HDCP_STATUS_HDCP2_REAUTH_REQUEST: 170 return "MOD_HDCP_STATUS_HDCP2_REAUTH_REQUEST"; 171 case MOD_HDCP_STATUS_HDCP2_REAUTH_LINK_INTEGRITY_FAILURE: 172 return "MOD_HDCP_STATUS_HDCP2_REAUTH_LINK_INTEGRITY_FAILURE"; 173 case MOD_HDCP_STATUS_HDCP2_DEVICE_COUNT_MISMATCH_FAILURE: 174 return "MOD_HDCP_STATUS_HDCP2_DEVICE_COUNT_MISMATCH_FAILURE"; 175 case MOD_HDCP_STATUS_UNSUPPORTED_PSP_VER_FAILURE: 176 return "MOD_HDCP_STATUS_UNSUPPORTED_PSP_VER_FAILURE"; 177 default: 178 return "MOD_HDCP_STATUS_UNKNOWN"; 179 } 180 } 181 182 char *mod_hdcp_state_id_to_str(int32_t id) 183 { 184 switch (id) { 185 case HDCP_UNINITIALIZED: 186 return "HDCP_UNINITIALIZED"; 187 case HDCP_INITIALIZED: 188 return "HDCP_INITIALIZED"; 189 case HDCP_CP_NOT_DESIRED: 190 return "HDCP_CP_NOT_DESIRED"; 191 case H1_A0_WAIT_FOR_ACTIVE_RX: 192 return "H1_A0_WAIT_FOR_ACTIVE_RX"; 193 case H1_A1_EXCHANGE_KSVS: 194 return "H1_A1_EXCHANGE_KSVS"; 195 case H1_A2_COMPUTATIONS_A3_VALIDATE_RX_A6_TEST_FOR_REPEATER: 196 return "H1_A2_COMPUTATIONS_A3_VALIDATE_RX_A6_TEST_FOR_REPEATER"; 197 case H1_A45_AUTHENTICATED: 198 return "H1_A45_AUTHENTICATED"; 199 case H1_A8_WAIT_FOR_READY: 200 return "H1_A8_WAIT_FOR_READY"; 201 case H1_A9_READ_KSV_LIST: 202 return "H1_A9_READ_KSV_LIST"; 203 case D1_A0_DETERMINE_RX_HDCP_CAPABLE: 204 return "D1_A0_DETERMINE_RX_HDCP_CAPABLE"; 205 case D1_A1_EXCHANGE_KSVS: 206 return "D1_A1_EXCHANGE_KSVS"; 207 case D1_A23_WAIT_FOR_R0_PRIME: 208 return "D1_A23_WAIT_FOR_R0_PRIME"; 209 case D1_A2_COMPUTATIONS_A3_VALIDATE_RX_A5_TEST_FOR_REPEATER: 210 return "D1_A2_COMPUTATIONS_A3_VALIDATE_RX_A5_TEST_FOR_REPEATER"; 211 case D1_A4_AUTHENTICATED: 212 return "D1_A4_AUTHENTICATED"; 213 case D1_A6_WAIT_FOR_READY: 214 return "D1_A6_WAIT_FOR_READY"; 215 case D1_A7_READ_KSV_LIST: 216 return "D1_A7_READ_KSV_LIST"; 217 case H2_A0_KNOWN_HDCP2_CAPABLE_RX: 218 return "H2_A0_KNOWN_HDCP2_CAPABLE_RX"; 219 case H2_A1_SEND_AKE_INIT: 220 return "H2_A1_SEND_AKE_INIT"; 221 case H2_A1_VALIDATE_AKE_CERT: 222 return "H2_A1_VALIDATE_AKE_CERT"; 223 case H2_A1_SEND_NO_STORED_KM: 224 return "H2_A1_SEND_NO_STORED_KM"; 225 case H2_A1_READ_H_PRIME: 226 return "H2_A1_READ_H_PRIME"; 227 case H2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME: 228 return "H2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME"; 229 case H2_A1_SEND_STORED_KM: 230 return "H2_A1_SEND_STORED_KM"; 231 case H2_A1_VALIDATE_H_PRIME: 232 return "H2_A1_VALIDATE_H_PRIME"; 233 case H2_A2_LOCALITY_CHECK: 234 return "H2_A2_LOCALITY_CHECK"; 235 case H2_A3_EXCHANGE_KS_AND_TEST_FOR_REPEATER: 236 return "H2_A3_EXCHANGE_KS_AND_TEST_FOR_REPEATER"; 237 case H2_ENABLE_ENCRYPTION: 238 return "H2_ENABLE_ENCRYPTION"; 239 case H2_A5_AUTHENTICATED: 240 return "H2_A5_AUTHENTICATED"; 241 case H2_A6_WAIT_FOR_RX_ID_LIST: 242 return "H2_A6_WAIT_FOR_RX_ID_LIST"; 243 case H2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK: 244 return "H2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK"; 245 case H2_A9_SEND_STREAM_MANAGEMENT: 246 return "H2_A9_SEND_STREAM_MANAGEMENT"; 247 case H2_A9_VALIDATE_STREAM_READY: 248 return "H2_A9_VALIDATE_STREAM_READY"; 249 case D2_A0_DETERMINE_RX_HDCP_CAPABLE: 250 return "D2_A0_DETERMINE_RX_HDCP_CAPABLE"; 251 case D2_A1_SEND_AKE_INIT: 252 return "D2_A1_SEND_AKE_INIT"; 253 case D2_A1_VALIDATE_AKE_CERT: 254 return "D2_A1_VALIDATE_AKE_CERT"; 255 case D2_A1_SEND_NO_STORED_KM: 256 return "D2_A1_SEND_NO_STORED_KM"; 257 case D2_A1_READ_H_PRIME: 258 return "D2_A1_READ_H_PRIME"; 259 case D2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME: 260 return "D2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME"; 261 case D2_A1_SEND_STORED_KM: 262 return "D2_A1_SEND_STORED_KM"; 263 case D2_A1_VALIDATE_H_PRIME: 264 return "D2_A1_VALIDATE_H_PRIME"; 265 case D2_A2_LOCALITY_CHECK: 266 return "D2_A2_LOCALITY_CHECK"; 267 case D2_A34_EXCHANGE_KS_AND_TEST_FOR_REPEATER: 268 return "D2_A34_EXCHANGE_KS_AND_TEST_FOR_REPEATER"; 269 case D2_SEND_CONTENT_STREAM_TYPE: 270 return "D2_SEND_CONTENT_STREAM_TYPE"; 271 case D2_ENABLE_ENCRYPTION: 272 return "D2_ENABLE_ENCRYPTION"; 273 case D2_A5_AUTHENTICATED: 274 return "D2_A5_AUTHENTICATED"; 275 case D2_A6_WAIT_FOR_RX_ID_LIST: 276 return "D2_A6_WAIT_FOR_RX_ID_LIST"; 277 case D2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK: 278 return "D2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK"; 279 case D2_A9_SEND_STREAM_MANAGEMENT: 280 return "D2_A9_SEND_STREAM_MANAGEMENT"; 281 case D2_A9_VALIDATE_STREAM_READY: 282 return "D2_A9_VALIDATE_STREAM_READY"; 283 default: 284 return "UNKNOWN_STATE_ID"; 285 } 286 } 287 288