Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

USB Redirect Virtual Channel of RDP Protocol

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

In the RDP remote Desktop protocol, the USB device virtual channel extension protocol is used to transfer USB packets from the terminal server to the terminal client. The end client forwards the USB packet to the physical USB device. The client then returns the result after the physical device reassembles the packet.

Generally speaking, remote access protocols can redirect USB devices, so in use and process, clients must be provided with a way to specify USB devices that are redirected using this protocol, or to choose devices that use alternative methods or devices that do not redirect at all. Because when the device is redirected, it can no longer be used on the client. For example:

USB mouse: if you use this protocol for USB mouse redirection, the mouse will not be available locally on the client side. This result is useful in the scenario of full-screen use of virtual desktops, but in traditional RDP services, both our client and server need to reuse our mouse devices at the same time, so how does the USB virtual channel of RDP protocol solve this problem?

In the face of this problem, we do not think about the implementation of the RDP protocol USB virtual channel itself, but on the premise that we first think about how to solve this problem. Then there are two ways to solve the problem:

1. Use a drive-free mouse

2. The client uses two mice.

The first scheme seems to be very good, but with restrictions, it is not perfect; the second condition is a purely anti-human scheme, direct pass. We find that it seems that only by optimizing the protocol can we be perfectly compatible with the current usage habits and operating experience.

This involves what perfect mechanism the USB virtual channel of the RDP protocol uses to achieve the above requirements. To solve this problem, let's see how the USB virtual channel of the RDP protocol works. In order to solve our above questions!

First, we need to talk about a few concepts:

1. Device driver: software used by the system to communicate with a device, such as a monitor, printer, mouse, or communication adapter. It is an abstraction layer that controls application access to various hardware devices on a given computer system. We usually call it "drive" for short. So how does the driver communicate with the hardware? This involves the registers of each hardware. I have written an article about how applications interact with hardware through drivers, including how drivers find the register address of the hardware and how to interact with registers.

2. Device interface: a unified and extensible mechanism that can interact with applications and systems programmatically. A device driver can provide one or more device interfaces for a particular device. The device interface is represented by the GUID (globally unique Identifier).

3. Remote device: a device connected to a remote (or client) machine.

4. Terminal client: the client of terminal server. A terminal client program that runs on the client. In Windows, RDP is just a protocol that enables us to access the server desktop and display images. Providing display resources and interactive resources for this protocol is called Terminal Services, which is changed to remote Desktop Services in the high version.

5. Terminal server: a server that runs terminal services.

In terms of the above questions, the USB virtual channel of the RDP protocol uses a more flexible design to ensure the flexibility of use. first of all, the decision on the need to redirect those USB devices is given to the user, and the user gives a clear answer.

The implementation of these rules and policies can be seen in the terminal client of Windows, which is the user interface for selecting the right device, and these are only common devices, which are more fully integrated with other Windows services: group policy, registry, notification, etc. Therefore, like other protocols, the flexibility to choose redirected devices is a perfect solution for this design to meet the current usage habits and operating experience.

Secondly, aiming at the problem of USB mouse reuse, I think the USB virtual channel of RDP is no different from other protocols. It automatically switches the USB mouse based on the judgment of "session" and "focus", which has achieved the purpose of reusing USB mouse. The session should be easy to understand. Starting a remote desktop connection is a session, and the properties of the session include the user, connection password, connection address, and so on. The focus is to determine whether the user's current desktop is on the local client or remote desktop.

Let's describe in detail how the USB virtual channel of the RDP protocol works.

In the implementation of USB virtual channel, the USB hardware device of the terminal client needs to be redirected to the terminal server, so the terminal client and the hardware USB device need to be connected first, and then the device is redirected to the terminal server through the RDP protocol client. To recognize a hardware USB device, a terminal server must install a device driver on the server.

The following figure describes the sequence of events related to the USB device and the USB driver stack on the server.

Figure 1:USB stack flow

When the USB device is plugged in, the client sends an add virtual channel message to the server. In response, the server sends the same virtual channel creation message to the client and waits for the same message from the client. After the client sends the virtual channel creation message, the client immediately sends the add device message, and after both sides have finished creating the virtual channel, the server immediately starts to create a USB driver stack, and the driver will indicate the existence of the USB device to the system. After that, the server and client are ready to exchange I / O packets.

