コード例 #1
0
        /// <summary>
        /// Submits data to the client USB device.
        /// </summary>
        /// <param name="device">The context of the device which is being operated.</param>
        /// <param name="tsUrb">A TS_URB structure.</param>
        /// <param name="outputBuffer">The raw data to be sent to the device.</param>
        public void TransferOutRequest(EusbDeviceContext device, TS_URB tsUrb, byte[] outputBuffer)
        {
            uint size = null == outputBuffer ? 0 : (uint)outputBuffer.Length;

            Site.Log.Add(
                LogEntryKind.Debug,
                "Sending TRANSFER_OUT_REQUEST. Device: {0}, URB: {1}, Output buffer size: {2}",
                device,
                tsUrb,
                size);

            EusbTransferOutRequestPdu requestPdu = new EusbTransferOutRequestPdu(device.UsbDeviceInterfaceId);

            byte[] buf = PduMarshaler.Marshal(tsUrb);
            requestPdu.CbTsUrb = (uint)buf.Length;

            // TODO: Need verify for negtive test cases?
            if (tsUrb.Header.Size != (ushort)requestPdu.CbTsUrb)
            {
                throw new ArgumentException(String.Format(
                                                "Header.Size ({0}) doesn't match the actual size ({1}).",
                                                tsUrb.Header.Size,
                                                requestPdu.CbTsUrb
                                                ));
            }

            requestPdu.TsUrb            = buf;
            requestPdu.OutputBuffer     = outputBuffer;
            requestPdu.OutputBufferSize = size;
            SendPdu(requestPdu, device.VirtualChannel);
        }
コード例 #2
0
        /// <summary>
        /// Requests data from the client USB device.
        /// </summary>
        /// <param name="device">The context of the device which is being operated.</param>
        /// <param name="tsUrb">A TS_URB structure.</param>
        /// <param name="outputBufferSize">This value represents the maximum number of bytes of data that is requested from
        /// the USB device.</param>
        public void TransferInRequest(EusbDeviceContext device, TS_URB tsUrb, uint outputBufferSize)
        {
            // TODO: Check this verification.
            //Site.Assume.IsFalse(
            //    tsUrb is TS_URB_ISOCH_TRANSFER && device.NoAckIsochWriteJitterBufferSizeInMs,
            //    "The client does not support TS_URB_ISOCH_TRANSFER messages."
            //    );

            Site.Log.Add(
                LogEntryKind.Debug,
                "Sending TRANSFER_IN_REQUEST. Device: {0}, URB: {1}, Output buffer size: {2}",
                device,
                tsUrb,
                outputBufferSize);

            EusbTransferInRequestPdu requestPdu = new EusbTransferInRequestPdu(device.UsbDeviceInterfaceId);

            byte[] buf = PduMarshaler.Marshal(tsUrb);
            requestPdu.CbTsUrb = (uint)buf.Length;

            // TODO: Need verify for negtive test cases?
            if (tsUrb.Header.Size != (ushort)requestPdu.CbTsUrb)
            {
                throw new ArgumentException(String.Format(
                                                "Header.Size ({0}) doesn't match the actual size ({1}).",
                                                tsUrb.Header.Size,
                                                requestPdu.CbTsUrb
                                                ));
            }

            requestPdu.TsUrb            = buf;
            requestPdu.OutputBufferSize = outputBufferSize;
            SendPdu(requestPdu, device.VirtualChannel);
        }
コード例 #3
0
        /// <summary>
        /// This method is used to verify the URB_COMPLETION PDU.
        /// </summary>
        /// <param name="responsePdu">The PDU from the client.</param>
        /// <param name="tsUrb">The TS_URB in the request.</param>
        /// <param name="requestCompletion">A unique InterfaceID to be set in the Register Request Callback Message.</param>
        public static void VerifyUrbCompletion(EusbUrbCompletionPdu responsePdu, TS_URB tsUrb, 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.URB_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>(
                tsUrb.Header.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}.",
                responsePdu.RequestId);
        }
