]> www.vanbest.org Git - sasc-ng.git/commitdiff
trigger rebuild caid list if smartcard/cardclient change handled caid
authorleslie <unknown>
Wed, 12 Aug 2009 02:38:24 +0000 (10:38 +0800)
committerleslie <unknown>
Wed, 12 Aug 2009 02:38:24 +0000 (10:38 +0800)
16 files changed:
cam.c
cam.h
sc.c
sc.h
smartcard.c
smartcard.h
systems/cardclient/camd.c
systems/cardclient/cc.c
systems/cardclient/cc.h
systems/cardclient/cccam2.c
systems/cardclient/newcamd.c
systems/cardclient/radegast.c
systems/sc-conax/sc-conax.c
systems/sc-cryptoworks/sc-cryptoworks.c
systems/sc-irdeto/sc-irdeto.c
systems/sc-videoguard2/sc-videoguard2.c

diff --git a/cam.c b/cam.c
index 5561e0eeacefbf06d03bf6d1c46c8d78554036a8..dad0adf050b560cf6a86b239ca56f830c66c3463 100644 (file)
--- a/cam.c
+++ b/cam.c
@@ -58,7 +58,6 @@
 #define ECM_DATA_TIME    6000 // time to wait for ECM data updates
 #define MAX_ECM_IDLE   300000 // delay before an idle handler can be removed
 #define MAX_ECM_HOLD    15000 // delay before an idle handler stops processing
-#define CAID_TIME      300000 // time between caid scans
 
 #define ECMCACHE_FILE "ecm.cache"
 
@@ -865,7 +864,7 @@ for(cPrgPid *pid=pids.First(); pid; pid=pids.Next(pid)) {
   return HasPidCaDescr();
 }
 
