bool cSoftCAM::Load(const char *cfgdir)
{
if(!Feature.KeyFile()) keys.Disable();
- if(!Feature.SmartCard()) smartcards.Disable();
+ if(!Feature.SmartCard()) carddatas.Disable();
cStructLoaders::Load(false);
if(Feature.KeyFile() && keys.Count()<1)
PRINTF(L_GEN_ERROR,"no keys loaded for softcam!");
cStructLoaders::Save(true);
cSystems::Clean();
smartcards.Shutdown();
+ carddatas.SafeClear();
keys.SafeClear();
}
ident=Ident;
}
+// -- cSmartCardDatas ----------------------------------------------------------
+
+cSmartCardDatas carddatas;
+
+cSmartCardDatas::cSmartCardDatas(void)
+:cStructList<cSmartCardData>("smartcard data",DATAFILE,SL_MISSINGOK|SL_WATCH|SL_VERBOSE)
+{}
+
+cSmartCardData *cSmartCardDatas::Find(cSmartCardData *param)
+{
+ ListLock(false);
+ cSmartCardData *cd;
+ for(cd=First(); cd; cd=Next(cd))
+ if(cd->Ident()==param->Ident() && cd->Matches(param)) break;
+ ListUnlock();
+ return cd;
+}
+
+cStructItem *cSmartCardDatas::ParseLine(char *line)
+{
+ char *r=index(line,':');
+ if(r)
+ for(cSmartCardLink *scl=cSmartCards::first; scl; scl=scl->next)
+ if(!strncasecmp(scl->name,line,r-line)) {
+ cSmartCardData *scd=scl->CreateData();
+ if(scd && scd->Parse(r+1)) return scd;
+ delete scd;
+ break;
+ }
+ return 0;
+}
+
// -- cSmartCardLink -----------------------------------------------------------
cSmartCardLink::cSmartCardLink(const char *Name, int Id)
cSmartCards::cSmartCards(void)
:cThread("SmartcardWatcher")
-,cStructList<cSmartCardData>("smartcard data",DATAFILE,SL_MISSINGOK|SL_WATCH|SL_VERBOSE)
{
for(int i=0 ; i<MAX_PORTS ; i++) ports[i].Serial=0;
firstRun=true;
}
}
mutex.Unlock();
- ListLock(true); Clear(); ListUnlock();
}
bool cSmartCards::AddPort(const char *devName, bool invCD, bool invRST, int clock)
return false;
}
-cStructItem *cSmartCards::ParseLine(char *line)
-{
- char *r=index(line,':');
- if(r)
- for(cSmartCardLink *scl=first; scl; scl=scl->next)
- if(!strncasecmp(scl->name,line,r-line)) {
- cSmartCardData *scd=scl->CreateData();
- if(scd && scd->Parse(r+1)) return scd;
- delete scd;
- break;
- }
- return 0;
-}
-
-cSmartCardData *cSmartCards::FindCardData(cSmartCardData *param)
-{
- ListLock(false);
- cSmartCardData *cd;
- for(cd=First(); cd; cd=Next(cd))
- if(cd->ident==param->ident && cd->Matches(param)) break;
- ListUnlock();
- return cd;
-}
-
bool cSmartCards::HaveCard(int id)
{
cMutexLock lock(&mutex);
// ----------------------------------------------------------------
class cSmartCardData : public cStructItem {
-friend class cSmartCards;
protected:
int ident;
public:
virtual ~cSmartCardData() {}
virtual bool Parse(const char *line)=0;
virtual bool Matches(cSmartCardData *cmp)=0;
+ int Ident(void) const { return ident; }
};
// ----------------------------------------------------------------
+class cSmartCardDatas : public cStructList<cSmartCardData> {
+protected:
+ virtual cStructItem *ParseLine(char *line);
+public:
+ cSmartCardDatas(void);
+ cSmartCardData *Find(cSmartCardData *param);
+ };
+
+extern cSmartCardDatas carddatas;
+
+// ----------------------------------------------------------------
+
class cSmartCardLink {
-friend class cSmartCards;
-private:
+public:
cSmartCardLink *next;
const char *name;
int id;
virtual ~cSmartCardLink() {}
virtual cSmartCard *Create(void)=0;
virtual cSmartCardData *CreateData(void) { return 0; }
- int ID(void) { return id; }
};
// ----------------------------------------------------------------
struct Atr Atr;
};
-class cSmartCards : private cThread, public cStructList<cSmartCardData> {
+class cSmartCards : private cThread {
friend class cSmartCardLink;
+friend class cSmartCardDatas;
private:
static cSmartCardLink *first;
cMutex mutex;
void SetPort(struct Port *port, cSmartCard *sc, int id, bool dead);
protected:
virtual void Action(void);
- virtual cStructItem *ParseLine(char *line);
public:
cSmartCards(void);
void Shutdown(void);
bool HaveCard(int id);
cSmartCard *LockCard(int id);
void ReleaseCard(cSmartCard *sc);
- cSmartCardData *FindCardData(cSmartCardData *param);
// to be called ONLY from frontend thread!
bool AddPort(const char *devName, bool invCD, bool invRST, int clock);
void LaunchWatcher(void);
if(ReadRecord(buff,0x9E)>=66) {
HEXDUMP(L_SC_EXTRA,&buff[2],64,"card ISK");
cSmartCardDataCryptoworks cd(dtIPK,Caid);
- cSmartCardDataCryptoworks *entry=(cSmartCardDataCryptoworks *)smartcards.FindCardData(&cd);
+ cSmartCardDataCryptoworks *entry=(cSmartCardDataCryptoworks *)carddatas.Find(&cd);
if(entry) {
PRINTF(L_SC_EXTRA,"got IPK from smartcard.conf");
if(rsa.RSA(&buff[2],&buff[2],64,exp,entry->key,false)>0) {
}
if(!ucpkValid) {
cSmartCardDataCryptoworks cd(dtUCPK,serial);
- cSmartCardDataCryptoworks *entry=(cSmartCardDataCryptoworks *)smartcards.FindCardData(&cd);
+ cSmartCardDataCryptoworks *entry=(cSmartCardDataCryptoworks *)carddatas.Find(&cd);
if(entry) {
BN_copy(ucpk,entry->key);
ucpkValid=true;
}
if(!pinOK) {
cSmartCardDataCryptoworks cd(dtPIN,serial);
- cSmartCardDataCryptoworks *entry=(cSmartCardDataCryptoworks *)smartcards.FindCardData(&cd);
+ cSmartCardDataCryptoworks *entry=(cSmartCardDataCryptoworks *)carddatas.Find(&cd);
if(entry) {
memcpy(&buff[2],entry->pin,4);
pinOK=true;
cSmartCardDataIrdeto *entry=0;
if(!doPlain) {
cSmartCardDataIrdeto cd(ACS,caId);
- if(!(entry=(cSmartCardDataIrdeto *)smartcards.FindCardData(&cd))) {
+ if(!(entry=(cSmartCardDataIrdeto *)carddatas.Find(&cd))) {
PRINTF(L_GEN_WARN,"didn't find Irdeto card specific certificate, falling back to default");
cSmartCardDataIrdeto cd(-1,-1);
- if(!(entry=(cSmartCardDataIrdeto *)smartcards.FindCardData(&cd))) {
+ if(!(entry=(cSmartCardDataIrdeto *)carddatas.Find(&cd))) {
PRINTF(L_GEN_WARN,"didn't find default Irdeto certificate, please add one");
if(ACS!=0x0384) return false;
PRINTF(L_GEN_WARN,"trying pre-coded ACS 384 challenge. This mode is DEPRECATED. There ARE valid certificates for these cards available!");
bool sessOk=false;
if(buff[5]!=0 && irdProvId==((buff[10]*256)|buff[11])) { // prepare DT08 data
cSmartCardDataNagra cd(irdProvId,true);
- if(!(entry=(cSmartCardDataNagra *)smartcards.FindCardData(&cd))) {
+ if(!(entry=(cSmartCardDataNagra *)carddatas.Find(&cd))) {
PRINTF(L_GEN_WARN,"didn't find smartcard Nagra IRD modulus");
}
else {
}
else {
cSmartCardDataNagra cd(irdProvId);
- if(!(entry=(cSmartCardDataNagra *)smartcards.FindCardData(&cd))) {
+ if(!(entry=(cSmartCardDataNagra *)carddatas.Find(&cd))) {
PRINTF(L_GEN_WARN,"didn't find smartcard Nagra CAM modulus");
}
else {
}
if(!boxidOK) {
cSmartCardDataVideoGuard2 cd(dtBoxId);
- cSmartCardDataVideoGuard2 *entry=(cSmartCardDataVideoGuard2 *)smartcards.FindCardData(&cd);
+ cSmartCardDataVideoGuard2 *entry=(cSmartCardDataVideoGuard2 *)carddatas.Find(&cd);
if(entry) {
memcpy(&boxID,entry->boxid,sizeof(boxID));
boxidOK=true;
PRINTF(L_SC_INIT,"cardtype: %c%c.%d boxID %s caid %04x cardID %s",atr->hist[10],atr->hist[11],atr->hist[12],HexStr(str,boxID,4),CAID,HexStr(str2,cardID,4));
cSmartCardDataVideoGuard2 cd(dtSeed);
- cSmartCardDataVideoGuard2 *entry=(cSmartCardDataVideoGuard2 *)smartcards.FindCardData(&cd);
+ cSmartCardDataVideoGuard2 *entry=(cSmartCardDataVideoGuard2 *)carddatas.Find(&cd);
if(!entry) {
PRINTF(L_SC_ERROR,"no NDS seed available");
return false;