Hello, i've got 2 problems
My virtual smart card driver is unable to set protocol and send ATR
I would like to recieve ATR and some data from driver.
And my reader is some kind of "doubled": i shoud have "MPICO MPICO Reader 0" but i have "MPICO MPICO Reader 1" and when uninstalling i see a "null device" removal..
I use pscr example fromm Driver Kit as a base and i'm trying only to modify functions.
WinDBG logs:
Installing driver:
Code:
MPICO: DriverEntry: Enter - KMDF Version Built Jan 29 2009 09:54:25
MPICO: >> DeviceAdd
MPICO: << DeviceAdd with NTStatus 0x0
MPICO: >> EvtIoDeviceControl
MPICO: >> SmcLibComplete
MPICO: >> EvtIoDeviceControl
MPICO: IOCTL_SMARTCARD_GET_ATTRIBUTE
MPICO: >> SmcLibComplete
MPICO: >> EvtIoDeviceControl
ShimLib - MPICO: IOCTL_SMARTCARD_GET_ATTRIBUTE
MPICO: >> SmcLibComplete
MPICO: >> EvtIoDeviceControl
[Shim] AddProcessParametersFlags("20000")
(s: 0 0x63c.640 runonce.exe) USRK-[Wrn] xxxCreateDesktop: Object name exists MPICO: IOCTL_SMARTCARD_GET_ATTRIBUTE
MPICO: >> SmcLibComplete
SCardSvr!CalaisHandlerEx *WARNING* New device '\\?\ROOT#SMARTCARDREADER#0000#{50dd5230-ba8a-11d1-bf5d-0000f805f530}' added.
MPICO: >> EvtIoDeviceControl
MPICO: IOCTL_SMARTCARD_GET_ATTRIBUTE
MPICO: >> SmcLibComplete
MPICO: >> EvtIoDeviceControl
MPICO: IOCTL_SMARTCARD_GET_ATTRIBUTE
MPICO: >> SmcLibComplete
MPICO: >> EvtIoDeviceControl
MPICO: IOCTL_SMARTCARD_GET_STATE
MPICO: >> ReaderFunction[RDF_CARD_POWER]
MPICO: Request = ColdReset
MPICO: SCARD_COLD_RESET
MPICO: PowerUp, Current state 0x2
MPICO: pSmartcardExtension->IoRequest.ReplyBufferLength 0x24
MPICO: >> SmcLibComplete
MPICO: >> EvtIoDeviceControl
MPICO: IOCTL_SMARTCARD_POWER
MPICO: irp 8220D620
MPICO: POWER CODE - 7fff0002
MPICO: >> SmcLibComplete
MPICO: >> EvtIoDeviceControl
MPICO: >> SmcLibComplete
MPICO: >> EvtIoDeviceControl
MPICO: IOCTL_SMARTCARD_GET_STATE
MPICO: >> SmcLibComplete
MPICO: >> EvtIoDeviceControl
MPICO: IOCTL_SMARTCARD_GET_ATTRIBUTE
MPICO: >> ReaderFunction[RDF_CARD_TRACKING]
Executing "GetATR" Command:
Code:
(s: 0 0x660.670 EXPLORER.EXE) USRK-[Wrn=1400] ValidateHwnd: Invalid hwnd (0X000900F0)
w LinkInfo (d:\xpsprtm\shell\ext\brfcase\filesync\linkinfo\cnrlink.c line 675): GetNetType(): WNetGetResourceInformation() failed for CNR \\.host\mpico, returning 53.
(s: 0 0x4dc.508 mmc.exe) USER-[Wrn=1400] HMValidateHandle: Invalid:00000000 Type:0x1
(s: 0 0x4dc.508 mmc.exe) USER-[Wrn=1400] HMValidateHandle: Invalid:00000000 Type:0x1
(s: 0 0x550.4f8 APDU_Exchange.e) USRK-[Wrn] xxxCreateDesktop: Object name exists
MPICO: >> EvtIoDeviceControl
MPICO: IOCTL_SMARTCARD_IS_ABSENT
MPICO: >> ReaderFunction[RDF_CARD_POWER]
MPICO: Request = PowerDown
MPICO: SCARD_POWER_DOWN
MPICO: >> SmcLibComplete
w LinkInfo (d:\xpsprtm\shell\ext\brfcase\filesync\linkinfo\cnrlink.c line 675): GetNetType(): WNetGetResourceInformation() failed for CNR \\.host\mpico, returning 53.
MPICO: >> EvtIoDeviceControl
MPICO: IOCTL_SMARTCARD_POWER
MPICO: irp 82239338
MPICO: POWER CODE - 0
MPICO: >> SmcLibComplete
MPICO: >> EvtIoDeviceControl
MPICO: IOCTL_SMARTCARD_GET_STATE
MPICO: >> SmcLibComplete
MPICO: >> EvtIoDeviceControl
MPICO: IOCTL_SMARTCARD_GET_STATE
MPICO: >> SmcLibComplete
MPICO: >> EvtIoDeviceControl
MPICO: IOCTL_SMARTCARD_GET_ATTRIBUTE
MPICO: >> SmcLibComplete
MPICO: >> EvtIoDeviceControl
MPICO: IOCTL_SMARTCARD_GET_ATTRIBUTE
MPICO: >> SmcLibComplete
SCardSvr!CReaderDriver::SyncIoControl *ERROR* Smart Card Reader 'MPICO MPICO Reader 1' rejected IOCTL SET_PROTOCOL: The disk media is not recognized. It may not be formatted.
SCardSvr!CReaderDriver::Control *WARNING* Driver 'MPICO MPICO Reader 1' returned error code to control request: The disk media is not recognized. It may not be formatted.
MPICO: >> EvtIoDeviceControl
MPICO: IOCTL_SMARTCARD_SET_PROTOCOL
MPICO: >> SmcLibComplete
MPICO: >> EvtIoDeviceControl
MPICO: IOCTL_SMARTCARD_GET_STATE
MPICO: >> ReaderFunction[RDF_CARD_POWER]
MPICO: Request = PowerDown
MPICO: SCARD_POWER_DOWN
MPICO: >> SmcLibComplete
SCardSvr!CServiceThread::DoConnect *WARNING* Failed to Connect to reader
Uninstalling driver:
Code:
MPICO: >> EvtIoDeviceControl
MPICO: IOCTL_SMARTCARD_GET_STATE
MPICO: >> ReaderFunction[RDF_CARD_POWER]
MPICO: Request = PowerDown
MPICO: SCARD_POWER_DOWN
MPICO: >> SmcLibComplete
MPICO: >> EvtIoDeviceControl
MPICO: IOCTL_SMARTCARD_POWER
MPICO: irp 8202B2F8
MPICO: POWER CODE - 0
MPICO: >> SmcLibComplete
SCardSvr!CReader::PowerDown *WARNING* Reader 'MPICO MPICO Reader 1' won't change state!
MPICO: >> EvtIoCanceledOnQueue
SCardSvr!CReaderDriver::Disable *WARNING* Reader Driver Disable: Closing reader MPICO MPICO Reader 1
SCardSvr!CalaisHandlerEx *WARNING* Device '\\?\ROOT#SMARTCARDREADER#0000#{50dd5230-ba8a-11d1-bf5d-0000f805f530}' removal pending.
SCardSvr!CalaisHandlerEx *WARNING* Device '(null)' being removed.
MPICO: >> EvtCleanupCallback
MPICO: >> EvtCleanupCallback
MPICO: >> EvtDriverUnload
SCardSvr!CalaisHandlerEx *WARNING* Device '\\?\ROOT#SMARTCARDREADER#0000#{50dd5230-ba8a-11d1-bf5d-0000f805f530}' Removed.
SCardSvr!CalaisHandlerEx *WARNING* Device '(null)' being removed.
My SetProtocol, CardTracking functions:
Code:
NTSTATUS
CBSetProtocol(
PSMARTCARD_EXTENSION pSmartcardExtension
)
{
NTSTATUS NTStatus = STATUS_PENDING;
USHORT LibProtocol;
KdPrint((__DRIVER_NAME ">> ReaderFunction[RDF_SET_PROTOCOL]\n"));
if ((NTStatus = SmartcardAcquireRemoveLock(pSmartcardExtension)) != STATUS_SUCCESS)
{
KdPrint((__DRIVER_NAME ">> SmartcardAcquireRemoveLock failed\n"));
pSmartcardExtension->IoRequest.Information = 0;
// We should immediately return the control back, because the driver
// is about to unload.
}
else
{
// LibProtocol = (USHORT)(pSmartcardExtension->MinorIoControlCode);
// pSmartcardExtension->SmartcardRequest.BufferLength = 1;
// pSmartcardExtension->SmartcardReply.BufferLength = 0;
LibProtocol = SCARD_PROTOCOL_T0;
//pSmartcardExtension->CardCapabilities.Protocol.Supported = LibProtocol;
pSmartcardExtension->CardCapabilities.Protocol.Selected = LibProtocol;
*(PULONG)(pSmartcardExtension->IoRequest.ReplyBuffer) = LibProtocol;
pSmartcardExtension->ReaderCapabilities.CurrentState= SCARD_NEGOTIABLE;
*(pSmartcardExtension->IoRequest.Information) = sizeof(ULONG);
SmartcardReleaseRemoveLock(pSmartcardExtension);
}
return NTStatus;
}
Code:
NTSTATUS
CBCardTracking(
PSMARTCARD_EXTENSION SmartcardExtension
)
{
WDFREQUEST request;
PDEVICE_EXTENSION DeviceExtension;
NTSTATUS status;
KdPrint((__DRIVER_NAME ">> ReaderFunction[RDF_CARD_TRACKING]\n"));
request = GET_WDFREQUEST_FROM_IRP(SmartcardExtension->OsData->NotificationIrp);
DeviceExtension = GetDeviceExtension(WdfIoQueueGetDevice(WdfRequestGetIoQueue(request)));
IoMarkIrpPending(SmartcardExtension->OsData->NotificationIrp);
//
// Move the stack pointer back to where it was when the IRP
// was delivered to the driver. This compensates for the
// IoSetNextIrpStackLocation that we did when we presented the IRP
// to the smartcard libarary.
//
IoSkipCurrentIrpStackLocation(SmartcardExtension->OsData->NotificationIrp);
status = WdfRequestForwardToIoQueue(request,
DeviceExtension->NotificationQueue);
if (!NT_SUCCESS(status)) {
ASSERT(NT_SUCCESS(status));
InterlockedExchangePointer(
&(SmartcardExtension->OsData->NotificationIrp),
NULL
);
WdfRequestComplete(request, status);
}
status = STATUS_PENDING;
return status;
}