-// -- cEcmSys ------------------------------------------------------------------
+// -- cEcmPri ------------------------------------------------------------------
 
 class cEcmPri : public cSimpleItem {
 public:
@@ -1973,6 +1972,9 @@ void cChannelList::Purge(int caid, bool fullch)
 
 // -- cScCiAdapter -------------------------------------------------------------
 
+#define CAID_TIME      300000 // time between caid scans
+#define TRIGGER_TIME    10000 // min. time between caid scan trigger
+
 #define TDPU_SIZE_INDICATOR 0x80
 
 struct TPDU {
@@ -1994,10 +1996,11 @@ private:
   cRingBufferLinear *rb;
   cScCamSlot *slots[MAX_CI_SLOTS];
   //
-  cTimeMs caidTimer;
+  cTimeMs caidTimer, triggerTimer;
   int version[MAX_CI_SLOTS];
   caid_t caids[MAX_CI_SLOTS][MAX_CI_SLOT_CAIDS+1];
   int tcid;
+  bool rebuildcaids;
   //
   cTimeMs readTimer, writeTimer;
   //
@@ -2015,6 +2018,7 @@ public:
   void CamAddPrg(cPrg *prg);
   bool CamSoftCSA(void);
   int GetCaids(int slot, unsigned short *Caids, int max);
+  void CaidsChanged(void);
   };
 
 // -- cScCamSlot ---------------------------------------------------------------
@@ -2224,7 +2228,7 @@ void cScCamSlot::Process(const unsigned char *data, int len)
 cScCiAdapter::cScCiAdapter(cDevice *Device, int CardIndex, cCam *Cam)
 {
   device=Device; cardIndex=CardIndex; cam=Cam;
-  tcid=0;
+  tcid=0; rebuildcaids=false;
   memset(version,0,sizeof(version));
   memset(slots,0,sizeof(slots));
   SetDescription("SC-CI adapter on device %d",cardIndex);
@@ -2283,9 +2287,14 @@ int cScCiAdapter::GetCaids(int slot, unsigned short *Caids, int max)
   return version[slot];
 }
 
+void cScCiAdapter::CaidsChanged(void)
+{
+  rebuildcaids=true;
+}
+
 void cScCiAdapter::BuildCaids(bool force)
 {
-  if(caidTimer.TimedOut() || force) {
+  if(caidTimer.TimedOut() || force || (rebuildcaids && triggerTimer.TimedOut())) {
     PRINTF(L_CORE_CAIDS,"%d: building caid lists",cardIndex);
     cChannelList list(cardIndex);
     Channels.Lock(false);
@@ -2329,6 +2338,8 @@ void cScCiAdapter::BuildCaids(bool force)
     ciMutex.Unlock();
 
     caidTimer.Set(CAID_TIME);
+    triggerTimer.Set(TRIGGER_TIME);
+    rebuildcaids=false;
     }
 }
 
@@ -3048,6 +3059,14 @@ bool cScDvbDevice::SoftCSA(bool live)
   return softcsa && (!fullts || !live);
 }
 
+void cScDvbDevice::CaidsChanged(void)
+{
+#if APIVERSNUM >= 10500
+  if(ciadapter) ciadapter->CaidsChanged();
+  PRINTF(L_CORE_CAIDS,"caid list rebuild triggered");
+#endif
+}
+
 bool cScDvbDevice::SetCaDescr(ca_descr_t *ca_descr, bool initial)
 {
   if(!softcsa || (fullts && ca_descr->index==0)) {
@@ -3181,6 +3200,9 @@ bool cScDvbDevice::Initialize(void)
   return true;
 }
 
+void cScDvbDevice::CaidsChanged(void)
+{}
+
 bool cScDvbDevice::SoftCSA(bool live)
 {
   return softcsa && !live;
diff --git a/cam.h b/cam.h
index df2f5c94506774d17bb3cae7bcf01b4b3c9d6fc2..61cfef3efc3181ec7fae86b50c00682029ab8a7f 100644 (file)
--- a/cam.h
+++ b/cam.h
@@ -235,6 +235,7 @@ public:
   void DumpAV7110(void);
   cCam *Cam(void) { return cam; }
   bool SoftCSA(bool live);
+  void CaidsChanged(void);
   };
 
 #endif // ___CAM_H
diff --git a/sc.c b/sc.c
index fc74767875a4c7669215838b71e9f2b4dc5883de..8f9afbffbf5fcd3e8934b31e6b505df28f8c0352 100644 (file)
--- a/sc.c
+++ b/sc.c
@@ -1064,6 +1064,14 @@ bool cSoftCAM::TriggerHook(int CardNum, int id)
   return dev && dev->Cam() && dev->Cam()->TriggerHook(id);
 }
 
+void cSoftCAM::CaidsChanged(void)
+{
+  for(int n=cDevice::NumDevices(); --n>=0;) {
+    cScDvbDevice *dev=dynamic_cast<cScDvbDevice *>(cDevice::GetDevice(n));
+    if(dev) dev->CaidsChanged();
+    }
+}
+
 // --- cScHousekeeper ----------------------------------------------------------
 
 class cScHousekeeper : public cThread {
diff --git a/sc.h b/sc.h
index cb8f4feec0fe9e802bbefc857b84888304292bf1..618ea5543d9d8b1e8203799560e7fbd4c20822d6 100644 (file)
--- a/sc.h
+++ b/sc.h
@@ -35,6 +35,7 @@ public:
   static void SetLogStatus(int CardNum, const cEcmInfo *ecm, bool on);
   static void AddHook(int CardNum, cLogHook *hook);
   static bool TriggerHook(int CardNum, int id);
+  static void CaidsChanged(void);
   };
 
 #endif // ___SC_H
index 448fc367a00abf66854c31f27ab3d5e2d2b3434f..49b1644228befc8910f965294e11eeee61d61887 100644 (file)
@@ -32,6 +32,7 @@
 #include <vdr/thread.h>
 
 #include "smartcard.h"
+#include "sc.h"
 #include "misc.h"
 #include "log-core.h"
 
@@ -1879,6 +1880,11 @@ int cSmartCard::CheckSctLen(const unsigned char *data, int off)
   return l;
 }
 
+void cSmartCard::CaidsChanged(void)
+{
+  cSoftCAM::CaidsChanged();
+}
+
 // -- cSmartCardLink -----------------------------------------------------------
 
 cSmartCardLink::cSmartCardLink(const char *Name, int Id)
index db2439cb9a1cd55d7d337a326b9312768d73810c..d889e435acb5da6e7c8557c611014e5d2355db2e 100644 (file)
@@ -127,6 +127,7 @@ protected:
   bool Status(void);
   void NewCardConfig(const struct CardConfig *Cfg);
   int CheckSctLen(const unsigned char *data, int off);
+  void CaidsChanged(void);
 public:
   cSmartCard(const struct CardConfig *Cfg, const struct StatusMsg *Msg);
   virtual ~cSmartCard() {};
index 891341a6fe44d9208bb78a9691b5e71d4c160192..02164512d56b072b8d7ac56d162ae8b62a68f4de 100644 (file)
@@ -278,7 +278,9 @@ void cCardClientCamd33::HandleEMMRequest(const unsigned char *buff, int len)
 {
   if(len>=13 && buff[0]==0 && !CheckNull(buff,len) && memcmp(buff,lastEmmReq,13)) {
     emmProcessing=false;
-    CAID=buff[1]*256+buff[2];
+    int c=buff[1]*256+buff[2];
+    if(c!=CAID) CaidsChanged();
+    CAID=c;
     ResetIdSet();
     switch(CAID>>8) {
       case 0x17:
@@ -362,6 +364,7 @@ bool cCardClientBuffy::Login(void)
     if(caid==0xFFFF) break;
     if(caid) CAIDs[numCAIDs++]=caid;
     }
+  CaidsChanged();
   LBSTART(L_CC_LOGIN);
   LBPUT("%s: CAIDs ",name);
   for(int i=0; i<numCAIDs && CAIDs[i]; i++) LBPUT("%04X ",CAIDs[i]);
@@ -586,6 +589,7 @@ void cCardClientCamd35::HandleEMMRequest(const struct CmdBlock *cb)
 
     if(!emmAllowed) PRINTF(L_CC_EMM,"%s: EMM disabled from config",name);
     emmProcessing=true;
+    CaidsChanged();
     }
 }
 
