WinUSB驱动

来源:互联网 发布:编程九九乘法表 编辑:程序博客网 时间:2024/05/21 08:30


WinUSB驱动  


|字号 订阅

; XXX USB Devices Driver

; Copyright (c) 2009, XXX company.

 

[Version]

Signature = "$Windows NT$"

Class = USB

ClassGuid={36fc9e60-c465-11cf-8056-444553540000}

Provider = %ProviderName%

DriverPackageDisplayName = %PackageDisplayName%

;CatalogFile=wudf.cat

CatalogFile.NTx86  = senx86.cat

CatalogFile.NTIA64 = senia64.cat

CatalogFile.NTAMD64 = senamd64.cat

DriverVer=09/01/2009,1.0.0.0

 

; ================== Class section ==================

 [ClassInstall32]

Addreg=MyDeviceClassReg

 [MyDeviceClassReg]

HKR,,,0,%ClassName%

HKR,,Icon,,-1

 ; ========== Manufacturer/Models sections ===========

 [Manufacturer]

%ProviderName% = MyDevice_WinUSB,NTx86,NTamd64,NTia64

 [MyDevice_WinUSB.NTx86]

%USB\MyDevice.DeviceDesc% =USB_Install, USB\VID_XXXX&PID_0101

 [MyDevice_WinUSB.NTamd64]

%USB\MyDevice.DeviceDesc% =USB_Install, USB\VID_XXXX&PID_0101

 [MyDevice_WinUSB.NTia64]

%USB\MyDevice.DeviceDesc% =USB_Install, USB\VID_XXXX&PID_0101

; =================== Installation ===================

 ;[1]

[USB_Install]

Include=winusb.inf

Needs=WINUSB.NT

 ;[2]

[USB_Install.Services]

Include=winusb.inf

AddService=WinUSB,0x00000002,WinUSB_ServiceInstall

 ;[3]

[WinUSB_ServiceInstall]

DisplayName     = %WinUSB_SvcDesc%

ServiceType     = 1

StartType       = 3

ErrorControl    = 1

ServiceBinary   = %12%\WinUSB.sys

 ;[4]

[USB_Install.Wdf]

KmdfService=WINUSB, WinUsb_Install

 [WinUSB_Install]

KmdfLibraryVersion=1.9

 ;[5]

[USB_Install.HW]

AddReg=Dev_AddReg

 [Dev_AddReg]

HKR,,DeviceInterfaceGUIDs,0x10000,"{8EA450C9-DA57-4973-8BF8-B21D59312345}"

;HKR,,"SystemWakeEnabled",0x00010001,1

HKR,,"DeviceIdleEnabled",0x00010001,1

HKR,,"DeviceIdleIgnoreWakeEnable",0x00010001,1

HKR,,"UserSetDeviceIdleEnabled",0x00010001,1

HKR,,"DefaultIdleState",0x00010001,0x1

HKR,,"DefaultIdleTimeout",0x00010001,500

 

;[6]

[USB_Install.CoInstallers]

AddReg=CoInstallers_AddReg

CopyFiles=CoInstallers_CopyFiles

 [CoInstallers_AddReg]

HKR,,CoInstallers32,0x00010000,"WinUSBCoInstaller2.dll","WdfCoInstaller01009.dll,WdfCoInstaller"

 [CoInstallers_CopyFiles]

WdfCoInstaller01009.dll

WinUSBCoInstaller2.dll

 [DestinationDirs]

CoInstallers_CopyFiles=11

 ; ================= Source Media Section =====================

;[7]

 [SourceDisksNames]

1 = %DISK_NAME%,,,\x86

2 = %DISK_NAME%,,,\amd64

3 = %DISK_NAME%,,,\ia64

 [SourceDisksFiles.x86]

WdfCoInstaller01009.dll=1

WinUSBCoInstaller2.dll=1

 [SourceDisksFiles.amd64]

WdfCoInstaller01009.dll=2

WinUSBCoInstaller2.dll=2

 [SourceDisksFiles.ia64]

WdfCoInstaller01009.dll=3

WinUSBCoInstaller2.dll=3

; =================== Strings ===================

 [Strings]

ProviderName="xxx provider"

PackageDisplayName="XXX USB Devices Driver"

USB\MyDevice.DeviceDesc="XXX SUB Devices"

WinUSB_SvcDesc="XXX USB Service"

DISK_NAME=" XXX USB Device Install Disk"

ClassName="xxx USB Devices"

 

1.注册表查看USB设备的信息:

Computer -> HKEY_LOCAL_MACHINE -> SYSTEM -> Enum -> USB -> 对应的VID_XXXX&PID_YYYY

2.想了解USB Driver, WinUSB 等相关知识,可参考http://www.lvr.com/usbcode.htm 该网站有源代码程序。

