SASC
DVBSoftCAM

cSmartCardSlot Class Reference

Inheritance diagram for cSmartCardSlot:

List of all members.

Public Member Functions

 cSmartCardSlot (void)
virtual ~cSmartCardSlot ()
bool Setup (int num, const char *cfg)
void SetCardConfig (const struct CardConfig *Cfg)
void TriggerReset (void)
bool HaveCard (int id)
cSmartCard * LockCard (int id)
void ReleaseCard (cSmartCard *sc)
void GetCardIdStr (char *str, int len)
bool GetCardInfoStr (char *str, int len)
int SlotNum (void)
virtual bool IsoRead (const unsigned char *cmd, unsigned char *data)
virtual bool IsoWrite (const unsigned char *cmd, const unsigned char *data)
virtual int RawRead (unsigned char *data, int len, int to=0)
virtual int RawWrite (const unsigned char *data, int len)
 cSmartCardSlot (void)
virtual ~cSmartCardSlot ()
bool Setup (int num, const char *cfg)
void SetCardConfig (const struct CardConfig *Cfg)
void TriggerReset (void)
bool HaveCard (int id)
cSmartCard * LockCard (int id)
void ReleaseCard (cSmartCard *sc)
void GetCardIdStr (char *str, int len)
bool GetCardInfoStr (char *str, int len)
int SlotNum (void)
virtual bool IsoRead (const unsigned char *cmd, unsigned char *data)
virtual bool IsoWrite (const unsigned char *cmd, const unsigned char *data)
virtual int RawRead (unsigned char *data, int len, int to=0)
virtual int RawWrite (const unsigned char *data, int len)

Protected Member Functions

virtual bool DeviceOpen (const char *cfg)=0
virtual void DeviceClose (void)
virtual bool DeviceSetMode (int mode, int baud)=0
virtual int DeviceRead (unsigned char *mem, int len, int timeout, int initialTimeout=0)=0
virtual int DeviceWrite (const unsigned char *mem, int len, int delay=0)=0
virtual void DeviceToggleReset (void)=0
virtual bool DevicePTS (void)=0
virtual bool DeviceIsInserted (void)=0
virtual int DeviceCurrentMode (void)
virtual void Action (void)
int Procedure (unsigned char ins, int restLen)
int Read (unsigned char *data, int len, int to=0)
int Write (const unsigned char *data, int len)
bool Test (bool res)
void Invert (unsigned char *data, int n)
virtual bool Reset (void)
bool ParseAtr (void)
virtual bool DeviceOpen (const char *cfg)=0
virtual void DeviceClose (void)
virtual bool DeviceSetMode (int mode, int baud)=0
virtual int DeviceRead (unsigned char *mem, int len, int timeout, int initialTimeout=0)=0
virtual int DeviceWrite (const unsigned char *mem, int len, int delay=0)=0
virtual void DeviceToggleReset (void)=0
virtual bool DevicePTS (void)=0
virtual bool DeviceIsInserted (void)=0
virtual int DeviceCurrentMode (void)
virtual void Action (void)
int Procedure (unsigned char ins, int restLen)
int Read (unsigned char *data, int len, int to=0)
int Write (const unsigned char *data, int len)
bool Test (bool res)
void Invert (unsigned char *data, int n)
virtual bool Reset (void)
bool ParseAtr (void)

Protected Attributes

int slotnum
int clock
struct CardConfig * cfg
unsigned char sb [SB_LEN]
struct Atr atr
bool localecho
bool singlereset
char devName [256]
int currMode

Detailed Description

Definition at line 47 of file smartcard.c.


Constructor & Destructor Documentation

cSmartCardSlot::cSmartCardSlot ( void  )

Definition at line 107 of file smartcard.c.

References cfg, clock, currMode, ISO_FREQ, localecho, singlereset, slotnum, and SM_NONE.

{
  card=0; cfg=0; usecount=0; slotnum=-1; currMode=SM_NONE; clock=ISO_FREQ;
  firstRun=true; needsReset=false; dead=false;
  localecho=true; singlereset=false;
}
cSmartCardSlot::~cSmartCardSlot ( ) [virtual]

Definition at line 114 of file smartcard.c.

References cThread::Cancel(), and DeviceClose().

{
  Cancel(3);
  SetCard(0);
  DeviceClose();
}
cSmartCardSlot::cSmartCardSlot ( void  )
virtual cSmartCardSlot::~cSmartCardSlot ( ) [virtual]

Member Function Documentation

void cSmartCardSlot::Action ( void  ) [protected, virtual]

A derived cThread class must implement the code it wants to execute as a separate thread in this function. If this is a loop, it must check Running() repeatedly to see whether it's time to stop.

Implements cThread.

Definition at line 202 of file smartcard.c.

References atr, cCondVar::Broadcast(), DeviceCurrentMode(), DeviceIsInserted(), DeviceSetMode(), cSmartCards::First(), ISO_BAUD, L_CORE_SC, cMutex::Lock(), cSmartCards::Next(), PRINTF, cThread::Running(), sb, sc, serModes, cSmartCard::Setup(), singlereset, cCondWait::SleepMs(), slotnum, SM_MASK, SM_MAX, SM_NONE, smartcards, and cMutex::Unlock().

{
  while(Running()) {
    if(card) {
      card->Lock();
      if(!DeviceIsInserted()) {
        card->Unlock();
        PRINTF(L_CORE_SC,"%d: card removed (usecount=%d)",slotnum,usecount);
        SetCard(0);
        }
      else if(needsReset) {
        PRINTF(L_CORE_SC,"%d: card reset requested",slotnum);
        int mode=DeviceCurrentMode()&SM_MASK;
        if(!DeviceSetMode(mode,ISO_BAUD)
            || !CardReset()
            || !card->Setup(this,mode,&atr,sb)) {
          card->Unlock();
          PRINTF(L_CORE_SC,"%d: card re-init failed",slotnum);
          SetCard(0); dead=true;
          }
        }
      if(card) card->Unlock();
      }
    else if(DeviceIsInserted()) {
      if(!dead) {
        PRINTF(L_CORE_SC,"%d: new card inserted",slotnum);
        bool resetdone=false;
        for(int mode=SM_NONE+1 ; mode<SM_MAX ; mode++) {
          if(DeviceSetMode(mode,ISO_BAUD)) {
            if((singlereset && resetdone) || (resetdone=CardReset())) {
              for(cSmartCardLink *scl=smartcards.First(); scl; scl=smartcards.Next(scl)) {
                if(!Running()) goto done;
                PRINTF(L_CORE_SC,"%d: checking for %s card",slotnum,scl->Name());
                cSmartCard *sc=scl->Create();
                if(sc && sc->Setup(this,mode,&atr,sb)) {
                  SetCard(sc,scl->Id());
                  goto done; // ugly, any better solution?
                  }
                delete sc;
                }
              PRINTF(L_CORE_SC,"%d: no card handler found",slotnum);
              }
            else PRINTF(L_CORE_SC,"%d: reset/atr error",slotnum);
            }
          else PRINTF(L_CORE_SC,"%d: failed to set serial mode %s",slotnum,serModes[mode]);
          }
        dead=true;
        PRINTF(L_CORE_SC,"%d: can't initialise new card, ignoring port until card reinserted",slotnum);
        }
      }
    else {
      if(dead) PRINTF(L_CORE_SC,"%d: card removed, port reactivated",slotnum);
      dead=false;
      }
done:
    if(firstRun) {
      mutex.Lock();
      cond.Broadcast();
      firstRun=false;
      mutex.Unlock();
      }
    cCondWait::SleepMs(300);
    }
}
virtual void cSmartCardSlot::Action ( void  ) [protected, virtual]

A derived cThread class must implement the code it wants to execute as a separate thread in this function. If this is a loop, it must check Running() repeatedly to see whether it's time to stop.

