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,
const 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;
211 return STATUS_SUCCESS;
214static LONG smartcard_ndr_read(wLog* log,
wStream* s, BYTE** data,
size_t min,
size_t elementSize,
215 const ndr_ptr_t type)
217 return smartcard_ndr_read_ex(log, s, data, min, elementSize, type,
nullptr);
220static BOOL smartcard_ndr_pointer_write(
wStream* s, UINT32* index, DWORD length)
222 const UINT32 ndrPtr = 0x20000 + (*index) * 4;
226 if (!Stream_EnsureRemainingCapacity(s, 4))
231 Stream_Write_UINT32(s, ndrPtr);
232 (*index) = (*index) + 1;
235 Stream_Write_UINT32(s, 0);
239static LONG smartcard_ndr_write(
wStream* s,
const BYTE* data, UINT32 size, UINT32 elementSize,
240 const ndr_ptr_t type)
242 const UINT32 offset = 0;
243 const UINT32 len = size;
244 const UINT32 dataLen = size * elementSize;
248 return SCARD_S_SUCCESS;
262 return SCARD_E_INVALID_PARAMETER;
265 if (!Stream_EnsureRemainingCapacity(s, required + dataLen + 4))
266 return STATUS_BUFFER_TOO_SMALL;
271 Stream_Write_UINT32(s, len);
272 Stream_Write_UINT32(s, offset);
273 Stream_Write_UINT32(s, len);
276 Stream_Write_UINT32(s, len);
281 return SCARD_E_INVALID_PARAMETER;
285 Stream_Write(s, data, dataLen);
287 Stream_Zero(s, dataLen);
288 return smartcard_pack_write_size_align(s, dataLen, 4);
292 const ndr_ptr_t type)
300 WINPR_ASSERT(data || (size == 0));
306 const ndr_ptr_t type)
318 size_t min,
const ndr_ptr_t type)
326 const LONG status = smartcard_ndr_read(log, s, u.ppv, min,
sizeof(
LocateCards_ATRMask), type);
327 if (status != SCARD_S_SUCCESS)
334 for (
size_t x = 0; x < min; x++)
336 const UINT32 val = winpr_Data_Get_UINT32(&masks[x].cbAtr);
337 if (val > ARRAYSIZE(masks[x].rgbAtr))
339 WLog_Print(log, WLOG_ERROR,
340 "LocateCards_ATRMask[%" PRIuz
"]::cbAtr %" PRIu32
" exceeds %" PRIuz, x, val,
341 (
size_t)ARRAYSIZE(masks[x].rgbAtr));
344 return STATUS_DATA_ERROR;
347 return SCARD_S_SUCCESS;
350static LONG smartcard_ndr_read_fixed_string_a(wLog* log,
wStream* s, CHAR** data,
size_t min,
351 const ndr_ptr_t type)
359 return smartcard_ndr_read(log, s, u.ppv, min,
sizeof(CHAR), type);
362static LONG smartcard_ndr_read_fixed_string_w(wLog* log,
wStream* s, WCHAR** data,
size_t min,
363 const ndr_ptr_t type)
371 return smartcard_ndr_read(log, s, u.ppv, min,
sizeof(WCHAR), type);
374static LONG smartcard_ndr_read_a(wLog* log,
wStream* s, CHAR** data,
const ndr_ptr_t type)
382 return smartcard_ndr_read(log, s, u.ppv, 0,
sizeof(CHAR), type);
385static LONG smartcard_ndr_read_w(wLog* log,
wStream* s, WCHAR** data,
const ndr_ptr_t type)
393 return smartcard_ndr_read(log, s, u.ppv, 0,
sizeof(WCHAR), type);
396static LONG smartcard_ndr_write_w(
wStream* s,
const WCHAR* data, UINT32 size,
const ndr_ptr_t type)
404 return smartcard_ndr_write(s, cnv.bp, size,
sizeof(WCHAR), type);
407static LONG smartcard_ndr_write_a(
wStream* s,
const CHAR* data, UINT32 size,
const ndr_ptr_t type)
415 return smartcard_ndr_write(s, cnv.bp, size,
sizeof(CHAR), type);
418static LONG smartcard_ndr_read_u(wLog* log,
wStream* s,
UUID** data)
426 return smartcard_ndr_read(log, s, u.ppv, 1,
sizeof(
UUID), NDR_PTR_FIXED);
429static char* smartcard_convert_string_list(
const void* in,
size_t bytes, BOOL unicode)
438 char* mszA =
nullptr;
450 mszA = ConvertMszWCharNToUtf8Alloc(
string.wz, bytes /
sizeof(WCHAR), &length);
456 mszA = (
char*)calloc(bytes,
sizeof(
char));
459 CopyMemory(mszA,
string.sz, bytes - 1);
468 for (
size_t index = 0; index < length - 1; index++)
470 if (mszA[index] ==
'\0')
477WINPR_ATTR_MALLOC(free, 1)
478static
char* smartcard_create_msz_dump(const
char* msz,
size_t len)
480 size_t bufferLen = len;
481 char* buffer = calloc(len + 1, 1);
486 const char* cur = msz;
488 while ((len > 0) && cur && cur[0] !=
'\0' && (bufferLen > 0))
490 size_t clen = strnlen(cur, len);
491 int rc = _snprintf(buf, bufferLen,
"%s", cur);
492 bufferLen -= (size_t)rc;
501static void smartcard_msz_dump(wLog* log, DWORD level,
const char* prefix,
const void* data,
502 size_t len, UINT32 wchar)
504 if (!WLog_IsLevelActive(log, level))
508 const char* msz = WINPR_CXX_COMPAT_CAST(
const char*, data);
512 tmp = ConvertMszWCharNToUtf8Alloc(data, len, &mszlen);
516 char* array = smartcard_create_msz_dump(msz, mszlen);
517 WLog_Print(log, level,
"%s%s", prefix, array);
522WINPR_ATTR_MALLOC(free, 1)
523static
char* smartcard_create_array_dump(const
void* pd,
size_t len)
525 const BYTE* data = pd;
528 size_t bufferLen = len * 4;
531 char* buffer = calloc(bufferLen + 1, 1);
534 char* start = buffer;
536 WINPR_ASSERT(buffer || (bufferLen == 0));
538 if (!data && (len > 0))
540 (void)_snprintf(buffer, bufferLen,
"{ nullptr [%" PRIuz
"] }", len);
544 rc = _snprintf(buffer, bufferLen,
"{ ");
545 if ((rc < 0) || ((
size_t)rc >= bufferLen))
548 bufferLen -= (size_t)rc;
550 for (
size_t x = 0; x < len; x++)
552 rc = _snprintf(buffer, bufferLen,
"%02X", data[x]);
553 if ((rc < 0) || ((
size_t)rc >= bufferLen))
556 bufferLen -= (size_t)rc;
559 rc = _snprintf(buffer, bufferLen,
" }");
560 if ((rc < 0) || ((
size_t)rc >= bufferLen))
567WINPR_ATTR_FORMAT_ARG(3, 7)
568static
void smartcard_dump_array(wLog* log, DWORD level, WINPR_FORMAT_ARG const
char* prefix,
569 const
char* postfix, const
void* data,
size_t len, ...)
571 if (!WLog_IsLevelActive(log, level))
574 char* buffer = smartcard_create_array_dump(data, len);
576 char* fprefix =
nullptr;
578 va_list ap = WINPR_C_ARRAY_INIT;
580 winpr_vasprintf(&fprefix, &flen, prefix, ap);
582 WLog_Print(log, level,
"%s%s%s", fprefix, buffer, postfix);
587static void smartcard_log_redir_handle(wLog* log,
const REDIR_SCARDHANDLE* pHandle)
589 WINPR_ASSERT(pHandle);
590 smartcard_dump_array(log, g_LogLevel,
"handle: ",
"", pHandle->pbHandle, pHandle->cbHandle);
595 WINPR_ASSERT(phContext);
596 smartcard_dump_array(log, g_LogLevel,
"hContext: ",
"", phContext->pbContext,
597 phContext->cbContext);
600static void smartcard_trace_context_and_string_call_a(wLog* log,
const char* name,
604 if (!WLog_IsLevelActive(log, g_LogLevel))
607 WLog_Print(log, g_LogLevel,
"%s {", name);
608 smartcard_log_context(log, phContext);
609 WLog_Print(log, g_LogLevel,
" sz=%s", sz);
611 WLog_Print(log, g_LogLevel,
"}");
614static void smartcard_trace_context_and_string_call_w(wLog* log,
const char* name,
620 if (!WLog_IsLevelActive(log, g_LogLevel))
624 tmp = ConvertWCharToUtf8Alloc(sz,
nullptr);
626 WLog_Print(log, g_LogLevel,
"%s {", name);
627 smartcard_log_context(log, phContext);
628 WLog_Print(log, g_LogLevel,
" sz=%s", tmp);
629 WLog_Print(log, g_LogLevel,
"}");
633static void smartcard_trace_context_call(wLog* log,
const Context_Call* call,
const char* name)
637 if (!WLog_IsLevelActive(log, g_LogLevel))
640 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
641 smartcard_log_context(log, &call->handles.hContext);
643 WLog_Print(log, g_LogLevel,
"}");
651 if (!WLog_IsLevelActive(log, g_LogLevel))
654 WLog_Print(log, g_LogLevel,
"ListReaderGroups%s_Call {", unicode ?
"W" :
"A");
655 smartcard_log_context(log, &call->handles.hContext);
657 WLog_Print(log, g_LogLevel,
"fmszGroupsIsNULL: %" PRId32
" cchGroups: 0x%08" PRIx32,
658 call->fmszGroupsIsNULL, call->cchGroups);
659 WLog_Print(log, g_LogLevel,
"}");
662static void dump_reader_states_return(wLog* log,
const ReaderState_Return* rgReaderStates,
665 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
666 for (UINT32 index = 0; index < cReaders; index++)
669 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
670 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
671 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
672 szCurrentState, readerState->dwCurrentState);
673 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
674 szEventState, readerState->dwEventState);
675 free(szCurrentState);
678 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
679 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
686 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
687 for (UINT32 index = 0; index < cReaders; index++)
691 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
692 readerState->szReader, readerState->cbAtr);
693 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
694 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
695 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
696 szCurrentState, readerState->dwCurrentState);
697 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
698 szEventState, readerState->dwEventState);
699 free(szCurrentState);
702 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
703 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
710 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
711 for (UINT32 index = 0; index < cReaders; index++)
714 char* buffer = ConvertWCharToUtf8Alloc(readerState->szReader,
nullptr);
715 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
716 buffer, readerState->cbAtr);
718 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
719 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
720 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
721 szCurrentState, readerState->dwCurrentState);
722 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
723 szEventState, readerState->dwEventState);
724 free(szCurrentState);
727 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
728 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
736 if (!WLog_IsLevelActive(log, g_LogLevel))
739 WLog_Print(log, g_LogLevel,
"GetStatusChangeW_Call {");
740 smartcard_log_context(log, &call->handles.hContext);
742 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
745 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
747 WLog_Print(log, g_LogLevel,
"}");
755 if (!WLog_IsLevelActive(log, g_LogLevel))
758 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
760 WLog_Print(log, g_LogLevel,
"ListReaderGroups%s_Return {", unicode ?
"W" :
"A");
761 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIx32
")",
762 SCardGetErrorString(ret->ReturnCode),
763 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
764 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
765 WLog_Print(log, g_LogLevel,
"}");
769static void smartcard_trace_list_readers_call(wLog* log,
const ListReaders_Call* call, BOOL unicode)
773 if (!WLog_IsLevelActive(log, g_LogLevel))
776 char* mszGroupsA = smartcard_convert_string_list(call->mszGroups, call->cBytes, unicode);
778 WLog_Print(log, g_LogLevel,
"ListReaders%s_Call {", unicode ?
"W" :
"A");
779 smartcard_log_context(log, &call->handles.hContext);
781 WLog_Print(log, g_LogLevel,
782 "cBytes: %" PRIu32
" mszGroups: %s fmszReadersIsNULL: %" PRId32
783 " cchReaders: 0x%08" PRIX32
"",
784 call->cBytes, mszGroupsA, call->fmszReadersIsNULL, call->cchReaders);
785 WLog_Print(log, g_LogLevel,
"}");
790static void smartcard_trace_locate_cards_by_atr_a_call(wLog* log,
795 if (!WLog_IsLevelActive(log, g_LogLevel))
798 WLog_Print(log, g_LogLevel,
"LocateCardsByATRA_Call {");
799 smartcard_log_context(log, &call->handles.hContext);
801 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
803 WLog_Print(log, g_LogLevel,
"}");
806static void smartcard_trace_locate_cards_a_call(wLog* log,
const LocateCardsA_Call* call)
810 if (!WLog_IsLevelActive(log, g_LogLevel))
813 WLog_Print(log, g_LogLevel,
"LocateCardsA_Call {");
814 smartcard_log_context(log, &call->handles.hContext);
815 WLog_Print(log, g_LogLevel,
" cBytes=%" PRIu32, call->cBytes);
816 smartcard_msz_dump(log, g_LogLevel,
" mszCards=", call->mszCards, call->cBytes, FALSE);
817 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, call->cReaders);
818 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
820 WLog_Print(log, g_LogLevel,
"}");
823static void smartcard_trace_locate_cards_return(wLog* log,
const LocateCards_Return* ret)
827 if (!WLog_IsLevelActive(log, g_LogLevel))
830 WLog_Print(log, g_LogLevel,
"LocateCards_Return {");
831 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
832 SCardGetErrorString(ret->ReturnCode),
833 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
835 if (ret->ReturnCode == SCARD_S_SUCCESS)
837 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, ret->cReaders);
839 WLog_Print(log, g_LogLevel,
"}");
846 if (!WLog_IsLevelActive(log, g_LogLevel))
849 WLog_Print(log, g_LogLevel,
"GetReaderIcon_Return {");
850 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
851 SCardGetErrorString(ret->ReturnCode),
852 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
854 if (ret->ReturnCode == SCARD_S_SUCCESS)
856 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, ret->cbDataLen);
858 WLog_Print(log, g_LogLevel,
"}");
865 if (!WLog_IsLevelActive(log, g_LogLevel))
868 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Return {");
869 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
870 SCardGetErrorString(ret->ReturnCode),
871 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
873 WLog_Print(log, g_LogLevel,
" cTransmitCount=%" PRIu32, ret->cTransmitCount);
874 WLog_Print(log, g_LogLevel,
"}");
877static void smartcard_trace_read_cache_return(wLog* log,
const ReadCache_Return* ret)
881 if (!WLog_IsLevelActive(log, g_LogLevel))
884 WLog_Print(log, g_LogLevel,
"ReadCache_Return {");
885 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
886 SCardGetErrorString(ret->ReturnCode),
887 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
889 if (ret->ReturnCode == SCARD_S_SUCCESS)
891 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, ret->cbDataLen);
892 smartcard_dump_array(log, g_LogLevel,
" cbData: ",
"", ret->pbData, ret->cbDataLen);
894 WLog_Print(log, g_LogLevel,
"}");
897static void smartcard_trace_locate_cards_w_call(wLog* log,
const LocateCardsW_Call* call)
901 if (!WLog_IsLevelActive(log, g_LogLevel))
904 WLog_Print(log, g_LogLevel,
"LocateCardsW_Call {");
905 smartcard_log_context(log, &call->handles.hContext);
906 WLog_Print(log, g_LogLevel,
" cBytes=%" PRIu32, call->cBytes);
907 smartcard_msz_dump(log, g_LogLevel,
" sz2=", call->mszCards, call->cBytes, TRUE);
908 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, call->cReaders);
909 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
910 WLog_Print(log, g_LogLevel,
"}");
913static void smartcard_trace_list_readers_return(wLog* log,
const ListReaders_Return* ret,
918 if (!WLog_IsLevelActive(log, g_LogLevel))
921 WLog_Print(log, g_LogLevel,
"ListReaders%s_Return {", unicode ?
"W" :
"A");
922 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
923 SCardGetErrorString(ret->ReturnCode),
924 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
926 if (ret->ReturnCode != SCARD_S_SUCCESS)
928 WLog_Print(log, g_LogLevel,
"}");
932 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
934 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
935 WLog_Print(log, g_LogLevel,
"}");
944 if (!WLog_IsLevelActive(log, g_LogLevel))
947 WLog_Print(log, g_LogLevel,
"GetStatusChange%s_Return {", unicode ?
"W" :
"A");
948 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
949 SCardGetErrorString(ret->ReturnCode),
950 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
951 WLog_Print(log, g_LogLevel,
" cReaders: %" PRIu32
"", ret->cReaders);
953 dump_reader_states_return(log, ret->rgReaderStates, ret->cReaders);
955 if (!ret->rgReaderStates && (ret->cReaders > 0))
957 WLog_Print(log, g_LogLevel,
" [INVALID STATE] rgReaderStates=nullptr, cReaders=%" PRIu32,
960 else if (ret->ReturnCode != SCARD_S_SUCCESS)
962 WLog_Print(log, g_LogLevel,
" [INVALID RETURN] rgReaderStates, cReaders=%" PRIu32,
967 for (UINT32 index = 0; index < ret->cReaders; index++)
970 char* szCurrentState = SCardGetReaderStateString(rgReaderState->dwCurrentState);
971 char* szEventState = SCardGetReaderStateString(rgReaderState->dwEventState);
972 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")",
973 index, szCurrentState, rgReaderState->dwCurrentState);
974 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")",
975 index, szEventState, rgReaderState->dwEventState);
976 smartcard_dump_array(
977 log, g_LogLevel,
" [%" PRIu32
"]: cbAtr: %" PRIu32
" rgbAtr: ",
"",
978 rgReaderState->rgbAtr, rgReaderState->cbAtr, index, rgReaderState->cbAtr);
979 free(szCurrentState);
984 WLog_Print(log, g_LogLevel,
"}");
987static void smartcard_trace_context_and_two_strings_a_call(wLog* log,
992 if (!WLog_IsLevelActive(log, g_LogLevel))
995 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
996 smartcard_log_context(log, &call->handles.hContext);
997 WLog_Print(log, g_LogLevel,
" sz1=%s", call->sz1);
998 WLog_Print(log, g_LogLevel,
" sz2=%s", call->sz2);
999 WLog_Print(log, g_LogLevel,
"}");
1002static void smartcard_trace_context_and_two_strings_w_call(wLog* log,
1006 char sz1[1024] = WINPR_C_ARRAY_INIT;
1007 char sz2[1024] = WINPR_C_ARRAY_INIT;
1009 if (!WLog_IsLevelActive(log, g_LogLevel))
1012 (void)ConvertWCharToUtf8(call->sz1, sz1, ARRAYSIZE(sz1));
1014 (void)ConvertWCharToUtf8(call->sz2, sz2, ARRAYSIZE(sz2));
1016 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
1017 smartcard_log_context(log, &call->handles.hContext);
1018 WLog_Print(log, g_LogLevel,
" sz1=%s", sz1);
1019 WLog_Print(log, g_LogLevel,
" sz2=%s", sz2);
1020 WLog_Print(log, g_LogLevel,
"}");
1027 if (!WLog_IsLevelActive(log, g_LogLevel))
1030 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Call {");
1031 smartcard_log_context(log, &call->handles.hContext);
1032 smartcard_log_redir_handle(log, &call->handles.hCard);
1034 WLog_Print(log, g_LogLevel,
"}");
1037static void smartcard_trace_write_cache_a_call(wLog* log,
const WriteCacheA_Call* call)
1041 if (!WLog_IsLevelActive(log, g_LogLevel))
1044 WLog_Print(log, g_LogLevel,
"WriteCacheA_Call {");
1046 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
1048 smartcard_log_context(log, &call->Common.handles.hContext);
1049 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1051 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1052 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1053 smartcard_dump_array(log, g_LogLevel,
" pbData=",
"", call->Common.pbData,
1054 call->Common.cbDataLen);
1055 WLog_Print(log, g_LogLevel,
"}");
1058static void smartcard_trace_write_cache_w_call(wLog* log,
const WriteCacheW_Call* call)
1061 char tmp[1024] = WINPR_C_ARRAY_INIT;
1063 if (!WLog_IsLevelActive(log, g_LogLevel))
1066 WLog_Print(log, g_LogLevel,
"WriteCacheW_Call {");
1068 if (call->szLookupName)
1069 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
1070 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
1072 smartcard_log_context(log, &call->Common.handles.hContext);
1073 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1075 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1076 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1077 smartcard_dump_array(log, g_LogLevel,
" pbData=",
"", call->Common.pbData,
1078 call->Common.cbDataLen);
1079 WLog_Print(log, g_LogLevel,
"}");
1082static void smartcard_trace_read_cache_a_call(wLog* log,
const ReadCacheA_Call* call)
1086 if (!WLog_IsLevelActive(log, g_LogLevel))
1089 WLog_Print(log, g_LogLevel,
"ReadCacheA_Call {");
1091 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
1092 smartcard_log_context(log, &call->Common.handles.hContext);
1093 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1095 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1096 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1097 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1099 WLog_Print(log, g_LogLevel,
"}");
1102static void smartcard_trace_read_cache_w_call(wLog* log,
const ReadCacheW_Call* call)
1105 char tmp[1024] = WINPR_C_ARRAY_INIT;
1107 if (!WLog_IsLevelActive(log, g_LogLevel))
1110 WLog_Print(log, g_LogLevel,
"ReadCacheW_Call {");
1111 if (call->szLookupName)
1112 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
1113 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
1115 smartcard_log_context(log, &call->Common.handles.hContext);
1116 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1118 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1119 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1120 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1122 WLog_Print(log, g_LogLevel,
"}");
1125static void smartcard_trace_transmit_call(wLog* log,
const Transmit_Call* call)
1128 UINT32 cbExtraBytes = 0;
1129 BYTE* pbExtraBytes =
nullptr;
1131 if (!WLog_IsLevelActive(log, g_LogLevel))
1134 WLog_Print(log, g_LogLevel,
"Transmit_Call {");
1135 smartcard_log_context(log, &call->handles.hContext);
1136 smartcard_log_redir_handle(log, &call->handles.hCard);
1138 if (call->pioSendPci)
1140 cbExtraBytes = (UINT32)(call->pioSendPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1142 WLog_Print(log, g_LogLevel,
"pioSendPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1143 call->pioSendPci->dwProtocol, cbExtraBytes);
1147 smartcard_dump_array(log, g_LogLevel,
"pbExtraBytes: ",
"", pbExtraBytes, cbExtraBytes);
1152 WLog_Print(log, g_LogLevel,
"pioSendPci: null");
1155 WLog_Print(log, g_LogLevel,
"cbSendLength: %" PRIu32
"", call->cbSendLength);
1157 if (call->pbSendBuffer)
1159 smartcard_dump_array(log, g_LogLevel,
"pbSendBuffer: ",
"", call->pbSendBuffer,
1160 call->cbSendLength);
1164 WLog_Print(log, g_LogLevel,
"pbSendBuffer: null");
1167 if (call->pioRecvPci)
1169 cbExtraBytes = (UINT32)(call->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1171 WLog_Print(log, g_LogLevel,
"pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1172 call->pioRecvPci->dwProtocol, cbExtraBytes);
1176 smartcard_dump_array(log, g_LogLevel,
"pbExtraBytes: ",
"", pbExtraBytes, cbExtraBytes);
1181 WLog_Print(log, g_LogLevel,
"pioRecvPci: null");
1184 WLog_Print(log, g_LogLevel,
"fpbRecvBufferIsNULL: %" PRId32
" cbRecvLength: %" PRIu32
"",
1185 call->fpbRecvBufferIsNULL, call->cbRecvLength);
1186 WLog_Print(log, g_LogLevel,
"}");
1189static void smartcard_trace_locate_cards_by_atr_w_call(wLog* log,
1194 if (!WLog_IsLevelActive(log, g_LogLevel))
1197 WLog_Print(log, g_LogLevel,
"LocateCardsByATRW_Call {");
1198 smartcard_log_context(log, &call->handles.hContext);
1200 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
1202 WLog_Print(log, g_LogLevel,
"}");
1205static void smartcard_trace_transmit_return(wLog* log,
const Transmit_Return* ret)
1208 UINT32 cbExtraBytes = 0;
1209 BYTE* pbExtraBytes =
nullptr;
1211 if (!WLog_IsLevelActive(log, g_LogLevel))
1214 WLog_Print(log, g_LogLevel,
"Transmit_Return {");
1215 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1216 SCardGetErrorString(ret->ReturnCode),
1217 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1219 if (ret->pioRecvPci)
1221 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1223 WLog_Print(log, g_LogLevel,
1224 " pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1225 ret->pioRecvPci->dwProtocol, cbExtraBytes);
1229 smartcard_dump_array(log, g_LogLevel,
" pbExtraBytes: ",
"", pbExtraBytes,
1235 WLog_Print(log, g_LogLevel,
" pioRecvPci: null");
1238 WLog_Print(log, g_LogLevel,
" cbRecvLength: %" PRIu32
"", ret->cbRecvLength);
1240 if (ret->pbRecvBuffer)
1242 smartcard_dump_array(log, g_LogLevel,
" pbRecvBuffer: ",
"", ret->pbRecvBuffer,
1247 WLog_Print(log, g_LogLevel,
" pbRecvBuffer: null");
1250 WLog_Print(log, g_LogLevel,
"}");
1253static void smartcard_trace_control_return(wLog* log,
const Control_Return* ret)
1257 if (!WLog_IsLevelActive(log, g_LogLevel))
1260 WLog_Print(log, g_LogLevel,
"Control_Return {");
1261 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1262 SCardGetErrorString(ret->ReturnCode),
1263 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1264 WLog_Print(log, g_LogLevel,
" cbOutBufferSize: %" PRIu32
"", ret->cbOutBufferSize);
1266 if (ret->pvOutBuffer)
1268 smartcard_dump_array(log, g_LogLevel,
"pvOutBuffer: ",
"", ret->pvOutBuffer,
1269 ret->cbOutBufferSize);
1273 WLog_Print(log, g_LogLevel,
"pvOutBuffer: null");
1276 WLog_Print(log, g_LogLevel,
"}");
1279static void smartcard_trace_control_call(wLog* log,
const Control_Call* call)
1283 if (!WLog_IsLevelActive(log, g_LogLevel))
1286 WLog_Print(log, g_LogLevel,
"Control_Call {");
1287 smartcard_log_context(log, &call->handles.hContext);
1288 smartcard_log_redir_handle(log, &call->handles.hCard);
1290 WLog_Print(log, g_LogLevel,
1291 "dwControlCode: 0x%08" PRIX32
" cbInBufferSize: %" PRIu32
1292 " fpvOutBufferIsNULL: %" PRId32
" cbOutBufferSize: %" PRIu32
"",
1293 call->dwControlCode, call->cbInBufferSize, call->fpvOutBufferIsNULL,
1294 call->cbOutBufferSize);
1296 if (call->pvInBuffer)
1298 smartcard_dump_array(log, WLOG_DEBUG,
"pbInBuffer: ",
"", call->pvInBuffer,
1299 call->cbInBufferSize);
1303 WLog_Print(log, g_LogLevel,
"pvInBuffer: null");
1306 WLog_Print(log, g_LogLevel,
"}");
1309static void smartcard_trace_set_attrib_call(wLog* log,
const SetAttrib_Call* call)
1313 if (!WLog_IsLevelActive(log, g_LogLevel))
1316 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1317 smartcard_log_context(log, &call->handles.hContext);
1318 smartcard_log_redir_handle(log, &call->handles.hCard);
1319 WLog_Print(log, g_LogLevel,
"dwAttrId: 0x%08" PRIX32, call->dwAttrId);
1320 WLog_Print(log, g_LogLevel,
"cbAttrLen: 0x%08" PRIx32, call->cbAttrLen);
1321 smartcard_dump_array(log, g_LogLevel,
"pbAttr: ",
"", call->pbAttr, call->cbAttrLen);
1322 WLog_Print(log, g_LogLevel,
"}");
1325static void smartcard_trace_get_attrib_return(wLog* log,
const GetAttrib_Return* ret,
1330 if (!WLog_IsLevelActive(log, g_LogLevel))
1333 WLog_Print(log, g_LogLevel,
"GetAttrib_Return {");
1334 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1335 SCardGetErrorString(ret->ReturnCode),
1336 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1337 WLog_Print(log, g_LogLevel,
" dwAttrId: %s (0x%08" PRIX32
") cbAttrLen: 0x%08" PRIX32
"",
1338 SCardGetAttributeString(dwAttrId), dwAttrId, ret->cbAttrLen);
1339 smartcard_dump_array(log, g_LogLevel,
" ",
"", ret->pbAttr, ret->cbAttrLen);
1341 WLog_Print(log, g_LogLevel,
"}");
1344static void smartcard_trace_get_attrib_call(wLog* log,
const GetAttrib_Call* call)
1348 if (!WLog_IsLevelActive(log, g_LogLevel))
1351 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1352 smartcard_log_context(log, &call->handles.hContext);
1353 smartcard_log_redir_handle(log, &call->handles.hCard);
1355 WLog_Print(log, g_LogLevel,
1356 "dwAttrId: %s (0x%08" PRIX32
") fpbAttrIsNULL: %" PRId32
" cbAttrLen: 0x%08" PRIX32
1358 SCardGetAttributeString(call->dwAttrId), call->dwAttrId, call->fpbAttrIsNULL,
1360 WLog_Print(log, g_LogLevel,
"}");
1363static void smartcard_trace_status_call(wLog* log,
const Status_Call* call, BOOL unicode)
1367 if (!WLog_IsLevelActive(log, g_LogLevel))
1370 WLog_Print(log, g_LogLevel,
"Status%s_Call {", unicode ?
"W" :
"A");
1371 smartcard_log_context(log, &call->handles.hContext);
1372 smartcard_log_redir_handle(log, &call->handles.hCard);
1374 WLog_Print(log, g_LogLevel,
1375 "fmszReaderNamesIsNULL: %" PRId32
" cchReaderLen: %" PRIu32
" cbAtrLen: %" PRIu32
"",
1376 call->fmszReaderNamesIsNULL, call->cchReaderLen, call->cbAtrLen);
1377 WLog_Print(log, g_LogLevel,
"}");
1380static void smartcard_trace_status_return(wLog* log,
const Status_Return* ret, BOOL unicode)
1383 char* mszReaderNamesA =
nullptr;
1386 if (!WLog_IsLevelActive(log, g_LogLevel))
1388 cBytes = ret->cBytes;
1389 if (ret->ReturnCode != SCARD_S_SUCCESS)
1391 if (cBytes == SCARD_AUTOALLOCATE)
1393 mszReaderNamesA = smartcard_convert_string_list(ret->mszReaderNames, cBytes, unicode);
1395 WLog_Print(log, g_LogLevel,
"Status%s_Return {", unicode ?
"W" :
"A");
1396 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1397 SCardGetErrorString(ret->ReturnCode),
1398 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1399 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
") dwProtocol: %s (0x%08" PRIX32
")",
1400 SCardGetCardStateString(ret->dwState), ret->dwState,
1401 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1403 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" mszReaderNames: %s", ret->cBytes,
1406 smartcard_dump_array(log, g_LogLevel,
" cbAtrLen: %" PRIu32
" pbAtr: ",
"", ret->pbAtr,
1407 ret->cbAtrLen, ret->cbAtrLen);
1408 WLog_Print(log, g_LogLevel,
"}");
1409 free(mszReaderNamesA);
1412static void smartcard_trace_state_return(wLog* log,
const State_Return* ret)
1415 char* state =
nullptr;
1417 if (!WLog_IsLevelActive(log, g_LogLevel))
1420 state = SCardGetReaderStateString(ret->dwState);
1421 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1422 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1423 SCardGetErrorString(ret->ReturnCode),
1424 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1425 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
")", state, ret->dwState);
1426 WLog_Print(log, g_LogLevel,
" dwProtocol: %s (0x%08" PRIX32
")",
1427 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1428 WLog_Print(log, g_LogLevel,
" cbAtrLen: (0x%08" PRIX32
")", ret->cbAtrLen);
1429 smartcard_dump_array(log, g_LogLevel,
" rgAtr: ",
"", ret->rgAtr,
sizeof(ret->rgAtr));
1430 WLog_Print(log, g_LogLevel,
"}");
1434static void smartcard_trace_reconnect_return(wLog* log,
const Reconnect_Return* ret)
1438 if (!WLog_IsLevelActive(log, g_LogLevel))
1441 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1442 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1443 SCardGetErrorString(ret->ReturnCode),
1444 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1445 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1446 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1447 WLog_Print(log, g_LogLevel,
"}");
1450static void smartcard_trace_connect_a_call(wLog* log,
const ConnectA_Call* call)
1454 if (!WLog_IsLevelActive(log, g_LogLevel))
1457 WLog_Print(log, g_LogLevel,
"ConnectA_Call {");
1458 smartcard_log_context(log, &call->Common.handles.hContext);
1460 WLog_Print(log, g_LogLevel,
1461 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1462 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1463 call->szReader, SCardGetShareModeString(call->Common.dwShareMode),
1464 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1465 call->Common.dwPreferredProtocols);
1466 WLog_Print(log, g_LogLevel,
"}");
1469static void smartcard_trace_connect_w_call(wLog* log,
const ConnectW_Call* call)
1472 char szReaderA[1024] = WINPR_C_ARRAY_INIT;
1474 if (!WLog_IsLevelActive(log, g_LogLevel))
1478 (void)ConvertWCharToUtf8(call->szReader, szReaderA, ARRAYSIZE(szReaderA));
1479 WLog_Print(log, g_LogLevel,
"ConnectW_Call {");
1480 smartcard_log_context(log, &call->Common.handles.hContext);
1482 WLog_Print(log, g_LogLevel,
1483 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1484 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1485 szReaderA, SCardGetShareModeString(call->Common.dwShareMode),
1486 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1487 call->Common.dwPreferredProtocols);
1488 WLog_Print(log, g_LogLevel,
"}");
1491static void smartcard_trace_hcard_and_disposition_call(wLog* log,
1497 if (!WLog_IsLevelActive(log, g_LogLevel))
1500 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
1501 smartcard_log_context(log, &call->handles.hContext);
1502 smartcard_log_redir_handle(log, &call->handles.hCard);
1504 WLog_Print(log, g_LogLevel,
"dwDisposition: %s (0x%08" PRIX32
")",
1505 SCardGetDispositionString(call->dwDisposition), call->dwDisposition);
1506 WLog_Print(log, g_LogLevel,
"}");
1513 if (!WLog_IsLevelActive(log, g_LogLevel))
1516 WLog_Print(log, g_LogLevel,
"EstablishContext_Call {");
1517 WLog_Print(log, g_LogLevel,
"dwScope: %s (0x%08" PRIX32
")", SCardGetScopeString(call->dwScope),
1519 WLog_Print(log, g_LogLevel,
"}");
1526 if (!WLog_IsLevelActive(log, g_LogLevel))
1529 WLog_Print(log, g_LogLevel,
"EstablishContext_Return {");
1530 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1531 SCardGetErrorString(ret->ReturnCode),
1532 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1533 smartcard_log_context(log, &ret->hContext);
1535 WLog_Print(log, g_LogLevel,
"}");
1538void smartcard_trace_long_return(
const Long_Return* ret,
const char* name)
1540 wLog* log = scard_log();
1541 smartcard_trace_long_return_int(log, ret, name);
1544void smartcard_trace_long_return_int(wLog* log,
const Long_Return* ret,
const char* name)
1548 if (!WLog_IsLevelActive(log, g_LogLevel))
1551 WLog_Print(log, g_LogLevel,
"%s_Return {", name);
1552 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1553 SCardGetErrorString(ret->ReturnCode),
1554 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1555 WLog_Print(log, g_LogLevel,
"}");
1558static void smartcard_trace_connect_return(wLog* log,
const Connect_Return* ret)
1562 if (!WLog_IsLevelActive(log, g_LogLevel))
1565 WLog_Print(log, g_LogLevel,
"Connect_Return {");
1566 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1567 SCardGetErrorString(ret->ReturnCode),
1568 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1569 smartcard_log_context(log, &ret->hContext);
1570 smartcard_log_redir_handle(log, &ret->hCard);
1572 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1573 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1574 WLog_Print(log, g_LogLevel,
"}");
1577static void smartcard_trace_reconnect_call(wLog* log,
const Reconnect_Call* call)
1581 if (!WLog_IsLevelActive(log, g_LogLevel))
1584 WLog_Print(log, g_LogLevel,
"Reconnect_Call {");
1585 smartcard_log_context(log, &call->handles.hContext);
1586 smartcard_log_redir_handle(log, &call->handles.hCard);
1588 WLog_Print(log, g_LogLevel,
1589 "dwShareMode: %s (0x%08" PRIX32
") dwPreferredProtocols: %s (0x%08" PRIX32
1590 ") dwInitialization: %s (0x%08" PRIX32
")",
1591 SCardGetShareModeString(call->dwShareMode), call->dwShareMode,
1592 SCardGetProtocolString(call->dwPreferredProtocols), call->dwPreferredProtocols,
1593 SCardGetDispositionString(call->dwInitialization), call->dwInitialization);
1594 WLog_Print(log, g_LogLevel,
"}");
1601 if (!WLog_IsLevelActive(log, g_LogLevel))
1604 WLog_Print(log, g_LogLevel,
"GetDeviceTypeId_Return {");
1605 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1606 SCardGetErrorString(ret->ReturnCode),
1607 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1608 WLog_Print(log, g_LogLevel,
" dwDeviceId=%08" PRIx32, ret->dwDeviceId);
1610 WLog_Print(log, g_LogLevel,
"}");
1613static LONG smartcard_unpack_common_context_and_string_a(wLog* log,
wStream* s,
1615 CHAR** pszReaderName)
1618 UINT32 pbContextNdrPtr = 0;
1619 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1620 if (status != SCARD_S_SUCCESS)
1623 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
1624 return ERROR_INVALID_DATA;
1626 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1627 if (status != SCARD_S_SUCCESS)
1630 status = smartcard_ndr_read_a(log, s, pszReaderName, NDR_PTR_FULL);
1631 if (status != SCARD_S_SUCCESS)
1634 smartcard_trace_context_and_string_call_a(log, __func__, phContext, *pszReaderName);
1635 return SCARD_S_SUCCESS;
1638static LONG smartcard_unpack_common_context_and_string_w(wLog* log,
wStream* s,
1640 WCHAR** pszReaderName)
1643 UINT32 pbContextNdrPtr = 0;
1645 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1646 if (status != SCARD_S_SUCCESS)
1649 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
1650 return ERROR_INVALID_DATA;
1652 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1653 if (status != SCARD_S_SUCCESS)
1656 status = smartcard_ndr_read_w(log, s, pszReaderName, NDR_PTR_FULL);
1657 if (status != SCARD_S_SUCCESS)
1660 smartcard_trace_context_and_string_call_w(log, __func__, phContext, *pszReaderName);
1661 return SCARD_S_SUCCESS;
1664LONG smartcard_unpack_common_type_header(
wStream* s)
1666 wLog* log = scard_log();
1669 UINT8 endianness = 0;
1670 UINT16 commonHeaderLength = 0;
1672 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1673 return STATUS_BUFFER_TOO_SMALL;
1676 Stream_Read_UINT8(s, version);
1677 Stream_Read_UINT8(s, endianness);
1678 Stream_Read_UINT16(s, commonHeaderLength);
1679 Stream_Read_UINT32(s, filler);
1683 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Version %" PRIu8
"", version);
1684 return STATUS_INVALID_PARAMETER;
1687 if (endianness != 0x10)
1689 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Endianness %" PRIu8
"",
1691 return STATUS_INVALID_PARAMETER;
1694 if (commonHeaderLength != 8)
1696 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader CommonHeaderLength %" PRIu16
"",
1697 commonHeaderLength);
1698 return STATUS_INVALID_PARAMETER;
1701 if (filler != 0xCCCCCCCC)
1703 WLog_Print(log, WLOG_WARN,
"Unexpected CommonTypeHeader Filler 0x%08" PRIX32
"", filler);
1704 return STATUS_INVALID_PARAMETER;
1707 return SCARD_S_SUCCESS;
1710void smartcard_pack_common_type_header(
wStream* s)
1712 Stream_Write_UINT8(s, 1);
1713 Stream_Write_UINT8(s, 0x10);
1714 Stream_Write_UINT16(s, 8);
1715 Stream_Write_UINT32(s, 0xCCCCCCCC);
1718LONG smartcard_unpack_private_type_header(
wStream* s)
1720 wLog* log = scard_log();
1722 UINT32 objectBufferLength = 0;
1724 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1725 return STATUS_BUFFER_TOO_SMALL;
1727 Stream_Read_UINT32(s, objectBufferLength);
1728 Stream_Read_UINT32(s, filler);
1730 if (filler != 0x00000000)
1732 WLog_Print(log, WLOG_WARN,
"Unexpected PrivateTypeHeader Filler 0x%08" PRIX32
"", filler);
1733 return STATUS_INVALID_PARAMETER;
1736 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, objectBufferLength))
1737 return STATUS_INVALID_PARAMETER;
1739 return SCARD_S_SUCCESS;
1742void smartcard_pack_private_type_header(
wStream* s, UINT32 objectBufferLength)
1744 Stream_Write_UINT32(s, objectBufferLength);
1745 Stream_Write_UINT32(s, 0x00000000);
1748LONG smartcard_unpack_read_size_align(
wStream* s,
size_t size, UINT32 alignment)
1750 const size_t padsize = (size + alignment - 1) & ~(alignment - 1);
1751 const size_t pad = padsize - size;
1755 if (!Stream_SafeSeek(s, pad))
1762LONG smartcard_pack_write_size_align(
wStream* s,
size_t size, UINT32 alignment)
1764 const size_t padsize = (size + alignment - 1) & ~(alignment - 1);
1765 const size_t pad = padsize - size;
1769 if (!Stream_EnsureRemainingCapacity(s, pad))
1771 wLog* log = scard_log();
1772 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
1773 return SCARD_F_INTERNAL_ERROR;
1776 Stream_Zero(s, pad);
1779 return SCARD_S_SUCCESS;
1782SCARDCONTEXT smartcard_scard_context_native_from_redir(
const REDIR_SCARDCONTEXT* context)
1784 SCARDCONTEXT hContext = WINPR_C_ARRAY_INIT;
1786 WINPR_ASSERT(context);
1787 if ((context->cbContext !=
sizeof(ULONG_PTR)) && (context->cbContext != 0))
1789 wLog* log = scard_log();
1790 WLog_Print(log, WLOG_WARN,
1791 "REDIR_SCARDCONTEXT does not match native size: Actual: %" PRIu32
1792 ", Expected: %" PRIuz
"",
1793 context->cbContext,
sizeof(ULONG_PTR));
1797 if (context->cbContext)
1798 CopyMemory(&hContext, &(context->pbContext), context->cbContext);
1803void smartcard_scard_context_native_to_redir(
REDIR_SCARDCONTEXT* context, SCARDCONTEXT hContext)
1805 WINPR_ASSERT(context);
1807 context->cbContext =
sizeof(ULONG_PTR);
1808 CopyMemory(&(context->pbContext), &hContext, context->cbContext);
1811SCARDHANDLE smartcard_scard_handle_native_from_redir(
const REDIR_SCARDHANDLE* handle)
1813 SCARDHANDLE hCard = 0;
1815 WINPR_ASSERT(handle);
1816 if (handle->cbHandle == 0)
1819 if (handle->cbHandle !=
sizeof(ULONG_PTR))
1821 wLog* log = scard_log();
1822 WLog_Print(log, WLOG_WARN,
1823 "REDIR_SCARDHANDLE does not match native size: Actual: %" PRIu32
1824 ", Expected: %" PRIuz
"",
1825 handle->cbHandle,
sizeof(ULONG_PTR));
1829 if (handle->cbHandle)
1830 CopyMemory(&hCard, &(handle->pbHandle), handle->cbHandle);
1835void smartcard_scard_handle_native_to_redir(
REDIR_SCARDHANDLE* handle, SCARDHANDLE hCard)
1837 WINPR_ASSERT(handle);
1839 handle->cbHandle =
sizeof(ULONG_PTR);
1840 CopyMemory(&(handle->pbHandle), &hCard, handle->cbHandle);
1843#define smartcard_context_supported(log, size) \
1844 smartcard_context_supported_((log), (size), __FILE__, __func__, __LINE__)
1845static LONG smartcard_context_supported_(wLog* log, uint32_t size,
const char* file,
1846 const char* fkt,
size_t line)
1853 return SCARD_S_SUCCESS;
1856 const uint32_t level = WLOG_WARN;
1857 if (WLog_IsLevelActive(log, level))
1859 WLog_PrintTextMessage(log, level, line, file, fkt,
1860 "REDIR_SCARDCONTEXT length is not 0, 4 or 8: %" PRIu32
"",
1863 return STATUS_INVALID_PARAMETER;
1869 UINT32* index, UINT32* ppbContextNdrPtr,
1870 const char* file,
const char* function,
size_t line)
1872 UINT32 pbContextNdrPtr = 0;
1875 WINPR_ASSERT(context);
1879 if (!Stream_CheckAndLogRequiredLengthWLogEx(log, WLOG_WARN, s, 4, 1,
"%s(%s:%" PRIuz
")", file,
1881 return STATUS_BUFFER_TOO_SMALL;
1883 const LONG status = smartcard_context_supported_(log, context->cbContext, file, function, line);
1884 if (status != SCARD_S_SUCCESS)
1887 Stream_Read_UINT32(s, context->cbContext);
1889 if (!smartcard_ndr_pointer_read_(log, s, index, &pbContextNdrPtr, file, function, line))
1890 return ERROR_INVALID_DATA;
1892 if (((context->cbContext == 0) && pbContextNdrPtr) ||
1893 ((context->cbContext != 0) && !pbContextNdrPtr))
1895 WLog_Print(log, WLOG_WARN,
1896 "REDIR_SCARDCONTEXT cbContext (%" PRIu32
") pbContextNdrPtr (%" PRIu32
1898 context->cbContext, pbContextNdrPtr);
1899 return STATUS_INVALID_PARAMETER;
1902 *ppbContextNdrPtr = pbContextNdrPtr;
1903 return SCARD_S_SUCCESS;
1906LONG smartcard_pack_redir_scard_context(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1909 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
1911 WINPR_ASSERT(context);
1912 if (context->cbContext != 0)
1914 Stream_Write_UINT32(s, context->cbContext);
1915 Stream_Write_UINT32(s, pbContextNdrPtr);
1916 *index = *index + 1;
1921 return SCARD_S_SUCCESS;
1924LONG smartcard_unpack_redir_scard_context_ref(wLog* log,
wStream* s,
1925 WINPR_ATTR_UNUSED UINT32 pbContextNdrPtr,
1930 WINPR_ASSERT(context);
1932 if (context->cbContext == 0)
1933 return SCARD_S_SUCCESS;
1935 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1936 return STATUS_BUFFER_TOO_SMALL;
1938 Stream_Read_UINT32(s, length);
1940 if (length != context->cbContext)
1942 WLog_Print(log, WLOG_WARN,
1943 "REDIR_SCARDCONTEXT length (%" PRIu32
") cbContext (%" PRIu32
") mismatch",
1944 length, context->cbContext);
1945 return STATUS_INVALID_PARAMETER;
1948 const LONG status = smartcard_context_supported(log, context->cbContext);
1949 if (status != SCARD_S_SUCCESS)
1952 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, context->cbContext))
1953 return STATUS_BUFFER_TOO_SMALL;
1955 if (context->cbContext)
1956 Stream_Read(s, &(context->pbContext), context->cbContext);
1958 ZeroMemory(&(context->pbContext),
sizeof(context->pbContext));
1960 return SCARD_S_SUCCESS;
1963LONG smartcard_pack_redir_scard_context_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1966 WINPR_ASSERT(context);
1968 if (context->cbContext == 0)
1969 return SCARD_S_SUCCESS;
1971 Stream_Write_UINT32(s, context->cbContext);
1972 Stream_Write(s, &(context->pbContext), context->cbContext);
1974 return SCARD_S_SUCCESS;
1978 UINT32* index,
const char* file,
const char* function,
1981 UINT32 pbHandleNdrPtr = 0;
1983 WINPR_ASSERT(handle);
1986 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1987 return STATUS_BUFFER_TOO_SMALL;
1989 Stream_Read_UINT32(s, handle->cbHandle);
1991 if (!smartcard_ndr_pointer_read_(log, s, index, &pbHandleNdrPtr, file, function, line))
1992 return ERROR_INVALID_DATA;
1994 if (((handle->cbHandle == 0) && pbHandleNdrPtr) ||
1995 ((handle->cbHandle != 0) && !pbHandleNdrPtr))
1997 WLog_Print(log, WLOG_WARN,
1998 "REDIR_SCARDHANDLE cbHandle (%" PRIu32
") pbHandleNdrPtr (%" PRIu32
2000 handle->cbHandle, pbHandleNdrPtr);
2001 return STATUS_INVALID_PARAMETER;
2004 return SCARD_S_SUCCESS;
2007LONG smartcard_pack_redir_scard_handle(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
2010 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
2012 WINPR_ASSERT(handle);
2013 if (handle->cbHandle != 0)
2015 Stream_Write_UINT32(s, handle->cbHandle);
2016 Stream_Write_UINT32(s, pbContextNdrPtr);
2017 *index = *index + 1;
2021 return SCARD_S_SUCCESS;
2028 WINPR_ASSERT(handle);
2030 if (handle->cbHandle == 0)
2031 return SCARD_S_SUCCESS;
2033 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2034 return STATUS_BUFFER_TOO_SMALL;
2036 Stream_Read_UINT32(s, length);
2038 if (length != handle->cbHandle)
2040 WLog_Print(log, WLOG_WARN,
2041 "REDIR_SCARDHANDLE length (%" PRIu32
") cbHandle (%" PRIu32
") mismatch", length,
2043 return STATUS_INVALID_PARAMETER;
2046 if ((handle->cbHandle != 4) && (handle->cbHandle != 8))
2048 WLog_Print(log, WLOG_WARN,
"REDIR_SCARDHANDLE length is not 4 or 8: %" PRIu32
"",
2050 return STATUS_INVALID_PARAMETER;
2053 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, handle->cbHandle))
2054 return STATUS_BUFFER_TOO_SMALL;
2056 if (handle->cbHandle)
2057 Stream_Read(s, &(handle->pbHandle), handle->cbHandle);
2059 return SCARD_S_SUCCESS;
2062LONG smartcard_pack_redir_scard_handle_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
2065 WINPR_ASSERT(handle);
2067 if (handle->cbHandle == 0)
2068 return SCARD_S_SUCCESS;
2070 Stream_Write_UINT32(s, handle->cbHandle);
2071 Stream_Write(s, &(handle->pbHandle), handle->cbHandle);
2073 return SCARD_S_SUCCESS;
2079 wLog* log = scard_log();
2081 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2082 return STATUS_BUFFER_TOO_SMALL;
2084 Stream_Read_UINT32(s, call->dwScope);
2085 smartcard_trace_establish_context_call(log, call);
2086 return SCARD_S_SUCCESS;
2092 wLog* log = scard_log();
2094 smartcard_trace_establish_context_call(log, call);
2096 if (!Stream_EnsureRemainingCapacity(s, 4))
2097 return SCARD_E_NO_MEMORY;
2099 Stream_Write_UINT32(s, call->dwScope);
2101 return SCARD_S_SUCCESS;
2107 wLog* log = scard_log();
2111 smartcard_trace_establish_context_return(log, ret);
2112 if (ret->ReturnCode != SCARD_S_SUCCESS)
2113 return ret->ReturnCode;
2115 status = smartcard_pack_redir_scard_context(log, s, &(ret->hContext), &index);
2116 if (status != SCARD_S_SUCCESS)
2119 return smartcard_pack_redir_scard_context_ref(log, s, &(ret->hContext));
2125 wLog* log = scard_log();
2127 UINT32 pbContextNdrPtr = 0;
2130 smartcard_unpack_redir_scard_context(log, s, &(ret->hContext), &index, &pbContextNdrPtr);
2131 if (status != SCARD_S_SUCCESS)
2134 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &(ret->hContext));
2135 if (status != SCARD_S_SUCCESS)
2138 smartcard_trace_establish_context_return(log, ret);
2139 return SCARD_S_SUCCESS;
2145 UINT32 pbContextNdrPtr = 0;
2146 wLog* log = scard_log();
2149 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2151 if (status != SCARD_S_SUCCESS)
2154 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2155 &(call->handles.hContext));
2156 if (status != SCARD_S_SUCCESS)
2157 WLog_Print(log, WLOG_ERROR,
2158 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2161 smartcard_trace_context_call(log, call, name);
2168 UINT32 pbContextNdrPtr = 0;
2169 wLog* log = scard_log();
2172 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2175 if (status != SCARD_S_SUCCESS)
2178 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2179 return STATUS_BUFFER_TOO_SMALL;
2181 Stream_Read_INT32(s, call->fmszGroupsIsNULL);
2182 Stream_Read_UINT32(s, call->cchGroups);
2183 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2184 &(call->handles.hContext));
2186 if (status != SCARD_S_SUCCESS)
2189 smartcard_trace_list_reader_groups_call(log, call, unicode);
2190 return SCARD_S_SUCCESS;
2197 wLog* log = scard_log();
2200 smartcard_trace_list_reader_groups_call(log, call, unicode);
2202 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
2203 if (status != SCARD_S_SUCCESS)
2206 if (!Stream_EnsureRemainingCapacity(s, 8))
2207 return SCARD_E_NO_MEMORY;
2209 Stream_Write_INT32(s, call->fmszGroupsIsNULL);
2210 Stream_Write_UINT32(s, call->cchGroups);
2212 return smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
2219 wLog* log = scard_log();
2221 DWORD cBytes = ret->cBytes;
2224 smartcard_trace_list_reader_groups_return(log, ret, unicode);
2225 if (ret->ReturnCode != SCARD_S_SUCCESS)
2227 if (cBytes == SCARD_AUTOALLOCATE)
2230 if (!Stream_EnsureRemainingCapacity(s, 4))
2231 return SCARD_E_NO_MEMORY;
2233 Stream_Write_UINT32(s, cBytes);
2234 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
2235 return SCARD_E_NO_MEMORY;
2237 status = smartcard_ndr_write(s, ret->msz, cBytes, 1, NDR_PTR_SIMPLE);
2238 if (status != SCARD_S_SUCCESS)
2240 return ret->ReturnCode;
2247 wLog* log = scard_log();
2249 UINT32 mszNdrPtr = 0;
2251 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2252 return STATUS_BUFFER_TOO_SMALL;
2254 const UINT32 cBytes = Stream_Get_UINT32(s);
2256 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
2257 return ERROR_INVALID_DATA;
2261 LONG status = smartcard_ndr_read(log, s, &ret->msz, cBytes, 1, NDR_PTR_SIMPLE);
2262 if (status != SCARD_S_SUCCESS)
2264 ret->cBytes = cBytes;
2267 smartcard_trace_list_reader_groups_return(log, ret, unicode);
2268 return SCARD_S_SUCCESS;
2274 UINT32 mszGroupsNdrPtr = 0;
2275 UINT32 pbContextNdrPtr = 0;
2276 wLog* log = scard_log();
2279 call->mszGroups =
nullptr;
2281 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2283 if (status != SCARD_S_SUCCESS)
2286 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2287 return STATUS_BUFFER_TOO_SMALL;
2289 const UINT32 cBytes = Stream_Get_UINT32(s);
2290 if (!smartcard_ndr_pointer_read(log, s, &index, &mszGroupsNdrPtr))
2291 return ERROR_INVALID_DATA;
2293 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2294 return STATUS_BUFFER_TOO_SMALL;
2295 Stream_Read_INT32(s, call->fmszReadersIsNULL);
2296 Stream_Read_UINT32(s, call->cchReaders);
2298 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2299 &(call->handles.hContext));
2300 if (status != SCARD_S_SUCCESS)
2303 if (mszGroupsNdrPtr)
2305 status = smartcard_ndr_read(log, s, &call->mszGroups, cBytes, 1, NDR_PTR_SIMPLE);
2306 if (status != SCARD_S_SUCCESS)
2308 call->cBytes = cBytes;
2311 smartcard_trace_list_readers_call(log, call, unicode);
2312 return SCARD_S_SUCCESS;
2318 wLog* log = scard_log();
2321 UINT32 size = ret->cBytes;
2323 smartcard_trace_list_readers_return(log, ret, unicode);
2324 if (ret->ReturnCode != SCARD_S_SUCCESS)
2327 if (!Stream_EnsureRemainingCapacity(s, 4))
2329 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
2330 return SCARD_F_INTERNAL_ERROR;
2333 Stream_Write_UINT32(s, size);
2334 if (!smartcard_ndr_pointer_write(s, &index, size))
2335 return SCARD_E_NO_MEMORY;
2337 status = smartcard_ndr_write(s, ret->msz, size, 1, NDR_PTR_SIMPLE);
2338 if (status != SCARD_S_SUCCESS)
2340 return ret->ReturnCode;
2344 UINT32* index, UINT32* ppbContextNdrPtr)
2346 WINPR_ASSERT(common);
2347 LONG status = smartcard_unpack_redir_scard_context(log, s, &(common->handles.hContext), index,
2349 if (status != SCARD_S_SUCCESS)
2352 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2353 return STATUS_BUFFER_TOO_SMALL;
2355 Stream_Read_UINT32(s, common->dwShareMode);
2356 Stream_Read_UINT32(s, common->dwPreferredProtocols);
2357 return SCARD_S_SUCCESS;
2364 UINT32 pbContextNdrPtr = 0;
2367 wLog* log = scard_log();
2369 call->szReader =
nullptr;
2371 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
2372 return ERROR_INVALID_DATA;
2374 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2375 if (status != SCARD_S_SUCCESS)
2377 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2382 status = smartcard_ndr_read_a(log, s, &call->szReader, NDR_PTR_FULL);
2383 if (status != SCARD_S_SUCCESS)
2386 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2387 &(call->Common.handles.hContext));
2388 if (status != SCARD_S_SUCCESS)
2389 WLog_Print(log, WLOG_ERROR,
2390 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2393 smartcard_trace_connect_a_call(log, call);
2401 UINT32 pbContextNdrPtr = 0;
2404 wLog* log = scard_log();
2405 call->szReader =
nullptr;
2407 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
2408 return ERROR_INVALID_DATA;
2410 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2411 if (status != SCARD_S_SUCCESS)
2413 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2418 status = smartcard_ndr_read_w(log, s, &call->szReader, NDR_PTR_FULL);
2419 if (status != SCARD_S_SUCCESS)
2422 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2423 &(call->Common.handles.hContext));
2424 if (status != SCARD_S_SUCCESS)
2425 WLog_Print(log, WLOG_ERROR,
2426 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2429 smartcard_trace_connect_w_call(log, call);
2439 wLog* log = scard_log();
2440 smartcard_trace_connect_return(log, ret);
2442 status = smartcard_pack_redir_scard_context(log, s, &ret->hContext, &index);
2443 if (status != SCARD_S_SUCCESS)
2446 status = smartcard_pack_redir_scard_handle(log, s, &ret->hCard, &index);
2447 if (status != SCARD_S_SUCCESS)
2450 if (!Stream_EnsureRemainingCapacity(s, 4))
2451 return SCARD_E_NO_MEMORY;
2453 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2454 status = smartcard_pack_redir_scard_context_ref(log, s, &ret->hContext);
2455 if (status != SCARD_S_SUCCESS)
2457 return smartcard_pack_redir_scard_handle_ref(log, s, &(ret->hCard));
2463 UINT32 pbContextNdrPtr = 0;
2466 wLog* log = scard_log();
2467 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2469 if (status != SCARD_S_SUCCESS)
2472 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2473 if (status != SCARD_S_SUCCESS)
2476 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2477 return STATUS_BUFFER_TOO_SMALL;
2479 Stream_Read_UINT32(s, call->dwShareMode);
2480 Stream_Read_UINT32(s, call->dwPreferredProtocols);
2481 Stream_Read_UINT32(s, call->dwInitialization);
2483 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2484 &(call->handles.hContext));
2485 if (status != SCARD_S_SUCCESS)
2487 WLog_Print(log, WLOG_ERROR,
2488 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2493 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2494 if (status != SCARD_S_SUCCESS)
2495 WLog_Print(log, WLOG_ERROR,
2496 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
2498 smartcard_trace_reconnect_call(log, call);
2505 wLog* log = scard_log();
2508 smartcard_trace_reconnect_call(log, call);
2510 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
2511 if (status != SCARD_S_SUCCESS)
2514 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
2515 if (status != SCARD_S_SUCCESS)
2518 if (!Stream_EnsureRemainingCapacity(s, 12))
2519 return SCARD_E_NO_MEMORY;
2521 Stream_Write_UINT32(s, call->dwShareMode);
2522 Stream_Write_UINT32(s, call->dwPreferredProtocols);
2523 Stream_Write_UINT32(s, call->dwInitialization);
2525 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
2526 if (status != SCARD_S_SUCCESS)
2529 return smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
2535 wLog* log = scard_log();
2536 smartcard_trace_reconnect_return(log, ret);
2538 if (!Stream_EnsureRemainingCapacity(s, 4))
2539 return SCARD_E_NO_MEMORY;
2540 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2541 return ret->ReturnCode;
2547 wLog* log = scard_log();
2549 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2550 return STATUS_BUFFER_TOO_SMALL;
2552 Stream_Read_UINT32(s, ret->dwActiveProtocol);
2554 smartcard_trace_reconnect_return(log, ret);
2555 return SCARD_S_SUCCESS;
2562 UINT32 pbContextNdrPtr = 0;
2565 wLog* log = scard_log();
2567 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2569 if (status != SCARD_S_SUCCESS)
2572 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2573 if (status != SCARD_S_SUCCESS)
2576 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2577 return STATUS_BUFFER_TOO_SMALL;
2579 Stream_Read_UINT32(s, call->dwDisposition);
2581 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2582 &(call->handles.hContext));
2583 if (status != SCARD_S_SUCCESS)
2586 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2587 if (status != SCARD_S_SUCCESS)
2590 smartcard_trace_hcard_and_disposition_call(log, call, name);
2598 if (!WLog_IsLevelActive(log, g_LogLevel))
2601 WLog_Print(log, g_LogLevel,
"GetStatusChangeA_Call {");
2602 smartcard_log_context(log, &call->handles.hContext);
2604 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
2607 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
2609 WLog_Print(log, g_LogLevel,
"}");
2613 UINT32 cReaders, UINT32* ptrIndex)
2615 LONG status = SCARD_E_NO_MEMORY;
2617 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2618 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2621 const UINT32 len = Stream_Get_UINT32(s);
2622 if (len != cReaders)
2624 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEA");
2630 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2631 if (!rgReaderStates || !states)
2633 status = ERROR_INVALID_DATA;
2635 for (UINT32 index = 0; index < cReaders; index++)
2637 UINT32 ptr = UINT32_MAX;
2640 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2643 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2649 states[index] = ptr != 0;
2650 Stream_Read_UINT32(s, readerState->dwCurrentState);
2651 Stream_Read_UINT32(s, readerState->dwEventState);
2652 Stream_Read_UINT32(s, readerState->cbAtr);
2653 if (readerState->cbAtr > ARRAYSIZE(readerState->rgbAtr))
2655 WLog_Print(log, WLOG_ERROR,
2656 "SCARD_READERSTATEA[%" PRIu32
"]::cbAtr %" PRIu32
" exceeds %" PRIuz, index,
2657 readerState->cbAtr, (
size_t)ARRAYSIZE(readerState->rgbAtr));
2660 Stream_Read(s, readerState->rgbAtr, 36);
2663 for (UINT32 index = 0; index < cReaders; index++)
2670 status = smartcard_ndr_read_a(log, s, &readerState->szReader, NDR_PTR_FULL);
2671 if (status != SCARD_S_SUCCESS)
2675 *ppcReaders = rgReaderStates;
2677 return SCARD_S_SUCCESS;
2681 for (UINT32 index = 0; index < cReaders; index++)
2684 free(readerState->szReader);
2687 free(rgReaderStates);
2693 UINT32 cReaders, UINT32* ptrIndex)
2695 LONG status = SCARD_E_NO_MEMORY;
2697 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2698 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2701 const UINT32 len = Stream_Get_UINT32(s);
2702 if (len != cReaders)
2704 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEW");
2710 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2712 if (!rgReaderStates || !states)
2715 status = ERROR_INVALID_DATA;
2716 for (UINT32 index = 0; index < cReaders; index++)
2718 UINT32 ptr = UINT32_MAX;
2721 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2724 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2730 states[index] = ptr != 0;
2731 Stream_Read_UINT32(s, readerState->dwCurrentState);
2732 Stream_Read_UINT32(s, readerState->dwEventState);
2733 Stream_Read_UINT32(s, readerState->cbAtr);
2734 if (readerState->cbAtr > ARRAYSIZE(readerState->rgbAtr))
2736 WLog_Print(log, WLOG_ERROR,
2737 "SCARD_READERSTATEW[%" PRIu32
"]::cbAtr %" PRIu32
" exceeds %" PRIuz, index,
2738 readerState->cbAtr, (
size_t)ARRAYSIZE(readerState->rgbAtr));
2741 Stream_Read(s, readerState->rgbAtr, 36);
2744 for (UINT32 index = 0; index < cReaders; index++)
2752 status = smartcard_ndr_read_w(log, s, &readerState->szReader, NDR_PTR_FULL);
2753 if (status != SCARD_S_SUCCESS)
2757 *ppcReaders = rgReaderStates;
2759 return SCARD_S_SUCCESS;
2763 for (UINT32 index = 0; index < cReaders; index++)
2766 free(readerState->szReader);
2769 free(rgReaderStates);
2782 UINT32 pbContextNdrPtr = 0;
2785 wLog* log = scard_log();
2787 call->rgReaderStates =
nullptr;
2789 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2791 if (status != SCARD_S_SUCCESS)
2794 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2795 return STATUS_BUFFER_TOO_SMALL;
2797 Stream_Read_UINT32(s, call->dwTimeOut);
2798 const DWORD cReaders = Stream_Get_UINT32(s);
2799 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2800 return ERROR_INVALID_DATA;
2802 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2803 &(call->handles.hContext));
2804 if (status != SCARD_S_SUCCESS)
2809 status = smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, cReaders, &index);
2810 if (status != SCARD_S_SUCCESS)
2812 call->cReaders = cReaders;
2816 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2817 return SCARD_E_UNEXPECTED;
2820 smartcard_trace_get_status_change_a_call(log, call);
2821 return SCARD_S_SUCCESS;
2828 UINT32 pbContextNdrPtr = 0;
2831 wLog* log = scard_log();
2832 call->rgReaderStates =
nullptr;
2834 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2836 if (status != SCARD_S_SUCCESS)
2839 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2840 return STATUS_BUFFER_TOO_SMALL;
2842 Stream_Read_UINT32(s, call->dwTimeOut);
2843 const DWORD cReaders = Stream_Get_UINT32(s);
2844 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2845 return ERROR_INVALID_DATA;
2847 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2848 &(call->handles.hContext));
2849 if (status != SCARD_S_SUCCESS)
2854 status = smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, cReaders, &index);
2855 if (status != SCARD_S_SUCCESS)
2857 call->cReaders = cReaders;
2861 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2862 return SCARD_E_UNEXPECTED;
2865 smartcard_trace_get_status_change_w_call(log, call);
2866 return SCARD_S_SUCCESS;
2873 wLog* log = scard_log();
2876 DWORD cReaders = ret->cReaders;
2879 smartcard_trace_get_status_change_return(log, ret, unicode);
2880 if ((ret->ReturnCode != SCARD_S_SUCCESS) && (ret->ReturnCode != SCARD_E_TIMEOUT))
2882 if (cReaders == SCARD_AUTOALLOCATE)
2885 if (!Stream_EnsureRemainingCapacity(s, 4))
2886 return SCARD_E_NO_MEMORY;
2888 Stream_Write_UINT32(s, cReaders);
2889 if (!smartcard_ndr_pointer_write(s, &index, cReaders))
2890 return SCARD_E_NO_MEMORY;
2891 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cReaders, NDR_PTR_SIMPLE);
2892 if (status != SCARD_S_SUCCESS)
2894 return ret->ReturnCode;
2900 UINT32 pbContextNdrPtr = 0;
2902 wLog* log = scard_log();
2905 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2907 if (status != SCARD_S_SUCCESS)
2910 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2911 if (status != SCARD_S_SUCCESS)
2914 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2915 return STATUS_BUFFER_TOO_SMALL;
2917 Stream_Read_INT32(s, call->fpbAtrIsNULL);
2918 Stream_Read_UINT32(s, call->cbAtrLen);
2920 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2921 &(call->handles.hContext));
2922 if (status != SCARD_S_SUCCESS)
2925 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2926 if (status != SCARD_S_SUCCESS)
2935 wLog* log = scard_log();
2937 DWORD cbAtrLen = ret->cbAtrLen;
2940 smartcard_trace_state_return(log, ret);
2941 if (ret->ReturnCode != SCARD_S_SUCCESS)
2943 if (cbAtrLen == SCARD_AUTOALLOCATE)
2946 Stream_Write_UINT32(s, ret->dwState);
2947 Stream_Write_UINT32(s, ret->dwProtocol);
2948 Stream_Write_UINT32(s, cbAtrLen);
2949 if (!smartcard_ndr_pointer_write(s, &index, cbAtrLen))
2950 return SCARD_E_NO_MEMORY;
2951 status = smartcard_ndr_write(s, ret->rgAtr, cbAtrLen, 1, NDR_PTR_SIMPLE);
2952 if (status != SCARD_S_SUCCESS)
2954 return ret->ReturnCode;
2960 UINT32 pbContextNdrPtr = 0;
2963 wLog* log = scard_log();
2965 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2967 if (status != SCARD_S_SUCCESS)
2970 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2971 if (status != SCARD_S_SUCCESS)
2974 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2975 return STATUS_BUFFER_TOO_SMALL;
2977 Stream_Read_INT32(s, call->fmszReaderNamesIsNULL);
2978 Stream_Read_UINT32(s, call->cchReaderLen);
2979 Stream_Read_UINT32(s, call->cbAtrLen);
2981 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2982 &(call->handles.hContext));
2983 if (status != SCARD_S_SUCCESS)
2986 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2987 if (status != SCARD_S_SUCCESS)
2990 smartcard_trace_status_call(log, call, unicode);
2997 wLog* log = scard_log();
3000 smartcard_trace_status_call(log, call, unicode);
3002 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
3003 if (status != SCARD_S_SUCCESS)
3006 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
3007 if (status != SCARD_S_SUCCESS)
3010 if (!Stream_EnsureRemainingCapacity(s, 12))
3011 return SCARD_E_NO_MEMORY;
3013 Stream_Write_INT32(s, call->fmszReaderNamesIsNULL);
3014 Stream_Write_UINT32(s, call->cchReaderLen);
3015 Stream_Write_UINT32(s, call->cbAtrLen);
3017 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
3018 if (status != SCARD_S_SUCCESS)
3021 return smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
3027 wLog* log = scard_log();
3031 DWORD cBytes = ret->cBytes;
3033 smartcard_trace_status_return(log, ret, unicode);
3034 if (ret->ReturnCode != SCARD_S_SUCCESS)
3036 if (cBytes == SCARD_AUTOALLOCATE)
3039 if (!Stream_EnsureRemainingCapacity(s, 4))
3040 return SCARD_F_INTERNAL_ERROR;
3042 Stream_Write_UINT32(s, cBytes);
3043 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
3044 return SCARD_E_NO_MEMORY;
3046 if (!Stream_EnsureRemainingCapacity(s, 44))
3047 return SCARD_F_INTERNAL_ERROR;
3049 Stream_Write_UINT32(s, ret->dwState);
3050 Stream_Write_UINT32(s, ret->dwProtocol);
3051 Stream_Write(s, ret->pbAtr,
sizeof(ret->pbAtr));
3052 Stream_Write_UINT32(s, ret->cbAtrLen);
3053 status = smartcard_ndr_write(s, ret->mszReaderNames, cBytes, 1, NDR_PTR_SIMPLE);
3054 if (status != SCARD_S_SUCCESS)
3056 return ret->ReturnCode;
3062 wLog* log = scard_log();
3064 UINT32 mszNdrPtr = 0;
3066 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3067 return STATUS_BUFFER_TOO_SMALL;
3069 const UINT32 cBytes = Stream_Get_UINT32(s);
3071 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3072 return ERROR_INVALID_DATA;
3074 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 44))
3075 return STATUS_BUFFER_TOO_SMALL;
3077 Stream_Read_UINT32(s, ret->dwState);
3078 Stream_Read_UINT32(s, ret->dwProtocol);
3079 Stream_Read(s, ret->pbAtr,
sizeof(ret->pbAtr));
3080 Stream_Read_UINT32(s, ret->cbAtrLen);
3084 LONG status = smartcard_ndr_read(log, s, &ret->mszReaderNames, cBytes, 1, NDR_PTR_SIMPLE);
3085 if (status != SCARD_S_SUCCESS)
3087 ret->cBytes = cBytes;
3090 smartcard_trace_status_return(log, ret, unicode);
3091 return SCARD_S_SUCCESS;
3097 wLog* log = scard_log();
3099 UINT32 pbContextNdrPtr = 0;
3101 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3103 if (status != SCARD_S_SUCCESS)
3106 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3107 if (status != SCARD_S_SUCCESS)
3110 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3111 return STATUS_BUFFER_TOO_SMALL;
3113 Stream_Read_UINT32(s, call->dwAttrId);
3114 Stream_Read_INT32(s, call->fpbAttrIsNULL);
3115 Stream_Read_UINT32(s, call->cbAttrLen);
3117 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3118 &(call->handles.hContext));
3119 if (status != SCARD_S_SUCCESS)
3122 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3123 if (status != SCARD_S_SUCCESS)
3126 smartcard_trace_get_attrib_call(log, call);
3131 DWORD cbAttrCallLen)
3134 wLog* log = scard_log();
3136 DWORD cbAttrLen = 0;
3138 smartcard_trace_get_attrib_return(log, ret, dwAttrId);
3140 if (!Stream_EnsureRemainingCapacity(s, 4))
3141 return SCARD_F_INTERNAL_ERROR;
3143 cbAttrLen = ret->cbAttrLen;
3144 if (ret->ReturnCode != SCARD_S_SUCCESS)
3146 if (cbAttrLen == SCARD_AUTOALLOCATE)
3151 if (cbAttrCallLen < cbAttrLen)
3152 cbAttrLen = cbAttrCallLen;
3154 Stream_Write_UINT32(s, cbAttrLen);
3155 if (!smartcard_ndr_pointer_write(s, &index, cbAttrLen))
3156 return SCARD_E_NO_MEMORY;
3158 status = smartcard_ndr_write(s, ret->pbAttr, cbAttrLen, 1, NDR_PTR_SIMPLE);
3159 if (status != SCARD_S_SUCCESS)
3161 return ret->ReturnCode;
3167 wLog* log = scard_log();
3170 UINT32 pvInBufferNdrPtr = 0;
3171 UINT32 pbContextNdrPtr = 0;
3173 call->pvInBuffer =
nullptr;
3175 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3177 if (status != SCARD_S_SUCCESS)
3180 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3181 if (status != SCARD_S_SUCCESS)
3184 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 20))
3185 return STATUS_BUFFER_TOO_SMALL;
3187 Stream_Read_UINT32(s, call->dwControlCode);
3188 const UINT32 cbInBufferSize = Stream_Get_UINT32(s);
3189 if (!smartcard_ndr_pointer_read(log, s, &index,
3191 return ERROR_INVALID_DATA;
3192 Stream_Read_INT32(s, call->fpvOutBufferIsNULL);
3193 Stream_Read_UINT32(s, call->cbOutBufferSize);
3195 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3196 &(call->handles.hContext));
3197 if (status != SCARD_S_SUCCESS)
3200 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3201 if (status != SCARD_S_SUCCESS)
3204 if (pvInBufferNdrPtr)
3206 status = smartcard_ndr_read(log, s, &call->pvInBuffer, cbInBufferSize, 1, NDR_PTR_SIMPLE);
3207 if (status != SCARD_S_SUCCESS)
3209 call->cbInBufferSize = cbInBufferSize;
3212 smartcard_trace_control_call(log, call);
3213 return SCARD_S_SUCCESS;
3219 wLog* log = scard_log();
3222 DWORD cbDataLen = ret->cbOutBufferSize;
3225 smartcard_trace_control_return(log, ret);
3226 if (ret->ReturnCode != SCARD_S_SUCCESS)
3228 if (cbDataLen == SCARD_AUTOALLOCATE)
3231 if (!Stream_EnsureRemainingCapacity(s, 4))
3232 return SCARD_F_INTERNAL_ERROR;
3234 Stream_Write_UINT32(s, cbDataLen);
3235 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3236 return SCARD_E_NO_MEMORY;
3238 status = smartcard_ndr_write(s, ret->pvOutBuffer, cbDataLen, 1, NDR_PTR_SIMPLE);
3239 if (status != SCARD_S_SUCCESS)
3241 return ret->ReturnCode;
3247 BYTE* pbExtraBytes =
nullptr;
3248 UINT32 pbExtraBytesNdrPtr = 0;
3249 UINT32 pbSendBufferNdrPtr = 0;
3250 UINT32 pioRecvPciNdrPtr = 0;
3254 UINT32 pbContextNdrPtr = 0;
3257 wLog* log = scard_log();
3259 call->pioSendPci =
nullptr;
3260 call->pioRecvPci =
nullptr;
3261 call->pbSendBuffer =
nullptr;
3263 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3265 if (status != SCARD_S_SUCCESS)
3268 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3269 if (status != SCARD_S_SUCCESS)
3272 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 32))
3273 return STATUS_BUFFER_TOO_SMALL;
3275 Stream_Read_UINT32(s, ioSendPci.dwProtocol);
3276 Stream_Read_UINT32(s, ioSendPci.cbExtraBytes);
3277 if (!smartcard_ndr_pointer_read(log, s, &index,
3278 &pbExtraBytesNdrPtr))
3279 return ERROR_INVALID_DATA;
3281 const UINT32 cbSendLength = Stream_Get_UINT32(s);
3282 if (!smartcard_ndr_pointer_read(log, s, &index,
3283 &pbSendBufferNdrPtr))
3284 return ERROR_INVALID_DATA;
3286 if (!smartcard_ndr_pointer_read(log, s, &index,
3288 return ERROR_INVALID_DATA;
3290 Stream_Read_INT32(s, call->fpbRecvBufferIsNULL);
3291 Stream_Read_UINT32(s, call->cbRecvLength);
3293 if (ioSendPci.cbExtraBytes > 1024)
3295 WLog_Print(log, WLOG_WARN,
3296 "Transmit_Call ioSendPci.cbExtraBytes is out of bounds: %" PRIu32
" (max: 1024)",
3297 ioSendPci.cbExtraBytes);
3298 return STATUS_INVALID_PARAMETER;
3301 if (cbSendLength > 66560)
3303 WLog_Print(log, WLOG_WARN,
3304 "Transmit_Call cbSendLength is out of bounds: %" PRIu32
" (max: 66560)",
3305 ioSendPci.cbExtraBytes);
3306 return STATUS_INVALID_PARAMETER;
3309 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3310 &(call->handles.hContext));
3311 if (status != SCARD_S_SUCCESS)
3314 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3315 if (status != SCARD_S_SUCCESS)
3318 if (ioSendPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3322 "Transmit_Call ioSendPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3323 return STATUS_INVALID_PARAMETER;
3326 if (pbExtraBytesNdrPtr)
3329 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3330 return STATUS_BUFFER_TOO_SMALL;
3332 Stream_Read_UINT32(s, length);
3334 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioSendPci.cbExtraBytes))
3335 return STATUS_BUFFER_TOO_SMALL;
3337 ioSendPci.pbExtraBytes = Stream_Pointer(s);
3341 if (!call->pioSendPci)
3343 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3344 return STATUS_NO_MEMORY;
3347 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3348 call->pioSendPci->cbPciLength = (DWORD)(ioSendPci.cbExtraBytes +
sizeof(
SCARD_IO_REQUEST));
3350 Stream_Read(s, pbExtraBytes, ioSendPci.cbExtraBytes);
3351 if (smartcard_unpack_read_size_align(s, ioSendPci.cbExtraBytes, 4) < 0)
3352 return STATUS_INVALID_PARAMETER;
3358 if (!call->pioSendPci)
3360 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3361 return STATUS_NO_MEMORY;
3364 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3368 if (pbSendBufferNdrPtr)
3370 status = smartcard_ndr_read(log, s, &call->pbSendBuffer, cbSendLength, 1, NDR_PTR_SIMPLE);
3371 if (status != SCARD_S_SUCCESS)
3373 call->cbSendLength = cbSendLength;
3376 if (pioRecvPciNdrPtr)
3378 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3379 return STATUS_BUFFER_TOO_SMALL;
3381 Stream_Read_UINT32(s, ioRecvPci.dwProtocol);
3382 Stream_Read_UINT32(s, ioRecvPci.cbExtraBytes);
3383 if (!smartcard_ndr_pointer_read(log, s, &index,
3384 &pbExtraBytesNdrPtr))
3385 return ERROR_INVALID_DATA;
3387 if (ioRecvPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3391 "Transmit_Call ioRecvPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3392 return STATUS_INVALID_PARAMETER;
3395 if (pbExtraBytesNdrPtr)
3398 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3399 return STATUS_BUFFER_TOO_SMALL;
3401 Stream_Read_UINT32(s, length);
3403 if (ioRecvPci.cbExtraBytes > 1024)
3405 WLog_Print(log, WLOG_WARN,
3406 "Transmit_Call ioRecvPci.cbExtraBytes is out of bounds: %" PRIu32
3408 ioRecvPci.cbExtraBytes);
3409 return STATUS_INVALID_PARAMETER;
3412 if (length != ioRecvPci.cbExtraBytes)
3414 WLog_Print(log, WLOG_WARN,
3415 "Transmit_Call unexpected length: Actual: %" PRIu32
3416 ", Expected: %" PRIu32
" (ioRecvPci.cbExtraBytes)",
3417 length, ioRecvPci.cbExtraBytes);
3418 return STATUS_INVALID_PARAMETER;
3421 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioRecvPci.cbExtraBytes))
3422 return STATUS_BUFFER_TOO_SMALL;
3424 ioRecvPci.pbExtraBytes = Stream_Pointer(s);
3428 if (!call->pioRecvPci)
3430 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3431 return STATUS_NO_MEMORY;
3434 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3435 call->pioRecvPci->cbPciLength =
3438 Stream_Read(s, pbExtraBytes, ioRecvPci.cbExtraBytes);
3439 if (smartcard_unpack_read_size_align(s, ioRecvPci.cbExtraBytes, 4) < 0)
3440 return STATUS_INVALID_PARAMETER;
3446 if (!call->pioRecvPci)
3448 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3449 return STATUS_NO_MEMORY;
3452 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3457 smartcard_trace_transmit_call(log, call);
3458 return SCARD_S_SUCCESS;
3464 wLog* log = scard_log();
3469 UINT32 cbRecvLength = ret->cbRecvLength;
3470 UINT32 cbRecvPci = ret->pioRecvPci ? ret->pioRecvPci->cbPciLength : 0;
3472 smartcard_trace_transmit_return(log, ret);
3474 if (!ret->pbRecvBuffer)
3477 if (!smartcard_ndr_pointer_write(s, &index, cbRecvPci))
3478 return SCARD_E_NO_MEMORY;
3479 if (!Stream_EnsureRemainingCapacity(s, 4))
3480 return SCARD_E_NO_MEMORY;
3481 Stream_Write_UINT32(s, cbRecvLength);
3482 if (!smartcard_ndr_pointer_write(s, &index, cbRecvLength))
3483 return SCARD_E_NO_MEMORY;
3485 if (ret->pioRecvPci)
3487 UINT32 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
3490 if (!Stream_EnsureRemainingCapacity(s, cbExtraBytes + 16))
3492 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3493 return SCARD_F_INTERNAL_ERROR;
3496 Stream_Write_UINT32(s, ret->pioRecvPci->dwProtocol);
3497 Stream_Write_UINT32(s, cbExtraBytes);
3498 if (!smartcard_ndr_pointer_write(s, &index, cbExtraBytes))
3499 return SCARD_E_NO_MEMORY;
3500 error = smartcard_ndr_write(s, pbExtraBytes, cbExtraBytes, 1, NDR_PTR_SIMPLE);
3505 status = smartcard_ndr_write(s, ret->pbRecvBuffer, ret->cbRecvLength, 1, NDR_PTR_SIMPLE);
3506 if (status != SCARD_S_SUCCESS)
3508 return ret->ReturnCode;
3513 UINT32 rgReaderStatesNdrPtr = 0;
3514 UINT32 rgAtrMasksNdrPtr = 0;
3516 UINT32 pbContextNdrPtr = 0;
3519 wLog* log = scard_log();
3521 call->rgReaderStates =
nullptr;
3523 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3525 if (status != SCARD_S_SUCCESS)
3528 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3529 return STATUS_BUFFER_TOO_SMALL;
3531 Stream_Read_UINT32(s, call->cAtrs);
3532 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3533 return ERROR_INVALID_DATA;
3534 const DWORD cReaders = Stream_Get_UINT32(s);
3535 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3536 return ERROR_INVALID_DATA;
3538 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3539 &(call->handles.hContext));
3540 if (status != SCARD_S_SUCCESS)
3543 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3545 WLog_Print(log, WLOG_WARN,
3546 "LocateCardsByATRA_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3547 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3548 rgAtrMasksNdrPtr, call->cAtrs);
3549 return STATUS_INVALID_PARAMETER;
3552 if (rgAtrMasksNdrPtr)
3554 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3555 if (status != SCARD_S_SUCCESS)
3559 if (rgReaderStatesNdrPtr)
3561 status = smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, cReaders, &index);
3562 if (status != SCARD_S_SUCCESS)
3564 call->cReaders = cReaders;
3567 smartcard_trace_locate_cards_by_atr_a_call(log, call);
3568 return SCARD_S_SUCCESS;
3573 UINT32 sz1NdrPtr = 0;
3574 UINT32 sz2NdrPtr = 0;
3576 UINT32 pbContextNdrPtr = 0;
3579 wLog* log = scard_log();
3581 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3583 if (status != SCARD_S_SUCCESS)
3586 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3587 return ERROR_INVALID_DATA;
3588 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3589 return ERROR_INVALID_DATA;
3592 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3593 if (status != SCARD_S_SUCCESS)
3598 status = smartcard_ndr_read_a(log, s, &call->sz1, NDR_PTR_FULL);
3599 if (status != SCARD_S_SUCCESS)
3604 status = smartcard_ndr_read_a(log, s, &call->sz2, NDR_PTR_FULL);
3605 if (status != SCARD_S_SUCCESS)
3608 smartcard_trace_context_and_two_strings_a_call(log, call);
3609 return SCARD_S_SUCCESS;
3614 UINT32 sz1NdrPtr = 0;
3615 UINT32 sz2NdrPtr = 0;
3617 UINT32 pbContextNdrPtr = 0;
3620 wLog* log = scard_log();
3622 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3624 if (status != SCARD_S_SUCCESS)
3627 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3628 return ERROR_INVALID_DATA;
3629 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3630 return ERROR_INVALID_DATA;
3633 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3634 if (status != SCARD_S_SUCCESS)
3639 status = smartcard_ndr_read_w(log, s, &call->sz1, NDR_PTR_FULL);
3640 if (status != SCARD_S_SUCCESS)
3645 status = smartcard_ndr_read_w(log, s, &call->sz2, NDR_PTR_FULL);
3646 if (status != SCARD_S_SUCCESS)
3649 smartcard_trace_context_and_two_strings_w_call(log, call);
3650 return SCARD_S_SUCCESS;
3655 UINT32 sz1NdrPtr = 0;
3656 UINT32 sz2NdrPtr = 0;
3658 UINT32 pbContextNdrPtr = 0;
3661 wLog* log = scard_log();
3663 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3665 if (status != SCARD_S_SUCCESS)
3668 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3669 return STATUS_BUFFER_TOO_SMALL;
3671 const UINT32 cBytes = Stream_Get_UINT32(s);
3672 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3673 return ERROR_INVALID_DATA;
3675 const DWORD cReaders = Stream_Get_UINT32(s);
3676 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3677 return ERROR_INVALID_DATA;
3679 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3680 &(call->handles.hContext));
3681 if (status != SCARD_S_SUCCESS)
3686 status = smartcard_ndr_read_fixed_string_a(log, s, &call->mszCards, cBytes, NDR_PTR_SIMPLE);
3687 if (status != SCARD_S_SUCCESS)
3689 call->cBytes = cBytes;
3693 status = smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, cReaders, &index);
3694 if (status != SCARD_S_SUCCESS)
3696 call->cReaders = cReaders;
3698 smartcard_trace_locate_cards_a_call(log, call);
3699 return SCARD_S_SUCCESS;
3704 UINT32 sz1NdrPtr = 0;
3705 UINT32 sz2NdrPtr = 0;
3707 UINT32 pbContextNdrPtr = 0;
3710 wLog* log = scard_log();
3712 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3714 if (status != SCARD_S_SUCCESS)
3717 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3718 return STATUS_BUFFER_TOO_SMALL;
3720 const UINT32 cBytes = Stream_Get_UINT32(s);
3721 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3722 return ERROR_INVALID_DATA;
3724 const DWORD cReaders = Stream_Get_UINT32(s);
3725 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3726 return ERROR_INVALID_DATA;
3728 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3729 &(call->handles.hContext));
3730 if (status != SCARD_S_SUCCESS)
3735 status = smartcard_ndr_read_fixed_string_w(log, s, &call->mszCards, cBytes, NDR_PTR_SIMPLE);
3736 if (status != SCARD_S_SUCCESS)
3738 call->cBytes = cBytes;
3742 status = smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, cReaders, &index);
3743 if (status != SCARD_S_SUCCESS)
3745 call->cReaders = cReaders;
3747 smartcard_trace_locate_cards_w_call(log, call);
3748 return SCARD_S_SUCCESS;
3755 UINT32 pbContextNdrPtr = 0;
3758 wLog* log = scard_log();
3760 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3762 if (status != SCARD_S_SUCCESS)
3764 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3765 if (status != SCARD_S_SUCCESS)
3768 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3769 return STATUS_BUFFER_TOO_SMALL;
3770 Stream_Read_UINT32(s, call->dwAttrId);
3771 Stream_Read_UINT32(s, call->cbAttrLen);
3773 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
3774 return ERROR_INVALID_DATA;
3776 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3777 &(call->handles.hContext));
3778 if (status != SCARD_S_SUCCESS)
3781 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3782 if (status != SCARD_S_SUCCESS)
3788 status = smartcard_ndr_read_ex(log, s, &call->pbAttr, 0, 1, NDR_PTR_SIMPLE, &len);
3789 if (status != SCARD_S_SUCCESS)
3791 if (call->cbAttrLen > len)
3792 call->cbAttrLen = WINPR_ASSERTING_INT_CAST(DWORD, len);
3795 call->cbAttrLen = 0;
3796 smartcard_trace_set_attrib_call(log, call);
3797 return SCARD_S_SUCCESS;
3803 wLog* log = scard_log();
3806 smartcard_trace_set_attrib_call(log, call);
3808 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
3809 if (status != SCARD_S_SUCCESS)
3812 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
3813 if (status != SCARD_S_SUCCESS)
3816 if (!Stream_EnsureRemainingCapacity(s, 8))
3817 return SCARD_E_NO_MEMORY;
3819 Stream_Write_UINT32(s, call->dwAttrId);
3820 Stream_Write_UINT32(s, call->cbAttrLen);
3822 if (!smartcard_ndr_pointer_write(s, &index, call->cbAttrLen))
3823 return SCARD_E_NO_MEMORY;
3825 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
3826 if (status != SCARD_S_SUCCESS)
3829 status = smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
3830 if (status != SCARD_S_SUCCESS)
3833 status = smartcard_ndr_write(s, call->pbAttr, call->cbAttrLen, 1, NDR_PTR_SIMPLE);
3834 if (status != SCARD_S_SUCCESS)
3837 return SCARD_S_SUCCESS;
3842 UINT32 rgReaderStatesNdrPtr = 0;
3843 UINT32 rgAtrMasksNdrPtr = 0;
3845 UINT32 pbContextNdrPtr = 0;
3848 wLog* log = scard_log();
3850 call->rgReaderStates =
nullptr;
3852 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3854 if (status != SCARD_S_SUCCESS)
3857 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3858 return STATUS_BUFFER_TOO_SMALL;
3860 Stream_Read_UINT32(s, call->cAtrs);
3861 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3862 return ERROR_INVALID_DATA;
3864 const DWORD cReaders = Stream_Get_UINT32(s);
3865 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3866 return ERROR_INVALID_DATA;
3868 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3869 &(call->handles.hContext));
3870 if (status != SCARD_S_SUCCESS)
3873 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3875 WLog_Print(log, WLOG_WARN,
3876 "LocateCardsByATRW_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3877 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3878 rgAtrMasksNdrPtr, call->cAtrs);
3879 return STATUS_INVALID_PARAMETER;
3882 if (rgAtrMasksNdrPtr)
3884 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3885 if (status != SCARD_S_SUCCESS)
3889 if (rgReaderStatesNdrPtr)
3891 status = smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, cReaders, &index);
3892 if (status != SCARD_S_SUCCESS)
3894 call->cReaders = cReaders;
3897 smartcard_trace_locate_cards_by_atr_w_call(log, call);
3898 return SCARD_S_SUCCESS;
3903 UINT32 mszNdrPtr = 0;
3904 UINT32 contextNdrPtr = 0;
3906 UINT32 pbContextNdrPtr = 0;
3909 wLog* log = scard_log();
3911 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3912 return ERROR_INVALID_DATA;
3914 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3915 &index, &pbContextNdrPtr);
3916 if (status != SCARD_S_SUCCESS)
3919 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3920 return ERROR_INVALID_DATA;
3922 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3923 return STATUS_BUFFER_TOO_SMALL;
3924 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3925 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
3926 Stream_Read_UINT32(s, call->Common.cbDataLen);
3928 call->szLookupName =
nullptr;
3931 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
3932 if (status != SCARD_S_SUCCESS)
3936 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3937 &call->Common.handles.hContext);
3938 if (status != SCARD_S_SUCCESS)
3943 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3944 if (status != SCARD_S_SUCCESS)
3947 smartcard_trace_read_cache_a_call(log, call);
3948 return SCARD_S_SUCCESS;
3953 UINT32 mszNdrPtr = 0;
3954 UINT32 contextNdrPtr = 0;
3956 UINT32 pbContextNdrPtr = 0;
3959 wLog* log = scard_log();
3961 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3962 return ERROR_INVALID_DATA;
3964 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3965 &index, &pbContextNdrPtr);
3966 if (status != SCARD_S_SUCCESS)
3969 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3970 return ERROR_INVALID_DATA;
3972 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3973 return STATUS_BUFFER_TOO_SMALL;
3974 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3975 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
3976 Stream_Read_UINT32(s, call->Common.cbDataLen);
3978 call->szLookupName =
nullptr;
3981 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
3982 if (status != SCARD_S_SUCCESS)
3986 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3987 &call->Common.handles.hContext);
3988 if (status != SCARD_S_SUCCESS)
3993 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3994 if (status != SCARD_S_SUCCESS)
3997 smartcard_trace_read_cache_w_call(log, call);
3998 return SCARD_S_SUCCESS;
4003 UINT32 mszNdrPtr = 0;
4004 UINT32 contextNdrPtr = 0;
4005 UINT32 pbDataNdrPtr = 0;
4007 UINT32 pbContextNdrPtr = 0;
4010 wLog* log = scard_log();
4012 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
4013 return ERROR_INVALID_DATA;
4015 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
4016 &index, &pbContextNdrPtr);
4017 if (status != SCARD_S_SUCCESS)
4020 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
4021 return ERROR_INVALID_DATA;
4023 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
4024 return STATUS_BUFFER_TOO_SMALL;
4026 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
4027 const UINT32 cbDataLen = Stream_Get_UINT32(s);
4029 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
4030 return ERROR_INVALID_DATA;
4032 call->szLookupName =
nullptr;
4035 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
4036 if (status != SCARD_S_SUCCESS)
4040 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4041 &call->Common.handles.hContext);
4042 if (status != SCARD_S_SUCCESS)
4045 call->Common.CardIdentifier =
nullptr;
4048 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
4049 if (status != SCARD_S_SUCCESS)
4053 call->Common.pbData =
nullptr;
4056 status = smartcard_ndr_read(log, s, &call->Common.pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
4057 if (status != SCARD_S_SUCCESS)
4059 call->Common.cbDataLen = cbDataLen;
4061 smartcard_trace_write_cache_a_call(log, call);
4062 return SCARD_S_SUCCESS;
4067 UINT32 mszNdrPtr = 0;
4068 UINT32 contextNdrPtr = 0;
4069 UINT32 pbDataNdrPtr = 0;
4071 UINT32 pbContextNdrPtr = 0;
4074 wLog* log = scard_log();
4076 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
4077 return ERROR_INVALID_DATA;
4079 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
4080 &index, &pbContextNdrPtr);
4081 if (status != SCARD_S_SUCCESS)
4084 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
4085 return ERROR_INVALID_DATA;
4087 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
4088 return STATUS_BUFFER_TOO_SMALL;
4089 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
4090 const UINT32 cbDataLen = Stream_Get_UINT32(s);
4092 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
4093 return ERROR_INVALID_DATA;
4095 call->szLookupName =
nullptr;
4098 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
4099 if (status != SCARD_S_SUCCESS)
4103 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4104 &call->Common.handles.hContext);
4105 if (status != SCARD_S_SUCCESS)
4108 call->Common.CardIdentifier =
nullptr;
4111 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
4112 if (status != SCARD_S_SUCCESS)
4116 call->Common.pbData =
nullptr;
4119 status = smartcard_ndr_read(log, s, &call->Common.pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
4120 if (status != SCARD_S_SUCCESS)
4122 call->Common.cbDataLen = cbDataLen;
4124 smartcard_trace_write_cache_w_call(log, call);
4131 wLog* log = scard_log();
4134 UINT32 pbContextNdrPtr = 0;
4136 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
4138 if (status != SCARD_S_SUCCESS)
4141 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
4142 if (status != SCARD_S_SUCCESS)
4145 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4146 &(call->handles.hContext));
4147 if (status != SCARD_S_SUCCESS)
4149 WLog_Print(log, WLOG_ERROR,
4150 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
4155 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
4156 if (status != SCARD_S_SUCCESS)
4157 WLog_Print(log, WLOG_ERROR,
4158 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
4160 smartcard_trace_get_transmit_count_call(log, call);
4167 wLog* log = scard_log();
4168 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
4169 &call->szReaderName);
4175 wLog* log = scard_log();
4176 return smartcard_unpack_common_context_and_string_a(log, s, &call->handles.hContext, &call->sz);
4182 wLog* log = scard_log();
4183 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext, &call->sz);
4189 wLog* log = scard_log();
4190 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
4191 &call->szReaderName);
4197 wLog* log = scard_log();
4198 smartcard_trace_device_type_id_return(log, ret);
4200 if (!Stream_EnsureRemainingCapacity(s, 4))
4202 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4203 return SCARD_F_INTERNAL_ERROR;
4206 Stream_Write_UINT32(s, ret->dwDeviceId);
4208 return ret->ReturnCode;
4214 wLog* log = scard_log();
4217 DWORD cbDataLen = ret->cReaders;
4220 smartcard_trace_locate_cards_return(log, ret);
4221 if (ret->ReturnCode != SCARD_S_SUCCESS)
4223 if (cbDataLen == SCARD_AUTOALLOCATE)
4226 if (!Stream_EnsureRemainingCapacity(s, 4))
4228 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4229 return SCARD_F_INTERNAL_ERROR;
4232 Stream_Write_UINT32(s, cbDataLen);
4233 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
4234 return SCARD_E_NO_MEMORY;
4236 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cbDataLen, NDR_PTR_SIMPLE);
4237 if (status != SCARD_S_SUCCESS)
4239 return ret->ReturnCode;
4245 wLog* log = scard_log();
4249 DWORD cbDataLen = ret->cbDataLen;
4250 smartcard_trace_get_reader_icon_return(log, ret);
4251 if (ret->ReturnCode != SCARD_S_SUCCESS)
4253 if (cbDataLen == SCARD_AUTOALLOCATE)
4256 if (!Stream_EnsureRemainingCapacity(s, 4))
4258 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4259 return SCARD_F_INTERNAL_ERROR;
4262 Stream_Write_UINT32(s, cbDataLen);
4263 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
4264 return SCARD_E_NO_MEMORY;
4266 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
4267 if (status != SCARD_S_SUCCESS)
4269 return ret->ReturnCode;
4275 wLog* log = scard_log();
4277 smartcard_trace_get_transmit_count_return(log, ret);
4279 if (!Stream_EnsureRemainingCapacity(s, 4))
4281 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4282 return SCARD_F_INTERNAL_ERROR;
4285 Stream_Write_UINT32(s, ret->cTransmitCount);
4287 return ret->ReturnCode;
4293 wLog* log = scard_log();
4297 DWORD cbDataLen = ret->cbDataLen;
4298 smartcard_trace_read_cache_return(log, ret);
4299 if (ret->ReturnCode != SCARD_S_SUCCESS)
4302 if (cbDataLen == SCARD_AUTOALLOCATE)
4305 if (!Stream_EnsureRemainingCapacity(s, 4))
4307 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4308 return SCARD_F_INTERNAL_ERROR;
4311 Stream_Write_UINT32(s, cbDataLen);
4312 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
4313 return SCARD_E_NO_MEMORY;
4315 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
4316 if (status != SCARD_S_SUCCESS)
4318 return ret->ReturnCode;
4324 wLog* log = scard_log();
4327 smartcard_trace_context_call(log, call, name);
4329 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4330 if (status != SCARD_S_SUCCESS)
4333 return smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4339 wLog* log = scard_log();
4342 smartcard_trace_list_readers_call(log, call, unicode);
4344 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4345 if (status != SCARD_S_SUCCESS)
4348 if (!Stream_EnsureRemainingCapacity(s, 4))
4349 return SCARD_E_NO_MEMORY;
4351 Stream_Write_UINT32(s, call->cBytes);
4352 if (!smartcard_ndr_pointer_write(s, &index, call->cBytes))
4353 return SCARD_E_NO_MEMORY;
4355 if (!Stream_EnsureRemainingCapacity(s, 8))
4356 return SCARD_E_NO_MEMORY;
4358 Stream_Write_INT32(s, call->fmszReadersIsNULL);
4359 Stream_Write_UINT32(s, call->cchReaders);
4361 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4362 if (status != SCARD_S_SUCCESS)
4365 if (call->cBytes > 0)
4367 status = smartcard_ndr_write(s, call->mszGroups, call->cBytes, 1, NDR_PTR_SIMPLE);
4368 if (status != SCARD_S_SUCCESS)
4372 return SCARD_S_SUCCESS;
4376 UINT32 cReaders, UINT32* ptrIndex)
4378 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
4380 if (!Stream_EnsureRemainingCapacity(s, 4))
4381 return SCARD_E_NO_MEMORY;
4383 Stream_Write_UINT32(s, cReaders);
4385 for (UINT32 i = 0; i < cReaders; i++)
4389 if (!Stream_EnsureRemainingCapacity(s, 52))
4390 return SCARD_E_NO_MEMORY;
4392 const DWORD nameLen = state->szReader ? (DWORD)(strlen(state->szReader) + 1) : 0;
4393 if (!smartcard_ndr_pointer_write(s, ptrIndex, nameLen))
4394 return SCARD_E_NO_MEMORY;
4396 Stream_Write_UINT32(s, state->dwCurrentState);
4397 Stream_Write_UINT32(s, state->dwEventState);
4398 Stream_Write_UINT32(s, state->cbAtr);
4399 Stream_Write(s, state->rgbAtr, 36);
4402 for (UINT32 i = 0; i < cReaders; i++)
4406 if (state->szReader)
4408 const UINT32 nameLen = (UINT32)(strlen(state->szReader) + 1);
4409 LONG status = smartcard_ndr_write_a(s, state->szReader, nameLen, NDR_PTR_FULL);
4410 if (status != SCARD_S_SUCCESS)
4415 return SCARD_S_SUCCESS;
4419 UINT32 cReaders, UINT32* ptrIndex)
4421 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
4423 if (!Stream_EnsureRemainingCapacity(s, 4))
4424 return SCARD_E_NO_MEMORY;
4426 Stream_Write_UINT32(s, cReaders);
4428 for (UINT32 i = 0; i < cReaders; i++)
4432 if (!Stream_EnsureRemainingCapacity(s, 52))
4433 return SCARD_E_NO_MEMORY;
4435 const DWORD nameLen = state->szReader ? (DWORD)(_wcslen(state->szReader) + 1) : 0;
4436 if (!smartcard_ndr_pointer_write(s, ptrIndex, nameLen))
4437 return SCARD_E_NO_MEMORY;
4439 Stream_Write_UINT32(s, state->dwCurrentState);
4440 Stream_Write_UINT32(s, state->dwEventState);
4441 Stream_Write_UINT32(s, state->cbAtr);
4442 Stream_Write(s, state->rgbAtr, 36);
4445 for (UINT32 i = 0; i < cReaders; i++)
4449 if (state->szReader)
4451 const UINT32 nameLen = (UINT32)(_wcslen(state->szReader) + 1);
4452 LONG status = smartcard_ndr_write_w(s, state->szReader, nameLen, NDR_PTR_FULL);
4453 if (status != SCARD_S_SUCCESS)
4458 return SCARD_S_SUCCESS;
4464 wLog* log = scard_log();
4467 smartcard_trace_get_status_change_a_call(log, call);
4469 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4470 if (status != SCARD_S_SUCCESS)
4473 if (!Stream_EnsureRemainingCapacity(s, 8))
4474 return SCARD_E_NO_MEMORY;
4476 Stream_Write_UINT32(s, call->dwTimeOut);
4477 Stream_Write_UINT32(s, call->cReaders);
4479 if (!smartcard_ndr_pointer_write(s, &index, call->cReaders))
4480 return SCARD_E_NO_MEMORY;
4482 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4483 if (status != SCARD_S_SUCCESS)
4486 if (call->cReaders > 0)
4488 status = smartcard_pack_reader_state_a(s, call->rgReaderStates, call->cReaders, &index);
4489 if (status != SCARD_S_SUCCESS)
4493 return SCARD_S_SUCCESS;
4499 wLog* log = scard_log();
4502 smartcard_trace_get_status_change_w_call(log, call);
4504 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4505 if (status != SCARD_S_SUCCESS)
4508 if (!Stream_EnsureRemainingCapacity(s, 8))
4509 return SCARD_E_NO_MEMORY;
4511 Stream_Write_UINT32(s, call->dwTimeOut);
4512 Stream_Write_UINT32(s, call->cReaders);
4514 if (!smartcard_ndr_pointer_write(s, &index, call->cReaders))
4515 return SCARD_E_NO_MEMORY;
4517 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4518 if (status != SCARD_S_SUCCESS)
4521 if (call->cReaders > 0)
4523 status = smartcard_pack_reader_state_w(s, call->rgReaderStates, call->cReaders, &index);
4524 if (status != SCARD_S_SUCCESS)
4528 return SCARD_S_SUCCESS;
4534 wLog* log = scard_log();
4537 smartcard_trace_connect_a_call(log, call);
4539 const DWORD readerLen = call->szReader ? (DWORD)(strlen(call->szReader) + 1) : 0;
4540 if (!smartcard_ndr_pointer_write(s, &index, readerLen))
4541 return SCARD_E_NO_MEMORY;
4544 smartcard_pack_redir_scard_context(log, s, &call->Common.handles.hContext, &index);
4545 if (status != SCARD_S_SUCCESS)
4548 if (!Stream_EnsureRemainingCapacity(s, 8))
4549 return SCARD_E_NO_MEMORY;
4551 Stream_Write_UINT32(s, call->Common.dwShareMode);
4552 Stream_Write_UINT32(s, call->Common.dwPreferredProtocols);
4556 status = smartcard_ndr_write_a(s, call->szReader, readerLen, NDR_PTR_FULL);
4557 if (status != SCARD_S_SUCCESS)
4561 return smartcard_pack_redir_scard_context_ref(log, s, &call->Common.handles.hContext);
4567 wLog* log = scard_log();
4570 smartcard_trace_connect_w_call(log, call);
4572 const DWORD readerLen = call->szReader ? (DWORD)(_wcslen(call->szReader) + 1) : 0;
4573 if (!smartcard_ndr_pointer_write(s, &index, readerLen))
4574 return SCARD_E_NO_MEMORY;
4577 smartcard_pack_redir_scard_context(log, s, &call->Common.handles.hContext, &index);
4578 if (status != SCARD_S_SUCCESS)
4581 if (!Stream_EnsureRemainingCapacity(s, 8))
4582 return SCARD_E_NO_MEMORY;
4584 Stream_Write_UINT32(s, call->Common.dwShareMode);
4585 Stream_Write_UINT32(s, call->Common.dwPreferredProtocols);
4589 status = smartcard_ndr_write_w(s, call->szReader, readerLen, NDR_PTR_FULL);
4590 if (status != SCARD_S_SUCCESS)
4594 return smartcard_pack_redir_scard_context_ref(log, s, &call->Common.handles.hContext);
4600 wLog* log = scard_log();
4603 smartcard_trace_control_call(log, call);
4605 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4606 if (status != SCARD_S_SUCCESS)
4609 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
4610 if (status != SCARD_S_SUCCESS)
4613 if (!Stream_EnsureRemainingCapacity(s, 8))
4614 return SCARD_E_NO_MEMORY;
4616 Stream_Write_UINT32(s, call->dwControlCode);
4617 Stream_Write_UINT32(s, call->cbInBufferSize);
4618 if (!smartcard_ndr_pointer_write(s, &index, call->cbInBufferSize))
4619 return SCARD_E_NO_MEMORY;
4621 Stream_Write_INT32(s, call->fpvOutBufferIsNULL);
4622 Stream_Write_UINT32(s, call->cbOutBufferSize);
4624 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4625 if (status != SCARD_S_SUCCESS)
4628 status = smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
4629 if (status != SCARD_S_SUCCESS)
4632 if (call->cbInBufferSize)
4634 status = smartcard_ndr_write(s, call->pvInBuffer, call->cbInBufferSize, 1, NDR_PTR_SIMPLE);
4635 if (status != SCARD_S_SUCCESS)
4646 wLog* log = scard_log();
4649 smartcard_trace_hcard_and_disposition_call(log, call, name);
4651 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4652 if (status != SCARD_S_SUCCESS)
4655 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
4656 if (status != SCARD_S_SUCCESS)
4659 if (!Stream_EnsureRemainingCapacity(s, 4))
4660 return SCARD_E_NO_MEMORY;
4662 Stream_Write_UINT32(s, call->dwDisposition);
4664 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4665 if (status != SCARD_S_SUCCESS)
4668 return smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
4674 wLog* log = scard_log();
4677 smartcard_trace_transmit_call(log, call);
4679 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4680 if (status != SCARD_S_SUCCESS)
4683 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
4684 if (status != SCARD_S_SUCCESS)
4687 UINT32 cbExtraBytes = 0;
4688 const BYTE* pbExtraBytes =
nullptr;
4689 if (call->pioSendPci)
4691 cbExtraBytes = (UINT32)(call->pioSendPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
4692 if (cbExtraBytes > 0)
4696 if (!Stream_EnsureRemainingCapacity(s, 32))
4697 return SCARD_E_NO_MEMORY;
4699 Stream_Write_UINT32(s, call->pioSendPci ? call->pioSendPci->dwProtocol : 0);
4700 Stream_Write_UINT32(s, cbExtraBytes);
4701 if (!smartcard_ndr_pointer_write(s, &index, cbExtraBytes))
4702 return SCARD_E_NO_MEMORY;
4704 Stream_Write_UINT32(s, call->cbSendLength);
4705 if (!smartcard_ndr_pointer_write(s, &index, call->cbSendLength))
4706 return SCARD_E_NO_MEMORY;
4708 const UINT32 recvPciLen = call->pioRecvPci ? (UINT32)call->pioRecvPci->cbPciLength : 0;
4709 if (!smartcard_ndr_pointer_write(s, &index, recvPciLen))
4710 return SCARD_E_NO_MEMORY;
4712 Stream_Write_INT32(s, call->fpbRecvBufferIsNULL);
4713 Stream_Write_UINT32(s, call->cbRecvLength);
4715 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4716 if (status != SCARD_S_SUCCESS)
4719 status = smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
4720 if (status != SCARD_S_SUCCESS)
4723 if (cbExtraBytes > 0)
4725 status = smartcard_ndr_write(s, pbExtraBytes, cbExtraBytes, 1, NDR_PTR_SIMPLE);
4726 if (status != SCARD_S_SUCCESS)
4730 if (call->cbSendLength > 0)
4732 status = smartcard_ndr_write(s, call->pbSendBuffer, call->cbSendLength, 1, NDR_PTR_SIMPLE);
4733 if (status != SCARD_S_SUCCESS)
4737 if (call->pioRecvPci && recvPciLen > 0)
4739 UINT32 cbRecvExtra = (UINT32)(call->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
4740 const BYTE* pbRecvExtra = &((
const BYTE*)call->pioRecvPci)[
sizeof(
SCARD_IO_REQUEST)];
4742 if (!Stream_EnsureRemainingCapacity(s, 12))
4743 return SCARD_E_NO_MEMORY;
4745 Stream_Write_UINT32(s, call->pioRecvPci->dwProtocol);
4746 Stream_Write_UINT32(s, cbRecvExtra);
4747 if (!smartcard_ndr_pointer_write(s, &index, cbRecvExtra))
4748 return SCARD_E_NO_MEMORY;
4750 if (cbRecvExtra > 0)
4752 status = smartcard_ndr_write(s, pbRecvExtra, cbRecvExtra, 1, NDR_PTR_SIMPLE);
4753 if (status != SCARD_S_SUCCESS)
4758 return SCARD_S_SUCCESS;
4764 wLog* log = scard_log();
4767 smartcard_trace_get_attrib_call(log, call);
4769 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4770 if (status != SCARD_S_SUCCESS)
4773 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
4774 if (status != SCARD_S_SUCCESS)
4777 if (!Stream_EnsureRemainingCapacity(s, 12))
4778 return STATUS_NO_MEMORY;
4780 Stream_Write_UINT32(s, call->dwAttrId);
4781 Stream_Write_INT32(s, call->fpbAttrIsNULL);
4782 Stream_Write_UINT32(s, call->cbAttrLen);
4784 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4785 if (status != SCARD_S_SUCCESS)
4788 return smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
4794 wLog* log = scard_log();
4796 UINT32 mszNdrPtr = 0;
4798 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
4799 return STATUS_BUFFER_TOO_SMALL;
4801 const UINT32 cBytes = Stream_Get_UINT32(s);
4803 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
4804 return ERROR_INVALID_DATA;
4808 LONG status = smartcard_ndr_read(log, s, &ret->msz, cBytes, 1, NDR_PTR_SIMPLE);
4809 if (status != SCARD_S_SUCCESS)
4811 ret->cBytes = cBytes;
4814 smartcard_trace_list_readers_return(log, ret, unicode);
4815 return SCARD_S_SUCCESS;
4822 wLog* log = scard_log();
4826 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
4827 return STATUS_BUFFER_TOO_SMALL;
4829 Stream_Read_UINT32(s, ret->cReaders);
4831 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
4832 return ERROR_INVALID_DATA;
4834 if (ndrPtr && ret->cReaders > 0)
4837 smartcard_ndr_read_state(log, s, &ret->rgReaderStates, ret->cReaders, NDR_PTR_SIMPLE);
4838 if (status != SCARD_S_SUCCESS)
4842 ret->rgReaderStates =
nullptr;
4844 smartcard_trace_get_status_change_return(log, ret, unicode);
4845 return SCARD_S_SUCCESS;
4851 wLog* log = scard_log();
4853 UINT32 pbContextNdrPtr = 0;
4856 smartcard_unpack_redir_scard_context(log, s, &ret->hContext, &index, &pbContextNdrPtr);
4857 if (status != SCARD_S_SUCCESS)
4860 status = smartcard_unpack_redir_scard_handle(log, s, &ret->hCard, &index);
4861 if (status != SCARD_S_SUCCESS)
4864 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
4865 return STATUS_BUFFER_TOO_SMALL;
4867 Stream_Read_UINT32(s, ret->dwActiveProtocol);
4869 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &ret->hContext);
4870 if (status != SCARD_S_SUCCESS)
4873 status = smartcard_unpack_redir_scard_handle_ref(log, s, &ret->hCard);
4874 if (status != SCARD_S_SUCCESS)
4877 smartcard_trace_connect_return(log, ret);
4878 return SCARD_S_SUCCESS;
4884 wLog* log = scard_log();
4886 UINT32 pvOutBufferNdrPtr = 0;
4888 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
4889 return STATUS_BUFFER_TOO_SMALL;
4891 const UINT32 cbOutBufferSize = Stream_Get_UINT32(s);
4893 if (!smartcard_ndr_pointer_read(log, s, &index, &pvOutBufferNdrPtr))
4894 return ERROR_INVALID_DATA;
4896 if (pvOutBufferNdrPtr && (cbOutBufferSize > 0))
4899 smartcard_ndr_read(log, s, &ret->pvOutBuffer, cbOutBufferSize, 1, NDR_PTR_SIMPLE);
4900 if (status != SCARD_S_SUCCESS)
4902 ret->cbOutBufferSize = cbOutBufferSize;
4904 smartcard_trace_control_return(log, ret);
4905 return SCARD_S_SUCCESS;
4911 wLog* log = scard_log();
4913 UINT32 recvPciNdrPtr = 0;
4914 UINT32 recvBufferNdrPtr = 0;
4916 if (!smartcard_ndr_pointer_read(log, s, &index, &recvPciNdrPtr))
4917 return ERROR_INVALID_DATA;
4919 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
4920 return STATUS_BUFFER_TOO_SMALL;
4922 const UINT32 cbRecvLength = Stream_Get_UINT32(s);
4924 if (!smartcard_ndr_pointer_read(log, s, &index, &recvBufferNdrPtr))
4925 return ERROR_INVALID_DATA;
4929 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
4930 return STATUS_BUFFER_TOO_SMALL;
4932 UINT32 dwProtocol = 0;
4933 UINT32 cbExtraBytes = 0;
4934 Stream_Read_UINT32(s, dwProtocol);
4935 Stream_Read_UINT32(s, cbExtraBytes);
4937 UINT32 pbExtraBytesNdrPtr = 0;
4938 if (!smartcard_ndr_pointer_read(log, s, &index, &pbExtraBytesNdrPtr))
4939 return ERROR_INVALID_DATA;
4941 if (pbExtraBytesNdrPtr)
4943 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
4944 return STATUS_BUFFER_TOO_SMALL;
4947 Stream_Read_UINT32(s, length);
4948 if (length != cbExtraBytes)
4950 WLog_Print(log, WLOG_WARN,
4951 "Transmit_Return unexpected length: Actual: %" PRIu32
4952 ", Expected: %" PRIu32
" (pioRecvPci.cbExtraBytes)",
4953 length, cbExtraBytes);
4954 return STATUS_INVALID_PARAMETER;
4957 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, cbExtraBytes))
4958 return STATUS_BUFFER_TOO_SMALL;
4961 if (!ret->pioRecvPci)
4962 return SCARD_E_NO_MEMORY;
4964 ret->pioRecvPci->dwProtocol = dwProtocol;
4965 ret->pioRecvPci->cbPciLength = (DWORD)(
sizeof(
SCARD_IO_REQUEST) + cbExtraBytes);
4968 Stream_Read(s, pbExtraBytes, length);
4969 if (smartcard_unpack_read_size_align(s, cbExtraBytes, 4) < 0)
4970 return STATUS_INVALID_PARAMETER;
4975 if (!ret->pioRecvPci)
4976 return SCARD_E_NO_MEMORY;
4978 ret->pioRecvPci->dwProtocol = dwProtocol;
4983 if (recvBufferNdrPtr && (cbRecvLength > 0))
4986 smartcard_ndr_read(log, s, &ret->pbRecvBuffer, cbRecvLength, 1, NDR_PTR_SIMPLE);
4987 if (status != SCARD_S_SUCCESS)
4989 ret->cbRecvLength = cbRecvLength;
4992 smartcard_trace_transmit_return(log, ret);
4993 return SCARD_S_SUCCESS;
4999 wLog* log = scard_log();
5001 UINT32 pbAttrPtr = 0;
5003 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
5004 return STATUS_BUFFER_TOO_SMALL;
5006 const UINT32 cbAttrLen = Stream_Get_UINT32(s);
5008 if (!smartcard_ndr_pointer_read(log, s, &index, &pbAttrPtr))
5009 return ERROR_INVALID_DATA;
5011 LONG status = smartcard_ndr_read(log, s, &ret->pbAttr, cbAttrLen, 1, NDR_PTR_SIMPLE);
5012 if (status != SCARD_S_SUCCESS)
5014 ret->cbAttrLen = cbAttrLen;
5016 smartcard_trace_get_attrib_return(log, ret, 0);
5017 return SCARD_S_SUCCESS;