2014-04-04 02:47:18 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Smart Card Structure Packing
|
|
|
|
*
|
|
|
|
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2014-04-05 01:37:00 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/print.h>
|
|
|
|
|
2014-04-04 02:47:18 +04:00
|
|
|
#include "smartcard_pack.h"
|
|
|
|
|
2014-04-06 00:06:46 +04:00
|
|
|
UINT32 smartcard_unpack_common_type_header(SMARTCARD_DEVICE* smartcard, wStream* s)
|
|
|
|
{
|
|
|
|
UINT8 version;
|
|
|
|
UINT32 filler;
|
|
|
|
UINT8 endianness;
|
|
|
|
UINT16 commonHeaderLength;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "CommonTypeHeader is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Process CommonTypeHeader */
|
|
|
|
|
|
|
|
Stream_Read_UINT8(s, version); /* Version (1 byte) */
|
|
|
|
Stream_Read_UINT8(s, endianness); /* Endianness (1 byte) */
|
|
|
|
Stream_Read_UINT16(s, commonHeaderLength); /* CommonHeaderLength (2 bytes) */
|
|
|
|
Stream_Read_UINT32(s, filler); /* Filler (4 bytes), should be 0xCCCCCCCC */
|
|
|
|
|
|
|
|
if (version != 1)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Unsupported CommonTypeHeader Version %d", version);
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (endianness != 0x10)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Unsupported CommonTypeHeader Endianness %d", endianness);
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (commonHeaderLength != 8)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Unsupported CommonTypeHeader CommonHeaderLength %d", commonHeaderLength);
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (filler != 0xCCCCCCCC)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Unexpected CommonTypeHeader Filler 0x%08X", filler);
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT32 smartcard_pack_common_type_header(SMARTCARD_DEVICE* smartcard, wStream* s)
|
|
|
|
{
|
|
|
|
Stream_Write_UINT8(s, 1); /* Version (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, 0x10); /* Endianness (1 byte) */
|
|
|
|
Stream_Write_UINT16(s, 8); /* CommonHeaderLength (2 bytes) */
|
|
|
|
Stream_Write_UINT32(s, 0xCCCCCCCC); /* Filler (4 bytes), should be 0xCCCCCCCC */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT32 smartcard_unpack_private_type_header(SMARTCARD_DEVICE* smartcard, wStream* s)
|
|
|
|
{
|
|
|
|
UINT32 filler;
|
|
|
|
UINT32 objectBufferLength;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "PrivateTypeHeader is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, objectBufferLength); /* ObjectBufferLength (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, filler); /* Filler (4 bytes), should be 0x00000000 */
|
|
|
|
|
|
|
|
if (filler != 0x00000000)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Unexpected PrivateTypeHeader Filler 0x%08X", filler);
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (objectBufferLength != Stream_GetRemainingLength(s))
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "PrivateTypeHeader ObjectBufferLength mismatch: Actual: %d, Expected: %d",
|
|
|
|
(int) objectBufferLength, Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT32 smartcard_pack_private_type_header(SMARTCARD_DEVICE* smartcard, wStream* s, UINT32 objectBufferLength)
|
|
|
|
{
|
|
|
|
Stream_Write_UINT32(s, objectBufferLength); /* ObjectBufferLength (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, 0x00000000); /* Filler (4 bytes), should be 0x00000000 */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
UINT32 smartcard_unpack_read_size_align(SMARTCARD_DEVICE* smartcard, wStream* s, UINT32 size, UINT32 alignment)
|
2014-04-07 07:08:40 +04:00
|
|
|
{
|
|
|
|
UINT32 pad;
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
pad = size;
|
|
|
|
size = (size + alignment - 1) & ~(alignment - 1);
|
|
|
|
pad = size - pad;
|
2014-04-07 07:08:40 +04:00
|
|
|
|
2014-04-07 18:59:13 +04:00
|
|
|
if (pad)
|
|
|
|
Stream_Seek(s, pad);
|
2014-04-07 07:08:40 +04:00
|
|
|
|
|
|
|
return pad;
|
|
|
|
}
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
UINT32 smartcard_pack_write_size_align(SMARTCARD_DEVICE* smartcard, wStream* s, UINT32 size, UINT32 alignment)
|
2014-04-08 19:32:48 +04:00
|
|
|
{
|
|
|
|
UINT32 pad;
|
|
|
|
|
|
|
|
pad = size;
|
|
|
|
size = (size + alignment - 1) & ~(alignment - 1);
|
|
|
|
pad = size - pad;
|
|
|
|
|
|
|
|
if (pad)
|
2014-04-11 22:01:42 +04:00
|
|
|
Stream_Zero(s, pad);
|
2014-04-08 19:32:48 +04:00
|
|
|
|
|
|
|
return pad;
|
|
|
|
}
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
SCARDCONTEXT smartcard_scard_context_native_from_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDCONTEXT* context)
|
2014-04-07 07:08:40 +04:00
|
|
|
{
|
2014-04-11 22:01:42 +04:00
|
|
|
SCARDCONTEXT hContext = 0;
|
2014-04-07 07:08:40 +04:00
|
|
|
|
2014-05-04 01:07:30 +04:00
|
|
|
if ((context->cbContext != sizeof(ULONG_PTR)) && (context->cbContext != 0))
|
2014-04-11 22:01:42 +04:00
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN,
|
|
|
|
"REDIR_SCARDCONTEXT does not match native size: Actual: %d, Expected: %d",
|
|
|
|
context->cbContext, sizeof(ULONG_PTR));
|
2014-04-12 00:27:01 +04:00
|
|
|
return 0;
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
2014-04-07 07:08:40 +04:00
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
if (context->cbContext)
|
|
|
|
CopyMemory(&hContext, &(context->pbContext), context->cbContext);
|
2014-05-04 01:07:30 +04:00
|
|
|
else
|
|
|
|
ZeroMemory(&hContext, sizeof(ULONG_PTR));
|
2014-04-07 07:08:40 +04:00
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
return hContext;
|
|
|
|
}
|
2014-04-07 07:08:40 +04:00
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
void smartcard_scard_context_native_to_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDCONTEXT* context, SCARDCONTEXT hContext)
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
ZeroMemory(context, sizeof(REDIR_SCARDCONTEXT));
|
2014-04-11 22:01:42 +04:00
|
|
|
context->cbContext = sizeof(ULONG_PTR);
|
2014-04-12 00:27:01 +04:00
|
|
|
CopyMemory(&(context->pbContext), &hContext, context->cbContext);
|
2014-04-07 07:08:40 +04:00
|
|
|
}
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
SCARDHANDLE smartcard_scard_handle_native_from_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDHANDLE* handle)
|
2014-04-08 19:32:48 +04:00
|
|
|
{
|
2014-04-11 22:01:42 +04:00
|
|
|
SCARDHANDLE hCard = 0;
|
2014-04-08 19:32:48 +04:00
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
if (handle->cbHandle != sizeof(ULONG_PTR))
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN,
|
|
|
|
"REDIR_SCARDHANDLE does not match native size: Actual: %d, Expected: %d",
|
|
|
|
handle->cbHandle, sizeof(ULONG_PTR));
|
2014-04-12 00:27:01 +04:00
|
|
|
return 0;
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
2014-04-08 19:32:48 +04:00
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
if (handle->cbHandle)
|
|
|
|
CopyMemory(&hCard, &(handle->pbHandle), handle->cbHandle);
|
2014-04-08 19:32:48 +04:00
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
return hCard;
|
|
|
|
}
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
void smartcard_scard_handle_native_to_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDHANDLE* handle, SCARDHANDLE hCard)
|
2014-04-11 22:01:42 +04:00
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
ZeroMemory(handle, sizeof(REDIR_SCARDHANDLE));
|
|
|
|
handle->cbHandle = sizeof(ULONG_PTR);
|
|
|
|
CopyMemory(&(handle->pbHandle), &hCard, handle->cbHandle);
|
2014-04-08 19:32:48 +04:00
|
|
|
}
|
|
|
|
|
2014-04-06 00:06:46 +04:00
|
|
|
UINT32 smartcard_unpack_redir_scard_context(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDCONTEXT* context)
|
|
|
|
{
|
2014-04-11 22:13:06 +04:00
|
|
|
UINT32 pbContextNdrPtr;
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
ZeroMemory(context, sizeof(REDIR_SCARDCONTEXT));
|
2014-04-11 22:01:42 +04:00
|
|
|
|
2014-04-06 00:06:46 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDCONTEXT is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, context->cbContext); /* cbContext (4 bytes) */
|
|
|
|
|
2014-05-04 01:07:30 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < context->cbContext)
|
2014-04-06 00:06:46 +04:00
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDCONTEXT is too short: Actual: %d, Expected: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s), context->cbContext);
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
2014-05-04 01:07:30 +04:00
|
|
|
if ((context->cbContext != 0) && (context->cbContext != 4) && (context->cbContext != 8))
|
2014-04-12 01:44:27 +04:00
|
|
|
{
|
2014-05-04 01:07:30 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDCONTEXT length is not 0, 4 or 8: %d\n", context->cbContext);
|
2014-04-12 01:44:27 +04:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2014-04-11 22:13:06 +04:00
|
|
|
Stream_Read_UINT32(s, pbContextNdrPtr); /* pbContextNdrPtr (4 bytes) */
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2014-05-04 01:07:30 +04:00
|
|
|
if (((context->cbContext == 0) && pbContextNdrPtr) || ((context->cbContext != 0) && !pbContextNdrPtr))
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDCONTEXT cbContext (%d) pbContextNdrPtr (%d) inconsistency",
|
|
|
|
(int) context->cbContext, (int) pbContextNdrPtr);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2014-04-06 00:06:46 +04:00
|
|
|
if (context->cbContext > Stream_GetRemainingLength(s))
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDCONTEXT is too long: Actual: %d, Expected: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s), context->cbContext);
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-07 07:08:40 +04:00
|
|
|
UINT32 smartcard_pack_redir_scard_context(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDCONTEXT* context)
|
|
|
|
{
|
|
|
|
UINT32 pbContextNdrPtr;
|
|
|
|
|
|
|
|
pbContextNdrPtr = (context->cbContext) ? 0x00020001 : 0;
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, context->cbContext); /* cbContext (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, pbContextNdrPtr); /* pbContextNdrPtr (4 bytes) */
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-06 00:06:46 +04:00
|
|
|
UINT32 smartcard_unpack_redir_scard_context_ref(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDCONTEXT* context)
|
|
|
|
{
|
2014-04-11 22:13:06 +04:00
|
|
|
UINT32 length;
|
|
|
|
|
2014-05-04 01:07:30 +04:00
|
|
|
if (context->cbContext == 0)
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
|
2014-04-06 00:06:46 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDCONTEXT is too short: Actual: %d, Expected: %d\n",
|
|
|
|
(int) Stream_GetRemainingLength(s), 4);
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
2014-04-11 22:13:06 +04:00
|
|
|
Stream_Read_UINT32(s, length); /* Length (4 bytes) */
|
|
|
|
|
|
|
|
if (length != context->cbContext)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDCONTEXT length (%d) cbContext (%d) mismatch\n",
|
|
|
|
length, context->cbContext);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2014-05-04 01:07:30 +04:00
|
|
|
if ((context->cbContext != 0) && (context->cbContext != 4) && (context->cbContext != 8))
|
2014-04-06 00:06:46 +04:00
|
|
|
{
|
2014-04-11 22:01:42 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDCONTEXT length is not 4 or 8: %d\n", context->cbContext);
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
2014-05-04 01:07:30 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < context->cbContext)
|
2014-04-06 00:06:46 +04:00
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDCONTEXT is too short: Actual: %d, Expected: %d\n",
|
2014-04-11 22:01:42 +04:00
|
|
|
(int) Stream_GetRemainingLength(s), context->cbContext);
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
if (context->cbContext)
|
|
|
|
Stream_Read(s, &(context->pbContext), context->cbContext);
|
2014-05-04 01:07:30 +04:00
|
|
|
else
|
|
|
|
ZeroMemory(&(context->pbContext), sizeof(context->pbContext));
|
2014-04-06 00:06:46 +04:00
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-07 07:08:40 +04:00
|
|
|
UINT32 smartcard_pack_redir_scard_context_ref(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDCONTEXT* context)
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
Stream_Write_UINT32(s, context->cbContext); /* Length (4 bytes) */
|
|
|
|
|
2014-04-07 07:08:40 +04:00
|
|
|
if (context->cbContext)
|
|
|
|
{
|
2014-04-12 01:44:27 +04:00
|
|
|
Stream_Write(s, &(context->pbContext), context->cbContext);
|
2014-04-07 07:08:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-07 00:29:11 +04:00
|
|
|
UINT32 smartcard_unpack_redir_scard_handle(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDHANDLE* handle)
|
|
|
|
{
|
2014-04-11 22:01:42 +04:00
|
|
|
UINT32 pbHandleNdrPtr;
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
ZeroMemory(handle, sizeof(REDIR_SCARDHANDLE));
|
2014-04-07 00:29:11 +04:00
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "SCARDHANDLE is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
2014-04-11 22:13:06 +04:00
|
|
|
Stream_Read_UINT32(s, handle->cbHandle); /* Length (4 bytes) */
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2014-04-11 22:13:06 +04:00
|
|
|
if ((Stream_GetRemainingLength(s) < handle->cbHandle) || (!handle->cbHandle))
|
2014-04-07 00:29:11 +04:00
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "SCARDHANDLE is too short: Actual: %d, Expected: %d",
|
2014-04-11 22:13:06 +04:00
|
|
|
(int) Stream_GetRemainingLength(s), handle->cbHandle);
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
Stream_Read_UINT32(s, pbHandleNdrPtr); /* NdrPtr (4 bytes) */
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
return SCARD_S_SUCCESS;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
2014-04-07 07:08:40 +04:00
|
|
|
UINT32 smartcard_pack_redir_scard_handle(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDHANDLE* handle)
|
|
|
|
{
|
|
|
|
UINT32 pbHandleNdrPtr;
|
|
|
|
|
|
|
|
pbHandleNdrPtr = (handle->cbHandle) ? 0x00020002 : 0;
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, handle->cbHandle); /* cbHandle (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, pbHandleNdrPtr); /* pbHandleNdrPtr (4 bytes) */
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-07 00:29:11 +04:00
|
|
|
UINT32 smartcard_unpack_redir_scard_handle_ref(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDHANDLE* handle)
|
|
|
|
{
|
2014-04-11 22:13:06 +04:00
|
|
|
UINT32 length;
|
2014-04-07 00:29:11 +04:00
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDHANDLE is too short: Actual: %d, Expected: %d\n",
|
|
|
|
(int) Stream_GetRemainingLength(s), 4);
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
2014-04-11 22:13:06 +04:00
|
|
|
Stream_Read_UINT32(s, length); /* Length (4 bytes) */
|
|
|
|
|
|
|
|
if (length != handle->cbHandle)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDHANDLE length (%d) cbHandle (%d) mismatch\n",
|
|
|
|
length, handle->cbHandle);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
if ((handle->cbHandle != 4) && (handle->cbHandle != 8))
|
2014-04-07 00:29:11 +04:00
|
|
|
{
|
2014-04-11 22:01:42 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDHANDLE length is not 4 or 8: %d\n", handle->cbHandle);
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
if ((Stream_GetRemainingLength(s) < handle->cbHandle) || (!handle->cbHandle))
|
2014-04-07 00:29:11 +04:00
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDHANDLE is too short: Actual: %d, Expected: %d\n",
|
2014-04-11 22:01:42 +04:00
|
|
|
(int) Stream_GetRemainingLength(s), handle->cbHandle);
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
if (handle->cbHandle)
|
|
|
|
Stream_Read(s, &(handle->pbHandle), handle->cbHandle);
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
return SCARD_S_SUCCESS;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
2014-04-07 07:08:40 +04:00
|
|
|
UINT32 smartcard_pack_redir_scard_handle_ref(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDHANDLE* handle)
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
Stream_Write_UINT32(s, handle->cbHandle); /* Length (4 bytes) */
|
2014-04-07 07:08:40 +04:00
|
|
|
|
|
|
|
if (handle->cbHandle)
|
2014-04-12 00:27:01 +04:00
|
|
|
Stream_Write(s, &(handle->pbHandle), handle->cbHandle);
|
2014-04-07 07:08:40 +04:00
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
return SCARD_S_SUCCESS;
|
2014-04-07 07:08:40 +04:00
|
|
|
}
|
|
|
|
|
2014-04-07 05:09:49 +04:00
|
|
|
UINT32 smartcard_unpack_establish_context_call(SMARTCARD_DEVICE* smartcard, wStream* s, EstablishContext_Call* call)
|
|
|
|
{
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "EstablishContext_Call is too short: Actual: %d, Expected: %d\n",
|
|
|
|
(int) Stream_GetRemainingLength(s), 4);
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, call->dwScope); /* dwScope (4 bytes) */
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-11 10:17:36 +04:00
|
|
|
void smartcard_trace_establish_context_call(SMARTCARD_DEVICE* smartcard, EstablishContext_Call* call)
|
|
|
|
{
|
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "EstablishContext_Call {");
|
|
|
|
|
2014-04-12 22:31:54 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "dwScope: %s (0x%08X)",
|
|
|
|
SCardGetScopeString(call->dwScope), call->dwScope);
|
2014-04-11 10:17:36 +04:00
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
}
|
|
|
|
|
2014-04-07 07:08:40 +04:00
|
|
|
UINT32 smartcard_pack_establish_context_return(SMARTCARD_DEVICE* smartcard, wStream* s, EstablishContext_Return* ret)
|
|
|
|
{
|
|
|
|
UINT32 status;
|
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
status = smartcard_pack_redir_scard_context(smartcard, s, &(ret->hContext));
|
2014-04-07 07:08:40 +04:00
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
status = smartcard_pack_redir_scard_context_ref(smartcard, s, &(ret->hContext));
|
2014-04-07 07:08:40 +04:00
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-11 10:17:36 +04:00
|
|
|
void smartcard_trace_establish_context_return(SMARTCARD_DEVICE* smartcard, EstablishContext_Return* ret)
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
BYTE* pb;
|
|
|
|
|
2014-04-11 10:17:36 +04:00
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "EstablishContext_Return {");
|
2014-04-11 10:17:36 +04:00
|
|
|
|
2014-05-06 21:00:44 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "ReturnCode: %s (0x%08X)",
|
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
2014-04-11 10:17:36 +04:00
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
pb = (BYTE*) &(ret->hContext.pbContext);
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
if (ret->hContext.cbContext > 4)
|
2014-04-11 22:01:42 +04:00
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)",
|
2014-04-12 01:44:27 +04:00
|
|
|
pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], ret->hContext.cbContext);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)",
|
2014-04-12 01:44:27 +04:00
|
|
|
pb[0], pb[1], pb[2], pb[3], ret->hContext.cbContext);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
2014-04-11 10:17:36 +04:00
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
}
|
|
|
|
|
2014-04-07 05:09:49 +04:00
|
|
|
UINT32 smartcard_unpack_context_call(SMARTCARD_DEVICE* smartcard, wStream* s, Context_Call* call)
|
|
|
|
{
|
|
|
|
UINT32 status;
|
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->hContext));
|
2014-04-07 05:09:49 +04:00
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->hContext));
|
2014-04-07 05:09:49 +04:00
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
void smartcard_trace_context_call(SMARTCARD_DEVICE* smartcard, Context_Call* call, const char* name)
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
BYTE* pb;
|
|
|
|
|
2014-04-14 00:48:32 +04:00
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "%s_Call {", name);
|
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
pb = (BYTE*) &(call->hContext.pbContext);
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
if (call->hContext.cbContext > 4)
|
2014-04-11 22:01:42 +04:00
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)",
|
2014-04-12 01:44:27 +04:00
|
|
|
pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->hContext.cbContext);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)",
|
2014-04-12 01:44:27 +04:00
|
|
|
pb[0], pb[1], pb[2], pb[3], call->hContext.cbContext);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
}
|
|
|
|
|
2014-05-06 21:00:44 +04:00
|
|
|
void smartcard_trace_long_return(SMARTCARD_DEVICE* smartcard, Long_Return* ret, const char* name)
|
|
|
|
{
|
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "%s_Return {", name);
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "ReturnCode: %s (0x%08X)",
|
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
}
|
|
|
|
|
2014-04-07 05:09:49 +04:00
|
|
|
UINT32 smartcard_unpack_list_readers_call(SMARTCARD_DEVICE* smartcard, wStream* s, ListReaders_Call* call)
|
|
|
|
{
|
|
|
|
UINT32 status;
|
2014-04-09 02:55:50 +04:00
|
|
|
UINT32 count;
|
2014-04-08 01:17:26 +04:00
|
|
|
UINT32 mszGroupsNdrPtr;
|
|
|
|
|
|
|
|
call->mszGroups = NULL;
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->hContext));
|
2014-04-07 05:09:49 +04:00
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 16)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "ListReaders_Call is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, call->cBytes); /* cBytes (4 bytes) */
|
2014-04-08 01:17:26 +04:00
|
|
|
Stream_Read_UINT32(s, mszGroupsNdrPtr); /* mszGroupsNdrPtr (4 bytes) */
|
2014-04-07 05:09:49 +04:00
|
|
|
Stream_Read_UINT32(s, call->fmszReadersIsNULL); /* fmszReadersIsNULL (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->cchReaders); /* cchReaders (4 bytes) */
|
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->hContext));
|
2014-04-09 02:55:50 +04:00
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
if ((mszGroupsNdrPtr && !call->cBytes) || (!mszGroupsNdrPtr && call->cBytes))
|
2014-04-07 05:09:49 +04:00
|
|
|
{
|
2014-04-09 02:55:50 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_WARN,
|
|
|
|
"ListReaders_Call mszGroupsNdrPtr (0x%08X) and cBytes (0x%08X) inconsistency",
|
|
|
|
(int) mszGroupsNdrPtr, (int) call->cBytes);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
2014-04-09 02:55:50 +04:00
|
|
|
|
2014-04-08 01:17:26 +04:00
|
|
|
if (mszGroupsNdrPtr)
|
|
|
|
{
|
2014-04-09 02:55:50 +04:00
|
|
|
Stream_Read_UINT32(s, count); /* NdrCount (4 bytes) */
|
|
|
|
|
|
|
|
if (count != call->cBytes)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN,
|
|
|
|
"ListReaders_Call NdrCount (0x%08X) and cBytes (0x%08X) inconsistency",
|
|
|
|
(int) count, (int) call->cBytes);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < call->cBytes)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "ListReaders_Call is too short: Actual: %d, Expected: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s), call->cBytes);
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
call->mszGroups = (BYTE*) calloc(1, call->cBytes + 4);
|
|
|
|
|
|
|
|
if (!call->mszGroups)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "ListReaders_Call out of memory error (mszGroups)");
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read(s, call->mszGroups, call->cBytes);
|
|
|
|
|
|
|
|
smartcard_unpack_read_size_align(smartcard, s, call->cBytes, 4);
|
2014-04-08 01:17:26 +04:00
|
|
|
}
|
|
|
|
|
2014-04-07 05:09:49 +04:00
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
void smartcard_trace_list_readers_call(SMARTCARD_DEVICE* smartcard, ListReaders_Call* call, BOOL unicode)
|
2014-04-11 10:17:36 +04:00
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
BYTE* pb;
|
2014-04-11 10:17:36 +04:00
|
|
|
char* mszGroupsA = NULL;
|
|
|
|
|
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (unicode)
|
|
|
|
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) call->mszGroups, call->cBytes / 2, &mszGroupsA, 0, NULL, NULL);
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "ListReaders%S_Call {", unicode ? "W" : "A");
|
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
pb = (BYTE*) &(call->hContext.pbContext);
|
2014-04-11 10:17:36 +04:00
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
if (call->hContext.cbContext > 4)
|
2014-04-11 22:01:42 +04:00
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)",
|
2014-04-12 01:44:27 +04:00
|
|
|
pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->hContext.cbContext);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)",
|
2014-04-12 01:44:27 +04:00
|
|
|
pb[0], pb[1], pb[2], pb[3], call->hContext.cbContext);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
2014-04-11 10:17:36 +04:00
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG,
|
|
|
|
"cBytes: %d mszGroups: %s fmszReadersIsNULL: %d cchReaders: 0x%08X",
|
|
|
|
call->cBytes, mszGroupsA, call->fmszReadersIsNULL, call->cchReaders);
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
|
|
|
|
if (unicode)
|
|
|
|
free(mszGroupsA);
|
|
|
|
}
|
|
|
|
|
2014-04-07 08:10:27 +04:00
|
|
|
UINT32 smartcard_pack_list_readers_return(SMARTCARD_DEVICE* smartcard, wStream* s, ListReaders_Return* ret)
|
|
|
|
{
|
2014-04-10 01:44:39 +04:00
|
|
|
UINT32 mszNdrPtr;
|
|
|
|
|
|
|
|
mszNdrPtr = (ret->cBytes) ? 0x00020008 : 0;
|
|
|
|
|
2014-04-13 23:50:51 +04:00
|
|
|
Stream_EnsureRemainingCapacity(s, ret->cBytes + 32);
|
|
|
|
|
2014-04-07 08:10:27 +04:00
|
|
|
Stream_Write_UINT32(s, ret->cBytes); /* cBytes (4 bytes) */
|
2014-04-10 01:44:39 +04:00
|
|
|
Stream_Write_UINT32(s, mszNdrPtr); /* mszNdrPtr (4 bytes) */
|
2014-04-08 07:45:11 +04:00
|
|
|
|
2014-04-10 01:44:39 +04:00
|
|
|
if (mszNdrPtr)
|
|
|
|
{
|
|
|
|
Stream_Write_UINT32(s, ret->cBytes); /* mszNdrLen (4 bytes) */
|
2014-04-09 22:27:44 +04:00
|
|
|
|
2014-04-10 01:44:39 +04:00
|
|
|
if (ret->msz)
|
|
|
|
Stream_Write(s, ret->msz, ret->cBytes);
|
|
|
|
else
|
|
|
|
Stream_Zero(s, ret->cBytes);
|
|
|
|
|
|
|
|
smartcard_pack_write_size_align(smartcard, s, ret->cBytes, 4);
|
|
|
|
}
|
2014-04-07 08:10:27 +04:00
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
void smartcard_trace_list_readers_return(SMARTCARD_DEVICE* smartcard, ListReaders_Return* ret, BOOL unicode)
|
2014-04-11 10:17:36 +04:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
int length;
|
|
|
|
char* mszA = NULL;
|
|
|
|
|
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (unicode)
|
|
|
|
{
|
|
|
|
length = ret->cBytes / 2;
|
|
|
|
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) ret->msz, length, &mszA, 0, NULL, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
length = ret->cBytes;
|
|
|
|
mszA = (char*) malloc(length);
|
|
|
|
CopyMemory(mszA, ret->msz, ret->cBytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (index = 0; index < length - 2; index++)
|
|
|
|
{
|
|
|
|
if (mszA[index] == '\0')
|
|
|
|
mszA[index] = ',';
|
|
|
|
}
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "ListReaders%s_Return {", unicode ? "W" : "A");
|
2014-04-11 10:17:36 +04:00
|
|
|
|
2014-04-14 00:48:32 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "ReturnCode: %s (0x%08X)",
|
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "cBytes: %d msz: %s", ret->cBytes, mszA);
|
2014-04-11 10:17:36 +04:00
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
|
|
|
|
free(mszA);
|
|
|
|
}
|
|
|
|
|
2014-04-06 00:06:46 +04:00
|
|
|
UINT32 smartcard_unpack_connect_common(SMARTCARD_DEVICE* smartcard, wStream* s, Connect_Common* common)
|
|
|
|
{
|
|
|
|
UINT32 status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Connect_Common is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(common->hContext));
|
2014-04-06 00:06:46 +04:00
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, common->dwShareMode); /* dwShareMode (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, common->dwPreferredProtocols); /* dwPreferredProtocols (4 bytes) */
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT32 smartcard_unpack_connect_a_call(SMARTCARD_DEVICE* smartcard, wStream* s, ConnectA_Call* call)
|
|
|
|
{
|
|
|
|
UINT32 status;
|
|
|
|
UINT32 count;
|
|
|
|
|
|
|
|
call->szReader = NULL;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "ConnectA_Call is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
2014-04-07 07:08:40 +04:00
|
|
|
Stream_Seek_UINT32(s); /* szReaderNdrPtr (4 bytes) */
|
2014-04-06 00:06:46 +04:00
|
|
|
|
|
|
|
status = smartcard_unpack_connect_common(smartcard, s, &(call->Common));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
/* szReader */
|
|
|
|
|
|
|
|
Stream_Seek_UINT32(s); /* NdrMaxCount (4 bytes) */
|
|
|
|
Stream_Seek_UINT32(s); /* NdrOffset (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, count); /* NdrActualCount (4 bytes) */
|
|
|
|
|
2014-04-11 10:17:36 +04:00
|
|
|
call->szReader = (unsigned char*) malloc(count + 1);
|
2014-04-27 23:45:36 +04:00
|
|
|
|
|
|
|
if (!call->szReader)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "ConnectA_Call out of memory error (call->szReader)");
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2014-04-06 00:06:46 +04:00
|
|
|
Stream_Read(s, call->szReader, count);
|
2014-04-08 19:32:48 +04:00
|
|
|
smartcard_unpack_read_size_align(smartcard, s, count, 4);
|
2014-04-06 00:06:46 +04:00
|
|
|
call->szReader[count] = '\0';
|
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->Common.hContext));
|
2014-04-06 00:06:46 +04:00
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-11 10:17:36 +04:00
|
|
|
void smartcard_trace_connect_a_call(SMARTCARD_DEVICE* smartcard, ConnectA_Call* call)
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
BYTE* pb;
|
|
|
|
|
2014-04-11 10:17:36 +04:00
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "ConnectA_Call {");
|
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
pb = (BYTE*) &(call->Common.hContext.pbContext);
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
if (call->Common.hContext.cbContext > 4)
|
2014-04-11 22:01:42 +04:00
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)",
|
2014-04-12 01:44:27 +04:00
|
|
|
pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->Common.hContext.cbContext);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)",
|
2014-04-12 01:44:27 +04:00
|
|
|
pb[0], pb[1], pb[2], pb[3], call->Common.hContext.cbContext);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
2014-04-11 10:17:36 +04:00
|
|
|
|
2014-04-12 20:42:09 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "szReader: %s dwShareMode: %s (0x%08X) dwPreferredProtocols: %s (0x%08X)",
|
|
|
|
call->szReader, SCardGetShareModeString(call->Common.dwShareMode), call->Common.dwShareMode,
|
|
|
|
SCardGetProtocolString(call->Common.dwPreferredProtocols), call->Common.dwPreferredProtocols);
|
2014-04-11 10:17:36 +04:00
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
}
|
|
|
|
|
2014-04-06 00:06:46 +04:00
|
|
|
UINT32 smartcard_unpack_connect_w_call(SMARTCARD_DEVICE* smartcard, wStream* s, ConnectW_Call* call)
|
|
|
|
{
|
|
|
|
UINT32 status;
|
|
|
|
UINT32 count;
|
|
|
|
|
|
|
|
call->szReader = NULL;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
{
|
2014-04-27 23:45:36 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "ConnectW_Call is too short: %d",
|
2014-04-06 00:06:46 +04:00
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
2014-04-07 07:08:40 +04:00
|
|
|
Stream_Seek_UINT32(s); /* szReaderNdrPtr (4 bytes) */
|
2014-04-06 00:06:46 +04:00
|
|
|
|
|
|
|
status = smartcard_unpack_connect_common(smartcard, s, &(call->Common));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
/* szReader */
|
|
|
|
|
|
|
|
Stream_Seek_UINT32(s); /* NdrMaxCount (4 bytes) */
|
|
|
|
Stream_Seek_UINT32(s); /* NdrOffset (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, count); /* NdrActualCount (4 bytes) */
|
|
|
|
|
2014-04-11 10:17:36 +04:00
|
|
|
call->szReader = (WCHAR*) malloc((count + 1) * 2);
|
2014-04-27 23:45:36 +04:00
|
|
|
|
|
|
|
if (!call->szReader)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "ConnectW_Call out of memory error (call->szReader)");
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2014-04-06 00:06:46 +04:00
|
|
|
Stream_Read(s, call->szReader, (count * 2));
|
2014-04-08 19:32:48 +04:00
|
|
|
smartcard_unpack_read_size_align(smartcard, s, (count * 2), 4);
|
2014-04-06 00:06:46 +04:00
|
|
|
call->szReader[count] = '\0';
|
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->Common.hContext));
|
2014-04-06 00:06:46 +04:00
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2014-04-11 10:17:36 +04:00
|
|
|
void smartcard_trace_connect_w_call(SMARTCARD_DEVICE* smartcard, ConnectW_Call* call)
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
BYTE* pb;
|
2014-04-11 10:17:36 +04:00
|
|
|
char* szReaderA = NULL;
|
|
|
|
|
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ConvertFromUnicode(CP_UTF8, 0, call->szReader, -1, &szReaderA, 0, NULL, NULL);
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "ConnectA_Call {");
|
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
pb = (BYTE*) &(call->Common.hContext.pbContext);
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
if (call->Common.hContext.cbContext > 4)
|
2014-04-11 22:01:42 +04:00
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)",
|
2014-04-12 01:44:27 +04:00
|
|
|
pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->Common.hContext.cbContext);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)",
|
2014-04-12 01:44:27 +04:00
|
|
|
pb[0], pb[1], pb[2], pb[3], call->Common.hContext.cbContext);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
2014-04-11 10:17:36 +04:00
|
|
|
|
2014-04-12 20:42:09 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "szReader: %s dwShareMode: %s (0x%08X) dwPreferredProtocols: %s (0x%08X)",
|
|
|
|
szReaderA, SCardGetShareModeString(call->Common.dwShareMode), call->Common.dwShareMode,
|
|
|
|
SCardGetProtocolString(call->Common.dwPreferredProtocols), call->Common.dwPreferredProtocols);
|
2014-04-11 10:17:36 +04:00
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
|
|
|
|
free(szReaderA);
|
|
|
|
}
|
|
|
|
|
2014-04-07 07:08:40 +04:00
|
|
|
UINT32 smartcard_pack_connect_return(SMARTCARD_DEVICE* smartcard, wStream* s, Connect_Return* ret)
|
|
|
|
{
|
|
|
|
UINT32 status;
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
status = smartcard_pack_redir_scard_context(smartcard, s, &(ret->hContext));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2014-04-07 07:08:40 +04:00
|
|
|
status = smartcard_pack_redir_scard_handle(smartcard, s, &(ret->hCard));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, ret->dwActiveProtocol); /* dwActiveProtocol (4 bytes) */
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
status = smartcard_pack_redir_scard_context_ref(smartcard, s, &(ret->hContext));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2014-04-07 07:08:40 +04:00
|
|
|
status = smartcard_pack_redir_scard_handle_ref(smartcard, s, &(ret->hCard));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-11 10:17:36 +04:00
|
|
|
void smartcard_trace_connect_return(SMARTCARD_DEVICE* smartcard, Connect_Return* ret)
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
BYTE* pb;
|
|
|
|
|
2014-04-11 10:17:36 +04:00
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "Connect_Return {");
|
|
|
|
|
2014-04-14 00:48:32 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "ReturnCode: %s (0x%08X)",
|
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
pb = (BYTE*) &(ret->hContext.pbContext);
|
|
|
|
|
|
|
|
if (ret->hContext.cbContext > 4)
|
2014-04-11 22:01:42 +04:00
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], ret->hContext.cbContext);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], ret->hContext.cbContext);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
pb = (BYTE*) &(ret->hCard.pbHandle);
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
if (ret->hCard.cbHandle > 4)
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], ret->hCard.cbHandle);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], ret->hCard.cbHandle);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
2014-04-11 10:17:36 +04:00
|
|
|
|
2014-04-12 20:42:09 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "dwActiveProtocol: %s (0x%08X)",
|
|
|
|
SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
|
2014-04-11 10:17:36 +04:00
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
}
|
|
|
|
|
2014-04-07 00:29:11 +04:00
|
|
|
UINT32 smartcard_unpack_reconnect_call(SMARTCARD_DEVICE* smartcard, wStream* s, Reconnect_Call* call)
|
|
|
|
{
|
|
|
|
UINT32 status;
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->hContext));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2014-04-07 00:29:11 +04:00
|
|
|
status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->hCard));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Reconnect_Call is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, call->dwShareMode); /* dwShareMode (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->dwPreferredProtocols); /* dwPreferredProtocols (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->dwInitialization); /* dwInitialization (4 bytes) */
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->hContext));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2014-04-07 00:29:11 +04:00
|
|
|
status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->hCard));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-14 00:48:32 +04:00
|
|
|
void smartcard_trace_reconnect_call(SMARTCARD_DEVICE* smartcard, Reconnect_Call* call)
|
|
|
|
{
|
|
|
|
BYTE* pb;
|
|
|
|
|
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "Reconnect_Call {");
|
|
|
|
|
|
|
|
pb = (BYTE*) &(call->hContext.pbContext);
|
|
|
|
|
|
|
|
if (call->hContext.cbContext > 4)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->hContext.cbContext);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], call->hContext.cbContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
pb = (BYTE*) &(call->hCard.pbHandle);
|
|
|
|
|
|
|
|
if (call->hCard.cbHandle > 4)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->hCard.cbHandle);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], call->hCard.cbHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG,
|
|
|
|
"dwShareMode: %s (0x%08X) dwPreferredProtocols: %s (0x%08X) dwInitialization: %s (0x%08X)",
|
|
|
|
SCardGetShareModeString(call->dwShareMode), call->dwShareMode,
|
|
|
|
SCardGetProtocolString(call->dwPreferredProtocols), call->dwPreferredProtocols,
|
|
|
|
SCardGetDispositionString(call->dwInitialization), call->dwInitialization);
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
}
|
|
|
|
|
2014-04-07 07:08:40 +04:00
|
|
|
UINT32 smartcard_pack_reconnect_return(SMARTCARD_DEVICE* smartcard, wStream* s, Reconnect_Return* ret)
|
|
|
|
{
|
|
|
|
Stream_Write_UINT32(s, ret->dwActiveProtocol); /* dwActiveProtocol (4 bytes) */
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-14 00:48:32 +04:00
|
|
|
void smartcard_trace_reconnect_return(SMARTCARD_DEVICE* smartcard, Reconnect_Return* ret)
|
|
|
|
{
|
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "Reconnect_Return {");
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "ReturnCode: %s (0x%08X)",
|
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "dwActiveProtocol: %s (0x%08X)",
|
|
|
|
SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
}
|
|
|
|
|
2014-04-07 00:29:11 +04:00
|
|
|
UINT32 smartcard_unpack_hcard_and_disposition_call(SMARTCARD_DEVICE* smartcard, wStream* s, HCardAndDisposition_Call* call)
|
|
|
|
{
|
|
|
|
UINT32 status;
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->hContext));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2014-04-07 00:29:11 +04:00
|
|
|
status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->hCard));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "HCardAndDisposition_Call is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, call->dwDisposition); /* dwDisposition (4 bytes) */
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->hContext));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2014-04-07 00:29:11 +04:00
|
|
|
status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->hCard));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
void smartcard_trace_hcard_and_disposition_call(SMARTCARD_DEVICE* smartcard, HCardAndDisposition_Call* call, const char* name)
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
BYTE* pb;
|
|
|
|
|
2014-04-14 00:48:32 +04:00
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "%s_Call {", name);
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
pb = (BYTE*) &(call->hContext.pbContext);
|
|
|
|
|
|
|
|
if (call->hContext.cbContext > 4)
|
2014-04-11 22:01:42 +04:00
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->hContext.cbContext);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], call->hContext.cbContext);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
pb = (BYTE*) &(call->hCard.pbHandle);
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
if (call->hCard.cbHandle > 4)
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->hCard.cbHandle);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], call->hCard.cbHandle);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
|
2014-04-12 20:42:09 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "dwDisposition: %s (0x%08X)",
|
|
|
|
SCardGetDispositionString(call->dwDisposition), call->dwDisposition);
|
2014-04-11 22:01:42 +04:00
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
}
|
|
|
|
|
2014-04-07 00:29:11 +04:00
|
|
|
UINT32 smartcard_unpack_get_status_change_a_call(SMARTCARD_DEVICE* smartcard, wStream* s, GetStatusChangeA_Call* call)
|
|
|
|
{
|
2014-04-11 07:55:11 +04:00
|
|
|
UINT32 index;
|
2014-04-07 00:29:11 +04:00
|
|
|
UINT32 count;
|
|
|
|
UINT32 status;
|
2014-04-11 07:55:11 +04:00
|
|
|
UINT32 offset;
|
|
|
|
UINT32 maxCount;
|
2014-04-08 01:17:26 +04:00
|
|
|
UINT32 szReaderNdrPtr;
|
|
|
|
UINT32 rgReaderStatesNdrPtr;
|
2014-04-11 07:55:11 +04:00
|
|
|
LPSCARD_READERSTATEA readerState;
|
2014-04-07 00:29:11 +04:00
|
|
|
|
|
|
|
call->rgReaderStates = NULL;
|
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->hContext));
|
2014-04-07 00:29:11 +04:00
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "GetStatusChangeA_Call is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, call->dwTimeOut); /* dwTimeOut (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->cReaders); /* cReaders (4 bytes) */
|
2014-04-08 01:17:26 +04:00
|
|
|
Stream_Read_UINT32(s, rgReaderStatesNdrPtr); /* rgReaderStatesNdrPtr (4 bytes) */
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->hContext));
|
2014-04-07 00:29:11 +04:00
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "GetStatusChangeA_Call is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
2014-04-08 01:17:26 +04:00
|
|
|
Stream_Read_UINT32(s, count); /* NdrCount (4 bytes) */
|
|
|
|
|
|
|
|
if (count != call->cReaders)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN,
|
|
|
|
"GetStatusChangeA_Call unexpected reader count: Actual: %d, Expected: %d",
|
|
|
|
(int) count, call->cReaders);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2014-04-07 00:29:11 +04:00
|
|
|
|
|
|
|
if (call->cReaders > 0)
|
|
|
|
{
|
2014-04-11 07:55:11 +04:00
|
|
|
call->rgReaderStates = (LPSCARD_READERSTATEA) calloc(call->cReaders, sizeof(SCARD_READERSTATEA));
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2014-04-27 23:45:36 +04:00
|
|
|
if (!call->rgReaderStates)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "GetStatusChangeA_Call out of memory error (call->rgReaderStates)");
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2014-04-07 00:29:11 +04:00
|
|
|
for (index = 0; index < call->cReaders; index++)
|
|
|
|
{
|
|
|
|
readerState = &call->rgReaderStates[index];
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 52)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "GetStatusChangeA_Call is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
2014-04-08 01:17:26 +04:00
|
|
|
Stream_Read_UINT32(s, szReaderNdrPtr); /* szReaderNdrPtr (4 bytes) */
|
2014-04-11 07:55:11 +04:00
|
|
|
Stream_Read_UINT32(s, readerState->dwCurrentState); /* dwCurrentState (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, readerState->dwEventState); /* dwEventState (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, readerState->cbAtr); /* cbAtr (4 bytes) */
|
|
|
|
Stream_Read(s, readerState->rgbAtr, 32); /* rgbAtr [0..32] (32 bytes) */
|
|
|
|
Stream_Seek(s, 4); /* rgbAtr [32..36] (4 bytes) */
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (index = 0; index < call->cReaders; index++)
|
|
|
|
{
|
|
|
|
readerState = &call->rgReaderStates[index];
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "GetStatusChangeA_Call is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
2014-04-11 07:55:11 +04:00
|
|
|
Stream_Read_UINT32(s, maxCount); /* NdrMaxCount (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, offset); /* NdrOffset (4 bytes) */
|
2014-04-07 00:29:11 +04:00
|
|
|
Stream_Read_UINT32(s, count); /* NdrActualCount (4 bytes) */
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < count)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "GetStatusChangeA_Call is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
2014-04-11 07:55:11 +04:00
|
|
|
readerState->szReader = (LPCSTR) malloc(count + 1);
|
2014-04-27 23:45:36 +04:00
|
|
|
|
|
|
|
if (!readerState->szReader)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN,
|
|
|
|
"GetStatusChangeA_Call out of memory error (readerState->szReader)");
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2014-04-11 07:55:11 +04:00
|
|
|
Stream_Read(s, (void*) readerState->szReader, count);
|
2014-04-08 19:32:48 +04:00
|
|
|
smartcard_unpack_read_size_align(smartcard, s, count, 4);
|
2014-04-11 07:55:11 +04:00
|
|
|
((char*) readerState->szReader)[count] = '\0';
|
2014-04-07 00:29:11 +04:00
|
|
|
|
|
|
|
if (!readerState->szReader)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "GetStatusChangeA_Call null reader name");
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-11 10:17:36 +04:00
|
|
|
void smartcard_trace_get_status_change_a_call(SMARTCARD_DEVICE* smartcard, GetStatusChangeA_Call* call)
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
BYTE* pb;
|
2014-04-11 10:17:36 +04:00
|
|
|
UINT32 index;
|
2014-04-12 22:31:54 +04:00
|
|
|
char* szEventState;
|
|
|
|
char* szCurrentState;
|
2014-04-11 10:17:36 +04:00
|
|
|
LPSCARD_READERSTATEA readerState;
|
|
|
|
|
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "GetStatusChangeA_Call {");
|
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
pb = (BYTE*) &(call->hContext.pbContext);
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
if (call->hContext.cbContext > 4)
|
2014-04-11 22:01:42 +04:00
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)",
|
2014-04-12 01:44:27 +04:00
|
|
|
pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->hContext.cbContext);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)",
|
2014-04-12 01:44:27 +04:00
|
|
|
pb[0], pb[1], pb[2], pb[3], call->hContext.cbContext);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
2014-04-11 10:17:36 +04:00
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "dwTimeOut: 0x%08X cReaders: %d",
|
|
|
|
call->dwTimeOut, call->cReaders);
|
|
|
|
|
|
|
|
for (index = 0; index < call->cReaders; index++)
|
|
|
|
{
|
|
|
|
readerState = &call->rgReaderStates[index];
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG,
|
2014-04-12 22:31:54 +04:00
|
|
|
"\t[%d]: szReader: %s cbAtr: %d",
|
|
|
|
index, readerState->szReader, readerState->cbAtr);
|
|
|
|
|
|
|
|
szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
|
|
|
|
szEventState = SCardGetReaderStateString(readerState->dwEventState);
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG,
|
|
|
|
"\t[%d]: dwCurrentState: %s (0x%08X)",
|
|
|
|
index, szCurrentState, readerState->dwCurrentState);
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG,
|
|
|
|
"\t[%d]: dwEventState: %s (0x%08X)",
|
|
|
|
index, szEventState, readerState->dwEventState);
|
|
|
|
|
|
|
|
free(szCurrentState);
|
|
|
|
free(szEventState);
|
2014-04-11 10:17:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
}
|
|
|
|
|
2014-04-07 00:29:11 +04:00
|
|
|
UINT32 smartcard_unpack_get_status_change_w_call(SMARTCARD_DEVICE* smartcard, wStream* s, GetStatusChangeW_Call* call)
|
|
|
|
{
|
2014-04-11 07:55:11 +04:00
|
|
|
UINT32 index;
|
2014-04-07 00:29:11 +04:00
|
|
|
UINT32 count;
|
|
|
|
UINT32 status;
|
2014-04-11 07:55:11 +04:00
|
|
|
UINT32 offset;
|
|
|
|
UINT32 maxCount;
|
|
|
|
UINT32 szReaderNdrPtr;
|
2014-04-08 01:17:26 +04:00
|
|
|
UINT32 rgReaderStatesNdrPtr;
|
2014-04-11 07:55:11 +04:00
|
|
|
LPSCARD_READERSTATEW readerState;
|
2014-04-07 00:29:11 +04:00
|
|
|
|
|
|
|
call->rgReaderStates = NULL;
|
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->hContext));
|
2014-04-07 00:29:11 +04:00
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "GetStatusChangeW_Call is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, call->dwTimeOut); /* dwTimeOut (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->cReaders); /* cReaders (4 bytes) */
|
2014-04-08 01:17:26 +04:00
|
|
|
Stream_Read_UINT32(s, rgReaderStatesNdrPtr); /* rgReaderStatesNdrPtr (4 bytes) */
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->hContext));
|
2014-04-07 00:29:11 +04:00
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "GetStatusChangeW_Call is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Seek_UINT32(s); /* NdrConformant (4 bytes) */
|
|
|
|
|
|
|
|
if (call->cReaders > 0)
|
|
|
|
{
|
2014-04-11 07:55:11 +04:00
|
|
|
call->rgReaderStates = (LPSCARD_READERSTATEW) calloc(call->cReaders, sizeof(SCARD_READERSTATEW));
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2014-04-27 23:45:36 +04:00
|
|
|
if (!call->rgReaderStates)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "GetStatusChangeW_Call out of memory error (call->rgReaderStates)");
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2014-04-07 00:29:11 +04:00
|
|
|
for (index = 0; index < call->cReaders; index++)
|
|
|
|
{
|
|
|
|
readerState = &call->rgReaderStates[index];
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 52)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "GetStatusChangeW_Call is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
2014-04-11 07:55:11 +04:00
|
|
|
Stream_Read_UINT32(s, szReaderNdrPtr); /* (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, readerState->dwCurrentState); /* dwCurrentState (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, readerState->dwEventState); /* dwEventState (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, readerState->cbAtr); /* cbAtr (4 bytes) */
|
|
|
|
Stream_Read(s, readerState->rgbAtr, 32); /* rgbAtr [0..32] (32 bytes) */
|
|
|
|
Stream_Seek(s, 4); /* rgbAtr [32..36] (4 bytes) */
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (index = 0; index < call->cReaders; index++)
|
|
|
|
{
|
|
|
|
readerState = &call->rgReaderStates[index];
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "GetStatusChangeW_Call is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
2014-04-11 07:55:11 +04:00
|
|
|
Stream_Read_UINT32(s, maxCount); /* NdrMaxCount (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, offset); /* NdrOffset (4 bytes) */
|
2014-04-07 00:29:11 +04:00
|
|
|
Stream_Read_UINT32(s, count); /* NdrActualCount (4 bytes) */
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < (count * 2))
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "GetStatusChangeW_Call is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
2014-04-11 01:36:42 +04:00
|
|
|
readerState->szReader = (WCHAR*) malloc((count + 1) * 2);
|
2014-04-27 23:45:36 +04:00
|
|
|
|
|
|
|
if (!readerState->szReader)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN,
|
|
|
|
"GetStatusChangeW_Call out of memory error (readerState->szReader)");
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2014-04-11 07:55:11 +04:00
|
|
|
Stream_Read(s, (void*) readerState->szReader, (count * 2));
|
2014-04-08 19:32:48 +04:00
|
|
|
smartcard_unpack_read_size_align(smartcard, s, (count * 2), 4);
|
2014-04-11 07:55:11 +04:00
|
|
|
((WCHAR*) readerState->szReader)[count] = '\0';
|
2014-04-07 00:29:11 +04:00
|
|
|
|
|
|
|
if (!readerState->szReader)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "GetStatusChangeW_Call null reader name");
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2014-04-11 10:17:36 +04:00
|
|
|
void smartcard_trace_get_status_change_w_call(SMARTCARD_DEVICE* smartcard, GetStatusChangeW_Call* call)
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
BYTE* pb;
|
2014-04-11 10:17:36 +04:00
|
|
|
UINT32 index;
|
2014-04-12 22:31:54 +04:00
|
|
|
char* szEventState;
|
|
|
|
char* szCurrentState;
|
2014-04-11 10:17:36 +04:00
|
|
|
LPSCARD_READERSTATEW readerState;
|
|
|
|
|
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "GetStatusChangeW_Call {");
|
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
pb = (BYTE*) &(call->hContext.pbContext);
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2014-04-12 01:44:27 +04:00
|
|
|
if (call->hContext.cbContext > 4)
|
2014-04-11 22:01:42 +04:00
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)",
|
2014-04-12 01:44:27 +04:00
|
|
|
pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->hContext.cbContext);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)",
|
2014-04-12 01:44:27 +04:00
|
|
|
pb[0], pb[1], pb[2], pb[3], call->hContext.cbContext);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
2014-04-11 10:17:36 +04:00
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "dwTimeOut: 0x%08X cReaders: %d",
|
|
|
|
call->dwTimeOut, call->cReaders);
|
|
|
|
|
|
|
|
for (index = 0; index < call->cReaders; index++)
|
|
|
|
{
|
|
|
|
char* szReaderA = NULL;
|
|
|
|
|
|
|
|
readerState = &call->rgReaderStates[index];
|
|
|
|
|
|
|
|
ConvertFromUnicode(CP_UTF8, 0, readerState->szReader, -1, &szReaderA, 0, NULL, NULL);
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG,
|
2014-04-12 22:31:54 +04:00
|
|
|
"\t[%d]: szReader: %s cbAtr: %d",
|
|
|
|
index, szReaderA, readerState->cbAtr);
|
|
|
|
|
|
|
|
szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
|
|
|
|
szEventState = SCardGetReaderStateString(readerState->dwEventState);
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG,
|
|
|
|
"\t[%d]: dwCurrentState: %s (0x%08X)",
|
|
|
|
index, szCurrentState, readerState->dwCurrentState);
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG,
|
|
|
|
"\t[%d]: dwEventState: %s (0x%08X)",
|
|
|
|
index, szEventState, readerState->dwEventState);
|
|
|
|
|
|
|
|
free(szCurrentState);
|
|
|
|
free(szEventState);
|
2014-04-11 10:17:36 +04:00
|
|
|
|
|
|
|
free(szReaderA);
|
|
|
|
}
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
}
|
|
|
|
|
2014-04-07 18:59:13 +04:00
|
|
|
UINT32 smartcard_pack_get_status_change_return(SMARTCARD_DEVICE* smartcard, wStream* s, GetStatusChange_Return* ret)
|
|
|
|
{
|
2014-04-11 07:55:11 +04:00
|
|
|
UINT32 index;
|
2014-04-07 18:59:13 +04:00
|
|
|
ReaderState_Return* rgReaderState;
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, ret->cReaders); /* cReaders (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, 0x00020100); /* rgReaderStatesNdrPtr (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, ret->cReaders); /* rgReaderStatesNdrCount (4 bytes) */
|
|
|
|
|
|
|
|
for (index = 0; index < ret->cReaders; index++)
|
|
|
|
{
|
|
|
|
rgReaderState = &(ret->rgReaderStates[index]);
|
|
|
|
Stream_Write_UINT32(s, rgReaderState->dwCurrentState); /* dwCurrentState (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, rgReaderState->dwEventState); /* dwEventState (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, rgReaderState->cbAtr); /* cbAtr (4 bytes) */
|
|
|
|
Stream_Write(s, rgReaderState->rgbAtr, 32); /* rgbAtr [0..32] (32 bytes) */
|
2014-04-11 07:55:11 +04:00
|
|
|
Stream_Zero(s, 4); /* rgbAtr [32..36] (32 bytes) */
|
2014-04-07 18:59:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-12 20:42:09 +04:00
|
|
|
void smartcard_trace_get_status_change_return(SMARTCARD_DEVICE* smartcard, GetStatusChange_Return* ret, BOOL unicode)
|
2014-04-11 10:17:36 +04:00
|
|
|
{
|
|
|
|
UINT32 index;
|
2014-04-13 23:50:51 +04:00
|
|
|
char* rgbAtr;
|
2014-04-12 02:57:04 +04:00
|
|
|
char* szEventState;
|
|
|
|
char* szCurrentState;
|
2014-04-11 10:17:36 +04:00
|
|
|
ReaderState_Return* rgReaderState;
|
|
|
|
|
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
2014-04-12 20:42:09 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "GetStatusChange%s_Return {", unicode ? "W" : "A");
|
2014-04-11 10:17:36 +04:00
|
|
|
|
2014-04-14 00:48:32 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "ReturnCode: %s (0x%08X)",
|
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "cReaders: %d", ret->cReaders);
|
2014-04-11 10:17:36 +04:00
|
|
|
|
|
|
|
for (index = 0; index < ret->cReaders; index++)
|
|
|
|
{
|
|
|
|
rgReaderState = &(ret->rgReaderStates[index]);
|
2014-04-12 02:57:04 +04:00
|
|
|
|
2014-04-12 22:31:54 +04:00
|
|
|
szCurrentState = SCardGetReaderStateString(rgReaderState->dwCurrentState);
|
|
|
|
szEventState = SCardGetReaderStateString(rgReaderState->dwEventState);
|
2014-04-16 22:03:22 +04:00
|
|
|
rgbAtr = winpr_BinToHexString((BYTE*) &(rgReaderState->rgbAtr), rgReaderState->cbAtr, FALSE);
|
2014-04-12 02:57:04 +04:00
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG,
|
2014-04-12 22:31:54 +04:00
|
|
|
"\t[%d]: dwCurrentState: %s (0x%08X)",
|
|
|
|
index, szCurrentState, rgReaderState->dwCurrentState);
|
2014-04-11 10:17:36 +04:00
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG,
|
2014-04-12 22:31:54 +04:00
|
|
|
"\t[%d]: dwEventState: %s (0x%08X)",
|
|
|
|
index, szEventState, rgReaderState->dwEventState);
|
2014-04-12 02:57:04 +04:00
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG,
|
2014-04-13 23:50:51 +04:00
|
|
|
"\t[%d]: cbAtr: %d rgbAtr: %s",
|
|
|
|
index, rgReaderState->cbAtr, rgbAtr);
|
2014-04-12 02:57:04 +04:00
|
|
|
|
|
|
|
free(szCurrentState);
|
|
|
|
free(szEventState);
|
2014-04-13 23:50:51 +04:00
|
|
|
free(rgbAtr);
|
2014-04-11 10:17:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
}
|
|
|
|
|
2014-04-07 05:09:49 +04:00
|
|
|
UINT32 smartcard_unpack_state_call(SMARTCARD_DEVICE* smartcard, wStream* s, State_Call* call)
|
|
|
|
{
|
|
|
|
UINT32 status;
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->hContext));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2014-04-07 05:09:49 +04:00
|
|
|
status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->hCard));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "State_Call is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, call->fpbAtrIsNULL); /* fpbAtrIsNULL (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->cbAtrLen); /* cbAtrLen (4 bytes) */
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->hContext));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2014-04-07 05:09:49 +04:00
|
|
|
status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->hCard));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-07 09:19:58 +04:00
|
|
|
UINT32 smartcard_pack_state_return(SMARTCARD_DEVICE* smartcard, wStream* s, State_Return* ret)
|
|
|
|
{
|
|
|
|
Stream_Write_UINT32(s, ret->dwState); /* dwState (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, ret->dwProtocol); /* dwProtocol (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, ret->cbAtrLen); /* cbAtrLen (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, 0x00020020); /* rgAtrNdrPtr (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, ret->cbAtrLen); /* rgAtrLength (4 bytes) */
|
|
|
|
Stream_Write(s, ret->rgAtr, ret->cbAtrLen); /* rgAtr */
|
2014-04-11 07:55:11 +04:00
|
|
|
|
2014-04-08 19:32:48 +04:00
|
|
|
smartcard_pack_write_size_align(smartcard, s, ret->cbAtrLen, 4);
|
2014-04-07 09:19:58 +04:00
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-07 05:09:49 +04:00
|
|
|
UINT32 smartcard_unpack_status_call(SMARTCARD_DEVICE* smartcard, wStream* s, Status_Call* call)
|
|
|
|
{
|
|
|
|
UINT32 status;
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->hContext));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2014-04-07 05:09:49 +04:00
|
|
|
status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->hCard));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Status_Call is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, call->fmszReaderNamesIsNULL); /* fmszReaderNamesIsNULL (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->cchReaderLen); /* cchReaderLen (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->cbAtrLen); /* cbAtrLen (4 bytes) */
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->hContext));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2014-04-07 05:09:49 +04:00
|
|
|
status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->hCard));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
void smartcard_trace_status_call(SMARTCARD_DEVICE* smartcard, Status_Call* call, BOOL unicode)
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
BYTE* pb;
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "Status%s_Call {", unicode ? "W" : "A");
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
pb = (BYTE*) &(call->hContext.pbContext);
|
|
|
|
|
|
|
|
if (call->hContext.cbContext > 4)
|
2014-04-11 22:01:42 +04:00
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->hContext.cbContext);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], call->hContext.cbContext);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
pb = (BYTE*) &(call->hCard.pbHandle);
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
if (call->hCard.cbHandle > 4)
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->hCard.cbHandle);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], call->hCard.cbHandle);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "fmszReaderNamesIsNULL: %d cchReaderLen: %d cbAtrLen: %d",
|
|
|
|
call->fmszReaderNamesIsNULL, call->cchReaderLen, call->cbAtrLen);
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
}
|
|
|
|
|
2014-04-07 08:58:34 +04:00
|
|
|
UINT32 smartcard_pack_status_return(SMARTCARD_DEVICE* smartcard, wStream* s, Status_Return* ret)
|
|
|
|
{
|
2014-04-13 23:50:51 +04:00
|
|
|
Stream_EnsureRemainingCapacity(s, ret->cBytes + 64);
|
|
|
|
|
2014-04-07 08:58:34 +04:00
|
|
|
Stream_Write_UINT32(s, ret->cBytes); /* cBytes (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, 0x00020010); /* mszReaderNamesNdrPtr (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, ret->dwState); /* dwState (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, ret->dwProtocol); /* dwProtocol (4 bytes) */
|
|
|
|
Stream_Write(s, ret->pbAtr, 32); /* pbAtr (32 bytes) */
|
|
|
|
Stream_Write_UINT32(s, ret->cbAtrLen); /* cbAtrLen (4 bytes) */
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, ret->cBytes); /* mszReaderNamesNdrLen (4 bytes) */
|
2014-04-08 07:45:11 +04:00
|
|
|
|
|
|
|
if (ret->mszReaderNames)
|
|
|
|
Stream_Write(s, ret->mszReaderNames, ret->cBytes);
|
|
|
|
else
|
|
|
|
Stream_Zero(s, ret->cBytes);
|
|
|
|
|
2014-04-08 19:32:48 +04:00
|
|
|
smartcard_pack_write_size_align(smartcard, s, ret->cBytes, 4);
|
2014-04-07 08:58:34 +04:00
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
void smartcard_trace_status_return(SMARTCARD_DEVICE* smartcard, Status_Return* ret, BOOL unicode)
|
|
|
|
{
|
|
|
|
UINT32 index;
|
|
|
|
UINT32 length;
|
2014-04-13 23:50:51 +04:00
|
|
|
char* pbAtr = NULL;
|
2014-04-11 22:01:42 +04:00
|
|
|
char* mszReaderNamesA = NULL;
|
|
|
|
|
2014-04-12 02:57:04 +04:00
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
if (unicode)
|
|
|
|
{
|
|
|
|
length = ret->cBytes / 2;
|
|
|
|
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) ret->mszReaderNames, length, &mszReaderNamesA, 0, NULL, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
length = ret->cBytes;
|
|
|
|
mszReaderNamesA = (char*) malloc(length);
|
|
|
|
CopyMemory(mszReaderNamesA, ret->mszReaderNames, ret->cBytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (index = 0; index < length - 2; index++)
|
|
|
|
{
|
|
|
|
if (mszReaderNamesA[index] == '\0')
|
|
|
|
mszReaderNamesA[index] = ',';
|
|
|
|
}
|
|
|
|
|
2014-04-13 23:50:51 +04:00
|
|
|
pbAtr = winpr_BinToHexString(ret->pbAtr, ret->cbAtrLen, FALSE);
|
2014-04-12 02:57:04 +04:00
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "Status%s_Return {", unicode ? "W" : "A");
|
|
|
|
|
2014-04-14 00:48:32 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "ReturnCode: %s (0x%08X)",
|
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
2014-04-11 22:01:42 +04:00
|
|
|
|
2014-04-12 02:57:04 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "dwState: %s (0x%08X) dwProtocol: %s (0x%08X)",
|
2014-04-12 22:31:54 +04:00
|
|
|
SCardGetCardStateString(ret->dwState), ret->dwState,
|
|
|
|
SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
|
2014-04-11 22:01:42 +04:00
|
|
|
|
2014-04-12 02:57:04 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "cBytes: %d mszReaderNames: %s",
|
|
|
|
ret->cBytes, mszReaderNamesA);
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG,
|
2014-04-13 23:50:51 +04:00
|
|
|
"cbAtrLen: %d pbAtr: %s", ret->cbAtrLen, pbAtr);
|
2014-04-11 22:01:42 +04:00
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
|
|
|
|
free(mszReaderNamesA);
|
2014-04-13 23:50:51 +04:00
|
|
|
free(pbAtr);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
|
2014-04-07 05:09:49 +04:00
|
|
|
UINT32 smartcard_unpack_get_attrib_call(SMARTCARD_DEVICE* smartcard, wStream* s, GetAttrib_Call* call)
|
|
|
|
{
|
|
|
|
UINT32 status;
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->hContext));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2014-04-07 05:09:49 +04:00
|
|
|
status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->hCard));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "GetAttrib_Call is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, call->dwAttrId); /* dwAttrId (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->fpbAttrIsNULL); /* fpbAttrIsNULL (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->cbAttrLen); /* cbAttrLen (4 bytes) */
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->hContext));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2014-04-07 05:09:49 +04:00
|
|
|
status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->hCard));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
void smartcard_trace_get_attrib_call(SMARTCARD_DEVICE* smartcard, GetAttrib_Call* call)
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
BYTE* pb;
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "GetAttrib_Call {");
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
pb = (BYTE*) &(call->hContext.pbContext);
|
|
|
|
|
|
|
|
if (call->hContext.cbContext > 4)
|
2014-04-11 22:01:42 +04:00
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->hContext.cbContext);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], call->hContext.cbContext);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
pb = (BYTE*) &(call->hCard.pbHandle);
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
if (call->hCard.cbHandle > 4)
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->hCard.cbHandle);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-12 00:27:01 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], call->hCard.cbHandle);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "dwAttrId: %s (0x%08X) fpbAttrIsNULL: %d cbAttrLen: 0x%08X",
|
|
|
|
SCardGetAttributeString(call->dwAttrId), call->dwAttrId, call->fpbAttrIsNULL, call->cbAttrLen);
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
}
|
|
|
|
|
2014-04-07 09:19:58 +04:00
|
|
|
UINT32 smartcard_pack_get_attrib_return(SMARTCARD_DEVICE* smartcard, wStream* s, GetAttrib_Return* ret)
|
|
|
|
{
|
2014-04-13 23:50:51 +04:00
|
|
|
Stream_EnsureRemainingCapacity(s, ret->cbAttrLen + 32);
|
|
|
|
|
2014-04-07 09:19:58 +04:00
|
|
|
Stream_Write_UINT32(s, ret->cbAttrLen); /* cbAttrLen (4 bytes) */
|
2014-04-08 01:17:26 +04:00
|
|
|
Stream_Write_UINT32(s, 0x00020080); /* pbAttrNdrPtr (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, ret->cbAttrLen); /* pbAttrNdrCount (4 bytes) */
|
2014-04-07 09:19:58 +04:00
|
|
|
|
|
|
|
if (!ret->pbAttr)
|
|
|
|
Stream_Zero(s, ret->cbAttrLen); /* pbAttr */
|
|
|
|
else
|
|
|
|
Stream_Write(s, ret->pbAttr, ret->cbAttrLen); /* pbAttr */
|
|
|
|
|
2014-04-08 19:32:48 +04:00
|
|
|
smartcard_pack_write_size_align(smartcard, s, ret->cbAttrLen, 4);
|
2014-04-07 09:19:58 +04:00
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-11 22:01:42 +04:00
|
|
|
void smartcard_trace_get_attrib_return(SMARTCARD_DEVICE* smartcard, GetAttrib_Return* ret, DWORD dwAttrId)
|
|
|
|
{
|
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "GetAttrib_Return {");
|
|
|
|
|
2014-04-14 00:48:32 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "ReturnCode: %s (0x%08X)",
|
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
2014-04-11 22:01:42 +04:00
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "dwAttrId: %s (0x%08X) cbAttrLen: 0x%08X",
|
|
|
|
SCardGetAttributeString(dwAttrId), dwAttrId, ret->cbAttrLen);
|
|
|
|
|
|
|
|
if (dwAttrId == SCARD_ATTR_VENDOR_NAME)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "pbAttr: %.*s", ret->cbAttrLen, (char*) ret->pbAttr);
|
|
|
|
}
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
}
|
|
|
|
|
2014-04-07 05:09:49 +04:00
|
|
|
UINT32 smartcard_unpack_control_call(SMARTCARD_DEVICE* smartcard, wStream* s, Control_Call* call)
|
|
|
|
{
|
|
|
|
UINT32 status;
|
|
|
|
UINT32 length;
|
|
|
|
|
|
|
|
call->pvInBuffer = NULL;
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->hContext));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2014-04-07 05:09:49 +04:00
|
|
|
status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->hCard));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 20)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Control_Call is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, call->dwControlCode); /* dwControlCode (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->cbInBufferSize); /* cbInBufferSize (4 bytes) */
|
|
|
|
Stream_Seek_UINT32(s); /* pvInBufferNdrPtr (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->fpvOutBufferIsNULL); /* fpvOutBufferIsNULL (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->cbOutBufferSize); /* cbOutBufferSize (4 bytes) */
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->hContext));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2014-04-07 05:09:49 +04:00
|
|
|
status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->hCard));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
if (call->cbInBufferSize)
|
|
|
|
{
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Control_Call is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, length); /* Length (4 bytes) */
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < length)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Control_Call is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
call->pvInBuffer = (BYTE*) malloc(length);
|
2014-04-27 23:45:36 +04:00
|
|
|
|
|
|
|
if (!call->pvInBuffer)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Control_Call out of memory error (call->pvInBuffer)");
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2014-04-07 05:09:49 +04:00
|
|
|
call->cbInBufferSize = length;
|
|
|
|
|
|
|
|
Stream_Read(s, call->pvInBuffer, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-14 00:48:32 +04:00
|
|
|
void smartcard_trace_control_call(SMARTCARD_DEVICE* smartcard, Control_Call* call)
|
|
|
|
{
|
|
|
|
BYTE* pb;
|
|
|
|
|
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "Control_Call {");
|
|
|
|
|
|
|
|
pb = (BYTE*) &(call->hContext.pbContext);
|
|
|
|
|
|
|
|
if (call->hContext.cbContext > 4)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->hContext.cbContext);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], call->hContext.cbContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
pb = (BYTE*) &(call->hCard.pbHandle);
|
|
|
|
|
|
|
|
if (call->hCard.cbHandle > 4)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->hCard.cbHandle);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], call->hCard.cbHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG,
|
|
|
|
"dwControlCode: 0x%08X cbInBufferSize: %d fpvOutBufferIsNULL: %d cbOutBufferSize: %d",
|
|
|
|
call->dwControlCode, call->cbInBufferSize, call->fpvOutBufferIsNULL, call->cbOutBufferSize);
|
|
|
|
|
|
|
|
if (call->pvInBuffer)
|
|
|
|
{
|
|
|
|
char* szInBuffer = winpr_BinToHexString(call->pvInBuffer, call->cbInBufferSize, TRUE);
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "pbInBuffer: %s", szInBuffer);
|
|
|
|
free(szInBuffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "pvInBuffer: null");
|
|
|
|
}
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
}
|
|
|
|
|
2014-04-07 09:19:58 +04:00
|
|
|
UINT32 smartcard_pack_control_return(SMARTCARD_DEVICE* smartcard, wStream* s, Control_Return* ret)
|
|
|
|
{
|
2014-04-13 23:50:51 +04:00
|
|
|
Stream_EnsureRemainingCapacity(s, ret->cbOutBufferSize + 32);
|
|
|
|
|
2014-04-07 09:19:58 +04:00
|
|
|
Stream_Write_UINT32(s, ret->cbOutBufferSize); /* cbOutBufferSize (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, 0x00020040); /* pvOutBufferPointer (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, ret->cbOutBufferSize); /* pvOutBufferLength (4 bytes) */
|
|
|
|
|
|
|
|
if (ret->cbOutBufferSize > 0)
|
|
|
|
{
|
|
|
|
Stream_Write(s, ret->pvOutBuffer, ret->cbOutBufferSize); /* pvOutBuffer */
|
2014-04-08 19:32:48 +04:00
|
|
|
smartcard_pack_write_size_align(smartcard, s, ret->cbOutBufferSize, 4);
|
2014-04-07 09:19:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-04-14 00:48:32 +04:00
|
|
|
void smartcard_trace_control_return(SMARTCARD_DEVICE* smartcard, Control_Return* ret)
|
|
|
|
{
|
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "Control_Return {");
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "ReturnCode: %s (0x%08X)",
|
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "cbOutBufferSize: %d", ret->cbOutBufferSize);
|
|
|
|
|
|
|
|
if (ret->pvOutBuffer)
|
|
|
|
{
|
|
|
|
char* szOutBuffer = winpr_BinToHexString(ret->pvOutBuffer, ret->cbOutBufferSize, TRUE);
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "pvOutBuffer: %s", szOutBuffer);
|
|
|
|
free(szOutBuffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "pvOutBuffer: null");
|
|
|
|
}
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
}
|
|
|
|
|
2014-04-07 05:09:49 +04:00
|
|
|
UINT32 smartcard_unpack_transmit_call(SMARTCARD_DEVICE* smartcard, wStream* s, Transmit_Call* call)
|
|
|
|
{
|
|
|
|
UINT32 status;
|
|
|
|
UINT32 length;
|
|
|
|
BYTE* pbExtraBytes;
|
|
|
|
UINT32 pbExtraBytesNdrPtr;
|
|
|
|
UINT32 pbSendBufferNdrPtr;
|
|
|
|
UINT32 pioRecvPciNdrPtr;
|
|
|
|
SCardIO_Request ioSendPci;
|
|
|
|
SCardIO_Request ioRecvPci;
|
|
|
|
|
|
|
|
call->pioSendPci = NULL;
|
|
|
|
call->pioRecvPci = NULL;
|
|
|
|
call->pbSendBuffer = NULL;
|
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->hContext));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2014-04-07 05:09:49 +04:00
|
|
|
status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->hCard));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 32)
|
|
|
|
{
|
2014-04-07 20:53:38 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Transmit_Call is too short: Actual: %d, Expected: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s), 32);
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, ioSendPci.dwProtocol); /* dwProtocol (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, ioSendPci.cbExtraBytes); /* cbExtraBytes (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, pbExtraBytesNdrPtr); /* pbExtraBytesNdrPtr (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->cbSendLength); /* cbSendLength (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, pbSendBufferNdrPtr); /* pbSendBufferNdrPtr (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, pioRecvPciNdrPtr); /* pioRecvPciNdrPtr (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->fpbRecvBufferIsNULL); /* fpbRecvBufferIsNULL (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->cbRecvLength); /* cbRecvLength (4 bytes) */
|
|
|
|
|
2014-04-08 01:17:26 +04:00
|
|
|
if (ioSendPci.cbExtraBytes > 1024)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Transmit_Call ioSendPci.cbExtraBytes is out of bounds: %d (max: %d)",
|
|
|
|
(int) ioSendPci.cbExtraBytes, 1024);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (call->cbSendLength > 66560)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Transmit_Call cbSendLength is out of bounds: %d (max: %d)",
|
|
|
|
(int) ioSendPci.cbExtraBytes, 66560);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2014-04-07 21:39:47 +04:00
|
|
|
|
2014-04-12 00:27:01 +04:00
|
|
|
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->hContext));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2014-04-07 05:09:49 +04:00
|
|
|
status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->hCard));
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2014-04-08 01:17:26 +04:00
|
|
|
if (ioSendPci.cbExtraBytes && !pbExtraBytesNdrPtr)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN,
|
|
|
|
"Transmit_Call cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2014-04-07 05:09:49 +04:00
|
|
|
if (pbExtraBytesNdrPtr)
|
|
|
|
{
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Transmit_Call is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, length); /* Length (4 bytes) */
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < ioSendPci.cbExtraBytes)
|
|
|
|
{
|
2014-04-07 20:53:38 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_WARN,
|
|
|
|
"Transmit_Call is too short: Actual: %d, Expected: %d (ioSendPci.cbExtraBytes)",
|
|
|
|
(int) Stream_GetRemainingLength(s), (int) ioSendPci.cbExtraBytes);
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ioSendPci.pbExtraBytes = (BYTE*) Stream_Pointer(s);
|
|
|
|
|
|
|
|
call->pioSendPci = (LPSCARD_IO_REQUEST) malloc(sizeof(SCARD_IO_REQUEST) + ioSendPci.cbExtraBytes);
|
|
|
|
|
|
|
|
if (!call->pioSendPci)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Transmit_Call out of memory error (pioSendPci)");
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_NO_MEMORY;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
|
|
|
|
call->pioSendPci->cbPciLength = ioSendPci.cbExtraBytes + sizeof(SCARD_IO_REQUEST);
|
|
|
|
|
|
|
|
pbExtraBytes = &((BYTE*) call->pioSendPci)[sizeof(SCARD_IO_REQUEST)];
|
2014-04-10 01:44:39 +04:00
|
|
|
Stream_Read(s, pbExtraBytes, ioSendPci.cbExtraBytes);
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-07 21:39:47 +04:00
|
|
|
call->pioSendPci = (LPSCARD_IO_REQUEST) calloc(1, sizeof(SCARD_IO_REQUEST));
|
2014-04-07 05:09:49 +04:00
|
|
|
|
|
|
|
if (!call->pioSendPci)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Transmit_Call out of memory error (pioSendPci)");
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_NO_MEMORY;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
2014-04-08 01:17:26 +04:00
|
|
|
call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
|
2014-04-07 05:09:49 +04:00
|
|
|
call->pioSendPci->cbPciLength = sizeof(SCARD_IO_REQUEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pbSendBufferNdrPtr)
|
|
|
|
{
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Transmit_Call is too short: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, length); /* Length (4 bytes) */
|
|
|
|
|
2014-04-13 23:50:51 +04:00
|
|
|
if (length != call->cbSendLength)
|
2014-04-07 05:09:49 +04:00
|
|
|
{
|
2014-04-07 20:53:38 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_WARN,
|
|
|
|
"Transmit_Call unexpected length: Actual: %d, Expected: %d (cbSendLength)",
|
2014-04-07 05:09:49 +04:00
|
|
|
(int) length, (int) call->cbSendLength);
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < call->cbSendLength)
|
|
|
|
{
|
2014-04-07 20:53:38 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_WARN,
|
|
|
|
"Transmit_Call is too short: Actual: %d, Expected: %d (cbSendLength)",
|
|
|
|
(int) Stream_GetRemainingLength(s), (int) call->cbSendLength);
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
call->pbSendBuffer = (BYTE*) malloc(call->cbSendLength);
|
|
|
|
|
|
|
|
if (!call->pbSendBuffer)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Transmit_Call out of memory error (pbSendBuffer)");
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_NO_MEMORY;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read(s, call->pbSendBuffer, call->cbSendLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pioRecvPciNdrPtr)
|
|
|
|
{
|
2014-04-07 21:39:47 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
2014-04-07 05:09:49 +04:00
|
|
|
{
|
2014-04-07 20:53:38 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Transmit_Call is too short: Actual: %d, Expected: %d",
|
|
|
|
(int) Stream_GetRemainingLength(s), 16);
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, length); /* Length (4 bytes) */
|
|
|
|
|
2014-04-16 23:24:56 +04:00
|
|
|
Stream_Read_UINT32(s, ioRecvPci.dwProtocol); /* dwProtocol (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, ioRecvPci.cbExtraBytes); /* cbExtraBytes (4 bytes) */
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2014-04-08 01:17:26 +04:00
|
|
|
if (ioRecvPci.cbExtraBytes > 1024)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Transmit_Call ioRecvPci.cbExtraBytes is out of bounds: %d (max: %d)",
|
|
|
|
(int) ioSendPci.cbExtraBytes, 1024);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2014-04-07 05:09:49 +04:00
|
|
|
if (length < ioRecvPci.cbExtraBytes)
|
|
|
|
{
|
2014-04-07 20:53:38 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_WARN,
|
|
|
|
"Transmit_Call unexpected length: Actual: %d, Expected: %d (ioRecvPci.cbExtraBytes)",
|
2014-04-07 05:09:49 +04:00
|
|
|
(int) length, (int) ioRecvPci.cbExtraBytes);
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < ioRecvPci.cbExtraBytes)
|
|
|
|
{
|
2014-04-07 20:53:38 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_WARN,
|
|
|
|
"Transmit_Call is too short: Actual: %d, Expected: %d (ioRecvPci.cbExtraBytes)",
|
|
|
|
(int) Stream_GetRemainingLength(s), (int) ioRecvPci.cbExtraBytes);
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ioRecvPci.pbExtraBytes = (BYTE*) Stream_Pointer(s);
|
|
|
|
|
|
|
|
call->pioRecvPci = (LPSCARD_IO_REQUEST) malloc(sizeof(SCARD_IO_REQUEST) + ioRecvPci.cbExtraBytes);
|
|
|
|
|
2014-04-08 01:17:26 +04:00
|
|
|
if (!call->pioRecvPci)
|
2014-04-07 05:09:49 +04:00
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_WARN, "Transmit_Call out of memory error (pioRecvPci)");
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_NO_MEMORY;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
|
|
|
|
call->pioRecvPci->cbPciLength = ioRecvPci.cbExtraBytes + sizeof(SCARD_IO_REQUEST);
|
|
|
|
|
|
|
|
pbExtraBytes = &((BYTE*) call->pioRecvPci)[sizeof(SCARD_IO_REQUEST)];
|
2014-04-10 01:44:39 +04:00
|
|
|
Stream_Read(s, pbExtraBytes, ioRecvPci.cbExtraBytes);
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
2014-04-07 07:08:40 +04:00
|
|
|
|
2014-04-13 23:50:51 +04:00
|
|
|
void smartcard_trace_transmit_call(SMARTCARD_DEVICE* smartcard, Transmit_Call* call)
|
|
|
|
{
|
|
|
|
BYTE* pb;
|
|
|
|
UINT32 cbExtraBytes;
|
|
|
|
BYTE* pbExtraBytes;
|
|
|
|
|
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "Transmit_Call {");
|
|
|
|
|
|
|
|
pb = (BYTE*) &(call->hContext.pbContext);
|
|
|
|
|
|
|
|
if (call->hContext.cbContext > 4)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->hContext.cbContext);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], call->hContext.cbContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
pb = (BYTE*) &(call->hCard.pbHandle);
|
|
|
|
|
|
|
|
if (call->hCard.cbHandle > 4)
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->hCard.cbHandle);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%02X%02X%02X%02X (%d)",
|
|
|
|
pb[0], pb[1], pb[2], pb[3], call->hCard.cbHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (call->pioSendPci)
|
|
|
|
{
|
|
|
|
cbExtraBytes = call->pioSendPci->cbPciLength - sizeof(SCARD_IO_REQUEST);
|
|
|
|
pbExtraBytes = &((BYTE*) call->pioSendPci)[sizeof(SCARD_IO_REQUEST)];
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "pioSendPci: dwProtocol: %d cbExtraBytes: %d",
|
|
|
|
call->pioSendPci->dwProtocol, cbExtraBytes);
|
|
|
|
|
|
|
|
if (cbExtraBytes)
|
|
|
|
{
|
|
|
|
char* szExtraBytes = winpr_BinToHexString(pbExtraBytes, cbExtraBytes, TRUE);
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "pbExtraBytes: %s", szExtraBytes);
|
|
|
|
free(szExtraBytes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "pioSendPci: null");
|
|
|
|
}
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "cbSendLength: %d", call->cbSendLength);
|
|
|
|
|
|
|
|
if (call->pbSendBuffer)
|
|
|
|
{
|
|
|
|
char* szSendBuffer = winpr_BinToHexString(call->pbSendBuffer, call->cbSendLength, TRUE);
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "pbSendBuffer: %s", szSendBuffer);
|
|
|
|
free(szSendBuffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "pbSendBuffer: null");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (call->pioRecvPci)
|
|
|
|
{
|
|
|
|
cbExtraBytes = call->pioRecvPci->cbPciLength - sizeof(SCARD_IO_REQUEST);
|
|
|
|
pbExtraBytes = &((BYTE*) call->pioRecvPci)[sizeof(SCARD_IO_REQUEST)];
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "pioRecvPci: dwProtocol: %d cbExtraBytes: %d",
|
|
|
|
call->pioRecvPci->dwProtocol, cbExtraBytes);
|
|
|
|
|
|
|
|
if (cbExtraBytes)
|
|
|
|
{
|
|
|
|
char* szExtraBytes = winpr_BinToHexString(pbExtraBytes, cbExtraBytes, TRUE);
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "pbExtraBytes: %s", szExtraBytes);
|
|
|
|
free(szExtraBytes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "pioRecvPci: null");
|
|
|
|
}
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "fpbRecvBufferIsNULL: %d cbRecvLength: 0x%08X",
|
|
|
|
call->fpbRecvBufferIsNULL, call->cbRecvLength);
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
}
|
|
|
|
|
2014-04-07 07:08:40 +04:00
|
|
|
UINT32 smartcard_pack_transmit_return(SMARTCARD_DEVICE* smartcard, wStream* s, Transmit_Return* ret)
|
|
|
|
{
|
2014-04-09 05:36:47 +04:00
|
|
|
UINT32 cbExtraBytes;
|
|
|
|
BYTE* pbExtraBytes;
|
|
|
|
UINT32 pioRecvPciNdrPtr;
|
|
|
|
UINT32 pbRecvBufferNdrPtr;
|
|
|
|
|
|
|
|
if (!ret->pbRecvBuffer)
|
|
|
|
ret->cbRecvLength = 0;
|
|
|
|
|
|
|
|
pioRecvPciNdrPtr = (ret->pioRecvPci) ? 0x00020200 : 0;
|
|
|
|
pbRecvBufferNdrPtr = (ret->pbRecvBuffer) ? 0x00020400 : 0;
|
2014-04-07 07:08:40 +04:00
|
|
|
|
2014-04-09 05:36:47 +04:00
|
|
|
Stream_Write_UINT32(s, pioRecvPciNdrPtr); /* pioRecvPciNdrPtr (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, ret->cbRecvLength); /* cbRecvLength (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, pbRecvBufferNdrPtr); /* pbRecvBufferNdrPtr (4 bytes) */
|
|
|
|
|
|
|
|
if (pioRecvPciNdrPtr)
|
2014-04-07 20:53:38 +04:00
|
|
|
{
|
2014-04-09 05:36:47 +04:00
|
|
|
cbExtraBytes = ret->pioRecvPci->cbPciLength - sizeof(SCARD_IO_REQUEST);
|
|
|
|
pbExtraBytes = &((BYTE*) ret->pioRecvPci)[sizeof(SCARD_IO_REQUEST)];
|
|
|
|
|
|
|
|
Stream_EnsureRemainingCapacity(s, cbExtraBytes + 16);
|
|
|
|
Stream_Write_UINT32(s, cbExtraBytes); /* Length (4 bytes) */
|
2014-04-16 23:24:56 +04:00
|
|
|
Stream_Write_UINT32(s, ret->pioRecvPci->dwProtocol); /* dwProtocol (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, cbExtraBytes); /* cbExtraBytes (4 bytes) */
|
2014-04-09 05:36:47 +04:00
|
|
|
Stream_Write(s, pbExtraBytes, cbExtraBytes);
|
|
|
|
smartcard_pack_write_size_align(smartcard, s, cbExtraBytes, 4);
|
2014-04-07 20:53:38 +04:00
|
|
|
}
|
|
|
|
|
2014-04-09 05:36:47 +04:00
|
|
|
if (pbRecvBufferNdrPtr)
|
2014-04-07 07:08:40 +04:00
|
|
|
{
|
2014-04-09 05:36:47 +04:00
|
|
|
Stream_EnsureRemainingCapacity(s, ret->cbRecvLength + 16);
|
2014-04-07 07:08:40 +04:00
|
|
|
Stream_Write_UINT32(s, ret->cbRecvLength); /* pbRecvBufferNdrLen (4 bytes) */
|
|
|
|
Stream_Write(s, ret->pbRecvBuffer, ret->cbRecvLength);
|
2014-04-08 19:32:48 +04:00
|
|
|
smartcard_pack_write_size_align(smartcard, s, ret->cbRecvLength, 4);
|
2014-04-07 07:08:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
2014-04-10 01:44:39 +04:00
|
|
|
|
2014-04-13 23:50:51 +04:00
|
|
|
void smartcard_trace_transmit_return(SMARTCARD_DEVICE* smartcard, Transmit_Return* ret)
|
|
|
|
{
|
|
|
|
UINT32 cbExtraBytes;
|
|
|
|
BYTE* pbExtraBytes;
|
|
|
|
|
|
|
|
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "Transmit_Return {");
|
|
|
|
|
2014-04-14 00:48:32 +04:00
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "ReturnCode: %s (0x%08X)",
|
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
2014-04-13 23:50:51 +04:00
|
|
|
|
|
|
|
if (ret->pioRecvPci)
|
|
|
|
{
|
|
|
|
cbExtraBytes = ret->pioRecvPci->cbPciLength - sizeof(SCARD_IO_REQUEST);
|
|
|
|
pbExtraBytes = &((BYTE*) ret->pioRecvPci)[sizeof(SCARD_IO_REQUEST)];
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "pioRecvPci: dwProtocol: %d cbExtraBytes: %d",
|
|
|
|
ret->pioRecvPci->dwProtocol, cbExtraBytes);
|
|
|
|
|
|
|
|
if (cbExtraBytes)
|
|
|
|
{
|
|
|
|
char* szExtraBytes = winpr_BinToHexString(pbExtraBytes, cbExtraBytes, TRUE);
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "pbExtraBytes: %s", szExtraBytes);
|
|
|
|
free(szExtraBytes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "pioRecvPci: null");
|
|
|
|
}
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "cbRecvLength: %d", ret->cbRecvLength);
|
|
|
|
|
|
|
|
if (ret->pbRecvBuffer)
|
|
|
|
{
|
|
|
|
char* szRecvBuffer = winpr_BinToHexString(ret->pbRecvBuffer, ret->cbRecvLength, TRUE);
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "pbRecvBuffer: %s", szRecvBuffer);
|
|
|
|
free(szRecvBuffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "pbRecvBuffer: null");
|
|
|
|
}
|
|
|
|
|
|
|
|
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
|
|
|
|
}
|