source: svn/trunk/newcon3bcm2_21bu/magnum/syslib/hdcplib/7552/bhdcplib.c

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 34.8 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2005-2011, 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: bhdcplib.c $
11 * $brcm_Revision: Hydra_Software_Devel/15 $
12 * $brcm_Date: 11/14/11 3:23p $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/syslib/hdcplib/7401/bhdcplib.c $
19 *
20 * Hydra_Software_Devel/15   11/14/11 3:23p rgreen
21 * SW7325-872: Fix unused warning messages for non-debug buiilds
22 *
23 * Hydra_Software_Devel/14   11/7/11 11:25a rgreen
24 * SW7325-872,SW7405-3987:  Remove double negative in error message.
25 * Update message to include the return code and current HDCP
26 * Authentication state
27 *
28 * Hydra_Software_Devel/13   10/31/11 3:34p rgreen
29 * SW7325-872: update debug messages to use text instead of numbers when
30 * showing the HDCP states
31 *
32 * Hydra_Software_Devel/12   10/12/11 3:39p vle
33 * SW7125-1091: Enable encryption right after part 1 of hdcp
34 * authentication succeed
35 *
36 * Hydra_Software_Devel/11   9/9/11 3:19p vle
37 * SW7420-2041: Avoid unnecessary attempts to check hdcp status when HDMI
38 * Rx is disconnected/unpowered
39 *
40 * Hydra_Software_Devel/10   3/3/10 12:37p vle
41 * SW7405-3987: Merge into main branch
42 *
43 * Hydra_Software_Devel/SW7405-3987/2   3/2/10 7:12p vle
44 * SW7405-3987: Report specific HDCP error status to high level
45 * application - Take 2: warn users for invalid errors.
46 *
47 * Hydra_Software_Devel/SW7405-3987/1   3/2/10 5:39p vle
48 * SW7405-3987: Report specific HDCP error status to high level
49 * application.
50 *
51 * Hydra_Software_Devel/9   1/28/10 1:56p vle
52 * SW7420-489: merge to main branch
53 *
54 * Hydra_Software_Devel/SW7420-489/1   1/26/10 3:39p vle
55 * SW7420-489: propagate max_device_count and max_depth to application
56 *
57 * Hydra_Software_Devel/8   8/25/09 3:31p vle
58 * SW7405-2670:
59 * Do not poll for receiver sense while encryption is still enabled.
60 * Add implementation of interrupt based receiver sense
61 *
62 * Hydra_Software_Devel/PR56486/1   8/6/09 12:05p vle
63 * PR56486: Do not poll for receiver sense while encryption is still
64 * enabled.
65 *
66 * Hydra_Software_Devel/7   2/27/09 8:56p vle
67 * PR52505: Fix non-const global data in HDM and HDCPLIB
68 *
69 * Hydra_Software_Devel/6   11/24/08 8:42p vle
70 * PR49219, PR49593, PR48842, PR48937: Merge to main branch
71 *
72 * Hydra_Software_Devel/HDMI_TX_Plugfest11_200811/2   11/24/08 8:26p vle
73 * PR49219, PR49593, PR48842: Add additional state in the state machine to
74 * clearly identify HDCP authentication errors. Update the current hdcp
75 * state appropriately.
76 *
77 * Hydra_Software_Devel/HDMI_TX_Plugfest11_200811/1   11/12/08 4:54p vle
78 * PR 48937: Add support for HDCP repeater error during HDCP
79 * authentication process.
80 *
81 * Hydra_Software_Devel/5   11/10/08 6:56p vle
82 * PR44550, PR48842: Be sure to retrieve receiver info for the
83 * authentication process instead of relying on the application.
84 *
85 * Hydra_Software_Devel/4   11/6/08 11:23a vle
86 * PR48705: Fix crash in kernel mode when closing BHDCPlib.
87 *
88 * Hydra_Software_Devel/3   10/29/08 7:40p vle
89 * PR44550: Merge changes from bdvd_v2.0 branch.
90 * Fix bug on size of revoked KSV list
91 * Be sure to free the revoked KSV list appropriately.
92 *
93 * Hydra_Software_Devel/2   3/18/08 7:18p vle
94 * PR 39991: Rename HDMIlib to HDCPlib. Remove unused implementation.
95 *
96 * Hydra_Software_Devel/1   2/26/08 5:43p jgarrett
97 * PR 39991: Renaming new HDMlib to HDCPlib
98 *
99 * Hydra_Software_Devel/Syslib_Initiative/11   2/22/08 6:16p vle
100 * PR 31924: Set default HDCP configuration during open.
101 * Use HDCP test keys as default HDCP keys.
102 *
103 * Hydra_Software_Devel/Syslib_Initiative/10   2/21/08 7:01p vle
104 * PR 31924: Fix RevokedKSV callback
105 *
106 * Hydra_Software_Devel/Syslib_Initiative/9   2/21/08 5:00p vle
107 * PR 31924: Change Settings back to Dependencies
108 * Remove Hotplug callback
109 * Move RevokedKSVList to Handle
110 *
111 * Hydra_Software_Devel/Syslib_Initiative/8   2/15/08 10:01p vle
112 * PR 31924: Improve HDMI Syslib API from feedback.
113 *
114 ***************************************************************************/
115
116#include "bavc_hdmi.h"
117#include "bhdcplib.h"
118#include "bhdcplib_priv.h"
119#include "bhdcplib_keyloader.h"
120
121
122BDBG_MODULE(BHDCPLIB) ;
123
124
125#define BHDCPLIB_CHECK_RC( rc, func )                 \
126do                                                \
127{                                                                                         \
128        if( (rc = BERR_TRACE(func)) != BERR_SUCCESS ) \
129        {                                                                                     \
130                goto done;                                                            \
131        }                                                                                     \
132} while(0)
133
134
135/* HDCP default settings */
136static const BHDCPlib_Configuration stHdcpDefaultConfiguration = 
137{
138        BHDM_HDCP_AnSelect_eRandomAn, 
139        {
140                {0x14, 0xF7, 0x61, 0x03, 0xB7}, 
141                {               /* HDCP Test Keys */           
142                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x691e138f, 0x58a44d00},
143                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x0950e658, 0x35821f00},
144                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x0d98b9ab, 0x476a8a00},
145                        { 0, 0, 0, 0, 0, 0, 0, 0, 0xcac5cb52, 0x1b18f300},
146                        { 0, 0, 0, 0, 0, 0, 0, 0, 0xb4d89668, 0x7f14fb00},
147                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x818f4878, 0xc98be000},
148                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x412c11c8, 0x64d0a000},
149                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x44202428, 0x5a9db300},
150                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x6b56adbd, 0xb228b900},
151                        { 0, 0, 0, 0, 0, 0, 0, 0, 0xf6e46c4a, 0x7ba49100},
152                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x589d5e20, 0xf8005600},
153                        { 0, 0, 0, 0, 0, 0, 0, 0, 0xa03fee06, 0xb77f8c00},
154                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x28bc7c9d, 0x8c2dc000},
155                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x059f4be5, 0x61125600},
156                        { 0, 0, 0, 0, 0, 0, 0, 0, 0xcbc1ca8c, 0xdef07400},
157                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x6adbfc0e, 0xf6b83b00},
158                        { 0, 0, 0, 0, 0, 0, 0, 0, 0xd72fb216, 0xbb2ba000},
159                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x98547846, 0x8e2f4800},
160                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x38472762, 0x25ae6600},
161                        { 0, 0, 0, 0, 0, 0, 0, 0, 0xf2dd23a3, 0x52493d00},
162                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x543a7b76, 0x31d2e200}, 
163                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x2561e6ed, 0x1a584d00},
164                        { 0, 0, 0, 0, 0, 0, 0, 0, 0xf7227bbf, 0x82603200},
165                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x6bce3035, 0x461bf600},
166                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x6b97d7f0, 0x09043600},
167                        { 0, 0, 0, 0, 0, 0, 0, 0, 0xf9498d61, 0x05e1a100}, 
168                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x063405d1, 0x9d8ec900}, 
169                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x90614294, 0x67c32000},
170                        { 0, 0, 0, 0, 0, 0, 0, 0, 0xc34facce, 0x51449600},
171                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x8a8ce104, 0x45903e00},
172                        { 0, 0, 0, 0, 0, 0, 0, 0, 0xfc2d9c57, 0x10002900},
173                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x80b1e569, 0x3b94d700},
174                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x437bdd5b, 0xeac75400},
175                        { 0, 0, 0, 0, 0, 0, 0, 0, 0xba90c787, 0x58fb7400}, 
176                        { 0, 0, 0, 0, 0, 0, 0, 0, 0xe01d4e36, 0xfa5c9300},
177                        { 0, 0, 0, 0, 0, 0, 0, 0, 0xae119a15, 0x5e070300},
178                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x01fb788a, 0x40d30500},
179                        { 0, 0, 0, 0, 0, 0, 0, 0, 0xb34da0d7, 0xa5590000},
180                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x409e2c4a, 0x633b3700},
181                        { 0, 0, 0, 0, 0, 0, 0, 0, 0x412056b4, 0xbb732500}
182                }
183        },
184        {{0x11,0x11,0x11,0x11,0x11}, 0, 0, false}, 
185        100                             /* msWaitForR0 */, 
186        100                                     /*msIntervalKsvFifoReadyCheck */,
187        1                                       /* uiKsvFifoReadyChecks */      ,
188        BHDM_HDCP_REPEATER_MAX_DEVICE_COUNT             /* uiMaxDeviceCount */,
189        BHDM_HDCP_REPEATER_MAX_DEPTH                    /* uiMaxDepth */
190};
191
192
193typedef struct _BHDCPLIB_P_HDM_HdcpErrors
194{
195        BERR_Code hdmHdcpError;
196        BHDCPlib_HdcpError hdcplibHdcpError;
197       
198} BHDCPLIB_P_HDM_HdcpErrors;
199
200static const BHDCPLIB_P_HDM_HdcpErrors BHDCPlib_SupportedHdcpErrors[BHDCPlib_HdcpError_eCount]=
201{
202        {BERR_SUCCESS,                                                  BHDCPlib_HdcpError_eSuccess},
203        {BHDM_HDCP_RX_BKSV_ERROR,                               BHDCPlib_HdcpError_eRxBksvError},
204        {BHDM_HDCP_RX_BKSV_REVOKED,                             BHDCPlib_HdcpError_eRxBksvRevoked},
205        {BHDM_HDCP_RX_BKSV_I2C_READ_ERROR,              BHDCPlib_HdcpError_eRxBksvI2cReadError},
206        {BHDM_HDCP_TX_AKSV_ERROR,                               BHDCPlib_HdcpError_eTxAksvError},
207        {BHDM_HDCP_TX_AKSV_I2C_WRITE_ERROR,     BHDCPlib_HdcpError_eTxAksvI2cWriteError},
208        {BHDM_HDCP_RECEIVER_AUTH_ERROR,                 BHDCPlib_HdcpError_eReceiverAuthenticationError},
209        {BHDM_HDCP_REPEATER_AUTH_ERROR,                 BHDCPlib_HdcpError_eRepeaterAuthenticationError},
210        {BHDM_HDCP_RX_DEVICES_EXCEEDED,                 BHDCPlib_HdcpError_eRxDevicesExceeded},
211        {BHDM_HDCP_REPEATER_DEPTH_EXCEEDED,     BHDCPlib_HdcpError_eRepeaterDepthExceeded},
212        {BHDM_HDCP_REPEATER_FIFO_NOT_READY,     BHDCPlib_HdcpError_eRepeaterFifoNotReady},
213        {BHDM_HDCP_REPEATER_DEVCOUNT_0,                 BHDCPlib_HdcpError_eRepeaterDeviceCount0},
214        {BHDM_HDCP_LINK_FAILURE,                                BHDCPlib_HdcpError_eRepeaterLinkFailure},
215        {BHDM_HDCP_LINK_RI_FAILURE,                     BHDCPlib_HdcpError_eLinkRiFailure},
216        {BHDM_HDCP_LINK_PJ_FAILURE,                     BHDCPlib_HdcpError_eLinkPjFailure},
217        {BHDM_HDCP_FIFO_UNDERFLOW,                              BHDCPlib_HdcpError_eFifoUnderflow},
218        {BHDM_HDCP_FIFO_OVERFLOW,                               BHDCPlib_HdcpError_eFifoOverflow},
219        {BHDM_HDCP_MULTIPLE_AN_REQUEST,                 BHDCPlib_HdcpError_eMultipleAnRequest}
220};
221
222
223#if BDBG_DEBUG_BUILD                   
224static const char *BHDCPlib_StateText[] =
225{
226        "UnPowered",
227        "Unauthenticated",
228        "InitializeAuthentication",
229        "WaitForReceiverAuthentication",
230        "ReceiverR0Ready",
231        "R0LinkFailure",
232        "ReceiverAuthenticated",        /* Part 1 Completed; R0 Match */
233        "WaitForRepeaterReady",
234        "CheckForRepeaterReady",
235        "RepeaterReady",
236        "LinkAuthenticated",            /* Part 2 Completed; Include down stream devices */
237        "EncryptionEnabled",            /* Part 3 Ri Link Integrity Checks Match */
238        "RepeaterAuthenticationFailure",
239        "RiLinkIntegrityFailure",
240        "PjLinkIntegrityFailure"
241} ;
242#endif
243
244static void BHDCPlib_P_ShowStateChange(BHDCPlib_Handle hHDCPlib, BHDCPlib_State currentState) 
245{
246        if (currentState != hHDCPlib->stHdcpStatus.eAuthenticationState) 
247        {
248                BDBG_MSG(("HDCP State Change: %s (%d) --> %s (%d)", 
249                        BHDCPlib_StateText[currentState], currentState,
250                        BHDCPlib_StateText[hHDCPlib->stHdcpStatus.eAuthenticationState],               
251                        hHDCPlib->stHdcpStatus.eAuthenticationState)) ;
252        }
253        return ;
254}
255       
256
257static BERR_Code BHDCPlib_P_CheckRepeaterReady(BHDCPlib_Handle hHDCPlib)
258{
259        BERR_Code rc = BERR_SUCCESS;
260        uint16_t msElapsedTime;
261        BHDCPlib_State currentState = hHDCPlib->stHdcpStatus.eAuthenticationState;
262       
263        BDBG_ENTER(BHDCPlib_P_CheckRepeaterReady);
264        BDBG_ASSERT(hHDCPlib);
265
266
267        rc = BHDCPlib_GetReceiverInfo(hHDCPlib, &hHDCPlib->stHdcpConfiguration.RxInfo);
268        if (rc != BERR_SUCCESS)
269                goto done;
270
271        if (hHDCPlib->stHdcpConfiguration.RxInfo.uiRxBCaps & BHDM_HDCP_RxCaps_eKsvFifoReady) 
272        {
273                hHDCPlib->stHdcpStatus.eAuthenticationState = BHDCPlib_State_eRepeaterReady;
274                goto done;             
275        }       
276
277        /* Calculate elapsed time */
278        msElapsedTime = hHDCPlib->stHdcpConfiguration.uiKsvFifoReadyChecks
279                * hHDCPlib->stHdcpConfiguration.msIntervalKsvFifoReadyCheck;
280
281        if (msElapsedTime >= 5000)
282        {
283                BDBG_ERR(("HDCP Auth Failure; Repeater KSV FIFO not ready")) ;
284                hHDCPlib->stHdcpStatus.eAuthenticationState = BHDCPlib_State_eRepeaterAuthenticationFailure;
285                rc = BHDM_HDCP_REPEATER_FIFO_NOT_READY ;
286                goto done;
287               
288        }
289        BDBG_WRN(("Wait for KSV FIFO Ready; timeout in %d ms", (5000 - msElapsedTime)));
290        hHDCPlib->stHdcpConfiguration.uiKsvFifoReadyChecks++;
291
292        /* Update HDCP Authentication state */
293        hHDCPlib->stHdcpStatus.eAuthenticationState = BHDCPlib_State_eWaitForRepeaterReady;
294
295        /* Restart periodic timer for msIntervalKsvFifoReadyCheck */
296        hHDCPlib->bRepeaterReadyTimerExpired = false;
297        BTMR_StopTimer(hHDCPlib->hTimer);
298        BTMR_StartTimer(hHDCPlib->hTimer, hHDCPlib->stHdcpConfiguration.msIntervalKsvFifoReadyCheck * 1000) ;
299
300done:   
301       
302        /* Clear authentication if error */
303        if (rc != BERR_SUCCESS)
304                BHDM_HDCP_ClearAuthentication(hHDCPlib->stDependencies.hHdm);
305
306        BHDCPlib_P_ShowStateChange(hHDCPlib, currentState) ;
307       
308        BDBG_LEAVE(BHDCPlib_P_CheckRepeaterReady);
309        return rc;
310       
311}
312
313
314static void BHDCPlib_P_TimerExpiration_isr (BHDCPlib_Handle hHDCPlib, int parm2) 
315{
316        BDBG_ENTER(BHDCPlib_P_TimerExpiration_isr);
317        BDBG_ASSERT(hHDCPlib);
318        BSTD_UNUSED(parm2);
319
320        switch (hHDCPlib->stHdcpStatus.eAuthenticationState)
321        {
322        case BHDCPlib_State_eWaitForReceiverAuthentication :
323                hHDCPlib->bR0ReadyTimerExpired = true;
324                break ;
325
326        case BHDCPlib_State_eWaitForRepeaterReady:
327                hHDCPlib->bRepeaterReadyTimerExpired = true;
328                break;
329               
330        default :
331                BDBG_WRN(("Unknown Timer expiration...")) ;
332        }
333       
334        BDBG_LEAVE(BHDCPlib_P_TimerExpiration_isr);
335}
336
337
338BERR_Code BHDCPlib_Open(BHDCPlib_Handle *hHDCPlib, const BHDCPlib_Dependencies *pstDependencies)
339{
340        BERR_Code rc = BERR_SUCCESS;
341        BHDCPlib_Handle hHandle;
342
343
344        BDBG_ENTER(BHDCPlib_Open);
345        BDBG_ASSERT(pstDependencies->hHdm);
346        BDBG_ASSERT(pstDependencies->hHsm);
347        BDBG_ASSERT(pstDependencies->hTmr);
348
349        /* Alloc memory from the system */
350        hHandle = BKNI_Malloc(sizeof(BHDCPlib_P_Handle));
351        if (hHandle == NULL)
352        {
353                rc = BERR_OUT_OF_SYSTEM_MEMORY;
354                BDBG_ERR(("BHDCPlib_Open: BKNI_malloc() failed\n"));
355                goto done;
356        }               
357       
358
359#if 0
360        if (!pstDependentData->pfHdcpGetRevokedKsvsCallback)
361        {
362                BDBG_ERR(("Missing required callback functions"));
363                rc = BERR_INVALID_PARAMETER;
364                goto done ;
365        }
366#endif
367
368        BKNI_Memcpy(&hHandle->stDependencies, pstDependencies, sizeof(BHDCPlib_Dependencies)) ;
369        hHandle->hTmr = pstDependencies->hTmr ;
370               
371    hHandle->stTmrSettings.type =  BTMR_Type_eCountDown ;
372        hHandle->stTmrSettings.cb_isr = (BTMR_CallbackFunc) BHDCPlib_P_TimerExpiration_isr ;
373        hHandle->stTmrSettings.pParm1 = hHandle;
374        hHandle->stTmrSettings.parm2 = 0 ;
375        hHandle->stTmrSettings.exclusive = false ;
376
377        rc = BTMR_CreateTimer(hHandle->hTmr, &hHandle->hTimer, &hHandle->stTmrSettings) ;
378        if(rc != BERR_SUCCESS)
379        {
380                rc = BERR_TRACE(BERR_LEAKED_RESOURCE);
381                goto done ;
382        }
383
384        /* Initialize HDCP authentication state, error status */
385        hHandle->stHdcpStatus.eAuthenticationState = BHDCPlib_State_eUnauthenticated;
386        hHandle->stHdcpStatus.eHdcpError = BHDCPlib_HdcpError_eSuccess;
387
388        /* Set default HDCP configuration information*/
389        BHDCPlib_GetDefaultConfiguration(&hHandle->stHdcpConfiguration);
390
391        /* Initialize revoked KSV list */
392        hHandle->RevokedKsvList.Ksvs = NULL;
393        hHandle->RevokedKsvList.uiNumRevokedKsvs = 0;
394       
395done:
396        if (rc != BERR_SUCCESS)
397        {
398                if (!hHandle)
399                {
400                        BKNI_Free(hHandle);
401                        hHandle=NULL;
402                }
403        }
404       
405        *hHDCPlib = hHandle;
406       
407        BDBG_LEAVE(BHDCPlib_Open);
408        return rc ;
409       
410}
411
412
413BERR_Code BHDCPlib_Close(BHDCPlib_Handle hHDCPlib)
414{
415        BERR_Code rc = BERR_SUCCESS;
416       
417        BDBG_ENTER(BHDCPlib_Close);
418        BDBG_ASSERT(hHDCPlib);
419
420        rc = BTMR_DestroyTimer(hHDCPlib->hTimer);
421        if (rc != BERR_SUCCESS)
422                BDBG_ERR(("Error destroying timer"));
423
424
425        /* free memory associated with the Revoked KSV list, if any */
426        if (hHDCPlib->RevokedKsvList.Ksvs)
427        {
428                BKNI_Free(hHDCPlib->RevokedKsvList.Ksvs);
429                hHDCPlib->RevokedKsvList.Ksvs = NULL;
430                hHDCPlib->RevokedKsvList.uiNumRevokedKsvs = 0;
431        }
432       
433        /* free memory associated with the HDMIlib Handle */
434        BKNI_Memset(hHDCPlib, 0, sizeof(BHDCPlib_P_Handle)) ;
435        BKNI_Free( (void *) hHDCPlib) ;
436
437       
438        BDBG_LEAVE(BHDCPlib_Close);
439        return rc;
440}
441
442
443BERR_Code BHDCPlib_GetDefaultDependencies(BHDCPlib_Dependencies *pDefaultDependencies)
444{
445        BERR_Code rc = BERR_SUCCESS;
446
447        BDBG_ENTER(BHDCPlib_GetDefaultDependencies);
448
449        /* Set all Dependencies to NULL */
450        BKNI_Memset(pDefaultDependencies, 0, sizeof(*pDefaultDependencies)); 
451
452        BDBG_LEAVE(BHDCPlib_GetDefaultDependencies);
453        return rc;
454}
455
456
457BERR_Code BHDCPlib_InitializeReceiverAuthentication(BHDCPlib_Handle hHDCPlib)
458{
459        BERR_Code   rc = BERR_SUCCESS;
460        uint8_t ucDeviceAttached=0;
461       
462        BDBG_ENTER(BHDCPlib_InitializeReceiverAuthentication) ;
463        BDBG_ASSERT(hHDCPlib);
464        BDBG_ASSERT(hHDCPlib->stDependencies.hHdm) ;   
465
466
467        rc = BHDM_RxDeviceAttached(hHDCPlib->stDependencies.hHdm, &ucDeviceAttached) ;
468        if (!ucDeviceAttached)
469        {
470                hHDCPlib->stHdcpStatus.eAuthenticationState = BHDCPlib_State_eUnPowered;
471                goto done;
472        }
473
474        /* get revoked list */
475        if (!hHDCPlib->stDependencies.pfHdcpGetRevokedKsvsCallback)
476        {
477                BDBG_WRN(("No Revoked KSV Callback Installed")) ;
478        }
479        else
480        {
481                BHDCPlib_RevokedKsvList tmpRevokedKSVs;
482               
483                hHDCPlib->stDependencies.pfHdcpGetRevokedKsvsCallback(
484                        hHDCPlib->stDependencies.pSysDevice, 
485                        hHDCPlib->stDependencies.iGetRevokedKsvParam2,
486                        &tmpRevokedKSVs) ;
487
488                BHDCPlib_SetRevokedKSVs(hHDCPlib, &tmpRevokedKSVs);
489        }
490
491        /* Retrieve Receiver information before starting the authentication process */
492        rc = BHDCPlib_GetReceiverInfo(hHDCPlib, &hHDCPlib->stHdcpConfiguration.RxInfo);
493        if (rc != BERR_SUCCESS)
494        {
495                BDBG_ERR(("Error getting receiver info"));
496                goto done;
497        }
498
499        /* Read the Bksv from the Rx,  compare revoked list against retrieved Rx information */
500        rc = BHDM_HDCP_ReadRxBksv(hHDCPlib->stDependencies.hHdm, 
501                (const uint8_t *) hHDCPlib->RevokedKsvList.Ksvs, 
502                hHDCPlib->RevokedKsvList.uiNumRevokedKsvs);
503        if (rc != BERR_SUCCESS) 
504                goto done;
505
506
507        /* Update the RxBksv in BHDCPlib_Configuration */
508        rc = BHDM_HDCP_GetRxKsv(hHDCPlib->stDependencies.hHdm, (uint8_t *) hHDCPlib->stHdcpConfiguration.RxInfo.RxBksv);
509        if (rc != BERR_SUCCESS) 
510                goto done;
511       
512
513        /* Generate/Write the Authentication An value */
514        rc = BHDM_HDCP_GenerateAn(hHDCPlib->stDependencies.hHdm, hHDCPlib->stHdcpConfiguration.eAnSelection) ;
515        if (rc != BERR_SUCCESS)
516                goto done;     
517
518
519        /* Write the Tx Aksv to the Receiver */
520        rc = BHDM_HDCP_WriteTxAksvToRx(hHDCPlib->stDependencies.hHdm, hHDCPlib->stHdcpConfiguration.TxKeySet.TxAksv);
521        if (rc != BERR_SUCCESS)
522                goto done;
523
524
525        /* load the transmitter HDCP Keys */
526        rc = BHDM_HDCP_EnableSerialKeyLoad(hHDCPlib->stDependencies.hHdm);
527        if (rc != BERR_SUCCESS) 
528                goto done;
529
530
531        rc = BHDCPlib_FastLoadEncryptedHdcpKeys(hHDCPlib);
532        if (rc != BERR_SUCCESS)
533                goto done;
534
535
536        /* Initiate timer countdown for msWaitForR0 (default 100ms) before setting Receiver Ready */
537        hHDCPlib->bR0ReadyTimerExpired = false;
538        BTMR_StopTimer(hHDCPlib->hTimer);
539        BTMR_StartTimer(hHDCPlib->hTimer, hHDCPlib->stHdcpConfiguration.msWaitForR0 * 1000) ;
540
541        /* Update HDCP authentication state */
542        hHDCPlib->stHdcpStatus.eAuthenticationState = BHDCPlib_State_eWaitForReceiverAuthentication;
543       
544done:
545
546        if (rc != BERR_SUCCESS)
547                hHDCPlib->stHdcpStatus.eAuthenticationState = BHDCPlib_State_eUnauthenticated;
548
549        BDBG_LEAVE(BHDCPlib_InitializeReceiverAuthentication) ;
550        return rc ;
551       
552}
553
554
555
556BERR_Code BHDCPlib_AuthenticateReceiver(BHDCPlib_Handle hHDCPlib)
557{
558        BERR_Code rc = BERR_SUCCESS;
559
560        BDBG_ENTER(BHDCPlib_AuthenticateReceiver) ;
561        BDBG_ASSERT(hHDCPlib);
562
563
564        /* Authenticate the Link  */
565        rc = BHDM_HDCP_AuthenticateLink(hHDCPlib->stDependencies.hHdm) ;
566        if ( rc != BERR_SUCCESS) 
567        {
568                hHDCPlib->stHdcpStatus.eAuthenticationState = BHDCPlib_State_eR0LinkFailure;
569                goto done;
570        }
571
572        hHDCPlib->stHdcpStatus.eAuthenticationState = BHDCPlib_State_eReceiverAuthenticated;
573
574        rc = BHDM_HDCP_XmitEncrypted(hHDCPlib->stDependencies.hHdm);
575        if (rc != BERR_SUCCESS)
576                goto done;
577       
578done:
579       
580        BDBG_LEAVE(BHDCPlib_AuthenticateReceiver) ;
581        return rc;
582       
583}
584
585
586
587BERR_Code BHDCPlib_InitializeRepeaterAuthentication(BHDCPlib_Handle hHDCPlib)
588{
589        BERR_Code rc = BERR_SUCCESS;
590       
591        BDBG_ENTER(BHDCPlib_InitializeRepeaterAuthentication) ;
592        BDBG_ASSERT(hHDCPlib);
593
594        /* Set default configuration    */
595        hHDCPlib->stHdcpConfiguration.msIntervalKsvFifoReadyCheck = 100;
596        hHDCPlib->stHdcpConfiguration.uiKsvFifoReadyChecks = 1;
597
598        /* Enable/Initiate periodic timer once every msIntervalKsvFifoReadyCheck */
599        hHDCPlib->bRepeaterReadyTimerExpired = false;
600        BTMR_StopTimer(hHDCPlib->hTimer);
601        BTMR_StartTimer(hHDCPlib->hTimer, hHDCPlib->stHdcpConfiguration.msIntervalKsvFifoReadyCheck * 1000) ;
602
603        /* Update state machine */
604        hHDCPlib->stHdcpStatus.eAuthenticationState = BHDCPlib_State_eWaitForRepeaterReady;
605
606        BDBG_LEAVE(BHDCPlib_InitializeRepeaterAuthentication) ;
607        return rc ;
608}
609
610
611
612BERR_Code BHDCPlib_AuthenticateRepeater(BHDCPlib_Handle hHDCPlib)
613{
614        BERR_Code rc = BERR_SUCCESS;
615        uint16_t BStatus;
616        uint8_t RepeaterLevels;
617        uint8_t DeviceCount;
618        uint16_t uiNumKsvBytes;
619        uint8_t KsvListMemoryAllocated = 0 ;
620        uint8_t *KsvFifoList = NULL ;
621
622        BDBG_ENTER(BHDCPlib_AuthenticateRepeater) ;
623        BDBG_ASSERT(hHDCPlib);
624       
625
626        /* check Repeater Values */
627        BHDCPLIB_CHECK_RC(rc, 
628                BHDM_HDCP_GetRxStatus(hHDCPlib->stDependencies.hHdm, &BStatus)) ;
629        BHDCPLIB_CHECK_RC(rc, 
630                BHDM_HDCP_GetRepeaterDepth(hHDCPlib->stDependencies.hHdm, &RepeaterLevels)) ;
631        BHDCPLIB_CHECK_RC(rc, 
632                BHDM_HDCP_GetRepeaterDeviceCount(hHDCPlib->stDependencies.hHdm, &DeviceCount)) ;
633
634        BDBG_MSG(("RXStatus: %X, Depth: %d, Devices: %d",
635                BStatus, RepeaterLevels, DeviceCount)) ;
636       
637       
638        /* check if the number of repeater levels has been exceeded */
639        if (BStatus & BHDM_HDCP_RxStatus_eMaxRepeatersExceeded)
640        {
641                BDBG_ERR(("%d Levels of Repeaters exceed the MAX allowed of %d", 
642                        RepeaterLevels, BHDM_HDCP_REPEATER_MAX_DEPTH )) ;
643                rc = BHDM_HDCP_REPEATER_DEPTH_EXCEEDED ;
644                goto done;
645        }
646
647        /* check if the number of receiver devices has been exceeded */
648        if (BStatus & BHDM_HDCP_RxStatus_eMaxDevicesExceeded) 
649        {
650                BDBG_ERR(("Number of Devices: %d exceeds the MAX allowed of %d", 
651                        DeviceCount, BHDM_HDCP_REPEATER_MAX_DEVICE_COUNT )) ;
652                rc = BHDM_HDCP_RX_DEVICES_EXCEEDED ;
653                goto done ;
654        }
655
656        /* initialize the Repeater Authentication */
657        BHDM_HDCP_InitializeRepeaterAuthentication(hHDCPlib->stDependencies.hHdm);
658
659        if (DeviceCount)
660        {
661                /* allocate a buffer to hold the Ksv List */
662                uiNumKsvBytes = (uint16_t) (DeviceCount * BHDM_HDCP_KSV_LENGTH) ;
663                KsvFifoList = (uint8_t *) BKNI_Malloc(sizeof(uint8_t) * uiNumKsvBytes) ;
664                KsvListMemoryAllocated = 1 ;
665
666                /* read the Ksv List */
667                /* pass the revoked list for checking against downstream Rx devices */
668                BHDCPLIB_CHECK_RC(rc, 
669                        BHDM_HDCP_ReadRxRepeaterKsvFIFO(hHDCPlib->stDependencies.hHdm, 
670                                KsvFifoList, DeviceCount, 
671                                (uint8_t *) &hHDCPlib->RevokedKsvList.Ksvs, 
672                                (uint16_t) hHDCPlib->RevokedKsvList.uiNumRevokedKsvs)) ;
673
674                /* write the Ksvs from the Rx (Repeater) to the Transmitter core for verification */
675                BHDCPLIB_CHECK_RC(rc, 
676                        BHDM_HDCP_WriteTxKsvFIFO(hHDCPlib->stDependencies.hHdm, 
677                                KsvFifoList, DeviceCount)) ;
678       
679        }
680        else    /* handle zero devices attached to repeater */
681        {
682#if BHDM_CONFIG_DISABLE_HDCP_AUTH_REPEATER_DEVCOUNT0
683                /* do not allow authentication with repeaters that have device count of 0 */
684                BDBG_WRN(("Auth Disabled for Repeaters with Device Count of 0")) ;
685                rc = BHDM_HDCP_REPEATER_DEVCOUNT_0 ;
686                goto done;
687#else
688                /* force V calculation for repeater with zero attached devices */
689                BHDM_HDCP_ForceVCalculation(hHDCPlib->stDependencies.hHdm) ;
690#endif         
691       
692        }
693
694        /* check SHA-1 Hash Verification (V).... */
695        BHDCPLIB_CHECK_RC(rc, 
696                BHDM_HDCP_RepeaterAuthenticateLink(hHDCPlib->stDependencies.hHdm, 
697                        &hHDCPlib->stHdcpConfiguration.RxInfo.uiIsAuthenticated)) ;
698       
699        if (!hHDCPlib->stHdcpConfiguration.RxInfo.uiIsAuthenticated)
700        {
701                BDBG_ERR(("Repeater failed to authenticate")) ; 
702                rc = BHDM_HDCP_REPEATER_AUTH_ERROR ;
703                goto done ;
704        }
705       
706        hHDCPlib->stHdcpStatus.eAuthenticationState = BHDCPlib_State_eLinkAuthenticated;               
707       
708done:
709        /* release allocated memory for Ksv list */
710        if (KsvListMemoryAllocated)
711                BKNI_Free(KsvFifoList) ;
712
713        if (rc != BERR_SUCCESS)
714                hHDCPlib->stHdcpStatus.eAuthenticationState = BHDCPlib_State_eRepeaterAuthenticationFailure;
715               
716        BDBG_LEAVE(BHDCPlib_AuthenticateRepeater) ;
717        return rc ;
718}
719
720
721BERR_Code BHDCPlib_TransmitEncrypted(BHDCPlib_Handle hHDCPlib)
722{
723        BERR_Code rc = BERR_SUCCESS;
724
725        BDBG_ENTER(BHDCPlib_TransmitEncrypted);
726        BDBG_ASSERT(hHDCPlib);
727       
728        rc = BHDM_HDCP_XmitEncrypted(hHDCPlib->stDependencies.hHdm);
729        if (rc != BERR_SUCCESS)
730                goto done;
731
732        hHDCPlib->stHdcpStatus.eAuthenticationState = BHDCPlib_State_eEncryptionEnabled;
733       
734done:   
735
736        BDBG_LEAVE(BHDCPlib_TransmitEncrypted); 
737        return rc;
738}
739
740BERR_Code BHDCPlib_TransmitClear(BHDCPlib_Handle hHDCPlib)
741{
742        BERR_Code rc = BERR_SUCCESS;
743        BHDCPlib_State currentState = hHDCPlib->stHdcpStatus.eAuthenticationState;
744
745        BDBG_ENTER(BHDCPlib_TransmitClear);
746        BDBG_ASSERT(hHDCPlib);
747       
748        rc = BHDM_HDCP_XmitClear(hHDCPlib->stDependencies.hHdm);
749        if (rc != BERR_SUCCESS)
750                goto done;
751
752        hHDCPlib->stHdcpStatus.eAuthenticationState = BHDCPlib_State_eUnauthenticated; 
753
754        BHDCPlib_P_ShowStateChange(hHDCPlib, currentState) ;
755       
756done:   
757
758        BDBG_LEAVE(BHDCPlib_TransmitClear);     
759        return rc;
760}
761
762void BHDCPlib_ProcessEvent(BHDCPlib_Handle hHDCPlib, BHDCPlib_Event *stHdmiEvent)
763{
764
765        BERR_Code rc ;
766        uint8_t ucRxSense;
767        uint8_t ucDeviceAttached;
768        uint8_t ucErrorDetected = 0 ; 
769        BHDCPlib_State currentState = hHDCPlib->stHdcpStatus.eAuthenticationState;
770
771        BDBG_ENTER(BHDCPlib_ProcessEvent);
772       
773        switch (stHdmiEvent->event)
774        {
775        case BHDM_EventHDCPRiValue:
776                if (BHDM_HDCP_RiLinkIntegrityCheck(hHDCPlib->stDependencies.hHdm) != BERR_SUCCESS)
777                {
778                        hHDCPlib->stHdcpStatus.eAuthenticationState = BHDCPlib_State_eRiLinkIntegrityFailure;
779                        ucErrorDetected = 1 ;
780                }
781
782                break;
783               
784        case BHDM_EventHDCPPjValue:
785                if (BHDM_HDCP_PjLinkIntegrityCheck(hHDCPlib->stDependencies.hHdm) != BERR_SUCCESS) 
786                {
787                        hHDCPlib->stHdcpStatus.eAuthenticationState = BHDCPlib_State_ePjLinkIntegrityFailure;
788                        ucErrorDetected = 1 ;
789                }
790       
791                break;
792               
793        case BHDM_EventHDCPRepeater:
794                hHDCPlib->stHdcpStatus.eAuthenticationState = BHDCPlib_State_eRepeaterAuthenticationFailure;
795                ucErrorDetected = 1 ;
796                break;
797               
798        case BHDM_EventHotPlug:
799                rc = BHDM_RxDeviceAttached(hHDCPlib->stDependencies.hHdm, &ucDeviceAttached) ;
800
801                if (!ucDeviceAttached)
802                        hHDCPlib->stHdcpStatus.eAuthenticationState =
803                                BHDCPlib_State_eUnPowered;
804                else
805                        hHDCPlib->stHdcpStatus.eAuthenticationState = 
806                                BHDCPlib_State_eUnauthenticated;
807
808                break;
809               
810        default:
811                BDBG_WRN(("Invalid Event")) ;
812                break;
813        }
814
815        if (ucErrorDetected)
816        {
817                rc = BHDM_GetReceiverSense(hHDCPlib->stDependencies.hHdm, &ucRxSense);
818                if (!ucRxSense)
819                {
820                        BDBG_WRN(("HdcpLibState: %d generated due to Rx powered off", 
821                                hHDCPlib->stHdcpStatus.eAuthenticationState)) ;
822                        hHDCPlib->stHdcpStatus.eAuthenticationState = BHDCPlib_State_eUnPowered;
823                }
824        }
825
826        BHDCPlib_P_ShowStateChange(hHDCPlib, currentState) ;
827       
828        BDBG_LEAVE(BHDCPlib_ProcessEvent);
829        return;
830}
831
832
833BERR_Code BHDCPlib_SetRevokedKSVs(BHDCPlib_Handle hHDCPlib, BHDCPlib_RevokedKsvList *stKsvList)
834{
835        BERR_Code rc = BERR_SUCCESS;
836
837        BDBG_ENTER(BHDCPlib_SetRevokedKSVs);
838        BDBG_ASSERT(hHDCPlib);
839
840
841        if (hHDCPlib->RevokedKsvList.Ksvs)
842        {
843                BKNI_Free(hHDCPlib->RevokedKsvList.Ksvs);
844                hHDCPlib->RevokedKsvList.Ksvs = NULL;
845                hHDCPlib->RevokedKsvList.uiNumRevokedKsvs = 0;
846        }
847       
848        if (!stKsvList->uiNumRevokedKsvs)
849        {
850                BDBG_WRN(("No Revoked KSVs specified."));
851                goto done;
852        }
853       
854        /* Store the Revoked KSVs in the handle */
855        hHDCPlib->RevokedKsvList.Ksvs = 
856                BKNI_Malloc(sizeof(uint8_t) * stKsvList->uiNumRevokedKsvs * BAVC_HDMI_HDCP_KSV_LENGTH);
857       
858        BKNI_Memcpy(hHDCPlib->RevokedKsvList.Ksvs, stKsvList->Ksvs, 
859                                        (sizeof(uint8_t) * stKsvList->uiNumRevokedKsvs * BAVC_HDMI_HDCP_KSV_LENGTH));
860       
861        hHDCPlib->RevokedKsvList.uiNumRevokedKsvs = stKsvList->uiNumRevokedKsvs;
862
863done:
864        BDBG_LEAVE(BHDCPlib_SetRevokedKSVs);
865        return rc;
866}
867
868
869BERR_Code BHDCPlib_SetConfiguration(BHDCPlib_Handle hHDCPlib, BHDCPlib_Configuration * stHdcpConfiguration)
870{
871        BDBG_ENTER(BHDCPlib_SetConfiguration);
872        BDBG_ASSERT(hHDCPlib);
873
874       
875        /* Copy Hdcp Link data into HDMlib handle       */
876        BKNI_Memcpy(&hHDCPlib->stHdcpConfiguration, stHdcpConfiguration, sizeof(BHDCPlib_Configuration));
877
878
879        BDBG_LEAVE(BHDCPlib_SetConfiguration);
880        return BERR_SUCCESS;
881}
882
883BERR_Code BHDCPlib_GetDefaultConfiguration(BHDCPlib_Configuration *stHdcpConfiguration)
884{
885        BDBG_ENTER(BHDCPlib_GetDefaultConfiguration);
886        BDBG_ASSERT(stHdcpConfiguration);
887
888        /* Copy default Hdcp configuration */
889        BKNI_Memcpy(stHdcpConfiguration, &stHdcpDefaultConfiguration, sizeof(BHDCPlib_Configuration));
890
891        BDBG_LEAVE(BHDCPlib_GetDefaultConfiguration);
892        return BERR_SUCCESS;
893}
894
895BERR_Code BHDCPlib_GetConfiguration(BHDCPlib_Handle hHDCPlib, BHDCPlib_Configuration *stHdcpConfiguration)
896{
897        BDBG_ENTER(BHDCPlib_GetConfiguration);
898        BDBG_ASSERT(hHDCPlib);
899
900
901        /* Copy Hdcp Link data from HDCPlib handle */
902        BKNI_Memcpy(stHdcpConfiguration, &hHDCPlib->stHdcpConfiguration, sizeof(BHDCPlib_Configuration));
903
904
905        BDBG_LEAVE(BHDCPlib_GetConfiguration);
906        return BERR_SUCCESS;
907}
908
909
910BERR_Code BHDCPlib_GetReceiverInfo(BHDCPlib_Handle hHDCPlib, BHDCPlib_RxInfo *stRxHdcpInfo)
911{
912        BERR_Code rc = BERR_SUCCESS;
913       
914        BDBG_ENTER(BHDCPlib_GetReceiverInfo);
915        BDBG_ASSERT(hHDCPlib);
916
917
918        /* Retrieve RxBCaps */
919        rc = BHDM_HDCP_GetRxCaps(hHDCPlib->stDependencies.hHdm, 
920                                &stRxHdcpInfo->uiRxBCaps) ;
921        if (rc != BERR_SUCCESS)
922        {
923                BDBG_ERR(("Error getting Rx BCaps"));
924                goto done;
925        }
926
927        /* Retrieve the RxBksv */
928        rc = BHDM_HDCP_GetRxKsv(hHDCPlib->stDependencies.hHdm, 
929                                (uint8_t *) stRxHdcpInfo->RxBksv);
930        if (rc != BERR_SUCCESS) 
931        {
932                BDBG_ERR(("Error getting Rx BCaps"));   
933                goto done;
934        }
935
936        /* Check for Repeater */
937        stRxHdcpInfo->bIsHdcpRepeater = 
938                stRxHdcpInfo->uiRxBCaps & BHDM_HDCP_RxCaps_eHdcpRepeater ;
939       
940done:
941
942        BDBG_LEAVE(BHDCPlib_GetReceiverInfo);
943        return rc;
944       
945}
946
947
948BERR_Code BHDCPlib_GetAuthenticationState(BHDCPlib_Handle hHDCPlib, BHDCPlib_State *eAuthenticationState)
949{
950        BDBG_ENTER(BHDCPlib_GetAuthenticationState);
951        BDBG_ASSERT(hHDCPlib);
952
953        /* Retrieve the current HDCP authentication state */
954        *eAuthenticationState = hHDCPlib->stHdcpStatus.eAuthenticationState;
955
956        BDBG_LEAVE(BHDCPlib_GetAuthenticationState);
957        return BERR_SUCCESS;
958}
959
960
961BERR_Code BHDCPlib_GetHdcpStatus(BHDCPlib_Handle hHDCPlib, BHDCPlib_Status *stHdcpStatus)
962{
963        BDBG_ENTER(BHDCPlib_GetHdcpStatus);
964        BDBG_ASSERT(hHDCPlib);
965
966        /* Retrieve the current HDCP status  */
967        BKNI_Memcpy(stHdcpStatus, &hHDCPlib->stHdcpStatus, sizeof(BHDCPlib_Status));
968
969
970        BDBG_LEAVE(BHDCPlib_GetHdcpStatus);
971        return BERR_SUCCESS;
972}
973
974
975bool BHDCPlib_LinkReadyForEncryption(BHDCPlib_Handle hHDCPlib)
976{
977        bool brc = false;
978
979        BDBG_ENTER(BHDCPlib_LinkReadyForEncryption);
980        BDBG_ASSERT(hHDCPlib);
981       
982        if (hHDCPlib->stHdcpStatus.eAuthenticationState == BHDCPlib_State_eLinkAuthenticated)
983                brc = true;
984
985
986        BDBG_LEAVE(BHDCPlib_LinkReadyForEncryption);
987        return brc;
988}
989
990
991BERR_Code BHDCPlib_StartAuthentication(BHDCPlib_Handle hHDCPlib)
992{
993        BHDCPlib_State currentState = hHDCPlib->stHdcpStatus.eAuthenticationState;
994
995        BDBG_ENTER(BHDCPlib_StartAuthentication);
996        BDBG_ASSERT(hHDCPlib);
997
998        /* Initialize HDCP Authentication state */
999        hHDCPlib->stHdcpStatus.eAuthenticationState = BHDCPlib_State_eInitializeAuthentication;
1000
1001        BHDCPlib_P_ShowStateChange(hHDCPlib, currentState) ;
1002
1003        BDBG_LEAVE(BHDCPlib_StartAuthentication);
1004        return BERR_SUCCESS;
1005}
1006
1007
1008/******************************
1009
1010Possible return errors:
1011
1012BHDM_NO_RX_DEVICE
1013BHDM_HDCP_RX_BKSV_ERROR
1014BHDM_HDCP_RX_BKSV_REVOKED
1015BHDM_HDCP_TX_AKSV_ERROR
1016
1017BHDM_HDCP_AUTH_ABORTED
1018BHDM_HDCP_AUTHENTICATE_ERROR           
1019BHDM_HDCP_LINK_RI_FAILURE
1020BHDM_HDCP_LINK_PJ_FAILURE       
1021
1022BHDM_HDCP_REPEATER_FIFO_NOT_READY
1023BHDM_HDCP_REPEATER_DEVCOUNT_0
1024BHDM_HDCP_REPEATER_DEPTH_EXCEEDED
1025BHDM_HDCP_RX_DEVICES_EXCEEDED
1026
1027
1028TBD:
1029
1030BHDM_HDCP_RX_NO_HDCP_SUPPORT
1031BHDM_HDCP_RECEIVER_AUTH_ERROR
1032BHDM_HDCP_REPEATER_AUTH_ERROR
1033BHDM_HDCP_NO_AUTHENTICATED_LINK
1034
1035**********************************/ 
1036BERR_Code BHDCPlib_ProcessAuthentication(BHDCPlib_Handle hHDCPlib, BHDCPlib_Status *stHdcpStatus)
1037{
1038        BERR_Code rc = BERR_SUCCESS;
1039        uint8_t i;
1040        bool bErrFound = false;
1041        BHDCPlib_State currentState = hHDCPlib->stHdcpStatus.eAuthenticationState;
1042
1043        BDBG_ENTER(BHDCPlib_ProcessAuthentication);
1044        BDBG_ASSERT(hHDCPlib);
1045
1046
1047        /* Always recommend a delay of 1 ms between states unless specified below */
1048        hHDCPlib->stHdcpStatus.msRecommendedWaitTime = 1;
1049       
1050        switch (hHDCPlib->stHdcpStatus.eAuthenticationState)
1051        {
1052        case BHDCPlib_State_eUnPowered:
1053                hHDCPlib->stHdcpStatus.msRecommendedWaitTime = 500 ;
1054                break;
1055
1056        case BHDCPlib_State_eUnauthenticated:
1057                hHDCPlib->stHdcpStatus.msRecommendedWaitTime = 100;
1058                break;
1059
1060        case BHDCPlib_State_eInitializeAuthentication:
1061                /* Attempting first part of authentication */
1062                rc = BHDCPlib_InitializeReceiverAuthentication(hHDCPlib);
1063                if (rc != BERR_SUCCESS)
1064                {
1065                        BDBG_ERR(("first part of the authentication process failed")) ;
1066                        goto done;
1067                }               
1068                break;
1069
1070        case BHDCPlib_State_eWaitForReceiverAuthentication:
1071                if (hHDCPlib->bR0ReadyTimerExpired)
1072                        hHDCPlib->stHdcpStatus.eAuthenticationState = BHDCPlib_State_eReceiverR0Ready;
1073                else
1074                        hHDCPlib->stHdcpStatus.msRecommendedWaitTime = hHDCPlib->stHdcpConfiguration.msWaitForR0;
1075               
1076                break;
1077
1078        case BHDCPlib_State_eReceiverR0Ready:
1079                rc = BHDCPlib_AuthenticateReceiver(hHDCPlib);
1080                if (rc != BERR_SUCCESS)
1081                {
1082                        BDBG_ERR(("Failed to authenticate receiver"));
1083                        goto done;
1084                }
1085                break;
1086
1087        case BHDCPlib_State_eR0LinkFailure:
1088                hHDCPlib->stHdcpStatus.msRecommendedWaitTime = 2000;
1089                break;
1090               
1091        case BHDCPlib_State_eReceiverAuthenticated:
1092                /* Proceed to part 2 of authentication if attached device is a repeater */
1093                if (hHDCPlib->stHdcpConfiguration.RxInfo.bIsHdcpRepeater)
1094                {
1095                        rc = BHDCPlib_InitializeRepeaterAuthentication(hHDCPlib);
1096                        if (rc != BERR_SUCCESS)
1097                        {
1098                                BDBG_ERR(("Second part of the authentication process failed"));
1099                                goto done;
1100                        }
1101                }
1102                else
1103                        hHDCPlib->stHdcpStatus.eAuthenticationState = BHDCPlib_State_eLinkAuthenticated;
1104
1105                break;
1106               
1107        case BHDCPlib_State_eWaitForRepeaterReady:             
1108                if (hHDCPlib->bRepeaterReadyTimerExpired)
1109                        hHDCPlib->stHdcpStatus.eAuthenticationState = BHDCPlib_State_eCheckForRepeaterReady;
1110                else
1111                        /* Recommend waiting 100 ms for Repeater Fifo ready */
1112                        hHDCPlib->stHdcpStatus.msRecommendedWaitTime = 100;
1113               
1114                break;
1115       
1116        case BHDCPlib_State_eCheckForRepeaterReady:
1117                /* Check for repeater FIFO ready */
1118                rc = BHDCPlib_P_CheckRepeaterReady(hHDCPlib);
1119                if (rc != BERR_SUCCESS)
1120                {
1121                        BDBG_ERR(("Repeater KSV FIFO not ready"));
1122                        goto done;
1123                }
1124                break;
1125
1126        case BHDCPlib_State_eRepeaterReady:
1127                /* Repeater Ready, start authenticate repeater */
1128                rc = BHDCPlib_AuthenticateRepeater(hHDCPlib);
1129                if (rc != BERR_SUCCESS)
1130                {
1131                        BDBG_ERR(("Failed to authenticate repeater"));
1132                        goto done;
1133                }
1134                break;
1135               
1136        case BHDCPlib_State_eLinkAuthenticated:
1137                /* HDCP AUTHENTICATION SUCCESS - link is now authenticated */
1138
1139                /* Recommend 10ms for checking encryption enabled */
1140                hHDCPlib->stHdcpStatus.msRecommendedWaitTime = 10;             
1141                break;
1142
1143
1144        case BHDCPlib_State_eEncryptionEnabled:
1145                /* Transmitting Encrypted Video */
1146                hHDCPlib->stHdcpStatus.msRecommendedWaitTime = 2000;
1147                goto done;             
1148                break;
1149
1150        case BHDCPlib_State_eRepeaterAuthenticationFailure:
1151                /* Repeater Error */
1152                rc = BHDM_HDCP_LINK_FAILURE;
1153                break;
1154
1155        case BHDCPlib_State_eRiLinkIntegrityFailure:
1156                /* Ri Link Failure */
1157                rc = BHDM_HDCP_LINK_RI_FAILURE;
1158                break;
1159
1160        case BHDCPlib_State_ePjLinkIntegrityFailure:
1161                /* Pj Link Failure */
1162                rc = BHDM_HDCP_LINK_PJ_FAILURE ;
1163                break;
1164       
1165        default:
1166                BDBG_WRN(("Invalid HDCP Authentication state: %d", hHDCPlib->stHdcpStatus.eAuthenticationState)) ;
1167                break;
1168                       
1169        }
1170
1171       
1172done:
1173        /* HDCP error */
1174        for (i=0; i < sizeof(BHDCPlib_SupportedHdcpErrors)/sizeof(BHDCPLIB_P_HDM_HdcpErrors); i++)
1175        {
1176                if (rc == BHDCPlib_SupportedHdcpErrors[i].hdmHdcpError)
1177                {
1178                        hHDCPlib->stHdcpStatus.eHdcpError = BHDCPlib_SupportedHdcpErrors[i].hdcplibHdcpError;
1179                        bErrFound = true;
1180                        break;
1181                }
1182        }
1183
1184        if (!bErrFound)
1185        {
1186                BDBG_ERR(("Unable to find matching BHDM_HDCP return code for HDCPlib return code %d", rc));
1187                BDBG_ERR(("Current Authentication State: %s (%d)", 
1188                        BHDCPlib_StateText[currentState], currentState)) ;
1189
1190                hHDCPlib->stHdcpStatus.eHdcpError = BHDCPlib_HdcpError_eReceiverAuthenticationError;
1191        }
1192
1193        /* Save current hdcp status  */
1194        BKNI_Memcpy(stHdcpStatus, &hHDCPlib->stHdcpStatus, sizeof(BHDCPlib_Status));
1195
1196        BHDCPlib_P_ShowStateChange(hHDCPlib, currentState) ;
1197       
1198        BDBG_LEAVE(BHDCPlib_ProcessAuthentication);
1199        return rc;
1200
1201}
1202
1203
1204BERR_Code BHDCPlib_DisableAuthentication(BHDCPlib_Handle hHDCPlib)
1205{
1206        BERR_Code rc = BERR_SUCCESS;
1207
1208        BDBG_ENTER(BHDCPlib_DisableAuthentication);
1209        BDBG_ASSERT(hHDCPlib);
1210
1211        /* clear HDCP Authentication */
1212        BHDM_HDCP_ClearAuthentication(hHDCPlib->stDependencies.hHdm) ;
1213
1214        /* Transmit clear data */
1215        rc = BHDCPlib_TransmitClear(hHDCPlib);
1216       
1217        BDBG_LEAVE(BHDCPlib_DisableAuthentication);
1218        return rc;
1219}
1220
Note: See TracBrowser for help on using the repository browser.