Implements cThread.

virtual void cSmartCardSlot::DeviceClose ( void  ) [inline, protected, virtual]

Reimplemented in cSmartCardSlotSerial, and cSmartCardSlotSerial.

Definition at line 59 of file smartcard.c.

{}
virtual void cSmartCardSlot::DeviceClose ( void  ) [inline, protected, virtual]

Reimplemented in cSmartCardSlotSerial, and cSmartCardSlotSerial.

Definition at line 59 of file smartcard.c.

Referenced by ~cSmartCardSlot().

{}
virtual int cSmartCardSlot::DeviceCurrentMode ( void  ) [inline, protected, virtual]

Definition at line 66 of file smartcard.c.

References currMode.

{ return currMode; }
virtual int cSmartCardSlot::DeviceCurrentMode ( void  ) [inline, protected, virtual]

Definition at line 66 of file smartcard.c.

References currMode.

Referenced by Action(), cSmartCardSlotSerial::DevicePTS(), and Reset().

{ return currMode; }
virtual bool cSmartCardSlot::DeviceIsInserted ( void  ) [protected, pure virtual]

Implemented in cSmartCardSlotSerial, and cSmartCardSlotSerial.

Referenced by Action(), and LockCard().

virtual bool cSmartCardSlot::DeviceIsInserted ( void  ) [protected, pure virtual]
virtual bool cSmartCardSlot::DeviceOpen ( const char *  cfg) [protected, pure virtual]
virtual bool cSmartCardSlot::DeviceOpen ( const char *  cfg) [protected, pure virtual]
virtual bool cSmartCardSlot::DevicePTS ( void  ) [protected, pure virtual]
virtual bool cSmartCardSlot::DevicePTS ( void  ) [protected, pure virtual]
virtual int cSmartCardSlot::DeviceRead ( unsigned char *  mem,
int  len,
int  timeout,
int  initialTimeout = 0 
) [protected, pure virtual]

Implemented in cSmartCardSlotSerial, and cSmartCardSlotSerial.

Referenced by Read(), Reset(), and Write().

virtual int cSmartCardSlot::DeviceRead ( unsigned char *  mem,
int  len,
int  timeout,
int  initialTimeout = 0 
) [protected, pure virtual]
virtual bool cSmartCardSlot::DeviceSetMode ( int  mode,
int  baud 
) [protected, pure virtual]
virtual bool cSmartCardSlot::DeviceSetMode ( int  mode,
int  baud 
) [protected, pure virtual]
virtual void cSmartCardSlot::DeviceToggleReset ( void  ) [protected, pure virtual]
virtual void cSmartCardSlot::DeviceToggleReset ( void  ) [protected, pure virtual]

Implemented in cSmartCardSlotSerial, and cSmartCardSlotSerial.

Referenced by Reset().

virtual int cSmartCardSlot::DeviceWrite ( const unsigned char *  mem,
int  len,
int  delay = 0 
) [protected, pure virtual]
virtual int cSmartCardSlot::DeviceWrite ( const unsigned char *  mem,
int  len,
int  delay = 0 
) [protected, pure virtual]

Implemented in cSmartCardSlotSerial, and cSmartCardSlotSerial.

Referenced by Write().

void cSmartCardSlot::GetCardIdStr ( char *  str,
int  len 
)

Definition at line 170 of file smartcard.c.

References cSmartCards::First(), cSmartCard::GetCardIdStr(), cMutex::Lock(), cSmartCards::Next(), smartcards, strn0cpy(), and cMutex::Unlock().

Referenced by cSmartCards::ListCard().

{
  mutex.Lock();
  if(card && !card->GetCardIdStr(str,len)) {
    for(cSmartCardLink *scl=smartcards.First(); scl; smartcards.Next(scl)) {
      if(scl->Id()==cardid) {
        strn0cpy(str,scl->Name(),len);
        break;
        }
      }
    }
  mutex.Unlock();
}
void cSmartCardSlot::GetCardIdStr ( char *  str,
int  len 
)
bool cSmartCardSlot::GetCardInfoStr ( char *  str,
int  len 
)

