コード例 #1
0
        protected EusbType GetPduType(byte[] data)
        {
            if (null == data) return EusbType.UNKNOWN;

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

            switch (pdu.Mask)
            {
                case Mask_Values.STREAM_ID_NONE:
                    {
                        return EusbType.RIM_EXCHANGE_CAPABILITY_REQUEST;
                    }
                case Mask_Values.STREAM_ID_PROXY:
                    {
                        if (pdu.InterfaceId == (uint)EusbInterfaceId_Values.ADD_VIRTUAL_CHANNEL_OR_DEVICE)
                        {
                            EusbRequestPdu requestPdu = new EusbRequestPdu();
                            if (!PduMarshaler.Unmarshal(data, requestPdu))
                            {
                                return EusbType.UNKNOWN;
                            }
                            switch ((FunctionId_Values)requestPdu.FunctionId)
                            {
                                case FunctionId_Values.ADD_DEVICE:
                                    return EusbType.ADD_DEVICE;
                                case FunctionId_Values.ADD_VIRTUAL_CHANNEL:
                                    return EusbType.ADD_VIRTUAL_CHANNEL;
                                default:
                                    break;
                            }
                        }
                        else if (pdu.InterfaceId == (uint)EusbInterfaceId_Values.CHANNEL_CREATED_CLIENT)
                        {
                            return EusbType.CHANNEL_CREATED;
                        }
                        else
                        {
                            EusbRequestPdu requestPdu = new EusbRequestPdu();
                            if (!PduMarshaler.Unmarshal(data, requestPdu))
                            {
                                return EusbType.UNKNOWN;
                            }

                            if (requestPdu.InterfaceId == RequestCompletionInterfaceId)
                            {
                                switch ((FunctionId_Values)requestPdu.FunctionId)
                                {
                                    case FunctionId_Values.IOCONTROL_COMPLETION:
                                        return EusbType.IOCONTROL_COMPLETION;
                                    case FunctionId_Values.URB_COMPLETION:
                                        return EusbType.URB_COMPLETION;
                                    case FunctionId_Values.URB_COMPLETION_NO_DATA:
                                        return EusbType.URB_COMPLETION_NO_DATA;
                                    default:
                                        break;
                                }
                            }
                        }
                    }
                    break;
                case Mask_Values.STREAM_ID_STUB:
                    {
                        return EusbType.QUERY_DEVICE_TEXT;
                    }
                default:
                    return EusbType.UNKNOWN;
            }
            return EusbType.UNKNOWN;
        }
コード例 #2
0
        private void SendPdu(EusbPdu pdu, DynamicVirtualChannel channel)
        {
            Site.Assume.IsNotNull(channel, "DynamicVirtualChannel must be initialized.");

            channel.Send(PduMarshaler.Marshal(pdu));

            Site.Log.Add(LogEntryKind.Debug, "Sending {0}: \r\n{1}\r\n", pdu.GetType().ToString(), pdu.ToString());
        }
コード例 #3
0
 private void LogPdu(EusbPdu pdu)
 {
     Site.Log.Add(LogEntryKind.Debug, "{0}\r\n{1}\r\n", pdu.GetType().ToString(), pdu.ToString());
 }
コード例 #4
0
        public static void VerifyResponse(EusbPdu request, EusbPdu responseToBeVerified)
        {
            if (!NeedVerify)
            {
                return;
            }

            if (responseToBeVerified is EusbIoControlCompletionPdu)
            {
                Site.Assert.IsInstanceOfType(
                    request,
                    typeof(EusbRegisterRequestCallbackPdu),
                    "The request must be type of EusbRegisterRequestCallbackPdu"
                    );
            }
        }
コード例 #5
0
        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;
        }
コード例 #6
0
        private USB_STRING_DESCRIPTOR ParseStringDescriptor(EusbPdu pdu)
        {
            if (pdu is EusbUrbCompletionNoDataPdu)
            {
                Site.Log.Add(
                    LogEntryKind.Debug,
                    "Unexpectedly received an EusbUrbCompletionNoDataPdu message: {0}",
                    pdu
                    );
                return null;
            }

            Site.Assert.IsInstanceOfType(
                pdu,
                typeof(EusbUrbCompletionPdu),
                "Must receive an EusbUrbCompletionPdu message."
                );

            EusbUrbCompletionPdu completionPdu = (EusbUrbCompletionPdu)pdu;

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

            USB_STRING_DESCRIPTOR res = UsbStructParser.Parse<USB_STRING_DESCRIPTOR>(completionPdu);

            Site.Assert.IsNotNull(res, "USB_STRING_DESCRIPTOR cannot be parsed from EusbUrbCompletionPdu");
            return res;
        }