24#include <freerdp/config.h>
27#include <winpr/print.h>
29#include <freerdp/channels/scard.h>
30#include <freerdp/utils/smartcard_pack.h>
31#include "smartcard_pack.h"
33#include <freerdp/log.h>
34#define SCARD_TAG FREERDP_TAG("scard.pack")
36static const DWORD g_LogLevel = WLOG_DEBUG;
38static wLog* scard_log(
void)
40 static wLog* log = NULL;
42 log = WLog_Get(SCARD_TAG);
46#define smartcard_unpack_redir_scard_context(log, s, context, index, ndr) \
47 smartcard_unpack_redir_scard_context_((log), (s), (context), (index), (ndr), __FILE__, \
49#define smartcard_unpack_redir_scard_handle(log, s, context, index) \
50 smartcard_unpack_redir_scard_handle_((log), (s), (context), (index), __FILE__, __func__, \
53static LONG smartcard_unpack_redir_scard_context_(wLog* log,
wStream* s,
55 UINT32* ppbContextNdrPtr,
const char* file,
56 const char* function,
size_t line);
57static LONG smartcard_pack_redir_scard_context(wLog* log,
wStream* s,
60 UINT32* index,
const char* file,
61 const char* function,
size_t line);
62static LONG smartcard_pack_redir_scard_handle(wLog* log,
wStream* s,
64static LONG smartcard_unpack_redir_scard_context_ref(wLog* log,
wStream* s, UINT32 pbContextNdrPtr,
66static LONG smartcard_pack_redir_scard_context_ref(wLog* log,
wStream* s,
69static LONG smartcard_unpack_redir_scard_handle_ref(wLog* log,
wStream* s,
71static LONG smartcard_pack_redir_scard_handle_ref(wLog* log,
wStream* s,
83#define smartcard_ndr_pointer_read(log, s, index, ptr) \
84 smartcard_ndr_pointer_read_((log), (s), (index), (ptr), __FILE__, __func__, __LINE__)
85static BOOL smartcard_ndr_pointer_read_(wLog* log,
wStream* s, UINT32* index, UINT32* ptr,
86 const char* file,
const char* fkt,
size_t line)
88 const UINT32 expect = 0x20000 + (*index) * 4;
93 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
96 Stream_Read_UINT32(s, ndrPtr);
102 if (ptr && (ndrPtr == 0))
104 WLog_Print(log, WLOG_WARN,
105 "[%s:%" PRIuz
"] Read context pointer 0x%08" PRIx32
", expected 0x%08" PRIx32,
106 fkt, line, ndrPtr, expect);
110 (*index) = (*index) + 1;
114static LONG smartcard_ndr_read_ex(wLog* log,
wStream* s, BYTE** data,
size_t min,
115 size_t elementSize, ndr_ptr_t type,
size_t* plen)
139 return STATUS_INVALID_PARAMETER;
142 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, required))
143 return STATUS_BUFFER_TOO_SMALL;
148 Stream_Read_UINT32(s, len);
149 Stream_Read_UINT32(s, offset);
150 Stream_Read_UINT32(s, len2);
151 if (len != offset + len2)
153 WLog_Print(log, WLOG_ERROR,
154 "Invalid data when reading full NDR pointer: total=%" PRIuz
155 ", offset=%" PRIuz
", remaining=%" PRIuz,
157 return STATUS_BUFFER_TOO_SMALL;
161 Stream_Read_UINT32(s, len);
163 if ((len != min) && (min > 0))
165 WLog_Print(log, WLOG_ERROR,
166 "Invalid data when reading simple NDR pointer: total=%" PRIuz
167 ", expected=%" PRIuz,
169 return STATUS_BUFFER_TOO_SMALL;
176 return STATUS_INVALID_PARAMETER;
181 WLog_Print(log, WLOG_ERROR,
182 "Invalid length read from NDR pointer, minimum %" PRIuz
", got %" PRIuz, min,
184 return STATUS_DATA_ERROR;
187 if (len > SIZE_MAX / 2)
188 return STATUS_BUFFER_TOO_SMALL;
190 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(log, s, len, elementSize))
191 return STATUS_BUFFER_TOO_SMALL;
198 r = calloc(len +
sizeof(WCHAR),
sizeof(CHAR));
200 return SCARD_E_NO_MEMORY;
201 Stream_Read(s, r, len);
202 const LONG pad = smartcard_unpack_read_size_align(s, len, 4);
206 return STATUS_INVALID_PARAMETER;
212 return STATUS_SUCCESS;
215static LONG smartcard_ndr_read(wLog* log,
wStream* s, BYTE** data,
size_t min,
size_t elementSize,
218 return smartcard_ndr_read_ex(log, s, data, min, elementSize, type, NULL);
221static BOOL smartcard_ndr_pointer_write(
wStream* s, UINT32* index, DWORD length)
223 const UINT32 ndrPtr = 0x20000 + (*index) * 4;
227 if (!Stream_EnsureRemainingCapacity(s, 4))
232 Stream_Write_UINT32(s, ndrPtr);
233 (*index) = (*index) + 1;
236 Stream_Write_UINT32(s, 0);
240static LONG smartcard_ndr_write(
wStream* s,
const BYTE* data, UINT32 size, UINT32 elementSize,
243 const UINT32 offset = 0;
244 const UINT32 len = size;
245 const UINT32 dataLen = size * elementSize;
249 return SCARD_S_SUCCESS;
263 return SCARD_E_INVALID_PARAMETER;
266 if (!Stream_EnsureRemainingCapacity(s, required + dataLen + 4))
267 return STATUS_BUFFER_TOO_SMALL;
272 Stream_Write_UINT32(s, len);
273 Stream_Write_UINT32(s, offset);
274 Stream_Write_UINT32(s, len);
277 Stream_Write_UINT32(s, len);
282 return SCARD_E_INVALID_PARAMETER;
286 Stream_Write(s, data, dataLen);
288 Stream_Zero(s, dataLen);
289 return smartcard_pack_write_size_align(s, len, 4);
301 WINPR_ASSERT(data || (size == 0));
307 size_t min, ndr_ptr_t type)
318static LONG smartcard_ndr_read_fixed_string_a(wLog* log,
wStream* s, CHAR** data,
size_t min,
327 return smartcard_ndr_read(log, s, u.ppv, min,
sizeof(CHAR), type);
330static LONG smartcard_ndr_read_fixed_string_w(wLog* log,
wStream* s, WCHAR** data,
size_t min,
339 return smartcard_ndr_read(log, s, u.ppv, min,
sizeof(WCHAR), type);
342static LONG smartcard_ndr_read_a(wLog* log,
wStream* s, CHAR** data, ndr_ptr_t type)
350 return smartcard_ndr_read(log, s, u.ppv, 0,
sizeof(CHAR), type);
353static LONG smartcard_ndr_read_w(wLog* log,
wStream* s, WCHAR** data, ndr_ptr_t type)
361 return smartcard_ndr_read(log, s, u.ppv, 0,
sizeof(WCHAR), type);
364static LONG smartcard_ndr_read_u(wLog* log,
wStream* s,
UUID** data)
372 return smartcard_ndr_read(log, s, u.ppv, 1,
sizeof(
UUID), NDR_PTR_FIXED);
375static char* smartcard_convert_string_list(
const void* in,
size_t bytes, BOOL unicode)
396 mszA = ConvertMszWCharNToUtf8Alloc(
string.wz, bytes /
sizeof(WCHAR), &length);
402 mszA = (
char*)calloc(bytes,
sizeof(
char));
405 CopyMemory(mszA,
string.sz, bytes - 1);
414 for (
size_t index = 0; index < length - 1; index++)
416 if (mszA[index] ==
'\0')
423static char* smartcard_msz_dump_a(
const char* msz,
size_t len,
char* buffer,
size_t bufferLen)
426 const char* cur = msz;
428 while ((len > 0) && cur && cur[0] !=
'\0' && (bufferLen > 0))
430 size_t clen = strnlen(cur, len);
431 int rc = _snprintf(buf, bufferLen,
"%s", cur);
432 bufferLen -= (size_t)rc;
441static char* smartcard_msz_dump_w(
const WCHAR* msz,
size_t len,
char* buffer,
size_t bufferLen)
446 char* sz = ConvertMszWCharNToUtf8Alloc(msz, len, &szlen);
450 smartcard_msz_dump_a(sz, szlen, buffer, bufferLen);
455static char* smartcard_array_dump(
const void* pd,
size_t len,
char* buffer,
size_t bufferLen)
457 const BYTE* data = pd;
459 char* start = buffer;
461 WINPR_ASSERT(buffer || (bufferLen == 0));
463 if (!data && (len > 0))
465 (void)_snprintf(buffer, bufferLen,
"{ NULL [%" PRIuz
"] }", len);
469 rc = _snprintf(buffer, bufferLen,
"{ ");
470 if ((rc < 0) || ((
size_t)rc >= bufferLen))
473 bufferLen -= (size_t)rc;
475 for (
size_t x = 0; x < len; x++)
477 rc = _snprintf(buffer, bufferLen,
"%02X", data[x]);
478 if ((rc < 0) || ((
size_t)rc >= bufferLen))
481 bufferLen -= (size_t)rc;
484 rc = _snprintf(buffer, bufferLen,
" }");
485 if ((rc < 0) || ((
size_t)rc >= bufferLen))
492static void smartcard_log_redir_handle(wLog* log,
const REDIR_SCARDHANDLE* pHandle)
494 char buffer[128] = { 0 };
496 WINPR_ASSERT(pHandle);
497 WLog_Print(log, g_LogLevel,
" hContext: %s",
498 smartcard_array_dump(pHandle->pbHandle, pHandle->cbHandle, buffer,
sizeof(buffer)));
503 char buffer[128] = { 0 };
505 WINPR_ASSERT(phContext);
507 log, g_LogLevel,
"hContext: %s",
508 smartcard_array_dump(phContext->pbContext, phContext->cbContext, buffer,
sizeof(buffer)));
511static void smartcard_trace_context_and_string_call_a(wLog* log,
const char* name,
515 if (!WLog_IsLevelActive(log, g_LogLevel))
518 WLog_Print(log, g_LogLevel,
"%s {", name);
519 smartcard_log_context(log, phContext);
520 WLog_Print(log, g_LogLevel,
" sz=%s", sz);
522 WLog_Print(log, g_LogLevel,
"}");
525static void smartcard_trace_context_and_string_call_w(wLog* log,
const char* name,
529 char tmp[1024] = { 0 };
531 if (!WLog_IsLevelActive(log, g_LogLevel))
535 (void)ConvertWCharToUtf8(sz, tmp, ARRAYSIZE(tmp));
537 WLog_Print(log, g_LogLevel,
"%s {", name);
538 smartcard_log_context(log, phContext);
539 WLog_Print(log, g_LogLevel,
" sz=%s", tmp);
540 WLog_Print(log, g_LogLevel,
"}");
543static void smartcard_trace_context_call(wLog* log,
const Context_Call* call,
const char* name)
547 if (!WLog_IsLevelActive(log, g_LogLevel))
550 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
551 smartcard_log_context(log, &call->handles.hContext);
553 WLog_Print(log, g_LogLevel,
"}");
561 if (!WLog_IsLevelActive(log, g_LogLevel))
564 WLog_Print(log, g_LogLevel,
"ListReaderGroups%s_Call {", unicode ?
"W" :
"A");
565 smartcard_log_context(log, &call->handles.hContext);
567 WLog_Print(log, g_LogLevel,
"fmszGroupsIsNULL: %" PRId32
" cchGroups: 0x%08" PRIx32,
568 call->fmszGroupsIsNULL, call->cchGroups);
569 WLog_Print(log, g_LogLevel,
"}");
572static void dump_reader_states_return(wLog* log,
const ReaderState_Return* rgReaderStates,
575 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
576 for (UINT32 index = 0; index < cReaders; index++)
578 char buffer[1024] = { 0 };
581 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
582 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
583 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
584 szCurrentState, readerState->dwCurrentState);
585 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
586 szEventState, readerState->dwEventState);
587 free(szCurrentState);
591 log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { %s }", index,
593 smartcard_array_dump(readerState->rgbAtr, readerState->cbAtr, buffer,
sizeof(buffer)));
600 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
601 for (UINT32 index = 0; index < cReaders; index++)
603 char buffer[1024] = { 0 };
607 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
608 readerState->szReader, readerState->cbAtr);
609 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
610 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
611 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
612 szCurrentState, readerState->dwCurrentState);
613 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
614 szEventState, readerState->dwEventState);
615 free(szCurrentState);
619 log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { %s }", index,
621 smartcard_array_dump(readerState->rgbAtr, readerState->cbAtr, buffer,
sizeof(buffer)));
628 WINPR_ASSERT(rgReaderStates || (cReaders == 0));
629 for (UINT32 index = 0; index < cReaders; index++)
631 char buffer[1024] = { 0 };
634 (void)ConvertWCharToUtf8(readerState->szReader, buffer,
sizeof(buffer));
635 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
636 buffer, readerState->cbAtr);
637 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
638 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
639 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
640 szCurrentState, readerState->dwCurrentState);
641 WLog_Print(log, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
642 szEventState, readerState->dwEventState);
643 free(szCurrentState);
647 log, g_LogLevel,
"\t[%" PRIu32
"]: cbAttr: %" PRIu32
" { %s }", index,
649 smartcard_array_dump(readerState->rgbAtr, readerState->cbAtr, buffer,
sizeof(buffer)));
657 if (!WLog_IsLevelActive(log, g_LogLevel))
660 WLog_Print(log, g_LogLevel,
"GetStatusChangeW_Call {");
661 smartcard_log_context(log, &call->handles.hContext);
663 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
666 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
668 WLog_Print(log, g_LogLevel,
"}");
676 if (!WLog_IsLevelActive(log, g_LogLevel))
679 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
681 WLog_Print(log, g_LogLevel,
"ListReaderGroups%s_Return {", unicode ?
"W" :
"A");
682 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIx32
")",
683 SCardGetErrorString(ret->ReturnCode),
684 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
685 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
686 WLog_Print(log, g_LogLevel,
"}");
690static void smartcard_trace_list_readers_call(wLog* log,
const ListReaders_Call* call, BOOL unicode)
694 if (!WLog_IsLevelActive(log, g_LogLevel))
697 char* mszGroupsA = smartcard_convert_string_list(call->mszGroups, call->cBytes, unicode);
699 WLog_Print(log, g_LogLevel,
"ListReaders%s_Call {", unicode ?
"W" :
"A");
700 smartcard_log_context(log, &call->handles.hContext);
702 WLog_Print(log, g_LogLevel,
703 "cBytes: %" PRIu32
" mszGroups: %s fmszReadersIsNULL: %" PRId32
704 " cchReaders: 0x%08" PRIX32
"",
705 call->cBytes, mszGroupsA, call->fmszReadersIsNULL, call->cchReaders);
706 WLog_Print(log, g_LogLevel,
"}");
711static void smartcard_trace_locate_cards_by_atr_a_call(wLog* log,
716 if (!WLog_IsLevelActive(log, g_LogLevel))
719 WLog_Print(log, g_LogLevel,
"LocateCardsByATRA_Call {");
720 smartcard_log_context(log, &call->handles.hContext);
722 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
724 WLog_Print(log, g_LogLevel,
"}");
727static void smartcard_trace_locate_cards_a_call(wLog* log,
const LocateCardsA_Call* call)
729 char buffer[8192] = { 0 };
733 if (!WLog_IsLevelActive(log, g_LogLevel))
736 WLog_Print(log, g_LogLevel,
"LocateCardsA_Call {");
737 smartcard_log_context(log, &call->handles.hContext);
738 WLog_Print(log, g_LogLevel,
" cBytes=%" PRIu32, call->cBytes);
739 WLog_Print(log, g_LogLevel,
" mszCards=%s",
740 smartcard_msz_dump_a(call->mszCards, call->cBytes, buffer,
sizeof(buffer)));
741 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, call->cReaders);
742 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
744 WLog_Print(log, g_LogLevel,
"}");
747static void smartcard_trace_locate_cards_return(wLog* log,
const LocateCards_Return* ret)
751 if (!WLog_IsLevelActive(log, g_LogLevel))
754 WLog_Print(log, g_LogLevel,
"LocateCards_Return {");
755 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
756 SCardGetErrorString(ret->ReturnCode),
757 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
759 if (ret->ReturnCode == SCARD_S_SUCCESS)
761 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, ret->cReaders);
763 WLog_Print(log, g_LogLevel,
"}");
770 if (!WLog_IsLevelActive(log, g_LogLevel))
773 WLog_Print(log, g_LogLevel,
"GetReaderIcon_Return {");
774 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
775 SCardGetErrorString(ret->ReturnCode),
776 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
778 if (ret->ReturnCode == SCARD_S_SUCCESS)
780 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, ret->cbDataLen);
782 WLog_Print(log, g_LogLevel,
"}");
789 if (!WLog_IsLevelActive(log, g_LogLevel))
792 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Return {");
793 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
794 SCardGetErrorString(ret->ReturnCode),
795 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
797 WLog_Print(log, g_LogLevel,
" cTransmitCount=%" PRIu32, ret->cTransmitCount);
798 WLog_Print(log, g_LogLevel,
"}");
801static void smartcard_trace_read_cache_return(wLog* log,
const ReadCache_Return* ret)
805 if (!WLog_IsLevelActive(log, g_LogLevel))
808 WLog_Print(log, g_LogLevel,
"ReadCache_Return {");
809 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
810 SCardGetErrorString(ret->ReturnCode),
811 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
813 if (ret->ReturnCode == SCARD_S_SUCCESS)
815 char buffer[1024] = { 0 };
816 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, ret->cbDataLen);
817 WLog_Print(log, g_LogLevel,
" cbData: %s",
818 smartcard_array_dump(ret->pbData, ret->cbDataLen, buffer,
sizeof(buffer)));
820 WLog_Print(log, g_LogLevel,
"}");
823static void smartcard_trace_locate_cards_w_call(wLog* log,
const LocateCardsW_Call* call)
826 char buffer[8192] = { 0 };
828 if (!WLog_IsLevelActive(log, g_LogLevel))
831 WLog_Print(log, g_LogLevel,
"LocateCardsW_Call {");
832 smartcard_log_context(log, &call->handles.hContext);
833 WLog_Print(log, g_LogLevel,
" cBytes=%" PRIu32, call->cBytes);
834 WLog_Print(log, g_LogLevel,
" sz2=%s",
835 smartcard_msz_dump_w(call->mszCards, call->cBytes, buffer,
sizeof(buffer)));
836 WLog_Print(log, g_LogLevel,
" cReaders=%" PRIu32, call->cReaders);
837 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
838 WLog_Print(log, g_LogLevel,
"}");
841static void smartcard_trace_list_readers_return(wLog* log,
const ListReaders_Return* ret,
846 if (!WLog_IsLevelActive(log, g_LogLevel))
849 WLog_Print(log, g_LogLevel,
"ListReaders%s_Return {", unicode ?
"W" :
"A");
850 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
851 SCardGetErrorString(ret->ReturnCode),
852 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
854 if (ret->ReturnCode != SCARD_S_SUCCESS)
856 WLog_Print(log, g_LogLevel,
"}");
860 char* mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
862 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
863 WLog_Print(log, g_LogLevel,
"}");
872 if (!WLog_IsLevelActive(log, g_LogLevel))
875 WLog_Print(log, g_LogLevel,
"GetStatusChange%s_Return {", unicode ?
"W" :
"A");
876 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
877 SCardGetErrorString(ret->ReturnCode),
878 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
879 WLog_Print(log, g_LogLevel,
" cReaders: %" PRIu32
"", ret->cReaders);
881 dump_reader_states_return(log, ret->rgReaderStates, ret->cReaders);
883 if (!ret->rgReaderStates && (ret->cReaders > 0))
885 WLog_Print(log, g_LogLevel,
" [INVALID STATE] rgReaderStates=NULL, cReaders=%" PRIu32,
888 else if (ret->ReturnCode != SCARD_S_SUCCESS)
890 WLog_Print(log, g_LogLevel,
" [INVALID RETURN] rgReaderStates, cReaders=%" PRIu32,
895 for (UINT32 index = 0; index < ret->cReaders; index++)
897 char buffer[1024] = { 0 };
899 char* szCurrentState = SCardGetReaderStateString(rgReaderState->dwCurrentState);
900 char* szEventState = SCardGetReaderStateString(rgReaderState->dwEventState);
901 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")",
902 index, szCurrentState, rgReaderState->dwCurrentState);
903 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")",
904 index, szEventState, rgReaderState->dwEventState);
905 WLog_Print(log, g_LogLevel,
" [%" PRIu32
"]: cbAtr: %" PRIu32
" rgbAtr: %s", index,
906 rgReaderState->cbAtr,
907 smartcard_array_dump(rgReaderState->rgbAtr, rgReaderState->cbAtr, buffer,
909 free(szCurrentState);
914 WLog_Print(log, g_LogLevel,
"}");
917static void smartcard_trace_context_and_two_strings_a_call(wLog* log,
922 if (!WLog_IsLevelActive(log, g_LogLevel))
925 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
926 smartcard_log_context(log, &call->handles.hContext);
927 WLog_Print(log, g_LogLevel,
" sz1=%s", call->sz1);
928 WLog_Print(log, g_LogLevel,
" sz2=%s", call->sz2);
929 WLog_Print(log, g_LogLevel,
"}");
932static void smartcard_trace_context_and_two_strings_w_call(wLog* log,
936 char sz1[1024] = { 0 };
937 char sz2[1024] = { 0 };
939 if (!WLog_IsLevelActive(log, g_LogLevel))
942 (void)ConvertWCharToUtf8(call->sz1, sz1, ARRAYSIZE(sz1));
944 (void)ConvertWCharToUtf8(call->sz2, sz2, ARRAYSIZE(sz2));
946 WLog_Print(log, g_LogLevel,
"ContextAndTwoStringW_Call {");
947 smartcard_log_context(log, &call->handles.hContext);
948 WLog_Print(log, g_LogLevel,
" sz1=%s", sz1);
949 WLog_Print(log, g_LogLevel,
" sz2=%s", sz2);
950 WLog_Print(log, g_LogLevel,
"}");
957 if (!WLog_IsLevelActive(log, g_LogLevel))
960 WLog_Print(log, g_LogLevel,
"GetTransmitCount_Call {");
961 smartcard_log_context(log, &call->handles.hContext);
962 smartcard_log_redir_handle(log, &call->handles.hCard);
964 WLog_Print(log, g_LogLevel,
"}");
967static void smartcard_trace_write_cache_a_call(wLog* log,
const WriteCacheA_Call* call)
970 char buffer[1024] = { 0 };
972 if (!WLog_IsLevelActive(log, g_LogLevel))
975 WLog_Print(log, g_LogLevel,
"WriteCacheA_Call {");
977 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
979 smartcard_log_context(log, &call->Common.handles.hContext);
981 log, g_LogLevel,
"..CardIdentifier=%s",
982 smartcard_array_dump(call->Common.CardIdentifier,
sizeof(
UUID), buffer,
sizeof(buffer)));
983 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
984 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
986 log, g_LogLevel,
" pbData=%s",
987 smartcard_array_dump(call->Common.pbData, call->Common.cbDataLen, buffer,
sizeof(buffer)));
988 WLog_Print(log, g_LogLevel,
"}");
991static void smartcard_trace_write_cache_w_call(wLog* log,
const WriteCacheW_Call* call)
994 char tmp[1024] = { 0 };
995 char buffer[1024] = { 0 };
997 if (!WLog_IsLevelActive(log, g_LogLevel))
1000 WLog_Print(log, g_LogLevel,
"WriteCacheW_Call {");
1002 if (call->szLookupName)
1003 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
1004 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
1006 smartcard_log_context(log, &call->Common.handles.hContext);
1008 log, g_LogLevel,
"..CardIdentifier=%s",
1009 smartcard_array_dump(call->Common.CardIdentifier,
sizeof(
UUID), buffer,
sizeof(buffer)));
1010 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1011 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1013 log, g_LogLevel,
" pbData=%s",
1014 smartcard_array_dump(call->Common.pbData, call->Common.cbDataLen, buffer,
sizeof(buffer)));
1015 WLog_Print(log, g_LogLevel,
"}");
1018static void smartcard_trace_read_cache_a_call(wLog* log,
const ReadCacheA_Call* call)
1021 char buffer[1024] = { 0 };
1023 if (!WLog_IsLevelActive(log, g_LogLevel))
1026 WLog_Print(log, g_LogLevel,
"ReadCacheA_Call {");
1028 WLog_Print(log, g_LogLevel,
" szLookupName=%s", call->szLookupName);
1029 smartcard_log_context(log, &call->Common.handles.hContext);
1031 log, g_LogLevel,
"..CardIdentifier=%s",
1032 smartcard_array_dump(call->Common.CardIdentifier,
sizeof(
UUID), buffer,
sizeof(buffer)));
1033 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1034 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1035 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1037 WLog_Print(log, g_LogLevel,
"}");
1040static void smartcard_trace_read_cache_w_call(wLog* log,
const ReadCacheW_Call* call)
1043 char tmp[1024] = { 0 };
1044 char buffer[1024] = { 0 };
1046 if (!WLog_IsLevelActive(log, g_LogLevel))
1049 WLog_Print(log, g_LogLevel,
"ReadCacheW_Call {");
1050 if (call->szLookupName)
1051 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
1052 WLog_Print(log, g_LogLevel,
" szLookupName=%s", tmp);
1054 smartcard_log_context(log, &call->Common.handles.hContext);
1056 log, g_LogLevel,
"..CardIdentifier=%s",
1057 smartcard_array_dump(call->Common.CardIdentifier,
sizeof(
UUID), buffer,
sizeof(buffer)));
1058 WLog_Print(log, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
1059 WLog_Print(log, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
1060 WLog_Print(log, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
1062 WLog_Print(log, g_LogLevel,
"}");
1065static void smartcard_trace_transmit_call(wLog* log,
const Transmit_Call* call)
1068 UINT32 cbExtraBytes = 0;
1069 BYTE* pbExtraBytes = NULL;
1071 if (!WLog_IsLevelActive(log, g_LogLevel))
1074 WLog_Print(log, g_LogLevel,
"Transmit_Call {");
1075 smartcard_log_context(log, &call->handles.hContext);
1076 smartcard_log_redir_handle(log, &call->handles.hCard);
1078 if (call->pioSendPci)
1080 cbExtraBytes = (UINT32)(call->pioSendPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1082 WLog_Print(log, g_LogLevel,
"pioSendPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1083 call->pioSendPci->dwProtocol, cbExtraBytes);
1087 char buffer[1024] = { 0 };
1088 WLog_Print(log, g_LogLevel,
"pbExtraBytes: %s",
1089 smartcard_array_dump(pbExtraBytes, cbExtraBytes, buffer,
sizeof(buffer)));
1094 WLog_Print(log, g_LogLevel,
"pioSendPci: null");
1097 WLog_Print(log, g_LogLevel,
"cbSendLength: %" PRIu32
"", call->cbSendLength);
1099 if (call->pbSendBuffer)
1101 char buffer[1024] = { 0 };
1103 log, g_LogLevel,
"pbSendBuffer: %s",
1104 smartcard_array_dump(call->pbSendBuffer, call->cbSendLength, buffer,
sizeof(buffer)));
1108 WLog_Print(log, g_LogLevel,
"pbSendBuffer: null");
1111 if (call->pioRecvPci)
1113 cbExtraBytes = (UINT32)(call->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1115 WLog_Print(log, g_LogLevel,
"pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1116 call->pioRecvPci->dwProtocol, cbExtraBytes);
1120 char buffer[1024] = { 0 };
1121 WLog_Print(log, g_LogLevel,
"pbExtraBytes: %s",
1122 smartcard_array_dump(pbExtraBytes, cbExtraBytes, buffer,
sizeof(buffer)));
1127 WLog_Print(log, g_LogLevel,
"pioRecvPci: null");
1130 WLog_Print(log, g_LogLevel,
"fpbRecvBufferIsNULL: %" PRId32
" cbRecvLength: %" PRIu32
"",
1131 call->fpbRecvBufferIsNULL, call->cbRecvLength);
1132 WLog_Print(log, g_LogLevel,
"}");
1135static void smartcard_trace_locate_cards_by_atr_w_call(wLog* log,
1140 if (!WLog_IsLevelActive(log, g_LogLevel))
1143 WLog_Print(log, g_LogLevel,
"LocateCardsByATRW_Call {");
1144 smartcard_log_context(log, &call->handles.hContext);
1146 dump_reader_states_w(log, call->rgReaderStates, call->cReaders);
1148 WLog_Print(log, g_LogLevel,
"}");
1151static void smartcard_trace_transmit_return(wLog* log,
const Transmit_Return* ret)
1154 UINT32 cbExtraBytes = 0;
1155 BYTE* pbExtraBytes = NULL;
1157 if (!WLog_IsLevelActive(log, g_LogLevel))
1160 WLog_Print(log, g_LogLevel,
"Transmit_Return {");
1161 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1162 SCardGetErrorString(ret->ReturnCode),
1163 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1165 if (ret->pioRecvPci)
1167 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1169 WLog_Print(log, g_LogLevel,
1170 " pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1171 ret->pioRecvPci->dwProtocol, cbExtraBytes);
1175 char buffer[1024] = { 0 };
1176 WLog_Print(log, g_LogLevel,
" pbExtraBytes: %s",
1177 smartcard_array_dump(pbExtraBytes, cbExtraBytes, buffer,
sizeof(buffer)));
1182 WLog_Print(log, g_LogLevel,
" pioRecvPci: null");
1185 WLog_Print(log, g_LogLevel,
" cbRecvLength: %" PRIu32
"", ret->cbRecvLength);
1187 if (ret->pbRecvBuffer)
1189 char buffer[1024] = { 0 };
1191 log, g_LogLevel,
" pbRecvBuffer: %s",
1192 smartcard_array_dump(ret->pbRecvBuffer, ret->cbRecvLength, buffer,
sizeof(buffer)));
1196 WLog_Print(log, g_LogLevel,
" pbRecvBuffer: null");
1199 WLog_Print(log, g_LogLevel,
"}");
1202static void smartcard_trace_control_return(wLog* log,
const Control_Return* ret)
1206 if (!WLog_IsLevelActive(log, g_LogLevel))
1209 WLog_Print(log, g_LogLevel,
"Control_Return {");
1210 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1211 SCardGetErrorString(ret->ReturnCode),
1212 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1213 WLog_Print(log, g_LogLevel,
" cbOutBufferSize: %" PRIu32
"", ret->cbOutBufferSize);
1215 if (ret->pvOutBuffer)
1217 char buffer[1024] = { 0 };
1219 log, g_LogLevel,
"pvOutBuffer: %s",
1220 smartcard_array_dump(ret->pvOutBuffer, ret->cbOutBufferSize, buffer,
sizeof(buffer)));
1224 WLog_Print(log, g_LogLevel,
"pvOutBuffer: null");
1227 WLog_Print(log, g_LogLevel,
"}");
1230static void smartcard_trace_control_call(wLog* log,
const Control_Call* call)
1234 if (!WLog_IsLevelActive(log, g_LogLevel))
1237 WLog_Print(log, g_LogLevel,
"Control_Call {");
1238 smartcard_log_context(log, &call->handles.hContext);
1239 smartcard_log_redir_handle(log, &call->handles.hCard);
1241 WLog_Print(log, g_LogLevel,
1242 "dwControlCode: 0x%08" PRIX32
" cbInBufferSize: %" PRIu32
1243 " fpvOutBufferIsNULL: %" PRId32
" cbOutBufferSize: %" PRIu32
"",
1244 call->dwControlCode, call->cbInBufferSize, call->fpvOutBufferIsNULL,
1245 call->cbOutBufferSize);
1247 if (call->pvInBuffer)
1249 char buffer[1024] = { 0 };
1251 log, WLOG_DEBUG,
"pbInBuffer: %s",
1252 smartcard_array_dump(call->pvInBuffer, call->cbInBufferSize, buffer,
sizeof(buffer)));
1256 WLog_Print(log, g_LogLevel,
"pvInBuffer: null");
1259 WLog_Print(log, g_LogLevel,
"}");
1262static void smartcard_trace_set_attrib_call(wLog* log,
const SetAttrib_Call* call)
1265 char buffer[8192] = { 0 };
1267 if (!WLog_IsLevelActive(log, g_LogLevel))
1270 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1271 smartcard_log_context(log, &call->handles.hContext);
1272 smartcard_log_redir_handle(log, &call->handles.hCard);
1273 WLog_Print(log, g_LogLevel,
"dwAttrId: 0x%08" PRIX32, call->dwAttrId);
1274 WLog_Print(log, g_LogLevel,
"cbAttrLen: 0x%08" PRIx32, call->cbAttrLen);
1275 WLog_Print(log, g_LogLevel,
"pbAttr: %s",
1276 smartcard_array_dump(call->pbAttr, call->cbAttrLen, buffer,
sizeof(buffer)));
1277 WLog_Print(log, g_LogLevel,
"}");
1280static void smartcard_trace_get_attrib_return(wLog* log,
const GetAttrib_Return* ret,
1284 char buffer[1024] = { 0 };
1286 if (!WLog_IsLevelActive(log, g_LogLevel))
1289 WLog_Print(log, g_LogLevel,
"GetAttrib_Return {");
1290 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1291 SCardGetErrorString(ret->ReturnCode),
1292 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1293 WLog_Print(log, g_LogLevel,
" dwAttrId: %s (0x%08" PRIX32
") cbAttrLen: 0x%08" PRIX32
"",
1294 SCardGetAttributeString(dwAttrId), dwAttrId, ret->cbAttrLen);
1295 WLog_Print(log, g_LogLevel,
" %s",
1296 smartcard_array_dump(ret->pbAttr, ret->cbAttrLen, buffer,
sizeof(buffer)));
1298 WLog_Print(log, g_LogLevel,
"}");
1301static void smartcard_trace_get_attrib_call(wLog* log,
const GetAttrib_Call* call)
1305 if (!WLog_IsLevelActive(log, g_LogLevel))
1308 WLog_Print(log, g_LogLevel,
"GetAttrib_Call {");
1309 smartcard_log_context(log, &call->handles.hContext);
1310 smartcard_log_redir_handle(log, &call->handles.hCard);
1312 WLog_Print(log, g_LogLevel,
1313 "dwAttrId: %s (0x%08" PRIX32
") fpbAttrIsNULL: %" PRId32
" cbAttrLen: 0x%08" PRIX32
1315 SCardGetAttributeString(call->dwAttrId), call->dwAttrId, call->fpbAttrIsNULL,
1317 WLog_Print(log, g_LogLevel,
"}");
1320static void smartcard_trace_status_call(wLog* log,
const Status_Call* call, BOOL unicode)
1324 if (!WLog_IsLevelActive(log, g_LogLevel))
1327 WLog_Print(log, g_LogLevel,
"Status%s_Call {", unicode ?
"W" :
"A");
1328 smartcard_log_context(log, &call->handles.hContext);
1329 smartcard_log_redir_handle(log, &call->handles.hCard);
1331 WLog_Print(log, g_LogLevel,
1332 "fmszReaderNamesIsNULL: %" PRId32
" cchReaderLen: %" PRIu32
" cbAtrLen: %" PRIu32
"",
1333 call->fmszReaderNamesIsNULL, call->cchReaderLen, call->cbAtrLen);
1334 WLog_Print(log, g_LogLevel,
"}");
1337static void smartcard_trace_status_return(wLog* log,
const Status_Return* ret, BOOL unicode)
1340 char* mszReaderNamesA = NULL;
1341 char buffer[1024] = { 0 };
1344 if (!WLog_IsLevelActive(log, g_LogLevel))
1346 cBytes = ret->cBytes;
1347 if (ret->ReturnCode != SCARD_S_SUCCESS)
1349 if (cBytes == SCARD_AUTOALLOCATE)
1351 mszReaderNamesA = smartcard_convert_string_list(ret->mszReaderNames, cBytes, unicode);
1353 WLog_Print(log, g_LogLevel,
"Status%s_Return {", unicode ?
"W" :
"A");
1354 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1355 SCardGetErrorString(ret->ReturnCode),
1356 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1357 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
") dwProtocol: %s (0x%08" PRIX32
")",
1358 SCardGetCardStateString(ret->dwState), ret->dwState,
1359 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1361 WLog_Print(log, g_LogLevel,
" cBytes: %" PRIu32
" mszReaderNames: %s", ret->cBytes,
1364 WLog_Print(log, g_LogLevel,
" cbAtrLen: %" PRIu32
" pbAtr: %s", ret->cbAtrLen,
1365 smartcard_array_dump(ret->pbAtr, ret->cbAtrLen, buffer,
sizeof(buffer)));
1366 WLog_Print(log, g_LogLevel,
"}");
1367 free(mszReaderNamesA);
1370static void smartcard_trace_state_return(wLog* log,
const State_Return* ret)
1373 char buffer[1024] = { 0 };
1376 if (!WLog_IsLevelActive(log, g_LogLevel))
1379 state = SCardGetReaderStateString(ret->dwState);
1380 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1381 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1382 SCardGetErrorString(ret->ReturnCode),
1383 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1384 WLog_Print(log, g_LogLevel,
" dwState: %s (0x%08" PRIX32
")", state, ret->dwState);
1385 WLog_Print(log, g_LogLevel,
" dwProtocol: %s (0x%08" PRIX32
")",
1386 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1387 WLog_Print(log, g_LogLevel,
" cbAtrLen: (0x%08" PRIX32
")", ret->cbAtrLen);
1388 WLog_Print(log, g_LogLevel,
" rgAtr: %s",
1389 smartcard_array_dump(ret->rgAtr,
sizeof(ret->rgAtr), buffer,
sizeof(buffer)));
1390 WLog_Print(log, g_LogLevel,
"}");
1394static void smartcard_trace_reconnect_return(wLog* log,
const Reconnect_Return* ret)
1398 if (!WLog_IsLevelActive(log, g_LogLevel))
1401 WLog_Print(log, g_LogLevel,
"Reconnect_Return {");
1402 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1403 SCardGetErrorString(ret->ReturnCode),
1404 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1405 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1406 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1407 WLog_Print(log, g_LogLevel,
"}");
1410static void smartcard_trace_connect_a_call(wLog* log,
const ConnectA_Call* call)
1414 if (!WLog_IsLevelActive(log, g_LogLevel))
1417 WLog_Print(log, g_LogLevel,
"ConnectA_Call {");
1418 smartcard_log_context(log, &call->Common.handles.hContext);
1420 WLog_Print(log, g_LogLevel,
1421 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1422 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1423 call->szReader, SCardGetShareModeString(call->Common.dwShareMode),
1424 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1425 call->Common.dwPreferredProtocols);
1426 WLog_Print(log, g_LogLevel,
"}");
1429static void smartcard_trace_connect_w_call(wLog* log,
const ConnectW_Call* call)
1432 char szReaderA[1024] = { 0 };
1434 if (!WLog_IsLevelActive(log, g_LogLevel))
1438 (void)ConvertWCharToUtf8(call->szReader, szReaderA, ARRAYSIZE(szReaderA));
1439 WLog_Print(log, g_LogLevel,
"ConnectW_Call {");
1440 smartcard_log_context(log, &call->Common.handles.hContext);
1442 WLog_Print(log, g_LogLevel,
1443 "szReader: %s dwShareMode: %s (0x%08" PRIX32
1444 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
1445 szReaderA, SCardGetShareModeString(call->Common.dwShareMode),
1446 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1447 call->Common.dwPreferredProtocols);
1448 WLog_Print(log, g_LogLevel,
"}");
1451static void smartcard_trace_hcard_and_disposition_call(wLog* log,
1457 if (!WLog_IsLevelActive(log, g_LogLevel))
1460 WLog_Print(log, g_LogLevel,
"%s_Call {", name);
1461 smartcard_log_context(log, &call->handles.hContext);
1462 smartcard_log_redir_handle(log, &call->handles.hCard);
1464 WLog_Print(log, g_LogLevel,
"dwDisposition: %s (0x%08" PRIX32
")",
1465 SCardGetDispositionString(call->dwDisposition), call->dwDisposition);
1466 WLog_Print(log, g_LogLevel,
"}");
1473 if (!WLog_IsLevelActive(log, g_LogLevel))
1476 WLog_Print(log, g_LogLevel,
"EstablishContext_Call {");
1477 WLog_Print(log, g_LogLevel,
"dwScope: %s (0x%08" PRIX32
")", SCardGetScopeString(call->dwScope),
1479 WLog_Print(log, g_LogLevel,
"}");
1486 if (!WLog_IsLevelActive(log, g_LogLevel))
1489 WLog_Print(log, g_LogLevel,
"EstablishContext_Return {");
1490 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1491 SCardGetErrorString(ret->ReturnCode),
1492 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1493 smartcard_log_context(log, &ret->hContext);
1495 WLog_Print(log, g_LogLevel,
"}");
1498void smartcard_trace_long_return(
const Long_Return* ret,
const char* name)
1500 wLog* log = scard_log();
1501 smartcard_trace_long_return_int(log, ret, name);
1504void smartcard_trace_long_return_int(wLog* log,
const Long_Return* ret,
const char* name)
1508 if (!WLog_IsLevelActive(log, g_LogLevel))
1511 WLog_Print(log, g_LogLevel,
"%s_Return {", name);
1512 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1513 SCardGetErrorString(ret->ReturnCode),
1514 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1515 WLog_Print(log, g_LogLevel,
"}");
1518static void smartcard_trace_connect_return(wLog* log,
const Connect_Return* ret)
1522 if (!WLog_IsLevelActive(log, g_LogLevel))
1525 WLog_Print(log, g_LogLevel,
"Connect_Return {");
1526 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1527 SCardGetErrorString(ret->ReturnCode),
1528 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1529 smartcard_log_context(log, &ret->hContext);
1530 smartcard_log_redir_handle(log, &ret->hCard);
1532 WLog_Print(log, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1533 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1534 WLog_Print(log, g_LogLevel,
"}");
1537static void smartcard_trace_reconnect_call(wLog* log,
const Reconnect_Call* call)
1541 if (!WLog_IsLevelActive(log, g_LogLevel))
1544 WLog_Print(log, g_LogLevel,
"Reconnect_Call {");
1545 smartcard_log_context(log, &call->handles.hContext);
1546 smartcard_log_redir_handle(log, &call->handles.hCard);
1548 WLog_Print(log, g_LogLevel,
1549 "dwShareMode: %s (0x%08" PRIX32
") dwPreferredProtocols: %s (0x%08" PRIX32
1550 ") dwInitialization: %s (0x%08" PRIX32
")",
1551 SCardGetShareModeString(call->dwShareMode), call->dwShareMode,
1552 SCardGetProtocolString(call->dwPreferredProtocols), call->dwPreferredProtocols,
1553 SCardGetDispositionString(call->dwInitialization), call->dwInitialization);
1554 WLog_Print(log, g_LogLevel,
"}");
1561 if (!WLog_IsLevelActive(log, g_LogLevel))
1564 WLog_Print(log, g_LogLevel,
"GetDeviceTypeId_Return {");
1565 WLog_Print(log, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1566 SCardGetErrorString(ret->ReturnCode),
1567 WINPR_CXX_COMPAT_CAST(UINT32, ret->ReturnCode));
1568 WLog_Print(log, g_LogLevel,
" dwDeviceId=%08" PRIx32, ret->dwDeviceId);
1570 WLog_Print(log, g_LogLevel,
"}");
1573static LONG smartcard_unpack_common_context_and_string_a(wLog* log,
wStream* s,
1575 CHAR** pszReaderName)
1578 UINT32 pbContextNdrPtr = 0;
1579 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1580 if (status != SCARD_S_SUCCESS)
1583 if (!smartcard_ndr_pointer_read(log, s, &index, NULL))
1584 return ERROR_INVALID_DATA;
1586 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1587 if (status != SCARD_S_SUCCESS)
1590 status = smartcard_ndr_read_a(log, s, pszReaderName, NDR_PTR_FULL);
1591 if (status != SCARD_S_SUCCESS)
1594 smartcard_trace_context_and_string_call_a(log, __func__, phContext, *pszReaderName);
1595 return SCARD_S_SUCCESS;
1598static LONG smartcard_unpack_common_context_and_string_w(wLog* log,
wStream* s,
1600 WCHAR** pszReaderName)
1603 UINT32 pbContextNdrPtr = 0;
1605 LONG status = smartcard_unpack_redir_scard_context(log, s, phContext, &index, &pbContextNdrPtr);
1606 if (status != SCARD_S_SUCCESS)
1609 if (!smartcard_ndr_pointer_read(log, s, &index, NULL))
1610 return ERROR_INVALID_DATA;
1612 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, phContext);
1613 if (status != SCARD_S_SUCCESS)
1616 status = smartcard_ndr_read_w(log, s, pszReaderName, NDR_PTR_FULL);
1617 if (status != SCARD_S_SUCCESS)
1620 smartcard_trace_context_and_string_call_w(log, __func__, phContext, *pszReaderName);
1621 return SCARD_S_SUCCESS;
1624LONG smartcard_unpack_common_type_header(
wStream* s)
1626 wLog* log = scard_log();
1629 UINT8 endianness = 0;
1630 UINT16 commonHeaderLength = 0;
1632 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1633 return STATUS_BUFFER_TOO_SMALL;
1636 Stream_Read_UINT8(s, version);
1637 Stream_Read_UINT8(s, endianness);
1638 Stream_Read_UINT16(s, commonHeaderLength);
1639 Stream_Read_UINT32(s, filler);
1643 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Version %" PRIu8
"", version);
1644 return STATUS_INVALID_PARAMETER;
1647 if (endianness != 0x10)
1649 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader Endianness %" PRIu8
"",
1651 return STATUS_INVALID_PARAMETER;
1654 if (commonHeaderLength != 8)
1656 WLog_Print(log, WLOG_WARN,
"Unsupported CommonTypeHeader CommonHeaderLength %" PRIu16
"",
1657 commonHeaderLength);
1658 return STATUS_INVALID_PARAMETER;
1661 if (filler != 0xCCCCCCCC)
1663 WLog_Print(log, WLOG_WARN,
"Unexpected CommonTypeHeader Filler 0x%08" PRIX32
"", filler);
1664 return STATUS_INVALID_PARAMETER;
1667 return SCARD_S_SUCCESS;
1670void smartcard_pack_common_type_header(
wStream* s)
1672 Stream_Write_UINT8(s, 1);
1673 Stream_Write_UINT8(s, 0x10);
1674 Stream_Write_UINT16(s, 8);
1675 Stream_Write_UINT32(s, 0xCCCCCCCC);
1678LONG smartcard_unpack_private_type_header(
wStream* s)
1680 wLog* log = scard_log();
1682 UINT32 objectBufferLength = 0;
1684 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
1685 return STATUS_BUFFER_TOO_SMALL;
1687 Stream_Read_UINT32(s, objectBufferLength);
1688 Stream_Read_UINT32(s, filler);
1690 if (filler != 0x00000000)
1692 WLog_Print(log, WLOG_WARN,
"Unexpected PrivateTypeHeader Filler 0x%08" PRIX32
"", filler);
1693 return STATUS_INVALID_PARAMETER;
1696 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, objectBufferLength))
1697 return STATUS_INVALID_PARAMETER;
1699 return SCARD_S_SUCCESS;
1702void smartcard_pack_private_type_header(
wStream* s, UINT32 objectBufferLength)
1704 Stream_Write_UINT32(s, objectBufferLength);
1705 Stream_Write_UINT32(s, 0x00000000);
1708LONG smartcard_unpack_read_size_align(
wStream* s,
size_t size, UINT32 alignment)
1710 const size_t padsize = (size + alignment - 1) & ~(alignment - 1);
1711 const size_t pad = padsize - size;
1715 if (!Stream_SafeSeek(s, pad))
1722LONG smartcard_pack_write_size_align(
wStream* s,
size_t size, UINT32 alignment)
1724 const size_t padsize = (size + alignment - 1) & ~(alignment - 1);
1725 const size_t pad = padsize - size;
1729 if (!Stream_EnsureRemainingCapacity(s, pad))
1731 wLog* log = scard_log();
1732 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
1733 return SCARD_F_INTERNAL_ERROR;
1736 Stream_Zero(s, pad);
1739 return SCARD_S_SUCCESS;
1744 SCARDCONTEXT hContext = { 0 };
1746 WINPR_ASSERT(context);
1747 if ((context->cbContext !=
sizeof(ULONG_PTR)) && (context->cbContext != 0))
1749 wLog* log = scard_log();
1750 WLog_Print(log, WLOG_WARN,
1751 "REDIR_SCARDCONTEXT does not match native size: Actual: %" PRIu32
1752 ", Expected: %" PRIuz
"",
1753 context->cbContext,
sizeof(ULONG_PTR));
1757 if (context->cbContext)
1758 CopyMemory(&hContext, &(context->pbContext), context->cbContext);
1763void smartcard_scard_context_native_to_redir(
REDIR_SCARDCONTEXT* context, SCARDCONTEXT hContext)
1765 WINPR_ASSERT(context);
1767 context->cbContext =
sizeof(ULONG_PTR);
1768 CopyMemory(&(context->pbContext), &hContext, context->cbContext);
1773 SCARDHANDLE hCard = 0;
1775 WINPR_ASSERT(handle);
1776 if (handle->cbHandle == 0)
1779 if (handle->cbHandle !=
sizeof(ULONG_PTR))
1781 wLog* log = scard_log();
1782 WLog_Print(log, WLOG_WARN,
1783 "REDIR_SCARDHANDLE does not match native size: Actual: %" PRIu32
1784 ", Expected: %" PRIuz
"",
1785 handle->cbHandle,
sizeof(ULONG_PTR));
1789 if (handle->cbHandle)
1790 CopyMemory(&hCard, &(handle->pbHandle), handle->cbHandle);
1795void smartcard_scard_handle_native_to_redir(
REDIR_SCARDHANDLE* handle, SCARDHANDLE hCard)
1797 WINPR_ASSERT(handle);
1799 handle->cbHandle =
sizeof(ULONG_PTR);
1800 CopyMemory(&(handle->pbHandle), &hCard, handle->cbHandle);
1803#define smartcard_context_supported(log, size) \
1804 smartcard_context_supported_((log), (size), __FILE__, __func__, __LINE__)
1805static LONG smartcard_context_supported_(wLog* log, uint32_t size,
const char* file,
1806 const char* fkt,
size_t line)
1813 return SCARD_S_SUCCESS;
1816 const uint32_t level = WLOG_WARN;
1817 if (WLog_IsLevelActive(log, level))
1819 WLog_PrintTextMessage(log, level, line, file, fkt,
1820 "REDIR_SCARDCONTEXT length is not 0, 4 or 8: %" PRIu32
"",
1823 return STATUS_INVALID_PARAMETER;
1829 UINT32* index, UINT32* ppbContextNdrPtr,
1830 const char* file,
const char* function,
size_t line)
1832 UINT32 pbContextNdrPtr = 0;
1835 WINPR_ASSERT(context);
1839 if (!Stream_CheckAndLogRequiredLengthWLogEx(log, WLOG_WARN, s, 4, 1,
"%s(%s:%" PRIuz
")", file,
1841 return STATUS_BUFFER_TOO_SMALL;
1843 const LONG status = smartcard_context_supported_(log, context->cbContext, file, function, line);
1844 if (status != SCARD_S_SUCCESS)
1847 Stream_Read_UINT32(s, context->cbContext);
1849 if (!smartcard_ndr_pointer_read_(log, s, index, &pbContextNdrPtr, file, function, line))
1850 return ERROR_INVALID_DATA;
1852 if (((context->cbContext == 0) && pbContextNdrPtr) ||
1853 ((context->cbContext != 0) && !pbContextNdrPtr))
1855 WLog_Print(log, WLOG_WARN,
1856 "REDIR_SCARDCONTEXT cbContext (%" PRIu32
") pbContextNdrPtr (%" PRIu32
1858 context->cbContext, pbContextNdrPtr);
1859 return STATUS_INVALID_PARAMETER;
1862 if (!Stream_CheckAndLogRequiredLengthWLogEx(log, WLOG_WARN, s, context->cbContext, 1,
1863 "%s(%s:%" PRIuz
")", file, function, line))
1864 return STATUS_INVALID_PARAMETER;
1866 *ppbContextNdrPtr = pbContextNdrPtr;
1867 return SCARD_S_SUCCESS;
1870LONG smartcard_pack_redir_scard_context(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1873 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
1875 WINPR_ASSERT(context);
1876 if (context->cbContext != 0)
1878 Stream_Write_UINT32(s, context->cbContext);
1879 Stream_Write_UINT32(s, pbContextNdrPtr);
1880 *index = *index + 1;
1885 return SCARD_S_SUCCESS;
1888LONG smartcard_unpack_redir_scard_context_ref(wLog* log,
wStream* s,
1889 WINPR_ATTR_UNUSED UINT32 pbContextNdrPtr,
1894 WINPR_ASSERT(context);
1895 if (context->cbContext == 0)
1896 return SCARD_S_SUCCESS;
1898 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1899 return STATUS_BUFFER_TOO_SMALL;
1901 Stream_Read_UINT32(s, length);
1903 if (length != context->cbContext)
1905 WLog_Print(log, WLOG_WARN,
1906 "REDIR_SCARDCONTEXT length (%" PRIu32
") cbContext (%" PRIu32
") mismatch",
1907 length, context->cbContext);
1908 return STATUS_INVALID_PARAMETER;
1911 const LONG status = smartcard_context_supported(log, context->cbContext);
1912 if (status != SCARD_S_SUCCESS)
1915 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, context->cbContext))
1916 return STATUS_BUFFER_TOO_SMALL;
1918 if (context->cbContext)
1919 Stream_Read(s, &(context->pbContext), context->cbContext);
1921 ZeroMemory(&(context->pbContext),
sizeof(context->pbContext));
1923 return SCARD_S_SUCCESS;
1926LONG smartcard_pack_redir_scard_context_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1929 WINPR_ASSERT(context);
1930 Stream_Write_UINT32(s, context->cbContext);
1932 if (context->cbContext)
1934 Stream_Write(s, &(context->pbContext), context->cbContext);
1937 return SCARD_S_SUCCESS;
1941 UINT32* index,
const char* file,
const char* function,
1944 WINPR_ASSERT(handle);
1947 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1948 return STATUS_BUFFER_TOO_SMALL;
1950 Stream_Read_UINT32(s, handle->cbHandle);
1952 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, handle->cbHandle))
1953 return STATUS_BUFFER_TOO_SMALL;
1955 if (!smartcard_ndr_pointer_read_(log, s, index, NULL, file, function, line))
1956 return ERROR_INVALID_DATA;
1958 return SCARD_S_SUCCESS;
1961LONG smartcard_pack_redir_scard_handle(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
1964 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
1966 WINPR_ASSERT(handle);
1967 if (handle->cbHandle != 0)
1969 Stream_Write_UINT32(s, handle->cbHandle);
1970 Stream_Write_UINT32(s, pbContextNdrPtr);
1971 *index = *index + 1;
1975 return SCARD_S_SUCCESS;
1982 WINPR_ASSERT(handle);
1983 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
1984 return STATUS_BUFFER_TOO_SMALL;
1986 Stream_Read_UINT32(s, length);
1988 if (length != handle->cbHandle)
1990 WLog_Print(log, WLOG_WARN,
1991 "REDIR_SCARDHANDLE length (%" PRIu32
") cbHandle (%" PRIu32
") mismatch", length,
1993 return STATUS_INVALID_PARAMETER;
1996 if ((handle->cbHandle != 4) && (handle->cbHandle != 8))
1998 WLog_Print(log, WLOG_WARN,
"REDIR_SCARDHANDLE length is not 4 or 8: %" PRIu32
"",
2000 return STATUS_INVALID_PARAMETER;
2003 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, handle->cbHandle))
2004 return STATUS_BUFFER_TOO_SMALL;
2006 if (handle->cbHandle)
2007 Stream_Read(s, &(handle->pbHandle), handle->cbHandle);
2009 return SCARD_S_SUCCESS;
2012LONG smartcard_pack_redir_scard_handle_ref(WINPR_ATTR_UNUSED wLog* log,
wStream* s,
2015 WINPR_ASSERT(handle);
2016 Stream_Write_UINT32(s, handle->cbHandle);
2018 if (handle->cbHandle)
2019 Stream_Write(s, &(handle->pbHandle), handle->cbHandle);
2021 return SCARD_S_SUCCESS;
2027 wLog* log = scard_log();
2029 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2030 return STATUS_BUFFER_TOO_SMALL;
2032 Stream_Read_UINT32(s, call->dwScope);
2033 smartcard_trace_establish_context_call(log, call);
2034 return SCARD_S_SUCCESS;
2040 wLog* log = scard_log();
2044 smartcard_trace_establish_context_return(log, ret);
2045 if (ret->ReturnCode != SCARD_S_SUCCESS)
2046 return ret->ReturnCode;
2048 status = smartcard_pack_redir_scard_context(log, s, &(ret->hContext), &index);
2049 if (status != SCARD_S_SUCCESS)
2052 return smartcard_pack_redir_scard_context_ref(log, s, &(ret->hContext));
2058 UINT32 pbContextNdrPtr = 0;
2059 wLog* log = scard_log();
2062 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2064 if (status != SCARD_S_SUCCESS)
2067 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2068 &(call->handles.hContext));
2069 if (status != SCARD_S_SUCCESS)
2070 WLog_Print(log, WLOG_ERROR,
2071 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2074 smartcard_trace_context_call(log, call, name);
2081 UINT32 pbContextNdrPtr = 0;
2082 wLog* log = scard_log();
2085 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2088 if (status != SCARD_S_SUCCESS)
2091 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2092 return STATUS_BUFFER_TOO_SMALL;
2094 Stream_Read_INT32(s, call->fmszGroupsIsNULL);
2095 Stream_Read_UINT32(s, call->cchGroups);
2096 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2097 &(call->handles.hContext));
2099 if (status != SCARD_S_SUCCESS)
2102 smartcard_trace_list_reader_groups_call(log, call, unicode);
2103 return SCARD_S_SUCCESS;
2110 wLog* log = scard_log();
2112 DWORD cBytes = ret->cBytes;
2115 smartcard_trace_list_reader_groups_return(log, ret, unicode);
2116 if (ret->ReturnCode != SCARD_S_SUCCESS)
2118 if (cBytes == SCARD_AUTOALLOCATE)
2121 if (!Stream_EnsureRemainingCapacity(s, 4))
2122 return SCARD_E_NO_MEMORY;
2124 Stream_Write_UINT32(s, cBytes);
2125 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
2126 return SCARD_E_NO_MEMORY;
2128 status = smartcard_ndr_write(s, ret->msz, cBytes, 1, NDR_PTR_SIMPLE);
2129 if (status != SCARD_S_SUCCESS)
2131 return ret->ReturnCode;
2137 UINT32 mszGroupsNdrPtr = 0;
2138 UINT32 pbContextNdrPtr = 0;
2139 wLog* log = scard_log();
2142 call->mszGroups = NULL;
2144 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2146 if (status != SCARD_S_SUCCESS)
2149 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2150 return STATUS_BUFFER_TOO_SMALL;
2152 Stream_Read_UINT32(s, call->cBytes);
2153 if (!smartcard_ndr_pointer_read(log, s, &index, &mszGroupsNdrPtr))
2154 return ERROR_INVALID_DATA;
2156 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2157 return STATUS_BUFFER_TOO_SMALL;
2158 Stream_Read_INT32(s, call->fmszReadersIsNULL);
2159 Stream_Read_UINT32(s, call->cchReaders);
2161 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2162 &(call->handles.hContext));
2163 if (status != SCARD_S_SUCCESS)
2166 if (mszGroupsNdrPtr)
2168 status = smartcard_ndr_read(log, s, &call->mszGroups, call->cBytes, 1, NDR_PTR_SIMPLE);
2169 if (status != SCARD_S_SUCCESS)
2173 smartcard_trace_list_readers_call(log, call, unicode);
2174 return SCARD_S_SUCCESS;
2180 wLog* log = scard_log();
2183 UINT32 size = ret->cBytes;
2185 smartcard_trace_list_readers_return(log, ret, unicode);
2186 if (ret->ReturnCode != SCARD_S_SUCCESS)
2189 if (!Stream_EnsureRemainingCapacity(s, 4))
2191 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
2192 return SCARD_F_INTERNAL_ERROR;
2195 Stream_Write_UINT32(s, size);
2196 if (!smartcard_ndr_pointer_write(s, &index, size))
2197 return SCARD_E_NO_MEMORY;
2199 status = smartcard_ndr_write(s, ret->msz, size, 1, NDR_PTR_SIMPLE);
2200 if (status != SCARD_S_SUCCESS)
2202 return ret->ReturnCode;
2206 UINT32* index, UINT32* ppbContextNdrPtr)
2208 WINPR_ASSERT(common);
2209 LONG status = smartcard_unpack_redir_scard_context(log, s, &(common->handles.hContext), index,
2211 if (status != SCARD_S_SUCCESS)
2214 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2215 return STATUS_BUFFER_TOO_SMALL;
2217 Stream_Read_UINT32(s, common->dwShareMode);
2218 Stream_Read_UINT32(s, common->dwPreferredProtocols);
2219 return SCARD_S_SUCCESS;
2226 UINT32 pbContextNdrPtr = 0;
2229 wLog* log = scard_log();
2231 call->szReader = NULL;
2233 if (!smartcard_ndr_pointer_read(log, s, &index, NULL))
2234 return ERROR_INVALID_DATA;
2236 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2237 if (status != SCARD_S_SUCCESS)
2239 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2244 status = smartcard_ndr_read_a(log, s, &call->szReader, NDR_PTR_FULL);
2245 if (status != SCARD_S_SUCCESS)
2248 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2249 &(call->Common.handles.hContext));
2250 if (status != SCARD_S_SUCCESS)
2251 WLog_Print(log, WLOG_ERROR,
2252 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2255 smartcard_trace_connect_a_call(log, call);
2263 UINT32 pbContextNdrPtr = 0;
2266 wLog* log = scard_log();
2267 call->szReader = NULL;
2269 if (!smartcard_ndr_pointer_read(log, s, &index, NULL))
2270 return ERROR_INVALID_DATA;
2272 status = smartcard_unpack_connect_common(log, s, &(call->Common), &index, &pbContextNdrPtr);
2273 if (status != SCARD_S_SUCCESS)
2275 WLog_Print(log, WLOG_ERROR,
"smartcard_unpack_connect_common failed with error %" PRId32
"",
2280 status = smartcard_ndr_read_w(log, s, &call->szReader, NDR_PTR_FULL);
2281 if (status != SCARD_S_SUCCESS)
2284 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2285 &(call->Common.handles.hContext));
2286 if (status != SCARD_S_SUCCESS)
2287 WLog_Print(log, WLOG_ERROR,
2288 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2291 smartcard_trace_connect_w_call(log, call);
2301 wLog* log = scard_log();
2302 smartcard_trace_connect_return(log, ret);
2304 status = smartcard_pack_redir_scard_context(log, s, &ret->hContext, &index);
2305 if (status != SCARD_S_SUCCESS)
2308 status = smartcard_pack_redir_scard_handle(log, s, &ret->hCard, &index);
2309 if (status != SCARD_S_SUCCESS)
2312 if (!Stream_EnsureRemainingCapacity(s, 4))
2313 return SCARD_E_NO_MEMORY;
2315 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2316 status = smartcard_pack_redir_scard_context_ref(log, s, &ret->hContext);
2317 if (status != SCARD_S_SUCCESS)
2319 return smartcard_pack_redir_scard_handle_ref(log, s, &(ret->hCard));
2325 UINT32 pbContextNdrPtr = 0;
2328 wLog* log = scard_log();
2329 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2331 if (status != SCARD_S_SUCCESS)
2334 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2335 if (status != SCARD_S_SUCCESS)
2338 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2339 return STATUS_BUFFER_TOO_SMALL;
2341 Stream_Read_UINT32(s, call->dwShareMode);
2342 Stream_Read_UINT32(s, call->dwPreferredProtocols);
2343 Stream_Read_UINT32(s, call->dwInitialization);
2345 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2346 &(call->handles.hContext));
2347 if (status != SCARD_S_SUCCESS)
2349 WLog_Print(log, WLOG_ERROR,
2350 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2355 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2356 if (status != SCARD_S_SUCCESS)
2357 WLog_Print(log, WLOG_ERROR,
2358 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
2360 smartcard_trace_reconnect_call(log, call);
2367 wLog* log = scard_log();
2368 smartcard_trace_reconnect_return(log, ret);
2370 if (!Stream_EnsureRemainingCapacity(s, 4))
2371 return SCARD_E_NO_MEMORY;
2372 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2373 return ret->ReturnCode;
2380 UINT32 pbContextNdrPtr = 0;
2383 wLog* log = scard_log();
2385 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2387 if (status != SCARD_S_SUCCESS)
2390 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2391 if (status != SCARD_S_SUCCESS)
2394 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2395 return STATUS_BUFFER_TOO_SMALL;
2397 Stream_Read_UINT32(s, call->dwDisposition);
2399 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2400 &(call->handles.hContext));
2401 if (status != SCARD_S_SUCCESS)
2404 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2405 if (status != SCARD_S_SUCCESS)
2408 smartcard_trace_hcard_and_disposition_call(log, call, name);
2416 if (!WLog_IsLevelActive(log, g_LogLevel))
2419 WLog_Print(log, g_LogLevel,
"GetStatusChangeA_Call {");
2420 smartcard_log_context(log, &call->handles.hContext);
2422 WLog_Print(log, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
2425 dump_reader_states_a(log, call->rgReaderStates, call->cReaders);
2427 WLog_Print(log, g_LogLevel,
"}");
2431 UINT32 cReaders, UINT32* ptrIndex)
2433 LONG status = SCARD_E_NO_MEMORY;
2435 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2436 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2439 const UINT32 len = Stream_Get_UINT32(s);
2440 if (len != cReaders)
2442 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEA");
2448 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2449 if (!rgReaderStates || !states)
2451 status = ERROR_INVALID_DATA;
2453 for (UINT32 index = 0; index < cReaders; index++)
2455 UINT32 ptr = UINT32_MAX;
2458 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2461 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2467 states[index] = ptr != 0;
2468 Stream_Read_UINT32(s, readerState->dwCurrentState);
2469 Stream_Read_UINT32(s, readerState->dwEventState);
2470 Stream_Read_UINT32(s, readerState->cbAtr);
2471 Stream_Read(s, readerState->rgbAtr, 36);
2474 for (UINT32 index = 0; index < cReaders; index++)
2481 status = smartcard_ndr_read_a(log, s, &readerState->szReader, NDR_PTR_FULL);
2482 if (status != SCARD_S_SUCCESS)
2486 *ppcReaders = rgReaderStates;
2488 return SCARD_S_SUCCESS;
2492 for (UINT32 index = 0; index < cReaders; index++)
2495 free(readerState->szReader);
2498 free(rgReaderStates);
2504 UINT32 cReaders, UINT32* ptrIndex)
2506 LONG status = SCARD_E_NO_MEMORY;
2508 WINPR_ASSERT(ppcReaders || (cReaders == 0));
2509 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
2512 const UINT32 len = Stream_Get_UINT32(s);
2513 if (len != cReaders)
2515 WLog_Print(log, WLOG_ERROR,
"Count mismatch when reading LPSCARD_READERSTATEW");
2521 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2523 if (!rgReaderStates || !states)
2526 status = ERROR_INVALID_DATA;
2527 for (UINT32 index = 0; index < cReaders; index++)
2529 UINT32 ptr = UINT32_MAX;
2532 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 52))
2535 if (!smartcard_ndr_pointer_read(log, s, ptrIndex, &ptr))
2541 states[index] = ptr != 0;
2542 Stream_Read_UINT32(s, readerState->dwCurrentState);
2543 Stream_Read_UINT32(s, readerState->dwEventState);
2544 Stream_Read_UINT32(s, readerState->cbAtr);
2545 Stream_Read(s, readerState->rgbAtr, 36);
2548 for (UINT32 index = 0; index < cReaders; index++)
2556 status = smartcard_ndr_read_w(log, s, &readerState->szReader, NDR_PTR_FULL);
2557 if (status != SCARD_S_SUCCESS)
2561 *ppcReaders = rgReaderStates;
2563 return SCARD_S_SUCCESS;
2567 for (UINT32 index = 0; index < cReaders; index++)
2570 free(readerState->szReader);
2573 free(rgReaderStates);
2586 UINT32 pbContextNdrPtr = 0;
2589 wLog* log = scard_log();
2591 call->rgReaderStates = NULL;
2593 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2595 if (status != SCARD_S_SUCCESS)
2598 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2599 return STATUS_BUFFER_TOO_SMALL;
2601 Stream_Read_UINT32(s, call->dwTimeOut);
2602 Stream_Read_UINT32(s, call->cReaders);
2603 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2604 return ERROR_INVALID_DATA;
2606 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2607 &(call->handles.hContext));
2608 if (status != SCARD_S_SUCCESS)
2614 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
2615 if (status != SCARD_S_SUCCESS)
2620 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2621 return SCARD_E_UNEXPECTED;
2624 smartcard_trace_get_status_change_a_call(log, call);
2625 return SCARD_S_SUCCESS;
2632 UINT32 pbContextNdrPtr = 0;
2635 wLog* log = scard_log();
2636 call->rgReaderStates = NULL;
2638 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2640 if (status != SCARD_S_SUCCESS)
2643 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2644 return STATUS_BUFFER_TOO_SMALL;
2646 Stream_Read_UINT32(s, call->dwTimeOut);
2647 Stream_Read_UINT32(s, call->cReaders);
2648 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
2649 return ERROR_INVALID_DATA;
2651 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2652 &(call->handles.hContext));
2653 if (status != SCARD_S_SUCCESS)
2659 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
2660 if (status != SCARD_S_SUCCESS)
2665 WLog_Print(log, WLOG_WARN,
"ndrPtr=0x%08" PRIx32
", can not read rgReaderStates", ndrPtr);
2666 return SCARD_E_UNEXPECTED;
2669 smartcard_trace_get_status_change_w_call(log, call);
2670 return SCARD_S_SUCCESS;
2677 wLog* log = scard_log();
2680 DWORD cReaders = ret->cReaders;
2683 smartcard_trace_get_status_change_return(log, ret, unicode);
2684 if (ret->ReturnCode != SCARD_S_SUCCESS)
2686 if (cReaders == SCARD_AUTOALLOCATE)
2689 if (!Stream_EnsureRemainingCapacity(s, 4))
2690 return SCARD_E_NO_MEMORY;
2692 Stream_Write_UINT32(s, cReaders);
2693 if (!smartcard_ndr_pointer_write(s, &index, cReaders))
2694 return SCARD_E_NO_MEMORY;
2695 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cReaders, NDR_PTR_SIMPLE);
2696 if (status != SCARD_S_SUCCESS)
2698 return ret->ReturnCode;
2704 UINT32 pbContextNdrPtr = 0;
2706 wLog* log = scard_log();
2709 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2711 if (status != SCARD_S_SUCCESS)
2714 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2715 if (status != SCARD_S_SUCCESS)
2718 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
2719 return STATUS_BUFFER_TOO_SMALL;
2721 Stream_Read_INT32(s, call->fpbAtrIsNULL);
2722 Stream_Read_UINT32(s, call->cbAtrLen);
2724 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2725 &(call->handles.hContext));
2726 if (status != SCARD_S_SUCCESS)
2729 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2730 if (status != SCARD_S_SUCCESS)
2739 wLog* log = scard_log();
2741 DWORD cbAtrLen = ret->cbAtrLen;
2744 smartcard_trace_state_return(log, ret);
2745 if (ret->ReturnCode != SCARD_S_SUCCESS)
2747 if (cbAtrLen == SCARD_AUTOALLOCATE)
2750 Stream_Write_UINT32(s, ret->dwState);
2751 Stream_Write_UINT32(s, ret->dwProtocol);
2752 Stream_Write_UINT32(s, cbAtrLen);
2753 if (!smartcard_ndr_pointer_write(s, &index, cbAtrLen))
2754 return SCARD_E_NO_MEMORY;
2755 status = smartcard_ndr_write(s, ret->rgAtr, cbAtrLen, 1, NDR_PTR_SIMPLE);
2756 if (status != SCARD_S_SUCCESS)
2758 return ret->ReturnCode;
2764 UINT32 pbContextNdrPtr = 0;
2767 wLog* log = scard_log();
2769 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2771 if (status != SCARD_S_SUCCESS)
2774 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2775 if (status != SCARD_S_SUCCESS)
2778 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2779 return STATUS_BUFFER_TOO_SMALL;
2781 Stream_Read_INT32(s, call->fmszReaderNamesIsNULL);
2782 Stream_Read_UINT32(s, call->cchReaderLen);
2783 Stream_Read_UINT32(s, call->cbAtrLen);
2785 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2786 &(call->handles.hContext));
2787 if (status != SCARD_S_SUCCESS)
2790 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2791 if (status != SCARD_S_SUCCESS)
2794 smartcard_trace_status_call(log, call, unicode);
2801 wLog* log = scard_log();
2805 DWORD cBytes = ret->cBytes;
2807 smartcard_trace_status_return(log, ret, unicode);
2808 if (ret->ReturnCode != SCARD_S_SUCCESS)
2810 if (cBytes == SCARD_AUTOALLOCATE)
2813 if (!Stream_EnsureRemainingCapacity(s, 4))
2814 return SCARD_F_INTERNAL_ERROR;
2816 Stream_Write_UINT32(s, cBytes);
2817 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
2818 return SCARD_E_NO_MEMORY;
2820 if (!Stream_EnsureRemainingCapacity(s, 44))
2821 return SCARD_F_INTERNAL_ERROR;
2823 Stream_Write_UINT32(s, ret->dwState);
2824 Stream_Write_UINT32(s, ret->dwProtocol);
2825 Stream_Write(s, ret->pbAtr,
sizeof(ret->pbAtr));
2826 Stream_Write_UINT32(s, ret->cbAtrLen);
2827 status = smartcard_ndr_write(s, ret->mszReaderNames, cBytes, 1, NDR_PTR_SIMPLE);
2828 if (status != SCARD_S_SUCCESS)
2830 return ret->ReturnCode;
2836 wLog* log = scard_log();
2838 UINT32 pbContextNdrPtr = 0;
2840 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2842 if (status != SCARD_S_SUCCESS)
2845 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2846 if (status != SCARD_S_SUCCESS)
2849 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
2850 return STATUS_BUFFER_TOO_SMALL;
2852 Stream_Read_UINT32(s, call->dwAttrId);
2853 Stream_Read_INT32(s, call->fpbAttrIsNULL);
2854 Stream_Read_UINT32(s, call->cbAttrLen);
2856 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2857 &(call->handles.hContext));
2858 if (status != SCARD_S_SUCCESS)
2861 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2862 if (status != SCARD_S_SUCCESS)
2865 smartcard_trace_get_attrib_call(log, call);
2870 DWORD cbAttrCallLen)
2873 wLog* log = scard_log();
2875 DWORD cbAttrLen = 0;
2877 smartcard_trace_get_attrib_return(log, ret, dwAttrId);
2879 if (!Stream_EnsureRemainingCapacity(s, 4))
2880 return SCARD_F_INTERNAL_ERROR;
2882 cbAttrLen = ret->cbAttrLen;
2883 if (ret->ReturnCode != SCARD_S_SUCCESS)
2885 if (cbAttrLen == SCARD_AUTOALLOCATE)
2890 if (cbAttrCallLen < cbAttrLen)
2891 cbAttrLen = cbAttrCallLen;
2893 Stream_Write_UINT32(s, cbAttrLen);
2894 if (!smartcard_ndr_pointer_write(s, &index, cbAttrLen))
2895 return SCARD_E_NO_MEMORY;
2897 status = smartcard_ndr_write(s, ret->pbAttr, cbAttrLen, 1, NDR_PTR_SIMPLE);
2898 if (status != SCARD_S_SUCCESS)
2900 return ret->ReturnCode;
2906 wLog* log = scard_log();
2909 UINT32 pvInBufferNdrPtr = 0;
2910 UINT32 pbContextNdrPtr = 0;
2912 call->pvInBuffer = NULL;
2914 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
2916 if (status != SCARD_S_SUCCESS)
2919 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
2920 if (status != SCARD_S_SUCCESS)
2923 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 20))
2924 return STATUS_BUFFER_TOO_SMALL;
2926 Stream_Read_UINT32(s, call->dwControlCode);
2927 Stream_Read_UINT32(s, call->cbInBufferSize);
2928 if (!smartcard_ndr_pointer_read(log, s, &index,
2930 return ERROR_INVALID_DATA;
2931 Stream_Read_INT32(s, call->fpvOutBufferIsNULL);
2932 Stream_Read_UINT32(s, call->cbOutBufferSize);
2934 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
2935 &(call->handles.hContext));
2936 if (status != SCARD_S_SUCCESS)
2939 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
2940 if (status != SCARD_S_SUCCESS)
2943 if (pvInBufferNdrPtr)
2946 smartcard_ndr_read(log, s, &call->pvInBuffer, call->cbInBufferSize, 1, NDR_PTR_SIMPLE);
2947 if (status != SCARD_S_SUCCESS)
2951 smartcard_trace_control_call(log, call);
2952 return SCARD_S_SUCCESS;
2958 wLog* log = scard_log();
2961 DWORD cbDataLen = ret->cbOutBufferSize;
2964 smartcard_trace_control_return(log, ret);
2965 if (ret->ReturnCode != SCARD_S_SUCCESS)
2967 if (cbDataLen == SCARD_AUTOALLOCATE)
2970 if (!Stream_EnsureRemainingCapacity(s, 4))
2971 return SCARD_F_INTERNAL_ERROR;
2973 Stream_Write_UINT32(s, cbDataLen);
2974 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
2975 return SCARD_E_NO_MEMORY;
2977 status = smartcard_ndr_write(s, ret->pvOutBuffer, cbDataLen, 1, NDR_PTR_SIMPLE);
2978 if (status != SCARD_S_SUCCESS)
2980 return ret->ReturnCode;
2986 BYTE* pbExtraBytes = NULL;
2987 UINT32 pbExtraBytesNdrPtr = 0;
2988 UINT32 pbSendBufferNdrPtr = 0;
2989 UINT32 pioRecvPciNdrPtr = 0;
2993 UINT32 pbContextNdrPtr = 0;
2996 wLog* log = scard_log();
2998 call->pioSendPci = NULL;
2999 call->pioRecvPci = NULL;
3000 call->pbSendBuffer = NULL;
3002 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3004 if (status != SCARD_S_SUCCESS)
3007 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3008 if (status != SCARD_S_SUCCESS)
3011 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 32))
3012 return STATUS_BUFFER_TOO_SMALL;
3014 Stream_Read_UINT32(s, ioSendPci.dwProtocol);
3015 Stream_Read_UINT32(s, ioSendPci.cbExtraBytes);
3016 if (!smartcard_ndr_pointer_read(log, s, &index,
3017 &pbExtraBytesNdrPtr))
3018 return ERROR_INVALID_DATA;
3020 Stream_Read_UINT32(s, call->cbSendLength);
3021 if (!smartcard_ndr_pointer_read(log, s, &index,
3022 &pbSendBufferNdrPtr))
3023 return ERROR_INVALID_DATA;
3025 if (!smartcard_ndr_pointer_read(log, s, &index,
3027 return ERROR_INVALID_DATA;
3029 Stream_Read_INT32(s, call->fpbRecvBufferIsNULL);
3030 Stream_Read_UINT32(s, call->cbRecvLength);
3032 if (ioSendPci.cbExtraBytes > 1024)
3034 WLog_Print(log, WLOG_WARN,
3035 "Transmit_Call ioSendPci.cbExtraBytes is out of bounds: %" PRIu32
" (max: 1024)",
3036 ioSendPci.cbExtraBytes);
3037 return STATUS_INVALID_PARAMETER;
3040 if (call->cbSendLength > 66560)
3042 WLog_Print(log, WLOG_WARN,
3043 "Transmit_Call cbSendLength is out of bounds: %" PRIu32
" (max: 66560)",
3044 ioSendPci.cbExtraBytes);
3045 return STATUS_INVALID_PARAMETER;
3048 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3049 &(call->handles.hContext));
3050 if (status != SCARD_S_SUCCESS)
3053 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3054 if (status != SCARD_S_SUCCESS)
3057 if (ioSendPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3061 "Transmit_Call ioSendPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3062 return STATUS_INVALID_PARAMETER;
3065 if (pbExtraBytesNdrPtr)
3068 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3069 return STATUS_BUFFER_TOO_SMALL;
3071 Stream_Read_UINT32(s, length);
3073 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioSendPci.cbExtraBytes))
3074 return STATUS_BUFFER_TOO_SMALL;
3076 ioSendPci.pbExtraBytes = Stream_Pointer(s);
3080 if (!call->pioSendPci)
3082 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3083 return STATUS_NO_MEMORY;
3086 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3087 call->pioSendPci->cbPciLength = (DWORD)(ioSendPci.cbExtraBytes +
sizeof(
SCARD_IO_REQUEST));
3089 Stream_Read(s, pbExtraBytes, ioSendPci.cbExtraBytes);
3090 if (smartcard_unpack_read_size_align(s, ioSendPci.cbExtraBytes, 4) < 0)
3091 return STATUS_INVALID_PARAMETER;
3097 if (!call->pioSendPci)
3099 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioSendPci)");
3100 return STATUS_NO_MEMORY;
3103 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
3107 if (pbSendBufferNdrPtr)
3110 smartcard_ndr_read(log, s, &call->pbSendBuffer, call->cbSendLength, 1, NDR_PTR_SIMPLE);
3111 if (status != SCARD_S_SUCCESS)
3115 if (pioRecvPciNdrPtr)
3117 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3118 return STATUS_BUFFER_TOO_SMALL;
3120 Stream_Read_UINT32(s, ioRecvPci.dwProtocol);
3121 Stream_Read_UINT32(s, ioRecvPci.cbExtraBytes);
3122 if (!smartcard_ndr_pointer_read(log, s, &index,
3123 &pbExtraBytesNdrPtr))
3124 return ERROR_INVALID_DATA;
3126 if (ioRecvPci.cbExtraBytes && !pbExtraBytesNdrPtr)
3130 "Transmit_Call ioRecvPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
3131 return STATUS_INVALID_PARAMETER;
3134 if (pbExtraBytesNdrPtr)
3137 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
3138 return STATUS_BUFFER_TOO_SMALL;
3140 Stream_Read_UINT32(s, length);
3142 if (ioRecvPci.cbExtraBytes > 1024)
3144 WLog_Print(log, WLOG_WARN,
3145 "Transmit_Call ioRecvPci.cbExtraBytes is out of bounds: %" PRIu32
3147 ioRecvPci.cbExtraBytes);
3148 return STATUS_INVALID_PARAMETER;
3151 if (length != ioRecvPci.cbExtraBytes)
3153 WLog_Print(log, WLOG_WARN,
3154 "Transmit_Call unexpected length: Actual: %" PRIu32
3155 ", Expected: %" PRIu32
" (ioRecvPci.cbExtraBytes)",
3156 length, ioRecvPci.cbExtraBytes);
3157 return STATUS_INVALID_PARAMETER;
3160 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, ioRecvPci.cbExtraBytes))
3161 return STATUS_BUFFER_TOO_SMALL;
3163 ioRecvPci.pbExtraBytes = Stream_Pointer(s);
3167 if (!call->pioRecvPci)
3169 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3170 return STATUS_NO_MEMORY;
3173 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3174 call->pioRecvPci->cbPciLength =
3177 Stream_Read(s, pbExtraBytes, ioRecvPci.cbExtraBytes);
3178 if (smartcard_unpack_read_size_align(s, ioRecvPci.cbExtraBytes, 4) < 0)
3179 return STATUS_INVALID_PARAMETER;
3185 if (!call->pioRecvPci)
3187 WLog_Print(log, WLOG_WARN,
"Transmit_Call out of memory error (pioRecvPci)");
3188 return STATUS_NO_MEMORY;
3191 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
3196 smartcard_trace_transmit_call(log, call);
3197 return SCARD_S_SUCCESS;
3203 wLog* log = scard_log();
3208 UINT32 cbRecvLength = ret->cbRecvLength;
3209 UINT32 cbRecvPci = ret->pioRecvPci ? ret->pioRecvPci->cbPciLength : 0;
3211 smartcard_trace_transmit_return(log, ret);
3213 if (!ret->pbRecvBuffer)
3216 if (!smartcard_ndr_pointer_write(s, &index, cbRecvPci))
3217 return SCARD_E_NO_MEMORY;
3218 if (!Stream_EnsureRemainingCapacity(s, 4))
3219 return SCARD_E_NO_MEMORY;
3220 Stream_Write_UINT32(s, cbRecvLength);
3221 if (!smartcard_ndr_pointer_write(s, &index, cbRecvLength))
3222 return SCARD_E_NO_MEMORY;
3224 if (ret->pioRecvPci)
3226 UINT32 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
3229 if (!Stream_EnsureRemainingCapacity(s, cbExtraBytes + 16))
3231 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3232 return SCARD_F_INTERNAL_ERROR;
3235 Stream_Write_UINT32(s, ret->pioRecvPci->dwProtocol);
3236 Stream_Write_UINT32(s, cbExtraBytes);
3237 if (!smartcard_ndr_pointer_write(s, &index, cbExtraBytes))
3238 return SCARD_E_NO_MEMORY;
3239 error = smartcard_ndr_write(s, pbExtraBytes, cbExtraBytes, 1, NDR_PTR_SIMPLE);
3244 status = smartcard_ndr_write(s, ret->pbRecvBuffer, ret->cbRecvLength, 1, NDR_PTR_SIMPLE);
3245 if (status != SCARD_S_SUCCESS)
3247 return ret->ReturnCode;
3252 UINT32 rgReaderStatesNdrPtr = 0;
3253 UINT32 rgAtrMasksNdrPtr = 0;
3255 UINT32 pbContextNdrPtr = 0;
3258 wLog* log = scard_log();
3260 call->rgReaderStates = NULL;
3262 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3264 if (status != SCARD_S_SUCCESS)
3267 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3268 return STATUS_BUFFER_TOO_SMALL;
3270 Stream_Read_UINT32(s, call->cAtrs);
3271 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3272 return ERROR_INVALID_DATA;
3273 Stream_Read_UINT32(s, call->cReaders);
3274 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3275 return ERROR_INVALID_DATA;
3277 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3278 &(call->handles.hContext));
3279 if (status != SCARD_S_SUCCESS)
3282 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3284 WLog_Print(log, WLOG_WARN,
3285 "LocateCardsByATRA_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3286 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3287 rgAtrMasksNdrPtr, call->cAtrs);
3288 return STATUS_INVALID_PARAMETER;
3291 if (rgAtrMasksNdrPtr)
3293 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3294 if (status != SCARD_S_SUCCESS)
3298 if (rgReaderStatesNdrPtr)
3301 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
3302 if (status != SCARD_S_SUCCESS)
3306 smartcard_trace_locate_cards_by_atr_a_call(log, call);
3307 return SCARD_S_SUCCESS;
3312 UINT32 sz1NdrPtr = 0;
3313 UINT32 sz2NdrPtr = 0;
3315 UINT32 pbContextNdrPtr = 0;
3318 wLog* log = scard_log();
3320 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3322 if (status != SCARD_S_SUCCESS)
3325 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3326 return ERROR_INVALID_DATA;
3327 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3328 return ERROR_INVALID_DATA;
3331 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3332 if (status != SCARD_S_SUCCESS)
3337 status = smartcard_ndr_read_a(log, s, &call->sz1, NDR_PTR_FULL);
3338 if (status != SCARD_S_SUCCESS)
3343 status = smartcard_ndr_read_a(log, s, &call->sz2, NDR_PTR_FULL);
3344 if (status != SCARD_S_SUCCESS)
3347 smartcard_trace_context_and_two_strings_a_call(log, call);
3348 return SCARD_S_SUCCESS;
3353 UINT32 sz1NdrPtr = 0;
3354 UINT32 sz2NdrPtr = 0;
3356 UINT32 pbContextNdrPtr = 0;
3359 wLog* log = scard_log();
3361 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3363 if (status != SCARD_S_SUCCESS)
3366 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3367 return ERROR_INVALID_DATA;
3368 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3369 return ERROR_INVALID_DATA;
3372 smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr, &call->handles.hContext);
3373 if (status != SCARD_S_SUCCESS)
3378 status = smartcard_ndr_read_w(log, s, &call->sz1, NDR_PTR_FULL);
3379 if (status != SCARD_S_SUCCESS)
3384 status = smartcard_ndr_read_w(log, s, &call->sz2, NDR_PTR_FULL);
3385 if (status != SCARD_S_SUCCESS)
3388 smartcard_trace_context_and_two_strings_w_call(log, call);
3389 return SCARD_S_SUCCESS;
3394 UINT32 sz1NdrPtr = 0;
3395 UINT32 sz2NdrPtr = 0;
3397 UINT32 pbContextNdrPtr = 0;
3400 wLog* log = scard_log();
3402 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3404 if (status != SCARD_S_SUCCESS)
3407 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3408 return STATUS_BUFFER_TOO_SMALL;
3410 Stream_Read_UINT32(s, call->cBytes);
3411 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3412 return ERROR_INVALID_DATA;
3414 Stream_Read_UINT32(s, call->cReaders);
3415 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3416 return ERROR_INVALID_DATA;
3418 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3419 &(call->handles.hContext));
3420 if (status != SCARD_S_SUCCESS)
3425 status = smartcard_ndr_read_fixed_string_a(log, s, &call->mszCards, call->cBytes,
3427 if (status != SCARD_S_SUCCESS)
3433 smartcard_unpack_reader_state_a(log, s, &call->rgReaderStates, call->cReaders, &index);
3434 if (status != SCARD_S_SUCCESS)
3437 smartcard_trace_locate_cards_a_call(log, call);
3438 return SCARD_S_SUCCESS;
3443 UINT32 sz1NdrPtr = 0;
3444 UINT32 sz2NdrPtr = 0;
3446 UINT32 pbContextNdrPtr = 0;
3449 wLog* log = scard_log();
3451 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3453 if (status != SCARD_S_SUCCESS)
3456 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3457 return STATUS_BUFFER_TOO_SMALL;
3459 Stream_Read_UINT32(s, call->cBytes);
3460 if (!smartcard_ndr_pointer_read(log, s, &index, &sz1NdrPtr))
3461 return ERROR_INVALID_DATA;
3463 Stream_Read_UINT32(s, call->cReaders);
3464 if (!smartcard_ndr_pointer_read(log, s, &index, &sz2NdrPtr))
3465 return ERROR_INVALID_DATA;
3467 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3468 &(call->handles.hContext));
3469 if (status != SCARD_S_SUCCESS)
3474 status = smartcard_ndr_read_fixed_string_w(log, s, &call->mszCards, call->cBytes,
3476 if (status != SCARD_S_SUCCESS)
3482 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
3483 if (status != SCARD_S_SUCCESS)
3486 smartcard_trace_locate_cards_w_call(log, call);
3487 return SCARD_S_SUCCESS;
3494 UINT32 pbContextNdrPtr = 0;
3497 wLog* log = scard_log();
3499 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3501 if (status != SCARD_S_SUCCESS)
3503 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3504 if (status != SCARD_S_SUCCESS)
3507 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3508 return STATUS_BUFFER_TOO_SMALL;
3509 Stream_Read_UINT32(s, call->dwAttrId);
3510 Stream_Read_UINT32(s, call->cbAttrLen);
3512 if (!smartcard_ndr_pointer_read(log, s, &index, &ndrPtr))
3513 return ERROR_INVALID_DATA;
3515 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3516 &(call->handles.hContext));
3517 if (status != SCARD_S_SUCCESS)
3520 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3521 if (status != SCARD_S_SUCCESS)
3527 status = smartcard_ndr_read_ex(log, s, &call->pbAttr, 0, 1, NDR_PTR_SIMPLE, &len);
3528 if (status != SCARD_S_SUCCESS)
3530 if (call->cbAttrLen > len)
3531 call->cbAttrLen = WINPR_ASSERTING_INT_CAST(DWORD, len);
3534 call->cbAttrLen = 0;
3535 smartcard_trace_set_attrib_call(log, call);
3536 return SCARD_S_SUCCESS;
3541 UINT32 rgReaderStatesNdrPtr = 0;
3542 UINT32 rgAtrMasksNdrPtr = 0;
3544 UINT32 pbContextNdrPtr = 0;
3547 wLog* log = scard_log();
3549 call->rgReaderStates = NULL;
3551 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3553 if (status != SCARD_S_SUCCESS)
3556 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16))
3557 return STATUS_BUFFER_TOO_SMALL;
3559 Stream_Read_UINT32(s, call->cAtrs);
3560 if (!smartcard_ndr_pointer_read(log, s, &index, &rgAtrMasksNdrPtr))
3561 return ERROR_INVALID_DATA;
3563 Stream_Read_UINT32(s, call->cReaders);
3564 if (!smartcard_ndr_pointer_read(log, s, &index, &rgReaderStatesNdrPtr))
3565 return ERROR_INVALID_DATA;
3567 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3568 &(call->handles.hContext));
3569 if (status != SCARD_S_SUCCESS)
3572 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3574 WLog_Print(log, WLOG_WARN,
3575 "LocateCardsByATRW_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3576 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3577 rgAtrMasksNdrPtr, call->cAtrs);
3578 return STATUS_INVALID_PARAMETER;
3581 if (rgAtrMasksNdrPtr)
3583 status = smartcard_ndr_read_atrmask(log, s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3584 if (status != SCARD_S_SUCCESS)
3588 if (rgReaderStatesNdrPtr)
3591 smartcard_unpack_reader_state_w(log, s, &call->rgReaderStates, call->cReaders, &index);
3592 if (status != SCARD_S_SUCCESS)
3596 smartcard_trace_locate_cards_by_atr_w_call(log, call);
3597 return SCARD_S_SUCCESS;
3602 UINT32 mszNdrPtr = 0;
3603 UINT32 contextNdrPtr = 0;
3605 UINT32 pbContextNdrPtr = 0;
3608 wLog* log = scard_log();
3610 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3611 return ERROR_INVALID_DATA;
3613 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3614 &index, &pbContextNdrPtr);
3615 if (status != SCARD_S_SUCCESS)
3618 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3619 return ERROR_INVALID_DATA;
3621 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3622 return STATUS_BUFFER_TOO_SMALL;
3623 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3624 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
3625 Stream_Read_UINT32(s, call->Common.cbDataLen);
3627 call->szLookupName = NULL;
3630 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
3631 if (status != SCARD_S_SUCCESS)
3635 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3636 &call->Common.handles.hContext);
3637 if (status != SCARD_S_SUCCESS)
3642 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3643 if (status != SCARD_S_SUCCESS)
3646 smartcard_trace_read_cache_a_call(log, call);
3647 return SCARD_S_SUCCESS;
3652 UINT32 mszNdrPtr = 0;
3653 UINT32 contextNdrPtr = 0;
3655 UINT32 pbContextNdrPtr = 0;
3658 wLog* log = scard_log();
3660 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3661 return ERROR_INVALID_DATA;
3663 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3664 &index, &pbContextNdrPtr);
3665 if (status != SCARD_S_SUCCESS)
3668 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3669 return ERROR_INVALID_DATA;
3671 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12))
3672 return STATUS_BUFFER_TOO_SMALL;
3673 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3674 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
3675 Stream_Read_UINT32(s, call->Common.cbDataLen);
3677 call->szLookupName = NULL;
3680 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
3681 if (status != SCARD_S_SUCCESS)
3685 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3686 &call->Common.handles.hContext);
3687 if (status != SCARD_S_SUCCESS)
3692 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3693 if (status != SCARD_S_SUCCESS)
3696 smartcard_trace_read_cache_w_call(log, call);
3697 return SCARD_S_SUCCESS;
3702 UINT32 mszNdrPtr = 0;
3703 UINT32 contextNdrPtr = 0;
3704 UINT32 pbDataNdrPtr = 0;
3706 UINT32 pbContextNdrPtr = 0;
3709 wLog* log = scard_log();
3711 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3712 return ERROR_INVALID_DATA;
3714 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3715 &index, &pbContextNdrPtr);
3716 if (status != SCARD_S_SUCCESS)
3719 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3720 return ERROR_INVALID_DATA;
3722 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
3723 return STATUS_BUFFER_TOO_SMALL;
3725 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3726 Stream_Read_UINT32(s, call->Common.cbDataLen);
3728 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
3729 return ERROR_INVALID_DATA;
3731 call->szLookupName = NULL;
3734 status = smartcard_ndr_read_a(log, s, &call->szLookupName, NDR_PTR_FULL);
3735 if (status != SCARD_S_SUCCESS)
3739 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3740 &call->Common.handles.hContext);
3741 if (status != SCARD_S_SUCCESS)
3744 call->Common.CardIdentifier = NULL;
3747 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3748 if (status != SCARD_S_SUCCESS)
3752 call->Common.pbData = NULL;
3755 status = smartcard_ndr_read(log, s, &call->Common.pbData, call->Common.cbDataLen, 1,
3757 if (status != SCARD_S_SUCCESS)
3760 smartcard_trace_write_cache_a_call(log, call);
3761 return SCARD_S_SUCCESS;
3766 UINT32 mszNdrPtr = 0;
3767 UINT32 contextNdrPtr = 0;
3768 UINT32 pbDataNdrPtr = 0;
3770 UINT32 pbContextNdrPtr = 0;
3773 wLog* log = scard_log();
3775 if (!smartcard_ndr_pointer_read(log, s, &index, &mszNdrPtr))
3776 return ERROR_INVALID_DATA;
3778 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->Common.handles.hContext),
3779 &index, &pbContextNdrPtr);
3780 if (status != SCARD_S_SUCCESS)
3783 if (!smartcard_ndr_pointer_read(log, s, &index, &contextNdrPtr))
3784 return ERROR_INVALID_DATA;
3786 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
3787 return STATUS_BUFFER_TOO_SMALL;
3788 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3789 Stream_Read_UINT32(s, call->Common.cbDataLen);
3791 if (!smartcard_ndr_pointer_read(log, s, &index, &pbDataNdrPtr))
3792 return ERROR_INVALID_DATA;
3794 call->szLookupName = NULL;
3797 status = smartcard_ndr_read_w(log, s, &call->szLookupName, NDR_PTR_FULL);
3798 if (status != SCARD_S_SUCCESS)
3802 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3803 &call->Common.handles.hContext);
3804 if (status != SCARD_S_SUCCESS)
3807 call->Common.CardIdentifier = NULL;
3810 status = smartcard_ndr_read_u(log, s, &call->Common.CardIdentifier);
3811 if (status != SCARD_S_SUCCESS)
3815 call->Common.pbData = NULL;
3818 status = smartcard_ndr_read(log, s, &call->Common.pbData, call->Common.cbDataLen, 1,
3820 if (status != SCARD_S_SUCCESS)
3823 smartcard_trace_write_cache_w_call(log, call);
3830 wLog* log = scard_log();
3833 UINT32 pbContextNdrPtr = 0;
3835 LONG status = smartcard_unpack_redir_scard_context(log, s, &(call->handles.hContext), &index,
3837 if (status != SCARD_S_SUCCESS)
3840 status = smartcard_unpack_redir_scard_handle(log, s, &(call->handles.hCard), &index);
3841 if (status != SCARD_S_SUCCESS)
3844 status = smartcard_unpack_redir_scard_context_ref(log, s, pbContextNdrPtr,
3845 &(call->handles.hContext));
3846 if (status != SCARD_S_SUCCESS)
3848 WLog_Print(log, WLOG_ERROR,
3849 "smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
3854 status = smartcard_unpack_redir_scard_handle_ref(log, s, &(call->handles.hCard));
3855 if (status != SCARD_S_SUCCESS)
3856 WLog_Print(log, WLOG_ERROR,
3857 "smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"", status);
3859 smartcard_trace_get_transmit_count_call(log, call);
3866 wLog* log = scard_log();
3867 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
3868 &call->szReaderName);
3874 wLog* log = scard_log();
3875 return smartcard_unpack_common_context_and_string_a(log, s, &call->handles.hContext, &call->sz);
3881 wLog* log = scard_log();
3882 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext, &call->sz);
3888 wLog* log = scard_log();
3889 return smartcard_unpack_common_context_and_string_w(log, s, &call->handles.hContext,
3890 &call->szReaderName);
3896 wLog* log = scard_log();
3897 smartcard_trace_device_type_id_return(log, ret);
3899 if (!Stream_EnsureRemainingCapacity(s, 4))
3901 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3902 return SCARD_F_INTERNAL_ERROR;
3905 Stream_Write_UINT32(s, ret->dwDeviceId);
3907 return ret->ReturnCode;
3913 wLog* log = scard_log();
3916 DWORD cbDataLen = ret->cReaders;
3919 smartcard_trace_locate_cards_return(log, ret);
3920 if (ret->ReturnCode != SCARD_S_SUCCESS)
3922 if (cbDataLen == SCARD_AUTOALLOCATE)
3925 if (!Stream_EnsureRemainingCapacity(s, 4))
3927 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3928 return SCARD_F_INTERNAL_ERROR;
3931 Stream_Write_UINT32(s, cbDataLen);
3932 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3933 return SCARD_E_NO_MEMORY;
3935 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cbDataLen, NDR_PTR_SIMPLE);
3936 if (status != SCARD_S_SUCCESS)
3938 return ret->ReturnCode;
3944 wLog* log = scard_log();
3948 DWORD cbDataLen = ret->cbDataLen;
3949 smartcard_trace_get_reader_icon_return(log, ret);
3950 if (ret->ReturnCode != SCARD_S_SUCCESS)
3952 if (cbDataLen == SCARD_AUTOALLOCATE)
3955 if (!Stream_EnsureRemainingCapacity(s, 4))
3957 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3958 return SCARD_F_INTERNAL_ERROR;
3961 Stream_Write_UINT32(s, cbDataLen);
3962 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3963 return SCARD_E_NO_MEMORY;
3965 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
3966 if (status != SCARD_S_SUCCESS)
3968 return ret->ReturnCode;
3974 wLog* log = scard_log();
3976 smartcard_trace_get_transmit_count_return(log, ret);
3978 if (!Stream_EnsureRemainingCapacity(s, 4))
3980 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
3981 return SCARD_F_INTERNAL_ERROR;
3984 Stream_Write_UINT32(s, ret->cTransmitCount);
3986 return ret->ReturnCode;
3992 wLog* log = scard_log();
3996 DWORD cbDataLen = ret->cbDataLen;
3997 smartcard_trace_read_cache_return(log, ret);
3998 if (ret->ReturnCode != SCARD_S_SUCCESS)
4001 if (cbDataLen == SCARD_AUTOALLOCATE)
4004 if (!Stream_EnsureRemainingCapacity(s, 4))
4006 WLog_Print(log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
4007 return SCARD_F_INTERNAL_ERROR;
4010 Stream_Write_UINT32(s, cbDataLen);
4011 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
4012 return SCARD_E_NO_MEMORY;
4014 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
4015 if (status != SCARD_S_SUCCESS)
4017 return ret->ReturnCode;