Definition at line 184 of file smartcard.c.

References cSmartCard::GetCardInfoStr(), cMutex::Lock(), and cMutex::Unlock().

Referenced by cSmartCards::CardInfo().

{
  mutex.Lock();
  bool res=false;
  if(card) res=card->GetCardInfoStr(str,len);
  mutex.Unlock();
  return res;
}
bool cSmartCardSlot::GetCardInfoStr ( char *  str,
int  len 
)
bool cSmartCardSlot::HaveCard ( int  id)
bool cSmartCardSlot::HaveCard ( int  id)

Definition at line 133 of file smartcard.c.

References id, cThread::Running(), and cCondVar::Wait().

{
  cMutexLock lock(&mutex);
  while(Running() && firstRun) cond.Wait(mutex);
  return card && cardid==id;
}
void cSmartCardSlot::Invert ( unsigned char *  data,
int  n 
) [protected]
void cSmartCardSlot::Invert ( unsigned char *  data,
int  n 
) [protected]

Definition at line 289 of file smartcard.c.

References i.

Referenced by ParseAtr(), Read(), and Write().

{
  static const unsigned char swaptab[] =  { 15,7,11,3,13,5,9,1,14,6,10,2,12,4,8,0 };
  for(int i=n-1; i>=0; i--)
    data[i]=(swaptab[data[i]&0x0f]<<4) | swaptab[data[i]>>4];
}
bool cSmartCardSlot::IsoRead ( const unsigned char *  cmd,
unsigned char *  data 
) [virtual]

Definition at line 365 of file smartcard.c.

References CMD_LEN, INS_IDX, L_CORE_SC, LDUMP, LEN_IDX, Procedure(), Read(), slotnum, Test(), tr, and Write().

Referenced by cSmartCard::IsoRead().

{
  LDUMP(L_CORE_SC,cmd,CMD_LEN,"%d: -> INS:",slotnum);
  if(Write(cmd,CMD_LEN)<0) return Test(false);
  int tr=cmd[LEN_IDX] ? cmd[LEN_IDX] : 256;
  int len=0;
  while(1) {
    int r=Procedure(cmd[INS_IDX],tr-len);
    if(r<=0) return Test(r==0);
    if(Read(data+len,r)<0) return Test(false);
    LDUMP(L_CORE_SC,data+len,r,"%d: <- DATA:",slotnum);
    len+=r;
    }
}
virtual bool cSmartCardSlot::IsoRead ( const unsigned char *  cmd,
unsigned char *  data 
) [virtual]
bool cSmartCardSlot::IsoWrite ( const unsigned char *  cmd,
const unsigned char *  data 
) [virtual]

Definition at line 380 of file smartcard.c.

References CMD_LEN, INS_IDX, L_CORE_SC, LDUMP, LEN_IDX, Procedure(), slotnum, Test(), and Write().

Referenced by cSmartCard::IsoWrite().

{
  LDUMP(L_CORE_SC,cmd,CMD_LEN,"%d: -> INS:",slotnum);
  if(Write(cmd,CMD_LEN)<0) return Test(false);
  int len=0;
  while(1) {
    int r=Procedure(cmd[INS_IDX],cmd[LEN_IDX]-len);
    if(r<=0) return Test(r==0);
    if(Write(data+len,r)<0) return Test(false);
    LDUMP(L_CORE_SC,data+len,r,"%d: -> DATA:",slotnum);
    len+=r;
    }
}
virtual bool cSmartCardSlot::IsoWrite ( const unsigned char *  cmd,
const unsigned char *  data 
) [virtual]
cSmartCard * cSmartCardSlot::LockCard ( int  id)

Definition at line 140 of file smartcard.c.

References cCondVar::Broadcast(), cSmartCard::CardUp(), DeviceIsInserted(), cMutex::Lock(), cThread::Running(), cMutex::Unlock(), and cCondVar::Wait().

