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 (unicode && ((cBytes % 2) != 0))
2367 WLog_Print(log, WLOG_ERROR,
2368 "2.2.3.4 ListReaderGroupsW_Return and ListReadersW_Return cBytes (%" PRIu32
2371 return SCARD_E_INVALID_PARAMETER;
2373 if (!smartcard_ndr_pointer_read(log, s, &index, &mszGroupsNdrPtr))
2374 return ERROR_INVALID_DATA;
2376 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2377 return STATUS_BUFFER_TOO_SMALL;
2378 Stream_Read_INT32(s, call->fmszReadersIsNULL);
2379 Stream_Read_UINT32(s, call->cchReaders);
2381 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2382 &(call->handles.hContext));
2383 if (status != SCARD_S_SUCCESS)
2386 if (mszGroupsNdrPtr)
2388 status = smartcard_ndr_read(log, s, &call->mszGroups, cBytes, 1, NDR_PTR_SIMPLE);
2389 if (status != SCARD_S_SUCCESS)
2391 call->cBytes = cBytes;
2394 smartcard_trace_list_readers_call(log, call, unicode);
2395 return SCARD_S_SUCCESS;
2401 wLog* log = scard_log();
2404 UINT32 size = ret->cBytes;
2406 smartcard_trace_list_readers_return(log, ret, unicode);
2407 if (ret->ReturnCode != SCARD_S_SUCCESS)
2410 if (!Stream_EnsureRemainingCapacity(s, 4))
2412 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
2413 return SCARD_F_INTERNAL_ERROR;
2418 WLog_Print(log, WLOG_ERROR,
2419 "2.2.3.4 ListReaderGroups_Return and ListReaders_Return cBytes (%" PRIu32
2422 return SCARD_E_INVALID_PARAMETER;
2425 Stream_Write_UINT32(s, size);
2426 if (!smartcard_ndr_pointer_write(s, &index, size))
2427 return SCARD_E_NO_MEMORY;
2429 status = smartcard_ndr_write(s, ret->msz, size, 1, NDR_PTR_SIMPLE);
2430 if (status != SCARD_S_SUCCESS)
2432 return ret->ReturnCode;
2435WINPR_ATTR_NODISCARD
static LONG smartcard_unpack_connect_common(wLog* log,
wStream* s,
2438 UINT32* ppbContextNdrPtr)
2440 WINPR_ASSERT(common);
2441 LONG status = smartcard_unpack_redir_scard_context(log, s, &(common->handles.hContext), index,
2443 if (status != SCARD_S_SUCCESS)
2446 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2447 return STATUS_BUFFER_TOO_SMALL;
2449 Stream_Read_UINT32(s, common->dwShareMode);
2450 Stream_Read_UINT32(s, common->dwPreferredProtocols);
2451 return SCARD_S_SUCCESS;
2458 UINT32 pbContextNdrPtr = 0;
2461 wLog* log = scard_log();
2463 call->szReader =
nullptr;
2465 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
2466 return ERROR_INVALID_DATA;
2468 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2469 if (status != SCARD_S_SUCCESS)
2471 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2476 status = smartcard_ndr_read_a(log, s, &call->szReader, NDR_PTR_FULL);
2477 if (status != SCARD_S_SUCCESS)
2480 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2481 &(call->Common.handles.hContext));
2482 if (status != SCARD_S_SUCCESS)
2483 WLog_Print(log, WLOG_ERROR,
2484 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2487 smartcard_trace_connect_a_call(log, call);
2495 UINT32 pbContextNdrPtr = 0;
2498 wLog* log = scard_log();
2499 call->szReader =
nullptr;
2501 if (!smartcard_ndr_pointer_read(log, s, &index,
nullptr))
2502 return ERROR_INVALID_DATA;
2504 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2505 if (status != SCARD_S_SUCCESS)
2507 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2512 status = smartcard_ndr_read_w(log, s, &call->szReader, NDR_PTR_FULL);
2513 if (status != SCARD_S_SUCCESS)
2516 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2517 &(call->Common.handles.hContext));
2518 if (status != SCARD_S_SUCCESS)
2519 WLog_Print(log, WLOG_ERROR,
2520 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2523 smartcard_trace_connect_w_call(log, call);
2533 wLog* log = scard_log();
2534 smartcard_trace_connect_return(log, ret);
2536 status = smartcard_pack_redir_scard_context(log, s, &ret->hContext, &index);
2537 if (status != SCARD_S_SUCCESS)
2540 status = smartcard_pack_redir_scard_handle(log, s, &ret->hCard, &index);
2541 if (status != SCARD_S_SUCCESS)
2544 if (!Stream_EnsureRemainingCapacity(s, 4))
2545 return SCARD_E_NO_MEMORY;
2547 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2548 status = smartcard_pack_redir_scard_context_ref(log, s, &ret->hContext);
2549 if (status != SCARD_S_SUCCESS)
2551 return smartcard_pack_redir_scard_handle_ref(log, s, &(ret->hCard));
2557 UINT32 pbContextNdrPtr = 0;
2560 wLog* log = scard_log();
2561 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2563 if (status != SCARD_S_SUCCESS)
2566 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2567 if (status != SCARD_S_SUCCESS)
2570 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2571 return STATUS_BUFFER_TOO_SMALL;
2573 Stream_Read_UINT32(s, call->dwShareMode);
2574 Stream_Read_UINT32(s, call->dwPreferredProtocols);
2575 Stream_Read_UINT32(s, call->dwInitialization);
2577 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2578 &(call->handles.hContext));
2579 if (status != SCARD_S_SUCCESS)
2581 WLog_Print(log, WLOG_ERROR,
2582 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2587 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2588 if (status != SCARD_S_SUCCESS)
2589 WLog_Print(log, WLOG_ERROR,
2590 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
2592 smartcard_trace_reconnect_call(log, call);
2599 wLog* log = scard_log();
2602 smartcard_trace_reconnect_call(log, call);
2604 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
2605 if (status != SCARD_S_SUCCESS)
2608 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
2609 if (status != SCARD_S_SUCCESS)
2612 if (!Stream_EnsureRemainingCapacity(s, 12))
2613 return SCARD_E_NO_MEMORY;
2615 Stream_Write_UINT32(s, call->dwShareMode);
2616 Stream_Write_UINT32(s, call->dwPreferredProtocols);
2617 Stream_Write_UINT32(s, call->dwInitialization);
2619 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
2620 if (status != SCARD_S_SUCCESS)
2623 return smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
2629 wLog* log = scard_log();
2630 smartcard_trace_reconnect_return(log, ret);
2632 if (!Stream_EnsureRemainingCapacity(s, 4))
2633 return SCARD_E_NO_MEMORY;
2634 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2635 return ret->ReturnCode;
2641 wLog* log = scard_log();
2643 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2644 return STATUS_BUFFER_TOO_SMALL;
2646 Stream_Read_UINT32(s, ret->dwActiveProtocol);
2648 smartcard_trace_reconnect_return(log, ret);
2649 return SCARD_S_SUCCESS;
2656 UINT32 pbContextNdrPtr = 0;
2659 wLog* log = scard_log();
2661 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2663 if (status != SCARD_S_SUCCESS)
2666 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2667 if (status != SCARD_S_SUCCESS)
2670 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2671 return STATUS_BUFFER_TOO_SMALL;
2673 Stream_Read_UINT32(s, call->dwDisposition);
2675 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2676 &(call->handles.hContext));
2677 if (status != SCARD_S_SUCCESS)
2680 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2681 if (status != SCARD_S_SUCCESS)
2684 smartcard_trace_hcard_and_disposition_call(log, call, name);
2692 if (!WLog_IsLevelActive(log, g_LogLevel))
2695 WLog_Print(log, g_LogLevel,
"GetStatusChangeA_Call {");
2696 smartcard_log_context(log, &call->handles.hContext);
2698 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
2701 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
2703 WLog_Print(log, g_LogLevel,
"}");
2706WINPR_ATTR_NODISCARD
static LONG smartcard_unpack_reader_state_a(wLog* log,
wStream* s,
2708 UINT32 cReaders, UINT32* ptrIndex)
2710 LONG status = SCARD_E_NO_MEMORY;
2712 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2713 if (cReaders > UINT8_MAX)
2715 WLog_Print(log, WLOG_ERROR,
2716 "Too many readers(%" PRIu32
"), rejecting request. Limited to <= %d", cReaders,
2718 return SCARD_E_WRITE_TOO_MANY;
2721 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2724 const UINT32 len = Stream_Get_UINT32(s);
2725 if (len != cReaders)
2727 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEA");
2733 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2734 if (!rgReaderStates || !states)
2736 status = ERROR_INVALID_DATA;
2738 for (UINT32 index = 0; index < cReaders; index++)
2740 UINT32 ptr = UINT32_MAX;
2743 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2746 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2752 states[index] = ptr != 0;
2753 Stream_Read_UINT32(s, readerState->dwCurrentState);
2754 Stream_Read_UINT32(s, readerState->dwEventState);
2755 Stream_Read_UINT32(s, readerState->cbAtr);
2756 if (readerState->cbAtr > ARRAYSIZE(readerState->rgbAtr))
2758 WLog_Print(log, WLOG_WARN,
2759 "SCARD_READERSTATEA[%" PRIu32
"]::cbAtr %" PRIu32
" exceeds %" PRIuz, index,
2760 readerState->cbAtr, (
size_t)ARRAYSIZE(readerState->rgbAtr));
2761 readerState->cbAtr = ARRAYSIZE(readerState->rgbAtr);
2763 Stream_Read(s, readerState->rgbAtr, 36);
2766 for (UINT32 index = 0; index < cReaders; index++)
2773 status = smartcard_ndr_read_a(log, s, &readerState->szReader, NDR_PTR_FULL);
2774 if (status != SCARD_S_SUCCESS)
2776 if (!readerState->szReader)
2780 *ppcReaders = rgReaderStates;
2782 return SCARD_S_SUCCESS;
2786 for (UINT32 index = 0; index < cReaders; index++)
2789 free(readerState->szReader);
2792 free(rgReaderStates);
2797WINPR_ATTR_NODISCARD
static LONG smartcard_unpack_reader_state_w(wLog* log,
wStream* s,
2799 UINT32 cReaders, UINT32* ptrIndex)
2801 LONG status = SCARD_E_NO_MEMORY;
2803 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2805 if (cReaders > UINT8_MAX)
2807 WLog_Print(log, WLOG_ERROR,
2808 "Too many readers(%" PRIu32
"), rejecting request. Limited to <= %d", cReaders,
2810 return SCARD_E_WRITE_TOO_MANY;
2813 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2816 const UINT32 len = Stream_Get_UINT32(s);
2817 if (len != cReaders)
2819 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEW");
2825 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2827 if (!rgReaderStates || !states)
2830 status = ERROR_INVALID_DATA;
2831 for (UINT32 index = 0; index < cReaders; index++)
2833 UINT32 ptr = UINT32_MAX;
2836 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2839 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2845 states[index] = ptr != 0;
2846 Stream_Read_UINT32(s, readerState->dwCurrentState);
2847 Stream_Read_UINT32(s, readerState->dwEventState);
2848 Stream_Read_UINT32(s, readerState->cbAtr);
2849 if (readerState->cbAtr > ARRAYSIZE(readerState->rgbAtr))
2851 WLog_Print(log, WLOG_WARN,
2852 "SCARD_READERSTATEW[%" PRIu32
"]::cbAtr %" PRIu32
" exceeds %" PRIuz, index,
2853 readerState->cbAtr, ARRAYSIZE(readerState->rgbAtr));
2854 readerState->cbAtr = ARRAYSIZE(readerState->rgbAtr);
2856 Stream_Read(s, readerState->rgbAtr, 36);
2859 for (UINT32 index = 0; index < cReaders; index++)
2867 status = smartcard_ndr_read_w(log, s, &readerState->szReader, NDR_PTR_FULL);
2868 if (status != SCARD_S_SUCCESS)
2870 if (!readerState->szReader)
2874 *ppcReaders = rgReaderStates;
2876 return SCARD_S_SUCCESS;
2880 for (UINT32 index = 0; index < cReaders; index++)
2883 free(readerState->szReader);
2886 free(rgReaderStates);
2899 UINT32 pbContextNdrPtr = 0;
2902 wLog* log = scard_log();
2904 call->rgReaderStates =
nullptr;
2906 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2908 if (status != SCARD_S_SUCCESS)
2911 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2912 return STATUS_BUFFER_TOO_SMALL;
2914 Stream_Read_UINT32(s, call->dwTimeOut);
2915 const UINT32 cReaders = Stream_Get_UINT32(s);
2918 WLog_Print(log, WLOG_WARN,
2919 "2.2.2.11 GetStatusChangeA_Call: cReaders must be <= 11, got %" PRIu32,
2921 return ERROR_INVALID_DATA;
2924 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2925 return ERROR_INVALID_DATA;
2927 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2928 &(call->handles.hContext));
2929 if (status != SCARD_S_SUCCESS)
2934 status = smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, cReaders, &index);
2935 if (status != SCARD_S_SUCCESS)
2937 call->cReaders = cReaders;
2941 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2942 return SCARD_E_UNEXPECTED;
2945 smartcard_trace_get_status_change_a_call(log, call);
2946 return SCARD_S_SUCCESS;
2953 UINT32 pbContextNdrPtr = 0;
2956 wLog* log = scard_log();
2957 call->rgReaderStates =
nullptr;
2959 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2961 if (status != SCARD_S_SUCCESS)
2964 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2965 return STATUS_BUFFER_TOO_SMALL;
2967 Stream_Read_UINT32(s, call->dwTimeOut);
2968 const UINT32 cReaders = Stream_Get_UINT32(s);
2971 WLog_Print(log, WLOG_WARN,
2972 "2.2.2.12 GetStatusChangeW_Call: cReaders must be <= 11, got %" PRIu32,
2974 return ERROR_INVALID_DATA;
2977 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2978 return ERROR_INVALID_DATA;
2980 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2981 &(call->handles.hContext));
2982 if (status != SCARD_S_SUCCESS)
2987 status = smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, cReaders, &index);
2988 if (status != SCARD_S_SUCCESS)
2990 call->cReaders = cReaders;
2994 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2995 return SCARD_E_UNEXPECTED;
2998 smartcard_trace_get_status_change_w_call(log, call);
2999 return SCARD_S_SUCCESS;
3006 wLog* log = scard_log();
3009 UINT32 cReaders = ret->cReaders;
3012 if (ret->cReaders > 10)
3014 WLog_Print(log, WLOG_ERROR,
3015 "2.2.3.5 LocateCards_Return and GetStatusChange_Return cReaders(%" PRIu32
3018 return SCARD_E_INVALID_PARAMETER;
3021 smartcard_trace_get_status_change_return(log, ret, unicode);
3022 if ((ret->ReturnCode != SCARD_S_SUCCESS) && (ret->ReturnCode != SCARD_E_TIMEOUT))
3024 if (cReaders == SCARD_AUTOALLOCATE)
3027 if (!Stream_EnsureRemainingCapacity(s, 4))
3028 return SCARD_E_NO_MEMORY;
3030 Stream_Write_UINT32(s, cReaders);
3031 if (!smartcard_ndr_pointer_write(s, &index, cReaders))
3032 return SCARD_E_NO_MEMORY;
3033 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cReaders, NDR_PTR_SIMPLE);
3034 if (status != SCARD_S_SUCCESS)
3036 return ret->ReturnCode;
3042 UINT32 pbContextNdrPtr = 0;
3044 wLog* log = scard_log();
3047 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3049 if (status != SCARD_S_SUCCESS)
3052 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3053 if (status != SCARD_S_SUCCESS)
3056 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
3057 return STATUS_BUFFER_TOO_SMALL;
3059 Stream_Read_INT32(s, call->fpbAtrIsNULL);
3060 Stream_Read_UINT32(s, call->cbAtrLen);
3062 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3063 &(call->handles.hContext));
3064 if (status != SCARD_S_SUCCESS)
3067 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3068 if (status != SCARD_S_SUCCESS)
3077 wLog* log = scard_log();
3079 UINT32 cbAtrLen = ret->cbAtrLen;
3082 smartcard_trace_state_return(log, ret);
3083 if (ret->ReturnCode != SCARD_S_SUCCESS)
3085 if (cbAtrLen == SCARD_AUTOALLOCATE)
3088 Stream_Write_UINT32(s, ret->dwState);
3089 Stream_Write_UINT32(s, ret->dwProtocol);
3090 Stream_Write_UINT32(s, cbAtrLen);
3091 if (!smartcard_ndr_pointer_write(s, &index, cbAtrLen))
3092 return SCARD_E_NO_MEMORY;
3093 status = smartcard_ndr_write(s, ret->rgAtr, cbAtrLen, 1, NDR_PTR_SIMPLE);
3094 if (status != SCARD_S_SUCCESS)
3096 return ret->ReturnCode;
3102 UINT32 pbContextNdrPtr = 0;
3105 wLog* log = scard_log();
3107 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3109 if (status != SCARD_S_SUCCESS)
3112 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3113 if (status != SCARD_S_SUCCESS)
3116 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3117 return STATUS_BUFFER_TOO_SMALL;
3119 Stream_Read_INT32(s, call->fmszReaderNamesIsNULL);
3120 Stream_Read_UINT32(s, call->cchReaderLen);
3121 Stream_Read_UINT32(s, call->cbAtrLen);
3123 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3124 &(call->handles.hContext));
3125 if (status != SCARD_S_SUCCESS)
3128 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3129 if (status != SCARD_S_SUCCESS)
3132 smartcard_trace_status_call(log, call, unicode);
3139 wLog* log = scard_log();
3142 smartcard_trace_status_call(log, call, unicode);
3144 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
3145 if (status != SCARD_S_SUCCESS)
3148 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
3149 if (status != SCARD_S_SUCCESS)
3152 if (!Stream_EnsureRemainingCapacity(s, 12))
3153 return SCARD_E_NO_MEMORY;
3155 Stream_Write_INT32(s, call->fmszReaderNamesIsNULL);
3156 Stream_Write_UINT32(s, call->cchReaderLen);
3157 Stream_Write_UINT32(s, call->cbAtrLen);
3159 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
3160 if (status != SCARD_S_SUCCESS)
3163 return smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
3169 wLog* log = scard_log();
3173 UINT32 cBytes = ret->cBytes;
3175 smartcard_trace_status_return(log, ret, unicode);
3176 if (ret->ReturnCode != SCARD_S_SUCCESS)
3178 if (cBytes == SCARD_AUTOALLOCATE)
3181 if (!Stream_EnsureRemainingCapacity(s, 4))
3182 return SCARD_F_INTERNAL_ERROR;
3186 WLog_Print(log, WLOG_ERROR,
"2.2.3.10 Status_Return cBytes(%" PRIu32
") > 65536", cBytes);
3187 return SCARD_E_INVALID_PARAMETER;
3190 Stream_Write_UINT32(s, cBytes);
3191 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
3192 return SCARD_E_NO_MEMORY;
3194 if (!Stream_EnsureRemainingCapacity(s, 44))
3195 return SCARD_F_INTERNAL_ERROR;
3197 Stream_Write_UINT32(s, ret->dwState);
3198 Stream_Write_UINT32(s, ret->dwProtocol);
3199 Stream_Write(s, ret->pbAtr,
sizeof(ret->pbAtr));
3201 if (ret->cbAtrLen > 32)
3203 WLog_Print(log, WLOG_ERROR,
"2.2.3.10 Status_Return cbAtrLen(%" PRIu32
") > 32",
3205 return SCARD_E_INVALID_PARAMETER;
3208 Stream_Write_UINT32(s, ret->cbAtrLen);
3209 status = smartcard_ndr_write(s, ret->mszReaderNames, cBytes, 1, NDR_PTR_SIMPLE);
3210 if (status != SCARD_S_SUCCESS)
3212 return ret->ReturnCode;
3218 wLog* log = scard_log();
3220 UINT32 mszNdrPtr = 0;
3222 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3223 return STATUS_BUFFER_TOO_SMALL;
3225 const UINT32 cBytes = Stream_Get_UINT32(s);
3228 WLog_Print(log, WLOG_ERROR,
"2.2.3.10 Status_Return cBytes(%" PRIu32
") > 65536", cBytes);
3229 return SCARD_E_INVALID_PARAMETER;
3232 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3233 return ERROR_INVALID_DATA;
3235 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 44))
3236 return STATUS_BUFFER_TOO_SMALL;
3238 Stream_Read_UINT32(s, ret->dwState);
3239 Stream_Read_UINT32(s, ret->dwProtocol);
3240 Stream_Read(s, ret->pbAtr,
sizeof(ret->pbAtr));
3241 Stream_Read_UINT32(s, ret->cbAtrLen);
3243 if (ret->cbAtrLen > ARRAYSIZE(ret->pbAtr))
3245 WLog_Print(log, WLOG_ERROR,
"Status_Return::cbAtrLen %" PRIu32
" exceeds %" PRIuz,
3246 ret->cbAtrLen, ARRAYSIZE(ret->pbAtr));
3247 return SCARD_E_INVALID_ATR;
3252 LONG status = smartcard_ndr_read(log, s, &ret->mszReaderNames, cBytes, 1, NDR_PTR_SIMPLE);
3253 if (status != SCARD_S_SUCCESS)
3255 ret->cBytes = cBytes;
3258 smartcard_trace_status_return(log, ret, unicode);
3259 return SCARD_S_SUCCESS;
3265 wLog* log = scard_log();
3267 UINT32 pbContextNdrPtr = 0;
3269 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3271 if (status != SCARD_S_SUCCESS)
3274 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3275 if (status != SCARD_S_SUCCESS)
3278 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3279 return STATUS_BUFFER_TOO_SMALL;
3281 Stream_Read_UINT32(s, call->dwAttrId);
3282 Stream_Read_INT32(s, call->fpbAttrIsNULL);
3283 Stream_Read_UINT32(s, call->cbAttrLen);
3285 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3286 &(call->handles.hContext));
3287 if (status != SCARD_S_SUCCESS)
3290 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3291 if (status != SCARD_S_SUCCESS)
3294 smartcard_trace_get_attrib_call(log, call);
3299 DWORD cbAttrCallLen)
3302 wLog* log = scard_log();
3304 UINT32 cbAttrLen = 0;
3306 smartcard_trace_get_attrib_return(log, ret, dwAttrId);
3308 if (!Stream_EnsureRemainingCapacity(s, 4))
3309 return SCARD_F_INTERNAL_ERROR;
3311 cbAttrLen = ret->cbAttrLen;
3312 if (ret->ReturnCode != SCARD_S_SUCCESS)
3314 if (cbAttrLen == SCARD_AUTOALLOCATE)
3319 if (cbAttrCallLen < cbAttrLen)
3320 cbAttrLen = cbAttrCallLen;
3322 if (cbAttrLen > 65536)
3324 WLog_Print(log, WLOG_ERROR,
"2.2.3.12 GetAttrib_Return cbAttrLen(%" PRIu32
") > 65536",
3326 return SCARD_E_INVALID_PARAMETER;
3328 Stream_Write_UINT32(s, cbAttrLen);
3329 if (!smartcard_ndr_pointer_write(s, &index, cbAttrLen))
3330 return SCARD_E_NO_MEMORY;
3332 status = smartcard_ndr_write(s, ret->pbAttr, cbAttrLen, 1, NDR_PTR_SIMPLE);
3333 if (status != SCARD_S_SUCCESS)
3335 return ret->ReturnCode;
3341 wLog* log = scard_log();
3344 UINT32 pvInBufferNdrPtr = 0;
3345 UINT32 pbContextNdrPtr = 0;
3347 call->pvInBuffer =
nullptr;
3349 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3351 if (status != SCARD_S_SUCCESS)
3354 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3355 if (status != SCARD_S_SUCCESS)
3358 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 20))
3359 return STATUS_BUFFER_TOO_SMALL;
3361 Stream_Read_UINT32(s, call->dwControlCode);
3362 const UINT32 cbInBufferSize = Stream_Get_UINT32(s);
3363 if (cbInBufferSize > 66560)
3365 WLog_Print(log, WLOG_ERROR,
"2.2.2.20 Control_Call cbInBufferSize (%" PRIu32
") > 66560",
3367 return SCARD_E_INVALID_PARAMETER;
3370 if (!smartcard_ndr_pointer_read(log, s, &index,
3372 return ERROR_INVALID_DATA;
3373 Stream_Read_INT32(s, call->fpvOutBufferIsNULL);
3374 Stream_Read_UINT32(s, call->cbOutBufferSize);
3376 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3377 &(call->handles.hContext));
3378 if (status != SCARD_S_SUCCESS)
3381 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3382 if (status != SCARD_S_SUCCESS)
3385 if (pvInBufferNdrPtr)
3387 status = smartcard_ndr_read(log, s, &call->pvInBuffer, cbInBufferSize, 1, NDR_PTR_SIMPLE);
3388 if (status != SCARD_S_SUCCESS)
3390 call->cbInBufferSize = cbInBufferSize;
3393 smartcard_trace_control_call(log, call);
3394 return SCARD_S_SUCCESS;
3400 wLog* log = scard_log();
3403 UINT32 cbDataLen = ret->cbOutBufferSize;
3406 smartcard_trace_control_return(log, ret);
3407 if (ret->ReturnCode != SCARD_S_SUCCESS)
3409 if (cbDataLen == SCARD_AUTOALLOCATE)
3412 if (!Stream_EnsureRemainingCapacity(s, 4))
3413 return SCARD_F_INTERNAL_ERROR;
3415 if (cbDataLen > 66560)
3417 WLog_Print(log, WLOG_ERROR,
"2.2.3.6 Control_Return cbOutBufferSize(%" PRIu32
") > 66560",
3419 return SCARD_E_INVALID_PARAMETER;
3422 Stream_Write_UINT32(s, cbDataLen);
3423 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3424 return SCARD_E_NO_MEMORY;
3426 status = smartcard_ndr_write(s, ret->pvOutBuffer, cbDataLen, 1, NDR_PTR_SIMPLE);
3427 if (status != SCARD_S_SUCCESS)
3429 return ret->ReturnCode;
3435 BYTE* pbExtraBytes =
nullptr;
3436 UINT32 pbExtraBytesNdrPtr = 0;
3437 UINT32 pbSendBufferNdrPtr = 0;
3438 UINT32 pioRecvPciNdrPtr = 0;
3442 UINT32 pbContextNdrPtr = 0;
3445 wLog* log = scard_log();
3447 call->pioSendPci =
nullptr;
3448 call->pioRecvPci =
nullptr;
3449 call->pbSendBuffer =
nullptr;
3451 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3453 if (status != SCARD_S_SUCCESS)
3456 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3457 if (status != SCARD_S_SUCCESS)
3460 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 32))
3461 return STATUS_BUFFER_TOO_SMALL;
3463 Stream_Read_UINT32(s, ioSendPci.dwProtocol);
3464 Stream_Read_UINT32(s, ioSendPci.cbExtraBytes);
3465 if (!smartcard_ndr_pointer_read(log, s, &index,
3466 &pbExtraBytesNdrPtr))
3467 return ERROR_INVALID_DATA;
3469 const UINT32 cbSendLength = Stream_Get_UINT32(s);
3470 if (cbSendLength > 66560)
3472 WLog_Print(log, WLOG_ERROR,
"2.2.2.19 Transmit_Call cbSendLength (%" PRIu32
") > 66560",
3474 return SCARD_E_INVALID_PARAMETER;
3476 if (!smartcard_ndr_pointer_read(log, s, &index,
3477 &pbSendBufferNdrPtr))
3478 return ERROR_INVALID_DATA;
3480 if (!smartcard_ndr_pointer_read(log, s, &index,
3482 return ERROR_INVALID_DATA;
3484 Stream_Read_INT32(s, call->fpbRecvBufferIsNULL);
3485 Stream_Read_UINT32(s, call->cbRecvLength);
3487 if (ioSendPci.cbExtraBytes > 1024)
3489 WLog_Print(log, WLOG_WARN,
3490 "Transmit_Call ioSendPci.cbExtraBytes is out of bounds: %" PRIu32
" (max: 1024)",
3491 ioSendPci.cbExtraBytes);
3492 return STATUS_INVALID_PARAMETER;
3495 if (cbSendLength > 66560)
3497 WLog_Print(log, WLOG_WARN,
3498 "Transmit_Call cbSendLength is out of bounds: %" PRIu32
" (max: 66560)",
3499 ioSendPci.cbExtraBytes);
3500 return STATUS_INVALID_PARAMETER;
3503 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3504 &(call->handles.hContext));
3505 if (status != SCARD_S_SUCCESS)
3508 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3509 if (status != SCARD_S_SUCCESS)
3512 if (ioSendPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3516 "Transmit_Call ioSendPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3517 return STATUS_INVALID_PARAMETER;
3520 if (pbExtraBytesNdrPtr)
3523 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3524 return STATUS_BUFFER_TOO_SMALL;
3526 Stream_Read_UINT32(s, length);
3528 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioSendPci.cbExtraBytes))
3529 return STATUS_BUFFER_TOO_SMALL;
3531 ioSendPci.pbExtraBytes = Stream_Pointer(s);
3535 if (!call->pioSendPci)
3537 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3538 return STATUS_NO_MEMORY;
3541 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3542 call->pioSendPci->cbPciLength = (DWORD)(ioSendPci.cbExtraBytes +
sizeof(
SCARD_IO_REQUEST));
3544 Stream_Read(s, pbExtraBytes, ioSendPci.cbExtraBytes);
3545 if (smartcard_unpack_read_size_align(s, ioSendPci.cbExtraBytes, 4) < 0)
3546 return STATUS_INVALID_PARAMETER;
3552 if (!call->pioSendPci)
3554 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3555 return STATUS_NO_MEMORY;
3558 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3562 if (pbSendBufferNdrPtr)
3564 status = smartcard_ndr_read(log, s, &call->pbSendBuffer, cbSendLength, 1, NDR_PTR_SIMPLE);
3565 if (status != SCARD_S_SUCCESS)
3567 call->cbSendLength = cbSendLength;
3570 if (pioRecvPciNdrPtr)
3572 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3573 return STATUS_BUFFER_TOO_SMALL;
3575 Stream_Read_UINT32(s, ioRecvPci.dwProtocol);
3576 Stream_Read_UINT32(s, ioRecvPci.cbExtraBytes);
3577 if (!smartcard_ndr_pointer_read(log, s, &index,
3578 &pbExtraBytesNdrPtr))
3579 return ERROR_INVALID_DATA;
3581 if (ioRecvPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3585 "Transmit_Call ioRecvPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3586 return STATUS_INVALID_PARAMETER;
3589 if (pbExtraBytesNdrPtr)
3592 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3593 return STATUS_BUFFER_TOO_SMALL;
3595 Stream_Read_UINT32(s, length);
3597 if (ioRecvPci.cbExtraBytes > 1024)
3599 WLog_Print(log, WLOG_WARN,
3600 "Transmit_Call ioRecvPci.cbExtraBytes is out of bounds: %" PRIu32
3602 ioRecvPci.cbExtraBytes);
3603 return STATUS_INVALID_PARAMETER;
3606 if (length != ioRecvPci.cbExtraBytes)
3608 WLog_Print(log, WLOG_WARN,
3609 "Transmit_Call unexpected length: Actual: %" PRIu32
3610 ", Expected: %" PRIu32
" (ioRecvPci.cbExtraBytes)",
3611 length, ioRecvPci.cbExtraBytes);
3612 return STATUS_INVALID_PARAMETER;
3615 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioRecvPci.cbExtraBytes))
3616 return STATUS_BUFFER_TOO_SMALL;
3618 ioRecvPci.pbExtraBytes = Stream_Pointer(s);
3622 if (!call->pioRecvPci)
3624 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3625 return STATUS_NO_MEMORY;
3628 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3629 call->pioRecvPci->cbPciLength =
3632 Stream_Read(s, pbExtraBytes, ioRecvPci.cbExtraBytes);
3633 if (smartcard_unpack_read_size_align(s, ioRecvPci.cbExtraBytes, 4) < 0)
3634 return STATUS_INVALID_PARAMETER;
3640 if (!call->pioRecvPci)
3642 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3643 return STATUS_NO_MEMORY;
3646 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3651 smartcard_trace_transmit_call(log, call);
3652 return SCARD_S_SUCCESS;
3658 wLog* log = scard_log();
3663 UINT32 cbRecvLength = ret->cbRecvLength;
3664 UINT32 cbRecvPci = ret->pioRecvPci ? ret->pioRecvPci->cbPciLength : 0;
3666 smartcard_trace_transmit_return(log, ret);
3668 if (!ret->pbRecvBuffer)
3671 if (!smartcard_ndr_pointer_write(s, &index, cbRecvPci))
3672 return SCARD_E_NO_MEMORY;
3673 if (!Stream_EnsureRemainingCapacity(s, 4))
3674 return SCARD_E_NO_MEMORY;
3676 if (cbRecvLength > 66560)
3678 WLog_Print(log, WLOG_ERROR,
"2.2.3.11 Transmit_Return cbRecvLength(%" PRIu32
") > 66560",
3680 return SCARD_E_INVALID_PARAMETER;
3683 Stream_Write_UINT32(s, cbRecvLength);
3684 if (!smartcard_ndr_pointer_write(s, &index, cbRecvLength))
3685 return SCARD_E_NO_MEMORY;
3687 if (ret->pioRecvPci)
3689 UINT32 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
3692 if (!Stream_EnsureRemainingCapacity(s, 8ull))
3694 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3695 return SCARD_F_INTERNAL_ERROR;
3698 Stream_Write_UINT32(s, ret->pioRecvPci->dwProtocol);
3699 Stream_Write_UINT32(s, cbExtraBytes);
3700 if (!smartcard_ndr_pointer_write(s, &index, cbExtraBytes))
3701 return SCARD_E_NO_MEMORY;
3702 error = smartcard_ndr_write(s, pbExtraBytes, cbExtraBytes, 1, NDR_PTR_SIMPLE);
3707 status = smartcard_ndr_write(s, ret->pbRecvBuffer, ret->cbRecvLength, 1, NDR_PTR_SIMPLE);
3708 if (status != SCARD_S_SUCCESS)
3710 return ret->ReturnCode;
3715 UINT32 rgReaderStatesNdrPtr = 0;
3716 UINT32 rgAtrMasksNdrPtr = 0;
3718 UINT32 pbContextNdrPtr = 0;
3721 wLog* log = scard_log();
3723 call->rgReaderStates =
nullptr;
3725 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3727 if (status != SCARD_S_SUCCESS)
3730 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3731 return STATUS_BUFFER_TOO_SMALL;
3733 Stream_Read_UINT32(s, call->cAtrs);
3734 if (call->cAtrs > 1000)
3736 WLog_Print(log, WLOG_ERROR,
"2.2.2.23 LocateCardsByATRA_Call cAtrs(%" PRIu32
") > 1000",
3738 return SCARD_E_INVALID_PARAMETER;
3741 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3742 return ERROR_INVALID_DATA;
3743 const UINT32 cReaders = Stream_Get_UINT32(s);
3746 WLog_Print(log, WLOG_ERROR,
"2.2.2.23 LocateCardsByATRA_Call cReaders(%" PRIu32
") > 10",
3748 return SCARD_E_INVALID_PARAMETER;
3750 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3751 return ERROR_INVALID_DATA;
3753 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3754 &(call->handles.hContext));
3755 if (status != SCARD_S_SUCCESS)
3758 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3760 WLog_Print(log, WLOG_WARN,
3761 "LocateCardsByATRA_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3762 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3763 rgAtrMasksNdrPtr, call->cAtrs);
3764 return STATUS_INVALID_PARAMETER;
3767 if (rgAtrMasksNdrPtr)
3769 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3770 if (status != SCARD_S_SUCCESS)
3774 if (rgReaderStatesNdrPtr)
3776 status = smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, cReaders, &index);
3777 if (status != SCARD_S_SUCCESS)
3779 call->cReaders = cReaders;
3782 smartcard_trace_locate_cards_by_atr_a_call(log, call);
3783 return SCARD_S_SUCCESS;
3788 UINT32 sz1NdrPtr = 0;
3789 UINT32 sz2NdrPtr = 0;
3791 UINT32 pbContextNdrPtr = 0;
3794 wLog* log = scard_log();
3796 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3798 if (status != SCARD_S_SUCCESS)
3801 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3802 return ERROR_INVALID_DATA;
3803 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3804 return ERROR_INVALID_DATA;
3807 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3808 if (status != SCARD_S_SUCCESS)
3813 status = smartcard_ndr_read_a(log, s, &call->sz1, NDR_PTR_FULL);
3814 if (status != SCARD_S_SUCCESS)
3819 status = smartcard_ndr_read_a(log, s, &call->sz2, NDR_PTR_FULL);
3820 if (status != SCARD_S_SUCCESS)
3823 smartcard_trace_context_and_two_strings_a_call(log, call);
3824 return SCARD_S_SUCCESS;
3829 UINT32 sz1NdrPtr = 0;
3830 UINT32 sz2NdrPtr = 0;
3832 UINT32 pbContextNdrPtr = 0;
3835 wLog* log = scard_log();
3837 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3839 if (status != SCARD_S_SUCCESS)
3842 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3843 return ERROR_INVALID_DATA;
3844 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3845 return ERROR_INVALID_DATA;
3848 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3849 if (status != SCARD_S_SUCCESS)
3854 status = smartcard_ndr_read_w(log, s, &call->sz1, NDR_PTR_FULL);
3855 if (status != SCARD_S_SUCCESS)
3860 status = smartcard_ndr_read_w(log, s, &call->sz2, NDR_PTR_FULL);
3861 if (status != SCARD_S_SUCCESS)
3864 smartcard_trace_context_and_two_strings_w_call(log, call);
3865 return SCARD_S_SUCCESS;
3870 UINT32 sz1NdrPtr = 0;
3871 UINT32 sz2NdrPtr = 0;
3873 UINT32 pbContextNdrPtr = 0;
3876 wLog* log = scard_log();
3878 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3880 if (status != SCARD_S_SUCCESS)
3883 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3884 return STATUS_BUFFER_TOO_SMALL;
3886 const UINT32 cBytes = Stream_Get_UINT32(s);
3887 if (call->cBytes > 65536)
3889 WLog_Print(log, WLOG_ERROR,
"2.2.2.9 LocateCardsA_Call cBytes(%" PRIu32
") > 65536",
3891 return SCARD_E_INVALID_PARAMETER;
3894 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3895 return ERROR_INVALID_DATA;
3897 const UINT32 cReaders = Stream_Get_UINT32(s);
3900 WLog_Print(log, WLOG_ERROR,
"2.2.2.9 LocateCardsA_Call cReaders(%" PRIu32
") > 10",
3902 return SCARD_E_INVALID_PARAMETER;
3904 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3905 return ERROR_INVALID_DATA;
3907 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3908 &(call->handles.hContext));
3909 if (status != SCARD_S_SUCCESS)
3914 status = smartcard_ndr_read_fixed_string_a(log, s, &call->mszCards, cBytes, NDR_PTR_SIMPLE);
3915 if (status != SCARD_S_SUCCESS)
3917 call->cBytes = cBytes;
3921 status = smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, cReaders, &index);
3922 if (status != SCARD_S_SUCCESS)
3924 call->cReaders = cReaders;
3926 smartcard_trace_locate_cards_a_call(log, call);
3927 return SCARD_S_SUCCESS;
3932 UINT32 sz1NdrPtr = 0;
3933 UINT32 sz2NdrPtr = 0;
3935 UINT32 pbContextNdrPtr = 0;
3938 wLog* log = scard_log();
3940 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3942 if (status != SCARD_S_SUCCESS)
3945 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3946 return STATUS_BUFFER_TOO_SMALL;
3948 const UINT32 cBytes = Stream_Get_UINT32(s);
3949 if (call->cBytes > 65536)
3951 WLog_Print(log, WLOG_ERROR,
"2.2.2.10 LocateCardsW_Call cBytes(%" PRIu32
") > 65536",
3953 return SCARD_E_INVALID_PARAMETER;
3956 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3957 return ERROR_INVALID_DATA;
3959 const UINT32 cReaders = Stream_Get_UINT32(s);
3962 WLog_Print(log, WLOG_ERROR,
"2.2.2.10 LocateCardsW_Call cReaders(%" PRIu32
") > 10",
3964 return SCARD_E_INVALID_PARAMETER;
3967 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3968 return ERROR_INVALID_DATA;
3970 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3971 &(call->handles.hContext));
3972 if (status != SCARD_S_SUCCESS)
3977 status = smartcard_ndr_read_fixed_string_w(log, s, &call->mszCards, cBytes, NDR_PTR_SIMPLE);
3978 if (status != SCARD_S_SUCCESS)
3980 call->cBytes = cBytes;
3984 status = smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, cReaders, &index);
3985 if (status != SCARD_S_SUCCESS)
3987 call->cReaders = cReaders;
3989 smartcard_trace_locate_cards_w_call(log, call);
3990 return SCARD_S_SUCCESS;
3997 UINT32 pbContextNdrPtr = 0;
4000 wLog* log = scard_log();
4002 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
4004 if (status != SCARD_S_SUCCESS)
4006 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
4007 if (status != SCARD_S_SUCCESS)
4010 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
4011 return STATUS_BUFFER_TOO_SMALL;
4012 Stream_Read_UINT32(s, call->dwAttrId);
4013 Stream_Read_UINT32(s, call->cbAttrLen);
4014 if (call->cbAttrLen > 65536)
4016 WLog_Print(log, WLOG_ERROR,
"2.2.2.22 SetAttrib_Call call->cbAttrLen (%" PRIu32
") > 65536",
4018 return SCARD_E_INVALID_PARAMETER;
4021 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
4022 return ERROR_INVALID_DATA;
4024 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4025 &(call->handles.hContext));
4026 if (status != SCARD_S_SUCCESS)
4029 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
4030 if (status != SCARD_S_SUCCESS)
4036 status = smartcard_ndr_read_ex(log, s, &call->pbAttr, 0, 1, NDR_PTR_SIMPLE, &len);
4037 if (status != SCARD_S_SUCCESS)
4039 if (call->cbAttrLen > len)
4040 call->cbAttrLen = WINPR_ASSERTING_INT_CAST(DWORD, len);
4043 call->cbAttrLen = 0;
4044 smartcard_trace_set_attrib_call(log, call);
4045 return SCARD_S_SUCCESS;
4051 wLog* log = scard_log();
4054 smartcard_trace_set_attrib_call(log, call);
4056 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4057 if (status != SCARD_S_SUCCESS)
4060 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
4061 if (status != SCARD_S_SUCCESS)
4064 if (!Stream_EnsureRemainingCapacity(s, 8))
4065 return SCARD_E_NO_MEMORY;
4067 Stream_Write_UINT32(s, call->dwAttrId);
4068 Stream_Write_UINT32(s, call->cbAttrLen);
4070 if (!smartcard_ndr_pointer_write(s, &index, call->cbAttrLen))
4071 return SCARD_E_NO_MEMORY;
4073 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4074 if (status != SCARD_S_SUCCESS)
4077 status = smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
4078 if (status != SCARD_S_SUCCESS)
4081 status = smartcard_ndr_write(s, call->pbAttr, call->cbAttrLen, 1, NDR_PTR_SIMPLE);
4082 if (status != SCARD_S_SUCCESS)
4085 return SCARD_S_SUCCESS;
4090 UINT32 rgReaderStatesNdrPtr = 0;
4091 UINT32 rgAtrMasksNdrPtr = 0;
4093 UINT32 pbContextNdrPtr = 0;
4096 wLog* log = scard_log();
4098 call->rgReaderStates =
nullptr;
4100 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
4102 if (status != SCARD_S_SUCCESS)
4105 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
4106 return STATUS_BUFFER_TOO_SMALL;
4108 Stream_Read_UINT32(s, call->cAtrs);
4109 if (call->cAtrs > 1000)
4111 WLog_Print(log, WLOG_ERROR,
"2.2.2.24 LocateCardsByATRW_Call cAtrs(%" PRIu32
") > 1000",
4113 return SCARD_E_INVALID_PARAMETER;
4116 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
4117 return ERROR_INVALID_DATA;
4119 const UINT32 cReaders = Stream_Get_UINT32(s);
4122 WLog_Print(log, WLOG_ERROR,
"2.2.2.24 LocateCardsByATRW_Call cReaders(%" PRIu32
") > 10",
4124 return SCARD_E_INVALID_PARAMETER;
4126 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
4127 return ERROR_INVALID_DATA;
4129 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4130 &(call->handles.hContext));
4131 if (status != SCARD_S_SUCCESS)
4134 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
4136 WLog_Print(log, WLOG_WARN,
4137 "LocateCardsByATRW_Call rgAtrMasksNdrPtr (0x%08" PRIX32
4138 ") and cAtrs (0x%08" PRIX32
") inconsistency",
4139 rgAtrMasksNdrPtr, call->cAtrs);
4140 return STATUS_INVALID_PARAMETER;
4143 if (rgAtrMasksNdrPtr)
4145 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
4146 if (status != SCARD_S_SUCCESS)
4150 if (rgReaderStatesNdrPtr)
4152 status = smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, cReaders, &index);
4153 if (status != SCARD_S_SUCCESS)
4155 call->cReaders = cReaders;
4158 smartcard_trace_locate_cards_by_atr_w_call(log, call);
4159 return SCARD_S_SUCCESS;
4164 UINT32 mszNdrPtr = 0;
4165 UINT32 contextNdrPtr = 0;
4167 UINT32 pbContextNdrPtr = 0;
4170 wLog* log = scard_log();
4172 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
4173 return ERROR_INVALID_DATA;
4175 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
4176 &index, &pbContextNdrPtr);
4177 if (status != SCARD_S_SUCCESS)
4180 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
4181 return ERROR_INVALID_DATA;
4183 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
4184 return STATUS_BUFFER_TOO_SMALL;
4185 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
4186 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
4187 Stream_Read_UINT32(s, call->Common.cbDataLen);
4189 call->szLookupName =
nullptr;
4192 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
4193 if (status != SCARD_S_SUCCESS)
4197 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4198 &call->Common.handles.hContext);
4199 if (status != SCARD_S_SUCCESS)
4204 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
4205 if (status != SCARD_S_SUCCESS)
4208 smartcard_trace_read_cache_a_call(log, call);
4209 return SCARD_S_SUCCESS;
4214 UINT32 mszNdrPtr = 0;
4215 UINT32 contextNdrPtr = 0;
4217 UINT32 pbContextNdrPtr = 0;
4220 wLog* log = scard_log();
4222 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
4223 return ERROR_INVALID_DATA;
4225 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
4226 &index, &pbContextNdrPtr);
4227 if (status != SCARD_S_SUCCESS)
4230 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
4231 return ERROR_INVALID_DATA;
4233 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
4234 return STATUS_BUFFER_TOO_SMALL;
4235 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
4236 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
4237 Stream_Read_UINT32(s, call->Common.cbDataLen);
4239 call->szLookupName =
nullptr;
4242 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
4243 if (status != SCARD_S_SUCCESS)
4247 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4248 &call->Common.handles.hContext);
4249 if (status != SCARD_S_SUCCESS)
4254 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
4255 if (status != SCARD_S_SUCCESS)
4258 smartcard_trace_read_cache_w_call(log, call);
4259 return SCARD_S_SUCCESS;
4264 UINT32 mszNdrPtr = 0;
4265 UINT32 contextNdrPtr = 0;
4266 UINT32 pbDataNdrPtr = 0;
4268 UINT32 pbContextNdrPtr = 0;
4271 wLog* log = scard_log();
4273 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
4274 return ERROR_INVALID_DATA;
4276 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
4277 &index, &pbContextNdrPtr);
4278 if (status != SCARD_S_SUCCESS)
4281 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
4282 return ERROR_INVALID_DATA;
4284 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
4285 return STATUS_BUFFER_TOO_SMALL;
4287 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
4288 const UINT32 cbDataLen = Stream_Get_UINT32(s);
4289 if (cbDataLen > 65536)
4291 WLog_Print(log, WLOG_ERROR,
"2.2.1.10 WriteCache_Common cbDataLen(%" PRIu32
") > 65536",
4293 return ERROR_INVALID_DATA;
4296 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
4297 return ERROR_INVALID_DATA;
4299 call->szLookupName =
nullptr;
4302 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
4303 if (status != SCARD_S_SUCCESS)
4307 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4308 &call->Common.handles.hContext);
4309 if (status != SCARD_S_SUCCESS)
4312 call->Common.CardIdentifier =
nullptr;
4315 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
4316 if (status != SCARD_S_SUCCESS)
4320 call->Common.pbData =
nullptr;
4323 status = smartcard_ndr_read(log, s, &call->Common.pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
4324 if (status != SCARD_S_SUCCESS)
4326 call->Common.cbDataLen = cbDataLen;
4328 smartcard_trace_write_cache_a_call(log, call);
4329 return SCARD_S_SUCCESS;
4334 UINT32 mszNdrPtr = 0;
4335 UINT32 contextNdrPtr = 0;
4336 UINT32 pbDataNdrPtr = 0;
4338 UINT32 pbContextNdrPtr = 0;
4341 wLog* log = scard_log();
4343 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
4344 return ERROR_INVALID_DATA;
4346 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
4347 &index, &pbContextNdrPtr);
4348 if (status != SCARD_S_SUCCESS)
4351 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
4352 return ERROR_INVALID_DATA;
4354 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
4355 return STATUS_BUFFER_TOO_SMALL;
4356 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
4357 const UINT32 cbDataLen = Stream_Get_UINT32(s);
4359 if (cbDataLen > 65536)
4361 WLog_Print(log, WLOG_ERROR,
"2.2.1.10 WriteCache_Common cbDataLen(%" PRIu32
") > 65536",
4363 return ERROR_INVALID_DATA;
4366 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
4367 return ERROR_INVALID_DATA;
4369 call->szLookupName =
nullptr;
4372 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
4373 if (status != SCARD_S_SUCCESS)
4377 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4378 &call->Common.handles.hContext);
4379 if (status != SCARD_S_SUCCESS)
4382 call->Common.CardIdentifier =
nullptr;
4385 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
4386 if (status != SCARD_S_SUCCESS)
4390 call->Common.pbData =
nullptr;
4393 status = smartcard_ndr_read(log, s, &call->Common.pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
4394 if (status != SCARD_S_SUCCESS)
4396 call->Common.cbDataLen = cbDataLen;
4398 smartcard_trace_write_cache_w_call(log, call);
4405 wLog* log = scard_log();
4408 UINT32 pbContextNdrPtr = 0;
4410 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
4412 if (status != SCARD_S_SUCCESS)
4415 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
4416 if (status != SCARD_S_SUCCESS)
4419 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
4420 &(call->handles.hContext));
4421 if (status != SCARD_S_SUCCESS)
4423 WLog_Print(log, WLOG_ERROR,
4424 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
4429 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
4430 if (status != SCARD_S_SUCCESS)
4431 WLog_Print(log, WLOG_ERROR,
4432 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
4434 smartcard_trace_get_transmit_count_call(log, call);
4441 wLog* log = scard_log();
4442 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
4443 &call->szReaderName);
4449 wLog* log = scard_log();
4450 return smartcard_unpack_common_context_and_string_a(log, s, &call->handles.hContext, &call->sz);
4456 wLog* log = scard_log();
4457 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext, &call->sz);
4463 wLog* log = scard_log();
4464 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
4465 &call->szReaderName);
4471 wLog* log = scard_log();
4472 smartcard_trace_device_type_id_return(log, ret);
4474 if (!Stream_EnsureRemainingCapacity(s, 4))
4476 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4477 return SCARD_F_INTERNAL_ERROR;
4480 Stream_Write_UINT32(s, ret->dwDeviceId);
4482 return ret->ReturnCode;
4488 wLog* log = scard_log();
4491 UINT32 cbDataLen = ret->cReaders;
4494 smartcard_trace_locate_cards_return(log, ret);
4495 if (ret->ReturnCode != SCARD_S_SUCCESS)
4497 if (cbDataLen == SCARD_AUTOALLOCATE)
4500 if (!Stream_EnsureRemainingCapacity(s, 4))
4502 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4503 return SCARD_F_INTERNAL_ERROR;
4506 if (ret->cReaders > 10)
4508 WLog_Print(log, WLOG_ERROR,
4509 "2.2.3.5 LocateCards_Return and GetStatusChange_Return cReaders(%" PRIu32
4512 return SCARD_E_INVALID_PARAMETER;
4515 Stream_Write_UINT32(s, cbDataLen);
4516 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
4517 return SCARD_E_NO_MEMORY;
4519 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cbDataLen, NDR_PTR_SIMPLE);
4520 if (status != SCARD_S_SUCCESS)
4522 return ret->ReturnCode;
4528 wLog* log = scard_log();
4532 UINT32 cbDataLen = ret->cbDataLen;
4533 smartcard_trace_get_reader_icon_return(log, ret);
4534 if (ret->ReturnCode != SCARD_S_SUCCESS)
4536 if (cbDataLen == SCARD_AUTOALLOCATE)
4539 if (!Stream_EnsureRemainingCapacity(s, 4))
4541 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4542 return SCARD_F_INTERNAL_ERROR;
4545 Stream_Write_UINT32(s, cbDataLen);
4546 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
4547 return SCARD_E_NO_MEMORY;
4549 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
4550 if (status != SCARD_S_SUCCESS)
4552 return ret->ReturnCode;
4558 wLog* log = scard_log();
4560 smartcard_trace_get_transmit_count_return(log, ret);
4562 if (!Stream_EnsureRemainingCapacity(s, 4))
4564 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4565 return SCARD_F_INTERNAL_ERROR;
4568 Stream_Write_UINT32(s, ret->cTransmitCount);
4570 return ret->ReturnCode;
4576 wLog* log = scard_log();
4580 UINT32 cbDataLen = ret->cbDataLen;
4581 smartcard_trace_read_cache_return(log, ret);
4582 if (ret->ReturnCode != SCARD_S_SUCCESS)
4585 if (cbDataLen == SCARD_AUTOALLOCATE)
4588 if (!Stream_EnsureRemainingCapacity(s, 4))
4590 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4591 return SCARD_F_INTERNAL_ERROR;
4594 if (cbDataLen > 65536)
4596 WLog_Print(log, WLOG_ERROR,
"2.2.3.1 ReadCache_Return cbDataLen (%" PRIu32
") > 65536",
4598 return SCARD_E_INVALID_PARAMETER;
4601 Stream_Write_UINT32(s, cbDataLen);
4602 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
4603 return SCARD_E_NO_MEMORY;
4605 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
4606 if (status != SCARD_S_SUCCESS)
4608 return ret->ReturnCode;
4614 wLog* log = scard_log();
4617 smartcard_trace_context_call(log, call, name);
4619 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4620 if (status != SCARD_S_SUCCESS)
4623 return smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4629 wLog* log = scard_log();
4632 smartcard_trace_list_readers_call(log, call, unicode);
4634 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4635 if (status != SCARD_S_SUCCESS)
4638 if (!Stream_EnsureRemainingCapacity(s, 4))
4639 return SCARD_E_NO_MEMORY;
4641 Stream_Write_UINT32(s, call->cBytes);
4642 if (call->cBytes > 65536)
4644 WLog_Print(log, WLOG_ERROR,
"2.2.2.4 ListReaders_Call cBytes(%" PRIu32
") > 65536",
4646 return SCARD_E_INVALID_PARAMETER;
4649 if (!smartcard_ndr_pointer_write(s, &index, call->cBytes))
4650 return SCARD_E_NO_MEMORY;
4652 if (!Stream_EnsureRemainingCapacity(s, 8))
4653 return SCARD_E_NO_MEMORY;
4655 Stream_Write_INT32(s, call->fmszReadersIsNULL);
4656 Stream_Write_UINT32(s, call->cchReaders);
4658 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4659 if (status != SCARD_S_SUCCESS)
4662 if (call->cBytes > 0)
4664 status = smartcard_ndr_write(s, call->mszGroups, call->cBytes, 1, NDR_PTR_SIMPLE);
4665 if (status != SCARD_S_SUCCESS)
4669 return SCARD_S_SUCCESS;
4672WINPR_ATTR_NODISCARD
static LONG
4674 UINT32 cReaders, UINT32* ptrIndex)
4676 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
4678 if (!Stream_EnsureRemainingCapacity(s, 4))
4679 return SCARD_E_NO_MEMORY;
4681 Stream_Write_UINT32(s, cReaders);
4683 for (UINT32 i = 0; i < cReaders; i++)
4687 if (!Stream_EnsureRemainingCapacity(s, 52))
4688 return SCARD_E_NO_MEMORY;
4690 const UINT32 nameLen = state->szReader ? (UINT32)(strlen(state->szReader) + 1) : 0;
4691 if (!smartcard_ndr_pointer_write(s, ptrIndex, nameLen))
4692 return SCARD_E_NO_MEMORY;
4694 Stream_Write_UINT32(s, state->dwCurrentState);
4695 Stream_Write_UINT32(s, state->dwEventState);
4696 if (state->cbAtr > 36)
4698 WLog_Print(log, WLOG_WARN,
"2.2.2.12 GetStatusChangeW_Call cbAtr(%" PRIu32
") > 36",
4700 return SCARD_E_INVALID_PARAMETER;
4702 Stream_Write_UINT32(s, state->cbAtr);
4703 Stream_Write(s, state->rgbAtr, 36);
4706 for (UINT32 i = 0; i < cReaders; i++)
4710 if (state->szReader)
4712 const UINT32 nameLen = (UINT32)(strlen(state->szReader) + 1);
4713 LONG status = smartcard_ndr_write_a(s, state->szReader, nameLen, NDR_PTR_FULL);
4714 if (status != SCARD_S_SUCCESS)
4719 return SCARD_S_SUCCESS;
4722WINPR_ATTR_NODISCARD
static LONG
4724 UINT32 cReaders, UINT32* ptrIndex)
4726 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
4728 if (!Stream_EnsureRemainingCapacity(s, 4))
4729 return SCARD_E_NO_MEMORY;
4731 Stream_Write_UINT32(s, cReaders);
4733 for (UINT32 i = 0; i < cReaders; i++)
4737 if (!Stream_EnsureRemainingCapacity(s, 52))
4738 return SCARD_E_NO_MEMORY;
4740 const UINT32 nameLen = state->szReader ? (UINT32)(_wcslen(state->szReader) + 1) : 0;
4741 if (!smartcard_ndr_pointer_write(s, ptrIndex, nameLen))
4742 return SCARD_E_NO_MEMORY;
4744 Stream_Write_UINT32(s, state->dwCurrentState);
4745 Stream_Write_UINT32(s, state->dwEventState);
4746 if (state->cbAtr > 36)
4748 WLog_Print(log, WLOG_WARN,
"2.2.2.12 GetStatusChangeW_Call cbAtr(%" PRIu32
") > 36",
4750 return SCARD_E_INVALID_PARAMETER;
4752 Stream_Write_UINT32(s, state->cbAtr);
4753 Stream_Write(s, state->rgbAtr, 36);
4756 for (UINT32 i = 0; i < cReaders; i++)
4760 if (state->szReader)
4762 const UINT32 nameLen = (UINT32)(_wcslen(state->szReader) + 1);
4763 LONG status = smartcard_ndr_write_w(s, state->szReader, nameLen, NDR_PTR_FULL);
4764 if (status != SCARD_S_SUCCESS)
4769 return SCARD_S_SUCCESS;
4775 wLog* log = scard_log();
4778 smartcard_trace_get_status_change_a_call(log, call);
4780 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4781 if (status != SCARD_S_SUCCESS)
4784 if (!Stream_EnsureRemainingCapacity(s, 8))
4785 return SCARD_E_NO_MEMORY;
4787 Stream_Write_UINT32(s, call->dwTimeOut);
4788 Stream_Write_UINT32(s, call->cReaders);
4789 if (call->cReaders > 11)
4791 WLog_Print(log, WLOG_ERROR,
"2.2.2.11 GetStatusChangeA_Call cReaders (%" PRIu32
") > 11",
4793 return SCARD_E_INVALID_PARAMETER;
4795 if (!smartcard_ndr_pointer_write(s, &index, call->cReaders))
4796 return SCARD_E_NO_MEMORY;
4798 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4799 if (status != SCARD_S_SUCCESS)
4802 if (call->cReaders > 0)
4805 smartcard_pack_reader_state_a(log, s, call->rgReaderStates, call->cReaders, &index);
4806 if (status != SCARD_S_SUCCESS)
4810 return SCARD_S_SUCCESS;
4816 wLog* log = scard_log();
4819 smartcard_trace_get_status_change_w_call(log, call);
4821 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4822 if (status != SCARD_S_SUCCESS)
4825 if (!Stream_EnsureRemainingCapacity(s, 8))
4826 return SCARD_E_NO_MEMORY;
4828 Stream_Write_UINT32(s, call->dwTimeOut);
4829 Stream_Write_UINT32(s, call->cReaders);
4830 if (call->cReaders > 11)
4832 WLog_Print(log, WLOG_ERROR,
"2.2.2.12 GetStatusChangeW_Call cReaders (%" PRIu32
") > 11",
4834 return SCARD_E_INVALID_PARAMETER;
4837 if (!smartcard_ndr_pointer_write(s, &index, call->cReaders))
4838 return SCARD_E_NO_MEMORY;
4840 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4841 if (status != SCARD_S_SUCCESS)
4844 if (call->cReaders > 0)
4847 smartcard_pack_reader_state_w(log, s, call->rgReaderStates, call->cReaders, &index);
4848 if (status != SCARD_S_SUCCESS)
4852 return SCARD_S_SUCCESS;
4858 wLog* log = scard_log();
4861 smartcard_trace_connect_a_call(log, call);
4863 const UINT32 readerLen = call->szReader ? (UINT32)(strlen(call->szReader) + 1) : 0;
4864 if (!smartcard_ndr_pointer_write(s, &index, readerLen))
4865 return SCARD_E_NO_MEMORY;
4868 smartcard_pack_redir_scard_context(log, s, &call->Common.handles.hContext, &index);
4869 if (status != SCARD_S_SUCCESS)
4872 if (!Stream_EnsureRemainingCapacity(s, 8))
4873 return SCARD_E_NO_MEMORY;
4875 Stream_Write_UINT32(s, call->Common.dwShareMode);
4876 Stream_Write_UINT32(s, call->Common.dwPreferredProtocols);
4880 status = smartcard_ndr_write_a(s, call->szReader, readerLen, NDR_PTR_FULL);
4881 if (status != SCARD_S_SUCCESS)
4885 return smartcard_pack_redir_scard_context_ref(log, s, &call->Common.handles.hContext);
4891 wLog* log = scard_log();
4894 smartcard_trace_connect_w_call(log, call);
4896 const UINT32 readerLen = call->szReader ? (UINT32)(_wcslen(call->szReader) + 1) : 0;
4897 if (!smartcard_ndr_pointer_write(s, &index, readerLen))
4898 return SCARD_E_NO_MEMORY;
4901 smartcard_pack_redir_scard_context(log, s, &call->Common.handles.hContext, &index);
4902 if (status != SCARD_S_SUCCESS)
4905 if (!Stream_EnsureRemainingCapacity(s, 8))
4906 return SCARD_E_NO_MEMORY;
4908 Stream_Write_UINT32(s, call->Common.dwShareMode);
4909 Stream_Write_UINT32(s, call->Common.dwPreferredProtocols);
4913 status = smartcard_ndr_write_w(s, call->szReader, readerLen, NDR_PTR_FULL);
4914 if (status != SCARD_S_SUCCESS)
4918 return smartcard_pack_redir_scard_context_ref(log, s, &call->Common.handles.hContext);
4924 wLog* log = scard_log();
4927 smartcard_trace_control_call(log, call);
4929 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4930 if (status != SCARD_S_SUCCESS)
4933 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
4934 if (status != SCARD_S_SUCCESS)
4937 if (!Stream_EnsureRemainingCapacity(s, 8))
4938 return SCARD_E_NO_MEMORY;
4940 Stream_Write_UINT32(s, call->dwControlCode);
4941 Stream_Write_UINT32(s, call->cbInBufferSize);
4942 if (!smartcard_ndr_pointer_write(s, &index, call->cbInBufferSize))
4943 return SCARD_E_NO_MEMORY;
4945 Stream_Write_INT32(s, call->fpvOutBufferIsNULL);
4946 Stream_Write_UINT32(s, call->cbOutBufferSize);
4948 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4949 if (status != SCARD_S_SUCCESS)
4952 status = smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
4953 if (status != SCARD_S_SUCCESS)
4956 if (call->cbInBufferSize)
4958 status = smartcard_ndr_write(s, call->pvInBuffer, call->cbInBufferSize, 1, NDR_PTR_SIMPLE);
4959 if (status != SCARD_S_SUCCESS)
4970 wLog* log = scard_log();
4973 smartcard_trace_hcard_and_disposition_call(log, call, name);
4975 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
4976 if (status != SCARD_S_SUCCESS)
4979 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
4980 if (status != SCARD_S_SUCCESS)
4983 if (!Stream_EnsureRemainingCapacity(s, 4))
4984 return SCARD_E_NO_MEMORY;
4986 Stream_Write_UINT32(s, call->dwDisposition);
4988 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
4989 if (status != SCARD_S_SUCCESS)
4992 return smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
4998 wLog* log = scard_log();
5001 smartcard_trace_transmit_call(log, call);
5003 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
5004 if (status != SCARD_S_SUCCESS)
5007 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
5008 if (status != SCARD_S_SUCCESS)
5011 UINT32 cbExtraBytes = 0;
5012 const BYTE* pbExtraBytes =
nullptr;
5013 if (call->pioSendPci)
5015 cbExtraBytes = (UINT32)(call->pioSendPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
5016 if (cbExtraBytes > 0)
5020 if (!Stream_EnsureRemainingCapacity(s, 32))
5021 return SCARD_E_NO_MEMORY;
5023 Stream_Write_UINT32(s, call->pioSendPci ? call->pioSendPci->dwProtocol : 0);
5024 Stream_Write_UINT32(s, cbExtraBytes);
5025 if (!smartcard_ndr_pointer_write(s, &index, cbExtraBytes))
5026 return SCARD_E_NO_MEMORY;
5028 Stream_Write_UINT32(s, call->cbSendLength);
5029 if (!smartcard_ndr_pointer_write(s, &index, call->cbSendLength))
5030 return SCARD_E_NO_MEMORY;
5032 const UINT32 recvPciLen = call->pioRecvPci ? (UINT32)call->pioRecvPci->cbPciLength : 0;
5033 if (!smartcard_ndr_pointer_write(s, &index, recvPciLen))
5034 return SCARD_E_NO_MEMORY;
5036 Stream_Write_INT32(s, call->fpbRecvBufferIsNULL);
5037 Stream_Write_UINT32(s, call->cbRecvLength);
5039 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
5040 if (status != SCARD_S_SUCCESS)
5043 status = smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
5044 if (status != SCARD_S_SUCCESS)
5047 if (cbExtraBytes > 0)
5049 status = smartcard_ndr_write(s, pbExtraBytes, cbExtraBytes, 1, NDR_PTR_SIMPLE);
5050 if (status != SCARD_S_SUCCESS)
5054 if (call->cbSendLength > 0)
5056 status = smartcard_ndr_write(s, call->pbSendBuffer, call->cbSendLength, 1, NDR_PTR_SIMPLE);
5057 if (status != SCARD_S_SUCCESS)
5061 if (call->pioRecvPci && recvPciLen > 0)
5063 UINT32 cbRecvExtra = (UINT32)(call->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
5064 const BYTE* pbRecvExtra = &((
const BYTE*)call->pioRecvPci)[
sizeof(
SCARD_IO_REQUEST)];
5066 if (!Stream_EnsureRemainingCapacity(s, 12))
5067 return SCARD_E_NO_MEMORY;
5069 Stream_Write_UINT32(s, call->pioRecvPci->dwProtocol);
5070 Stream_Write_UINT32(s, cbRecvExtra);
5071 if (!smartcard_ndr_pointer_write(s, &index, cbRecvExtra))
5072 return SCARD_E_NO_MEMORY;
5074 if (cbRecvExtra > 0)
5076 status = smartcard_ndr_write(s, pbRecvExtra, cbRecvExtra, 1, NDR_PTR_SIMPLE);
5077 if (status != SCARD_S_SUCCESS)
5082 return SCARD_S_SUCCESS;
5088 wLog* log = scard_log();
5091 smartcard_trace_get_attrib_call(log, call);
5093 LONG status = smartcard_pack_redir_scard_context(log, s, &call->handles.hContext, &index);
5094 if (status != SCARD_S_SUCCESS)
5097 status = smartcard_pack_redir_scard_handle(log, s, &call->handles.hCard, &index);
5098 if (status != SCARD_S_SUCCESS)
5101 if (!Stream_EnsureRemainingCapacity(s, 12))
5102 return STATUS_NO_MEMORY;
5104 Stream_Write_UINT32(s, call->dwAttrId);
5105 Stream_Write_INT32(s, call->fpbAttrIsNULL);
5106 Stream_Write_UINT32(s, call->cbAttrLen);
5108 status = smartcard_pack_redir_scard_context_ref(log, s, &call->handles.hContext);
5109 if (status != SCARD_S_SUCCESS)
5112 return smartcard_pack_redir_scard_handle_ref(log, s, &call->handles.hCard);
5118 wLog* log = scard_log();
5120 UINT32 mszNdrPtr = 0;
5122 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
5123 return STATUS_BUFFER_TOO_SMALL;
5125 const UINT32 cBytes = Stream_Get_UINT32(s);
5127 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
5128 return ERROR_INVALID_DATA;
5132 LONG status = smartcard_ndr_read(log, s, &ret->msz, cBytes, 1, NDR_PTR_SIMPLE);
5133 if (status != SCARD_S_SUCCESS)
5135 ret->cBytes = cBytes;
5138 smartcard_trace_list_readers_return(log, ret, unicode);
5139 return SCARD_S_SUCCESS;
5146 wLog* log = scard_log();
5150 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
5151 return STATUS_BUFFER_TOO_SMALL;
5153 Stream_Read_UINT32(s, ret->cReaders);
5154 if (ret->cReaders > 10)
5156 WLog_Print(log, WLOG_ERROR,
5157 "2.2.3.5 LocateCards_Return and GetStatusChange_Return cReaders(%" PRIu32
5160 return SCARD_E_INVALID_PARAMETER;
5163 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
5164 return ERROR_INVALID_DATA;
5166 if (ndrPtr && ret->cReaders > 0)
5169 smartcard_ndr_read_state(log, s, &ret->rgReaderStates, ret->cReaders, NDR_PTR_SIMPLE);
5170 if (status != SCARD_S_SUCCESS)
5174 ret->rgReaderStates =
nullptr;
5176 smartcard_trace_get_status_change_return(log, ret, unicode);
5177 return SCARD_S_SUCCESS;
5183 wLog* log = scard_log();
5185 UINT32 pbContextNdrPtr = 0;
5188 smartcard_unpack_redir_scard_context(log, s, &ret->hContext, &index, &pbContextNdrPtr);
5189 if (status != SCARD_S_SUCCESS)
5192 status = smartcard_unpack_redir_scard_handle(log, s, &ret->hCard, &index);
5193 if (status != SCARD_S_SUCCESS)
5196 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
5197 return STATUS_BUFFER_TOO_SMALL;
5199 Stream_Read_UINT32(s, ret->dwActiveProtocol);
5201 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &ret->hContext);
5202 if (status != SCARD_S_SUCCESS)
5205 status = smartcard_unpack_redir_scard_handle_ref(log, s, &ret->hCard);
5206 if (status != SCARD_S_SUCCESS)
5209 smartcard_trace_connect_return(log, ret);
5210 return SCARD_S_SUCCESS;
5216 wLog* log = scard_log();
5218 UINT32 pvOutBufferNdrPtr = 0;
5220 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
5221 return STATUS_BUFFER_TOO_SMALL;
5223 const UINT32 cbOutBufferSize = Stream_Get_UINT32(s);
5225 if (!smartcard_ndr_pointer_read(log, s, &index, &pvOutBufferNdrPtr))
5226 return ERROR_INVALID_DATA;
5228 if (pvOutBufferNdrPtr && (cbOutBufferSize > 0))
5231 smartcard_ndr_read(log, s, &ret->pvOutBuffer, cbOutBufferSize, 1, NDR_PTR_SIMPLE);
5232 if (status != SCARD_S_SUCCESS)
5234 ret->cbOutBufferSize = cbOutBufferSize;
5236 smartcard_trace_control_return(log, ret);
5237 return SCARD_S_SUCCESS;
5243 wLog* log = scard_log();
5245 UINT32 recvPciNdrPtr = 0;
5246 UINT32 recvBufferNdrPtr = 0;
5248 if (!smartcard_ndr_pointer_read(log, s, &index, &recvPciNdrPtr))
5249 return ERROR_INVALID_DATA;
5251 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
5252 return STATUS_BUFFER_TOO_SMALL;
5254 const UINT32 cbRecvLength = Stream_Get_UINT32(s);
5255 if (cbRecvLength > 66560)
5257 WLog_Print(log, WLOG_ERROR,
"2.2.3.11 Transmit_Return cbRecvLength(%" PRIu32
") > 66560",
5259 return SCARD_E_INVALID_PARAMETER;
5262 if (!smartcard_ndr_pointer_read(log, s, &index, &recvBufferNdrPtr))
5263 return ERROR_INVALID_DATA;
5267 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
5268 return STATUS_BUFFER_TOO_SMALL;
5270 UINT32 dwProtocol = 0;
5271 UINT32 cbExtraBytes = 0;
5272 Stream_Read_UINT32(s, dwProtocol);
5273 Stream_Read_UINT32(s, cbExtraBytes);
5275 UINT32 pbExtraBytesNdrPtr = 0;
5276 if (!smartcard_ndr_pointer_read(log, s, &index, &pbExtraBytesNdrPtr))
5277 return ERROR_INVALID_DATA;
5279 if (pbExtraBytesNdrPtr)
5281 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
5282 return STATUS_BUFFER_TOO_SMALL;
5285 Stream_Read_UINT32(s, length);
5286 if (length != cbExtraBytes)
5288 WLog_Print(log, WLOG_WARN,
5289 "Transmit_Return unexpected length: Actual: %" PRIu32
5290 ", Expected: %" PRIu32
" (pioRecvPci.cbExtraBytes)",
5291 length, cbExtraBytes);
5292 return STATUS_INVALID_PARAMETER;
5295 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, cbExtraBytes))
5296 return STATUS_BUFFER_TOO_SMALL;
5299 if (!ret->pioRecvPci)
5300 return SCARD_E_NO_MEMORY;
5302 ret->pioRecvPci->dwProtocol = dwProtocol;
5303 ret->pioRecvPci->cbPciLength = (DWORD)(
sizeof(
SCARD_IO_REQUEST) + cbExtraBytes);
5306 Stream_Read(s, pbExtraBytes, length);
5307 if (smartcard_unpack_read_size_align(s, cbExtraBytes, 4) < 0)
5308 return STATUS_INVALID_PARAMETER;
5313 if (!ret->pioRecvPci)
5314 return SCARD_E_NO_MEMORY;
5316 ret->pioRecvPci->dwProtocol = dwProtocol;
5321 if (recvBufferNdrPtr && (cbRecvLength > 0))
5324 smartcard_ndr_read(log, s, &ret->pbRecvBuffer, cbRecvLength, 1, NDR_PTR_SIMPLE);
5325 if (status != SCARD_S_SUCCESS)
5327 ret->cbRecvLength = cbRecvLength;
5330 smartcard_trace_transmit_return(log, ret);
5331 return SCARD_S_SUCCESS;
5337 wLog* log = scard_log();
5339 UINT32 pbAttrPtr = 0;
5341 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
5342 return STATUS_BUFFER_TOO_SMALL;
5344 const UINT32 cbAttrLen = Stream_Get_UINT32(s);
5345 if (cbAttrLen > 65536)
5347 WLog_Print(log, WLOG_ERROR,
"2.2.3.12 GetAttrib_Return cbAttrLen(%" PRIu32
") > 65536",
5349 return SCARD_E_INVALID_PARAMETER;
5352 if (!smartcard_ndr_pointer_read(log, s, &index, &pbAttrPtr))
5353 return ERROR_INVALID_DATA;
5355 LONG status = smartcard_ndr_read(log, s, &ret->pbAttr, cbAttrLen, 1, NDR_PTR_SIMPLE);
5356 if (status != SCARD_S_SUCCESS)
5358 ret->cbAttrLen = cbAttrLen;
5360 smartcard_trace_get_attrib_return(log, ret, 0);
5361 return SCARD_S_SUCCESS;
5364BOOL smartcard_reader_state_return_is_valid_ex(
size_t pos,
const ReaderState_Return* val,
5365 const char* file,
size_t line,
const char* fkt)
5369 WLog_Print_dbg_tag(SCARD_TAG, WLOG_WARN, line, file, fkt,
"[%" PRIuz
"] val = nullptr",
5373 if (val->cbAtr >
sizeof(val->rgbAtr))
5375 WLog_Print_dbg_tag(SCARD_TAG, WLOG_WARN, line, file, fkt,
5376 "[%" PRIuz
"] val->cbAtr=%" PRIu32
", max=%" PRIuz, pos, val->cbAtr,
5377 sizeof(val->rgbAtr));