|
SASC
DVBSoftCAM
|
00001 /* 00002 * Softcam plugin to VDR (C++) 00003 * 00004 * This code is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This code is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html 00018 */ 00019 00020 #ifndef ___SYSTEM_H 00021 #define ___SYSTEM_H 00022 00023 #include <vdr/tools.h> 00024 00025 #include "data.h" 00026 #include "misc.h" 00027 00028 // ---------------------------------------------------------------- 00029 00030 #define SYSTEM_MASK 0xFF00 00031 00032 // ---------------------------------------------------------------- 00033 00034 class cEcmInfo; 00035 class cPlainKey; 00036 class cSystem; 00037 class cSystems; 00038 class cLogger; 00039 class cOpts; 00040 class cHookManager; 00041 class cCam; 00042 00043 // ---------------------------------------------------------------- 00044 00045 class cFeature { 00046 private: 00047 static bool keyfile, smartcard; 00048 public: 00049 void NeedsKeyFile(void); 00050 void NeedsSmartCard(void); 00051 bool KeyFile(void) const { return keyfile; } 00052 bool SmartCard(void) const { return smartcard; } 00053 }; 00054 00055 extern cFeature Feature; 00056 00057 // ---------------------------------------------------------------- 00058 00059 class cKeySnoop { 00060 private: 00061 cSystem *sys; 00062 int type, id, keynr; 00063 bool ok; 00064 public: 00065 cKeySnoop(cSystem *Sys, int Type, int Id, int Keynr); 00066 ~cKeySnoop(); 00067 void OK(cPlainKey *pk); 00068 }; 00069 00070 // ---------------------------------------------------------------- 00071 00072 class cLogHook : public cSimpleItem { 00073 friend class cHookManager; 00074 private: 00075 // int cardNum, id; 00076 int id; 00077 const char *name; 00078 cTimeMs delay; 00079 bool bailOut; 00080 protected: 00081 cPids pids; 00082 public: 00083 cLogHook(int Id, const char *Name); 00084 virtual ~cLogHook() {} 00085 virtual void Process(int pid, unsigned char *data)=0; 00086 void BailOut(void) { bailOut=true; } 00087 }; 00088 00089 // ---------------------------------------------------------------- 00090 00091 struct EcmCheck; 00092 00093 class cSystem : public cSimpleItem { 00094 friend class cKeySnoop; 00095 private: 00096 static int foundKeys, newKeys; 00097 int pri; 00098 cLastKey lastkey; 00099 char *lastTxt; 00100 char currentKeyStr[48]; 00101 struct EcmCheck *check; 00102 cEcmInfo *logecm; 00103 cCam *cam; 00104 protected: 00105 const char *name; 00106 unsigned char cw[16]; 00107 bool doLog; 00108 // config details 00109 int maxEcmTry; 00110 bool local, hasLogger, needsLogger, needsDescrData, constant; 00111 // 00112 void KeyOK(cPlainKey *pk); 00113 void KeyOK(const char *txt); 00114 void KeyFail(int type, int id, int keynr); 00115 void StartLog(const cEcmInfo *ecm, int caid); 00116 public: 00117 cSystem(const char *Name, int Pri); 00118 virtual ~cSystem(); 00119 void SetOwner(cCam *Cam) { cam=Cam; } 00120 static void CaidsChanged(void); 00121 // 00122 virtual int CheckECM(const cEcmInfo *ecm, const unsigned char *data, bool sync); 00123 virtual void CheckECMResult(const cEcmInfo *ecm, const unsigned char *data, bool result); 00124 virtual bool ProcessECM(const cEcmInfo *ecm, unsigned char *buffer)=0; 00125 virtual void ProcessEMM(int pid, int caid, const unsigned char *buffer) {}; 00126 virtual void ParseCADescriptor(cSimpleList<cEcmInfo> *ecms, unsigned short sysId, int source, const unsigned char *data, int len); 00127 virtual void ParseCAT(cPids *pids, const unsigned char *buffer, int source, int transponder); 00128 // 00129 void AddHook(cLogHook *hook); 00130 bool TriggerHook(int id); 00131 // 00132 unsigned char *CW(void) { return cw; } 00133 void DoLog(bool Log) { doLog=Log; } 00134 int Pri(void) { return pri; } 00135 const char *CurrentKeyStr(void) { return currentKeyStr; } 00136 const char *Name(void) { return name; } 00137 int MaxEcmTry(void) { return maxEcmTry; } 00138 bool HasLogger(void) { return hasLogger; } 00139 bool NeedsLogger(void) { return needsLogger; } 00140 bool Local(void) { return local; } 00141 bool NeedsData(void) { return needsDescrData; } 00142 bool Constant(void) { return constant; } 00143 // 00144 static void FoundKey(void) { foundKeys++; } 00145 static void NewKey(void) { newKeys++; } 00146 static void KeyStats(int &fk, int &nk) { fk=foundKeys; nk=newKeys; } 00147 }; 00148 00149 // ---------------------------------------------------------------- 00150 00151 class cSystemLink { 00152 friend class cSystems; 00153 private: 00154 int sysIdent; 00155 protected: 00156 cSystemLink *next; 00157 const char *name; 00158 int pri; 00159 cOpts *opts; 00160 bool noFF; 00161 public: 00162 cSystemLink(const char *Name, int Pri); 00163 virtual ~cSystemLink(); 00164 virtual bool CanHandle(unsigned short SysId)=0; 00165 virtual cSystem *Create(void)=0; 00166 virtual bool Init(const char *cfgdir) { return true; } 00167 virtual void Clean(void) {} 00168 virtual void NewConfig(void) {} 00169 }; 00170 00171 // ---------------------------------------------------------------- 00172 00173 class cSystems { 00174 friend class cSystemLink; 00175 private: 00176 static cSystemLink *first; 00177 static int nextSysIdent; 00178 // 00179 static void Register(cSystemLink *sysLink); 00180 static cSystemLink *FindByName(const char *Name); 00181 static cSystemLink *FindById(unsigned short SysId, bool ff, int oldPri); 00182 static cSystemLink *FindByIdent(int ident); 00183 public: 00184 static int CanHandle(int SysId, bool ff); 00185 static cSystem *FindBySysId(unsigned short SysId, bool ff, int oldPri); 00186 static int FindIdentBySysId(unsigned short SysId, bool ff, int &Pri); 00187 static int FindIdentBySysName(unsigned short SysId, bool ff, const char *Name, int &Pri); 00188 static cSystem *FindBySysIdent(int ident); 00189 static bool Init(const char *cfgdir); 00190 static void Clean(void); 00191 // 00192 static bool ConfigParse(const char *Name, const char *Value); 00193 static void ConfigStore(bool AsIs); 00194 static cOpts *GetSystemOpts(bool start); 00195 }; 00196 00197 // ---------------------------------------------------------------- 00198 00199 struct Cache; 00200 00201 class cMsgCache { 00202 private: 00203 struct Cache *caches; 00204 unsigned char *stores; 00205 int numCache, ptr, storeSize, maxFail; 00206 cMutex mutex; 00207 cCondVar wait; 00208 // 00209 struct Cache *FindMsg(int crc); 00210 public: 00211 cMsgCache(int NumCache, int StoreSize); 00212 ~cMsgCache(); 00213 int Cache(int id, bool result, const unsigned char *store); 00214 int Get(const unsigned char *msg, int len, unsigned char *store); 00215 void Clear(void); 00216 void SetMaxFail(int max); 00217 }; 00218 00219 #endif //___SYSTEM_H