DVBCore  20.3.0
DVBCore Documentation
ap_ca.c
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright © 2014 The DTVKit Open Software Foundation Ltd (www.dtvkit.org)
3  * Copyright © 2011 Ocean Blue Software Ltd
4  *
5  * This file is part of a DTVKit Software Component
6  * You are permitted to copy, modify or distribute this file subject to the terms
7  * of the DTVKit 1.0 Licence which can be found in licence.txt or at www.dtvkit.org
8  *
9  * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
10  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
11  * OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
12  *
13  * If you or your organisation is not a member of DTVKit then you have access
14  * to this source code outside of the terms of the licence agreement
15  * and you are expected to delete this and any associated files immediately.
16  * Further information on DTVKit, membership and terms can be found at www.dtvkit.org
17  *******************************************************************************/
25 //#define CA_DEBUG
26 
27 //---includes for this file----------------------------------------------------
28 // compiler library header files
29 
30 #include <stdio.h>
31 #include <string.h>
32 
33 // third party header files
34 
35 // Ocean Blue Software header files
36 
37 #include "techtype.h"
38 #include "dbgfuncs.h"
39 
40 #include "stbdpc.h"
41 #include "stbpvr.h"
42 #include "stbsiflt.h"
43 #include "stbsitab.h"
44 
45 #include "ca_glue.h"
46 
47 #include "ap_dbacc.h"
48 
49 //---constant definitions for this file----------------------------------------
50 #ifdef CA_DEBUG
51  #define AP_CA_PRINT(x) STB_SPDebugWrite x
52 #else
53  #define AP_CA_PRINT(x)
54 #endif
55 
56 
57 //---local typedefs, structs, enumerations for this file--------------------------------------------
58 
59 
60 //---local (static) variable declarations for this file------------------------
61 // (internal variables declared static to make them local)
62 
63 //---local function prototypes for this file-----------------------------------
64 // (internal functions declared static to make them local)
65 
66 //--------------------------------------------------------------------------------------------------
67 // global function definitions
68 //--------------------------------------------------------------------------------------------------
69 
70 /*!**************************************************************************
71  * @brief Acquires a CA descrambler for the given path on the given service if
72  * needed. No CA descrambler is acquired if a CI slot has been already
73  * acquired (CI takes precedence) or if a CA descrambler is already
74  * associated to this path.
75  * @param path - decode path
76  * @param s_ptr - service to be used on the path
77  * @return TRUE if the CA path has been successfully acquired, FALSE otherwise.
78  ****************************************************************************/
79 BOOLEAN ACA_AcquireCADescrambler(U8BIT path, void *s_ptr)
80 {
81  U8BIT *pmt_data;
82  U16BIT data_len;
83  BOOLEAN has_ca;
84  U32BIT ca_handle;
85  U8BIT running_status;
86  BOOLEAN retval = FALSE;
87 
88  FUNCTION_START(ACA_AcquireCADescrambler);
89 
90  has_ca = STB_DPGetPathCADescrambler(path, &ca_handle);
91 
92 #ifdef CA_DEBUG
93 #ifdef COMMON_INTERFACE
94  AP_CA_PRINT(("%s(path=%u): CI slot=%u, CA=%u(0x%lx)", __FUNCTION__, path,
95  STB_DPGetPathCISlot(path), has_ca, ca_handle));
96 #else
97  AP_CA_PRINT(("%s(path=%u): CA=%u(0x%lx)", __FUNCTION__, path, has_ca, ca_handle));
98 #endif
99 #endif
100 
101  /* Only acquire a CA slot if there isn't one already and there's no CI slot */
102  if (!has_ca
103 #ifdef COMMON_INTERFACE
104  && (STB_DPGetPathCISlot(path) == INVALID_RES_ID)
105 #endif
106  )
107  {
108  pmt_data = ADB_GetServicePMTData(s_ptr, &data_len);
109  if (pmt_data != NULL)
110  {
111  if (STB_DPAcquireCADescramblerForPath(path, pmt_data, &ca_handle))
112  {
113  retval = TRUE;
114 
115  /* Pass the PMT to the CA system */
116  STB_CAReportPMT(ca_handle, pmt_data, data_len);
117 
118  if ((running_status = ADB_GetServiceRunningStatus(s_ptr)) != 0)
119  {
120  /* Pass the running status to the CA system */
121  STB_CANotifyRunningStatus(ca_handle, running_status);
122  }
123  }
124 #ifdef CA_DEBUG
125  else
126  {
127  AP_CA_PRINT(("%s(path=%u): couldn't acquire a CA slot", __FUNCTION__, path));
128  }
129 #endif
130  }
131 #ifdef CA_DEBUG
132  else
133  {
134  AP_CA_PRINT(("%s(path=%u): no pmt data available on service %p", __FUNCTION__, path, s_ptr));
135  }
136 #endif
137  }
138 
139  FUNCTION_FINISH(ACA_AcquireCADescrambler);
140 
141  return retval;
142 }
143 
144 //--------------------------------------------------------------------------------------------------
145 // local function definitions
146 //--------------------------------------------------------------------------------------------------
U8BIT STB_DPGetPathCISlot(U8BIT path)
Returns the CI slot id associated with the given path.
Definition: stbdpc.c:1082
BOOLEAN STB_DPAcquireCADescramblerForPath(U8BIT path, U8BIT *pmt_data, U32BIT *ca_handle)
Acquire a CA descrambler and assign it to the given path.
Definition: stbdpc.c:1147
BOOLEAN ACA_AcquireCADescrambler(U8BIT path, void *s_ptr)
Acquires a CA descrambler for the given path on the given service if needed. No CA descrambler is acq...
Definition: ap_ca.c:79
Header file - macros and function prototypes for public use.
U8BIT ADB_GetServiceRunningStatus(void *s_ptr)
Returns the running status of the given service as reported by the SDT.
Definition: ap_dbacc.c:5627
U8BIT * ADB_GetServicePMTData(void *s_ptr, U16BIT *data_len)
Returns the current PMT data for the given service.
Definition: ap_dbacc.c:11293
Header file - macros and function prototypes for public use.
Debug functions header file.
Header file - macros and function prototypes for public use.
void STB_CANotifyRunningStatus(U32BIT handle, U8BIT status)
This function will be called when there&#39;s a change to the running status of a service being descrambl...
Definition: ca_glue.c:296
Glue layer between DVB and conditional access systems.
System Wide Global Technical Data Type Definitions.
BOOLEAN STB_DPGetPathCADescrambler(U8BIT path, U32BIT *handle)
Get the handle of the CA descrambler associated with the given path.
Definition: stbdpc.c:1244
void STB_CAReportPMT(U32BIT handle, U8BIT *pmt_data, U16BIT data_len)
When there&#39;s an update to the PMT for a service, the updated PMT will be reported to the CA system us...
Definition: ca_glue.c:162
Application database access functions.
Header file - macros and function prototypes for public use.