diff options
author | jmagne <jmagne@fba4d07e-fe0f-4d7f-8147-e0026e666dc0> | 2007-10-16 00:05:31 +0000 |
---|---|---|
committer | jmagne <jmagne@fba4d07e-fe0f-4d7f-8147-e0026e666dc0> | 2007-10-16 00:05:31 +0000 |
commit | d35b5dd1e7e3e7c0f82768a52bf19b09b97e4797 (patch) | |
tree | 0981afaa97b78330a80215286840abdc99f8bc64 /src | |
parent | 3d9c3cde5d5086bb738cadb652644e04610df3ad (diff) |
Address Gemalto USBKey 64K detection issues. Bug #285441, r. rrelyea.
git-svn-id: http://svn.fedorahosted.org/svn/coolkey/trunk@69 fba4d07e-fe0f-4d7f-8147-e0026e666dc0
Diffstat (limited to 'src')
-rw-r--r-- | src/coolkey/slot.cpp | 70 | ||||
-rw-r--r-- | src/coolkey/slot.h | 2 |
2 files changed, 69 insertions, 3 deletions
diff --git a/src/coolkey/slot.cpp b/src/coolkey/slot.cpp index b71b4e9..577df24 100644 --- a/src/coolkey/slot.cpp +++ b/src/coolkey/slot.cpp @@ -205,6 +205,29 @@ SlotList::readerExists(const char *readerName, unsigned int *hint) 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 @@ SlotList::updateReaderList() * 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 @@ Slot::connectToToken() // 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(); @@ -1074,6 +1136,7 @@ SlotList::waitForSlotEvent(CK_FLAGS flag, CK_SLOT_ID_PTR slotp, CK_VOID_PTR res) } throw; } + if (myNumReaders != numReaders) { if (myReaderStates) { delete [] myReaderStates; @@ -1100,6 +1163,7 @@ SlotList::waitForSlotEvent(CK_FLAGS flag, CK_SLOT_ID_PTR slotp, CK_VOID_PTR res) } } } + if (found || (flag == CKF_DONT_BLOCK) || shuttingDown) { break; } diff --git a/src/coolkey/slot.h b/src/coolkey/slot.h index 1e2b12e..9edb083 100644 --- a/src/coolkey/slot.h +++ b/src/coolkey/slot.h @@ -527,6 +527,8 @@ class SlotList { * 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); |