1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 // Software and any modification/derivatives thereof.
18 // No right, ownership, or interest to MStar Software and any
19 // modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 // supplied together with third party`s software and the use of MStar
23 // Software may require additional licenses from third parties.
24 // Therefore, you hereby agree it is your sole responsibility to separately
25 // obtain any and all third party right and license necessary for your use of
26 // such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 // MStar`s confidential information and you agree to keep MStar`s
30 // confidential information in strictest confidence and not disclose to any
31 // third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 // kind. Any warranties are hereby expressly disclaimed by MStar, including
35 // without limitation, any warranties of merchantability, non-infringement of
36 // intellectual property rights, fitness for a particular purpose, error free
37 // and in conformity with any international standard. You agree to waive any
38 // claim against MStar for any loss, damage, cost or expense that you may
39 // incur related to your use of MStar Software.
40 // In no event shall MStar be liable for any direct, indirect, incidental or
41 // consequential damages, including without limitation, lost of profit or
42 // revenues, lost or damage of data, and unauthorized system use.
43 // You agree that this Section 4 shall still apply without being affected
44 // even if MStar Software has been modified by MStar in accordance with your
45 // request or instruction for your use, except otherwise agreed by both
46 // parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 // services in relation with MStar Software to you for your use of
50 // MStar Software in conjunction with your or your customer`s product
51 // ("Services").
52 // You understand and agree that, except otherwise agreed by both parties in
53 // writing, Services are provided on an "AS IS" basis and the warranty
54 // disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 // or otherwise:
58 // (a) conferring any license or right to use MStar name, trademark, service
59 // mark, symbol or any other identification;
60 // (b) obligating MStar or any of its affiliates to furnish any person,
61 // including without limitation, you and your customers, any assistance
62 // of any kind whatsoever, or any information; or
63 // (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 // of Taiwan, R.O.C., excluding its conflict of law rules.
67 // Any and all dispute arising out hereof or related hereto shall be finally
68 // settled by arbitration referred to the Chinese Arbitration Association,
69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 // Rules of the Association by three (3) arbitrators appointed in accordance
71 // with the said Rules.
72 // The place of arbitration shall be in Taipei, Taiwan and the language shall
73 // be English.
74 // The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2006-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94
95 ////////////////////////////////////////////////////////////////////////////////////////////////////
96 ///
97 /// file drvDSCMB.c
98 /// @brief Descrambler (DSCMB) Driver Interface
99 /// @author MStar Semiconductor,Inc.
100 ////////////////////////////////////////////////////////////////////////////////////////////////////
101
102 #include "MsCommon.h"
103 #include "MsVersion.h"
104 #ifdef MSOS_TYPE_LINUX_KERNEL
105 #include <linux/string.h>
106 #include <linux/limits.h>
107 #else
108 #include <limits.h>
109 #include <string.h>
110 #endif
111
112 #include "drvSYS.h"
113 #include "drvMMIO.h"
114
115 #include "drvDSCMB.h"
116 #include "regDSCMB.h"
117 #include "halDSCMB.h"
118 #include "asmCPU.h"
119 #include "utopia.h"
120
121 #ifdef DSCMB_UTOPIA_20
122 #define DSCMB_UTOPIA20
123 #else
124 #undef DSCMB_UTOPIA20
125 #endif
126
127 #ifdef DSCMB_UTOPIA20
128 #include "drvDSCMB_v2.h"
129 #endif
130
131 #include "drvDSCMB_private.h"
132
133 // Threshold for KL calculation //
134 #define DSCMB_KL_WAIT_THRESHOLD 300
135
136 #define FLEXIBLE_PIDSLOTMAP
137 //=========================================================================================
138 // Data Structure Declaration
139 //=========================================================================================
140 #define DSCMB_LOCK(_a_) MsOS_ObtainMutex ( (_a_) , MSOS_WAIT_FOREVER ); HAL_DSCMB_KTE_HW_SEM_Lock(DSCMB_KL_WAIT_THRESHOLD);
141 #define DSCMB_UNLOCK(_a_) HAL_DSCMB_KTE_HW_SEM_Unlock(); MsOS_ReleaseMutex( (_a_) )
142
143 static MS_U32 _u32DSCMB2DbgLv = DSCMB2_DBGLV_WARNING;
144 static MS_BOOL _bDSCMB2Drv_Inited = FALSE;
145 static MS_BOOL _bKLDrv_Inited = FALSE;
146
147 #ifdef DSCMB_NO_PRINTF
148 #define DRVDSCMB2_DBG(lv, x, args...)
149 #else
150 #define DRVDSCMB2_DBG(lv, x, args...) \
151 if (lv <= _u32DSCMB2DbgLv ) \
152 { \
153 if(lv == DSCMB2_DBGLV_ERR){ printf("[ERROR]"); } \
154 else if(lv == DSCMB2_DBGLV_WARNING){ printf("[WARNING]"); }\
155 else{ printf("[DEBUG]"); }\
156 if(_u32DSCMB2DbgLv >= DSCMB2_DBGLV_DEBUG){ printf("[%05d][%-35s]", __LINE__, __FUNCTION__); }\
157 printf(" ");\
158 printf(x, ##args); \
159 }
160 #endif
161
162 #define DSCMB_ASSERT(x, p, ret) if (!(x)){DRVDSCMB2_DBG(DSCMB2_DBGLV_ALERT, "ALERT FAIL: %s\n", p); return ret;}
163 #define DSCMB_INIT_CHECK(ret) DSCMB_ASSERT(_bDSCMB2Drv_Inited == TRUE, "The drvDSCMB2 is not initialized\n", ret)
164 #define KL_INIT_CHECK(ret) DSCMB_ASSERT(_bKLDrv_Inited == TRUE, "The Key Ladder is not initialized\n", ret)
165 #define OBSOLETE_FUNCTION(x, args...) DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING, "[%05d][%-35s]"x, __LINE__, __FUNCTION__, ##args)
166
167 static MSIF_Version _drv_dscmb_version =
168 {
169 .DDI = { DSCMB_DRV_VERSION, },
170 };
171
172
173
174
175 #ifdef DSCMB_UTOPIA20
176 extern stTspFltInfo* _u32PidFlt2Dscmb;
177 extern MS_BOOL* _bFreeSlot;
178 extern stDscmbTspMap (*DscmbTspMap)[HAL_DSCMB_KTE_MAX];
179 extern MS_BOOL* _bFreeRIVSlot;
180 #else
181 static stTspFltInfo _u32PidFlt2Dscmb[HAL_DSCMB_PIDFLT_NUM];
182 static stDscmbTspMap DscmbTspMap[HAL_DSCMB_ENG_NUM][HAL_DSCMB_KTE_MAX];
183 static MS_BOOL _bFreeSlot[HAL_DSCMB_KTE_MAX];
184 static MS_BOOL _bFreeRIVSlot[HAL_DSCMB_RIV_MAX];
185 #endif
186
187 // TODO: Fix me, need to put to resource private?
188 static MS_S32 _s32DscMutexId = -1 ;
189 static MS_S32 _s32KLMutexId = -1 ;
190
191 // TODO: Does it nessarary?
192 MS_U8 _u8KLPreLevel = 0;
193
194 static MS_BOOL _bUsedCAFlt[DSCMB_CAPVR_PIDTABLE_NUM][HAL_DSCMB_SPSPVR_FLT_NUM];
195
196
197 #ifdef DSCMB_UTOPIA20
198 static void *pu32DscmbInst = NULL;
199 #endif
200
201 #define SLOTUSED 1
202 #define SLOTEMPTY 0
203
204 //--------------------------------------------------------------------------------------------------
_DSCMB_SlotEmptyCount(void)205 MS_U32 _DSCMB_SlotEmptyCount(void)
206 {
207 MS_U32 i = 0 ;
208 MS_U32 count = 0 ;
209
210 for ( i = 0 ; i < HAL_DSCMB_KTE_MAX ; i++)
211 {
212 if (_bFreeSlot[i] == SLOTEMPTY )
213 {
214 count++;
215 }
216 }
217 return count;
218 }
219
_DSCMB_SlotAlloc(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Key_Type KeyType,MS_U32 * pu32SlotId)220 MS_BOOL _DSCMB_SlotAlloc(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Key_Type KeyType, MS_U32* pu32SlotId)
221 {
222 MS_U32 i = 0 ;
223 *pu32SlotId = 0 ;
224
225 for ( i = 0 ; i < HAL_DSCMB_KTE_MAX ; i++)
226 {
227 if (_bFreeSlot[i] == SLOTEMPTY )
228 {
229 _bFreeSlot[i] = SLOTUSED ;
230 *pu32SlotId = i ;
231 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "DSCMB Filter 0x%x Key 0x%x has index 0x%x\n", (MS_U16)u32DscmbId,
232 (MS_U16)KeyType, (MS_U16)i);
233 return TRUE;
234 }
235 }
236 return FALSE ;
237 }
238
239
_DSCMB_SlotFree(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Key_Type KeyType,MS_U32 u32SlotId)240 MS_BOOL _DSCMB_SlotFree(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Key_Type KeyType, MS_U32 u32SlotId)
241 {
242 if(u32SlotId < HAL_DSCMB_KTE_MAX)
243 {
244 _bFreeSlot[u32SlotId] = SLOTEMPTY ;
245 return TRUE ;
246 }
247
248 DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING, "Free an empty keyslot out of range\n");
249
250 return FALSE;
251 }
252
_DSCMB_SlotRIVAlloc(MS_U32 u32EngId,MS_U32 u32DscmbId,MS_U32 * pu32SlotId)253 MS_BOOL _DSCMB_SlotRIVAlloc(MS_U32 u32EngId, MS_U32 u32DscmbId, MS_U32* pu32SlotId)
254 {
255 MS_U32 i = 0 ;
256 *pu32SlotId = 0 ;
257
258 for ( i = 0 ; i < HAL_DSCMB_RIV_MAX ; i++)
259 {
260 if (_bFreeRIVSlot[i] == SLOTEMPTY )
261 {
262 _bFreeRIVSlot[i] = SLOTUSED ;
263 *pu32SlotId = i ;
264 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "DSCMB 0x%x has RIV index 0x%x\n", (MS_U16)u32DscmbId,(MS_U16)i);
265 return TRUE;
266 }
267 }
268 return FALSE ;
269 }
270
271
_DSCMB_SlotRIVFree(MS_U32 u32EngId,MS_U32 u32DscmbId,MS_U32 u32SlotId)272 MS_BOOL _DSCMB_SlotRIVFree(MS_U32 u32EngId, MS_U32 u32DscmbId, MS_U32 u32SlotId)
273 {
274 if(u32SlotId < HAL_DSCMB_RIV_MAX)
275 {
276 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Free u32SlotId 0x%x\n", u32SlotId);
277 _bFreeRIVSlot[u32SlotId] = SLOTEMPTY ;
278 return TRUE ;
279 }
280
281 DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING, "Free an empty keyslot out of range\n");
282
283 return FALSE;
284 }
285
286 // Find a filter which connect to target dscmb ID
_DSCMB_Dscmb2Flt(MS_U32 u32DscmbId,MS_U32 * pFltId)287 MS_BOOL _DSCMB_Dscmb2Flt(MS_U32 u32DscmbId , MS_U32* pFltId)
288 {
289 #ifdef FLEXIBLE_PIDSLOTMAP
290 *pFltId = u32DscmbId;
291 return TRUE;
292 #else
293 *pFltId = 0 ;
294 MS_U32 i ;
295
296 for ( i = 0 ; i < HAL_DSCMB_PIDFLT_NUM ; i ++)
297 {
298 if ( _u32PidFlt2Dscmb[i].u8DscmbId== u32DscmbId )
299 {
300 break ;
301 }
302 }
303
304 if ( i == HAL_DSCMB_PIDFLT_NUM )
305 {
306 return FALSE ;
307 }
308
309 *pFltId = i ;
310
311 return TRUE ;
312 #endif /* FLEXIBLE_PIDSLOTMAP */
313 }
314
_DumpMapInfo(MS_U32 idx)315 void _DumpMapInfo(MS_U32 idx)
316 {
317 stDscmbTspMap* pMap = NULL;
318
319 pMap = &DscmbTspMap[0][idx];
320 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Index: %u\n", idx);
321 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Used: %d\n", pMap->bUsed);
322 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Even Idx: %u\n", pMap->u32SlotIdEven);
323 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Odd Idx: %u\n", pMap->u32SlotIdOdd);
324 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Clear Idx: %u\n", pMap->u32SlotIdClear);
325 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "RIV Idx: %u\n", pMap->u32RIVIdx);
326 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "PidFlt #: %u\n", pMap->u32PidFltIdNum);
327 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Dscmb: %d\n", pMap->bDscmb);
328 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, " %s\n", pMap->eFltType == E_DSCMB_FLT_2_KEYS ?"2 Keys":"3 Keys");
329 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "CAVid: %u\n", pMap->u32CAVid);
330 }
331
332 //Enable all PIDSlotMap in the Dscmb filter
_DSCMB_EnableDSCMB(MS_U32 u32DscmbId)333 MS_BOOL _DSCMB_EnableDSCMB(MS_U32 u32DscmbId)
334 {
335 MS_U32 i;
336
337 for ( i = 0 ; i < HAL_DSCMB_PIDFLT_NUM ; i ++)
338 {
339 if ( _u32PidFlt2Dscmb[i].u8DscmbId== u32DscmbId )
340 {
341 if(FALSE == HAL_DSCMB_PidIdx_EnableSlot(i))
342 {
343 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "FAIL\n");
344 return FALSE;
345 }
346 else
347 {
348 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Enable PIDSlotMap %d !!!!!!!!!!!\n", i);
349 }
350 }
351 }
352
353 return TRUE;
354 }
355
356 //Disable all PIDSlotMap in the Dscmb filter
_DSCMB_DisableDSCMB(MS_U32 u32DscmbId)357 MS_BOOL _DSCMB_DisableDSCMB(MS_U32 u32DscmbId)
358 {
359 MS_U32 i;
360
361 for ( i = 0 ; i < HAL_DSCMB_PIDFLT_NUM ; i ++)
362 {
363 if ( _u32PidFlt2Dscmb[i].u8DscmbId== u32DscmbId )
364 {
365 if(FALSE == HAL_DSCMB_PidIdx_DisableSlot(i))
366 {
367 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "FAIL\n");
368 return FALSE;
369 }
370 else
371 {
372 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Disable PIDSlotMap %d !!!!!!!!!!!\n", i);
373 }
374
375 }
376 }
377
378 return TRUE;
379 }
380
_DSCMB_IsFltConnectDSCMB(MS_U32 u32DscmbId,MS_U32 u32FltId)381 MS_BOOL _DSCMB_IsFltConnectDSCMB(MS_U32 u32DscmbId, MS_U32 u32FltId)
382 {
383 if(u32DscmbId >= HAL_DSCMB_KTE_MAX || u32FltId >= HAL_DSCMB_PIDFLT_NUM)
384 {
385 return FALSE;
386 }
387
388 if(_u32PidFlt2Dscmb[u32FltId].u8DscmbId == u32DscmbId)
389 {
390 return TRUE;
391 }
392 else
393 {
394 return FALSE;
395 }
396 }
397
_MDrv_DSCMB2_SetPowerState(EN_POWER_MODE u16PowerState)398 MS_U32 _MDrv_DSCMB2_SetPowerState(EN_POWER_MODE u16PowerState)
399 {
400 MS_U16 _ret = FALSE;
401
402 switch (u16PowerState)
403 {
404 case E_POWER_SUSPEND:
405 _ret = _MDrv_DSCMB2_Exit();
406 break;
407
408 case E_POWER_RESUME:
409 _ret = _MDrv_DSCMB2_Init();
410 break;
411
412 case E_POWER_MECHANICAL:
413 case E_POWER_SOFT_OFF:
414 default:
415 DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING, "[%s] %d Power state not support!!\n", __FUNCTION__, __LINE__);
416 break;
417 }
418
419 return _ret;
420 }
421
_MDrv_DSCMB2_KLadder_Init(void)422 MS_BOOL _MDrv_DSCMB2_KLadder_Init(void)
423 {
424 MS_VIRT u32Bank;
425 MS_PHY u32BankSize;
426
427 if(_bKLDrv_Inited == TRUE)
428 {
429 DRVDSCMB2_DBG(DSCMB2_DBGLV_NOTICE, "Key Ladder driver already init\n");
430 return TRUE;
431 }
432
433 if (FALSE == MDrv_MMIO_GetBASE(&u32Bank, &u32BankSize, MS_MODULE_HW))
434 {
435 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Get MMIO base fail\n");
436 return FALSE;
437 }
438
439 HAL_DSCMB_SetBank(u32Bank);
440
441 _s32KLMutexId = MsOS_CreateMutex(E_MSOS_FIFO,"KeyLadder_Mutex", MSOS_PROCESS_SHARED);
442 _bKLDrv_Inited = TRUE;
443 return TRUE;
444 }
445
446 //--------------------------------------------------------------------------------------------------
447 /// Initialize dscrambler driver and descrambler engine by init flag
448 /// @param bSWInit\b IN: If TRUE, do SW init only. If FALSE do HW&SW init.
449 /// @return TRUE - Success
450 /// @return FALSE - Failure
451 /// @note
452 /// It should be called before calling any other dscrambler DDI functions.
453 //--------------------------------------------------------------------------------------------------
_MDrv_DSCMB2_InitBySWFlag(MS_BOOL bSWInit)454 MS_BOOL _MDrv_DSCMB2_InitBySWFlag(MS_BOOL bSWInit)
455 {
456 MS_VIRT u32Bank;
457 MS_PHY u32BankSize;
458 MS_U32 i , j;
459 MS_U32 u32CAVid = DEFAULT_CAVID;
460 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG,"u32CAVid = %d ++++\n", u32CAVid);
461 DRVDSCMB2_DBG(DSCMB2_DBGLV_INFO,"ChipRev=%d\n", MDrv_SYS_GetChipRev());
462 if(_bDSCMB2Drv_Inited == TRUE)
463 {
464 DRVDSCMB2_DBG(DSCMB2_DBGLV_NOTICE, "DSCMB driver already init\n");
465 return TRUE;
466 }
467
468 if(u32CAVid == 0)
469 {
470 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Invalid CAVid\n");
471 return FALSE;
472 }
473
474 if (FALSE == MDrv_MMIO_GetBASE(&u32Bank, &u32BankSize, MS_MODULE_HW))
475 {
476 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Get MMIO base fail\n");
477 return FALSE;
478 }
479
480 DRVDSCMB2_DBG(DSCMB2_DBGLV_INFO, "Bank = 0x%X\n", (unsigned int)u32Bank);
481 HAL_DSCMB_SetBank(u32Bank);
482
483 DRVDSCMB2_DBG(DSCMB2_DBGLV_INFO, "CAVid = 0x%X\n", (unsigned int)u32CAVid);
484 HAL_DSCMB_SetCAVid(u32CAVid);
485
486 _s32DscMutexId = MsOS_CreateMutex(E_MSOS_FIFO,"DSCMB_Mutex", MSOS_PROCESS_SHARED);
487 if( FALSE == _MDrv_DSCMB2_KLadder_Init() )
488 {
489 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Init Keyladder Fail\n");
490 return FALSE;
491 }
492 if(TRUE == bSWInit)
493 {
494 goto _MDrv_DSCMB2_InitBySWFlag_RET;
495 }
496
497 HAL_DSCMB_Init();
498 memset(_bFreeSlot, 0x0, sizeof(MS_BOOL)*HAL_DSCMB_KTE_MAX);
499 memset(DscmbTspMap , 0x0, sizeof(stDscmbTspMap)*HAL_DSCMB_ENG_NUM*HAL_DSCMB_KTE_MAX);
500 memset(_bFreeRIVSlot, 0x0, sizeof(MS_BOOL)*HAL_DSCMB_RIV_MAX);
501 memset(_bUsedCAFlt, 0x0, sizeof(_bUsedCAFlt));
502 memset(_u32PidFlt2Dscmb, 0x0, sizeof(stTspFltInfo)*HAL_DSCMB_PIDFLT_NUM);
503
504 for( j = 0 ; j < HAL_DSCMB_ENG_NUM ; j ++)
505 {
506 DscmbTspMap[j][0].bUsed = TRUE;//0 will not be used forever
507
508 for ( i = 0 ; i < HAL_DSCMB_KTE_MAX ; i ++)
509 {
510 DscmbTspMap[j][i].u32SlotIdOdd = DRV_DSCMB_FLT_NULL;
511 DscmbTspMap[j][i].u32SlotIdEven = DRV_DSCMB_FLT_NULL;
512 DscmbTspMap[j][i].u32SlotIdClear = DRV_DSCMB_FLT_NULL;
513 DscmbTspMap[j][i].u32CAVid = u32CAVid;
514 DscmbTspMap[j][i].u32RIVIdx = HAL_DSCMB_RIV_MAX;
515 DscmbTspMap[j][i].u32Tsid = HAL_DSCMB_TSID_MAX;
516 }
517 }
518
519 for ( i = 0 ; i < HAL_DSCMB_PIDFLT_NUM ; i++)
520 {
521 _u32PidFlt2Dscmb[i].u8DscmbId= HAL_DSCMB_KTE_MAX ;
522 _u32PidFlt2Dscmb[i].u8CaVid = u32CAVid;
523 _u32PidFlt2Dscmb[i].u8TsId = HAL_DSCMB_TSID_MAX;
524 }
525
526 //Only if DSCMB is enable by OTP, we connect the path to DSCMB
527 if( HAL_DSCMB_OTPEnDSCMB() == TRUE)
528 {
529 //go through DSCMB
530 for (i = 0 ; i < REG_DSCMB_PATH_CNT ; i++)
531 {
532 // set recbuf source to DSCMB
533 HAL_DSCMB_ConnectPath(i,TRUE);
534 }
535 #ifndef DSCMB_NO_PRINTF
536 printf("\033[31mGo through DSCMB\n\033[m");
537 #endif
538 }
539 else
540 {
541 #ifndef DSCMB_NO_PRINTF
542 printf("\033[33m ByPass DSCMB\n\033[m");
543 #endif
544 }
545
546 _MDrv_DSCMB2_InitBySWFlag_RET:
547
548 _bDSCMB2Drv_Inited = TRUE;
549
550 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG,"[%s][%d] ++++\n", __FUNCTION__, __LINE__);
551
552 return TRUE;
553 }
554
555
556 //--------------------------------------------------------------------------------------------------
557 /// Initialize dscrambler driver and descrambler engine
558 /// @return TRUE - Success
559 /// @return FALSE - Failure
560 /// @note
561 /// It should be called before calling any other dscrambler DDI functions.
562 //--------------------------------------------------------------------------------------------------
_MDrv_DSCMB2_Init(void)563 MS_BOOL _MDrv_DSCMB2_Init(void)
564 {
565 return _MDrv_DSCMB2_InitBySWFlag(FALSE);
566 }
567
568
569 //--------------------------------------------------------------------------------------------------
570 /// Exit dscrambler driver and descrambler engine
571 /// @return TRUE - Success
572 /// @return FALSE - Failure
573 /// @note
574 /// It should be called after finish any other dscrambler DDI functions.
575 //--------------------------------------------------------------------------------------------------
_MDrv_DSCMB2_Exit(void)576 MS_BOOL _MDrv_DSCMB2_Exit(void)
577 {
578 if (_s32DscMutexId != -1)
579 {
580 MsOS_DeleteMutex(_s32DscMutexId);
581 _s32DscMutexId = -1;
582 }
583
584 if (_s32KLMutexId != -1)
585 {
586 MsOS_DeleteMutex(_s32KLMutexId);
587 _s32KLMutexId = -1;
588 }
589
590 _bDSCMB2Drv_Inited = FALSE;
591 _bKLDrv_Inited = FALSE;
592 return TRUE;
593 }
594
595 //--------------------------------------------------------------------------------------------------
596 /// Allocate a dscrambler filter
597 /// @param eFltType \b IN: type for descramber filter
598 /// @return Descrambler filter ID - Success
599 /// @return DRV_DSCMB_FLT_NULL - Failure
600 //--------------------------------------------------------------------------------------------------
_MDrv_DSCMB2_FltAllocWithCAVid(MS_U32 u32EngId,DSCMB_Flt_Type eFltType,MS_U32 u32CAVid)601 MS_U32 _MDrv_DSCMB2_FltAllocWithCAVid(MS_U32 u32EngId, DSCMB_Flt_Type eFltType, MS_U32 u32CAVid)
602 {
603 DSCMB_INIT_CHECK(DRV_DSCMB_FLT_NULL);
604 MS_BOOL bSecureSlot = (( E_DSCMB_FLT_SECURE_KEYS_ENABLE & eFltType) != 0) ? TRUE : FALSE;
605 eFltType = eFltType & (~(E_DSCMB_FLT_SECURE_KEYS_ENABLE));
606 //#define E_DSCMB_FLT_PRIV_KEYS_ENABLE (1 << 6)
607 // MS_BOOL bPrivilegeSlot = (( E_DSCMB_FLT_PRIV_KEYS_ENABLE & eFltType) != 0) ? TRUE : FALSE;
608 // eFltType = eFltType & (~(E_DSCMB_FLT_SECURE_KEYS_ENABLE | E_DSCMB_FLT_PRIV_KEYS_ENABLE));
609 DSCMB_ASSERT(u32EngId == 0, "EngId input error", DRV_DSCMB_FLT_NULL);
610 DSCMB_ASSERT((eFltType == E_DSCMB_FLT_3_KEYS) || (eFltType == E_DSCMB_FLT_2_KEYS) || (eFltType == E_DSCMB_FLT_1_KEYS), "FltType input error", DRV_DSCMB_FLT_NULL);
611 DSCMB_ASSERT((u32CAVid != 0) && (u32CAVid <= DEFAULT_CAVID), "CAVid input error", DRV_DSCMB_FLT_NULL);
612 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Allocate with %d CAVid=%u\n", eFltType, u32CAVid);
613
614 MS_U32 i = 0;
615 stDscmbTspMap* pMap = NULL;
616
617 DSCMB_LOCK(_s32DscMutexId);
618
619 // Find free dscmb slots for a DSCMB flt //
620 for ( i = 0 ; i < HAL_DSCMB_KTE_MAX ; i ++)
621 {
622 pMap = &DscmbTspMap[u32EngId][i];
623 if ( pMap->bUsed == FALSE )
624 {
625 pMap->bUsed = TRUE ;
626 // For 1 Key for a Dscmb filter //
627 if(eFltType == E_DSCMB_FLT_1_KEYS)
628 {
629 MS_U32 u32IgoreModeKeyIdx = 0;
630 if (FALSE == _DSCMB_SlotAlloc( u32EngId , i , E_DSCMB_KEY_CLEAR , &u32IgoreModeKeyIdx))
631 {
632 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Find SlotMap FAIL\n");
633 goto MDrv_DSCMB2_FltAlloc_Ex_FAIL;
634 }
635
636 pMap->u32SlotIdClear = u32IgoreModeKeyIdx;
637 pMap->u32SlotIdEven = u32IgoreModeKeyIdx;
638 pMap->u32SlotIdOdd = u32IgoreModeKeyIdx;
639
640 break;
641 }
642 // For 3 Keys for a Dscmb filter //
643 if ( E_DSCMB_FLT_3_KEYS == eFltType)
644 {
645 // Clear key is init in BypassMode
646 if (FALSE == _DSCMB_SlotAlloc( u32EngId , i , E_DSCMB_KEY_CLEAR , &(pMap->u32SlotIdClear)))
647 {
648 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Find SlotMap FAIL\n");
649 goto MDrv_DSCMB2_FltAlloc_Ex_FAIL;
650 }
651 }
652
653 // 2 Keys for a Dscmb filter //
654 if (FALSE == _DSCMB_SlotAlloc( u32EngId , i , E_DSCMB_KEY_EVEN , &(pMap->u32SlotIdEven)))
655 {
656 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Find SlotMap FAIL\n");
657 goto MDrv_DSCMB2_FltAlloc_Ex_FAIL;
658 }
659 if (FALSE == _DSCMB_SlotAlloc( u32EngId , i , E_DSCMB_KEY_ODD , &(pMap->u32SlotIdOdd)))
660 {
661 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Find SlotMap FAIL\n");
662 goto MDrv_DSCMB2_FltAlloc_Ex_FAIL;
663 }
664
665 break; // successfully find a Free DSCMB filter
666 }
667 }
668
669 // Check No free slot
670 if( i == HAL_DSCMB_KTE_MAX )
671 {
672 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Find SlotMap FAIL\n");
673 goto MDrv_DSCMB2_FltAlloc_Ex_FAIL;
674 }
675
676 // Set default value to Map object
677 pMap->u32PidFltIdNum = 0;
678 pMap->bDscmb = TRUE; //Descramble or Scramble
679 pMap->eFltType = eFltType;
680 pMap->u32CAVid = u32CAVid;
681 pMap->u32RIVIdx = HAL_DSCMB_RIV_MAX;
682 pMap->u32Tsid = HAL_DSCMB_TSID_MAX;
683 pMap->bSecure = bSecureSlot;
684
685 _DumpMapInfo(i);
686
687 #ifdef FLEXIBLE_PIDSLOTMAP
688 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(i, E_DSCMB_KEY_EVEN);
689 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(i, E_DSCMB_KEY_ODD);
690 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(i, E_DSCMB_KEY_CLEAR);
691
692 HAL_DSCMB_PidIdx_SetCAVid(i, u32CAVid);
693 HAL_DSCMB_PidIdx_SetSecure(i, pMap->bSecure);
694 //HAL_DSCMB_PidIdx_SetPrivilege(i, bPrivilegeSlot);
695 if ( FALSE == HAL_DSCMB_PidIdx_SetSlotKeyIdx( i , E_DSCMB_KEY_EVEN , pMap->u32SlotIdEven) )
696 {
697 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set SlotMap Fail\n");
698 goto MDrv_DSCMB2_FltAlloc_Ex_FAIL;
699 }
700
701 if ( FALSE == HAL_DSCMB_PidIdx_SetSlotKeyIdx( i , E_DSCMB_KEY_ODD , pMap->u32SlotIdOdd) )
702 {
703 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set SlotMap Fail\n");
704 goto MDrv_DSCMB2_FltAlloc_Ex_FAIL;
705 }
706
707 if(pMap->eFltType == E_DSCMB_FLT_3_KEYS || (pMap->eFltType == E_DSCMB_FLT_1_KEYS))
708 {
709 if ( FALSE == HAL_DSCMB_PidIdx_SetSlotKeyIdx( i , E_DSCMB_KEY_CLEAR , pMap->u32SlotIdClear) )
710 {
711 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set SlotMap Fail\n");
712 goto MDrv_DSCMB2_FltAlloc_Ex_FAIL;
713 }
714 }
715 #endif /* FLEXIBLE_PIDSLOTMAP */
716
717 DSCMB_UNLOCK(_s32DscMutexId);
718
719 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Allocate DSCMB Filter ID: %u\n", i);
720
721 return i;
722
723 MDrv_DSCMB2_FltAlloc_Ex_FAIL:
724
725 #ifdef FLEXIBLE_PIDSLOTMAP
726 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(i, E_DSCMB_KEY_EVEN);
727 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(i, E_DSCMB_KEY_ODD);
728 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(i, E_DSCMB_KEY_CLEAR);
729
730 HAL_DSCMB_PidIdx_SetSecure(i, FALSE);
731 #endif /* FLEXIBLE_PIDSLOTMAP */
732
733 if(i != HAL_DSCMB_KTE_MAX)
734 {
735 // Free key Slots //
736 if (pMap->u32SlotIdClear != DRV_DSCMB_FLT_NULL)
737 {
738 _DSCMB_SlotFree(u32EngId, i , E_DSCMB_KEY_CLEAR ,pMap->u32SlotIdClear);
739 pMap->u32SlotIdClear = DRV_DSCMB_FLT_NULL ;
740 }
741 if (pMap->u32SlotIdOdd != DRV_DSCMB_FLT_NULL)
742 {
743 _DSCMB_SlotFree(u32EngId, i , E_DSCMB_KEY_ODD ,pMap->u32SlotIdOdd);
744 pMap->u32SlotIdOdd = DRV_DSCMB_FLT_NULL ;
745 }
746 if (pMap->u32SlotIdEven != DRV_DSCMB_FLT_NULL)
747 {
748 _DSCMB_SlotFree(u32EngId, i , E_DSCMB_KEY_EVEN ,pMap->u32SlotIdEven);
749 pMap->u32SlotIdEven = DRV_DSCMB_FLT_NULL ;
750 }
751
752 pMap->bUsed = FALSE;
753 pMap->bSecure = FALSE;
754 }
755 DSCMB_UNLOCK(_s32DscMutexId);
756 return DRV_DSCMB_FLT_NULL;
757 }
758
759 //--------------------------------------------------------------------------------------------------
760 /// Allocate a dscrambler filter
761 /// @return Descrambler filter ID - Success
762 /// @return DRV_DSCMB_FLT_NULL - Failure
763 //--------------------------------------------------------------------------------------------------
_MDrv_DSCMB2_FltAlloc_Ex(MS_U32 u32EngId,DSCMB_Flt_Type eFltType)764 MS_U32 _MDrv_DSCMB2_FltAlloc_Ex(MS_U32 u32EngId, DSCMB_Flt_Type eFltType)
765 {
766 return _MDrv_DSCMB2_FltAllocWithCAVid(u32EngId, eFltType, HAL_DSCMB_GetCAVid());
767 }
768
_MDrv_DSCMB2_FltAlloc(MS_U32 u32EngId)769 MS_U32 _MDrv_DSCMB2_FltAlloc(MS_U32 u32EngId)
770 {
771 return _MDrv_DSCMB2_FltAlloc_Ex(u32EngId, E_DSCMB_FLT_2_KEYS);
772 }
773
774 //--------------------------------------------------------------------------------------------------
775 /// Free the specific DSCMB filter by ID
776 /// @return TRUE - SUCCESS
777 /// @return FALSE - Failure
778 /// @note
779 ///
780 //--------------------------------------------------------------------------------------------------
_MDrv_DSCMB2_FltFree(MS_U32 u32EngId,MS_U32 u32DscmbId)781 MS_BOOL _MDrv_DSCMB2_FltFree(MS_U32 u32EngId, MS_U32 u32DscmbId)
782 {
783 DSCMB_INIT_CHECK(FALSE);
784
785 DSCMB_ASSERT(u32EngId == 0, "EngId input error", FALSE);
786 DSCMB_ASSERT(u32DscmbId < HAL_DSCMB_KTE_MAX, "DscmbId input error", FALSE);
787 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Free with u32DscmbId=%u\n", u32DscmbId);
788
789 MS_U32 i = 0;
790 stDscmbTspMap* pMap = NULL;
791 stDscmbTspMap* pMapTmp = NULL;
792 MS_BOOL bDisablePES = TRUE;
793
794 DSCMB_LOCK(_s32DscMutexId);
795
796 pMap = &DscmbTspMap[u32EngId][u32DscmbId];
797
798 if(pMap->bUsed == FALSE)
799 {
800 DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING, "Free an unused DSCMB filter\n");
801 }
802
803 //Check if two or more u32DSCMB use PES decrypt in the same tsid
804 // If there exist a dscmb id that use PES decrypt, do not disable PES
805 for ( i = 0 ; i < HAL_DSCMB_KTE_MAX ; i ++)
806 {
807 if(i == u32DscmbId)
808 {
809 continue;
810 }
811 pMapTmp = &DscmbTspMap[u32EngId][i];
812 if ( (pMapTmp->bUsed == TRUE) && (pMapTmp->u32Tsid == pMap->u32Tsid))
813 {
814 if(pMapTmp->u32RIVIdx != HAL_DSCMB_RIV_MAX)
815 {
816 bDisablePES = FALSE;
817 }
818 }
819 }
820
821 if(pMap->u32RIVIdx != HAL_DSCMB_RIV_MAX)
822 {
823 if(bDisablePES == TRUE)
824 {
825 HAL_DSCMB_PES_Enable (0, pMap->u32Tsid, FALSE);
826 }
827 }
828
829 #ifdef FLEXIBLE_PIDSLOTMAP
830 // Reset the Key index
831 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(u32DscmbId, E_DSCMB_KEY_CLEAR);
832 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(u32DscmbId, E_DSCMB_KEY_EVEN);
833 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(u32DscmbId, E_DSCMB_KEY_ODD);
834 HAL_DSCMB_PidIdx_SetSecure(u32DscmbId, FALSE);
835 HAL_DSCMB_KTE_Clear_KeyFSCB(u32DscmbId);
836 #endif /* FLEXIBLE_PIDSLOTMAP */
837
838 // Disable Pid Slot
839 for ( i = 0 ; i < HAL_DSCMB_PIDFLT_NUM ; i ++)
840 {
841 if (_u32PidFlt2Dscmb[i].u8DscmbId== u32DscmbId)
842 {
843 #ifndef FLEXIBLE_PIDSLOTMAP
844 // Reset the Key index
845 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(i, E_DSCMB_KEY_CLEAR);
846 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(i, E_DSCMB_KEY_EVEN);
847 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(i, E_DSCMB_KEY_ODD);
848 HAL_DSCMB_PidIdx_SetSecure(i, FALSE);
849 HAL_DSCMB_KTE_Clear_KeyFSCB(i);
850 #endif /* FLEXIBLE_PIDSLOTMAP */
851
852 HAL_DSCMB_PidIdx_DisableSlot(i);
853 pMap->u32PidFltIdNum--;
854 _u32PidFlt2Dscmb[i].u8DscmbId= HAL_DSCMB_KTE_MAX ;
855 _u32PidFlt2Dscmb[i].u8TsId = HAL_DSCMB_TSID_MAX;
856 _u32PidFlt2Dscmb[i].u8CaVid = DEFAULT_CAVID;
857
858 }
859 }
860
861 // Free key Slots //
862 if (pMap->u32SlotIdClear != DRV_DSCMB_FLT_NULL)
863 {
864 _DSCMB_SlotFree(u32EngId, u32DscmbId , E_DSCMB_KEY_CLEAR ,pMap->u32SlotIdClear);
865 pMap->u32SlotIdClear = DRV_DSCMB_FLT_NULL ;
866 }
867 if (pMap->u32SlotIdOdd != DRV_DSCMB_FLT_NULL)
868 {
869 _DSCMB_SlotFree(u32EngId, u32DscmbId , E_DSCMB_KEY_ODD ,pMap->u32SlotIdOdd);
870 pMap->u32SlotIdOdd = DRV_DSCMB_FLT_NULL ;
871 }
872 if (pMap->u32SlotIdEven != DRV_DSCMB_FLT_NULL)
873 {
874 _DSCMB_SlotFree(u32EngId, u32DscmbId , E_DSCMB_KEY_EVEN ,pMap->u32SlotIdEven);
875 pMap->u32SlotIdEven = DRV_DSCMB_FLT_NULL ;
876 }
877 if(pMap->u32RIVIdx != HAL_DSCMB_RIV_MAX)
878 {
879 _DSCMB_SlotRIVFree (u32EngId, u32DscmbId, pMap->u32RIVIdx);
880 pMap->u32RIVIdx = HAL_DSCMB_RIV_MAX;
881 }
882 pMap->u32CAVid = DEFAULT_CAVID ;
883 pMap->u32Tsid = HAL_DSCMB_TSID_MAX;
884 pMap->bUsed = FALSE ;
885 pMap->bSecure = FALSE;
886
887 DSCMB_UNLOCK(_s32DscMutexId);
888 return TRUE;
889 }
890
891
_MDrv_DSCMB2_FltConnectFltId(MS_U32 u32EngId,MS_U32 u32DscmbId,MS_U32 u32FltId)892 MS_BOOL _MDrv_DSCMB2_FltConnectFltId(MS_U32 u32EngId, MS_U32 u32DscmbId, MS_U32 u32FltId)
893 {
894 DSCMB_INIT_CHECK(FALSE);
895
896 DSCMB_ASSERT(u32EngId == 0, "EngId input error", FALSE);
897 DSCMB_ASSERT(u32DscmbId < HAL_DSCMB_KTE_MAX, "DscmbId input error", FALSE);
898 DSCMB_ASSERT((u32FltId < HAL_DSCMB_PIDIDX_MAX) && (u32FltId != 0), "FltId input error", FALSE);
899 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Connect u32FltId=%u to u32DscmbId=%u\n", u32FltId, u32DscmbId);
900
901 stDscmbTspMap* pMap = NULL;
902 MS_U32 u32Tsid = 0;
903 MS_U32 i = 0;
904 MS_U32 u32CAVid = DEFAULT_CAVID;
905
906 DSCMB_LOCK(_s32DscMutexId);
907
908 pMap = &DscmbTspMap[u32EngId][u32DscmbId];
909 u32CAVid = pMap->u32CAVid;
910
911 if(pMap->bUsed == FALSE)
912 {
913 DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING, "DSCMB filter does not allocated yet\n");
914 goto MDrv_DSCMB2_FltConnectFltId_FAIL;
915 }
916
917 for(i = 0 ; i < HAL_DSCMB_KTE_MAX; i++)
918 {
919 if(_DSCMB_IsFltConnectDSCMB(i, u32FltId))
920 {
921 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "DSCMB filter already connect to another dscmb_id\n");
922 goto MDrv_DSCMB2_FltConnectFltId_FAIL;
923 }
924 }
925
926 HAL_DSCMB_Get_TsidInput (u32FltId, &u32Tsid);
927
928 if(pMap->u32PidFltIdNum == 0)
929 {
930 pMap->u32Tsid = u32Tsid;
931 }
932 else
933 {
934 if(u32Tsid != pMap->u32Tsid)
935 {
936 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "DSCMB filter=%d tsid=%d not match tsid=%d\n",
937 u32FltId, u32Tsid, pMap->u32Tsid);
938 goto MDrv_DSCMB2_FltConnectFltId_FAIL;
939
940 }
941 }
942
943 #ifdef FLEXIBLE_PIDSLOTMAP
944 HAL_DSCMB_SetTSPCADst_PidSlotMap(u32FltId, _u32PidFlt2Dscmb[u32FltId].u8CaDestUpp, _u32PidFlt2Dscmb[u32FltId].u8CaDestLow, u32DscmbId);
945 #else
946 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(u32FltId, E_DSCMB_KEY_EVEN);
947 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(u32FltId, E_DSCMB_KEY_ODD);
948 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(u32FltId, E_DSCMB_KEY_CLEAR);
949
950 HAL_DSCMB_PidIdx_SetCAVid(u32FltId, u32CAVid);
951
952 if ( FALSE == HAL_DSCMB_PidIdx_SetSlotKeyIdx( u32FltId , E_DSCMB_KEY_EVEN , pMap->u32SlotIdEven) )
953 {
954 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set SlotMap Fail\n");
955 goto MDrv_DSCMB2_FltConnectFltId_FAIL;
956 }
957
958 if ( FALSE == HAL_DSCMB_PidIdx_SetSlotKeyIdx( u32FltId , E_DSCMB_KEY_ODD , pMap->u32SlotIdOdd) )
959 {
960 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set SlotMap Fail\n");
961 goto MDrv_DSCMB2_FltConnectFltId_FAIL;
962 }
963
964 if(pMap->eFltType == E_DSCMB_FLT_3_KEYS || (pMap->eFltType == E_DSCMB_FLT_1_KEYS))
965 {
966 if ( FALSE == HAL_DSCMB_PidIdx_SetSlotKeyIdx( u32FltId , E_DSCMB_KEY_CLEAR , pMap->u32SlotIdClear) )
967 {
968 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set SlotMap Fail\n");
969 goto MDrv_DSCMB2_FltConnectFltId_FAIL;
970 }
971 }
972
973 HAL_DSCMB_PidIdx_SetSecure(u32FltId, pMap->bSecure);
974 #endif /* FLEXIBLE_PIDSLOTMAP */
975
976 HAL_DSCMB_PidIdx_EnableSlot(u32FltId);
977
978 pMap->u32PidFltIdNum++;
979 _u32PidFlt2Dscmb[u32FltId].u8DscmbId = u32DscmbId;
980 _u32PidFlt2Dscmb[u32FltId].u8TsId = u32Tsid;
981
982 #ifdef ENABLE_KEY_FSCB
983 #ifdef FLEXIBLE_PIDSLOTMAP
984 // do nothing
985 #else
986 // Copy KeyFSCBs from existed KeySlot
987 for( i = 0 ; i < HAL_DSCMB_PIDFLT_NUM ; i++ )
988 {
989 if( i != u32FltId && _u32PidFlt2Dscmb[i].u8DscmbId==u32DscmbId )
990 {
991 HAL_DSCMB_KTE_Copy_KeyFSCB( i, u32FltId);
992 break;
993 }
994 }
995 #endif
996 #endif
997
998 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Connect TSP flt %u to DSCMB flt %u\n", u32FltId, u32DscmbId);
999 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "DSCMB ID: %u has %u TSP filter connected\n", u32DscmbId, pMap->u32PidFltIdNum);
1000
1001 DSCMB_UNLOCK(_s32DscMutexId);
1002 return TRUE ;
1003
1004 MDrv_DSCMB2_FltConnectFltId_FAIL:
1005
1006 DSCMB_UNLOCK(_s32DscMutexId);
1007 return FALSE;
1008 }
1009
_MDrv_DSCMB2_FltDisconnectFltId(MS_U32 u32EngId,MS_U32 u32DscmbId,MS_U32 u32FltId)1010 MS_BOOL _MDrv_DSCMB2_FltDisconnectFltId(MS_U32 u32EngId, MS_U32 u32DscmbId, MS_U32 u32FltId)
1011 {
1012 DSCMB_INIT_CHECK(FALSE);
1013
1014 DSCMB_ASSERT(u32EngId == 0, "EngId input error", FALSE);
1015 DSCMB_ASSERT(u32DscmbId < HAL_DSCMB_KTE_MAX, "DscmbId input error", FALSE);
1016 DSCMB_ASSERT((u32FltId < HAL_DSCMB_PIDIDX_MAX) && (u32FltId != 0), "FltId input error", FALSE);
1017 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Disconnect u32FltId=%u from u32DscmbId=%u\n", u32FltId, u32DscmbId);
1018
1019 stDscmbTspMap* pMap = NULL;
1020
1021 // [FIXME] Discoonect Filter , Disable PidIdx reference.
1022 DSCMB_LOCK(_s32DscMutexId);
1023
1024 pMap = &DscmbTspMap[u32EngId][u32DscmbId];
1025
1026 // Check DSCMB filter data
1027 if((pMap->bUsed == FALSE) || (pMap->u32PidFltIdNum <= 0))
1028 {
1029 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "DSCMB filter content error\n");
1030 goto MDrv_DSCMB2_FltDisconnectFltId_FAIL;
1031 }
1032
1033 // Check if the TSP filter is mapped to the DSCMB filter
1034 if(_u32PidFlt2Dscmb[u32FltId].u8DscmbId != u32DscmbId)
1035 {
1036 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "DSCMB filter mapping error\n");
1037 goto MDrv_DSCMB2_FltDisconnectFltId_FAIL;
1038 }
1039
1040 #ifdef FLEXIBLE_PIDSLOTMAP
1041 HAL_DSCMB_SetTSPCADst_PidSlotMap(u32FltId, _u32PidFlt2Dscmb[u32FltId].u8CaDestUpp, _u32PidFlt2Dscmb[u32FltId].u8CaDestLow, 0);
1042 #else
1043 // Reset the Key index
1044 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(u32FltId, E_DSCMB_KEY_CLEAR);
1045 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(u32FltId, E_DSCMB_KEY_EVEN);
1046 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(u32FltId, E_DSCMB_KEY_ODD);
1047 HAL_DSCMB_PidIdx_SetSecure(u32FltId, FALSE);
1048 #endif /* FLEXIBLE_PIDSLOTMAP*/
1049
1050 // disable Keytable SlotMap
1051 HAL_DSCMB_PidIdx_DisableSlot(u32FltId);
1052
1053 // Update the internal data structure
1054 pMap->u32PidFltIdNum--;
1055 _u32PidFlt2Dscmb[u32FltId].u8DscmbId= HAL_DSCMB_KTE_MAX;
1056 _u32PidFlt2Dscmb[u32FltId].u8TsId = 0xff;
1057 _u32PidFlt2Dscmb[u32FltId].u8CaVid = 0xff;
1058
1059 #ifdef ENABLE_KEY_FSCB
1060 #ifdef FLEXIBLE_PIDSLOTMAP
1061 // do nothing
1062 #else
1063 // Clear all KeyFSCBs of given u32FltId
1064 HAL_DSCMB_KTE_Clear_KeyFSCB(u32FltId);
1065 #endif
1066 #endif
1067
1068 DSCMB_UNLOCK(_s32DscMutexId);
1069 return TRUE ;
1070
1071 MDrv_DSCMB2_FltDisconnectFltId_FAIL:
1072
1073 DSCMB_UNLOCK(_s32DscMutexId);
1074 return FALSE ;
1075 }
1076
1077
_MDrv_DSCMB2_FltSwitchType(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Flt_Type eFltType)1078 MS_BOOL _MDrv_DSCMB2_FltSwitchType(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Flt_Type eFltType)
1079 {
1080 DSCMB_INIT_CHECK(FALSE);
1081
1082 DSCMB_ASSERT(u32EngId == 0, "EngId input error", FALSE);
1083 DSCMB_ASSERT(u32DscmbId < HAL_DSCMB_KTE_MAX, "DscmbId input error", FALSE);
1084
1085 stDscmbTspMap* pMap = NULL;
1086 #ifndef FLEXIBLE_PIDSLOTMAP
1087 MS_U32 i = 0;
1088 #endif /* FLEXIBLE_PIDSLOTMAP */
1089 MS_U32 u32OldSlotIdOdd = DRV_DSCMB_FLT_NULL;
1090 MS_U32 u32OldSlotIdClear = DRV_DSCMB_FLT_NULL;
1091
1092 DSCMB_LOCK(_s32DscMutexId);
1093
1094 pMap = &DscmbTspMap[u32EngId][u32DscmbId];
1095
1096 if(pMap->bUsed == FALSE)
1097 {
1098 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "DSCMB filter does not allocated yet\n");
1099 goto MDrv_DSCMB2_FltSwitchType_FAIL;
1100 }
1101
1102 if((eFltType == E_DSCMB_FLT_2_KEYS_SHARE) || (pMap->eFltType == E_DSCMB_FLT_2_KEYS_SHARE))
1103 {
1104 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "DSCMB filter does not support the type switch\n");
1105 goto MDrv_DSCMB2_FltSwitchType_FAIL;
1106 }
1107
1108 if(eFltType == pMap->eFltType)
1109 {
1110 DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING, "DSCMB filter has the same type\n");
1111 goto MDrv_DSCMB2_FltSwitchType_OK;
1112 }
1113
1114 //make sure keyslot is enough, then SW operation never fail
1115 if(_DSCMB_SlotEmptyCount()<2)
1116 {
1117 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "KeySlot not enough\n");
1118 goto MDrv_DSCMB2_FltSwitchType_FAIL;
1119 }
1120
1121 ////////////////////////////////////////////////////////////////
1122 //// SW operation (6 cases)
1123 ///////////////////////////////////////////////////////////////
1124 u32OldSlotIdOdd = pMap->u32SlotIdOdd;
1125 u32OldSlotIdClear = pMap->u32SlotIdClear;
1126
1127 //case +1 slot odd key
1128 if((eFltType==E_DSCMB_FLT_2_KEYS) && (pMap->eFltType==E_DSCMB_FLT_1_KEYS))
1129 {
1130 _DSCMB_SlotAlloc( u32EngId , u32DscmbId , E_DSCMB_KEY_ODD , &(pMap->u32SlotIdOdd));
1131 pMap->u32SlotIdClear = DRV_DSCMB_FLT_NULL;
1132
1133 }
1134 //case +1 slot clear key
1135 else if((eFltType==E_DSCMB_FLT_3_KEYS) && (pMap->eFltType==E_DSCMB_FLT_2_KEYS))
1136 {
1137 _DSCMB_SlotAlloc( u32EngId , u32DscmbId , E_DSCMB_KEY_CLEAR , &(pMap->u32SlotIdClear));
1138 }
1139 //case +2 slot odd & clear key
1140 else if((eFltType==E_DSCMB_FLT_3_KEYS) && (pMap->eFltType==E_DSCMB_FLT_1_KEYS))
1141 {
1142 _DSCMB_SlotAlloc( u32EngId , u32DscmbId , E_DSCMB_KEY_ODD , &(pMap->u32SlotIdOdd));
1143 _DSCMB_SlotAlloc( u32EngId , u32DscmbId , E_DSCMB_KEY_CLEAR , &(pMap->u32SlotIdClear));
1144 }
1145 //case -1 slot clear key
1146 else if((eFltType==E_DSCMB_FLT_2_KEYS) && (pMap->eFltType==E_DSCMB_FLT_3_KEYS))
1147 {
1148 _DSCMB_SlotFree(u32EngId, u32DscmbId , E_DSCMB_KEY_CLEAR ,pMap->u32SlotIdClear);
1149 pMap->u32SlotIdClear= DRV_DSCMB_FLT_NULL;
1150 }
1151 //case -1 slot (enable odd & clear & even index all the same)
1152 else if((eFltType==E_DSCMB_FLT_1_KEYS) && (pMap->eFltType==E_DSCMB_FLT_2_KEYS))
1153 {
1154 _DSCMB_SlotFree(u32EngId, u32DscmbId , E_DSCMB_KEY_ODD ,pMap->u32SlotIdOdd);
1155 pMap->u32SlotIdOdd = pMap->u32SlotIdEven;
1156 pMap->u32SlotIdClear = pMap->u32SlotIdEven;
1157
1158 }
1159 //case -2 slot (enable odd & clear & even index all the same)
1160 else if((eFltType==E_DSCMB_FLT_1_KEYS) && (pMap->eFltType==E_DSCMB_FLT_3_KEYS))
1161 {
1162 _DSCMB_SlotFree(u32EngId, u32DscmbId , E_DSCMB_KEY_ODD ,pMap->u32SlotIdOdd);
1163 _DSCMB_SlotFree(u32EngId, u32DscmbId , E_DSCMB_KEY_CLEAR ,pMap->u32SlotIdClear);
1164 pMap->u32SlotIdOdd = pMap->u32SlotIdEven;
1165 pMap->u32SlotIdClear = pMap->u32SlotIdEven;
1166 }
1167
1168 // if no one connected, we don't need to update HW
1169 if(pMap->u32PidFltIdNum == 0)
1170 {
1171 goto MDrv_DSCMB2_FltSwitchType_OK;
1172 }
1173
1174 ///////////////////////////////////////////////////////////////
1175 //// HW operation (6 cases)
1176 /////////////////////////////////////////////////////////////
1177 #ifdef FLEXIBLE_PIDSLOTMAP
1178 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(u32DscmbId, E_DSCMB_KEY_ODD);
1179 if(pMap->u32SlotIdOdd != DRV_DSCMB_FLT_NULL)
1180 {
1181 if(FALSE == HAL_DSCMB_PidIdx_SetSlotKeyIdx(u32DscmbId, E_DSCMB_KEY_ODD, pMap->u32SlotIdOdd))
1182 {
1183 goto MDrv_DSCMB2_FltSwitchType_HWFAIL;
1184 }
1185 }
1186
1187 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(u32DscmbId, E_DSCMB_KEY_CLEAR);
1188 if(pMap->u32SlotIdClear != DRV_DSCMB_FLT_NULL)
1189 {
1190 if(FALSE == HAL_DSCMB_PidIdx_SetSlotKeyIdx(u32DscmbId, E_DSCMB_KEY_CLEAR, pMap->u32SlotIdClear))
1191 {
1192 goto MDrv_DSCMB2_FltSwitchType_HWFAIL;
1193 }
1194 }
1195 #else
1196 for ( i = 0 ; i < HAL_DSCMB_PIDFLT_NUM ; i ++)
1197 {
1198 if (_u32PidFlt2Dscmb[i].u8DscmbId== u32DscmbId)
1199 {
1200 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(i,E_DSCMB_KEY_ODD);
1201 if(pMap->u32SlotIdOdd != DRV_DSCMB_FLT_NULL)
1202 {
1203 if(FALSE == HAL_DSCMB_PidIdx_SetSlotKeyIdx(i,E_DSCMB_KEY_ODD,pMap->u32SlotIdOdd))
1204 {
1205 goto MDrv_DSCMB2_FltSwitchType_HWFAIL;
1206 }
1207 }
1208
1209 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(i,E_DSCMB_KEY_CLEAR);
1210 if(pMap->u32SlotIdClear != DRV_DSCMB_FLT_NULL)
1211 {
1212 if(FALSE == HAL_DSCMB_PidIdx_SetSlotKeyIdx(i,E_DSCMB_KEY_CLEAR,pMap->u32SlotIdClear))
1213 {
1214 goto MDrv_DSCMB2_FltSwitchType_HWFAIL;
1215 }
1216 }
1217 }
1218 }
1219 #endif /* FLEXIBLE_PIDSLOTMAP */
1220
1221 MDrv_DSCMB2_FltSwitchType_OK:
1222 pMap->eFltType = eFltType;
1223 DSCMB_UNLOCK(_s32DscMutexId);
1224 return TRUE;
1225
1226 MDrv_DSCMB2_FltSwitchType_HWFAIL:
1227 // revert the original setting
1228 pMap->u32SlotIdOdd = u32OldSlotIdOdd;
1229 pMap->u32SlotIdClear = u32OldSlotIdClear;
1230 #ifdef FLEXIBLE_PIDSLOTMAP
1231 if(pMap->u32SlotIdOdd != DRV_DSCMB_FLT_NULL)
1232 {
1233 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(u32DscmbId, E_DSCMB_KEY_ODD);
1234 if(FALSE == HAL_DSCMB_PidIdx_SetSlotKeyIdx(u32DscmbId, E_DSCMB_KEY_ODD, pMap->u32SlotIdOdd))
1235 {
1236 goto MDrv_DSCMB2_FltSwitchType_FAIL;
1237 }
1238 }
1239 if(pMap->u32SlotIdClear != DRV_DSCMB_FLT_NULL)
1240 {
1241 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(u32DscmbId, E_DSCMB_KEY_CLEAR);
1242 if(FALSE == HAL_DSCMB_PidIdx_SetSlotKeyIdx(u32DscmbId, E_DSCMB_KEY_CLEAR, pMap->u32SlotIdClear))
1243 {
1244 goto MDrv_DSCMB2_FltSwitchType_FAIL;
1245 }
1246 }
1247 #else
1248 for ( i = 0 ; i < HAL_DSCMB_PIDFLT_NUM ; i ++)
1249 {
1250 if (_u32PidFlt2Dscmb[i].u8DscmbId== u32DscmbId)
1251 {
1252 if(pMap->u32SlotIdOdd != DRV_DSCMB_FLT_NULL)
1253 {
1254 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(i,E_DSCMB_KEY_ODD);
1255 if(FALSE == HAL_DSCMB_PidIdx_SetSlotKeyIdx(i,E_DSCMB_KEY_ODD,pMap->u32SlotIdOdd))
1256 {
1257 goto MDrv_DSCMB2_FltSwitchType_FAIL;
1258 }
1259 }
1260 if(pMap->u32SlotIdClear != DRV_DSCMB_FLT_NULL)
1261 {
1262 HAL_DSCMB_PidIdx_ClearSlotKeyIdx(i,E_DSCMB_KEY_CLEAR);
1263 if(FALSE == HAL_DSCMB_PidIdx_SetSlotKeyIdx(i,E_DSCMB_KEY_CLEAR,pMap->u32SlotIdClear))
1264 {
1265 goto MDrv_DSCMB2_FltSwitchType_FAIL;
1266 }
1267 }
1268 }
1269 }
1270 #endif /* FLEXIBLE_PIDSLOTMAP */
1271 MDrv_DSCMB2_FltSwitchType_FAIL:
1272
1273 DSCMB_UNLOCK(_s32DscMutexId);
1274 return FALSE;
1275
1276 }
1277
1278
_MDrv_DSCMB2_EngEnableKey(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Eng_Type eEngType,DSCMB_Key_Type eKeyType,MS_BOOL bEnable)1279 MS_BOOL _MDrv_DSCMB2_EngEnableKey(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Eng_Type eEngType, DSCMB_Key_Type eKeyType, MS_BOOL bEnable)
1280 {
1281 MS_U32 u32FltId = 0;
1282 stDscmbTspMap* pMap = NULL;
1283 MS_U32 u32CAVid = DEFAULT_CAVID;
1284 DSCMB_Key_Type eSecureKeyType = E_DSCMB_KEY_CLEAR;
1285
1286 DSCMB_LOCK(_s32DscMutexId);
1287
1288 pMap = &DscmbTspMap[u32EngId][u32DscmbId];
1289 u32CAVid = pMap->u32CAVid;
1290
1291 if (!_DSCMB_Dscmb2Flt( u32DscmbId , &u32FltId ))
1292 {
1293 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "No filter connect to DSCMB\n");
1294 goto MDrv_DSCMB2_FltEnableKey_FAIL;
1295 }
1296
1297 if(TRUE == pMap->bSecure)
1298 {
1299 eSecureKeyType = E_DSCMB_KEY_SECURE_KEYS_ENABLE;
1300 }
1301
1302 if (!HAL_DSCMB_KTE_Key_Ctrl (u32FltId, eKeyType , eEngType | eSecureKeyType, u32CAVid, bEnable ))
1303 {
1304 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Enable Key Fail\n");
1305 goto MDrv_DSCMB2_FltEnableKey_FAIL;
1306 }
1307 DSCMB_UNLOCK(_s32DscMutexId);
1308 return TRUE;
1309
1310 MDrv_DSCMB2_FltEnableKey_FAIL:
1311 DSCMB_UNLOCK(_s32DscMutexId);
1312 return FALSE;
1313 }
1314
1315
_MDrv_DSCMB2_EngSetFSCB(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_FSCB eForceSCB)1316 MS_BOOL _MDrv_DSCMB2_EngSetFSCB(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_FSCB eForceSCB )
1317 {
1318 DSCMB_INIT_CHECK(FALSE);
1319
1320 DSCMB_ASSERT(u32EngId == 0, "EngId input error", FALSE);
1321 DSCMB_ASSERT(u32DscmbId < HAL_DSCMB_KTE_MAX, "DscmbId input error", FALSE);
1322 DSCMB_ASSERT(eForceSCB <= DSCMB_FSCB_ODD, "ForceSCB input error", FALSE);
1323
1324 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Set DscmbId=%u FSCB=%d\n", u32DscmbId, eForceSCB);
1325
1326 stDscmbTspMap* pMap = NULL;
1327 MS_U32 u32FltId = 0 ;
1328 MS_U32 u32CAVid = DEFAULT_CAVID;
1329 MS_BOOL bRet = TRUE;
1330 DSCMB_Key_Type eSecureKeyType = E_DSCMB_KEY_CLEAR;
1331
1332 DSCMB_LOCK(_s32DscMutexId);
1333 pMap = &DscmbTspMap[u32EngId][u32DscmbId];
1334 u32CAVid = pMap->u32CAVid;
1335
1336 if (!_DSCMB_Dscmb2Flt( u32DscmbId , &u32FltId ) )
1337 {
1338 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "No filter connect to DSCMB\n");
1339 goto MDrv_DSCMB2_EngSetFSCB_FAIL;
1340 }
1341
1342 if(TRUE == pMap->bSecure)
1343 {
1344 eSecureKeyType = E_DSCMB_KEY_SECURE_KEYS_ENABLE;
1345 }
1346
1347 bRet &= HAL_DSCMB_KTE_Write_FSCB(u32FltId, (E_DSCMB_KEY_ODD|eSecureKeyType), u32CAVid, eForceSCB);
1348 bRet &= HAL_DSCMB_KTE_Write_FSCB(u32FltId, (E_DSCMB_KEY_EVEN|eSecureKeyType), u32CAVid, eForceSCB);
1349
1350 if(pMap->eFltType == E_DSCMB_FLT_3_KEYS)
1351 {
1352 bRet &= HAL_DSCMB_KTE_Write_FSCB(u32FltId, (E_DSCMB_KEY_CLEAR|eSecureKeyType), u32CAVid, eForceSCB);
1353 }
1354
1355 if (!bRet)
1356 {
1357 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set FSCB Fail\n");
1358 goto MDrv_DSCMB2_EngSetFSCB_FAIL;
1359 }
1360
1361 DSCMB_UNLOCK(_s32DscMutexId);
1362 return TRUE;
1363
1364 MDrv_DSCMB2_EngSetFSCB_FAIL:
1365 DSCMB_UNLOCK(_s32DscMutexId);
1366 return FALSE;
1367 }
1368
1369 // Set Upper & lower switch to dscmb filter //
1370 //--------------------------------------------------------------------------------------------------
1371 /// Set upper switch and lower switch to choose which engine will go into.
1372 /// @param u32DscmbId\b IN: The descrambler id which is get from MDrv_DSCMB2_FltAlloc.
1373 /// @param eUppSwitch\b IN: An Enum type for choosing descrambler engine when go through upper path.
1374 /// @param eLowSwitch\b IN: An Enum type for choosing descrambler engine when go through lower path.
1375 /// @return TRUE - SUCCESS
1376 /// @return FALSE - Failure
1377 /// @note
1378 ///
1379 //--------------------------------------------------------------------------------------------------
_MDrv_DSCMB2_EngSetSwitch(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Eng_Type eUppSwitch,DSCMB_Eng_Type eLowSwitch)1380 MS_BOOL _MDrv_DSCMB2_EngSetSwitch(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Eng_Type eUppSwitch ,DSCMB_Eng_Type eLowSwitch)
1381 {
1382 DSCMB_INIT_CHECK(FALSE);
1383
1384 DSCMB_ASSERT(u32EngId == 0, "EngId input error", FALSE);
1385 DSCMB_ASSERT(u32DscmbId < HAL_DSCMB_KTE_MAX, "DscmbId input error", FALSE);
1386 DSCMB_ASSERT(eUppSwitch <= (E_DSCMB_ENG_LSAS|E_DSCMB_ENG_ESA|E_DSCMB_ENG_LSAD), "UppSwitch input error", FALSE);
1387 DSCMB_ASSERT(eLowSwitch <= (E_DSCMB_ENG_LSAS|E_DSCMB_ENG_ESA|E_DSCMB_ENG_LSAD), "LowSwitch input error", FALSE);
1388 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Set DscmbId=%u UppSwitch=%d LowSwitch=%d\n", u32DscmbId, eUppSwitch, eLowSwitch);
1389
1390 stDscmbTspMap* pMap = NULL;
1391 MS_U32 u32FltId = 0 ;
1392 MS_BOOL bRet = TRUE;
1393 MS_U32 u32CAVid = DEFAULT_CAVID;
1394 DSCMB_Key_Type eSecureKeyType = E_DSCMB_KEY_CLEAR;
1395
1396 DSCMB_LOCK(_s32DscMutexId);
1397 pMap = &DscmbTspMap[u32EngId][u32DscmbId];
1398 u32CAVid = pMap->u32CAVid;
1399
1400 if (!_DSCMB_Dscmb2Flt( u32DscmbId , &u32FltId ) )
1401 {
1402 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "No filter connect to DSCMB\n");
1403 goto MDrv_DSCMB2_EngSetSwitch_FAIL;
1404 }
1405
1406 if(TRUE == pMap->bSecure)
1407 {
1408 eSecureKeyType = E_DSCMB_KEY_SECURE_KEYS_ENABLE;
1409 }
1410
1411 bRet &= HAL_DSCMB_KTE_Write_PacketSwitch(u32FltId, (E_DSCMB_KEY_EVEN|eSecureKeyType), u32CAVid, eUppSwitch, eLowSwitch);
1412 bRet &= HAL_DSCMB_KTE_Write_PacketSwitch(u32FltId, (E_DSCMB_KEY_ODD|eSecureKeyType), u32CAVid, eUppSwitch, eLowSwitch);
1413
1414 if(pMap->eFltType == E_DSCMB_FLT_3_KEYS)
1415 {
1416 bRet &= HAL_DSCMB_KTE_Write_PacketSwitch(u32FltId, (E_DSCMB_KEY_CLEAR|eSecureKeyType), u32CAVid, eUppSwitch, eLowSwitch);
1417 }
1418
1419 if(!bRet)
1420 {
1421 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set Switch Fail\n");
1422 goto MDrv_DSCMB2_EngSetSwitch_FAIL;
1423 }
1424
1425 DSCMB_UNLOCK(_s32DscMutexId);
1426 return TRUE;
1427
1428 MDrv_DSCMB2_EngSetSwitch_FAIL:
1429 DSCMB_UNLOCK(_s32DscMutexId);
1430 return FALSE;
1431 }
1432
_MDrv_DSCMB2_EngSetAlgo(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Eng_Type eEngType,DSCMB_Algo_Cfg stConfig)1433 MS_BOOL _MDrv_DSCMB2_EngSetAlgo(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Eng_Type eEngType, DSCMB_Algo_Cfg stConfig)
1434 {
1435 DSCMB_INIT_CHECK(FALSE);
1436
1437 DSCMB_ASSERT(u32EngId == 0, "EngId input error", FALSE);
1438 DSCMB_ASSERT(u32DscmbId < HAL_DSCMB_KTE_MAX, "DscmbId input error", FALSE);
1439 DSCMB_ASSERT(eEngType <= (E_DSCMB_ENG_LSAS|E_DSCMB_ENG_ESA|E_DSCMB_ENG_LSAD), "EngType input error", FALSE);
1440 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Set Algo DscmbId=%u eEngType=%d\n", u32DscmbId, eEngType);
1441
1442 MS_U32 u32FltId = 0;
1443 stDscmbTspMap* pMap = NULL;
1444 MS_U32 u32CAVid = DEFAULT_CAVID;
1445 MS_U32 u32Variant = 0x0;
1446 DSCMB_Key_Type eSecureKeyType = E_DSCMB_KEY_CLEAR;
1447 DSCMB_LOCK(_s32DscMutexId);
1448 pMap = &DscmbTspMap[u32EngId][u32DscmbId];
1449 u32CAVid = pMap->u32CAVid;
1450
1451 if (!_DSCMB_Dscmb2Flt( u32DscmbId , &u32FltId ) )
1452 {
1453 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "No filter connect to DSCMB\n");
1454 goto MDrv_DSCMB2_EngSetAlgo_FAIL;
1455 }
1456
1457 if(TRUE == pMap->bSecure)
1458 {
1459 eSecureKeyType = E_DSCMB_KEY_SECURE_KEYS_ENABLE;
1460 }
1461
1462 if((eEngType & E_DSCMB_ENG_LSAS ) == E_DSCMB_ENG_LSAS)
1463 {
1464 if ((!HAL_DSCMB_KTE_Write_Algo(u32FltId, (E_DSCMB_KEY_EVEN|eSecureKeyType), E_DSCMB_ENG_LSAS, u32CAVid, stConfig.eMainAlgo,
1465 stConfig.eSubAlgo, stConfig.eResAlgo, stConfig.eSBAlgo, stConfig.bDecrypt ))||
1466 (!HAL_DSCMB_KTE_Write_Algo(u32FltId, (E_DSCMB_KEY_ODD|eSecureKeyType) , E_DSCMB_ENG_LSAS, u32CAVid, stConfig.eMainAlgo,
1467 stConfig.eSubAlgo, stConfig.eResAlgo, stConfig.eSBAlgo, stConfig.bDecrypt )))
1468 {
1469 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set LSAS Engine Algorithm Fail\n");
1470 goto MDrv_DSCMB2_EngSetAlgo_FAIL;
1471 }
1472
1473 if(pMap->eFltType == E_DSCMB_FLT_3_KEYS)
1474 {
1475 if(!HAL_DSCMB_KTE_Write_Algo(u32FltId, (E_DSCMB_KEY_CLEAR|eSecureKeyType), E_DSCMB_ENG_LSAS, u32CAVid, stConfig.eMainAlgo,
1476 stConfig.eSubAlgo, stConfig.eResAlgo, stConfig.eSBAlgo, stConfig.bDecrypt ))
1477 {
1478 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set LSAS Engine Algorithm Fail\n");
1479 goto MDrv_DSCMB2_EngSetAlgo_FAIL;
1480 }
1481 }
1482 }
1483
1484 if((eEngType & E_DSCMB_ENG_ESA ) == E_DSCMB_ENG_ESA)
1485 {
1486 if ((!HAL_DSCMB_KTE_Write_Algo(u32FltId, (E_DSCMB_KEY_EVEN|eSecureKeyType), E_DSCMB_ENG_ESA, u32CAVid, stConfig.eMainAlgo,
1487 stConfig.eSubAlgo, stConfig.eResAlgo, stConfig.eSBAlgo, stConfig.bDecrypt ))||
1488 (!HAL_DSCMB_KTE_Write_Algo(u32FltId, (E_DSCMB_KEY_ODD|eSecureKeyType) , E_DSCMB_ENG_ESA, u32CAVid, stConfig.eMainAlgo,
1489 stConfig.eSubAlgo, stConfig.eResAlgo, stConfig.eSBAlgo, stConfig.bDecrypt )))
1490 {
1491 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set ESA Engine Algorithm Fail\n");
1492 goto MDrv_DSCMB2_EngSetAlgo_FAIL;
1493 }
1494
1495 if(pMap->eFltType == E_DSCMB_FLT_3_KEYS)
1496 {
1497 if(!HAL_DSCMB_KTE_Write_Algo(u32FltId, (E_DSCMB_KEY_CLEAR|eSecureKeyType), E_DSCMB_ENG_ESA, u32CAVid, stConfig.eMainAlgo,
1498 stConfig.eSubAlgo, stConfig.eResAlgo, stConfig.eSBAlgo, stConfig.bDecrypt ))
1499 {
1500 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set LSAS Engine Algorithm Fail\n");
1501 goto MDrv_DSCMB2_EngSetAlgo_FAIL;
1502 }
1503 }
1504 }
1505
1506 if((eEngType & E_DSCMB_ENG_LSAD ) == E_DSCMB_ENG_LSAD)
1507 {
1508 if ((!HAL_DSCMB_KTE_Write_Algo(u32FltId, (E_DSCMB_KEY_EVEN|eSecureKeyType), E_DSCMB_ENG_LSAD, u32CAVid, stConfig.eMainAlgo,
1509 stConfig.eSubAlgo, stConfig.eResAlgo, stConfig.eSBAlgo, stConfig.bDecrypt ))||
1510 (!HAL_DSCMB_KTE_Write_Algo(u32FltId, (E_DSCMB_KEY_ODD|eSecureKeyType) , E_DSCMB_ENG_LSAD, u32CAVid, stConfig.eMainAlgo,
1511 stConfig.eSubAlgo, stConfig.eResAlgo, stConfig.eSBAlgo, stConfig.bDecrypt )))
1512 {
1513 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set LSAD Engine Algorithm Fail\n");
1514 goto MDrv_DSCMB2_EngSetAlgo_FAIL;
1515 }
1516
1517 if(pMap->eFltType == E_DSCMB_FLT_3_KEYS)
1518 {
1519 if(!HAL_DSCMB_KTE_Write_Algo(u32FltId, (E_DSCMB_KEY_CLEAR|eSecureKeyType), E_DSCMB_ENG_LSAD, u32CAVid, stConfig.eMainAlgo,
1520 stConfig.eSubAlgo, stConfig.eResAlgo, stConfig.eSBAlgo, stConfig.bDecrypt ))
1521 {
1522 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set LSAS Engine Algorithm Fail\n");
1523 goto MDrv_DSCMB2_EngSetAlgo_FAIL;
1524 }
1525 }
1526 }
1527
1528 if((eEngType & E_DSCMB_ENG_ESA ) == E_DSCMB_ENG_ESA)
1529 {
1530 if((stConfig.eMainAlgo == E_DSCMB_MAIN_ALGO_CSA2) ||(stConfig.eMainAlgo == E_DSCMB_MAIN_ALGO_CSA2_CONF))
1531 {
1532 u32Variant = 0x1;
1533 }
1534
1535 HAL_DSCMB_KTE_Write_SBOX( u32FltId , (E_DSCMB_KEY_ODD|eSecureKeyType) , u32CAVid, u32Variant, FALSE );
1536 HAL_DSCMB_KTE_Write_SBOX( u32FltId , (E_DSCMB_KEY_EVEN|eSecureKeyType) , u32CAVid, u32Variant, FALSE );
1537 if(pMap->eFltType == E_DSCMB_FLT_3_KEYS)
1538 {
1539 HAL_DSCMB_KTE_Write_SBOX( u32FltId , (E_DSCMB_KEY_CLEAR|eSecureKeyType), u32CAVid, u32Variant, FALSE );
1540 }
1541 }
1542
1543 if(stConfig.bDecrypt == TRUE)
1544 {
1545 HAL_DSCMB_KTE_Write_FSCB(u32FltId, (E_DSCMB_KEY_ODD|eSecureKeyType), u32CAVid, DSCMB_FSCB_CLEAR);
1546 HAL_DSCMB_KTE_Write_FSCB(u32FltId, (E_DSCMB_KEY_EVEN|eSecureKeyType), u32CAVid, DSCMB_FSCB_CLEAR);
1547 if(pMap->eFltType == E_DSCMB_FLT_3_KEYS)
1548 {
1549 HAL_DSCMB_KTE_Write_FSCB(u32FltId, (E_DSCMB_KEY_CLEAR|eSecureKeyType), u32CAVid, DSCMB_FSCB_CLEAR);
1550 }
1551 }
1552 else
1553 {
1554 HAL_DSCMB_KTE_Write_FSCB(u32FltId, (E_DSCMB_KEY_ODD|eSecureKeyType), u32CAVid, DSCMB_FSCB_UNCHG);
1555 HAL_DSCMB_KTE_Write_FSCB(u32FltId, (E_DSCMB_KEY_EVEN|eSecureKeyType), u32CAVid, DSCMB_FSCB_UNCHG);
1556 if(pMap->eFltType == E_DSCMB_FLT_3_KEYS)
1557 {
1558 HAL_DSCMB_KTE_Write_FSCB(u32FltId, (E_DSCMB_KEY_CLEAR|eSecureKeyType), u32CAVid, DSCMB_FSCB_UNCHG);
1559 }
1560 }
1561
1562 DSCMB_UNLOCK(_s32DscMutexId);
1563 return TRUE ;
1564
1565 MDrv_DSCMB2_EngSetAlgo_FAIL:
1566
1567 DSCMB_UNLOCK(_s32DscMutexId);
1568 return FALSE ;
1569 }
1570
_MDrv_DSCMB2_EngSetIV(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Key_Type eKeyType,MS_U8 * pu8IV)1571 MS_BOOL _MDrv_DSCMB2_EngSetIV(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Key_Type eKeyType, MS_U8* pu8IV)
1572 {
1573 DSCMB_INIT_CHECK(FALSE);
1574
1575 DSCMB_ASSERT(u32EngId == 0, "EngId input error", FALSE);
1576 DSCMB_ASSERT(u32DscmbId < HAL_DSCMB_KTE_MAX, "DscmbId input error", FALSE);
1577 DSCMB_ASSERT(eKeyType <= E_DSCMB_KEY_ODD, "KeyType input error", FALSE);
1578 DSCMB_ASSERT(pu8IV != NULL, "Key data input error", FALSE);
1579 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Set IV DscmbId=%u eKeyType=%d\n", u32DscmbId, eKeyType);
1580
1581 MS_U32 u32FltId = 0;
1582 stDscmbTspMap* pMap = NULL;
1583 MS_U32 u32CAVid = DEFAULT_CAVID;
1584 DSCMB_Key_Type eSecureKeyType = E_DSCMB_KEY_CLEAR;
1585
1586 DSCMB_LOCK(_s32DscMutexId);
1587
1588 pMap = &DscmbTspMap[u32EngId][u32DscmbId];
1589 u32CAVid = pMap->u32CAVid;
1590
1591 if (!_DSCMB_Dscmb2Flt( u32DscmbId , &u32FltId ))
1592 {
1593 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "No filter connect to DSCMB\n");
1594 goto MDrv_DSCMB2_EngSetIV_FAIL;
1595 }
1596
1597 if(TRUE == pMap->bSecure)
1598 {
1599 eSecureKeyType = E_DSCMB_KEY_SECURE_KEYS_ENABLE;
1600 }
1601
1602 if((pMap->eFltType == E_DSCMB_FLT_2_KEYS) && (eKeyType == E_DSCMB_KEY_CLEAR))
1603 {
1604 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "User Try to use 3 Keys.\n");
1605 goto MDrv_DSCMB2_EngSetIV_FAIL;
1606 }
1607
1608 if (!HAL_DSCMB_KTE_Write_IV(u32FltId, eKeyType | eSecureKeyType , u32CAVid, pu8IV))
1609 {
1610 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set IV Fail\n");
1611 goto MDrv_DSCMB2_EngSetIV_FAIL;
1612 }
1613
1614 if (!HAL_DSCMB_KTE_IV_Ctrl (u32FltId, eKeyType | eSecureKeyType , u32CAVid, TRUE ))
1615 {
1616 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set IV Fail\n");
1617 goto MDrv_DSCMB2_EngSetIV_FAIL;
1618 }
1619
1620 DSCMB_UNLOCK(_s32DscMutexId);
1621 return TRUE;
1622
1623 MDrv_DSCMB2_EngSetIV_FAIL:
1624
1625 DSCMB_UNLOCK(_s32DscMutexId);
1626 return FALSE ;
1627 }
1628
1629
_MDrv_DSCMB2_EngSetIV_Ex(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Eng_Type eEngType,DSCMB_Key_Type eKeyType,MS_U8 * pu8IV)1630 MS_BOOL _MDrv_DSCMB2_EngSetIV_Ex(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Eng_Type eEngType, DSCMB_Key_Type eKeyType, MS_U8* pu8IV)
1631 {
1632 DSCMB_INIT_CHECK(FALSE);
1633
1634 DSCMB_ASSERT(u32EngId == 0, "EngId input error", FALSE);
1635 DSCMB_ASSERT(u32DscmbId < HAL_DSCMB_KTE_MAX, "DscmbId input error", FALSE);
1636 DSCMB_ASSERT(eEngType <= (E_DSCMB_ENG_LSAS|E_DSCMB_ENG_ESA|E_DSCMB_ENG_LSAD), "EngType input error", FALSE);
1637 DSCMB_ASSERT(eKeyType <= E_DSCMB_KEY_ODD, "KeyType input error", FALSE);
1638 DSCMB_ASSERT(pu8IV != NULL, "Key data input error", FALSE);
1639 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Set IV DscmbId=%u eKeyType=%d\n", u32DscmbId, eKeyType);
1640
1641 MS_U32 u32FltId = 0;
1642 stDscmbTspMap* pMap = NULL;
1643 MS_U32 u32CAVid = DEFAULT_CAVID;
1644 DSCMB_Key_Type eSecureKeyType = E_DSCMB_KEY_CLEAR;
1645
1646 DSCMB_LOCK(_s32DscMutexId);
1647
1648 pMap = &DscmbTspMap[u32EngId][u32DscmbId];
1649 u32CAVid = pMap->u32CAVid;
1650
1651 if (!_DSCMB_Dscmb2Flt( u32DscmbId , &u32FltId ))
1652 {
1653 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "No filter connect to DSCMB\n");
1654 goto MDrv_DSCMB2_EngSetIV_Ex_FAIL;
1655 }
1656
1657 if(TRUE == pMap->bSecure)
1658 {
1659 eSecureKeyType = E_DSCMB_KEY_SECURE_KEYS_ENABLE;
1660 }
1661
1662 if((pMap->eFltType == E_DSCMB_FLT_2_KEYS) && (eKeyType == E_DSCMB_KEY_CLEAR))
1663 {
1664 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "User Try to use 3 Keys.\n");
1665 goto MDrv_DSCMB2_EngSetIV_Ex_FAIL;
1666 }
1667
1668 //Deal with LSAS engine
1669 if((eEngType & E_DSCMB_ENG_LSAS) == E_DSCMB_ENG_LSAS )
1670 {
1671 if (!HAL_DSCMB_KTE_Write_IV_Ex(u32FltId, eKeyType | eSecureKeyType, E_DSCMB_ENG_LSAS, u32CAVid, pu8IV))
1672 {
1673 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set LSAS IV Fail\n");
1674 goto MDrv_DSCMB2_EngSetIV_Ex_FAIL;
1675 }
1676
1677 if (!HAL_DSCMB_KTE_IV_Ctrl_Ex (u32FltId, eKeyType | eSecureKeyType, E_DSCMB_ENG_LSAS, u32CAVid, TRUE ))
1678 {
1679 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set LSAS IV Fail\n");
1680 goto MDrv_DSCMB2_EngSetIV_Ex_FAIL;
1681 }
1682 }
1683
1684 //Deal with ESA engine
1685 if((eEngType & E_DSCMB_ENG_ESA) == E_DSCMB_ENG_ESA )
1686 {
1687 if (!HAL_DSCMB_KTE_Write_IV_Ex(u32FltId, eKeyType | eSecureKeyType, E_DSCMB_ENG_ESA, u32CAVid, pu8IV))
1688 {
1689 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set ESA IV Fail\n");
1690 goto MDrv_DSCMB2_EngSetIV_Ex_FAIL;
1691 }
1692
1693 if (!HAL_DSCMB_KTE_IV_Ctrl_Ex (u32FltId, eKeyType | eSecureKeyType, E_DSCMB_ENG_ESA, u32CAVid, TRUE ))
1694 {
1695 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set ESA IV Fail\n");
1696 goto MDrv_DSCMB2_EngSetIV_Ex_FAIL;
1697 }
1698 }
1699
1700 //Deal with LSAD engine
1701 if((eEngType & E_DSCMB_ENG_LSAD) == E_DSCMB_ENG_LSAD )
1702 {
1703 if (!HAL_DSCMB_KTE_Write_IV_Ex(u32FltId, eKeyType | eSecureKeyType, E_DSCMB_ENG_LSAD, u32CAVid, pu8IV))
1704 {
1705 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set LSAD IV Fail\n");
1706 goto MDrv_DSCMB2_EngSetIV_Ex_FAIL;
1707 }
1708
1709 if (!HAL_DSCMB_KTE_IV_Ctrl_Ex (u32FltId, eKeyType | eSecureKeyType, E_DSCMB_ENG_LSAD, u32CAVid, TRUE ))
1710 {
1711 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set LSAD IV Fail\n");
1712 goto MDrv_DSCMB2_EngSetIV_Ex_FAIL;
1713 }
1714 }
1715
1716 DSCMB_UNLOCK(_s32DscMutexId);
1717 return TRUE;
1718
1719 MDrv_DSCMB2_EngSetIV_Ex_FAIL:
1720
1721 DSCMB_UNLOCK(_s32DscMutexId);
1722 return FALSE ;
1723 }
1724
_MDrv_DSCMB2_EngSetRIV(MS_U32 u32EngId,MS_U32 u32DscmbId,MS_U8 * pu8RIV)1725 MS_BOOL _MDrv_DSCMB2_EngSetRIV(MS_U32 u32EngId, MS_U32 u32DscmbId, MS_U8* pu8RIV)
1726 {
1727 DSCMB_INIT_CHECK(FALSE);
1728
1729 DSCMB_ASSERT(u32EngId == 0, "EngId input error", FALSE);
1730 DSCMB_ASSERT(u32DscmbId < HAL_DSCMB_KTE_MAX, "DscmbId input error", FALSE);
1731 DSCMB_ASSERT(pu8RIV != NULL, "Key data input error", FALSE);
1732
1733 MS_U32 u32FltId = 0;
1734 stDscmbTspMap* pMap = NULL;
1735 MS_U32 u32CAVid = DEFAULT_CAVID;
1736 DSCMB_Key_Type eSecureKeyType = E_DSCMB_KEY_CLEAR;
1737 DSCMB_LOCK(_s32DscMutexId);
1738
1739 pMap = &DscmbTspMap[u32EngId][u32DscmbId];
1740 u32CAVid = pMap->u32CAVid;
1741 if (!_DSCMB_Dscmb2Flt( u32DscmbId , &u32FltId ))
1742 {
1743 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "No filter connect to DSCMB\n");
1744 goto MDrv_DSCMB2_EngSetRIV_FAIL;
1745 }
1746
1747 if(TRUE == pMap->bSecure)
1748 {
1749 eSecureKeyType = E_DSCMB_KEY_SECURE_KEYS_ENABLE;
1750 }
1751
1752 if(pMap->eFltType == E_DSCMB_FLT_2_KEYS)
1753 {
1754 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "User Try to use 3 Keys.\n");
1755 goto MDrv_DSCMB2_EngSetRIV_FAIL;
1756 }
1757
1758 if(pMap->u32RIVIdx == HAL_DSCMB_RIV_MAX)
1759 {
1760 if(_DSCMB_SlotRIVAlloc (u32EngId, u32DscmbId, &pMap->u32RIVIdx) == FALSE)
1761 {
1762 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Find RIV Slot FAIL\n");
1763 goto MDrv_DSCMB2_EngSetRIV_FAIL;
1764 }
1765 }
1766
1767 if (!HAL_DSCMB_KTE_Write_RIV(u32FltId, (E_DSCMB_KEY_CLEAR|eSecureKeyType), u32CAVid, pu8RIV, pMap->u32RIVIdx))
1768 {
1769 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set RIV Fail\n");
1770 goto MDrv_DSCMB2_EngSetRIV_FAIL;
1771 }
1772
1773 if (!HAL_DSCMB_KTE_IV_Ctrl_Ex (u32FltId, (E_DSCMB_KEY_CLEAR|eSecureKeyType), E_DSCMB_ENG_ESA, u32CAVid, TRUE ))
1774 {
1775 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set RIV Fail\n");
1776 goto MDrv_DSCMB2_EngSetRIV_FAIL;
1777 }
1778
1779 // TODO: need to fix channel number
1780 HAL_DSCMB_PES_Enable (0, pMap->u32Tsid, TRUE);
1781
1782 DSCMB_UNLOCK(_s32DscMutexId);
1783 return TRUE;
1784
1785 MDrv_DSCMB2_EngSetRIV_FAIL:
1786
1787 DSCMB_UNLOCK(_s32DscMutexId);
1788 return FALSE ;
1789
1790 }
1791
_MDrv_DSCMB2_EngSetKeyFSCB(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Eng_Type eEngType,DSCMB_Key_Type eKeyType,DSCMB_FSCB eForceSCB)1792 MS_BOOL _MDrv_DSCMB2_EngSetKeyFSCB(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Eng_Type eEngType, DSCMB_Key_Type eKeyType, DSCMB_FSCB eForceSCB)
1793 {
1794 DSCMB_INIT_CHECK(FALSE);
1795
1796 DSCMB_ASSERT(u32EngId == 0, "EngId input error", FALSE);
1797 DSCMB_ASSERT(u32DscmbId < HAL_DSCMB_KTE_MAX, "DscmbId input error", FALSE);
1798 DSCMB_ASSERT(eEngType <= (E_DSCMB_ENG_LSAS|E_DSCMB_ENG_ESA|E_DSCMB_ENG_LSAD), "EngType input error", FALSE);
1799 DSCMB_ASSERT(eKeyType <= E_DSCMB_KEY_ODD, "KeyType input error", FALSE);
1800
1801 MS_BOOL bRet = TRUE;
1802
1803 #ifdef ENABLE_KEY_FSCB
1804 MS_U32 u32KteSel = REG_KTE_SEL_LSAD;
1805 MS_U32 u32i = 0;
1806 MS_U32 u32FltId = 0;
1807
1808 if (!_DSCMB_Dscmb2Flt( u32DscmbId , &u32FltId ))
1809 {
1810 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "No filter connect to DSCMB\n");
1811 return FALSE;
1812 }
1813
1814 switch(eEngType)
1815 {
1816 case E_DSCMB_ENG_LSAS:
1817 u32KteSel = E_HAL_DSCMB_ENG_LSAS;
1818 break;
1819 case E_DSCMB_ENG_ESA:
1820 u32KteSel = E_HAL_DSCMB_ENG_ESA;
1821 break;
1822 case E_DSCMB_ENG_LSAD:
1823 u32KteSel = E_HAL_DSCMB_ENG_LSAD;
1824 break;
1825 default:
1826 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "EngType input error\n");
1827 return FALSE;
1828 }
1829 #ifdef FLEXIBLE_PIDSLOTMAP
1830 bRet = HAL_DSCMB_KTE_Write_KeyFSCB( u32FltId, u32KteSel, eKeyType, eForceSCB);
1831 u32i = u32i;
1832 #else
1833 for(u32i = 0 ; u32i < HAL_DSCMB_PIDFLT_NUM ; u32i++ )
1834 {
1835 if ( _u32PidFlt2Dscmb[u32i].u8DscmbId==u32DscmbId )
1836 {
1837 bRet |= HAL_DSCMB_KTE_Write_KeyFSCB( u32i, u32KteSel, eKeyType, eForceSCB);
1838 }
1839
1840 if( TRUE!= bRet )
1841 {
1842 break;
1843 }
1844 }
1845 #endif
1846 #else
1847 DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING,"Not support.\n");
1848 bRet = FALSE;
1849 #endif
1850
1851 return bRet;
1852 }
1853
_MDrv_DSCMB2_EngSetKey(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Eng_Type eEngType,DSCMB_Key_Type eKeyType,MS_U8 * pu8Key)1854 MS_BOOL _MDrv_DSCMB2_EngSetKey(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Eng_Type eEngType, DSCMB_Key_Type eKeyType, MS_U8* pu8Key)
1855 {
1856 DSCMB_INIT_CHECK(FALSE);
1857
1858 DSCMB_ASSERT(u32EngId == 0, "EngId input error", FALSE);
1859 DSCMB_ASSERT(u32DscmbId < HAL_DSCMB_KTE_MAX, "DscmbId input error", FALSE);
1860 DSCMB_ASSERT(eEngType <= (E_DSCMB_ENG_LSAS|E_DSCMB_ENG_ESA|E_DSCMB_ENG_LSAD), "EngType input error", FALSE);
1861 DSCMB_ASSERT(eKeyType <= E_DSCMB_KEY_ODD, "KeyType input error", FALSE);
1862 DSCMB_ASSERT(pu8Key != NULL, "Key data input error", FALSE);
1863 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Set Key DscmbId=%u eEngType=%d, eKeyType=%d\n", u32DscmbId, eEngType, eKeyType);
1864
1865 MS_U32 u32FltId = 0;
1866 stDscmbTspMap* pMap = NULL;
1867 MS_U32 u32CAVid = DEFAULT_CAVID;
1868 DSCMB_Key_Type eSecureKeyType = E_DSCMB_KEY_CLEAR;
1869
1870 DSCMB_LOCK(_s32DscMutexId);
1871
1872 if (!_DSCMB_Dscmb2Flt( u32DscmbId , &u32FltId ))
1873 {
1874 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "No filter connect to DSCMB\n");
1875 goto MDrv_DSCMB2_EngSetKey_FAIL;
1876 }
1877
1878 pMap = &DscmbTspMap[u32EngId][u32DscmbId];
1879 u32CAVid = pMap->u32CAVid;
1880
1881 if(TRUE == pMap->bSecure)
1882 {
1883 eSecureKeyType = E_DSCMB_KEY_SECURE_KEYS_ENABLE;
1884 }
1885
1886 if((pMap->eFltType == E_DSCMB_FLT_2_KEYS) && (eKeyType == E_DSCMB_KEY_CLEAR))
1887 {
1888 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "User Try to use 3 Keys.\n");
1889 goto MDrv_DSCMB2_EngSetKey_FAIL;
1890 }
1891
1892 //Deal with LSAS engine
1893 if((eEngType & E_DSCMB_ENG_LSAS) == E_DSCMB_ENG_LSAS )
1894 {
1895 if (!HAL_DSCMB_KTE_Write_Key(u32FltId, eKeyType | eSecureKeyType , E_DSCMB_ENG_LSAS , u32CAVid, pu8Key))
1896 {
1897 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set Key Fail with LSAS Engine.\n");
1898 goto MDrv_DSCMB2_EngSetKey_FAIL;
1899 }
1900
1901 if (!HAL_DSCMB_KTE_Key_Ctrl (u32FltId, eKeyType | eSecureKeyType, E_DSCMB_ENG_LSAS , u32CAVid, TRUE ))
1902 {
1903 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set Key Fail with LSAS Engine.\n");
1904 goto MDrv_DSCMB2_EngSetKey_FAIL;
1905 }
1906 }
1907 //Deal with ESA engine
1908 if((eEngType & E_DSCMB_ENG_ESA) == E_DSCMB_ENG_ESA )
1909 {
1910 if (!HAL_DSCMB_KTE_Write_Key(u32FltId, eKeyType | eSecureKeyType, E_DSCMB_ENG_ESA , u32CAVid, pu8Key))
1911 {
1912 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set Key Fail with ESA Engine.\n");
1913 goto MDrv_DSCMB2_EngSetKey_FAIL;
1914 }
1915
1916 if (!HAL_DSCMB_KTE_Key_Ctrl (u32FltId, eKeyType | eSecureKeyType, E_DSCMB_ENG_ESA , u32CAVid, TRUE ))
1917 {
1918 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set Key Fail with ESA Engine.\n");
1919 goto MDrv_DSCMB2_EngSetKey_FAIL;
1920 }
1921 }
1922 //Deal with LSAD engine
1923 if((eEngType & E_DSCMB_ENG_LSAD) == E_DSCMB_ENG_LSAD )
1924 {
1925 if (!HAL_DSCMB_KTE_Write_Key(u32FltId, eKeyType | eSecureKeyType, E_DSCMB_ENG_LSAD , u32CAVid, pu8Key))
1926 {
1927 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set Key Fail with LSAD Engine.\n");
1928 goto MDrv_DSCMB2_EngSetKey_FAIL;
1929 }
1930
1931 if (!HAL_DSCMB_KTE_Key_Ctrl (u32FltId, eKeyType | eSecureKeyType, E_DSCMB_ENG_LSAD , u32CAVid, TRUE ))
1932 {
1933 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set Key Fail with LSAD Engine.\n");
1934 goto MDrv_DSCMB2_EngSetKey_FAIL;
1935 }
1936 }
1937
1938 DSCMB_UNLOCK(_s32DscMutexId);
1939 return TRUE;
1940
1941 MDrv_DSCMB2_EngSetKey_FAIL:
1942
1943 DSCMB_UNLOCK(_s32DscMutexId);
1944 return FALSE ;
1945 }
1946
_MDrv_DSCMB2_EngResetKey(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Eng_Type eEngType,DSCMB_Key_Type eKeyType)1947 MS_BOOL _MDrv_DSCMB2_EngResetKey(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Eng_Type eEngType, DSCMB_Key_Type eKeyType)
1948 {
1949 DSCMB_INIT_CHECK(FALSE);
1950
1951 DSCMB_ASSERT(u32EngId == 0, "EngId input error", FALSE);
1952 DSCMB_ASSERT(u32DscmbId < HAL_DSCMB_KTE_MAX, "DscmbId input error", FALSE);
1953 DSCMB_ASSERT(eEngType <= (E_DSCMB_ENG_LSAS|E_DSCMB_ENG_ESA|E_DSCMB_ENG_LSAD), "EngType input error", FALSE);
1954 DSCMB_ASSERT(eKeyType <= E_DSCMB_KEY_ODD, "KeyType input error", FALSE);
1955
1956 MS_U8 ClrKey[16] = {0};
1957 MS_U32 u32FltId = 0 ;
1958 stDscmbTspMap* pMap = NULL;
1959 MS_U32 u32CAVid = DEFAULT_CAVID;
1960 DSCMB_Key_Type eSecureKeyType = E_DSCMB_KEY_CLEAR;
1961
1962 DSCMB_LOCK(_s32DscMutexId);
1963
1964 if (!_DSCMB_Dscmb2Flt( u32DscmbId , &u32FltId ) )
1965 {
1966 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "No filter connect to DSCMB\n");
1967 goto MDrv_DSCMB2_EngResetKey_FAIL;
1968 }
1969
1970 pMap = &DscmbTspMap[u32EngId][u32DscmbId];
1971 u32CAVid = pMap->u32CAVid;
1972
1973 if(TRUE == pMap->bSecure)
1974 {
1975 eSecureKeyType = E_DSCMB_KEY_SECURE_KEYS_ENABLE;
1976 }
1977
1978 if((pMap->eFltType == E_DSCMB_FLT_2_KEYS) && (eKeyType == E_DSCMB_KEY_CLEAR))
1979 {
1980 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "User Try to use 3 Keys.\n");
1981 goto MDrv_DSCMB2_EngResetKey_FAIL;
1982 }
1983
1984 //Deal with LSAS engine
1985 if((eEngType & E_DSCMB_ENG_LSAS) == E_DSCMB_ENG_LSAS )
1986 {
1987 if (!HAL_DSCMB_KTE_Write_Key(u32FltId, eKeyType | eSecureKeyType, E_DSCMB_ENG_LSAS, u32CAVid, ClrKey))
1988 {
1989 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Reset Key Fail with LSAS Engine.\n");
1990 goto MDrv_DSCMB2_EngResetKey_FAIL;
1991 }
1992 }
1993 //Deal with ESA engine
1994 if((eEngType & E_DSCMB_ENG_ESA) == E_DSCMB_ENG_ESA )
1995 {
1996 if (!HAL_DSCMB_KTE_Write_Key(u32FltId, eKeyType | eSecureKeyType, E_DSCMB_ENG_ESA, u32CAVid, ClrKey))
1997 {
1998 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Reset Key Fail with ESA Engine.\n");
1999 goto MDrv_DSCMB2_EngResetKey_FAIL;
2000 }
2001 }
2002 //Deal with LSAD engine
2003 if((eEngType & E_DSCMB_ENG_LSAD) == E_DSCMB_ENG_LSAD )
2004 {
2005 if (!HAL_DSCMB_KTE_Write_Key(u32FltId, eKeyType | eSecureKeyType, E_DSCMB_ENG_LSAD, u32CAVid, ClrKey))
2006 {
2007 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Reset Key Fail with LSAD Engine.\n");
2008 goto MDrv_DSCMB2_EngResetKey_FAIL;
2009 }
2010 }
2011
2012 DSCMB_UNLOCK(_s32DscMutexId);
2013 return TRUE ;
2014 MDrv_DSCMB2_EngResetKey_FAIL:
2015
2016 DSCMB_UNLOCK(_s32DscMutexId);
2017 return FALSE;
2018 }
2019
_MDrv_DSCMB2_EngSetCAVid(MS_U32 u32EngId,MS_U32 u32DscmbId,MS_U32 u32CAVid)2020 MS_BOOL _MDrv_DSCMB2_EngSetCAVid(MS_U32 u32EngId, MS_U32 u32DscmbId, MS_U32 u32CAVid)
2021 {
2022 DSCMB_INIT_CHECK(FALSE);
2023
2024 MS_U32 i = 0;
2025 stDscmbTspMap* pMap = NULL;
2026
2027 DSCMB_LOCK(_s32DscMutexId);
2028 pMap = &DscmbTspMap[u32EngId][u32DscmbId];
2029
2030 for(i = 0 ; i < HAL_DSCMB_PIDFLT_NUM; i++)
2031 {
2032 if(_DSCMB_IsFltConnectDSCMB(u32DscmbId, i))
2033 {
2034 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "DSCMB filter connect more than one filter\n");
2035 goto MDrv_DSCMB2_EngSetCAVid_FAIL;
2036 }
2037 }
2038
2039 pMap->u32CAVid = u32CAVid;
2040
2041 DSCMB_UNLOCK(_s32DscMutexId);
2042 return TRUE;
2043
2044 MDrv_DSCMB2_EngSetCAVid_FAIL:
2045
2046 DSCMB_UNLOCK(_s32DscMutexId);
2047 return FALSE;
2048 }
2049
_MDrv_DSCMB2_SetDefaultCAVid(MS_U32 u32EngId,MS_U32 u32CAVid)2050 MS_BOOL _MDrv_DSCMB2_SetDefaultCAVid(MS_U32 u32EngId, MS_U32 u32CAVid)
2051 {
2052 DSCMB_INIT_CHECK(FALSE);
2053
2054 DSCMB_ASSERT(u32EngId == 0, "EngId input error", FALSE);
2055 DSCMB_ASSERT((u32CAVid != 0) && (u32CAVid <= DEFAULT_CAVID), "CAVid input error", FALSE);
2056
2057 MS_U32 i = 0;
2058 stDscmbTspMap* pMap = NULL;
2059
2060 DSCMB_LOCK(_s32DscMutexId);
2061 #ifdef FLEXIBLE_PIDSLOTMAP
2062 for ( i = 1 ; i < HAL_DSCMB_KTE_MAX ; i ++)
2063 #else
2064 for ( i = 0 ; i < HAL_DSCMB_KTE_MAX ; i ++)
2065 #endif
2066 {
2067 pMap = &DscmbTspMap[u32EngId][i];
2068 if ( (pMap->bUsed == TRUE) && (pMap->u32CAVid != u32CAVid))
2069 {
2070 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Please release dscmb id %u\n", i);
2071 goto MDrv_DSCMB2_SetDefaultCAVid_FAIL;
2072 }
2073 }
2074
2075 //set default cavid
2076 HAL_DSCMB_SetCAVid (u32CAVid);
2077
2078 //set tsp cavid and packet out cavid
2079 for(i = 0 ; i < HAL_DSCMB_TSID_MAX; i++)
2080 {
2081 HAL_DSCMB_SetTSPCAVid(i, u32CAVid);
2082 }
2083
2084 DSCMB_UNLOCK(_s32DscMutexId);
2085 return TRUE;
2086 MDrv_DSCMB2_SetDefaultCAVid_FAIL:
2087 DSCMB_UNLOCK(_s32DscMutexId);
2088 return FALSE;
2089 }
2090
_MDrv_DSCMB2_GetPidSlotMapIndex(MS_U32 u32EngId,MS_U32 u32DscmbId)2091 MS_U32 _MDrv_DSCMB2_GetPidSlotMapIndex(MS_U32 u32EngId, MS_U32 u32DscmbId)
2092 {
2093 DSCMB_INIT_CHECK(DRV_DSCMB_FLT_NULL);
2094
2095 DSCMB_ASSERT(u32EngId == 0, "EngId input error", FALSE);
2096 DSCMB_ASSERT(u32DscmbId < HAL_DSCMB_KTE_MAX, "DscmbId input error", FALSE);
2097
2098 MS_U32 u32FltId = 0 ;
2099
2100 DSCMB_LOCK(_s32DscMutexId);
2101
2102 if (!_DSCMB_Dscmb2Flt( u32DscmbId , &u32FltId ) )
2103 {
2104 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "No filter connect to DSCMB\n");
2105 goto MDrv_DSCMB2_GetPidSlotMapIndex_FAIL;
2106 }
2107
2108 DSCMB_UNLOCK(_s32DscMutexId);
2109 return u32FltId;
2110
2111 MDrv_DSCMB2_GetPidSlotMapIndex_FAIL:
2112 DSCMB_UNLOCK(_s32DscMutexId);
2113 return DRV_DSCMB_FLT_NULL;
2114
2115 }
2116
_MDrv_DSCMB2_IsKTEValid(MS_U32 u32FltId,DSCMB_Key_Type eKeyType)2117 MS_BOOL _MDrv_DSCMB2_IsKTEValid(MS_U32 u32FltId, DSCMB_Key_Type eKeyType)
2118 {
2119 DSCMB_INIT_CHECK(FALSE);
2120
2121 MS_U32 KeyStatus = 0;
2122
2123 DSCMB_LOCK(_s32DscMutexId);
2124
2125
2126 if(_u32PidFlt2Dscmb[u32FltId].u8DscmbId != HAL_DSCMB_KTE_MAX)
2127 {
2128 #ifdef FLEXIBLE_PIDSLOTMAP
2129 HAL_DSCMB_KTE_GetStatus(_u32PidFlt2Dscmb[u32FltId].u8DscmbId, eKeyType, &KeyStatus);
2130 #else
2131 HAL_DSCMB_KTE_GetStatus(u32FltId, eKeyType, &KeyStatus);
2132 #endif /* FLEXIBLE_PIDSLOTMAP */
2133 }
2134
2135 DSCMB_UNLOCK(_s32DscMutexId);
2136
2137 return (KeyStatus & DSCMB_KTE_VALID)?TRUE:FALSE;
2138 }
2139
2140
_MDrv_DSCMB2_SetTSPCAVid(DSCMB_TSIF eSrcTSIf,MS_U32 u32CAVid)2141 MS_BOOL _MDrv_DSCMB2_SetTSPCAVid(DSCMB_TSIF eSrcTSIf, MS_U32 u32CAVid)
2142 {
2143 DSCMB_INIT_CHECK(FALSE);
2144
2145 MS_U32 u32Tsid = HAL_DSCMB_FltSrc2PktDmx(eSrcTSIf);
2146
2147 HAL_DSCMB_SetTSPCAVid(u32Tsid, u32CAVid);
2148
2149 return TRUE;
2150 }
2151
_MDrv_DSCMB2_SetTSPCADst(MS_U32 u32FltId,MS_U32 u32UpDst,MS_U32 u32LowDst)2152 MS_BOOL _MDrv_DSCMB2_SetTSPCADst(MS_U32 u32FltId, MS_U32 u32UpDst, MS_U32 u32LowDst)
2153 {
2154 DSCMB_INIT_CHECK(FALSE);
2155 MS_U32 u32PidSlotMapNo=0;
2156 DSCMB_LOCK(_s32DscMutexId);
2157
2158 #ifdef FLEXIBLE_PIDSLOTMAP
2159 if(_u32PidFlt2Dscmb[u32FltId].u8DscmbId != HAL_DSCMB_KTE_MAX)
2160 {
2161 u32PidSlotMapNo =_u32PidFlt2Dscmb[u32FltId].u8DscmbId;
2162 }
2163 #else
2164 u32PidSlotMapNo = u32FltId;
2165 #endif
2166
2167 _u32PidFlt2Dscmb[u32FltId].u8CaDestUpp = u32UpDst;
2168 _u32PidFlt2Dscmb[u32FltId].u8CaDestLow = u32LowDst;
2169 HAL_DSCMB_SetTSPCADst_PidSlotMap(u32FltId, u32UpDst, u32LowDst, u32PidSlotMapNo);
2170
2171 DSCMB_UNLOCK(_s32DscMutexId);
2172 return TRUE;
2173 }
2174
_MDrv_DSCMB2_DualPath_Enable(MS_U32 u32EngId,MS_U32 u32FltId)2175 MS_BOOL _MDrv_DSCMB2_DualPath_Enable(MS_U32 u32EngId, MS_U32 u32FltId)
2176 {
2177 DSCMB_INIT_CHECK(FALSE);
2178 MS_BOOL bRet = FALSE;
2179
2180 DSCMB_LOCK(_s32DscMutexId);
2181 if(_u32PidFlt2Dscmb[u32FltId].u8DscmbId != HAL_DSCMB_KTE_MAX)
2182 {
2183 #ifdef FLEXIBLE_PIDSLOTMAP
2184 bRet = HAL_DSCMB_PidIdx_DualPath(_u32PidFlt2Dscmb[u32FltId].u8DscmbId, TRUE); //enable small switch pid_no dual path
2185 #else
2186 bRet = HAL_DSCMB_PidIdx_DualPath(u32FltId, TRUE);
2187 #endif /* FLEXIBLE_PIDSLOTMAP */
2188 }
2189 else
2190 {
2191 bRet = FALSE;
2192 }
2193
2194 DSCMB_UNLOCK(_s32DscMutexId);
2195 return bRet;
2196 }
2197
_MDrv_DSCMB2_DualPath_Disable(MS_U32 u32EngId,MS_U32 u32FltId)2198 MS_BOOL _MDrv_DSCMB2_DualPath_Disable(MS_U32 u32EngId, MS_U32 u32FltId)
2199 {
2200 DSCMB_INIT_CHECK(FALSE);
2201 MS_BOOL bRet = FALSE;
2202
2203 DSCMB_LOCK(_s32DscMutexId);
2204
2205 if(_u32PidFlt2Dscmb[u32FltId].u8DscmbId != HAL_DSCMB_KTE_MAX)
2206 {
2207 #ifdef FLEXIBLE_PIDSLOTMAP
2208 bRet = HAL_DSCMB_PidIdx_DualPath(_u32PidFlt2Dscmb[u32FltId].u8DscmbId, FALSE); //disable small switch pid_no dual path
2209 #else
2210 bRet = HAL_DSCMB_PidIdx_DualPath(u32FltId, FALSE);
2211 #endif /* FLEXIBLE_PIDSLOTMAP */
2212 }
2213 else
2214 {
2215 bRet = FALSE;
2216 }
2217
2218 DSCMB_UNLOCK(_s32DscMutexId);
2219 return bRet;
2220 }
2221
_MDrv_DSCMB2_SPD_Enable(DSCMB_TSIF ePvrSrcTSIf)2222 MS_BOOL _MDrv_DSCMB2_SPD_Enable(DSCMB_TSIF ePvrSrcTSIf)
2223 {
2224 DSCMB_INIT_CHECK(FALSE);
2225
2226 MS_U32 u32Tsif = HAL_DSCMB_FltSrc2TSIF(ePvrSrcTSIf);
2227
2228 if( u32Tsif >= E_HAL_DSCMB_TSIF_NUM)
2229 {
2230 DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING,"Not support.\n");
2231 return FALSE;
2232 }
2233
2234 HAL_DSCMB_SPD_Enable(u32Tsif);
2235 HAL_DSCMB_SPD_Reset(u32Tsif);
2236
2237 return TRUE;
2238 }
2239
_MDrv_DSCMB2_SPD_Disable(DSCMB_TSIF ePvrSrcTSIf)2240 MS_BOOL _MDrv_DSCMB2_SPD_Disable(DSCMB_TSIF ePvrSrcTSIf)
2241 {
2242 DSCMB_INIT_CHECK(FALSE);
2243
2244 MS_U32 u32Tsif = HAL_DSCMB_FltSrc2TSIF(ePvrSrcTSIf);
2245
2246 if( u32Tsif >= E_HAL_DSCMB_TSIF_NUM)
2247 {
2248 DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING,"Not support.\n");
2249 return FALSE;
2250 }
2251
2252 HAL_DSCMB_SPD_Disable(u32Tsif);
2253 HAL_DSCMB_SPD_Reset(u32Tsif);
2254
2255 return TRUE;
2256 }
2257
MDrv_DSCMB2_SPS_Enable(DSCMB_CAPVR_MODE eCaMode)2258 MS_BOOL MDrv_DSCMB2_SPS_Enable (DSCMB_CAPVR_MODE eCaMode)
2259 {
2260 DSCMB_INIT_CHECK(FALSE);
2261
2262 MS_U32 u32ProgId = HAL_DSCMB_GetProgId(eCaMode);
2263
2264 return HAL_DSCMB_Cipher_SPS_Enable(u32ProgId, TRUE);
2265 }
2266
MDrv_DSCMB2_SPS_Disable(DSCMB_CAPVR_MODE eCaMode)2267 MS_BOOL MDrv_DSCMB2_SPS_Disable (DSCMB_CAPVR_MODE eCaMode)
2268 {
2269 DSCMB_INIT_CHECK(FALSE);
2270
2271 MS_U32 u32ProgId = HAL_DSCMB_GetProgId(eCaMode);
2272
2273 return HAL_DSCMB_Cipher_SPS_Enable(u32ProgId, FALSE);
2274 }
2275
2276 /*//////////////////////////////////////////////////////////////////////
2277
2278 Arg: ePvrSrcTSIf, need to identify with TSP DMX_TSIF when use this function
2279
2280 //////////////////////////////////////////////////////////////////////*/
_MDrv_DSCMB2_CAPVR_FlowSet(MS_U32 u32EngId,DSCMB_CAPVR_MODE eCaMode,DSCMB_TSIF ePvrSrcTsif)2281 MS_BOOL _MDrv_DSCMB2_CAPVR_FlowSet(MS_U32 u32EngId, DSCMB_CAPVR_MODE eCaMode, DSCMB_TSIF ePvrSrcTsif)
2282 {
2283 DSCMB_INIT_CHECK(FALSE);
2284
2285 MS_U32 u32Tsid = HAL_DSCMB_FltSrc2PktDmx(ePvrSrcTsif); //genereate from ePvrSrcTSIF
2286 MS_U32 u32CaVid = HAL_DSCMB_GetCAVid();
2287 MS_U32 u32Channel = HAL_DSCMB_GetChannlId(ePvrSrcTsif);
2288 MS_U32 u32ProgId = HAL_DSCMB_GetProgId(eCaMode);
2289
2290 HAL_DSCMB_Cipher_Output_Ctrl(u32ProgId, u32Channel, TRUE, FALSE, u32Tsid, u32CaVid);
2291 return TRUE;
2292 }
2293
_MDrv_DSCMB2_SetPidPair(MS_U32 u32FltIdPri,MS_U32 u32FltIdSec)2294 MS_BOOL _MDrv_DSCMB2_SetPidPair(MS_U32 u32FltIdPri, MS_U32 u32FltIdSec)
2295 {
2296 DSCMB_INIT_CHECK(FALSE);
2297
2298 DSCMB_LOCK(_s32DscMutexId);
2299
2300 if(!HAL_DSCMB_PidFlt_SetPidPair(u32FltIdPri, u32FltIdSec) )
2301 {
2302 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Set Pid Pair Fail\n");
2303 goto MDrv_DSCMB2_SetPidPair_FAIL;
2304 }
2305
2306 DSCMB_UNLOCK(_s32DscMutexId);
2307 return TRUE;
2308
2309 MDrv_DSCMB2_SetPidPair_FAIL:
2310 DSCMB_UNLOCK(_s32DscMutexId);
2311 return FALSE;
2312 }
2313
_MDrv_DSCMB2_ClearPidPair(MS_U32 u32FltIdPri,MS_U32 u32FltIdSec)2314 MS_BOOL _MDrv_DSCMB2_ClearPidPair(MS_U32 u32FltIdPri, MS_U32 u32FltIdSec)
2315 {
2316 DSCMB_INIT_CHECK(FALSE);
2317
2318 DSCMB_LOCK(_s32DscMutexId);
2319
2320 if(!HAL_DSCMB_PidFlt_ClearPidPair(u32FltIdPri, u32FltIdSec) )
2321 {
2322 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Clear Pid Pair Fail\n");
2323 goto MDrv_DSCMB2_Clear_FAIL;
2324 }
2325
2326 DSCMB_UNLOCK(_s32DscMutexId);
2327 return TRUE;
2328
2329 MDrv_DSCMB2_Clear_FAIL:
2330 DSCMB_UNLOCK(_s32DscMutexId);
2331 return FALSE;
2332 }
2333
2334
2335 //----------------------------------------------------------------------//
2336 // Old Interface for compatibility //
2337 //----------------------------------------------------------------------//
_MDrv_DSCMB2_FltTypeSet(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Type DscmbType)2338 MS_BOOL _MDrv_DSCMB2_FltTypeSet(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Type DscmbType)
2339 {
2340 DSCMB_INIT_CHECK(FALSE);
2341
2342 DSCMB_ASSERT(u32EngId == 0, "EngId input error", FALSE);
2343 DSCMB_ASSERT(u32DscmbId < HAL_DSCMB_KTE_MAX, "DscmbId input error", FALSE);
2344 DSCMB_ASSERT(DscmbType <= E_DSCMB_TYPE_CSA_CONF, "Dscmb Type input error", FALSE);
2345
2346 stDscmbTspMap* pMap = NULL;
2347
2348 DSCMB_MainAlgo_Type eAlgo = E_DSCMB_MAIN_ALGO_AES;
2349 DSCMB_SubAlgo_Type eSubAlgo = E_DSCMB_SUB_ALGO_NONE;
2350 DSCMB_ResSBAlgo_Type eRes = E_DSCMB_RESSB_ALGO_NONE;
2351 DSCMB_ResSBAlgo_Type eSB = E_DSCMB_RESSB_ALGO_NONE;
2352
2353 pMap = &DscmbTspMap[u32EngId][u32DscmbId];
2354
2355 switch (DscmbType)
2356 {
2357 case E_DSCMB_TYPE_CSA:
2358 eAlgo = E_DSCMB_MAIN_ALGO_CSA2;
2359 break;
2360 case E_DSCMB_TYPE_CSA_CONF:
2361 eAlgo = E_DSCMB_MAIN_ALGO_CSA2_CONF;
2362 break;
2363 case E_DSCMB_TYPE_NSA_AS_ESA:
2364 //[FIXME] Ask Designer to update this setting.
2365 eAlgo = E_DSCMB_MAIN_ALGO_CSA2 ;
2366 break;
2367 case E_DSCMB_TYPE_DES:
2368 eAlgo = E_DSCMB_MAIN_ALGO_DES ;
2369 break;
2370 case E_DSCMB_TYPE_AES: // AES - CBC
2371 eAlgo = E_DSCMB_MAIN_ALGO_AES ;
2372 eSubAlgo = E_DSCMB_SUB_ALGO_CBC ;
2373 break;
2374 case E_DSCMB_TYPE_AES_ECB: // AES ECB
2375 eAlgo = E_DSCMB_MAIN_ALGO_AES ;
2376 eSubAlgo = E_DSCMB_SUB_ALGO_ECB ;
2377 break;
2378 case E_DSCMB_TYPE_AES_CTR:
2379 eAlgo = E_DSCMB_MAIN_ALGO_AES ;
2380 eSubAlgo = E_DSCMB_SUB_ALGO_CTR ;
2381 eRes = E_DSCMB_RESSB_ALGO_CTR ;
2382 eSB = E_DSCMB_RESSB_ALGO_CTR ;
2383 break;
2384 case E_DSCMB_TYPE_AES_SCTE52: //AES - SCTE 52 - CBC
2385 eAlgo = E_DSCMB_MAIN_ALGO_AES ;
2386 eSubAlgo = E_DSCMB_SUB_ALGO_CBC ;
2387 eRes = E_DSCMB_RESSB_ALGO_SCTE52 ;
2388 eSB = E_DSCMB_RESSB_ALGO_SCTE52 ;
2389 break;
2390 case E_DSCMB_TYPE_TDES_ECB:
2391 eAlgo = E_DSCMB_MAIN_ALGO_TDES ;
2392 eSubAlgo = E_DSCMB_SUB_ALGO_ECB ;
2393 break;
2394 case E_DSCMB_TYPE_TDES_SCTE52:
2395 eAlgo = E_DSCMB_MAIN_ALGO_TDES ;
2396 eSubAlgo = E_DSCMB_SUB_ALGO_CBC ;
2397 eRes = E_DSCMB_RESSB_ALGO_SCTE52 ;
2398 eSB = E_DSCMB_RESSB_ALGO_SCTE52 ;
2399 break;
2400 case E_DSCMB_TYPE_SYN_AES:
2401 eAlgo = E_DSCMB_MAIN_ALGO_AES ;
2402 eSubAlgo = E_DSCMB_SUB_ALGO_LEADING_CLEAR ;
2403 break;
2404 case E_DSCMB_TYPE_MULTI2: //[FIXME] check setting
2405 eAlgo = E_DSCMB_MAIN_ALGO_MULTI2 ;
2406 eSubAlgo = E_DSCMB_SUB_ALGO_CBC ;
2407 eRes = E_DSCMB_RESSB_ALGO_SCTE52 ;
2408 eSB = E_DSCMB_RESSB_ALGO_CLR ;
2409 break;
2410 case E_DSCMB_TYPE_CSA3:
2411 eAlgo = E_DSCMB_MAIN_ALGO_CSA3 ;
2412 break;
2413 default:
2414 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Invalid Algorithm Type\n");
2415 return FALSE;
2416 }
2417
2418 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Algo info %d %d %d %d %d \n", pMap->bDscmb, eAlgo, eSubAlgo, eRes, eSB);
2419
2420 DSCMB_Algo_Cfg stAlgoConfig =
2421 {
2422 .eMainAlgo= eAlgo,
2423 .eSubAlgo = eSubAlgo,
2424 .eResAlgo = eRes,
2425 .eSBAlgo = eSB,
2426 .bDecrypt = pMap->bDscmb
2427 };
2428
2429 DSCMB_FSCB eFSCB = ((stAlgoConfig.bDecrypt == TRUE)?DSCMB_FSCB_CLEAR : DSCMB_FSCB_UNCHG);
2430
2431 if(FALSE == _MDrv_DSCMB2_EngSetAlgo (u32EngId, u32DscmbId, E_DSCMB_ENG_ESA, stAlgoConfig) )
2432 {
2433 return FALSE;
2434 }
2435
2436 if(FALSE == _MDrv_DSCMB2_EngSetSwitch (0, u32DscmbId, 0, E_DSCMB_ENG_ESA))
2437 {
2438 return FALSE;
2439 }
2440
2441 if(FALSE == _MDrv_DSCMB2_EngSetFSCB (0, u32DscmbId, eFSCB))
2442 {
2443 return FALSE;
2444 }
2445
2446 return TRUE;
2447 }
2448
_MDrv_DSCMB2_FltKeySet(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Key_Type eKeyType,MS_U8 * pu8Key)2449 MS_BOOL _MDrv_DSCMB2_FltKeySet(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Key_Type eKeyType, MS_U8* pu8Key)
2450 {
2451 return _MDrv_DSCMB2_EngSetKey (u32EngId, u32DscmbId, E_DSCMB_ENG_ESA, eKeyType, pu8Key);
2452 }
2453
_MDrv_DSCMB2_FltIVSet(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Key_Type eKeyType,MS_U8 * pu8IV)2454 MS_BOOL _MDrv_DSCMB2_FltIVSet(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Key_Type eKeyType, MS_U8* pu8IV)
2455 {
2456 return _MDrv_DSCMB2_EngSetIV (u32EngId, u32DscmbId, eKeyType, pu8IV);
2457 }
2458
_MDrv_DSCMB2_FltKeyReset(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Key_Type eKeyType)2459 MS_BOOL _MDrv_DSCMB2_FltKeyReset(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Key_Type eKeyType)
2460 {
2461 return _MDrv_DSCMB2_EngResetKey(u32EngId, u32DscmbId, E_DSCMB_ENG_ESA, eKeyType);
2462 }
2463
_MDrv_DSCMB2_FltDscmb(MS_U32 u32EngId,MS_U32 u32DscmbId,MS_BOOL bDscmb)2464 MS_BOOL _MDrv_DSCMB2_FltDscmb(MS_U32 u32EngId, MS_U32 u32DscmbId, MS_BOOL bDscmb)
2465 {
2466 DSCMB_INIT_CHECK(FALSE);
2467
2468 stDscmbTspMap* pMap = NULL;
2469 DSCMB_LOCK(_s32DscMutexId);
2470
2471 pMap = &DscmbTspMap[u32EngId][u32DscmbId];
2472 pMap->bDscmb = bDscmb ;
2473
2474 DSCMB_UNLOCK(_s32DscMutexId);
2475
2476 return TRUE ;
2477 }
2478
2479 #if !(defined(MSOS_TYPE_OPTEE) || defined(MSOS_TYPE_NUTTX))
_MDrv_DSCMB2_FltConnectPid(MS_U32 u32EngId,MS_U32 u32DscmbId,MS_U32 u32Pid)2480 MS_BOOL _MDrv_DSCMB2_FltConnectPid(MS_U32 u32EngId, MS_U32 u32DscmbId, MS_U32 u32Pid)
2481 {
2482 DSCMB_INIT_CHECK(FALSE);
2483
2484 MS_U32 j = 0;
2485 MS_BOOL bConnected = FALSE;
2486
2487 DSCMB_ASSERT_AND_RETURN(TRUE == DscmbTspMap[u32EngId][u32DscmbId].bUsed);
2488
2489 for(j = 1 ; j < HAL_DSCMB_PIDFLT_NUM; j ++)
2490 {
2491 if(HAL_DSCMB_PidFlt_GetPid(j) == u32Pid)
2492 {
2493 if(_MDrv_DSCMB2_FltConnectFltId(u32EngId, u32DscmbId, j) == FALSE)
2494 {
2495 DSCMB_ASSERT_AND_RETURN(0);
2496 return FALSE;
2497 }
2498 bConnected = TRUE;
2499 }
2500 }
2501
2502 return bConnected;
2503
2504 }
2505
2506
_MDrv_DSCMB2_FltDisconnectPid_Ex(MS_U32 u32EngId,MS_U32 u32DscmbId,MS_U32 u32Pid)2507 MS_BOOL _MDrv_DSCMB2_FltDisconnectPid_Ex(MS_U32 u32EngId, MS_U32 u32DscmbId, MS_U32 u32Pid)
2508 {
2509 DSCMB_INIT_CHECK(FALSE);
2510
2511 MS_U32 j = 0;
2512 MS_BOOL bDisconnected = FALSE;
2513
2514 DSCMB_ASSERT_AND_RETURN(TRUE == DscmbTspMap[u32EngId][u32DscmbId].bUsed);
2515
2516 for(j = 1 ; j < HAL_DSCMB_PIDFLT_NUM; j ++)
2517 {
2518 if(HAL_DSCMB_PidFlt_GetPid(j) == u32Pid)
2519 {
2520 if(_MDrv_DSCMB2_FltDisconnectFltId(u32EngId, u32DscmbId, j) == FALSE)
2521 {
2522 DSCMB_ASSERT_AND_RETURN(0);
2523 return FALSE;
2524 }
2525 bDisconnected = TRUE;
2526 }
2527 }
2528
2529 return bDisconnected;
2530
2531 }
2532 #endif//MSOS_TYPE_NUTTX , MSOS_TYPE_NUTTX
2533
2534 //------------------------------------- ------------------//
2535 //----------------------Keyladder API -----------------------//
2536 //-------------------------------------------------------//
2537 //--------------------------------------------------------------------------------------------------
2538 /// An atomic Key ladder function for Key generation, including common KL use cases.
2539 /// Thread safe for cuncurrent usage.
2540 /// @param KLCfg\b IN: KL execution setting for target key generation
2541 /// @param ACPU_Out\b IN: A 16 bytes array pointer for Acpu key output.
2542 /// @param u32Status\b IN: Key ladder running status
2543 /// @return TRUE - Success
2544 /// @return FALSE - Failure
2545 //--------------------------------------------------------------------------------------------------
_MDrv_DSCMB2_KLadder_AtomicExec(DSCMB_KLCfg_All * KLCfg,MS_U8 * ACPU_Out,DSCMB_KL_Status * u32Status)2546 MS_BOOL _MDrv_DSCMB2_KLadder_AtomicExec(DSCMB_KLCfg_All* KLCfg , MS_U8 *ACPU_Out, DSCMB_KL_Status* u32Status )
2547 {
2548 KL_INIT_CHECK(FALSE);
2549 DSCMB_ASSERT(KLCfg != NULL, "KLCfg input error", FALSE);
2550 DSCMB_ASSERT(u32Status != NULL, "u32Status input error", FALSE);
2551
2552 MS_U32 i = 0;
2553 MS_U32 u32ErrMsg = 0;
2554 // MS_BOOL bKeepRound=FALSE;
2555 MS_U32 u32FltId = 0;
2556 MS_U32 u32Field = 0;
2557 MS_U32 u32CAVid = KLCfg->u32CAVid;
2558
2559 DSCMB_KL_SelEng eKLEng = KLCfg->eKLSel;
2560 DSCMB_KLDst eKLDst = KLCfg->eDst & (~E_DSCMB_KL_DST_KT_PIDSLOTMAP_ENABLE);
2561 DSCMB_KLSrc eKLSrc = KLCfg->eSrc & (~E_DSCMB_KL_SRC_KDF_ENABLE);
2562 MS_BOOL bEnableKDF = ((KLCfg->eSrc & E_DSCMB_KL_SRC_KDF_ENABLE) == E_DSCMB_KL_SRC_KDF_ENABLE);
2563 MS_BOOL bEnablePidslotmap = ((KLCfg->eDst & E_DSCMB_KL_DST_KT_PIDSLOTMAP_ENABLE) == E_DSCMB_KL_DST_KT_PIDSLOTMAP_ENABLE);
2564 DSCMB_Key_Type eKeyType = KLCfg->eKeyType & (~E_DSCMB_KEY_FSCB_ENABLE);
2565 #ifdef ENABLE_KEY_FSCB
2566 MS_BOOL bEnableKeyFscb = ((KLCfg->eKeyType & E_DSCMB_KEY_FSCB_ENABLE) == E_DSCMB_KEY_FSCB_ENABLE);
2567 #endif
2568 MS_BOOL bKLDstSecure = ((KLCfg->eKeyType & E_DSCMB_KEY_SECURE_KEYS_ENABLE) == E_DSCMB_KEY_SECURE_KEYS_ENABLE);
2569
2570 if(_MDrv_DSCMB2_KLadder_Init () == FALSE)
2571 {
2572 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Keyladder Init Fail\n");
2573 return FALSE;
2574 }
2575
2576 MDrv_DSCMB_KLadder_Lock();
2577 if ( FALSE == HAL_DSCMB_KL_HW_SEM_Lock(eKLEng, DSCMB_KL_WAIT_THRESHOLD)) //TODO: fix constant value
2578 {
2579 *u32Status = KL_STATUS_WAIT_KL_READY_TIMEOUT;
2580 goto KL_Fail;
2581 }
2582 *u32Status = KL_STATUS_KEY_OK ;
2583
2584 ///translate cavid to Default CAVID if user set input cavid to 0x0
2585 if(u32CAVid == 0)
2586 {
2587 u32CAVid = DEFAULT_CAVID;
2588 }
2589
2590 /////////////// Check Source and acpu data ////////////////////
2591 if ((E_DSCMB_KL_SRC_ACPU == eKLSrc) && (NULL == KLCfg->u8KeyACPU))
2592 {
2593 *u32Status = KL_STATUS_ACPU_KEY_NULL;
2594 goto KL_Fail;
2595 }
2596
2597 /////////////// Check KL level ////////////////////
2598 if((KLCfg->u32Level >5) && (KLCfg->u32Level != 9) && (KLCfg->u32Level != 0xD))
2599 {
2600 //bKeepRound = TRUE ;
2601 *u32Status = KL_STATUS_INVALID_INPUT_LEVEL;
2602 goto KL_Fail;
2603 }
2604 else if(( 0 == KLCfg->u32Level ) && (0==(DSCMB_KL_DST_CLASS_DMA & eKLDst)))
2605 {
2606 *u32Status = KL_STATUS_INVALID_INPUT_LEVEL;
2607 goto KL_Fail;
2608 }
2609
2610 ////////////// check Key destination ///////////////
2611 /// Compatible and translate old version to new version
2612 if( ((eKLDst & 0xF0) == 0) && ( (eKLDst & 0x0F) > 0 )) //OLD Destination
2613 {
2614 switch(eKLDst)
2615 {
2616 case E_DSCMB_KL_DST_ACPU:
2617 eKLDst = E_DSCMB_KL_DST_CPU_ACPU;
2618 break;
2619 case E_DSCMB_KL_DST_KT_NSA:
2620 eKLDst = E_DSCMB_KL_DST_KT_ESA;
2621 break;
2622 case E_DSCMB_KL_DST_DMA_AES:
2623 eKLDst = E_DSCMB_KL_DST_DMA_SK0;
2624 break;
2625 case E_DSCMB_KL_DST_DMA_TDES:
2626 eKLDst = E_DSCMB_KL_DST_DMA_SK0;
2627 break;
2628 case E_DSCMB_KL_DST_PRIVATE0:
2629 eKLDst = E_DSCMB_KL_DST_PRIVATE_0;
2630 break;
2631 case E_DSCMB_KL_DST_PRIVATE1:
2632 eKLDst = E_DSCMB_KL_DST_PRIVATE_1;
2633 break;
2634 case E_DSCMB_KL_DST_PRIVATE2:
2635 eKLDst = E_DSCMB_KL_DST_PRIVATE_2;
2636 break;
2637 default:
2638 ;
2639 }
2640 }
2641
2642 // If destination is key table, and use dscmbId to get pidslotmap entry,
2643 // need to check descrambler driver init
2644 if (DSCMB_KL_DST_CLASS_KT & eKLDst)
2645 {
2646 if(bEnablePidslotmap == FALSE)
2647 {
2648 DSCMB_INIT_CHECK(FALSE);
2649 }
2650 }
2651
2652 if (E_DSCMB_KL_DST_CPU_ACPU == eKLDst)
2653 {
2654 //KL to ACPU
2655 if(NULL == ACPU_Out)
2656 {
2657 *u32Status = KL_STATUS_ACPU_OUTKEY_NULL;
2658 goto KL_Fail;
2659 }
2660 }
2661 else if (DSCMB_KL_DST_CLASS_KT & eKLDst)
2662 {
2663 //KL to KT
2664 if(bEnablePidslotmap)
2665 {
2666 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Keyladder destination KT class\n");
2667 u32FltId = KLCfg->u32DscID;
2668 }
2669 else
2670 {
2671 if ( FALSE == DscmbTspMap[KLCfg->u32EngID][KLCfg->u32DscID].bUsed )
2672 {
2673 //The keyslot is not allocated for the DSCMB ID
2674 *u32Status = KL_STATUS_IVALID_DSCMB_ID;
2675 goto KL_Fail;
2676 }
2677 if( 0 == DscmbTspMap[KLCfg->u32EngID][KLCfg->u32DscID].u32PidFltIdNum )
2678 {
2679 //No pid filter is connected to the DSCMB ID
2680 *u32Status = KL_STATUS_IVALID_DSCMB_ID;
2681 goto KL_Fail;
2682 }
2683
2684 // Get Filter ID
2685 if(FALSE == _DSCMB_Dscmb2Flt(KLCfg->u32DscID, &u32FltId))
2686 {
2687 *u32Status = KL_STATUS_IVALID_DSCMB_ID;
2688 goto KL_Fail;
2689 }
2690
2691 }
2692 // Get Field
2693
2694 }
2695 else if (DSCMB_KL_DST_CLASS_DMA & eKLDst)
2696 {
2697 //KL to DMA
2698 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Keyladder destination DMA class\n");
2699 }
2700 else if(DSCMB_KL_DST_CLASS_PVT &eKLDst)
2701 {
2702 //KL to PVT
2703 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Keyladder destination Private Key class\n");
2704 }
2705 else if(DSCMB_KL_DST_CLASS_TSIO & eKLDst)
2706 {
2707 //KL to TSIO
2708 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Keyladder destination TSIO\n");
2709 u32FltId = KLCfg->u32DscID; //TSIO service id
2710 }
2711 else if(DSCMB_KL_DST_CLASS_CFB& eKLDst)
2712 {
2713 //KL to CFB
2714 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Keyladder destination CFB\n");
2715 }
2716 else
2717 {
2718 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Unknown Keyladder destination\n");
2719 *u32Status = KL_STATUS_KL_INPUT_NULL;
2720 goto KL_Fail;
2721 }
2722
2723 //Check KeyLadder Input
2724 if ((KLCfg->u32Level != 0) && (NULL == KLCfg->pu8KeyKLIn))
2725 {
2726 *u32Status = KL_STATUS_KL_INPUT_NULL;
2727 goto KL_Fail;
2728 }
2729
2730 // TODO: Here need to check key property if support KDF or not
2731
2732 if((E_DSCMB_KL_TYPE_INF == _u8KLPreLevel) || ((E_DSCMB_KL_TYPE_INF == _u8KLPreLevel) && (E_DSCMB_KL_TYPE_LV1 == KLCfg->u32Level)))
2733 {
2734 _u8KLPreLevel = KLCfg->u32Level;
2735 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Keyladder keep round and not reset \n");
2736 }
2737 else
2738 {
2739 _u8KLPreLevel = KLCfg->u32Level;
2740 HAL_DSCMB_KL_Reset(eKLEng);
2741 HAL_DSCMB_KL_KDF_Disable(eKLEng);
2742 }
2743
2744 if(E_DSCMB_KL_SRC_ACPU == eKLSrc)
2745 {
2746 HAL_DSCMB_KL_ACPURootKey(eKLEng, KLCfg->u8KeyACPU);
2747 }
2748
2749 DRVDSCMB2_DBG(DSCMB2_DBGLV_INFO, "u32CAVid=%X\n", u32CAVid);
2750 //FIXME: If Key from OTP, should we set usage & entropy ?
2751 if(DSCMB_KL_DST_CLASS_TSIO & eKLDst)
2752 {
2753 HAL_DSCMB_KL_KeyProp( eKLEng, u32CAVid, 0 , /*Usage*/ 1 /*Entropy*/);
2754 }
2755 else
2756 {
2757 HAL_DSCMB_KL_KeyProp( eKLEng, u32CAVid, 0 , /*Usage*/ 0 /*Entropy*/);
2758 }
2759
2760 //Enable KDF
2761 if(bEnableKDF)
2762 {
2763 HAL_DSCMB_KL_KDF_Enable( eKLEng, KLCfg->stKDF.eKDFType, KLCfg->stKDF.u16AppId, KLCfg->stKDF.eHWKeyId);
2764 }
2765
2766 // Set KL Level input //
2767 if(E_DSCMB_KL_TYPE_INF == KLCfg->u32Level) //Keep round, 1 stage
2768 {
2769 HAL_DSCMB_KL_Input(eKLEng, 0, KLCfg->pu8KeyKLIn);
2770 }
2771 else if(E_DSCMB_KL_TYPE_S5 == KLCfg->u32Level) //SMI Keyladder
2772 {
2773 for( i = 0 ; i < 5 ; i ++ )
2774 {
2775 HAL_DSCMB_KL_Input(eKLEng, (4 - i), KLCfg->pu8KeyKLIn+(16*i));
2776 }
2777 }
2778 else if(KLCfg->u32Level <= 5) //0~5 level keyladder
2779 {
2780 for( i = 0 ; i < KLCfg->u32Level ; i ++ )
2781 {
2782 HAL_DSCMB_KL_Input(eKLEng, (KLCfg->u32Level-i-1), KLCfg->pu8KeyKLIn+(16*i));
2783 }
2784 }
2785 else
2786 {
2787 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Unknown Keyladder type(level) setting\n");
2788 *u32Status = KL_STATUS_INVALID_INPUT_LEVEL;
2789 goto KL_Fail;
2790 }
2791
2792 // Set KL Ctrl
2793 if(FALSE == HAL_DSCMB_KL_Ctrl(eKLEng, KLCfg->eAlgo, KLCfg->u32Level, eKLSrc, eKLDst))
2794 {
2795 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Invalid Keyladder control setting\n");
2796 *u32Status = KL_STATUS_INVALID_INPUT_LEVEL;
2797 goto KL_Fail;
2798 }
2799
2800 //KL to secure key slot
2801 HAL_DSCMB_KL_DstSecure(eKLEng, bKLDstSecure);
2802
2803 if (DSCMB_KL_DST_CLASS_CPU & eKLDst)
2804 {
2805 // KL flow for ACPU output //
2806 HAL_DSCMB_KL_KeyBus(eKLEng,
2807 0, /*For Dst KT*/
2808 0, /*For Dst KT*/
2809 0, /*For Dst KT*/
2810 0); /*For Dst DMA*/
2811 }
2812 else if (DSCMB_KL_DST_CLASS_DMA & eKLDst)
2813 {
2814 // KL flow for output to CryptoDMA //
2815 HAL_DSCMB_KL_KeyBus(eKLEng,
2816 0, /*For Dst KT*/
2817 0, /*For Dst KT*/
2818 0, /*For Dst KT*/
2819 eKLDst); /*For Dst DMA*/
2820 }
2821 else if (DSCMB_KL_DST_CLASS_KT & eKLDst)
2822 {
2823 #ifdef ENABLE_KEY_FSCB
2824 if(bEnableKeyFscb){
2825 // KL flow for output to KTE (with KeyFSCB) //
2826 HAL_DSCMB_KL_KeyBus_Ex(eKLEng,
2827 u32FltId, /*For Dst KT*/
2828 u32Field, /*For Dst KT*/
2829 eKeyType, /*For Dst KT*/
2830 eKLDst, /*For Dst KT*/
2831 KLCfg->eFSCB); /*For Dst KT*/
2832 }
2833 else{
2834 #endif
2835 // KL flow for output to KTE //
2836 HAL_DSCMB_KL_KeyBus(eKLEng,
2837 u32FltId, /*For Dst KT*/
2838 u32Field, /*For Dst KT*/
2839 eKeyType, /*For Dst KT*/
2840 eKLDst); /*For Dst KT*/
2841 #ifdef ENABLE_KEY_FSCB
2842 }
2843 #endif
2844 }
2845 else if (DSCMB_KL_DST_CLASS_PVT & eKLDst)
2846 {
2847 // KL flow for output to PVT //
2848 HAL_DSCMB_KL_KeyBus(eKLEng,
2849 0, /*For Dst KT*/
2850 0, /*For Dst KT*/
2851 0, /*For Dst KT*/
2852 0); /*For Dst DMA*/
2853 }
2854 else if(DSCMB_KL_DST_CLASS_TSIO & eKLDst)
2855 {
2856 // KL flow for output to TSIO //
2857 HAL_DSCMB_KL_KeyBus(eKLEng,
2858 u32FltId, /*For Dst TSIO*/
2859 0, /*For Dst TSIO*/
2860 KLCfg->eKeyType, /*For Dst TSIO*/
2861 eKLDst); /*For Dst TSIO*/
2862 }
2863 else if(DSCMB_KL_DST_CLASS_CFB& eKLDst)
2864 {
2865 // KL flow for output to CFB //
2866 HAL_DSCMB_KL_KeyBus(eKLEng,
2867 0, /*For Dst KT*/
2868 0, /*For Dst KT*/
2869 0, /*For Dst KT*/
2870 eKLDst); /*For Dst CFB*/
2871 }
2872
2873 if(HAL_DSCMB_KL_Start(eKLEng) == FALSE)
2874 {
2875 HAL_DSCMB_KL_ErrMsg(eKLEng, &u32ErrMsg);
2876 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "\033[31m KL error message 0x%X\n\033[m", (unsigned int)u32ErrMsg);
2877 goto KL_Fail;
2878 }
2879
2880 if ((DSCMB_KL_DST_CLASS_SPSSPD & eKLDst) == DSCMB_KL_DST_CLASS_SPSSPD)
2881 {
2882 // KL flow for output to CryptoDMA //
2883 HAL_DSCMB_KL_SP_KeyCtrl(eKLEng, eKLDst);
2884 if(HAL_DSCMB_KL_SP_Start(eKLEng) == FALSE)
2885 {
2886 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "\033[31m KL to SPS SPD Fail\n\033[m");
2887 goto KL_Fail;
2888 }
2889 }
2890
2891 // enable key
2892 if (DSCMB_KL_DST_CLASS_KT & eKLDst)
2893 {
2894 DSCMB_Eng_Type eEngType = E_DSCMB_ENG_ESA;
2895 if(eKLDst == E_DSCMB_KL_DST_KT_ESA )
2896 {
2897 eEngType = E_DSCMB_ENG_ESA;
2898 }
2899 else if(eKLDst == E_DSCMB_KL_DST_KT_LSAS )
2900 {
2901 eEngType = E_DSCMB_ENG_LSAS;
2902 }
2903 else if(eKLDst == E_DSCMB_KL_DST_KT_LSAD )
2904 {
2905 eEngType = E_DSCMB_ENG_LSAD;
2906 }
2907
2908 if (FALSE == HAL_DSCMB_KTE_Key_Ctrl_Ex(u32FltId,
2909 eKeyType,
2910 eEngType,
2911 u32CAVid,
2912 TRUE,
2913 TRUE))
2914 {
2915 *u32Status = KL_STATUS_KL_INPUT_NULL;
2916 goto KL_Fail;
2917 }
2918 }
2919
2920 //Output to ACPU
2921 if (E_DSCMB_KL_DST_CPU_ACPU == eKLDst)
2922 {
2923 MS_U32 u32OutKeySize = 0;
2924 if(KLCfg->eOutsize == E_DSCMB_KL_64_BITS)
2925 {
2926 u32OutKeySize = 8;
2927 }
2928 else if(KLCfg->eOutsize == E_DSCMB_KL_128_BITS)
2929 {
2930 u32OutKeySize = 16;
2931 }
2932 memset(ACPU_Out , 0x0 , u32OutKeySize );
2933 HAL_DSCMB_KL_GetACPUOut(eKLEng,ACPU_Out,u32OutKeySize);
2934 }
2935
2936 HAL_DSCMB_KL_HW_SEM_Unlock(eKLEng);
2937 MDrv_DSCMB_KLadder_Unlock();
2938 return TRUE;
2939
2940 KL_Fail:
2941
2942 HAL_DSCMB_KL_HW_SEM_Unlock(eKLEng);
2943 MDrv_DSCMB_KLadder_Unlock();
2944 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "DSCMB KL Fail = %08X \n",*u32Status);
2945 DSCMB_ASSERT_AND_RETURN(FALSE);
2946
2947 return FALSE;
2948 }
2949
2950 #if 0
2951 //--------------------------------------------------------------------------------------------------
2952 /// An atomic Key ladder function for TCSA3 Key generation.
2953 /// Thread safe for cuncurrent usage.
2954 /// @param KLCfg\b IN: KL execution setting for target key generation
2955 /// @param ACPU_Out\b IN: A 16 bytes array pointer for Acpu key output.
2956 /// @param u32Status\b IN: Key ladder running status
2957 /// @return TRUE - Success
2958 /// @return FALSE - Failure
2959 //--------------------------------------------------------------------------------------------------
2960 MS_BOOL _MDrv_DSCMB2_KLadder_TCSA3(DSCMB_KLCfg_All* KLCfg , MS_U8 *pu8ActCode, MS_U32 u32CHSel,DSCMB_KL_Status* u32Status )
2961 {
2962 DSCMB_INIT_CHECK(FALSE);
2963
2964 MS_U32 i;
2965 *u32Status = KL_STATUS_KEY_OK ;
2966 DSCMB_KL_SelEng eKLEng = E_DSCMB_KL_SEL_CW;
2967 MS_U32 u32FltId = 0;
2968 MS_U32 u32ErrMsg = 0;
2969 MS_U32 u32Step2Level = KLCfg->u32Level-1; /*level - 1*/
2970 MS_BOOL bKDFBusy = TRUE;
2971 DSCMB_Key_Type eKeyType = KLCfg->eKeyType & (~E_DSCMB_KEY_FSCB_ENABLE);
2972 //MS_BOOL bEnableKeyFscb = ((KLCfg->eKeyType & E_DSCMB_KEY_FSCB_ENABLE) == E_DSCMB_KEY_FSCB_ENABLE);
2973
2974 MDrv_DSCMB_KLadder_Lock();
2975
2976 // TODO: This global cavid may not work, dscmb id has its own cavid, use it in the future.
2977 if( E_HAL_DSCMB_CAVID4 != HAL_DSCMB_GetCAVid())
2978 {
2979 *u32Status = KL_STATUS_KL_INPUT_NULL;
2980 goto KL_Fail;
2981 }
2982
2983 if(FALSE == HAL_DSCMB_KL_KDF_Busy(E_DSCMB_KL_SEL_CW, &bKDFBusy))
2984 {
2985 *u32Status = KL_STATUS_KL_INPUT_NULL;
2986 goto KL_Fail;
2987 }
2988 else
2989 {
2990 if(bKDFBusy == TRUE)
2991 {
2992 *u32Status = KL_STATUS_KL_INPUT_NULL;
2993 goto KL_Fail;
2994 }
2995 }
2996
2997 //////////////////////////////////////////////////
2998 ////////////Step 1, KL Output Clear CW to KT ////////
2999 //////////////////////////////////////////////////
3000 HAL_DSCMB_KL_Reset(eKLEng);
3001
3002 for( i = 0 ; i < KLCfg->u32Level ; i ++ )
3003 {
3004 HAL_DSCMB_KL_Input(eKLEng, (KLCfg->u32Level-i-1), KLCfg->pu8KeyKLIn+(16*i));
3005 }
3006
3007 HAL_DSCMB_KL_Ctrl(eKLEng, KLCfg->eAlgo,
3008 KLCfg->u32Level,
3009 KLCfg->eSrc,
3010 E_DSCMB_KL_DST_KT_ESA/*output to KT ESA*/);
3011
3012 // Get Filter ID
3013 if(FALSE == _DSCMB_Dscmb2Flt(KLCfg->u32DscID, &u32FltId))
3014 {
3015 *u32Status = KL_STATUS_IVALID_DSCMB_ID;
3016 goto KL_Fail;
3017 }
3018 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Filter ID %u\n\033[m", u32FltId);
3019
3020 HAL_DSCMB_KL_KeyBus(eKLEng,
3021 u32FltId, /*For Dst KT*/
3022 0, /*For Dst KT*/ /*No use*/
3023 eKeyType, /*For Dst KT*/
3024 E_HAL_DSCMB_KL_DSTKT_ESA); /*For Dst DMA*/
3025
3026 //Enable the key slot
3027 if (FALSE == HAL_DSCMB_KTE_Key_Ctrl(u32FltId,
3028 eKeyType,
3029 E_DSCMB_ENG_ESA,
3030 KLCfg->u32CAVid,
3031 TRUE))
3032 {
3033 *u32Status = KL_STATUS_KL_INPUT_NULL;
3034 goto KL_Fail;
3035 }
3036
3037 if(FALSE == HAL_DSCMB_KL_Start(eKLEng))
3038 {
3039 HAL_DSCMB_KL_ErrMsg(eKLEng, &u32ErrMsg);
3040 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "\033[31m KL error message 0x%X\n\033[m", (unsigned int)u32ErrMsg);
3041 }
3042
3043 //////////////////////////////////////////////////
3044 ////////////Step 2, KL Output to CSSK////////////////
3045 //////////////////////////////////////////////////
3046 HAL_DSCMB_KL_Reset(eKLEng);
3047
3048 // Set KL Level input /*level - 1*/
3049 for( i = 0 ; i < (u32Step2Level) ; i ++ )
3050 {
3051 HAL_DSCMB_KL_Input(eKLEng, (u32Step2Level-i-1), KLCfg->pu8KeyKLIn+(16*i));
3052 }
3053
3054 HAL_DSCMB_KL_KeyBus(eKLEng,
3055 0, /*For Dst KT*/
3056 0, /*For Dst KT*/ /*No use*/
3057 0, /*For Dst KT*/
3058 E_DSCMB_KL_DST_DMA_CSSK); /*For Dst DMA*/
3059
3060 // Set KL Ctrl
3061 HAL_DSCMB_KL_Ctrl(eKLEng, KLCfg->eAlgo,
3062 u32Step2Level, /*level - 1*/
3063 KLCfg->eSrc,
3064 E_DSCMB_KL_DST_DMA_CSSK /*FIXME to CSSK*/);
3065
3066
3067 if(FALSE == HAL_DSCMB_KL_Start(eKLEng))
3068 {
3069 HAL_DSCMB_KL_ErrMsg(eKLEng, &u32ErrMsg);
3070 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "\033[31m KL error message 0x%X\n\033[m", (unsigned int)u32ErrMsg);
3071 }
3072
3073 //////////////////////////////////////////////////
3074 ////////////Step 3, KL Output IV & RK to CSA3 ////////
3075 //////////////////////////////////////////////////
3076 HAL_DSCMB_KL_TCSA3_ActCode(pu8ActCode,16);
3077 HAL_DSCMB_KL_TCSA3_CHSel(u32CHSel);
3078 HAL_DSCMB_KL_TCSA3_Start();
3079
3080 HAL_DSCMB_KL_ErrMsg(eKLEng, &u32ErrMsg);
3081 DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING, "\033[31m KL error message 0x%X\n\033[m", (unsigned int)u32ErrMsg);
3082
3083 if(FALSE == HAL_DSCMB_Cipher_TCSA3(u32CHSel,TRUE))
3084 {
3085 *u32Status = KL_STATUS_IVALID_DSCMB_ID;
3086 goto KL_Fail;
3087 }
3088
3089 MDrv_DSCMB_KLadder_Unlock();
3090 return TRUE;
3091
3092 KL_Fail:
3093
3094
3095 #if 0
3096
3097 i = HAL_DSCMB_KLadder_Status();
3098 if ( i != 0 )
3099 {
3100 //printf("KL Satus = %x \n",i );
3101 *u32Status |= i ;
3102 }
3103
3104 MDrv_DSCMB_KLadder_Stop();
3105 #endif
3106
3107 MDrv_DSCMB_KLadder_Unlock();
3108 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "DSCMB KL Fail = %08X \n",*u32Status);
3109 DSCMB_ASSERT_AND_RETURN(FALSE);
3110 return FALSE;
3111
3112 }
3113 #endif
3114
3115 //--------------------------------------------------------------------------------------------------
3116 /// An ETSI Key ladder function for Key generation, including common KL use cases.
3117 /// Thread safe for cuncurrent usage.
3118 /// @param KLCfg\b IN: KL execution setting for target key generation
3119 /// @param ACPU_Out\b IN: A 16 bytes array pointer for Acpu key output.
3120 /// @param pu8Nonce\b IN: A 16 bytes array pointer for Nonce input
3121 /// @param pu8Response\n OUT: A 16 byte array pointer for Response output
3122 /// @param u32Status\b IN: Key ladder running status
3123 /// @return TRUE - Success
3124 /// @return FALSE - Failure
3125 //--------------------------------------------------------------------------------------------------
_MDrv_DSCMB2_KLadder_ETSI(DSCMB_KLCfg_All * KLCfg,MS_U8 * ACPU_Out,MS_U8 * pu8Nonce,MS_U8 * pu8Response,DSCMB_KL_Status * u32Status)3126 MS_BOOL _MDrv_DSCMB2_KLadder_ETSI(DSCMB_KLCfg_All* KLCfg , MS_U8 *ACPU_Out, MS_U8 *pu8Nonce, MS_U8 *pu8Response, DSCMB_KL_Status* u32Status )
3127 {
3128 KL_INIT_CHECK(FALSE);
3129 DSCMB_ASSERT(KLCfg != NULL, "KLCfg input error", FALSE);
3130 DSCMB_ASSERT(u32Status != NULL, "u32Status input error", FALSE);
3131 DSCMB_ASSERT(pu8Nonce != NULL, "pu8Nonce input error", FALSE);
3132
3133 MS_U32 i = 0;
3134 MS_U32 u32ErrMsg = 0;
3135 MS_U32 u32FltId = 0;
3136 MS_U32 u32Field = 0;
3137 MS_U32 u32CAVid = KLCfg->u32CAVid;
3138
3139 DSCMB_KL_SelEng eKLEng = KLCfg->eKLSel;
3140 DSCMB_KLDst eKLDst = KLCfg->eDst & (~E_DSCMB_KL_DST_KT_PIDSLOTMAP_ENABLE);
3141 DSCMB_KLSrc eKLSrc = KLCfg->eSrc & (~E_DSCMB_KL_SRC_KDF_ENABLE);
3142 MS_BOOL bEnableKDF = ((KLCfg->eSrc & E_DSCMB_KL_SRC_KDF_ENABLE) == E_DSCMB_KL_SRC_KDF_ENABLE);
3143 MS_BOOL bEnablePidslotmap = ((KLCfg->eDst & E_DSCMB_KL_DST_KT_PIDSLOTMAP_ENABLE) == E_DSCMB_KL_DST_KT_PIDSLOTMAP_ENABLE);
3144 DSCMB_Key_Type eKeyType = KLCfg->eKeyType & (~E_DSCMB_KEY_FSCB_ENABLE);
3145 #ifdef ENABLE_KEY_FSCB
3146 MS_BOOL bEnableKeyFscb = ((KLCfg->eKeyType & E_DSCMB_KEY_FSCB_ENABLE) == E_DSCMB_KEY_FSCB_ENABLE);
3147 #endif
3148 MS_BOOL bKLDstSecure = ((KLCfg->eKeyType & E_DSCMB_KEY_SECURE_KEYS_ENABLE) == E_DSCMB_KEY_SECURE_KEYS_ENABLE);
3149
3150 if(_MDrv_DSCMB2_KLadder_Init () == FALSE)
3151 {
3152 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Keyladder Init Fail\n");
3153 return FALSE;
3154 }
3155
3156 MDrv_DSCMB_KLadder_Lock();
3157 if ( FALSE == HAL_DSCMB_KL_HW_SEM_Lock(eKLEng, DSCMB_KL_WAIT_THRESHOLD)) //TODO: fix constant value
3158 {
3159 *u32Status = KL_STATUS_WAIT_KL_READY_TIMEOUT;
3160 goto KL_Fail;
3161 }
3162
3163 *u32Status = KL_STATUS_KEY_OK ;
3164
3165 ///translate cavid to Default CAVID if user set input cavid to 0x0
3166 if(u32CAVid == 0)
3167 {
3168 u32CAVid = DEFAULT_CAVID;
3169 }
3170
3171 /////////////// Check Source and acpu data ////////////////////
3172 if ((E_DSCMB_KL_SRC_ACPU == eKLSrc) && (NULL == KLCfg->u8KeyACPU))
3173 {
3174 *u32Status = KL_STATUS_ACPU_KEY_NULL;
3175 goto KL_Fail;
3176 }
3177
3178 /////////////// Check KL level ////////////////////
3179 if(KLCfg->u32Level != 3) //ETSI keyladder, must be 3 level!
3180 {
3181 *u32Status = KL_STATUS_INVALID_INPUT_LEVEL;
3182 goto KL_Fail;
3183 }
3184
3185 ////////////// check Key destination ///////////////
3186 /// Compatible and translate old version to new version
3187 if( ((eKLDst & 0xF0) == 0) && ( (eKLDst & 0x0F) > 0 )) //OLD Destination
3188 {
3189 switch(eKLDst)
3190 {
3191 case E_DSCMB_KL_DST_ACPU:
3192 eKLDst = E_DSCMB_KL_DST_CPU_ACPU;
3193 break;
3194 case E_DSCMB_KL_DST_KT_NSA:
3195 eKLDst = E_DSCMB_KL_DST_KT_ESA;
3196 break;
3197 case E_DSCMB_KL_DST_DMA_AES:
3198 eKLDst = E_DSCMB_KL_DST_DMA_SK0;
3199 break;
3200 case E_DSCMB_KL_DST_DMA_TDES:
3201 eKLDst = E_DSCMB_KL_DST_DMA_SK0;
3202 break;
3203 case E_DSCMB_KL_DST_PRIVATE0:
3204 eKLDst = E_DSCMB_KL_DST_PRIVATE_0;
3205 break;
3206 case E_DSCMB_KL_DST_PRIVATE1:
3207 eKLDst = E_DSCMB_KL_DST_PRIVATE_1;
3208 break;
3209 case E_DSCMB_KL_DST_PRIVATE2:
3210 eKLDst = E_DSCMB_KL_DST_PRIVATE_2;
3211 break;
3212 default:
3213 ;
3214 }
3215 }
3216
3217 // If destination is key table, and use dscmbId to get pidslotmap entry,
3218 // need to check descrambler driver init
3219 if (DSCMB_KL_DST_CLASS_KT & eKLDst)
3220 {
3221 if(bEnablePidslotmap == FALSE)
3222 {
3223 DSCMB_INIT_CHECK(FALSE);
3224 }
3225 }
3226
3227 if (E_DSCMB_KL_DST_CPU_ACPU == eKLDst)
3228 {
3229 //KL to ACPU
3230 if(NULL == ACPU_Out)
3231 {
3232 *u32Status = KL_STATUS_ACPU_OUTKEY_NULL;
3233 goto KL_Fail;
3234 }
3235 }
3236 else if (DSCMB_KL_DST_CLASS_KT & eKLDst)
3237 {
3238 //KL to KT
3239 if(bEnablePidslotmap)
3240 {
3241 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Keyladder destination KT class\n");
3242 u32FltId = KLCfg->u32DscID;
3243 }
3244 else
3245 {
3246 if ( FALSE == DscmbTspMap[KLCfg->u32EngID][KLCfg->u32DscID].bUsed )
3247 {
3248 //The keyslot is not allocated for the DSCMB ID
3249 *u32Status = KL_STATUS_IVALID_DSCMB_ID;
3250 goto KL_Fail;
3251 }
3252 if( 0 == DscmbTspMap[KLCfg->u32EngID][KLCfg->u32DscID].u32PidFltIdNum )
3253 {
3254 //No pid filter is connected to the DSCMB ID
3255 *u32Status = KL_STATUS_IVALID_DSCMB_ID;
3256 goto KL_Fail;
3257 }
3258
3259 // Get Filter ID
3260 if(FALSE == _DSCMB_Dscmb2Flt(KLCfg->u32DscID, &u32FltId))
3261 {
3262 *u32Status = KL_STATUS_IVALID_DSCMB_ID;
3263 goto KL_Fail;
3264 }
3265
3266 }
3267 // Get Field
3268
3269 }
3270 else if (DSCMB_KL_DST_CLASS_DMA & eKLDst)
3271 {
3272 //KL to DMA
3273 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Keyladder destination DMA class\n");
3274 }
3275 else if(DSCMB_KL_DST_CLASS_PVT &eKLDst)
3276 {
3277 //KL to PVT
3278 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Keyladder destination Private Key class\n");
3279 }
3280 else if(DSCMB_KL_DST_CLASS_TSIO & eKLDst)
3281 {
3282 //KL to TSIO
3283 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Keyladder destination TSIO\n");
3284 u32FltId = KLCfg->u32DscID; //TSIO service id
3285 }
3286 else if(DSCMB_KL_DST_CLASS_CFB& eKLDst)
3287 {
3288 //KL to CFB
3289 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Keyladder destination CFB\n");
3290 }
3291 else
3292 {
3293 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Unknown Keyladder destination\n");
3294 *u32Status = KL_STATUS_KL_INPUT_NULL;
3295 goto KL_Fail;
3296 }
3297
3298 //Check KeyLadder Input
3299 if ((KLCfg->u32Level != 0) && (NULL == KLCfg->pu8KeyKLIn))
3300 {
3301 *u32Status = KL_STATUS_KL_INPUT_NULL;
3302 goto KL_Fail;
3303 }
3304
3305 // TODO: Here need to check key property if support KDF or not
3306
3307 HAL_DSCMB_KL_Reset(eKLEng);
3308 HAL_DSCMB_KL_KDF_Disable(eKLEng);
3309
3310
3311 if(E_DSCMB_KL_SRC_ACPU == eKLSrc)
3312 {
3313 HAL_DSCMB_KL_ACPURootKey(eKLEng, KLCfg->u8KeyACPU);
3314 }
3315
3316 DRVDSCMB2_DBG(DSCMB2_DBGLV_INFO, "u32CAVid=%X\n", u32CAVid);
3317 //FIXME: If Key from OTP, should we set usage & entropy ?
3318 if(DSCMB_KL_DST_CLASS_TSIO & eKLDst)
3319 {
3320 HAL_DSCMB_KL_KeyProp( eKLEng, u32CAVid, 0 , /*Usage*/ 1 /*Entropy*/);
3321 }
3322 else
3323 {
3324 HAL_DSCMB_KL_KeyProp( eKLEng, u32CAVid, 0 , /*Usage*/ 0 /*Entropy*/);
3325 }
3326
3327 //Enable KDF
3328 if(bEnableKDF)
3329 {
3330 HAL_DSCMB_KL_KDF_Enable( eKLEng, KLCfg->stKDF.eKDFType, KLCfg->stKDF.u16AppId, KLCfg->stKDF.eHWKeyId);
3331 }
3332
3333 // Set KL Level input //
3334 for( i = 0 ; i < KLCfg->u32Level ; i ++ )
3335 {
3336 HAL_DSCMB_KL_Input(eKLEng, (KLCfg->u32Level-i-1), KLCfg->pu8KeyKLIn+(16*i));
3337 }
3338
3339
3340 //Set ETSI KL Nonce input
3341 HAL_DSCMB_KL_ETSI_Nonce(eKLEng, pu8Nonce);
3342
3343 // Set KL Ctrl
3344 if(FALSE == HAL_DSCMB_KL_Ctrl(eKLEng, KLCfg->eAlgo, KLCfg->u32Level, eKLSrc, eKLDst))
3345 {
3346 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Invalid Keyladder control setting\n");
3347 *u32Status = KL_STATUS_INVALID_INPUT_LEVEL;
3348 goto KL_Fail;
3349
3350 }
3351
3352 //KL to secure key slot
3353 HAL_DSCMB_KL_DstSecure(eKLEng, bKLDstSecure);
3354
3355 if (DSCMB_KL_DST_CLASS_CPU & eKLDst)
3356 {
3357 // KL flow for ACPU output //
3358 HAL_DSCMB_KL_KeyBus(eKLEng,
3359 0, /*For Dst KT*/
3360 0, /*For Dst KT*/
3361 0, /*For Dst KT*/
3362 0); /*For Dst DMA*/
3363 }
3364 else if (DSCMB_KL_DST_CLASS_DMA & eKLDst)
3365 {
3366 // KL flow for output to CryptoDMA //
3367 HAL_DSCMB_KL_KeyBus(eKLEng,
3368 0, /*For Dst KT*/
3369 0, /*For Dst KT*/
3370 0, /*For Dst KT*/
3371 eKLDst); /*For Dst DMA*/
3372 }
3373 else if (DSCMB_KL_DST_CLASS_KT & eKLDst)
3374 {
3375 #ifdef ENABLE_KEY_FSCB
3376 if(bEnableKeyFscb){
3377 // KL flow for output to KTE (with KeyFSCB) //
3378 HAL_DSCMB_KL_KeyBus_Ex(eKLEng,
3379 u32FltId, /*For Dst KT*/
3380 u32Field, /*For Dst KT*/
3381 eKeyType, /*For Dst KT*/
3382 eKLDst, /*For Dst KT*/
3383 KLCfg->eFSCB); /*For Dst KT*/
3384 }
3385 else{
3386 #endif
3387 // KL flow for output to KTE //
3388 HAL_DSCMB_KL_KeyBus(eKLEng,
3389 u32FltId, /*For Dst KT*/
3390 u32Field, /*For Dst KT*/
3391 eKeyType, /*For Dst KT*/
3392 eKLDst); /*For Dst KT*/
3393 #ifdef ENABLE_KEY_FSCB
3394 }
3395 #endif
3396 }
3397 else if (DSCMB_KL_DST_CLASS_PVT & eKLDst)
3398 {
3399 // KL flow for output to PVT //
3400 HAL_DSCMB_KL_KeyBus(eKLEng,
3401 0, /*For Dst KT*/
3402 0, /*For Dst KT*/
3403 0, /*For Dst KT*/
3404 0); /*For Dst DMA*/
3405 }
3406 else if(DSCMB_KL_DST_CLASS_TSIO & eKLDst)
3407 {
3408 // KL flow for output to TSIO //
3409 HAL_DSCMB_KL_KeyBus(eKLEng,
3410 u32FltId, /*For Dst TSIO*/
3411 0, /*For Dst TSIO*/
3412 KLCfg->eKeyType, /*For Dst TSIO*/
3413 eKLDst); /*For Dst TSIO*/
3414 }
3415 else if(DSCMB_KL_DST_CLASS_CFB& eKLDst)
3416 {
3417 // KL flow for output to CFB //
3418 HAL_DSCMB_KL_KeyBus(eKLEng,
3419 0, /*For Dst KT*/
3420 0, /*For Dst KT*/
3421 0, /*For Dst KT*/
3422 eKLDst); /*For Dst CFB*/
3423 }
3424
3425 if(HAL_DSCMB_KL_Start(eKLEng) == FALSE)
3426 {
3427 HAL_DSCMB_KL_ErrMsg(eKLEng, &u32ErrMsg);
3428 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "\033[31m KL error message 0x%X\n\033[m", (unsigned int)u32ErrMsg);
3429 goto KL_Fail;
3430 }
3431
3432 if ((DSCMB_KL_DST_CLASS_SPSSPD & eKLDst) == DSCMB_KL_DST_CLASS_SPSSPD)
3433 {
3434 // KL flow for output to CryptoDMA //
3435 HAL_DSCMB_KL_SP_KeyCtrl(eKLEng, eKLDst);
3436 if(HAL_DSCMB_KL_SP_Start(eKLEng) == FALSE)
3437 {
3438 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "\033[31m KL to SPS SPD Fail\n\033[m");
3439 goto KL_Fail;
3440 }
3441 }
3442
3443 // enable key
3444 if (DSCMB_KL_DST_CLASS_KT & eKLDst)
3445 {
3446 DSCMB_Eng_Type eEngType = E_DSCMB_ENG_ESA;
3447 if(eKLDst == E_DSCMB_KL_DST_KT_ESA )
3448 {
3449 eEngType = E_DSCMB_ENG_ESA;
3450 }
3451 else if(eKLDst == E_DSCMB_KL_DST_KT_LSAS )
3452 {
3453 eEngType = E_DSCMB_ENG_LSAS;
3454 }
3455 else if(eKLDst == E_DSCMB_KL_DST_KT_LSAD )
3456 {
3457 eEngType = E_DSCMB_ENG_LSAD;
3458 }
3459
3460 if (FALSE == HAL_DSCMB_KTE_Key_Ctrl_Ex(u32FltId,
3461 eKeyType,
3462 eEngType,
3463 u32CAVid,
3464 TRUE,
3465 TRUE))
3466 {
3467 *u32Status = KL_STATUS_KL_INPUT_NULL;
3468 goto KL_Fail;
3469 }
3470 }
3471
3472 //Output to ACPU
3473 if (E_DSCMB_KL_DST_CPU_ACPU == eKLDst)
3474 {
3475 MS_U32 u32OutKeySize = 0;
3476 if(KLCfg->eOutsize == E_DSCMB_KL_64_BITS)
3477 {
3478 u32OutKeySize = 8;
3479 }
3480 else if(KLCfg->eOutsize == E_DSCMB_KL_128_BITS)
3481 {
3482 u32OutKeySize = 16;
3483 }
3484 memset(ACPU_Out , 0x0 , u32OutKeySize );
3485 HAL_DSCMB_KL_GetACPUOut(eKLEng,ACPU_Out,u32OutKeySize);
3486 }
3487
3488 HAL_DSCMB_KL_ETSI_Response(eKLEng, pu8Response);
3489
3490 HAL_DSCMB_KL_HW_SEM_Unlock(eKLEng);
3491 MDrv_DSCMB_KLadder_Unlock();
3492 return TRUE;
3493
3494 KL_Fail:
3495
3496 HAL_DSCMB_KL_HW_SEM_Unlock(eKLEng);
3497 MDrv_DSCMB_KLadder_Unlock();
3498 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "DSCMB KL Fail = %08X \n",*u32Status);
3499 DSCMB_ASSERT_AND_RETURN(FALSE);
3500
3501 return FALSE;
3502 }
3503
3504 #if 0
3505 DLL_PUBLIC MS_BOOL MDrv_DSCMB_KLadder_TCSA3_TA(DSCMB_KLCfg_All* KLCfg , MS_U8 *pu8ActCode, MS_U32 u32CHSel, MS_U8 *
3506 pu8EncCW, DSCMB_KL_TA_LUT3* LUT3Tab, DSCMB_KL_Status* u32Status)
3507 {
3508 MS_U32 i = 0;
3509 *u32Status = KL_STATUS_KEY_OK ;
3510 DSCMB_KL_SelEng eKLEng = E_DSCMB_KL_SEL_CW;
3511 MS_U32 u32FltId = 0;
3512 MS_U32 u32ErrMsg = 0;
3513 MS_U32 u32Step2Level = KLCfg->u32Level-1; /*level - 1*/
3514 MS_BOOL bKDFBusy = TRUE;
3515
3516 MDrv_DSCMB_KLadder_Lock();
3517
3518 if( DRV_DSCMB_CAVID_IRD != HAL_DSCMB_GetCavid())
3519 {
3520 *u32Status = KL_STATUS_KL_INPUT_NULL;
3521 goto KL_Fail;
3522 }
3523
3524 if(FALSE == HAL_DSCMB_KL_KDF_Busy(E_DSCMB_KL_SEL_CW, &bKDFBusy))
3525 {
3526 *u32Status = KL_STATUS_KL_INPUT_NULL;
3527 goto KL_Fail;
3528 }
3529 else
3530 {
3531 if(bKDFBusy == TRUE)
3532 {
3533 *u32Status = KL_STATUS_KL_INPUT_NULL;
3534 goto KL_Fail;
3535 }
3536 }
3537
3538 //////////////////////////////////////////////////
3539 ////////////Step 1, KL Output Clear CW to KT ////////
3540 //////////////////////////////////////////////////
3541 HAL_DSCMB_KL_Reset(eKLEng);
3542
3543 for( i = 0 ; i < KLCfg->u32Level ; i ++ )
3544 {
3545 HAL_DSCMB_KL_Input(eKLEng, (KLCfg->u32Level-i-1), KLCfg->pu8KeyKLIn+(16*i));
3546 }
3547
3548 //Unlock LUT3 table
3549 HAL_DSCMB_KL_TA_EN(eKLEng, FALSE);
3550
3551 //Set Transformed Algorithm EncCW
3552 if(FALSE == HAL_DSCMB_KL_TA_EncCW(eKLEng, pu8EncCW))
3553 {
3554 *u32Status = KL_STATUS_KL_INPUT_NULL;
3555 goto KL_Fail;
3556 }
3557 //////////////////////////////////////////////////
3558 ////Set Transformed Algorithm LUT3 table address //////
3559 //////////////////////////////////////////////////
3560 HAL_DSCMB_KL_TA_LUT3(eKLEng, LUT3Tab);
3561
3562 //Enable TA and lock LUT3 table
3563 HAL_DSCMB_KL_TA_EN(eKLEng, TRUE);
3564
3565 HAL_DSCMB_KL_Ctrl(eKLEng, KLCfg->eAlgo,
3566 KLCfg->u32Level,
3567 KLCfg->eSrc,
3568 E_DSCMB_KL_DST_KT_ESA/*output to KT ESA*/);
3569
3570 // Get Filter ID
3571 if(FALSE == _DSCMB_Dscmb2Flt(KLCfg->u32DscID, &u32FltId))
3572 {
3573 *u32Status = KL_STATUS_IVALID_DSCMB_ID;
3574 goto KL_Fail;
3575 }
3576 DSCMB_DBG("\033[31m LINE %d, filter ID %lu\n\033[m", __LINE__, u32FltId);
3577
3578
3579 HAL_DSCMB_KL_KeyBus(eKLEng,
3580 u32FltId, /*For Dst KT*/
3581 0, /*For Dst KT*/ /*No use*/
3582 KLCfg->eKeyType, /*For Dst KT*/
3583 E_HAL_DSCMB_KL_DSTKT_ESA); /*For Dst DMA*/
3584
3585 //Enable the key slot
3586 if (FALSE == HAL_DSCMB_KTE_Key_Ctrl(u32FltId,
3587 KLCfg->eKeyType,
3588 E_DSCMB_ENG_KEY_ESA,
3589 TRUE))
3590 {
3591 *u32Status = KL_STATUS_KL_INPUT_NULL;
3592 goto KL_Fail;
3593 }
3594
3595 HAL_DSCMB_KL_Start(eKLEng);
3596
3597 HAL_DSCMB_KL_ErrMsg(eKLEng, &u32ErrMsg);
3598
3599 DSCMB_DBG("\033[31m KL error message 0x%X\n\033[m", (unsigned int)u32ErrMsg);
3600
3601 //////////////////////////////////////////////////
3602 ////////////Step 2, KL Output to CSSK////////////////
3603 //////////////////////////////////////////////////
3604 HAL_DSCMB_KL_Reset(eKLEng);
3605
3606 // Set KL Level input /*level - 1*/
3607 for( i = 0 ; i < (u32Step2Level) ; i ++ )
3608 {
3609 HAL_DSCMB_KL_Input(eKLEng, (u32Step2Level-i-1), KLCfg->pu8KeyKLIn+(16*i));
3610 }
3611
3612 HAL_DSCMB_KL_KeyBus(eKLEng,
3613 0, /*For Dst KT*/
3614 0, /*For Dst KT*/ /*No use*/
3615 0, /*For Dst KT*/
3616 E_DSCMB_KL_DST_DMA_CSSK); /*For Dst DMA*/
3617
3618 // Set KL Ctrl
3619 HAL_DSCMB_KL_Ctrl(eKLEng, KLCfg->eAlgo,
3620 u32Step2Level, /*level - 1*/
3621 KLCfg->eSrc,
3622 E_DSCMB_KL_DST_DMA_CSSK /*FIXME to CSSK*/);
3623
3624 HAL_DSCMB_KL_Start(eKLEng);
3625
3626 HAL_DSCMB_KL_ErrMsg(eKLEng, &u32ErrMsg);
3627 DSCMB_DBG("\033[31m KL error message 0x%X\n\033[m", (unsigned int)u32ErrMsg);
3628
3629 //////////////////////////////////////////////////
3630 ////////////Step 3, KL Output IV & RK to CSA3 ////////
3631 //////////////////////////////////////////////////
3632 HAL_DSCMB_KL_TCSA3_ActCode(pu8ActCode,16);
3633 HAL_DSCMB_KL_TCSA3_CHSel(u32CHSel);
3634 HAL_DSCMB_KL_TCSA3_Start();
3635
3636 HAL_DSCMB_KL_ErrMsg(eKLEng, &u32ErrMsg);
3637 DSCMB_DBG("\033[31m KL error message 0x%X\n\033[m", (unsigned int)u32ErrMsg);
3638
3639 if(FALSE == HAL_DSCMB_Cipher_TCSA3(u32CHSel,TRUE))
3640 {
3641 *u32Status = KL_STATUS_IVALID_DSCMB_ID;
3642 goto KL_Fail;
3643 }
3644
3645 //Unlock LUT3 table and KL SRAM
3646 HAL_DSCMB_KL_TA_EN(eKLEng, FALSE);
3647
3648 MDrv_DSCMB_KLadder_Unlock();
3649 return TRUE;
3650
3651 KL_Fail:
3652
3653 HAL_DSCMB_KL_TA_EN(eKLEng, FALSE);
3654 MDrv_DSCMB_KLadder_Unlock();
3655 printf("[%s][%d]TCSA3 TA DSCMB KL Fail = %08lX \n",__FUNCTION__,__LINE__,*u32Status );
3656 DSCMB_ASSERT_AND_RETURN(FALSE);
3657
3658 return FALSE;
3659 }
3660 #endif
3661
_MDrv_DSCMB2_GetCap(MS_U32 u32EngId,DSCMB_Query_Type eQueryType,void * pInput,void * pOutput)3662 MS_BOOL _MDrv_DSCMB2_GetCap(MS_U32 u32EngId, DSCMB_Query_Type eQueryType, void* pInput, void* pOutput)
3663 {
3664 HAL_DSCMB_Query_Type u32Cap;
3665
3666 DSCMB_ASSERT_AND_RETURN(u32EngId == 0);
3667 DSCMB_ASSERT_AND_RETURN(pOutput != NULL);
3668
3669 switch (eQueryType)
3670 {
3671 case E_DSCMB_CAP_ENGINE_NUM:
3672 u32Cap = E_HAL_DSCMB_CAP_ENGINE_NUM;
3673 break;
3674 case E_DSCMB_CAP_FLT_NUM:
3675 u32Cap = E_HAL_DSCMB_CAP_FLT_NUM;
3676 break;
3677 case E_DSCMB_CAP_SUPPORT_ALGORITHM:
3678 DSCMB_ASSERT_AND_RETURN(pInput != NULL);
3679 u32Cap = E_HAL_DSCMB_CAP_SUPPORT_ALGORITHM;
3680 break;
3681 case E_DSCMB_CAP_SUPPORT_KEY_TYPE:
3682 DSCMB_ASSERT_AND_RETURN(pInput != NULL);
3683 if((*(DSCMB_Key_Type *)pInput) <= E_DSCMB_KEY_ODD)
3684 {
3685 return TRUE;
3686 }
3687 else
3688 {
3689 return FALSE;
3690 }
3691 break;
3692 case E_DSCMB_CAP_PIDFILTER_MAP_START:
3693 u32Cap = E_HAL_DSCMB_CAP_PIDFILTER_MAP_START;
3694 break;
3695 case E_DSCMB_CAP_PIDFILTER_MAP_END:
3696 u32Cap = E_HAL_DSCMB_CAP_PIDFILTER_MAP_END;
3697 break;
3698 case E_DSCMB_CAP_SHARE_KEY_SLOT_MAX_NUM:
3699 u32Cap = E_HAL_DSCMB_CAP_SHARE_KEY_SLOT_NUM;
3700 break;
3701 case E_DSCMB_CAP_SHARE_KEY_REGION_NUM:
3702 u32Cap = E_HAL_DSCMB_CAP_SHARE_KEY_REGION_NUM;
3703 break;
3704 case E_DSCMB_CAP_SHARE_KEY_REGION_START:
3705 u32Cap = E_HAL_DSCMB_CAP_SHARE_KEY_REGION_START;
3706 break;
3707 case E_DSCMB_CAP_SHARE_KEY_REGION_END:
3708 u32Cap = E_HAL_DSCMB_CAP_SHARE_KEY_REGION_END;
3709 break;
3710 default:
3711 return FALSE;
3712 break;
3713 }
3714
3715 return HAL_DSCMB_GetCap(u32EngId, u32Cap, pInput, pOutput);
3716
3717 }
3718
3719 //--------------------------------------------------------------------------------------------------
3720 /// Get Dscmb driver library information
3721 /// @param ppVersion \b OUT: Descrambler library version infomation
3722 /// @return TRUE - Success
3723 /// @return FALSE - Failure
3724 //--------------------------------------------------------------------------------------------------
_MDrv_DSCMB2_GetLibVer(const MSIF_Version ** ppVersion)3725 MS_BOOL _MDrv_DSCMB2_GetLibVer(const MSIF_Version **ppVersion)
3726 {
3727 *ppVersion = &_drv_dscmb_version;
3728 return TRUE;
3729 }
3730
3731 //--------------------------------------------------------------------------------------------------
3732 /// Set Dscmb driver debug level
3733 /// @param u32Level \b IN: debug level
3734 /// @return TRUE - Success
3735 /// @return FALSE - Failure
3736 //--------------------------------------------------------------------------------------------------
_MDrv_DSCMB2_SetDBGLevel(MS_U32 u32Level)3737 MS_BOOL _MDrv_DSCMB2_SetDBGLevel(MS_U32 u32Level)
3738 {
3739 _u32DSCMB2DbgLv = u32Level;
3740 DRVDSCMB2_DBG(DSCMB2_DBGLV_INFO, "%s level: %x\n", __FUNCTION__, u32Level);
3741 HAL_DSCMB_SetDBGLevel(u32Level);
3742 return TRUE;
3743 }
_MDrv_DSCMB2_PVR_RecCtrl(MS_U32 u32EngId,MS_BOOL Enable)3744 MS_BOOL _MDrv_DSCMB2_PVR_RecCtrl(MS_U32 u32EngId, MS_BOOL Enable)
3745 {
3746 //For compatible, always return TRUE because PVR MW will check the return status
3747 OBSOLETE_FUNCTION ("Not support\n");
3748 return TRUE;
3749 }
3750
_MDrv_DSCMB2_PidFlt_ScmbStatus(MS_U32 u32EngId,MS_U32 u32PidFltId,SCMB_Level * pScmbLevel)3751 MS_BOOL _MDrv_DSCMB2_PidFlt_ScmbStatus(MS_U32 u32EngId, MS_U32 u32PidFltId, SCMB_Level* pScmbLevel)
3752 {
3753 OBSOLETE_FUNCTION ("Not support\n");
3754 return FALSE;
3755 }
3756
_MDrv_DSCMB2_Multi2_SetRound(MS_U32 u32EngId,MS_U32 u32Round)3757 MS_BOOL _MDrv_DSCMB2_Multi2_SetRound(MS_U32 u32EngId, MS_U32 u32Round)
3758 {
3759 DSCMB_INIT_CHECK(FALSE);
3760
3761 DSCMB_LOCK(_s32DscMutexId);
3762 HAL_DSCMB_KTE_Write_MULTI2_Round(u32Round);
3763 DSCMB_UNLOCK(_s32DscMutexId);
3764
3765 return TRUE;
3766 }
3767
_MDrv_DSCMB2_Multi2_SetSystemKey(MS_U32 u32EngId,MS_U8 * u8Syskey)3768 MS_BOOL _MDrv_DSCMB2_Multi2_SetSystemKey(MS_U32 u32EngId, MS_U8* u8Syskey)
3769 {
3770 DSCMB_INIT_CHECK(FALSE);
3771 DSCMB_ASSERT(u8Syskey != NULL, "System key input NULL", FALSE);
3772
3773 DSCMB_LOCK(_s32DscMutexId);
3774 HAL_DSCMB_KTE_Write_MULTI2_SysKey(u8Syskey, HAL_DSCMB_MULTI2_SYSKEY_MAX);
3775 DSCMB_UNLOCK(_s32DscMutexId);
3776
3777 return TRUE;
3778 }
3779
_MDrv_DSCMB2_HDCP2_SetRIV(MS_U32 u32EngId,MS_U8 * pu8RIV)3780 MS_BOOL _MDrv_DSCMB2_HDCP2_SetRIV(MS_U32 u32EngId, MS_U8* pu8RIV)
3781 {
3782 OBSOLETE_FUNCTION ("Obsolete function\n");
3783 return FALSE;
3784 }
3785
_MDrv_DSCMB2_HDCP2_SetRIV_Ex(MS_U32 u32EngId,MS_U32 u32DscmbId,MS_U8 * pu8RIV)3786 MS_BOOL _MDrv_DSCMB2_HDCP2_SetRIV_Ex(MS_U32 u32EngId, MS_U32 u32DscmbId, MS_U8* pu8RIV)
3787 {
3788 return _MDrv_DSCMB2_EngSetRIV(u32EngId, u32DscmbId, pu8RIV);
3789 }
3790
_MDrv_DSCMB2_ES_SetStaticKey(MS_U32 u32EngId,MS_U8 * pu8Statickey)3791 MS_BOOL _MDrv_DSCMB2_ES_SetStaticKey(MS_U32 u32EngId, MS_U8* pu8Statickey)
3792 {
3793 DSCMB_INIT_CHECK(FALSE);
3794
3795 DSCMB_LOCK(_s32DscMutexId);
3796 HAL_DSCMB_Cipher_ES_SetStaticKey(u32EngId, pu8Statickey, HAL_DSCMB_ES_STATICKEY_MAX);
3797 DSCMB_UNLOCK(_s32DscMutexId);
3798
3799 return TRUE;
3800 }
3801
3802 //------------------------------------- ------------------//
3803 //----------------------Debug API -------------------------//
3804 //-------------------------------------------------------//
_MDrv_DSCMB2_GetConnectStatus(MS_U32 u32EngId,MS_U32 u32DscmbId,MS_U32 u32TspFltId)3805 MS_BOOL _MDrv_DSCMB2_GetConnectStatus(MS_U32 u32EngId, MS_U32 u32DscmbId, MS_U32 u32TspFltId)
3806 {
3807 DSCMB_INIT_CHECK(FALSE);
3808
3809 return _DSCMB_IsFltConnectDSCMB(u32DscmbId, u32TspFltId);
3810 }
3811
_MDrv_DSCMB2_ReadSwitch(MS_U32 u32FltId,DSCMB_Key_Type type,MS_U32 u32CAVid)3812 void _MDrv_DSCMB2_ReadSwitch(MS_U32 u32FltId, DSCMB_Key_Type type, MS_U32 u32CAVid)
3813 {
3814 DSCMB_INIT_CHECK();
3815
3816 DSCMB_LOCK(_s32DscMutexId);
3817
3818 if(_u32PidFlt2Dscmb[u32FltId].u8DscmbId != HAL_DSCMB_KTE_MAX)
3819 {
3820 #ifdef FLEXIBLE_PIDSLOTMAP
3821 HAL_DSCMB_PrintSwitchSetup(_u32PidFlt2Dscmb[u32FltId].u8DscmbId, type, u32CAVid);
3822 #else
3823 HAL_DSCMB_PrintSwitchSetup(u32FltId, type, u32CAVid);
3824 #endif /* FLEXIBLE_PIDSLOTMAP */
3825 }
3826
3827 DSCMB_UNLOCK(_s32DscMutexId);
3828 }
3829
_MDrv_DSCMB2_ReadPidSlotMap(MS_U32 u32FltId)3830 void _MDrv_DSCMB2_ReadPidSlotMap(MS_U32 u32FltId)
3831 {
3832 DSCMB_INIT_CHECK();
3833
3834 PidSlotMapRead_t tReadData;
3835 memset(&tReadData, 0, sizeof(PidSlotMapRead_t));
3836
3837 DSCMB_LOCK(_s32DscMutexId);
3838
3839 if(_u32PidFlt2Dscmb[u32FltId].u8DscmbId != HAL_DSCMB_KTE_MAX)
3840 {
3841 #ifdef FLEXIBLE_PIDSLOTMAP
3842 HAL_DSCMB_ReadPidSlotMap(_u32PidFlt2Dscmb[u32FltId].u8DscmbId, &tReadData);
3843 #else
3844 HAL_DSCMB_ReadPidSlotMap(u32FltId, &tReadData);
3845 #endif /* FLEXIBLE_PIDSLOTMAP */
3846 }
3847
3848 DSCMB_UNLOCK(_s32DscMutexId);
3849 }
3850
_MDrv_DSCMB2_PacketView(MS_U32 u32Eng,MS_U32 u32FltId,MS_U32 Mode,MS_U32 u32Range,MS_BOOL bRst)3851 void _MDrv_DSCMB2_PacketView(MS_U32 u32Eng, MS_U32 u32FltId, MS_U32 Mode, MS_U32 u32Range, MS_BOOL bRst)
3852 {
3853 DSCMB_INIT_CHECK();
3854
3855 MS_U32 u32pktparser = 0;
3856 MS_U32 u32tsif = 0;
3857 Mode = Mode >= 1? TRUE: FALSE;
3858
3859 //Mode = 1, enable snap mode, stop when pktcnt is finished
3860 //Mode = 0, enable trigger mode, stop when badpkt occurs
3861
3862 HAL_DSCMB_Get_TsidInput(u32FltId, &u32tsif);
3863 //printf("%s, u32tsif = %lx, reset = %d\n", __FUNCTION__, u32tsif, bRst);
3864
3865 if(bRst == TRUE)
3866 {
3867 //reset....
3868 u32pktparser = HAL_DSCMB_PktParser_Ctrl(u32Eng, u32tsif, TRUE, u32Range, 0, Mode);
3869 return;
3870 }
3871
3872 u32pktparser = HAL_DSCMB_PktParser_Ctrl(u32Eng, u32tsif, FALSE, u32Range, E_HAL_DSCMB_PARSER_EVENT, Mode);
3873 DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING, "Event = 0x%08x\n", u32pktparser);
3874 HAL_DSCMB_PktParser_PrintEvent(u32pktparser);
3875
3876 u32pktparser = HAL_DSCMB_PktParser_Ctrl(u32Eng, u32tsif, FALSE, u32Range, E_HAL_DSCMB_PARSER_SCB, Mode);
3877 DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING, "SCB_00 = 0x%x\n", (u32pktparser & 0xFF000000) >>24);
3878 DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING, "SCB_01 = 0x%x\n", (u32pktparser & 0x00FF0000) >>16);
3879 DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING, "SCB_10 = 0x%x\n", (u32pktparser & 0x0000FF00) >> 8);
3880 DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING, "SCB_11 = 0x%x\n", (u32pktparser & 0x000000FF) >> 0);
3881
3882 u32pktparser = HAL_DSCMB_PktParser_Ctrl(u32Eng, u32tsif, FALSE, u32Range, E_HAL_DSCMB_PARSER_BADPKT, Mode);
3883 DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING, "BADPKT_UPP = 0x%x\n", (u32pktparser & 0xFF000000) >>24);
3884 DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING, "BADPKT_LOW = 0x%x\n", (u32pktparser & 0x00FF0000) >>16);
3885 DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING, "PKT_UPP = 0x%x\n", (u32pktparser & 0x0000FF00) >> 8);
3886 DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING, "PKT_LOW = 0x%x\n", (u32pktparser & 0x000000FF) >> 0);
3887
3888 u32pktparser = HAL_DSCMB_PktParser_Ctrl(u32Eng, u32tsif, FALSE, u32Range, E_HAL_DSCMB_PARSER_2NDHIT, Mode);
3889 DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING, "2NDHIT = 0x%x\n", u32pktparser);
3890
3891 u32pktparser = HAL_DSCMB_PktParser_Ctrl(u32Eng, u32tsif, FALSE, u32Range, E_HAL_DSCMB_PARSER_ESA, Mode);
3892 DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING, "ESA = 0x%x\n", u32pktparser);
3893
3894 u32pktparser = HAL_DSCMB_PktParser_Ctrl(u32Eng, u32tsif, FALSE, u32Range, E_HAL_DSCMB_PARSER_LSA, Mode);
3895 DRVDSCMB2_DBG(DSCMB2_DBGLV_WARNING, "LSA = 0x%x\n", u32pktparser);
3896 }
3897
MDrv_DSCMB2_SetPowerState(EN_POWER_MODE u16PowerState)3898 MS_U32 MDrv_DSCMB2_SetPowerState(EN_POWER_MODE u16PowerState)
3899 {
3900 #ifdef DSCMB_UTOPIA20
3901 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
3902 EN_POWER_MODE pArgs = u16PowerState;
3903 if(pu32DscmbInst == NULL)
3904 {
3905 if(UTOPIA_STATUS_FAIL == UtopiaOpen(MODULE_DSCMB, &pu32DscmbInst, 0x0, NULL))
3906 {
3907 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "UtopiaOpen DSCMB fail\n");
3908 return FALSE;
3909 }
3910 }
3911
3912 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_SetPowerState, (void*)&pArgs);
3913 if(UTOPIA_STATUS_SUCCESS != u32Ret)
3914 {
3915 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
3916 return FALSE;
3917 }
3918
3919 return TRUE;
3920 #else
3921 return _MDrv_DSCMB2_SetPowerState(u16PowerState);
3922 #endif
3923 }
3924
3925
MDrv_DSCMB2_Init(void)3926 MS_BOOL MDrv_DSCMB2_Init(void)
3927 {
3928 #ifdef DSCMB_UTOPIA20
3929 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
3930
3931 if(pu32DscmbInst == NULL)
3932 {
3933 if(UTOPIA_STATUS_FAIL == UtopiaOpen(MODULE_DSCMB, &pu32DscmbInst, 0x0, NULL))
3934 {
3935 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "UtopiaOpen DSCMB fail\n");
3936 return FALSE;
3937 }
3938 }
3939
3940 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_Init, NULL);
3941 if(UTOPIA_STATUS_SUCCESS != u32Ret)
3942 {
3943 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
3944 return FALSE;
3945 }
3946
3947 return TRUE;
3948 #else
3949 return _MDrv_DSCMB2_Init();
3950 #endif
3951 }
3952
MDrv_DSCMB2_Exit(void)3953 MS_BOOL MDrv_DSCMB2_Exit(void)
3954 {
3955 #ifdef DSCMB_UTOPIA20
3956 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
3957 if(pu32DscmbInst == NULL)
3958 {
3959 return FALSE;
3960 }
3961
3962 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_Exit, NULL);
3963 if(UTOPIA_STATUS_SUCCESS != u32Ret)
3964 {
3965 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
3966 return FALSE;
3967 }
3968
3969 return TRUE;
3970
3971 #else
3972 return _MDrv_DSCMB2_Exit();
3973 #endif
3974 }
3975
MDrv_DSCMB2_FltAllocWithCAVid(MS_U32 u32EngId,DSCMB_Flt_Type eFltType,MS_U32 u32CAVid)3976 MS_U32 MDrv_DSCMB2_FltAllocWithCAVid(MS_U32 u32EngId, DSCMB_Flt_Type eFltType, MS_U32 u32CAVid)
3977 {
3978 return _MDrv_DSCMB2_FltAllocWithCAVid(u32EngId, eFltType, u32CAVid);
3979 }
3980
MDrv_DSCMB2_FltAlloc_Ex(MS_U32 u32EngId,DSCMB_Flt_Type eFltType)3981 MS_U32 MDrv_DSCMB2_FltAlloc_Ex(MS_U32 u32EngId, DSCMB_Flt_Type eFltType)
3982 {
3983 #ifdef DSCMB_UTOPIA20
3984 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
3985 DSCMB_FLTALLOC pArgs;
3986 if(pu32DscmbInst == NULL)
3987 {
3988 return DRV_DSCMB_FLT_NULL;
3989 }
3990
3991 pArgs.u32EngId = u32EngId;
3992 pArgs.eFltType = eFltType;
3993 pArgs.u32DscmbId = 0xFF;
3994
3995 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_FltAlloc, (void*)&pArgs);
3996 if(UTOPIA_STATUS_SUCCESS != u32Ret)
3997 {
3998 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
3999 return DRV_DSCMB_FLT_NULL;
4000 }
4001
4002 return pArgs.u32DscmbId;
4003
4004 #else
4005 return _MDrv_DSCMB2_FltAlloc_Ex(u32EngId, eFltType);
4006 #endif
4007 }
4008
MDrv_DSCMB2_FltAlloc(MS_U32 u32EngId)4009 MS_U32 MDrv_DSCMB2_FltAlloc(MS_U32 u32EngId)
4010 {
4011 return MDrv_DSCMB2_FltAlloc_Ex(u32EngId, E_DSCMB_FLT_2_KEYS);
4012 }
4013
4014 //--------------------------------------------------------------------------------------------------
4015 /// Free the specific DSCMB filter by ID
4016 /// @return TRUE - SUCCESS
4017 /// @return FALSE - Failure
4018 /// @note
4019 ///
4020 //--------------------------------------------------------------------------------------------------
4021
MDrv_DSCMB2_FltFree(MS_U32 u32EngId,MS_U32 u32DscmbId)4022 MS_BOOL MDrv_DSCMB2_FltFree(MS_U32 u32EngId, MS_U32 u32DscmbId)
4023 {
4024 #ifdef DSCMB_UTOPIA20
4025 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4026 DSCMB_FLTFREE pArgs;
4027
4028 memset(&pArgs, 0, sizeof(DSCMB_FLTFREE));
4029 if(pu32DscmbInst == NULL)
4030 {
4031 return FALSE;
4032 }
4033
4034 pArgs.u32DscmbId = u32DscmbId;
4035
4036 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_FltFree, (void*)&pArgs);
4037 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4038 {
4039 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4040 return FALSE;
4041 }
4042
4043 return TRUE;
4044
4045 #else
4046 return _MDrv_DSCMB2_FltFree(u32EngId, u32DscmbId);
4047 #endif
4048 }
4049
4050
MDrv_DSCMB2_FltConnectFltId(MS_U32 u32EngId,MS_U32 u32DscmbId,MS_U32 u32FltId)4051 MS_BOOL MDrv_DSCMB2_FltConnectFltId(MS_U32 u32EngId, MS_U32 u32DscmbId, MS_U32 u32FltId)
4052 {
4053 #ifdef DSCMB_UTOPIA20
4054 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4055 DSCMB_CONNECTFLT pArgs;
4056 memset(&pArgs, 0, sizeof(DSCMB_CONNECTFLT));
4057
4058 if(pu32DscmbInst == NULL)
4059 {
4060 return FALSE;
4061 }
4062
4063 pArgs.u32DscmbId = u32DscmbId;
4064 pArgs.u32DmxFltId = u32FltId;
4065
4066 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_FltConnectFltId, (void*)&pArgs);
4067 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4068 {
4069 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4070 return FALSE;
4071 }
4072
4073 return TRUE;
4074 #else
4075 return _MDrv_DSCMB2_FltConnectFltId(u32EngId, u32DscmbId, u32FltId);
4076 #endif
4077 }
4078
4079
4080
MDrv_DSCMB2_FltDisconnectFltId(MS_U32 u32EngId,MS_U32 u32DscmbId,MS_U32 u32FltId)4081 MS_BOOL MDrv_DSCMB2_FltDisconnectFltId(MS_U32 u32EngId, MS_U32 u32DscmbId, MS_U32 u32FltId)
4082 {
4083 #ifdef DSCMB_UTOPIA20
4084 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4085 DSCMB_DISCONNECTFLT pArgs;
4086 memset(&pArgs, 0, sizeof(DSCMB_DISCONNECTFLT));
4087 if(pu32DscmbInst == NULL)
4088 {
4089 return FALSE;
4090 }
4091
4092 pArgs.u32DscmbId = u32DscmbId;
4093 pArgs.u32DmxFltId = u32FltId;
4094 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_FltDisconnectFltId, (void*)&pArgs);
4095 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4096 {
4097 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4098 return FALSE;
4099 }
4100
4101 return TRUE;
4102 #else
4103 return _MDrv_DSCMB2_FltDisconnectFltId(u32EngId, u32DscmbId, u32FltId);
4104 #endif
4105 }
4106
MDrv_DSCMB2_EngSetFSCB(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_FSCB eForceSCB)4107 MS_BOOL MDrv_DSCMB2_EngSetFSCB(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_FSCB eForceSCB )
4108 {
4109 #ifdef DSCMB_UTOPIA20
4110 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4111 DSCMB_ENGFSCB pArgs;
4112 memset(&pArgs, 0, sizeof(DSCMB_ENGFSCB));
4113 if(pu32DscmbInst == NULL)
4114 {
4115 return FALSE;
4116 }
4117
4118 pArgs.u32EngId = u32EngId;
4119 pArgs.u32DscmbId = u32DscmbId;
4120 pArgs.eForceSCB = eForceSCB;
4121
4122 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_EngSetFSCB, (void*)&pArgs);
4123 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4124 {
4125 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4126 return FALSE;
4127 }
4128
4129 return TRUE;
4130 #else
4131 return _MDrv_DSCMB2_EngSetFSCB(u32EngId, u32DscmbId, eForceSCB);
4132 #endif
4133 }
4134
4135 // Set Upper & lower switch to dscmb filter //
4136 //--------------------------------------------------------------------------------------------------
4137 /// Set upper switch and lower switch to choose which engine will go into.
4138 /// @param u32DscmbId\b IN: The descrambler id which is get from MDrv_DSCMB2_FltAlloc.
4139 /// @param eUppSwitch\b IN: An Enum type for choosing descrambler engine when go through upper path.
4140 /// @param eLowSwitch\b IN: An Enum type for choosing descrambler engine when go through lower path.
4141 /// @return TRUE - SUCCESS
4142 /// @return FALSE - Failure
4143 /// @note
4144 ///
4145 //--------------------------------------------------------------------------------------------------
MDrv_DSCMB2_EngSetSwitch(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Eng_Type eUppSwitch,DSCMB_Eng_Type eLowSwitch)4146 MS_BOOL MDrv_DSCMB2_EngSetSwitch(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Eng_Type eUppSwitch, DSCMB_Eng_Type eLowSwitch)
4147 {
4148 #ifdef DSCMB_UTOPIA20
4149 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4150 DSCMB_ENGSWITCH pArgs;
4151 memset(&pArgs, 0, sizeof(DSCMB_ENGSWITCH));
4152 if(pu32DscmbInst == NULL)
4153 {
4154 return FALSE;
4155 }
4156
4157 pArgs.u32EngId = u32EngId;
4158 pArgs.u32DscmbId = u32DscmbId;
4159 pArgs.eUppSwitch = eUppSwitch;
4160 pArgs.eLowSwitch = eLowSwitch;
4161
4162 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_EngSetSwitch, (void*)&pArgs);
4163 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4164 {
4165 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4166 return FALSE;
4167 }
4168
4169 return TRUE;
4170 #else
4171 return _MDrv_DSCMB2_EngSetSwitch(u32EngId, u32DscmbId, eUppSwitch, eLowSwitch);
4172 #endif
4173 }
4174
MDrv_DSCMB2_EngSetAlgo(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Eng_Type eEngType,DSCMB_Algo_Cfg stConfig)4175 MS_BOOL MDrv_DSCMB2_EngSetAlgo(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Eng_Type eEngType, DSCMB_Algo_Cfg stConfig)
4176 {
4177 #ifdef DSCMB_UTOPIA20
4178 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4179 DSCMB_ENGALGO pArgs;
4180 memset(&pArgs, 0, sizeof(DSCMB_ENGALGO));
4181 if(pu32DscmbInst == NULL)
4182 {
4183 return FALSE;
4184 }
4185
4186 pArgs.u32EngId = u32EngId;
4187 pArgs.u32DscmbId = u32DscmbId;
4188 pArgs.eEngType = eEngType;
4189 pArgs.stConfig = stConfig;
4190
4191 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_EngSetAlgo, (void*)&pArgs);
4192 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4193 {
4194 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4195 return FALSE;
4196 }
4197
4198 return TRUE;
4199 #else
4200 return _MDrv_DSCMB2_EngSetAlgo(u32EngId, u32DscmbId, eEngType, stConfig);
4201 #endif
4202 }
4203
MDrv_DSCMB2_EngSetRIV(MS_U32 u32EngId,MS_U32 u32DscmbId,MS_U8 * pu8RIV)4204 MS_BOOL MDrv_DSCMB2_EngSetRIV(MS_U32 u32EngId, MS_U32 u32DscmbId, MS_U8* pu8RIV)
4205 {
4206 return _MDrv_DSCMB2_EngSetRIV(u32EngId, u32DscmbId, pu8RIV);
4207 }
4208
MDrv_DSCMB2_EngSetIV(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Key_Type eKeyType,MS_U8 * pu8IV)4209 MS_BOOL MDrv_DSCMB2_EngSetIV(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Key_Type eKeyType, MS_U8* pu8IV)
4210 {
4211 #ifdef DSCMB_UTOPIA20
4212 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4213 DSCMB_ENGIV pArgs;
4214 memset(&pArgs, 0, sizeof(DSCMB_ENGIV));
4215 if(pu32DscmbInst == NULL)
4216 {
4217 return FALSE;
4218 }
4219
4220 pArgs.u32EngId = u32EngId;
4221 pArgs.u32DscmbId = u32DscmbId;
4222 pArgs.eKeyType = eKeyType;
4223 pArgs.pu8IV = pu8IV;
4224
4225 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_EngSetIV, (void*)&pArgs);
4226 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4227 {
4228 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4229 return FALSE;
4230 }
4231
4232 return TRUE;
4233 #else
4234 return _MDrv_DSCMB2_EngSetIV(u32EngId, u32DscmbId, eKeyType, pu8IV);
4235 #endif
4236 }
4237
MDrv_DSCMB2_EngSetIV_Ex(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Eng_Type eEngType,DSCMB_Key_Type eKeyType,MS_U8 * pu8IV)4238 MS_BOOL MDrv_DSCMB2_EngSetIV_Ex(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Eng_Type eEngType, DSCMB_Key_Type eKeyType, MS_U8* pu8IV)
4239 {
4240 #ifdef DSCMB_UTOPIA20
4241 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4242 DSCMB_ENGIV_EX pArgs;
4243 memset(&pArgs, 0, sizeof(DSCMB_ENGIV_EX));
4244 if(pu32DscmbInst == NULL)
4245 {
4246 return FALSE;
4247 }
4248
4249 pArgs.u32EngId = u32EngId;
4250 pArgs.u32DscmbId = u32DscmbId;
4251 pArgs.eEngType = eEngType;
4252 pArgs.eKeyType = eKeyType;
4253 pArgs.pu8IV = pu8IV;
4254
4255 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_EngSetIV_Ex, (void*)&pArgs);
4256 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4257 {
4258 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4259 return FALSE;
4260 }
4261
4262 return TRUE;
4263 #else
4264 return _MDrv_DSCMB2_EngSetIV_Ex(u32EngId, u32DscmbId, eEngType, eKeyType, pu8IV);
4265 #endif
4266 }
4267
MDrv_DSCMB2_EngSetKeyFSCB(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Eng_Type eEngType,DSCMB_Key_Type eKeyType,DSCMB_FSCB eForceSCB)4268 MS_BOOL MDrv_DSCMB2_EngSetKeyFSCB(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Eng_Type eEngType, DSCMB_Key_Type eKeyType, DSCMB_FSCB eForceSCB)
4269 {
4270 #ifdef DSCMB_UTOPIA20
4271 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4272 DSCMB_ENGKEYFSCB pArgs;
4273 memset(&pArgs, 0, sizeof(DSCMB_ENGKEY));
4274 if(pu32DscmbInst == NULL)
4275 {
4276 return FALSE;
4277 }
4278
4279 pArgs.u32EngId = u32EngId;
4280 pArgs.u32DscmbId = u32DscmbId;
4281 pArgs.eEngType = eEngType;
4282 pArgs.eKeyType = eKeyType;
4283 pArgs.eForceSCB = eForceSCB;
4284
4285 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_EngSetKeyFSCB, (void*)&pArgs);
4286 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4287 {
4288 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4289 return FALSE;
4290 }
4291
4292 return TRUE;
4293 #else
4294 return _MDrv_DSCMB2_EngSetKeyFSCB(u32EngId, u32DscmbId, eEngType, eKeyType, eForceSCB);
4295 #endif
4296 }
4297
4298
MDrv_DSCMB2_EngSetKey(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Eng_Type eEngType,DSCMB_Key_Type eKeyType,MS_U8 * pu8Key)4299 MS_BOOL MDrv_DSCMB2_EngSetKey(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Eng_Type eEngType, DSCMB_Key_Type eKeyType, MS_U8* pu8Key)
4300 {
4301 #ifdef DSCMB_UTOPIA20
4302 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4303 DSCMB_ENGKEY pArgs;
4304 memset(&pArgs, 0, sizeof(DSCMB_ENGKEY));
4305 if(pu32DscmbInst == NULL)
4306 {
4307 return FALSE;
4308 }
4309
4310 pArgs.u32EngId = u32EngId;
4311 pArgs.u32DscmbId = u32DscmbId;
4312 pArgs.eEngType = eEngType;
4313 pArgs.eKeyType = eKeyType;
4314 pArgs.pu8Key = pu8Key;
4315
4316 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_EngSetKey, (void*)&pArgs);
4317 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4318 {
4319 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4320 return FALSE;
4321 }
4322
4323 return TRUE;
4324 #else
4325 return _MDrv_DSCMB2_EngSetKey(u32EngId, u32DscmbId, eEngType, eKeyType, pu8Key);
4326 #endif
4327 }
4328
MDrv_DSCMB2_EngResetKey(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Eng_Type eEngType,DSCMB_Key_Type eKeyType)4329 MS_BOOL MDrv_DSCMB2_EngResetKey(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Eng_Type eEngType, DSCMB_Key_Type eKeyType)
4330 {
4331 #ifdef DSCMB_UTOPIA20
4332 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4333 DSCMB_ENGRESETKEY pArgs;
4334 memset(&pArgs, 0, sizeof(DSCMB_ENGRESETKEY));
4335 if(pu32DscmbInst == NULL)
4336 {
4337 return FALSE;
4338 }
4339
4340 pArgs.u32EngId = u32EngId;
4341 pArgs.u32DscmbId = u32DscmbId;
4342 pArgs.eEngType = eEngType;
4343 pArgs.eKeyType = eKeyType;
4344
4345 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_EngResetKey, (void*)&pArgs);
4346 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4347 {
4348 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4349 return FALSE;
4350 }
4351
4352 return TRUE;
4353 #else
4354 return _MDrv_DSCMB2_EngResetKey(u32EngId, u32DscmbId, eEngType, eKeyType);
4355 #endif
4356 }
4357
MDrv_DSCMB2_EngSetCAVid(MS_U32 u32EngId,MS_U32 u32DscmbId,MS_U32 u32CAVid)4358 MS_BOOL MDrv_DSCMB2_EngSetCAVid(MS_U32 u32EngId, MS_U32 u32DscmbId, MS_U32 u32CAVid)
4359 {
4360 return _MDrv_DSCMB2_EngSetCAVid(u32EngId, u32DscmbId, u32CAVid);
4361 }
4362
MDrv_DSCMB2_SetDefaultCAVid(MS_U32 u32EngId,MS_U32 u32CAVid)4363 MS_BOOL MDrv_DSCMB2_SetDefaultCAVid(MS_U32 u32EngId, MS_U32 u32CAVid)
4364 {
4365 #ifdef DSCMB_UTOPIA20
4366 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4367 DSCMB_DEFAULT_CAVID pArgs;
4368 memset(&pArgs, 0, sizeof(DSCMB_DEFAULT_CAVID));
4369 if(pu32DscmbInst == NULL)
4370 {
4371 return FALSE;
4372 }
4373
4374 pArgs.u32EngId = u32EngId;
4375 pArgs.u32CAVid = u32CAVid;
4376
4377 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_SetDefaultCAVid, (void*)&pArgs);
4378 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4379 {
4380 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4381 return FALSE;
4382 }
4383
4384 return TRUE;
4385 #else
4386 return _MDrv_DSCMB2_SetDefaultCAVid(u32EngId, u32CAVid);
4387 #endif
4388 }
4389
MDrv_DSCMB2_IsKTEValid(MS_U32 u32FltId,DSCMB_Key_Type eKeyType)4390 MS_BOOL MDrv_DSCMB2_IsKTEValid(MS_U32 u32FltId, DSCMB_Key_Type eKeyType)
4391 {
4392 return _MDrv_DSCMB2_IsKTEValid (u32FltId, eKeyType);
4393 }
4394
MDrv_DSCMB2_SetTSPCAVid(DSCMB_TSIF eSrcTSIf,MS_U32 u32CAVid)4395 MS_BOOL MDrv_DSCMB2_SetTSPCAVid(DSCMB_TSIF eSrcTSIf, MS_U32 u32CAVid)
4396 {
4397 return _MDrv_DSCMB2_SetTSPCAVid(eSrcTSIf, u32CAVid);
4398 }
4399
MDrv_DSCMB2_SetTSPCADst(MS_U32 u32FltId,MS_U32 u32UpDst,MS_U32 u32LowDst)4400 MS_BOOL MDrv_DSCMB2_SetTSPCADst(MS_U32 u32FltId, MS_U32 u32UpDst, MS_U32 u32LowDst)
4401 {
4402 return _MDrv_DSCMB2_SetTSPCADst(u32FltId, u32UpDst, u32LowDst);
4403 }
4404
MDrv_DSCMB2_DualPath_Enable(MS_U32 u32EngId,MS_U32 u32FltId)4405 MS_BOOL MDrv_DSCMB2_DualPath_Enable(MS_U32 u32EngId, MS_U32 u32FltId)
4406 {
4407 #ifdef DSCMB_UTOPIA20
4408 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4409 DSCMB_DUALPATH pArgs;
4410 memset(&pArgs, 0, sizeof(DSCMB_DUALPATH));
4411 if(pu32DscmbInst == NULL)
4412 {
4413 return FALSE;
4414 }
4415
4416 pArgs.u32EngId = u32EngId;
4417 pArgs.u32DmxFltId = u32FltId;
4418
4419 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_DualPath_Enable, (void*)&pArgs);
4420 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4421 {
4422 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4423 return FALSE;
4424 }
4425
4426 return TRUE;
4427 #else
4428 return _MDrv_DSCMB2_DualPath_Enable(u32EngId, u32FltId);
4429 #endif
4430 }
4431
MDrv_DSCMB2_DualPath_Disable(MS_U32 u32EngId,MS_U32 u32FltId)4432 MS_BOOL MDrv_DSCMB2_DualPath_Disable(MS_U32 u32EngId, MS_U32 u32FltId)
4433 {
4434 #ifdef DSCMB_UTOPIA20
4435 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4436 DSCMB_DUALPATH pArgs;
4437 memset(&pArgs, 0, sizeof(DSCMB_DUALPATH));
4438 if(pu32DscmbInst == NULL)
4439 {
4440 return FALSE;
4441 }
4442
4443 pArgs.u32EngId = u32EngId;
4444 pArgs.u32DmxFltId = u32FltId;
4445
4446 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_DualPath_Disable, (void*)&pArgs);
4447 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4448 {
4449 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4450 return FALSE;
4451 }
4452
4453 return TRUE;
4454 #else
4455 return _MDrv_DSCMB2_DualPath_Disable(u32EngId, u32FltId); //enable small switch pid_no dual path
4456 #endif
4457 }
4458
MDrv_DSCMB2_SPD_Enable(DSCMB_TSIF ePvrSrcTSIf)4459 MS_BOOL MDrv_DSCMB2_SPD_Enable(DSCMB_TSIF ePvrSrcTSIf)
4460 {
4461 return _MDrv_DSCMB2_SPD_Enable(ePvrSrcTSIf);
4462 }
4463
MDrv_DSCMB2_SPD_Disable(DSCMB_TSIF ePvrSrcTSIf)4464 MS_BOOL MDrv_DSCMB2_SPD_Disable(DSCMB_TSIF ePvrSrcTSIf)
4465 {
4466 return _MDrv_DSCMB2_SPD_Disable(ePvrSrcTSIf);
4467 }
4468
MDrv_DSCMB2_CAPVR_FlowSet(MS_U32 u32EngId,DSCMB_CAPVR_MODE eCaMode,DSCMB_TSIF ePvrSrcTsif)4469 MS_BOOL MDrv_DSCMB2_CAPVR_FlowSet(MS_U32 u32EngId, DSCMB_CAPVR_MODE eCaMode, DSCMB_TSIF ePvrSrcTsif)
4470 {
4471 #ifdef DSCMB_UTOPIA20
4472 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4473 DSCMB_CAPVR_FLOWSET pArgs;
4474 memset(&pArgs, 0, sizeof(DSCMB_CAPVR_FLOWSET));
4475 if(pu32DscmbInst == NULL)
4476 {
4477 return FALSE;
4478 }
4479
4480 pArgs.u32EngId = u32EngId;
4481 pArgs.eCaMode = eCaMode;
4482 pArgs.ePvrSrcTsif = ePvrSrcTsif;
4483
4484 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_CAPVR_FlowSet, (void*)&pArgs);
4485 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4486 {
4487 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4488 return FALSE;
4489 }
4490
4491 return TRUE;
4492 #else
4493 return _MDrv_DSCMB2_CAPVR_FlowSet(u32EngId, eCaMode, ePvrSrcTsif);
4494 #endif
4495 }
4496
MDrv_DSCMB2_SetPidPair(MS_U32 u32FltIdPri,MS_U32 u32FltIdSec)4497 MS_BOOL MDrv_DSCMB2_SetPidPair(MS_U32 u32FltIdPri, MS_U32 u32FltIdSec)
4498 {
4499 return _MDrv_DSCMB2_SetPidPair(u32FltIdPri, u32FltIdSec);
4500 }
4501
MDrv_DSCMB2_ClearPidPair(MS_U32 u32FltIdPri,MS_U32 u32FltIdSec)4502 MS_BOOL MDrv_DSCMB2_ClearPidPair(MS_U32 u32FltIdPri, MS_U32 u32FltIdSec)
4503 {
4504 return _MDrv_DSCMB2_ClearPidPair(u32FltIdPri, u32FltIdSec);
4505 }
4506
4507
MDrv_DSCMB2_FltTypeSet(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Type DscmbType)4508 MS_BOOL MDrv_DSCMB2_FltTypeSet(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Type DscmbType)
4509 {
4510 #ifdef DSCMB_UTOPIA20
4511 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4512 DSCMB_TYPESET pArgs;
4513 memset(&pArgs, 0, sizeof(DSCMB_TYPESET));
4514 if(pu32DscmbInst == NULL)
4515 {
4516 return FALSE;
4517 }
4518
4519 pArgs.u32EngId = u32EngId;
4520 pArgs.u32DscmbId = u32DscmbId;
4521 pArgs.eType = DscmbType;
4522
4523 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_FltTypeSet, (void*)&pArgs);
4524 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4525 {
4526 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4527 return FALSE;
4528 }
4529
4530 return TRUE;
4531 #else
4532 return _MDrv_DSCMB2_FltTypeSet(u32EngId, u32DscmbId, DscmbType);
4533 #endif
4534 }
4535
4536
4537
MDrv_DSCMB2_FltKeySet(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Key_Type eKeyType,MS_U8 * pu8Key)4538 MS_BOOL MDrv_DSCMB2_FltKeySet(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Key_Type eKeyType, MS_U8* pu8Key)
4539 {
4540 #ifdef DSCMB_UTOPIA20
4541 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4542 DSCMB_FLTKEYSET pArgs;
4543 memset(&pArgs, 0, sizeof(DSCMB_FLTKEYSET));
4544 if(pu32DscmbInst == NULL)
4545 {
4546 return FALSE;
4547 }
4548
4549 pArgs.u32EngId = u32EngId;
4550 pArgs.u32DscmbId = u32DscmbId;
4551 pArgs.eKeyType = eKeyType;
4552 pArgs.pu8Key = pu8Key;
4553
4554 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_FltKeySet, (void*)&pArgs);
4555 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4556 {
4557 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4558 return FALSE;
4559 }
4560
4561 return TRUE;
4562 #else
4563 return _MDrv_DSCMB2_FltKeySet(u32EngId, u32DscmbId, eKeyType, pu8Key);
4564 #endif
4565 }
4566
MDrv_DSCMB2_FltIVSet(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Key_Type eKeyType,MS_U8 * pu8IV)4567 MS_BOOL MDrv_DSCMB2_FltIVSet(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Key_Type eKeyType, MS_U8* pu8IV)
4568 {
4569 #ifdef DSCMB_UTOPIA20
4570 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4571 DSCMB_FLTIVSET pArgs;
4572 memset(&pArgs, 0, sizeof(DSCMB_FLTIVSET));
4573 if(pu32DscmbInst == NULL)
4574 {
4575 return FALSE;
4576 }
4577
4578 pArgs.u32EngId = u32EngId;
4579 pArgs.u32DscmbId = u32DscmbId;
4580 pArgs.eKeyType = eKeyType;
4581 pArgs.pu8IV = pu8IV;
4582
4583 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_FltIVSet, (void*)&pArgs);
4584 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4585 {
4586 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4587 return FALSE;
4588 }
4589
4590 return TRUE;
4591 #else
4592 return _MDrv_DSCMB2_FltIVSet(u32EngId, u32DscmbId, eKeyType, pu8IV);
4593 #endif
4594 }
4595
4596
MDrv_DSCMB2_FltKeyReset(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Key_Type eKeyType)4597 MS_BOOL MDrv_DSCMB2_FltKeyReset(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Key_Type eKeyType)
4598 {
4599 #ifdef DSCMB_UTOPIA20
4600 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4601 DSCMB_FLTKEYRESET pArgs;
4602 memset(&pArgs, 0, sizeof(DSCMB_FLTKEYRESET));
4603 if(pu32DscmbInst == NULL)
4604 {
4605 return FALSE;
4606 }
4607
4608 pArgs.u32EngId = u32EngId;
4609 pArgs.u32DscmbId = u32DscmbId;
4610 pArgs.eKeyType = eKeyType;
4611 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_FltKeyReset, (void*)&pArgs);
4612
4613 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4614 {
4615 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4616 return FALSE;
4617 }
4618
4619 return TRUE;
4620 #else
4621 return _MDrv_DSCMB2_FltKeyReset(u32EngId, u32DscmbId, eKeyType);
4622 #endif
4623 }
4624
MDrv_DSCMB2_FltDscmb(MS_U32 u32EngId,MS_U32 u32DscmbId,MS_BOOL bDscmb)4625 MS_BOOL MDrv_DSCMB2_FltDscmb(MS_U32 u32EngId, MS_U32 u32DscmbId, MS_BOOL bDscmb)
4626 {
4627 #ifdef DSCMB_UTOPIA20
4628 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4629 DSCMB_FLTDSCMB pArgs;
4630 memset(&pArgs, 0, sizeof(DSCMB_FLTDSCMB));
4631 if(pu32DscmbInst == NULL)
4632 {
4633 return FALSE;
4634 }
4635
4636 pArgs.u32EngId = u32EngId;
4637 pArgs.u32DscmbId = u32DscmbId;
4638 pArgs.bDscmb = bDscmb;
4639
4640 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_FltDscmb, (void*)&pArgs);
4641 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4642 {
4643 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4644 return FALSE;
4645 }
4646
4647 return TRUE;
4648 #else
4649 return _MDrv_DSCMB2_FltDscmb(u32EngId, u32DscmbId, bDscmb);
4650 #endif
4651 }
4652
4653 #if !(defined(MSOS_TYPE_OPTEE) || defined(MSOS_TYPE_NUTTX))
MDrv_DSCMB2_FltDisconnectPid_Ex(MS_U32 u32EngId,MS_U32 u32DscmbId,MS_U32 u32Pid)4654 DLL_PUBLIC MS_BOOL MDrv_DSCMB2_FltDisconnectPid_Ex(MS_U32 u32EngId, MS_U32 u32DscmbId, MS_U32 u32Pid)
4655 {
4656 #ifdef DSCMB_UTOPIA20
4657 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4658 DSCMB_DISCONNECTPID pArgs;
4659 memset(&pArgs, 0, sizeof(DSCMB_DISCONNECTPID));
4660 if(pu32DscmbInst == NULL)
4661 {
4662 return FALSE;
4663 }
4664
4665 pArgs.u32EngId = u32EngId;
4666 pArgs.u32DscmbId = u32DscmbId;
4667 pArgs.u32Pid = u32Pid;
4668 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_FltDisconnectPid, (void*)&pArgs);
4669
4670 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4671 {
4672 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4673 return FALSE;
4674 }
4675
4676 return TRUE;
4677 #else
4678 return _MDrv_DSCMB2_FltDisconnectPid_Ex(u32EngId, u32DscmbId, u32Pid);
4679 #endif
4680
4681 }
4682
MDrv_DSCMB2_FltConnectPid(MS_U32 u32EngId,MS_U32 u32DscmbId,MS_U32 u32Pid)4683 MS_BOOL MDrv_DSCMB2_FltConnectPid(MS_U32 u32EngId, MS_U32 u32DscmbId, MS_U32 u32Pid)
4684 {
4685 #ifdef DSCMB_UTOPIA20
4686 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4687 DSCMB_CONNECTPID pArgs;
4688 memset(&pArgs, 0, sizeof(DSCMB_CONNECTPID));
4689 if(pu32DscmbInst == NULL)
4690 {
4691 return FALSE;
4692 }
4693
4694 pArgs.u32EngId = u32EngId;
4695 pArgs.u32DscmbId = u32DscmbId;
4696 pArgs.u32Pid = u32Pid;
4697
4698 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_FltConnectPid, (void*)&pArgs);
4699 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4700 {
4701 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4702 return FALSE;
4703 }
4704
4705 return TRUE;
4706 #else
4707 return _MDrv_DSCMB2_FltConnectPid(u32EngId, u32DscmbId, u32Pid);
4708 #endif
4709 }
4710
4711
MDrv_DSCMB2_FltDisconnectPid(MS_U32 u32EngId,MS_U32 u32DscmbId,MS_U32 u32Pid)4712 MS_BOOL MDrv_DSCMB2_FltDisconnectPid(MS_U32 u32EngId, MS_U32 u32DscmbId, MS_U32 u32Pid)
4713 {
4714 return MDrv_DSCMB2_FltDisconnectPid_Ex(u32EngId, u32DscmbId, u32Pid);
4715 }
4716 #endif
4717
4718 //----------------------------------------------------------------------//
4719 // New Interface for K3 Series //
4720 //----------------------------------------------------------------------//
MDrv_DSCMB2_KLadder_AtomicExec(DSCMB_KLCfg_All * KLCfg,MS_U8 * ACPU_Out,DSCMB_KL_Status * u32Status)4721 MS_BOOL MDrv_DSCMB2_KLadder_AtomicExec(DSCMB_KLCfg_All* KLCfg , MS_U8 *ACPU_Out, DSCMB_KL_Status* u32Status)
4722 {
4723 #ifdef DSCMB_UTOPIA20
4724 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4725 DSCMB_KL_ATOMICEXEC pArgs;
4726 memset(&pArgs, 0, sizeof(DSCMB_KL_ATOMICEXEC));
4727 if(pu32DscmbInst == NULL)
4728 {
4729 return FALSE;
4730 }
4731
4732 pArgs.KLCfg = KLCfg;
4733 pArgs.ACPU_Out = ACPU_Out;
4734 pArgs.u32Status = u32Status;
4735
4736 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_KLadder_AtomicExec, (void*)&pArgs);
4737 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4738 {
4739 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4740 return FALSE;
4741 }
4742
4743 return TRUE;
4744
4745 #else
4746 return _MDrv_DSCMB2_KLadder_AtomicExec(KLCfg, ACPU_Out, u32Status);
4747 #endif
4748 }
4749
4750
4751 //--------------------------------------------------------------------------------------------------
4752 /// An atomic Key ladder function for TCSA3 Key generation.
4753 /// Thread safe for cuncurrent usage.
4754 /// @param KLCfg\b IN: KL execution setting for target key generation
4755 /// @param ACPU_Out\b IN: A 16 bytes array pointer for Acpu key output.
4756 /// @param u32Status\b IN: Key ladder running status
4757 /// @return TRUE - Success
4758 /// @return FALSE - Failure
4759 //--------------------------------------------------------------------------------------------------
4760 #if 0
4761 MS_BOOL MDrv_DSCMB2_KLadder_TCSA3(DSCMB_KLCfg_All* KLCfg , MS_U8 *pu8ActCode, MS_U32 u32CHSel, DSCMB_KL_Status* u32Status )
4762 {
4763 return _MDrv_DSCMB2_KLadder_TCSA3(KLCfg, pu8ActCode, u32CHSel, u32Status);
4764 }
4765 #endif
4766
MDrv_DSCMB2_KLadder_ETSI(DSCMB_KLCfg_All * KLCfg,MS_U8 * ACPU_Out,MS_U8 * pu8Nonce,MS_U8 * pu8Response,DSCMB_KL_Status * u32Status)4767 MS_BOOL MDrv_DSCMB2_KLadder_ETSI(DSCMB_KLCfg_All* KLCfg , MS_U8 *ACPU_Out, MS_U8 *pu8Nonce, MS_U8 *pu8Response, DSCMB_KL_Status* u32Status )
4768 {
4769 #ifdef DSCMB_UTOPIA20
4770 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
4771 DSCMB_KL_ETSI pArgs;
4772 memset(&pArgs, 0, sizeof(DSCMB_KL_ETSI));
4773 if(pu32DscmbInst == NULL)
4774 {
4775 return FALSE;
4776 }
4777 pArgs.KLCfg = KLCfg;
4778 pArgs.ACPU_Out = ACPU_Out;
4779 pArgs.pu8Nonce = pu8Nonce;
4780 pArgs.pu8Response = pu8Response;
4781 pArgs.u32Status = u32Status;
4782
4783 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_KLadder_ETSI, &pArgs);
4784 if(UTOPIA_STATUS_SUCCESS != u32Ret)
4785 {
4786 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
4787 return FALSE;
4788 }
4789
4790 return TRUE;
4791
4792 #else
4793 return _MDrv_DSCMB2_KLadder_ETSI(KLCfg, ACPU_Out, pu8Nonce, pu8Response, u32Status);
4794 #endif
4795 }
4796
4797 #if 0
4798 MS_BOOL MDrv_DSCMB2_KLadder_TA(DSCMB_KLCfg_All* KLCfg , MS_U8* ACPU_Out, DSCMB_KL_Status* u32Status)
4799 {
4800 DSCMB_INIT_CHECK(FALSE);
4801
4802 MS_U32 i = 0;
4803 MS_U32 u32ErrMsg = 0;
4804 *u32Status = KL_STATUS_KEY_OK ;
4805 DSCMB_KL_SelEng eKLEng = KLCfg->eKLSel;
4806 MS_U32 u32FltId = 0;
4807 MS_U32 u32Field = 0;
4808 DSCMB_KLDst eKLDst = KLCfg->eDst;
4809 MS_U32 u32CAVid = KLCfg->u32CAVid;
4810
4811 MDrv_DSCMB_KLadder_Lock();
4812 ///translate cavid to Default CAVID if user set input cavid to 0x0
4813 if(u32CAVid == 0)
4814 {
4815 u32CAVid = DEFAULT_CAVID;
4816 }
4817
4818 /////////////// Check Source and acpu data ////////////////////
4819 if ((E_DSCMB_KL_SRC_ACPU == KLCfg->eSrc) && (NULL == KLCfg->u8KeyACPU))
4820 {
4821 *u32Status = KL_STATUS_ACPU_KEY_NULL;
4822 goto KL_Fail;
4823 }
4824
4825 /////////////// Check KL level ////////////////////
4826 if((KLCfg->u32Level >3) && (KLCfg->u32Level != 9) && (KLCfg->u32Level != 0xD))
4827 {
4828 //bKeepRound = TRUE ;
4829 *u32Status = KL_STATUS_INVALID_INPUT_LEVEL;
4830 goto KL_Fail;
4831 }
4832 else if(( 0 == KLCfg->u32Level ) && (0==(DSCMB_KL_DST_CLASS_DMA & eKLDst)))
4833 {
4834 *u32Status = KL_STATUS_INVALID_INPUT_LEVEL;
4835 goto KL_Fail;
4836 }
4837
4838 ////////////// check Key destination ///////////////
4839 /// Compatible and translate old version to new version
4840 if( ((KLCfg->eDst & 0xF0) == 0) && ( (KLCfg->eDst & 0x0F) > 0 )) //OLD Destination
4841 {
4842 switch(KLCfg->eDst)
4843 {
4844 case E_DSCMB_KL_DST_ACPU:
4845 eKLDst = E_DSCMB_KL_DST_CPU_ACPU;
4846 break;
4847 case E_DSCMB_KL_DST_KT_NSA:
4848 eKLDst = E_DSCMB_KL_DST_KT_ESA;
4849 break;
4850 case E_DSCMB_KL_DST_DMA_AES:
4851 eKLDst = E_DSCMB_KL_DST_DMA_SK0;
4852 break;
4853 case E_DSCMB_KL_DST_DMA_TDES:
4854 eKLDst = E_DSCMB_KL_DST_DMA_SK0;
4855 break;
4856 case E_DSCMB_KL_DST_PRIVATE0:
4857 eKLDst = E_DSCMB_KL_DST_PRIVATE_0;
4858 break;
4859 case E_DSCMB_KL_DST_PRIVATE1:
4860 eKLDst = E_DSCMB_KL_DST_PRIVATE_1;
4861 break;
4862 case E_DSCMB_KL_DST_PRIVATE2:
4863 eKLDst = E_DSCMB_KL_DST_PRIVATE_2;
4864 break;
4865 default:
4866 ;
4867 }
4868 }
4869
4870 if (E_DSCMB_KL_DST_CPU_ACPU == eKLDst)
4871 {
4872 //KL to ACPU
4873 if(NULL == ACPU_Out)
4874 {
4875 *u32Status = KL_STATUS_ACPU_OUTKEY_NULL;
4876 goto KL_Fail;
4877 }
4878 }
4879 else if (DSCMB_KL_DST_CLASS_KT & eKLDst)
4880 {
4881 //KL to KT
4882 if ( FALSE == DscmbTspMap[KLCfg->u32EngID][KLCfg->u32DscID].bUsed )
4883 {
4884 //The keyslot is not allocated for the DSCMB ID
4885 *u32Status = KL_STATUS_IVALID_DSCMB_ID;
4886 goto KL_Fail;
4887 }
4888 if( 0 == DscmbTspMap[KLCfg->u32EngID][KLCfg->u32DscID].u32PidFltIdNum )
4889 {
4890 //No pid filter is connected to the DSCMB ID
4891 *u32Status = KL_STATUS_IVALID_DSCMB_ID;
4892 goto KL_Fail;
4893 }
4894
4895 // Get Filter ID
4896 if(FALSE == _DSCMB_Dscmb2Flt(KLCfg->u32DscID, &u32FltId))
4897 {
4898 *u32Status = KL_STATUS_IVALID_DSCMB_ID;
4899 goto KL_Fail;
4900 }
4901
4902 // Get Field
4903
4904 }
4905 else if (DSCMB_KL_DST_CLASS_DMA & eKLDst)
4906 {
4907 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Keyladder destination DMA class\n");
4908 }
4909 else if(DSCMB_KL_DST_CLASS_PVT &eKLDst)
4910 {
4911 //KL to PVT
4912 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Keyladder destination Private Key class\n");
4913 }
4914 else
4915 {
4916 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Unknown Keyladder destination\n");
4917 *u32Status = KL_STATUS_KL_INPUT_NULL;
4918 goto KL_Fail;
4919 }
4920
4921 //Check KeyLadder Input
4922 if ((KLCfg->u32Level != 0) && (NULL == KLCfg->pu8KeyKLIn))
4923 {
4924 *u32Status = KL_STATUS_KL_INPUT_NULL;
4925 goto KL_Fail;
4926 }
4927
4928 if((_u8KLPreLevel == 9) || ((_u8KLPreLevel == 9) && (KLCfg->u32Level == 1)))
4929 {
4930 _u8KLPreLevel = KLCfg->u32Level;
4931 DRVDSCMB2_DBG(DSCMB2_DBGLV_DEBUG, "Keyladder keep round and not reset \n");
4932 }
4933 else
4934 {
4935 _u8KLPreLevel = KLCfg->u32Level;
4936 HAL_DSCMB_KL_Reset(eKLEng);
4937 }
4938
4939 if(E_DSCMB_KL_SRC_ACPU == KLCfg->eSrc)
4940 {
4941 HAL_DSCMB_KL_ACPURootKey(eKLEng, KLCfg->u8KeyACPU);
4942 }
4943
4944
4945 DRVDSCMB2_DBG(DSCMB2_DBGLV_INFO, "u32CAVid=%lX\n", (unsigned long)u32CAVid);
4946 //FIXME: If Key from OTP, should we set usage & entropy ?
4947 HAL_DSCMB_KL_KeyProp( eKLEng, u32CAVid, 0 , /*Usage*/ 0 /*Entropy*/);
4948
4949 // Set KL Level input //
4950 if(KLCfg->u32Level == 9) //Keep round, 1 stage
4951 {
4952 HAL_DSCMB_KL_Input(eKLEng, 0, KLCfg->pu8KeyKLIn);
4953 }
4954 else if(KLCfg->u32Level == 0xD) //SMI Keyladder
4955 {
4956 for( i = 0 ; i < 5 ; i ++ )
4957 {
4958 HAL_DSCMB_KL_Input(eKLEng, (4 - i), KLCfg->pu8KeyKLIn+(16*i));
4959 }
4960 }
4961 else if(KLCfg->u32Level <= 3) //0~3 level keyladder
4962 {
4963 for( i = 0 ; i < KLCfg->u32Level ; i ++ )
4964 {
4965 HAL_DSCMB_KL_Input(eKLEng, (KLCfg->u32Level-i-1), KLCfg->pu8KeyKLIn+(16*i));
4966 }
4967 }
4968 else
4969 {
4970 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "Unknown Keyladder type(level) setting\n");
4971 *u32Status = KL_STATUS_INVALID_INPUT_LEVEL;
4972 goto KL_Fail;
4973 }
4974
4975 //Set Transformed Algorithm EncCW
4976 if(FALSE == HAL_DSCMB_KL_TA_EncCW(eKLEng, KLCfg->pu8KeyKLIn+(16*(KLCfg->u32Level-1)) ))
4977 {
4978 *u32Status = KL_STATUS_KL_INPUT_NULL;
4979 goto KL_Fail;
4980 }
4981 //Set Transformed Algorithm LUT3 table address
4982 HAL_DSCMB_KL_TA_LUT3(eKLEng, NULL);
4983
4984 //Enable TA and lock LUT3 table and KL SRAM
4985 HAL_DSCMB_KL_TA_EN(eKLEng, TRUE);
4986
4987 // Set KL Ctrl
4988 HAL_DSCMB_KL_Ctrl(eKLEng, KLCfg->eAlgo,
4989 KLCfg->u32Level,
4990 KLCfg->eSrc,
4991 eKLDst);
4992
4993 if (DSCMB_KL_DST_CLASS_CPU & eKLDst)
4994 {
4995 // KL flow for ACPU output //
4996
4997 HAL_DSCMB_KL_KeyBus(eKLEng,
4998 0, /*For Dst KT*/
4999 0, /*For Dst KT*/
5000 0, /*For Dst KT*/
5001 0); /*For Dst DMA*/
5002 }
5003 else if (DSCMB_KL_DST_CLASS_DMA & eKLDst)
5004 {
5005 // KL flow for output to CryptoDMA //
5006 HAL_DSCMB_KL_KeyBus(eKLEng,
5007 0, /*For Dst KT*/
5008 0, /*For Dst KT*/
5009 0, /*For Dst KT*/
5010 eKLDst); /*For Dst DMA*/
5011 }
5012 else if (DSCMB_KL_DST_CLASS_KT & eKLDst)
5013 {
5014 // KL flow for output to KTE //
5015 HAL_DSCMB_KL_KeyBus(eKLEng,
5016 u32FltId, /*For Dst KT*/
5017 u32Field, /*For Dst KT*/
5018 KLCfg->eKeyType, /*For Dst KT*/
5019 eKLDst); /*For Dst KT*/
5020 }
5021 else if (DSCMB_KL_DST_CLASS_PVT & eKLDst)
5022 {
5023 // KL flow for output to PVT //
5024 HAL_DSCMB_KL_KeyBus(eKLEng,
5025 0, /*For Dst KT*/
5026 0, /*For Dst KT*/
5027 0, /*For Dst KT*/
5028 0); /*For Dst DMA*/
5029 }
5030
5031 if(HAL_DSCMB_KL_Start(eKLEng) == FALSE)
5032 {
5033 HAL_DSCMB_KL_ErrMsg(eKLEng, &u32ErrMsg);
5034 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "\033[31m KL error message 0x%X\n\033[m", (unsigned int)u32ErrMsg);
5035 goto KL_Fail;
5036 }
5037
5038 // enable key
5039 if (DSCMB_KL_DST_CLASS_KT & eKLDst)
5040 {
5041 DSCMB_Eng_Type eEngType = E_DSCMB_ENG_ESA;
5042 if(eKLDst == E_DSCMB_KL_DST_KT_ESA )
5043 {
5044 eEngType = E_DSCMB_ENG_ESA;
5045 }
5046 else if(eKLDst == E_DSCMB_KL_DST_KT_LSAS )
5047 {
5048 eEngType = E_DSCMB_ENG_LSAS;
5049 }
5050 else if(eKLDst == E_DSCMB_KL_DST_KT_LSAD )
5051 {
5052 eEngType = E_DSCMB_ENG_LSAD;
5053 }
5054
5055 if (FALSE == HAL_DSCMB_KTE_Key_Ctrl_Ex(u32FltId,
5056 KLCfg->eKeyType,
5057 eEngType,
5058 KLCfg->u32CAVid,
5059 TRUE,
5060 TRUE))
5061 {
5062 *u32Status = KL_STATUS_KL_INPUT_NULL;
5063 goto KL_Fail;
5064 }
5065 }
5066
5067 //Output to ACPU
5068 if (E_DSCMB_KL_DST_CPU_ACPU == eKLDst)
5069 {
5070 MS_U32 u32OutKeySize = 0;
5071 if(KLCfg->eOutsize == E_DSCMB_KL_64_BITS)
5072 {
5073 u32OutKeySize = 8;
5074 }
5075 else if(KLCfg->eOutsize == E_DSCMB_KL_128_BITS)
5076 {
5077 u32OutKeySize = 16;
5078 }
5079 memset(ACPU_Out , 0x0 , u32OutKeySize );
5080 HAL_DSCMB_KL_GetACPUOut(eKLEng,ACPU_Out,u32OutKeySize);
5081 }
5082
5083 //Unlock LUT3 table and KL SRAM
5084 HAL_DSCMB_KL_TA_EN(eKLEng, FALSE);
5085 MDrv_DSCMB_KLadder_Unlock();
5086 return TRUE;
5087
5088
5089 KL_Fail:
5090
5091
5092 #if 0
5093
5094 i = HAL_DSCMB_KLadder_Status();
5095 if ( i != 0 )
5096 {
5097 //printf("KL Satus = %x \n",i );
5098 *u32Status |= i ;
5099 }
5100
5101 MDrv_DSCMB_KLadder_Stop();
5102 #endif
5103
5104 MDrv_DSCMB_KLadder_Unlock();
5105 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "DSCMB KL Fail = %08lX \n",(unsigned long)*u32Status);
5106
5107 DSCMB_ASSERT_AND_RETURN(FALSE);
5108
5109 return FALSE;
5110
5111 }
5112 #endif
5113
MDrv_DSCMB2_GetCap(MS_U32 u32EngId,DSCMB_Query_Type eQueryType,void * pInput,void * pOutput)5114 MS_BOOL MDrv_DSCMB2_GetCap(MS_U32 u32EngId, DSCMB_Query_Type eQueryType, void* pInput, void* pOutput)
5115 {
5116 #ifdef DSCMB_UTOPIA20
5117 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
5118 DSCMB_QUERYCAP pArgs;
5119 memset(&pArgs, 0, sizeof(DSCMB_QUERYCAP));
5120 if(pu32DscmbInst == NULL)
5121 {
5122 return FALSE;
5123 }
5124 pArgs.u32EngId = u32EngId;
5125 pArgs.eQueryType = eQueryType;
5126 pArgs.pInput = pInput;
5127 pArgs.pOutput = pOutput;
5128
5129 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_QueryCap, &pArgs);
5130 if(UTOPIA_STATUS_SUCCESS != u32Ret)
5131 {
5132 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
5133 return FALSE;
5134 }
5135
5136 return TRUE;
5137
5138 #else
5139 return _MDrv_DSCMB2_GetCap(u32EngId, eQueryType, pInput, pOutput);
5140 #endif
5141 }
5142
MDrv_DSCMB2_GetLibVer(const MSIF_Version ** ppVersion)5143 MS_BOOL MDrv_DSCMB2_GetLibVer(const MSIF_Version **ppVersion)
5144 {
5145 #ifdef DSCMB_UTOPIA20
5146 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
5147 const MSIF_Version** pArgs = ppVersion;
5148
5149 if(pu32DscmbInst == NULL)
5150 {
5151 return FALSE;
5152 }
5153
5154 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_GetLibVer , pArgs);
5155 if(UTOPIA_STATUS_SUCCESS != u32Ret)
5156 {
5157 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
5158 return FALSE;
5159 }
5160
5161 return TRUE;
5162
5163 #else
5164 return _MDrv_DSCMB2_GetLibVer(ppVersion);
5165 #endif
5166 }
5167
5168 //--------------------------------------------------------------------------------------------------
5169 /// Set Dscmb driver debug level
5170 /// @param u32Level \b IN: debug level
5171 /// @return TRUE - Success
5172 /// @return FALSE - Failure
5173 //--------------------------------------------------------------------------------------------------
MDrv_DSCMB2_SetDBGLevel(MS_U32 u32Level)5174 MS_BOOL MDrv_DSCMB2_SetDBGLevel(MS_U32 u32Level)
5175 {
5176 #ifdef DSCMB_UTOPIA20
5177 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
5178 MS_U32 pArgs = u32Level;
5179
5180 if(pu32DscmbInst == NULL)
5181 {
5182 return FALSE;
5183 }
5184
5185 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_SetDBGLevel , &pArgs);
5186 if(UTOPIA_STATUS_SUCCESS != u32Ret)
5187 {
5188 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
5189 return FALSE;
5190 }
5191
5192 return TRUE;
5193
5194 #else
5195 return _MDrv_DSCMB2_SetDBGLevel(u32Level);
5196 #endif
5197 }
5198
MDrv_DSCMB2_PVR_RecCtrl(MS_U32 u32EngId,MS_BOOL Enable)5199 MS_BOOL MDrv_DSCMB2_PVR_RecCtrl(MS_U32 u32EngId, MS_BOOL Enable)
5200 {
5201 #ifdef DSCMB_UTOPIA20
5202 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
5203 DSCMB_PVR_RECCTRL pArgs;
5204 memset(&pArgs, 0, sizeof(DSCMB_PVR_RECCTRL));
5205 if(pu32DscmbInst == NULL)
5206 {
5207 return FALSE;
5208 }
5209
5210 pArgs.u32EngId = u32EngId;
5211 pArgs.bEnable = Enable;
5212
5213 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_PVR_RecCtrl, &pArgs);
5214 if(UTOPIA_STATUS_SUCCESS != u32Ret)
5215 {
5216 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
5217 return FALSE;
5218 }
5219
5220 return TRUE;
5221
5222 #else
5223 return _MDrv_DSCMB2_PVR_RecCtrl(u32EngId, Enable);
5224 #endif
5225 }
5226
MDrv_DSCMB2_PidFlt_ScmbStatus(MS_U32 u32EngId,MS_U32 u32PidFltId,SCMB_Level * pScmbLevel)5227 MS_BOOL MDrv_DSCMB2_PidFlt_ScmbStatus(MS_U32 u32EngId, MS_U32 u32PidFltId, SCMB_Level* pScmbLevel)
5228 {
5229 #ifdef DSCMB_UTOPIA20
5230 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
5231 DSCMB_DSCMBSTATUS pArgs;
5232 memset(&pArgs, 0, sizeof(DSCMB_DSCMBSTATUS));
5233 if(pu32DscmbInst == NULL)
5234 {
5235 return FALSE;
5236 }
5237
5238 pArgs.u32EngId = u32EngId;
5239 pArgs.u32DmxFltId = u32PidFltId;
5240 pArgs.pScmbLevel = pScmbLevel;
5241
5242 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_PidFlt_ScmbStatus, (void*)&pArgs);
5243 if(UTOPIA_STATUS_SUCCESS != u32Ret)
5244 {
5245 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
5246 return FALSE;
5247 }
5248
5249 return TRUE;
5250 #else
5251 return _MDrv_DSCMB2_PidFlt_ScmbStatus(u32EngId, u32PidFltId, pScmbLevel);
5252 #endif
5253 }
5254
MDrv_DSCMB2_Multi2_SetRound(MS_U32 u32EngId,MS_U32 u32Round)5255 MS_BOOL MDrv_DSCMB2_Multi2_SetRound(MS_U32 u32EngId, MS_U32 u32Round)
5256 {
5257 #ifdef DSCMB_UTOPIA20
5258 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
5259 DSCMB_MULTI2_SETROUND pArgs;
5260 memset(&pArgs, 0, sizeof(DSCMB_MULTI2_SETROUND));
5261 if(pu32DscmbInst == NULL)
5262 {
5263 return FALSE;
5264 }
5265 pArgs.u32EngId = u32EngId;
5266 pArgs.u32Round = u32Round;
5267
5268 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_Multi2_SetRound, &pArgs);
5269 if(UTOPIA_STATUS_SUCCESS != u32Ret)
5270 {
5271 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
5272 return FALSE;
5273 }
5274
5275 return TRUE;
5276
5277 #else
5278 return _MDrv_DSCMB2_Multi2_SetRound(u32EngId, u32Round);
5279 #endif
5280 }
5281
MDrv_DSCMB2_Multi2_SetSystemKey(MS_U32 u32EngId,MS_U8 * pu8Syskey)5282 MS_BOOL MDrv_DSCMB2_Multi2_SetSystemKey(MS_U32 u32EngId, MS_U8* pu8Syskey)
5283 {
5284 #ifdef DSCMB_UTOPIA20
5285 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
5286 DSCMB_MULTI2_SETSYSKEY pArgs;
5287 memset(&pArgs, 0, sizeof(DSCMB_MULTI2_SETSYSKEY));
5288 if(pu32DscmbInst == NULL)
5289 {
5290 return FALSE;
5291 }
5292 pArgs.u32EngId = u32EngId;
5293 pArgs.pu8SysKey = pu8Syskey;
5294
5295 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_Multi2_SetSysKey, &pArgs);
5296 if(UTOPIA_STATUS_SUCCESS != u32Ret)
5297 {
5298 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
5299 return FALSE;
5300 }
5301
5302 return TRUE;
5303
5304 #else
5305 return _MDrv_DSCMB2_Multi2_SetSystemKey(u32EngId, pu8Syskey);
5306 #endif
5307 }
5308
MDrv_DSCMB2_ES_SetStaticKey(MS_U32 u32EngId,MS_U8 * pu8Statickey)5309 MS_BOOL MDrv_DSCMB2_ES_SetStaticKey(MS_U32 u32EngId, MS_U8* pu8Statickey)
5310 {
5311 #ifdef DSCMB_UTOPIA20
5312 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
5313 DSCMB_ES_SETSTATICKEY pArgs;
5314 memset(&pArgs, 0, sizeof(DSCMB_ES_SETSTATICKEY));
5315 if(pu32DscmbInst == NULL)
5316 {
5317 return FALSE;
5318 }
5319 pArgs.u32EngId = u32EngId;
5320 pArgs.pu8StaticKey = pu8Statickey;
5321
5322 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_ES_SetStaticKey, &pArgs);
5323 if(UTOPIA_STATUS_SUCCESS != u32Ret)
5324 {
5325 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
5326 return FALSE;
5327 }
5328
5329 return TRUE;
5330
5331 #else
5332 return _MDrv_DSCMB2_ES_SetStaticKey(u32EngId, pu8Statickey);
5333 #endif
5334 }
5335
MDrv_DSCMB2_HDCP2_SetRIV(MS_U32 u32EngId,MS_U8 * pu8RIV)5336 MS_BOOL MDrv_DSCMB2_HDCP2_SetRIV(MS_U32 u32EngId, MS_U8* pu8RIV)
5337 {
5338 #ifdef DSCMB_UTOPIA20
5339 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
5340 DSCMB_HDCP2_SETRIV pArgs;
5341 memset(&pArgs, 0, sizeof(DSCMB_HDCP2_SETRIV));
5342 if(pu32DscmbInst == NULL)
5343 {
5344 return FALSE;
5345 }
5346 pArgs.u32EngId = u32EngId;
5347 pArgs.pu8Riv = pu8RIV;
5348
5349 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_HDCP2_SetRiv, &pArgs);
5350 if(UTOPIA_STATUS_SUCCESS != u32Ret)
5351 {
5352 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
5353 return FALSE;
5354 }
5355
5356 return TRUE;
5357
5358 #else
5359 return _MDrv_DSCMB2_HDCP2_SetRIV(u32EngId, pu8RIV);
5360 #endif
5361
5362 }
5363
MDrv_DSCMB2_HDCP2_SetRIV_Ex(MS_U32 u32EngId,MS_U32 u32DscmbId,MS_U8 * pu8RIV)5364 MS_BOOL MDrv_DSCMB2_HDCP2_SetRIV_Ex(MS_U32 u32EngId, MS_U32 u32DscmbId, MS_U8* pu8RIV)
5365 {
5366 #ifdef DSCMB_UTOPIA20
5367 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
5368 DSCMB_HDCP2_SETRIV_EX pArgs;
5369 memset(&pArgs, 0, sizeof(DSCMB_HDCP2_SETRIV_EX));
5370 if(pu32DscmbInst == NULL)
5371 {
5372 return FALSE;
5373 }
5374 pArgs.u32EngId = u32EngId;
5375 pArgs.u32DscmbId = u32DscmbId;
5376 pArgs.pu8Riv = pu8RIV;
5377
5378 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_HDCP2_SetRiv_Ex, &pArgs);
5379 if(UTOPIA_STATUS_SUCCESS != u32Ret)
5380 {
5381 DRVDSCMB2_DBG(DSCMB2_DBGLV_ERR, "[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret);
5382 return FALSE;
5383 }
5384
5385 return TRUE;
5386
5387 #else
5388 return _MDrv_DSCMB2_HDCP2_SetRIV_Ex(u32EngId, u32DscmbId, pu8RIV);
5389 #endif
5390 }
5391
5392
5393 //------------------------------------- ------------------//
5394 //----------------------Debug API -------------------------//
5395 //-------------------------------------------------------//
MDrv_DSCMB2_GetConnectStatus(MS_U32 u32EngId,MS_U32 u32DscmbId,MS_U32 u32TspFltId)5396 MS_BOOL MDrv_DSCMB2_GetConnectStatus(MS_U32 u32EngId, MS_U32 u32DscmbId, MS_U32 u32TspFltId)
5397 {
5398 #ifdef DSCMB_UTOPIA20
5399 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
5400 DSCMB_CONNECTSTATUS pArgs;
5401 memset(&pArgs, 0, sizeof(DSCMB_CONNECTSTATUS));
5402 if(pu32DscmbInst == NULL)
5403 {
5404 return FALSE;
5405 }
5406 pArgs.u32EngId = u32EngId;
5407 pArgs.u32DscmbId = u32DscmbId;
5408 pArgs.u32DmxFltId = u32TspFltId;
5409
5410 u32Ret = UtopiaIoctl(pu32DscmbInst, E_MDRV_CMD_DSCMB_GetConnectStatus, &pArgs);
5411 if(UTOPIA_STATUS_SUCCESS != u32Ret)
5412 {
5413 return FALSE;
5414 }
5415
5416 return TRUE;
5417
5418 #else
5419 return _MDrv_DSCMB2_GetConnectStatus(u32EngId, u32DscmbId, u32TspFltId);
5420 #endif
5421 }
5422
MDrv_DSCMB2_ReadSwitch(MS_U32 u32FltId,DSCMB_Key_Type type,MS_U32 u32CAVid)5423 void MDrv_DSCMB2_ReadSwitch(MS_U32 u32FltId, DSCMB_Key_Type type, MS_U32 u32CAVid)
5424 {
5425 _MDrv_DSCMB2_ReadSwitch(u32FltId, type, u32CAVid);
5426 }
5427
MDrv_DSCMB2_ReadPidSlotMap(MS_U32 u32FltId)5428 void MDrv_DSCMB2_ReadPidSlotMap(MS_U32 u32FltId)
5429 {
5430 _MDrv_DSCMB2_ReadPidSlotMap(u32FltId);
5431 }
5432
MDrv_DSCMB2_PacketView(MS_U32 u32Eng,MS_U32 u32FltId,MS_U32 Mode,MS_U32 u32Range,MS_BOOL bRst)5433 void MDrv_DSCMB2_PacketView(MS_U32 u32Eng, MS_U32 u32FltId, MS_U32 Mode, MS_U32 u32Range, MS_BOOL bRst)
5434 {
5435 _MDrv_DSCMB2_PacketView(u32Eng, u32FltId, Mode, u32Range, bRst);
5436 }
5437
5438 //------------------------------------- ------------------//
5439 //------------------------Depreted API ---------------------//
5440 //-------------------------------------------------------//
MDrv_DSCMB_Init(void)5441 MS_BOOL MDrv_DSCMB_Init(void)
5442 {
5443 return MDrv_DSCMB2_Init();
5444 }
5445
MDrv_DSCMB_Exit(void)5446 MS_BOOL MDrv_DSCMB_Exit(void)
5447 {
5448 return MDrv_DSCMB2_Exit();
5449 }
5450
5451 //--------------------------------------------------------------------------------------------------
5452 /// Dscmb lock API for supporting multithreading
5453 /// @param u
5454 /// @return TRUE - Success
5455 /// @return FALSE - Failure
5456 //--------------------------------------------------------------------------------------------------
MDrv_DSCMB_KLadder_Lock(void)5457 MS_BOOL MDrv_DSCMB_KLadder_Lock(void )
5458 {
5459 return MsOS_ObtainMutex(_s32KLMutexId, MSOS_WAIT_FOREVER);
5460 }
5461
5462 //--------------------------------------------------------------------------------------------------
5463 /// Dscmb unlock API for supporting multithreading
5464 /// @param u
5465 /// @return TRUE - Success
5466 /// @return FALSE - Failure
5467 //--------------------------------------------------------------------------------------------------
MDrv_DSCMB_KLadder_Unlock(void)5468 MS_BOOL MDrv_DSCMB_KLadder_Unlock(void)
5469 {
5470 return MsOS_ReleaseMutex(_s32KLMutexId);
5471 }
5472
5473 //--------------------------------------------------------------------------------------------------
5474 /// Check if key ladder operation is complete
5475 /// @return TRUE - Success
5476 /// @return FALSE - Failure
5477 //--------------------------------------------------------------------------------------------------
MDrv_DSCMB_KLadder_IsComplete(void)5478 MS_BOOL MDrv_DSCMB_KLadder_IsComplete(void)
5479 {
5480 OBSOLETE_FUNCTION("Obsolete function\n");
5481 return FALSE;
5482 }
5483
5484 //--------------------------------------------------------------------------------------------------
5485 /// Check if key ladder output is complete
5486 /// @return TRUE - Success
5487 /// @return FALSE - Failure
5488 //--------------------------------------------------------------------------------------------------
MDrv_DSCMB_KLadder_Output_IsComplete(void)5489 MS_BOOL MDrv_DSCMB_KLadder_Output_IsComplete(void)
5490 {
5491 OBSOLETE_FUNCTION("Obsolete function\n");
5492 return FALSE;
5493 }
5494
5495 //--------------------------------------------------------------------------------------------------
5496 /// Make key ladder start output
5497 /// @param u32DscmbId \b IN: Descrambler filter ID obtained from MDrv_DSCMB_FltAlloc
5498 /// @param eKeyType \b IN: Descrambler key type
5499 /// @return TRUE - Success
5500 /// @return FALSE - Failure
5501 //--------------------------------------------------------------------------------------------------
MDrv_DSCMB_KLadder_Output_Start(MS_U32 u32DscmbId,DSCMB_Key_Type eKeyType)5502 MS_BOOL MDrv_DSCMB_KLadder_Output_Start(MS_U32 u32DscmbId, DSCMB_Key_Type eKeyType)
5503 {
5504 OBSOLETE_FUNCTION("Obsolete function\n");
5505 return FALSE;
5506 }
5507
5508 //--------------------------------------------------------------------------------------------------
5509 /// Make key ladder stop output
5510 /// @return TRUE - Success
5511 /// @return FALSE - Failure
5512 //--------------------------------------------------------------------------------------------------
MDrv_DSCMB_KLadder_Output_Stop(void)5513 MS_BOOL MDrv_DSCMB_KLadder_Output_Stop(void)
5514 {
5515 OBSOLETE_FUNCTION("Obsolete function\n");
5516 return FALSE;
5517 }
5518
5519 //--------------------------------------------------------------------------------------------------
5520 /// Reset key ladder
5521 /// @return TRUE - Success
5522 /// @return FALSE - Failure
5523 //--------------------------------------------------------------------------------------------------
MDrv_DSCMB_KLadder_Reset(void)5524 MS_BOOL MDrv_DSCMB_KLadder_Reset(void)
5525 {
5526 OBSOLETE_FUNCTION("Obsolete function\n");
5527 return FALSE;
5528 }
5529
MDrv_DSCMB_KLadder_ResetAcpuAck(void)5530 MS_BOOL MDrv_DSCMB_KLadder_ResetAcpuAck(void)
5531 {
5532 OBSOLETE_FUNCTION("Obsolete function\n");
5533 return FALSE;
5534 }
5535
5536 //--------------------------------------------------------------------------------------------------
5537 /// Make key ladder start operating
5538 /// @return TRUE - Success
5539 /// @return FALSE - Failure
5540 //--------------------------------------------------------------------------------------------------
MDrv_DSCMB_KLadder_Start(void)5541 MS_BOOL MDrv_DSCMB_KLadder_Start(void)
5542 {
5543 OBSOLETE_FUNCTION("Obsolete function\n");
5544 return FALSE;
5545 }
5546
5547 //--------------------------------------------------------------------------------------------------
5548 /// Make key ladder stop operating
5549 /// @return TRUE - Success
5550 /// @return FALSE - Failure
5551 //--------------------------------------------------------------------------------------------------
MDrv_DSCMB_KLadder_Stop(void)5552 MS_BOOL MDrv_DSCMB_KLadder_Stop(void)
5553 {
5554 OBSOLETE_FUNCTION("Obsolete function\n");
5555 return FALSE;
5556 }
5557
5558 //--------------------------------------------------------------------------------------------------
5559 /// Set key ladder input
5560 /// @param KLSrc \b IN: key ladder key source
5561 /// @param pu8Key \b IN: The target key of key ladder
5562 /// @param u32KeyLen \b IN: the length of the target key of key ladder
5563 /// @return TRUE - Success
5564 /// @return FALSE - Failure
5565 //--------------------------------------------------------------------------------------------------
MDrv_DSCMB_KLadder_SetKey(DSCMB_KLSrc KLSrc,MS_U8 * pu8Key,MS_U32 u32KeyLen)5566 MS_BOOL MDrv_DSCMB_KLadder_SetKey(DSCMB_KLSrc KLSrc, MS_U8* pu8Key, MS_U32 u32KeyLen)
5567 {
5568 OBSOLETE_FUNCTION("Obsolete function\n");
5569 return FALSE;
5570 }
5571
5572 //--------------------------------------------------------------------------------------------------
5573 /// Set key ladder input
5574 /// @param u32Level \b IN: key ladder level
5575 /// @param pu8In \b IN: input of key ladder at u32Level level
5576 /// @param u32InLen \b IN: input length
5577 /// @return TRUE - Success
5578 /// @return FALSE - Failure
5579 //--------------------------------------------------------------------------------------------------
MDrv_DSCMB_KLadder_SetInput(MS_U32 u32Level,MS_U8 * pu8In,MS_U32 u32InLen)5580 MS_BOOL MDrv_DSCMB_KLadder_SetInput(MS_U32 u32Level, MS_U8* pu8In, MS_U32 u32InLen)
5581 {
5582 OBSOLETE_FUNCTION("Obsolete function\n");
5583 return FALSE;
5584 }
5585
5586 //--------------------------------------------------------------------------------------------------
5587 /// Set key ladder configurations
5588 /// @param pConfig \b IN: key ladder configurations
5589 //--------------------------------------------------------------------------------------------------
MDrv_DSCMB_KLadder_SetConfig(DSCMB_KLCfg * KLCfg)5590 void MDrv_DSCMB_KLadder_SetConfig(DSCMB_KLCfg *KLCfg)
5591 {
5592 OBSOLETE_FUNCTION("Obsolete function\n");
5593 return;
5594 }
5595
5596 //--------------------------------------------------------------------------------------------------
5597 /// Set key ladder destination
5598 /// @param KLDst \b IN: key ladder key destination
5599 /// @return TRUE - Success
5600 /// @return FALSE - Failure
5601 //--------------------------------------------------------------------------------------------------
MDrv_DSCMB_KLadder_SetDst(DSCMB_KLDst KLDst)5602 MS_BOOL MDrv_DSCMB_KLadder_SetDst(DSCMB_KLDst KLDst)
5603 {
5604 OBSOLETE_FUNCTION("Obsolete function\n");
5605 return FALSE;
5606 }
5607
MDrv_DSCMB_KLadder_ReadDataFromAcpu(MS_U8 * pu8Out)5608 MS_BOOL MDrv_DSCMB_KLadder_ReadDataFromAcpu(MS_U8* pu8Out)
5609 {
5610 OBSOLETE_FUNCTION("Obsolete function\n");
5611 return FALSE;
5612 }
5613
MApi_DSCMB_SetPowerState(EN_POWER_MODE u16PowerState)5614 MS_U32 MApi_DSCMB_SetPowerState(EN_POWER_MODE u16PowerState)
5615 {
5616 return MDrv_DSCMB2_SetPowerState(u16PowerState);
5617 }
5618
MDrv_DSCMB_SlotSwitchWrite(MS_U32 u32DscmbId,DSCMB_Key_Type eKeyType,MS_U32 u32SW0,MS_U32 u32SW1,MS_U32 u32SW2)5619 MS_BOOL MDrv_DSCMB_SlotSwitchWrite(MS_U32 u32DscmbId, DSCMB_Key_Type eKeyType, MS_U32 u32SW0, MS_U32 u32SW1, MS_U32 u32SW2)
5620 {
5621 OBSOLETE_FUNCTION("Not support\n");
5622 return FALSE;
5623 }
5624
MDrv_DSCMB_GetLibVer(const MSIF_Version ** ppVersion)5625 MS_BOOL MDrv_DSCMB_GetLibVer(const MSIF_Version **ppVersion)
5626 {
5627 return MDrv_DSCMB2_GetLibVer (ppVersion);
5628 }
5629
MDrv_DSCMB_SetDBGLevel(MS_U32 u32Level)5630 MS_BOOL MDrv_DSCMB_SetDBGLevel(MS_U32 u32Level)
5631 {
5632 return MDrv_DSCMB2_SetDBGLevel(u32Level);
5633 }
5634
MDrv_DSCMB_KLadder_AtomicExec(DSCMB_KLCfg_All * KLCfg,MS_U8 * ACPU_Out,DSCMB_KL_Status * u32Status)5635 MS_BOOL MDrv_DSCMB_KLadder_AtomicExec(DSCMB_KLCfg_All* KLCfg , MS_U8 *ACPU_Out, DSCMB_KL_Status* u32Status)
5636 {
5637 return MDrv_DSCMB2_KLadder_AtomicExec(KLCfg, ACPU_Out, u32Status);
5638 }
5639
5640 //--------------------------------------------------------------------------------------------------
5641 /// Get the status between descramble id and tsp filter id
5642 /// @param u32DscmbId \b IN: descramble id
5643 /// @param u32TspFltId \b IN: tsp filter id
5644 /// @return TRUE - Success
5645 /// @return FALSE - Failure
5646 //--------------------------------------------------------------------------------------------------
MDrv_DSCMB_GetConnectStatus(MS_U32 u32EngId,MS_U32 u32DscmbId,MS_U32 u32TspFltId)5647 MS_BOOL MDrv_DSCMB_GetConnectStatus(MS_U32 u32EngId, MS_U32 u32DscmbId, MS_U32 u32TspFltId)
5648 {
5649 return MDrv_DSCMB2_GetConnectStatus(u32EngId, u32DscmbId, u32TspFltId);
5650 }
5651
5652 //--------------------------------------------------------------------------------------------------
5653 /// Get Dscmb driver status
5654 /// @param pStatus \b OUT: Descrambler status
5655 /// @return TRUE - Success
5656 /// @return FALSE - Failure
5657 //--------------------------------------------------------------------------------------------------
MDrv_DSCMB_GetStatus(DSCMB_Status * pStatus)5658 MS_BOOL MDrv_DSCMB_GetStatus(DSCMB_Status *pStatus)
5659 {
5660 OBSOLETE_FUNCTION("Not Implement\n");
5661 return FALSE;
5662 }
5663
5664 //--------------------------------------------------------------------------------------------------
5665 /// Get Dscmb driver information
5666 /// @return DSCMB_Info
5667 //--------------------------------------------------------------------------------------------------
MDrv_DSCMB_GetInfo(void)5668 const DSCMB_Info* MDrv_DSCMB_GetInfo(void)
5669 {
5670 OBSOLETE_FUNCTION("Not Implement\n");
5671 return NULL;
5672 }
5673
5674 //--------------------------------------------------------------------------------------------------
5675 /// Set the PID to be replaced
5676 /// @param u32PidPrim\b IN: The packet with this target PID(u32PidPrim) will be replaced in the field of PID byu32Pid2ndary
5677 /// @param u32Pid2ndary\b IN: The packet with this target PID(u32PidPrim) will be replaced in the field of PID byu32Pid2ndary
5678 /// @return TRUE - Success
5679 /// @return FALSE - Failure
5680 //--------------------------------------------------------------------------------------------------
MDrv_DSCMB_2ndarySet(MS_U32 u32PidPrim,MS_U32 u32Pid2ndary)5681 MS_BOOL MDrv_DSCMB_2ndarySet(MS_U32 u32PidPrim, MS_U32 u32Pid2ndary)
5682 {
5683 OBSOLETE_FUNCTION("Not support\n");
5684 return FALSE;
5685 }
5686
5687 //--------------------------------------------------------------------------------------------------
5688 /// Reset the PID to be replaced
5689 /// @param u32PidPrim\b IN: Reset the replacement of PID (u32PidPrim) set by MDrv_DSCMB_2ndarySet
5690 /// @return TRUE - Success
5691 /// @return FALSE - Failure
5692 //--------------------------------------------------------------------------------------------------
MDrv_DSCMB_2ndaryReset(MS_U32 u32PidPrim)5693 MS_BOOL MDrv_DSCMB_2ndaryReset(MS_U32 u32PidPrim)
5694 {
5695 OBSOLETE_FUNCTION("Not support\n");
5696 return FALSE;
5697 }
5698
MDrv_DSCMB2_SetRecBuf(MS_U32 u32EngId,MS_U32 u32Start,MS_U32 u32Size)5699 MS_BOOL MDrv_DSCMB2_SetRecBuf(MS_U32 u32EngId , MS_U32 u32Start, MS_U32 u32Size)
5700 {
5701 OBSOLETE_FUNCTION("Not support\n");
5702 return FALSE;
5703 }
5704
MDrv_DSCMB2_RecCtrl(MS_U32 u32EngId,MS_BOOL bEnable)5705 MS_BOOL MDrv_DSCMB2_RecCtrl(MS_U32 u32EngId, MS_BOOL bEnable)
5706 {
5707 OBSOLETE_FUNCTION("Not support\n");
5708 return FALSE;
5709 }
5710
MDrv_DSCMB2_GetRecWptr(MS_U32 u32EngId,MS_U32 * pu32Write)5711 MS_BOOL MDrv_DSCMB2_GetRecWptr(MS_U32 u32EngId, MS_U32* pu32Write)
5712 {
5713 OBSOLETE_FUNCTION("Not support\n");
5714 return FALSE;
5715 }
5716
MDrv_DSCMB2_EngEnableKey(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Eng_Type eEngType,DSCMB_Key_Type eKeyType,MS_BOOL bEnable)5717 MS_BOOL MDrv_DSCMB2_EngEnableKey(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Eng_Type eEngType, DSCMB_Key_Type eKeyType, MS_BOOL bEnable)
5718 {
5719 return _MDrv_DSCMB2_EngEnableKey(u32EngId, u32DscmbId, eEngType, eKeyType, bEnable);
5720 }
5721
5722
MDrv_DSCMB2_FltSwitchType(MS_U32 u32EngId,MS_U32 u32DscmbId,DSCMB_Flt_Type eFltType)5723 MS_BOOL MDrv_DSCMB2_FltSwitchType(MS_U32 u32EngId, MS_U32 u32DscmbId, DSCMB_Flt_Type eFltType)
5724 {
5725 return _MDrv_DSCMB2_FltSwitchType(u32EngId, u32DscmbId, eFltType);
5726 }
5727
MDrv_DSCMB2_GetPidSlotMapIndex(MS_U32 u32EngId,MS_U32 u32DscmbId)5728 MS_U32 MDrv_DSCMB2_GetPidSlotMapIndex(MS_U32 u32EngId, MS_U32 u32DscmbId)
5729 {
5730 return _MDrv_DSCMB2_GetPidSlotMapIndex(u32EngId, u32DscmbId);
5731 }
5732
5733