/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT smartcard_free(DEVICE* device) { UINT error; SMARTCARD_DEVICE* smartcard = CAST_FROM_DEVICE(device); if (!smartcard) return ERROR_INVALID_PARAMETER; /** * Calling smartcard_release_all_contexts to unblock all operations waiting for transactions * to unlock. */ smartcard_release_all_contexts(smartcard); /* Stopping all threads and cancelling all IRPs */ if (smartcard->IrpQueue) { if (MessageQueue_PostQuit(smartcard->IrpQueue, 0) && (WaitForSingleObject(smartcard->thread, INFINITE) == WAIT_FAILED)) { error = GetLastError(); WLog_ERR(TAG, "WaitForSingleObject failed with error %"PRIu32"!", error); return error; } } if (sSmartcard == smartcard) sSmartcard = NULL; return smartcard_free_(smartcard); }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT smartcard_init(DEVICE* device) { SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) device; smartcard_release_all_contexts(smartcard); return CHANNEL_RC_OK; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT smartcard_init(DEVICE* device) { SMARTCARD_DEVICE* smartcard = CAST_FROM_DEVICE(device); if (!smartcard) return ERROR_INVALID_PARAMETER; smartcard_release_all_contexts(smartcard); return CHANNEL_RC_OK; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT smartcard_free(DEVICE* device) { UINT error; SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) device; /** * Calling smartcard_release_all_contexts to unblock all operations waiting for transactions * to unlock. */ smartcard_release_all_contexts(smartcard); /* Stopping all threads and cancelling all IRPs */ if (smartcard->IrpQueue) { if (MessageQueue_PostQuit(smartcard->IrpQueue, 0) && (WaitForSingleObject(smartcard->thread, INFINITE) == WAIT_FAILED)) { error = GetLastError(); WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error); return error; } MessageQueue_Free(smartcard->IrpQueue); smartcard->IrpQueue = NULL; CloseHandle(smartcard->thread); smartcard->thread = NULL; } if (smartcard->device.data) { Stream_Free(smartcard->device.data, TRUE); smartcard->device.data = NULL; } ListDictionary_Free(smartcard->rgSCardContextList); ListDictionary_Free(smartcard->rgOutstandingMessages); Queue_Free(smartcard->CompletedIrpQueue); if (smartcard->StartedEvent) { SCardReleaseStartedEvent(); smartcard->StartedEvent = NULL; } free(device); return CHANNEL_RC_OK; }