{
  mutex.Lock();
  while(Running() && firstRun) cond.Wait(mutex);
  if(card && cardid==id) {
    usecount++;
    mutex.Unlock();
    card->Lock();
    if(DeviceIsInserted() && card->CardUp() && !needsReset) return card;
    // if failed, unlock the card and decrement UseCount
    card->Unlock();
    mutex.Lock();
    usecount--;
    cond.Broadcast();
    }
  mutex.Unlock();
  return 0;
}
cSmartCard* cSmartCardSlot::LockCard ( int  id)
bool cSmartCardSlot::ParseAtr ( void  ) [protected]

Definition at line 410 of file smartcard.c.

References Atr::atr, atr, Atr::atrLen, Atr::BWI, Atr::bwt, clock, Atr::convention, cs, Atr::CWI, Atr::D, Atr::F, Atr::fs, Atr::hist, Atr::histLen, i, Invert(), L_CORE_SC, LBEND, LBFLUSH, LBPUT, LBSTART, LBSTARTF, Atr::N, NEED, PRINTF, slotnum, SM_DIRECT, SM_INDIRECT, SM_INDIRECT_INV, Atr::T, Atr::TA1, Atr::Tspec, Atr::WI, Atr::wwt, and XorSum().

{
  // default values
  atr.histLen=0; atr.T=0; atr.F=372; atr.fs=clock; atr.D=1.0; atr.N=0; atr.WI=10;
  atr.BWI=4; atr.CWI=0; atr.Tspec=-1;

  static const int Ftable[16] = {
    372,372,558,744,1116,1488,1860,0,0,512,768,1024,1536,2048,0,0
    };
  static const int fstable[16] = {
    3571200,5000000,6000000, 8000000,12000000,16000000,20000000,0,
          0,5000000,7500000,10000000,15000000,20000000,       0,0
    };
  static const float Dtable[16] = {
    0.0,1.0,2.0,4.0,8.0,16.0,0.0,0.0,
    0.0,0.0,0.5,0.25,0.125,0.0625,0.03125,0.015625
    };

  const unsigned char *rawatr=atr.atr;
  if(rawatr[0]==0x03) {
    PRINTF(L_CORE_SC,"%d: indirect convention detected",slotnum);
    Invert(atr.atr,atr.atrLen);
    atr.convention=SM_INDIRECT;
    }
  else if(rawatr[0]==0x3B) {
    PRINTF(L_CORE_SC,"%d: direct convention detected",slotnum);
    atr.convention=SM_DIRECT;
    }
  else if(rawatr[0]==0x3F) {
    PRINTF(L_CORE_SC,"%d: inverted indirect convention detected",slotnum);
    atr.convention=SM_INDIRECT_INV;
    }
  else {
    PRINTF(L_CORE_SC,"%d: byte mode not supported 0x%02x",slotnum,rawatr[0]);
    return false;
    }

  // TS TO
  atr.histLen=rawatr[1]&0x0F;
  int Y=rawatr[1]&0xF0, i=1, len=2;
  LBSTARTF(L_CORE_SC);
  LBPUT("%d: atr decoding TS=%02x hist=%d Y%d=%02x ",slotnum,rawatr[0],atr.histLen,i,Y);
  do {
    if(Y&0x10) { // TAi
      NEED(1);
      LBPUT("TA%d=%02x ",i,rawatr[len]);
      if(i==1) {
        atr.TA1=rawatr[len];
        int i=(rawatr[len]>>4)&0x0F;
        atr.F=Ftable[i]; atr.fs=fstable[i];
        atr.D=Dtable[rawatr[len]&0x0F];
        LBPUT("F=%d fs=%.4f D=%f ",atr.F,atr.fs/1000000.0,atr.D);
        }
      else if(i==2) {
        atr.Tspec=rawatr[len]&0x0F;
        LBPUT("Tspec=%d ",atr.Tspec);
        }
      else if(i==3) {
        LBPUT("IFSC=%d ",rawatr[len]);
        }
      len++;
      }
    if(Y&0x20) { // TBi
      NEED(1);
      LBPUT("TB%d=%02x ",i,rawatr[len]);
      if(i==3) {
        atr.BWI=(rawatr[len]>>4)&0x0F;
        atr.CWI=rawatr[len]&0x0F;
        LBPUT("BWI=%d CWI=%d ",atr.BWI,atr.CWI);
        }
      len++;
      }
    if(Y&0x40) { // TCi
      NEED(1);
      LBPUT("TC%d=%02x ",i,rawatr[len]);
      if(i==1) {
        atr.N=rawatr[len];
        LBPUT("N=%d ",atr.N);
        }
      else if(i==2) {
        atr.WI=rawatr[len];
        LBPUT("WI=%d ",atr.WI);
        }
      else if(i==3) {
        LBPUT("CHK=%s ",rawatr[len]&1 ? "CRC16":"LRC");
        }
      len++;
      }
    if(Y&0x80) { // TDi
      NEED(1);
      LBPUT("TD%d=%02x ",i,rawatr[len]);
      if(i==1) {
        atr.T=rawatr[len]&0x0F;
        LBPUT("T=%d ",atr.T);
        }
      else {
        LBPUT("Tn=%d ",rawatr[len]&0x0F);
        }
      Y=rawatr[len]&0xF0;
      len++;
      }
    else Y=0;
    i++;
    LBPUT("Y%d=%02x ",i,Y);
    } while(Y);
  NEED(atr.histLen);
  LBEND();

  LBSTART(L_CORE_SC);
  LBPUT("%d: historical:",slotnum);
  for(int i=0; i<atr.histLen; i++) LBPUT(" %02x",rawatr[len+i]);
  LBFLUSH();
  LBPUT("%d: historical: '",slotnum);
  for(int i=0; i<atr.histLen; i++) LBPUT("%c",isprint(rawatr[len+i]) ? rawatr[len+i] : '.');
  LBEND();

  memcpy(atr.hist,&rawatr[len],atr.histLen);
  len+=atr.histLen;

  // TCK
  if(atr.T!=0 && len+1<=atr.atrLen) {
    len++;
    unsigned char cs=XorSum(rawatr+1,len-1);
    // according to the ISO the initial TS byte isn't checksumed, but
    // some cards do so. In this case the checksum is equal TS.
    if(cs==0) PRINTF(L_CORE_SC,"%d: atr checksum ok",slotnum);
    else if(cs==rawatr[0]) PRINTF(L_CORE_SC,"iso: %d: atr checksum is TS (not ISO compliant)",slotnum);
    else {
      PRINTF(L_CORE_SC,"%d: atr checksum FAILED (cs:%02x)",slotnum,cs);
      return false;
      }
    }
  else PRINTF(L_CORE_SC,"%d: atr checksum not given/not required",slotnum);

  if(atr.atrLen>len) PRINTF(L_CORE_SC,"%d: long atr read=%d len=%d",slotnum,atr.atrLen,len);
  atr.wwt=960*atr.WI*atr.F/(clock/1000);
  atr.bwt=(int)(960*(float)(1<<atr.BWI)*372/(clock/1000));
  PRINTF(L_CORE_SC,"%d: indicated wwt(T0)=%d ms, bwt(T1)=%d ms (at %.4f MHz)",slotnum,atr.wwt,atr.bwt,(float)clock/1000000);
  return true;
}
bool cSmartCardSlot::ParseAtr ( void  ) [protected]
int cSmartCardSlot::Procedure ( unsigned char  ins,
int  restLen 
) [protected]

