Adds host-device backends for the MS-RDPEUSB (URBDRC) client and wires
them into `ironrdp-client` and the viewer, so local USB devices can be
redirected to the server. On Windows it redirects USB the way mstsc
does, through the in-box RemoteFX USB drivers, when policy allows it,
and falls back to nusb otherwise. It also fixes three interop bugs in
`ironrdp-rdpeusb` found by redirecting a device to Windows Server 2025.
## Device coverage
- **Windows, with RemoteFX USB redirection allowed**: any device,
including HID, mass storage, smart card readers and cameras, through
`TsUsbFlt` and `TsUsbGD`, the drivers mstsc uses. Isochronous transfers
and the cancellation of a single request are supported. The
`fUsbRedirectionEnableMode` policy ("Allow RDP redirection of other
supported RemoteFX USB devices from this computer") decides who may
claim devices: nobody by default, elevated administrators, or every
user.
- **Windows, otherwise**, through [nusb](https://docs.rs/nusb): only
devices bound to WinUSB, or composite devices whose interfaces all use
WinUSB. Firmware that requests WinUSB works out of the box; other
devices need Zadig or similar.
- **Linux**, through nusb: broad. Kernel drivers are detached while the
device is redirected and reattached afterwards; the user needs udev
access to `/dev/bus/usb`.
- **macOS**, through nusb: only devices not claimed by a kernel or
system extension.
nusb was chosen for the portable backend because it's pure Rust and
supports hotplug on Windows, Linux and macOS. The full list of limits is
in `crates/ironrdp-rdpeusb-native/README.md`.
## Changes
- **New crate `ironrdp-rdpeusb-native`**, publishable like
`ironrdp-rdpeusb`. It implements `DeviceManagerBackend` and
`UrbdrcDeviceBackend`. Both backends share device selection,
announcement and unplug handling through a small `RedirectableDevice`
trait.
- **nusb backend** (all platforms):
- lists and filters devices, opens them and claims every interface
before announcing them to the server;
- translates control, bulk and interrupt URBs, plus feature, status,
descriptor, vendor/class and Microsoft OS descriptor requests;
- handles cancel, abort pipe and clear stall, configuration and
interface selection, port IOCTLs and device text;
- follows plug and unplug during the session, including devices
unplugged before their channel opens;
- rejects isochronous transfers packet by packet;
- bounds the data each device holds in flight (64 MiB) and each IN
transfer (16 MiB).
The translation code has no I/O and is unit-tested. Each device gets its
own worker thread with a single-threaded Tokio runtime and one ordered
queue per endpoint. nusb can only cancel a whole endpoint, so transfers
cancelled only because another request was cancelled resume where they
stopped.
- **RemoteFX USB backend** (Windows): claims the selected devices
through the hub filter's control object and finds them, re-enumerated
under the generic redirection driver, as interfaces of the
per-connection claim GUID.
- `TS_URB`s are re-encoded and submitted as overlapped I/O on a
completion port; the driver writes each `TS_URB_RESULT` over its
request.
- IO controls are forwarded, and a single request can be cancelled.
- A device is given back to its own driver when its channel closes, when
the server retracts it, or when the connection ends.
The driver interface is undocumented and was reverse-engineered from the
Windows 11 binaries.
- **Device selection**: FreeRDP `/usb` rules (`id:VID:PID#...`,
`addr:BUS:ADDR#...`, `auto`, `filter:CLASS#...` / `filter:none`) and the
`.rdp` `usbdevicestoredirect` property (`*`, `USB\VID_xxxx&PID_yyyy...`,
device instance IDs, `-` exclusions). `auto` and `*` keep audio, HID,
mass storage, hubs and smart cards local by default, as FreeRDP does.
Both backends select devices with the same rules.
- **`ironrdp-client`**: new `usb` feature, included in `all`, that
registers the URBDRC listener.
- Backend events go through the unbounded ordered queue the clipboard
already uses (`RdpInputSender::send_urbdrc`, new `RdpInputEvent::Urbdrc`
variant). The bounded input queue drops events when full, and a lost
completion would leave the server driver waiting forever.
- Events are scoped to their connection and device channel, so a
reconnection that reuses channel IDs never receives stale ones.
- USB redirection is suppressed when the RD Gateway's device-redirection
policy disables Plug and Play or all devices, over both the HTTP and
RPCH transports.
- New `ConfigBuilder::with_usb_redirection`. `usbdevicestoredirect` is
mapped in `with_property_set` through a new `ironrdp-cfg` accessor.
- The backend crate is re-exported as `ironrdp_client::usb`, and
`ironrdp` gains a `client-usb` feature.
- **`ironrdp-rdpeusb`** (client side):
- `CANCEL_REQUEST` keeps the request pending until the backend completes
it, so the server-side IRP finishes; FreeRDP does the same.
- `DeviceInfo::isochronous`: `ADD_DEVICE` advertises a nonzero no-ack
isochronous jitter buffer only when the backend performs isochronous
transfers.
- The listener takes the device before allocating its interface ID, so a
refused channel doesn't use one up.
- `TsUrbInPacket` and `TsUrbOutPacket` gain `encode_ts_urb` and
`decode_ts_urb_result`, for backends that hand `TS_URB`s to the
operating system as they are.
- Interop fixes found against Windows Server 2025:
- `REGISTER_REQUEST_CALLBACK` accepted only request completion interface
IDs of 4 or more, but Windows picks one below 4. The device channel
failed to decode and the whole session ended right after a device was
announced.
- Windows sends control requests without a data stage, including OUT
ones such as HID `SET_IDLE`, in `TRANSFER_IN_REQUEST` messages whose
flags keep the OUT direction. They were rejected when decoded and when
encoded. Bulk, interrupt and isochronous transfers are still checked.
- **`ironrdp-dvc`**: a client-initiated `DYNVC_CLOSE` now tolerates data
that races it, with bounded bookkeeping that keeps the close order and
lets a channel ID be reused. `close_channel_batch` returns the Soft-Sync
tunnel the channel used, so the close travels on it.
- **Viewer**: `--usb RULES`, repeatable, overrides the `.rdp` value.
`--usb list` prints the local devices with the values the rules match
against and, on Windows, each device's driver.
- **ActiveX**: `RedirectDevices` is left as `E_NOTIMPL`. It switches
Plug and Play device redirection (MS-RDPEPNP), not URBDRC.
## Testing
- `cargo xtask check fmt -v`, `cargo xtask check lints -v` and `cargo
xtask check locks -v` pass.
- Unit and integration tests pass:
- `ironrdp-rdpeusb-native` (57);
- `ironrdp-client` with all features (68);
- the rdpeusb/dvc suites in `ironrdp-testsuite-core` (144);
- the client config suite in `ironrdp-testsuite-extra` (70).
They cover URB translation, cancellation and resumed transfers,
select-configuration results, completion status and HRESULT, IOCTLs,
filter and `.rdp` parsing, the config and gateway policy mapping, the
RemoteFX USB request buffers and status mapping, and regression tests
for each interop fix.
- On Windows, `--usb list` enumerates the local devices.
- **Live, against Windows Server 2025**, with the RemoteFX USB backend
and the policy set to every user, repeated on this PR's head:
- A YubiKey 5 was claimed, redirected, and enumerated on the server with
its composite device, OTP keyboard, FIDO and CCID interfaces all OK.
- A CTAPHID `INIT` sent to its FIDO interface in the session got its
nonce echoed back, which exercises interrupt OUT and IN transfers end to
end.
- The session stayed up for about an hour, and the YubiKey went back to
its own drivers when the session ended.
- Unplugging the YubiKey during the session closed its device channel;
plugging it back in claimed it again on a new channel, and the CTAPHID
ping passed on the new device.
- The server needed the RD Session Host role and `fDisablePNPRedir = 0`
to offer URBDRC; it isn't offered in remote administration mode.
- With the nusb backend, URBDRC negotiates; no WinUSB device was
available to redirect.
- **Not verified**:
- a WinUSB device redirected through the nusb backend;
- smart card access in the session: the reader enumerates, but the
server's smart card service wasn't reachable;
- OTP keystrokes reach the server's console rather than the session, as
with mstsc.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
20 KiB
Architecture
This document describes the high-level architecture of IronRDP.
Roughly, it takes 2x more time to write a patch if you are unfamiliar with the project, but it takes 10x more time to figure out where you should change the code.
Code Map
This section talks briefly about various important directories and data structures.
Note also which crates are API Boundaries. Remember, rules at the boundary are different.
Core Tier
Set of foundational libraries for which strict quality standards must be observed. Note that all crates in this tier are API Boundaries. Pay attention to the "Architecture Invariant" sections.
Architectural Invariant: doing I/O is not allowed for these crates.
Architectural Invariant: all these crates must be fuzzed.
Architectural Invariant: must be #[no_std]-compatible (optionally using the alloc crate). Usage of the standard
library must be opt-in through a feature flag called std that is enabled by default. When the alloc crate is optional,
a feature flag called alloc must exist to enable its use.
Architectural Invariant: no platform-dependant code (#[cfg(windows)] and such).
Architectural Invariant: no non-essential dependency is allowed.
Architectural Invariant: no proc-macro dependency. Dependencies such as syn should be pushed
as far as possible from the foundational crates so it doesn’t become too much of a compilation
bottleneck. Compilation time is a multiplier for everything.
The paper Developer Productivity For Humans, Part 4: Build Latency, Predictability,
and Developer Productivity by Ciera Jaspan and Collin Green, Google
researchers, also elaborates on why it is important to keep build times low.
Architectural Invariant: unless the performance, usability or ergonomic gain is really worth it, the amount of monomorphization incurred in downstream user code should be minimal to avoid binary bloating and to keep the compilation as parallel as possible. Large generic functions should be avoided if possible.
crates/ironrdp
Meta crate re-exporting important crates.
Architectural Invariant: this crate re-exports other crates and does not provide anything else.
crates/ironrdp-core
Common traits and types.
This crate is motivated by the fact that only a few items are required to build most of the other crates such as the virtual channels.
To move up these crates up in the compilation tree, ironrdp-core must remain small, with very few dependencies.
It contains the most "low-context" building blocks.
Most notable traits are Decode and Encode which are used to define a common interface for PDU encoding and decoding.
These are object-safe, and must remain so.
Most notable types are ReadCursor, WriteCursor and WriteBuf which are used pervasively for encoding and decoding in a no-std manner.
crates/ironrdp-pdu
PDU encoding and decoding.
TODO: clean up the dependencies
crates/ironrdp-graphics
Image processing primitives.
TODO: break down into multiple smaller crates
TODO: clean up the dependencies
crates/ironrdp-svc
Traits to implement RDP static virtual channels.
crates/ironrdp-dvc
DRDYNVC static channel implementation and traits to implement dynamic virtual channels.
crates/ironrdp-cliprdr
CLIPRDR static channel for clipboard implemented as described in MS-RDPECLIP.
crates/ironrdp-rdpdr
RDPDR channel implementation.
crates/ironrdp-rdpsnd
Audio output channels (the static RDPSND channel and the AUDIO_PLAYBACK_DVC dynamic channels), wave codecs and a jitter-buffer policy, implemented as described in MS-RDPEA.
crates/ironrdp-egfx
EGFX dynamic channel implemented as described in MS-RDPEGFX.
crates/ironrdp-rdpeai
AUDIO_INPUT dynamic channel for client microphone capture implemented as described in MS-RDPEAI.
crates/ironrdp-rdpeusb
URBDRC dynamic channel state machines, PDU codecs, and USB device backend interfaces implemented as described in MS-RDPEUSB. The crate performs no USB I/O; host device access belongs to a backend.
crates/ironrdp-rdpecam
Video capture dynamic channel client and backend boundary implemented as described in MS-RDPECAM.
The crate performs no camera I/O and advertises only devices explicitly supplied by its caller.
The Windows Media Foundation capture backend lives in crates/ironrdp-rdpecam-native.
crates/ironrdp-egfx-native
Native H.264 decoders for the ironrdp-egfx decoder trait; on Windows, the Media Foundation decoder transform.
crates/ironrdp-rdpegt
Geometry tracking dynamic channel client and PDU codecs implemented as described in MS-RDPEGT.
crates/ironrdp-rdpevor
Video optimized remoting dynamic channel clients implemented as described in MS-RDPEVOR.
Its presenter decodes H.264 through the ironrdp-egfx decoder trait and places pictures with MS-RDPEGT geometry; it performs no I/O and takes time from a caller-supplied clock.
crates/ironrdp-rdpel
Location dynamic channel client and PDU codecs implemented as described in MS-RDPEL. The crate forwards only location data supplied by its caller and performs no location acquisition or I/O.
crates/ironrdp-rdpewa
RDPEWA dynamic virtual channel for WebAuthn redirection as described in MS-RDPEWA.
The Windows backend lives in crates/ironrdp-rdpewa-native.
crates/ironrdp-connector
State machines to drive an RDP connection sequence.
crates/ironrdp-session
State machines to drive an RDP session.
crates/ironrdp-input
Utilities to manage and build input packets.
crates/ironrdp-rdcleanpath
RDCleanPath PDU structure used by IronRDP web client and Devolutions Gateway.
crates/ironrdp-error
Lightweight and no_std-compatible generic Error and Report types.
The Error type wraps a custom consumer-defined type for domain-specific details (such as PduErrorKind).
crates/ironrdp-propertyset
The main type is PropertySet, a key-value store for configuration options.
crates/ironrdp-rdpfile
Loader and writer for the .RDP file format.
Extra Tier
Higher level libraries and binaries built on top of the core tier. Guidelines and constraints are relaxed to some extent.
crates/ironrdp-blocking
Blocking I/O abstraction wrapping the state machines conveniently.
This crate is an API Boundary.
crates/ironrdp-async
Provides Futures wrapping the state machines conveniently.
This crate is an API Boundary.
crates/ironrdp-tokio
Framed* traits implementation above tokio’s traits.
This crate is an API Boundary.
crates/ironrdp-futures
Framed* traits implementation above futures’s traits.
This crate is an API Boundary.
crates/ironrdp-tls
TLS boilerplate common with most IronRDP clients.
NOTE: it’s not yet clear if this crate is an API Boundary or an implementation detail for the native clients.
crates/ironrdp-client
Reusable client engine library: holds the Config/ConfigBuilder, the RdpClient runtime,
input/output event types, and the WebSocket transport. Consumed by ironrdp-viewer and any
other embedder (e.g. a headless agent).
crates/ironrdp-vmconnect
Hyper-V VM console front-end implementing the PCB → TLS → CredSSP → X.224 connection ordering.
This crate is an API Boundary, exposed directly through the ironrdp meta crate's optional
vmconnect feature and integrated into ironrdp-client through its optional vmconnect feature.
crates/ironrdp-viewer
Portable RDP client binary without GPU acceleration. A thin wrapper around ironrdp-client
that adds the winit/softbuffer GUI event loop, the clap CLI, the inquire prompts and the
.rdp file / PropertySet plumbing.
crates/ironrdp-daemon
Reusable persistent RDP-session support. It provides local RPC daemon lifecycle and
server handling, retained framebuffer, input and screenshot handling, session log buffering, NOW
endpoint management, and durable NOW operations. Its RPC schema and transport dependency is
ironrdp-rpc.
crates/ironrdp-rpc
Shared local RPC protocol and transport: typed request/response schema, binary codecs, framed
messages, Unix-domain-socket and Windows named-pipe transports. Used by ironrdp-daemon and its
local clients (ironrdp-agent, ironrdp-viewer, ironrdp-activex); both endpoints must use
compatible protocol versions.
crates/ironrdp-web
WebAssembly high-level bindings targeting web browsers.
This crate is an API Boundary (WASM module).
web-client/iron-remote-desktop
Protocol-agnostic web component and NPM package for remote desktop sessions.
Used by iron-svelte-client as a Web Component.
This crate is an API Boundary.
Architectural Invariant: iron-remote-desktop must remain completely agnostic of any specific
remote protocol (RDP, VNC, or otherwise). It defines the universal surface for features that are
meaningful regardless of the underlying protocol: keyboard and mouse input, canvas rendering,
clipboard text/binary transfer, resize, connection lifecycle, and cursor style.
A method belongs in the base API if either of the following is true:
- The web component itself needs to call it to implement transparent, protocol-independent
behaviour (e.g.,
supportsUnicodeKeyboardShortcuts()is called internally by the component to adapt keyboard handling, without consumer involvement). - The feature is universal — every reasonable remote protocol backend would implement it in a meaningful way (e.g., resize, clipboard text/binary, cursor style).
If neither applies, particularly if the method exposes protocol wire concepts such as PDU fields, lock IDs, stream IDs, or protocol-specific flags, it belongs in the backend and must be delivered via the extension mechanism.
The extension system works as follows:
Extensionis typed asunknown; intentionally opaque at this layer.- Backends define their own concrete
Extensiontypes and factory functions. - The consumer calls
userInteraction.configBuilder().withExtension(ext)oruserInteraction.invokeExtension(ext)at runtime. iron-remote-desktoppasses the value through to the backend without inspection.- The backend (e.g.,
iron-remote-desktop-rdp) interprets it meaningfully.
See web-client/iron-remote-desktop-rdp for a concrete
example: RDP-specific capabilities such as preConnectionBlob, displayControl, kdcProxyUrl,
and enableCredssp are all delivered as backend extensions, not as base API surface.
web-client/iron-remote-desktop-rdp
RDP backend for iron-remote-desktop. Implements RemoteDesktopModule using the WASM bindings
from ironrdp-web, and exposes RDP-specific Extension factory functions.
This crate is an API Boundary.
web-client/iron-svelte-client
Web-based frontend using Svelte and Material frameworks.
crates/ironrdp-cliprdr-native
Native CLIPRDR backend implementations.
crates/ironrdp-rdpeusb-native
nusb backend for the MS-RDPEUSB client, handling device selection, discovery, and USB I/O outside the session loop.
crates/ironrdp-client integrates it through its optional usb feature.
crates/ironrdp-cfg
IronRDP-related utilities for ironrdp-propertyset.
Internal Tier
Crates that are only used inside the IronRDP project, not meant to be published. This is mostly test case generators, fuzzing oracles, build tools, and so on.
Architecture Invariant: these crates are not, and will never be, an API Boundary.
crates/ironrdp-pdu-generators
proptest generators for ironrdp-pdu types.
crates/ironrdp-session-generators
proptest generators for ironrdp-session types.
crates/ironrdp-testsuite-core
Contains all integration tests for code living in the core tier, in a single binary, organized in modules.
Architectural Invariant: no dependency from another tier is allowed. It must be the case that compiling and running the core test suite does not require building any library from the extra tier. This is to keep iteration time short.
crates/ironrdp-testsuite-extra
Contains all integration tests for code living in the extra tier, in a single binary, organized in modules.
crates/ironrdp-fuzzing
Provides test case generators and oracles for use with fuzzing.
crates/ironrdp-capture-replay
Offline direct-TCP RDP capture analysis that routes recovered plaintext and exports payload-free replay diagnostics with rendered framebuffer snapshots.
fuzz
Fuzz targets for code in core tier.
xtask
IronRDP’s free-form automation using Rust code.
Community Tier
Crates provided and maintained by the community. Core maintainers will not invest a lot of time into these. One or several community maintainers are associated to each one.
The IronRDP team is happy to accept new crates but may not necessarily commit to keeping them working when changing foundational libraries. We promise to notify you if such a crate breaks, and will always try to fix things when it's a minor change.
crates/ironrdp-acceptor (@mihneabuz)
State machines to drive an RDP connection acceptance sequence
crates/ironrdp-server (@mihneabuz)
Extendable skeleton for implementing custom RDP servers.
crates/ironrdp-mstsgu (@steffengy)
Terminal Services Gateway Server Protocol implementation.
crates/ironrdp-glutin-renderer (no maintainer)
glutin primitives for OpenGL rendering.
crates/ironrdp-client-glutin (no maintainer)
GPU-accelerated RDP client using glutin.
crates/ironrdp-replay-client (no maintainer)
Utility tool to replay RDP graphics pipeline for debugging purposes.
Cross-Cutting Concerns
This section talks about the things which are everywhere and nowhere in particular.
General
- Dependency injection when runtime information is necessary in core tier crates (no system call such as
gethostname) - Keep non-portable code out of core tier crates
- Make crate
no_std-compatible wherever possible - Facilitate fuzzing
- In libraries, provide concrete error types either hand-crafted or using
thiserrorcrate - In binaries, use the convenient catch-all error type
anyhow::Error - Free-form automation a-la
makefollowingcargo xtaskspecification
Avoid I/O wherever possible
Architecture Invariant: core tier crates must never interact with the outside world. Only extra tier crates
such as ironrdp-client, ironrdp-web or ironrdp-async are allowed to do I/O.
Continuous integration
We use GitHub action and our workflows simply run cargo xtask.
The expectation is that, if cargo xtask ci passes locally, the CI will be green as well.
Architecture Invariant: cargo xtask ci and CI workflow must be logically equivalents. It must
be the case that a successful cargo xtask ci run implies a successful CI workflow run and vice versa.
MSRV policy
IronRDP libraries follow a conservative MSRV (Minimum Supported Rust Version) policy.
Definition: The MSRV is the oldest of:
- the latest stable Rust release that is at least 6 months old;
- the Rust version packaged by the latest Fedora stable release; or
- the Rust version available in Debian stable-backports.
Toolchain and CI: The Rust toolchain pinned in rust-toolchain.toml is both the project toolchain and the MSRV validated by CI.
The rust-version key in each published crate's Cargo.toml is kept in sync with this toolchain version.
The workspace is compiled once using the pinned toolchain to keep CI efficient; there are no separate CI jobs dedicated to validating older Rust versions.
Architecture Invariant: The MSRV is not validated by a separately configured toolchain or a dedicated CI job.
The pinned toolchain in rust-toolchain.toml serves as the single source of truth.
Bumping the MSRV: The MSRV may be bumped when:
- a dependency requires a newer version of Rust; or
- a newer Rust feature offers a clear maintenance, correctness, or performance benefit.
MSRV bumps must be documented in the release notes and must not occur in patch releases.
Testing
Test at the boundaries (test features, not code)
We should focus on testing the public API of libraries (keyword: API boundary).
That’s why most (if not all) tests should go into the ironrdp-testsuite-core and ironrdp-testsuite-extra crates.
Do not depend on external resources
Architecture Invariant: tests do not depend on any kind of external resources, they are perfectly reproducible.
Fuzzing
See fuzz/README.md.
Readability
Do not include huge binary chunks directly in source files (*.rs). Place these in separate files (*.bin, *.bmp)
and include them using macros such as include_bytes! or include_str!.
Use expect-test for snapshot testing
When comparing structured data (e.g.: error results, decoded PDUs), use expect-test. It is both easy to create
and maintain such tests. When something affecting the representation is changed, simply run the test again with
UPDATE_EXPECT=1 env variable to magically update the code.
See:
- https://matklad.github.io/2021/05/31/how-to-test.html#Expect-Tests
- https://docs.rs/expect-test/latest/expect_test/
TODO: take further inspiration from rust-analyzer
- https://github.com/rust-lang/rust-analyzer/blob/d7c99931d05e3723d878bea5dc26766791fa4e69/docs/dev/architecture.md#testing
- https://matklad.github.io/2021/05/31/how-to-test.html
Use rstest for fixture-based testing
When a test can be generalized for multiple inputs, use rstest to avoid code duplication.
Use proptest for property testing
It allows to test that certain properties of your code hold for arbitrary inputs, and if a failure is found, automatically finds the minimal test case to reproduce the problem.