24#include <freerdp/config.h>
27#include <winpr/print.h>
29#include <freerdp/channels/scard.h>
30#include <freerdp/utils/smartcard_pack.h>
31#include "smartcard_pack.h"
33#include <freerdp/log.h>
34#define SCARD_TAG FREERDP_TAG("scard.pack")
36static const DWORD g_LogLevel = WLOG_DEBUG;
38static wLog* scard_log(
void)
40 static wLog* log =
nullptr;
42 log = WLog_Get(SCARD_TAG);
46#define smartcard_unpack_redir_scard_context(log, s, context, index, ndr) \
47 smartcard_unpack_redir_scard_context_((log), (s), (context), (index), (ndr), __FILE__, \
49#define smartcard_unpack_redir_scard_handle(log, s, context, index) \
50 smartcard_unpack_redir_scard_handle_((log), (s), (context), (index), __FILE__, __func__, \
53WINPR_ATTR_NODISCARD
static LONG
55 UINT32* index, UINT32* ppbContextNdrPtr,
const char* file,
56 const char* function,
size_t line);
57WINPR_ATTR_NODISCARD
static LONG
60WINPR_ATTR_NODISCARD
static LONG
62 UINT32* index,
const char* file,
const char* function,
64WINPR_ATTR_NODISCARD
static LONG smartcard_pack_redir_scard_handle(wLog* log,
wStream* s,
67WINPR_ATTR_NODISCARD
static LONG
68smartcard_unpack_redir_scard_context_ref(wLog* log,
wStream* s, UINT32 pbContextNdrPtr,
70WINPR_ATTR_NODISCARD
static LONG
73WINPR_ATTR_NODISCARD
static LONG smartcard_unpack_redir_scard_handle_ref(wLog* log,
wStream* s,
75WINPR_ATTR_NODISCARD
static LONG
87#define smartcard_ndr_pointer_read(log, s, index, ptr) \
88 smartcard_ndr_pointer_read_((log), (s), (index), (ptr), __FILE__, __func__, __LINE__)
89static BOOL smartcard_ndr_pointer_read_(wLog* log,
wStream* s, UINT32* index, UINT32* ptr,
90 const char* file,
const char* fkt,
size_t line)
92 const UINT32 expect = 0x20000 + (*index) * 4;
97 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
100 Stream_Read_UINT32(s, ndrPtr);
103 if (expect != ndrPtr)
106 if (ptr && (ndrPtr == 0))
108 WLog_Print(log, WLOG_WARN,
109 "[%s:%" PRIuz
"] Read context pointer 0x%08" PRIx32
", expected 0x%08" PRIx32,
110 fkt, line, ndrPtr, expect);
114 (*index) = (*index) + 1;
118WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_read_ex(wLog* log,
wStream* s, BYTE** data,
119 size_t min,
size_t elementSize,
120 const ndr_ptr_t type,
size_t* plen)
144 return STATUS_INVALID_PARAMETER;
147 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, required))
148 return STATUS_BUFFER_TOO_SMALL;
153 Stream_Read_UINT32(s, len);
154 Stream_Read_UINT32(s, offset);
155 Stream_Read_UINT32(s, len2);
156 if (len != offset + len2)
158 WLog_Print(log, WLOG_ERROR,
159 "Invalid data when reading full NDR pointer: total=%" PRIuz
160 ", offset=%" PRIuz
", remaining=%" PRIuz,
162 return STATUS_BUFFER_TOO_SMALL;
166 Stream_Read_UINT32(s, len);
168 if ((len != min) && (min > 0))
170 WLog_Print(log, WLOG_ERROR,
171 "Invalid data when reading simple NDR pointer: total=%" PRIuz
172 ", expected=%" PRIuz,
174 return STATUS_BUFFER_TOO_SMALL;
181 return STATUS_INVALID_PARAMETER;
186 WLog_Print(log, WLOG_ERROR,
187 "Invalid length read from NDR pointer, minimum %" PRIuz
", got %" PRIuz, min,
189 return STATUS_DATA_ERROR;
192 if (len > SIZE_MAX / 2)
193 return STATUS_BUFFER_TOO_SMALL;
195 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(log, s, len, elementSize))
196 return STATUS_BUFFER_TOO_SMALL;
203 r = calloc(len +
sizeof(WCHAR),
sizeof(CHAR));
205 return SCARD_E_NO_MEMORY;
206 Stream_Read(s, r, len);
207 const LONG pad = smartcard_unpack_read_size_align(s, len, 4);
211 return STATUS_INVALID_PARAMETER;
216 return STATUS_SUCCESS;
219WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_read(wLog* log,
wStream* s, BYTE** data,
size_t min,
220 size_t elementSize,
const ndr_ptr_t type)
222 return smartcard_ndr_read_ex(log, s, data, min, elementSize, type,
nullptr);
226static BOOL smartcard_ndr_pointer_write(
wStream* s, UINT32* index, UINT32 length)
228 const UINT32 ndrPtr = 0x20000 + (*index) * 4;
232 if (!Stream_EnsureRemainingCapacity(s, 4))
237 Stream_Write_UINT32(s, ndrPtr);
238 (*index) = (*index) + 1;
241 Stream_Write_UINT32(s, 0);
245WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_write(
wStream* s,
const BYTE* data, UINT32 size,
246 UINT32 elementSize,
const ndr_ptr_t type)
248 const UINT32 offset = 0;
249 const UINT32 len = size;
250 const UINT32 dataLen = size * elementSize;
254 return SCARD_S_SUCCESS;
268 return SCARD_E_INVALID_PARAMETER;
271 if (!Stream_EnsureRemainingCapacity(s, required))
272 return STATUS_BUFFER_TOO_SMALL;
277 Stream_Write_UINT32(s, len);
278 Stream_Write_UINT32(s, offset);
279 Stream_Write_UINT32(s, len);
282 Stream_Write_UINT32(s, len);
287 return SCARD_E_INVALID_PARAMETER;
290 if (!Stream_EnsureRemainingCapacity(s, dataLen))
291 return STATUS_BUFFER_TOO_SMALL;
294 Stream_Write(s, data, dataLen);
296 Stream_Zero(s, dataLen);
297 return smartcard_pack_write_size_align(s, dataLen, 4);
300WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_write_state(
wStream* s,
302 UINT32 size,
const ndr_ptr_t type)
310 WINPR_ASSERT(data || (size == 0));
313 for (
size_t x = 0; x < size; x++)
316 if (!smartcard_reader_state_return_is_valid(x, cur))
317 return SCARD_E_INVALID_ATR;
322WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_read_state(wLog* log,
wStream* s,
324 const ndr_ptr_t type)
338 if (status != SCARD_S_SUCCESS)
342 return SCARD_E_INVALID_VALUE;
344 for (
size_t x = 0; x < min; x++)
347 if (!smartcard_reader_state_return_is_valid(x, cur))
348 return SCARD_E_INVALID_ATR;
353WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_read_atrmask(wLog* log,
wStream* s,
355 const ndr_ptr_t type)
363 const LONG status = smartcard_ndr_read(log, s, u.ppv, min,
sizeof(
LocateCards_ATRMask), type);
364 if (status != SCARD_S_SUCCESS)
371 for (
size_t x = 0; x < min; x++)
373 const UINT32 val = winpr_Data_Get_UINT32(&masks[x].cbAtr);
374 if (val > ARRAYSIZE(masks[x].rgbAtr))
376 WLog_Print(log, WLOG_ERROR,
377 "LocateCards_ATRMask[%" PRIuz
"]::cbAtr %" PRIu32
" exceeds %" PRIuz, x, val,
378 (
size_t)ARRAYSIZE(masks[x].rgbAtr));
381 return STATUS_DATA_ERROR;
384 return SCARD_S_SUCCESS;
387WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_read_fixed_string_a(wLog* log,
wStream* s,
388 CHAR** data,
size_t min,
389 const ndr_ptr_t type)
397 return smartcard_ndr_read(log, s, u.ppv, min,
sizeof(CHAR), type);
400WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_read_fixed_string_w(wLog* log,
wStream* s,
401 WCHAR** data,
size_t min,
402 const ndr_ptr_t type)
410 return smartcard_ndr_read(log, s, u.ppv, min,
sizeof(WCHAR), type);
413WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_read_a(wLog* log,
wStream* s, CHAR** data,
414 const ndr_ptr_t type)
422 return smartcard_ndr_read(log, s, u.ppv, 0,
sizeof(CHAR), type);
425WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_read_w(wLog* log,
wStream* s, WCHAR** data,
426 const ndr_ptr_t type)
434 return smartcard_ndr_read(log, s, u.ppv, 0,
sizeof(WCHAR), type);
437WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_write_w(
wStream* s,
const WCHAR* data, UINT32 size,
438 const ndr_ptr_t type)
446 return smartcard_ndr_write(s, cnv.bp, size,
sizeof(WCHAR), type);
449WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_write_a(
wStream* s,
const CHAR* data, UINT32 size,
450 const ndr_ptr_t type)
458 return smartcard_ndr_write(s, cnv.bp, size,
sizeof(CHAR), type);
461WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_read_u(wLog* log,
wStream* s,
UUID** data)
469 return smartcard_ndr_read(log, s, u.ppv, 1,
sizeof(
UUID), NDR_PTR_FIXED);
472static char* smartcard_convert_string_list(
const void* in,
size_t bytes, BOOL unicode)
481 char* mszA =
nullptr;
493 mszA = ConvertMszWCharNToUtf8Alloc(
string.wz, bytes /
sizeof(WCHAR), &length);
499 mszA = (
char*)calloc(bytes,
sizeof(
char));
502 CopyMemory(mszA,
string.sz, bytes - 1);
511 for (
size_t index = 0; index < length - 1; index++)
513 if (mszA[index] ==
'\0')
520WINPR_ATTR_MALLOC(free, 1)
521static
char* smartcard_create_msz_dump(const
char* msz,
size_t len)
523 size_t bufferLen = len;
524 char* buffer = calloc(len + 1, 1);
529 const char* cur = msz;
531 while ((len > 0) && cur && cur[0] !=
'\0' && (bufferLen > 0))
533 size_t clen = strnlen(cur, len);
534 int rc = _snprintf(buf, bufferLen,
"%s", cur);
535 bufferLen -= (size_t)rc;
544static void smartcard_msz_dump(wLog* log, DWORD level,
const char* prefix,
const void* data,
545 size_t len, UINT32 wchar)
547 if (!WLog_IsLevelActive(log, level))
551 const char* msz = WINPR_CXX_COMPAT_CAST(
const char*, data);
555 tmp = ConvertMszWCharNToUtf8Alloc(data, len, &mszlen);
559 char* array = smartcard_create_msz_dump(msz, mszlen);
560 WLog_Print(log, level,
"%s%s", prefix, array);
565WINPR_ATTR_MALLOC(free, 1)
566static
char* smartcard_create_array_dump(const
void* pd,
size_t len)
568 const BYTE* data = pd;
571 size_t bufferLen = len * 4;
574 char* buffer = calloc(bufferLen + 1, 1);
577 char* start = buffer;
579 WINPR_ASSERT(buffer || (bufferLen == 0));
581 if (!data && (len > 0))
583 (void)_snprintf(buffer, bufferLen,
"{ nullptr [%" PRIuz
"] }", len);
587 rc = _snprintf(buffer, bufferLen,
"{ ");
588 if ((rc < 0) || ((
size_t)rc >= bufferLen))
591 bufferLen -= (size_t)rc;
593 for (
size_t x = 0; x < len; x++)
595 rc = _snprintf(buffer, bufferLen,
"%02X", data[x]);
596 if ((rc < 0) || ((
size_t)rc >= bufferLen))
599 bufferLen -= (size_t)rc;
602 rc = _snprintf(buffer, bufferLen,
" }");
603 if ((rc < 0) || ((
size_t)rc >= bufferLen))
610WINPR_ATTR_FORMAT_ARG(3, 7)
611static
void smartcard_dump_array(wLog* log, DWORD level, WINPR_FORMAT_ARG const
char* prefix,
612 const
char* postfix, const
void* data,
size_t len, ...)
614 if (!WLog_IsLevelActive(log, level))
617 char* buffer = smartcard_create_array_dump(data, len);
619 char* fprefix =
nullptr;
621 va_list ap = WINPR_C_ARRAY_INIT;
623 winpr_vasprintf(&fprefix, &flen, prefix, ap);
625 WLog_Print(log, level,
"%s%s%s", fprefix, buffer, postfix);
630static void smartcard_log_redir_handle(wLog* log,
const REDIR_SCARDHANDLE* pHandle)
632 WINPR_ASSERT(pHandle);
633 smartcard_dump_array(log, g_LogLevel,
"handle: ",
"", pHandle->pbHandle, pHandle->cbHandle);
638 WINPR_ASSERT(phContext);
639 smartcard_dump_array(log, g_LogLevel,
"hContext: ",
"", phContext->pbContext,
640 phContext->cbContext);
643static void smartcard_trace_context_and_string_call_a(wLog* log,
const char* name,
647 if (!WLog_IsLevelActive(log, g_LogLevel))
650 WLog_Print(log, g_LogLevel,
"%s {", name);
651 smartcard_log_context(log, phContext);
652 WLog_Print(log, g_LogLevel,
" sz=%s", sz);
654 WLog_Print(log, g_LogLevel,
"}");
657static void smartcard_trace_context_and_string_call_w(wLog* log,
const char* name,
663 if (!WLog_IsLevelActive(log, g_LogLevel))
667 tmp = ConvertWCharToUtf8Alloc(sz,
nullptr);
669 WLog_Print(log, g_LogLevel,
"%s {", name);
670 smartcard_log_context(log, phContext);
671 WLog_Print(log, g_LogLevel,
" sz=%s", tmp);
672 WLog_Print(log, g_LogLevel,
"}");
676static void smartcard_trace_context_call(wLog* log,
const Context_Call* call,
const char* name)
680 if (!WLog_IsLevelActive(log, g_LogLevel))
683 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
684 smartcard_log_context(log, &call->handles.hContext);
686 WLog_Print(log, g_LogLevel,
"}");
694 if (!WLog_IsLevelActive(log, g_LogLevel))
697 WLog_Print(log, g_LogLevel,
"ListReaderGroups%s_Call {", unicode ?
"W" :
"A");
698 smartcard_log_context(log, &call->handles.hContext);
700 WLog_Print(log, g_LogLevel,
"fmszGroupsIsNULL: %" PRId32
" cchGroups: 0x%08" PRIx32,
701 call->fmszGroupsIsNULL, call->cchGroups);
702 WLog_Print(log, g_LogLevel,
"}");
705static void dump_reader_states_return(wLog* log,
const ReaderState_Return* rgReaderStates,
708 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
709 for (UINT32 index = 0; index < cReaders; index++)
712 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
713 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
714 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
715 szCurrentState, readerState->dwCurrentState);
716 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
717 szEventState, readerState->dwEventState);
718 free(szCurrentState);
721 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
722 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
729 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
730 for (UINT32 index = 0; index < cReaders; index++)
734 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
735 readerState->szReader, readerState->cbAtr);
736 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
737 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
738 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
739 szCurrentState, readerState->dwCurrentState);
740 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
741 szEventState, readerState->dwEventState);
742 free(szCurrentState);
745 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
746 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
753 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
754 for (UINT32 index = 0; index < cReaders; index++)
757 char* buffer = ConvertWCharToUtf8Alloc(readerState->szReader,
nullptr);
758 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
759 buffer, readerState->cbAtr);
761 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
762 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
763 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
764 szCurrentState, readerState->dwCurrentState);
765 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
766 szEventState, readerState->dwEventState);
767 free(szCurrentState);
770 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
771 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
779 if (!WLog_IsLevelActive(log, g_LogLevel))
782 WLog_Print(log, g_LogLevel,
"GetStatusChangeW_Call {");
783 smartcard_log_context(log, &call->handles.hContext);
785 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
788 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
790 WLog_Print(log, g_LogLevel,
"}");
798 if (!WLog_IsLevelActive(log, g_LogLevel))
801 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
803 WLog_Print(log, g_LogLevel,
"ListReaderGroups%s_Return {", unicode ?
"W" :
"A");
804 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIx32
")",
805 SCardGetErrorString(ret->ReturnCode),
806 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
807 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
808 WLog_Print(log, g_LogLevel,
"}");
812static void smartcard_trace_list_readers_call(wLog* log,
const ListReaders_Call* call, BOOL unicode)
816 if (!WLog_IsLevelActive(log, g_LogLevel))
819 char* mszGroupsA = smartcard_convert_string_list(call->mszGroups, call->cBytes, unicode);
821 WLog_Print(log, g_LogLevel,
"ListReaders%s_Call {", unicode ?
"W" :
"A");
822 smartcard_log_context(log, &call->handles.hContext);
824 WLog_Print(log, g_LogLevel,
825 "cBytes: %" PRIu32
" mszGroups: %s fmszReadersIsNULL: %" PRId32
826 " cchReaders: 0x%08" PRIX32
"",
827 call->cBytes, mszGroupsA, call->fmszReadersIsNULL, call->cchReaders);
828 WLog_Print(log, g_LogLevel,
"}");
833static void smartcard_trace_locate_cards_by_atr_a_call(wLog* log,
838 if (!WLog_IsLevelActive(log, g_LogLevel))
841 WLog_Print(log, g_LogLevel,
"LocateCardsByATRA_Call {");
842 smartcard_log_context(log, &call->handles.hContext);
844 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
846 WLog_Print(log, g_LogLevel,
"}");
849static void smartcard_trace_locate_cards_a_call(wLog* log,
const LocateCardsA_Call* call)
853 if (!WLog_IsLevelActive(log, g_LogLevel))
856 WLog_Print(log, g_LogLevel,
"LocateCardsA_Call {");
857 smartcard_log_context(log, &call->handles.hContext);
858 WLog_Print(log, g_LogLevel,
" cBytes=%" PRIu32, call->cBytes);
859 smartcard_msz_dump(log, g_LogLevel,
" mszCards=", call->mszCards, call->cBytes, FALSE);
860 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, call->cReaders);
861 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
863 WLog_Print(log, g_LogLevel,
"}");
866static void smartcard_trace_locate_cards_return(wLog* log,
const LocateCards_Return* ret)
870 if (!WLog_IsLevelActive(log, g_LogLevel))
873 WLog_Print(log, g_LogLevel,
"LocateCards_Return {");
874 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
875 SCardGetErrorString(ret->ReturnCode),
876 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
878 if (ret->ReturnCode == SCARD_S_SUCCESS)
880 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, ret->cReaders);
882 WLog_Print(log, g_LogLevel,
"}");
889 if (!WLog_IsLevelActive(log, g_LogLevel))
892 WLog_Print(log, g_LogLevel,
"GetReaderIcon_Return {");
893 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
894 SCardGetErrorString(ret->ReturnCode),
895 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
897 if (ret->ReturnCode == SCARD_S_SUCCESS)
899 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, ret->cbDataLen);
901 WLog_Print(log, g_LogLevel,
"}");
908 if (!WLog_IsLevelActive(log, g_LogLevel))
911 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Return {");
912 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
913 SCardGetErrorString(ret->ReturnCode),
914 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
916 WLog_Print(log, g_LogLevel,
" cTransmitCount=%" PRIu32, ret->cTransmitCount);
917 WLog_Print(log, g_LogLevel,
"}");
920static void smartcard_trace_read_cache_return(wLog* log,
const ReadCache_Return* ret)
924 if (!WLog_IsLevelActive(log, g_LogLevel))
927 WLog_Print(log, g_LogLevel,
"ReadCache_Return {");
928 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
929 SCardGetErrorString(ret->ReturnCode),
930 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
932 if (ret->ReturnCode == SCARD_S_SUCCESS)
934 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, ret->cbDataLen);
935 smartcard_dump_array(log, g_LogLevel,
" cbData: ",
"", ret->pbData, ret->cbDataLen);
937 WLog_Print(log, g_LogLevel,
"}");
940static void smartcard_trace_locate_cards_w_call(wLog* log,
const LocateCardsW_Call* call)
944 if (!WLog_IsLevelActive(log, g_LogLevel))
947 WLog_Print(log, g_LogLevel,
"LocateCardsW_Call {");
948 smartcard_log_context(log, &call->handles.hContext);
949 WLog_Print(log, g_LogLevel,
" cBytes=%" PRIu32, call->cBytes);
950 smartcard_msz_dump(log, g_LogLevel,
" sz2=", call->mszCards, call->cBytes, TRUE);
951 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, call->cReaders);
952 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
953 WLog_Print(log, g_LogLevel,
"}");
956static void smartcard_trace_list_readers_return(wLog* log,
const ListReaders_Return* ret,
961 if (!WLog_IsLevelActive(log, g_LogLevel))
964 WLog_Print(log, g_LogLevel,
"ListReaders%s_Return {", unicode ?
"W" :
"A");
965 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
966 SCardGetErrorString(ret->ReturnCode),
967 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
969 if (ret->ReturnCode != SCARD_S_SUCCESS)
971 WLog_Print(log, g_LogLevel,
"}");
975 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
977 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
978 WLog_Print(log, g_LogLevel,
"}");
982static void smartcard_trace_get_status_change_return(wLog* log,
const GetStatusChange_Return* ret,
987 if (!WLog_IsLevelActive(log, g_LogLevel))
990 WLog_Print(log, g_LogLevel,
"GetStatusChange%s_Return {", unicode ?
"W" :
"A");
991 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
992 SCardGetErrorString(ret->ReturnCode),
993 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
994 WLog_Print(log, g_LogLevel,
" cReaders: %" PRIu32
"", ret->cReaders);
996 dump_reader_states_return(log, ret->rgReaderStates, ret->cReaders);
998 if (!ret->rgReaderStates && (ret->cReaders > 0))
1000 WLog_Print(log, g_LogLevel,
" [INVALID STATE] rgReaderStates=nullptr, cReaders=%" PRIu32,
1003 else if (ret->ReturnCode != SCARD_S_SUCCESS)
1005 WLog_Print(log, g_LogLevel,
" [INVALID RETURN] rgReaderStates, cReaders=%" PRIu32,
1010 for (UINT32 index = 0; index < ret->cReaders; index++)
1013 char* szCurrentState = SCardGetReaderStateString(rgReaderState->dwCurrentState);
1014 char* szEventState = SCardGetReaderStateString(rgReaderState->dwEventState);
1015 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")",
1016 index, szCurrentState, rgReaderState->dwCurrentState);
1017 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")",
1018 index, szEventState, rgReaderState->dwEventState);
1019 smartcard_dump_array(
1020 log, g_LogLevel,
" [%" PRIu32
"]: cbAtr: %" PRIu32
" rgbAtr: ",
"",
1021 rgReaderState->rgbAtr, rgReaderState->cbAtr, index, rgReaderState->cbAtr);
1022 free(szCurrentState);
1027 WLog_Print(log, g_LogLevel,
"}");
1030static void smartcard_trace_context_and_two_strings_a_call(wLog* log,
1035 if (!WLog_IsLevelActive(log, g_LogLevel))
1038 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
1039 smartcard_log_context(log, &call->handles.hContext);
1040 WLog_Print(log, g_LogLevel,
" sz1=%s", call->sz1);
1041 WLog_Print(log, g_LogLevel,
" sz2=%s", call->sz2);
1042 WLog_Print(log, g_LogLevel,
"}");
1045static void smartcard_trace_context_and_two_strings_w_call(wLog* log,
1049 char sz1[1024] = WINPR_C_ARRAY_INIT;
1050 char sz2[1024] = WINPR_C_ARRAY_INIT;
1052 if (!WLog_IsLevelActive(log, g_LogLevel))
1055 (void)ConvertWCharToUtf8(call->sz1, sz1, ARRAYSIZE(sz1));
1057 (void)ConvertWCharToUtf8(call->sz2, sz2, ARRAYSIZE(sz2));
1059 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
1060 smartcard_log_context(log, &call->handles.hContext);
1061 WLog_Print(log, g_LogLevel,
" sz1=%s", sz1);
1062 WLog_Print(log, g_LogLevel,
" sz2=%s", sz2);
1063 WLog_Print(log, g_LogLevel,
"}");
1070 if (!WLog_IsLevelActive(log, g_LogLevel))
1073 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Call {");
1074 smartcard_log_context(log, &call->handles.hContext);
1075 smartcard_log_redir_handle(log, &call->handles.hCard);
1077 WLog_Print(log, g_LogLevel,
"}");
1080static void smartcard_trace_write_cache_a_call(wLog* log,
const WriteCacheA_Call* call)
1084 if (!WLog_IsLevelActive(log, g_LogLevel))
1087 WLog_Print(log, g_LogLevel,
"WriteCacheA_Call {");
1089 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
1091 smartcard_log_context(log, &call->Common.handles.hContext);
1092 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1094 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1095 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1096 smartcard_dump_array(log, g_LogLevel,
" pbData=",
"", call->Common.pbData,
1097 call->Common.cbDataLen);
1098 WLog_Print(log, g_LogLevel,
"}");
1101static void smartcard_trace_write_cache_w_call(wLog* log,
const WriteCacheW_Call* call)
1104 char tmp[1024] = WINPR_C_ARRAY_INIT;
1106 if (!WLog_IsLevelActive(log, g_LogLevel))
1109 WLog_Print(log, g_LogLevel,
"WriteCacheW_Call {");
1111 if (call->szLookupName)
1112 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
1113 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
1115 smartcard_log_context(log, &call->Common.handles.hContext);
1116 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1118 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1119 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1120 smartcard_dump_array(log, g_LogLevel,
" pbData=",
"", call->Common.pbData,
1121 call->Common.cbDataLen);
1122 WLog_Print(log, g_LogLevel,
"}");
1125static void smartcard_trace_read_cache_a_call(wLog* log,
const ReadCacheA_Call* call)
1129 if (!WLog_IsLevelActive(log, g_LogLevel))
1132 WLog_Print(log, g_LogLevel,
"ReadCacheA_Call {");
1134 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
1135 smartcard_log_context(log, &call->Common.handles.hContext);
1136 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1138 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1139 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1140 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1142 WLog_Print(log, g_LogLevel,
"}");
1145static void smartcard_trace_read_cache_w_call(wLog* log,
const ReadCacheW_Call* call)
1148 char tmp[1024] = WINPR_C_ARRAY_INIT;
1150 if (!WLog_IsLevelActive(log, g_LogLevel))
1153 WLog_Print(log, g_LogLevel,
"ReadCacheW_Call {");
1154 if (call->szLookupName)
1155 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
1156 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
1158 smartcard_log_context(log, &call->Common.handles.hContext);
1159 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1161 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1162 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1163 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1165 WLog_Print(log, g_LogLevel,
"}");
1168static void smartcard_trace_transmit_call(wLog* log,
const Transmit_Call* call)
1171 UINT32 cbExtraBytes = 0;
1172 BYTE* pbExtraBytes =
nullptr;
1174 if (!WLog_IsLevelActive(log, g_LogLevel))
1177 WLog_Print(log, g_LogLevel,
"Transmit_Call {");
1178 smartcard_log_context(log, &call->handles.hContext);
1179 smartcard_log_redir_handle(log, &call->handles.hCard);
1181 if (call->pioSendPci)
1183 cbExtraBytes = (UINT32)(call->pioSendPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1185 WLog_Print(log, g_LogLevel,
"pioSendPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1186 call->pioSendPci->dwProtocol, cbExtraBytes);
1190 smartcard_dump_array(log, g_LogLevel,
"pbExtraBytes: ",
"", pbExtraBytes, cbExtraBytes);
1195 WLog_Print(log, g_LogLevel,
"pioSendPci: null");
1198 WLog_Print(log, g_LogLevel,
"cbSendLength: %" PRIu32
"", call->cbSendLength);
1200 if (call->pbSendBuffer)
1202 smartcard_dump_array(log, g_LogLevel,
"pbSendBuffer: ",
"", call->pbSendBuffer,
1203 call->cbSendLength);
1207 WLog_Print(log, g_LogLevel,
"pbSendBuffer: null");
1210 if (call->pioRecvPci)
1212 cbExtraBytes = (UINT32)(call->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1214 WLog_Print(log, g_LogLevel,
"pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1215 call->pioRecvPci->dwProtocol, cbExtraBytes);
1219 smartcard_dump_array(log, g_LogLevel,
"pbExtraBytes: ",
"", pbExtraBytes, cbExtraBytes);
1224 WLog_Print(log, g_LogLevel,
"pioRecvPci: null");
1227 WLog_Print(log, g_LogLevel,
"fpbRecvBufferIsNULL: %" PRId32
" cbRecvLength: %" PRIu32
"",
1228 call->fpbRecvBufferIsNULL, call->cbRecvLength);
1229 WLog_Print(log, g_LogLevel,
"}");
1232static void smartcard_trace_locate_cards_by_atr_w_call(wLog* log,
1237 if (!WLog_IsLevelActive(log, g_LogLevel))
1240 WLog_Print(log, g_LogLevel,
"LocateCardsByATRW_Call {");
1241 smartcard_log_context(log, &call->handles.hContext);
1243 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
1245 WLog_Print(log, g_LogLevel,
"}");
1248static void smartcard_trace_transmit_return(wLog* log,
const Transmit_Return* ret)
1251 UINT32 cbExtraBytes = 0;
1252 BYTE* pbExtraBytes =
nullptr;
1254 if (!WLog_IsLevelActive(log, g_LogLevel))
1257 WLog_Print(log, g_LogLevel,
"Transmit_Return {");
1258 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1259 SCardGetErrorString(ret->ReturnCode),
1260 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1262 if (ret->pioRecvPci)
1264 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1266 WLog_Print(log, g_LogLevel,
1267 " pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1268 ret->pioRecvPci->dwProtocol, cbExtraBytes);
1272 smartcard_dump_array(log, g_LogLevel,
" pbExtraBytes: ",
"", pbExtraBytes,
1278 WLog_Print(log, g_LogLevel,
" pioRecvPci: null");
1281 WLog_Print(log, g_LogLevel,
" cbRecvLength: %" PRIu32
"", ret->cbRecvLength);
1283 if (ret->pbRecvBuffer)
1285 smartcard_dump_array(log, g_LogLevel,
" pbRecvBuffer: ",
"", ret->pbRecvBuffer,
1290 WLog_Print(log, g_LogLevel,
" pbRecvBuffer: null");
1293 WLog_Print(log, g_LogLevel,
"}");
1296static void smartcard_trace_control_return(wLog* log,
const Control_Return* ret)
1300 if (!WLog_IsLevelActive(log, g_LogLevel))
1303 WLog_Print(log, g_LogLevel,
"Control_Return {");
1304 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1305 SCardGetErrorString(ret->ReturnCode),
1306 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1307 WLog_Print(log, g_LogLevel,
" cbOutBufferSize: %" PRIu32
"", ret->cbOutBufferSize);
1309 if (ret->pvOutBuffer)
1311 smartcard_dump_array(log, g_LogLevel,
"pvOutBuffer: ",
"", ret->pvOutBuffer,
1312 ret->cbOutBufferSize);
1316 WLog_Print(log, g_LogLevel,
"pvOutBuffer: null");
1319 WLog_Print(log, g_LogLevel,
"}");
1322static void smartcard_trace_control_call(wLog* log,
const Control_Call* call)
1326 if (!WLog_IsLevelActive(log, g_LogLevel))
1329 WLog_Print(log, g_LogLevel,
"Control_Call {");
1330 smartcard_log_context(log, &call->handles.hContext);
1331 smartcard_log_redir_handle(log, &call->handles.hCard);
1333 WLog_Print(log, g_LogLevel,
1334 "dwControlCode: 0x%08" PRIX32
" cbInBufferSize: %" PRIu32
1335 " fpvOutBufferIsNULL: %" PRId32
" cbOutBufferSize: %" PRIu32
"",
1336 call->dwControlCode, call->cbInBufferSize, call->fpvOutBufferIsNULL,
1337 call->cbOutBufferSize);
1339 if (call->pvInBuffer)
1341 smartcard_dump_array(log, WLOG_DEBUG,
"pbInBuffer: ",
"", call->pvInBuffer,
1342 call->cbInBufferSize);
1346 WLog_Print(log, g_LogLevel,
"pvInBuffer: null");
1349 WLog_Print(log, g_LogLevel,
"}");
1352static void smartcard_trace_set_attrib_call(wLog* log,
const SetAttrib_Call* call)
1356 if (!WLog_IsLevelActive(log, g_LogLevel))
1359 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1360 smartcard_log_context(log, &call->handles.hContext);
1361 smartcard_log_redir_handle(log, &call->handles.hCard);
1362 WLog_Print(log, g_LogLevel,
"dwAttrId: 0x%08" PRIX32, call->dwAttrId);
1363 WLog_Print(log, g_LogLevel,
"cbAttrLen: 0x%08" PRIx32, call->cbAttrLen);
1364 smartcard_dump_array(log, g_LogLevel,
"pbAttr: ",
"", call->pbAttr, call->cbAttrLen);
1365 WLog_Print(log, g_LogLevel,
"}");
1368static void smartcard_trace_get_attrib_return(wLog* log,
const GetAttrib_Return* ret,
1373 if (!WLog_IsLevelActive(log, g_LogLevel))
1376 WLog_Print(log, g_LogLevel,
"GetAttrib_Return {");
1377 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1378 SCardGetErrorString(ret->ReturnCode),
1379 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1380 WLog_Print(log, g_LogLevel,
" dwAttrId: %s (0x%08" PRIX32
") cbAttrLen: 0x%08" PRIX32
"",
1381 SCardGetAttributeString(dwAttrId), dwAttrId, ret->cbAttrLen);
1382 smartcard_dump_array(log, g_LogLevel,
" ",
"", ret->pbAttr, ret->cbAttrLen);
1384 WLog_Print(log, g_LogLevel,
"}");
1387static void smartcard_trace_get_attrib_call(wLog* log,
const GetAttrib_Call* call)
1391 if (!WLog_IsLevelActive(log, g_LogLevel))
1394 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1395 smartcard_log_context(log, &call->handles.hContext);
1396 smartcard_log_redir_handle(log, &call->handles.hCard);
1398 WLog_Print(log, g_LogLevel,
1399 "dwAttrId: %s (0x%08" PRIX32
") fpbAttrIsNULL: %" PRId32
" cbAttrLen: 0x%08" PRIX32
1401 SCardGetAttributeString(call->dwAttrId), call->dwAttrId, call->fpbAttrIsNULL,
1403 WLog_Print(log, g_LogLevel,
"}");
1406static void smartcard_trace_status_call(wLog* log,
const Status_Call* call, BOOL unicode)
1410 if (!WLog_IsLevelActive(log, g_LogLevel))
1413 WLog_Print(log, g_LogLevel,
"Status%s_Call {", unicode ?
"W" :
"A");
1414 smartcard_log_context(log, &call->handles.hContext);
1415 smartcard_log_redir_handle(log, &call->handles.hCard);
1417 WLog_Print(log, g_LogLevel,
1418 "fmszReaderNamesIsNULL: %" PRId32
" cchReaderLen: %" PRIu32
" cbAtrLen: %" PRIu32
"",
1419 call->fmszReaderNamesIsNULL, call->cchReaderLen, call->cbAtrLen);
1420 WLog_Print(log, g_LogLevel,
"}");
1423static void smartcard_trace_status_return(wLog* log,
const Status_Return* ret, BOOL unicode)
1426 char* mszReaderNamesA =
nullptr;
1429 if (!WLog_IsLevelActive(log, g_LogLevel))
1431 cBytes = ret->cBytes;
1432 if (ret->ReturnCode != SCARD_S_SUCCESS)
1434 if (cBytes == SCARD_AUTOALLOCATE)
1436 mszReaderNamesA = smartcard_convert_string_list(ret->mszReaderNames, cBytes, unicode);
1438 WLog_Print(log, g_LogLevel,
"Status%s_Return {", unicode ?
"W" :
"A");
1439 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1440 SCardGetErrorString(ret->ReturnCode),
1441 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1442 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
") dwProtocol: %s (0x%08" PRIX32
")",
1443 SCardGetCardStateString(ret->dwState), ret->dwState,
1444 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1446 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" mszReaderNames: %s", ret->cBytes,
1449 smartcard_dump_array(log, g_LogLevel,
" cbAtrLen: %" PRIu32
" pbAtr: ",
"", ret->pbAtr,
1450 ret->cbAtrLen, ret->cbAtrLen);
1451 WLog_Print(log, g_LogLevel,
"}");
1452 free(mszReaderNamesA);
1455static void smartcard_trace_state_return(wLog* log,
const State_Return* ret)
1458 char* state =
nullptr;
1460 if (!WLog_IsLevelActive(log, g_LogLevel))
1463 state = SCardGetReaderStateString(ret->dwState);
1464 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1465 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1466 SCardGetErrorString(ret->ReturnCode),
1467 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1468 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
")", state, ret->dwState);
1469 WLog_Print(log, g_LogLevel,
" dwProtocol: %s (0x%08" PRIX32
")",
1470 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1471 WLog_Print(log, g_LogLevel,
" cbAtrLen: (0x%08" PRIX32
")", ret->cbAtrLen);
1472 smartcard_dump_array(log, g_LogLevel,
" rgAtr: ",
"", ret->rgAtr,
sizeof(ret->rgAtr));
1473 WLog_Print(log, g_LogLevel,
"}");
1477static void smartcard_trace_reconnect_return(wLog* log,
const Reconnect_Return* ret)
1481 if (!WLog_IsLevelActive(log, g_LogLevel))
1484 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1485 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1486 SCardGetErrorString(ret->ReturnCode),
1487 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1488 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1489 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1490 WLog_Print(log, g_LogLevel,
"}");
1493static void smartcard_trace_connect_a_call(wLog* log,
const ConnectA_Call* call)
1497 if (!WLog_IsLevelActive(log, g_LogLevel))
1500 WLog_Print(log, g_LogLevel,
"ConnectA_Call {");
1501 smartcard_log_context(log, &call->Common.handles.hContext);
1503 WLog_Print(log, g_LogLevel,
1504 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1505 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1506 call->szReader, SCardGetShareModeString(call->Common.dwShareMode),
1507 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1508 call->Common.dwPreferredProtocols);
1509 WLog_Print(log, g_LogLevel,
"}");
1512static void smartcard_trace_connect_w_call(wLog* log,
const ConnectW_Call* call)
1515 char szReaderA[1024] = WINPR_C_ARRAY_INIT;
1517 if (!WLog_IsLevelActive(log, g_LogLevel))
1521 (void)ConvertWCharToUtf8(call->szReader, szReaderA, ARRAYSIZE(szReaderA));
1522 WLog_Print(log, g_LogLevel,
"ConnectW_Call {");
1523 smartcard_log_context(log, &call->Common.handles.hContext);
1525 WLog_Print(log, g_LogLevel,
1526 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1527 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1528 szReaderA, SCardGetShareModeString(call->Common.dwShareMode),
1529 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1530 call->Common.dwPreferredProtocols);
1531 WLog_Print(log, g_LogLevel,
"}");
1534static void smartcard_trace_hcard_and_disposition_call(wLog* log,
1540 if (!WLog_IsLevelActive(log, g_LogLevel))
1543 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
1544 smartcard_log_context(log, &call->handles.hContext);
1545 smartcard_log_redir_handle(log, &call->handles.hCard);
1547 WLog_Print(log, g_LogLevel,
"dwDisposition: %s (0x%08" PRIX32
")",
1548 SCardGetDispositionString(call->dwDisposition), call->dwDisposition);
1549 WLog_Print(log, g_LogLevel,
"}");
1556 if (!WLog_IsLevelActive(log, g_LogLevel))
1559 WLog_Print(log, g_LogLevel,
"EstablishContext_Call {");
1560 WLog_Print(log, g_LogLevel,
"dwScope: %s (0x%08" PRIX32
")", SCardGetScopeString(call->dwScope),
1562 WLog_Print(log, g_LogLevel,
"}");
1569 if (!WLog_IsLevelActive(log, g_LogLevel))
1572 WLog_Print(log, g_LogLevel,
"EstablishContext_Return {");
1573 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1574 SCardGetErrorString(ret->ReturnCode),
1575 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1576 smartcard_log_context(log, &ret->hContext);
1578 WLog_Print(log, g_LogLevel,
"}");
1581void smartcard_trace_long_return(
const Long_Return* ret,
const char* name)
1583 wLog* log = scard_log();
1584 smartcard_trace_long_return_int(log, ret, name);
1587void smartcard_trace_long_return_int(wLog* log,
const Long_Return* ret,
const char* name)
1591 if (!WLog_IsLevelActive(log, g_LogLevel))
1594 WLog_Print(log, g_LogLevel,
"%s_Return {", name);
1595 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1596 SCardGetErrorString(ret->ReturnCode),
1597 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1598 WLog_Print(log, g_LogLevel,
"}");
1601static void smartcard_trace_connect_return(wLog* log,
const Connect_Return* ret)
1605 if (!WLog_IsLevelActive(log, g_LogLevel))
1608 WLog_Print(log, g_LogLevel,
"Connect_Return {");
1609 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1610 SCardGetErrorString(ret->ReturnCode),
1611 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1612 smartcard_log_context(log, &ret->hContext);
1613 smartcard_log_redir_handle(log, &ret->hCard);
1615 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1616 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1617 WLog_Print(log, g_LogLevel,
"}");
1620static void smartcard_trace_reconnect_call(wLog* log,
const Reconnect_Call* call)
1624 if (!WLog_IsLevelActive(log, g_LogLevel))
1627 WLog_Print(log, g_LogLevel,
"Reconnect_Call {");
1628 smartcard_log_context(log, &call->handles.hContext);
1629 smartcard_log_redir_handle(log, &call->handles.hCard);
1631 WLog_Print(log, g_LogLevel,
1632 "dwShareMode: %s (0x%08" PRIX32
") dwPreferredProtocols: %s (0x%08" PRIX32
1633 ") dwInitialization: %s (0x%08" PRIX32
")",
1634 SCardGetShareModeString(call->dwShareMode), call->dwShareMode,
1635 SCardGetProtocolString(call->dwPreferredProtocols), call->dwPreferredProtocols,
1636 SCardGetDispositionString(call->dwInitialization), call->dwInitialization);
1637 WLog_Print(log, g_LogLevel,
"}");
1644 if (!WLog_IsLevelActive(log, g_LogLevel))
1647 WLog_Print(log, g_LogLevel,
"GetDeviceTypeId_Return {");
1648 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1649 SCardGetErrorString(ret->ReturnCode),
1650 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1651 WLog_Print(log, g_LogLevel,
" dwDeviceId=%08" PRIx32, ret->dwDeviceId);
1653 WLog_Print(log, g_LogLevel,
"}");
1656WINPR_ATTR_NODISCARD
static LONG
1658 CHAR** pszReaderName)
1661 UINT32 pbContextNdrPtr = 0;
1662 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1663 if (status != SCARD_S_SUCCESS)
1666 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
1667 return ERROR_INVALID_DATA;
1669 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1670 if (status != SCARD_S_SUCCESS)
1673 status = smartcard_ndr_read_a(log, s, pszReaderName, NDR_PTR_FULL);
1674 if (status != SCARD_S_SUCCESS)
1677 smartcard_trace_context_and_string_call_a(log, __func__, phContext, *pszReaderName);
1678 return SCARD_S_SUCCESS;
1681WINPR_ATTR_NODISCARD
static LONG
1683 WCHAR** pszReaderName)
1686 UINT32 pbContextNdrPtr = 0;
1688 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1689 if (status != SCARD_S_SUCCESS)
1692 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
1693 return ERROR_INVALID_DATA;
1695 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1696 if (status != SCARD_S_SUCCESS)
1699 status = smartcard_ndr_read_w(log, s, pszReaderName, NDR_PTR_FULL);
1700 if (status != SCARD_S_SUCCESS)
1703 smartcard_trace_context_and_string_call_w(log, __func__, phContext, *pszReaderName);
1704 return SCARD_S_SUCCESS;
1707LONG smartcard_unpack_common_type_header(
wStream* s)
1709 wLog* log = scard_log();
1712 UINT8 endianness = 0;
1713 UINT16 commonHeaderLength = 0;
1715 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1716 return STATUS_BUFFER_TOO_SMALL;
1719 Stream_Read_UINT8(s, version);
1720 Stream_Read_UINT8(s, endianness);
1721 Stream_Read_UINT16(s, commonHeaderLength);
1722 Stream_Read_UINT32(s, filler);
1726 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Version %" PRIu8
"", version);
1727 return STATUS_INVALID_PARAMETER;
1730 if (endianness != 0x10)
1732 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Endianness %" PRIu8
"",
1734 return STATUS_INVALID_PARAMETER;
1737 if (commonHeaderLength != 8)
1739 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader CommonHeaderLength %" PRIu16
"",
1740 commonHeaderLength);
1741 return STATUS_INVALID_PARAMETER;
1744 if (filler != 0xCCCCCCCC)
1746 WLog_Print(log, WLOG_WARN,
"Unexpected CommonTypeHeader Filler 0x%08" PRIX32
"", filler);
1747 return STATUS_INVALID_PARAMETER;
1750 return SCARD_S_SUCCESS;
1753void smartcard_pack_common_type_header(
wStream* s)
1755 Stream_Write_UINT8(s, 1);
1756 Stream_Write_UINT8(s, 0x10);
1757 Stream_Write_UINT16(s, 8);
1758 Stream_Write_UINT32(s, 0xCCCCCCCC);
1761LONG smartcard_unpack_private_type_header(
wStream* s)
1763 wLog* log = scard_log();
1765 UINT32 objectBufferLength = 0;
1767 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1768 return STATUS_BUFFER_TOO_SMALL;
1770 Stream_Read_UINT32(s, objectBufferLength);
1771 Stream_Read_UINT32(s, filler);
1773 if (filler != 0x00000000)
1775 WLog_Print(log, WLOG_WARN,
"Unexpected PrivateTypeHeader Filler 0x%08" PRIX32
"", filler);
1776 return STATUS_INVALID_PARAMETER;
1779 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, objectBufferLength))
1780 return STATUS_INVALID_PARAMETER;
1782 return SCARD_S_SUCCESS;
1785void smartcard_pack_private_type_header(
wStream* s, UINT32 objectBufferLength)
1787 Stream_Write_UINT32(s, objectBufferLength);
1788 Stream_Write_UINT32(s, 0x00000000);
1791LONG smartcard_unpack_read_size_align(
wStream* s,
size_t size, UINT32 alignment)
1793 const size_t padsize = (size + alignment - 1) & ~(alignment - 1);
1794 const size_t pad = padsize - size;
1798 if (!Stream_SafeSeek(s, pad))
1805LONG smartcard_pack_write_size_align(
wStream* s,
size_t size, UINT32 alignment)
1807 const size_t padsize = (size + alignment - 1) & ~(alignment - 1);
1808 const size_t pad = padsize - size;
1812 if (!Stream_EnsureRemainingCapacity(s, pad))
1814 wLog* log = scard_log();
1815 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
1816 return SCARD_F_INTERNAL_ERROR;
1819 Stream_Zero(s, pad);
1822 return SCARD_S_SUCCESS;
1825SCARDCONTEXT smartcard_scard_context_native_from_redir(
const REDIR_SCARDCONTEXT* context)
1827 SCARDCONTEXT hContext = WINPR_C_ARRAY_INIT;
1829 WINPR_ASSERT(context);
1830 if ((context->cbContext !=
sizeof(ULONG_PTR)) && (context->cbContext != 0))
1832 wLog* log = scard_log();
1833 WLog_Print(log, WLOG_WARN,
1834 "REDIR_SCARDCONTEXT does not match native size: Actual: %" PRIu32
1835 ", Expected: %" PRIuz
"",
1836 context->cbContext,
sizeof(ULONG_PTR));
1840 if (context->cbContext)
1841 CopyMemory(&hContext, &(context->pbContext), context->cbContext);
1846void smartcard_scard_context_native_to_redir(
REDIR_SCARDCONTEXT* context, SCARDCONTEXT hContext)
1848 WINPR_ASSERT(context);
1850 context->cbContext =
sizeof(ULONG_PTR);
1851 CopyMemory(&(context->pbContext), &hContext, context->cbContext);
1854SCARDHANDLE smartcard_scard_handle_native_from_redir(
const REDIR_SCARDHANDLE* handle)
1856 SCARDHANDLE hCard = 0;
1858 WINPR_ASSERT(handle);
1859 if (handle->cbHandle == 0)
1862 if (handle->cbHandle !=
sizeof(ULONG_PTR))
1864 wLog* log = scard_log();
1865 WLog_Print(log, WLOG_WARN,
1866 "REDIR_SCARDHANDLE does not match native size: Actual: %" PRIu32
1867 ", Expected: %" PRIuz
"",
1868 handle->cbHandle,
sizeof(ULONG_PTR));
1872 if (handle->cbHandle)
1873 CopyMemory(&hCard, &(handle->pbHandle), handle->cbHandle);
1878void smartcard_scard_handle_native_to_redir(
REDIR_SCARDHANDLE* handle, SCARDHANDLE hCard)
1880 WINPR_ASSERT(handle);
1882 handle->cbHandle =
sizeof(ULONG_PTR);
1883 CopyMemory(&(handle->pbHandle), &hCard, handle->cbHandle);
1886#define smartcard_context_supported(log, size) \
1887 smartcard_context_supported_((log), (size), __FILE__, __func__, __LINE__)
1888WINPR_ATTR_NODISCARD
static LONG smartcard_context_supported_(wLog* log, uint32_t size,
1889 const char* file,
const char* fkt,
1897 return SCARD_S_SUCCESS;
1900 const uint32_t level = WLOG_WARN;
1901 if (WLog_IsLevelActive(log, level))
1903 WLog_PrintTextMessage(log, level, line, file, fkt,
1904 "REDIR_SCARDCONTEXT length is not 0, 4 or 8: %" PRIu32
"",
1907 return STATUS_INVALID_PARAMETER;
1913 UINT32* index, UINT32* ppbContextNdrPtr,
1914 const char* file,
const char* function,
size_t line)
1916 UINT32 pbContextNdrPtr = 0;
1919 WINPR_ASSERT(context);
1923 if (!Stream_CheckAndLogRequiredLengthWLogEx(log, WLOG_WARN, s, 4, 1,
"%s(%s:%" PRIuz
")", file,
1925 return STATUS_BUFFER_TOO_SMALL;
1927 const LONG status = smartcard_context_supported_(log, context->cbContext, file, function, line);
1928 if (status != SCARD_S_SUCCESS)
1931 Stream_Read_UINT32(s, context->cbContext);
1932 if (context->cbContext > 16)
1934 WLog_Print(log, WLOG_WARN,
"REDIR_SCARDCONTEXT cbContext (%" PRIu32
") > 16",
1935 context->cbContext);
1936 return ERROR_INVALID_DATA;
1939 if (!smartcard_ndr_pointer_read_(log, s, index, &pbContextNdrPtr, file, function, line))
1940 return ERROR_INVALID_DATA;
1942 if (((context->cbContext == 0) && pbContextNdrPtr) ||
1943 ((context->cbContext != 0) && !pbContextNdrPtr))
1945 WLog_Print(log, WLOG_WARN,
1946 "REDIR_SCARDCONTEXT cbContext (%" PRIu32
") pbContextNdrPtr (%" PRIu32
1948 context->cbContext, pbContextNdrPtr);
1949 return STATUS_INVALID_PARAMETER;
1952 *ppbContextNdrPtr = pbContextNdrPtr;
1953 return SCARD_S_SUCCESS;
1956LONG smartcard_pack_redir_scard_context(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1959 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
1961 WINPR_ASSERT(context);
1962 if (!Stream_EnsureRemainingCapacity(s, 8))
1963 return SCARD_E_NO_MEMORY;
1965 if (context->cbContext != 0)
1967 Stream_Write_UINT32(s, context->cbContext);
1968 Stream_Write_UINT32(s, pbContextNdrPtr);
1969 *index = *index + 1;
1974 return SCARD_S_SUCCESS;
1977LONG smartcard_unpack_redir_scard_context_ref(wLog* log,
wStream* s,
1978 WINPR_ATTR_UNUSED UINT32 pbContextNdrPtr,
1983 WINPR_ASSERT(context);
1985 if (context->cbContext == 0)
1986 return SCARD_S_SUCCESS;
1988 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1989 return STATUS_BUFFER_TOO_SMALL;
1991 Stream_Read_UINT32(s, length);
1993 if (length != context->cbContext)
1995 WLog_Print(log, WLOG_WARN,
1996 "REDIR_SCARDCONTEXT length (%" PRIu32
") cbContext (%" PRIu32
") mismatch",
1997 length, context->cbContext);
1998 return STATUS_INVALID_PARAMETER;
2001 const LONG status = smartcard_context_supported(log, context->cbContext);
2002 if (status != SCARD_S_SUCCESS)
2005 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, context->cbContext))
2006 return STATUS_BUFFER_TOO_SMALL;
2008 if (context->cbContext)
2009 Stream_Read(s, &(context->pbContext), context->cbContext);
2011 ZeroMemory(&(context->pbContext),
sizeof(context->pbContext));
2013 return SCARD_S_SUCCESS;
2016LONG smartcard_pack_redir_scard_context_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
2019 WINPR_ASSERT(context);
2021 if (context->cbContext == 0)
2022 return SCARD_S_SUCCESS;
2024 if (context->cbContext >
sizeof(context->pbContext))
2025 return SCARD_E_INVALID_PARAMETER;
2027 if (!Stream_EnsureRemainingCapacity(s, 4ull + context->cbContext))
2028 return SCARD_E_NO_MEMORY;
2030 Stream_Write_UINT32(s, context->cbContext);
2031 Stream_Write(s, &(context->pbContext), context->cbContext);
2033 return SCARD_S_SUCCESS;
2037 UINT32* index,
const char* file,
const char* function,
2040 UINT32 pbHandleNdrPtr = 0;
2042 WINPR_ASSERT(handle);
2045 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2046 return STATUS_BUFFER_TOO_SMALL;
2048 Stream_Read_UINT32(s, handle->cbHandle);
2050 if (!smartcard_ndr_pointer_read_(log, s, index, &pbHandleNdrPtr, file, function, line))
2051 return ERROR_INVALID_DATA;
2053 if (((handle->cbHandle == 0) && pbHandleNdrPtr) ||
2054 ((handle->cbHandle != 0) && !pbHandleNdrPtr))
2056 WLog_Print(log, WLOG_WARN,
2057 "REDIR_SCARDHANDLE cbHandle (%" PRIu32
") pbHandleNdrPtr (%" PRIu32
2059 handle->cbHandle, pbHandleNdrPtr);
2060 return STATUS_INVALID_PARAMETER;
2063 return SCARD_S_SUCCESS;
2066LONG smartcard_pack_redir_scard_handle(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
2069 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
2071 WINPR_ASSERT(handle);
2072 if (!Stream_EnsureRemainingCapacity(s, 8))
2073 return SCARD_E_NO_MEMORY;
2075 if (handle->cbHandle != 0)
2077 Stream_Write_UINT32(s, handle->cbHandle);
2078 Stream_Write_UINT32(s, pbContextNdrPtr);
2079 *index = *index + 1;
2083 return SCARD_S_SUCCESS;
2090 WINPR_ASSERT(handle);
2092 if (handle->cbHandle == 0)
2093 return SCARD_S_SUCCESS;
2095 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2096 return STATUS_BUFFER_TOO_SMALL;
2098 Stream_Read_UINT32(s, length);
2100 if (length != handle->cbHandle)
2102 WLog_Print(log, WLOG_WARN,
2103 "REDIR_SCARDHANDLE length (%" PRIu32
") cbHandle (%" PRIu32
") mismatch", length,
2105 return STATUS_INVALID_PARAMETER;
2108 if ((handle->cbHandle != 4) && (handle->cbHandle != 8))
2110 WLog_Print(log, WLOG_WARN,
"REDIR_SCARDHANDLE length is not 4 or 8: %" PRIu32
"",
2112 return STATUS_INVALID_PARAMETER;
2115 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, handle->cbHandle))
2116 return STATUS_BUFFER_TOO_SMALL;
2118 if (handle->cbHandle)
2119 Stream_Read(s, &(handle->pbHandle), handle->cbHandle);
2121 return SCARD_S_SUCCESS;
2124LONG smartcard_pack_redir_scard_handle_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
2127 WINPR_ASSERT(handle);
2129 if (handle->cbHandle == 0)
2130 return SCARD_S_SUCCESS;
2132 if (handle->cbHandle >
sizeof(handle->pbHandle))
2133 return SCARD_E_INVALID_PARAMETER;
2135 if (!Stream_EnsureRemainingCapacity(s, 4ull + handle->cbHandle))
2136 return SCARD_E_NO_MEMORY;
2138 Stream_Write_UINT32(s, handle->cbHandle);
2139 Stream_Write(s, &(handle->pbHandle), handle->cbHandle);
2141 return SCARD_S_SUCCESS;
2147 wLog* log = scard_log();
2149 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2150 return STATUS_BUFFER_TOO_SMALL;
2152 Stream_Read_UINT32(s, call->dwScope);
2153 smartcard_trace_establish_context_call(log, call);
2154 return SCARD_S_SUCCESS;
2160 wLog* log = scard_log();
2162 smartcard_trace_establish_context_call(log, call);
2164 if (!Stream_EnsureRemainingCapacity(s, 4))
2165 return SCARD_E_NO_MEMORY;
2167 Stream_Write_UINT32(s, call->dwScope);
2169 return SCARD_S_SUCCESS;
2175 wLog* log = scard_log();
2179 smartcard_trace_establish_context_return(log, ret);
2180 if (ret->ReturnCode != SCARD_S_SUCCESS)
2181 return ret->ReturnCode;
2183 status = smartcard_pack_redir_scard_context(log, s, &(ret->hContext), &index);
2184 if (status != SCARD_S_SUCCESS)
2187 return smartcard_pack_redir_scard_context_ref(log, s, &(ret->hContext));
2193 wLog* log = scard_log();
2195 UINT32 pbContextNdrPtr = 0;
2198 smartcard_unpack_redir_scard_context(log, s, &(ret->hContext), &index, &pbContextNdrPtr);
2199 if (status != SCARD_S_SUCCESS)
2202 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &(ret->hContext));
2203 if (status != SCARD_S_SUCCESS)
2206 smartcard_trace_establish_context_return(log, ret);
2207 return SCARD_S_SUCCESS;
2213 UINT32 pbContextNdrPtr = 0;
2214 wLog* log = scard_log();
2217 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2219 if (status != SCARD_S_SUCCESS)
2222 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2223 &(call->handles.hContext));
2224 if (status != SCARD_S_SUCCESS)
2225 WLog_Print(log, WLOG_ERROR,
2226 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2229 smartcard_trace_context_call(log, call, name);
2236 UINT32 pbContextNdrPtr = 0;
2237 wLog* log = scard_log();
2240 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2243 if (status != SCARD_S_SUCCESS)
2246 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2247 return STATUS_BUFFER_TOO_SMALL;
2249 Stream_Read_INT32(s, call->fmszGroupsIsNULL);
2250 Stream_Read_UINT32(s, call->cchGroups);
2251 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2252 &(call->handles.hContext));
2254 if (status != SCARD_S_SUCCESS)
2257 smartcard_trace_list_reader_groups_call(log, call, unicode);
2258 return SCARD_S_SUCCESS;
2265 wLog* log = scard_log();
2268 smartcard_trace_list_reader_groups_call(log, call, unicode);
2270 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
2271 if (status != SCARD_S_SUCCESS)
2274 if (!Stream_EnsureRemainingCapacity(s, 8))
2275 return SCARD_E_NO_MEMORY;
2277 Stream_Write_INT32(s, call->fmszGroupsIsNULL);
2278 Stream_Write_UINT32(s, call->cchGroups);
2280 return smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
2287 wLog* log = scard_log();
2289 UINT32 cBytes = ret->cBytes;
2292 smartcard_trace_list_reader_groups_return(log, ret, unicode);
2293 if (ret->ReturnCode != SCARD_S_SUCCESS)
2295 if (cBytes == SCARD_AUTOALLOCATE)
2298 if (!Stream_EnsureRemainingCapacity(s, 4))
2299 return SCARD_E_NO_MEMORY;
2303 WLog_Print(log, WLOG_ERROR,
2304 "2.2.3.4 ListReaderGroups_Return and ListReaders_Return cBytes (%" PRIu32
2307 return SCARD_E_INVALID_PARAMETER;
2310 Stream_Write_UINT32(s, cBytes);
2311 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
2312 return SCARD_E_NO_MEMORY;
2314 status = smartcard_ndr_write(s, ret->msz, cBytes, 1, NDR_PTR_SIMPLE);
2315 if (status != SCARD_S_SUCCESS)
2317 return ret->ReturnCode;
2324 wLog* log = scard_log();
2326 UINT32 mszNdrPtr = 0;
2328 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2329 return STATUS_BUFFER_TOO_SMALL;
2331 const UINT32 cBytes = Stream_Get_UINT32(s);
2334 WLog_Print(log, WLOG_ERROR,
2335 "2.2.3.4 ListReaderGroups_Return and ListReaders_Return cBytes (%" PRIu32
2338 return SCARD_E_INVALID_PARAMETER;
2341 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
2342 return ERROR_INVALID_DATA;
2346 LONG status = smartcard_ndr_read(log, s, &ret->msz, cBytes, 1, NDR_PTR_SIMPLE);
2347 if (status != SCARD_S_SUCCESS)
2349 ret->cBytes = cBytes;
2352 smartcard_trace_list_reader_groups_return(log, ret, unicode);
2353 return SCARD_S_SUCCESS;
2359 UINT32 mszGroupsNdrPtr = 0;
2360 UINT32 pbContextNdrPtr = 0;
2361 wLog* log = scard_log();
2364 call->mszGroups =
nullptr;
2366 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2368 if (status != SCARD_S_SUCCESS)
2371 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2372 return STATUS_BUFFER_TOO_SMALL;
2374 const UINT32 cBytes = Stream_Get_UINT32(s);
2377 WLog_Print(log, WLOG_ERROR,
2378 "2.2.3.4 ListReaderGroups_Return and ListReaders_Return cBytes (%" PRIu32
2381 return SCARD_E_INVALID_PARAMETER;
2383 if (unicode && ((cBytes % 2) != 0))
2385 WLog_Print(log, WLOG_ERROR,
2386 "2.2.3.4 ListReaderGroupsW_Return and ListReadersW_Return cBytes (%" PRIu32
2389 return SCARD_E_INVALID_PARAMETER;
2391 if (!smartcard_ndr_pointer_read(log, s, &index, &mszGroupsNdrPtr))
2392 return ERROR_INVALID_DATA;
2394 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2395 return STATUS_BUFFER_TOO_SMALL;
2396 Stream_Read_INT32(s, call->fmszReadersIsNULL);
2397 Stream_Read_UINT32(s, call->cchReaders);
2399 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2400 &(call->handles.hContext));
2401 if (status != SCARD_S_SUCCESS)
2404 if (mszGroupsNdrPtr)
2406 status = smartcard_ndr_read(log, s, &call->mszGroups, cBytes, 1, NDR_PTR_SIMPLE);
2407 if (status != SCARD_S_SUCCESS)
2409 call->cBytes = cBytes;
2412 smartcard_trace_list_readers_call(log, call, unicode);
2413 return SCARD_S_SUCCESS;
2416LONG smartcard_pack_list_readers_return(
wStream* s,
const ListReaders_Return* ret, BOOL unicode)
2419 wLog* log = scard_log();
2422 UINT32 size = ret->cBytes;
2424 smartcard_trace_list_readers_return(log, ret, unicode);
2425 if (ret->ReturnCode != SCARD_S_SUCCESS)
2428 if (!Stream_EnsureRemainingCapacity(s, 4))
2430 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
2431 return SCARD_F_INTERNAL_ERROR;
2436 WLog_Print(log, WLOG_ERROR,
2437 "2.2.3.4 ListReaderGroups_Return and ListReaders_Return cBytes (%" PRIu32
2440 return SCARD_E_INVALID_PARAMETER;
2443 Stream_Write_UINT32(s, size);
2444 if (!smartcard_ndr_pointer_write(s, &index, size))
2445 return SCARD_E_NO_MEMORY;
2447 status = smartcard_ndr_write(s, ret->msz, size, 1, NDR_PTR_SIMPLE);
2448 if (status != SCARD_S_SUCCESS)
2450 return ret->ReturnCode;
2453WINPR_ATTR_NODISCARD
static LONG smartcard_unpack_connect_common(wLog* log,
wStream* s,
2456 UINT32* ppbContextNdrPtr)
2458 WINPR_ASSERT(common);
2459 LONG status = smartcard_unpack_redir_scard_context(log, s, &(common->handles.hContext), index,
2461 if (status != SCARD_S_SUCCESS)
2464 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2465 return STATUS_BUFFER_TOO_SMALL;
2467 Stream_Read_UINT32(s, common->dwShareMode);
2468 Stream_Read_UINT32(s, common->dwPreferredProtocols);
2469 return SCARD_S_SUCCESS;
2476 UINT32 pbContextNdrPtr = 0;
2479 wLog* log = scard_log();
2481 call->szReader =
nullptr;
2483 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
2484 return ERROR_INVALID_DATA;
2486 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2487 if (status != SCARD_S_SUCCESS)
2489 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2494 status = smartcard_ndr_read_a(log, s, &call->szReader, NDR_PTR_FULL);
2495 if (status != SCARD_S_SUCCESS)
2498 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2499 &(call->Common.handles.hContext));
2500 if (status != SCARD_S_SUCCESS)
2501 WLog_Print(log, WLOG_ERROR,
2502 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2505 smartcard_trace_connect_a_call(log, call);
2513 UINT32 pbContextNdrPtr = 0;
2516 wLog* log = scard_log();
2517 call->szReader =
nullptr;
2519 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
2520 return ERROR_INVALID_DATA;
2522 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2523 if (status != SCARD_S_SUCCESS)
2525 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2530 status = smartcard_ndr_read_w(log, s, &call->szReader, NDR_PTR_FULL);
2531 if (status != SCARD_S_SUCCESS)
2534 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2535 &(call->Common.handles.hContext));
2536 if (status != SCARD_S_SUCCESS)
2537 WLog_Print(log, WLOG_ERROR,
2538 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2541 smartcard_trace_connect_w_call(log, call);
2551 wLog* log = scard_log();
2552 smartcard_trace_connect_return(log, ret);
2554 status = smartcard_pack_redir_scard_context(log, s, &ret->hContext, &index);
2555 if (status != SCARD_S_SUCCESS)
2558 status = smartcard_pack_redir_scard_handle(log, s, &ret->hCard, &index);
2559 if (status != SCARD_S_SUCCESS)
2562 if (!Stream_EnsureRemainingCapacity(s, 4))
2563 return SCARD_E_NO_MEMORY;
2565 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2566 status = smartcard_pack_redir_scard_context_ref(log, s, &ret->hContext);
2567 if (status != SCARD_S_SUCCESS)
2569 return smartcard_pack_redir_scard_handle_ref(log, s, &(ret->hCard));
2575 UINT32 pbContextNdrPtr = 0;
2578 wLog* log = scard_log();
2579 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2581 if (status != SCARD_S_SUCCESS)
2584 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2585 if (status != SCARD_S_SUCCESS)
2588 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2589 return STATUS_BUFFER_TOO_SMALL;
2591 Stream_Read_UINT32(s, call->dwShareMode);
2592 Stream_Read_UINT32(s, call->dwPreferredProtocols);
2593 Stream_Read_UINT32(s, call->dwInitialization);
2595 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2596 &(call->handles.hContext));
2597 if (status != SCARD_S_SUCCESS)
2599 WLog_Print(log, WLOG_ERROR,
2600 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2605 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2606 if (status != SCARD_S_SUCCESS)
2607 WLog_Print(log, WLOG_ERROR,
2608 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
2610 smartcard_trace_reconnect_call(log, call);
2617 wLog* log = scard_log();
2620 smartcard_trace_reconnect_call(log, call);
2622 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
2623 if (status != SCARD_S_SUCCESS)
2626 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
2627 if (status != SCARD_S_SUCCESS)
2630 if (!Stream_EnsureRemainingCapacity(s, 12))
2631 return SCARD_E_NO_MEMORY;
2633 Stream_Write_UINT32(s, call->dwShareMode);
2634 Stream_Write_UINT32(s, call->dwPreferredProtocols);
2635 Stream_Write_UINT32(s, call->dwInitialization);
2637 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
2638 if (status != SCARD_S_SUCCESS)
2641 return smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
2647 wLog* log = scard_log();
2648 smartcard_trace_reconnect_return(log, ret);
2650 if (!Stream_EnsureRemainingCapacity(s, 4))
2651 return SCARD_E_NO_MEMORY;
2652 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2653 return ret->ReturnCode;
2659 wLog* log = scard_log();
2661 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2662 return STATUS_BUFFER_TOO_SMALL;
2664 Stream_Read_UINT32(s, ret->dwActiveProtocol);
2666 smartcard_trace_reconnect_return(log, ret);
2667 return SCARD_S_SUCCESS;
2674 UINT32 pbContextNdrPtr = 0;
2677 wLog* log = scard_log();
2679 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2681 if (status != SCARD_S_SUCCESS)
2684 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2685 if (status != SCARD_S_SUCCESS)
2688 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2689 return STATUS_BUFFER_TOO_SMALL;
2691 Stream_Read_UINT32(s, call->dwDisposition);
2693 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2694 &(call->handles.hContext));
2695 if (status != SCARD_S_SUCCESS)
2698 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2699 if (status != SCARD_S_SUCCESS)
2702 smartcard_trace_hcard_and_disposition_call(log, call, name);
2710 if (!WLog_IsLevelActive(log, g_LogLevel))
2713 WLog_Print(log, g_LogLevel,
"GetStatusChangeA_Call {");
2714 smartcard_log_context(log, &call->handles.hContext);
2716 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
2719 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
2721 WLog_Print(log, g_LogLevel,
"}");
2724WINPR_ATTR_NODISCARD
static LONG smartcard_unpack_reader_state_a(wLog* log,
wStream* s,
2725 LPSCARD_READERSTATEA* ppcReaders,
2726 UINT32 cReaders, UINT32* ptrIndex)
2728 LONG status = SCARD_E_NO_MEMORY;
2730 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2731 if (cReaders > UINT8_MAX)
2733 WLog_Print(log, WLOG_ERROR,
2734 "Too many readers(%" PRIu32
"), rejecting request. Limited to <= %d", cReaders,
2736 return SCARD_E_WRITE_TOO_MANY;
2739 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2742 const UINT32 len = Stream_Get_UINT32(s);
2743 if (len != cReaders)
2745 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEA");
2749 LPSCARD_READERSTATEA rgReaderStates =
2751 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2752 if (!rgReaderStates || !states)
2754 status = ERROR_INVALID_DATA;
2756 for (UINT32 index = 0; index < cReaders; index++)
2758 UINT32 ptr = UINT32_MAX;
2759 LPSCARD_READERSTATEA readerState = &rgReaderStates[index];
2761 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2764 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2770 states[index] = ptr != 0;
2771 Stream_Read_UINT32(s, readerState->dwCurrentState);
2772 Stream_Read_UINT32(s, readerState->dwEventState);
2773 Stream_Read_UINT32(s, readerState->cbAtr);
2774 if (readerState->cbAtr > ARRAYSIZE(readerState->rgbAtr))
2776 WLog_Print(log, WLOG_WARN,
2777 "SCARD_READERSTATEA[%" PRIu32
"]::cbAtr %" PRIu32
" exceeds %" PRIuz, index,
2778 readerState->cbAtr, (
size_t)ARRAYSIZE(readerState->rgbAtr));
2779 readerState->cbAtr = ARRAYSIZE(readerState->rgbAtr);
2781 Stream_Read(s, readerState->rgbAtr, 36);
2784 for (UINT32 index = 0; index < cReaders; index++)
2786 LPSCARD_READERSTATEA readerState = &rgReaderStates[index];
2791 status = smartcard_ndr_read_a(log, s, &readerState->szReader, NDR_PTR_FULL);
2792 if (status != SCARD_S_SUCCESS)
2794 if (!readerState->szReader)
2798 *ppcReaders = rgReaderStates;
2800 return SCARD_S_SUCCESS;
2804 for (UINT32 index = 0; index < cReaders; index++)
2806 LPSCARD_READERSTATEA readerState = &rgReaderStates[index];
2807 free(readerState->szReader);
2810 free(rgReaderStates);
2815WINPR_ATTR_NODISCARD
static LONG smartcard_unpack_reader_state_w(wLog* log,
wStream* s,
2816 LPSCARD_READERSTATEW* ppcReaders,
2817 UINT32 cReaders, UINT32* ptrIndex)
2819 LONG status = SCARD_E_NO_MEMORY;
2821 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2823 if (cReaders > UINT8_MAX)
2825 WLog_Print(log, WLOG_ERROR,
2826 "Too many readers(%" PRIu32
"), rejecting request. Limited to <= %d", cReaders,
2828 return SCARD_E_WRITE_TOO_MANY;
2831 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2834 const UINT32 len = Stream_Get_UINT32(s);
2835 if (len != cReaders)
2837 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEW");
2841 LPSCARD_READERSTATEW rgReaderStates =
2843 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2845 if (!rgReaderStates || !states)
2848 status = ERROR_INVALID_DATA;
2849 for (UINT32 index = 0; index < cReaders; index++)
2851 UINT32 ptr = UINT32_MAX;
2852 LPSCARD_READERSTATEW readerState = &rgReaderStates[index];
2854 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2857 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2863 states[index] = ptr != 0;
2864 Stream_Read_UINT32(s, readerState->dwCurrentState);
2865 Stream_Read_UINT32(s, readerState->dwEventState);
2866 Stream_Read_UINT32(s, readerState->cbAtr);
2867 if (readerState->cbAtr > ARRAYSIZE(readerState->rgbAtr))
2869 WLog_Print(log, WLOG_WARN,
2870 "SCARD_READERSTATEW[%" PRIu32
"]::cbAtr %" PRIu32
" exceeds %" PRIuz, index,
2871 readerState->cbAtr, ARRAYSIZE(readerState->rgbAtr));
2872 readerState->cbAtr = ARRAYSIZE(readerState->rgbAtr);
2874 Stream_Read(s, readerState->rgbAtr, 36);
2877 for (UINT32 index = 0; index < cReaders; index++)
2879 LPSCARD_READERSTATEW readerState = &rgReaderStates[index];
2885 status = smartcard_ndr_read_w(log, s, &readerState->szReader, NDR_PTR_FULL);
2886 if (status != SCARD_S_SUCCESS)
2888 if (!readerState->szReader)
2892 *ppcReaders = rgReaderStates;
2894 return SCARD_S_SUCCESS;
2898 for (UINT32 index = 0; index < cReaders; index++)
2900 LPSCARD_READERSTATEW readerState = &rgReaderStates[index];
2901 free(readerState->szReader);
2904 free(rgReaderStates);
2917 UINT32 pbContextNdrPtr = 0;
2920 wLog* log = scard_log();
2922 call->rgReaderStates =
nullptr;
2924 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2926 if (status != SCARD_S_SUCCESS)
2929 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2930 return STATUS_BUFFER_TOO_SMALL;
2932 Stream_Read_UINT32(s, call->dwTimeOut);
2933 const UINT32 cReaders = Stream_Get_UINT32(s);
2936 WLog_Print(log, WLOG_WARN,
2937 "2.2.2.11 GetStatusChangeA_Call: cReaders must be <= 11, got %" PRIu32,
2939 return ERROR_INVALID_DATA;
2942 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2943 return ERROR_INVALID_DATA;
2945 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2946 &(call->handles.hContext));
2947 if (status != SCARD_S_SUCCESS)
2952 status = smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, cReaders, &index);
2953 if (status != SCARD_S_SUCCESS)
2955 call->cReaders = cReaders;
2959 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2960 return SCARD_E_UNEXPECTED;
2963 smartcard_trace_get_status_change_a_call(log, call);
2964 return SCARD_S_SUCCESS;
2971 UINT32 pbContextNdrPtr = 0;
2974 wLog* log = scard_log();
2975 call->rgReaderStates =
nullptr;
2977 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2979 if (status != SCARD_S_SUCCESS)
2982 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2983 return STATUS_BUFFER_TOO_SMALL;
2985 Stream_Read_UINT32(s, call->dwTimeOut);
2986 const UINT32 cReaders = Stream_Get_UINT32(s);
2989 WLog_Print(log, WLOG_WARN,
2990 "2.2.2.12 GetStatusChangeW_Call: cReaders must be <= 11, got %" PRIu32,
2992 return ERROR_INVALID_DATA;
2995 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2996 return ERROR_INVALID_DATA;
2998 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2999 &(call->handles.hContext));
3000 if (status != SCARD_S_SUCCESS)
3005 status = smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, cReaders, &index);
3006 if (status != SCARD_S_SUCCESS)
3008 call->cReaders = cReaders;
3012 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
3013 return SCARD_E_UNEXPECTED;
3016 smartcard_trace_get_status_change_w_call(log, call);
3017 return SCARD_S_SUCCESS;
3020LONG smartcard_pack_get_status_change_return(
wStream* s,
const GetStatusChange_Return* ret,
3024 wLog* log = scard_log();
3027 UINT32 cReaders = ret->cReaders;
3030 if (ret->cReaders > 10)
3032 WLog_Print(log, WLOG_ERROR,
3033 "2.2.3.5 LocateCards_Return and GetStatusChange_Return cReaders(%" PRIu32
3036 return SCARD_E_INVALID_PARAMETER;
3039 smartcard_trace_get_status_change_return(log, ret, unicode);
3040 if ((ret->ReturnCode != SCARD_S_SUCCESS) && (ret->ReturnCode != SCARD_E_TIMEOUT))
3042 if (cReaders == SCARD_AUTOALLOCATE)
3045 if (!Stream_EnsureRemainingCapacity(s, 4))
3046 return SCARD_E_NO_MEMORY;
3048 Stream_Write_UINT32(s, cReaders);
3049 if (!smartcard_ndr_pointer_write(s, &index, cReaders))
3050 return SCARD_E_NO_MEMORY;
3051 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cReaders, NDR_PTR_SIMPLE);
3052 if (status != SCARD_S_SUCCESS)
3054 return ret->ReturnCode;
3060 UINT32 pbContextNdrPtr = 0;
3062 wLog* log = scard_log();
3065 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3067 if (status != SCARD_S_SUCCESS)
3070 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3071 if (status != SCARD_S_SUCCESS)
3074 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
3075 return STATUS_BUFFER_TOO_SMALL;
3077 Stream_Read_INT32(s, call->fpbAtrIsNULL);
3078 Stream_Read_UINT32(s, call->cbAtrLen);
3080 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3081 &(call->handles.hContext));
3082 if (status != SCARD_S_SUCCESS)
3085 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3086 if (status != SCARD_S_SUCCESS)
3095 wLog* log = scard_log();
3097 UINT32 cbAtrLen = ret->cbAtrLen;
3100 smartcard_trace_state_return(log, ret);
3101 if (ret->ReturnCode != SCARD_S_SUCCESS)
3103 if (cbAtrLen == SCARD_AUTOALLOCATE)
3106 if (!Stream_EnsureRemainingCapacity(s, 12))
3107 return SCARD_E_NO_MEMORY;
3109 Stream_Write_UINT32(s, ret->dwState);
3110 Stream_Write_UINT32(s, ret->dwProtocol);
3111 Stream_Write_UINT32(s, cbAtrLen);
3112 if (!smartcard_ndr_pointer_write(s, &index, cbAtrLen))
3113 return SCARD_E_NO_MEMORY;
3114 status = smartcard_ndr_write(s, ret->rgAtr, cbAtrLen, 1, NDR_PTR_SIMPLE);
3115 if (status != SCARD_S_SUCCESS)
3117 return ret->ReturnCode;
3123 UINT32 pbContextNdrPtr = 0;
3126 wLog* log = scard_log();
3128 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3130 if (status != SCARD_S_SUCCESS)
3133 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3134 if (status != SCARD_S_SUCCESS)
3137 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3138 return STATUS_BUFFER_TOO_SMALL;
3140 Stream_Read_INT32(s, call->fmszReaderNamesIsNULL);
3141 Stream_Read_UINT32(s, call->cchReaderLen);
3142 Stream_Read_UINT32(s, call->cbAtrLen);
3144 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3145 &(call->handles.hContext));
3146 if (status != SCARD_S_SUCCESS)
3149 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3150 if (status != SCARD_S_SUCCESS)
3153 smartcard_trace_status_call(log, call, unicode);
3160 wLog* log = scard_log();
3163 smartcard_trace_status_call(log, call, unicode);
3165 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
3166 if (status != SCARD_S_SUCCESS)
3169 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
3170 if (status != SCARD_S_SUCCESS)
3173 if (!Stream_EnsureRemainingCapacity(s, 12))
3174 return SCARD_E_NO_MEMORY;
3176 Stream_Write_INT32(s, call->fmszReaderNamesIsNULL);
3177 Stream_Write_UINT32(s, call->cchReaderLen);
3178 Stream_Write_UINT32(s, call->cbAtrLen);
3180 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
3181 if (status != SCARD_S_SUCCESS)
3184 return smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
3190 wLog* log = scard_log();
3194 UINT32 cBytes = ret->cBytes;
3196 smartcard_trace_status_return(log, ret, unicode);
3197 if (ret->ReturnCode != SCARD_S_SUCCESS)
3199 if (cBytes == SCARD_AUTOALLOCATE)
3202 if (!Stream_EnsureRemainingCapacity(s, 4))
3203 return SCARD_F_INTERNAL_ERROR;
3207 WLog_Print(log, WLOG_ERROR,
"2.2.3.10 Status_Return cBytes(%" PRIu32
") > 65536", cBytes);
3208 return SCARD_E_INVALID_PARAMETER;
3211 Stream_Write_UINT32(s, cBytes);
3212 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
3213 return SCARD_E_NO_MEMORY;
3215 if (!Stream_EnsureRemainingCapacity(s, 44))
3216 return SCARD_F_INTERNAL_ERROR;
3218 Stream_Write_UINT32(s, ret->dwState);
3219 Stream_Write_UINT32(s, ret->dwProtocol);
3220 Stream_Write(s, ret->pbAtr,
sizeof(ret->pbAtr));
3222 if (ret->cbAtrLen > 32)
3224 WLog_Print(log, WLOG_ERROR,
"2.2.3.10 Status_Return cbAtrLen(%" PRIu32
") > 32",
3226 return SCARD_E_INVALID_PARAMETER;
3229 Stream_Write_UINT32(s, ret->cbAtrLen);
3230 status = smartcard_ndr_write(s, ret->mszReaderNames, cBytes, 1, NDR_PTR_SIMPLE);
3231 if (status != SCARD_S_SUCCESS)
3233 return ret->ReturnCode;
3239 wLog* log = scard_log();
3241 UINT32 mszNdrPtr = 0;
3243 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3244 return STATUS_BUFFER_TOO_SMALL;
3246 const UINT32 cBytes = Stream_Get_UINT32(s);
3249 WLog_Print(log, WLOG_ERROR,
"2.2.3.10 Status_Return cBytes(%" PRIu32
") > 65536", cBytes);
3250 return SCARD_E_INVALID_PARAMETER;
3253 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3254 return ERROR_INVALID_DATA;
3256 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 44))
3257 return STATUS_BUFFER_TOO_SMALL;
3259 Stream_Read_UINT32(s, ret->dwState);
3260 Stream_Read_UINT32(s, ret->dwProtocol);
3261 Stream_Read(s, ret->pbAtr,
sizeof(ret->pbAtr));
3262 Stream_Read_UINT32(s, ret->cbAtrLen);
3264 if (ret->cbAtrLen > ARRAYSIZE(ret->pbAtr))
3266 WLog_Print(log, WLOG_ERROR,
"Status_Return::cbAtrLen %" PRIu32
" exceeds %" PRIuz,
3267 ret->cbAtrLen, ARRAYSIZE(ret->pbAtr));
3268 return SCARD_E_INVALID_ATR;
3273 LONG status = smartcard_ndr_read(log, s, &ret->mszReaderNames, cBytes, 1, NDR_PTR_SIMPLE);
3274 if (status != SCARD_S_SUCCESS)
3276 ret->cBytes = cBytes;
3279 smartcard_trace_status_return(log, ret, unicode);
3280 return SCARD_S_SUCCESS;
3286 wLog* log = scard_log();
3288 UINT32 pbContextNdrPtr = 0;
3290 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3292 if (status != SCARD_S_SUCCESS)
3295 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3296 if (status != SCARD_S_SUCCESS)
3299 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3300 return STATUS_BUFFER_TOO_SMALL;
3302 Stream_Read_UINT32(s, call->dwAttrId);
3303 Stream_Read_INT32(s, call->fpbAttrIsNULL);
3304 Stream_Read_UINT32(s, call->cbAttrLen);
3306 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3307 &(call->handles.hContext));
3308 if (status != SCARD_S_SUCCESS)
3311 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3312 if (status != SCARD_S_SUCCESS)
3315 smartcard_trace_get_attrib_call(log, call);
3320 DWORD cbAttrCallLen)
3323 wLog* log = scard_log();
3325 UINT32 cbAttrLen = 0;
3327 smartcard_trace_get_attrib_return(log, ret, dwAttrId);
3329 if (!Stream_EnsureRemainingCapacity(s, 4))
3330 return SCARD_F_INTERNAL_ERROR;
3332 cbAttrLen = ret->cbAttrLen;
3333 if (ret->ReturnCode != SCARD_S_SUCCESS)
3335 if (cbAttrLen == SCARD_AUTOALLOCATE)
3340 if (cbAttrCallLen < cbAttrLen)
3341 cbAttrLen = cbAttrCallLen;
3343 if (cbAttrLen > 65536)
3345 WLog_Print(log, WLOG_ERROR,
"2.2.3.12 GetAttrib_Return cbAttrLen(%" PRIu32
") > 65536",
3347 return SCARD_E_INVALID_PARAMETER;
3349 Stream_Write_UINT32(s, cbAttrLen);
3350 if (!smartcard_ndr_pointer_write(s, &index, cbAttrLen))
3351 return SCARD_E_NO_MEMORY;
3353 status = smartcard_ndr_write(s, ret->pbAttr, cbAttrLen, 1, NDR_PTR_SIMPLE);
3354 if (status != SCARD_S_SUCCESS)
3356 return ret->ReturnCode;
3362 wLog* log = scard_log();
3365 UINT32 pvInBufferNdrPtr = 0;
3366 UINT32 pbContextNdrPtr = 0;
3368 call->pvInBuffer =
nullptr;
3370 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3372 if (status != SCARD_S_SUCCESS)
3375 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3376 if (status != SCARD_S_SUCCESS)
3379 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 20))
3380 return STATUS_BUFFER_TOO_SMALL;
3382 Stream_Read_UINT32(s, call->dwControlCode);
3383 const UINT32 cbInBufferSize = Stream_Get_UINT32(s);
3384 if (cbInBufferSize > 66560)
3386 WLog_Print(log, WLOG_ERROR,
"2.2.2.20 Control_Call cbInBufferSize (%" PRIu32
") > 66560",
3388 return SCARD_E_INVALID_PARAMETER;
3391 if (!smartcard_ndr_pointer_read(log, s, &index,
3393 return ERROR_INVALID_DATA;
3394 Stream_Read_INT32(s, call->fpvOutBufferIsNULL);
3395 Stream_Read_UINT32(s, call->cbOutBufferSize);
3397 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3398 &(call->handles.hContext));
3399 if (status != SCARD_S_SUCCESS)
3402 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3403 if (status != SCARD_S_SUCCESS)
3406 if (pvInBufferNdrPtr)
3408 status = smartcard_ndr_read(log, s, &call->pvInBuffer, cbInBufferSize, 1, NDR_PTR_SIMPLE);
3409 if (status != SCARD_S_SUCCESS)
3411 call->cbInBufferSize = cbInBufferSize;
3414 smartcard_trace_control_call(log, call);
3415 return SCARD_S_SUCCESS;
3421 wLog* log = scard_log();
3424 UINT32 cbDataLen = ret->cbOutBufferSize;
3427 smartcard_trace_control_return(log, ret);
3428 if (ret->ReturnCode != SCARD_S_SUCCESS)
3430 if (cbDataLen == SCARD_AUTOALLOCATE)
3433 if (!Stream_EnsureRemainingCapacity(s, 4))
3434 return SCARD_F_INTERNAL_ERROR;
3436 if (cbDataLen > 66560)
3438 WLog_Print(log, WLOG_ERROR,
"2.2.3.6 Control_Return cbOutBufferSize(%" PRIu32
") > 66560",
3440 return SCARD_E_INVALID_PARAMETER;
3443 Stream_Write_UINT32(s, cbDataLen);
3444 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3445 return SCARD_E_NO_MEMORY;
3447 status = smartcard_ndr_write(s, ret->pvOutBuffer, cbDataLen, 1, NDR_PTR_SIMPLE);
3448 if (status != SCARD_S_SUCCESS)
3450 return ret->ReturnCode;
3456 BYTE* pbExtraBytes =
nullptr;
3457 UINT32 pbExtraBytesNdrPtr = 0;
3458 UINT32 pbSendBufferNdrPtr = 0;
3459 UINT32 pioRecvPciNdrPtr = 0;
3463 UINT32 pbContextNdrPtr = 0;
3466 wLog* log = scard_log();
3468 call->pioSendPci =
nullptr;
3469 call->pioRecvPci =
nullptr;
3470 call->pbSendBuffer =
nullptr;
3472 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3474 if (status != SCARD_S_SUCCESS)
3477 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3478 if (status != SCARD_S_SUCCESS)
3481 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 32))
3482 return STATUS_BUFFER_TOO_SMALL;
3484 Stream_Read_UINT32(s, ioSendPci.dwProtocol);
3485 Stream_Read_UINT32(s, ioSendPci.cbExtraBytes);
3486 if (!smartcard_ndr_pointer_read(log, s, &index,
3487 &pbExtraBytesNdrPtr))
3488 return ERROR_INVALID_DATA;
3490 const UINT32 cbSendLength = Stream_Get_UINT32(s);
3491 if (cbSendLength > 66560)
3493 WLog_Print(log, WLOG_ERROR,
"2.2.2.19 Transmit_Call cbSendLength (%" PRIu32
") > 66560",
3495 return SCARD_E_INVALID_PARAMETER;
3497 if (!smartcard_ndr_pointer_read(log, s, &index,
3498 &pbSendBufferNdrPtr))
3499 return ERROR_INVALID_DATA;
3501 if (!smartcard_ndr_pointer_read(log, s, &index,
3503 return ERROR_INVALID_DATA;
3505 Stream_Read_INT32(s, call->fpbRecvBufferIsNULL);
3506 Stream_Read_UINT32(s, call->cbRecvLength);
3508 if (ioSendPci.cbExtraBytes > 1024)
3510 WLog_Print(log, WLOG_WARN,
3511 "Transmit_Call ioSendPci.cbExtraBytes is out of bounds: %" PRIu32
" (max: 1024)",
3512 ioSendPci.cbExtraBytes);
3513 return STATUS_INVALID_PARAMETER;
3516 if (cbSendLength > 66560)
3518 WLog_Print(log, WLOG_WARN,
3519 "Transmit_Call cbSendLength is out of bounds: %" PRIu32
" (max: 66560)",
3520 ioSendPci.cbExtraBytes);
3521 return STATUS_INVALID_PARAMETER;
3524 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3525 &(call->handles.hContext));
3526 if (status != SCARD_S_SUCCESS)
3529 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3530 if (status != SCARD_S_SUCCESS)
3533 if (ioSendPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3537 "Transmit_Call ioSendPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3538 return STATUS_INVALID_PARAMETER;
3541 if (pbExtraBytesNdrPtr)
3544 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3545 return STATUS_BUFFER_TOO_SMALL;
3547 Stream_Read_UINT32(s, length);
3549 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioSendPci.cbExtraBytes))
3550 return STATUS_BUFFER_TOO_SMALL;
3552 ioSendPci.pbExtraBytes = Stream_Pointer(s);
3554 (LPSCARD_IO_REQUEST)malloc(
sizeof(
SCARD_IO_REQUEST) + ioSendPci.cbExtraBytes);
3556 if (!call->pioSendPci)
3558 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3559 return STATUS_NO_MEMORY;
3562 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3563 call->pioSendPci->cbPciLength = (DWORD)(ioSendPci.cbExtraBytes +
sizeof(
SCARD_IO_REQUEST));
3565 Stream_Read(s, pbExtraBytes, ioSendPci.cbExtraBytes);
3566 if (smartcard_unpack_read_size_align(s, ioSendPci.cbExtraBytes, 4) < 0)
3567 return STATUS_INVALID_PARAMETER;
3571 call->pioSendPci = (LPSCARD_IO_REQUEST)calloc(1,
sizeof(
SCARD_IO_REQUEST));
3573 if (!call->pioSendPci)
3575 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3576 return STATUS_NO_MEMORY;
3579 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3583 if (pbSendBufferNdrPtr)
3585 status = smartcard_ndr_read(log, s, &call->pbSendBuffer, cbSendLength, 1, NDR_PTR_SIMPLE);
3586 if (status != SCARD_S_SUCCESS)
3588 call->cbSendLength = cbSendLength;
3591 if (pioRecvPciNdrPtr)
3593 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3594 return STATUS_BUFFER_TOO_SMALL;
3596 Stream_Read_UINT32(s, ioRecvPci.dwProtocol);
3597 Stream_Read_UINT32(s, ioRecvPci.cbExtraBytes);
3598 if (!smartcard_ndr_pointer_read(log, s, &index,
3599 &pbExtraBytesNdrPtr))
3600 return ERROR_INVALID_DATA;
3602 if (ioRecvPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3606 "Transmit_Call ioRecvPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3607 return STATUS_INVALID_PARAMETER;
3610 if (pbExtraBytesNdrPtr)
3613 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3614 return STATUS_BUFFER_TOO_SMALL;
3616 Stream_Read_UINT32(s, length);
3618 if (ioRecvPci.cbExtraBytes > 1024)
3620 WLog_Print(log, WLOG_WARN,
3621 "Transmit_Call ioRecvPci.cbExtraBytes is out of bounds: %" PRIu32
3623 ioRecvPci.cbExtraBytes);
3624 return STATUS_INVALID_PARAMETER;
3627 if (length != ioRecvPci.cbExtraBytes)
3629 WLog_Print(log, WLOG_WARN,
3630 "Transmit_Call unexpected length: Actual: %" PRIu32
3631 ", Expected: %" PRIu32
" (ioRecvPci.cbExtraBytes)",
3632 length, ioRecvPci.cbExtraBytes);
3633 return STATUS_INVALID_PARAMETER;
3636 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioRecvPci.cbExtraBytes))
3637 return STATUS_BUFFER_TOO_SMALL;
3639 ioRecvPci.pbExtraBytes = Stream_Pointer(s);
3641 (LPSCARD_IO_REQUEST)malloc(
sizeof(
SCARD_IO_REQUEST) + ioRecvPci.cbExtraBytes);
3643 if (!call->pioRecvPci)
3645 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3646 return STATUS_NO_MEMORY;
3649 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3650 call->pioRecvPci->cbPciLength =
3653 Stream_Read(s, pbExtraBytes, ioRecvPci.cbExtraBytes);
3654 if (smartcard_unpack_read_size_align(s, ioRecvPci.cbExtraBytes, 4) < 0)
3655 return STATUS_INVALID_PARAMETER;
3659 call->pioRecvPci = (LPSCARD_IO_REQUEST)calloc(1,
sizeof(
SCARD_IO_REQUEST));
3661 if (!call->pioRecvPci)
3663 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3664 return STATUS_NO_MEMORY;
3667 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3672 smartcard_trace_transmit_call(log, call);
3673 return SCARD_S_SUCCESS;
3679 wLog* log = scard_log();
3684 UINT32 cbRecvLength = ret->cbRecvLength;
3685 UINT32 cbRecvPci = ret->pioRecvPci ? ret->pioRecvPci->cbPciLength : 0;
3687 smartcard_trace_transmit_return(log, ret);
3689 if (!ret->pbRecvBuffer)
3692 if (!smartcard_ndr_pointer_write(s, &index, cbRecvPci))
3693 return SCARD_E_NO_MEMORY;
3694 if (!Stream_EnsureRemainingCapacity(s, 4))
3695 return SCARD_E_NO_MEMORY;
3697 if (cbRecvLength > 66560)
3699 WLog_Print(log, WLOG_ERROR,
"2.2.3.11 Transmit_Return cbRecvLength(%" PRIu32
") > 66560",
3701 return SCARD_E_INVALID_PARAMETER;
3704 Stream_Write_UINT32(s, cbRecvLength);
3705 if (!smartcard_ndr_pointer_write(s, &index, cbRecvLength))
3706 return SCARD_E_NO_MEMORY;
3708 if (ret->pioRecvPci)
3710 UINT32 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
3713 if (!Stream_EnsureRemainingCapacity(s, 8ull))
3715 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3716 return SCARD_F_INTERNAL_ERROR;
3719 Stream_Write_UINT32(s, ret->pioRecvPci->dwProtocol);
3720 Stream_Write_UINT32(s, cbExtraBytes);
3721 if (!smartcard_ndr_pointer_write(s, &index, cbExtraBytes))
3722 return SCARD_E_NO_MEMORY;
3723 error = smartcard_ndr_write(s, pbExtraBytes, cbExtraBytes, 1, NDR_PTR_SIMPLE);
3728 status = smartcard_ndr_write(s, ret->pbRecvBuffer, ret->cbRecvLength, 1, NDR_PTR_SIMPLE);
3729 if (status != SCARD_S_SUCCESS)
3731 return ret->ReturnCode;
3736 UINT32 rgReaderStatesNdrPtr = 0;
3737 UINT32 rgAtrMasksNdrPtr = 0;
3739 UINT32 pbContextNdrPtr = 0;
3742 wLog* log = scard_log();
3744 call->rgReaderStates =
nullptr;
3746 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3748 if (status != SCARD_S_SUCCESS)
3751 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3752 return STATUS_BUFFER_TOO_SMALL;
3754 Stream_Read_UINT32(s, call->cAtrs);
3755 if (call->cAtrs > 1000)
3757 WLog_Print(log, WLOG_ERROR,
"2.2.2.23 LocateCardsByATRA_Call cAtrs(%" PRIu32
") > 1000",
3759 return SCARD_E_INVALID_PARAMETER;
3762 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3763 return ERROR_INVALID_DATA;
3764 const UINT32 cReaders = Stream_Get_UINT32(s);
3767 WLog_Print(log, WLOG_ERROR,
"2.2.2.23 LocateCardsByATRA_Call cReaders(%" PRIu32
") > 10",
3769 return SCARD_E_INVALID_PARAMETER;
3771 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3772 return ERROR_INVALID_DATA;
3774 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3775 &(call->handles.hContext));
3776 if (status != SCARD_S_SUCCESS)
3779 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3781 WLog_Print(log, WLOG_WARN,
3782 "LocateCardsByATRA_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3783 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3784 rgAtrMasksNdrPtr, call->cAtrs);
3785 return STATUS_INVALID_PARAMETER;
3788 if (rgAtrMasksNdrPtr)
3790 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3791 if (status != SCARD_S_SUCCESS)
3795 if (rgReaderStatesNdrPtr)
3797 status = smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, cReaders, &index);
3798 if (status != SCARD_S_SUCCESS)
3800 call->cReaders = cReaders;
3803 smartcard_trace_locate_cards_by_atr_a_call(log, call);
3804 return SCARD_S_SUCCESS;
3809 UINT32 sz1NdrPtr = 0;
3810 UINT32 sz2NdrPtr = 0;
3812 UINT32 pbContextNdrPtr = 0;
3815 wLog* log = scard_log();
3817 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3819 if (status != SCARD_S_SUCCESS)
3822 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3823 return ERROR_INVALID_DATA;
3824 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3825 return ERROR_INVALID_DATA;
3828 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3829 if (status != SCARD_S_SUCCESS)
3834 status = smartcard_ndr_read_a(log, s, &call->sz1, NDR_PTR_FULL);
3835 if (status != SCARD_S_SUCCESS)
3840 status = smartcard_ndr_read_a(log, s, &call->sz2, NDR_PTR_FULL);
3841 if (status != SCARD_S_SUCCESS)
3844 smartcard_trace_context_and_two_strings_a_call(log, call);
3845 return SCARD_S_SUCCESS;
3850 UINT32 sz1NdrPtr = 0;
3851 UINT32 sz2NdrPtr = 0;
3853 UINT32 pbContextNdrPtr = 0;
3856 wLog* log = scard_log();
3858 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3860 if (status != SCARD_S_SUCCESS)
3863 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3864 return ERROR_INVALID_DATA;
3865 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3866 return ERROR_INVALID_DATA;
3869 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3870 if (status != SCARD_S_SUCCESS)
3875 status = smartcard_ndr_read_w(log, s, &call->sz1, NDR_PTR_FULL);
3876 if (status != SCARD_S_SUCCESS)
3881 status = smartcard_ndr_read_w(log, s, &call->sz2, NDR_PTR_FULL);
3882 if (status != SCARD_S_SUCCESS)
3885 smartcard_trace_context_and_two_strings_w_call(log, call);
3886 return SCARD_S_SUCCESS;
3891 UINT32 sz1NdrPtr = 0;
3892 UINT32 sz2NdrPtr = 0;
3894 UINT32 pbContextNdrPtr = 0;
3897 wLog* log = scard_log();
3899 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3901 if (status != SCARD_S_SUCCESS)
3904 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3905 return STATUS_BUFFER_TOO_SMALL;
3907 const UINT32 cBytes = Stream_Get_UINT32(s);
3908 if (call->cBytes > 65536)
3910 WLog_Print(log, WLOG_ERROR,
"2.2.2.9 LocateCardsA_Call cBytes(%" PRIu32
") > 65536",
3912 return SCARD_E_INVALID_PARAMETER;
3915 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3916 return ERROR_INVALID_DATA;
3918 const UINT32 cReaders = Stream_Get_UINT32(s);
3921 WLog_Print(log, WLOG_ERROR,
"2.2.2.9 LocateCardsA_Call cReaders(%" PRIu32
") > 10",
3923 return SCARD_E_INVALID_PARAMETER;
3925 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3926 return ERROR_INVALID_DATA;
3928 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3929 &(call->handles.hContext));
3930 if (status != SCARD_S_SUCCESS)
3935 status = smartcard_ndr_read_fixed_string_a(log, s, &call->mszCards, cBytes, NDR_PTR_SIMPLE);
3936 if (status != SCARD_S_SUCCESS)
3938 call->cBytes = cBytes;
3942 status = smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, cReaders, &index);
3943 if (status != SCARD_S_SUCCESS)
3945 call->cReaders = cReaders;
3947 smartcard_trace_locate_cards_a_call(log, call);
3948 return SCARD_S_SUCCESS;
3953 UINT32 sz1NdrPtr = 0;
3954 UINT32 sz2NdrPtr = 0;
3956 UINT32 pbContextNdrPtr = 0;
3959 wLog* log = scard_log();
3961 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3963 if (status != SCARD_S_SUCCESS)
3966 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3967 return STATUS_BUFFER_TOO_SMALL;
3969 const UINT32 cBytes = Stream_Get_UINT32(s);
3970 if (call->cBytes > 65536)
3972 WLog_Print(log, WLOG_ERROR,
"2.2.2.10 LocateCardsW_Call cBytes(%" PRIu32
") > 65536",
3974 return SCARD_E_INVALID_PARAMETER;
3977 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3978 return ERROR_INVALID_DATA;
3980 const UINT32 cReaders = Stream_Get_UINT32(s);
3983 WLog_Print(log, WLOG_ERROR,
"2.2.2.10 LocateCardsW_Call cReaders(%" PRIu32
") > 10",
3985 return SCARD_E_INVALID_PARAMETER;
3988 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3989 return ERROR_INVALID_DATA;
3991 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3992 &(call->handles.hContext));
3993 if (status != SCARD_S_SUCCESS)
3998 status = smartcard_ndr_read_fixed_string_w(log, s, &call->mszCards, cBytes, NDR_PTR_SIMPLE);
3999 if (status != SCARD_S_SUCCESS)
4001 call->cBytes = cBytes;
4005 status = smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, cReaders, &index);
4006 if (status != SCARD_S_SUCCESS)
4008 call->cReaders = cReaders;
4010 smartcard_trace_locate_cards_w_call(log, call);
4011 return SCARD_S_SUCCESS;
4018 UINT32 pbContextNdrPtr = 0;
4021 wLog* log = scard_log();
4023 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
4025 if (status != SCARD_S_SUCCESS)
4027 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
4028 if (status != SCARD_S_SUCCESS)
4031 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
4032 return STATUS_BUFFER_TOO_SMALL;
4033 Stream_Read_UINT32(s, call->dwAttrId);
4034 Stream_Read_UINT32(s, call->cbAttrLen);
4035 if (call->cbAttrLen > 65536)
4037 WLog_Print(log, WLOG_ERROR,
"2.2.2.22 SetAttrib_Call call->cbAttrLen (%" PRIu32
") > 65536",
4039 return SCARD_E_INVALID_PARAMETER;
4042 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
4043 return ERROR_INVALID_DATA;
4045 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4046 &(call->handles.hContext));
4047 if (status != SCARD_S_SUCCESS)
4050 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
4051 if (status != SCARD_S_SUCCESS)
4057 status = smartcard_ndr_read_ex(log, s, &call->pbAttr, 0, 1, NDR_PTR_SIMPLE, &len);
4058 if (status != SCARD_S_SUCCESS)
4060 if (call->cbAttrLen > len)
4061 call->cbAttrLen = WINPR_ASSERTING_INT_CAST(DWORD, len);
4064 call->cbAttrLen = 0;
4065 smartcard_trace_set_attrib_call(log, call);
4066 return SCARD_S_SUCCESS;
4072 wLog* log = scard_log();
4075 smartcard_trace_set_attrib_call(log, call);
4077 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4078 if (status != SCARD_S_SUCCESS)
4081 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
4082 if (status != SCARD_S_SUCCESS)
4085 if (!Stream_EnsureRemainingCapacity(s, 8))
4086 return SCARD_E_NO_MEMORY;
4088 Stream_Write_UINT32(s, call->dwAttrId);
4089 Stream_Write_UINT32(s, call->cbAttrLen);
4091 if (!smartcard_ndr_pointer_write(s, &index, call->cbAttrLen))
4092 return SCARD_E_NO_MEMORY;
4094 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4095 if (status != SCARD_S_SUCCESS)
4098 status = smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
4099 if (status != SCARD_S_SUCCESS)
4102 status = smartcard_ndr_write(s, call->pbAttr, call->cbAttrLen, 1, NDR_PTR_SIMPLE);
4103 if (status != SCARD_S_SUCCESS)
4106 return SCARD_S_SUCCESS;
4111 UINT32 rgReaderStatesNdrPtr = 0;
4112 UINT32 rgAtrMasksNdrPtr = 0;
4114 UINT32 pbContextNdrPtr = 0;
4117 wLog* log = scard_log();
4119 call->rgReaderStates =
nullptr;
4121 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
4123 if (status != SCARD_S_SUCCESS)
4126 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
4127 return STATUS_BUFFER_TOO_SMALL;
4129 Stream_Read_UINT32(s, call->cAtrs);
4130 if (call->cAtrs > 1000)
4132 WLog_Print(log, WLOG_ERROR,
"2.2.2.24 LocateCardsByATRW_Call cAtrs(%" PRIu32
") > 1000",
4134 return SCARD_E_INVALID_PARAMETER;
4137 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
4138 return ERROR_INVALID_DATA;
4140 const UINT32 cReaders = Stream_Get_UINT32(s);
4143 WLog_Print(log, WLOG_ERROR,
"2.2.2.24 LocateCardsByATRW_Call cReaders(%" PRIu32
") > 10",
4145 return SCARD_E_INVALID_PARAMETER;
4147 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
4148 return ERROR_INVALID_DATA;
4150 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4151 &(call->handles.hContext));
4152 if (status != SCARD_S_SUCCESS)
4155 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
4157 WLog_Print(log, WLOG_WARN,
4158 "LocateCardsByATRW_Call rgAtrMasksNdrPtr (0x%08" PRIX32
4159 ") and cAtrs (0x%08" PRIX32
") inconsistency",
4160 rgAtrMasksNdrPtr, call->cAtrs);
4161 return STATUS_INVALID_PARAMETER;
4164 if (rgAtrMasksNdrPtr)
4166 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
4167 if (status != SCARD_S_SUCCESS)
4171 if (rgReaderStatesNdrPtr)
4173 status = smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, cReaders, &index);
4174 if (status != SCARD_S_SUCCESS)
4176 call->cReaders = cReaders;
4179 smartcard_trace_locate_cards_by_atr_w_call(log, call);
4180 return SCARD_S_SUCCESS;
4185 UINT32 mszNdrPtr = 0;
4186 UINT32 contextNdrPtr = 0;
4188 UINT32 pbContextNdrPtr = 0;
4191 wLog* log = scard_log();
4193 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
4194 return ERROR_INVALID_DATA;
4196 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
4197 &index, &pbContextNdrPtr);
4198 if (status != SCARD_S_SUCCESS)
4201 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
4202 return ERROR_INVALID_DATA;
4204 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
4205 return STATUS_BUFFER_TOO_SMALL;
4206 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
4207 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
4208 Stream_Read_UINT32(s, call->Common.cbDataLen);
4210 call->szLookupName =
nullptr;
4213 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
4214 if (status != SCARD_S_SUCCESS)
4218 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4219 &call->Common.handles.hContext);
4220 if (status != SCARD_S_SUCCESS)
4225 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
4226 if (status != SCARD_S_SUCCESS)
4229 smartcard_trace_read_cache_a_call(log, call);
4230 return SCARD_S_SUCCESS;
4235 UINT32 mszNdrPtr = 0;
4236 UINT32 contextNdrPtr = 0;
4238 UINT32 pbContextNdrPtr = 0;
4241 wLog* log = scard_log();
4243 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
4244 return ERROR_INVALID_DATA;
4246 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
4247 &index, &pbContextNdrPtr);
4248 if (status != SCARD_S_SUCCESS)
4251 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
4252 return ERROR_INVALID_DATA;
4254 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
4255 return STATUS_BUFFER_TOO_SMALL;
4256 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
4257 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
4258 Stream_Read_UINT32(s, call->Common.cbDataLen);
4260 call->szLookupName =
nullptr;
4263 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
4264 if (status != SCARD_S_SUCCESS)
4268 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4269 &call->Common.handles.hContext);
4270 if (status != SCARD_S_SUCCESS)
4275 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
4276 if (status != SCARD_S_SUCCESS)
4279 smartcard_trace_read_cache_w_call(log, call);
4280 return SCARD_S_SUCCESS;
4285 UINT32 mszNdrPtr = 0;
4286 UINT32 contextNdrPtr = 0;
4287 UINT32 pbDataNdrPtr = 0;
4289 UINT32 pbContextNdrPtr = 0;
4292 wLog* log = scard_log();
4294 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
4295 return ERROR_INVALID_DATA;
4297 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
4298 &index, &pbContextNdrPtr);
4299 if (status != SCARD_S_SUCCESS)
4302 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
4303 return ERROR_INVALID_DATA;
4305 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
4306 return STATUS_BUFFER_TOO_SMALL;
4308 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
4309 const UINT32 cbDataLen = Stream_Get_UINT32(s);
4310 if (cbDataLen > 65536)
4312 WLog_Print(log, WLOG_ERROR,
"2.2.1.10 WriteCache_Common cbDataLen(%" PRIu32
") > 65536",
4314 return ERROR_INVALID_DATA;
4317 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
4318 return ERROR_INVALID_DATA;
4320 call->szLookupName =
nullptr;
4323 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
4324 if (status != SCARD_S_SUCCESS)
4328 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4329 &call->Common.handles.hContext);
4330 if (status != SCARD_S_SUCCESS)
4333 call->Common.CardIdentifier =
nullptr;
4336 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
4337 if (status != SCARD_S_SUCCESS)
4341 call->Common.pbData =
nullptr;
4344 status = smartcard_ndr_read(log, s, &call->Common.pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
4345 if (status != SCARD_S_SUCCESS)
4347 call->Common.cbDataLen = cbDataLen;
4349 smartcard_trace_write_cache_a_call(log, call);
4350 return SCARD_S_SUCCESS;
4355 UINT32 mszNdrPtr = 0;
4356 UINT32 contextNdrPtr = 0;
4357 UINT32 pbDataNdrPtr = 0;
4359 UINT32 pbContextNdrPtr = 0;
4362 wLog* log = scard_log();
4364 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
4365 return ERROR_INVALID_DATA;
4367 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
4368 &index, &pbContextNdrPtr);
4369 if (status != SCARD_S_SUCCESS)
4372 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
4373 return ERROR_INVALID_DATA;
4375 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
4376 return STATUS_BUFFER_TOO_SMALL;
4377 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
4378 const UINT32 cbDataLen = Stream_Get_UINT32(s);
4380 if (cbDataLen > 65536)
4382 WLog_Print(log, WLOG_ERROR,
"2.2.1.10 WriteCache_Common cbDataLen(%" PRIu32
") > 65536",
4384 return ERROR_INVALID_DATA;
4387 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
4388 return ERROR_INVALID_DATA;
4390 call->szLookupName =
nullptr;
4393 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
4394 if (status != SCARD_S_SUCCESS)
4398 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4399 &call->Common.handles.hContext);
4400 if (status != SCARD_S_SUCCESS)
4403 call->Common.CardIdentifier =
nullptr;
4406 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
4407 if (status != SCARD_S_SUCCESS)
4411 call->Common.pbData =
nullptr;
4414 status = smartcard_ndr_read(log, s, &call->Common.pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
4415 if (status != SCARD_S_SUCCESS)
4417 call->Common.cbDataLen = cbDataLen;
4419 smartcard_trace_write_cache_w_call(log, call);
4426 wLog* log = scard_log();
4429 UINT32 pbContextNdrPtr = 0;
4431 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
4433 if (status != SCARD_S_SUCCESS)
4436 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
4437 if (status != SCARD_S_SUCCESS)
4440 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4441 &(call->handles.hContext));
4442 if (status != SCARD_S_SUCCESS)
4444 WLog_Print(log, WLOG_ERROR,
4445 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
4450 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
4451 if (status != SCARD_S_SUCCESS)
4452 WLog_Print(log, WLOG_ERROR,
4453 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
4455 smartcard_trace_get_transmit_count_call(log, call);
4462 wLog* log = scard_log();
4463 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
4464 &call->szReaderName);
4470 wLog* log = scard_log();
4471 return smartcard_unpack_common_context_and_string_a(log, s, &call->handles.hContext, &call->sz);
4477 wLog* log = scard_log();
4478 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext, &call->sz);
4484 wLog* log = scard_log();
4485 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
4486 &call->szReaderName);
4492 wLog* log = scard_log();
4493 smartcard_trace_device_type_id_return(log, ret);
4495 if (!Stream_EnsureRemainingCapacity(s, 4))
4497 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4498 return SCARD_F_INTERNAL_ERROR;
4501 Stream_Write_UINT32(s, ret->dwDeviceId);
4503 return ret->ReturnCode;
4509 wLog* log = scard_log();
4512 UINT32 cbDataLen = ret->cReaders;
4515 smartcard_trace_locate_cards_return(log, ret);
4516 if (ret->ReturnCode != SCARD_S_SUCCESS)
4518 if (cbDataLen == SCARD_AUTOALLOCATE)
4521 if (!Stream_EnsureRemainingCapacity(s, 4))
4523 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4524 return SCARD_F_INTERNAL_ERROR;
4527 if (ret->cReaders > 10)
4529 WLog_Print(log, WLOG_ERROR,
4530 "2.2.3.5 LocateCards_Return and GetStatusChange_Return cReaders(%" PRIu32
4533 return SCARD_E_INVALID_PARAMETER;
4536 Stream_Write_UINT32(s, cbDataLen);
4537 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
4538 return SCARD_E_NO_MEMORY;
4540 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cbDataLen, NDR_PTR_SIMPLE);
4541 if (status != SCARD_S_SUCCESS)
4543 return ret->ReturnCode;
4549 wLog* log = scard_log();
4553 UINT32 cbDataLen = ret->cbDataLen;
4554 smartcard_trace_get_reader_icon_return(log, ret);
4555 if (ret->ReturnCode != SCARD_S_SUCCESS)
4557 if (cbDataLen == SCARD_AUTOALLOCATE)
4560 if (!Stream_EnsureRemainingCapacity(s, 4))
4562 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4563 return SCARD_F_INTERNAL_ERROR;
4566 Stream_Write_UINT32(s, cbDataLen);
4567 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
4568 return SCARD_E_NO_MEMORY;
4570 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
4571 if (status != SCARD_S_SUCCESS)
4573 return ret->ReturnCode;
4579 wLog* log = scard_log();
4581 smartcard_trace_get_transmit_count_return(log, ret);
4583 if (!Stream_EnsureRemainingCapacity(s, 4))
4585 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4586 return SCARD_F_INTERNAL_ERROR;
4589 Stream_Write_UINT32(s, ret->cTransmitCount);
4591 return ret->ReturnCode;
4597 wLog* log = scard_log();
4601 UINT32 cbDataLen = ret->cbDataLen;
4602 smartcard_trace_read_cache_return(log, ret);
4603 if (ret->ReturnCode != SCARD_S_SUCCESS)
4606 if (cbDataLen == SCARD_AUTOALLOCATE)
4609 if (!Stream_EnsureRemainingCapacity(s, 4))
4611 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4612 return SCARD_F_INTERNAL_ERROR;
4615 if (cbDataLen > 65536)
4617 WLog_Print(log, WLOG_ERROR,
"2.2.3.1 ReadCache_Return cbDataLen (%" PRIu32
") > 65536",
4619 return SCARD_E_INVALID_PARAMETER;
4622 Stream_Write_UINT32(s, cbDataLen);
4623 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
4624 return SCARD_E_NO_MEMORY;
4626 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
4627 if (status != SCARD_S_SUCCESS)
4629 return ret->ReturnCode;
4635 wLog* log = scard_log();
4638 smartcard_trace_context_call(log, call, name);
4640 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4641 if (status != SCARD_S_SUCCESS)
4644 return smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4650 wLog* log = scard_log();
4653 smartcard_trace_list_readers_call(log, call, unicode);
4655 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4656 if (status != SCARD_S_SUCCESS)
4659 if (!Stream_EnsureRemainingCapacity(s, 4))
4660 return SCARD_E_NO_MEMORY;
4662 Stream_Write_UINT32(s, call->cBytes);
4663 if (call->cBytes > 65536)
4665 WLog_Print(log, WLOG_ERROR,
"2.2.2.4 ListReaders_Call cBytes(%" PRIu32
") > 65536",
4667 return SCARD_E_INVALID_PARAMETER;
4670 if (!smartcard_ndr_pointer_write(s, &index, call->cBytes))
4671 return SCARD_E_NO_MEMORY;
4673 if (!Stream_EnsureRemainingCapacity(s, 8))
4674 return SCARD_E_NO_MEMORY;
4676 Stream_Write_INT32(s, call->fmszReadersIsNULL);
4677 Stream_Write_UINT32(s, call->cchReaders);
4679 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4680 if (status != SCARD_S_SUCCESS)
4683 if (call->cBytes > 0)
4685 status = smartcard_ndr_write(s, call->mszGroups, call->cBytes, 1, NDR_PTR_SIMPLE);
4686 if (status != SCARD_S_SUCCESS)
4690 return SCARD_S_SUCCESS;
4693WINPR_ATTR_NODISCARD
static LONG
4694smartcard_pack_reader_state_a(wLog* log,
wStream* s,
const LPSCARD_READERSTATEA rgReaderStates,
4695 UINT32 cReaders, UINT32* ptrIndex)
4697 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
4699 if (!Stream_EnsureRemainingCapacity(s, 4))
4700 return SCARD_E_NO_MEMORY;
4702 Stream_Write_UINT32(s, cReaders);
4704 for (UINT32 i = 0; i < cReaders; i++)
4708 if (!Stream_EnsureRemainingCapacity(s, 52))
4709 return SCARD_E_NO_MEMORY;
4711 const UINT32 nameLen = state->szReader ? (UINT32)(strlen(state->szReader) + 1) : 0;
4712 if (!smartcard_ndr_pointer_write(s, ptrIndex, nameLen))
4713 return SCARD_E_NO_MEMORY;
4715 Stream_Write_UINT32(s, state->dwCurrentState);
4716 Stream_Write_UINT32(s, state->dwEventState);
4717 if (state->cbAtr > 36)
4719 WLog_Print(log, WLOG_WARN,
"2.2.2.12 GetStatusChangeW_Call cbAtr(%" PRIu32
") > 36",
4721 return SCARD_E_INVALID_PARAMETER;
4723 Stream_Write_UINT32(s, state->cbAtr);
4724 Stream_Write(s, state->rgbAtr, 36);
4727 for (UINT32 i = 0; i < cReaders; i++)
4731 if (state->szReader)
4733 const UINT32 nameLen = (UINT32)(strlen(state->szReader) + 1);
4734 LONG status = smartcard_ndr_write_a(s, state->szReader, nameLen, NDR_PTR_FULL);
4735 if (status != SCARD_S_SUCCESS)
4740 return SCARD_S_SUCCESS;
4743WINPR_ATTR_NODISCARD
static LONG
4744smartcard_pack_reader_state_w(wLog* log,
wStream* s,
const LPSCARD_READERSTATEW rgReaderStates,
4745 UINT32 cReaders, UINT32* ptrIndex)
4747 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
4749 if (!Stream_EnsureRemainingCapacity(s, 4))
4750 return SCARD_E_NO_MEMORY;
4752 Stream_Write_UINT32(s, cReaders);
4754 for (UINT32 i = 0; i < cReaders; i++)
4758 if (!Stream_EnsureRemainingCapacity(s, 52))
4759 return SCARD_E_NO_MEMORY;
4761 const UINT32 nameLen = state->szReader ? (UINT32)(_wcslen(state->szReader) + 1) : 0;
4762 if (!smartcard_ndr_pointer_write(s, ptrIndex, nameLen))
4763 return SCARD_E_NO_MEMORY;
4765 Stream_Write_UINT32(s, state->dwCurrentState);
4766 Stream_Write_UINT32(s, state->dwEventState);
4767 if (state->cbAtr > 36)
4769 WLog_Print(log, WLOG_WARN,
"2.2.2.12 GetStatusChangeW_Call cbAtr(%" PRIu32
") > 36",
4771 return SCARD_E_INVALID_PARAMETER;
4773 Stream_Write_UINT32(s, state->cbAtr);
4774 Stream_Write(s, state->rgbAtr, 36);
4777 for (UINT32 i = 0; i < cReaders; i++)
4781 if (state->szReader)
4783 const UINT32 nameLen = (UINT32)(_wcslen(state->szReader) + 1);
4784 LONG status = smartcard_ndr_write_w(s, state->szReader, nameLen, NDR_PTR_FULL);
4785 if (status != SCARD_S_SUCCESS)
4790 return SCARD_S_SUCCESS;
4796 wLog* log = scard_log();
4799 smartcard_trace_get_status_change_a_call(log, call);
4801 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4802 if (status != SCARD_S_SUCCESS)
4805 if (!Stream_EnsureRemainingCapacity(s, 8))
4806 return SCARD_E_NO_MEMORY;
4808 Stream_Write_UINT32(s, call->dwTimeOut);
4809 Stream_Write_UINT32(s, call->cReaders);
4810 if (call->cReaders > 11)
4812 WLog_Print(log, WLOG_ERROR,
"2.2.2.11 GetStatusChangeA_Call cReaders (%" PRIu32
") > 11",
4814 return SCARD_E_INVALID_PARAMETER;
4816 if (!smartcard_ndr_pointer_write(s, &index, call->cReaders))
4817 return SCARD_E_NO_MEMORY;
4819 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4820 if (status != SCARD_S_SUCCESS)
4823 if (call->cReaders > 0)
4826 smartcard_pack_reader_state_a(log, s, call->rgReaderStates, call->cReaders, &index);
4827 if (status != SCARD_S_SUCCESS)
4831 return SCARD_S_SUCCESS;
4837 wLog* log = scard_log();
4840 smartcard_trace_get_status_change_w_call(log, call);
4842 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4843 if (status != SCARD_S_SUCCESS)
4846 if (!Stream_EnsureRemainingCapacity(s, 8))
4847 return SCARD_E_NO_MEMORY;
4849 Stream_Write_UINT32(s, call->dwTimeOut);
4850 Stream_Write_UINT32(s, call->cReaders);
4851 if (call->cReaders > 11)
4853 WLog_Print(log, WLOG_ERROR,
"2.2.2.12 GetStatusChangeW_Call cReaders (%" PRIu32
") > 11",
4855 return SCARD_E_INVALID_PARAMETER;
4858 if (!smartcard_ndr_pointer_write(s, &index, call->cReaders))
4859 return SCARD_E_NO_MEMORY;
4861 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4862 if (status != SCARD_S_SUCCESS)
4865 if (call->cReaders > 0)
4868 smartcard_pack_reader_state_w(log, s, call->rgReaderStates, call->cReaders, &index);
4869 if (status != SCARD_S_SUCCESS)
4873 return SCARD_S_SUCCESS;
4879 wLog* log = scard_log();
4882 smartcard_trace_connect_a_call(log, call);
4884 const UINT32 readerLen = call->szReader ? (UINT32)(strlen(call->szReader) + 1) : 0;
4885 if (!smartcard_ndr_pointer_write(s, &index, readerLen))
4886 return SCARD_E_NO_MEMORY;
4889 smartcard_pack_redir_scard_context(log, s, &call->Common.handles.hContext, &index);
4890 if (status != SCARD_S_SUCCESS)
4893 if (!Stream_EnsureRemainingCapacity(s, 8))
4894 return SCARD_E_NO_MEMORY;
4896 Stream_Write_UINT32(s, call->Common.dwShareMode);
4897 Stream_Write_UINT32(s, call->Common.dwPreferredProtocols);
4901 status = smartcard_ndr_write_a(s, call->szReader, readerLen, NDR_PTR_FULL);
4902 if (status != SCARD_S_SUCCESS)
4906 return smartcard_pack_redir_scard_context_ref(log, s, &call->Common.handles.hContext);
4912 wLog* log = scard_log();
4915 smartcard_trace_connect_w_call(log, call);
4917 const UINT32 readerLen = call->szReader ? (UINT32)(_wcslen(call->szReader) + 1) : 0;
4918 if (!smartcard_ndr_pointer_write(s, &index, readerLen))
4919 return SCARD_E_NO_MEMORY;
4922 smartcard_pack_redir_scard_context(log, s, &call->Common.handles.hContext, &index);
4923 if (status != SCARD_S_SUCCESS)
4926 if (!Stream_EnsureRemainingCapacity(s, 8))
4927 return SCARD_E_NO_MEMORY;
4929 Stream_Write_UINT32(s, call->Common.dwShareMode);
4930 Stream_Write_UINT32(s, call->Common.dwPreferredProtocols);
4934 status = smartcard_ndr_write_w(s, call->szReader, readerLen, NDR_PTR_FULL);
4935 if (status != SCARD_S_SUCCESS)
4939 return smartcard_pack_redir_scard_context_ref(log, s, &call->Common.handles.hContext);
4945 wLog* log = scard_log();
4948 smartcard_trace_control_call(log, call);
4950 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4951 if (status != SCARD_S_SUCCESS)
4954 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
4955 if (status != SCARD_S_SUCCESS)
4958 if (!Stream_EnsureRemainingCapacity(s, 8))
4959 return SCARD_E_NO_MEMORY;
4961 Stream_Write_UINT32(s, call->dwControlCode);
4962 Stream_Write_UINT32(s, call->cbInBufferSize);
4963 if (!smartcard_ndr_pointer_write(s, &index, call->cbInBufferSize))
4964 return SCARD_E_NO_MEMORY;
4966 if (!Stream_EnsureRemainingCapacity(s, 8))
4967 return SCARD_E_NO_MEMORY;
4969 Stream_Write_INT32(s, call->fpvOutBufferIsNULL);
4970 Stream_Write_UINT32(s, call->cbOutBufferSize);
4972 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4973 if (status != SCARD_S_SUCCESS)
4976 status = smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
4977 if (status != SCARD_S_SUCCESS)
4980 if (call->cbInBufferSize)
4982 status = smartcard_ndr_write(s, call->pvInBuffer, call->cbInBufferSize, 1, NDR_PTR_SIMPLE);
4983 if (status != SCARD_S_SUCCESS)
4994 wLog* log = scard_log();
4997 smartcard_trace_hcard_and_disposition_call(log, call, name);
4999 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
5000 if (status != SCARD_S_SUCCESS)
5003 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
5004 if (status != SCARD_S_SUCCESS)
5007 if (!Stream_EnsureRemainingCapacity(s, 4))
5008 return SCARD_E_NO_MEMORY;
5010 Stream_Write_UINT32(s, call->dwDisposition);
5012 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
5013 if (status != SCARD_S_SUCCESS)
5016 return smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
5022 wLog* log = scard_log();
5025 smartcard_trace_transmit_call(log, call);
5027 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
5028 if (status != SCARD_S_SUCCESS)
5031 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
5032 if (status != SCARD_S_SUCCESS)
5035 UINT32 cbExtraBytes = 0;
5036 const BYTE* pbExtraBytes =
nullptr;
5037 if (call->pioSendPci)
5039 cbExtraBytes = (UINT32)(call->pioSendPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
5040 if (cbExtraBytes > 0)
5044 if (!Stream_EnsureRemainingCapacity(s, 32))
5045 return SCARD_E_NO_MEMORY;
5047 Stream_Write_UINT32(s, call->pioSendPci ? call->pioSendPci->dwProtocol : 0);
5048 Stream_Write_UINT32(s, cbExtraBytes);
5049 if (!smartcard_ndr_pointer_write(s, &index, cbExtraBytes))
5050 return SCARD_E_NO_MEMORY;
5052 Stream_Write_UINT32(s, call->cbSendLength);
5053 if (!smartcard_ndr_pointer_write(s, &index, call->cbSendLength))
5054 return SCARD_E_NO_MEMORY;
5056 const UINT32 recvPciLen = call->pioRecvPci ? (UINT32)call->pioRecvPci->cbPciLength : 0;
5057 if (!smartcard_ndr_pointer_write(s, &index, recvPciLen))
5058 return SCARD_E_NO_MEMORY;
5060 Stream_Write_INT32(s, call->fpbRecvBufferIsNULL);
5061 Stream_Write_UINT32(s, call->cbRecvLength);
5063 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
5064 if (status != SCARD_S_SUCCESS)
5067 status = smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
5068 if (status != SCARD_S_SUCCESS)
5071 if (cbExtraBytes > 0)
5073 status = smartcard_ndr_write(s, pbExtraBytes, cbExtraBytes, 1, NDR_PTR_SIMPLE);
5074 if (status != SCARD_S_SUCCESS)
5078 if (call->cbSendLength > 0)
5080 status = smartcard_ndr_write(s, call->pbSendBuffer, call->cbSendLength, 1, NDR_PTR_SIMPLE);
5081 if (status != SCARD_S_SUCCESS)
5085 if (call->pioRecvPci && recvPciLen > 0)
5087 UINT32 cbRecvExtra = (UINT32)(call->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
5088 const BYTE* pbRecvExtra = &((
const BYTE*)call->pioRecvPci)[
sizeof(
SCARD_IO_REQUEST)];
5090 if (!Stream_EnsureRemainingCapacity(s, 12))
5091 return SCARD_E_NO_MEMORY;
5093 Stream_Write_UINT32(s, call->pioRecvPci->dwProtocol);
5094 Stream_Write_UINT32(s, cbRecvExtra);
5095 if (!smartcard_ndr_pointer_write(s, &index, cbRecvExtra))
5096 return SCARD_E_NO_MEMORY;
5098 if (cbRecvExtra > 0)
5100 status = smartcard_ndr_write(s, pbRecvExtra, cbRecvExtra, 1, NDR_PTR_SIMPLE);
5101 if (status != SCARD_S_SUCCESS)
5106 return SCARD_S_SUCCESS;
5112 wLog* log = scard_log();
5115 smartcard_trace_get_attrib_call(log, call);
5117 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
5118 if (status != SCARD_S_SUCCESS)
5121 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
5122 if (status != SCARD_S_SUCCESS)
5125 if (!Stream_EnsureRemainingCapacity(s, 12))
5126 return STATUS_NO_MEMORY;
5128 Stream_Write_UINT32(s, call->dwAttrId);
5129 Stream_Write_INT32(s, call->fpbAttrIsNULL);
5130 Stream_Write_UINT32(s, call->cbAttrLen);
5132 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
5133 if (status != SCARD_S_SUCCESS)
5136 return smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
5139LONG smartcard_unpack_list_readers_return(
wStream* s, ListReaders_Return* ret, BOOL unicode)
5142 wLog* log = scard_log();
5144 UINT32 mszNdrPtr = 0;
5146 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
5147 return STATUS_BUFFER_TOO_SMALL;
5149 const UINT32 cBytes = Stream_Get_UINT32(s);
5151 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
5152 return ERROR_INVALID_DATA;
5156 LONG status = smartcard_ndr_read(log, s, &ret->msz, cBytes, 1, NDR_PTR_SIMPLE);
5157 if (status != SCARD_S_SUCCESS)
5159 ret->cBytes = cBytes;
5162 smartcard_trace_list_readers_return(log, ret, unicode);
5163 return SCARD_S_SUCCESS;
5166LONG smartcard_unpack_get_status_change_return(
wStream* s, GetStatusChange_Return* ret,
5170 wLog* log = scard_log();
5175 ret->rgReaderStates =
nullptr;
5176 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
5177 return STATUS_BUFFER_TOO_SMALL;
5179 const UINT32 cReaders = Stream_Get_UINT32(s);
5182 WLog_Print(log, WLOG_ERROR,
5183 "2.2.3.5 LocateCards_Return and GetStatusChange_Return cReaders(%" PRIu32
5186 return SCARD_E_INVALID_PARAMETER;
5189 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
5190 return ERROR_INVALID_DATA;
5192 if ((cReaders > 0) && !ndrPtr)
5194 WLog_Print(log, WLOG_WARN,
5195 "GetStatusChange_Return rgReaderStatesNdrPtr (0x%08" PRIX32
5196 ") and cReaders (0x%08" PRIX32
") inconsistency",
5198 return SCARD_E_INVALID_VALUE;
5204 smartcard_ndr_read_state(log, s, &ret->rgReaderStates, ret->cReaders, NDR_PTR_SIMPLE);
5205 if (status != SCARD_S_SUCCESS)
5207 ret->cReaders = cReaders;
5210 smartcard_trace_get_status_change_return(log, ret, unicode);
5211 return SCARD_S_SUCCESS;
5217 wLog* log = scard_log();
5219 UINT32 pbContextNdrPtr = 0;
5222 smartcard_unpack_redir_scard_context(log, s, &ret->hContext, &index, &pbContextNdrPtr);
5223 if (status != SCARD_S_SUCCESS)
5226 status = smartcard_unpack_redir_scard_handle(log, s, &ret->hCard, &index);
5227 if (status != SCARD_S_SUCCESS)
5230 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
5231 return STATUS_BUFFER_TOO_SMALL;
5233 Stream_Read_UINT32(s, ret->dwActiveProtocol);
5235 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &ret->hContext);
5236 if (status != SCARD_S_SUCCESS)
5239 status = smartcard_unpack_redir_scard_handle_ref(log, s, &ret->hCard);
5240 if (status != SCARD_S_SUCCESS)
5243 smartcard_trace_connect_return(log, ret);
5244 return SCARD_S_SUCCESS;
5250 wLog* log = scard_log();
5252 UINT32 pvOutBufferNdrPtr = 0;
5254 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
5255 return STATUS_BUFFER_TOO_SMALL;
5257 const UINT32 cbOutBufferSize = Stream_Get_UINT32(s);
5259 if (!smartcard_ndr_pointer_read(log, s, &index, &pvOutBufferNdrPtr))
5260 return ERROR_INVALID_DATA;
5262 if (pvOutBufferNdrPtr && (cbOutBufferSize > 0))
5265 smartcard_ndr_read(log, s, &ret->pvOutBuffer, cbOutBufferSize, 1, NDR_PTR_SIMPLE);
5266 if (status != SCARD_S_SUCCESS)
5268 ret->cbOutBufferSize = cbOutBufferSize;
5270 smartcard_trace_control_return(log, ret);
5271 return SCARD_S_SUCCESS;
5277 wLog* log = scard_log();
5279 UINT32 recvPciNdrPtr = 0;
5280 UINT32 recvBufferNdrPtr = 0;
5282 if (!smartcard_ndr_pointer_read(log, s, &index, &recvPciNdrPtr))
5283 return ERROR_INVALID_DATA;
5285 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
5286 return STATUS_BUFFER_TOO_SMALL;
5288 const UINT32 cbRecvLength = Stream_Get_UINT32(s);
5289 if (cbRecvLength > 66560)
5291 WLog_Print(log, WLOG_ERROR,
"2.2.3.11 Transmit_Return cbRecvLength(%" PRIu32
") > 66560",
5293 return SCARD_E_INVALID_PARAMETER;
5296 if (!smartcard_ndr_pointer_read(log, s, &index, &recvBufferNdrPtr))
5297 return ERROR_INVALID_DATA;
5301 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
5302 return STATUS_BUFFER_TOO_SMALL;
5304 UINT32 dwProtocol = 0;
5305 UINT32 cbExtraBytes = 0;
5306 Stream_Read_UINT32(s, dwProtocol);
5307 Stream_Read_UINT32(s, cbExtraBytes);
5309 UINT32 pbExtraBytesNdrPtr = 0;
5310 if (!smartcard_ndr_pointer_read(log, s, &index, &pbExtraBytesNdrPtr))
5311 return ERROR_INVALID_DATA;
5313 if (pbExtraBytesNdrPtr)
5315 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
5316 return STATUS_BUFFER_TOO_SMALL;
5319 Stream_Read_UINT32(s, length);
5320 if (length != cbExtraBytes)
5322 WLog_Print(log, WLOG_WARN,
5323 "Transmit_Return unexpected length: Actual: %" PRIu32
5324 ", Expected: %" PRIu32
" (pioRecvPci.cbExtraBytes)",
5325 length, cbExtraBytes);
5326 return STATUS_INVALID_PARAMETER;
5329 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, cbExtraBytes))
5330 return STATUS_BUFFER_TOO_SMALL;
5332 ret->pioRecvPci = (LPSCARD_IO_REQUEST)malloc(
sizeof(
SCARD_IO_REQUEST) + cbExtraBytes);
5333 if (!ret->pioRecvPci)
5334 return SCARD_E_NO_MEMORY;
5336 ret->pioRecvPci->dwProtocol = dwProtocol;
5337 ret->pioRecvPci->cbPciLength = (DWORD)(
sizeof(
SCARD_IO_REQUEST) + cbExtraBytes);
5340 Stream_Read(s, pbExtraBytes, length);
5341 if (smartcard_unpack_read_size_align(s, cbExtraBytes, 4) < 0)
5342 return STATUS_INVALID_PARAMETER;
5347 if (!ret->pioRecvPci)
5348 return SCARD_E_NO_MEMORY;
5350 ret->pioRecvPci->dwProtocol = dwProtocol;
5355 if (recvBufferNdrPtr && (cbRecvLength > 0))
5358 smartcard_ndr_read(log, s, &ret->pbRecvBuffer, cbRecvLength, 1, NDR_PTR_SIMPLE);
5359 if (status != SCARD_S_SUCCESS)
5361 ret->cbRecvLength = cbRecvLength;
5364 smartcard_trace_transmit_return(log, ret);
5365 return SCARD_S_SUCCESS;
5371 wLog* log = scard_log();
5373 UINT32 pbAttrPtr = 0;
5375 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
5376 return STATUS_BUFFER_TOO_SMALL;
5378 const UINT32 cbAttrLen = Stream_Get_UINT32(s);
5379 if (cbAttrLen > 65536)
5381 WLog_Print(log, WLOG_ERROR,
"2.2.3.12 GetAttrib_Return cbAttrLen(%" PRIu32
") > 65536",
5383 return SCARD_E_INVALID_PARAMETER;
5386 if (!smartcard_ndr_pointer_read(log, s, &index, &pbAttrPtr))
5387 return ERROR_INVALID_DATA;
5389 LONG status = smartcard_ndr_read(log, s, &ret->pbAttr, cbAttrLen, 1, NDR_PTR_SIMPLE);
5390 if (status != SCARD_S_SUCCESS)
5392 ret->cbAttrLen = cbAttrLen;
5394 smartcard_trace_get_attrib_return(log, ret, 0);
5395 return SCARD_S_SUCCESS;
5398BOOL smartcard_reader_state_return_is_valid_ex(
size_t pos,
const ReaderState_Return* val,
5399 const char* file,
size_t line,
const char* fkt)
5403 WLog_Print_dbg_tag(SCARD_TAG, WLOG_WARN, line, file, fkt,
"[%" PRIuz
"] val = nullptr",
5407 if (val->cbAtr >
sizeof(val->rgbAtr))
5409 WLog_Print_dbg_tag(SCARD_TAG, WLOG_WARN, line, file, fkt,
5410 "[%" PRIuz
"] val->cbAtr=%" PRIu32
", max=%" PRIuz, pos, val->cbAtr,
5411 sizeof(val->rgbAtr));