* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
* Copyright 2015 Thincast Technologies GmbH
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
+ * Copyright 2020 Armin Novak <armin.novak@thincast.com>
+ * Copyright 2020 Thincast Technologies GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "smartcard_pack.h"
+static const DWORD g_LogLevel = WLOG_INFO;
+
#define smartcard_unpack_redir_scard_context(smartcard, s, context, index) \
smartcard_unpack_redir_scard_context_((smartcard), (s), (context), (index), __FILE__, \
__FUNCTION__, __LINE__)
REDIR_SCARDCONTEXT* context, UINT32* index,
const char* file, const char* function, int line);
static LONG smartcard_pack_redir_scard_context(SMARTCARD_DEVICE* smartcard, wStream* s,
- const REDIR_SCARDCONTEXT* context);
+ const REDIR_SCARDCONTEXT* context, DWORD* index);
static LONG smartcard_unpack_redir_scard_handle_(SMARTCARD_DEVICE* smartcard, wStream* s,
REDIR_SCARDHANDLE* handle, UINT32* index,
const char* file, const char* function, int line);
static LONG smartcard_pack_redir_scard_handle(SMARTCARD_DEVICE* smartcard, wStream* s,
- const REDIR_SCARDHANDLE* handle);
+ const REDIR_SCARDHANDLE* handle, DWORD* index);
static LONG smartcard_unpack_redir_scard_context_ref(SMARTCARD_DEVICE* smartcard, wStream* s,
REDIR_SCARDCONTEXT* context);
static LONG smartcard_pack_redir_scard_context_ref(SMARTCARD_DEVICE* smartcard, wStream* s,
return STATUS_SUCCESS;
}
+static BOOL smartcard_ndr_pointer_write(wStream* s, UINT32* index, DWORD length)
+{
+ const UINT32 ndrPtr = 0x20000 + (*index) * 4;
+
+ if (!s)
+ return FALSE;
+ if (!Stream_EnsureRemainingCapacity(s, 4))
+ return FALSE;
+
+ if (length > 0)
+ {
+ Stream_Write_UINT32(s, ndrPtr); /* mszGroupsNdrPtr (4 bytes) */
+ (*index) = (*index) + 1;
+ }
+ else
+ Stream_Write_UINT32(s, 0);
+ return TRUE;
+}
+
+static LONG smartcard_ndr_write(wStream* s, const BYTE* data, UINT32 size, UINT32 elementSize,
+ ndr_ptr_t type)
+{
+ const UINT32 offset = 0;
+ const UINT32 len = size;
+ const UINT32 dataLen = size * elementSize;
+ size_t required;
+
+ if (size == 0)
+ return SCARD_S_SUCCESS;
+
+ switch (type)
+ {
+ case NDR_PTR_FULL:
+ required = 12;
+ break;
+ case NDR_PTR_SIMPLE:
+ required = 4;
+ break;
+ case NDR_PTR_FIXED:
+ required = 0;
+ break;
+ }
+
+ if (!Stream_EnsureRemainingCapacity(s, required + dataLen))
+ return STATUS_BUFFER_TOO_SMALL;
+
+ switch (type)
+ {
+ case NDR_PTR_FULL:
+ Stream_Write_UINT32(s, len);
+ Stream_Write_UINT32(s, offset);
+ Stream_Write_UINT32(s, len);
+ break;
+ case NDR_PTR_SIMPLE:
+ Stream_Write_UINT32(s, len);
+ break;
+ case NDR_PTR_FIXED:
+ break;
+ }
+
+ if (data)
+ Stream_Write(s, data, dataLen);
+ else
+ Stream_Zero(s, dataLen);
+ smartcard_pack_write_size_align(NULL, s, len, 4);
+
+ return STATUS_SUCCESS;
+}
+
+static LONG smartcard_ndr_write_state(wStream* s, const ReaderState_Return* data, UINT32 size,
+ ndr_ptr_t type)
+{
+ union {
+ const ReaderState_Return* reader;
+ const BYTE* data;
+ } cnv;
+
+ cnv.reader = data;
+ return smartcard_ndr_write(s, cnv.data, size, sizeof(ReaderState_Return), type);
+}
+
static LONG smartcard_ndr_read_atrmask(wStream* s, LocateCards_ATRMask** data, size_t min,
ndr_ptr_t type)
{
{
char buffer[128];
- WLog_DBG(tag, "hContext: %s",
+ WLog_LVL(tag, g_LogLevel, "hContext: %s",
smartcard_array_dump(pHandle->pbHandle, pHandle->cbHandle, buffer, sizeof(buffer)));
}
const REDIR_SCARDCONTEXT* phContext,
const CHAR* sz)
{
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "%s {", name);
+ WLog_LVL(TAG, g_LogLevel, "%s {", name);
smartcard_log_context(TAG, phContext);
- WLog_DBG(TAG, " sz=%s", sz);
+ WLog_LVL(TAG, g_LogLevel, " sz=%s", sz);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_context_and_string_call_w(const char* name,
const WCHAR* sz)
{
char* tmp;
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "%s {", name);
+ WLog_LVL(TAG, g_LogLevel, "%s {", name);
smartcard_log_context(TAG, phContext);
ConvertFromUnicode(CP_UTF8, 0, sz, -1, &tmp, 0, NULL, NULL);
- WLog_DBG(TAG, " sz=%s", tmp);
+ WLog_LVL(TAG, g_LogLevel, " sz=%s", tmp);
free(tmp);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_context_call(SMARTCARD_DEVICE* smartcard, const Context_Call* call,
{
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "%s_Call {", name);
+ WLog_LVL(TAG, g_LogLevel, "%s_Call {", name);
smartcard_log_context(TAG, &call->hContext);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_list_reader_groups_call(SMARTCARD_DEVICE* smartcard,
{
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "ListReaderGroups%S_Call {", unicode ? "W" : "A");
+ WLog_LVL(TAG, g_LogLevel, "ListReaderGroups%S_Call {", unicode ? "W" : "A");
smartcard_log_context(TAG, &call->hContext);
- WLog_DBG(TAG, "fmszGroupsIsNULL: %" PRId32 " cchGroups: 0x%08" PRIx32, call->fmszGroupsIsNULL,
- call->cchGroups);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "fmszGroupsIsNULL: %" PRId32 " cchGroups: 0x%08" PRIx32,
+ call->fmszGroupsIsNULL, call->cchGroups);
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_get_status_change_w_call(SMARTCARD_DEVICE* smartcard,
LPSCARD_READERSTATEW readerState;
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "GetStatusChangeW_Call {");
+ WLog_LVL(TAG, g_LogLevel, "GetStatusChangeW_Call {");
smartcard_log_context(TAG, &call->hContext);
- WLog_DBG(TAG, "dwTimeOut: 0x%08" PRIX32 " cReaders: %" PRIu32 "", call->dwTimeOut,
+ WLog_LVL(TAG, g_LogLevel, "dwTimeOut: 0x%08" PRIX32 " cReaders: %" PRIu32 "", call->dwTimeOut,
call->cReaders);
for (index = 0; index < call->cReaders; index++)
char* szReaderA = NULL;
readerState = &call->rgReaderStates[index];
ConvertFromUnicode(CP_UTF8, 0, readerState->szReader, -1, &szReaderA, 0, NULL, NULL);
- WLog_DBG(TAG, "\t[%" PRIu32 "]: szReader: %s cbAtr: %" PRIu32 "", index, szReaderA,
- readerState->cbAtr);
+ WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: szReader: %s cbAtr: %" PRIu32 "", index,
+ szReaderA, readerState->cbAtr);
szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
szEventState = SCardGetReaderStateString(readerState->dwEventState);
- WLog_DBG(TAG, "\t[%" PRIu32 "]: dwCurrentState: %s (0x%08" PRIX32 ")", index,
+ WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: dwCurrentState: %s (0x%08" PRIX32 ")", index,
szCurrentState, readerState->dwCurrentState);
- WLog_DBG(TAG, "\t[%" PRIu32 "]: dwEventState: %s (0x%08" PRIX32 ")", index, szEventState,
- readerState->dwEventState);
+ WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: dwEventState: %s (0x%08" PRIX32 ")", index,
+ szEventState, readerState->dwEventState);
free(szCurrentState);
free(szEventState);
free(szReaderA);
}
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_list_reader_groups_return(SMARTCARD_DEVICE* smartcard,
char* mszA = NULL;
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
- WLog_DBG(TAG, "ListReaderGroups%s_Return {", unicode ? "W" : "A");
- WLog_DBG(TAG, "ReturnCode: %s (0x%08" PRIx32 ")", SCardGetErrorString(ret->ReturnCode),
- ret->ReturnCode);
- WLog_DBG(TAG, "cBytes: %" PRIu32 " msz: %s", ret->cBytes, mszA);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "ListReaderGroups%s_Return {", unicode ? "W" : "A");
+ WLog_LVL(TAG, g_LogLevel, "ReturnCode: %s (0x%08" PRIx32 ")",
+ SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
+ WLog_LVL(TAG, g_LogLevel, "cBytes: %" PRIu32 " msz: %s", ret->cBytes, mszA);
+ WLog_LVL(TAG, g_LogLevel, "}");
free(mszA);
}
char* mszGroupsA = NULL;
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
mszGroupsA = smartcard_convert_string_list(call->mszGroups, call->cBytes, unicode);
- WLog_DBG(TAG, "ListReaders%s_Call {", unicode ? "W" : "A");
+ WLog_LVL(TAG, g_LogLevel, "ListReaders%s_Call {", unicode ? "W" : "A");
smartcard_log_context(TAG, &call->hContext);
- WLog_DBG(TAG,
+ WLog_LVL(TAG, g_LogLevel,
"cBytes: %" PRIu32 " mszGroups: %s fmszReadersIsNULL: %" PRId32
" cchReaders: 0x%08" PRIX32 "",
call->cBytes, mszGroupsA, call->fmszReadersIsNULL, call->cchReaders);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
free(mszGroupsA);
}
UINT32 index;
char* szEventState;
char* szCurrentState;
- char* rgbAtr;
- LPSCARD_READERSTATEA readerState;
+
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "LocateCardsByATRA_Call {");
+ WLog_LVL(TAG, g_LogLevel, "LocateCardsByATRA_Call {");
smartcard_log_context(TAG, &call->hContext);
for (index = 0; index < call->cReaders; index++)
{
- readerState = (LPSCARD_READERSTATEA)&call->rgReaderStates[index];
- WLog_DBG(TAG, "\t[%" PRIu32 "]: szReader: %s cbAtr: %" PRIu32 "", index,
+ char buffer[1024];
+ const LPSCARD_READERSTATEA readerState = &call->rgReaderStates[index];
+
+ WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: szReader: %s cbAtr: %" PRIu32 "", index,
readerState->szReader, readerState->cbAtr);
szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
szEventState = SCardGetReaderStateString(readerState->dwEventState);
- rgbAtr = winpr_BinToHexString((BYTE*)&(readerState->rgbAtr), readerState->cbAtr, FALSE);
- WLog_DBG(TAG, "\t[%" PRIu32 "]: dwCurrentState: %s (0x%08" PRIX32 ")", index,
+ WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: dwCurrentState: %s (0x%08" PRIX32 ")", index,
szCurrentState, readerState->dwCurrentState);
- WLog_DBG(TAG, "\t[%" PRIu32 "]: dwEventState: %s (0x%08" PRIX32 ")", index, szEventState,
- readerState->dwEventState);
+ WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: dwEventState: %s (0x%08" PRIX32 ")", index,
+ szEventState, readerState->dwEventState);
- if (rgbAtr)
- {
- WLog_DBG(TAG, "\t[%" PRIu32 "]: cbAtr: %" PRIu32 " rgbAtr: %s", index,
- readerState->cbAtr, rgbAtr);
- }
- else
- {
- WLog_DBG(TAG, "\t[%" PRIu32 "]: cbAtr: 0 rgbAtr: n/a", index);
- }
+ WLog_DBG(
+ TAG, "\t[%" PRIu32 "]: cbAtr: %" PRIu32 " rgbAtr: %s", index, readerState->cbAtr,
+ smartcard_array_dump(readerState->rgbAtr, readerState->cbAtr, buffer, sizeof(buffer)));
free(szCurrentState);
free(szEventState);
- free(rgbAtr);
}
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_locate_cards_a_call(SMARTCARD_DEVICE* smartcard,
char buffer[8192];
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "LocateCardsA_Call {");
+ WLog_LVL(TAG, g_LogLevel, "LocateCardsA_Call {");
smartcard_log_context(TAG, &call->hContext);
- WLog_DBG(TAG, " cBytes=%" PRId32, call->cBytes);
- WLog_DBG(TAG, " mszCards=%s",
+ WLog_LVL(TAG, g_LogLevel, " cBytes=%" PRId32, call->cBytes);
+ WLog_LVL(TAG, g_LogLevel, " mszCards=%s",
smartcard_msz_dump_a(call->mszCards, call->cBytes, buffer, sizeof(buffer)));
- WLog_DBG(TAG, " cReaders=%" PRId32, call->cReaders);
- // WLog_DBG(TAG, " cReaders=%" PRId32, call->rgReaderStates);
+ WLog_LVL(TAG, g_LogLevel, " cReaders=%" PRId32, call->cReaders);
+ // WLog_LVL(TAG, g_LogLevel, " cReaders=%" PRId32, call->rgReaderStates);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_locate_cards_return(SMARTCARD_DEVICE* smartcard,
const LocateCards_Return* ret)
{
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "LocateCards_Return {");
- WLog_DBG(TAG, "ReturnCode: %s (0x%08" PRIX32 ")", SCardGetErrorString(ret->ReturnCode),
- ret->ReturnCode);
+ WLog_LVL(TAG, g_LogLevel, "LocateCards_Return {");
+ WLog_LVL(TAG, g_LogLevel, "ReturnCode: %s (0x%08" PRIX32 ")",
+ SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
if (ret->ReturnCode == SCARD_S_SUCCESS)
{
- WLog_DBG(TAG, " cReaders=%" PRId32, ret->cReaders);
- // WLog_DBG(TAG, " cReaders=%" PRId32, call->rgReaderStates);
+ WLog_LVL(TAG, g_LogLevel, " cReaders=%" PRId32, ret->cReaders);
+ // WLog_LVL(TAG, g_LogLevel, " cReaders=%" PRId32, call->rgReaderStates);
}
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_get_reader_icon_return(SMARTCARD_DEVICE* smartcard,
const GetReaderIcon_Return* ret)
{
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "GetReaderIcon_Return {");
- WLog_DBG(TAG, "ReturnCode: %s (0x%08" PRIX32 ")", SCardGetErrorString(ret->ReturnCode),
- ret->ReturnCode);
+ WLog_LVL(TAG, g_LogLevel, "GetReaderIcon_Return {");
+ WLog_LVL(TAG, g_LogLevel, "ReturnCode: %s (0x%08" PRIX32 ")",
+ SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
if (ret->ReturnCode == SCARD_S_SUCCESS)
{
- WLog_DBG(TAG, " cbDataLen=%" PRId32, ret->cbDataLen);
- // WLog_DBG(TAG, " cReaders=%" PRId32, call->pbData);
+ WLog_LVL(TAG, g_LogLevel, " cbDataLen=%" PRId32, ret->cbDataLen);
+ // WLog_LVL(TAG, g_LogLevel, " cReaders=%" PRId32, call->pbData);
}
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_get_transmit_count_return(SMARTCARD_DEVICE* smartcard,
const GetTransmitCount_Return* ret)
{
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "GetTransmitCount_Return {");
- WLog_DBG(TAG, "ReturnCode: %s (0x%08" PRIX32 ")", SCardGetErrorString(ret->ReturnCode),
- ret->ReturnCode);
+ WLog_LVL(TAG, g_LogLevel, "GetTransmitCount_Return {");
+ WLog_LVL(TAG, g_LogLevel, "ReturnCode: %s (0x%08" PRIX32 ")",
+ SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
- WLog_DBG(TAG, " cTransmitCount=%" PRIu32, ret->cTransmitCount);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, " cTransmitCount=%" PRIu32, ret->cTransmitCount);
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_read_cache_return(SMARTCARD_DEVICE* smartcard,
const ReadCache_Return* ret)
{
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "ReadCache_Return {");
- WLog_DBG(TAG, "ReturnCode: %s (0x%08" PRIX32 ")", SCardGetErrorString(ret->ReturnCode),
- ret->ReturnCode);
+ WLog_LVL(TAG, g_LogLevel, "ReadCache_Return {");
+ WLog_LVL(TAG, g_LogLevel, "ReturnCode: %s (0x%08" PRIX32 ")",
+ SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
if (ret->ReturnCode == SCARD_S_SUCCESS)
{
- WLog_DBG(TAG, " cbDataLen=%" PRId32, ret->cbDataLen);
- // WLog_DBG(TAG, " cReaders=%" PRId32, call->cReaders);
+ WLog_LVL(TAG, g_LogLevel, " cbDataLen=%" PRId32, ret->cbDataLen);
+ // WLog_LVL(TAG, g_LogLevel, " cReaders=%" PRId32, call->cReaders);
}
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_locate_cards_w_call(SMARTCARD_DEVICE* smartcard,
{
char buffer[8192];
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "LocateCardsW_Call {");
+ WLog_LVL(TAG, g_LogLevel, "LocateCardsW_Call {");
smartcard_log_context(TAG, &call->hContext);
- WLog_DBG(TAG, " cBytes=%" PRId32, call->cBytes);
- WLog_DBG(TAG, " sz2=%s",
+ WLog_LVL(TAG, g_LogLevel, " cBytes=%" PRId32, call->cBytes);
+ WLog_LVL(TAG, g_LogLevel, " sz2=%s",
smartcard_msz_dump_w(call->mszCards, call->cBytes, buffer, sizeof(buffer)));
- WLog_DBG(TAG, " cReaders=%" PRId32, call->cReaders);
- // WLog_DBG(TAG, " sz2=%s", call->rgReaderStates);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, " cReaders=%" PRId32, call->cReaders);
+ // WLog_LVL(TAG, g_LogLevel, " sz2=%s", call->rgReaderStates);
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_list_readers_return(SMARTCARD_DEVICE* smartcard,
char* mszA = NULL;
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "ListReaders%s_Return {", unicode ? "W" : "A");
- WLog_DBG(TAG, "ReturnCode: %s (0x%08" PRIX32 ")", SCardGetErrorString(ret->ReturnCode),
- ret->ReturnCode);
+ WLog_LVL(TAG, g_LogLevel, "ListReaders%s_Return {", unicode ? "W" : "A");
+ WLog_LVL(TAG, g_LogLevel, "ReturnCode: %s (0x%08" PRIX32 ")",
+ SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
if (ret->ReturnCode != SCARD_S_SUCCESS)
{
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
return;
}
mszA = smartcard_convert_string_list(ret->msz, ret->cBytes, unicode);
- WLog_DBG(TAG, "cBytes: %" PRIu32 " msz: %s", ret->cBytes, mszA);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "cBytes: %" PRIu32 " msz: %s", ret->cBytes, mszA);
+ WLog_LVL(TAG, g_LogLevel, "}");
free(mszA);
}
BOOL unicode)
{
UINT32 index;
- char* rgbAtr;
char* szEventState;
char* szCurrentState;
- ReaderState_Return* rgReaderState;
+
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "GetStatusChange%s_Return {", unicode ? "W" : "A");
- WLog_DBG(TAG, "ReturnCode: %s (0x%08" PRIX32 ")", SCardGetErrorString(ret->ReturnCode),
- ret->ReturnCode);
- WLog_DBG(TAG, "cReaders: %" PRIu32 "", ret->cReaders);
+ WLog_LVL(TAG, g_LogLevel, "GetStatusChange%s_Return {", unicode ? "W" : "A");
+ WLog_LVL(TAG, g_LogLevel, "ReturnCode: %s (0x%08" PRIX32 ")",
+ SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
+ WLog_LVL(TAG, g_LogLevel, "cReaders: %" PRIu32 "", ret->cReaders);
for (index = 0; index < ret->cReaders; index++)
{
- rgReaderState = &(ret->rgReaderStates[index]);
+ char buffer[1024];
+ const ReaderState_Return* rgReaderState = &(ret->rgReaderStates[index]);
szCurrentState = SCardGetReaderStateString(rgReaderState->dwCurrentState);
szEventState = SCardGetReaderStateString(rgReaderState->dwEventState);
- rgbAtr = winpr_BinToHexString((BYTE*)&(rgReaderState->rgbAtr), rgReaderState->cbAtr, FALSE);
- WLog_DBG(TAG, "\t[%" PRIu32 "]: dwCurrentState: %s (0x%08" PRIX32 ")", index,
+ WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: dwCurrentState: %s (0x%08" PRIX32 ")", index,
szCurrentState, rgReaderState->dwCurrentState);
- WLog_DBG(TAG, "\t[%" PRIu32 "]: dwEventState: %s (0x%08" PRIX32 ")", index, szEventState,
- rgReaderState->dwEventState);
- WLog_DBG(TAG, "\t[%" PRIu32 "]: cbAtr: %" PRIu32 " rgbAtr: %s", index, rgReaderState->cbAtr,
- rgbAtr);
+ WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: dwEventState: %s (0x%08" PRIX32 ")", index,
+ szEventState, rgReaderState->dwEventState);
+ WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: cbAtr: %" PRIu32 " rgbAtr: %s", index,
+ rgReaderState->cbAtr,
+ smartcard_array_dump(rgReaderState->rgbAtr, rgReaderState->cbAtr, buffer,
+ sizeof(buffer)));
free(szCurrentState);
free(szEventState);
- free(rgbAtr);
}
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_context_and_two_strings_a_call(SMARTCARD_DEVICE* smartcard,
const ContextAndTwoStringA_Call* call)
{
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "ContextAndTwoStringW_Call {");
+ WLog_LVL(TAG, g_LogLevel, "ContextAndTwoStringW_Call {");
smartcard_log_context(TAG, &call->hContext);
- WLog_DBG(TAG, " sz1=%s", call->sz1);
- WLog_DBG(TAG, " sz2=%s", call->sz2);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, " sz1=%s", call->sz1);
+ WLog_LVL(TAG, g_LogLevel, " sz2=%s", call->sz2);
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_context_and_two_strings_w_call(SMARTCARD_DEVICE* smartcard,
CHAR* sz2 = NULL;
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "ContextAndTwoStringW_Call {");
+ WLog_LVL(TAG, g_LogLevel, "ContextAndTwoStringW_Call {");
smartcard_log_context(TAG, &call->hContext);
ConvertFromUnicode(CP_UTF8, 0, call->sz1, -1, &sz1, 0, NULL, NULL);
ConvertFromUnicode(CP_UTF8, 0, call->sz2, -1, &sz2, 0, NULL, NULL);
- WLog_DBG(TAG, " sz1=%s", sz1);
- WLog_DBG(TAG, " sz2=%s", sz2);
+ WLog_LVL(TAG, g_LogLevel, " sz1=%s", sz1);
+ WLog_LVL(TAG, g_LogLevel, " sz2=%s", sz2);
free(sz1);
free(sz2);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_get_transmit_count_call(SMARTCARD_DEVICE* smartcard,
const GetTransmitCount_Call* call)
{
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "GetTransmitCount_Call {");
+ WLog_LVL(TAG, g_LogLevel, "GetTransmitCount_Call {");
smartcard_log_context(TAG, &call->hContext);
smartcard_log_redir_handle(TAG, &call->hCard);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_write_cache_a_call(SMARTCARD_DEVICE* smartcard,
{
char buffer[1024];
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "GetTransmitCount_Call {");
+ WLog_LVL(TAG, g_LogLevel, "GetTransmitCount_Call {");
- WLog_DBG(TAG, " szLookupName=%s", call->szLookupName);
+ WLog_LVL(TAG, g_LogLevel, " szLookupName=%s", call->szLookupName);
smartcard_log_context(TAG, &call->Common.hContext);
WLog_DBG(
TAG, "..CardIdentifier=%s",
smartcard_array_dump(call->Common.CardIdentifier, sizeof(UUID), buffer, sizeof(buffer)));
- WLog_DBG(TAG, " FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
- WLog_DBG(TAG, " cbDataLen=%" PRIu32, call->Common.cbDataLen);
+ WLog_LVL(TAG, g_LogLevel, " FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
+ WLog_LVL(TAG, g_LogLevel, " cbDataLen=%" PRIu32, call->Common.cbDataLen);
WLog_DBG(
TAG, " pbData=%s",
smartcard_array_dump(call->Common.pbData, call->Common.cbDataLen, buffer, sizeof(buffer)));
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_write_cache_w_call(SMARTCARD_DEVICE* smartcard,
char* tmp;
char buffer[1024];
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "GetTransmitCount_Call {");
+ WLog_LVL(TAG, g_LogLevel, "GetTransmitCount_Call {");
ConvertFromUnicode(CP_UTF8, 0, call->szLookupName, -1, &tmp, 0, NULL, NULL);
- WLog_DBG(TAG, " szLookupName=%s", tmp);
+ WLog_LVL(TAG, g_LogLevel, " szLookupName=%s", tmp);
free(tmp);
smartcard_log_context(TAG, &call->Common.hContext);
WLog_DBG(
TAG, "..CardIdentifier=%s",
smartcard_array_dump(call->Common.CardIdentifier, sizeof(UUID), buffer, sizeof(buffer)));
- WLog_DBG(TAG, " FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
- WLog_DBG(TAG, " cbDataLen=%" PRIu32, call->Common.cbDataLen);
+ WLog_LVL(TAG, g_LogLevel, " FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
+ WLog_LVL(TAG, g_LogLevel, " cbDataLen=%" PRIu32, call->Common.cbDataLen);
WLog_DBG(
TAG, " pbData=%s",
smartcard_array_dump(call->Common.pbData, call->Common.cbDataLen, buffer, sizeof(buffer)));
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_read_cache_a_call(SMARTCARD_DEVICE* smartcard,
{
char buffer[1024];
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "GetTransmitCount_Call {");
+ WLog_LVL(TAG, g_LogLevel, "GetTransmitCount_Call {");
- WLog_DBG(TAG, " szLookupName=%s", call->szLookupName);
+ WLog_LVL(TAG, g_LogLevel, " szLookupName=%s", call->szLookupName);
smartcard_log_context(TAG, &call->Common.hContext);
WLog_DBG(
TAG, "..CardIdentifier=%s",
smartcard_array_dump(call->Common.CardIdentifier, sizeof(UUID), buffer, sizeof(buffer)));
- WLog_DBG(TAG, " FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
- WLog_DBG(TAG, " fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
- WLog_DBG(TAG, " cbDataLen=%" PRIu32, call->Common.cbDataLen);
+ WLog_LVL(TAG, g_LogLevel, " FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
+ WLog_LVL(TAG, g_LogLevel, " fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
+ WLog_LVL(TAG, g_LogLevel, " cbDataLen=%" PRIu32, call->Common.cbDataLen);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_read_cache_w_call(SMARTCARD_DEVICE* smartcard,
char* tmp;
char buffer[1024];
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "GetTransmitCount_Call {");
+ WLog_LVL(TAG, g_LogLevel, "GetTransmitCount_Call {");
ConvertFromUnicode(CP_UTF8, 0, call->szLookupName, -1, &tmp, 0, NULL, NULL);
- WLog_DBG(TAG, " szLookupName=%s", tmp);
+ WLog_LVL(TAG, g_LogLevel, " szLookupName=%s", tmp);
free(tmp);
smartcard_log_context(TAG, &call->Common.hContext);
WLog_DBG(
TAG, "..CardIdentifier=%s",
smartcard_array_dump(call->Common.CardIdentifier, sizeof(UUID), buffer, sizeof(buffer)));
- WLog_DBG(TAG, " FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
- WLog_DBG(TAG, " fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
- WLog_DBG(TAG, " cbDataLen=%" PRIu32, call->Common.cbDataLen);
+ WLog_LVL(TAG, g_LogLevel, " FreshnessCounter=%" PRIu32, call->Common.FreshnessCounter);
+ WLog_LVL(TAG, g_LogLevel, " fPbDataIsNULL=%" PRId32, call->Common.fPbDataIsNULL);
+ WLog_LVL(TAG, g_LogLevel, " cbDataLen=%" PRIu32, call->Common.cbDataLen);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_transmit_call(SMARTCARD_DEVICE* smartcard, const Transmit_Call* call)
BYTE* pbExtraBytes;
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "Transmit_Call {");
+ WLog_LVL(TAG, g_LogLevel, "Transmit_Call {");
smartcard_log_context(TAG, &call->hContext);
smartcard_log_redir_handle(TAG, &call->hCard);
{
cbExtraBytes = (UINT32)(call->pioSendPci->cbPciLength - sizeof(SCARD_IO_REQUEST));
pbExtraBytes = &((BYTE*)call->pioSendPci)[sizeof(SCARD_IO_REQUEST)];
- WLog_DBG(TAG, "pioSendPci: dwProtocol: %" PRIu32 " cbExtraBytes: %" PRIu32 "",
+ WLog_LVL(TAG, g_LogLevel, "pioSendPci: dwProtocol: %" PRIu32 " cbExtraBytes: %" PRIu32 "",
call->pioSendPci->dwProtocol, cbExtraBytes);
if (cbExtraBytes)
{
- char* szExtraBytes = winpr_BinToHexString(pbExtraBytes, cbExtraBytes, TRUE);
- WLog_DBG(TAG, "pbExtraBytes: %s", szExtraBytes);
- free(szExtraBytes);
+ char buffer[1024];
+ WLog_LVL(TAG, g_LogLevel, "pbExtraBytes: %s",
+ smartcard_array_dump(pbExtraBytes, cbExtraBytes, buffer, sizeof(buffer)));
}
}
else
{
- WLog_DBG(TAG, "pioSendPci: null");
+ WLog_LVL(TAG, g_LogLevel, "pioSendPci: null");
}
- WLog_DBG(TAG, "cbSendLength: %" PRIu32 "", call->cbSendLength);
+ WLog_LVL(TAG, g_LogLevel, "cbSendLength: %" PRIu32 "", call->cbSendLength);
if (call->pbSendBuffer)
{
- char* szSendBuffer = winpr_BinToHexString(call->pbSendBuffer, call->cbSendLength, TRUE);
- WLog_DBG(TAG, "pbSendBuffer: %s", szSendBuffer);
- free(szSendBuffer);
+ char buffer[1024];
+ WLog_DBG(
+ TAG, "pbSendBuffer: %s",
+ smartcard_array_dump(call->pbSendBuffer, call->cbSendLength, buffer, sizeof(buffer)));
}
else
{
- WLog_DBG(TAG, "pbSendBuffer: null");
+ WLog_LVL(TAG, g_LogLevel, "pbSendBuffer: null");
}
if (call->pioRecvPci)
{
cbExtraBytes = (UINT32)(call->pioRecvPci->cbPciLength - sizeof(SCARD_IO_REQUEST));
pbExtraBytes = &((BYTE*)call->pioRecvPci)[sizeof(SCARD_IO_REQUEST)];
- WLog_DBG(TAG, "pioRecvPci: dwProtocol: %" PRIu32 " cbExtraBytes: %" PRIu32 "",
+ WLog_LVL(TAG, g_LogLevel, "pioRecvPci: dwProtocol: %" PRIu32 " cbExtraBytes: %" PRIu32 "",
call->pioRecvPci->dwProtocol, cbExtraBytes);
if (cbExtraBytes)
{
- char* szExtraBytes = winpr_BinToHexString(pbExtraBytes, cbExtraBytes, TRUE);
- WLog_DBG(TAG, "pbExtraBytes: %s", szExtraBytes);
- free(szExtraBytes);
+ char buffer[1024];
+ WLog_LVL(TAG, g_LogLevel, "pbExtraBytes: %s",
+ smartcard_array_dump(pbExtraBytes, cbExtraBytes, buffer, sizeof(buffer)));
}
}
else
{
- WLog_DBG(TAG, "pioRecvPci: null");
+ WLog_LVL(TAG, g_LogLevel, "pioRecvPci: null");
}
- WLog_DBG(TAG, "fpbRecvBufferIsNULL: %" PRId32 " cbRecvLength: %" PRIu32 "",
+ WLog_LVL(TAG, g_LogLevel, "fpbRecvBufferIsNULL: %" PRId32 " cbRecvLength: %" PRIu32 "",
call->fpbRecvBufferIsNULL, call->cbRecvLength);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_locate_cards_by_atr_w_call(SMARTCARD_DEVICE* smartcard,
UINT32 index;
char* szEventState;
char* szCurrentState;
- char* rgbAtr;
+
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "LocateCardsByATRW_Call {");
+ WLog_LVL(TAG, g_LogLevel, "LocateCardsByATRW_Call {");
smartcard_log_context(TAG, &call->hContext);
for (index = 0; index < call->cReaders; index++)
{
+ char buffer[1024];
char* tmp = NULL;
const LPSCARD_READERSTATEW readerState =
(const LPSCARD_READERSTATEW)&call->rgReaderStates[index];
ConvertFromUnicode(CP_UTF8, 0, readerState->szReader, -1, &tmp, 0, NULL, NULL);
- WLog_DBG(TAG, "\t[%" PRIu32 "]: szReader: %s cbAtr: %" PRIu32 "", index, tmp,
+ WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: szReader: %s cbAtr: %" PRIu32 "", index, tmp,
readerState->cbAtr);
szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
szEventState = SCardGetReaderStateString(readerState->dwEventState);
- rgbAtr = winpr_BinToHexString((BYTE*)&(readerState->rgbAtr), readerState->cbAtr, FALSE);
- WLog_DBG(TAG, "\t[%" PRIu32 "]: dwCurrentState: %s (0x%08" PRIX32 ")", index,
+ WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: dwCurrentState: %s (0x%08" PRIX32 ")", index,
szCurrentState, readerState->dwCurrentState);
- WLog_DBG(TAG, "\t[%" PRIu32 "]: dwEventState: %s (0x%08" PRIX32 ")", index, szEventState,
- readerState->dwEventState);
+ WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: dwEventState: %s (0x%08" PRIX32 ")", index,
+ szEventState, readerState->dwEventState);
- if (rgbAtr)
- {
- WLog_DBG(TAG, "\t[%" PRIu32 "]: cbAtr: %" PRIu32 " rgbAtr: %s", index,
- readerState->cbAtr, rgbAtr);
- }
- else
- {
- WLog_DBG(TAG, "\t[%" PRIu32 "]: cbAtr: 0 rgbAtr: n/a", index);
- }
+ WLog_DBG(
+ TAG, "\t[%" PRIu32 "]: cbAtr: %" PRIu32 " rgbAtr: %s", index, readerState->cbAtr,
+ smartcard_array_dump(readerState->rgbAtr, readerState->cbAtr, buffer, sizeof(buffer)));
free(szCurrentState);
free(szEventState);
- free(rgbAtr);
free(tmp);
}
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_transmit_return(SMARTCARD_DEVICE* smartcard, const Transmit_Return* ret)
BYTE* pbExtraBytes;
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "Transmit_Return {");
- WLog_DBG(TAG, "ReturnCode: %s (0x%08" PRIX32 ")", SCardGetErrorString(ret->ReturnCode),
- ret->ReturnCode);
+ WLog_LVL(TAG, g_LogLevel, "Transmit_Return {");
+ WLog_LVL(TAG, g_LogLevel, "ReturnCode: %s (0x%08" PRIX32 ")",
+ SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
if (ret->pioRecvPci)
{
cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength - sizeof(SCARD_IO_REQUEST));
pbExtraBytes = &((BYTE*)ret->pioRecvPci)[sizeof(SCARD_IO_REQUEST)];
- WLog_DBG(TAG, "pioRecvPci: dwProtocol: %" PRIu32 " cbExtraBytes: %" PRIu32 "",
+ WLog_LVL(TAG, g_LogLevel, "pioRecvPci: dwProtocol: %" PRIu32 " cbExtraBytes: %" PRIu32 "",
ret->pioRecvPci->dwProtocol, cbExtraBytes);
if (cbExtraBytes)
{
- char* szExtraBytes = winpr_BinToHexString(pbExtraBytes, cbExtraBytes, TRUE);
- WLog_DBG(TAG, "pbExtraBytes: %s", szExtraBytes);
- free(szExtraBytes);
+ char buffer[1024];
+ WLog_LVL(TAG, g_LogLevel, "pbExtraBytes: %s",
+ smartcard_array_dump(pbExtraBytes, cbExtraBytes, buffer, sizeof(buffer)));
}
}
else
{
- WLog_DBG(TAG, "pioRecvPci: null");
+ WLog_LVL(TAG, g_LogLevel, "pioRecvPci: null");
}
- WLog_DBG(TAG, "cbRecvLength: %" PRIu32 "", ret->cbRecvLength);
+ WLog_LVL(TAG, g_LogLevel, "cbRecvLength: %" PRIu32 "", ret->cbRecvLength);
if (ret->pbRecvBuffer)
{
- char* szRecvBuffer = winpr_BinToHexString(ret->pbRecvBuffer, ret->cbRecvLength, TRUE);
- WLog_DBG(TAG, "pbRecvBuffer: %s", szRecvBuffer);
- free(szRecvBuffer);
+ char buffer[1024];
+ WLog_DBG(
+ TAG, "pbRecvBuffer: %s",
+ smartcard_array_dump(ret->pbRecvBuffer, ret->cbRecvLength, buffer, sizeof(buffer)));
}
else
{
- WLog_DBG(TAG, "pbRecvBuffer: null");
+ WLog_LVL(TAG, g_LogLevel, "pbRecvBuffer: null");
}
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_control_return(SMARTCARD_DEVICE* smartcard, const Control_Return* ret)
{
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "Control_Return {");
- WLog_DBG(TAG, "ReturnCode: %s (0x%08" PRIX32 ")", SCardGetErrorString(ret->ReturnCode),
- ret->ReturnCode);
- WLog_DBG(TAG, "cbOutBufferSize: %" PRIu32 "", ret->cbOutBufferSize);
+ WLog_LVL(TAG, g_LogLevel, "Control_Return {");
+ WLog_LVL(TAG, g_LogLevel, "ReturnCode: %s (0x%08" PRIX32 ")",
+ SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
+ WLog_LVL(TAG, g_LogLevel, "cbOutBufferSize: %" PRIu32 "", ret->cbOutBufferSize);
if (ret->pvOutBuffer)
{
- char* szOutBuffer = winpr_BinToHexString(ret->pvOutBuffer, ret->cbOutBufferSize, TRUE);
- WLog_DBG(TAG, "pvOutBuffer: %s", szOutBuffer);
- free(szOutBuffer);
+ char buffer[1024];
+ WLog_DBG(
+ TAG, "pvOutBuffer: %s",
+ smartcard_array_dump(ret->pvOutBuffer, ret->cbOutBufferSize, buffer, sizeof(buffer)));
}
else
{
- WLog_DBG(TAG, "pvOutBuffer: null");
+ WLog_LVL(TAG, g_LogLevel, "pvOutBuffer: null");
}
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_control_call(SMARTCARD_DEVICE* smartcard, const Control_Call* call)
{
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "Control_Call {");
+ WLog_LVL(TAG, g_LogLevel, "Control_Call {");
smartcard_log_context(TAG, &call->hContext);
smartcard_log_redir_handle(TAG, &call->hCard);
- WLog_DBG(TAG,
+ WLog_LVL(TAG, g_LogLevel,
"dwControlCode: 0x%08" PRIX32 " cbInBufferSize: %" PRIu32
" fpvOutBufferIsNULL: %" PRId32 " cbOutBufferSize: %" PRIu32 "",
call->dwControlCode, call->cbInBufferSize, call->fpvOutBufferIsNULL,
if (call->pvInBuffer)
{
- char* szInBuffer = winpr_BinToHexString(call->pvInBuffer, call->cbInBufferSize, TRUE);
- WLog_DBG(TAG, "pbInBuffer: %s", szInBuffer);
- free(szInBuffer);
+ char buffer[1024];
+ WLog_DBG(
+ TAG, "pbInBuffer: %s",
+ smartcard_array_dump(call->pvInBuffer, call->cbInBufferSize, buffer, sizeof(buffer)));
}
else
{
- WLog_DBG(TAG, "pvInBuffer: null");
+ WLog_LVL(TAG, g_LogLevel, "pvInBuffer: null");
}
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_set_attrib_call(SMARTCARD_DEVICE* smartcard, const SetAttrib_Call* call)
char buffer[8192];
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "GetAttrib_Call {");
+ WLog_LVL(TAG, g_LogLevel, "GetAttrib_Call {");
smartcard_log_context(TAG, &call->hContext);
smartcard_log_redir_handle(TAG, &call->hCard);
- WLog_DBG(TAG, "dwAttrId: 0x%08" PRIX32, call->dwAttrId);
- WLog_DBG(TAG, "cbAttrLen: 0x%08" PRId32, call->cbAttrLen);
- WLog_DBG(TAG, "pbAttr: %s",
+ WLog_LVL(TAG, g_LogLevel, "dwAttrId: 0x%08" PRIX32, call->dwAttrId);
+ WLog_LVL(TAG, g_LogLevel, "cbAttrLen: 0x%08" PRId32, call->cbAttrLen);
+ WLog_LVL(TAG, g_LogLevel, "pbAttr: %s",
smartcard_array_dump(call->pbAttr, call->cbAttrLen, buffer, sizeof(buffer)));
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_get_attrib_return(SMARTCARD_DEVICE* smartcard,
{
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "GetAttrib_Return {");
- WLog_DBG(TAG, "ReturnCode: %s (0x%08" PRIX32 ")", SCardGetErrorString(ret->ReturnCode),
- ret->ReturnCode);
- WLog_DBG(TAG, "dwAttrId: %s (0x%08" PRIX32 ") cbAttrLen: 0x%08" PRIX32 "",
+ WLog_LVL(TAG, g_LogLevel, "GetAttrib_Return {");
+ WLog_LVL(TAG, g_LogLevel, "ReturnCode: %s (0x%08" PRIX32 ")",
+ SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
+ WLog_LVL(TAG, g_LogLevel, "dwAttrId: %s (0x%08" PRIX32 ") cbAttrLen: 0x%08" PRIX32 "",
SCardGetAttributeString(dwAttrId), dwAttrId, ret->cbAttrLen);
if (dwAttrId == SCARD_ATTR_VENDOR_NAME)
{
- WLog_DBG(TAG, "pbAttr: %.*s", ret->cbAttrLen, (char*)ret->pbAttr);
+ WLog_LVL(TAG, g_LogLevel, "pbAttr: %.*s", ret->cbAttrLen, (char*)ret->pbAttr);
}
else if (dwAttrId == SCARD_ATTR_CURRENT_PROTOCOL_TYPE)
{
UINT32 dwProtocolType = *((UINT32*)ret->pbAttr);
- WLog_DBG(TAG, "dwProtocolType: %s (0x%08" PRIX32 ")",
+ WLog_LVL(TAG, g_LogLevel, "dwProtocolType: %s (0x%08" PRIX32 ")",
SCardGetProtocolString(dwProtocolType), dwProtocolType);
}
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_get_attrib_call(SMARTCARD_DEVICE* smartcard, const GetAttrib_Call* call)
{
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "GetAttrib_Call {");
+ WLog_LVL(TAG, g_LogLevel, "GetAttrib_Call {");
smartcard_log_context(TAG, &call->hContext);
smartcard_log_redir_handle(TAG, &call->hCard);
- WLog_DBG(TAG,
+ WLog_LVL(TAG, g_LogLevel,
"dwAttrId: %s (0x%08" PRIX32 ") fpbAttrIsNULL: %" PRId32 " cbAttrLen: 0x%08" PRIX32 "",
SCardGetAttributeString(call->dwAttrId), call->dwAttrId, call->fpbAttrIsNULL,
call->cbAttrLen);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_status_call(SMARTCARD_DEVICE* smartcard, const Status_Call* call,
{
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "Status%s_Call {", unicode ? "W" : "A");
+ WLog_LVL(TAG, g_LogLevel, "Status%s_Call {", unicode ? "W" : "A");
smartcard_log_context(TAG, &call->hContext);
smartcard_log_redir_handle(TAG, &call->hCard);
- WLog_DBG(TAG,
+ WLog_LVL(TAG, g_LogLevel,
"fmszReaderNamesIsNULL: %" PRId32 " cchReaderLen: %" PRIu32 " cbAtrLen: %" PRIu32 "",
call->fmszReaderNamesIsNULL, call->cchReaderLen, call->cbAtrLen);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_status_return(SMARTCARD_DEVICE* smartcard, const Status_Return* ret,
BOOL unicode)
{
- char* pbAtr = NULL;
char* mszReaderNamesA = NULL;
+ char buffer[1024];
+
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
mszReaderNamesA = smartcard_convert_string_list(ret->mszReaderNames, ret->cBytes, unicode);
- pbAtr = winpr_BinToHexString(ret->pbAtr, ret->cbAtrLen, FALSE);
- WLog_DBG(TAG, "Status%s_Return {", unicode ? "W" : "A");
- WLog_DBG(TAG, "ReturnCode: %s (0x%08" PRIX32 ")", SCardGetErrorString(ret->ReturnCode),
- ret->ReturnCode);
- WLog_DBG(TAG, "dwState: %s (0x%08" PRIX32 ") dwProtocol: %s (0x%08" PRIX32 ")",
+ WLog_LVL(TAG, g_LogLevel, "Status%s_Return {", unicode ? "W" : "A");
+ WLog_LVL(TAG, g_LogLevel, "ReturnCode: %s (0x%08" PRIX32 ")",
+ SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
+ WLog_LVL(TAG, g_LogLevel, "dwState: %s (0x%08" PRIX32 ") dwProtocol: %s (0x%08" PRIX32 ")",
SCardGetCardStateString(ret->dwState), ret->dwState,
SCardGetProtocolString(ret->dwProtocol), ret->dwProtocol);
- WLog_DBG(TAG, "cBytes: %" PRIu32 " mszReaderNames: %s", ret->cBytes, mszReaderNamesA);
+ WLog_LVL(TAG, g_LogLevel, "cBytes: %" PRIu32 " mszReaderNames: %s", ret->cBytes,
+ mszReaderNamesA);
- WLog_DBG(TAG, "cbAtrLen: %" PRIu32 " pbAtr: %s", ret->cbAtrLen, pbAtr);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "cbAtrLen: %" PRIu32 " pbAtr: %s", ret->cbAtrLen,
+ smartcard_array_dump(ret->pbAtr, ret->cbAtrLen, buffer, sizeof(buffer)));
+ WLog_LVL(TAG, g_LogLevel, "}");
free(mszReaderNamesA);
- free(pbAtr);
+}
+
+static void smartcard_trace_state_return(SMARTCARD_DEVICE* smartcard, const State_Return* ret)
+{
+ char buffer[1024];
+
+ WINPR_UNUSED(smartcard);
+
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
+ return;
+
+ WLog_LVL(TAG, g_LogLevel, "Reconnect_Return {");
+ WLog_LVL(TAG, g_LogLevel, "ReturnCode: %s (0x%08" PRIX32 ")",
+ SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
+ WLog_LVL(TAG, g_LogLevel, "dwState: %s (0x%08" PRIX32 ")", ret->dwState);
+ WLog_LVL(TAG, g_LogLevel, "dwProtocol: %s (0x%08" PRIX32 ")", ret->dwProtocol);
+ WLog_LVL(TAG, g_LogLevel, "cbAtrLen: %s (0x%08" PRIX32 ")", ret->cbAtrLen);
+ WLog_LVL(TAG, g_LogLevel, "rgAtr: %s",
+ smartcard_array_dump(ret->rgAtr, sizeof(ret->rgAtr), buffer, sizeof(buffer)));
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_reconnect_return(SMARTCARD_DEVICE* smartcard,
{
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "Reconnect_Return {");
- WLog_DBG(TAG, "ReturnCode: %s (0x%08" PRIX32 ")", SCardGetErrorString(ret->ReturnCode),
- ret->ReturnCode);
- WLog_DBG(TAG, "dwActiveProtocol: %s (0x%08" PRIX32 ")",
+ WLog_LVL(TAG, g_LogLevel, "Reconnect_Return {");
+ WLog_LVL(TAG, g_LogLevel, "ReturnCode: %s (0x%08" PRIX32 ")",
+ SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
+ WLog_LVL(TAG, g_LogLevel, "dwActiveProtocol: %s (0x%08" PRIX32 ")",
SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_connect_a_call(SMARTCARD_DEVICE* smartcard, const ConnectA_Call* call)
{
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "ConnectA_Call {");
+ WLog_LVL(TAG, g_LogLevel, "ConnectA_Call {");
smartcard_log_context(TAG, &call->Common.hContext);
- WLog_DBG(TAG,
+ WLog_LVL(TAG, g_LogLevel,
"szReader: %s dwShareMode: %s (0x%08" PRIX32 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
call->szReader, SCardGetShareModeString(call->Common.dwShareMode),
call->Common.dwShareMode, SCardGetProtocolString(call->Common.dwPreferredProtocols),
call->Common.dwPreferredProtocols);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_connect_w_call(SMARTCARD_DEVICE* smartcard, const ConnectW_Call* call)
char* szReaderA = NULL;
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
ConvertFromUnicode(CP_UTF8, 0, call->szReader, -1, &szReaderA, 0, NULL, NULL);
- WLog_DBG(TAG, "ConnectW_Call {");
+ WLog_LVL(TAG, g_LogLevel, "ConnectW_Call {");
smartcard_log_context(TAG, &call->Common.hContext);
- WLog_DBG(TAG,
+ WLog_LVL(TAG, g_LogLevel,
"szReader: %s dwShareMode: %s (0x%08" PRIX32 ") dwPreferredProtocols: %s (0x%08" PRIX32
")",
szReaderA, SCardGetShareModeString(call->Common.dwShareMode), call->Common.dwShareMode,
SCardGetProtocolString(call->Common.dwPreferredProtocols),
call->Common.dwPreferredProtocols);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
free(szReaderA);
}
{
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "%s_Call {", name);
+ WLog_LVL(TAG, g_LogLevel, "%s_Call {", name);
smartcard_log_context(TAG, &call->hContext);
smartcard_log_redir_handle(TAG, &call->hCard);
- WLog_DBG(TAG, "dwDisposition: %s (0x%08" PRIX32 ")",
+ WLog_LVL(TAG, g_LogLevel, "dwDisposition: %s (0x%08" PRIX32 ")",
SCardGetDispositionString(call->dwDisposition), call->dwDisposition);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_establish_context_call(SMARTCARD_DEVICE* smartcard,
{
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "EstablishContext_Call {");
- WLog_DBG(TAG, "dwScope: %s (0x%08" PRIX32 ")", SCardGetScopeString(call->dwScope),
+ WLog_LVL(TAG, g_LogLevel, "EstablishContext_Call {");
+ WLog_LVL(TAG, g_LogLevel, "dwScope: %s (0x%08" PRIX32 ")", SCardGetScopeString(call->dwScope),
call->dwScope);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_establish_context_return(SMARTCARD_DEVICE* smartcard,
{
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "EstablishContext_Return {");
- WLog_DBG(TAG, "ReturnCode: %s (0x%08" PRIX32 ")", SCardGetErrorString(ret->ReturnCode),
- ret->ReturnCode);
+ WLog_LVL(TAG, g_LogLevel, "EstablishContext_Return {");
+ WLog_LVL(TAG, g_LogLevel, "ReturnCode: %s (0x%08" PRIX32 ")",
+ SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
smartcard_log_context(TAG, &ret->hContext);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
void smartcard_trace_long_return(SMARTCARD_DEVICE* smartcard, const Long_Return* ret,
{
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "%s_Return {", name);
- WLog_DBG(TAG, "ReturnCode: %s (0x%08" PRIX32 ")", SCardGetErrorString(ret->ReturnCode),
- ret->ReturnCode);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "%s_Return {", name);
+ WLog_LVL(TAG, g_LogLevel, "ReturnCode: %s (0x%08" PRIX32 ")",
+ SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
+ WLog_LVL(TAG, g_LogLevel, "}");
}
-void smartcard_trace_connect_return(SMARTCARD_DEVICE* smartcard, const Connect_Return* ret)
+static void smartcard_trace_connect_return(SMARTCARD_DEVICE* smartcard, const Connect_Return* ret)
{
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "Connect_Return {");
- WLog_DBG(TAG, "ReturnCode: %s (0x%08" PRIX32 ")", SCardGetErrorString(ret->ReturnCode),
- ret->ReturnCode);
+ WLog_LVL(TAG, g_LogLevel, "Connect_Return {");
+ WLog_LVL(TAG, g_LogLevel, "ReturnCode: %s (0x%08" PRIX32 ")",
+ SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
smartcard_log_context(TAG, &ret->hContext);
smartcard_log_redir_handle(TAG, &ret->hCard);
- WLog_DBG(TAG, "dwActiveProtocol: %s (0x%08" PRIX32 ")",
+ WLog_LVL(TAG, g_LogLevel, "dwActiveProtocol: %s (0x%08" PRIX32 ")",
SCardGetProtocolString(ret->dwActiveProtocol), ret->dwActiveProtocol);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
void smartcard_trace_reconnect_call(SMARTCARD_DEVICE* smartcard, const Reconnect_Call* call)
{
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "Reconnect_Call {");
+ WLog_LVL(TAG, g_LogLevel, "Reconnect_Call {");
smartcard_log_context(TAG, &call->hContext);
smartcard_log_redir_handle(TAG, &call->hCard);
- WLog_DBG(TAG,
+ WLog_LVL(TAG, g_LogLevel,
"dwShareMode: %s (0x%08" PRIX32 ") dwPreferredProtocols: %s (0x%08" PRIX32
") dwInitialization: %s (0x%08" PRIX32 ")",
SCardGetShareModeString(call->dwShareMode), call->dwShareMode,
SCardGetProtocolString(call->dwPreferredProtocols), call->dwPreferredProtocols,
SCardGetDispositionString(call->dwInitialization), call->dwInitialization);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static void smartcard_trace_device_type_id_return(SMARTCARD_DEVICE* smartcard,
{
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "GetDeviceTypeId_Return {");
- WLog_DBG(TAG, " ReturnCode: %s (0x%08" PRIX32 ")", SCardGetErrorString(ret->ReturnCode),
- ret->ReturnCode);
- WLog_DBG(TAG, " dwDeviceId=%08" PRIx32, ret->dwDeviceId);
+ WLog_LVL(TAG, g_LogLevel, "GetDeviceTypeId_Return {");
+ WLog_LVL(TAG, g_LogLevel, " ReturnCode: %s (0x%08" PRIX32 ")",
+ SCardGetErrorString(ret->ReturnCode), ret->ReturnCode);
+ WLog_LVL(TAG, g_LogLevel, " dwDeviceId=%08" PRIx32, ret->dwDeviceId);
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static LONG smartcard_unpack_common_context_and_string_a(SMARTCARD_DEVICE* smartcard, wStream* s,
}
LONG smartcard_pack_redir_scard_context(SMARTCARD_DEVICE* smartcard, wStream* s,
- const REDIR_SCARDCONTEXT* context)
+ const REDIR_SCARDCONTEXT* context, DWORD* index)
{
- UINT32 pbContextNdrPtr;
+ const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
WINPR_UNUSED(smartcard);
- pbContextNdrPtr = (context->cbContext) ? 0x00020001 : 0;
- Stream_Write_UINT32(s, context->cbContext); /* cbContext (4 bytes) */
- Stream_Write_UINT32(s, pbContextNdrPtr); /* pbContextNdrPtr (4 bytes) */
+
+ if (context->cbContext != 0)
+ {
+ Stream_Write_UINT32(s, context->cbContext); /* cbContext (4 bytes) */
+ Stream_Write_UINT32(s, pbContextNdrPtr); /* pbContextNdrPtr (4 bytes) */
+ *index = *index + 1;
+ }
+ else
+ Stream_Zero(s, 8);
+
return SCARD_S_SUCCESS;
}
}
LONG smartcard_pack_redir_scard_handle(SMARTCARD_DEVICE* smartcard, wStream* s,
- const REDIR_SCARDHANDLE* handle)
+ const REDIR_SCARDHANDLE* handle, DWORD* index)
{
- UINT32 pbHandleNdrPtr;
+ const UINT32 pbContextNdrPtr = 0x00020000 + *index * 4;
WINPR_UNUSED(smartcard);
- pbHandleNdrPtr = (handle->cbHandle) ? 0x00020002 : 0;
- Stream_Write_UINT32(s, handle->cbHandle); /* cbHandle (4 bytes) */
- Stream_Write_UINT32(s, pbHandleNdrPtr); /* pbHandleNdrPtr (4 bytes) */
+
+ if (handle->cbHandle != 0)
+ {
+ Stream_Write_UINT32(s, handle->cbHandle); /* cbContext (4 bytes) */
+ Stream_Write_UINT32(s, pbContextNdrPtr); /* pbContextNdrPtr (4 bytes) */
+ *index = *index + 1;
+ }
+ else
+ Stream_Zero(s, 8);
return SCARD_S_SUCCESS;
}
const EstablishContext_Return* ret)
{
LONG status;
+ DWORD index = 0;
smartcard_trace_establish_context_return(smartcard, ret);
- if ((status = smartcard_pack_redir_scard_context(smartcard, s, &(ret->hContext))))
- {
- WLog_ERR(TAG, "smartcard_pack_redir_scard_context failed with error %" PRId32 "", status);
- return status;
- }
+ if (ret->ReturnCode != SCARD_S_SUCCESS)
+ return ret->ReturnCode;
- if ((status = smartcard_pack_redir_scard_context_ref(smartcard, s, &(ret->hContext))))
- WLog_ERR(TAG, "smartcard_pack_redir_scard_context_ref failed with error %" PRId32 "",
- status);
+ if ((status = smartcard_pack_redir_scard_context(smartcard, s, &(ret->hContext), &index)))
+ return status;
- return status;
+ return smartcard_pack_redir_scard_context_ref(smartcard, s, &(ret->hContext));
}
LONG smartcard_unpack_context_call(SMARTCARD_DEVICE* smartcard, wStream* s, Context_Call* call,
LONG smartcard_pack_list_reader_groups_return(SMARTCARD_DEVICE* smartcard, wStream* s,
const ListReaderGroups_Return* ret)
{
- UINT32 mszNdrPtr;
+ DWORD index = 0;
smartcard_trace_list_reader_groups_return(smartcard, ret, FALSE);
+ if (ret->ReturnCode != SCARD_S_SUCCESS)
+ return ret->ReturnCode;
- mszNdrPtr = (ret->cBytes) ? 0x00020008 : 0;
- Stream_EnsureRemainingCapacity(s, ret->cBytes + 32);
- Stream_Write_UINT32(s, ret->cBytes); /* cBytes (4 bytes) */
- Stream_Write_UINT32(s, mszNdrPtr); /* mszNdrPtr (4 bytes) */
-
- if (mszNdrPtr)
- {
- Stream_Write_UINT32(s, ret->cBytes); /* mszNdrLen (4 bytes) */
-
- if (ret->msz)
- Stream_Write(s, ret->msz, ret->cBytes);
- else
- Stream_Zero(s, ret->cBytes);
+ if (!Stream_EnsureRemainingCapacity(s, 4))
+ return SCARD_E_NO_MEMORY;
- smartcard_pack_write_size_align(smartcard, s, ret->cBytes, 4);
- }
+ Stream_Write_UINT32(s, ret->cBytes); /* cBytes (4 bytes) */
+ if (!smartcard_ndr_pointer_write(s, &index, ret->cBytes))
+ return SCARD_E_NO_MEMORY;
- return SCARD_S_SUCCESS;
+ return smartcard_ndr_write(s, ret->msz, ret->cBytes, 1, NDR_PTR_SIMPLE);
}
LONG smartcard_unpack_list_readers_call(SMARTCARD_DEVICE* smartcard, wStream* s,
LONG smartcard_pack_list_readers_return(SMARTCARD_DEVICE* smartcard, wStream* s,
const ListReaders_Return* ret, BOOL unicode)
{
- UINT32 mszNdrPtr;
- LONG error;
+ DWORD index = 0;
smartcard_trace_list_readers_return(smartcard, ret, unicode);
if (ret->ReturnCode != SCARD_S_SUCCESS)
return ret->ReturnCode;
- mszNdrPtr = (ret->cBytes) ? 0x00020008 : 0;
-
- if (!Stream_EnsureRemainingCapacity(s, ret->cBytes + 32))
+ if (!Stream_EnsureRemainingCapacity(s, 4))
{
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
return SCARD_F_INTERNAL_ERROR;
}
Stream_Write_UINT32(s, ret->cBytes); /* cBytes (4 bytes) */
- Stream_Write_UINT32(s, mszNdrPtr); /* mszNdrPtr (4 bytes) */
-
- if (mszNdrPtr)
- {
- Stream_Write_UINT32(s, ret->cBytes); /* mszNdrLen (4 bytes) */
-
- if (ret->msz)
- Stream_Write(s, ret->msz, ret->cBytes);
- else
- Stream_Zero(s, ret->cBytes);
-
- if ((error = smartcard_pack_write_size_align(smartcard, s, ret->cBytes, 4)))
- {
- WLog_ERR(TAG, "smartcard_pack_write_size_align failed with error %" PRId32 "", error);
- return error;
- }
- }
+ if (!smartcard_ndr_pointer_write(s, &index, ret->cBytes))
+ return SCARD_E_NO_MEMORY;
- return SCARD_S_SUCCESS;
+ return smartcard_ndr_write(s, ret->msz, ret->cBytes, unicode ? sizeof(WCHAR) : sizeof(CHAR),
+ NDR_PTR_SIMPLE);
}
static LONG smartcard_unpack_connect_common(SMARTCARD_DEVICE* smartcard, wStream* s,
return status;
}
-LONG smartcard_pack_connect_return(SMARTCARD_DEVICE* smartcard, wStream* s, Connect_Return* ret)
+LONG smartcard_pack_connect_return(SMARTCARD_DEVICE* smartcard, wStream* s,
+ const Connect_Return* ret)
{
LONG status;
+ DWORD index = 0;
- if ((status = smartcard_pack_redir_scard_context(smartcard, s, &(ret->hContext))))
- {
- WLog_ERR(TAG, "smartcard_pack_redir_scard_context failed with error %" PRId32 "", status);
- return status;
- }
+ smartcard_trace_connect_return(smartcard, ret);
+ if (ret->ReturnCode != SCARD_S_SUCCESS)
+ return ret->ReturnCode;
- if ((status = smartcard_pack_redir_scard_handle(smartcard, s, &(ret->hCard))))
- {
- WLog_ERR(TAG, "smartcard_pack_redir_scard_handle failed with error %" PRId32 "", status);
+ status = smartcard_pack_redir_scard_context(smartcard, s, &ret->hContext, &index);
+ if (status)
return status;
- }
- Stream_Write_UINT32(s, ret->dwActiveProtocol); /* dwActiveProtocol (4 bytes) */
-
- if ((status = smartcard_pack_redir_scard_context_ref(smartcard, s, &(ret->hContext))))
- {
- WLog_ERR(TAG, "smartcard_pack_redir_scard_context_ref failed with error %" PRId32 "",
- status);
+ status = smartcard_pack_redir_scard_handle(smartcard, s, &ret->hCard, &index);
+ if (status)
return status;
- }
- if ((status = smartcard_pack_redir_scard_handle_ref(smartcard, s, &(ret->hCard))))
- WLog_ERR(TAG, "smartcard_pack_redir_scard_handle_ref failed with error %" PRId32 "",
- status);
+ if (!Stream_EnsureRemainingCapacity(s, 4))
+ return SCARD_E_NO_MEMORY;
- return status;
+ Stream_Write_UINT32(s, ret->dwActiveProtocol); /* dwActiveProtocol (4 bytes) */
+ status = smartcard_pack_redir_scard_context_ref(smartcard, s, &ret->hContext);
+ if (status)
+ return status;
+ return smartcard_pack_redir_scard_handle_ref(smartcard, s, &(ret->hCard));
}
LONG smartcard_unpack_reconnect_call(SMARTCARD_DEVICE* smartcard, wStream* s, Reconnect_Call* call)
LONG smartcard_pack_reconnect_return(SMARTCARD_DEVICE* smartcard, wStream* s,
const Reconnect_Return* ret)
{
- WINPR_UNUSED(smartcard);
smartcard_trace_reconnect_return(smartcard, ret);
+ if (ret->ReturnCode != SCARD_S_SUCCESS)
+ return ret->ReturnCode;
+
+ if (!Stream_EnsureRemainingCapacity(s, 4))
+ return SCARD_E_NO_MEMORY;
Stream_Write_UINT32(s, ret->dwActiveProtocol); /* dwActiveProtocol (4 bytes) */
return SCARD_S_SUCCESS;
}
LPSCARD_READERSTATEA readerState;
WINPR_UNUSED(smartcard);
- if (!WLog_IsLevelActive(WLog_Get(TAG), WLOG_DEBUG))
+ if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
return;
- WLog_DBG(TAG, "GetStatusChangeA_Call {");
+ WLog_LVL(TAG, g_LogLevel, "GetStatusChangeA_Call {");
smartcard_log_context(TAG, &call->hContext);
- WLog_DBG(TAG, "dwTimeOut: 0x%08" PRIX32 " cReaders: %" PRIu32 "", call->dwTimeOut,
+ WLog_LVL(TAG, g_LogLevel, "dwTimeOut: 0x%08" PRIX32 " cReaders: %" PRIu32 "", call->dwTimeOut,
call->cReaders);
for (index = 0; index < call->cReaders; index++)
{
readerState = &call->rgReaderStates[index];
- WLog_DBG(TAG, "\t[%" PRIu32 "]: szReader: %s cbAtr: %" PRIu32 "", index,
+ WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: szReader: %s cbAtr: %" PRIu32 "", index,
readerState->szReader, readerState->cbAtr);
szCurrentState = SCardGetReaderStateString(readerState->dwCurrentState);
szEventState = SCardGetReaderStateString(readerState->dwEventState);
- WLog_DBG(TAG, "\t[%" PRIu32 "]: dwCurrentState: %s (0x%08" PRIX32 ")", index,
+ WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: dwCurrentState: %s (0x%08" PRIX32 ")", index,
szCurrentState, readerState->dwCurrentState);
- WLog_DBG(TAG, "\t[%" PRIu32 "]: dwEventState: %s (0x%08" PRIX32 ")", index, szEventState,
- readerState->dwEventState);
+ WLog_LVL(TAG, g_LogLevel, "\t[%" PRIu32 "]: dwEventState: %s (0x%08" PRIX32 ")", index,
+ szEventState, readerState->dwEventState);
free(szCurrentState);
free(szEventState);
}
- WLog_DBG(TAG, "}");
+ WLog_LVL(TAG, g_LogLevel, "}");
}
static LONG smartcard_unpack_reader_state_a(wStream* s, LPSCARD_READERSTATEA* ppcReaders,
Stream_Read_UINT32(s, readerState->dwCurrentState); /* dwCurrentState (4 bytes) */
Stream_Read_UINT32(s, readerState->dwEventState); /* dwEventState (4 bytes) */
Stream_Read_UINT32(s, readerState->cbAtr); /* cbAtr (4 bytes) */
- Stream_Read(s, readerState->rgbAtr, 32); /* rgbAtr [0..32] (32 bytes) */
- Stream_Seek(s, 4); /* rgbAtr [32..36] (4 bytes) */
+ Stream_Read(s, readerState->rgbAtr, 36); /* rgbAtr [0..36] (36 bytes) */
}
for (index = 0; index < cReaders; index++)
Stream_Read_UINT32(s, readerState->dwCurrentState); /* dwCurrentState (4 bytes) */
Stream_Read_UINT32(s, readerState->dwEventState); /* dwEventState (4 bytes) */
Stream_Read_UINT32(s, readerState->cbAtr); /* cbAtr (4 bytes) */
- Stream_Read(s, readerState->rgbAtr, 32); /* rgbAtr [0..32] (32 bytes) */
- Stream_Seek(s, 4); /* rgbAtr [32..36] (4 bytes) */
+ Stream_Read(s, readerState->rgbAtr, 36); /* rgbAtr [0..36] (36 bytes) */
}
for (index = 0; index < cReaders; index++)
LONG smartcard_pack_get_status_change_return(SMARTCARD_DEVICE* smartcard, wStream* s,
const GetStatusChange_Return* ret, BOOL unicode)
{
- UINT32 index;
- ReaderState_Return* rgReaderState;
- WINPR_UNUSED(smartcard);
+ UINT32 index = 0;
smartcard_trace_get_status_change_return(smartcard, ret, unicode);
+ if (ret->ReturnCode != SCARD_S_SUCCESS)
+ return ret->ReturnCode;
- Stream_Write_UINT32(s, ret->cReaders); /* cReaders (4 bytes) */
- Stream_Write_UINT32(s, 0x00020100); /* rgReaderStatesNdrPtr (4 bytes) */
- Stream_Write_UINT32(s, ret->cReaders); /* rgReaderStatesNdrCount (4 bytes) */
-
- for (index = 0; index < ret->cReaders; index++)
- {
- rgReaderState = &(ret->rgReaderStates[index]);
- Stream_Write_UINT32(s, rgReaderState->dwCurrentState); /* dwCurrentState (4 bytes) */
- Stream_Write_UINT32(s, rgReaderState->dwEventState); /* dwEventState (4 bytes) */
- Stream_Write_UINT32(s, rgReaderState->cbAtr); /* cbAtr (4 bytes) */
- Stream_Write(s, rgReaderState->rgbAtr, 32); /* rgbAtr [0..32] (32 bytes) */
- Stream_Zero(s, 4); /* rgbAtr [32..36] (32 bytes) */
- }
+ if (!Stream_EnsureRemainingCapacity(s, 4))
+ return SCARD_E_NO_MEMORY;
- return SCARD_S_SUCCESS;
+ Stream_Write_UINT32(s, ret->cReaders); /* cReaders (4 bytes) */
+ if (!smartcard_ndr_pointer_write(s, &index, ret->cReaders))
+ return SCARD_E_NO_MEMORY;
+ return smartcard_ndr_write_state(s, ret->rgReaderStates, ret->cReaders, NDR_PTR_SIMPLE);
}
LONG smartcard_unpack_state_call(SMARTCARD_DEVICE* smartcard, wStream* s, State_Call* call)
LONG smartcard_pack_state_return(SMARTCARD_DEVICE* smartcard, wStream* s, const State_Return* ret)
{
- LONG status;
+ DWORD index = 0;
+
+ smartcard_trace_state_return(smartcard, ret);
+ if (ret->ReturnCode != SCARD_S_SUCCESS)
+ return ret->ReturnCode;
+
Stream_Write_UINT32(s, ret->dwState); /* dwState (4 bytes) */
Stream_Write_UINT32(s, ret->dwProtocol); /* dwProtocol (4 bytes) */
Stream_Write_UINT32(s, ret->cbAtrLen); /* cbAtrLen (4 bytes) */
- Stream_Write_UINT32(s, 0x00020020); /* rgAtrNdrPtr (4 bytes) */
- Stream_Write_UINT32(s, ret->cbAtrLen); /* rgAtrLength (4 bytes) */
- Stream_Write(s, ret->rgAtr, ret->cbAtrLen); /* rgAtr */
-
- if ((status = smartcard_pack_write_size_align(smartcard, s, ret->cbAtrLen, 4)))
- WLog_ERR(TAG, "smartcard_pack_write_size_align failed with error %" PRId32 "", status);
-
- return status;
+ if (!smartcard_ndr_pointer_write(s, &index, ret->cbAtrLen))
+ return SCARD_E_NO_MEMORY;
+ return smartcard_ndr_write(s, ret->rgAtr, ret->cbAtrLen, 1, NDR_PTR_SIMPLE);
}
LONG smartcard_unpack_status_call(SMARTCARD_DEVICE* smartcard, wStream* s, Status_Call* call,
LONG smartcard_pack_status_return(SMARTCARD_DEVICE* smartcard, wStream* s, const Status_Return* ret,
BOOL unicode)
{
- LONG status;
+ DWORD index = 0;
smartcard_trace_status_return(smartcard, ret, unicode);
- if (!Stream_EnsureRemainingCapacity(s, ret->cBytes + 64))
- {
- WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
+ if (ret->ReturnCode != SCARD_S_SUCCESS)
+ return ret->ReturnCode;
+
+ if (!Stream_EnsureRemainingCapacity(s, 4))
return SCARD_F_INTERNAL_ERROR;
- }
Stream_Write_UINT32(s, ret->cBytes); /* cBytes (4 bytes) */
- Stream_Write_UINT32(s, 0x00020010); /* mszReaderNamesNdrPtr (4 bytes) */
+ if (!smartcard_ndr_pointer_write(s, &index, ret->cBytes))
+ return SCARD_E_NO_MEMORY;
+
+ if (!Stream_EnsureRemainingCapacity(s, 44))
+ return SCARD_F_INTERNAL_ERROR;
+
Stream_Write_UINT32(s, ret->dwState); /* dwState (4 bytes) */
Stream_Write_UINT32(s, ret->dwProtocol); /* dwProtocol (4 bytes) */
Stream_Write(s, ret->pbAtr, 32); /* pbAtr (32 bytes) */
Stream_Write_UINT32(s, ret->cbAtrLen); /* cbAtrLen (4 bytes) */
- Stream_Write_UINT32(s, ret->cBytes); /* mszReaderNamesNdrLen (4 bytes) */
-
- if (ret->mszReaderNames)
- Stream_Write(s, ret->mszReaderNames, ret->cBytes);
- else
- Stream_Zero(s, ret->cBytes);
-
- if ((status = smartcard_pack_write_size_align(smartcard, s, ret->cBytes, 4)))
- WLog_ERR(TAG, "smartcard_pack_write_size_align failed with error %" PRId32 "", status);
-
- return status;
+ return smartcard_ndr_write(s, ret->mszReaderNames, ret->cBytes,
+ unicode ? sizeof(WCHAR) : sizeof(CHAR), NDR_PTR_SIMPLE);
}
LONG smartcard_unpack_get_attrib_call(SMARTCARD_DEVICE* smartcard, wStream* s, GetAttrib_Call* call)
LONG smartcard_pack_get_attrib_return(SMARTCARD_DEVICE* smartcard, wStream* s,
const GetAttrib_Return* ret, DWORD dwAttrId)
{
- LONG status;
-
+ DWORD index = 0;
smartcard_trace_get_attrib_return(smartcard, ret, dwAttrId);
- if (!Stream_EnsureRemainingCapacity(s, ret->cbAttrLen + 32))
- {
- WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
+ if (ret->ReturnCode != SCARD_S_SUCCESS)
+ return ret->ReturnCode;
+
+ if (!Stream_EnsureRemainingCapacity(s, 4))
return SCARD_F_INTERNAL_ERROR;
- }
Stream_Write_UINT32(s, ret->cbAttrLen); /* cbAttrLen (4 bytes) */
- Stream_Write_UINT32(s, 0x00020080); /* pbAttrNdrPtr (4 bytes) */
- Stream_Write_UINT32(s, ret->cbAttrLen); /* pbAttrNdrCount (4 bytes) */
-
- if (!ret->pbAttr)
- Stream_Zero(s, ret->cbAttrLen); /* pbAttr */
- else
- Stream_Write(s, ret->pbAttr, ret->cbAttrLen); /* pbAttr */
-
- if ((status = smartcard_pack_write_size_align(smartcard, s, ret->cbAttrLen, 4)))
- WLog_ERR(TAG, "smartcard_pack_write_size_align failed with error %" PRId32 "", status);
+ if (!smartcard_ndr_pointer_write(s, &index, ret->cbAttrLen))
+ return SCARD_E_NO_MEMORY;
- return status;
+ return smartcard_ndr_write(s, ret->pbAttr, ret->cbAttrLen, 1, NDR_PTR_SIMPLE);
}
LONG smartcard_unpack_control_call(SMARTCARD_DEVICE* smartcard, wStream* s, Control_Call* call)
LONG smartcard_pack_control_return(SMARTCARD_DEVICE* smartcard, wStream* s,
const Control_Return* ret)
{
- LONG error;
+ DWORD index = 0;
smartcard_trace_control_return(smartcard, ret);
- if (!Stream_EnsureRemainingCapacity(s, ret->cbOutBufferSize + 32))
- {
- WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
+ if (ret->ReturnCode != SCARD_S_SUCCESS)
+ return ret->ReturnCode;
+
+ if (!Stream_EnsureRemainingCapacity(s, 4))
return SCARD_F_INTERNAL_ERROR;
- }
Stream_Write_UINT32(s, ret->cbOutBufferSize); /* cbOutBufferSize (4 bytes) */
- Stream_Write_UINT32(s, 0x00020040); /* pvOutBufferPointer (4 bytes) */
- Stream_Write_UINT32(s, ret->cbOutBufferSize); /* pvOutBufferLength (4 bytes) */
-
- if (ret->cbOutBufferSize > 0)
- {
- Stream_Write(s, ret->pvOutBuffer, ret->cbOutBufferSize); /* pvOutBuffer */
-
- if ((error = smartcard_pack_write_size_align(smartcard, s, ret->cbOutBufferSize, 4)))
- {
- WLog_ERR(TAG, "smartcard_pack_write_size_align failed with error %" PRId32 "", error);
- return error;
- }
- }
+ if (!smartcard_ndr_pointer_write(s, &index, ret->cbOutBufferSize))
+ return SCARD_E_NO_MEMORY;
- return SCARD_S_SUCCESS;
+ return smartcard_ndr_write(s, ret->pvOutBuffer, ret->cbOutBufferSize, 1, NDR_PTR_SIMPLE);
}
LONG smartcard_unpack_transmit_call(SMARTCARD_DEVICE* smartcard, wStream* s, Transmit_Call* call)
LONG smartcard_pack_transmit_return(SMARTCARD_DEVICE* smartcard, wStream* s,
const Transmit_Return* ret)
{
- UINT32 cbExtraBytes;
- BYTE* pbExtraBytes;
- UINT32 pioRecvPciNdrPtr;
- UINT32 pbRecvBufferNdrPtr;
- UINT32 pbExtraBytesNdrPtr;
+ DWORD index = 0;
LONG error;
UINT32 cbRecvLength = ret->cbRecvLength;
+ UINT32 cbRecvPci = ret->pioRecvPci ? ret->pioRecvPci->cbPciLength : 0;
smartcard_trace_transmit_return(smartcard, ret);
+ if (ret->ReturnCode != SCARD_S_SUCCESS)
+ return ret->ReturnCode;
+
if (!ret->pbRecvBuffer)
cbRecvLength = 0;
- pioRecvPciNdrPtr = (ret->pioRecvPci) ? 0x00020000 : 0;
- pbRecvBufferNdrPtr = (ret->pbRecvBuffer) ? 0x00020004 : 0;
- Stream_Write_UINT32(s, pioRecvPciNdrPtr); /* pioRecvPciNdrPtr (4 bytes) */
- Stream_Write_UINT32(s, cbRecvLength); /* cbRecvLength (4 bytes) */
- Stream_Write_UINT32(s, pbRecvBufferNdrPtr); /* pbRecvBufferNdrPtr (4 bytes) */
+ if (!smartcard_ndr_pointer_write(s, &index, cbRecvPci))
+ return SCARD_E_NO_MEMORY;
+ if (!Stream_EnsureRemainingCapacity(s, 4))
+ return SCARD_E_NO_MEMORY;
+ Stream_Write_UINT32(s, cbRecvLength); /* cbRecvLength (4 bytes) */
+ if (!smartcard_ndr_pointer_write(s, &index, cbRecvLength))
+ return SCARD_E_NO_MEMORY;
- if (pioRecvPciNdrPtr)
+ if (ret->pioRecvPci)
{
- cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength - sizeof(SCARD_IO_REQUEST));
- pbExtraBytes = &((BYTE*)ret->pioRecvPci)[sizeof(SCARD_IO_REQUEST)];
- pbExtraBytesNdrPtr = cbExtraBytes ? 0x00020008 : 0;
+ UINT32 cbExtraBytes = (UINT32)(ret->pioRecvPci->cbPciLength - sizeof(SCARD_IO_REQUEST));
+ BYTE* pbExtraBytes = &((BYTE*)ret->pioRecvPci)[sizeof(SCARD_IO_REQUEST)];
if (!Stream_EnsureRemainingCapacity(s, cbExtraBytes + 16))
{
Stream_Write_UINT32(s, ret->pioRecvPci->dwProtocol); /* dwProtocol (4 bytes) */
Stream_Write_UINT32(s, cbExtraBytes); /* cbExtraBytes (4 bytes) */
- Stream_Write_UINT32(s, pbExtraBytesNdrPtr); /* pbExtraBytesNdrPtr (4 bytes) */
-
- if (pbExtraBytesNdrPtr)
- {
- Stream_Write_UINT32(s, cbExtraBytes); /* Length (4 bytes) */
- Stream_Write(s, pbExtraBytes, cbExtraBytes);
-
- if ((error = smartcard_pack_write_size_align(smartcard, s, cbExtraBytes, 4)))
- {
- WLog_ERR(TAG, "smartcard_pack_write_size_align failed with error %" PRId32 "!",
- error);
- return error;
- }
- }
- }
-
- if (pbRecvBufferNdrPtr)
- {
- if (!Stream_EnsureRemainingCapacity(s, ret->cbRecvLength + 16))
- {
- WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
- return SCARD_F_INTERNAL_ERROR;
- }
-
- Stream_Write_UINT32(s, ret->cbRecvLength); /* pbRecvBufferNdrLen (4 bytes) */
- Stream_Write(s, ret->pbRecvBuffer, ret->cbRecvLength);
-
- if ((error = smartcard_pack_write_size_align(smartcard, s, ret->cbRecvLength, 4)))
- {
- WLog_ERR(TAG, "smartcard_pack_write_size_align failed with error %" PRId32 "!", error);
+ if (!smartcard_ndr_pointer_write(s, &index, cbExtraBytes))
+ return SCARD_E_NO_MEMORY;
+ error = smartcard_ndr_write(s, pbExtraBytes, cbExtraBytes, 1, NDR_PTR_SIMPLE);
+ if (error)
return error;
- }
}
- return SCARD_S_SUCCESS;
+ return smartcard_ndr_write(s, ret->pbRecvBuffer, ret->cbRecvLength, 1, NDR_PTR_SIMPLE);
}
LONG smartcard_unpack_locate_cards_by_atr_a_call(SMARTCARD_DEVICE* smartcard, wStream* s,
return SCARD_S_SUCCESS;
}
-LONG smartcard_pack_set_attrib_return(SMARTCARD_DEVICE* smartcard, wStream* s,
- const GetAttrib_Return* ret)
-{
- LONG error;
-
- if (!Stream_EnsureRemainingCapacity(s, ret->cbAttrLen + 8))
- {
- WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
- return SCARD_F_INTERNAL_ERROR;
- }
-
- Stream_Write_UINT32(s, ret->cbAttrLen); /* cbOutBufferSize (4 bytes) */
- Stream_Write(s, ret->pbAttr, ret->cbAttrLen);
-
- if ((error = smartcard_pack_write_size_align(smartcard, s, ret->cbAttrLen, 4)))
- {
- WLog_ERR(TAG, "smartcard_pack_write_size_align failed with error %" PRId32 "", error);
- return error;
- }
-
- return SCARD_S_SUCCESS;
-}
-
LONG smartcard_unpack_locate_cards_by_atr_w_call(SMARTCARD_DEVICE* smartcard, wStream* s,
LocateCardsByATRW_Call* call)
{
LONG smartcard_pack_device_type_id_return(SMARTCARD_DEVICE* smartcard, wStream* s,
const GetDeviceTypeId_Return* ret)
{
- WINPR_UNUSED(smartcard);
smartcard_trace_device_type_id_return(smartcard, ret);
+ if (ret->ReturnCode != SCARD_S_SUCCESS)
+ return ret->ReturnCode;
- if (!Stream_EnsureRemainingCapacity(s, 8))
+ if (!Stream_EnsureRemainingCapacity(s, 4))
{
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
return SCARD_F_INTERNAL_ERROR;
LONG smartcard_pack_locate_cards_return(SMARTCARD_DEVICE* smartcard, wStream* s,
const LocateCards_Return* ret)
{
-
- UINT32 pbDataNdrPtr = (ret->rgReaderStates) ? 0x00020000 : 0;
+ DWORD index = 0;
smartcard_trace_locate_cards_return(smartcard, ret);
- if (!Stream_EnsureRemainingCapacity(s, 8))
+ if (ret->ReturnCode != SCARD_S_SUCCESS)
+ return ret->ReturnCode;
+
+ if (!Stream_EnsureRemainingCapacity(s, 4))
{
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
return SCARD_F_INTERNAL_ERROR;
}
Stream_Write_UINT32(s, ret->cReaders); /* cBytes (4 cbDataLen) */
- Stream_Write_UINT32(s, pbDataNdrPtr);
- if (ret->rgReaderStates)
- {
- size_t x, size;
-
- size = sizeof(ReaderState_Return) * ret->cReaders;
- if (!Stream_EnsureRemainingCapacity(s, size + 8))
- {
- WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
- return SCARD_F_INTERNAL_ERROR;
- }
-
- Stream_Write_UINT32(s, (UINT32)size);
- for (x = 0; x < ret->cReaders; x++)
- {
- ReaderState_Return* reader = &ret->rgReaderStates[x];
- Stream_Write_UINT32(s, reader->dwCurrentState);
- Stream_Write_UINT32(s, reader->dwEventState);
- Stream_Write_UINT32(s, reader->cbAtr);
- Stream_Write(s, reader->rgbAtr, sizeof(reader->rgbAtr));
- }
- smartcard_pack_write_size_align(smartcard, s, (UINT32)size, 4);
- }
+ if (!smartcard_ndr_pointer_write(s, &index, ret->cReaders))
+ return SCARD_E_NO_MEMORY;
- return SCARD_S_SUCCESS;
+ return smartcard_ndr_write_state(s, ret->rgReaderStates, ret->cReaders, NDR_PTR_SIMPLE);
}
LONG smartcard_pack_get_reader_icon_return(SMARTCARD_DEVICE* smartcard, wStream* s,
const GetReaderIcon_Return* ret)
{
- UINT32 pbDataNdrPtr = (ret->pbData) ? 0x00020000 : 0;
+ DWORD index = 0;
smartcard_trace_get_reader_icon_return(smartcard, ret);
- if (!Stream_EnsureRemainingCapacity(s, 8))
+ if (ret->ReturnCode != SCARD_S_SUCCESS)
+ return ret->ReturnCode;
+
+ if (!Stream_EnsureRemainingCapacity(s, 4))
{
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
return SCARD_F_INTERNAL_ERROR;
}
Stream_Write_UINT32(s, ret->cbDataLen); /* cBytes (4 cbDataLen) */
- Stream_Write_UINT32(s, pbDataNdrPtr);
- if (ret->pbData)
- {
- if (!Stream_EnsureRemainingCapacity(s, ret->cbDataLen + 8))
- {
- WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
- return SCARD_F_INTERNAL_ERROR;
- }
-
- Stream_Write_UINT32(s, ret->cbDataLen);
- Stream_Write(s, ret->pbData, ret->cbDataLen);
- smartcard_pack_write_size_align(smartcard, s, ret->cbDataLen, 4);
- }
+ if (!smartcard_ndr_pointer_write(s, &index, ret->cbDataLen))
+ return SCARD_E_NO_MEMORY;
- return SCARD_S_SUCCESS;
+ return smartcard_ndr_write(s, ret->pbData, ret->cbDataLen, 1, NDR_PTR_SIMPLE);
}
LONG smartcard_pack_get_transmit_count_return(SMARTCARD_DEVICE* smartcard, wStream* s,
const GetTransmitCount_Return* ret)
{
-
smartcard_trace_get_transmit_count_return(smartcard, ret);
- if (!Stream_EnsureRemainingCapacity(s, 8))
+ if (ret->ReturnCode != SCARD_S_SUCCESS)
+ return ret->ReturnCode;
+
+ if (!Stream_EnsureRemainingCapacity(s, 4))
{
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
return SCARD_F_INTERNAL_ERROR;
LONG smartcard_pack_read_cache_return(SMARTCARD_DEVICE* smartcard, wStream* s,
const ReadCache_Return* ret)
{
- UINT32 pbDataNdrPtr = (ret->pbData) ? 0x00020000 : 0;
+ DWORD index = 0;
+
smartcard_trace_read_cache_return(smartcard, ret);
- if (!Stream_EnsureRemainingCapacity(s, 8))
+ if (ret->ReturnCode != SCARD_S_SUCCESS)
+ return ret->ReturnCode;
+
+ if (!Stream_EnsureRemainingCapacity(s, 4))
{
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
return SCARD_F_INTERNAL_ERROR;
}
Stream_Write_UINT32(s, ret->cbDataLen); /* cBytes (4 cbDataLen) */
- Stream_Write_UINT32(s, pbDataNdrPtr);
- if (ret->pbData)
- {
- if (!Stream_EnsureRemainingCapacity(s, ret->cbDataLen + 8))
- {
- WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
- return SCARD_F_INTERNAL_ERROR;
- }
-
- Stream_Write_UINT32(s, ret->cbDataLen);
- Stream_Write(s, ret->pbData, ret->cbDataLen);
- smartcard_pack_write_size_align(smartcard, s, ret->cbDataLen, 4);
- }
+ if (!smartcard_ndr_pointer_write(s, &index, ret->cbDataLen))
+ return SCARD_E_NO_MEMORY;
- return SCARD_S_SUCCESS;
+ return smartcard_ndr_write(s, ret->pbData, ret->cbDataLen, 1, NDR_PTR_SIMPLE);
}
* Smart Card API
*
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
+ * Copyright 2020 Armin Novak <armin.novak@thincast.com>
+ * Copyright 2020 Thincast Technologies GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
return SCARD_E_UNSUPPORTED_FEATURE;
}
-static LONG PCSC_MapErrorCodeToWinSCard(LONG errorCode)
+static LONG PCSC_MapErrorCodeToWinSCard(PCSC_LONG errorCode)
{
/**
* pcsc-lite returns SCARD_E_UNEXPECTED when it
if (errorCode == SCARD_E_UNEXPECTED)
errorCode = SCARD_E_UNSUPPORTED_FEATURE;
}
+
return errorCode;
}
LPSCARDCONTEXT phContext)
{
WINPR_UNUSED(dwScope); /* SCARD_SCOPE_SYSTEM is the only scope supported by pcsc-lite */
- LONG status = SCARD_S_SUCCESS;
+ PCSC_LONG status = SCARD_S_SUCCESS;
if (!g_PCSC.pfnSCardEstablishContext)
return PCSC_SCard_LogError("g_PCSC.pfnSCardEstablishContext");
- status = (LONG)g_PCSC.pfnSCardEstablishContext(SCARD_SCOPE_SYSTEM, pvReserved1, pvReserved2,
- phContext);
- status = PCSC_MapErrorCodeToWinSCard(status);
- return status;
+ status =
+ g_PCSC.pfnSCardEstablishContext(SCARD_SCOPE_SYSTEM, pvReserved1, pvReserved2, phContext);
+ return PCSC_MapErrorCodeToWinSCard(status);
}
static LONG WINAPI PCSC_SCardEstablishContext(DWORD dwScope, LPCVOID pvReserved1,
static LONG WINAPI PCSC_SCardReleaseContext_Internal(SCARDCONTEXT hContext)
{
- LONG status = SCARD_S_SUCCESS;
+ PCSC_LONG status = SCARD_S_SUCCESS;
if (!g_PCSC.pfnSCardReleaseContext)
return PCSC_SCard_LogError("g_PCSC.pfnSCardReleaseContext");
if (!hContext)
{
WLog_ERR(TAG, "SCardReleaseContext: null hContext");
- return status;
+ return PCSC_MapErrorCodeToWinSCard(status);
}
- status = (LONG)g_PCSC.pfnSCardReleaseContext(hContext);
- status = PCSC_MapErrorCodeToWinSCard(status);
- return status;
+ status = g_PCSC.pfnSCardReleaseContext(hContext);
+ return PCSC_MapErrorCodeToWinSCard(status);
}
static LONG WINAPI PCSC_SCardReleaseContext(SCARDCONTEXT hContext)
static LONG WINAPI PCSC_SCardIsValidContext(SCARDCONTEXT hContext)
{
- LONG status = SCARD_S_SUCCESS;
+ PCSC_LONG status = SCARD_S_SUCCESS;
if (!g_PCSC.pfnSCardIsValidContext)
return PCSC_SCard_LogError("g_PCSC.pfnSCardIsValidContext");
- status = (LONG)g_PCSC.pfnSCardIsValidContext(hContext);
- status = PCSC_MapErrorCodeToWinSCard(status);
- return status;
+ status = g_PCSC.pfnSCardIsValidContext(hContext);
+ return PCSC_MapErrorCodeToWinSCard(status);
}
static LONG WINAPI PCSC_SCardListReaderGroups_Internal(SCARDCONTEXT hContext, LPSTR mszGroups,
LPDWORD pcchGroups)
{
- LONG status = SCARD_S_SUCCESS;
+ PCSC_LONG status = SCARD_S_SUCCESS;
BOOL pcchGroupsAlloc = FALSE;
LPSTR* pMszGroups = (LPSTR*)mszGroups;
PCSC_DWORD pcsc_cchGroups = 0;
if (pcchGroupsAlloc && !g_SCardAutoAllocate)
{
pcsc_cchGroups = 0;
- status = (LONG)g_PCSC.pfnSCardListReaderGroups(hContext, NULL, &pcsc_cchGroups);
+ status = g_PCSC.pfnSCardListReaderGroups(hContext, NULL, &pcsc_cchGroups);
if (status == SCARD_S_SUCCESS)
{
if (!*pMszGroups)
return SCARD_E_NO_MEMORY;
- status = (LONG)g_PCSC.pfnSCardListReaderGroups(hContext, *pMszGroups, &pcsc_cchGroups);
+ status = g_PCSC.pfnSCardListReaderGroups(hContext, *pMszGroups, &pcsc_cchGroups);
if (status != SCARD_S_SUCCESS)
free(*pMszGroups);
}
else
{
- status = (LONG)g_PCSC.pfnSCardListReaderGroups(hContext, mszGroups, &pcsc_cchGroups);
+ status = g_PCSC.pfnSCardListReaderGroups(hContext, mszGroups, &pcsc_cchGroups);
}
- status = PCSC_MapErrorCodeToWinSCard(status);
*pcchGroups = (DWORD)pcsc_cchGroups;
- return status;
+ return PCSC_MapErrorCodeToWinSCard(status);
}
static LONG WINAPI PCSC_SCardListReaderGroupsA(SCARDCONTEXT hContext, LPSTR mszGroups,
static LONG WINAPI PCSC_SCardListReaders_Internal(SCARDCONTEXT hContext, LPCSTR mszGroups,
LPSTR mszReaders, LPDWORD pcchReaders)
{
- LONG status = SCARD_S_SUCCESS;
+ PCSC_LONG status = SCARD_S_SUCCESS;
BOOL pcchReadersAlloc = FALSE;
LPSTR* pMszReaders = (LPSTR*)mszReaders;
PCSC_DWORD pcsc_cchReaders = 0;
if (pcchReadersAlloc && !g_SCardAutoAllocate)
{
pcsc_cchReaders = 0;
- status = (LONG)g_PCSC.pfnSCardListReaders(hContext, mszGroups, NULL, &pcsc_cchReaders);
+ status = g_PCSC.pfnSCardListReaders(hContext, mszGroups, NULL, &pcsc_cchReaders);
if (status == SCARD_S_SUCCESS)
{
if (!*pMszReaders)
return SCARD_E_NO_MEMORY;
- status = (LONG)g_PCSC.pfnSCardListReaders(hContext, mszGroups, *pMszReaders,
- &pcsc_cchReaders);
+ status =
+ g_PCSC.pfnSCardListReaders(hContext, mszGroups, *pMszReaders, &pcsc_cchReaders);
if (status != SCARD_S_SUCCESS)
free(*pMszReaders);
}
else
{
- status =
- (LONG)g_PCSC.pfnSCardListReaders(hContext, mszGroups, mszReaders, &pcsc_cchReaders);
+ status = g_PCSC.pfnSCardListReaders(hContext, mszGroups, mszReaders, &pcsc_cchReaders);
}
- status = PCSC_MapErrorCodeToWinSCard(status);
*pcchReaders = (DWORD)pcsc_cchReaders;
- return status;
+ return PCSC_MapErrorCodeToWinSCard(status);
}
static LONG WINAPI PCSC_SCardListReadersA(SCARDCONTEXT hContext, LPCSTR mszGroups, LPSTR mszReaders,
static LONG WINAPI PCSC_SCardFreeMemory_Internal(SCARDCONTEXT hContext, LPVOID pvMem)
{
- LONG status = SCARD_S_SUCCESS;
+ PCSC_LONG status = SCARD_S_SUCCESS;
if (PCSC_RemoveMemoryBlock(hContext, pvMem))
{
{
if (g_PCSC.pfnSCardFreeMemory)
{
- status = (LONG)g_PCSC.pfnSCardFreeMemory(hContext, pvMem);
- status = PCSC_MapErrorCodeToWinSCard(status);
+ status = g_PCSC.pfnSCardFreeMemory(hContext, pvMem);
}
}
- return status;
+ return PCSC_MapErrorCodeToWinSCard(status);
}
static LONG WINAPI PCSC_SCardFreeMemory(SCARDCONTEXT hContext, LPVOID pvMem)
DWORD cReaders)
{
PCSC_DWORD i, j;
- int* map;
+ INT64* map;
PCSC_DWORD cMappedReaders;
PCSC_SCARD_READERSTATE* states;
- LONG status = SCARD_S_SUCCESS;
+ PCSC_LONG status = SCARD_S_SUCCESS;
PCSC_DWORD pcsc_dwTimeout = (PCSC_DWORD)dwTimeout;
PCSC_DWORD pcsc_cReaders = (PCSC_DWORD)cReaders;
* To work around this apparent lack of "\\\\?PnP?\\Notification" support,
* we have to filter rgReaderStates to exclude the special PnP reader name.
*/
- map = (int*)calloc(pcsc_cReaders, sizeof(int));
+ map = (INT64*)calloc(pcsc_cReaders, sizeof(INT64));
if (!map)
return SCARD_E_NO_MEMORY;
}
}
- map[i] = j;
+ map[i] = (INT64)j;
states[j].szReader = rgReaderStates[i].szReader;
states[j].dwCurrentState = rgReaderStates[i].dwCurrentState;
states[j].pvUserData = rgReaderStates[i].pvUserData;
if (cMappedReaders > 0)
{
- status =
- (LONG)g_PCSC.pfnSCardGetStatusChange(hContext, pcsc_dwTimeout, states, cMappedReaders);
- status = PCSC_MapErrorCodeToWinSCard(status);
+ status = g_PCSC.pfnSCardGetStatusChange(hContext, pcsc_dwTimeout, states, cMappedReaders);
}
else
{
if (map[i] < 0)
continue; /* unmapped */
- j = map[i];
- rgReaderStates[i].dwCurrentState = states[j].dwCurrentState;
- rgReaderStates[i].cbAtr = states[j].cbAtr;
+ j = (PCSC_DWORD)map[i];
+ rgReaderStates[i].dwCurrentState = (DWORD)states[j].dwCurrentState;
+ rgReaderStates[i].cbAtr = (DWORD)states[j].cbAtr;
CopyMemory(&(rgReaderStates[i].rgbAtr), &(states[j].rgbAtr), PCSC_MAX_ATR_SIZE);
- rgReaderStates[i].dwEventState = states[j].dwEventState;
+ rgReaderStates[i].dwEventState = (DWORD)states[j].dwEventState;
}
free(map);
free(states);
- return status;
+ return PCSC_MapErrorCodeToWinSCard(status);
}
static LONG WINAPI PCSC_SCardGetStatusChangeA(SCARDCONTEXT hContext, DWORD dwTimeout,
static LONG WINAPI PCSC_SCardCancel(SCARDCONTEXT hContext)
{
- LONG status = SCARD_S_SUCCESS;
+ PCSC_LONG status = SCARD_S_SUCCESS;
if (!g_PCSC.pfnSCardCancel)
return PCSC_SCard_LogError("g_PCSC.pfnSCardCancel");
- status = (LONG)g_PCSC.pfnSCardCancel(hContext);
- status = PCSC_MapErrorCodeToWinSCard(status);
- return status;
+ status = g_PCSC.pfnSCardCancel(hContext);
+ return PCSC_MapErrorCodeToWinSCard(status);
}
static LONG WINAPI PCSC_SCardConnect_Internal(SCARDCONTEXT hContext, LPCSTR szReader,
LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol)
{
BOOL shared;
- char* szReaderPCSC;
- LONG status = SCARD_S_SUCCESS;
+ const char* szReaderPCSC;
+ PCSC_LONG status = SCARD_S_SUCCESS;
PCSC_SCARDHANDLE* pCard = NULL;
PCSC_DWORD pcsc_dwShareMode = (PCSC_DWORD)dwShareMode;
PCSC_DWORD pcsc_dwPreferredProtocols = 0;
shared = (dwShareMode == SCARD_SHARE_DIRECT) ? TRUE : FALSE;
PCSC_WaitForCardAccess(hContext, 0, shared);
- szReaderPCSC = (char*)szReader;
+ szReaderPCSC = szReader;
/**
* As stated here :
pcsc_dwPreferredProtocols =
(PCSC_DWORD)PCSC_ConvertProtocolsFromWinSCard(dwPreferredProtocols);
- status =
- (LONG)g_PCSC.pfnSCardConnect(hContext, szReaderPCSC, pcsc_dwShareMode,
- pcsc_dwPreferredProtocols, phCard, &pcsc_dwActiveProtocol);
- status = PCSC_MapErrorCodeToWinSCard(status);
+ status = g_PCSC.pfnSCardConnect(hContext, szReaderPCSC, pcsc_dwShareMode,
+ pcsc_dwPreferredProtocols, phCard, &pcsc_dwActiveProtocol);
if (status == SCARD_S_SUCCESS)
{
PCSC_WaitForCardAccess(hContext, pCard->hSharedContext, shared);
}
- return status;
+ return PCSC_MapErrorCodeToWinSCard(status);
}
static LONG WINAPI PCSC_SCardConnectA(SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode,
LPDWORD pdwActiveProtocol)
{
BOOL shared;
- LONG status = SCARD_S_SUCCESS;
+ PCSC_LONG status = SCARD_S_SUCCESS;
PCSC_DWORD pcsc_dwShareMode = (PCSC_DWORD)dwShareMode;
PCSC_DWORD pcsc_dwPreferredProtocols = 0;
PCSC_DWORD pcsc_dwInitialization = (PCSC_DWORD)dwInitialization;
shared = (dwShareMode == SCARD_SHARE_DIRECT) ? TRUE : FALSE;
PCSC_WaitForCardAccess(0, hCard, shared);
pcsc_dwPreferredProtocols = (PCSC_DWORD)PCSC_ConvertProtocolsFromWinSCard(dwPreferredProtocols);
- status = (LONG)g_PCSC.pfnSCardReconnect(hCard, pcsc_dwShareMode, pcsc_dwPreferredProtocols,
- pcsc_dwInitialization, &pcsc_dwActiveProtocol);
- status = PCSC_MapErrorCodeToWinSCard(status);
+ status = g_PCSC.pfnSCardReconnect(hCard, pcsc_dwShareMode, pcsc_dwPreferredProtocols,
+ pcsc_dwInitialization, &pcsc_dwActiveProtocol);
+
*pdwActiveProtocol = PCSC_ConvertProtocolsToWinSCard((DWORD)pcsc_dwActiveProtocol);
- return status;
+ return PCSC_MapErrorCodeToWinSCard(status);
}
static LONG WINAPI PCSC_SCardDisconnect(SCARDHANDLE hCard, DWORD dwDisposition)
{
- LONG status = SCARD_S_SUCCESS;
+ PCSC_LONG status = SCARD_S_SUCCESS;
PCSC_DWORD pcsc_dwDisposition = (PCSC_DWORD)dwDisposition;
if (!g_PCSC.pfnSCardDisconnect)
return PCSC_SCard_LogError("g_PCSC.pfnSCardDisconnect");
- status = (LONG)g_PCSC.pfnSCardDisconnect(hCard, pcsc_dwDisposition);
- status = PCSC_MapErrorCodeToWinSCard(status);
+ status = g_PCSC.pfnSCardDisconnect(hCard, pcsc_dwDisposition);
if (status == SCARD_S_SUCCESS)
{
}
PCSC_ReleaseCardAccess(0, hCard);
- return status;
+ return PCSC_MapErrorCodeToWinSCard(status);
}
static LONG WINAPI PCSC_SCardBeginTransaction(SCARDHANDLE hCard)
{
- LONG status = SCARD_S_SUCCESS;
+ PCSC_LONG status = SCARD_S_SUCCESS;
PCSC_SCARDHANDLE* pCard = NULL;
PCSC_SCARDCONTEXT* pContext = NULL;
if (pContext->isTransactionLocked)
return SCARD_S_SUCCESS; /* disable nested transactions */
- status = (LONG)g_PCSC.pfnSCardBeginTransaction(hCard);
- status = PCSC_MapErrorCodeToWinSCard(status);
+ status = g_PCSC.pfnSCardBeginTransaction(hCard);
+
pContext->isTransactionLocked = TRUE;
- return status;
+ return PCSC_MapErrorCodeToWinSCard(status);
}
static LONG WINAPI PCSC_SCardEndTransaction(SCARDHANDLE hCard, DWORD dwDisposition)
{
- LONG status = SCARD_S_SUCCESS;
+ PCSC_LONG status = SCARD_S_SUCCESS;
PCSC_SCARDHANDLE* pCard = NULL;
PCSC_SCARDCONTEXT* pContext = NULL;
PCSC_DWORD pcsc_dwDisposition = (PCSC_DWORD)dwDisposition;
if (!pContext->isTransactionLocked)
return SCARD_S_SUCCESS; /* disable nested transactions */
- status = (LONG)g_PCSC.pfnSCardEndTransaction(hCard, pcsc_dwDisposition);
- status = PCSC_MapErrorCodeToWinSCard(status);
+ status = g_PCSC.pfnSCardEndTransaction(hCard, pcsc_dwDisposition);
+
pContext->isTransactionLocked = FALSE;
- return status;
+ return PCSC_MapErrorCodeToWinSCard(status);
}
static LONG WINAPI PCSC_SCardCancelTransaction(SCARDHANDLE hCard)
PCSC_DWORD cchReaderLen;
SCARDCONTEXT hContext = 0;
LPSTR mszReaderNames = NULL;
- LONG status = SCARD_S_SUCCESS;
+ PCSC_LONG status = SCARD_S_SUCCESS;
PCSC_SCARDHANDLE* pCard = NULL;
PCSC_DWORD pcsc_dwState = 0;
PCSC_DWORD pcsc_dwProtocol = 0;
return SCARD_E_INVALID_VALUE;
cchReaderLen = SCARD_AUTOALLOCATE;
- status = (LONG)g_PCSC.pfnSCardStatus(hCard, (LPSTR)&mszReaderNames, &cchReaderLen,
- &pcsc_dwState, &pcsc_dwProtocol, pbAtr, &pcsc_cbAtrLen);
- status = PCSC_MapErrorCodeToWinSCard(status);
+ status = g_PCSC.pfnSCardStatus(hCard, (LPSTR)&mszReaderNames, &cchReaderLen, &pcsc_dwState,
+ &pcsc_dwProtocol, pbAtr, &pcsc_cbAtrLen);
if (mszReaderNames)
PCSC_SCardFreeMemory_Internal(hContext, mszReaderNames);
*pdwState = (DWORD)pcsc_dwState;
*pdwProtocol = PCSC_ConvertProtocolsToWinSCard((DWORD)pcsc_dwProtocol);
*pcbAtrLen = (DWORD)pcsc_cbAtrLen;
- return status;
+ return PCSC_MapErrorCodeToWinSCard(status);
}
/*
{
PCSC_SCARDHANDLE* pCard = NULL;
SCARDCONTEXT hContext;
- LONG status;
+ PCSC_LONG status;
PCSC_DWORD pcsc_cchReaderLen = 0;
PCSC_DWORD pcsc_cbAtrLen = 0;
PCSC_DWORD pcsc_dwState = 0;
if (!hContext)
return SCARD_E_INVALID_VALUE;
- status = (LONG)g_PCSC.pfnSCardStatus(hCard, NULL, &pcsc_cchReaderLen, NULL, NULL, NULL,
- &pcsc_cbAtrLen);
+ status =
+ g_PCSC.pfnSCardStatus(hCard, NULL, &pcsc_cchReaderLen, NULL, NULL, NULL, &pcsc_cbAtrLen);
if (status != STATUS_SUCCESS)
return PCSC_MapErrorCodeToWinSCard(status);
atr = tATR;
}
- status = (LONG)g_PCSC.pfnSCardStatus(hCard, readerNames, &pcsc_cchReaderLen, &pcsc_dwState,
- &pcsc_dwProtocol, atr, &pcsc_cbAtrLen);
+ status = g_PCSC.pfnSCardStatus(hCard, readerNames, &pcsc_cchReaderLen, &pcsc_dwState,
+ &pcsc_dwProtocol, atr, &pcsc_cbAtrLen);
if (status != STATUS_SUCCESS)
goto out_fail;
LPSCARD_IO_REQUEST pioRecvPci, LPBYTE pbRecvBuffer,
LPDWORD pcbRecvLength)
{
- LONG status = SCARD_S_SUCCESS;
+ PCSC_LONG status = SCARD_S_SUCCESS;
PCSC_SCARDHANDLE* pCard = NULL;
PCSC_DWORD cbExtraBytes = 0;
BYTE* pbExtraBytes = NULL;
* pcsc-lite cannot have a null pioSendPci parameter, unlike WinSCard.
* Query the current protocol and use default SCARD_IO_REQUEST for it.
*/
- status = (LONG)g_PCSC.pfnSCardStatus(hCard, NULL, &cchReaderLen, &dwState, &dwProtocol,
- NULL, &cbAtrLen);
+ status = g_PCSC.pfnSCardStatus(hCard, NULL, &cchReaderLen, &dwState, &dwProtocol, NULL,
+ &cbAtrLen);
if (status == SCARD_S_SUCCESS)
{
CopyMemory(pcsc_pbExtraBytes, pbExtraBytes, cbExtraBytes);
}
- status = (LONG)g_PCSC.pfnSCardTransmit(hCard, pcsc_pioSendPci, pbSendBuffer, pcsc_cbSendLength,
- pcsc_pioRecvPci, pbRecvBuffer, &pcsc_cbRecvLength);
- status = PCSC_MapErrorCodeToWinSCard(status);
+ status = g_PCSC.pfnSCardTransmit(hCard, pcsc_pioSendPci, pbSendBuffer, pcsc_cbSendLength,
+ pcsc_pioRecvPci, pbRecvBuffer, &pcsc_cbRecvLength);
+
*pcbRecvLength = (DWORD)pcsc_cbRecvLength;
if (pioSendPci)
non null */
}
- return status;
+ return PCSC_MapErrorCodeToWinSCard(status);
+ ;
}
static LONG WINAPI PCSC_SCardGetTransmitCount(SCARDHANDLE hCard, LPDWORD pcTransmitCount)
DWORD IoCtlAccess = 0;
DWORD IoCtlDeviceType = 0;
BOOL getFeatureRequest = FALSE;
- LONG status = SCARD_S_SUCCESS;
+ PCSC_LONG status = SCARD_S_SUCCESS;
PCSC_SCARDHANDLE* pCard = NULL;
PCSC_DWORD pcsc_dwControlCode = 0;
PCSC_DWORD pcsc_cbInBufferSize = (PCSC_DWORD)cbInBufferSize;
dwControlCode = PCSC_SCARD_CTL_CODE(IoCtlFunction);
pcsc_dwControlCode = (PCSC_DWORD)dwControlCode;
- status =
- (LONG)g_PCSC.pfnSCardControl(hCard, pcsc_dwControlCode, lpInBuffer, pcsc_cbInBufferSize,
- lpOutBuffer, pcsc_cbOutBufferSize, &pcsc_BytesReturned);
- status = PCSC_MapErrorCodeToWinSCard(status);
+ status = g_PCSC.pfnSCardControl(hCard, pcsc_dwControlCode, lpInBuffer, pcsc_cbInBufferSize,
+ lpOutBuffer, pcsc_cbOutBufferSize, &pcsc_BytesReturned);
+
*lpBytesReturned = (DWORD)pcsc_BytesReturned;
if (getFeatureRequest)
}
}
- return status;
+ return PCSC_MapErrorCodeToWinSCard(status);
+ ;
}
static LONG WINAPI PCSC_SCardGetAttrib_Internal(SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE pbAttr,
SCARDCONTEXT hContext = 0;
BOOL pcbAttrLenAlloc = FALSE;
LPBYTE* pPbAttr = (LPBYTE*)pbAttr;
- LONG status = SCARD_S_SUCCESS;
+ PCSC_LONG status = SCARD_S_SUCCESS;
PCSC_SCARDHANDLE* pCard = NULL;
PCSC_DWORD pcsc_dwAttrId = (PCSC_DWORD)dwAttrId;
PCSC_DWORD pcsc_cbAttrLen = 0;
if (pcbAttrLenAlloc && !g_SCardAutoAllocate)
{
pcsc_cbAttrLen = 0;
- status = (LONG)g_PCSC.pfnSCardGetAttrib(hCard, pcsc_dwAttrId, NULL, &pcsc_cbAttrLen);
+ status = g_PCSC.pfnSCardGetAttrib(hCard, pcsc_dwAttrId, NULL, &pcsc_cbAttrLen);
if (status == SCARD_S_SUCCESS)
{
if (!*pPbAttr)
return SCARD_E_NO_MEMORY;
- status =
- (LONG)g_PCSC.pfnSCardGetAttrib(hCard, pcsc_dwAttrId, *pPbAttr, &pcsc_cbAttrLen);
+ status = g_PCSC.pfnSCardGetAttrib(hCard, pcsc_dwAttrId, *pPbAttr, &pcsc_cbAttrLen);
if (status != SCARD_S_SUCCESS)
free(*pPbAttr);
}
else
{
- status = (LONG)g_PCSC.pfnSCardGetAttrib(hCard, pcsc_dwAttrId, pbAttr, &pcsc_cbAttrLen);
+ status = g_PCSC.pfnSCardGetAttrib(hCard, pcsc_dwAttrId, pbAttr, &pcsc_cbAttrLen);
}
- status = PCSC_MapErrorCodeToWinSCard(status);
-
if (status == SCARD_S_SUCCESS)
*pcbAttrLen = (DWORD)pcsc_cbAttrLen;
-
- return status;
+ return PCSC_MapErrorCodeToWinSCard(status);
}
static LONG WINAPI PCSC_SCardGetAttrib_FriendlyName(SCARDHANDLE hCard, DWORD dwAttrId,
}
else
{
+
if (dwAttrId == SCARD_ATTR_CURRENT_PROTOCOL_TYPE)
{
if (!pcbAttrLenAlloc)
static LONG WINAPI PCSC_SCardSetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, LPCBYTE pbAttr,
DWORD cbAttrLen)
{
- LONG status = SCARD_S_SUCCESS;
+ PCSC_LONG status = SCARD_S_SUCCESS;
PCSC_SCARDHANDLE* pCard = NULL;
PCSC_DWORD pcsc_dwAttrId = (PCSC_DWORD)dwAttrId;
PCSC_DWORD pcsc_cbAttrLen = (PCSC_DWORD)cbAttrLen;
return SCARD_E_INVALID_VALUE;
PCSC_WaitForCardAccess(0, hCard, pCard->shared);
- status = (LONG)g_PCSC.pfnSCardSetAttrib(hCard, pcsc_dwAttrId, pbAttr, pcsc_cbAttrLen);
- status = PCSC_MapErrorCodeToWinSCard(status);
- return status;
+ status = g_PCSC.pfnSCardSetAttrib(hCard, pcsc_dwAttrId, pbAttr, pcsc_cbAttrLen);
+ return PCSC_MapErrorCodeToWinSCard(status);
}
static LONG WINAPI PCSC_SCardUIDlgSelectCardA(LPOPENCARDNAMEA_EX pDlgStruc)
HashTable_Remove(ctx->cache, id);
HashTable_Add(ctx->cache, id, data);
- free(id);
+
return SCARD_S_SUCCESS;
}
HashTable_Remove(ctx->cache, id);
HashTable_Add(ctx->cache, id, data);
- free(id);
+
return SCARD_S_SUCCESS;
}