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=%" PRIuz
152 ", offset=%" PRIuz
", remaining=%" PRIuz,
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=%" PRIuz
164 ", expected=%" PRIuz,
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 %" PRIuz
", got %" PRIuz, 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),
667 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
668 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
669 WLog_Print(log, g_LogLevel,
"}");
673static void smartcard_trace_list_readers_call(wLog* log,
const ListReaders_Call* call, BOOL unicode)
677 if (!WLog_IsLevelActive(log, g_LogLevel))
680 char* mszGroupsA = smartcard_convert_string_list(call->mszGroups, call->cBytes, unicode);
682 WLog_Print(log, g_LogLevel,
"ListReaders%s_Call {", unicode ?
"W" :
"A");
683 smartcard_log_context(log, &call->handles.hContext);
685 WLog_Print(log, g_LogLevel,
686 "cBytes: %" PRIu32
" mszGroups: %s fmszReadersIsNULL: %" PRId32
687 " cchReaders: 0x%08" PRIX32
"",
688 call->cBytes, mszGroupsA, call->fmszReadersIsNULL, call->cchReaders);
689 WLog_Print(log, g_LogLevel,
"}");
694static void smartcard_trace_locate_cards_by_atr_a_call(wLog* log,
699 if (!WLog_IsLevelActive(log, g_LogLevel))
702 WLog_Print(log, g_LogLevel,
"LocateCardsByATRA_Call {");
703 smartcard_log_context(log, &call->handles.hContext);
705 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
707 WLog_Print(log, g_LogLevel,
"}");
710static void smartcard_trace_locate_cards_a_call(wLog* log,
const LocateCardsA_Call* call)
712 char buffer[8192] = { 0 };
716 if (!WLog_IsLevelActive(log, g_LogLevel))
719 WLog_Print(log, g_LogLevel,
"LocateCardsA_Call {");
720 smartcard_log_context(log, &call->handles.hContext);
721 WLog_Print(log, g_LogLevel,
" cBytes=%" PRIu32, call->cBytes);
722 WLog_Print(log, g_LogLevel,
" mszCards=%s",
723 smartcard_msz_dump_a(call->mszCards, call->cBytes, buffer,
sizeof(buffer)));
724 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, call->cReaders);
725 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
727 WLog_Print(log, g_LogLevel,
"}");
730static void smartcard_trace_locate_cards_return(wLog* log,
const LocateCards_Return* ret)
734 if (!WLog_IsLevelActive(log, g_LogLevel))
737 WLog_Print(log, g_LogLevel,
"LocateCards_Return {");
738 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
739 SCardGetErrorString(ret->ReturnCode),
740 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
742 if (ret->ReturnCode == SCARD_S_SUCCESS)
744 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, ret->cReaders);
746 WLog_Print(log, g_LogLevel,
"}");
753 if (!WLog_IsLevelActive(log, g_LogLevel))
756 WLog_Print(log, g_LogLevel,
"GetReaderIcon_Return {");
757 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
758 SCardGetErrorString(ret->ReturnCode),
759 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
761 if (ret->ReturnCode == SCARD_S_SUCCESS)
763 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, ret->cbDataLen);
765 WLog_Print(log, g_LogLevel,
"}");
772 if (!WLog_IsLevelActive(log, g_LogLevel))
775 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Return {");
776 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
777 SCardGetErrorString(ret->ReturnCode),
778 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
780 WLog_Print(log, g_LogLevel,
" cTransmitCount=%" PRIu32, ret->cTransmitCount);
781 WLog_Print(log, g_LogLevel,
"}");
784static void smartcard_trace_read_cache_return(wLog* log,
const ReadCache_Return* ret)
788 if (!WLog_IsLevelActive(log, g_LogLevel))
791 WLog_Print(log, g_LogLevel,
"ReadCache_Return {");
792 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
793 SCardGetErrorString(ret->ReturnCode),
794 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
796 if (ret->ReturnCode == SCARD_S_SUCCESS)
798 char buffer[1024] = { 0 };
799 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, ret->cbDataLen);
800 WLog_Print(log, g_LogLevel,
" cbData: %s",
801 smartcard_array_dump(ret->pbData, ret->cbDataLen, buffer,
sizeof(buffer)));
803 WLog_Print(log, g_LogLevel,
"}");
806static void smartcard_trace_locate_cards_w_call(wLog* log,
const LocateCardsW_Call* call)
809 char buffer[8192] = { 0 };
811 if (!WLog_IsLevelActive(log, g_LogLevel))
814 WLog_Print(log, g_LogLevel,
"LocateCardsW_Call {");
815 smartcard_log_context(log, &call->handles.hContext);
816 WLog_Print(log, g_LogLevel,
" cBytes=%" PRIu32, call->cBytes);
817 WLog_Print(log, g_LogLevel,
" sz2=%s",
818 smartcard_msz_dump_w(call->mszCards, call->cBytes, buffer,
sizeof(buffer)));
819 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, call->cReaders);
820 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
821 WLog_Print(log, g_LogLevel,
"}");
824static void smartcard_trace_list_readers_return(wLog* log,
const ListReaders_Return* ret,
829 if (!WLog_IsLevelActive(log, g_LogLevel))
832 WLog_Print(log, g_LogLevel,
"ListReaders%s_Return {", unicode ?
"W" :
"A");
833 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
834 SCardGetErrorString(ret->ReturnCode),
835 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
837 if (ret->ReturnCode != SCARD_S_SUCCESS)
839 WLog_Print(log, g_LogLevel,
"}");
843 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
845 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
846 WLog_Print(log, g_LogLevel,
"}");
855 if (!WLog_IsLevelActive(log, g_LogLevel))
858 WLog_Print(log, g_LogLevel,
"GetStatusChange%s_Return {", unicode ?
"W" :
"A");
859 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
860 SCardGetErrorString(ret->ReturnCode),
861 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
862 WLog_Print(log, g_LogLevel,
" cReaders: %" PRIu32
"", ret->cReaders);
864 dump_reader_states_return(log, ret->rgReaderStates, ret->cReaders);
866 if (!ret->rgReaderStates && (ret->cReaders > 0))
868 WLog_Print(log, g_LogLevel,
" [INVALID STATE] rgReaderStates=NULL, cReaders=%" PRIu32,
871 else if (ret->ReturnCode != SCARD_S_SUCCESS)
873 WLog_Print(log, g_LogLevel,
" [INVALID RETURN] rgReaderStates, cReaders=%" PRIu32,
878 for (UINT32 index = 0; index < ret->cReaders; index++)
880 char buffer[1024] = { 0 };
882 char* szCurrentState = SCardGetReaderStateString(rgReaderState->dwCurrentState);
883 char* szEventState = SCardGetReaderStateString(rgReaderState->dwEventState);
884 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")",
885 index, szCurrentState, rgReaderState->dwCurrentState);
886 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")",
887 index, szEventState, rgReaderState->dwEventState);
888 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: cbAtr: %" PRIu32
" rgbAtr: %s", index,
889 rgReaderState->cbAtr,
890 smartcard_array_dump(rgReaderState->rgbAtr, rgReaderState->cbAtr, buffer,
892 free(szCurrentState);
897 WLog_Print(log, g_LogLevel,
"}");
900static void smartcard_trace_context_and_two_strings_a_call(wLog* log,
905 if (!WLog_IsLevelActive(log, g_LogLevel))
908 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
909 smartcard_log_context(log, &call->handles.hContext);
910 WLog_Print(log, g_LogLevel,
" sz1=%s", call->sz1);
911 WLog_Print(log, g_LogLevel,
" sz2=%s", call->sz2);
912 WLog_Print(log, g_LogLevel,
"}");
915static void smartcard_trace_context_and_two_strings_w_call(wLog* log,
919 char sz1[1024] = { 0 };
920 char sz2[1024] = { 0 };
922 if (!WLog_IsLevelActive(log, g_LogLevel))
925 (void)ConvertWCharToUtf8(call->sz1, sz1, ARRAYSIZE(sz1));
927 (void)ConvertWCharToUtf8(call->sz2, sz2, ARRAYSIZE(sz2));
929 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
930 smartcard_log_context(log, &call->handles.hContext);
931 WLog_Print(log, g_LogLevel,
" sz1=%s", sz1);
932 WLog_Print(log, g_LogLevel,
" sz2=%s", sz2);
933 WLog_Print(log, g_LogLevel,
"}");
940 if (!WLog_IsLevelActive(log, g_LogLevel))
943 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Call {");
944 smartcard_log_context(log, &call->handles.hContext);
945 smartcard_log_redir_handle(log, &call->handles.hCard);
947 WLog_Print(log, g_LogLevel,
"}");
950static void smartcard_trace_write_cache_a_call(wLog* log,
const WriteCacheA_Call* call)
953 char buffer[1024] = { 0 };
955 if (!WLog_IsLevelActive(log, g_LogLevel))
958 WLog_Print(log, g_LogLevel,
"WriteCacheA_Call {");
960 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
962 smartcard_log_context(log, &call->Common.handles.hContext);
964 log, g_LogLevel,
"..CardIdentifier=%s",
965 smartcard_array_dump(call->Common.CardIdentifier,
sizeof(
UUID), buffer,
sizeof(buffer)));
966 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
967 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
969 log, g_LogLevel,
" pbData=%s",
970 smartcard_array_dump(call->Common.pbData, call->Common.cbDataLen, buffer,
sizeof(buffer)));
971 WLog_Print(log, g_LogLevel,
"}");
974static void smartcard_trace_write_cache_w_call(wLog* log,
const WriteCacheW_Call* call)
977 char tmp[1024] = { 0 };
978 char buffer[1024] = { 0 };
980 if (!WLog_IsLevelActive(log, g_LogLevel))
983 WLog_Print(log, g_LogLevel,
"WriteCacheW_Call {");
985 if (call->szLookupName)
986 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
987 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
989 smartcard_log_context(log, &call->Common.handles.hContext);
991 log, g_LogLevel,
"..CardIdentifier=%s",
992 smartcard_array_dump(call->Common.CardIdentifier,
sizeof(
UUID), buffer,
sizeof(buffer)));
993 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
994 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
996 log, g_LogLevel,
" pbData=%s",
997 smartcard_array_dump(call->Common.pbData, call->Common.cbDataLen, buffer,
sizeof(buffer)));
998 WLog_Print(log, g_LogLevel,
"}");
1001static void smartcard_trace_read_cache_a_call(wLog* log,
const ReadCacheA_Call* call)
1004 char buffer[1024] = { 0 };
1006 if (!WLog_IsLevelActive(log, g_LogLevel))
1009 WLog_Print(log, g_LogLevel,
"ReadCacheA_Call {");
1011 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
1012 smartcard_log_context(log, &call->Common.handles.hContext);
1014 log, g_LogLevel,
"..CardIdentifier=%s",
1015 smartcard_array_dump(call->Common.CardIdentifier,
sizeof(
UUID), buffer,
sizeof(buffer)));
1016 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1017 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1018 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1020 WLog_Print(log, g_LogLevel,
"}");
1023static void smartcard_trace_read_cache_w_call(wLog* log,
const ReadCacheW_Call* call)
1026 char tmp[1024] = { 0 };
1027 char buffer[1024] = { 0 };
1029 if (!WLog_IsLevelActive(log, g_LogLevel))
1032 WLog_Print(log, g_LogLevel,
"ReadCacheW_Call {");
1033 if (call->szLookupName)
1034 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
1035 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
1037 smartcard_log_context(log, &call->Common.handles.hContext);
1039 log, g_LogLevel,
"..CardIdentifier=%s",
1040 smartcard_array_dump(call->Common.CardIdentifier,
sizeof(
UUID), buffer,
sizeof(buffer)));
1041 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1042 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1043 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1045 WLog_Print(log, g_LogLevel,
"}");
1048static void smartcard_trace_transmit_call(wLog* log,
const Transmit_Call* call)
1051 UINT32 cbExtraBytes = 0;
1052 BYTE* pbExtraBytes = NULL;
1054 if (!WLog_IsLevelActive(log, g_LogLevel))
1057 WLog_Print(log, g_LogLevel,
"Transmit_Call {");
1058 smartcard_log_context(log, &call->handles.hContext);
1059 smartcard_log_redir_handle(log, &call->handles.hCard);
1061 if (call->pioSendPci)
1063 cbExtraBytes = (UINT32)(call->pioSendPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1065 WLog_Print(log, g_LogLevel,
"pioSendPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1066 call->pioSendPci->dwProtocol, cbExtraBytes);
1070 char buffer[1024] = { 0 };
1071 WLog_Print(log, g_LogLevel,
"pbExtraBytes: %s",
1072 smartcard_array_dump(pbExtraBytes, cbExtraBytes, buffer,
sizeof(buffer)));
1077 WLog_Print(log, g_LogLevel,
"pioSendPci: null");
1080 WLog_Print(log, g_LogLevel,
"cbSendLength: %" PRIu32
"", call->cbSendLength);
1082 if (call->pbSendBuffer)
1084 char buffer[1024] = { 0 };
1086 log, g_LogLevel,
"pbSendBuffer: %s",
1087 smartcard_array_dump(call->pbSendBuffer, call->cbSendLength, buffer,
sizeof(buffer)));
1091 WLog_Print(log, g_LogLevel,
"pbSendBuffer: null");
1094 if (call->pioRecvPci)
1096 cbExtraBytes = (UINT32)(call->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1098 WLog_Print(log, g_LogLevel,
"pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1099 call->pioRecvPci->dwProtocol, cbExtraBytes);
1103 char buffer[1024] = { 0 };
1104 WLog_Print(log, g_LogLevel,
"pbExtraBytes: %s",
1105 smartcard_array_dump(pbExtraBytes, cbExtraBytes, buffer,
sizeof(buffer)));
1110 WLog_Print(log, g_LogLevel,
"pioRecvPci: null");
1113 WLog_Print(log, g_LogLevel,
"fpbRecvBufferIsNULL: %" PRId32
" cbRecvLength: %" PRIu32
"",
1114 call->fpbRecvBufferIsNULL, call->cbRecvLength);
1115 WLog_Print(log, g_LogLevel,
"}");
1118static void smartcard_trace_locate_cards_by_atr_w_call(wLog* log,
1123 if (!WLog_IsLevelActive(log, g_LogLevel))
1126 WLog_Print(log, g_LogLevel,
"LocateCardsByATRW_Call {");
1127 smartcard_log_context(log, &call->handles.hContext);
1129 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
1131 WLog_Print(log, g_LogLevel,
"}");
1134static void smartcard_trace_transmit_return(wLog* log,
const Transmit_Return* ret)
1137 UINT32 cbExtraBytes = 0;
1138 BYTE* pbExtraBytes = NULL;
1140 if (!WLog_IsLevelActive(log, g_LogLevel))
1143 WLog_Print(log, g_LogLevel,
"Transmit_Return {");
1144 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1145 SCardGetErrorString(ret->ReturnCode),
1146 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1148 if (ret->pioRecvPci)
1150 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1152 WLog_Print(log, g_LogLevel,
1153 " pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1154 ret->pioRecvPci->dwProtocol, cbExtraBytes);
1158 char buffer[1024] = { 0 };
1159 WLog_Print(log, g_LogLevel,
" pbExtraBytes: %s",
1160 smartcard_array_dump(pbExtraBytes, cbExtraBytes, buffer,
sizeof(buffer)));
1165 WLog_Print(log, g_LogLevel,
" pioRecvPci: null");
1168 WLog_Print(log, g_LogLevel,
" cbRecvLength: %" PRIu32
"", ret->cbRecvLength);
1170 if (ret->pbRecvBuffer)
1172 char buffer[1024] = { 0 };
1174 log, g_LogLevel,
" pbRecvBuffer: %s",
1175 smartcard_array_dump(ret->pbRecvBuffer, ret->cbRecvLength, buffer,
sizeof(buffer)));
1179 WLog_Print(log, g_LogLevel,
" pbRecvBuffer: null");
1182 WLog_Print(log, g_LogLevel,
"}");
1185static void smartcard_trace_control_return(wLog* log,
const Control_Return* ret)
1189 if (!WLog_IsLevelActive(log, g_LogLevel))
1192 WLog_Print(log, g_LogLevel,
"Control_Return {");
1193 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1194 SCardGetErrorString(ret->ReturnCode),
1195 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1196 WLog_Print(log, g_LogLevel,
" cbOutBufferSize: %" PRIu32
"", ret->cbOutBufferSize);
1198 if (ret->pvOutBuffer)
1200 char buffer[1024] = { 0 };
1202 log, g_LogLevel,
"pvOutBuffer: %s",
1203 smartcard_array_dump(ret->pvOutBuffer, ret->cbOutBufferSize, buffer,
sizeof(buffer)));
1207 WLog_Print(log, g_LogLevel,
"pvOutBuffer: null");
1210 WLog_Print(log, g_LogLevel,
"}");
1213static void smartcard_trace_control_call(wLog* log,
const Control_Call* call)
1217 if (!WLog_IsLevelActive(log, g_LogLevel))
1220 WLog_Print(log, g_LogLevel,
"Control_Call {");
1221 smartcard_log_context(log, &call->handles.hContext);
1222 smartcard_log_redir_handle(log, &call->handles.hCard);
1224 WLog_Print(log, g_LogLevel,
1225 "dwControlCode: 0x%08" PRIX32
" cbInBufferSize: %" PRIu32
1226 " fpvOutBufferIsNULL: %" PRId32
" cbOutBufferSize: %" PRIu32
"",
1227 call->dwControlCode, call->cbInBufferSize, call->fpvOutBufferIsNULL,
1228 call->cbOutBufferSize);
1230 if (call->pvInBuffer)
1232 char buffer[1024] = { 0 };
1234 log, WLOG_DEBUG,
"pbInBuffer: %s",
1235 smartcard_array_dump(call->pvInBuffer, call->cbInBufferSize, buffer,
sizeof(buffer)));
1239 WLog_Print(log, g_LogLevel,
"pvInBuffer: null");
1242 WLog_Print(log, g_LogLevel,
"}");
1245static void smartcard_trace_set_attrib_call(wLog* log,
const SetAttrib_Call* call)
1248 char buffer[8192] = { 0 };
1250 if (!WLog_IsLevelActive(log, g_LogLevel))
1253 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1254 smartcard_log_context(log, &call->handles.hContext);
1255 smartcard_log_redir_handle(log, &call->handles.hCard);
1256 WLog_Print(log, g_LogLevel,
"dwAttrId: 0x%08" PRIX32, call->dwAttrId);
1257 WLog_Print(log, g_LogLevel,
"cbAttrLen: 0x%08" PRIx32, call->cbAttrLen);
1258 WLog_Print(log, g_LogLevel,
"pbAttr: %s",
1259 smartcard_array_dump(call->pbAttr, call->cbAttrLen, buffer,
sizeof(buffer)));
1260 WLog_Print(log, g_LogLevel,
"}");
1263static void smartcard_trace_get_attrib_return(wLog* log,
const GetAttrib_Return* ret,
1267 char buffer[1024] = { 0 };
1269 if (!WLog_IsLevelActive(log, g_LogLevel))
1272 WLog_Print(log, g_LogLevel,
"GetAttrib_Return {");
1273 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1274 SCardGetErrorString(ret->ReturnCode),
1275 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1276 WLog_Print(log, g_LogLevel,
" dwAttrId: %s (0x%08" PRIX32
") cbAttrLen: 0x%08" PRIX32
"",
1277 SCardGetAttributeString(dwAttrId), dwAttrId, ret->cbAttrLen);
1278 WLog_Print(log, g_LogLevel,
" %s",
1279 smartcard_array_dump(ret->pbAttr, ret->cbAttrLen, buffer,
sizeof(buffer)));
1281 WLog_Print(log, g_LogLevel,
"}");
1284static void smartcard_trace_get_attrib_call(wLog* log,
const GetAttrib_Call* call)
1288 if (!WLog_IsLevelActive(log, g_LogLevel))
1291 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1292 smartcard_log_context(log, &call->handles.hContext);
1293 smartcard_log_redir_handle(log, &call->handles.hCard);
1295 WLog_Print(log, g_LogLevel,
1296 "dwAttrId: %s (0x%08" PRIX32
") fpbAttrIsNULL: %" PRId32
" cbAttrLen: 0x%08" PRIX32
1298 SCardGetAttributeString(call->dwAttrId), call->dwAttrId, call->fpbAttrIsNULL,
1300 WLog_Print(log, g_LogLevel,
"}");
1303static void smartcard_trace_status_call(wLog* log,
const Status_Call* call, BOOL unicode)
1307 if (!WLog_IsLevelActive(log, g_LogLevel))
1310 WLog_Print(log, g_LogLevel,
"Status%s_Call {", unicode ?
"W" :
"A");
1311 smartcard_log_context(log, &call->handles.hContext);
1312 smartcard_log_redir_handle(log, &call->handles.hCard);
1314 WLog_Print(log, g_LogLevel,
1315 "fmszReaderNamesIsNULL: %" PRId32
" cchReaderLen: %" PRIu32
" cbAtrLen: %" PRIu32
"",
1316 call->fmszReaderNamesIsNULL, call->cchReaderLen, call->cbAtrLen);
1317 WLog_Print(log, g_LogLevel,
"}");
1320static void smartcard_trace_status_return(wLog* log,
const Status_Return* ret, BOOL unicode)
1323 char* mszReaderNamesA = NULL;
1324 char buffer[1024] = { 0 };
1327 if (!WLog_IsLevelActive(log, g_LogLevel))
1329 cBytes = ret->cBytes;
1330 if (ret->ReturnCode != SCARD_S_SUCCESS)
1332 if (cBytes == SCARD_AUTOALLOCATE)
1334 mszReaderNamesA = smartcard_convert_string_list(ret->mszReaderNames, cBytes, unicode);
1336 WLog_Print(log, g_LogLevel,
"Status%s_Return {", unicode ?
"W" :
"A");
1337 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1338 SCardGetErrorString(ret->ReturnCode),
1339 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1340 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
") dwProtocol: %s (0x%08" PRIX32
")",
1341 SCardGetCardStateString(ret->dwState), ret->dwState,
1342 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1344 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" mszReaderNames: %s", ret->cBytes,
1347 WLog_Print(log, g_LogLevel,
" cbAtrLen: %" PRIu32
" pbAtr: %s", ret->cbAtrLen,
1348 smartcard_array_dump(ret->pbAtr, ret->cbAtrLen, buffer,
sizeof(buffer)));
1349 WLog_Print(log, g_LogLevel,
"}");
1350 free(mszReaderNamesA);
1353static void smartcard_trace_state_return(wLog* log,
const State_Return* ret)
1356 char buffer[1024] = { 0 };
1359 if (!WLog_IsLevelActive(log, g_LogLevel))
1362 state = SCardGetReaderStateString(ret->dwState);
1363 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1364 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1365 SCardGetErrorString(ret->ReturnCode),
1366 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1367 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
")", state, ret->dwState);
1368 WLog_Print(log, g_LogLevel,
" dwProtocol: %s (0x%08" PRIX32
")",
1369 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1370 WLog_Print(log, g_LogLevel,
" cbAtrLen: (0x%08" PRIX32
")", ret->cbAtrLen);
1371 WLog_Print(log, g_LogLevel,
" rgAtr: %s",
1372 smartcard_array_dump(ret->rgAtr,
sizeof(ret->rgAtr), buffer,
sizeof(buffer)));
1373 WLog_Print(log, g_LogLevel,
"}");
1377static void smartcard_trace_reconnect_return(wLog* log,
const Reconnect_Return* ret)
1381 if (!WLog_IsLevelActive(log, g_LogLevel))
1384 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1385 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1386 SCardGetErrorString(ret->ReturnCode),
1387 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1388 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1389 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1390 WLog_Print(log, g_LogLevel,
"}");
1393static void smartcard_trace_connect_a_call(wLog* log,
const ConnectA_Call* call)
1397 if (!WLog_IsLevelActive(log, g_LogLevel))
1400 WLog_Print(log, g_LogLevel,
"ConnectA_Call {");
1401 smartcard_log_context(log, &call->Common.handles.hContext);
1403 WLog_Print(log, g_LogLevel,
1404 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1405 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1406 call->szReader, SCardGetShareModeString(call->Common.dwShareMode),
1407 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1408 call->Common.dwPreferredProtocols);
1409 WLog_Print(log, g_LogLevel,
"}");
1412static void smartcard_trace_connect_w_call(wLog* log,
const ConnectW_Call* call)
1415 char szReaderA[1024] = { 0 };
1417 if (!WLog_IsLevelActive(log, g_LogLevel))
1421 (void)ConvertWCharToUtf8(call->szReader, szReaderA, ARRAYSIZE(szReaderA));
1422 WLog_Print(log, g_LogLevel,
"ConnectW_Call {");
1423 smartcard_log_context(log, &call->Common.handles.hContext);
1425 WLog_Print(log, g_LogLevel,
1426 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1427 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1428 szReaderA, SCardGetShareModeString(call->Common.dwShareMode),
1429 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1430 call->Common.dwPreferredProtocols);
1431 WLog_Print(log, g_LogLevel,
"}");
1434static void smartcard_trace_hcard_and_disposition_call(wLog* log,
1440 if (!WLog_IsLevelActive(log, g_LogLevel))
1443 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
1444 smartcard_log_context(log, &call->handles.hContext);
1445 smartcard_log_redir_handle(log, &call->handles.hCard);
1447 WLog_Print(log, g_LogLevel,
"dwDisposition: %s (0x%08" PRIX32
")",
1448 SCardGetDispositionString(call->dwDisposition), call->dwDisposition);
1449 WLog_Print(log, g_LogLevel,
"}");
1456 if (!WLog_IsLevelActive(log, g_LogLevel))
1459 WLog_Print(log, g_LogLevel,
"EstablishContext_Call {");
1460 WLog_Print(log, g_LogLevel,
"dwScope: %s (0x%08" PRIX32
")", SCardGetScopeString(call->dwScope),
1462 WLog_Print(log, g_LogLevel,
"}");
1469 if (!WLog_IsLevelActive(log, g_LogLevel))
1472 WLog_Print(log, g_LogLevel,
"EstablishContext_Return {");
1473 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1474 SCardGetErrorString(ret->ReturnCode),
1475 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1476 smartcard_log_context(log, &ret->hContext);
1478 WLog_Print(log, g_LogLevel,
"}");
1481void smartcard_trace_long_return(
const Long_Return* ret,
const char* name)
1483 wLog* log = scard_log();
1484 smartcard_trace_long_return_int(log, ret, name);
1487void smartcard_trace_long_return_int(wLog* log,
const Long_Return* ret,
const char* name)
1491 if (!WLog_IsLevelActive(log, g_LogLevel))
1494 WLog_Print(log, g_LogLevel,
"%s_Return {", name);
1495 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1496 SCardGetErrorString(ret->ReturnCode),
1497 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1498 WLog_Print(log, g_LogLevel,
"}");
1501static void smartcard_trace_connect_return(wLog* log,
const Connect_Return* ret)
1505 if (!WLog_IsLevelActive(log, g_LogLevel))
1508 WLog_Print(log, g_LogLevel,
"Connect_Return {");
1509 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1510 SCardGetErrorString(ret->ReturnCode),
1511 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1512 smartcard_log_context(log, &ret->hContext);
1513 smartcard_log_redir_handle(log, &ret->hCard);
1515 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1516 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1517 WLog_Print(log, g_LogLevel,
"}");
1520static void smartcard_trace_reconnect_call(wLog* log,
const Reconnect_Call* call)
1524 if (!WLog_IsLevelActive(log, g_LogLevel))
1527 WLog_Print(log, g_LogLevel,
"Reconnect_Call {");
1528 smartcard_log_context(log, &call->handles.hContext);
1529 smartcard_log_redir_handle(log, &call->handles.hCard);
1531 WLog_Print(log, g_LogLevel,
1532 "dwShareMode: %s (0x%08" PRIX32
") dwPreferredProtocols: %s (0x%08" PRIX32
1533 ") dwInitialization: %s (0x%08" PRIX32
")",
1534 SCardGetShareModeString(call->dwShareMode), call->dwShareMode,
1535 SCardGetProtocolString(call->dwPreferredProtocols), call->dwPreferredProtocols,
1536 SCardGetDispositionString(call->dwInitialization), call->dwInitialization);
1537 WLog_Print(log, g_LogLevel,
"}");
1544 if (!WLog_IsLevelActive(log, g_LogLevel))
1547 WLog_Print(log, g_LogLevel,
"GetDeviceTypeId_Return {");
1548 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1549 SCardGetErrorString(ret->ReturnCode),
1550 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1551 WLog_Print(log, g_LogLevel,
" dwDeviceId=%08" PRIx32, ret->dwDeviceId);
1553 WLog_Print(log, g_LogLevel,
"}");
1556static LONG smartcard_unpack_common_context_and_string_a(wLog* log,
wStream* s,
1558 CHAR** pszReaderName)
1561 UINT32 pbContextNdrPtr = 0;
1562 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1563 if (status != SCARD_S_SUCCESS)
1566 if (!smartcard_ndr_pointer_read(log, s, &index, NULL))
1567 return ERROR_INVALID_DATA;
1569 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1570 if (status != SCARD_S_SUCCESS)
1573 status = smartcard_ndr_read_a(log, s, pszReaderName, NDR_PTR_FULL);
1574 if (status != SCARD_S_SUCCESS)
1577 smartcard_trace_context_and_string_call_a(log, __func__, phContext, *pszReaderName);
1578 return SCARD_S_SUCCESS;
1581static LONG smartcard_unpack_common_context_and_string_w(wLog* log,
wStream* s,
1583 WCHAR** pszReaderName)
1586 UINT32 pbContextNdrPtr = 0;
1588 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1589 if (status != SCARD_S_SUCCESS)
1592 if (!smartcard_ndr_pointer_read(log, s, &index, NULL))
1593 return ERROR_INVALID_DATA;
1595 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1596 if (status != SCARD_S_SUCCESS)
1599 status = smartcard_ndr_read_w(log, s, pszReaderName, NDR_PTR_FULL);
1600 if (status != SCARD_S_SUCCESS)
1603 smartcard_trace_context_and_string_call_w(log, __func__, phContext, *pszReaderName);
1604 return SCARD_S_SUCCESS;
1607LONG smartcard_unpack_common_type_header(
wStream* s)
1609 wLog* log = scard_log();
1612 UINT8 endianness = 0;
1613 UINT16 commonHeaderLength = 0;
1615 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1616 return STATUS_BUFFER_TOO_SMALL;
1619 Stream_Read_UINT8(s, version);
1620 Stream_Read_UINT8(s, endianness);
1621 Stream_Read_UINT16(s, commonHeaderLength);
1622 Stream_Read_UINT32(s, filler);
1626 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Version %" PRIu8
"", version);
1627 return STATUS_INVALID_PARAMETER;
1630 if (endianness != 0x10)
1632 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Endianness %" PRIu8
"",
1634 return STATUS_INVALID_PARAMETER;
1637 if (commonHeaderLength != 8)
1639 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader CommonHeaderLength %" PRIu16
"",
1640 commonHeaderLength);
1641 return STATUS_INVALID_PARAMETER;
1644 if (filler != 0xCCCCCCCC)
1646 WLog_Print(log, WLOG_WARN,
"Unexpected CommonTypeHeader Filler 0x%08" PRIX32
"", filler);
1647 return STATUS_INVALID_PARAMETER;
1650 return SCARD_S_SUCCESS;
1653void smartcard_pack_common_type_header(
wStream* s)
1655 Stream_Write_UINT8(s, 1);
1656 Stream_Write_UINT8(s, 0x10);
1657 Stream_Write_UINT16(s, 8);
1658 Stream_Write_UINT32(s, 0xCCCCCCCC);
1661LONG smartcard_unpack_private_type_header(
wStream* s)
1663 wLog* log = scard_log();
1665 UINT32 objectBufferLength = 0;
1667 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1668 return STATUS_BUFFER_TOO_SMALL;
1670 Stream_Read_UINT32(s, objectBufferLength);
1671 Stream_Read_UINT32(s, filler);
1673 if (filler != 0x00000000)
1675 WLog_Print(log, WLOG_WARN,
"Unexpected PrivateTypeHeader Filler 0x%08" PRIX32
"", filler);
1676 return STATUS_INVALID_PARAMETER;
1679 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, objectBufferLength))
1680 return STATUS_INVALID_PARAMETER;
1682 return SCARD_S_SUCCESS;
1685void smartcard_pack_private_type_header(
wStream* s, UINT32 objectBufferLength)
1687 Stream_Write_UINT32(s, objectBufferLength);
1688 Stream_Write_UINT32(s, 0x00000000);
1691LONG smartcard_unpack_read_size_align(
wStream* s,
size_t size, UINT32 alignment)
1696 size = (size + alignment - 1) & ~(alignment - 1);
1700 Stream_Seek(s, pad);
1705LONG smartcard_pack_write_size_align(
wStream* s,
size_t size, UINT32 alignment)
1710 size = (size + alignment - 1) & ~(alignment - 1);
1715 if (!Stream_EnsureRemainingCapacity(s, pad))
1717 wLog* log = scard_log();
1718 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
1719 return SCARD_F_INTERNAL_ERROR;
1722 Stream_Zero(s, pad);
1725 return SCARD_S_SUCCESS;
1730 SCARDCONTEXT hContext = { 0 };
1732 WINPR_ASSERT(context);
1733 if ((context->cbContext !=
sizeof(ULONG_PTR)) && (context->cbContext != 0))
1735 wLog* log = scard_log();
1736 WLog_Print(log, WLOG_WARN,
1737 "REDIR_SCARDCONTEXT does not match native size: Actual: %" PRIu32
1738 ", Expected: %" PRIuz
"",
1739 context->cbContext,
sizeof(ULONG_PTR));
1743 if (context->cbContext)
1744 CopyMemory(&hContext, &(context->pbContext), context->cbContext);
1749void smartcard_scard_context_native_to_redir(
REDIR_SCARDCONTEXT* context, SCARDCONTEXT hContext)
1751 WINPR_ASSERT(context);
1753 context->cbContext =
sizeof(ULONG_PTR);
1754 CopyMemory(&(context->pbContext), &hContext, context->cbContext);
1759 SCARDHANDLE hCard = 0;
1761 WINPR_ASSERT(handle);
1762 if (handle->cbHandle == 0)
1765 if (handle->cbHandle !=
sizeof(ULONG_PTR))
1767 wLog* log = scard_log();
1768 WLog_Print(log, WLOG_WARN,
1769 "REDIR_SCARDHANDLE does not match native size: Actual: %" PRIu32
1770 ", Expected: %" PRIuz
"",
1771 handle->cbHandle,
sizeof(ULONG_PTR));
1775 if (handle->cbHandle)
1776 CopyMemory(&hCard, &(handle->pbHandle), handle->cbHandle);
1781void smartcard_scard_handle_native_to_redir(
REDIR_SCARDHANDLE* handle, SCARDHANDLE hCard)
1783 WINPR_ASSERT(handle);
1785 handle->cbHandle =
sizeof(ULONG_PTR);
1786 CopyMemory(&(handle->pbHandle), &hCard, handle->cbHandle);
1789#define smartcard_context_supported(log, size) \
1790 smartcard_context_supported_((log), (size), __FILE__, __func__, __LINE__)
1791static LONG smartcard_context_supported_(wLog* log, uint32_t size,
const char* file,
1792 const char* fkt,
size_t line)
1799 return SCARD_S_SUCCESS;
1802 const uint32_t level = WLOG_WARN;
1803 if (WLog_IsLevelActive(log, level))
1805 WLog_PrintTextMessage(log, level, line, file, fkt,
1806 "REDIR_SCARDCONTEXT length is not 0, 4 or 8: %" PRIu32
"",
1809 return STATUS_INVALID_PARAMETER;
1815 UINT32* index, UINT32* ppbContextNdrPtr,
1816 const char* file,
const char* function,
size_t line)
1818 UINT32 pbContextNdrPtr = 0;
1821 WINPR_ASSERT(context);
1825 if (!Stream_CheckAndLogRequiredLengthWLogEx(log, WLOG_WARN, s, 4, 1,
"%s(%s:%" PRIuz
")", file,
1827 return STATUS_BUFFER_TOO_SMALL;
1829 const LONG status = smartcard_context_supported_(log, context->cbContext, file, function, line);
1830 if (status != SCARD_S_SUCCESS)
1833 Stream_Read_UINT32(s, context->cbContext);
1835 if (!smartcard_ndr_pointer_read_(log, s, index, &pbContextNdrPtr, file, function, line))
1836 return ERROR_INVALID_DATA;
1838 if (((context->cbContext == 0) && pbContextNdrPtr) ||
1839 ((context->cbContext != 0) && !pbContextNdrPtr))
1841 WLog_Print(log, WLOG_WARN,
1842 "REDIR_SCARDCONTEXT cbContext (%" PRIu32
") pbContextNdrPtr (%" PRIu32
1844 context->cbContext, pbContextNdrPtr);
1845 return STATUS_INVALID_PARAMETER;
1848 if (!Stream_CheckAndLogRequiredLengthWLogEx(log, WLOG_WARN, s, context->cbContext, 1,
1849 "%s(%s:%" PRIuz
")", file, function, line))
1850 return STATUS_INVALID_PARAMETER;
1852 *ppbContextNdrPtr = pbContextNdrPtr;
1853 return SCARD_S_SUCCESS;
1856LONG smartcard_pack_redir_scard_context(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1859 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
1861 WINPR_ASSERT(context);
1862 if (context->cbContext != 0)
1864 Stream_Write_UINT32(s, context->cbContext);
1865 Stream_Write_UINT32(s, pbContextNdrPtr);
1866 *index = *index + 1;
1871 return SCARD_S_SUCCESS;
1874LONG smartcard_unpack_redir_scard_context_ref(wLog* log,
wStream* s,
1875 WINPR_ATTR_UNUSED UINT32 pbContextNdrPtr,
1880 WINPR_ASSERT(context);
1881 if (context->cbContext == 0)
1882 return SCARD_S_SUCCESS;
1884 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1885 return STATUS_BUFFER_TOO_SMALL;
1887 Stream_Read_UINT32(s, length);
1889 if (length != context->cbContext)
1891 WLog_Print(log, WLOG_WARN,
1892 "REDIR_SCARDCONTEXT length (%" PRIu32
") cbContext (%" PRIu32
") mismatch",
1893 length, context->cbContext);
1894 return STATUS_INVALID_PARAMETER;
1897 const LONG status = smartcard_context_supported(log, context->cbContext);
1898 if (status != SCARD_S_SUCCESS)
1901 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, context->cbContext))
1902 return STATUS_BUFFER_TOO_SMALL;
1904 if (context->cbContext)
1905 Stream_Read(s, &(context->pbContext), context->cbContext);
1907 ZeroMemory(&(context->pbContext),
sizeof(context->pbContext));
1909 return SCARD_S_SUCCESS;
1912LONG smartcard_pack_redir_scard_context_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1915 WINPR_ASSERT(context);
1916 Stream_Write_UINT32(s, context->cbContext);
1918 if (context->cbContext)
1920 Stream_Write(s, &(context->pbContext), context->cbContext);
1923 return SCARD_S_SUCCESS;
1927 UINT32* index,
const char* file,
const char* function,
1930 WINPR_ASSERT(handle);
1933 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1934 return STATUS_BUFFER_TOO_SMALL;
1936 Stream_Read_UINT32(s, handle->cbHandle);
1938 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, handle->cbHandle))
1939 return STATUS_BUFFER_TOO_SMALL;
1941 if (!smartcard_ndr_pointer_read_(log, s, index, NULL, file, function, line))
1942 return ERROR_INVALID_DATA;
1944 return SCARD_S_SUCCESS;
1947LONG smartcard_pack_redir_scard_handle(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1950 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
1952 WINPR_ASSERT(handle);
1953 if (handle->cbHandle != 0)
1955 Stream_Write_UINT32(s, handle->cbHandle);
1956 Stream_Write_UINT32(s, pbContextNdrPtr);
1957 *index = *index + 1;
1961 return SCARD_S_SUCCESS;
1968 WINPR_ASSERT(handle);
1969 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1970 return STATUS_BUFFER_TOO_SMALL;
1972 Stream_Read_UINT32(s, length);
1974 if (length != handle->cbHandle)
1976 WLog_Print(log, WLOG_WARN,
1977 "REDIR_SCARDHANDLE length (%" PRIu32
") cbHandle (%" PRIu32
") mismatch", length,
1979 return STATUS_INVALID_PARAMETER;
1982 if ((handle->cbHandle != 4) && (handle->cbHandle != 8))
1984 WLog_Print(log, WLOG_WARN,
"REDIR_SCARDHANDLE length is not 4 or 8: %" PRIu32
"",
1986 return STATUS_INVALID_PARAMETER;
1989 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, handle->cbHandle))
1990 return STATUS_BUFFER_TOO_SMALL;
1992 if (handle->cbHandle)
1993 Stream_Read(s, &(handle->pbHandle), handle->cbHandle);
1995 return SCARD_S_SUCCESS;
1998LONG smartcard_pack_redir_scard_handle_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
2001 WINPR_ASSERT(handle);
2002 Stream_Write_UINT32(s, handle->cbHandle);
2004 if (handle->cbHandle)
2005 Stream_Write(s, &(handle->pbHandle), handle->cbHandle);
2007 return SCARD_S_SUCCESS;
2013 wLog* log = scard_log();
2015 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2016 return STATUS_BUFFER_TOO_SMALL;
2018 Stream_Read_UINT32(s, call->dwScope);
2019 smartcard_trace_establish_context_call(log, call);
2020 return SCARD_S_SUCCESS;
2026 wLog* log = scard_log();
2030 smartcard_trace_establish_context_return(log, ret);
2031 if (ret->ReturnCode != SCARD_S_SUCCESS)
2032 return ret->ReturnCode;
2034 status = smartcard_pack_redir_scard_context(log, s, &(ret->hContext), &index);
2035 if (status != SCARD_S_SUCCESS)
2038 return smartcard_pack_redir_scard_context_ref(log, s, &(ret->hContext));
2044 UINT32 pbContextNdrPtr = 0;
2045 wLog* log = scard_log();
2048 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2050 if (status != SCARD_S_SUCCESS)
2053 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2054 &(call->handles.hContext));
2055 if (status != SCARD_S_SUCCESS)
2056 WLog_Print(log, WLOG_ERROR,
2057 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2060 smartcard_trace_context_call(log, call, name);
2067 UINT32 pbContextNdrPtr = 0;
2068 wLog* log = scard_log();
2071 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2074 if (status != SCARD_S_SUCCESS)
2077 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2078 return STATUS_BUFFER_TOO_SMALL;
2080 Stream_Read_INT32(s, call->fmszGroupsIsNULL);
2081 Stream_Read_UINT32(s, call->cchGroups);
2082 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2083 &(call->handles.hContext));
2085 if (status != SCARD_S_SUCCESS)
2088 smartcard_trace_list_reader_groups_call(log, call, unicode);
2089 return SCARD_S_SUCCESS;
2096 wLog* log = scard_log();
2098 DWORD cBytes = ret->cBytes;
2101 smartcard_trace_list_reader_groups_return(log, ret, unicode);
2102 if (ret->ReturnCode != SCARD_S_SUCCESS)
2104 if (cBytes == SCARD_AUTOALLOCATE)
2107 if (!Stream_EnsureRemainingCapacity(s, 4))
2108 return SCARD_E_NO_MEMORY;
2110 Stream_Write_UINT32(s, cBytes);
2111 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
2112 return SCARD_E_NO_MEMORY;
2114 status = smartcard_ndr_write(s, ret->msz, cBytes, 1, NDR_PTR_SIMPLE);
2115 if (status != SCARD_S_SUCCESS)
2117 return ret->ReturnCode;
2123 UINT32 mszGroupsNdrPtr = 0;
2124 UINT32 pbContextNdrPtr = 0;
2125 wLog* log = scard_log();
2128 call->mszGroups = NULL;
2130 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2132 if (status != SCARD_S_SUCCESS)
2135 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2136 return STATUS_BUFFER_TOO_SMALL;
2138 Stream_Read_UINT32(s, call->cBytes);
2139 if (!smartcard_ndr_pointer_read(log, s, &index, &mszGroupsNdrPtr))
2140 return ERROR_INVALID_DATA;
2142 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2143 return STATUS_BUFFER_TOO_SMALL;
2144 Stream_Read_INT32(s, call->fmszReadersIsNULL);
2145 Stream_Read_UINT32(s, call->cchReaders);
2147 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2148 &(call->handles.hContext));
2149 if (status != SCARD_S_SUCCESS)
2152 if (mszGroupsNdrPtr)
2154 status = smartcard_ndr_read(log, s, &call->mszGroups, call->cBytes, 1, NDR_PTR_SIMPLE);
2155 if (status != SCARD_S_SUCCESS)
2159 smartcard_trace_list_readers_call(log, call, unicode);
2160 return SCARD_S_SUCCESS;
2166 wLog* log = scard_log();
2169 UINT32 size = ret->cBytes;
2171 smartcard_trace_list_readers_return(log, ret, unicode);
2172 if (ret->ReturnCode != SCARD_S_SUCCESS)
2175 if (!Stream_EnsureRemainingCapacity(s, 4))
2177 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
2178 return SCARD_F_INTERNAL_ERROR;
2181 Stream_Write_UINT32(s, size);
2182 if (!smartcard_ndr_pointer_write(s, &index, size))
2183 return SCARD_E_NO_MEMORY;
2185 status = smartcard_ndr_write(s, ret->msz, size, 1, NDR_PTR_SIMPLE);
2186 if (status != SCARD_S_SUCCESS)
2188 return ret->ReturnCode;
2192 UINT32* index, UINT32* ppbContextNdrPtr)
2194 WINPR_ASSERT(common);
2195 LONG status = smartcard_unpack_redir_scard_context(log, s, &(common->handles.hContext), index,
2197 if (status != SCARD_S_SUCCESS)
2200 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2201 return STATUS_BUFFER_TOO_SMALL;
2203 Stream_Read_UINT32(s, common->dwShareMode);
2204 Stream_Read_UINT32(s, common->dwPreferredProtocols);
2205 return SCARD_S_SUCCESS;
2212 UINT32 pbContextNdrPtr = 0;
2215 wLog* log = scard_log();
2217 call->szReader = NULL;
2219 if (!smartcard_ndr_pointer_read(log, s, &index, NULL))
2220 return ERROR_INVALID_DATA;
2222 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2223 if (status != SCARD_S_SUCCESS)
2225 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2230 status = smartcard_ndr_read_a(log, s, &call->szReader, NDR_PTR_FULL);
2231 if (status != SCARD_S_SUCCESS)
2234 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2235 &(call->Common.handles.hContext));
2236 if (status != SCARD_S_SUCCESS)
2237 WLog_Print(log, WLOG_ERROR,
2238 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2241 smartcard_trace_connect_a_call(log, call);
2249 UINT32 pbContextNdrPtr = 0;
2252 wLog* log = scard_log();
2253 call->szReader = NULL;
2255 if (!smartcard_ndr_pointer_read(log, s, &index, NULL))
2256 return ERROR_INVALID_DATA;
2258 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2259 if (status != SCARD_S_SUCCESS)
2261 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2266 status = smartcard_ndr_read_w(log, s, &call->szReader, NDR_PTR_FULL);
2267 if (status != SCARD_S_SUCCESS)
2270 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2271 &(call->Common.handles.hContext));
2272 if (status != SCARD_S_SUCCESS)
2273 WLog_Print(log, WLOG_ERROR,
2274 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2277 smartcard_trace_connect_w_call(log, call);
2287 wLog* log = scard_log();
2288 smartcard_trace_connect_return(log, ret);
2290 status = smartcard_pack_redir_scard_context(log, s, &ret->hContext, &index);
2291 if (status != SCARD_S_SUCCESS)
2294 status = smartcard_pack_redir_scard_handle(log, s, &ret->hCard, &index);
2295 if (status != SCARD_S_SUCCESS)
2298 if (!Stream_EnsureRemainingCapacity(s, 4))
2299 return SCARD_E_NO_MEMORY;
2301 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2302 status = smartcard_pack_redir_scard_context_ref(log, s, &ret->hContext);
2303 if (status != SCARD_S_SUCCESS)
2305 return smartcard_pack_redir_scard_handle_ref(log, s, &(ret->hCard));
2311 UINT32 pbContextNdrPtr = 0;
2314 wLog* log = scard_log();
2315 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2317 if (status != SCARD_S_SUCCESS)
2320 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2321 if (status != SCARD_S_SUCCESS)
2324 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2325 return STATUS_BUFFER_TOO_SMALL;
2327 Stream_Read_UINT32(s, call->dwShareMode);
2328 Stream_Read_UINT32(s, call->dwPreferredProtocols);
2329 Stream_Read_UINT32(s, call->dwInitialization);
2331 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2332 &(call->handles.hContext));
2333 if (status != SCARD_S_SUCCESS)
2335 WLog_Print(log, WLOG_ERROR,
2336 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2341 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2342 if (status != SCARD_S_SUCCESS)
2343 WLog_Print(log, WLOG_ERROR,
2344 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
2346 smartcard_trace_reconnect_call(log, call);
2353 wLog* log = scard_log();
2354 smartcard_trace_reconnect_return(log, ret);
2356 if (!Stream_EnsureRemainingCapacity(s, 4))
2357 return SCARD_E_NO_MEMORY;
2358 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2359 return ret->ReturnCode;
2366 UINT32 pbContextNdrPtr = 0;
2369 wLog* log = scard_log();
2371 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2373 if (status != SCARD_S_SUCCESS)
2376 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2377 if (status != SCARD_S_SUCCESS)
2380 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2381 return STATUS_BUFFER_TOO_SMALL;
2383 Stream_Read_UINT32(s, call->dwDisposition);
2385 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2386 &(call->handles.hContext));
2387 if (status != SCARD_S_SUCCESS)
2390 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2391 if (status != SCARD_S_SUCCESS)
2394 smartcard_trace_hcard_and_disposition_call(log, call, name);
2402 if (!WLog_IsLevelActive(log, g_LogLevel))
2405 WLog_Print(log, g_LogLevel,
"GetStatusChangeA_Call {");
2406 smartcard_log_context(log, &call->handles.hContext);
2408 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
2411 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
2413 WLog_Print(log, g_LogLevel,
"}");
2417 UINT32 cReaders, UINT32* ptrIndex)
2419 LONG status = SCARD_E_NO_MEMORY;
2421 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2422 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2425 const UINT32 len = Stream_Get_UINT32(s);
2426 if (len != cReaders)
2428 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEA");
2434 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2435 if (!rgReaderStates || !states)
2437 status = ERROR_INVALID_DATA;
2439 for (UINT32 index = 0; index < cReaders; index++)
2441 UINT32 ptr = UINT32_MAX;
2444 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2447 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2453 states[index] = ptr != 0;
2454 Stream_Read_UINT32(s, readerState->dwCurrentState);
2455 Stream_Read_UINT32(s, readerState->dwEventState);
2456 Stream_Read_UINT32(s, readerState->cbAtr);
2457 Stream_Read(s, readerState->rgbAtr, 36);
2460 for (UINT32 index = 0; index < cReaders; index++)
2467 status = smartcard_ndr_read_a(log, s, &readerState->szReader, NDR_PTR_FULL);
2468 if (status != SCARD_S_SUCCESS)
2472 *ppcReaders = rgReaderStates;
2474 return SCARD_S_SUCCESS;
2478 for (UINT32 index = 0; index < cReaders; index++)
2481 free(readerState->szReader);
2484 free(rgReaderStates);
2490 UINT32 cReaders, UINT32* ptrIndex)
2492 LONG status = SCARD_E_NO_MEMORY;
2494 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2495 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2498 const UINT32 len = Stream_Get_UINT32(s);
2499 if (len != cReaders)
2501 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEW");
2507 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2509 if (!rgReaderStates || !states)
2512 status = ERROR_INVALID_DATA;
2513 for (UINT32 index = 0; index < cReaders; index++)
2515 UINT32 ptr = UINT32_MAX;
2518 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2521 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2527 states[index] = ptr != 0;
2528 Stream_Read_UINT32(s, readerState->dwCurrentState);
2529 Stream_Read_UINT32(s, readerState->dwEventState);
2530 Stream_Read_UINT32(s, readerState->cbAtr);
2531 Stream_Read(s, readerState->rgbAtr, 36);
2534 for (UINT32 index = 0; index < cReaders; index++)
2542 status = smartcard_ndr_read_w(log, s, &readerState->szReader, NDR_PTR_FULL);
2543 if (status != SCARD_S_SUCCESS)
2547 *ppcReaders = rgReaderStates;
2549 return SCARD_S_SUCCESS;
2553 for (UINT32 index = 0; index < cReaders; index++)
2556 free(readerState->szReader);
2559 free(rgReaderStates);
2572 UINT32 pbContextNdrPtr = 0;
2575 wLog* log = scard_log();
2577 call->rgReaderStates = NULL;
2579 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2581 if (status != SCARD_S_SUCCESS)
2584 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2585 return STATUS_BUFFER_TOO_SMALL;
2587 Stream_Read_UINT32(s, call->dwTimeOut);
2588 Stream_Read_UINT32(s, call->cReaders);
2589 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2590 return ERROR_INVALID_DATA;
2592 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2593 &(call->handles.hContext));
2594 if (status != SCARD_S_SUCCESS)
2600 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
2601 if (status != SCARD_S_SUCCESS)
2606 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2607 return SCARD_E_UNEXPECTED;
2610 smartcard_trace_get_status_change_a_call(log, call);
2611 return SCARD_S_SUCCESS;
2618 UINT32 pbContextNdrPtr = 0;
2621 wLog* log = scard_log();
2622 call->rgReaderStates = NULL;
2624 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2626 if (status != SCARD_S_SUCCESS)
2629 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2630 return STATUS_BUFFER_TOO_SMALL;
2632 Stream_Read_UINT32(s, call->dwTimeOut);
2633 Stream_Read_UINT32(s, call->cReaders);
2634 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2635 return ERROR_INVALID_DATA;
2637 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2638 &(call->handles.hContext));
2639 if (status != SCARD_S_SUCCESS)
2645 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
2646 if (status != SCARD_S_SUCCESS)
2651 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2652 return SCARD_E_UNEXPECTED;
2655 smartcard_trace_get_status_change_w_call(log, call);
2656 return SCARD_S_SUCCESS;
2663 wLog* log = scard_log();
2666 DWORD cReaders = ret->cReaders;
2669 smartcard_trace_get_status_change_return(log, ret, unicode);
2670 if (ret->ReturnCode != SCARD_S_SUCCESS)
2672 if (cReaders == SCARD_AUTOALLOCATE)
2675 if (!Stream_EnsureRemainingCapacity(s, 4))
2676 return SCARD_E_NO_MEMORY;
2678 Stream_Write_UINT32(s, cReaders);
2679 if (!smartcard_ndr_pointer_write(s, &index, cReaders))
2680 return SCARD_E_NO_MEMORY;
2681 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cReaders, NDR_PTR_SIMPLE);
2682 if (status != SCARD_S_SUCCESS)
2684 return ret->ReturnCode;
2690 UINT32 pbContextNdrPtr = 0;
2692 wLog* log = scard_log();
2695 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2697 if (status != SCARD_S_SUCCESS)
2700 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2701 if (status != SCARD_S_SUCCESS)
2704 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2705 return STATUS_BUFFER_TOO_SMALL;
2707 Stream_Read_INT32(s, call->fpbAtrIsNULL);
2708 Stream_Read_UINT32(s, call->cbAtrLen);
2710 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2711 &(call->handles.hContext));
2712 if (status != SCARD_S_SUCCESS)
2715 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2716 if (status != SCARD_S_SUCCESS)
2725 wLog* log = scard_log();
2727 DWORD cbAtrLen = ret->cbAtrLen;
2730 smartcard_trace_state_return(log, ret);
2731 if (ret->ReturnCode != SCARD_S_SUCCESS)
2733 if (cbAtrLen == SCARD_AUTOALLOCATE)
2736 Stream_Write_UINT32(s, ret->dwState);
2737 Stream_Write_UINT32(s, ret->dwProtocol);
2738 Stream_Write_UINT32(s, cbAtrLen);
2739 if (!smartcard_ndr_pointer_write(s, &index, cbAtrLen))
2740 return SCARD_E_NO_MEMORY;
2741 status = smartcard_ndr_write(s, ret->rgAtr, cbAtrLen, 1, NDR_PTR_SIMPLE);
2742 if (status != SCARD_S_SUCCESS)
2744 return ret->ReturnCode;
2750 UINT32 pbContextNdrPtr = 0;
2753 wLog* log = scard_log();
2755 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2757 if (status != SCARD_S_SUCCESS)
2760 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2761 if (status != SCARD_S_SUCCESS)
2764 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2765 return STATUS_BUFFER_TOO_SMALL;
2767 Stream_Read_INT32(s, call->fmszReaderNamesIsNULL);
2768 Stream_Read_UINT32(s, call->cchReaderLen);
2769 Stream_Read_UINT32(s, call->cbAtrLen);
2771 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2772 &(call->handles.hContext));
2773 if (status != SCARD_S_SUCCESS)
2776 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2777 if (status != SCARD_S_SUCCESS)
2780 smartcard_trace_status_call(log, call, unicode);
2787 wLog* log = scard_log();
2791 DWORD cBytes = ret->cBytes;
2793 smartcard_trace_status_return(log, ret, unicode);
2794 if (ret->ReturnCode != SCARD_S_SUCCESS)
2796 if (cBytes == SCARD_AUTOALLOCATE)
2799 if (!Stream_EnsureRemainingCapacity(s, 4))
2800 return SCARD_F_INTERNAL_ERROR;
2802 Stream_Write_UINT32(s, cBytes);
2803 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
2804 return SCARD_E_NO_MEMORY;
2806 if (!Stream_EnsureRemainingCapacity(s, 44))
2807 return SCARD_F_INTERNAL_ERROR;
2809 Stream_Write_UINT32(s, ret->dwState);
2810 Stream_Write_UINT32(s, ret->dwProtocol);
2811 Stream_Write(s, ret->pbAtr,
sizeof(ret->pbAtr));
2812 Stream_Write_UINT32(s, ret->cbAtrLen);
2813 status = smartcard_ndr_write(s, ret->mszReaderNames, cBytes, 1, NDR_PTR_SIMPLE);
2814 if (status != SCARD_S_SUCCESS)
2816 return ret->ReturnCode;
2822 wLog* log = scard_log();
2824 UINT32 pbContextNdrPtr = 0;
2826 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2828 if (status != SCARD_S_SUCCESS)
2831 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2832 if (status != SCARD_S_SUCCESS)
2835 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2836 return STATUS_BUFFER_TOO_SMALL;
2838 Stream_Read_UINT32(s, call->dwAttrId);
2839 Stream_Read_INT32(s, call->fpbAttrIsNULL);
2840 Stream_Read_UINT32(s, call->cbAttrLen);
2842 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2843 &(call->handles.hContext));
2844 if (status != SCARD_S_SUCCESS)
2847 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2848 if (status != SCARD_S_SUCCESS)
2851 smartcard_trace_get_attrib_call(log, call);
2856 DWORD cbAttrCallLen)
2859 wLog* log = scard_log();
2861 DWORD cbAttrLen = 0;
2863 smartcard_trace_get_attrib_return(log, ret, dwAttrId);
2865 if (!Stream_EnsureRemainingCapacity(s, 4))
2866 return SCARD_F_INTERNAL_ERROR;
2868 cbAttrLen = ret->cbAttrLen;
2869 if (ret->ReturnCode != SCARD_S_SUCCESS)
2871 if (cbAttrLen == SCARD_AUTOALLOCATE)
2876 if (cbAttrCallLen < cbAttrLen)
2877 cbAttrLen = cbAttrCallLen;
2879 Stream_Write_UINT32(s, cbAttrLen);
2880 if (!smartcard_ndr_pointer_write(s, &index, cbAttrLen))
2881 return SCARD_E_NO_MEMORY;
2883 status = smartcard_ndr_write(s, ret->pbAttr, cbAttrLen, 1, NDR_PTR_SIMPLE);
2884 if (status != SCARD_S_SUCCESS)
2886 return ret->ReturnCode;
2892 wLog* log = scard_log();
2895 UINT32 pvInBufferNdrPtr = 0;
2896 UINT32 pbContextNdrPtr = 0;
2898 call->pvInBuffer = NULL;
2900 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2902 if (status != SCARD_S_SUCCESS)
2905 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2906 if (status != SCARD_S_SUCCESS)
2909 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 20))
2910 return STATUS_BUFFER_TOO_SMALL;
2912 Stream_Read_UINT32(s, call->dwControlCode);
2913 Stream_Read_UINT32(s, call->cbInBufferSize);
2914 if (!smartcard_ndr_pointer_read(log, s, &index,
2916 return ERROR_INVALID_DATA;
2917 Stream_Read_INT32(s, call->fpvOutBufferIsNULL);
2918 Stream_Read_UINT32(s, call->cbOutBufferSize);
2920 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2921 &(call->handles.hContext));
2922 if (status != SCARD_S_SUCCESS)
2925 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2926 if (status != SCARD_S_SUCCESS)
2929 if (pvInBufferNdrPtr)
2932 smartcard_ndr_read(log, s, &call->pvInBuffer, call->cbInBufferSize, 1, NDR_PTR_SIMPLE);
2933 if (status != SCARD_S_SUCCESS)
2937 smartcard_trace_control_call(log, call);
2938 return SCARD_S_SUCCESS;
2944 wLog* log = scard_log();
2947 DWORD cbDataLen = ret->cbOutBufferSize;
2950 smartcard_trace_control_return(log, ret);
2951 if (ret->ReturnCode != SCARD_S_SUCCESS)
2953 if (cbDataLen == SCARD_AUTOALLOCATE)
2956 if (!Stream_EnsureRemainingCapacity(s, 4))
2957 return SCARD_F_INTERNAL_ERROR;
2959 Stream_Write_UINT32(s, cbDataLen);
2960 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
2961 return SCARD_E_NO_MEMORY;
2963 status = smartcard_ndr_write(s, ret->pvOutBuffer, cbDataLen, 1, NDR_PTR_SIMPLE);
2964 if (status != SCARD_S_SUCCESS)
2966 return ret->ReturnCode;
2972 BYTE* pbExtraBytes = NULL;
2973 UINT32 pbExtraBytesNdrPtr = 0;
2974 UINT32 pbSendBufferNdrPtr = 0;
2975 UINT32 pioRecvPciNdrPtr = 0;
2979 UINT32 pbContextNdrPtr = 0;
2982 wLog* log = scard_log();
2984 call->pioSendPci = NULL;
2985 call->pioRecvPci = NULL;
2986 call->pbSendBuffer = NULL;
2988 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2990 if (status != SCARD_S_SUCCESS)
2993 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2994 if (status != SCARD_S_SUCCESS)
2997 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 32))
2998 return STATUS_BUFFER_TOO_SMALL;
3000 Stream_Read_UINT32(s, ioSendPci.dwProtocol);
3001 Stream_Read_UINT32(s, ioSendPci.cbExtraBytes);
3002 if (!smartcard_ndr_pointer_read(log, s, &index,
3003 &pbExtraBytesNdrPtr))
3004 return ERROR_INVALID_DATA;
3006 Stream_Read_UINT32(s, call->cbSendLength);
3007 if (!smartcard_ndr_pointer_read(log, s, &index,
3008 &pbSendBufferNdrPtr))
3009 return ERROR_INVALID_DATA;
3011 if (!smartcard_ndr_pointer_read(log, s, &index,
3013 return ERROR_INVALID_DATA;
3015 Stream_Read_INT32(s, call->fpbRecvBufferIsNULL);
3016 Stream_Read_UINT32(s, call->cbRecvLength);
3018 if (ioSendPci.cbExtraBytes > 1024)
3020 WLog_Print(log, WLOG_WARN,
3021 "Transmit_Call ioSendPci.cbExtraBytes is out of bounds: %" PRIu32
" (max: 1024)",
3022 ioSendPci.cbExtraBytes);
3023 return STATUS_INVALID_PARAMETER;
3026 if (call->cbSendLength > 66560)
3028 WLog_Print(log, WLOG_WARN,
3029 "Transmit_Call cbSendLength is out of bounds: %" PRIu32
" (max: 66560)",
3030 ioSendPci.cbExtraBytes);
3031 return STATUS_INVALID_PARAMETER;
3034 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3035 &(call->handles.hContext));
3036 if (status != SCARD_S_SUCCESS)
3039 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3040 if (status != SCARD_S_SUCCESS)
3043 if (ioSendPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3047 "Transmit_Call ioSendPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3048 return STATUS_INVALID_PARAMETER;
3051 if (pbExtraBytesNdrPtr)
3054 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3055 return STATUS_BUFFER_TOO_SMALL;
3057 Stream_Read_UINT32(s, length);
3059 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioSendPci.cbExtraBytes))
3060 return STATUS_BUFFER_TOO_SMALL;
3062 ioSendPci.pbExtraBytes = Stream_Pointer(s);
3066 if (!call->pioSendPci)
3068 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3069 return STATUS_NO_MEMORY;
3072 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3073 call->pioSendPci->cbPciLength = (DWORD)(ioSendPci.cbExtraBytes +
sizeof(
SCARD_IO_REQUEST));
3075 Stream_Read(s, pbExtraBytes, ioSendPci.cbExtraBytes);
3076 smartcard_unpack_read_size_align(s, ioSendPci.cbExtraBytes, 4);
3082 if (!call->pioSendPci)
3084 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3085 return STATUS_NO_MEMORY;
3088 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3092 if (pbSendBufferNdrPtr)
3095 smartcard_ndr_read(log, s, &call->pbSendBuffer, call->cbSendLength, 1, NDR_PTR_SIMPLE);
3096 if (status != SCARD_S_SUCCESS)
3100 if (pioRecvPciNdrPtr)
3102 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3103 return STATUS_BUFFER_TOO_SMALL;
3105 Stream_Read_UINT32(s, ioRecvPci.dwProtocol);
3106 Stream_Read_UINT32(s, ioRecvPci.cbExtraBytes);
3107 if (!smartcard_ndr_pointer_read(log, s, &index,
3108 &pbExtraBytesNdrPtr))
3109 return ERROR_INVALID_DATA;
3111 if (ioRecvPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3115 "Transmit_Call ioRecvPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3116 return STATUS_INVALID_PARAMETER;
3119 if (pbExtraBytesNdrPtr)
3122 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3123 return STATUS_BUFFER_TOO_SMALL;
3125 Stream_Read_UINT32(s, length);
3127 if (ioRecvPci.cbExtraBytes > 1024)
3129 WLog_Print(log, WLOG_WARN,
3130 "Transmit_Call ioRecvPci.cbExtraBytes is out of bounds: %" PRIu32
3132 ioRecvPci.cbExtraBytes);
3133 return STATUS_INVALID_PARAMETER;
3136 if (length != ioRecvPci.cbExtraBytes)
3138 WLog_Print(log, WLOG_WARN,
3139 "Transmit_Call unexpected length: Actual: %" PRIu32
3140 ", Expected: %" PRIu32
" (ioRecvPci.cbExtraBytes)",
3141 length, ioRecvPci.cbExtraBytes);
3142 return STATUS_INVALID_PARAMETER;
3145 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioRecvPci.cbExtraBytes))
3146 return STATUS_BUFFER_TOO_SMALL;
3148 ioRecvPci.pbExtraBytes = Stream_Pointer(s);
3152 if (!call->pioRecvPci)
3154 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3155 return STATUS_NO_MEMORY;
3158 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3159 call->pioRecvPci->cbPciLength =
3162 Stream_Read(s, pbExtraBytes, ioRecvPci.cbExtraBytes);
3163 smartcard_unpack_read_size_align(s, ioRecvPci.cbExtraBytes, 4);
3169 if (!call->pioRecvPci)
3171 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3172 return STATUS_NO_MEMORY;
3175 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3180 smartcard_trace_transmit_call(log, call);
3181 return SCARD_S_SUCCESS;
3187 wLog* log = scard_log();
3192 UINT32 cbRecvLength = ret->cbRecvLength;
3193 UINT32 cbRecvPci = ret->pioRecvPci ? ret->pioRecvPci->cbPciLength : 0;
3195 smartcard_trace_transmit_return(log, ret);
3197 if (!ret->pbRecvBuffer)
3200 if (!smartcard_ndr_pointer_write(s, &index, cbRecvPci))
3201 return SCARD_E_NO_MEMORY;
3202 if (!Stream_EnsureRemainingCapacity(s, 4))
3203 return SCARD_E_NO_MEMORY;
3204 Stream_Write_UINT32(s, cbRecvLength);
3205 if (!smartcard_ndr_pointer_write(s, &index, cbRecvLength))
3206 return SCARD_E_NO_MEMORY;
3208 if (ret->pioRecvPci)
3210 UINT32 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
3213 if (!Stream_EnsureRemainingCapacity(s, cbExtraBytes + 16))
3215 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3216 return SCARD_F_INTERNAL_ERROR;
3219 Stream_Write_UINT32(s, ret->pioRecvPci->dwProtocol);
3220 Stream_Write_UINT32(s, cbExtraBytes);
3221 if (!smartcard_ndr_pointer_write(s, &index, cbExtraBytes))
3222 return SCARD_E_NO_MEMORY;
3223 error = smartcard_ndr_write(s, pbExtraBytes, cbExtraBytes, 1, NDR_PTR_SIMPLE);
3228 status = smartcard_ndr_write(s, ret->pbRecvBuffer, ret->cbRecvLength, 1, NDR_PTR_SIMPLE);
3229 if (status != SCARD_S_SUCCESS)
3231 return ret->ReturnCode;
3236 UINT32 rgReaderStatesNdrPtr = 0;
3237 UINT32 rgAtrMasksNdrPtr = 0;
3239 UINT32 pbContextNdrPtr = 0;
3242 wLog* log = scard_log();
3244 call->rgReaderStates = NULL;
3246 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3248 if (status != SCARD_S_SUCCESS)
3251 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3252 return STATUS_BUFFER_TOO_SMALL;
3254 Stream_Read_UINT32(s, call->cAtrs);
3255 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3256 return ERROR_INVALID_DATA;
3257 Stream_Read_UINT32(s, call->cReaders);
3258 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3259 return ERROR_INVALID_DATA;
3261 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3262 &(call->handles.hContext));
3263 if (status != SCARD_S_SUCCESS)
3266 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3268 WLog_Print(log, WLOG_WARN,
3269 "LocateCardsByATRA_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3270 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3271 rgAtrMasksNdrPtr, call->cAtrs);
3272 return STATUS_INVALID_PARAMETER;
3275 if (rgAtrMasksNdrPtr)
3277 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3278 if (status != SCARD_S_SUCCESS)
3282 if (rgReaderStatesNdrPtr)
3285 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
3286 if (status != SCARD_S_SUCCESS)
3290 smartcard_trace_locate_cards_by_atr_a_call(log, call);
3291 return SCARD_S_SUCCESS;
3296 UINT32 sz1NdrPtr = 0;
3297 UINT32 sz2NdrPtr = 0;
3299 UINT32 pbContextNdrPtr = 0;
3302 wLog* log = scard_log();
3304 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3306 if (status != SCARD_S_SUCCESS)
3309 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3310 return ERROR_INVALID_DATA;
3311 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3312 return ERROR_INVALID_DATA;
3315 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3316 if (status != SCARD_S_SUCCESS)
3321 status = smartcard_ndr_read_a(log, s, &call->sz1, NDR_PTR_FULL);
3322 if (status != SCARD_S_SUCCESS)
3327 status = smartcard_ndr_read_a(log, s, &call->sz2, NDR_PTR_FULL);
3328 if (status != SCARD_S_SUCCESS)
3331 smartcard_trace_context_and_two_strings_a_call(log, call);
3332 return SCARD_S_SUCCESS;
3337 UINT32 sz1NdrPtr = 0;
3338 UINT32 sz2NdrPtr = 0;
3340 UINT32 pbContextNdrPtr = 0;
3343 wLog* log = scard_log();
3345 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3347 if (status != SCARD_S_SUCCESS)
3350 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3351 return ERROR_INVALID_DATA;
3352 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3353 return ERROR_INVALID_DATA;
3356 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3357 if (status != SCARD_S_SUCCESS)
3362 status = smartcard_ndr_read_w(log, s, &call->sz1, NDR_PTR_FULL);
3363 if (status != SCARD_S_SUCCESS)
3368 status = smartcard_ndr_read_w(log, s, &call->sz2, NDR_PTR_FULL);
3369 if (status != SCARD_S_SUCCESS)
3372 smartcard_trace_context_and_two_strings_w_call(log, call);
3373 return SCARD_S_SUCCESS;
3378 UINT32 sz1NdrPtr = 0;
3379 UINT32 sz2NdrPtr = 0;
3381 UINT32 pbContextNdrPtr = 0;
3384 wLog* log = scard_log();
3386 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3388 if (status != SCARD_S_SUCCESS)
3391 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3392 return STATUS_BUFFER_TOO_SMALL;
3394 Stream_Read_UINT32(s, call->cBytes);
3395 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3396 return ERROR_INVALID_DATA;
3398 Stream_Read_UINT32(s, call->cReaders);
3399 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3400 return ERROR_INVALID_DATA;
3402 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3403 &(call->handles.hContext));
3404 if (status != SCARD_S_SUCCESS)
3409 status = smartcard_ndr_read_fixed_string_a(log, s, &call->mszCards, call->cBytes,
3411 if (status != SCARD_S_SUCCESS)
3417 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
3418 if (status != SCARD_S_SUCCESS)
3421 smartcard_trace_locate_cards_a_call(log, call);
3422 return SCARD_S_SUCCESS;
3427 UINT32 sz1NdrPtr = 0;
3428 UINT32 sz2NdrPtr = 0;
3430 UINT32 pbContextNdrPtr = 0;
3433 wLog* log = scard_log();
3435 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3437 if (status != SCARD_S_SUCCESS)
3440 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3441 return STATUS_BUFFER_TOO_SMALL;
3443 Stream_Read_UINT32(s, call->cBytes);
3444 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3445 return ERROR_INVALID_DATA;
3447 Stream_Read_UINT32(s, call->cReaders);
3448 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3449 return ERROR_INVALID_DATA;
3451 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3452 &(call->handles.hContext));
3453 if (status != SCARD_S_SUCCESS)
3458 status = smartcard_ndr_read_fixed_string_w(log, s, &call->mszCards, call->cBytes,
3460 if (status != SCARD_S_SUCCESS)
3466 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
3467 if (status != SCARD_S_SUCCESS)
3470 smartcard_trace_locate_cards_w_call(log, call);
3471 return SCARD_S_SUCCESS;
3478 UINT32 pbContextNdrPtr = 0;
3481 wLog* log = scard_log();
3483 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3485 if (status != SCARD_S_SUCCESS)
3487 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3488 if (status != SCARD_S_SUCCESS)
3491 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3492 return STATUS_BUFFER_TOO_SMALL;
3493 Stream_Read_UINT32(s, call->dwAttrId);
3494 Stream_Read_UINT32(s, call->cbAttrLen);
3496 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
3497 return ERROR_INVALID_DATA;
3499 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3500 &(call->handles.hContext));
3501 if (status != SCARD_S_SUCCESS)
3504 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3505 if (status != SCARD_S_SUCCESS)
3512 status = smartcard_ndr_read(log, s, &call->pbAttr, 0, 1, NDR_PTR_SIMPLE);
3513 if (status != SCARD_S_SUCCESS)
3516 smartcard_trace_set_attrib_call(log, call);
3517 return SCARD_S_SUCCESS;
3522 UINT32 rgReaderStatesNdrPtr = 0;
3523 UINT32 rgAtrMasksNdrPtr = 0;
3525 UINT32 pbContextNdrPtr = 0;
3528 wLog* log = scard_log();
3530 call->rgReaderStates = NULL;
3532 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3534 if (status != SCARD_S_SUCCESS)
3537 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3538 return STATUS_BUFFER_TOO_SMALL;
3540 Stream_Read_UINT32(s, call->cAtrs);
3541 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3542 return ERROR_INVALID_DATA;
3544 Stream_Read_UINT32(s, call->cReaders);
3545 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3546 return ERROR_INVALID_DATA;
3548 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3549 &(call->handles.hContext));
3550 if (status != SCARD_S_SUCCESS)
3553 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3555 WLog_Print(log, WLOG_WARN,
3556 "LocateCardsByATRW_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3557 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3558 rgAtrMasksNdrPtr, call->cAtrs);
3559 return STATUS_INVALID_PARAMETER;
3562 if (rgAtrMasksNdrPtr)
3564 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3565 if (status != SCARD_S_SUCCESS)
3569 if (rgReaderStatesNdrPtr)
3572 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
3573 if (status != SCARD_S_SUCCESS)
3577 smartcard_trace_locate_cards_by_atr_w_call(log, call);
3578 return SCARD_S_SUCCESS;
3583 UINT32 mszNdrPtr = 0;
3584 UINT32 contextNdrPtr = 0;
3586 UINT32 pbContextNdrPtr = 0;
3589 wLog* log = scard_log();
3591 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3592 return ERROR_INVALID_DATA;
3594 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3595 &index, &pbContextNdrPtr);
3596 if (status != SCARD_S_SUCCESS)
3599 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3600 return ERROR_INVALID_DATA;
3602 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3603 return STATUS_BUFFER_TOO_SMALL;
3604 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3605 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
3606 Stream_Read_UINT32(s, call->Common.cbDataLen);
3608 call->szLookupName = NULL;
3611 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
3612 if (status != SCARD_S_SUCCESS)
3616 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3617 &call->Common.handles.hContext);
3618 if (status != SCARD_S_SUCCESS)
3623 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3624 if (status != SCARD_S_SUCCESS)
3627 smartcard_trace_read_cache_a_call(log, call);
3628 return SCARD_S_SUCCESS;
3633 UINT32 mszNdrPtr = 0;
3634 UINT32 contextNdrPtr = 0;
3636 UINT32 pbContextNdrPtr = 0;
3639 wLog* log = scard_log();
3641 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3642 return ERROR_INVALID_DATA;
3644 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3645 &index, &pbContextNdrPtr);
3646 if (status != SCARD_S_SUCCESS)
3649 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3650 return ERROR_INVALID_DATA;
3652 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3653 return STATUS_BUFFER_TOO_SMALL;
3654 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3655 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
3656 Stream_Read_UINT32(s, call->Common.cbDataLen);
3658 call->szLookupName = NULL;
3661 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
3662 if (status != SCARD_S_SUCCESS)
3666 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3667 &call->Common.handles.hContext);
3668 if (status != SCARD_S_SUCCESS)
3673 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3674 if (status != SCARD_S_SUCCESS)
3677 smartcard_trace_read_cache_w_call(log, call);
3678 return SCARD_S_SUCCESS;
3683 UINT32 mszNdrPtr = 0;
3684 UINT32 contextNdrPtr = 0;
3685 UINT32 pbDataNdrPtr = 0;
3687 UINT32 pbContextNdrPtr = 0;
3690 wLog* log = scard_log();
3692 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3693 return ERROR_INVALID_DATA;
3695 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3696 &index, &pbContextNdrPtr);
3697 if (status != SCARD_S_SUCCESS)
3700 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3701 return ERROR_INVALID_DATA;
3703 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
3704 return STATUS_BUFFER_TOO_SMALL;
3706 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3707 Stream_Read_UINT32(s, call->Common.cbDataLen);
3709 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
3710 return ERROR_INVALID_DATA;
3712 call->szLookupName = NULL;
3715 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
3716 if (status != SCARD_S_SUCCESS)
3720 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3721 &call->Common.handles.hContext);
3722 if (status != SCARD_S_SUCCESS)
3725 call->Common.CardIdentifier = NULL;
3728 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3729 if (status != SCARD_S_SUCCESS)
3733 call->Common.pbData = NULL;
3736 status = smartcard_ndr_read(log, s, &call->Common.pbData, call->Common.cbDataLen, 1,
3738 if (status != SCARD_S_SUCCESS)
3741 smartcard_trace_write_cache_a_call(log, call);
3742 return SCARD_S_SUCCESS;
3747 UINT32 mszNdrPtr = 0;
3748 UINT32 contextNdrPtr = 0;
3749 UINT32 pbDataNdrPtr = 0;
3751 UINT32 pbContextNdrPtr = 0;
3754 wLog* log = scard_log();
3756 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3757 return ERROR_INVALID_DATA;
3759 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3760 &index, &pbContextNdrPtr);
3761 if (status != SCARD_S_SUCCESS)
3764 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3765 return ERROR_INVALID_DATA;
3767 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
3768 return STATUS_BUFFER_TOO_SMALL;
3769 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3770 Stream_Read_UINT32(s, call->Common.cbDataLen);
3772 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
3773 return ERROR_INVALID_DATA;
3775 call->szLookupName = NULL;
3778 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
3779 if (status != SCARD_S_SUCCESS)
3783 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3784 &call->Common.handles.hContext);
3785 if (status != SCARD_S_SUCCESS)
3788 call->Common.CardIdentifier = NULL;
3791 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3792 if (status != SCARD_S_SUCCESS)
3796 call->Common.pbData = NULL;
3799 status = smartcard_ndr_read(log, s, &call->Common.pbData, call->Common.cbDataLen, 1,
3801 if (status != SCARD_S_SUCCESS)
3804 smartcard_trace_write_cache_w_call(log, call);
3811 wLog* log = scard_log();
3814 UINT32 pbContextNdrPtr = 0;
3816 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3818 if (status != SCARD_S_SUCCESS)
3821 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3822 if (status != SCARD_S_SUCCESS)
3825 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3826 &(call->handles.hContext));
3827 if (status != SCARD_S_SUCCESS)
3829 WLog_Print(log, WLOG_ERROR,
3830 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
3835 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3836 if (status != SCARD_S_SUCCESS)
3837 WLog_Print(log, WLOG_ERROR,
3838 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
3840 smartcard_trace_get_transmit_count_call(log, call);
3847 wLog* log = scard_log();
3848 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
3849 &call->szReaderName);
3855 wLog* log = scard_log();
3856 return smartcard_unpack_common_context_and_string_a(log, s, &call->handles.hContext, &call->sz);
3862 wLog* log = scard_log();
3863 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext, &call->sz);
3869 wLog* log = scard_log();
3870 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
3871 &call->szReaderName);
3877 wLog* log = scard_log();
3878 smartcard_trace_device_type_id_return(log, ret);
3880 if (!Stream_EnsureRemainingCapacity(s, 4))
3882 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3883 return SCARD_F_INTERNAL_ERROR;
3886 Stream_Write_UINT32(s, ret->dwDeviceId);
3888 return ret->ReturnCode;
3894 wLog* log = scard_log();
3897 DWORD cbDataLen = ret->cReaders;
3900 smartcard_trace_locate_cards_return(log, ret);
3901 if (ret->ReturnCode != SCARD_S_SUCCESS)
3903 if (cbDataLen == SCARD_AUTOALLOCATE)
3906 if (!Stream_EnsureRemainingCapacity(s, 4))
3908 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3909 return SCARD_F_INTERNAL_ERROR;
3912 Stream_Write_UINT32(s, cbDataLen);
3913 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3914 return SCARD_E_NO_MEMORY;
3916 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cbDataLen, NDR_PTR_SIMPLE);
3917 if (status != SCARD_S_SUCCESS)
3919 return ret->ReturnCode;
3925 wLog* log = scard_log();
3929 DWORD cbDataLen = ret->cbDataLen;
3930 smartcard_trace_get_reader_icon_return(log, ret);
3931 if (ret->ReturnCode != SCARD_S_SUCCESS)
3933 if (cbDataLen == SCARD_AUTOALLOCATE)
3936 if (!Stream_EnsureRemainingCapacity(s, 4))
3938 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3939 return SCARD_F_INTERNAL_ERROR;
3942 Stream_Write_UINT32(s, cbDataLen);
3943 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3944 return SCARD_E_NO_MEMORY;
3946 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
3947 if (status != SCARD_S_SUCCESS)
3949 return ret->ReturnCode;
3955 wLog* log = scard_log();
3957 smartcard_trace_get_transmit_count_return(log, ret);
3959 if (!Stream_EnsureRemainingCapacity(s, 4))
3961 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3962 return SCARD_F_INTERNAL_ERROR;
3965 Stream_Write_UINT32(s, ret->cTransmitCount);
3967 return ret->ReturnCode;
3973 wLog* log = scard_log();
3977 DWORD cbDataLen = ret->cbDataLen;
3978 smartcard_trace_read_cache_return(log, ret);
3979 if (ret->ReturnCode != SCARD_S_SUCCESS)
3982 if (cbDataLen == SCARD_AUTOALLOCATE)
3985 if (!Stream_EnsureRemainingCapacity(s, 4))
3987 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3988 return SCARD_F_INTERNAL_ERROR;
3991 Stream_Write_UINT32(s, cbDataLen);
3992 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3993 return SCARD_E_NO_MEMORY;
3995 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
3996 if (status != SCARD_S_SUCCESS)
3998 return ret->ReturnCode;