3. Q: How a host application read or write to USB device using WinUSB driver?
A: 如果使用WinUSB + UMDF, 使用 DeviceIoControl api (import kernel32.dll参考 http://www.pinvoke.net/default.aspx/kernel32/DeviceIoControl.html ), 如果仅使用 WinUSB, 则使用winusb.dll,参考http://www.lvr.com/usbcode.htm, 下为使用winusb.dll的例子:

[DllImport("winusb.dll", SetLastError = true)]

internal static extern Boolean WinUsb_Initialize(SafeFileHandle

DeviceHandle, ref IntPtr InterfaceHandle);

另注意HKR,,DeviceInterfaceGUIDs,0x10000,"{8EA450C9-DA57-4973-8BF8-B21D593A9116}"中的GUID,可以在host application中用来查找设备。这个GUID是由驱动开发者自定义的,如下所示,在可以在每个驱动版本中使用不同的GUID,以便区分。

// Guid for driver 5.0

DEFINE_GUID(GUID_INTERFACE_CP210x_50,

0xa2a39220, 0x39f4, 0x4b88, 0xae, 0xcb, 0x3d, 0x86, 0xa3, 0x5d, 0xc7, 0x48);

// Guid for driver 4.20 through 4.40

DEFINE_GUID(GUID_INTERFACE_CP210x_420_440,

0x993f7832, 0x6e2d, 0x4a0f, 0xb2, 0x72, 0xe2, 0xc7, 0x8e, 0x74, 0xf9, 0x3e);

// Guid for pre-4.20 driver, uncommon

DEFINE_GUID(GUID_INTERFACE_CP210x_410,

0xE4768D57, 0x352E, 0x4495, 0x88, 0x0C, 0x05, 0x6A, 0x7C, 0xB3, 0x46, 0x11);

// Guid for CP210x device programmed as USBXpress devices (uses USBXpress driver)

DEFINE_GUID(GUID_INTERFACE_USBXPRESS,

0x3c5e1462, 0x5695, 0x4e18, 0x87, 0x6b, 0xf3, 0xf3, 0xd0, 0x8a, 0xaf, 0x18);

4.Q: Selective suspend USB, 选择性挂起USB设备不工作?

首先确保使用的是WDDK 7600.16385.0,旧版本的WDDKselective suspend USB功能不工作。然后参考如下说明,有些USB hub并不支持selective suspend USB.

I have two PC.
One PC running Windows XP bought in 2006
The other one running Vista bought in 2008.
I install WinUSB (latest version from WinDDK 7600.16385.0) as my USB device 
driver in both PC. The idle timeout is 100 ms.
 
I plug in my USB device to Vista PC, it can selective suspend successfully, 
and read or write data is fine.
I plug in my USB device to XP PC, it cann't selective suspend, but read or 
write data is fine. If I disable the usb hub in Device Manager, it can 
suspend successfully (I think this is not selective suspend, this is global 
suspend). 
I plug in a high speed usb hub to XP PC, and then plug in my usb device to 
the high speed usb hub, it can selective suspend successfully, and read or 
write data is fine.
 
Conclusion: Some usb hub does not support selective suspend. I couldn't find 
out what kind of USB hub does not support selective suspend yet. But I would 
like to share what I already know.

 

5.Q: 如何签名 WinUSB驱动?

There is a Microsoft
document that shows what to do.

http://www.microsoft.com/whdc/connec...usb_howto.mspx

Basically, you have to write an .inf file for your device (N.B. there is an
error in the example .inf, [SourceDisksFiles.NTamd64] should read
[SourceDisksFiles.amd64])
Next, make a .cat file with the inf2cat utility from the DDK. (the document
says it is not in the DDK, but it is!)
Then sign this .cat file with the right certificate and include it in your
package.
There is a list with CA's from Microsoft for this purpose, with certificates
that ultimately link to the Microsoft CA. 
http://msdn.microsoft.com/en-us/library/ms995347.aspx
Comodo is not on the list, I chose the cheapest one, which was GlobalSign.

Afterwards, I found out that a fresh Vista x64 install from MSDN does not
contain the root GlobalSign certificate (only the one from Verisign, which
is the most expensive CA).
First I tried to install the GlobalSign certificate myself with a program,
but this would generate another warning, which defeats the idea of signing
to stop nasty warnings. I fixed this by running 'rootsupd.exe' from MS
Update. This works without warnings, but will sometimes trigger a UAC
warning in Vista. All in all, the system is not really waterproof in my
opinion. MS should of course include the root certificates that they advise
to use in every new installation, not just after running the right update!

 

 

检查*.inf文件语法: 新建CheckInf.bat文件,内容如下:

cd /d C:\WinDDK\7600.16385.0\tools\Chkinf
chkinf D:\Projects\Release\Driver\Driver_v1.0.1\Driver\OSWinUSB.inf /L D:\Projects\Release\Driver\log.txt /b

创建cat文件:新建Inf2Cat.bat,内容如下:

 cd /d C:\WinDDK\7600.16385.0\bin\selfsign
Inf2Cat /driver:D:\Projects\Release\Driver\Driver_v1.0.1\Driver /os:XP_X86,Vista_X86,7_X86
Inf2Cat /driver:D:\Projects\Release\Driver\Driver_v1.0.1\Driver /os:XP_X64,Vista_X64,7_X64

关于如何测试自签名的驱动请参考:

http://www.microsoft.com/whdc/driver/install/drvsign/kmcs-walkthrough.mspx

或者安装WinDDK后,搜索selfsign_example.cmd

原创粉丝点击