2012-08-15 01:09:01 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2012-08-15 01:09:01 +04:00
|
|
|
* Smartcard Device Service Virtual Channel
|
|
|
|
*
|
|
|
|
* Copyright 2011 O.S. Systems Software Ltda.
|
|
|
|
* Copyright 2011 Eduardo Fiss Beloni <beloni@ossystems.com.br>
|
|
|
|
* Copyright 2011 Anthony Tong <atong@trustedcs.com>
|
2015-07-03 14:09:03 +03:00
|
|
|
* Copyright 2015 Thincast Technologies GmbH
|
|
|
|
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
2012-08-15 01:09:01 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2011-10-15 19:30:10 +04:00
|
|
|
#include "config.h"
|
2012-08-15 01:09:01 +04:00
|
|
|
#endif
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2012-11-21 20:56:40 +04:00
|
|
|
#include <winpr/crt.h>
|
2014-04-03 23:27:55 +04:00
|
|
|
#include <winpr/smartcard.h>
|
2014-05-03 21:49:50 +04:00
|
|
|
#include <winpr/environment.h>
|
2012-11-21 20:56:40 +04:00
|
|
|
|
2012-10-09 05:00:07 +04:00
|
|
|
#include <freerdp/channels/rdpdr.h>
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2012-11-21 20:56:40 +04:00
|
|
|
#include "smartcard_main.h"
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2014-05-12 19:28:20 +04:00
|
|
|
void* smartcard_context_thread(SMARTCARD_CONTEXT* pContext)
|
|
|
|
{
|
|
|
|
DWORD nCount;
|
2015-09-01 13:27:54 +03:00
|
|
|
LONG status = 0;
|
|
|
|
DWORD waitStatus;
|
2014-05-12 19:28:20 +04:00
|
|
|
HANDLE hEvents[2];
|
|
|
|
wMessage message;
|
|
|
|
SMARTCARD_DEVICE* smartcard;
|
2014-05-13 01:05:20 +04:00
|
|
|
SMARTCARD_OPERATION* operation;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2014-05-12 19:28:20 +04:00
|
|
|
|
|
|
|
smartcard = pContext->smartcard;
|
|
|
|
|
|
|
|
nCount = 0;
|
|
|
|
hEvents[nCount++] = MessageQueue_Event(pContext->IrpQueue);
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2015-09-01 13:27:54 +03:00
|
|
|
waitStatus = WaitForMultipleObjects(nCount, hEvents, FALSE, INFINITE);
|
2015-07-30 16:49:21 +03:00
|
|
|
|
2015-09-01 13:27:54 +03:00
|
|
|
if (waitStatus == WAIT_FAILED)
|
|
|
|
{
|
|
|
|
error = GetLastError();
|
|
|
|
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
|
|
|
|
break;
|
|
|
|
}
|
2015-07-30 16:49:21 +03:00
|
|
|
|
2015-09-01 13:27:54 +03:00
|
|
|
waitStatus = WaitForSingleObject(MessageQueue_Event(pContext->IrpQueue), 0);
|
2014-05-12 19:28:20 +04:00
|
|
|
|
2015-09-01 13:27:54 +03:00
|
|
|
if (waitStatus == WAIT_FAILED)
|
|
|
|
{
|
|
|
|
error = GetLastError();
|
|
|
|
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
|
|
|
|
break;
|
|
|
|
}
|
2015-07-30 16:49:21 +03:00
|
|
|
|
|
|
|
if (waitStatus == WAIT_OBJECT_0)
|
2014-05-12 19:28:20 +04:00
|
|
|
{
|
|
|
|
if (!MessageQueue_Peek(pContext->IrpQueue, &message, TRUE))
|
2015-07-15 10:50:35 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "MessageQueue_Peek failed!");
|
|
|
|
status = ERROR_INTERNAL_ERROR;
|
2014-05-12 19:28:20 +04:00
|
|
|
break;
|
2015-07-15 10:50:35 +03:00
|
|
|
}
|
|
|
|
|
2014-05-12 19:28:20 +04:00
|
|
|
|
|
|
|
if (message.id == WMQ_QUIT)
|
|
|
|
break;
|
|
|
|
|
2014-05-13 01:05:20 +04:00
|
|
|
operation = (SMARTCARD_OPERATION*) message.wParam;
|
2014-05-12 19:28:20 +04:00
|
|
|
|
2014-05-13 01:05:20 +04:00
|
|
|
if (operation)
|
2014-05-12 19:28:20 +04:00
|
|
|
{
|
2015-07-03 14:09:03 +03:00
|
|
|
if ((status = smartcard_irp_device_control_call(smartcard, operation)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "smartcard_irp_device_control_call failed with error %lu", status);
|
|
|
|
break;
|
|
|
|
}
|
2014-05-13 01:05:20 +04:00
|
|
|
|
2015-07-15 10:50:35 +03:00
|
|
|
if (!Queue_Enqueue(smartcard->CompletedIrpQueue, (void*) operation->irp))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Queue_Enqueue failed!");
|
|
|
|
status = ERROR_INTERNAL_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
2014-05-13 01:05:20 +04:00
|
|
|
|
|
|
|
free(operation);
|
2014-05-12 19:28:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-15 10:50:35 +03:00
|
|
|
if (status && smartcard->rdpcontext)
|
|
|
|
setChannelError(smartcard->rdpcontext, error, "smartcard_context_thread reported an error");
|
|
|
|
|
|
|
|
ExitThread((DWORD)status);
|
2014-05-12 19:28:20 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
SMARTCARD_CONTEXT* smartcard_context_new(SMARTCARD_DEVICE* smartcard, SCARDCONTEXT hContext)
|
|
|
|
{
|
|
|
|
SMARTCARD_CONTEXT* pContext;
|
|
|
|
|
|
|
|
pContext = (SMARTCARD_CONTEXT*) calloc(1, sizeof(SMARTCARD_CONTEXT));
|
|
|
|
if (!pContext)
|
2015-07-15 10:50:35 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
2014-05-12 19:28:20 +04:00
|
|
|
return pContext;
|
2015-07-15 10:50:35 +03:00
|
|
|
}
|
2014-05-12 19:28:20 +04:00
|
|
|
|
2014-05-13 01:05:20 +04:00
|
|
|
pContext->smartcard = smartcard;
|
2014-05-12 19:28:20 +04:00
|
|
|
pContext->hContext = hContext;
|
|
|
|
|
|
|
|
pContext->IrpQueue = MessageQueue_New(NULL);
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!pContext->IrpQueue)
|
2015-07-15 10:50:35 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "MessageQueue_New failed!");
|
2015-05-18 12:28:00 +03:00
|
|
|
goto error_irpqueue;
|
2015-07-15 10:50:35 +03:00
|
|
|
}
|
2014-05-12 19:28:20 +04:00
|
|
|
|
|
|
|
pContext->thread = CreateThread(NULL, 0,
|
|
|
|
(LPTHREAD_START_ROUTINE) smartcard_context_thread,
|
|
|
|
pContext, 0, NULL);
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!pContext->thread)
|
2015-07-15 10:50:35 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "CreateThread failed!");
|
2015-05-18 12:28:00 +03:00
|
|
|
goto error_thread;
|
2015-07-15 10:50:35 +03:00
|
|
|
}
|
|
|
|
|
2014-05-12 19:28:20 +04:00
|
|
|
return pContext;
|
2015-05-18 12:28:00 +03:00
|
|
|
|
|
|
|
error_thread:
|
|
|
|
MessageQueue_Free(pContext->IrpQueue);
|
|
|
|
error_irpqueue:
|
|
|
|
free(pContext);
|
|
|
|
return NULL;
|
2014-05-12 19:28:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void smartcard_context_free(SMARTCARD_CONTEXT* pContext)
|
|
|
|
{
|
|
|
|
if (!pContext)
|
|
|
|
return;
|
|
|
|
|
2014-12-28 22:56:13 +03:00
|
|
|
/* cancel blocking calls like SCardGetStatusChange */
|
|
|
|
SCardCancel(pContext->hContext);
|
2015-07-30 17:29:12 +03:00
|
|
|
if (MessageQueue_PostQuit(pContext->IrpQueue, 0) && (WaitForSingleObject(pContext->thread, INFINITE) == WAIT_FAILED))
|
|
|
|
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", GetLastError());
|
2014-12-28 22:56:13 +03:00
|
|
|
|
2014-05-12 19:28:20 +04:00
|
|
|
CloseHandle(pContext->thread);
|
|
|
|
|
|
|
|
MessageQueue_Free(pContext->IrpQueue);
|
|
|
|
|
|
|
|
free(pContext);
|
|
|
|
}
|
|
|
|
|
2013-08-13 18:29:19 +04:00
|
|
|
|
2015-07-17 16:37:44 +03:00
|
|
|
static void smartcard_release_all_contexts(SMARTCARD_DEVICE* smartcard) {
|
2014-04-06 01:15:17 +04:00
|
|
|
int index;
|
|
|
|
int keyCount;
|
|
|
|
ULONG_PTR* pKeys;
|
2014-05-07 01:42:10 +04:00
|
|
|
SCARDCONTEXT hContext;
|
2014-05-12 19:28:20 +04:00
|
|
|
SMARTCARD_CONTEXT* pContext;
|
2014-04-06 00:57:31 +04:00
|
|
|
|
2014-05-07 01:42:10 +04:00
|
|
|
/**
|
|
|
|
* On protocol termination, the following actions are performed:
|
2015-07-17 16:37:44 +03:00
|
|
|
* 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.
|
2014-05-07 01:42:10 +04:00
|
|
|
*/
|
|
|
|
|
2014-05-08 01:41:53 +04:00
|
|
|
/**
|
2015-07-17 16:37:44 +03:00
|
|
|
* Call SCardCancel on existing contexts, unblocking all outstanding SCardGetStatusChange calls.
|
2014-05-08 01:41:53 +04:00
|
|
|
*/
|
|
|
|
|
2014-05-07 01:42:10 +04:00
|
|
|
if (ListDictionary_Count(smartcard->rgSCardContextList) > 0)
|
|
|
|
{
|
|
|
|
pKeys = NULL;
|
|
|
|
keyCount = ListDictionary_GetKeys(smartcard->rgSCardContextList, &pKeys);
|
|
|
|
|
|
|
|
for (index = 0; index < keyCount; index++)
|
|
|
|
{
|
2014-05-12 19:28:20 +04:00
|
|
|
pContext = (SMARTCARD_CONTEXT*) ListDictionary_GetItemValue(smartcard->rgSCardContextList, (void*) pKeys[index]);
|
|
|
|
|
|
|
|
if (!pContext)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
hContext = pContext->hContext;
|
2014-05-07 01:42:10 +04:00
|
|
|
|
2015-07-17 18:13:02 +03:00
|
|
|
if (SCardIsValidContext(hContext) == SCARD_S_SUCCESS)
|
2014-05-08 01:41:53 +04:00
|
|
|
{
|
|
|
|
SCardCancel(hContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(pKeys);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-08 23:24:33 +04:00
|
|
|
* Call SCardReleaseContext on remaining contexts and remove them from rgSCardContextList.
|
2014-05-08 01:41:53 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (ListDictionary_Count(smartcard->rgSCardContextList) > 0)
|
|
|
|
{
|
|
|
|
pKeys = NULL;
|
|
|
|
keyCount = ListDictionary_GetKeys(smartcard->rgSCardContextList, &pKeys);
|
|
|
|
|
|
|
|
for (index = 0; index < keyCount; index++)
|
|
|
|
{
|
2014-05-12 19:28:20 +04:00
|
|
|
pContext = (SMARTCARD_CONTEXT*) ListDictionary_Remove(smartcard->rgSCardContextList, (void*) pKeys[index]);
|
|
|
|
|
|
|
|
if (!pContext)
|
|
|
|
continue;
|
2014-05-12 18:17:49 +04:00
|
|
|
|
2014-05-12 19:28:20 +04:00
|
|
|
hContext = pContext->hContext;
|
2014-05-08 01:41:53 +04:00
|
|
|
|
2015-07-17 18:13:02 +03:00
|
|
|
if (SCardIsValidContext(hContext) == SCARD_S_SUCCESS)
|
2014-05-08 01:41:53 +04:00
|
|
|
{
|
|
|
|
SCardReleaseContext(hContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(pKeys);
|
|
|
|
}
|
2015-07-17 16:37:44 +03:00
|
|
|
}
|
|
|
|
|
2015-07-30 17:29:12 +03:00
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT smartcard_free(DEVICE* device)
|
2015-07-17 16:37:44 +03:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2015-07-17 16:37:44 +03:00
|
|
|
SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) device;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calling smartcard_release_all_contexts to unblock all operations waiting for transactions
|
|
|
|
* to unlock.
|
|
|
|
*/
|
2015-07-30 17:29:12 +03:00
|
|
|
|
2015-07-17 16:37:44 +03:00
|
|
|
smartcard_release_all_contexts(smartcard);
|
|
|
|
|
|
|
|
/* Stopping all threads and cancelling all IRPs */
|
|
|
|
|
|
|
|
if (smartcard->IrpQueue)
|
|
|
|
{
|
2015-07-30 17:29:12 +03:00
|
|
|
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;
|
|
|
|
}
|
2015-07-17 16:37:44 +03:00
|
|
|
|
|
|
|
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);
|
2015-07-30 17:29:12 +03:00
|
|
|
|
|
|
|
return CHANNEL_RC_OK;
|
2015-07-17 16:37:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialization occurs when the protocol server sends a device announce message.
|
|
|
|
* At that time, we need to cancel all outstanding IRPs.
|
|
|
|
*/
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT smartcard_init(DEVICE* device)
|
2015-07-17 16:37:44 +03:00
|
|
|
{
|
|
|
|
SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) device;
|
|
|
|
|
|
|
|
smartcard_release_all_contexts(smartcard);
|
|
|
|
|
2015-06-12 13:26:15 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-04-06 00:57:31 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT smartcard_complete_irp(SMARTCARD_DEVICE* smartcard, IRP* irp)
|
2014-04-06 00:57:31 +04:00
|
|
|
{
|
|
|
|
void* key;
|
|
|
|
|
|
|
|
key = (void*) (size_t) irp->CompletionId;
|
2014-05-07 01:42:10 +04:00
|
|
|
ListDictionary_Remove(smartcard->rgOutstandingMessages, key);
|
2014-04-06 00:57:31 +04:00
|
|
|
|
2015-07-03 14:09:03 +03:00
|
|
|
return irp->Complete(irp);
|
2014-04-06 00:57:31 +04:00
|
|
|
}
|
|
|
|
|
2014-04-06 00:06:46 +04:00
|
|
|
/**
|
|
|
|
* Multiple threads and SCardGetStatusChange:
|
|
|
|
* http://musclecard.996296.n3.nabble.com/Multiple-threads-and-SCardGetStatusChange-td4430.html
|
|
|
|
*/
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT smartcard_process_irp(SMARTCARD_DEVICE* smartcard, IRP* irp)
|
2014-04-06 01:51:13 +04:00
|
|
|
{
|
|
|
|
void* key;
|
2015-07-03 14:09:03 +03:00
|
|
|
LONG status;
|
2014-04-06 01:51:13 +04:00
|
|
|
BOOL asyncIrp = FALSE;
|
2014-05-13 01:05:20 +04:00
|
|
|
SMARTCARD_CONTEXT* pContext = NULL;
|
2014-05-12 23:47:49 +04:00
|
|
|
SMARTCARD_OPERATION* operation = NULL;
|
2014-04-06 01:51:13 +04:00
|
|
|
|
|
|
|
key = (void*) (size_t) irp->CompletionId;
|
2015-07-03 14:09:03 +03:00
|
|
|
if (!ListDictionary_Add(smartcard->rgOutstandingMessages, key, irp))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "ListDictionary_Add failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
2014-04-06 01:51:13 +04:00
|
|
|
|
|
|
|
if (irp->MajorFunction == IRP_MJ_DEVICE_CONTROL)
|
|
|
|
{
|
2014-05-12 23:47:49 +04:00
|
|
|
operation = (SMARTCARD_OPERATION*) calloc(1, sizeof(SMARTCARD_OPERATION));
|
|
|
|
|
|
|
|
if (!operation)
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2014-05-12 23:47:49 +04:00
|
|
|
|
|
|
|
operation->irp = irp;
|
|
|
|
|
|
|
|
status = smartcard_irp_device_control_decode(smartcard, operation);
|
|
|
|
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
{
|
2015-07-03 14:09:03 +03:00
|
|
|
irp->IoStatus = (UINT32)STATUS_UNSUCCESSFUL;
|
2014-05-12 23:47:49 +04:00
|
|
|
|
2015-07-03 14:09:03 +03:00
|
|
|
if (!Queue_Enqueue(smartcard->CompletedIrpQueue, (void*) irp))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Queue_Enqueue failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
2014-04-06 01:51:13 +04:00
|
|
|
|
2015-07-03 14:09:03 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-05-12 23:47:49 +04:00
|
|
|
}
|
2014-04-06 01:51:13 +04:00
|
|
|
|
2014-05-08 05:16:05 +04:00
|
|
|
asyncIrp = TRUE;
|
2014-05-03 21:49:50 +04:00
|
|
|
|
2014-05-08 05:16:05 +04:00
|
|
|
/**
|
|
|
|
* The following matches mstsc's behavior of processing
|
|
|
|
* only certain requests asynchronously while processing
|
|
|
|
* those expected to return fast synchronously.
|
|
|
|
*/
|
|
|
|
|
2014-05-12 23:47:49 +04:00
|
|
|
switch (operation->ioControlCode)
|
2014-05-08 05:16:05 +04:00
|
|
|
{
|
|
|
|
case SCARD_IOCTL_ESTABLISHCONTEXT:
|
|
|
|
case SCARD_IOCTL_RELEASECONTEXT:
|
|
|
|
case SCARD_IOCTL_ISVALIDCONTEXT:
|
|
|
|
case SCARD_IOCTL_LISTREADERGROUPSA:
|
|
|
|
case SCARD_IOCTL_LISTREADERGROUPSW:
|
|
|
|
case SCARD_IOCTL_LISTREADERSA:
|
|
|
|
case SCARD_IOCTL_LISTREADERSW:
|
|
|
|
case SCARD_IOCTL_INTRODUCEREADERGROUPA:
|
|
|
|
case SCARD_IOCTL_INTRODUCEREADERGROUPW:
|
|
|
|
case SCARD_IOCTL_FORGETREADERGROUPA:
|
|
|
|
case SCARD_IOCTL_FORGETREADERGROUPW:
|
|
|
|
case SCARD_IOCTL_INTRODUCEREADERA:
|
|
|
|
case SCARD_IOCTL_INTRODUCEREADERW:
|
|
|
|
case SCARD_IOCTL_FORGETREADERA:
|
|
|
|
case SCARD_IOCTL_FORGETREADERW:
|
|
|
|
case SCARD_IOCTL_ADDREADERTOGROUPA:
|
|
|
|
case SCARD_IOCTL_ADDREADERTOGROUPW:
|
|
|
|
case SCARD_IOCTL_REMOVEREADERFROMGROUPA:
|
|
|
|
case SCARD_IOCTL_REMOVEREADERFROMGROUPW:
|
|
|
|
case SCARD_IOCTL_LOCATECARDSA:
|
|
|
|
case SCARD_IOCTL_LOCATECARDSW:
|
|
|
|
case SCARD_IOCTL_LOCATECARDSBYATRA:
|
|
|
|
case SCARD_IOCTL_LOCATECARDSBYATRW:
|
|
|
|
case SCARD_IOCTL_CANCEL:
|
|
|
|
case SCARD_IOCTL_READCACHEA:
|
|
|
|
case SCARD_IOCTL_READCACHEW:
|
|
|
|
case SCARD_IOCTL_WRITECACHEA:
|
|
|
|
case SCARD_IOCTL_WRITECACHEW:
|
|
|
|
case SCARD_IOCTL_GETREADERICON:
|
|
|
|
case SCARD_IOCTL_GETDEVICETYPEID:
|
|
|
|
asyncIrp = FALSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCARD_IOCTL_GETSTATUSCHANGEA:
|
|
|
|
case SCARD_IOCTL_GETSTATUSCHANGEW:
|
|
|
|
asyncIrp = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCARD_IOCTL_CONNECTA:
|
|
|
|
case SCARD_IOCTL_CONNECTW:
|
|
|
|
case SCARD_IOCTL_RECONNECT:
|
|
|
|
case SCARD_IOCTL_DISCONNECT:
|
|
|
|
case SCARD_IOCTL_BEGINTRANSACTION:
|
|
|
|
case SCARD_IOCTL_ENDTRANSACTION:
|
|
|
|
case SCARD_IOCTL_STATE:
|
|
|
|
case SCARD_IOCTL_STATUSA:
|
|
|
|
case SCARD_IOCTL_STATUSW:
|
|
|
|
case SCARD_IOCTL_TRANSMIT:
|
|
|
|
case SCARD_IOCTL_CONTROL:
|
|
|
|
case SCARD_IOCTL_GETATTRIB:
|
|
|
|
case SCARD_IOCTL_SETATTRIB:
|
|
|
|
case SCARD_IOCTL_GETTRANSMITCOUNT:
|
|
|
|
asyncIrp = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCARD_IOCTL_ACCESSSTARTEDEVENT:
|
|
|
|
case SCARD_IOCTL_RELEASESTARTEDEVENT:
|
|
|
|
asyncIrp = FALSE;
|
|
|
|
break;
|
2014-04-06 01:51:13 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 01:05:20 +04:00
|
|
|
pContext = ListDictionary_GetItemValue(smartcard->rgSCardContextList, (void*) operation->hContext);
|
|
|
|
|
|
|
|
if (!pContext)
|
|
|
|
asyncIrp = FALSE;
|
|
|
|
|
2014-05-12 23:32:02 +04:00
|
|
|
if (!asyncIrp)
|
|
|
|
{
|
2015-07-03 14:09:03 +03:00
|
|
|
if ((status = smartcard_irp_device_control_call(smartcard, operation)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "smartcard_irp_device_control_call failed with error %lu!", status);
|
|
|
|
return (UINT32)status;
|
|
|
|
}
|
|
|
|
if (!Queue_Enqueue(smartcard->CompletedIrpQueue, (void*) irp))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Queue_Enqueue failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
2014-05-12 23:47:49 +04:00
|
|
|
free(operation);
|
2014-04-06 01:51:13 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-13 01:05:20 +04:00
|
|
|
if (pContext)
|
|
|
|
{
|
2015-07-03 14:09:03 +03:00
|
|
|
if (!MessageQueue_Post(pContext->IrpQueue, NULL, 0, (void*) operation, NULL))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "MessageQueue_Post failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
2014-05-13 01:05:20 +04:00
|
|
|
}
|
2014-04-06 01:51:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-20 19:16:37 +03:00
|
|
|
WLog_ERR(TAG, "Unexpected SmartCard IRP: MajorFunction 0x%08X MinorFunction: 0x%08X",
|
2014-09-12 18:19:32 +04:00
|
|
|
irp->MajorFunction, irp->MinorFunction);
|
2015-07-03 14:09:03 +03:00
|
|
|
irp->IoStatus = (UINT32)STATUS_NOT_SUPPORTED;
|
2014-05-08 01:41:53 +04:00
|
|
|
|
2015-07-03 14:09:03 +03:00
|
|
|
if (!Queue_Enqueue(smartcard->CompletedIrpQueue, (void*) irp))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Queue_Enqueue failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
2014-04-06 01:51:13 +04:00
|
|
|
}
|
2015-07-03 14:09:03 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-04-06 01:51:13 +04:00
|
|
|
}
|
|
|
|
|
2013-11-04 05:46:40 +04:00
|
|
|
static void* smartcard_thread_func(void* arg)
|
2011-10-15 19:30:10 +04:00
|
|
|
{
|
2012-09-23 21:54:14 +04:00
|
|
|
IRP* irp;
|
2014-05-08 01:41:53 +04:00
|
|
|
DWORD nCount;
|
|
|
|
DWORD status;
|
|
|
|
HANDLE hEvents[2];
|
2013-11-04 05:46:40 +04:00
|
|
|
wMessage message;
|
|
|
|
SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) arg;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2014-05-08 01:41:53 +04:00
|
|
|
nCount = 0;
|
|
|
|
hEvents[nCount++] = MessageQueue_Event(smartcard->IrpQueue);
|
|
|
|
hEvents[nCount++] = Queue_Event(smartcard->CompletedIrpQueue);
|
|
|
|
|
2012-11-21 21:53:54 +04:00
|
|
|
while (1)
|
2011-10-15 19:30:10 +04:00
|
|
|
{
|
2014-05-08 01:41:53 +04:00
|
|
|
status = WaitForMultipleObjects(nCount, hEvents, FALSE, INFINITE);
|
2012-11-21 21:53:54 +04:00
|
|
|
|
2015-09-01 13:27:54 +03:00
|
|
|
if (status == WAIT_FAILED)
|
|
|
|
{
|
|
|
|
error = GetLastError();
|
|
|
|
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
|
|
|
|
break;
|
|
|
|
}
|
2015-07-30 16:49:21 +03:00
|
|
|
|
2015-09-01 13:27:54 +03:00
|
|
|
status = WaitForSingleObject(MessageQueue_Event(smartcard->IrpQueue), 0);
|
2015-07-30 16:49:21 +03:00
|
|
|
|
2015-09-01 13:27:54 +03:00
|
|
|
if (status == WAIT_FAILED)
|
|
|
|
{
|
|
|
|
error = GetLastError();
|
|
|
|
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
|
|
|
|
break;
|
|
|
|
}
|
2015-07-30 16:49:21 +03:00
|
|
|
|
2015-09-01 13:27:54 +03:00
|
|
|
if (status == WAIT_OBJECT_0)
|
2014-05-08 01:41:53 +04:00
|
|
|
{
|
|
|
|
if (!MessageQueue_Peek(smartcard->IrpQueue, &message, TRUE))
|
2015-07-15 10:50:35 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "MessageQueue_Peek failed!");
|
|
|
|
error = ERROR_INTERNAL_ERROR;
|
2014-05-08 01:41:53 +04:00
|
|
|
break;
|
2015-07-15 10:50:35 +03:00
|
|
|
}
|
|
|
|
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2014-05-08 01:41:53 +04:00
|
|
|
if (message.id == WMQ_QUIT)
|
2014-05-08 23:24:33 +04:00
|
|
|
{
|
2015-07-30 16:49:21 +03:00
|
|
|
while (1)
|
2014-05-08 23:24:33 +04:00
|
|
|
{
|
2015-09-01 13:27:54 +03:00
|
|
|
status = WaitForSingleObject(Queue_Event(smartcard->CompletedIrpQueue), 0);
|
2015-07-30 16:49:21 +03:00
|
|
|
|
2015-09-01 13:27:54 +03:00
|
|
|
if (status == WAIT_FAILED)
|
|
|
|
{
|
|
|
|
error = GetLastError();
|
|
|
|
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
|
|
|
|
goto out;
|
|
|
|
}
|
2015-07-30 16:49:21 +03:00
|
|
|
|
2015-09-01 13:27:54 +03:00
|
|
|
if (status == WAIT_TIMEOUT)
|
|
|
|
break;
|
2015-07-30 16:49:21 +03:00
|
|
|
|
2015-09-01 13:27:54 +03:00
|
|
|
irp = (IRP*) Queue_Dequeue(smartcard->CompletedIrpQueue);
|
2014-05-08 23:24:33 +04:00
|
|
|
|
|
|
|
if (irp)
|
|
|
|
{
|
|
|
|
if (irp->thread)
|
|
|
|
{
|
2015-07-30 16:49:21 +03:00
|
|
|
status = WaitForSingleObject(irp->thread, INFINITE);
|
|
|
|
|
2015-09-01 13:27:54 +03:00
|
|
|
if (status == WAIT_FAILED)
|
|
|
|
{
|
|
|
|
error = GetLastError();
|
|
|
|
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
|
|
|
|
goto out;
|
|
|
|
}
|
2015-07-30 16:49:21 +03:00
|
|
|
|
2014-05-08 23:24:33 +04:00
|
|
|
CloseHandle(irp->thread);
|
2014-12-28 22:56:13 +03:00
|
|
|
irp->thread = NULL;
|
2014-05-08 23:24:33 +04:00
|
|
|
}
|
|
|
|
|
2015-07-03 14:09:03 +03:00
|
|
|
if ((error = smartcard_complete_irp(smartcard, irp)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "smartcard_complete_irp failed with error %lu!", error);
|
|
|
|
goto out;
|
|
|
|
}
|
2014-05-08 23:24:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-08 01:41:53 +04:00
|
|
|
break;
|
2014-05-08 23:24:33 +04:00
|
|
|
}
|
2012-11-21 20:56:40 +04:00
|
|
|
|
2014-05-08 01:41:53 +04:00
|
|
|
irp = (IRP*) message.wParam;
|
2012-08-02 02:05:45 +04:00
|
|
|
|
2014-05-08 01:41:53 +04:00
|
|
|
if (irp)
|
|
|
|
{
|
2015-07-03 14:09:03 +03:00
|
|
|
if ((error = smartcard_process_irp(smartcard, irp)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "smartcard_process_irp failed with error %lu!", error);
|
|
|
|
goto out;
|
|
|
|
}
|
2014-05-08 01:41:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-01 13:27:54 +03:00
|
|
|
status = WaitForSingleObject(Queue_Event(smartcard->CompletedIrpQueue), 0);
|
2015-07-30 16:49:21 +03:00
|
|
|
|
2015-09-01 13:27:54 +03:00
|
|
|
if (status == WAIT_FAILED)
|
|
|
|
{
|
|
|
|
error = GetLastError();
|
|
|
|
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
|
|
|
|
break;
|
|
|
|
}
|
2015-07-30 16:49:21 +03:00
|
|
|
|
2015-09-01 13:27:54 +03:00
|
|
|
if (status == WAIT_OBJECT_0)
|
|
|
|
{
|
2015-07-30 16:49:21 +03:00
|
|
|
|
2015-09-01 13:27:54 +03:00
|
|
|
irp = (IRP*) Queue_Dequeue(smartcard->CompletedIrpQueue);
|
2014-05-08 01:41:53 +04:00
|
|
|
|
|
|
|
if (irp)
|
|
|
|
{
|
|
|
|
if (irp->thread)
|
|
|
|
{
|
2015-07-30 16:49:21 +03:00
|
|
|
status = WaitForSingleObject(irp->thread, INFINITE);
|
|
|
|
|
2015-09-01 13:27:54 +03:00
|
|
|
if (status == WAIT_FAILED)
|
|
|
|
{
|
|
|
|
error = GetLastError();
|
|
|
|
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
|
|
|
|
break;
|
|
|
|
}
|
2015-07-30 16:49:21 +03:00
|
|
|
|
2014-05-08 01:41:53 +04:00
|
|
|
CloseHandle(irp->thread);
|
2014-12-28 22:56:13 +03:00
|
|
|
irp->thread = NULL;
|
2014-05-08 01:41:53 +04:00
|
|
|
}
|
|
|
|
|
2015-07-03 14:09:03 +03:00
|
|
|
if ((error = smartcard_complete_irp(smartcard, irp)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "smartcard_complete_irp failed with error %lu!", error);
|
|
|
|
goto out;
|
|
|
|
}
|
2014-05-08 01:41:53 +04:00
|
|
|
}
|
|
|
|
}
|
2012-08-02 02:05:45 +04:00
|
|
|
}
|
2015-07-03 14:09:03 +03:00
|
|
|
out:
|
2015-07-15 10:50:35 +03:00
|
|
|
if (error && smartcard->rdpcontext)
|
|
|
|
setChannelError(smartcard->rdpcontext, error, "smartcard_thread_func reported an error");
|
|
|
|
|
2015-07-03 14:09:03 +03:00
|
|
|
ExitThread((DWORD)error);
|
2013-11-04 05:46:40 +04:00
|
|
|
return NULL;
|
2012-08-02 02:05:45 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT smartcard_irp_request(DEVICE* device, IRP* irp)
|
2011-10-15 19:30:10 +04:00
|
|
|
{
|
2012-11-21 21:53:54 +04:00
|
|
|
SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) device;
|
2015-07-15 10:50:35 +03:00
|
|
|
if (!MessageQueue_Post(smartcard->IrpQueue, NULL, 0, (void*) irp, NULL))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "MessageQueue_Post failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
2015-06-12 13:26:15 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2011-10-15 19:30:10 +04:00
|
|
|
}
|
|
|
|
|
2014-04-06 04:05:51 +04:00
|
|
|
/* smartcard is always built-in */
|
2012-10-14 10:38:58 +04:00
|
|
|
#define DeviceServiceEntry smartcard_DeviceServiceEntry
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
|
2011-10-15 19:30:10 +04:00
|
|
|
{
|
|
|
|
char* name;
|
|
|
|
char* path;
|
2015-07-03 14:09:03 +03:00
|
|
|
size_t length;
|
|
|
|
int ck;
|
2012-11-09 04:01:52 +04:00
|
|
|
RDPDR_SMARTCARD* device;
|
2012-11-21 20:56:40 +04:00
|
|
|
SMARTCARD_DEVICE* smartcard;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_NO_MEMORY;
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2012-11-09 04:01:52 +04:00
|
|
|
device = (RDPDR_SMARTCARD*) pEntryPoints->device;
|
2014-04-04 01:29:12 +04:00
|
|
|
|
2012-11-09 04:01:52 +04:00
|
|
|
name = device->Name;
|
|
|
|
path = device->Path;
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2014-03-26 19:05:12 +04:00
|
|
|
smartcard = (SMARTCARD_DEVICE*) calloc(1, sizeof(SMARTCARD_DEVICE));
|
|
|
|
if (!smartcard)
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2013-09-12 16:34:18 +04:00
|
|
|
smartcard->device.type = RDPDR_DTYP_SMARTCARD;
|
|
|
|
smartcard->device.name = "SCARD";
|
|
|
|
smartcard->device.IRPRequest = smartcard_irp_request;
|
2014-04-06 00:57:31 +04:00
|
|
|
smartcard->device.Init = smartcard_init;
|
2013-09-12 16:34:18 +04:00
|
|
|
smartcard->device.Free = smartcard_free;
|
2015-07-15 10:50:35 +03:00
|
|
|
smartcard->rdpcontext = pEntryPoints->rdpcontext;
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2013-09-12 16:34:18 +04:00
|
|
|
length = strlen(smartcard->device.name);
|
|
|
|
smartcard->device.data = Stream_New(NULL, length + 1);
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!smartcard->device.data)
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
2015-05-18 12:28:00 +03:00
|
|
|
goto error_device_data;
|
2015-07-03 14:09:03 +03:00
|
|
|
}
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2013-09-12 16:55:25 +04:00
|
|
|
Stream_Write(smartcard->device.data, "SCARD", 6);
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2013-09-12 16:41:11 +04:00
|
|
|
smartcard->name = NULL;
|
|
|
|
smartcard->path = NULL;
|
2013-10-24 23:12:11 +04:00
|
|
|
|
2013-09-12 16:41:11 +04:00
|
|
|
if (path)
|
|
|
|
{
|
2012-11-21 20:56:40 +04:00
|
|
|
smartcard->path = path;
|
2013-09-12 16:41:11 +04:00
|
|
|
smartcard->name = name;
|
|
|
|
}
|
2013-09-12 16:55:25 +04:00
|
|
|
else if (name)
|
2013-09-12 16:41:11 +04:00
|
|
|
{
|
|
|
|
if (1 == sscanf(name, "%d", &ck))
|
|
|
|
smartcard->path = name;
|
|
|
|
else
|
|
|
|
smartcard->name = name;
|
|
|
|
}
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2014-04-03 23:27:55 +04:00
|
|
|
smartcard->IrpQueue = MessageQueue_New(NULL);
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!smartcard->IrpQueue)
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "MessageQueue_New failed!");
|
2015-05-18 12:28:00 +03:00
|
|
|
goto error_irp_queue;
|
2015-07-03 14:09:03 +03:00
|
|
|
}
|
|
|
|
|
2014-12-28 22:56:13 +03:00
|
|
|
|
|
|
|
smartcard->CompletedIrpQueue = Queue_New(TRUE, -1, -1);
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!smartcard->CompletedIrpQueue)
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Queue_New failed!");
|
2015-05-18 12:28:00 +03:00
|
|
|
goto error_completed_irp_queue;
|
2015-07-03 14:09:03 +03:00
|
|
|
}
|
2014-12-28 22:56:13 +03:00
|
|
|
|
2014-05-07 01:42:10 +04:00
|
|
|
smartcard->rgSCardContextList = ListDictionary_New(TRUE);
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!smartcard->rgSCardContextList)
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "ListDictionary_New failed!");
|
2015-05-18 12:28:00 +03:00
|
|
|
goto error_context_list;
|
2015-07-03 14:09:03 +03:00
|
|
|
}
|
2014-12-28 22:56:13 +03:00
|
|
|
|
|
|
|
ListDictionary_ValueObject(smartcard->rgSCardContextList)->fnObjectFree =
|
|
|
|
(OBJECT_FREE_FN) smartcard_context_free;
|
|
|
|
|
2014-05-07 01:42:10 +04:00
|
|
|
smartcard->rgOutstandingMessages = ListDictionary_New(TRUE);
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!smartcard->rgOutstandingMessages)
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "ListDictionary_New failed!");
|
|
|
|
goto error_outstanding_messages;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) smartcard)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "RegisterDevice failed!");
|
2015-05-18 12:28:00 +03:00
|
|
|
goto error_outstanding_messages;
|
2015-07-03 14:09:03 +03:00
|
|
|
}
|
|
|
|
|
2014-04-06 00:57:31 +04:00
|
|
|
|
2013-09-12 16:34:18 +04:00
|
|
|
smartcard->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) smartcard_thread_func,
|
|
|
|
smartcard, CREATE_SUSPENDED, NULL);
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!smartcard->thread)
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "ListDictionary_New failed!");
|
|
|
|
error = ERROR_INTERNAL_ERROR;
|
2015-05-18 12:28:00 +03:00
|
|
|
goto error_thread;
|
2015-07-03 14:09:03 +03:00
|
|
|
}
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2013-09-12 16:34:18 +04:00
|
|
|
ResumeThread(smartcard->thread);
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2015-07-03 14:09:03 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2015-05-18 12:28:00 +03:00
|
|
|
|
|
|
|
error_thread:
|
|
|
|
ListDictionary_Free(smartcard->rgOutstandingMessages);
|
|
|
|
error_outstanding_messages:
|
|
|
|
ListDictionary_Free(smartcard->rgSCardContextList);
|
|
|
|
error_context_list:
|
|
|
|
Queue_Free(smartcard->CompletedIrpQueue);
|
|
|
|
error_completed_irp_queue:
|
|
|
|
MessageQueue_Free(smartcard->IrpQueue);
|
|
|
|
error_irp_queue:
|
|
|
|
Stream_Free(smartcard->device.data, TRUE);
|
|
|
|
error_device_data:
|
|
|
|
free(smartcard);
|
2015-07-03 14:09:03 +03:00
|
|
|
return error;
|
2011-10-15 19:30:10 +04:00
|
|
|
}
|
2012-11-21 20:56:40 +04:00
|
|
|
|