2012-08-15 01:09:01 +04:00
|
|
|
/**
|
2012-10-09 05:00:07 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2012-08-15 01:09:01 +04:00
|
|
|
* Smartcard Device Service Virtual Channel
|
|
|
|
*
|
|
|
|
* Copyright (C) Alexi Volkov <alexi@myrealbox.com> 2006
|
|
|
|
* Copyright 2011 O.S. Systems Software Ltda.
|
|
|
|
* Copyright 2011 Anthony Tong <atong@trustedcs.com>
|
2015-07-03 14:09:03 +03:00
|
|
|
* Copyright 2015 Thincast Technologies GmbH
|
|
|
|
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
2017-02-20 20:31:58 +03:00
|
|
|
* Copyright 2017 Armin Novak <armin.novak@thincast.com>
|
|
|
|
* Copyright 2017 Thincast Technologies GmbH
|
2012-08-15 01:09:01 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2011-10-15 19:30:10 +04:00
|
|
|
#include "config.h"
|
2012-08-15 01:09:01 +04:00
|
|
|
#endif
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2014-02-11 07:12:13 +04:00
|
|
|
#include <assert.h>
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2012-11-20 08:49:08 +04:00
|
|
|
#include <winpr/crt.h>
|
2012-12-14 08:54:54 +04:00
|
|
|
#include <winpr/print.h>
|
2013-03-22 00:45:25 +04:00
|
|
|
#include <winpr/stream.h>
|
2014-04-03 23:27:55 +04:00
|
|
|
#include <winpr/smartcard.h>
|
2013-03-22 01:58:18 +04:00
|
|
|
|
|
|
|
#include <freerdp/freerdp.h>
|
2012-10-09 05:00:07 +04:00
|
|
|
#include <freerdp/channels/rdpdr.h>
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2012-11-21 20:56:40 +04:00
|
|
|
#include "smartcard_main.h"
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static LONG log_status_error(const char* tag, const char* what, LONG status)
|
|
|
|
{
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
WLog_ERR(tag, "%s failed with error %s [%" PRId32 "]", what, SCardGetErrorString(status),
|
|
|
|
status);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2019-11-20 13:30:14 +03:00
|
|
|
static const char* smartcard_get_ioctl_string(UINT32 ioControlCode, BOOL funcName)
|
2014-04-04 08:56:24 +04:00
|
|
|
{
|
|
|
|
switch (ioControlCode)
|
|
|
|
{
|
|
|
|
case SCARD_IOCTL_ESTABLISHCONTEXT:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardEstablishContext" : "SCARD_IOCTL_ESTABLISHCONTEXT";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_RELEASECONTEXT:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardReleaseContext" : "SCARD_IOCTL_RELEASECONTEXT";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_ISVALIDCONTEXT:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardIsValidContext" : "SCARD_IOCTL_ISVALIDCONTEXT";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_LISTREADERGROUPSA:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardListReaderGroupsA" : "SCARD_IOCTL_LISTREADERGROUPSA";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_LISTREADERGROUPSW:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardListReaderGroupsW" : "SCARD_IOCTL_LISTREADERGROUPSW";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_LISTREADERSA:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardListReadersA" : "SCARD_IOCTL_LISTREADERSA";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_LISTREADERSW:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardListReadersW" : "SCARD_IOCTL_LISTREADERSW";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_INTRODUCEREADERGROUPA:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardIntroduceReaderGroupA" : "SCARD_IOCTL_INTRODUCEREADERGROUPA";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_INTRODUCEREADERGROUPW:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardIntroduceReaderGroupW" : "SCARD_IOCTL_INTRODUCEREADERGROUPW";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_FORGETREADERGROUPA:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardForgetReaderGroupA" : "SCARD_IOCTL_FORGETREADERGROUPA";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_FORGETREADERGROUPW:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardForgetReaderGroupW" : "SCARD_IOCTL_FORGETREADERGROUPW";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_INTRODUCEREADERA:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardIntroduceReaderA" : "SCARD_IOCTL_INTRODUCEREADERA";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_INTRODUCEREADERW:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardIntroduceReaderW" : "SCARD_IOCTL_INTRODUCEREADERW";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_FORGETREADERA:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardForgetReaderA" : "SCARD_IOCTL_FORGETREADERA";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_FORGETREADERW:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardForgetReaderW" : "SCARD_IOCTL_FORGETREADERW";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_ADDREADERTOGROUPA:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardAddReaderToGroupA" : "SCARD_IOCTL_ADDREADERTOGROUPA";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_ADDREADERTOGROUPW:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardAddReaderToGroupW" : "SCARD_IOCTL_ADDREADERTOGROUPW";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_REMOVEREADERFROMGROUPA:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardRemoveReaderFromGroupA" : "SCARD_IOCTL_REMOVEREADERFROMGROUPA";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_REMOVEREADERFROMGROUPW:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardRemoveReaderFromGroupW" : "SCARD_IOCTL_REMOVEREADERFROMGROUPW";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_LOCATECARDSA:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardLocateCardsA" : "SCARD_IOCTL_LOCATECARDSA";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_LOCATECARDSW:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardLocateCardsW" : "SCARD_IOCTL_LOCATECARDSW";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_GETSTATUSCHANGEA:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardGetStatusChangeA" : "SCARD_IOCTL_GETSTATUSCHANGEA";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_GETSTATUSCHANGEW:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardGetStatusChangeW" : "SCARD_IOCTL_GETSTATUSCHANGEW";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_CANCEL:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardCancel" : "SCARD_IOCTL_CANCEL";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_CONNECTA:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardConnectA" : "SCARD_IOCTL_CONNECTA";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_CONNECTW:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardConnectW" : "SCARD_IOCTL_CONNECTW";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_RECONNECT:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardReconnect" : "SCARD_IOCTL_RECONNECT";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_DISCONNECT:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardDisconnect" : "SCARD_IOCTL_DISCONNECT";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_BEGINTRANSACTION:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardBeginTransaction" : "SCARD_IOCTL_BEGINTRANSACTION";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_ENDTRANSACTION:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardEndTransaction" : "SCARD_IOCTL_ENDTRANSACTION";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_STATE:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardState" : "SCARD_IOCTL_STATE";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_STATUSA:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardStatusA" : "SCARD_IOCTL_STATUSA";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_STATUSW:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardStatusW" : "SCARD_IOCTL_STATUSW";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_TRANSMIT:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardTransmit" : "SCARD_IOCTL_TRANSMIT";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_CONTROL:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardControl" : "SCARD_IOCTL_CONTROL";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_GETATTRIB:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardGetAttrib" : "SCARD_IOCTL_GETATTRIB";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_SETATTRIB:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardSetAttrib" : "SCARD_IOCTL_SETATTRIB";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_ACCESSSTARTEDEVENT:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardAccessStartedEvent" : "SCARD_IOCTL_ACCESSSTARTEDEVENT";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_LOCATECARDSBYATRA:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardLocateCardsByATRA" : "SCARD_IOCTL_LOCATECARDSBYATRA";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_LOCATECARDSBYATRW:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardLocateCardsByATRB" : "SCARD_IOCTL_LOCATECARDSBYATRW";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_READCACHEA:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardReadCacheA" : "SCARD_IOCTL_READCACHEA";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_READCACHEW:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardReadCacheW" : "SCARD_IOCTL_READCACHEW";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_WRITECACHEA:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardWriteCacheA" : "SCARD_IOCTL_WRITECACHEA";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_WRITECACHEW:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardWriteCacheW" : "SCARD_IOCTL_WRITECACHEW";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_GETTRANSMITCOUNT:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardGetTransmitCount" : "SCARD_IOCTL_GETTRANSMITCOUNT";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
case SCARD_IOCTL_RELEASETARTEDEVENT:
|
|
|
|
return funcName ? "SCardReleaseStartedEvent" : "SCARD_IOCTL_RELEASETARTEDEVENT";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_GETREADERICON:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardGetReaderIcon" : "SCARD_IOCTL_GETREADERICON";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
case SCARD_IOCTL_GETDEVICETYPEID:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardGetDeviceTypeId" : "SCARD_IOCTL_GETDEVICETYPEID";
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
default:
|
2014-04-07 00:29:11 +04:00
|
|
|
return funcName ? "SCardUnknown" : "SCARD_IOCTL_UNKNOWN";
|
2014-04-04 08:56:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_EstablishContext_Decode(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2011-10-15 19:30:10 +04:00
|
|
|
{
|
2015-07-03 14:09:03 +03:00
|
|
|
LONG status;
|
2015-06-30 18:42:01 +03:00
|
|
|
EstablishContext_Call* call;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->call = call = calloc(1, sizeof(EstablishContext_Call));
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-03-27 16:49:09 +03:00
|
|
|
status = smartcard_unpack_establish_context_call(smartcard, irp->input, call);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
return log_status_error(TAG, "smartcard_unpack_establish_context_call", status);
|
2015-07-03 14:09:03 +03:00
|
|
|
}
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2015-07-03 14:09:03 +03:00
|
|
|
return SCARD_S_SUCCESS;
|
2014-05-12 22:13:57 +04:00
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_EstablishContext_Call(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
2015-07-03 14:09:03 +03:00
|
|
|
LONG status;
|
2020-02-20 14:17:42 +03:00
|
|
|
SCARDCONTEXT hContext = { 0 };
|
2014-05-12 22:13:57 +04:00
|
|
|
EstablishContext_Return ret;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
EstablishContext_Call* call = operation->call;
|
2014-05-12 22:13:57 +04:00
|
|
|
status = ret.ReturnCode = SCardEstablishContext(call->dwScope, NULL, NULL, &hContext);
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2014-05-07 01:42:10 +04:00
|
|
|
if (ret.ReturnCode == SCARD_S_SUCCESS)
|
|
|
|
{
|
2014-08-18 21:34:47 +04:00
|
|
|
SMARTCARD_CONTEXT* pContext;
|
2019-11-06 17:24:51 +03:00
|
|
|
void* key = (void*)(size_t)hContext;
|
2015-05-18 12:28:00 +03:00
|
|
|
// TODO: handle return values
|
2014-05-12 19:28:20 +04:00
|
|
|
pContext = smartcard_context_new(smartcard, hContext);
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2015-07-03 14:09:03 +03:00
|
|
|
if (!pContext)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "smartcard_context_new failed!");
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!ListDictionary_Add(smartcard->rgSCardContextList, key, (void*)pContext))
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "ListDictionary_Add failed!");
|
|
|
|
return STATUS_INTERNAL_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
return log_status_error(TAG, "SCardEstablishContext", status);
|
2014-05-07 01:42:10 +04:00
|
|
|
}
|
2014-04-12 01:44:27 +04:00
|
|
|
|
|
|
|
smartcard_scard_context_native_to_redir(smartcard, &(ret.hContext), hContext);
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-03-27 16:49:09 +03:00
|
|
|
status = smartcard_pack_establish_context_return(smartcard, irp->output, &ret);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
return log_status_error(TAG, "smartcard_pack_establish_context_return", status);
|
2015-07-03 14:09:03 +03:00
|
|
|
}
|
2014-04-07 20:13:31 +04:00
|
|
|
|
|
|
|
return ret.ReturnCode;
|
2011-10-15 19:30:10 +04:00
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_ReleaseContext_Decode(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
2015-07-03 14:09:03 +03:00
|
|
|
LONG status;
|
2015-06-30 18:42:01 +03:00
|
|
|
Context_Call* call;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->call = call = calloc(1, sizeof(Context_Call));
|
2014-05-12 22:13:57 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-03-27 16:49:09 +03:00
|
|
|
status = smartcard_unpack_context_call(smartcard, irp->input, call, "ReleaseContext");
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
log_status_error(TAG, "smartcard_unpack_context_call", status);
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2014-05-13 00:45:24 +04:00
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
2014-05-12 22:13:57 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_ReleaseContext_Call(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
|
|
|
Long_Return ret;
|
2020-01-13 12:51:22 +03:00
|
|
|
ret.ReturnCode = SCardReleaseContext(operation->hContext);
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2014-05-07 01:42:10 +04:00
|
|
|
if (ret.ReturnCode == SCARD_S_SUCCESS)
|
|
|
|
{
|
2014-08-18 21:34:47 +04:00
|
|
|
SMARTCARD_CONTEXT* pContext;
|
2019-11-06 17:24:51 +03:00
|
|
|
void* key = (void*)(size_t)operation->hContext;
|
|
|
|
pContext = (SMARTCARD_CONTEXT*)ListDictionary_Remove(smartcard->rgSCardContextList, key);
|
2014-05-12 19:28:20 +04:00
|
|
|
smartcard_context_free(pContext);
|
2014-05-07 01:42:10 +04:00
|
|
|
}
|
2015-07-03 14:09:03 +03:00
|
|
|
else
|
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
return log_status_error(TAG, "SCardReleaseContext", ret.ReturnCode);
|
2015-07-03 14:09:03 +03:00
|
|
|
}
|
2014-05-07 01:42:10 +04:00
|
|
|
|
2014-05-06 21:00:44 +04:00
|
|
|
smartcard_trace_long_return(smartcard, &ret, "ReleaseContext");
|
2014-04-07 20:13:31 +04:00
|
|
|
return ret.ReturnCode;
|
2011-10-15 19:30:10 +04:00
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_IsValidContext_Decode(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
2015-07-03 14:09:03 +03:00
|
|
|
LONG status;
|
2015-06-30 18:42:01 +03:00
|
|
|
Context_Call* call;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->call = call = calloc(1, sizeof(Context_Call));
|
2014-04-11 10:17:36 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_unpack_context_call(smartcard, irp->input, call, "IsValidContext");
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2014-05-13 00:45:24 +04:00
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
2014-05-12 22:13:57 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_IsValidContext_Call(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
|
|
|
Long_Return ret;
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
ret.ReturnCode = SCardIsValidContext(operation->hContext);
|
2014-05-06 21:00:44 +04:00
|
|
|
smartcard_trace_long_return(smartcard, &ret, "IsValidContext");
|
2014-04-07 20:13:31 +04:00
|
|
|
return ret.ReturnCode;
|
2011-10-15 19:30:10 +04:00
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_ListReaderGroupsA_Decode(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2015-06-30 18:42:01 +03:00
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
ListReaderGroups_Call* call;
|
|
|
|
IRP* irp = operation->irp;
|
|
|
|
operation->call = call = calloc(1, sizeof(ListReaderGroups_Call));
|
|
|
|
|
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_unpack_list_reader_groups_call(smartcard, irp->input, call, FALSE);
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_ListReaderGroupsA_Call(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2015-06-30 18:42:01 +03:00
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
ListReaderGroups_Return ret;
|
|
|
|
LPSTR mszGroups = NULL;
|
|
|
|
DWORD cchGroups = 0;
|
|
|
|
IRP* irp = operation->irp;
|
|
|
|
cchGroups = SCARD_AUTOALLOCATE;
|
2019-11-06 17:24:51 +03:00
|
|
|
status = ret.ReturnCode =
|
|
|
|
SCardListReaderGroupsA(operation->hContext, (LPSTR)&mszGroups, &cchGroups);
|
|
|
|
ret.msz = (BYTE*)mszGroups;
|
2015-06-30 18:42:01 +03:00
|
|
|
ret.cBytes = cchGroups;
|
|
|
|
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
2020-02-20 17:35:11 +03:00
|
|
|
status = smartcard_pack_list_reader_groups_return(smartcard, irp->output, &ret, FALSE);
|
2015-06-30 18:42:01 +03:00
|
|
|
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
if (mszGroups)
|
|
|
|
SCardFreeMemory(operation->hContext, mszGroups);
|
|
|
|
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_ListReaderGroupsW_Decode(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2015-06-30 18:42:01 +03:00
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
ListReaderGroups_Call* call;
|
|
|
|
IRP* irp = operation->irp;
|
|
|
|
operation->call = call = calloc(1, sizeof(ListReaderGroups_Call));
|
|
|
|
|
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_unpack_list_reader_groups_call(smartcard, irp->input, call, TRUE);
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_ListReaderGroupsW_Call(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2015-06-30 18:42:01 +03:00
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
ListReaderGroups_Return ret;
|
|
|
|
LPWSTR mszGroups = NULL;
|
|
|
|
DWORD cchGroups = 0;
|
|
|
|
IRP* irp = operation->irp;
|
|
|
|
cchGroups = SCARD_AUTOALLOCATE;
|
2019-11-06 17:24:51 +03:00
|
|
|
status = ret.ReturnCode =
|
|
|
|
SCardListReaderGroupsW(operation->hContext, (LPWSTR)&mszGroups, &cchGroups);
|
|
|
|
ret.msz = (BYTE*)mszGroups;
|
2015-06-30 18:42:01 +03:00
|
|
|
ret.cBytes = cchGroups;
|
|
|
|
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
2020-02-20 17:35:11 +03:00
|
|
|
status = smartcard_pack_list_reader_groups_return(smartcard, irp->output, &ret, TRUE);
|
2015-06-30 18:42:01 +03:00
|
|
|
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
if (mszGroups)
|
|
|
|
SCardFreeMemory(operation->hContext, mszGroups);
|
|
|
|
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
|
|
|
|
2018-09-04 13:58:05 +03:00
|
|
|
static BOOL filter_match(wLinkedList* list, LPCSTR reader, size_t readerLen)
|
|
|
|
{
|
|
|
|
if (readerLen < 1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
LinkedList_Enumerator_Reset(list);
|
|
|
|
|
|
|
|
while (LinkedList_Enumerator_MoveNext(list))
|
|
|
|
{
|
|
|
|
const char* filter = LinkedList_Enumerator_Current(list);
|
|
|
|
|
|
|
|
if (filter)
|
|
|
|
{
|
|
|
|
if (strstr(reader, filter) != NULL)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD filter_device_by_name_a(wLinkedList* list, LPSTR* mszReaders, DWORD cchReaders)
|
|
|
|
{
|
|
|
|
size_t rpos = 0, wpos = 0;
|
|
|
|
|
2019-05-02 07:11:57 +03:00
|
|
|
if (*mszReaders == NULL || LinkedList_Count(list) < 1)
|
2018-09-04 13:58:05 +03:00
|
|
|
return cchReaders;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
LPCSTR rreader = &(*mszReaders)[rpos];
|
|
|
|
LPSTR wreader = &(*mszReaders)[wpos];
|
|
|
|
size_t readerLen = strnlen(rreader, cchReaders - rpos);
|
2020-04-08 14:03:02 +03:00
|
|
|
|
2018-09-04 13:58:05 +03:00
|
|
|
rpos += readerLen + 1;
|
|
|
|
|
|
|
|
if (filter_match(list, rreader, readerLen))
|
|
|
|
{
|
|
|
|
if (rreader != wreader)
|
2020-04-08 14:03:02 +03:00
|
|
|
memmove(wreader, rreader, readerLen + 1);
|
2018-09-04 13:58:05 +03:00
|
|
|
|
|
|
|
wpos += readerLen + 1;
|
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
} while (rpos < cchReaders);
|
2018-09-04 13:58:05 +03:00
|
|
|
|
|
|
|
/* this string must be double 0 terminated */
|
|
|
|
if (rpos != wpos)
|
|
|
|
{
|
|
|
|
if (wpos >= cchReaders)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
(*mszReaders)[wpos++] = '\0';
|
|
|
|
}
|
|
|
|
|
2020-01-23 12:39:43 +03:00
|
|
|
return (DWORD)wpos;
|
2018-09-04 13:58:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD filter_device_by_name_w(wLinkedList* list, LPWSTR* mszReaders, DWORD cchReaders)
|
|
|
|
{
|
2019-02-07 16:33:08 +03:00
|
|
|
int res;
|
2018-09-04 13:58:05 +03:00
|
|
|
DWORD rc;
|
2019-04-26 10:10:41 +03:00
|
|
|
LPSTR readers = NULL;
|
2018-09-04 13:58:05 +03:00
|
|
|
|
|
|
|
if (LinkedList_Count(list) < 1)
|
|
|
|
return cchReaders;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
res = ConvertFromUnicode(CP_UTF8, 0, *mszReaders, (int)cchReaders, &readers, 0, NULL, NULL);
|
2019-02-07 16:33:08 +03:00
|
|
|
|
2019-04-26 10:10:41 +03:00
|
|
|
/* When res==0, readers may have been set to NULL by ConvertFromUnicode */
|
|
|
|
if ((res < 0) || ((DWORD)res != cchReaders) || (readers == 0))
|
2018-09-04 13:58:05 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
free(*mszReaders);
|
2018-09-04 16:22:06 +03:00
|
|
|
*mszReaders = NULL;
|
2018-09-04 13:58:05 +03:00
|
|
|
rc = filter_device_by_name_a(list, &readers, cchReaders);
|
2019-02-07 16:33:08 +03:00
|
|
|
res = ConvertToUnicode(CP_UTF8, 0, readers, (int)rc, mszReaders, 0);
|
|
|
|
|
|
|
|
if ((res < 0) || ((DWORD)res != rc))
|
2018-09-04 13:58:05 +03:00
|
|
|
rc = 0;
|
|
|
|
|
|
|
|
free(readers);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_ListReadersA_Decode(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
2015-07-03 14:09:03 +03:00
|
|
|
LONG status;
|
2015-06-30 18:42:01 +03:00
|
|
|
ListReaders_Call* call;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->call = call = calloc(1, sizeof(ListReaders_Call));
|
2014-05-12 22:13:57 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_unpack_list_readers_call(smartcard, irp->input, call, FALSE);
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2014-05-13 00:45:24 +04:00
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
2014-05-12 22:13:57 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_ListReadersA_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2011-10-15 19:30:10 +04:00
|
|
|
{
|
2015-07-03 14:09:03 +03:00
|
|
|
LONG status;
|
2014-04-07 08:10:27 +04:00
|
|
|
ListReaders_Return ret;
|
|
|
|
LPSTR mszReaders = NULL;
|
|
|
|
DWORD cchReaders = 0;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
ListReaders_Call* call = operation->call;
|
2014-04-07 08:10:27 +04:00
|
|
|
cchReaders = SCARD_AUTOALLOCATE;
|
2019-11-06 17:24:51 +03:00
|
|
|
status = ret.ReturnCode = SCardListReadersA(operation->hContext, (LPCSTR)call->mszGroups,
|
|
|
|
(LPSTR)&mszReaders, &cchReaders);
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2014-12-27 21:50:50 +03:00
|
|
|
if (call->mszGroups)
|
|
|
|
{
|
|
|
|
free(call->mszGroups);
|
|
|
|
call->mszGroups = NULL;
|
|
|
|
}
|
|
|
|
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
return log_status_error(TAG, "SCardListReadersA", status);
|
2015-07-03 14:09:03 +03:00
|
|
|
}
|
2014-04-11 01:36:42 +04:00
|
|
|
|
2019-05-02 07:11:57 +03:00
|
|
|
cchReaders = filter_device_by_name_a(smartcard->names, &mszReaders, cchReaders);
|
2019-11-06 17:24:51 +03:00
|
|
|
ret.msz = (BYTE*)mszReaders;
|
2019-05-02 07:11:57 +03:00
|
|
|
ret.cBytes = cchReaders;
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-03-27 16:49:09 +03:00
|
|
|
status = smartcard_pack_list_readers_return(smartcard, irp->output, &ret, FALSE);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
return log_status_error(TAG, "smartcard_pack_list_readers_return", status);
|
2015-07-03 14:09:03 +03:00
|
|
|
}
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2014-04-07 08:10:27 +04:00
|
|
|
if (mszReaders)
|
2014-05-13 00:45:24 +04:00
|
|
|
SCardFreeMemory(operation->hContext, mszReaders);
|
2014-04-07 05:09:49 +04:00
|
|
|
|
2015-07-22 17:25:17 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
2014-04-07 20:13:31 +04:00
|
|
|
return ret.ReturnCode;
|
2014-04-07 08:10:27 +04:00
|
|
|
}
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_ListReadersW_Decode(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
2015-07-03 14:09:03 +03:00
|
|
|
LONG status;
|
2015-06-30 18:42:01 +03:00
|
|
|
ListReaders_Call* call;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->call = call = calloc(1, sizeof(ListReaders_Call));
|
2014-05-12 22:13:57 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_unpack_list_readers_call(smartcard, irp->input, call, TRUE);
|
|
|
|
|
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_context_and_two_strings_a_Decode(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
ContextAndTwoStringA_Call* call;
|
|
|
|
IRP* irp = operation->irp;
|
|
|
|
operation->call = call = calloc(1, sizeof(ContextAndTwoStringA_Call));
|
|
|
|
|
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
status = smartcard_unpack_context_and_two_strings_a_call(smartcard, irp->input, call);
|
|
|
|
|
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_context_and_two_strings_w_Decode(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
ContextAndTwoStringW_Call* call;
|
|
|
|
IRP* irp = operation->irp;
|
|
|
|
operation->call = call = calloc(1, sizeof(ContextAndTwoStringW_Call));
|
|
|
|
|
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
status = smartcard_unpack_context_and_two_strings_w_call(smartcard, irp->input, call);
|
|
|
|
|
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_context_and_string_a_Decode(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
ContextAndStringA_Call* call;
|
|
|
|
IRP* irp = operation->irp;
|
|
|
|
operation->call = call = calloc(1, sizeof(ContextAndStringA_Call));
|
|
|
|
|
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
status = smartcard_unpack_context_and_string_a_call(smartcard, irp->input, call);
|
|
|
|
|
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_context_and_string_w_Decode(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
ContextAndStringW_Call* call;
|
|
|
|
IRP* irp = operation->irp;
|
|
|
|
operation->call = call = calloc(1, sizeof(ContextAndStringW_Call));
|
|
|
|
|
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
status = smartcard_unpack_context_and_string_w_call(smartcard, irp->input, call);
|
|
|
|
|
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_LocateCardsA_Decode(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
LocateCardsA_Call* call;
|
|
|
|
IRP* irp = operation->irp;
|
|
|
|
operation->call = call = calloc(1, sizeof(LocateCardsA_Call));
|
|
|
|
|
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
status = smartcard_unpack_locate_cards_a_call(smartcard, irp->input, call);
|
|
|
|
|
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_LocateCardsW_Decode(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
LocateCardsW_Call* call;
|
|
|
|
IRP* irp = operation->irp;
|
|
|
|
operation->call = call = calloc(1, sizeof(LocateCardsW_Call));
|
|
|
|
|
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
status = smartcard_unpack_locate_cards_w_call(smartcard, irp->input, call);
|
2014-12-27 21:50:50 +03:00
|
|
|
|
2014-05-13 00:45:24 +04:00
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
2014-05-12 22:13:57 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_ListReadersW_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
2015-07-03 14:09:03 +03:00
|
|
|
LONG status;
|
2014-05-12 22:13:57 +04:00
|
|
|
ListReaders_Return ret;
|
|
|
|
DWORD cchReaders = 0;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
ListReaders_Call* call = operation->call;
|
2020-01-23 12:39:43 +03:00
|
|
|
union {
|
|
|
|
const BYTE* bp;
|
|
|
|
const char* sz;
|
|
|
|
const WCHAR* wz;
|
|
|
|
} string;
|
2020-02-20 16:36:53 +03:00
|
|
|
union {
|
|
|
|
WCHAR** ppw;
|
|
|
|
WCHAR* pw;
|
|
|
|
CHAR* pc;
|
|
|
|
BYTE* pb;
|
|
|
|
} mszReaders;
|
2020-01-23 12:39:43 +03:00
|
|
|
|
|
|
|
string.bp = call->mszGroups;
|
2014-04-07 08:10:27 +04:00
|
|
|
cchReaders = SCARD_AUTOALLOCATE;
|
2020-01-13 12:51:22 +03:00
|
|
|
status = ret.ReturnCode =
|
2020-02-20 16:36:53 +03:00
|
|
|
SCardListReadersW(operation->hContext, string.wz, (LPWSTR)&mszReaders.pw, &cchReaders);
|
2014-04-11 01:36:42 +04:00
|
|
|
|
2014-12-27 21:50:50 +03:00
|
|
|
if (call->mszGroups)
|
|
|
|
{
|
|
|
|
free(call->mszGroups);
|
|
|
|
call->mszGroups = NULL;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return log_status_error(TAG, "SCardListReadersW", status);
|
|
|
|
|
2020-02-20 16:36:53 +03:00
|
|
|
cchReaders = filter_device_by_name_w(smartcard->names, &mszReaders.pw, cchReaders);
|
|
|
|
ret.msz = mszReaders.pb;
|
2020-02-18 13:50:11 +03:00
|
|
|
ret.cBytes = cchReaders;
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_pack_list_readers_return(smartcard, irp->output, &ret, TRUE);
|
|
|
|
|
2020-02-20 16:36:53 +03:00
|
|
|
if (mszReaders.pb)
|
|
|
|
SCardFreeMemory(operation->hContext, mszReaders.pb);
|
2020-01-13 12:51:22 +03:00
|
|
|
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_IntroduceReaderGroupA_Call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
Long_Return ret;
|
|
|
|
ContextAndStringA_Call* call = operation->call;
|
|
|
|
ret.ReturnCode = SCardIntroduceReaderGroupA(operation->hContext, call->sz);
|
|
|
|
log_status_error(TAG, "SCardIntroduceReaderGroupA", ret.ReturnCode);
|
|
|
|
if (call->sz)
|
|
|
|
{
|
|
|
|
free(call->sz);
|
|
|
|
call->sz = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
smartcard_trace_long_return(smartcard, &ret, "IntroduceReaderGroupA");
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_IntroduceReaderGroupW_Call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
Long_Return ret;
|
|
|
|
ContextAndStringW_Call* call = operation->call;
|
|
|
|
ret.ReturnCode = SCardIntroduceReaderGroupW(operation->hContext, call->sz);
|
|
|
|
log_status_error(TAG, "SCardIntroduceReaderGroupW", ret.ReturnCode);
|
|
|
|
if (call->sz)
|
2015-07-03 14:09:03 +03:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
free(call->sz);
|
|
|
|
call->sz = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
smartcard_trace_long_return(smartcard, &ret, "IntroduceReaderGroupW");
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_IntroduceReaderA_Call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
Long_Return ret;
|
|
|
|
ContextAndTwoStringA_Call* call = operation->call;
|
|
|
|
ret.ReturnCode = SCardIntroduceReaderA(operation->hContext, call->sz1, call->sz2);
|
|
|
|
log_status_error(TAG, "SCardIntroduceReaderA", ret.ReturnCode);
|
|
|
|
free(call->sz1);
|
|
|
|
call->sz1 = NULL;
|
|
|
|
free(call->sz2);
|
|
|
|
call->sz2 = NULL;
|
|
|
|
|
|
|
|
smartcard_trace_long_return(smartcard, &ret, "IntroduceReaderA");
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_IntroduceReaderW_Call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
Long_Return ret;
|
|
|
|
ContextAndTwoStringW_Call* call = operation->call;
|
|
|
|
ret.ReturnCode = SCardIntroduceReaderW(operation->hContext, call->sz1, call->sz2);
|
|
|
|
log_status_error(TAG, "SCardIntroduceReaderW", ret.ReturnCode);
|
|
|
|
free(call->sz1);
|
|
|
|
call->sz1 = NULL;
|
|
|
|
free(call->sz2);
|
|
|
|
call->sz2 = NULL;
|
|
|
|
|
|
|
|
smartcard_trace_long_return(smartcard, &ret, "IntroduceReaderW");
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_ForgetReaderA_Call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
Long_Return ret;
|
|
|
|
ContextAndStringA_Call* call = operation->call;
|
|
|
|
ret.ReturnCode = SCardForgetReaderA(operation->hContext, call->sz);
|
|
|
|
log_status_error(TAG, "SCardForgetReaderA", ret.ReturnCode);
|
|
|
|
if (call->sz)
|
|
|
|
{
|
|
|
|
free(call->sz);
|
|
|
|
call->sz = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
smartcard_trace_long_return(smartcard, &ret, "SCardForgetReaderA");
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_ForgetReaderW_Call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
Long_Return ret;
|
|
|
|
ContextAndStringW_Call* call = operation->call;
|
|
|
|
ret.ReturnCode = SCardForgetReaderW(operation->hContext, call->sz);
|
|
|
|
log_status_error(TAG, "SCardForgetReaderW", ret.ReturnCode);
|
|
|
|
if (call->sz)
|
|
|
|
{
|
|
|
|
free(call->sz);
|
|
|
|
call->sz = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
smartcard_trace_long_return(smartcard, &ret, "SCardForgetReaderW");
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_AddReaderToGroupA_Call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
Long_Return ret;
|
|
|
|
ContextAndTwoStringA_Call* call = operation->call;
|
|
|
|
ret.ReturnCode = SCardAddReaderToGroupA(operation->hContext, call->sz1, call->sz2);
|
|
|
|
log_status_error(TAG, "SCardAddReaderToGroupA", ret.ReturnCode);
|
|
|
|
free(call->sz1);
|
|
|
|
call->sz1 = NULL;
|
|
|
|
free(call->sz2);
|
|
|
|
call->sz2 = NULL;
|
|
|
|
|
|
|
|
smartcard_trace_long_return(smartcard, &ret, "SCardAddReaderToGroupA");
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_AddReaderToGroupW_Call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
Long_Return ret;
|
|
|
|
ContextAndTwoStringW_Call* call = operation->call;
|
|
|
|
ret.ReturnCode = SCardAddReaderToGroupW(operation->hContext, call->sz1, call->sz2);
|
|
|
|
log_status_error(TAG, "SCardAddReaderToGroupW", ret.ReturnCode);
|
|
|
|
free(call->sz1);
|
|
|
|
call->sz1 = NULL;
|
|
|
|
free(call->sz2);
|
|
|
|
call->sz2 = NULL;
|
|
|
|
|
|
|
|
smartcard_trace_long_return(smartcard, &ret, "SCardAddReaderToGroupA");
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_RemoveReaderFromGroupA_Call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
Long_Return ret;
|
|
|
|
ContextAndTwoStringA_Call* call = operation->call;
|
|
|
|
ret.ReturnCode = SCardRemoveReaderFromGroupA(operation->hContext, call->sz1, call->sz2);
|
|
|
|
log_status_error(TAG, "SCardRemoveReaderFromGroupA", ret.ReturnCode);
|
|
|
|
free(call->sz1);
|
|
|
|
call->sz1 = NULL;
|
|
|
|
free(call->sz2);
|
|
|
|
call->sz2 = NULL;
|
|
|
|
|
|
|
|
smartcard_trace_long_return(smartcard, &ret, "SCardRemoveReaderFromGroupA");
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_RemoveReaderFromGroupW_Call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
Long_Return ret;
|
|
|
|
ContextAndTwoStringW_Call* call = operation->call;
|
|
|
|
ret.ReturnCode = SCardRemoveReaderFromGroupW(operation->hContext, call->sz1, call->sz2);
|
|
|
|
log_status_error(TAG, "SCardRemoveReaderFromGroupW", ret.ReturnCode);
|
|
|
|
free(call->sz1);
|
|
|
|
call->sz1 = NULL;
|
|
|
|
free(call->sz2);
|
|
|
|
call->sz2 = NULL;
|
|
|
|
|
|
|
|
smartcard_trace_long_return(smartcard, &ret, "SCardRemoveReaderFromGroupW");
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_LocateCardsA_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
UINT32 x;
|
|
|
|
LONG status;
|
|
|
|
LocateCards_Return ret;
|
|
|
|
LocateCardsA_Call* call = operation->call;
|
|
|
|
IRP* irp = operation->irp;
|
|
|
|
|
|
|
|
ret.ReturnCode = SCardLocateCardsA(operation->hContext, call->mszCards, call->rgReaderStates,
|
|
|
|
call->cReaders);
|
|
|
|
log_status_error(TAG, "SCardLocateCardsA", ret.ReturnCode);
|
|
|
|
free(call->mszCards);
|
|
|
|
for (x = 0; x < call->cReaders; x++)
|
|
|
|
{
|
2020-01-23 12:39:43 +03:00
|
|
|
SCARD_READERSTATEA* state = &call->rgReaderStates[x];
|
2020-01-13 12:51:22 +03:00
|
|
|
free(state->szReader);
|
|
|
|
}
|
|
|
|
free(call->rgReaderStates);
|
|
|
|
|
|
|
|
status = smartcard_pack_locate_cards_return(smartcard, irp->output, &ret);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_LocateCardsW_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
UINT32 x;
|
|
|
|
LONG status;
|
|
|
|
LocateCards_Return ret;
|
|
|
|
LocateCardsW_Call* call = operation->call;
|
|
|
|
IRP* irp = operation->irp;
|
|
|
|
|
|
|
|
ret.ReturnCode = SCardLocateCardsW(operation->hContext, call->mszCards, call->rgReaderStates,
|
|
|
|
call->cReaders);
|
|
|
|
log_status_error(TAG, "SCardLocateCardsW", ret.ReturnCode);
|
|
|
|
free(call->mszCards);
|
|
|
|
for (x = 0; x < call->cReaders; x++)
|
|
|
|
{
|
2020-01-23 12:39:43 +03:00
|
|
|
SCARD_READERSTATEW* state = &call->rgReaderStates[x];
|
2020-01-13 12:51:22 +03:00
|
|
|
free(state->szReader);
|
|
|
|
}
|
|
|
|
free(call->rgReaderStates);
|
|
|
|
|
|
|
|
status = smartcard_pack_locate_cards_return(smartcard, irp->output, &ret);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_ReadCacheA_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
ReadCache_Return ret = { 0 };
|
|
|
|
ReadCacheA_Call* call = operation->call;
|
|
|
|
IRP* irp = operation->irp;
|
2020-02-17 12:54:03 +03:00
|
|
|
BOOL autoalloc = (call->Common.cbDataLen == SCARD_AUTOALLOCATE);
|
2020-01-13 12:51:22 +03:00
|
|
|
|
|
|
|
if (!call->Common.fPbDataIsNULL)
|
|
|
|
{
|
|
|
|
ret.cbDataLen = call->Common.cbDataLen;
|
2020-04-20 14:42:02 +03:00
|
|
|
if (!autoalloc)
|
2020-02-17 12:54:03 +03:00
|
|
|
{
|
|
|
|
ret.pbData = malloc(ret.cbDataLen);
|
|
|
|
if (!ret.pbData)
|
|
|
|
return SCARD_F_INTERNAL_ERROR;
|
|
|
|
}
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
2020-02-17 12:54:03 +03:00
|
|
|
if (autoalloc)
|
|
|
|
ret.ReturnCode = SCardReadCacheA(operation->hContext, call->Common.CardIdentifier,
|
|
|
|
call->Common.FreshnessCounter, call->szLookupName,
|
|
|
|
(BYTE*)&ret.pbData, &ret.cbDataLen);
|
|
|
|
else
|
|
|
|
ret.ReturnCode = SCardReadCacheA(operation->hContext, call->Common.CardIdentifier,
|
|
|
|
call->Common.FreshnessCounter, call->szLookupName,
|
|
|
|
ret.pbData, &ret.cbDataLen);
|
2020-04-20 14:42:02 +03:00
|
|
|
if ((ret.ReturnCode != SCARD_W_CACHE_ITEM_NOT_FOUND) &&
|
|
|
|
(ret.ReturnCode != SCARD_W_CACHE_ITEM_STALE))
|
|
|
|
{
|
|
|
|
log_status_error(TAG, "SCardReadCacheA", ret.ReturnCode);
|
|
|
|
}
|
2020-01-13 12:51:22 +03:00
|
|
|
free(call->szLookupName);
|
|
|
|
free(call->Common.CardIdentifier);
|
|
|
|
|
|
|
|
status = smartcard_pack_read_cache_return(smartcard, irp->output, &ret);
|
2020-02-17 12:54:03 +03:00
|
|
|
if (autoalloc)
|
|
|
|
SCardFreeMemory(operation->hContext, ret.pbData);
|
|
|
|
else
|
|
|
|
free(ret.pbData);
|
2020-01-13 12:51:22 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_ReadCacheW_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
ReadCache_Return ret = { 0 };
|
|
|
|
ReadCacheW_Call* call = operation->call;
|
|
|
|
IRP* irp = operation->irp;
|
2020-02-17 12:54:03 +03:00
|
|
|
BOOL autoalloc = (call->Common.cbDataLen == SCARD_AUTOALLOCATE);
|
2020-01-13 12:51:22 +03:00
|
|
|
if (!call->Common.fPbDataIsNULL)
|
|
|
|
{
|
|
|
|
ret.cbDataLen = call->Common.cbDataLen;
|
2020-04-20 14:42:02 +03:00
|
|
|
if (!autoalloc)
|
2020-02-17 12:54:03 +03:00
|
|
|
{
|
|
|
|
ret.pbData = malloc(ret.cbDataLen);
|
|
|
|
if (!ret.pbData)
|
|
|
|
return SCARD_F_INTERNAL_ERROR;
|
|
|
|
}
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
2020-02-17 12:54:03 +03:00
|
|
|
if (autoalloc)
|
|
|
|
ret.ReturnCode = SCardReadCacheW(operation->hContext, call->Common.CardIdentifier,
|
|
|
|
call->Common.FreshnessCounter, call->szLookupName,
|
|
|
|
(BYTE*)&ret.pbData, &ret.cbDataLen);
|
|
|
|
else
|
|
|
|
ret.ReturnCode = SCardReadCacheW(operation->hContext, call->Common.CardIdentifier,
|
|
|
|
call->Common.FreshnessCounter, call->szLookupName,
|
|
|
|
ret.pbData, &ret.cbDataLen);
|
2020-04-20 14:42:02 +03:00
|
|
|
if ((ret.ReturnCode != SCARD_W_CACHE_ITEM_NOT_FOUND) &&
|
|
|
|
(ret.ReturnCode != SCARD_W_CACHE_ITEM_STALE))
|
|
|
|
{
|
|
|
|
log_status_error(TAG, "SCardReadCacheA", ret.ReturnCode);
|
|
|
|
}
|
2020-01-13 12:51:22 +03:00
|
|
|
free(call->szLookupName);
|
|
|
|
free(call->Common.CardIdentifier);
|
|
|
|
|
|
|
|
status = smartcard_pack_read_cache_return(smartcard, irp->output, &ret);
|
2020-02-17 12:54:03 +03:00
|
|
|
if (autoalloc)
|
|
|
|
SCardFreeMemory(operation->hContext, ret.pbData);
|
|
|
|
else
|
|
|
|
free(ret.pbData);
|
2020-01-13 12:51:22 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_WriteCacheA_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
Long_Return ret;
|
|
|
|
WriteCacheA_Call* call = operation->call;
|
|
|
|
|
|
|
|
ret.ReturnCode = SCardWriteCacheA(operation->hContext, call->Common.CardIdentifier,
|
|
|
|
call->Common.FreshnessCounter, call->szLookupName,
|
|
|
|
call->Common.pbData, call->Common.cbDataLen);
|
|
|
|
log_status_error(TAG, "SCardWriteCacheA", ret.ReturnCode);
|
|
|
|
free(call->szLookupName);
|
|
|
|
free(call->Common.CardIdentifier);
|
|
|
|
free(call->Common.pbData);
|
|
|
|
|
|
|
|
smartcard_trace_long_return(smartcard, &ret, "SCardWriteCacheA");
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_WriteCacheW_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
Long_Return ret;
|
|
|
|
WriteCacheW_Call* call = operation->call;
|
|
|
|
|
|
|
|
ret.ReturnCode = SCardWriteCacheW(operation->hContext, call->Common.CardIdentifier,
|
|
|
|
call->Common.FreshnessCounter, call->szLookupName,
|
|
|
|
call->Common.pbData, call->Common.cbDataLen);
|
|
|
|
log_status_error(TAG, "SCardWriteCacheW", ret.ReturnCode);
|
|
|
|
free(call->szLookupName);
|
|
|
|
free(call->Common.CardIdentifier);
|
|
|
|
free(call->Common.pbData);
|
|
|
|
|
|
|
|
smartcard_trace_long_return(smartcard, &ret, "SCardWriteCacheW");
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_GetTransmitCount_Call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
GetTransmitCount_Return ret;
|
|
|
|
IRP* irp = operation->irp;
|
|
|
|
|
|
|
|
ret.ReturnCode = SCardGetTransmitCount(operation->hContext, &ret.cTransmitCount);
|
|
|
|
log_status_error(TAG, "SCardGetTransmitCount", ret.ReturnCode);
|
2020-03-27 16:49:09 +03:00
|
|
|
status = smartcard_pack_get_transmit_count_return(smartcard, irp->output, &ret);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
|
|
|
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_ReleaseStartedEvent_Call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
2020-01-23 12:39:43 +03:00
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
WINPR_UNUSED(operation);
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
WLog_WARN(TAG, "According to [MS-RDPESC] 3.1.4 Message Processing Events and Sequencing Rules "
|
|
|
|
"this is not supported?!?");
|
|
|
|
return SCARD_E_UNSUPPORTED_FEATURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_GetReaderIcon_Call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
LONG status;
|
2020-01-23 12:39:43 +03:00
|
|
|
GetReaderIcon_Return ret = { 0 };
|
2020-01-13 12:51:22 +03:00
|
|
|
GetReaderIcon_Call* call = operation->call;
|
|
|
|
IRP* irp = operation->irp;
|
|
|
|
|
|
|
|
ret.cbDataLen = SCARD_AUTOALLOCATE;
|
2020-01-23 12:39:43 +03:00
|
|
|
ret.ReturnCode = SCardGetReaderIconW(operation->hContext, call->szReaderName,
|
|
|
|
(LPBYTE)&ret.pbData, &ret.cbDataLen);
|
2020-01-13 12:51:22 +03:00
|
|
|
log_status_error(TAG, "SCardGetReaderIconW", ret.ReturnCode);
|
|
|
|
free(call->szReaderName);
|
|
|
|
status = smartcard_pack_get_reader_icon_return(smartcard, irp->output, &ret);
|
|
|
|
SCardFreeMemory(operation->hContext, ret.pbData);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2014-04-07 20:13:31 +04:00
|
|
|
return status;
|
2014-04-07 08:10:27 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
2014-12-27 21:50:50 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
static LONG smartcard_GetDeviceTypeId_Call(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
GetDeviceTypeId_Return ret;
|
|
|
|
GetDeviceTypeId_Call* call = operation->call;
|
|
|
|
IRP* irp = operation->irp;
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
ret.ReturnCode =
|
|
|
|
SCardGetDeviceTypeIdW(operation->hContext, call->szReaderName, &ret.dwDeviceId);
|
|
|
|
log_status_error(TAG, "SCardGetDeviceTypeIdW", ret.ReturnCode);
|
|
|
|
free(call->szReaderName);
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_pack_device_type_id_return(smartcard, irp->output, &ret);
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2015-07-22 17:25:17 +03:00
|
|
|
return status;
|
|
|
|
|
2014-04-07 20:13:31 +04:00
|
|
|
return ret.ReturnCode;
|
2011-10-15 19:30:10 +04:00
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_GetStatusChangeA_Decode(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
|
|
|
LONG status;
|
2015-06-30 18:42:01 +03:00
|
|
|
GetStatusChangeA_Call* call;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->call = call = calloc(1, sizeof(GetStatusChangeA_Call));
|
2014-05-12 22:13:57 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_unpack_get_status_change_a_call(smartcard, irp->input, call);
|
2015-07-03 14:09:03 +03:00
|
|
|
|
2014-05-13 00:45:24 +04:00
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
2014-05-12 22:13:57 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_GetStatusChangeA_Call(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2011-10-15 19:30:10 +04:00
|
|
|
{
|
2014-04-07 00:29:11 +04:00
|
|
|
UINT32 index;
|
2014-04-07 18:59:13 +04:00
|
|
|
GetStatusChange_Return ret;
|
2014-04-05 19:22:48 +04:00
|
|
|
LPSCARD_READERSTATEA rgReaderState = NULL;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
GetStatusChangeA_Call* call = operation->call;
|
2019-11-06 17:24:51 +03:00
|
|
|
ret.ReturnCode = SCardGetStatusChangeA(operation->hContext, call->dwTimeOut,
|
|
|
|
call->rgReaderStates, call->cReaders);
|
2020-01-13 12:51:22 +03:00
|
|
|
log_status_error(TAG, "SCardGetStatusChangeA", ret.ReturnCode);
|
2014-05-12 22:13:57 +04:00
|
|
|
ret.cReaders = call->cReaders;
|
2015-09-01 12:58:43 +03:00
|
|
|
ret.rgReaderStates = NULL;
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2017-12-13 17:46:50 +03:00
|
|
|
if (ret.cReaders > 0)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
ret.rgReaderStates = (ReaderState_Return*)calloc(ret.cReaders, sizeof(ReaderState_Return));
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2017-12-04 18:16:59 +03:00
|
|
|
if (!ret.rgReaderStates)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
2015-01-19 20:04:23 +03:00
|
|
|
|
2014-04-07 18:59:13 +04:00
|
|
|
for (index = 0; index < ret.cReaders; index++)
|
2013-09-12 15:53:15 +04:00
|
|
|
{
|
2014-05-12 22:13:57 +04:00
|
|
|
ret.rgReaderStates[index].dwCurrentState = call->rgReaderStates[index].dwCurrentState;
|
|
|
|
ret.rgReaderStates[index].dwEventState = call->rgReaderStates[index].dwEventState;
|
|
|
|
ret.rgReaderStates[index].cbAtr = call->rgReaderStates[index].cbAtr;
|
2020-03-27 17:03:59 +03:00
|
|
|
CopyMemory(&(ret.rgReaderStates[index].rgbAtr), &(call->rgReaderStates[index].rgbAtr),
|
|
|
|
sizeof(ret.rgReaderStates[index].rgbAtr));
|
2013-09-12 15:53:15 +04:00
|
|
|
}
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_pack_get_status_change_return(smartcard, irp->output, &ret, FALSE);
|
2014-04-07 20:13:31 +04:00
|
|
|
|
2014-05-12 22:13:57 +04:00
|
|
|
if (call->rgReaderStates)
|
2014-04-07 00:29:11 +04:00
|
|
|
{
|
2014-05-12 22:13:57 +04:00
|
|
|
for (index = 0; index < call->cReaders; index++)
|
2011-10-15 19:30:10 +04:00
|
|
|
{
|
2014-05-12 22:13:57 +04:00
|
|
|
rgReaderState = &call->rgReaderStates[index];
|
2015-06-30 18:42:01 +03:00
|
|
|
free((void*)rgReaderState->szReader);
|
2011-10-15 19:30:10 +04:00
|
|
|
}
|
2014-08-18 19:23:03 +04:00
|
|
|
|
2014-05-12 22:13:57 +04:00
|
|
|
free(call->rgReaderStates);
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2014-04-07 18:59:13 +04:00
|
|
|
free(ret.rgReaderStates);
|
2014-04-07 20:13:31 +04:00
|
|
|
return ret.ReturnCode;
|
2014-04-07 00:29:11 +04:00
|
|
|
}
|
2014-04-05 00:45:11 +04:00
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_GetStatusChangeW_Decode(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
|
|
|
LONG status;
|
2015-06-30 18:42:01 +03:00
|
|
|
GetStatusChangeW_Call* call;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->call = call = calloc(1, sizeof(GetStatusChangeW_Call));
|
2014-05-12 22:13:57 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_unpack_get_status_change_w_call(smartcard, irp->input, call);
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2014-05-13 00:45:24 +04:00
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
2014-05-12 22:13:57 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_GetStatusChangeW_Call(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2014-04-07 00:29:11 +04:00
|
|
|
{
|
|
|
|
UINT32 index;
|
2014-04-07 18:59:13 +04:00
|
|
|
GetStatusChange_Return ret;
|
2014-04-07 00:29:11 +04:00
|
|
|
LPSCARD_READERSTATEW rgReaderState = NULL;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
GetStatusChangeW_Call* call = operation->call;
|
2017-12-04 18:16:59 +03:00
|
|
|
ret.ReturnCode = SCardGetStatusChangeW(operation->hContext, call->dwTimeOut,
|
2017-12-13 17:46:50 +03:00
|
|
|
call->rgReaderStates, call->cReaders);
|
2020-01-13 12:51:22 +03:00
|
|
|
log_status_error(TAG, "SCardGetStatusChangeW", ret.ReturnCode);
|
2014-05-12 22:13:57 +04:00
|
|
|
ret.cReaders = call->cReaders;
|
2015-09-01 12:58:43 +03:00
|
|
|
ret.rgReaderStates = NULL;
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2017-12-13 17:46:50 +03:00
|
|
|
if (ret.cReaders > 0)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
ret.rgReaderStates = (ReaderState_Return*)calloc(ret.cReaders, sizeof(ReaderState_Return));
|
2014-04-05 19:22:48 +04:00
|
|
|
|
2017-12-04 18:16:59 +03:00
|
|
|
if (!ret.rgReaderStates)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
2015-01-19 20:04:23 +03:00
|
|
|
|
2014-04-07 18:59:13 +04:00
|
|
|
for (index = 0; index < ret.cReaders; index++)
|
2011-10-15 19:30:10 +04:00
|
|
|
{
|
2014-05-12 22:13:57 +04:00
|
|
|
ret.rgReaderStates[index].dwCurrentState = call->rgReaderStates[index].dwCurrentState;
|
|
|
|
ret.rgReaderStates[index].dwEventState = call->rgReaderStates[index].dwEventState;
|
|
|
|
ret.rgReaderStates[index].cbAtr = call->rgReaderStates[index].cbAtr;
|
2020-03-27 17:03:59 +03:00
|
|
|
CopyMemory(&(ret.rgReaderStates[index].rgbAtr), &(call->rgReaderStates[index].rgbAtr),
|
|
|
|
sizeof(ret.rgReaderStates[index].rgbAtr));
|
2011-10-15 19:30:10 +04:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_pack_get_status_change_return(smartcard, irp->output, &ret, TRUE);
|
2014-04-07 20:13:31 +04:00
|
|
|
|
2014-05-12 22:13:57 +04:00
|
|
|
if (call->rgReaderStates)
|
2013-10-01 15:09:52 +04:00
|
|
|
{
|
2014-05-12 22:13:57 +04:00
|
|
|
for (index = 0; index < call->cReaders; index++)
|
2013-10-01 15:09:52 +04:00
|
|
|
{
|
2014-05-12 22:13:57 +04:00
|
|
|
rgReaderState = &call->rgReaderStates[index];
|
2015-06-30 18:42:01 +03:00
|
|
|
free((void*)rgReaderState->szReader);
|
2013-10-01 15:09:52 +04:00
|
|
|
}
|
2014-08-18 19:23:03 +04:00
|
|
|
|
2014-05-12 22:13:57 +04:00
|
|
|
free(call->rgReaderStates);
|
2013-10-01 15:09:52 +04:00
|
|
|
}
|
2013-09-12 15:53:15 +04:00
|
|
|
|
2014-04-07 18:59:13 +04:00
|
|
|
free(ret.rgReaderStates);
|
2014-04-07 20:13:31 +04:00
|
|
|
return ret.ReturnCode;
|
2011-10-15 19:30:10 +04:00
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_Cancel_Decode(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
|
|
|
LONG status;
|
2015-06-30 18:42:01 +03:00
|
|
|
Context_Call* call;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->call = call = calloc(1, sizeof(Context_Call));
|
2014-05-12 22:13:57 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_unpack_context_call(smartcard, irp->input, call, "Cancel");
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2014-05-13 00:45:24 +04:00
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
2014-05-12 22:13:57 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_Cancel_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
|
|
|
Long_Return ret;
|
2015-07-03 14:09:03 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
ret.ReturnCode = SCardCancel(operation->hContext);
|
|
|
|
log_status_error(TAG, "SCardCancel", ret.ReturnCode);
|
2014-05-06 21:00:44 +04:00
|
|
|
smartcard_trace_long_return(smartcard, &ret, "Cancel");
|
2014-04-07 20:13:31 +04:00
|
|
|
return ret.ReturnCode;
|
2011-10-15 19:30:10 +04:00
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_ConnectA_Decode(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
|
|
|
LONG status;
|
2015-06-30 18:42:01 +03:00
|
|
|
ConnectA_Call* call;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->call = call = calloc(1, sizeof(ConnectA_Call));
|
2014-05-12 22:13:57 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_unpack_connect_a_call(smartcard, irp->input, call);
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
operation->hContext =
|
|
|
|
smartcard_scard_context_native_from_redir(smartcard, &(call->Common.hContext));
|
2014-05-12 22:13:57 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_ConnectA_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
|
|
|
LONG status;
|
2014-12-28 22:56:13 +03:00
|
|
|
SCARDHANDLE hCard = 0;
|
|
|
|
Connect_Return ret = { 0 };
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
ConnectA_Call* call = operation->call;
|
2014-04-06 00:06:46 +04:00
|
|
|
|
2014-05-12 22:13:57 +04:00
|
|
|
if ((call->Common.dwPreferredProtocols == SCARD_PROTOCOL_UNDEFINED) &&
|
2015-06-30 18:42:01 +03:00
|
|
|
(call->Common.dwShareMode != SCARD_SHARE_DIRECT))
|
2014-04-07 07:08:40 +04:00
|
|
|
{
|
2014-05-12 22:13:57 +04:00
|
|
|
call->Common.dwPreferredProtocols = SCARD_PROTOCOL_Tx;
|
2014-04-07 07:08:40 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
status = ret.ReturnCode =
|
|
|
|
SCardConnectA(operation->hContext, (char*)call->szReader, call->Common.dwShareMode,
|
|
|
|
call->Common.dwPreferredProtocols, &hCard, &ret.dwActiveProtocol);
|
2014-05-13 00:45:24 +04:00
|
|
|
smartcard_scard_context_native_to_redir(smartcard, &(ret.hContext), operation->hContext);
|
2014-04-12 01:44:27 +04:00
|
|
|
smartcard_scard_handle_native_to_redir(smartcard, &(ret.hCard), hCard);
|
2014-06-03 01:20:01 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_pack_connect_return(smartcard, irp->output, &ret);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
2017-12-14 18:21:19 +03:00
|
|
|
goto out_fail;
|
2013-10-24 23:34:14 +04:00
|
|
|
|
2017-12-13 18:57:53 +03:00
|
|
|
status = ret.ReturnCode;
|
|
|
|
out_fail:
|
2015-05-11 10:07:39 +03:00
|
|
|
free(call->szReader);
|
2017-12-13 18:57:53 +03:00
|
|
|
return status;
|
2014-04-06 00:06:46 +04:00
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_ConnectW_Decode(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
|
|
|
LONG status;
|
2015-06-30 18:42:01 +03:00
|
|
|
ConnectW_Call* call;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->call = call = calloc(1, sizeof(ConnectW_Call));
|
2014-05-12 22:13:57 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
2014-05-12 22:13:57 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_unpack_connect_w_call(smartcard, irp->input, call);
|
2015-07-03 14:09:03 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
operation->hContext =
|
|
|
|
smartcard_scard_context_native_from_redir(smartcard, &(call->Common.hContext));
|
2014-05-12 22:13:57 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_ConnectW_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
|
|
|
LONG status;
|
2014-12-28 22:56:13 +03:00
|
|
|
SCARDHANDLE hCard = 0;
|
|
|
|
Connect_Return ret = { 0 };
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
ConnectW_Call* call = operation->call;
|
2014-05-12 22:13:57 +04:00
|
|
|
|
|
|
|
if ((call->Common.dwPreferredProtocols == SCARD_PROTOCOL_UNDEFINED) &&
|
2015-06-30 18:42:01 +03:00
|
|
|
(call->Common.dwShareMode != SCARD_SHARE_DIRECT))
|
2014-04-07 07:08:40 +04:00
|
|
|
{
|
2014-05-12 22:13:57 +04:00
|
|
|
call->Common.dwPreferredProtocols = SCARD_PROTOCOL_Tx;
|
2014-04-07 07:08:40 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
status = ret.ReturnCode =
|
|
|
|
SCardConnectW(operation->hContext, (WCHAR*)call->szReader, call->Common.dwShareMode,
|
|
|
|
call->Common.dwPreferredProtocols, &hCard, &ret.dwActiveProtocol);
|
2014-05-13 00:45:24 +04:00
|
|
|
smartcard_scard_context_native_to_redir(smartcard, &(ret.hContext), operation->hContext);
|
2014-04-12 01:44:27 +04:00
|
|
|
smartcard_scard_handle_native_to_redir(smartcard, &(ret.hCard), hCard);
|
2014-06-03 01:20:01 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_pack_connect_return(smartcard, irp->output, &ret);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
2017-12-13 18:57:53 +03:00
|
|
|
goto out_fail;
|
2014-04-07 20:13:31 +04:00
|
|
|
|
2017-12-13 18:57:53 +03:00
|
|
|
status = ret.ReturnCode;
|
|
|
|
out_fail:
|
2015-05-11 10:07:39 +03:00
|
|
|
free(call->szReader);
|
2017-12-13 18:57:53 +03:00
|
|
|
return status;
|
2011-10-15 19:30:10 +04:00
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_Reconnect_Decode(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
|
|
|
LONG status;
|
2015-06-30 18:42:01 +03:00
|
|
|
Reconnect_Call* call;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->call = call = calloc(1, sizeof(Reconnect_Call));
|
2014-05-12 22:13:57 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_unpack_reconnect_call(smartcard, irp->input, call);
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2014-05-13 00:45:24 +04:00
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
operation->hCard = smartcard_scard_handle_native_from_redir(smartcard, &(call->hCard));
|
2014-05-12 22:13:57 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_Reconnect_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2011-10-15 19:30:10 +04:00
|
|
|
{
|
2012-11-21 20:56:40 +04:00
|
|
|
LONG status;
|
2014-04-05 19:22:48 +04:00
|
|
|
Reconnect_Return ret;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
Reconnect_Call* call = operation->call;
|
2019-11-06 17:24:51 +03:00
|
|
|
ret.ReturnCode = SCardReconnect(operation->hCard, call->dwShareMode, call->dwPreferredProtocols,
|
|
|
|
call->dwInitialization, &ret.dwActiveProtocol);
|
2020-01-13 12:51:22 +03:00
|
|
|
log_status_error(TAG, "SCardReconnect", ret.ReturnCode);
|
|
|
|
status = smartcard_pack_reconnect_return(smartcard, irp->output, &ret);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
2013-09-12 14:18:35 +04:00
|
|
|
return status;
|
|
|
|
|
2014-05-12 22:13:57 +04:00
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_Disconnect_Decode(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
|
|
|
LONG status;
|
2015-06-30 18:42:01 +03:00
|
|
|
HCardAndDisposition_Call* call;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->call = call = calloc(1, sizeof(HCardAndDisposition_Call));
|
2014-04-07 20:13:31 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_unpack_hcard_and_disposition_call(smartcard, irp->input, call, "Disconnect");
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2014-05-13 00:45:24 +04:00
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
operation->hCard = smartcard_scard_handle_native_from_redir(smartcard, &(call->hCard));
|
2014-05-12 22:13:57 +04:00
|
|
|
return status;
|
2011-10-15 19:30:10 +04:00
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_Disconnect_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2011-10-15 19:30:10 +04:00
|
|
|
{
|
2014-04-07 18:59:13 +04:00
|
|
|
Long_Return ret;
|
2015-06-30 18:42:01 +03:00
|
|
|
HCardAndDisposition_Call* call = operation->call;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
ret.ReturnCode = SCardDisconnect(operation->hCard, call->dwDisposition);
|
|
|
|
log_status_error(TAG, "SCardDisconnect", ret.ReturnCode);
|
2015-07-03 14:09:03 +03:00
|
|
|
smartcard_trace_long_return(smartcard, &ret, "Disconnect");
|
2013-09-12 14:18:35 +04:00
|
|
|
|
2014-05-12 22:13:57 +04:00
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_BeginTransaction_Decode(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
|
|
|
LONG status;
|
2015-06-30 18:42:01 +03:00
|
|
|
HCardAndDisposition_Call* call;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->call = call = calloc(1, sizeof(HCardAndDisposition_Call));
|
2014-05-12 22:13:57 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_unpack_hcard_and_disposition_call(smartcard, irp->input, call,
|
|
|
|
"BeginTransaction");
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2014-05-13 00:45:24 +04:00
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
operation->hCard = smartcard_scard_handle_native_from_redir(smartcard, &(call->hCard));
|
2014-05-12 22:13:57 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_BeginTransaction_Call(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2011-10-15 19:30:10 +04:00
|
|
|
{
|
2014-04-07 18:59:13 +04:00
|
|
|
Long_Return ret;
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
ret.ReturnCode = SCardBeginTransaction(operation->hCard);
|
|
|
|
log_status_error(TAG, "SCardBeginTransaction", ret.ReturnCode);
|
2014-05-12 22:13:57 +04:00
|
|
|
smartcard_trace_long_return(smartcard, &ret, "BeginTransaction");
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
2013-09-12 14:18:35 +04:00
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_EndTransaction_Decode(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
|
|
|
LONG status;
|
2015-06-30 18:42:01 +03:00
|
|
|
HCardAndDisposition_Call* call;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->call = call = calloc(1, sizeof(HCardAndDisposition_Call));
|
2014-05-12 22:13:57 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status =
|
|
|
|
smartcard_unpack_hcard_and_disposition_call(smartcard, irp->input, call, "EndTransaction");
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2014-05-13 00:45:24 +04:00
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
operation->hCard = smartcard_scard_handle_native_from_redir(smartcard, &(call->hCard));
|
2014-05-12 22:13:57 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_EndTransaction_Call(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2011-10-15 19:30:10 +04:00
|
|
|
{
|
2014-04-07 18:59:13 +04:00
|
|
|
Long_Return ret;
|
2015-06-30 18:42:01 +03:00
|
|
|
HCardAndDisposition_Call* call = operation->call;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
ret.ReturnCode = SCardEndTransaction(operation->hCard, call->dwDisposition);
|
|
|
|
log_status_error(TAG, "SCardEndTransaction", ret.ReturnCode);
|
2014-05-12 22:13:57 +04:00
|
|
|
smartcard_trace_long_return(smartcard, &ret, "EndTransaction");
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
2013-09-12 14:18:35 +04:00
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_State_Decode(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
|
|
|
LONG status;
|
2015-06-30 18:42:01 +03:00
|
|
|
State_Call* call;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->call = call = calloc(1, sizeof(State_Call));
|
2014-05-12 22:13:57 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_unpack_state_call(smartcard, irp->input, call);
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2014-05-13 00:45:24 +04:00
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
operation->hCard = smartcard_scard_handle_native_from_redir(smartcard, &(call->hCard));
|
2014-05-12 22:13:57 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_State_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2011-10-15 19:30:10 +04:00
|
|
|
{
|
2012-11-21 20:56:40 +04:00
|
|
|
LONG status;
|
2014-04-05 19:22:48 +04:00
|
|
|
State_Return ret;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2014-04-05 19:22:48 +04:00
|
|
|
ret.cbAtrLen = SCARD_ATR_LENGTH;
|
2019-11-06 17:24:51 +03:00
|
|
|
ret.ReturnCode = SCardState(operation->hCard, &ret.dwState, &ret.dwProtocol, (BYTE*)&ret.rgAtr,
|
2015-06-30 18:42:01 +03:00
|
|
|
&ret.cbAtrLen);
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
log_status_error(TAG, "SCardState", ret.ReturnCode);
|
|
|
|
status = smartcard_pack_state_return(smartcard, irp->output, &ret);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
2014-04-07 20:13:31 +04:00
|
|
|
return status;
|
|
|
|
|
|
|
|
return ret.ReturnCode;
|
2011-10-15 19:30:10 +04:00
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_StatusA_Decode(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
|
|
|
LONG status;
|
2015-06-30 18:42:01 +03:00
|
|
|
Status_Call* call;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2017-02-20 20:31:58 +03:00
|
|
|
operation->call = call = calloc(1, sizeof(Status_Call));
|
2014-05-12 22:13:57 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_unpack_status_call(smartcard, irp->input, call, FALSE);
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2014-05-13 00:45:24 +04:00
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
operation->hCard = smartcard_scard_handle_native_from_redir(smartcard, &(call->hCard));
|
2014-05-12 22:13:57 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_StatusA_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2011-10-15 19:30:10 +04:00
|
|
|
{
|
2012-11-21 20:56:40 +04:00
|
|
|
LONG status;
|
2014-05-06 22:25:19 +04:00
|
|
|
Status_Return ret = { 0 };
|
2014-04-07 08:58:34 +04:00
|
|
|
DWORD cchReaderLen = 0;
|
2017-12-13 17:46:50 +03:00
|
|
|
DWORD cbAtrLen = 0;
|
2014-04-07 08:58:34 +04:00
|
|
|
LPSTR mszReaderNames = NULL;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
Status_Call* call = operation->call;
|
2020-03-27 17:03:59 +03:00
|
|
|
|
2018-01-11 17:19:02 +03:00
|
|
|
call->cbAtrLen = 32;
|
2017-12-13 17:46:50 +03:00
|
|
|
cbAtrLen = call->cbAtrLen;
|
|
|
|
|
|
|
|
if (call->fmszReaderNamesIsNULL)
|
|
|
|
cchReaderLen = 0;
|
|
|
|
else
|
|
|
|
cchReaderLen = SCARD_AUTOALLOCATE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
status = ret.ReturnCode =
|
|
|
|
SCardStatusA(operation->hCard, call->fmszReaderNamesIsNULL ? NULL : (LPSTR)&mszReaderNames,
|
|
|
|
&cchReaderLen, &ret.dwState, &ret.dwProtocol,
|
|
|
|
cbAtrLen ? (BYTE*)&ret.pbAtr : NULL, &cbAtrLen);
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
log_status_error(TAG, "SCardStatusA", status);
|
2014-05-06 22:25:19 +04:00
|
|
|
if (status == SCARD_S_SUCCESS)
|
|
|
|
{
|
2017-12-13 17:46:50 +03:00
|
|
|
if (!call->fmszReaderNamesIsNULL)
|
2019-11-06 17:24:51 +03:00
|
|
|
ret.mszReaderNames = (BYTE*)mszReaderNames;
|
2017-12-13 17:46:50 +03:00
|
|
|
|
2014-05-06 22:25:19 +04:00
|
|
|
ret.cBytes = cchReaderLen;
|
2017-12-13 17:46:50 +03:00
|
|
|
|
|
|
|
if (call->cbAtrLen)
|
|
|
|
ret.cbAtrLen = cbAtrLen;
|
2014-05-06 22:25:19 +04:00
|
|
|
}
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_pack_status_return(smartcard, irp->output, &ret, FALSE);
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2014-04-07 08:58:34 +04:00
|
|
|
if (mszReaderNames)
|
2014-05-13 00:45:24 +04:00
|
|
|
SCardFreeMemory(operation->hContext, mszReaderNames);
|
2014-04-07 08:58:34 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
2014-04-07 20:13:31 +04:00
|
|
|
return ret.ReturnCode;
|
2014-04-07 08:58:34 +04:00
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_StatusW_Decode(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
|
|
|
LONG status;
|
2015-06-30 18:42:01 +03:00
|
|
|
Status_Call* call;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2017-02-20 20:31:58 +03:00
|
|
|
operation->call = call = calloc(1, sizeof(Status_Call));
|
2014-05-12 22:13:57 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_unpack_status_call(smartcard, irp->input, call, TRUE);
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2014-05-13 00:45:24 +04:00
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
operation->hCard = smartcard_scard_handle_native_from_redir(smartcard, &(call->hCard));
|
2014-05-12 22:13:57 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_StatusW_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2014-04-07 08:58:34 +04:00
|
|
|
{
|
|
|
|
LONG status;
|
2020-02-17 16:07:20 +03:00
|
|
|
Status_Return ret = { 0 };
|
2014-04-07 08:58:34 +04:00
|
|
|
LPWSTR mszReaderNames = NULL;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
Status_Call* call = operation->call;
|
2017-12-13 17:46:50 +03:00
|
|
|
DWORD cbAtrLen;
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2019-07-10 19:36:34 +03:00
|
|
|
/**
|
|
|
|
* [MS-RDPESC]
|
|
|
|
* According to 2.2.2.18 Status_Call cbAtrLen is unused an must be ignored upon receipt.
|
|
|
|
*/
|
|
|
|
cbAtrLen = call->cbAtrLen = 32;
|
|
|
|
|
2017-12-13 17:46:50 +03:00
|
|
|
if (call->fmszReaderNamesIsNULL)
|
2020-02-18 13:50:11 +03:00
|
|
|
ret.cBytes = 0;
|
2017-12-13 17:46:50 +03:00
|
|
|
else
|
2020-02-18 13:50:11 +03:00
|
|
|
ret.cBytes = SCARD_AUTOALLOCATE;
|
2017-12-13 17:46:50 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
status = ret.ReturnCode =
|
|
|
|
SCardStatusW(operation->hCard, call->fmszReaderNamesIsNULL ? NULL : (LPWSTR)&mszReaderNames,
|
2020-02-18 13:50:11 +03:00
|
|
|
&ret.cBytes, &ret.dwState, &ret.dwProtocol, (BYTE*)&ret.pbAtr, &cbAtrLen);
|
2020-01-13 12:51:22 +03:00
|
|
|
log_status_error(TAG, "SCardStatusW", status);
|
2017-12-13 17:46:50 +03:00
|
|
|
if (status == SCARD_S_SUCCESS)
|
|
|
|
{
|
|
|
|
if (!call->fmszReaderNamesIsNULL)
|
2019-11-06 17:24:51 +03:00
|
|
|
ret.mszReaderNames = (BYTE*)mszReaderNames;
|
2017-12-13 17:46:50 +03:00
|
|
|
|
2019-07-10 19:36:34 +03:00
|
|
|
ret.cbAtrLen = cbAtrLen;
|
2017-12-13 17:46:50 +03:00
|
|
|
}
|
2017-12-21 12:45:55 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_pack_status_return(smartcard, irp->output, &ret, TRUE);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
2014-04-07 20:13:31 +04:00
|
|
|
return status;
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2014-04-07 08:58:34 +04:00
|
|
|
if (mszReaderNames)
|
2014-05-13 00:45:24 +04:00
|
|
|
SCardFreeMemory(operation->hContext, mszReaderNames);
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2014-04-07 20:13:31 +04:00
|
|
|
return ret.ReturnCode;
|
2011-10-15 19:30:10 +04:00
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_Transmit_Decode(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
|
|
|
LONG status;
|
2015-06-30 18:42:01 +03:00
|
|
|
Transmit_Call* call;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->call = call = calloc(1, sizeof(Transmit_Call));
|
2014-05-12 22:13:57 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_unpack_transmit_call(smartcard, irp->input, call);
|
2015-01-19 20:04:23 +03:00
|
|
|
|
2014-05-13 00:45:24 +04:00
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
operation->hCard = smartcard_scard_handle_native_from_redir(smartcard, &(call->hCard));
|
2014-05-12 22:13:57 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_Transmit_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
Transmit_Return ret;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
Transmit_Call* call = operation->call;
|
2014-04-07 07:08:40 +04:00
|
|
|
ret.cbRecvLength = 0;
|
|
|
|
ret.pbRecvBuffer = NULL;
|
|
|
|
|
2014-05-12 22:13:57 +04:00
|
|
|
if (call->cbRecvLength && !call->fpbRecvBufferIsNULL)
|
2014-04-04 01:29:12 +04:00
|
|
|
{
|
2014-05-12 22:13:57 +04:00
|
|
|
if (call->cbRecvLength >= 66560)
|
|
|
|
call->cbRecvLength = 66560;
|
2014-04-07 21:39:47 +04:00
|
|
|
|
2014-05-12 22:13:57 +04:00
|
|
|
ret.cbRecvLength = call->cbRecvLength;
|
2019-11-06 17:24:51 +03:00
|
|
|
ret.pbRecvBuffer = (BYTE*)malloc(ret.cbRecvLength);
|
2015-01-19 20:04:23 +03:00
|
|
|
|
|
|
|
if (!ret.pbRecvBuffer)
|
|
|
|
return STATUS_NO_MEMORY;
|
2014-04-04 01:29:12 +04:00
|
|
|
}
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2014-05-12 22:13:57 +04:00
|
|
|
ret.pioRecvPci = call->pioRecvPci;
|
2019-11-06 17:24:51 +03:00
|
|
|
ret.ReturnCode =
|
|
|
|
SCardTransmit(operation->hCard, call->pioSendPci, call->pbSendBuffer, call->cbSendLength,
|
|
|
|
ret.pioRecvPci, ret.pbRecvBuffer, &(ret.cbRecvLength));
|
2020-01-13 12:51:22 +03:00
|
|
|
|
|
|
|
log_status_error(TAG, "SCardTransmit", ret.ReturnCode);
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2019-04-05 12:40:10 +03:00
|
|
|
status = smartcard_pack_transmit_return(smartcard, irp->output, &ret);
|
2015-05-11 10:07:39 +03:00
|
|
|
free(call->pbSendBuffer);
|
|
|
|
free(ret.pbRecvBuffer);
|
|
|
|
free(call->pioSendPci);
|
|
|
|
free(call->pioRecvPci);
|
2019-04-05 12:40:10 +03:00
|
|
|
|
2020-03-27 16:49:09 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2019-04-05 12:40:10 +03:00
|
|
|
return status;
|
2014-04-07 20:13:31 +04:00
|
|
|
return ret.ReturnCode;
|
2011-10-15 19:30:10 +04:00
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_Control_Decode(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
|
|
|
LONG status;
|
2015-06-30 18:42:01 +03:00
|
|
|
Control_Call* call;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->call = call = calloc(1, sizeof(Control_Call));
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_unpack_control_call(smartcard, irp->input, call);
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2014-05-13 00:45:24 +04:00
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
operation->hCard = smartcard_scard_handle_native_from_redir(smartcard, &(call->hCard));
|
2014-05-12 22:13:57 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_Control_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
|
|
|
LONG status;
|
2020-01-13 12:51:22 +03:00
|
|
|
Control_Return ret = { 0 };
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
Control_Call* call = operation->call;
|
2014-05-12 22:13:57 +04:00
|
|
|
ret.cbOutBufferSize = call->cbOutBufferSize;
|
2019-11-06 17:24:51 +03:00
|
|
|
ret.pvOutBuffer = (BYTE*)malloc(call->cbOutBufferSize);
|
2014-05-12 22:13:57 +04:00
|
|
|
|
2014-05-13 00:45:24 +04:00
|
|
|
if (!ret.pvOutBuffer)
|
|
|
|
return SCARD_E_NO_MEMORY;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
ret.ReturnCode =
|
|
|
|
SCardControl(operation->hCard, call->dwControlCode, call->pvInBuffer, call->cbInBufferSize,
|
|
|
|
ret.pvOutBuffer, call->cbOutBufferSize, &ret.cbOutBufferSize);
|
2020-01-13 12:51:22 +03:00
|
|
|
log_status_error(TAG, "SCardControl", ret.ReturnCode);
|
|
|
|
status = smartcard_pack_control_return(smartcard, irp->output, &ret);
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2015-05-11 10:07:39 +03:00
|
|
|
free(call->pvInBuffer);
|
|
|
|
free(ret.pvOutBuffer);
|
2020-01-13 12:51:22 +03:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
|
|
|
return status;
|
2014-04-07 20:13:31 +04:00
|
|
|
return ret.ReturnCode;
|
2011-10-15 19:30:10 +04:00
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_GetAttrib_Decode(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2014-05-12 22:13:57 +04:00
|
|
|
{
|
|
|
|
LONG status;
|
2015-06-30 18:42:01 +03:00
|
|
|
GetAttrib_Call* call;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->call = call = calloc(1, sizeof(GetAttrib_Call));
|
2014-05-12 22:13:57 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_unpack_get_attrib_call(smartcard, irp->input, call);
|
|
|
|
|
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
operation->hCard = smartcard_scard_handle_native_from_redir(smartcard, &(call->hCard));
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_SetAttrib_Decode(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
LONG status;
|
2020-01-23 11:32:34 +03:00
|
|
|
SetAttrib_Call* call;
|
2020-01-13 12:51:22 +03:00
|
|
|
IRP* irp = operation->irp;
|
|
|
|
operation->call = call = calloc(1, sizeof(SetAttrib_Call));
|
|
|
|
|
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
status = smartcard_unpack_set_attrib_call(smartcard, irp->input, call);
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2014-05-13 00:45:24 +04:00
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
operation->hCard = smartcard_scard_handle_native_from_redir(smartcard, &(call->hCard));
|
2014-05-12 22:13:57 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_GetAttrib_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2011-10-15 19:30:10 +04:00
|
|
|
{
|
2012-11-21 20:56:40 +04:00
|
|
|
LONG status;
|
2014-04-05 19:22:48 +04:00
|
|
|
DWORD cbAttrLen;
|
2014-12-22 21:28:16 +03:00
|
|
|
BOOL autoAllocate;
|
2014-04-05 19:22:48 +04:00
|
|
|
GetAttrib_Return ret;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
GetAttrib_Call* call = operation->call;
|
2014-04-05 19:22:48 +04:00
|
|
|
ret.pbAttr = NULL;
|
|
|
|
|
2014-05-12 22:13:57 +04:00
|
|
|
if (call->fpbAttrIsNULL)
|
|
|
|
call->cbAttrLen = 0;
|
2012-11-21 20:56:40 +04:00
|
|
|
|
2014-12-22 21:28:16 +03:00
|
|
|
autoAllocate = (call->cbAttrLen == SCARD_AUTOALLOCATE) ? TRUE : FALSE;
|
|
|
|
|
|
|
|
if (call->cbAttrLen && !autoAllocate)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
ret.pbAttr = (BYTE*)malloc(call->cbAttrLen);
|
2014-04-05 19:22:48 +04:00
|
|
|
|
2014-12-22 21:28:16 +03:00
|
|
|
if (!ret.pbAttr)
|
|
|
|
return SCARD_E_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2014-05-12 22:13:57 +04:00
|
|
|
cbAttrLen = call->cbAttrLen;
|
2019-11-06 17:24:51 +03:00
|
|
|
ret.ReturnCode =
|
|
|
|
SCardGetAttrib(operation->hCard, call->dwAttrId,
|
|
|
|
autoAllocate ? (LPBYTE) & (ret.pbAttr) : ret.pbAttr, &cbAttrLen);
|
2020-01-13 12:51:22 +03:00
|
|
|
log_status_error(TAG, "SCardGetAttrib", ret.ReturnCode);
|
2014-04-09 07:52:24 +04:00
|
|
|
ret.cbAttrLen = cbAttrLen;
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_pack_get_attrib_return(smartcard, irp->output, &ret, call->dwAttrId);
|
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if (autoAllocate)
|
|
|
|
SCardFreeMemory(operation->hContext, ret.pbAttr);
|
|
|
|
else
|
|
|
|
free(ret.pbAttr);
|
|
|
|
return status;
|
2020-01-13 12:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_SetAttrib_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
Long_Return ret;
|
|
|
|
SetAttrib_Call* call = operation->call;
|
|
|
|
|
|
|
|
ret.ReturnCode =
|
|
|
|
SCardSetAttrib(operation->hCard, call->dwAttrId, call->pbAttr, call->cbAttrLen);
|
|
|
|
log_status_error(TAG, "SCardSetAttrib", ret.ReturnCode);
|
|
|
|
free(call->pbAttr);
|
|
|
|
smartcard_trace_long_return(smartcard, &ret, "SetAttrib");
|
|
|
|
|
2014-04-07 20:13:31 +04:00
|
|
|
return ret.ReturnCode;
|
2011-10-15 19:30:10 +04:00
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_AccessStartedEvent_Decode(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2011-10-15 19:30:10 +04:00
|
|
|
{
|
2015-06-30 18:42:01 +03:00
|
|
|
Long_Call* call;
|
2019-05-08 13:26:04 +03:00
|
|
|
IRP* irp;
|
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->call = call = calloc(1, sizeof(Long_Call));
|
2014-05-13 00:19:44 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
2014-04-07 18:59:13 +04:00
|
|
|
|
2013-09-12 14:18:35 +04:00
|
|
|
if (Stream_GetRemainingLength(irp->input) < 4)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "AccessStartedEvent is too short: %" PRIuz "",
|
2015-06-30 18:42:01 +03:00
|
|
|
Stream_GetRemainingLength(irp->input));
|
2013-09-12 14:18:35 +04:00
|
|
|
return SCARD_F_INTERNAL_ERROR;
|
|
|
|
}
|
2013-10-24 23:34:14 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
Stream_Read_INT32(irp->input, call->LongValue); /* Unused (4 bytes) */
|
2014-05-12 23:04:31 +04:00
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_AccessStartedEvent_Call(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2014-05-12 23:04:31 +04:00
|
|
|
{
|
2017-02-17 16:25:59 +03:00
|
|
|
LONG status = SCARD_S_SUCCESS;
|
2019-05-08 13:26:04 +03:00
|
|
|
WINPR_UNUSED(operation);
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2014-05-11 07:43:25 +04:00
|
|
|
if (!smartcard->StartedEvent)
|
|
|
|
smartcard->StartedEvent = SCardAccessStartedEvent();
|
|
|
|
|
|
|
|
if (!smartcard->StartedEvent)
|
2017-02-17 16:25:59 +03:00
|
|
|
status = SCARD_E_NO_SERVICE;
|
2014-04-07 18:59:13 +04:00
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
return status;
|
2011-10-15 19:30:10 +04:00
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_LocateCardsByATRA_Decode(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2014-11-10 00:42:35 +03:00
|
|
|
{
|
|
|
|
LONG status;
|
2015-06-30 18:42:01 +03:00
|
|
|
LocateCardsByATRA_Call* call;
|
2014-11-10 00:42:35 +03:00
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->call = call = calloc(1, sizeof(LocateCardsByATRA_Call));
|
2014-11-10 00:42:35 +03:00
|
|
|
|
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_unpack_locate_cards_by_atr_a_call(smartcard, irp->input, call);
|
|
|
|
|
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_LocateCardsByATRW_Decode(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
LocateCardsByATRW_Call* call;
|
|
|
|
IRP* irp = operation->irp;
|
|
|
|
operation->call = call = calloc(1, sizeof(LocateCardsByATRW_Call));
|
|
|
|
|
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
status = smartcard_unpack_locate_cards_by_atr_w_call(smartcard, irp->input, call);
|
|
|
|
|
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_ReadCacheA_Decode(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
ReadCacheA_Call* call;
|
|
|
|
IRP* irp = operation->irp;
|
|
|
|
operation->call = call = calloc(1, sizeof(ReadCacheA_Call));
|
|
|
|
|
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
status = smartcard_unpack_read_cache_a_call(smartcard, irp->input, call);
|
|
|
|
|
|
|
|
operation->hContext =
|
|
|
|
smartcard_scard_context_native_from_redir(smartcard, &(call->Common.hContext));
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_ReadCacheW_Decode(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
ReadCacheW_Call* call;
|
|
|
|
IRP* irp = operation->irp;
|
|
|
|
operation->call = call = calloc(1, sizeof(ReadCacheW_Call));
|
|
|
|
|
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
status = smartcard_unpack_read_cache_w_call(smartcard, irp->input, call);
|
|
|
|
|
|
|
|
operation->hContext =
|
|
|
|
smartcard_scard_context_native_from_redir(smartcard, &(call->Common.hContext));
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_WriteCacheA_Decode(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
WriteCacheA_Call* call;
|
|
|
|
IRP* irp = operation->irp;
|
|
|
|
operation->call = call = calloc(1, sizeof(WriteCacheA_Call));
|
|
|
|
|
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
status = smartcard_unpack_write_cache_a_call(smartcard, irp->input, call);
|
|
|
|
|
|
|
|
operation->hContext =
|
|
|
|
smartcard_scard_context_native_from_redir(smartcard, &(call->Common.hContext));
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_WriteCacheW_Decode(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
WriteCacheW_Call* call;
|
|
|
|
IRP* irp = operation->irp;
|
|
|
|
operation->call = call = calloc(1, sizeof(WriteCacheW_Call));
|
|
|
|
|
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
status = smartcard_unpack_write_cache_w_call(smartcard, irp->input, call);
|
|
|
|
|
|
|
|
operation->hContext =
|
|
|
|
smartcard_scard_context_native_from_redir(smartcard, &(call->Common.hContext));
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_GetTransmitCount_Decode(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
GetTransmitCount_Call* call;
|
|
|
|
IRP* irp = operation->irp;
|
|
|
|
operation->call = call = calloc(1, sizeof(GetTransmitCount_Call));
|
|
|
|
|
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
status = smartcard_unpack_get_transmit_count_call(smartcard, irp->input, call);
|
|
|
|
|
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_ReleaseStartedEvent_Decode(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
WINPR_UNUSED(smartcard);
|
|
|
|
WINPR_UNUSED(operation);
|
|
|
|
WLog_WARN(TAG, "According to [MS-RDPESC] 3.1.4 Message Processing Events and Sequencing Rules "
|
|
|
|
"SCARD_IOCTL_RELEASETARTEDEVENT is not supported");
|
|
|
|
return SCARD_E_UNSUPPORTED_FEATURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_GetReaderIcon_Decode(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
GetReaderIcon_Call* call;
|
|
|
|
IRP* irp = operation->irp;
|
|
|
|
operation->call = call = calloc(1, sizeof(GetReaderIcon_Call));
|
|
|
|
|
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
status = smartcard_unpack_get_reader_icon_call(smartcard, irp->input, call);
|
|
|
|
|
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG smartcard_GetDeviceTypeId_Decode(SMARTCARD_DEVICE* smartcard,
|
|
|
|
SMARTCARD_OPERATION* operation)
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
GetDeviceTypeId_Call* call;
|
|
|
|
IRP* irp = operation->irp;
|
|
|
|
operation->call = call = calloc(1, sizeof(GetDeviceTypeId_Call));
|
|
|
|
|
|
|
|
if (!call)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
status = smartcard_unpack_get_device_type_id_call(smartcard, irp->input, call);
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2014-11-10 00:42:35 +03:00
|
|
|
operation->hContext = smartcard_scard_context_native_from_redir(smartcard, &(call->hContext));
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
static LONG smartcard_LocateCardsByATRA_Call(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2014-11-10 00:42:35 +03:00
|
|
|
{
|
|
|
|
LONG status;
|
2015-01-19 20:04:23 +03:00
|
|
|
DWORD i, j, k;
|
2014-11-10 00:42:35 +03:00
|
|
|
GetStatusChange_Return ret;
|
2015-01-19 20:04:23 +03:00
|
|
|
LPSCARD_READERSTATEA state = NULL;
|
2014-11-10 00:42:35 +03:00
|
|
|
LPSCARD_READERSTATEA states = NULL;
|
|
|
|
IRP* irp = operation->irp;
|
2015-06-30 18:42:01 +03:00
|
|
|
LocateCardsByATRA_Call* call = operation->call;
|
2019-11-06 17:24:51 +03:00
|
|
|
states = (LPSCARD_READERSTATEA)calloc(call->cReaders, sizeof(SCARD_READERSTATEA));
|
2015-01-19 20:04:23 +03:00
|
|
|
|
|
|
|
if (!states)
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
for (i = 0; i < call->cReaders; i++)
|
2014-11-10 00:42:35 +03:00
|
|
|
{
|
2020-01-13 12:51:22 +03:00
|
|
|
states[i].szReader = (LPSTR)call->rgReaderStates[i].szReader;
|
2020-01-23 12:39:43 +03:00
|
|
|
states[i].dwCurrentState = call->rgReaderStates[i].dwCurrentState;
|
|
|
|
states[i].dwEventState = call->rgReaderStates[i].dwEventState;
|
|
|
|
states[i].cbAtr = call->rgReaderStates[i].cbAtr;
|
|
|
|
CopyMemory(&(states[i].rgbAtr), &(call->rgReaderStates[i].rgbAtr), 36);
|
2014-11-10 00:42:35 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
status = ret.ReturnCode =
|
|
|
|
SCardGetStatusChangeA(operation->hContext, 0x000001F4, states, call->cReaders);
|
2014-11-10 00:42:35 +03:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
log_status_error(TAG, "SCardGetStatusChangeA", status);
|
2014-11-10 00:42:35 +03:00
|
|
|
if (status && (status != SCARD_E_TIMEOUT) && (status != SCARD_E_CANCELLED))
|
|
|
|
{
|
2015-01-19 20:04:23 +03:00
|
|
|
call->cReaders = 0;
|
2014-11-10 00:42:35 +03:00
|
|
|
}
|
|
|
|
|
2015-01-19 20:04:23 +03:00
|
|
|
for (i = 0; i < call->cAtrs; i++)
|
2014-11-10 00:42:35 +03:00
|
|
|
{
|
2015-01-19 20:04:23 +03:00
|
|
|
for (j = 0; j < call->cReaders; j++)
|
2014-11-10 00:42:35 +03:00
|
|
|
{
|
2015-01-19 20:04:23 +03:00
|
|
|
for (k = 0; k < call->rgAtrMasks[i].cbAtr; k++)
|
2014-11-10 00:42:35 +03:00
|
|
|
{
|
2015-01-19 20:04:23 +03:00
|
|
|
if ((call->rgAtrMasks[i].rgbAtr[k] & call->rgAtrMasks[i].rgbMask[k]) !=
|
|
|
|
(states[j].rgbAtr[k] & call->rgAtrMasks[i].rgbMask[k]))
|
2014-11-10 00:42:35 +03:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2017-12-21 12:45:55 +03:00
|
|
|
states[j].dwEventState |= SCARD_STATE_ATRMATCH;
|
2014-11-10 00:42:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret.cReaders = call->cReaders;
|
2015-09-01 12:58:43 +03:00
|
|
|
ret.rgReaderStates = NULL;
|
2015-06-30 18:42:01 +03:00
|
|
|
|
2015-09-01 12:58:43 +03:00
|
|
|
if (ret.cReaders > 0)
|
2019-11-06 17:24:51 +03:00
|
|
|
ret.rgReaderStates = (ReaderState_Return*)calloc(ret.cReaders, sizeof(ReaderState_Return));
|
2014-11-10 00:42:35 +03:00
|
|
|
|
2015-01-19 20:04:23 +03:00
|
|
|
if (!ret.rgReaderStates)
|
2019-04-05 12:40:10 +03:00
|
|
|
{
|
|
|
|
free(states);
|
2015-01-19 20:04:23 +03:00
|
|
|
return STATUS_NO_MEMORY;
|
2019-04-05 12:40:10 +03:00
|
|
|
}
|
2015-01-19 20:04:23 +03:00
|
|
|
|
|
|
|
for (i = 0; i < ret.cReaders; i++)
|
2014-11-10 00:42:35 +03:00
|
|
|
{
|
2015-01-19 20:04:23 +03:00
|
|
|
state = &states[i];
|
|
|
|
ret.rgReaderStates[i].dwCurrentState = state->dwCurrentState;
|
|
|
|
ret.rgReaderStates[i].dwEventState = state->dwEventState;
|
|
|
|
ret.rgReaderStates[i].cbAtr = state->cbAtr;
|
2020-03-27 17:03:59 +03:00
|
|
|
CopyMemory(&(ret.rgReaderStates[i].rgbAtr), &(state->rgbAtr),
|
|
|
|
sizeof(ret.rgReaderStates[i].rgbAtr));
|
2014-11-10 00:42:35 +03:00
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
free(states);
|
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_pack_get_status_change_return(smartcard, irp->output, &ret, FALSE);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
2014-11-10 00:42:35 +03:00
|
|
|
return status;
|
|
|
|
|
|
|
|
if (call->rgReaderStates)
|
|
|
|
{
|
2015-01-19 20:04:23 +03:00
|
|
|
for (i = 0; i < call->cReaders; i++)
|
2014-11-10 00:42:35 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
state = (LPSCARD_READERSTATEA)&call->rgReaderStates[i];
|
2014-11-10 00:42:35 +03:00
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
if (state->szReader)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
free((void*)state->szReader);
|
2015-01-19 20:04:23 +03:00
|
|
|
state->szReader = NULL;
|
2014-11-10 00:42:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(call->rgReaderStates);
|
|
|
|
call->rgReaderStates = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(ret.rgReaderStates);
|
|
|
|
return ret.ReturnCode;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
LONG smartcard_irp_device_control_decode(SMARTCARD_DEVICE* smartcard,
|
2019-11-06 17:24:51 +03:00
|
|
|
SMARTCARD_OPERATION* operation)
|
2011-10-15 19:30:10 +04:00
|
|
|
{
|
2015-07-03 14:09:03 +03:00
|
|
|
LONG status;
|
2014-04-09 06:10:21 +04:00
|
|
|
UINT32 offset;
|
2014-04-06 00:06:46 +04:00
|
|
|
UINT32 ioControlCode;
|
2014-04-04 08:56:24 +04:00
|
|
|
UINT32 outputBufferLength;
|
|
|
|
UINT32 inputBufferLength;
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp = operation->irp;
|
2014-05-12 23:47:49 +04:00
|
|
|
|
2014-04-06 00:06:46 +04:00
|
|
|
/* Device Control Request */
|
2012-11-21 20:56:40 +04:00
|
|
|
|
2013-09-12 14:18:35 +04:00
|
|
|
if (Stream_GetRemainingLength(irp->input) < 32)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "Device Control Request is too short: %" PRIuz "",
|
2015-06-30 18:42:01 +03:00
|
|
|
Stream_GetRemainingLength(irp->input));
|
2014-05-12 23:04:31 +04:00
|
|
|
return SCARD_F_INTERNAL_ERROR;
|
2013-09-12 14:18:35 +04:00
|
|
|
}
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2014-04-04 08:56:24 +04:00
|
|
|
Stream_Read_UINT32(irp->input, outputBufferLength); /* OutputBufferLength (4 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT32(irp->input, inputBufferLength); /* InputBufferLength (4 bytes) */
|
|
|
|
Stream_Read_UINT32(irp->input, ioControlCode); /* IoControlCode (4 bytes) */
|
|
|
|
Stream_Seek(irp->input, 20); /* Padding (20 bytes) */
|
2014-05-12 23:47:49 +04:00
|
|
|
operation->ioControlCode = ioControlCode;
|
2014-05-12 23:22:57 +04:00
|
|
|
|
2014-04-06 00:06:46 +04:00
|
|
|
if (Stream_Length(irp->input) != (Stream_GetPosition(irp->input) + inputBufferLength))
|
2014-04-05 19:56:02 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "InputBufferLength mismatch: Actual: %" PRIuz " Expected: %" PRIuz "",
|
|
|
|
Stream_Length(irp->input), Stream_GetPosition(irp->input) + inputBufferLength);
|
2014-05-12 23:04:31 +04:00
|
|
|
return SCARD_F_INTERNAL_ERROR;
|
2014-04-05 19:56:02 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_DBG(TAG, "%s (0x%08" PRIX32 ") FileId: %" PRIu32 " CompletionId: %" PRIu32 "",
|
|
|
|
smartcard_get_ioctl_string(ioControlCode, TRUE), ioControlCode, irp->FileId,
|
|
|
|
irp->CompletionId);
|
2014-04-06 03:58:48 +04:00
|
|
|
|
2014-04-06 00:06:46 +04:00
|
|
|
if ((ioControlCode != SCARD_IOCTL_ACCESSSTARTEDEVENT) &&
|
2020-01-13 12:51:22 +03:00
|
|
|
(ioControlCode != SCARD_IOCTL_RELEASETARTEDEVENT))
|
2014-04-05 19:56:02 +04:00
|
|
|
{
|
2020-03-27 16:49:09 +03:00
|
|
|
status = smartcard_unpack_common_type_header(smartcard, irp->input);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
2014-04-05 19:56:02 +04:00
|
|
|
|
2020-03-27 16:49:09 +03:00
|
|
|
status = smartcard_unpack_private_type_header(smartcard, irp->input);
|
|
|
|
if (status != SCARD_S_SUCCESS)
|
2020-01-13 12:51:22 +03:00
|
|
|
return status;
|
2014-04-05 19:56:02 +04:00
|
|
|
}
|
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
/* Decode */
|
2015-06-30 18:42:01 +03:00
|
|
|
operation->call = NULL;
|
2014-05-12 23:04:31 +04:00
|
|
|
|
|
|
|
switch (ioControlCode)
|
|
|
|
{
|
|
|
|
case SCARD_IOCTL_ESTABLISHCONTEXT:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_EstablishContext_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_RELEASECONTEXT:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_ReleaseContext_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_ISVALIDCONTEXT:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_IsValidContext_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_LISTREADERGROUPSA:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_ListReaderGroupsA_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_LISTREADERGROUPSW:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_ListReaderGroupsW_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_LISTREADERSA:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_ListReadersA_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_LISTREADERSW:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_ListReadersW_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_INTRODUCEREADERGROUPA:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_context_and_string_a_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_INTRODUCEREADERGROUPW:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_context_and_string_w_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_FORGETREADERGROUPA:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_context_and_string_a_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_FORGETREADERGROUPW:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_context_and_string_w_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_INTRODUCEREADERA:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_context_and_two_strings_a_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_INTRODUCEREADERW:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_context_and_two_strings_w_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_FORGETREADERA:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_context_and_string_a_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_FORGETREADERW:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_context_and_string_w_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_ADDREADERTOGROUPA:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_context_and_two_strings_a_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_ADDREADERTOGROUPW:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_context_and_two_strings_w_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_REMOVEREADERFROMGROUPA:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_context_and_two_strings_a_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_REMOVEREADERFROMGROUPW:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_context_and_two_strings_w_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_LOCATECARDSA:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_LocateCardsA_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_LOCATECARDSW:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_LocateCardsW_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_GETSTATUSCHANGEA:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_GetStatusChangeA_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_GETSTATUSCHANGEW:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_GetStatusChangeW_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_CANCEL:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_Cancel_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_CONNECTA:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_ConnectA_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_CONNECTW:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_ConnectW_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_RECONNECT:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_Reconnect_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_DISCONNECT:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_Disconnect_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_BEGINTRANSACTION:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_BeginTransaction_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_ENDTRANSACTION:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_EndTransaction_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_STATE:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_State_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_STATUSA:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_StatusA_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_STATUSW:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_StatusW_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_TRANSMIT:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_Transmit_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_CONTROL:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_Control_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_GETATTRIB:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_GetAttrib_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_SETATTRIB:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_SetAttrib_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_ACCESSSTARTEDEVENT:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_AccessStartedEvent_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_LOCATECARDSBYATRA:
|
2015-06-30 18:42:01 +03:00
|
|
|
status = smartcard_LocateCardsByATRA_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_LOCATECARDSBYATRW:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_LocateCardsByATRW_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_READCACHEA:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_ReadCacheA_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_READCACHEW:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_ReadCacheW_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_WRITECACHEA:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_WriteCacheA_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_WRITECACHEW:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_WriteCacheW_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_GETTRANSMITCOUNT:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_GetTransmitCount_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
case SCARD_IOCTL_RELEASETARTEDEVENT:
|
|
|
|
status = smartcard_ReleaseStartedEvent_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_GETREADERICON:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_GetReaderIcon_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
case SCARD_IOCTL_GETDEVICETYPEID:
|
2020-01-13 12:51:22 +03:00
|
|
|
status = smartcard_GetDeviceTypeId_Decode(smartcard, operation);
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
default:
|
2014-05-12 23:22:57 +04:00
|
|
|
status = SCARD_F_INTERNAL_ERROR;
|
2014-05-12 23:04:31 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-05-12 23:22:57 +04:00
|
|
|
if ((ioControlCode != SCARD_IOCTL_ACCESSSTARTEDEVENT) &&
|
2020-01-13 12:51:22 +03:00
|
|
|
(ioControlCode != SCARD_IOCTL_RELEASETARTEDEVENT))
|
2014-05-12 23:22:57 +04:00
|
|
|
{
|
|
|
|
offset = (RDPDR_DEVICE_IO_REQUEST_LENGTH + RDPDR_DEVICE_IO_CONTROL_REQ_HDR_LENGTH);
|
|
|
|
smartcard_unpack_read_size_align(smartcard, irp->input,
|
2015-06-30 18:42:01 +03:00
|
|
|
Stream_GetPosition(irp->input) - offset, 8);
|
2014-05-12 23:22:57 +04:00
|
|
|
}
|
|
|
|
|
2016-12-14 00:47:08 +03:00
|
|
|
if (Stream_GetPosition(irp->input) < Stream_Length(irp->input))
|
2014-05-12 23:22:57 +04:00
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
SIZE_T difference;
|
|
|
|
difference = Stream_Length(irp->input) - Stream_GetPosition(irp->input);
|
2015-06-30 18:42:01 +03:00
|
|
|
WLog_WARN(TAG,
|
2020-01-13 12:51:22 +03:00
|
|
|
"IRP was not fully parsed %s (%s [0x%08" PRIX32 "]): Actual: %" PRIuz
|
2019-11-06 17:24:51 +03:00
|
|
|
", Expected: %" PRIuz ", Difference: %" PRIuz "",
|
2020-01-13 12:51:22 +03:00
|
|
|
smartcard_get_ioctl_string(ioControlCode, TRUE),
|
|
|
|
smartcard_get_ioctl_string(ioControlCode, FALSE), ioControlCode,
|
2015-06-30 18:42:01 +03:00
|
|
|
Stream_GetPosition(irp->input), Stream_Length(irp->input), difference);
|
2014-08-18 19:23:03 +04:00
|
|
|
winpr_HexDump(TAG, WLOG_WARN, Stream_Pointer(irp->input), difference);
|
2014-05-12 23:22:57 +04:00
|
|
|
}
|
|
|
|
|
2016-12-14 00:47:08 +03:00
|
|
|
if (Stream_GetPosition(irp->input) > Stream_Length(irp->input))
|
2014-05-12 23:22:57 +04:00
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
SIZE_T difference;
|
|
|
|
difference = Stream_GetPosition(irp->input) - Stream_Length(irp->input);
|
2015-06-30 18:42:01 +03:00
|
|
|
WLog_WARN(TAG,
|
2019-11-06 17:24:51 +03:00
|
|
|
"IRP was parsed beyond its end %s (0x%08" PRIX32 "): Actual: %" PRIuz
|
|
|
|
", Expected: %" PRIuz ", Difference: %" PRIuz "",
|
2015-06-30 18:42:01 +03:00
|
|
|
smartcard_get_ioctl_string(ioControlCode, TRUE), ioControlCode,
|
|
|
|
Stream_GetPosition(irp->input), Stream_Length(irp->input), difference);
|
2014-05-12 23:22:57 +04:00
|
|
|
}
|
|
|
|
|
2014-05-12 23:04:31 +04:00
|
|
|
if (status != SCARD_S_SUCCESS)
|
2014-05-12 23:22:57 +04:00
|
|
|
{
|
2015-06-30 18:42:01 +03:00
|
|
|
free(operation->call);
|
|
|
|
operation->call = NULL;
|
2014-05-12 23:22:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-07-03 14:09:03 +03:00
|
|
|
LONG smartcard_irp_device_control_call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation)
|
2014-05-12 23:22:57 +04:00
|
|
|
{
|
2014-08-18 21:34:47 +04:00
|
|
|
IRP* irp;
|
2015-07-03 14:09:03 +03:00
|
|
|
LONG result;
|
2014-05-12 23:22:57 +04:00
|
|
|
UINT32 offset;
|
2014-05-12 23:47:49 +04:00
|
|
|
UINT32 ioControlCode;
|
2014-05-12 23:22:57 +04:00
|
|
|
UINT32 outputBufferLength;
|
|
|
|
UINT32 objectBufferLength;
|
2014-05-12 23:47:49 +04:00
|
|
|
irp = operation->irp;
|
|
|
|
ioControlCode = operation->ioControlCode;
|
2014-05-12 23:22:57 +04:00
|
|
|
/**
|
|
|
|
* [MS-RDPESC] 3.2.5.1: Sending Outgoing Messages:
|
|
|
|
* the output buffer length SHOULD be set to 2048
|
|
|
|
*
|
|
|
|
* Since it's a SHOULD and not a MUST, we don't care
|
|
|
|
* about it, but we still reserve at least 2048 bytes.
|
|
|
|
*/
|
2020-02-17 16:07:20 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(irp->output, 2048))
|
|
|
|
return SCARD_E_NO_MEMORY;
|
|
|
|
|
2014-05-12 23:22:57 +04:00
|
|
|
/* Device Control Response */
|
|
|
|
Stream_Seek_UINT32(irp->output); /* OutputBufferLength (4 bytes) */
|
|
|
|
Stream_Seek(irp->output, SMARTCARD_COMMON_TYPE_HEADER_LENGTH); /* CommonTypeHeader (8 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Seek(irp->output,
|
|
|
|
SMARTCARD_PRIVATE_TYPE_HEADER_LENGTH); /* PrivateTypeHeader (8 bytes) */
|
|
|
|
Stream_Seek_UINT32(irp->output); /* Result (4 bytes) */
|
2014-05-12 23:04:31 +04:00
|
|
|
|
|
|
|
/* Call */
|
|
|
|
|
2014-04-04 02:47:18 +04:00
|
|
|
switch (ioControlCode)
|
2011-10-15 19:30:10 +04:00
|
|
|
{
|
2014-04-04 02:47:18 +04:00
|
|
|
case SCARD_IOCTL_ESTABLISHCONTEXT:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_EstablishContext_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_RELEASECONTEXT:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_ReleaseContext_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 02:47:18 +04:00
|
|
|
case SCARD_IOCTL_ISVALIDCONTEXT:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_IsValidContext_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_LISTREADERGROUPSA:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_ListReaderGroupsA_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_LISTREADERGROUPSW:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_ListReaderGroupsW_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 02:47:18 +04:00
|
|
|
case SCARD_IOCTL_LISTREADERSA:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_ListReadersA_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 02:47:18 +04:00
|
|
|
case SCARD_IOCTL_LISTREADERSW:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_ListReadersW_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_INTRODUCEREADERGROUPA:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_IntroduceReaderGroupA_Call(smartcard, operation);
|
2014-04-04 21:57:28 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_INTRODUCEREADERGROUPW:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_IntroduceReaderGroupW_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_FORGETREADERGROUPA:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_ForgetReaderA_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_FORGETREADERGROUPW:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_ForgetReaderW_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_INTRODUCEREADERA:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_IntroduceReaderA_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_INTRODUCEREADERW:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_IntroduceReaderW_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_FORGETREADERA:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_ForgetReaderA_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_FORGETREADERW:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_ForgetReaderW_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_ADDREADERTOGROUPA:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_AddReaderToGroupA_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_ADDREADERTOGROUPW:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_AddReaderToGroupW_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_REMOVEREADERFROMGROUPA:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_RemoveReaderFromGroupA_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_REMOVEREADERFROMGROUPW:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_RemoveReaderFromGroupW_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_LOCATECARDSA:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_LocateCardsA_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_LOCATECARDSW:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_LocateCardsW_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 02:47:18 +04:00
|
|
|
case SCARD_IOCTL_GETSTATUSCHANGEA:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_GetStatusChangeA_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 02:47:18 +04:00
|
|
|
case SCARD_IOCTL_GETSTATUSCHANGEW:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_GetStatusChangeW_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2011-10-15 19:30:10 +04:00
|
|
|
case SCARD_IOCTL_CANCEL:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_Cancel_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 02:47:18 +04:00
|
|
|
case SCARD_IOCTL_CONNECTA:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_ConnectA_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 02:47:18 +04:00
|
|
|
case SCARD_IOCTL_CONNECTW:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_ConnectW_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2011-10-15 19:30:10 +04:00
|
|
|
case SCARD_IOCTL_RECONNECT:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_Reconnect_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2011-10-15 19:30:10 +04:00
|
|
|
case SCARD_IOCTL_DISCONNECT:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_Disconnect_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 02:47:18 +04:00
|
|
|
case SCARD_IOCTL_BEGINTRANSACTION:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_BeginTransaction_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 02:47:18 +04:00
|
|
|
case SCARD_IOCTL_ENDTRANSACTION:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_EndTransaction_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2011-10-15 19:30:10 +04:00
|
|
|
case SCARD_IOCTL_STATE:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_State_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 02:47:18 +04:00
|
|
|
case SCARD_IOCTL_STATUSA:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_StatusA_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 02:47:18 +04:00
|
|
|
case SCARD_IOCTL_STATUSW:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_StatusW_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2011-10-15 19:30:10 +04:00
|
|
|
case SCARD_IOCTL_TRANSMIT:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_Transmit_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2011-10-15 19:30:10 +04:00
|
|
|
case SCARD_IOCTL_CONTROL:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_Control_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2011-10-15 19:30:10 +04:00
|
|
|
case SCARD_IOCTL_GETATTRIB:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_GetAttrib_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_SETATTRIB:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_SetAttrib_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 02:47:18 +04:00
|
|
|
case SCARD_IOCTL_ACCESSSTARTEDEVENT:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_AccessStartedEvent_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 02:47:18 +04:00
|
|
|
case SCARD_IOCTL_LOCATECARDSBYATRA:
|
2015-06-30 18:42:01 +03:00
|
|
|
result = smartcard_LocateCardsByATRA_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-04 02:47:18 +04:00
|
|
|
case SCARD_IOCTL_LOCATECARDSBYATRW:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_LocateCardsW_Call(smartcard, operation);
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_READCACHEA:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_ReadCacheA_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_READCACHEW:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_ReadCacheW_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_WRITECACHEA:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_WriteCacheA_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_WRITECACHEW:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_WriteCacheW_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_GETTRANSMITCOUNT:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_GetTransmitCount_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2020-01-13 12:51:22 +03:00
|
|
|
case SCARD_IOCTL_RELEASETARTEDEVENT:
|
|
|
|
result = smartcard_ReleaseStartedEvent_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_GETREADERICON:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_GetReaderIcon_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-04-05 19:56:02 +04:00
|
|
|
case SCARD_IOCTL_GETDEVICETYPEID:
|
2020-01-13 12:51:22 +03:00
|
|
|
result = smartcard_GetDeviceTypeId_Call(smartcard, operation);
|
2014-04-05 19:56:02 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2011-10-15 19:30:10 +04:00
|
|
|
default:
|
2014-04-04 08:56:24 +04:00
|
|
|
result = STATUS_UNSUCCESSFUL;
|
2011-10-15 19:30:10 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-06-30 18:42:01 +03:00
|
|
|
free(operation->call);
|
|
|
|
operation->call = NULL;
|
2014-05-12 23:04:31 +04:00
|
|
|
|
2014-05-12 23:22:57 +04:00
|
|
|
/**
|
|
|
|
* [MS-RPCE] 2.2.6.3 Primitive Type Serialization
|
|
|
|
* The type MUST be aligned on an 8-byte boundary. If the size of the
|
|
|
|
* primitive type is not a multiple of 8 bytes, the data MUST be padded.
|
|
|
|
*/
|
|
|
|
|
2014-04-09 06:10:21 +04:00
|
|
|
if ((ioControlCode != SCARD_IOCTL_ACCESSSTARTEDEVENT) &&
|
2020-01-13 12:51:22 +03:00
|
|
|
(ioControlCode != SCARD_IOCTL_RELEASETARTEDEVENT))
|
2014-04-09 06:10:21 +04:00
|
|
|
{
|
2014-05-12 23:22:57 +04:00
|
|
|
offset = (RDPDR_DEVICE_IO_RESPONSE_LENGTH + RDPDR_DEVICE_IO_CONTROL_RSP_HDR_LENGTH);
|
2019-11-06 17:24:51 +03:00
|
|
|
smartcard_pack_write_size_align(smartcard, irp->output,
|
|
|
|
Stream_GetPosition(irp->output) - offset, 8);
|
2014-04-09 06:10:21 +04:00
|
|
|
}
|
|
|
|
|
2014-04-09 18:40:52 +04:00
|
|
|
if ((result != SCARD_S_SUCCESS) && (result != SCARD_E_TIMEOUT) &&
|
2020-04-20 14:42:02 +03:00
|
|
|
(result != SCARD_E_NO_READERS_AVAILABLE) && (result != SCARD_E_NO_SERVICE) &&
|
|
|
|
(result != SCARD_W_CACHE_ITEM_NOT_FOUND) && (result != SCARD_W_CACHE_ITEM_STALE))
|
2014-04-05 19:56:02 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "IRP failure: %s (0x%08" PRIX32 "), status: %s (0x%08" PRIX32 ")",
|
2015-06-30 18:42:01 +03:00
|
|
|
smartcard_get_ioctl_string(ioControlCode, TRUE), ioControlCode,
|
|
|
|
SCardGetErrorString(result), result);
|
2014-04-05 19:56:02 +04:00
|
|
|
}
|
2011-10-15 19:30:10 +04:00
|
|
|
|
2017-12-04 14:17:57 +03:00
|
|
|
irp->IoStatus = STATUS_SUCCESS;
|
2014-04-07 20:13:31 +04:00
|
|
|
|
2020-02-17 16:07:20 +03:00
|
|
|
if ((result & 0xC0000000L) == 0xC0000000L)
|
2014-04-07 20:13:31 +04:00
|
|
|
{
|
|
|
|
/* NTSTATUS error */
|
2015-07-03 14:09:03 +03:00
|
|
|
irp->IoStatus = (UINT32)result;
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "IRP failure: %s (0x%08" PRIX32 "), ntstatus: 0x%08" PRIX32 "",
|
2015-06-30 18:42:01 +03:00
|
|
|
smartcard_get_ioctl_string(ioControlCode, TRUE), ioControlCode, result);
|
2014-04-07 20:13:31 +04:00
|
|
|
}
|
|
|
|
|
2014-04-06 00:06:46 +04:00
|
|
|
Stream_SealLength(irp->output);
|
|
|
|
outputBufferLength = Stream_Length(irp->output) - RDPDR_DEVICE_IO_RESPONSE_LENGTH - 4;
|
|
|
|
objectBufferLength = outputBufferLength - RDPDR_DEVICE_IO_RESPONSE_LENGTH;
|
|
|
|
Stream_SetPosition(irp->output, RDPDR_DEVICE_IO_RESPONSE_LENGTH);
|
|
|
|
/* Device Control Response */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT32(irp->output, outputBufferLength); /* OutputBufferLength (4 bytes) */
|
2017-12-04 14:31:10 +03:00
|
|
|
smartcard_pack_common_type_header(smartcard, irp->output); /* CommonTypeHeader (8 bytes) */
|
2017-12-13 17:46:50 +03:00
|
|
|
smartcard_pack_private_type_header(smartcard, irp->output,
|
|
|
|
objectBufferLength); /* PrivateTypeHeader (8 bytes) */
|
2020-02-17 16:07:20 +03:00
|
|
|
Stream_Write_INT32(irp->output, result); /* Result (4 bytes) */
|
2014-04-06 00:06:46 +04:00
|
|
|
Stream_SetPosition(irp->output, Stream_Length(irp->output));
|
2014-05-12 23:04:31 +04:00
|
|
|
return SCARD_S_SUCCESS;
|
2011-10-15 19:30:10 +04:00
|
|
|
}
|