コード例 #4
0
        protected URB_FUNCTIONID GetTsUrbType(byte[] data)
        {
            if (null == data)
            {
                return(URB_FUNCTIONID.UNKNOWN);
            }

            TS_URB urb = new TS_URB();

            if (!PduMarshaler.Unmarshal(data, urb))
            {
                return(URB_FUNCTIONID.UNKNOWN);
            }

            return(urb.Header.URB_Function);
        }
コード例 #5
0
        /// <summary>
        /// This method is used to verify the URB_COMPLETION_NO_DATA PDU.
        /// </summary>
        /// <param name="responsePdu">The PDU from the client.</param>
        /// <param name="tsUrb">The TS_URB in the request.</param>
        /// <param name="isTransferInRequest">This specify if the request is TRANSFER_IN_REQUEST or TRANSFER_OUT_REQUEST.</param>
        /// <param name="requestCompletion">A unique InterfaceID to be set in the Register Request Callback Message.</param>
        public static void VerifyUrbCompletionNoData(EusbUrbCompletionNoDataPdu responsePdu, TS_URB tsUrb, bool isTransferInRequest, 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.URB_COMPLETION_NO_DATA,
                (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>(
                tsUrb.Header.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}.",
                responsePdu.RequestId);

            if (isTransferInRequest)
            {
                #region Verify Response For TRANSFER_IN_REQUEST
                Site.Assert.AreEqual <uint>(
                    0,
                    responsePdu.OutputBufferSize,
                    "Expect that the OutputBufferSize in the response PDU is zero. The actual value is 0x{0:x8}.",
                    responsePdu.OutputBufferSize);

                if (tsUrb is TS_URB_SELECT_CONFIGURATION)
                {
                    #region Verify TS_URB_SELECT_CONFIGURATION_RESULT
                    Site.Log.Add(LogEntryKind.Debug,
                                 "Expect the TsUrbResult is TS_URB_SELECT_CONFIGURATION_RESULT when the TsUrb in the request is TS_URB_SELECT_CONFIGURATION.");
                    TS_URB_SELECT_CONFIGURATION_RESULT urb = new TS_URB_SELECT_CONFIGURATION_RESULT();

                    if (!PduMarshaler.Unmarshal(responsePdu.TsUrbResult, urb))
                    {
                        // TsUrbResult can not be unmarshaled to TS_URB_SELECT_CONFIGURATION_RESULT
                        TS_URB_UNKNOWN unknowUrb = new TS_URB_UNKNOWN();
                        Site.Assume.IsTrue(PduMarshaler.Unmarshal(responsePdu.TsUrbResult, unknowUrb),
                                           "Marshaling the data to an unknown PDU MUST succeed.");

                        Site.Log.Add(LogEntryKind.CheckFailed,
                                     "The TsUrbResult is not valid TS_URB_SELECT_CONFIGURATION_RESULT. The data is:\r\n{0}", unknowUrb.ToString());
                    }
                    else
                    {
                        Site.Log.Add(LogEntryKind.CheckSucceeded, "The TsUrbResult is expected TS_URB_SELECT_CONFIGURATION_RESULT.");
                    }
                    #endregion
                }
                else if (tsUrb is TS_URB_SELECT_INTERFACE)
                {
                    #region Verify TS_URB_SELECT_INTERFACE_RESULT
                    Site.Log.Add(LogEntryKind.Debug,
                                 "Expect the TsUrbResult is TS_URB_SELECT_INTERFACE_RESULT when the TsUrb in the request is TS_URB_SELECT_INTERFACE.");
                    TS_URB_SELECT_INTERFACE_RESULT urb = new TS_URB_SELECT_INTERFACE_RESULT();

                    if (!PduMarshaler.Unmarshal(responsePdu.TsUrbResult, urb))
                    {
                        // TsUrbResult can not be unmarshaled to TS_URB_SELECT_INTERFACE_RESULT
                        TS_URB_UNKNOWN unknowUrb = new TS_URB_UNKNOWN();
                        Site.Assume.IsTrue(PduMarshaler.Unmarshal(responsePdu.TsUrbResult, unknowUrb),
                                           "Marshaling the data to an unknown PDU MUST succeed.");

                        Site.Log.Add(LogEntryKind.CheckFailed,
                                     "The TsUrbResult is not valid TS_URB_SELECT_INTERFACE_RESULT. The data is:\r\n{0}", unknowUrb.ToString());
                    }
                    else
                    {
                        Site.Log.Add(LogEntryKind.CheckSucceeded, "The TsUrbResult is expected TS_URB_SELECT_INTERFACE_RESULT.");
                    }
                    #endregion
                }
                else if (tsUrb is TS_URB_GET_CURRENT_FRAME_NUMBER)
                {
                    #region Verify TS_URB_GET_CURRENT_FRAME_NUMBER_RESULT
                    Site.Log.Add(LogEntryKind.Debug,
                                 "Expect the TsUrbResult is TS_URB_GET_CURRENT_FRAME_NUMBER_RESULT when the TsUrb in the request is TS_URB_GET_CURRENT_FRAME_NUMBER.");
                    TS_URB_GET_CURRENT_FRAME_NUMBER_RESULT urb = new TS_URB_GET_CURRENT_FRAME_NUMBER_RESULT();

                    if (!PduMarshaler.Unmarshal(responsePdu.TsUrbResult, urb))
                    {
                        // TsUrbResult can not be unmarshaled to TS_URB_GET_CURRENT_FRAME_NUMBER_RESULT
                        TS_URB_UNKNOWN unknowUrb = new TS_URB_UNKNOWN();
                        Site.Assume.IsTrue(PduMarshaler.Unmarshal(responsePdu.TsUrbResult, unknowUrb),
                                           "Marshaling the data to an unknown PDU MUST succeed.");

                        Site.Log.Add(LogEntryKind.CheckFailed,
                                     "The TsUrbResult is not valid TS_URB_GET_CURRENT_FRAME_NUMBER_RESULT. The data is:\r\n{0}", unknowUrb.ToString());
                    }
                    else
                    {
                        Site.Log.Add(LogEntryKind.CheckSucceeded, "The TsUrbResult is expected TS_URB_GET_CURRENT_FRAME_NUMBER_RESULT.");
                    }
                    #endregion
                }
                #endregion
            }
            else
            {
                #region Verify Response For TRANSFER_OUT_REQUEST
                Site.Assert.AreNotEqual <uint>(
                    0,
                    responsePdu.OutputBufferSize,
                    "Expect that the OutputBufferSize in the response PDU is not zero. The actual value is 0x{0:x8}.",
                    responsePdu.OutputBufferSize);
                #endregion
            }

            #region Verify TS_URB_ISOCH_TRANSFER_RESULT
            if (tsUrb is TS_URB_ISOCH_TRANSFER)
            {
                Site.Log.Add(LogEntryKind.Debug,
                             "Expect the TsUrbResult is TS_URB_ISOCH_TRANSFER_RESULT when the TsUrb in the request is TS_URB_ISOCH_TRANSFER.");
                TS_URB_ISOCH_TRANSFER_RESULT urb = new TS_URB_ISOCH_TRANSFER_RESULT();

                if (!PduMarshaler.Unmarshal(responsePdu.TsUrbResult, urb))
                {
                    // TsUrbResult can not be unmarshaled to TS_URB_ISOCH_TRANSFER_RESULT
                    TS_URB_UNKNOWN unknowUrb = new TS_URB_UNKNOWN();
                    Site.Assume.IsTrue(PduMarshaler.Unmarshal(responsePdu.TsUrbResult, unknowUrb),
                                       "Marshaling the data to an unknown PDU MUST succeed.");

                    Site.Log.Add(LogEntryKind.CheckFailed,
                                 "The TsUrbResult is not valid TS_URB_ISOCH_TRANSFER_RESULT. The data is:\r\n{0}", unknowUrb.ToString());
                }
                else
                {
                    Site.Log.Add(LogEntryKind.CheckSucceeded, "Expect that the TsUrbResult is TS_URB_ISOCH_TRANSFER_RESULT.");
                }
            }
            #endregion
        }