|
SASC
DVBSoftCAM
|
Inheritance diagram for cCardClientCommon:Public Member Functions | |
| cCardClientCommon (const char *Name, bool ConReply, bool LogReply, bool DoAES, int MinMsgLen) | |
| virtual bool | Init (const char *config) |
| virtual bool | Login (void) |
| virtual bool | Immediate (void) |
| virtual bool | ProcessECM (const cEcmInfo *ecm, const unsigned char *source, unsigned char *cw) |
| virtual bool | ProcessEMM (int caSys, const unsigned char *source) |
| cCardClientCommon (const char *Name, bool ConReply, bool LogReply, bool DoAES, int MinMsgLen) | |
| virtual bool | Init (const char *config) |
| virtual bool | Login (void) |
| virtual bool | Immediate (void) |
| virtual bool | ProcessECM (const cEcmInfo *ecm, const unsigned char *source, unsigned char *cw) |
| virtual bool | ProcessEMM (int caSys, const unsigned char *source) |
Protected Member Functions | |
| bool | ParseKeyConfig (const char *config, int *num) |
| bool | ParseUserConfig (const char *config, int *num) |
| virtual bool | SendMsg (const unsigned char *data, int len) |
| virtual int | RecvMsg (unsigned char *data, int len, int to=-1) |
| virtual void | HandleEMMRequest (const unsigned char *buff, int len) |
| virtual bool | CanHandleEMM (int SysId) |
| bool | ParseKeyConfig (const char *config, int *num) |
| bool | ParseUserConfig (const char *config, int *num) |
| virtual bool | SendMsg (const unsigned char *data, int len) |
| virtual int | RecvMsg (unsigned char *data, int len, int to=-1) |
| virtual void | HandleEMMRequest (const unsigned char *buff, int len) |
| virtual bool | CanHandleEMM (int SysId) |
Protected Attributes | |
| bool | emmProcessing |
| char | username [11] |
| char | password [11] |
| int | emmReqLen |
| cCardClientCommon::cCardClientCommon | ( | const char * | Name, |
| bool | ConReply, | ||
| bool | LogReply, | ||
| bool | DoAES, | ||
| int | MinMsgLen | ||
| ) |
Definition at line 63 of file camd.c.
References CCTIMEOUT, emmProcessing, emmReqLen, cNetSocket::SetRWTimeout(), and cCardClient::so.
:cCardClient(Name) { conReply=ConReply; logReply=LogReply; doAES=DoAES; minMsgLen=MinMsgLen; emmProcessing=exclusive=false; so.SetRWTimeout(CCTIMEOUT); emmReqLen=-64; }
| cCardClientCommon::cCardClientCommon | ( | const char * | Name, |
| bool | ConReply, | ||
| bool | LogReply, | ||
| bool | DoAES, | ||
| int | MinMsgLen | ||
| ) |
| virtual bool cCardClientCommon::CanHandleEMM | ( | int | SysId | ) | [inline, protected, virtual] |
Reimplemented in cCardClientCamd33, and cCardClientCamd33.
Definition at line 53 of file camd.c.
Referenced by ProcessEMM().
{ return false; }
| virtual bool cCardClientCommon::CanHandleEMM | ( | int | SysId | ) | [inline, protected, virtual] |
Reimplemented in cCardClientCamd33, and cCardClientCamd33.
Definition at line 53 of file camd.c.
{ return false; }
| virtual void cCardClientCommon::HandleEMMRequest | ( | const unsigned char * | buff, |
| int | len | ||
| ) | [inline, protected, virtual] |
| virtual void cCardClientCommon::HandleEMMRequest | ( | const unsigned char * | buff, |
| int | len | ||
| ) | [inline, protected, virtual] |
Reimplemented in cCardClientCamd33, and cCardClientCamd33.
Definition at line 52 of file camd.c.
Referenced by Login(), and ProcessECM().
{}
| bool cCardClientCommon::Immediate | ( | void | ) | [virtual] |
Reimplemented from cCardClient.
Definition at line 126 of file camd.c.
References cCardClient::emmAllowed.
{
return emmAllowed && logReply && cCardClient::Immediate();
}
| virtual bool cCardClientCommon::Immediate | ( | void | ) | [virtual] |
Reimplemented from cCardClient.
| virtual bool cCardClientCommon::Init | ( | const char * | config | ) | [virtual] |
Implements cCardClient.
Reimplemented in cCardClientBuffy, and cCardClientBuffy.
| bool cCardClientCommon::Init | ( | const char * | config | ) | [virtual] |
Implements cCardClient.
Reimplemented in cCardClientBuffy, and cCardClientBuffy.
Definition at line 131 of file camd.c.
References cCardClient::Logout(), ParseKeyConfig(), cCardClient::ParseStdConfig(), and ParseUserConfig().
{
cMutexLock lock(this);
Logout();
int num=0;
if(ParseStdConfig(config,&num) &&
ParseUserConfig(config,&num) &&
(!doAES || ParseKeyConfig(config,&num))) {
return true;
}
return false;
}
| bool cCardClientCommon::Login | ( | void | ) | [virtual] |
Implements cCardClient.
Reimplemented in cCardClientBuffy, and cCardClientBuffy.
Definition at line 144 of file camd.c.
References CCVERSION, cNetSocket::Connect(), cCardClient::emmAllowed, emmProcessing, emmReqLen, HandleEMMRequest(), cCardClient::hostname, L_CC_CAMD, L_CC_LOGIN, cCardClient::Logout(), cCardClient::name, password, cCardClient::port, PRINTF, RecvMsg(), SendMsg(), cCardClient::so, and username.
Referenced by cCardClientBuffy::Login(), and ProcessECM().
{
Logout();
if(!so.Connect(hostname,port)) return false;
PRINTF(L_CC_LOGIN,"%s: connected to %s:%d (%s)",name,hostname,port,name);
emmProcessing=false;
unsigned char buff[128];
if(conReply) {
if(RecvMsg(buff,16)<0) {
PRINTF(L_CC_CAMD,"bad connect reply");
return false;
}
}
memset(buff,0,32);
int user_len=strlen(username)+1;
memcpy(buff+1,username,user_len);
int pass_len=strlen(password)+1;
memcpy(buff+1+user_len+1,password,pass_len);
int vers_len=strlen(CCVERSION)+1;
memcpy(buff+1+user_len+pass_len+1,CCVERSION,vers_len);
PRINTF(L_CC_CAMD,"login user='%s' password=hidden version=%s",username,CCVERSION);
if(!SendMsg(buff,32)) return false;
if(emmAllowed && logReply) {
PRINTF(L_CC_CAMD,"waiting for login reply ...");
int r=RecvMsg(buff,emmReqLen);
if(r>0) HandleEMMRequest(buff,r);
}
PRINTF(L_CC_LOGIN,"%s: login done",name);
return true;
}
| virtual bool cCardClientCommon::Login | ( | void | ) | [virtual] |
Implements cCardClient.
Reimplemented in cCardClientBuffy, and cCardClientBuffy.
| bool cCardClientCommon::ParseKeyConfig | ( | const char * | config, |
| int * | num | ||
| ) | [protected] |
Definition at line 83 of file camd.c.
References GetHex(), L_CC_CAMD, L_CC_CORE, LDUMP, cCardClient::name, PRINTF, and cAES::SetKey().
Referenced by Init().
{
char hexkey[33];
int startNum=*num;
if(sscanf(&config[*num],":%32[^:]%n",hexkey,num)==1) {
*num+=startNum;
PRINTF(L_CC_CORE,"%s: key=%s",name,hexkey);
unsigned char binkey[16];
memset(binkey,0,sizeof(binkey));
const char *line=hexkey;
int n=GetHex(line,binkey,sizeof(binkey),false);
if(n!=(int)sizeof(binkey))
PRINTF(L_CC_CAMD,"warning AES key not %d bytes long",(int)sizeof(binkey));
LDUMP(L_CC_CAMD,binkey,16,"AES activated key =");
SetKey(binkey);
}
return true;
}
| bool cCardClientCommon::ParseKeyConfig | ( | const char * | config, |
| int * | num | ||
| ) | [protected] |
| bool cCardClientCommon::ParseUserConfig | ( | const char * | config, |
| int * | num | ||
| ) | [protected] |
| bool cCardClientCommon::ParseUserConfig | ( | const char * | config, |
| int * | num | ||
| ) | [protected] |
| virtual bool cCardClientCommon::ProcessECM | ( | const cEcmInfo * | ecm, |
| const unsigned char * | source, | ||
| unsigned char * | cw | ||
| ) | [virtual] |
Implements cCardClient.
| bool cCardClientCommon::ProcessECM | ( | const cEcmInfo * | ecm, |
| const unsigned char * | source, | ||
| unsigned char * | cw | ||
| ) | [virtual] |
Implements cCardClient.
Definition at line 203 of file camd.c.
References AUTOMEM, cCondVar::Broadcast(), cEcmInfo::caId, cCardClient::CanHandle(), CCTIMEOUT, CheckNull(), cNetSocket::Connected(), emmProcessing, HandleEMMRequest(), L_CC_CAMD, L_CC_ECM, cMutex::Lock(), Login(), cCardClient::name, PRINTF, RecvMsg(), SCT_LEN, SendMsg(), cTimeMs::Set(), cCardClient::so, cTimeMs::TimedOut(), cCondVar::TimedWait(), cMutex::Unlock(), and cCondVar::Wait().
{
Lock();
bool res=false;
while(exclusive) sleepCond.Wait(*this);
if((so.Connected() || Login()) && (!emmProcessing || CanHandle(ecm->caId))) {
const int length=SCT_LEN(source);
unsigned char *buff=AUTOMEM(length+32);
int n;
while((n=RecvMsg(buff,-16,0))>0) HandleEMMRequest(buff,n);
buff[0]=0x02;
buff[1]=(ecm->caId>>8);
buff[2]=(ecm->caId&0xFF);
memset(&buff[3],0,4);
memcpy(&buff[7],source,length);
if(SendMsg(buff,length+7)) {
exclusive=true;
time.Set(CCTIMEOUT);
do {
sleepCond.TimedWait(*this,50);
while((n=RecvMsg(buff,-32,0))>0) {
if(n>=21 && buff[0]==2) {
if(!CheckNull(buff+5,16)) {
if(!res) {
memcpy(cw,buff+5,16);
res=true;
}
else PRINTF(L_CC_CAMD,"unexpected CW packet");
}
else {
PRINTF(L_CC_ECM,"%s: server is unable to handle ECM",name);
n=-1;
break;
}
}
else HandleEMMRequest(buff,n);
}
} while(!res && n>=0 && !time.TimedOut());
if(!res && time.TimedOut()) PRINTF(L_CC_ECM,"%s: CW request timed out",name);
exclusive=false;
sleepCond.Broadcast();
}
}
Unlock();
return res;
}
| virtual bool cCardClientCommon::ProcessEMM | ( | int | caSys, |
| const unsigned char * | source | ||
| ) | [virtual] |
Reimplemented from cCardClient.
| bool cCardClientCommon::ProcessEMM | ( | int | caSys, |
| const unsigned char * | source | ||
| ) | [virtual] |
Reimplemented from cCardClient.
Definition at line 178 of file camd.c.
References AUTOMEM, cMsgCache::Cache(), CanHandleEMM(), cIdSet::card, cCardClient::emmAllowed, cMsgCache::Get(), cIdSet::MatchEMM(), cCardClient::msEMM, SCT_LEN, and SendMsg().
{
if(emmAllowed && CanHandleEMM(caSys)) {
cMutexLock lock(this);
if(MatchEMM(source)) {
const int length=SCT_LEN(source);
int id=msEMM.Get(source,length,0);
if(id>0 || emmAllowed>1) {
unsigned char *buff=AUTOMEM(length+32);
buff[0]=0x03;
buff[1]=(caSys>>8);
buff[2]=(caSys&0xFF);
memcpy(buff+3,((cCardIrdeto *)card)->hexSer,3);
buff[6]=((cCardIrdeto *)card)->hexBase;
memcpy(&buff[7],source,length);
//PRINTF(L_CC_CAMD,"%s: sending EMM for caid 0x%04X",name,caSys);
SendMsg(buff,length+7);
msEMM.Cache(id,true,0);
}
return true;
}
}
return false;
}
| virtual int cCardClientCommon::RecvMsg | ( | unsigned char * | data, |
| int | len, | ||
| int | to = -1 |
||
| ) | [protected, virtual] |
Reimplemented from cCardClient.
| int cCardClientCommon::RecvMsg | ( | unsigned char * | data, |
| int | len, | ||
| int | to = -1 |
||
| ) | [protected, virtual] |
Reimplemented from cCardClient.
Definition at line 116 of file camd.c.
References cAES::Decrypt(), L_CC_CAMD, and PRINTF.
Referenced by cCardClientBuffy::Login(), Login(), and ProcessECM().
| bool cCardClientCommon::SendMsg | ( | const unsigned char * | data, |
| int | len | ||
| ) | [protected, virtual] |
Reimplemented from cCardClient.
Definition at line 102 of file camd.c.
References AUTOMEM, and cAES::Encrypt().
Referenced by cCardClientBuffy::Login(), Login(), ProcessECM(), and ProcessEMM().
| virtual bool cCardClientCommon::SendMsg | ( | const unsigned char * | data, |
| int | len | ||
| ) | [protected, virtual] |
Reimplemented from cCardClient.
bool cCardClientCommon::emmProcessing [protected] |
Definition at line 44 of file camd.c.
Referenced by cCardClientCamd33::CanHandleEMM(), cCardClientCommon(), cCardClientCamd33::HandleEMMRequest(), Login(), and ProcessECM().
int cCardClientCommon::emmReqLen [protected] |
Definition at line 46 of file camd.c.
Referenced by cCardClientCamd33::cCardClientCamd33(), cCardClientCommon(), cCardClientCamd33::HandleEMMRequest(), and Login().
char cCardClientCommon::password [protected] |
Definition at line 45 of file camd.c.
Referenced by Login(), and ParseUserConfig().
char cCardClientCommon::username [protected] |
Definition at line 45 of file camd.c.
Referenced by Login(), and ParseUserConfig().