channels/smartcard: cleanup SCardControl

This commit is contained in:
Marc-André Moreau 2014-12-22 16:25:59 -05:00
parent 0625be2720
commit 9ebc67ba02
5 changed files with 98 additions and 77 deletions

View File

@ -508,8 +508,6 @@ int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
smartcard->log = WLog_Get("com.freerdp.channel.smartcard.client");
//WLog_SetLogLevel(smartcard->log, WLOG_DEBUG);
smartcard->IrpQueue = MessageQueue_New(NULL);
smartcard->rgSCardContextList = ListDictionary_New(TRUE);
smartcard->rgOutstandingMessages = ListDictionary_New(TRUE);

View File

@ -551,6 +551,7 @@ static UINT32 smartcard_ConnectA_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPE
status = ret.ReturnCode = SCardConnectA(operation->hContext, (char*) call->szReader, call->Common.dwShareMode,
call->Common.dwPreferredProtocols, &hCard, &ret.dwActiveProtocol);
smartcard_scard_context_native_to_redir(smartcard, &(ret.hContext), operation->hContext);
smartcard_scard_handle_native_to_redir(smartcard, &(ret.hCard), hCard);
smartcard_trace_connect_return(smartcard, &ret);
@ -580,6 +581,7 @@ static UINT32 smartcard_ConnectW_Decode(SMARTCARD_DEVICE* smartcard, SMARTCARD_O
status = smartcard_unpack_connect_w_call(smartcard, irp->input, call);
smartcard_trace_connect_w_call(smartcard, call);
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->Common.hContext));
return status;
}
@ -598,6 +600,7 @@ static UINT32 smartcard_ConnectW_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPE
status = ret.ReturnCode = SCardConnectW(operation->hContext, (WCHAR*) call->szReader, call->Common.dwShareMode,
call->Common.dwPreferredProtocols, &hCard, &ret.dwActiveProtocol);
smartcard_scard_context_native_to_redir(smartcard, &(ret.hContext), operation->hContext);
smartcard_scard_handle_native_to_redir(smartcard, &(ret.hCard), hCard);
smartcard_trace_connect_return(smartcard, &ret);

View File

@ -135,6 +135,8 @@
#define IOCTL_SMARTCARD_GET_LAST_ERROR SCARD_CTL_CODE(15)
#define IOCTL_SMARTCARD_GET_PERF_CNTR SCARD_CTL_CODE(16)
#define IOCTL_SMARTCARD_GET_FEATURE_REQUEST SCARD_CTL_CODE(3400)
#define MAXIMUM_ATTR_STRING_LENGTH 32
#define MAXIMUM_SMARTCARD_READERS 10

View File

@ -180,9 +180,8 @@ static wListDictionary* g_MemoryBlocks = NULL;
char SMARTCARD_PNP_NOTIFICATION_A[] = "\\\\?PnP?\\Notification";
WCHAR SMARTCARD_PNP_NOTIFICATION_W[] = { '\\','\\','?','P','n','P','?',
'\\','N','o','t','i','f','i','c','a','t','i','o','n','\0'
};
WCHAR SMARTCARD_PNP_NOTIFICATION_W[] =
{ '\\','\\','?','P','n','P','?','\\','N','o','t','i','f','i','c','a','t','i','o','n','\0' };
const PCSC_SCARD_IO_REQUEST g_PCSC_rgSCardT0Pci = { SCARD_PROTOCOL_T0, sizeof(PCSC_SCARD_IO_REQUEST) };
const PCSC_SCARD_IO_REQUEST g_PCSC_rgSCardT1Pci = { SCARD_PROTOCOL_T1, sizeof(PCSC_SCARD_IO_REQUEST) };
@ -745,7 +744,8 @@ char* PCSC_ConvertReaderNameToWinSCard(const char* name)
char* PCSC_GetReaderAliasFromName(char* namePCSC)
{
char* nameWinSCard;
char* nameWinSCard = NULL;
nameWinSCard = PCSC_ConvertReaderNameToWinSCard(namePCSC);
if (nameWinSCard)
@ -1636,8 +1636,10 @@ WINSCARDAPI LONG WINAPI PCSC_SCardConnect_Internal(SCARDCONTEXT hContext,
pcsc_dwPreferredProtocols = SCARD_PROTOCOL_UNDEFINED;
else
pcsc_dwPreferredProtocols = (PCSC_DWORD) PCSC_ConvertProtocolsFromWinSCard(dwPreferredProtocols);
status = (LONG) g_PCSC.pfnSCardConnect(hPrivateContext, szReaderPCSC,
pcsc_dwShareMode, pcsc_dwPreferredProtocols, phCard, &pcsc_dwActiveProtocol);
status = PCSC_MapErrorCodeToWinSCard(status);
if (status == SCARD_S_SUCCESS)
@ -2115,36 +2117,52 @@ WINSCARDAPI LONG WINAPI PCSC_SCardControl(SCARDHANDLE hCard,
if (!g_PCSC.pfnSCardControl)
return SCARD_E_NO_SERVICE;
/**
* PCSCv2 Part 10:
* http://www.pcscworkgroup.com/specifications/files/pcsc10_v2.02.09.pdf
*
* Smart Card Driver IOCTLs:
* http://msdn.microsoft.com/en-us/library/windows/hardware/ff548988/
*
* 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);
IoCtlDeviceType = DEVICE_TYPE_FROM_CTL_CODE(dwControlCode);
if (dwControlCode == PCSC_CM_IOCTL_GET_FEATURE_REQUEST)
if (dwControlCode == IOCTL_SMARTCARD_GET_FEATURE_REQUEST)
getFeatureRequest = TRUE;
if (IoCtlDeviceType == FILE_DEVICE_SMARTCARD)
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;
if (getFeatureRequest)
{
UINT32 ioCtlValue;
UINT32 index;
UINT32 count;
PCSC_TLV_STRUCTURE* tlv = (PCSC_TLV_STRUCTURE*) lpOutBuffer;
void* lpOutBufferEnd = (void*) &((BYTE*) lpOutBuffer)[*lpBytesReturned];
for (; ((void*) tlv) < lpOutBufferEnd; tlv++)
if ((*lpBytesReturned % sizeof(PCSC_TLV_STRUCTURE)) != 0)
return SCARD_E_UNEXPECTED;
count = *lpBytesReturned / sizeof(PCSC_TLV_STRUCTURE);
for (index = 0; index < count; index++)
{
ioCtlValue = _byteswap_ulong(tlv->value);
ioCtlValue -= 0x42000000; /* inverse of PCSC_SCARD_CTL_CODE() */
ioCtlValue = SCARD_CTL_CODE(ioCtlValue);
tlv->value = _byteswap_ulong(ioCtlValue);
if (tlv[index].length != 4)
return SCARD_E_UNEXPECTED;
}
}

View File

@ -76,7 +76,7 @@ typedef long PCSC_LONG;
#define PCSC_SCARD_PCI_RAW (&g_PCSC_rgSCardRawPci)
#define PCSC_SCARD_CTL_CODE(code) (0x42000000 + (code))
#define PCSC_CM_IOCTL_GET_FEATURE_REQUEST SCARD_CTL_CODE(3400)
#define PCSC_CM_IOCTL_GET_FEATURE_REQUEST PCSC_SCARD_CTL_CODE(3400)
/**
* pcsc-lite defines SCARD_READERSTATE, SCARD_IO_REQUEST as packed