1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef HDMI_HDCP_H 10 #define HDMI_HDCP_H 11 12 #include "hdf_base.h" 13 #include "osal_mutex.h" 14 15 #ifdef __cplusplus 16 #if __cplusplus 17 extern "C" { 18 #endif 19 #endif /* __cplusplus */ 20 21 /* HDCP(High-bandwidth Digital Content Protection) Sysytem. */ 22 23 enum HdmiHdcpPortOffset { 24 /* HDCP 1.4 Spec */ 25 HDMI_HDCP_BKSV = 0x00, /* Rd, 5 bytes */ 26 HDMI_HDCP_RI = 0x08, /* Rd, 2 bytes */ 27 HDMI_HDCP_PJ = 0x0A, /* Rd, 1 byte */ 28 HDMI_HDCP_AKSV = 0x10, /* Wr, 5 bytes */ 29 HDMI_HDCP_AINFO = 0x15, /* Wr, 1 byte */ 30 HDMI_HDCP_AN = 0x18, /* Wr, 8 bytes */ 31 HDMI_HDCP_V_H0 = 0x20, /* Rd, 4 bytes */ 32 HDMI_HDCP_V_H1 = 0x24, /* Rd, 4 bytes */ 33 HDMI_HDCP_V_H2 = 0x28, /* Rd, 4 bytes */ 34 HDMI_HDCP_V_H3 = 0x2C, /* Rd, 4 bytes */ 35 HDMI_HDCP_V_H4 = 0x30, /* Rd, 4 bytes */ 36 HDMI_HDCP_BCAPS = 0x40, /* Rd, 1 byte */ 37 HDMI_HDCP_BSTATUS = 0x41, /* Rd, 2 bytes */ 38 HDMI_HDCP_KSV_FIFO = 0x43, /* Rd, 1 byte */ 39 40 /* HDCP 2.2 Spec */ 41 HDMI_HDCP_HDCP2VERSION = 0x50, /* Rd, 1 byte */ 42 HDMI_HDCP_WRITE_MSG = 0x60, /* Wr, 1 byte */ 43 HDMI_HDCP_RXSTATUS = 0x70, /* Rd, 2 bytes */ 44 HDMI_HDCP_READ_MSG = 0x80, /* Rd, 1 byte */ 45 }; 46 47 /* HDCP 2.2 Read/Write Message Id */ 48 enum HdmiHdcpMsgId { 49 HDMI_HDCP_MSG_AKE_INIT = 2, /* Write, 12 bytes */ 50 HDMI_HDCP_MSG_AKE_SEND_CERT = 3, /* Read, 534 bytes */ 51 HDMI_HDCP_MSG_AKE_NO_STORED_KM = 4, /* Write, 129 bytes */ 52 HDMI_HDCP_MSG_AKE_STORED_KM = 5, /* Write, 33 bytes */ 53 HDMI_HDCP_MSG_AKE_SEND_H_PRIME = 7, /* Read, 33 bytes */ 54 HDMI_HDCP_MSG_AKE_SEND_PAIRING_INFO = 8, /* Read, 17 bytes */ 55 HDMI_HDCP_MSG_LC_INIT = 9, /* Write, 9 bytes */ 56 HDMI_HDCP_MSG_LC_SEND_L_PRIME = 10, /* Read, 33 bytes */ 57 HDMI_HDCP_MSG_SKE_SEND_EKS = 11, /* Write, 25 bytes */ 58 HDMI_HDCP_MSG_REPEATER_AUTH_SEND_RCVID_LIST = 12, /* Read, 22 + 5 * device_count bytes */ 59 HDMI_HDCP_MSG_REPEATER_AUTH_SEND_ACK = 15, /* Write, 17 bytes */ 60 HDMI_HDCP_MSG_REPEATER_AUTH_STREAM_MANAGE = 16, /* Write, 6 + 2 * k bytes */ 61 HDMI_HDCP_MSG_REPEATER_AUTH_STREAM_READY = 17, /* Read, 33 bytes */ 62 }; 63 64 enum HdmiHdcpRegOptType { 65 /* HDCP 1.4 Spec */ 66 HDMI_HDCP_OPT_WRITE_BKSV = 0x00, 67 HDMI_HDCP_OPT_WRITE_RI = 0x01, 68 HDMI_HDCP_OPT_WRITE_PJ = 0x02, 69 HDMI_HDCP_OPT_WRITE_V_H0 = 0x03, 70 HDMI_HDCP_OPT_WRITE_V_H1 = 0x04, 71 HDMI_HDCP_OPT_WRITE_V_H2 = 0x05, 72 HDMI_HDCP_OPT_WRITE_V_H3 = 0x06, 73 HDMI_HDCP_OPT_WRITE_V_H4 = 0x07, 74 HDMI_HDCP_OPT_WRITE_V_H_ALL = 0x08, 75 HDMI_HDCP_OPT_WRITE_BCAPS = 0x0C, 76 HDMI_HDCP_OPT_WRITE_BSTATUS = 0x0D, 77 HDMI_HDCP_OPT_WRITE_KSV_FIFO = 0x0E, 78 HDMI_HDCP_OPT_RESET_SHA = 0x0F, 79 HDMI_HDCP_OPT_CHECK_V = 0x10, 80 HDMI_HDCP_OPT_CHECK_R = 0x11, 81 HDMI_HDCP_OPT_AUTH_FAIL = 0x12, 82 HDMI_HDCP_OPT_AUTH_DONE = 0x13, 83 HDMI_HDCP_OPT_AUTH_CLOSE = 0x14, 84 }; 85 86 #define HDMI_HDCP_MSG_BKSV_LEN 5 87 #define HDMI_HDCP_MSG_RI_LEN 2 88 #define HDMI_HDCP_MSG_PJ_LEN 1 89 #define HDMI_HDCP_MSG_AKSV_LEN 5 90 #define HDMI_HDCP_MSG_AINFO_LEN 1 91 #define HDMI_HDCP_MSG_AN_LEN 8 92 #define HDMI_HDCP_MSG_PER_VH_LEN 4 93 #define HDMI_HDCP_MSG_ALL_VH_LEN 20 94 #define HDMI_HDCP_MSG_BCAPS_LEN 1 95 #define HDMI_HDCP_MSG_BSTATUS_LEN 2 96 #define HDMI_HDCP_MSG_KSV_FIFO_LEN 1 97 #define HDMI_HDCP_DEVICE_COUNT_MAX 127 98 #define HDMI_HDCP_MSG_KSV_MAX_LEN (5 * HDMI_HDCP_DEVICE_COUNT_MAX) 99 #define HDMI_HDCP_GET_KSV_LEN(x) (5 * (x)) 100 101 #define HDMI_HDCP_AKSV_ONE_NUM 20 102 #define HDMI_HDCP_BCAPS_REPEATER_MARK 0x40 103 #define HDMI_HDCP_BCAPS_KSV_FIFO_READY_MARK 0x20 104 #define HDMI_HDCP_DEFAULT_READ_REG_TRY 100 105 #define HDMI_HDCP_WAIT_KSV_LIST_TIMES 5000 /* 5s */ 106 #define HDMI_HDCP_WAIT_KSV_LIST_READ_REG_INTERVAL 20 /* 20ms */ 107 #define HDMI_HDCP_WAIT_KSV_LIST_READ_REG_CNT \ 108 (HDMI_HDCP_WAIT_KSV_LIST_TIMES / HDMI_HDCP_WAIT_KSV_LIST_READ_REG_INTERVAL) 109 110 #define HDMI_HDCP_BSTATUS_DEVICE_COUNT_MARK 0x7F 111 #define HDMI_HDCP_BSTATUS_MAX_DEVS_EXCEEDED_MARK (1 << 7) 112 #define HDMI_HDCP_BSTATUS_MAX_CASCADE_EXCEEDED_MARK (1 << 11) 113 #define HDMI_HDCP_BSTATUS_DEPTH_MARK 0x07 114 #define HDMI_HDCP_BSTATUS_DEPTH_SHIFT 8 115 116 117 #define HDMI_HDCP_MSG_HDCP2VERSION_LEN 1 118 #define HDMI_HDCP_MSG_RXSTATUS_LEN 2 119 #define HDMI_HDCP_MSG_AKE_INIT_LEN 12 120 #define HDMI_HDCP_MSG_AKE_CERT_LEN 534 121 #define HDMI_HDCP_MSG_AKE_NO_STORED_KM_LEN 129 122 #define HDMI_HDCP_MSG_AKE_STORED_KM_LEN 33 123 #define HDMI_HDCP_MSG_AKE_H_PRIME_LEN 33 124 #define HDMI_HDCP_MSG_AKE_PAIRING_INFO 17 125 #define HDMI_HDCP_MSG_LC_INIT_LEN 9 126 #define HDMI_HDCP_MSG_LC_L_PRIME_LEN 33 127 #define HDMI_HDCP_MSG_SKE_EKS_LEN 25 128 #define HDMI_HDCP_MSG_AUTH_RCVID_LIST_LEN (22 + 5 * 31) 129 #define HDMI_HDCP_MSG_REPEATER_AUTH_ACK_LEN 17 130 #define HDMI_HDCP_MSG_REPEATER_AUTH_STREAM_MANAGE_LEN (6 + 2 * 31) 131 #define HDMI_HDCP_MSG_REPEATER_AUTH_STREAM_READY_LEN 33 132 133 #define HDMI_HDCP_2_2_VERSION 2 134 #define HDMI_HDCP_GET_AUTH_RCVID_LIST_LEN(x) (22 + (5 * (x))) 135 136 struct HdmiHdcpMsg { 137 /* HDCP 1.4 message */ 138 uint8_t bksv[HDMI_HDCP_MSG_BKSV_LEN]; 139 uint8_t ri[HDMI_HDCP_MSG_RI_LEN]; 140 uint8_t pj; 141 uint8_t aksv[HDMI_HDCP_MSG_AKSV_LEN]; 142 uint8_t ainfo; 143 uint8_t an[HDMI_HDCP_MSG_AN_LEN]; 144 uint8_t vh[HDMI_HDCP_MSG_ALL_VH_LEN]; 145 uint8_t bcaps; 146 uint8_t bstatus[HDMI_HDCP_MSG_BSTATUS_LEN]; 147 uint8_t ksvList[HDMI_HDCP_MSG_KSV_MAX_LEN]; 148 uint32_t ksvLen; 149 150 /* HDCP 2.2 Message */ 151 uint8_t Hdcp2Version; 152 uint8_t rxStatus[HDMI_HDCP_MSG_RXSTATUS_LEN]; 153 uint8_t akeInit[HDMI_HDCP_MSG_AKE_INIT_LEN]; 154 uint8_t akeCert[HDMI_HDCP_MSG_AKE_CERT_LEN]; 155 uint8_t akeNoStoredKm[HDMI_HDCP_MSG_AKE_NO_STORED_KM_LEN]; 156 uint8_t akeStoredKm[HDMI_HDCP_MSG_AKE_STORED_KM_LEN]; 157 uint8_t akeHPrime[HDMI_HDCP_MSG_AKE_H_PRIME_LEN]; 158 uint8_t akePairingInfo[HDMI_HDCP_MSG_AKE_PAIRING_INFO]; 159 uint8_t lcInit[HDMI_HDCP_MSG_LC_INIT_LEN]; 160 uint8_t lcLPrime[HDMI_HDCP_MSG_LC_L_PRIME_LEN]; 161 uint8_t skeEks[HDMI_HDCP_MSG_SKE_EKS_LEN]; 162 uint8_t rxIdList[HDMI_HDCP_MSG_AUTH_RCVID_LIST_LEN]; 163 uint32_t rxIdListLen; 164 uint8_t authAck[HDMI_HDCP_MSG_REPEATER_AUTH_ACK_LEN]; 165 uint8_t authStreamManage[HDMI_HDCP_MSG_REPEATER_AUTH_STREAM_MANAGE_LEN]; 166 uint32_t authStreamManageLen; 167 uint8_t authStreamReady[HDMI_HDCP_MSG_REPEATER_AUTH_STREAM_READY_LEN]; 168 }; 169 170 enum HdmiHdcpAuthState { 171 HDMI_HDCP_AUTH_INACTIVE = 0, 172 HDMI_HDCP_AUTH_AKSV_INVALID = 1, 173 HDMI_HDCP_AUTH_DOING = 2, 174 HDMI_HDCP_AUTH_DONE = 3, 175 HDMI_HDCP_AUTH_FAIL = 4, 176 }; 177 178 #define HDMI_HDCP_AUTH_MAX_RETRY_CNT 10 179 struct HdmiHdcp { 180 struct OsalMutex hdcpMutex; 181 enum HdmiHdcpAuthState state; 182 uint8_t authRetryCnt; 183 /* HDCP 1.4 */ 184 uint8_t aksv[HDMI_HDCP_MSG_AKSV_LEN]; /* need driver to generate */ 185 uint8_t an[HDMI_HDCP_MSG_AN_LEN]; /* need driver to generate */ 186 uint8_t bksv[HDMI_HDCP_MSG_BKSV_LEN]; 187 uint8_t bcaps; 188 uint8_t ri[HDMI_HDCP_MSG_RI_LEN]; 189 uint8_t bstatus[HDMI_HDCP_MSG_BSTATUS_LEN]; 190 uint8_t deviceCount; 191 uint8_t ksvList[HDMI_HDCP_MSG_KSV_MAX_LEN]; 192 uint32_t ksvLen; 193 uint8_t vh[HDMI_HDCP_MSG_ALL_VH_LEN]; 194 bool aksvValid; 195 void *priv; 196 }; 197 198 struct HdmiHdcpStatus { 199 bool hdcp22; 200 bool hdcp14; 201 uint8_t bksv[HDMI_HDCP_MSG_BKSV_LEN]; 202 uint8_t aksv[HDMI_HDCP_MSG_AKSV_LEN]; 203 }; 204 205 int32_t HdmiHdcpOpen(struct HdmiHdcp *hdcp); 206 void HdmiHdcpClose(struct HdmiHdcp *hdcp); 207 208 #ifdef __cplusplus 209 #if __cplusplus 210 } 211 #endif 212 #endif /* __cplusplus */ 213 214 #endif /* HDMI_HDCP_H */ 215