public override EusbPdu ParsePdu(byte[] data)
        {
            EusbPdu pdu;

            switch (GetPduType(data))
            {
                case EusbType.RIM_EXCHANGE_CAPABILITY_REQUEST:
                    pdu = new EusbRimExchangeCapRequestPdu();
                    break;
                case EusbType.CHANNEL_CREATED:
                    pdu = new EusbChannelCreatedPdu(true);
                    break;
                case EusbType.REGISTER_REQUEST_CALLBACK:
                    pdu = new EusbRegisterRequestCallbackPdu();
                    break;
                case EusbType.QUERY_DEVICE_TEXT:
                    pdu = new EusbQueryDeviceTextRequestPdu();
                    break;
                case EusbType.IO_CONTROL:
                    pdu = new EusbIoControlPdu();
                    break;
                case EusbType.INTERNAL_IO_CONTROL:
                    pdu = new EusbInternalIoControlPdu();
                    break;
                case EusbType.TRANSFER_IN_REQUEST:
                    pdu = new EusbTransferInRequestPdu();
                    break;
                case EusbType.TRANSFER_OUT_REQUEST:
                    pdu = new EusbTransferOutRequestPdu();
                    break;
                case EusbType.CANCEL_REQUEST:
                    pdu = new EusbCancelRequestPdu();
                    break;
                case EusbType.RETRACT_DEVICE:
                    pdu = new EusbRetractDevicePdu();
                    break;
                default:
                    return base.ParsePdu(data);
            }

            if (!PduMarshaler.Unmarshal(data, pdu))
            {
                pdu = new EusbUnknownPdu();
                PduMarshaler.Unmarshal(data, pdu);
            }
            return pdu;
        }
        /// <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);
            }
        }