When the device is unplugged from the client, the protocol shuts down the Imax O channel that the server sends to the specific device.

Specifically, the establishment of virtual channels for USB devices and the exchange of data need to follow the following logical order:

1. Channel setting order: open the channel and exchange capacity. The channel is assigned a specific identifier used by the client and server to identify the USB device. USB device virtual channels use multiple channels in a single named dynamic virtual channel. Each USB device has a control channel and a data channel. The goal of this sequence is to set the channel identifier and exchange hardware identification and version functions.

Figure 2: Channel setting order

2. New device order: the client notifies the server of the arrival of the new device. The server creates a device on the server computer that corresponds to the device reported by the client. The client uses a new device sequence to notify the server about the new device. It first informs the server to create a new instance of the USB redirect virtual channel. Once a new virtual channel is created, the new device message is sent to the server via the new virtual channel. The device is identified according to the HardwareIds field in which the device message is added.

Figure 3: new equipment sequence

3. USB O sequence: the server sends the USB packet to the client, and the client forwards it to the physical device, and sends back the result after the physical device reassembles the packet. The server sends an Ipicuro request to the client using the Icano sequence. In the USB virtual channel of the RDP protocol, the server can send multiple I / O requests to the client without waiting for the previously sent request to complete.

Graph 4:I/O sequence

The USB device virtual channel is embedded in the dynamic virtual channel transmission, and the dynamic channel virtual channel is extended on top of the virtual channel protocol to achieve a general connection-oriented communication channel. Dynamic virtual channel (DVC) is based on the existing static virtual channel. A static virtual channel session is a typical client / server relationship. The remote Desktop Protocol (RDP) layer [the architectural level of the RDP protocol] manages channel creation, setup, and data transfer over virtual channels. A DVC consists of two endpoints logically connected through a network. One endpoint is an application running on a Terminal Services (TS) server, and the other is an application running on a terminal client. DVC is created and maintained by the DVC manager. There is a DVC manager on both the terminal server and the terminal client. The DVC server manager is responsible for initializing the DVC environment and creating a separate DVC. The DVC client manager is responsible for creating and maintaining connections to client-side DVC manager applications. After the DVC manager is initialized, the DVC server manager can create a separate DVC. These channels are used to exchange messages between applications running on the terminal server and DVC listeners running on the terminal client. Sending and receiving messages are symmetrical between the client and the server, and both parties can initiate the sending of data messages (or messages).

Therefore, the essence of USB virtual channel is to establish a static client / server relationship virtual channel, and then through the static virtual channel, the dynamic virtual channel manager creates the exchange data channel between each other. The conversion between static and dynamic virtual channels is as follows:

The USB device virtual channel runs only after the dynamic virtual channel transport is fully established. If the dynamic virtual channel transmission is terminated, the USB device virtual channel is also terminated. That is, when the USB device is manually unplugged, the dynamic virtual channel is terminated, and the corresponding USB device virtual channel is also terminated. The server-side message will indicate that the USB device has been unplugged, and this message will be sent through the static virtual channel data exchange channel. If the protocol is terminated by closing the underlying virtual channel, the connection to the RDP session is closed directly. When the underlying virtual channel is terminated, the dynamic virtual channel is terminated, and the USB device virtual channel is also terminated.

In addition to redirecting devices, we can also redirect drivers and applications for USB devices. If you want to redirect device drivers and applications, the following requirements must be met:

1. All communication between the device and the application is routed through the Imax O sequence supported by the device driver. Traffic cannot be routed in any other way, such as shared memory, registry, or disk files.

2. Communication between device drivers and applications cannot be anything other than these basic calls [read, write, and IO control].

Why? Because the protocol format field specifies and restricts the use of transport calls.

Finally, I would like to ask a question:

If I have a computer with dual graphics cards, two monitors, two mice and two keyboards. Suppose I assign it to two people to use this computer at the same time, where the first monitor uses the locally calculated operating system and opens a RDP session through the remote desktop in the window of the second monitor for the second user to use. So how should I set up so that the two mice and two keyboards do not interfere with each other, the first mouse and keyboard are dedicated to the local system, and the second mouse and keyboard are dedicated to RDP sessions?

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report