Usb热插拔

来自ling
跳转至: 导航搜索

[1]usb热插拔实现机制 C#实现USB插入检测,移除 C# 禁/启用USB接口源码 VC实现USB的禁用和启用 硬件设备的监控处理之三——(USB设备的禁用和启用) 程序实现启用/禁用设备(驱动)enable/disable device with windows api

启用禁用USB接口 启用禁用外网 SetupDi* 启用与停用设备 硬件检测:安装、停用

PnP 测试(设备基本测试)


C# 访问USB(HID)设备 c#收发数据给USB HID hid C#代码 Windows下开发HID设备主机程序流程 --HID上位机开发必备(自己总结)

USB 驱动程序堆栈体系结构

OwinSelfHost

[2] [3]

kestrel

[4]

原生命令

USB开发基础--USB命令(请求)和USB描述符 [5] usb热插拔的来龙去脉 LibUsbDotNet LibUsbDotNet使用例子 libusb的使用教程和例子


税局软件

URB

我们能够触发这个控制PIPE的命令吗 – URB_FUNCTION_ABORT_PIPE?

重置或者中断在某个端点的传输

URB_FUNCTION_RESET_PIPE
URB_FUNCTION_ABORT_PIPE
  • windows平台把跟USB接口的设备进行数据通讯统一使用URB数据包,每个包都指定一个Function功能号,
  • 也就是URB的功能种类。Function的种类大概有20多个,其实依然是从USB接口的四种通讯方式派生出来的,
  • 比如URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER 这个URB功能就是中断传输和批量传输的合并。
  • URB_FUNCTION_ISOCH_TRANSFER就是同步传输,
  • 而余下来的20多个 URB_FUNCTION_XXX可以完全理解成控制传输的某个命令。
  • 比如URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE就是控制传输中,从USB设备获取设备描述符。

最佳实践:使用 URB Windows-driver-samples URB structure

libusb阻塞

远程访问USB设备的驱动源代码工程 USB设备驱动开发之远程访问USB设备(一USB设备数据采集端) USB设备驱动开发之远程访问USB设备(二 USB设备虚拟端) USB设备驱动开发之远程访问USB设备( 三 虚拟USB控制器和根集线器)

利用USB虚拟总线驱动模拟USB摄像头的应用层例子代码工程

usb4java

http://usb4java.org/index.html

hid4java

https://github.com/gary-rowe/hid4java

hidapi

https://github.com/signal11/hidapi

将dll放到jdk bin目录下调用成功

税控钥匙描述信息

Bus 001 Device 030: ID 1ea8:c102
Connected to port: 1
Parent: Bus 001 Device 028: ID 05e3:0610
Device Descriptor:
  bLength                 18
  bDescriptorType          1
  bcdUSB                1.10
  bDeviceClass             0 Per Interface
  bDeviceSubClass          0
  bDeviceProtocol          0
  bMaxPacketSize0         64
  idVendor            0x1ea8
  idProduct           0xc102
  bcdDevice             1.00
  iManufacturer            1
  iProduct                 2
  iSerial                  0
  bNumConfigurations       1

Configuration Descriptor:
  bLength                  9
  bDescriptorType          2
  wTotalLength            41
  bNumInterfaces           1
  bConfigurationValue      1
  iConfiguration           1
  bmAttributes          0x80
    (Bus Powered)
  bMaxPower              100mA

Interface Descriptor:
  bLength                  9
  bDescriptorType          4
  bInterfaceNumber         0
  bAlternateSetting        0
  bNumEndpoints            2
  bInterfaceClass          3 HID
  bInterfaceSubClass       0
  bInterfaceProtocol       0
  iInterface               0

Endpoint Descriptor:
  bLength                  7
  bDescriptorType          5
  bEndpointAddress      0x02  EP 2 OUT
  bmAttributes             3
    Transfer Type             Interrupt
    Synch Type                None
    Usage Type                Data
  wMaxPacketSize          64
  bInterval               10

