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__, \
53WINPR_ATTR_NODISCARD
static LONG
55 UINT32* index, UINT32* ppbContextNdrPtr,
const char* file,
56 const char* function,
size_t line);
57WINPR_ATTR_NODISCARD
static LONG
60WINPR_ATTR_NODISCARD
static LONG
62 UINT32* index,
const char* file,
const char* function,
64WINPR_ATTR_NODISCARD
static LONG smartcard_pack_redir_scard_handle(wLog* log,
wStream* s,
67WINPR_ATTR_NODISCARD
static LONG
68smartcard_unpack_redir_scard_context_ref(wLog* log,
wStream* s, UINT32 pbContextNdrPtr,
70WINPR_ATTR_NODISCARD
static LONG
73WINPR_ATTR_NODISCARD
static LONG smartcard_unpack_redir_scard_handle_ref(wLog* log,
wStream* s,
75WINPR_ATTR_NODISCARD
static LONG
87#define smartcard_ndr_pointer_read(log, s, index, ptr) \
88 smartcard_ndr_pointer_read_((log), (s), (index), (ptr), __FILE__, __func__, __LINE__)
89static BOOL smartcard_ndr_pointer_read_(wLog* log,
wStream* s, UINT32* index, UINT32* ptr,
90 const char* file,
const char* fkt,
size_t line)
92 const UINT32 expect = 0x20000 + (*index) * 4;
97 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
100 Stream_Read_UINT32(s, ndrPtr);
103 if (expect != ndrPtr)
106 if (ptr && (ndrPtr == 0))
108 WLog_Print(log, WLOG_WARN,
109 "[%s:%" PRIuz
"] Read context pointer 0x%08" PRIx32
", expected 0x%08" PRIx32,
110 fkt, line, ndrPtr, expect);
114 (*index) = (*index) + 1;
118WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_read_ex(wLog* log,
wStream* s, BYTE** data,
119 size_t min,
size_t elementSize,
120 const ndr_ptr_t type,
size_t* plen)
144 return STATUS_INVALID_PARAMETER;
147 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, required))
148 return STATUS_BUFFER_TOO_SMALL;
153 Stream_Read_UINT32(s, len);
154 Stream_Read_UINT32(s, offset);
155 Stream_Read_UINT32(s, len2);
156 if (len != offset + len2)
158 WLog_Print(log, WLOG_ERROR,
159 "Invalid data when reading full NDR pointer: total=%" PRIuz
160 ", offset=%" PRIuz
", remaining=%" PRIuz,
162 return STATUS_BUFFER_TOO_SMALL;
166 Stream_Read_UINT32(s, len);
168 if ((len != min) && (min > 0))
170 WLog_Print(log, WLOG_ERROR,
171 "Invalid data when reading simple NDR pointer: total=%" PRIuz
172 ", expected=%" PRIuz,
174 return STATUS_BUFFER_TOO_SMALL;
181 return STATUS_INVALID_PARAMETER;
186 WLog_Print(log, WLOG_ERROR,
187 "Invalid length read from NDR pointer, minimum %" PRIuz
", got %" PRIuz, min,
189 return STATUS_DATA_ERROR;
192 if (len > SIZE_MAX / 2)
193 return STATUS_BUFFER_TOO_SMALL;
195 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(log, s, len, elementSize))
196 return STATUS_BUFFER_TOO_SMALL;
203 r = calloc(len +
sizeof(WCHAR),
sizeof(CHAR));
205 return SCARD_E_NO_MEMORY;
206 Stream_Read(s, r, len);
207 const LONG pad = smartcard_unpack_read_size_align(s, len, 4);
211 return STATUS_INVALID_PARAMETER;
216 return STATUS_SUCCESS;
219WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_read(wLog* log,
wStream* s, BYTE** data,
size_t min,
220 size_t elementSize,
const ndr_ptr_t type)
222 return smartcard_ndr_read_ex(log, s, data, min, elementSize, type,
nullptr);
226static BOOL smartcard_ndr_pointer_write(
wStream* s, UINT32* index, UINT32 length)
228 const UINT32 ndrPtr = 0x20000 + (*index) * 4;
232 if (!Stream_EnsureRemainingCapacity(s, 4))
237 Stream_Write_UINT32(s, ndrPtr);
238 (*index) = (*index) + 1;
241 Stream_Write_UINT32(s, 0);
245WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_write(
wStream* s,
const BYTE* data, UINT32 size,
246 UINT32 elementSize,
const ndr_ptr_t type)
248 const UINT32 offset = 0;
249 const UINT32 len = size;
250 const UINT32 dataLen = size * elementSize;
254 return SCARD_S_SUCCESS;
268 return SCARD_E_INVALID_PARAMETER;
271 if (!Stream_EnsureRemainingCapacity(s, required))
272 return STATUS_BUFFER_TOO_SMALL;
277 Stream_Write_UINT32(s, len);
278 Stream_Write_UINT32(s, offset);
279 Stream_Write_UINT32(s, len);
282 Stream_Write_UINT32(s, len);
287 return SCARD_E_INVALID_PARAMETER;
290 if (!Stream_EnsureRemainingCapacity(s, dataLen))
291 return STATUS_BUFFER_TOO_SMALL;
294 Stream_Write(s, data, dataLen);
296 Stream_Zero(s, dataLen);
297 return smartcard_pack_write_size_align(s, dataLen, 4);
300WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_write_state(
wStream* s,
302 UINT32 size,
const ndr_ptr_t type)
310 WINPR_ASSERT(data || (size == 0));
313 for (
size_t x = 0; x < size; x++)
316 if (!smartcard_reader_state_return_is_valid(x, cur))
317 return SCARD_E_INVALID_ATR;
322WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_read_state(wLog* log,
wStream* s,
324 const ndr_ptr_t type)
338 if (status != SCARD_S_SUCCESS)
342 return SCARD_E_INVALID_VALUE;
344 for (
size_t x = 0; x < min; x++)
347 if (!smartcard_reader_state_return_is_valid(x, cur))
348 return SCARD_E_INVALID_ATR;
353WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_read_atrmask(wLog* log,
wStream* s,
355 const ndr_ptr_t type)
363 const LONG status = smartcard_ndr_read(log, s, u.ppv, min,
sizeof(
LocateCards_ATRMask), type);
364 if (status != SCARD_S_SUCCESS)
371 for (
size_t x = 0; x < min; x++)
373 const UINT32 val = winpr_Data_Get_UINT32(&masks[x].cbAtr);
374 if (val > ARRAYSIZE(masks[x].rgbAtr))
376 WLog_Print(log, WLOG_ERROR,
377 "LocateCards_ATRMask[%" PRIuz
"]::cbAtr %" PRIu32
" exceeds %" PRIuz, x, val,
378 (
size_t)ARRAYSIZE(masks[x].rgbAtr));
381 return STATUS_DATA_ERROR;
384 return SCARD_S_SUCCESS;
387WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_read_fixed_string_a(wLog* log,
wStream* s,
388 CHAR** data,
size_t min,
389 const ndr_ptr_t type)
397 return smartcard_ndr_read(log, s, u.ppv, min,
sizeof(CHAR), type);
400WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_read_fixed_string_w(wLog* log,
wStream* s,
401 WCHAR** data,
size_t min,
402 const ndr_ptr_t type)
410 return smartcard_ndr_read(log, s, u.ppv, min,
sizeof(WCHAR), type);
413WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_read_a(wLog* log,
wStream* s, CHAR** data,
414 const ndr_ptr_t type)
422 return smartcard_ndr_read(log, s, u.ppv, 0,
sizeof(CHAR), type);
425WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_read_w(wLog* log,
wStream* s, WCHAR** data,
426 const ndr_ptr_t type)
434 return smartcard_ndr_read(log, s, u.ppv, 0,
sizeof(WCHAR), type);
437WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_write_w(
wStream* s,
const WCHAR* data, UINT32 size,
438 const ndr_ptr_t type)
446 return smartcard_ndr_write(s, cnv.bp, size,
sizeof(WCHAR), type);
449WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_write_a(
wStream* s,
const CHAR* data, UINT32 size,
450 const ndr_ptr_t type)
458 return smartcard_ndr_write(s, cnv.bp, size,
sizeof(CHAR), type);
461WINPR_ATTR_NODISCARD
static LONG smartcard_ndr_read_u(wLog* log,
wStream* s,
UUID** data)
469 return smartcard_ndr_read(log, s, u.ppv, 1,
sizeof(
UUID), NDR_PTR_FIXED);
472static char* smartcard_convert_string_list(
const void* in,
size_t bytes, BOOL unicode)
481 char* mszA =
nullptr;
493 mszA = ConvertMszWCharNToUtf8Alloc(
string.wz, bytes /
sizeof(WCHAR), &length);
499 mszA = (
char*)calloc(bytes,
sizeof(
char));
502 CopyMemory(mszA,
string.sz, bytes - 1);
511 for (
size_t index = 0; index < length - 1; index++)
513 if (mszA[index] ==
'\0')
520WINPR_ATTR_MALLOC(free, 1)
521static
char* smartcard_create_msz_dump(const
char* msz,
size_t len)
523 size_t bufferLen = len;
524 char* buffer = calloc(len + 1, 1);
529 const char* cur = msz;
531 while ((len > 0) && cur && cur[0] !=
'\0' && (bufferLen > 0))
533 size_t clen = strnlen(cur, len);
534 int rc = _snprintf(buf, bufferLen,
"%s", cur);
535 bufferLen -= (size_t)rc;
544static void smartcard_msz_dump(wLog* log, DWORD level,
const char* prefix,
const void* data,
545 size_t len, UINT32 wchar)
547 if (!WLog_IsLevelActive(log, level))
551 const char* msz = WINPR_CXX_COMPAT_CAST(
const char*, data);
555 tmp = ConvertMszWCharNToUtf8Alloc(data, len, &mszlen);
559 char* array = smartcard_create_msz_dump(msz, mszlen);
560 WLog_Print(log, level,
"%s%s", prefix, array);
565WINPR_ATTR_MALLOC(free, 1)
566static
char* smartcard_create_array_dump(const
void* pd,
size_t len)
568 const BYTE* data = pd;
571 size_t bufferLen = len * 4;
574 char* buffer = calloc(bufferLen + 1, 1);
577 char* start = buffer;
579 WINPR_ASSERT(buffer || (bufferLen == 0));
581 if (!data && (len > 0))
583 (void)_snprintf(buffer, bufferLen,
"{ nullptr [%" PRIuz
"] }", len);
587 rc = _snprintf(buffer, bufferLen,
"{ ");
588 if ((rc < 0) || ((
size_t)rc >= bufferLen))
591 bufferLen -= (size_t)rc;
593 for (
size_t x = 0; x < len; x++)
595 rc = _snprintf(buffer, bufferLen,
"%02X", data[x]);
596 if ((rc < 0) || ((
size_t)rc >= bufferLen))
599 bufferLen -= (size_t)rc;
602 rc = _snprintf(buffer, bufferLen,
" }");
603 if ((rc < 0) || ((
size_t)rc >= bufferLen))
610WINPR_ATTR_FORMAT_ARG(3, 7)
611static
void smartcard_dump_array(wLog* log, DWORD level, WINPR_FORMAT_ARG const
char* prefix,
612 const
char* postfix, const
void* data,
size_t len, ...)
614 if (!WLog_IsLevelActive(log, level))
617 char* buffer = smartcard_create_array_dump(data, len);
619 char* fprefix =
nullptr;
621 va_list ap = WINPR_C_ARRAY_INIT;
623 winpr_vasprintf(&fprefix, &flen, prefix, ap);
625 WLog_Print(log, level,
"%s%s%s", fprefix, buffer, postfix);
630static void smartcard_log_redir_handle(wLog* log,
const REDIR_SCARDHANDLE* pHandle)
632 WINPR_ASSERT(pHandle);
633 smartcard_dump_array(log, g_LogLevel,
"handle: ",
"", pHandle->pbHandle, pHandle->cbHandle);
638 WINPR_ASSERT(phContext);
639 smartcard_dump_array(log, g_LogLevel,
"hContext: ",
"", phContext->pbContext,
640 phContext->cbContext);
643static void smartcard_trace_context_and_string_call_a(wLog* log,
const char* name,
647 if (!WLog_IsLevelActive(log, g_LogLevel))
650 WLog_Print(log, g_LogLevel,
"%s {", name);
651 smartcard_log_context(log, phContext);
652 WLog_Print(log, g_LogLevel,
" sz=%s", sz);
654 WLog_Print(log, g_LogLevel,
"}");
657static void smartcard_trace_context_and_string_call_w(wLog* log,
const char* name,
663 if (!WLog_IsLevelActive(log, g_LogLevel))
667 tmp = ConvertWCharToUtf8Alloc(sz,
nullptr);
669 WLog_Print(log, g_LogLevel,
"%s {", name);
670 smartcard_log_context(log, phContext);
671 WLog_Print(log, g_LogLevel,
" sz=%s", tmp);
672 WLog_Print(log, g_LogLevel,
"}");
676static void smartcard_trace_context_call(wLog* log,
const Context_Call* call,
const char* name)
680 if (!WLog_IsLevelActive(log, g_LogLevel))
683 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
684 smartcard_log_context(log, &call->handles.hContext);
686 WLog_Print(log, g_LogLevel,
"}");
694 if (!WLog_IsLevelActive(log, g_LogLevel))
697 WLog_Print(log, g_LogLevel,
"ListReaderGroups%s_Call {", unicode ?
"W" :
"A");
698 smartcard_log_context(log, &call->handles.hContext);
700 WLog_Print(log, g_LogLevel,
"fmszGroupsIsNULL: %" PRId32
" cchGroups: 0x%08" PRIx32,
701 call->fmszGroupsIsNULL, call->cchGroups);
702 WLog_Print(log, g_LogLevel,
"}");
705static void dump_reader_states_return(wLog* log,
const ReaderState_Return* rgReaderStates,
708 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
709 for (UINT32 index = 0; index < cReaders; index++)
712 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
713 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
714 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
715 szCurrentState, readerState->dwCurrentState);
716 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
717 szEventState, readerState->dwEventState);
718 free(szCurrentState);
721 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
722 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
729 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
730 for (UINT32 index = 0; index < cReaders; index++)
734 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
735 readerState->szReader, readerState->cbAtr);
736 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
737 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
738 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
739 szCurrentState, readerState->dwCurrentState);
740 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
741 szEventState, readerState->dwEventState);
742 free(szCurrentState);
745 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
746 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
753 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
754 for (UINT32 index = 0; index < cReaders; index++)
757 char* buffer = ConvertWCharToUtf8Alloc(readerState->szReader,
nullptr);
758 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
759 buffer, readerState->cbAtr);
761 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
762 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
763 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
764 szCurrentState, readerState->dwCurrentState);
765 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
766 szEventState, readerState->dwEventState);
767 free(szCurrentState);
770 smartcard_dump_array(log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { ",
" }",
771 readerState->rgbAtr, readerState->cbAtr, index, readerState->cbAtr);
779 if (!WLog_IsLevelActive(log, g_LogLevel))
782 WLog_Print(log, g_LogLevel,
"GetStatusChangeW_Call {");
783 smartcard_log_context(log, &call->handles.hContext);
785 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
788 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
790 WLog_Print(log, g_LogLevel,
"}");
798 if (!WLog_IsLevelActive(log, g_LogLevel))
801 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
803 WLog_Print(log, g_LogLevel,
"ListReaderGroups%s_Return {", unicode ?
"W" :
"A");
804 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIx32
")",
805 SCardGetErrorString(ret->ReturnCode),
806 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
807 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
808 WLog_Print(log, g_LogLevel,
"}");
812static void smartcard_trace_list_readers_call(wLog* log,
const ListReaders_Call* call, BOOL unicode)
816 if (!WLog_IsLevelActive(log, g_LogLevel))
819 char* mszGroupsA = smartcard_convert_string_list(call->mszGroups, call->cBytes, unicode);
821 WLog_Print(log, g_LogLevel,
"ListReaders%s_Call {", unicode ?
"W" :
"A");
822 smartcard_log_context(log, &call->handles.hContext);
824 WLog_Print(log, g_LogLevel,
825 "cBytes: %" PRIu32
" mszGroups: %s fmszReadersIsNULL: %" PRId32
826 " cchReaders: 0x%08" PRIX32
"",
827 call->cBytes, mszGroupsA, call->fmszReadersIsNULL, call->cchReaders);
828 WLog_Print(log, g_LogLevel,
"}");
833static void smartcard_trace_locate_cards_by_atr_a_call(wLog* log,
838 if (!WLog_IsLevelActive(log, g_LogLevel))
841 WLog_Print(log, g_LogLevel,
"LocateCardsByATRA_Call {");
842 smartcard_log_context(log, &call->handles.hContext);
844 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
846 WLog_Print(log, g_LogLevel,
"}");
849static void smartcard_trace_locate_cards_a_call(wLog* log,
const LocateCardsA_Call* call)
853 if (!WLog_IsLevelActive(log, g_LogLevel))
856 WLog_Print(log, g_LogLevel,
"LocateCardsA_Call {");
857 smartcard_log_context(log, &call->handles.hContext);
858 WLog_Print(log, g_LogLevel,
" cBytes=%" PRIu32, call->cBytes);
859 smartcard_msz_dump(log, g_LogLevel,
" mszCards=", call->mszCards, call->cBytes, FALSE);
860 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, call->cReaders);
861 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
863 WLog_Print(log, g_LogLevel,
"}");
866static void smartcard_trace_locate_cards_return(wLog* log,
const LocateCards_Return* ret)
870 if (!WLog_IsLevelActive(log, g_LogLevel))
873 WLog_Print(log, g_LogLevel,
"LocateCards_Return {");
874 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
875 SCardGetErrorString(ret->ReturnCode),
876 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
878 if (ret->ReturnCode == SCARD_S_SUCCESS)
880 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, ret->cReaders);
882 WLog_Print(log, g_LogLevel,
"}");
889 if (!WLog_IsLevelActive(log, g_LogLevel))
892 WLog_Print(log, g_LogLevel,
"GetReaderIcon_Return {");
893 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
894 SCardGetErrorString(ret->ReturnCode),
895 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
897 if (ret->ReturnCode == SCARD_S_SUCCESS)
899 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, ret->cbDataLen);
901 WLog_Print(log, g_LogLevel,
"}");
908 if (!WLog_IsLevelActive(log, g_LogLevel))
911 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Return {");
912 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
913 SCardGetErrorString(ret->ReturnCode),
914 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
916 WLog_Print(log, g_LogLevel,
" cTransmitCount=%" PRIu32, ret->cTransmitCount);
917 WLog_Print(log, g_LogLevel,
"}");
920static void smartcard_trace_read_cache_return(wLog* log,
const ReadCache_Return* ret)
924 if (!WLog_IsLevelActive(log, g_LogLevel))
927 WLog_Print(log, g_LogLevel,
"ReadCache_Return {");
928 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
929 SCardGetErrorString(ret->ReturnCode),
930 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
932 if (ret->ReturnCode == SCARD_S_SUCCESS)
934 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, ret->cbDataLen);
935 smartcard_dump_array(log, g_LogLevel,
" cbData: ",
"", ret->pbData, ret->cbDataLen);
937 WLog_Print(log, g_LogLevel,
"}");
940static void smartcard_trace_locate_cards_w_call(wLog* log,
const LocateCardsW_Call* call)
944 if (!WLog_IsLevelActive(log, g_LogLevel))
947 WLog_Print(log, g_LogLevel,
"LocateCardsW_Call {");
948 smartcard_log_context(log, &call->handles.hContext);
949 WLog_Print(log, g_LogLevel,
" cBytes=%" PRIu32, call->cBytes);
950 smartcard_msz_dump(log, g_LogLevel,
" sz2=", call->mszCards, call->cBytes, TRUE);
951 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, call->cReaders);
952 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
953 WLog_Print(log, g_LogLevel,
"}");
956static void smartcard_trace_list_readers_return(wLog* log,
const ListReaders_Return* ret,
961 if (!WLog_IsLevelActive(log, g_LogLevel))
964 WLog_Print(log, g_LogLevel,
"ListReaders%s_Return {", unicode ?
"W" :
"A");
965 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
966 SCardGetErrorString(ret->ReturnCode),
967 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
969 if (ret->ReturnCode != SCARD_S_SUCCESS)
971 WLog_Print(log, g_LogLevel,
"}");
975 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
977 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
978 WLog_Print(log, g_LogLevel,
"}");
987 if (!WLog_IsLevelActive(log, g_LogLevel))
990 WLog_Print(log, g_LogLevel,
"GetStatusChange%s_Return {", unicode ?
"W" :
"A");
991 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
992 SCardGetErrorString(ret->ReturnCode),
993 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
994 WLog_Print(log, g_LogLevel,
" cReaders: %" PRIu32
"", ret->cReaders);
996 dump_reader_states_return(log, ret->rgReaderStates, ret->cReaders);
998 if (!ret->rgReaderStates && (ret->cReaders > 0))
1000 WLog_Print(log, g_LogLevel,
" [INVALID STATE] rgReaderStates=nullptr, cReaders=%" PRIu32,
1003 else if (ret->ReturnCode != SCARD_S_SUCCESS)
1005 WLog_Print(log, g_LogLevel,
" [INVALID RETURN] rgReaderStates, cReaders=%" PRIu32,
1010 for (UINT32 index = 0; index < ret->cReaders; index++)
1013 char* szCurrentState = SCardGetReaderStateString(rgReaderState->dwCurrentState);
1014 char* szEventState = SCardGetReaderStateString(rgReaderState->dwEventState);
1015 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")",
1016 index, szCurrentState, rgReaderState->dwCurrentState);
1017 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")",
1018 index, szEventState, rgReaderState->dwEventState);
1019 smartcard_dump_array(
1020 log, g_LogLevel,
" [%" PRIu32
"]: cbAtr: %" PRIu32
" rgbAtr: ",
"",
1021 rgReaderState->rgbAtr, rgReaderState->cbAtr, index, rgReaderState->cbAtr);
1022 free(szCurrentState);
1027 WLog_Print(log, g_LogLevel,
"}");
1030static void smartcard_trace_context_and_two_strings_a_call(wLog* log,
1035 if (!WLog_IsLevelActive(log, g_LogLevel))
1038 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
1039 smartcard_log_context(log, &call->handles.hContext);
1040 WLog_Print(log, g_LogLevel,
" sz1=%s", call->sz1);
1041 WLog_Print(log, g_LogLevel,
" sz2=%s", call->sz2);
1042 WLog_Print(log, g_LogLevel,
"}");
1045static void smartcard_trace_context_and_two_strings_w_call(wLog* log,
1049 char sz1[1024] = WINPR_C_ARRAY_INIT;
1050 char sz2[1024] = WINPR_C_ARRAY_INIT;
1052 if (!WLog_IsLevelActive(log, g_LogLevel))
1055 (void)ConvertWCharToUtf8(call->sz1, sz1, ARRAYSIZE(sz1));
1057 (void)ConvertWCharToUtf8(call->sz2, sz2, ARRAYSIZE(sz2));
1059 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
1060 smartcard_log_context(log, &call->handles.hContext);
1061 WLog_Print(log, g_LogLevel,
" sz1=%s", sz1);
1062 WLog_Print(log, g_LogLevel,
" sz2=%s", sz2);
1063 WLog_Print(log, g_LogLevel,
"}");
1070 if (!WLog_IsLevelActive(log, g_LogLevel))
1073 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Call {");
1074 smartcard_log_context(log, &call->handles.hContext);
1075 smartcard_log_redir_handle(log, &call->handles.hCard);
1077 WLog_Print(log, g_LogLevel,
"}");
1080static void smartcard_trace_write_cache_a_call(wLog* log,
const WriteCacheA_Call* call)
1084 if (!WLog_IsLevelActive(log, g_LogLevel))
1087 WLog_Print(log, g_LogLevel,
"WriteCacheA_Call {");
1089 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
1091 smartcard_log_context(log, &call->Common.handles.hContext);
1092 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1094 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1095 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1096 smartcard_dump_array(log, g_LogLevel,
" pbData=",
"", call->Common.pbData,
1097 call->Common.cbDataLen);
1098 WLog_Print(log, g_LogLevel,
"}");
1101static void smartcard_trace_write_cache_w_call(wLog* log,
const WriteCacheW_Call* call)
1104 char tmp[1024] = WINPR_C_ARRAY_INIT;
1106 if (!WLog_IsLevelActive(log, g_LogLevel))
1109 WLog_Print(log, g_LogLevel,
"WriteCacheW_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,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1120 smartcard_dump_array(log, g_LogLevel,
" pbData=",
"", call->Common.pbData,
1121 call->Common.cbDataLen);
1122 WLog_Print(log, g_LogLevel,
"}");
1125static void smartcard_trace_read_cache_a_call(wLog* log,
const ReadCacheA_Call* call)
1129 if (!WLog_IsLevelActive(log, g_LogLevel))
1132 WLog_Print(log, g_LogLevel,
"ReadCacheA_Call {");
1134 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
1135 smartcard_log_context(log, &call->Common.handles.hContext);
1136 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1138 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1139 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1140 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1142 WLog_Print(log, g_LogLevel,
"}");
1145static void smartcard_trace_read_cache_w_call(wLog* log,
const ReadCacheW_Call* call)
1148 char tmp[1024] = WINPR_C_ARRAY_INIT;
1150 if (!WLog_IsLevelActive(log, g_LogLevel))
1153 WLog_Print(log, g_LogLevel,
"ReadCacheW_Call {");
1154 if (call->szLookupName)
1155 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
1156 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
1158 smartcard_log_context(log, &call->Common.handles.hContext);
1159 smartcard_dump_array(log, g_LogLevel,
"..CardIdentifier=",
"", call->Common.CardIdentifier,
1161 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1162 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1163 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1165 WLog_Print(log, g_LogLevel,
"}");
1168static void smartcard_trace_transmit_call(wLog* log,
const Transmit_Call* call)
1171 UINT32 cbExtraBytes = 0;
1172 BYTE* pbExtraBytes =
nullptr;
1174 if (!WLog_IsLevelActive(log, g_LogLevel))
1177 WLog_Print(log, g_LogLevel,
"Transmit_Call {");
1178 smartcard_log_context(log, &call->handles.hContext);
1179 smartcard_log_redir_handle(log, &call->handles.hCard);
1181 if (call->pioSendPci)
1183 cbExtraBytes = (UINT32)(call->pioSendPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1185 WLog_Print(log, g_LogLevel,
"pioSendPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1186 call->pioSendPci->dwProtocol, cbExtraBytes);
1190 smartcard_dump_array(log, g_LogLevel,
"pbExtraBytes: ",
"", pbExtraBytes, cbExtraBytes);
1195 WLog_Print(log, g_LogLevel,
"pioSendPci: null");
1198 WLog_Print(log, g_LogLevel,
"cbSendLength: %" PRIu32
"", call->cbSendLength);
1200 if (call->pbSendBuffer)
1202 smartcard_dump_array(log, g_LogLevel,
"pbSendBuffer: ",
"", call->pbSendBuffer,
1203 call->cbSendLength);
1207 WLog_Print(log, g_LogLevel,
"pbSendBuffer: null");
1210 if (call->pioRecvPci)
1212 cbExtraBytes = (UINT32)(call->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1214 WLog_Print(log, g_LogLevel,
"pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1215 call->pioRecvPci->dwProtocol, cbExtraBytes);
1219 smartcard_dump_array(log, g_LogLevel,
"pbExtraBytes: ",
"", pbExtraBytes, cbExtraBytes);
1224 WLog_Print(log, g_LogLevel,
"pioRecvPci: null");
1227 WLog_Print(log, g_LogLevel,
"fpbRecvBufferIsNULL: %" PRId32
" cbRecvLength: %" PRIu32
"",
1228 call->fpbRecvBufferIsNULL, call->cbRecvLength);
1229 WLog_Print(log, g_LogLevel,
"}");
1232static void smartcard_trace_locate_cards_by_atr_w_call(wLog* log,
1237 if (!WLog_IsLevelActive(log, g_LogLevel))
1240 WLog_Print(log, g_LogLevel,
"LocateCardsByATRW_Call {");
1241 smartcard_log_context(log, &call->handles.hContext);
1243 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
1245 WLog_Print(log, g_LogLevel,
"}");
1248static void smartcard_trace_transmit_return(wLog* log,
const Transmit_Return* ret)
1251 UINT32 cbExtraBytes = 0;
1252 BYTE* pbExtraBytes =
nullptr;
1254 if (!WLog_IsLevelActive(log, g_LogLevel))
1257 WLog_Print(log, g_LogLevel,
"Transmit_Return {");
1258 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1259 SCardGetErrorString(ret->ReturnCode),
1260 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1262 if (ret->pioRecvPci)
1264 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1266 WLog_Print(log, g_LogLevel,
1267 " pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1268 ret->pioRecvPci->dwProtocol, cbExtraBytes);
1272 smartcard_dump_array(log, g_LogLevel,
" pbExtraBytes: ",
"", pbExtraBytes,
1278 WLog_Print(log, g_LogLevel,
" pioRecvPci: null");
1281 WLog_Print(log, g_LogLevel,
" cbRecvLength: %" PRIu32
"", ret->cbRecvLength);
1283 if (ret->pbRecvBuffer)
1285 smartcard_dump_array(log, g_LogLevel,
" pbRecvBuffer: ",
"", ret->pbRecvBuffer,
1290 WLog_Print(log, g_LogLevel,
" pbRecvBuffer: null");
1293 WLog_Print(log, g_LogLevel,
"}");
1296static void smartcard_trace_control_return(wLog* log,
const Control_Return* ret)
1300 if (!WLog_IsLevelActive(log, g_LogLevel))
1303 WLog_Print(log, g_LogLevel,
"Control_Return {");
1304 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1305 SCardGetErrorString(ret->ReturnCode),
1306 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1307 WLog_Print(log, g_LogLevel,
" cbOutBufferSize: %" PRIu32
"", ret->cbOutBufferSize);
1309 if (ret->pvOutBuffer)
1311 smartcard_dump_array(log, g_LogLevel,
"pvOutBuffer: ",
"", ret->pvOutBuffer,
1312 ret->cbOutBufferSize);
1316 WLog_Print(log, g_LogLevel,
"pvOutBuffer: null");
1319 WLog_Print(log, g_LogLevel,
"}");
1322static void smartcard_trace_control_call(wLog* log,
const Control_Call* call)
1326 if (!WLog_IsLevelActive(log, g_LogLevel))
1329 WLog_Print(log, g_LogLevel,
"Control_Call {");
1330 smartcard_log_context(log, &call->handles.hContext);
1331 smartcard_log_redir_handle(log, &call->handles.hCard);
1333 WLog_Print(log, g_LogLevel,
1334 "dwControlCode: 0x%08" PRIX32
" cbInBufferSize: %" PRIu32
1335 " fpvOutBufferIsNULL: %" PRId32
" cbOutBufferSize: %" PRIu32
"",
1336 call->dwControlCode, call->cbInBufferSize, call->fpvOutBufferIsNULL,
1337 call->cbOutBufferSize);
1339 if (call->pvInBuffer)
1341 smartcard_dump_array(log, WLOG_DEBUG,
"pbInBuffer: ",
"", call->pvInBuffer,
1342 call->cbInBufferSize);
1346 WLog_Print(log, g_LogLevel,
"pvInBuffer: null");
1349 WLog_Print(log, g_LogLevel,
"}");
1352static void smartcard_trace_set_attrib_call(wLog* log,
const SetAttrib_Call* call)
1356 if (!WLog_IsLevelActive(log, g_LogLevel))
1359 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1360 smartcard_log_context(log, &call->handles.hContext);
1361 smartcard_log_redir_handle(log, &call->handles.hCard);
1362 WLog_Print(log, g_LogLevel,
"dwAttrId: 0x%08" PRIX32, call->dwAttrId);
1363 WLog_Print(log, g_LogLevel,
"cbAttrLen: 0x%08" PRIx32, call->cbAttrLen);
1364 smartcard_dump_array(log, g_LogLevel,
"pbAttr: ",
"", call->pbAttr, call->cbAttrLen);
1365 WLog_Print(log, g_LogLevel,
"}");
1368static void smartcard_trace_get_attrib_return(wLog* log,
const GetAttrib_Return* ret,
1373 if (!WLog_IsLevelActive(log, g_LogLevel))
1376 WLog_Print(log, g_LogLevel,
"GetAttrib_Return {");
1377 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1378 SCardGetErrorString(ret->ReturnCode),
1379 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1380 WLog_Print(log, g_LogLevel,
" dwAttrId: %s (0x%08" PRIX32
") cbAttrLen: 0x%08" PRIX32
"",
1381 SCardGetAttributeString(dwAttrId), dwAttrId, ret->cbAttrLen);
1382 smartcard_dump_array(log, g_LogLevel,
" ",
"", ret->pbAttr, ret->cbAttrLen);
1384 WLog_Print(log, g_LogLevel,
"}");
1387static void smartcard_trace_get_attrib_call(wLog* log,
const GetAttrib_Call* call)
1391 if (!WLog_IsLevelActive(log, g_LogLevel))
1394 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1395 smartcard_log_context(log, &call->handles.hContext);
1396 smartcard_log_redir_handle(log, &call->handles.hCard);
1398 WLog_Print(log, g_LogLevel,
1399 "dwAttrId: %s (0x%08" PRIX32
") fpbAttrIsNULL: %" PRId32
" cbAttrLen: 0x%08" PRIX32
1401 SCardGetAttributeString(call->dwAttrId), call->dwAttrId, call->fpbAttrIsNULL,
1403 WLog_Print(log, g_LogLevel,
"}");
1406static void smartcard_trace_status_call(wLog* log,
const Status_Call* call, BOOL unicode)
1410 if (!WLog_IsLevelActive(log, g_LogLevel))
1413 WLog_Print(log, g_LogLevel,
"Status%s_Call {", unicode ?
"W" :
"A");
1414 smartcard_log_context(log, &call->handles.hContext);
1415 smartcard_log_redir_handle(log, &call->handles.hCard);
1417 WLog_Print(log, g_LogLevel,
1418 "fmszReaderNamesIsNULL: %" PRId32
" cchReaderLen: %" PRIu32
" cbAtrLen: %" PRIu32
"",
1419 call->fmszReaderNamesIsNULL, call->cchReaderLen, call->cbAtrLen);
1420 WLog_Print(log, g_LogLevel,
"}");
1423static void smartcard_trace_status_return(wLog* log,
const Status_Return* ret, BOOL unicode)
1426 char* mszReaderNamesA =
nullptr;
1429 if (!WLog_IsLevelActive(log, g_LogLevel))
1431 cBytes = ret->cBytes;
1432 if (ret->ReturnCode != SCARD_S_SUCCESS)
1434 if (cBytes == SCARD_AUTOALLOCATE)
1436 mszReaderNamesA = smartcard_convert_string_list(ret->mszReaderNames, cBytes, unicode);
1438 WLog_Print(log, g_LogLevel,
"Status%s_Return {", unicode ?
"W" :
"A");
1439 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1440 SCardGetErrorString(ret->ReturnCode),
1441 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1442 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
") dwProtocol: %s (0x%08" PRIX32
")",
1443 SCardGetCardStateString(ret->dwState), ret->dwState,
1444 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1446 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" mszReaderNames: %s", ret->cBytes,
1449 smartcard_dump_array(log, g_LogLevel,
" cbAtrLen: %" PRIu32
" pbAtr: ",
"", ret->pbAtr,
1450 ret->cbAtrLen, ret->cbAtrLen);
1451 WLog_Print(log, g_LogLevel,
"}");
1452 free(mszReaderNamesA);
1455static void smartcard_trace_state_return(wLog* log,
const State_Return* ret)
1458 char* state =
nullptr;
1460 if (!WLog_IsLevelActive(log, g_LogLevel))
1463 state = SCardGetReaderStateString(ret->dwState);
1464 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1465 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1466 SCardGetErrorString(ret->ReturnCode),
1467 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1468 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
")", state, ret->dwState);
1469 WLog_Print(log, g_LogLevel,
" dwProtocol: %s (0x%08" PRIX32
")",
1470 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1471 WLog_Print(log, g_LogLevel,
" cbAtrLen: (0x%08" PRIX32
")", ret->cbAtrLen);
1472 smartcard_dump_array(log, g_LogLevel,
" rgAtr: ",
"", ret->rgAtr,
sizeof(ret->rgAtr));
1473 WLog_Print(log, g_LogLevel,
"}");
1477static void smartcard_trace_reconnect_return(wLog* log,
const Reconnect_Return* ret)
1481 if (!WLog_IsLevelActive(log, g_LogLevel))
1484 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1485 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1486 SCardGetErrorString(ret->ReturnCode),
1487 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1488 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1489 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1490 WLog_Print(log, g_LogLevel,
"}");
1493static void smartcard_trace_connect_a_call(wLog* log,
const ConnectA_Call* call)
1497 if (!WLog_IsLevelActive(log, g_LogLevel))
1500 WLog_Print(log, g_LogLevel,
"ConnectA_Call {");
1501 smartcard_log_context(log, &call->Common.handles.hContext);
1503 WLog_Print(log, g_LogLevel,
1504 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1505 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1506 call->szReader, SCardGetShareModeString(call->Common.dwShareMode),
1507 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1508 call->Common.dwPreferredProtocols);
1509 WLog_Print(log, g_LogLevel,
"}");
1512static void smartcard_trace_connect_w_call(wLog* log,
const ConnectW_Call* call)
1515 char szReaderA[1024] = WINPR_C_ARRAY_INIT;
1517 if (!WLog_IsLevelActive(log, g_LogLevel))
1521 (void)ConvertWCharToUtf8(call->szReader, szReaderA, ARRAYSIZE(szReaderA));
1522 WLog_Print(log, g_LogLevel,
"ConnectW_Call {");
1523 smartcard_log_context(log, &call->Common.handles.hContext);
1525 WLog_Print(log, g_LogLevel,
1526 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1527 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1528 szReaderA, SCardGetShareModeString(call->Common.dwShareMode),
1529 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1530 call->Common.dwPreferredProtocols);
1531 WLog_Print(log, g_LogLevel,
"}");
1534static void smartcard_trace_hcard_and_disposition_call(wLog* log,
1540 if (!WLog_IsLevelActive(log, g_LogLevel))
1543 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
1544 smartcard_log_context(log, &call->handles.hContext);
1545 smartcard_log_redir_handle(log, &call->handles.hCard);
1547 WLog_Print(log, g_LogLevel,
"dwDisposition: %s (0x%08" PRIX32
")",
1548 SCardGetDispositionString(call->dwDisposition), call->dwDisposition);
1549 WLog_Print(log, g_LogLevel,
"}");
1556 if (!WLog_IsLevelActive(log, g_LogLevel))
1559 WLog_Print(log, g_LogLevel,
"EstablishContext_Call {");
1560 WLog_Print(log, g_LogLevel,
"dwScope: %s (0x%08" PRIX32
")", SCardGetScopeString(call->dwScope),
1562 WLog_Print(log, g_LogLevel,
"}");
1569 if (!WLog_IsLevelActive(log, g_LogLevel))
1572 WLog_Print(log, g_LogLevel,
"EstablishContext_Return {");
1573 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1574 SCardGetErrorString(ret->ReturnCode),
1575 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1576 smartcard_log_context(log, &ret->hContext);
1578 WLog_Print(log, g_LogLevel,
"}");
1581void smartcard_trace_long_return(
const Long_Return* ret,
const char* name)
1583 wLog* log = scard_log();
1584 smartcard_trace_long_return_int(log, ret, name);
1587void smartcard_trace_long_return_int(wLog* log,
const Long_Return* ret,
const char* name)
1591 if (!WLog_IsLevelActive(log, g_LogLevel))
1594 WLog_Print(log, g_LogLevel,
"%s_Return {", name);
1595 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1596 SCardGetErrorString(ret->ReturnCode),
1597 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1598 WLog_Print(log, g_LogLevel,
"}");
1601static void smartcard_trace_connect_return(wLog* log,
const Connect_Return* ret)
1605 if (!WLog_IsLevelActive(log, g_LogLevel))
1608 WLog_Print(log, g_LogLevel,
"Connect_Return {");
1609 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1610 SCardGetErrorString(ret->ReturnCode),
1611 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1612 smartcard_log_context(log, &ret->hContext);
1613 smartcard_log_redir_handle(log, &ret->hCard);
1615 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1616 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1617 WLog_Print(log, g_LogLevel,
"}");
1620static void smartcard_trace_reconnect_call(wLog* log,
const Reconnect_Call* call)
1624 if (!WLog_IsLevelActive(log, g_LogLevel))
1627 WLog_Print(log, g_LogLevel,
"Reconnect_Call {");
1628 smartcard_log_context(log, &call->handles.hContext);
1629 smartcard_log_redir_handle(log, &call->handles.hCard);
1631 WLog_Print(log, g_LogLevel,
1632 "dwShareMode: %s (0x%08" PRIX32
") dwPreferredProtocols: %s (0x%08" PRIX32
1633 ") dwInitialization: %s (0x%08" PRIX32
")",
1634 SCardGetShareModeString(call->dwShareMode), call->dwShareMode,
1635 SCardGetProtocolString(call->dwPreferredProtocols), call->dwPreferredProtocols,
1636 SCardGetDispositionString(call->dwInitialization), call->dwInitialization);
1637 WLog_Print(log, g_LogLevel,
"}");
1644 if (!WLog_IsLevelActive(log, g_LogLevel))
1647 WLog_Print(log, g_LogLevel,
"GetDeviceTypeId_Return {");
1648 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1649 SCardGetErrorString(ret->ReturnCode),
1650 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1651 WLog_Print(log, g_LogLevel,
" dwDeviceId=%08" PRIx32, ret->dwDeviceId);
1653 WLog_Print(log, g_LogLevel,
"}");
1656WINPR_ATTR_NODISCARD
static LONG
1658 CHAR** pszReaderName)
1661 UINT32 pbContextNdrPtr = 0;
1662 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1663 if (status != SCARD_S_SUCCESS)
1666 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
1667 return ERROR_INVALID_DATA;
1669 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1670 if (status != SCARD_S_SUCCESS)
1673 status = smartcard_ndr_read_a(log, s, pszReaderName, NDR_PTR_FULL);
1674 if (status != SCARD_S_SUCCESS)
1677 smartcard_trace_context_and_string_call_a(log, __func__, phContext, *pszReaderName);
1678 return SCARD_S_SUCCESS;
1681WINPR_ATTR_NODISCARD
static LONG
1683 WCHAR** pszReaderName)
1686 UINT32 pbContextNdrPtr = 0;
1688 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1689 if (status != SCARD_S_SUCCESS)
1692 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
1693 return ERROR_INVALID_DATA;
1695 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1696 if (status != SCARD_S_SUCCESS)
1699 status = smartcard_ndr_read_w(log, s, pszReaderName, NDR_PTR_FULL);
1700 if (status != SCARD_S_SUCCESS)
1703 smartcard_trace_context_and_string_call_w(log, __func__, phContext, *pszReaderName);
1704 return SCARD_S_SUCCESS;
1707LONG smartcard_unpack_common_type_header(
wStream* s)
1709 wLog* log = scard_log();
1712 UINT8 endianness = 0;
1713 UINT16 commonHeaderLength = 0;
1715 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1716 return STATUS_BUFFER_TOO_SMALL;
1719 Stream_Read_UINT8(s, version);
1720 Stream_Read_UINT8(s, endianness);
1721 Stream_Read_UINT16(s, commonHeaderLength);
1722 Stream_Read_UINT32(s, filler);
1726 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Version %" PRIu8
"", version);
1727 return STATUS_INVALID_PARAMETER;
1730 if (endianness != 0x10)
1732 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Endianness %" PRIu8
"",
1734 return STATUS_INVALID_PARAMETER;
1737 if (commonHeaderLength != 8)
1739 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader CommonHeaderLength %" PRIu16
"",
1740 commonHeaderLength);
1741 return STATUS_INVALID_PARAMETER;
1744 if (filler != 0xCCCCCCCC)
1746 WLog_Print(log, WLOG_WARN,
"Unexpected CommonTypeHeader Filler 0x%08" PRIX32
"", filler);
1747 return STATUS_INVALID_PARAMETER;
1750 return SCARD_S_SUCCESS;
1753void smartcard_pack_common_type_header(
wStream* s)
1755 Stream_Write_UINT8(s, 1);
1756 Stream_Write_UINT8(s, 0x10);
1757 Stream_Write_UINT16(s, 8);
1758 Stream_Write_UINT32(s, 0xCCCCCCCC);
1761LONG smartcard_unpack_private_type_header(
wStream* s)
1763 wLog* log = scard_log();
1765 UINT32 objectBufferLength = 0;
1767 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1768 return STATUS_BUFFER_TOO_SMALL;
1770 Stream_Read_UINT32(s, objectBufferLength);
1771 Stream_Read_UINT32(s, filler);
1773 if (filler != 0x00000000)
1775 WLog_Print(log, WLOG_WARN,
"Unexpected PrivateTypeHeader Filler 0x%08" PRIX32
"", filler);
1776 return STATUS_INVALID_PARAMETER;
1779 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, objectBufferLength))
1780 return STATUS_INVALID_PARAMETER;
1782 return SCARD_S_SUCCESS;
1785void smartcard_pack_private_type_header(
wStream* s, UINT32 objectBufferLength)
1787 Stream_Write_UINT32(s, objectBufferLength);
1788 Stream_Write_UINT32(s, 0x00000000);
1791LONG smartcard_unpack_read_size_align(
wStream* s,
size_t size, UINT32 alignment)
1793 const size_t padsize = (size + alignment - 1) & ~(alignment - 1);
1794 const size_t pad = padsize - size;
1798 if (!Stream_SafeSeek(s, pad))
1805LONG smartcard_pack_write_size_align(
wStream* s,
size_t size, UINT32 alignment)
1807 const size_t padsize = (size + alignment - 1) & ~(alignment - 1);
1808 const size_t pad = padsize - size;
1812 if (!Stream_EnsureRemainingCapacity(s, pad))
1814 wLog* log = scard_log();
1815 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
1816 return SCARD_F_INTERNAL_ERROR;
1819 Stream_Zero(s, pad);
1822 return SCARD_S_SUCCESS;
1825SCARDCONTEXT smartcard_scard_context_native_from_redir(
const REDIR_SCARDCONTEXT* context)
1827 SCARDCONTEXT hContext = WINPR_C_ARRAY_INIT;
1829 WINPR_ASSERT(context);
1830 if ((context->cbContext !=
sizeof(ULONG_PTR)) && (context->cbContext != 0))
1832 wLog* log = scard_log();
1833 WLog_Print(log, WLOG_WARN,
1834 "REDIR_SCARDCONTEXT does not match native size: Actual: %" PRIu32
1835 ", Expected: %" PRIuz
"",
1836 context->cbContext,
sizeof(ULONG_PTR));
1840 if (context->cbContext)
1841 CopyMemory(&hContext, &(context->pbContext), context->cbContext);
1846void smartcard_scard_context_native_to_redir(
REDIR_SCARDCONTEXT* context, SCARDCONTEXT hContext)
1848 WINPR_ASSERT(context);
1850 context->cbContext =
sizeof(ULONG_PTR);
1851 CopyMemory(&(context->pbContext), &hContext, context->cbContext);
1854SCARDHANDLE smartcard_scard_handle_native_from_redir(
const REDIR_SCARDHANDLE* handle)
1856 SCARDHANDLE hCard = 0;
1858 WINPR_ASSERT(handle);
1859 if (handle->cbHandle == 0)
1862 if (handle->cbHandle !=
sizeof(ULONG_PTR))
1864 wLog* log = scard_log();
1865 WLog_Print(log, WLOG_WARN,
1866 "REDIR_SCARDHANDLE does not match native size: Actual: %" PRIu32
1867 ", Expected: %" PRIuz
"",
1868 handle->cbHandle,
sizeof(ULONG_PTR));
1872 if (handle->cbHandle)
1873 CopyMemory(&hCard, &(handle->pbHandle), handle->cbHandle);
1878void smartcard_scard_handle_native_to_redir(
REDIR_SCARDHANDLE* handle, SCARDHANDLE hCard)
1880 WINPR_ASSERT(handle);
1882 handle->cbHandle =
sizeof(ULONG_PTR);
1883 CopyMemory(&(handle->pbHandle), &hCard, handle->cbHandle);
1886#define smartcard_context_supported(log, size) \
1887 smartcard_context_supported_((log), (size), __FILE__, __func__, __LINE__)
1888WINPR_ATTR_NODISCARD
static LONG smartcard_context_supported_(wLog* log, uint32_t size,
1889 const char* file,
const char* fkt,
1897 return SCARD_S_SUCCESS;
1900 const uint32_t level = WLOG_WARN;
1901 if (WLog_IsLevelActive(log, level))
1903 WLog_PrintTextMessage(log, level, line, file, fkt,
1904 "REDIR_SCARDCONTEXT length is not 0, 4 or 8: %" PRIu32
"",
1907 return STATUS_INVALID_PARAMETER;
1913 UINT32* index, UINT32* ppbContextNdrPtr,
1914 const char* file,
const char* function,
size_t line)
1916 UINT32 pbContextNdrPtr = 0;
1919 WINPR_ASSERT(context);
1923 if (!Stream_CheckAndLogRequiredLengthWLogEx(log, WLOG_WARN, s, 4, 1,
"%s(%s:%" PRIuz
")", file,
1925 return STATUS_BUFFER_TOO_SMALL;
1927 const LONG status = smartcard_context_supported_(log, context->cbContext, file, function, line);
1928 if (status != SCARD_S_SUCCESS)
1931 Stream_Read_UINT32(s, context->cbContext);
1932 if (context->cbContext > 16)
1934 WLog_Print(log, WLOG_WARN,
"REDIR_SCARDCONTEXT cbContext (%" PRIu32
") > 16",
1935 context->cbContext);
1936 return ERROR_INVALID_DATA;
1939 if (!smartcard_ndr_pointer_read_(log, s, index, &pbContextNdrPtr, file, function, line))
1940 return ERROR_INVALID_DATA;
1942 if (((context->cbContext == 0) && pbContextNdrPtr) ||
1943 ((context->cbContext != 0) && !pbContextNdrPtr))
1945 WLog_Print(log, WLOG_WARN,
1946 "REDIR_SCARDCONTEXT cbContext (%" PRIu32
") pbContextNdrPtr (%" PRIu32
1948 context->cbContext, pbContextNdrPtr);
1949 return STATUS_INVALID_PARAMETER;
1952 *ppbContextNdrPtr = pbContextNdrPtr;
1953 return SCARD_S_SUCCESS;
1956LONG smartcard_pack_redir_scard_context(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1959 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
1961 WINPR_ASSERT(context);
1962 if (context->cbContext != 0)
1964 Stream_Write_UINT32(s, context->cbContext);
1965 Stream_Write_UINT32(s, pbContextNdrPtr);
1966 *index = *index + 1;
1971 return SCARD_S_SUCCESS;
1974LONG smartcard_unpack_redir_scard_context_ref(wLog* log,
wStream* s,
1975 WINPR_ATTR_UNUSED UINT32 pbContextNdrPtr,
1980 WINPR_ASSERT(context);
1982 if (context->cbContext == 0)
1983 return SCARD_S_SUCCESS;
1985 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1986 return STATUS_BUFFER_TOO_SMALL;
1988 Stream_Read_UINT32(s, length);
1990 if (length != context->cbContext)
1992 WLog_Print(log, WLOG_WARN,
1993 "REDIR_SCARDCONTEXT length (%" PRIu32
") cbContext (%" PRIu32
") mismatch",
1994 length, context->cbContext);
1995 return STATUS_INVALID_PARAMETER;
1998 const LONG status = smartcard_context_supported(log, context->cbContext);
1999 if (status != SCARD_S_SUCCESS)
2002 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, context->cbContext))
2003 return STATUS_BUFFER_TOO_SMALL;
2005 if (context->cbContext)
2006 Stream_Read(s, &(context->pbContext), context->cbContext);
2008 ZeroMemory(&(context->pbContext),
sizeof(context->pbContext));
2010 return SCARD_S_SUCCESS;
2013LONG smartcard_pack_redir_scard_context_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
2016 WINPR_ASSERT(context);
2018 if (context->cbContext == 0)
2019 return SCARD_S_SUCCESS;
2021 Stream_Write_UINT32(s, context->cbContext);
2022 Stream_Write(s, &(context->pbContext), context->cbContext);
2024 return SCARD_S_SUCCESS;
2028 UINT32* index,
const char* file,
const char* function,
2031 UINT32 pbHandleNdrPtr = 0;
2033 WINPR_ASSERT(handle);
2036 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2037 return STATUS_BUFFER_TOO_SMALL;
2039 Stream_Read_UINT32(s, handle->cbHandle);
2041 if (!smartcard_ndr_pointer_read_(log, s, index, &pbHandleNdrPtr, file, function, line))
2042 return ERROR_INVALID_DATA;
2044 if (((handle->cbHandle == 0) && pbHandleNdrPtr) ||
2045 ((handle->cbHandle != 0) && !pbHandleNdrPtr))
2047 WLog_Print(log, WLOG_WARN,
2048 "REDIR_SCARDHANDLE cbHandle (%" PRIu32
") pbHandleNdrPtr (%" PRIu32
2050 handle->cbHandle, pbHandleNdrPtr);
2051 return STATUS_INVALID_PARAMETER;
2054 return SCARD_S_SUCCESS;
2057LONG smartcard_pack_redir_scard_handle(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
2060 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
2062 WINPR_ASSERT(handle);
2063 if (handle->cbHandle != 0)
2065 Stream_Write_UINT32(s, handle->cbHandle);
2066 Stream_Write_UINT32(s, pbContextNdrPtr);
2067 *index = *index + 1;
2071 return SCARD_S_SUCCESS;
2078 WINPR_ASSERT(handle);
2080 if (handle->cbHandle == 0)
2081 return SCARD_S_SUCCESS;
2083 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2084 return STATUS_BUFFER_TOO_SMALL;
2086 Stream_Read_UINT32(s, length);
2088 if (length != handle->cbHandle)
2090 WLog_Print(log, WLOG_WARN,
2091 "REDIR_SCARDHANDLE length (%" PRIu32
") cbHandle (%" PRIu32
") mismatch", length,
2093 return STATUS_INVALID_PARAMETER;
2096 if ((handle->cbHandle != 4) && (handle->cbHandle != 8))
2098 WLog_Print(log, WLOG_WARN,
"REDIR_SCARDHANDLE length is not 4 or 8: %" PRIu32
"",
2100 return STATUS_INVALID_PARAMETER;
2103 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, handle->cbHandle))
2104 return STATUS_BUFFER_TOO_SMALL;
2106 if (handle->cbHandle)
2107 Stream_Read(s, &(handle->pbHandle), handle->cbHandle);
2109 return SCARD_S_SUCCESS;
2112LONG smartcard_pack_redir_scard_handle_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
2115 WINPR_ASSERT(handle);
2117 if (handle->cbHandle == 0)
2118 return SCARD_S_SUCCESS;
2120 Stream_Write_UINT32(s, handle->cbHandle);
2121 Stream_Write(s, &(handle->pbHandle), handle->cbHandle);
2123 return SCARD_S_SUCCESS;
2129 wLog* log = scard_log();
2131 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2132 return STATUS_BUFFER_TOO_SMALL;
2134 Stream_Read_UINT32(s, call->dwScope);
2135 smartcard_trace_establish_context_call(log, call);
2136 return SCARD_S_SUCCESS;
2142 wLog* log = scard_log();
2144 smartcard_trace_establish_context_call(log, call);
2146 if (!Stream_EnsureRemainingCapacity(s, 4))
2147 return SCARD_E_NO_MEMORY;
2149 Stream_Write_UINT32(s, call->dwScope);
2151 return SCARD_S_SUCCESS;
2157 wLog* log = scard_log();
2161 smartcard_trace_establish_context_return(log, ret);
2162 if (ret->ReturnCode != SCARD_S_SUCCESS)
2163 return ret->ReturnCode;
2165 status = smartcard_pack_redir_scard_context(log, s, &(ret->hContext), &index);
2166 if (status != SCARD_S_SUCCESS)
2169 return smartcard_pack_redir_scard_context_ref(log, s, &(ret->hContext));
2175 wLog* log = scard_log();
2177 UINT32 pbContextNdrPtr = 0;
2180 smartcard_unpack_redir_scard_context(log, s, &(ret->hContext), &index, &pbContextNdrPtr);
2181 if (status != SCARD_S_SUCCESS)
2184 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &(ret->hContext));
2185 if (status != SCARD_S_SUCCESS)
2188 smartcard_trace_establish_context_return(log, ret);
2189 return SCARD_S_SUCCESS;
2195 UINT32 pbContextNdrPtr = 0;
2196 wLog* log = scard_log();
2199 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2201 if (status != SCARD_S_SUCCESS)
2204 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2205 &(call->handles.hContext));
2206 if (status != SCARD_S_SUCCESS)
2207 WLog_Print(log, WLOG_ERROR,
2208 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2211 smartcard_trace_context_call(log, call, name);
2218 UINT32 pbContextNdrPtr = 0;
2219 wLog* log = scard_log();
2222 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2225 if (status != SCARD_S_SUCCESS)
2228 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2229 return STATUS_BUFFER_TOO_SMALL;
2231 Stream_Read_INT32(s, call->fmszGroupsIsNULL);
2232 Stream_Read_UINT32(s, call->cchGroups);
2233 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2234 &(call->handles.hContext));
2236 if (status != SCARD_S_SUCCESS)
2239 smartcard_trace_list_reader_groups_call(log, call, unicode);
2240 return SCARD_S_SUCCESS;
2247 wLog* log = scard_log();
2250 smartcard_trace_list_reader_groups_call(log, call, unicode);
2252 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
2253 if (status != SCARD_S_SUCCESS)
2256 if (!Stream_EnsureRemainingCapacity(s, 8))
2257 return SCARD_E_NO_MEMORY;
2259 Stream_Write_INT32(s, call->fmszGroupsIsNULL);
2260 Stream_Write_UINT32(s, call->cchGroups);
2262 return smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
2269 wLog* log = scard_log();
2271 UINT32 cBytes = ret->cBytes;
2274 smartcard_trace_list_reader_groups_return(log, ret, unicode);
2275 if (ret->ReturnCode != SCARD_S_SUCCESS)
2277 if (cBytes == SCARD_AUTOALLOCATE)
2280 if (!Stream_EnsureRemainingCapacity(s, 4))
2281 return SCARD_E_NO_MEMORY;
2285 WLog_Print(log, WLOG_ERROR,
2286 "2.2.3.4 ListReaderGroups_Return and ListReaders_Return cBytes (%" PRIu32
2289 return SCARD_E_INVALID_PARAMETER;
2292 Stream_Write_UINT32(s, cBytes);
2293 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
2294 return SCARD_E_NO_MEMORY;
2296 status = smartcard_ndr_write(s, ret->msz, cBytes, 1, NDR_PTR_SIMPLE);
2297 if (status != SCARD_S_SUCCESS)
2299 return ret->ReturnCode;
2306 wLog* log = scard_log();
2308 UINT32 mszNdrPtr = 0;
2310 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2311 return STATUS_BUFFER_TOO_SMALL;
2313 const UINT32 cBytes = Stream_Get_UINT32(s);
2316 WLog_Print(log, WLOG_ERROR,
2317 "2.2.3.4 ListReaderGroups_Return and ListReaders_Return cBytes (%" PRIu32
2320 return SCARD_E_INVALID_PARAMETER;
2323 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
2324 return ERROR_INVALID_DATA;
2328 LONG status = smartcard_ndr_read(log, s, &ret->msz, cBytes, 1, NDR_PTR_SIMPLE);
2329 if (status != SCARD_S_SUCCESS)
2331 ret->cBytes = cBytes;
2334 smartcard_trace_list_reader_groups_return(log, ret, unicode);
2335 return SCARD_S_SUCCESS;
2341 UINT32 mszGroupsNdrPtr = 0;
2342 UINT32 pbContextNdrPtr = 0;
2343 wLog* log = scard_log();
2346 call->mszGroups =
nullptr;
2348 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2350 if (status != SCARD_S_SUCCESS)
2353 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2354 return STATUS_BUFFER_TOO_SMALL;
2356 const UINT32 cBytes = Stream_Get_UINT32(s);
2359 WLog_Print(log, WLOG_ERROR,
2360 "2.2.3.4 ListReaderGroups_Return and ListReaders_Return cBytes (%" PRIu32
2363 return SCARD_E_INVALID_PARAMETER;
2365 if (!smartcard_ndr_pointer_read(log, s, &index, &mszGroupsNdrPtr))
2366 return ERROR_INVALID_DATA;
2368 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2369 return STATUS_BUFFER_TOO_SMALL;
2370 Stream_Read_INT32(s, call->fmszReadersIsNULL);
2371 Stream_Read_UINT32(s, call->cchReaders);
2373 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2374 &(call->handles.hContext));
2375 if (status != SCARD_S_SUCCESS)
2378 if (mszGroupsNdrPtr)
2380 status = smartcard_ndr_read(log, s, &call->mszGroups, cBytes, 1, NDR_PTR_SIMPLE);
2381 if (status != SCARD_S_SUCCESS)
2383 call->cBytes = cBytes;
2386 smartcard_trace_list_readers_call(log, call, unicode);
2387 return SCARD_S_SUCCESS;
2393 wLog* log = scard_log();
2396 UINT32 size = ret->cBytes;
2398 smartcard_trace_list_readers_return(log, ret, unicode);
2399 if (ret->ReturnCode != SCARD_S_SUCCESS)
2402 if (!Stream_EnsureRemainingCapacity(s, 4))
2404 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
2405 return SCARD_F_INTERNAL_ERROR;
2410 WLog_Print(log, WLOG_ERROR,
2411 "2.2.3.4 ListReaderGroups_Return and ListReaders_Return cBytes (%" PRIu32
2414 return SCARD_E_INVALID_PARAMETER;
2417 Stream_Write_UINT32(s, size);
2418 if (!smartcard_ndr_pointer_write(s, &index, size))
2419 return SCARD_E_NO_MEMORY;
2421 status = smartcard_ndr_write(s, ret->msz, size, 1, NDR_PTR_SIMPLE);
2422 if (status != SCARD_S_SUCCESS)
2424 return ret->ReturnCode;
2427WINPR_ATTR_NODISCARD
static LONG smartcard_unpack_connect_common(wLog* log,
wStream* s,
2430 UINT32* ppbContextNdrPtr)
2432 WINPR_ASSERT(common);
2433 LONG status = smartcard_unpack_redir_scard_context(log, s, &(common->handles.hContext), index,
2435 if (status != SCARD_S_SUCCESS)
2438 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2439 return STATUS_BUFFER_TOO_SMALL;
2441 Stream_Read_UINT32(s, common->dwShareMode);
2442 Stream_Read_UINT32(s, common->dwPreferredProtocols);
2443 return SCARD_S_SUCCESS;
2450 UINT32 pbContextNdrPtr = 0;
2453 wLog* log = scard_log();
2455 call->szReader =
nullptr;
2457 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
2458 return ERROR_INVALID_DATA;
2460 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2461 if (status != SCARD_S_SUCCESS)
2463 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2468 status = smartcard_ndr_read_a(log, s, &call->szReader, NDR_PTR_FULL);
2469 if (status != SCARD_S_SUCCESS)
2472 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2473 &(call->Common.handles.hContext));
2474 if (status != SCARD_S_SUCCESS)
2475 WLog_Print(log, WLOG_ERROR,
2476 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2479 smartcard_trace_connect_a_call(log, call);
2487 UINT32 pbContextNdrPtr = 0;
2490 wLog* log = scard_log();
2491 call->szReader =
nullptr;
2493 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
2494 return ERROR_INVALID_DATA;
2496 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2497 if (status != SCARD_S_SUCCESS)
2499 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2504 status = smartcard_ndr_read_w(log, s, &call->szReader, NDR_PTR_FULL);
2505 if (status != SCARD_S_SUCCESS)
2508 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2509 &(call->Common.handles.hContext));
2510 if (status != SCARD_S_SUCCESS)
2511 WLog_Print(log, WLOG_ERROR,
2512 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2515 smartcard_trace_connect_w_call(log, call);
2525 wLog* log = scard_log();
2526 smartcard_trace_connect_return(log, ret);
2528 status = smartcard_pack_redir_scard_context(log, s, &ret->hContext, &index);
2529 if (status != SCARD_S_SUCCESS)
2532 status = smartcard_pack_redir_scard_handle(log, s, &ret->hCard, &index);
2533 if (status != SCARD_S_SUCCESS)
2536 if (!Stream_EnsureRemainingCapacity(s, 4))
2537 return SCARD_E_NO_MEMORY;
2539 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2540 status = smartcard_pack_redir_scard_context_ref(log, s, &ret->hContext);
2541 if (status != SCARD_S_SUCCESS)
2543 return smartcard_pack_redir_scard_handle_ref(log, s, &(ret->hCard));
2549 UINT32 pbContextNdrPtr = 0;
2552 wLog* log = scard_log();
2553 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2555 if (status != SCARD_S_SUCCESS)
2558 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2559 if (status != SCARD_S_SUCCESS)
2562 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2563 return STATUS_BUFFER_TOO_SMALL;
2565 Stream_Read_UINT32(s, call->dwShareMode);
2566 Stream_Read_UINT32(s, call->dwPreferredProtocols);
2567 Stream_Read_UINT32(s, call->dwInitialization);
2569 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2570 &(call->handles.hContext));
2571 if (status != SCARD_S_SUCCESS)
2573 WLog_Print(log, WLOG_ERROR,
2574 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2579 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2580 if (status != SCARD_S_SUCCESS)
2581 WLog_Print(log, WLOG_ERROR,
2582 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
2584 smartcard_trace_reconnect_call(log, call);
2591 wLog* log = scard_log();
2594 smartcard_trace_reconnect_call(log, call);
2596 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
2597 if (status != SCARD_S_SUCCESS)
2600 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
2601 if (status != SCARD_S_SUCCESS)
2604 if (!Stream_EnsureRemainingCapacity(s, 12))
2605 return SCARD_E_NO_MEMORY;
2607 Stream_Write_UINT32(s, call->dwShareMode);
2608 Stream_Write_UINT32(s, call->dwPreferredProtocols);
2609 Stream_Write_UINT32(s, call->dwInitialization);
2611 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
2612 if (status != SCARD_S_SUCCESS)
2615 return smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
2621 wLog* log = scard_log();
2622 smartcard_trace_reconnect_return(log, ret);
2624 if (!Stream_EnsureRemainingCapacity(s, 4))
2625 return SCARD_E_NO_MEMORY;
2626 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2627 return ret->ReturnCode;
2633 wLog* log = scard_log();
2635 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2636 return STATUS_BUFFER_TOO_SMALL;
2638 Stream_Read_UINT32(s, ret->dwActiveProtocol);
2640 smartcard_trace_reconnect_return(log, ret);
2641 return SCARD_S_SUCCESS;
2648 UINT32 pbContextNdrPtr = 0;
2651 wLog* log = scard_log();
2653 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2655 if (status != SCARD_S_SUCCESS)
2658 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2659 if (status != SCARD_S_SUCCESS)
2662 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2663 return STATUS_BUFFER_TOO_SMALL;
2665 Stream_Read_UINT32(s, call->dwDisposition);
2667 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2668 &(call->handles.hContext));
2669 if (status != SCARD_S_SUCCESS)
2672 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2673 if (status != SCARD_S_SUCCESS)
2676 smartcard_trace_hcard_and_disposition_call(log, call, name);
2684 if (!WLog_IsLevelActive(log, g_LogLevel))
2687 WLog_Print(log, g_LogLevel,
"GetStatusChangeA_Call {");
2688 smartcard_log_context(log, &call->handles.hContext);
2690 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
2693 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
2695 WLog_Print(log, g_LogLevel,
"}");
2698WINPR_ATTR_NODISCARD
static LONG smartcard_unpack_reader_state_a(wLog* log,
wStream* s,
2700 UINT32 cReaders, UINT32* ptrIndex)
2702 LONG status = SCARD_E_NO_MEMORY;
2704 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2705 if (cReaders > UINT8_MAX)
2707 WLog_Print(log, WLOG_ERROR,
2708 "Too many readers(%" PRIu32
"), rejecting request. Limited to <= %d", cReaders,
2710 return SCARD_E_WRITE_TOO_MANY;
2713 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2716 const UINT32 len = Stream_Get_UINT32(s);
2717 if (len != cReaders)
2719 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEA");
2725 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2726 if (!rgReaderStates || !states)
2728 status = ERROR_INVALID_DATA;
2730 for (UINT32 index = 0; index < cReaders; index++)
2732 UINT32 ptr = UINT32_MAX;
2735 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2738 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2744 states[index] = ptr != 0;
2745 Stream_Read_UINT32(s, readerState->dwCurrentState);
2746 Stream_Read_UINT32(s, readerState->dwEventState);
2747 Stream_Read_UINT32(s, readerState->cbAtr);
2748 if (readerState->cbAtr > ARRAYSIZE(readerState->rgbAtr))
2750 WLog_Print(log, WLOG_WARN,
2751 "SCARD_READERSTATEA[%" PRIu32
"]::cbAtr %" PRIu32
" exceeds %" PRIuz, index,
2752 readerState->cbAtr, (
size_t)ARRAYSIZE(readerState->rgbAtr));
2753 readerState->cbAtr = ARRAYSIZE(readerState->rgbAtr);
2755 Stream_Read(s, readerState->rgbAtr, 36);
2758 for (UINT32 index = 0; index < cReaders; index++)
2765 status = smartcard_ndr_read_a(log, s, &readerState->szReader, NDR_PTR_FULL);
2766 if (status != SCARD_S_SUCCESS)
2768 if (!readerState->szReader)
2772 *ppcReaders = rgReaderStates;
2774 return SCARD_S_SUCCESS;
2778 for (UINT32 index = 0; index < cReaders; index++)
2781 free(readerState->szReader);
2784 free(rgReaderStates);
2789WINPR_ATTR_NODISCARD
static LONG smartcard_unpack_reader_state_w(wLog* log,
wStream* s,
2791 UINT32 cReaders, UINT32* ptrIndex)
2793 LONG status = SCARD_E_NO_MEMORY;
2795 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2797 if (cReaders > UINT8_MAX)
2799 WLog_Print(log, WLOG_ERROR,
2800 "Too many readers(%" PRIu32
"), rejecting request. Limited to <= %d", cReaders,
2802 return SCARD_E_WRITE_TOO_MANY;
2805 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2808 const UINT32 len = Stream_Get_UINT32(s);
2809 if (len != cReaders)
2811 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEW");
2817 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2819 if (!rgReaderStates || !states)
2822 status = ERROR_INVALID_DATA;
2823 for (UINT32 index = 0; index < cReaders; index++)
2825 UINT32 ptr = UINT32_MAX;
2828 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2831 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2837 states[index] = ptr != 0;
2838 Stream_Read_UINT32(s, readerState->dwCurrentState);
2839 Stream_Read_UINT32(s, readerState->dwEventState);
2840 Stream_Read_UINT32(s, readerState->cbAtr);
2841 if (readerState->cbAtr > ARRAYSIZE(readerState->rgbAtr))
2843 WLog_Print(log, WLOG_WARN,
2844 "SCARD_READERSTATEW[%" PRIu32
"]::cbAtr %" PRIu32
" exceeds %" PRIuz, index,
2845 readerState->cbAtr, ARRAYSIZE(readerState->rgbAtr));
2846 readerState->cbAtr = ARRAYSIZE(readerState->rgbAtr);
2848 Stream_Read(s, readerState->rgbAtr, 36);
2851 for (UINT32 index = 0; index < cReaders; index++)
2859 status = smartcard_ndr_read_w(log, s, &readerState->szReader, NDR_PTR_FULL);
2860 if (status != SCARD_S_SUCCESS)
2862 if (!readerState->szReader)
2866 *ppcReaders = rgReaderStates;
2868 return SCARD_S_SUCCESS;
2872 for (UINT32 index = 0; index < cReaders; index++)
2875 free(readerState->szReader);
2878 free(rgReaderStates);
2891 UINT32 pbContextNdrPtr = 0;
2894 wLog* log = scard_log();
2896 call->rgReaderStates =
nullptr;
2898 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2900 if (status != SCARD_S_SUCCESS)
2903 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2904 return STATUS_BUFFER_TOO_SMALL;
2906 Stream_Read_UINT32(s, call->dwTimeOut);
2907 const UINT32 cReaders = Stream_Get_UINT32(s);
2910 WLog_Print(log, WLOG_WARN,
2911 "2.2.2.11 GetStatusChangeA_Call: cReaders must be <= 11, got %" PRIu32,
2913 return ERROR_INVALID_DATA;
2916 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2917 return ERROR_INVALID_DATA;
2919 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2920 &(call->handles.hContext));
2921 if (status != SCARD_S_SUCCESS)
2926 status = smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, cReaders, &index);
2927 if (status != SCARD_S_SUCCESS)
2929 call->cReaders = cReaders;
2933 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2934 return SCARD_E_UNEXPECTED;
2937 smartcard_trace_get_status_change_a_call(log, call);
2938 return SCARD_S_SUCCESS;
2945 UINT32 pbContextNdrPtr = 0;
2948 wLog* log = scard_log();
2949 call->rgReaderStates =
nullptr;
2951 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2953 if (status != SCARD_S_SUCCESS)
2956 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2957 return STATUS_BUFFER_TOO_SMALL;
2959 Stream_Read_UINT32(s, call->dwTimeOut);
2960 const UINT32 cReaders = Stream_Get_UINT32(s);
2963 WLog_Print(log, WLOG_WARN,
2964 "2.2.2.12 GetStatusChangeW_Call: cReaders must be <= 11, got %" PRIu32,
2966 return ERROR_INVALID_DATA;
2969 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2970 return ERROR_INVALID_DATA;
2972 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2973 &(call->handles.hContext));
2974 if (status != SCARD_S_SUCCESS)
2979 status = smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, cReaders, &index);
2980 if (status != SCARD_S_SUCCESS)
2982 call->cReaders = cReaders;
2986 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2987 return SCARD_E_UNEXPECTED;
2990 smartcard_trace_get_status_change_w_call(log, call);
2991 return SCARD_S_SUCCESS;
2998 wLog* log = scard_log();
3001 UINT32 cReaders = ret->cReaders;
3004 if (ret->cReaders > 10)
3006 WLog_Print(log, WLOG_ERROR,
3007 "2.2.3.5 LocateCards_Return and GetStatusChange_Return cReaders(%" PRIu32
3010 return SCARD_E_INVALID_PARAMETER;
3013 smartcard_trace_get_status_change_return(log, ret, unicode);
3014 if ((ret->ReturnCode != SCARD_S_SUCCESS) && (ret->ReturnCode != SCARD_E_TIMEOUT))
3016 if (cReaders == SCARD_AUTOALLOCATE)
3019 if (!Stream_EnsureRemainingCapacity(s, 4))
3020 return SCARD_E_NO_MEMORY;
3022 Stream_Write_UINT32(s, cReaders);
3023 if (!smartcard_ndr_pointer_write(s, &index, cReaders))
3024 return SCARD_E_NO_MEMORY;
3025 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cReaders, NDR_PTR_SIMPLE);
3026 if (status != SCARD_S_SUCCESS)
3028 return ret->ReturnCode;
3034 UINT32 pbContextNdrPtr = 0;
3036 wLog* log = scard_log();
3039 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3041 if (status != SCARD_S_SUCCESS)
3044 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3045 if (status != SCARD_S_SUCCESS)
3048 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
3049 return STATUS_BUFFER_TOO_SMALL;
3051 Stream_Read_INT32(s, call->fpbAtrIsNULL);
3052 Stream_Read_UINT32(s, call->cbAtrLen);
3054 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3055 &(call->handles.hContext));
3056 if (status != SCARD_S_SUCCESS)
3059 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3060 if (status != SCARD_S_SUCCESS)
3069 wLog* log = scard_log();
3071 UINT32 cbAtrLen = ret->cbAtrLen;
3074 smartcard_trace_state_return(log, ret);
3075 if (ret->ReturnCode != SCARD_S_SUCCESS)
3077 if (cbAtrLen == SCARD_AUTOALLOCATE)
3080 Stream_Write_UINT32(s, ret->dwState);
3081 Stream_Write_UINT32(s, ret->dwProtocol);
3082 Stream_Write_UINT32(s, cbAtrLen);
3083 if (!smartcard_ndr_pointer_write(s, &index, cbAtrLen))
3084 return SCARD_E_NO_MEMORY;
3085 status = smartcard_ndr_write(s, ret->rgAtr, cbAtrLen, 1, NDR_PTR_SIMPLE);
3086 if (status != SCARD_S_SUCCESS)
3088 return ret->ReturnCode;
3094 UINT32 pbContextNdrPtr = 0;
3097 wLog* log = scard_log();
3099 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3101 if (status != SCARD_S_SUCCESS)
3104 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3105 if (status != SCARD_S_SUCCESS)
3108 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3109 return STATUS_BUFFER_TOO_SMALL;
3111 Stream_Read_INT32(s, call->fmszReaderNamesIsNULL);
3112 Stream_Read_UINT32(s, call->cchReaderLen);
3113 Stream_Read_UINT32(s, call->cbAtrLen);
3115 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3116 &(call->handles.hContext));
3117 if (status != SCARD_S_SUCCESS)
3120 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3121 if (status != SCARD_S_SUCCESS)
3124 smartcard_trace_status_call(log, call, unicode);
3131 wLog* log = scard_log();
3134 smartcard_trace_status_call(log, call, unicode);
3136 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
3137 if (status != SCARD_S_SUCCESS)
3140 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
3141 if (status != SCARD_S_SUCCESS)
3144 if (!Stream_EnsureRemainingCapacity(s, 12))
3145 return SCARD_E_NO_MEMORY;
3147 Stream_Write_INT32(s, call->fmszReaderNamesIsNULL);
3148 Stream_Write_UINT32(s, call->cchReaderLen);
3149 Stream_Write_UINT32(s, call->cbAtrLen);
3151 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
3152 if (status != SCARD_S_SUCCESS)
3155 return smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
3161 wLog* log = scard_log();
3165 UINT32 cBytes = ret->cBytes;
3167 smartcard_trace_status_return(log, ret, unicode);
3168 if (ret->ReturnCode != SCARD_S_SUCCESS)
3170 if (cBytes == SCARD_AUTOALLOCATE)
3173 if (!Stream_EnsureRemainingCapacity(s, 4))
3174 return SCARD_F_INTERNAL_ERROR;
3178 WLog_Print(log, WLOG_ERROR,
"2.2.3.10 Status_Return cBytes(%" PRIu32
") > 65536", cBytes);
3179 return SCARD_E_INVALID_PARAMETER;
3182 Stream_Write_UINT32(s, cBytes);
3183 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
3184 return SCARD_E_NO_MEMORY;
3186 if (!Stream_EnsureRemainingCapacity(s, 44))
3187 return SCARD_F_INTERNAL_ERROR;
3189 Stream_Write_UINT32(s, ret->dwState);
3190 Stream_Write_UINT32(s, ret->dwProtocol);
3191 Stream_Write(s, ret->pbAtr,
sizeof(ret->pbAtr));
3193 if (ret->cbAtrLen > 32)
3195 WLog_Print(log, WLOG_ERROR,
"2.2.3.10 Status_Return cbAtrLen(%" PRIu32
") > 32",
3197 return SCARD_E_INVALID_PARAMETER;
3200 Stream_Write_UINT32(s, ret->cbAtrLen);
3201 status = smartcard_ndr_write(s, ret->mszReaderNames, cBytes, 1, NDR_PTR_SIMPLE);
3202 if (status != SCARD_S_SUCCESS)
3204 return ret->ReturnCode;
3210 wLog* log = scard_log();
3212 UINT32 mszNdrPtr = 0;
3214 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3215 return STATUS_BUFFER_TOO_SMALL;
3217 const UINT32 cBytes = Stream_Get_UINT32(s);
3220 WLog_Print(log, WLOG_ERROR,
"2.2.3.10 Status_Return cBytes(%" PRIu32
") > 65536", cBytes);
3221 return SCARD_E_INVALID_PARAMETER;
3224 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3225 return ERROR_INVALID_DATA;
3227 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 44))
3228 return STATUS_BUFFER_TOO_SMALL;
3230 Stream_Read_UINT32(s, ret->dwState);
3231 Stream_Read_UINT32(s, ret->dwProtocol);
3232 Stream_Read(s, ret->pbAtr,
sizeof(ret->pbAtr));
3233 Stream_Read_UINT32(s, ret->cbAtrLen);
3235 if (ret->cbAtrLen > ARRAYSIZE(ret->pbAtr))
3237 WLog_Print(log, WLOG_ERROR,
"Status_Return::cbAtrLen %" PRIu32
" exceeds %" PRIuz,
3238 ret->cbAtrLen, ARRAYSIZE(ret->pbAtr));
3239 return SCARD_E_INVALID_ATR;
3244 LONG status = smartcard_ndr_read(log, s, &ret->mszReaderNames, cBytes, 1, NDR_PTR_SIMPLE);
3245 if (status != SCARD_S_SUCCESS)
3247 ret->cBytes = cBytes;
3250 smartcard_trace_status_return(log, ret, unicode);
3251 return SCARD_S_SUCCESS;
3257 wLog* log = scard_log();
3259 UINT32 pbContextNdrPtr = 0;
3261 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3263 if (status != SCARD_S_SUCCESS)
3266 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3267 if (status != SCARD_S_SUCCESS)
3270 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3271 return STATUS_BUFFER_TOO_SMALL;
3273 Stream_Read_UINT32(s, call->dwAttrId);
3274 Stream_Read_INT32(s, call->fpbAttrIsNULL);
3275 Stream_Read_UINT32(s, call->cbAttrLen);
3277 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3278 &(call->handles.hContext));
3279 if (status != SCARD_S_SUCCESS)
3282 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3283 if (status != SCARD_S_SUCCESS)
3286 smartcard_trace_get_attrib_call(log, call);
3291 DWORD cbAttrCallLen)
3294 wLog* log = scard_log();
3296 UINT32 cbAttrLen = 0;
3298 smartcard_trace_get_attrib_return(log, ret, dwAttrId);
3300 if (!Stream_EnsureRemainingCapacity(s, 4))
3301 return SCARD_F_INTERNAL_ERROR;
3303 cbAttrLen = ret->cbAttrLen;
3304 if (ret->ReturnCode != SCARD_S_SUCCESS)
3306 if (cbAttrLen == SCARD_AUTOALLOCATE)
3311 if (cbAttrCallLen < cbAttrLen)
3312 cbAttrLen = cbAttrCallLen;
3314 if (cbAttrLen > 65536)
3316 WLog_Print(log, WLOG_ERROR,
"2.2.3.12 GetAttrib_Return cbAttrLen(%" PRIu32
") > 65536",
3318 return SCARD_E_INVALID_PARAMETER;
3320 Stream_Write_UINT32(s, cbAttrLen);
3321 if (!smartcard_ndr_pointer_write(s, &index, cbAttrLen))
3322 return SCARD_E_NO_MEMORY;
3324 status = smartcard_ndr_write(s, ret->pbAttr, cbAttrLen, 1, NDR_PTR_SIMPLE);
3325 if (status != SCARD_S_SUCCESS)
3327 return ret->ReturnCode;
3333 wLog* log = scard_log();
3336 UINT32 pvInBufferNdrPtr = 0;
3337 UINT32 pbContextNdrPtr = 0;
3339 call->pvInBuffer =
nullptr;
3341 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3343 if (status != SCARD_S_SUCCESS)
3346 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3347 if (status != SCARD_S_SUCCESS)
3350 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 20))
3351 return STATUS_BUFFER_TOO_SMALL;
3353 Stream_Read_UINT32(s, call->dwControlCode);
3354 const UINT32 cbInBufferSize = Stream_Get_UINT32(s);
3355 if (cbInBufferSize > 66560)
3357 WLog_Print(log, WLOG_ERROR,
"2.2.2.20 Control_Call cbInBufferSize (%" PRIu32
") > 66560",
3359 return SCARD_E_INVALID_PARAMETER;
3362 if (!smartcard_ndr_pointer_read(log, s, &index,
3364 return ERROR_INVALID_DATA;
3365 Stream_Read_INT32(s, call->fpvOutBufferIsNULL);
3366 Stream_Read_UINT32(s, call->cbOutBufferSize);
3368 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3369 &(call->handles.hContext));
3370 if (status != SCARD_S_SUCCESS)
3373 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3374 if (status != SCARD_S_SUCCESS)
3377 if (pvInBufferNdrPtr)
3379 status = smartcard_ndr_read(log, s, &call->pvInBuffer, cbInBufferSize, 1, NDR_PTR_SIMPLE);
3380 if (status != SCARD_S_SUCCESS)
3382 call->cbInBufferSize = cbInBufferSize;
3385 smartcard_trace_control_call(log, call);
3386 return SCARD_S_SUCCESS;
3392 wLog* log = scard_log();
3395 UINT32 cbDataLen = ret->cbOutBufferSize;
3398 smartcard_trace_control_return(log, ret);
3399 if (ret->ReturnCode != SCARD_S_SUCCESS)
3401 if (cbDataLen == SCARD_AUTOALLOCATE)
3404 if (!Stream_EnsureRemainingCapacity(s, 4))
3405 return SCARD_F_INTERNAL_ERROR;
3407 if (cbDataLen > 66560)
3409 WLog_Print(log, WLOG_ERROR,
"2.2.3.6 Control_Return cbOutBufferSize(%" PRIu32
") > 66560",
3411 return SCARD_E_INVALID_PARAMETER;
3414 Stream_Write_UINT32(s, cbDataLen);
3415 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3416 return SCARD_E_NO_MEMORY;
3418 status = smartcard_ndr_write(s, ret->pvOutBuffer, cbDataLen, 1, NDR_PTR_SIMPLE);
3419 if (status != SCARD_S_SUCCESS)
3421 return ret->ReturnCode;
3427 BYTE* pbExtraBytes =
nullptr;
3428 UINT32 pbExtraBytesNdrPtr = 0;
3429 UINT32 pbSendBufferNdrPtr = 0;
3430 UINT32 pioRecvPciNdrPtr = 0;
3434 UINT32 pbContextNdrPtr = 0;
3437 wLog* log = scard_log();
3439 call->pioSendPci =
nullptr;
3440 call->pioRecvPci =
nullptr;
3441 call->pbSendBuffer =
nullptr;
3443 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3445 if (status != SCARD_S_SUCCESS)
3448 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3449 if (status != SCARD_S_SUCCESS)
3452 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 32))
3453 return STATUS_BUFFER_TOO_SMALL;
3455 Stream_Read_UINT32(s, ioSendPci.dwProtocol);
3456 Stream_Read_UINT32(s, ioSendPci.cbExtraBytes);
3457 if (!smartcard_ndr_pointer_read(log, s, &index,
3458 &pbExtraBytesNdrPtr))
3459 return ERROR_INVALID_DATA;
3461 const UINT32 cbSendLength = Stream_Get_UINT32(s);
3462 if (cbSendLength > 66560)
3464 WLog_Print(log, WLOG_ERROR,
"2.2.2.19 Transmit_Call cbSendLength (%" PRIu32
") > 66560",
3466 return SCARD_E_INVALID_PARAMETER;
3468 if (!smartcard_ndr_pointer_read(log, s, &index,
3469 &pbSendBufferNdrPtr))
3470 return ERROR_INVALID_DATA;
3472 if (!smartcard_ndr_pointer_read(log, s, &index,
3474 return ERROR_INVALID_DATA;
3476 Stream_Read_INT32(s, call->fpbRecvBufferIsNULL);
3477 Stream_Read_UINT32(s, call->cbRecvLength);
3479 if (ioSendPci.cbExtraBytes > 1024)
3481 WLog_Print(log, WLOG_WARN,
3482 "Transmit_Call ioSendPci.cbExtraBytes is out of bounds: %" PRIu32
" (max: 1024)",
3483 ioSendPci.cbExtraBytes);
3484 return STATUS_INVALID_PARAMETER;
3487 if (cbSendLength > 66560)
3489 WLog_Print(log, WLOG_WARN,
3490 "Transmit_Call cbSendLength is out of bounds: %" PRIu32
" (max: 66560)",
3491 ioSendPci.cbExtraBytes);
3492 return STATUS_INVALID_PARAMETER;
3495 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3496 &(call->handles.hContext));
3497 if (status != SCARD_S_SUCCESS)
3500 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3501 if (status != SCARD_S_SUCCESS)
3504 if (ioSendPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3508 "Transmit_Call ioSendPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3509 return STATUS_INVALID_PARAMETER;
3512 if (pbExtraBytesNdrPtr)
3515 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3516 return STATUS_BUFFER_TOO_SMALL;
3518 Stream_Read_UINT32(s, length);
3520 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioSendPci.cbExtraBytes))
3521 return STATUS_BUFFER_TOO_SMALL;
3523 ioSendPci.pbExtraBytes = Stream_Pointer(s);
3527 if (!call->pioSendPci)
3529 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3530 return STATUS_NO_MEMORY;
3533 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3534 call->pioSendPci->cbPciLength = (DWORD)(ioSendPci.cbExtraBytes +
sizeof(
SCARD_IO_REQUEST));
3536 Stream_Read(s, pbExtraBytes, ioSendPci.cbExtraBytes);
3537 if (smartcard_unpack_read_size_align(s, ioSendPci.cbExtraBytes, 4) < 0)
3538 return STATUS_INVALID_PARAMETER;
3544 if (!call->pioSendPci)
3546 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3547 return STATUS_NO_MEMORY;
3550 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3554 if (pbSendBufferNdrPtr)
3556 status = smartcard_ndr_read(log, s, &call->pbSendBuffer, cbSendLength, 1, NDR_PTR_SIMPLE);
3557 if (status != SCARD_S_SUCCESS)
3559 call->cbSendLength = cbSendLength;
3562 if (pioRecvPciNdrPtr)
3564 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3565 return STATUS_BUFFER_TOO_SMALL;
3567 Stream_Read_UINT32(s, ioRecvPci.dwProtocol);
3568 Stream_Read_UINT32(s, ioRecvPci.cbExtraBytes);
3569 if (!smartcard_ndr_pointer_read(log, s, &index,
3570 &pbExtraBytesNdrPtr))
3571 return ERROR_INVALID_DATA;
3573 if (ioRecvPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3577 "Transmit_Call ioRecvPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3578 return STATUS_INVALID_PARAMETER;
3581 if (pbExtraBytesNdrPtr)
3584 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3585 return STATUS_BUFFER_TOO_SMALL;
3587 Stream_Read_UINT32(s, length);
3589 if (ioRecvPci.cbExtraBytes > 1024)
3591 WLog_Print(log, WLOG_WARN,
3592 "Transmit_Call ioRecvPci.cbExtraBytes is out of bounds: %" PRIu32
3594 ioRecvPci.cbExtraBytes);
3595 return STATUS_INVALID_PARAMETER;
3598 if (length != ioRecvPci.cbExtraBytes)
3600 WLog_Print(log, WLOG_WARN,
3601 "Transmit_Call unexpected length: Actual: %" PRIu32
3602 ", Expected: %" PRIu32
" (ioRecvPci.cbExtraBytes)",
3603 length, ioRecvPci.cbExtraBytes);
3604 return STATUS_INVALID_PARAMETER;
3607 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioRecvPci.cbExtraBytes))
3608 return STATUS_BUFFER_TOO_SMALL;
3610 ioRecvPci.pbExtraBytes = Stream_Pointer(s);
3614 if (!call->pioRecvPci)
3616 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3617 return STATUS_NO_MEMORY;
3620 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3621 call->pioRecvPci->cbPciLength =
3624 Stream_Read(s, pbExtraBytes, ioRecvPci.cbExtraBytes);
3625 if (smartcard_unpack_read_size_align(s, ioRecvPci.cbExtraBytes, 4) < 0)
3626 return STATUS_INVALID_PARAMETER;
3632 if (!call->pioRecvPci)
3634 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3635 return STATUS_NO_MEMORY;
3638 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3643 smartcard_trace_transmit_call(log, call);
3644 return SCARD_S_SUCCESS;
3650 wLog* log = scard_log();
3655 UINT32 cbRecvLength = ret->cbRecvLength;
3656 UINT32 cbRecvPci = ret->pioRecvPci ? ret->pioRecvPci->cbPciLength : 0;
3658 smartcard_trace_transmit_return(log, ret);
3660 if (!ret->pbRecvBuffer)
3663 if (!smartcard_ndr_pointer_write(s, &index, cbRecvPci))
3664 return SCARD_E_NO_MEMORY;
3665 if (!Stream_EnsureRemainingCapacity(s, 4))
3666 return SCARD_E_NO_MEMORY;
3668 if (cbRecvLength > 66560)
3670 WLog_Print(log, WLOG_ERROR,
"2.2.3.11 Transmit_Return cbRecvLength(%" PRIu32
") > 66560",
3672 return SCARD_E_INVALID_PARAMETER;
3675 Stream_Write_UINT32(s, cbRecvLength);
3676 if (!smartcard_ndr_pointer_write(s, &index, cbRecvLength))
3677 return SCARD_E_NO_MEMORY;
3679 if (ret->pioRecvPci)
3681 UINT32 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
3684 if (!Stream_EnsureRemainingCapacity(s, 8ull))
3686 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3687 return SCARD_F_INTERNAL_ERROR;
3690 Stream_Write_UINT32(s, ret->pioRecvPci->dwProtocol);
3691 Stream_Write_UINT32(s, cbExtraBytes);
3692 if (!smartcard_ndr_pointer_write(s, &index, cbExtraBytes))
3693 return SCARD_E_NO_MEMORY;
3694 error = smartcard_ndr_write(s, pbExtraBytes, cbExtraBytes, 1, NDR_PTR_SIMPLE);
3699 status = smartcard_ndr_write(s, ret->pbRecvBuffer, ret->cbRecvLength, 1, NDR_PTR_SIMPLE);
3700 if (status != SCARD_S_SUCCESS)
3702 return ret->ReturnCode;
3707 UINT32 rgReaderStatesNdrPtr = 0;
3708 UINT32 rgAtrMasksNdrPtr = 0;
3710 UINT32 pbContextNdrPtr = 0;
3713 wLog* log = scard_log();
3715 call->rgReaderStates =
nullptr;
3717 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3719 if (status != SCARD_S_SUCCESS)
3722 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3723 return STATUS_BUFFER_TOO_SMALL;
3725 Stream_Read_UINT32(s, call->cAtrs);
3726 if (call->cAtrs > 1000)
3728 WLog_Print(log, WLOG_ERROR,
"2.2.2.23 LocateCardsByATRA_Call cAtrs(%" PRIu32
") > 1000",
3730 return SCARD_E_INVALID_PARAMETER;
3733 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3734 return ERROR_INVALID_DATA;
3735 const UINT32 cReaders = Stream_Get_UINT32(s);
3738 WLog_Print(log, WLOG_ERROR,
"2.2.2.23 LocateCardsByATRA_Call cReaders(%" PRIu32
") > 10",
3740 return SCARD_E_INVALID_PARAMETER;
3742 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3743 return ERROR_INVALID_DATA;
3745 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3746 &(call->handles.hContext));
3747 if (status != SCARD_S_SUCCESS)
3750 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3752 WLog_Print(log, WLOG_WARN,
3753 "LocateCardsByATRA_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3754 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3755 rgAtrMasksNdrPtr, call->cAtrs);
3756 return STATUS_INVALID_PARAMETER;
3759 if (rgAtrMasksNdrPtr)
3761 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3762 if (status != SCARD_S_SUCCESS)
3766 if (rgReaderStatesNdrPtr)
3768 status = smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, cReaders, &index);
3769 if (status != SCARD_S_SUCCESS)
3771 call->cReaders = cReaders;
3774 smartcard_trace_locate_cards_by_atr_a_call(log, call);
3775 return SCARD_S_SUCCESS;
3780 UINT32 sz1NdrPtr = 0;
3781 UINT32 sz2NdrPtr = 0;
3783 UINT32 pbContextNdrPtr = 0;
3786 wLog* log = scard_log();
3788 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3790 if (status != SCARD_S_SUCCESS)
3793 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3794 return ERROR_INVALID_DATA;
3795 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3796 return ERROR_INVALID_DATA;
3799 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3800 if (status != SCARD_S_SUCCESS)
3805 status = smartcard_ndr_read_a(log, s, &call->sz1, NDR_PTR_FULL);
3806 if (status != SCARD_S_SUCCESS)
3811 status = smartcard_ndr_read_a(log, s, &call->sz2, NDR_PTR_FULL);
3812 if (status != SCARD_S_SUCCESS)
3815 smartcard_trace_context_and_two_strings_a_call(log, call);
3816 return SCARD_S_SUCCESS;
3821 UINT32 sz1NdrPtr = 0;
3822 UINT32 sz2NdrPtr = 0;
3824 UINT32 pbContextNdrPtr = 0;
3827 wLog* log = scard_log();
3829 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3831 if (status != SCARD_S_SUCCESS)
3834 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3835 return ERROR_INVALID_DATA;
3836 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3837 return ERROR_INVALID_DATA;
3840 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3841 if (status != SCARD_S_SUCCESS)
3846 status = smartcard_ndr_read_w(log, s, &call->sz1, NDR_PTR_FULL);
3847 if (status != SCARD_S_SUCCESS)
3852 status = smartcard_ndr_read_w(log, s, &call->sz2, NDR_PTR_FULL);
3853 if (status != SCARD_S_SUCCESS)
3856 smartcard_trace_context_and_two_strings_w_call(log, call);
3857 return SCARD_S_SUCCESS;
3862 UINT32 sz1NdrPtr = 0;
3863 UINT32 sz2NdrPtr = 0;
3865 UINT32 pbContextNdrPtr = 0;
3868 wLog* log = scard_log();
3870 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3872 if (status != SCARD_S_SUCCESS)
3875 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3876 return STATUS_BUFFER_TOO_SMALL;
3878 const UINT32 cBytes = Stream_Get_UINT32(s);
3879 if (call->cBytes > 65536)
3881 WLog_Print(log, WLOG_ERROR,
"2.2.2.9 LocateCardsA_Call cBytes(%" PRIu32
") > 65536",
3883 return SCARD_E_INVALID_PARAMETER;
3886 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3887 return ERROR_INVALID_DATA;
3889 const UINT32 cReaders = Stream_Get_UINT32(s);
3892 WLog_Print(log, WLOG_ERROR,
"2.2.2.9 LocateCardsA_Call cReaders(%" PRIu32
") > 10",
3894 return SCARD_E_INVALID_PARAMETER;
3896 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3897 return ERROR_INVALID_DATA;
3899 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3900 &(call->handles.hContext));
3901 if (status != SCARD_S_SUCCESS)
3906 status = smartcard_ndr_read_fixed_string_a(log, s, &call->mszCards, cBytes, NDR_PTR_SIMPLE);
3907 if (status != SCARD_S_SUCCESS)
3909 call->cBytes = cBytes;
3913 status = smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, cReaders, &index);
3914 if (status != SCARD_S_SUCCESS)
3916 call->cReaders = cReaders;
3918 smartcard_trace_locate_cards_a_call(log, call);
3919 return SCARD_S_SUCCESS;
3924 UINT32 sz1NdrPtr = 0;
3925 UINT32 sz2NdrPtr = 0;
3927 UINT32 pbContextNdrPtr = 0;
3930 wLog* log = scard_log();
3932 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3934 if (status != SCARD_S_SUCCESS)
3937 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3938 return STATUS_BUFFER_TOO_SMALL;
3940 const UINT32 cBytes = Stream_Get_UINT32(s);
3941 if (call->cBytes > 65536)
3943 WLog_Print(log, WLOG_ERROR,
"2.2.2.10 LocateCardsW_Call cBytes(%" PRIu32
") > 65536",
3945 return SCARD_E_INVALID_PARAMETER;
3948 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3949 return ERROR_INVALID_DATA;
3951 const UINT32 cReaders = Stream_Get_UINT32(s);
3954 WLog_Print(log, WLOG_ERROR,
"2.2.2.10 LocateCardsW_Call cReaders(%" PRIu32
") > 10",
3956 return SCARD_E_INVALID_PARAMETER;
3959 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3960 return ERROR_INVALID_DATA;
3962 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3963 &(call->handles.hContext));
3964 if (status != SCARD_S_SUCCESS)
3969 status = smartcard_ndr_read_fixed_string_w(log, s, &call->mszCards, cBytes, NDR_PTR_SIMPLE);
3970 if (status != SCARD_S_SUCCESS)
3972 call->cBytes = cBytes;
3976 status = smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, cReaders, &index);
3977 if (status != SCARD_S_SUCCESS)
3979 call->cReaders = cReaders;
3981 smartcard_trace_locate_cards_w_call(log, call);
3982 return SCARD_S_SUCCESS;
3989 UINT32 pbContextNdrPtr = 0;
3992 wLog* log = scard_log();
3994 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3996 if (status != SCARD_S_SUCCESS)
3998 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3999 if (status != SCARD_S_SUCCESS)
4002 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
4003 return STATUS_BUFFER_TOO_SMALL;
4004 Stream_Read_UINT32(s, call->dwAttrId);
4005 Stream_Read_UINT32(s, call->cbAttrLen);
4006 if (call->cbAttrLen > 65536)
4008 WLog_Print(log, WLOG_ERROR,
"2.2.2.22 SetAttrib_Call call->cbAttrLen (%" PRIu32
") > 65536",
4010 return SCARD_E_INVALID_PARAMETER;
4013 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
4014 return ERROR_INVALID_DATA;
4016 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4017 &(call->handles.hContext));
4018 if (status != SCARD_S_SUCCESS)
4021 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
4022 if (status != SCARD_S_SUCCESS)
4028 status = smartcard_ndr_read_ex(log, s, &call->pbAttr, 0, 1, NDR_PTR_SIMPLE, &len);
4029 if (status != SCARD_S_SUCCESS)
4031 if (call->cbAttrLen > len)
4032 call->cbAttrLen = WINPR_ASSERTING_INT_CAST(DWORD, len);
4035 call->cbAttrLen = 0;
4036 smartcard_trace_set_attrib_call(log, call);
4037 return SCARD_S_SUCCESS;
4043 wLog* log = scard_log();
4046 smartcard_trace_set_attrib_call(log, call);
4048 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4049 if (status != SCARD_S_SUCCESS)
4052 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
4053 if (status != SCARD_S_SUCCESS)
4056 if (!Stream_EnsureRemainingCapacity(s, 8))
4057 return SCARD_E_NO_MEMORY;
4059 Stream_Write_UINT32(s, call->dwAttrId);
4060 Stream_Write_UINT32(s, call->cbAttrLen);
4062 if (!smartcard_ndr_pointer_write(s, &index, call->cbAttrLen))
4063 return SCARD_E_NO_MEMORY;
4065 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4066 if (status != SCARD_S_SUCCESS)
4069 status = smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
4070 if (status != SCARD_S_SUCCESS)
4073 status = smartcard_ndr_write(s, call->pbAttr, call->cbAttrLen, 1, NDR_PTR_SIMPLE);
4074 if (status != SCARD_S_SUCCESS)
4077 return SCARD_S_SUCCESS;
4082 UINT32 rgReaderStatesNdrPtr = 0;
4083 UINT32 rgAtrMasksNdrPtr = 0;
4085 UINT32 pbContextNdrPtr = 0;
4088 wLog* log = scard_log();
4090 call->rgReaderStates =
nullptr;
4092 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
4094 if (status != SCARD_S_SUCCESS)
4097 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
4098 return STATUS_BUFFER_TOO_SMALL;
4100 Stream_Read_UINT32(s, call->cAtrs);
4101 if (call->cAtrs > 1000)
4103 WLog_Print(log, WLOG_ERROR,
"2.2.2.24 LocateCardsByATRW_Call cAtrs(%" PRIu32
") > 1000",
4105 return SCARD_E_INVALID_PARAMETER;
4108 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
4109 return ERROR_INVALID_DATA;
4111 const UINT32 cReaders = Stream_Get_UINT32(s);
4114 WLog_Print(log, WLOG_ERROR,
"2.2.2.24 LocateCardsByATRW_Call cReaders(%" PRIu32
") > 10",
4116 return SCARD_E_INVALID_PARAMETER;
4118 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
4119 return ERROR_INVALID_DATA;
4121 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4122 &(call->handles.hContext));
4123 if (status != SCARD_S_SUCCESS)
4126 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
4128 WLog_Print(log, WLOG_WARN,
4129 "LocateCardsByATRW_Call rgAtrMasksNdrPtr (0x%08" PRIX32
4130 ") and cAtrs (0x%08" PRIX32
") inconsistency",
4131 rgAtrMasksNdrPtr, call->cAtrs);
4132 return STATUS_INVALID_PARAMETER;
4135 if (rgAtrMasksNdrPtr)
4137 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
4138 if (status != SCARD_S_SUCCESS)
4142 if (rgReaderStatesNdrPtr)
4144 status = smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, cReaders, &index);
4145 if (status != SCARD_S_SUCCESS)
4147 call->cReaders = cReaders;
4150 smartcard_trace_locate_cards_by_atr_w_call(log, call);
4151 return SCARD_S_SUCCESS;
4156 UINT32 mszNdrPtr = 0;
4157 UINT32 contextNdrPtr = 0;
4159 UINT32 pbContextNdrPtr = 0;
4162 wLog* log = scard_log();
4164 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
4165 return ERROR_INVALID_DATA;
4167 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
4168 &index, &pbContextNdrPtr);
4169 if (status != SCARD_S_SUCCESS)
4172 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
4173 return ERROR_INVALID_DATA;
4175 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
4176 return STATUS_BUFFER_TOO_SMALL;
4177 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
4178 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
4179 Stream_Read_UINT32(s, call->Common.cbDataLen);
4181 call->szLookupName =
nullptr;
4184 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
4185 if (status != SCARD_S_SUCCESS)
4189 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4190 &call->Common.handles.hContext);
4191 if (status != SCARD_S_SUCCESS)
4196 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
4197 if (status != SCARD_S_SUCCESS)
4200 smartcard_trace_read_cache_a_call(log, call);
4201 return SCARD_S_SUCCESS;
4206 UINT32 mszNdrPtr = 0;
4207 UINT32 contextNdrPtr = 0;
4209 UINT32 pbContextNdrPtr = 0;
4212 wLog* log = scard_log();
4214 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
4215 return ERROR_INVALID_DATA;
4217 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
4218 &index, &pbContextNdrPtr);
4219 if (status != SCARD_S_SUCCESS)
4222 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
4223 return ERROR_INVALID_DATA;
4225 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
4226 return STATUS_BUFFER_TOO_SMALL;
4227 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
4228 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
4229 Stream_Read_UINT32(s, call->Common.cbDataLen);
4231 call->szLookupName =
nullptr;
4234 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
4235 if (status != SCARD_S_SUCCESS)
4239 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4240 &call->Common.handles.hContext);
4241 if (status != SCARD_S_SUCCESS)
4246 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
4247 if (status != SCARD_S_SUCCESS)
4250 smartcard_trace_read_cache_w_call(log, call);
4251 return SCARD_S_SUCCESS;
4256 UINT32 mszNdrPtr = 0;
4257 UINT32 contextNdrPtr = 0;
4258 UINT32 pbDataNdrPtr = 0;
4260 UINT32 pbContextNdrPtr = 0;
4263 wLog* log = scard_log();
4265 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
4266 return ERROR_INVALID_DATA;
4268 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
4269 &index, &pbContextNdrPtr);
4270 if (status != SCARD_S_SUCCESS)
4273 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
4274 return ERROR_INVALID_DATA;
4276 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
4277 return STATUS_BUFFER_TOO_SMALL;
4279 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
4280 const UINT32 cbDataLen = Stream_Get_UINT32(s);
4281 if (cbDataLen > 65536)
4283 WLog_Print(log, WLOG_ERROR,
"2.2.1.10 WriteCache_Common cbDataLen(%" PRIu32
") > 65536",
4285 return ERROR_INVALID_DATA;
4288 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
4289 return ERROR_INVALID_DATA;
4291 call->szLookupName =
nullptr;
4294 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
4295 if (status != SCARD_S_SUCCESS)
4299 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4300 &call->Common.handles.hContext);
4301 if (status != SCARD_S_SUCCESS)
4304 call->Common.CardIdentifier =
nullptr;
4307 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
4308 if (status != SCARD_S_SUCCESS)
4312 call->Common.pbData =
nullptr;
4315 status = smartcard_ndr_read(log, s, &call->Common.pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
4316 if (status != SCARD_S_SUCCESS)
4318 call->Common.cbDataLen = cbDataLen;
4320 smartcard_trace_write_cache_a_call(log, call);
4321 return SCARD_S_SUCCESS;
4326 UINT32 mszNdrPtr = 0;
4327 UINT32 contextNdrPtr = 0;
4328 UINT32 pbDataNdrPtr = 0;
4330 UINT32 pbContextNdrPtr = 0;
4333 wLog* log = scard_log();
4335 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
4336 return ERROR_INVALID_DATA;
4338 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
4339 &index, &pbContextNdrPtr);
4340 if (status != SCARD_S_SUCCESS)
4343 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
4344 return ERROR_INVALID_DATA;
4346 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
4347 return STATUS_BUFFER_TOO_SMALL;
4348 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
4349 const UINT32 cbDataLen = Stream_Get_UINT32(s);
4351 if (cbDataLen > 65536)
4353 WLog_Print(log, WLOG_ERROR,
"2.2.1.10 WriteCache_Common cbDataLen(%" PRIu32
") > 65536",
4355 return ERROR_INVALID_DATA;
4358 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
4359 return ERROR_INVALID_DATA;
4361 call->szLookupName =
nullptr;
4364 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
4365 if (status != SCARD_S_SUCCESS)
4369 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4370 &call->Common.handles.hContext);
4371 if (status != SCARD_S_SUCCESS)
4374 call->Common.CardIdentifier =
nullptr;
4377 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
4378 if (status != SCARD_S_SUCCESS)
4382 call->Common.pbData =
nullptr;
4385 status = smartcard_ndr_read(log, s, &call->Common.pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
4386 if (status != SCARD_S_SUCCESS)
4388 call->Common.cbDataLen = cbDataLen;
4390 smartcard_trace_write_cache_w_call(log, call);
4397 wLog* log = scard_log();
4400 UINT32 pbContextNdrPtr = 0;
4402 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
4404 if (status != SCARD_S_SUCCESS)
4407 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
4408 if (status != SCARD_S_SUCCESS)
4411 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4412 &(call->handles.hContext));
4413 if (status != SCARD_S_SUCCESS)
4415 WLog_Print(log, WLOG_ERROR,
4416 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
4421 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
4422 if (status != SCARD_S_SUCCESS)
4423 WLog_Print(log, WLOG_ERROR,
4424 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
4426 smartcard_trace_get_transmit_count_call(log, call);
4433 wLog* log = scard_log();
4434 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
4435 &call->szReaderName);
4441 wLog* log = scard_log();
4442 return smartcard_unpack_common_context_and_string_a(log, s, &call->handles.hContext, &call->sz);
4448 wLog* log = scard_log();
4449 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext, &call->sz);
4455 wLog* log = scard_log();
4456 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
4457 &call->szReaderName);
4463 wLog* log = scard_log();
4464 smartcard_trace_device_type_id_return(log, ret);
4466 if (!Stream_EnsureRemainingCapacity(s, 4))
4468 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4469 return SCARD_F_INTERNAL_ERROR;
4472 Stream_Write_UINT32(s, ret->dwDeviceId);
4474 return ret->ReturnCode;
4480 wLog* log = scard_log();
4483 UINT32 cbDataLen = ret->cReaders;
4486 smartcard_trace_locate_cards_return(log, ret);
4487 if (ret->ReturnCode != SCARD_S_SUCCESS)
4489 if (cbDataLen == SCARD_AUTOALLOCATE)
4492 if (!Stream_EnsureRemainingCapacity(s, 4))
4494 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4495 return SCARD_F_INTERNAL_ERROR;
4498 if (ret->cReaders > 10)
4500 WLog_Print(log, WLOG_ERROR,
4501 "2.2.3.5 LocateCards_Return and GetStatusChange_Return cReaders(%" PRIu32
4504 return SCARD_E_INVALID_PARAMETER;
4507 Stream_Write_UINT32(s, cbDataLen);
4508 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
4509 return SCARD_E_NO_MEMORY;
4511 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cbDataLen, NDR_PTR_SIMPLE);
4512 if (status != SCARD_S_SUCCESS)
4514 return ret->ReturnCode;
4520 wLog* log = scard_log();
4524 UINT32 cbDataLen = ret->cbDataLen;
4525 smartcard_trace_get_reader_icon_return(log, ret);
4526 if (ret->ReturnCode != SCARD_S_SUCCESS)
4528 if (cbDataLen == SCARD_AUTOALLOCATE)
4531 if (!Stream_EnsureRemainingCapacity(s, 4))
4533 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4534 return SCARD_F_INTERNAL_ERROR;
4537 Stream_Write_UINT32(s, cbDataLen);
4538 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
4539 return SCARD_E_NO_MEMORY;
4541 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
4542 if (status != SCARD_S_SUCCESS)
4544 return ret->ReturnCode;
4550 wLog* log = scard_log();
4552 smartcard_trace_get_transmit_count_return(log, ret);
4554 if (!Stream_EnsureRemainingCapacity(s, 4))
4556 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4557 return SCARD_F_INTERNAL_ERROR;
4560 Stream_Write_UINT32(s, ret->cTransmitCount);
4562 return ret->ReturnCode;
4568 wLog* log = scard_log();
4572 UINT32 cbDataLen = ret->cbDataLen;
4573 smartcard_trace_read_cache_return(log, ret);
4574 if (ret->ReturnCode != SCARD_S_SUCCESS)
4577 if (cbDataLen == SCARD_AUTOALLOCATE)
4580 if (!Stream_EnsureRemainingCapacity(s, 4))
4582 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4583 return SCARD_F_INTERNAL_ERROR;
4586 if (cbDataLen > 65536)
4588 WLog_Print(log, WLOG_ERROR,
"2.2.3.1 ReadCache_Return cbDataLen (%" PRIu32
") > 65536",
4590 return SCARD_E_INVALID_PARAMETER;
4593 Stream_Write_UINT32(s, cbDataLen);
4594 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
4595 return SCARD_E_NO_MEMORY;
4597 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
4598 if (status != SCARD_S_SUCCESS)
4600 return ret->ReturnCode;
4606 wLog* log = scard_log();
4609 smartcard_trace_context_call(log, call, name);
4611 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4612 if (status != SCARD_S_SUCCESS)
4615 return smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4621 wLog* log = scard_log();
4624 smartcard_trace_list_readers_call(log, call, unicode);
4626 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4627 if (status != SCARD_S_SUCCESS)
4630 if (!Stream_EnsureRemainingCapacity(s, 4))
4631 return SCARD_E_NO_MEMORY;
4633 Stream_Write_UINT32(s, call->cBytes);
4634 if (call->cBytes > 65536)
4636 WLog_Print(log, WLOG_ERROR,
"2.2.2.4 ListReaders_Call cBytes(%" PRIu32
") > 65536",
4638 return SCARD_E_INVALID_PARAMETER;
4641 if (!smartcard_ndr_pointer_write(s, &index, call->cBytes))
4642 return SCARD_E_NO_MEMORY;
4644 if (!Stream_EnsureRemainingCapacity(s, 8))
4645 return SCARD_E_NO_MEMORY;
4647 Stream_Write_INT32(s, call->fmszReadersIsNULL);
4648 Stream_Write_UINT32(s, call->cchReaders);
4650 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4651 if (status != SCARD_S_SUCCESS)
4654 if (call->cBytes > 0)
4656 status = smartcard_ndr_write(s, call->mszGroups, call->cBytes, 1, NDR_PTR_SIMPLE);
4657 if (status != SCARD_S_SUCCESS)
4661 return SCARD_S_SUCCESS;
4664WINPR_ATTR_NODISCARD
static LONG
4666 UINT32 cReaders, UINT32* ptrIndex)
4668 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
4670 if (!Stream_EnsureRemainingCapacity(s, 4))
4671 return SCARD_E_NO_MEMORY;
4673 Stream_Write_UINT32(s, cReaders);
4675 for (UINT32 i = 0; i < cReaders; i++)
4679 if (!Stream_EnsureRemainingCapacity(s, 52))
4680 return SCARD_E_NO_MEMORY;
4682 const UINT32 nameLen = state->szReader ? (UINT32)(strlen(state->szReader) + 1) : 0;
4683 if (!smartcard_ndr_pointer_write(s, ptrIndex, nameLen))
4684 return SCARD_E_NO_MEMORY;
4686 Stream_Write_UINT32(s, state->dwCurrentState);
4687 Stream_Write_UINT32(s, state->dwEventState);
4688 if (state->cbAtr > 36)
4690 WLog_Print(log, WLOG_WARN,
"2.2.2.12 GetStatusChangeW_Call cbAtr(%" PRIu32
") > 36",
4692 return SCARD_E_INVALID_PARAMETER;
4694 Stream_Write_UINT32(s, state->cbAtr);
4695 Stream_Write(s, state->rgbAtr, 36);
4698 for (UINT32 i = 0; i < cReaders; i++)
4702 if (state->szReader)
4704 const UINT32 nameLen = (UINT32)(strlen(state->szReader) + 1);
4705 LONG status = smartcard_ndr_write_a(s, state->szReader, nameLen, NDR_PTR_FULL);
4706 if (status != SCARD_S_SUCCESS)
4711 return SCARD_S_SUCCESS;
4714WINPR_ATTR_NODISCARD
static LONG
4716 UINT32 cReaders, UINT32* ptrIndex)
4718 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
4720 if (!Stream_EnsureRemainingCapacity(s, 4))
4721 return SCARD_E_NO_MEMORY;
4723 Stream_Write_UINT32(s, cReaders);
4725 for (UINT32 i = 0; i < cReaders; i++)
4729 if (!Stream_EnsureRemainingCapacity(s, 52))
4730 return SCARD_E_NO_MEMORY;
4732 const UINT32 nameLen = state->szReader ? (UINT32)(_wcslen(state->szReader) + 1) : 0;
4733 if (!smartcard_ndr_pointer_write(s, ptrIndex, nameLen))
4734 return SCARD_E_NO_MEMORY;
4736 Stream_Write_UINT32(s, state->dwCurrentState);
4737 Stream_Write_UINT32(s, state->dwEventState);
4738 if (state->cbAtr > 36)
4740 WLog_Print(log, WLOG_WARN,
"2.2.2.12 GetStatusChangeW_Call cbAtr(%" PRIu32
") > 36",
4742 return SCARD_E_INVALID_PARAMETER;
4744 Stream_Write_UINT32(s, state->cbAtr);
4745 Stream_Write(s, state->rgbAtr, 36);
4748 for (UINT32 i = 0; i < cReaders; i++)
4752 if (state->szReader)
4754 const UINT32 nameLen = (UINT32)(_wcslen(state->szReader) + 1);
4755 LONG status = smartcard_ndr_write_w(s, state->szReader, nameLen, NDR_PTR_FULL);
4756 if (status != SCARD_S_SUCCESS)
4761 return SCARD_S_SUCCESS;
4767 wLog* log = scard_log();
4770 smartcard_trace_get_status_change_a_call(log, call);
4772 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4773 if (status != SCARD_S_SUCCESS)
4776 if (!Stream_EnsureRemainingCapacity(s, 8))
4777 return SCARD_E_NO_MEMORY;
4779 Stream_Write_UINT32(s, call->dwTimeOut);
4780 Stream_Write_UINT32(s, call->cReaders);
4781 if (call->cReaders > 11)
4783 WLog_Print(log, WLOG_ERROR,
"2.2.2.11 GetStatusChangeA_Call cReaders (%" PRIu32
") > 11",
4785 return SCARD_E_INVALID_PARAMETER;
4787 if (!smartcard_ndr_pointer_write(s, &index, call->cReaders))
4788 return SCARD_E_NO_MEMORY;
4790 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4791 if (status != SCARD_S_SUCCESS)
4794 if (call->cReaders > 0)
4797 smartcard_pack_reader_state_a(log, s, call->rgReaderStates, call->cReaders, &index);
4798 if (status != SCARD_S_SUCCESS)
4802 return SCARD_S_SUCCESS;
4808 wLog* log = scard_log();
4811 smartcard_trace_get_status_change_w_call(log, call);
4813 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4814 if (status != SCARD_S_SUCCESS)
4817 if (!Stream_EnsureRemainingCapacity(s, 8))
4818 return SCARD_E_NO_MEMORY;
4820 Stream_Write_UINT32(s, call->dwTimeOut);
4821 Stream_Write_UINT32(s, call->cReaders);
4822 if (call->cReaders > 11)
4824 WLog_Print(log, WLOG_ERROR,
"2.2.2.12 GetStatusChangeW_Call cReaders (%" PRIu32
") > 11",
4826 return SCARD_E_INVALID_PARAMETER;
4829 if (!smartcard_ndr_pointer_write(s, &index, call->cReaders))
4830 return SCARD_E_NO_MEMORY;
4832 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4833 if (status != SCARD_S_SUCCESS)
4836 if (call->cReaders > 0)
4839 smartcard_pack_reader_state_w(log, s, call->rgReaderStates, call->cReaders, &index);
4840 if (status != SCARD_S_SUCCESS)
4844 return SCARD_S_SUCCESS;
4850 wLog* log = scard_log();
4853 smartcard_trace_connect_a_call(log, call);
4855 const UINT32 readerLen = call->szReader ? (UINT32)(strlen(call->szReader) + 1) : 0;
4856 if (!smartcard_ndr_pointer_write(s, &index, readerLen))
4857 return SCARD_E_NO_MEMORY;
4860 smartcard_pack_redir_scard_context(log, s, &call->Common.handles.hContext, &index);
4861 if (status != SCARD_S_SUCCESS)
4864 if (!Stream_EnsureRemainingCapacity(s, 8))
4865 return SCARD_E_NO_MEMORY;
4867 Stream_Write_UINT32(s, call->Common.dwShareMode);
4868 Stream_Write_UINT32(s, call->Common.dwPreferredProtocols);
4872 status = smartcard_ndr_write_a(s, call->szReader, readerLen, NDR_PTR_FULL);
4873 if (status != SCARD_S_SUCCESS)
4877 return smartcard_pack_redir_scard_context_ref(log, s, &call->Common.handles.hContext);
4883 wLog* log = scard_log();
4886 smartcard_trace_connect_w_call(log, call);
4888 const UINT32 readerLen = call->szReader ? (UINT32)(_wcslen(call->szReader) + 1) : 0;
4889 if (!smartcard_ndr_pointer_write(s, &index, readerLen))
4890 return SCARD_E_NO_MEMORY;
4893 smartcard_pack_redir_scard_context(log, s, &call->Common.handles.hContext, &index);
4894 if (status != SCARD_S_SUCCESS)
4897 if (!Stream_EnsureRemainingCapacity(s, 8))
4898 return SCARD_E_NO_MEMORY;
4900 Stream_Write_UINT32(s, call->Common.dwShareMode);
4901 Stream_Write_UINT32(s, call->Common.dwPreferredProtocols);
4905 status = smartcard_ndr_write_w(s, call->szReader, readerLen, NDR_PTR_FULL);
4906 if (status != SCARD_S_SUCCESS)
4910 return smartcard_pack_redir_scard_context_ref(log, s, &call->Common.handles.hContext);
4916 wLog* log = scard_log();
4919 smartcard_trace_control_call(log, call);
4921 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4922 if (status != SCARD_S_SUCCESS)
4925 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
4926 if (status != SCARD_S_SUCCESS)
4929 if (!Stream_EnsureRemainingCapacity(s, 8))
4930 return SCARD_E_NO_MEMORY;
4932 Stream_Write_UINT32(s, call->dwControlCode);
4933 Stream_Write_UINT32(s, call->cbInBufferSize);
4934 if (!smartcard_ndr_pointer_write(s, &index, call->cbInBufferSize))
4935 return SCARD_E_NO_MEMORY;
4937 Stream_Write_INT32(s, call->fpvOutBufferIsNULL);
4938 Stream_Write_UINT32(s, call->cbOutBufferSize);
4940 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4941 if (status != SCARD_S_SUCCESS)
4944 status = smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
4945 if (status != SCARD_S_SUCCESS)
4948 if (call->cbInBufferSize)
4950 status = smartcard_ndr_write(s, call->pvInBuffer, call->cbInBufferSize, 1, NDR_PTR_SIMPLE);
4951 if (status != SCARD_S_SUCCESS)
4962 wLog* log = scard_log();
4965 smartcard_trace_hcard_and_disposition_call(log, call, name);
4967 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4968 if (status != SCARD_S_SUCCESS)
4971 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
4972 if (status != SCARD_S_SUCCESS)
4975 if (!Stream_EnsureRemainingCapacity(s, 4))
4976 return SCARD_E_NO_MEMORY;
4978 Stream_Write_UINT32(s, call->dwDisposition);
4980 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4981 if (status != SCARD_S_SUCCESS)
4984 return smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
4990 wLog* log = scard_log();
4993 smartcard_trace_transmit_call(log, call);
4995 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4996 if (status != SCARD_S_SUCCESS)
4999 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
5000 if (status != SCARD_S_SUCCESS)
5003 UINT32 cbExtraBytes = 0;
5004 const BYTE* pbExtraBytes =
nullptr;
5005 if (call->pioSendPci)
5007 cbExtraBytes = (UINT32)(call->pioSendPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
5008 if (cbExtraBytes > 0)
5012 if (!Stream_EnsureRemainingCapacity(s, 32))
5013 return SCARD_E_NO_MEMORY;
5015 Stream_Write_UINT32(s, call->pioSendPci ? call->pioSendPci->dwProtocol : 0);
5016 Stream_Write_UINT32(s, cbExtraBytes);
5017 if (!smartcard_ndr_pointer_write(s, &index, cbExtraBytes))
5018 return SCARD_E_NO_MEMORY;
5020 Stream_Write_UINT32(s, call->cbSendLength);
5021 if (!smartcard_ndr_pointer_write(s, &index, call->cbSendLength))
5022 return SCARD_E_NO_MEMORY;
5024 const UINT32 recvPciLen = call->pioRecvPci ? (UINT32)call->pioRecvPci->cbPciLength : 0;
5025 if (!smartcard_ndr_pointer_write(s, &index, recvPciLen))
5026 return SCARD_E_NO_MEMORY;
5028 Stream_Write_INT32(s, call->fpbRecvBufferIsNULL);
5029 Stream_Write_UINT32(s, call->cbRecvLength);
5031 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
5032 if (status != SCARD_S_SUCCESS)
5035 status = smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
5036 if (status != SCARD_S_SUCCESS)
5039 if (cbExtraBytes > 0)
5041 status = smartcard_ndr_write(s, pbExtraBytes, cbExtraBytes, 1, NDR_PTR_SIMPLE);
5042 if (status != SCARD_S_SUCCESS)
5046 if (call->cbSendLength > 0)
5048 status = smartcard_ndr_write(s, call->pbSendBuffer, call->cbSendLength, 1, NDR_PTR_SIMPLE);
5049 if (status != SCARD_S_SUCCESS)
5053 if (call->pioRecvPci && recvPciLen > 0)
5055 UINT32 cbRecvExtra = (UINT32)(call->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
5056 const BYTE* pbRecvExtra = &((
const BYTE*)call->pioRecvPci)[
sizeof(
SCARD_IO_REQUEST)];
5058 if (!Stream_EnsureRemainingCapacity(s, 12))
5059 return SCARD_E_NO_MEMORY;
5061 Stream_Write_UINT32(s, call->pioRecvPci->dwProtocol);
5062 Stream_Write_UINT32(s, cbRecvExtra);
5063 if (!smartcard_ndr_pointer_write(s, &index, cbRecvExtra))
5064 return SCARD_E_NO_MEMORY;
5066 if (cbRecvExtra > 0)
5068 status = smartcard_ndr_write(s, pbRecvExtra, cbRecvExtra, 1, NDR_PTR_SIMPLE);
5069 if (status != SCARD_S_SUCCESS)
5074 return SCARD_S_SUCCESS;
5080 wLog* log = scard_log();
5083 smartcard_trace_get_attrib_call(log, call);
5085 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
5086 if (status != SCARD_S_SUCCESS)
5089 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
5090 if (status != SCARD_S_SUCCESS)
5093 if (!Stream_EnsureRemainingCapacity(s, 12))
5094 return STATUS_NO_MEMORY;
5096 Stream_Write_UINT32(s, call->dwAttrId);
5097 Stream_Write_INT32(s, call->fpbAttrIsNULL);
5098 Stream_Write_UINT32(s, call->cbAttrLen);
5100 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
5101 if (status != SCARD_S_SUCCESS)
5104 return smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
5110 wLog* log = scard_log();
5112 UINT32 mszNdrPtr = 0;
5114 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
5115 return STATUS_BUFFER_TOO_SMALL;
5117 const UINT32 cBytes = Stream_Get_UINT32(s);
5119 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
5120 return ERROR_INVALID_DATA;
5124 LONG status = smartcard_ndr_read(log, s, &ret->msz, cBytes, 1, NDR_PTR_SIMPLE);
5125 if (status != SCARD_S_SUCCESS)
5127 ret->cBytes = cBytes;
5130 smartcard_trace_list_readers_return(log, ret, unicode);
5131 return SCARD_S_SUCCESS;
5138 wLog* log = scard_log();
5142 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
5143 return STATUS_BUFFER_TOO_SMALL;
5145 Stream_Read_UINT32(s, ret->cReaders);
5146 if (ret->cReaders > 10)
5148 WLog_Print(log, WLOG_ERROR,
5149 "2.2.3.5 LocateCards_Return and GetStatusChange_Return cReaders(%" PRIu32
5152 return SCARD_E_INVALID_PARAMETER;
5155 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
5156 return ERROR_INVALID_DATA;
5158 if (ndrPtr && ret->cReaders > 0)
5161 smartcard_ndr_read_state(log, s, &ret->rgReaderStates, ret->cReaders, NDR_PTR_SIMPLE);
5162 if (status != SCARD_S_SUCCESS)
5166 ret->rgReaderStates =
nullptr;
5168 smartcard_trace_get_status_change_return(log, ret, unicode);
5169 return SCARD_S_SUCCESS;
5175 wLog* log = scard_log();
5177 UINT32 pbContextNdrPtr = 0;
5180 smartcard_unpack_redir_scard_context(log, s, &ret->hContext, &index, &pbContextNdrPtr);
5181 if (status != SCARD_S_SUCCESS)
5184 status = smartcard_unpack_redir_scard_handle(log, s, &ret->hCard, &index);
5185 if (status != SCARD_S_SUCCESS)
5188 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
5189 return STATUS_BUFFER_TOO_SMALL;
5191 Stream_Read_UINT32(s, ret->dwActiveProtocol);
5193 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &ret->hContext);
5194 if (status != SCARD_S_SUCCESS)
5197 status = smartcard_unpack_redir_scard_handle_ref(log, s, &ret->hCard);
5198 if (status != SCARD_S_SUCCESS)
5201 smartcard_trace_connect_return(log, ret);
5202 return SCARD_S_SUCCESS;
5208 wLog* log = scard_log();
5210 UINT32 pvOutBufferNdrPtr = 0;
5212 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
5213 return STATUS_BUFFER_TOO_SMALL;
5215 const UINT32 cbOutBufferSize = Stream_Get_UINT32(s);
5217 if (!smartcard_ndr_pointer_read(log, s, &index, &pvOutBufferNdrPtr))
5218 return ERROR_INVALID_DATA;
5220 if (pvOutBufferNdrPtr && (cbOutBufferSize > 0))
5223 smartcard_ndr_read(log, s, &ret->pvOutBuffer, cbOutBufferSize, 1, NDR_PTR_SIMPLE);
5224 if (status != SCARD_S_SUCCESS)
5226 ret->cbOutBufferSize = cbOutBufferSize;
5228 smartcard_trace_control_return(log, ret);
5229 return SCARD_S_SUCCESS;
5235 wLog* log = scard_log();
5237 UINT32 recvPciNdrPtr = 0;
5238 UINT32 recvBufferNdrPtr = 0;
5240 if (!smartcard_ndr_pointer_read(log, s, &index, &recvPciNdrPtr))
5241 return ERROR_INVALID_DATA;
5243 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
5244 return STATUS_BUFFER_TOO_SMALL;
5246 const UINT32 cbRecvLength = Stream_Get_UINT32(s);
5247 if (cbRecvLength > 66560)
5249 WLog_Print(log, WLOG_ERROR,
"2.2.3.11 Transmit_Return cbRecvLength(%" PRIu32
") > 66560",
5251 return SCARD_E_INVALID_PARAMETER;
5254 if (!smartcard_ndr_pointer_read(log, s, &index, &recvBufferNdrPtr))
5255 return ERROR_INVALID_DATA;
5259 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
5260 return STATUS_BUFFER_TOO_SMALL;
5262 UINT32 dwProtocol = 0;
5263 UINT32 cbExtraBytes = 0;
5264 Stream_Read_UINT32(s, dwProtocol);
5265 Stream_Read_UINT32(s, cbExtraBytes);
5267 UINT32 pbExtraBytesNdrPtr = 0;
5268 if (!smartcard_ndr_pointer_read(log, s, &index, &pbExtraBytesNdrPtr))
5269 return ERROR_INVALID_DATA;
5271 if (pbExtraBytesNdrPtr)
5273 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
5274 return STATUS_BUFFER_TOO_SMALL;
5277 Stream_Read_UINT32(s, length);
5278 if (length != cbExtraBytes)
5280 WLog_Print(log, WLOG_WARN,
5281 "Transmit_Return unexpected length: Actual: %" PRIu32
5282 ", Expected: %" PRIu32
" (pioRecvPci.cbExtraBytes)",
5283 length, cbExtraBytes);
5284 return STATUS_INVALID_PARAMETER;
5287 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, cbExtraBytes))
5288 return STATUS_BUFFER_TOO_SMALL;
5291 if (!ret->pioRecvPci)
5292 return SCARD_E_NO_MEMORY;
5294 ret->pioRecvPci->dwProtocol = dwProtocol;
5295 ret->pioRecvPci->cbPciLength = (DWORD)(
sizeof(
SCARD_IO_REQUEST) + cbExtraBytes);
5298 Stream_Read(s, pbExtraBytes, length);
5299 if (smartcard_unpack_read_size_align(s, cbExtraBytes, 4) < 0)
5300 return STATUS_INVALID_PARAMETER;
5305 if (!ret->pioRecvPci)
5306 return SCARD_E_NO_MEMORY;
5308 ret->pioRecvPci->dwProtocol = dwProtocol;
5313 if (recvBufferNdrPtr && (cbRecvLength > 0))
5316 smartcard_ndr_read(log, s, &ret->pbRecvBuffer, cbRecvLength, 1, NDR_PTR_SIMPLE);
5317 if (status != SCARD_S_SUCCESS)
5319 ret->cbRecvLength = cbRecvLength;
5322 smartcard_trace_transmit_return(log, ret);
5323 return SCARD_S_SUCCESS;
5329 wLog* log = scard_log();
5331 UINT32 pbAttrPtr = 0;
5333 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
5334 return STATUS_BUFFER_TOO_SMALL;
5336 const UINT32 cbAttrLen = Stream_Get_UINT32(s);
5337 if (cbAttrLen > 65536)
5339 WLog_Print(log, WLOG_ERROR,
"2.2.3.12 GetAttrib_Return cbAttrLen(%" PRIu32
") > 65536",
5341 return SCARD_E_INVALID_PARAMETER;
5344 if (!smartcard_ndr_pointer_read(log, s, &index, &pbAttrPtr))
5345 return ERROR_INVALID_DATA;
5347 LONG status = smartcard_ndr_read(log, s, &ret->pbAttr, cbAttrLen, 1, NDR_PTR_SIMPLE);
5348 if (status != SCARD_S_SUCCESS)
5350 ret->cbAttrLen = cbAttrLen;
5352 smartcard_trace_get_attrib_return(log, ret, 0);
5353 return SCARD_S_SUCCESS;
5356BOOL smartcard_reader_state_return_is_valid_ex(
size_t pos,
const ReaderState_Return* val,
5357 const char* file,
size_t line,
const char* fkt)
5361 WLog_Print_dbg_tag(SCARD_TAG, WLOG_WARN, line, file, fkt,
"[%" PRIuz
"] val = nullptr",
5365 if (val->cbAtr >
sizeof(val->rgbAtr))
5367 WLog_Print_dbg_tag(SCARD_TAG, WLOG_WARN, line, file, fkt,
5368 "[%" PRIuz
"] val->cbAtr=%" PRIu32
", max=%" PRIuz, pos, val->cbAtr,
5369 sizeof(val->rgbAtr));