From: leslie Date: Wed, 15 Oct 2008 22:37:46 +0000 (+0800) Subject: sc-videoguard2: add delayed writing mode (untested) X-Git-Tag: 0.9.1~10 X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=139043c78713830065f9e89362bc01e4dbd110ea;p=sasc-ng.git sc-videoguard2: add delayed writing mode (untested) --- diff --git a/smartcard.c b/smartcard.c index fb3838e..0f642bd 100644 --- a/smartcard.c +++ b/smartcard.c @@ -161,7 +161,7 @@ bool cSerial::SetMode(int mode, int baud) LBPUT("%s: set serial options: %d,",devName,baud); tio.c_cflag = (CS8 | CREAD | HUPCL | CLOCAL); if(!(mode&SM_1SB)) tio.c_cflag |= CSTOPB; - tio.c_iflag = (INPCK | BRKINT); + tio.c_iflag = (INPCK | IGNBRK); tio.c_cc[VMIN] = 1; cfsetispeed(&tio,bconst); cfsetospeed(&tio,bconst); @@ -761,8 +761,14 @@ static const float Dtable[16] = { cSmartCard::cSmartCard(const struct CardConfig *Cfg, const struct StatusMsg *Msg) { - cfg=Cfg; msg=Msg; + msg=Msg; ser=0; atr=0; idStr[0]=0; cardUp=false; needsReset=true; + NewCardConfig(Cfg); +} + +void cSmartCard::NewCardConfig(const struct CardConfig *Cfg) +{ + cfg=Cfg; } bool cSmartCard::GetCardIdStr(char *str, int len) @@ -965,7 +971,7 @@ int cSmartCard::Write(const unsigned char *data, int len) Invert(tmp,len); data=tmp; } - int r=ser->Write(data,len); + int r=ser->Write(data,len,cfg->serDL); if(r>0) { unsigned char *buff=AUTOMEM(r); int rr=ser->Read(buff,r,cfg->serTO); diff --git a/smartcard.h b/smartcard.h index f1eb72f..838ab07 100644 --- a/smartcard.h +++ b/smartcard.h @@ -74,7 +74,7 @@ public: struct CardConfig { int SerMode; - int workTO, serTO; // values in ms + int workTO, serTO, serDL; // values in ms }; struct StatusMsg { @@ -117,6 +117,7 @@ protected: bool IsoWrite(const unsigned char *cmd, const unsigned char *data); bool Status(void); bool Test(bool res); + void NewCardConfig(const struct CardConfig *Cfg); int CheckSctLen(const unsigned char *data, int off); void TriggerReset(void) { needsReset=true; } static void Invert(unsigned char *data, int n); diff --git a/systems/sc-videoguard2/sc-videoguard2.c b/systems/sc-videoguard2/sc-videoguard2.c index 9dcdc11..3080e88 100644 --- a/systems/sc-videoguard2/sc-videoguard2.c +++ b/systems/sc-videoguard2/sc-videoguard2.c @@ -498,6 +498,10 @@ static const struct CardConfig cardCfg = { SM_8O2,2000,1400 }; +static const struct CardConfig cardCfgDelay = { + SM_8O2,2000,1400,20 + }; + cSmartCardVideoGuard2::cSmartCardVideoGuard2(void) :cSmartCard(&cardCfg,msgs) { @@ -531,7 +535,11 @@ bool cSmartCardVideoGuard2::Init(void) static unsigned char ins7401[] = { 0xD0,0x74,0x01,0x00,0x00 }; int l; - if((l=ReadCmdLen(ins7401))<0) return false; + if((l=ReadCmdLen(ins7401))<0) { + PRINTF(L_SC_ERROR,"bogus answer. Now try delayed mode"); + NewCardConfig(&cardCfgDelay); + if((l=ReadCmdLen(ins7401))<0) return false; + } ins7401[4]=l; unsigned char buff[256]; if(!IsoRead(ins7401,buff) || !Status()) {