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(wLog* log,
wStream* s, BYTE** data,
size_t min,
size_t elementSize,
136 return STATUS_INVALID_PARAMETER;
139 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, required))
140 return STATUS_BUFFER_TOO_SMALL;
145 Stream_Read_UINT32(s, len);
146 Stream_Read_UINT32(s, offset);
147 Stream_Read_UINT32(s, len2);
148 if (len != offset + len2)
150 WLog_Print(log, WLOG_ERROR,
151 "Invalid data when reading full NDR pointer: total=%" PRIu32
152 ", offset=%" PRIu32
", remaining=%" PRIu32,
154 return STATUS_BUFFER_TOO_SMALL;
158 Stream_Read_UINT32(s, len);
160 if ((len != min) && (min > 0))
162 WLog_Print(log, WLOG_ERROR,
163 "Invalid data when reading simple NDR pointer: total=%" PRIu32
164 ", expected=%" PRIu32,
166 return STATUS_BUFFER_TOO_SMALL;
173 return STATUS_INVALID_PARAMETER;
178 WLog_Print(log, WLOG_ERROR,
179 "Invalid length read from NDR pointer, minimum %" PRIu32
", got %" PRIu32, min,
181 return STATUS_DATA_ERROR;
184 if (len > SIZE_MAX / 2)
185 return STATUS_BUFFER_TOO_SMALL;
187 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(log, s, len, elementSize))
188 return STATUS_BUFFER_TOO_SMALL;
195 r = calloc(len +
sizeof(WCHAR),
sizeof(CHAR));
197 return SCARD_E_NO_MEMORY;
198 Stream_Read(s, r, len);
199 smartcard_unpack_read_size_align(s, len, 4);
201 return STATUS_SUCCESS;
204static BOOL smartcard_ndr_pointer_write(
wStream* s, UINT32* index, DWORD length)
206 const UINT32 ndrPtr = 0x20000 + (*index) * 4;
210 if (!Stream_EnsureRemainingCapacity(s, 4))
215 Stream_Write_UINT32(s, ndrPtr);
216 (*index) = (*index) + 1;
219 Stream_Write_UINT32(s, 0);
223static LONG smartcard_ndr_write(
wStream* s,
const BYTE* data, UINT32 size, UINT32 elementSize,
226 const UINT32 offset = 0;
227 const UINT32 len = size;
228 const UINT32 dataLen = size * elementSize;
232 return SCARD_S_SUCCESS;
246 return SCARD_E_INVALID_PARAMETER;
249 if (!Stream_EnsureRemainingCapacity(s, required + dataLen + 4))
250 return STATUS_BUFFER_TOO_SMALL;
255 Stream_Write_UINT32(s, len);
256 Stream_Write_UINT32(s, offset);
257 Stream_Write_UINT32(s, len);
260 Stream_Write_UINT32(s, len);
265 return SCARD_E_INVALID_PARAMETER;
269 Stream_Write(s, data, dataLen);
271 Stream_Zero(s, dataLen);
272 return smartcard_pack_write_size_align(s, len, 4);
284 WINPR_ASSERT(data || (size == 0));
290 size_t min, ndr_ptr_t type)
301static LONG smartcard_ndr_read_fixed_string_a(wLog* log,
wStream* s, CHAR** data,
size_t min,
310 return smartcard_ndr_read(log, s, u.ppv, min,
sizeof(CHAR), type);
313static LONG smartcard_ndr_read_fixed_string_w(wLog* log,
wStream* s, WCHAR** data,
size_t min,
322 return smartcard_ndr_read(log, s, u.ppv, min,
sizeof(WCHAR), type);
325static LONG smartcard_ndr_read_a(wLog* log,
wStream* s, CHAR** data, ndr_ptr_t type)
333 return smartcard_ndr_read(log, s, u.ppv, 0,
sizeof(CHAR), type);
336static LONG smartcard_ndr_read_w(wLog* log,
wStream* s, WCHAR** data, ndr_ptr_t type)
344 return smartcard_ndr_read(log, s, u.ppv, 0,
sizeof(WCHAR), type);
347static LONG smartcard_ndr_read_u(wLog* log,
wStream* s,
UUID** data)
355 return smartcard_ndr_read(log, s, u.ppv, 1,
sizeof(
UUID), NDR_PTR_FIXED);
358static char* smartcard_convert_string_list(
const void* in,
size_t bytes, BOOL unicode)
379 mszA = ConvertMszWCharNToUtf8Alloc(
string.wz, bytes /
sizeof(WCHAR), &length);
385 mszA = (
char*)calloc(bytes,
sizeof(
char));
388 CopyMemory(mszA,
string.sz, bytes - 1);
397 for (
size_t index = 0; index < length - 1; index++)
399 if (mszA[index] ==
'\0')
406static char* smartcard_msz_dump_a(
const char* msz,
size_t len,
char* buffer,
size_t bufferLen)
409 const char* cur = msz;
411 while ((len > 0) && cur && cur[0] !=
'\0' && (bufferLen > 0))
413 size_t clen = strnlen(cur, len);
414 int rc = _snprintf(buf, bufferLen,
"%s", cur);
415 bufferLen -= (size_t)rc;
424static char* smartcard_msz_dump_w(
const WCHAR* msz,
size_t len,
char* buffer,
size_t bufferLen)
429 char* sz = ConvertMszWCharNToUtf8Alloc(msz, len, &szlen);
433 smartcard_msz_dump_a(sz, szlen, buffer, bufferLen);
438static char* smartcard_array_dump(
const void* pd,
size_t len,
char* buffer,
size_t bufferLen)
440 const BYTE* data = pd;
442 char* start = buffer;
444 WINPR_ASSERT(buffer || (bufferLen == 0));
446 if (!data && (len > 0))
448 (void)_snprintf(buffer, bufferLen,
"{ NULL [%" PRIuz
"] }", len);
452 rc = _snprintf(buffer, bufferLen,
"{ ");
453 if ((rc < 0) || ((
size_t)rc >= bufferLen))
456 bufferLen -= (size_t)rc;
458 for (
size_t x = 0; x < len; x++)
460 rc = _snprintf(buffer, bufferLen,
"%02X", data[x]);
461 if ((rc < 0) || ((
size_t)rc >= bufferLen))
464 bufferLen -= (size_t)rc;
467 rc = _snprintf(buffer, bufferLen,
" }");
468 if ((rc < 0) || ((
size_t)rc >= bufferLen))
475static void smartcard_log_redir_handle(wLog* log,
const REDIR_SCARDHANDLE* pHandle)
477 char buffer[128] = { 0 };
479 WINPR_ASSERT(pHandle);
480 WLog_Print(log, g_LogLevel,
" hContext: %s",
481 smartcard_array_dump(pHandle->pbHandle, pHandle->cbHandle, buffer,
sizeof(buffer)));
486 char buffer[128] = { 0 };
488 WINPR_ASSERT(phContext);
490 log, g_LogLevel,
"hContext: %s",
491 smartcard_array_dump(phContext->pbContext, phContext->cbContext, buffer,
sizeof(buffer)));
494static void smartcard_trace_context_and_string_call_a(wLog* log,
const char* name,
498 if (!WLog_IsLevelActive(log, g_LogLevel))
501 WLog_Print(log, g_LogLevel,
"%s {", name);
502 smartcard_log_context(log, phContext);
503 WLog_Print(log, g_LogLevel,
" sz=%s", sz);
505 WLog_Print(log, g_LogLevel,
"}");
508static void smartcard_trace_context_and_string_call_w(wLog* log,
const char* name,
512 char tmp[1024] = { 0 };
514 if (!WLog_IsLevelActive(log, g_LogLevel))
518 (void)ConvertWCharToUtf8(sz, tmp, ARRAYSIZE(tmp));
520 WLog_Print(log, g_LogLevel,
"%s {", name);
521 smartcard_log_context(log, phContext);
522 WLog_Print(log, g_LogLevel,
" sz=%s", tmp);
523 WLog_Print(log, g_LogLevel,
"}");
526static void smartcard_trace_context_call(wLog* log,
const Context_Call* call,
const char* name)
530 if (!WLog_IsLevelActive(log, g_LogLevel))
533 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
534 smartcard_log_context(log, &call->handles.hContext);
536 WLog_Print(log, g_LogLevel,
"}");
544 if (!WLog_IsLevelActive(log, g_LogLevel))
547 WLog_Print(log, g_LogLevel,
"ListReaderGroups%S_Call {", unicode ?
"W" :
"A");
548 smartcard_log_context(log, &call->handles.hContext);
550 WLog_Print(log, g_LogLevel,
"fmszGroupsIsNULL: %" PRId32
" cchGroups: 0x%08" PRIx32,
551 call->fmszGroupsIsNULL, call->cchGroups);
552 WLog_Print(log, g_LogLevel,
"}");
555static void dump_reader_states_return(wLog* log,
const ReaderState_Return* rgReaderStates,
558 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
559 for (UINT32 index = 0; index < cReaders; index++)
561 char buffer[1024] = { 0 };
564 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
565 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
566 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
567 szCurrentState, readerState->dwCurrentState);
568 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
569 szEventState, readerState->dwEventState);
570 free(szCurrentState);
574 log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { %s }", index,
576 smartcard_array_dump(readerState->rgbAtr, readerState->cbAtr, buffer,
sizeof(buffer)));
583 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
584 for (UINT32 index = 0; index < cReaders; index++)
586 char buffer[1024] = { 0 };
590 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
591 readerState->szReader, readerState->cbAtr);
592 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
593 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
594 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
595 szCurrentState, readerState->dwCurrentState);
596 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
597 szEventState, readerState->dwEventState);
598 free(szCurrentState);
602 log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { %s }", index,
604 smartcard_array_dump(readerState->rgbAtr, readerState->cbAtr, buffer,
sizeof(buffer)));
611 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
612 for (UINT32 index = 0; index < cReaders; index++)
614 char buffer[1024] = { 0 };
617 (void)ConvertWCharToUtf8(readerState->szReader, buffer,
sizeof(buffer));
618 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
619 buffer, readerState->cbAtr);
620 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
621 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
622 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
623 szCurrentState, readerState->dwCurrentState);
624 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
625 szEventState, readerState->dwEventState);
626 free(szCurrentState);
630 log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { %s }", index,
632 smartcard_array_dump(readerState->rgbAtr, readerState->cbAtr, buffer,
sizeof(buffer)));
640 if (!WLog_IsLevelActive(log, g_LogLevel))
643 WLog_Print(log, g_LogLevel,
"GetStatusChangeW_Call {");
644 smartcard_log_context(log, &call->handles.hContext);
646 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
649 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
651 WLog_Print(log, g_LogLevel,
"}");
659 if (!WLog_IsLevelActive(log, g_LogLevel))
662 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
664 WLog_Print(log, g_LogLevel,
"ListReaderGroups%s_Return {", unicode ?
"W" :
"A");
665 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIx32
")",
666 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
667 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
668 WLog_Print(log, g_LogLevel,
"}");
672static void smartcard_trace_list_readers_call(wLog* log,
const ListReaders_Call* call, BOOL unicode)
676 if (!WLog_IsLevelActive(log, g_LogLevel))
679 char* mszGroupsA = smartcard_convert_string_list(call->mszGroups, call->cBytes, unicode);
681 WLog_Print(log, g_LogLevel,
"ListReaders%s_Call {", unicode ?
"W" :
"A");
682 smartcard_log_context(log, &call->handles.hContext);
684 WLog_Print(log, g_LogLevel,
685 "cBytes: %" PRIu32
" mszGroups: %s fmszReadersIsNULL: %" PRId32
686 " cchReaders: 0x%08" PRIX32
"",
687 call->cBytes, mszGroupsA, call->fmszReadersIsNULL, call->cchReaders);
688 WLog_Print(log, g_LogLevel,
"}");
693static void smartcard_trace_locate_cards_by_atr_a_call(wLog* log,
698 if (!WLog_IsLevelActive(log, g_LogLevel))
701 WLog_Print(log, g_LogLevel,
"LocateCardsByATRA_Call {");
702 smartcard_log_context(log, &call->handles.hContext);
704 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
706 WLog_Print(log, g_LogLevel,
"}");
709static void smartcard_trace_locate_cards_a_call(wLog* log,
const LocateCardsA_Call* call)
711 char buffer[8192] = { 0 };
715 if (!WLog_IsLevelActive(log, g_LogLevel))
718 WLog_Print(log, g_LogLevel,
"LocateCardsA_Call {");
719 smartcard_log_context(log, &call->handles.hContext);
720 WLog_Print(log, g_LogLevel,
" cBytes=%" PRId32, call->cBytes);
721 WLog_Print(log, g_LogLevel,
" mszCards=%s",
722 smartcard_msz_dump_a(call->mszCards, call->cBytes, buffer,
sizeof(buffer)));
723 WLog_Print(log, g_LogLevel,
" cReaders=%" PRId32, call->cReaders);
724 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
726 WLog_Print(log, g_LogLevel,
"}");
729static void smartcard_trace_locate_cards_return(wLog* log,
const LocateCards_Return* ret)
733 if (!WLog_IsLevelActive(log, g_LogLevel))
736 WLog_Print(log, g_LogLevel,
"LocateCards_Return {");
737 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
738 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
740 if (ret->ReturnCode == SCARD_S_SUCCESS)
742 WLog_Print(log, g_LogLevel,
" cReaders=%" PRId32, ret->cReaders);
744 WLog_Print(log, g_LogLevel,
"}");
751 if (!WLog_IsLevelActive(log, g_LogLevel))
754 WLog_Print(log, g_LogLevel,
"GetReaderIcon_Return {");
755 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
756 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
758 if (ret->ReturnCode == SCARD_S_SUCCESS)
760 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRId32, ret->cbDataLen);
762 WLog_Print(log, g_LogLevel,
"}");
769 if (!WLog_IsLevelActive(log, g_LogLevel))
772 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Return {");
773 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
774 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
776 WLog_Print(log, g_LogLevel,
" cTransmitCount=%" PRIu32, ret->cTransmitCount);
777 WLog_Print(log, g_LogLevel,
"}");
780static void smartcard_trace_read_cache_return(wLog* log,
const ReadCache_Return* ret)
784 if (!WLog_IsLevelActive(log, g_LogLevel))
787 WLog_Print(log, g_LogLevel,
"ReadCache_Return {");
788 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
789 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
791 if (ret->ReturnCode == SCARD_S_SUCCESS)
793 char buffer[1024] = { 0 };
794 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRId32, ret->cbDataLen);
795 WLog_Print(log, g_LogLevel,
" cbData: %s",
796 smartcard_array_dump(ret->pbData, ret->cbDataLen, buffer,
sizeof(buffer)));
798 WLog_Print(log, g_LogLevel,
"}");
801static void smartcard_trace_locate_cards_w_call(wLog* log,
const LocateCardsW_Call* call)
804 char buffer[8192] = { 0 };
806 if (!WLog_IsLevelActive(log, g_LogLevel))
809 WLog_Print(log, g_LogLevel,
"LocateCardsW_Call {");
810 smartcard_log_context(log, &call->handles.hContext);
811 WLog_Print(log, g_LogLevel,
" cBytes=%" PRId32, call->cBytes);
812 WLog_Print(log, g_LogLevel,
" sz2=%s",
813 smartcard_msz_dump_w(call->mszCards, call->cBytes, buffer,
sizeof(buffer)));
814 WLog_Print(log, g_LogLevel,
" cReaders=%" PRId32, call->cReaders);
815 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
816 WLog_Print(log, g_LogLevel,
"}");
819static void smartcard_trace_list_readers_return(wLog* log,
const ListReaders_Return* ret,
824 if (!WLog_IsLevelActive(log, g_LogLevel))
827 WLog_Print(log, g_LogLevel,
"ListReaders%s_Return {", unicode ?
"W" :
"A");
828 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
829 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
831 if (ret->ReturnCode != SCARD_S_SUCCESS)
833 WLog_Print(log, g_LogLevel,
"}");
837 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
839 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
840 WLog_Print(log, g_LogLevel,
"}");
849 if (!WLog_IsLevelActive(log, g_LogLevel))
852 WLog_Print(log, g_LogLevel,
"GetStatusChange%s_Return {", unicode ?
"W" :
"A");
853 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
854 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
855 WLog_Print(log, g_LogLevel,
" cReaders: %" PRIu32
"", ret->cReaders);
857 dump_reader_states_return(log, ret->rgReaderStates, ret->cReaders);
859 if (!ret->rgReaderStates && (ret->cReaders > 0))
861 WLog_Print(log, g_LogLevel,
" [INVALID STATE] rgReaderStates=NULL, cReaders=%" PRIu32,
864 else if (ret->ReturnCode != SCARD_S_SUCCESS)
866 WLog_Print(log, g_LogLevel,
" [INVALID RETURN] rgReaderStates, cReaders=%" PRIu32,
871 for (UINT32 index = 0; index < ret->cReaders; index++)
873 char buffer[1024] = { 0 };
875 char* szCurrentState = SCardGetReaderStateString(rgReaderState->dwCurrentState);
876 char* szEventState = SCardGetReaderStateString(rgReaderState->dwEventState);
877 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")",
878 index, szCurrentState, rgReaderState->dwCurrentState);
879 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")",
880 index, szEventState, rgReaderState->dwEventState);
881 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: cbAtr: %" PRIu32
" rgbAtr: %s", index,
882 rgReaderState->cbAtr,
883 smartcard_array_dump(rgReaderState->rgbAtr, rgReaderState->cbAtr, buffer,
885 free(szCurrentState);
890 WLog_Print(log, g_LogLevel,
"}");
893static void smartcard_trace_context_and_two_strings_a_call(wLog* log,
898 if (!WLog_IsLevelActive(log, g_LogLevel))
901 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
902 smartcard_log_context(log, &call->handles.hContext);
903 WLog_Print(log, g_LogLevel,
" sz1=%s", call->sz1);
904 WLog_Print(log, g_LogLevel,
" sz2=%s", call->sz2);
905 WLog_Print(log, g_LogLevel,
"}");
908static void smartcard_trace_context_and_two_strings_w_call(wLog* log,
912 char sz1[1024] = { 0 };
913 char sz2[1024] = { 0 };
915 if (!WLog_IsLevelActive(log, g_LogLevel))
918 (void)ConvertWCharToUtf8(call->sz1, sz1, ARRAYSIZE(sz1));
920 (void)ConvertWCharToUtf8(call->sz2, sz2, ARRAYSIZE(sz2));
922 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
923 smartcard_log_context(log, &call->handles.hContext);
924 WLog_Print(log, g_LogLevel,
" sz1=%s", sz1);
925 WLog_Print(log, g_LogLevel,
" sz2=%s", sz2);
926 WLog_Print(log, g_LogLevel,
"}");
933 if (!WLog_IsLevelActive(log, g_LogLevel))
936 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Call {");
937 smartcard_log_context(log, &call->handles.hContext);
938 smartcard_log_redir_handle(log, &call->handles.hCard);
940 WLog_Print(log, g_LogLevel,
"}");
943static void smartcard_trace_write_cache_a_call(wLog* log,
const WriteCacheA_Call* call)
946 char buffer[1024] = { 0 };
948 if (!WLog_IsLevelActive(log, g_LogLevel))
951 WLog_Print(log, g_LogLevel,
"WriteCacheA_Call {");
953 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
955 smartcard_log_context(log, &call->Common.handles.hContext);
957 log, g_LogLevel,
"..CardIdentifier=%s",
958 smartcard_array_dump(call->Common.CardIdentifier,
sizeof(
UUID), buffer,
sizeof(buffer)));
959 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
960 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
962 log, g_LogLevel,
" pbData=%s",
963 smartcard_array_dump(call->Common.pbData, call->Common.cbDataLen, buffer,
sizeof(buffer)));
964 WLog_Print(log, g_LogLevel,
"}");
967static void smartcard_trace_write_cache_w_call(wLog* log,
const WriteCacheW_Call* call)
970 char tmp[1024] = { 0 };
971 char buffer[1024] = { 0 };
973 if (!WLog_IsLevelActive(log, g_LogLevel))
976 WLog_Print(log, g_LogLevel,
"WriteCacheW_Call {");
978 if (call->szLookupName)
979 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
980 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
982 smartcard_log_context(log, &call->Common.handles.hContext);
984 log, g_LogLevel,
"..CardIdentifier=%s",
985 smartcard_array_dump(call->Common.CardIdentifier,
sizeof(
UUID), buffer,
sizeof(buffer)));
986 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
987 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
989 log, g_LogLevel,
" pbData=%s",
990 smartcard_array_dump(call->Common.pbData, call->Common.cbDataLen, buffer,
sizeof(buffer)));
991 WLog_Print(log, g_LogLevel,
"}");
994static void smartcard_trace_read_cache_a_call(wLog* log,
const ReadCacheA_Call* call)
997 char buffer[1024] = { 0 };
999 if (!WLog_IsLevelActive(log, g_LogLevel))
1002 WLog_Print(log, g_LogLevel,
"ReadCacheA_Call {");
1004 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
1005 smartcard_log_context(log, &call->Common.handles.hContext);
1007 log, g_LogLevel,
"..CardIdentifier=%s",
1008 smartcard_array_dump(call->Common.CardIdentifier,
sizeof(
UUID), buffer,
sizeof(buffer)));
1009 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1010 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1011 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1013 WLog_Print(log, g_LogLevel,
"}");
1016static void smartcard_trace_read_cache_w_call(wLog* log,
const ReadCacheW_Call* call)
1019 char tmp[1024] = { 0 };
1020 char buffer[1024] = { 0 };
1022 if (!WLog_IsLevelActive(log, g_LogLevel))
1025 WLog_Print(log, g_LogLevel,
"ReadCacheW_Call {");
1026 if (call->szLookupName)
1027 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
1028 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
1030 smartcard_log_context(log, &call->Common.handles.hContext);
1032 log, g_LogLevel,
"..CardIdentifier=%s",
1033 smartcard_array_dump(call->Common.CardIdentifier,
sizeof(
UUID), buffer,
sizeof(buffer)));
1034 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1035 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1036 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1038 WLog_Print(log, g_LogLevel,
"}");
1041static void smartcard_trace_transmit_call(wLog* log,
const Transmit_Call* call)
1044 UINT32 cbExtraBytes = 0;
1045 BYTE* pbExtraBytes = NULL;
1047 if (!WLog_IsLevelActive(log, g_LogLevel))
1050 WLog_Print(log, g_LogLevel,
"Transmit_Call {");
1051 smartcard_log_context(log, &call->handles.hContext);
1052 smartcard_log_redir_handle(log, &call->handles.hCard);
1054 if (call->pioSendPci)
1056 cbExtraBytes = (UINT32)(call->pioSendPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1058 WLog_Print(log, g_LogLevel,
"pioSendPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1059 call->pioSendPci->dwProtocol, cbExtraBytes);
1063 char buffer[1024] = { 0 };
1064 WLog_Print(log, g_LogLevel,
"pbExtraBytes: %s",
1065 smartcard_array_dump(pbExtraBytes, cbExtraBytes, buffer,
sizeof(buffer)));
1070 WLog_Print(log, g_LogLevel,
"pioSendPci: null");
1073 WLog_Print(log, g_LogLevel,
"cbSendLength: %" PRIu32
"", call->cbSendLength);
1075 if (call->pbSendBuffer)
1077 char buffer[1024] = { 0 };
1079 log, g_LogLevel,
"pbSendBuffer: %s",
1080 smartcard_array_dump(call->pbSendBuffer, call->cbSendLength, buffer,
sizeof(buffer)));
1084 WLog_Print(log, g_LogLevel,
"pbSendBuffer: null");
1087 if (call->pioRecvPci)
1089 cbExtraBytes = (UINT32)(call->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1091 WLog_Print(log, g_LogLevel,
"pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1092 call->pioRecvPci->dwProtocol, cbExtraBytes);
1096 char buffer[1024] = { 0 };
1097 WLog_Print(log, g_LogLevel,
"pbExtraBytes: %s",
1098 smartcard_array_dump(pbExtraBytes, cbExtraBytes, buffer,
sizeof(buffer)));
1103 WLog_Print(log, g_LogLevel,
"pioRecvPci: null");
1106 WLog_Print(log, g_LogLevel,
"fpbRecvBufferIsNULL: %" PRId32
" cbRecvLength: %" PRIu32
"",
1107 call->fpbRecvBufferIsNULL, call->cbRecvLength);
1108 WLog_Print(log, g_LogLevel,
"}");
1111static void smartcard_trace_locate_cards_by_atr_w_call(wLog* log,
1116 if (!WLog_IsLevelActive(log, g_LogLevel))
1119 WLog_Print(log, g_LogLevel,
"LocateCardsByATRW_Call {");
1120 smartcard_log_context(log, &call->handles.hContext);
1122 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
1124 WLog_Print(log, g_LogLevel,
"}");
1127static void smartcard_trace_transmit_return(wLog* log,
const Transmit_Return* ret)
1130 UINT32 cbExtraBytes = 0;
1131 BYTE* pbExtraBytes = NULL;
1133 if (!WLog_IsLevelActive(log, g_LogLevel))
1136 WLog_Print(log, g_LogLevel,
"Transmit_Return {");
1137 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1138 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
1140 if (ret->pioRecvPci)
1142 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1144 WLog_Print(log, g_LogLevel,
1145 " pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1146 ret->pioRecvPci->dwProtocol, cbExtraBytes);
1150 char buffer[1024] = { 0 };
1151 WLog_Print(log, g_LogLevel,
" pbExtraBytes: %s",
1152 smartcard_array_dump(pbExtraBytes, cbExtraBytes, buffer,
sizeof(buffer)));
1157 WLog_Print(log, g_LogLevel,
" pioRecvPci: null");
1160 WLog_Print(log, g_LogLevel,
" cbRecvLength: %" PRIu32
"", ret->cbRecvLength);
1162 if (ret->pbRecvBuffer)
1164 char buffer[1024] = { 0 };
1166 log, g_LogLevel,
" pbRecvBuffer: %s",
1167 smartcard_array_dump(ret->pbRecvBuffer, ret->cbRecvLength, buffer,
sizeof(buffer)));
1171 WLog_Print(log, g_LogLevel,
" pbRecvBuffer: null");
1174 WLog_Print(log, g_LogLevel,
"}");
1177static void smartcard_trace_control_return(wLog* log,
const Control_Return* ret)
1181 if (!WLog_IsLevelActive(log, g_LogLevel))
1184 WLog_Print(log, g_LogLevel,
"Control_Return {");
1185 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1186 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
1187 WLog_Print(log, g_LogLevel,
" cbOutBufferSize: %" PRIu32
"", ret->cbOutBufferSize);
1189 if (ret->pvOutBuffer)
1191 char buffer[1024] = { 0 };
1193 log, g_LogLevel,
"pvOutBuffer: %s",
1194 smartcard_array_dump(ret->pvOutBuffer, ret->cbOutBufferSize, buffer,
sizeof(buffer)));
1198 WLog_Print(log, g_LogLevel,
"pvOutBuffer: null");
1201 WLog_Print(log, g_LogLevel,
"}");
1204static void smartcard_trace_control_call(wLog* log,
const Control_Call* call)
1208 if (!WLog_IsLevelActive(log, g_LogLevel))
1211 WLog_Print(log, g_LogLevel,
"Control_Call {");
1212 smartcard_log_context(log, &call->handles.hContext);
1213 smartcard_log_redir_handle(log, &call->handles.hCard);
1215 WLog_Print(log, g_LogLevel,
1216 "dwControlCode: 0x%08" PRIX32
" cbInBufferSize: %" PRIu32
1217 " fpvOutBufferIsNULL: %" PRId32
" cbOutBufferSize: %" PRIu32
"",
1218 call->dwControlCode, call->cbInBufferSize, call->fpvOutBufferIsNULL,
1219 call->cbOutBufferSize);
1221 if (call->pvInBuffer)
1223 char buffer[1024] = { 0 };
1225 log, WLOG_DEBUG,
"pbInBuffer: %s",
1226 smartcard_array_dump(call->pvInBuffer, call->cbInBufferSize, buffer,
sizeof(buffer)));
1230 WLog_Print(log, g_LogLevel,
"pvInBuffer: null");
1233 WLog_Print(log, g_LogLevel,
"}");
1236static void smartcard_trace_set_attrib_call(wLog* log,
const SetAttrib_Call* call)
1239 char buffer[8192] = { 0 };
1241 if (!WLog_IsLevelActive(log, g_LogLevel))
1244 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1245 smartcard_log_context(log, &call->handles.hContext);
1246 smartcard_log_redir_handle(log, &call->handles.hCard);
1247 WLog_Print(log, g_LogLevel,
"dwAttrId: 0x%08" PRIX32, call->dwAttrId);
1248 WLog_Print(log, g_LogLevel,
"cbAttrLen: 0x%08" PRId32, call->cbAttrLen);
1249 WLog_Print(log, g_LogLevel,
"pbAttr: %s",
1250 smartcard_array_dump(call->pbAttr, call->cbAttrLen, buffer,
sizeof(buffer)));
1251 WLog_Print(log, g_LogLevel,
"}");
1254static void smartcard_trace_get_attrib_return(wLog* log,
const GetAttrib_Return* ret,
1258 char buffer[1024] = { 0 };
1260 if (!WLog_IsLevelActive(log, g_LogLevel))
1263 WLog_Print(log, g_LogLevel,
"GetAttrib_Return {");
1264 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1265 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
1266 WLog_Print(log, g_LogLevel,
" dwAttrId: %s (0x%08" PRIX32
") cbAttrLen: 0x%08" PRIX32
"",
1267 SCardGetAttributeString(dwAttrId), dwAttrId, ret->cbAttrLen);
1268 WLog_Print(log, g_LogLevel,
" %s",
1269 smartcard_array_dump(ret->pbAttr, ret->cbAttrLen, buffer,
sizeof(buffer)));
1271 WLog_Print(log, g_LogLevel,
"}");
1274static void smartcard_trace_get_attrib_call(wLog* log,
const GetAttrib_Call* call)
1278 if (!WLog_IsLevelActive(log, g_LogLevel))
1281 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1282 smartcard_log_context(log, &call->handles.hContext);
1283 smartcard_log_redir_handle(log, &call->handles.hCard);
1285 WLog_Print(log, g_LogLevel,
1286 "dwAttrId: %s (0x%08" PRIX32
") fpbAttrIsNULL: %" PRId32
" cbAttrLen: 0x%08" PRIX32
1288 SCardGetAttributeString(call->dwAttrId), call->dwAttrId, call->fpbAttrIsNULL,
1290 WLog_Print(log, g_LogLevel,
"}");
1293static void smartcard_trace_status_call(wLog* log,
const Status_Call* call, BOOL unicode)
1297 if (!WLog_IsLevelActive(log, g_LogLevel))
1300 WLog_Print(log, g_LogLevel,
"Status%s_Call {", unicode ?
"W" :
"A");
1301 smartcard_log_context(log, &call->handles.hContext);
1302 smartcard_log_redir_handle(log, &call->handles.hCard);
1304 WLog_Print(log, g_LogLevel,
1305 "fmszReaderNamesIsNULL: %" PRId32
" cchReaderLen: %" PRIu32
" cbAtrLen: %" PRIu32
"",
1306 call->fmszReaderNamesIsNULL, call->cchReaderLen, call->cbAtrLen);
1307 WLog_Print(log, g_LogLevel,
"}");
1310static void smartcard_trace_status_return(wLog* log,
const Status_Return* ret, BOOL unicode)
1313 char* mszReaderNamesA = NULL;
1314 char buffer[1024] = { 0 };
1317 if (!WLog_IsLevelActive(log, g_LogLevel))
1319 cBytes = ret->cBytes;
1320 if (ret->ReturnCode != SCARD_S_SUCCESS)
1322 if (cBytes == SCARD_AUTOALLOCATE)
1324 mszReaderNamesA = smartcard_convert_string_list(ret->mszReaderNames, cBytes, unicode);
1326 WLog_Print(log, g_LogLevel,
"Status%s_Return {", unicode ?
"W" :
"A");
1327 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1328 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
1329 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
") dwProtocol: %s (0x%08" PRIX32
")",
1330 SCardGetCardStateString(ret->dwState), ret->dwState,
1331 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1333 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" mszReaderNames: %s", ret->cBytes,
1336 WLog_Print(log, g_LogLevel,
" cbAtrLen: %" PRIu32
" pbAtr: %s", ret->cbAtrLen,
1337 smartcard_array_dump(ret->pbAtr, ret->cbAtrLen, buffer,
sizeof(buffer)));
1338 WLog_Print(log, g_LogLevel,
"}");
1339 free(mszReaderNamesA);
1342static void smartcard_trace_state_return(wLog* log,
const State_Return* ret)
1345 char buffer[1024] = { 0 };
1348 if (!WLog_IsLevelActive(log, g_LogLevel))
1351 state = SCardGetReaderStateString(ret->dwState);
1352 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1353 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1354 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
1355 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
")", state, ret->dwState);
1356 WLog_Print(log, g_LogLevel,
" dwProtocol: %s (0x%08" PRIX32
")",
1357 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1358 WLog_Print(log, g_LogLevel,
" cbAtrLen: (0x%08" PRIX32
")", ret->cbAtrLen);
1359 WLog_Print(log, g_LogLevel,
" rgAtr: %s",
1360 smartcard_array_dump(ret->rgAtr,
sizeof(ret->rgAtr), buffer,
sizeof(buffer)));
1361 WLog_Print(log, g_LogLevel,
"}");
1365static void smartcard_trace_reconnect_return(wLog* log,
const Reconnect_Return* ret)
1369 if (!WLog_IsLevelActive(log, g_LogLevel))
1372 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1373 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1374 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
1375 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1376 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1377 WLog_Print(log, g_LogLevel,
"}");
1380static void smartcard_trace_connect_a_call(wLog* log,
const ConnectA_Call* call)
1384 if (!WLog_IsLevelActive(log, g_LogLevel))
1387 WLog_Print(log, g_LogLevel,
"ConnectA_Call {");
1388 smartcard_log_context(log, &call->Common.handles.hContext);
1390 WLog_Print(log, g_LogLevel,
1391 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1392 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1393 call->szReader, SCardGetShareModeString(call->Common.dwShareMode),
1394 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1395 call->Common.dwPreferredProtocols);
1396 WLog_Print(log, g_LogLevel,
"}");
1399static void smartcard_trace_connect_w_call(wLog* log,
const ConnectW_Call* call)
1402 char szReaderA[1024] = { 0 };
1404 if (!WLog_IsLevelActive(log, g_LogLevel))
1408 (void)ConvertWCharToUtf8(call->szReader, szReaderA, ARRAYSIZE(szReaderA));
1409 WLog_Print(log, g_LogLevel,
"ConnectW_Call {");
1410 smartcard_log_context(log, &call->Common.handles.hContext);
1412 WLog_Print(log, g_LogLevel,
1413 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1414 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1415 szReaderA, SCardGetShareModeString(call->Common.dwShareMode),
1416 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1417 call->Common.dwPreferredProtocols);
1418 WLog_Print(log, g_LogLevel,
"}");
1421static void smartcard_trace_hcard_and_disposition_call(wLog* log,
1427 if (!WLog_IsLevelActive(log, g_LogLevel))
1430 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
1431 smartcard_log_context(log, &call->handles.hContext);
1432 smartcard_log_redir_handle(log, &call->handles.hCard);
1434 WLog_Print(log, g_LogLevel,
"dwDisposition: %s (0x%08" PRIX32
")",
1435 SCardGetDispositionString(call->dwDisposition), call->dwDisposition);
1436 WLog_Print(log, g_LogLevel,
"}");
1443 if (!WLog_IsLevelActive(log, g_LogLevel))
1446 WLog_Print(log, g_LogLevel,
"EstablishContext_Call {");
1447 WLog_Print(log, g_LogLevel,
"dwScope: %s (0x%08" PRIX32
")", SCardGetScopeString(call->dwScope),
1449 WLog_Print(log, g_LogLevel,
"}");
1456 if (!WLog_IsLevelActive(log, g_LogLevel))
1459 WLog_Print(log, g_LogLevel,
"EstablishContext_Return {");
1460 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1461 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
1462 smartcard_log_context(log, &ret->hContext);
1464 WLog_Print(log, g_LogLevel,
"}");
1467void smartcard_trace_long_return(
const Long_Return* ret,
const char* name)
1469 wLog* log = scard_log();
1470 smartcard_trace_long_return_int(log, ret, name);
1473void smartcard_trace_long_return_int(wLog* log,
const Long_Return* ret,
const char* name)
1477 if (!WLog_IsLevelActive(log, g_LogLevel))
1480 WLog_Print(log, g_LogLevel,
"%s_Return {", name);
1481 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1482 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
1483 WLog_Print(log, g_LogLevel,
"}");
1486static void smartcard_trace_connect_return(wLog* log,
const Connect_Return* ret)
1490 if (!WLog_IsLevelActive(log, g_LogLevel))
1493 WLog_Print(log, g_LogLevel,
"Connect_Return {");
1494 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1495 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
1496 smartcard_log_context(log, &ret->hContext);
1497 smartcard_log_redir_handle(log, &ret->hCard);
1499 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1500 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1501 WLog_Print(log, g_LogLevel,
"}");
1504static void smartcard_trace_reconnect_call(wLog* log,
const Reconnect_Call* call)
1508 if (!WLog_IsLevelActive(log, g_LogLevel))
1511 WLog_Print(log, g_LogLevel,
"Reconnect_Call {");
1512 smartcard_log_context(log, &call->handles.hContext);
1513 smartcard_log_redir_handle(log, &call->handles.hCard);
1515 WLog_Print(log, g_LogLevel,
1516 "dwShareMode: %s (0x%08" PRIX32
") dwPreferredProtocols: %s (0x%08" PRIX32
1517 ") dwInitialization: %s (0x%08" PRIX32
")",
1518 SCardGetShareModeString(call->dwShareMode), call->dwShareMode,
1519 SCardGetProtocolString(call->dwPreferredProtocols), call->dwPreferredProtocols,
1520 SCardGetDispositionString(call->dwInitialization), call->dwInitialization);
1521 WLog_Print(log, g_LogLevel,
"}");
1528 if (!WLog_IsLevelActive(log, g_LogLevel))
1531 WLog_Print(log, g_LogLevel,
"GetDeviceTypeId_Return {");
1532 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1533 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
1534 WLog_Print(log, g_LogLevel,
" dwDeviceId=%08" PRIx32, ret->dwDeviceId);
1536 WLog_Print(log, g_LogLevel,
"}");
1539static LONG smartcard_unpack_common_context_and_string_a(wLog* log,
wStream* s,
1541 CHAR** pszReaderName)
1544 UINT32 pbContextNdrPtr = 0;
1545 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1546 if (status != SCARD_S_SUCCESS)
1549 if (!smartcard_ndr_pointer_read(log, s, &index, NULL))
1550 return ERROR_INVALID_DATA;
1552 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1553 if (status != SCARD_S_SUCCESS)
1556 status = smartcard_ndr_read_a(log, s, pszReaderName, NDR_PTR_FULL);
1557 if (status != SCARD_S_SUCCESS)
1560 smartcard_trace_context_and_string_call_a(log, __func__, phContext, *pszReaderName);
1561 return SCARD_S_SUCCESS;
1564static LONG smartcard_unpack_common_context_and_string_w(wLog* log,
wStream* s,
1566 WCHAR** pszReaderName)
1569 UINT32 pbContextNdrPtr = 0;
1571 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1572 if (status != SCARD_S_SUCCESS)
1575 if (!smartcard_ndr_pointer_read(log, s, &index, NULL))
1576 return ERROR_INVALID_DATA;
1578 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1579 if (status != SCARD_S_SUCCESS)
1582 status = smartcard_ndr_read_w(log, s, pszReaderName, NDR_PTR_FULL);
1583 if (status != SCARD_S_SUCCESS)
1586 smartcard_trace_context_and_string_call_w(log, __func__, phContext, *pszReaderName);
1587 return SCARD_S_SUCCESS;
1590LONG smartcard_unpack_common_type_header(
wStream* s)
1592 wLog* log = scard_log();
1595 UINT8 endianness = 0;
1596 UINT16 commonHeaderLength = 0;
1598 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1599 return STATUS_BUFFER_TOO_SMALL;
1602 Stream_Read_UINT8(s, version);
1603 Stream_Read_UINT8(s, endianness);
1604 Stream_Read_UINT16(s, commonHeaderLength);
1605 Stream_Read_UINT32(s, filler);
1609 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Version %" PRIu8
"", version);
1610 return STATUS_INVALID_PARAMETER;
1613 if (endianness != 0x10)
1615 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Endianness %" PRIu8
"",
1617 return STATUS_INVALID_PARAMETER;
1620 if (commonHeaderLength != 8)
1622 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader CommonHeaderLength %" PRIu16
"",
1623 commonHeaderLength);
1624 return STATUS_INVALID_PARAMETER;
1627 if (filler != 0xCCCCCCCC)
1629 WLog_Print(log, WLOG_WARN,
"Unexpected CommonTypeHeader Filler 0x%08" PRIX32
"", filler);
1630 return STATUS_INVALID_PARAMETER;
1633 return SCARD_S_SUCCESS;
1636void smartcard_pack_common_type_header(
wStream* s)
1638 Stream_Write_UINT8(s, 1);
1639 Stream_Write_UINT8(s, 0x10);
1640 Stream_Write_UINT16(s, 8);
1641 Stream_Write_UINT32(s, 0xCCCCCCCC);
1644LONG smartcard_unpack_private_type_header(
wStream* s)
1646 wLog* log = scard_log();
1648 UINT32 objectBufferLength = 0;
1650 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1651 return STATUS_BUFFER_TOO_SMALL;
1653 Stream_Read_UINT32(s, objectBufferLength);
1654 Stream_Read_UINT32(s, filler);
1656 if (filler != 0x00000000)
1658 WLog_Print(log, WLOG_WARN,
"Unexpected PrivateTypeHeader Filler 0x%08" PRIX32
"", filler);
1659 return STATUS_INVALID_PARAMETER;
1662 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, objectBufferLength))
1663 return STATUS_INVALID_PARAMETER;
1665 return SCARD_S_SUCCESS;
1668void smartcard_pack_private_type_header(
wStream* s, UINT32 objectBufferLength)
1670 Stream_Write_UINT32(s, objectBufferLength);
1671 Stream_Write_UINT32(s, 0x00000000);
1674LONG smartcard_unpack_read_size_align(
wStream* s,
size_t size, UINT32 alignment)
1679 size = (size + alignment - 1) & ~(alignment - 1);
1683 Stream_Seek(s, pad);
1688LONG smartcard_pack_write_size_align(
wStream* s,
size_t size, UINT32 alignment)
1693 size = (size + alignment - 1) & ~(alignment - 1);
1698 if (!Stream_EnsureRemainingCapacity(s, pad))
1700 wLog* log = scard_log();
1701 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
1702 return SCARD_F_INTERNAL_ERROR;
1705 Stream_Zero(s, pad);
1708 return SCARD_S_SUCCESS;
1713 SCARDCONTEXT hContext = { 0 };
1715 WINPR_ASSERT(context);
1716 if ((context->cbContext !=
sizeof(ULONG_PTR)) && (context->cbContext != 0))
1718 wLog* log = scard_log();
1719 WLog_Print(log, WLOG_WARN,
1720 "REDIR_SCARDCONTEXT does not match native size: Actual: %" PRIu32
1721 ", Expected: %" PRIuz
"",
1722 context->cbContext,
sizeof(ULONG_PTR));
1726 if (context->cbContext)
1727 CopyMemory(&hContext, &(context->pbContext), context->cbContext);
1732void smartcard_scard_context_native_to_redir(
REDIR_SCARDCONTEXT* context, SCARDCONTEXT hContext)
1734 WINPR_ASSERT(context);
1736 context->cbContext =
sizeof(ULONG_PTR);
1737 CopyMemory(&(context->pbContext), &hContext, context->cbContext);
1742 SCARDHANDLE hCard = 0;
1744 WINPR_ASSERT(handle);
1745 if (handle->cbHandle == 0)
1748 if (handle->cbHandle !=
sizeof(ULONG_PTR))
1750 wLog* log = scard_log();
1751 WLog_Print(log, WLOG_WARN,
1752 "REDIR_SCARDHANDLE does not match native size: Actual: %" PRIu32
1753 ", Expected: %" PRIuz
"",
1754 handle->cbHandle,
sizeof(ULONG_PTR));
1758 if (handle->cbHandle)
1759 CopyMemory(&hCard, &(handle->pbHandle), handle->cbHandle);
1764void smartcard_scard_handle_native_to_redir(
REDIR_SCARDHANDLE* handle, SCARDHANDLE hCard)
1766 WINPR_ASSERT(handle);
1768 handle->cbHandle =
sizeof(ULONG_PTR);
1769 CopyMemory(&(handle->pbHandle), &hCard, handle->cbHandle);
1772#define smartcard_context_supported(log, size) \
1773 smartcard_context_supported_((log), (size), __FILE__, __func__, __LINE__)
1774static LONG smartcard_context_supported_(wLog* log, uint32_t size,
const char* file,
1775 const char* fkt,
size_t line)
1782 return SCARD_S_SUCCESS;
1785 const uint32_t level = WLOG_WARN;
1786 if (WLog_IsLevelActive(log, level))
1788 WLog_PrintMessage(log, WLOG_MESSAGE_TEXT, level, line, file, fkt,
1789 "REDIR_SCARDCONTEXT length is not 0, 4 or 8: %" PRIu32
"", size);
1791 return STATUS_INVALID_PARAMETER;
1797 UINT32* index, UINT32* ppbContextNdrPtr,
1798 const char* file,
const char* function,
size_t line)
1800 UINT32 pbContextNdrPtr = 0;
1803 WINPR_ASSERT(context);
1807 if (!Stream_CheckAndLogRequiredLengthWLogEx(log, WLOG_WARN, s, 4, 1,
"%s(%s:%" PRIuz
")", file,
1809 return STATUS_BUFFER_TOO_SMALL;
1811 const LONG status = smartcard_context_supported_(log, context->cbContext, file, function, line);
1812 if (status != SCARD_S_SUCCESS)
1815 Stream_Read_UINT32(s, context->cbContext);
1817 if (!smartcard_ndr_pointer_read_(log, s, index, &pbContextNdrPtr, file, function, line))
1818 return ERROR_INVALID_DATA;
1820 if (((context->cbContext == 0) && pbContextNdrPtr) ||
1821 ((context->cbContext != 0) && !pbContextNdrPtr))
1823 WLog_Print(log, WLOG_WARN,
1824 "REDIR_SCARDCONTEXT cbContext (%" PRIu32
") pbContextNdrPtr (%" PRIu32
1826 context->cbContext, pbContextNdrPtr);
1827 return STATUS_INVALID_PARAMETER;
1830 if (!Stream_CheckAndLogRequiredLengthWLogEx(log, WLOG_WARN, s, context->cbContext, 1,
1831 "%s(%s:%" PRIuz
")", file, function, line))
1832 return STATUS_INVALID_PARAMETER;
1834 *ppbContextNdrPtr = pbContextNdrPtr;
1835 return SCARD_S_SUCCESS;
1838LONG smartcard_pack_redir_scard_context(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1841 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
1843 WINPR_ASSERT(context);
1844 if (context->cbContext != 0)
1846 Stream_Write_UINT32(s, context->cbContext);
1847 Stream_Write_UINT32(s, pbContextNdrPtr);
1848 *index = *index + 1;
1853 return SCARD_S_SUCCESS;
1856LONG smartcard_unpack_redir_scard_context_ref(wLog* log,
wStream* s,
1857 WINPR_ATTR_UNUSED UINT32 pbContextNdrPtr,
1862 WINPR_ASSERT(context);
1863 if (context->cbContext == 0)
1864 return SCARD_S_SUCCESS;
1866 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1867 return STATUS_BUFFER_TOO_SMALL;
1869 Stream_Read_UINT32(s, length);
1871 if (length != context->cbContext)
1873 WLog_Print(log, WLOG_WARN,
1874 "REDIR_SCARDCONTEXT length (%" PRIu32
") cbContext (%" PRIu32
") mismatch",
1875 length, context->cbContext);
1876 return STATUS_INVALID_PARAMETER;
1879 const LONG status = smartcard_context_supported(log, context->cbContext);
1880 if (status != SCARD_S_SUCCESS)
1883 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, context->cbContext))
1884 return STATUS_BUFFER_TOO_SMALL;
1886 if (context->cbContext)
1887 Stream_Read(s, &(context->pbContext), context->cbContext);
1889 ZeroMemory(&(context->pbContext),
sizeof(context->pbContext));
1891 return SCARD_S_SUCCESS;
1894LONG smartcard_pack_redir_scard_context_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1897 WINPR_ASSERT(context);
1898 Stream_Write_UINT32(s, context->cbContext);
1900 if (context->cbContext)
1902 Stream_Write(s, &(context->pbContext), context->cbContext);
1905 return SCARD_S_SUCCESS;
1909 UINT32* index,
const char* file,
const char* function,
1912 WINPR_ASSERT(handle);
1915 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1916 return STATUS_BUFFER_TOO_SMALL;
1918 Stream_Read_UINT32(s, handle->cbHandle);
1920 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, handle->cbHandle))
1921 return STATUS_BUFFER_TOO_SMALL;
1923 if (!smartcard_ndr_pointer_read_(log, s, index, NULL, file, function, line))
1924 return ERROR_INVALID_DATA;
1926 return SCARD_S_SUCCESS;
1929LONG smartcard_pack_redir_scard_handle(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1932 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
1934 WINPR_ASSERT(handle);
1935 if (handle->cbHandle != 0)
1937 Stream_Write_UINT32(s, handle->cbHandle);
1938 Stream_Write_UINT32(s, pbContextNdrPtr);
1939 *index = *index + 1;
1943 return SCARD_S_SUCCESS;
1950 WINPR_ASSERT(handle);
1951 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1952 return STATUS_BUFFER_TOO_SMALL;
1954 Stream_Read_UINT32(s, length);
1956 if (length != handle->cbHandle)
1958 WLog_Print(log, WLOG_WARN,
1959 "REDIR_SCARDHANDLE length (%" PRIu32
") cbHandle (%" PRIu32
") mismatch", length,
1961 return STATUS_INVALID_PARAMETER;
1964 if ((handle->cbHandle != 4) && (handle->cbHandle != 8))
1966 WLog_Print(log, WLOG_WARN,
"REDIR_SCARDHANDLE length is not 4 or 8: %" PRIu32
"",
1968 return STATUS_INVALID_PARAMETER;
1971 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, handle->cbHandle))
1972 return STATUS_BUFFER_TOO_SMALL;
1974 if (handle->cbHandle)
1975 Stream_Read(s, &(handle->pbHandle), handle->cbHandle);
1977 return SCARD_S_SUCCESS;
1980LONG smartcard_pack_redir_scard_handle_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1983 WINPR_ASSERT(handle);
1984 Stream_Write_UINT32(s, handle->cbHandle);
1986 if (handle->cbHandle)
1987 Stream_Write(s, &(handle->pbHandle), handle->cbHandle);
1989 return SCARD_S_SUCCESS;
1995 wLog* log = scard_log();
1997 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1998 return STATUS_BUFFER_TOO_SMALL;
2000 Stream_Read_UINT32(s, call->dwScope);
2001 smartcard_trace_establish_context_call(log, call);
2002 return SCARD_S_SUCCESS;
2008 wLog* log = scard_log();
2012 smartcard_trace_establish_context_return(log, ret);
2013 if (ret->ReturnCode != SCARD_S_SUCCESS)
2014 return ret->ReturnCode;
2016 status = smartcard_pack_redir_scard_context(log, s, &(ret->hContext), &index);
2017 if (status != SCARD_S_SUCCESS)
2020 return smartcard_pack_redir_scard_context_ref(log, s, &(ret->hContext));
2026 UINT32 pbContextNdrPtr = 0;
2027 wLog* log = scard_log();
2030 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2032 if (status != SCARD_S_SUCCESS)
2035 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2036 &(call->handles.hContext));
2037 if (status != SCARD_S_SUCCESS)
2038 WLog_Print(log, WLOG_ERROR,
2039 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2042 smartcard_trace_context_call(log, call, name);
2049 UINT32 pbContextNdrPtr = 0;
2050 wLog* log = scard_log();
2053 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2056 if (status != SCARD_S_SUCCESS)
2059 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2060 return STATUS_BUFFER_TOO_SMALL;
2062 Stream_Read_INT32(s, call->fmszGroupsIsNULL);
2063 Stream_Read_UINT32(s, call->cchGroups);
2064 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2065 &(call->handles.hContext));
2067 if (status != SCARD_S_SUCCESS)
2070 smartcard_trace_list_reader_groups_call(log, call, unicode);
2071 return SCARD_S_SUCCESS;
2078 wLog* log = scard_log();
2080 DWORD cBytes = ret->cBytes;
2083 smartcard_trace_list_reader_groups_return(log, ret, unicode);
2084 if (ret->ReturnCode != SCARD_S_SUCCESS)
2086 if (cBytes == SCARD_AUTOALLOCATE)
2089 if (!Stream_EnsureRemainingCapacity(s, 4))
2090 return SCARD_E_NO_MEMORY;
2092 Stream_Write_UINT32(s, cBytes);
2093 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
2094 return SCARD_E_NO_MEMORY;
2096 status = smartcard_ndr_write(s, ret->msz, cBytes, 1, NDR_PTR_SIMPLE);
2097 if (status != SCARD_S_SUCCESS)
2099 return ret->ReturnCode;
2105 UINT32 mszGroupsNdrPtr = 0;
2106 UINT32 pbContextNdrPtr = 0;
2107 wLog* log = scard_log();
2110 call->mszGroups = NULL;
2112 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2114 if (status != SCARD_S_SUCCESS)
2117 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2118 return STATUS_BUFFER_TOO_SMALL;
2120 Stream_Read_UINT32(s, call->cBytes);
2121 if (!smartcard_ndr_pointer_read(log, s, &index, &mszGroupsNdrPtr))
2122 return ERROR_INVALID_DATA;
2124 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2125 return STATUS_BUFFER_TOO_SMALL;
2126 Stream_Read_INT32(s, call->fmszReadersIsNULL);
2127 Stream_Read_UINT32(s, call->cchReaders);
2129 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2130 &(call->handles.hContext));
2131 if (status != SCARD_S_SUCCESS)
2134 if (mszGroupsNdrPtr)
2136 status = smartcard_ndr_read(log, s, &call->mszGroups, call->cBytes, 1, NDR_PTR_SIMPLE);
2137 if (status != SCARD_S_SUCCESS)
2141 smartcard_trace_list_readers_call(log, call, unicode);
2142 return SCARD_S_SUCCESS;
2148 wLog* log = scard_log();
2151 UINT32 size = ret->cBytes;
2153 smartcard_trace_list_readers_return(log, ret, unicode);
2154 if (ret->ReturnCode != SCARD_S_SUCCESS)
2157 if (!Stream_EnsureRemainingCapacity(s, 4))
2159 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
2160 return SCARD_F_INTERNAL_ERROR;
2163 Stream_Write_UINT32(s, size);
2164 if (!smartcard_ndr_pointer_write(s, &index, size))
2165 return SCARD_E_NO_MEMORY;
2167 status = smartcard_ndr_write(s, ret->msz, size, 1, NDR_PTR_SIMPLE);
2168 if (status != SCARD_S_SUCCESS)
2170 return ret->ReturnCode;
2174 UINT32* index, UINT32* ppbContextNdrPtr)
2176 WINPR_ASSERT(common);
2177 LONG status = smartcard_unpack_redir_scard_context(log, s, &(common->handles.hContext), index,
2179 if (status != SCARD_S_SUCCESS)
2182 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2183 return STATUS_BUFFER_TOO_SMALL;
2185 Stream_Read_UINT32(s, common->dwShareMode);
2186 Stream_Read_UINT32(s, common->dwPreferredProtocols);
2187 return SCARD_S_SUCCESS;
2194 UINT32 pbContextNdrPtr = 0;
2197 wLog* log = scard_log();
2199 call->szReader = NULL;
2201 if (!smartcard_ndr_pointer_read(log, s, &index, NULL))
2202 return ERROR_INVALID_DATA;
2204 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2205 if (status != SCARD_S_SUCCESS)
2207 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2212 status = smartcard_ndr_read_a(log, s, &call->szReader, NDR_PTR_FULL);
2213 if (status != SCARD_S_SUCCESS)
2216 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2217 &(call->Common.handles.hContext));
2218 if (status != SCARD_S_SUCCESS)
2219 WLog_Print(log, WLOG_ERROR,
2220 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2223 smartcard_trace_connect_a_call(log, call);
2231 UINT32 pbContextNdrPtr = 0;
2234 wLog* log = scard_log();
2235 call->szReader = NULL;
2237 if (!smartcard_ndr_pointer_read(log, s, &index, NULL))
2238 return ERROR_INVALID_DATA;
2240 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2241 if (status != SCARD_S_SUCCESS)
2243 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2248 status = smartcard_ndr_read_w(log, s, &call->szReader, NDR_PTR_FULL);
2249 if (status != SCARD_S_SUCCESS)
2252 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2253 &(call->Common.handles.hContext));
2254 if (status != SCARD_S_SUCCESS)
2255 WLog_Print(log, WLOG_ERROR,
2256 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2259 smartcard_trace_connect_w_call(log, call);
2269 wLog* log = scard_log();
2270 smartcard_trace_connect_return(log, ret);
2272 status = smartcard_pack_redir_scard_context(log, s, &ret->hContext, &index);
2273 if (status != SCARD_S_SUCCESS)
2276 status = smartcard_pack_redir_scard_handle(log, s, &ret->hCard, &index);
2277 if (status != SCARD_S_SUCCESS)
2280 if (!Stream_EnsureRemainingCapacity(s, 4))
2281 return SCARD_E_NO_MEMORY;
2283 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2284 status = smartcard_pack_redir_scard_context_ref(log, s, &ret->hContext);
2285 if (status != SCARD_S_SUCCESS)
2287 return smartcard_pack_redir_scard_handle_ref(log, s, &(ret->hCard));
2293 UINT32 pbContextNdrPtr = 0;
2296 wLog* log = scard_log();
2297 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2299 if (status != SCARD_S_SUCCESS)
2302 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2303 if (status != SCARD_S_SUCCESS)
2306 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2307 return STATUS_BUFFER_TOO_SMALL;
2309 Stream_Read_UINT32(s, call->dwShareMode);
2310 Stream_Read_UINT32(s, call->dwPreferredProtocols);
2311 Stream_Read_UINT32(s, call->dwInitialization);
2313 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2314 &(call->handles.hContext));
2315 if (status != SCARD_S_SUCCESS)
2317 WLog_Print(log, WLOG_ERROR,
2318 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2323 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2324 if (status != SCARD_S_SUCCESS)
2325 WLog_Print(log, WLOG_ERROR,
2326 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
2328 smartcard_trace_reconnect_call(log, call);
2335 wLog* log = scard_log();
2336 smartcard_trace_reconnect_return(log, ret);
2338 if (!Stream_EnsureRemainingCapacity(s, 4))
2339 return SCARD_E_NO_MEMORY;
2340 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2341 return ret->ReturnCode;
2348 UINT32 pbContextNdrPtr = 0;
2351 wLog* log = scard_log();
2353 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2355 if (status != SCARD_S_SUCCESS)
2358 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2359 if (status != SCARD_S_SUCCESS)
2362 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2363 return STATUS_BUFFER_TOO_SMALL;
2365 Stream_Read_UINT32(s, call->dwDisposition);
2367 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2368 &(call->handles.hContext));
2369 if (status != SCARD_S_SUCCESS)
2372 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2373 if (status != SCARD_S_SUCCESS)
2376 smartcard_trace_hcard_and_disposition_call(log, call, name);
2384 if (!WLog_IsLevelActive(log, g_LogLevel))
2387 WLog_Print(log, g_LogLevel,
"GetStatusChangeA_Call {");
2388 smartcard_log_context(log, &call->handles.hContext);
2390 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
2393 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
2395 WLog_Print(log, g_LogLevel,
"}");
2399 UINT32 cReaders, UINT32* ptrIndex)
2401 LONG status = SCARD_E_NO_MEMORY;
2403 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2404 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2407 const UINT32 len = Stream_Get_UINT32(s);
2408 if (len != cReaders)
2410 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEA");
2416 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2417 if (!rgReaderStates || !states)
2419 status = ERROR_INVALID_DATA;
2421 for (UINT32 index = 0; index < cReaders; index++)
2423 UINT32 ptr = UINT32_MAX;
2426 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2429 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2435 states[index] = ptr != 0;
2436 Stream_Read_UINT32(s, readerState->dwCurrentState);
2437 Stream_Read_UINT32(s, readerState->dwEventState);
2438 Stream_Read_UINT32(s, readerState->cbAtr);
2439 Stream_Read(s, readerState->rgbAtr, 36);
2442 for (UINT32 index = 0; index < cReaders; index++)
2449 status = smartcard_ndr_read_a(log, s, &readerState->szReader, NDR_PTR_FULL);
2450 if (status != SCARD_S_SUCCESS)
2454 *ppcReaders = rgReaderStates;
2456 return SCARD_S_SUCCESS;
2460 for (UINT32 index = 0; index < cReaders; index++)
2463 free(readerState->szReader);
2466 free(rgReaderStates);
2472 UINT32 cReaders, UINT32* ptrIndex)
2474 LONG status = SCARD_E_NO_MEMORY;
2476 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2477 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2480 const UINT32 len = Stream_Get_UINT32(s);
2481 if (len != cReaders)
2483 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEW");
2489 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2491 if (!rgReaderStates || !states)
2494 status = ERROR_INVALID_DATA;
2495 for (UINT32 index = 0; index < cReaders; index++)
2497 UINT32 ptr = UINT32_MAX;
2500 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2503 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2509 states[index] = ptr != 0;
2510 Stream_Read_UINT32(s, readerState->dwCurrentState);
2511 Stream_Read_UINT32(s, readerState->dwEventState);
2512 Stream_Read_UINT32(s, readerState->cbAtr);
2513 Stream_Read(s, readerState->rgbAtr, 36);
2516 for (UINT32 index = 0; index < cReaders; index++)
2524 status = smartcard_ndr_read_w(log, s, &readerState->szReader, NDR_PTR_FULL);
2525 if (status != SCARD_S_SUCCESS)
2529 *ppcReaders = rgReaderStates;
2531 return SCARD_S_SUCCESS;
2535 for (UINT32 index = 0; index < cReaders; index++)
2538 free(readerState->szReader);
2541 free(rgReaderStates);
2554 UINT32 pbContextNdrPtr = 0;
2557 wLog* log = scard_log();
2559 call->rgReaderStates = NULL;
2561 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2563 if (status != SCARD_S_SUCCESS)
2566 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2567 return STATUS_BUFFER_TOO_SMALL;
2569 Stream_Read_UINT32(s, call->dwTimeOut);
2570 Stream_Read_UINT32(s, call->cReaders);
2571 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2572 return ERROR_INVALID_DATA;
2574 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2575 &(call->handles.hContext));
2576 if (status != SCARD_S_SUCCESS)
2582 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
2583 if (status != SCARD_S_SUCCESS)
2588 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2589 return SCARD_E_UNEXPECTED;
2592 smartcard_trace_get_status_change_a_call(log, call);
2593 return SCARD_S_SUCCESS;
2600 UINT32 pbContextNdrPtr = 0;
2603 wLog* log = scard_log();
2604 call->rgReaderStates = NULL;
2606 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2608 if (status != SCARD_S_SUCCESS)
2611 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2612 return STATUS_BUFFER_TOO_SMALL;
2614 Stream_Read_UINT32(s, call->dwTimeOut);
2615 Stream_Read_UINT32(s, call->cReaders);
2616 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2617 return ERROR_INVALID_DATA;
2619 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2620 &(call->handles.hContext));
2621 if (status != SCARD_S_SUCCESS)
2627 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
2628 if (status != SCARD_S_SUCCESS)
2633 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2634 return SCARD_E_UNEXPECTED;
2637 smartcard_trace_get_status_change_w_call(log, call);
2638 return SCARD_S_SUCCESS;
2645 wLog* log = scard_log();
2648 DWORD cReaders = ret->cReaders;
2651 smartcard_trace_get_status_change_return(log, ret, unicode);
2652 if (ret->ReturnCode != SCARD_S_SUCCESS)
2654 if (cReaders == SCARD_AUTOALLOCATE)
2657 if (!Stream_EnsureRemainingCapacity(s, 4))
2658 return SCARD_E_NO_MEMORY;
2660 Stream_Write_UINT32(s, cReaders);
2661 if (!smartcard_ndr_pointer_write(s, &index, cReaders))
2662 return SCARD_E_NO_MEMORY;
2663 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cReaders, NDR_PTR_SIMPLE);
2664 if (status != SCARD_S_SUCCESS)
2666 return ret->ReturnCode;
2672 UINT32 pbContextNdrPtr = 0;
2674 wLog* log = scard_log();
2677 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2679 if (status != SCARD_S_SUCCESS)
2682 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2683 if (status != SCARD_S_SUCCESS)
2686 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2687 return STATUS_BUFFER_TOO_SMALL;
2689 Stream_Read_INT32(s, call->fpbAtrIsNULL);
2690 Stream_Read_UINT32(s, call->cbAtrLen);
2692 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2693 &(call->handles.hContext));
2694 if (status != SCARD_S_SUCCESS)
2697 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2698 if (status != SCARD_S_SUCCESS)
2707 wLog* log = scard_log();
2709 DWORD cbAtrLen = ret->cbAtrLen;
2712 smartcard_trace_state_return(log, ret);
2713 if (ret->ReturnCode != SCARD_S_SUCCESS)
2715 if (cbAtrLen == SCARD_AUTOALLOCATE)
2718 Stream_Write_UINT32(s, ret->dwState);
2719 Stream_Write_UINT32(s, ret->dwProtocol);
2720 Stream_Write_UINT32(s, cbAtrLen);
2721 if (!smartcard_ndr_pointer_write(s, &index, cbAtrLen))
2722 return SCARD_E_NO_MEMORY;
2723 status = smartcard_ndr_write(s, ret->rgAtr, cbAtrLen, 1, NDR_PTR_SIMPLE);
2724 if (status != SCARD_S_SUCCESS)
2726 return ret->ReturnCode;
2732 UINT32 pbContextNdrPtr = 0;
2735 wLog* log = scard_log();
2737 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2739 if (status != SCARD_S_SUCCESS)
2742 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2743 if (status != SCARD_S_SUCCESS)
2746 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2747 return STATUS_BUFFER_TOO_SMALL;
2749 Stream_Read_INT32(s, call->fmszReaderNamesIsNULL);
2750 Stream_Read_UINT32(s, call->cchReaderLen);
2751 Stream_Read_UINT32(s, call->cbAtrLen);
2753 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2754 &(call->handles.hContext));
2755 if (status != SCARD_S_SUCCESS)
2758 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2759 if (status != SCARD_S_SUCCESS)
2762 smartcard_trace_status_call(log, call, unicode);
2769 wLog* log = scard_log();
2773 DWORD cBytes = ret->cBytes;
2775 smartcard_trace_status_return(log, ret, unicode);
2776 if (ret->ReturnCode != SCARD_S_SUCCESS)
2778 if (cBytes == SCARD_AUTOALLOCATE)
2781 if (!Stream_EnsureRemainingCapacity(s, 4))
2782 return SCARD_F_INTERNAL_ERROR;
2784 Stream_Write_UINT32(s, cBytes);
2785 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
2786 return SCARD_E_NO_MEMORY;
2788 if (!Stream_EnsureRemainingCapacity(s, 44))
2789 return SCARD_F_INTERNAL_ERROR;
2791 Stream_Write_UINT32(s, ret->dwState);
2792 Stream_Write_UINT32(s, ret->dwProtocol);
2793 Stream_Write(s, ret->pbAtr,
sizeof(ret->pbAtr));
2794 Stream_Write_UINT32(s, ret->cbAtrLen);
2795 status = smartcard_ndr_write(s, ret->mszReaderNames, cBytes, 1, NDR_PTR_SIMPLE);
2796 if (status != SCARD_S_SUCCESS)
2798 return ret->ReturnCode;
2804 wLog* log = scard_log();
2806 UINT32 pbContextNdrPtr = 0;
2808 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2810 if (status != SCARD_S_SUCCESS)
2813 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2814 if (status != SCARD_S_SUCCESS)
2817 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2818 return STATUS_BUFFER_TOO_SMALL;
2820 Stream_Read_UINT32(s, call->dwAttrId);
2821 Stream_Read_INT32(s, call->fpbAttrIsNULL);
2822 Stream_Read_UINT32(s, call->cbAttrLen);
2824 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2825 &(call->handles.hContext));
2826 if (status != SCARD_S_SUCCESS)
2829 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2830 if (status != SCARD_S_SUCCESS)
2833 smartcard_trace_get_attrib_call(log, call);
2838 DWORD cbAttrCallLen)
2841 wLog* log = scard_log();
2843 DWORD cbAttrLen = 0;
2845 smartcard_trace_get_attrib_return(log, ret, dwAttrId);
2847 if (!Stream_EnsureRemainingCapacity(s, 4))
2848 return SCARD_F_INTERNAL_ERROR;
2850 cbAttrLen = ret->cbAttrLen;
2851 if (ret->ReturnCode != SCARD_S_SUCCESS)
2853 if (cbAttrLen == SCARD_AUTOALLOCATE)
2858 if (cbAttrCallLen < cbAttrLen)
2859 cbAttrLen = cbAttrCallLen;
2861 Stream_Write_UINT32(s, cbAttrLen);
2862 if (!smartcard_ndr_pointer_write(s, &index, cbAttrLen))
2863 return SCARD_E_NO_MEMORY;
2865 status = smartcard_ndr_write(s, ret->pbAttr, cbAttrLen, 1, NDR_PTR_SIMPLE);
2866 if (status != SCARD_S_SUCCESS)
2868 return ret->ReturnCode;
2874 wLog* log = scard_log();
2877 UINT32 pvInBufferNdrPtr = 0;
2878 UINT32 pbContextNdrPtr = 0;
2880 call->pvInBuffer = NULL;
2882 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2884 if (status != SCARD_S_SUCCESS)
2887 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2888 if (status != SCARD_S_SUCCESS)
2891 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 20))
2892 return STATUS_BUFFER_TOO_SMALL;
2894 Stream_Read_UINT32(s, call->dwControlCode);
2895 Stream_Read_UINT32(s, call->cbInBufferSize);
2896 if (!smartcard_ndr_pointer_read(log, s, &index,
2898 return ERROR_INVALID_DATA;
2899 Stream_Read_INT32(s, call->fpvOutBufferIsNULL);
2900 Stream_Read_UINT32(s, call->cbOutBufferSize);
2902 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2903 &(call->handles.hContext));
2904 if (status != SCARD_S_SUCCESS)
2907 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2908 if (status != SCARD_S_SUCCESS)
2911 if (pvInBufferNdrPtr)
2914 smartcard_ndr_read(log, s, &call->pvInBuffer, call->cbInBufferSize, 1, NDR_PTR_SIMPLE);
2915 if (status != SCARD_S_SUCCESS)
2919 smartcard_trace_control_call(log, call);
2920 return SCARD_S_SUCCESS;
2926 wLog* log = scard_log();
2929 DWORD cbDataLen = ret->cbOutBufferSize;
2932 smartcard_trace_control_return(log, ret);
2933 if (ret->ReturnCode != SCARD_S_SUCCESS)
2935 if (cbDataLen == SCARD_AUTOALLOCATE)
2938 if (!Stream_EnsureRemainingCapacity(s, 4))
2939 return SCARD_F_INTERNAL_ERROR;
2941 Stream_Write_UINT32(s, cbDataLen);
2942 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
2943 return SCARD_E_NO_MEMORY;
2945 status = smartcard_ndr_write(s, ret->pvOutBuffer, cbDataLen, 1, NDR_PTR_SIMPLE);
2946 if (status != SCARD_S_SUCCESS)
2948 return ret->ReturnCode;
2954 BYTE* pbExtraBytes = NULL;
2955 UINT32 pbExtraBytesNdrPtr = 0;
2956 UINT32 pbSendBufferNdrPtr = 0;
2957 UINT32 pioRecvPciNdrPtr = 0;
2961 UINT32 pbContextNdrPtr = 0;
2964 wLog* log = scard_log();
2966 call->pioSendPci = NULL;
2967 call->pioRecvPci = NULL;
2968 call->pbSendBuffer = NULL;
2970 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2972 if (status != SCARD_S_SUCCESS)
2975 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2976 if (status != SCARD_S_SUCCESS)
2979 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 32))
2980 return STATUS_BUFFER_TOO_SMALL;
2982 Stream_Read_UINT32(s, ioSendPci.dwProtocol);
2983 Stream_Read_UINT32(s, ioSendPci.cbExtraBytes);
2984 if (!smartcard_ndr_pointer_read(log, s, &index,
2985 &pbExtraBytesNdrPtr))
2986 return ERROR_INVALID_DATA;
2988 Stream_Read_UINT32(s, call->cbSendLength);
2989 if (!smartcard_ndr_pointer_read(log, s, &index,
2990 &pbSendBufferNdrPtr))
2991 return ERROR_INVALID_DATA;
2993 if (!smartcard_ndr_pointer_read(log, s, &index,
2995 return ERROR_INVALID_DATA;
2997 Stream_Read_INT32(s, call->fpbRecvBufferIsNULL);
2998 Stream_Read_UINT32(s, call->cbRecvLength);
3000 if (ioSendPci.cbExtraBytes > 1024)
3002 WLog_Print(log, WLOG_WARN,
3003 "Transmit_Call ioSendPci.cbExtraBytes is out of bounds: %" PRIu32
" (max: 1024)",
3004 ioSendPci.cbExtraBytes);
3005 return STATUS_INVALID_PARAMETER;
3008 if (call->cbSendLength > 66560)
3010 WLog_Print(log, WLOG_WARN,
3011 "Transmit_Call cbSendLength is out of bounds: %" PRIu32
" (max: 66560)",
3012 ioSendPci.cbExtraBytes);
3013 return STATUS_INVALID_PARAMETER;
3016 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3017 &(call->handles.hContext));
3018 if (status != SCARD_S_SUCCESS)
3021 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3022 if (status != SCARD_S_SUCCESS)
3025 if (ioSendPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3029 "Transmit_Call ioSendPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3030 return STATUS_INVALID_PARAMETER;
3033 if (pbExtraBytesNdrPtr)
3036 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3037 return STATUS_BUFFER_TOO_SMALL;
3039 Stream_Read_UINT32(s, length);
3041 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioSendPci.cbExtraBytes))
3042 return STATUS_BUFFER_TOO_SMALL;
3044 ioSendPci.pbExtraBytes = Stream_Pointer(s);
3048 if (!call->pioSendPci)
3050 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3051 return STATUS_NO_MEMORY;
3054 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3055 call->pioSendPci->cbPciLength = (DWORD)(ioSendPci.cbExtraBytes +
sizeof(
SCARD_IO_REQUEST));
3057 Stream_Read(s, pbExtraBytes, ioSendPci.cbExtraBytes);
3058 smartcard_unpack_read_size_align(s, ioSendPci.cbExtraBytes, 4);
3064 if (!call->pioSendPci)
3066 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3067 return STATUS_NO_MEMORY;
3070 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3074 if (pbSendBufferNdrPtr)
3077 smartcard_ndr_read(log, s, &call->pbSendBuffer, call->cbSendLength, 1, NDR_PTR_SIMPLE);
3078 if (status != SCARD_S_SUCCESS)
3082 if (pioRecvPciNdrPtr)
3084 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3085 return STATUS_BUFFER_TOO_SMALL;
3087 Stream_Read_UINT32(s, ioRecvPci.dwProtocol);
3088 Stream_Read_UINT32(s, ioRecvPci.cbExtraBytes);
3089 if (!smartcard_ndr_pointer_read(log, s, &index,
3090 &pbExtraBytesNdrPtr))
3091 return ERROR_INVALID_DATA;
3093 if (ioRecvPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3097 "Transmit_Call ioRecvPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3098 return STATUS_INVALID_PARAMETER;
3101 if (pbExtraBytesNdrPtr)
3104 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3105 return STATUS_BUFFER_TOO_SMALL;
3107 Stream_Read_UINT32(s, length);
3109 if (ioRecvPci.cbExtraBytes > 1024)
3111 WLog_Print(log, WLOG_WARN,
3112 "Transmit_Call ioRecvPci.cbExtraBytes is out of bounds: %" PRIu32
3114 ioRecvPci.cbExtraBytes);
3115 return STATUS_INVALID_PARAMETER;
3118 if (length != ioRecvPci.cbExtraBytes)
3120 WLog_Print(log, WLOG_WARN,
3121 "Transmit_Call unexpected length: Actual: %" PRIu32
3122 ", Expected: %" PRIu32
" (ioRecvPci.cbExtraBytes)",
3123 length, ioRecvPci.cbExtraBytes);
3124 return STATUS_INVALID_PARAMETER;
3127 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioRecvPci.cbExtraBytes))
3128 return STATUS_BUFFER_TOO_SMALL;
3130 ioRecvPci.pbExtraBytes = Stream_Pointer(s);
3134 if (!call->pioRecvPci)
3136 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3137 return STATUS_NO_MEMORY;
3140 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3141 call->pioRecvPci->cbPciLength =
3144 Stream_Read(s, pbExtraBytes, ioRecvPci.cbExtraBytes);
3145 smartcard_unpack_read_size_align(s, ioRecvPci.cbExtraBytes, 4);
3151 if (!call->pioRecvPci)
3153 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3154 return STATUS_NO_MEMORY;
3157 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3162 smartcard_trace_transmit_call(log, call);
3163 return SCARD_S_SUCCESS;
3169 wLog* log = scard_log();
3174 UINT32 cbRecvLength = ret->cbRecvLength;
3175 UINT32 cbRecvPci = ret->pioRecvPci ? ret->pioRecvPci->cbPciLength : 0;
3177 smartcard_trace_transmit_return(log, ret);
3179 if (!ret->pbRecvBuffer)
3182 if (!smartcard_ndr_pointer_write(s, &index, cbRecvPci))
3183 return SCARD_E_NO_MEMORY;
3184 if (!Stream_EnsureRemainingCapacity(s, 4))
3185 return SCARD_E_NO_MEMORY;
3186 Stream_Write_UINT32(s, cbRecvLength);
3187 if (!smartcard_ndr_pointer_write(s, &index, cbRecvLength))
3188 return SCARD_E_NO_MEMORY;
3190 if (ret->pioRecvPci)
3192 UINT32 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
3195 if (!Stream_EnsureRemainingCapacity(s, cbExtraBytes + 16))
3197 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3198 return SCARD_F_INTERNAL_ERROR;
3201 Stream_Write_UINT32(s, ret->pioRecvPci->dwProtocol);
3202 Stream_Write_UINT32(s, cbExtraBytes);
3203 if (!smartcard_ndr_pointer_write(s, &index, cbExtraBytes))
3204 return SCARD_E_NO_MEMORY;
3205 error = smartcard_ndr_write(s, pbExtraBytes, cbExtraBytes, 1, NDR_PTR_SIMPLE);
3210 status = smartcard_ndr_write(s, ret->pbRecvBuffer, ret->cbRecvLength, 1, NDR_PTR_SIMPLE);
3211 if (status != SCARD_S_SUCCESS)
3213 return ret->ReturnCode;
3218 UINT32 rgReaderStatesNdrPtr = 0;
3219 UINT32 rgAtrMasksNdrPtr = 0;
3221 UINT32 pbContextNdrPtr = 0;
3224 wLog* log = scard_log();
3226 call->rgReaderStates = NULL;
3228 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3230 if (status != SCARD_S_SUCCESS)
3233 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3234 return STATUS_BUFFER_TOO_SMALL;
3236 Stream_Read_UINT32(s, call->cAtrs);
3237 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3238 return ERROR_INVALID_DATA;
3239 Stream_Read_UINT32(s, call->cReaders);
3240 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3241 return ERROR_INVALID_DATA;
3243 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3244 &(call->handles.hContext));
3245 if (status != SCARD_S_SUCCESS)
3248 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3250 WLog_Print(log, WLOG_WARN,
3251 "LocateCardsByATRA_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3252 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3253 rgAtrMasksNdrPtr, call->cAtrs);
3254 return STATUS_INVALID_PARAMETER;
3257 if (rgAtrMasksNdrPtr)
3259 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3260 if (status != SCARD_S_SUCCESS)
3264 if (rgReaderStatesNdrPtr)
3267 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
3268 if (status != SCARD_S_SUCCESS)
3272 smartcard_trace_locate_cards_by_atr_a_call(log, call);
3273 return SCARD_S_SUCCESS;
3278 UINT32 sz1NdrPtr = 0;
3279 UINT32 sz2NdrPtr = 0;
3281 UINT32 pbContextNdrPtr = 0;
3284 wLog* log = scard_log();
3286 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3288 if (status != SCARD_S_SUCCESS)
3291 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3292 return ERROR_INVALID_DATA;
3293 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3294 return ERROR_INVALID_DATA;
3297 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3298 if (status != SCARD_S_SUCCESS)
3303 status = smartcard_ndr_read_a(log, s, &call->sz1, NDR_PTR_FULL);
3304 if (status != SCARD_S_SUCCESS)
3309 status = smartcard_ndr_read_a(log, s, &call->sz2, NDR_PTR_FULL);
3310 if (status != SCARD_S_SUCCESS)
3313 smartcard_trace_context_and_two_strings_a_call(log, call);
3314 return SCARD_S_SUCCESS;
3319 UINT32 sz1NdrPtr = 0;
3320 UINT32 sz2NdrPtr = 0;
3322 UINT32 pbContextNdrPtr = 0;
3325 wLog* log = scard_log();
3327 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3329 if (status != SCARD_S_SUCCESS)
3332 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3333 return ERROR_INVALID_DATA;
3334 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3335 return ERROR_INVALID_DATA;
3338 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3339 if (status != SCARD_S_SUCCESS)
3344 status = smartcard_ndr_read_w(log, s, &call->sz1, NDR_PTR_FULL);
3345 if (status != SCARD_S_SUCCESS)
3350 status = smartcard_ndr_read_w(log, s, &call->sz2, NDR_PTR_FULL);
3351 if (status != SCARD_S_SUCCESS)
3354 smartcard_trace_context_and_two_strings_w_call(log, call);
3355 return SCARD_S_SUCCESS;
3360 UINT32 sz1NdrPtr = 0;
3361 UINT32 sz2NdrPtr = 0;
3363 UINT32 pbContextNdrPtr = 0;
3366 wLog* log = scard_log();
3368 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3370 if (status != SCARD_S_SUCCESS)
3373 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3374 return STATUS_BUFFER_TOO_SMALL;
3376 Stream_Read_UINT32(s, call->cBytes);
3377 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3378 return ERROR_INVALID_DATA;
3380 Stream_Read_UINT32(s, call->cReaders);
3381 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3382 return ERROR_INVALID_DATA;
3384 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3385 &(call->handles.hContext));
3386 if (status != SCARD_S_SUCCESS)
3391 status = smartcard_ndr_read_fixed_string_a(log, s, &call->mszCards, call->cBytes,
3393 if (status != SCARD_S_SUCCESS)
3399 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
3400 if (status != SCARD_S_SUCCESS)
3403 smartcard_trace_locate_cards_a_call(log, call);
3404 return SCARD_S_SUCCESS;
3409 UINT32 sz1NdrPtr = 0;
3410 UINT32 sz2NdrPtr = 0;
3412 UINT32 pbContextNdrPtr = 0;
3415 wLog* log = scard_log();
3417 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3419 if (status != SCARD_S_SUCCESS)
3422 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3423 return STATUS_BUFFER_TOO_SMALL;
3425 Stream_Read_UINT32(s, call->cBytes);
3426 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3427 return ERROR_INVALID_DATA;
3429 Stream_Read_UINT32(s, call->cReaders);
3430 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3431 return ERROR_INVALID_DATA;
3433 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3434 &(call->handles.hContext));
3435 if (status != SCARD_S_SUCCESS)
3440 status = smartcard_ndr_read_fixed_string_w(log, s, &call->mszCards, call->cBytes,
3442 if (status != SCARD_S_SUCCESS)
3448 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
3449 if (status != SCARD_S_SUCCESS)
3452 smartcard_trace_locate_cards_w_call(log, call);
3453 return SCARD_S_SUCCESS;
3460 UINT32 pbContextNdrPtr = 0;
3463 wLog* log = scard_log();
3465 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3467 if (status != SCARD_S_SUCCESS)
3469 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3470 if (status != SCARD_S_SUCCESS)
3473 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3474 return STATUS_BUFFER_TOO_SMALL;
3475 Stream_Read_UINT32(s, call->dwAttrId);
3476 Stream_Read_UINT32(s, call->cbAttrLen);
3478 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
3479 return ERROR_INVALID_DATA;
3481 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3482 &(call->handles.hContext));
3483 if (status != SCARD_S_SUCCESS)
3486 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3487 if (status != SCARD_S_SUCCESS)
3494 status = smartcard_ndr_read(log, s, &call->pbAttr, 0, 1, NDR_PTR_SIMPLE);
3495 if (status != SCARD_S_SUCCESS)
3498 smartcard_trace_set_attrib_call(log, call);
3499 return SCARD_S_SUCCESS;
3504 UINT32 rgReaderStatesNdrPtr = 0;
3505 UINT32 rgAtrMasksNdrPtr = 0;
3507 UINT32 pbContextNdrPtr = 0;
3510 wLog* log = scard_log();
3512 call->rgReaderStates = NULL;
3514 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3516 if (status != SCARD_S_SUCCESS)
3519 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3520 return STATUS_BUFFER_TOO_SMALL;
3522 Stream_Read_UINT32(s, call->cAtrs);
3523 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3524 return ERROR_INVALID_DATA;
3526 Stream_Read_UINT32(s, call->cReaders);
3527 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3528 return ERROR_INVALID_DATA;
3530 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3531 &(call->handles.hContext));
3532 if (status != SCARD_S_SUCCESS)
3535 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3537 WLog_Print(log, WLOG_WARN,
3538 "LocateCardsByATRW_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3539 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3540 rgAtrMasksNdrPtr, call->cAtrs);
3541 return STATUS_INVALID_PARAMETER;
3544 if (rgAtrMasksNdrPtr)
3546 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3547 if (status != SCARD_S_SUCCESS)
3551 if (rgReaderStatesNdrPtr)
3554 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
3555 if (status != SCARD_S_SUCCESS)
3559 smartcard_trace_locate_cards_by_atr_w_call(log, call);
3560 return SCARD_S_SUCCESS;
3565 UINT32 mszNdrPtr = 0;
3566 UINT32 contextNdrPtr = 0;
3568 UINT32 pbContextNdrPtr = 0;
3571 wLog* log = scard_log();
3573 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3574 return ERROR_INVALID_DATA;
3576 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3577 &index, &pbContextNdrPtr);
3578 if (status != SCARD_S_SUCCESS)
3581 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3582 return ERROR_INVALID_DATA;
3584 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3585 return STATUS_BUFFER_TOO_SMALL;
3586 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3587 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
3588 Stream_Read_UINT32(s, call->Common.cbDataLen);
3590 call->szLookupName = NULL;
3593 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
3594 if (status != SCARD_S_SUCCESS)
3598 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3599 &call->Common.handles.hContext);
3600 if (status != SCARD_S_SUCCESS)
3605 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3606 if (status != SCARD_S_SUCCESS)
3609 smartcard_trace_read_cache_a_call(log, call);
3610 return SCARD_S_SUCCESS;
3615 UINT32 mszNdrPtr = 0;
3616 UINT32 contextNdrPtr = 0;
3618 UINT32 pbContextNdrPtr = 0;
3621 wLog* log = scard_log();
3623 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3624 return ERROR_INVALID_DATA;
3626 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3627 &index, &pbContextNdrPtr);
3628 if (status != SCARD_S_SUCCESS)
3631 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3632 return ERROR_INVALID_DATA;
3634 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3635 return STATUS_BUFFER_TOO_SMALL;
3636 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3637 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
3638 Stream_Read_UINT32(s, call->Common.cbDataLen);
3640 call->szLookupName = NULL;
3643 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
3644 if (status != SCARD_S_SUCCESS)
3648 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3649 &call->Common.handles.hContext);
3650 if (status != SCARD_S_SUCCESS)
3655 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3656 if (status != SCARD_S_SUCCESS)
3659 smartcard_trace_read_cache_w_call(log, call);
3660 return SCARD_S_SUCCESS;
3665 UINT32 mszNdrPtr = 0;
3666 UINT32 contextNdrPtr = 0;
3667 UINT32 pbDataNdrPtr = 0;
3669 UINT32 pbContextNdrPtr = 0;
3672 wLog* log = scard_log();
3674 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3675 return ERROR_INVALID_DATA;
3677 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3678 &index, &pbContextNdrPtr);
3679 if (status != SCARD_S_SUCCESS)
3682 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3683 return ERROR_INVALID_DATA;
3685 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
3686 return STATUS_BUFFER_TOO_SMALL;
3688 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3689 Stream_Read_UINT32(s, call->Common.cbDataLen);
3691 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
3692 return ERROR_INVALID_DATA;
3694 call->szLookupName = NULL;
3697 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
3698 if (status != SCARD_S_SUCCESS)
3702 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3703 &call->Common.handles.hContext);
3704 if (status != SCARD_S_SUCCESS)
3707 call->Common.CardIdentifier = NULL;
3710 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3711 if (status != SCARD_S_SUCCESS)
3715 call->Common.pbData = NULL;
3718 status = smartcard_ndr_read(log, s, &call->Common.pbData, call->Common.cbDataLen, 1,
3720 if (status != SCARD_S_SUCCESS)
3723 smartcard_trace_write_cache_a_call(log, call);
3724 return SCARD_S_SUCCESS;
3729 UINT32 mszNdrPtr = 0;
3730 UINT32 contextNdrPtr = 0;
3731 UINT32 pbDataNdrPtr = 0;
3733 UINT32 pbContextNdrPtr = 0;
3736 wLog* log = scard_log();
3738 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3739 return ERROR_INVALID_DATA;
3741 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3742 &index, &pbContextNdrPtr);
3743 if (status != SCARD_S_SUCCESS)
3746 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3747 return ERROR_INVALID_DATA;
3749 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
3750 return STATUS_BUFFER_TOO_SMALL;
3751 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3752 Stream_Read_UINT32(s, call->Common.cbDataLen);
3754 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
3755 return ERROR_INVALID_DATA;
3757 call->szLookupName = NULL;
3760 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
3761 if (status != SCARD_S_SUCCESS)
3765 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3766 &call->Common.handles.hContext);
3767 if (status != SCARD_S_SUCCESS)
3770 call->Common.CardIdentifier = NULL;
3773 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3774 if (status != SCARD_S_SUCCESS)
3778 call->Common.pbData = NULL;
3781 status = smartcard_ndr_read(log, s, &call->Common.pbData, call->Common.cbDataLen, 1,
3783 if (status != SCARD_S_SUCCESS)
3786 smartcard_trace_write_cache_w_call(log, call);
3793 wLog* log = scard_log();
3796 UINT32 pbContextNdrPtr = 0;
3798 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3800 if (status != SCARD_S_SUCCESS)
3803 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3804 if (status != SCARD_S_SUCCESS)
3807 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3808 &(call->handles.hContext));
3809 if (status != SCARD_S_SUCCESS)
3811 WLog_Print(log, WLOG_ERROR,
3812 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
3817 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3818 if (status != SCARD_S_SUCCESS)
3819 WLog_Print(log, WLOG_ERROR,
3820 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
3822 smartcard_trace_get_transmit_count_call(log, call);
3829 wLog* log = scard_log();
3830 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
3831 &call->szReaderName);
3837 wLog* log = scard_log();
3838 return smartcard_unpack_common_context_and_string_a(log, s, &call->handles.hContext, &call->sz);
3844 wLog* log = scard_log();
3845 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext, &call->sz);
3851 wLog* log = scard_log();
3852 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
3853 &call->szReaderName);
3859 wLog* log = scard_log();
3860 smartcard_trace_device_type_id_return(log, ret);
3862 if (!Stream_EnsureRemainingCapacity(s, 4))
3864 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3865 return SCARD_F_INTERNAL_ERROR;
3868 Stream_Write_UINT32(s, ret->dwDeviceId);
3870 return ret->ReturnCode;
3876 wLog* log = scard_log();
3879 DWORD cbDataLen = ret->cReaders;
3882 smartcard_trace_locate_cards_return(log, ret);
3883 if (ret->ReturnCode != SCARD_S_SUCCESS)
3885 if (cbDataLen == SCARD_AUTOALLOCATE)
3888 if (!Stream_EnsureRemainingCapacity(s, 4))
3890 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3891 return SCARD_F_INTERNAL_ERROR;
3894 Stream_Write_UINT32(s, cbDataLen);
3895 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3896 return SCARD_E_NO_MEMORY;
3898 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cbDataLen, NDR_PTR_SIMPLE);
3899 if (status != SCARD_S_SUCCESS)
3901 return ret->ReturnCode;
3907 wLog* log = scard_log();
3911 DWORD cbDataLen = ret->cbDataLen;
3912 smartcard_trace_get_reader_icon_return(log, ret);
3913 if (ret->ReturnCode != SCARD_S_SUCCESS)
3915 if (cbDataLen == SCARD_AUTOALLOCATE)
3918 if (!Stream_EnsureRemainingCapacity(s, 4))
3920 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3921 return SCARD_F_INTERNAL_ERROR;
3924 Stream_Write_UINT32(s, cbDataLen);
3925 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3926 return SCARD_E_NO_MEMORY;
3928 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
3929 if (status != SCARD_S_SUCCESS)
3931 return ret->ReturnCode;
3937 wLog* log = scard_log();
3939 smartcard_trace_get_transmit_count_return(log, ret);
3941 if (!Stream_EnsureRemainingCapacity(s, 4))
3943 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3944 return SCARD_F_INTERNAL_ERROR;
3947 Stream_Write_UINT32(s, ret->cTransmitCount);
3949 return ret->ReturnCode;
3955 wLog* log = scard_log();
3959 DWORD cbDataLen = ret->cbDataLen;
3960 smartcard_trace_read_cache_return(log, ret);
3961 if (ret->ReturnCode != SCARD_S_SUCCESS)
3964 if (cbDataLen == SCARD_AUTOALLOCATE)
3967 if (!Stream_EnsureRemainingCapacity(s, 4))
3969 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3970 return SCARD_F_INTERNAL_ERROR;
3973 Stream_Write_UINT32(s, cbDataLen);
3974 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3975 return SCARD_E_NO_MEMORY;
3977 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
3978 if (status != SCARD_S_SUCCESS)
3980 return ret->ReturnCode;