forked from ipruthi/sasc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
system.h
210 lines (185 loc) · 6.07 KB
/
system.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
/*
* 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 ___SYSTEM_H
#define ___SYSTEM_H
#include <vdr/tools.h>
#include "data.h"
#include "misc.h"
// ----------------------------------------------------------------
#define SYSTEM_MASK 0xFF00
// ----------------------------------------------------------------
class cEcmInfo;
class cPlainKey;
class cSystem;
class cSystems;
class cLogger;
class cOpts;
class cHookManager;
// ----------------------------------------------------------------
class cFeature {
private:
static bool keyfile, smartcard;
public:
void NeedsKeyFile(void);
void NeedsSmartCard(void);
bool KeyFile(void) const { return keyfile; }
bool SmartCard(void) const { return smartcard; }
};
extern cFeature Feature;
// ----------------------------------------------------------------
class cKeySnoop {
private:
cSystem *sys;
int type, id, keynr;
bool ok;
public:
cKeySnoop(cSystem *Sys, int Type, int Id, int Keynr);
~cKeySnoop();
void OK(cPlainKey *pk);
};
// ----------------------------------------------------------------
class cLogHook : public cSimpleItem {
friend class cHookManager;
private:
int cardNum, id;
const char *name;
cTimeMs delay;
bool bailOut;
protected:
cPids pids;
public:
cLogHook(int Id, const char *Name);
virtual ~cLogHook() {}
virtual void Process(int pid, unsigned char *data)=0;
void BailOut(void) { bailOut=true; }
};
// ----------------------------------------------------------------
struct EcmCheck;
class cSystem : public cSimpleItem {
friend class cKeySnoop;
private:
static int foundKeys, newKeys;
int pri, cardNum;
cLastKey lastkey;
char *lastTxt;
char currentKeyStr[48];
struct EcmCheck *check;
cEcmInfo *logecm;
protected:
const char *name;
unsigned char cw[16];
bool doLog;
// config details
int maxEcmTry;
bool local, hasLogger, needsLogger, needsDescrData, constant;
//
void KeyOK(cPlainKey *pk);
void KeyOK(const char *txt);
void KeyFail(int type, int id, int keynr);
void StartLog(const cEcmInfo *ecm, int caid);
public:
cSystem(const char *Name, int Pri);
virtual ~cSystem();
virtual int CheckECM(const cEcmInfo *ecm, const unsigned char *data, bool sync);
virtual void CheckECMResult(const cEcmInfo *ecm, const unsigned char *data, bool result);
virtual bool ProcessECM(const cEcmInfo *ecm, unsigned char *buffer)=0;
virtual void ProcessEMM(int pid, int caid, const unsigned char *buffer) {};
virtual void ParseCADescriptor(cSimpleList<cEcmInfo> *ecms, unsigned short sysId, int source, const unsigned char *data, int len);
virtual void ParseCAT(cPids *pids, const unsigned char *buffer, int source, int transponder);
unsigned char *CW(void) { return cw; }
void DoLog(bool Log) { doLog=Log; }
int Pri(void) { return pri; }
const char *CurrentKeyStr(void) { return currentKeyStr; }
const char *Name(void) { return name; }
int CardNum(void) { return cardNum; }
void CardNum(int CardNum) { cardNum=CardNum; }
int MaxEcmTry(void) { return maxEcmTry; }
bool HasLogger(void) { return hasLogger; }
bool NeedsLogger(void) { return needsLogger; }
bool Local(void) { return local; }
bool NeedsData(void) { return needsDescrData; }
bool Constant(void) { return constant; }
static void FoundKey(void) { foundKeys++; }
static void NewKey(void) { newKeys++; }
static void KeyStats(int &fk, int &nk) { fk=foundKeys; nk=newKeys; }
};
// ----------------------------------------------------------------
class cSystemLink {
friend class cSystems;
private:
int sysIdent;
protected:
cSystemLink *next;
const char *name;
int pri;
cOpts *opts;
bool noFF;
public:
cSystemLink(const char *Name, int Pri);
virtual ~cSystemLink();
virtual bool CanHandle(unsigned short SysId)=0;
virtual cSystem *Create(void)=0;
virtual bool Init(const char *cfgdir) { return true; }
virtual void Clean(void) {}
virtual void NewConfig(void) {}
};
// ----------------------------------------------------------------
class cSystems {
friend class cSystemLink;
private:
static cSystemLink *first;
static int nextSysIdent;
//
static void Register(cSystemLink *sysLink);
static cSystemLink *FindByName(const char *Name);
static cSystemLink *FindById(unsigned short SysId, bool ff, int oldPri);
static cSystemLink *FindByIdent(int ident);
public:
static int CanHandle(int SysId, bool ff);
static cSystem *FindBySysId(unsigned short SysId, bool ff, int oldPri);
static int FindIdentBySysId(unsigned short SysId, bool ff, int &Pri);
static int FindIdentBySysName(unsigned short SysId, bool ff, const char *Name, int &Pri);
static cSystem *FindBySysIdent(int ident);
static bool Init(const char *cfgdir);
static void Clean(void);
//
static bool ConfigParse(const char *Name, const char *Value);
static void ConfigStore(bool AsIs);
static cOpts *GetSystemOpts(bool start);
};
// ----------------------------------------------------------------
struct Cache;
class cMsgCache {
private:
struct Cache *caches;
unsigned char *stores;
int numCache, ptr, storeSize, maxFail;
cMutex mutex;
cCondVar wait;
//
struct Cache *FindMsg(int crc);
public:
cMsgCache(int NumCache, int StoreSize);
~cMsgCache();
int Cache(int id, bool result, const unsigned char *store);
int Get(const unsigned char *msg, int len, unsigned char *store);
void Clear(void);
void SetMaxFail(int max);
};
#endif //___SYSTEM_H