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;
        }
        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;
        }
        /// <summary>
        /// Sends CHANNEL_CREATED to notify the client the channel has been created.
        /// </summary>
        /// <param name="channel">The channel to be sent in.</param>
        /// <param name="messageId">A unique ID for the request or response pair.</param>
        /// <param name="majorVersion">The major version of RDP USB redirection supported.</param>
        /// <param name="minorVersion">The minor version of RDP USB redirection supported.</param>
        /// <param name="capability">The capabilities of RDP USB redirection supported.</param>
        public void ChannelCreated(DynamicVirtualChannel channel, uint messageId, uint majorVersion, uint minorVersion, uint capability)
        {
            Site.Log.Add(
                LogEntryKind.Debug,
                "Sending CHANNEL_CREATED: Channel ID {0}, Message ID {1}, Version major {2} minor {3}, Capability {4}.",
                channel.ChannelId,
                messageId,
                majorVersion,
                minorVersion,
                capability
            );

            EusbChannelCreatedPdu requestPdu = new EusbChannelCreatedPdu(true);
            requestPdu.MessageId = messageId;
            requestPdu.MajorVersion = majorVersion;
            requestPdu.MinorVersion = minorVersion;
            requestPdu.Capabilities = capability;

            SendPdu(requestPdu, channel);

            if (majorVersion == 1 && minorVersion == 0 && capability == 0)
            {
                // Positive tests so expect a valid response.
                Site.Log.Add(LogEntryKind.Debug, "Receiving CHANNEL_CREATED.");
                EusbChannelCreatedPdu responsePdu = this.rdpeusbServer.ExpectRdpeusbPdu<EusbChannelCreatedPdu>(channel.ChannelId, waitTime);

                #region Verify CHANNEL_CREATED Response

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

                // Log this PDU if responsePdu is not null
                LogPdu(responsePdu);

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

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

                Site.Assert.AreEqual<uint>(responsePdu.MajorVersion,
                    1,
                    "Expect that the MajorVersion in the response PDU is 1. The actual value is {0}.",
                    responsePdu.MajorVersion);

                Site.Assert.AreEqual<uint>(responsePdu.MinorVersion,
                    0,
                    "Expect that the MinorVersion in the response PDU is 0. The actual value is {0}.",
                    responsePdu.MinorVersion);

                Site.Assert.AreEqual<uint>(responsePdu.Capabilities,
                    0,
                    "Expect that the Capabilities in the response PDU is 0. The actual value is {0}.",
                    responsePdu.Capabilities);

                #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);
            }
        }