Smart Card, rejected IOCTL SET_PROTOCOL
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Smart Card, rejected IOCTL SET_PROTOCOL

Hybrid View

  1. #1
    Join Date
    Dec 2008
    Posts
    16

    Smart Card, rejected IOCTL SET_PROTOCOL

    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;
    }

  2. #2
    Join Date
    Mar 2009
    Posts
    1

    Re: Smart Card, rejected IOCTL SET_PROTOCOL

    Hi,

    there are a few things u need to do:

    1. you need to change CBPowerUpReader to return a ATR. After this, your CBSetProtoCol will be called.

    2. In your CBSetProtocol, please change the line
    pSmartcardExtension->ReaderCapabilities.CurrentState= SCARD_NEGOTIABLE;

    to:
    pSmartcardExtension->ReaderCapabilities.CurrentState = SCARD_SPECIFIC;
    inorder to handle C-APDU

    3. the name of the reader is merge by "vendor name"(smartcardExtension->VendorAttr.VendorName.Buffer) and "reader name"(smartcardExtension->VendorAttr.IfdType.Buffer), so i beleive you have set these 2 option to "MPICO" that why the application see "MPICO MPICO" reader. Regard to "1" u mentioned, it is true as the "DeviceInstanceNo" is first increment in driverAdd callback.

    Best Regards,
    cbm

  3. #3
    Join Date
    Dec 2008
    Posts
    16

    Re: Smart Card, rejected IOCTL SET_PROTOCOL

    Thanks for your answer, iv'e managed to fix the problem on my own.
    Generally driver works

    I have 1 question:

    The driver works only if i load(install) it with SCARD_PRESENT or above, i would like to load it with SCARD_ABSENT and then change it to present when a request to read a card comes from application.
    But i cant force a state change anywhere in the driver so i get "UNRESPONSIVE_CARD" from application.

    Problem is that i dont want COLD_RESET and atr read to occur until the user realy wants it (e. g. opens pc/sc application)

  4. #4
    Join Date
    Mar 2013
    Posts
    1

    Re: Smart Card, rejected IOCTL SET_PROTOCOL

    HELLO
    I have a problem I need help to program a device is a fingerprint reader-01R Motorola MC7XFPR I have the SDK but the problem is I can not program it or do not know how to make the recording of fingerprints and compararacion of them if they could support me thank you very much and I can say with whom I can contact me so I can support THANKS.

    Sincerely.
    Derick
    der8578

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center