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_KSV_LIST_NOT_READY: 94 return "MOD_HDCP_STATUS_HDCP1_KSV_LIST_NOT_READY"; 95 case MOD_HDCP_STATUS_HDCP1_VALIDATE_KSV_LIST_FAILURE: 96 return "MOD_HDCP_STATUS_HDCP1_VALIDATE_KSV_LIST_FAILURE"; 97 case MOD_HDCP_STATUS_HDCP1_ENABLE_ENCRYPTION: 98 return "MOD_HDCP_STATUS_HDCP1_ENABLE_ENCRYPTION"; 99 case MOD_HDCP_STATUS_HDCP1_ENABLE_STREAM_ENCRYPTION_FAILURE: 100 return "MOD_HDCP_STATUS_HDCP1_ENABLE_STREAM_ENCRYPTION_FAILURE"; 101 case MOD_HDCP_STATUS_HDCP1_MAX_CASCADE_EXCEEDED_FAILURE: 102 return "MOD_HDCP_STATUS_HDCP1_MAX_CASCADE_EXCEEDED_FAILURE"; 103 case MOD_HDCP_STATUS_HDCP1_MAX_DEVS_EXCEEDED_FAILURE: 104 return "MOD_HDCP_STATUS_HDCP1_MAX_DEVS_EXCEEDED_FAILURE"; 105 case MOD_HDCP_STATUS_HDCP1_DEVICE_COUNT_MISMATCH_FAILURE: 106 return "MOD_HDCP_STATUS_HDCP1_DEVICE_COUNT_MISMATCH_FAILURE"; 107 case MOD_HDCP_STATUS_HDCP1_LINK_INTEGRITY_FAILURE: 108 return "MOD_HDCP_STATUS_HDCP1_LINK_INTEGRITY_FAILURE"; 109 case MOD_HDCP_STATUS_HDCP1_REAUTH_REQUEST_ISSUED: 110 return "MOD_HDCP_STATUS_HDCP1_REAUTH_REQUEST_ISSUED"; 111 case MOD_HDCP_STATUS_HDCP1_LINK_MAINTENANCE_FAILURE: 112 return "MOD_HDCP_STATUS_HDCP1_LINK_MAINTENANCE_FAILURE"; 113 case MOD_HDCP_STATUS_HDCP1_INVALID_BKSV: 114 return "MOD_HDCP_STATUS_HDCP1_INVALID_BKSV"; 115 case MOD_HDCP_STATUS_DDC_FAILURE: 116 return "MOD_HDCP_STATUS_DDC_FAILURE"; 117 case MOD_HDCP_STATUS_INVALID_OPERATION: 118 return "MOD_HDCP_STATUS_INVALID_OPERATION"; 119 case MOD_HDCP_STATUS_HDCP2_NOT_CAPABLE: 120 return "MOD_HDCP_STATUS_HDCP2_NOT_CAPABLE"; 121 case MOD_HDCP_STATUS_HDCP2_CREATE_SESSION_FAILURE: 122 return "MOD_HDCP_STATUS_HDCP2_CREATE_SESSION_FAILURE"; 123 case MOD_HDCP_STATUS_HDCP2_DESTROY_SESSION_FAILURE: 124 return "MOD_HDCP_STATUS_HDCP2_DESTROY_SESSION_FAILURE"; 125 case MOD_HDCP_STATUS_HDCP2_PREP_AKE_INIT_FAILURE: 126 return "MOD_HDCP_STATUS_HDCP2_PREP_AKE_INIT_FAILURE"; 127 case MOD_HDCP_STATUS_HDCP2_AKE_CERT_PENDING: 128 return "MOD_HDCP_STATUS_HDCP2_AKE_CERT_PENDING"; 129 case MOD_HDCP_STATUS_HDCP2_H_PRIME_PENDING: 130 return "MOD_HDCP_STATUS_HDCP2_H_PRIME_PENDING"; 131 case MOD_HDCP_STATUS_HDCP2_PAIRING_INFO_PENDING: 132 return "MOD_HDCP_STATUS_HDCP2_PAIRING_INFO_PENDING"; 133 case MOD_HDCP_STATUS_HDCP2_VALIDATE_AKE_CERT_FAILURE: 134 return "MOD_HDCP_STATUS_HDCP2_VALIDATE_AKE_CERT_FAILURE"; 135 case MOD_HDCP_STATUS_HDCP2_AKE_CERT_REVOKED: 136 return "MOD_HDCP_STATUS_HDCP2_AKE_CERT_REVOKED"; 137 case MOD_HDCP_STATUS_HDCP2_VALIDATE_H_PRIME_FAILURE: 138 return "MOD_HDCP_STATUS_HDCP2_VALIDATE_H_PRIME_FAILURE"; 139 case MOD_HDCP_STATUS_HDCP2_VALIDATE_PAIRING_INFO_FAILURE: 140 return "MOD_HDCP_STATUS_HDCP2_VALIDATE_PAIRING_INFO_FAILURE"; 141 case MOD_HDCP_STATUS_HDCP2_PREP_LC_INIT_FAILURE: 142 return "MOD_HDCP_STATUS_HDCP2_PREP_LC_INIT_FAILURE"; 143 case MOD_HDCP_STATUS_HDCP2_L_PRIME_PENDING: 144 return "MOD_HDCP_STATUS_HDCP2_L_PRIME_PENDING"; 145 case MOD_HDCP_STATUS_HDCP2_VALIDATE_L_PRIME_FAILURE: 146 return "MOD_HDCP_STATUS_HDCP2_VALIDATE_L_PRIME_FAILURE"; 147 case MOD_HDCP_STATUS_HDCP2_PREP_EKS_FAILURE: 148 return "MOD_HDCP_STATUS_HDCP2_PREP_EKS_FAILURE"; 149 case MOD_HDCP_STATUS_HDCP2_ENABLE_ENCRYPTION_FAILURE: 150 return "MOD_HDCP_STATUS_HDCP2_ENABLE_ENCRYPTION_FAILURE"; 151 case MOD_HDCP_STATUS_HDCP2_VALIDATE_RX_ID_LIST_FAILURE: 152 return "MOD_HDCP_STATUS_HDCP2_VALIDATE_RX_ID_LIST_FAILURE"; 153 case MOD_HDCP_STATUS_HDCP2_RX_ID_LIST_REVOKED: 154 return "MOD_HDCP_STATUS_HDCP2_RX_ID_LIST_REVOKED"; 155 case MOD_HDCP_STATUS_HDCP2_RX_ID_LIST_NOT_READY: 156 return "MOD_HDCP_STATUS_HDCP2_RX_ID_LIST_NOT_READY"; 157 case MOD_HDCP_STATUS_HDCP2_ENABLE_STREAM_ENCRYPTION: 158 return "MOD_HDCP_STATUS_HDCP2_ENABLE_STREAM_ENCRYPTION"; 159 case MOD_HDCP_STATUS_HDCP2_STREAM_READY_PENDING: 160 return "MOD_HDCP_STATUS_HDCP2_STREAM_READY_PENDING"; 161 case MOD_HDCP_STATUS_HDCP2_VALIDATE_STREAM_READY_FAILURE: 162 return "MOD_HDCP_STATUS_HDCP2_VALIDATE_STREAM_READY_FAILURE"; 163 case MOD_HDCP_STATUS_HDCP2_PREPARE_STREAM_MANAGEMENT_FAILURE: 164 return "MOD_HDCP_STATUS_HDCP2_PREPARE_STREAM_MANAGEMENT_FAILURE"; 165 case MOD_HDCP_STATUS_HDCP2_REAUTH_REQUEST: 166 return "MOD_HDCP_STATUS_HDCP2_REAUTH_REQUEST"; 167 case MOD_HDCP_STATUS_HDCP2_REAUTH_LINK_INTEGRITY_FAILURE: 168 return "MOD_HDCP_STATUS_HDCP2_REAUTH_LINK_INTEGRITY_FAILURE"; 169 case MOD_HDCP_STATUS_HDCP2_DEVICE_COUNT_MISMATCH_FAILURE: 170 return "MOD_HDCP_STATUS_HDCP2_DEVICE_COUNT_MISMATCH_FAILURE"; 171 default: 172 return "MOD_HDCP_STATUS_UNKNOWN"; 173 } 174 } 175 176 char *mod_hdcp_state_id_to_str(int32_t id) 177 { 178 switch (id) { 179 case HDCP_UNINITIALIZED: 180 return "HDCP_UNINITIALIZED"; 181 case HDCP_INITIALIZED: 182 return "HDCP_INITIALIZED"; 183 case HDCP_CP_NOT_DESIRED: 184 return "HDCP_CP_NOT_DESIRED"; 185 case H1_A0_WAIT_FOR_ACTIVE_RX: 186 return "H1_A0_WAIT_FOR_ACTIVE_RX"; 187 case H1_A1_EXCHANGE_KSVS: 188 return "H1_A1_EXCHANGE_KSVS"; 189 case H1_A2_COMPUTATIONS_A3_VALIDATE_RX_A6_TEST_FOR_REPEATER: 190 return "H1_A2_COMPUTATIONS_A3_VALIDATE_RX_A6_TEST_FOR_REPEATER"; 191 case H1_A45_AUTHENTICATED: 192 return "H1_A45_AUTHENTICATED"; 193 case H1_A8_WAIT_FOR_READY: 194 return "H1_A8_WAIT_FOR_READY"; 195 case H1_A9_READ_KSV_LIST: 196 return "H1_A9_READ_KSV_LIST"; 197 case D1_A0_DETERMINE_RX_HDCP_CAPABLE: 198 return "D1_A0_DETERMINE_RX_HDCP_CAPABLE"; 199 case D1_A1_EXCHANGE_KSVS: 200 return "D1_A1_EXCHANGE_KSVS"; 201 case D1_A23_WAIT_FOR_R0_PRIME: 202 return "D1_A23_WAIT_FOR_R0_PRIME"; 203 case D1_A2_COMPUTATIONS_A3_VALIDATE_RX_A5_TEST_FOR_REPEATER: 204 return "D1_A2_COMPUTATIONS_A3_VALIDATE_RX_A5_TEST_FOR_REPEATER"; 205 case D1_A4_AUTHENTICATED: 206 return "D1_A4_AUTHENTICATED"; 207 case D1_A6_WAIT_FOR_READY: 208 return "D1_A6_WAIT_FOR_READY"; 209 case D1_A7_READ_KSV_LIST: 210 return "D1_A7_READ_KSV_LIST"; 211 case H2_A0_KNOWN_HDCP2_CAPABLE_RX: 212 return "H2_A0_KNOWN_HDCP2_CAPABLE_RX"; 213 case H2_A1_SEND_AKE_INIT: 214 return "H2_A1_SEND_AKE_INIT"; 215 case H2_A1_VALIDATE_AKE_CERT: 216 return "H2_A1_VALIDATE_AKE_CERT"; 217 case H2_A1_SEND_NO_STORED_KM: 218 return "H2_A1_SEND_NO_STORED_KM"; 219 case H2_A1_READ_H_PRIME: 220 return "H2_A1_READ_H_PRIME"; 221 case H2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME: 222 return "H2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME"; 223 case H2_A1_SEND_STORED_KM: 224 return "H2_A1_SEND_STORED_KM"; 225 case H2_A1_VALIDATE_H_PRIME: 226 return "H2_A1_VALIDATE_H_PRIME"; 227 case H2_A2_LOCALITY_CHECK: 228 return "H2_A2_LOCALITY_CHECK"; 229 case H2_A3_EXCHANGE_KS_AND_TEST_FOR_REPEATER: 230 return "H2_A3_EXCHANGE_KS_AND_TEST_FOR_REPEATER"; 231 case H2_ENABLE_ENCRYPTION: 232 return "H2_ENABLE_ENCRYPTION"; 233 case H2_A5_AUTHENTICATED: 234 return "H2_A5_AUTHENTICATED"; 235 case H2_A6_WAIT_FOR_RX_ID_LIST: 236 return "H2_A6_WAIT_FOR_RX_ID_LIST"; 237 case H2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK: 238 return "H2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK"; 239 case H2_A9_SEND_STREAM_MANAGEMENT: 240 return "H2_A9_SEND_STREAM_MANAGEMENT"; 241 case H2_A9_VALIDATE_STREAM_READY: 242 return "H2_A9_VALIDATE_STREAM_READY"; 243 case D2_A0_DETERMINE_RX_HDCP_CAPABLE: 244 return "D2_A0_DETERMINE_RX_HDCP_CAPABLE"; 245 case D2_A1_SEND_AKE_INIT: 246 return "D2_A1_SEND_AKE_INIT"; 247 case D2_A1_VALIDATE_AKE_CERT: 248 return "D2_A1_VALIDATE_AKE_CERT"; 249 case D2_A1_SEND_NO_STORED_KM: 250 return "D2_A1_SEND_NO_STORED_KM"; 251 case D2_A1_READ_H_PRIME: 252 return "D2_A1_READ_H_PRIME"; 253 case D2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME: 254 return "D2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME"; 255 case D2_A1_SEND_STORED_KM: 256 return "D2_A1_SEND_STORED_KM"; 257 case D2_A1_VALIDATE_H_PRIME: 258 return "D2_A1_VALIDATE_H_PRIME"; 259 case D2_A2_LOCALITY_CHECK: 260 return "D2_A2_LOCALITY_CHECK"; 261 case D2_A34_EXCHANGE_KS_AND_TEST_FOR_REPEATER: 262 return "D2_A34_EXCHANGE_KS_AND_TEST_FOR_REPEATER"; 263 case D2_SEND_CONTENT_STREAM_TYPE: 264 return "D2_SEND_CONTENT_STREAM_TYPE"; 265 case D2_ENABLE_ENCRYPTION: 266 return "D2_ENABLE_ENCRYPTION"; 267 case D2_A5_AUTHENTICATED: 268 return "D2_A5_AUTHENTICATED"; 269 case D2_A6_WAIT_FOR_RX_ID_LIST: 270 return "D2_A6_WAIT_FOR_RX_ID_LIST"; 271 case D2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK: 272 return "D2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK"; 273 case D2_A9_SEND_STREAM_MANAGEMENT: 274 return "D2_A9_SEND_STREAM_MANAGEMENT"; 275 case D2_A9_VALIDATE_STREAM_READY: 276 return "D2_A9_VALIDATE_STREAM_READY"; 277 default: 278 return "UNKNOWN_STATE_ID"; 279 }; 280 } 281 282