From 406447efbe7df7a7ab6d1eefaa5f1d596bfed3cb Mon Sep 17 00:00:00 2001 From: leslie Date: Fri, 18 Sep 2009 20:11:35 +0800 Subject: [PATCH] move CAID ignore setup to override.conf. Check your setup! --- README | 3 +- cam.c | 44 ++++++++++++++------- examples/override.conf.example | 21 +++++++++- override.c | 72 ++++++++++++++++++++++++++++++++-- override.h | 4 +- sc.c | 11 ------ scsetup.h | 3 -- system.c | 48 +++++++---------------- system.h | 2 +- 9 files changed, 138 insertions(+), 70 deletions(-) diff --git a/README b/README index d7e4a4f..68cee5d 100644 --- a/README +++ b/README @@ -174,7 +174,8 @@ To reduce the number of CAIDs SC has to deal with, you should obey some rules: (e.g. SHL seems pretty useless nowadays). -When using a cardclient, be as precise as possible with the CAID/MASK values in the cardclient.conf file. Using wide open 0000/0000 is not recommended. --Add CAIDs which you cannot use due to lack of keys to the SC.CaIgnore setting. +-Add CAIDs which you cannot use due to lack of keys to the ignore setup in + override.conf. diff --git a/cam.c b/cam.c index 3f82a5e..3a91321 100644 --- a/cam.c +++ b/cam.c @@ -320,17 +320,19 @@ bool cLogChain::Parse(const unsigned char *cat) } else { LBPUT(" ->"); - int Pri=0; - while((sys=cSystems::FindBySysId(caid,!softCSA,Pri))) { - Pri=sys->Pri(); - if(sys->HasLogger()) { - sys->CardNum(cardNum); - sys->ParseCAT(&pids,cat,source,transponder); - systems.Add(sys); - LBPUT(" %s(%d)",sys->Name(),sys->Pri()); + if(!overrides.Ignore(source,transponder,caid)) { + int Pri=0; + while((sys=cSystems::FindBySysId(caid,!softCSA,Pri))) { + Pri=sys->Pri(); + if(sys->HasLogger()) { + sys->CardNum(cardNum); + sys->ParseCAT(&pids,cat,source,transponder); + systems.Add(sys); + LBPUT(" %s(%d)",sys->Name(),sys->Pri()); + } + else + delete sys; } - else - delete sys; } } if(systems.Count()==0) LBPUT(" none available"); @@ -1300,6 +1302,7 @@ void cEcmHandler::AddEcmPri(cEcmInfo *n) { int ident, pri=0; while(1) { + if(overrides.Ignore(n->source,n->transponder,n->caId)) break; if(!n->Cached()) ident=cSystems::FindIdentBySysId(n->caId,!cam->IsSoftCSA(filterCwIndex==0),pri); else ident=(pri==0) ? cSystems::FindIdentBySysName(n->caId,!cam->IsSoftCSA(filterCwIndex==0),n->name,pri) : 0; if(ident<=0) break; @@ -1414,6 +1417,10 @@ void cEcmHandler::ParseCAInfo(int SysId) int sysId=WORD(buff,index+2,0xFFFF); if(SysId!=0xFFFF && sysId!=SysId) continue; if(dolog) LDUMP(L_CORE_ECM,&buff[index+2],buff[index+1],"%s: descriptor",id); + if(overrides.Ignore(filterSource,filterTransponder,sysId)) { + if(dolog) PRINTF(L_CORE_ECM,"%s: system %04x ignored",id,sysId); + continue; + } int sysPri=0; cSystem *sys; while((sys=cSystems::FindBySysId(sysId,!cam->IsSoftCSA(filterCwIndex==0),sysPri))) { @@ -1918,6 +1925,8 @@ public: void Dump(int n); const caid_t *Caids(void) { caids[numcaids]=0; return caids; } int NumCaids(void) { return numcaids; } + int Source(void) const { return source; } + int Transponder(void) const { return transponder; } }; cChannelCaids::cChannelCaids(cChannel *channel) @@ -2006,7 +2015,9 @@ void cChannelList::CheckIgnore(void) const caid_t *ids=ch->Caids(); while(*ids) { int pri=0; - if(!cSystems::FindIdentBySysId(*ids,false,pri)) { + if(overrides.Ignore(ch->Source(),ch->Transponder(),*ids)) + ch->Del(*ids); + else if(!cSystems::FindIdentBySysId(*ids,false,pri)) { for(cChannelCaids *ch2=Next(ch); ch2; ch2=Next(ch2)) ch2->Del(*ids); ch->Del(*ids); } @@ -3153,10 +3164,13 @@ bool cScDvbDevice::SetChannelDevice(const cChannel *Channel, bool LiveView) int cScDvbDevice::ProvidesCa(const cChannel *Channel) const { if(cam && Channel->Ca()>=CA_ENCRYPTED_MIN) { - int j; - caid_t ids[MAXCAIDS+1]; - for(j=0; j<=MAXCAIDS; j++) if((ids[j]=Channel->Ca(j))==0) break; - if(cSystems::Provides(ids,!softcsa)>0) return 2; + int caid; + for(int j=0; (caid=Channel->Ca(j)); j++) + if(!overrides.Ignore(Channel->Source(),Channel->Transponder(),caid)) { + int n=cSystems::CanHandle(caid,!softcsa); + if(n<0) break; + if(n>0) return 2; + } } return cDvbDevice::ProvidesCa(Channel); } diff --git a/examples/override.conf.example b/examples/override.conf.example index a9a221a..73ea030 100644 --- a/examples/override.conf.example +++ b/examples/override.conf.example @@ -31,6 +31,26 @@ ; {1234::} ; +; +; Define ignored CAIDs for general processing +; +; NOTE: this replace the CaIgnore option in setup.conf. See below on how to +; convert your settings +; +; format: +; ignore:{src[-src]:[freq[-freq]]}caid[:caid][...] +; ignore:{*}caid[:caid][...] +; +; if your ignore line in setup.conf looks like this +; sc.CaIgnore = 622 9c4 b00 d22 1702 1722 1836 1837 +; then you should add an entry like this +; ignore:{*}0622:09c4:0b00:0d22:1702:1722:1836:1837 +; Of course you could set a more fine grade validity range as well. +; +; examples +; ignore:{S61.5W-S148W:}1801:0D04:0600 +; ignore:{*}0622:1833 + ; ; Add entries to the CAT (conditional access table) in case a EMM stream is ; not announced there. @@ -88,6 +108,5 @@ emmtable:{1815:S82W-S91W:}83:84 # BEV N3 ; format: ; tunnel:{caid[-caid]:[src[-src]]:[freq[-freq]]}newcaid[:rewriter] ; -; ; examples: ; tunnel:{1833:S19.2E:}1702:nagra-beta diff --git a/override.c b/override.c index 37b6738..ced1cd4 100644 --- a/override.c +++ b/override.c @@ -32,13 +32,15 @@ cValidityRange::cValidityRange(void) { fromCaid=toCaid=-1; fromSource=toSource=-1; fromFreq=toFreq=-1; + wildcard=false; } bool cValidityRange::Match(int caid, int source, int freq) const { - return (caid<0 || fromCaid<0 || (toCaid<0 && caid==fromCaid) || (caid>=fromCaid && caid<=toCaid)) && - (fromSource<0 || (toSource<0 && source==fromSource) || (source>=fromSource && source<=toSource)) && - (fromFreq<0 || (toFreq<0 && freq==fromFreq) || (freq>=fromFreq && freq<=toFreq)); + return wildcard || + ((caid<0 || fromCaid<0 || (toCaid<0 && caid==fromCaid) || (caid>=fromCaid && caid<=toCaid)) && + (fromSource<0 || (toSource<0 && source==fromSource) || (source>=fromSource && source<=toSource)) && + (fromFreq<0 || (toFreq<0 && freq==fromFreq) || (freq>=fromFreq && freq<=toFreq))); } char *cValidityRange::Parse3(char *s) @@ -69,13 +71,18 @@ char *cValidityRange::Parse3(char *s) return 0; } -char *cValidityRange::Parse2(char *s) +char *cValidityRange::Parse2(char *s, bool wildAllow) { bool log=true; s=skipspace(s); char *e=index(s,'}'); if(e && *s++=='{') { *e=0; e=skipspace(e+1); + s=skipspace(s); + if(wildAllow && *s=='*' && isempty(s+1)) { + wildcard=true; + return e; + } char *p; if((p=index(s,':'))) { *p=0; @@ -140,6 +147,7 @@ bool cValidityRange::ParseSourceRange(const char *str) cString cValidityRange::Print(void) { + if(wildcard) return "*"; char buff[256]; int q=0; if(fromCaid>0) { @@ -169,6 +177,7 @@ cString cValidityRange::Print(void) #define OV_ECMTABLE 3 #define OV_EMMTABLE 4 #define OV_TUNNEL 5 +#define OV_IGNORE 6 // -- cOverrideCat ------------------------------------------------------------- @@ -433,6 +442,48 @@ int cOverrideTunnel::GetTunnel(int *id, bool log) return caid; } +// -- cOverrideIgnore ---------------------------------------------------------- + +#define OV_MAXIGNORES 64 + +class cOverrideIgnore : public cOverride { +private: + int num, caid[OV_MAXIGNORES]; +public: + cOverrideIgnore(void) { type=OV_IGNORE; } + virtual bool Parse(char *str); + bool Ignore(int Caid); + }; + +bool cOverrideIgnore::Parse(char *str) +{ + if((str=Parse2(str,true))) { + num=0; + int n=-1; + do { + int l=n+1; + if(sscanf(&str[l],"%x%n",&caid[num],&n)!=1) { + PRINTF(L_CORE_LOAD,"override: IGNORE format error"); + return false; + } + n+=l; num++; + } while(numParse(p)) { delete ov; ov=0; } } return ov; @@ -506,3 +558,15 @@ bool cOverrides::AddEmmPids(int caid, int source, int transponder, cPids *pids, ListUnlock(); return res; } + +bool cOverrides::Ignore(int source, int transponder, int caid) +{ + bool res=false; + ListLock(false); + for(cOverride *ov=0; (ov=Find(OV_IGNORE,-1,source,transponder,ov)) && !res;) { + cOverrideIgnore *ovi=dynamic_cast(ov); + if(ovi && ovi->Ignore(caid)) res=true; + } + ListUnlock(); + return res; +} diff --git a/override.h b/override.h index 87fdb78..42b8216 100644 --- a/override.h +++ b/override.h @@ -29,13 +29,14 @@ private: int fromCaid, toCaid; int fromSource, toSource; int fromFreq, toFreq; + bool wildcard; // bool ParseCaidRange(const char *str); bool ParseSourceRange(const char *str); bool ParseFreqRange(const char *str); protected: char *Parse3(char *s); - char *Parse2(char *s); + char *Parse2(char *s, bool wildAllow=false); cString Print(void); public: cValidityRange(void); @@ -90,6 +91,7 @@ public: int GetCat(int source, int transponder, unsigned char *buff, int len); void UpdateEcm(cEcmInfo *ecm, bool log); bool AddEmmPids(int caid, int source, int transponder, cPids *pids, int pid); + bool Ignore(int source, int transponder, int caid); }; extern cOverrides overrides; diff --git a/sc.c b/sc.c index 8f9afbf..2280957 100644 --- a/sc.c +++ b/sc.c @@ -949,7 +949,6 @@ cScSetup::cScSetup(void) ScCaps[0]=1; ScCaps[1]=2; ConcurrentFF=0; - memset(CaIgnore,0,sizeof(CaIgnore)); LocalPriority=0; ForceTransfer=1; PrestartAU=0; @@ -975,8 +974,6 @@ void cScSetup::Check(void) PRINTF(L_CORE_LOAD,"** ECM cache is set to %s",EcmCache ? (EcmCache==1?"READ-ONLY":"DISABLED"):"enabled"); LBSTART(L_CORE_LOAD); LBPUT("** ScCaps are"); for(int i=0; iAdd(new cOptBool ("LocalPriority",trNOOP("Prefer local systems") ,&ScSetup.LocalPriority)); ScOpts->Add(new cOptSel ("EcmCache" ,trNOOP("ECM cache") ,&ScSetup.EcmCache,3,ecache)); ScOpts->Add(new cOptMInt ("ScCaps" ,trNOOP("Active on DVB card") , ScSetup.ScCaps,MAXSCCAPS,0)); - ScOpts->Add(new cOptMInt ("CaIgnore" ,trNOOP("Ignore CAID") , ScSetup.CaIgnore,MAXCAIGN,2)); LogOpts=new cOpts(0,6); LogOpts->Add(new cOptBool ("LogConsole" ,trNOOP("Log to console") ,&logcfg.logCon)); LogOpts->Add(new cOptBool ("LogFile" ,trNOOP("Log to file") ,&logcfg.logFile)); diff --git a/scsetup.h b/scsetup.h index 1f43fae..5e12c0b 100644 --- a/scsetup.h +++ b/scsetup.h @@ -21,7 +21,6 @@ #define ___SC_SETUP_H #define MAXSCCAPS 10 -#define MAXCAIGN 64 // ---------------------------------------------------------------- @@ -30,7 +29,6 @@ public: int AutoUpdate; int ScCaps[MAXSCCAPS]; int ConcurrentFF; - int CaIgnore[MAXCAIGN]; int LocalPriority; int ForceTransfer; int PrestartAU; @@ -41,7 +39,6 @@ public: void Check(void); void Store(bool AsIs); bool CapCheck(int n); - bool Ignore(unsigned short caid); }; extern cScSetup ScSetup; diff --git a/system.c b/system.c index e2e8700..11d8f7c 100644 --- a/system.c +++ b/system.c @@ -26,7 +26,6 @@ #include #include "sc.h" -#include "scsetup.h" #include "system.h" #include "data.h" #include "override.h" @@ -285,22 +284,12 @@ void cSystems::Register(cSystemLink *sysLink) first=sysLink; } -int cSystems::Provides(const unsigned short *SysIds, bool ff) +int cSystems::CanHandle(int SysId, bool ff) { - int n=0; - for(; *SysIds; SysIds++) { - if(ScSetup.Ignore(*SysIds)) continue; - cSystemLink *sl=first; - while(sl) { - if(sl->CanHandle(*SysIds)) { - if(sl->noFF && ff) return 0; - n++; - break; - } - sl=sl->next; - } - } - return n; + for(cSystemLink *sl=first; sl; sl=sl->next) + if(sl->CanHandle(SysId)) + return (sl->noFF && ff) ? -1:1; + return 0; } cSystemLink *cSystems::FindByName(const char *Name) @@ -346,33 +335,26 @@ cSystemLink *cSystems::FindByIdent(int ident) cSystem *cSystems::FindBySysId(unsigned short SysId, bool ff, int oldPri) { - if(!ScSetup.Ignore(SysId)) { - cSystemLink *csl=FindById(SysId,ff,oldPri); - if(csl) return csl->Create(); - } - return 0; + cSystemLink *csl=FindById(SysId,ff,oldPri); + return csl ? csl->Create() : 0; } int cSystems::FindIdentBySysId(unsigned short SysId, bool ff, int &Pri) { - if(!ScSetup.Ignore(SysId)) { - cSystemLink *csl=FindById(SysId,ff,Pri); - if(csl) { - Pri=csl->pri; - return csl->sysIdent; - } + cSystemLink *csl=FindById(SysId,ff,Pri); + if(csl) { + Pri=csl->pri; + return csl->sysIdent; } return 0; } int cSystems::FindIdentBySysName(unsigned short SysId, bool ff, const char *Name, int &Pri) { - if(!ScSetup.Ignore(SysId)) { - cSystemLink *csl=FindByName(Name); - if(csl && (!ff || !csl->noFF) && csl->CanHandle(SysId)) { - Pri=csl->pri; - return csl->sysIdent; - } + cSystemLink *csl=FindByName(Name); + if(csl && (!ff || !csl->noFF) && csl->CanHandle(SysId)) { + Pri=csl->pri; + return csl->sysIdent; } return 0; } diff --git a/system.h b/system.h index 6a405d1..524ad57 100644 --- a/system.h +++ b/system.h @@ -172,7 +172,7 @@ private: static cSystemLink *FindById(unsigned short SysId, bool ff, int oldPri); static cSystemLink *FindByIdent(int ident); public: - static int Provides(const unsigned short *SysIds, bool ff); + static int CanHandle(int SysId, bool ff); static cSystem *FindBySysId(unsigned short SysId, bool ff, int oldPri); static int FindIdentBySysId(unsigned short SysId, bool ff, int &Pri); static int FindIdentBySysName(unsigned short SysId, bool ff, const char *Name, int &Pri); -- 2.39.5