void edna_emulator::cancel() { INFO_MSG("Canceling emulation"); should_cancel = true; SCardCancel(pcsc_context); }
static UINT32 smartcard_Cancel_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation, Context_Call* call) { LONG status; Long_Return ret; status = ret.ReturnCode = SCardCancel(operation->hContext); smartcard_trace_long_return(smartcard, &ret, "Cancel"); return ret.ReturnCode; }
void smartcard_context_free(SMARTCARD_CONTEXT* pContext) { if (!pContext) return; /* cancel blocking calls like SCardGetStatusChange */ SCardCancel(pContext->hContext); if (MessageQueue_PostQuit(pContext->IrpQueue, 0) && (WaitForSingleObject(pContext->thread, INFINITE) == WAIT_FAILED)) WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", GetLastError()); CloseHandle(pContext->thread); MessageQueue_Free(pContext->IrpQueue); free(pContext); }
void smartcard_context_free(SMARTCARD_CONTEXT* pContext) { if (!pContext) return; /* cancel blocking calls like SCardGetStatusChange */ SCardCancel(pContext->hContext); if (MessageQueue_PostQuit(pContext->IrpQueue, 0)) WaitForSingleObject(pContext->thread, INFINITE); CloseHandle(pContext->thread); MessageQueue_Free(pContext->IrpQueue); free(pContext); }
static uint32 handle_Cancel(IRP *irp) { LONG rv; SCARDCONTEXT hContext; stream_seek(irp->input, 0x1C); stream_read_uint32(irp->input, hContext); rv = SCardCancel(hContext); if (rv != SCARD_S_SUCCESS) DEBUG_SCARD("Failure: %s (0x%08x)\n", pcsc_stringify_error(rv), (unsigned) rv); else DEBUG_SCARD("Success context: 0x%08x %s\n", (unsigned) hContext, pcsc_stringify_error(rv)); sc_output_alignment(irp, 8); return rv; }
static UINT32 handle_Cancel(IRP *irp) { LONG status; SCARDCONTEXT hContext; stream_seek(irp->input, 0x1C); stream_read_UINT32(irp->input, hContext); status = SCardCancel(hContext); if (status != SCARD_S_SUCCESS) DEBUG_SCARD("Failure: %s (0x%08x)", pcsc_stringify_error(status), (unsigned) status); else DEBUG_SCARD("Success context: 0x%08x %s", (unsigned) hContext, pcsc_stringify_error(status)); smartcard_output_alignment(irp, 8); return status; }
void CReaderMonitor::stop(bool mustWait) { if (m_hMonitorThread) { g_pListener = NULL; InterlockedIncrement(&g_fExit); if (SCARD_S_SUCCESS == SCardIsValidContext(g_hContext)) SCardCancel(g_hContext); if(mustWait) { if (WaitForSingleObject(m_hMonitorThread, POLL_PERIOD * 4) == WAIT_TIMEOUT) TerminateThread(m_hMonitorThread, 0); InterlockedDecrement(&g_fExit); CloseHandle(m_hMonitorThread); } else { TerminateThread(m_hMonitorThread, 0); InterlockedDecrement(&g_fExit); CloseHandle(m_hMonitorThread); } m_hMonitorThread = NULL; } }
static void smartcard_release_all_contexts(SMARTCARD_DEVICE* smartcard) { int index; int keyCount; ULONG_PTR* pKeys; SCARDCONTEXT hContext; SMARTCARD_CONTEXT* pContext; /** * On protocol termination, the following actions are performed: * For each context in rgSCardContextList, SCardCancel is called causing all SCardGetStatusChange calls to be processed. * After that, SCardReleaseContext is called on each context and the context MUST be removed from rgSCardContextList. */ /** * Call SCardCancel on existing contexts, unblocking all outstanding SCardGetStatusChange calls. */ if (ListDictionary_Count(smartcard->rgSCardContextList) > 0) { pKeys = NULL; keyCount = ListDictionary_GetKeys(smartcard->rgSCardContextList, &pKeys); for (index = 0; index < keyCount; index++) { pContext = (SMARTCARD_CONTEXT*) ListDictionary_GetItemValue(smartcard->rgSCardContextList, (void*) pKeys[index]); if (!pContext) continue; hContext = pContext->hContext; if (SCardIsValidContext(hContext) == SCARD_S_SUCCESS) { SCardCancel(hContext); } } free(pKeys); } /** * Call SCardReleaseContext on remaining contexts and remove them from rgSCardContextList. */ if (ListDictionary_Count(smartcard->rgSCardContextList) > 0) { pKeys = NULL; keyCount = ListDictionary_GetKeys(smartcard->rgSCardContextList, &pKeys); for (index = 0; index < keyCount; index++) { pContext = (SMARTCARD_CONTEXT*) ListDictionary_Remove(smartcard->rgSCardContextList, (void*) pKeys[index]); if (!pContext) continue; hContext = pContext->hContext; if (SCardIsValidContext(hContext) == SCARD_S_SUCCESS) { SCardReleaseContext(hContext); if (MessageQueue_PostQuit(pContext->IrpQueue, 0) && (WaitForSingleObject(pContext->thread, INFINITE) == WAIT_FAILED)) WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", GetLastError()); CloseHandle(pContext->thread); MessageQueue_Free(pContext->IrpQueue); free(pContext); } } free(pKeys); } }
/* * Cancel card transaction. */ JNIEXPORT jint JNICALL GEN_FUNCNAME(Context_NativeCancel) (JNIEnv *env, jobject _this) { SCARDCONTEXT ctx = (SCARDCONTEXT) (*env)->GetLongField(env, _this, CtxField); return SCardCancel(ctx); }
static void smartcard_init(DEVICE* device) { int index; int keyCount; ULONG_PTR* pKeys; SCARDCONTEXT hContext; SMARTCARD_CONTEXT* pContext; SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) device; /** * On protocol termination, the following actions are performed: * For each context in rgSCardContextList, SCardCancel is called causing all outstanding messages to be processed. * After there are no more outstanding messages, SCardReleaseContext is called on each context and the context MUST * be removed from rgSCardContextList. */ /** * Call SCardCancel on existing contexts, unblocking all outstanding IRPs. */ if (ListDictionary_Count(smartcard->rgSCardContextList) > 0) { pKeys = NULL; keyCount = ListDictionary_GetKeys(smartcard->rgSCardContextList, &pKeys); for (index = 0; index < keyCount; index++) { pContext = (SMARTCARD_CONTEXT*) ListDictionary_GetItemValue(smartcard->rgSCardContextList, (void*) pKeys[index]); if (!pContext) continue; hContext = pContext->hContext; if (SCardIsValidContext(hContext)) { SCardCancel(hContext); } } free(pKeys); } /** * Call SCardReleaseContext on remaining contexts and remove them from rgSCardContextList. */ if (ListDictionary_Count(smartcard->rgSCardContextList) > 0) { pKeys = NULL; keyCount = ListDictionary_GetKeys(smartcard->rgSCardContextList, &pKeys); for (index = 0; index < keyCount; index++) { pContext = (SMARTCARD_CONTEXT*) ListDictionary_Remove(smartcard->rgSCardContextList, (void*) pKeys[index]); if (!pContext) continue; hContext = pContext->hContext; if (SCardIsValidContext(hContext)) { SCardReleaseContext(hContext); } } free(pKeys); } }