mirror of
https://github.com/Devolutions/IronRDP.git
synced 2026-11-23 00:14:10 +00:00
refactor(server): define the USB device announce type (#1933)
Follow-up to #1417: > RDPEUSB types still reaches the consumer. RdpUsbDeviceAnnounceInfo carries the raw DeviceAnnounce, so a consumer that wants the device speed reads DeviceSpeed, an RDPEUSB PDU type. The goal is for a downstream bridge to need no ironrdp-rdpeusb dependency at all. I would rather agree on the facade shape than guess at it, so it is left as a follow-up. Backends received ironrdp-rdpeusb's DeviceAnnounce, so implementing UsbRedirDevice meant naming RDPEUSB wire types. UsbDeviceAnnounce reports the bus speed as ironrdp-usb's UsbSpeed and exposes the device identifiers and mapped USB speed while keeping the remaining RDPEUSB capability fields out of the announcement facade, leaving the facade free of RDPEUSB vocabulary. Downstream like qemu-rdp can thus drop ironrdp-rdpeusb deps. --------- Signed-off-by: uchouT <i@uchout.moe>
This commit is contained in:
@@ -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<DeviceSpeed> 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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<String>,
|
||||
/// Identifiers of the device classes the client reports the device is
|
||||
/// compatible with, most specific first.
|
||||
pub compat_ids: Vec<String>,
|
||||
/// 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<DeviceAnnounce> 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(())
|
||||
|
||||
Reference in New Issue
Block a user