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 default: 120 return "MOD_HDCP_STATUS_UNKNOWN"; 121 } 122 } 123 124 char *mod_hdcp_state_id_to_str(int32_t id) 125 { 126 switch (id) { 127 case HDCP_UNINITIALIZED: 128 return "HDCP_UNINITIALIZED"; 129 case HDCP_INITIALIZED: 130 return "HDCP_INITIALIZED"; 131 case HDCP_CP_NOT_DESIRED: 132 return "HDCP_CP_NOT_DESIRED"; 133 case H1_A0_WAIT_FOR_ACTIVE_RX: 134 return "H1_A0_WAIT_FOR_ACTIVE_RX"; 135 case H1_A1_EXCHANGE_KSVS: 136 return "H1_A1_EXCHANGE_KSVS"; 137 case H1_A2_COMPUTATIONS_A3_VALIDATE_RX_A6_TEST_FOR_REPEATER: 138 return "H1_A2_COMPUTATIONS_A3_VALIDATE_RX_A6_TEST_FOR_REPEATER"; 139 case H1_A45_AUTHENTICATED: 140 return "H1_A45_AUTHENTICATED"; 141 case H1_A8_WAIT_FOR_READY: 142 return "H1_A8_WAIT_FOR_READY"; 143 case H1_A9_READ_KSV_LIST: 144 return "H1_A9_READ_KSV_LIST"; 145 case D1_A0_DETERMINE_RX_HDCP_CAPABLE: 146 return "D1_A0_DETERMINE_RX_HDCP_CAPABLE"; 147 case D1_A1_EXCHANGE_KSVS: 148 return "D1_A1_EXCHANGE_KSVS"; 149 case D1_A23_WAIT_FOR_R0_PRIME: 150 return "D1_A23_WAIT_FOR_R0_PRIME"; 151 case D1_A2_COMPUTATIONS_A3_VALIDATE_RX_A5_TEST_FOR_REPEATER: 152 return "D1_A2_COMPUTATIONS_A3_VALIDATE_RX_A5_TEST_FOR_REPEATER"; 153 case D1_A4_AUTHENTICATED: 154 return "D1_A4_AUTHENTICATED"; 155 case D1_A6_WAIT_FOR_READY: 156 return "D1_A6_WAIT_FOR_READY"; 157 case D1_A7_READ_KSV_LIST: 158 return "D1_A7_READ_KSV_LIST"; 159 default: 160 return "UNKNOWN_STATE_ID"; 161 }; 162 } 163 164