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>
|
2015-07-03 14:09:03 +03:00
|
|
|
* Copyright 2015 Thincast Technologies GmbH
|
|
|
|
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
2020-02-17 16:07:20 +03:00
|
|
|
* Copyright 2020 Armin Novak <armin.novak@thincast.com>
|
|
|
|
* Copyright 2020 Thincast Technologies GmbH
|
2014-04-04 02:47:18 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#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"
|
|
|
|
|
2020-02-19 10:01:20 +03:00
|
|
|
static const DWORD g_LogLevel = WLOG_DEBUG;
|
2020-02-17 16:07:20 +03:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
#define smartcard_unpack_redir_scard_context(smartcard, s, context, index) \
|
|
|
|
smartcard_unpack_redir_scard_context_((smartcard), (s), (context), (index), __FILE__, \
|
|
|
|
__FUNCTION__, __LINE__)
|
|
|
|
#define smartcard_unpack_redir_scard_handle(smartcard, s, context, index) \
|
|
|
|
smartcard_unpack_redir_scard_handle_((smartcard), (s), (context), (index), __FILE__, \
|
|
|
|
__FUNCTION__, __LINE__)
|
|
|
|
|
|
|
|
static LONG smartcard_unpack_redir_scard_context_(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
REDIR_SCARDCONTEXT* context, UINT32* index,
|
|
|
|
const char* file, const char* function, int line);
|
2020-01-13 12:51:22 +03:00
|
|
|
static LONG smartcard_pack_redir_scard_context(SMARTCARD_DEVICE* smartcard, wStream* s,
|
2020-02-17 16:07:20 +03:00
|
|
|
const REDIR_SCARDCONTEXT* context, DWORD* index);
|
2020-02-13 19:26:15 +03:00
|
|
|
static LONG smartcard_unpack_redir_scard_handle_(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
REDIR_SCARDHANDLE* handle, UINT32* index,
|
|
|
|
const char* file, const char* function, int line);
|
2020-01-13 12:51:22 +03:00
|
|
|
static LONG smartcard_pack_redir_scard_handle(SMARTCARD_DEVICE* smartcard, wStream* s,
|
2020-02-17 16:07:20 +03:00
|
|
|
const REDIR_SCARDHANDLE* handle, DWORD* index);
|
2020-01-13 12:51:22 +03:00
|
|
|
static LONG smartcard_unpack_redir_scard_context_ref(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
REDIR_SCARDCONTEXT* context);
|
|
|
|
static LONG smartcard_pack_redir_scard_context_ref(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
const REDIR_SCARDCONTEXT* context);
|
|
|
|
|
|
|
|
static LONG smartcard_unpack_redir_scard_handle_ref(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
REDIR_SCARDHANDLE* handle);
|
|
|
|
static LONG smartcard_pack_redir_scard_handle_ref(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
const REDIR_SCARDHANDLE* handle);
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
NDR_PTR_FULL,
|
|
|
|
NDR_PTR_SIMPLE,
|
|
|
|
NDR_PTR_FIXED
|
|
|
|
} ndr_ptr_t;
|
|
|
|
|
|
|
|
/* Reads a NDR pointer and checks if the value read has the expected relative
|
|
|
|
* addressing */
|
|
|
|
#define smartcard_ndr_pointer_read(s, index, ptr) \
|
|
|
|
smartcard_ndr_pointer_read_((s), (index), (ptr), __FILE__, __FUNCTION__, __LINE__)
|
|
|
|
static BOOL smartcard_ndr_pointer_read_(wStream* s, UINT32* index, UINT32* ptr, const char* file,
|
|
|
|
const char* fkt, int line)
|
|
|
|
{
|
|
|
|
const UINT32 expect = 0x20000 + (*index) * 4;
|
|
|
|
UINT32 ndrPtr;
|
|
|
|
WINPR_UNUSED(file);
|
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, ndrPtr); /* mszGroupsNdrPtr (4 bytes) */
|
|
|
|
if (ptr)
|
|
|
|
*ptr = ndrPtr;
|
|
|
|
if (expect != ndrPtr)
|
|
|
|
{
|
|
|
|
/* Allow NULL pointer if we read the result */
|
|
|
|
if (ptr && (ndrPtr == 0))
|
|
|
|
return TRUE;
|
|
|
|
WLog_WARN(TAG, "[%s:%d] Read context pointer 0x%08" PRIx32 ", expected 0x%08" PRIx32, fkt,
|
|
|
|
line, ndrPtr, expect);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*index) = (*index) + 1;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_ndr_read(wStream* s, BYTE** data, size_t min, size_t elementSize,
|
|
|
|
ndr_ptr_t type)
|
2020-01-24 15:41:27 +03:00
|
|
|
{
|
2020-05-12 18:16:14 +03:00
|
|
|
size_t len = 0, offset, len2;
|
2020-01-24 15:41:27 +03:00
|
|
|
void* r;
|
2020-05-12 18:16:14 +03:00
|
|
|
size_t required = 0;
|
2020-01-24 15:41:27 +03:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case NDR_PTR_FULL:
|
|
|
|
required = 12;
|
|
|
|
break;
|
|
|
|
case NDR_PTR_SIMPLE:
|
|
|
|
required = 4;
|
|
|
|
break;
|
|
|
|
case NDR_PTR_FIXED:
|
|
|
|
required = min;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < required)
|
2020-01-24 15:41:27 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Short data while trying to read NDR pointer, expected 4, got %" PRIu32,
|
|
|
|
Stream_GetRemainingLength(s));
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
2020-02-13 19:26:15 +03:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case NDR_PTR_FULL:
|
|
|
|
Stream_Read_UINT32(s, len);
|
|
|
|
Stream_Read_UINT32(s, offset);
|
|
|
|
Stream_Read_UINT32(s, len2);
|
|
|
|
if (len != offset + len2)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG,
|
|
|
|
"Invalid data when reading full NDR pointer: total=%" PRIu32
|
|
|
|
", offset=%" PRIu32 ", remaining=%" PRIu32,
|
|
|
|
len, offset, len2);
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NDR_PTR_SIMPLE:
|
|
|
|
Stream_Read_UINT32(s, len);
|
|
|
|
|
|
|
|
if ((len != min) && (min > 0))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG,
|
|
|
|
"Invalid data when reading simple NDR pointer: total=%" PRIu32
|
|
|
|
", expected=%" PRIu32,
|
|
|
|
len, min);
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NDR_PTR_FIXED:
|
|
|
|
len = (UINT32)min;
|
|
|
|
break;
|
|
|
|
}
|
2020-01-24 15:41:27 +03:00
|
|
|
|
|
|
|
if (min > len)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Invalid length read from NDR pointer, minimum %" PRIu32 ", got %" PRIu32,
|
|
|
|
min, len);
|
|
|
|
return STATUS_DATA_ERROR;
|
|
|
|
}
|
|
|
|
|
2020-04-29 16:55:51 +03:00
|
|
|
if (len > SIZE_MAX / 2)
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) / elementSize < len)
|
2020-01-24 15:41:27 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG,
|
|
|
|
"Short data while trying to read data from NDR pointer, expected %" PRIu32
|
|
|
|
", got %" PRIu32,
|
|
|
|
len, Stream_GetRemainingLength(s));
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
2020-04-29 16:55:51 +03:00
|
|
|
len *= elementSize;
|
2020-01-24 15:41:27 +03:00
|
|
|
|
|
|
|
r = calloc(len + 1, sizeof(CHAR));
|
|
|
|
if (!r)
|
|
|
|
return SCARD_E_NO_MEMORY;
|
|
|
|
Stream_Read(s, r, len);
|
2020-02-13 19:26:15 +03:00
|
|
|
smartcard_unpack_read_size_align(NULL, s, len, 4);
|
2020-01-24 15:41:27 +03:00
|
|
|
*data = r;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
static BOOL smartcard_ndr_pointer_write(wStream* s, UINT32* index, DWORD length)
|
|
|
|
{
|
|
|
|
const UINT32 ndrPtr = 0x20000 + (*index) * 4;
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 4))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (length > 0)
|
|
|
|
{
|
|
|
|
Stream_Write_UINT32(s, ndrPtr); /* mszGroupsNdrPtr (4 bytes) */
|
|
|
|
(*index) = (*index) + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Stream_Write_UINT32(s, 0);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_ndr_write(wStream* s, const BYTE* data, UINT32 size, UINT32 elementSize,
|
|
|
|
ndr_ptr_t type)
|
|
|
|
{
|
|
|
|
const UINT32 offset = 0;
|
|
|
|
const UINT32 len = size;
|
|
|
|
const UINT32 dataLen = size * elementSize;
|
|
|
|
size_t required;
|
|
|
|
|
|
|
|
if (size == 0)
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case NDR_PTR_FULL:
|
|
|
|
required = 12;
|
|
|
|
break;
|
|
|
|
case NDR_PTR_SIMPLE:
|
|
|
|
required = 4;
|
|
|
|
break;
|
|
|
|
case NDR_PTR_FIXED:
|
|
|
|
required = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-02-18 13:50:11 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, required + dataLen + 4))
|
2020-02-17 16:07:20 +03:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case NDR_PTR_FULL:
|
|
|
|
Stream_Write_UINT32(s, len);
|
|
|
|
Stream_Write_UINT32(s, offset);
|
|
|
|
Stream_Write_UINT32(s, len);
|
|
|
|
break;
|
|
|
|
case NDR_PTR_SIMPLE:
|
|
|
|
Stream_Write_UINT32(s, len);
|
|
|
|
break;
|
|
|
|
case NDR_PTR_FIXED:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data)
|
|
|
|
Stream_Write(s, data, dataLen);
|
|
|
|
else
|
|
|
|
Stream_Zero(s, dataLen);
|
2020-02-18 13:50:11 +03:00
|
|
|
return smartcard_pack_write_size_align(NULL, s, len, 4);
|
2020-02-17 16:07:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_ndr_write_state(wStream* s, const ReaderState_Return* data, UINT32 size,
|
|
|
|
ndr_ptr_t type)
|
|
|
|
{
|
2021-02-06 17:22:38 +03:00
|
|
|
union
|
|
|
|
{
|
2020-02-17 16:07:20 +03:00
|
|
|
const ReaderState_Return* reader;
|
|
|
|
const BYTE* data;
|
|
|
|
} cnv;
|
|
|
|
|
|
|
|
cnv.reader = data;
|
|
|
|
return smartcard_ndr_write(s, cnv.data, size, sizeof(ReaderState_Return), type);
|
|
|
|
}
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
static LONG smartcard_ndr_read_atrmask(wStream* s, LocateCards_ATRMask** data, size_t min,
|
|
|
|
ndr_ptr_t type)
|
|
|
|
{
|
2021-02-06 17:22:38 +03:00
|
|
|
union
|
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
LocateCards_ATRMask** ppc;
|
|
|
|
BYTE** ppv;
|
|
|
|
} u;
|
|
|
|
u.ppc = data;
|
|
|
|
return smartcard_ndr_read(s, u.ppv, min, sizeof(LocateCards_ATRMask), type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_ndr_read_fixed_string_a(wStream* s, CHAR** data, size_t min, ndr_ptr_t type)
|
|
|
|
{
|
2021-02-06 17:22:38 +03:00
|
|
|
union
|
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
CHAR** ppc;
|
|
|
|
BYTE** ppv;
|
|
|
|
} u;
|
|
|
|
u.ppc = data;
|
|
|
|
return smartcard_ndr_read(s, u.ppv, min, sizeof(CHAR), type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_ndr_read_fixed_string_w(wStream* s, WCHAR** data, size_t min, ndr_ptr_t type)
|
|
|
|
{
|
2021-02-06 17:22:38 +03:00
|
|
|
union
|
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
WCHAR** ppc;
|
|
|
|
BYTE** ppv;
|
|
|
|
} u;
|
|
|
|
u.ppc = data;
|
|
|
|
return smartcard_ndr_read(s, u.ppv, min, sizeof(WCHAR), type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_ndr_read_a(wStream* s, CHAR** data, ndr_ptr_t type)
|
2020-01-24 15:41:27 +03:00
|
|
|
{
|
2021-02-06 17:22:38 +03:00
|
|
|
union
|
|
|
|
{
|
2020-01-24 15:41:27 +03:00
|
|
|
CHAR** ppc;
|
|
|
|
BYTE** ppv;
|
|
|
|
} u;
|
|
|
|
u.ppc = data;
|
2020-02-13 19:26:15 +03:00
|
|
|
return smartcard_ndr_read(s, u.ppv, 0, sizeof(CHAR), type);
|
2020-01-24 15:41:27 +03:00
|
|
|
}
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
static LONG smartcard_ndr_read_w(wStream* s, WCHAR** data, ndr_ptr_t type)
|
2020-01-24 15:41:27 +03:00
|
|
|
{
|
2021-02-06 17:22:38 +03:00
|
|
|
union
|
|
|
|
{
|
2020-01-24 15:41:27 +03:00
|
|
|
WCHAR** ppc;
|
|
|
|
BYTE** ppv;
|
|
|
|
} u;
|
|
|
|
u.ppc = data;
|
2020-02-13 19:26:15 +03:00
|
|
|
return smartcard_ndr_read(s, u.ppv, 0, sizeof(WCHAR), type);
|
2020-01-24 15:41:27 +03:00
|
|
|
}
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
static LONG smartcard_ndr_read_u(wStream* s, UUID** data)
|
2020-01-24 15:41:27 +03:00
|
|
|
{
|
2021-02-06 17:22:38 +03:00
|
|
|
union
|
|
|
|
{
|
2020-01-24 15:41:27 +03:00
|
|
|
UUID** ppc;
|
|
|
|
BYTE** ppv;
|
|
|
|
} u;
|
|
|
|
u.ppc = data;
|
2020-02-13 19:26:15 +03:00
|
|
|
return smartcard_ndr_read(s, u.ppv, 1, sizeof(UUID), NDR_PTR_FIXED);
|
2020-01-24 15:41:27 +03:00
|
|
|
}
|
|
|
|
|
2020-01-23 12:07:54 +03:00
|
|
|
static char* smartcard_convert_string_list(const void* in, size_t bytes, BOOL unicode)
|
|
|
|
{
|
|
|
|
size_t index, length;
|
2021-02-06 17:22:38 +03:00
|
|
|
union
|
|
|
|
{
|
2020-01-23 12:07:54 +03:00
|
|
|
const void* pv;
|
|
|
|
const char* sz;
|
|
|
|
const WCHAR* wz;
|
|
|
|
} string;
|
|
|
|
char* mszA = NULL;
|
|
|
|
|
|
|
|
string.pv = in;
|
|
|
|
|
2020-02-10 16:28:38 +03:00
|
|
|
if (bytes < 1)
|
|
|
|
return NULL;
|
|
|
|
|
2020-01-23 12:07:54 +03:00
|
|
|
if (unicode)
|
|
|
|
{
|
|
|
|
length = (bytes / 2);
|
|
|
|
if (ConvertFromUnicode(CP_UTF8, 0, string.wz, (int)length, &mszA, 0, NULL, NULL) !=
|
|
|
|
(int)length)
|
|
|
|
{
|
|
|
|
free(mszA);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
length = bytes;
|
|
|
|
mszA = (char*)malloc(length);
|
|
|
|
if (!mszA)
|
|
|
|
return NULL;
|
|
|
|
CopyMemory(mszA, string.sz, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (index = 0; index < length - 1; index++)
|
|
|
|
{
|
|
|
|
if (mszA[index] == '\0')
|
|
|
|
mszA[index] = ',';
|
|
|
|
}
|
|
|
|
|
|
|
|
return mszA;
|
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static char* smartcard_msz_dump_a(const char* msz, size_t len, char* buffer, size_t bufferLen)
|
2014-04-06 00:06:46 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
char* buf = buffer;
|
|
|
|
const char* cur = msz;
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
while ((len > 0) && cur && cur[0] != '\0' && (bufferLen > 0))
|
2014-04-06 00:06:46 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
size_t clen = strnlen(cur, len);
|
|
|
|
int rc = _snprintf(buf, bufferLen, "%s", cur);
|
|
|
|
bufferLen -= (size_t)rc;
|
|
|
|
buf += rc;
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
cur += clen;
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
return buffer;
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static char* smartcard_msz_dump_w(const WCHAR* msz, size_t len, char* buffer, size_t bufferLen)
|
2014-04-06 00:06:46 +04:00
|
|
|
{
|
2020-06-03 13:28:32 +03:00
|
|
|
char* sz = NULL;
|
2020-01-23 11:32:34 +03:00
|
|
|
ConvertFromUnicode(CP_UTF8, 0, msz, (int)len, &sz, 0, NULL, NULL);
|
2020-01-13 12:51:22 +03:00
|
|
|
return smartcard_msz_dump_a(sz, len, buffer, bufferLen);
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static char* smartcard_array_dump(const void* pd, size_t len, char* buffer, size_t bufferLen)
|
2014-04-06 00:06:46 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
const BYTE* data = pd;
|
|
|
|
size_t x;
|
|
|
|
int rc;
|
|
|
|
char* start = buffer;
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-03-02 11:01:39 +03:00
|
|
|
/* Ensure '\0' termination */
|
|
|
|
if (bufferLen > 0)
|
|
|
|
{
|
|
|
|
buffer[bufferLen - 1] = '\0';
|
|
|
|
bufferLen--;
|
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
rc = _snprintf(buffer, bufferLen, "{ ");
|
2020-03-02 11:01:39 +03:00
|
|
|
if ((rc < 0) || ((size_t)rc > bufferLen))
|
|
|
|
goto fail;
|
2020-01-13 12:51:22 +03:00
|
|
|
buffer += rc;
|
|
|
|
bufferLen -= (size_t)rc;
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
for (x = 0; x < len; x++)
|
2014-04-06 00:06:46 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
rc = _snprintf(buffer, bufferLen, "%02X", data[x]);
|
2020-03-02 11:01:39 +03:00
|
|
|
if ((rc < 0) || ((size_t)rc > bufferLen))
|
|
|
|
goto fail;
|
2020-01-13 12:51:22 +03:00
|
|
|
buffer += rc;
|
|
|
|
bufferLen -= (size_t)rc;
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
2020-02-20 14:17:42 +03:00
|
|
|
rc = _snprintf(buffer, bufferLen, " }");
|
2020-03-02 11:01:39 +03:00
|
|
|
if ((rc < 0) || ((size_t)rc > bufferLen))
|
|
|
|
goto fail;
|
2020-01-13 12:51:22 +03:00
|
|
|
buffer += rc;
|
|
|
|
bufferLen -= (size_t)rc;
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-03-02 11:01:39 +03:00
|
|
|
fail:
|
2020-01-13 12:51:22 +03:00
|
|
|
return start;
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_log_redir_handle(const char* tag, const REDIR_SCARDHANDLE* pHandle)
|
2014-04-06 00:06:46 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
char buffer[128];
|
|
|
|
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(tag, g_LogLevel, " hContext: %s",
|
2020-01-23 11:32:34 +03:00
|
|
|
smartcard_array_dump(pHandle->pbHandle, pHandle->cbHandle, buffer, sizeof(buffer)));
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_log_context(const char* tag, const REDIR_SCARDCONTEXT* phContext)
|
2014-04-07 07:08:40 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
char buffer[128];
|
2020-01-23 11:32:34 +03:00
|
|
|
WLog_DBG(
|
|
|
|
tag, "hContext: %s",
|
|
|
|
smartcard_array_dump(phContext->pbContext, phContext->cbContext, buffer, sizeof(buffer)));
|
2014-04-07 07:08:40 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_context_and_string_call_a(const char* name,
|
|
|
|
const REDIR_SCARDCONTEXT* phContext,
|
|
|
|
const CHAR* sz)
|
2014-04-08 19:32:48 +04:00
|
|
|
{
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "%s {", name);
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_log_context(TAG, phContext);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " sz=%s", sz);
|
2014-04-08 19:32:48 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-08 19:32:48 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_context_and_string_call_w(const char* name,
|
|
|
|
const REDIR_SCARDCONTEXT* phContext,
|
|
|
|
const WCHAR* sz)
|
2014-04-07 07:08:40 +04:00
|
|
|
{
|
2020-06-03 13:28:32 +03:00
|
|
|
char* tmp = NULL;
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
2014-04-07 07:08:40 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "%s {", name);
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_log_context(TAG, phContext);
|
|
|
|
ConvertFromUnicode(CP_UTF8, 0, sz, -1, &tmp, 0, NULL, NULL);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " sz=%s", tmp);
|
2020-01-13 12:51:22 +03:00
|
|
|
free(tmp);
|
2014-04-07 07:08:40 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
2014-04-07 07:08:40 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_context_call(SMARTCARD_DEVICE* smartcard, const Context_Call* call,
|
|
|
|
const char* name)
|
2014-04-11 22:01:42 +04:00
|
|
|
{
|
2019-05-08 13:26:04 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "%s_Call {", name);
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->handles.hContext);
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-07 07:08:40 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_list_reader_groups_call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const ListReaderGroups_Call* call, BOOL unicode)
|
2014-04-08 19:32:48 +04:00
|
|
|
{
|
2019-05-08 13:26:04 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2014-04-08 19:32:48 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
2014-04-08 19:32:48 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "ListReaderGroups%S_Call {", unicode ? "W" : "A");
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->handles.hContext);
|
2014-04-08 19:32:48 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "fmszGroupsIsNULL: %" PRId32 " cchGroups: 0x%08" PRIx32,
|
|
|
|
call->fmszGroupsIsNULL, call->cchGroups);
|
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_get_status_change_w_call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const GetStatusChangeW_Call* call)
|
2014-04-11 22:01:42 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
UINT32 index;
|
|
|
|
char* szEventState;
|
|
|
|
char* szCurrentState;
|
|
|
|
LPSCARD_READERSTATEW readerState;
|
2019-05-08 13:26:04 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2014-04-08 19:32:48 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
2014-04-11 22:01:42 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "GetStatusChangeW_Call {");
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->handles.hContext);
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "dwTimeOut: 0x%08" PRIX32 " cReaders: %" PRIu32 "", call->dwTimeOut,
|
2020-01-13 12:51:22 +03:00
|
|
|
call->cReaders);
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
for (index = 0; index < call->cReaders; index++)
|
2014-04-06 00:06:46 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
char* szReaderA = NULL;
|
|
|
|
readerState = &call->rgReaderStates[index];
|
|
|
|
ConvertFromUnicode(CP_UTF8, 0, readerState->szReader, -1, &szReaderA, 0, NULL, NULL);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: szReader: %s cbAtr: %" PRIu32 "", index,
|
|
|
|
szReaderA, readerState->cbAtr);
|
2020-01-13 12:51:22 +03:00
|
|
|
szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
|
|
|
|
szEventState = SCardGetReaderStateString(readerState->dwEventState);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: dwCurrentState: %s (0x%08" PRIX32 ")", index,
|
2020-01-13 12:51:22 +03:00
|
|
|
szCurrentState, readerState->dwCurrentState);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: dwEventState: %s (0x%08" PRIX32 ")", index,
|
|
|
|
szEventState, readerState->dwEventState);
|
2020-01-13 12:51:22 +03:00
|
|
|
free(szCurrentState);
|
|
|
|
free(szEventState);
|
|
|
|
free(szReaderA);
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
2014-04-12 01:44:27 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_list_reader_groups_return(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const ListReaderGroups_Return* ret,
|
|
|
|
BOOL unicode)
|
|
|
|
{
|
|
|
|
char* mszA = NULL;
|
|
|
|
WINPR_UNUSED(smartcard);
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
|
|
|
|
2020-01-23 12:07:54 +03:00
|
|
|
mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "ListReaderGroups%s_Return {", unicode ? "W" : "A");
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " ReturnCode: %s (0x%08" PRIx32 ")",
|
2020-02-17 16:07:20 +03:00
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " cBytes: %" PRIu32 " msz: %s", ret->cBytes, mszA);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2020-01-13 12:51:22 +03:00
|
|
|
free(mszA);
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_list_readers_call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const ListReaders_Call* call, BOOL unicode)
|
2014-04-07 07:08:40 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
char* mszGroupsA = NULL;
|
2019-05-08 13:26:04 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2014-04-11 22:13:06 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-01-23 12:07:54 +03:00
|
|
|
mszGroupsA = smartcard_convert_string_list(call->mszGroups, call->cBytes, unicode);
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "ListReaders%s_Call {", unicode ? "W" : "A");
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->handles.hContext);
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel,
|
2020-01-13 12:51:22 +03:00
|
|
|
"cBytes: %" PRIu32 " mszGroups: %s fmszReadersIsNULL: %" PRId32
|
|
|
|
" cchReaders: 0x%08" PRIX32 "",
|
|
|
|
call->cBytes, mszGroupsA, call->fmszReadersIsNULL, call->cchReaders);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-01-23 12:07:54 +03:00
|
|
|
free(mszGroupsA);
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_locate_cards_by_atr_a_call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const LocateCardsByATRA_Call* call)
|
2014-04-07 07:08:40 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
UINT32 index;
|
|
|
|
char* szEventState;
|
|
|
|
char* szCurrentState;
|
2020-02-17 16:07:20 +03:00
|
|
|
|
2019-05-08 13:26:04 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2014-04-07 07:08:40 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
2014-04-07 07:08:40 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "LocateCardsByATRA_Call {");
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->handles.hContext);
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
for (index = 0; index < call->cReaders; index++)
|
2014-04-07 00:29:11 +04:00
|
|
|
{
|
2020-02-17 16:07:20 +03:00
|
|
|
char buffer[1024];
|
|
|
|
const LPSCARD_READERSTATEA readerState = &call->rgReaderStates[index];
|
|
|
|
|
|
|
|
WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: szReader: %s cbAtr: %" PRIu32 "", index,
|
2020-01-13 12:51:22 +03:00
|
|
|
readerState->szReader, readerState->cbAtr);
|
|
|
|
szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
|
|
|
|
szEventState = SCardGetReaderStateString(readerState->dwEventState);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: dwCurrentState: %s (0x%08" PRIX32 ")", index,
|
2020-01-13 12:51:22 +03:00
|
|
|
szCurrentState, readerState->dwCurrentState);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: dwEventState: %s (0x%08" PRIX32 ")", index,
|
|
|
|
szEventState, readerState->dwEventState);
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_DBG(
|
|
|
|
TAG, "\t[%" PRIu32 "]: cbAtr: %" PRIu32 " rgbAtr: %s", index, readerState->cbAtr,
|
|
|
|
smartcard_array_dump(readerState->rgbAtr, readerState->cbAtr, buffer, sizeof(buffer)));
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
free(szCurrentState);
|
|
|
|
free(szEventState);
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-07 07:08:40 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_locate_cards_a_call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const LocateCardsA_Call* call)
|
2014-04-07 00:29:11 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
char buffer[8192];
|
2019-05-08 13:26:04 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "LocateCardsA_Call {");
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->handles.hContext);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " cBytes=%" PRId32, call->cBytes);
|
|
|
|
WLog_LVL(TAG, g_LogLevel, " mszCards=%s",
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_msz_dump_a(call->mszCards, call->cBytes, buffer, sizeof(buffer)));
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " cReaders=%" PRId32, call->cReaders);
|
|
|
|
// WLog_LVL(TAG, g_LogLevel, " cReaders=%" PRId32, call->rgReaderStates);
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_locate_cards_return(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const LocateCards_Return* ret)
|
2014-04-07 07:08:40 +04:00
|
|
|
{
|
2019-05-08 13:26:04 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
2014-04-07 07:08:40 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "LocateCards_Return {");
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " ReturnCode: %s (0x%08" PRIX32 ")",
|
2020-02-17 16:07:20 +03:00
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
2019-05-08 13:26:04 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (ret->ReturnCode == SCARD_S_SUCCESS)
|
2014-04-07 05:09:49 +04:00
|
|
|
{
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " cReaders=%" PRId32, ret->cReaders);
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_get_reader_icon_return(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const GetReaderIcon_Return* ret)
|
2014-04-11 10:17:36 +04:00
|
|
|
{
|
2019-05-08 13:26:04 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2014-04-11 10:17:36 +04:00
|
|
|
return;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "GetReaderIcon_Return {");
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " ReturnCode: %s (0x%08" PRIX32 ")",
|
2020-02-17 16:07:20 +03:00
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
2014-04-07 07:08:40 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (ret->ReturnCode == SCARD_S_SUCCESS)
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " cbDataLen=%" PRId32, ret->cbDataLen);
|
2015-07-03 14:09:03 +03:00
|
|
|
}
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-07 07:08:40 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_get_transmit_count_return(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const GetTransmitCount_Return* ret)
|
2014-04-11 10:17:36 +04:00
|
|
|
{
|
2019-05-08 13:26:04 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2014-04-11 10:17:36 +04:00
|
|
|
return;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "GetTransmitCount_Return {");
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " ReturnCode: %s (0x%08" PRIX32 ")",
|
2020-02-17 16:07:20 +03:00
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
2014-04-11 10:17:36 +04:00
|
|
|
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " cTransmitCount=%" PRIu32, ret->cTransmitCount);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-11 10:17:36 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_read_cache_return(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const ReadCache_Return* ret)
|
2014-04-07 05:09:49 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "ReadCache_Return {");
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " ReturnCode: %s (0x%08" PRIX32 ")",
|
2020-02-17 16:07:20 +03:00
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (ret->ReturnCode == SCARD_S_SUCCESS)
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
2020-04-20 14:42:02 +03:00
|
|
|
char buffer[1024];
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " cbDataLen=%" PRId32, ret->cbDataLen);
|
2020-04-20 14:42:02 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " cbData: %s",
|
|
|
|
smartcard_array_dump(ret->pbData, ret->cbDataLen, buffer, sizeof(buffer)));
|
2015-07-03 14:09:03 +03:00
|
|
|
}
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_locate_cards_w_call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const LocateCardsW_Call* call)
|
2014-04-11 22:01:42 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
char buffer[8192];
|
2019-05-08 13:26:04 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2014-04-14 00:48:32 +04:00
|
|
|
return;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "LocateCardsW_Call {");
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->handles.hContext);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " cBytes=%" PRId32, call->cBytes);
|
|
|
|
WLog_LVL(TAG, g_LogLevel, " sz2=%s",
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_msz_dump_w(call->mszCards, call->cBytes, buffer, sizeof(buffer)));
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " cReaders=%" PRId32, call->cReaders);
|
|
|
|
// WLog_LVL(TAG, g_LogLevel, " sz2=%s", call->rgReaderStates);
|
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_list_readers_return(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const ListReaders_Return* ret, BOOL unicode)
|
2014-05-06 21:00:44 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
char* mszA = NULL;
|
2019-05-08 13:26:04 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2014-05-06 21:00:44 +04:00
|
|
|
return;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "ListReaders%s_Return {", unicode ? "W" : "A");
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " ReturnCode: %s (0x%08" PRIX32 ")",
|
2020-02-17 16:07:20 +03:00
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (ret->ReturnCode != SCARD_S_SUCCESS)
|
|
|
|
{
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-01-23 12:07:54 +03:00
|
|
|
mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " cBytes: %" PRIu32 " msz: %s", ret->cBytes, mszA);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2020-01-13 12:51:22 +03:00
|
|
|
free(mszA);
|
2015-06-30 18:42:01 +03:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_get_status_change_return(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const GetStatusChange_Return* ret,
|
|
|
|
BOOL unicode)
|
2015-06-30 18:42:01 +03:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
UINT32 index;
|
|
|
|
char* szEventState;
|
|
|
|
char* szCurrentState;
|
2020-02-17 16:07:20 +03:00
|
|
|
|
2019-05-08 13:26:04 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2015-06-30 18:42:01 +03:00
|
|
|
return;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "GetStatusChange%s_Return {", unicode ? "W" : "A");
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " ReturnCode: %s (0x%08" PRIX32 ")",
|
2020-02-17 16:07:20 +03:00
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " cReaders: %" PRIu32 "", ret->cReaders);
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
for (index = 0; index < ret->cReaders; index++)
|
2015-06-30 18:42:01 +03:00
|
|
|
{
|
2020-02-17 16:07:20 +03:00
|
|
|
char buffer[1024];
|
|
|
|
const ReaderState_Return* rgReaderState = &(ret->rgReaderStates[index]);
|
2020-01-13 12:51:22 +03:00
|
|
|
szCurrentState = SCardGetReaderStateString(rgReaderState->dwCurrentState);
|
|
|
|
szEventState = SCardGetReaderStateString(rgReaderState->dwEventState);
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " [%" PRIu32 "]: dwCurrentState: %s (0x%08" PRIX32 ")", index,
|
2020-01-13 12:51:22 +03:00
|
|
|
szCurrentState, rgReaderState->dwCurrentState);
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " [%" PRIu32 "]: dwEventState: %s (0x%08" PRIX32 ")", index,
|
2020-02-17 16:07:20 +03:00
|
|
|
szEventState, rgReaderState->dwEventState);
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " [%" PRIu32 "]: cbAtr: %" PRIu32 " rgbAtr: %s", index,
|
2020-02-17 16:07:20 +03:00
|
|
|
rgReaderState->cbAtr,
|
|
|
|
smartcard_array_dump(rgReaderState->rgbAtr, rgReaderState->cbAtr, buffer,
|
|
|
|
sizeof(buffer)));
|
2020-01-13 12:51:22 +03:00
|
|
|
free(szCurrentState);
|
|
|
|
free(szEventState);
|
2015-06-30 18:42:01 +03:00
|
|
|
}
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2015-06-30 18:42:01 +03:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_context_and_two_strings_a_call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const ContextAndTwoStringA_Call* call)
|
2015-06-30 18:42:01 +03:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "ContextAndTwoStringW_Call {");
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->handles.hContext);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " sz1=%s", call->sz1);
|
|
|
|
WLog_LVL(TAG, g_LogLevel, " sz2=%s", call->sz2);
|
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_context_and_two_strings_w_call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const ContextAndTwoStringW_Call* call)
|
|
|
|
{
|
|
|
|
CHAR* sz1 = NULL;
|
|
|
|
CHAR* sz2 = NULL;
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "ContextAndTwoStringW_Call {");
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->handles.hContext);
|
2020-01-13 12:51:22 +03:00
|
|
|
ConvertFromUnicode(CP_UTF8, 0, call->sz1, -1, &sz1, 0, NULL, NULL);
|
|
|
|
ConvertFromUnicode(CP_UTF8, 0, call->sz2, -1, &sz2, 0, NULL, NULL);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " sz1=%s", sz1);
|
|
|
|
WLog_LVL(TAG, g_LogLevel, " sz2=%s", sz2);
|
2020-01-13 12:51:22 +03:00
|
|
|
free(sz1);
|
|
|
|
free(sz2);
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2015-06-30 18:42:01 +03:00
|
|
|
}
|
2014-05-06 21:00:44 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_get_transmit_count_call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const GetTransmitCount_Call* call)
|
2015-06-30 18:42:01 +03:00
|
|
|
{
|
2019-05-08 13:26:04 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2015-06-30 18:42:01 +03:00
|
|
|
return;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "GetTransmitCount_Call {");
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->handles.hContext);
|
|
|
|
smartcard_log_redir_handle(TAG, &call->handles.hCard);
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-05-06 21:00:44 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_write_cache_a_call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const WriteCacheA_Call* call)
|
2014-04-07 05:09:49 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
char buffer[1024];
|
|
|
|
WINPR_UNUSED(smartcard);
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "GetTransmitCount_Call {");
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " szLookupName=%s", call->szLookupName);
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->Common.handles.hContext);
|
2020-01-23 11:32:34 +03:00
|
|
|
WLog_DBG(
|
|
|
|
TAG, "..CardIdentifier=%s",
|
|
|
|
smartcard_array_dump(call->Common.CardIdentifier, sizeof(UUID), buffer, sizeof(buffer)));
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
|
|
|
|
WLog_LVL(TAG, g_LogLevel, " cbDataLen=%" PRIu32, call->Common.cbDataLen);
|
2020-01-23 11:32:34 +03:00
|
|
|
WLog_DBG(
|
|
|
|
TAG, " pbData=%s",
|
|
|
|
smartcard_array_dump(call->Common.pbData, call->Common.cbDataLen, buffer, sizeof(buffer)));
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
2015-07-03 14:09:03 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_write_cache_w_call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const WriteCacheW_Call* call)
|
|
|
|
{
|
2020-06-03 13:28:32 +03:00
|
|
|
char* tmp = NULL;
|
2020-01-13 12:51:22 +03:00
|
|
|
char buffer[1024];
|
|
|
|
WINPR_UNUSED(smartcard);
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "GetTransmitCount_Call {");
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
ConvertFromUnicode(CP_UTF8, 0, call->szLookupName, -1, &tmp, 0, NULL, NULL);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " szLookupName=%s", tmp);
|
2020-01-13 12:51:22 +03:00
|
|
|
free(tmp);
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->Common.handles.hContext);
|
2020-01-23 11:32:34 +03:00
|
|
|
WLog_DBG(
|
|
|
|
TAG, "..CardIdentifier=%s",
|
|
|
|
smartcard_array_dump(call->Common.CardIdentifier, sizeof(UUID), buffer, sizeof(buffer)));
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
|
|
|
|
WLog_LVL(TAG, g_LogLevel, " cbDataLen=%" PRIu32, call->Common.cbDataLen);
|
2020-01-23 11:32:34 +03:00
|
|
|
WLog_DBG(
|
|
|
|
TAG, " pbData=%s",
|
|
|
|
smartcard_array_dump(call->Common.pbData, call->Common.cbDataLen, buffer, sizeof(buffer)));
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_read_cache_a_call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const ReadCacheA_Call* call)
|
|
|
|
{
|
|
|
|
char buffer[1024];
|
|
|
|
WINPR_UNUSED(smartcard);
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "GetTransmitCount_Call {");
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " szLookupName=%s", call->szLookupName);
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->Common.handles.hContext);
|
2020-01-23 11:32:34 +03:00
|
|
|
WLog_DBG(
|
|
|
|
TAG, "..CardIdentifier=%s",
|
|
|
|
smartcard_array_dump(call->Common.CardIdentifier, sizeof(UUID), buffer, sizeof(buffer)));
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
|
|
|
|
WLog_LVL(TAG, g_LogLevel, " fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
|
|
|
|
WLog_LVL(TAG, g_LogLevel, " cbDataLen=%" PRIu32, call->Common.cbDataLen);
|
2014-04-08 01:17:26 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_read_cache_w_call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const ReadCacheW_Call* call)
|
2014-04-11 10:17:36 +04:00
|
|
|
{
|
2020-06-04 08:44:08 +03:00
|
|
|
char* tmp = NULL;
|
2020-01-13 12:51:22 +03:00
|
|
|
char buffer[1024];
|
2019-05-08 13:26:04 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2014-04-11 10:17:36 +04:00
|
|
|
return;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "GetTransmitCount_Call {");
|
2014-04-11 10:17:36 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
ConvertFromUnicode(CP_UTF8, 0, call->szLookupName, -1, &tmp, 0, NULL, NULL);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " szLookupName=%s", tmp);
|
2020-01-13 12:51:22 +03:00
|
|
|
free(tmp);
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->Common.handles.hContext);
|
2020-01-23 11:32:34 +03:00
|
|
|
WLog_DBG(
|
|
|
|
TAG, "..CardIdentifier=%s",
|
|
|
|
smartcard_array_dump(call->Common.CardIdentifier, sizeof(UUID), buffer, sizeof(buffer)));
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
|
|
|
|
WLog_LVL(TAG, g_LogLevel, " fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
|
|
|
|
WLog_LVL(TAG, g_LogLevel, " cbDataLen=%" PRIu32, call->Common.cbDataLen);
|
2014-04-11 10:17:36 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-11 10:17:36 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_transmit_call(SMARTCARD_DEVICE* smartcard, const Transmit_Call* call)
|
2014-04-07 08:10:27 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
UINT32 cbExtraBytes;
|
|
|
|
BYTE* pbExtraBytes;
|
|
|
|
WINPR_UNUSED(smartcard);
|
2014-04-10 01:44:39 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
2014-04-13 23:50:51 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "Transmit_Call {");
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->handles.hContext);
|
|
|
|
smartcard_log_redir_handle(TAG, &call->handles.hCard);
|
2015-08-19 13:50:48 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (call->pioSendPci)
|
2014-04-10 01:44:39 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
cbExtraBytes = (UINT32)(call->pioSendPci->cbPciLength - sizeof(SCARD_IO_REQUEST));
|
|
|
|
pbExtraBytes = &((BYTE*)call->pioSendPci)[sizeof(SCARD_IO_REQUEST)];
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "pioSendPci: dwProtocol: %" PRIu32 " cbExtraBytes: %" PRIu32 "",
|
2020-01-13 12:51:22 +03:00
|
|
|
call->pioSendPci->dwProtocol, cbExtraBytes);
|
2014-04-10 01:44:39 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (cbExtraBytes)
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
2020-02-17 16:07:20 +03:00
|
|
|
char buffer[1024];
|
|
|
|
WLog_LVL(TAG, g_LogLevel, "pbExtraBytes: %s",
|
|
|
|
smartcard_array_dump(pbExtraBytes, cbExtraBytes, buffer, sizeof(buffer)));
|
2015-07-03 14:09:03 +03:00
|
|
|
}
|
2014-04-10 01:44:39 +04:00
|
|
|
}
|
2020-01-13 12:51:22 +03:00
|
|
|
else
|
2015-08-19 13:50:48 +03:00
|
|
|
{
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "pioSendPci: null");
|
2015-08-19 13:50:48 +03:00
|
|
|
}
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "cbSendLength: %" PRIu32 "", call->cbSendLength);
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (call->pbSendBuffer)
|
|
|
|
{
|
2020-02-17 16:07:20 +03:00
|
|
|
char buffer[1024];
|
|
|
|
WLog_DBG(
|
|
|
|
TAG, "pbSendBuffer: %s",
|
|
|
|
smartcard_array_dump(call->pbSendBuffer, call->cbSendLength, buffer, sizeof(buffer)));
|
2014-04-11 10:17:36 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "pbSendBuffer: null");
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (call->pioRecvPci)
|
|
|
|
{
|
|
|
|
cbExtraBytes = (UINT32)(call->pioRecvPci->cbPciLength - sizeof(SCARD_IO_REQUEST));
|
|
|
|
pbExtraBytes = &((BYTE*)call->pioRecvPci)[sizeof(SCARD_IO_REQUEST)];
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "pioRecvPci: dwProtocol: %" PRIu32 " cbExtraBytes: %" PRIu32 "",
|
2020-01-13 12:51:22 +03:00
|
|
|
call->pioRecvPci->dwProtocol, cbExtraBytes);
|
|
|
|
|
|
|
|
if (cbExtraBytes)
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
2020-02-17 16:07:20 +03:00
|
|
|
char buffer[1024];
|
|
|
|
WLog_LVL(TAG, g_LogLevel, "pbExtraBytes: %s",
|
|
|
|
smartcard_array_dump(pbExtraBytes, cbExtraBytes, buffer, sizeof(buffer)));
|
2015-07-03 14:09:03 +03:00
|
|
|
}
|
2014-04-11 10:17:36 +04:00
|
|
|
}
|
2020-01-13 12:51:22 +03:00
|
|
|
else
|
2014-04-11 10:17:36 +04:00
|
|
|
{
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "pioRecvPci: null");
|
2014-04-11 10:17:36 +04:00
|
|
|
}
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "fpbRecvBufferIsNULL: %" PRId32 " cbRecvLength: %" PRIu32 "",
|
2020-01-13 12:51:22 +03:00
|
|
|
call->fpbRecvBufferIsNULL, call->cbRecvLength);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-11 10:17:36 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_locate_cards_by_atr_w_call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const LocateCardsByATRW_Call* call)
|
2014-04-06 00:06:46 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
UINT32 index;
|
|
|
|
char* szEventState;
|
|
|
|
char* szCurrentState;
|
2020-02-17 16:07:20 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "LocateCardsByATRW_Call {");
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->handles.hContext);
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
for (index = 0; index < call->cReaders; index++)
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
2020-02-17 16:07:20 +03:00
|
|
|
char buffer[1024];
|
2020-01-13 12:51:22 +03:00
|
|
|
char* tmp = NULL;
|
|
|
|
const LPSCARD_READERSTATEW readerState =
|
|
|
|
(const LPSCARD_READERSTATEW)&call->rgReaderStates[index];
|
|
|
|
|
|
|
|
ConvertFromUnicode(CP_UTF8, 0, readerState->szReader, -1, &tmp, 0, NULL, NULL);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: szReader: %s cbAtr: %" PRIu32 "", index, tmp,
|
2020-01-13 12:51:22 +03:00
|
|
|
readerState->cbAtr);
|
|
|
|
szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
|
|
|
|
szEventState = SCardGetReaderStateString(readerState->dwEventState);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: dwCurrentState: %s (0x%08" PRIX32 ")", index,
|
2020-01-13 12:51:22 +03:00
|
|
|
szCurrentState, readerState->dwCurrentState);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: dwEventState: %s (0x%08" PRIX32 ")", index,
|
|
|
|
szEventState, readerState->dwEventState);
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_DBG(
|
|
|
|
TAG, "\t[%" PRIu32 "]: cbAtr: %" PRIu32 " rgbAtr: %s", index, readerState->cbAtr,
|
|
|
|
smartcard_array_dump(readerState->rgbAtr, readerState->cbAtr, buffer, sizeof(buffer)));
|
2020-01-13 12:51:22 +03:00
|
|
|
|
|
|
|
free(szCurrentState);
|
|
|
|
free(szEventState);
|
|
|
|
free(tmp);
|
2015-07-03 14:09:03 +03:00
|
|
|
}
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_transmit_return(SMARTCARD_DEVICE* smartcard, const Transmit_Return* ret)
|
2014-04-06 00:06:46 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
UINT32 cbExtraBytes;
|
|
|
|
BYTE* pbExtraBytes;
|
|
|
|
WINPR_UNUSED(smartcard);
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "Transmit_Return {");
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " ReturnCode: %s (0x%08" PRIX32 ")",
|
2020-02-17 16:07:20 +03:00
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (ret->pioRecvPci)
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength - sizeof(SCARD_IO_REQUEST));
|
|
|
|
pbExtraBytes = &((BYTE*)ret->pioRecvPci)[sizeof(SCARD_IO_REQUEST)];
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " pioRecvPci: dwProtocol: %" PRIu32 " cbExtraBytes: %" PRIu32 "",
|
2020-01-13 12:51:22 +03:00
|
|
|
ret->pioRecvPci->dwProtocol, cbExtraBytes);
|
2014-04-27 23:45:36 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (cbExtraBytes)
|
|
|
|
{
|
2020-02-17 16:07:20 +03:00
|
|
|
char buffer[1024];
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " pbExtraBytes: %s",
|
2020-02-17 16:07:20 +03:00
|
|
|
smartcard_array_dump(pbExtraBytes, cbExtraBytes, buffer, sizeof(buffer)));
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2014-04-27 23:45:36 +04:00
|
|
|
{
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " pioRecvPci: null");
|
2014-04-27 23:45:36 +04:00
|
|
|
}
|
|
|
|
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " cbRecvLength: %" PRIu32 "", ret->cbRecvLength);
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (ret->pbRecvBuffer)
|
|
|
|
{
|
2020-02-17 16:07:20 +03:00
|
|
|
char buffer[1024];
|
|
|
|
WLog_DBG(
|
2020-02-20 14:17:42 +03:00
|
|
|
TAG, " pbRecvBuffer: %s",
|
2020-02-17 16:07:20 +03:00
|
|
|
smartcard_array_dump(ret->pbRecvBuffer, ret->cbRecvLength, buffer, sizeof(buffer)));
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " pbRecvBuffer: null");
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_control_return(SMARTCARD_DEVICE* smartcard, const Control_Return* ret)
|
2014-04-11 10:17:36 +04:00
|
|
|
{
|
2019-05-08 13:26:04 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2014-04-11 10:17:36 +04:00
|
|
|
return;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "Control_Return {");
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " ReturnCode: %s (0x%08" PRIX32 ")",
|
2020-02-17 16:07:20 +03:00
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " cbOutBufferSize: %" PRIu32 "", ret->cbOutBufferSize);
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (ret->pvOutBuffer)
|
2014-04-11 22:01:42 +04:00
|
|
|
{
|
2020-02-17 16:07:20 +03:00
|
|
|
char buffer[1024];
|
|
|
|
WLog_DBG(
|
|
|
|
TAG, "pvOutBuffer: %s",
|
|
|
|
smartcard_array_dump(ret->pvOutBuffer, ret->cbOutBufferSize, buffer, sizeof(buffer)));
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "pvOutBuffer: null");
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
2014-04-11 10:17:36 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-11 10:17:36 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_control_call(SMARTCARD_DEVICE* smartcard, const Control_Call* call)
|
2014-04-06 00:06:46 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "Control_Call {");
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->handles.hContext);
|
|
|
|
smartcard_log_redir_handle(TAG, &call->handles.hCard);
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel,
|
2020-01-13 12:51:22 +03:00
|
|
|
"dwControlCode: 0x%08" PRIX32 " cbInBufferSize: %" PRIu32
|
|
|
|
" fpvOutBufferIsNULL: %" PRId32 " cbOutBufferSize: %" PRIu32 "",
|
|
|
|
call->dwControlCode, call->cbInBufferSize, call->fpvOutBufferIsNULL,
|
|
|
|
call->cbOutBufferSize);
|
|
|
|
|
|
|
|
if (call->pvInBuffer)
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
2020-02-17 16:07:20 +03:00
|
|
|
char buffer[1024];
|
|
|
|
WLog_DBG(
|
|
|
|
TAG, "pbInBuffer: %s",
|
|
|
|
smartcard_array_dump(call->pvInBuffer, call->cbInBufferSize, buffer, sizeof(buffer)));
|
2015-07-03 14:09:03 +03:00
|
|
|
}
|
2020-01-13 12:51:22 +03:00
|
|
|
else
|
2014-04-27 23:45:36 +04:00
|
|
|
{
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "pvInBuffer: null");
|
2014-04-27 23:45:36 +04:00
|
|
|
}
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-01-23 11:32:34 +03:00
|
|
|
static void smartcard_trace_set_attrib_call(SMARTCARD_DEVICE* smartcard, const SetAttrib_Call* call)
|
2014-04-11 10:17:36 +04:00
|
|
|
{
|
2020-01-23 11:32:34 +03:00
|
|
|
char buffer[8192];
|
2019-05-08 13:26:04 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2014-04-11 10:17:36 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2014-04-11 10:17:36 +04:00
|
|
|
return;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "GetAttrib_Call {");
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->handles.hContext);
|
|
|
|
smartcard_log_redir_handle(TAG, &call->handles.hCard);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "dwAttrId: 0x%08" PRIX32, call->dwAttrId);
|
|
|
|
WLog_LVL(TAG, g_LogLevel, "cbAttrLen: 0x%08" PRId32, call->cbAttrLen);
|
|
|
|
WLog_LVL(TAG, g_LogLevel, "pbAttr: %s",
|
2020-01-23 11:32:34 +03:00
|
|
|
smartcard_array_dump(call->pbAttr, call->cbAttrLen, buffer, sizeof(buffer)));
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-11 10:17:36 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_get_attrib_return(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const GetAttrib_Return* ret, DWORD dwAttrId)
|
2014-04-07 07:08:40 +04:00
|
|
|
{
|
2019-05-08 13:26:04 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2014-04-11 10:17:36 +04:00
|
|
|
return;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "GetAttrib_Return {");
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " ReturnCode: %s (0x%08" PRIX32 ")",
|
2020-02-17 16:07:20 +03:00
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " dwAttrId: %s (0x%08" PRIX32 ") cbAttrLen: 0x%08" PRIX32 "",
|
2020-01-13 12:51:22 +03:00
|
|
|
SCardGetAttributeString(dwAttrId), dwAttrId, ret->cbAttrLen);
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (dwAttrId == SCARD_ATTR_VENDOR_NAME)
|
2014-04-11 22:01:42 +04:00
|
|
|
{
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " pbAttr: %.*s", ret->cbAttrLen, (char*)ret->pbAttr);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
2020-01-13 12:51:22 +03:00
|
|
|
else if (dwAttrId == SCARD_ATTR_CURRENT_PROTOCOL_TYPE)
|
2014-04-11 22:01:42 +04:00
|
|
|
{
|
2021-02-06 17:22:38 +03:00
|
|
|
union
|
|
|
|
{
|
2020-02-20 16:36:53 +03:00
|
|
|
BYTE* pb;
|
|
|
|
DWORD* pd;
|
|
|
|
} attr;
|
|
|
|
attr.pb = ret->pbAttr;
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " dwProtocolType: %s (0x%08" PRIX32 ")",
|
2020-02-20 16:36:53 +03:00
|
|
|
SCardGetProtocolString(*attr.pd), *attr.pd);
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
2014-04-11 10:17:36 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-11 10:17:36 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_get_attrib_call(SMARTCARD_DEVICE* smartcard, const GetAttrib_Call* call)
|
2014-04-07 00:29:11 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "GetAttrib_Call {");
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->handles.hContext);
|
|
|
|
smartcard_log_redir_handle(TAG, &call->handles.hCard);
|
2015-07-03 14:09:03 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel,
|
2020-01-13 12:51:22 +03:00
|
|
|
"dwAttrId: %s (0x%08" PRIX32 ") fpbAttrIsNULL: %" PRId32 " cbAttrLen: 0x%08" PRIX32 "",
|
|
|
|
SCardGetAttributeString(call->dwAttrId), call->dwAttrId, call->fpbAttrIsNULL,
|
|
|
|
call->cbAttrLen);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_status_call(SMARTCARD_DEVICE* smartcard, const Status_Call* call,
|
|
|
|
BOOL unicode)
|
|
|
|
{
|
|
|
|
WINPR_UNUSED(smartcard);
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "Status%s_Call {", unicode ? "W" : "A");
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->handles.hContext);
|
|
|
|
smartcard_log_redir_handle(TAG, &call->handles.hCard);
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel,
|
2020-01-13 12:51:22 +03:00
|
|
|
"fmszReaderNamesIsNULL: %" PRId32 " cchReaderLen: %" PRIu32 " cbAtrLen: %" PRIu32 "",
|
|
|
|
call->fmszReaderNamesIsNULL, call->cchReaderLen, call->cbAtrLen);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_status_return(SMARTCARD_DEVICE* smartcard, const Status_Return* ret,
|
|
|
|
BOOL unicode)
|
2014-04-14 00:48:32 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
char* mszReaderNamesA = NULL;
|
2020-02-17 16:07:20 +03:00
|
|
|
char buffer[1024];
|
2021-02-18 18:48:09 +03:00
|
|
|
DWORD cBytes;
|
2020-02-17 16:07:20 +03:00
|
|
|
|
2019-05-08 13:26:04 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2014-04-14 00:48:32 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2014-04-14 00:48:32 +04:00
|
|
|
return;
|
2021-02-18 18:48:09 +03:00
|
|
|
cBytes = ret->cBytes;
|
|
|
|
if (ret->ReturnCode != SCARD_S_SUCCESS)
|
|
|
|
cBytes = 0;
|
|
|
|
if (cBytes == SCARD_AUTOALLOCATE)
|
|
|
|
cBytes = 0;
|
|
|
|
mszReaderNamesA = smartcard_convert_string_list(ret->mszReaderNames, cBytes, unicode);
|
2014-04-14 00:48:32 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "Status%s_Return {", unicode ? "W" : "A");
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " ReturnCode: %s (0x%08" PRIX32 ")",
|
2020-02-17 16:07:20 +03:00
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " dwState: %s (0x%08" PRIX32 ") dwProtocol: %s (0x%08" PRIX32 ")",
|
2020-01-13 12:51:22 +03:00
|
|
|
SCardGetCardStateString(ret->dwState), ret->dwState,
|
|
|
|
SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
|
2014-04-14 00:48:32 +04:00
|
|
|
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " cBytes: %" PRIu32 " mszReaderNames: %s", ret->cBytes,
|
2020-02-17 16:07:20 +03:00
|
|
|
mszReaderNamesA);
|
2014-04-14 00:48:32 +04:00
|
|
|
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " cbAtrLen: %" PRIu32 " pbAtr: %s", ret->cbAtrLen,
|
2020-02-17 16:07:20 +03:00
|
|
|
smartcard_array_dump(ret->pbAtr, ret->cbAtrLen, buffer, sizeof(buffer)));
|
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2020-01-13 12:51:22 +03:00
|
|
|
free(mszReaderNamesA);
|
2020-02-17 16:07:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void smartcard_trace_state_return(SMARTCARD_DEVICE* smartcard, const State_Return* ret)
|
|
|
|
{
|
|
|
|
char buffer[1024];
|
|
|
|
|
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
|
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WLog_LVL(TAG, g_LogLevel, "Reconnect_Return {");
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " ReturnCode: %s (0x%08" PRIX32 ")",
|
2020-02-17 16:07:20 +03:00
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " dwState: %s (0x%08" PRIX32 ")", ret->dwState);
|
|
|
|
WLog_LVL(TAG, g_LogLevel, " dwProtocol: %s (0x%08" PRIX32 ")", ret->dwProtocol);
|
|
|
|
WLog_LVL(TAG, g_LogLevel, " cbAtrLen: %s (0x%08" PRIX32 ")", ret->cbAtrLen);
|
|
|
|
WLog_LVL(TAG, g_LogLevel, " rgAtr: %s",
|
2020-02-17 16:07:20 +03:00
|
|
|
smartcard_array_dump(ret->rgAtr, sizeof(ret->rgAtr), buffer, sizeof(buffer)));
|
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-14 00:48:32 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_reconnect_return(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const Reconnect_Return* ret)
|
2014-04-14 00:48:32 +04:00
|
|
|
{
|
2019-05-08 13:26:04 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2014-04-14 00:48:32 +04:00
|
|
|
return;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "Reconnect_Return {");
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " ReturnCode: %s (0x%08" PRIX32 ")",
|
2020-02-17 16:07:20 +03:00
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " dwActiveProtocol: %s (0x%08" PRIX32 ")",
|
2015-06-30 18:42:01 +03:00
|
|
|
SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-14 00:48:32 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_connect_a_call(SMARTCARD_DEVICE* smartcard, const ConnectA_Call* call)
|
2014-04-07 00:29:11 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "ConnectA_Call {");
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->Common.handles.hContext);
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel,
|
2020-01-13 12:51:22 +03:00
|
|
|
"szReader: %s dwShareMode: %s (0x%08" PRIX32 ") dwPreferredProtocols: %s (0x%08" PRIX32
|
|
|
|
")",
|
|
|
|
call->szReader, SCardGetShareModeString(call->Common.dwShareMode),
|
|
|
|
call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
|
|
|
|
call->Common.dwPreferredProtocols);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_connect_w_call(SMARTCARD_DEVICE* smartcard, const ConnectW_Call* call)
|
|
|
|
{
|
|
|
|
char* szReaderA = NULL;
|
|
|
|
WINPR_UNUSED(smartcard);
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
ConvertFromUnicode(CP_UTF8, 0, call->szReader, -1, &szReaderA, 0, NULL, NULL);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "ConnectW_Call {");
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->Common.handles.hContext);
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel,
|
2020-01-13 12:51:22 +03:00
|
|
|
"szReader: %s dwShareMode: %s (0x%08" PRIX32 ") dwPreferredProtocols: %s (0x%08" PRIX32
|
|
|
|
")",
|
|
|
|
szReaderA, SCardGetShareModeString(call->Common.dwShareMode), call->Common.dwShareMode,
|
|
|
|
SCardGetProtocolString(call->Common.dwPreferredProtocols),
|
|
|
|
call->Common.dwPreferredProtocols);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2020-01-13 12:51:22 +03:00
|
|
|
free(szReaderA);
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_hcard_and_disposition_call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const HCardAndDisposition_Call* call,
|
|
|
|
const char* name)
|
2014-04-11 22:01:42 +04:00
|
|
|
{
|
2019-05-08 13:26:04 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2014-04-14 00:48:32 +04:00
|
|
|
return;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "%s_Call {", name);
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->handles.hContext);
|
|
|
|
smartcard_log_redir_handle(TAG, &call->handles.hCard);
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "dwDisposition: %s (0x%08" PRIX32 ")",
|
2020-01-13 12:51:22 +03:00
|
|
|
SCardGetDispositionString(call->dwDisposition), call->dwDisposition);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
2014-04-11 22:01:42 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_establish_context_call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const EstablishContext_Call* call)
|
|
|
|
{
|
|
|
|
WINPR_UNUSED(smartcard);
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
2014-04-11 22:01:42 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "EstablishContext_Call {");
|
|
|
|
WLog_LVL(TAG, g_LogLevel, "dwScope: %s (0x%08" PRIX32 ")", SCardGetScopeString(call->dwScope),
|
2020-01-13 12:51:22 +03:00
|
|
|
call->dwScope);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static void smartcard_trace_establish_context_return(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const EstablishContext_Return* ret)
|
2014-04-07 00:29:11 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "EstablishContext_Return {");
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " ReturnCode: %s (0x%08" PRIX32 ")",
|
2020-02-17 16:07:20 +03:00
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_log_context(TAG, &ret->hContext);
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void smartcard_trace_long_return(SMARTCARD_DEVICE* smartcard, const Long_Return* ret,
|
|
|
|
const char* name)
|
|
|
|
{
|
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "%s_Return {", name);
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " ReturnCode: %s (0x%08" PRIX32 ")",
|
2020-02-17 16:07:20 +03:00
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
static void smartcard_trace_connect_return(SMARTCARD_DEVICE* smartcard, const Connect_Return* ret)
|
2020-01-13 12:51:22 +03:00
|
|
|
{
|
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "Connect_Return {");
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " ReturnCode: %s (0x%08" PRIX32 ")",
|
2020-02-17 16:07:20 +03:00
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_log_context(TAG, &ret->hContext);
|
|
|
|
smartcard_log_redir_handle(TAG, &ret->hCard);
|
|
|
|
|
2020-02-20 14:17:42 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, " dwActiveProtocol: %s (0x%08" PRIX32 ")",
|
2020-01-13 12:51:22 +03:00
|
|
|
SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void smartcard_trace_reconnect_call(SMARTCARD_DEVICE* smartcard, const Reconnect_Call* call)
|
|
|
|
{
|
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "Reconnect_Call {");
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->handles.hContext);
|
|
|
|
smartcard_log_redir_handle(TAG, &call->handles.hCard);
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel,
|
2020-01-13 12:51:22 +03:00
|
|
|
"dwShareMode: %s (0x%08" PRIX32 ") dwPreferredProtocols: %s (0x%08" PRIX32
|
|
|
|
") dwInitialization: %s (0x%08" PRIX32 ")",
|
|
|
|
SCardGetShareModeString(call->dwShareMode), call->dwShareMode,
|
|
|
|
SCardGetProtocolString(call->dwPreferredProtocols), call->dwPreferredProtocols,
|
|
|
|
SCardGetDispositionString(call->dwInitialization), call->dwInitialization);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void smartcard_trace_device_type_id_return(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const GetDeviceTypeId_Return* ret)
|
|
|
|
{
|
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "GetDeviceTypeId_Return {");
|
|
|
|
WLog_LVL(TAG, g_LogLevel, " ReturnCode: %s (0x%08" PRIX32 ")",
|
|
|
|
SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
|
|
|
|
WLog_LVL(TAG, g_LogLevel, " dwDeviceId=%08" PRIx32, ret->dwDeviceId);
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_unpack_common_context_and_string_a(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
REDIR_SCARDCONTEXT* phContext,
|
|
|
|
CHAR** pszReaderName)
|
|
|
|
{
|
|
|
|
LONG status;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, phContext, &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, NULL))
|
|
|
|
return ERROR_INVALID_DATA;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, phContext);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read_a(s, pszReaderName, NDR_PTR_FULL);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
|
|
|
smartcard_trace_context_and_string_call_a(__FUNCTION__, phContext, *pszReaderName);
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_unpack_common_context_and_string_w(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
REDIR_SCARDCONTEXT* phContext,
|
|
|
|
WCHAR** pszReaderName)
|
|
|
|
{
|
|
|
|
LONG status;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
|
|
|
|
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, phContext, &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, NULL))
|
|
|
|
return ERROR_INVALID_DATA;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, phContext);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read_w(s, pszReaderName, NDR_PTR_FULL);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
|
|
|
smartcard_trace_context_and_string_call_w(__FUNCTION__, phContext, *pszReaderName);
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_unpack_common_type_header(SMARTCARD_DEVICE* smartcard, wStream* s)
|
|
|
|
{
|
|
|
|
UINT8 version;
|
|
|
|
UINT32 filler;
|
|
|
|
UINT8 endianness;
|
|
|
|
UINT16 commonHeaderLength;
|
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "CommonTypeHeader is too short: %" PRIuz "", Stream_GetRemainingLength(s));
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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_WARN(TAG, "Unsupported CommonTypeHeader Version %" PRIu8 "", version);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (endianness != 0x10)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "Unsupported CommonTypeHeader Endianness %" PRIu8 "", endianness);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (commonHeaderLength != 8)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "Unsupported CommonTypeHeader CommonHeaderLength %" PRIu16 "",
|
|
|
|
commonHeaderLength);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filler != 0xCCCCCCCC)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "Unexpected CommonTypeHeader Filler 0x%08" PRIX32 "", filler);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void smartcard_pack_common_type_header(SMARTCARD_DEVICE* smartcard, wStream* s)
|
|
|
|
{
|
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
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 */
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_unpack_private_type_header(SMARTCARD_DEVICE* smartcard, wStream* s)
|
|
|
|
{
|
|
|
|
UINT32 filler;
|
|
|
|
UINT32 objectBufferLength;
|
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "PrivateTypeHeader is too short: %" PRIuz "", Stream_GetRemainingLength(s));
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, objectBufferLength); /* ObjectBufferLength (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, filler); /* Filler (4 bytes), should be 0x00000000 */
|
|
|
|
|
|
|
|
if (filler != 0x00000000)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "Unexpected PrivateTypeHeader Filler 0x%08" PRIX32 "", filler);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (objectBufferLength != Stream_GetRemainingLength(s))
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"PrivateTypeHeader ObjectBufferLength mismatch: Actual: %" PRIu32
|
|
|
|
", Expected: %" PRIuz "",
|
|
|
|
objectBufferLength, Stream_GetRemainingLength(s));
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void smartcard_pack_private_type_header(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
UINT32 objectBufferLength)
|
|
|
|
{
|
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
Stream_Write_UINT32(s, objectBufferLength); /* ObjectBufferLength (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, 0x00000000); /* Filler (4 bytes), should be 0x00000000 */
|
|
|
|
}
|
|
|
|
|
2020-02-20 14:17:42 +03:00
|
|
|
LONG smartcard_unpack_read_size_align(SMARTCARD_DEVICE* smartcard, wStream* s, size_t size,
|
2020-01-13 12:51:22 +03:00
|
|
|
UINT32 alignment)
|
|
|
|
{
|
2020-02-20 14:17:42 +03:00
|
|
|
size_t pad;
|
2020-01-13 12:51:22 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
pad = size;
|
|
|
|
size = (size + alignment - 1) & ~(alignment - 1);
|
|
|
|
pad = size - pad;
|
|
|
|
|
|
|
|
if (pad)
|
|
|
|
Stream_Seek(s, pad);
|
|
|
|
|
2020-01-23 12:07:54 +03:00
|
|
|
return (LONG)pad;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
2020-02-20 14:17:42 +03:00
|
|
|
LONG smartcard_pack_write_size_align(SMARTCARD_DEVICE* smartcard, wStream* s, size_t size,
|
2020-01-13 12:51:22 +03:00
|
|
|
UINT32 alignment)
|
|
|
|
{
|
2020-02-20 14:17:42 +03:00
|
|
|
size_t pad;
|
2020-01-13 12:51:22 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
pad = size;
|
|
|
|
size = (size + alignment - 1) & ~(alignment - 1);
|
|
|
|
pad = size - pad;
|
|
|
|
|
|
|
|
if (pad)
|
|
|
|
{
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, pad))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
|
|
|
return SCARD_F_INTERNAL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Zero(s, pad);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCARDCONTEXT smartcard_scard_context_native_from_redir(SMARTCARD_DEVICE* smartcard,
|
|
|
|
REDIR_SCARDCONTEXT* context)
|
|
|
|
{
|
|
|
|
SCARDCONTEXT hContext = { 0 };
|
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
|
|
|
|
if ((context->cbContext != sizeof(ULONG_PTR)) && (context->cbContext != 0))
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"REDIR_SCARDCONTEXT does not match native size: Actual: %" PRIu32
|
|
|
|
", Expected: %" PRIuz "",
|
|
|
|
context->cbContext, sizeof(ULONG_PTR));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context->cbContext)
|
|
|
|
CopyMemory(&hContext, &(context->pbContext), context->cbContext);
|
|
|
|
|
|
|
|
return hContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
void smartcard_scard_context_native_to_redir(SMARTCARD_DEVICE* smartcard,
|
|
|
|
REDIR_SCARDCONTEXT* context, SCARDCONTEXT hContext)
|
|
|
|
{
|
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
ZeroMemory(context, sizeof(REDIR_SCARDCONTEXT));
|
|
|
|
context->cbContext = sizeof(ULONG_PTR);
|
|
|
|
CopyMemory(&(context->pbContext), &hContext, context->cbContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
SCARDHANDLE smartcard_scard_handle_native_from_redir(SMARTCARD_DEVICE* smartcard,
|
|
|
|
REDIR_SCARDHANDLE* handle)
|
|
|
|
{
|
|
|
|
SCARDHANDLE hCard = 0;
|
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
|
2021-02-06 17:08:57 +03:00
|
|
|
if (handle->cbHandle == 0)
|
|
|
|
return hCard;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (handle->cbHandle != sizeof(ULONG_PTR))
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"REDIR_SCARDHANDLE does not match native size: Actual: %" PRIu32
|
|
|
|
", Expected: %" PRIuz "",
|
|
|
|
handle->cbHandle, sizeof(ULONG_PTR));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handle->cbHandle)
|
|
|
|
CopyMemory(&hCard, &(handle->pbHandle), handle->cbHandle);
|
|
|
|
|
|
|
|
return hCard;
|
|
|
|
}
|
|
|
|
|
|
|
|
void smartcard_scard_handle_native_to_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDHANDLE* handle,
|
|
|
|
SCARDHANDLE hCard)
|
|
|
|
{
|
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
ZeroMemory(handle, sizeof(REDIR_SCARDHANDLE));
|
|
|
|
handle->cbHandle = sizeof(ULONG_PTR);
|
|
|
|
CopyMemory(&(handle->pbHandle), &hCard, handle->cbHandle);
|
|
|
|
}
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
LONG smartcard_unpack_redir_scard_context_(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
REDIR_SCARDCONTEXT* context, UINT32* index,
|
|
|
|
const char* file, const char* function, int line)
|
2020-01-13 12:51:22 +03:00
|
|
|
{
|
|
|
|
UINT32 pbContextNdrPtr;
|
|
|
|
WINPR_UNUSED(smartcard);
|
2020-02-13 19:26:15 +03:00
|
|
|
WINPR_UNUSED(file);
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
ZeroMemory(context, sizeof(REDIR_SCARDCONTEXT));
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "REDIR_SCARDCONTEXT is too short: %" PRIuz "", Stream_GetRemainingLength(s));
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, context->cbContext); /* cbContext (4 bytes) */
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < context->cbContext)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "REDIR_SCARDCONTEXT is too short: Actual: %" PRIuz ", Expected: %" PRIu32 "",
|
|
|
|
Stream_GetRemainingLength(s), context->cbContext);
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((context->cbContext != 0) && (context->cbContext != 4) && (context->cbContext != 8))
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "REDIR_SCARDCONTEXT length is not 0, 4 or 8: %" PRIu32 "",
|
|
|
|
context->cbContext);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read_(s, index, &pbContextNdrPtr, file, function, line))
|
|
|
|
return ERROR_INVALID_DATA;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
|
|
|
if (((context->cbContext == 0) && pbContextNdrPtr) ||
|
|
|
|
((context->cbContext != 0) && !pbContextNdrPtr))
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"REDIR_SCARDCONTEXT cbContext (%" PRIu32 ") pbContextNdrPtr (%" PRIu32
|
|
|
|
") inconsistency",
|
|
|
|
context->cbContext, pbContextNdrPtr);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context->cbContext > Stream_GetRemainingLength(s))
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "REDIR_SCARDCONTEXT is too long: Actual: %" PRIuz ", Expected: %" PRIu32 "",
|
|
|
|
Stream_GetRemainingLength(s), context->cbContext);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_pack_redir_scard_context(SMARTCARD_DEVICE* smartcard, wStream* s,
|
2020-02-17 16:07:20 +03:00
|
|
|
const REDIR_SCARDCONTEXT* context, DWORD* index)
|
2020-01-13 12:51:22 +03:00
|
|
|
{
|
2020-02-17 16:07:20 +03:00
|
|
|
const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
|
2020-01-13 12:51:22 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2020-02-17 16:07:20 +03:00
|
|
|
|
|
|
|
if (context->cbContext != 0)
|
|
|
|
{
|
|
|
|
Stream_Write_UINT32(s, context->cbContext); /* cbContext (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, pbContextNdrPtr); /* pbContextNdrPtr (4 bytes) */
|
|
|
|
*index = *index + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Stream_Zero(s, 8);
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_unpack_redir_scard_context_ref(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
REDIR_SCARDCONTEXT* context)
|
|
|
|
{
|
|
|
|
UINT32 length;
|
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
|
|
|
|
if (context->cbContext == 0)
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "REDIR_SCARDCONTEXT is too short: Actual: %" PRIuz ", Expected: 4",
|
|
|
|
Stream_GetRemainingLength(s));
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, length); /* Length (4 bytes) */
|
|
|
|
|
|
|
|
if (length != context->cbContext)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "REDIR_SCARDCONTEXT length (%" PRIu32 ") cbContext (%" PRIu32 ") mismatch",
|
|
|
|
length, context->cbContext);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((context->cbContext != 0) && (context->cbContext != 4) && (context->cbContext != 8))
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "REDIR_SCARDCONTEXT length is not 4 or 8: %" PRIu32 "", context->cbContext);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < context->cbContext)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "REDIR_SCARDCONTEXT is too short: Actual: %" PRIuz ", Expected: %" PRIu32 "",
|
|
|
|
Stream_GetRemainingLength(s), context->cbContext);
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context->cbContext)
|
|
|
|
Stream_Read(s, &(context->pbContext), context->cbContext);
|
|
|
|
else
|
|
|
|
ZeroMemory(&(context->pbContext), sizeof(context->pbContext));
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_pack_redir_scard_context_ref(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
const REDIR_SCARDCONTEXT* context)
|
|
|
|
{
|
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
Stream_Write_UINT32(s, context->cbContext); /* Length (4 bytes) */
|
|
|
|
|
|
|
|
if (context->cbContext)
|
|
|
|
{
|
|
|
|
Stream_Write(s, &(context->pbContext), context->cbContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
LONG smartcard_unpack_redir_scard_handle_(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
REDIR_SCARDHANDLE* handle, UINT32* index,
|
|
|
|
const char* file, const char* function, int line)
|
2020-01-13 12:51:22 +03:00
|
|
|
{
|
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
ZeroMemory(handle, sizeof(REDIR_SCARDHANDLE));
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "SCARDHANDLE is too short: %" PRIuz "", Stream_GetRemainingLength(s));
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, handle->cbHandle); /* Length (4 bytes) */
|
|
|
|
|
|
|
|
if ((Stream_GetRemainingLength(s) < handle->cbHandle) || (!handle->cbHandle))
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "SCARDHANDLE is too short: Actual: %" PRIuz ", Expected: %" PRIu32 "",
|
|
|
|
Stream_GetRemainingLength(s), handle->cbHandle);
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read_(s, index, NULL, file, function, line))
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_pack_redir_scard_handle(SMARTCARD_DEVICE* smartcard, wStream* s,
|
2020-02-17 16:07:20 +03:00
|
|
|
const REDIR_SCARDHANDLE* handle, DWORD* index)
|
2020-01-13 12:51:22 +03:00
|
|
|
{
|
2020-02-17 16:07:20 +03:00
|
|
|
const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
|
2020-01-13 12:51:22 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
2020-02-17 16:07:20 +03:00
|
|
|
|
|
|
|
if (handle->cbHandle != 0)
|
|
|
|
{
|
|
|
|
Stream_Write_UINT32(s, handle->cbHandle); /* cbContext (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, pbContextNdrPtr); /* pbContextNdrPtr (4 bytes) */
|
|
|
|
*index = *index + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Stream_Zero(s, 8);
|
2020-01-13 12:51:22 +03:00
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_unpack_redir_scard_handle_ref(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
REDIR_SCARDHANDLE* handle)
|
|
|
|
{
|
|
|
|
UINT32 length;
|
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "REDIR_SCARDHANDLE is too short: Actual: %" PRIuz ", Expected: 4",
|
|
|
|
Stream_GetRemainingLength(s));
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, length); /* Length (4 bytes) */
|
|
|
|
|
|
|
|
if (length != handle->cbHandle)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "REDIR_SCARDHANDLE length (%" PRIu32 ") cbHandle (%" PRIu32 ") mismatch",
|
|
|
|
length, handle->cbHandle);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((handle->cbHandle != 4) && (handle->cbHandle != 8))
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "REDIR_SCARDHANDLE length is not 4 or 8: %" PRIu32 "", handle->cbHandle);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((Stream_GetRemainingLength(s) < handle->cbHandle) || (!handle->cbHandle))
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "REDIR_SCARDHANDLE is too short: Actual: %" PRIuz ", Expected: %" PRIu32 "",
|
|
|
|
Stream_GetRemainingLength(s), handle->cbHandle);
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handle->cbHandle)
|
|
|
|
Stream_Read(s, &(handle->pbHandle), handle->cbHandle);
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_pack_redir_scard_handle_ref(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
const REDIR_SCARDHANDLE* handle)
|
|
|
|
{
|
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
Stream_Write_UINT32(s, handle->cbHandle); /* Length (4 bytes) */
|
|
|
|
|
|
|
|
if (handle->cbHandle)
|
|
|
|
Stream_Write(s, &(handle->pbHandle), handle->cbHandle);
|
|
|
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_unpack_establish_context_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
EstablishContext_Call* call)
|
|
|
|
{
|
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "EstablishContext_Call is too short: Actual: %" PRIuz ", Expected: 4",
|
|
|
|
Stream_GetRemainingLength(s));
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, call->dwScope); /* dwScope (4 bytes) */
|
|
|
|
smartcard_trace_establish_context_call(smartcard, call);
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_pack_establish_context_return(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
const EstablishContext_Return* ret)
|
|
|
|
{
|
|
|
|
LONG status;
|
2020-02-17 16:07:20 +03:00
|
|
|
DWORD index = 0;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
|
|
|
smartcard_trace_establish_context_return(smartcard, ret);
|
2020-02-17 16:07:20 +03:00
|
|
|
if (ret->ReturnCode != SCARD_S_SUCCESS)
|
|
|
|
return ret->ReturnCode;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if ((status = smartcard_pack_redir_scard_context(smartcard, s, &(ret->hContext), &index)))
|
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
return smartcard_pack_redir_scard_context_ref(smartcard, s, &(ret->hContext));
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_unpack_context_call(SMARTCARD_DEVICE* smartcard, wStream* s, Context_Call* call,
|
|
|
|
const char* name)
|
|
|
|
{
|
|
|
|
LONG status;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->handles.hContext), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status =
|
|
|
|
smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->handles.hContext))))
|
2020-01-13 12:51:22 +03:00
|
|
|
WLog_ERR(TAG, "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32 "",
|
|
|
|
status);
|
|
|
|
|
|
|
|
smartcard_trace_context_call(smartcard, call, name);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_unpack_list_reader_groups_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
ListReaderGroups_Call* call, BOOL unicode)
|
|
|
|
{
|
|
|
|
LONG status;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->handles.hContext), &index);
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
WLog_WARN(TAG, "ListReaderGroups_Call is too short: %" PRIdz, Stream_GetRemainingLength(s));
|
2020-01-13 12:51:22 +03:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_INT32(s, call->fmszGroupsIsNULL); /* fmszGroupsIsNULL (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->cchGroups); /* cchGroups (4 bytes) */
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->handles.hContext));
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
|
|
|
smartcard_trace_list_reader_groups_call(smartcard, call, unicode);
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_pack_list_reader_groups_return(SMARTCARD_DEVICE* smartcard, wStream* s,
|
2020-02-20 17:35:11 +03:00
|
|
|
const ListReaderGroups_Return* ret, BOOL unicode)
|
2020-01-13 12:51:22 +03:00
|
|
|
{
|
2021-02-06 16:28:28 +03:00
|
|
|
LONG status;
|
|
|
|
DWORD cBytes = ret->cBytes;
|
2020-02-17 16:07:20 +03:00
|
|
|
DWORD index = 0;
|
2020-02-20 17:35:11 +03:00
|
|
|
|
|
|
|
smartcard_trace_list_reader_groups_return(smartcard, ret, unicode);
|
2020-02-17 16:07:20 +03:00
|
|
|
if (ret->ReturnCode != SCARD_S_SUCCESS)
|
2021-02-06 16:28:28 +03:00
|
|
|
cBytes = 0;
|
|
|
|
if (cBytes == SCARD_AUTOALLOCATE)
|
|
|
|
cBytes = 0;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 4))
|
|
|
|
return SCARD_E_NO_MEMORY;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2021-02-06 16:28:28 +03:00
|
|
|
Stream_Write_UINT32(s, cBytes); /* cBytes (4 bytes) */
|
|
|
|
if (!smartcard_ndr_pointer_write(s, &index, cBytes))
|
2020-02-17 16:07:20 +03:00
|
|
|
return SCARD_E_NO_MEMORY;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2021-02-06 16:28:28 +03:00
|
|
|
status = smartcard_ndr_write(s, ret->msz, cBytes, 1, NDR_PTR_SIMPLE);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
|
|
|
return ret->ReturnCode;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_unpack_list_readers_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
ListReaders_Call* call, BOOL unicode)
|
|
|
|
{
|
|
|
|
LONG status;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
2020-01-13 12:51:22 +03:00
|
|
|
UINT32 mszGroupsNdrPtr;
|
|
|
|
call->mszGroups = NULL;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->handles.hContext), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 16)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "ListReaders_Call is too short: %" PRIuz "", Stream_GetRemainingLength(s));
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
Stream_Read_UINT32(s, call->cBytes); /* cBytes (4 bytes) */
|
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &mszGroupsNdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
2020-01-13 12:51:22 +03:00
|
|
|
Stream_Read_INT32(s, call->fmszReadersIsNULL); /* fmszReadersIsNULL (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->cchReaders); /* cchReaders (4 bytes) */
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status =
|
|
|
|
smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->handles.hContext))))
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
|
|
|
if (mszGroupsNdrPtr)
|
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read(s, &call->mszGroups, call->cBytes, 1, NDR_PTR_SIMPLE);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
smartcard_trace_list_readers_call(smartcard, call, unicode);
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_pack_list_readers_return(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
const ListReaders_Return* ret, BOOL unicode)
|
|
|
|
{
|
2021-02-06 16:28:28 +03:00
|
|
|
LONG status;
|
2020-02-17 16:07:20 +03:00
|
|
|
DWORD index = 0;
|
2020-02-20 17:21:17 +03:00
|
|
|
UINT32 size = unicode ? sizeof(WCHAR) : sizeof(CHAR);
|
|
|
|
|
|
|
|
size *= ret->cBytes;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
|
|
|
smartcard_trace_list_readers_return(smartcard, ret, unicode);
|
|
|
|
if (ret->ReturnCode != SCARD_S_SUCCESS)
|
2021-02-06 16:28:28 +03:00
|
|
|
size = 0;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 4))
|
2020-01-13 12:51:22 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
|
|
|
return SCARD_F_INTERNAL_ERROR;
|
|
|
|
}
|
|
|
|
|
2020-02-20 17:21:17 +03:00
|
|
|
Stream_Write_UINT32(s, size); /* cBytes (4 bytes) */
|
|
|
|
if (!smartcard_ndr_pointer_write(s, &index, size))
|
2020-02-17 16:07:20 +03:00
|
|
|
return SCARD_E_NO_MEMORY;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2021-02-06 16:28:28 +03:00
|
|
|
status = smartcard_ndr_write(s, ret->msz, size, 1, NDR_PTR_SIMPLE);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
|
|
|
return ret->ReturnCode;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_unpack_connect_common(SMARTCARD_DEVICE* smartcard, wStream* s,
|
2021-02-06 17:22:38 +03:00
|
|
|
Connect_Common_Call* common, UINT32* index)
|
2020-01-13 12:51:22 +03:00
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(common->handles.hContext), index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "Connect_Common is too short: %" PRIuz "", Stream_GetRemainingLength(s));
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, common->dwShareMode); /* dwShareMode (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, common->dwPreferredProtocols); /* dwPreferredProtocols (4 bytes) */
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_unpack_connect_a_call(SMARTCARD_DEVICE* smartcard, wStream* s, ConnectA_Call* call)
|
|
|
|
{
|
|
|
|
LONG status;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
2020-01-13 12:51:22 +03:00
|
|
|
call->szReader = NULL;
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, NULL))
|
|
|
|
return ERROR_INVALID_DATA;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if ((status = smartcard_unpack_connect_common(smartcard, s, &(call->Common), &index)))
|
2020-01-13 12:51:22 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "smartcard_unpack_connect_common failed with error %" PRId32 "", status);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read_a(s, &call->szReader, NDR_PTR_FULL);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status = smartcard_unpack_redir_scard_context_ref(smartcard, s,
|
|
|
|
&(call->Common.handles.hContext))))
|
2020-01-13 12:51:22 +03:00
|
|
|
WLog_ERR(TAG, "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32 "",
|
|
|
|
status);
|
|
|
|
|
|
|
|
smartcard_trace_connect_a_call(smartcard, call);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_unpack_connect_w_call(SMARTCARD_DEVICE* smartcard, wStream* s, ConnectW_Call* call)
|
|
|
|
{
|
|
|
|
LONG status;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
call->szReader = NULL;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, NULL))
|
|
|
|
return ERROR_INVALID_DATA;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if ((status = smartcard_unpack_connect_common(smartcard, s, &(call->Common), &index)))
|
2020-01-13 12:51:22 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "smartcard_unpack_connect_common failed with error %" PRId32 "", status);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read_w(s, &call->szReader, NDR_PTR_FULL);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status = smartcard_unpack_redir_scard_context_ref(smartcard, s,
|
|
|
|
&(call->Common.handles.hContext))))
|
2020-01-13 12:51:22 +03:00
|
|
|
WLog_ERR(TAG, "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32 "",
|
|
|
|
status);
|
|
|
|
|
|
|
|
smartcard_trace_connect_w_call(smartcard, call);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
LONG smartcard_pack_connect_return(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
const Connect_Return* ret)
|
2020-01-13 12:51:22 +03:00
|
|
|
{
|
|
|
|
LONG status;
|
2020-02-17 16:07:20 +03:00
|
|
|
DWORD index = 0;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
smartcard_trace_connect_return(smartcard, ret);
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
status = smartcard_pack_redir_scard_context(smartcard, s, &ret->hContext, &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
status = smartcard_pack_redir_scard_handle(smartcard, s, &ret->hCard, &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 4))
|
|
|
|
return SCARD_E_NO_MEMORY;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
Stream_Write_UINT32(s, ret->dwActiveProtocol); /* dwActiveProtocol (4 bytes) */
|
|
|
|
status = smartcard_pack_redir_scard_context_ref(smartcard, s, &ret->hContext);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-17 16:07:20 +03:00
|
|
|
return status;
|
|
|
|
return smartcard_pack_redir_scard_handle_ref(smartcard, s, &(ret->hCard));
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_unpack_reconnect_call(SMARTCARD_DEVICE* smartcard, wStream* s, Reconnect_Call* call)
|
|
|
|
{
|
|
|
|
LONG status;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->handles.hContext), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->handles.hCard), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "Reconnect_Call is too short: %" PRIuz "", Stream_GetRemainingLength(s));
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) */
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status =
|
|
|
|
smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->handles.hContext))))
|
2020-01-13 12:51:22 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32 "",
|
|
|
|
status);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->handles.hCard))))
|
2020-01-13 12:51:22 +03:00
|
|
|
WLog_ERR(TAG, "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32 "",
|
|
|
|
status);
|
|
|
|
|
|
|
|
smartcard_trace_reconnect_call(smartcard, call);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_pack_reconnect_return(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
const Reconnect_Return* ret)
|
|
|
|
{
|
|
|
|
smartcard_trace_reconnect_return(smartcard, ret);
|
2020-02-17 16:07:20 +03:00
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 4))
|
|
|
|
return SCARD_E_NO_MEMORY;
|
2020-01-13 12:51:22 +03:00
|
|
|
Stream_Write_UINT32(s, ret->dwActiveProtocol); /* dwActiveProtocol (4 bytes) */
|
2021-02-06 16:28:28 +03:00
|
|
|
return ret->ReturnCode;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_unpack_hcard_and_disposition_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
HCardAndDisposition_Call* call, const char* name)
|
|
|
|
{
|
|
|
|
LONG status;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->handles.hContext), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->handles.hCard), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "HCardAndDisposition_Call is too short: %" PRIuz "",
|
|
|
|
Stream_GetRemainingLength(s));
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, call->dwDisposition); /* dwDisposition (4 bytes) */
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status =
|
|
|
|
smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->handles.hContext))))
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->handles.hCard))))
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
|
|
|
smartcard_trace_hcard_and_disposition_call(smartcard, call, name);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void smartcard_trace_get_status_change_a_call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
const GetStatusChangeA_Call* call)
|
|
|
|
{
|
|
|
|
UINT32 index;
|
|
|
|
char* szEventState;
|
|
|
|
char* szCurrentState;
|
|
|
|
LPSCARD_READERSTATEA readerState;
|
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
|
2020-01-13 12:51:22 +03:00
|
|
|
return;
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "GetStatusChangeA_Call {");
|
2021-02-06 17:22:38 +03:00
|
|
|
smartcard_log_context(TAG, &call->handles.hContext);
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "dwTimeOut: 0x%08" PRIX32 " cReaders: %" PRIu32 "", call->dwTimeOut,
|
2020-01-13 12:51:22 +03:00
|
|
|
call->cReaders);
|
|
|
|
|
|
|
|
for (index = 0; index < call->cReaders; index++)
|
|
|
|
{
|
|
|
|
readerState = &call->rgReaderStates[index];
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: szReader: %s cbAtr: %" PRIu32 "", index,
|
2020-01-13 12:51:22 +03:00
|
|
|
readerState->szReader, readerState->cbAtr);
|
|
|
|
szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
|
|
|
|
szEventState = SCardGetReaderStateString(readerState->dwEventState);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: dwCurrentState: %s (0x%08" PRIX32 ")", index,
|
2020-01-13 12:51:22 +03:00
|
|
|
szCurrentState, readerState->dwCurrentState);
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: dwEventState: %s (0x%08" PRIX32 ")", index,
|
|
|
|
szEventState, readerState->dwEventState);
|
2020-01-13 12:51:22 +03:00
|
|
|
free(szCurrentState);
|
|
|
|
free(szEventState);
|
|
|
|
}
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
WLog_LVL(TAG, g_LogLevel, "}");
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
static LONG smartcard_unpack_reader_state_a(wStream* s, LPSCARD_READERSTATEA* ppcReaders,
|
|
|
|
UINT32 cReaders, UINT32* ptrIndex)
|
2020-01-13 12:51:22 +03:00
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index, len;
|
2021-02-07 14:21:44 +03:00
|
|
|
LONG status = SCARD_E_NO_MEMORY;
|
2020-02-13 19:26:15 +03:00
|
|
|
LPSCARD_READERSTATEA rgReaderStates;
|
2021-02-07 14:21:44 +03:00
|
|
|
BOOL* states;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
Stream_Read_UINT32(s, len);
|
|
|
|
if (len != cReaders)
|
2014-04-07 00:29:11 +04:00
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
WLog_ERR(TAG, "Count mismatch when reading LPSCARD_READERSTATEA");
|
|
|
|
return status;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
2020-02-13 19:26:15 +03:00
|
|
|
rgReaderStates = (LPSCARD_READERSTATEA)calloc(cReaders, sizeof(SCARD_READERSTATEA));
|
2021-02-07 14:21:44 +03:00
|
|
|
states = calloc(cReaders, sizeof(BOOL));
|
|
|
|
if (!rgReaderStates || !states)
|
|
|
|
goto fail;
|
|
|
|
status = ERROR_INVALID_DATA;
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
for (index = 0; index < cReaders; index++)
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
2021-02-07 14:21:44 +03:00
|
|
|
UINT32 ptr = UINT32_MAX;
|
2020-02-13 19:26:15 +03:00
|
|
|
LPSCARD_READERSTATEA readerState = &rgReaderStates[index];
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 52)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "GetStatusChangeA_Call is too short: %" PRIuz "",
|
|
|
|
Stream_GetRemainingLength(s));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2021-02-07 14:21:44 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, ptrIndex, &ptr))
|
|
|
|
{
|
|
|
|
if (ptr != 0)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
/* Ignore NULL length strings */
|
|
|
|
states[index] = ptr != 0;
|
2020-02-13 19:26:15 +03: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) */
|
2020-02-17 16:07:20 +03:00
|
|
|
Stream_Read(s, readerState->rgbAtr, 36); /* rgbAtr [0..36] (36 bytes) */
|
2015-07-03 14:09:03 +03:00
|
|
|
}
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
for (index = 0; index < cReaders; index++)
|
2014-04-07 00:29:11 +04:00
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
LPSCARD_READERSTATEA readerState = &rgReaderStates[index];
|
|
|
|
|
2021-02-07 14:21:44 +03:00
|
|
|
/* Ignore empty strings */
|
|
|
|
if (!states[index])
|
|
|
|
continue;
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read_a(s, &readerState->szReader, NDR_PTR_FULL);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
goto fail;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
*ppcReaders = rgReaderStates;
|
2021-02-07 14:21:44 +03:00
|
|
|
free(states);
|
2020-02-13 19:26:15 +03:00
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
fail:
|
|
|
|
if (rgReaderStates)
|
|
|
|
{
|
|
|
|
for (index = 0; index < cReaders; index++)
|
|
|
|
{
|
|
|
|
LPSCARD_READERSTATEA readerState = &rgReaderStates[index];
|
|
|
|
free(readerState->szReader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(rgReaderStates);
|
2021-02-07 14:21:44 +03:00
|
|
|
free(states);
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_unpack_reader_state_w(wStream* s, LPSCARD_READERSTATEW* ppcReaders,
|
|
|
|
UINT32 cReaders, UINT32* ptrIndex)
|
|
|
|
{
|
|
|
|
UINT32 index, len;
|
2021-02-07 14:21:44 +03:00
|
|
|
LONG status = SCARD_E_NO_MEMORY;
|
2020-02-13 19:26:15 +03:00
|
|
|
LPSCARD_READERSTATEW rgReaderStates;
|
2021-02-07 14:21:44 +03:00
|
|
|
BOOL* states;
|
2020-02-13 19:26:15 +03:00
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
return status;
|
2014-04-08 01:17:26 +04:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
Stream_Read_UINT32(s, len);
|
|
|
|
if (len != cReaders)
|
2014-04-08 01:17:26 +04:00
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
WLog_ERR(TAG, "Count mismatch when reading LPSCARD_READERSTATEW");
|
|
|
|
return status;
|
2014-04-08 01:17:26 +04:00
|
|
|
}
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
rgReaderStates = (LPSCARD_READERSTATEW)calloc(cReaders, sizeof(SCARD_READERSTATEW));
|
2021-02-07 14:21:44 +03:00
|
|
|
states = calloc(cReaders, sizeof(BOOL));
|
2020-02-13 19:26:15 +03:00
|
|
|
|
2021-02-07 14:21:44 +03:00
|
|
|
if (!rgReaderStates || !states)
|
|
|
|
goto fail;
|
2020-02-13 19:26:15 +03:00
|
|
|
|
2021-02-07 14:21:44 +03:00
|
|
|
status = ERROR_INVALID_DATA;
|
2020-02-13 19:26:15 +03:00
|
|
|
for (index = 0; index < cReaders; index++)
|
2014-04-07 00:29:11 +04:00
|
|
|
{
|
2021-02-07 14:21:44 +03:00
|
|
|
UINT32 ptr = UINT32_MAX;
|
2020-02-13 19:26:15 +03:00
|
|
|
LPSCARD_READERSTATEW readerState = &rgReaderStates[index];
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 52)
|
2014-04-27 23:45:36 +04:00
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
WLog_WARN(TAG, "GetStatusChangeA_Call is too short: %" PRIuz "",
|
|
|
|
Stream_GetRemainingLength(s));
|
|
|
|
goto fail;
|
2014-04-27 23:45:36 +04:00
|
|
|
}
|
|
|
|
|
2021-02-07 14:21:44 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, ptrIndex, &ptr))
|
|
|
|
{
|
|
|
|
if (ptr != 0)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
/* Ignore NULL length strings */
|
|
|
|
states[index] = ptr != 0;
|
2020-02-13 19:26:15 +03: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) */
|
2020-02-17 16:07:20 +03:00
|
|
|
Stream_Read(s, readerState->rgbAtr, 36); /* rgbAtr [0..36] (36 bytes) */
|
2020-02-13 19:26:15 +03:00
|
|
|
}
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
for (index = 0; index < cReaders; index++)
|
|
|
|
{
|
|
|
|
LPSCARD_READERSTATEW readerState = &rgReaderStates[index];
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2021-02-07 14:21:44 +03:00
|
|
|
/* Skip NULL pointers */
|
|
|
|
if (!states[index])
|
|
|
|
continue;
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read_w(s, &readerState->szReader, NDR_PTR_FULL);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
goto fail;
|
|
|
|
}
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
*ppcReaders = rgReaderStates;
|
2021-02-07 14:21:44 +03:00
|
|
|
free(states);
|
2020-02-13 19:26:15 +03:00
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
fail:
|
|
|
|
if (rgReaderStates)
|
|
|
|
{
|
|
|
|
for (index = 0; index < cReaders; index++)
|
2014-04-07 00:29:11 +04:00
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
LPSCARD_READERSTATEW readerState = &rgReaderStates[index];
|
|
|
|
free(readerState->szReader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(rgReaderStates);
|
2021-02-07 14:21:44 +03:00
|
|
|
free(states);
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
|
|
|
}
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
/******************************************************************************/
|
|
|
|
/************************************* End Trace Functions ********************/
|
|
|
|
/******************************************************************************/
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
LONG smartcard_unpack_get_status_change_a_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
GetStatusChangeA_Call* call)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
UINT32 ndrPtr;
|
|
|
|
UINT32 index = 0;
|
|
|
|
call->rgReaderStates = NULL;
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->handles.hContext), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "GetStatusChangeA_Call is too short: %" PRIuz "",
|
|
|
|
Stream_GetRemainingLength(s));
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
2014-04-27 23:45:36 +04:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
Stream_Read_UINT32(s, call->dwTimeOut); /* dwTimeOut (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->cReaders); /* cReaders (4 bytes) */
|
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &ndrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
2014-04-27 23:45:36 +04:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status =
|
|
|
|
smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->handles.hContext))))
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (ndrPtr)
|
|
|
|
{
|
|
|
|
status = smartcard_unpack_reader_state_a(s, &call->rgReaderStates, call->cReaders, &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_trace_get_status_change_a_call(smartcard, call);
|
2014-04-07 00:29:11 +04:00
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
LONG smartcard_unpack_get_status_change_w_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
2019-11-06 17:24:51 +03:00
|
|
|
GetStatusChangeW_Call* call)
|
2014-04-07 00:29:11 +04:00
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 ndrPtr;
|
2015-07-03 14:09:03 +03:00
|
|
|
LONG status;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
|
|
|
|
2014-04-07 00:29:11 +04:00
|
|
|
call->rgReaderStates = NULL;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->handles.hContext), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2014-04-07 00:29:11 +04:00
|
|
|
return status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "GetStatusChangeW_Call is too short: %" PRIuz "",
|
2015-06-30 18:42:01 +03:00
|
|
|
Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
Stream_Read_UINT32(s, call->dwTimeOut); /* dwTimeOut (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->cReaders); /* cReaders (4 bytes) */
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &ndrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
2014-04-07 00:29:11 +04:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status =
|
|
|
|
smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->handles.hContext))))
|
2014-04-07 00:29:11 +04:00
|
|
|
return status;
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (ndrPtr)
|
2014-04-07 00:29:11 +04:00
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_unpack_reader_state_w(s, &call->rgReaderStates, call->cReaders, &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_trace_get_status_change_w_call(smartcard, call);
|
2014-04-07 00:29:11 +04:00
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
LONG smartcard_pack_get_status_change_return(SMARTCARD_DEVICE* smartcard, wStream* s,
|
2020-01-13 12:51:22 +03:00
|
|
|
const GetStatusChange_Return* ret, BOOL unicode)
|
2014-04-07 18:59:13 +04:00
|
|
|
{
|
2021-02-06 16:28:28 +03:00
|
|
|
LONG status;
|
|
|
|
DWORD cReaders = ret->cReaders;
|
2020-02-17 16:07:20 +03:00
|
|
|
UINT32 index = 0;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
|
|
|
smartcard_trace_get_status_change_return(smartcard, ret, unicode);
|
2020-02-17 16:07:20 +03:00
|
|
|
if (ret->ReturnCode != SCARD_S_SUCCESS)
|
2021-02-06 16:28:28 +03:00
|
|
|
cReaders = 0;
|
|
|
|
if (cReaders == SCARD_AUTOALLOCATE)
|
|
|
|
cReaders = 0;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 4))
|
|
|
|
return SCARD_E_NO_MEMORY;
|
2014-04-07 18:59:13 +04:00
|
|
|
|
2021-02-06 16:28:28 +03:00
|
|
|
Stream_Write_UINT32(s, cReaders); /* cReaders (4 bytes) */
|
|
|
|
if (!smartcard_ndr_pointer_write(s, &index, cReaders))
|
2020-02-17 16:07:20 +03:00
|
|
|
return SCARD_E_NO_MEMORY;
|
2021-02-06 16:28:28 +03:00
|
|
|
status = smartcard_ndr_write_state(s, ret->rgReaderStates, cReaders, NDR_PTR_SIMPLE);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
|
|
|
return ret->ReturnCode;
|
2014-04-07 18:59:13 +04:00
|
|
|
}
|
|
|
|
|
2015-07-03 14:09:03 +03:00
|
|
|
LONG smartcard_unpack_state_call(SMARTCARD_DEVICE* smartcard, wStream* s, State_Call* call)
|
2014-04-07 05:09:49 +04:00
|
|
|
{
|
2015-07-03 14:09:03 +03:00
|
|
|
LONG status;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->handles.hContext), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2014-04-12 00:27:01 +04:00
|
|
|
return status;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->handles.hCard), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2014-04-07 05:09:49 +04:00
|
|
|
return status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "State_Call is too short: %" PRIuz "", Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
Stream_Read_INT32(s, call->fpbAtrIsNULL); /* fpbAtrIsNULL (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->cbAtrLen); /* cbAtrLen (4 bytes) */
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status =
|
|
|
|
smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->handles.hContext))))
|
2014-04-12 00:27:01 +04:00
|
|
|
return status;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->handles.hCard))))
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2015-07-03 14:09:03 +03:00
|
|
|
return status;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
LONG smartcard_pack_state_return(SMARTCARD_DEVICE* smartcard, wStream* s, const State_Return* ret)
|
2014-04-07 09:19:58 +04:00
|
|
|
{
|
2021-02-06 16:28:28 +03:00
|
|
|
LONG status;
|
|
|
|
DWORD cbAtrLen = ret->cbAtrLen;
|
2020-02-17 16:07:20 +03:00
|
|
|
DWORD index = 0;
|
|
|
|
|
|
|
|
smartcard_trace_state_return(smartcard, ret);
|
|
|
|
if (ret->ReturnCode != SCARD_S_SUCCESS)
|
2021-02-06 16:28:28 +03:00
|
|
|
cbAtrLen = 0;
|
|
|
|
if (cbAtrLen == SCARD_AUTOALLOCATE)
|
|
|
|
cbAtrLen = 0;
|
2020-02-17 16:07:20 +03:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
Stream_Write_UINT32(s, ret->dwState); /* dwState (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, ret->dwProtocol); /* dwProtocol (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, cbAtrLen); /* cbAtrLen (4 bytes) */
|
2021-02-06 16:28:28 +03:00
|
|
|
if (!smartcard_ndr_pointer_write(s, &index, cbAtrLen))
|
2020-02-17 16:07:20 +03:00
|
|
|
return SCARD_E_NO_MEMORY;
|
2021-02-06 16:28:28 +03:00
|
|
|
status = smartcard_ndr_write(s, ret->rgAtr, cbAtrLen, 1, NDR_PTR_SIMPLE);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
|
|
|
return ret->ReturnCode;
|
2014-04-07 09:19:58 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
LONG smartcard_unpack_status_call(SMARTCARD_DEVICE* smartcard, wStream* s, Status_Call* call,
|
|
|
|
BOOL unicode)
|
2014-04-07 05:09:49 +04:00
|
|
|
{
|
2015-07-03 14:09:03 +03:00
|
|
|
LONG status;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->handles.hContext), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2014-04-12 00:27:01 +04:00
|
|
|
return status;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->handles.hCard), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2014-04-07 05:09:49 +04:00
|
|
|
return status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "Status_Call is too short: %" PRIuz "", Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
Stream_Read_INT32(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-07 05:09:49 +04:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status =
|
|
|
|
smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->handles.hContext))))
|
2014-04-12 00:27:01 +04:00
|
|
|
return status;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->handles.hCard))))
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_trace_status_call(smartcard, call, unicode);
|
2015-07-03 14:09:03 +03:00
|
|
|
return status;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
LONG smartcard_pack_status_return(SMARTCARD_DEVICE* smartcard, wStream* s, const Status_Return* ret,
|
|
|
|
BOOL unicode)
|
2014-04-07 08:58:34 +04:00
|
|
|
{
|
2021-02-06 16:28:28 +03:00
|
|
|
LONG status;
|
2020-02-17 16:07:20 +03:00
|
|
|
DWORD index = 0;
|
2021-02-06 16:28:28 +03:00
|
|
|
DWORD cBytes = ret->cBytes;
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_trace_status_return(smartcard, ret, unicode);
|
2020-02-17 16:07:20 +03:00
|
|
|
if (ret->ReturnCode != SCARD_S_SUCCESS)
|
2021-02-06 16:28:28 +03:00
|
|
|
cBytes = 0;
|
|
|
|
if (cBytes == SCARD_AUTOALLOCATE)
|
|
|
|
cBytes = 0;
|
2020-02-17 16:07:20 +03:00
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 4))
|
2020-01-13 12:51:22 +03:00
|
|
|
return SCARD_F_INTERNAL_ERROR;
|
2014-04-12 02:57:04 +04:00
|
|
|
|
2021-02-06 16:28:28 +03:00
|
|
|
Stream_Write_UINT32(s, cBytes); /* cBytes (4 bytes) */
|
|
|
|
if (!smartcard_ndr_pointer_write(s, &index, cBytes))
|
2020-02-17 16:07:20 +03:00
|
|
|
return SCARD_E_NO_MEMORY;
|
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 44))
|
|
|
|
return SCARD_F_INTERNAL_ERROR;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
Stream_Write_UINT32(s, ret->dwState); /* dwState (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, ret->dwProtocol); /* dwProtocol (4 bytes) */
|
2020-03-27 17:03:59 +03:00
|
|
|
Stream_Write(s, ret->pbAtr, sizeof(ret->pbAtr)); /* pbAtr (32 bytes) */
|
2021-02-06 17:22:38 +03:00
|
|
|
Stream_Write_UINT32(s, ret->cbAtrLen); /* cbAtrLen (4 bytes) */
|
2021-02-06 16:28:28 +03:00
|
|
|
status = smartcard_ndr_write(s, ret->mszReaderNames, cBytes, 1, NDR_PTR_SIMPLE);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
|
|
|
return ret->ReturnCode;
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
|
2015-07-03 14:09:03 +03:00
|
|
|
LONG smartcard_unpack_get_attrib_call(SMARTCARD_DEVICE* smartcard, wStream* s, GetAttrib_Call* call)
|
2014-04-07 05:09:49 +04:00
|
|
|
{
|
2015-07-03 14:09:03 +03:00
|
|
|
LONG status;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->handles.hContext), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2014-04-12 00:27:01 +04:00
|
|
|
return status;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->handles.hCard), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2014-04-07 05:09:49 +04:00
|
|
|
return status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "GetAttrib_Call is too short: %" PRIuz "", Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
Stream_Read_UINT32(s, call->dwAttrId); /* dwAttrId (4 bytes) */
|
|
|
|
Stream_Read_INT32(s, call->fpbAttrIsNULL); /* fpbAttrIsNULL (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->cbAttrLen); /* cbAttrLen (4 bytes) */
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status =
|
|
|
|
smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->handles.hContext))))
|
2014-04-12 00:27:01 +04:00
|
|
|
return status;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->handles.hCard))))
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_trace_get_attrib_call(smartcard, call);
|
2015-07-03 14:09:03 +03:00
|
|
|
return status;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
LONG smartcard_pack_get_attrib_return(SMARTCARD_DEVICE* smartcard, wStream* s,
|
2021-02-07 20:48:59 +03:00
|
|
|
const GetAttrib_Return* ret, DWORD dwAttrId,
|
|
|
|
DWORD cbAttrCallLen)
|
2014-04-07 09:19:58 +04:00
|
|
|
{
|
2021-02-06 16:28:28 +03:00
|
|
|
LONG status;
|
|
|
|
DWORD cbAttrLen;
|
2020-02-17 16:07:20 +03:00
|
|
|
DWORD index = 0;
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_trace_get_attrib_return(smartcard, ret, dwAttrId);
|
2020-02-17 16:07:20 +03:00
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 4))
|
2015-07-03 14:09:03 +03:00
|
|
|
return SCARD_F_INTERNAL_ERROR;
|
2014-04-13 23:50:51 +04:00
|
|
|
|
2021-02-06 16:28:28 +03:00
|
|
|
cbAttrLen = ret->cbAttrLen;
|
2021-02-07 20:48:59 +03:00
|
|
|
if (ret->ReturnCode != SCARD_S_SUCCESS)
|
2021-02-07 20:13:18 +03:00
|
|
|
cbAttrLen = 0;
|
2021-02-06 16:28:28 +03:00
|
|
|
if (cbAttrLen == SCARD_AUTOALLOCATE)
|
|
|
|
cbAttrLen = 0;
|
2021-02-07 20:48:59 +03:00
|
|
|
if (cbAttrCallLen < cbAttrLen)
|
|
|
|
cbAttrLen = cbAttrCallLen;
|
2021-02-06 16:28:28 +03:00
|
|
|
Stream_Write_UINT32(s, cbAttrLen); /* cbAttrLen (4 bytes) */
|
|
|
|
if (!smartcard_ndr_pointer_write(s, &index, cbAttrLen))
|
2020-02-17 16:07:20 +03:00
|
|
|
return SCARD_E_NO_MEMORY;
|
2014-04-07 09:19:58 +04:00
|
|
|
|
2021-02-06 16:28:28 +03:00
|
|
|
status = smartcard_ndr_write(s, ret->pbAttr, cbAttrLen, 1, NDR_PTR_SIMPLE);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
|
|
|
return ret->ReturnCode;
|
2014-04-07 09:19:58 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
LONG smartcard_unpack_control_call(SMARTCARD_DEVICE* smartcard, wStream* s, Control_Call* call)
|
2014-04-11 22:01:42 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
LONG status;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
|
|
|
UINT32 pvInBufferNdrPtr;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
call->pvInBuffer = NULL;
|
2019-05-08 13:26:04 +03:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->handles.hContext), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
2014-04-11 22:01:42 +04:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->handles.hCard), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
2014-04-11 22:01:42 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 20)
|
2014-04-11 22:01:42 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
WLog_WARN(TAG, "Control_Call is too short: %" PRIuz "", Stream_GetRemainingLength(s));
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
Stream_Read_UINT32(s, call->dwControlCode); /* dwControlCode (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->cbInBufferSize); /* cbInBufferSize (4 bytes) */
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &pvInBufferNdrPtr)) /* pvInBufferNdrPtr (4 bytes) */
|
|
|
|
return ERROR_INVALID_DATA;
|
2020-01-13 12:51:22 +03:00
|
|
|
Stream_Read_INT32(s, call->fpvOutBufferIsNULL); /* fpvOutBufferIsNULL (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->cbOutBufferSize); /* cbOutBufferSize (4 bytes) */
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status =
|
|
|
|
smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->handles.hContext))))
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
2014-04-11 22:01:42 +04:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->handles.hCard))))
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (pvInBufferNdrPtr)
|
2020-01-13 12:51:22 +03:00
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read(s, &call->pvInBuffer, call->cbInBufferSize, 1, NDR_PTR_SIMPLE);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
smartcard_trace_control_call(smartcard, call);
|
|
|
|
return SCARD_S_SUCCESS;
|
2014-04-11 22:01:42 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
LONG smartcard_pack_control_return(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
const Control_Return* ret)
|
2014-04-07 05:09:49 +04:00
|
|
|
{
|
2021-02-06 16:28:28 +03:00
|
|
|
LONG status;
|
|
|
|
DWORD cbDataLen = ret->cbOutBufferSize;
|
2020-02-17 16:07:20 +03:00
|
|
|
DWORD index = 0;
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_trace_control_return(smartcard, ret);
|
2020-02-17 16:07:20 +03:00
|
|
|
if (ret->ReturnCode != SCARD_S_SUCCESS)
|
2021-02-06 16:28:28 +03:00
|
|
|
cbDataLen = 0;
|
|
|
|
if (cbDataLen == SCARD_AUTOALLOCATE)
|
|
|
|
cbDataLen = 0;
|
2020-02-17 16:07:20 +03:00
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 4))
|
2020-01-13 12:51:22 +03:00
|
|
|
return SCARD_F_INTERNAL_ERROR;
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2021-02-06 16:28:28 +03:00
|
|
|
Stream_Write_UINT32(s, cbDataLen); /* cbOutBufferSize (4 bytes) */
|
|
|
|
if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
|
2020-02-17 16:07:20 +03:00
|
|
|
return SCARD_E_NO_MEMORY;
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2021-02-06 16:28:28 +03:00
|
|
|
status = smartcard_ndr_write(s, ret->pvOutBuffer, cbDataLen, 1, NDR_PTR_SIMPLE);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
|
|
|
return ret->ReturnCode;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_unpack_transmit_call(SMARTCARD_DEVICE* smartcard, wStream* s, Transmit_Call* call)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
UINT32 length;
|
|
|
|
BYTE* pbExtraBytes;
|
|
|
|
UINT32 pbExtraBytesNdrPtr;
|
|
|
|
UINT32 pbSendBufferNdrPtr;
|
|
|
|
UINT32 pioRecvPciNdrPtr;
|
|
|
|
SCardIO_Request ioSendPci;
|
|
|
|
SCardIO_Request ioRecvPci;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
2020-01-13 12:51:22 +03:00
|
|
|
call->pioSendPci = NULL;
|
|
|
|
call->pioRecvPci = NULL;
|
|
|
|
call->pbSendBuffer = NULL;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->handles.hContext), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->handles.hCard), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 32)
|
2014-04-07 05:09:49 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
WLog_WARN(TAG, "Transmit_Call is too short: Actual: %" PRIuz ", Expected: 32",
|
|
|
|
Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
Stream_Read_UINT32(s, ioSendPci.dwProtocol); /* dwProtocol (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, ioSendPci.cbExtraBytes); /* cbExtraBytes (4 bytes) */
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index,
|
|
|
|
&pbExtraBytesNdrPtr)) /* pbExtraBytesNdrPtr (4 bytes) */
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
Stream_Read_UINT32(s, call->cbSendLength); /* cbSendLength (4 bytes) */
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index,
|
|
|
|
&pbSendBufferNdrPtr)) /* pbSendBufferNdrPtr (4 bytes) */
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &pioRecvPciNdrPtr)) /* pioRecvPciNdrPtr (4 bytes) */
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
Stream_Read_INT32(s, call->fpbRecvBufferIsNULL); /* fpbRecvBufferIsNULL (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, call->cbRecvLength); /* cbRecvLength (4 bytes) */
|
|
|
|
|
|
|
|
if (ioSendPci.cbExtraBytes > 1024)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"Transmit_Call ioSendPci.cbExtraBytes is out of bounds: %" PRIu32 " (max: 1024)",
|
|
|
|
ioSendPci.cbExtraBytes);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (call->cbSendLength > 66560)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "Transmit_Call cbSendLength is out of bounds: %" PRIu32 " (max: 66560)",
|
|
|
|
ioSendPci.cbExtraBytes);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status =
|
|
|
|
smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->handles.hContext))))
|
2014-04-12 00:27:01 +04:00
|
|
|
return status;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->handles.hCard))))
|
2014-04-07 05:09:49 +04:00
|
|
|
return status;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (ioSendPci.cbExtraBytes && !pbExtraBytesNdrPtr)
|
|
|
|
{
|
|
|
|
WLog_WARN(
|
|
|
|
TAG, "Transmit_Call ioSendPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pbExtraBytesNdrPtr)
|
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
// TODO: Use unified pointer reading
|
2020-01-13 12:51:22 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "Transmit_Call is too short: %" PRIuz " (ioSendPci.pbExtraBytes)",
|
|
|
|
Stream_GetRemainingLength(s));
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, length); /* Length (4 bytes) */
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < ioSendPci.cbExtraBytes)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"Transmit_Call is too short: Actual: %" PRIuz ", Expected: %" PRIu32
|
|
|
|
" (ioSendPci.cbExtraBytes)",
|
|
|
|
Stream_GetRemainingLength(s), ioSendPci.cbExtraBytes);
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ioSendPci.pbExtraBytes = Stream_Pointer(s);
|
|
|
|
call->pioSendPci =
|
|
|
|
(LPSCARD_IO_REQUEST)malloc(sizeof(SCARD_IO_REQUEST) + ioSendPci.cbExtraBytes);
|
|
|
|
|
|
|
|
if (!call->pioSendPci)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "Transmit_Call out of memory error (pioSendPci)");
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
|
|
|
|
call->pioSendPci->cbPciLength = (DWORD)(ioSendPci.cbExtraBytes + sizeof(SCARD_IO_REQUEST));
|
|
|
|
pbExtraBytes = &((BYTE*)call->pioSendPci)[sizeof(SCARD_IO_REQUEST)];
|
|
|
|
Stream_Read(s, pbExtraBytes, ioSendPci.cbExtraBytes);
|
|
|
|
smartcard_unpack_read_size_align(smartcard, s, ioSendPci.cbExtraBytes, 4);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
call->pioSendPci = (LPSCARD_IO_REQUEST)calloc(1, sizeof(SCARD_IO_REQUEST));
|
|
|
|
|
|
|
|
if (!call->pioSendPci)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "Transmit_Call out of memory error (pioSendPci)");
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
|
|
|
|
call->pioSendPci->cbPciLength = sizeof(SCARD_IO_REQUEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pbSendBufferNdrPtr)
|
2014-04-07 05:09:49 +04:00
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read(s, &call->pbSendBuffer, call->cbSendLength, 1, NDR_PTR_SIMPLE);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (pioRecvPciNdrPtr)
|
|
|
|
{
|
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "Transmit_Call is too short: Actual: %" PRIuz ", Expected: 12",
|
|
|
|
Stream_GetRemainingLength(s));
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
Stream_Read_UINT32(s, ioRecvPci.dwProtocol); /* dwProtocol (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, ioRecvPci.cbExtraBytes); /* cbExtraBytes (4 bytes) */
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index,
|
|
|
|
&pbExtraBytesNdrPtr)) /* pbExtraBytesNdrPtr (4 bytes) */
|
|
|
|
return ERROR_INVALID_DATA;
|
2014-04-14 00:48:32 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (ioRecvPci.cbExtraBytes && !pbExtraBytesNdrPtr)
|
|
|
|
{
|
|
|
|
WLog_WARN(
|
|
|
|
TAG,
|
|
|
|
"Transmit_Call ioRecvPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2014-04-14 00:48:32 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (pbExtraBytesNdrPtr)
|
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
// TODO: Unify ndr pointer reading
|
2020-01-13 12:51:22 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "Transmit_Call is too short: %" PRIuz " (ioRecvPci.pbExtraBytes)",
|
|
|
|
Stream_GetRemainingLength(s));
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
2014-04-14 00:48:32 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
Stream_Read_UINT32(s, length); /* Length (4 bytes) */
|
2014-04-14 00:48:32 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (ioRecvPci.cbExtraBytes > 1024)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"Transmit_Call ioRecvPci.cbExtraBytes is out of bounds: %" PRIu32
|
|
|
|
" (max: 1024)",
|
|
|
|
ioRecvPci.cbExtraBytes);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2014-04-14 00:48:32 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (length != ioRecvPci.cbExtraBytes)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"Transmit_Call unexpected length: Actual: %" PRIu32 ", Expected: %" PRIu32
|
|
|
|
" (ioRecvPci.cbExtraBytes)",
|
|
|
|
length, ioRecvPci.cbExtraBytes);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2014-04-14 00:48:32 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < ioRecvPci.cbExtraBytes)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"Transmit_Call is too short: Actual: %" PRIuz ", Expected: %" PRIu32
|
|
|
|
" (ioRecvPci.cbExtraBytes)",
|
|
|
|
Stream_GetRemainingLength(s), ioRecvPci.cbExtraBytes);
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
2014-04-14 00:48:32 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
ioRecvPci.pbExtraBytes = Stream_Pointer(s);
|
|
|
|
call->pioRecvPci =
|
|
|
|
(LPSCARD_IO_REQUEST)malloc(sizeof(SCARD_IO_REQUEST) + ioRecvPci.cbExtraBytes);
|
|
|
|
|
|
|
|
if (!call->pioRecvPci)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "Transmit_Call out of memory error (pioRecvPci)");
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
|
|
|
|
call->pioRecvPci->cbPciLength =
|
|
|
|
(DWORD)(ioRecvPci.cbExtraBytes + sizeof(SCARD_IO_REQUEST));
|
|
|
|
pbExtraBytes = &((BYTE*)call->pioRecvPci)[sizeof(SCARD_IO_REQUEST)];
|
|
|
|
Stream_Read(s, pbExtraBytes, ioRecvPci.cbExtraBytes);
|
|
|
|
smartcard_unpack_read_size_align(smartcard, s, ioRecvPci.cbExtraBytes, 4);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
call->pioRecvPci = (LPSCARD_IO_REQUEST)calloc(1, sizeof(SCARD_IO_REQUEST));
|
|
|
|
|
|
|
|
if (!call->pioRecvPci)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "Transmit_Call out of memory error (pioRecvPci)");
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
|
|
|
|
call->pioRecvPci->cbPciLength = sizeof(SCARD_IO_REQUEST);
|
|
|
|
}
|
2014-04-14 00:48:32 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_trace_transmit_call(smartcard, call);
|
|
|
|
return SCARD_S_SUCCESS;
|
2014-04-14 00:48:32 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
LONG smartcard_pack_transmit_return(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
const Transmit_Return* ret)
|
2014-04-07 09:19:58 +04:00
|
|
|
{
|
2021-02-06 16:28:28 +03:00
|
|
|
LONG status;
|
2020-02-17 16:07:20 +03:00
|
|
|
DWORD index = 0;
|
2015-07-03 14:09:03 +03:00
|
|
|
LONG error;
|
2020-01-13 12:51:22 +03:00
|
|
|
UINT32 cbRecvLength = ret->cbRecvLength;
|
2020-02-17 16:07:20 +03:00
|
|
|
UINT32 cbRecvPci = ret->pioRecvPci ? ret->pioRecvPci->cbPciLength : 0;
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_trace_transmit_return(smartcard, ret);
|
2020-02-17 16:07:20 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (!ret->pbRecvBuffer)
|
|
|
|
cbRecvLength = 0;
|
2014-04-13 23:50:51 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!smartcard_ndr_pointer_write(s, &index, cbRecvPci))
|
|
|
|
return SCARD_E_NO_MEMORY;
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 4))
|
|
|
|
return SCARD_E_NO_MEMORY;
|
|
|
|
Stream_Write_UINT32(s, cbRecvLength); /* cbRecvLength (4 bytes) */
|
|
|
|
if (!smartcard_ndr_pointer_write(s, &index, cbRecvLength))
|
|
|
|
return SCARD_E_NO_MEMORY;
|
2014-04-07 09:19:58 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (ret->pioRecvPci)
|
2014-04-07 09:19:58 +04:00
|
|
|
{
|
2020-02-17 16:07:20 +03:00
|
|
|
UINT32 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength - sizeof(SCARD_IO_REQUEST));
|
|
|
|
BYTE* pbExtraBytes = &((BYTE*)ret->pioRecvPci)[sizeof(SCARD_IO_REQUEST)];
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, cbExtraBytes + 16))
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
|
|
|
return SCARD_F_INTERNAL_ERROR;
|
2015-07-03 14:09:03 +03:00
|
|
|
}
|
2014-04-07 09:19:58 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
Stream_Write_UINT32(s, ret->pioRecvPci->dwProtocol); /* dwProtocol (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, cbExtraBytes); /* cbExtraBytes (4 bytes) */
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!smartcard_ndr_pointer_write(s, &index, cbExtraBytes))
|
|
|
|
return SCARD_E_NO_MEMORY;
|
|
|
|
error = smartcard_ndr_write(s, pbExtraBytes, cbExtraBytes, 1, NDR_PTR_SIMPLE);
|
|
|
|
if (error)
|
2020-01-13 12:51:22 +03:00
|
|
|
return error;
|
2014-04-14 00:48:32 +04:00
|
|
|
}
|
|
|
|
|
2021-02-06 16:28:28 +03:00
|
|
|
status = smartcard_ndr_write(s, ret->pbRecvBuffer, ret->cbRecvLength, 1, NDR_PTR_SIMPLE);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
|
|
|
return ret->ReturnCode;
|
2014-04-14 00:48:32 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
LONG smartcard_unpack_locate_cards_by_atr_a_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
LocateCardsByATRA_Call* call)
|
2014-04-07 05:09:49 +04:00
|
|
|
{
|
2015-07-03 14:09:03 +03:00
|
|
|
LONG status;
|
2020-01-13 12:51:22 +03:00
|
|
|
UINT32 rgReaderStatesNdrPtr;
|
|
|
|
UINT32 rgAtrMasksNdrPtr;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
2020-01-13 12:51:22 +03:00
|
|
|
call->rgReaderStates = NULL;
|
2014-04-12 00:27:01 +04:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->handles.hContext), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2014-04-07 05:09:49 +04:00
|
|
|
return status;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 16)
|
2014-04-07 05:09:49 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
WLog_WARN(TAG, "LocateCardsByATRA_Call is too short: %" PRIuz "",
|
2015-06-30 18:42:01 +03:00
|
|
|
Stream_GetRemainingLength(s));
|
2014-04-07 20:13:31 +04:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
Stream_Read_UINT32(s, call->cAtrs);
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &rgAtrMasksNdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
Stream_Read_UINT32(s, call->cReaders); /* cReaders (4 bytes) */
|
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &rgReaderStatesNdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
2014-04-07 21:39:47 +04:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status =
|
|
|
|
smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->handles.hContext))))
|
2014-04-12 00:27:01 +04:00
|
|
|
return status;
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
|
2014-04-08 01:17:26 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
WLog_WARN(TAG,
|
|
|
|
"LocateCardsByATRA_Call rgAtrMasksNdrPtr (0x%08" PRIX32
|
|
|
|
") and cAtrs (0x%08" PRIX32 ") inconsistency",
|
|
|
|
rgAtrMasksNdrPtr, call->cAtrs);
|
2014-04-08 01:17:26 +04:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (rgAtrMasksNdrPtr)
|
2014-04-07 05:09:49 +04:00
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read_atrmask(s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (rgReaderStatesNdrPtr)
|
2020-01-13 12:51:22 +03:00
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_unpack_reader_state_a(s, &call->rgReaderStates, call->cReaders, &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_trace_locate_cards_by_atr_a_call(smartcard, call);
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
2015-01-31 20:27:48 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
LONG smartcard_unpack_context_and_two_strings_a_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
ContextAndTwoStringA_Call* call)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
UINT32 sz1NdrPtr, sz2NdrPtr;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
2015-01-31 20:27:48 +03:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->handles.hContext), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
|
|
|
|
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &sz1NdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &sz2NdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &call->handles.hContext);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
|
|
|
if (sz1NdrPtr)
|
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read_a(s, &call->sz1, NDR_PTR_FULL);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
if (sz2NdrPtr)
|
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read_a(s, &call->sz2, NDR_PTR_FULL);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
2020-02-13 19:26:15 +03:00
|
|
|
smartcard_trace_context_and_two_strings_a_call(smartcard, call);
|
|
|
|
return SCARD_S_SUCCESS;
|
2014-04-07 05:09:49 +04:00
|
|
|
}
|
2014-04-07 07:08:40 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
LONG smartcard_unpack_context_and_two_strings_w_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
ContextAndTwoStringW_Call* call)
|
2014-04-13 23:50:51 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
LONG status;
|
|
|
|
UINT32 sz1NdrPtr, sz2NdrPtr;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->handles.hContext), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2014-04-13 23:50:51 +04:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &sz1NdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &sz2NdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
2014-04-13 23:50:51 +04:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &call->handles.hContext);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
2014-04-13 23:50:51 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (sz1NdrPtr)
|
2014-04-13 23:50:51 +04:00
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read_w(s, &call->sz1, NDR_PTR_FULL);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2014-04-13 23:50:51 +04:00
|
|
|
}
|
2020-01-13 12:51:22 +03:00
|
|
|
if (sz2NdrPtr)
|
2014-04-13 23:50:51 +04:00
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read_w(s, &call->sz2, NDR_PTR_FULL);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2014-04-13 23:50:51 +04:00
|
|
|
}
|
2020-02-13 19:26:15 +03:00
|
|
|
smartcard_trace_context_and_two_strings_w_call(smartcard, call);
|
2020-01-13 12:51:22 +03:00
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
2014-04-13 23:50:51 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
LONG smartcard_unpack_locate_cards_a_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
LocateCardsA_Call* call)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
UINT32 sz1NdrPtr, sz2NdrPtr;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->handles.hContext), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 16)
|
2014-04-13 23:50:51 +04:00
|
|
|
{
|
2020-01-23 11:48:20 +03:00
|
|
|
WLog_WARN(TAG, "%s is too short: %" PRIuz "", __FUNCTION__, Stream_GetRemainingLength(s));
|
2020-01-13 12:51:22 +03:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2014-04-13 23:50:51 +04:00
|
|
|
}
|
2020-01-13 12:51:22 +03:00
|
|
|
Stream_Read_UINT32(s, call->cBytes);
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &sz1NdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
Stream_Read_UINT32(s, call->cReaders);
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &sz2NdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (sz1NdrPtr)
|
2014-04-13 23:50:51 +04:00
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status =
|
|
|
|
smartcard_ndr_read_fixed_string_a(s, &call->mszCards, call->cBytes, NDR_PTR_SIMPLE);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2014-04-13 23:50:51 +04:00
|
|
|
}
|
2020-01-13 12:51:22 +03:00
|
|
|
if (sz2NdrPtr)
|
2014-04-13 23:50:51 +04:00
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_unpack_reader_state_a(s, &call->rgReaderStates, call->cReaders, &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
2020-02-13 19:26:15 +03:00
|
|
|
smartcard_trace_locate_cards_a_call(smartcard, call);
|
2020-01-13 12:51:22 +03:00
|
|
|
return SCARD_S_SUCCESS;
|
2014-04-13 23:50:51 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
LONG smartcard_unpack_locate_cards_w_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
LocateCardsW_Call* call)
|
2014-04-07 07:08:40 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
LONG status;
|
|
|
|
UINT32 sz1NdrPtr, sz2NdrPtr;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
2014-04-09 05:36:47 +04:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->handles.hContext), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
2014-04-09 05:36:47 +04:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 16)
|
2014-04-07 20:53:38 +04:00
|
|
|
{
|
2020-01-23 11:48:20 +03:00
|
|
|
WLog_WARN(TAG, "%s is too short: %" PRIuz "", __FUNCTION__, Stream_GetRemainingLength(s));
|
2020-01-13 12:51:22 +03:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
Stream_Read_UINT32(s, call->cBytes);
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &sz1NdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
Stream_Read_UINT32(s, call->cReaders);
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &sz2NdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (sz1NdrPtr)
|
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status =
|
|
|
|
smartcard_ndr_read_fixed_string_w(s, &call->mszCards, call->cBytes, NDR_PTR_SIMPLE);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2014-04-07 20:53:38 +04:00
|
|
|
}
|
2020-01-13 12:51:22 +03:00
|
|
|
if (sz2NdrPtr)
|
2014-04-07 07:08:40 +04:00
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_unpack_reader_state_w(s, &call->rgReaderStates, call->cReaders, &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
2020-02-13 19:26:15 +03:00
|
|
|
smartcard_trace_locate_cards_w_call(smartcard, call);
|
2014-04-07 07:08:40 +04:00
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
2014-04-10 01:44:39 +04:00
|
|
|
|
2020-01-23 11:32:34 +03:00
|
|
|
LONG smartcard_unpack_set_attrib_call(SMARTCARD_DEVICE* smartcard, wStream* s, SetAttrib_Call* call)
|
2014-04-13 23:50:51 +04:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
LONG status;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
|
|
|
UINT32 ndrPtr;
|
2014-04-13 23:50:51 +04:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->handles.hContext), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->handles.hCard), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
2014-04-13 23:50:51 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
Stream_Read_UINT32(s, call->dwAttrId);
|
|
|
|
Stream_Read_UINT32(s, call->cbAttrLen);
|
2020-03-30 12:07:47 +03:00
|
|
|
|
2021-02-06 14:40:17 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &ndrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status =
|
|
|
|
smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->handles.hContext))))
|
2020-03-30 12:07:47 +03:00
|
|
|
return status;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->handles.hCard))))
|
2020-03-30 12:07:47 +03:00
|
|
|
return status;
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (ndrPtr)
|
|
|
|
{
|
|
|
|
// TODO: call->cbAttrLen was larger than the pointer value.
|
|
|
|
// TODO: Maybe need to refine the checks?
|
|
|
|
status = smartcard_ndr_read(s, &call->pbAttr, 0, 1, NDR_PTR_SIMPLE);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
smartcard_trace_set_attrib_call(smartcard, call);
|
2020-01-13 12:51:22 +03:00
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
2014-04-13 23:50:51 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
LONG smartcard_unpack_locate_cards_by_atr_w_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
LocateCardsByATRW_Call* call)
|
2014-11-10 00:42:35 +03:00
|
|
|
{
|
2015-07-03 14:09:03 +03:00
|
|
|
LONG status;
|
2014-11-10 00:42:35 +03:00
|
|
|
UINT32 rgReaderStatesNdrPtr;
|
|
|
|
UINT32 rgAtrMasksNdrPtr;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
2014-11-10 00:42:35 +03:00
|
|
|
call->rgReaderStates = NULL;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->handles.hContext), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2014-11-10 00:42:35 +03:00
|
|
|
return status;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 16)
|
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
WLog_WARN(TAG, "LocateCardsByATRW_Call is too short: %" PRIuz "",
|
2015-06-30 18:42:01 +03:00
|
|
|
Stream_GetRemainingLength(s));
|
2014-11-10 00:42:35 +03:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, call->cAtrs);
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &rgAtrMasksNdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
Stream_Read_UINT32(s, call->cReaders); /* cReaders (4 bytes) */
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &rgReaderStatesNdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
2014-11-10 00:42:35 +03:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status =
|
|
|
|
smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->handles.hContext))))
|
2014-11-10 00:42:35 +03:00
|
|
|
return status;
|
|
|
|
|
|
|
|
if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
|
|
|
|
{
|
2015-06-30 18:42:01 +03:00
|
|
|
WLog_WARN(TAG,
|
2020-01-13 12:51:22 +03:00
|
|
|
"LocateCardsByATRW_Call rgAtrMasksNdrPtr (0x%08" PRIX32
|
2019-11-06 17:24:51 +03:00
|
|
|
") and cAtrs (0x%08" PRIX32 ") inconsistency",
|
2015-06-30 18:42:01 +03:00
|
|
|
rgAtrMasksNdrPtr, call->cAtrs);
|
2014-11-10 00:42:35 +03:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rgAtrMasksNdrPtr)
|
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read_atrmask(s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2014-11-10 00:42:35 +03:00
|
|
|
}
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (rgReaderStatesNdrPtr)
|
2014-11-10 00:42:35 +03:00
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_unpack_reader_state_w(s, &call->rgReaderStates, call->cReaders, &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
2014-11-10 00:42:35 +03:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_trace_locate_cards_by_atr_w_call(smartcard, call);
|
2014-11-10 00:42:35 +03:00
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
LONG smartcard_unpack_read_cache_a_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
ReadCacheA_Call* call)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
UINT32 mszNdrPtr;
|
|
|
|
UINT32 contextNdrPtr;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &mszNdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->Common.handles.hContext),
|
|
|
|
&index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &contextNdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
2020-01-13 12:51:22 +03:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
Stream_Read_UINT32(s, call->Common.FreshnessCounter);
|
|
|
|
Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
|
|
|
|
Stream_Read_UINT32(s, call->Common.cbDataLen);
|
|
|
|
|
|
|
|
call->szLookupName = NULL;
|
|
|
|
if (mszNdrPtr)
|
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read_a(s, &call->szLookupName, NDR_PTR_FULL);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-24 15:41:27 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &call->Common.handles.hContext);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (contextNdrPtr)
|
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read_u(s, &call->Common.CardIdentifier);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-24 15:41:27 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
2020-02-13 19:26:15 +03:00
|
|
|
smartcard_trace_read_cache_a_call(smartcard, call);
|
2020-01-13 12:51:22 +03:00
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_unpack_read_cache_w_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
ReadCacheW_Call* call)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
UINT32 mszNdrPtr;
|
|
|
|
UINT32 contextNdrPtr;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &mszNdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->Common.handles.hContext),
|
|
|
|
&index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &contextNdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
2020-01-13 12:51:22 +03:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
Stream_Read_UINT32(s, call->Common.FreshnessCounter);
|
|
|
|
Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
|
|
|
|
Stream_Read_UINT32(s, call->Common.cbDataLen);
|
|
|
|
|
|
|
|
call->szLookupName = NULL;
|
|
|
|
if (mszNdrPtr)
|
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read_w(s, &call->szLookupName, NDR_PTR_FULL);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-24 15:41:27 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &call->Common.handles.hContext);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (contextNdrPtr)
|
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read_u(s, &call->Common.CardIdentifier);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-24 15:41:27 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
2020-02-13 19:26:15 +03:00
|
|
|
smartcard_trace_read_cache_w_call(smartcard, call);
|
2020-01-13 12:51:22 +03:00
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_unpack_write_cache_a_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
WriteCacheA_Call* call)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
UINT32 mszNdrPtr;
|
|
|
|
UINT32 contextNdrPtr;
|
|
|
|
UINT32 pbDataNdrPtr;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &mszNdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->Common.handles.hContext),
|
|
|
|
&index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &contextNdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
2020-01-13 12:51:22 +03:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2020-02-13 19:26:15 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
Stream_Read_UINT32(s, call->Common.FreshnessCounter);
|
|
|
|
Stream_Read_UINT32(s, call->Common.cbDataLen);
|
2020-02-13 19:26:15 +03:00
|
|
|
|
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &pbDataNdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
|
|
|
call->szLookupName = NULL;
|
|
|
|
if (mszNdrPtr)
|
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read_a(s, &call->szLookupName, NDR_PTR_FULL);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-24 15:41:27 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &call->Common.handles.hContext);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
call->Common.CardIdentifier = NULL;
|
|
|
|
if (contextNdrPtr)
|
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read_u(s, &call->Common.CardIdentifier);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-24 15:41:27 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
call->Common.pbData = NULL;
|
|
|
|
if (pbDataNdrPtr)
|
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status =
|
|
|
|
smartcard_ndr_read(s, &call->Common.pbData, call->Common.cbDataLen, 1, NDR_PTR_SIMPLE);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-24 15:41:27 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
2020-02-13 19:26:15 +03:00
|
|
|
smartcard_trace_write_cache_a_call(smartcard, call);
|
2020-01-13 12:51:22 +03:00
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_unpack_write_cache_w_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
WriteCacheW_Call* call)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
UINT32 mszNdrPtr;
|
|
|
|
UINT32 contextNdrPtr;
|
|
|
|
UINT32 pbDataNdrPtr;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &mszNdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->Common.handles.hContext),
|
|
|
|
&index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &contextNdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
2020-01-13 12:51:22 +03:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
Stream_Read_UINT32(s, call->Common.FreshnessCounter);
|
|
|
|
Stream_Read_UINT32(s, call->Common.cbDataLen);
|
2020-02-13 19:26:15 +03:00
|
|
|
|
|
|
|
if (!smartcard_ndr_pointer_read(s, &index, &pbDataNdrPtr))
|
|
|
|
return ERROR_INVALID_DATA;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
|
|
|
call->szLookupName = NULL;
|
|
|
|
if (mszNdrPtr)
|
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read_w(s, &call->szLookupName, NDR_PTR_FULL);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-24 15:41:27 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &call->Common.handles.hContext);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-02-13 19:26:15 +03:00
|
|
|
return status;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
call->Common.CardIdentifier = NULL;
|
|
|
|
if (contextNdrPtr)
|
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status = smartcard_ndr_read_u(s, &call->Common.CardIdentifier);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-24 15:41:27 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
call->Common.pbData = NULL;
|
|
|
|
if (pbDataNdrPtr)
|
|
|
|
{
|
2020-02-13 19:26:15 +03:00
|
|
|
status =
|
|
|
|
smartcard_ndr_read(s, &call->Common.pbData, call->Common.cbDataLen, 1, NDR_PTR_SIMPLE);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-24 15:41:27 +03:00
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
2020-02-13 19:26:15 +03:00
|
|
|
smartcard_trace_write_cache_w_call(smartcard, call);
|
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_unpack_get_transmit_count_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
GetTransmitCount_Call* call)
|
|
|
|
{
|
|
|
|
LONG status;
|
2020-02-13 19:26:15 +03:00
|
|
|
UINT32 index = 0;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->handles.hContext), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->handles.hCard), &index);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status =
|
|
|
|
smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->handles.hContext))))
|
2020-03-30 12:07:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32 "",
|
|
|
|
status);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2021-02-06 17:22:38 +03:00
|
|
|
if ((status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->handles.hCard))))
|
2020-03-30 12:07:47 +03:00
|
|
|
WLog_ERR(TAG, "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32 "",
|
|
|
|
status);
|
|
|
|
|
2020-02-13 19:26:15 +03:00
|
|
|
smartcard_trace_get_transmit_count_call(smartcard, call);
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_unpack_get_reader_icon_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
GetReaderIcon_Call* call)
|
|
|
|
{
|
2021-02-06 17:22:38 +03:00
|
|
|
return smartcard_unpack_common_context_and_string_w(smartcard, s, &call->handles.hContext,
|
2020-01-13 12:51:22 +03:00
|
|
|
&call->szReaderName);
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_unpack_context_and_string_a_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
ContextAndStringA_Call* call)
|
|
|
|
{
|
2021-02-06 17:22:38 +03:00
|
|
|
return smartcard_unpack_common_context_and_string_a(smartcard, s, &call->handles.hContext,
|
|
|
|
&call->sz);
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_unpack_context_and_string_w_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
ContextAndStringW_Call* call)
|
|
|
|
{
|
2021-02-06 17:22:38 +03:00
|
|
|
return smartcard_unpack_common_context_and_string_w(smartcard, s, &call->handles.hContext,
|
|
|
|
&call->sz);
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_unpack_get_device_type_id_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
GetDeviceTypeId_Call* call)
|
|
|
|
{
|
2021-02-06 17:22:38 +03:00
|
|
|
return smartcard_unpack_common_context_and_string_w(smartcard, s, &call->handles.hContext,
|
2020-01-13 12:51:22 +03:00
|
|
|
&call->szReaderName);
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_pack_device_type_id_return(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
const GetDeviceTypeId_Return* ret)
|
2014-11-10 00:42:35 +03:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_trace_device_type_id_return(smartcard, ret);
|
2014-11-10 00:42:35 +03:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 4))
|
2020-01-13 12:51:22 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
|
|
|
return SCARD_F_INTERNAL_ERROR;
|
|
|
|
}
|
2014-11-10 00:42:35 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
Stream_Write_UINT32(s, ret->dwDeviceId); /* cBytes (4 bytes) */
|
|
|
|
|
2021-02-06 16:28:28 +03:00
|
|
|
return ret->ReturnCode;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_pack_locate_cards_return(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
const LocateCards_Return* ret)
|
|
|
|
{
|
2021-02-06 16:28:28 +03:00
|
|
|
LONG status;
|
|
|
|
DWORD cbDataLen = ret->cReaders;
|
2020-02-17 16:07:20 +03:00
|
|
|
DWORD index = 0;
|
2021-02-06 16:28:28 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_trace_locate_cards_return(smartcard, ret);
|
2020-02-17 16:07:20 +03:00
|
|
|
if (ret->ReturnCode != SCARD_S_SUCCESS)
|
2021-02-06 16:28:28 +03:00
|
|
|
cbDataLen = 0;
|
|
|
|
if (cbDataLen == SCARD_AUTOALLOCATE)
|
|
|
|
cbDataLen = 0;
|
2020-02-17 16:07:20 +03:00
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 4))
|
2014-11-10 00:42:35 +03:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
|
|
|
return SCARD_F_INTERNAL_ERROR;
|
2014-11-10 00:42:35 +03:00
|
|
|
}
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2021-02-06 16:28:28 +03:00
|
|
|
Stream_Write_UINT32(s, cbDataLen); /* cBytes (4 cbDataLen) */
|
|
|
|
if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
|
2020-02-17 16:07:20 +03:00
|
|
|
return SCARD_E_NO_MEMORY;
|
2014-11-10 00:42:35 +03:00
|
|
|
|
2021-02-06 16:28:28 +03:00
|
|
|
status = smartcard_ndr_write_state(s, ret->rgReaderStates, cbDataLen, NDR_PTR_SIMPLE);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
|
|
|
return ret->ReturnCode;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_pack_get_reader_icon_return(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
const GetReaderIcon_Return* ret)
|
|
|
|
{
|
2021-02-06 16:28:28 +03:00
|
|
|
LONG status;
|
2020-02-17 16:07:20 +03:00
|
|
|
DWORD index = 0;
|
2021-02-06 16:28:28 +03:00
|
|
|
DWORD cbDataLen = ret->cbDataLen;
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_trace_get_reader_icon_return(smartcard, ret);
|
2020-02-17 16:07:20 +03:00
|
|
|
if (ret->ReturnCode != SCARD_S_SUCCESS)
|
2021-02-06 16:28:28 +03:00
|
|
|
cbDataLen = 0;
|
|
|
|
if (cbDataLen == SCARD_AUTOALLOCATE)
|
|
|
|
cbDataLen = 0;
|
2020-02-17 16:07:20 +03:00
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 4))
|
2014-11-10 00:42:35 +03:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
|
|
|
return SCARD_F_INTERNAL_ERROR;
|
|
|
|
}
|
2014-11-10 00:42:35 +03:00
|
|
|
|
2021-02-06 16:28:28 +03:00
|
|
|
Stream_Write_UINT32(s, cbDataLen); /* cBytes (4 cbDataLen) */
|
|
|
|
if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
|
2020-02-17 16:07:20 +03:00
|
|
|
return SCARD_E_NO_MEMORY;
|
2020-01-13 12:51:22 +03:00
|
|
|
|
2021-02-06 16:28:28 +03:00
|
|
|
status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
|
|
|
return ret->ReturnCode;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_pack_get_transmit_count_return(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
const GetTransmitCount_Return* ret)
|
|
|
|
{
|
|
|
|
smartcard_trace_get_transmit_count_return(smartcard, ret);
|
2020-02-17 16:07:20 +03:00
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 4))
|
2020-01-13 12:51:22 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
|
|
|
return SCARD_F_INTERNAL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, ret->cTransmitCount); /* cBytes (4 cbDataLen) */
|
|
|
|
|
2021-02-06 16:28:28 +03:00
|
|
|
return ret->ReturnCode;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG smartcard_pack_read_cache_return(SMARTCARD_DEVICE* smartcard, wStream* s,
|
|
|
|
const ReadCache_Return* ret)
|
|
|
|
{
|
2021-02-06 16:28:28 +03:00
|
|
|
LONG status;
|
2020-02-17 16:07:20 +03:00
|
|
|
DWORD index = 0;
|
2021-02-06 16:28:28 +03:00
|
|
|
DWORD cbDataLen = ret->cbDataLen;
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_trace_read_cache_return(smartcard, ret);
|
2020-02-17 16:07:20 +03:00
|
|
|
if (ret->ReturnCode != SCARD_S_SUCCESS)
|
2021-02-06 16:28:28 +03:00
|
|
|
cbDataLen = 0;
|
|
|
|
|
|
|
|
if (cbDataLen == SCARD_AUTOALLOCATE)
|
|
|
|
cbDataLen = 0;
|
2020-02-17 16:07:20 +03:00
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 4))
|
2020-01-13 12:51:22 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
|
|
|
return SCARD_F_INTERNAL_ERROR;
|
|
|
|
}
|
|
|
|
|
2021-02-06 16:28:28 +03:00
|
|
|
Stream_Write_UINT32(s, cbDataLen); /* cBytes (4 cbDataLen) */
|
|
|
|
if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
|
2020-02-17 16:07:20 +03:00
|
|
|
return SCARD_E_NO_MEMORY;
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2021-02-06 16:28:28 +03:00
|
|
|
status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
|
|
|
return ret->ReturnCode;
|
2014-11-10 00:42:35 +03:00
|
|
|
}
|