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); }
private EusbPdu ExpectRdpeusbPdu(uint channelId, TimeSpan timeout) { lock (receivedDvcData) { if (!receivedDvcData.ContainsKey(channelId)) { receivedDvcData.Add(channelId, new QueueManager()); } } byte[] data = null; try { data = (byte[])(receivedDvcData[channelId].GetObject(ref timeout)); } catch (TimeoutException) { return(null); } if (null == data) { return(null); } EusbPdu pdu = pduParser.ParsePdu(data); return(pdu); }
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); }
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()); }
public void BVT_EUSB_CancelRequest_TransferInRequest() { LogComment("BVT_EUSB_CancelRequest_TransferInRequest"); LogComment("1. Creates the control virtual channel, exchanges capabilities then notifies that the channel is created."); context.ControlChannel = CreateVirtualChannel(); LogComment("2. Receives an add virtual channel request."); rdpeusbAdapter.ExpectAddVirtualChannel(context.ControlChannel); LogComment("3. Creates a new virtual channel for the device."); DynamicVirtualChannel channel = CreateVirtualChannel(); LogComment("4. Receives an add device request."); EusbDeviceContext device = rdpeusbAdapter.ExpectAddDevice(channel); LogComment("5. Register a callback to provide the Request Completion Interface to the client."); uint interfaceId = IdGenerator.NewId(); rdpeusbAdapter.RegisterCallback(device, 1, interfaceId); // TODO: Needs a long processing transfer in request so that the request cannot be completed before cancel is // received. LogComment("6. Sends TS_URB_CONTROL_DESCRIPTOR_REQUEST within a transfer in request."); uint requestId = IdGenerator.NewId(); TS_URB_CONTROL_DESCRIPTOR_REQUEST des = new UrbBuilder( URB_FUNCTIONID.URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE, requestId, 0).BuildDeviceDescriptorRequest(); rdpeusbAdapter.TransferInRequest(device, des, USB_DEVICE_DESCRIPTOR.DefaultSize); LogComment("7. Sends a cancel request with the request ID specified in the transfer in request."); rdpeusbAdapter.CancelRequest(device, requestId); LogComment("8. Expects not to receive a completion message."); EusbPdu pdu = rdpeusbAdapter.ExpectCompletion(device.VirtualChannel); if (null != pdu) { Site.Log.Add( LogEntryKind.Debug, "The Completion message is received. Callback interface ID: {0}, Completion Interface ID: {1}", interfaceId, pdu.InterfaceId ); } LogComment("9. Sends retract device request and the channel for the device is expected to be closed."); rdpeusbAdapter.RetractDevice(device, USB_RETRACT_REASON.UsbRetractReason_BlockedByPolicy); }
public void BVT_EUSB_CancelRequest_InternalIoControl() { LogComment("BVT_EUSB_CancelRequest_InternalIoControl"); LogComment("1. Creates the control virtual channel, exchanges capabilities then notifies that the channel is created."); context.ControlChannel = CreateVirtualChannel(); LogComment("2. Receives an add virtual channel request."); rdpeusbAdapter.ExpectAddVirtualChannel(context.ControlChannel); LogComment("3. Creates a new virtual channel for the device."); DynamicVirtualChannel channel = CreateVirtualChannel(); LogComment("4. Receives an add device request."); EusbDeviceContext device = rdpeusbAdapter.ExpectAddDevice(channel); LogComment("5. Register a callback to provide the Request Completion Interface to the client."); uint interfaceId = IdGenerator.NewId(); rdpeusbAdapter.RegisterCallback(device, 1, interfaceId); // TODO: Needs a long processing internal IO request so that the request cannot be completed before cancel is // received. LogComment("6. Sends an internal IO request."); uint requestId = IdGenerator.NewId(); const uint outputSize = 4; rdpeusbAdapter.InternalIoControl(device, UsbInternalIoControlCode.IOCTL_TSUSBGD_IOCTL_USBDI_QUERY_BUS_TIME, null, outputSize, requestId); LogComment("7. Sends a cancel request with the request ID specified in the IO request."); rdpeusbAdapter.CancelRequest(device, requestId); LogComment("8. Expects not to receive a completion message."); EusbPdu pdu = rdpeusbAdapter.ExpectCompletion(device.VirtualChannel); if (null != pdu) { Site.Log.Add( LogEntryKind.Debug, "The Completion message is received. Callback interface ID: {0}, Completion Interface ID: {1}", interfaceId, pdu.InterfaceId ); } LogComment("9. Sends retract device request and the channel for the device is expected to be closed."); rdpeusbAdapter.RetractDevice(device, USB_RETRACT_REASON.UsbRetractReason_BlockedByPolicy); }
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" ); } }
/// <summary> /// Receives an IOCONTROL_COMPLETION, URB_COMPLETION or URB_COMPLETION_NO_DATA request from the client. /// </summary> /// <param name="channel">The channel to be received in.</param> /// <returns>The received completion PDU. Returns null, if timeout or required .</returns> public EusbPdu ExpectCompletion(DynamicVirtualChannel channel) { EusbPdu pdu = this.rdpeusbServer.ExpectRdpeusbPdu <EusbPdu>(channel.ChannelId, waitTime); if (null == pdu) { return(null); } bool isCompletionPdu = ( (pdu is EusbIoControlCompletionPdu) || (pdu is EusbUrbCompletionPdu) || (pdu is EusbUrbCompletionNoDataPdu) ); Site.Assert.IsTrue(isCompletionPdu, "Expect a completion PDU, current pdu is {0}.", pdu.ToString()); return(pdu); }
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); }
private void LogPdu(EusbPdu pdu) { Site.Log.Add(LogEntryKind.Debug, "{0}\r\n{1}\r\n", pdu.GetType().ToString(), pdu.ToString()); }