--- src/coolkey/slot.cpp.gemalto.64k 2008-01-10 11:17:02.000000000 -0800 +++ src/coolkey/slot.cpp 2008-01-10 11:20:45.000000000 -0800 @@ -205,6 +205,29 @@ return FALSE; } +bool +SlotList::readerNameExistsInList(const char *readerName,CKYReaderNameList *readerNameList) +{ + if( !readerName || !readerNameList) { + return FALSE; + } + + int i = 0; + int readerNameCnt = CKYReaderNameList_GetCount(*readerNameList); + + const char *curReaderName = NULL; + for(i=0; i < readerNameCnt; i++) { + curReaderName = CKYReaderNameList_GetValue(*readerNameList,i); + + if(!strcmp(curReaderName,readerName)) { + return TRUE; + } + + } + + return FALSE; +} + /* * you need to hold the ReaderList Lock before you can update the ReaderList */ @@ -258,6 +281,27 @@ * don't recognize. */ + /* first though, let's check to see if any previously removed readers have + * come back from the dead. If the ignored bit has been set, we do not need + * it any more. + */ + + const char *curReaderName = NULL; + unsigned long knownState = 0; + for(int ri = 0 ; ri < numReaders; ri ++) { + + knownState = CKYReader_GetKnownState(&readerStates[ri]); + if( !(knownState & SCARD_STATE_IGNORE)) { + continue; + } + + curReaderName = CKYReader_GetReaderName(&readerStates[ri]); + if(readerNameExistsInList(curReaderName,&readerNames)) { + CKYReader_SetKnownState(&readerStates[ri], knownState & ~SCARD_STATE_IGNORE); + + } + } + const char *newReadersData[MAX_READER_DELTA]; const char **newReaders = &newReadersData[0]; unsigned int newReaderCount = 0; @@ -539,13 +583,31 @@ // try to connect to the card if( ! CKYCardConnection_IsConnected(conn) ) { - status = CKYCardConnection_Connect(conn, readerName); - if( status != CKYSUCCESS ) { - log->log("Unable to connect to token\n"); + int i = 0; + //for cranky readers try again a few more times + while( i++ < 5 && status != CKYSUCCESS ) + { + status = CKYCardConnection_Connect(conn, readerName); + if( status != CKYSUCCESS && + CKYCardConnection_GetLastError(conn) == SCARD_E_PROTO_MISMATCH ) + { + log->log("Unable to connect to token status %d ConnGetGetLastError %x .\n",status,CKYCardConnection_GetLastError(conn)); + + } + else + { + break; + } + OSSleep(100000); + } + + if( status != CKYSUCCESS) + { state = UNKNOWN; return; } } + log->log("time connect: Connect Time %d ms\n", OSTimeNow() - time); if (!slotInfoFound) { readSlotInfo(); @@ -564,15 +626,10 @@ state = CARD_PRESENT; } - if ( CKYBuffer_DataIsEqual(&cardATR, ATR, sizeof (ATR)) || - CKYBuffer_DataIsEqual(&cardATR, ATR1, sizeof(ATR1)) || - CKYBuffer_DataIsEqual(&cardATR, ATR2, sizeof(ATR2)) ) { - - if (Params::hasParam("noAppletOK")) - { - state |= APPLET_SELECTABLE; - mCoolkey = 1; - } + if (Params::hasParam("noAppletOK")) + { + state |= APPLET_SELECTABLE; + mCoolkey = 1; } /* support CAC card. identify the card based on applets, not the ATRS */ @@ -1079,6 +1136,7 @@ } throw; } + if (myNumReaders != numReaders) { if (myReaderStates) { delete [] myReaderStates; @@ -1105,6 +1163,7 @@ } } } + if (found || (flag == CKF_DONT_BLOCK) || shuttingDown) { break; } --- src/coolkey/slot.h.gemalto.64k 2008-01-10 11:17:21.000000000 -0800 +++ src/coolkey/slot.h 2008-01-10 11:20:53.000000000 -0800 @@ -527,6 +527,8 @@ * has called 'C_GetSlotList' with a NULL parameter */ void updateReaderList(); + /* see if a reader name exists in a caller provided reader name list. */ + bool readerNameExistsInList(const char *readerName,CKYReaderNameList *readerNameList ); bool readerExists(const char *readerName, unsigned int *hint = 0); public: SlotList(Log *log);