-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathcam.h
288 lines (259 loc) · 7.17 KB
/
cam.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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
* Softcam plugin to VDR (C++)
*
* This code is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* Or, point your browser to http://www.gnu.org/copyleft/gpl.html
*/
#ifndef ___CAM_H
#define ___CAM_H
#include <linux/dvb/ca.h>
#include <vdr/ci.h>
#include <vdr/thread.h>
#include "data.h"
#include "misc.h"
class cChannel;
class cRingBufferLinear;
class cDevice;
class cEcmHandler;
class cEcmData;
class cLogger;
class cHookManager;
class cLogHook;
class cScCamSlot;
class cDeCSA;
class cPrg;
class cScDevicePlugin;
// ----------------------------------------------------------------
class cEcmCache : public cStructListPlain<cEcmData> {
private:
cEcmData *Exists(cEcmInfo *e);
protected:
virtual bool ParseLinePlain(const char *line);
public:
cEcmCache(void);
void New(cEcmInfo *e);
int GetCached(cSimpleList<cEcmInfo> *list, int sid, int Source, int Transponder);
void Delete(cEcmInfo *e);
void Flush(void);
};
extern cEcmCache ecmcache;
// ----------------------------------------------------------------
#ifndef CA_SET_PID /* removed in kernel 4.14 */
typedef struct ca_pid {
unsigned int pid;
int index; /* -1 == disable */
} ca_pid_t;
#define CA_SET_PID _IOW('o', 135, struct ca_pid)
#endif
#ifndef SASC
class cCiFrame {
private:
cRingBufferLinear *rb;
unsigned char *mem;
int len, alen, glen;
public:
cCiFrame(void);
~cCiFrame();
void SetRb(cRingBufferLinear *Rb) { rb=Rb; }
unsigned char *GetBuff(int l);
void Put(void);
unsigned char *Get(int &l);
void Del(void);
int Avail(void);
};
#endif //!SASC
// ----------------------------------------------------------------
class cCaDescr {
private:
unsigned char *descr;
int len;
public:
cCaDescr(void);
cCaDescr(const cCaDescr &arg);
~cCaDescr();
const unsigned char *Get(int &l) const;
void Set(const cCaDescr *d);
void Set(const unsigned char *de, int l);
void Clear(void);
bool operator== (const cCaDescr &arg) const;
void Join(const cCaDescr *cd, bool rev=false);
cString ToString(void);
};
// ----------------------------------------------------------------
class cPrgPid : public cSimpleItem {
private:
bool proc;
public:
int type, pid;
cCaDescr caDescr;
//
cPrgPid(int Type, int Pid) { type=Type; pid=Pid; proc=false; }
bool Proc(void) const { return proc; }
void Proc(bool is) { proc=is; };
};
// ----------------------------------------------------------------
class cPrg : public cSimpleItem {
private:
bool isUpdate, pidCaDescr;
//
void Setup(void);
public:
int sid, source, transponder;
cSimpleList<cPrgPid> pids;
cCaDescr caDescr;
//
cPrg(void);
cPrg(int Sid, bool IsUpdate);
bool IsUpdate(void) const { return isUpdate; }
bool HasPidCaDescr(void) const { return pidCaDescr; }
void SetPidCaDescr(bool val) { pidCaDescr=val; }
bool SimplifyCaDescr(void);
void DumpCaDescr(int c);
};
// ----------------------------------------------------------------
typedef int caid_t;
#define MAX_CI_SLOTS 8
#ifdef VDR_MAXCAID
#define MAX_CI_SLOT_CAIDS VDR_MAXCAID
#else
#define MAX_CI_SLOT_CAIDS 16
#endif
#define MAX_CW_IDX 16
#define MAX_SPLIT_SID 16
#ifndef SASC
class cCam : public cCiAdapter, public cSimpleItem {
#else
class cCam : public cSimpleItem {
#endif
private:
cDevice *device;
const char *devId;
int adapter, frontend;
#ifndef SASC
cMutex ciMutex;
cRingBufferLinear *rb;
cScCamSlot *slots[MAX_CI_SLOTS];
cCiFrame frame;
//
cDeCSA *decsa;
#endif
cScDevicePlugin *devplugin;
bool softcsa, fullts;
//
cTimeMs caidTimer, triggerTimer;
int version[MAX_CI_SLOTS];
caid_t caids[MAX_CI_SLOTS][MAX_CI_SLOT_CAIDS+1];
int tcid;
bool rebuildcaids;
//
cTimeMs readTimer, writeTimer;
//
cMutex camMutex;
cSimpleList<cEcmHandler> handlerList;
cLogger *logger;
cHookManager *hookman;
int source, transponder, liveVpid, liveApid;
int splitSid[MAX_SPLIT_SID+1];
unsigned char indexMap[MAX_CW_IDX], lastCW[MAX_CW_IDX][2*8];
//
void BuildCaids(bool force);
cEcmHandler *GetHandler(int sid, bool needZero, bool noshift);
void RemHandler(cEcmHandler *handler);
int GetFreeIndex(void);
void LogStartup(void);
protected:
#ifndef SASC
virtual int Read(unsigned char *Buffer, int MaxLength);
virtual void Write(const unsigned char *Buffer, int Length);
virtual bool Reset(int Slot);
virtual eModuleStatus ModuleStatus(int Slot);
virtual bool Assign(cDevice *Device, bool Query=false);
#endif
public:
cCam(cDevice *Device, int Adapter, int Frontend, const char *DevId, cScDevicePlugin *DevPlugin, bool SoftCSA, bool FullTS);
virtual ~cCam();
// CI adapter API
int GetCaids(int slot, unsigned short *Caids, int max);
void CaidsChanged(void);
virtual bool SetCaDescr(ca_descr_t *ca_descr, bool initial);
virtual bool SetCaPid(ca_pid_t *ca_pid);
void Stop(void);
void AddPrg(cPrg *prg);
bool HasPrg(int prg);
// EcmHandler API
void WriteCW(int index, unsigned char *cw, bool force);
void SetCWIndex(int pid, int index);
void DumpAV7110(void);
bool IsSoftCSA(bool live);
int Adapter(void) { return adapter; }
int Frontend(void) { return frontend; }
// System API
void LogEcmStatus(const cEcmInfo *ecm, bool on);
void AddHook(cLogHook *hook);
bool TriggerHook(int id);
// Plugin API
bool Active(bool log);
void HouseKeeping(void);
void Tune(const cChannel *channel);
void PostTune(void);
void SetPid(int type, int pid, bool on);
char *CurrentKeyStr(int num, const char **id);
#ifndef SASC
bool OwnSlot(const cCamSlot *slot) const;
cDeCSA *DeCSA(void) const { return decsa; }
#endif
};
void LogStatsDown(void);
// ----------------------------------------------------------------
#ifndef SASC
#ifdef LIBDVBCSA
extern "C" {
#include <dvbcsa/dvbcsa.h>
}
#endif
#define MAX_CSA_PIDS 8192
#define MAX_CSA_IDX 16
class cDeCSA {
private:
int cs;
#ifndef LIBDVBCSA
unsigned char **range, *lastData;
void *keys[MAX_CSA_IDX];
#else
struct dvbcsa_bs_batch_s *cs_tsbbatch_even;
struct dvbcsa_bs_batch_s *cs_tsbbatch_odd;
struct dvbcsa_bs_key_s *cs_key_even[MAX_CSA_IDX];
struct dvbcsa_bs_key_s *cs_key_odd[MAX_CSA_IDX];
#endif
unsigned char pidmap[MAX_CSA_PIDS];
unsigned int even_odd[MAX_CSA_IDX], flags[MAX_CSA_IDX];
cMutex mutex;
cCondVar wait;
cTimeMs stall;
bool active;
const char *devId;
//
bool GetKeyStruct(int idx);
void ResetState(void);
public:
cDeCSA(const char *DevId);
~cDeCSA();
bool Decrypt(unsigned char *data, int len, bool force);
bool SetDescr(ca_descr_t *ca_descr, bool initial);
bool SetCaPid(ca_pid_t *ca_pid);
void SetActive(bool on);
};
#endif //!SASC
#endif // ___CAM_H