SASC
DVBSoftCAM

constcw.c

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 #include <stdio.h>
00021 #include <string.h>
00022 #include <ctype.h>
00023 
00024 #include <vdr/channels.h>
00025 #include <vdr/sources.h>
00026 
00027 #include "system.h"
00028 #include "system-common.h"
00029 #include "data.h"
00030 #include "misc.h"
00031 #include "version.h"
00032 
00033 SCAPIVERSTAG();
00034 
00035 #define SYSTEM_NAME          "ConstCW"
00036 #define SYSTEM_PRI           -20
00037 
00038 // -- cPlainKeyConstCw ----------------------------------------------------------------
00039 
00040 #define PLAINLEN_CW 16
00041 
00042 class cPlainKeyConstCw : public cHexKey {
00043 private:
00044   int prgId, source, transponder;
00045   int freq;
00046   char pol;
00047 protected:
00048   virtual int IdSize(void) { return 4; }
00049   virtual cString PrintKeyNr(void);
00050   virtual bool CmpExtId(cPlainKey *k);
00051 public:
00052   cPlainKeyConstCw(bool Super);
00053   virtual bool Parse(const char *line);
00054   bool Matches(const cEcmInfo *ecm);
00055   };
00056 
00057 static cPlainKeyTypeReg<cPlainKeyConstCw,'X'> KeyReg;
00058 
00059 cPlainKeyConstCw::cPlainKeyConstCw(bool Super)
00060 :cHexKey(Super)
00061 {
00062   freq=-1;
00063 }
00064 
00065 bool cPlainKeyConstCw::CmpExtId(cPlainKey *k)
00066 {
00067   cPlainKeyConstCw *ck=dynamic_cast<cPlainKeyConstCw *>(k); // downcast
00068   return ck && prgId==ck->prgId && source==ck->source && freq==ck->freq && pol==ck->pol;
00069 }
00070 
00071 bool cPlainKeyConstCw::Matches(const cEcmInfo *ecm)
00072 {
00073   return ecm->prgId==prgId && ecm->source==source && ecm->transponder==transponder;
00074 }
00075 
00076 bool cPlainKeyConstCw::Parse(const char *line)
00077 {
00078   unsigned char caid[2], skey[PLAINLEN_CW];
00079   if(GetChar(line,&type,1) && GetHex(line,caid,2)) {
00080     int num;
00081     char srcBuf[16];
00082     if(sscanf(line," %d:%c:%15[^:]:%d%n",&freq,&pol,srcBuf,&prgId,&num)==4) {
00083       source=cSource::FromString(srcBuf);
00084       transponder=freq;
00085       while(transponder>20000) transponder/=1000;
00086       if(cSource::IsSat(source)) transponder=cChannel::Transponder(transponder,pol);
00087       line+=num;
00088       if(GetHex(line,skey,PLAINLEN_CW)) {
00089         type=toupper(type);
00090         id=Bin2Int(caid,2);
00091         keynr=0;
00092         SetBinKey(skey,PLAINLEN_CW);
00093         return true;
00094         }
00095       }
00096     }
00097   return false;
00098 }
00099 
00100 cString cPlainKeyConstCw::PrintKeyNr(void)
00101 {
00102   return freq<0 ? "" : cString::sprintf("%d:%c:%s:%d",freq,pol,*cSource::ToString(source),prgId);
00103 }
00104 
00105 // -- cSystemConstCw ------------------------------------------------------------------
00106 
00107 class cSystemConstCw : public cSystem {
00108 public:
00109   cSystemConstCw(void);
00110   virtual bool ProcessECM(const cEcmInfo *ecm, unsigned char *source);
00111   };
00112 
00113 cSystemConstCw::cSystemConstCw(void)
00114 :cSystem(SYSTEM_NAME,SYSTEM_PRI)
00115 {
00116   constant=true;
00117 }
00118 
00119 bool cSystemConstCw::ProcessECM(const cEcmInfo *ecm, unsigned char *source)
00120 {
00121   cKeySnoop ks(this,'X',ecm->caId,0);
00122   cPlainKey *pk=0;
00123   while((pk=keys.FindKey('X',ecm->caId,0,16,pk))) {
00124     cPlainKeyConstCw *ck=dynamic_cast<cPlainKeyConstCw *>(pk); // downcast
00125     if(ck && ck->Matches(ecm)) {
00126       pk->Get(cw);
00127       ks.OK(pk);
00128       return true;
00129       }
00130     }
00131   return false;
00132 }
00133 
00134 // -- cSystemLinkConstCw ------------------------------------------------------------
00135 
00136 class cSystemLinkConstCw : public cSystemLink {
00137 public:
00138   cSystemLinkConstCw(void);
00139   virtual bool CanHandle(unsigned short SysId);
00140   virtual cSystem *Create(void) { return new cSystemConstCw; }
00141   };
00142 
00143 static cSystemLinkConstCw staticInit;
00144 
00145 cSystemLinkConstCw::cSystemLinkConstCw(void)
00146 :cSystemLink(SYSTEM_NAME,SYSTEM_PRI)
00147 {
00148   Feature.NeedsKeyFile();
00149 }
00150 
00151 bool cSystemLinkConstCw::CanHandle(unsigned short SysId)
00152 {
00153   return keys.FindKeyNoTrig('X',SysId,0,16)!=0;
00154 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines