locked
USB Function Driver using WDK RRS feed

  • Question

  • Hi,

    I am trying to develop a function driver using WDK which will fit in with the existing implementation, where the buffer passed from user has the endpoint as the first ULONG of the buffer.

    I wrote the WDK driver based on the UsbSamp in the WDK 7.1 sources. The device has 3 bulk endpoints for passing different data. However, the driver fails to install, saying the driver is either corrupt or missing.

    Can a senior developer please point out all the steps I need to get this done, I have gone through two books on WDK, but they both follow one or the other samples from WDK and have not helped much.

    Regards,

    JV.

    Monday, September 19, 2011 3:38 PM

Answers

  • have you looked at winusb?  you can easily do this entirely within user mode using winusb.
    d -- This posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, September 19, 2011 4:19 PM

All replies

  • I have added my header file:

    typedef

    struct _DEVICE_CONTEXT

    {

    WDFUSBDEVICE UsbDevice;

    USB_DEVICE_DESCRIPTOR UsbDeviceDescriptor;

    PUSB_CONFIGURATION_DESCRIPTOR UsbConfigurationDescriptor;

    WDFUSBDEVICE WdfUsbTargetDevice;

    ULONG WaitWakeEnable;

    BOOLEAN IsDeviceHighSpeed;

    WDFUSBINTERFACE UsbInterface;

    UCHAR NumberConfiguredPipes;

    ULONG MaximumTransferSize;

    WDFUSBPIPE BulkWritePipe1;

    WDFUSBPIPE BulkReadPipe1;

    WDFUSBPIPE BulkReadPipe2;

    WDFUSBPIPE BulkReadPipe3;

    UCHAR CurrentSwitchState;

    ULONG UsbDeviceTraits;

    WDFMEMORY DeviceNameMemory;

    PCWSTR DeviceName;

    WDFMEMORY LocationMemory;

    PCWSTR Location;

    } DEVICE_CONTEXT, *PDEVICE_CONTEXT;

     

    //Create an accessor method with a specified name for the driver's object-specific context space

    WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DEVICE_CONTEXT, GetDeviceContext);

    FORCEINLINE GUID RequestToActivityId( __in WDFREQUEST Request)

    {

    GUID activity = {0};

    RtlCopyMemory(&activity, &Request,

    sizeof(WDFREQUEST));

     

    return activity;

    }

    FORCEINLINE GUID DeviceToActivityId( __in WDFDEVICE Device)

    {

    GUID activity = {0};

    RtlCopyMemory(&activity, &Device,

    sizeof(WDFDEVICE));

     

    return activity;

    }

    DRIVER_INITIALIZE DriverEntry;

    EVT_WDF_DRIVER_DEVICE_ADD EvtDriverDeviceAdd;

    EVT_WDF_DEVICE_PREPARE_HARDWARE EvtDevicePrepareHardware;

    EVT_WDF_DEVICE_D0_ENTRY EvtDeviceD0Entry;

    EVT_WDF_DEVICE_D0_EXIT EvtDeviceD0Exit;

    EVT_WDF_IO_QUEUE_IO_READ EvtBulkIoRead;

    EVT_WDF_IO_QUEUE_IO_WRITE EvtBulkIoWrite;

    EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL EvtIoDeviceControl;

    EVT_WDF_REQUEST_COMPLETION_ROUTINE EvtRequestReadCompletionRoutine;

    EVT_WDF_REQUEST_COMPLETION_ROUTINE EvtRequestWriteCompletionRoutine;

    EVT_WDF_IO_QUEUE_IO_STOP EvtBulkIoStop;

    __drv_requiresIRQL(PASSIVE_LEVEL) NTSTATUS SelectInterfaces(__in WDFDEVICE Device);

    __drv_requiresIRQL(PASSIVE_LEVEL) NTSTATUS USBDeviceSetPowerPolicy(__in WDFDEVICE Device);


    JV. ZZ Plural 9 Z Alhpa...err...what does Z stand for? Which One? Any one.
    Monday, September 19, 2011 3:45 PM
  • have you looked at winusb?  you can easily do this entirely within user mode using winusb.
    d -- This posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, September 19, 2011 4:19 PM
  • Yes I did, unfortunately this needs to tie in with the existing interface, which will not change...hence the requirement for a new function driver.


    JV. ZZ Plural 9 Z Alhpa...err...what does Z stand for? Which One? Any one.
    Monday, September 19, 2011 6:07 PM
  • Jitesh Varma wrote:
    >
    >I am trying to develop a function driver using WDK which will fit in
    >with the existing implementation, where the buffer passed from user
    >has the endpoint as the first ULONG of the buffer.
    >
    >I wrote the WDK driver based on the UsbSamp in the WDK 7.1 sources.
    >The device has 3 bulk endpoints for passing different data. However,
    >the driver fails to install, saying the driver is either corrupt or
    >missing.
     
    Well, is it?  How did you install the driver?  Did you have the binary in
    the same folder as the INF, or the appropriate subdirectory?  Are you
    testing on a 64-bit system?  If so, did you build a 64-bit driver?
    --
    Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.
     

    Tim Roberts, DDK MVP Providenza & Boekelheide, Inc.
    Tuesday, September 20, 2011 3:45 AM
  • The driver was installed fine, and yes, the binary is in the same folder as the INF. It is on a 32 bit system, it is supposed to be installed on 32 bit Win 7 and XP systems.
    JV. ZZ Plural 9 Z Alhpa...err...what does Z stand for? Which One? Any one.
    Tuesday, September 20, 2011 1:12 PM
  • Well no the driver wasn't installed fine. As per you "the driver fails to install, saying the driver is either corrupt or missing".

     

    You need to debug why the driver is "either corrupt or missing". This can happen if the driver has an unresolved external reference, and the depends.exe tool can be quite helpful in identifying this problem. Otherwise perhaps there is a mismatch between where you have identified the .sys file as being located and where it is actually located?



    Mark Roddy Windows Driver and OS consultant www.hollistech.com
    Wednesday, September 21, 2011 10:17 PM
  • Thanks Mark,

    Depends.exe shows WDFLDR.sys is missing on the system. Does this need to be packaged with the function driver for installation? This is a WinXP 32-bit system with WDK 7.1 installed. Shouldn't it already have WDFLDR.sys?

    How can I install WDFLDR.sys on this machine?

     


    JV. ZZ Plural 9 Z Alhpa...err...what does Z stand for? Which One? Any one.
    Thursday, September 22, 2011 2:31 PM
  • OK so it seems to be an error is the INF. Both WDFLDR.sys and wdf01000.sys are in the system32/drivers directory. The INF is based on the samples as well. Unless the samples are wrong, I don't know how to fix this, can anyone please have a look?

    ChkInf says its all hunky dory...Driver Verifier says the driver is fine.

    [Version]
    Signature="$Windows NT$"
    Class=USB
    ClassGUID={36fc9e60-c465-11cf-8056-444553540000}
    Provider=%DvmUsb.Provider%
    DriverVer=03/31/2011,1.0.0.1
    CatalogFile=DvmUsb.cat

    [SourceDisksNames]
    1 = %DvmUsb.DriverDiskName%

    [SourceDisksFiles]
    DvmUsb.sys = 1
    WdfCoInstaller01009.dll=1

    [DestinationDirs]
    DefaultDestDir = 12
    CoInstaller.CopyFiles = 11

    [Manufacturer]
    %DvmUsb.Manufacturer%=DvmUsb

    [DvmUsb]
    %DvmUsb.DeviceDesc%=DvmUsb.INSTALL, USB\VID_0404&PID_010a
    %DvmUsb.DeviceDesc%=DvmUsb.CoInstallers, USB\VID_0404&PID_010a

    [DvmUsb.INSTALL]
    CopyFiles=DvmUsb.CopyFile,CoInstaller.CopyFiles
    AddReg=DvmUsb.AddRegLoader
         
    [DvmUsb.AddRegLoader]
    HKR,,DevLoader,,*ntkern
    HKR,,NTMPDriver,,DvmUsb.sys

    [DvmUsb.INSTALL.Services]
    AddService = DvmUsb,0x00000002,DvmUsb.AddService,DvmUsb.EventLog

    [DvmUsb.AddService]
    DisplayName     = %DvmUsb.SrvName%
    Description = %DvmUsb.SrvDesc%
    ServiceType     = 1 ;%SERVICE_KERNEL_DRIVER%
    StartType       = 3 ;%SERVICE_DEMAND_START%
    ErrorControl    = 1 ;%SERVICE_ERROR_NORMAL%
    ServiceBinary   = %12%\DvmUsb.sys

    [DvmUsb.EventLog]
    AddReg=DvmUsb.AddEventLogReg

    [DvmUsb.AddEventLogReg]
    HKR,,EventMessageFile,0x00020000,"%%SystemRoot%%\System32\IoLogMsg.dll;%%SystemRoot%%\System32\drivers\DvmUsb.sys"
    HKR,,TypesSupported,0x00010001,7

    [DvmUsb.CopyFile]
    DvmUsb.sys

    [CoInstaller.CopyFiles]
    WdfCoInstaller01009.dll,,2

    [DvmUsb.CoInstallers]
    AddReg=CoInstaller_AddReg
    CopyFiles=CoInstaller.CopyFiles

    [SourceDisksFiles]
    WdfCoInstaller01009.dll=1 ; make sure the number matches with SourceDisksNames

    [CoInstaller_AddReg]
    HKR,,CoInstallers32,0x00010000, "WdfCoInstaller01009.dll,WdfCoInstaller"

    [DvmUsb.NT.Wdf]
    KmdfService = DvmUsb, DvmUsb.Wdfsect

    [DvmUsb.Wdfsect]
    KmdfLibraryVersion = 1.9

    [Strings]
    DvmUsb.Provider="DVM Corporation"
    NCR="DVM Corporation"
    DvmUsb.Manufacturer="DVM Corporation"
    DvmUsb.DeviceDesc="USB DVM"
    DvmUsb.DriverDiskName="USB Dvm Installation Diskette"
    DvmUsb.SrvName="UsbDvm"
    DvmUsb.SrvDesc="Provides access to the DVM Module"


    JV. ZZ Plural 9 Z Alhpa...err...what does Z stand for? Which One? Any one.
    Thursday, September 22, 2011 2:59 PM
  • No XP will not have the correct version of WDF installed unless a prior driver installed it. Installation of the WDK is not relevant. Did you include the wdfcoinstaller01009.dll with your driver package?
    Mark Roddy Windows Driver and OS consultant www.hollistech.com
    Thursday, September 22, 2011 3:21 PM
  • Yes the coinstaller is included in the driver package (WdfCoInstaller01009.dll). The systems32/drivers directory includes WDFLDR.sys and wdf01000.sys . INF attached below:

    [Version]
    Signature="$Windows NT$"
    Class=USB
    ClassGUID={36fc9e60-c465-11cf-8056-444553540000}
    Provider=%DvmUsb.Provider%
    DriverVer=03/31/2011,1.0.0.1
    CatalogFile=DvmUsb.cat

    [SourceDisksNames]
    1 = %DvmUsb.DriverDiskName%

    [SourceDisksFiles]
    DvmUsb.sys = 1
    WdfCoInstaller01009.dll=1

    [DestinationDirs]
    DefaultDestDir = 12
    CoInstaller.CopyFiles = 11

    [Manufacturer]
    %DvmUsb.Manufacturer%=DvmUsb

    [DvmUsb]
    %DvmUsb.DeviceDesc%=DvmUsb.INSTALL, USB\VID_0404&PID_010a
    %DvmUsb.DeviceDesc%=DvmUsb.CoInstallers, USB\VID_0404&PID_010a

    [DvmUsb.INSTALL]
    CopyFiles=DvmUsb.CopyFile,CoInstaller.CopyFiles
    AddReg=DvmUsb.AddRegLoader
         
    [DvmUsb.AddRegLoader]
    HKR,,DevLoader,,*ntkern
    HKR,,NTMPDriver,,DvmUsb.sys

    [DvmUsb.INSTALL.Services]
    AddService = DvmUsb,0x00000002,DvmUsb.AddService,DvmUsb.EventLog

    [DvmUsb.AddService]
    DisplayName     = %DvmUsb.SrvName%
    Description = %DvmUsb.SrvDesc%
    ServiceType     = 1 ;%SERVICE_KERNEL_DRIVER%
    StartType       = 3 ;%SERVICE_DEMAND_START%
    ErrorControl    = 1 ;%SERVICE_ERROR_NORMAL%
    ServiceBinary   = %12%\DvmUsb.sys

    [DvmUsb.EventLog]
    AddReg=DvmUsb.AddEventLogReg

    [DvmUsb.AddEventLogReg]
    HKR,,EventMessageFile,0x00020000,"%%SystemRoot%%\System32\IoLogMsg.dll;%%SystemRoot%%\System32\drivers\DvmUsb.sys"
    HKR,,TypesSupported,0x00010001,7

    [DvmUsb.CopyFile]
    DvmUsb.sys

    [CoInstaller.CopyFiles]
    WdfCoInstaller01009.dll,,2

    [DvmUsb.CoInstallers]
    AddReg=CoInstaller_AddReg
    CopyFiles=CoInstaller.CopyFiles

    [SourceDisksFiles]
    WdfCoInstaller01009.dll=1 ; make sure the number matches with SourceDisksNames

    [CoInstaller_AddReg]
    HKR,,CoInstallers32,0x00010000, "WdfCoInstaller01009.dll,WdfCoInstaller"

    [DvmUsb.NT.Wdf]
    KmdfService = DvmUsb, DvmUsb.Wdfsect

    [DvmUsb.Wdfsect]
    KmdfLibraryVersion = 1.9

    [Strings]
    DvmUsb.Provider="DVM Corporation"
    NCR="DVM Corporation"
    DvmUsb.Manufacturer="DVM Corporation"
    DvmUsb.DeviceDesc="USB DVM"
    DvmUsb.DriverDiskName="USB Dvm Installation Diskette"
    DvmUsb.SrvName="UsbDvm"
    DvmUsb.SrvDesc="Provides access to the DVM Module"


    JV. ZZ Plural 9 Z Alhpa...err...what does Z stand for? Which One? Any one.
    Thursday, September 22, 2011 3:45 PM
  • Jitesh Varma wrote:
    >
    >Depends.exe shows WDFLDR.sys is missing on the system.
     
    Depends.exe does not know how to check drivers.  It doesn't know that it's
    supposed to look in system32\drivers.
     
    You can extract useful information from depends, but you have to know what
    you are doing.
    --
    Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.
     

    Tim Roberts, DDK MVP Providenza & Boekelheide, Inc.
    Monday, September 26, 2011 4:28 AM