channels/smartcard: implement usage of SCardAccessStartedEvent

This commit is contained in:
Marc-André Moreau 2014-05-10 23:43:25 -04:00
parent 3ef0157b6c
commit d04430cb02
4 changed files with 47 additions and 3 deletions

View File

@ -51,6 +51,12 @@ static void smartcard_free(DEVICE* device)
ListDictionary_Free(smartcard->rgOutstandingMessages); ListDictionary_Free(smartcard->rgOutstandingMessages);
Queue_Free(smartcard->CompletedIrpQueue); Queue_Free(smartcard->CompletedIrpQueue);
if (smartcard->StartedEvent)
{
SCardReleaseStartedEvent();
smartcard->StartedEvent = NULL;
}
free(device); free(device);
} }

View File

@ -91,6 +91,7 @@ struct _SMARTCARD_DEVICE
char* path; char* path;
HANDLE thread; HANDLE thread;
HANDLE StartedEvent;
wMessageQueue* IrpQueue; wMessageQueue* IrpQueue;
wQueue* CompletedIrpQueue; wQueue* CompletedIrpQueue;
wListDictionary* rgSCardContextList; wListDictionary* rgSCardContextList;

View File

@ -969,8 +969,12 @@ static UINT32 smartcard_AccessStartedEvent(SMARTCARD_DEVICE* smartcard, IRP* irp
} }
Stream_Seek(irp->input, 4); /* Unused (4 bytes) */ Stream_Seek(irp->input, 4); /* Unused (4 bytes) */
status = ret.ReturnCode = SCARD_S_SUCCESS; if (!smartcard->StartedEvent)
smartcard->StartedEvent = SCardAccessStartedEvent();
if (!smartcard->StartedEvent)
status = ret.ReturnCode = SCARD_E_NO_SERVICE;
return status; return status;
} }

View File

@ -56,6 +56,9 @@ typedef struct _PCSC_READER PCSC_READER;
static HMODULE g_PCSCModule = NULL; static HMODULE g_PCSCModule = NULL;
static PCSCFunctionTable g_PCSC = { 0 }; static PCSCFunctionTable g_PCSC = { 0 };
static HANDLE g_StartedEvent = NULL;
static int g_StartedEventRefCount = 0;
static BOOL g_SCardAutoAllocate = FALSE; static BOOL g_SCardAutoAllocate = FALSE;
static BOOL g_PnP_Notification = TRUE; static BOOL g_PnP_Notification = TRUE;
@ -1113,12 +1116,42 @@ WINSCARDAPI LONG WINAPI PCSC_SCardFreeMemory(SCARDCONTEXT hContext, LPCVOID pvMe
WINSCARDAPI HANDLE WINAPI PCSC_SCardAccessStartedEvent(void) WINSCARDAPI HANDLE WINAPI PCSC_SCardAccessStartedEvent(void)
{ {
return 0; LONG status = 0;
SCARDCONTEXT hContext = 0;
status = PCSC_SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
if (status != SCARD_S_SUCCESS)
return NULL;
status = PCSC_SCardReleaseContext(hContext);
if (status != SCARD_S_SUCCESS)
return NULL;
if (!g_StartedEvent)
{
g_StartedEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
SetEvent(g_StartedEvent);
}
g_StartedEventRefCount++;
return g_StartedEvent;
} }
WINSCARDAPI void WINAPI PCSC_SCardReleaseStartedEvent(void) WINSCARDAPI void WINAPI PCSC_SCardReleaseStartedEvent(void)
{ {
g_StartedEventRefCount--;
if (g_StartedEventRefCount == 0)
{
if (g_StartedEvent)
{
CloseHandle(g_StartedEvent);
g_StartedEvent = NULL;
}
}
} }
WINSCARDAPI LONG WINAPI PCSC_SCardLocateCardsA(SCARDCONTEXT hContext, WINSCARDAPI LONG WINAPI PCSC_SCardLocateCardsA(SCARDCONTEXT hContext,