Merge pull request #3774 from akallabeth/smartcard_reader_groups
smartcard: implement ListReaderGroups
This commit is contained in:
commit
c806d0e1ed
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -436,49 +436,83 @@ typedef struct _WriteCacheW_Call
|
||||
|
||||
#include "smartcard_main.h"
|
||||
|
||||
LONG smartcard_pack_write_size_align(SMARTCARD_DEVICE* smartcard, wStream* s, UINT32 size, UINT32 alignment);
|
||||
LONG smartcard_unpack_read_size_align(SMARTCARD_DEVICE* smartcard, wStream* s, UINT32 size, UINT32 alignment);
|
||||
LONG smartcard_pack_write_size_align(SMARTCARD_DEVICE* smartcard, wStream* s, UINT32 size,
|
||||
UINT32 alignment);
|
||||
LONG smartcard_unpack_read_size_align(SMARTCARD_DEVICE* smartcard, wStream* s, UINT32 size,
|
||||
UINT32 alignment);
|
||||
|
||||
SCARDCONTEXT smartcard_scard_context_native_from_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDCONTEXT* context);
|
||||
void smartcard_scard_context_native_to_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDCONTEXT* context, SCARDCONTEXT hContext);
|
||||
SCARDCONTEXT smartcard_scard_context_native_from_redir(SMARTCARD_DEVICE* smartcard,
|
||||
REDIR_SCARDCONTEXT* context);
|
||||
void smartcard_scard_context_native_to_redir(SMARTCARD_DEVICE* smartcard,
|
||||
REDIR_SCARDCONTEXT* context, SCARDCONTEXT hContext);
|
||||
|
||||
SCARDHANDLE smartcard_scard_handle_native_from_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDHANDLE* handle);
|
||||
void smartcard_scard_handle_native_to_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDHANDLE* handle, SCARDHANDLE hCard);
|
||||
SCARDHANDLE smartcard_scard_handle_native_from_redir(SMARTCARD_DEVICE* smartcard,
|
||||
REDIR_SCARDHANDLE* handle);
|
||||
void smartcard_scard_handle_native_to_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDHANDLE* handle,
|
||||
SCARDHANDLE hCard);
|
||||
|
||||
LONG smartcard_unpack_common_type_header(SMARTCARD_DEVICE* smartcard, wStream* s);
|
||||
LONG smartcard_pack_common_type_header(SMARTCARD_DEVICE* smartcard, wStream* s);
|
||||
|
||||
LONG smartcard_unpack_private_type_header(SMARTCARD_DEVICE* smartcard, wStream* s);
|
||||
LONG smartcard_pack_private_type_header(SMARTCARD_DEVICE* smartcard, wStream* s, UINT32 objectBufferLength);
|
||||
LONG smartcard_pack_private_type_header(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
UINT32 objectBufferLength);
|
||||
|
||||
LONG smartcard_unpack_redir_scard_context(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDCONTEXT* context);
|
||||
LONG smartcard_pack_redir_scard_context(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDCONTEXT* context);
|
||||
LONG smartcard_unpack_redir_scard_context(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
REDIR_SCARDCONTEXT* context);
|
||||
LONG smartcard_pack_redir_scard_context(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
REDIR_SCARDCONTEXT* context);
|
||||
|
||||
LONG smartcard_unpack_redir_scard_context_ref(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDCONTEXT* context);
|
||||
LONG smartcard_pack_redir_scard_context_ref(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDCONTEXT* context);
|
||||
LONG smartcard_unpack_redir_scard_context_ref(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
REDIR_SCARDCONTEXT* context);
|
||||
LONG smartcard_pack_redir_scard_context_ref(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
REDIR_SCARDCONTEXT* context);
|
||||
|
||||
LONG smartcard_unpack_redir_scard_handle(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDHANDLE* handle);
|
||||
LONG smartcard_pack_redir_scard_handle(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDHANDLE* handle);
|
||||
LONG smartcard_unpack_redir_scard_handle(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
REDIR_SCARDHANDLE* handle);
|
||||
LONG smartcard_pack_redir_scard_handle(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
REDIR_SCARDHANDLE* handle);
|
||||
|
||||
LONG smartcard_unpack_redir_scard_handle_ref(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDHANDLE* handle);
|
||||
LONG smartcard_pack_redir_scard_handle_ref(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDHANDLE* handle);
|
||||
LONG smartcard_unpack_redir_scard_handle_ref(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
REDIR_SCARDHANDLE* handle);
|
||||
LONG smartcard_pack_redir_scard_handle_ref(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
REDIR_SCARDHANDLE* handle);
|
||||
|
||||
LONG smartcard_unpack_establish_context_call(SMARTCARD_DEVICE* smartcard, wStream* s, EstablishContext_Call* call);
|
||||
void smartcard_trace_establish_context_call(SMARTCARD_DEVICE* smartcard, EstablishContext_Call* call);
|
||||
LONG smartcard_unpack_establish_context_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
EstablishContext_Call* call);
|
||||
void smartcard_trace_establish_context_call(SMARTCARD_DEVICE* smartcard,
|
||||
EstablishContext_Call* call);
|
||||
|
||||
LONG smartcard_pack_establish_context_return(SMARTCARD_DEVICE* smartcard, wStream* s, EstablishContext_Return* ret);
|
||||
void smartcard_trace_establish_context_return(SMARTCARD_DEVICE* smartcard, EstablishContext_Return* ret);
|
||||
LONG smartcard_pack_establish_context_return(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
EstablishContext_Return* ret);
|
||||
void smartcard_trace_establish_context_return(SMARTCARD_DEVICE* smartcard,
|
||||
EstablishContext_Return* ret);
|
||||
|
||||
LONG smartcard_unpack_context_call(SMARTCARD_DEVICE* smartcard, wStream* s, Context_Call* call);
|
||||
void smartcard_trace_context_call(SMARTCARD_DEVICE* smartcard, Context_Call* call, const char* name);
|
||||
void smartcard_trace_context_call(SMARTCARD_DEVICE* smartcard, Context_Call* call,
|
||||
const char* name);
|
||||
|
||||
void smartcard_trace_long_return(SMARTCARD_DEVICE* smartcard, Long_Return* ret, const char* name);
|
||||
|
||||
LONG smartcard_unpack_list_readers_call(SMARTCARD_DEVICE* smartcard, wStream* s, ListReaders_Call* call);
|
||||
void smartcard_trace_list_readers_call(SMARTCARD_DEVICE* smartcard, ListReaders_Call* call, BOOL unicode);
|
||||
LONG smartcard_unpack_list_reader_groups_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
ListReaderGroups_Call* call);
|
||||
void smartcard_trace_list_reader_groups_call(SMARTCARD_DEVICE* smartcard,
|
||||
ListReaderGroups_Call* call, BOOL unicode);
|
||||
|
||||
LONG smartcard_pack_list_readers_return(SMARTCARD_DEVICE* smartcard, wStream* s, ListReaders_Return* ret);
|
||||
void smartcard_trace_list_readers_return(SMARTCARD_DEVICE* smartcard, ListReaders_Return* ret, BOOL unicode);
|
||||
LONG smartcard_pack_list_reader_groups_return(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
ListReaderGroups_Return* ret);
|
||||
void smartcard_trace_list_reader_groups_return(SMARTCARD_DEVICE* smartcard,
|
||||
ListReaderGroups_Return* ret, BOOL unicode);
|
||||
|
||||
LONG smartcard_unpack_list_readers_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
ListReaders_Call* call);
|
||||
void smartcard_trace_list_readers_call(SMARTCARD_DEVICE* smartcard, ListReaders_Call* call,
|
||||
BOOL unicode);
|
||||
|
||||
LONG smartcard_pack_list_readers_return(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
ListReaders_Return* ret);
|
||||
void smartcard_trace_list_readers_return(SMARTCARD_DEVICE* smartcard, ListReaders_Return* ret,
|
||||
BOOL unicode);
|
||||
|
||||
LONG smartcard_unpack_connect_a_call(SMARTCARD_DEVICE* smartcard, wStream* s, ConnectA_Call* call);
|
||||
void smartcard_trace_connect_a_call(SMARTCARD_DEVICE* smartcard, ConnectA_Call* call);
|
||||
@ -492,20 +526,29 @@ void smartcard_trace_connect_return(SMARTCARD_DEVICE* smartcard, Connect_Return*
|
||||
LONG smartcard_unpack_reconnect_call(SMARTCARD_DEVICE* smartcard, wStream* s, Reconnect_Call* call);
|
||||
void smartcard_trace_reconnect_call(SMARTCARD_DEVICE* smartcard, Reconnect_Call* call);
|
||||
|
||||
LONG smartcard_pack_reconnect_return(SMARTCARD_DEVICE* smartcard, wStream* s, Reconnect_Return* ret);
|
||||
LONG smartcard_pack_reconnect_return(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
Reconnect_Return* ret);
|
||||
void smartcard_trace_reconnect_return(SMARTCARD_DEVICE* smartcard, Reconnect_Return* ret);
|
||||
|
||||
LONG smartcard_unpack_hcard_and_disposition_call(SMARTCARD_DEVICE* smartcard, wStream* s, HCardAndDisposition_Call* call);
|
||||
void smartcard_trace_hcard_and_disposition_call(SMARTCARD_DEVICE* smartcard, HCardAndDisposition_Call* call, const char* name);
|
||||
LONG smartcard_unpack_hcard_and_disposition_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
HCardAndDisposition_Call* call);
|
||||
void smartcard_trace_hcard_and_disposition_call(SMARTCARD_DEVICE* smartcard,
|
||||
HCardAndDisposition_Call* call, const char* name);
|
||||
|
||||
LONG smartcard_unpack_get_status_change_a_call(SMARTCARD_DEVICE* smartcard, wStream* s, GetStatusChangeA_Call* call);
|
||||
void smartcard_trace_get_status_change_a_call(SMARTCARD_DEVICE* smartcard, GetStatusChangeA_Call* call);
|
||||
LONG smartcard_unpack_get_status_change_a_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
GetStatusChangeA_Call* call);
|
||||
void smartcard_trace_get_status_change_a_call(SMARTCARD_DEVICE* smartcard,
|
||||
GetStatusChangeA_Call* call);
|
||||
|
||||
LONG smartcard_unpack_get_status_change_w_call(SMARTCARD_DEVICE* smartcard, wStream* s, GetStatusChangeW_Call* call);
|
||||
void smartcard_trace_get_status_change_w_call(SMARTCARD_DEVICE* smartcard, GetStatusChangeW_Call* call);
|
||||
LONG smartcard_unpack_get_status_change_w_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
GetStatusChangeW_Call* call);
|
||||
void smartcard_trace_get_status_change_w_call(SMARTCARD_DEVICE* smartcard,
|
||||
GetStatusChangeW_Call* call);
|
||||
|
||||
LONG smartcard_pack_get_status_change_return(SMARTCARD_DEVICE* smartcard, wStream* s, GetStatusChange_Return* ret);
|
||||
void smartcard_trace_get_status_change_return(SMARTCARD_DEVICE* smartcard, GetStatusChange_Return* ret, BOOL unicode);
|
||||
LONG smartcard_pack_get_status_change_return(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
GetStatusChange_Return* ret);
|
||||
void smartcard_trace_get_status_change_return(SMARTCARD_DEVICE* smartcard,
|
||||
GetStatusChange_Return* ret, BOOL unicode);
|
||||
|
||||
LONG smartcard_unpack_state_call(SMARTCARD_DEVICE* smartcard, wStream* s, State_Call* call);
|
||||
LONG smartcard_pack_state_return(SMARTCARD_DEVICE* smartcard, wStream* s, State_Return* ret);
|
||||
@ -516,11 +559,14 @@ void smartcard_trace_status_call(SMARTCARD_DEVICE* smartcard, Status_Call* call,
|
||||
LONG smartcard_pack_status_return(SMARTCARD_DEVICE* smartcard, wStream* s, Status_Return* ret);
|
||||
void smartcard_trace_status_return(SMARTCARD_DEVICE* smartcard, Status_Return* ret, BOOL unicode);
|
||||
|
||||
LONG smartcard_unpack_get_attrib_call(SMARTCARD_DEVICE* smartcard, wStream* s, GetAttrib_Call* call);
|
||||
LONG smartcard_unpack_get_attrib_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
GetAttrib_Call* call);
|
||||
void smartcard_trace_get_attrib_call(SMARTCARD_DEVICE* smartcard, GetAttrib_Call* call);
|
||||
|
||||
LONG smartcard_pack_get_attrib_return(SMARTCARD_DEVICE* smartcard, wStream* s, GetAttrib_Return* ret);
|
||||
void smartcard_trace_get_attrib_return(SMARTCARD_DEVICE* smartcard, GetAttrib_Return* ret, DWORD dwAttrId);
|
||||
LONG smartcard_pack_get_attrib_return(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
GetAttrib_Return* ret);
|
||||
void smartcard_trace_get_attrib_return(SMARTCARD_DEVICE* smartcard, GetAttrib_Return* ret,
|
||||
DWORD dwAttrId);
|
||||
|
||||
LONG smartcard_unpack_control_call(SMARTCARD_DEVICE* smartcard, wStream* s, Control_Call* call);
|
||||
void smartcard_trace_control_call(SMARTCARD_DEVICE* smartcard, Control_Call* call);
|
||||
@ -534,8 +580,10 @@ void smartcard_trace_transmit_call(SMARTCARD_DEVICE* smartcard, Transmit_Call* c
|
||||
LONG smartcard_pack_transmit_return(SMARTCARD_DEVICE* smartcard, wStream* s, Transmit_Return* ret);
|
||||
void smartcard_trace_transmit_return(SMARTCARD_DEVICE* smartcard, Transmit_Return* ret);
|
||||
|
||||
LONG smartcard_unpack_locate_cards_by_atr_a_call(SMARTCARD_DEVICE* smartcard, wStream* s, LocateCardsByATRA_Call* call);
|
||||
void smartcard_trace_locate_cards_by_atr_a_call(SMARTCARD_DEVICE* smartcard, LocateCardsByATRA_Call* call);
|
||||
LONG smartcard_unpack_locate_cards_by_atr_a_call(SMARTCARD_DEVICE* smartcard, wStream* s,
|
||||
LocateCardsByATRA_Call* call);
|
||||
void smartcard_trace_locate_cards_by_atr_a_call(SMARTCARD_DEVICE* smartcard,
|
||||
LocateCardsByATRA_Call* call);
|
||||
|
||||
|
||||
#endif /* FREERDP_CHANNEL_SMARTCARD_CLIENT_PACK_H */
|
||||
|
@ -312,12 +312,14 @@ PCSC_SCARDCONTEXT* PCSC_EstablishCardContext(SCARDCONTEXT hContext)
|
||||
return NULL;
|
||||
|
||||
pContext->hContext = hContext;
|
||||
|
||||
if (!InitializeCriticalSectionAndSpinCount(&(pContext->lock), 4000))
|
||||
goto error_spinlock;
|
||||
|
||||
if (!g_CardContexts)
|
||||
{
|
||||
g_CardContexts = ListDictionary_New(TRUE);
|
||||
|
||||
if (!g_CardContexts)
|
||||
goto errors;
|
||||
}
|
||||
@ -325,15 +327,17 @@ PCSC_SCARDCONTEXT* PCSC_EstablishCardContext(SCARDCONTEXT hContext)
|
||||
if (!g_Readers)
|
||||
{
|
||||
g_Readers = ArrayList_New(TRUE);
|
||||
|
||||
if (!g_Readers)
|
||||
goto errors;
|
||||
|
||||
ArrayList_Object(g_Readers)->fnObjectFree = (OBJECT_FREE_FN) PCSC_ReaderAliasFree;
|
||||
}
|
||||
|
||||
if (!ListDictionary_Add(g_CardContexts, (void*) hContext, (void*) pContext))
|
||||
goto errors;
|
||||
return pContext;
|
||||
|
||||
return pContext;
|
||||
errors:
|
||||
DeleteCriticalSection(&(pContext->lock));
|
||||
error_spinlock:
|
||||
@ -426,7 +430,6 @@ BOOL PCSC_WaitForCardAccess(SCARDCONTEXT hContext, SCARDHANDLE hCard, BOOL share
|
||||
if (!hCard)
|
||||
{
|
||||
/* SCardConnect */
|
||||
|
||||
pContext = PCSC_GetCardContextData(hContext);
|
||||
|
||||
if (!pContext)
|
||||
@ -436,7 +439,6 @@ BOOL PCSC_WaitForCardAccess(SCARDCONTEXT hContext, SCARDHANDLE hCard, BOOL share
|
||||
return TRUE;
|
||||
|
||||
/* wait for card ownership */
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -447,7 +449,6 @@ BOOL PCSC_WaitForCardAccess(SCARDCONTEXT hContext, SCARDHANDLE hCard, BOOL share
|
||||
|
||||
shared = pCard->shared;
|
||||
hContext = pCard->hSharedContext;
|
||||
|
||||
pContext = PCSC_GetCardContextData(hContext);
|
||||
|
||||
if (!pContext)
|
||||
@ -456,7 +457,6 @@ BOOL PCSC_WaitForCardAccess(SCARDCONTEXT hContext, SCARDHANDLE hCard, BOOL share
|
||||
if (!pContext->owner)
|
||||
{
|
||||
/* card is not owned */
|
||||
|
||||
if (!shared)
|
||||
pContext->owner = hCard;
|
||||
|
||||
@ -483,7 +483,6 @@ BOOL PCSC_ReleaseCardAccess(SCARDCONTEXT hContext, SCARDHANDLE hCard)
|
||||
if (!hCard)
|
||||
{
|
||||
/* release current owner */
|
||||
|
||||
pContext = PCSC_GetCardContextData(hContext);
|
||||
|
||||
if (!pContext)
|
||||
@ -500,9 +499,7 @@ BOOL PCSC_ReleaseCardAccess(SCARDCONTEXT hContext, SCARDHANDLE hCard)
|
||||
return FALSE;
|
||||
|
||||
/* release card ownership */
|
||||
|
||||
pContext->owner = 0;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -512,7 +509,6 @@ BOOL PCSC_ReleaseCardAccess(SCARDCONTEXT hContext, SCARDHANDLE hCard)
|
||||
return FALSE;
|
||||
|
||||
hContext = pCard->hSharedContext;
|
||||
|
||||
pContext = PCSC_GetCardContextData(hContext);
|
||||
|
||||
if (!pContext)
|
||||
@ -521,7 +517,6 @@ BOOL PCSC_ReleaseCardAccess(SCARDCONTEXT hContext, SCARDHANDLE hCard)
|
||||
if (pContext->owner == hCard)
|
||||
{
|
||||
/* release card ownership */
|
||||
|
||||
pContext->owner = 0;
|
||||
}
|
||||
|
||||
@ -541,6 +536,7 @@ PCSC_SCARDHANDLE* PCSC_ConnectCardHandle(SCARDCONTEXT hSharedContext, SCARDHANDL
|
||||
}
|
||||
|
||||
pCard = (PCSC_SCARDHANDLE*) calloc(1, sizeof(PCSC_SCARDHANDLE));
|
||||
|
||||
if (!pCard)
|
||||
return NULL;
|
||||
|
||||
@ -549,6 +545,7 @@ PCSC_SCARDHANDLE* PCSC_ConnectCardHandle(SCARDCONTEXT hSharedContext, SCARDHANDL
|
||||
if (!g_CardHandles)
|
||||
{
|
||||
g_CardHandles = ListDictionary_New(TRUE);
|
||||
|
||||
if (!g_CardHandles)
|
||||
goto error;
|
||||
}
|
||||
@ -558,7 +555,6 @@ PCSC_SCARDHANDLE* PCSC_ConnectCardHandle(SCARDCONTEXT hSharedContext, SCARDHANDL
|
||||
|
||||
pContext->dwCardHandleCount++;
|
||||
return pCard;
|
||||
|
||||
error:
|
||||
free(pCard);
|
||||
return NULL;
|
||||
@ -568,7 +564,6 @@ void PCSC_DisconnectCardHandle(SCARDHANDLE hCard)
|
||||
{
|
||||
PCSC_SCARDHANDLE* pCard;
|
||||
PCSC_SCARDCONTEXT* pContext;
|
||||
|
||||
pCard = PCSC_GetCardHandleData(hCard);
|
||||
|
||||
if (!pCard)
|
||||
@ -623,20 +618,24 @@ BOOL PCSC_AddReaderNameAlias(char* namePCSC, char* nameWinSCard)
|
||||
return TRUE;
|
||||
|
||||
reader = (PCSC_READER*) calloc(1, sizeof(PCSC_READER));
|
||||
|
||||
if (!reader)
|
||||
return FALSE;
|
||||
|
||||
reader->namePCSC = _strdup(namePCSC);
|
||||
|
||||
if (!reader->namePCSC)
|
||||
goto error_namePSC;
|
||||
|
||||
reader->nameWinSCard = _strdup(nameWinSCard);
|
||||
|
||||
if (!reader->nameWinSCard)
|
||||
goto error_nameWinSCard;
|
||||
|
||||
if (ArrayList_Add(g_Readers, reader) < 0)
|
||||
goto error_add;
|
||||
return TRUE;
|
||||
|
||||
return TRUE;
|
||||
error_add:
|
||||
free(reader->nameWinSCard);
|
||||
error_nameWinSCard:
|
||||
@ -674,6 +673,7 @@ char* PCSC_ConvertReaderNameToWinSCard(const char* name)
|
||||
char* tokens[64][2];
|
||||
char* nameWinSCard;
|
||||
char* checkAliasName;
|
||||
|
||||
/**
|
||||
* pcsc-lite reader name format:
|
||||
* name [interface] (serial) index slot
|
||||
@ -716,8 +716,8 @@ char* PCSC_ConvertReaderNameToWinSCard(const char* name)
|
||||
*/
|
||||
if (!name)
|
||||
return NULL;
|
||||
memset(tokens, 0, sizeof(tokens));
|
||||
|
||||
memset(tokens, 0, sizeof(tokens));
|
||||
length = strlen(name);
|
||||
|
||||
if (length < 10)
|
||||
@ -802,8 +802,8 @@ char* PCSC_ConvertReaderNameToWinSCard(const char* name)
|
||||
*/
|
||||
index = 0;
|
||||
sprintf_s(nameWinSCard, size, "%.*s %d", length, p, index);
|
||||
|
||||
checkAliasName = PCSC_GetReaderNameFromAlias(nameWinSCard);
|
||||
|
||||
while ((checkAliasName != NULL) && (strcmp(checkAliasName, name) != 0))
|
||||
{
|
||||
index++;
|
||||
@ -817,7 +817,6 @@ char* PCSC_ConvertReaderNameToWinSCard(const char* name)
|
||||
char* PCSC_GetReaderAliasFromName(char* namePCSC)
|
||||
{
|
||||
char* nameWinSCard = NULL;
|
||||
|
||||
nameWinSCard = PCSC_ConvertReaderNameToWinSCard(namePCSC);
|
||||
|
||||
if (nameWinSCard)
|
||||
@ -914,6 +913,7 @@ BOOL PCSC_AddMemoryBlock(SCARDCONTEXT hContext, void* pvMem)
|
||||
if (!g_MemoryBlocks)
|
||||
{
|
||||
g_MemoryBlocks = ListDictionary_New(TRUE);
|
||||
|
||||
if (!g_MemoryBlocks)
|
||||
return FALSE;
|
||||
}
|
||||
@ -942,6 +942,7 @@ void* PCSC_SCardAllocMemory(SCARDCONTEXT hContext, size_t size)
|
||||
free(pvMem);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pvMem;
|
||||
}
|
||||
|
||||
@ -1017,11 +1018,73 @@ WINSCARDAPI LONG WINAPI PCSC_SCardIsValidContext(SCARDCONTEXT hContext)
|
||||
return status;
|
||||
}
|
||||
|
||||
WINSCARDAPI LONG WINAPI PCSC_SCardListReaderGroups_Internal(SCARDCONTEXT hContext,
|
||||
LPSTR mszGroups, LPDWORD pcchGroups)
|
||||
{
|
||||
LONG status = SCARD_S_SUCCESS;
|
||||
char* mszGroupsWinSCard = NULL;
|
||||
BOOL pcchGroupsAlloc = FALSE;
|
||||
LPSTR* pMszGroups = (LPSTR*) mszGroups;
|
||||
PCSC_DWORD pcsc_cchGroups = 0;
|
||||
|
||||
if (!pcchGroups)
|
||||
return SCARD_E_INVALID_PARAMETER;
|
||||
|
||||
if (!g_PCSC.pfnSCardListReaderGroups)
|
||||
return SCARD_E_NO_SERVICE;
|
||||
|
||||
if (*pcchGroups == SCARD_AUTOALLOCATE)
|
||||
pcchGroupsAlloc = TRUE;
|
||||
|
||||
pcsc_cchGroups = pcchGroupsAlloc ? PCSC_SCARD_AUTOALLOCATE : (PCSC_DWORD) * pcchGroups;
|
||||
|
||||
if (pcchGroupsAlloc && !g_SCardAutoAllocate)
|
||||
{
|
||||
pcsc_cchGroups = 0;
|
||||
status = (LONG) g_PCSC.pfnSCardListReaderGroups(hContext, NULL, &pcsc_cchGroups);
|
||||
|
||||
if (status == SCARD_S_SUCCESS)
|
||||
{
|
||||
*pMszGroups = calloc(1, pcsc_cchGroups);
|
||||
|
||||
if (!*pMszGroups)
|
||||
return SCARD_E_NO_MEMORY;
|
||||
|
||||
status = (LONG) g_PCSC.pfnSCardListReaderGroups(hContext, *pMszGroups, &pcsc_cchGroups);
|
||||
|
||||
if (status != SCARD_S_SUCCESS)
|
||||
free(*pMszGroups);
|
||||
else
|
||||
PCSC_AddMemoryBlock(hContext, *pMszGroups);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status = (LONG) g_PCSC.pfnSCardListReaderGroups(hContext, mszGroups, &pcsc_cchGroups);
|
||||
}
|
||||
|
||||
status = PCSC_MapErrorCodeToWinSCard(status);
|
||||
*pcchGroups = (DWORD) pcsc_cchGroups;
|
||||
|
||||
if (status == SCARD_S_SUCCESS)
|
||||
{
|
||||
mszGroupsWinSCard = PCSC_ConvertReaderNamesToWinSCard(*pMszGroups, pcchGroups);
|
||||
|
||||
if (mszGroupsWinSCard)
|
||||
{
|
||||
PCSC_SCardFreeMemory_Internal(hContext, *pMszGroups);
|
||||
*pMszGroups = mszGroupsWinSCard;
|
||||
PCSC_AddMemoryBlock(hContext, *pMszGroups);
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
WINSCARDAPI LONG WINAPI PCSC_SCardListReaderGroupsA(SCARDCONTEXT hContext,
|
||||
LPSTR mszGroups, LPDWORD pcchGroups)
|
||||
{
|
||||
LONG status = SCARD_S_SUCCESS;
|
||||
PCSC_DWORD pcsc_cchGroups = (PCSC_DWORD) *pcchGroups;
|
||||
|
||||
if (!g_PCSC.pfnSCardListReaderGroups)
|
||||
return SCARD_E_NO_SERVICE;
|
||||
@ -1029,9 +1092,7 @@ WINSCARDAPI LONG WINAPI PCSC_SCardListReaderGroupsA(SCARDCONTEXT hContext,
|
||||
if (!PCSC_LockCardContext(hContext))
|
||||
return SCARD_E_INVALID_HANDLE;
|
||||
|
||||
status = (LONG) g_PCSC.pfnSCardListReaderGroups(hContext, mszGroups, &pcsc_cchGroups);
|
||||
status = PCSC_MapErrorCodeToWinSCard(status);
|
||||
*pcchGroups = (DWORD) pcsc_cchGroups;
|
||||
status = PCSC_SCardListReaderGroups_Internal(hContext, mszGroups, pcchGroups);
|
||||
|
||||
if (!PCSC_UnlockCardContext(hContext))
|
||||
return SCARD_E_INVALID_HANDLE;
|
||||
@ -1042,8 +1103,9 @@ WINSCARDAPI LONG WINAPI PCSC_SCardListReaderGroupsA(SCARDCONTEXT hContext,
|
||||
WINSCARDAPI LONG WINAPI PCSC_SCardListReaderGroupsW(SCARDCONTEXT hContext,
|
||||
LPWSTR mszGroups, LPDWORD pcchGroups)
|
||||
{
|
||||
LPSTR mszGroupsA = NULL;
|
||||
LPSTR* pMszGroupsA = &mszGroupsA;
|
||||
LONG status = SCARD_S_SUCCESS;
|
||||
PCSC_DWORD pcsc_cchGroups = (PCSC_DWORD) *pcchGroups;
|
||||
|
||||
if (!g_PCSC.pfnSCardListReaderGroups)
|
||||
return SCARD_E_NO_SERVICE;
|
||||
@ -1051,13 +1113,14 @@ WINSCARDAPI LONG WINAPI PCSC_SCardListReaderGroupsW(SCARDCONTEXT hContext,
|
||||
if (!PCSC_LockCardContext(hContext))
|
||||
return SCARD_E_INVALID_HANDLE;
|
||||
|
||||
mszGroups = NULL;
|
||||
pcchGroups = 0;
|
||||
/* FIXME: unicode conversion */
|
||||
status = (LONG) g_PCSC.pfnSCardListReaderGroups(hContext, (LPSTR) mszGroups, &pcsc_cchGroups);
|
||||
status = PCSC_MapErrorCodeToWinSCard(status);
|
||||
if (pcchGroups)
|
||||
*pcchGroups = (DWORD) pcsc_cchGroups;
|
||||
status = PCSC_SCardListReaderGroups_Internal(hContext, (LPSTR) &mszGroupsA, pcchGroups);
|
||||
|
||||
if (status == SCARD_S_SUCCESS)
|
||||
{
|
||||
*pcchGroups = ConvertToUnicode(CP_UTF8, 0, *pMszGroupsA, *pcchGroups, (WCHAR**) mszGroups, 0);
|
||||
PCSC_AddMemoryBlock(hContext, mszGroups);
|
||||
PCSC_SCardFreeMemory_Internal(hContext, *pMszGroupsA);
|
||||
}
|
||||
|
||||
if (!PCSC_UnlockCardContext(hContext))
|
||||
return SCARD_E_INVALID_HANDLE;
|
||||
@ -1218,13 +1281,15 @@ WINSCARDAPI LONG WINAPI PCSC_SCardListReadersW(SCARDCONTEXT hContext,
|
||||
}
|
||||
|
||||
WINSCARDAPI LONG WINAPI PCSC_SCardListCardsA(SCARDCONTEXT hContext,
|
||||
LPCBYTE pbAtr, LPCGUID rgquidInterfaces, DWORD cguidInterfaceCount, CHAR* mszCards, LPDWORD pcchCards)
|
||||
LPCBYTE pbAtr, LPCGUID rgquidInterfaces, DWORD cguidInterfaceCount, CHAR* mszCards,
|
||||
LPDWORD pcchCards)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
WINSCARDAPI LONG WINAPI PCSC_SCardListCardsW(SCARDCONTEXT hContext,
|
||||
LPCBYTE pbAtr, LPCGUID rgquidInterfaces, DWORD cguidInterfaceCount, WCHAR* mszCards, LPDWORD pcchCards)
|
||||
LPCBYTE pbAtr, LPCGUID rgquidInterfaces, DWORD cguidInterfaceCount, WCHAR* mszCards,
|
||||
LPDWORD pcchCards)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -1498,7 +1563,6 @@ WINSCARDAPI LONG WINAPI PCSC_SCardGetStatusChange_Internal(SCARDCONTEXT hContext
|
||||
|
||||
/* pcsc-lite interprets value 0 as INFINITE, work around the problem by using value 1 */
|
||||
pcsc_dwTimeout = pcsc_dwTimeout ? pcsc_dwTimeout : 1;
|
||||
|
||||
/**
|
||||
* Apple's SmartCard Services (not vanilla pcsc-lite) appears to have trouble with the
|
||||
* "\\\\?PnP?\\Notification" reader name. I am always getting EXC_BAD_ACCESS with it.
|
||||
@ -1572,7 +1636,6 @@ WINSCARDAPI LONG WINAPI PCSC_SCardGetStatusChange_Internal(SCARDCONTEXT hContext
|
||||
rgReaderStates[i].dwCurrentState = states[j].dwCurrentState;
|
||||
rgReaderStates[i].cbAtr = states[j].cbAtr;
|
||||
CopyMemory(&(rgReaderStates[i].rgbAtr), &(states[j].rgbAtr), PCSC_MAX_ATR_SIZE);
|
||||
|
||||
dwEventState = states[j].dwEventState & ~SCARD_STATE_CHANGED;
|
||||
|
||||
if (dwEventState != rgReaderStates[i].dwCurrentState)
|
||||
@ -1598,6 +1661,7 @@ WINSCARDAPI LONG WINAPI PCSC_SCardGetStatusChange_Internal(SCARDCONTEXT hContext
|
||||
|
||||
free(map);
|
||||
free(states);
|
||||
|
||||
if ((status == SCARD_S_SUCCESS) && !stateChanged)
|
||||
status = SCARD_E_TIMEOUT;
|
||||
else if ((status == SCARD_E_TIMEOUT) && stateChanged)
|
||||
@ -1704,9 +1768,7 @@ WINSCARDAPI LONG WINAPI PCSC_SCardConnect_Internal(SCARDCONTEXT hContext,
|
||||
return SCARD_E_NO_SERVICE;
|
||||
|
||||
shared = (dwShareMode == SCARD_SHARE_DIRECT) ? TRUE : FALSE;
|
||||
|
||||
access = PCSC_WaitForCardAccess(hContext, 0, shared);
|
||||
|
||||
szReaderPCSC = PCSC_GetReaderNameFromAlias((char*) szReader);
|
||||
|
||||
if (!szReaderPCSC)
|
||||
@ -1724,14 +1786,12 @@ WINSCARDAPI LONG WINAPI PCSC_SCardConnect_Internal(SCARDCONTEXT hContext,
|
||||
|
||||
status = (LONG) g_PCSC.pfnSCardConnect(hContext, szReaderPCSC,
|
||||
pcsc_dwShareMode, pcsc_dwPreferredProtocols, phCard, &pcsc_dwActiveProtocol);
|
||||
|
||||
status = PCSC_MapErrorCodeToWinSCard(status);
|
||||
|
||||
if (status == SCARD_S_SUCCESS)
|
||||
{
|
||||
pCard = PCSC_ConnectCardHandle(hContext, *phCard);
|
||||
*pdwActiveProtocol = PCSC_ConvertProtocolsToWinSCard((DWORD) pcsc_dwActiveProtocol);
|
||||
|
||||
pCard->shared = shared;
|
||||
PCSC_WaitForCardAccess(hContext, pCard->hSharedContext, shared);
|
||||
}
|
||||
@ -1795,15 +1855,12 @@ WINSCARDAPI LONG WINAPI PCSC_SCardReconnect(SCARDHANDLE hCard,
|
||||
return SCARD_E_NO_SERVICE;
|
||||
|
||||
shared = (dwShareMode == SCARD_SHARE_DIRECT) ? TRUE : FALSE;
|
||||
|
||||
access = 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);
|
||||
*pdwActiveProtocol = PCSC_ConvertProtocolsToWinSCard((DWORD) pcsc_dwActiveProtocol);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -1824,7 +1881,6 @@ WINSCARDAPI LONG WINAPI PCSC_SCardDisconnect(SCARDHANDLE hCard, DWORD dwDisposit
|
||||
}
|
||||
|
||||
PCSC_ReleaseCardAccess(0, hCard);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -1852,7 +1908,6 @@ WINSCARDAPI LONG WINAPI PCSC_SCardBeginTransaction(SCARDHANDLE hCard)
|
||||
|
||||
status = (LONG) g_PCSC.pfnSCardBeginTransaction(hCard);
|
||||
status = PCSC_MapErrorCodeToWinSCard(status);
|
||||
|
||||
pContext->isTransactionLocked = TRUE;
|
||||
return status;
|
||||
}
|
||||
@ -1884,9 +1939,7 @@ WINSCARDAPI LONG WINAPI PCSC_SCardEndTransaction(SCARDHANDLE hCard, DWORD dwDisp
|
||||
|
||||
status = (LONG) g_PCSC.pfnSCardEndTransaction(hCard, pcsc_dwDisposition);
|
||||
status = PCSC_MapErrorCodeToWinSCard(status);
|
||||
|
||||
pContext->isTransactionLocked = FALSE;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -1916,7 +1969,6 @@ WINSCARDAPI LONG WINAPI PCSC_SCardState(SCARDHANDLE hCard,
|
||||
return SCARD_E_INVALID_VALUE;
|
||||
|
||||
PCSC_WaitForCardAccess(0, hCard, pCard->shared);
|
||||
|
||||
hContext = PCSC_GetCardContextFromHandle(hCard);
|
||||
|
||||
if (!hContext)
|
||||
@ -1933,7 +1985,6 @@ WINSCARDAPI LONG WINAPI PCSC_SCardState(SCARDHANDLE hCard,
|
||||
*pdwState = (DWORD) pcsc_dwState;
|
||||
*pdwProtocol = PCSC_ConvertProtocolsToWinSCard((DWORD) pcsc_dwProtocol);
|
||||
*pcbAtrLen = (DWORD) pcsc_cbAtrLen;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -1963,7 +2014,6 @@ WINSCARDAPI LONG WINAPI PCSC_SCardStatus_Internal(SCARDHANDLE hCard,
|
||||
return SCARD_E_INVALID_VALUE;
|
||||
|
||||
PCSC_WaitForCardAccess(0, hCard, pCard->shared);
|
||||
|
||||
hContext = PCSC_GetCardContextFromHandle(hCard);
|
||||
|
||||
if (!hContext || !pcchReaderLen || !pdwState || !pdwProtocol || !pcbAtrLen)
|
||||
@ -1997,11 +2047,13 @@ WINSCARDAPI LONG WINAPI PCSC_SCardStatus_Internal(SCARDHANDLE hCard,
|
||||
if (pcchReaderLenAlloc)
|
||||
{
|
||||
#ifdef __MACOSX__
|
||||
|
||||
/**
|
||||
* Workaround for SCardStatus Bug in MAC OS X Yosemite
|
||||
*/
|
||||
if (OSXVersion == 0x10100000)
|
||||
pcsc_cchReaderLen++;
|
||||
|
||||
#endif
|
||||
*pMszReaderNames = (LPSTR) calloc(1, pcsc_cchReaderLen);
|
||||
|
||||
@ -2075,7 +2127,8 @@ WINSCARDAPI LONG WINAPI PCSC_SCardStatusA(SCARDHANDLE hCard,
|
||||
LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen)
|
||||
{
|
||||
LONG status = SCARD_S_SUCCESS;
|
||||
status = PCSC_SCardStatus_Internal(hCard, mszReaderNames, pcchReaderLen, pdwState, pdwProtocol, pbAtr, pcbAtrLen);
|
||||
status = PCSC_SCardStatus_Internal(hCard, mszReaderNames, pcchReaderLen, pdwState, pdwProtocol,
|
||||
pbAtr, pcbAtrLen);
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -2095,11 +2148,13 @@ WINSCARDAPI LONG WINAPI PCSC_SCardStatusW(SCARDHANDLE hCard,
|
||||
if (!hContext)
|
||||
return SCARD_E_INVALID_VALUE;
|
||||
|
||||
status = PCSC_SCardStatus_Internal(hCard, (LPSTR) &mszReaderNamesA, pcchReaderLen, pdwState, pdwProtocol, pbAtr, pcbAtrLen);
|
||||
status = PCSC_SCardStatus_Internal(hCard, (LPSTR) &mszReaderNamesA, pcchReaderLen, pdwState,
|
||||
pdwProtocol, pbAtr, pcbAtrLen);
|
||||
|
||||
if (mszReaderNamesA)
|
||||
{
|
||||
*pcchReaderLen = ConvertToUnicode(CP_UTF8, 0, mszReaderNamesA, *pcchReaderLen, (WCHAR**) mszReaderNames, 0);
|
||||
*pcchReaderLen = ConvertToUnicode(CP_UTF8, 0, mszReaderNamesA, *pcchReaderLen,
|
||||
(WCHAR**) mszReaderNames, 0);
|
||||
PCSC_AddMemoryBlock(hContext, mszReaderNames);
|
||||
PCSC_SCardFreeMemory_Internal(hContext, mszReaderNamesA);
|
||||
}
|
||||
@ -2149,7 +2204,8 @@ WINSCARDAPI LONG WINAPI PCSC_SCardTransmit(SCARDHANDLE hCard,
|
||||
* 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 = (LONG) g_PCSC.pfnSCardStatus(hCard, NULL, &cchReaderLen, &dwState, &dwProtocol, NULL,
|
||||
&cbAtrLen);
|
||||
|
||||
if (status == SCARD_S_SUCCESS)
|
||||
{
|
||||
@ -2185,6 +2241,7 @@ WINSCARDAPI LONG WINAPI PCSC_SCardTransmit(SCARDHANDLE hCard,
|
||||
{
|
||||
if (pioSendPci)
|
||||
free(pcsc_pioSendPci);
|
||||
|
||||
return SCARD_E_NO_MEMORY;
|
||||
}
|
||||
|
||||
@ -2218,14 +2275,12 @@ WINSCARDAPI LONG WINAPI PCSC_SCardTransmit(SCARDHANDLE hCard,
|
||||
WINSCARDAPI LONG WINAPI PCSC_SCardGetTransmitCount(SCARDHANDLE hCard, LPDWORD pcTransmitCount)
|
||||
{
|
||||
PCSC_SCARDHANDLE* pCard = NULL;
|
||||
|
||||
pCard = PCSC_GetCardHandleData(hCard);
|
||||
|
||||
if (!pCard)
|
||||
return SCARD_E_INVALID_VALUE;
|
||||
|
||||
PCSC_WaitForCardAccess(0, hCard, pCard->shared);
|
||||
|
||||
return SCARD_S_SUCCESS;
|
||||
}
|
||||
|
||||
@ -2254,7 +2309,6 @@ WINSCARDAPI LONG WINAPI PCSC_SCardControl(SCARDHANDLE hCard,
|
||||
return SCARD_E_INVALID_VALUE;
|
||||
|
||||
PCSC_WaitForCardAccess(0, hCard, pCard->shared);
|
||||
|
||||
/**
|
||||
* PCSCv2 Part 10:
|
||||
* http://www.pcscworkgroup.com/specifications/files/pcsc10_v2.02.09.pdf
|
||||
@ -2265,7 +2319,6 @@ WINSCARDAPI LONG WINAPI PCSC_SCardControl(SCARDHANDLE hCard,
|
||||
* Converting Windows Feature Request IOCTL code to the pcsc-lite control code:
|
||||
* http://musclecard.996296.n3.nabble.com/Converting-Windows-Feature-Request-IOCTL-code-to-the-pcsc-lite-control-code-td4906.html
|
||||
*/
|
||||
|
||||
IoCtlMethod = METHOD_FROM_CTL_CODE(dwControlCode);
|
||||
IoCtlFunction = FUNCTION_FROM_CTL_CODE(dwControlCode);
|
||||
IoCtlAccess = ACCESS_FROM_CTL_CODE(dwControlCode);
|
||||
@ -2278,11 +2331,9 @@ WINSCARDAPI LONG WINAPI PCSC_SCardControl(SCARDHANDLE hCard,
|
||||
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);
|
||||
*lpBytesReturned = (DWORD) pcsc_BytesReturned;
|
||||
|
||||
@ -2307,7 +2358,8 @@ WINSCARDAPI LONG WINAPI PCSC_SCardControl(SCARDHANDLE hCard,
|
||||
return status;
|
||||
}
|
||||
|
||||
WINSCARDAPI LONG WINAPI PCSC_SCardGetAttrib_Internal(SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE pbAttr, LPDWORD pcbAttrLen)
|
||||
WINSCARDAPI LONG WINAPI PCSC_SCardGetAttrib_Internal(SCARDHANDLE hCard, DWORD dwAttrId,
|
||||
LPBYTE pbAttr, LPDWORD pcbAttrLen)
|
||||
{
|
||||
SCARDCONTEXT hContext = 0;
|
||||
BOOL pcbAttrLenAlloc = FALSE;
|
||||
@ -2326,7 +2378,6 @@ WINSCARDAPI LONG WINAPI PCSC_SCardGetAttrib_Internal(SCARDHANDLE hCard, DWORD dw
|
||||
return SCARD_E_INVALID_VALUE;
|
||||
|
||||
PCSC_WaitForCardAccess(0, hCard, pCard->shared);
|
||||
|
||||
hContext = PCSC_GetCardContextFromHandle(hCard);
|
||||
|
||||
if (!hContext)
|
||||
@ -2373,7 +2424,8 @@ WINSCARDAPI LONG WINAPI PCSC_SCardGetAttrib_Internal(SCARDHANDLE hCard, DWORD dw
|
||||
return status;
|
||||
}
|
||||
|
||||
WINSCARDAPI LONG WINAPI PCSC_SCardGetAttrib_FriendlyName(SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE pbAttr, LPDWORD pcbAttrLen)
|
||||
WINSCARDAPI LONG WINAPI PCSC_SCardGetAttrib_FriendlyName(SCARDHANDLE hCard, DWORD dwAttrId,
|
||||
LPBYTE pbAttr, LPDWORD pcbAttrLen)
|
||||
{
|
||||
int length = 0;
|
||||
char* namePCSC = NULL;
|
||||
@ -2393,18 +2445,21 @@ WINSCARDAPI LONG WINAPI PCSC_SCardGetAttrib_FriendlyName(SCARDHANDLE hCard, DWOR
|
||||
|
||||
cbAttrLen = *pcbAttrLen;
|
||||
*pcbAttrLen = SCARD_AUTOALLOCATE;
|
||||
status = PCSC_SCardGetAttrib_Internal(hCard, SCARD_ATTR_DEVICE_FRIENDLY_NAME_A, (LPBYTE) &pbAttrA, pcbAttrLen);
|
||||
status = PCSC_SCardGetAttrib_Internal(hCard, SCARD_ATTR_DEVICE_FRIENDLY_NAME_A, (LPBYTE) &pbAttrA,
|
||||
pcbAttrLen);
|
||||
|
||||
if (status != SCARD_S_SUCCESS)
|
||||
{
|
||||
pbAttrA = NULL;
|
||||
*pcbAttrLen = SCARD_AUTOALLOCATE;
|
||||
status = PCSC_SCardGetAttrib_Internal(hCard, SCARD_ATTR_DEVICE_FRIENDLY_NAME_W, (LPBYTE) &pbAttrW, pcbAttrLen);
|
||||
status = PCSC_SCardGetAttrib_Internal(hCard, SCARD_ATTR_DEVICE_FRIENDLY_NAME_W, (LPBYTE) &pbAttrW,
|
||||
pcbAttrLen);
|
||||
|
||||
if (status != SCARD_S_SUCCESS)
|
||||
return status;
|
||||
|
||||
length = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) pbAttrW, *pcbAttrLen, (char**) &pbAttrA, 0, NULL, NULL);
|
||||
length = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) pbAttrW, *pcbAttrLen, (char**) &pbAttrA, 0, NULL,
|
||||
NULL);
|
||||
namePCSC = pbAttrA;
|
||||
PCSC_SCardFreeMemory_Internal(hContext, pbAttrW);
|
||||
}
|
||||
@ -2499,18 +2554,17 @@ WINSCARDAPI LONG WINAPI PCSC_SCardGetAttrib_FriendlyName(SCARDHANDLE hCard, DWOR
|
||||
|
||||
free(namePCSC);
|
||||
free(nameWinSCard);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
WINSCARDAPI LONG WINAPI PCSC_SCardGetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE pbAttr, LPDWORD pcbAttrLen)
|
||||
WINSCARDAPI LONG WINAPI PCSC_SCardGetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE pbAttr,
|
||||
LPDWORD pcbAttrLen)
|
||||
{
|
||||
DWORD cbAttrLen;
|
||||
SCARDCONTEXT hContext;
|
||||
BOOL pcbAttrLenAlloc = FALSE;
|
||||
LONG status = SCARD_S_SUCCESS;
|
||||
LPBYTE* pPbAttr = (LPBYTE*) pbAttr;
|
||||
|
||||
cbAttrLen = *pcbAttrLen;
|
||||
|
||||
if (*pcbAttrLen == SCARD_AUTOALLOCATE)
|
||||
@ -2524,7 +2578,6 @@ WINSCARDAPI LONG WINAPI PCSC_SCardGetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, L
|
||||
* pcsc-lite returns SCARD_E_INSUFFICIENT_BUFFER if the given
|
||||
* buffer size is larger than PCSC_MAX_BUFFER_SIZE (264)
|
||||
*/
|
||||
|
||||
if (*pcbAttrLen > PCSC_MAX_BUFFER_SIZE)
|
||||
*pcbAttrLen = PCSC_MAX_BUFFER_SIZE;
|
||||
}
|
||||
@ -2534,7 +2587,8 @@ WINSCARDAPI LONG WINAPI PCSC_SCardGetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, L
|
||||
if (!hContext)
|
||||
return SCARD_E_INVALID_HANDLE;
|
||||
|
||||
if ((dwAttrId == SCARD_ATTR_DEVICE_FRIENDLY_NAME_A) || (dwAttrId == SCARD_ATTR_DEVICE_FRIENDLY_NAME_W))
|
||||
if ((dwAttrId == SCARD_ATTR_DEVICE_FRIENDLY_NAME_A) ||
|
||||
(dwAttrId == SCARD_ATTR_DEVICE_FRIENDLY_NAME_W))
|
||||
{
|
||||
status = PCSC_SCardGetAttrib_FriendlyName(hCard, dwAttrId, pbAttr, pcbAttrLen);
|
||||
return status;
|
||||
@ -2574,8 +2628,8 @@ WINSCARDAPI LONG WINAPI PCSC_SCardGetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, L
|
||||
PCSC_DWORD cbAtrLen = 0;
|
||||
PCSC_DWORD dwProtocol = 0;
|
||||
PCSC_DWORD cchReaderLen = 0;
|
||||
|
||||
status = (LONG) g_PCSC.pfnSCardStatus(hCard, NULL, &cchReaderLen, &dwState, &dwProtocol, NULL, &cbAtrLen);
|
||||
status = (LONG) g_PCSC.pfnSCardStatus(hCard, NULL, &cchReaderLen, &dwState, &dwProtocol, NULL,
|
||||
&cbAtrLen);
|
||||
|
||||
if (status == SCARD_S_SUCCESS)
|
||||
{
|
||||
@ -2600,7 +2654,6 @@ WINSCARDAPI LONG WINAPI PCSC_SCardGetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, L
|
||||
return SCARD_E_INSUFFICIENT_BUFFER;
|
||||
|
||||
status = SCARD_S_SUCCESS;
|
||||
|
||||
*((DWORD*) pbAttr) = (channelType << 16) | channelNumber;
|
||||
*pcbAttrLen = sizeof(DWORD);
|
||||
}
|
||||
@ -2670,7 +2723,8 @@ WINSCARDAPI LONG WINAPI PCSC_SCardGetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, L
|
||||
return status;
|
||||
}
|
||||
|
||||
WINSCARDAPI LONG WINAPI PCSC_SCardSetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, LPCBYTE pbAttr, DWORD cbAttrLen)
|
||||
WINSCARDAPI LONG WINAPI PCSC_SCardSetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, LPCBYTE pbAttr,
|
||||
DWORD cbAttrLen)
|
||||
{
|
||||
LONG status = SCARD_S_SUCCESS;
|
||||
PCSC_SCARDHANDLE* pCard = NULL;
|
||||
@ -2686,10 +2740,8 @@ WINSCARDAPI LONG WINAPI PCSC_SCardSetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, L
|
||||
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;
|
||||
}
|
||||
|
||||
@ -2754,12 +2806,14 @@ WINSCARDAPI LONG WINAPI PCSC_SCardGetReaderIconW(SCARDCONTEXT hContext,
|
||||
return 0;
|
||||
}
|
||||
|
||||
WINSCARDAPI LONG WINAPI PCSC_SCardGetDeviceTypeIdA(SCARDCONTEXT hContext, LPCSTR szReaderName, LPDWORD pdwDeviceTypeId)
|
||||
WINSCARDAPI LONG WINAPI PCSC_SCardGetDeviceTypeIdA(SCARDCONTEXT hContext, LPCSTR szReaderName,
|
||||
LPDWORD pdwDeviceTypeId)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
WINSCARDAPI LONG WINAPI PCSC_SCardGetDeviceTypeIdW(SCARDCONTEXT hContext, LPCWSTR szReaderName, LPDWORD pdwDeviceTypeId)
|
||||
WINSCARDAPI LONG WINAPI PCSC_SCardGetDeviceTypeIdW(SCARDCONTEXT hContext, LPCWSTR szReaderName,
|
||||
LPDWORD pdwDeviceTypeId)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -2805,14 +2859,17 @@ unsigned int determineMacOSXVersion()
|
||||
int minorVersion = 0;
|
||||
int patchVersion = 0;
|
||||
int count = 0;
|
||||
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_OSRELEASE;
|
||||
|
||||
if (sysctl(mib, 2, NULL, &len, NULL, 0) != 0)
|
||||
return 0;
|
||||
|
||||
kernelVersion = calloc(len, sizeof(char));
|
||||
|
||||
if (!kernelVersion)
|
||||
return 0;
|
||||
|
||||
if (sysctl(mib, 2, kernelVersion, &len, NULL, 0) != 0)
|
||||
{
|
||||
free(kernelVersion);
|
||||
@ -2820,6 +2877,7 @@ unsigned int determineMacOSXVersion()
|
||||
}
|
||||
|
||||
tok = strtok(kernelVersion, ".");
|
||||
|
||||
while (tok)
|
||||
{
|
||||
switch (count)
|
||||
@ -2827,13 +2885,16 @@ unsigned int determineMacOSXVersion()
|
||||
case 0:
|
||||
majorVersion = atoi(tok);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
minorVersion = atoi(tok);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
patchVersion = atoi(tok);
|
||||
break;
|
||||
}
|
||||
|
||||
tok = strtok(NULL, ".");
|
||||
count++;
|
||||
}
|
||||
@ -2855,34 +2916,44 @@ unsigned int determineMacOSXVersion()
|
||||
case 5:
|
||||
version = 0x10010000;
|
||||
break;
|
||||
|
||||
case 6:
|
||||
version = 0x10020000;
|
||||
break;
|
||||
|
||||
case 7:
|
||||
version = 0x10030000;
|
||||
break;
|
||||
|
||||
case 8:
|
||||
version = 0x10040000;
|
||||
break;
|
||||
|
||||
case 9:
|
||||
version = 0x10050000;
|
||||
break;
|
||||
|
||||
case 10:
|
||||
version = 0x10060000;
|
||||
break;
|
||||
|
||||
case 11:
|
||||
version = 0x10070000;
|
||||
break;
|
||||
|
||||
case 12:
|
||||
version = 0x10080000;
|
||||
break;
|
||||
|
||||
case 13:
|
||||
version = 0x10090000;
|
||||
break;
|
||||
|
||||
default:
|
||||
version = 0x10100000;
|
||||
break;
|
||||
}
|
||||
|
||||
version |= (minorVersion << 8) | (patchVersion);
|
||||
}
|
||||
|
||||
@ -2983,17 +3054,19 @@ int PCSC_InitializeSCardApi(void)
|
||||
{
|
||||
/* Disable pcsc-lite's (poor) blocking so we can handle it ourselves */
|
||||
SetEnvironmentVariableA("PCSCLITE_NO_BLOCKING", "1");
|
||||
|
||||
#ifdef __MACOSX__
|
||||
g_PCSCModule = LoadLibraryA("/System/Library/Frameworks/PCSC.framework/PCSC");
|
||||
OSXVersion = determineMacOSXVersion();
|
||||
|
||||
if (OSXVersion == 0)
|
||||
return -1;
|
||||
|
||||
#else
|
||||
g_PCSCModule = LoadLibraryA("libpcsclite.so.1");
|
||||
|
||||
if (!g_PCSCModule)
|
||||
g_PCSCModule = LoadLibraryA("libpcsclite.so");
|
||||
|
||||
#endif
|
||||
|
||||
if (!g_PCSCModule)
|
||||
@ -3009,23 +3082,22 @@ int PCSC_InitializeSCardApi(void)
|
||||
g_PCSC.pfnSCardEndTransaction = (void*) GetProcAddress(g_PCSCModule, "SCardEndTransaction");
|
||||
g_PCSC.pfnSCardStatus = (void*) GetProcAddress(g_PCSCModule, "SCardStatus");
|
||||
g_PCSC.pfnSCardGetStatusChange = (void*) GetProcAddress(g_PCSCModule, "SCardGetStatusChange");
|
||||
|
||||
#ifdef __MACOSX__
|
||||
|
||||
if (OSXVersion >= 0x10050600)
|
||||
g_PCSC.pfnSCardControl = (void*) GetProcAddress(g_PCSCModule, "SCardControl132");
|
||||
else
|
||||
g_PCSC.pfnSCardControl = (void*) GetProcAddress(g_PCSCModule, "SCardControl");
|
||||
|
||||
#else
|
||||
g_PCSC.pfnSCardControl = (void*) GetProcAddress(g_PCSCModule, "SCardControl");
|
||||
#endif
|
||||
|
||||
g_PCSC.pfnSCardTransmit = (void*) GetProcAddress(g_PCSCModule, "SCardTransmit");
|
||||
g_PCSC.pfnSCardListReaderGroups = (void*) GetProcAddress(g_PCSCModule, "SCardListReaderGroups");
|
||||
g_PCSC.pfnSCardListReaders = (void*) GetProcAddress(g_PCSCModule, "SCardListReaders");
|
||||
g_PCSC.pfnSCardCancel = (void*) GetProcAddress(g_PCSCModule, "SCardCancel");
|
||||
g_PCSC.pfnSCardGetAttrib = (void*) GetProcAddress(g_PCSCModule, "SCardGetAttrib");
|
||||
g_PCSC.pfnSCardSetAttrib = (void*) GetProcAddress(g_PCSCModule, "SCardSetAttrib");
|
||||
|
||||
g_PCSC.pfnSCardFreeMemory = NULL;
|
||||
#ifndef __APPLE__
|
||||
g_PCSC.pfnSCardFreeMemory = (void*) GetProcAddress(g_PCSCModule, "SCardFreeMemory");
|
||||
@ -3038,11 +3110,9 @@ int PCSC_InitializeSCardApi(void)
|
||||
g_PCSC.pfnSCardFreeMemory = NULL;
|
||||
g_SCardAutoAllocate = FALSE;
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
g_PnP_Notification = FALSE;
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user