vadimgrn / usbip-win2

USB/IP Client for Windows
GNU General Public License v3.0
469 stars 40 forks source link
usb-over-ethernet usb-over-ip usb-over-network usb-to-ethernet usbip usbip-client usbip-linux usbip-win vhci virtual-usb-hub

USBip logo

latest release release date downloads commits since commit activity license

USB/IP Client for Windows

Requirements

Key features

Differences with cezanne/usbip-win

Build

Build Tools

Build Visual Studio solution

Setup USB/IP server on Ubuntu Linux

Setup USB/IP on Windows

Enable Windows Test Signing Mode

Install USB/IP

Use usbip.exe to attach remote device(s)

"%APPDIR%\usbip.exe" detach --all

"%APPDIR%\devnode.exe" remove %HWID% root rem pnputil.exe /remove-device /deviceid %HWID% /subtree

rem WARNING: use %%P and %%~nxP if you run this command in a .bat file FOR /f %P IN ('findstr /M /L %HWID% C:\WINDOWS\INF\oem*.inf') DO pnputil.exe /delete-driver %~nxP /uninstall

"%APPDIR%\classfilter.exe" uninstall "%APPDIR%\usbip2_filter.inf" DefaultUninstall.NTamd64 rd /S /Q "%APPDIR%"

### Disable Windows Test Signing Mode without removing USB/IP
- Can be useful if you want to temporary disable test signing
- After that, USBip will not work until the test signing will be reenabled
- **usbip2_filter driver must be disabled, otherwise all USB controllers/devices will not work**

devcon.exe classfilter usb upper !usbip2_filter bcdedit.exe /set testsigning off

- To enable it again

devcon.exe classfilter usb upper +usbip2_filter bcdedit.exe /set testsigning on

- If devcon.exe is not installed
  - Run regedit.exe
  - Open key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\\{36fc9e60-c465-11cf-8056-444553540000}
  - Remove ```usbip2_filter``` line from ```UpperFilters``` multi-string value to disable the driver
  - Add this line to enable the driver

## Obtaining USB/IP logs on Windows
- WPP Software Tracing is used
- Use the tools for software tracing, such as TraceView, Tracelog, Tracefmt, and Tracepdb to configure, start, and stop tracing sessions and to display and filter trace messages
- These tools are included in the [Windows Driver Kit](https://learn.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk#download-icon-step-3-install-windows-11-version-22h2-wdk)
- **Pick "Select Components/Program DataBase files" during USBip installation**
- Start log sessions for drivers (run commands as Administrator)

rem change to your WDK version set PATH=%PATH%;C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64

set NAME=usbip

tracelog.exe -stop %NAME%-flt tracelog.exe -stop %NAME%-ude

del /F %NAME%-. tracepdb.exe -f "C:\Program Files\USBip*.pdb" -s -p %TEMP%\%NAME%

tracelog.exe -start %NAME%-flt -guid #90c336ed-69fb-43d6-b800-1552d72d200b -f %NAME%-flt.etl -flag 0x3 -level 5 tracelog.exe -start %NAME%-ude -guid #ed18c9c5-8322-48ae-bf78-d01d898a1562 -f %NAME%-ude.etl -flag 0xF -level 5

- Reproduce the issue
- Stop log sessions and get plain text logs (run commands as Administrator)
- **If you copy commands to a .bat file, double '%' in TRACE_FORMAT_PREFIX**

rem change to your WDK version set PATH=%PATH%;C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64

set NAME=usbip set TRACE_FORMAT_PREFIX=[%9]%3!04x! %!LEVEL! %!FUNC!:

tracelog.exe -stop %NAME%-flt tracelog.exe -stop %NAME%-ude

tracefmt.exe -nosummary -p %TEMP%\%NAME% -o %NAME%-flt.txt %NAME%-flt.etl tracefmt.exe -nosummary -p %TEMP%\%NAME% -o %NAME%-ude.txt %NAME%-ude.etl

rem sed -i "s/TRACE_LEVEL_CRITICAL/CRT/;s/TRACE_LEVEL_ERROR/ERR/;s/TRACE_LEVEL_WARNING/WRN/;s/TRACE_LEVEL_INFORMATION/INF/;s/TRACE_LEVEL_VERBOSE/VRB/" %NAME%-.txt rem sed -i "s/`anonymous namespace':://" %NAME%-.txt rem del /F sed*


## Debugging [BSOD](https://en.wikipedia.org/wiki/Blue_screen_of_death)
- Enable kernel memory dump
  - Open "System Properties" dialog box
  - Select "Advanced" tab
  - Click on "Settings" in "Startup and Recovery"
  - "System failure", "Write debugging information", pick "Automatic Memory Dump" or "Kernel Memory Dump"
  - Check "Overwrite any existing file"
- Start WPP tracing session for drivers as described in the previous topic
- When BSOD has occured
  - Reboot PC if automatic reboot is not set
  - Run Windows debugger WinDbg.exe as Administrator
  - Press Ctrl+D to open crash dump in C:\Windows
  - Run following commands and copy the output

.sympath+ C:\Program Files\USBip !wmitrace.searchpath +%TEMP%\usbip !analyze -v !wdfkd.wdfsearchpath %TEMP%\USBip !wdfkd.wdfsettraceprefix [%9]%3!04x! %!LEVEL! %!FUNC!: !wdfkd.wdflogdump usbip2_ude -d !wdfkd.wdflogdump usbip2_ude -f


## Obtaining USB/IP log on Linux

sudo killall usbipd sudo modprobe -r usbip-host usbip-vudc vhci-hcd usbip-core sudo modprobe usbip-core usbip_debug_flag=0xFFFFFFFF sudo modprobe -a usbip-host usbip-vudc vhci-hcd sudo usbipd -D dmesg --follow | tee ~/usbip.log


## Testing the driver
- [Driver Verifier](https://docs.microsoft.com/en-us/windows-hardware/drivers/devtest/driver-verifier) is used for testing
- Run verifier.exe as Administrator
- Enable testing

verifier /rc 1 2 4 5 6 8 9 12 18 34 10 11 14 15 16 17 20 24 26 33 35 36 /driver usbip2_filter.sys usbip2_ude.sys

- Be aware that rule class 26 "Code integrity checking" forces to use NonPagedPoolNx instead of NonPagedPool
- Query driver statistics

verifier /query

- Disable testing

verifier /reset


- To run Static Driver Verifier, set "Treat Warnings As Errors" to "No" for libdrv, usbip2_filter, usbip2_ude projects

### If you like this project
<a href="https://www.buymeacoffee.com/usbip" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-blue.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>