Skip to content

sreejithsin/USBShare

Repository files navigation

USBDeviceShare

USBDeviceShare allows USB devices physically attached to one Windows machine (the Server) to be accessed remotely from another Windows machine (the Client) over a local network or the internet. The remote machine sees the device as if it were directly plugged in — the original USB device driver loads and operates normally on the client side.

How It Works

[Server Machine]                          [Client Machine]
Physical USB Device                       App uses device normally
       │                                          │
  udsstub.sys                               udsbus.sys
 (stub/func driver)  ◄── TCP port 4540 ──► (virtual bus driver)
       │                                          │
  Server App (GUI)                         Client App (GUI)
  • Server side: When a device is shared, udsstub.sys is loaded over the physical USB device (replacing its original driver). It intercepts all USB requests (URBs) and forwards them to the server application, which ships them over TCP to the client.
  • Client side: udsbus.sys is a virtual bus driver that presents a virtual USB device to Windows. The original USB device driver installs and runs on top of this virtual device exactly as it would on real hardware. The client application receives URB packets from the server and writes them to the bus driver to complete the IRPs.
  • 32/64-bit interoperability: The server and client can be different architectures (x86/x64). The PacketTranslator component on the server translates URB structures between 32-bit and 64-bit pointer sizes transparently.

Features

  • Share any USB device class over TCP/IP (HID, mass storage, audio, serial, webcam, composite devices, etc.)
  • Works over LAN or internet
  • Server can initiate connection to client (callback mode), useful when client is behind NAT
  • IP filtering — allow or block connections by IP address / hostname
  • Password authentication for incoming connections
  • Auto-share devices on plug-in
  • Auto-start at Windows startup (tray mode)
  • Per-device sharing properties (nick name, auto-share, inactivity timeout, deny-share)
  • Device caching — remembers sharing preferences across restarts

Requirements

Build

  • Visual Studio 2012 (v110 toolset) — for the Server and Client GUI applications
  • Windows Driver Kit (WDK) — legacy build environment (build.exe) for the kernel drivers (udsbus.sys, udsstub.sys)
  • MFC (static linking, included with Visual Studio)

Runtime

  • Windows Vista or later (x86 or x64)
  • Administrative privileges required on both machines
  • Driver signing: drivers must be signed (or test-signing must be enabled on the target machine for development)

Building

1. Kernel Drivers

Open a WDK build environment command prompt and run from the repo root:

build.bat

This builds in order:

  1. lib/UsbLib.lib — shared URB serialization library
  2. bus/udsbus.sys — virtual bus driver (client side)
  3. func/udsstub.sys — USB stub/function driver (server side)

Or build each individually:

cd lib  && build -cz
cd bus  && build -cz
cd func && build -cz

2. GUI Applications

Open USBDeviceShare.sln in Visual Studio 2012 and build, or use MSBuild:

msbuild USBDeviceShare.sln /p:Configuration=Release /p:Platform=Win32
msbuild USBDeviceShare.sln /p:Configuration=Release /p:Platform=x64

Individual projects:

msbuild USBDeviceShare-Server\USBDeviceShare-Server.vcxproj /p:Configuration=Release /p:Platform=x64
msbuild USBDeviceShare-Client\USBDeviceShare-Client.vcxproj /p:Configuration=Release /p:Platform=x64

Available configurations: Debug|Win32, Release|Win32, Debug|x64, Release|x64

Installation

Server Machine (where USB devices are physically attached)

  1. Install the virtual bus driver on the client machine (see below) first.
  2. Copy udsstub.sys and ushare-stub.inf to a drivers\ folder alongside the server application.
  3. Run USBDeviceShare-Server.exe as Administrator.
  4. To share a device: select it in the list and click Share. The application will install udsstub.sys over the device's existing driver automatically.

Client Machine (where you want to use the device remotely)

  1. Install the virtual bus driver using Device Manager or pnputil:
    pnputil -i -a ushare-bus.inf
    
    Then add the root-enumerated device (requires a small enumerator tool or devcon):
    devcon install ushare-bus.inf root\udsbus
    
  2. Run USBDeviceShare-Client.exe as Administrator.
  3. Add the server's IP address or hostname, then connect to the shared device.

Project Structure

USBDeviceShare.sln          Master solution (all projects)
│
├── USBDeviceShare-Server/  Server GUI application (MFC)
│   ├── ServerFramework     Core: manages shared devices, connections, protocol dispatch
│   ├── LocalDevice         Per-device: loads stub driver, reads/writes URBs via IOCTL
│   ├── LocalDeviceManager  Enumerates physical USB devices via SetupAPI
│   ├── PacketTranslator    32↔64-bit URB structure conversion
│   ├── Protocol            Packet encoder/decoder (TCP, port 4540)
│   ├── NetworkManager      TCP socket wrapper
│   └── DeviceCache         Persists device sharing preferences
│
├── USBDeviceShare-Client/  Client GUI application (MFC)
│   ├── ClientFramework     Manages server connections and remote device list
│   └── LocalDevice         Per-device: plug-in/out virtual devices via bus IOCTL
│
├── bus/                    udsbus.sys — virtual bus driver (client side, WDM)
│   └── repeater.c          Core: shuttles URB packets between user-mode and PDO IRP queue
│
├── func/                   udsstub.sys — USB stub/function driver (server side, WDM)
│   └── ioctl.c             Exposes \\.\snusb device node; queues USB IRPs for user-mode pickup
│
├── lib/                    UsbLib.lib — shared kernel library
│   └── urbmanager.c        URB serialization/deserialization
│
├── inc/                    Shared headers
│   ├── public.h            IOCTL codes, bus plugin/unplug structures, GUIDs
│   └── ususb.h             Platform-neutral US32_URB / US64_URB structure definitions
│
└── inf/                    Copies of driver INF files for distribution

Architecture Notes

  • Communication protocol: All packets follow [ULONG packetSize][PACKET_TYPE][data] over a plain TCP stream. See USBDeviceShare-Server/Protocol.h for the full packet type enumeration and structures. Default port: 4540.
  • URB packet format: Defined in inc/ususb.h. Each IO_PACKET contains the URB header plus serialized URB contents. Transfer buffers are appended inline after the URB structure.
  • Driver IOCTLs:
    • Bus FDO (inc/public.h): IOCTL_BUSENUM_PLUGIN_HARDWARE, IOCTL_BUSENUM_UNPLUG_HARDWARE
    • Bus PDO (bus/repeater.h): IOCTL_BUSPDO_READ_PACKET, IOCTL_BUSPDO_WRITE_PACKET, IOCTL_BUSPDO_REGISTER_EVENTS
    • Stub driver (inc/public.h): IOCTL_USBFUNC_READ_PACKET, IOCTL_USBFUNC_WRITE_PACKET, IOCTL_USBFUNC_REGISTER_EVENTS
  • Driver names: udsbus.sys (bus, client side), udsstub.sys (stub, server side). Pool tag for both: UdsD ('dsdU').
  • The stub driver INF (ushare-stub.inf) covers all USB device classes (USB\Class_00 through USB\Class_ff and USB\COMPOSITE), so it can be installed over any USB device.

License

This project is licensed under the GNU General Public License v3.0 (GPL-3.0).

About

Share USB Devices over IP

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages