| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2002-2008, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bhdmlib_hdcp.c $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/35 $ |
|---|
| 12 | * $brcm_Date: 8/14/08 6:02p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * This module contains function calls used to test the HDCP Authentication |
|---|
| 16 | * of an DVI or HDMI receiver. These calls make use of the transport (BXPT) |
|---|
| 17 | * and HDMI (BHDM) porting interface modules |
|---|
| 18 | * |
|---|
| 19 | * Revision History: |
|---|
| 20 | * |
|---|
| 21 | * $brcm_Log: /magnum/syslib/hdmlib/bhdmlib_hdcp.c $ |
|---|
| 22 | * |
|---|
| 23 | * Hydra_Software_Devel/35 8/14/08 6:02p vle |
|---|
| 24 | * PR 45705: Check for existence of BTMR_Handle before starting HDCP |
|---|
| 25 | * authentication |
|---|
| 26 | * |
|---|
| 27 | * Hydra_Software_Devel/34 4/23/08 4:39p rgreen |
|---|
| 28 | * PR42107: Remove prior HDCP Repeater Simulation code used to test |
|---|
| 29 | * epeaters unctionality hen epeaters were not widely available |
|---|
| 30 | * |
|---|
| 31 | * Hydra_Software_Devel/33 4/23/08 4:31p rgreen |
|---|
| 32 | * PR42107: Send Encrypted HDCP frames once repeater authentication has |
|---|
| 33 | * completed successfully |
|---|
| 34 | * |
|---|
| 35 | * Hydra_Software_Devel/32 4/2/08 2:31p vle |
|---|
| 36 | * PR 40101: Time HDCP Keyloader function to accurately calculate |
|---|
| 37 | * appropriate wait time before reading R0' |
|---|
| 38 | * |
|---|
| 39 | * Hydra_Software_Devel/31 2/28/08 11:08a rgreen |
|---|
| 40 | * PR40101 : On Aegis based chips, adjust VxWorks to full 100ms for DCP |
|---|
| 41 | * Compliance test |
|---|
| 42 | * |
|---|
| 43 | * Hydra_Software_Devel/30 1/30/08 6:58p vle |
|---|
| 44 | * PR 39077: Clear authentication if there is an error authenticate |
|---|
| 45 | * attached repeater. |
|---|
| 46 | * |
|---|
| 47 | * Hydra_Software_Devel/29 10/10/07 11:02a rgreen |
|---|
| 48 | * PR35874 ,PR31560: |
|---|
| 49 | * Read/Write Repeater KSV FIFO only if devices are attached |
|---|
| 50 | * Increase delay before reading R0' to ensure meeting 100ms HDCP |
|---|
| 51 | * requirement. |
|---|
| 52 | * |
|---|
| 53 | * Hydra_Software_Devel/28 9/17/07 4:09p rgreen |
|---|
| 54 | * PR34967: Stop Authentication process when MAX_CASCADE_EXCEEDED is set |
|---|
| 55 | * in repeaters BStatus register |
|---|
| 56 | * |
|---|
| 57 | * Hydra_Software_Devel/27 7/11/07 6:15p rgreen |
|---|
| 58 | * PR31560,PR3296: Restore use of BKNI_Sleep vs BKNI_Delay to minimize |
|---|
| 59 | * effect of delay. Refactor of HDCP Authenitication process to be |
|---|
| 60 | * implemented moving delay control to the app |
|---|
| 61 | * |
|---|
| 62 | * Hydra_Software_Devel/26 5/23/07 11:31p rgreen |
|---|
| 63 | * PR31560:Remove excess delay in reading HDCP R0 value from receiver |
|---|
| 64 | * |
|---|
| 65 | * Hydra_Software_Devel/25 1/25/07 6:58p vle |
|---|
| 66 | * PR 25502: Add 100ms delay to allow Rx R0 to be ready at receiver. |
|---|
| 67 | * |
|---|
| 68 | * Hydra_Software_Devel/24 8/11/06 1:15p rgreen |
|---|
| 69 | * PR22187: Fix HDCP Key Loader to use standalone HSM PI |
|---|
| 70 | * |
|---|
| 71 | * Hydra_Software_Devel/23 5/2/06 3:11p rgreen |
|---|
| 72 | * PR20139: Re-Enable compilation for HSM for HDCP |
|---|
| 73 | * |
|---|
| 74 | * Hydra_Software_Devel/22 3/10/06 1:13p rgreen |
|---|
| 75 | * PR19265: Add BCM97400 HDMI Support; No HDCP yet |
|---|
| 76 | * |
|---|
| 77 | * Hydra_Software_Devel/21 2/24/06 7:58p rgreen |
|---|
| 78 | * PR19265: Remove un-needed header file |
|---|
| 79 | * |
|---|
| 80 | * Hydra_Software_Devel/20 2/8/06 5:00p rgreen |
|---|
| 81 | * PR8896: Fix compilation warnings. |
|---|
| 82 | * |
|---|
| 83 | * Hydra_Software_Devel/19 10/21/05 5:44p rgreen |
|---|
| 84 | * PR17750: Fix Ksv FIFO Ready message |
|---|
| 85 | * |
|---|
| 86 | * Hydra_Software_Devel/18 10/20/05 5:31p erickson |
|---|
| 87 | * PR17108: added temp 7401 hacks |
|---|
| 88 | * |
|---|
| 89 | * Hydra_Software_Devel/17 6/27/05 6:22p rgreen |
|---|
| 90 | * PR15217: Add Auth Support for HDCP Repeaters with Device Count 0; |
|---|
| 91 | * Use bhdm_config.h configuration option. |
|---|
| 92 | * Add option for Repeater Simulation Test |
|---|
| 93 | * |
|---|
| 94 | * Hydra_Software_Devel/16 4/29/05 5:43p rgreen |
|---|
| 95 | * PR14848: Return failure when Repeater downstream devices do not |
|---|
| 96 | * authenticate |
|---|
| 97 | * |
|---|
| 98 | * Hydra_Software_Devel/15 4/21/05 7:58p rgreen |
|---|
| 99 | * PR9474: HDCP Support |
|---|
| 100 | * Increase timeout for waiting for KSV FIFO Ready to 5 seconds |
|---|
| 101 | * |
|---|
| 102 | * Hydra_Software_Devel/14 3/8/05 4:21p rgreen |
|---|
| 103 | * PR9474: HDCP 1.1 Support |
|---|
| 104 | * Restore inadvertantly removed BHDM_HDCP_GetBCaps function |
|---|
| 105 | * |
|---|
| 106 | * Hydra_Software_Devel/13 3/3/05 5:22p rgreen |
|---|
| 107 | * PR9474: HDCP 1.1 Support |
|---|
| 108 | * Remove unused debug functions |
|---|
| 109 | * Remove call to depracated function BHDM_HDCP_SetVersion |
|---|
| 110 | * |
|---|
| 111 | * Hydra_Software_Devel/12 12/9/04 2:40p rgreen |
|---|
| 112 | * PR8896: Correctly report status of BHDM_HDCP_AuthenticateRepeater; Use |
|---|
| 113 | * function argument uint8_t RepeaterAuthenticated instead of local bool |
|---|
| 114 | * bRepeaterAuthenticated when checking the status of the Repeater |
|---|
| 115 | * Authentication. |
|---|
| 116 | * |
|---|
| 117 | * Clean up debug messages |
|---|
| 118 | * |
|---|
| 119 | * Hydra_Software_Devel/11 10/21/04 6:26p rgreen |
|---|
| 120 | * PR8896: Remove HDCP Key functions used for debug purposes. |
|---|
| 121 | * |
|---|
| 122 | * Hydra_Software_Devel/10 10/18/04 11:59a rgreen |
|---|
| 123 | * PR9474: Add HDCP 1.1 Support |
|---|
| 124 | * Add check to determine if Rx supports HDCP 1.1 |
|---|
| 125 | * Remove debug message |
|---|
| 126 | * |
|---|
| 127 | * Hydra_Software_Devel/9 9/24/04 6:24p rgreen |
|---|
| 128 | * PR9474: Add timeout for reading the HDCP Repeater KSV FIFO |
|---|
| 129 | * |
|---|
| 130 | * Hydra_Software_Devel/8 8/18/04 4:40p rgreen |
|---|
| 131 | * PR 12116: Add HDCP Key Loading Support |
|---|
| 132 | * Use new BHDM_EncryptedHdcpStructure for HDCP Key loading |
|---|
| 133 | * |
|---|
| 134 | * Hydra_Software_Devel/7 5/13/04 4:32p rgreen |
|---|
| 135 | * PR 10273: HDMI / HDCP Revocation/renewability support requirement |
|---|
| 136 | * |
|---|
| 137 | * Hydra_Software_Devel/6 4/5/04 1:17p rgreen |
|---|
| 138 | * PR8896: HDMI API Development/Test |
|---|
| 139 | * PR10273: HDCP Revocation/renewability support |
|---|
| 140 | * Add support to AuthenticateReceiver function for checking Revoked KSVs |
|---|
| 141 | * |
|---|
| 142 | * Hydra_Software_Devel/5 3/26/04 7:16p rgreen |
|---|
| 143 | * PR8896: HDMI API Development/Test |
|---|
| 144 | * Fix compilation error for BXPT_Ca_SetKeySerializer |
|---|
| 145 | * |
|---|
| 146 | * Hydra_Software_Devel/4 2/13/04 7:58p rgreen |
|---|
| 147 | * PR8896: HDMI API Development/Test |
|---|
| 148 | * Add code to support Repeater Authentication; |
|---|
| 149 | * Use BHDM_CONFIG_REPEATER_SIMULATION_TEST to generate Tx verifications values contained in |
|---|
| 150 | * the HDCP 1.1 Spec |
|---|
| 151 | * Modify BHDM_HDCP_AuthenticateRepeater call |
|---|
| 152 | * |
|---|
| 153 | * Hydra_Software_Devel/3 1/27/04 1:03p rgreen |
|---|
| 154 | * PR8896: HDMI API Development/Test |
|---|
| 155 | * Move AuthenticateRepeater function to BHDMlib; needs access to XPT |
|---|
| 156 | * handle for authentication with HDCP Repeater |
|---|
| 157 | * |
|---|
| 158 | * Hydra_Software_Devel/2 1/26/04 11:22a rgreen |
|---|
| 159 | * PR8896: HDMI API Development/Test |
|---|
| 160 | * Remove unused variable in AuthenticateReceiver function (compile |
|---|
| 161 | * warning) |
|---|
| 162 | * Correct labels in enter/leave macros for Debug function |
|---|
| 163 | * |
|---|
| 164 | * Hydra_Software_Devel/1 1/20/04 7:37p rgreen |
|---|
| 165 | * PR8896: HDMI API Development/Test |
|---|
| 166 | * Create HDMI HDCP Syslib to utilize XPT Key Serializer |
|---|
| 167 | * |
|---|
| 168 | * |
|---|
| 169 | ***************************************************************************/ |
|---|
| 170 | #include "bstd.h" |
|---|
| 171 | |
|---|
| 172 | #include "bxpt.h" |
|---|
| 173 | #include "btmr.h" |
|---|
| 174 | #include "bhdm_config.h" |
|---|
| 175 | #include "bhdmlib_hdcp.h" |
|---|
| 176 | #include "bhdmlib_hdcp_keyloader.h" |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | BDBG_MODULE(BHDMLIB_HDCP) ; |
|---|
| 181 | |
|---|
| 182 | #define BHDM_CHECK_RC( rc, func ) \ |
|---|
| 183 | do \ |
|---|
| 184 | { \ |
|---|
| 185 | if( (rc = BERR_TRACE(func)) != BERR_SUCCESS ) \ |
|---|
| 186 | { \ |
|---|
| 187 | goto done; \ |
|---|
| 188 | } \ |
|---|
| 189 | } while(0) |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | typedef struct BHDMlib_HDCP_P_Handle |
|---|
| 193 | { |
|---|
| 194 | BHDM_Handle hHDMI ; |
|---|
| 195 | BHDMLIB_KeyHandle hHANDLE ; |
|---|
| 196 | BTMR_Handle hTMR; |
|---|
| 197 | } BHDMlib_HDCP_P_Handle ; |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | /****************************************************************************** |
|---|
| 201 | BERR_Code BHDMlib_HDCP_Open |
|---|
| 202 | Summary:Open a HDCP handle for HDCP Authentication between the Transmitter and |
|---|
| 203 | the Receiver. |
|---|
| 204 | *******************************************************************************/ |
|---|
| 205 | BERR_Code BHDMlib_HDCP_Open( |
|---|
| 206 | BHDMlib_HDCP_Handle *phHDCP, /* [out] pointer to new HDCP lib handle */ |
|---|
| 207 | BHDM_Handle hHDMI, /* [in] newly opened HDMI handle */ |
|---|
| 208 | BHDMLIB_KeyHandle hHANDLE ) /* [in] newly opened handle for Keys*/ |
|---|
| 209 | { |
|---|
| 210 | BERR_Code rc = BERR_SUCCESS; |
|---|
| 211 | BHDMlib_HDCP_Handle hHDCP = NULL ; |
|---|
| 212 | |
|---|
| 213 | BDBG_ENTER(BHDMlib_HDCP_Open) ; |
|---|
| 214 | |
|---|
| 215 | BDBG_ASSERT(hHDMI) ; |
|---|
| 216 | BDBG_ASSERT(hHANDLE) ; |
|---|
| 217 | |
|---|
| 218 | hHDCP = (BHDMlib_HDCP_Handle) BKNI_Malloc(sizeof(BHDMlib_HDCP_P_Handle)) ; |
|---|
| 219 | if (!hHDCP) |
|---|
| 220 | { |
|---|
| 221 | rc = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY); |
|---|
| 222 | goto done; |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | hHDCP->hHDMI = hHDMI ; |
|---|
| 226 | hHDCP_BHDMLIB_KeyHandle = hHANDLE ; |
|---|
| 227 | hHDCP->hTMR = NULL; |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | /* keep created pointer */ |
|---|
| 231 | *phHDCP = hHDCP ; |
|---|
| 232 | |
|---|
| 233 | done: |
|---|
| 234 | BDBG_LEAVE(BHDMlib_HDCP_Open); |
|---|
| 235 | return rc ; |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | /****************************************************************************** |
|---|
| 240 | BERR_Code BHDMlib_HDCP_Close |
|---|
| 241 | Summary:Close the HDCP handled opened for HDCP Authentication between the |
|---|
| 242 | Transmitter and the Receiver. |
|---|
| 243 | *******************************************************************************/ |
|---|
| 244 | BERR_Code BHDMlib_HDCP_Close( |
|---|
| 245 | BHDMlib_HDCP_Handle hHDCP /* [in] HDCP lib handle */ |
|---|
| 246 | ) |
|---|
| 247 | { |
|---|
| 248 | BERR_Code rc = BERR_SUCCESS; |
|---|
| 249 | |
|---|
| 250 | BDBG_ENTER(BHDMlib_HDCP_Close); |
|---|
| 251 | |
|---|
| 252 | /* free memory associated with the HDCP handle */ |
|---|
| 253 | BKNI_Free( (void *) hHDCP) ; |
|---|
| 254 | |
|---|
| 255 | BDBG_LEAVE(BHDMlib_HDCP_Close); |
|---|
| 256 | return rc ; |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | |
|---|
| 260 | /****************************************************************************** |
|---|
| 261 | BERR_Code BHDMlib_HDCP_AuthenticateReceiver |
|---|
| 262 | Summary:Authenticate the HDCP link between the Transmitter and the Receiver. |
|---|
| 263 | *******************************************************************************/ |
|---|
| 264 | BERR_Code BHDMlib_HDCP_AuthenticateReceiver( |
|---|
| 265 | BHDMlib_HDCP_Handle hHDCP, /* [in] HDCP lib handle */ |
|---|
| 266 | BHDM_HDCP_AnSelect AnSelection, /* [in] HDCP An type value to use */ |
|---|
| 267 | const uint8_t *pTxAksv, /* [in] pointer HDCP Key Set Aksv Value */ |
|---|
| 268 | const BHDM_EncryptedHdcpKeyStruct *pTxKeyStructure, /* [in] pointer to HDCP Keys */ |
|---|
| 269 | const uint8_t *pRevokedKsvList, /* [in] pointer to Revoked KSV List */ |
|---|
| 270 | const uint16_t uiNumRevokedKsvs /* [in] number of KSVs in Revoked Ksv List */ |
|---|
| 271 | ) |
|---|
| 272 | { |
|---|
| 273 | BERR_Code rc = BERR_SUCCESS; |
|---|
| 274 | |
|---|
| 275 | uint8_t RxAuthenticated = 0 ; |
|---|
| 276 | |
|---|
| 277 | #ifdef RESET_OLDER_SI_DVI_RX |
|---|
| 278 | uint8_t RxHasBeenResetOnce = 0 ; |
|---|
| 279 | #endif |
|---|
| 280 | |
|---|
| 281 | uint8_t BCaps ; |
|---|
| 282 | uint8_t RxIsHdcpRepeater = 0 ; |
|---|
| 283 | BTMR_TimerHandle hTimer; |
|---|
| 284 | BTMR_Settings stTmrSettings; |
|---|
| 285 | uint32_t uiTimer1 = 0; |
|---|
| 286 | uint32_t uiTimer2 = 0; |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | BDBG_ENTER(BHDMlib_HDCP_AuthenticateReceiver) ; |
|---|
| 290 | BDBG_ASSERT( hHDCP ); |
|---|
| 291 | BDBG_ASSERT( hHDCP->hTMR ); |
|---|
| 292 | |
|---|
| 293 | /************************************************/ |
|---|
| 294 | /* Create timer to monitor wait time before reading R0' */ |
|---|
| 295 | /************************************************/ |
|---|
| 296 | rc = BTMR_GetDefaultTimerSettings(&stTmrSettings); |
|---|
| 297 | if (rc != BERR_SUCCESS) |
|---|
| 298 | { |
|---|
| 299 | goto done; |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | /* Set appropriate Timer Settings */ |
|---|
| 303 | stTmrSettings.type = BTMR_Type_eSharedFreeRun; |
|---|
| 304 | stTmrSettings.exclusive = false ; |
|---|
| 305 | |
|---|
| 306 | /* Create timer */ |
|---|
| 307 | rc = BTMR_CreateTimer(hHDCP->hTMR, &hTimer, &stTmrSettings) ; |
|---|
| 308 | if(rc != BERR_SUCCESS) |
|---|
| 309 | { |
|---|
| 310 | rc = BERR_TRACE(BERR_LEAKED_RESOURCE); |
|---|
| 311 | goto done ; |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | |
|---|
| 315 | /* use the Rx BCaps register to check which HDCP Version to use */ |
|---|
| 316 | BHDM_CHECK_RC(rc, BHDM_HDCP_GetRxCaps(hHDCP->hHDMI, &BCaps)) ; |
|---|
| 317 | |
|---|
| 318 | while (!RxAuthenticated) |
|---|
| 319 | { |
|---|
| 320 | /* Read the Bksv from the Rx */ |
|---|
| 321 | if ((rc = BHDM_HDCP_ReadRxBksv(hHDCP->hHDMI, pRevokedKsvList, uiNumRevokedKsvs)) != BERR_SUCCESS) |
|---|
| 322 | goto ResetRx ; |
|---|
| 323 | |
|---|
| 324 | /* Generate/Write the Authentication An value */ |
|---|
| 325 | BHDM_CHECK_RC(rc, BHDM_HDCP_GenerateAn(hHDCP->hHDMI, AnSelection)) ; |
|---|
| 326 | |
|---|
| 327 | /* Write the Tx Aksv to the Receiver */ |
|---|
| 328 | if ((rc = BHDM_HDCP_WriteTxAksvToRx(hHDCP->hHDMI, pTxAksv)) != BERR_SUCCESS) |
|---|
| 329 | goto ResetRx ; |
|---|
| 330 | |
|---|
| 331 | /* Record timer before loading HDCP keys */ |
|---|
| 332 | if ((rc = BTMR_ReadTimer(hTimer, &uiTimer1)) != BERR_SUCCESS) |
|---|
| 333 | { |
|---|
| 334 | BDBG_ERR(("Error reading shared timer")); |
|---|
| 335 | goto done; |
|---|
| 336 | } |
|---|
| 337 | |
|---|
| 338 | |
|---|
| 339 | /* Rx R0 is ready 100ms after writing Aksv */ |
|---|
| 340 | /* while waiting for R0..., load the transmitter HDCP Keys */ |
|---|
| 341 | if ((rc = BHDM_HDCP_EnableSerialKeyLoad(hHDCP->hHDMI)) != BERR_SUCCESS) |
|---|
| 342 | goto ResetRx ; |
|---|
| 343 | |
|---|
| 344 | if ((rc = BHDMLIB_HDCP_LoadEncryptedHdcpKeys(hHDCP_BHDMLIB_KeyHandle, pTxKeyStructure)) != BERR_SUCCESS) |
|---|
| 345 | goto ResetRx ; |
|---|
| 346 | |
|---|
| 347 | /* Read timer after finish loading HDCP keys and calculate elapsed time for loading HDCP keys*/ |
|---|
| 348 | if ((rc = BTMR_ReadTimer(hTimer, &uiTimer2)) != BERR_SUCCESS) |
|---|
| 349 | { |
|---|
| 350 | BDBG_ERR(("Error reading shared timer")); |
|---|
| 351 | goto done; |
|---|
| 352 | } |
|---|
| 353 | uiTimer1 = (uiTimer2 - uiTimer1)/1000; |
|---|
| 354 | |
|---|
| 355 | /* Make sure to wait a total of 100ms or more before reading R0' after writing Aksv */ |
|---|
| 356 | /* Wait time = 115 ms - the time it took to load the HDCP keys */ |
|---|
| 357 | BKNI_Sleep(115 - uiTimer1); |
|---|
| 358 | |
|---|
| 359 | |
|---|
| 360 | |
|---|
| 361 | /* Authenticate the Link */ |
|---|
| 362 | |
|---|
| 363 | if ((rc = BHDM_HDCP_AuthenticateLink(hHDCP->hHDMI)) == BERR_SUCCESS) |
|---|
| 364 | { |
|---|
| 365 | RxAuthenticated = 1 ; |
|---|
| 366 | |
|---|
| 367 | /* check if Rx is a Repeater */ |
|---|
| 368 | RxIsHdcpRepeater = BCaps & BHDM_HDCP_RxCaps_eHdcpRepeater ; |
|---|
| 369 | if (RxIsHdcpRepeater) |
|---|
| 370 | { |
|---|
| 371 | /* |
|---|
| 372 | Send encrypted frames to the repeater |
|---|
| 373 | after it has been authenticated. |
|---|
| 374 | i.e. before starting HDCP Repeater Authentication (Part 2) |
|---|
| 375 | */ |
|---|
| 376 | BHDM_HDCP_XmitEncrypted(hHDCP->hHDMI) ; |
|---|
| 377 | |
|---|
| 378 | |
|---|
| 379 | rc = BHDMlib_HDCP_AuthenticateRepeater(hHDCP->hHDMI, |
|---|
| 380 | &RxAuthenticated, pRevokedKsvList, uiNumRevokedKsvs) ; |
|---|
| 381 | } |
|---|
| 382 | |
|---|
| 383 | if (RxAuthenticated) |
|---|
| 384 | goto done ; |
|---|
| 385 | } |
|---|
| 386 | |
|---|
| 387 | |
|---|
| 388 | ResetRx: |
|---|
| 389 | BDBG_MSG(("Unable to Authenticate Receiver")) ; |
|---|
| 390 | |
|---|
| 391 | #ifndef RESET_OLDER_SI_DVI_RX |
|---|
| 392 | break ; /* DO NOT TRY RESETTING Rx Receiver */ |
|---|
| 393 | |
|---|
| 394 | #else |
|---|
| 395 | /* Debug/Test code to support earlier Silicon Image DVI Rx */ |
|---|
| 396 | /* |
|---|
| 397 | ** RESET RX |
|---|
| 398 | ** |
|---|
| 399 | ** try resetting the Rx... this will occur only if there was a problem |
|---|
| 400 | ** with enabling the HDCP link. Try resetting the Rx only once. |
|---|
| 401 | */ |
|---|
| 402 | |
|---|
| 403 | if (RxHasBeenResetOnce) |
|---|
| 404 | break ; |
|---|
| 405 | |
|---|
| 406 | BDBG_WRN(("Attempting Reset of Receiver...\n")); |
|---|
| 407 | |
|---|
| 408 | /* |
|---|
| 409 | ** This reset step is REQUIRED for resetting OLDER Silicon Image (SI) |
|---|
| 410 | ** Receivers. If the Si Rx is not properly reset the HDCP |
|---|
| 411 | ** Authentication will fail. the SI Receivers need the TMDS buffer and |
|---|
| 412 | ** clock turned off for 100ms and subsequently turned back on to reset. |
|---|
| 413 | ** |
|---|
| 414 | ** NOTE: the TMDS buffer on/off will cause all displays to blank |
|---|
| 415 | ** for a fraction of a second. The reset will most likely be needed on |
|---|
| 416 | ** displays containing OLDER SI Receivers. |
|---|
| 417 | */ |
|---|
| 418 | |
|---|
| 419 | BHDM_ResetHdmiRx(hHDCP->hHDMI) ; |
|---|
| 420 | RxHasBeenResetOnce = 1 ; |
|---|
| 421 | #endif |
|---|
| 422 | } /* while !RxAuthenticated) */ |
|---|
| 423 | |
|---|
| 424 | done: |
|---|
| 425 | |
|---|
| 426 | BDBG_LEAVE(BHDMlib_HDCP_AuthenticateReceiver) ; |
|---|
| 427 | |
|---|
| 428 | /* Destroy Timer */ |
|---|
| 429 | BTMR_DestroyTimer(hTimer); |
|---|
| 430 | |
|---|
| 431 | return rc ; |
|---|
| 432 | } /* end BHDMlib_HDCP_AuthenticateReceiver */ |
|---|
| 433 | |
|---|
| 434 | |
|---|
| 435 | |
|---|
| 436 | /****************************************************************************** |
|---|
| 437 | BERR_Code BHDMlib_HDCP_AuthenticateRepeater |
|---|
| 438 | Summary:Authenticate the HDCP link between the Transmitter and an HDCP Repeater. |
|---|
| 439 | *******************************************************************************/ |
|---|
| 440 | BERR_Code BHDMlib_HDCP_AuthenticateRepeater( |
|---|
| 441 | BHDM_Handle hHDMI, /* [in] HDCP lib handle */ |
|---|
| 442 | uint8_t *RepeaterAuthenticated, |
|---|
| 443 | const uint8_t *pRevokedKsvList, /* [in] pointer to Revoked KSV List */ |
|---|
| 444 | const uint16_t uiNumRevokedKsvs /* [in] number of KSVs in Revoked Ksv List */ |
|---|
| 445 | ) |
|---|
| 446 | { |
|---|
| 447 | BERR_Code rc = BERR_SUCCESS; |
|---|
| 448 | bool KsvFifoReady ; |
|---|
| 449 | uint8_t timeoutMs ; |
|---|
| 450 | |
|---|
| 451 | uint8_t |
|---|
| 452 | KsvListMemoryAllocated = 0 ; |
|---|
| 453 | |
|---|
| 454 | uint8_t |
|---|
| 455 | BCaps, |
|---|
| 456 | *KsvList = NULL, |
|---|
| 457 | DeviceCount, |
|---|
| 458 | RepeaterLevels ; |
|---|
| 459 | |
|---|
| 460 | uint16_t |
|---|
| 461 | BStatus, |
|---|
| 462 | iNumKsvBytes ; |
|---|
| 463 | |
|---|
| 464 | |
|---|
| 465 | BDBG_ENTER(BHDMlib_HDCP_AuthenticateRepeater) ; |
|---|
| 466 | BDBG_ASSERT( hHDMI ); |
|---|
| 467 | |
|---|
| 468 | *RepeaterAuthenticated = 0 ; |
|---|
| 469 | |
|---|
| 470 | timeoutMs = 50 ; |
|---|
| 471 | do |
|---|
| 472 | { |
|---|
| 473 | BHDM_CHECK_RC(rc, BHDM_HDCP_GetRxCaps(hHDMI, &BCaps)) ; |
|---|
| 474 | if ((KsvFifoReady = BCaps & BHDM_HDCP_RxCaps_eKsvFifoReady)) |
|---|
| 475 | break ; |
|---|
| 476 | |
|---|
| 477 | BDBG_WRN(("Wait for KSV FIFO Rdy; timeout in %d ms", timeoutMs * 100)) ; |
|---|
| 478 | BKNI_Sleep(100) ; |
|---|
| 479 | } |
|---|
| 480 | while (timeoutMs--) ; |
|---|
| 481 | |
|---|
| 482 | |
|---|
| 483 | if (!KsvFifoReady) |
|---|
| 484 | { |
|---|
| 485 | BDBG_ERR(("HDCP Auth Failure; Repeater KSV FIFO not ready")) ; |
|---|
| 486 | rc = BHDM_HDCP_REPEATER_FIFO_NOT_READY ; |
|---|
| 487 | goto done ; |
|---|
| 488 | } |
|---|
| 489 | |
|---|
| 490 | /* check Repeater Values */ |
|---|
| 491 | BHDM_CHECK_RC(rc, BHDM_HDCP_GetRxStatus(hHDMI, &BStatus)) ; |
|---|
| 492 | BHDM_CHECK_RC(rc, BHDM_HDCP_GetRepeaterDepth(hHDMI, &RepeaterLevels)) ; |
|---|
| 493 | BHDM_CHECK_RC(rc, BHDM_HDCP_GetRepeaterDeviceCount(hHDMI, &DeviceCount)) ; |
|---|
| 494 | |
|---|
| 495 | BDBG_MSG(("RXStatus: %X, Depth: %d, Devices: %d", |
|---|
| 496 | BStatus, RepeaterLevels, DeviceCount)) ; |
|---|
| 497 | |
|---|
| 498 | /* check if the number of repeater levels has been exceeded */ |
|---|
| 499 | if (BStatus & BHDM_HDCP_RxStatus_eMaxRepeatersExceeded) |
|---|
| 500 | { |
|---|
| 501 | BDBG_ERR(("%d Levels of Repeaters exceed the MAX allowed of %d", |
|---|
| 502 | RepeaterLevels, BHDM_HDCP_REPEATER_MAX_DEPTH )) ; |
|---|
| 503 | rc = BHDM_HDCP_REPEATER_DEPTH_EXCEEDED ; |
|---|
| 504 | goto done ; |
|---|
| 505 | } |
|---|
| 506 | |
|---|
| 507 | /* check if the number of receiver devices has been exceeded */ |
|---|
| 508 | if (BStatus & BHDM_HDCP_RxStatus_eMaxDevicesExceeded) |
|---|
| 509 | { |
|---|
| 510 | BDBG_ERR(("Number of Devices: %d exceeds the MAX allowed of %d", |
|---|
| 511 | DeviceCount, BHDM_HDCP_REPEATER_MAX_DEVICE_COUNT )) ; |
|---|
| 512 | rc = BHDM_HDCP_RX_DEVICES_EXCEEDED ; |
|---|
| 513 | goto done ; |
|---|
| 514 | } |
|---|
| 515 | |
|---|
| 516 | |
|---|
| 517 | /* initialize the Repeater Authentication */ |
|---|
| 518 | BHDM_HDCP_InitializeRepeaterAuthentication(hHDMI) ; |
|---|
| 519 | |
|---|
| 520 | if (DeviceCount) |
|---|
| 521 | { |
|---|
| 522 | /* allocate a buffer to hold the Ksv List */ |
|---|
| 523 | iNumKsvBytes = (uint16_t) (DeviceCount * BHDM_HDCP_KSV_LENGTH) ; |
|---|
| 524 | KsvList = (uint8_t *) BKNI_Malloc(sizeof(uint8_t) * iNumKsvBytes) ; |
|---|
| 525 | KsvListMemoryAllocated = 1 ; |
|---|
| 526 | |
|---|
| 527 | /* read the Ksv List */ |
|---|
| 528 | /* pass the revoked list for checking against downstream Rx devices */ |
|---|
| 529 | BHDM_CHECK_RC(rc, BHDM_HDCP_ReadRxRepeaterKsvFIFO(hHDMI, |
|---|
| 530 | KsvList, DeviceCount, pRevokedKsvList, uiNumRevokedKsvs)) ; |
|---|
| 531 | |
|---|
| 532 | /* write the Ksvs from the Rx (Repeater) to the Transmitter core for verification */ |
|---|
| 533 | BHDM_CHECK_RC(rc, BHDM_HDCP_WriteTxKsvFIFO(hHDMI, KsvList, DeviceCount)) ; |
|---|
| 534 | } |
|---|
| 535 | else /* handle zero devices attached to repeater */ |
|---|
| 536 | { |
|---|
| 537 | #if BHDM_CONFIG_DISABLE_HDCP_AUTH_REPEATER_DEVCOUNT0 |
|---|
| 538 | /* do not allow authentication with repeaters that have device count of 0 */ |
|---|
| 539 | BDBG_WRN(("Auth Disabled for Repeaters with Device Count of 0")) ; |
|---|
| 540 | return BHDM_HDCP_REPEATER_DEVCOUNT_0 ; |
|---|
| 541 | #else |
|---|
| 542 | /* force V calculation for repeater with zero attached devices */ |
|---|
| 543 | BHDM_HDCP_ForceVCalculation(hHDMI) ; |
|---|
| 544 | #endif |
|---|
| 545 | } |
|---|
| 546 | |
|---|
| 547 | /* check SHA-1 Hash Verification (V).... */ |
|---|
| 548 | BHDM_CHECK_RC(rc, BHDM_HDCP_RepeaterAuthenticateLink(hHDMI, RepeaterAuthenticated)) ; |
|---|
| 549 | |
|---|
| 550 | if (!*RepeaterAuthenticated) |
|---|
| 551 | { |
|---|
| 552 | BDBG_ERR(("Repeater failed to authenticate")) ; |
|---|
| 553 | rc = BHDM_HDCP_REPEATER_AUTH_ERROR ; |
|---|
| 554 | goto done ; |
|---|
| 555 | } |
|---|
| 556 | |
|---|
| 557 | done: |
|---|
| 558 | /* release allocated memory for Ksv list */ |
|---|
| 559 | if (KsvListMemoryAllocated) |
|---|
| 560 | BKNI_Free(KsvList) ; |
|---|
| 561 | |
|---|
| 562 | if (rc != BERR_SUCCESS) |
|---|
| 563 | BHDM_HDCP_ClearAuthentication(hHDMI); |
|---|
| 564 | |
|---|
| 565 | BDBG_LEAVE(BHDMlib_HDCP_AuthenticateRepeater) ; |
|---|
| 566 | return rc ; |
|---|
| 567 | } /* end BHDMlib_HDCP_AuthenticateRepeater */ |
|---|
| 568 | |
|---|
| 569 | |
|---|
| 570 | BERR_Code BHDMlib_HDCP_SetTimerHandle( |
|---|
| 571 | BHDMlib_HDCP_Handle hHDCP, /* [out] pointer to new HDCP lib handle */ |
|---|
| 572 | BTMR_Handle hTMR) /* [in] TMR handle */ |
|---|
| 573 | { |
|---|
| 574 | |
|---|
| 575 | BERR_Code rc = BERR_SUCCESS; |
|---|
| 576 | |
|---|
| 577 | BDBG_ENTER(BHDMlib_HDCP_SetTimerHandle) ; |
|---|
| 578 | BDBG_ASSERT(hTMR) ; |
|---|
| 579 | |
|---|
| 580 | /* Save TMR handle into HDMlib handle */ |
|---|
| 581 | hHDCP->hTMR = hTMR ; |
|---|
| 582 | |
|---|
| 583 | |
|---|
| 584 | BDBG_LEAVE(BHDMlib_HDCP_SetTimerHandle); |
|---|
| 585 | return rc ; |
|---|
| 586 | } |
|---|