Endpoint Descriptor:
  bLength                  7
  bDescriptorType          5
  bEndpointAddress      0x81  EP 1 IN
  bmAttributes             3
    Transfer Type             Interrupt
    Synch Type                None
    Usage Type                Data
  wMaxPacketSize          64
  bInterval               10
    public final static short V_ID = 7848;//"0x1EA8"
    public final static short P_ID = -16126;//"0xC102"

 HIDDeviceInfo [path=\\?\hid#vid_1ea8&pid_c102#7&1d920223&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}, vendor_id=7848, product_id=49410, serial_number=null, release_number=256, manufacturer_string=ExcelSecu, product_string=USB Key, usage_page=65448, usage=0, interface_number=-1]

Windows平台的SDK、DDK与WDK

[6] [7]

Cfgmgr32

[DllImport("Cfgmgr32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int CM_Disable_DevNode(uint dnDevInst, CM_Disable_DevNode_FLAG ulFlags = CM_Disable_DevNode_FLAG.CM_DISABLE_POLITE);
[DllImport("Cfgmgr32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int CM_Enable_DevNode(uint dnDevInst, uint ulFlags = 0);

libusb

Installation Instructions (Windows)

  • Install libusb
    • Download the current libusb-Binaries from http://libusb.info
    • The current version of LibusbJava supports libusb-1.0.19 Windows Binaries Other Releases
    • Extract downloaded file
    • copy the corresponding libusb-1.0.dll (64-bit) into your System32 directory (C:\Windows\System32)
  • Install LibusbJava
    • If you like to use LibusbJava with the USB BDI for the MPC555 or a Atmel AT90USB1287, you may also download the NTB Windows Driver Package. It includes the necessary .inf-Files for WinUSB for this two types of Hardware and LibusbJava. **More information can be found here.
    • OR: Download latest Binaries
    • copy LibusbJava.jar to C:\Windows\Sun\Java\lib\ext
    • copy LibusbJava-1_1.dll and the MinGW C++ Standard Libraries (libgcc_s_seh-1.dll, libstdc++-6.dll, libwinpthread-1.dll) to C:\Windows\System32

Installation Instructions (Ubuntu 14.04 64 bit)

install libusb and the Java JDK: $ sudo apt-get update $ sudo apt-get install libusb-1.0-0-dev openjdk-7-jdk download LibusbJava: http://sourceforge.net/projects/libusbjava/ extract the archive and copy the file libLibusbJava-1_1.so to /usr/lib: $ sudo cp libLibusbJava-1_1.so /usr/lib/ copy the file LibusbJava.jar to /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/: $ sudo cp LibusbJava.jar /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/ create the file /etc/udev/rules.d/50-bdi.rules and write the following content to it: SUBSYSTEM=="usb", GROUP="plugdev", ATTRS{idVendor}=="8235", ATTRS{idProduct}=="0100" reload the udev rules: $ sudo udevadm control --reload-rules

usb结构

struct usb_device_descriptor {  
    __u8  bLength;//设备描述符的字节数大小,为0x12   
    __u8  bDescriptorType;//描述符类型编号,为0x01   
  
    __le16 bcdUSB;//USB版本号   
    __u8  bDeviceClass;//USB分配的设备类代码,0x01~0xfe为标准设备类,0xff为厂商自定义类型   
      
    //0x00不是在设备描述符中定义的,如HID   
    __u8  bDeviceSubClass;//usb分配的子类代码,同上,值由USB规定和分配的  
    __u8  bDeviceProtocol;//USB分配的设备协议代码,同上   
    __u8  bMaxPacketSize0;//端点0的最大包的大小   
    __le16 idVendor;//厂商编号   
    __le16 idProduct;//产品编号   
    __le16 bcdDevice;//设备出厂编号  
    __u8  iManufacturer;//描述厂商字符串的索引   
    __u8  iProduct;//描述产品字符串的索引  
    __u8  iSerialNumber;//描述设备序列号字符串的索引   
    __u8  bNumConfigurations;//可能的配置数量  
} __attribute__ ((packed));  
  
  
struct usb_config_descriptor {  
    __u8  bLength;//设备描述符的字节数大小,为0x12   
    __u8  bDescriptorType;//描述符类型编号,为0x01   
    __le16 wTotalLength;//配置所返回的所有数量的大小   
  
    __u8  bNumInterfaces;//此配置所支持的接口数量   
    __u8  bConfigurationValue;//Set_Configuration命令需要的参数值   
    __u8  iConfiguration;//描述该配置的字符串的索引值   
    __u8  bmAttributes;//供电模式的选择  
    __u8  bMaxPower;//设备从总线提取的最大电流   
} __attribute__ ((packed));  
  
struct usb_interface_descriptor {  
    __u8  bLength;//设备描述符的字节数大小,为0x12  
    __u8  bDescriptorType;//描述符类型编号,为0x01   
  
    __u8  bInterfaceNumber;//接口的编号   
    __u8  bAlternateSetting;//备用的接口描述符编号   
    __u8  bNumEndpoints;//该接口使用端点数,不包括端点0  
    __u8  bInterfaceClass;//接口类型   
    __u8  bInterfaceSubClass;//接口子类型  
    __u8  bInterfaceProtocol;//接口所遵循的协议   
    __u8  iInterface;//描述该接口的字符串索引值  
} __attribute__ ((packed));  
  
  
struct usb_endpoint_descriptor {  
    __u8  bLength;//设备描述符的字节数大小,为0x12   
    __u8  bDescriptorType;//描述符类型编号,为0x01   
  
    __u8  bEndpointAddress;//端点地址及输入输出属性   
    __u8  bmAttributes;//端点的传输类型属性   
    __le16 wMaxPacketSize;//端点收、发的最大包的大小  
    __u8  bInterval;//主机查询端点的时间间隔  
  
    /* NOTE:  these two are _only_ in audio endpoints. */  
    /* use USB_DT_ENDPOINT*_SIZE in bLength, not sizeof. */  
    __u8  bRefresh;  
    __u8  bSynchAddress;  
} __attribute__ ((packed));  
  
struct usb_string_descriptor {  
    __u8  bLength;//设备描述符的字节数大小,为0x12   
    __u8  bDescriptorType;//描述符类型编号,为0x01   
  
    __le16 wData[1];        /* UTF-16LE encoded */  
} __attribute__ ((packed));