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, dataLen, 4);
301 WINPR_ASSERT(data || (size == 0));
319 size_t min, ndr_ptr_t type)
327 const LONG status = smartcard_ndr_read(log, s, u.ppv, min,
sizeof(
LocateCards_ATRMask), type);
328 if (status != SCARD_S_SUCCESS)
335 for (
size_t x = 0; x < min; x++)
337 const UINT32 val = winpr_Data_Get_UINT32(&masks[x].cbAtr);
338 if (val > ARRAYSIZE(masks[x].rgbAtr))
340 WLog_Print(log, WLOG_ERROR,
341 "LocateCards_ATRMask[%" PRIuz
"]::cbAtr %" PRIu32
" exceeds %" PRIuz, x, val,
342 (
size_t)ARRAYSIZE(masks[x].rgbAtr));
345 return STATUS_DATA_ERROR;
348 return SCARD_S_SUCCESS;
351static LONG smartcard_ndr_read_fixed_string_a(wLog* log,
wStream* s, CHAR** data,
size_t min,
360 return smartcard_ndr_read(log, s, u.ppv, min,
sizeof(CHAR), type);
363static LONG smartcard_ndr_read_fixed_string_w(wLog* log,
wStream* s, WCHAR** data,
size_t min,
372 return smartcard_ndr_read(log, s, u.ppv, min,
sizeof(WCHAR), type);
375static LONG smartcard_ndr_read_a(wLog* log,
wStream* s, CHAR** data, ndr_ptr_t type)
383 return smartcard_ndr_read(log, s, u.ppv, 0,
sizeof(CHAR), type);
386static LONG smartcard_ndr_read_w(wLog* log,
wStream* s, WCHAR** data, ndr_ptr_t type)
394 return smartcard_ndr_read(log, s, u.ppv, 0,
sizeof(WCHAR), type);
397static LONG smartcard_ndr_write_w(
wStream* s,
const WCHAR* data, UINT32 size, ndr_ptr_t type)
405 return smartcard_ndr_write(s, cnv.bp, size,
sizeof(WCHAR), type);
408static LONG smartcard_ndr_write_a(
wStream* s,
const CHAR* data, UINT32 size, ndr_ptr_t type)
416 return smartcard_ndr_write(s, cnv.bp, size,
sizeof(CHAR), type);
419static LONG smartcard_ndr_read_u(wLog* log,
wStream* s,
UUID** data)
427 return smartcard_ndr_read(log, s, u.ppv, 1,
sizeof(
UUID), NDR_PTR_FIXED);
430static char* smartcard_convert_string_list(
const void* in,
size_t bytes, BOOL unicode)
439 char* mszA =
nullptr;
451 mszA = ConvertMszWCharNToUtf8Alloc(
string.wz, bytes /
sizeof(WCHAR), &length);
457 mszA = (
char*)calloc(bytes,
sizeof(
char));
460 CopyMemory(mszA,
string.sz, bytes - 1);
469 for (
size_t index = 0; index < length - 1; index++)
471 if (mszA[index] ==
'\0')
478WINPR_ATTR_MALLOC(free, 1)
479static
char* smartcard_create_msz_dump(const
char* msz,
size_t len)
481 size_t bufferLen = len;
482 char* buffer = calloc(len + 1, 1);
487 const char* cur = msz;
489 while ((len > 0) && cur && cur[0] !=
'\0' && (bufferLen > 0))
491 size_t clen = strnlen(cur, len);
492 int rc = _snprintf(buf, bufferLen,
"%s", cur);
493 bufferLen -= (size_t)rc;
502static void smartcard_msz_dump(wLog* log, DWORD level,
const char* prefix,
const void* data,
503 size_t len, BOOL wchar)
505 if (!WLog_IsLevelActive(log, level))
509 const char* msz = WINPR_CXX_COMPAT_CAST(
const char*, data);
513 tmp = ConvertMszWCharNToUtf8Alloc(data, len, &mszlen);
517 char* array = smartcard_create_msz_dump(msz, mszlen);
518 WLog_Print(log, level,
"%s%s", prefix, array);
523WINPR_ATTR_MALLOC(free, 1)
524static
char* smartcard_create_array_dump(const
void* pd,
size_t len)
526 const BYTE* data = pd;
529 size_t bufferLen = len * 4;
532 char* buffer = calloc(bufferLen + 1, 1);
535 char* start = buffer;
537 WINPR_ASSERT(buffer || (bufferLen == 0));
539 if (!data && (len > 0))
541 (void)_snprintf(buffer, bufferLen,
"{ nullptr [%" PRIuz
"] }", len);
545 rc = _snprintf(buffer, bufferLen,
"{ ");
546 if ((rc < 0) || ((
size_t)rc >= bufferLen))
549 bufferLen -= (size_t)rc;
551 for (
size_t x = 0; x < len; x++)
553 rc = _snprintf(buffer, bufferLen,
"%02X", data[x]);
554 if ((rc < 0) || ((
size_t)rc >= bufferLen))
557 bufferLen -= (size_t)rc;
560 rc = _snprintf(buffer, bufferLen,
" }");
561 if ((rc < 0) || ((
size_t)rc >= bufferLen))
568WINPR_ATTR_FORMAT_ARG(3, 7)
569static
void smartcard_dump_array(wLog* log, DWORD level, WINPR_FORMAT_ARG const
char* prefix,
570 const
char* postfix, const
void* data,
size_t len, ...)
572 if (!WLog_IsLevelActive(log, level))
575 char* buffer = smartcard_create_array_dump(data, len);
577 char* fprefix =
nullptr;
579 va_list ap = WINPR_C_ARRAY_INIT;
581 winpr_vasprintf(&fprefix, &flen, prefix, ap);
583 WLog_Print(log, level,
"%s%s%s", fprefix, buffer, postfix);
588static void smartcard_log_redir_handle(wLog* log,
const REDIR_SCARDHANDLE* pHandle)
590 WINPR_ASSERT(pHandle);
591 smartcard_dump_array(log, g_LogLevel,
"handle: ",
"", pHandle->pbHandle, pHandle->cbHandle);
596 WINPR_ASSERT(phContext);
597 smartcard_dump_array(log, g_LogLevel,
"hContext: ",
"", phContext->pbContext,
598 phContext->cbContext);
601static void smartcard_trace_context_and_string_call_a(wLog* log,
const char* name,
605 if (!WLog_IsLevelActive(log, g_LogLevel))
608 WLog_Print(log, g_LogLevel,
"%s {", name);
609 smartcard_log_context(log, phContext);
610 WLog_Print(log, g_LogLevel,
" sz=%s", sz);
612 WLog_Print(log, g_LogLevel,
"}");
615static void smartcard_trace_context_and_string_call_w(wLog* log,
const char* name,
621 if (!WLog_IsLevelActive(log, g_LogLevel))
625 tmp = ConvertWCharToUtf8Alloc(sz,
nullptr);
627 WLog_Print(log, g_LogLevel,
"%s {", name);
628 smartcard_log_context(log, phContext);
629 WLog_Print(log, g_LogLevel,
" sz=%s", tmp);
630 WLog_Print(log, g_LogLevel,
"}");
634static void smartcard_trace_context_call(wLog* log,
const Context_Call* call,
const char* name)
638 if (!WLog_IsLevelActive(log, g_LogLevel))
641 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
642 smartcard_log_context(log, &call->handles.hContext);
644 WLog_Print(log, g_LogLevel,
"}");
652 if (!WLog_IsLevelActive(log, g_LogLevel))
655 WLog_Print(log, g_LogLevel,
"ListReaderGroups%s_Call {", unicode ?
"W" :
"A");
656 smartcard_log_context(log, &call->handles.hContext);
658 WLog_Print(log, g_LogLevel,
"fmszGroupsIsNULL: %" PRId32
" cchGroups: 0x%08" PRIx32,
659 call->fmszGroupsIsNULL, call->cchGroups);
660 WLog_Print(log, g_LogLevel,
"}");
663static void dump_reader_states_return(wLog* log,
const ReaderState_Return* rgReaderStates,
666 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
667 for (UINT32 index = 0; index < cReaders; index++)
670 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
671 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
672 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
673 szCurrentState, readerState->dwCurrentState);
674 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
675 szEventState, readerState->dwEventState);
676 free(szCurrentState);
679 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
680 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
687 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
688 for (UINT32 index = 0; index < cReaders; index++)
692 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
693 readerState->szReader, readerState->cbAtr);
694 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
695 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
696 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
697 szCurrentState, readerState->dwCurrentState);
698 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
699 szEventState, readerState->dwEventState);
700 free(szCurrentState);
703 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
704 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
711 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
712 for (UINT32 index = 0; index < cReaders; index++)
715 char* buffer = ConvertWCharToUtf8Alloc(readerState->szReader,
nullptr);
716 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
717 buffer, readerState->cbAtr);
719 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
720 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
721 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
722 szCurrentState, readerState->dwCurrentState);
723 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
724 szEventState, readerState->dwEventState);
725 free(szCurrentState);
728 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
729 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
737 if (!WLog_IsLevelActive(log, g_LogLevel))
740 WLog_Print(log, g_LogLevel,
"GetStatusChangeW_Call {");
741 smartcard_log_context(log, &call->handles.hContext);
743 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
746 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
748 WLog_Print(log, g_LogLevel,
"}");
756 if (!WLog_IsLevelActive(log, g_LogLevel))
759 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
761 WLog_Print(log, g_LogLevel,
"ListReaderGroups%s_Return {", unicode ?
"W" :
"A");
762 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIx32
")",
763 SCardGetErrorString(ret->ReturnCode),
764 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
765 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
766 WLog_Print(log, g_LogLevel,
"}");
770static void smartcard_trace_list_readers_call(wLog* log,
const ListReaders_Call* call, BOOL unicode)
774 if (!WLog_IsLevelActive(log, g_LogLevel))
777 char* mszGroupsA = smartcard_convert_string_list(call->mszGroups, call->cBytes, unicode);
779 WLog_Print(log, g_LogLevel,
"ListReaders%s_Call {", unicode ?
"W" :
"A");
780 smartcard_log_context(log, &call->handles.hContext);
782 WLog_Print(log, g_LogLevel,
783 "cBytes: %" PRIu32
" mszGroups: %s fmszReadersIsNULL: %" PRId32
784 " cchReaders: 0x%08" PRIX32
"",
785 call->cBytes, mszGroupsA, call->fmszReadersIsNULL, call->cchReaders);
786 WLog_Print(log, g_LogLevel,
"}");
791static void smartcard_trace_locate_cards_by_atr_a_call(wLog* log,
796 if (!WLog_IsLevelActive(log, g_LogLevel))
799 WLog_Print(log, g_LogLevel,
"LocateCardsByATRA_Call {");
800 smartcard_log_context(log, &call->handles.hContext);
802 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
804 WLog_Print(log, g_LogLevel,
"}");
807static void smartcard_trace_locate_cards_a_call(wLog* log,
const LocateCardsA_Call* call)
811 if (!WLog_IsLevelActive(log, g_LogLevel))
814 WLog_Print(log, g_LogLevel,
"LocateCardsA_Call {");
815 smartcard_log_context(log, &call->handles.hContext);
816 WLog_Print(log, g_LogLevel,
" cBytes=%" PRIu32, call->cBytes);
817 smartcard_msz_dump(log, g_LogLevel,
" mszCards=", call->mszCards, call->cBytes, FALSE);
818 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, call->cReaders);
819 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
821 WLog_Print(log, g_LogLevel,
"}");
824static void smartcard_trace_locate_cards_return(wLog* log,
const LocateCards_Return* ret)
828 if (!WLog_IsLevelActive(log, g_LogLevel))
831 WLog_Print(log, g_LogLevel,
"LocateCards_Return {");
832 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
833 SCardGetErrorString(ret->ReturnCode),
834 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
836 if (ret->ReturnCode == SCARD_S_SUCCESS)
838 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, ret->cReaders);
840 WLog_Print(log, g_LogLevel,
"}");
847 if (!WLog_IsLevelActive(log, g_LogLevel))
850 WLog_Print(log, g_LogLevel,
"GetReaderIcon_Return {");
851 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
852 SCardGetErrorString(ret->ReturnCode),
853 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
855 if (ret->ReturnCode == SCARD_S_SUCCESS)
857 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, ret->cbDataLen);
859 WLog_Print(log, g_LogLevel,
"}");
866 if (!WLog_IsLevelActive(log, g_LogLevel))
869 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Return {");
870 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
871 SCardGetErrorString(ret->ReturnCode),
872 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
874 WLog_Print(log, g_LogLevel,
" cTransmitCount=%" PRIu32, ret->cTransmitCount);
875 WLog_Print(log, g_LogLevel,
"}");
878static void smartcard_trace_read_cache_return(wLog* log,
const ReadCache_Return* ret)
882 if (!WLog_IsLevelActive(log, g_LogLevel))
885 WLog_Print(log, g_LogLevel,
"ReadCache_Return {");
886 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
887 SCardGetErrorString(ret->ReturnCode),
888 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
890 if (ret->ReturnCode == SCARD_S_SUCCESS)
892 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, ret->cbDataLen);
893 smartcard_dump_array(log, g_LogLevel,
" cbData: ",
"", ret->pbData, ret->cbDataLen);
895 WLog_Print(log, g_LogLevel,
"}");
898static void smartcard_trace_locate_cards_w_call(wLog* log,
const LocateCardsW_Call* call)
902 if (!WLog_IsLevelActive(log, g_LogLevel))
905 WLog_Print(log, g_LogLevel,
"LocateCardsW_Call {");
906 smartcard_log_context(log, &call->handles.hContext);
907 WLog_Print(log, g_LogLevel,
" cBytes=%" PRIu32, call->cBytes);
908 smartcard_msz_dump(log, g_LogLevel,
" sz2=", call->mszCards, call->cBytes, TRUE);
909 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, call->cReaders);
910 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
911 WLog_Print(log, g_LogLevel,
"}");
914static void smartcard_trace_list_readers_return(wLog* log,
const ListReaders_Return* ret,
919 if (!WLog_IsLevelActive(log, g_LogLevel))
922 WLog_Print(log, g_LogLevel,
"ListReaders%s_Return {", unicode ?
"W" :
"A");
923 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
924 SCardGetErrorString(ret->ReturnCode),
925 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
927 if (ret->ReturnCode != SCARD_S_SUCCESS)
929 WLog_Print(log, g_LogLevel,
"}");
933 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
935 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
936 WLog_Print(log, g_LogLevel,
"}");
945 if (!WLog_IsLevelActive(log, g_LogLevel))
948 WLog_Print(log, g_LogLevel,
"GetStatusChange%s_Return {", unicode ?
"W" :
"A");
949 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
950 SCardGetErrorString(ret->ReturnCode),
951 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
952 WLog_Print(log, g_LogLevel,
" cReaders: %" PRIu32
"", ret->cReaders);
954 dump_reader_states_return(log, ret->rgReaderStates, ret->cReaders);
956 if (!ret->rgReaderStates && (ret->cReaders > 0))
958 WLog_Print(log, g_LogLevel,
" [INVALID STATE] rgReaderStates=nullptr, cReaders=%" PRIu32,
961 else if (ret->ReturnCode != SCARD_S_SUCCESS)
963 WLog_Print(log, g_LogLevel,
" [INVALID RETURN] rgReaderStates, cReaders=%" PRIu32,
968 for (UINT32 index = 0; index < ret->cReaders; index++)
971 char* szCurrentState = SCardGetReaderStateString(rgReaderState->dwCurrentState);
972 char* szEventState = SCardGetReaderStateString(rgReaderState->dwEventState);
973 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")",
974 index, szCurrentState, rgReaderState->dwCurrentState);
975 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")",
976 index, szEventState, rgReaderState->dwEventState);
977 smartcard_dump_array(
978 log, g_LogLevel,
" [%" PRIu32
"]: cbAtr: %" PRIu32
" rgbAtr: ",
"",
979 rgReaderState->rgbAtr, rgReaderState->cbAtr, index, rgReaderState->cbAtr);
980 free(szCurrentState);
985 WLog_Print(log, g_LogLevel,
"}");
988static void smartcard_trace_context_and_two_strings_a_call(wLog* log,
993 if (!WLog_IsLevelActive(log, g_LogLevel))
996 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
997 smartcard_log_context(log, &call->handles.hContext);
998 WLog_Print(log, g_LogLevel,
" sz1=%s", call->sz1);
999 WLog_Print(log, g_LogLevel,
" sz2=%s", call->sz2);
1000 WLog_Print(log, g_LogLevel,
"}");
1003static void smartcard_trace_context_and_two_strings_w_call(wLog* log,
1007 char sz1[1024] = WINPR_C_ARRAY_INIT;
1008 char sz2[1024] = WINPR_C_ARRAY_INIT;
1010 if (!WLog_IsLevelActive(log, g_LogLevel))
1013 (void)ConvertWCharToUtf8(call->sz1, sz1, ARRAYSIZE(sz1));
1015 (void)ConvertWCharToUtf8(call->sz2, sz2, ARRAYSIZE(sz2));
1017 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
1018 smartcard_log_context(log, &call->handles.hContext);
1019 WLog_Print(log, g_LogLevel,
" sz1=%s", sz1);
1020 WLog_Print(log, g_LogLevel,
" sz2=%s", sz2);
1021 WLog_Print(log, g_LogLevel,
"}");
1028 if (!WLog_IsLevelActive(log, g_LogLevel))
1031 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Call {");
1032 smartcard_log_context(log, &call->handles.hContext);
1033 smartcard_log_redir_handle(log, &call->handles.hCard);
1035 WLog_Print(log, g_LogLevel,
"}");
1038static void smartcard_trace_write_cache_a_call(wLog* log,
const WriteCacheA_Call* call)
1042 if (!WLog_IsLevelActive(log, g_LogLevel))
1045 WLog_Print(log, g_LogLevel,
"WriteCacheA_Call {");
1047 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
1049 smartcard_log_context(log, &call->Common.handles.hContext);
1050 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1052 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1053 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1054 smartcard_dump_array(log, g_LogLevel,
" pbData=",
"", call->Common.pbData,
1055 call->Common.cbDataLen);
1056 WLog_Print(log, g_LogLevel,
"}");
1059static void smartcard_trace_write_cache_w_call(wLog* log,
const WriteCacheW_Call* call)
1062 char tmp[1024] = WINPR_C_ARRAY_INIT;
1064 if (!WLog_IsLevelActive(log, g_LogLevel))
1067 WLog_Print(log, g_LogLevel,
"WriteCacheW_Call {");
1069 if (call->szLookupName)
1070 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
1071 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
1073 smartcard_log_context(log, &call->Common.handles.hContext);
1074 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1076 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1077 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1078 smartcard_dump_array(log, g_LogLevel,
" pbData=",
"", call->Common.pbData,
1079 call->Common.cbDataLen);
1080 WLog_Print(log, g_LogLevel,
"}");
1083static void smartcard_trace_read_cache_a_call(wLog* log,
const ReadCacheA_Call* call)
1087 if (!WLog_IsLevelActive(log, g_LogLevel))
1090 WLog_Print(log, g_LogLevel,
"ReadCacheA_Call {");
1092 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
1093 smartcard_log_context(log, &call->Common.handles.hContext);
1094 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1096 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1097 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1098 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1100 WLog_Print(log, g_LogLevel,
"}");
1103static void smartcard_trace_read_cache_w_call(wLog* log,
const ReadCacheW_Call* call)
1106 char tmp[1024] = WINPR_C_ARRAY_INIT;
1108 if (!WLog_IsLevelActive(log, g_LogLevel))
1111 WLog_Print(log, g_LogLevel,
"ReadCacheW_Call {");
1112 if (call->szLookupName)
1113 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
1114 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
1116 smartcard_log_context(log, &call->Common.handles.hContext);
1117 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1119 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1120 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1121 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1123 WLog_Print(log, g_LogLevel,
"}");
1126static void smartcard_trace_transmit_call(wLog* log,
const Transmit_Call* call)
1129 UINT32 cbExtraBytes = 0;
1130 BYTE* pbExtraBytes =
nullptr;
1132 if (!WLog_IsLevelActive(log, g_LogLevel))
1135 WLog_Print(log, g_LogLevel,
"Transmit_Call {");
1136 smartcard_log_context(log, &call->handles.hContext);
1137 smartcard_log_redir_handle(log, &call->handles.hCard);
1139 if (call->pioSendPci)
1141 cbExtraBytes = (UINT32)(call->pioSendPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1143 WLog_Print(log, g_LogLevel,
"pioSendPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1144 call->pioSendPci->dwProtocol, cbExtraBytes);
1148 smartcard_dump_array(log, g_LogLevel,
"pbExtraBytes: ",
"", pbExtraBytes, cbExtraBytes);
1153 WLog_Print(log, g_LogLevel,
"pioSendPci: null");
1156 WLog_Print(log, g_LogLevel,
"cbSendLength: %" PRIu32
"", call->cbSendLength);
1158 if (call->pbSendBuffer)
1160 smartcard_dump_array(log, g_LogLevel,
"pbSendBuffer: ",
"", call->pbSendBuffer,
1161 call->cbSendLength);
1165 WLog_Print(log, g_LogLevel,
"pbSendBuffer: null");
1168 if (call->pioRecvPci)
1170 cbExtraBytes = (UINT32)(call->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1172 WLog_Print(log, g_LogLevel,
"pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1173 call->pioRecvPci->dwProtocol, cbExtraBytes);
1177 smartcard_dump_array(log, g_LogLevel,
"pbExtraBytes: ",
"", pbExtraBytes, cbExtraBytes);
1182 WLog_Print(log, g_LogLevel,
"pioRecvPci: null");
1185 WLog_Print(log, g_LogLevel,
"fpbRecvBufferIsNULL: %" PRId32
" cbRecvLength: %" PRIu32
"",
1186 call->fpbRecvBufferIsNULL, call->cbRecvLength);
1187 WLog_Print(log, g_LogLevel,
"}");
1190static void smartcard_trace_locate_cards_by_atr_w_call(wLog* log,
1195 if (!WLog_IsLevelActive(log, g_LogLevel))
1198 WLog_Print(log, g_LogLevel,
"LocateCardsByATRW_Call {");
1199 smartcard_log_context(log, &call->handles.hContext);
1201 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
1203 WLog_Print(log, g_LogLevel,
"}");
1206static void smartcard_trace_transmit_return(wLog* log,
const Transmit_Return* ret)
1209 UINT32 cbExtraBytes = 0;
1210 BYTE* pbExtraBytes =
nullptr;
1212 if (!WLog_IsLevelActive(log, g_LogLevel))
1215 WLog_Print(log, g_LogLevel,
"Transmit_Return {");
1216 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1217 SCardGetErrorString(ret->ReturnCode),
1218 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1220 if (ret->pioRecvPci)
1222 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1224 WLog_Print(log, g_LogLevel,
1225 " pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1226 ret->pioRecvPci->dwProtocol, cbExtraBytes);
1230 smartcard_dump_array(log, g_LogLevel,
" pbExtraBytes: ",
"", pbExtraBytes,
1236 WLog_Print(log, g_LogLevel,
" pioRecvPci: null");
1239 WLog_Print(log, g_LogLevel,
" cbRecvLength: %" PRIu32
"", ret->cbRecvLength);
1241 if (ret->pbRecvBuffer)
1243 smartcard_dump_array(log, g_LogLevel,
" pbRecvBuffer: ",
"", ret->pbRecvBuffer,
1248 WLog_Print(log, g_LogLevel,
" pbRecvBuffer: null");
1251 WLog_Print(log, g_LogLevel,
"}");
1254static void smartcard_trace_control_return(wLog* log,
const Control_Return* ret)
1258 if (!WLog_IsLevelActive(log, g_LogLevel))
1261 WLog_Print(log, g_LogLevel,
"Control_Return {");
1262 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1263 SCardGetErrorString(ret->ReturnCode),
1264 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1265 WLog_Print(log, g_LogLevel,
" cbOutBufferSize: %" PRIu32
"", ret->cbOutBufferSize);
1267 if (ret->pvOutBuffer)
1269 smartcard_dump_array(log, g_LogLevel,
"pvOutBuffer: ",
"", ret->pvOutBuffer,
1270 ret->cbOutBufferSize);
1274 WLog_Print(log, g_LogLevel,
"pvOutBuffer: null");
1277 WLog_Print(log, g_LogLevel,
"}");
1280static void smartcard_trace_control_call(wLog* log,
const Control_Call* call)
1284 if (!WLog_IsLevelActive(log, g_LogLevel))
1287 WLog_Print(log, g_LogLevel,
"Control_Call {");
1288 smartcard_log_context(log, &call->handles.hContext);
1289 smartcard_log_redir_handle(log, &call->handles.hCard);
1291 WLog_Print(log, g_LogLevel,
1292 "dwControlCode: 0x%08" PRIX32
" cbInBufferSize: %" PRIu32
1293 " fpvOutBufferIsNULL: %" PRId32
" cbOutBufferSize: %" PRIu32
"",
1294 call->dwControlCode, call->cbInBufferSize, call->fpvOutBufferIsNULL,
1295 call->cbOutBufferSize);
1297 if (call->pvInBuffer)
1299 smartcard_dump_array(log, WLOG_DEBUG,
"pbInBuffer: ",
"", call->pvInBuffer,
1300 call->cbInBufferSize);
1304 WLog_Print(log, g_LogLevel,
"pvInBuffer: null");
1307 WLog_Print(log, g_LogLevel,
"}");
1310static void smartcard_trace_set_attrib_call(wLog* log,
const SetAttrib_Call* call)
1314 if (!WLog_IsLevelActive(log, g_LogLevel))
1317 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1318 smartcard_log_context(log, &call->handles.hContext);
1319 smartcard_log_redir_handle(log, &call->handles.hCard);
1320 WLog_Print(log, g_LogLevel,
"dwAttrId: 0x%08" PRIX32, call->dwAttrId);
1321 WLog_Print(log, g_LogLevel,
"cbAttrLen: 0x%08" PRIx32, call->cbAttrLen);
1322 smartcard_dump_array(log, g_LogLevel,
"pbAttr: ",
"", call->pbAttr, call->cbAttrLen);
1323 WLog_Print(log, g_LogLevel,
"}");
1326static void smartcard_trace_get_attrib_return(wLog* log,
const GetAttrib_Return* ret,
1331 if (!WLog_IsLevelActive(log, g_LogLevel))
1334 WLog_Print(log, g_LogLevel,
"GetAttrib_Return {");
1335 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1336 SCardGetErrorString(ret->ReturnCode),
1337 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1338 WLog_Print(log, g_LogLevel,
" dwAttrId: %s (0x%08" PRIX32
") cbAttrLen: 0x%08" PRIX32
"",
1339 SCardGetAttributeString(dwAttrId), dwAttrId, ret->cbAttrLen);
1340 smartcard_dump_array(log, g_LogLevel,
" ",
"", ret->pbAttr, ret->cbAttrLen);
1342 WLog_Print(log, g_LogLevel,
"}");
1345static void smartcard_trace_get_attrib_call(wLog* log,
const GetAttrib_Call* call)
1349 if (!WLog_IsLevelActive(log, g_LogLevel))
1352 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1353 smartcard_log_context(log, &call->handles.hContext);
1354 smartcard_log_redir_handle(log, &call->handles.hCard);
1356 WLog_Print(log, g_LogLevel,
1357 "dwAttrId: %s (0x%08" PRIX32
") fpbAttrIsNULL: %" PRId32
" cbAttrLen: 0x%08" PRIX32
1359 SCardGetAttributeString(call->dwAttrId), call->dwAttrId, call->fpbAttrIsNULL,
1361 WLog_Print(log, g_LogLevel,
"}");
1364static void smartcard_trace_status_call(wLog* log,
const Status_Call* call, BOOL unicode)
1368 if (!WLog_IsLevelActive(log, g_LogLevel))
1371 WLog_Print(log, g_LogLevel,
"Status%s_Call {", unicode ?
"W" :
"A");
1372 smartcard_log_context(log, &call->handles.hContext);
1373 smartcard_log_redir_handle(log, &call->handles.hCard);
1375 WLog_Print(log, g_LogLevel,
1376 "fmszReaderNamesIsNULL: %" PRId32
" cchReaderLen: %" PRIu32
" cbAtrLen: %" PRIu32
"",
1377 call->fmszReaderNamesIsNULL, call->cchReaderLen, call->cbAtrLen);
1378 WLog_Print(log, g_LogLevel,
"}");
1381static void smartcard_trace_status_return(wLog* log,
const Status_Return* ret, BOOL unicode)
1384 char* mszReaderNamesA =
nullptr;
1387 if (!WLog_IsLevelActive(log, g_LogLevel))
1389 cBytes = ret->cBytes;
1390 if (ret->ReturnCode != SCARD_S_SUCCESS)
1392 if (cBytes == SCARD_AUTOALLOCATE)
1394 mszReaderNamesA = smartcard_convert_string_list(ret->mszReaderNames, cBytes, unicode);
1396 WLog_Print(log, g_LogLevel,
"Status%s_Return {", unicode ?
"W" :
"A");
1397 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1398 SCardGetErrorString(ret->ReturnCode),
1399 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1400 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
") dwProtocol: %s (0x%08" PRIX32
")",
1401 SCardGetCardStateString(ret->dwState), ret->dwState,
1402 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1404 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" mszReaderNames: %s", ret->cBytes,
1407 smartcard_dump_array(log, g_LogLevel,
" cbAtrLen: %" PRIu32
" pbAtr: ",
"", ret->pbAtr,
1408 ret->cbAtrLen, ret->cbAtrLen);
1409 WLog_Print(log, g_LogLevel,
"}");
1410 free(mszReaderNamesA);
1413static void smartcard_trace_state_return(wLog* log,
const State_Return* ret)
1416 char* state =
nullptr;
1418 if (!WLog_IsLevelActive(log, g_LogLevel))
1421 state = SCardGetReaderStateString(ret->dwState);
1422 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1423 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1424 SCardGetErrorString(ret->ReturnCode),
1425 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1426 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
")", state, ret->dwState);
1427 WLog_Print(log, g_LogLevel,
" dwProtocol: %s (0x%08" PRIX32
")",
1428 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1429 WLog_Print(log, g_LogLevel,
" cbAtrLen: (0x%08" PRIX32
")", ret->cbAtrLen);
1430 smartcard_dump_array(log, g_LogLevel,
" rgAtr: ",
"", ret->rgAtr,
sizeof(ret->rgAtr));
1431 WLog_Print(log, g_LogLevel,
"}");
1435static void smartcard_trace_reconnect_return(wLog* log,
const Reconnect_Return* ret)
1439 if (!WLog_IsLevelActive(log, g_LogLevel))
1442 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1443 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1444 SCardGetErrorString(ret->ReturnCode),
1445 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1446 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1447 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1448 WLog_Print(log, g_LogLevel,
"}");
1451static void smartcard_trace_connect_a_call(wLog* log,
const ConnectA_Call* call)
1455 if (!WLog_IsLevelActive(log, g_LogLevel))
1458 WLog_Print(log, g_LogLevel,
"ConnectA_Call {");
1459 smartcard_log_context(log, &call->Common.handles.hContext);
1461 WLog_Print(log, g_LogLevel,
1462 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1463 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1464 call->szReader, SCardGetShareModeString(call->Common.dwShareMode),
1465 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1466 call->Common.dwPreferredProtocols);
1467 WLog_Print(log, g_LogLevel,
"}");
1470static void smartcard_trace_connect_w_call(wLog* log,
const ConnectW_Call* call)
1473 char szReaderA[1024] = WINPR_C_ARRAY_INIT;
1475 if (!WLog_IsLevelActive(log, g_LogLevel))
1479 (void)ConvertWCharToUtf8(call->szReader, szReaderA, ARRAYSIZE(szReaderA));
1480 WLog_Print(log, g_LogLevel,
"ConnectW_Call {");
1481 smartcard_log_context(log, &call->Common.handles.hContext);
1483 WLog_Print(log, g_LogLevel,
1484 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1485 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1486 szReaderA, SCardGetShareModeString(call->Common.dwShareMode),
1487 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1488 call->Common.dwPreferredProtocols);
1489 WLog_Print(log, g_LogLevel,
"}");
1492static void smartcard_trace_hcard_and_disposition_call(wLog* log,
1498 if (!WLog_IsLevelActive(log, g_LogLevel))
1501 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
1502 smartcard_log_context(log, &call->handles.hContext);
1503 smartcard_log_redir_handle(log, &call->handles.hCard);
1505 WLog_Print(log, g_LogLevel,
"dwDisposition: %s (0x%08" PRIX32
")",
1506 SCardGetDispositionString(call->dwDisposition), call->dwDisposition);
1507 WLog_Print(log, g_LogLevel,
"}");
1514 if (!WLog_IsLevelActive(log, g_LogLevel))
1517 WLog_Print(log, g_LogLevel,
"EstablishContext_Call {");
1518 WLog_Print(log, g_LogLevel,
"dwScope: %s (0x%08" PRIX32
")", SCardGetScopeString(call->dwScope),
1520 WLog_Print(log, g_LogLevel,
"}");
1527 if (!WLog_IsLevelActive(log, g_LogLevel))
1530 WLog_Print(log, g_LogLevel,
"EstablishContext_Return {");
1531 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1532 SCardGetErrorString(ret->ReturnCode),
1533 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1534 smartcard_log_context(log, &ret->hContext);
1536 WLog_Print(log, g_LogLevel,
"}");
1539void smartcard_trace_long_return(
const Long_Return* ret,
const char* name)
1541 wLog* log = scard_log();
1542 smartcard_trace_long_return_int(log, ret, name);
1545void smartcard_trace_long_return_int(wLog* log,
const Long_Return* ret,
const char* name)
1549 if (!WLog_IsLevelActive(log, g_LogLevel))
1552 WLog_Print(log, g_LogLevel,
"%s_Return {", name);
1553 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1554 SCardGetErrorString(ret->ReturnCode),
1555 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1556 WLog_Print(log, g_LogLevel,
"}");
1559static void smartcard_trace_connect_return(wLog* log,
const Connect_Return* ret)
1563 if (!WLog_IsLevelActive(log, g_LogLevel))
1566 WLog_Print(log, g_LogLevel,
"Connect_Return {");
1567 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1568 SCardGetErrorString(ret->ReturnCode),
1569 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1570 smartcard_log_context(log, &ret->hContext);
1571 smartcard_log_redir_handle(log, &ret->hCard);
1573 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1574 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1575 WLog_Print(log, g_LogLevel,
"}");
1578static void smartcard_trace_reconnect_call(wLog* log,
const Reconnect_Call* call)
1582 if (!WLog_IsLevelActive(log, g_LogLevel))
1585 WLog_Print(log, g_LogLevel,
"Reconnect_Call {");
1586 smartcard_log_context(log, &call->handles.hContext);
1587 smartcard_log_redir_handle(log, &call->handles.hCard);
1589 WLog_Print(log, g_LogLevel,
1590 "dwShareMode: %s (0x%08" PRIX32
") dwPreferredProtocols: %s (0x%08" PRIX32
1591 ") dwInitialization: %s (0x%08" PRIX32
")",
1592 SCardGetShareModeString(call->dwShareMode), call->dwShareMode,
1593 SCardGetProtocolString(call->dwPreferredProtocols), call->dwPreferredProtocols,
1594 SCardGetDispositionString(call->dwInitialization), call->dwInitialization);
1595 WLog_Print(log, g_LogLevel,
"}");
1602 if (!WLog_IsLevelActive(log, g_LogLevel))
1605 WLog_Print(log, g_LogLevel,
"GetDeviceTypeId_Return {");
1606 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1607 SCardGetErrorString(ret->ReturnCode),
1608 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1609 WLog_Print(log, g_LogLevel,
" dwDeviceId=%08" PRIx32, ret->dwDeviceId);
1611 WLog_Print(log, g_LogLevel,
"}");
1614static LONG smartcard_unpack_common_context_and_string_a(wLog* log,
wStream* s,
1616 CHAR** pszReaderName)
1619 UINT32 pbContextNdrPtr = 0;
1620 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1621 if (status != SCARD_S_SUCCESS)
1624 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
1625 return ERROR_INVALID_DATA;
1627 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1628 if (status != SCARD_S_SUCCESS)
1631 status = smartcard_ndr_read_a(log, s, pszReaderName, NDR_PTR_FULL);
1632 if (status != SCARD_S_SUCCESS)
1635 smartcard_trace_context_and_string_call_a(log, __func__, phContext, *pszReaderName);
1636 return SCARD_S_SUCCESS;
1639static LONG smartcard_unpack_common_context_and_string_w(wLog* log,
wStream* s,
1641 WCHAR** pszReaderName)
1644 UINT32 pbContextNdrPtr = 0;
1646 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1647 if (status != SCARD_S_SUCCESS)
1650 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
1651 return ERROR_INVALID_DATA;
1653 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1654 if (status != SCARD_S_SUCCESS)
1657 status = smartcard_ndr_read_w(log, s, pszReaderName, NDR_PTR_FULL);
1658 if (status != SCARD_S_SUCCESS)
1661 smartcard_trace_context_and_string_call_w(log, __func__, phContext, *pszReaderName);
1662 return SCARD_S_SUCCESS;
1665LONG smartcard_unpack_common_type_header(
wStream* s)
1667 wLog* log = scard_log();
1670 UINT8 endianness = 0;
1671 UINT16 commonHeaderLength = 0;
1673 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1674 return STATUS_BUFFER_TOO_SMALL;
1677 Stream_Read_UINT8(s, version);
1678 Stream_Read_UINT8(s, endianness);
1679 Stream_Read_UINT16(s, commonHeaderLength);
1680 Stream_Read_UINT32(s, filler);
1684 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Version %" PRIu8
"", version);
1685 return STATUS_INVALID_PARAMETER;
1688 if (endianness != 0x10)
1690 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Endianness %" PRIu8
"",
1692 return STATUS_INVALID_PARAMETER;
1695 if (commonHeaderLength != 8)
1697 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader CommonHeaderLength %" PRIu16
"",
1698 commonHeaderLength);
1699 return STATUS_INVALID_PARAMETER;
1702 if (filler != 0xCCCCCCCC)
1704 WLog_Print(log, WLOG_WARN,
"Unexpected CommonTypeHeader Filler 0x%08" PRIX32
"", filler);
1705 return STATUS_INVALID_PARAMETER;
1708 return SCARD_S_SUCCESS;
1711void smartcard_pack_common_type_header(
wStream* s)
1713 Stream_Write_UINT8(s, 1);
1714 Stream_Write_UINT8(s, 0x10);
1715 Stream_Write_UINT16(s, 8);
1716 Stream_Write_UINT32(s, 0xCCCCCCCC);
1719LONG smartcard_unpack_private_type_header(
wStream* s)
1721 wLog* log = scard_log();
1723 UINT32 objectBufferLength = 0;
1725 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1726 return STATUS_BUFFER_TOO_SMALL;
1728 Stream_Read_UINT32(s, objectBufferLength);
1729 Stream_Read_UINT32(s, filler);
1731 if (filler != 0x00000000)
1733 WLog_Print(log, WLOG_WARN,
"Unexpected PrivateTypeHeader Filler 0x%08" PRIX32
"", filler);
1734 return STATUS_INVALID_PARAMETER;
1737 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, objectBufferLength))
1738 return STATUS_INVALID_PARAMETER;
1740 return SCARD_S_SUCCESS;
1743void smartcard_pack_private_type_header(
wStream* s, UINT32 objectBufferLength)
1745 Stream_Write_UINT32(s, objectBufferLength);
1746 Stream_Write_UINT32(s, 0x00000000);
1749LONG smartcard_unpack_read_size_align(
wStream* s,
size_t size, UINT32 alignment)
1751 const size_t padsize = (size + alignment - 1) & ~(alignment - 1);
1752 const size_t pad = padsize - size;
1756 if (!Stream_SafeSeek(s, pad))
1763LONG smartcard_pack_write_size_align(
wStream* s,
size_t size, UINT32 alignment)
1765 const size_t padsize = (size + alignment - 1) & ~(alignment - 1);
1766 const size_t pad = padsize - size;
1770 if (!Stream_EnsureRemainingCapacity(s, pad))
1772 wLog* log = scard_log();
1773 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
1774 return SCARD_F_INTERNAL_ERROR;
1777 Stream_Zero(s, pad);
1780 return SCARD_S_SUCCESS;
1785 SCARDCONTEXT hContext = WINPR_C_ARRAY_INIT;
1787 WINPR_ASSERT(context);
1788 if ((context->cbContext !=
sizeof(ULONG_PTR)) && (context->cbContext != 0))
1790 wLog* log = scard_log();
1791 WLog_Print(log, WLOG_WARN,
1792 "REDIR_SCARDCONTEXT does not match native size: Actual: %" PRIu32
1793 ", Expected: %" PRIuz
"",
1794 context->cbContext,
sizeof(ULONG_PTR));
1798 if (context->cbContext)
1799 CopyMemory(&hContext, &(context->pbContext), context->cbContext);
1804void smartcard_scard_context_native_to_redir(
REDIR_SCARDCONTEXT* context, SCARDCONTEXT hContext)
1806 WINPR_ASSERT(context);
1808 context->cbContext =
sizeof(ULONG_PTR);
1809 CopyMemory(&(context->pbContext), &hContext, context->cbContext);
1814 SCARDHANDLE hCard = 0;
1816 WINPR_ASSERT(handle);
1817 if (handle->cbHandle == 0)
1820 if (handle->cbHandle !=
sizeof(ULONG_PTR))
1822 wLog* log = scard_log();
1823 WLog_Print(log, WLOG_WARN,
1824 "REDIR_SCARDHANDLE does not match native size: Actual: %" PRIu32
1825 ", Expected: %" PRIuz
"",
1826 handle->cbHandle,
sizeof(ULONG_PTR));
1830 if (handle->cbHandle)
1831 CopyMemory(&hCard, &(handle->pbHandle), handle->cbHandle);
1836void smartcard_scard_handle_native_to_redir(
REDIR_SCARDHANDLE* handle, SCARDHANDLE hCard)
1838 WINPR_ASSERT(handle);
1840 handle->cbHandle =
sizeof(ULONG_PTR);
1841 CopyMemory(&(handle->pbHandle), &hCard, handle->cbHandle);
1844#define smartcard_context_supported(log, size) \
1845 smartcard_context_supported_((log), (size), __FILE__, __func__, __LINE__)
1846static LONG smartcard_context_supported_(wLog* log, uint32_t size,
const char* file,
1847 const char* fkt,
size_t line)
1854 return SCARD_S_SUCCESS;
1857 const uint32_t level = WLOG_WARN;
1858 if (WLog_IsLevelActive(log, level))
1860 WLog_PrintTextMessage(log, level, line, file, fkt,
1861 "REDIR_SCARDCONTEXT length is not 0, 4 or 8: %" PRIu32
"",
1864 return STATUS_INVALID_PARAMETER;
1870 UINT32* index, UINT32* ppbContextNdrPtr,
1871 const char* file,
const char* function,
size_t line)
1873 UINT32 pbContextNdrPtr = 0;
1876 WINPR_ASSERT(context);
1880 if (!Stream_CheckAndLogRequiredLengthWLogEx(log, WLOG_WARN, s, 4, 1,
"%s(%s:%" PRIuz
")", file,
1882 return STATUS_BUFFER_TOO_SMALL;
1884 const LONG status = smartcard_context_supported_(log, context->cbContext, file, function, line);
1885 if (status != SCARD_S_SUCCESS)
1888 Stream_Read_UINT32(s, context->cbContext);
1890 if (!smartcard_ndr_pointer_read_(log, s, index, &pbContextNdrPtr, file, function, line))
1891 return ERROR_INVALID_DATA;
1893 if (((context->cbContext == 0) && pbContextNdrPtr) ||
1894 ((context->cbContext != 0) && !pbContextNdrPtr))
1896 WLog_Print(log, WLOG_WARN,
1897 "REDIR_SCARDCONTEXT cbContext (%" PRIu32
") pbContextNdrPtr (%" PRIu32
1899 context->cbContext, pbContextNdrPtr);
1900 return STATUS_INVALID_PARAMETER;
1903 if (!Stream_CheckAndLogRequiredLengthWLogEx(log, WLOG_WARN, s, context->cbContext, 1,
1904 "%s(%s:%" PRIuz
")", file, function, line))
1905 return STATUS_INVALID_PARAMETER;
1907 *ppbContextNdrPtr = pbContextNdrPtr;
1908 return SCARD_S_SUCCESS;
1911LONG smartcard_pack_redir_scard_context(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1914 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
1916 WINPR_ASSERT(context);
1917 if (context->cbContext != 0)
1919 Stream_Write_UINT32(s, context->cbContext);
1920 Stream_Write_UINT32(s, pbContextNdrPtr);
1921 *index = *index + 1;
1926 return SCARD_S_SUCCESS;
1929LONG smartcard_unpack_redir_scard_context_ref(wLog* log,
wStream* s,
1930 WINPR_ATTR_UNUSED UINT32 pbContextNdrPtr,
1935 WINPR_ASSERT(context);
1936 if (context->cbContext == 0)
1937 return SCARD_S_SUCCESS;
1939 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1940 return STATUS_BUFFER_TOO_SMALL;
1942 Stream_Read_UINT32(s, length);
1944 if (length != context->cbContext)
1946 WLog_Print(log, WLOG_WARN,
1947 "REDIR_SCARDCONTEXT length (%" PRIu32
") cbContext (%" PRIu32
") mismatch",
1948 length, context->cbContext);
1949 return STATUS_INVALID_PARAMETER;
1952 const LONG status = smartcard_context_supported(log, context->cbContext);
1953 if (status != SCARD_S_SUCCESS)
1956 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, context->cbContext))
1957 return STATUS_BUFFER_TOO_SMALL;
1959 if (context->cbContext)
1960 Stream_Read(s, &(context->pbContext), context->cbContext);
1962 ZeroMemory(&(context->pbContext),
sizeof(context->pbContext));
1964 return SCARD_S_SUCCESS;
1967LONG smartcard_pack_redir_scard_context_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1970 WINPR_ASSERT(context);
1971 Stream_Write_UINT32(s, context->cbContext);
1973 if (context->cbContext)
1975 Stream_Write(s, &(context->pbContext), context->cbContext);
1978 return SCARD_S_SUCCESS;
1982 UINT32* index,
const char* file,
const char* function,
1985 WINPR_ASSERT(handle);
1988 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1989 return STATUS_BUFFER_TOO_SMALL;
1991 Stream_Read_UINT32(s, handle->cbHandle);
1993 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, handle->cbHandle))
1994 return STATUS_BUFFER_TOO_SMALL;
1996 if (!smartcard_ndr_pointer_read_(log, s, index,
nullptr, file, function, line))
1997 return ERROR_INVALID_DATA;
1999 return SCARD_S_SUCCESS;
2002LONG smartcard_pack_redir_scard_handle(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
2005 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
2007 WINPR_ASSERT(handle);
2008 if (handle->cbHandle != 0)
2010 Stream_Write_UINT32(s, handle->cbHandle);
2011 Stream_Write_UINT32(s, pbContextNdrPtr);
2012 *index = *index + 1;
2016 return SCARD_S_SUCCESS;
2023 WINPR_ASSERT(handle);
2024 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2025 return STATUS_BUFFER_TOO_SMALL;
2027 Stream_Read_UINT32(s, length);
2029 if (length != handle->cbHandle)
2031 WLog_Print(log, WLOG_WARN,
2032 "REDIR_SCARDHANDLE length (%" PRIu32
") cbHandle (%" PRIu32
") mismatch", length,
2034 return STATUS_INVALID_PARAMETER;
2037 if ((handle->cbHandle != 4) && (handle->cbHandle != 8))
2039 WLog_Print(log, WLOG_WARN,
"REDIR_SCARDHANDLE length is not 4 or 8: %" PRIu32
"",
2041 return STATUS_INVALID_PARAMETER;
2044 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, handle->cbHandle))
2045 return STATUS_BUFFER_TOO_SMALL;
2047 if (handle->cbHandle)
2048 Stream_Read(s, &(handle->pbHandle), handle->cbHandle);
2050 return SCARD_S_SUCCESS;
2053LONG smartcard_pack_redir_scard_handle_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
2056 WINPR_ASSERT(handle);
2057 Stream_Write_UINT32(s, handle->cbHandle);
2059 if (handle->cbHandle)
2060 Stream_Write(s, &(handle->pbHandle), handle->cbHandle);
2062 return SCARD_S_SUCCESS;
2068 wLog* log = scard_log();
2070 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2071 return STATUS_BUFFER_TOO_SMALL;
2073 Stream_Read_UINT32(s, call->dwScope);
2074 smartcard_trace_establish_context_call(log, call);
2075 return SCARD_S_SUCCESS;
2081 wLog* log = scard_log();
2083 smartcard_trace_establish_context_call(log, call);
2085 if (!Stream_EnsureRemainingCapacity(s, 4))
2086 return SCARD_E_NO_MEMORY;
2088 Stream_Write_UINT32(s, call->dwScope);
2090 return SCARD_S_SUCCESS;
2096 wLog* log = scard_log();
2100 smartcard_trace_establish_context_return(log, ret);
2101 if (ret->ReturnCode != SCARD_S_SUCCESS)
2102 return ret->ReturnCode;
2104 status = smartcard_pack_redir_scard_context(log, s, &(ret->hContext), &index);
2105 if (status != SCARD_S_SUCCESS)
2108 return smartcard_pack_redir_scard_context_ref(log, s, &(ret->hContext));
2114 wLog* log = scard_log();
2116 UINT32 pbContextNdrPtr = 0;
2119 smartcard_unpack_redir_scard_context(log, s, &(ret->hContext), &index, &pbContextNdrPtr);
2120 if (status != SCARD_S_SUCCESS)
2123 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &(ret->hContext));
2124 if (status != SCARD_S_SUCCESS)
2127 smartcard_trace_establish_context_return(log, ret);
2128 return SCARD_S_SUCCESS;
2134 UINT32 pbContextNdrPtr = 0;
2135 wLog* log = scard_log();
2138 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2140 if (status != SCARD_S_SUCCESS)
2143 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2144 &(call->handles.hContext));
2145 if (status != SCARD_S_SUCCESS)
2146 WLog_Print(log, WLOG_ERROR,
2147 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2150 smartcard_trace_context_call(log, call, name);
2157 UINT32 pbContextNdrPtr = 0;
2158 wLog* log = scard_log();
2161 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2164 if (status != SCARD_S_SUCCESS)
2167 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2168 return STATUS_BUFFER_TOO_SMALL;
2170 Stream_Read_INT32(s, call->fmszGroupsIsNULL);
2171 Stream_Read_UINT32(s, call->cchGroups);
2172 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2173 &(call->handles.hContext));
2175 if (status != SCARD_S_SUCCESS)
2178 smartcard_trace_list_reader_groups_call(log, call, unicode);
2179 return SCARD_S_SUCCESS;
2186 wLog* log = scard_log();
2189 smartcard_trace_list_reader_groups_call(log, call, unicode);
2191 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
2192 if (status != SCARD_S_SUCCESS)
2195 if (!Stream_EnsureRemainingCapacity(s, 8))
2196 return SCARD_E_NO_MEMORY;
2198 Stream_Write_INT32(s, call->fmszGroupsIsNULL);
2199 Stream_Write_UINT32(s, call->cchGroups);
2201 return smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
2208 wLog* log = scard_log();
2210 DWORD cBytes = ret->cBytes;
2213 smartcard_trace_list_reader_groups_return(log, ret, unicode);
2214 if (ret->ReturnCode != SCARD_S_SUCCESS)
2216 if (cBytes == SCARD_AUTOALLOCATE)
2219 if (!Stream_EnsureRemainingCapacity(s, 4))
2220 return SCARD_E_NO_MEMORY;
2222 Stream_Write_UINT32(s, cBytes);
2223 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
2224 return SCARD_E_NO_MEMORY;
2226 status = smartcard_ndr_write(s, ret->msz, cBytes, 1, NDR_PTR_SIMPLE);
2227 if (status != SCARD_S_SUCCESS)
2229 return ret->ReturnCode;
2236 wLog* log = scard_log();
2238 UINT32 mszNdrPtr = 0;
2240 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2241 return STATUS_BUFFER_TOO_SMALL;
2243 Stream_Read_UINT32(s, ret->cBytes);
2245 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
2246 return ERROR_INVALID_DATA;
2250 LONG status = smartcard_ndr_read(log, s, &ret->msz, ret->cBytes, 1, NDR_PTR_SIMPLE);
2251 if (status != SCARD_S_SUCCESS)
2255 smartcard_trace_list_reader_groups_return(log, ret, unicode);
2256 return SCARD_S_SUCCESS;
2262 UINT32 mszGroupsNdrPtr = 0;
2263 UINT32 pbContextNdrPtr = 0;
2264 wLog* log = scard_log();
2267 call->mszGroups =
nullptr;
2269 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2271 if (status != SCARD_S_SUCCESS)
2274 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2275 return STATUS_BUFFER_TOO_SMALL;
2277 Stream_Read_UINT32(s, call->cBytes);
2278 if (!smartcard_ndr_pointer_read(log, s, &index, &mszGroupsNdrPtr))
2279 return ERROR_INVALID_DATA;
2281 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2282 return STATUS_BUFFER_TOO_SMALL;
2283 Stream_Read_INT32(s, call->fmszReadersIsNULL);
2284 Stream_Read_UINT32(s, call->cchReaders);
2286 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2287 &(call->handles.hContext));
2288 if (status != SCARD_S_SUCCESS)
2291 if (mszGroupsNdrPtr)
2293 status = smartcard_ndr_read(log, s, &call->mszGroups, call->cBytes, 1, NDR_PTR_SIMPLE);
2294 if (status != SCARD_S_SUCCESS)
2298 smartcard_trace_list_readers_call(log, call, unicode);
2299 return SCARD_S_SUCCESS;
2305 wLog* log = scard_log();
2308 UINT32 size = ret->cBytes;
2310 smartcard_trace_list_readers_return(log, ret, unicode);
2311 if (ret->ReturnCode != SCARD_S_SUCCESS)
2314 if (!Stream_EnsureRemainingCapacity(s, 4))
2316 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
2317 return SCARD_F_INTERNAL_ERROR;
2320 Stream_Write_UINT32(s, size);
2321 if (!smartcard_ndr_pointer_write(s, &index, size))
2322 return SCARD_E_NO_MEMORY;
2324 status = smartcard_ndr_write(s, ret->msz, size, 1, NDR_PTR_SIMPLE);
2325 if (status != SCARD_S_SUCCESS)
2327 return ret->ReturnCode;
2331 UINT32* index, UINT32* ppbContextNdrPtr)
2333 WINPR_ASSERT(common);
2334 LONG status = smartcard_unpack_redir_scard_context(log, s, &(common->handles.hContext), index,
2336 if (status != SCARD_S_SUCCESS)
2339 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2340 return STATUS_BUFFER_TOO_SMALL;
2342 Stream_Read_UINT32(s, common->dwShareMode);
2343 Stream_Read_UINT32(s, common->dwPreferredProtocols);
2344 return SCARD_S_SUCCESS;
2351 UINT32 pbContextNdrPtr = 0;
2354 wLog* log = scard_log();
2356 call->szReader =
nullptr;
2358 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
2359 return ERROR_INVALID_DATA;
2361 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2362 if (status != SCARD_S_SUCCESS)
2364 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2369 status = smartcard_ndr_read_a(log, s, &call->szReader, NDR_PTR_FULL);
2370 if (status != SCARD_S_SUCCESS)
2373 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2374 &(call->Common.handles.hContext));
2375 if (status != SCARD_S_SUCCESS)
2376 WLog_Print(log, WLOG_ERROR,
2377 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2380 smartcard_trace_connect_a_call(log, call);
2388 UINT32 pbContextNdrPtr = 0;
2391 wLog* log = scard_log();
2392 call->szReader =
nullptr;
2394 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
2395 return ERROR_INVALID_DATA;
2397 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2398 if (status != SCARD_S_SUCCESS)
2400 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2405 status = smartcard_ndr_read_w(log, s, &call->szReader, NDR_PTR_FULL);
2406 if (status != SCARD_S_SUCCESS)
2409 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2410 &(call->Common.handles.hContext));
2411 if (status != SCARD_S_SUCCESS)
2412 WLog_Print(log, WLOG_ERROR,
2413 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2416 smartcard_trace_connect_w_call(log, call);
2426 wLog* log = scard_log();
2427 smartcard_trace_connect_return(log, ret);
2429 status = smartcard_pack_redir_scard_context(log, s, &ret->hContext, &index);
2430 if (status != SCARD_S_SUCCESS)
2433 status = smartcard_pack_redir_scard_handle(log, s, &ret->hCard, &index);
2434 if (status != SCARD_S_SUCCESS)
2437 if (!Stream_EnsureRemainingCapacity(s, 4))
2438 return SCARD_E_NO_MEMORY;
2440 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2441 status = smartcard_pack_redir_scard_context_ref(log, s, &ret->hContext);
2442 if (status != SCARD_S_SUCCESS)
2444 return smartcard_pack_redir_scard_handle_ref(log, s, &(ret->hCard));
2450 UINT32 pbContextNdrPtr = 0;
2453 wLog* log = scard_log();
2454 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2456 if (status != SCARD_S_SUCCESS)
2459 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2460 if (status != SCARD_S_SUCCESS)
2463 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2464 return STATUS_BUFFER_TOO_SMALL;
2466 Stream_Read_UINT32(s, call->dwShareMode);
2467 Stream_Read_UINT32(s, call->dwPreferredProtocols);
2468 Stream_Read_UINT32(s, call->dwInitialization);
2470 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2471 &(call->handles.hContext));
2472 if (status != SCARD_S_SUCCESS)
2474 WLog_Print(log, WLOG_ERROR,
2475 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2480 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2481 if (status != SCARD_S_SUCCESS)
2482 WLog_Print(log, WLOG_ERROR,
2483 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
2485 smartcard_trace_reconnect_call(log, call);
2492 wLog* log = scard_log();
2495 smartcard_trace_reconnect_call(log, call);
2497 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
2498 if (status != SCARD_S_SUCCESS)
2501 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
2502 if (status != SCARD_S_SUCCESS)
2505 if (!Stream_EnsureRemainingCapacity(s, 12))
2506 return SCARD_E_NO_MEMORY;
2508 Stream_Write_UINT32(s, call->dwShareMode);
2509 Stream_Write_UINT32(s, call->dwPreferredProtocols);
2510 Stream_Write_UINT32(s, call->dwInitialization);
2512 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
2513 if (status != SCARD_S_SUCCESS)
2516 return smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
2522 wLog* log = scard_log();
2523 smartcard_trace_reconnect_return(log, ret);
2525 if (!Stream_EnsureRemainingCapacity(s, 4))
2526 return SCARD_E_NO_MEMORY;
2527 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2528 return ret->ReturnCode;
2534 wLog* log = scard_log();
2536 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2537 return STATUS_BUFFER_TOO_SMALL;
2539 Stream_Read_UINT32(s, ret->dwActiveProtocol);
2541 smartcard_trace_reconnect_return(log, ret);
2542 return SCARD_S_SUCCESS;
2549 UINT32 pbContextNdrPtr = 0;
2552 wLog* log = scard_log();
2554 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2556 if (status != SCARD_S_SUCCESS)
2559 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2560 if (status != SCARD_S_SUCCESS)
2563 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2564 return STATUS_BUFFER_TOO_SMALL;
2566 Stream_Read_UINT32(s, call->dwDisposition);
2568 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2569 &(call->handles.hContext));
2570 if (status != SCARD_S_SUCCESS)
2573 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2574 if (status != SCARD_S_SUCCESS)
2577 smartcard_trace_hcard_and_disposition_call(log, call, name);
2585 if (!WLog_IsLevelActive(log, g_LogLevel))
2588 WLog_Print(log, g_LogLevel,
"GetStatusChangeA_Call {");
2589 smartcard_log_context(log, &call->handles.hContext);
2591 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
2594 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
2596 WLog_Print(log, g_LogLevel,
"}");
2600 UINT32 cReaders, UINT32* ptrIndex)
2602 LONG status = SCARD_E_NO_MEMORY;
2604 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2605 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2608 const UINT32 len = Stream_Get_UINT32(s);
2609 if (len != cReaders)
2611 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEA");
2617 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2618 if (!rgReaderStates || !states)
2620 status = ERROR_INVALID_DATA;
2622 for (UINT32 index = 0; index < cReaders; index++)
2624 UINT32 ptr = UINT32_MAX;
2627 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2630 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2636 states[index] = ptr != 0;
2637 Stream_Read_UINT32(s, readerState->dwCurrentState);
2638 Stream_Read_UINT32(s, readerState->dwEventState);
2639 Stream_Read_UINT32(s, readerState->cbAtr);
2640 if (readerState->cbAtr > ARRAYSIZE(readerState->rgbAtr))
2642 WLog_Print(log, WLOG_ERROR,
2643 "SCARD_READERSTATEA[%" PRIu32
"]::cbAtr %" PRIu32
" exceeds %" PRIuz, index,
2644 readerState->cbAtr, (
size_t)ARRAYSIZE(readerState->rgbAtr));
2647 Stream_Read(s, readerState->rgbAtr, 36);
2650 for (UINT32 index = 0; index < cReaders; index++)
2657 status = smartcard_ndr_read_a(log, s, &readerState->szReader, NDR_PTR_FULL);
2658 if (status != SCARD_S_SUCCESS)
2662 *ppcReaders = rgReaderStates;
2664 return SCARD_S_SUCCESS;
2668 for (UINT32 index = 0; index < cReaders; index++)
2671 free(readerState->szReader);
2674 free(rgReaderStates);
2680 UINT32 cReaders, UINT32* ptrIndex)
2682 LONG status = SCARD_E_NO_MEMORY;
2684 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2685 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2688 const UINT32 len = Stream_Get_UINT32(s);
2689 if (len != cReaders)
2691 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEW");
2697 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2699 if (!rgReaderStates || !states)
2702 status = ERROR_INVALID_DATA;
2703 for (UINT32 index = 0; index < cReaders; index++)
2705 UINT32 ptr = UINT32_MAX;
2708 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2711 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2717 states[index] = ptr != 0;
2718 Stream_Read_UINT32(s, readerState->dwCurrentState);
2719 Stream_Read_UINT32(s, readerState->dwEventState);
2720 Stream_Read_UINT32(s, readerState->cbAtr);
2721 if (readerState->cbAtr > ARRAYSIZE(readerState->rgbAtr))
2723 WLog_Print(log, WLOG_ERROR,
2724 "SCARD_READERSTATEW[%" PRIu32
"]::cbAtr %" PRIu32
" exceeds %" PRIuz, index,
2725 readerState->cbAtr, (
size_t)ARRAYSIZE(readerState->rgbAtr));
2728 Stream_Read(s, readerState->rgbAtr, 36);
2731 for (UINT32 index = 0; index < cReaders; index++)
2739 status = smartcard_ndr_read_w(log, s, &readerState->szReader, NDR_PTR_FULL);
2740 if (status != SCARD_S_SUCCESS)
2744 *ppcReaders = rgReaderStates;
2746 return SCARD_S_SUCCESS;
2750 for (UINT32 index = 0; index < cReaders; index++)
2753 free(readerState->szReader);
2756 free(rgReaderStates);
2769 UINT32 pbContextNdrPtr = 0;
2772 wLog* log = scard_log();
2774 call->rgReaderStates =
nullptr;
2776 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2778 if (status != SCARD_S_SUCCESS)
2781 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2782 return STATUS_BUFFER_TOO_SMALL;
2784 Stream_Read_UINT32(s, call->dwTimeOut);
2785 Stream_Read_UINT32(s, call->cReaders);
2786 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2787 return ERROR_INVALID_DATA;
2789 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2790 &(call->handles.hContext));
2791 if (status != SCARD_S_SUCCESS)
2797 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
2798 if (status != SCARD_S_SUCCESS)
2803 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2804 return SCARD_E_UNEXPECTED;
2807 smartcard_trace_get_status_change_a_call(log, call);
2808 return SCARD_S_SUCCESS;
2815 UINT32 pbContextNdrPtr = 0;
2818 wLog* log = scard_log();
2819 call->rgReaderStates =
nullptr;
2821 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2823 if (status != SCARD_S_SUCCESS)
2826 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2827 return STATUS_BUFFER_TOO_SMALL;
2829 Stream_Read_UINT32(s, call->dwTimeOut);
2830 Stream_Read_UINT32(s, call->cReaders);
2831 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2832 return ERROR_INVALID_DATA;
2834 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2835 &(call->handles.hContext));
2836 if (status != SCARD_S_SUCCESS)
2842 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
2843 if (status != SCARD_S_SUCCESS)
2848 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2849 return SCARD_E_UNEXPECTED;
2852 smartcard_trace_get_status_change_w_call(log, call);
2853 return SCARD_S_SUCCESS;
2860 wLog* log = scard_log();
2863 DWORD cReaders = ret->cReaders;
2866 smartcard_trace_get_status_change_return(log, ret, unicode);
2867 if (ret->ReturnCode != SCARD_S_SUCCESS)
2869 if (cReaders == SCARD_AUTOALLOCATE)
2872 if (!Stream_EnsureRemainingCapacity(s, 4))
2873 return SCARD_E_NO_MEMORY;
2875 Stream_Write_UINT32(s, cReaders);
2876 if (!smartcard_ndr_pointer_write(s, &index, cReaders))
2877 return SCARD_E_NO_MEMORY;
2878 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cReaders, NDR_PTR_SIMPLE);
2879 if (status != SCARD_S_SUCCESS)
2881 return ret->ReturnCode;
2887 UINT32 pbContextNdrPtr = 0;
2889 wLog* log = scard_log();
2892 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2894 if (status != SCARD_S_SUCCESS)
2897 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2898 if (status != SCARD_S_SUCCESS)
2901 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2902 return STATUS_BUFFER_TOO_SMALL;
2904 Stream_Read_INT32(s, call->fpbAtrIsNULL);
2905 Stream_Read_UINT32(s, call->cbAtrLen);
2907 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2908 &(call->handles.hContext));
2909 if (status != SCARD_S_SUCCESS)
2912 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2913 if (status != SCARD_S_SUCCESS)
2922 wLog* log = scard_log();
2924 DWORD cbAtrLen = ret->cbAtrLen;
2927 smartcard_trace_state_return(log, ret);
2928 if (ret->ReturnCode != SCARD_S_SUCCESS)
2930 if (cbAtrLen == SCARD_AUTOALLOCATE)
2933 Stream_Write_UINT32(s, ret->dwState);
2934 Stream_Write_UINT32(s, ret->dwProtocol);
2935 Stream_Write_UINT32(s, cbAtrLen);
2936 if (!smartcard_ndr_pointer_write(s, &index, cbAtrLen))
2937 return SCARD_E_NO_MEMORY;
2938 status = smartcard_ndr_write(s, ret->rgAtr, cbAtrLen, 1, NDR_PTR_SIMPLE);
2939 if (status != SCARD_S_SUCCESS)
2941 return ret->ReturnCode;
2947 UINT32 pbContextNdrPtr = 0;
2950 wLog* log = scard_log();
2952 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2954 if (status != SCARD_S_SUCCESS)
2957 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2958 if (status != SCARD_S_SUCCESS)
2961 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2962 return STATUS_BUFFER_TOO_SMALL;
2964 Stream_Read_INT32(s, call->fmszReaderNamesIsNULL);
2965 Stream_Read_UINT32(s, call->cchReaderLen);
2966 Stream_Read_UINT32(s, call->cbAtrLen);
2968 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2969 &(call->handles.hContext));
2970 if (status != SCARD_S_SUCCESS)
2973 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2974 if (status != SCARD_S_SUCCESS)
2977 smartcard_trace_status_call(log, call, unicode);
2984 wLog* log = scard_log();
2987 smartcard_trace_status_call(log, call, unicode);
2989 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
2990 if (status != SCARD_S_SUCCESS)
2993 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
2994 if (status != SCARD_S_SUCCESS)
2997 if (!Stream_EnsureRemainingCapacity(s, 12))
2998 return SCARD_E_NO_MEMORY;
3000 Stream_Write_INT32(s, call->fmszReaderNamesIsNULL);
3001 Stream_Write_UINT32(s, call->cchReaderLen);
3002 Stream_Write_UINT32(s, call->cbAtrLen);
3004 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
3005 if (status != SCARD_S_SUCCESS)
3008 return smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
3014 wLog* log = scard_log();
3018 DWORD cBytes = ret->cBytes;
3020 smartcard_trace_status_return(log, ret, unicode);
3021 if (ret->ReturnCode != SCARD_S_SUCCESS)
3023 if (cBytes == SCARD_AUTOALLOCATE)
3026 if (!Stream_EnsureRemainingCapacity(s, 4))
3027 return SCARD_F_INTERNAL_ERROR;
3029 Stream_Write_UINT32(s, cBytes);
3030 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
3031 return SCARD_E_NO_MEMORY;
3033 if (!Stream_EnsureRemainingCapacity(s, 44))
3034 return SCARD_F_INTERNAL_ERROR;
3036 Stream_Write_UINT32(s, ret->dwState);
3037 Stream_Write_UINT32(s, ret->dwProtocol);
3038 Stream_Write(s, ret->pbAtr,
sizeof(ret->pbAtr));
3039 Stream_Write_UINT32(s, ret->cbAtrLen);
3040 status = smartcard_ndr_write(s, ret->mszReaderNames, cBytes, 1, NDR_PTR_SIMPLE);
3041 if (status != SCARD_S_SUCCESS)
3043 return ret->ReturnCode;
3049 wLog* log = scard_log();
3051 UINT32 mszNdrPtr = 0;
3053 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3054 return STATUS_BUFFER_TOO_SMALL;
3056 Stream_Read_UINT32(s, ret->cBytes);
3058 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3059 return ERROR_INVALID_DATA;
3061 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 44))
3062 return STATUS_BUFFER_TOO_SMALL;
3064 Stream_Read_UINT32(s, ret->dwState);
3065 Stream_Read_UINT32(s, ret->dwProtocol);
3066 Stream_Read(s, ret->pbAtr,
sizeof(ret->pbAtr));
3067 Stream_Read_UINT32(s, ret->cbAtrLen);
3072 smartcard_ndr_read(log, s, &ret->mszReaderNames, ret->cBytes, 1, NDR_PTR_SIMPLE);
3073 if (status != SCARD_S_SUCCESS)
3077 smartcard_trace_status_return(log, ret, unicode);
3078 return SCARD_S_SUCCESS;
3084 wLog* log = scard_log();
3086 UINT32 pbContextNdrPtr = 0;
3088 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3090 if (status != SCARD_S_SUCCESS)
3093 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3094 if (status != SCARD_S_SUCCESS)
3097 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3098 return STATUS_BUFFER_TOO_SMALL;
3100 Stream_Read_UINT32(s, call->dwAttrId);
3101 Stream_Read_INT32(s, call->fpbAttrIsNULL);
3102 Stream_Read_UINT32(s, call->cbAttrLen);
3104 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3105 &(call->handles.hContext));
3106 if (status != SCARD_S_SUCCESS)
3109 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3110 if (status != SCARD_S_SUCCESS)
3113 smartcard_trace_get_attrib_call(log, call);
3118 DWORD cbAttrCallLen)
3121 wLog* log = scard_log();
3123 DWORD cbAttrLen = 0;
3125 smartcard_trace_get_attrib_return(log, ret, dwAttrId);
3127 if (!Stream_EnsureRemainingCapacity(s, 4))
3128 return SCARD_F_INTERNAL_ERROR;
3130 cbAttrLen = ret->cbAttrLen;
3131 if (ret->ReturnCode != SCARD_S_SUCCESS)
3133 if (cbAttrLen == SCARD_AUTOALLOCATE)
3138 if (cbAttrCallLen < cbAttrLen)
3139 cbAttrLen = cbAttrCallLen;
3141 Stream_Write_UINT32(s, cbAttrLen);
3142 if (!smartcard_ndr_pointer_write(s, &index, cbAttrLen))
3143 return SCARD_E_NO_MEMORY;
3145 status = smartcard_ndr_write(s, ret->pbAttr, cbAttrLen, 1, NDR_PTR_SIMPLE);
3146 if (status != SCARD_S_SUCCESS)
3148 return ret->ReturnCode;
3154 wLog* log = scard_log();
3157 UINT32 pvInBufferNdrPtr = 0;
3158 UINT32 pbContextNdrPtr = 0;
3160 call->pvInBuffer =
nullptr;
3162 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3164 if (status != SCARD_S_SUCCESS)
3167 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3168 if (status != SCARD_S_SUCCESS)
3171 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 20))
3172 return STATUS_BUFFER_TOO_SMALL;
3174 Stream_Read_UINT32(s, call->dwControlCode);
3175 Stream_Read_UINT32(s, call->cbInBufferSize);
3176 if (!smartcard_ndr_pointer_read(log, s, &index,
3178 return ERROR_INVALID_DATA;
3179 Stream_Read_INT32(s, call->fpvOutBufferIsNULL);
3180 Stream_Read_UINT32(s, call->cbOutBufferSize);
3182 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3183 &(call->handles.hContext));
3184 if (status != SCARD_S_SUCCESS)
3187 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3188 if (status != SCARD_S_SUCCESS)
3191 if (pvInBufferNdrPtr)
3194 smartcard_ndr_read(log, s, &call->pvInBuffer, call->cbInBufferSize, 1, NDR_PTR_SIMPLE);
3195 if (status != SCARD_S_SUCCESS)
3199 smartcard_trace_control_call(log, call);
3200 return SCARD_S_SUCCESS;
3206 wLog* log = scard_log();
3209 DWORD cbDataLen = ret->cbOutBufferSize;
3212 smartcard_trace_control_return(log, ret);
3213 if (ret->ReturnCode != SCARD_S_SUCCESS)
3215 if (cbDataLen == SCARD_AUTOALLOCATE)
3218 if (!Stream_EnsureRemainingCapacity(s, 4))
3219 return SCARD_F_INTERNAL_ERROR;
3221 Stream_Write_UINT32(s, cbDataLen);
3222 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3223 return SCARD_E_NO_MEMORY;
3225 status = smartcard_ndr_write(s, ret->pvOutBuffer, cbDataLen, 1, NDR_PTR_SIMPLE);
3226 if (status != SCARD_S_SUCCESS)
3228 return ret->ReturnCode;
3234 BYTE* pbExtraBytes =
nullptr;
3235 UINT32 pbExtraBytesNdrPtr = 0;
3236 UINT32 pbSendBufferNdrPtr = 0;
3237 UINT32 pioRecvPciNdrPtr = 0;
3241 UINT32 pbContextNdrPtr = 0;
3244 wLog* log = scard_log();
3246 call->pioSendPci =
nullptr;
3247 call->pioRecvPci =
nullptr;
3248 call->pbSendBuffer =
nullptr;
3250 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3252 if (status != SCARD_S_SUCCESS)
3255 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3256 if (status != SCARD_S_SUCCESS)
3259 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 32))
3260 return STATUS_BUFFER_TOO_SMALL;
3262 Stream_Read_UINT32(s, ioSendPci.dwProtocol);
3263 Stream_Read_UINT32(s, ioSendPci.cbExtraBytes);
3264 if (!smartcard_ndr_pointer_read(log, s, &index,
3265 &pbExtraBytesNdrPtr))
3266 return ERROR_INVALID_DATA;
3268 Stream_Read_UINT32(s, call->cbSendLength);
3269 if (!smartcard_ndr_pointer_read(log, s, &index,
3270 &pbSendBufferNdrPtr))
3271 return ERROR_INVALID_DATA;
3273 if (!smartcard_ndr_pointer_read(log, s, &index,
3275 return ERROR_INVALID_DATA;
3277 Stream_Read_INT32(s, call->fpbRecvBufferIsNULL);
3278 Stream_Read_UINT32(s, call->cbRecvLength);
3280 if (ioSendPci.cbExtraBytes > 1024)
3282 WLog_Print(log, WLOG_WARN,
3283 "Transmit_Call ioSendPci.cbExtraBytes is out of bounds: %" PRIu32
" (max: 1024)",
3284 ioSendPci.cbExtraBytes);
3285 return STATUS_INVALID_PARAMETER;
3288 if (call->cbSendLength > 66560)
3290 WLog_Print(log, WLOG_WARN,
3291 "Transmit_Call cbSendLength is out of bounds: %" PRIu32
" (max: 66560)",
3292 ioSendPci.cbExtraBytes);
3293 return STATUS_INVALID_PARAMETER;
3296 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3297 &(call->handles.hContext));
3298 if (status != SCARD_S_SUCCESS)
3301 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3302 if (status != SCARD_S_SUCCESS)
3305 if (ioSendPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3309 "Transmit_Call ioSendPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3310 return STATUS_INVALID_PARAMETER;
3313 if (pbExtraBytesNdrPtr)
3316 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3317 return STATUS_BUFFER_TOO_SMALL;
3319 Stream_Read_UINT32(s, length);
3321 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioSendPci.cbExtraBytes))
3322 return STATUS_BUFFER_TOO_SMALL;
3324 ioSendPci.pbExtraBytes = Stream_Pointer(s);
3328 if (!call->pioSendPci)
3330 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3331 return STATUS_NO_MEMORY;
3334 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3335 call->pioSendPci->cbPciLength = (DWORD)(ioSendPci.cbExtraBytes +
sizeof(
SCARD_IO_REQUEST));
3337 Stream_Read(s, pbExtraBytes, ioSendPci.cbExtraBytes);
3338 if (smartcard_unpack_read_size_align(s, ioSendPci.cbExtraBytes, 4) < 0)
3339 return STATUS_INVALID_PARAMETER;
3345 if (!call->pioSendPci)
3347 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3348 return STATUS_NO_MEMORY;
3351 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3355 if (pbSendBufferNdrPtr)
3358 smartcard_ndr_read(log, s, &call->pbSendBuffer, call->cbSendLength, 1, NDR_PTR_SIMPLE);
3359 if (status != SCARD_S_SUCCESS)
3363 if (pioRecvPciNdrPtr)
3365 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3366 return STATUS_BUFFER_TOO_SMALL;
3368 Stream_Read_UINT32(s, ioRecvPci.dwProtocol);
3369 Stream_Read_UINT32(s, ioRecvPci.cbExtraBytes);
3370 if (!smartcard_ndr_pointer_read(log, s, &index,
3371 &pbExtraBytesNdrPtr))
3372 return ERROR_INVALID_DATA;
3374 if (ioRecvPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3378 "Transmit_Call ioRecvPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3379 return STATUS_INVALID_PARAMETER;
3382 if (pbExtraBytesNdrPtr)
3385 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3386 return STATUS_BUFFER_TOO_SMALL;
3388 Stream_Read_UINT32(s, length);
3390 if (ioRecvPci.cbExtraBytes > 1024)
3392 WLog_Print(log, WLOG_WARN,
3393 "Transmit_Call ioRecvPci.cbExtraBytes is out of bounds: %" PRIu32
3395 ioRecvPci.cbExtraBytes);
3396 return STATUS_INVALID_PARAMETER;
3399 if (length != ioRecvPci.cbExtraBytes)
3401 WLog_Print(log, WLOG_WARN,
3402 "Transmit_Call unexpected length: Actual: %" PRIu32
3403 ", Expected: %" PRIu32
" (ioRecvPci.cbExtraBytes)",
3404 length, ioRecvPci.cbExtraBytes);
3405 return STATUS_INVALID_PARAMETER;
3408 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioRecvPci.cbExtraBytes))
3409 return STATUS_BUFFER_TOO_SMALL;
3411 ioRecvPci.pbExtraBytes = Stream_Pointer(s);
3415 if (!call->pioRecvPci)
3417 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3418 return STATUS_NO_MEMORY;
3421 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3422 call->pioRecvPci->cbPciLength =
3425 Stream_Read(s, pbExtraBytes, ioRecvPci.cbExtraBytes);
3426 if (smartcard_unpack_read_size_align(s, ioRecvPci.cbExtraBytes, 4) < 0)
3427 return STATUS_INVALID_PARAMETER;
3433 if (!call->pioRecvPci)
3435 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3436 return STATUS_NO_MEMORY;
3439 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3444 smartcard_trace_transmit_call(log, call);
3445 return SCARD_S_SUCCESS;
3451 wLog* log = scard_log();
3456 UINT32 cbRecvLength = ret->cbRecvLength;
3457 UINT32 cbRecvPci = ret->pioRecvPci ? ret->pioRecvPci->cbPciLength : 0;
3459 smartcard_trace_transmit_return(log, ret);
3461 if (!ret->pbRecvBuffer)
3464 if (!smartcard_ndr_pointer_write(s, &index, cbRecvPci))
3465 return SCARD_E_NO_MEMORY;
3466 if (!Stream_EnsureRemainingCapacity(s, 4))
3467 return SCARD_E_NO_MEMORY;
3468 Stream_Write_UINT32(s, cbRecvLength);
3469 if (!smartcard_ndr_pointer_write(s, &index, cbRecvLength))
3470 return SCARD_E_NO_MEMORY;
3472 if (ret->pioRecvPci)
3474 UINT32 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
3477 if (!Stream_EnsureRemainingCapacity(s, cbExtraBytes + 16))
3479 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3480 return SCARD_F_INTERNAL_ERROR;
3483 Stream_Write_UINT32(s, ret->pioRecvPci->dwProtocol);
3484 Stream_Write_UINT32(s, cbExtraBytes);
3485 if (!smartcard_ndr_pointer_write(s, &index, cbExtraBytes))
3486 return SCARD_E_NO_MEMORY;
3487 error = smartcard_ndr_write(s, pbExtraBytes, cbExtraBytes, 1, NDR_PTR_SIMPLE);
3492 status = smartcard_ndr_write(s, ret->pbRecvBuffer, ret->cbRecvLength, 1, NDR_PTR_SIMPLE);
3493 if (status != SCARD_S_SUCCESS)
3495 return ret->ReturnCode;
3500 UINT32 rgReaderStatesNdrPtr = 0;
3501 UINT32 rgAtrMasksNdrPtr = 0;
3503 UINT32 pbContextNdrPtr = 0;
3506 wLog* log = scard_log();
3508 call->rgReaderStates =
nullptr;
3510 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3512 if (status != SCARD_S_SUCCESS)
3515 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3516 return STATUS_BUFFER_TOO_SMALL;
3518 Stream_Read_UINT32(s, call->cAtrs);
3519 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3520 return ERROR_INVALID_DATA;
3521 Stream_Read_UINT32(s, call->cReaders);
3522 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3523 return ERROR_INVALID_DATA;
3525 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3526 &(call->handles.hContext));
3527 if (status != SCARD_S_SUCCESS)
3530 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3532 WLog_Print(log, WLOG_WARN,
3533 "LocateCardsByATRA_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3534 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3535 rgAtrMasksNdrPtr, call->cAtrs);
3536 return STATUS_INVALID_PARAMETER;
3539 if (rgAtrMasksNdrPtr)
3541 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3542 if (status != SCARD_S_SUCCESS)
3546 if (rgReaderStatesNdrPtr)
3549 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
3550 if (status != SCARD_S_SUCCESS)
3554 smartcard_trace_locate_cards_by_atr_a_call(log, call);
3555 return SCARD_S_SUCCESS;
3560 UINT32 sz1NdrPtr = 0;
3561 UINT32 sz2NdrPtr = 0;
3563 UINT32 pbContextNdrPtr = 0;
3566 wLog* log = scard_log();
3568 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3570 if (status != SCARD_S_SUCCESS)
3573 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3574 return ERROR_INVALID_DATA;
3575 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3576 return ERROR_INVALID_DATA;
3579 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3580 if (status != SCARD_S_SUCCESS)
3585 status = smartcard_ndr_read_a(log, s, &call->sz1, NDR_PTR_FULL);
3586 if (status != SCARD_S_SUCCESS)
3591 status = smartcard_ndr_read_a(log, s, &call->sz2, NDR_PTR_FULL);
3592 if (status != SCARD_S_SUCCESS)
3595 smartcard_trace_context_and_two_strings_a_call(log, call);
3596 return SCARD_S_SUCCESS;
3601 UINT32 sz1NdrPtr = 0;
3602 UINT32 sz2NdrPtr = 0;
3604 UINT32 pbContextNdrPtr = 0;
3607 wLog* log = scard_log();
3609 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3611 if (status != SCARD_S_SUCCESS)
3614 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3615 return ERROR_INVALID_DATA;
3616 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3617 return ERROR_INVALID_DATA;
3620 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3621 if (status != SCARD_S_SUCCESS)
3626 status = smartcard_ndr_read_w(log, s, &call->sz1, NDR_PTR_FULL);
3627 if (status != SCARD_S_SUCCESS)
3632 status = smartcard_ndr_read_w(log, s, &call->sz2, NDR_PTR_FULL);
3633 if (status != SCARD_S_SUCCESS)
3636 smartcard_trace_context_and_two_strings_w_call(log, call);
3637 return SCARD_S_SUCCESS;
3642 UINT32 sz1NdrPtr = 0;
3643 UINT32 sz2NdrPtr = 0;
3645 UINT32 pbContextNdrPtr = 0;
3648 wLog* log = scard_log();
3650 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3652 if (status != SCARD_S_SUCCESS)
3655 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3656 return STATUS_BUFFER_TOO_SMALL;
3658 Stream_Read_UINT32(s, call->cBytes);
3659 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3660 return ERROR_INVALID_DATA;
3662 Stream_Read_UINT32(s, call->cReaders);
3663 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3664 return ERROR_INVALID_DATA;
3666 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3667 &(call->handles.hContext));
3668 if (status != SCARD_S_SUCCESS)
3673 status = smartcard_ndr_read_fixed_string_a(log, s, &call->mszCards, call->cBytes,
3675 if (status != SCARD_S_SUCCESS)
3681 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
3682 if (status != SCARD_S_SUCCESS)
3685 smartcard_trace_locate_cards_a_call(log, call);
3686 return SCARD_S_SUCCESS;
3691 UINT32 sz1NdrPtr = 0;
3692 UINT32 sz2NdrPtr = 0;
3694 UINT32 pbContextNdrPtr = 0;
3697 wLog* log = scard_log();
3699 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3701 if (status != SCARD_S_SUCCESS)
3704 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3705 return STATUS_BUFFER_TOO_SMALL;
3707 Stream_Read_UINT32(s, call->cBytes);
3708 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3709 return ERROR_INVALID_DATA;
3711 Stream_Read_UINT32(s, call->cReaders);
3712 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3713 return ERROR_INVALID_DATA;
3715 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3716 &(call->handles.hContext));
3717 if (status != SCARD_S_SUCCESS)
3722 status = smartcard_ndr_read_fixed_string_w(log, s, &call->mszCards, call->cBytes,
3724 if (status != SCARD_S_SUCCESS)
3730 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
3731 if (status != SCARD_S_SUCCESS)
3734 smartcard_trace_locate_cards_w_call(log, call);
3735 return SCARD_S_SUCCESS;
3742 UINT32 pbContextNdrPtr = 0;
3745 wLog* log = scard_log();
3747 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3749 if (status != SCARD_S_SUCCESS)
3751 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3752 if (status != SCARD_S_SUCCESS)
3755 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3756 return STATUS_BUFFER_TOO_SMALL;
3757 Stream_Read_UINT32(s, call->dwAttrId);
3758 Stream_Read_UINT32(s, call->cbAttrLen);
3760 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
3761 return ERROR_INVALID_DATA;
3763 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3764 &(call->handles.hContext));
3765 if (status != SCARD_S_SUCCESS)
3768 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3769 if (status != SCARD_S_SUCCESS)
3775 status = smartcard_ndr_read_ex(log, s, &call->pbAttr, 0, 1, NDR_PTR_SIMPLE, &len);
3776 if (status != SCARD_S_SUCCESS)
3778 if (call->cbAttrLen > len)
3779 call->cbAttrLen = WINPR_ASSERTING_INT_CAST(DWORD, len);
3782 call->cbAttrLen = 0;
3783 smartcard_trace_set_attrib_call(log, call);
3784 return SCARD_S_SUCCESS;
3790 wLog* log = scard_log();
3793 smartcard_trace_set_attrib_call(log, call);
3795 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
3796 if (status != SCARD_S_SUCCESS)
3799 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
3800 if (status != SCARD_S_SUCCESS)
3803 if (!Stream_EnsureRemainingCapacity(s, 8))
3804 return SCARD_E_NO_MEMORY;
3806 Stream_Write_UINT32(s, call->dwAttrId);
3807 Stream_Write_UINT32(s, call->cbAttrLen);
3809 if (!smartcard_ndr_pointer_write(s, &index, call->cbAttrLen))
3810 return SCARD_E_NO_MEMORY;
3812 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
3813 if (status != SCARD_S_SUCCESS)
3816 status = smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
3817 if (status != SCARD_S_SUCCESS)
3820 status = smartcard_ndr_write(s, call->pbAttr, call->cbAttrLen, 1, NDR_PTR_SIMPLE);
3821 if (status != SCARD_S_SUCCESS)
3824 return SCARD_S_SUCCESS;
3829 UINT32 rgReaderStatesNdrPtr = 0;
3830 UINT32 rgAtrMasksNdrPtr = 0;
3832 UINT32 pbContextNdrPtr = 0;
3835 wLog* log = scard_log();
3837 call->rgReaderStates =
nullptr;
3839 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3841 if (status != SCARD_S_SUCCESS)
3844 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3845 return STATUS_BUFFER_TOO_SMALL;
3847 Stream_Read_UINT32(s, call->cAtrs);
3848 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3849 return ERROR_INVALID_DATA;
3851 Stream_Read_UINT32(s, call->cReaders);
3852 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3853 return ERROR_INVALID_DATA;
3855 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3856 &(call->handles.hContext));
3857 if (status != SCARD_S_SUCCESS)
3860 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3862 WLog_Print(log, WLOG_WARN,
3863 "LocateCardsByATRW_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3864 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3865 rgAtrMasksNdrPtr, call->cAtrs);
3866 return STATUS_INVALID_PARAMETER;
3869 if (rgAtrMasksNdrPtr)
3871 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3872 if (status != SCARD_S_SUCCESS)
3876 if (rgReaderStatesNdrPtr)
3879 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
3880 if (status != SCARD_S_SUCCESS)
3884 smartcard_trace_locate_cards_by_atr_w_call(log, call);
3885 return SCARD_S_SUCCESS;
3890 UINT32 mszNdrPtr = 0;
3891 UINT32 contextNdrPtr = 0;
3893 UINT32 pbContextNdrPtr = 0;
3896 wLog* log = scard_log();
3898 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3899 return ERROR_INVALID_DATA;
3901 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3902 &index, &pbContextNdrPtr);
3903 if (status != SCARD_S_SUCCESS)
3906 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3907 return ERROR_INVALID_DATA;
3909 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3910 return STATUS_BUFFER_TOO_SMALL;
3911 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3912 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
3913 Stream_Read_UINT32(s, call->Common.cbDataLen);
3915 call->szLookupName =
nullptr;
3918 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
3919 if (status != SCARD_S_SUCCESS)
3923 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3924 &call->Common.handles.hContext);
3925 if (status != SCARD_S_SUCCESS)
3930 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3931 if (status != SCARD_S_SUCCESS)
3934 smartcard_trace_read_cache_a_call(log, call);
3935 return SCARD_S_SUCCESS;
3940 UINT32 mszNdrPtr = 0;
3941 UINT32 contextNdrPtr = 0;
3943 UINT32 pbContextNdrPtr = 0;
3946 wLog* log = scard_log();
3948 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3949 return ERROR_INVALID_DATA;
3951 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3952 &index, &pbContextNdrPtr);
3953 if (status != SCARD_S_SUCCESS)
3956 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3957 return ERROR_INVALID_DATA;
3959 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3960 return STATUS_BUFFER_TOO_SMALL;
3961 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3962 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
3963 Stream_Read_UINT32(s, call->Common.cbDataLen);
3965 call->szLookupName =
nullptr;
3968 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
3969 if (status != SCARD_S_SUCCESS)
3973 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3974 &call->Common.handles.hContext);
3975 if (status != SCARD_S_SUCCESS)
3980 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3981 if (status != SCARD_S_SUCCESS)
3984 smartcard_trace_read_cache_w_call(log, call);
3985 return SCARD_S_SUCCESS;
3990 UINT32 mszNdrPtr = 0;
3991 UINT32 contextNdrPtr = 0;
3992 UINT32 pbDataNdrPtr = 0;
3994 UINT32 pbContextNdrPtr = 0;
3997 wLog* log = scard_log();
3999 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
4000 return ERROR_INVALID_DATA;
4002 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
4003 &index, &pbContextNdrPtr);
4004 if (status != SCARD_S_SUCCESS)
4007 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
4008 return ERROR_INVALID_DATA;
4010 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
4011 return STATUS_BUFFER_TOO_SMALL;
4013 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
4014 Stream_Read_UINT32(s, call->Common.cbDataLen);
4016 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
4017 return ERROR_INVALID_DATA;
4019 call->szLookupName =
nullptr;
4022 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
4023 if (status != SCARD_S_SUCCESS)
4027 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4028 &call->Common.handles.hContext);
4029 if (status != SCARD_S_SUCCESS)
4032 call->Common.CardIdentifier =
nullptr;
4035 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
4036 if (status != SCARD_S_SUCCESS)
4040 call->Common.pbData =
nullptr;
4043 status = smartcard_ndr_read(log, s, &call->Common.pbData, call->Common.cbDataLen, 1,
4045 if (status != SCARD_S_SUCCESS)
4048 smartcard_trace_write_cache_a_call(log, call);
4049 return SCARD_S_SUCCESS;
4054 UINT32 mszNdrPtr = 0;
4055 UINT32 contextNdrPtr = 0;
4056 UINT32 pbDataNdrPtr = 0;
4058 UINT32 pbContextNdrPtr = 0;
4061 wLog* log = scard_log();
4063 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
4064 return ERROR_INVALID_DATA;
4066 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
4067 &index, &pbContextNdrPtr);
4068 if (status != SCARD_S_SUCCESS)
4071 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
4072 return ERROR_INVALID_DATA;
4074 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
4075 return STATUS_BUFFER_TOO_SMALL;
4076 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
4077 Stream_Read_UINT32(s, call->Common.cbDataLen);
4079 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
4080 return ERROR_INVALID_DATA;
4082 call->szLookupName =
nullptr;
4085 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
4086 if (status != SCARD_S_SUCCESS)
4090 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4091 &call->Common.handles.hContext);
4092 if (status != SCARD_S_SUCCESS)
4095 call->Common.CardIdentifier =
nullptr;
4098 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
4099 if (status != SCARD_S_SUCCESS)
4103 call->Common.pbData =
nullptr;
4106 status = smartcard_ndr_read(log, s, &call->Common.pbData, call->Common.cbDataLen, 1,
4108 if (status != SCARD_S_SUCCESS)
4111 smartcard_trace_write_cache_w_call(log, call);
4118 wLog* log = scard_log();
4121 UINT32 pbContextNdrPtr = 0;
4123 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
4125 if (status != SCARD_S_SUCCESS)
4128 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
4129 if (status != SCARD_S_SUCCESS)
4132 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4133 &(call->handles.hContext));
4134 if (status != SCARD_S_SUCCESS)
4136 WLog_Print(log, WLOG_ERROR,
4137 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
4142 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
4143 if (status != SCARD_S_SUCCESS)
4144 WLog_Print(log, WLOG_ERROR,
4145 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
4147 smartcard_trace_get_transmit_count_call(log, call);
4154 wLog* log = scard_log();
4155 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
4156 &call->szReaderName);
4162 wLog* log = scard_log();
4163 return smartcard_unpack_common_context_and_string_a(log, s, &call->handles.hContext, &call->sz);
4169 wLog* log = scard_log();
4170 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext, &call->sz);
4176 wLog* log = scard_log();
4177 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
4178 &call->szReaderName);
4184 wLog* log = scard_log();
4185 smartcard_trace_device_type_id_return(log, ret);
4187 if (!Stream_EnsureRemainingCapacity(s, 4))
4189 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4190 return SCARD_F_INTERNAL_ERROR;
4193 Stream_Write_UINT32(s, ret->dwDeviceId);
4195 return ret->ReturnCode;
4201 wLog* log = scard_log();
4204 DWORD cbDataLen = ret->cReaders;
4207 smartcard_trace_locate_cards_return(log, ret);
4208 if (ret->ReturnCode != SCARD_S_SUCCESS)
4210 if (cbDataLen == SCARD_AUTOALLOCATE)
4213 if (!Stream_EnsureRemainingCapacity(s, 4))
4215 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4216 return SCARD_F_INTERNAL_ERROR;
4219 Stream_Write_UINT32(s, cbDataLen);
4220 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
4221 return SCARD_E_NO_MEMORY;
4223 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cbDataLen, NDR_PTR_SIMPLE);
4224 if (status != SCARD_S_SUCCESS)
4226 return ret->ReturnCode;
4232 wLog* log = scard_log();
4236 DWORD cbDataLen = ret->cbDataLen;
4237 smartcard_trace_get_reader_icon_return(log, ret);
4238 if (ret->ReturnCode != SCARD_S_SUCCESS)
4240 if (cbDataLen == SCARD_AUTOALLOCATE)
4243 if (!Stream_EnsureRemainingCapacity(s, 4))
4245 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4246 return SCARD_F_INTERNAL_ERROR;
4249 Stream_Write_UINT32(s, cbDataLen);
4250 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
4251 return SCARD_E_NO_MEMORY;
4253 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
4254 if (status != SCARD_S_SUCCESS)
4256 return ret->ReturnCode;
4262 wLog* log = scard_log();
4264 smartcard_trace_get_transmit_count_return(log, ret);
4266 if (!Stream_EnsureRemainingCapacity(s, 4))
4268 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4269 return SCARD_F_INTERNAL_ERROR;
4272 Stream_Write_UINT32(s, ret->cTransmitCount);
4274 return ret->ReturnCode;
4280 wLog* log = scard_log();
4284 DWORD cbDataLen = ret->cbDataLen;
4285 smartcard_trace_read_cache_return(log, ret);
4286 if (ret->ReturnCode != SCARD_S_SUCCESS)
4289 if (cbDataLen == SCARD_AUTOALLOCATE)
4292 if (!Stream_EnsureRemainingCapacity(s, 4))
4294 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4295 return SCARD_F_INTERNAL_ERROR;
4298 Stream_Write_UINT32(s, cbDataLen);
4299 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
4300 return SCARD_E_NO_MEMORY;
4302 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
4303 if (status != SCARD_S_SUCCESS)
4305 return ret->ReturnCode;
4311 wLog* log = scard_log();
4314 smartcard_trace_context_call(log, call, name);
4316 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4317 if (status != SCARD_S_SUCCESS)
4320 return smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4326 wLog* log = scard_log();
4329 smartcard_trace_list_readers_call(log, call, unicode);
4331 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4332 if (status != SCARD_S_SUCCESS)
4335 if (!Stream_EnsureRemainingCapacity(s, 4))
4336 return SCARD_E_NO_MEMORY;
4338 Stream_Write_UINT32(s, call->cBytes);
4339 if (!smartcard_ndr_pointer_write(s, &index, call->cBytes))
4340 return SCARD_E_NO_MEMORY;
4342 if (!Stream_EnsureRemainingCapacity(s, 8))
4343 return SCARD_E_NO_MEMORY;
4345 Stream_Write_INT32(s, call->fmszReadersIsNULL);
4346 Stream_Write_UINT32(s, call->cchReaders);
4348 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4349 if (status != SCARD_S_SUCCESS)
4352 if (call->cBytes > 0)
4354 status = smartcard_ndr_write(s, call->mszGroups, call->cBytes, 1, NDR_PTR_SIMPLE);
4355 if (status != SCARD_S_SUCCESS)
4359 return SCARD_S_SUCCESS;
4363 UINT32 cReaders, UINT32* ptrIndex)
4365 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
4367 if (!Stream_EnsureRemainingCapacity(s, 4))
4368 return SCARD_E_NO_MEMORY;
4370 Stream_Write_UINT32(s, cReaders);
4372 for (UINT32 i = 0; i < cReaders; i++)
4376 if (!Stream_EnsureRemainingCapacity(s, 52))
4377 return SCARD_E_NO_MEMORY;
4379 const DWORD nameLen = state->szReader ? (DWORD)(strlen(state->szReader) + 1) : 0;
4380 if (!smartcard_ndr_pointer_write(s, ptrIndex, nameLen))
4381 return SCARD_E_NO_MEMORY;
4383 Stream_Write_UINT32(s, state->dwCurrentState);
4384 Stream_Write_UINT32(s, state->dwEventState);
4385 Stream_Write_UINT32(s, state->cbAtr);
4386 Stream_Write(s, state->rgbAtr, 36);
4389 for (UINT32 i = 0; i < cReaders; i++)
4393 if (state->szReader)
4395 const UINT32 nameLen = (UINT32)(strlen(state->szReader) + 1);
4396 LONG status = smartcard_ndr_write_a(s, state->szReader, nameLen, NDR_PTR_FULL);
4397 if (status != SCARD_S_SUCCESS)
4402 return SCARD_S_SUCCESS;
4406 UINT32 cReaders, UINT32* ptrIndex)
4408 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
4410 if (!Stream_EnsureRemainingCapacity(s, 4))
4411 return SCARD_E_NO_MEMORY;
4413 Stream_Write_UINT32(s, cReaders);
4415 for (UINT32 i = 0; i < cReaders; i++)
4419 if (!Stream_EnsureRemainingCapacity(s, 52))
4420 return SCARD_E_NO_MEMORY;
4422 const DWORD nameLen = state->szReader ? (DWORD)(_wcslen(state->szReader) + 1) : 0;
4423 if (!smartcard_ndr_pointer_write(s, ptrIndex, nameLen))
4424 return SCARD_E_NO_MEMORY;
4426 Stream_Write_UINT32(s, state->dwCurrentState);
4427 Stream_Write_UINT32(s, state->dwEventState);
4428 Stream_Write_UINT32(s, state->cbAtr);
4429 Stream_Write(s, state->rgbAtr, 36);
4432 for (UINT32 i = 0; i < cReaders; i++)
4436 if (state->szReader)
4438 const UINT32 nameLen = (UINT32)(_wcslen(state->szReader) + 1);
4439 LONG status = smartcard_ndr_write_w(s, state->szReader, nameLen, NDR_PTR_FULL);
4440 if (status != SCARD_S_SUCCESS)
4445 return SCARD_S_SUCCESS;
4451 wLog* log = scard_log();
4454 smartcard_trace_get_status_change_a_call(log, call);
4456 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4457 if (status != SCARD_S_SUCCESS)
4460 if (!Stream_EnsureRemainingCapacity(s, 8))
4461 return SCARD_E_NO_MEMORY;
4463 Stream_Write_UINT32(s, call->dwTimeOut);
4464 Stream_Write_UINT32(s, call->cReaders);
4466 if (!smartcard_ndr_pointer_write(s, &index, call->cReaders))
4467 return SCARD_E_NO_MEMORY;
4469 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4470 if (status != SCARD_S_SUCCESS)
4473 if (call->cReaders > 0)
4475 status = smartcard_pack_reader_state_a(s, call->rgReaderStates, call->cReaders, &index);
4476 if (status != SCARD_S_SUCCESS)
4480 return SCARD_S_SUCCESS;
4486 wLog* log = scard_log();
4489 smartcard_trace_get_status_change_w_call(log, call);
4491 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4492 if (status != SCARD_S_SUCCESS)
4495 if (!Stream_EnsureRemainingCapacity(s, 8))
4496 return SCARD_E_NO_MEMORY;
4498 Stream_Write_UINT32(s, call->dwTimeOut);
4499 Stream_Write_UINT32(s, call->cReaders);
4501 if (!smartcard_ndr_pointer_write(s, &index, call->cReaders))
4502 return SCARD_E_NO_MEMORY;
4504 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4505 if (status != SCARD_S_SUCCESS)
4508 if (call->cReaders > 0)
4510 status = smartcard_pack_reader_state_w(s, call->rgReaderStates, call->cReaders, &index);
4511 if (status != SCARD_S_SUCCESS)
4515 return SCARD_S_SUCCESS;
4521 wLog* log = scard_log();
4524 smartcard_trace_connect_a_call(log, call);
4526 const DWORD readerLen = call->szReader ? (DWORD)(strlen(call->szReader) + 1) : 0;
4527 if (!smartcard_ndr_pointer_write(s, &index, readerLen))
4528 return SCARD_E_NO_MEMORY;
4531 smartcard_pack_redir_scard_context(log, s, &call->Common.handles.hContext, &index);
4532 if (status != SCARD_S_SUCCESS)
4535 if (!Stream_EnsureRemainingCapacity(s, 8))
4536 return SCARD_E_NO_MEMORY;
4538 Stream_Write_UINT32(s, call->Common.dwShareMode);
4539 Stream_Write_UINT32(s, call->Common.dwPreferredProtocols);
4543 status = smartcard_ndr_write_a(s, call->szReader, readerLen, NDR_PTR_FULL);
4544 if (status != SCARD_S_SUCCESS)
4548 return smartcard_pack_redir_scard_context_ref(log, s, &call->Common.handles.hContext);
4554 wLog* log = scard_log();
4557 smartcard_trace_connect_w_call(log, call);
4559 const DWORD readerLen = call->szReader ? (DWORD)(_wcslen(call->szReader) + 1) : 0;
4560 if (!smartcard_ndr_pointer_write(s, &index, readerLen))
4561 return SCARD_E_NO_MEMORY;
4564 smartcard_pack_redir_scard_context(log, s, &call->Common.handles.hContext, &index);
4565 if (status != SCARD_S_SUCCESS)
4568 if (!Stream_EnsureRemainingCapacity(s, 8))
4569 return SCARD_E_NO_MEMORY;
4571 Stream_Write_UINT32(s, call->Common.dwShareMode);
4572 Stream_Write_UINT32(s, call->Common.dwPreferredProtocols);
4576 status = smartcard_ndr_write_w(s, call->szReader, readerLen, NDR_PTR_FULL);
4577 if (status != SCARD_S_SUCCESS)
4581 return smartcard_pack_redir_scard_context_ref(log, s, &call->Common.handles.hContext);
4587 wLog* log = scard_log();
4590 smartcard_trace_control_call(log, call);
4592 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4593 if (status != SCARD_S_SUCCESS)
4596 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
4597 if (status != SCARD_S_SUCCESS)
4600 if (!Stream_EnsureRemainingCapacity(s, 8))
4601 return SCARD_E_NO_MEMORY;
4603 Stream_Write_UINT32(s, call->dwControlCode);
4604 Stream_Write_UINT32(s, call->cbInBufferSize);
4605 if (!smartcard_ndr_pointer_write(s, &index, call->cbInBufferSize))
4606 return SCARD_E_NO_MEMORY;
4608 Stream_Write_INT32(s, call->fpvOutBufferIsNULL);
4609 Stream_Write_UINT32(s, call->cbOutBufferSize);
4611 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4612 if (status != SCARD_S_SUCCESS)
4615 status = smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
4616 if (status != SCARD_S_SUCCESS)
4619 if (call->cbInBufferSize)
4621 status = smartcard_ndr_write(s, call->pvInBuffer, call->cbInBufferSize, 1, NDR_PTR_SIMPLE);
4622 if (status != SCARD_S_SUCCESS)
4633 wLog* log = scard_log();
4636 smartcard_trace_hcard_and_disposition_call(log, call, name);
4638 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4639 if (status != SCARD_S_SUCCESS)
4642 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
4643 if (status != SCARD_S_SUCCESS)
4646 if (!Stream_EnsureRemainingCapacity(s, 4))
4647 return SCARD_E_NO_MEMORY;
4649 Stream_Write_UINT32(s, call->dwDisposition);
4651 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4652 if (status != SCARD_S_SUCCESS)
4655 return smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
4661 wLog* log = scard_log();
4664 smartcard_trace_transmit_call(log, call);
4666 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4667 if (status != SCARD_S_SUCCESS)
4670 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
4671 if (status != SCARD_S_SUCCESS)
4674 UINT32 cbExtraBytes = 0;
4675 const BYTE* pbExtraBytes =
nullptr;
4676 if (call->pioSendPci)
4678 cbExtraBytes = (UINT32)(call->pioSendPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
4679 if (cbExtraBytes > 0)
4683 if (!Stream_EnsureRemainingCapacity(s, 32))
4684 return SCARD_E_NO_MEMORY;
4686 Stream_Write_UINT32(s, call->pioSendPci ? call->pioSendPci->dwProtocol : 0);
4687 Stream_Write_UINT32(s, cbExtraBytes);
4688 if (!smartcard_ndr_pointer_write(s, &index, cbExtraBytes))
4689 return SCARD_E_NO_MEMORY;
4691 Stream_Write_UINT32(s, call->cbSendLength);
4692 if (!smartcard_ndr_pointer_write(s, &index, call->cbSendLength))
4693 return SCARD_E_NO_MEMORY;
4695 const UINT32 recvPciLen = call->pioRecvPci ? (UINT32)call->pioRecvPci->cbPciLength : 0;
4696 if (!smartcard_ndr_pointer_write(s, &index, recvPciLen))
4697 return SCARD_E_NO_MEMORY;
4699 Stream_Write_INT32(s, call->fpbRecvBufferIsNULL);
4700 Stream_Write_UINT32(s, call->cbRecvLength);
4702 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4703 if (status != SCARD_S_SUCCESS)
4706 status = smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
4707 if (status != SCARD_S_SUCCESS)
4710 if (cbExtraBytes > 0)
4712 status = smartcard_ndr_write(s, pbExtraBytes, cbExtraBytes, 1, NDR_PTR_SIMPLE);
4713 if (status != SCARD_S_SUCCESS)
4717 if (call->cbSendLength > 0)
4719 status = smartcard_ndr_write(s, call->pbSendBuffer, call->cbSendLength, 1, NDR_PTR_SIMPLE);
4720 if (status != SCARD_S_SUCCESS)
4724 if (call->pioRecvPci && recvPciLen > 0)
4726 UINT32 cbRecvExtra = (UINT32)(call->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
4727 const BYTE* pbRecvExtra = &((
const BYTE*)call->pioRecvPci)[
sizeof(
SCARD_IO_REQUEST)];
4729 if (!Stream_EnsureRemainingCapacity(s, 12))
4730 return SCARD_E_NO_MEMORY;
4732 Stream_Write_UINT32(s, call->pioRecvPci->dwProtocol);
4733 Stream_Write_UINT32(s, cbRecvExtra);
4734 if (!smartcard_ndr_pointer_write(s, &index, cbRecvExtra))
4735 return SCARD_E_NO_MEMORY;
4737 if (cbRecvExtra > 0)
4739 status = smartcard_ndr_write(s, pbRecvExtra, cbRecvExtra, 1, NDR_PTR_SIMPLE);
4740 if (status != SCARD_S_SUCCESS)
4745 return SCARD_S_SUCCESS;
4751 wLog* log = scard_log();
4754 smartcard_trace_get_attrib_call(log, call);
4756 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4757 if (status != SCARD_S_SUCCESS)
4760 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
4761 if (status != SCARD_S_SUCCESS)
4764 if (!Stream_EnsureRemainingCapacity(s, 12))
4765 return STATUS_NO_MEMORY;
4767 Stream_Write_UINT32(s, call->dwAttrId);
4768 Stream_Write_INT32(s, call->fpbAttrIsNULL);
4769 Stream_Write_UINT32(s, call->cbAttrLen);
4771 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4772 if (status != SCARD_S_SUCCESS)
4775 return smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
4781 wLog* log = scard_log();
4783 UINT32 mszNdrPtr = 0;
4785 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
4786 return STATUS_BUFFER_TOO_SMALL;
4788 Stream_Read_UINT32(s, ret->cBytes);
4790 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
4791 return ERROR_INVALID_DATA;
4795 LONG status = smartcard_ndr_read(log, s, &ret->msz, ret->cBytes, 1, NDR_PTR_SIMPLE);
4796 if (status != SCARD_S_SUCCESS)
4800 smartcard_trace_list_readers_return(log, ret, unicode);
4801 return SCARD_S_SUCCESS;
4808 wLog* log = scard_log();
4812 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
4813 return STATUS_BUFFER_TOO_SMALL;
4815 Stream_Read_UINT32(s, ret->cReaders);
4817 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
4818 return ERROR_INVALID_DATA;
4820 if (ndrPtr && ret->cReaders > 0)
4823 smartcard_ndr_read_state(log, s, &ret->rgReaderStates, ret->cReaders, NDR_PTR_SIMPLE);
4824 if (status != SCARD_S_SUCCESS)
4828 ret->rgReaderStates =
nullptr;
4830 smartcard_trace_get_status_change_return(log, ret, unicode);
4831 return SCARD_S_SUCCESS;
4837 wLog* log = scard_log();
4839 UINT32 pbContextNdrPtr = 0;
4842 smartcard_unpack_redir_scard_context(log, s, &ret->hContext, &index, &pbContextNdrPtr);
4843 if (status != SCARD_S_SUCCESS)
4846 status = smartcard_unpack_redir_scard_handle(log, s, &ret->hCard, &index);
4847 if (status != SCARD_S_SUCCESS)
4850 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
4851 return STATUS_BUFFER_TOO_SMALL;
4853 Stream_Read_UINT32(s, ret->dwActiveProtocol);
4855 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &ret->hContext);
4856 if (status != SCARD_S_SUCCESS)
4859 status = smartcard_unpack_redir_scard_handle_ref(log, s, &ret->hCard);
4860 if (status != SCARD_S_SUCCESS)
4863 smartcard_trace_connect_return(log, ret);
4864 return SCARD_S_SUCCESS;
4870 wLog* log = scard_log();
4872 UINT32 pvOutBufferNdrPtr = 0;
4874 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
4875 return STATUS_BUFFER_TOO_SMALL;
4877 Stream_Read_UINT32(s, ret->cbOutBufferSize);
4879 if (!smartcard_ndr_pointer_read(log, s, &index, &pvOutBufferNdrPtr))
4880 return ERROR_INVALID_DATA;
4882 if (pvOutBufferNdrPtr && ret->cbOutBufferSize)
4885 smartcard_ndr_read(log, s, &ret->pvOutBuffer, ret->cbOutBufferSize, 1, NDR_PTR_SIMPLE);
4886 if (status != SCARD_S_SUCCESS)
4889 smartcard_trace_control_return(log, ret);
4890 return SCARD_S_SUCCESS;
4896 wLog* log = scard_log();
4898 UINT32 recvPciNdrPtr = 0;
4899 UINT32 recvBufferNdrPtr = 0;
4901 if (!smartcard_ndr_pointer_read(log, s, &index, &recvPciNdrPtr))
4902 return ERROR_INVALID_DATA;
4904 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
4905 return STATUS_BUFFER_TOO_SMALL;
4907 Stream_Read_UINT32(s, ret->cbRecvLength);
4909 if (!smartcard_ndr_pointer_read(log, s, &index, &recvBufferNdrPtr))
4910 return ERROR_INVALID_DATA;
4914 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
4915 return STATUS_BUFFER_TOO_SMALL;
4917 UINT32 dwProtocol = 0;
4918 UINT32 cbExtraBytes = 0;
4919 Stream_Read_UINT32(s, dwProtocol);
4920 Stream_Read_UINT32(s, cbExtraBytes);
4922 UINT32 pbExtraBytesNdrPtr = 0;
4923 if (!smartcard_ndr_pointer_read(log, s, &index, &pbExtraBytesNdrPtr))
4924 return ERROR_INVALID_DATA;
4926 if (pbExtraBytesNdrPtr)
4928 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
4929 return STATUS_BUFFER_TOO_SMALL;
4932 Stream_Read_UINT32(s, length);
4933 if (length != cbExtraBytes)
4935 WLog_Print(log, WLOG_WARN,
4936 "Transmit_Return unexpected length: Actual: %" PRIu32
4937 ", Expected: %" PRIu32
" (pioRecvPci.cbExtraBytes)",
4938 length, cbExtraBytes);
4939 return STATUS_INVALID_PARAMETER;
4942 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, cbExtraBytes))
4943 return STATUS_BUFFER_TOO_SMALL;
4946 if (!ret->pioRecvPci)
4947 return SCARD_E_NO_MEMORY;
4949 ret->pioRecvPci->dwProtocol = dwProtocol;
4950 ret->pioRecvPci->cbPciLength = (DWORD)(
sizeof(
SCARD_IO_REQUEST) + cbExtraBytes);
4953 Stream_Read(s, pbExtraBytes, length);
4954 if (smartcard_unpack_read_size_align(s, cbExtraBytes, 4) < 0)
4955 return STATUS_INVALID_PARAMETER;
4959 if (recvBufferNdrPtr && ret->cbRecvLength > 0)
4962 smartcard_ndr_read(log, s, &ret->pbRecvBuffer, ret->cbRecvLength, 1, NDR_PTR_SIMPLE);
4963 if (status != SCARD_S_SUCCESS)
4967 smartcard_trace_transmit_return(log, ret);
4968 return SCARD_S_SUCCESS;
4974 wLog* log = scard_log();
4976 UINT32 pbAttrPtr = 0;
4978 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
4979 return STATUS_BUFFER_TOO_SMALL;
4981 ret->cbAttrLen = Stream_Get_UINT32(s);
4983 if (!smartcard_ndr_pointer_read(log, s, &index, &pbAttrPtr))
4984 return ERROR_INVALID_DATA;
4986 LONG status = smartcard_ndr_read(log, s, &ret->pbAttr, ret->cbAttrLen, 1, NDR_PTR_SIMPLE);
4987 if (status != SCARD_S_SUCCESS)
4990 smartcard_trace_get_attrib_return(log, ret, 0);
4991 return SCARD_S_SUCCESS;