24#include <freerdp/config.h>
27#include <winpr/print.h>
29#include <freerdp/channels/scard.h>
30#include <freerdp/utils/smartcard_pack.h>
31#include "smartcard_pack.h"
33#include <freerdp/log.h>
34#define SCARD_TAG FREERDP_TAG("scard.pack")
36static const DWORD g_LogLevel = WLOG_DEBUG;
38static wLog* scard_log(
void)
40 static wLog* log =
nullptr;
42 log = WLog_Get(SCARD_TAG);
46#define smartcard_unpack_redir_scard_context(log, s, context, index, ndr) \
47 smartcard_unpack_redir_scard_context_((log), (s), (context), (index), (ndr), __FILE__, \
49#define smartcard_unpack_redir_scard_handle(log, s, context, index) \
50 smartcard_unpack_redir_scard_handle_((log), (s), (context), (index), __FILE__, __func__, \
53static LONG smartcard_unpack_redir_scard_context_(wLog* log,
wStream* s,
55 UINT32* ppbContextNdrPtr,
const char* file,
56 const char* function,
size_t line);
57static LONG smartcard_pack_redir_scard_context(wLog* log,
wStream* s,
60 UINT32* index,
const char* file,
61 const char* function,
size_t line);
62static LONG smartcard_pack_redir_scard_handle(wLog* log,
wStream* s,
64static LONG smartcard_unpack_redir_scard_context_ref(wLog* log,
wStream* s, UINT32 pbContextNdrPtr,
66static LONG smartcard_pack_redir_scard_context_ref(wLog* log,
wStream* s,
69static LONG smartcard_unpack_redir_scard_handle_ref(wLog* log,
wStream* s,
71static LONG smartcard_pack_redir_scard_handle_ref(wLog* log,
wStream* s,
83#define smartcard_ndr_pointer_read(log, s, index, ptr) \
84 smartcard_ndr_pointer_read_((log), (s), (index), (ptr), __FILE__, __func__, __LINE__)
85static BOOL smartcard_ndr_pointer_read_(wLog* log,
wStream* s, UINT32* index, UINT32* ptr,
86 const char* file,
const char* fkt,
size_t line)
88 const UINT32 expect = 0x20000 + (*index) * 4;
93 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
96 Stream_Read_UINT32(s, ndrPtr);
102 if (ptr && (ndrPtr == 0))
104 WLog_Print(log, WLOG_WARN,
105 "[%s:%" PRIuz
"] Read context pointer 0x%08" PRIx32
", expected 0x%08" PRIx32,
106 fkt, line, ndrPtr, expect);
110 (*index) = (*index) + 1;
114static LONG smartcard_ndr_read_ex(wLog* log,
wStream* s, BYTE** data,
size_t min,
115 size_t elementSize, ndr_ptr_t type,
size_t* plen)
139 return STATUS_INVALID_PARAMETER;
142 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, required))
143 return STATUS_BUFFER_TOO_SMALL;
148 Stream_Read_UINT32(s, len);
149 Stream_Read_UINT32(s, offset);
150 Stream_Read_UINT32(s, len2);
151 if (len != offset + len2)
153 WLog_Print(log, WLOG_ERROR,
154 "Invalid data when reading full NDR pointer: total=%" PRIuz
155 ", offset=%" PRIuz
", remaining=%" PRIuz,
157 return STATUS_BUFFER_TOO_SMALL;
161 Stream_Read_UINT32(s, len);
163 if ((len != min) && (min > 0))
165 WLog_Print(log, WLOG_ERROR,
166 "Invalid data when reading simple NDR pointer: total=%" PRIuz
167 ", expected=%" PRIuz,
169 return STATUS_BUFFER_TOO_SMALL;
176 return STATUS_INVALID_PARAMETER;
181 WLog_Print(log, WLOG_ERROR,
182 "Invalid length read from NDR pointer, minimum %" PRIuz
", got %" PRIuz, min,
184 return STATUS_DATA_ERROR;
187 if (len > SIZE_MAX / 2)
188 return STATUS_BUFFER_TOO_SMALL;
190 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(log, s, len, elementSize))
191 return STATUS_BUFFER_TOO_SMALL;
198 r = calloc(len +
sizeof(WCHAR),
sizeof(CHAR));
200 return SCARD_E_NO_MEMORY;
201 Stream_Read(s, r, len);
202 const LONG pad = smartcard_unpack_read_size_align(s, len, 4);
206 return STATUS_INVALID_PARAMETER;
212 return STATUS_SUCCESS;
215static LONG smartcard_ndr_read(wLog* log,
wStream* s, BYTE** data,
size_t min,
size_t elementSize,
218 return smartcard_ndr_read_ex(log, s, data, min, elementSize, type,
nullptr);
221static BOOL smartcard_ndr_pointer_write(
wStream* s, UINT32* index, DWORD length)
223 const UINT32 ndrPtr = 0x20000 + (*index) * 4;
227 if (!Stream_EnsureRemainingCapacity(s, 4))
232 Stream_Write_UINT32(s, ndrPtr);
233 (*index) = (*index) + 1;
236 Stream_Write_UINT32(s, 0);
240static LONG smartcard_ndr_write(
wStream* s,
const BYTE* data, UINT32 size, UINT32 elementSize,
243 const UINT32 offset = 0;
244 const UINT32 len = size;
245 const UINT32 dataLen = size * elementSize;
249 return SCARD_S_SUCCESS;
263 return SCARD_E_INVALID_PARAMETER;
266 if (!Stream_EnsureRemainingCapacity(s, required + dataLen + 4))
267 return STATUS_BUFFER_TOO_SMALL;
272 Stream_Write_UINT32(s, len);
273 Stream_Write_UINT32(s, offset);
274 Stream_Write_UINT32(s, len);
277 Stream_Write_UINT32(s, len);
282 return SCARD_E_INVALID_PARAMETER;
286 Stream_Write(s, data, dataLen);
288 Stream_Zero(s, dataLen);
289 return smartcard_pack_write_size_align(s, len, 4);
301 WINPR_ASSERT(data || (size == 0));
307 size_t min, ndr_ptr_t type)
315 const LONG status = smartcard_ndr_read(log, s, u.ppv, min,
sizeof(
LocateCards_ATRMask), type);
316 if (status != SCARD_S_SUCCESS)
323 for (
size_t x = 0; x < min; x++)
325 const UINT32 val = winpr_Data_Get_UINT32(&masks[x].cbAtr);
326 if (val > ARRAYSIZE(masks[x].rgbAtr))
328 WLog_Print(log, WLOG_ERROR,
329 "LocateCards_ATRMask[%" PRIuz
"]::cbAtr %" PRIu32
" exceeds %" PRIuz, x, val,
330 (
size_t)ARRAYSIZE(masks[x].rgbAtr));
333 return STATUS_DATA_ERROR;
336 return SCARD_S_SUCCESS;
339static LONG smartcard_ndr_read_fixed_string_a(wLog* log,
wStream* s, CHAR** data,
size_t min,
348 return smartcard_ndr_read(log, s, u.ppv, min,
sizeof(CHAR), type);
351static LONG smartcard_ndr_read_fixed_string_w(wLog* log,
wStream* s, WCHAR** data,
size_t min,
360 return smartcard_ndr_read(log, s, u.ppv, min,
sizeof(WCHAR), type);
363static LONG smartcard_ndr_read_a(wLog* log,
wStream* s, CHAR** data, ndr_ptr_t type)
371 return smartcard_ndr_read(log, s, u.ppv, 0,
sizeof(CHAR), type);
374static LONG smartcard_ndr_read_w(wLog* log,
wStream* s, WCHAR** data, ndr_ptr_t type)
382 return smartcard_ndr_read(log, s, u.ppv, 0,
sizeof(WCHAR), type);
385static LONG smartcard_ndr_read_u(wLog* log,
wStream* s,
UUID** data)
393 return smartcard_ndr_read(log, s, u.ppv, 1,
sizeof(
UUID), NDR_PTR_FIXED);
396static char* smartcard_convert_string_list(
const void* in,
size_t bytes, BOOL unicode)
405 char* mszA =
nullptr;
417 mszA = ConvertMszWCharNToUtf8Alloc(
string.wz, bytes /
sizeof(WCHAR), &length);
423 mszA = (
char*)calloc(bytes,
sizeof(
char));
426 CopyMemory(mszA,
string.sz, bytes - 1);
435 for (
size_t index = 0; index < length - 1; index++)
437 if (mszA[index] ==
'\0')
444WINPR_ATTR_MALLOC(free, 1)
445static
char* smartcard_create_msz_dump(const
char* msz,
size_t len)
447 size_t bufferLen = len;
448 char* buffer = calloc(len + 1, 1);
453 const char* cur = msz;
455 while ((len > 0) && cur && cur[0] !=
'\0' && (bufferLen > 0))
457 size_t clen = strnlen(cur, len);
458 int rc = _snprintf(buf, bufferLen,
"%s", cur);
459 bufferLen -= (size_t)rc;
468static void smartcard_msz_dump(wLog* log, DWORD level,
const char* prefix,
const void* data,
469 size_t len, BOOL wchar)
471 if (!WLog_IsLevelActive(log, level))
475 const char* msz = WINPR_CXX_COMPAT_CAST(
const char*, data);
479 tmp = ConvertMszWCharNToUtf8Alloc(data, len, &mszlen);
483 char* array = smartcard_create_msz_dump(msz, mszlen);
484 WLog_Print(log, level,
"%s%s", prefix, array);
489WINPR_ATTR_MALLOC(free, 1)
490static
char* smartcard_create_array_dump(const
void* pd,
size_t len)
492 const BYTE* data = pd;
495 size_t bufferLen = len * 4;
498 char* buffer = calloc(bufferLen + 1, 1);
501 char* start = buffer;
503 WINPR_ASSERT(buffer || (bufferLen == 0));
505 if (!data && (len > 0))
507 (void)_snprintf(buffer, bufferLen,
"{ nullptr [%" PRIuz
"] }", len);
511 rc = _snprintf(buffer, bufferLen,
"{ ");
512 if ((rc < 0) || ((
size_t)rc >= bufferLen))
515 bufferLen -= (size_t)rc;
517 for (
size_t x = 0; x < len; x++)
519 rc = _snprintf(buffer, bufferLen,
"%02X", data[x]);
520 if ((rc < 0) || ((
size_t)rc >= bufferLen))
523 bufferLen -= (size_t)rc;
526 rc = _snprintf(buffer, bufferLen,
" }");
527 if ((rc < 0) || ((
size_t)rc >= bufferLen))
534WINPR_ATTR_FORMAT_ARG(3, 7)
535static
void smartcard_dump_array(wLog* log, DWORD level, WINPR_FORMAT_ARG const
char* prefix,
536 const
char* postfix, const
void* data,
size_t len, ...)
538 if (!WLog_IsLevelActive(log, level))
541 char* buffer = smartcard_create_array_dump(data, len);
543 char* fprefix =
nullptr;
545 va_list ap = WINPR_C_ARRAY_INIT;
547 winpr_vasprintf(&fprefix, &flen, prefix, ap);
549 WLog_Print(log, level,
"%s%s%s", prefix, buffer, postfix);
554static void smartcard_log_redir_handle(wLog* log,
const REDIR_SCARDHANDLE* pHandle)
556 WINPR_ASSERT(pHandle);
557 smartcard_dump_array(log, g_LogLevel,
" hContext: ",
"", pHandle->pbHandle, pHandle->cbHandle);
562 WINPR_ASSERT(phContext);
563 smartcard_dump_array(log, g_LogLevel,
"hContext: ",
"", phContext->pbContext,
564 phContext->cbContext);
567static void smartcard_trace_context_and_string_call_a(wLog* log,
const char* name,
571 if (!WLog_IsLevelActive(log, g_LogLevel))
574 WLog_Print(log, g_LogLevel,
"%s {", name);
575 smartcard_log_context(log, phContext);
576 WLog_Print(log, g_LogLevel,
" sz=%s", sz);
578 WLog_Print(log, g_LogLevel,
"}");
581static void smartcard_trace_context_and_string_call_w(wLog* log,
const char* name,
587 if (!WLog_IsLevelActive(log, g_LogLevel))
591 tmp = ConvertWCharToUtf8Alloc(sz,
nullptr);
593 WLog_Print(log, g_LogLevel,
"%s {", name);
594 smartcard_log_context(log, phContext);
595 WLog_Print(log, g_LogLevel,
" sz=%s", tmp);
596 WLog_Print(log, g_LogLevel,
"}");
600static void smartcard_trace_context_call(wLog* log,
const Context_Call* call,
const char* name)
604 if (!WLog_IsLevelActive(log, g_LogLevel))
607 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
608 smartcard_log_context(log, &call->handles.hContext);
610 WLog_Print(log, g_LogLevel,
"}");
618 if (!WLog_IsLevelActive(log, g_LogLevel))
621 WLog_Print(log, g_LogLevel,
"ListReaderGroups%s_Call {", unicode ?
"W" :
"A");
622 smartcard_log_context(log, &call->handles.hContext);
624 WLog_Print(log, g_LogLevel,
"fmszGroupsIsNULL: %" PRId32
" cchGroups: 0x%08" PRIx32,
625 call->fmszGroupsIsNULL, call->cchGroups);
626 WLog_Print(log, g_LogLevel,
"}");
629static void dump_reader_states_return(wLog* log,
const ReaderState_Return* rgReaderStates,
632 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
633 for (UINT32 index = 0; index < cReaders; index++)
636 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
637 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
638 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
639 szCurrentState, readerState->dwCurrentState);
640 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
641 szEventState, readerState->dwEventState);
642 free(szCurrentState);
645 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
646 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
653 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
654 for (UINT32 index = 0; index < cReaders; index++)
658 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
659 readerState->szReader, readerState->cbAtr);
660 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
661 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
662 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
663 szCurrentState, readerState->dwCurrentState);
664 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
665 szEventState, readerState->dwEventState);
666 free(szCurrentState);
669 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
670 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
677 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
678 for (UINT32 index = 0; index < cReaders; index++)
681 char* buffer = ConvertWCharToUtf8Alloc(readerState->szReader,
nullptr);
682 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
683 buffer, readerState->cbAtr);
685 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
686 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
687 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
688 szCurrentState, readerState->dwCurrentState);
689 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
690 szEventState, readerState->dwEventState);
691 free(szCurrentState);
694 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
695 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
703 if (!WLog_IsLevelActive(log, g_LogLevel))
706 WLog_Print(log, g_LogLevel,
"GetStatusChangeW_Call {");
707 smartcard_log_context(log, &call->handles.hContext);
709 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
712 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
714 WLog_Print(log, g_LogLevel,
"}");
722 if (!WLog_IsLevelActive(log, g_LogLevel))
725 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
727 WLog_Print(log, g_LogLevel,
"ListReaderGroups%s_Return {", unicode ?
"W" :
"A");
728 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIx32
")",
729 SCardGetErrorString(ret->ReturnCode),
730 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
731 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
732 WLog_Print(log, g_LogLevel,
"}");
736static void smartcard_trace_list_readers_call(wLog* log,
const ListReaders_Call* call, BOOL unicode)
740 if (!WLog_IsLevelActive(log, g_LogLevel))
743 char* mszGroupsA = smartcard_convert_string_list(call->mszGroups, call->cBytes, unicode);
745 WLog_Print(log, g_LogLevel,
"ListReaders%s_Call {", unicode ?
"W" :
"A");
746 smartcard_log_context(log, &call->handles.hContext);
748 WLog_Print(log, g_LogLevel,
749 "cBytes: %" PRIu32
" mszGroups: %s fmszReadersIsNULL: %" PRId32
750 " cchReaders: 0x%08" PRIX32
"",
751 call->cBytes, mszGroupsA, call->fmszReadersIsNULL, call->cchReaders);
752 WLog_Print(log, g_LogLevel,
"}");
757static void smartcard_trace_locate_cards_by_atr_a_call(wLog* log,
762 if (!WLog_IsLevelActive(log, g_LogLevel))
765 WLog_Print(log, g_LogLevel,
"LocateCardsByATRA_Call {");
766 smartcard_log_context(log, &call->handles.hContext);
768 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
770 WLog_Print(log, g_LogLevel,
"}");
773static void smartcard_trace_locate_cards_a_call(wLog* log,
const LocateCardsA_Call* call)
777 if (!WLog_IsLevelActive(log, g_LogLevel))
780 WLog_Print(log, g_LogLevel,
"LocateCardsA_Call {");
781 smartcard_log_context(log, &call->handles.hContext);
782 WLog_Print(log, g_LogLevel,
" cBytes=%" PRIu32, call->cBytes);
783 smartcard_msz_dump(log, g_LogLevel,
" mszCards=", call->mszCards, call->cBytes, FALSE);
784 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, call->cReaders);
785 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
787 WLog_Print(log, g_LogLevel,
"}");
790static void smartcard_trace_locate_cards_return(wLog* log,
const LocateCards_Return* ret)
794 if (!WLog_IsLevelActive(log, g_LogLevel))
797 WLog_Print(log, g_LogLevel,
"LocateCards_Return {");
798 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
799 SCardGetErrorString(ret->ReturnCode),
800 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
802 if (ret->ReturnCode == SCARD_S_SUCCESS)
804 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, ret->cReaders);
806 WLog_Print(log, g_LogLevel,
"}");
813 if (!WLog_IsLevelActive(log, g_LogLevel))
816 WLog_Print(log, g_LogLevel,
"GetReaderIcon_Return {");
817 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
818 SCardGetErrorString(ret->ReturnCode),
819 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
821 if (ret->ReturnCode == SCARD_S_SUCCESS)
823 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, ret->cbDataLen);
825 WLog_Print(log, g_LogLevel,
"}");
832 if (!WLog_IsLevelActive(log, g_LogLevel))
835 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Return {");
836 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
837 SCardGetErrorString(ret->ReturnCode),
838 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
840 WLog_Print(log, g_LogLevel,
" cTransmitCount=%" PRIu32, ret->cTransmitCount);
841 WLog_Print(log, g_LogLevel,
"}");
844static void smartcard_trace_read_cache_return(wLog* log,
const ReadCache_Return* ret)
848 if (!WLog_IsLevelActive(log, g_LogLevel))
851 WLog_Print(log, g_LogLevel,
"ReadCache_Return {");
852 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
853 SCardGetErrorString(ret->ReturnCode),
854 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
856 if (ret->ReturnCode == SCARD_S_SUCCESS)
858 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, ret->cbDataLen);
859 smartcard_dump_array(log, g_LogLevel,
" cbData: ",
"", ret->pbData, ret->cbDataLen);
861 WLog_Print(log, g_LogLevel,
"}");
864static void smartcard_trace_locate_cards_w_call(wLog* log,
const LocateCardsW_Call* call)
868 if (!WLog_IsLevelActive(log, g_LogLevel))
871 WLog_Print(log, g_LogLevel,
"LocateCardsW_Call {");
872 smartcard_log_context(log, &call->handles.hContext);
873 WLog_Print(log, g_LogLevel,
" cBytes=%" PRIu32, call->cBytes);
874 smartcard_msz_dump(log, g_LogLevel,
" sz2=", call->mszCards, call->cBytes, TRUE);
875 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, call->cReaders);
876 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
877 WLog_Print(log, g_LogLevel,
"}");
880static void smartcard_trace_list_readers_return(wLog* log,
const ListReaders_Return* ret,
885 if (!WLog_IsLevelActive(log, g_LogLevel))
888 WLog_Print(log, g_LogLevel,
"ListReaders%s_Return {", unicode ?
"W" :
"A");
889 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
890 SCardGetErrorString(ret->ReturnCode),
891 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
893 if (ret->ReturnCode != SCARD_S_SUCCESS)
895 WLog_Print(log, g_LogLevel,
"}");
899 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
901 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
902 WLog_Print(log, g_LogLevel,
"}");
911 if (!WLog_IsLevelActive(log, g_LogLevel))
914 WLog_Print(log, g_LogLevel,
"GetStatusChange%s_Return {", unicode ?
"W" :
"A");
915 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
916 SCardGetErrorString(ret->ReturnCode),
917 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
918 WLog_Print(log, g_LogLevel,
" cReaders: %" PRIu32
"", ret->cReaders);
920 dump_reader_states_return(log, ret->rgReaderStates, ret->cReaders);
922 if (!ret->rgReaderStates && (ret->cReaders > 0))
924 WLog_Print(log, g_LogLevel,
" [INVALID STATE] rgReaderStates=nullptr, cReaders=%" PRIu32,
927 else if (ret->ReturnCode != SCARD_S_SUCCESS)
929 WLog_Print(log, g_LogLevel,
" [INVALID RETURN] rgReaderStates, cReaders=%" PRIu32,
934 for (UINT32 index = 0; index < ret->cReaders; index++)
937 char* szCurrentState = SCardGetReaderStateString(rgReaderState->dwCurrentState);
938 char* szEventState = SCardGetReaderStateString(rgReaderState->dwEventState);
939 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")",
940 index, szCurrentState, rgReaderState->dwCurrentState);
941 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")",
942 index, szEventState, rgReaderState->dwEventState);
943 smartcard_dump_array(
944 log, g_LogLevel,
" [%" PRIu32
"]: cbAtr: %" PRIu32
" rgbAtr: ",
"",
945 rgReaderState->rgbAtr, rgReaderState->cbAtr, index, rgReaderState->cbAtr);
946 free(szCurrentState);
951 WLog_Print(log, g_LogLevel,
"}");
954static void smartcard_trace_context_and_two_strings_a_call(wLog* log,
959 if (!WLog_IsLevelActive(log, g_LogLevel))
962 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
963 smartcard_log_context(log, &call->handles.hContext);
964 WLog_Print(log, g_LogLevel,
" sz1=%s", call->sz1);
965 WLog_Print(log, g_LogLevel,
" sz2=%s", call->sz2);
966 WLog_Print(log, g_LogLevel,
"}");
969static void smartcard_trace_context_and_two_strings_w_call(wLog* log,
973 char sz1[1024] = WINPR_C_ARRAY_INIT;
974 char sz2[1024] = WINPR_C_ARRAY_INIT;
976 if (!WLog_IsLevelActive(log, g_LogLevel))
979 (void)ConvertWCharToUtf8(call->sz1, sz1, ARRAYSIZE(sz1));
981 (void)ConvertWCharToUtf8(call->sz2, sz2, ARRAYSIZE(sz2));
983 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
984 smartcard_log_context(log, &call->handles.hContext);
985 WLog_Print(log, g_LogLevel,
" sz1=%s", sz1);
986 WLog_Print(log, g_LogLevel,
" sz2=%s", sz2);
987 WLog_Print(log, g_LogLevel,
"}");
994 if (!WLog_IsLevelActive(log, g_LogLevel))
997 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Call {");
998 smartcard_log_context(log, &call->handles.hContext);
999 smartcard_log_redir_handle(log, &call->handles.hCard);
1001 WLog_Print(log, g_LogLevel,
"}");
1004static void smartcard_trace_write_cache_a_call(wLog* log,
const WriteCacheA_Call* call)
1008 if (!WLog_IsLevelActive(log, g_LogLevel))
1011 WLog_Print(log, g_LogLevel,
"WriteCacheA_Call {");
1013 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
1015 smartcard_log_context(log, &call->Common.handles.hContext);
1016 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1018 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1019 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1020 smartcard_dump_array(log, g_LogLevel,
" pbData=",
"", call->Common.pbData,
1021 call->Common.cbDataLen);
1022 WLog_Print(log, g_LogLevel,
"}");
1025static void smartcard_trace_write_cache_w_call(wLog* log,
const WriteCacheW_Call* call)
1028 char tmp[1024] = WINPR_C_ARRAY_INIT;
1030 if (!WLog_IsLevelActive(log, g_LogLevel))
1033 WLog_Print(log, g_LogLevel,
"WriteCacheW_Call {");
1035 if (call->szLookupName)
1036 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
1037 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
1039 smartcard_log_context(log, &call->Common.handles.hContext);
1040 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1042 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1043 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1044 smartcard_dump_array(log, g_LogLevel,
" pbData=",
"", call->Common.pbData,
1045 call->Common.cbDataLen);
1046 WLog_Print(log, g_LogLevel,
"}");
1049static void smartcard_trace_read_cache_a_call(wLog* log,
const ReadCacheA_Call* call)
1053 if (!WLog_IsLevelActive(log, g_LogLevel))
1056 WLog_Print(log, g_LogLevel,
"ReadCacheA_Call {");
1058 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
1059 smartcard_log_context(log, &call->Common.handles.hContext);
1060 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1062 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1063 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1064 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1066 WLog_Print(log, g_LogLevel,
"}");
1069static void smartcard_trace_read_cache_w_call(wLog* log,
const ReadCacheW_Call* call)
1072 char tmp[1024] = WINPR_C_ARRAY_INIT;
1074 if (!WLog_IsLevelActive(log, g_LogLevel))
1077 WLog_Print(log, g_LogLevel,
"ReadCacheW_Call {");
1078 if (call->szLookupName)
1079 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
1080 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
1082 smartcard_log_context(log, &call->Common.handles.hContext);
1083 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1085 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1086 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1087 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1089 WLog_Print(log, g_LogLevel,
"}");
1092static void smartcard_trace_transmit_call(wLog* log,
const Transmit_Call* call)
1095 UINT32 cbExtraBytes = 0;
1096 BYTE* pbExtraBytes =
nullptr;
1098 if (!WLog_IsLevelActive(log, g_LogLevel))
1101 WLog_Print(log, g_LogLevel,
"Transmit_Call {");
1102 smartcard_log_context(log, &call->handles.hContext);
1103 smartcard_log_redir_handle(log, &call->handles.hCard);
1105 if (call->pioSendPci)
1107 cbExtraBytes = (UINT32)(call->pioSendPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1109 WLog_Print(log, g_LogLevel,
"pioSendPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1110 call->pioSendPci->dwProtocol, cbExtraBytes);
1114 smartcard_dump_array(log, g_LogLevel,
"pbExtraBytes: ",
"", pbExtraBytes, cbExtraBytes);
1119 WLog_Print(log, g_LogLevel,
"pioSendPci: null");
1122 WLog_Print(log, g_LogLevel,
"cbSendLength: %" PRIu32
"", call->cbSendLength);
1124 if (call->pbSendBuffer)
1126 smartcard_dump_array(log, g_LogLevel,
"pbSendBuffer: ",
"", call->pbSendBuffer,
1127 call->cbSendLength);
1131 WLog_Print(log, g_LogLevel,
"pbSendBuffer: null");
1134 if (call->pioRecvPci)
1136 cbExtraBytes = (UINT32)(call->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1138 WLog_Print(log, g_LogLevel,
"pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1139 call->pioRecvPci->dwProtocol, cbExtraBytes);
1143 smartcard_dump_array(log, g_LogLevel,
"pbExtraBytes: ",
"", pbExtraBytes, cbExtraBytes);
1148 WLog_Print(log, g_LogLevel,
"pioRecvPci: null");
1151 WLog_Print(log, g_LogLevel,
"fpbRecvBufferIsNULL: %" PRId32
" cbRecvLength: %" PRIu32
"",
1152 call->fpbRecvBufferIsNULL, call->cbRecvLength);
1153 WLog_Print(log, g_LogLevel,
"}");
1156static void smartcard_trace_locate_cards_by_atr_w_call(wLog* log,
1161 if (!WLog_IsLevelActive(log, g_LogLevel))
1164 WLog_Print(log, g_LogLevel,
"LocateCardsByATRW_Call {");
1165 smartcard_log_context(log, &call->handles.hContext);
1167 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
1169 WLog_Print(log, g_LogLevel,
"}");
1172static void smartcard_trace_transmit_return(wLog* log,
const Transmit_Return* ret)
1175 UINT32 cbExtraBytes = 0;
1176 BYTE* pbExtraBytes =
nullptr;
1178 if (!WLog_IsLevelActive(log, g_LogLevel))
1181 WLog_Print(log, g_LogLevel,
"Transmit_Return {");
1182 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1183 SCardGetErrorString(ret->ReturnCode),
1184 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1186 if (ret->pioRecvPci)
1188 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1190 WLog_Print(log, g_LogLevel,
1191 " pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1192 ret->pioRecvPci->dwProtocol, cbExtraBytes);
1196 smartcard_dump_array(log, g_LogLevel,
" pbExtraBytes: ",
"", pbExtraBytes,
1202 WLog_Print(log, g_LogLevel,
" pioRecvPci: null");
1205 WLog_Print(log, g_LogLevel,
" cbRecvLength: %" PRIu32
"", ret->cbRecvLength);
1207 if (ret->pbRecvBuffer)
1209 smartcard_dump_array(log, g_LogLevel,
" pbRecvBuffer: ",
"", ret->pbRecvBuffer,
1214 WLog_Print(log, g_LogLevel,
" pbRecvBuffer: null");
1217 WLog_Print(log, g_LogLevel,
"}");
1220static void smartcard_trace_control_return(wLog* log,
const Control_Return* ret)
1224 if (!WLog_IsLevelActive(log, g_LogLevel))
1227 WLog_Print(log, g_LogLevel,
"Control_Return {");
1228 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1229 SCardGetErrorString(ret->ReturnCode),
1230 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1231 WLog_Print(log, g_LogLevel,
" cbOutBufferSize: %" PRIu32
"", ret->cbOutBufferSize);
1233 if (ret->pvOutBuffer)
1235 smartcard_dump_array(log, g_LogLevel,
"pvOutBuffer: ",
"", ret->pvOutBuffer,
1236 ret->cbOutBufferSize);
1240 WLog_Print(log, g_LogLevel,
"pvOutBuffer: null");
1243 WLog_Print(log, g_LogLevel,
"}");
1246static void smartcard_trace_control_call(wLog* log,
const Control_Call* call)
1250 if (!WLog_IsLevelActive(log, g_LogLevel))
1253 WLog_Print(log, g_LogLevel,
"Control_Call {");
1254 smartcard_log_context(log, &call->handles.hContext);
1255 smartcard_log_redir_handle(log, &call->handles.hCard);
1257 WLog_Print(log, g_LogLevel,
1258 "dwControlCode: 0x%08" PRIX32
" cbInBufferSize: %" PRIu32
1259 " fpvOutBufferIsNULL: %" PRId32
" cbOutBufferSize: %" PRIu32
"",
1260 call->dwControlCode, call->cbInBufferSize, call->fpvOutBufferIsNULL,
1261 call->cbOutBufferSize);
1263 if (call->pvInBuffer)
1265 smartcard_dump_array(log, WLOG_DEBUG,
"pbInBuffer: ",
"", call->pvInBuffer,
1266 call->cbInBufferSize);
1270 WLog_Print(log, g_LogLevel,
"pvInBuffer: null");
1273 WLog_Print(log, g_LogLevel,
"}");
1276static void smartcard_trace_set_attrib_call(wLog* log,
const SetAttrib_Call* call)
1280 if (!WLog_IsLevelActive(log, g_LogLevel))
1283 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1284 smartcard_log_context(log, &call->handles.hContext);
1285 smartcard_log_redir_handle(log, &call->handles.hCard);
1286 WLog_Print(log, g_LogLevel,
"dwAttrId: 0x%08" PRIX32, call->dwAttrId);
1287 WLog_Print(log, g_LogLevel,
"cbAttrLen: 0x%08" PRIx32, call->cbAttrLen);
1288 smartcard_dump_array(log, g_LogLevel,
"pbAttr: ",
"", call->pbAttr, call->cbAttrLen);
1289 WLog_Print(log, g_LogLevel,
"}");
1292static void smartcard_trace_get_attrib_return(wLog* log,
const GetAttrib_Return* ret,
1297 if (!WLog_IsLevelActive(log, g_LogLevel))
1300 WLog_Print(log, g_LogLevel,
"GetAttrib_Return {");
1301 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1302 SCardGetErrorString(ret->ReturnCode),
1303 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1304 WLog_Print(log, g_LogLevel,
" dwAttrId: %s (0x%08" PRIX32
") cbAttrLen: 0x%08" PRIX32
"",
1305 SCardGetAttributeString(dwAttrId), dwAttrId, ret->cbAttrLen);
1306 smartcard_dump_array(log, g_LogLevel,
" ",
"", ret->pbAttr, ret->cbAttrLen);
1308 WLog_Print(log, g_LogLevel,
"}");
1311static void smartcard_trace_get_attrib_call(wLog* log,
const GetAttrib_Call* call)
1315 if (!WLog_IsLevelActive(log, g_LogLevel))
1318 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1319 smartcard_log_context(log, &call->handles.hContext);
1320 smartcard_log_redir_handle(log, &call->handles.hCard);
1322 WLog_Print(log, g_LogLevel,
1323 "dwAttrId: %s (0x%08" PRIX32
") fpbAttrIsNULL: %" PRId32
" cbAttrLen: 0x%08" PRIX32
1325 SCardGetAttributeString(call->dwAttrId), call->dwAttrId, call->fpbAttrIsNULL,
1327 WLog_Print(log, g_LogLevel,
"}");
1330static void smartcard_trace_status_call(wLog* log,
const Status_Call* call, BOOL unicode)
1334 if (!WLog_IsLevelActive(log, g_LogLevel))
1337 WLog_Print(log, g_LogLevel,
"Status%s_Call {", unicode ?
"W" :
"A");
1338 smartcard_log_context(log, &call->handles.hContext);
1339 smartcard_log_redir_handle(log, &call->handles.hCard);
1341 WLog_Print(log, g_LogLevel,
1342 "fmszReaderNamesIsNULL: %" PRId32
" cchReaderLen: %" PRIu32
" cbAtrLen: %" PRIu32
"",
1343 call->fmszReaderNamesIsNULL, call->cchReaderLen, call->cbAtrLen);
1344 WLog_Print(log, g_LogLevel,
"}");
1347static void smartcard_trace_status_return(wLog* log,
const Status_Return* ret, BOOL unicode)
1350 char* mszReaderNamesA =
nullptr;
1353 if (!WLog_IsLevelActive(log, g_LogLevel))
1355 cBytes = ret->cBytes;
1356 if (ret->ReturnCode != SCARD_S_SUCCESS)
1358 if (cBytes == SCARD_AUTOALLOCATE)
1360 mszReaderNamesA = smartcard_convert_string_list(ret->mszReaderNames, cBytes, unicode);
1362 WLog_Print(log, g_LogLevel,
"Status%s_Return {", unicode ?
"W" :
"A");
1363 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1364 SCardGetErrorString(ret->ReturnCode),
1365 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1366 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
") dwProtocol: %s (0x%08" PRIX32
")",
1367 SCardGetCardStateString(ret->dwState), ret->dwState,
1368 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1370 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" mszReaderNames: %s", ret->cBytes,
1373 smartcard_dump_array(log, g_LogLevel,
" cbAtrLen: %" PRIu32
" pbAtr: ",
"", ret->pbAtr,
1374 ret->cbAtrLen, ret->cbAtrLen);
1375 WLog_Print(log, g_LogLevel,
"}");
1376 free(mszReaderNamesA);
1379static void smartcard_trace_state_return(wLog* log,
const State_Return* ret)
1382 char* state =
nullptr;
1384 if (!WLog_IsLevelActive(log, g_LogLevel))
1387 state = SCardGetReaderStateString(ret->dwState);
1388 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1389 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1390 SCardGetErrorString(ret->ReturnCode),
1391 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1392 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
")", state, ret->dwState);
1393 WLog_Print(log, g_LogLevel,
" dwProtocol: %s (0x%08" PRIX32
")",
1394 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1395 WLog_Print(log, g_LogLevel,
" cbAtrLen: (0x%08" PRIX32
")", ret->cbAtrLen);
1396 smartcard_dump_array(log, g_LogLevel,
" rgAtr: ",
"", ret->rgAtr,
sizeof(ret->rgAtr));
1397 WLog_Print(log, g_LogLevel,
"}");
1401static void smartcard_trace_reconnect_return(wLog* log,
const Reconnect_Return* ret)
1405 if (!WLog_IsLevelActive(log, g_LogLevel))
1408 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1409 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1410 SCardGetErrorString(ret->ReturnCode),
1411 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1412 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1413 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1414 WLog_Print(log, g_LogLevel,
"}");
1417static void smartcard_trace_connect_a_call(wLog* log,
const ConnectA_Call* call)
1421 if (!WLog_IsLevelActive(log, g_LogLevel))
1424 WLog_Print(log, g_LogLevel,
"ConnectA_Call {");
1425 smartcard_log_context(log, &call->Common.handles.hContext);
1427 WLog_Print(log, g_LogLevel,
1428 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1429 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1430 call->szReader, SCardGetShareModeString(call->Common.dwShareMode),
1431 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1432 call->Common.dwPreferredProtocols);
1433 WLog_Print(log, g_LogLevel,
"}");
1436static void smartcard_trace_connect_w_call(wLog* log,
const ConnectW_Call* call)
1439 char szReaderA[1024] = WINPR_C_ARRAY_INIT;
1441 if (!WLog_IsLevelActive(log, g_LogLevel))
1445 (void)ConvertWCharToUtf8(call->szReader, szReaderA, ARRAYSIZE(szReaderA));
1446 WLog_Print(log, g_LogLevel,
"ConnectW_Call {");
1447 smartcard_log_context(log, &call->Common.handles.hContext);
1449 WLog_Print(log, g_LogLevel,
1450 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1451 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1452 szReaderA, SCardGetShareModeString(call->Common.dwShareMode),
1453 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1454 call->Common.dwPreferredProtocols);
1455 WLog_Print(log, g_LogLevel,
"}");
1458static void smartcard_trace_hcard_and_disposition_call(wLog* log,
1464 if (!WLog_IsLevelActive(log, g_LogLevel))
1467 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
1468 smartcard_log_context(log, &call->handles.hContext);
1469 smartcard_log_redir_handle(log, &call->handles.hCard);
1471 WLog_Print(log, g_LogLevel,
"dwDisposition: %s (0x%08" PRIX32
")",
1472 SCardGetDispositionString(call->dwDisposition), call->dwDisposition);
1473 WLog_Print(log, g_LogLevel,
"}");
1480 if (!WLog_IsLevelActive(log, g_LogLevel))
1483 WLog_Print(log, g_LogLevel,
"EstablishContext_Call {");
1484 WLog_Print(log, g_LogLevel,
"dwScope: %s (0x%08" PRIX32
")", SCardGetScopeString(call->dwScope),
1486 WLog_Print(log, g_LogLevel,
"}");
1493 if (!WLog_IsLevelActive(log, g_LogLevel))
1496 WLog_Print(log, g_LogLevel,
"EstablishContext_Return {");
1497 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1498 SCardGetErrorString(ret->ReturnCode),
1499 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1500 smartcard_log_context(log, &ret->hContext);
1502 WLog_Print(log, g_LogLevel,
"}");
1505void smartcard_trace_long_return(
const Long_Return* ret,
const char* name)
1507 wLog* log = scard_log();
1508 smartcard_trace_long_return_int(log, ret, name);
1511void smartcard_trace_long_return_int(wLog* log,
const Long_Return* ret,
const char* name)
1515 if (!WLog_IsLevelActive(log, g_LogLevel))
1518 WLog_Print(log, g_LogLevel,
"%s_Return {", name);
1519 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1520 SCardGetErrorString(ret->ReturnCode),
1521 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1522 WLog_Print(log, g_LogLevel,
"}");
1525static void smartcard_trace_connect_return(wLog* log,
const Connect_Return* ret)
1529 if (!WLog_IsLevelActive(log, g_LogLevel))
1532 WLog_Print(log, g_LogLevel,
"Connect_Return {");
1533 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1534 SCardGetErrorString(ret->ReturnCode),
1535 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1536 smartcard_log_context(log, &ret->hContext);
1537 smartcard_log_redir_handle(log, &ret->hCard);
1539 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1540 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1541 WLog_Print(log, g_LogLevel,
"}");
1544static void smartcard_trace_reconnect_call(wLog* log,
const Reconnect_Call* call)
1548 if (!WLog_IsLevelActive(log, g_LogLevel))
1551 WLog_Print(log, g_LogLevel,
"Reconnect_Call {");
1552 smartcard_log_context(log, &call->handles.hContext);
1553 smartcard_log_redir_handle(log, &call->handles.hCard);
1555 WLog_Print(log, g_LogLevel,
1556 "dwShareMode: %s (0x%08" PRIX32
") dwPreferredProtocols: %s (0x%08" PRIX32
1557 ") dwInitialization: %s (0x%08" PRIX32
")",
1558 SCardGetShareModeString(call->dwShareMode), call->dwShareMode,
1559 SCardGetProtocolString(call->dwPreferredProtocols), call->dwPreferredProtocols,
1560 SCardGetDispositionString(call->dwInitialization), call->dwInitialization);
1561 WLog_Print(log, g_LogLevel,
"}");
1568 if (!WLog_IsLevelActive(log, g_LogLevel))
1571 WLog_Print(log, g_LogLevel,
"GetDeviceTypeId_Return {");
1572 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1573 SCardGetErrorString(ret->ReturnCode),
1574 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1575 WLog_Print(log, g_LogLevel,
" dwDeviceId=%08" PRIx32, ret->dwDeviceId);
1577 WLog_Print(log, g_LogLevel,
"}");
1580static LONG smartcard_unpack_common_context_and_string_a(wLog* log,
wStream* s,
1582 CHAR** pszReaderName)
1585 UINT32 pbContextNdrPtr = 0;
1586 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1587 if (status != SCARD_S_SUCCESS)
1590 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
1591 return ERROR_INVALID_DATA;
1593 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1594 if (status != SCARD_S_SUCCESS)
1597 status = smartcard_ndr_read_a(log, s, pszReaderName, NDR_PTR_FULL);
1598 if (status != SCARD_S_SUCCESS)
1601 smartcard_trace_context_and_string_call_a(log, __func__, phContext, *pszReaderName);
1602 return SCARD_S_SUCCESS;
1605static LONG smartcard_unpack_common_context_and_string_w(wLog* log,
wStream* s,
1607 WCHAR** pszReaderName)
1610 UINT32 pbContextNdrPtr = 0;
1612 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1613 if (status != SCARD_S_SUCCESS)
1616 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
1617 return ERROR_INVALID_DATA;
1619 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1620 if (status != SCARD_S_SUCCESS)
1623 status = smartcard_ndr_read_w(log, s, pszReaderName, NDR_PTR_FULL);
1624 if (status != SCARD_S_SUCCESS)
1627 smartcard_trace_context_and_string_call_w(log, __func__, phContext, *pszReaderName);
1628 return SCARD_S_SUCCESS;
1631LONG smartcard_unpack_common_type_header(
wStream* s)
1633 wLog* log = scard_log();
1636 UINT8 endianness = 0;
1637 UINT16 commonHeaderLength = 0;
1639 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1640 return STATUS_BUFFER_TOO_SMALL;
1643 Stream_Read_UINT8(s, version);
1644 Stream_Read_UINT8(s, endianness);
1645 Stream_Read_UINT16(s, commonHeaderLength);
1646 Stream_Read_UINT32(s, filler);
1650 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Version %" PRIu8
"", version);
1651 return STATUS_INVALID_PARAMETER;
1654 if (endianness != 0x10)
1656 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Endianness %" PRIu8
"",
1658 return STATUS_INVALID_PARAMETER;
1661 if (commonHeaderLength != 8)
1663 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader CommonHeaderLength %" PRIu16
"",
1664 commonHeaderLength);
1665 return STATUS_INVALID_PARAMETER;
1668 if (filler != 0xCCCCCCCC)
1670 WLog_Print(log, WLOG_WARN,
"Unexpected CommonTypeHeader Filler 0x%08" PRIX32
"", filler);
1671 return STATUS_INVALID_PARAMETER;
1674 return SCARD_S_SUCCESS;
1677void smartcard_pack_common_type_header(
wStream* s)
1679 Stream_Write_UINT8(s, 1);
1680 Stream_Write_UINT8(s, 0x10);
1681 Stream_Write_UINT16(s, 8);
1682 Stream_Write_UINT32(s, 0xCCCCCCCC);
1685LONG smartcard_unpack_private_type_header(
wStream* s)
1687 wLog* log = scard_log();
1689 UINT32 objectBufferLength = 0;
1691 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1692 return STATUS_BUFFER_TOO_SMALL;
1694 Stream_Read_UINT32(s, objectBufferLength);
1695 Stream_Read_UINT32(s, filler);
1697 if (filler != 0x00000000)
1699 WLog_Print(log, WLOG_WARN,
"Unexpected PrivateTypeHeader Filler 0x%08" PRIX32
"", filler);
1700 return STATUS_INVALID_PARAMETER;
1703 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, objectBufferLength))
1704 return STATUS_INVALID_PARAMETER;
1706 return SCARD_S_SUCCESS;
1709void smartcard_pack_private_type_header(
wStream* s, UINT32 objectBufferLength)
1711 Stream_Write_UINT32(s, objectBufferLength);
1712 Stream_Write_UINT32(s, 0x00000000);
1715LONG smartcard_unpack_read_size_align(
wStream* s,
size_t size, UINT32 alignment)
1717 const size_t padsize = (size + alignment - 1) & ~(alignment - 1);
1718 const size_t pad = padsize - size;
1722 if (!Stream_SafeSeek(s, pad))
1729LONG smartcard_pack_write_size_align(
wStream* s,
size_t size, UINT32 alignment)
1731 const size_t padsize = (size + alignment - 1) & ~(alignment - 1);
1732 const size_t pad = padsize - size;
1736 if (!Stream_EnsureRemainingCapacity(s, pad))
1738 wLog* log = scard_log();
1739 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
1740 return SCARD_F_INTERNAL_ERROR;
1743 Stream_Zero(s, pad);
1746 return SCARD_S_SUCCESS;
1751 SCARDCONTEXT hContext = WINPR_C_ARRAY_INIT;
1753 WINPR_ASSERT(context);
1754 if ((context->cbContext !=
sizeof(ULONG_PTR)) && (context->cbContext != 0))
1756 wLog* log = scard_log();
1757 WLog_Print(log, WLOG_WARN,
1758 "REDIR_SCARDCONTEXT does not match native size: Actual: %" PRIu32
1759 ", Expected: %" PRIuz
"",
1760 context->cbContext,
sizeof(ULONG_PTR));
1764 if (context->cbContext)
1765 CopyMemory(&hContext, &(context->pbContext), context->cbContext);
1770void smartcard_scard_context_native_to_redir(
REDIR_SCARDCONTEXT* context, SCARDCONTEXT hContext)
1772 WINPR_ASSERT(context);
1774 context->cbContext =
sizeof(ULONG_PTR);
1775 CopyMemory(&(context->pbContext), &hContext, context->cbContext);
1780 SCARDHANDLE hCard = 0;
1782 WINPR_ASSERT(handle);
1783 if (handle->cbHandle == 0)
1786 if (handle->cbHandle !=
sizeof(ULONG_PTR))
1788 wLog* log = scard_log();
1789 WLog_Print(log, WLOG_WARN,
1790 "REDIR_SCARDHANDLE does not match native size: Actual: %" PRIu32
1791 ", Expected: %" PRIuz
"",
1792 handle->cbHandle,
sizeof(ULONG_PTR));
1796 if (handle->cbHandle)
1797 CopyMemory(&hCard, &(handle->pbHandle), handle->cbHandle);
1802void smartcard_scard_handle_native_to_redir(
REDIR_SCARDHANDLE* handle, SCARDHANDLE hCard)
1804 WINPR_ASSERT(handle);
1806 handle->cbHandle =
sizeof(ULONG_PTR);
1807 CopyMemory(&(handle->pbHandle), &hCard, handle->cbHandle);
1810#define smartcard_context_supported(log, size) \
1811 smartcard_context_supported_((log), (size), __FILE__, __func__, __LINE__)
1812static LONG smartcard_context_supported_(wLog* log, uint32_t size,
const char* file,
1813 const char* fkt,
size_t line)
1820 return SCARD_S_SUCCESS;
1823 const uint32_t level = WLOG_WARN;
1824 if (WLog_IsLevelActive(log, level))
1826 WLog_PrintTextMessage(log, level, line, file, fkt,
1827 "REDIR_SCARDCONTEXT length is not 0, 4 or 8: %" PRIu32
"",
1830 return STATUS_INVALID_PARAMETER;
1836 UINT32* index, UINT32* ppbContextNdrPtr,
1837 const char* file,
const char* function,
size_t line)
1839 UINT32 pbContextNdrPtr = 0;
1842 WINPR_ASSERT(context);
1846 if (!Stream_CheckAndLogRequiredLengthWLogEx(log, WLOG_WARN, s, 4, 1,
"%s(%s:%" PRIuz
")", file,
1848 return STATUS_BUFFER_TOO_SMALL;
1850 const LONG status = smartcard_context_supported_(log, context->cbContext, file, function, line);
1851 if (status != SCARD_S_SUCCESS)
1854 Stream_Read_UINT32(s, context->cbContext);
1856 if (!smartcard_ndr_pointer_read_(log, s, index, &pbContextNdrPtr, file, function, line))
1857 return ERROR_INVALID_DATA;
1859 if (((context->cbContext == 0) && pbContextNdrPtr) ||
1860 ((context->cbContext != 0) && !pbContextNdrPtr))
1862 WLog_Print(log, WLOG_WARN,
1863 "REDIR_SCARDCONTEXT cbContext (%" PRIu32
") pbContextNdrPtr (%" PRIu32
1865 context->cbContext, pbContextNdrPtr);
1866 return STATUS_INVALID_PARAMETER;
1869 if (!Stream_CheckAndLogRequiredLengthWLogEx(log, WLOG_WARN, s, context->cbContext, 1,
1870 "%s(%s:%" PRIuz
")", file, function, line))
1871 return STATUS_INVALID_PARAMETER;
1873 *ppbContextNdrPtr = pbContextNdrPtr;
1874 return SCARD_S_SUCCESS;
1877LONG smartcard_pack_redir_scard_context(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1880 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
1882 WINPR_ASSERT(context);
1883 if (context->cbContext != 0)
1885 Stream_Write_UINT32(s, context->cbContext);
1886 Stream_Write_UINT32(s, pbContextNdrPtr);
1887 *index = *index + 1;
1892 return SCARD_S_SUCCESS;
1895LONG smartcard_unpack_redir_scard_context_ref(wLog* log,
wStream* s,
1896 WINPR_ATTR_UNUSED UINT32 pbContextNdrPtr,
1901 WINPR_ASSERT(context);
1902 if (context->cbContext == 0)
1903 return SCARD_S_SUCCESS;
1905 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1906 return STATUS_BUFFER_TOO_SMALL;
1908 Stream_Read_UINT32(s, length);
1910 if (length != context->cbContext)
1912 WLog_Print(log, WLOG_WARN,
1913 "REDIR_SCARDCONTEXT length (%" PRIu32
") cbContext (%" PRIu32
") mismatch",
1914 length, context->cbContext);
1915 return STATUS_INVALID_PARAMETER;
1918 const LONG status = smartcard_context_supported(log, context->cbContext);
1919 if (status != SCARD_S_SUCCESS)
1922 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, context->cbContext))
1923 return STATUS_BUFFER_TOO_SMALL;
1925 if (context->cbContext)
1926 Stream_Read(s, &(context->pbContext), context->cbContext);
1928 ZeroMemory(&(context->pbContext),
sizeof(context->pbContext));
1930 return SCARD_S_SUCCESS;
1933LONG smartcard_pack_redir_scard_context_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1936 WINPR_ASSERT(context);
1937 Stream_Write_UINT32(s, context->cbContext);
1939 if (context->cbContext)
1941 Stream_Write(s, &(context->pbContext), context->cbContext);
1944 return SCARD_S_SUCCESS;
1948 UINT32* index,
const char* file,
const char* function,
1951 WINPR_ASSERT(handle);
1954 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1955 return STATUS_BUFFER_TOO_SMALL;
1957 Stream_Read_UINT32(s, handle->cbHandle);
1959 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, handle->cbHandle))
1960 return STATUS_BUFFER_TOO_SMALL;
1962 if (!smartcard_ndr_pointer_read_(log, s, index,
nullptr, file, function, line))
1963 return ERROR_INVALID_DATA;
1965 return SCARD_S_SUCCESS;
1968LONG smartcard_pack_redir_scard_handle(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1971 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
1973 WINPR_ASSERT(handle);
1974 if (handle->cbHandle != 0)
1976 Stream_Write_UINT32(s, handle->cbHandle);
1977 Stream_Write_UINT32(s, pbContextNdrPtr);
1978 *index = *index + 1;
1982 return SCARD_S_SUCCESS;
1989 WINPR_ASSERT(handle);
1990 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1991 return STATUS_BUFFER_TOO_SMALL;
1993 Stream_Read_UINT32(s, length);
1995 if (length != handle->cbHandle)
1997 WLog_Print(log, WLOG_WARN,
1998 "REDIR_SCARDHANDLE length (%" PRIu32
") cbHandle (%" PRIu32
") mismatch", length,
2000 return STATUS_INVALID_PARAMETER;
2003 if ((handle->cbHandle != 4) && (handle->cbHandle != 8))
2005 WLog_Print(log, WLOG_WARN,
"REDIR_SCARDHANDLE length is not 4 or 8: %" PRIu32
"",
2007 return STATUS_INVALID_PARAMETER;
2010 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, handle->cbHandle))
2011 return STATUS_BUFFER_TOO_SMALL;
2013 if (handle->cbHandle)
2014 Stream_Read(s, &(handle->pbHandle), handle->cbHandle);
2016 return SCARD_S_SUCCESS;
2019LONG smartcard_pack_redir_scard_handle_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
2022 WINPR_ASSERT(handle);
2023 Stream_Write_UINT32(s, handle->cbHandle);
2025 if (handle->cbHandle)
2026 Stream_Write(s, &(handle->pbHandle), handle->cbHandle);
2028 return SCARD_S_SUCCESS;
2034 wLog* log = scard_log();
2036 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2037 return STATUS_BUFFER_TOO_SMALL;
2039 Stream_Read_UINT32(s, call->dwScope);
2040 smartcard_trace_establish_context_call(log, call);
2041 return SCARD_S_SUCCESS;
2047 wLog* log = scard_log();
2051 smartcard_trace_establish_context_return(log, ret);
2052 if (ret->ReturnCode != SCARD_S_SUCCESS)
2053 return ret->ReturnCode;
2055 status = smartcard_pack_redir_scard_context(log, s, &(ret->hContext), &index);
2056 if (status != SCARD_S_SUCCESS)
2059 return smartcard_pack_redir_scard_context_ref(log, s, &(ret->hContext));
2065 UINT32 pbContextNdrPtr = 0;
2066 wLog* log = scard_log();
2069 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2071 if (status != SCARD_S_SUCCESS)
2074 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2075 &(call->handles.hContext));
2076 if (status != SCARD_S_SUCCESS)
2077 WLog_Print(log, WLOG_ERROR,
2078 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2081 smartcard_trace_context_call(log, call, name);
2088 UINT32 pbContextNdrPtr = 0;
2089 wLog* log = scard_log();
2092 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2095 if (status != SCARD_S_SUCCESS)
2098 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2099 return STATUS_BUFFER_TOO_SMALL;
2101 Stream_Read_INT32(s, call->fmszGroupsIsNULL);
2102 Stream_Read_UINT32(s, call->cchGroups);
2103 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2104 &(call->handles.hContext));
2106 if (status != SCARD_S_SUCCESS)
2109 smartcard_trace_list_reader_groups_call(log, call, unicode);
2110 return SCARD_S_SUCCESS;
2117 wLog* log = scard_log();
2119 DWORD cBytes = ret->cBytes;
2122 smartcard_trace_list_reader_groups_return(log, ret, unicode);
2123 if (ret->ReturnCode != SCARD_S_SUCCESS)
2125 if (cBytes == SCARD_AUTOALLOCATE)
2128 if (!Stream_EnsureRemainingCapacity(s, 4))
2129 return SCARD_E_NO_MEMORY;
2131 Stream_Write_UINT32(s, cBytes);
2132 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
2133 return SCARD_E_NO_MEMORY;
2135 status = smartcard_ndr_write(s, ret->msz, cBytes, 1, NDR_PTR_SIMPLE);
2136 if (status != SCARD_S_SUCCESS)
2138 return ret->ReturnCode;
2144 UINT32 mszGroupsNdrPtr = 0;
2145 UINT32 pbContextNdrPtr = 0;
2146 wLog* log = scard_log();
2149 call->mszGroups =
nullptr;
2151 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2153 if (status != SCARD_S_SUCCESS)
2156 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2157 return STATUS_BUFFER_TOO_SMALL;
2159 Stream_Read_UINT32(s, call->cBytes);
2160 if (!smartcard_ndr_pointer_read(log, s, &index, &mszGroupsNdrPtr))
2161 return ERROR_INVALID_DATA;
2163 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2164 return STATUS_BUFFER_TOO_SMALL;
2165 Stream_Read_INT32(s, call->fmszReadersIsNULL);
2166 Stream_Read_UINT32(s, call->cchReaders);
2168 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2169 &(call->handles.hContext));
2170 if (status != SCARD_S_SUCCESS)
2173 if (mszGroupsNdrPtr)
2175 status = smartcard_ndr_read(log, s, &call->mszGroups, call->cBytes, 1, NDR_PTR_SIMPLE);
2176 if (status != SCARD_S_SUCCESS)
2180 smartcard_trace_list_readers_call(log, call, unicode);
2181 return SCARD_S_SUCCESS;
2187 wLog* log = scard_log();
2190 UINT32 size = ret->cBytes;
2192 smartcard_trace_list_readers_return(log, ret, unicode);
2193 if (ret->ReturnCode != SCARD_S_SUCCESS)
2196 if (!Stream_EnsureRemainingCapacity(s, 4))
2198 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
2199 return SCARD_F_INTERNAL_ERROR;
2202 Stream_Write_UINT32(s, size);
2203 if (!smartcard_ndr_pointer_write(s, &index, size))
2204 return SCARD_E_NO_MEMORY;
2206 status = smartcard_ndr_write(s, ret->msz, size, 1, NDR_PTR_SIMPLE);
2207 if (status != SCARD_S_SUCCESS)
2209 return ret->ReturnCode;
2213 UINT32* index, UINT32* ppbContextNdrPtr)
2215 WINPR_ASSERT(common);
2216 LONG status = smartcard_unpack_redir_scard_context(log, s, &(common->handles.hContext), index,
2218 if (status != SCARD_S_SUCCESS)
2221 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2222 return STATUS_BUFFER_TOO_SMALL;
2224 Stream_Read_UINT32(s, common->dwShareMode);
2225 Stream_Read_UINT32(s, common->dwPreferredProtocols);
2226 return SCARD_S_SUCCESS;
2233 UINT32 pbContextNdrPtr = 0;
2236 wLog* log = scard_log();
2238 call->szReader =
nullptr;
2240 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
2241 return ERROR_INVALID_DATA;
2243 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2244 if (status != SCARD_S_SUCCESS)
2246 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2251 status = smartcard_ndr_read_a(log, s, &call->szReader, NDR_PTR_FULL);
2252 if (status != SCARD_S_SUCCESS)
2255 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2256 &(call->Common.handles.hContext));
2257 if (status != SCARD_S_SUCCESS)
2258 WLog_Print(log, WLOG_ERROR,
2259 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2262 smartcard_trace_connect_a_call(log, call);
2270 UINT32 pbContextNdrPtr = 0;
2273 wLog* log = scard_log();
2274 call->szReader =
nullptr;
2276 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
2277 return ERROR_INVALID_DATA;
2279 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2280 if (status != SCARD_S_SUCCESS)
2282 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2287 status = smartcard_ndr_read_w(log, s, &call->szReader, NDR_PTR_FULL);
2288 if (status != SCARD_S_SUCCESS)
2291 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2292 &(call->Common.handles.hContext));
2293 if (status != SCARD_S_SUCCESS)
2294 WLog_Print(log, WLOG_ERROR,
2295 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2298 smartcard_trace_connect_w_call(log, call);
2308 wLog* log = scard_log();
2309 smartcard_trace_connect_return(log, ret);
2311 status = smartcard_pack_redir_scard_context(log, s, &ret->hContext, &index);
2312 if (status != SCARD_S_SUCCESS)
2315 status = smartcard_pack_redir_scard_handle(log, s, &ret->hCard, &index);
2316 if (status != SCARD_S_SUCCESS)
2319 if (!Stream_EnsureRemainingCapacity(s, 4))
2320 return SCARD_E_NO_MEMORY;
2322 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2323 status = smartcard_pack_redir_scard_context_ref(log, s, &ret->hContext);
2324 if (status != SCARD_S_SUCCESS)
2326 return smartcard_pack_redir_scard_handle_ref(log, s, &(ret->hCard));
2332 UINT32 pbContextNdrPtr = 0;
2335 wLog* log = scard_log();
2336 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2338 if (status != SCARD_S_SUCCESS)
2341 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2342 if (status != SCARD_S_SUCCESS)
2345 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2346 return STATUS_BUFFER_TOO_SMALL;
2348 Stream_Read_UINT32(s, call->dwShareMode);
2349 Stream_Read_UINT32(s, call->dwPreferredProtocols);
2350 Stream_Read_UINT32(s, call->dwInitialization);
2352 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2353 &(call->handles.hContext));
2354 if (status != SCARD_S_SUCCESS)
2356 WLog_Print(log, WLOG_ERROR,
2357 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2362 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2363 if (status != SCARD_S_SUCCESS)
2364 WLog_Print(log, WLOG_ERROR,
2365 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
2367 smartcard_trace_reconnect_call(log, call);
2374 wLog* log = scard_log();
2375 smartcard_trace_reconnect_return(log, ret);
2377 if (!Stream_EnsureRemainingCapacity(s, 4))
2378 return SCARD_E_NO_MEMORY;
2379 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2380 return ret->ReturnCode;
2387 UINT32 pbContextNdrPtr = 0;
2390 wLog* log = scard_log();
2392 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2394 if (status != SCARD_S_SUCCESS)
2397 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2398 if (status != SCARD_S_SUCCESS)
2401 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2402 return STATUS_BUFFER_TOO_SMALL;
2404 Stream_Read_UINT32(s, call->dwDisposition);
2406 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2407 &(call->handles.hContext));
2408 if (status != SCARD_S_SUCCESS)
2411 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2412 if (status != SCARD_S_SUCCESS)
2415 smartcard_trace_hcard_and_disposition_call(log, call, name);
2423 if (!WLog_IsLevelActive(log, g_LogLevel))
2426 WLog_Print(log, g_LogLevel,
"GetStatusChangeA_Call {");
2427 smartcard_log_context(log, &call->handles.hContext);
2429 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
2432 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
2434 WLog_Print(log, g_LogLevel,
"}");
2438 UINT32 cReaders, UINT32* ptrIndex)
2440 LONG status = SCARD_E_NO_MEMORY;
2442 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2443 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2446 const UINT32 len = Stream_Get_UINT32(s);
2447 if (len != cReaders)
2449 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEA");
2455 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2456 if (!rgReaderStates || !states)
2458 status = ERROR_INVALID_DATA;
2460 for (UINT32 index = 0; index < cReaders; index++)
2462 UINT32 ptr = UINT32_MAX;
2465 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2468 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2474 states[index] = ptr != 0;
2475 Stream_Read_UINT32(s, readerState->dwCurrentState);
2476 Stream_Read_UINT32(s, readerState->dwEventState);
2477 Stream_Read_UINT32(s, readerState->cbAtr);
2478 if (readerState->cbAtr > ARRAYSIZE(readerState->rgbAtr))
2480 WLog_Print(log, WLOG_ERROR,
2481 "SCARD_READERSTATEA[%" PRIu32
"]::cbAtr %" PRIu32
" exceeds %" PRIuz, index,
2482 readerState->cbAtr, (
size_t)ARRAYSIZE(readerState->rgbAtr));
2485 Stream_Read(s, readerState->rgbAtr, 36);
2488 for (UINT32 index = 0; index < cReaders; index++)
2495 status = smartcard_ndr_read_a(log, s, &readerState->szReader, NDR_PTR_FULL);
2496 if (status != SCARD_S_SUCCESS)
2500 *ppcReaders = rgReaderStates;
2502 return SCARD_S_SUCCESS;
2506 for (UINT32 index = 0; index < cReaders; index++)
2509 free(readerState->szReader);
2512 free(rgReaderStates);
2518 UINT32 cReaders, UINT32* ptrIndex)
2520 LONG status = SCARD_E_NO_MEMORY;
2522 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2523 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2526 const UINT32 len = Stream_Get_UINT32(s);
2527 if (len != cReaders)
2529 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEW");
2535 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2537 if (!rgReaderStates || !states)
2540 status = ERROR_INVALID_DATA;
2541 for (UINT32 index = 0; index < cReaders; index++)
2543 UINT32 ptr = UINT32_MAX;
2546 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2549 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2555 states[index] = ptr != 0;
2556 Stream_Read_UINT32(s, readerState->dwCurrentState);
2557 Stream_Read_UINT32(s, readerState->dwEventState);
2558 Stream_Read_UINT32(s, readerState->cbAtr);
2559 if (readerState->cbAtr > ARRAYSIZE(readerState->rgbAtr))
2561 WLog_Print(log, WLOG_ERROR,
2562 "SCARD_READERSTATEW[%" PRIu32
"]::cbAtr %" PRIu32
" exceeds %" PRIuz, index,
2563 readerState->cbAtr, (
size_t)ARRAYSIZE(readerState->rgbAtr));
2566 Stream_Read(s, readerState->rgbAtr, 36);
2569 for (UINT32 index = 0; index < cReaders; index++)
2577 status = smartcard_ndr_read_w(log, s, &readerState->szReader, NDR_PTR_FULL);
2578 if (status != SCARD_S_SUCCESS)
2582 *ppcReaders = rgReaderStates;
2584 return SCARD_S_SUCCESS;
2588 for (UINT32 index = 0; index < cReaders; index++)
2591 free(readerState->szReader);
2594 free(rgReaderStates);
2607 UINT32 pbContextNdrPtr = 0;
2610 wLog* log = scard_log();
2612 call->rgReaderStates =
nullptr;
2614 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2616 if (status != SCARD_S_SUCCESS)
2619 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2620 return STATUS_BUFFER_TOO_SMALL;
2622 Stream_Read_UINT32(s, call->dwTimeOut);
2623 Stream_Read_UINT32(s, call->cReaders);
2624 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2625 return ERROR_INVALID_DATA;
2627 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2628 &(call->handles.hContext));
2629 if (status != SCARD_S_SUCCESS)
2635 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
2636 if (status != SCARD_S_SUCCESS)
2641 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2642 return SCARD_E_UNEXPECTED;
2645 smartcard_trace_get_status_change_a_call(log, call);
2646 return SCARD_S_SUCCESS;
2653 UINT32 pbContextNdrPtr = 0;
2656 wLog* log = scard_log();
2657 call->rgReaderStates =
nullptr;
2659 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2661 if (status != SCARD_S_SUCCESS)
2664 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2665 return STATUS_BUFFER_TOO_SMALL;
2667 Stream_Read_UINT32(s, call->dwTimeOut);
2668 Stream_Read_UINT32(s, call->cReaders);
2669 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2670 return ERROR_INVALID_DATA;
2672 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2673 &(call->handles.hContext));
2674 if (status != SCARD_S_SUCCESS)
2680 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
2681 if (status != SCARD_S_SUCCESS)
2686 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2687 return SCARD_E_UNEXPECTED;
2690 smartcard_trace_get_status_change_w_call(log, call);
2691 return SCARD_S_SUCCESS;
2698 wLog* log = scard_log();
2701 DWORD cReaders = ret->cReaders;
2704 smartcard_trace_get_status_change_return(log, ret, unicode);
2705 if (ret->ReturnCode != SCARD_S_SUCCESS)
2707 if (cReaders == SCARD_AUTOALLOCATE)
2710 if (!Stream_EnsureRemainingCapacity(s, 4))
2711 return SCARD_E_NO_MEMORY;
2713 Stream_Write_UINT32(s, cReaders);
2714 if (!smartcard_ndr_pointer_write(s, &index, cReaders))
2715 return SCARD_E_NO_MEMORY;
2716 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cReaders, NDR_PTR_SIMPLE);
2717 if (status != SCARD_S_SUCCESS)
2719 return ret->ReturnCode;
2725 UINT32 pbContextNdrPtr = 0;
2727 wLog* log = scard_log();
2730 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2732 if (status != SCARD_S_SUCCESS)
2735 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2736 if (status != SCARD_S_SUCCESS)
2739 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2740 return STATUS_BUFFER_TOO_SMALL;
2742 Stream_Read_INT32(s, call->fpbAtrIsNULL);
2743 Stream_Read_UINT32(s, call->cbAtrLen);
2745 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2746 &(call->handles.hContext));
2747 if (status != SCARD_S_SUCCESS)
2750 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2751 if (status != SCARD_S_SUCCESS)
2760 wLog* log = scard_log();
2762 DWORD cbAtrLen = ret->cbAtrLen;
2765 smartcard_trace_state_return(log, ret);
2766 if (ret->ReturnCode != SCARD_S_SUCCESS)
2768 if (cbAtrLen == SCARD_AUTOALLOCATE)
2771 Stream_Write_UINT32(s, ret->dwState);
2772 Stream_Write_UINT32(s, ret->dwProtocol);
2773 Stream_Write_UINT32(s, cbAtrLen);
2774 if (!smartcard_ndr_pointer_write(s, &index, cbAtrLen))
2775 return SCARD_E_NO_MEMORY;
2776 status = smartcard_ndr_write(s, ret->rgAtr, cbAtrLen, 1, NDR_PTR_SIMPLE);
2777 if (status != SCARD_S_SUCCESS)
2779 return ret->ReturnCode;
2785 UINT32 pbContextNdrPtr = 0;
2788 wLog* log = scard_log();
2790 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2792 if (status != SCARD_S_SUCCESS)
2795 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2796 if (status != SCARD_S_SUCCESS)
2799 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2800 return STATUS_BUFFER_TOO_SMALL;
2802 Stream_Read_INT32(s, call->fmszReaderNamesIsNULL);
2803 Stream_Read_UINT32(s, call->cchReaderLen);
2804 Stream_Read_UINT32(s, call->cbAtrLen);
2806 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2807 &(call->handles.hContext));
2808 if (status != SCARD_S_SUCCESS)
2811 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2812 if (status != SCARD_S_SUCCESS)
2815 smartcard_trace_status_call(log, call, unicode);
2822 wLog* log = scard_log();
2826 DWORD cBytes = ret->cBytes;
2828 smartcard_trace_status_return(log, ret, unicode);
2829 if (ret->ReturnCode != SCARD_S_SUCCESS)
2831 if (cBytes == SCARD_AUTOALLOCATE)
2834 if (!Stream_EnsureRemainingCapacity(s, 4))
2835 return SCARD_F_INTERNAL_ERROR;
2837 Stream_Write_UINT32(s, cBytes);
2838 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
2839 return SCARD_E_NO_MEMORY;
2841 if (!Stream_EnsureRemainingCapacity(s, 44))
2842 return SCARD_F_INTERNAL_ERROR;
2844 Stream_Write_UINT32(s, ret->dwState);
2845 Stream_Write_UINT32(s, ret->dwProtocol);
2846 Stream_Write(s, ret->pbAtr,
sizeof(ret->pbAtr));
2847 Stream_Write_UINT32(s, ret->cbAtrLen);
2848 status = smartcard_ndr_write(s, ret->mszReaderNames, cBytes, 1, NDR_PTR_SIMPLE);
2849 if (status != SCARD_S_SUCCESS)
2851 return ret->ReturnCode;
2857 wLog* log = scard_log();
2859 UINT32 pbContextNdrPtr = 0;
2861 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2863 if (status != SCARD_S_SUCCESS)
2866 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2867 if (status != SCARD_S_SUCCESS)
2870 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2871 return STATUS_BUFFER_TOO_SMALL;
2873 Stream_Read_UINT32(s, call->dwAttrId);
2874 Stream_Read_INT32(s, call->fpbAttrIsNULL);
2875 Stream_Read_UINT32(s, call->cbAttrLen);
2877 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2878 &(call->handles.hContext));
2879 if (status != SCARD_S_SUCCESS)
2882 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2883 if (status != SCARD_S_SUCCESS)
2886 smartcard_trace_get_attrib_call(log, call);
2891 DWORD cbAttrCallLen)
2894 wLog* log = scard_log();
2896 DWORD cbAttrLen = 0;
2898 smartcard_trace_get_attrib_return(log, ret, dwAttrId);
2900 if (!Stream_EnsureRemainingCapacity(s, 4))
2901 return SCARD_F_INTERNAL_ERROR;
2903 cbAttrLen = ret->cbAttrLen;
2904 if (ret->ReturnCode != SCARD_S_SUCCESS)
2906 if (cbAttrLen == SCARD_AUTOALLOCATE)
2911 if (cbAttrCallLen < cbAttrLen)
2912 cbAttrLen = cbAttrCallLen;
2914 Stream_Write_UINT32(s, cbAttrLen);
2915 if (!smartcard_ndr_pointer_write(s, &index, cbAttrLen))
2916 return SCARD_E_NO_MEMORY;
2918 status = smartcard_ndr_write(s, ret->pbAttr, cbAttrLen, 1, NDR_PTR_SIMPLE);
2919 if (status != SCARD_S_SUCCESS)
2921 return ret->ReturnCode;
2927 wLog* log = scard_log();
2930 UINT32 pvInBufferNdrPtr = 0;
2931 UINT32 pbContextNdrPtr = 0;
2933 call->pvInBuffer =
nullptr;
2935 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2937 if (status != SCARD_S_SUCCESS)
2940 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2941 if (status != SCARD_S_SUCCESS)
2944 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 20))
2945 return STATUS_BUFFER_TOO_SMALL;
2947 Stream_Read_UINT32(s, call->dwControlCode);
2948 Stream_Read_UINT32(s, call->cbInBufferSize);
2949 if (!smartcard_ndr_pointer_read(log, s, &index,
2951 return ERROR_INVALID_DATA;
2952 Stream_Read_INT32(s, call->fpvOutBufferIsNULL);
2953 Stream_Read_UINT32(s, call->cbOutBufferSize);
2955 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2956 &(call->handles.hContext));
2957 if (status != SCARD_S_SUCCESS)
2960 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2961 if (status != SCARD_S_SUCCESS)
2964 if (pvInBufferNdrPtr)
2967 smartcard_ndr_read(log, s, &call->pvInBuffer, call->cbInBufferSize, 1, NDR_PTR_SIMPLE);
2968 if (status != SCARD_S_SUCCESS)
2972 smartcard_trace_control_call(log, call);
2973 return SCARD_S_SUCCESS;
2979 wLog* log = scard_log();
2982 DWORD cbDataLen = ret->cbOutBufferSize;
2985 smartcard_trace_control_return(log, ret);
2986 if (ret->ReturnCode != SCARD_S_SUCCESS)
2988 if (cbDataLen == SCARD_AUTOALLOCATE)
2991 if (!Stream_EnsureRemainingCapacity(s, 4))
2992 return SCARD_F_INTERNAL_ERROR;
2994 Stream_Write_UINT32(s, cbDataLen);
2995 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
2996 return SCARD_E_NO_MEMORY;
2998 status = smartcard_ndr_write(s, ret->pvOutBuffer, cbDataLen, 1, NDR_PTR_SIMPLE);
2999 if (status != SCARD_S_SUCCESS)
3001 return ret->ReturnCode;
3007 BYTE* pbExtraBytes =
nullptr;
3008 UINT32 pbExtraBytesNdrPtr = 0;
3009 UINT32 pbSendBufferNdrPtr = 0;
3010 UINT32 pioRecvPciNdrPtr = 0;
3014 UINT32 pbContextNdrPtr = 0;
3017 wLog* log = scard_log();
3019 call->pioSendPci =
nullptr;
3020 call->pioRecvPci =
nullptr;
3021 call->pbSendBuffer =
nullptr;
3023 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3025 if (status != SCARD_S_SUCCESS)
3028 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3029 if (status != SCARD_S_SUCCESS)
3032 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 32))
3033 return STATUS_BUFFER_TOO_SMALL;
3035 Stream_Read_UINT32(s, ioSendPci.dwProtocol);
3036 Stream_Read_UINT32(s, ioSendPci.cbExtraBytes);
3037 if (!smartcard_ndr_pointer_read(log, s, &index,
3038 &pbExtraBytesNdrPtr))
3039 return ERROR_INVALID_DATA;
3041 Stream_Read_UINT32(s, call->cbSendLength);
3042 if (!smartcard_ndr_pointer_read(log, s, &index,
3043 &pbSendBufferNdrPtr))
3044 return ERROR_INVALID_DATA;
3046 if (!smartcard_ndr_pointer_read(log, s, &index,
3048 return ERROR_INVALID_DATA;
3050 Stream_Read_INT32(s, call->fpbRecvBufferIsNULL);
3051 Stream_Read_UINT32(s, call->cbRecvLength);
3053 if (ioSendPci.cbExtraBytes > 1024)
3055 WLog_Print(log, WLOG_WARN,
3056 "Transmit_Call ioSendPci.cbExtraBytes is out of bounds: %" PRIu32
" (max: 1024)",
3057 ioSendPci.cbExtraBytes);
3058 return STATUS_INVALID_PARAMETER;
3061 if (call->cbSendLength > 66560)
3063 WLog_Print(log, WLOG_WARN,
3064 "Transmit_Call cbSendLength is out of bounds: %" PRIu32
" (max: 66560)",
3065 ioSendPci.cbExtraBytes);
3066 return STATUS_INVALID_PARAMETER;
3069 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3070 &(call->handles.hContext));
3071 if (status != SCARD_S_SUCCESS)
3074 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3075 if (status != SCARD_S_SUCCESS)
3078 if (ioSendPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3082 "Transmit_Call ioSendPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3083 return STATUS_INVALID_PARAMETER;
3086 if (pbExtraBytesNdrPtr)
3089 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3090 return STATUS_BUFFER_TOO_SMALL;
3092 Stream_Read_UINT32(s, length);
3094 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioSendPci.cbExtraBytes))
3095 return STATUS_BUFFER_TOO_SMALL;
3097 ioSendPci.pbExtraBytes = Stream_Pointer(s);
3101 if (!call->pioSendPci)
3103 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3104 return STATUS_NO_MEMORY;
3107 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3108 call->pioSendPci->cbPciLength = (DWORD)(ioSendPci.cbExtraBytes +
sizeof(
SCARD_IO_REQUEST));
3110 Stream_Read(s, pbExtraBytes, ioSendPci.cbExtraBytes);
3111 if (smartcard_unpack_read_size_align(s, ioSendPci.cbExtraBytes, 4) < 0)
3112 return STATUS_INVALID_PARAMETER;
3118 if (!call->pioSendPci)
3120 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3121 return STATUS_NO_MEMORY;
3124 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3128 if (pbSendBufferNdrPtr)
3131 smartcard_ndr_read(log, s, &call->pbSendBuffer, call->cbSendLength, 1, NDR_PTR_SIMPLE);
3132 if (status != SCARD_S_SUCCESS)
3136 if (pioRecvPciNdrPtr)
3138 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3139 return STATUS_BUFFER_TOO_SMALL;
3141 Stream_Read_UINT32(s, ioRecvPci.dwProtocol);
3142 Stream_Read_UINT32(s, ioRecvPci.cbExtraBytes);
3143 if (!smartcard_ndr_pointer_read(log, s, &index,
3144 &pbExtraBytesNdrPtr))
3145 return ERROR_INVALID_DATA;
3147 if (ioRecvPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3151 "Transmit_Call ioRecvPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3152 return STATUS_INVALID_PARAMETER;
3155 if (pbExtraBytesNdrPtr)
3158 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3159 return STATUS_BUFFER_TOO_SMALL;
3161 Stream_Read_UINT32(s, length);
3163 if (ioRecvPci.cbExtraBytes > 1024)
3165 WLog_Print(log, WLOG_WARN,
3166 "Transmit_Call ioRecvPci.cbExtraBytes is out of bounds: %" PRIu32
3168 ioRecvPci.cbExtraBytes);
3169 return STATUS_INVALID_PARAMETER;
3172 if (length != ioRecvPci.cbExtraBytes)
3174 WLog_Print(log, WLOG_WARN,
3175 "Transmit_Call unexpected length: Actual: %" PRIu32
3176 ", Expected: %" PRIu32
" (ioRecvPci.cbExtraBytes)",
3177 length, ioRecvPci.cbExtraBytes);
3178 return STATUS_INVALID_PARAMETER;
3181 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioRecvPci.cbExtraBytes))
3182 return STATUS_BUFFER_TOO_SMALL;
3184 ioRecvPci.pbExtraBytes = Stream_Pointer(s);
3188 if (!call->pioRecvPci)
3190 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3191 return STATUS_NO_MEMORY;
3194 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3195 call->pioRecvPci->cbPciLength =
3198 Stream_Read(s, pbExtraBytes, ioRecvPci.cbExtraBytes);
3199 if (smartcard_unpack_read_size_align(s, ioRecvPci.cbExtraBytes, 4) < 0)
3200 return STATUS_INVALID_PARAMETER;
3206 if (!call->pioRecvPci)
3208 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3209 return STATUS_NO_MEMORY;
3212 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3217 smartcard_trace_transmit_call(log, call);
3218 return SCARD_S_SUCCESS;
3224 wLog* log = scard_log();
3229 UINT32 cbRecvLength = ret->cbRecvLength;
3230 UINT32 cbRecvPci = ret->pioRecvPci ? ret->pioRecvPci->cbPciLength : 0;
3232 smartcard_trace_transmit_return(log, ret);
3234 if (!ret->pbRecvBuffer)
3237 if (!smartcard_ndr_pointer_write(s, &index, cbRecvPci))
3238 return SCARD_E_NO_MEMORY;
3239 if (!Stream_EnsureRemainingCapacity(s, 4))
3240 return SCARD_E_NO_MEMORY;
3241 Stream_Write_UINT32(s, cbRecvLength);
3242 if (!smartcard_ndr_pointer_write(s, &index, cbRecvLength))
3243 return SCARD_E_NO_MEMORY;
3245 if (ret->pioRecvPci)
3247 UINT32 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
3250 if (!Stream_EnsureRemainingCapacity(s, cbExtraBytes + 16))
3252 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3253 return SCARD_F_INTERNAL_ERROR;
3256 Stream_Write_UINT32(s, ret->pioRecvPci->dwProtocol);
3257 Stream_Write_UINT32(s, cbExtraBytes);
3258 if (!smartcard_ndr_pointer_write(s, &index, cbExtraBytes))
3259 return SCARD_E_NO_MEMORY;
3260 error = smartcard_ndr_write(s, pbExtraBytes, cbExtraBytes, 1, NDR_PTR_SIMPLE);
3265 status = smartcard_ndr_write(s, ret->pbRecvBuffer, ret->cbRecvLength, 1, NDR_PTR_SIMPLE);
3266 if (status != SCARD_S_SUCCESS)
3268 return ret->ReturnCode;
3273 UINT32 rgReaderStatesNdrPtr = 0;
3274 UINT32 rgAtrMasksNdrPtr = 0;
3276 UINT32 pbContextNdrPtr = 0;
3279 wLog* log = scard_log();
3281 call->rgReaderStates =
nullptr;
3283 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3285 if (status != SCARD_S_SUCCESS)
3288 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3289 return STATUS_BUFFER_TOO_SMALL;
3291 Stream_Read_UINT32(s, call->cAtrs);
3292 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3293 return ERROR_INVALID_DATA;
3294 Stream_Read_UINT32(s, call->cReaders);
3295 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3296 return ERROR_INVALID_DATA;
3298 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3299 &(call->handles.hContext));
3300 if (status != SCARD_S_SUCCESS)
3303 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3305 WLog_Print(log, WLOG_WARN,
3306 "LocateCardsByATRA_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3307 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3308 rgAtrMasksNdrPtr, call->cAtrs);
3309 return STATUS_INVALID_PARAMETER;
3312 if (rgAtrMasksNdrPtr)
3314 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3315 if (status != SCARD_S_SUCCESS)
3319 if (rgReaderStatesNdrPtr)
3322 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
3323 if (status != SCARD_S_SUCCESS)
3327 smartcard_trace_locate_cards_by_atr_a_call(log, call);
3328 return SCARD_S_SUCCESS;
3333 UINT32 sz1NdrPtr = 0;
3334 UINT32 sz2NdrPtr = 0;
3336 UINT32 pbContextNdrPtr = 0;
3339 wLog* log = scard_log();
3341 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3343 if (status != SCARD_S_SUCCESS)
3346 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3347 return ERROR_INVALID_DATA;
3348 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3349 return ERROR_INVALID_DATA;
3352 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3353 if (status != SCARD_S_SUCCESS)
3358 status = smartcard_ndr_read_a(log, s, &call->sz1, NDR_PTR_FULL);
3359 if (status != SCARD_S_SUCCESS)
3364 status = smartcard_ndr_read_a(log, s, &call->sz2, NDR_PTR_FULL);
3365 if (status != SCARD_S_SUCCESS)
3368 smartcard_trace_context_and_two_strings_a_call(log, call);
3369 return SCARD_S_SUCCESS;
3374 UINT32 sz1NdrPtr = 0;
3375 UINT32 sz2NdrPtr = 0;
3377 UINT32 pbContextNdrPtr = 0;
3380 wLog* log = scard_log();
3382 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3384 if (status != SCARD_S_SUCCESS)
3387 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3388 return ERROR_INVALID_DATA;
3389 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3390 return ERROR_INVALID_DATA;
3393 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3394 if (status != SCARD_S_SUCCESS)
3399 status = smartcard_ndr_read_w(log, s, &call->sz1, NDR_PTR_FULL);
3400 if (status != SCARD_S_SUCCESS)
3405 status = smartcard_ndr_read_w(log, s, &call->sz2, NDR_PTR_FULL);
3406 if (status != SCARD_S_SUCCESS)
3409 smartcard_trace_context_and_two_strings_w_call(log, call);
3410 return SCARD_S_SUCCESS;
3415 UINT32 sz1NdrPtr = 0;
3416 UINT32 sz2NdrPtr = 0;
3418 UINT32 pbContextNdrPtr = 0;
3421 wLog* log = scard_log();
3423 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3425 if (status != SCARD_S_SUCCESS)
3428 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3429 return STATUS_BUFFER_TOO_SMALL;
3431 Stream_Read_UINT32(s, call->cBytes);
3432 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3433 return ERROR_INVALID_DATA;
3435 Stream_Read_UINT32(s, call->cReaders);
3436 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3437 return ERROR_INVALID_DATA;
3439 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3440 &(call->handles.hContext));
3441 if (status != SCARD_S_SUCCESS)
3446 status = smartcard_ndr_read_fixed_string_a(log, s, &call->mszCards, call->cBytes,
3448 if (status != SCARD_S_SUCCESS)
3454 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
3455 if (status != SCARD_S_SUCCESS)
3458 smartcard_trace_locate_cards_a_call(log, call);
3459 return SCARD_S_SUCCESS;
3464 UINT32 sz1NdrPtr = 0;
3465 UINT32 sz2NdrPtr = 0;
3467 UINT32 pbContextNdrPtr = 0;
3470 wLog* log = scard_log();
3472 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3474 if (status != SCARD_S_SUCCESS)
3477 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3478 return STATUS_BUFFER_TOO_SMALL;
3480 Stream_Read_UINT32(s, call->cBytes);
3481 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3482 return ERROR_INVALID_DATA;
3484 Stream_Read_UINT32(s, call->cReaders);
3485 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3486 return ERROR_INVALID_DATA;
3488 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3489 &(call->handles.hContext));
3490 if (status != SCARD_S_SUCCESS)
3495 status = smartcard_ndr_read_fixed_string_w(log, s, &call->mszCards, call->cBytes,
3497 if (status != SCARD_S_SUCCESS)
3503 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
3504 if (status != SCARD_S_SUCCESS)
3507 smartcard_trace_locate_cards_w_call(log, call);
3508 return SCARD_S_SUCCESS;
3515 UINT32 pbContextNdrPtr = 0;
3518 wLog* log = scard_log();
3520 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3522 if (status != SCARD_S_SUCCESS)
3524 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3525 if (status != SCARD_S_SUCCESS)
3528 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3529 return STATUS_BUFFER_TOO_SMALL;
3530 Stream_Read_UINT32(s, call->dwAttrId);
3531 Stream_Read_UINT32(s, call->cbAttrLen);
3533 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
3534 return ERROR_INVALID_DATA;
3536 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3537 &(call->handles.hContext));
3538 if (status != SCARD_S_SUCCESS)
3541 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3542 if (status != SCARD_S_SUCCESS)
3548 status = smartcard_ndr_read_ex(log, s, &call->pbAttr, 0, 1, NDR_PTR_SIMPLE, &len);
3549 if (status != SCARD_S_SUCCESS)
3551 if (call->cbAttrLen > len)
3552 call->cbAttrLen = WINPR_ASSERTING_INT_CAST(DWORD, len);
3555 call->cbAttrLen = 0;
3556 smartcard_trace_set_attrib_call(log, call);
3557 return SCARD_S_SUCCESS;
3562 UINT32 rgReaderStatesNdrPtr = 0;
3563 UINT32 rgAtrMasksNdrPtr = 0;
3565 UINT32 pbContextNdrPtr = 0;
3568 wLog* log = scard_log();
3570 call->rgReaderStates =
nullptr;
3572 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3574 if (status != SCARD_S_SUCCESS)
3577 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3578 return STATUS_BUFFER_TOO_SMALL;
3580 Stream_Read_UINT32(s, call->cAtrs);
3581 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3582 return ERROR_INVALID_DATA;
3584 Stream_Read_UINT32(s, call->cReaders);
3585 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3586 return ERROR_INVALID_DATA;
3588 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3589 &(call->handles.hContext));
3590 if (status != SCARD_S_SUCCESS)
3593 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3595 WLog_Print(log, WLOG_WARN,
3596 "LocateCardsByATRW_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3597 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3598 rgAtrMasksNdrPtr, call->cAtrs);
3599 return STATUS_INVALID_PARAMETER;
3602 if (rgAtrMasksNdrPtr)
3604 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3605 if (status != SCARD_S_SUCCESS)
3609 if (rgReaderStatesNdrPtr)
3612 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
3613 if (status != SCARD_S_SUCCESS)
3617 smartcard_trace_locate_cards_by_atr_w_call(log, call);
3618 return SCARD_S_SUCCESS;
3623 UINT32 mszNdrPtr = 0;
3624 UINT32 contextNdrPtr = 0;
3626 UINT32 pbContextNdrPtr = 0;
3629 wLog* log = scard_log();
3631 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3632 return ERROR_INVALID_DATA;
3634 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3635 &index, &pbContextNdrPtr);
3636 if (status != SCARD_S_SUCCESS)
3639 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3640 return ERROR_INVALID_DATA;
3642 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3643 return STATUS_BUFFER_TOO_SMALL;
3644 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3645 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
3646 Stream_Read_UINT32(s, call->Common.cbDataLen);
3648 call->szLookupName =
nullptr;
3651 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
3652 if (status != SCARD_S_SUCCESS)
3656 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3657 &call->Common.handles.hContext);
3658 if (status != SCARD_S_SUCCESS)
3663 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3664 if (status != SCARD_S_SUCCESS)
3667 smartcard_trace_read_cache_a_call(log, call);
3668 return SCARD_S_SUCCESS;
3673 UINT32 mszNdrPtr = 0;
3674 UINT32 contextNdrPtr = 0;
3676 UINT32 pbContextNdrPtr = 0;
3679 wLog* log = scard_log();
3681 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3682 return ERROR_INVALID_DATA;
3684 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3685 &index, &pbContextNdrPtr);
3686 if (status != SCARD_S_SUCCESS)
3689 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3690 return ERROR_INVALID_DATA;
3692 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3693 return STATUS_BUFFER_TOO_SMALL;
3694 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3695 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
3696 Stream_Read_UINT32(s, call->Common.cbDataLen);
3698 call->szLookupName =
nullptr;
3701 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
3702 if (status != SCARD_S_SUCCESS)
3706 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3707 &call->Common.handles.hContext);
3708 if (status != SCARD_S_SUCCESS)
3713 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3714 if (status != SCARD_S_SUCCESS)
3717 smartcard_trace_read_cache_w_call(log, call);
3718 return SCARD_S_SUCCESS;
3723 UINT32 mszNdrPtr = 0;
3724 UINT32 contextNdrPtr = 0;
3725 UINT32 pbDataNdrPtr = 0;
3727 UINT32 pbContextNdrPtr = 0;
3730 wLog* log = scard_log();
3732 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3733 return ERROR_INVALID_DATA;
3735 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3736 &index, &pbContextNdrPtr);
3737 if (status != SCARD_S_SUCCESS)
3740 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3741 return ERROR_INVALID_DATA;
3743 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
3744 return STATUS_BUFFER_TOO_SMALL;
3746 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3747 Stream_Read_UINT32(s, call->Common.cbDataLen);
3749 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
3750 return ERROR_INVALID_DATA;
3752 call->szLookupName =
nullptr;
3755 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
3756 if (status != SCARD_S_SUCCESS)
3760 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3761 &call->Common.handles.hContext);
3762 if (status != SCARD_S_SUCCESS)
3765 call->Common.CardIdentifier =
nullptr;
3768 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3769 if (status != SCARD_S_SUCCESS)
3773 call->Common.pbData =
nullptr;
3776 status = smartcard_ndr_read(log, s, &call->Common.pbData, call->Common.cbDataLen, 1,
3778 if (status != SCARD_S_SUCCESS)
3781 smartcard_trace_write_cache_a_call(log, call);
3782 return SCARD_S_SUCCESS;
3787 UINT32 mszNdrPtr = 0;
3788 UINT32 contextNdrPtr = 0;
3789 UINT32 pbDataNdrPtr = 0;
3791 UINT32 pbContextNdrPtr = 0;
3794 wLog* log = scard_log();
3796 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3797 return ERROR_INVALID_DATA;
3799 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3800 &index, &pbContextNdrPtr);
3801 if (status != SCARD_S_SUCCESS)
3804 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3805 return ERROR_INVALID_DATA;
3807 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
3808 return STATUS_BUFFER_TOO_SMALL;
3809 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3810 Stream_Read_UINT32(s, call->Common.cbDataLen);
3812 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
3813 return ERROR_INVALID_DATA;
3815 call->szLookupName =
nullptr;
3818 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
3819 if (status != SCARD_S_SUCCESS)
3823 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3824 &call->Common.handles.hContext);
3825 if (status != SCARD_S_SUCCESS)
3828 call->Common.CardIdentifier =
nullptr;
3831 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3832 if (status != SCARD_S_SUCCESS)
3836 call->Common.pbData =
nullptr;
3839 status = smartcard_ndr_read(log, s, &call->Common.pbData, call->Common.cbDataLen, 1,
3841 if (status != SCARD_S_SUCCESS)
3844 smartcard_trace_write_cache_w_call(log, call);
3851 wLog* log = scard_log();
3854 UINT32 pbContextNdrPtr = 0;
3856 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3858 if (status != SCARD_S_SUCCESS)
3861 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3862 if (status != SCARD_S_SUCCESS)
3865 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3866 &(call->handles.hContext));
3867 if (status != SCARD_S_SUCCESS)
3869 WLog_Print(log, WLOG_ERROR,
3870 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
3875 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3876 if (status != SCARD_S_SUCCESS)
3877 WLog_Print(log, WLOG_ERROR,
3878 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
3880 smartcard_trace_get_transmit_count_call(log, call);
3887 wLog* log = scard_log();
3888 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
3889 &call->szReaderName);
3895 wLog* log = scard_log();
3896 return smartcard_unpack_common_context_and_string_a(log, s, &call->handles.hContext, &call->sz);
3902 wLog* log = scard_log();
3903 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext, &call->sz);
3909 wLog* log = scard_log();
3910 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
3911 &call->szReaderName);
3917 wLog* log = scard_log();
3918 smartcard_trace_device_type_id_return(log, ret);
3920 if (!Stream_EnsureRemainingCapacity(s, 4))
3922 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3923 return SCARD_F_INTERNAL_ERROR;
3926 Stream_Write_UINT32(s, ret->dwDeviceId);
3928 return ret->ReturnCode;
3934 wLog* log = scard_log();
3937 DWORD cbDataLen = ret->cReaders;
3940 smartcard_trace_locate_cards_return(log, ret);
3941 if (ret->ReturnCode != SCARD_S_SUCCESS)
3943 if (cbDataLen == SCARD_AUTOALLOCATE)
3946 if (!Stream_EnsureRemainingCapacity(s, 4))
3948 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3949 return SCARD_F_INTERNAL_ERROR;
3952 Stream_Write_UINT32(s, cbDataLen);
3953 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3954 return SCARD_E_NO_MEMORY;
3956 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cbDataLen, NDR_PTR_SIMPLE);
3957 if (status != SCARD_S_SUCCESS)
3959 return ret->ReturnCode;
3965 wLog* log = scard_log();
3969 DWORD cbDataLen = ret->cbDataLen;
3970 smartcard_trace_get_reader_icon_return(log, ret);
3971 if (ret->ReturnCode != SCARD_S_SUCCESS)
3973 if (cbDataLen == SCARD_AUTOALLOCATE)
3976 if (!Stream_EnsureRemainingCapacity(s, 4))
3978 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3979 return SCARD_F_INTERNAL_ERROR;
3982 Stream_Write_UINT32(s, cbDataLen);
3983 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3984 return SCARD_E_NO_MEMORY;
3986 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
3987 if (status != SCARD_S_SUCCESS)
3989 return ret->ReturnCode;
3995 wLog* log = scard_log();
3997 smartcard_trace_get_transmit_count_return(log, call);
3999 if (!Stream_EnsureRemainingCapacity(s, 4))
4001 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4002 return SCARD_F_INTERNAL_ERROR;
4005 Stream_Write_UINT32(s, call->cTransmitCount);
4007 return call->ReturnCode;
4013 wLog* log = scard_log();
4017 DWORD cbDataLen = ret->cbDataLen;
4018 smartcard_trace_read_cache_return(log, ret);
4019 if (ret->ReturnCode != SCARD_S_SUCCESS)
4022 if (cbDataLen == SCARD_AUTOALLOCATE)
4025 if (!Stream_EnsureRemainingCapacity(s, 4))
4027 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4028 return SCARD_F_INTERNAL_ERROR;
4031 Stream_Write_UINT32(s, cbDataLen);
4032 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
4033 return SCARD_E_NO_MEMORY;
4035 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
4036 if (status != SCARD_S_SUCCESS)
4038 return ret->ReturnCode;