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))
453 char* msz = WINPR_CXX_COMPAT_CAST(
char*, data);
456 msz = ConvertMszWCharNToUtf8Alloc(data, len, &mszlen);
458 char* array = smartcard_create_msz_dump(msz, mszlen);
459 WLog_Print(log, level,
"%s%s", prefix, array);
465WINPR_ATTR_MALLOC(free, 1)
466static
char* smartcard_create_array_dump(const
void* pd,
size_t len)
468 const BYTE* data = pd;
471 size_t bufferLen = len * 4;
474 char* buffer = calloc(bufferLen + 1, 1);
477 char* start = buffer;
479 WINPR_ASSERT(buffer || (bufferLen == 0));
481 if (!data && (len > 0))
483 (void)_snprintf(buffer, bufferLen,
"{ nullptr [%" PRIuz
"] }", len);
487 rc = _snprintf(buffer, bufferLen,
"{ ");
488 if ((rc < 0) || ((
size_t)rc >= bufferLen))
491 bufferLen -= (size_t)rc;
493 for (
size_t x = 0; x < len; x++)
495 rc = _snprintf(buffer, bufferLen,
"%02X", data[x]);
496 if ((rc < 0) || ((
size_t)rc >= bufferLen))
499 bufferLen -= (size_t)rc;
502 rc = _snprintf(buffer, bufferLen,
" }");
503 if ((rc < 0) || ((
size_t)rc >= bufferLen))
510static void smartcard_dump_array(wLog* log, DWORD level,
const char* prefix,
const char* postfix,
511 const void* data,
size_t len, ...)
513 if (!WLog_IsLevelActive(log, level))
516 char* buffer = smartcard_create_array_dump(data, len);
518 char* fprefix =
nullptr;
520 va_list ap = WINPR_C_ARRAY_INIT;
522 winpr_vasprintf(&fprefix, &flen, prefix, ap);
524 WLog_Print(log, level,
"%s%s%s", prefix, buffer, postfix);
529static void smartcard_log_redir_handle(wLog* log,
const REDIR_SCARDHANDLE* pHandle)
531 WINPR_ASSERT(pHandle);
532 smartcard_dump_array(log, g_LogLevel,
" hContext: ",
"", pHandle->pbHandle, pHandle->cbHandle);
537 WINPR_ASSERT(phContext);
538 smartcard_dump_array(log, g_LogLevel,
"hContext: %s",
"", phContext->pbContext,
539 phContext->cbContext);
542static void smartcard_trace_context_and_string_call_a(wLog* log,
const char* name,
546 if (!WLog_IsLevelActive(log, g_LogLevel))
549 WLog_Print(log, g_LogLevel,
"%s {", name);
550 smartcard_log_context(log, phContext);
551 WLog_Print(log, g_LogLevel,
" sz=%s", sz);
553 WLog_Print(log, g_LogLevel,
"}");
556static void smartcard_trace_context_and_string_call_w(wLog* log,
const char* name,
560 char tmp[1024] = WINPR_C_ARRAY_INIT;
562 if (!WLog_IsLevelActive(log, g_LogLevel))
566 (void)ConvertWCharToUtf8(sz, tmp, ARRAYSIZE(tmp));
568 WLog_Print(log, g_LogLevel,
"%s {", name);
569 smartcard_log_context(log, phContext);
570 WLog_Print(log, g_LogLevel,
" sz=%s", tmp);
571 WLog_Print(log, g_LogLevel,
"}");
574static void smartcard_trace_context_call(wLog* log,
const Context_Call* call,
const char* name)
578 if (!WLog_IsLevelActive(log, g_LogLevel))
581 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
582 smartcard_log_context(log, &call->handles.hContext);
584 WLog_Print(log, g_LogLevel,
"}");
592 if (!WLog_IsLevelActive(log, g_LogLevel))
595 WLog_Print(log, g_LogLevel,
"ListReaderGroups%s_Call {", unicode ?
"W" :
"A");
596 smartcard_log_context(log, &call->handles.hContext);
598 WLog_Print(log, g_LogLevel,
"fmszGroupsIsNULL: %" PRId32
" cchGroups: 0x%08" PRIx32,
599 call->fmszGroupsIsNULL, call->cchGroups);
600 WLog_Print(log, g_LogLevel,
"}");
603static void dump_reader_states_return(wLog* log,
const ReaderState_Return* rgReaderStates,
606 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
607 for (UINT32 index = 0; index < cReaders; index++)
610 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
611 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
612 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
613 szCurrentState, readerState->dwCurrentState);
614 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
615 szEventState, readerState->dwEventState);
616 free(szCurrentState);
619 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
620 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
627 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
628 for (UINT32 index = 0; index < cReaders; index++)
632 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
633 readerState->szReader, readerState->cbAtr);
634 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
635 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
636 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
637 szCurrentState, readerState->dwCurrentState);
638 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
639 szEventState, readerState->dwEventState);
640 free(szCurrentState);
643 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
644 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
651 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
652 for (UINT32 index = 0; index < cReaders; index++)
655 char* buffer = ConvertWCharToUtf8Alloc(readerState->szReader,
nullptr);
656 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
657 buffer, readerState->cbAtr);
659 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
660 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
661 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
662 szCurrentState, readerState->dwCurrentState);
663 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
664 szEventState, readerState->dwEventState);
665 free(szCurrentState);
668 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
669 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
677 if (!WLog_IsLevelActive(log, g_LogLevel))
680 WLog_Print(log, g_LogLevel,
"GetStatusChangeW_Call {");
681 smartcard_log_context(log, &call->handles.hContext);
683 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
686 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
688 WLog_Print(log, g_LogLevel,
"}");
696 if (!WLog_IsLevelActive(log, g_LogLevel))
699 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
701 WLog_Print(log, g_LogLevel,
"ListReaderGroups%s_Return {", unicode ?
"W" :
"A");
702 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIx32
")",
703 SCardGetErrorString(ret->ReturnCode),
704 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
705 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
706 WLog_Print(log, g_LogLevel,
"}");
710static void smartcard_trace_list_readers_call(wLog* log,
const ListReaders_Call* call, BOOL unicode)
714 if (!WLog_IsLevelActive(log, g_LogLevel))
717 char* mszGroupsA = smartcard_convert_string_list(call->mszGroups, call->cBytes, unicode);
719 WLog_Print(log, g_LogLevel,
"ListReaders%s_Call {", unicode ?
"W" :
"A");
720 smartcard_log_context(log, &call->handles.hContext);
722 WLog_Print(log, g_LogLevel,
723 "cBytes: %" PRIu32
" mszGroups: %s fmszReadersIsNULL: %" PRId32
724 " cchReaders: 0x%08" PRIX32
"",
725 call->cBytes, mszGroupsA, call->fmszReadersIsNULL, call->cchReaders);
726 WLog_Print(log, g_LogLevel,
"}");
731static void smartcard_trace_locate_cards_by_atr_a_call(wLog* log,
736 if (!WLog_IsLevelActive(log, g_LogLevel))
739 WLog_Print(log, g_LogLevel,
"LocateCardsByATRA_Call {");
740 smartcard_log_context(log, &call->handles.hContext);
742 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
744 WLog_Print(log, g_LogLevel,
"}");
747static void smartcard_trace_locate_cards_a_call(wLog* log,
const LocateCardsA_Call* call)
751 if (!WLog_IsLevelActive(log, g_LogLevel))
754 WLog_Print(log, g_LogLevel,
"LocateCardsA_Call {");
755 smartcard_log_context(log, &call->handles.hContext);
756 WLog_Print(log, g_LogLevel,
" cBytes=%" PRIu32, call->cBytes);
757 smartcard_msz_dump(log, g_LogLevel,
" mszCards=", call->mszCards, call->cBytes, FALSE);
758 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, call->cReaders);
759 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
761 WLog_Print(log, g_LogLevel,
"}");
764static void smartcard_trace_locate_cards_return(wLog* log,
const LocateCards_Return* ret)
768 if (!WLog_IsLevelActive(log, g_LogLevel))
771 WLog_Print(log, g_LogLevel,
"LocateCards_Return {");
772 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
773 SCardGetErrorString(ret->ReturnCode),
774 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
776 if (ret->ReturnCode == SCARD_S_SUCCESS)
778 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, ret->cReaders);
780 WLog_Print(log, g_LogLevel,
"}");
787 if (!WLog_IsLevelActive(log, g_LogLevel))
790 WLog_Print(log, g_LogLevel,
"GetReaderIcon_Return {");
791 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
792 SCardGetErrorString(ret->ReturnCode),
793 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
795 if (ret->ReturnCode == SCARD_S_SUCCESS)
797 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, ret->cbDataLen);
799 WLog_Print(log, g_LogLevel,
"}");
806 if (!WLog_IsLevelActive(log, g_LogLevel))
809 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Return {");
810 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
811 SCardGetErrorString(ret->ReturnCode),
812 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
814 WLog_Print(log, g_LogLevel,
" cTransmitCount=%" PRIu32, ret->cTransmitCount);
815 WLog_Print(log, g_LogLevel,
"}");
818static void smartcard_trace_read_cache_return(wLog* log,
const ReadCache_Return* ret)
822 if (!WLog_IsLevelActive(log, g_LogLevel))
825 WLog_Print(log, g_LogLevel,
"ReadCache_Return {");
826 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
827 SCardGetErrorString(ret->ReturnCode),
828 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
830 if (ret->ReturnCode == SCARD_S_SUCCESS)
832 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, ret->cbDataLen);
833 smartcard_dump_array(log, g_LogLevel,
" cbData: ",
"", ret->pbData, ret->cbDataLen);
835 WLog_Print(log, g_LogLevel,
"}");
838static void smartcard_trace_locate_cards_w_call(wLog* log,
const LocateCardsW_Call* call)
842 if (!WLog_IsLevelActive(log, g_LogLevel))
845 WLog_Print(log, g_LogLevel,
"LocateCardsW_Call {");
846 smartcard_log_context(log, &call->handles.hContext);
847 WLog_Print(log, g_LogLevel,
" cBytes=%" PRIu32, call->cBytes);
848 smartcard_msz_dump(log, g_LogLevel,
" sz2=", call->mszCards, call->cBytes, TRUE);
849 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, call->cReaders);
850 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
851 WLog_Print(log, g_LogLevel,
"}");
854static void smartcard_trace_list_readers_return(wLog* log,
const ListReaders_Return* ret,
859 if (!WLog_IsLevelActive(log, g_LogLevel))
862 WLog_Print(log, g_LogLevel,
"ListReaders%s_Return {", unicode ?
"W" :
"A");
863 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
864 SCardGetErrorString(ret->ReturnCode),
865 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
867 if (ret->ReturnCode != SCARD_S_SUCCESS)
869 WLog_Print(log, g_LogLevel,
"}");
873 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
875 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
876 WLog_Print(log, g_LogLevel,
"}");
885 if (!WLog_IsLevelActive(log, g_LogLevel))
888 WLog_Print(log, g_LogLevel,
"GetStatusChange%s_Return {", unicode ?
"W" :
"A");
889 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
890 SCardGetErrorString(ret->ReturnCode),
891 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
892 WLog_Print(log, g_LogLevel,
" cReaders: %" PRIu32
"", ret->cReaders);
894 dump_reader_states_return(log, ret->rgReaderStates, ret->cReaders);
896 if (!ret->rgReaderStates && (ret->cReaders > 0))
898 WLog_Print(log, g_LogLevel,
" [INVALID STATE] rgReaderStates=nullptr, cReaders=%" PRIu32,
901 else if (ret->ReturnCode != SCARD_S_SUCCESS)
903 WLog_Print(log, g_LogLevel,
" [INVALID RETURN] rgReaderStates, cReaders=%" PRIu32,
908 for (UINT32 index = 0; index < ret->cReaders; index++)
911 char* szCurrentState = SCardGetReaderStateString(rgReaderState->dwCurrentState);
912 char* szEventState = SCardGetReaderStateString(rgReaderState->dwEventState);
913 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")",
914 index, szCurrentState, rgReaderState->dwCurrentState);
915 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")",
916 index, szEventState, rgReaderState->dwEventState);
917 smartcard_dump_array(
918 log, g_LogLevel,
" [%" PRIu32
"]: cbAtr: %" PRIu32
" rgbAtr: ",
"",
919 rgReaderState->rgbAtr, rgReaderState->cbAtr, index, rgReaderState->cbAtr);
920 free(szCurrentState);
925 WLog_Print(log, g_LogLevel,
"}");
928static void smartcard_trace_context_and_two_strings_a_call(wLog* log,
933 if (!WLog_IsLevelActive(log, g_LogLevel))
936 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
937 smartcard_log_context(log, &call->handles.hContext);
938 WLog_Print(log, g_LogLevel,
" sz1=%s", call->sz1);
939 WLog_Print(log, g_LogLevel,
" sz2=%s", call->sz2);
940 WLog_Print(log, g_LogLevel,
"}");
943static void smartcard_trace_context_and_two_strings_w_call(wLog* log,
947 char sz1[1024] = WINPR_C_ARRAY_INIT;
948 char sz2[1024] = WINPR_C_ARRAY_INIT;
950 if (!WLog_IsLevelActive(log, g_LogLevel))
953 (void)ConvertWCharToUtf8(call->sz1, sz1, ARRAYSIZE(sz1));
955 (void)ConvertWCharToUtf8(call->sz2, sz2, ARRAYSIZE(sz2));
957 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
958 smartcard_log_context(log, &call->handles.hContext);
959 WLog_Print(log, g_LogLevel,
" sz1=%s", sz1);
960 WLog_Print(log, g_LogLevel,
" sz2=%s", sz2);
961 WLog_Print(log, g_LogLevel,
"}");
968 if (!WLog_IsLevelActive(log, g_LogLevel))
971 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Call {");
972 smartcard_log_context(log, &call->handles.hContext);
973 smartcard_log_redir_handle(log, &call->handles.hCard);
975 WLog_Print(log, g_LogLevel,
"}");
978static void smartcard_trace_write_cache_a_call(wLog* log,
const WriteCacheA_Call* call)
982 if (!WLog_IsLevelActive(log, g_LogLevel))
985 WLog_Print(log, g_LogLevel,
"WriteCacheA_Call {");
987 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
989 smartcard_log_context(log, &call->Common.handles.hContext);
990 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
992 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
993 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
994 smartcard_dump_array(log, g_LogLevel,
" pbData=",
"", call->Common.pbData,
995 call->Common.cbDataLen);
996 WLog_Print(log, g_LogLevel,
"}");
999static void smartcard_trace_write_cache_w_call(wLog* log,
const WriteCacheW_Call* call)
1002 char tmp[1024] = WINPR_C_ARRAY_INIT;
1004 if (!WLog_IsLevelActive(log, g_LogLevel))
1007 WLog_Print(log, g_LogLevel,
"WriteCacheW_Call {");
1009 if (call->szLookupName)
1010 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
1011 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
1013 smartcard_log_context(log, &call->Common.handles.hContext);
1014 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1016 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1017 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1018 smartcard_dump_array(log, g_LogLevel,
" pbData=",
"", call->Common.pbData,
1019 call->Common.cbDataLen);
1020 WLog_Print(log, g_LogLevel,
"}");
1023static void smartcard_trace_read_cache_a_call(wLog* log,
const ReadCacheA_Call* call)
1027 if (!WLog_IsLevelActive(log, g_LogLevel))
1030 WLog_Print(log, g_LogLevel,
"ReadCacheA_Call {");
1032 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
1033 smartcard_log_context(log, &call->Common.handles.hContext);
1034 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1036 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1037 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1038 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1040 WLog_Print(log, g_LogLevel,
"}");
1043static void smartcard_trace_read_cache_w_call(wLog* log,
const ReadCacheW_Call* call)
1046 char tmp[1024] = WINPR_C_ARRAY_INIT;
1048 if (!WLog_IsLevelActive(log, g_LogLevel))
1051 WLog_Print(log, g_LogLevel,
"ReadCacheW_Call {");
1052 if (call->szLookupName)
1053 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
1054 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
1056 smartcard_log_context(log, &call->Common.handles.hContext);
1057 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1059 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1060 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1061 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1063 WLog_Print(log, g_LogLevel,
"}");
1066static void smartcard_trace_transmit_call(wLog* log,
const Transmit_Call* call)
1069 UINT32 cbExtraBytes = 0;
1070 BYTE* pbExtraBytes =
nullptr;
1072 if (!WLog_IsLevelActive(log, g_LogLevel))
1075 WLog_Print(log, g_LogLevel,
"Transmit_Call {");
1076 smartcard_log_context(log, &call->handles.hContext);
1077 smartcard_log_redir_handle(log, &call->handles.hCard);
1079 if (call->pioSendPci)
1081 cbExtraBytes = (UINT32)(call->pioSendPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1083 WLog_Print(log, g_LogLevel,
"pioSendPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1084 call->pioSendPci->dwProtocol, cbExtraBytes);
1088 smartcard_dump_array(log, g_LogLevel,
"pbExtraBytes: ",
"", pbExtraBytes, cbExtraBytes);
1093 WLog_Print(log, g_LogLevel,
"pioSendPci: null");
1096 WLog_Print(log, g_LogLevel,
"cbSendLength: %" PRIu32
"", call->cbSendLength);
1098 if (call->pbSendBuffer)
1100 smartcard_dump_array(log, g_LogLevel,
"pbSendBuffer: ",
"", call->pbSendBuffer,
1101 call->cbSendLength);
1105 WLog_Print(log, g_LogLevel,
"pbSendBuffer: null");
1108 if (call->pioRecvPci)
1110 cbExtraBytes = (UINT32)(call->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1112 WLog_Print(log, g_LogLevel,
"pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1113 call->pioRecvPci->dwProtocol, cbExtraBytes);
1117 smartcard_dump_array(log, g_LogLevel,
"pbExtraBytes: ",
"", pbExtraBytes, cbExtraBytes);
1122 WLog_Print(log, g_LogLevel,
"pioRecvPci: null");
1125 WLog_Print(log, g_LogLevel,
"fpbRecvBufferIsNULL: %" PRId32
" cbRecvLength: %" PRIu32
"",
1126 call->fpbRecvBufferIsNULL, call->cbRecvLength);
1127 WLog_Print(log, g_LogLevel,
"}");
1130static void smartcard_trace_locate_cards_by_atr_w_call(wLog* log,
1135 if (!WLog_IsLevelActive(log, g_LogLevel))
1138 WLog_Print(log, g_LogLevel,
"LocateCardsByATRW_Call {");
1139 smartcard_log_context(log, &call->handles.hContext);
1141 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
1143 WLog_Print(log, g_LogLevel,
"}");
1146static void smartcard_trace_transmit_return(wLog* log,
const Transmit_Return* ret)
1149 UINT32 cbExtraBytes = 0;
1150 BYTE* pbExtraBytes =
nullptr;
1152 if (!WLog_IsLevelActive(log, g_LogLevel))
1155 WLog_Print(log, g_LogLevel,
"Transmit_Return {");
1156 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1157 SCardGetErrorString(ret->ReturnCode),
1158 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1160 if (ret->pioRecvPci)
1162 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1164 WLog_Print(log, g_LogLevel,
1165 " pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1166 ret->pioRecvPci->dwProtocol, cbExtraBytes);
1170 smartcard_dump_array(log, g_LogLevel,
" pbExtraBytes: ",
"", pbExtraBytes,
1176 WLog_Print(log, g_LogLevel,
" pioRecvPci: null");
1179 WLog_Print(log, g_LogLevel,
" cbRecvLength: %" PRIu32
"", ret->cbRecvLength);
1181 if (ret->pbRecvBuffer)
1183 smartcard_dump_array(log, g_LogLevel,
" pbRecvBuffer: ",
"", ret->pbRecvBuffer,
1188 WLog_Print(log, g_LogLevel,
" pbRecvBuffer: null");
1191 WLog_Print(log, g_LogLevel,
"}");
1194static void smartcard_trace_control_return(wLog* log,
const Control_Return* ret)
1198 if (!WLog_IsLevelActive(log, g_LogLevel))
1201 WLog_Print(log, g_LogLevel,
"Control_Return {");
1202 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1203 SCardGetErrorString(ret->ReturnCode),
1204 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1205 WLog_Print(log, g_LogLevel,
" cbOutBufferSize: %" PRIu32
"", ret->cbOutBufferSize);
1207 if (ret->pvOutBuffer)
1209 smartcard_dump_array(log, g_LogLevel,
"pvOutBuffer: ",
"", ret->pvOutBuffer,
1210 ret->cbOutBufferSize);
1214 WLog_Print(log, g_LogLevel,
"pvOutBuffer: null");
1217 WLog_Print(log, g_LogLevel,
"}");
1220static void smartcard_trace_control_call(wLog* log,
const Control_Call* call)
1224 if (!WLog_IsLevelActive(log, g_LogLevel))
1227 WLog_Print(log, g_LogLevel,
"Control_Call {");
1228 smartcard_log_context(log, &call->handles.hContext);
1229 smartcard_log_redir_handle(log, &call->handles.hCard);
1231 WLog_Print(log, g_LogLevel,
1232 "dwControlCode: 0x%08" PRIX32
" cbInBufferSize: %" PRIu32
1233 " fpvOutBufferIsNULL: %" PRId32
" cbOutBufferSize: %" PRIu32
"",
1234 call->dwControlCode, call->cbInBufferSize, call->fpvOutBufferIsNULL,
1235 call->cbOutBufferSize);
1237 if (call->pvInBuffer)
1239 smartcard_dump_array(log, WLOG_DEBUG,
"pbInBuffer: ",
"", call->pvInBuffer,
1240 call->cbInBufferSize);
1244 WLog_Print(log, g_LogLevel,
"pvInBuffer: null");
1247 WLog_Print(log, g_LogLevel,
"}");
1250static void smartcard_trace_set_attrib_call(wLog* log,
const SetAttrib_Call* call)
1254 if (!WLog_IsLevelActive(log, g_LogLevel))
1257 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1258 smartcard_log_context(log, &call->handles.hContext);
1259 smartcard_log_redir_handle(log, &call->handles.hCard);
1260 WLog_Print(log, g_LogLevel,
"dwAttrId: 0x%08" PRIX32, call->dwAttrId);
1261 WLog_Print(log, g_LogLevel,
"cbAttrLen: 0x%08" PRIx32, call->cbAttrLen);
1262 smartcard_dump_array(log, g_LogLevel,
"pbAttr: ",
"", call->pbAttr, call->cbAttrLen);
1263 WLog_Print(log, g_LogLevel,
"}");
1266static void smartcard_trace_get_attrib_return(wLog* log,
const GetAttrib_Return* ret,
1271 if (!WLog_IsLevelActive(log, g_LogLevel))
1274 WLog_Print(log, g_LogLevel,
"GetAttrib_Return {");
1275 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1276 SCardGetErrorString(ret->ReturnCode),
1277 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1278 WLog_Print(log, g_LogLevel,
" dwAttrId: %s (0x%08" PRIX32
") cbAttrLen: 0x%08" PRIX32
"",
1279 SCardGetAttributeString(dwAttrId), dwAttrId, ret->cbAttrLen);
1280 smartcard_dump_array(log, g_LogLevel,
" ",
"", ret->pbAttr, ret->cbAttrLen);
1282 WLog_Print(log, g_LogLevel,
"}");
1285static void smartcard_trace_get_attrib_call(wLog* log,
const GetAttrib_Call* call)
1289 if (!WLog_IsLevelActive(log, g_LogLevel))
1292 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1293 smartcard_log_context(log, &call->handles.hContext);
1294 smartcard_log_redir_handle(log, &call->handles.hCard);
1296 WLog_Print(log, g_LogLevel,
1297 "dwAttrId: %s (0x%08" PRIX32
") fpbAttrIsNULL: %" PRId32
" cbAttrLen: 0x%08" PRIX32
1299 SCardGetAttributeString(call->dwAttrId), call->dwAttrId, call->fpbAttrIsNULL,
1301 WLog_Print(log, g_LogLevel,
"}");
1304static void smartcard_trace_status_call(wLog* log,
const Status_Call* call, BOOL unicode)
1308 if (!WLog_IsLevelActive(log, g_LogLevel))
1311 WLog_Print(log, g_LogLevel,
"Status%s_Call {", unicode ?
"W" :
"A");
1312 smartcard_log_context(log, &call->handles.hContext);
1313 smartcard_log_redir_handle(log, &call->handles.hCard);
1315 WLog_Print(log, g_LogLevel,
1316 "fmszReaderNamesIsNULL: %" PRId32
" cchReaderLen: %" PRIu32
" cbAtrLen: %" PRIu32
"",
1317 call->fmszReaderNamesIsNULL, call->cchReaderLen, call->cbAtrLen);
1318 WLog_Print(log, g_LogLevel,
"}");
1321static void smartcard_trace_status_return(wLog* log,
const Status_Return* ret, BOOL unicode)
1324 char* mszReaderNamesA =
nullptr;
1327 if (!WLog_IsLevelActive(log, g_LogLevel))
1329 cBytes = ret->cBytes;
1330 if (ret->ReturnCode != SCARD_S_SUCCESS)
1332 if (cBytes == SCARD_AUTOALLOCATE)
1334 mszReaderNamesA = smartcard_convert_string_list(ret->mszReaderNames, cBytes, unicode);
1336 WLog_Print(log, g_LogLevel,
"Status%s_Return {", unicode ?
"W" :
"A");
1337 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1338 SCardGetErrorString(ret->ReturnCode),
1339 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1340 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
") dwProtocol: %s (0x%08" PRIX32
")",
1341 SCardGetCardStateString(ret->dwState), ret->dwState,
1342 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1344 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" mszReaderNames: %s", ret->cBytes,
1347 smartcard_dump_array(log, g_LogLevel,
" cbAtrLen: %" PRIu32
" pbAtr: ",
"", ret->pbAtr,
1348 ret->cbAtrLen, ret->cbAtrLen);
1349 WLog_Print(log, g_LogLevel,
"}");
1350 free(mszReaderNamesA);
1353static void smartcard_trace_state_return(wLog* log,
const State_Return* ret)
1356 char* state =
nullptr;
1358 if (!WLog_IsLevelActive(log, g_LogLevel))
1361 state = SCardGetReaderStateString(ret->dwState);
1362 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1363 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1364 SCardGetErrorString(ret->ReturnCode),
1365 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1366 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
")", state, ret->dwState);
1367 WLog_Print(log, g_LogLevel,
" dwProtocol: %s (0x%08" PRIX32
")",
1368 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1369 WLog_Print(log, g_LogLevel,
" cbAtrLen: (0x%08" PRIX32
")", ret->cbAtrLen);
1370 smartcard_dump_array(log, g_LogLevel,
" rgAtr: ",
"", ret->rgAtr,
sizeof(ret->rgAtr));
1371 WLog_Print(log, g_LogLevel,
"}");
1375static void smartcard_trace_reconnect_return(wLog* log,
const Reconnect_Return* ret)
1379 if (!WLog_IsLevelActive(log, g_LogLevel))
1382 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1383 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1384 SCardGetErrorString(ret->ReturnCode),
1385 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1386 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1387 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1388 WLog_Print(log, g_LogLevel,
"}");
1391static void smartcard_trace_connect_a_call(wLog* log,
const ConnectA_Call* call)
1395 if (!WLog_IsLevelActive(log, g_LogLevel))
1398 WLog_Print(log, g_LogLevel,
"ConnectA_Call {");
1399 smartcard_log_context(log, &call->Common.handles.hContext);
1401 WLog_Print(log, g_LogLevel,
1402 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1403 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1404 call->szReader, SCardGetShareModeString(call->Common.dwShareMode),
1405 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1406 call->Common.dwPreferredProtocols);
1407 WLog_Print(log, g_LogLevel,
"}");
1410static void smartcard_trace_connect_w_call(wLog* log,
const ConnectW_Call* call)
1413 char szReaderA[1024] = WINPR_C_ARRAY_INIT;
1415 if (!WLog_IsLevelActive(log, g_LogLevel))
1419 (void)ConvertWCharToUtf8(call->szReader, szReaderA, ARRAYSIZE(szReaderA));
1420 WLog_Print(log, g_LogLevel,
"ConnectW_Call {");
1421 smartcard_log_context(log, &call->Common.handles.hContext);
1423 WLog_Print(log, g_LogLevel,
1424 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1425 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1426 szReaderA, SCardGetShareModeString(call->Common.dwShareMode),
1427 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1428 call->Common.dwPreferredProtocols);
1429 WLog_Print(log, g_LogLevel,
"}");
1432static void smartcard_trace_hcard_and_disposition_call(wLog* log,
1438 if (!WLog_IsLevelActive(log, g_LogLevel))
1441 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
1442 smartcard_log_context(log, &call->handles.hContext);
1443 smartcard_log_redir_handle(log, &call->handles.hCard);
1445 WLog_Print(log, g_LogLevel,
"dwDisposition: %s (0x%08" PRIX32
")",
1446 SCardGetDispositionString(call->dwDisposition), call->dwDisposition);
1447 WLog_Print(log, g_LogLevel,
"}");
1454 if (!WLog_IsLevelActive(log, g_LogLevel))
1457 WLog_Print(log, g_LogLevel,
"EstablishContext_Call {");
1458 WLog_Print(log, g_LogLevel,
"dwScope: %s (0x%08" PRIX32
")", SCardGetScopeString(call->dwScope),
1460 WLog_Print(log, g_LogLevel,
"}");
1467 if (!WLog_IsLevelActive(log, g_LogLevel))
1470 WLog_Print(log, g_LogLevel,
"EstablishContext_Return {");
1471 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1472 SCardGetErrorString(ret->ReturnCode),
1473 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1474 smartcard_log_context(log, &ret->hContext);
1476 WLog_Print(log, g_LogLevel,
"}");
1479void smartcard_trace_long_return(
const Long_Return* ret,
const char* name)
1481 wLog* log = scard_log();
1482 smartcard_trace_long_return_int(log, ret, name);
1485void smartcard_trace_long_return_int(wLog* log,
const Long_Return* ret,
const char* name)
1489 if (!WLog_IsLevelActive(log, g_LogLevel))
1492 WLog_Print(log, g_LogLevel,
"%s_Return {", name);
1493 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1494 SCardGetErrorString(ret->ReturnCode),
1495 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1496 WLog_Print(log, g_LogLevel,
"}");
1499static void smartcard_trace_connect_return(wLog* log,
const Connect_Return* ret)
1503 if (!WLog_IsLevelActive(log, g_LogLevel))
1506 WLog_Print(log, g_LogLevel,
"Connect_Return {");
1507 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1508 SCardGetErrorString(ret->ReturnCode),
1509 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1510 smartcard_log_context(log, &ret->hContext);
1511 smartcard_log_redir_handle(log, &ret->hCard);
1513 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1514 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1515 WLog_Print(log, g_LogLevel,
"}");
1518static void smartcard_trace_reconnect_call(wLog* log,
const Reconnect_Call* call)
1522 if (!WLog_IsLevelActive(log, g_LogLevel))
1525 WLog_Print(log, g_LogLevel,
"Reconnect_Call {");
1526 smartcard_log_context(log, &call->handles.hContext);
1527 smartcard_log_redir_handle(log, &call->handles.hCard);
1529 WLog_Print(log, g_LogLevel,
1530 "dwShareMode: %s (0x%08" PRIX32
") dwPreferredProtocols: %s (0x%08" PRIX32
1531 ") dwInitialization: %s (0x%08" PRIX32
")",
1532 SCardGetShareModeString(call->dwShareMode), call->dwShareMode,
1533 SCardGetProtocolString(call->dwPreferredProtocols), call->dwPreferredProtocols,
1534 SCardGetDispositionString(call->dwInitialization), call->dwInitialization);
1535 WLog_Print(log, g_LogLevel,
"}");
1542 if (!WLog_IsLevelActive(log, g_LogLevel))
1545 WLog_Print(log, g_LogLevel,
"GetDeviceTypeId_Return {");
1546 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1547 SCardGetErrorString(ret->ReturnCode),
1548 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1549 WLog_Print(log, g_LogLevel,
" dwDeviceId=%08" PRIx32, ret->dwDeviceId);
1551 WLog_Print(log, g_LogLevel,
"}");
1554static LONG smartcard_unpack_common_context_and_string_a(wLog* log,
wStream* s,
1556 CHAR** pszReaderName)
1559 UINT32 pbContextNdrPtr = 0;
1560 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1561 if (status != SCARD_S_SUCCESS)
1564 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
1565 return ERROR_INVALID_DATA;
1567 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1568 if (status != SCARD_S_SUCCESS)
1571 status = smartcard_ndr_read_a(log, s, pszReaderName, NDR_PTR_FULL);
1572 if (status != SCARD_S_SUCCESS)
1575 smartcard_trace_context_and_string_call_a(log, __func__, phContext, *pszReaderName);
1576 return SCARD_S_SUCCESS;
1579static LONG smartcard_unpack_common_context_and_string_w(wLog* log,
wStream* s,
1581 WCHAR** pszReaderName)
1584 UINT32 pbContextNdrPtr = 0;
1586 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1587 if (status != SCARD_S_SUCCESS)
1590 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
1591 return ERROR_INVALID_DATA;
1593 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1594 if (status != SCARD_S_SUCCESS)
1597 status = smartcard_ndr_read_w(log, s, pszReaderName, NDR_PTR_FULL);
1598 if (status != SCARD_S_SUCCESS)
1601 smartcard_trace_context_and_string_call_w(log, __func__, phContext, *pszReaderName);
1602 return SCARD_S_SUCCESS;
1605LONG smartcard_unpack_common_type_header(
wStream* s)
1607 wLog* log = scard_log();
1610 UINT8 endianness = 0;
1611 UINT16 commonHeaderLength = 0;
1613 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1614 return STATUS_BUFFER_TOO_SMALL;
1617 Stream_Read_UINT8(s, version);
1618 Stream_Read_UINT8(s, endianness);
1619 Stream_Read_UINT16(s, commonHeaderLength);
1620 Stream_Read_UINT32(s, filler);
1624 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Version %" PRIu8
"", version);
1625 return STATUS_INVALID_PARAMETER;
1628 if (endianness != 0x10)
1630 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Endianness %" PRIu8
"",
1632 return STATUS_INVALID_PARAMETER;
1635 if (commonHeaderLength != 8)
1637 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader CommonHeaderLength %" PRIu16
"",
1638 commonHeaderLength);
1639 return STATUS_INVALID_PARAMETER;
1642 if (filler != 0xCCCCCCCC)
1644 WLog_Print(log, WLOG_WARN,
"Unexpected CommonTypeHeader Filler 0x%08" PRIX32
"", filler);
1645 return STATUS_INVALID_PARAMETER;
1648 return SCARD_S_SUCCESS;
1651void smartcard_pack_common_type_header(
wStream* s)
1653 Stream_Write_UINT8(s, 1);
1654 Stream_Write_UINT8(s, 0x10);
1655 Stream_Write_UINT16(s, 8);
1656 Stream_Write_UINT32(s, 0xCCCCCCCC);
1659LONG smartcard_unpack_private_type_header(
wStream* s)
1661 wLog* log = scard_log();
1663 UINT32 objectBufferLength = 0;
1665 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1666 return STATUS_BUFFER_TOO_SMALL;
1668 Stream_Read_UINT32(s, objectBufferLength);
1669 Stream_Read_UINT32(s, filler);
1671 if (filler != 0x00000000)
1673 WLog_Print(log, WLOG_WARN,
"Unexpected PrivateTypeHeader Filler 0x%08" PRIX32
"", filler);
1674 return STATUS_INVALID_PARAMETER;
1677 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, objectBufferLength))
1678 return STATUS_INVALID_PARAMETER;
1680 return SCARD_S_SUCCESS;
1683void smartcard_pack_private_type_header(
wStream* s, UINT32 objectBufferLength)
1685 Stream_Write_UINT32(s, objectBufferLength);
1686 Stream_Write_UINT32(s, 0x00000000);
1689LONG smartcard_unpack_read_size_align(
wStream* s,
size_t size, UINT32 alignment)
1691 const size_t padsize = (size + alignment - 1) & ~(alignment - 1);
1692 const size_t pad = padsize - size;
1696 if (!Stream_SafeSeek(s, pad))
1703LONG smartcard_pack_write_size_align(
wStream* s,
size_t size, UINT32 alignment)
1705 const size_t padsize = (size + alignment - 1) & ~(alignment - 1);
1706 const size_t pad = padsize - size;
1710 if (!Stream_EnsureRemainingCapacity(s, pad))
1712 wLog* log = scard_log();
1713 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
1714 return SCARD_F_INTERNAL_ERROR;
1717 Stream_Zero(s, pad);
1720 return SCARD_S_SUCCESS;
1725 SCARDCONTEXT hContext = WINPR_C_ARRAY_INIT;
1727 WINPR_ASSERT(context);
1728 if ((context->cbContext !=
sizeof(ULONG_PTR)) && (context->cbContext != 0))
1730 wLog* log = scard_log();
1731 WLog_Print(log, WLOG_WARN,
1732 "REDIR_SCARDCONTEXT does not match native size: Actual: %" PRIu32
1733 ", Expected: %" PRIuz
"",
1734 context->cbContext,
sizeof(ULONG_PTR));
1738 if (context->cbContext)
1739 CopyMemory(&hContext, &(context->pbContext), context->cbContext);
1744void smartcard_scard_context_native_to_redir(
REDIR_SCARDCONTEXT* context, SCARDCONTEXT hContext)
1746 WINPR_ASSERT(context);
1748 context->cbContext =
sizeof(ULONG_PTR);
1749 CopyMemory(&(context->pbContext), &hContext, context->cbContext);
1754 SCARDHANDLE hCard = 0;
1756 WINPR_ASSERT(handle);
1757 if (handle->cbHandle == 0)
1760 if (handle->cbHandle !=
sizeof(ULONG_PTR))
1762 wLog* log = scard_log();
1763 WLog_Print(log, WLOG_WARN,
1764 "REDIR_SCARDHANDLE does not match native size: Actual: %" PRIu32
1765 ", Expected: %" PRIuz
"",
1766 handle->cbHandle,
sizeof(ULONG_PTR));
1770 if (handle->cbHandle)
1771 CopyMemory(&hCard, &(handle->pbHandle), handle->cbHandle);
1776void smartcard_scard_handle_native_to_redir(
REDIR_SCARDHANDLE* handle, SCARDHANDLE hCard)
1778 WINPR_ASSERT(handle);
1780 handle->cbHandle =
sizeof(ULONG_PTR);
1781 CopyMemory(&(handle->pbHandle), &hCard, handle->cbHandle);
1784#define smartcard_context_supported(log, size) \
1785 smartcard_context_supported_((log), (size), __FILE__, __func__, __LINE__)
1786static LONG smartcard_context_supported_(wLog* log, uint32_t size,
const char* file,
1787 const char* fkt,
size_t line)
1794 return SCARD_S_SUCCESS;
1797 const uint32_t level = WLOG_WARN;
1798 if (WLog_IsLevelActive(log, level))
1800 WLog_PrintTextMessage(log, level, line, file, fkt,
1801 "REDIR_SCARDCONTEXT length is not 0, 4 or 8: %" PRIu32
"",
1804 return STATUS_INVALID_PARAMETER;
1810 UINT32* index, UINT32* ppbContextNdrPtr,
1811 const char* file,
const char* function,
size_t line)
1813 UINT32 pbContextNdrPtr = 0;
1816 WINPR_ASSERT(context);
1820 if (!Stream_CheckAndLogRequiredLengthWLogEx(log, WLOG_WARN, s, 4, 1,
"%s(%s:%" PRIuz
")", file,
1822 return STATUS_BUFFER_TOO_SMALL;
1824 const LONG status = smartcard_context_supported_(log, context->cbContext, file, function, line);
1825 if (status != SCARD_S_SUCCESS)
1828 Stream_Read_UINT32(s, context->cbContext);
1830 if (!smartcard_ndr_pointer_read_(log, s, index, &pbContextNdrPtr, file, function, line))
1831 return ERROR_INVALID_DATA;
1833 if (((context->cbContext == 0) && pbContextNdrPtr) ||
1834 ((context->cbContext != 0) && !pbContextNdrPtr))
1836 WLog_Print(log, WLOG_WARN,
1837 "REDIR_SCARDCONTEXT cbContext (%" PRIu32
") pbContextNdrPtr (%" PRIu32
1839 context->cbContext, pbContextNdrPtr);
1840 return STATUS_INVALID_PARAMETER;
1843 if (!Stream_CheckAndLogRequiredLengthWLogEx(log, WLOG_WARN, s, context->cbContext, 1,
1844 "%s(%s:%" PRIuz
")", file, function, line))
1845 return STATUS_INVALID_PARAMETER;
1847 *ppbContextNdrPtr = pbContextNdrPtr;
1848 return SCARD_S_SUCCESS;
1851LONG smartcard_pack_redir_scard_context(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1854 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
1856 WINPR_ASSERT(context);
1857 if (context->cbContext != 0)
1859 Stream_Write_UINT32(s, context->cbContext);
1860 Stream_Write_UINT32(s, pbContextNdrPtr);
1861 *index = *index + 1;
1866 return SCARD_S_SUCCESS;
1869LONG smartcard_unpack_redir_scard_context_ref(wLog* log,
wStream* s,
1870 WINPR_ATTR_UNUSED UINT32 pbContextNdrPtr,
1875 WINPR_ASSERT(context);
1876 if (context->cbContext == 0)
1877 return SCARD_S_SUCCESS;
1879 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1880 return STATUS_BUFFER_TOO_SMALL;
1882 Stream_Read_UINT32(s, length);
1884 if (length != context->cbContext)
1886 WLog_Print(log, WLOG_WARN,
1887 "REDIR_SCARDCONTEXT length (%" PRIu32
") cbContext (%" PRIu32
") mismatch",
1888 length, context->cbContext);
1889 return STATUS_INVALID_PARAMETER;
1892 const LONG status = smartcard_context_supported(log, context->cbContext);
1893 if (status != SCARD_S_SUCCESS)
1896 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, context->cbContext))
1897 return STATUS_BUFFER_TOO_SMALL;
1899 if (context->cbContext)
1900 Stream_Read(s, &(context->pbContext), context->cbContext);
1902 ZeroMemory(&(context->pbContext),
sizeof(context->pbContext));
1904 return SCARD_S_SUCCESS;
1907LONG smartcard_pack_redir_scard_context_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1910 WINPR_ASSERT(context);
1911 Stream_Write_UINT32(s, context->cbContext);
1913 if (context->cbContext)
1915 Stream_Write(s, &(context->pbContext), context->cbContext);
1918 return SCARD_S_SUCCESS;
1922 UINT32* index,
const char* file,
const char* function,
1925 WINPR_ASSERT(handle);
1928 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1929 return STATUS_BUFFER_TOO_SMALL;
1931 Stream_Read_UINT32(s, handle->cbHandle);
1933 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, handle->cbHandle))
1934 return STATUS_BUFFER_TOO_SMALL;
1936 if (!smartcard_ndr_pointer_read_(log, s, index,
nullptr, file, function, line))
1937 return ERROR_INVALID_DATA;
1939 return SCARD_S_SUCCESS;
1942LONG smartcard_pack_redir_scard_handle(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1945 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
1947 WINPR_ASSERT(handle);
1948 if (handle->cbHandle != 0)
1950 Stream_Write_UINT32(s, handle->cbHandle);
1951 Stream_Write_UINT32(s, pbContextNdrPtr);
1952 *index = *index + 1;
1956 return SCARD_S_SUCCESS;
1963 WINPR_ASSERT(handle);
1964 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1965 return STATUS_BUFFER_TOO_SMALL;
1967 Stream_Read_UINT32(s, length);
1969 if (length != handle->cbHandle)
1971 WLog_Print(log, WLOG_WARN,
1972 "REDIR_SCARDHANDLE length (%" PRIu32
") cbHandle (%" PRIu32
") mismatch", length,
1974 return STATUS_INVALID_PARAMETER;
1977 if ((handle->cbHandle != 4) && (handle->cbHandle != 8))
1979 WLog_Print(log, WLOG_WARN,
"REDIR_SCARDHANDLE length is not 4 or 8: %" PRIu32
"",
1981 return STATUS_INVALID_PARAMETER;
1984 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, handle->cbHandle))
1985 return STATUS_BUFFER_TOO_SMALL;
1987 if (handle->cbHandle)
1988 Stream_Read(s, &(handle->pbHandle), handle->cbHandle);
1990 return SCARD_S_SUCCESS;
1993LONG smartcard_pack_redir_scard_handle_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1996 WINPR_ASSERT(handle);
1997 Stream_Write_UINT32(s, handle->cbHandle);
1999 if (handle->cbHandle)
2000 Stream_Write(s, &(handle->pbHandle), handle->cbHandle);
2002 return SCARD_S_SUCCESS;
2008 wLog* log = scard_log();
2010 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2011 return STATUS_BUFFER_TOO_SMALL;
2013 Stream_Read_UINT32(s, call->dwScope);
2014 smartcard_trace_establish_context_call(log, call);
2015 return SCARD_S_SUCCESS;
2021 wLog* log = scard_log();
2025 smartcard_trace_establish_context_return(log, ret);
2026 if (ret->ReturnCode != SCARD_S_SUCCESS)
2027 return ret->ReturnCode;
2029 status = smartcard_pack_redir_scard_context(log, s, &(ret->hContext), &index);
2030 if (status != SCARD_S_SUCCESS)
2033 return smartcard_pack_redir_scard_context_ref(log, s, &(ret->hContext));
2039 UINT32 pbContextNdrPtr = 0;
2040 wLog* log = scard_log();
2043 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2045 if (status != SCARD_S_SUCCESS)
2048 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2049 &(call->handles.hContext));
2050 if (status != SCARD_S_SUCCESS)
2051 WLog_Print(log, WLOG_ERROR,
2052 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2055 smartcard_trace_context_call(log, call, name);
2062 UINT32 pbContextNdrPtr = 0;
2063 wLog* log = scard_log();
2066 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2069 if (status != SCARD_S_SUCCESS)
2072 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2073 return STATUS_BUFFER_TOO_SMALL;
2075 Stream_Read_INT32(s, call->fmszGroupsIsNULL);
2076 Stream_Read_UINT32(s, call->cchGroups);
2077 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2078 &(call->handles.hContext));
2080 if (status != SCARD_S_SUCCESS)
2083 smartcard_trace_list_reader_groups_call(log, call, unicode);
2084 return SCARD_S_SUCCESS;
2091 wLog* log = scard_log();
2093 DWORD cBytes = ret->cBytes;
2096 smartcard_trace_list_reader_groups_return(log, ret, unicode);
2097 if (ret->ReturnCode != SCARD_S_SUCCESS)
2099 if (cBytes == SCARD_AUTOALLOCATE)
2102 if (!Stream_EnsureRemainingCapacity(s, 4))
2103 return SCARD_E_NO_MEMORY;
2105 Stream_Write_UINT32(s, cBytes);
2106 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
2107 return SCARD_E_NO_MEMORY;
2109 status = smartcard_ndr_write(s, ret->msz, cBytes, 1, NDR_PTR_SIMPLE);
2110 if (status != SCARD_S_SUCCESS)
2112 return ret->ReturnCode;
2118 UINT32 mszGroupsNdrPtr = 0;
2119 UINT32 pbContextNdrPtr = 0;
2120 wLog* log = scard_log();
2123 call->mszGroups =
nullptr;
2125 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2127 if (status != SCARD_S_SUCCESS)
2130 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2131 return STATUS_BUFFER_TOO_SMALL;
2133 Stream_Read_UINT32(s, call->cBytes);
2134 if (!smartcard_ndr_pointer_read(log, s, &index, &mszGroupsNdrPtr))
2135 return ERROR_INVALID_DATA;
2137 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2138 return STATUS_BUFFER_TOO_SMALL;
2139 Stream_Read_INT32(s, call->fmszReadersIsNULL);
2140 Stream_Read_UINT32(s, call->cchReaders);
2142 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2143 &(call->handles.hContext));
2144 if (status != SCARD_S_SUCCESS)
2147 if (mszGroupsNdrPtr)
2149 status = smartcard_ndr_read(log, s, &call->mszGroups, call->cBytes, 1, NDR_PTR_SIMPLE);
2150 if (status != SCARD_S_SUCCESS)
2154 smartcard_trace_list_readers_call(log, call, unicode);
2155 return SCARD_S_SUCCESS;
2161 wLog* log = scard_log();
2164 UINT32 size = ret->cBytes;
2166 smartcard_trace_list_readers_return(log, ret, unicode);
2167 if (ret->ReturnCode != SCARD_S_SUCCESS)
2170 if (!Stream_EnsureRemainingCapacity(s, 4))
2172 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
2173 return SCARD_F_INTERNAL_ERROR;
2176 Stream_Write_UINT32(s, size);
2177 if (!smartcard_ndr_pointer_write(s, &index, size))
2178 return SCARD_E_NO_MEMORY;
2180 status = smartcard_ndr_write(s, ret->msz, size, 1, NDR_PTR_SIMPLE);
2181 if (status != SCARD_S_SUCCESS)
2183 return ret->ReturnCode;
2187 UINT32* index, UINT32* ppbContextNdrPtr)
2189 WINPR_ASSERT(common);
2190 LONG status = smartcard_unpack_redir_scard_context(log, s, &(common->handles.hContext), index,
2192 if (status != SCARD_S_SUCCESS)
2195 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2196 return STATUS_BUFFER_TOO_SMALL;
2198 Stream_Read_UINT32(s, common->dwShareMode);
2199 Stream_Read_UINT32(s, common->dwPreferredProtocols);
2200 return SCARD_S_SUCCESS;
2207 UINT32 pbContextNdrPtr = 0;
2210 wLog* log = scard_log();
2212 call->szReader =
nullptr;
2214 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
2215 return ERROR_INVALID_DATA;
2217 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2218 if (status != SCARD_S_SUCCESS)
2220 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2225 status = smartcard_ndr_read_a(log, s, &call->szReader, NDR_PTR_FULL);
2226 if (status != SCARD_S_SUCCESS)
2229 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2230 &(call->Common.handles.hContext));
2231 if (status != SCARD_S_SUCCESS)
2232 WLog_Print(log, WLOG_ERROR,
2233 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2236 smartcard_trace_connect_a_call(log, call);
2244 UINT32 pbContextNdrPtr = 0;
2247 wLog* log = scard_log();
2248 call->szReader =
nullptr;
2250 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
2251 return ERROR_INVALID_DATA;
2253 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2254 if (status != SCARD_S_SUCCESS)
2256 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2261 status = smartcard_ndr_read_w(log, s, &call->szReader, NDR_PTR_FULL);
2262 if (status != SCARD_S_SUCCESS)
2265 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2266 &(call->Common.handles.hContext));
2267 if (status != SCARD_S_SUCCESS)
2268 WLog_Print(log, WLOG_ERROR,
2269 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2272 smartcard_trace_connect_w_call(log, call);
2282 wLog* log = scard_log();
2283 smartcard_trace_connect_return(log, ret);
2285 status = smartcard_pack_redir_scard_context(log, s, &ret->hContext, &index);
2286 if (status != SCARD_S_SUCCESS)
2289 status = smartcard_pack_redir_scard_handle(log, s, &ret->hCard, &index);
2290 if (status != SCARD_S_SUCCESS)
2293 if (!Stream_EnsureRemainingCapacity(s, 4))
2294 return SCARD_E_NO_MEMORY;
2296 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2297 status = smartcard_pack_redir_scard_context_ref(log, s, &ret->hContext);
2298 if (status != SCARD_S_SUCCESS)
2300 return smartcard_pack_redir_scard_handle_ref(log, s, &(ret->hCard));
2306 UINT32 pbContextNdrPtr = 0;
2309 wLog* log = scard_log();
2310 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2312 if (status != SCARD_S_SUCCESS)
2315 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2316 if (status != SCARD_S_SUCCESS)
2319 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2320 return STATUS_BUFFER_TOO_SMALL;
2322 Stream_Read_UINT32(s, call->dwShareMode);
2323 Stream_Read_UINT32(s, call->dwPreferredProtocols);
2324 Stream_Read_UINT32(s, call->dwInitialization);
2326 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2327 &(call->handles.hContext));
2328 if (status != SCARD_S_SUCCESS)
2330 WLog_Print(log, WLOG_ERROR,
2331 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2336 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2337 if (status != SCARD_S_SUCCESS)
2338 WLog_Print(log, WLOG_ERROR,
2339 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
2341 smartcard_trace_reconnect_call(log, call);
2348 wLog* log = scard_log();
2349 smartcard_trace_reconnect_return(log, ret);
2351 if (!Stream_EnsureRemainingCapacity(s, 4))
2352 return SCARD_E_NO_MEMORY;
2353 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2354 return ret->ReturnCode;
2361 UINT32 pbContextNdrPtr = 0;
2364 wLog* log = scard_log();
2366 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2368 if (status != SCARD_S_SUCCESS)
2371 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2372 if (status != SCARD_S_SUCCESS)
2375 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2376 return STATUS_BUFFER_TOO_SMALL;
2378 Stream_Read_UINT32(s, call->dwDisposition);
2380 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2381 &(call->handles.hContext));
2382 if (status != SCARD_S_SUCCESS)
2385 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2386 if (status != SCARD_S_SUCCESS)
2389 smartcard_trace_hcard_and_disposition_call(log, call, name);
2397 if (!WLog_IsLevelActive(log, g_LogLevel))
2400 WLog_Print(log, g_LogLevel,
"GetStatusChangeA_Call {");
2401 smartcard_log_context(log, &call->handles.hContext);
2403 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
2406 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
2408 WLog_Print(log, g_LogLevel,
"}");
2412 UINT32 cReaders, UINT32* ptrIndex)
2414 LONG status = SCARD_E_NO_MEMORY;
2416 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2417 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2420 const UINT32 len = Stream_Get_UINT32(s);
2421 if (len != cReaders)
2423 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEA");
2429 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2430 if (!rgReaderStates || !states)
2432 status = ERROR_INVALID_DATA;
2434 for (UINT32 index = 0; index < cReaders; index++)
2436 UINT32 ptr = UINT32_MAX;
2439 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2442 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2448 states[index] = ptr != 0;
2449 Stream_Read_UINT32(s, readerState->dwCurrentState);
2450 Stream_Read_UINT32(s, readerState->dwEventState);
2451 Stream_Read_UINT32(s, readerState->cbAtr);
2452 Stream_Read(s, readerState->rgbAtr, 36);
2455 for (UINT32 index = 0; index < cReaders; index++)
2462 status = smartcard_ndr_read_a(log, s, &readerState->szReader, NDR_PTR_FULL);
2463 if (status != SCARD_S_SUCCESS)
2467 *ppcReaders = rgReaderStates;
2469 return SCARD_S_SUCCESS;
2473 for (UINT32 index = 0; index < cReaders; index++)
2476 free(readerState->szReader);
2479 free(rgReaderStates);
2485 UINT32 cReaders, UINT32* ptrIndex)
2487 LONG status = SCARD_E_NO_MEMORY;
2489 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2490 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2493 const UINT32 len = Stream_Get_UINT32(s);
2494 if (len != cReaders)
2496 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEW");
2502 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2504 if (!rgReaderStates || !states)
2507 status = ERROR_INVALID_DATA;
2508 for (UINT32 index = 0; index < cReaders; index++)
2510 UINT32 ptr = UINT32_MAX;
2513 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2516 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2522 states[index] = ptr != 0;
2523 Stream_Read_UINT32(s, readerState->dwCurrentState);
2524 Stream_Read_UINT32(s, readerState->dwEventState);
2525 Stream_Read_UINT32(s, readerState->cbAtr);
2526 Stream_Read(s, readerState->rgbAtr, 36);
2529 for (UINT32 index = 0; index < cReaders; index++)
2537 status = smartcard_ndr_read_w(log, s, &readerState->szReader, NDR_PTR_FULL);
2538 if (status != SCARD_S_SUCCESS)
2542 *ppcReaders = rgReaderStates;
2544 return SCARD_S_SUCCESS;
2548 for (UINT32 index = 0; index < cReaders; index++)
2551 free(readerState->szReader);
2554 free(rgReaderStates);
2567 UINT32 pbContextNdrPtr = 0;
2570 wLog* log = scard_log();
2572 call->rgReaderStates =
nullptr;
2574 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2576 if (status != SCARD_S_SUCCESS)
2579 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2580 return STATUS_BUFFER_TOO_SMALL;
2582 Stream_Read_UINT32(s, call->dwTimeOut);
2583 Stream_Read_UINT32(s, call->cReaders);
2584 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2585 return ERROR_INVALID_DATA;
2587 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2588 &(call->handles.hContext));
2589 if (status != SCARD_S_SUCCESS)
2595 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
2596 if (status != SCARD_S_SUCCESS)
2601 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2602 return SCARD_E_UNEXPECTED;
2605 smartcard_trace_get_status_change_a_call(log, call);
2606 return SCARD_S_SUCCESS;
2613 UINT32 pbContextNdrPtr = 0;
2616 wLog* log = scard_log();
2617 call->rgReaderStates =
nullptr;
2619 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2621 if (status != SCARD_S_SUCCESS)
2624 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2625 return STATUS_BUFFER_TOO_SMALL;
2627 Stream_Read_UINT32(s, call->dwTimeOut);
2628 Stream_Read_UINT32(s, call->cReaders);
2629 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2630 return ERROR_INVALID_DATA;
2632 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2633 &(call->handles.hContext));
2634 if (status != SCARD_S_SUCCESS)
2640 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
2641 if (status != SCARD_S_SUCCESS)
2646 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2647 return SCARD_E_UNEXPECTED;
2650 smartcard_trace_get_status_change_w_call(log, call);
2651 return SCARD_S_SUCCESS;
2658 wLog* log = scard_log();
2661 DWORD cReaders = ret->cReaders;
2664 smartcard_trace_get_status_change_return(log, ret, unicode);
2665 if (ret->ReturnCode != SCARD_S_SUCCESS)
2667 if (cReaders == SCARD_AUTOALLOCATE)
2670 if (!Stream_EnsureRemainingCapacity(s, 4))
2671 return SCARD_E_NO_MEMORY;
2673 Stream_Write_UINT32(s, cReaders);
2674 if (!smartcard_ndr_pointer_write(s, &index, cReaders))
2675 return SCARD_E_NO_MEMORY;
2676 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cReaders, NDR_PTR_SIMPLE);
2677 if (status != SCARD_S_SUCCESS)
2679 return ret->ReturnCode;
2685 UINT32 pbContextNdrPtr = 0;
2687 wLog* log = scard_log();
2690 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2692 if (status != SCARD_S_SUCCESS)
2695 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2696 if (status != SCARD_S_SUCCESS)
2699 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2700 return STATUS_BUFFER_TOO_SMALL;
2702 Stream_Read_INT32(s, call->fpbAtrIsNULL);
2703 Stream_Read_UINT32(s, call->cbAtrLen);
2705 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2706 &(call->handles.hContext));
2707 if (status != SCARD_S_SUCCESS)
2710 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2711 if (status != SCARD_S_SUCCESS)
2720 wLog* log = scard_log();
2722 DWORD cbAtrLen = ret->cbAtrLen;
2725 smartcard_trace_state_return(log, ret);
2726 if (ret->ReturnCode != SCARD_S_SUCCESS)
2728 if (cbAtrLen == SCARD_AUTOALLOCATE)
2731 Stream_Write_UINT32(s, ret->dwState);
2732 Stream_Write_UINT32(s, ret->dwProtocol);
2733 Stream_Write_UINT32(s, cbAtrLen);
2734 if (!smartcard_ndr_pointer_write(s, &index, cbAtrLen))
2735 return SCARD_E_NO_MEMORY;
2736 status = smartcard_ndr_write(s, ret->rgAtr, cbAtrLen, 1, NDR_PTR_SIMPLE);
2737 if (status != SCARD_S_SUCCESS)
2739 return ret->ReturnCode;
2745 UINT32 pbContextNdrPtr = 0;
2748 wLog* log = scard_log();
2750 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2752 if (status != SCARD_S_SUCCESS)
2755 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2756 if (status != SCARD_S_SUCCESS)
2759 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2760 return STATUS_BUFFER_TOO_SMALL;
2762 Stream_Read_INT32(s, call->fmszReaderNamesIsNULL);
2763 Stream_Read_UINT32(s, call->cchReaderLen);
2764 Stream_Read_UINT32(s, call->cbAtrLen);
2766 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2767 &(call->handles.hContext));
2768 if (status != SCARD_S_SUCCESS)
2771 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2772 if (status != SCARD_S_SUCCESS)
2775 smartcard_trace_status_call(log, call, unicode);
2782 wLog* log = scard_log();
2786 DWORD cBytes = ret->cBytes;
2788 smartcard_trace_status_return(log, ret, unicode);
2789 if (ret->ReturnCode != SCARD_S_SUCCESS)
2791 if (cBytes == SCARD_AUTOALLOCATE)
2794 if (!Stream_EnsureRemainingCapacity(s, 4))
2795 return SCARD_F_INTERNAL_ERROR;
2797 Stream_Write_UINT32(s, cBytes);
2798 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
2799 return SCARD_E_NO_MEMORY;
2801 if (!Stream_EnsureRemainingCapacity(s, 44))
2802 return SCARD_F_INTERNAL_ERROR;
2804 Stream_Write_UINT32(s, ret->dwState);
2805 Stream_Write_UINT32(s, ret->dwProtocol);
2806 Stream_Write(s, ret->pbAtr,
sizeof(ret->pbAtr));
2807 Stream_Write_UINT32(s, ret->cbAtrLen);
2808 status = smartcard_ndr_write(s, ret->mszReaderNames, cBytes, 1, NDR_PTR_SIMPLE);
2809 if (status != SCARD_S_SUCCESS)
2811 return ret->ReturnCode;
2817 wLog* log = scard_log();
2819 UINT32 pbContextNdrPtr = 0;
2821 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2823 if (status != SCARD_S_SUCCESS)
2826 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2827 if (status != SCARD_S_SUCCESS)
2830 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2831 return STATUS_BUFFER_TOO_SMALL;
2833 Stream_Read_UINT32(s, call->dwAttrId);
2834 Stream_Read_INT32(s, call->fpbAttrIsNULL);
2835 Stream_Read_UINT32(s, call->cbAttrLen);
2837 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2838 &(call->handles.hContext));
2839 if (status != SCARD_S_SUCCESS)
2842 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2843 if (status != SCARD_S_SUCCESS)
2846 smartcard_trace_get_attrib_call(log, call);
2851 DWORD cbAttrCallLen)
2854 wLog* log = scard_log();
2856 DWORD cbAttrLen = 0;
2858 smartcard_trace_get_attrib_return(log, ret, dwAttrId);
2860 if (!Stream_EnsureRemainingCapacity(s, 4))
2861 return SCARD_F_INTERNAL_ERROR;
2863 cbAttrLen = ret->cbAttrLen;
2864 if (ret->ReturnCode != SCARD_S_SUCCESS)
2866 if (cbAttrLen == SCARD_AUTOALLOCATE)
2871 if (cbAttrCallLen < cbAttrLen)
2872 cbAttrLen = cbAttrCallLen;
2874 Stream_Write_UINT32(s, cbAttrLen);
2875 if (!smartcard_ndr_pointer_write(s, &index, cbAttrLen))
2876 return SCARD_E_NO_MEMORY;
2878 status = smartcard_ndr_write(s, ret->pbAttr, cbAttrLen, 1, NDR_PTR_SIMPLE);
2879 if (status != SCARD_S_SUCCESS)
2881 return ret->ReturnCode;
2887 wLog* log = scard_log();
2890 UINT32 pvInBufferNdrPtr = 0;
2891 UINT32 pbContextNdrPtr = 0;
2893 call->pvInBuffer =
nullptr;
2895 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2897 if (status != SCARD_S_SUCCESS)
2900 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2901 if (status != SCARD_S_SUCCESS)
2904 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 20))
2905 return STATUS_BUFFER_TOO_SMALL;
2907 Stream_Read_UINT32(s, call->dwControlCode);
2908 Stream_Read_UINT32(s, call->cbInBufferSize);
2909 if (!smartcard_ndr_pointer_read(log, s, &index,
2911 return ERROR_INVALID_DATA;
2912 Stream_Read_INT32(s, call->fpvOutBufferIsNULL);
2913 Stream_Read_UINT32(s, call->cbOutBufferSize);
2915 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2916 &(call->handles.hContext));
2917 if (status != SCARD_S_SUCCESS)
2920 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2921 if (status != SCARD_S_SUCCESS)
2924 if (pvInBufferNdrPtr)
2927 smartcard_ndr_read(log, s, &call->pvInBuffer, call->cbInBufferSize, 1, NDR_PTR_SIMPLE);
2928 if (status != SCARD_S_SUCCESS)
2932 smartcard_trace_control_call(log, call);
2933 return SCARD_S_SUCCESS;
2939 wLog* log = scard_log();
2942 DWORD cbDataLen = ret->cbOutBufferSize;
2945 smartcard_trace_control_return(log, ret);
2946 if (ret->ReturnCode != SCARD_S_SUCCESS)
2948 if (cbDataLen == SCARD_AUTOALLOCATE)
2951 if (!Stream_EnsureRemainingCapacity(s, 4))
2952 return SCARD_F_INTERNAL_ERROR;
2954 Stream_Write_UINT32(s, cbDataLen);
2955 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
2956 return SCARD_E_NO_MEMORY;
2958 status = smartcard_ndr_write(s, ret->pvOutBuffer, cbDataLen, 1, NDR_PTR_SIMPLE);
2959 if (status != SCARD_S_SUCCESS)
2961 return ret->ReturnCode;
2967 BYTE* pbExtraBytes =
nullptr;
2968 UINT32 pbExtraBytesNdrPtr = 0;
2969 UINT32 pbSendBufferNdrPtr = 0;
2970 UINT32 pioRecvPciNdrPtr = 0;
2974 UINT32 pbContextNdrPtr = 0;
2977 wLog* log = scard_log();
2979 call->pioSendPci =
nullptr;
2980 call->pioRecvPci =
nullptr;
2981 call->pbSendBuffer =
nullptr;
2983 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2985 if (status != SCARD_S_SUCCESS)
2988 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2989 if (status != SCARD_S_SUCCESS)
2992 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 32))
2993 return STATUS_BUFFER_TOO_SMALL;
2995 Stream_Read_UINT32(s, ioSendPci.dwProtocol);
2996 Stream_Read_UINT32(s, ioSendPci.cbExtraBytes);
2997 if (!smartcard_ndr_pointer_read(log, s, &index,
2998 &pbExtraBytesNdrPtr))
2999 return ERROR_INVALID_DATA;
3001 Stream_Read_UINT32(s, call->cbSendLength);
3002 if (!smartcard_ndr_pointer_read(log, s, &index,
3003 &pbSendBufferNdrPtr))
3004 return ERROR_INVALID_DATA;
3006 if (!smartcard_ndr_pointer_read(log, s, &index,
3008 return ERROR_INVALID_DATA;
3010 Stream_Read_INT32(s, call->fpbRecvBufferIsNULL);
3011 Stream_Read_UINT32(s, call->cbRecvLength);
3013 if (ioSendPci.cbExtraBytes > 1024)
3015 WLog_Print(log, WLOG_WARN,
3016 "Transmit_Call ioSendPci.cbExtraBytes is out of bounds: %" PRIu32
" (max: 1024)",
3017 ioSendPci.cbExtraBytes);
3018 return STATUS_INVALID_PARAMETER;
3021 if (call->cbSendLength > 66560)
3023 WLog_Print(log, WLOG_WARN,
3024 "Transmit_Call cbSendLength is out of bounds: %" PRIu32
" (max: 66560)",
3025 ioSendPci.cbExtraBytes);
3026 return STATUS_INVALID_PARAMETER;
3029 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3030 &(call->handles.hContext));
3031 if (status != SCARD_S_SUCCESS)
3034 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3035 if (status != SCARD_S_SUCCESS)
3038 if (ioSendPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3042 "Transmit_Call ioSendPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3043 return STATUS_INVALID_PARAMETER;
3046 if (pbExtraBytesNdrPtr)
3049 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3050 return STATUS_BUFFER_TOO_SMALL;
3052 Stream_Read_UINT32(s, length);
3054 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioSendPci.cbExtraBytes))
3055 return STATUS_BUFFER_TOO_SMALL;
3057 ioSendPci.pbExtraBytes = Stream_Pointer(s);
3061 if (!call->pioSendPci)
3063 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3064 return STATUS_NO_MEMORY;
3067 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3068 call->pioSendPci->cbPciLength = (DWORD)(ioSendPci.cbExtraBytes +
sizeof(
SCARD_IO_REQUEST));
3070 Stream_Read(s, pbExtraBytes, ioSendPci.cbExtraBytes);
3071 if (smartcard_unpack_read_size_align(s, ioSendPci.cbExtraBytes, 4) < 0)
3072 return STATUS_INVALID_PARAMETER;
3078 if (!call->pioSendPci)
3080 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3081 return STATUS_NO_MEMORY;
3084 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3088 if (pbSendBufferNdrPtr)
3091 smartcard_ndr_read(log, s, &call->pbSendBuffer, call->cbSendLength, 1, NDR_PTR_SIMPLE);
3092 if (status != SCARD_S_SUCCESS)
3096 if (pioRecvPciNdrPtr)
3098 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3099 return STATUS_BUFFER_TOO_SMALL;
3101 Stream_Read_UINT32(s, ioRecvPci.dwProtocol);
3102 Stream_Read_UINT32(s, ioRecvPci.cbExtraBytes);
3103 if (!smartcard_ndr_pointer_read(log, s, &index,
3104 &pbExtraBytesNdrPtr))
3105 return ERROR_INVALID_DATA;
3107 if (ioRecvPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3111 "Transmit_Call ioRecvPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3112 return STATUS_INVALID_PARAMETER;
3115 if (pbExtraBytesNdrPtr)
3118 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3119 return STATUS_BUFFER_TOO_SMALL;
3121 Stream_Read_UINT32(s, length);
3123 if (ioRecvPci.cbExtraBytes > 1024)
3125 WLog_Print(log, WLOG_WARN,
3126 "Transmit_Call ioRecvPci.cbExtraBytes is out of bounds: %" PRIu32
3128 ioRecvPci.cbExtraBytes);
3129 return STATUS_INVALID_PARAMETER;
3132 if (length != ioRecvPci.cbExtraBytes)
3134 WLog_Print(log, WLOG_WARN,
3135 "Transmit_Call unexpected length: Actual: %" PRIu32
3136 ", Expected: %" PRIu32
" (ioRecvPci.cbExtraBytes)",
3137 length, ioRecvPci.cbExtraBytes);
3138 return STATUS_INVALID_PARAMETER;
3141 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioRecvPci.cbExtraBytes))
3142 return STATUS_BUFFER_TOO_SMALL;
3144 ioRecvPci.pbExtraBytes = Stream_Pointer(s);
3148 if (!call->pioRecvPci)
3150 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3151 return STATUS_NO_MEMORY;
3154 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3155 call->pioRecvPci->cbPciLength =
3158 Stream_Read(s, pbExtraBytes, ioRecvPci.cbExtraBytes);
3159 if (smartcard_unpack_read_size_align(s, ioRecvPci.cbExtraBytes, 4) < 0)
3160 return STATUS_INVALID_PARAMETER;
3166 if (!call->pioRecvPci)
3168 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3169 return STATUS_NO_MEMORY;
3172 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3177 smartcard_trace_transmit_call(log, call);
3178 return SCARD_S_SUCCESS;
3184 wLog* log = scard_log();
3189 UINT32 cbRecvLength = ret->cbRecvLength;
3190 UINT32 cbRecvPci = ret->pioRecvPci ? ret->pioRecvPci->cbPciLength : 0;
3192 smartcard_trace_transmit_return(log, ret);
3194 if (!ret->pbRecvBuffer)
3197 if (!smartcard_ndr_pointer_write(s, &index, cbRecvPci))
3198 return SCARD_E_NO_MEMORY;
3199 if (!Stream_EnsureRemainingCapacity(s, 4))
3200 return SCARD_E_NO_MEMORY;
3201 Stream_Write_UINT32(s, cbRecvLength);
3202 if (!smartcard_ndr_pointer_write(s, &index, cbRecvLength))
3203 return SCARD_E_NO_MEMORY;
3205 if (ret->pioRecvPci)
3207 UINT32 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
3210 if (!Stream_EnsureRemainingCapacity(s, cbExtraBytes + 16))
3212 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3213 return SCARD_F_INTERNAL_ERROR;
3216 Stream_Write_UINT32(s, ret->pioRecvPci->dwProtocol);
3217 Stream_Write_UINT32(s, cbExtraBytes);
3218 if (!smartcard_ndr_pointer_write(s, &index, cbExtraBytes))
3219 return SCARD_E_NO_MEMORY;
3220 error = smartcard_ndr_write(s, pbExtraBytes, cbExtraBytes, 1, NDR_PTR_SIMPLE);
3225 status = smartcard_ndr_write(s, ret->pbRecvBuffer, ret->cbRecvLength, 1, NDR_PTR_SIMPLE);
3226 if (status != SCARD_S_SUCCESS)
3228 return ret->ReturnCode;
3233 UINT32 rgReaderStatesNdrPtr = 0;
3234 UINT32 rgAtrMasksNdrPtr = 0;
3236 UINT32 pbContextNdrPtr = 0;
3239 wLog* log = scard_log();
3241 call->rgReaderStates =
nullptr;
3243 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3245 if (status != SCARD_S_SUCCESS)
3248 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3249 return STATUS_BUFFER_TOO_SMALL;
3251 Stream_Read_UINT32(s, call->cAtrs);
3252 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3253 return ERROR_INVALID_DATA;
3254 Stream_Read_UINT32(s, call->cReaders);
3255 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3256 return ERROR_INVALID_DATA;
3258 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3259 &(call->handles.hContext));
3260 if (status != SCARD_S_SUCCESS)
3263 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3265 WLog_Print(log, WLOG_WARN,
3266 "LocateCardsByATRA_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3267 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3268 rgAtrMasksNdrPtr, call->cAtrs);
3269 return STATUS_INVALID_PARAMETER;
3272 if (rgAtrMasksNdrPtr)
3274 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3275 if (status != SCARD_S_SUCCESS)
3279 if (rgReaderStatesNdrPtr)
3282 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
3283 if (status != SCARD_S_SUCCESS)
3287 smartcard_trace_locate_cards_by_atr_a_call(log, call);
3288 return SCARD_S_SUCCESS;
3293 UINT32 sz1NdrPtr = 0;
3294 UINT32 sz2NdrPtr = 0;
3296 UINT32 pbContextNdrPtr = 0;
3299 wLog* log = scard_log();
3301 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3303 if (status != SCARD_S_SUCCESS)
3306 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3307 return ERROR_INVALID_DATA;
3308 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3309 return ERROR_INVALID_DATA;
3312 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3313 if (status != SCARD_S_SUCCESS)
3318 status = smartcard_ndr_read_a(log, s, &call->sz1, NDR_PTR_FULL);
3319 if (status != SCARD_S_SUCCESS)
3324 status = smartcard_ndr_read_a(log, s, &call->sz2, NDR_PTR_FULL);
3325 if (status != SCARD_S_SUCCESS)
3328 smartcard_trace_context_and_two_strings_a_call(log, call);
3329 return SCARD_S_SUCCESS;
3334 UINT32 sz1NdrPtr = 0;
3335 UINT32 sz2NdrPtr = 0;
3337 UINT32 pbContextNdrPtr = 0;
3340 wLog* log = scard_log();
3342 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3344 if (status != SCARD_S_SUCCESS)
3347 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3348 return ERROR_INVALID_DATA;
3349 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3350 return ERROR_INVALID_DATA;
3353 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3354 if (status != SCARD_S_SUCCESS)
3359 status = smartcard_ndr_read_w(log, s, &call->sz1, NDR_PTR_FULL);
3360 if (status != SCARD_S_SUCCESS)
3365 status = smartcard_ndr_read_w(log, s, &call->sz2, NDR_PTR_FULL);
3366 if (status != SCARD_S_SUCCESS)
3369 smartcard_trace_context_and_two_strings_w_call(log, call);
3370 return SCARD_S_SUCCESS;
3375 UINT32 sz1NdrPtr = 0;
3376 UINT32 sz2NdrPtr = 0;
3378 UINT32 pbContextNdrPtr = 0;
3381 wLog* log = scard_log();
3383 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3385 if (status != SCARD_S_SUCCESS)
3388 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3389 return STATUS_BUFFER_TOO_SMALL;
3391 Stream_Read_UINT32(s, call->cBytes);
3392 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3393 return ERROR_INVALID_DATA;
3395 Stream_Read_UINT32(s, call->cReaders);
3396 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3397 return ERROR_INVALID_DATA;
3399 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3400 &(call->handles.hContext));
3401 if (status != SCARD_S_SUCCESS)
3406 status = smartcard_ndr_read_fixed_string_a(log, s, &call->mszCards, call->cBytes,
3408 if (status != SCARD_S_SUCCESS)
3414 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
3415 if (status != SCARD_S_SUCCESS)
3418 smartcard_trace_locate_cards_a_call(log, call);
3419 return SCARD_S_SUCCESS;
3424 UINT32 sz1NdrPtr = 0;
3425 UINT32 sz2NdrPtr = 0;
3427 UINT32 pbContextNdrPtr = 0;
3430 wLog* log = scard_log();
3432 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3434 if (status != SCARD_S_SUCCESS)
3437 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3438 return STATUS_BUFFER_TOO_SMALL;
3440 Stream_Read_UINT32(s, call->cBytes);
3441 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3442 return ERROR_INVALID_DATA;
3444 Stream_Read_UINT32(s, call->cReaders);
3445 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3446 return ERROR_INVALID_DATA;
3448 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3449 &(call->handles.hContext));
3450 if (status != SCARD_S_SUCCESS)
3455 status = smartcard_ndr_read_fixed_string_w(log, s, &call->mszCards, call->cBytes,
3457 if (status != SCARD_S_SUCCESS)
3463 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
3464 if (status != SCARD_S_SUCCESS)
3467 smartcard_trace_locate_cards_w_call(log, call);
3468 return SCARD_S_SUCCESS;
3475 UINT32 pbContextNdrPtr = 0;
3478 wLog* log = scard_log();
3480 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3482 if (status != SCARD_S_SUCCESS)
3484 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3485 if (status != SCARD_S_SUCCESS)
3488 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3489 return STATUS_BUFFER_TOO_SMALL;
3490 Stream_Read_UINT32(s, call->dwAttrId);
3491 Stream_Read_UINT32(s, call->cbAttrLen);
3493 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
3494 return ERROR_INVALID_DATA;
3496 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3497 &(call->handles.hContext));
3498 if (status != SCARD_S_SUCCESS)
3501 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3502 if (status != SCARD_S_SUCCESS)
3508 status = smartcard_ndr_read_ex(log, s, &call->pbAttr, 0, 1, NDR_PTR_SIMPLE, &len);
3509 if (status != SCARD_S_SUCCESS)
3511 if (call->cbAttrLen > len)
3512 call->cbAttrLen = WINPR_ASSERTING_INT_CAST(DWORD, len);
3515 call->cbAttrLen = 0;
3516 smartcard_trace_set_attrib_call(log, call);
3517 return SCARD_S_SUCCESS;
3522 UINT32 rgReaderStatesNdrPtr = 0;
3523 UINT32 rgAtrMasksNdrPtr = 0;
3525 UINT32 pbContextNdrPtr = 0;
3528 wLog* log = scard_log();
3530 call->rgReaderStates =
nullptr;
3532 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3534 if (status != SCARD_S_SUCCESS)
3537 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3538 return STATUS_BUFFER_TOO_SMALL;
3540 Stream_Read_UINT32(s, call->cAtrs);
3541 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3542 return ERROR_INVALID_DATA;
3544 Stream_Read_UINT32(s, call->cReaders);
3545 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3546 return ERROR_INVALID_DATA;
3548 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3549 &(call->handles.hContext));
3550 if (status != SCARD_S_SUCCESS)
3553 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3555 WLog_Print(log, WLOG_WARN,
3556 "LocateCardsByATRW_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3557 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3558 rgAtrMasksNdrPtr, call->cAtrs);
3559 return STATUS_INVALID_PARAMETER;
3562 if (rgAtrMasksNdrPtr)
3564 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3565 if (status != SCARD_S_SUCCESS)
3569 if (rgReaderStatesNdrPtr)
3572 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
3573 if (status != SCARD_S_SUCCESS)
3577 smartcard_trace_locate_cards_by_atr_w_call(log, call);
3578 return SCARD_S_SUCCESS;
3583 UINT32 mszNdrPtr = 0;
3584 UINT32 contextNdrPtr = 0;
3586 UINT32 pbContextNdrPtr = 0;
3589 wLog* log = scard_log();
3591 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3592 return ERROR_INVALID_DATA;
3594 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3595 &index, &pbContextNdrPtr);
3596 if (status != SCARD_S_SUCCESS)
3599 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3600 return ERROR_INVALID_DATA;
3602 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3603 return STATUS_BUFFER_TOO_SMALL;
3604 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3605 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
3606 Stream_Read_UINT32(s, call->Common.cbDataLen);
3608 call->szLookupName =
nullptr;
3611 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
3612 if (status != SCARD_S_SUCCESS)
3616 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3617 &call->Common.handles.hContext);
3618 if (status != SCARD_S_SUCCESS)
3623 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3624 if (status != SCARD_S_SUCCESS)
3627 smartcard_trace_read_cache_a_call(log, call);
3628 return SCARD_S_SUCCESS;
3633 UINT32 mszNdrPtr = 0;
3634 UINT32 contextNdrPtr = 0;
3636 UINT32 pbContextNdrPtr = 0;
3639 wLog* log = scard_log();
3641 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3642 return ERROR_INVALID_DATA;
3644 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3645 &index, &pbContextNdrPtr);
3646 if (status != SCARD_S_SUCCESS)
3649 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3650 return ERROR_INVALID_DATA;
3652 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3653 return STATUS_BUFFER_TOO_SMALL;
3654 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3655 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
3656 Stream_Read_UINT32(s, call->Common.cbDataLen);
3658 call->szLookupName =
nullptr;
3661 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
3662 if (status != SCARD_S_SUCCESS)
3666 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3667 &call->Common.handles.hContext);
3668 if (status != SCARD_S_SUCCESS)
3673 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3674 if (status != SCARD_S_SUCCESS)
3677 smartcard_trace_read_cache_w_call(log, call);
3678 return SCARD_S_SUCCESS;
3683 UINT32 mszNdrPtr = 0;
3684 UINT32 contextNdrPtr = 0;
3685 UINT32 pbDataNdrPtr = 0;
3687 UINT32 pbContextNdrPtr = 0;
3690 wLog* log = scard_log();
3692 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3693 return ERROR_INVALID_DATA;
3695 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3696 &index, &pbContextNdrPtr);
3697 if (status != SCARD_S_SUCCESS)
3700 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3701 return ERROR_INVALID_DATA;
3703 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
3704 return STATUS_BUFFER_TOO_SMALL;
3706 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3707 Stream_Read_UINT32(s, call->Common.cbDataLen);
3709 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
3710 return ERROR_INVALID_DATA;
3712 call->szLookupName =
nullptr;
3715 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
3716 if (status != SCARD_S_SUCCESS)
3720 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3721 &call->Common.handles.hContext);
3722 if (status != SCARD_S_SUCCESS)
3725 call->Common.CardIdentifier =
nullptr;
3728 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3729 if (status != SCARD_S_SUCCESS)
3733 call->Common.pbData =
nullptr;
3736 status = smartcard_ndr_read(log, s, &call->Common.pbData, call->Common.cbDataLen, 1,
3738 if (status != SCARD_S_SUCCESS)
3741 smartcard_trace_write_cache_a_call(log, call);
3742 return SCARD_S_SUCCESS;
3747 UINT32 mszNdrPtr = 0;
3748 UINT32 contextNdrPtr = 0;
3749 UINT32 pbDataNdrPtr = 0;
3751 UINT32 pbContextNdrPtr = 0;
3754 wLog* log = scard_log();
3756 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3757 return ERROR_INVALID_DATA;
3759 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3760 &index, &pbContextNdrPtr);
3761 if (status != SCARD_S_SUCCESS)
3764 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3765 return ERROR_INVALID_DATA;
3767 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
3768 return STATUS_BUFFER_TOO_SMALL;
3769 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3770 Stream_Read_UINT32(s, call->Common.cbDataLen);
3772 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
3773 return ERROR_INVALID_DATA;
3775 call->szLookupName =
nullptr;
3778 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
3779 if (status != SCARD_S_SUCCESS)
3783 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3784 &call->Common.handles.hContext);
3785 if (status != SCARD_S_SUCCESS)
3788 call->Common.CardIdentifier =
nullptr;
3791 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3792 if (status != SCARD_S_SUCCESS)
3796 call->Common.pbData =
nullptr;
3799 status = smartcard_ndr_read(log, s, &call->Common.pbData, call->Common.cbDataLen, 1,
3801 if (status != SCARD_S_SUCCESS)
3804 smartcard_trace_write_cache_w_call(log, call);
3811 wLog* log = scard_log();
3814 UINT32 pbContextNdrPtr = 0;
3816 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3818 if (status != SCARD_S_SUCCESS)
3821 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3822 if (status != SCARD_S_SUCCESS)
3825 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3826 &(call->handles.hContext));
3827 if (status != SCARD_S_SUCCESS)
3829 WLog_Print(log, WLOG_ERROR,
3830 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
3835 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3836 if (status != SCARD_S_SUCCESS)
3837 WLog_Print(log, WLOG_ERROR,
3838 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
3840 smartcard_trace_get_transmit_count_call(log, call);
3847 wLog* log = scard_log();
3848 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
3849 &call->szReaderName);
3855 wLog* log = scard_log();
3856 return smartcard_unpack_common_context_and_string_a(log, s, &call->handles.hContext, &call->sz);
3862 wLog* log = scard_log();
3863 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext, &call->sz);
3869 wLog* log = scard_log();
3870 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
3871 &call->szReaderName);
3877 wLog* log = scard_log();
3878 smartcard_trace_device_type_id_return(log, ret);
3880 if (!Stream_EnsureRemainingCapacity(s, 4))
3882 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3883 return SCARD_F_INTERNAL_ERROR;
3886 Stream_Write_UINT32(s, ret->dwDeviceId);
3888 return ret->ReturnCode;
3894 wLog* log = scard_log();
3897 DWORD cbDataLen = ret->cReaders;
3900 smartcard_trace_locate_cards_return(log, ret);
3901 if (ret->ReturnCode != SCARD_S_SUCCESS)
3903 if (cbDataLen == SCARD_AUTOALLOCATE)
3906 if (!Stream_EnsureRemainingCapacity(s, 4))
3908 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3909 return SCARD_F_INTERNAL_ERROR;
3912 Stream_Write_UINT32(s, cbDataLen);
3913 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3914 return SCARD_E_NO_MEMORY;
3916 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cbDataLen, NDR_PTR_SIMPLE);
3917 if (status != SCARD_S_SUCCESS)
3919 return ret->ReturnCode;
3925 wLog* log = scard_log();
3929 DWORD cbDataLen = ret->cbDataLen;
3930 smartcard_trace_get_reader_icon_return(log, ret);
3931 if (ret->ReturnCode != SCARD_S_SUCCESS)
3933 if (cbDataLen == SCARD_AUTOALLOCATE)
3936 if (!Stream_EnsureRemainingCapacity(s, 4))
3938 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3939 return SCARD_F_INTERNAL_ERROR;
3942 Stream_Write_UINT32(s, cbDataLen);
3943 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3944 return SCARD_E_NO_MEMORY;
3946 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
3947 if (status != SCARD_S_SUCCESS)
3949 return ret->ReturnCode;
3955 wLog* log = scard_log();
3957 smartcard_trace_get_transmit_count_return(log, call);
3959 if (!Stream_EnsureRemainingCapacity(s, 4))
3961 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3962 return SCARD_F_INTERNAL_ERROR;
3965 Stream_Write_UINT32(s, call->cTransmitCount);
3967 return call->ReturnCode;
3973 wLog* log = scard_log();
3977 DWORD cbDataLen = ret->cbDataLen;
3978 smartcard_trace_read_cache_return(log, ret);
3979 if (ret->ReturnCode != SCARD_S_SUCCESS)
3982 if (cbDataLen == SCARD_AUTOALLOCATE)
3985 if (!Stream_EnsureRemainingCapacity(s, 4))
3987 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3988 return SCARD_F_INTERNAL_ERROR;
3991 Stream_Write_UINT32(s, cbDataLen);
3992 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3993 return SCARD_E_NO_MEMORY;
3995 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
3996 if (status != SCARD_S_SUCCESS)
3998 return ret->ReturnCode;