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 = NULL;
42 log = WLog_Get(SCARD_TAG);
46#define smartcard_unpack_redir_scard_context(log, s, context, index, ndr) \
47 smartcard_unpack_redir_scard_context_((log), (s), (context), (index), (ndr), __FILE__, \
49#define smartcard_unpack_redir_scard_handle(log, s, context, index) \
50 smartcard_unpack_redir_scard_handle_((log), (s), (context), (index), __FILE__, __func__, \
53static LONG smartcard_unpack_redir_scard_context_(wLog* log,
wStream* s,
55 UINT32* ppbContextNdrPtr,
const char* file,
56 const char* function,
size_t line);
57static LONG smartcard_pack_redir_scard_context(wLog* log,
wStream* s,
60 UINT32* index,
const char* file,
61 const char* function,
size_t line);
62static LONG smartcard_pack_redir_scard_handle(wLog* log,
wStream* s,
64static LONG smartcard_unpack_redir_scard_context_ref(wLog* log,
wStream* s, UINT32 pbContextNdrPtr,
66static LONG smartcard_pack_redir_scard_context_ref(wLog* log,
wStream* s,
69static LONG smartcard_unpack_redir_scard_handle_ref(wLog* log,
wStream* s,
71static LONG smartcard_pack_redir_scard_handle_ref(wLog* log,
wStream* s,
83#define smartcard_ndr_pointer_read(log, s, index, ptr) \
84 smartcard_ndr_pointer_read_((log), (s), (index), (ptr), __FILE__, __func__, __LINE__)
85static BOOL smartcard_ndr_pointer_read_(wLog* log,
wStream* s, UINT32* index, UINT32* ptr,
86 const char* file,
const char* fkt,
size_t line)
88 const UINT32 expect = 0x20000 + (*index) * 4;
93 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
96 Stream_Read_UINT32(s, ndrPtr);
102 if (ptr && (ndrPtr == 0))
104 WLog_Print(log, WLOG_WARN,
105 "[%s:%" PRIuz
"] Read context pointer 0x%08" PRIx32
", expected 0x%08" PRIx32,
106 fkt, line, ndrPtr, expect);
110 (*index) = (*index) + 1;
114static LONG smartcard_ndr_read_ex(wLog* log,
wStream* s, BYTE** data,
size_t min,
115 size_t elementSize, ndr_ptr_t type,
size_t* plen)
139 return STATUS_INVALID_PARAMETER;
142 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, required))
143 return STATUS_BUFFER_TOO_SMALL;
148 Stream_Read_UINT32(s, len);
149 Stream_Read_UINT32(s, offset);
150 Stream_Read_UINT32(s, len2);
151 if (len != offset + len2)
153 WLog_Print(log, WLOG_ERROR,
154 "Invalid data when reading full NDR pointer: total=%" PRIuz
155 ", offset=%" PRIuz
", remaining=%" PRIuz,
157 return STATUS_BUFFER_TOO_SMALL;
161 Stream_Read_UINT32(s, len);
163 if ((len != min) && (min > 0))
165 WLog_Print(log, WLOG_ERROR,
166 "Invalid data when reading simple NDR pointer: total=%" PRIuz
167 ", expected=%" PRIuz,
169 return STATUS_BUFFER_TOO_SMALL;
176 return STATUS_INVALID_PARAMETER;
181 WLog_Print(log, WLOG_ERROR,
182 "Invalid length read from NDR pointer, minimum %" PRIuz
", got %" PRIuz, min,
184 return STATUS_DATA_ERROR;
187 if (len > SIZE_MAX / 2)
188 return STATUS_BUFFER_TOO_SMALL;
190 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(log, s, len, elementSize))
191 return STATUS_BUFFER_TOO_SMALL;
198 r = calloc(len +
sizeof(WCHAR),
sizeof(CHAR));
200 return SCARD_E_NO_MEMORY;
201 Stream_Read(s, r, len);
202 const LONG pad = smartcard_unpack_read_size_align(s, len, 4);
207 return STATUS_SUCCESS;
210static LONG smartcard_ndr_read(wLog* log,
wStream* s, BYTE** data,
size_t min,
size_t elementSize,
213 return smartcard_ndr_read_ex(log, s, data, min, elementSize, type, NULL);
216static BOOL smartcard_ndr_pointer_write(
wStream* s, UINT32* index, DWORD length)
218 const UINT32 ndrPtr = 0x20000 + (*index) * 4;
222 if (!Stream_EnsureRemainingCapacity(s, 4))
227 Stream_Write_UINT32(s, ndrPtr);
228 (*index) = (*index) + 1;
231 Stream_Write_UINT32(s, 0);
235static LONG smartcard_ndr_write(
wStream* s,
const BYTE* data, UINT32 size, UINT32 elementSize,
238 const UINT32 offset = 0;
239 const UINT32 len = size;
240 const UINT32 dataLen = size * elementSize;
244 return SCARD_S_SUCCESS;
258 return SCARD_E_INVALID_PARAMETER;
261 if (!Stream_EnsureRemainingCapacity(s, required + dataLen + 4))
262 return STATUS_BUFFER_TOO_SMALL;
267 Stream_Write_UINT32(s, len);
268 Stream_Write_UINT32(s, offset);
269 Stream_Write_UINT32(s, len);
272 Stream_Write_UINT32(s, len);
277 return SCARD_E_INVALID_PARAMETER;
281 Stream_Write(s, data, dataLen);
283 Stream_Zero(s, dataLen);
284 return smartcard_pack_write_size_align(s, len, 4);
296 WINPR_ASSERT(data || (size == 0));
302 size_t min, ndr_ptr_t type)
313static LONG smartcard_ndr_read_fixed_string_a(wLog* log,
wStream* s, CHAR** data,
size_t min,
322 return smartcard_ndr_read(log, s, u.ppv, min,
sizeof(CHAR), type);
325static LONG smartcard_ndr_read_fixed_string_w(wLog* log,
wStream* s, WCHAR** data,
size_t min,
334 return smartcard_ndr_read(log, s, u.ppv, min,
sizeof(WCHAR), type);
337static LONG smartcard_ndr_read_a(wLog* log,
wStream* s, CHAR** data, ndr_ptr_t type)
345 return smartcard_ndr_read(log, s, u.ppv, 0,
sizeof(CHAR), type);
348static LONG smartcard_ndr_read_w(wLog* log,
wStream* s, WCHAR** data, ndr_ptr_t type)
356 return smartcard_ndr_read(log, s, u.ppv, 0,
sizeof(WCHAR), type);
359static LONG smartcard_ndr_read_u(wLog* log,
wStream* s,
UUID** data)
367 return smartcard_ndr_read(log, s, u.ppv, 1,
sizeof(
UUID), NDR_PTR_FIXED);
370static char* smartcard_convert_string_list(
const void* in,
size_t bytes, BOOL unicode)
391 mszA = ConvertMszWCharNToUtf8Alloc(
string.wz, bytes /
sizeof(WCHAR), &length);
397 mszA = (
char*)calloc(bytes,
sizeof(
char));
400 CopyMemory(mszA,
string.sz, bytes - 1);
409 for (
size_t index = 0; index < length - 1; index++)
411 if (mszA[index] ==
'\0')
418static char* smartcard_msz_dump_a(
const char* msz,
size_t len,
char* buffer,
size_t bufferLen)
421 const char* cur = msz;
423 while ((len > 0) && cur && cur[0] !=
'\0' && (bufferLen > 0))
425 size_t clen = strnlen(cur, len);
426 int rc = _snprintf(buf, bufferLen,
"%s", cur);
427 bufferLen -= (size_t)rc;
436static char* smartcard_msz_dump_w(
const WCHAR* msz,
size_t len,
char* buffer,
size_t bufferLen)
441 char* sz = ConvertMszWCharNToUtf8Alloc(msz, len, &szlen);
445 smartcard_msz_dump_a(sz, szlen, buffer, bufferLen);
450static char* smartcard_array_dump(
const void* pd,
size_t len,
char* buffer,
size_t bufferLen)
452 const BYTE* data = pd;
454 char* start = buffer;
456 WINPR_ASSERT(buffer || (bufferLen == 0));
458 if (!data && (len > 0))
460 (void)_snprintf(buffer, bufferLen,
"{ NULL [%" PRIuz
"] }", len);
464 rc = _snprintf(buffer, bufferLen,
"{ ");
465 if ((rc < 0) || ((
size_t)rc >= bufferLen))
468 bufferLen -= (size_t)rc;
470 for (
size_t x = 0; x < len; x++)
472 rc = _snprintf(buffer, bufferLen,
"%02X", data[x]);
473 if ((rc < 0) || ((
size_t)rc >= bufferLen))
476 bufferLen -= (size_t)rc;
479 rc = _snprintf(buffer, bufferLen,
" }");
480 if ((rc < 0) || ((
size_t)rc >= bufferLen))
487static void smartcard_log_redir_handle(wLog* log,
const REDIR_SCARDHANDLE* pHandle)
489 char buffer[128] = { 0 };
491 WINPR_ASSERT(pHandle);
492 WLog_Print(log, g_LogLevel,
" hContext: %s",
493 smartcard_array_dump(pHandle->pbHandle, pHandle->cbHandle, buffer,
sizeof(buffer)));
498 char buffer[128] = { 0 };
500 WINPR_ASSERT(phContext);
502 log, g_LogLevel,
"hContext: %s",
503 smartcard_array_dump(phContext->pbContext, phContext->cbContext, buffer,
sizeof(buffer)));
506static void smartcard_trace_context_and_string_call_a(wLog* log,
const char* name,
510 if (!WLog_IsLevelActive(log, g_LogLevel))
513 WLog_Print(log, g_LogLevel,
"%s {", name);
514 smartcard_log_context(log, phContext);
515 WLog_Print(log, g_LogLevel,
" sz=%s", sz);
517 WLog_Print(log, g_LogLevel,
"}");
520static void smartcard_trace_context_and_string_call_w(wLog* log,
const char* name,
524 char tmp[1024] = { 0 };
526 if (!WLog_IsLevelActive(log, g_LogLevel))
530 (void)ConvertWCharToUtf8(sz, tmp, ARRAYSIZE(tmp));
532 WLog_Print(log, g_LogLevel,
"%s {", name);
533 smartcard_log_context(log, phContext);
534 WLog_Print(log, g_LogLevel,
" sz=%s", tmp);
535 WLog_Print(log, g_LogLevel,
"}");
538static void smartcard_trace_context_call(wLog* log,
const Context_Call* call,
const char* name)
542 if (!WLog_IsLevelActive(log, g_LogLevel))
545 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
546 smartcard_log_context(log, &call->handles.hContext);
548 WLog_Print(log, g_LogLevel,
"}");
556 if (!WLog_IsLevelActive(log, g_LogLevel))
559 WLog_Print(log, g_LogLevel,
"ListReaderGroups%s_Call {", unicode ?
"W" :
"A");
560 smartcard_log_context(log, &call->handles.hContext);
562 WLog_Print(log, g_LogLevel,
"fmszGroupsIsNULL: %" PRId32
" cchGroups: 0x%08" PRIx32,
563 call->fmszGroupsIsNULL, call->cchGroups);
564 WLog_Print(log, g_LogLevel,
"}");
567static void dump_reader_states_return(wLog* log,
const ReaderState_Return* rgReaderStates,
570 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
571 for (UINT32 index = 0; index < cReaders; index++)
573 char buffer[1024] = { 0 };
576 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
577 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
578 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
579 szCurrentState, readerState->dwCurrentState);
580 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
581 szEventState, readerState->dwEventState);
582 free(szCurrentState);
586 log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { %s }", index,
588 smartcard_array_dump(readerState->rgbAtr, readerState->cbAtr, buffer,
sizeof(buffer)));
595 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
596 for (UINT32 index = 0; index < cReaders; index++)
598 char buffer[1024] = { 0 };
602 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
603 readerState->szReader, readerState->cbAtr);
604 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
605 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
606 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
607 szCurrentState, readerState->dwCurrentState);
608 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
609 szEventState, readerState->dwEventState);
610 free(szCurrentState);
614 log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { %s }", index,
616 smartcard_array_dump(readerState->rgbAtr, readerState->cbAtr, buffer,
sizeof(buffer)));
623 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
624 for (UINT32 index = 0; index < cReaders; index++)
626 char buffer[1024] = { 0 };
629 (void)ConvertWCharToUtf8(readerState->szReader, buffer,
sizeof(buffer));
630 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
631 buffer, readerState->cbAtr);
632 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
633 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
634 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
635 szCurrentState, readerState->dwCurrentState);
636 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
637 szEventState, readerState->dwEventState);
638 free(szCurrentState);
642 log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { %s }", index,
644 smartcard_array_dump(readerState->rgbAtr, readerState->cbAtr, buffer,
sizeof(buffer)));
652 if (!WLog_IsLevelActive(log, g_LogLevel))
655 WLog_Print(log, g_LogLevel,
"GetStatusChangeW_Call {");
656 smartcard_log_context(log, &call->handles.hContext);
658 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
661 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
663 WLog_Print(log, g_LogLevel,
"}");
671 if (!WLog_IsLevelActive(log, g_LogLevel))
674 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
676 WLog_Print(log, g_LogLevel,
"ListReaderGroups%s_Return {", unicode ?
"W" :
"A");
677 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIx32
")",
678 SCardGetErrorString(ret->ReturnCode),
679 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
680 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
681 WLog_Print(log, g_LogLevel,
"}");
685static void smartcard_trace_list_readers_call(wLog* log,
const ListReaders_Call* call, BOOL unicode)
689 if (!WLog_IsLevelActive(log, g_LogLevel))
692 char* mszGroupsA = smartcard_convert_string_list(call->mszGroups, call->cBytes, unicode);
694 WLog_Print(log, g_LogLevel,
"ListReaders%s_Call {", unicode ?
"W" :
"A");
695 smartcard_log_context(log, &call->handles.hContext);
697 WLog_Print(log, g_LogLevel,
698 "cBytes: %" PRIu32
" mszGroups: %s fmszReadersIsNULL: %" PRId32
699 " cchReaders: 0x%08" PRIX32
"",
700 call->cBytes, mszGroupsA, call->fmszReadersIsNULL, call->cchReaders);
701 WLog_Print(log, g_LogLevel,
"}");
706static void smartcard_trace_locate_cards_by_atr_a_call(wLog* log,
711 if (!WLog_IsLevelActive(log, g_LogLevel))
714 WLog_Print(log, g_LogLevel,
"LocateCardsByATRA_Call {");
715 smartcard_log_context(log, &call->handles.hContext);
717 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
719 WLog_Print(log, g_LogLevel,
"}");
722static void smartcard_trace_locate_cards_a_call(wLog* log,
const LocateCardsA_Call* call)
724 char buffer[8192] = { 0 };
728 if (!WLog_IsLevelActive(log, g_LogLevel))
731 WLog_Print(log, g_LogLevel,
"LocateCardsA_Call {");
732 smartcard_log_context(log, &call->handles.hContext);
733 WLog_Print(log, g_LogLevel,
" cBytes=%" PRIu32, call->cBytes);
734 WLog_Print(log, g_LogLevel,
" mszCards=%s",
735 smartcard_msz_dump_a(call->mszCards, call->cBytes, buffer,
sizeof(buffer)));
736 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, call->cReaders);
737 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
739 WLog_Print(log, g_LogLevel,
"}");
742static void smartcard_trace_locate_cards_return(wLog* log,
const LocateCards_Return* ret)
746 if (!WLog_IsLevelActive(log, g_LogLevel))
749 WLog_Print(log, g_LogLevel,
"LocateCards_Return {");
750 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
751 SCardGetErrorString(ret->ReturnCode),
752 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
754 if (ret->ReturnCode == SCARD_S_SUCCESS)
756 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, ret->cReaders);
758 WLog_Print(log, g_LogLevel,
"}");
765 if (!WLog_IsLevelActive(log, g_LogLevel))
768 WLog_Print(log, g_LogLevel,
"GetReaderIcon_Return {");
769 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
770 SCardGetErrorString(ret->ReturnCode),
771 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
773 if (ret->ReturnCode == SCARD_S_SUCCESS)
775 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, ret->cbDataLen);
777 WLog_Print(log, g_LogLevel,
"}");
784 if (!WLog_IsLevelActive(log, g_LogLevel))
787 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Return {");
788 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
789 SCardGetErrorString(ret->ReturnCode),
790 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
792 WLog_Print(log, g_LogLevel,
" cTransmitCount=%" PRIu32, ret->cTransmitCount);
793 WLog_Print(log, g_LogLevel,
"}");
796static void smartcard_trace_read_cache_return(wLog* log,
const ReadCache_Return* ret)
800 if (!WLog_IsLevelActive(log, g_LogLevel))
803 WLog_Print(log, g_LogLevel,
"ReadCache_Return {");
804 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
805 SCardGetErrorString(ret->ReturnCode),
806 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
808 if (ret->ReturnCode == SCARD_S_SUCCESS)
810 char buffer[1024] = { 0 };
811 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, ret->cbDataLen);
812 WLog_Print(log, g_LogLevel,
" cbData: %s",
813 smartcard_array_dump(ret->pbData, ret->cbDataLen, buffer,
sizeof(buffer)));
815 WLog_Print(log, g_LogLevel,
"}");
818static void smartcard_trace_locate_cards_w_call(wLog* log,
const LocateCardsW_Call* call)
821 char buffer[8192] = { 0 };
823 if (!WLog_IsLevelActive(log, g_LogLevel))
826 WLog_Print(log, g_LogLevel,
"LocateCardsW_Call {");
827 smartcard_log_context(log, &call->handles.hContext);
828 WLog_Print(log, g_LogLevel,
" cBytes=%" PRIu32, call->cBytes);
829 WLog_Print(log, g_LogLevel,
" sz2=%s",
830 smartcard_msz_dump_w(call->mszCards, call->cBytes, buffer,
sizeof(buffer)));
831 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, call->cReaders);
832 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
833 WLog_Print(log, g_LogLevel,
"}");
836static void smartcard_trace_list_readers_return(wLog* log,
const ListReaders_Return* ret,
841 if (!WLog_IsLevelActive(log, g_LogLevel))
844 WLog_Print(log, g_LogLevel,
"ListReaders%s_Return {", unicode ?
"W" :
"A");
845 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
846 SCardGetErrorString(ret->ReturnCode),
847 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
849 if (ret->ReturnCode != SCARD_S_SUCCESS)
851 WLog_Print(log, g_LogLevel,
"}");
855 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
857 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
858 WLog_Print(log, g_LogLevel,
"}");
867 if (!WLog_IsLevelActive(log, g_LogLevel))
870 WLog_Print(log, g_LogLevel,
"GetStatusChange%s_Return {", unicode ?
"W" :
"A");
871 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
872 SCardGetErrorString(ret->ReturnCode),
873 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
874 WLog_Print(log, g_LogLevel,
" cReaders: %" PRIu32
"", ret->cReaders);
876 dump_reader_states_return(log, ret->rgReaderStates, ret->cReaders);
878 if (!ret->rgReaderStates && (ret->cReaders > 0))
880 WLog_Print(log, g_LogLevel,
" [INVALID STATE] rgReaderStates=NULL, cReaders=%" PRIu32,
883 else if (ret->ReturnCode != SCARD_S_SUCCESS)
885 WLog_Print(log, g_LogLevel,
" [INVALID RETURN] rgReaderStates, cReaders=%" PRIu32,
890 for (UINT32 index = 0; index < ret->cReaders; index++)
892 char buffer[1024] = { 0 };
894 char* szCurrentState = SCardGetReaderStateString(rgReaderState->dwCurrentState);
895 char* szEventState = SCardGetReaderStateString(rgReaderState->dwEventState);
896 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")",
897 index, szCurrentState, rgReaderState->dwCurrentState);
898 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")",
899 index, szEventState, rgReaderState->dwEventState);
900 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: cbAtr: %" PRIu32
" rgbAtr: %s", index,
901 rgReaderState->cbAtr,
902 smartcard_array_dump(rgReaderState->rgbAtr, rgReaderState->cbAtr, buffer,
904 free(szCurrentState);
909 WLog_Print(log, g_LogLevel,
"}");
912static void smartcard_trace_context_and_two_strings_a_call(wLog* log,
917 if (!WLog_IsLevelActive(log, g_LogLevel))
920 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
921 smartcard_log_context(log, &call->handles.hContext);
922 WLog_Print(log, g_LogLevel,
" sz1=%s", call->sz1);
923 WLog_Print(log, g_LogLevel,
" sz2=%s", call->sz2);
924 WLog_Print(log, g_LogLevel,
"}");
927static void smartcard_trace_context_and_two_strings_w_call(wLog* log,
931 char sz1[1024] = { 0 };
932 char sz2[1024] = { 0 };
934 if (!WLog_IsLevelActive(log, g_LogLevel))
937 (void)ConvertWCharToUtf8(call->sz1, sz1, ARRAYSIZE(sz1));
939 (void)ConvertWCharToUtf8(call->sz2, sz2, ARRAYSIZE(sz2));
941 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
942 smartcard_log_context(log, &call->handles.hContext);
943 WLog_Print(log, g_LogLevel,
" sz1=%s", sz1);
944 WLog_Print(log, g_LogLevel,
" sz2=%s", sz2);
945 WLog_Print(log, g_LogLevel,
"}");
952 if (!WLog_IsLevelActive(log, g_LogLevel))
955 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Call {");
956 smartcard_log_context(log, &call->handles.hContext);
957 smartcard_log_redir_handle(log, &call->handles.hCard);
959 WLog_Print(log, g_LogLevel,
"}");
962static void smartcard_trace_write_cache_a_call(wLog* log,
const WriteCacheA_Call* call)
965 char buffer[1024] = { 0 };
967 if (!WLog_IsLevelActive(log, g_LogLevel))
970 WLog_Print(log, g_LogLevel,
"WriteCacheA_Call {");
972 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
974 smartcard_log_context(log, &call->Common.handles.hContext);
976 log, g_LogLevel,
"..CardIdentifier=%s",
977 smartcard_array_dump(call->Common.CardIdentifier,
sizeof(
UUID), buffer,
sizeof(buffer)));
978 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
979 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
981 log, g_LogLevel,
" pbData=%s",
982 smartcard_array_dump(call->Common.pbData, call->Common.cbDataLen, buffer,
sizeof(buffer)));
983 WLog_Print(log, g_LogLevel,
"}");
986static void smartcard_trace_write_cache_w_call(wLog* log,
const WriteCacheW_Call* call)
989 char tmp[1024] = { 0 };
990 char buffer[1024] = { 0 };
992 if (!WLog_IsLevelActive(log, g_LogLevel))
995 WLog_Print(log, g_LogLevel,
"WriteCacheW_Call {");
997 if (call->szLookupName)
998 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
999 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
1001 smartcard_log_context(log, &call->Common.handles.hContext);
1003 log, g_LogLevel,
"..CardIdentifier=%s",
1004 smartcard_array_dump(call->Common.CardIdentifier,
sizeof(
UUID), buffer,
sizeof(buffer)));
1005 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1006 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1008 log, g_LogLevel,
" pbData=%s",
1009 smartcard_array_dump(call->Common.pbData, call->Common.cbDataLen, buffer,
sizeof(buffer)));
1010 WLog_Print(log, g_LogLevel,
"}");
1013static void smartcard_trace_read_cache_a_call(wLog* log,
const ReadCacheA_Call* call)
1016 char buffer[1024] = { 0 };
1018 if (!WLog_IsLevelActive(log, g_LogLevel))
1021 WLog_Print(log, g_LogLevel,
"ReadCacheA_Call {");
1023 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
1024 smartcard_log_context(log, &call->Common.handles.hContext);
1026 log, g_LogLevel,
"..CardIdentifier=%s",
1027 smartcard_array_dump(call->Common.CardIdentifier,
sizeof(
UUID), buffer,
sizeof(buffer)));
1028 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1029 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1030 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1032 WLog_Print(log, g_LogLevel,
"}");
1035static void smartcard_trace_read_cache_w_call(wLog* log,
const ReadCacheW_Call* call)
1038 char tmp[1024] = { 0 };
1039 char buffer[1024] = { 0 };
1041 if (!WLog_IsLevelActive(log, g_LogLevel))
1044 WLog_Print(log, g_LogLevel,
"ReadCacheW_Call {");
1045 if (call->szLookupName)
1046 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
1047 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
1049 smartcard_log_context(log, &call->Common.handles.hContext);
1051 log, g_LogLevel,
"..CardIdentifier=%s",
1052 smartcard_array_dump(call->Common.CardIdentifier,
sizeof(
UUID), buffer,
sizeof(buffer)));
1053 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1054 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1055 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1057 WLog_Print(log, g_LogLevel,
"}");
1060static void smartcard_trace_transmit_call(wLog* log,
const Transmit_Call* call)
1063 UINT32 cbExtraBytes = 0;
1064 BYTE* pbExtraBytes = NULL;
1066 if (!WLog_IsLevelActive(log, g_LogLevel))
1069 WLog_Print(log, g_LogLevel,
"Transmit_Call {");
1070 smartcard_log_context(log, &call->handles.hContext);
1071 smartcard_log_redir_handle(log, &call->handles.hCard);
1073 if (call->pioSendPci)
1075 cbExtraBytes = (UINT32)(call->pioSendPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1077 WLog_Print(log, g_LogLevel,
"pioSendPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1078 call->pioSendPci->dwProtocol, cbExtraBytes);
1082 char buffer[1024] = { 0 };
1083 WLog_Print(log, g_LogLevel,
"pbExtraBytes: %s",
1084 smartcard_array_dump(pbExtraBytes, cbExtraBytes, buffer,
sizeof(buffer)));
1089 WLog_Print(log, g_LogLevel,
"pioSendPci: null");
1092 WLog_Print(log, g_LogLevel,
"cbSendLength: %" PRIu32
"", call->cbSendLength);
1094 if (call->pbSendBuffer)
1096 char buffer[1024] = { 0 };
1098 log, g_LogLevel,
"pbSendBuffer: %s",
1099 smartcard_array_dump(call->pbSendBuffer, call->cbSendLength, buffer,
sizeof(buffer)));
1103 WLog_Print(log, g_LogLevel,
"pbSendBuffer: null");
1106 if (call->pioRecvPci)
1108 cbExtraBytes = (UINT32)(call->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1110 WLog_Print(log, g_LogLevel,
"pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1111 call->pioRecvPci->dwProtocol, cbExtraBytes);
1115 char buffer[1024] = { 0 };
1116 WLog_Print(log, g_LogLevel,
"pbExtraBytes: %s",
1117 smartcard_array_dump(pbExtraBytes, cbExtraBytes, buffer,
sizeof(buffer)));
1122 WLog_Print(log, g_LogLevel,
"pioRecvPci: null");
1125 WLog_Print(log, g_LogLevel,
"fpbRecvBufferIsNULL: %" PRId32
" cbRecvLength: %" PRIu32
"",
1126 call->fpbRecvBufferIsNULL, call->cbRecvLength);
1127 WLog_Print(log, g_LogLevel,
"}");
1130static void smartcard_trace_locate_cards_by_atr_w_call(wLog* log,
1135 if (!WLog_IsLevelActive(log, g_LogLevel))
1138 WLog_Print(log, g_LogLevel,
"LocateCardsByATRW_Call {");
1139 smartcard_log_context(log, &call->handles.hContext);
1141 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
1143 WLog_Print(log, g_LogLevel,
"}");
1146static void smartcard_trace_transmit_return(wLog* log,
const Transmit_Return* ret)
1149 UINT32 cbExtraBytes = 0;
1150 BYTE* pbExtraBytes = NULL;
1152 if (!WLog_IsLevelActive(log, g_LogLevel))
1155 WLog_Print(log, g_LogLevel,
"Transmit_Return {");
1156 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1157 SCardGetErrorString(ret->ReturnCode),
1158 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1160 if (ret->pioRecvPci)
1162 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1164 WLog_Print(log, g_LogLevel,
1165 " pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1166 ret->pioRecvPci->dwProtocol, cbExtraBytes);
1170 char buffer[1024] = { 0 };
1171 WLog_Print(log, g_LogLevel,
" pbExtraBytes: %s",
1172 smartcard_array_dump(pbExtraBytes, cbExtraBytes, buffer,
sizeof(buffer)));
1177 WLog_Print(log, g_LogLevel,
" pioRecvPci: null");
1180 WLog_Print(log, g_LogLevel,
" cbRecvLength: %" PRIu32
"", ret->cbRecvLength);
1182 if (ret->pbRecvBuffer)
1184 char buffer[1024] = { 0 };
1186 log, g_LogLevel,
" pbRecvBuffer: %s",
1187 smartcard_array_dump(ret->pbRecvBuffer, ret->cbRecvLength, buffer,
sizeof(buffer)));
1191 WLog_Print(log, g_LogLevel,
" pbRecvBuffer: null");
1194 WLog_Print(log, g_LogLevel,
"}");
1197static void smartcard_trace_control_return(wLog* log,
const Control_Return* ret)
1201 if (!WLog_IsLevelActive(log, g_LogLevel))
1204 WLog_Print(log, g_LogLevel,
"Control_Return {");
1205 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1206 SCardGetErrorString(ret->ReturnCode),
1207 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1208 WLog_Print(log, g_LogLevel,
" cbOutBufferSize: %" PRIu32
"", ret->cbOutBufferSize);
1210 if (ret->pvOutBuffer)
1212 char buffer[1024] = { 0 };
1214 log, g_LogLevel,
"pvOutBuffer: %s",
1215 smartcard_array_dump(ret->pvOutBuffer, ret->cbOutBufferSize, buffer,
sizeof(buffer)));
1219 WLog_Print(log, g_LogLevel,
"pvOutBuffer: null");
1222 WLog_Print(log, g_LogLevel,
"}");
1225static void smartcard_trace_control_call(wLog* log,
const Control_Call* call)
1229 if (!WLog_IsLevelActive(log, g_LogLevel))
1232 WLog_Print(log, g_LogLevel,
"Control_Call {");
1233 smartcard_log_context(log, &call->handles.hContext);
1234 smartcard_log_redir_handle(log, &call->handles.hCard);
1236 WLog_Print(log, g_LogLevel,
1237 "dwControlCode: 0x%08" PRIX32
" cbInBufferSize: %" PRIu32
1238 " fpvOutBufferIsNULL: %" PRId32
" cbOutBufferSize: %" PRIu32
"",
1239 call->dwControlCode, call->cbInBufferSize, call->fpvOutBufferIsNULL,
1240 call->cbOutBufferSize);
1242 if (call->pvInBuffer)
1244 char buffer[1024] = { 0 };
1246 log, WLOG_DEBUG,
"pbInBuffer: %s",
1247 smartcard_array_dump(call->pvInBuffer, call->cbInBufferSize, buffer,
sizeof(buffer)));
1251 WLog_Print(log, g_LogLevel,
"pvInBuffer: null");
1254 WLog_Print(log, g_LogLevel,
"}");
1257static void smartcard_trace_set_attrib_call(wLog* log,
const SetAttrib_Call* call)
1260 char buffer[8192] = { 0 };
1262 if (!WLog_IsLevelActive(log, g_LogLevel))
1265 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1266 smartcard_log_context(log, &call->handles.hContext);
1267 smartcard_log_redir_handle(log, &call->handles.hCard);
1268 WLog_Print(log, g_LogLevel,
"dwAttrId: 0x%08" PRIX32, call->dwAttrId);
1269 WLog_Print(log, g_LogLevel,
"cbAttrLen: 0x%08" PRIx32, call->cbAttrLen);
1270 WLog_Print(log, g_LogLevel,
"pbAttr: %s",
1271 smartcard_array_dump(call->pbAttr, call->cbAttrLen, buffer,
sizeof(buffer)));
1272 WLog_Print(log, g_LogLevel,
"}");
1275static void smartcard_trace_get_attrib_return(wLog* log,
const GetAttrib_Return* ret,
1279 char buffer[1024] = { 0 };
1281 if (!WLog_IsLevelActive(log, g_LogLevel))
1284 WLog_Print(log, g_LogLevel,
"GetAttrib_Return {");
1285 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1286 SCardGetErrorString(ret->ReturnCode),
1287 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1288 WLog_Print(log, g_LogLevel,
" dwAttrId: %s (0x%08" PRIX32
") cbAttrLen: 0x%08" PRIX32
"",
1289 SCardGetAttributeString(dwAttrId), dwAttrId, ret->cbAttrLen);
1290 WLog_Print(log, g_LogLevel,
" %s",
1291 smartcard_array_dump(ret->pbAttr, ret->cbAttrLen, buffer,
sizeof(buffer)));
1293 WLog_Print(log, g_LogLevel,
"}");
1296static void smartcard_trace_get_attrib_call(wLog* log,
const GetAttrib_Call* call)
1300 if (!WLog_IsLevelActive(log, g_LogLevel))
1303 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1304 smartcard_log_context(log, &call->handles.hContext);
1305 smartcard_log_redir_handle(log, &call->handles.hCard);
1307 WLog_Print(log, g_LogLevel,
1308 "dwAttrId: %s (0x%08" PRIX32
") fpbAttrIsNULL: %" PRId32
" cbAttrLen: 0x%08" PRIX32
1310 SCardGetAttributeString(call->dwAttrId), call->dwAttrId, call->fpbAttrIsNULL,
1312 WLog_Print(log, g_LogLevel,
"}");
1315static void smartcard_trace_status_call(wLog* log,
const Status_Call* call, BOOL unicode)
1319 if (!WLog_IsLevelActive(log, g_LogLevel))
1322 WLog_Print(log, g_LogLevel,
"Status%s_Call {", unicode ?
"W" :
"A");
1323 smartcard_log_context(log, &call->handles.hContext);
1324 smartcard_log_redir_handle(log, &call->handles.hCard);
1326 WLog_Print(log, g_LogLevel,
1327 "fmszReaderNamesIsNULL: %" PRId32
" cchReaderLen: %" PRIu32
" cbAtrLen: %" PRIu32
"",
1328 call->fmszReaderNamesIsNULL, call->cchReaderLen, call->cbAtrLen);
1329 WLog_Print(log, g_LogLevel,
"}");
1332static void smartcard_trace_status_return(wLog* log,
const Status_Return* ret, BOOL unicode)
1335 char* mszReaderNamesA = NULL;
1336 char buffer[1024] = { 0 };
1339 if (!WLog_IsLevelActive(log, g_LogLevel))
1341 cBytes = ret->cBytes;
1342 if (ret->ReturnCode != SCARD_S_SUCCESS)
1344 if (cBytes == SCARD_AUTOALLOCATE)
1346 mszReaderNamesA = smartcard_convert_string_list(ret->mszReaderNames, cBytes, unicode);
1348 WLog_Print(log, g_LogLevel,
"Status%s_Return {", unicode ?
"W" :
"A");
1349 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1350 SCardGetErrorString(ret->ReturnCode),
1351 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1352 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
") dwProtocol: %s (0x%08" PRIX32
")",
1353 SCardGetCardStateString(ret->dwState), ret->dwState,
1354 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1356 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" mszReaderNames: %s", ret->cBytes,
1359 WLog_Print(log, g_LogLevel,
" cbAtrLen: %" PRIu32
" pbAtr: %s", ret->cbAtrLen,
1360 smartcard_array_dump(ret->pbAtr, ret->cbAtrLen, buffer,
sizeof(buffer)));
1361 WLog_Print(log, g_LogLevel,
"}");
1362 free(mszReaderNamesA);
1365static void smartcard_trace_state_return(wLog* log,
const State_Return* ret)
1368 char buffer[1024] = { 0 };
1371 if (!WLog_IsLevelActive(log, g_LogLevel))
1374 state = SCardGetReaderStateString(ret->dwState);
1375 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1376 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1377 SCardGetErrorString(ret->ReturnCode),
1378 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1379 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
")", state, ret->dwState);
1380 WLog_Print(log, g_LogLevel,
" dwProtocol: %s (0x%08" PRIX32
")",
1381 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1382 WLog_Print(log, g_LogLevel,
" cbAtrLen: (0x%08" PRIX32
")", ret->cbAtrLen);
1383 WLog_Print(log, g_LogLevel,
" rgAtr: %s",
1384 smartcard_array_dump(ret->rgAtr,
sizeof(ret->rgAtr), buffer,
sizeof(buffer)));
1385 WLog_Print(log, g_LogLevel,
"}");
1389static void smartcard_trace_reconnect_return(wLog* log,
const Reconnect_Return* ret)
1393 if (!WLog_IsLevelActive(log, g_LogLevel))
1396 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1397 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1398 SCardGetErrorString(ret->ReturnCode),
1399 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1400 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1401 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1402 WLog_Print(log, g_LogLevel,
"}");
1405static void smartcard_trace_connect_a_call(wLog* log,
const ConnectA_Call* call)
1409 if (!WLog_IsLevelActive(log, g_LogLevel))
1412 WLog_Print(log, g_LogLevel,
"ConnectA_Call {");
1413 smartcard_log_context(log, &call->Common.handles.hContext);
1415 WLog_Print(log, g_LogLevel,
1416 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1417 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1418 call->szReader, SCardGetShareModeString(call->Common.dwShareMode),
1419 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1420 call->Common.dwPreferredProtocols);
1421 WLog_Print(log, g_LogLevel,
"}");
1424static void smartcard_trace_connect_w_call(wLog* log,
const ConnectW_Call* call)
1427 char szReaderA[1024] = { 0 };
1429 if (!WLog_IsLevelActive(log, g_LogLevel))
1433 (void)ConvertWCharToUtf8(call->szReader, szReaderA, ARRAYSIZE(szReaderA));
1434 WLog_Print(log, g_LogLevel,
"ConnectW_Call {");
1435 smartcard_log_context(log, &call->Common.handles.hContext);
1437 WLog_Print(log, g_LogLevel,
1438 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1439 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1440 szReaderA, SCardGetShareModeString(call->Common.dwShareMode),
1441 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1442 call->Common.dwPreferredProtocols);
1443 WLog_Print(log, g_LogLevel,
"}");
1446static void smartcard_trace_hcard_and_disposition_call(wLog* log,
1452 if (!WLog_IsLevelActive(log, g_LogLevel))
1455 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
1456 smartcard_log_context(log, &call->handles.hContext);
1457 smartcard_log_redir_handle(log, &call->handles.hCard);
1459 WLog_Print(log, g_LogLevel,
"dwDisposition: %s (0x%08" PRIX32
")",
1460 SCardGetDispositionString(call->dwDisposition), call->dwDisposition);
1461 WLog_Print(log, g_LogLevel,
"}");
1468 if (!WLog_IsLevelActive(log, g_LogLevel))
1471 WLog_Print(log, g_LogLevel,
"EstablishContext_Call {");
1472 WLog_Print(log, g_LogLevel,
"dwScope: %s (0x%08" PRIX32
")", SCardGetScopeString(call->dwScope),
1474 WLog_Print(log, g_LogLevel,
"}");
1481 if (!WLog_IsLevelActive(log, g_LogLevel))
1484 WLog_Print(log, g_LogLevel,
"EstablishContext_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 smartcard_log_context(log, &ret->hContext);
1490 WLog_Print(log, g_LogLevel,
"}");
1493void smartcard_trace_long_return(
const Long_Return* ret,
const char* name)
1495 wLog* log = scard_log();
1496 smartcard_trace_long_return_int(log, ret, name);
1499void smartcard_trace_long_return_int(wLog* log,
const Long_Return* ret,
const char* name)
1503 if (!WLog_IsLevelActive(log, g_LogLevel))
1506 WLog_Print(log, g_LogLevel,
"%s_Return {", name);
1507 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1508 SCardGetErrorString(ret->ReturnCode),
1509 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1510 WLog_Print(log, g_LogLevel,
"}");
1513static void smartcard_trace_connect_return(wLog* log,
const Connect_Return* ret)
1517 if (!WLog_IsLevelActive(log, g_LogLevel))
1520 WLog_Print(log, g_LogLevel,
"Connect_Return {");
1521 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1522 SCardGetErrorString(ret->ReturnCode),
1523 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1524 smartcard_log_context(log, &ret->hContext);
1525 smartcard_log_redir_handle(log, &ret->hCard);
1527 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1528 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1529 WLog_Print(log, g_LogLevel,
"}");
1532static void smartcard_trace_reconnect_call(wLog* log,
const Reconnect_Call* call)
1536 if (!WLog_IsLevelActive(log, g_LogLevel))
1539 WLog_Print(log, g_LogLevel,
"Reconnect_Call {");
1540 smartcard_log_context(log, &call->handles.hContext);
1541 smartcard_log_redir_handle(log, &call->handles.hCard);
1543 WLog_Print(log, g_LogLevel,
1544 "dwShareMode: %s (0x%08" PRIX32
") dwPreferredProtocols: %s (0x%08" PRIX32
1545 ") dwInitialization: %s (0x%08" PRIX32
")",
1546 SCardGetShareModeString(call->dwShareMode), call->dwShareMode,
1547 SCardGetProtocolString(call->dwPreferredProtocols), call->dwPreferredProtocols,
1548 SCardGetDispositionString(call->dwInitialization), call->dwInitialization);
1549 WLog_Print(log, g_LogLevel,
"}");
1556 if (!WLog_IsLevelActive(log, g_LogLevel))
1559 WLog_Print(log, g_LogLevel,
"GetDeviceTypeId_Return {");
1560 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1561 SCardGetErrorString(ret->ReturnCode),
1562 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1563 WLog_Print(log, g_LogLevel,
" dwDeviceId=%08" PRIx32, ret->dwDeviceId);
1565 WLog_Print(log, g_LogLevel,
"}");
1568static LONG smartcard_unpack_common_context_and_string_a(wLog* log,
wStream* s,
1570 CHAR** pszReaderName)
1573 UINT32 pbContextNdrPtr = 0;
1574 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1575 if (status != SCARD_S_SUCCESS)
1578 if (!smartcard_ndr_pointer_read(log, s, &index, NULL))
1579 return ERROR_INVALID_DATA;
1581 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1582 if (status != SCARD_S_SUCCESS)
1585 status = smartcard_ndr_read_a(log, s, pszReaderName, NDR_PTR_FULL);
1586 if (status != SCARD_S_SUCCESS)
1589 smartcard_trace_context_and_string_call_a(log, __func__, phContext, *pszReaderName);
1590 return SCARD_S_SUCCESS;
1593static LONG smartcard_unpack_common_context_and_string_w(wLog* log,
wStream* s,
1595 WCHAR** pszReaderName)
1598 UINT32 pbContextNdrPtr = 0;
1600 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1601 if (status != SCARD_S_SUCCESS)
1604 if (!smartcard_ndr_pointer_read(log, s, &index, NULL))
1605 return ERROR_INVALID_DATA;
1607 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1608 if (status != SCARD_S_SUCCESS)
1611 status = smartcard_ndr_read_w(log, s, pszReaderName, NDR_PTR_FULL);
1612 if (status != SCARD_S_SUCCESS)
1615 smartcard_trace_context_and_string_call_w(log, __func__, phContext, *pszReaderName);
1616 return SCARD_S_SUCCESS;
1619LONG smartcard_unpack_common_type_header(
wStream* s)
1621 wLog* log = scard_log();
1624 UINT8 endianness = 0;
1625 UINT16 commonHeaderLength = 0;
1627 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1628 return STATUS_BUFFER_TOO_SMALL;
1631 Stream_Read_UINT8(s, version);
1632 Stream_Read_UINT8(s, endianness);
1633 Stream_Read_UINT16(s, commonHeaderLength);
1634 Stream_Read_UINT32(s, filler);
1638 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Version %" PRIu8
"", version);
1639 return STATUS_INVALID_PARAMETER;
1642 if (endianness != 0x10)
1644 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Endianness %" PRIu8
"",
1646 return STATUS_INVALID_PARAMETER;
1649 if (commonHeaderLength != 8)
1651 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader CommonHeaderLength %" PRIu16
"",
1652 commonHeaderLength);
1653 return STATUS_INVALID_PARAMETER;
1656 if (filler != 0xCCCCCCCC)
1658 WLog_Print(log, WLOG_WARN,
"Unexpected CommonTypeHeader Filler 0x%08" PRIX32
"", filler);
1659 return STATUS_INVALID_PARAMETER;
1662 return SCARD_S_SUCCESS;
1665void smartcard_pack_common_type_header(
wStream* s)
1667 Stream_Write_UINT8(s, 1);
1668 Stream_Write_UINT8(s, 0x10);
1669 Stream_Write_UINT16(s, 8);
1670 Stream_Write_UINT32(s, 0xCCCCCCCC);
1673LONG smartcard_unpack_private_type_header(
wStream* s)
1675 wLog* log = scard_log();
1677 UINT32 objectBufferLength = 0;
1679 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1680 return STATUS_BUFFER_TOO_SMALL;
1682 Stream_Read_UINT32(s, objectBufferLength);
1683 Stream_Read_UINT32(s, filler);
1685 if (filler != 0x00000000)
1687 WLog_Print(log, WLOG_WARN,
"Unexpected PrivateTypeHeader Filler 0x%08" PRIX32
"", filler);
1688 return STATUS_INVALID_PARAMETER;
1691 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, objectBufferLength))
1692 return STATUS_INVALID_PARAMETER;
1694 return SCARD_S_SUCCESS;
1697void smartcard_pack_private_type_header(
wStream* s, UINT32 objectBufferLength)
1699 Stream_Write_UINT32(s, objectBufferLength);
1700 Stream_Write_UINT32(s, 0x00000000);
1703LONG smartcard_unpack_read_size_align(
wStream* s,
size_t size, UINT32 alignment)
1708 size = (size + alignment - 1) & ~(alignment - 1);
1712 Stream_Seek(s, pad);
1717LONG smartcard_pack_write_size_align(
wStream* s,
size_t size, UINT32 alignment)
1722 size = (size + alignment - 1) & ~(alignment - 1);
1727 if (!Stream_EnsureRemainingCapacity(s, pad))
1729 wLog* log = scard_log();
1730 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
1731 return SCARD_F_INTERNAL_ERROR;
1734 Stream_Zero(s, pad);
1737 return SCARD_S_SUCCESS;
1742 SCARDCONTEXT hContext = { 0 };
1744 WINPR_ASSERT(context);
1745 if ((context->cbContext !=
sizeof(ULONG_PTR)) && (context->cbContext != 0))
1747 wLog* log = scard_log();
1748 WLog_Print(log, WLOG_WARN,
1749 "REDIR_SCARDCONTEXT does not match native size: Actual: %" PRIu32
1750 ", Expected: %" PRIuz
"",
1751 context->cbContext,
sizeof(ULONG_PTR));
1755 if (context->cbContext)
1756 CopyMemory(&hContext, &(context->pbContext), context->cbContext);
1761void smartcard_scard_context_native_to_redir(
REDIR_SCARDCONTEXT* context, SCARDCONTEXT hContext)
1763 WINPR_ASSERT(context);
1765 context->cbContext =
sizeof(ULONG_PTR);
1766 CopyMemory(&(context->pbContext), &hContext, context->cbContext);
1771 SCARDHANDLE hCard = 0;
1773 WINPR_ASSERT(handle);
1774 if (handle->cbHandle == 0)
1777 if (handle->cbHandle !=
sizeof(ULONG_PTR))
1779 wLog* log = scard_log();
1780 WLog_Print(log, WLOG_WARN,
1781 "REDIR_SCARDHANDLE does not match native size: Actual: %" PRIu32
1782 ", Expected: %" PRIuz
"",
1783 handle->cbHandle,
sizeof(ULONG_PTR));
1787 if (handle->cbHandle)
1788 CopyMemory(&hCard, &(handle->pbHandle), handle->cbHandle);
1793void smartcard_scard_handle_native_to_redir(
REDIR_SCARDHANDLE* handle, SCARDHANDLE hCard)
1795 WINPR_ASSERT(handle);
1797 handle->cbHandle =
sizeof(ULONG_PTR);
1798 CopyMemory(&(handle->pbHandle), &hCard, handle->cbHandle);
1801#define smartcard_context_supported(log, size) \
1802 smartcard_context_supported_((log), (size), __FILE__, __func__, __LINE__)
1803static LONG smartcard_context_supported_(wLog* log, uint32_t size,
const char* file,
1804 const char* fkt,
size_t line)
1811 return SCARD_S_SUCCESS;
1814 const uint32_t level = WLOG_WARN;
1815 if (WLog_IsLevelActive(log, level))
1817 WLog_PrintTextMessage(log, level, line, file, fkt,
1818 "REDIR_SCARDCONTEXT length is not 0, 4 or 8: %" PRIu32
"",
1821 return STATUS_INVALID_PARAMETER;
1827 UINT32* index, UINT32* ppbContextNdrPtr,
1828 const char* file,
const char* function,
size_t line)
1830 UINT32 pbContextNdrPtr = 0;
1833 WINPR_ASSERT(context);
1837 if (!Stream_CheckAndLogRequiredLengthWLogEx(log, WLOG_WARN, s, 4, 1,
"%s(%s:%" PRIuz
")", file,
1839 return STATUS_BUFFER_TOO_SMALL;
1841 const LONG status = smartcard_context_supported_(log, context->cbContext, file, function, line);
1842 if (status != SCARD_S_SUCCESS)
1845 Stream_Read_UINT32(s, context->cbContext);
1847 if (!smartcard_ndr_pointer_read_(log, s, index, &pbContextNdrPtr, file, function, line))
1848 return ERROR_INVALID_DATA;
1850 if (((context->cbContext == 0) && pbContextNdrPtr) ||
1851 ((context->cbContext != 0) && !pbContextNdrPtr))
1853 WLog_Print(log, WLOG_WARN,
1854 "REDIR_SCARDCONTEXT cbContext (%" PRIu32
") pbContextNdrPtr (%" PRIu32
1856 context->cbContext, pbContextNdrPtr);
1857 return STATUS_INVALID_PARAMETER;
1860 if (!Stream_CheckAndLogRequiredLengthWLogEx(log, WLOG_WARN, s, context->cbContext, 1,
1861 "%s(%s:%" PRIuz
")", file, function, line))
1862 return STATUS_INVALID_PARAMETER;
1864 *ppbContextNdrPtr = pbContextNdrPtr;
1865 return SCARD_S_SUCCESS;
1868LONG smartcard_pack_redir_scard_context(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1871 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
1873 WINPR_ASSERT(context);
1874 if (context->cbContext != 0)
1876 Stream_Write_UINT32(s, context->cbContext);
1877 Stream_Write_UINT32(s, pbContextNdrPtr);
1878 *index = *index + 1;
1883 return SCARD_S_SUCCESS;
1886LONG smartcard_unpack_redir_scard_context_ref(wLog* log,
wStream* s,
1887 WINPR_ATTR_UNUSED UINT32 pbContextNdrPtr,
1892 WINPR_ASSERT(context);
1893 if (context->cbContext == 0)
1894 return SCARD_S_SUCCESS;
1896 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1897 return STATUS_BUFFER_TOO_SMALL;
1899 Stream_Read_UINT32(s, length);
1901 if (length != context->cbContext)
1903 WLog_Print(log, WLOG_WARN,
1904 "REDIR_SCARDCONTEXT length (%" PRIu32
") cbContext (%" PRIu32
") mismatch",
1905 length, context->cbContext);
1906 return STATUS_INVALID_PARAMETER;
1909 const LONG status = smartcard_context_supported(log, context->cbContext);
1910 if (status != SCARD_S_SUCCESS)
1913 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, context->cbContext))
1914 return STATUS_BUFFER_TOO_SMALL;
1916 if (context->cbContext)
1917 Stream_Read(s, &(context->pbContext), context->cbContext);
1919 ZeroMemory(&(context->pbContext),
sizeof(context->pbContext));
1921 return SCARD_S_SUCCESS;
1924LONG smartcard_pack_redir_scard_context_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1927 WINPR_ASSERT(context);
1928 Stream_Write_UINT32(s, context->cbContext);
1930 if (context->cbContext)
1932 Stream_Write(s, &(context->pbContext), context->cbContext);
1935 return SCARD_S_SUCCESS;
1939 UINT32* index,
const char* file,
const char* function,
1942 WINPR_ASSERT(handle);
1945 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1946 return STATUS_BUFFER_TOO_SMALL;
1948 Stream_Read_UINT32(s, handle->cbHandle);
1950 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, handle->cbHandle))
1951 return STATUS_BUFFER_TOO_SMALL;
1953 if (!smartcard_ndr_pointer_read_(log, s, index, NULL, file, function, line))
1954 return ERROR_INVALID_DATA;
1956 return SCARD_S_SUCCESS;
1959LONG smartcard_pack_redir_scard_handle(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1962 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
1964 WINPR_ASSERT(handle);
1965 if (handle->cbHandle != 0)
1967 Stream_Write_UINT32(s, handle->cbHandle);
1968 Stream_Write_UINT32(s, pbContextNdrPtr);
1969 *index = *index + 1;
1973 return SCARD_S_SUCCESS;
1980 WINPR_ASSERT(handle);
1981 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1982 return STATUS_BUFFER_TOO_SMALL;
1984 Stream_Read_UINT32(s, length);
1986 if (length != handle->cbHandle)
1988 WLog_Print(log, WLOG_WARN,
1989 "REDIR_SCARDHANDLE length (%" PRIu32
") cbHandle (%" PRIu32
") mismatch", length,
1991 return STATUS_INVALID_PARAMETER;
1994 if ((handle->cbHandle != 4) && (handle->cbHandle != 8))
1996 WLog_Print(log, WLOG_WARN,
"REDIR_SCARDHANDLE length is not 4 or 8: %" PRIu32
"",
1998 return STATUS_INVALID_PARAMETER;
2001 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, handle->cbHandle))
2002 return STATUS_BUFFER_TOO_SMALL;
2004 if (handle->cbHandle)
2005 Stream_Read(s, &(handle->pbHandle), handle->cbHandle);
2007 return SCARD_S_SUCCESS;
2010LONG smartcard_pack_redir_scard_handle_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
2013 WINPR_ASSERT(handle);
2014 Stream_Write_UINT32(s, handle->cbHandle);
2016 if (handle->cbHandle)
2017 Stream_Write(s, &(handle->pbHandle), handle->cbHandle);
2019 return SCARD_S_SUCCESS;
2025 wLog* log = scard_log();
2027 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2028 return STATUS_BUFFER_TOO_SMALL;
2030 Stream_Read_UINT32(s, call->dwScope);
2031 smartcard_trace_establish_context_call(log, call);
2032 return SCARD_S_SUCCESS;
2038 wLog* log = scard_log();
2042 smartcard_trace_establish_context_return(log, ret);
2043 if (ret->ReturnCode != SCARD_S_SUCCESS)
2044 return ret->ReturnCode;
2046 status = smartcard_pack_redir_scard_context(log, s, &(ret->hContext), &index);
2047 if (status != SCARD_S_SUCCESS)
2050 return smartcard_pack_redir_scard_context_ref(log, s, &(ret->hContext));
2056 UINT32 pbContextNdrPtr = 0;
2057 wLog* log = scard_log();
2060 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2062 if (status != SCARD_S_SUCCESS)
2065 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2066 &(call->handles.hContext));
2067 if (status != SCARD_S_SUCCESS)
2068 WLog_Print(log, WLOG_ERROR,
2069 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2072 smartcard_trace_context_call(log, call, name);
2079 UINT32 pbContextNdrPtr = 0;
2080 wLog* log = scard_log();
2083 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2086 if (status != SCARD_S_SUCCESS)
2089 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2090 return STATUS_BUFFER_TOO_SMALL;
2092 Stream_Read_INT32(s, call->fmszGroupsIsNULL);
2093 Stream_Read_UINT32(s, call->cchGroups);
2094 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2095 &(call->handles.hContext));
2097 if (status != SCARD_S_SUCCESS)
2100 smartcard_trace_list_reader_groups_call(log, call, unicode);
2101 return SCARD_S_SUCCESS;
2108 wLog* log = scard_log();
2110 DWORD cBytes = ret->cBytes;
2113 smartcard_trace_list_reader_groups_return(log, ret, unicode);
2114 if (ret->ReturnCode != SCARD_S_SUCCESS)
2116 if (cBytes == SCARD_AUTOALLOCATE)
2119 if (!Stream_EnsureRemainingCapacity(s, 4))
2120 return SCARD_E_NO_MEMORY;
2122 Stream_Write_UINT32(s, cBytes);
2123 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
2124 return SCARD_E_NO_MEMORY;
2126 status = smartcard_ndr_write(s, ret->msz, cBytes, 1, NDR_PTR_SIMPLE);
2127 if (status != SCARD_S_SUCCESS)
2129 return ret->ReturnCode;
2135 UINT32 mszGroupsNdrPtr = 0;
2136 UINT32 pbContextNdrPtr = 0;
2137 wLog* log = scard_log();
2140 call->mszGroups = NULL;
2142 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2144 if (status != SCARD_S_SUCCESS)
2147 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2148 return STATUS_BUFFER_TOO_SMALL;
2150 Stream_Read_UINT32(s, call->cBytes);
2151 if (!smartcard_ndr_pointer_read(log, s, &index, &mszGroupsNdrPtr))
2152 return ERROR_INVALID_DATA;
2154 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2155 return STATUS_BUFFER_TOO_SMALL;
2156 Stream_Read_INT32(s, call->fmszReadersIsNULL);
2157 Stream_Read_UINT32(s, call->cchReaders);
2159 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2160 &(call->handles.hContext));
2161 if (status != SCARD_S_SUCCESS)
2164 if (mszGroupsNdrPtr)
2166 status = smartcard_ndr_read(log, s, &call->mszGroups, call->cBytes, 1, NDR_PTR_SIMPLE);
2167 if (status != SCARD_S_SUCCESS)
2171 smartcard_trace_list_readers_call(log, call, unicode);
2172 return SCARD_S_SUCCESS;
2178 wLog* log = scard_log();
2181 UINT32 size = ret->cBytes;
2183 smartcard_trace_list_readers_return(log, ret, unicode);
2184 if (ret->ReturnCode != SCARD_S_SUCCESS)
2187 if (!Stream_EnsureRemainingCapacity(s, 4))
2189 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
2190 return SCARD_F_INTERNAL_ERROR;
2193 Stream_Write_UINT32(s, size);
2194 if (!smartcard_ndr_pointer_write(s, &index, size))
2195 return SCARD_E_NO_MEMORY;
2197 status = smartcard_ndr_write(s, ret->msz, size, 1, NDR_PTR_SIMPLE);
2198 if (status != SCARD_S_SUCCESS)
2200 return ret->ReturnCode;
2204 UINT32* index, UINT32* ppbContextNdrPtr)
2206 WINPR_ASSERT(common);
2207 LONG status = smartcard_unpack_redir_scard_context(log, s, &(common->handles.hContext), index,
2209 if (status != SCARD_S_SUCCESS)
2212 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2213 return STATUS_BUFFER_TOO_SMALL;
2215 Stream_Read_UINT32(s, common->dwShareMode);
2216 Stream_Read_UINT32(s, common->dwPreferredProtocols);
2217 return SCARD_S_SUCCESS;
2224 UINT32 pbContextNdrPtr = 0;
2227 wLog* log = scard_log();
2229 call->szReader = NULL;
2231 if (!smartcard_ndr_pointer_read(log, s, &index, NULL))
2232 return ERROR_INVALID_DATA;
2234 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2235 if (status != SCARD_S_SUCCESS)
2237 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2242 status = smartcard_ndr_read_a(log, s, &call->szReader, NDR_PTR_FULL);
2243 if (status != SCARD_S_SUCCESS)
2246 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2247 &(call->Common.handles.hContext));
2248 if (status != SCARD_S_SUCCESS)
2249 WLog_Print(log, WLOG_ERROR,
2250 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2253 smartcard_trace_connect_a_call(log, call);
2261 UINT32 pbContextNdrPtr = 0;
2264 wLog* log = scard_log();
2265 call->szReader = NULL;
2267 if (!smartcard_ndr_pointer_read(log, s, &index, NULL))
2268 return ERROR_INVALID_DATA;
2270 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2271 if (status != SCARD_S_SUCCESS)
2273 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2278 status = smartcard_ndr_read_w(log, s, &call->szReader, NDR_PTR_FULL);
2279 if (status != SCARD_S_SUCCESS)
2282 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2283 &(call->Common.handles.hContext));
2284 if (status != SCARD_S_SUCCESS)
2285 WLog_Print(log, WLOG_ERROR,
2286 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2289 smartcard_trace_connect_w_call(log, call);
2299 wLog* log = scard_log();
2300 smartcard_trace_connect_return(log, ret);
2302 status = smartcard_pack_redir_scard_context(log, s, &ret->hContext, &index);
2303 if (status != SCARD_S_SUCCESS)
2306 status = smartcard_pack_redir_scard_handle(log, s, &ret->hCard, &index);
2307 if (status != SCARD_S_SUCCESS)
2310 if (!Stream_EnsureRemainingCapacity(s, 4))
2311 return SCARD_E_NO_MEMORY;
2313 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2314 status = smartcard_pack_redir_scard_context_ref(log, s, &ret->hContext);
2315 if (status != SCARD_S_SUCCESS)
2317 return smartcard_pack_redir_scard_handle_ref(log, s, &(ret->hCard));
2323 UINT32 pbContextNdrPtr = 0;
2326 wLog* log = scard_log();
2327 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2329 if (status != SCARD_S_SUCCESS)
2332 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2333 if (status != SCARD_S_SUCCESS)
2336 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2337 return STATUS_BUFFER_TOO_SMALL;
2339 Stream_Read_UINT32(s, call->dwShareMode);
2340 Stream_Read_UINT32(s, call->dwPreferredProtocols);
2341 Stream_Read_UINT32(s, call->dwInitialization);
2343 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2344 &(call->handles.hContext));
2345 if (status != SCARD_S_SUCCESS)
2347 WLog_Print(log, WLOG_ERROR,
2348 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2353 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2354 if (status != SCARD_S_SUCCESS)
2355 WLog_Print(log, WLOG_ERROR,
2356 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
2358 smartcard_trace_reconnect_call(log, call);
2365 wLog* log = scard_log();
2366 smartcard_trace_reconnect_return(log, ret);
2368 if (!Stream_EnsureRemainingCapacity(s, 4))
2369 return SCARD_E_NO_MEMORY;
2370 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2371 return ret->ReturnCode;
2378 UINT32 pbContextNdrPtr = 0;
2381 wLog* log = scard_log();
2383 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2385 if (status != SCARD_S_SUCCESS)
2388 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2389 if (status != SCARD_S_SUCCESS)
2392 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2393 return STATUS_BUFFER_TOO_SMALL;
2395 Stream_Read_UINT32(s, call->dwDisposition);
2397 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2398 &(call->handles.hContext));
2399 if (status != SCARD_S_SUCCESS)
2402 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2403 if (status != SCARD_S_SUCCESS)
2406 smartcard_trace_hcard_and_disposition_call(log, call, name);
2414 if (!WLog_IsLevelActive(log, g_LogLevel))
2417 WLog_Print(log, g_LogLevel,
"GetStatusChangeA_Call {");
2418 smartcard_log_context(log, &call->handles.hContext);
2420 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
2423 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
2425 WLog_Print(log, g_LogLevel,
"}");
2429 UINT32 cReaders, UINT32* ptrIndex)
2431 LONG status = SCARD_E_NO_MEMORY;
2433 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2434 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2437 const UINT32 len = Stream_Get_UINT32(s);
2438 if (len != cReaders)
2440 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEA");
2446 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2447 if (!rgReaderStates || !states)
2449 status = ERROR_INVALID_DATA;
2451 for (UINT32 index = 0; index < cReaders; index++)
2453 UINT32 ptr = UINT32_MAX;
2456 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2459 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2465 states[index] = ptr != 0;
2466 Stream_Read_UINT32(s, readerState->dwCurrentState);
2467 Stream_Read_UINT32(s, readerState->dwEventState);
2468 Stream_Read_UINT32(s, readerState->cbAtr);
2469 Stream_Read(s, readerState->rgbAtr, 36);
2472 for (UINT32 index = 0; index < cReaders; index++)
2479 status = smartcard_ndr_read_a(log, s, &readerState->szReader, NDR_PTR_FULL);
2480 if (status != SCARD_S_SUCCESS)
2484 *ppcReaders = rgReaderStates;
2486 return SCARD_S_SUCCESS;
2490 for (UINT32 index = 0; index < cReaders; index++)
2493 free(readerState->szReader);
2496 free(rgReaderStates);
2502 UINT32 cReaders, UINT32* ptrIndex)
2504 LONG status = SCARD_E_NO_MEMORY;
2506 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2507 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2510 const UINT32 len = Stream_Get_UINT32(s);
2511 if (len != cReaders)
2513 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEW");
2519 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2521 if (!rgReaderStates || !states)
2524 status = ERROR_INVALID_DATA;
2525 for (UINT32 index = 0; index < cReaders; index++)
2527 UINT32 ptr = UINT32_MAX;
2530 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2533 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2539 states[index] = ptr != 0;
2540 Stream_Read_UINT32(s, readerState->dwCurrentState);
2541 Stream_Read_UINT32(s, readerState->dwEventState);
2542 Stream_Read_UINT32(s, readerState->cbAtr);
2543 Stream_Read(s, readerState->rgbAtr, 36);
2546 for (UINT32 index = 0; index < cReaders; index++)
2554 status = smartcard_ndr_read_w(log, s, &readerState->szReader, NDR_PTR_FULL);
2555 if (status != SCARD_S_SUCCESS)
2559 *ppcReaders = rgReaderStates;
2561 return SCARD_S_SUCCESS;
2565 for (UINT32 index = 0; index < cReaders; index++)
2568 free(readerState->szReader);
2571 free(rgReaderStates);
2584 UINT32 pbContextNdrPtr = 0;
2587 wLog* log = scard_log();
2589 call->rgReaderStates = NULL;
2591 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2593 if (status != SCARD_S_SUCCESS)
2596 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2597 return STATUS_BUFFER_TOO_SMALL;
2599 Stream_Read_UINT32(s, call->dwTimeOut);
2600 Stream_Read_UINT32(s, call->cReaders);
2601 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2602 return ERROR_INVALID_DATA;
2604 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2605 &(call->handles.hContext));
2606 if (status != SCARD_S_SUCCESS)
2612 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
2613 if (status != SCARD_S_SUCCESS)
2618 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2619 return SCARD_E_UNEXPECTED;
2622 smartcard_trace_get_status_change_a_call(log, call);
2623 return SCARD_S_SUCCESS;
2630 UINT32 pbContextNdrPtr = 0;
2633 wLog* log = scard_log();
2634 call->rgReaderStates = NULL;
2636 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2638 if (status != SCARD_S_SUCCESS)
2641 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2642 return STATUS_BUFFER_TOO_SMALL;
2644 Stream_Read_UINT32(s, call->dwTimeOut);
2645 Stream_Read_UINT32(s, call->cReaders);
2646 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2647 return ERROR_INVALID_DATA;
2649 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2650 &(call->handles.hContext));
2651 if (status != SCARD_S_SUCCESS)
2657 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
2658 if (status != SCARD_S_SUCCESS)
2663 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2664 return SCARD_E_UNEXPECTED;
2667 smartcard_trace_get_status_change_w_call(log, call);
2668 return SCARD_S_SUCCESS;
2675 wLog* log = scard_log();
2678 DWORD cReaders = ret->cReaders;
2681 smartcard_trace_get_status_change_return(log, ret, unicode);
2682 if (ret->ReturnCode != SCARD_S_SUCCESS)
2684 if (cReaders == SCARD_AUTOALLOCATE)
2687 if (!Stream_EnsureRemainingCapacity(s, 4))
2688 return SCARD_E_NO_MEMORY;
2690 Stream_Write_UINT32(s, cReaders);
2691 if (!smartcard_ndr_pointer_write(s, &index, cReaders))
2692 return SCARD_E_NO_MEMORY;
2693 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cReaders, NDR_PTR_SIMPLE);
2694 if (status != SCARD_S_SUCCESS)
2696 return ret->ReturnCode;
2702 UINT32 pbContextNdrPtr = 0;
2704 wLog* log = scard_log();
2707 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2709 if (status != SCARD_S_SUCCESS)
2712 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2713 if (status != SCARD_S_SUCCESS)
2716 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2717 return STATUS_BUFFER_TOO_SMALL;
2719 Stream_Read_INT32(s, call->fpbAtrIsNULL);
2720 Stream_Read_UINT32(s, call->cbAtrLen);
2722 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2723 &(call->handles.hContext));
2724 if (status != SCARD_S_SUCCESS)
2727 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2728 if (status != SCARD_S_SUCCESS)
2737 wLog* log = scard_log();
2739 DWORD cbAtrLen = ret->cbAtrLen;
2742 smartcard_trace_state_return(log, ret);
2743 if (ret->ReturnCode != SCARD_S_SUCCESS)
2745 if (cbAtrLen == SCARD_AUTOALLOCATE)
2748 Stream_Write_UINT32(s, ret->dwState);
2749 Stream_Write_UINT32(s, ret->dwProtocol);
2750 Stream_Write_UINT32(s, cbAtrLen);
2751 if (!smartcard_ndr_pointer_write(s, &index, cbAtrLen))
2752 return SCARD_E_NO_MEMORY;
2753 status = smartcard_ndr_write(s, ret->rgAtr, cbAtrLen, 1, NDR_PTR_SIMPLE);
2754 if (status != SCARD_S_SUCCESS)
2756 return ret->ReturnCode;
2762 UINT32 pbContextNdrPtr = 0;
2765 wLog* log = scard_log();
2767 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2769 if (status != SCARD_S_SUCCESS)
2772 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2773 if (status != SCARD_S_SUCCESS)
2776 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2777 return STATUS_BUFFER_TOO_SMALL;
2779 Stream_Read_INT32(s, call->fmszReaderNamesIsNULL);
2780 Stream_Read_UINT32(s, call->cchReaderLen);
2781 Stream_Read_UINT32(s, call->cbAtrLen);
2783 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2784 &(call->handles.hContext));
2785 if (status != SCARD_S_SUCCESS)
2788 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2789 if (status != SCARD_S_SUCCESS)
2792 smartcard_trace_status_call(log, call, unicode);
2799 wLog* log = scard_log();
2803 DWORD cBytes = ret->cBytes;
2805 smartcard_trace_status_return(log, ret, unicode);
2806 if (ret->ReturnCode != SCARD_S_SUCCESS)
2808 if (cBytes == SCARD_AUTOALLOCATE)
2811 if (!Stream_EnsureRemainingCapacity(s, 4))
2812 return SCARD_F_INTERNAL_ERROR;
2814 Stream_Write_UINT32(s, cBytes);
2815 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
2816 return SCARD_E_NO_MEMORY;
2818 if (!Stream_EnsureRemainingCapacity(s, 44))
2819 return SCARD_F_INTERNAL_ERROR;
2821 Stream_Write_UINT32(s, ret->dwState);
2822 Stream_Write_UINT32(s, ret->dwProtocol);
2823 Stream_Write(s, ret->pbAtr,
sizeof(ret->pbAtr));
2824 Stream_Write_UINT32(s, ret->cbAtrLen);
2825 status = smartcard_ndr_write(s, ret->mszReaderNames, cBytes, 1, NDR_PTR_SIMPLE);
2826 if (status != SCARD_S_SUCCESS)
2828 return ret->ReturnCode;
2834 wLog* log = scard_log();
2836 UINT32 pbContextNdrPtr = 0;
2838 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2840 if (status != SCARD_S_SUCCESS)
2843 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2844 if (status != SCARD_S_SUCCESS)
2847 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2848 return STATUS_BUFFER_TOO_SMALL;
2850 Stream_Read_UINT32(s, call->dwAttrId);
2851 Stream_Read_INT32(s, call->fpbAttrIsNULL);
2852 Stream_Read_UINT32(s, call->cbAttrLen);
2854 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2855 &(call->handles.hContext));
2856 if (status != SCARD_S_SUCCESS)
2859 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2860 if (status != SCARD_S_SUCCESS)
2863 smartcard_trace_get_attrib_call(log, call);
2868 DWORD cbAttrCallLen)
2871 wLog* log = scard_log();
2873 DWORD cbAttrLen = 0;
2875 smartcard_trace_get_attrib_return(log, ret, dwAttrId);
2877 if (!Stream_EnsureRemainingCapacity(s, 4))
2878 return SCARD_F_INTERNAL_ERROR;
2880 cbAttrLen = ret->cbAttrLen;
2881 if (ret->ReturnCode != SCARD_S_SUCCESS)
2883 if (cbAttrLen == SCARD_AUTOALLOCATE)
2888 if (cbAttrCallLen < cbAttrLen)
2889 cbAttrLen = cbAttrCallLen;
2891 Stream_Write_UINT32(s, cbAttrLen);
2892 if (!smartcard_ndr_pointer_write(s, &index, cbAttrLen))
2893 return SCARD_E_NO_MEMORY;
2895 status = smartcard_ndr_write(s, ret->pbAttr, cbAttrLen, 1, NDR_PTR_SIMPLE);
2896 if (status != SCARD_S_SUCCESS)
2898 return ret->ReturnCode;
2904 wLog* log = scard_log();
2907 UINT32 pvInBufferNdrPtr = 0;
2908 UINT32 pbContextNdrPtr = 0;
2910 call->pvInBuffer = NULL;
2912 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2914 if (status != SCARD_S_SUCCESS)
2917 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2918 if (status != SCARD_S_SUCCESS)
2921 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 20))
2922 return STATUS_BUFFER_TOO_SMALL;
2924 Stream_Read_UINT32(s, call->dwControlCode);
2925 Stream_Read_UINT32(s, call->cbInBufferSize);
2926 if (!smartcard_ndr_pointer_read(log, s, &index,
2928 return ERROR_INVALID_DATA;
2929 Stream_Read_INT32(s, call->fpvOutBufferIsNULL);
2930 Stream_Read_UINT32(s, call->cbOutBufferSize);
2932 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2933 &(call->handles.hContext));
2934 if (status != SCARD_S_SUCCESS)
2937 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2938 if (status != SCARD_S_SUCCESS)
2941 if (pvInBufferNdrPtr)
2944 smartcard_ndr_read(log, s, &call->pvInBuffer, call->cbInBufferSize, 1, NDR_PTR_SIMPLE);
2945 if (status != SCARD_S_SUCCESS)
2949 smartcard_trace_control_call(log, call);
2950 return SCARD_S_SUCCESS;
2956 wLog* log = scard_log();
2959 DWORD cbDataLen = ret->cbOutBufferSize;
2962 smartcard_trace_control_return(log, ret);
2963 if (ret->ReturnCode != SCARD_S_SUCCESS)
2965 if (cbDataLen == SCARD_AUTOALLOCATE)
2968 if (!Stream_EnsureRemainingCapacity(s, 4))
2969 return SCARD_F_INTERNAL_ERROR;
2971 Stream_Write_UINT32(s, cbDataLen);
2972 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
2973 return SCARD_E_NO_MEMORY;
2975 status = smartcard_ndr_write(s, ret->pvOutBuffer, cbDataLen, 1, NDR_PTR_SIMPLE);
2976 if (status != SCARD_S_SUCCESS)
2978 return ret->ReturnCode;
2984 BYTE* pbExtraBytes = NULL;
2985 UINT32 pbExtraBytesNdrPtr = 0;
2986 UINT32 pbSendBufferNdrPtr = 0;
2987 UINT32 pioRecvPciNdrPtr = 0;
2991 UINT32 pbContextNdrPtr = 0;
2994 wLog* log = scard_log();
2996 call->pioSendPci = NULL;
2997 call->pioRecvPci = NULL;
2998 call->pbSendBuffer = NULL;
3000 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3002 if (status != SCARD_S_SUCCESS)
3005 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3006 if (status != SCARD_S_SUCCESS)
3009 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 32))
3010 return STATUS_BUFFER_TOO_SMALL;
3012 Stream_Read_UINT32(s, ioSendPci.dwProtocol);
3013 Stream_Read_UINT32(s, ioSendPci.cbExtraBytes);
3014 if (!smartcard_ndr_pointer_read(log, s, &index,
3015 &pbExtraBytesNdrPtr))
3016 return ERROR_INVALID_DATA;
3018 Stream_Read_UINT32(s, call->cbSendLength);
3019 if (!smartcard_ndr_pointer_read(log, s, &index,
3020 &pbSendBufferNdrPtr))
3021 return ERROR_INVALID_DATA;
3023 if (!smartcard_ndr_pointer_read(log, s, &index,
3025 return ERROR_INVALID_DATA;
3027 Stream_Read_INT32(s, call->fpbRecvBufferIsNULL);
3028 Stream_Read_UINT32(s, call->cbRecvLength);
3030 if (ioSendPci.cbExtraBytes > 1024)
3032 WLog_Print(log, WLOG_WARN,
3033 "Transmit_Call ioSendPci.cbExtraBytes is out of bounds: %" PRIu32
" (max: 1024)",
3034 ioSendPci.cbExtraBytes);
3035 return STATUS_INVALID_PARAMETER;
3038 if (call->cbSendLength > 66560)
3040 WLog_Print(log, WLOG_WARN,
3041 "Transmit_Call cbSendLength is out of bounds: %" PRIu32
" (max: 66560)",
3042 ioSendPci.cbExtraBytes);
3043 return STATUS_INVALID_PARAMETER;
3046 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3047 &(call->handles.hContext));
3048 if (status != SCARD_S_SUCCESS)
3051 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3052 if (status != SCARD_S_SUCCESS)
3055 if (ioSendPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3059 "Transmit_Call ioSendPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3060 return STATUS_INVALID_PARAMETER;
3063 if (pbExtraBytesNdrPtr)
3066 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3067 return STATUS_BUFFER_TOO_SMALL;
3069 Stream_Read_UINT32(s, length);
3071 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioSendPci.cbExtraBytes))
3072 return STATUS_BUFFER_TOO_SMALL;
3074 ioSendPci.pbExtraBytes = Stream_Pointer(s);
3078 if (!call->pioSendPci)
3080 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3081 return STATUS_NO_MEMORY;
3084 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3085 call->pioSendPci->cbPciLength = (DWORD)(ioSendPci.cbExtraBytes +
sizeof(
SCARD_IO_REQUEST));
3087 Stream_Read(s, pbExtraBytes, ioSendPci.cbExtraBytes);
3088 smartcard_unpack_read_size_align(s, ioSendPci.cbExtraBytes, 4);
3094 if (!call->pioSendPci)
3096 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3097 return STATUS_NO_MEMORY;
3100 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3104 if (pbSendBufferNdrPtr)
3107 smartcard_ndr_read(log, s, &call->pbSendBuffer, call->cbSendLength, 1, NDR_PTR_SIMPLE);
3108 if (status != SCARD_S_SUCCESS)
3112 if (pioRecvPciNdrPtr)
3114 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3115 return STATUS_BUFFER_TOO_SMALL;
3117 Stream_Read_UINT32(s, ioRecvPci.dwProtocol);
3118 Stream_Read_UINT32(s, ioRecvPci.cbExtraBytes);
3119 if (!smartcard_ndr_pointer_read(log, s, &index,
3120 &pbExtraBytesNdrPtr))
3121 return ERROR_INVALID_DATA;
3123 if (ioRecvPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3127 "Transmit_Call ioRecvPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3128 return STATUS_INVALID_PARAMETER;
3131 if (pbExtraBytesNdrPtr)
3134 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3135 return STATUS_BUFFER_TOO_SMALL;
3137 Stream_Read_UINT32(s, length);
3139 if (ioRecvPci.cbExtraBytes > 1024)
3141 WLog_Print(log, WLOG_WARN,
3142 "Transmit_Call ioRecvPci.cbExtraBytes is out of bounds: %" PRIu32
3144 ioRecvPci.cbExtraBytes);
3145 return STATUS_INVALID_PARAMETER;
3148 if (length != ioRecvPci.cbExtraBytes)
3150 WLog_Print(log, WLOG_WARN,
3151 "Transmit_Call unexpected length: Actual: %" PRIu32
3152 ", Expected: %" PRIu32
" (ioRecvPci.cbExtraBytes)",
3153 length, ioRecvPci.cbExtraBytes);
3154 return STATUS_INVALID_PARAMETER;
3157 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioRecvPci.cbExtraBytes))
3158 return STATUS_BUFFER_TOO_SMALL;
3160 ioRecvPci.pbExtraBytes = Stream_Pointer(s);
3164 if (!call->pioRecvPci)
3166 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3167 return STATUS_NO_MEMORY;
3170 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3171 call->pioRecvPci->cbPciLength =
3174 Stream_Read(s, pbExtraBytes, ioRecvPci.cbExtraBytes);
3175 smartcard_unpack_read_size_align(s, ioRecvPci.cbExtraBytes, 4);
3181 if (!call->pioRecvPci)
3183 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3184 return STATUS_NO_MEMORY;
3187 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3192 smartcard_trace_transmit_call(log, call);
3193 return SCARD_S_SUCCESS;
3199 wLog* log = scard_log();
3204 UINT32 cbRecvLength = ret->cbRecvLength;
3205 UINT32 cbRecvPci = ret->pioRecvPci ? ret->pioRecvPci->cbPciLength : 0;
3207 smartcard_trace_transmit_return(log, ret);
3209 if (!ret->pbRecvBuffer)
3212 if (!smartcard_ndr_pointer_write(s, &index, cbRecvPci))
3213 return SCARD_E_NO_MEMORY;
3214 if (!Stream_EnsureRemainingCapacity(s, 4))
3215 return SCARD_E_NO_MEMORY;
3216 Stream_Write_UINT32(s, cbRecvLength);
3217 if (!smartcard_ndr_pointer_write(s, &index, cbRecvLength))
3218 return SCARD_E_NO_MEMORY;
3220 if (ret->pioRecvPci)
3222 UINT32 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
3225 if (!Stream_EnsureRemainingCapacity(s, cbExtraBytes + 16))
3227 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3228 return SCARD_F_INTERNAL_ERROR;
3231 Stream_Write_UINT32(s, ret->pioRecvPci->dwProtocol);
3232 Stream_Write_UINT32(s, cbExtraBytes);
3233 if (!smartcard_ndr_pointer_write(s, &index, cbExtraBytes))
3234 return SCARD_E_NO_MEMORY;
3235 error = smartcard_ndr_write(s, pbExtraBytes, cbExtraBytes, 1, NDR_PTR_SIMPLE);
3240 status = smartcard_ndr_write(s, ret->pbRecvBuffer, ret->cbRecvLength, 1, NDR_PTR_SIMPLE);
3241 if (status != SCARD_S_SUCCESS)
3243 return ret->ReturnCode;
3248 UINT32 rgReaderStatesNdrPtr = 0;
3249 UINT32 rgAtrMasksNdrPtr = 0;
3251 UINT32 pbContextNdrPtr = 0;
3254 wLog* log = scard_log();
3256 call->rgReaderStates = NULL;
3258 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3260 if (status != SCARD_S_SUCCESS)
3263 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3264 return STATUS_BUFFER_TOO_SMALL;
3266 Stream_Read_UINT32(s, call->cAtrs);
3267 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3268 return ERROR_INVALID_DATA;
3269 Stream_Read_UINT32(s, call->cReaders);
3270 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3271 return ERROR_INVALID_DATA;
3273 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3274 &(call->handles.hContext));
3275 if (status != SCARD_S_SUCCESS)
3278 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3280 WLog_Print(log, WLOG_WARN,
3281 "LocateCardsByATRA_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3282 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3283 rgAtrMasksNdrPtr, call->cAtrs);
3284 return STATUS_INVALID_PARAMETER;
3287 if (rgAtrMasksNdrPtr)
3289 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3290 if (status != SCARD_S_SUCCESS)
3294 if (rgReaderStatesNdrPtr)
3297 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
3298 if (status != SCARD_S_SUCCESS)
3302 smartcard_trace_locate_cards_by_atr_a_call(log, call);
3303 return SCARD_S_SUCCESS;
3308 UINT32 sz1NdrPtr = 0;
3309 UINT32 sz2NdrPtr = 0;
3311 UINT32 pbContextNdrPtr = 0;
3314 wLog* log = scard_log();
3316 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3318 if (status != SCARD_S_SUCCESS)
3321 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3322 return ERROR_INVALID_DATA;
3323 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3324 return ERROR_INVALID_DATA;
3327 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3328 if (status != SCARD_S_SUCCESS)
3333 status = smartcard_ndr_read_a(log, s, &call->sz1, NDR_PTR_FULL);
3334 if (status != SCARD_S_SUCCESS)
3339 status = smartcard_ndr_read_a(log, s, &call->sz2, NDR_PTR_FULL);
3340 if (status != SCARD_S_SUCCESS)
3343 smartcard_trace_context_and_two_strings_a_call(log, call);
3344 return SCARD_S_SUCCESS;
3349 UINT32 sz1NdrPtr = 0;
3350 UINT32 sz2NdrPtr = 0;
3352 UINT32 pbContextNdrPtr = 0;
3355 wLog* log = scard_log();
3357 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3359 if (status != SCARD_S_SUCCESS)
3362 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3363 return ERROR_INVALID_DATA;
3364 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3365 return ERROR_INVALID_DATA;
3368 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3369 if (status != SCARD_S_SUCCESS)
3374 status = smartcard_ndr_read_w(log, s, &call->sz1, NDR_PTR_FULL);
3375 if (status != SCARD_S_SUCCESS)
3380 status = smartcard_ndr_read_w(log, s, &call->sz2, NDR_PTR_FULL);
3381 if (status != SCARD_S_SUCCESS)
3384 smartcard_trace_context_and_two_strings_w_call(log, call);
3385 return SCARD_S_SUCCESS;
3390 UINT32 sz1NdrPtr = 0;
3391 UINT32 sz2NdrPtr = 0;
3393 UINT32 pbContextNdrPtr = 0;
3396 wLog* log = scard_log();
3398 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3400 if (status != SCARD_S_SUCCESS)
3403 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3404 return STATUS_BUFFER_TOO_SMALL;
3406 Stream_Read_UINT32(s, call->cBytes);
3407 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3408 return ERROR_INVALID_DATA;
3410 Stream_Read_UINT32(s, call->cReaders);
3411 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3412 return ERROR_INVALID_DATA;
3414 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3415 &(call->handles.hContext));
3416 if (status != SCARD_S_SUCCESS)
3421 status = smartcard_ndr_read_fixed_string_a(log, s, &call->mszCards, call->cBytes,
3423 if (status != SCARD_S_SUCCESS)
3429 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
3430 if (status != SCARD_S_SUCCESS)
3433 smartcard_trace_locate_cards_a_call(log, call);
3434 return SCARD_S_SUCCESS;
3439 UINT32 sz1NdrPtr = 0;
3440 UINT32 sz2NdrPtr = 0;
3442 UINT32 pbContextNdrPtr = 0;
3445 wLog* log = scard_log();
3447 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3449 if (status != SCARD_S_SUCCESS)
3452 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3453 return STATUS_BUFFER_TOO_SMALL;
3455 Stream_Read_UINT32(s, call->cBytes);
3456 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3457 return ERROR_INVALID_DATA;
3459 Stream_Read_UINT32(s, call->cReaders);
3460 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3461 return ERROR_INVALID_DATA;
3463 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3464 &(call->handles.hContext));
3465 if (status != SCARD_S_SUCCESS)
3470 status = smartcard_ndr_read_fixed_string_w(log, s, &call->mszCards, call->cBytes,
3472 if (status != SCARD_S_SUCCESS)
3478 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
3479 if (status != SCARD_S_SUCCESS)
3482 smartcard_trace_locate_cards_w_call(log, call);
3483 return SCARD_S_SUCCESS;
3490 UINT32 pbContextNdrPtr = 0;
3493 wLog* log = scard_log();
3495 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3497 if (status != SCARD_S_SUCCESS)
3499 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3500 if (status != SCARD_S_SUCCESS)
3503 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3504 return STATUS_BUFFER_TOO_SMALL;
3505 Stream_Read_UINT32(s, call->dwAttrId);
3506 Stream_Read_UINT32(s, call->cbAttrLen);
3508 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
3509 return ERROR_INVALID_DATA;
3511 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3512 &(call->handles.hContext));
3513 if (status != SCARD_S_SUCCESS)
3516 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3517 if (status != SCARD_S_SUCCESS)
3523 status = smartcard_ndr_read_ex(log, s, &call->pbAttr, 0, 1, NDR_PTR_SIMPLE, &len);
3524 if (status != SCARD_S_SUCCESS)
3526 if (call->cbAttrLen > len)
3527 call->cbAttrLen = WINPR_ASSERTING_INT_CAST(DWORD, len);
3530 call->cbAttrLen = 0;
3531 smartcard_trace_set_attrib_call(log, call);
3532 return SCARD_S_SUCCESS;
3537 UINT32 rgReaderStatesNdrPtr = 0;
3538 UINT32 rgAtrMasksNdrPtr = 0;
3540 UINT32 pbContextNdrPtr = 0;
3543 wLog* log = scard_log();
3545 call->rgReaderStates = NULL;
3547 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3549 if (status != SCARD_S_SUCCESS)
3552 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3553 return STATUS_BUFFER_TOO_SMALL;
3555 Stream_Read_UINT32(s, call->cAtrs);
3556 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3557 return ERROR_INVALID_DATA;
3559 Stream_Read_UINT32(s, call->cReaders);
3560 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3561 return ERROR_INVALID_DATA;
3563 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3564 &(call->handles.hContext));
3565 if (status != SCARD_S_SUCCESS)
3568 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3570 WLog_Print(log, WLOG_WARN,
3571 "LocateCardsByATRW_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3572 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3573 rgAtrMasksNdrPtr, call->cAtrs);
3574 return STATUS_INVALID_PARAMETER;
3577 if (rgAtrMasksNdrPtr)
3579 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3580 if (status != SCARD_S_SUCCESS)
3584 if (rgReaderStatesNdrPtr)
3587 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
3588 if (status != SCARD_S_SUCCESS)
3592 smartcard_trace_locate_cards_by_atr_w_call(log, call);
3593 return SCARD_S_SUCCESS;
3598 UINT32 mszNdrPtr = 0;
3599 UINT32 contextNdrPtr = 0;
3601 UINT32 pbContextNdrPtr = 0;
3604 wLog* log = scard_log();
3606 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3607 return ERROR_INVALID_DATA;
3609 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3610 &index, &pbContextNdrPtr);
3611 if (status != SCARD_S_SUCCESS)
3614 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3615 return ERROR_INVALID_DATA;
3617 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3618 return STATUS_BUFFER_TOO_SMALL;
3619 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3620 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
3621 Stream_Read_UINT32(s, call->Common.cbDataLen);
3623 call->szLookupName = NULL;
3626 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
3627 if (status != SCARD_S_SUCCESS)
3631 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3632 &call->Common.handles.hContext);
3633 if (status != SCARD_S_SUCCESS)
3638 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3639 if (status != SCARD_S_SUCCESS)
3642 smartcard_trace_read_cache_a_call(log, call);
3643 return SCARD_S_SUCCESS;
3648 UINT32 mszNdrPtr = 0;
3649 UINT32 contextNdrPtr = 0;
3651 UINT32 pbContextNdrPtr = 0;
3654 wLog* log = scard_log();
3656 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3657 return ERROR_INVALID_DATA;
3659 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3660 &index, &pbContextNdrPtr);
3661 if (status != SCARD_S_SUCCESS)
3664 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3665 return ERROR_INVALID_DATA;
3667 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3668 return STATUS_BUFFER_TOO_SMALL;
3669 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3670 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
3671 Stream_Read_UINT32(s, call->Common.cbDataLen);
3673 call->szLookupName = NULL;
3676 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
3677 if (status != SCARD_S_SUCCESS)
3681 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3682 &call->Common.handles.hContext);
3683 if (status != SCARD_S_SUCCESS)
3688 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3689 if (status != SCARD_S_SUCCESS)
3692 smartcard_trace_read_cache_w_call(log, call);
3693 return SCARD_S_SUCCESS;
3698 UINT32 mszNdrPtr = 0;
3699 UINT32 contextNdrPtr = 0;
3700 UINT32 pbDataNdrPtr = 0;
3702 UINT32 pbContextNdrPtr = 0;
3705 wLog* log = scard_log();
3707 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3708 return ERROR_INVALID_DATA;
3710 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3711 &index, &pbContextNdrPtr);
3712 if (status != SCARD_S_SUCCESS)
3715 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3716 return ERROR_INVALID_DATA;
3718 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
3719 return STATUS_BUFFER_TOO_SMALL;
3721 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3722 Stream_Read_UINT32(s, call->Common.cbDataLen);
3724 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
3725 return ERROR_INVALID_DATA;
3727 call->szLookupName = NULL;
3730 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
3731 if (status != SCARD_S_SUCCESS)
3735 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3736 &call->Common.handles.hContext);
3737 if (status != SCARD_S_SUCCESS)
3740 call->Common.CardIdentifier = NULL;
3743 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3744 if (status != SCARD_S_SUCCESS)
3748 call->Common.pbData = NULL;
3751 status = smartcard_ndr_read(log, s, &call->Common.pbData, call->Common.cbDataLen, 1,
3753 if (status != SCARD_S_SUCCESS)
3756 smartcard_trace_write_cache_a_call(log, call);
3757 return SCARD_S_SUCCESS;
3762 UINT32 mszNdrPtr = 0;
3763 UINT32 contextNdrPtr = 0;
3764 UINT32 pbDataNdrPtr = 0;
3766 UINT32 pbContextNdrPtr = 0;
3769 wLog* log = scard_log();
3771 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3772 return ERROR_INVALID_DATA;
3774 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3775 &index, &pbContextNdrPtr);
3776 if (status != SCARD_S_SUCCESS)
3779 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3780 return ERROR_INVALID_DATA;
3782 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
3783 return STATUS_BUFFER_TOO_SMALL;
3784 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3785 Stream_Read_UINT32(s, call->Common.cbDataLen);
3787 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
3788 return ERROR_INVALID_DATA;
3790 call->szLookupName = NULL;
3793 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
3794 if (status != SCARD_S_SUCCESS)
3798 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3799 &call->Common.handles.hContext);
3800 if (status != SCARD_S_SUCCESS)
3803 call->Common.CardIdentifier = NULL;
3806 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3807 if (status != SCARD_S_SUCCESS)
3811 call->Common.pbData = NULL;
3814 status = smartcard_ndr_read(log, s, &call->Common.pbData, call->Common.cbDataLen, 1,
3816 if (status != SCARD_S_SUCCESS)
3819 smartcard_trace_write_cache_w_call(log, call);
3826 wLog* log = scard_log();
3829 UINT32 pbContextNdrPtr = 0;
3831 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3833 if (status != SCARD_S_SUCCESS)
3836 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3837 if (status != SCARD_S_SUCCESS)
3840 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3841 &(call->handles.hContext));
3842 if (status != SCARD_S_SUCCESS)
3844 WLog_Print(log, WLOG_ERROR,
3845 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
3850 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3851 if (status != SCARD_S_SUCCESS)
3852 WLog_Print(log, WLOG_ERROR,
3853 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
3855 smartcard_trace_get_transmit_count_call(log, call);
3862 wLog* log = scard_log();
3863 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
3864 &call->szReaderName);
3870 wLog* log = scard_log();
3871 return smartcard_unpack_common_context_and_string_a(log, s, &call->handles.hContext, &call->sz);
3877 wLog* log = scard_log();
3878 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext, &call->sz);
3884 wLog* log = scard_log();
3885 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
3886 &call->szReaderName);
3892 wLog* log = scard_log();
3893 smartcard_trace_device_type_id_return(log, ret);
3895 if (!Stream_EnsureRemainingCapacity(s, 4))
3897 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3898 return SCARD_F_INTERNAL_ERROR;
3901 Stream_Write_UINT32(s, ret->dwDeviceId);
3903 return ret->ReturnCode;
3909 wLog* log = scard_log();
3912 DWORD cbDataLen = ret->cReaders;
3915 smartcard_trace_locate_cards_return(log, ret);
3916 if (ret->ReturnCode != SCARD_S_SUCCESS)
3918 if (cbDataLen == SCARD_AUTOALLOCATE)
3921 if (!Stream_EnsureRemainingCapacity(s, 4))
3923 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3924 return SCARD_F_INTERNAL_ERROR;
3927 Stream_Write_UINT32(s, cbDataLen);
3928 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3929 return SCARD_E_NO_MEMORY;
3931 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cbDataLen, NDR_PTR_SIMPLE);
3932 if (status != SCARD_S_SUCCESS)
3934 return ret->ReturnCode;
3940 wLog* log = scard_log();
3944 DWORD cbDataLen = ret->cbDataLen;
3945 smartcard_trace_get_reader_icon_return(log, ret);
3946 if (ret->ReturnCode != SCARD_S_SUCCESS)
3948 if (cbDataLen == SCARD_AUTOALLOCATE)
3951 if (!Stream_EnsureRemainingCapacity(s, 4))
3953 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3954 return SCARD_F_INTERNAL_ERROR;
3957 Stream_Write_UINT32(s, cbDataLen);
3958 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3959 return SCARD_E_NO_MEMORY;
3961 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
3962 if (status != SCARD_S_SUCCESS)
3964 return ret->ReturnCode;
3970 wLog* log = scard_log();
3972 smartcard_trace_get_transmit_count_return(log, ret);
3974 if (!Stream_EnsureRemainingCapacity(s, 4))
3976 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3977 return SCARD_F_INTERNAL_ERROR;
3980 Stream_Write_UINT32(s, ret->cTransmitCount);
3982 return ret->ReturnCode;
3988 wLog* log = scard_log();
3992 DWORD cbDataLen = ret->cbDataLen;
3993 smartcard_trace_read_cache_return(log, ret);
3994 if (ret->ReturnCode != SCARD_S_SUCCESS)
3997 if (cbDataLen == SCARD_AUTOALLOCATE)
4000 if (!Stream_EnsureRemainingCapacity(s, 4))
4002 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4003 return SCARD_F_INTERNAL_ERROR;
4006 Stream_Write_UINT32(s, cbDataLen);
4007 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
4008 return SCARD_E_NO_MEMORY;
4010 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
4011 if (status != SCARD_S_SUCCESS)
4013 return ret->ReturnCode;