index c8bbb533dc8e517ce39ec2427f52154a724c27f4..d2315f5eed14781ab9134fcb7137ed6a805d1f80 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "system.h"
 #include "cc.h"
+#include "sc.h"
 #include "network.h"
 #include "misc.h"
 #include "opts.h"
@@ -65,6 +66,11 @@ bool cCardClient::Immediate(void)
   return immediate;
 }
 
+void cCardClient::CaidsChanged(void)
+{
+  cSoftCAM::CaidsChanged();
+}
+
 bool cCardClient::ParseStdConfig(const char *config, int *num)
 {
   int n, emm=0;
index 2e2045638a6cde9dd287c3d6ec4096977d353fbb..a8f5eef078ebdc83b5bef65ac144b62c4da86c65 100644 (file)
@@ -70,6 +70,7 @@ protected:
   virtual int RecvMsg(cNetSocket *so, unsigned char *data, int len, int to=-1);
   virtual bool Login(void) { return false; }
   bool Immediate(void);
+  void CaidsChanged(void);
 public:
   cCardClient(const char *Name);
   virtual bool Init(const char *config)=0;
index 3b98f923583b30d8c18b4adc62497e03fd6e4835..249527c2ecf71aa6bb44b179d79dff94422a5dc7 100644 (file)
@@ -305,6 +305,7 @@ private:
 public:
   int GetShares(const cEcmInfo *ecm, cShares *ss);
   void SetLag(int shareid, int lag);
+  bool HasCaid(int caid);
   };
 
 cShare *cShares::Find(int shareid)
@@ -326,6 +327,13 @@ void cShares::SetLag(int shareid, int lag)
   Unlock();
 }
 
+bool cShares::HasCaid(int caid)
+{
+  for(cShare *s=First(); s; s=Next(s))
+    if(s->CaID()==caid) return true;
+  return false;
+}
+
 int cShares::GetShares(const cEcmInfo *ecm, cShares *ss)
 {
   Lock(true);
@@ -499,7 +507,9 @@ void cCardClientCCcam2::PacketAnalyzer(const struct CmdHeader *hdr, int length)
           cShare *n=shares.Next(s);
           if(s->ShareID()==shareid) {
             PRINTF(L_CC_CCCAM2SH,"REMOVE share %08x caid: %04x",s->ShareID(),s->CaID());
+            int caid=s->CaID();
             shares.Del(s);
+            if(!shares.HasCaid(caid)) CaidsChanged();
             }
           s=n;
           }
@@ -511,6 +521,9 @@ void cCardClientCCcam2::PacketAnalyzer(const struct CmdHeader *hdr, int length)
         struct AddShare *add=(struct AddShare *)hdr;
         int caid=UINT16_BE(&add->caid);
         int shareid=UINT32_BE(&add->shareid);
+        shares.Lock(false);
+        if(!shares.HasCaid(caid)) CaidsChanged();
+        shares.Unlock();
         cShare *s=new cShare(shareid,caid,add->uphops);
         LBSTARTF(L_CC_CCCAM2SH);
         LBPUT("ADD share %08x hops %d maxdown %d caid %04x serial ",shareid,add->uphops,add->maxdown,caid);
index 4bd65551459da8637a91bcc200a4d501fe6fa869..5487f92b9cb83f869b21b7a93fde0183950f7778 100644 (file)
@@ -421,7 +421,9 @@ bool cCardClientNewCamd::Login(void)
 
   if(!CmdSend(&so,MSG_CARD_DATA_REQ) || ReceiveMessage(&so,buffer,false)<=0) return false;
   if(buffer[0] == MSG_CARD_DATA) {
-    caId=(buffer[4]<<8)+buffer[5];
+    int c=(buffer[4]<<8)+buffer[5];
+    if(c!=caId) CaidsChanged();
+    caId=c;
     LBSTARTF(L_CC_LOGIN);
     char str[32], str2[32];
     LBPUT("%s: CaID=%04x admin=%d srvUA=%s",name,caId,buffer[3]==1,HexStr(str,&buffer[6],8));
index 58936116edf790623aa17bb49bf0084e514d3aac..a4907a718084f78590924f75db8830e4b5ea2fc3 100644 (file)
@@ -215,7 +215,8 @@ bool cCardClientRadegast::Login(void)
   else PRINTF(L_CC_RDGD,"no server hello, assuming old mode");
   if(emmProcessing && !emmAllowed) 
     PRINTF(L_CC_EMM,"%s: EMM disabled from config",name);
-  return true; 
+  CaidsChanged();
+  return true;
 }
 
 bool cCardClientRadegast::ProcessECM(const cEcmInfo *ecm, const unsigned char *source, unsigned char *cw, int cardnum)
