SASC
DVBSoftCAM

tps.h

Go to the documentation of this file.
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 __VIACCESS_TPS_H
00021 #define __VIACCESS_TPS_H
00022 
00023 #include <time.h>
00024 #include <vdr/tools.h>
00025 #include <vdr/thread.h>
00026 #include "data.h"
00027 #include "crypto.h"
00028 
00029 class cSystem;
00030 class cSatTime;
00031 class cTpsAuHook;
00032 class cOpenTVModule;
00033 class cST20;
00034 
00035 // ----------------------------------------------------------------
00036 
00037 class cTPSDecrypt : private cAES, private cRC6 {
00038 private:
00039   static unsigned char *mem;
00040   static int memLen, cb1off, cb2off, cb3off;
00041   static cMutex st20Mutex;
00042   static cST20 st20;
00043   static bool st20Inited;
00044   //
00045   static bool InitST20(void);
00046   static bool DecryptAlgo3(const unsigned char *key, unsigned char *data);
00047 protected:
00048   void TpsDecrypt(unsigned char *data, short mode, const unsigned char *key);
00049   static bool RegisterAlgo3(const unsigned char *data, int cb1, int cb2, int cb3, int len);
00050   static unsigned char *DumpAlgo3(int &len, int &cb1, int &cb2, int &cb3);
00051   static bool Handle80008003(const unsigned char *src, int len, unsigned char *dest);
00052   };
00053 
00054 // ----------------------------------------------------------------
00055 
00056 class cTPS : private cTPSDecrypt {
00057 private:
00058   cSatTime *sattime;
00059   int doPost;
00060   short postMode;
00061   unsigned char postKey[16];
00062 public:
00063   cTPS(void);
00064   ~cTPS();
00065   int Decrypt(cSystem *sys, int Source, int Transponder, unsigned char *data, int len);
00066   void PostProc(unsigned char *cw);
00067   };
00068 
00069 // ----------------------------------------------------------------
00070 
00071 class cTpsKey : public cStructItem {
00072 private:
00073   time_t timestamp;
00074   int opmode;
00075   struct {
00076     unsigned char mode;
00077     unsigned char key[16];
00078     } step[3];
00079   //
00080   void Put(unsigned char *mem) const;
00081 public:
00082   cTpsKey(void);
00083   const unsigned char *Key(int st) const { return step[st].key; }
00084   int Mode(int st) const { return step[st].mode; }
00085   int Opmode(void) const { return opmode; }
00086   time_t Timestamp(void) const { return timestamp; }
00087   void Set(const cTpsKey *k);
00088   void Set(const unsigned char *mem);
00089   virtual cString ToString(bool hide=false);
00090   };
00091 
00092 // ----------------------------------------------------------------
00093 
00094 class cTpsKeys : public cStructListPlain<cTpsKey>, private cTPSDecrypt {
00095 friend class cTpsAuHook;
00096 private:
00097   time_t first, last;
00098   cSimpleList<cTpsKey> *loadlist;
00099   //
00100   cTimeMs lastCheck, lastLoad, lastAu;
00101   cMutex checkMutex;
00102   //
00103   unsigned char *algomem;
00104   int algolen, algoread, cb1off, cb2off, cb3off;
00105   //
00106   void Join(cSimpleList<cTpsKey> *nlist);
00107   void Purge(time_t now);
00108   void GetFirstLast(void);
00109   bool LoadBin(void);
00110   void DecryptBin(const unsigned char *in, unsigned char *out);
00111   cString Time(time_t t);
00112   bool ProcessAu(const cOpenTVModule *mod);
00113 protected:
00114   virtual bool ParseLinePlain(const char *line);
00115   virtual void PreLoad(void);
00116   virtual void PostLoad(void);
00117   virtual void PostSave(FILE *f);
00118 public:
00119   cTpsKeys(void);
00120   ~cTpsKeys();
00121   const cTpsKey *GetKey(time_t t);
00122   const cTpsKey *GetV2Key(int id);
00123   void Check(time_t now, cSystem *sys);
00124   };
00125 
00126 extern cTpsKeys tpskeys;
00127 extern int tpsAuMode;
00128 
00129 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines