diff --git a/crates/ironrdp-rdpeusb/src/pdu/sink.rs b/crates/ironrdp-rdpeusb/src/pdu/sink.rs index 49609bdfd..1d011ec9b 100644 --- a/crates/ironrdp-rdpeusb/src/pdu/sink.rs +++ b/crates/ironrdp-rdpeusb/src/pdu/sink.rs @@ -15,6 +15,7 @@ use ironrdp_dvc::DvcEncode; use ironrdp_pdu::utils::strict_sum; use ironrdp_str::multi_sz::MultiSzString; use ironrdp_str::prefixed::Cch32String; +use ironrdp_usb::UsbSpeed; use crate::pdu::header::{FunctionId, InterfaceId, Mask, MessageId, SharedMsgHeader}; @@ -410,6 +411,20 @@ impl DeviceSpeed { } } +impl From for UsbSpeed { + fn from(value: DeviceSpeed) -> Self { + // MS-RDPEUSB 2.2.11 defines only full speed (0) and high speed (1). + // To tolerate clients reporting newer USB speeds, unknown values deliberately fall back to High. + // This compatibility fallback does not identify the device's actual operating speed. + // UNTESTED: No test pins this mapping; when changing it, check full, high, and an unknown raw value. + if value == DeviceSpeed::FULL_SPEED { + Self::Full + } else { + Self::High + } + } +} + #[repr(transparent)] #[derive(Debug, PartialEq, Clone, Copy)] pub struct NoAckIsochWriteJitterBufSizeInMs(u32); diff --git a/crates/ironrdp-server/src/lib.rs b/crates/ironrdp-server/src/lib.rs index ef0f6ccf3..9d7aea117 100644 --- a/crates/ironrdp-server/src/lib.rs +++ b/crates/ironrdp-server/src/lib.rs @@ -47,7 +47,7 @@ pub use ironrdp_acceptor::{Acceptor, CredentialOrigin, CredsspAuthIdentity, Cred pub use ironrdp_pdu::rdp::server_error_info::ErrorInfo; pub use ironrdp_pdu::rdp::session_info::ServerAutoReconnect; #[cfg(feature = "usb")] -pub use ironrdp_rdpeusb::io::{CompletionData, DeviceAnnounce, DeviceText, InternalIoControlPacket}; +pub use ironrdp_rdpeusb::io::{CompletionData, DeviceText, InternalIoControlPacket}; pub use rdpdr::{NoopRdpdrServerBackend, RdpdrServerBackend, RdpdrServerFactory, RdpdrServerMessage}; pub use rdpeai::{NoopRdpeaiServerBackend, RdpeaiServerBackend, RdpeaiServerFactory, RdpeaiServerMessage}; pub use rdpei::{ @@ -77,8 +77,8 @@ pub use server::{SharedWriter, client_max_request_size, dispatch_static_channel_ pub use sound::{RdpsndServerHandler, RdpsndServerMessage, SoundServerFactory}; #[cfg(feature = "usb")] pub use urbdrc::{ - CompletionFut, DeviceFactory, PendingHandle, PendingRequest, RdpUsbDeviceAnnounceInfo, UsbDeviceHandle, - UsbRedirDevice, UsbRequestCompletion, + CompletionFut, DeviceFactory, PendingHandle, PendingRequest, RdpUsbDeviceAnnounceInfo, UsbDeviceAnnounce, + UsbDeviceHandle, UsbRedirDevice, UsbRequestCompletion, }; #[cfg(feature = "__bench")] pub mod bench { diff --git a/crates/ironrdp-server/src/urbdrc.rs b/crates/ironrdp-server/src/urbdrc.rs index d16c29508..c09e57450 100644 --- a/crates/ironrdp-server/src/urbdrc.rs +++ b/crates/ironrdp-server/src/urbdrc.rs @@ -23,7 +23,7 @@ use ironrdp_rdpeusb::{ server::{UrbdrcControlServerBackend, UrbdrcDeviceServerBackend}, }; use ironrdp_usb::{ - InterfaceSelection, TransferType, + InterfaceSelection, TransferType, UsbSpeed, control::GetDescriptorRequest, descriptor::{ConfigurationDescriptorSet, InterfaceDescriptor, ValidConfigurationDescriptorSet}, endpoint::EndpointAddress, @@ -1440,9 +1440,52 @@ pub trait UsbRedirDevice: Send { fn close(&mut self) {} } +/// A redirected USB device announced by the client in an [Add Device Message (ADD_DEVICE)][1]. +/// +/// [1]: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpeusb/a26bcb6d-d45d-48a9-b9bd-22e0107d8393 +#[derive(Debug, Clone)] +#[non_exhaustive] +pub struct UsbDeviceAnnounce { + /// Identity the client assigned to the redirected device. + /// + /// It is opaque to the server and stable for the lifetime of the device + /// channel, which makes it usable as a key for per-device state. + pub device_instance_id: String, + /// Device identifiers reported by the client, most specific first. + pub hw_ids: Vec, + /// Identifiers of the device classes the client reports the device is + /// compatible with, most specific first. + pub compat_ids: Vec, + /// Identifier shared by every function of the same physical device, which + /// groups the announcements of a composite device. + pub container_id: String, + /// Bus speed derived from the client's [USB_DEVICE_CAPABILITIES][1]. + /// + /// INVARIANT: `speed` is either [`UsbSpeed::High`] or [`UsbSpeed::Full`]. + /// MS-RDPEUSB defines only full speed (0) and high speed (1), with no separate low-speed encoding. + /// Unknown values map to [`UsbSpeed::High`] to tolerate clients reporting newer USB speeds. + /// This compatibility fallback does not identify the device's actual operating speed. + /// + /// [1]: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpeusb/98d4650e-b6d8-47e5-b71b-4d320ab542ee + pub speed: UsbSpeed, +} + +impl From for UsbDeviceAnnounce { + fn from(value: DeviceAnnounce) -> Self { + Self { + device_instance_id: value.device_instance_id, + hw_ids: value.hw_ids, + compat_ids: value.compat_ids, + container_id: value.container_id, + speed: value.usb_device_caps.device_speed.into(), + } + } +} + +/// A device announcement together with the handle which drives that device. #[derive(Debug)] pub struct RdpUsbDeviceAnnounceInfo { - pub announce: DeviceAnnounce, + pub announce: UsbDeviceAnnounce, pub usb_handle: UsbDeviceHandle, } @@ -1508,7 +1551,7 @@ impl UsbRedirServer { impl UrbdrcDeviceServerBackend for UsbRedirServer { fn add_device(&mut self, device: DeviceAnnounce) -> PduResult<()> { self.device.device_added(RdpUsbDeviceAnnounceInfo { - announce: device, + announce: device.into(), usb_handle: self.handle.clone(), }); Ok(())