forked from srx6/CasProcessor
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathTVCAS.h
259 lines (209 loc) · 6.15 KB
/
TVCAS.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#ifndef TV_CAS_H
#define TV_CAS_H
#include <pshpack1.h>
namespace TVCAS
{
enum
{
LIB_VERSION = 0x00000001UL,
MAX_DEVICE_NAME = 64,
MAX_DEVICE_TEXT = 64
};
struct ModuleInfo
{
DWORD LibVersion;
DWORD Flags;
LPCWSTR Name;
LPCWSTR Version;
};
struct CasDeviceInfo
{
DWORD DeviceID;
DWORD Flags;
WCHAR Name[MAX_DEVICE_NAME];
WCHAR Text[MAX_DEVICE_TEXT];
};
struct CasCardInfo
{
WORD CASystemID;
BYTE CardID[6];
BYTE CardType;
BYTE MessagePartitionLength;
BYTE SystemKey[32];
BYTE InitialCBC[8];
BYTE CardManufacturerID;
BYTE CardVersion;
WORD CheckCode;
WCHAR CardIDText[32];
};
enum
{
EVENT_EMM_PROCESSED = 0x00000001U,
EVENT_EMM_ERROR = 0x00000002U,
EVENT_ECM_ERROR = 0x00000003U,
EVENT_ECM_REFUSED = 0x00000004U,
EVENT_CARD_READER_HUNG = 0x00000005U
};
enum LogType
{
LOG_VERBOSE,
LOG_INFO,
LOG_WARNING,
LOG_ERROR
};
struct ErrorInfo
{
int Code;
LPCWSTR pszText;
LPCWSTR pszAdvise;
LPCWSTR pszSystemMessage;
};
struct EcmErrorInfo
{
LPCWSTR pszText;
WORD EcmPID;
};
struct EmmErrorInfo
{
LPCWSTR pszText;
};
enum ContractStatus
{
CONTRACT_CONTRACTED,
CONTRACT_UNCONTRACTED,
CONTRACT_UNKNOWN,
CONTRACT_ERROR
};
__interface __declspec(uuid("C19221E8-CBB1-4BEF-96A8-3F294244CBB0")) IBase
{
void Refer();
void Release();
LPCWSTR GetName() const;
IBase * GetInterface(REFIID riid);
bool GetProperty(LPCWSTR pszName, void *pProperty, SIZE_T *pSize) const;
bool SetProperty(LPCWSTR pszName, const void *pProperty, SIZE_T Size);
};
__interface __declspec(uuid("973B85B2-CF36-4DF5-A2E8-663550B3BAEA")) ICasClient : public IBase
{
LRESULT OnEvent(UINT Event, void *pParam);
LRESULT OnError(const ErrorInfo *pInfo);
void OutLog(LogType Type, LPCWSTR pszMessage);
};
__interface __declspec(uuid("BC023720-CB97-462E-A142-ED37CE396FB3")) ICasDevice : public IBase
{
bool GetDeviceInfo(CasDeviceInfo *pInfo) const;
int GetCardCount() const;
bool GetCardName(int Index, LPWSTR pszName, int MaxName) const;
bool IsCardAvailable(LPCWSTR pszName);
};
__interface __declspec(uuid("080EDD04-8215-4037-8B66-E03954FD81BD")) ICasManager : public IBase
{
bool Initialize(ICasClient *pClient);
bool Reset();
bool EnableDescramble(bool Enable);
bool IsDescrambleEnabled() const;
bool EnableContract(bool Enable);
bool IsContractEnabled() const;
int GetCasDeviceCount() const;
bool GetCasDeviceInfo(int Device, CasDeviceInfo *pInfo) const;
ICasDevice * OpenCasDevice(int Device);
bool IsCasDeviceAvailable(int Device);
bool CheckCasDeviceAvailability(int Device, bool *pAvailable, LPWSTR pszMessage, int MaxLength);
int GetDefaultCasDevice();
int GetCasDeviceByID(DWORD DeviceID) const;
int GetCasDeviceByName(LPCWSTR pszName) const;
bool OpenCasCard(int Device, LPCWSTR pszName = NULL);
bool CloseCasCard();
bool IsCasCardOpen() const;
int GetCasDevice() const;
int GetCasCardName(LPWSTR pszName, int MaxName) const;
bool GetCasCardInfo(CasCardInfo *pInfo) const;
bool SendCasCommand(const void *pSendData, DWORD SendSize, void *pRecvData, DWORD *pRecvSize);
bool ProcessStream(const void *pSrcData, const DWORD SrcSize,
void **ppDstData, DWORD *pDstSize);
bool ProcessPacket(void *pData, DWORD PacketSize);
ULONGLONG GetInputPacketCount() const;
ULONGLONG GetScramblePacketCount() const;
void ResetScramblePacketCount();
bool SetDescrambleServiceID(WORD ServiceID);
WORD GetDescrambleServiceID() const;
bool SetDescrambleServices(const WORD *pServiceIDList, int ServiceCount);
bool GetDescrambleServices(WORD *pServiceIDList, int *pServiceCount) const;
WORD GetEcmPIDByServiceID(WORD ServiceID) const;
ContractStatus GetContractStatus(WORD NetworkID, WORD ServiceID, const SYSTEMTIME *pTime = NULL);
ContractStatus GetContractPeriod(WORD NetworkID, WORD ServiceID, SYSTEMTIME *pTime);
bool HasContractInfo(WORD NetworkID, WORD ServiceID) const;
int GetInstructionName(int Instruction, LPWSTR pszName, int MaxName) const;
UINT GetAvailableInstructions() const;
bool SetInstruction(int Instruction);
int GetInstruction() const;
bool DescrambleBenchmarkTest(int Instruction, DWORD Round, DWORD *pTime);
};
typedef BOOL (WINAPI *GetModuleInfoFunc)(ModuleInfo *pInfo);
typedef IBase * (WINAPI *CreateInstanceFunc)(REFIID riid);
namespace Helper
{
namespace Module
{
inline GetModuleInfoFunc GetModuleInfo(HMODULE hLib)
{
return reinterpret_cast<GetModuleInfoFunc>(::GetProcAddress(hLib, "TVCAS_GetModuleInfo"));
}
inline CreateInstanceFunc CreateInstance(HMODULE hLib)
{
return reinterpret_cast<CreateInstanceFunc>(::GetProcAddress(hLib, "TVCAS_CreateInstance"));
}
}
#if (__cplusplus >= 201103L) || (defined(_MSC_VER) && (_MSC_VER >= 1700))
#define TVCAS_FINAL override final
#elif defined(_MSC_VER)
#define TVCAS_FINAL override
#else
#define TVCAS_FINAL
#endif
class CBaseImplNoRef
{
protected:
virtual void ReferImpl() {}
virtual void ReleaseImpl() {}
virtual IBase * GetInterfaceImpl(REFIID riid)
{
return NULL;
}
virtual bool GetPropertyImpl(LPCWSTR pszName, void *pProperty, SIZE_T *pSize) const
{
return false;
}
virtual bool SetPropertyImpl(LPCWSTR pszName, const void *pProperty, SIZE_T Size)
{
return false;
}
};
class CBaseImpl : public CBaseImplNoRef
{
public:
CBaseImpl() : m_RefCount(1) {}
virtual ~CBaseImpl() {}
protected:
void ReferImpl() TVCAS_FINAL
{
::InterlockedIncrement(&m_RefCount);
}
void ReleaseImpl() TVCAS_FINAL
{
if (::InterlockedDecrement(&m_RefCount) == 0)
delete this;
}
private:
LONG m_RefCount;
};
#define TVCAS_DECLARE_BASE \
void Refer() TVCAS_FINAL { ReferImpl(); } \
void Release() TVCAS_FINAL { ReleaseImpl(); } \
TVCAS::IBase * GetInterface(REFIID riid) TVCAS_FINAL { return GetInterfaceImpl(riid); } \
bool GetProperty(LPCWSTR pszName, void *pProperty, SIZE_T *pSize) const TVCAS_FINAL { return GetPropertyImpl(pszName, pProperty, pSize); } \
bool SetProperty(LPCWSTR pszName, const void *pProperty, SIZE_T Size) TVCAS_FINAL { return SetPropertyImpl(pszName, pProperty, Size); }
} // namespace Helper
} // namespace TVCAS
#include <poppack.h>
#endif