SASC
DVBSoftCAM

aroureos.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 
00023 #include "cc.h"
00024 #include "parse.h"
00025 
00026 // -- cCardClientAroureos ------------------------------------------------------
00027 
00028 class cCardClientAroureos : public cCardClient, protected cIdSet {
00029 private:
00030   bool ParseCardConfig(const char *config, int *num);
00031 public:
00032   cCardClientAroureos(const char *Name);
00033   virtual bool Init(const char *config);
00034   virtual bool Login(void);
00035   virtual bool ProcessECM(const cEcmInfo *ecm, const unsigned char *source, unsigned char *cw);
00036   virtual bool ProcessEMM(int caSys, const unsigned char *source);
00037   };
00038 
00039 static cCardClientLinkReg<cCardClientAroureos> __aroureos("Aroureos");
00040 
00041 cCardClientAroureos::cCardClientAroureos(const char *Name)
00042 :cCardClient(Name)
00043 {
00044   so.SetRWTimeout(5*1000);
00045 }
00046 
00047 bool cCardClientAroureos::ParseCardConfig(const char *config, int *num)
00048 {
00049   int hb, hs;
00050   int startNum=*num;
00051   if(sscanf(&config[*num],":%x:%x%n",&hb,&hs,num)==2) {
00052     *num+=startNum;
00053     unsigned char h[3];
00054     h[0]=(hs>>16)&0xFF;
00055     h[1]=(hs>> 8)&0xFF;
00056     h[2]=(hs>> 0)&0xFF;
00057     PRINTF(L_CC_LOGIN,"%s: hexser %02X%02X%02X hexbase %02X",name,h[0],h[1],h[2],hb);
00058     ResetIdSet();
00059     SetCard(new cCardIrdeto(hb,&h[0]));
00060     }
00061   return true;
00062 }
00063 
00064 bool cCardClientAroureos::Init(const char *config)
00065 {
00066   cMutexLock lock(this);
00067   Logout();
00068   int num=0;
00069   return ParseStdConfig(config,&num) &&
00070          ParseCardConfig(config,&num);
00071 }
00072 
00073 bool cCardClientAroureos::Login(void)
00074 {
00075   Logout();
00076   if(!so.Connect(hostname,port)) return false;
00077   PRINTF(L_CC_LOGIN,"%s: connected to %s:%d",name,hostname,port);
00078   if(!emmAllowed) PRINTF(L_CC_EMM,"%s: EMM disabled from config",name);
00079   return true;  
00080 }
00081 
00082 bool cCardClientAroureos::ProcessEMM(int caSys, const unsigned char *source)
00083 {
00084   if(emmAllowed) {
00085     cMutexLock lock(this);
00086     if(MatchEMM(source)) {
00087       const int length=SCT_LEN(source);
00088       int id=msEMM.Get(source,length,0);
00089       if(id>0 || emmAllowed>1) {
00090         unsigned char *buff=AUTOMEM(length+8);
00091         memcpy(buff,"EMM",3);
00092         memcpy(&buff[3],source,length);
00093         SendMsg(buff,length+3);
00094         msEMM.Cache(id,true,0);
00095         }
00096       return true;
00097       }
00098     }
00099   return false;
00100 }
00101 
00102 bool cCardClientAroureos::ProcessECM(const cEcmInfo *ecm, const unsigned char *source, unsigned char *cw)
00103 {
00104   cMutexLock lock(this);
00105   so.Flush();
00106   const int len=SCT_LEN(source);
00107   if(len<=93) {
00108     unsigned char buff[128];
00109     memcpy(buff,"ECM",3);
00110     memcpy(&buff[3],source,len);
00111 
00112     if(!SendMsg(buff,96)) return false;
00113     if(RecvMsg(buff,16)>0 && !CheckNull(buff,16)) {
00114       memcpy(cw,buff,16);
00115       return true;
00116       }
00117     }
00118   return false;
00119 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines