private uint ParseUInt32IoResult(EusbPdu pdu)
        {
            Site.Assert.IsInstanceOfType(
                pdu,
                typeof(EusbIoControlCompletionPdu),
                "Must receive an EusbIoControlCompletionPdu message."
                );

            EusbIoControlCompletionPdu completionPdu = (EusbIoControlCompletionPdu)pdu;

            Site.Assert.IsSuccess(
                (int)completionPdu.HResult,
                "the HResult member of the EusbIoControlCompletionPdu must be a successful code."
                );

            Site.Assert.AreEqual <uint>(
                4,
                completionPdu.OutputBufferSize,
                "If the operation is successful, the client MUST set the OutputBufferSize field to 0x4."
                );

            uint res = BitConverter.ToUInt32(completionPdu.OutputBuffer, 0);

            return(res);
        }
        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);
        }
Пример #3
0
        /// <summary>
        /// This method is used to verify the IOCONTROL_COMPLETION PDU.
        /// </summary>
        /// <param name="responsePdu">The PDU from the client.</param>
        /// <param name="requestId">The RequestId in the request PDU.</param>
        /// <param name="outputBufferSize">The OutputBufferSize in the request PDU.</param>
        /// <param name="requestCompletion">A unique InterfaceID to be set in the Register Request Callback Message.</param>
        public static void VerifyIoControlCompletion(EusbIoControlCompletionPdu responsePdu, uint requestId, uint outputBufferSize, uint requestCompletion)
        {
            Site.Assert.AreEqual <uint>(
                requestCompletion,
                responsePdu.InterfaceId,
                "Expect that the InterfaceId in the response PDU equals the RequestCompletion field of the REGISTER_REQUEST_CALLBACK PDU. The actual value is 0x{0:x8}.",
                responsePdu.InterfaceId);

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

            Site.Assert.AreEqual <FunctionId_Values>(
                FunctionId_Values.IOCONTROL_COMPLETION,
                (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>(
                requestId,
                responsePdu.RequestId,
                "Expect that the RequestId in the response PDU equals the RequestId in the request PDU. The actual value is 0x{0:x8}.",
                requestId);

            if (responsePdu.HResult == (uint)HRESULT_FROM_WIN32.ERROR_SUCCESS)
            {
                Site.Assert.AreEqual <uint>(
                    outputBufferSize,
                    responsePdu.OutputBufferSize,
                    "Expect that the OutputBufferSize in the response PDU equals the OutputBufferSize in the request PDU. The actual value is 0x{0:x8}.",
                    responsePdu.OutputBufferSize);

                Site.Assert.AreEqual <uint>(
                    outputBufferSize,
                    (uint)responsePdu.OutputBuffer.Length,
                    "Expect that the length of OutputBuffer in the response PDU equals the OutputBufferSize in the request PDU. The actual value is 0x{0:x8}.",
                    (uint)responsePdu.OutputBuffer.Length);
            }
            else if (responsePdu.HResult == (uint)HRESULT_FROM_WIN32.ERROR_INSUFFICIENT_BUFFER)
            {
                Site.Assert.AreEqual <uint>(
                    outputBufferSize,
                    responsePdu.OutputBufferSize,
                    "Expect that the OutputBufferSize in the response PDU equals the OutputBufferSize in the request PDU. The actual value is 0x{0:x8}.",
                    responsePdu.OutputBufferSize);

                Site.Assert.IsTrue(
                    responsePdu.Information > outputBufferSize,
                    "Expect that the Information in the response PDU is bigger than the OutputBufferSize in the request PDU when returning ERROR_INSUFFICIENT_BUFFER. The actual value is 0x{0:x8}.",
                    responsePdu.Information);

                Site.Assert.AreEqual <uint>(
                    responsePdu.Information,
                    (uint)responsePdu.OutputBuffer.Length,
                    "Expect that the length of OutputBuffer in the response PDU equals the Information in the response PDU. The actual value is 0x{0:x8}.",
                    (uint)responsePdu.OutputBuffer.Length);
            }
            else
            {
                Site.Assert.AreEqual <uint>(
                    0,
                    responsePdu.OutputBufferSize,
                    "Expect that the OutputBufferSize in the response PDU is zero when returning other errors. The actual value is 0x{0:x8}.",
                    responsePdu.OutputBufferSize);

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