24 #include <freerdp/config.h>
26 #include <winpr/crt.h>
27 #include <winpr/print.h>
29 #include <freerdp/channels/scard.h>
30 #include <freerdp/utils/smartcard_pack.h>
32 #include <freerdp/log.h>
33 #define TAG FREERDP_TAG("scard.pack")
35 static const DWORD g_LogLevel = WLOG_DEBUG;
37 #define smartcard_unpack_redir_scard_context(s, context, index, ndr) \
38 smartcard_unpack_redir_scard_context_((s), (context), (index), (ndr), __FILE__, __func__, \
40 #define smartcard_unpack_redir_scard_handle(s, context, index) \
41 smartcard_unpack_redir_scard_handle_((s), (context), (index), __FILE__, __func__, __LINE__)
44 UINT32* index, UINT32* ppbContextNdrPtr,
45 const char* file,
const char*
function,
int line);
49 UINT32* index,
const char* file,
50 const char*
function,
int line);
53 static LONG smartcard_unpack_redir_scard_context_ref(
wStream* s, UINT32 pbContextNdrPtr,
69 #define smartcard_ndr_pointer_read(s, index, ptr) \
70 smartcard_ndr_pointer_read_((s), (index), (ptr), __FILE__, __func__, __LINE__)
71 static BOOL smartcard_ndr_pointer_read_(
wStream* s, UINT32* index, UINT32* ptr,
const char* file,
72 const char* fkt,
size_t line)
74 const UINT32 expect = 0x20000 + (*index) * 4;
79 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
82 Stream_Read_UINT32(s, ndrPtr);
88 if (ptr && (ndrPtr == 0))
91 "[%s:%" PRIuz
"] Read context pointer 0x%08" PRIx32
", expected 0x%08" PRIx32,
92 fkt, line, ndrPtr, expect);
96 (*index) = (*index) + 1;
100 static LONG smartcard_ndr_read(
wStream* s, BYTE** data,
size_t min,
size_t elementSize,
122 return STATUS_INVALID_PARAMETER;
125 if (!Stream_CheckAndLogRequiredLength(TAG, s, required))
126 return STATUS_BUFFER_TOO_SMALL;
131 Stream_Read_UINT32(s, len);
132 Stream_Read_UINT32(s, offset);
133 Stream_Read_UINT32(s, len2);
134 if (len != offset + len2)
137 "Invalid data when reading full NDR pointer: total=%" PRIu32
138 ", offset=%" PRIu32
", remaining=%" PRIu32,
140 return STATUS_BUFFER_TOO_SMALL;
144 Stream_Read_UINT32(s, len);
146 if ((len != min) && (min > 0))
149 "Invalid data when reading simple NDR pointer: total=%" PRIu32
150 ", expected=%" PRIu32,
152 return STATUS_BUFFER_TOO_SMALL;
159 return STATUS_INVALID_PARAMETER;
164 WLog_ERR(TAG,
"Invalid length read from NDR pointer, minimum %" PRIu32
", got %" PRIu32,
166 return STATUS_DATA_ERROR;
169 if (len > SIZE_MAX / 2)
170 return STATUS_BUFFER_TOO_SMALL;
172 if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, len, elementSize))
173 return STATUS_BUFFER_TOO_SMALL;
180 r = calloc(len +
sizeof(WCHAR),
sizeof(CHAR));
182 return SCARD_E_NO_MEMORY;
183 Stream_Read(s, r, len);
184 smartcard_unpack_read_size_align(s, len, 4);
186 return STATUS_SUCCESS;
189 static BOOL smartcard_ndr_pointer_write(
wStream* s, UINT32* index, DWORD length)
191 const UINT32 ndrPtr = 0x20000 + (*index) * 4;
195 if (!Stream_EnsureRemainingCapacity(s, 4))
200 Stream_Write_UINT32(s, ndrPtr);
201 (*index) = (*index) + 1;
204 Stream_Write_UINT32(s, 0);
208 static LONG smartcard_ndr_write(
wStream* s,
const BYTE* data, UINT32 size, UINT32 elementSize,
211 const UINT32 offset = 0;
212 const UINT32 len = size;
213 const UINT32 dataLen = size * elementSize;
217 return SCARD_S_SUCCESS;
231 return SCARD_E_INVALID_PARAMETER;
234 if (!Stream_EnsureRemainingCapacity(s, required + dataLen + 4))
235 return STATUS_BUFFER_TOO_SMALL;
240 Stream_Write_UINT32(s, len);
241 Stream_Write_UINT32(s, offset);
242 Stream_Write_UINT32(s, len);
245 Stream_Write_UINT32(s, len);
250 return SCARD_E_INVALID_PARAMETER;
254 Stream_Write(s, data, dataLen);
256 Stream_Zero(s, dataLen);
257 return smartcard_pack_write_size_align(s, len, 4);
285 static LONG smartcard_ndr_read_fixed_string_a(
wStream* s, CHAR** data,
size_t min, ndr_ptr_t type)
293 return smartcard_ndr_read(s, u.ppv, min,
sizeof(CHAR), type);
296 static LONG smartcard_ndr_read_fixed_string_w(
wStream* s, WCHAR** data,
size_t min, ndr_ptr_t type)
304 return smartcard_ndr_read(s, u.ppv, min,
sizeof(WCHAR), type);
307 static LONG smartcard_ndr_read_a(
wStream* s, CHAR** data, ndr_ptr_t type)
315 return smartcard_ndr_read(s, u.ppv, 0,
sizeof(CHAR), type);
318 static LONG smartcard_ndr_read_w(
wStream* s, WCHAR** data, ndr_ptr_t type)
326 return smartcard_ndr_read(s, u.ppv, 0,
sizeof(WCHAR), type);
329 static LONG smartcard_ndr_read_u(
wStream* s, UUID** data)
337 return smartcard_ndr_read(s, u.ppv, 1,
sizeof(UUID), NDR_PTR_FIXED);
340 static char* smartcard_convert_string_list(
const void* in,
size_t bytes, BOOL unicode)
361 mszA = ConvertMszWCharNToUtf8Alloc(
string.wz, bytes /
sizeof(WCHAR), &length);
367 mszA = (
char*)calloc(bytes,
sizeof(
char));
370 CopyMemory(mszA,
string.sz, bytes - 1);
379 for (
size_t index = 0; index < length - 1; index++)
381 if (mszA[index] ==
'\0')
388 static char* smartcard_msz_dump_a(
const char* msz,
size_t len,
char* buffer,
size_t bufferLen)
391 const char* cur = msz;
393 while ((len > 0) && cur && cur[0] !=
'\0' && (bufferLen > 0))
395 size_t clen = strnlen(cur, len);
396 int rc = _snprintf(buf, bufferLen,
"%s", cur);
397 bufferLen -= (size_t)rc;
406 static char* smartcard_msz_dump_w(
const WCHAR* msz,
size_t len,
char* buffer,
size_t bufferLen)
411 char* sz = ConvertMszWCharNToUtf8Alloc(msz, len, &szlen);
415 smartcard_msz_dump_a(sz, szlen, buffer, bufferLen);
420 static char* smartcard_array_dump(
const void* pd,
size_t len,
char* buffer,
size_t bufferLen)
422 const BYTE* data = pd;
424 char* start = buffer;
429 buffer[bufferLen - 1] =
'\0';
433 rc = _snprintf(buffer, bufferLen,
"{ ");
434 if ((rc < 0) || ((
size_t)rc > bufferLen))
437 bufferLen -= (size_t)rc;
439 for (
size_t x = 0; x < len; x++)
441 rc = _snprintf(buffer, bufferLen,
"%02X", data[x]);
442 if ((rc < 0) || ((
size_t)rc > bufferLen))
445 bufferLen -= (size_t)rc;
448 rc = _snprintf(buffer, bufferLen,
" }");
449 if ((rc < 0) || ((
size_t)rc > bufferLen))
455 static void smartcard_log_redir_handle(
const char* tag,
const REDIR_SCARDHANDLE* pHandle)
459 WLog_LVL(tag, g_LogLevel,
" hContext: %s",
460 smartcard_array_dump(pHandle->pbHandle, pHandle->cbHandle, buffer,
sizeof(buffer)));
463 static void smartcard_log_context(
const char* tag,
const REDIR_SCARDCONTEXT* phContext)
468 smartcard_array_dump(phContext->pbContext, phContext->cbContext, buffer,
sizeof(buffer)));
471 static void smartcard_trace_context_and_string_call_a(
const char* name,
475 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
478 WLog_LVL(TAG, g_LogLevel,
"%s {", name);
479 smartcard_log_context(TAG, phContext);
480 WLog_LVL(TAG, g_LogLevel,
" sz=%s", sz);
482 WLog_LVL(TAG, g_LogLevel,
"}");
485 static void smartcard_trace_context_and_string_call_w(
const char* name,
489 char tmp[1024] = { 0 };
490 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
494 (void)ConvertWCharToUtf8(sz, tmp, ARRAYSIZE(tmp));
496 WLog_LVL(TAG, g_LogLevel,
"%s {", name);
497 smartcard_log_context(TAG, phContext);
498 WLog_LVL(TAG, g_LogLevel,
" sz=%s", tmp);
499 WLog_LVL(TAG, g_LogLevel,
"}");
502 static void smartcard_trace_context_call(
const Context_Call* call,
const char* name)
505 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
508 WLog_LVL(TAG, g_LogLevel,
"%s_Call {", name);
509 smartcard_log_context(TAG, &call->handles.hContext);
511 WLog_LVL(TAG, g_LogLevel,
"}");
517 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
520 WLog_LVL(TAG, g_LogLevel,
"ListReaderGroups%S_Call {", unicode ?
"W" :
"A");
521 smartcard_log_context(TAG, &call->handles.hContext);
523 WLog_LVL(TAG, g_LogLevel,
"fmszGroupsIsNULL: %" PRId32
" cchGroups: 0x%08" PRIx32,
524 call->fmszGroupsIsNULL, call->cchGroups);
525 WLog_LVL(TAG, g_LogLevel,
"}");
530 char* szEventState = NULL;
531 char* szCurrentState = NULL;
533 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
536 WLog_LVL(TAG, g_LogLevel,
"GetStatusChangeW_Call {");
537 smartcard_log_context(TAG, &call->handles.hContext);
539 WLog_LVL(TAG, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
542 for (UINT32 index = 0; index < call->cReaders; index++)
545 char szReaderA[1024] = { 0 };
547 (void)ConvertWCharToUtf8(readerState->szReader, szReaderA, ARRAYSIZE(szReaderA));
549 WLog_LVL(TAG, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
550 szReaderA, readerState->cbAtr);
551 szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
552 szEventState = SCardGetReaderStateString(readerState->dwEventState);
553 WLog_LVL(TAG, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
554 szCurrentState, readerState->dwCurrentState);
555 WLog_LVL(TAG, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
556 szEventState, readerState->dwEventState);
557 free(szCurrentState);
561 WLog_LVL(TAG, g_LogLevel,
"}");
569 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
572 mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
574 WLog_LVL(TAG, g_LogLevel,
"ListReaderGroups%s_Return {", unicode ?
"W" :
"A");
575 WLog_LVL(TAG, g_LogLevel,
" ReturnCode: %s (0x%08" PRIx32
")",
576 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
577 WLog_LVL(TAG, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
578 WLog_LVL(TAG, g_LogLevel,
"}");
582 static void smartcard_trace_list_readers_call(
const ListReaders_Call* call, BOOL unicode)
584 char* mszGroupsA = NULL;
586 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
589 mszGroupsA = smartcard_convert_string_list(call->mszGroups, call->cBytes, unicode);
591 WLog_LVL(TAG, g_LogLevel,
"ListReaders%s_Call {", unicode ?
"W" :
"A");
592 smartcard_log_context(TAG, &call->handles.hContext);
594 WLog_LVL(TAG, g_LogLevel,
595 "cBytes: %" PRIu32
" mszGroups: %s fmszReadersIsNULL: %" PRId32
596 " cchReaders: 0x%08" PRIX32
"",
597 call->cBytes, mszGroupsA, call->fmszReadersIsNULL, call->cchReaders);
598 WLog_LVL(TAG, g_LogLevel,
"}");
605 char* szEventState = NULL;
606 char* szCurrentState = NULL;
608 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
611 WLog_LVL(TAG, g_LogLevel,
"LocateCardsByATRA_Call {");
612 smartcard_log_context(TAG, &call->handles.hContext);
614 for (UINT32 index = 0; index < call->cReaders; index++)
619 WLog_LVL(TAG, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
620 readerState->szReader, readerState->cbAtr);
621 szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
622 szEventState = SCardGetReaderStateString(readerState->dwEventState);
623 WLog_LVL(TAG, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
624 szCurrentState, readerState->dwCurrentState);
625 WLog_LVL(TAG, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
626 szEventState, readerState->dwEventState);
629 TAG,
"\t[%" PRIu32
"]: cbAtr: %" PRIu32
" rgbAtr: %s", index, readerState->cbAtr,
630 smartcard_array_dump(readerState->rgbAtr, readerState->cbAtr, buffer,
sizeof(buffer)));
632 free(szCurrentState);
636 WLog_LVL(TAG, g_LogLevel,
"}");
643 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
646 WLog_LVL(TAG, g_LogLevel,
"LocateCardsA_Call {");
647 smartcard_log_context(TAG, &call->handles.hContext);
648 WLog_LVL(TAG, g_LogLevel,
" cBytes=%" PRId32, call->cBytes);
649 WLog_LVL(TAG, g_LogLevel,
" mszCards=%s",
650 smartcard_msz_dump_a(call->mszCards, call->cBytes, buffer,
sizeof(buffer)));
651 WLog_LVL(TAG, g_LogLevel,
" cReaders=%" PRId32, call->cReaders);
654 WLog_LVL(TAG, g_LogLevel,
"}");
660 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
663 WLog_LVL(TAG, g_LogLevel,
"LocateCards_Return {");
664 WLog_LVL(TAG, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
665 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
667 if (ret->ReturnCode == SCARD_S_SUCCESS)
669 WLog_LVL(TAG, g_LogLevel,
" cReaders=%" PRId32, ret->cReaders);
671 WLog_LVL(TAG, g_LogLevel,
"}");
677 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
680 WLog_LVL(TAG, g_LogLevel,
"GetReaderIcon_Return {");
681 WLog_LVL(TAG, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
682 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
684 if (ret->ReturnCode == SCARD_S_SUCCESS)
686 WLog_LVL(TAG, g_LogLevel,
" cbDataLen=%" PRId32, ret->cbDataLen);
688 WLog_LVL(TAG, g_LogLevel,
"}");
694 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
697 WLog_LVL(TAG, g_LogLevel,
"GetTransmitCount_Return {");
698 WLog_LVL(TAG, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
699 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
701 WLog_LVL(TAG, g_LogLevel,
" cTransmitCount=%" PRIu32, ret->cTransmitCount);
702 WLog_LVL(TAG, g_LogLevel,
"}");
708 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
711 WLog_LVL(TAG, g_LogLevel,
"ReadCache_Return {");
712 WLog_LVL(TAG, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
713 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
715 if (ret->ReturnCode == SCARD_S_SUCCESS)
718 WLog_LVL(TAG, g_LogLevel,
" cbDataLen=%" PRId32, ret->cbDataLen);
719 WLog_LVL(TAG, g_LogLevel,
" cbData: %s",
720 smartcard_array_dump(ret->pbData, ret->cbDataLen, buffer,
sizeof(buffer)));
722 WLog_LVL(TAG, g_LogLevel,
"}");
729 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
732 WLog_LVL(TAG, g_LogLevel,
"LocateCardsW_Call {");
733 smartcard_log_context(TAG, &call->handles.hContext);
734 WLog_LVL(TAG, g_LogLevel,
" cBytes=%" PRId32, call->cBytes);
735 WLog_LVL(TAG, g_LogLevel,
" sz2=%s",
736 smartcard_msz_dump_w(call->mszCards, call->cBytes, buffer,
sizeof(buffer)));
737 WLog_LVL(TAG, g_LogLevel,
" cReaders=%" PRId32, call->cReaders);
739 WLog_LVL(TAG, g_LogLevel,
"}");
742 static void smartcard_trace_list_readers_return(
const ListReaders_Return* ret, BOOL unicode)
746 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
749 WLog_LVL(TAG, g_LogLevel,
"ListReaders%s_Return {", unicode ?
"W" :
"A");
750 WLog_LVL(TAG, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
751 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
753 if (ret->ReturnCode != SCARD_S_SUCCESS)
755 WLog_LVL(TAG, g_LogLevel,
"}");
759 mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
761 WLog_LVL(TAG, g_LogLevel,
" cBytes: %" PRIu32
" msz: %s", ret->cBytes, mszA);
762 WLog_LVL(TAG, g_LogLevel,
"}");
769 char* szEventState = NULL;
770 char* szCurrentState = NULL;
772 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
775 WLog_LVL(TAG, g_LogLevel,
"GetStatusChange%s_Return {", unicode ?
"W" :
"A");
776 WLog_LVL(TAG, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
777 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
778 WLog_LVL(TAG, g_LogLevel,
" cReaders: %" PRIu32
"", ret->cReaders);
780 for (UINT32 index = 0; index < ret->cReaders; index++)
784 szCurrentState = SCardGetReaderStateString(rgReaderState->dwCurrentState);
785 szEventState = SCardGetReaderStateString(rgReaderState->dwEventState);
786 WLog_LVL(TAG, g_LogLevel,
" [%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
787 szCurrentState, rgReaderState->dwCurrentState);
788 WLog_LVL(TAG, g_LogLevel,
" [%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
789 szEventState, rgReaderState->dwEventState);
790 WLog_LVL(TAG, g_LogLevel,
" [%" PRIu32
"]: cbAtr: %" PRIu32
" rgbAtr: %s", index,
791 rgReaderState->cbAtr,
792 smartcard_array_dump(rgReaderState->rgbAtr, rgReaderState->cbAtr, buffer,
794 free(szCurrentState);
798 WLog_LVL(TAG, g_LogLevel,
"}");
803 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
806 WLog_LVL(TAG, g_LogLevel,
"ContextAndTwoStringW_Call {");
807 smartcard_log_context(TAG, &call->handles.hContext);
808 WLog_LVL(TAG, g_LogLevel,
" sz1=%s", call->sz1);
809 WLog_LVL(TAG, g_LogLevel,
" sz2=%s", call->sz2);
810 WLog_LVL(TAG, g_LogLevel,
"}");
815 char sz1[1024] = { 0 };
816 char sz2[1024] = { 0 };
818 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
821 (void)ConvertWCharToUtf8(call->sz1, sz1, ARRAYSIZE(sz1));
823 (void)ConvertWCharToUtf8(call->sz2, sz2, ARRAYSIZE(sz2));
825 WLog_LVL(TAG, g_LogLevel,
"ContextAndTwoStringW_Call {");
826 smartcard_log_context(TAG, &call->handles.hContext);
827 WLog_LVL(TAG, g_LogLevel,
" sz1=%s", sz1);
828 WLog_LVL(TAG, g_LogLevel,
" sz2=%s", sz2);
829 WLog_LVL(TAG, g_LogLevel,
"}");
834 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
837 WLog_LVL(TAG, g_LogLevel,
"GetTransmitCount_Call {");
838 smartcard_log_context(TAG, &call->handles.hContext);
839 smartcard_log_redir_handle(TAG, &call->handles.hCard);
841 WLog_LVL(TAG, g_LogLevel,
"}");
844 static void smartcard_trace_write_cache_a_call(
const WriteCacheA_Call* call)
848 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
851 WLog_LVL(TAG, g_LogLevel,
"WriteCacheA_Call {");
853 WLog_LVL(TAG, g_LogLevel,
" szLookupName=%s", call->szLookupName);
855 smartcard_log_context(TAG, &call->Common.handles.hContext);
857 TAG,
"..CardIdentifier=%s",
858 smartcard_array_dump(call->Common.CardIdentifier,
sizeof(UUID), buffer,
sizeof(buffer)));
859 WLog_LVL(TAG, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
860 WLog_LVL(TAG, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
863 smartcard_array_dump(call->Common.pbData, call->Common.cbDataLen, buffer,
sizeof(buffer)));
864 WLog_LVL(TAG, g_LogLevel,
"}");
867 static void smartcard_trace_write_cache_w_call(
const WriteCacheW_Call* call)
869 char tmp[1024] = { 0 };
870 char buffer[1024] = { 0 };
872 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
875 WLog_LVL(TAG, g_LogLevel,
"WriteCacheW_Call {");
877 if (call->szLookupName)
878 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
879 WLog_LVL(TAG, g_LogLevel,
" szLookupName=%s", tmp);
881 smartcard_log_context(TAG, &call->Common.handles.hContext);
883 TAG,
"..CardIdentifier=%s",
884 smartcard_array_dump(call->Common.CardIdentifier,
sizeof(UUID), buffer,
sizeof(buffer)));
885 WLog_LVL(TAG, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
886 WLog_LVL(TAG, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
889 smartcard_array_dump(call->Common.pbData, call->Common.cbDataLen, buffer,
sizeof(buffer)));
890 WLog_LVL(TAG, g_LogLevel,
"}");
893 static void smartcard_trace_read_cache_a_call(
const ReadCacheA_Call* call)
897 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
900 WLog_LVL(TAG, g_LogLevel,
"ReadCacheA_Call {");
902 WLog_LVL(TAG, g_LogLevel,
" szLookupName=%s", call->szLookupName);
903 smartcard_log_context(TAG, &call->Common.handles.hContext);
905 TAG,
"..CardIdentifier=%s",
906 smartcard_array_dump(call->Common.CardIdentifier,
sizeof(UUID), buffer,
sizeof(buffer)));
907 WLog_LVL(TAG, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
908 WLog_LVL(TAG, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
909 WLog_LVL(TAG, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
911 WLog_LVL(TAG, g_LogLevel,
"}");
914 static void smartcard_trace_read_cache_w_call(
const ReadCacheW_Call* call)
916 char tmp[1024] = { 0 };
917 char buffer[1024] = { 0 };
919 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
922 WLog_LVL(TAG, g_LogLevel,
"ReadCacheW_Call {");
923 if (call->szLookupName)
924 (void)ConvertWCharToUtf8(call->szLookupName, tmp, ARRAYSIZE(tmp));
925 WLog_LVL(TAG, g_LogLevel,
" szLookupName=%s", tmp);
927 smartcard_log_context(TAG, &call->Common.handles.hContext);
929 TAG,
"..CardIdentifier=%s",
930 smartcard_array_dump(call->Common.CardIdentifier,
sizeof(UUID), buffer,
sizeof(buffer)));
931 WLog_LVL(TAG, g_LogLevel,
" FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
932 WLog_LVL(TAG, g_LogLevel,
" fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
933 WLog_LVL(TAG, g_LogLevel,
" cbDataLen=%" PRIu32, call->Common.cbDataLen);
935 WLog_LVL(TAG, g_LogLevel,
"}");
938 static void smartcard_trace_transmit_call(
const Transmit_Call* call)
940 UINT32 cbExtraBytes = 0;
941 BYTE* pbExtraBytes = NULL;
943 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
946 WLog_LVL(TAG, g_LogLevel,
"Transmit_Call {");
947 smartcard_log_context(TAG, &call->handles.hContext);
948 smartcard_log_redir_handle(TAG, &call->handles.hCard);
950 if (call->pioSendPci)
952 cbExtraBytes = (UINT32)(call->pioSendPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
954 WLog_LVL(TAG, g_LogLevel,
"pioSendPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
955 call->pioSendPci->dwProtocol, cbExtraBytes);
960 WLog_LVL(TAG, g_LogLevel,
"pbExtraBytes: %s",
961 smartcard_array_dump(pbExtraBytes, cbExtraBytes, buffer,
sizeof(buffer)));
966 WLog_LVL(TAG, g_LogLevel,
"pioSendPci: null");
969 WLog_LVL(TAG, g_LogLevel,
"cbSendLength: %" PRIu32
"", call->cbSendLength);
971 if (call->pbSendBuffer)
975 TAG,
"pbSendBuffer: %s",
976 smartcard_array_dump(call->pbSendBuffer, call->cbSendLength, buffer,
sizeof(buffer)));
980 WLog_LVL(TAG, g_LogLevel,
"pbSendBuffer: null");
983 if (call->pioRecvPci)
985 cbExtraBytes = (UINT32)(call->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
987 WLog_LVL(TAG, g_LogLevel,
"pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
988 call->pioRecvPci->dwProtocol, cbExtraBytes);
993 WLog_LVL(TAG, g_LogLevel,
"pbExtraBytes: %s",
994 smartcard_array_dump(pbExtraBytes, cbExtraBytes, buffer,
sizeof(buffer)));
999 WLog_LVL(TAG, g_LogLevel,
"pioRecvPci: null");
1002 WLog_LVL(TAG, g_LogLevel,
"fpbRecvBufferIsNULL: %" PRId32
" cbRecvLength: %" PRIu32
"",
1003 call->fpbRecvBufferIsNULL, call->cbRecvLength);
1004 WLog_LVL(TAG, g_LogLevel,
"}");
1009 char* szEventState = NULL;
1010 char* szCurrentState = NULL;
1012 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
1015 WLog_LVL(TAG, g_LogLevel,
"LocateCardsByATRW_Call {");
1016 smartcard_log_context(TAG, &call->handles.hContext);
1018 for (UINT32 index = 0; index < call->cReaders; index++)
1020 char buffer[1024] = { 0 };
1021 char tmp[1024] = { 0 };
1025 if (readerState->szReader)
1026 (void)ConvertWCharToUtf8(readerState->szReader, tmp, ARRAYSIZE(tmp));
1027 WLog_LVL(TAG, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index, tmp,
1028 readerState->cbAtr);
1029 szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
1030 szEventState = SCardGetReaderStateString(readerState->dwEventState);
1031 WLog_LVL(TAG, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
1032 szCurrentState, readerState->dwCurrentState);
1033 WLog_LVL(TAG, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
1034 szEventState, readerState->dwEventState);
1037 TAG,
"\t[%" PRIu32
"]: cbAtr: %" PRIu32
" rgbAtr: %s", index, readerState->cbAtr,
1038 smartcard_array_dump(readerState->rgbAtr, readerState->cbAtr, buffer,
sizeof(buffer)));
1040 free(szCurrentState);
1044 WLog_LVL(TAG, g_LogLevel,
"}");
1047 static void smartcard_trace_transmit_return(
const Transmit_Return* ret)
1049 UINT32 cbExtraBytes = 0;
1050 BYTE* pbExtraBytes = NULL;
1052 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
1055 WLog_LVL(TAG, g_LogLevel,
"Transmit_Return {");
1056 WLog_LVL(TAG, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1057 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
1059 if (ret->pioRecvPci)
1061 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
1063 WLog_LVL(TAG, g_LogLevel,
" pioRecvPci: dwProtocol: %" PRIu32
" cbExtraBytes: %" PRIu32
"",
1064 ret->pioRecvPci->dwProtocol, cbExtraBytes);
1069 WLog_LVL(TAG, g_LogLevel,
" pbExtraBytes: %s",
1070 smartcard_array_dump(pbExtraBytes, cbExtraBytes, buffer,
sizeof(buffer)));
1075 WLog_LVL(TAG, g_LogLevel,
" pioRecvPci: null");
1078 WLog_LVL(TAG, g_LogLevel,
" cbRecvLength: %" PRIu32
"", ret->cbRecvLength);
1080 if (ret->pbRecvBuffer)
1084 TAG,
" pbRecvBuffer: %s",
1085 smartcard_array_dump(ret->pbRecvBuffer, ret->cbRecvLength, buffer,
sizeof(buffer)));
1089 WLog_LVL(TAG, g_LogLevel,
" pbRecvBuffer: null");
1092 WLog_LVL(TAG, g_LogLevel,
"}");
1095 static void smartcard_trace_control_return(
const Control_Return* ret)
1097 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
1100 WLog_LVL(TAG, g_LogLevel,
"Control_Return {");
1101 WLog_LVL(TAG, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1102 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
1103 WLog_LVL(TAG, g_LogLevel,
" cbOutBufferSize: %" PRIu32
"", ret->cbOutBufferSize);
1105 if (ret->pvOutBuffer)
1109 TAG,
"pvOutBuffer: %s",
1110 smartcard_array_dump(ret->pvOutBuffer, ret->cbOutBufferSize, buffer,
sizeof(buffer)));
1114 WLog_LVL(TAG, g_LogLevel,
"pvOutBuffer: null");
1117 WLog_LVL(TAG, g_LogLevel,
"}");
1120 static void smartcard_trace_control_call(
const Control_Call* call)
1122 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
1125 WLog_LVL(TAG, g_LogLevel,
"Control_Call {");
1126 smartcard_log_context(TAG, &call->handles.hContext);
1127 smartcard_log_redir_handle(TAG, &call->handles.hCard);
1129 WLog_LVL(TAG, g_LogLevel,
1130 "dwControlCode: 0x%08" PRIX32
" cbInBufferSize: %" PRIu32
1131 " fpvOutBufferIsNULL: %" PRId32
" cbOutBufferSize: %" PRIu32
"",
1132 call->dwControlCode, call->cbInBufferSize, call->fpvOutBufferIsNULL,
1133 call->cbOutBufferSize);
1135 if (call->pvInBuffer)
1139 TAG,
"pbInBuffer: %s",
1140 smartcard_array_dump(call->pvInBuffer, call->cbInBufferSize, buffer,
sizeof(buffer)));
1144 WLog_LVL(TAG, g_LogLevel,
"pvInBuffer: null");
1147 WLog_LVL(TAG, g_LogLevel,
"}");
1150 static void smartcard_trace_set_attrib_call(
const SetAttrib_Call* call)
1154 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
1157 WLog_LVL(TAG, g_LogLevel,
"GetAttrib_Call {");
1158 smartcard_log_context(TAG, &call->handles.hContext);
1159 smartcard_log_redir_handle(TAG, &call->handles.hCard);
1160 WLog_LVL(TAG, g_LogLevel,
"dwAttrId: 0x%08" PRIX32, call->dwAttrId);
1161 WLog_LVL(TAG, g_LogLevel,
"cbAttrLen: 0x%08" PRId32, call->cbAttrLen);
1162 WLog_LVL(TAG, g_LogLevel,
"pbAttr: %s",
1163 smartcard_array_dump(call->pbAttr, call->cbAttrLen, buffer,
sizeof(buffer)));
1164 WLog_LVL(TAG, g_LogLevel,
"}");
1167 static void smartcard_trace_get_attrib_return(
const GetAttrib_Return* ret, DWORD dwAttrId)
1170 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
1173 WLog_LVL(TAG, g_LogLevel,
"GetAttrib_Return {");
1174 WLog_LVL(TAG, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1175 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
1176 WLog_LVL(TAG, g_LogLevel,
" dwAttrId: %s (0x%08" PRIX32
") cbAttrLen: 0x%08" PRIX32
"",
1177 SCardGetAttributeString(dwAttrId), dwAttrId, ret->cbAttrLen);
1179 if (dwAttrId == SCARD_ATTR_VENDOR_NAME)
1181 WLog_LVL(TAG, g_LogLevel,
" pbAttr: %.*s", ret->cbAttrLen, (
char*)ret->pbAttr);
1183 else if (dwAttrId == SCARD_ATTR_CURRENT_PROTOCOL_TYPE)
1190 attr.pb = ret->pbAttr;
1191 WLog_LVL(TAG, g_LogLevel,
" dwProtocolType: %s (0x%08" PRIX32
")",
1192 SCardGetProtocolString(*attr.pd), *attr.pd);
1195 WLog_LVL(TAG, g_LogLevel,
"}");
1198 static void smartcard_trace_get_attrib_call(
const GetAttrib_Call* call)
1200 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
1203 WLog_LVL(TAG, g_LogLevel,
"GetAttrib_Call {");
1204 smartcard_log_context(TAG, &call->handles.hContext);
1205 smartcard_log_redir_handle(TAG, &call->handles.hCard);
1207 WLog_LVL(TAG, g_LogLevel,
1208 "dwAttrId: %s (0x%08" PRIX32
") fpbAttrIsNULL: %" PRId32
" cbAttrLen: 0x%08" PRIX32
"",
1209 SCardGetAttributeString(call->dwAttrId), call->dwAttrId, call->fpbAttrIsNULL,
1211 WLog_LVL(TAG, g_LogLevel,
"}");
1214 static void smartcard_trace_status_call(
const Status_Call* call, BOOL unicode)
1216 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
1219 WLog_LVL(TAG, g_LogLevel,
"Status%s_Call {", unicode ?
"W" :
"A");
1220 smartcard_log_context(TAG, &call->handles.hContext);
1221 smartcard_log_redir_handle(TAG, &call->handles.hCard);
1223 WLog_LVL(TAG, g_LogLevel,
1224 "fmszReaderNamesIsNULL: %" PRId32
" cchReaderLen: %" PRIu32
" cbAtrLen: %" PRIu32
"",
1225 call->fmszReaderNamesIsNULL, call->cchReaderLen, call->cbAtrLen);
1226 WLog_LVL(TAG, g_LogLevel,
"}");
1229 static void smartcard_trace_status_return(
const Status_Return* ret, BOOL unicode)
1231 char* mszReaderNamesA = NULL;
1235 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
1237 cBytes = ret->cBytes;
1238 if (ret->ReturnCode != SCARD_S_SUCCESS)
1240 if (cBytes == SCARD_AUTOALLOCATE)
1242 mszReaderNamesA = smartcard_convert_string_list(ret->mszReaderNames, cBytes, unicode);
1244 WLog_LVL(TAG, g_LogLevel,
"Status%s_Return {", unicode ?
"W" :
"A");
1245 WLog_LVL(TAG, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1246 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
1247 WLog_LVL(TAG, g_LogLevel,
" dwState: %s (0x%08" PRIX32
") dwProtocol: %s (0x%08" PRIX32
")",
1248 SCardGetCardStateString(ret->dwState), ret->dwState,
1249 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1251 WLog_LVL(TAG, g_LogLevel,
" cBytes: %" PRIu32
" mszReaderNames: %s", ret->cBytes,
1254 WLog_LVL(TAG, g_LogLevel,
" cbAtrLen: %" PRIu32
" pbAtr: %s", ret->cbAtrLen,
1255 smartcard_array_dump(ret->pbAtr, ret->cbAtrLen, buffer,
sizeof(buffer)));
1256 WLog_LVL(TAG, g_LogLevel,
"}");
1257 free(mszReaderNamesA);
1260 static void smartcard_trace_state_return(
const State_Return* ret)
1265 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
1268 state = SCardGetReaderStateString(ret->dwState);
1269 WLog_LVL(TAG, g_LogLevel,
"Reconnect_Return {");
1270 WLog_LVL(TAG, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1271 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
1272 WLog_LVL(TAG, g_LogLevel,
" dwState: %s (0x%08" PRIX32
")", state, ret->dwState);
1273 WLog_LVL(TAG, g_LogLevel,
" dwProtocol: %s (0x%08" PRIX32
")",
1274 SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
1275 WLog_LVL(TAG, g_LogLevel,
" cbAtrLen: (0x%08" PRIX32
")", ret->cbAtrLen);
1276 WLog_LVL(TAG, g_LogLevel,
" rgAtr: %s",
1277 smartcard_array_dump(ret->rgAtr,
sizeof(ret->rgAtr), buffer,
sizeof(buffer)));
1278 WLog_LVL(TAG, g_LogLevel,
"}");
1285 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
1288 WLog_LVL(TAG, g_LogLevel,
"Reconnect_Return {");
1289 WLog_LVL(TAG, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1290 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
1291 WLog_LVL(TAG, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1292 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1293 WLog_LVL(TAG, g_LogLevel,
"}");
1296 static void smartcard_trace_connect_a_call(
const ConnectA_Call* call)
1299 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
1302 WLog_LVL(TAG, g_LogLevel,
"ConnectA_Call {");
1303 smartcard_log_context(TAG, &call->Common.handles.hContext);
1305 WLog_LVL(TAG, g_LogLevel,
1306 "szReader: %s dwShareMode: %s (0x%08" PRIX32
") dwPreferredProtocols: %s (0x%08" PRIX32
1308 call->szReader, SCardGetShareModeString(call->Common.dwShareMode),
1309 call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
1310 call->Common.dwPreferredProtocols);
1311 WLog_LVL(TAG, g_LogLevel,
"}");
1314 static void smartcard_trace_connect_w_call(
const ConnectW_Call* call)
1316 char szReaderA[1024] = { 0 };
1318 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
1322 (void)ConvertWCharToUtf8(call->szReader, szReaderA, ARRAYSIZE(szReaderA));
1323 WLog_LVL(TAG, g_LogLevel,
"ConnectW_Call {");
1324 smartcard_log_context(TAG, &call->Common.handles.hContext);
1326 WLog_LVL(TAG, g_LogLevel,
1327 "szReader: %s dwShareMode: %s (0x%08" PRIX32
") dwPreferredProtocols: %s (0x%08" PRIX32
1329 szReaderA, SCardGetShareModeString(call->Common.dwShareMode), call->Common.dwShareMode,
1330 SCardGetProtocolString(call->Common.dwPreferredProtocols),
1331 call->Common.dwPreferredProtocols);
1332 WLog_LVL(TAG, g_LogLevel,
"}");
1338 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
1341 WLog_LVL(TAG, g_LogLevel,
"%s_Call {", name);
1342 smartcard_log_context(TAG, &call->handles.hContext);
1343 smartcard_log_redir_handle(TAG, &call->handles.hCard);
1345 WLog_LVL(TAG, g_LogLevel,
"dwDisposition: %s (0x%08" PRIX32
")",
1346 SCardGetDispositionString(call->dwDisposition), call->dwDisposition);
1347 WLog_LVL(TAG, g_LogLevel,
"}");
1353 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
1356 WLog_LVL(TAG, g_LogLevel,
"EstablishContext_Call {");
1357 WLog_LVL(TAG, g_LogLevel,
"dwScope: %s (0x%08" PRIX32
")", SCardGetScopeString(call->dwScope),
1359 WLog_LVL(TAG, g_LogLevel,
"}");
1365 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
1368 WLog_LVL(TAG, g_LogLevel,
"EstablishContext_Return {");
1369 WLog_LVL(TAG, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1370 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
1371 smartcard_log_context(TAG, &ret->hContext);
1373 WLog_LVL(TAG, g_LogLevel,
"}");
1376 void smartcard_trace_long_return(
const Long_Return* ret,
const char* name)
1378 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
1381 WLog_LVL(TAG, g_LogLevel,
"%s_Return {", name);
1382 WLog_LVL(TAG, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1383 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
1384 WLog_LVL(TAG, g_LogLevel,
"}");
1387 static void smartcard_trace_connect_return(
const Connect_Return* ret)
1389 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
1392 WLog_LVL(TAG, g_LogLevel,
"Connect_Return {");
1393 WLog_LVL(TAG, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1394 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
1395 smartcard_log_context(TAG, &ret->hContext);
1396 smartcard_log_redir_handle(TAG, &ret->hCard);
1398 WLog_LVL(TAG, g_LogLevel,
" dwActiveProtocol: %s (0x%08" PRIX32
")",
1399 SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
1400 WLog_LVL(TAG, g_LogLevel,
"}");
1403 static void smartcard_trace_reconnect_call(
const Reconnect_Call* call)
1405 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
1408 WLog_LVL(TAG, g_LogLevel,
"Reconnect_Call {");
1409 smartcard_log_context(TAG, &call->handles.hContext);
1410 smartcard_log_redir_handle(TAG, &call->handles.hCard);
1412 WLog_LVL(TAG, g_LogLevel,
1413 "dwShareMode: %s (0x%08" PRIX32
") dwPreferredProtocols: %s (0x%08" PRIX32
1414 ") dwInitialization: %s (0x%08" PRIX32
")",
1415 SCardGetShareModeString(call->dwShareMode), call->dwShareMode,
1416 SCardGetProtocolString(call->dwPreferredProtocols), call->dwPreferredProtocols,
1417 SCardGetDispositionString(call->dwInitialization), call->dwInitialization);
1418 WLog_LVL(TAG, g_LogLevel,
"}");
1423 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
1426 WLog_LVL(TAG, g_LogLevel,
"GetDeviceTypeId_Return {");
1427 WLog_LVL(TAG, g_LogLevel,
" ReturnCode: %s (0x%08" PRIX32
")",
1428 SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
1429 WLog_LVL(TAG, g_LogLevel,
" dwDeviceId=%08" PRIx32, ret->dwDeviceId);
1431 WLog_LVL(TAG, g_LogLevel,
"}");
1435 CHAR** pszReaderName)
1438 UINT32 pbContextNdrPtr = 0;
1439 LONG status = smartcard_unpack_redir_scard_context(s, phContext, &index, &pbContextNdrPtr);
1440 if (status != SCARD_S_SUCCESS)
1443 if (!smartcard_ndr_pointer_read(s, &index, NULL))
1444 return ERROR_INVALID_DATA;
1446 status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr, phContext);
1447 if (status != SCARD_S_SUCCESS)
1450 status = smartcard_ndr_read_a(s, pszReaderName, NDR_PTR_FULL);
1451 if (status != SCARD_S_SUCCESS)
1454 smartcard_trace_context_and_string_call_a(__func__, phContext, *pszReaderName);
1455 return SCARD_S_SUCCESS;
1459 WCHAR** pszReaderName)
1462 UINT32 pbContextNdrPtr = 0;
1464 LONG status = smartcard_unpack_redir_scard_context(s, phContext, &index, &pbContextNdrPtr);
1465 if (status != SCARD_S_SUCCESS)
1468 if (!smartcard_ndr_pointer_read(s, &index, NULL))
1469 return ERROR_INVALID_DATA;
1471 status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr, phContext);
1472 if (status != SCARD_S_SUCCESS)
1475 status = smartcard_ndr_read_w(s, pszReaderName, NDR_PTR_FULL);
1476 if (status != SCARD_S_SUCCESS)
1479 smartcard_trace_context_and_string_call_w(__func__, phContext, *pszReaderName);
1480 return SCARD_S_SUCCESS;
1483 LONG smartcard_unpack_common_type_header(
wStream* s)
1487 UINT8 endianness = 0;
1488 UINT16 commonHeaderLength = 0;
1490 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
1491 return STATUS_BUFFER_TOO_SMALL;
1494 Stream_Read_UINT8(s, version);
1495 Stream_Read_UINT8(s, endianness);
1496 Stream_Read_UINT16(s, commonHeaderLength);
1497 Stream_Read_UINT32(s, filler);
1501 WLog_WARN(TAG,
"Unsupported CommonTypeHeader Version %" PRIu8
"", version);
1502 return STATUS_INVALID_PARAMETER;
1505 if (endianness != 0x10)
1507 WLog_WARN(TAG,
"Unsupported CommonTypeHeader Endianness %" PRIu8
"", endianness);
1508 return STATUS_INVALID_PARAMETER;
1511 if (commonHeaderLength != 8)
1513 WLog_WARN(TAG,
"Unsupported CommonTypeHeader CommonHeaderLength %" PRIu16
"",
1514 commonHeaderLength);
1515 return STATUS_INVALID_PARAMETER;
1518 if (filler != 0xCCCCCCCC)
1520 WLog_WARN(TAG,
"Unexpected CommonTypeHeader Filler 0x%08" PRIX32
"", filler);
1521 return STATUS_INVALID_PARAMETER;
1524 return SCARD_S_SUCCESS;
1527 void smartcard_pack_common_type_header(
wStream* s)
1529 Stream_Write_UINT8(s, 1);
1530 Stream_Write_UINT8(s, 0x10);
1531 Stream_Write_UINT16(s, 8);
1532 Stream_Write_UINT32(s, 0xCCCCCCCC);
1535 LONG smartcard_unpack_private_type_header(
wStream* s)
1538 UINT32 objectBufferLength = 0;
1540 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
1541 return STATUS_BUFFER_TOO_SMALL;
1543 Stream_Read_UINT32(s, objectBufferLength);
1544 Stream_Read_UINT32(s, filler);
1546 if (filler != 0x00000000)
1548 WLog_WARN(TAG,
"Unexpected PrivateTypeHeader Filler 0x%08" PRIX32
"", filler);
1549 return STATUS_INVALID_PARAMETER;
1552 if (!Stream_CheckAndLogRequiredLength(TAG, s, objectBufferLength))
1553 return STATUS_INVALID_PARAMETER;
1555 return SCARD_S_SUCCESS;
1558 void smartcard_pack_private_type_header(
wStream* s, UINT32 objectBufferLength)
1560 Stream_Write_UINT32(s, objectBufferLength);
1561 Stream_Write_UINT32(s, 0x00000000);
1564 LONG smartcard_unpack_read_size_align(
wStream* s,
size_t size, UINT32 alignment)
1569 size = (size + alignment - 1) & ~(alignment - 1);
1573 Stream_Seek(s, pad);
1578 LONG smartcard_pack_write_size_align(
wStream* s,
size_t size, UINT32 alignment)
1583 size = (size + alignment - 1) & ~(alignment - 1);
1588 if (!Stream_EnsureRemainingCapacity(s, pad))
1590 WLog_ERR(TAG,
"Stream_EnsureRemainingCapacity failed!");
1591 return SCARD_F_INTERNAL_ERROR;
1594 Stream_Zero(s, pad);
1597 return SCARD_S_SUCCESS;
1602 SCARDCONTEXT hContext = { 0 };
1604 if ((context->cbContext !=
sizeof(ULONG_PTR)) && (context->cbContext != 0))
1607 "REDIR_SCARDCONTEXT does not match native size: Actual: %" PRIu32
1608 ", Expected: %" PRIuz
"",
1609 context->cbContext,
sizeof(ULONG_PTR));
1613 if (context->cbContext)
1614 CopyMemory(&hContext, &(context->pbContext), context->cbContext);
1619 void smartcard_scard_context_native_to_redir(
REDIR_SCARDCONTEXT* context, SCARDCONTEXT hContext)
1621 WINPR_ASSERT(context);
1623 context->cbContext =
sizeof(ULONG_PTR);
1624 CopyMemory(&(context->pbContext), &hContext, context->cbContext);
1629 SCARDHANDLE hCard = 0;
1631 if (handle->cbHandle == 0)
1634 if (handle->cbHandle !=
sizeof(ULONG_PTR))
1637 "REDIR_SCARDHANDLE does not match native size: Actual: %" PRIu32
1638 ", Expected: %" PRIuz
"",
1639 handle->cbHandle,
sizeof(ULONG_PTR));
1643 if (handle->cbHandle)
1644 CopyMemory(&hCard, &(handle->pbHandle), handle->cbHandle);
1649 void smartcard_scard_handle_native_to_redir(
REDIR_SCARDHANDLE* handle, SCARDHANDLE hCard)
1651 WINPR_ASSERT(handle);
1653 handle->cbHandle =
sizeof(ULONG_PTR);
1654 CopyMemory(&(handle->pbHandle), &hCard, handle->cbHandle);
1658 UINT32* ppbContextNdrPtr,
const char* file,
1659 const char*
function,
int line)
1661 UINT32 pbContextNdrPtr = 0;
1664 WINPR_ASSERT(context);
1668 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
1669 return STATUS_BUFFER_TOO_SMALL;
1671 Stream_Read_UINT32(s, context->cbContext);
1673 if (!Stream_CheckAndLogRequiredLength(TAG, s, context->cbContext))
1674 return STATUS_BUFFER_TOO_SMALL;
1676 if ((context->cbContext != 0) && (context->cbContext != 4) && (context->cbContext != 8))
1678 WLog_WARN(TAG,
"REDIR_SCARDCONTEXT length is not 0, 4 or 8: %" PRIu32
"",
1679 context->cbContext);
1680 return STATUS_INVALID_PARAMETER;
1683 if (!smartcard_ndr_pointer_read_(s, index, &pbContextNdrPtr, file,
function, line))
1684 return ERROR_INVALID_DATA;
1686 if (((context->cbContext == 0) && pbContextNdrPtr) ||
1687 ((context->cbContext != 0) && !pbContextNdrPtr))
1690 "REDIR_SCARDCONTEXT cbContext (%" PRIu32
") pbContextNdrPtr (%" PRIu32
1692 context->cbContext, pbContextNdrPtr);
1693 return STATUS_INVALID_PARAMETER;
1696 if (!Stream_CheckAndLogRequiredLength(TAG, s, context->cbContext))
1697 return STATUS_INVALID_PARAMETER;
1699 *ppbContextNdrPtr = pbContextNdrPtr;
1700 return SCARD_S_SUCCESS;
1705 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
1707 if (context->cbContext != 0)
1709 Stream_Write_UINT32(s, context->cbContext);
1710 Stream_Write_UINT32(s, pbContextNdrPtr);
1711 *index = *index + 1;
1716 return SCARD_S_SUCCESS;
1719 LONG smartcard_unpack_redir_scard_context_ref(
wStream* s, UINT32 pbContextNdrPtr,
1724 WINPR_ASSERT(context);
1725 if (context->cbContext == 0)
1726 return SCARD_S_SUCCESS;
1728 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
1729 return STATUS_BUFFER_TOO_SMALL;
1731 Stream_Read_UINT32(s, length);
1733 if (length != context->cbContext)
1735 WLog_WARN(TAG,
"REDIR_SCARDCONTEXT length (%" PRIu32
") cbContext (%" PRIu32
") mismatch",
1736 length, context->cbContext);
1737 return STATUS_INVALID_PARAMETER;
1740 if ((context->cbContext != 0) && (context->cbContext != 4) && (context->cbContext != 8))
1742 WLog_WARN(TAG,
"REDIR_SCARDCONTEXT length is not 4 or 8: %" PRIu32
"", context->cbContext);
1743 return STATUS_INVALID_PARAMETER;
1746 if (!Stream_CheckAndLogRequiredLength(TAG, s, context->cbContext))
1747 return STATUS_BUFFER_TOO_SMALL;
1749 if (context->cbContext)
1750 Stream_Read(s, &(context->pbContext), context->cbContext);
1752 ZeroMemory(&(context->pbContext),
sizeof(context->pbContext));
1754 return SCARD_S_SUCCESS;
1760 Stream_Write_UINT32(s, context->cbContext);
1762 if (context->cbContext)
1764 Stream_Write(s, &(context->pbContext), context->cbContext);
1767 return SCARD_S_SUCCESS;
1771 const char* file,
const char*
function,
int line)
1773 WINPR_ASSERT(handle);
1776 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
1777 return STATUS_BUFFER_TOO_SMALL;
1779 Stream_Read_UINT32(s, handle->cbHandle);
1781 if (!Stream_CheckAndLogRequiredLength(TAG, s, handle->cbHandle))
1782 return STATUS_BUFFER_TOO_SMALL;
1784 if (!smartcard_ndr_pointer_read_(s, index, NULL, file,
function, line))
1785 return ERROR_INVALID_DATA;
1787 return SCARD_S_SUCCESS;
1792 const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
1794 if (handle->cbHandle != 0)
1796 Stream_Write_UINT32(s, handle->cbHandle);
1797 Stream_Write_UINT32(s, pbContextNdrPtr);
1798 *index = *index + 1;
1802 return SCARD_S_SUCCESS;
1809 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
1810 return STATUS_BUFFER_TOO_SMALL;
1812 Stream_Read_UINT32(s, length);
1814 if (length != handle->cbHandle)
1816 WLog_WARN(TAG,
"REDIR_SCARDHANDLE length (%" PRIu32
") cbHandle (%" PRIu32
") mismatch",
1817 length, handle->cbHandle);
1818 return STATUS_INVALID_PARAMETER;
1821 if ((handle->cbHandle != 4) && (handle->cbHandle != 8))
1823 WLog_WARN(TAG,
"REDIR_SCARDHANDLE length is not 4 or 8: %" PRIu32
"", handle->cbHandle);
1824 return STATUS_INVALID_PARAMETER;
1827 if (!Stream_CheckAndLogRequiredLength(TAG, s, handle->cbHandle))
1828 return STATUS_BUFFER_TOO_SMALL;
1830 if (handle->cbHandle)
1831 Stream_Read(s, &(handle->pbHandle), handle->cbHandle);
1833 return SCARD_S_SUCCESS;
1839 Stream_Write_UINT32(s, handle->cbHandle);
1841 if (handle->cbHandle)
1842 Stream_Write(s, &(handle->pbHandle), handle->cbHandle);
1844 return SCARD_S_SUCCESS;
1849 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
1850 return STATUS_BUFFER_TOO_SMALL;
1852 Stream_Read_UINT32(s, call->dwScope);
1853 smartcard_trace_establish_context_call(call);
1854 return SCARD_S_SUCCESS;
1862 smartcard_trace_establish_context_return(ret);
1863 if (ret->ReturnCode != SCARD_S_SUCCESS)
1864 return ret->ReturnCode;
1866 if ((status = smartcard_pack_redir_scard_context(s, &(ret->hContext), &index)))
1869 return smartcard_pack_redir_scard_context_ref(s, &(ret->hContext));
1875 UINT32 pbContextNdrPtr = 0;
1877 LONG status = smartcard_unpack_redir_scard_context(s, &(call->handles.hContext), &index,
1879 if (status != SCARD_S_SUCCESS)
1882 if ((status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
1883 &(call->handles.hContext))))
1884 WLog_ERR(TAG,
"smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
1887 smartcard_trace_context_call(call, name);
1894 UINT32 pbContextNdrPtr = 0;
1896 LONG status = smartcard_unpack_redir_scard_context(s, &(call->handles.hContext), &index,
1899 if (status != SCARD_S_SUCCESS)
1902 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
1903 return STATUS_BUFFER_TOO_SMALL;
1905 Stream_Read_INT32(s, call->fmszGroupsIsNULL);
1906 Stream_Read_UINT32(s, call->cchGroups);
1908 smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr, &(call->handles.hContext));
1910 if (status != SCARD_S_SUCCESS)
1913 smartcard_trace_list_reader_groups_call(call, unicode);
1914 return SCARD_S_SUCCESS;
1921 DWORD cBytes = ret->cBytes;
1924 smartcard_trace_list_reader_groups_return(ret, unicode);
1925 if (ret->ReturnCode != SCARD_S_SUCCESS)
1927 if (cBytes == SCARD_AUTOALLOCATE)
1930 if (!Stream_EnsureRemainingCapacity(s, 4))
1931 return SCARD_E_NO_MEMORY;
1933 Stream_Write_UINT32(s, cBytes);
1934 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
1935 return SCARD_E_NO_MEMORY;
1937 status = smartcard_ndr_write(s, ret->msz, cBytes, 1, NDR_PTR_SIMPLE);
1938 if (status != SCARD_S_SUCCESS)
1940 return ret->ReturnCode;
1946 UINT32 mszGroupsNdrPtr = 0;
1947 UINT32 pbContextNdrPtr = 0;
1949 call->mszGroups = NULL;
1951 LONG status = smartcard_unpack_redir_scard_context(s, &(call->handles.hContext), &index,
1953 if (status != SCARD_S_SUCCESS)
1956 if (!Stream_CheckAndLogRequiredLength(TAG, s, 16))
1957 return STATUS_BUFFER_TOO_SMALL;
1959 Stream_Read_UINT32(s, call->cBytes);
1960 if (!smartcard_ndr_pointer_read(s, &index, &mszGroupsNdrPtr))
1961 return ERROR_INVALID_DATA;
1962 Stream_Read_INT32(s, call->fmszReadersIsNULL);
1963 Stream_Read_UINT32(s, call->cchReaders);
1965 if ((status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
1966 &(call->handles.hContext))))
1969 if (mszGroupsNdrPtr)
1971 status = smartcard_ndr_read(s, &call->mszGroups, call->cBytes, 1, NDR_PTR_SIMPLE);
1972 if (status != SCARD_S_SUCCESS)
1976 smartcard_trace_list_readers_call(call, unicode);
1977 return SCARD_S_SUCCESS;
1984 UINT32 size = ret->cBytes;
1986 smartcard_trace_list_readers_return(ret, unicode);
1987 if (ret->ReturnCode != SCARD_S_SUCCESS)
1990 if (!Stream_EnsureRemainingCapacity(s, 4))
1992 WLog_ERR(TAG,
"Stream_EnsureRemainingCapacity failed!");
1993 return SCARD_F_INTERNAL_ERROR;
1996 Stream_Write_UINT32(s, size);
1997 if (!smartcard_ndr_pointer_write(s, &index, size))
1998 return SCARD_E_NO_MEMORY;
2000 status = smartcard_ndr_write(s, ret->msz, size, 1, NDR_PTR_SIMPLE);
2001 if (status != SCARD_S_SUCCESS)
2003 return ret->ReturnCode;
2007 UINT32* ppbContextNdrPtr)
2009 LONG status = smartcard_unpack_redir_scard_context(s, &(common->handles.hContext), index,
2011 if (status != SCARD_S_SUCCESS)
2014 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
2015 return STATUS_BUFFER_TOO_SMALL;
2017 Stream_Read_UINT32(s, common->dwShareMode);
2018 Stream_Read_UINT32(s, common->dwPreferredProtocols);
2019 return SCARD_S_SUCCESS;
2026 UINT32 pbContextNdrPtr = 0;
2027 call->szReader = NULL;
2029 if (!smartcard_ndr_pointer_read(s, &index, NULL))
2030 return ERROR_INVALID_DATA;
2032 if ((status = smartcard_unpack_connect_common(s, &(call->Common), &index, &pbContextNdrPtr)))
2034 WLog_ERR(TAG,
"smartcard_unpack_connect_common failed with error %" PRId32
"", status);
2038 status = smartcard_ndr_read_a(s, &call->szReader, NDR_PTR_FULL);
2039 if (status != SCARD_S_SUCCESS)
2042 if ((status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
2043 &(call->Common.handles.hContext))))
2044 WLog_ERR(TAG,
"smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2047 smartcard_trace_connect_a_call(call);
2055 UINT32 pbContextNdrPtr = 0;
2057 call->szReader = NULL;
2059 if (!smartcard_ndr_pointer_read(s, &index, NULL))
2060 return ERROR_INVALID_DATA;
2062 if ((status = smartcard_unpack_connect_common(s, &(call->Common), &index, &pbContextNdrPtr)))
2064 WLog_ERR(TAG,
"smartcard_unpack_connect_common failed with error %" PRId32
"", status);
2068 status = smartcard_ndr_read_w(s, &call->szReader, NDR_PTR_FULL);
2069 if (status != SCARD_S_SUCCESS)
2072 if ((status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
2073 &(call->Common.handles.hContext))))
2074 WLog_ERR(TAG,
"smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2077 smartcard_trace_connect_w_call(call);
2086 smartcard_trace_connect_return(ret);
2088 status = smartcard_pack_redir_scard_context(s, &ret->hContext, &index);
2089 if (status != SCARD_S_SUCCESS)
2092 status = smartcard_pack_redir_scard_handle(s, &ret->hCard, &index);
2093 if (status != SCARD_S_SUCCESS)
2096 if (!Stream_EnsureRemainingCapacity(s, 4))
2097 return SCARD_E_NO_MEMORY;
2099 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2100 status = smartcard_pack_redir_scard_context_ref(s, &ret->hContext);
2101 if (status != SCARD_S_SUCCESS)
2103 return smartcard_pack_redir_scard_handle_ref(s, &(ret->hCard));
2109 UINT32 pbContextNdrPtr = 0;
2110 LONG status = smartcard_unpack_redir_scard_context(s, &(call->handles.hContext), &index,
2112 if (status != SCARD_S_SUCCESS)
2115 status = smartcard_unpack_redir_scard_handle(s, &(call->handles.hCard), &index);
2116 if (status != SCARD_S_SUCCESS)
2119 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
2120 return STATUS_BUFFER_TOO_SMALL;
2122 Stream_Read_UINT32(s, call->dwShareMode);
2123 Stream_Read_UINT32(s, call->dwPreferredProtocols);
2124 Stream_Read_UINT32(s, call->dwInitialization);
2126 if ((status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
2127 &(call->handles.hContext))))
2129 WLog_ERR(TAG,
"smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
2134 if ((status = smartcard_unpack_redir_scard_handle_ref(s, &(call->handles.hCard))))
2135 WLog_ERR(TAG,
"smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"",
2138 smartcard_trace_reconnect_call(call);
2144 smartcard_trace_reconnect_return(ret);
2146 if (!Stream_EnsureRemainingCapacity(s, 4))
2147 return SCARD_E_NO_MEMORY;
2148 Stream_Write_UINT32(s, ret->dwActiveProtocol);
2149 return ret->ReturnCode;
2156 UINT32 pbContextNdrPtr = 0;
2158 LONG status = smartcard_unpack_redir_scard_context(s, &(call->handles.hContext), &index,
2160 if (status != SCARD_S_SUCCESS)
2163 status = smartcard_unpack_redir_scard_handle(s, &(call->handles.hCard), &index);
2164 if (status != SCARD_S_SUCCESS)
2167 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
2168 return STATUS_BUFFER_TOO_SMALL;
2170 Stream_Read_UINT32(s, call->dwDisposition);
2172 if ((status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
2173 &(call->handles.hContext))))
2176 if ((status = smartcard_unpack_redir_scard_handle_ref(s, &(call->handles.hCard))))
2179 smartcard_trace_hcard_and_disposition_call(call, name);
2185 if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
2188 WLog_LVL(TAG, g_LogLevel,
"GetStatusChangeA_Call {");
2189 smartcard_log_context(TAG, &call->handles.hContext);
2191 WLog_LVL(TAG, g_LogLevel,
"dwTimeOut: 0x%08" PRIX32
" cReaders: %" PRIu32
"", call->dwTimeOut,
2194 for (UINT32 index = 0; index < call->cReaders; index++)
2197 WLog_LVL(TAG, g_LogLevel,
"\t[%" PRIu32
"]: szReader: %s cbAtr: %" PRIu32
"", index,
2198 readerState->szReader, readerState->cbAtr);
2199 char* szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
2200 char* szEventState = SCardGetReaderStateString(readerState->dwEventState);
2201 WLog_LVL(TAG, g_LogLevel,
"\t[%" PRIu32
"]: dwCurrentState: %s (0x%08" PRIX32
")", index,
2202 szCurrentState, readerState->dwCurrentState);
2203 WLog_LVL(TAG, g_LogLevel,
"\t[%" PRIu32
"]: dwEventState: %s (0x%08" PRIX32
")", index,
2204 szEventState, readerState->dwEventState);
2205 free(szCurrentState);
2209 WLog_LVL(TAG, g_LogLevel,
"}");
2213 UINT32 cReaders, UINT32* ptrIndex)
2215 LONG status = SCARD_E_NO_MEMORY;
2217 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
2220 const UINT32 len = Stream_Get_UINT32(s);
2221 if (len != cReaders)
2223 WLog_ERR(TAG,
"Count mismatch when reading LPSCARD_READERSTATEA");
2229 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2230 if (!rgReaderStates || !states)
2232 status = ERROR_INVALID_DATA;
2234 for (UINT32 index = 0; index < cReaders; index++)
2236 UINT32 ptr = UINT32_MAX;
2239 if (!Stream_CheckAndLogRequiredLength(TAG, s, 52))
2242 if (!smartcard_ndr_pointer_read(s, ptrIndex, &ptr))
2248 states[index] = ptr != 0;
2249 Stream_Read_UINT32(s, readerState->dwCurrentState);
2250 Stream_Read_UINT32(s, readerState->dwEventState);
2251 Stream_Read_UINT32(s, readerState->cbAtr);
2252 Stream_Read(s, readerState->rgbAtr, 36);
2255 for (UINT32 index = 0; index < cReaders; index++)
2262 status = smartcard_ndr_read_a(s, &readerState->szReader, NDR_PTR_FULL);
2263 if (status != SCARD_S_SUCCESS)
2267 *ppcReaders = rgReaderStates;
2269 return SCARD_S_SUCCESS;
2273 for (UINT32 index = 0; index < cReaders; index++)
2276 free(readerState->szReader);
2279 free(rgReaderStates);
2285 UINT32 cReaders, UINT32* ptrIndex)
2287 LONG status = SCARD_E_NO_MEMORY;
2289 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
2292 const UINT32 len = Stream_Get_UINT32(s);
2293 if (len != cReaders)
2295 WLog_ERR(TAG,
"Count mismatch when reading LPSCARD_READERSTATEW");
2301 BOOL* states = calloc(cReaders,
sizeof(BOOL));
2303 if (!rgReaderStates || !states)
2306 status = ERROR_INVALID_DATA;
2307 for (UINT32 index = 0; index < cReaders; index++)
2309 UINT32 ptr = UINT32_MAX;
2312 if (!Stream_CheckAndLogRequiredLength(TAG, s, 52))
2315 if (!smartcard_ndr_pointer_read(s, ptrIndex, &ptr))
2321 states[index] = ptr != 0;
2322 Stream_Read_UINT32(s, readerState->dwCurrentState);
2323 Stream_Read_UINT32(s, readerState->dwEventState);
2324 Stream_Read_UINT32(s, readerState->cbAtr);
2325 Stream_Read(s, readerState->rgbAtr, 36);
2328 for (UINT32 index = 0; index < cReaders; index++)
2336 status = smartcard_ndr_read_w(s, &readerState->szReader, NDR_PTR_FULL);
2337 if (status != SCARD_S_SUCCESS)
2341 *ppcReaders = rgReaderStates;
2343 return SCARD_S_SUCCESS;
2347 for (UINT32 index = 0; index < cReaders; index++)
2350 free(readerState->szReader);
2353 free(rgReaderStates);
2366 UINT32 pbContextNdrPtr = 0;
2368 call->rgReaderStates = NULL;
2370 LONG status = smartcard_unpack_redir_scard_context(s, &(call->handles.hContext), &index,
2372 if (status != SCARD_S_SUCCESS)
2375 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
2376 return STATUS_BUFFER_TOO_SMALL;
2378 Stream_Read_UINT32(s, call->dwTimeOut);
2379 Stream_Read_UINT32(s, call->cReaders);
2380 if (!smartcard_ndr_pointer_read(s, &index, &ndrPtr))
2381 return ERROR_INVALID_DATA;
2383 if ((status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
2384 &(call->handles.hContext))))
2389 status = smartcard_unpack_reader_state_a(s, &call->rgReaderStates, call->cReaders, &index);
2390 if (status != SCARD_S_SUCCESS)
2394 smartcard_trace_get_status_change_a_call(call);
2395 return SCARD_S_SUCCESS;
2402 UINT32 pbContextNdrPtr = 0;
2404 call->rgReaderStates = NULL;
2406 LONG status = smartcard_unpack_redir_scard_context(s, &(call->handles.hContext), &index,
2408 if (status != SCARD_S_SUCCESS)
2411 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
2412 return STATUS_BUFFER_TOO_SMALL;
2414 Stream_Read_UINT32(s, call->dwTimeOut);
2415 Stream_Read_UINT32(s, call->cReaders);
2416 if (!smartcard_ndr_pointer_read(s, &index, &ndrPtr))
2417 return ERROR_INVALID_DATA;
2419 if ((status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
2420 &(call->handles.hContext))))
2425 status = smartcard_unpack_reader_state_w(s, &call->rgReaderStates, call->cReaders, &index);
2426 if (status != SCARD_S_SUCCESS)
2430 smartcard_trace_get_status_change_w_call(call);
2431 return SCARD_S_SUCCESS;
2438 DWORD cReaders = ret->cReaders;
2441 smartcard_trace_get_status_change_return(ret, unicode);
2442 if (ret->ReturnCode != SCARD_S_SUCCESS)
2444 if (cReaders == SCARD_AUTOALLOCATE)
2447 if (!Stream_EnsureRemainingCapacity(s, 4))
2448 return SCARD_E_NO_MEMORY;
2450 Stream_Write_UINT32(s, cReaders);
2451 if (!smartcard_ndr_pointer_write(s, &index, cReaders))
2452 return SCARD_E_NO_MEMORY;
2453 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cReaders, NDR_PTR_SIMPLE);
2454 if (status != SCARD_S_SUCCESS)
2456 return ret->ReturnCode;
2462 UINT32 pbContextNdrPtr = 0;
2463 LONG status = smartcard_unpack_redir_scard_context(s, &(call->handles.hContext), &index,
2465 if (status != SCARD_S_SUCCESS)
2468 status = smartcard_unpack_redir_scard_handle(s, &(call->handles.hCard), &index);
2469 if (status != SCARD_S_SUCCESS)
2472 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
2473 return STATUS_BUFFER_TOO_SMALL;
2475 Stream_Read_INT32(s, call->fpbAtrIsNULL);
2476 Stream_Read_UINT32(s, call->cbAtrLen);
2478 if ((status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
2479 &(call->handles.hContext))))
2482 if ((status = smartcard_unpack_redir_scard_handle_ref(s, &(call->handles.hCard))))
2491 DWORD cbAtrLen = ret->cbAtrLen;
2494 smartcard_trace_state_return(ret);
2495 if (ret->ReturnCode != SCARD_S_SUCCESS)
2497 if (cbAtrLen == SCARD_AUTOALLOCATE)
2500 Stream_Write_UINT32(s, ret->dwState);
2501 Stream_Write_UINT32(s, ret->dwProtocol);
2502 Stream_Write_UINT32(s, cbAtrLen);
2503 if (!smartcard_ndr_pointer_write(s, &index, cbAtrLen))
2504 return SCARD_E_NO_MEMORY;
2505 status = smartcard_ndr_write(s, ret->rgAtr, cbAtrLen, 1, NDR_PTR_SIMPLE);
2506 if (status != SCARD_S_SUCCESS)
2508 return ret->ReturnCode;
2514 UINT32 pbContextNdrPtr = 0;
2516 LONG status = smartcard_unpack_redir_scard_context(s, &(call->handles.hContext), &index,
2518 if (status != SCARD_S_SUCCESS)
2521 status = smartcard_unpack_redir_scard_handle(s, &(call->handles.hCard), &index);
2522 if (status != SCARD_S_SUCCESS)
2525 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
2526 return STATUS_BUFFER_TOO_SMALL;
2528 Stream_Read_INT32(s, call->fmszReaderNamesIsNULL);
2529 Stream_Read_UINT32(s, call->cchReaderLen);
2530 Stream_Read_UINT32(s, call->cbAtrLen);
2532 if ((status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
2533 &(call->handles.hContext))))
2536 if ((status = smartcard_unpack_redir_scard_handle_ref(s, &(call->handles.hCard))))
2539 smartcard_trace_status_call(call, unicode);
2547 DWORD cBytes = ret->cBytes;
2549 smartcard_trace_status_return(ret, unicode);
2550 if (ret->ReturnCode != SCARD_S_SUCCESS)
2552 if (cBytes == SCARD_AUTOALLOCATE)
2555 if (!Stream_EnsureRemainingCapacity(s, 4))
2556 return SCARD_F_INTERNAL_ERROR;
2558 Stream_Write_UINT32(s, cBytes);
2559 if (!smartcard_ndr_pointer_write(s, &index, cBytes))
2560 return SCARD_E_NO_MEMORY;
2562 if (!Stream_EnsureRemainingCapacity(s, 44))
2563 return SCARD_F_INTERNAL_ERROR;
2565 Stream_Write_UINT32(s, ret->dwState);
2566 Stream_Write_UINT32(s, ret->dwProtocol);
2567 Stream_Write(s, ret->pbAtr,
sizeof(ret->pbAtr));
2568 Stream_Write_UINT32(s, ret->cbAtrLen);
2569 status = smartcard_ndr_write(s, ret->mszReaderNames, cBytes, 1, NDR_PTR_SIMPLE);
2570 if (status != SCARD_S_SUCCESS)
2572 return ret->ReturnCode;
2578 UINT32 pbContextNdrPtr = 0;
2580 LONG status = smartcard_unpack_redir_scard_context(s, &(call->handles.hContext), &index,
2582 if (status != SCARD_S_SUCCESS)
2585 status = smartcard_unpack_redir_scard_handle(s, &(call->handles.hCard), &index);
2586 if (status != SCARD_S_SUCCESS)
2589 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
2590 return STATUS_BUFFER_TOO_SMALL;
2592 Stream_Read_UINT32(s, call->dwAttrId);
2593 Stream_Read_INT32(s, call->fpbAttrIsNULL);
2594 Stream_Read_UINT32(s, call->cbAttrLen);
2596 if ((status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
2597 &(call->handles.hContext))))
2600 if ((status = smartcard_unpack_redir_scard_handle_ref(s, &(call->handles.hCard))))
2603 smartcard_trace_get_attrib_call(call);
2608 DWORD cbAttrCallLen)
2611 DWORD cbAttrLen = 0;
2613 smartcard_trace_get_attrib_return(ret, dwAttrId);
2615 if (!Stream_EnsureRemainingCapacity(s, 4))
2616 return SCARD_F_INTERNAL_ERROR;
2618 cbAttrLen = ret->cbAttrLen;
2619 if (ret->ReturnCode != SCARD_S_SUCCESS)
2621 if (cbAttrLen == SCARD_AUTOALLOCATE)
2626 if (cbAttrCallLen < cbAttrLen)
2627 cbAttrLen = cbAttrCallLen;
2629 Stream_Write_UINT32(s, cbAttrLen);
2630 if (!smartcard_ndr_pointer_write(s, &index, cbAttrLen))
2631 return SCARD_E_NO_MEMORY;
2633 status = smartcard_ndr_write(s, ret->pbAttr, cbAttrLen, 1, NDR_PTR_SIMPLE);
2634 if (status != SCARD_S_SUCCESS)
2636 return ret->ReturnCode;
2642 UINT32 pvInBufferNdrPtr = 0;
2643 UINT32 pbContextNdrPtr = 0;
2645 call->pvInBuffer = NULL;
2647 LONG status = smartcard_unpack_redir_scard_context(s, &(call->handles.hContext), &index,
2649 if (status != SCARD_S_SUCCESS)
2652 status = smartcard_unpack_redir_scard_handle(s, &(call->handles.hCard), &index);
2653 if (status != SCARD_S_SUCCESS)
2656 if (!Stream_CheckAndLogRequiredLength(TAG, s, 20))
2657 return STATUS_BUFFER_TOO_SMALL;
2659 Stream_Read_UINT32(s, call->dwControlCode);
2660 Stream_Read_UINT32(s, call->cbInBufferSize);
2661 if (!smartcard_ndr_pointer_read(s, &index, &pvInBufferNdrPtr))
2662 return ERROR_INVALID_DATA;
2663 Stream_Read_INT32(s, call->fpvOutBufferIsNULL);
2664 Stream_Read_UINT32(s, call->cbOutBufferSize);
2666 if ((status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
2667 &(call->handles.hContext))))
2670 if ((status = smartcard_unpack_redir_scard_handle_ref(s, &(call->handles.hCard))))
2673 if (pvInBufferNdrPtr)
2675 status = smartcard_ndr_read(s, &call->pvInBuffer, call->cbInBufferSize, 1, NDR_PTR_SIMPLE);
2676 if (status != SCARD_S_SUCCESS)
2680 smartcard_trace_control_call(call);
2681 return SCARD_S_SUCCESS;
2687 DWORD cbDataLen = ret->cbOutBufferSize;
2690 smartcard_trace_control_return(ret);
2691 if (ret->ReturnCode != SCARD_S_SUCCESS)
2693 if (cbDataLen == SCARD_AUTOALLOCATE)
2696 if (!Stream_EnsureRemainingCapacity(s, 4))
2697 return SCARD_F_INTERNAL_ERROR;
2699 Stream_Write_UINT32(s, cbDataLen);
2700 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
2701 return SCARD_E_NO_MEMORY;
2703 status = smartcard_ndr_write(s, ret->pvOutBuffer, cbDataLen, 1, NDR_PTR_SIMPLE);
2704 if (status != SCARD_S_SUCCESS)
2706 return ret->ReturnCode;
2712 BYTE* pbExtraBytes = NULL;
2713 UINT32 pbExtraBytesNdrPtr = 0;
2714 UINT32 pbSendBufferNdrPtr = 0;
2715 UINT32 pioRecvPciNdrPtr = 0;
2719 UINT32 pbContextNdrPtr = 0;
2721 call->pioSendPci = NULL;
2722 call->pioRecvPci = NULL;
2723 call->pbSendBuffer = NULL;
2725 LONG status = smartcard_unpack_redir_scard_context(s, &(call->handles.hContext), &index,
2727 if (status != SCARD_S_SUCCESS)
2730 status = smartcard_unpack_redir_scard_handle(s, &(call->handles.hCard), &index);
2731 if (status != SCARD_S_SUCCESS)
2734 if (!Stream_CheckAndLogRequiredLength(TAG, s, 32))
2735 return STATUS_BUFFER_TOO_SMALL;
2737 Stream_Read_UINT32(s, ioSendPci.dwProtocol);
2738 Stream_Read_UINT32(s, ioSendPci.cbExtraBytes);
2739 if (!smartcard_ndr_pointer_read(s, &index,
2740 &pbExtraBytesNdrPtr))
2741 return ERROR_INVALID_DATA;
2743 Stream_Read_UINT32(s, call->cbSendLength);
2744 if (!smartcard_ndr_pointer_read(s, &index,
2745 &pbSendBufferNdrPtr))
2746 return ERROR_INVALID_DATA;
2748 if (!smartcard_ndr_pointer_read(s, &index, &pioRecvPciNdrPtr))
2749 return ERROR_INVALID_DATA;
2751 Stream_Read_INT32(s, call->fpbRecvBufferIsNULL);
2752 Stream_Read_UINT32(s, call->cbRecvLength);
2754 if (ioSendPci.cbExtraBytes > 1024)
2757 "Transmit_Call ioSendPci.cbExtraBytes is out of bounds: %" PRIu32
" (max: 1024)",
2758 ioSendPci.cbExtraBytes);
2759 return STATUS_INVALID_PARAMETER;
2762 if (call->cbSendLength > 66560)
2764 WLog_WARN(TAG,
"Transmit_Call cbSendLength is out of bounds: %" PRIu32
" (max: 66560)",
2765 ioSendPci.cbExtraBytes);
2766 return STATUS_INVALID_PARAMETER;
2769 if ((status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
2770 &(call->handles.hContext))))
2773 if ((status = smartcard_unpack_redir_scard_handle_ref(s, &(call->handles.hCard))))
2776 if (ioSendPci.cbExtraBytes && !pbExtraBytesNdrPtr)
2779 TAG,
"Transmit_Call ioSendPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
2780 return STATUS_INVALID_PARAMETER;
2783 if (pbExtraBytesNdrPtr)
2786 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
2787 return STATUS_BUFFER_TOO_SMALL;
2789 Stream_Read_UINT32(s, length);
2791 if (!Stream_CheckAndLogRequiredLength(TAG, s, ioSendPci.cbExtraBytes))
2792 return STATUS_BUFFER_TOO_SMALL;
2794 ioSendPci.pbExtraBytes = Stream_Pointer(s);
2798 if (!call->pioSendPci)
2800 WLog_WARN(TAG,
"Transmit_Call out of memory error (pioSendPci)");
2801 return STATUS_NO_MEMORY;
2804 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
2805 call->pioSendPci->cbPciLength = (DWORD)(ioSendPci.cbExtraBytes +
sizeof(
SCARD_IO_REQUEST));
2807 Stream_Read(s, pbExtraBytes, ioSendPci.cbExtraBytes);
2808 smartcard_unpack_read_size_align(s, ioSendPci.cbExtraBytes, 4);
2814 if (!call->pioSendPci)
2816 WLog_WARN(TAG,
"Transmit_Call out of memory error (pioSendPci)");
2817 return STATUS_NO_MEMORY;
2820 call->pioSendPci->dwProtocol = ioSendPci.dwProtocol;
2824 if (pbSendBufferNdrPtr)
2826 status = smartcard_ndr_read(s, &call->pbSendBuffer, call->cbSendLength, 1, NDR_PTR_SIMPLE);
2827 if (status != SCARD_S_SUCCESS)
2831 if (pioRecvPciNdrPtr)
2833 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
2834 return STATUS_BUFFER_TOO_SMALL;
2836 Stream_Read_UINT32(s, ioRecvPci.dwProtocol);
2837 Stream_Read_UINT32(s, ioRecvPci.cbExtraBytes);
2838 if (!smartcard_ndr_pointer_read(s, &index,
2839 &pbExtraBytesNdrPtr))
2840 return ERROR_INVALID_DATA;
2842 if (ioRecvPci.cbExtraBytes && !pbExtraBytesNdrPtr)
2846 "Transmit_Call ioRecvPci.cbExtraBytes is non-zero but pbExtraBytesNdrPtr is null");
2847 return STATUS_INVALID_PARAMETER;
2850 if (pbExtraBytesNdrPtr)
2853 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
2854 return STATUS_BUFFER_TOO_SMALL;
2856 Stream_Read_UINT32(s, length);
2858 if (ioRecvPci.cbExtraBytes > 1024)
2861 "Transmit_Call ioRecvPci.cbExtraBytes is out of bounds: %" PRIu32
2863 ioRecvPci.cbExtraBytes);
2864 return STATUS_INVALID_PARAMETER;
2867 if (length != ioRecvPci.cbExtraBytes)
2870 "Transmit_Call unexpected length: Actual: %" PRIu32
", Expected: %" PRIu32
2871 " (ioRecvPci.cbExtraBytes)",
2872 length, ioRecvPci.cbExtraBytes);
2873 return STATUS_INVALID_PARAMETER;
2876 if (!Stream_CheckAndLogRequiredLength(TAG, s, ioRecvPci.cbExtraBytes))
2877 return STATUS_BUFFER_TOO_SMALL;
2879 ioRecvPci.pbExtraBytes = Stream_Pointer(s);
2883 if (!call->pioRecvPci)
2885 WLog_WARN(TAG,
"Transmit_Call out of memory error (pioRecvPci)");
2886 return STATUS_NO_MEMORY;
2889 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
2890 call->pioRecvPci->cbPciLength =
2893 Stream_Read(s, pbExtraBytes, ioRecvPci.cbExtraBytes);
2894 smartcard_unpack_read_size_align(s, ioRecvPci.cbExtraBytes, 4);
2900 if (!call->pioRecvPci)
2902 WLog_WARN(TAG,
"Transmit_Call out of memory error (pioRecvPci)");
2903 return STATUS_NO_MEMORY;
2906 call->pioRecvPci->dwProtocol = ioRecvPci.dwProtocol;
2911 smartcard_trace_transmit_call(call);
2912 return SCARD_S_SUCCESS;
2920 UINT32 cbRecvLength = ret->cbRecvLength;
2921 UINT32 cbRecvPci = ret->pioRecvPci ? ret->pioRecvPci->cbPciLength : 0;
2923 smartcard_trace_transmit_return(ret);
2925 if (!ret->pbRecvBuffer)
2928 if (!smartcard_ndr_pointer_write(s, &index, cbRecvPci))
2929 return SCARD_E_NO_MEMORY;
2930 if (!Stream_EnsureRemainingCapacity(s, 4))
2931 return SCARD_E_NO_MEMORY;
2932 Stream_Write_UINT32(s, cbRecvLength);
2933 if (!smartcard_ndr_pointer_write(s, &index, cbRecvLength))
2934 return SCARD_E_NO_MEMORY;
2936 if (ret->pioRecvPci)
2938 UINT32 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength -
sizeof(
SCARD_IO_REQUEST));
2941 if (!Stream_EnsureRemainingCapacity(s, cbExtraBytes + 16))
2943 WLog_ERR(TAG,
"Stream_EnsureRemainingCapacity failed!");
2944 return SCARD_F_INTERNAL_ERROR;
2947 Stream_Write_UINT32(s, ret->pioRecvPci->dwProtocol);
2948 Stream_Write_UINT32(s, cbExtraBytes);
2949 if (!smartcard_ndr_pointer_write(s, &index, cbExtraBytes))
2950 return SCARD_E_NO_MEMORY;
2951 error = smartcard_ndr_write(s, pbExtraBytes, cbExtraBytes, 1, NDR_PTR_SIMPLE);
2956 status = smartcard_ndr_write(s, ret->pbRecvBuffer, ret->cbRecvLength, 1, NDR_PTR_SIMPLE);
2957 if (status != SCARD_S_SUCCESS)
2959 return ret->ReturnCode;
2964 UINT32 rgReaderStatesNdrPtr = 0;
2965 UINT32 rgAtrMasksNdrPtr = 0;
2967 UINT32 pbContextNdrPtr = 0;
2969 call->rgReaderStates = NULL;
2971 LONG status = smartcard_unpack_redir_scard_context(s, &(call->handles.hContext), &index,
2973 if (status != SCARD_S_SUCCESS)
2976 if (!Stream_CheckAndLogRequiredLength(TAG, s, 16))
2977 return STATUS_BUFFER_TOO_SMALL;
2979 Stream_Read_UINT32(s, call->cAtrs);
2980 if (!smartcard_ndr_pointer_read(s, &index, &rgAtrMasksNdrPtr))
2981 return ERROR_INVALID_DATA;
2982 Stream_Read_UINT32(s, call->cReaders);
2983 if (!smartcard_ndr_pointer_read(s, &index, &rgReaderStatesNdrPtr))
2984 return ERROR_INVALID_DATA;
2986 if ((status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
2987 &(call->handles.hContext))))
2990 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
2993 "LocateCardsByATRA_Call rgAtrMasksNdrPtr (0x%08" PRIX32
2994 ") and cAtrs (0x%08" PRIX32
") inconsistency",
2995 rgAtrMasksNdrPtr, call->cAtrs);
2996 return STATUS_INVALID_PARAMETER;
2999 if (rgAtrMasksNdrPtr)
3001 status = smartcard_ndr_read_atrmask(s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3002 if (status != SCARD_S_SUCCESS)
3006 if (rgReaderStatesNdrPtr)
3008 status = smartcard_unpack_reader_state_a(s, &call->rgReaderStates, call->cReaders, &index);
3009 if (status != SCARD_S_SUCCESS)
3013 smartcard_trace_locate_cards_by_atr_a_call(call);
3014 return SCARD_S_SUCCESS;
3019 UINT32 sz1NdrPtr = 0;
3020 UINT32 sz2NdrPtr = 0;
3022 UINT32 pbContextNdrPtr = 0;
3024 LONG status = smartcard_unpack_redir_scard_context(s, &(call->handles.hContext), &index,
3026 if (status != SCARD_S_SUCCESS)
3029 if (!smartcard_ndr_pointer_read(s, &index, &sz1NdrPtr))
3030 return ERROR_INVALID_DATA;
3031 if (!smartcard_ndr_pointer_read(s, &index, &sz2NdrPtr))
3032 return ERROR_INVALID_DATA;
3034 status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr, &call->handles.hContext);
3035 if (status != SCARD_S_SUCCESS)
3040 status = smartcard_ndr_read_a(s, &call->sz1, NDR_PTR_FULL);
3041 if (status != SCARD_S_SUCCESS)
3046 status = smartcard_ndr_read_a(s, &call->sz2, NDR_PTR_FULL);
3047 if (status != SCARD_S_SUCCESS)
3050 smartcard_trace_context_and_two_strings_a_call(call);
3051 return SCARD_S_SUCCESS;
3056 UINT32 sz1NdrPtr = 0;
3057 UINT32 sz2NdrPtr = 0;
3059 UINT32 pbContextNdrPtr = 0;
3061 LONG status = smartcard_unpack_redir_scard_context(s, &(call->handles.hContext), &index,
3063 if (status != SCARD_S_SUCCESS)
3066 if (!smartcard_ndr_pointer_read(s, &index, &sz1NdrPtr))
3067 return ERROR_INVALID_DATA;
3068 if (!smartcard_ndr_pointer_read(s, &index, &sz2NdrPtr))
3069 return ERROR_INVALID_DATA;
3071 status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr, &call->handles.hContext);
3072 if (status != SCARD_S_SUCCESS)
3077 status = smartcard_ndr_read_w(s, &call->sz1, NDR_PTR_FULL);
3078 if (status != SCARD_S_SUCCESS)
3083 status = smartcard_ndr_read_w(s, &call->sz2, NDR_PTR_FULL);
3084 if (status != SCARD_S_SUCCESS)
3087 smartcard_trace_context_and_two_strings_w_call(call);
3088 return SCARD_S_SUCCESS;
3093 UINT32 sz1NdrPtr = 0;
3094 UINT32 sz2NdrPtr = 0;
3096 UINT32 pbContextNdrPtr = 0;
3098 LONG status = smartcard_unpack_redir_scard_context(s, &(call->handles.hContext), &index,
3100 if (status != SCARD_S_SUCCESS)
3103 if (!Stream_CheckAndLogRequiredLength(TAG, s, 16))
3104 return STATUS_BUFFER_TOO_SMALL;
3106 Stream_Read_UINT32(s, call->cBytes);
3107 if (!smartcard_ndr_pointer_read(s, &index, &sz1NdrPtr))
3108 return ERROR_INVALID_DATA;
3110 Stream_Read_UINT32(s, call->cReaders);
3111 if (!smartcard_ndr_pointer_read(s, &index, &sz2NdrPtr))
3112 return ERROR_INVALID_DATA;
3114 if ((status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
3115 &(call->handles.hContext))))
3121 smartcard_ndr_read_fixed_string_a(s, &call->mszCards, call->cBytes, NDR_PTR_SIMPLE);
3122 if (status != SCARD_S_SUCCESS)
3127 status = smartcard_unpack_reader_state_a(s, &call->rgReaderStates, call->cReaders, &index);
3128 if (status != SCARD_S_SUCCESS)
3131 smartcard_trace_locate_cards_a_call(call);
3132 return SCARD_S_SUCCESS;
3137 UINT32 sz1NdrPtr = 0;
3138 UINT32 sz2NdrPtr = 0;
3140 UINT32 pbContextNdrPtr = 0;
3142 LONG status = smartcard_unpack_redir_scard_context(s, &(call->handles.hContext), &index,
3144 if (status != SCARD_S_SUCCESS)
3147 if (!Stream_CheckAndLogRequiredLength(TAG, s, 16))
3148 return STATUS_BUFFER_TOO_SMALL;
3150 Stream_Read_UINT32(s, call->cBytes);
3151 if (!smartcard_ndr_pointer_read(s, &index, &sz1NdrPtr))
3152 return ERROR_INVALID_DATA;
3154 Stream_Read_UINT32(s, call->cReaders);
3155 if (!smartcard_ndr_pointer_read(s, &index, &sz2NdrPtr))
3156 return ERROR_INVALID_DATA;
3158 if ((status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
3159 &(call->handles.hContext))))
3165 smartcard_ndr_read_fixed_string_w(s, &call->mszCards, call->cBytes, NDR_PTR_SIMPLE);
3166 if (status != SCARD_S_SUCCESS)
3171 status = smartcard_unpack_reader_state_w(s, &call->rgReaderStates, call->cReaders, &index);
3172 if (status != SCARD_S_SUCCESS)
3175 smartcard_trace_locate_cards_w_call(call);
3176 return SCARD_S_SUCCESS;
3183 UINT32 pbContextNdrPtr = 0;
3185 LONG status = smartcard_unpack_redir_scard_context(s, &(call->handles.hContext), &index,
3187 if (status != SCARD_S_SUCCESS)
3189 status = smartcard_unpack_redir_scard_handle(s, &(call->handles.hCard), &index);
3190 if (status != SCARD_S_SUCCESS)
3193 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
3194 return STATUS_BUFFER_TOO_SMALL;
3195 Stream_Read_UINT32(s, call->dwAttrId);
3196 Stream_Read_UINT32(s, call->cbAttrLen);
3198 if (!smartcard_ndr_pointer_read(s, &index, &ndrPtr))
3199 return ERROR_INVALID_DATA;
3201 if ((status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
3202 &(call->handles.hContext))))
3205 if ((status = smartcard_unpack_redir_scard_handle_ref(s, &(call->handles.hCard))))
3212 status = smartcard_ndr_read(s, &call->pbAttr, 0, 1, NDR_PTR_SIMPLE);
3213 if (status != SCARD_S_SUCCESS)
3216 smartcard_trace_set_attrib_call(call);
3217 return SCARD_S_SUCCESS;
3222 UINT32 rgReaderStatesNdrPtr = 0;
3223 UINT32 rgAtrMasksNdrPtr = 0;
3225 UINT32 pbContextNdrPtr = 0;
3227 call->rgReaderStates = NULL;
3229 LONG status = smartcard_unpack_redir_scard_context(s, &(call->handles.hContext), &index,
3231 if (status != SCARD_S_SUCCESS)
3234 if (!Stream_CheckAndLogRequiredLength(TAG, s, 16))
3235 return STATUS_BUFFER_TOO_SMALL;
3237 Stream_Read_UINT32(s, call->cAtrs);
3238 if (!smartcard_ndr_pointer_read(s, &index, &rgAtrMasksNdrPtr))
3239 return ERROR_INVALID_DATA;
3241 Stream_Read_UINT32(s, call->cReaders);
3242 if (!smartcard_ndr_pointer_read(s, &index, &rgReaderStatesNdrPtr))
3243 return ERROR_INVALID_DATA;
3245 if ((status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
3246 &(call->handles.hContext))))
3249 if ((rgAtrMasksNdrPtr && !call->cAtrs) || (!rgAtrMasksNdrPtr && call->cAtrs))
3252 "LocateCardsByATRW_Call rgAtrMasksNdrPtr (0x%08" PRIX32
3253 ") and cAtrs (0x%08" PRIX32
") inconsistency",
3254 rgAtrMasksNdrPtr, call->cAtrs);
3255 return STATUS_INVALID_PARAMETER;
3258 if (rgAtrMasksNdrPtr)
3260 status = smartcard_ndr_read_atrmask(s, &call->rgAtrMasks, call->cAtrs, NDR_PTR_SIMPLE);
3261 if (status != SCARD_S_SUCCESS)
3265 if (rgReaderStatesNdrPtr)
3267 status = smartcard_unpack_reader_state_w(s, &call->rgReaderStates, call->cReaders, &index);
3268 if (status != SCARD_S_SUCCESS)
3272 smartcard_trace_locate_cards_by_atr_w_call(call);
3273 return SCARD_S_SUCCESS;
3278 UINT32 mszNdrPtr = 0;
3279 UINT32 contextNdrPtr = 0;
3281 UINT32 pbContextNdrPtr = 0;
3283 if (!smartcard_ndr_pointer_read(s, &index, &mszNdrPtr))
3284 return ERROR_INVALID_DATA;
3286 LONG status = smartcard_unpack_redir_scard_context(s, &(call->Common.handles.hContext), &index,
3288 if (status != SCARD_S_SUCCESS)
3291 if (!smartcard_ndr_pointer_read(s, &index, &contextNdrPtr))
3292 return ERROR_INVALID_DATA;
3294 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
3295 return STATUS_BUFFER_TOO_SMALL;
3296 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3297 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
3298 Stream_Read_UINT32(s, call->Common.cbDataLen);
3300 call->szLookupName = NULL;
3303 status = smartcard_ndr_read_a(s, &call->szLookupName, NDR_PTR_FULL);
3304 if (status != SCARD_S_SUCCESS)
3308 status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
3309 &call->Common.handles.hContext);
3310 if (status != SCARD_S_SUCCESS)
3315 status = smartcard_ndr_read_u(s, &call->Common.CardIdentifier);
3316 if (status != SCARD_S_SUCCESS)
3319 smartcard_trace_read_cache_a_call(call);
3320 return SCARD_S_SUCCESS;
3325 UINT32 mszNdrPtr = 0;
3326 UINT32 contextNdrPtr = 0;
3328 UINT32 pbContextNdrPtr = 0;
3330 if (!smartcard_ndr_pointer_read(s, &index, &mszNdrPtr))
3331 return ERROR_INVALID_DATA;
3333 LONG status = smartcard_unpack_redir_scard_context(s, &(call->Common.handles.hContext), &index,
3335 if (status != SCARD_S_SUCCESS)
3338 if (!smartcard_ndr_pointer_read(s, &index, &contextNdrPtr))
3339 return ERROR_INVALID_DATA;
3341 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
3342 return STATUS_BUFFER_TOO_SMALL;
3343 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3344 Stream_Read_INT32(s, call->Common.fPbDataIsNULL);
3345 Stream_Read_UINT32(s, call->Common.cbDataLen);
3347 call->szLookupName = NULL;
3350 status = smartcard_ndr_read_w(s, &call->szLookupName, NDR_PTR_FULL);
3351 if (status != SCARD_S_SUCCESS)
3355 status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
3356 &call->Common.handles.hContext);
3357 if (status != SCARD_S_SUCCESS)
3362 status = smartcard_ndr_read_u(s, &call->Common.CardIdentifier);
3363 if (status != SCARD_S_SUCCESS)
3366 smartcard_trace_read_cache_w_call(call);
3367 return SCARD_S_SUCCESS;
3372 UINT32 mszNdrPtr = 0;
3373 UINT32 contextNdrPtr = 0;
3374 UINT32 pbDataNdrPtr = 0;
3376 UINT32 pbContextNdrPtr = 0;
3378 if (!smartcard_ndr_pointer_read(s, &index, &mszNdrPtr))
3379 return ERROR_INVALID_DATA;
3381 LONG status = smartcard_unpack_redir_scard_context(s, &(call->Common.handles.hContext), &index,
3383 if (status != SCARD_S_SUCCESS)
3386 if (!smartcard_ndr_pointer_read(s, &index, &contextNdrPtr))
3387 return ERROR_INVALID_DATA;
3389 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
3390 return STATUS_BUFFER_TOO_SMALL;
3392 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3393 Stream_Read_UINT32(s, call->Common.cbDataLen);
3395 if (!smartcard_ndr_pointer_read(s, &index, &pbDataNdrPtr))
3396 return ERROR_INVALID_DATA;
3398 call->szLookupName = NULL;
3401 status = smartcard_ndr_read_a(s, &call->szLookupName, NDR_PTR_FULL);
3402 if (status != SCARD_S_SUCCESS)
3406 status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
3407 &call->Common.handles.hContext);
3408 if (status != SCARD_S_SUCCESS)
3411 call->Common.CardIdentifier = NULL;
3414 status = smartcard_ndr_read_u(s, &call->Common.CardIdentifier);
3415 if (status != SCARD_S_SUCCESS)
3419 call->Common.pbData = NULL;
3423 smartcard_ndr_read(s, &call->Common.pbData, call->Common.cbDataLen, 1, NDR_PTR_SIMPLE);
3424 if (status != SCARD_S_SUCCESS)
3427 smartcard_trace_write_cache_a_call(call);
3428 return SCARD_S_SUCCESS;
3433 UINT32 mszNdrPtr = 0;
3434 UINT32 contextNdrPtr = 0;
3435 UINT32 pbDataNdrPtr = 0;
3437 UINT32 pbContextNdrPtr = 0;
3439 if (!smartcard_ndr_pointer_read(s, &index, &mszNdrPtr))
3440 return ERROR_INVALID_DATA;
3442 LONG status = smartcard_unpack_redir_scard_context(s, &(call->Common.handles.hContext), &index,
3444 if (status != SCARD_S_SUCCESS)
3447 if (!smartcard_ndr_pointer_read(s, &index, &contextNdrPtr))
3448 return ERROR_INVALID_DATA;
3450 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
3451 return STATUS_BUFFER_TOO_SMALL;
3452 Stream_Read_UINT32(s, call->Common.FreshnessCounter);
3453 Stream_Read_UINT32(s, call->Common.cbDataLen);
3455 if (!smartcard_ndr_pointer_read(s, &index, &pbDataNdrPtr))
3456 return ERROR_INVALID_DATA;
3458 call->szLookupName = NULL;
3461 status = smartcard_ndr_read_w(s, &call->szLookupName, NDR_PTR_FULL);
3462 if (status != SCARD_S_SUCCESS)
3466 status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
3467 &call->Common.handles.hContext);
3468 if (status != SCARD_S_SUCCESS)
3471 call->Common.CardIdentifier = NULL;
3474 status = smartcard_ndr_read_u(s, &call->Common.CardIdentifier);
3475 if (status != SCARD_S_SUCCESS)
3479 call->Common.pbData = NULL;
3483 smartcard_ndr_read(s, &call->Common.pbData, call->Common.cbDataLen, 1, NDR_PTR_SIMPLE);
3484 if (status != SCARD_S_SUCCESS)
3487 smartcard_trace_write_cache_w_call(call);
3494 UINT32 pbContextNdrPtr = 0;
3496 LONG status = smartcard_unpack_redir_scard_context(s, &(call->handles.hContext), &index,
3498 if (status != SCARD_S_SUCCESS)
3501 status = smartcard_unpack_redir_scard_handle(s, &(call->handles.hCard), &index);
3502 if (status != SCARD_S_SUCCESS)
3505 if ((status = smartcard_unpack_redir_scard_context_ref(s, pbContextNdrPtr,
3506 &(call->handles.hContext))))
3508 WLog_ERR(TAG,
"smartcard_unpack_redir_scard_context_ref failed with error %" PRId32
"",
3513 if ((status = smartcard_unpack_redir_scard_handle_ref(s, &(call->handles.hCard))))
3514 WLog_ERR(TAG,
"smartcard_unpack_redir_scard_handle_ref failed with error %" PRId32
"",
3517 smartcard_trace_get_transmit_count_call(call);
3523 return smartcard_unpack_common_context_and_string_w(s, &call->handles.hContext,
3524 &call->szReaderName);
3529 return smartcard_unpack_common_context_and_string_a(s, &call->handles.hContext, &call->sz);
3534 return smartcard_unpack_common_context_and_string_w(s, &call->handles.hContext, &call->sz);
3539 return smartcard_unpack_common_context_and_string_w(s, &call->handles.hContext,
3540 &call->szReaderName);
3545 smartcard_trace_device_type_id_return(ret);
3547 if (!Stream_EnsureRemainingCapacity(s, 4))
3549 WLog_ERR(TAG,
"Stream_EnsureRemainingCapacity failed!");
3550 return SCARD_F_INTERNAL_ERROR;
3553 Stream_Write_UINT32(s, ret->dwDeviceId);
3555 return ret->ReturnCode;
3561 DWORD cbDataLen = ret->cReaders;
3564 smartcard_trace_locate_cards_return(ret);
3565 if (ret->ReturnCode != SCARD_S_SUCCESS)
3567 if (cbDataLen == SCARD_AUTOALLOCATE)
3570 if (!Stream_EnsureRemainingCapacity(s, 4))
3572 WLog_ERR(TAG,
"Stream_EnsureRemainingCapacity failed!");
3573 return SCARD_F_INTERNAL_ERROR;
3576 Stream_Write_UINT32(s, cbDataLen);
3577 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3578 return SCARD_E_NO_MEMORY;
3580 status = smartcard_ndr_write_state(s, ret->rgReaderStates, cbDataLen, NDR_PTR_SIMPLE);
3581 if (status != SCARD_S_SUCCESS)
3583 return ret->ReturnCode;
3590 DWORD cbDataLen = ret->cbDataLen;
3591 smartcard_trace_get_reader_icon_return(ret);
3592 if (ret->ReturnCode != SCARD_S_SUCCESS)
3594 if (cbDataLen == SCARD_AUTOALLOCATE)
3597 if (!Stream_EnsureRemainingCapacity(s, 4))
3599 WLog_ERR(TAG,
"Stream_EnsureRemainingCapacity failed!");
3600 return SCARD_F_INTERNAL_ERROR;
3603 Stream_Write_UINT32(s, cbDataLen);
3604 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3605 return SCARD_E_NO_MEMORY;
3607 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
3608 if (status != SCARD_S_SUCCESS)
3610 return ret->ReturnCode;
3615 smartcard_trace_get_transmit_count_return(ret);
3617 if (!Stream_EnsureRemainingCapacity(s, 4))
3619 WLog_ERR(TAG,
"Stream_EnsureRemainingCapacity failed!");
3620 return SCARD_F_INTERNAL_ERROR;
3623 Stream_Write_UINT32(s, ret->cTransmitCount);
3625 return ret->ReturnCode;
3632 DWORD cbDataLen = ret->cbDataLen;
3633 smartcard_trace_read_cache_return(ret);
3634 if (ret->ReturnCode != SCARD_S_SUCCESS)
3637 if (cbDataLen == SCARD_AUTOALLOCATE)
3640 if (!Stream_EnsureRemainingCapacity(s, 4))
3642 WLog_ERR(TAG,
"Stream_EnsureRemainingCapacity failed!");
3643 return SCARD_F_INTERNAL_ERROR;
3646 Stream_Write_UINT32(s, cbDataLen);
3647 if (!smartcard_ndr_pointer_write(s, &index, cbDataLen))
3648 return SCARD_E_NO_MEMORY;
3650 status = smartcard_ndr_write(s, ret->pbData, cbDataLen, 1, NDR_PTR_SIMPLE);
3651 if (status != SCARD_S_SUCCESS)
3653 return ret->ReturnCode;