Definition at line 320 of file smartcard.c.

References cfg, L_CORE_SC, LBEND, LBPUT, LBSTARTF, Read(), sb, slotnum, and CardConfig::workTO.

Referenced by IsoRead(), and IsoWrite().

{
  int r;
  unsigned char buff;
  LBSTARTF(L_CORE_SC);
  LBPUT("%d: <- PROC: ",slotnum);
  do {
    do {
      if(Read(&buff,1,cfg->workTO)<=0) return -1;
      LBPUT("%02x ",buff);
      } while(buff==0x60);

    if((buff&0xF0)==0x60 || (buff&0xF0)==0x90) { // SW1/SW2
      sb[0]=buff;
      if(Read(&buff,1)<=0) return -1;
      LBPUT("%02x",buff);
      sb[1]=buff;
      return 0;
      }
    else {
      if((buff&0xFE)==(ins&0xFE)) r=restLen;
      else if((~buff&0xFE)==(ins&0xFE)) r=1;
      else {
        LBPUT("cannot handle procedure %02x (ins=%02x)",buff,ins);
        return -1;
        }
      if(r>restLen) {
        LBPUT("data overrun r=%d restLen=%d",r,restLen);
        return -1;
        }
      }
    } while(r==0);
  LBEND();
  return r;
}
int cSmartCardSlot::Procedure ( unsigned char  ins,
int  restLen 
) [protected]
int cSmartCardSlot::RawRead ( unsigned char *  data,
int  len,
int  to = 0 
) [virtual]

