Author Topic: winusb as a filter for umdf driver  (Read 17606 times)

ph0en1x3

  • Member
  • ***
  • Posts: 4
winusb as a filter for umdf driver
« on: November 29, 2010, 03:16:04 pm »
I am looking for more information on how winusb is used as a filter for a umdf driver project.    I downloaded the c# winusb application and the pinvoke command WinUsb_Initialize fails to populate the endpoints even though the device is detected and I have the handle.

Here is the inf file I used for the usb driver installation;

;
; WUDFOsrUsbFx2.inf - Install the OSR USB user-mode driver
;

[Version]
Signature="$Windows NT$"
Class=Sample
ClassGuid={78A1C341-4539-11d3-B88D-00C04FAD5171}
Provider=%MSFTUMDF%
DriverVer=11/26/2010,6.1.7600.16396
CatalogFile=wudf.cat

[Manufacturer]
%MSFTUMDF%=Microsoft,NTx86

[Microsoft.NTx86]
%OsrUsbDeviceName%=OsrUsb_Install, USB\Vid_045e&Pid_94aa&mi_00
%OsrUsbDeviceName%=OsrUsb_Install, USB\VID_0547&PID_1002

[ClassInstall32]
AddReg=SampleClass_RegistryAdd

[SampleClass_RegistryAdd]
HKR,,,,%ClassName%
HKR,,Icon,,"-10"

[SourceDisksFiles]
WUDFOsrUsbFx2.dll=1
WudfUpdate_01009.dll=1
WdfCoInstaller01009.dll=1
WinUsbCoinstaller2.dll=1

[SourceDisksNames]
1 = %MediaDescription%

; =================== UMDF OsrUsb Device ==================================

[OsrUsb_Install.NT]
CopyFiles=UMDriverCopy
Include=WINUSB.INF                      ; Import sections from WINUSB.INF
Needs=WINUSB.NT                         ; Run the CopyFiles & AddReg directives for WinUsb.INF

[OsrUsb_Install.NT.hw]
AddReg=OsrUsb_Device_AddReg

[OsrUsb_Install.NT.Services]
AddService=WUDFRd,0x000001fa,WUDFRD_ServiceInstall  ; flag 0x2 sets this as the service for the device
AddService=WinUsb,0x000001f8,WinUsb_ServiceInstall  ; this service is installed because its a filter.

[OsrUsb_Install.NT.Wdf]
KmdfService=WINUSB, WinUsb_Install
UmdfDispatcher=WinUsb
UmdfService=WUDFOsrUsbFx2, WUDFOsrUsbFx2_Install
UmdfServiceOrder=WUDFOsrUsbFx2

[OsrUsb_Install.NT.CoInstallers]
AddReg=CoInstallers_AddReg
CopyFiles=CoInstallers_CopyFiles

[WinUsb_Install]
KmdfLibraryVersion = 1.9

[WUDFOsrUsbFx2_Install]
UmdfLibraryVersion=1.9.0
DriverCLSID = "{0865b2b0-6b73-428f-a3ea-2172832d6bfc}"
ServiceBinary = "%12%\UMDF\WUDFOsrUsbFx2.dll"

[OsrUsb_Device_AddReg]
HKR,,"LowerFilters",0x00010008,"WinUsb" ; FLG_ADDREG_TYPE_MULTI_SZ | FLG_ADDREG_APPEND

[WUDFRD_ServiceInstall]
DisplayName = %WudfRdDisplayName%
ServiceType = 1
StartType = 3
ErrorControl = 1
ServiceBinary = %12%\WUDFRd.sys
LoadOrderGroup = Base


[WinUsb_ServiceInstall]
DisplayName     = %WinUsb_SvcDesc%
ServiceType     = 1
StartType       = 3
ErrorControl    = 1
ServiceBinary   = %12%\WinUSB.sys

[CoInstallers_AddReg]
HKR,,CoInstallers32,0x00010000,"WudfUpdate_01009.dll", "WinUsbCoinstaller2.dll", "WdfCoInstaller01009.dll,WdfCoInstaller"

[CoInstallers_CopyFiles]
WudfUpdate_01009.dll
WdfCoInstaller01009.dll
WinUsbCoinstaller2.dll

[DestinationDirs]
UMDriverCopy=12,UMDF ; copy to driversMdf
CoInstallers_CopyFiles=11

[UMDriverCopy]
WUDFOsrUsbFx2.dll

; =================== Generic ==================================

[Strings]
MSFTUMDF="Microsoft Internal (WDF:UMDF)"
MediaDescription="Microsoft Sample Driver Installation Media"
ClassName="Sample Device"
WudfRdDisplayName="Windows Driver Foundation - User-mode Driver Framework Reflector"
OsrUsbDeviceName="UMDF Sample Driver for OSR USB Fx2 Learning Kit"
WinUsb_SvcDesc="WinUSB Driver"



and the accompanying winusb.inf
;
;   Microsoft WinUsb installation Inf File.
;   Modified by OSR to support the OSRFX2 Learning
;   kit device.
;
[Version]
Signature = "$Windows NT$"
Class = OsrWinUsbDeviceClass
ClassGuid={1D165DB4-107F-4547-AA0C-1736A55F240B}
Provider = %ProviderName%
;CatalogFile=OsrCatFile.cat

;
; Since our device is not a standard USB device, we
; need to define a new class for the device.
;
[ClassInstall32]
Addreg=OsrWinUsbClassReg

[OsrWinUsbClassReg]
HKR,,,0,%ClassName%
HKR,,Icon,,-1

