/// <summary>
        /// Negotiates the capability through the specified channel with the connected RDP client.
        /// </summary>
        /// <param name="channel">The channel which the negotiation is sent in.</param>
        /// <param name="messageId">A unique ID for the request or response pair.</param>
        /// <param name="capability">The server's capability.</param>
        public void NegotiateCapability(DynamicVirtualChannel channel, uint messageId, CapabilityValue_Values capability)
        {
            Site.Log.Add(LogEntryKind.Debug, "Sending RIM_EXCHANGE_CAPABILITY_REQUEST: Channel ID {0}, Message ID {1}, Capability {2}.", channel.ChannelId, messageId, capability.ToString());

            EusbRimExchangeCapRequestPdu requestPdu = new EusbRimExchangeCapRequestPdu();

            requestPdu.MessageId = messageId;
            SendPdu(requestPdu, channel);

            if (capability == CapabilityValue_Values.RIM_CAPABILITY_VERSION_01)
            {
                // Positive tests so expect a valid response.
                Site.Log.Add(LogEntryKind.Debug, "Receiving EusbRimExchangeCapResponsePdu.");
                EusbRimExchangeCapResponsePdu responsePdu = this.rdpeusbServer.ExpectRdpeusbPdu <EusbRimExchangeCapResponsePdu>(channel.ChannelId, waitTime);

                #region Verify RIM_EXCHANGE_CAPABILITY_RESPONSE

                Site.Assert.IsNotNull(
                    responsePdu,
                    "Expect that the response from the client is EusbRimExchangeCapResponsePdu.");

                Site.Assert.AreEqual <uint>(
                    requestPdu.InterfaceId,
                    responsePdu.InterfaceId,
                    "Expect that the InterfaceId in the response PDU equals the InterfaceId in the request PDU. The actual value is 0x{0:x8}.",
                    responsePdu.InterfaceId);

                Site.Assert.AreEqual <uint>(
                    requestPdu.MessageId,
                    responsePdu.MessageId,
                    "Expect that the MessageId in the response PDU equals the MessageId in the request PDU. The actual value is 0x{0:x8}.",
                    responsePdu.MessageId);

                Site.Assert.AreEqual <Mask_Values>(
                    Mask_Values.STREAM_ID_NONE,
                    responsePdu.Mask,
                    "Expect that the Mask in the response PDU is STREAM_ID_NONE.");

                Site.Assert.AreEqual <uint>(
                    (uint)CapabilityValue_Values.RIM_CAPABILITY_VERSION_01,
                    responsePdu.CapabilityValue,
                    "Expect that the CapabilityValue in the response PDU is 0x00000001.");

                Site.Assert.AreEqual <uint>(
                    0,
                    responsePdu.Result,
                    "Expect that the Result in the response PDU is 0x00000000. The actual value is 0x{0:x8}.",
                    responsePdu.MessageId);

                #endregion
            }
            else
            {
                // Negative tests so expect the channel to be closed.
                bool channelClosed = IsChannelClosed(channel);
                Site.Assert.IsTrue(channelClosed, "Expect the channel {0} to be closed.", channel.ChannelId);
            }
        }
        public override EusbPdu ParsePdu(byte[] data)
        {
            EusbPdu pdu;

            switch (GetPduType(data))
            {
            case EusbType.RIM_EXCHANGE_CAPABILITY_REQUEST:
                pdu = new EusbRimExchangeCapResponsePdu();
                break;

            case EusbType.ADD_VIRTUAL_CHANNEL:
                pdu = new EusbAddVirtualChannelPdu();
                break;

            case EusbType.ADD_DEVICE:
                pdu = new EusbAddDevicePdu();
                break;

            case EusbType.CHANNEL_CREATED:
                pdu = new EusbChannelCreatedPdu(false);
                break;

            case EusbType.QUERY_DEVICE_TEXT:
                pdu = new EusbQueryDeviceTextResponsePdu();
                break;

            case EusbType.IOCONTROL_COMPLETION:
                pdu = new EusbIoControlCompletionPdu();
                break;

            case EusbType.URB_COMPLETION:
                pdu = new EusbUrbCompletionPdu();
                break;

            case EusbType.URB_COMPLETION_NO_DATA:
                pdu = new EusbUrbCompletionNoDataPdu();
                break;

            default:
                return(base.ParsePdu(data));
            }

            if (!PduMarshaler.Unmarshal(data, pdu))
            {
                pdu = new EusbUnknownPdu();
                PduMarshaler.Unmarshal(data, pdu);
            }
            return(pdu);
        }