move CAID ignore setup to override.conf. Check your setup!
authorleslie <unknown>
Fri, 18 Sep 2009 12:11:35 +0000 (20:11 +0800)
committerleslie <unknown>
Fri, 18 Sep 2009 12:11:35 +0000 (20:11 +0800)
README
cam.c
examples/override.conf.example
override.c
override.h
sc.c
scsetup.h
system.c
system.h

diff --git a/README b/README
index d7e4a4f12ea6c83adc8999762082021e5ac3ce09..68cee5d3744904c3320416a415e9d638f26f9fde 100644 (file)
--- 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 3f82a5e5db05b8cf25b92ef51c3205bc180ceb47..3a91321229b07e59fa2efc26f5d1442656b19efb 100644 (file)
--- 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);
 }
index a9a221a0a4173d7375d08b2f8b89692240e8b0f3..73ea030037288b4e10baaa50a8eea86f07394006 100644 (file)
 ; {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
index 37b6738ca19472525911cd4f60618a5e6084aa6e..ced1cd4a0c7711943b7eb8e43ed1e255082aa73c 100644 (file)
 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(num<OV_MAXTABLES && str[n]==':');
+    LBSTART(L_CORE_OVER);
+    LBPUT("ignore: %s - caids",*Print());
+    for(int i=0; i<num; i++) LBPUT(" %02x",caid[i]);
+    LBEND();
+    return true;
+    }
+  return false;
+}
+
+bool cOverrideIgnore::Ignore(int Caid)
+{
+  for(int i=0; i<num; i++)
+    if(Caid==caid[i]) return true;
+  return false;
+}
+
 // -- cOverrides ---------------------------------------------------------------
 
 cOverrides overrides;
@@ -453,6 +504,7 @@ cOverride *cOverrides::ParseLine(char *line)
     else if(!strncasecmp(line,"ecmtable",8)) ov=new cOverrideEcmTable;
     else if(!strncasecmp(line,"emmtable",8)) ov=new cOverrideEmmTable;
     else if(!strncasecmp(line,"tunnel",6)) ov=new cOverrideTunnel;
+    else if(!strncasecmp(line,"ignore",6)) ov=new cOverrideIgnore;
     if(ov && !ov->Parse(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<cOverrideIgnore *>(ov);
+    if(ovi && ovi->Ignore(caid)) res=true;
+    }
+  ListUnlock();
+  return res;
+}
index 87fdb78e7a4b37b5a62fce0e3141826d5c62ddd6..42b8216c9437ba5ed9278e712f835f52e4a4f9af 100644 (file)
@@ -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 8f9afbffbf5fcd3e8934b31e6b505df28f8c0352..2280957aa1f453ac903fc41b2cff8e39191b1149 100644 (file)
--- 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; i<MAXSCCAPS ; i++) LBPUT(" %d",ScCaps[i]);
-  LBFLUSH();
-  LBPUT("** Ignored CAIDs"); for(int i=0; i<MAXCAIGN ; i++) LBPUT(" %04X",CaIgnore[i]);
   LBEND();
 }
 
@@ -997,13 +994,6 @@ bool cScSetup::CapCheck(int n)
   return false;
 }
 
-bool cScSetup::Ignore(unsigned short caid)
-{
-  for(int i=0; i<MAXCAIGN; i++)
-    if(CaIgnore[i]==caid) return true;
-  return false;
-}
-
 // --- cSoftCAM ---------------------------------------------------------------
 
 bool cSoftCAM::Load(const char *cfgdir)
@@ -1269,7 +1259,6 @@ cScPlugin::cScPlugin(void)
   ScOpts->Add(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));
index 1f43faebb9be590e64c20cfd6ea0ce6b34e6ccb4..5e12c0b1468b660306050c1997eb64ed3f8f4170 100644 (file)
--- 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;
index e2e87009a70777132ed280fbebf79613e851671f..11d8f7ca74ce45fb85169999e05b4f34972de253 100644 (file)
--- a/system.c
+++ b/system.c
@@ -26,7 +26,6 @@
 #include <openssl/md5.h>
 
 #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;
 }
index 6a405d1600e39b22026d563015812ce4c70902b0..524ad57f160045777152997d090e33d28e9ff188 100644 (file)
--- 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);