index f909519495c4282a0ac56a7e34ead62280649ccd..f0facec7e3a214a05f4be20f45fafff3468bb31d 100644 (file)
@@ -246,7 +246,12 @@ bool cSmartCardConax::Init(void)
   for(int i=0; i<l; i+=buff[i+1]+2) {
     switch(buff[i]) {
       case 0x20: cardVer=buff[i+2]; break;
-      case 0x28: sysId=(buff[i+2]<<8)+buff[i+3]; break;
+      case 0x28: {
+                 int s=(buff[i+2]<<8)+buff[i+3];
+                 if(s!=sysId) CaidsChanged();
+                 sysId=s;
+                 break;
+                 }
       case 0x2f: currency=(buff[i+2]<<8)+buff[i+3]; break;
       }
     }
index 1f3eb7e2ef5d844c11ce5714493f522e510d0f3d..873b756a4974b07d7bc6e68aaa5f88216159fd7a 100644 (file)
@@ -223,7 +223,7 @@ cSmartCardCryptoworks::cSmartCardCryptoworks(void)
 {
   static const unsigned char cwexp[] = { 0x01,0x00,0x01 };
   BN_bin2bn(cwexp,sizeof(cwexp),exp);
-  ucpkValid=false;
+  caid=0; ucpkValid=false;
 }
 
 int cSmartCardCryptoworks::GetLen(void)
@@ -285,7 +285,9 @@ bool cSmartCardCryptoworks::Init(void)
     return false;
     }
   memcpy(Caid,&buff[2],2);
-  caid=buff[2]*256+buff[3];
+  int c=buff[2]*256+buff[3];
+  if(c!=caid) CaidsChanged();
+  caid=c;
   if(ReadRecord(buff,0x80)<7) {
     PRINTF(L_SC_ERROR,"reading record 2f01/80 failed");
     return false;
index 783b9eca94566c938697911a0fa0870e8354af1d..a62fc98420ce4ff1b0779005bd43de0a4c5d653c 100644 (file)
@@ -399,7 +399,9 @@ static const struct CardConfig cardCfg = {
 
 cSmartCardIrdeto::cSmartCardIrdeto(void)
 :cSmartCard(&cardCfg,msgs)
-{}
+{
+  ACS=0; caId=0; numProv=0;
+}
 
 bool cSmartCardIrdeto::Init(void)
 {
@@ -419,7 +421,9 @@ bool cSmartCardIrdeto::Init(void)
     return false;
     }
   ACS=buff[8]*256+buff[9];
-  caId=buff[13]*256+buff[14];
+  int c=buff[13]*256+buff[14];
+  if(c!=caId) CaidsChanged();
+  caId=c;
   memcpy(coco,&buff[21],3); coco[3]=0;
   PRINTF(L_SC_INIT,"ACS Version %04x, CAID %04x, CoCo %s",ACS,caId,coco);
   snprintf(idStr,sizeof(idStr),"%s (ACS %x)",SC_NAME,ACS);
index 7e98e1e1688ba631adc9cac57b12fb5d17f96b34..d114c8ba2fa5ed10e7d25f70022e20a936425c0a 100644 (file)
@@ -508,7 +508,7 @@ static const struct CardConfig cardCfgDelay = {
 cSmartCardVideoGuard2::cSmartCardVideoGuard2(void)
 :cSmartCard(&cardCfg,msgs)
 {
-  cmdList=0;
+  cmdList=0; CAID=0;
 }
 
 cSmartCardVideoGuard2::~cSmartCardVideoGuard2(void)
@@ -594,7 +594,9 @@ bool cSmartCardVideoGuard2::Init(void)
     return false;
     }
   
-  CAID=WORD(buff,0x1D,0xFFFF);
+  unsigned int c=WORD(buff,0x1D,0xFFFF);
+  if(c!=CAID) CaidsChanged();
+  CAID=c;
   memcpy(&cardID,&buff[8],4);
   memcpy(&groupID,&buff[8],4); groupID[3]=0;
   SetCard(new cCardNDS(cardID));