From: leslie Date: Sun, 2 Aug 2009 03:23:52 +0000 (+0800) Subject: cardclient-cccam2: cleanup, mainly logging X-Git-Tag: upstream/620~233 X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=cb1eccab10e0a39764c11c8adbf0523aafa82e86;p=sasc-ng.git cardclient-cccam2: cleanup, mainly logging --- diff --git a/systems/cardclient/cccam2.c b/systems/cardclient/cccam2.c index 7fd2299..c1a2bd4 100644 --- a/systems/cardclient/cccam2.c +++ b/systems/cardclient/cccam2.c @@ -77,6 +77,10 @@ void cCCcamCrypt::Decrypt(const unsigned char *in, unsigned char *out, int lengt void cCCcamCrypt::Encrypt(const unsigned char *in, unsigned char *out, int length) { + // There is a side-effect in this function: + // If in & out pointer are the same, then state is xor'ed with modified input + // (because output(=in ptr) is written before state xor) + // This side-effect is used when initialising the encrypt state! for(int pos=0; pos=16) { + if(length>=16) for(int index=0; index<8; index++) { - *(data+8)=index * (*data); - if(index<=5) *data^=cccamstr[index]; + data[8]=index*data[0]; + if(index<=5) data[0]^=cccamstr[index]; data++; } - } } unsigned int cCCcamCrypt::ShiftRightAndFill(unsigned int value, unsigned int fill, unsigned int places) @@ -340,7 +343,6 @@ public: ~cCardClientCCcam2(); virtual bool Init(const char *CfgDir); virtual bool ProcessECM(const cEcmInfo *ecm, const unsigned char *data, unsigned char *Cw, int cardnum); - virtual bool ProcessEMM(int caSys, const unsigned char *data); }; static cCardClientLinkReg __ncd("cccam2"); @@ -369,7 +371,9 @@ void cCardClientCCcam2::PacketAnalyzer(const unsigned char *data, int length) PRINTF(L_CC_CCCAM2,"got CW, current shareid %08x",shareid); unsigned char tempcw[16]; memcpy(tempcw,data+4,16); + LDUMP(L_CC_CCCAM2,tempcw,16,"scrambled CW"); cCCcamCrypt::ScrambleDcw(tempcw,16,nodeid,shareid); + LDUMP(L_CC_CCCAM2,tempcw,16,"un-scrambled CW"); if(cCCcamCrypt::DcwChecksum(tempcw)) { cwmutex.Lock(); newcw=true; @@ -377,6 +381,7 @@ void cCardClientCCcam2::PacketAnalyzer(const unsigned char *data, int length) cwwait.Broadcast(); cwmutex.Unlock(); } + else PRINTF(L_CC_CCCAM2,"CW checksum failed"); decr.Decrypt(tempcw,tempcw,16); break; } @@ -413,9 +418,8 @@ void cCardClientCCcam2::PacketAnalyzer(const unsigned char *data, int length) break; } case 8: - LDUMP(L_CC_CCCAM2,data+4,8,"Server NodeId: "); - PRINTF(L_CC_CCCAM2,"Server Version: %s",data+4+8); - PRINTF(L_CC_CCCAM2,"Builder Version: %s",data+4+8+32); + PRINTF(L_CC_LOGIN,"%s: server vers: %s builder version: %s",name,data+4+8,data+4+8+32); + LDUMP(L_CC_LOGIN,data+4,8,"%s: server nodeid:",name); break; case 0xff: case 0xfe: @@ -441,7 +445,7 @@ bool cCardClientCCcam2::Init(const char *config) || sscanf(&config[num],":%20[^:]:%20[^:]",username,password)!=2 ) return false; PRINTF(L_CC_CORE,"%s: username=%s password=%s",name,username,password); for(unsigned int i=0; iShareID())==0) continue; - buffer[ECM_HANDLER_POS]=shareid>>24; - buffer[ECM_HANDLER_POS+1]=shareid>>16; - buffer[ECM_HANDLER_POS+2]=shareid>>8; - buffer[ECM_HANDLER_POS+3]=shareid; + buffer[ECM_SHAREID_POS]=shareid>>24; + buffer[ECM_SHAREID_POS+1]=shareid>>16; + buffer[ECM_SHAREID_POS+2]=shareid>>8; + buffer[ECM_SHAREID_POS+3]=shareid; PRINTF(L_CC_CCCAM2,"now try shareid %08x",shareid); HEXDUMP(L_CC_CCCAM2,buffer,ecm_len,"send ecm:"); encr.Encrypt(buffer,netbuff,ecm_len); - so.Write(netbuff,ecm_len); + if(so.Write(netbuff,ecm_len)!=ecm_len) { + PRINTF(L_CC_CCCAM2,"failed so send ecm request"); + continue; + } cwmutex.Lock(); newcw=false; if(cwwait.TimedWait(cwmutex,7000)) { @@ -620,15 +627,12 @@ bool cCardClientCCcam2::ProcessECM(const cEcmInfo *ecm, const unsigned char *dat PRINTF(L_CC_CCCAM2,"got CW"); return true; } + else PRINTF(L_CC_CCCAM2,"no CW from this share"); } else PRINTF(L_CC_CCCAM2,"getting CW timedout"); cwmutex.Unlock(); } - return false; -} - -bool cCardClientCCcam2::ProcessEMM(int caSys, const unsigned char *data) -{ + PRINTF(L_CC_ECM,"%s: unable to decode the channel",name); return false; }