Definition at line 394 of file smartcard.c.

References Read(), and Test().

Referenced by cSmartCard::SerRead().

{
  int r=Read(data,len,to);
  if(r<0) Test(false);
  return r;
}
virtual int cSmartCardSlot::RawRead ( unsigned char *  data,
int  len,
int  to = 0 
) [virtual]
virtual int cSmartCardSlot::RawWrite ( const unsigned char *  data,
int  len 
) [virtual]
int cSmartCardSlot::RawWrite ( const unsigned char *  data,
int  len 
) [virtual]

Definition at line 401 of file smartcard.c.

References Test(), and Write().

Referenced by cSmartCard::SerWrite().

{
  int r=Write(data,len);
  if(r<0) Test(false);
  return r;
}
int cSmartCardSlot::Read ( unsigned char *  data,
int  len,
int  to = 0 
) [protected]
int cSmartCardSlot::Read ( unsigned char *  data,
int  len,
int  to = 0 
) [protected]

Definition at line 296 of file smartcard.c.

References atr, cfg, Atr::convention, DeviceRead(), Invert(), CardConfig::serTO, and SM_INDIRECT.

Referenced by IsoRead(), Procedure(), and RawRead().

{
  int r=DeviceRead(data,len,cfg->serTO,to);
  if(atr.convention==SM_INDIRECT && r>0) Invert(data,r);
  return r;
}
void cSmartCardSlot::ReleaseCard ( cSmartCard *  sc)
void cSmartCardSlot::ReleaseCard ( cSmartCard *  sc)

Definition at line 159 of file smartcard.c.

References cCondVar::Broadcast(), cMutex::Lock(), and cMutex::Unlock().

{
  if(card==sc) {
    card->Unlock();
    mutex.Lock();
    usecount--;
    cond.Broadcast();
    mutex.Unlock();
    }
}
virtual bool cSmartCardSlot::Reset ( void  ) [protected, virtual]
bool cSmartCardSlot::Reset ( void  ) [protected, virtual]

Definition at line 267 of file smartcard.c.

References Atr::atr, atr, Atr::atrLen, DeviceCurrentMode(), DeviceRead(), DeviceToggleReset(), L_CORE_SC, LDUMP, MAX_ATR_LEN, PRINTF, serModes, cCondWait::SleepMs(), and slotnum.

{
  PRINTF(L_CORE_SC,"%d: reseting card (sermode %s)",slotnum,serModes[DeviceCurrentMode()]);
  DeviceToggleReset();
  cCondWait::SleepMs(100);
  DeviceToggleReset();
  int r=DeviceRead(atr.atr,-MAX_ATR_LEN,800,2000);
  atr.atrLen=r;
  if(r>0) LDUMP(L_CORE_SC,atr.atr,r,"%d: <- ATR len=%d:",slotnum,r);
  return r>=2;
}
void cSmartCardSlot::SetCardConfig ( const struct CardConfig *  Cfg) [inline]