;
; Define the Manufacturers (OSR) supported by this INF file
; and the device models supported.   This is where we tell
; it the VID and PID of our USB device and what platforms
; we support.
;
[Manufacturer]
%ProviderName% = OsrWinUsb_WinUSB,NTx86,NTamd64,NTia64

;
; The following lines would be modified with the VID and PID
; of the USB device that you want to communicate with via
; WinUSB
;   
[OsrWinUsb_WinUSB.NTx86]
%USB\OsrWinUsb.DeviceDesc% =USB_Install, USB\VID_0547&PID_1002

[OsrWinUsb_WinUSB.NTamd64]
%USB\OsrWinUsb.DeviceDesc% =USB_Install, USB\VID_0547&PID_1002

[OsrWinUsb_WinUSB.NTia64]
%USB\OsrWinUsb.DeviceDesc% =USB_Install, USB\VID_0547&PID_1002

;
; The following sections indicate what to install if our device
; is found.   The original MS INF file that we had installed
; KMDF Version 1.5.    We updated it to support Version 1.7.
;
; This points at the microsoft provided WinUSB.INF file. So
; Don't name your INF file winusb.inf...
;
[USB_Install]
Include=winusb.inf
Needs=WINUSB.NT

[USB_Install.Services]
Include=winusb.inf
AddService=WinUSB,0x00000002,WinUSB_ServiceInstall

[WinUSB_ServiceInstall]
DisplayName     = %WinUSB_SvcDesc%
ServiceType     = 1
StartType       = 3
ErrorControl    = 1
ServiceBinary   = %12%\WinUSB.sys

[USB_Install.Wdf]
KmdfService=WINUSB, WinUsb_Install
UmdfServiceOrder=WINUSB
[WinUSB_Install]
KmdfLibraryVersion=1.9

[USB_Install.HW]
AddReg=Dev_AddReg

;
; This is the interface GUID that your user mode program would use with
; the SetupDiXXX interface in order to find and enumerate your device.
; You should generate your own GUID for this, so that you don't conflict
; with another WinUSB user.
;
; Note, if your device is capable of waking the system or if you want
; DeviceIdle enabled, make user you uncomment out the keys below....
;
[Dev_AddReg]
HKR,,DeviceInterfaceGUIDs,0x10000,"{b35924d6-3e16-4a9e-9782-5524a4b79bac}"
;HKR,,"DeviceIdleEnabled",0x00010001,1
;HKR,,"SystemWakeEnabled",0x00010001,1

[USB_Install.CoInstallers]
AddReg=CoInstallers_AddReg
CopyFiles=CoInstallers_CopyFiles

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

[CoInstallers_CopyFiles]
WinUSBCoInstaller.dll
WdfCoInstaller01009.dll
WUDFUpdate_01009.dll

[DestinationDirs]
CoInstallers_CopyFiles=11

;
; Tell the installer where to get the software from.   Make sure you create a directory
; that has the INF file in the top level, with 3 subdirectories named I386,AMD64, and Ia64.
; These directories must contain the WdfCoInstaller01007.dll, WinUSBCoInstaller.dll and
; WUDFUpdate_01007.dll for each supported platform.   These redistributable binaries
; are available in the WDK (6001.180002).
;
[SourceDisksNames]
1 = %DISK_NAME%,,,\i386
2 = %DISK_NAME%,,,\amd64
3 = %DISK_NAME%,,,\ia64

[SourceDisksFiles.x86]
WinUSBCoInstaller.dll=1
WdfCoInstaller01009.dll=1

[SourceDisksFiles.NTamd64]
WinUSBCoInstaller.dll=2
WdfCoInstaller01009.dll=2

[SourceDisksFiles.ia64]
WinUSBCoInstaller.dll=3
WdfCoInstaller01009.dll=3

;
; The strings section contains the substitution strings used
; by this INF file.
;
[Strings]
ProviderName="Osr Fx2 WinUsbTest"
USB\OsrWinUsb.DeviceDesc="Test using WinUSB only"
WinUSB_SvcDesc="WinUSB Test"
DISK_NAME="Osr Install Disk"
ClassName="OsrWinUsbClass"



Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research

Tsuneo

  • Frequent Contributor
  • ****
  • Posts: 145
Re: winusb as a filter for umdf driver
« Reply #2 on: November 30, 2010, 01:40:14 am »
Hi ph0en1x3,

Microsoft calls both of the kernel mode driver (Winusb.sys) and user-mode DLL (Winusb.dll) as WinUSB. Maybe it makes you confused.

"WinUSB Architecture and Modules"
http://msdn.microsoft.com/en-us/library/ff540207(VS.85).aspx

You are going to apply the WinUSB user-mode DLL, WinUsb_Initialize(), to a UMDF driver (OSR FX2 driver). It can't. The user-mode DLL is designed to access just to the WinUSB kernel mode driver directly.

The UMDF driver sits upon WinUSB kernel mode driver. But it doesn't alter the access method from usual device driver.

- Find the device and get the device path using SetupDi APIs
- Open the device using CreateFile()
- Read / Write the device using ReadFile() / WriteFile()
- Send a device specific request over DeviceIoControl()
- Close the device with CloseHandle()

A C Application example for this UMDF is found in WinDDK
C:\WINDDK\7600.16385.1\src\usb\osrusbfx2\umdf\fx2_driver\exe\

You can apply a part of Jan's C# WinUSB example for the UMDF driver.
- from SetupDi APIs to CreateFile()/CloseHandle().
These procedures are common to most of device driver.

But for ReadFile() / WriteFile() / DeviceIoControl(), you have to write your own C# code. Jan's C# HID example may help you for the declaration of these WinAPI on C#.

Tsuneo