Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions crates/ironrdp-rdpeusb/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ pub trait UrbdrcDeviceBackend: Send {
/// the message MUST match the RequestId in the QUERY_DEVICE_TEXT message.
///
/// [3.3.5.3.5]: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpeusb/834f56cc-cfed-4649-8952-0b6486638c28
fn query_device_text(&mut self, channel_id: u32, text_type: u32, locale_id: u32) -> PduResult<Option<DeviceText>>;
fn query_device_text(&mut self, channel_id: u32, text_type: u32, locale_id: u32) -> PduResult<DeviceText>;

/// Process an `IoControl` request.
///
Expand Down Expand Up @@ -550,19 +550,15 @@ impl DvcProcessor for UrbdrcDeviceClient {
if !self.ready_for_io || dev_text_pdu.udev_iface != self.udev_iface {
return Ok(Vec::new());
}
if let Some(device_text) =
let device_text =
self.backend
.query_device_text(channel_id, dev_text_pdu.text_type, dev_text_pdu.locale_id)?
{
Ok(vec![Box::new(QueryDeviceTextRsp {
msg_id: dev_text_pdu.msg_id,
udev_iface: dev_text_pdu.udev_iface,
hresult: device_text.hresult,
device_description: device_text.description.into(),
})])
} else {
Ok(Vec::new())
}
.query_device_text(channel_id, dev_text_pdu.text_type, dev_text_pdu.locale_id)?;
Ok(vec![Box::new(QueryDeviceTextRsp {
msg_id: dev_text_pdu.msg_id,
udev_iface: dev_text_pdu.udev_iface,
hresult: device_text.hresult,
device_description: device_text.description.into(),
})])
}
IoCtl(io_ctl_pdu) => {
if !self.ready_for_io || io_ctl_pdu.udev_iface != self.udev_iface {
Expand Down
36 changes: 12 additions & 24 deletions crates/ironrdp-testsuite-core/tests/rdpeusb/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,7 @@ use ironrdp_rdpeusb::pdu::{
UrbdrcClientControlPdu, UrbdrcClientDevicePdu, UrbdrcServerControlPdu, UrbdrcServerDevicePdu,
};

use super::simple_device_info;

const STREAM_ID_PROXY: u32 = 1;

fn proxy_iface_id(iface: InterfaceId) -> u32 {
u32::from(iface) | (STREAM_ID_PROXY << 30)
}

fn encode_pdu<T: ironrdp_core::Encode>(pdu: &T) -> Vec<u8> {
encode_vec(pdu).expect("encode should succeed")
}
use super::{encode_pdu, proxy_iface_id, simple_device_info};

fn decode_control_msg(message: &DvcMessage) -> UrbdrcClientControlPdu {
let encoded = encode_vec(message.as_ref()).expect("encode should succeed");
Expand Down Expand Up @@ -81,30 +71,28 @@ impl DeviceManagerBackend for TestDeviceManager {
}
}

struct TestDeviceBackend {
struct NoopDeviceClientBackend {
device_info: DeviceInfo,
}

impl TestDeviceBackend {
impl NoopDeviceClientBackend {
fn new(device_info: DeviceInfo) -> Self {
Self { device_info }
}
}

impl UrbdrcDeviceBackend for TestDeviceBackend {
impl UrbdrcDeviceBackend for NoopDeviceClientBackend {
fn device_info(&mut self, _channel_id: u32) -> PduResult<DeviceInfo> {
Ok(self.device_info.clone())
}

fn cancel_request(&mut self, _request_id: RequestId, _channel_id: u32) {}

fn query_device_text(
&mut self,
_channel_id: u32,
_text_type: u32,
_locale_id: u32,
) -> PduResult<Option<DeviceText>> {
Ok(None)
fn query_device_text(&mut self, _channel_id: u32, _text_type: u32, _locale_id: u32) -> PduResult<DeviceText> {
Ok(DeviceText {
hresult: 0,
description: String::new(),
})
}

fn io_control(
Expand Down Expand Up @@ -169,10 +157,10 @@ fn channel_setup_sequence() {
.expect("device manager state lock should not be poisoned");
state
.pending_devices
.push_back(Box::new(TestDeviceBackend::new(simple_device_info())));
.push_back(Box::new(NoopDeviceClientBackend::new(simple_device_info())));
state
.pending_devices
.push_back(Box::new(TestDeviceBackend::new(simple_device_info())));
.push_back(Box::new(NoopDeviceClientBackend::new(simple_device_info())));
}

let callback_manager_state = Arc::clone(&manager_state);
Expand Down Expand Up @@ -295,7 +283,7 @@ fn channel_setup_sequence() {
#[test]
fn new_device_sequence() {
let udev_iface = InterfaceId::try_from(4).expect("valid device interface id");
let backend = Box::new(TestDeviceBackend::new(simple_device_info()));
let backend = Box::new(NoopDeviceClientBackend::new(simple_device_info()));
let mut client = UrbdrcDeviceClient::new(udev_iface, backend).expect("device client should be created");

assert!(!client.ready_for_io());
Expand Down
Loading
Loading