Definition at line 90 of file smartcard.c.

{ cfg=Cfg; }
void cSmartCardSlot::SetCardConfig ( const struct CardConfig *  Cfg) [inline]

Definition at line 90 of file smartcard.c.

Referenced by cSmartCard::NewCardConfig(), and cSmartCard::Setup().

{ cfg=Cfg; }
bool cSmartCardSlot::Setup ( int  num,
const char *  cfg 
)

Definition at line 121 of file smartcard.c.

References DeviceOpen(), cThread::SetDescription(), slotnum, and cThread::Start().

Referenced by cSmartCardSlots::ParseLinePlain().

{
  slotnum=num;
  SetDescription("CardSlot %d watcher",slotnum);
  if(DeviceOpen(cfg)) {
    firstRun=true;
    Start();
    return true;
    }
  return false;
}
bool cSmartCardSlot::Setup ( int  num,
const char *  cfg 
)
int cSmartCardSlot::SlotNum ( void  ) [inline]

Definition at line 97 of file smartcard.c.

References slotnum.

Referenced by cSmartCard::Setup().

{ return slotnum; }
int cSmartCardSlot::SlotNum ( void  ) [inline]

Definition at line 97 of file smartcard.c.

References slotnum.

{ return slotnum; }
bool cSmartCardSlot::Test ( bool  res) [protected]

Definition at line 356 of file smartcard.c.

References L_CORE_SC, PRINTF, slotnum, and TriggerReset().

Referenced by IsoRead(), IsoWrite(), RawRead(), and RawWrite().

{
 if(!res) {
   TriggerReset();
   PRINTF(L_CORE_SC,"%d: reset triggered",slotnum);
   }
 return res;
}
bool cSmartCardSlot::Test ( bool  res) [protected]
void cSmartCardSlot::TriggerReset ( void  ) [inline]

Definition at line 91 of file smartcard.c.

{ needsReset=true; }
void cSmartCardSlot::TriggerReset ( void  ) [inline]

Definition at line 91 of file smartcard.c.

Referenced by cSmartCards::CardReset(), and Test().

{ needsReset=true; }
int cSmartCardSlot::Write ( const unsigned char *  data,
int  len 
) [protected]

Definition at line 303 of file smartcard.c.

References atr, AUTOMEM, cfg, Atr::convention, DeviceRead(), DeviceWrite(), Invert(), localecho, CardConfig::serDL, CardConfig::serTO, and SM_INDIRECT.

Referenced by IsoRead(), IsoWrite(), and RawWrite().

{
  unsigned char *tmp=AUTOMEM(len);
  if(atr.convention==SM_INDIRECT) {
    memcpy(tmp,data,len);
    Invert(tmp,len);
    data=tmp;
    }
  int r=DeviceWrite(data,len,cfg->serDL);
  if(r>0 && localecho) {
    unsigned char *buff=AUTOMEM(r);
    int rr=DeviceRead(buff,r,cfg->serTO);
    if(rr<0) r=rr;
    }
  return r;
}
int cSmartCardSlot::Write ( const unsigned char *  data,
int  len 
) [protected]

Member Data Documentation

struct CardConfig * cSmartCardSlot::cfg [protected]

Definition at line 79 of file smartcard.c.

Referenced by cSmartCardSlot(), Procedure(), Read(), and Write().

bool cSmartCardSlot::localecho [protected]

Definition at line 82 of file smartcard.c.

Referenced by cSmartCardSlot(), cSmartCardSlotSRPlus::cSmartCardSlotSRPlus(), and Write().

unsigned char cSmartCardSlot::sb [protected]

Definition at line 80 of file smartcard.c.

Referenced by Action(), and Procedure().

bool cSmartCardSlot::singlereset [protected]

Definition at line 82 of file smartcard.c.

Referenced by Action(), and cSmartCardSlot().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines