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__, \
53static LONG smartcard_unpack_redir_scard_context_(wLog* log,
wStream* s,
55 UINT32* ppbContextNdrPtr,
const char* file,
56 const char* function,
size_t line);
57static LONG smartcard_pack_redir_scard_context(wLog* log,
wStream* s,
60 UINT32* index,
const char* file,
61 const char* function,
size_t line);
62static LONG smartcard_pack_redir_scard_handle(wLog* log,
wStream* s,
64static LONG smartcard_unpack_redir_scard_context_ref(wLog* log,
wStream* s, UINT32 pbContextNdrPtr,
66static LONG smartcard_pack_redir_scard_context_ref(wLog* log,
wStream* s,
69static LONG smartcard_unpack_redir_scard_handle_ref(wLog* log,
wStream* s,
71static LONG smartcard_pack_redir_scard_handle_ref(wLog* log,
wStream* s,
83#define smartcard_ndr_pointer_read(log, s, index, ptr) \
84 smartcard_ndr_pointer_read_((log), (s), (index), (ptr), __FILE__, __func__, __LINE__)
85static BOOL smartcard_ndr_pointer_read_(wLog* log,
wStream* s, UINT32* index, UINT32* ptr,
86 const char* file,
const char* fkt,
size_t line)
88 const UINT32 expect = 0x20000 + (*index) * 4;
93 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
96 Stream_Read_UINT32(s, ndrPtr);
102 if (ptr && (ndrPtr == 0))
104 WLog_Print(log, WLOG_WARN,
105 "[%s:%" PRIuz
"] Read context pointer 0x%08" PRIx32
", expected 0x%08" PRIx32,
106 fkt, line, ndrPtr, expect);
110 (*index) = (*index) + 1;
114static LONG smartcard_ndr_read_ex(wLog* log,
wStream* s, BYTE** data,
size_t min,
115 size_t elementSize, ndr_ptr_t type,
size_t* plen)
139 return STATUS_INVALID_PARAMETER;
142 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, required))
143 return STATUS_BUFFER_TOO_SMALL;
148 Stream_Read_UINT32(s, len);
149 Stream_Read_UINT32(s, offset);
150 Stream_Read_UINT32(s, len2);
151 if (len != offset + len2)
153 WLog_Print(log, WLOG_ERROR,
154 "Invalid data when reading full NDR pointer: total=%" PRIuz
155 ", offset=%" PRIuz
", remaining=%" PRIuz,
157 return STATUS_BUFFER_TOO_SMALL;
161 Stream_Read_UINT32(s, len);
163 if ((len != min) && (min > 0))
165 WLog_Print(log, WLOG_ERROR,
166 "Invalid data when reading simple NDR pointer: total=%" PRIuz
167 ", expected=%" PRIuz,
169 return STATUS_BUFFER_TOO_SMALL;
176 return STATUS_INVALID_PARAMETER;
181 WLog_Print(log, WLOG_ERROR,
182 "Invalid length read from NDR pointer, minimum %" PRIuz
", got %" PRIuz, min,
184 return STATUS_DATA_ERROR;
187 if (len > SIZE_MAX / 2)
188 return STATUS_BUFFER_TOO_SMALL;
190 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(log, s, len, elementSize))
191 return STATUS_BUFFER_TOO_SMALL;
198 r = calloc(len +
sizeof(WCHAR),
sizeof(CHAR));
200 return SCARD_E_NO_MEMORY;
201 Stream_Read(s, r, len);
202 const LONG pad = smartcard_unpack_read_size_align(s, len, 4);
206 return STATUS_INVALID_PARAMETER;
212 return STATUS_SUCCESS;
215static LONG smartcard_ndr_read(wLog* log,
wStream* s, BYTE** data,
size_t min,
size_t elementSize,
218 return smartcard_ndr_read_ex(log, s, data, min, elementSize, type,
nullptr);
221static BOOL smartcard_ndr_pointer_write(
wStream* s, UINT32* index, DWORD length)
223 const UINT32 ndrPtr = 0x20000 + (*index) * 4;
227 if (!Stream_EnsureRemainingCapacity(s, 4))
232 Stream_Write_UINT32(s, ndrPtr);
233 (*index) = (*index) + 1;
236 Stream_Write_UINT32(s, 0);
240static LONG smartcard_ndr_write(
wStream* s,
const BYTE* data, UINT32 size, UINT32 elementSize,
243 const UINT32 offset = 0;
244 const UINT32 len = size;
245 const UINT32 dataLen = size * elementSize;
249 return SCARD_S_SUCCESS;
263 return SCARD_E_INVALID_PARAMETER;
266 if (!Stream_EnsureRemainingCapacity(s, required + dataLen + 4))
267 return STATUS_BUFFER_TOO_SMALL;
272 Stream_Write_UINT32(s, len);
273 Stream_Write_UINT32(s, offset);
274 Stream_Write_UINT32(s, len);
277 Stream_Write_UINT32(s, len);
282 return SCARD_E_INVALID_PARAMETER;
286 Stream_Write(s, data, dataLen);
288 Stream_Zero(s, dataLen);
289 return smartcard_pack_write_size_align(s, len, 4);
301 WINPR_ASSERT(data || (size == 0));
307 size_t min, ndr_ptr_t type)
318static LONG smartcard_ndr_read_fixed_string_a(wLog* log,
wStream* s, CHAR** data,
size_t min,
327 return smartcard_ndr_read(log, s, u.ppv, min,
sizeof(CHAR), type);
330static LONG smartcard_ndr_read_fixed_string_w(wLog* log,
wStream* s, WCHAR** data,
size_t min,
339 return smartcard_ndr_read(log, s, u.ppv, min,
sizeof(WCHAR), type);
342static LONG smartcard_ndr_read_a(wLog* log,
wStream* s, CHAR** data, ndr_ptr_t type)
350 return smartcard_ndr_read(log, s, u.ppv, 0,
sizeof(CHAR), type);
353static LONG smartcard_ndr_read_w(wLog* log,
wStream* s, WCHAR** data, ndr_ptr_t type)
361 return smartcard_ndr_read(log, s, u.ppv, 0,
sizeof(WCHAR), type);
364static LONG smartcard_ndr_read_u(wLog* log,
wStream* s,
UUID** data)
372 return smartcard_ndr_read(log, s, u.ppv, 1,
sizeof(
UUID), NDR_PTR_FIXED);
375static char* smartcard_convert_string_list(
const void* in,
size_t bytes, BOOL unicode)
384 char* mszA =
nullptr;
396 mszA = ConvertMszWCharNToUtf8Alloc(
string.wz, bytes /
sizeof(WCHAR), &length);
402 mszA = (
char*)calloc(bytes,
sizeof(
char));
405 CopyMemory(mszA,
string.sz, bytes - 1);
414 for (
size_t index = 0; index < length - 1; index++)
416 if (mszA[index] ==
'\0')
423WINPR_ATTR_MALLOC(free, 1)
424static
char* smartcard_create_msz_dump(const
char* msz,
size_t len)
426 size_t bufferLen = len;
427 char* buffer = calloc(len + 1, 1);
432 const char* cur = msz;
434 while ((len > 0) && cur && cur[0] !=
'\0' && (bufferLen > 0))
436 size_t clen = strnlen(cur, len);
437 int rc = _snprintf(buf, bufferLen,
"%s", cur);
438 bufferLen -= (size_t)rc;
447static void smartcard_msz_dump(wLog* log, DWORD level,
const char* prefix,
const void* data,
448 size_t len, BOOL wchar)
450 if (!WLog_IsLevelActive(log, level))
454 const char* msz = WINPR_CXX_COMPAT_CAST(
const char*, data);
458 tmp = ConvertMszWCharNToUtf8Alloc(data, len, &mszlen);
462 char* array = smartcard_create_msz_dump(msz, mszlen);
463 WLog_Print(log, level,
"%s%s", prefix, array);
468WINPR_ATTR_MALLOC(free, 1)
469static
char* smartcard_create_array_dump(const
void* pd,
size_t len)
471 const BYTE* data = pd;
474 size_t bufferLen = len * 4;
477 char* buffer = calloc(bufferLen + 1, 1);
480 char* start = buffer;
482 WINPR_ASSERT(buffer || (bufferLen == 0));
484 if (!data && (len > 0))
486 (void)_snprintf(buffer, bufferLen,
"{ nullptr [%" PRIuz
"] }", len);
490 rc = _snprintf(buffer, bufferLen,
"{ ");
491 if ((rc < 0) || ((
size_t)rc >= bufferLen))
494 bufferLen -= (size_t)rc;
496 for (
size_t x = 0; x < len; x++)
498 rc = _snprintf(buffer, bufferLen,
"%02X", data[x]);
499 if ((rc < 0) || ((
size_t)rc >= bufferLen))
502 bufferLen -= (size_t)rc;
505 rc = _snprintf(buffer, bufferLen,
" }");
506 if ((rc < 0) || ((
size_t)rc >= bufferLen))
513static void smartcard_dump_array(wLog* log, DWORD level,
const char* prefix,
const char* postfix,
514 const void* data,
size_t len, ...)
516 if (!WLog_IsLevelActive(log, level))
519 char* buffer = smartcard_create_array_dump(data, len);
521 char* fprefix =
nullptr;
523 va_list ap = WINPR_C_ARRAY_INIT;
525 winpr_vasprintf(&fprefix, &flen, prefix, ap);
527 WLog_Print(log, level,
"%s%s%s", prefix, buffer, postfix);
532static void smartcard_log_redir_handle(wLog* log,
const REDIR_SCARDHANDLE* pHandle)
534 WINPR_ASSERT(pHandle);
535 smartcard_dump_array(log, g_LogLevel,
" hContext: ",
"", pHandle->pbHandle, pHandle->cbHandle);
540 WINPR_ASSERT(phContext);
541 smartcard_dump_array(log, g_LogLevel,
"hContext: %s",
"", phContext->pbContext,
542 phContext->cbContext);
545static void smartcard_trace_context_and_string_call_a(wLog* log,
const char* name,
549 if (!WLog_IsLevelActive(log, g_LogLevel))
552 WLog_Print(log, g_LogLevel,
"%s {", name);
553 smartcard_log_context(log, phContext);
554 WLog_Print(log, g_LogLevel,
" sz=%s", sz);
556 WLog_Print(log, g_LogLevel,
"}");
559static void smartcard_trace_context_and_string_call_w(wLog* log,
const char* name,
563 char tmp[1024] = WINPR_C_ARRAY_INIT;
565 if (!WLog_IsLevelActive(log, g_LogLevel))
569 (void)ConvertWCharToUtf8(sz, tmp, ARRAYSIZE(tmp));
571 WLog_Print(log, g_LogLevel,
"%s {", name);
572 smartcard_log_context(log, phContext);
573 WLog_Print(log, g_LogLevel,
" sz=%s", tmp);
574 WLog_Print(log, g_LogLevel,
"}");
577static void smartcard_trace_context_call(wLog* log,
const Context_Call* call,
const char* name)
581 if (!WLog_IsLevelActive(log, g_LogLevel))
584 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
585 smartcard_log_context(log, &call->handles.hContext);
587 WLog_Print(log, g_LogLevel,
"}");
595 if (!WLog_IsLevelActive(log, g_LogLevel))
598 WLog_Print(log, g_LogLevel,
"ListReaderGroups%s_Call {", unicode ?
"W" :
"A");
599 smartcard_log_context(log, &call->handles.hContext);
601 WLog_Print(log, g_LogLevel,
"fmszGroupsIsNULL: %" PRId32
" cchGroups: 0x%08" PRIx32,
602 call->fmszGroupsIsNULL, call->cchGroups);
603 WLog_Print(log, g_LogLevel,
"}");
606static void dump_reader_states_return(wLog* log,
const ReaderState_Return* rgReaderStates,
609 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
610 for (UINT32 index = 0; index < cReaders; index++)
613 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
614 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
615 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
616 szCurrentState, readerState->dwCurrentState);
617 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
618 szEventState, readerState->dwEventState);
619 free(szCurrentState);
622 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
623 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
630 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
631 for (UINT32 index = 0; index < cReaders; index++)
635 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
636 readerState->szReader, readerState->cbAtr);
637 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
638 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
639 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
640 szCurrentState, readerState->dwCurrentState);
641 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
642 szEventState, readerState->dwEventState);
643 free(szCurrentState);
646 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
647 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
654 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
655 for (UINT32 index = 0; index < cReaders; index++)
658 char* buffer = ConvertWCharToUtf8Alloc(readerState->szReader,
nullptr);
659 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
660 buffer, readerState->cbAtr);
662 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
663 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
664 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
665 szCurrentState, readerState->dwCurrentState);
666 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
667 szEventState, readerState->dwEventState);
668 free(szCurrentState);
671 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
672 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
680 if (!WLog_IsLevelActive(log, g_LogLevel))
683 WLog_Print(log, g_LogLevel,
"GetStatusChangeW_Call {");
684 smartcard_log_context(log, &call->handles.hContext);
686 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
689 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
691 WLog_Print(log, g_LogLevel,
"}");
699 if (!WLog_IsLevelActive(log, g_LogLevel))
702 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
704 WLog_Print(log, g_LogLevel,
"ListReaderGroups%s_Return {", unicode ?
"W" :
"A");
705 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIx32
")",
706 SCardGetErrorString(ret->ReturnCode),
707 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
708 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
709 WLog_Print(log, g_LogLevel,
"}");
713static void smartcard_trace_list_readers_call(wLog* log,
const ListReaders_Call* call, BOOL unicode)
717 if (!WLog_IsLevelActive(log, g_LogLevel))
720 char* mszGroupsA = smartcard_convert_string_list(call->mszGroups, call->cBytes, unicode);
722 WLog_Print(log, g_LogLevel,
"ListReaders%s_Call {", unicode ?
"W" :
"A");
723 smartcard_log_context(log, &call->handles.hContext);
725 WLog_Print(log, g_LogLevel,
726 "cBytes: %" PRIu32
" mszGroups: %s fmszReadersIsNULL: %" PRId32
727 " cchReaders: 0x%08" PRIX32
"",
728 call->cBytes, mszGroupsA, call->fmszReadersIsNULL, call->cchReaders);
729 WLog_Print(log, g_LogLevel,
"}");
734static void smartcard_trace_locate_cards_by_atr_a_call(wLog* log,
739 if (!WLog_IsLevelActive(log, g_LogLevel))
742 WLog_Print(log, g_LogLevel,
"LocateCardsByATRA_Call {");
743 smartcard_log_context(log, &call->handles.hContext);
745 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
747 WLog_Print(log, g_LogLevel,
"}");
750static void smartcard_trace_locate_cards_a_call(wLog* log,
const LocateCardsA_Call* call)
754 if (!WLog_IsLevelActive(log, g_LogLevel))
757 WLog_Print(log, g_LogLevel,
"LocateCardsA_Call {");
758 smartcard_log_context(log, &call->handles.hContext);
759 WLog_Print(log, g_LogLevel,
" cBytes=%" PRIu32, call->cBytes);
760 smartcard_msz_dump(log, g_LogLevel,
" mszCards=", call->mszCards, call->cBytes, FALSE);
761 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, call->cReaders);
762 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
764 WLog_Print(log, g_LogLevel,
"}");
767static void smartcard_trace_locate_cards_return(wLog* log,
const LocateCards_Return* ret)
771 if (!WLog_IsLevelActive(log, g_LogLevel))
774 WLog_Print(log, g_LogLevel,
"LocateCards_Return {");
775 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
776 SCardGetErrorString(ret->ReturnCode),
777 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
779 if (ret->ReturnCode == SCARD_S_SUCCESS)
781 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, ret->cReaders);
783 WLog_Print(log, g_LogLevel,
"}");
790 if (!WLog_IsLevelActive(log, g_LogLevel))
793 WLog_Print(log, g_LogLevel,
"GetReaderIcon_Return {");
794 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
795 SCardGetErrorString(ret->ReturnCode),
796 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
798 if (ret->ReturnCode == SCARD_S_SUCCESS)
800 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, ret->cbDataLen);
802 WLog_Print(log, g_LogLevel,
"}");
809 if (!WLog_IsLevelActive(log, g_LogLevel))
812 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Return {");
813 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
814 SCardGetErrorString(ret->ReturnCode),
815 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
817 WLog_Print(log, g_LogLevel,
" cTransmitCount=%" PRIu32, ret->cTransmitCount);
818 WLog_Print(log, g_LogLevel,
"}");
821static void smartcard_trace_read_cache_return(wLog* log,
const ReadCache_Return* ret)
825 if (!WLog_IsLevelActive(log, g_LogLevel))
828 WLog_Print(log, g_LogLevel,
"ReadCache_Return {");
829 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
830 SCardGetErrorString(ret->ReturnCode),
831 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
833 if (ret->ReturnCode == SCARD_S_SUCCESS)
835 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, ret->cbDataLen);
836 smartcard_dump_array(log, g_LogLevel,
" cbData: ",
"", ret->pbData, ret->cbDataLen);
838 WLog_Print(log, g_LogLevel,
"}");
841static void smartcard_trace_locate_cards_w_call(wLog* log,
const LocateCardsW_Call* call)
845 if (!WLog_IsLevelActive(log, g_LogLevel))
848 WLog_Print(log, g_LogLevel,
"LocateCardsW_Call {");
849 smartcard_log_context(log, &call->handles.hContext);
850 WLog_Print(log, g_LogLevel,
" cBytes=%" PRIu32, call->cBytes);
851 smartcard_msz_dump(log, g_LogLevel,
" sz2=", call->mszCards, call->cBytes, TRUE);
852 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, call->cReaders);
853 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
854 WLog_Print(log, g_LogLevel,
"}");
857static void smartcard_trace_list_readers_return(wLog* log,
const ListReaders_Return* ret,
862 if (!WLog_IsLevelActive(log, g_LogLevel))
865 WLog_Print(log, g_LogLevel,
"ListReaders%s_Return {", unicode ?
"W" :
"A");
866 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
867 SCardGetErrorString(ret->ReturnCode),
868 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
870 if (ret->ReturnCode != SCARD_S_SUCCESS)
872 WLog_Print(log, g_LogLevel,
"}");
876 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
878 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
879 WLog_Print(log, g_LogLevel,
"}");
888 if (!WLog_IsLevelActive(log, g_LogLevel))
891 WLog_Print(log, g_LogLevel,
"GetStatusChange%s_Return {", unicode ?
"W" :
"A");
892 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
893 SCardGetErrorString(ret->ReturnCode),
894 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
895 WLog_Print(log, g_LogLevel,
" cReaders: %" PRIu32
"", ret->cReaders);
897 dump_reader_states_return(log, ret->rgReaderStates, ret->cReaders);
899 if (!ret->rgReaderStates && (ret->cReaders > 0))
901 WLog_Print(log, g_LogLevel,
" [INVALID STATE] rgReaderStates=nullptr, cReaders=%" PRIu32,
904 else if (ret->ReturnCode != SCARD_S_SUCCESS)
906 WLog_Print(log, g_LogLevel,
" [INVALID RETURN] rgReaderStates, cReaders=%" PRIu32,
911 for (UINT32 index = 0; index < ret->cReaders; index++)
914 char* szCurrentState = SCardGetReaderStateString(rgReaderState->dwCurrentState);
915 char* szEventState = SCardGetReaderStateString(rgReaderState->dwEventState);
916 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")",
917 index, szCurrentState, rgReaderState->dwCurrentState);
918 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")",
919 index, szEventState, rgReaderState->dwEventState);
920 smartcard_dump_array(
921 log, g_LogLevel,
" [%" PRIu32
"]: cbAtr: %" PRIu32
" rgbAtr: ",
"",
922 rgReaderState->rgbAtr, rgReaderState->cbAtr, index, rgReaderState->cbAtr);
923 free(szCurrentState);
928 WLog_Print(log, g_LogLevel,
"}");
931static void smartcard_trace_context_and_two_strings_a_call(wLog* log,
936 if (!WLog_IsLevelActive(log, g_LogLevel))
939 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
940 smartcard_log_context(log, &call->handles.hContext);
941 WLog_Print(log, g_LogLevel,
" sz1=%s", call->sz1);
942 WLog_Print(log, g_LogLevel,
" sz2=%s", call->sz2);
943 WLog_Print(log, g_LogLevel,
"}");
946static void smartcard_trace_context_and_two_strings_w_call(wLog* log,
950 char sz1[1024] = WINPR_C_ARRAY_INIT;
951 char sz2[1024] = WINPR_C_ARRAY_INIT;
953 if (!WLog_IsLevelActive(log, g_LogLevel))
956 (void)ConvertWCharToUtf8(call->sz1, sz1, ARRAYSIZE(sz1));
958 (void)ConvertWCharToUtf8(call->sz2, sz2, ARRAYSIZE(sz2));
960 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
961 smartcard_log_context(log, &call->handles.hContext);
962 WLog_Print(log, g_LogLevel,
" sz1=%s", sz1);
963 WLog_Print(log, g_LogLevel,
" sz2=%s", sz2);
964 WLog_Print(log, g_LogLevel,
"}");
971 if (!WLog_IsLevelActive(log, g_LogLevel))
974 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Call {");
975 smartcard_log_context(log, &call->handles.hContext);
976 smartcard_log_redir_handle(log, &call->handles.hCard);
978 WLog_Print(log, g_LogLevel,
"}");
981static void smartcard_trace_write_cache_a_call(wLog* log,
const WriteCacheA_Call* call)
985 if (!WLog_IsLevelActive(log, g_LogLevel))
988 WLog_Print(log, g_LogLevel,
"WriteCacheA_Call {");
990 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
992 smartcard_log_context(log, &call->Common.handles.hContext);
993 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
995 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
996 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
997 smartcard_dump_array(log, g_LogLevel,
" pbData=",
"", call->Common.pbData,
998 call->Common.cbDataLen);
999 WLog_Print(log, g_LogLevel,
"}");
1002static void smartcard_trace_write_cache_w_call(wLog* log,
const WriteCacheW_Call* call)
1005 char tmp[1024] = WINPR_C_ARRAY_INIT;
1007 if (!WLog_IsLevelActive(log, g_LogLevel))
1010 WLog_Print(log, g_LogLevel,
"WriteCacheW_Call {");
1012 if (call->szLookupName)
1013 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
1014 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
1016 smartcard_log_context(log, &call->Common.handles.hContext);
1017 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1019 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1020 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1021 smartcard_dump_array(log, g_LogLevel,
" pbData=",
"", call->Common.pbData,
1022 call->Common.cbDataLen);
1023 WLog_Print(log, g_LogLevel,
"}");
1026static void smartcard_trace_read_cache_a_call(wLog* log,
const ReadCacheA_Call* call)
1030 if (!WLog_IsLevelActive(log, g_LogLevel))
1033 WLog_Print(log, g_LogLevel,
"ReadCacheA_Call {");
1035 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
1036 smartcard_log_context(log, &call->Common.handles.hContext);
1037 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1039 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1040 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1041 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1043 WLog_Print(log, g_LogLevel,
"}");
1046static void smartcard_trace_read_cache_w_call(wLog* log,
const ReadCacheW_Call* call)
1049 char tmp[1024] = WINPR_C_ARRAY_INIT;
1051 if (!WLog_IsLevelActive(log, g_LogLevel))
1054 WLog_Print(log, g_LogLevel,
"ReadCacheW_Call {");
1055 if (call->szLookupName)
1056 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
1057 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
1059 smartcard_log_context(log, &call->Common.handles.hContext);
1060 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1062 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1063 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1064 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1066 WLog_Print(log, g_LogLevel,
"}");
1069static void smartcard_trace_transmit_call(wLog* log,
const Transmit_Call* call)
1072 UINT32 cbExtraBytes = 0;
1073 BYTE* pbExtraBytes =
nullptr;
1075 if (!WLog_IsLevelActive(log, g_LogLevel))
1078 WLog_Print(log, g_LogLevel,
"Transmit_Call {");
1079 smartcard_log_context(log, &call->handles.hContext);
1080 smartcard_log_redir_handle(log, &call->handles.hCard);
1082 if (call->pioSendPci)
1084 cbExtraBytes = (UINT32)(call->pioSendPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1086 WLog_Print(log, g_LogLevel,
"pioSendPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1087 call->pioSendPci->dwProtocol, cbExtraBytes);
1091 smartcard_dump_array(log, g_LogLevel,
"pbExtraBytes: ",
"", pbExtraBytes, cbExtraBytes);
1096 WLog_Print(log, g_LogLevel,
"pioSendPci: null");
1099 WLog_Print(log, g_LogLevel,
"cbSendLength: %" PRIu32
"", call->cbSendLength);
1101 if (call->pbSendBuffer)
1103 smartcard_dump_array(log, g_LogLevel,
"pbSendBuffer: ",
"", call->pbSendBuffer,
1104 call->cbSendLength);
1108 WLog_Print(log, g_LogLevel,
"pbSendBuffer: null");
1111 if (call->pioRecvPci)
1113 cbExtraBytes = (UINT32)(call->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1115 WLog_Print(log, g_LogLevel,
"pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1116 call->pioRecvPci->dwProtocol, cbExtraBytes);
1120 smartcard_dump_array(log, g_LogLevel,
"pbExtraBytes: ",
"", pbExtraBytes, cbExtraBytes);
1125 WLog_Print(log, g_LogLevel,
"pioRecvPci: null");
1128 WLog_Print(log, g_LogLevel,
"fpbRecvBufferIsNULL: %" PRId32
" cbRecvLength: %" PRIu32
"",
1129 call->fpbRecvBufferIsNULL, call->cbRecvLength);
1130 WLog_Print(log, g_LogLevel,
"}");
1133static void smartcard_trace_locate_cards_by_atr_w_call(wLog* log,
1138 if (!WLog_IsLevelActive(log, g_LogLevel))
1141 WLog_Print(log, g_LogLevel,
"LocateCardsByATRW_Call {");
1142 smartcard_log_context(log, &call->handles.hContext);
1144 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
1146 WLog_Print(log, g_LogLevel,
"}");
1149static void smartcard_trace_transmit_return(wLog* log,
const Transmit_Return* ret)
1152 UINT32 cbExtraBytes = 0;
1153 BYTE* pbExtraBytes =
nullptr;
1155 if (!WLog_IsLevelActive(log, g_LogLevel))
1158 WLog_Print(log, g_LogLevel,
"Transmit_Return {");
1159 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1160 SCardGetErrorString(ret->ReturnCode),
1161 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1163 if (ret->pioRecvPci)
1165 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1167 WLog_Print(log, g_LogLevel,
1168 " pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1169 ret->pioRecvPci->dwProtocol, cbExtraBytes);
1173 smartcard_dump_array(log, g_LogLevel,
" pbExtraBytes: ",
"", pbExtraBytes,
1179 WLog_Print(log, g_LogLevel,
" pioRecvPci: null");
1182 WLog_Print(log, g_LogLevel,
" cbRecvLength: %" PRIu32
"", ret->cbRecvLength);
1184 if (ret->pbRecvBuffer)
1186 smartcard_dump_array(log, g_LogLevel,
" pbRecvBuffer: ",
"", ret->pbRecvBuffer,
1191 WLog_Print(log, g_LogLevel,
" pbRecvBuffer: null");
1194 WLog_Print(log, g_LogLevel,
"}");
1197static void smartcard_trace_control_return(wLog* log,
const Control_Return* ret)
1201 if (!WLog_IsLevelActive(log, g_LogLevel))
1204 WLog_Print(log, g_LogLevel,
"Control_Return {");
1205 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1206 SCardGetErrorString(ret->ReturnCode),
1207 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1208 WLog_Print(log, g_LogLevel,
" cbOutBufferSize: %" PRIu32
"", ret->cbOutBufferSize);
1210 if (ret->pvOutBuffer)
1212 smartcard_dump_array(log, g_LogLevel,
"pvOutBuffer: ",
"", ret->pvOutBuffer,
1213 ret->cbOutBufferSize);
1217 WLog_Print(log, g_LogLevel,
"pvOutBuffer: null");
1220 WLog_Print(log, g_LogLevel,
"}");
1223static void smartcard_trace_control_call(wLog* log,
const Control_Call* call)
1227 if (!WLog_IsLevelActive(log, g_LogLevel))
1230 WLog_Print(log, g_LogLevel,
"Control_Call {");
1231 smartcard_log_context(log, &call->handles.hContext);
1232 smartcard_log_redir_handle(log, &call->handles.hCard);
1234 WLog_Print(log, g_LogLevel,
1235 "dwControlCode: 0x%08" PRIX32
" cbInBufferSize: %" PRIu32
1236 " fpvOutBufferIsNULL: %" PRId32
" cbOutBufferSize: %" PRIu32
"",
1237 call->dwControlCode, call->cbInBufferSize, call->fpvOutBufferIsNULL,
1238 call->cbOutBufferSize);
1240 if (call->pvInBuffer)
1242 smartcard_dump_array(log, WLOG_DEBUG,
"pbInBuffer: ",
"", call->pvInBuffer,
1243 call->cbInBufferSize);
1247 WLog_Print(log, g_LogLevel,
"pvInBuffer: null");
1250 WLog_Print(log, g_LogLevel,
"}");
1253static void smartcard_trace_set_attrib_call(wLog* log,
const SetAttrib_Call* call)
1257 if (!WLog_IsLevelActive(log, g_LogLevel))
1260 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1261 smartcard_log_context(log, &call->handles.hContext);
1262 smartcard_log_redir_handle(log, &call->handles.hCard);
1263 WLog_Print(log, g_LogLevel,
"dwAttrId: 0x%08" PRIX32, call->dwAttrId);
1264 WLog_Print(log, g_LogLevel,
"cbAttrLen: 0x%08" PRIx32, call->cbAttrLen);
1265 smartcard_dump_array(log, g_LogLevel,
"pbAttr: ",
"", call->pbAttr, call->cbAttrLen);
1266 WLog_Print(log, g_LogLevel,
"}");
1269static void smartcard_trace_get_attrib_return(wLog* log,
const GetAttrib_Return* ret,
1274 if (!WLog_IsLevelActive(log, g_LogLevel))
1277 WLog_Print(log, g_LogLevel,
"GetAttrib_Return {");
1278 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1279 SCardGetErrorString(ret->ReturnCode),
1280 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1281 WLog_Print(log, g_LogLevel,
" dwAttrId: %s (0x%08" PRIX32
") cbAttrLen: 0x%08" PRIX32
"",
1282 SCardGetAttributeString(dwAttrId), dwAttrId, ret->cbAttrLen);
1283 smartcard_dump_array(log, g_LogLevel,
" ",
"", ret->pbAttr, ret->cbAttrLen);
1285 WLog_Print(log, g_LogLevel,
"}");
1288static void smartcard_trace_get_attrib_call(wLog* log,
const GetAttrib_Call* call)
1292 if (!WLog_IsLevelActive(log, g_LogLevel))
1295 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1296 smartcard_log_context(log, &call->handles.hContext);
1297 smartcard_log_redir_handle(log, &call->handles.hCard);
1299 WLog_Print(log, g_LogLevel,
1300 "dwAttrId: %s (0x%08" PRIX32
") fpbAttrIsNULL: %" PRId32
" cbAttrLen: 0x%08" PRIX32
1302 SCardGetAttributeString(call->dwAttrId), call->dwAttrId, call->fpbAttrIsNULL,
1304 WLog_Print(log, g_LogLevel,
"}");
1307static void smartcard_trace_status_call(wLog* log,
const Status_Call* call, BOOL unicode)
1311 if (!WLog_IsLevelActive(log, g_LogLevel))
1314 WLog_Print(log, g_LogLevel,
"Status%s_Call {", unicode ?
"W" :
"A");
1315 smartcard_log_context(log, &call->handles.hContext);
1316 smartcard_log_redir_handle(log, &call->handles.hCard);
1318 WLog_Print(log, g_LogLevel,
1319 "fmszReaderNamesIsNULL: %" PRId32
" cchReaderLen: %" PRIu32
" cbAtrLen: %" PRIu32
"",
1320 call->fmszReaderNamesIsNULL, call->cchReaderLen, call->cbAtrLen);
1321 WLog_Print(log, g_LogLevel,
"}");
1324static void smartcard_trace_status_return(wLog* log,
const Status_Return* ret, BOOL unicode)
1327 char* mszReaderNamesA =
nullptr;
1330 if (!WLog_IsLevelActive(log, g_LogLevel))
1332 cBytes = ret->cBytes;
1333 if (ret->ReturnCode != SCARD_S_SUCCESS)
1335 if (cBytes == SCARD_AUTOALLOCATE)
1337 mszReaderNamesA = smartcard_convert_string_list(ret->mszReaderNames, cBytes, unicode);
1339 WLog_Print(log, g_LogLevel,
"Status%s_Return {", unicode ?
"W" :
"A");
1340 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1341 SCardGetErrorString(ret->ReturnCode),
1342 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1343 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
") dwProtocol: %s (0x%08" PRIX32
")",
1344 SCardGetCardStateString(ret->dwState), ret->dwState,
1345 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1347 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" mszReaderNames: %s", ret->cBytes,
1350 smartcard_dump_array(log, g_LogLevel,
" cbAtrLen: %" PRIu32
" pbAtr: ",
"", ret->pbAtr,
1351 ret->cbAtrLen, ret->cbAtrLen);
1352 WLog_Print(log, g_LogLevel,
"}");
1353 free(mszReaderNamesA);
1356static void smartcard_trace_state_return(wLog* log,
const State_Return* ret)
1359 char* state =
nullptr;
1361 if (!WLog_IsLevelActive(log, g_LogLevel))
1364 state = SCardGetReaderStateString(ret->dwState);
1365 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1366 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1367 SCardGetErrorString(ret->ReturnCode),
1368 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1369 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
")", state, ret->dwState);
1370 WLog_Print(log, g_LogLevel,
" dwProtocol: %s (0x%08" PRIX32
")",
1371 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1372 WLog_Print(log, g_LogLevel,
" cbAtrLen: (0x%08" PRIX32
")", ret->cbAtrLen);
1373 smartcard_dump_array(log, g_LogLevel,
" rgAtr: ",
"", ret->rgAtr,
sizeof(ret->rgAtr));
1374 WLog_Print(log, g_LogLevel,
"}");
1378static void smartcard_trace_reconnect_return(wLog* log,
const Reconnect_Return* ret)
1382 if (!WLog_IsLevelActive(log, g_LogLevel))
1385 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1386 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1387 SCardGetErrorString(ret->ReturnCode),
1388 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1389 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1390 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1391 WLog_Print(log, g_LogLevel,
"}");
1394static void smartcard_trace_connect_a_call(wLog* log,
const ConnectA_Call* call)
1398 if (!WLog_IsLevelActive(log, g_LogLevel))
1401 WLog_Print(log, g_LogLevel,
"ConnectA_Call {");
1402 smartcard_log_context(log, &call->Common.handles.hContext);
1404 WLog_Print(log, g_LogLevel,
1405 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1406 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1407 call->szReader, SCardGetShareModeString(call->Common.dwShareMode),
1408 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1409 call->Common.dwPreferredProtocols);
1410 WLog_Print(log, g_LogLevel,
"}");
1413static void smartcard_trace_connect_w_call(wLog* log,
const ConnectW_Call* call)
1416 char szReaderA[1024] = WINPR_C_ARRAY_INIT;
1418 if (!WLog_IsLevelActive(log, g_LogLevel))
1422 (void)ConvertWCharToUtf8(call->szReader, szReaderA, ARRAYSIZE(szReaderA));
1423 WLog_Print(log, g_LogLevel,
"ConnectW_Call {");
1424 smartcard_log_context(log, &call->Common.handles.hContext);
1426 WLog_Print(log, g_LogLevel,
1427 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1428 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1429 szReaderA, SCardGetShareModeString(call->Common.dwShareMode),
1430 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1431 call->Common.dwPreferredProtocols);
1432 WLog_Print(log, g_LogLevel,
"}");
1435static void smartcard_trace_hcard_and_disposition_call(wLog* log,
1441 if (!WLog_IsLevelActive(log, g_LogLevel))
1444 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
1445 smartcard_log_context(log, &call->handles.hContext);
1446 smartcard_log_redir_handle(log, &call->handles.hCard);
1448 WLog_Print(log, g_LogLevel,
"dwDisposition: %s (0x%08" PRIX32
")",
1449 SCardGetDispositionString(call->dwDisposition), call->dwDisposition);
1450 WLog_Print(log, g_LogLevel,
"}");
1457 if (!WLog_IsLevelActive(log, g_LogLevel))
1460 WLog_Print(log, g_LogLevel,
"EstablishContext_Call {");
1461 WLog_Print(log, g_LogLevel,
"dwScope: %s (0x%08" PRIX32
")", SCardGetScopeString(call->dwScope),
1463 WLog_Print(log, g_LogLevel,
"}");
1470 if (!WLog_IsLevelActive(log, g_LogLevel))
1473 WLog_Print(log, g_LogLevel,
"EstablishContext_Return {");
1474 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1475 SCardGetErrorString(ret->ReturnCode),
1476 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1477 smartcard_log_context(log, &ret->hContext);
1479 WLog_Print(log, g_LogLevel,
"}");
1482void smartcard_trace_long_return(
const Long_Return* ret,
const char* name)
1484 wLog* log = scard_log();
1485 smartcard_trace_long_return_int(log, ret, name);
1488void smartcard_trace_long_return_int(wLog* log,
const Long_Return* ret,
const char* name)
1492 if (!WLog_IsLevelActive(log, g_LogLevel))
1495 WLog_Print(log, g_LogLevel,
"%s_Return {", name);
1496 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1497 SCardGetErrorString(ret->ReturnCode),
1498 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1499 WLog_Print(log, g_LogLevel,
"}");
1502static void smartcard_trace_connect_return(wLog* log,
const Connect_Return* ret)
1506 if (!WLog_IsLevelActive(log, g_LogLevel))
1509 WLog_Print(log, g_LogLevel,
"Connect_Return {");
1510 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1511 SCardGetErrorString(ret->ReturnCode),
1512 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1513 smartcard_log_context(log, &ret->hContext);
1514 smartcard_log_redir_handle(log, &ret->hCard);
1516 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1517 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1518 WLog_Print(log, g_LogLevel,
"}");
1521static void smartcard_trace_reconnect_call(wLog* log,
const Reconnect_Call* call)
1525 if (!WLog_IsLevelActive(log, g_LogLevel))
1528 WLog_Print(log, g_LogLevel,
"Reconnect_Call {");
1529 smartcard_log_context(log, &call->handles.hContext);
1530 smartcard_log_redir_handle(log, &call->handles.hCard);
1532 WLog_Print(log, g_LogLevel,
1533 "dwShareMode: %s (0x%08" PRIX32
") dwPreferredProtocols: %s (0x%08" PRIX32
1534 ") dwInitialization: %s (0x%08" PRIX32
")",
1535 SCardGetShareModeString(call->dwShareMode), call->dwShareMode,
1536 SCardGetProtocolString(call->dwPreferredProtocols), call->dwPreferredProtocols,
1537 SCardGetDispositionString(call->dwInitialization), call->dwInitialization);
1538 WLog_Print(log, g_LogLevel,
"}");
1545 if (!WLog_IsLevelActive(log, g_LogLevel))
1548 WLog_Print(log, g_LogLevel,
"GetDeviceTypeId_Return {");
1549 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1550 SCardGetErrorString(ret->ReturnCode),
1551 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1552 WLog_Print(log, g_LogLevel,
" dwDeviceId=%08" PRIx32, ret->dwDeviceId);
1554 WLog_Print(log, g_LogLevel,
"}");
1557static LONG smartcard_unpack_common_context_and_string_a(wLog* log,
wStream* s,
1559 CHAR** pszReaderName)
1562 UINT32 pbContextNdrPtr = 0;
1563 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1564 if (status != SCARD_S_SUCCESS)
1567 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
1568 return ERROR_INVALID_DATA;
1570 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1571 if (status != SCARD_S_SUCCESS)
1574 status = smartcard_ndr_read_a(log, s, pszReaderName, NDR_PTR_FULL);
1575 if (status != SCARD_S_SUCCESS)
1578 smartcard_trace_context_and_string_call_a(log, __func__, phContext, *pszReaderName);
1579 return SCARD_S_SUCCESS;
1582static LONG smartcard_unpack_common_context_and_string_w(wLog* log,
wStream* s,
1584 WCHAR** pszReaderName)
1587 UINT32 pbContextNdrPtr = 0;
1589 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1590 if (status != SCARD_S_SUCCESS)
1593 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
1594 return ERROR_INVALID_DATA;
1596 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1597 if (status != SCARD_S_SUCCESS)
1600 status = smartcard_ndr_read_w(log, s, pszReaderName, NDR_PTR_FULL);
1601 if (status != SCARD_S_SUCCESS)
1604 smartcard_trace_context_and_string_call_w(log, __func__, phContext, *pszReaderName);
1605 return SCARD_S_SUCCESS;
1608LONG smartcard_unpack_common_type_header(
wStream* s)
1610 wLog* log = scard_log();
1613 UINT8 endianness = 0;
1614 UINT16 commonHeaderLength = 0;
1616 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1617 return STATUS_BUFFER_TOO_SMALL;
1620 Stream_Read_UINT8(s, version);
1621 Stream_Read_UINT8(s, endianness);
1622 Stream_Read_UINT16(s, commonHeaderLength);
1623 Stream_Read_UINT32(s, filler);
1627 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Version %" PRIu8
"", version);
1628 return STATUS_INVALID_PARAMETER;
1631 if (endianness != 0x10)
1633 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Endianness %" PRIu8
"",
1635 return STATUS_INVALID_PARAMETER;
1638 if (commonHeaderLength != 8)
1640 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader CommonHeaderLength %" PRIu16
"",
1641 commonHeaderLength);
1642 return STATUS_INVALID_PARAMETER;
1645 if (filler != 0xCCCCCCCC)
1647 WLog_Print(log, WLOG_WARN,
"Unexpected CommonTypeHeader Filler 0x%08" PRIX32
"", filler);
1648 return STATUS_INVALID_PARAMETER;
1651 return SCARD_S_SUCCESS;
1654void smartcard_pack_common_type_header(
wStream* s)
1656 Stream_Write_UINT8(s, 1);
1657 Stream_Write_UINT8(s, 0x10);
1658 Stream_Write_UINT16(s, 8);
1659 Stream_Write_UINT32(s, 0xCCCCCCCC);
1662LONG smartcard_unpack_private_type_header(
wStream* s)
1664 wLog* log = scard_log();
1666 UINT32 objectBufferLength = 0;
1668 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1669 return STATUS_BUFFER_TOO_SMALL;
1671 Stream_Read_UINT32(s, objectBufferLength);
1672 Stream_Read_UINT32(s, filler);
1674 if (filler != 0x00000000)
1676 WLog_Print(log, WLOG_WARN,
"Unexpected PrivateTypeHeader Filler 0x%08" PRIX32
"", filler);
1677 return STATUS_INVALID_PARAMETER;
1680 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, objectBufferLength))
1681 return STATUS_INVALID_PARAMETER;
1683 return SCARD_S_SUCCESS;
1686void smartcard_pack_private_type_header(
wStream* s, UINT32 objectBufferLength)
1688 Stream_Write_UINT32(s, objectBufferLength);
1689 Stream_Write_UINT32(s, 0x00000000);
1692LONG smartcard_unpack_read_size_align(
wStream* s,
size_t size, UINT32 alignment)
1694 const size_t padsize = (size + alignment - 1) & ~(alignment - 1);
1695 const size_t pad = padsize - size;
1699 if (!Stream_SafeSeek(s, pad))
1706LONG smartcard_pack_write_size_align(
wStream* s,
size_t size, UINT32 alignment)
1708 const size_t padsize = (size + alignment - 1) & ~(alignment - 1);
1709 const size_t pad = padsize - size;
1713 if (!Stream_EnsureRemainingCapacity(s, pad))
1715 wLog* log = scard_log();
1716 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
1717 return SCARD_F_INTERNAL_ERROR;
1720 Stream_Zero(s, pad);
1723 return SCARD_S_SUCCESS;
1728 SCARDCONTEXT hContext = WINPR_C_ARRAY_INIT;
1730 WINPR_ASSERT(context);
1731 if ((context->cbContext !=
sizeof(ULONG_PTR)) && (context->cbContext != 0))
1733 wLog* log = scard_log();
1734 WLog_Print(log, WLOG_WARN,
1735 "REDIR_SCARDCONTEXT does not match native size: Actual: %" PRIu32
1736 ", Expected: %" PRIuz
"",
1737 context->cbContext,
sizeof(ULONG_PTR));
1741 if (context->cbContext)
1742 CopyMemory(&hContext, &(context->pbContext), context->cbContext);
1747void smartcard_scard_context_native_to_redir(
REDIR_SCARDCONTEXT* context, SCARDCONTEXT hContext)
1749 WINPR_ASSERT(context);
1751 context->cbContext =
sizeof(ULONG_PTR);
1752 CopyMemory(&(context->pbContext), &hContext, context->cbContext);
1757 SCARDHANDLE hCard = 0;
1759 WINPR_ASSERT(handle);
1760 if (handle->cbHandle == 0)
1763 if (handle->cbHandle !=
sizeof(ULONG_PTR))
1765 wLog* log = scard_log();
1766 WLog_Print(log, WLOG_WARN,
1767 "REDIR_SCARDHANDLE does not match native size: Actual: %" PRIu32
1768 ", Expected: %" PRIuz
"",
1769 handle->cbHandle,
sizeof(ULONG_PTR));
1773 if (handle->cbHandle)
1774 CopyMemory(&hCard, &(handle->pbHandle), handle->cbHandle);
1779void smartcard_scard_handle_native_to_redir(
REDIR_SCARDHANDLE* handle, SCARDHANDLE hCard)
1781 WINPR_ASSERT(handle);
1783 handle->cbHandle =
sizeof(ULONG_PTR);
1784 CopyMemory(&(handle->pbHandle), &hCard, handle->cbHandle);
1787#define smartcard_context_supported(log, size) \
1788 smartcard_context_supported_((log), (size), __FILE__, __func__, __LINE__)
1789static LONG smartcard_context_supported_(wLog* log, uint32_t size,
const char* file,
1790 const char* fkt,
size_t line)
1797 return SCARD_S_SUCCESS;
1800 const uint32_t level = WLOG_WARN;
1801 if (WLog_IsLevelActive(log, level))
1803 WLog_PrintTextMessage(log, level, line, file, fkt,
1804 "REDIR_SCARDCONTEXT length is not 0, 4 or 8: %" PRIu32
"",
1807 return STATUS_INVALID_PARAMETER;
1813 UINT32* index, UINT32* ppbContextNdrPtr,
1814 const char* file,
const char* function,
size_t line)
1816 UINT32 pbContextNdrPtr = 0;
1819 WINPR_ASSERT(context);
1823 if (!Stream_CheckAndLogRequiredLengthWLogEx(log, WLOG_WARN, s, 4, 1,
"%s(%s:%" PRIuz
")", file,
1825 return STATUS_BUFFER_TOO_SMALL;
1827 const LONG status = smartcard_context_supported_(log, context->cbContext, file, function, line);
1828 if (status != SCARD_S_SUCCESS)
1831 Stream_Read_UINT32(s, context->cbContext);
1833 if (!smartcard_ndr_pointer_read_(log, s, index, &pbContextNdrPtr, file, function, line))
1834 return ERROR_INVALID_DATA;
1836 if (((context->cbContext == 0) && pbContextNdrPtr) ||
1837 ((context->cbContext != 0) && !pbContextNdrPtr))
1839 WLog_Print(log, WLOG_WARN,
1840 "REDIR_SCARDCONTEXT cbContext (%" PRIu32
") pbContextNdrPtr (%" PRIu32
1842 context->cbContext, pbContextNdrPtr);
1843 return STATUS_INVALID_PARAMETER;
1846 if (!Stream_CheckAndLogRequiredLengthWLogEx(log, WLOG_WARN, s, context->cbContext, 1,
1847 "%s(%s:%" PRIuz
")", file, function, line))
1848 return STATUS_INVALID_PARAMETER;
1850 *ppbContextNdrPtr = pbContextNdrPtr;
1851 return SCARD_S_SUCCESS;
1854LONG smartcard_pack_redir_scard_context(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1857 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
1859 WINPR_ASSERT(context);
1860 if (context->cbContext != 0)
1862 Stream_Write_UINT32(s, context->cbContext);
1863 Stream_Write_UINT32(s, pbContextNdrPtr);
1864 *index = *index + 1;
1869 return SCARD_S_SUCCESS;
1872LONG smartcard_unpack_redir_scard_context_ref(wLog* log,
wStream* s,
1873 WINPR_ATTR_UNUSED UINT32 pbContextNdrPtr,
1878 WINPR_ASSERT(context);
1879 if (context->cbContext == 0)
1880 return SCARD_S_SUCCESS;
1882 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1883 return STATUS_BUFFER_TOO_SMALL;
1885 Stream_Read_UINT32(s, length);
1887 if (length != context->cbContext)
1889 WLog_Print(log, WLOG_WARN,
1890 "REDIR_SCARDCONTEXT length (%" PRIu32
") cbContext (%" PRIu32
") mismatch",
1891 length, context->cbContext);
1892 return STATUS_INVALID_PARAMETER;
1895 const LONG status = smartcard_context_supported(log, context->cbContext);
1896 if (status != SCARD_S_SUCCESS)
1899 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, context->cbContext))
1900 return STATUS_BUFFER_TOO_SMALL;
1902 if (context->cbContext)
1903 Stream_Read(s, &(context->pbContext), context->cbContext);
1905 ZeroMemory(&(context->pbContext),
sizeof(context->pbContext));
1907 return SCARD_S_SUCCESS;
1910LONG smartcard_pack_redir_scard_context_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1913 WINPR_ASSERT(context);
1914 Stream_Write_UINT32(s, context->cbContext);
1916 if (context->cbContext)
1918 Stream_Write(s, &(context->pbContext), context->cbContext);
1921 return SCARD_S_SUCCESS;
1925 UINT32* index,
const char* file,
const char* function,
1928 WINPR_ASSERT(handle);
1931 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1932 return STATUS_BUFFER_TOO_SMALL;
1934 Stream_Read_UINT32(s, handle->cbHandle);
1936 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, handle->cbHandle))
1937 return STATUS_BUFFER_TOO_SMALL;
1939 if (!smartcard_ndr_pointer_read_(log, s, index,
nullptr, file, function, line))
1940 return ERROR_INVALID_DATA;
1942 return SCARD_S_SUCCESS;
1945LONG smartcard_pack_redir_scard_handle(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1948 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
1950 WINPR_ASSERT(handle);
1951 if (handle->cbHandle != 0)
1953 Stream_Write_UINT32(s, handle->cbHandle);
1954 Stream_Write_UINT32(s, pbContextNdrPtr);
1955 *index = *index + 1;
1959 return SCARD_S_SUCCESS;
1966 WINPR_ASSERT(handle);
1967 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1968 return STATUS_BUFFER_TOO_SMALL;
1970 Stream_Read_UINT32(s, length);
1972 if (length != handle->cbHandle)
1974 WLog_Print(log, WLOG_WARN,
1975 "REDIR_SCARDHANDLE length (%" PRIu32
") cbHandle (%" PRIu32
") mismatch", length,
1977 return STATUS_INVALID_PARAMETER;
1980 if ((handle->cbHandle != 4) && (handle->cbHandle != 8))
1982 WLog_Print(log, WLOG_WARN,
"REDIR_SCARDHANDLE length is not 4 or 8: %" PRIu32
"",
1984 return STATUS_INVALID_PARAMETER;
1987 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, handle->cbHandle))
1988 return STATUS_BUFFER_TOO_SMALL;
1990 if (handle->cbHandle)
1991 Stream_Read(s, &(handle->pbHandle), handle->cbHandle);
1993 return SCARD_S_SUCCESS;
1996LONG smartcard_pack_redir_scard_handle_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1999 WINPR_ASSERT(handle);
2000 Stream_Write_UINT32(s, handle->cbHandle);
2002 if (handle->cbHandle)
2003 Stream_Write(s, &(handle->pbHandle), handle->cbHandle);
2005 return SCARD_S_SUCCESS;
2011 wLog* log = scard_log();
2013 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2014 return STATUS_BUFFER_TOO_SMALL;
2016 Stream_Read_UINT32(s, call->dwScope);
2017 smartcard_trace_establish_context_call(log, call);
2018 return SCARD_S_SUCCESS;
2024 wLog* log = scard_log();
2028 smartcard_trace_establish_context_return(log, ret);
2029 if (ret->ReturnCode != SCARD_S_SUCCESS)
2030 return ret->ReturnCode;
2032 status = smartcard_pack_redir_scard_context(log, s, &(ret->hContext), &index);
2033 if (status != SCARD_S_SUCCESS)
2036 return smartcard_pack_redir_scard_context_ref(log, s, &(ret->hContext));
2042 UINT32 pbContextNdrPtr = 0;
2043 wLog* log = scard_log();
2046 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2048 if (status != SCARD_S_SUCCESS)
2051 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2052 &(call->handles.hContext));
2053 if (status != SCARD_S_SUCCESS)
2054 WLog_Print(log, WLOG_ERROR,
2055 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2058 smartcard_trace_context_call(log, call, name);
2065 UINT32 pbContextNdrPtr = 0;
2066 wLog* log = scard_log();
2069 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2072 if (status != SCARD_S_SUCCESS)
2075 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2076 return STATUS_BUFFER_TOO_SMALL;
2078 Stream_Read_INT32(s, call->fmszGroupsIsNULL);
2079 Stream_Read_UINT32(s, call->cchGroups);
2080 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2081 &(call->handles.hContext));
2083 if (status != SCARD_S_SUCCESS)
2086 smartcard_trace_list_reader_groups_call(log, call, unicode);
2087 return SCARD_S_SUCCESS;
2094 wLog* log = scard_log();
2096 DWORD cBytes = ret->cBytes;
2099 smartcard_trace_list_reader_groups_return(log, ret, unicode);
2100 if (ret->ReturnCode != SCARD_S_SUCCESS)
2102 if (cBytes == SCARD_AUTOALLOCATE)
2105 if (!Stream_EnsureRemainingCapacity(s, 4))
2106 return SCARD_E_NO_MEMORY;
2108 Stream_Write_UINT32(s, cBytes);
2109 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
2110 return SCARD_E_NO_MEMORY;
2112 status = smartcard_ndr_write(s, ret->msz, cBytes, 1, NDR_PTR_SIMPLE);
2113 if (status != SCARD_S_SUCCESS)
2115 return ret->ReturnCode;
2121 UINT32 mszGroupsNdrPtr = 0;
2122 UINT32 pbContextNdrPtr = 0;
2123 wLog* log = scard_log();
2126 call->mszGroups =
nullptr;
2128 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2130 if (status != SCARD_S_SUCCESS)
2133 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2134 return STATUS_BUFFER_TOO_SMALL;
2136 Stream_Read_UINT32(s, call->cBytes);
2137 if (!smartcard_ndr_pointer_read(log, s, &index, &mszGroupsNdrPtr))
2138 return ERROR_INVALID_DATA;
2140 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2141 return STATUS_BUFFER_TOO_SMALL;
2142 Stream_Read_INT32(s, call->fmszReadersIsNULL);
2143 Stream_Read_UINT32(s, call->cchReaders);
2145 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2146 &(call->handles.hContext));
2147 if (status != SCARD_S_SUCCESS)
2150 if (mszGroupsNdrPtr)
2152 status = smartcard_ndr_read(log, s, &call->mszGroups, call->cBytes, 1, NDR_PTR_SIMPLE);
2153 if (status != SCARD_S_SUCCESS)
2157 smartcard_trace_list_readers_call(log, call, unicode);
2158 return SCARD_S_SUCCESS;
2164 wLog* log = scard_log();
2167 UINT32 size = ret->cBytes;
2169 smartcard_trace_list_readers_return(log, ret, unicode);
2170 if (ret->ReturnCode != SCARD_S_SUCCESS)
2173 if (!Stream_EnsureRemainingCapacity(s, 4))
2175 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
2176 return SCARD_F_INTERNAL_ERROR;
2179 Stream_Write_UINT32(s, size);
2180 if (!smartcard_ndr_pointer_write(s, &index, size))
2181 return SCARD_E_NO_MEMORY;
2183 status = smartcard_ndr_write(s, ret->msz, size, 1, NDR_PTR_SIMPLE);
2184 if (status != SCARD_S_SUCCESS)
2186 return ret->ReturnCode;
2190 UINT32* index, UINT32* ppbContextNdrPtr)
2192 WINPR_ASSERT(common);
2193 LONG status = smartcard_unpack_redir_scard_context(log, s, &(common->handles.hContext), index,
2195 if (status != SCARD_S_SUCCESS)
2198 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2199 return STATUS_BUFFER_TOO_SMALL;
2201 Stream_Read_UINT32(s, common->dwShareMode);
2202 Stream_Read_UINT32(s, common->dwPreferredProtocols);
2203 return SCARD_S_SUCCESS;
2210 UINT32 pbContextNdrPtr = 0;
2213 wLog* log = scard_log();
2215 call->szReader =
nullptr;
2217 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
2218 return ERROR_INVALID_DATA;
2220 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2221 if (status != SCARD_S_SUCCESS)
2223 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2228 status = smartcard_ndr_read_a(log, s, &call->szReader, NDR_PTR_FULL);
2229 if (status != SCARD_S_SUCCESS)
2232 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2233 &(call->Common.handles.hContext));
2234 if (status != SCARD_S_SUCCESS)
2235 WLog_Print(log, WLOG_ERROR,
2236 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2239 smartcard_trace_connect_a_call(log, call);
2247 UINT32 pbContextNdrPtr = 0;
2250 wLog* log = scard_log();
2251 call->szReader =
nullptr;
2253 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
2254 return ERROR_INVALID_DATA;
2256 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2257 if (status != SCARD_S_SUCCESS)
2259 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2264 status = smartcard_ndr_read_w(log, s, &call->szReader, NDR_PTR_FULL);
2265 if (status != SCARD_S_SUCCESS)
2268 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2269 &(call->Common.handles.hContext));
2270 if (status != SCARD_S_SUCCESS)
2271 WLog_Print(log, WLOG_ERROR,
2272 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2275 smartcard_trace_connect_w_call(log, call);
2285 wLog* log = scard_log();
2286 smartcard_trace_connect_return(log, ret);
2288 status = smartcard_pack_redir_scard_context(log, s, &ret->hContext, &index);
2289 if (status != SCARD_S_SUCCESS)
2292 status = smartcard_pack_redir_scard_handle(log, s, &ret->hCard, &index);
2293 if (status != SCARD_S_SUCCESS)
2296 if (!Stream_EnsureRemainingCapacity(s, 4))
2297 return SCARD_E_NO_MEMORY;
2299 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2300 status = smartcard_pack_redir_scard_context_ref(log, s, &ret->hContext);
2301 if (status != SCARD_S_SUCCESS)
2303 return smartcard_pack_redir_scard_handle_ref(log, s, &(ret->hCard));
2309 UINT32 pbContextNdrPtr = 0;
2312 wLog* log = scard_log();
2313 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2315 if (status != SCARD_S_SUCCESS)
2318 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2319 if (status != SCARD_S_SUCCESS)
2322 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2323 return STATUS_BUFFER_TOO_SMALL;
2325 Stream_Read_UINT32(s, call->dwShareMode);
2326 Stream_Read_UINT32(s, call->dwPreferredProtocols);
2327 Stream_Read_UINT32(s, call->dwInitialization);
2329 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2330 &(call->handles.hContext));
2331 if (status != SCARD_S_SUCCESS)
2333 WLog_Print(log, WLOG_ERROR,
2334 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2339 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2340 if (status != SCARD_S_SUCCESS)
2341 WLog_Print(log, WLOG_ERROR,
2342 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
2344 smartcard_trace_reconnect_call(log, call);
2351 wLog* log = scard_log();
2352 smartcard_trace_reconnect_return(log, ret);
2354 if (!Stream_EnsureRemainingCapacity(s, 4))
2355 return SCARD_E_NO_MEMORY;
2356 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2357 return ret->ReturnCode;
2364 UINT32 pbContextNdrPtr = 0;
2367 wLog* log = scard_log();
2369 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2371 if (status != SCARD_S_SUCCESS)
2374 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2375 if (status != SCARD_S_SUCCESS)
2378 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2379 return STATUS_BUFFER_TOO_SMALL;
2381 Stream_Read_UINT32(s, call->dwDisposition);
2383 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2384 &(call->handles.hContext));
2385 if (status != SCARD_S_SUCCESS)
2388 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2389 if (status != SCARD_S_SUCCESS)
2392 smartcard_trace_hcard_and_disposition_call(log, call, name);
2400 if (!WLog_IsLevelActive(log, g_LogLevel))
2403 WLog_Print(log, g_LogLevel,
"GetStatusChangeA_Call {");
2404 smartcard_log_context(log, &call->handles.hContext);
2406 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
2409 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
2411 WLog_Print(log, g_LogLevel,
"}");
2415 UINT32 cReaders, UINT32* ptrIndex)
2417 LONG status = SCARD_E_NO_MEMORY;
2419 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2420 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2423 const UINT32 len = Stream_Get_UINT32(s);
2424 if (len != cReaders)
2426 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEA");
2432 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2433 if (!rgReaderStates || !states)
2435 status = ERROR_INVALID_DATA;
2437 for (UINT32 index = 0; index < cReaders; index++)
2439 UINT32 ptr = UINT32_MAX;
2442 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2445 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2451 states[index] = ptr != 0;
2452 Stream_Read_UINT32(s, readerState->dwCurrentState);
2453 Stream_Read_UINT32(s, readerState->dwEventState);
2454 Stream_Read_UINT32(s, readerState->cbAtr);
2455 Stream_Read(s, readerState->rgbAtr, 36);
2458 for (UINT32 index = 0; index < cReaders; index++)
2465 status = smartcard_ndr_read_a(log, s, &readerState->szReader, NDR_PTR_FULL);
2466 if (status != SCARD_S_SUCCESS)
2470 *ppcReaders = rgReaderStates;
2472 return SCARD_S_SUCCESS;
2476 for (UINT32 index = 0; index < cReaders; index++)
2479 free(readerState->szReader);
2482 free(rgReaderStates);
2488 UINT32 cReaders, UINT32* ptrIndex)
2490 LONG status = SCARD_E_NO_MEMORY;
2492 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2493 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2496 const UINT32 len = Stream_Get_UINT32(s);
2497 if (len != cReaders)
2499 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEW");
2505 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2507 if (!rgReaderStates || !states)
2510 status = ERROR_INVALID_DATA;
2511 for (UINT32 index = 0; index < cReaders; index++)
2513 UINT32 ptr = UINT32_MAX;
2516 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2519 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2525 states[index] = ptr != 0;
2526 Stream_Read_UINT32(s, readerState->dwCurrentState);
2527 Stream_Read_UINT32(s, readerState->dwEventState);
2528 Stream_Read_UINT32(s, readerState->cbAtr);
2529 Stream_Read(s, readerState->rgbAtr, 36);
2532 for (UINT32 index = 0; index < cReaders; index++)
2540 status = smartcard_ndr_read_w(log, s, &readerState->szReader, NDR_PTR_FULL);
2541 if (status != SCARD_S_SUCCESS)
2545 *ppcReaders = rgReaderStates;
2547 return SCARD_S_SUCCESS;
2551 for (UINT32 index = 0; index < cReaders; index++)
2554 free(readerState->szReader);
2557 free(rgReaderStates);
2570 UINT32 pbContextNdrPtr = 0;
2573 wLog* log = scard_log();
2575 call->rgReaderStates =
nullptr;
2577 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2579 if (status != SCARD_S_SUCCESS)
2582 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2583 return STATUS_BUFFER_TOO_SMALL;
2585 Stream_Read_UINT32(s, call->dwTimeOut);
2586 Stream_Read_UINT32(s, call->cReaders);
2587 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2588 return ERROR_INVALID_DATA;
2590 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2591 &(call->handles.hContext));
2592 if (status != SCARD_S_SUCCESS)
2598 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
2599 if (status != SCARD_S_SUCCESS)
2604 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2605 return SCARD_E_UNEXPECTED;
2608 smartcard_trace_get_status_change_a_call(log, call);
2609 return SCARD_S_SUCCESS;
2616 UINT32 pbContextNdrPtr = 0;
2619 wLog* log = scard_log();
2620 call->rgReaderStates =
nullptr;
2622 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2624 if (status != SCARD_S_SUCCESS)
2627 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2628 return STATUS_BUFFER_TOO_SMALL;
2630 Stream_Read_UINT32(s, call->dwTimeOut);
2631 Stream_Read_UINT32(s, call->cReaders);
2632 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2633 return ERROR_INVALID_DATA;
2635 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2636 &(call->handles.hContext));
2637 if (status != SCARD_S_SUCCESS)
2643 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
2644 if (status != SCARD_S_SUCCESS)
2649 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2650 return SCARD_E_UNEXPECTED;
2653 smartcard_trace_get_status_change_w_call(log, call);
2654 return SCARD_S_SUCCESS;
2661 wLog* log = scard_log();
2664 DWORD cReaders = ret->cReaders;
2667 smartcard_trace_get_status_change_return(log, ret, unicode);
2668 if (ret->ReturnCode != SCARD_S_SUCCESS)
2670 if (cReaders == SCARD_AUTOALLOCATE)
2673 if (!Stream_EnsureRemainingCapacity(s, 4))
2674 return SCARD_E_NO_MEMORY;
2676 Stream_Write_UINT32(s, cReaders);
2677 if (!smartcard_ndr_pointer_write(s, &index, cReaders))
2678 return SCARD_E_NO_MEMORY;
2679 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cReaders, NDR_PTR_SIMPLE);
2680 if (status != SCARD_S_SUCCESS)
2682 return ret->ReturnCode;
2688 UINT32 pbContextNdrPtr = 0;
2690 wLog* log = scard_log();
2693 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2695 if (status != SCARD_S_SUCCESS)
2698 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2699 if (status != SCARD_S_SUCCESS)
2702 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2703 return STATUS_BUFFER_TOO_SMALL;
2705 Stream_Read_INT32(s, call->fpbAtrIsNULL);
2706 Stream_Read_UINT32(s, call->cbAtrLen);
2708 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2709 &(call->handles.hContext));
2710 if (status != SCARD_S_SUCCESS)
2713 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2714 if (status != SCARD_S_SUCCESS)
2723 wLog* log = scard_log();
2725 DWORD cbAtrLen = ret->cbAtrLen;
2728 smartcard_trace_state_return(log, ret);
2729 if (ret->ReturnCode != SCARD_S_SUCCESS)
2731 if (cbAtrLen == SCARD_AUTOALLOCATE)
2734 Stream_Write_UINT32(s, ret->dwState);
2735 Stream_Write_UINT32(s, ret->dwProtocol);
2736 Stream_Write_UINT32(s, cbAtrLen);
2737 if (!smartcard_ndr_pointer_write(s, &index, cbAtrLen))
2738 return SCARD_E_NO_MEMORY;
2739 status = smartcard_ndr_write(s, ret->rgAtr, cbAtrLen, 1, NDR_PTR_SIMPLE);
2740 if (status != SCARD_S_SUCCESS)
2742 return ret->ReturnCode;
2748 UINT32 pbContextNdrPtr = 0;
2751 wLog* log = scard_log();
2753 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2755 if (status != SCARD_S_SUCCESS)
2758 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2759 if (status != SCARD_S_SUCCESS)
2762 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2763 return STATUS_BUFFER_TOO_SMALL;
2765 Stream_Read_INT32(s, call->fmszReaderNamesIsNULL);
2766 Stream_Read_UINT32(s, call->cchReaderLen);
2767 Stream_Read_UINT32(s, call->cbAtrLen);
2769 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2770 &(call->handles.hContext));
2771 if (status != SCARD_S_SUCCESS)
2774 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2775 if (status != SCARD_S_SUCCESS)
2778 smartcard_trace_status_call(log, call, unicode);
2785 wLog* log = scard_log();
2789 DWORD cBytes = ret->cBytes;
2791 smartcard_trace_status_return(log, ret, unicode);
2792 if (ret->ReturnCode != SCARD_S_SUCCESS)
2794 if (cBytes == SCARD_AUTOALLOCATE)
2797 if (!Stream_EnsureRemainingCapacity(s, 4))
2798 return SCARD_F_INTERNAL_ERROR;
2800 Stream_Write_UINT32(s, cBytes);
2801 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
2802 return SCARD_E_NO_MEMORY;
2804 if (!Stream_EnsureRemainingCapacity(s, 44))
2805 return SCARD_F_INTERNAL_ERROR;
2807 Stream_Write_UINT32(s, ret->dwState);
2808 Stream_Write_UINT32(s, ret->dwProtocol);
2809 Stream_Write(s, ret->pbAtr,
sizeof(ret->pbAtr));
2810 Stream_Write_UINT32(s, ret->cbAtrLen);
2811 status = smartcard_ndr_write(s, ret->mszReaderNames, cBytes, 1, NDR_PTR_SIMPLE);
2812 if (status != SCARD_S_SUCCESS)
2814 return ret->ReturnCode;
2820 wLog* log = scard_log();
2822 UINT32 pbContextNdrPtr = 0;
2824 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2826 if (status != SCARD_S_SUCCESS)
2829 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2830 if (status != SCARD_S_SUCCESS)
2833 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2834 return STATUS_BUFFER_TOO_SMALL;
2836 Stream_Read_UINT32(s, call->dwAttrId);
2837 Stream_Read_INT32(s, call->fpbAttrIsNULL);
2838 Stream_Read_UINT32(s, call->cbAttrLen);
2840 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2841 &(call->handles.hContext));
2842 if (status != SCARD_S_SUCCESS)
2845 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2846 if (status != SCARD_S_SUCCESS)
2849 smartcard_trace_get_attrib_call(log, call);
2854 DWORD cbAttrCallLen)
2857 wLog* log = scard_log();
2859 DWORD cbAttrLen = 0;
2861 smartcard_trace_get_attrib_return(log, ret, dwAttrId);
2863 if (!Stream_EnsureRemainingCapacity(s, 4))
2864 return SCARD_F_INTERNAL_ERROR;
2866 cbAttrLen = ret->cbAttrLen;
2867 if (ret->ReturnCode != SCARD_S_SUCCESS)
2869 if (cbAttrLen == SCARD_AUTOALLOCATE)
2874 if (cbAttrCallLen < cbAttrLen)
2875 cbAttrLen = cbAttrCallLen;
2877 Stream_Write_UINT32(s, cbAttrLen);
2878 if (!smartcard_ndr_pointer_write(s, &index, cbAttrLen))
2879 return SCARD_E_NO_MEMORY;
2881 status = smartcard_ndr_write(s, ret->pbAttr, cbAttrLen, 1, NDR_PTR_SIMPLE);
2882 if (status != SCARD_S_SUCCESS)
2884 return ret->ReturnCode;
2890 wLog* log = scard_log();
2893 UINT32 pvInBufferNdrPtr = 0;
2894 UINT32 pbContextNdrPtr = 0;
2896 call->pvInBuffer =
nullptr;
2898 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2900 if (status != SCARD_S_SUCCESS)
2903 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2904 if (status != SCARD_S_SUCCESS)
2907 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 20))
2908 return STATUS_BUFFER_TOO_SMALL;
2910 Stream_Read_UINT32(s, call->dwControlCode);
2911 Stream_Read_UINT32(s, call->cbInBufferSize);
2912 if (!smartcard_ndr_pointer_read(log, s, &index,
2914 return ERROR_INVALID_DATA;
2915 Stream_Read_INT32(s, call->fpvOutBufferIsNULL);
2916 Stream_Read_UINT32(s, call->cbOutBufferSize);
2918 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2919 &(call->handles.hContext));
2920 if (status != SCARD_S_SUCCESS)
2923 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2924 if (status != SCARD_S_SUCCESS)
2927 if (pvInBufferNdrPtr)
2930 smartcard_ndr_read(log, s, &call->pvInBuffer, call->cbInBufferSize, 1, NDR_PTR_SIMPLE);
2931 if (status != SCARD_S_SUCCESS)
2935 smartcard_trace_control_call(log, call);
2936 return SCARD_S_SUCCESS;
2942 wLog* log = scard_log();
2945 DWORD cbDataLen = ret->cbOutBufferSize;
2948 smartcard_trace_control_return(log, ret);
2949 if (ret->ReturnCode != SCARD_S_SUCCESS)
2951 if (cbDataLen == SCARD_AUTOALLOCATE)
2954 if (!Stream_EnsureRemainingCapacity(s, 4))
2955 return SCARD_F_INTERNAL_ERROR;
2957 Stream_Write_UINT32(s, cbDataLen);
2958 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
2959 return SCARD_E_NO_MEMORY;
2961 status = smartcard_ndr_write(s, ret->pvOutBuffer, cbDataLen, 1, NDR_PTR_SIMPLE);
2962 if (status != SCARD_S_SUCCESS)
2964 return ret->ReturnCode;
2970 BYTE* pbExtraBytes =
nullptr;
2971 UINT32 pbExtraBytesNdrPtr = 0;
2972 UINT32 pbSendBufferNdrPtr = 0;
2973 UINT32 pioRecvPciNdrPtr = 0;
2977 UINT32 pbContextNdrPtr = 0;
2980 wLog* log = scard_log();
2982 call->pioSendPci =
nullptr;
2983 call->pioRecvPci =
nullptr;
2984 call->pbSendBuffer =
nullptr;
2986 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2988 if (status != SCARD_S_SUCCESS)
2991 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2992 if (status != SCARD_S_SUCCESS)
2995 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 32))
2996 return STATUS_BUFFER_TOO_SMALL;
2998 Stream_Read_UINT32(s, ioSendPci.dwProtocol);
2999 Stream_Read_UINT32(s, ioSendPci.cbExtraBytes);
3000 if (!smartcard_ndr_pointer_read(log, s, &index,
3001 &pbExtraBytesNdrPtr))
3002 return ERROR_INVALID_DATA;
3004 Stream_Read_UINT32(s, call->cbSendLength);
3005 if (!smartcard_ndr_pointer_read(log, s, &index,
3006 &pbSendBufferNdrPtr))
3007 return ERROR_INVALID_DATA;
3009 if (!smartcard_ndr_pointer_read(log, s, &index,
3011 return ERROR_INVALID_DATA;
3013 Stream_Read_INT32(s, call->fpbRecvBufferIsNULL);
3014 Stream_Read_UINT32(s, call->cbRecvLength);
3016 if (ioSendPci.cbExtraBytes > 1024)
3018 WLog_Print(log, WLOG_WARN,
3019 "Transmit_Call ioSendPci.cbExtraBytes is out of bounds: %" PRIu32
" (max: 1024)",
3020 ioSendPci.cbExtraBytes);
3021 return STATUS_INVALID_PARAMETER;
3024 if (call->cbSendLength > 66560)
3026 WLog_Print(log, WLOG_WARN,
3027 "Transmit_Call cbSendLength is out of bounds: %" PRIu32
" (max: 66560)",
3028 ioSendPci.cbExtraBytes);
3029 return STATUS_INVALID_PARAMETER;
3032 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3033 &(call->handles.hContext));
3034 if (status != SCARD_S_SUCCESS)
3037 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3038 if (status != SCARD_S_SUCCESS)
3041 if (ioSendPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3045 "Transmit_Call ioSendPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3046 return STATUS_INVALID_PARAMETER;
3049 if (pbExtraBytesNdrPtr)
3052 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3053 return STATUS_BUFFER_TOO_SMALL;
3055 Stream_Read_UINT32(s, length);
3057 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioSendPci.cbExtraBytes))
3058 return STATUS_BUFFER_TOO_SMALL;
3060 ioSendPci.pbExtraBytes = Stream_Pointer(s);
3064 if (!call->pioSendPci)
3066 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3067 return STATUS_NO_MEMORY;
3070 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3071 call->pioSendPci->cbPciLength = (DWORD)(ioSendPci.cbExtraBytes +
sizeof(
SCARD_IO_REQUEST));
3073 Stream_Read(s, pbExtraBytes, ioSendPci.cbExtraBytes);
3074 if (smartcard_unpack_read_size_align(s, ioSendPci.cbExtraBytes, 4) < 0)
3075 return STATUS_INVALID_PARAMETER;
3081 if (!call->pioSendPci)
3083 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3084 return STATUS_NO_MEMORY;
3087 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3091 if (pbSendBufferNdrPtr)
3094 smartcard_ndr_read(log, s, &call->pbSendBuffer, call->cbSendLength, 1, NDR_PTR_SIMPLE);
3095 if (status != SCARD_S_SUCCESS)
3099 if (pioRecvPciNdrPtr)
3101 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3102 return STATUS_BUFFER_TOO_SMALL;
3104 Stream_Read_UINT32(s, ioRecvPci.dwProtocol);
3105 Stream_Read_UINT32(s, ioRecvPci.cbExtraBytes);
3106 if (!smartcard_ndr_pointer_read(log, s, &index,
3107 &pbExtraBytesNdrPtr))
3108 return ERROR_INVALID_DATA;
3110 if (ioRecvPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3114 "Transmit_Call ioRecvPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3115 return STATUS_INVALID_PARAMETER;
3118 if (pbExtraBytesNdrPtr)
3121 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3122 return STATUS_BUFFER_TOO_SMALL;
3124 Stream_Read_UINT32(s, length);
3126 if (ioRecvPci.cbExtraBytes > 1024)
3128 WLog_Print(log, WLOG_WARN,
3129 "Transmit_Call ioRecvPci.cbExtraBytes is out of bounds: %" PRIu32
3131 ioRecvPci.cbExtraBytes);
3132 return STATUS_INVALID_PARAMETER;
3135 if (length != ioRecvPci.cbExtraBytes)
3137 WLog_Print(log, WLOG_WARN,
3138 "Transmit_Call unexpected length: Actual: %" PRIu32
3139 ", Expected: %" PRIu32
" (ioRecvPci.cbExtraBytes)",
3140 length, ioRecvPci.cbExtraBytes);
3141 return STATUS_INVALID_PARAMETER;
3144 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioRecvPci.cbExtraBytes))
3145 return STATUS_BUFFER_TOO_SMALL;
3147 ioRecvPci.pbExtraBytes = Stream_Pointer(s);
3151 if (!call->pioRecvPci)
3153 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3154 return STATUS_NO_MEMORY;
3157 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3158 call->pioRecvPci->cbPciLength =
3161 Stream_Read(s, pbExtraBytes, ioRecvPci.cbExtraBytes);
3162 if (smartcard_unpack_read_size_align(s, ioRecvPci.cbExtraBytes, 4) < 0)
3163 return STATUS_INVALID_PARAMETER;
3169 if (!call->pioRecvPci)
3171 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3172 return STATUS_NO_MEMORY;
3175 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3180 smartcard_trace_transmit_call(log, call);
3181 return SCARD_S_SUCCESS;
3187 wLog* log = scard_log();
3192 UINT32 cbRecvLength = ret->cbRecvLength;
3193 UINT32 cbRecvPci = ret->pioRecvPci ? ret->pioRecvPci->cbPciLength : 0;
3195 smartcard_trace_transmit_return(log, ret);
3197 if (!ret->pbRecvBuffer)
3200 if (!smartcard_ndr_pointer_write(s, &index, cbRecvPci))
3201 return SCARD_E_NO_MEMORY;
3202 if (!Stream_EnsureRemainingCapacity(s, 4))
3203 return SCARD_E_NO_MEMORY;
3204 Stream_Write_UINT32(s, cbRecvLength);
3205 if (!smartcard_ndr_pointer_write(s, &index, cbRecvLength))
3206 return SCARD_E_NO_MEMORY;
3208 if (ret->pioRecvPci)
3210 UINT32 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
3213 if (!Stream_EnsureRemainingCapacity(s, cbExtraBytes + 16))
3215 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3216 return SCARD_F_INTERNAL_ERROR;
3219 Stream_Write_UINT32(s, ret->pioRecvPci->dwProtocol);
3220 Stream_Write_UINT32(s, cbExtraBytes);
3221 if (!smartcard_ndr_pointer_write(s, &index, cbExtraBytes))
3222 return SCARD_E_NO_MEMORY;
3223 error = smartcard_ndr_write(s, pbExtraBytes, cbExtraBytes, 1, NDR_PTR_SIMPLE);
3228 status = smartcard_ndr_write(s, ret->pbRecvBuffer, ret->cbRecvLength, 1, NDR_PTR_SIMPLE);
3229 if (status != SCARD_S_SUCCESS)
3231 return ret->ReturnCode;
3236 UINT32 rgReaderStatesNdrPtr = 0;
3237 UINT32 rgAtrMasksNdrPtr = 0;
3239 UINT32 pbContextNdrPtr = 0;
3242 wLog* log = scard_log();
3244 call->rgReaderStates =
nullptr;
3246 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3248 if (status != SCARD_S_SUCCESS)
3251 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3252 return STATUS_BUFFER_TOO_SMALL;
3254 Stream_Read_UINT32(s, call->cAtrs);
3255 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3256 return ERROR_INVALID_DATA;
3257 Stream_Read_UINT32(s, call->cReaders);
3258 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3259 return ERROR_INVALID_DATA;
3261 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3262 &(call->handles.hContext));
3263 if (status != SCARD_S_SUCCESS)
3266 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3268 WLog_Print(log, WLOG_WARN,
3269 "LocateCardsByATRA_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3270 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3271 rgAtrMasksNdrPtr, call->cAtrs);
3272 return STATUS_INVALID_PARAMETER;
3275 if (rgAtrMasksNdrPtr)
3277 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3278 if (status != SCARD_S_SUCCESS)
3282 if (rgReaderStatesNdrPtr)
3285 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
3286 if (status != SCARD_S_SUCCESS)
3290 smartcard_trace_locate_cards_by_atr_a_call(log, call);
3291 return SCARD_S_SUCCESS;
3296 UINT32 sz1NdrPtr = 0;
3297 UINT32 sz2NdrPtr = 0;
3299 UINT32 pbContextNdrPtr = 0;
3302 wLog* log = scard_log();
3304 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3306 if (status != SCARD_S_SUCCESS)
3309 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3310 return ERROR_INVALID_DATA;
3311 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3312 return ERROR_INVALID_DATA;
3315 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3316 if (status != SCARD_S_SUCCESS)
3321 status = smartcard_ndr_read_a(log, s, &call->sz1, NDR_PTR_FULL);
3322 if (status != SCARD_S_SUCCESS)
3327 status = smartcard_ndr_read_a(log, s, &call->sz2, NDR_PTR_FULL);
3328 if (status != SCARD_S_SUCCESS)
3331 smartcard_trace_context_and_two_strings_a_call(log, call);
3332 return SCARD_S_SUCCESS;
3337 UINT32 sz1NdrPtr = 0;
3338 UINT32 sz2NdrPtr = 0;
3340 UINT32 pbContextNdrPtr = 0;
3343 wLog* log = scard_log();
3345 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3347 if (status != SCARD_S_SUCCESS)
3350 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3351 return ERROR_INVALID_DATA;
3352 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3353 return ERROR_INVALID_DATA;
3356 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3357 if (status != SCARD_S_SUCCESS)
3362 status = smartcard_ndr_read_w(log, s, &call->sz1, NDR_PTR_FULL);
3363 if (status != SCARD_S_SUCCESS)
3368 status = smartcard_ndr_read_w(log, s, &call->sz2, NDR_PTR_FULL);
3369 if (status != SCARD_S_SUCCESS)
3372 smartcard_trace_context_and_two_strings_w_call(log, call);
3373 return SCARD_S_SUCCESS;
3378 UINT32 sz1NdrPtr = 0;
3379 UINT32 sz2NdrPtr = 0;
3381 UINT32 pbContextNdrPtr = 0;
3384 wLog* log = scard_log();
3386 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3388 if (status != SCARD_S_SUCCESS)
3391 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3392 return STATUS_BUFFER_TOO_SMALL;
3394 Stream_Read_UINT32(s, call->cBytes);
3395 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3396 return ERROR_INVALID_DATA;
3398 Stream_Read_UINT32(s, call->cReaders);
3399 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3400 return ERROR_INVALID_DATA;
3402 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3403 &(call->handles.hContext));
3404 if (status != SCARD_S_SUCCESS)
3409 status = smartcard_ndr_read_fixed_string_a(log, s, &call->mszCards, call->cBytes,
3411 if (status != SCARD_S_SUCCESS)
3417 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
3418 if (status != SCARD_S_SUCCESS)
3421 smartcard_trace_locate_cards_a_call(log, call);
3422 return SCARD_S_SUCCESS;
3427 UINT32 sz1NdrPtr = 0;
3428 UINT32 sz2NdrPtr = 0;
3430 UINT32 pbContextNdrPtr = 0;
3433 wLog* log = scard_log();
3435 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3437 if (status != SCARD_S_SUCCESS)
3440 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3441 return STATUS_BUFFER_TOO_SMALL;
3443 Stream_Read_UINT32(s, call->cBytes);
3444 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3445 return ERROR_INVALID_DATA;
3447 Stream_Read_UINT32(s, call->cReaders);
3448 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3449 return ERROR_INVALID_DATA;
3451 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3452 &(call->handles.hContext));
3453 if (status != SCARD_S_SUCCESS)
3458 status = smartcard_ndr_read_fixed_string_w(log, s, &call->mszCards, call->cBytes,
3460 if (status != SCARD_S_SUCCESS)
3466 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
3467 if (status != SCARD_S_SUCCESS)
3470 smartcard_trace_locate_cards_w_call(log, call);
3471 return SCARD_S_SUCCESS;
3478 UINT32 pbContextNdrPtr = 0;
3481 wLog* log = scard_log();
3483 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3485 if (status != SCARD_S_SUCCESS)
3487 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3488 if (status != SCARD_S_SUCCESS)
3491 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3492 return STATUS_BUFFER_TOO_SMALL;
3493 Stream_Read_UINT32(s, call->dwAttrId);
3494 Stream_Read_UINT32(s, call->cbAttrLen);
3496 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
3497 return ERROR_INVALID_DATA;
3499 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3500 &(call->handles.hContext));
3501 if (status != SCARD_S_SUCCESS)
3504 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3505 if (status != SCARD_S_SUCCESS)
3511 status = smartcard_ndr_read_ex(log, s, &call->pbAttr, 0, 1, NDR_PTR_SIMPLE, &len);
3512 if (status != SCARD_S_SUCCESS)
3514 if (call->cbAttrLen > len)
3515 call->cbAttrLen = WINPR_ASSERTING_INT_CAST(DWORD, len);
3518 call->cbAttrLen = 0;
3519 smartcard_trace_set_attrib_call(log, call);
3520 return SCARD_S_SUCCESS;
3525 UINT32 rgReaderStatesNdrPtr = 0;
3526 UINT32 rgAtrMasksNdrPtr = 0;
3528 UINT32 pbContextNdrPtr = 0;
3531 wLog* log = scard_log();
3533 call->rgReaderStates =
nullptr;
3535 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3537 if (status != SCARD_S_SUCCESS)
3540 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3541 return STATUS_BUFFER_TOO_SMALL;
3543 Stream_Read_UINT32(s, call->cAtrs);
3544 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3545 return ERROR_INVALID_DATA;
3547 Stream_Read_UINT32(s, call->cReaders);
3548 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3549 return ERROR_INVALID_DATA;
3551 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3552 &(call->handles.hContext));
3553 if (status != SCARD_S_SUCCESS)
3556 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3558 WLog_Print(log, WLOG_WARN,
3559 "LocateCardsByATRW_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3560 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3561 rgAtrMasksNdrPtr, call->cAtrs);
3562 return STATUS_INVALID_PARAMETER;
3565 if (rgAtrMasksNdrPtr)
3567 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3568 if (status != SCARD_S_SUCCESS)
3572 if (rgReaderStatesNdrPtr)
3575 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
3576 if (status != SCARD_S_SUCCESS)
3580 smartcard_trace_locate_cards_by_atr_w_call(log, call);
3581 return SCARD_S_SUCCESS;
3586 UINT32 mszNdrPtr = 0;
3587 UINT32 contextNdrPtr = 0;
3589 UINT32 pbContextNdrPtr = 0;
3592 wLog* log = scard_log();
3594 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3595 return ERROR_INVALID_DATA;
3597 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3598 &index, &pbContextNdrPtr);
3599 if (status != SCARD_S_SUCCESS)
3602 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3603 return ERROR_INVALID_DATA;
3605 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3606 return STATUS_BUFFER_TOO_SMALL;
3607 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3608 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
3609 Stream_Read_UINT32(s, call->Common.cbDataLen);
3611 call->szLookupName =
nullptr;
3614 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
3615 if (status != SCARD_S_SUCCESS)
3619 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3620 &call->Common.handles.hContext);
3621 if (status != SCARD_S_SUCCESS)
3626 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3627 if (status != SCARD_S_SUCCESS)
3630 smartcard_trace_read_cache_a_call(log, call);
3631 return SCARD_S_SUCCESS;
3636 UINT32 mszNdrPtr = 0;
3637 UINT32 contextNdrPtr = 0;
3639 UINT32 pbContextNdrPtr = 0;
3642 wLog* log = scard_log();
3644 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3645 return ERROR_INVALID_DATA;
3647 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3648 &index, &pbContextNdrPtr);
3649 if (status != SCARD_S_SUCCESS)
3652 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3653 return ERROR_INVALID_DATA;
3655 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3656 return STATUS_BUFFER_TOO_SMALL;
3657 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3658 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
3659 Stream_Read_UINT32(s, call->Common.cbDataLen);
3661 call->szLookupName =
nullptr;
3664 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
3665 if (status != SCARD_S_SUCCESS)
3669 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3670 &call->Common.handles.hContext);
3671 if (status != SCARD_S_SUCCESS)
3676 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3677 if (status != SCARD_S_SUCCESS)
3680 smartcard_trace_read_cache_w_call(log, call);
3681 return SCARD_S_SUCCESS;
3686 UINT32 mszNdrPtr = 0;
3687 UINT32 contextNdrPtr = 0;
3688 UINT32 pbDataNdrPtr = 0;
3690 UINT32 pbContextNdrPtr = 0;
3693 wLog* log = scard_log();
3695 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3696 return ERROR_INVALID_DATA;
3698 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3699 &index, &pbContextNdrPtr);
3700 if (status != SCARD_S_SUCCESS)
3703 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3704 return ERROR_INVALID_DATA;
3706 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
3707 return STATUS_BUFFER_TOO_SMALL;
3709 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3710 Stream_Read_UINT32(s, call->Common.cbDataLen);
3712 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
3713 return ERROR_INVALID_DATA;
3715 call->szLookupName =
nullptr;
3718 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
3719 if (status != SCARD_S_SUCCESS)
3723 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3724 &call->Common.handles.hContext);
3725 if (status != SCARD_S_SUCCESS)
3728 call->Common.CardIdentifier =
nullptr;
3731 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3732 if (status != SCARD_S_SUCCESS)
3736 call->Common.pbData =
nullptr;
3739 status = smartcard_ndr_read(log, s, &call->Common.pbData, call->Common.cbDataLen, 1,
3741 if (status != SCARD_S_SUCCESS)
3744 smartcard_trace_write_cache_a_call(log, call);
3745 return SCARD_S_SUCCESS;
3750 UINT32 mszNdrPtr = 0;
3751 UINT32 contextNdrPtr = 0;
3752 UINT32 pbDataNdrPtr = 0;
3754 UINT32 pbContextNdrPtr = 0;
3757 wLog* log = scard_log();
3759 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3760 return ERROR_INVALID_DATA;
3762 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3763 &index, &pbContextNdrPtr);
3764 if (status != SCARD_S_SUCCESS)
3767 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3768 return ERROR_INVALID_DATA;
3770 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
3771 return STATUS_BUFFER_TOO_SMALL;
3772 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3773 Stream_Read_UINT32(s, call->Common.cbDataLen);
3775 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
3776 return ERROR_INVALID_DATA;
3778 call->szLookupName =
nullptr;
3781 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
3782 if (status != SCARD_S_SUCCESS)
3786 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3787 &call->Common.handles.hContext);
3788 if (status != SCARD_S_SUCCESS)
3791 call->Common.CardIdentifier =
nullptr;
3794 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3795 if (status != SCARD_S_SUCCESS)
3799 call->Common.pbData =
nullptr;
3802 status = smartcard_ndr_read(log, s, &call->Common.pbData, call->Common.cbDataLen, 1,
3804 if (status != SCARD_S_SUCCESS)
3807 smartcard_trace_write_cache_w_call(log, call);
3814 wLog* log = scard_log();
3817 UINT32 pbContextNdrPtr = 0;
3819 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3821 if (status != SCARD_S_SUCCESS)
3824 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3825 if (status != SCARD_S_SUCCESS)
3828 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3829 &(call->handles.hContext));
3830 if (status != SCARD_S_SUCCESS)
3832 WLog_Print(log, WLOG_ERROR,
3833 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
3838 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3839 if (status != SCARD_S_SUCCESS)
3840 WLog_Print(log, WLOG_ERROR,
3841 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
3843 smartcard_trace_get_transmit_count_call(log, call);
3850 wLog* log = scard_log();
3851 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
3852 &call->szReaderName);
3858 wLog* log = scard_log();
3859 return smartcard_unpack_common_context_and_string_a(log, s, &call->handles.hContext, &call->sz);
3865 wLog* log = scard_log();
3866 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext, &call->sz);
3872 wLog* log = scard_log();
3873 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
3874 &call->szReaderName);
3880 wLog* log = scard_log();
3881 smartcard_trace_device_type_id_return(log, ret);
3883 if (!Stream_EnsureRemainingCapacity(s, 4))
3885 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3886 return SCARD_F_INTERNAL_ERROR;
3889 Stream_Write_UINT32(s, ret->dwDeviceId);
3891 return ret->ReturnCode;
3897 wLog* log = scard_log();
3900 DWORD cbDataLen = ret->cReaders;
3903 smartcard_trace_locate_cards_return(log, ret);
3904 if (ret->ReturnCode != SCARD_S_SUCCESS)
3906 if (cbDataLen == SCARD_AUTOALLOCATE)
3909 if (!Stream_EnsureRemainingCapacity(s, 4))
3911 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3912 return SCARD_F_INTERNAL_ERROR;
3915 Stream_Write_UINT32(s, cbDataLen);
3916 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3917 return SCARD_E_NO_MEMORY;
3919 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cbDataLen, NDR_PTR_SIMPLE);
3920 if (status != SCARD_S_SUCCESS)
3922 return ret->ReturnCode;
3928 wLog* log = scard_log();
3932 DWORD cbDataLen = ret->cbDataLen;
3933 smartcard_trace_get_reader_icon_return(log, ret);
3934 if (ret->ReturnCode != SCARD_S_SUCCESS)
3936 if (cbDataLen == SCARD_AUTOALLOCATE)
3939 if (!Stream_EnsureRemainingCapacity(s, 4))
3941 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3942 return SCARD_F_INTERNAL_ERROR;
3945 Stream_Write_UINT32(s, cbDataLen);
3946 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3947 return SCARD_E_NO_MEMORY;
3949 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
3950 if (status != SCARD_S_SUCCESS)
3952 return ret->ReturnCode;
3958 wLog* log = scard_log();
3960 smartcard_trace_get_transmit_count_return(log, call);
3962 if (!Stream_EnsureRemainingCapacity(s, 4))
3964 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3965 return SCARD_F_INTERNAL_ERROR;
3968 Stream_Write_UINT32(s, call->cTransmitCount);
3970 return call->ReturnCode;
3976 wLog* log = scard_log();
3980 DWORD cbDataLen = ret->cbDataLen;
3981 smartcard_trace_read_cache_return(log, ret);
3982 if (ret->ReturnCode != SCARD_S_SUCCESS)
3985 if (cbDataLen == SCARD_AUTOALLOCATE)
3988 if (!Stream_EnsureRemainingCapacity(s, 4))
3990 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3991 return SCARD_F_INTERNAL_ERROR;
3994 Stream_Write_UINT32(s, cbDataLen);
3995 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3996 return SCARD_E_NO_MEMORY;
3998 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
3999 if (status != SCARD_S_SUCCESS)
4001 return ret->ReturnCode;