Windows boot and driver loading..
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 29

Thread: Windows boot and driver loading..

  1. #1
    Join Date
    Dec 2008
    Posts
    16

    Windows boot and driver loading..

    Hi everyone.
    My smartcard driver works fine when fresh installed,
    but after windows reboot there aren't any actual readers availible in aplications for smart cards
    I have to uninstall and install the driver again after each reboot to see the reader in applications
    How is that possible and how to fix it?
    Lucas

  2. #2

    Re: Windows boot and driver loading..

    Hello,

    When the system is starting up, does the driverentry routine get called?
    If not, then it might be a registry problem (eg no entry in registry to load driver), if it does get called then it might be a problem with the set up of the driver in that driverentry routine.

    Hope this helps
    Peter

  3. #3
    Join Date
    Dec 2008
    Posts
    16

    Re: Windows boot and driver loading..

    Hi
    Dirverentry and EvtAddDevice are called when system is starting. And the driver is visible in device manager and there are no exclamation or question marks on the driver icon.

    I don't know where to seek the problem since everything is fine when driver is installed after system has booted.

    Lucas
    Last edited by hash3d; April 25th, 2009 at 01:50 AM.

  4. #4

    Re: Windows boot and driver loading..

    Hello,

    Has the SmartcardReader Interface been registered (After IoCreateDevice) using "IoRegisterDeviceInterface"?

    The interface guid "SmartCardReaderGuid" for the 2nd parameter of "IoRegisterDeviceInterface" is defined in "smclib.h"

    Peter

  5. #5
    Join Date
    Dec 2008
    Posts
    16

    Re: Windows boot and driver loading..

    Hello,
    Thanks for help so far

    Since this is KMDF driver in my EvtAddDevice i have

    Code:
    	WdfDeviceInitSetDeviceType(DeviceInit, FILE_DEVICE_SMARTCARD);
    
    	WdfDeviceInitSetIoType(DeviceInit, WdfDeviceIoBuffered);
    
    	WdfDeviceInitSetExclusive( DeviceInit, TRUE );
    
    	WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&fdoAttributes, DEVICE_EXTENSION);
    	fdoAttributes.EvtCleanupCallback = BtscEvtCleanupCallback;
    
    	WdfDeviceCreate(&DeviceInit, &fdoAttributes, &hDevice);  
    
    	WdfDeviceCreateDeviceInterface(hDevice, 
    				&SmartCardReaderGuid, 
    				NULL); // Reference string
    After that i fill SmartcardExtension structure and do
    SmartcardInitialize(SmartcardExtension);



    Only thing that comes into my mind is that since my driver is 'virtual' (by that i mean there's no physical hardware connected directly to my driver) i didn't implement any power or plug&play control into my driver and this could be the source of the problem. (and actually i don't know yet how to implement them properly)

    Other idea is that Windows loads my driver before Smart Card Resource Manager (or Smart Card Service) is started. But I don't have ANY clue how to correct this..


    Lucas
    Last edited by hash3d; April 26th, 2009 at 04:04 PM.

  6. #6

    Re: Windows boot and driver loading..

    Hi Lucas,

    So something important is happening on that fresh-install, but not on the reboot.
    How is the driver being installed? Is there any noticable difference in debugging output between install and reboot?

    Have you tried using the controlpanel Admin "Services" to stop and re-start the Smart Card Service?

    Doing the stop-start of the service wont fix the problem, but would be interesting to see what happens with your driver when it is done after the install (when driver is working) and also after reboot(when it is not working)

    Peter

  7. #7
    Join Date
    Dec 2008
    Posts
    16

    Re: Windows boot and driver loading..

    Hi Peter,

    Problem solved!

    I did the tests you suggested. The driver loading procedure at boot time was much shorter than on installation time.
    I searched for Smart Card service and noticed it was turned off. When i started it, the driver suddenly reacted and loaded completely.
    Then i ran my test application - the reader was visible on the reader list.

    I switched smart card service to start at boot - now it works perfectly fine

    So i was based on wrong assumption - that smart card service is always on (or any smart card reader driver installation turns it on permanently)

    But my driver only activated it on install, only once per install.

    I guess i have to make some changes in the INF file and it will be fine

    Thanks a lot, if it wasn't for this discussion I would be wondering for quite some time..

    Lucas

  8. #8

    Re: Windows boot and driver loading..

    Hi Lucas,

    Thats great news!

    Well done on getting the driver to work!

    Peter

  9. #9
    Join Date
    Jun 2009
    Posts
    13

    Re: Windows boot and driver loading..

    hi hash3d,
    i'm trying to develope a driver just like you did,could u send a copy of your source code to me?thank u so much!

  10. #10
    Join Date
    Jun 2009
    Posts
    13

    Re: Windows boot and driver loading..

    my email address: prisonbreakxl@163.com

  11. #11
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,947

    Re: Windows boot and driver loading..

    Don't post your email address. You'll get more spam in a week then you've had all your life!

    I doubt anyone is going to send you source code for any driver that is under development. You could ask him to post it here, and give it to the world...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  12. #12
    Join Date
    Jun 2009
    Posts
    13

    Re: Windows boot and driver loading..

    #pragma PAGEDCODE
    NTSTATUS SpenserCardAddDevice(IN PDRIVER_OBJECT DriverObject,
    IN PDEVICE_OBJECT PhysicalDeviceObject)
    {
    PAGED_CODE();
    KdPrint(("Enter SpenserCardAddDevice\n"));

    NTSTATUS status;
    PDEVICE_OBJECT fdo;
    UNICODE_STRING devName;
    PSMARTCARD_EXTENSION pSmartcardExtension;
    PREADER_EXTENSION ReaderExtension;
    RtlInitUnicodeString(&devName,L"\\Device\\MyWDMDevice");
    status = IoCreateDevice(
    DriverObject,
    sizeof(DEVICE_EXTENSION),
    &(UNICODE_STRING)devName,
    FILE_DEVICE_SMARTCARD,
    0,
    FALSE,
    &fdo);
    if( !NT_SUCCESS(status))
    return status;
    PDEVICE_EXTENSION pdx = (PDEVICE_EXTENSION)fdo->DeviceExtension;
    pdx->fdo = fdo;
    pSmartcardExtension = &pdx->SmartcardExtension;

    // allocate the reader extension
    ReaderExtension =(PREADER_EXTENSION)ExAllocatePool(
    NonPagedPool,
    sizeof( READER_EXTENSION )
    );

    if ( ReaderExtension == NULL ) {
    KdPrint((" allocate the reader failed\n"));
    }

    RtlZeroMemory( ReaderExtension, sizeof( READER_EXTENSION ));

    pSmartcardExtension->ReaderExtension = ReaderExtension;
    pSmartcardExtension->ReaderExtension->pDeviceExtension = pdx;
    pSmartcardExtension->Version = SMCLIB_VERSION;
    pSmartcardExtension->SmartcardRequest.BufferSize = MEMORY_BUF_SIZE;
    pSmartcardExtension->SmartcardReply.BufferSize = MEMORY_BUF_SIZE;

    pSmartcardExtension->ReaderFunction[RDF_CARD_POWER] = VdPowerReader;
    pSmartcardExtension->ReaderFunction[RDF_SET_PROTOCOL] = VdSetProtocol;
    pSmartcardExtension->ReaderFunction[RDF_TRANSMIT] = VdTransmit;
    pSmartcardExtension->ReaderFunction[RDF_CARD_TRACKING] = VdCardTracking;
    pSmartcardExtension->ReaderFunction[RDF_IOCTL_VENDOR] = VdVendorIOCTL;

    strcpy((char *)pSmartcardExtension->VendorAttr.VendorName.Buffer, (char *) "Spenser");
    pSmartcardExtension->VendorAttr.VendorName.Length =
    (USHORT) strlen((char*)pSmartcardExtension->VendorAttr.VendorName.Buffer);
    strcpy((char *)pSmartcardExtension->VendorAttr.IfdType.Buffer, (char *) "Card");
    pSmartcardExtension->VendorAttr.IfdType.Length =
    (USHORT)strlen((char *)pSmartcardExtension->VendorAttr.IfdType.Buffer);
    pSmartcardExtension->VendorAttr.UnitNo = 0;
    pSmartcardExtension->VendorAttr.IfdVersion.BuildNumber = 1;
    pSmartcardExtension->VendorAttr.IfdVersion.VersionMinor = 2;
    pSmartcardExtension->VendorAttr.IfdVersion.VersionMajor = 3;
    pSmartcardExtension->VendorAttr.IfdSerialNo.Length = 0;

    // Set the reader capabilities
    // Clk frequency in KHz encoded as little endian integer
    pSmartcardExtension->ReaderCapabilities.CLKFrequency.Default = 3571;
    pSmartcardExtension->ReaderCapabilities.CLKFrequency.Max = 93571;
    // 4000;
    pSmartcardExtension->ReaderCapabilities.DataRate.Default = 9600;
    pSmartcardExtension->ReaderCapabilities.DataRate.Max = 115200;// 10750;
    //dataRatesSupported[0];
    // reader could support higher data rates
    pSmartcardExtension->ReaderCapabilities.DataRatesSupported.List = dataRatesSupported;
    pSmartcardExtension->ReaderCapabilities.DataRatesSupported.Entries =
    sizeof(dataRatesSupported) / sizeof(dataRatesSupported[0]);
    pSmartcardExtension->ReaderCapabilities.MaxIFSD = 254;
    // This reader supports T0 and T1
    pSmartcardExtension->ReaderCapabilities.SupportedProtocols = SCARD_PROTOCOL_T0;
    //************************************************************************************
    //this place must be corrected ! I do not remember exactly what ATR reports, but later
    //any attempts to communicate with SC, using T1 protocol will be rejected by driver
    //************************************************************************************
    pSmartcardExtension->ReaderCapabilities.MechProperties = 0;
    pSmartcardExtension->ReaderCapabilities.Channel = 0;
    // Reader type
    pSmartcardExtension->ReaderCapabilities.ReaderType = SCARD_READER_TYPE_VENDOR;
    // Now setup information in our deviceExtension
    pSmartcardExtension->ReaderCapabilities.CurrentState = SCARD_ABSENT;

    status = SmartcardInitialize(pSmartcardExtension);

    if (status != STATUS_SUCCESS) {

    KdPrint(("SmartcardInitialize failed \n"));
    }
    pSmartcardExtension->OsData->DeviceObject = fdo;
    pdx->NextStackDevice = IoAttachDeviceToDeviceStack(fdo, PhysicalDeviceObject);
    UNICODE_STRING symLinkName;
    RtlInitUnicodeString(&symLinkName,L"\\DosDevices\\HelloWDM");

    pdx->ustrDeviceName = devName;
    pdx->ustrSymLinkName = symLinkName;
    status = IoCreateSymbolicLink(&(UNICODE_STRING)symLinkName,&(UNICODE_STRING)devName);



    if( !NT_SUCCESS(status))
    {
    KdPrint(("IoCreateSymbolicLink failed \n"));
    IoDeleteSymbolicLink(&pdx->ustrSymLinkName);
    status = IoCreateSymbolicLink(&symLinkName,&devName);
    if( !NT_SUCCESS(status))
    {
    return status;
    }
    }

    status = SmartcardCreateLink(&pdx->ustrSymLinkName, &devName);

    if( !NT_SUCCESS(status))
    {
    KdPrint(("SmartcardCreateLink failed \n"));
    }

    status = IoRegisterDeviceInterface(
    PhysicalDeviceObject,
    &GUID_DEVINTERFACE_SMART_CARD,
    NULL,
    &pdx->ustrDeviceName
    );

    //IoSetDeviceInterfaceState(&pdx->ustrSymLinkName,TRUE);
    if( !NT_SUCCESS(status))
    {
    KdPrint(("IoRegisterDeviceInterface failed \n"));
    }

    fdo->Flags |= DO_BUFFERED_IO | DO_POWER_PAGABLE;
    fdo->Flags &= ~DO_DEVICE_INITIALIZING;

    KdPrint(("Leave SpenserCardAddDevice\n"));
    return STATUS_SUCCESS;
    }

  13. #13
    Join Date
    Jun 2009
    Posts
    13

    Re: Windows boot and driver loading..

    i can find my device in the device manager,but scardlistreaders returns no reader found.
    my IRP_MN_START_DEVICE function did nothing but pringting some debug messages,is this the reason that the scardlistreader returns no reader? and i'm puzzled how to write a IRP_MN_START_DEVICE function?

  14. #14

    Re: Windows boot and driver loading..

    Hello Coslma,

    The first thing to check is that the SmartCard Service has been started - this is required to make sure that the reader device appears in the list of available smartcards - its not always set to be started on system boot.

    Under XP this can be done from the Services option of the Administrator Tools found in the Control Panel - look for "Smart Card"

    Peter

  15. #15
    Join Date
    Jun 2009
    Posts
    13

    Re: Windows boot and driver loading..

    Quote Originally Posted by PeterBritton View Post
    Hello Coslma,

    The first thing to check is that the SmartCard Service has been started - this is required to make sure that the reader device appears in the list of available smartcards - its not always set to be started on system boot.

    Under XP this can be done from the Services option of the Administrator Tools found in the Control Panel - look for "Smart Card"

    Peter
    thank u for your reply.i'm pretty sure that the smartcard service is runnning.

Page 1 of 2 12 LastLast

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