24#include <freerdp/config.h>
27#include <winpr/print.h>
29#include <freerdp/channels/scard.h>
30#include <freerdp/utils/smartcard_pack.h>
31#include "smartcard_pack.h"
33#include <freerdp/log.h>
34#define SCARD_TAG FREERDP_TAG("scard.pack")
36static const DWORD g_LogLevel = WLOG_DEBUG;
38static wLog* scard_log(
void)
40 static wLog* log =
nullptr;
42 log = WLog_Get(SCARD_TAG);
46#define smartcard_unpack_redir_scard_context(log, s, context, index, ndr) \
47 smartcard_unpack_redir_scard_context_((log), (s), (context), (index), (ndr), __FILE__, \
49#define smartcard_unpack_redir_scard_handle(log, s, context, index) \
50 smartcard_unpack_redir_scard_handle_((log), (s), (context), (index), __FILE__, __func__, \
53static LONG smartcard_unpack_redir_scard_context_(wLog* log,
wStream* s,
55 UINT32* ppbContextNdrPtr,
const char* file,
56 const char* function,
size_t line);
57static LONG smartcard_pack_redir_scard_context(wLog* log,
wStream* s,
60 UINT32* index,
const char* file,
61 const char* function,
size_t line);
62static LONG smartcard_pack_redir_scard_handle(wLog* log,
wStream* s,
64static LONG smartcard_unpack_redir_scard_context_ref(wLog* log,
wStream* s, UINT32 pbContextNdrPtr,
66static LONG smartcard_pack_redir_scard_context_ref(wLog* log,
wStream* s,
69static LONG smartcard_unpack_redir_scard_handle_ref(wLog* log,
wStream* s,
71static LONG smartcard_pack_redir_scard_handle_ref(wLog* log,
wStream* s,
83#define smartcard_ndr_pointer_read(log, s, index, ptr) \
84 smartcard_ndr_pointer_read_((log), (s), (index), (ptr), __FILE__, __func__, __LINE__)
85static BOOL smartcard_ndr_pointer_read_(wLog* log,
wStream* s, UINT32* index, UINT32* ptr,
86 const char* file,
const char* fkt,
size_t line)
88 const UINT32 expect = 0x20000 + (*index) * 4;
93 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
96 Stream_Read_UINT32(s, ndrPtr);
102 if (ptr && (ndrPtr == 0))
104 WLog_Print(log, WLOG_WARN,
105 "[%s:%" PRIuz
"] Read context pointer 0x%08" PRIx32
", expected 0x%08" PRIx32,
106 fkt, line, ndrPtr, expect);
110 (*index) = (*index) + 1;
114static LONG smartcard_ndr_read_ex(wLog* log,
wStream* s, BYTE** data,
size_t min,
115 size_t elementSize, ndr_ptr_t type,
size_t* plen)
139 return STATUS_INVALID_PARAMETER;
142 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, required))
143 return STATUS_BUFFER_TOO_SMALL;
148 Stream_Read_UINT32(s, len);
149 Stream_Read_UINT32(s, offset);
150 Stream_Read_UINT32(s, len2);
151 if (len != offset + len2)
153 WLog_Print(log, WLOG_ERROR,
154 "Invalid data when reading full NDR pointer: total=%" PRIuz
155 ", offset=%" PRIuz
", remaining=%" PRIuz,
157 return STATUS_BUFFER_TOO_SMALL;
161 Stream_Read_UINT32(s, len);
163 if ((len != min) && (min > 0))
165 WLog_Print(log, WLOG_ERROR,
166 "Invalid data when reading simple NDR pointer: total=%" PRIuz
167 ", expected=%" PRIuz,
169 return STATUS_BUFFER_TOO_SMALL;
176 return STATUS_INVALID_PARAMETER;
181 WLog_Print(log, WLOG_ERROR,
182 "Invalid length read from NDR pointer, minimum %" PRIuz
", got %" PRIuz, min,
184 return STATUS_DATA_ERROR;
187 if (len > SIZE_MAX / 2)
188 return STATUS_BUFFER_TOO_SMALL;
190 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(log, s, len, elementSize))
191 return STATUS_BUFFER_TOO_SMALL;
198 r = calloc(len +
sizeof(WCHAR),
sizeof(CHAR));
200 return SCARD_E_NO_MEMORY;
201 Stream_Read(s, r, len);
202 const LONG pad = smartcard_unpack_read_size_align(s, len, 4);
206 return STATUS_INVALID_PARAMETER;
212 return STATUS_SUCCESS;
215static LONG smartcard_ndr_read(wLog* log,
wStream* s, BYTE** data,
size_t min,
size_t elementSize,
218 return smartcard_ndr_read_ex(log, s, data, min, elementSize, type,
nullptr);
221static BOOL smartcard_ndr_pointer_write(
wStream* s, UINT32* index, DWORD length)
223 const UINT32 ndrPtr = 0x20000 + (*index) * 4;
227 if (!Stream_EnsureRemainingCapacity(s, 4))
232 Stream_Write_UINT32(s, ndrPtr);
233 (*index) = (*index) + 1;
236 Stream_Write_UINT32(s, 0);
240static LONG smartcard_ndr_write(
wStream* s,
const BYTE* data, UINT32 size, UINT32 elementSize,
243 const UINT32 offset = 0;
244 const UINT32 len = size;
245 const UINT32 dataLen = size * elementSize;
249 return SCARD_S_SUCCESS;
263 return SCARD_E_INVALID_PARAMETER;
266 if (!Stream_EnsureRemainingCapacity(s, required + dataLen + 4))
267 return STATUS_BUFFER_TOO_SMALL;
272 Stream_Write_UINT32(s, len);
273 Stream_Write_UINT32(s, offset);
274 Stream_Write_UINT32(s, len);
277 Stream_Write_UINT32(s, len);
282 return SCARD_E_INVALID_PARAMETER;
286 Stream_Write(s, data, dataLen);
288 Stream_Zero(s, dataLen);
289 return smartcard_pack_write_size_align(s, len, 4);
301 WINPR_ASSERT(data || (size == 0));
307 size_t min, ndr_ptr_t type)
318static LONG smartcard_ndr_read_fixed_string_a(wLog* log,
wStream* s, CHAR** data,
size_t min,
327 return smartcard_ndr_read(log, s, u.ppv, min,
sizeof(CHAR), type);
330static LONG smartcard_ndr_read_fixed_string_w(wLog* log,
wStream* s, WCHAR** data,
size_t min,
339 return smartcard_ndr_read(log, s, u.ppv, min,
sizeof(WCHAR), type);
342static LONG smartcard_ndr_read_a(wLog* log,
wStream* s, CHAR** data, ndr_ptr_t type)
350 return smartcard_ndr_read(log, s, u.ppv, 0,
sizeof(CHAR), type);
353static LONG smartcard_ndr_read_w(wLog* log,
wStream* s, WCHAR** data, ndr_ptr_t type)
361 return smartcard_ndr_read(log, s, u.ppv, 0,
sizeof(WCHAR), type);
364static LONG smartcard_ndr_read_u(wLog* log,
wStream* s,
UUID** data)
372 return smartcard_ndr_read(log, s, u.ppv, 1,
sizeof(
UUID), NDR_PTR_FIXED);
375static char* smartcard_convert_string_list(
const void* in,
size_t bytes, BOOL unicode)
384 char* mszA =
nullptr;
396 mszA = ConvertMszWCharNToUtf8Alloc(
string.wz, bytes /
sizeof(WCHAR), &length);
402 mszA = (
char*)calloc(bytes,
sizeof(
char));
405 CopyMemory(mszA,
string.sz, bytes - 1);
414 for (
size_t index = 0; index < length - 1; index++)
416 if (mszA[index] ==
'\0')
423WINPR_ATTR_MALLOC(free, 1)
424static
char* smartcard_create_msz_dump(const
char* msz,
size_t len)
426 size_t bufferLen = len;
427 char* buffer = calloc(len + 1, 1);
432 const char* cur = msz;
434 while ((len > 0) && cur && cur[0] !=
'\0' && (bufferLen > 0))
436 size_t clen = strnlen(cur, len);
437 int rc = _snprintf(buf, bufferLen,
"%s", cur);
438 bufferLen -= (size_t)rc;
447static void smartcard_msz_dump(wLog* log, DWORD level,
const char* prefix,
const void* data,
448 size_t len, BOOL wchar)
450 if (!WLog_IsLevelActive(log, level))
454 const char* msz = WINPR_CXX_COMPAT_CAST(
const char*, data);
458 tmp = ConvertMszWCharNToUtf8Alloc(data, len, &mszlen);
462 char* array = smartcard_create_msz_dump(msz, mszlen);
463 WLog_Print(log, level,
"%s%s", prefix, array);
468WINPR_ATTR_MALLOC(free, 1)
469static
char* smartcard_create_array_dump(const
void* pd,
size_t len)
471 const BYTE* data = pd;
474 size_t bufferLen = len * 4;
477 char* buffer = calloc(bufferLen + 1, 1);
480 char* start = buffer;
482 WINPR_ASSERT(buffer || (bufferLen == 0));
484 if (!data && (len > 0))
486 (void)_snprintf(buffer, bufferLen,
"{ nullptr [%" PRIuz
"] }", len);
490 rc = _snprintf(buffer, bufferLen,
"{ ");
491 if ((rc < 0) || ((
size_t)rc >= bufferLen))
494 bufferLen -= (size_t)rc;
496 for (
size_t x = 0; x < len; x++)
498 rc = _snprintf(buffer, bufferLen,
"%02X", data[x]);
499 if ((rc < 0) || ((
size_t)rc >= bufferLen))
502 bufferLen -= (size_t)rc;
505 rc = _snprintf(buffer, bufferLen,
" }");
506 if ((rc < 0) || ((
size_t)rc >= bufferLen))
513WINPR_ATTR_FORMAT_ARG(3, 7)
514static
void smartcard_dump_array(wLog* log, DWORD level, WINPR_FORMAT_ARG const
char* prefix,
515 const
char* postfix, const
void* data,
size_t len, ...)
517 if (!WLog_IsLevelActive(log, level))
520 char* buffer = smartcard_create_array_dump(data, len);
522 char* fprefix =
nullptr;
524 va_list ap = WINPR_C_ARRAY_INIT;
526 winpr_vasprintf(&fprefix, &flen, prefix, ap);
528 WLog_Print(log, level,
"%s%s%s", prefix, buffer, postfix);
533static void smartcard_log_redir_handle(wLog* log,
const REDIR_SCARDHANDLE* pHandle)
535 WINPR_ASSERT(pHandle);
536 smartcard_dump_array(log, g_LogLevel,
" hContext: ",
"", pHandle->pbHandle, pHandle->cbHandle);
541 WINPR_ASSERT(phContext);
542 smartcard_dump_array(log, g_LogLevel,
"hContext: ",
"", phContext->pbContext,
543 phContext->cbContext);
546static void smartcard_trace_context_and_string_call_a(wLog* log,
const char* name,
550 if (!WLog_IsLevelActive(log, g_LogLevel))
553 WLog_Print(log, g_LogLevel,
"%s {", name);
554 smartcard_log_context(log, phContext);
555 WLog_Print(log, g_LogLevel,
" sz=%s", sz);
557 WLog_Print(log, g_LogLevel,
"}");
560static void smartcard_trace_context_and_string_call_w(wLog* log,
const char* name,
566 if (!WLog_IsLevelActive(log, g_LogLevel))
570 tmp = ConvertWCharToUtf8Alloc(sz,
nullptr);
572 WLog_Print(log, g_LogLevel,
"%s {", name);
573 smartcard_log_context(log, phContext);
574 WLog_Print(log, g_LogLevel,
" sz=%s", tmp);
575 WLog_Print(log, g_LogLevel,
"}");
579static void smartcard_trace_context_call(wLog* log,
const Context_Call* call,
const char* name)
583 if (!WLog_IsLevelActive(log, g_LogLevel))
586 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
587 smartcard_log_context(log, &call->handles.hContext);
589 WLog_Print(log, g_LogLevel,
"}");
597 if (!WLog_IsLevelActive(log, g_LogLevel))
600 WLog_Print(log, g_LogLevel,
"ListReaderGroups%s_Call {", unicode ?
"W" :
"A");
601 smartcard_log_context(log, &call->handles.hContext);
603 WLog_Print(log, g_LogLevel,
"fmszGroupsIsNULL: %" PRId32
" cchGroups: 0x%08" PRIx32,
604 call->fmszGroupsIsNULL, call->cchGroups);
605 WLog_Print(log, g_LogLevel,
"}");
608static void dump_reader_states_return(wLog* log,
const ReaderState_Return* rgReaderStates,
611 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
612 for (UINT32 index = 0; index < cReaders; index++)
615 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
616 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
617 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
618 szCurrentState, readerState->dwCurrentState);
619 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
620 szEventState, readerState->dwEventState);
621 free(szCurrentState);
624 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
625 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
632 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
633 for (UINT32 index = 0; index < cReaders; index++)
637 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
638 readerState->szReader, readerState->cbAtr);
639 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
640 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
641 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
642 szCurrentState, readerState->dwCurrentState);
643 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
644 szEventState, readerState->dwEventState);
645 free(szCurrentState);
648 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
649 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
656 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
657 for (UINT32 index = 0; index < cReaders; index++)
660 char* buffer = ConvertWCharToUtf8Alloc(readerState->szReader,
nullptr);
661 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
662 buffer, readerState->cbAtr);
664 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
665 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
666 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
667 szCurrentState, readerState->dwCurrentState);
668 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
669 szEventState, readerState->dwEventState);
670 free(szCurrentState);
673 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
674 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
682 if (!WLog_IsLevelActive(log, g_LogLevel))
685 WLog_Print(log, g_LogLevel,
"GetStatusChangeW_Call {");
686 smartcard_log_context(log, &call->handles.hContext);
688 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
691 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
693 WLog_Print(log, g_LogLevel,
"}");
701 if (!WLog_IsLevelActive(log, g_LogLevel))
704 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
706 WLog_Print(log, g_LogLevel,
"ListReaderGroups%s_Return {", unicode ?
"W" :
"A");
707 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIx32
")",
708 SCardGetErrorString(ret->ReturnCode),
709 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
710 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
711 WLog_Print(log, g_LogLevel,
"}");
715static void smartcard_trace_list_readers_call(wLog* log,
const ListReaders_Call* call, BOOL unicode)
719 if (!WLog_IsLevelActive(log, g_LogLevel))
722 char* mszGroupsA = smartcard_convert_string_list(call->mszGroups, call->cBytes, unicode);
724 WLog_Print(log, g_LogLevel,
"ListReaders%s_Call {", unicode ?
"W" :
"A");
725 smartcard_log_context(log, &call->handles.hContext);
727 WLog_Print(log, g_LogLevel,
728 "cBytes: %" PRIu32
" mszGroups: %s fmszReadersIsNULL: %" PRId32
729 " cchReaders: 0x%08" PRIX32
"",
730 call->cBytes, mszGroupsA, call->fmszReadersIsNULL, call->cchReaders);
731 WLog_Print(log, g_LogLevel,
"}");
736static void smartcard_trace_locate_cards_by_atr_a_call(wLog* log,
741 if (!WLog_IsLevelActive(log, g_LogLevel))
744 WLog_Print(log, g_LogLevel,
"LocateCardsByATRA_Call {");
745 smartcard_log_context(log, &call->handles.hContext);
747 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
749 WLog_Print(log, g_LogLevel,
"}");
752static void smartcard_trace_locate_cards_a_call(wLog* log,
const LocateCardsA_Call* call)
756 if (!WLog_IsLevelActive(log, g_LogLevel))
759 WLog_Print(log, g_LogLevel,
"LocateCardsA_Call {");
760 smartcard_log_context(log, &call->handles.hContext);
761 WLog_Print(log, g_LogLevel,
" cBytes=%" PRIu32, call->cBytes);
762 smartcard_msz_dump(log, g_LogLevel,
" mszCards=", call->mszCards, call->cBytes, FALSE);
763 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, call->cReaders);
764 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
766 WLog_Print(log, g_LogLevel,
"}");
769static void smartcard_trace_locate_cards_return(wLog* log,
const LocateCards_Return* ret)
773 if (!WLog_IsLevelActive(log, g_LogLevel))
776 WLog_Print(log, g_LogLevel,
"LocateCards_Return {");
777 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
778 SCardGetErrorString(ret->ReturnCode),
779 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
781 if (ret->ReturnCode == SCARD_S_SUCCESS)
783 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, ret->cReaders);
785 WLog_Print(log, g_LogLevel,
"}");
792 if (!WLog_IsLevelActive(log, g_LogLevel))
795 WLog_Print(log, g_LogLevel,
"GetReaderIcon_Return {");
796 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
797 SCardGetErrorString(ret->ReturnCode),
798 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
800 if (ret->ReturnCode == SCARD_S_SUCCESS)
802 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, ret->cbDataLen);
804 WLog_Print(log, g_LogLevel,
"}");
811 if (!WLog_IsLevelActive(log, g_LogLevel))
814 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Return {");
815 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
816 SCardGetErrorString(ret->ReturnCode),
817 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
819 WLog_Print(log, g_LogLevel,
" cTransmitCount=%" PRIu32, ret->cTransmitCount);
820 WLog_Print(log, g_LogLevel,
"}");
823static void smartcard_trace_read_cache_return(wLog* log,
const ReadCache_Return* ret)
827 if (!WLog_IsLevelActive(log, g_LogLevel))
830 WLog_Print(log, g_LogLevel,
"ReadCache_Return {");
831 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
832 SCardGetErrorString(ret->ReturnCode),
833 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
835 if (ret->ReturnCode == SCARD_S_SUCCESS)
837 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, ret->cbDataLen);
838 smartcard_dump_array(log, g_LogLevel,
" cbData: ",
"", ret->pbData, ret->cbDataLen);
840 WLog_Print(log, g_LogLevel,
"}");
843static void smartcard_trace_locate_cards_w_call(wLog* log,
const LocateCardsW_Call* call)
847 if (!WLog_IsLevelActive(log, g_LogLevel))
850 WLog_Print(log, g_LogLevel,
"LocateCardsW_Call {");
851 smartcard_log_context(log, &call->handles.hContext);
852 WLog_Print(log, g_LogLevel,
" cBytes=%" PRIu32, call->cBytes);
853 smartcard_msz_dump(log, g_LogLevel,
" sz2=", call->mszCards, call->cBytes, TRUE);
854 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, call->cReaders);
855 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
856 WLog_Print(log, g_LogLevel,
"}");
859static void smartcard_trace_list_readers_return(wLog* log,
const ListReaders_Return* ret,
864 if (!WLog_IsLevelActive(log, g_LogLevel))
867 WLog_Print(log, g_LogLevel,
"ListReaders%s_Return {", unicode ?
"W" :
"A");
868 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
869 SCardGetErrorString(ret->ReturnCode),
870 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
872 if (ret->ReturnCode != SCARD_S_SUCCESS)
874 WLog_Print(log, g_LogLevel,
"}");
878 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
880 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
881 WLog_Print(log, g_LogLevel,
"}");
890 if (!WLog_IsLevelActive(log, g_LogLevel))
893 WLog_Print(log, g_LogLevel,
"GetStatusChange%s_Return {", unicode ?
"W" :
"A");
894 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
895 SCardGetErrorString(ret->ReturnCode),
896 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
897 WLog_Print(log, g_LogLevel,
" cReaders: %" PRIu32
"", ret->cReaders);
899 dump_reader_states_return(log, ret->rgReaderStates, ret->cReaders);
901 if (!ret->rgReaderStates && (ret->cReaders > 0))
903 WLog_Print(log, g_LogLevel,
" [INVALID STATE] rgReaderStates=nullptr, cReaders=%" PRIu32,
906 else if (ret->ReturnCode != SCARD_S_SUCCESS)
908 WLog_Print(log, g_LogLevel,
" [INVALID RETURN] rgReaderStates, cReaders=%" PRIu32,
913 for (UINT32 index = 0; index < ret->cReaders; index++)
916 char* szCurrentState = SCardGetReaderStateString(rgReaderState->dwCurrentState);
917 char* szEventState = SCardGetReaderStateString(rgReaderState->dwEventState);
918 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")",
919 index, szCurrentState, rgReaderState->dwCurrentState);
920 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")",
921 index, szEventState, rgReaderState->dwEventState);
922 smartcard_dump_array(
923 log, g_LogLevel,
" [%" PRIu32
"]: cbAtr: %" PRIu32
" rgbAtr: ",
"",
924 rgReaderState->rgbAtr, rgReaderState->cbAtr, index, rgReaderState->cbAtr);
925 free(szCurrentState);
930 WLog_Print(log, g_LogLevel,
"}");
933static void smartcard_trace_context_and_two_strings_a_call(wLog* log,
938 if (!WLog_IsLevelActive(log, g_LogLevel))
941 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
942 smartcard_log_context(log, &call->handles.hContext);
943 WLog_Print(log, g_LogLevel,
" sz1=%s", call->sz1);
944 WLog_Print(log, g_LogLevel,
" sz2=%s", call->sz2);
945 WLog_Print(log, g_LogLevel,
"}");
948static void smartcard_trace_context_and_two_strings_w_call(wLog* log,
952 char sz1[1024] = WINPR_C_ARRAY_INIT;
953 char sz2[1024] = WINPR_C_ARRAY_INIT;
955 if (!WLog_IsLevelActive(log, g_LogLevel))
958 (void)ConvertWCharToUtf8(call->sz1, sz1, ARRAYSIZE(sz1));
960 (void)ConvertWCharToUtf8(call->sz2, sz2, ARRAYSIZE(sz2));
962 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
963 smartcard_log_context(log, &call->handles.hContext);
964 WLog_Print(log, g_LogLevel,
" sz1=%s", sz1);
965 WLog_Print(log, g_LogLevel,
" sz2=%s", sz2);
966 WLog_Print(log, g_LogLevel,
"}");
973 if (!WLog_IsLevelActive(log, g_LogLevel))
976 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Call {");
977 smartcard_log_context(log, &call->handles.hContext);
978 smartcard_log_redir_handle(log, &call->handles.hCard);
980 WLog_Print(log, g_LogLevel,
"}");
983static void smartcard_trace_write_cache_a_call(wLog* log,
const WriteCacheA_Call* call)
987 if (!WLog_IsLevelActive(log, g_LogLevel))
990 WLog_Print(log, g_LogLevel,
"WriteCacheA_Call {");
992 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
994 smartcard_log_context(log, &call->Common.handles.hContext);
995 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
997 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
998 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
999 smartcard_dump_array(log, g_LogLevel,
" pbData=",
"", call->Common.pbData,
1000 call->Common.cbDataLen);
1001 WLog_Print(log, g_LogLevel,
"}");
1004static void smartcard_trace_write_cache_w_call(wLog* log,
const WriteCacheW_Call* call)
1007 char tmp[1024] = WINPR_C_ARRAY_INIT;
1009 if (!WLog_IsLevelActive(log, g_LogLevel))
1012 WLog_Print(log, g_LogLevel,
"WriteCacheW_Call {");
1014 if (call->szLookupName)
1015 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
1016 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
1018 smartcard_log_context(log, &call->Common.handles.hContext);
1019 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1021 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1022 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1023 smartcard_dump_array(log, g_LogLevel,
" pbData=",
"", call->Common.pbData,
1024 call->Common.cbDataLen);
1025 WLog_Print(log, g_LogLevel,
"}");
1028static void smartcard_trace_read_cache_a_call(wLog* log,
const ReadCacheA_Call* call)
1032 if (!WLog_IsLevelActive(log, g_LogLevel))
1035 WLog_Print(log, g_LogLevel,
"ReadCacheA_Call {");
1037 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
1038 smartcard_log_context(log, &call->Common.handles.hContext);
1039 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1041 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1042 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1043 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1045 WLog_Print(log, g_LogLevel,
"}");
1048static void smartcard_trace_read_cache_w_call(wLog* log,
const ReadCacheW_Call* call)
1051 char tmp[1024] = WINPR_C_ARRAY_INIT;
1053 if (!WLog_IsLevelActive(log, g_LogLevel))
1056 WLog_Print(log, g_LogLevel,
"ReadCacheW_Call {");
1057 if (call->szLookupName)
1058 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
1059 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
1061 smartcard_log_context(log, &call->Common.handles.hContext);
1062 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1064 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1065 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1066 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1068 WLog_Print(log, g_LogLevel,
"}");
1071static void smartcard_trace_transmit_call(wLog* log,
const Transmit_Call* call)
1074 UINT32 cbExtraBytes = 0;
1075 BYTE* pbExtraBytes =
nullptr;
1077 if (!WLog_IsLevelActive(log, g_LogLevel))
1080 WLog_Print(log, g_LogLevel,
"Transmit_Call {");
1081 smartcard_log_context(log, &call->handles.hContext);
1082 smartcard_log_redir_handle(log, &call->handles.hCard);
1084 if (call->pioSendPci)
1086 cbExtraBytes = (UINT32)(call->pioSendPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1088 WLog_Print(log, g_LogLevel,
"pioSendPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1089 call->pioSendPci->dwProtocol, cbExtraBytes);
1093 smartcard_dump_array(log, g_LogLevel,
"pbExtraBytes: ",
"", pbExtraBytes, cbExtraBytes);
1098 WLog_Print(log, g_LogLevel,
"pioSendPci: null");
1101 WLog_Print(log, g_LogLevel,
"cbSendLength: %" PRIu32
"", call->cbSendLength);
1103 if (call->pbSendBuffer)
1105 smartcard_dump_array(log, g_LogLevel,
"pbSendBuffer: ",
"", call->pbSendBuffer,
1106 call->cbSendLength);
1110 WLog_Print(log, g_LogLevel,
"pbSendBuffer: null");
1113 if (call->pioRecvPci)
1115 cbExtraBytes = (UINT32)(call->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1117 WLog_Print(log, g_LogLevel,
"pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1118 call->pioRecvPci->dwProtocol, cbExtraBytes);
1122 smartcard_dump_array(log, g_LogLevel,
"pbExtraBytes: ",
"", pbExtraBytes, cbExtraBytes);
1127 WLog_Print(log, g_LogLevel,
"pioRecvPci: null");
1130 WLog_Print(log, g_LogLevel,
"fpbRecvBufferIsNULL: %" PRId32
" cbRecvLength: %" PRIu32
"",
1131 call->fpbRecvBufferIsNULL, call->cbRecvLength);
1132 WLog_Print(log, g_LogLevel,
"}");
1135static void smartcard_trace_locate_cards_by_atr_w_call(wLog* log,
1140 if (!WLog_IsLevelActive(log, g_LogLevel))
1143 WLog_Print(log, g_LogLevel,
"LocateCardsByATRW_Call {");
1144 smartcard_log_context(log, &call->handles.hContext);
1146 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
1148 WLog_Print(log, g_LogLevel,
"}");
1151static void smartcard_trace_transmit_return(wLog* log,
const Transmit_Return* ret)
1154 UINT32 cbExtraBytes = 0;
1155 BYTE* pbExtraBytes =
nullptr;
1157 if (!WLog_IsLevelActive(log, g_LogLevel))
1160 WLog_Print(log, g_LogLevel,
"Transmit_Return {");
1161 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1162 SCardGetErrorString(ret->ReturnCode),
1163 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1165 if (ret->pioRecvPci)
1167 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1169 WLog_Print(log, g_LogLevel,
1170 " pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1171 ret->pioRecvPci->dwProtocol, cbExtraBytes);
1175 smartcard_dump_array(log, g_LogLevel,
" pbExtraBytes: ",
"", pbExtraBytes,
1181 WLog_Print(log, g_LogLevel,
" pioRecvPci: null");
1184 WLog_Print(log, g_LogLevel,
" cbRecvLength: %" PRIu32
"", ret->cbRecvLength);
1186 if (ret->pbRecvBuffer)
1188 smartcard_dump_array(log, g_LogLevel,
" pbRecvBuffer: ",
"", ret->pbRecvBuffer,
1193 WLog_Print(log, g_LogLevel,
" pbRecvBuffer: null");
1196 WLog_Print(log, g_LogLevel,
"}");
1199static void smartcard_trace_control_return(wLog* log,
const Control_Return* ret)
1203 if (!WLog_IsLevelActive(log, g_LogLevel))
1206 WLog_Print(log, g_LogLevel,
"Control_Return {");
1207 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1208 SCardGetErrorString(ret->ReturnCode),
1209 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1210 WLog_Print(log, g_LogLevel,
" cbOutBufferSize: %" PRIu32
"", ret->cbOutBufferSize);
1212 if (ret->pvOutBuffer)
1214 smartcard_dump_array(log, g_LogLevel,
"pvOutBuffer: ",
"", ret->pvOutBuffer,
1215 ret->cbOutBufferSize);
1219 WLog_Print(log, g_LogLevel,
"pvOutBuffer: null");
1222 WLog_Print(log, g_LogLevel,
"}");
1225static void smartcard_trace_control_call(wLog* log,
const Control_Call* call)
1229 if (!WLog_IsLevelActive(log, g_LogLevel))
1232 WLog_Print(log, g_LogLevel,
"Control_Call {");
1233 smartcard_log_context(log, &call->handles.hContext);
1234 smartcard_log_redir_handle(log, &call->handles.hCard);
1236 WLog_Print(log, g_LogLevel,
1237 "dwControlCode: 0x%08" PRIX32
" cbInBufferSize: %" PRIu32
1238 " fpvOutBufferIsNULL: %" PRId32
" cbOutBufferSize: %" PRIu32
"",
1239 call->dwControlCode, call->cbInBufferSize, call->fpvOutBufferIsNULL,
1240 call->cbOutBufferSize);
1242 if (call->pvInBuffer)
1244 smartcard_dump_array(log, WLOG_DEBUG,
"pbInBuffer: ",
"", call->pvInBuffer,
1245 call->cbInBufferSize);
1249 WLog_Print(log, g_LogLevel,
"pvInBuffer: null");
1252 WLog_Print(log, g_LogLevel,
"}");
1255static void smartcard_trace_set_attrib_call(wLog* log,
const SetAttrib_Call* call)
1259 if (!WLog_IsLevelActive(log, g_LogLevel))
1262 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1263 smartcard_log_context(log, &call->handles.hContext);
1264 smartcard_log_redir_handle(log, &call->handles.hCard);
1265 WLog_Print(log, g_LogLevel,
"dwAttrId: 0x%08" PRIX32, call->dwAttrId);
1266 WLog_Print(log, g_LogLevel,
"cbAttrLen: 0x%08" PRIx32, call->cbAttrLen);
1267 smartcard_dump_array(log, g_LogLevel,
"pbAttr: ",
"", call->pbAttr, call->cbAttrLen);
1268 WLog_Print(log, g_LogLevel,
"}");
1271static void smartcard_trace_get_attrib_return(wLog* log,
const GetAttrib_Return* ret,
1276 if (!WLog_IsLevelActive(log, g_LogLevel))
1279 WLog_Print(log, g_LogLevel,
"GetAttrib_Return {");
1280 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1281 SCardGetErrorString(ret->ReturnCode),
1282 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1283 WLog_Print(log, g_LogLevel,
" dwAttrId: %s (0x%08" PRIX32
") cbAttrLen: 0x%08" PRIX32
"",
1284 SCardGetAttributeString(dwAttrId), dwAttrId, ret->cbAttrLen);
1285 smartcard_dump_array(log, g_LogLevel,
" ",
"", ret->pbAttr, ret->cbAttrLen);
1287 WLog_Print(log, g_LogLevel,
"}");
1290static void smartcard_trace_get_attrib_call(wLog* log,
const GetAttrib_Call* call)
1294 if (!WLog_IsLevelActive(log, g_LogLevel))
1297 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1298 smartcard_log_context(log, &call->handles.hContext);
1299 smartcard_log_redir_handle(log, &call->handles.hCard);
1301 WLog_Print(log, g_LogLevel,
1302 "dwAttrId: %s (0x%08" PRIX32
") fpbAttrIsNULL: %" PRId32
" cbAttrLen: 0x%08" PRIX32
1304 SCardGetAttributeString(call->dwAttrId), call->dwAttrId, call->fpbAttrIsNULL,
1306 WLog_Print(log, g_LogLevel,
"}");
1309static void smartcard_trace_status_call(wLog* log,
const Status_Call* call, BOOL unicode)
1313 if (!WLog_IsLevelActive(log, g_LogLevel))
1316 WLog_Print(log, g_LogLevel,
"Status%s_Call {", unicode ?
"W" :
"A");
1317 smartcard_log_context(log, &call->handles.hContext);
1318 smartcard_log_redir_handle(log, &call->handles.hCard);
1320 WLog_Print(log, g_LogLevel,
1321 "fmszReaderNamesIsNULL: %" PRId32
" cchReaderLen: %" PRIu32
" cbAtrLen: %" PRIu32
"",
1322 call->fmszReaderNamesIsNULL, call->cchReaderLen, call->cbAtrLen);
1323 WLog_Print(log, g_LogLevel,
"}");
1326static void smartcard_trace_status_return(wLog* log,
const Status_Return* ret, BOOL unicode)
1329 char* mszReaderNamesA =
nullptr;
1332 if (!WLog_IsLevelActive(log, g_LogLevel))
1334 cBytes = ret->cBytes;
1335 if (ret->ReturnCode != SCARD_S_SUCCESS)
1337 if (cBytes == SCARD_AUTOALLOCATE)
1339 mszReaderNamesA = smartcard_convert_string_list(ret->mszReaderNames, cBytes, unicode);
1341 WLog_Print(log, g_LogLevel,
"Status%s_Return {", unicode ?
"W" :
"A");
1342 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1343 SCardGetErrorString(ret->ReturnCode),
1344 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1345 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
") dwProtocol: %s (0x%08" PRIX32
")",
1346 SCardGetCardStateString(ret->dwState), ret->dwState,
1347 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1349 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" mszReaderNames: %s", ret->cBytes,
1352 smartcard_dump_array(log, g_LogLevel,
" cbAtrLen: %" PRIu32
" pbAtr: ",
"", ret->pbAtr,
1353 ret->cbAtrLen, ret->cbAtrLen);
1354 WLog_Print(log, g_LogLevel,
"}");
1355 free(mszReaderNamesA);
1358static void smartcard_trace_state_return(wLog* log,
const State_Return* ret)
1361 char* state =
nullptr;
1363 if (!WLog_IsLevelActive(log, g_LogLevel))
1366 state = SCardGetReaderStateString(ret->dwState);
1367 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1368 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1369 SCardGetErrorString(ret->ReturnCode),
1370 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1371 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
")", state, ret->dwState);
1372 WLog_Print(log, g_LogLevel,
" dwProtocol: %s (0x%08" PRIX32
")",
1373 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1374 WLog_Print(log, g_LogLevel,
" cbAtrLen: (0x%08" PRIX32
")", ret->cbAtrLen);
1375 smartcard_dump_array(log, g_LogLevel,
" rgAtr: ",
"", ret->rgAtr,
sizeof(ret->rgAtr));
1376 WLog_Print(log, g_LogLevel,
"}");
1380static void smartcard_trace_reconnect_return(wLog* log,
const Reconnect_Return* ret)
1384 if (!WLog_IsLevelActive(log, g_LogLevel))
1387 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1388 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1389 SCardGetErrorString(ret->ReturnCode),
1390 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1391 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1392 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1393 WLog_Print(log, g_LogLevel,
"}");
1396static void smartcard_trace_connect_a_call(wLog* log,
const ConnectA_Call* call)
1400 if (!WLog_IsLevelActive(log, g_LogLevel))
1403 WLog_Print(log, g_LogLevel,
"ConnectA_Call {");
1404 smartcard_log_context(log, &call->Common.handles.hContext);
1406 WLog_Print(log, g_LogLevel,
1407 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1408 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1409 call->szReader, SCardGetShareModeString(call->Common.dwShareMode),
1410 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1411 call->Common.dwPreferredProtocols);
1412 WLog_Print(log, g_LogLevel,
"}");
1415static void smartcard_trace_connect_w_call(wLog* log,
const ConnectW_Call* call)
1418 char szReaderA[1024] = WINPR_C_ARRAY_INIT;
1420 if (!WLog_IsLevelActive(log, g_LogLevel))
1424 (void)ConvertWCharToUtf8(call->szReader, szReaderA, ARRAYSIZE(szReaderA));
1425 WLog_Print(log, g_LogLevel,
"ConnectW_Call {");
1426 smartcard_log_context(log, &call->Common.handles.hContext);
1428 WLog_Print(log, g_LogLevel,
1429 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1430 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1431 szReaderA, SCardGetShareModeString(call->Common.dwShareMode),
1432 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1433 call->Common.dwPreferredProtocols);
1434 WLog_Print(log, g_LogLevel,
"}");
1437static void smartcard_trace_hcard_and_disposition_call(wLog* log,
1443 if (!WLog_IsLevelActive(log, g_LogLevel))
1446 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
1447 smartcard_log_context(log, &call->handles.hContext);
1448 smartcard_log_redir_handle(log, &call->handles.hCard);
1450 WLog_Print(log, g_LogLevel,
"dwDisposition: %s (0x%08" PRIX32
")",
1451 SCardGetDispositionString(call->dwDisposition), call->dwDisposition);
1452 WLog_Print(log, g_LogLevel,
"}");
1459 if (!WLog_IsLevelActive(log, g_LogLevel))
1462 WLog_Print(log, g_LogLevel,
"EstablishContext_Call {");
1463 WLog_Print(log, g_LogLevel,
"dwScope: %s (0x%08" PRIX32
")", SCardGetScopeString(call->dwScope),
1465 WLog_Print(log, g_LogLevel,
"}");
1472 if (!WLog_IsLevelActive(log, g_LogLevel))
1475 WLog_Print(log, g_LogLevel,
"EstablishContext_Return {");
1476 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1477 SCardGetErrorString(ret->ReturnCode),
1478 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1479 smartcard_log_context(log, &ret->hContext);
1481 WLog_Print(log, g_LogLevel,
"}");
1484void smartcard_trace_long_return(
const Long_Return* ret,
const char* name)
1486 wLog* log = scard_log();
1487 smartcard_trace_long_return_int(log, ret, name);
1490void smartcard_trace_long_return_int(wLog* log,
const Long_Return* ret,
const char* name)
1494 if (!WLog_IsLevelActive(log, g_LogLevel))
1497 WLog_Print(log, g_LogLevel,
"%s_Return {", name);
1498 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1499 SCardGetErrorString(ret->ReturnCode),
1500 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1501 WLog_Print(log, g_LogLevel,
"}");
1504static void smartcard_trace_connect_return(wLog* log,
const Connect_Return* ret)
1508 if (!WLog_IsLevelActive(log, g_LogLevel))
1511 WLog_Print(log, g_LogLevel,
"Connect_Return {");
1512 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1513 SCardGetErrorString(ret->ReturnCode),
1514 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1515 smartcard_log_context(log, &ret->hContext);
1516 smartcard_log_redir_handle(log, &ret->hCard);
1518 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1519 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1520 WLog_Print(log, g_LogLevel,
"}");
1523static void smartcard_trace_reconnect_call(wLog* log,
const Reconnect_Call* call)
1527 if (!WLog_IsLevelActive(log, g_LogLevel))
1530 WLog_Print(log, g_LogLevel,
"Reconnect_Call {");
1531 smartcard_log_context(log, &call->handles.hContext);
1532 smartcard_log_redir_handle(log, &call->handles.hCard);
1534 WLog_Print(log, g_LogLevel,
1535 "dwShareMode: %s (0x%08" PRIX32
") dwPreferredProtocols: %s (0x%08" PRIX32
1536 ") dwInitialization: %s (0x%08" PRIX32
")",
1537 SCardGetShareModeString(call->dwShareMode), call->dwShareMode,
1538 SCardGetProtocolString(call->dwPreferredProtocols), call->dwPreferredProtocols,
1539 SCardGetDispositionString(call->dwInitialization), call->dwInitialization);
1540 WLog_Print(log, g_LogLevel,
"}");
1547 if (!WLog_IsLevelActive(log, g_LogLevel))
1550 WLog_Print(log, g_LogLevel,
"GetDeviceTypeId_Return {");
1551 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1552 SCardGetErrorString(ret->ReturnCode),
1553 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1554 WLog_Print(log, g_LogLevel,
" dwDeviceId=%08" PRIx32, ret->dwDeviceId);
1556 WLog_Print(log, g_LogLevel,
"}");
1559static LONG smartcard_unpack_common_context_and_string_a(wLog* log,
wStream* s,
1561 CHAR** pszReaderName)
1564 UINT32 pbContextNdrPtr = 0;
1565 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1566 if (status != SCARD_S_SUCCESS)
1569 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
1570 return ERROR_INVALID_DATA;
1572 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1573 if (status != SCARD_S_SUCCESS)
1576 status = smartcard_ndr_read_a(log, s, pszReaderName, NDR_PTR_FULL);
1577 if (status != SCARD_S_SUCCESS)
1580 smartcard_trace_context_and_string_call_a(log, __func__, phContext, *pszReaderName);
1581 return SCARD_S_SUCCESS;
1584static LONG smartcard_unpack_common_context_and_string_w(wLog* log,
wStream* s,
1586 WCHAR** pszReaderName)
1589 UINT32 pbContextNdrPtr = 0;
1591 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1592 if (status != SCARD_S_SUCCESS)
1595 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
1596 return ERROR_INVALID_DATA;
1598 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1599 if (status != SCARD_S_SUCCESS)
1602 status = smartcard_ndr_read_w(log, s, pszReaderName, NDR_PTR_FULL);
1603 if (status != SCARD_S_SUCCESS)
1606 smartcard_trace_context_and_string_call_w(log, __func__, phContext, *pszReaderName);
1607 return SCARD_S_SUCCESS;
1610LONG smartcard_unpack_common_type_header(
wStream* s)
1612 wLog* log = scard_log();
1615 UINT8 endianness = 0;
1616 UINT16 commonHeaderLength = 0;
1618 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1619 return STATUS_BUFFER_TOO_SMALL;
1622 Stream_Read_UINT8(s, version);
1623 Stream_Read_UINT8(s, endianness);
1624 Stream_Read_UINT16(s, commonHeaderLength);
1625 Stream_Read_UINT32(s, filler);
1629 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Version %" PRIu8
"", version);
1630 return STATUS_INVALID_PARAMETER;
1633 if (endianness != 0x10)
1635 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Endianness %" PRIu8
"",
1637 return STATUS_INVALID_PARAMETER;
1640 if (commonHeaderLength != 8)
1642 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader CommonHeaderLength %" PRIu16
"",
1643 commonHeaderLength);
1644 return STATUS_INVALID_PARAMETER;
1647 if (filler != 0xCCCCCCCC)
1649 WLog_Print(log, WLOG_WARN,
"Unexpected CommonTypeHeader Filler 0x%08" PRIX32
"", filler);
1650 return STATUS_INVALID_PARAMETER;
1653 return SCARD_S_SUCCESS;
1656void smartcard_pack_common_type_header(
wStream* s)
1658 Stream_Write_UINT8(s, 1);
1659 Stream_Write_UINT8(s, 0x10);
1660 Stream_Write_UINT16(s, 8);
1661 Stream_Write_UINT32(s, 0xCCCCCCCC);
1664LONG smartcard_unpack_private_type_header(
wStream* s)
1666 wLog* log = scard_log();
1668 UINT32 objectBufferLength = 0;
1670 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1671 return STATUS_BUFFER_TOO_SMALL;
1673 Stream_Read_UINT32(s, objectBufferLength);
1674 Stream_Read_UINT32(s, filler);
1676 if (filler != 0x00000000)
1678 WLog_Print(log, WLOG_WARN,
"Unexpected PrivateTypeHeader Filler 0x%08" PRIX32
"", filler);
1679 return STATUS_INVALID_PARAMETER;
1682 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, objectBufferLength))
1683 return STATUS_INVALID_PARAMETER;
1685 return SCARD_S_SUCCESS;
1688void smartcard_pack_private_type_header(
wStream* s, UINT32 objectBufferLength)
1690 Stream_Write_UINT32(s, objectBufferLength);
1691 Stream_Write_UINT32(s, 0x00000000);
1694LONG smartcard_unpack_read_size_align(
wStream* s,
size_t size, UINT32 alignment)
1696 const size_t padsize = (size + alignment - 1) & ~(alignment - 1);
1697 const size_t pad = padsize - size;
1701 if (!Stream_SafeSeek(s, pad))
1708LONG smartcard_pack_write_size_align(
wStream* s,
size_t size, UINT32 alignment)
1710 const size_t padsize = (size + alignment - 1) & ~(alignment - 1);
1711 const size_t pad = padsize - size;
1715 if (!Stream_EnsureRemainingCapacity(s, pad))
1717 wLog* log = scard_log();
1718 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
1719 return SCARD_F_INTERNAL_ERROR;
1722 Stream_Zero(s, pad);
1725 return SCARD_S_SUCCESS;
1730 SCARDCONTEXT hContext = WINPR_C_ARRAY_INIT;
1732 WINPR_ASSERT(context);
1733 if ((context->cbContext !=
sizeof(ULONG_PTR)) && (context->cbContext != 0))
1735 wLog* log = scard_log();
1736 WLog_Print(log, WLOG_WARN,
1737 "REDIR_SCARDCONTEXT does not match native size: Actual: %" PRIu32
1738 ", Expected: %" PRIuz
"",
1739 context->cbContext,
sizeof(ULONG_PTR));
1743 if (context->cbContext)
1744 CopyMemory(&hContext, &(context->pbContext), context->cbContext);
1749void smartcard_scard_context_native_to_redir(
REDIR_SCARDCONTEXT* context, SCARDCONTEXT hContext)
1751 WINPR_ASSERT(context);
1753 context->cbContext =
sizeof(ULONG_PTR);
1754 CopyMemory(&(context->pbContext), &hContext, context->cbContext);
1759 SCARDHANDLE hCard = 0;
1761 WINPR_ASSERT(handle);
1762 if (handle->cbHandle == 0)
1765 if (handle->cbHandle !=
sizeof(ULONG_PTR))
1767 wLog* log = scard_log();
1768 WLog_Print(log, WLOG_WARN,
1769 "REDIR_SCARDHANDLE does not match native size: Actual: %" PRIu32
1770 ", Expected: %" PRIuz
"",
1771 handle->cbHandle,
sizeof(ULONG_PTR));
1775 if (handle->cbHandle)
1776 CopyMemory(&hCard, &(handle->pbHandle), handle->cbHandle);
1781void smartcard_scard_handle_native_to_redir(
REDIR_SCARDHANDLE* handle, SCARDHANDLE hCard)
1783 WINPR_ASSERT(handle);
1785 handle->cbHandle =
sizeof(ULONG_PTR);
1786 CopyMemory(&(handle->pbHandle), &hCard, handle->cbHandle);
1789#define smartcard_context_supported(log, size) \
1790 smartcard_context_supported_((log), (size), __FILE__, __func__, __LINE__)
1791static LONG smartcard_context_supported_(wLog* log, uint32_t size,
const char* file,
1792 const char* fkt,
size_t line)
1799 return SCARD_S_SUCCESS;
1802 const uint32_t level = WLOG_WARN;
1803 if (WLog_IsLevelActive(log, level))
1805 WLog_PrintTextMessage(log, level, line, file, fkt,
1806 "REDIR_SCARDCONTEXT length is not 0, 4 or 8: %" PRIu32
"",
1809 return STATUS_INVALID_PARAMETER;
1815 UINT32* index, UINT32* ppbContextNdrPtr,
1816 const char* file,
const char* function,
size_t line)
1818 UINT32 pbContextNdrPtr = 0;
1821 WINPR_ASSERT(context);
1825 if (!Stream_CheckAndLogRequiredLengthWLogEx(log, WLOG_WARN, s, 4, 1,
"%s(%s:%" PRIuz
")", file,
1827 return STATUS_BUFFER_TOO_SMALL;
1829 const LONG status = smartcard_context_supported_(log, context->cbContext, file, function, line);
1830 if (status != SCARD_S_SUCCESS)
1833 Stream_Read_UINT32(s, context->cbContext);
1835 if (!smartcard_ndr_pointer_read_(log, s, index, &pbContextNdrPtr, file, function, line))
1836 return ERROR_INVALID_DATA;
1838 if (((context->cbContext == 0) && pbContextNdrPtr) ||
1839 ((context->cbContext != 0) && !pbContextNdrPtr))
1841 WLog_Print(log, WLOG_WARN,
1842 "REDIR_SCARDCONTEXT cbContext (%" PRIu32
") pbContextNdrPtr (%" PRIu32
1844 context->cbContext, pbContextNdrPtr);
1845 return STATUS_INVALID_PARAMETER;
1848 if (!Stream_CheckAndLogRequiredLengthWLogEx(log, WLOG_WARN, s, context->cbContext, 1,
1849 "%s(%s:%" PRIuz
")", file, function, line))
1850 return STATUS_INVALID_PARAMETER;
1852 *ppbContextNdrPtr = pbContextNdrPtr;
1853 return SCARD_S_SUCCESS;
1856LONG smartcard_pack_redir_scard_context(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1859 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
1861 WINPR_ASSERT(context);
1862 if (context->cbContext != 0)
1864 Stream_Write_UINT32(s, context->cbContext);
1865 Stream_Write_UINT32(s, pbContextNdrPtr);
1866 *index = *index + 1;
1871 return SCARD_S_SUCCESS;
1874LONG smartcard_unpack_redir_scard_context_ref(wLog* log,
wStream* s,
1875 WINPR_ATTR_UNUSED UINT32 pbContextNdrPtr,
1880 WINPR_ASSERT(context);
1881 if (context->cbContext == 0)
1882 return SCARD_S_SUCCESS;
1884 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1885 return STATUS_BUFFER_TOO_SMALL;
1887 Stream_Read_UINT32(s, length);
1889 if (length != context->cbContext)
1891 WLog_Print(log, WLOG_WARN,
1892 "REDIR_SCARDCONTEXT length (%" PRIu32
") cbContext (%" PRIu32
") mismatch",
1893 length, context->cbContext);
1894 return STATUS_INVALID_PARAMETER;
1897 const LONG status = smartcard_context_supported(log, context->cbContext);
1898 if (status != SCARD_S_SUCCESS)
1901 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, context->cbContext))
1902 return STATUS_BUFFER_TOO_SMALL;
1904 if (context->cbContext)
1905 Stream_Read(s, &(context->pbContext), context->cbContext);
1907 ZeroMemory(&(context->pbContext),
sizeof(context->pbContext));
1909 return SCARD_S_SUCCESS;
1912LONG smartcard_pack_redir_scard_context_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1915 WINPR_ASSERT(context);
1916 Stream_Write_UINT32(s, context->cbContext);
1918 if (context->cbContext)
1920 Stream_Write(s, &(context->pbContext), context->cbContext);
1923 return SCARD_S_SUCCESS;
1927 UINT32* index,
const char* file,
const char* function,
1930 WINPR_ASSERT(handle);
1933 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1934 return STATUS_BUFFER_TOO_SMALL;
1936 Stream_Read_UINT32(s, handle->cbHandle);
1938 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, handle->cbHandle))
1939 return STATUS_BUFFER_TOO_SMALL;
1941 if (!smartcard_ndr_pointer_read_(log, s, index,
nullptr, file, function, line))
1942 return ERROR_INVALID_DATA;
1944 return SCARD_S_SUCCESS;
1947LONG smartcard_pack_redir_scard_handle(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1950 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
1952 WINPR_ASSERT(handle);
1953 if (handle->cbHandle != 0)
1955 Stream_Write_UINT32(s, handle->cbHandle);
1956 Stream_Write_UINT32(s, pbContextNdrPtr);
1957 *index = *index + 1;
1961 return SCARD_S_SUCCESS;
1968 WINPR_ASSERT(handle);
1969 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1970 return STATUS_BUFFER_TOO_SMALL;
1972 Stream_Read_UINT32(s, length);
1974 if (length != handle->cbHandle)
1976 WLog_Print(log, WLOG_WARN,
1977 "REDIR_SCARDHANDLE length (%" PRIu32
") cbHandle (%" PRIu32
") mismatch", length,
1979 return STATUS_INVALID_PARAMETER;
1982 if ((handle->cbHandle != 4) && (handle->cbHandle != 8))
1984 WLog_Print(log, WLOG_WARN,
"REDIR_SCARDHANDLE length is not 4 or 8: %" PRIu32
"",
1986 return STATUS_INVALID_PARAMETER;
1989 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, handle->cbHandle))
1990 return STATUS_BUFFER_TOO_SMALL;
1992 if (handle->cbHandle)
1993 Stream_Read(s, &(handle->pbHandle), handle->cbHandle);
1995 return SCARD_S_SUCCESS;
1998LONG smartcard_pack_redir_scard_handle_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
2001 WINPR_ASSERT(handle);
2002 Stream_Write_UINT32(s, handle->cbHandle);
2004 if (handle->cbHandle)
2005 Stream_Write(s, &(handle->pbHandle), handle->cbHandle);
2007 return SCARD_S_SUCCESS;
2013 wLog* log = scard_log();
2015 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2016 return STATUS_BUFFER_TOO_SMALL;
2018 Stream_Read_UINT32(s, call->dwScope);
2019 smartcard_trace_establish_context_call(log, call);
2020 return SCARD_S_SUCCESS;
2026 wLog* log = scard_log();
2030 smartcard_trace_establish_context_return(log, ret);
2031 if (ret->ReturnCode != SCARD_S_SUCCESS)
2032 return ret->ReturnCode;
2034 status = smartcard_pack_redir_scard_context(log, s, &(ret->hContext), &index);
2035 if (status != SCARD_S_SUCCESS)
2038 return smartcard_pack_redir_scard_context_ref(log, s, &(ret->hContext));
2044 UINT32 pbContextNdrPtr = 0;
2045 wLog* log = scard_log();
2048 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2050 if (status != SCARD_S_SUCCESS)
2053 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2054 &(call->handles.hContext));
2055 if (status != SCARD_S_SUCCESS)
2056 WLog_Print(log, WLOG_ERROR,
2057 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2060 smartcard_trace_context_call(log, call, name);
2067 UINT32 pbContextNdrPtr = 0;
2068 wLog* log = scard_log();
2071 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2074 if (status != SCARD_S_SUCCESS)
2077 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2078 return STATUS_BUFFER_TOO_SMALL;
2080 Stream_Read_INT32(s, call->fmszGroupsIsNULL);
2081 Stream_Read_UINT32(s, call->cchGroups);
2082 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2083 &(call->handles.hContext));
2085 if (status != SCARD_S_SUCCESS)
2088 smartcard_trace_list_reader_groups_call(log, call, unicode);
2089 return SCARD_S_SUCCESS;
2096 wLog* log = scard_log();
2098 DWORD cBytes = ret->cBytes;
2101 smartcard_trace_list_reader_groups_return(log, ret, unicode);
2102 if (ret->ReturnCode != SCARD_S_SUCCESS)
2104 if (cBytes == SCARD_AUTOALLOCATE)
2107 if (!Stream_EnsureRemainingCapacity(s, 4))
2108 return SCARD_E_NO_MEMORY;
2110 Stream_Write_UINT32(s, cBytes);
2111 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
2112 return SCARD_E_NO_MEMORY;
2114 status = smartcard_ndr_write(s, ret->msz, cBytes, 1, NDR_PTR_SIMPLE);
2115 if (status != SCARD_S_SUCCESS)
2117 return ret->ReturnCode;
2123 UINT32 mszGroupsNdrPtr = 0;
2124 UINT32 pbContextNdrPtr = 0;
2125 wLog* log = scard_log();
2128 call->mszGroups =
nullptr;
2130 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2132 if (status != SCARD_S_SUCCESS)
2135 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2136 return STATUS_BUFFER_TOO_SMALL;
2138 Stream_Read_UINT32(s, call->cBytes);
2139 if (!smartcard_ndr_pointer_read(log, s, &index, &mszGroupsNdrPtr))
2140 return ERROR_INVALID_DATA;
2142 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2143 return STATUS_BUFFER_TOO_SMALL;
2144 Stream_Read_INT32(s, call->fmszReadersIsNULL);
2145 Stream_Read_UINT32(s, call->cchReaders);
2147 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2148 &(call->handles.hContext));
2149 if (status != SCARD_S_SUCCESS)
2152 if (mszGroupsNdrPtr)
2154 status = smartcard_ndr_read(log, s, &call->mszGroups, call->cBytes, 1, NDR_PTR_SIMPLE);
2155 if (status != SCARD_S_SUCCESS)
2159 smartcard_trace_list_readers_call(log, call, unicode);
2160 return SCARD_S_SUCCESS;
2166 wLog* log = scard_log();
2169 UINT32 size = ret->cBytes;
2171 smartcard_trace_list_readers_return(log, ret, unicode);
2172 if (ret->ReturnCode != SCARD_S_SUCCESS)
2175 if (!Stream_EnsureRemainingCapacity(s, 4))
2177 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
2178 return SCARD_F_INTERNAL_ERROR;
2181 Stream_Write_UINT32(s, size);
2182 if (!smartcard_ndr_pointer_write(s, &index, size))
2183 return SCARD_E_NO_MEMORY;
2185 status = smartcard_ndr_write(s, ret->msz, size, 1, NDR_PTR_SIMPLE);
2186 if (status != SCARD_S_SUCCESS)
2188 return ret->ReturnCode;
2192 UINT32* index, UINT32* ppbContextNdrPtr)
2194 WINPR_ASSERT(common);
2195 LONG status = smartcard_unpack_redir_scard_context(log, s, &(common->handles.hContext), index,
2197 if (status != SCARD_S_SUCCESS)
2200 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2201 return STATUS_BUFFER_TOO_SMALL;
2203 Stream_Read_UINT32(s, common->dwShareMode);
2204 Stream_Read_UINT32(s, common->dwPreferredProtocols);
2205 return SCARD_S_SUCCESS;
2212 UINT32 pbContextNdrPtr = 0;
2215 wLog* log = scard_log();
2217 call->szReader =
nullptr;
2219 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
2220 return ERROR_INVALID_DATA;
2222 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2223 if (status != SCARD_S_SUCCESS)
2225 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2230 status = smartcard_ndr_read_a(log, s, &call->szReader, NDR_PTR_FULL);
2231 if (status != SCARD_S_SUCCESS)
2234 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2235 &(call->Common.handles.hContext));
2236 if (status != SCARD_S_SUCCESS)
2237 WLog_Print(log, WLOG_ERROR,
2238 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2241 smartcard_trace_connect_a_call(log, call);
2249 UINT32 pbContextNdrPtr = 0;
2252 wLog* log = scard_log();
2253 call->szReader =
nullptr;
2255 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
2256 return ERROR_INVALID_DATA;
2258 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2259 if (status != SCARD_S_SUCCESS)
2261 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2266 status = smartcard_ndr_read_w(log, s, &call->szReader, NDR_PTR_FULL);
2267 if (status != SCARD_S_SUCCESS)
2270 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2271 &(call->Common.handles.hContext));
2272 if (status != SCARD_S_SUCCESS)
2273 WLog_Print(log, WLOG_ERROR,
2274 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2277 smartcard_trace_connect_w_call(log, call);
2287 wLog* log = scard_log();
2288 smartcard_trace_connect_return(log, ret);
2290 status = smartcard_pack_redir_scard_context(log, s, &ret->hContext, &index);
2291 if (status != SCARD_S_SUCCESS)
2294 status = smartcard_pack_redir_scard_handle(log, s, &ret->hCard, &index);
2295 if (status != SCARD_S_SUCCESS)
2298 if (!Stream_EnsureRemainingCapacity(s, 4))
2299 return SCARD_E_NO_MEMORY;
2301 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2302 status = smartcard_pack_redir_scard_context_ref(log, s, &ret->hContext);
2303 if (status != SCARD_S_SUCCESS)
2305 return smartcard_pack_redir_scard_handle_ref(log, s, &(ret->hCard));
2311 UINT32 pbContextNdrPtr = 0;
2314 wLog* log = scard_log();
2315 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2317 if (status != SCARD_S_SUCCESS)
2320 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2321 if (status != SCARD_S_SUCCESS)
2324 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2325 return STATUS_BUFFER_TOO_SMALL;
2327 Stream_Read_UINT32(s, call->dwShareMode);
2328 Stream_Read_UINT32(s, call->dwPreferredProtocols);
2329 Stream_Read_UINT32(s, call->dwInitialization);
2331 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2332 &(call->handles.hContext));
2333 if (status != SCARD_S_SUCCESS)
2335 WLog_Print(log, WLOG_ERROR,
2336 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2341 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2342 if (status != SCARD_S_SUCCESS)
2343 WLog_Print(log, WLOG_ERROR,
2344 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
2346 smartcard_trace_reconnect_call(log, call);
2353 wLog* log = scard_log();
2354 smartcard_trace_reconnect_return(log, ret);
2356 if (!Stream_EnsureRemainingCapacity(s, 4))
2357 return SCARD_E_NO_MEMORY;
2358 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2359 return ret->ReturnCode;
2366 UINT32 pbContextNdrPtr = 0;
2369 wLog* log = scard_log();
2371 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2373 if (status != SCARD_S_SUCCESS)
2376 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2377 if (status != SCARD_S_SUCCESS)
2380 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2381 return STATUS_BUFFER_TOO_SMALL;
2383 Stream_Read_UINT32(s, call->dwDisposition);
2385 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2386 &(call->handles.hContext));
2387 if (status != SCARD_S_SUCCESS)
2390 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2391 if (status != SCARD_S_SUCCESS)
2394 smartcard_trace_hcard_and_disposition_call(log, call, name);
2402 if (!WLog_IsLevelActive(log, g_LogLevel))
2405 WLog_Print(log, g_LogLevel,
"GetStatusChangeA_Call {");
2406 smartcard_log_context(log, &call->handles.hContext);
2408 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
2411 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
2413 WLog_Print(log, g_LogLevel,
"}");
2417 UINT32 cReaders, UINT32* ptrIndex)
2419 LONG status = SCARD_E_NO_MEMORY;
2421 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2422 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2425 const UINT32 len = Stream_Get_UINT32(s);
2426 if (len != cReaders)
2428 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEA");
2434 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2435 if (!rgReaderStates || !states)
2437 status = ERROR_INVALID_DATA;
2439 for (UINT32 index = 0; index < cReaders; index++)
2441 UINT32 ptr = UINT32_MAX;
2444 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2447 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2453 states[index] = ptr != 0;
2454 Stream_Read_UINT32(s, readerState->dwCurrentState);
2455 Stream_Read_UINT32(s, readerState->dwEventState);
2456 Stream_Read_UINT32(s, readerState->cbAtr);
2457 Stream_Read(s, readerState->rgbAtr, 36);
2460 for (UINT32 index = 0; index < cReaders; index++)
2467 status = smartcard_ndr_read_a(log, s, &readerState->szReader, NDR_PTR_FULL);
2468 if (status != SCARD_S_SUCCESS)
2472 *ppcReaders = rgReaderStates;
2474 return SCARD_S_SUCCESS;
2478 for (UINT32 index = 0; index < cReaders; index++)
2481 free(readerState->szReader);
2484 free(rgReaderStates);
2490 UINT32 cReaders, UINT32* ptrIndex)
2492 LONG status = SCARD_E_NO_MEMORY;
2494 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2495 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2498 const UINT32 len = Stream_Get_UINT32(s);
2499 if (len != cReaders)
2501 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEW");
2507 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2509 if (!rgReaderStates || !states)
2512 status = ERROR_INVALID_DATA;
2513 for (UINT32 index = 0; index < cReaders; index++)
2515 UINT32 ptr = UINT32_MAX;
2518 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2521 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2527 states[index] = ptr != 0;
2528 Stream_Read_UINT32(s, readerState->dwCurrentState);
2529 Stream_Read_UINT32(s, readerState->dwEventState);
2530 Stream_Read_UINT32(s, readerState->cbAtr);
2531 Stream_Read(s, readerState->rgbAtr, 36);
2534 for (UINT32 index = 0; index < cReaders; index++)
2542 status = smartcard_ndr_read_w(log, s, &readerState->szReader, NDR_PTR_FULL);
2543 if (status != SCARD_S_SUCCESS)
2547 *ppcReaders = rgReaderStates;
2549 return SCARD_S_SUCCESS;
2553 for (UINT32 index = 0; index < cReaders; index++)
2556 free(readerState->szReader);
2559 free(rgReaderStates);
2572 UINT32 pbContextNdrPtr = 0;
2575 wLog* log = scard_log();
2577 call->rgReaderStates =
nullptr;
2579 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2581 if (status != SCARD_S_SUCCESS)
2584 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2585 return STATUS_BUFFER_TOO_SMALL;
2587 Stream_Read_UINT32(s, call->dwTimeOut);
2588 Stream_Read_UINT32(s, call->cReaders);
2589 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2590 return ERROR_INVALID_DATA;
2592 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2593 &(call->handles.hContext));
2594 if (status != SCARD_S_SUCCESS)
2600 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
2601 if (status != SCARD_S_SUCCESS)
2606 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2607 return SCARD_E_UNEXPECTED;
2610 smartcard_trace_get_status_change_a_call(log, call);
2611 return SCARD_S_SUCCESS;
2618 UINT32 pbContextNdrPtr = 0;
2621 wLog* log = scard_log();
2622 call->rgReaderStates =
nullptr;
2624 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2626 if (status != SCARD_S_SUCCESS)
2629 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2630 return STATUS_BUFFER_TOO_SMALL;
2632 Stream_Read_UINT32(s, call->dwTimeOut);
2633 Stream_Read_UINT32(s, call->cReaders);
2634 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2635 return ERROR_INVALID_DATA;
2637 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2638 &(call->handles.hContext));
2639 if (status != SCARD_S_SUCCESS)
2645 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
2646 if (status != SCARD_S_SUCCESS)
2651 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2652 return SCARD_E_UNEXPECTED;
2655 smartcard_trace_get_status_change_w_call(log, call);
2656 return SCARD_S_SUCCESS;
2663 wLog* log = scard_log();
2666 DWORD cReaders = ret->cReaders;
2669 smartcard_trace_get_status_change_return(log, ret, unicode);
2670 if (ret->ReturnCode != SCARD_S_SUCCESS)
2672 if (cReaders == SCARD_AUTOALLOCATE)
2675 if (!Stream_EnsureRemainingCapacity(s, 4))
2676 return SCARD_E_NO_MEMORY;
2678 Stream_Write_UINT32(s, cReaders);
2679 if (!smartcard_ndr_pointer_write(s, &index, cReaders))
2680 return SCARD_E_NO_MEMORY;
2681 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cReaders, NDR_PTR_SIMPLE);
2682 if (status != SCARD_S_SUCCESS)
2684 return ret->ReturnCode;
2690 UINT32 pbContextNdrPtr = 0;
2692 wLog* log = scard_log();
2695 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2697 if (status != SCARD_S_SUCCESS)
2700 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2701 if (status != SCARD_S_SUCCESS)
2704 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2705 return STATUS_BUFFER_TOO_SMALL;
2707 Stream_Read_INT32(s, call->fpbAtrIsNULL);
2708 Stream_Read_UINT32(s, call->cbAtrLen);
2710 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2711 &(call->handles.hContext));
2712 if (status != SCARD_S_SUCCESS)
2715 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2716 if (status != SCARD_S_SUCCESS)
2725 wLog* log = scard_log();
2727 DWORD cbAtrLen = ret->cbAtrLen;
2730 smartcard_trace_state_return(log, ret);
2731 if (ret->ReturnCode != SCARD_S_SUCCESS)
2733 if (cbAtrLen == SCARD_AUTOALLOCATE)
2736 Stream_Write_UINT32(s, ret->dwState);
2737 Stream_Write_UINT32(s, ret->dwProtocol);
2738 Stream_Write_UINT32(s, cbAtrLen);
2739 if (!smartcard_ndr_pointer_write(s, &index, cbAtrLen))
2740 return SCARD_E_NO_MEMORY;
2741 status = smartcard_ndr_write(s, ret->rgAtr, cbAtrLen, 1, NDR_PTR_SIMPLE);
2742 if (status != SCARD_S_SUCCESS)
2744 return ret->ReturnCode;
2750 UINT32 pbContextNdrPtr = 0;
2753 wLog* log = scard_log();
2755 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2757 if (status != SCARD_S_SUCCESS)
2760 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2761 if (status != SCARD_S_SUCCESS)
2764 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2765 return STATUS_BUFFER_TOO_SMALL;
2767 Stream_Read_INT32(s, call->fmszReaderNamesIsNULL);
2768 Stream_Read_UINT32(s, call->cchReaderLen);
2769 Stream_Read_UINT32(s, call->cbAtrLen);
2771 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2772 &(call->handles.hContext));
2773 if (status != SCARD_S_SUCCESS)
2776 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2777 if (status != SCARD_S_SUCCESS)
2780 smartcard_trace_status_call(log, call, unicode);
2787 wLog* log = scard_log();
2791 DWORD cBytes = ret->cBytes;
2793 smartcard_trace_status_return(log, ret, unicode);
2794 if (ret->ReturnCode != SCARD_S_SUCCESS)
2796 if (cBytes == SCARD_AUTOALLOCATE)
2799 if (!Stream_EnsureRemainingCapacity(s, 4))
2800 return SCARD_F_INTERNAL_ERROR;
2802 Stream_Write_UINT32(s, cBytes);
2803 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
2804 return SCARD_E_NO_MEMORY;
2806 if (!Stream_EnsureRemainingCapacity(s, 44))
2807 return SCARD_F_INTERNAL_ERROR;
2809 Stream_Write_UINT32(s, ret->dwState);
2810 Stream_Write_UINT32(s, ret->dwProtocol);
2811 Stream_Write(s, ret->pbAtr,
sizeof(ret->pbAtr));
2812 Stream_Write_UINT32(s, ret->cbAtrLen);
2813 status = smartcard_ndr_write(s, ret->mszReaderNames, cBytes, 1, NDR_PTR_SIMPLE);
2814 if (status != SCARD_S_SUCCESS)
2816 return ret->ReturnCode;
2822 wLog* log = scard_log();
2824 UINT32 pbContextNdrPtr = 0;
2826 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2828 if (status != SCARD_S_SUCCESS)
2831 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2832 if (status != SCARD_S_SUCCESS)
2835 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2836 return STATUS_BUFFER_TOO_SMALL;
2838 Stream_Read_UINT32(s, call->dwAttrId);
2839 Stream_Read_INT32(s, call->fpbAttrIsNULL);
2840 Stream_Read_UINT32(s, call->cbAttrLen);
2842 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2843 &(call->handles.hContext));
2844 if (status != SCARD_S_SUCCESS)
2847 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2848 if (status != SCARD_S_SUCCESS)
2851 smartcard_trace_get_attrib_call(log, call);
2856 DWORD cbAttrCallLen)
2859 wLog* log = scard_log();
2861 DWORD cbAttrLen = 0;
2863 smartcard_trace_get_attrib_return(log, ret, dwAttrId);
2865 if (!Stream_EnsureRemainingCapacity(s, 4))
2866 return SCARD_F_INTERNAL_ERROR;
2868 cbAttrLen = ret->cbAttrLen;
2869 if (ret->ReturnCode != SCARD_S_SUCCESS)
2871 if (cbAttrLen == SCARD_AUTOALLOCATE)
2876 if (cbAttrCallLen < cbAttrLen)
2877 cbAttrLen = cbAttrCallLen;
2879 Stream_Write_UINT32(s, cbAttrLen);
2880 if (!smartcard_ndr_pointer_write(s, &index, cbAttrLen))
2881 return SCARD_E_NO_MEMORY;
2883 status = smartcard_ndr_write(s, ret->pbAttr, cbAttrLen, 1, NDR_PTR_SIMPLE);
2884 if (status != SCARD_S_SUCCESS)
2886 return ret->ReturnCode;
2892 wLog* log = scard_log();
2895 UINT32 pvInBufferNdrPtr = 0;
2896 UINT32 pbContextNdrPtr = 0;
2898 call->pvInBuffer =
nullptr;
2900 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2902 if (status != SCARD_S_SUCCESS)
2905 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2906 if (status != SCARD_S_SUCCESS)
2909 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 20))
2910 return STATUS_BUFFER_TOO_SMALL;
2912 Stream_Read_UINT32(s, call->dwControlCode);
2913 Stream_Read_UINT32(s, call->cbInBufferSize);
2914 if (!smartcard_ndr_pointer_read(log, s, &index,
2916 return ERROR_INVALID_DATA;
2917 Stream_Read_INT32(s, call->fpvOutBufferIsNULL);
2918 Stream_Read_UINT32(s, call->cbOutBufferSize);
2920 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2921 &(call->handles.hContext));
2922 if (status != SCARD_S_SUCCESS)
2925 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2926 if (status != SCARD_S_SUCCESS)
2929 if (pvInBufferNdrPtr)
2932 smartcard_ndr_read(log, s, &call->pvInBuffer, call->cbInBufferSize, 1, NDR_PTR_SIMPLE);
2933 if (status != SCARD_S_SUCCESS)
2937 smartcard_trace_control_call(log, call);
2938 return SCARD_S_SUCCESS;
2944 wLog* log = scard_log();
2947 DWORD cbDataLen = ret->cbOutBufferSize;
2950 smartcard_trace_control_return(log, ret);
2951 if (ret->ReturnCode != SCARD_S_SUCCESS)
2953 if (cbDataLen == SCARD_AUTOALLOCATE)
2956 if (!Stream_EnsureRemainingCapacity(s, 4))
2957 return SCARD_F_INTERNAL_ERROR;
2959 Stream_Write_UINT32(s, cbDataLen);
2960 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
2961 return SCARD_E_NO_MEMORY;
2963 status = smartcard_ndr_write(s, ret->pvOutBuffer, cbDataLen, 1, NDR_PTR_SIMPLE);
2964 if (status != SCARD_S_SUCCESS)
2966 return ret->ReturnCode;
2972 BYTE* pbExtraBytes =
nullptr;
2973 UINT32 pbExtraBytesNdrPtr = 0;
2974 UINT32 pbSendBufferNdrPtr = 0;
2975 UINT32 pioRecvPciNdrPtr = 0;
2979 UINT32 pbContextNdrPtr = 0;
2982 wLog* log = scard_log();
2984 call->pioSendPci =
nullptr;
2985 call->pioRecvPci =
nullptr;
2986 call->pbSendBuffer =
nullptr;
2988 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2990 if (status != SCARD_S_SUCCESS)
2993 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2994 if (status != SCARD_S_SUCCESS)
2997 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 32))
2998 return STATUS_BUFFER_TOO_SMALL;
3000 Stream_Read_UINT32(s, ioSendPci.dwProtocol);
3001 Stream_Read_UINT32(s, ioSendPci.cbExtraBytes);
3002 if (!smartcard_ndr_pointer_read(log, s, &index,
3003 &pbExtraBytesNdrPtr))
3004 return ERROR_INVALID_DATA;
3006 Stream_Read_UINT32(s, call->cbSendLength);
3007 if (!smartcard_ndr_pointer_read(log, s, &index,
3008 &pbSendBufferNdrPtr))
3009 return ERROR_INVALID_DATA;
3011 if (!smartcard_ndr_pointer_read(log, s, &index,
3013 return ERROR_INVALID_DATA;
3015 Stream_Read_INT32(s, call->fpbRecvBufferIsNULL);
3016 Stream_Read_UINT32(s, call->cbRecvLength);
3018 if (ioSendPci.cbExtraBytes > 1024)
3020 WLog_Print(log, WLOG_WARN,
3021 "Transmit_Call ioSendPci.cbExtraBytes is out of bounds: %" PRIu32
" (max: 1024)",
3022 ioSendPci.cbExtraBytes);
3023 return STATUS_INVALID_PARAMETER;
3026 if (call->cbSendLength > 66560)
3028 WLog_Print(log, WLOG_WARN,
3029 "Transmit_Call cbSendLength is out of bounds: %" PRIu32
" (max: 66560)",
3030 ioSendPci.cbExtraBytes);
3031 return STATUS_INVALID_PARAMETER;
3034 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3035 &(call->handles.hContext));
3036 if (status != SCARD_S_SUCCESS)
3039 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3040 if (status != SCARD_S_SUCCESS)
3043 if (ioSendPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3047 "Transmit_Call ioSendPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3048 return STATUS_INVALID_PARAMETER;
3051 if (pbExtraBytesNdrPtr)
3054 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3055 return STATUS_BUFFER_TOO_SMALL;
3057 Stream_Read_UINT32(s, length);
3059 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioSendPci.cbExtraBytes))
3060 return STATUS_BUFFER_TOO_SMALL;
3062 ioSendPci.pbExtraBytes = Stream_Pointer(s);
3066 if (!call->pioSendPci)
3068 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3069 return STATUS_NO_MEMORY;
3072 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3073 call->pioSendPci->cbPciLength = (DWORD)(ioSendPci.cbExtraBytes +
sizeof(
SCARD_IO_REQUEST));
3075 Stream_Read(s, pbExtraBytes, ioSendPci.cbExtraBytes);
3076 if (smartcard_unpack_read_size_align(s, ioSendPci.cbExtraBytes, 4) < 0)
3077 return STATUS_INVALID_PARAMETER;
3083 if (!call->pioSendPci)
3085 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3086 return STATUS_NO_MEMORY;
3089 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3093 if (pbSendBufferNdrPtr)
3096 smartcard_ndr_read(log, s, &call->pbSendBuffer, call->cbSendLength, 1, NDR_PTR_SIMPLE);
3097 if (status != SCARD_S_SUCCESS)
3101 if (pioRecvPciNdrPtr)
3103 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3104 return STATUS_BUFFER_TOO_SMALL;
3106 Stream_Read_UINT32(s, ioRecvPci.dwProtocol);
3107 Stream_Read_UINT32(s, ioRecvPci.cbExtraBytes);
3108 if (!smartcard_ndr_pointer_read(log, s, &index,
3109 &pbExtraBytesNdrPtr))
3110 return ERROR_INVALID_DATA;
3112 if (ioRecvPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3116 "Transmit_Call ioRecvPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3117 return STATUS_INVALID_PARAMETER;
3120 if (pbExtraBytesNdrPtr)
3123 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3124 return STATUS_BUFFER_TOO_SMALL;
3126 Stream_Read_UINT32(s, length);
3128 if (ioRecvPci.cbExtraBytes > 1024)
3130 WLog_Print(log, WLOG_WARN,
3131 "Transmit_Call ioRecvPci.cbExtraBytes is out of bounds: %" PRIu32
3133 ioRecvPci.cbExtraBytes);
3134 return STATUS_INVALID_PARAMETER;
3137 if (length != ioRecvPci.cbExtraBytes)
3139 WLog_Print(log, WLOG_WARN,
3140 "Transmit_Call unexpected length: Actual: %" PRIu32
3141 ", Expected: %" PRIu32
" (ioRecvPci.cbExtraBytes)",
3142 length, ioRecvPci.cbExtraBytes);
3143 return STATUS_INVALID_PARAMETER;
3146 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioRecvPci.cbExtraBytes))
3147 return STATUS_BUFFER_TOO_SMALL;
3149 ioRecvPci.pbExtraBytes = Stream_Pointer(s);
3153 if (!call->pioRecvPci)
3155 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3156 return STATUS_NO_MEMORY;
3159 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3160 call->pioRecvPci->cbPciLength =
3163 Stream_Read(s, pbExtraBytes, ioRecvPci.cbExtraBytes);
3164 if (smartcard_unpack_read_size_align(s, ioRecvPci.cbExtraBytes, 4) < 0)
3165 return STATUS_INVALID_PARAMETER;
3171 if (!call->pioRecvPci)
3173 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3174 return STATUS_NO_MEMORY;
3177 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3182 smartcard_trace_transmit_call(log, call);
3183 return SCARD_S_SUCCESS;
3189 wLog* log = scard_log();
3194 UINT32 cbRecvLength = ret->cbRecvLength;
3195 UINT32 cbRecvPci = ret->pioRecvPci ? ret->pioRecvPci->cbPciLength : 0;
3197 smartcard_trace_transmit_return(log, ret);
3199 if (!ret->pbRecvBuffer)
3202 if (!smartcard_ndr_pointer_write(s, &index, cbRecvPci))
3203 return SCARD_E_NO_MEMORY;
3204 if (!Stream_EnsureRemainingCapacity(s, 4))
3205 return SCARD_E_NO_MEMORY;
3206 Stream_Write_UINT32(s, cbRecvLength);
3207 if (!smartcard_ndr_pointer_write(s, &index, cbRecvLength))
3208 return SCARD_E_NO_MEMORY;
3210 if (ret->pioRecvPci)
3212 UINT32 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
3215 if (!Stream_EnsureRemainingCapacity(s, cbExtraBytes + 16))
3217 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3218 return SCARD_F_INTERNAL_ERROR;
3221 Stream_Write_UINT32(s, ret->pioRecvPci->dwProtocol);
3222 Stream_Write_UINT32(s, cbExtraBytes);
3223 if (!smartcard_ndr_pointer_write(s, &index, cbExtraBytes))
3224 return SCARD_E_NO_MEMORY;
3225 error = smartcard_ndr_write(s, pbExtraBytes, cbExtraBytes, 1, NDR_PTR_SIMPLE);
3230 status = smartcard_ndr_write(s, ret->pbRecvBuffer, ret->cbRecvLength, 1, NDR_PTR_SIMPLE);
3231 if (status != SCARD_S_SUCCESS)
3233 return ret->ReturnCode;
3238 UINT32 rgReaderStatesNdrPtr = 0;
3239 UINT32 rgAtrMasksNdrPtr = 0;
3241 UINT32 pbContextNdrPtr = 0;
3244 wLog* log = scard_log();
3246 call->rgReaderStates =
nullptr;
3248 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3250 if (status != SCARD_S_SUCCESS)
3253 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3254 return STATUS_BUFFER_TOO_SMALL;
3256 Stream_Read_UINT32(s, call->cAtrs);
3257 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3258 return ERROR_INVALID_DATA;
3259 Stream_Read_UINT32(s, call->cReaders);
3260 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3261 return ERROR_INVALID_DATA;
3263 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3264 &(call->handles.hContext));
3265 if (status != SCARD_S_SUCCESS)
3268 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3270 WLog_Print(log, WLOG_WARN,
3271 "LocateCardsByATRA_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3272 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3273 rgAtrMasksNdrPtr, call->cAtrs);
3274 return STATUS_INVALID_PARAMETER;
3277 if (rgAtrMasksNdrPtr)
3279 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3280 if (status != SCARD_S_SUCCESS)
3284 if (rgReaderStatesNdrPtr)
3287 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
3288 if (status != SCARD_S_SUCCESS)
3292 smartcard_trace_locate_cards_by_atr_a_call(log, call);
3293 return SCARD_S_SUCCESS;
3298 UINT32 sz1NdrPtr = 0;
3299 UINT32 sz2NdrPtr = 0;
3301 UINT32 pbContextNdrPtr = 0;
3304 wLog* log = scard_log();
3306 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3308 if (status != SCARD_S_SUCCESS)
3311 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3312 return ERROR_INVALID_DATA;
3313 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3314 return ERROR_INVALID_DATA;
3317 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3318 if (status != SCARD_S_SUCCESS)
3323 status = smartcard_ndr_read_a(log, s, &call->sz1, NDR_PTR_FULL);
3324 if (status != SCARD_S_SUCCESS)
3329 status = smartcard_ndr_read_a(log, s, &call->sz2, NDR_PTR_FULL);
3330 if (status != SCARD_S_SUCCESS)
3333 smartcard_trace_context_and_two_strings_a_call(log, call);
3334 return SCARD_S_SUCCESS;
3339 UINT32 sz1NdrPtr = 0;
3340 UINT32 sz2NdrPtr = 0;
3342 UINT32 pbContextNdrPtr = 0;
3345 wLog* log = scard_log();
3347 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3349 if (status != SCARD_S_SUCCESS)
3352 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3353 return ERROR_INVALID_DATA;
3354 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3355 return ERROR_INVALID_DATA;
3358 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3359 if (status != SCARD_S_SUCCESS)
3364 status = smartcard_ndr_read_w(log, s, &call->sz1, NDR_PTR_FULL);
3365 if (status != SCARD_S_SUCCESS)
3370 status = smartcard_ndr_read_w(log, s, &call->sz2, NDR_PTR_FULL);
3371 if (status != SCARD_S_SUCCESS)
3374 smartcard_trace_context_and_two_strings_w_call(log, call);
3375 return SCARD_S_SUCCESS;
3380 UINT32 sz1NdrPtr = 0;
3381 UINT32 sz2NdrPtr = 0;
3383 UINT32 pbContextNdrPtr = 0;
3386 wLog* log = scard_log();
3388 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3390 if (status != SCARD_S_SUCCESS)
3393 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3394 return STATUS_BUFFER_TOO_SMALL;
3396 Stream_Read_UINT32(s, call->cBytes);
3397 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3398 return ERROR_INVALID_DATA;
3400 Stream_Read_UINT32(s, call->cReaders);
3401 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3402 return ERROR_INVALID_DATA;
3404 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3405 &(call->handles.hContext));
3406 if (status != SCARD_S_SUCCESS)
3411 status = smartcard_ndr_read_fixed_string_a(log, s, &call->mszCards, call->cBytes,
3413 if (status != SCARD_S_SUCCESS)
3419 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
3420 if (status != SCARD_S_SUCCESS)
3423 smartcard_trace_locate_cards_a_call(log, call);
3424 return SCARD_S_SUCCESS;
3429 UINT32 sz1NdrPtr = 0;
3430 UINT32 sz2NdrPtr = 0;
3432 UINT32 pbContextNdrPtr = 0;
3435 wLog* log = scard_log();
3437 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3439 if (status != SCARD_S_SUCCESS)
3442 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3443 return STATUS_BUFFER_TOO_SMALL;
3445 Stream_Read_UINT32(s, call->cBytes);
3446 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3447 return ERROR_INVALID_DATA;
3449 Stream_Read_UINT32(s, call->cReaders);
3450 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3451 return ERROR_INVALID_DATA;
3453 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3454 &(call->handles.hContext));
3455 if (status != SCARD_S_SUCCESS)
3460 status = smartcard_ndr_read_fixed_string_w(log, s, &call->mszCards, call->cBytes,
3462 if (status != SCARD_S_SUCCESS)
3468 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
3469 if (status != SCARD_S_SUCCESS)
3472 smartcard_trace_locate_cards_w_call(log, call);
3473 return SCARD_S_SUCCESS;
3480 UINT32 pbContextNdrPtr = 0;
3483 wLog* log = scard_log();
3485 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3487 if (status != SCARD_S_SUCCESS)
3489 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3490 if (status != SCARD_S_SUCCESS)
3493 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3494 return STATUS_BUFFER_TOO_SMALL;
3495 Stream_Read_UINT32(s, call->dwAttrId);
3496 Stream_Read_UINT32(s, call->cbAttrLen);
3498 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
3499 return ERROR_INVALID_DATA;
3501 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3502 &(call->handles.hContext));
3503 if (status != SCARD_S_SUCCESS)
3506 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3507 if (status != SCARD_S_SUCCESS)
3513 status = smartcard_ndr_read_ex(log, s, &call->pbAttr, 0, 1, NDR_PTR_SIMPLE, &len);
3514 if (status != SCARD_S_SUCCESS)
3516 if (call->cbAttrLen > len)
3517 call->cbAttrLen = WINPR_ASSERTING_INT_CAST(DWORD, len);
3520 call->cbAttrLen = 0;
3521 smartcard_trace_set_attrib_call(log, call);
3522 return SCARD_S_SUCCESS;
3527 UINT32 rgReaderStatesNdrPtr = 0;
3528 UINT32 rgAtrMasksNdrPtr = 0;
3530 UINT32 pbContextNdrPtr = 0;
3533 wLog* log = scard_log();
3535 call->rgReaderStates =
nullptr;
3537 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3539 if (status != SCARD_S_SUCCESS)
3542 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3543 return STATUS_BUFFER_TOO_SMALL;
3545 Stream_Read_UINT32(s, call->cAtrs);
3546 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3547 return ERROR_INVALID_DATA;
3549 Stream_Read_UINT32(s, call->cReaders);
3550 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3551 return ERROR_INVALID_DATA;
3553 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3554 &(call->handles.hContext));
3555 if (status != SCARD_S_SUCCESS)
3558 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3560 WLog_Print(log, WLOG_WARN,
3561 "LocateCardsByATRW_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3562 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3563 rgAtrMasksNdrPtr, call->cAtrs);
3564 return STATUS_INVALID_PARAMETER;
3567 if (rgAtrMasksNdrPtr)
3569 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3570 if (status != SCARD_S_SUCCESS)
3574 if (rgReaderStatesNdrPtr)
3577 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
3578 if (status != SCARD_S_SUCCESS)
3582 smartcard_trace_locate_cards_by_atr_w_call(log, call);
3583 return SCARD_S_SUCCESS;
3588 UINT32 mszNdrPtr = 0;
3589 UINT32 contextNdrPtr = 0;
3591 UINT32 pbContextNdrPtr = 0;
3594 wLog* log = scard_log();
3596 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3597 return ERROR_INVALID_DATA;
3599 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3600 &index, &pbContextNdrPtr);
3601 if (status != SCARD_S_SUCCESS)
3604 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3605 return ERROR_INVALID_DATA;
3607 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3608 return STATUS_BUFFER_TOO_SMALL;
3609 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3610 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
3611 Stream_Read_UINT32(s, call->Common.cbDataLen);
3613 call->szLookupName =
nullptr;
3616 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
3617 if (status != SCARD_S_SUCCESS)
3621 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3622 &call->Common.handles.hContext);
3623 if (status != SCARD_S_SUCCESS)
3628 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3629 if (status != SCARD_S_SUCCESS)
3632 smartcard_trace_read_cache_a_call(log, call);
3633 return SCARD_S_SUCCESS;
3638 UINT32 mszNdrPtr = 0;
3639 UINT32 contextNdrPtr = 0;
3641 UINT32 pbContextNdrPtr = 0;
3644 wLog* log = scard_log();
3646 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3647 return ERROR_INVALID_DATA;
3649 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3650 &index, &pbContextNdrPtr);
3651 if (status != SCARD_S_SUCCESS)
3654 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3655 return ERROR_INVALID_DATA;
3657 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3658 return STATUS_BUFFER_TOO_SMALL;
3659 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3660 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
3661 Stream_Read_UINT32(s, call->Common.cbDataLen);
3663 call->szLookupName =
nullptr;
3666 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
3667 if (status != SCARD_S_SUCCESS)
3671 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3672 &call->Common.handles.hContext);
3673 if (status != SCARD_S_SUCCESS)
3678 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3679 if (status != SCARD_S_SUCCESS)
3682 smartcard_trace_read_cache_w_call(log, call);
3683 return SCARD_S_SUCCESS;
3688 UINT32 mszNdrPtr = 0;
3689 UINT32 contextNdrPtr = 0;
3690 UINT32 pbDataNdrPtr = 0;
3692 UINT32 pbContextNdrPtr = 0;
3695 wLog* log = scard_log();
3697 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3698 return ERROR_INVALID_DATA;
3700 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3701 &index, &pbContextNdrPtr);
3702 if (status != SCARD_S_SUCCESS)
3705 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3706 return ERROR_INVALID_DATA;
3708 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
3709 return STATUS_BUFFER_TOO_SMALL;
3711 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3712 Stream_Read_UINT32(s, call->Common.cbDataLen);
3714 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
3715 return ERROR_INVALID_DATA;
3717 call->szLookupName =
nullptr;
3720 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
3721 if (status != SCARD_S_SUCCESS)
3725 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3726 &call->Common.handles.hContext);
3727 if (status != SCARD_S_SUCCESS)
3730 call->Common.CardIdentifier =
nullptr;
3733 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3734 if (status != SCARD_S_SUCCESS)
3738 call->Common.pbData =
nullptr;
3741 status = smartcard_ndr_read(log, s, &call->Common.pbData, call->Common.cbDataLen, 1,
3743 if (status != SCARD_S_SUCCESS)
3746 smartcard_trace_write_cache_a_call(log, call);
3747 return SCARD_S_SUCCESS;
3752 UINT32 mszNdrPtr = 0;
3753 UINT32 contextNdrPtr = 0;
3754 UINT32 pbDataNdrPtr = 0;
3756 UINT32 pbContextNdrPtr = 0;
3759 wLog* log = scard_log();
3761 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3762 return ERROR_INVALID_DATA;
3764 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3765 &index, &pbContextNdrPtr);
3766 if (status != SCARD_S_SUCCESS)
3769 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3770 return ERROR_INVALID_DATA;
3772 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
3773 return STATUS_BUFFER_TOO_SMALL;
3774 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3775 Stream_Read_UINT32(s, call->Common.cbDataLen);
3777 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
3778 return ERROR_INVALID_DATA;
3780 call->szLookupName =
nullptr;
3783 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
3784 if (status != SCARD_S_SUCCESS)
3788 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3789 &call->Common.handles.hContext);
3790 if (status != SCARD_S_SUCCESS)
3793 call->Common.CardIdentifier =
nullptr;
3796 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3797 if (status != SCARD_S_SUCCESS)
3801 call->Common.pbData =
nullptr;
3804 status = smartcard_ndr_read(log, s, &call->Common.pbData, call->Common.cbDataLen, 1,
3806 if (status != SCARD_S_SUCCESS)
3809 smartcard_trace_write_cache_w_call(log, call);
3816 wLog* log = scard_log();
3819 UINT32 pbContextNdrPtr = 0;
3821 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3823 if (status != SCARD_S_SUCCESS)
3826 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3827 if (status != SCARD_S_SUCCESS)
3830 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3831 &(call->handles.hContext));
3832 if (status != SCARD_S_SUCCESS)
3834 WLog_Print(log, WLOG_ERROR,
3835 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
3840 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3841 if (status != SCARD_S_SUCCESS)
3842 WLog_Print(log, WLOG_ERROR,
3843 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
3845 smartcard_trace_get_transmit_count_call(log, call);
3852 wLog* log = scard_log();
3853 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
3854 &call->szReaderName);
3860 wLog* log = scard_log();
3861 return smartcard_unpack_common_context_and_string_a(log, s, &call->handles.hContext, &call->sz);
3867 wLog* log = scard_log();
3868 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext, &call->sz);
3874 wLog* log = scard_log();
3875 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
3876 &call->szReaderName);
3882 wLog* log = scard_log();
3883 smartcard_trace_device_type_id_return(log, ret);
3885 if (!Stream_EnsureRemainingCapacity(s, 4))
3887 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3888 return SCARD_F_INTERNAL_ERROR;
3891 Stream_Write_UINT32(s, ret->dwDeviceId);
3893 return ret->ReturnCode;
3899 wLog* log = scard_log();
3902 DWORD cbDataLen = ret->cReaders;
3905 smartcard_trace_locate_cards_return(log, ret);
3906 if (ret->ReturnCode != SCARD_S_SUCCESS)
3908 if (cbDataLen == SCARD_AUTOALLOCATE)
3911 if (!Stream_EnsureRemainingCapacity(s, 4))
3913 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3914 return SCARD_F_INTERNAL_ERROR;
3917 Stream_Write_UINT32(s, cbDataLen);
3918 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3919 return SCARD_E_NO_MEMORY;
3921 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cbDataLen, NDR_PTR_SIMPLE);
3922 if (status != SCARD_S_SUCCESS)
3924 return ret->ReturnCode;
3930 wLog* log = scard_log();
3934 DWORD cbDataLen = ret->cbDataLen;
3935 smartcard_trace_get_reader_icon_return(log, ret);
3936 if (ret->ReturnCode != SCARD_S_SUCCESS)
3938 if (cbDataLen == SCARD_AUTOALLOCATE)
3941 if (!Stream_EnsureRemainingCapacity(s, 4))
3943 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3944 return SCARD_F_INTERNAL_ERROR;
3947 Stream_Write_UINT32(s, cbDataLen);
3948 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3949 return SCARD_E_NO_MEMORY;
3951 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
3952 if (status != SCARD_S_SUCCESS)
3954 return ret->ReturnCode;
3960 wLog* log = scard_log();
3962 smartcard_trace_get_transmit_count_return(log, call);
3964 if (!Stream_EnsureRemainingCapacity(s, 4))
3966 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3967 return SCARD_F_INTERNAL_ERROR;
3970 Stream_Write_UINT32(s, call->cTransmitCount);
3972 return call->ReturnCode;
3978 wLog* log = scard_log();
3982 DWORD cbDataLen = ret->cbDataLen;
3983 smartcard_trace_read_cache_return(log, ret);
3984 if (ret->ReturnCode != SCARD_S_SUCCESS)
3987 if (cbDataLen == SCARD_AUTOALLOCATE)
3990 if (!Stream_EnsureRemainingCapacity(s, 4))
3992 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3993 return SCARD_F_INTERNAL_ERROR;
3996 Stream_Write_UINT32(s, cbDataLen);
3997 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3998 return SCARD_E_NO_MEMORY;
4000 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
4001 if (status != SCARD_S_SUCCESS)
4003 return ret->ReturnCode;