Microsoft.Protocols.TestSuites.Rdpeusb.RdpeusbTestSutie.S3_EUSB_OperateIo_GetStatus C# (CSharp) Method

S3_EUSB_OperateIo_GetStatus() private method

private S3_EUSB_OperateIo_GetStatus ( ) : void
return void
        public void S3_EUSB_OperateIo_GetStatus()
        {
            LogComment("S3_EUSB_OperateIo_GetStatus");

            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. Registers a callback to provide the Request Completion Interface to the client.");
            uint interfaceId = IdGenerator.NewId();
            rdpeusbAdapter.RegisterCallback(device, 1, interfaceId);

            LogComment("6. Selects the device configuration.");
            SelectConfiguration(device, 0);

            LogComment("7. Retrieves the status from the device by sending TS_URB_CONTROL_GET_STATUS_REQUEST and verifies the response.");
            const uint transferBufferLength = 2;
            const byte low4BitsMask = 0x0F;
            uint requestId;
            EusbPdu pdu;
            EusbUrbCompletionPdu pduRes;
            TS_URB_CONTROL_GET_STATUS_REQUEST req = new TS_URB_CONTROL_GET_STATUS_REQUEST();

            requestId = IdGenerator.NewId();
            req.Header.RequestId = requestId;
            req.Header.URB_Function = URB_FUNCTIONID.URB_FUNCTION_GET_STATUS_FROM_DEVICE;
            req.Index = 0;
            // Sends device status request.
            rdpeusbAdapter.TransferInRequest(device, req, transferBufferLength);

            // Waits for the result.
            pdu = rdpeusbAdapter.ExpectCompletion(device.VirtualChannel);
            Site.Assert.IsInstanceOfType(
                pdu,
                typeof(EusbUrbCompletionPdu),
                "The result must be type of EusbUrbCompletionPdu.");
            pduRes = (EusbUrbCompletionPdu)pdu;
            Site.Assert.IsSuccess((int)pduRes.HResult, "The EusbUrbCompletionNoDataPdu must indicate successful.");
            ReqCapturer.VerifyUrbCompletion(pduRes, req, interfaceId);

            LogComment("The device status is 0x{1:x4}", req.Index, BitConverter.ToUInt16(pduRes.OutputBuffer, 0));

            // TODO: Not sure how to get the index of interfaces and devices. Using any index can result successful responses.
            LogComment("8. Enumerates all interfaces and endpoints of the device and retrieves their status.");
            foreach (TS_USBD_INTERFACE_INFORMATION_RESULT iinf in context.SelectedConfig.Interface)
            {
                requestId = IdGenerator.NewId();
                req.Header.RequestId = requestId;
                req.Header.URB_Function = URB_FUNCTIONID.URB_FUNCTION_GET_STATUS_FROM_INTERFACE;
                req.Index = iinf.InterfaceNumber;
                // Sends interface status request.
                rdpeusbAdapter.TransferInRequest(device, req, transferBufferLength);

                // Waits for the result.
                pdu = rdpeusbAdapter.ExpectCompletion(device.VirtualChannel);
                Site.Assert.IsInstanceOfType(
                    pdu,
                    typeof(EusbUrbCompletionPdu),
                    "The result must be type of EusbUrbCompletionPdu.");
                pduRes = (EusbUrbCompletionPdu)pdu;
                Site.Assert.IsSuccess((int)pduRes.HResult, "The EusbUrbCompletionNoDataPdu must indicate successful.");
                ReqCapturer.VerifyUrbCompletion(pduRes, req, interfaceId);

                LogComment("The interface (index: {0}) status is 0x{1:x4}", req.Index, BitConverter.ToUInt16(pduRes.OutputBuffer, 0));

                foreach (TS_USBD_PIPE_INFORMATION_RESULT pinf in iinf.Pipes)
                {
                    requestId = IdGenerator.NewId();
                    req.Header.RequestId = requestId;
                    req.Header.URB_Function = URB_FUNCTIONID.URB_FUNCTION_GET_STATUS_FROM_ENDPOINT;
                    req.Index = (ushort)(pinf.EndpointAddress & low4BitsMask);
                    // Sends endpoint status request.
                    rdpeusbAdapter.TransferInRequest(device, req, transferBufferLength);

                    // Waits for the result.
                    pdu = rdpeusbAdapter.ExpectCompletion(device.VirtualChannel);
                    Site.Assert.IsInstanceOfType(
                        pdu,
                        typeof(EusbUrbCompletionPdu),
                        "The result must be type of EusbUrbCompletionPdu.");
                    pduRes = (EusbUrbCompletionPdu)pdu;
                    Site.Assert.IsSuccess((int)pduRes.HResult, "The EusbUrbCompletionNoDataPdu must indicate successful.");
                    ReqCapturer.VerifyUrbCompletion(pduRes, req, interfaceId);

                    LogComment("The endpoint (index: {0}) status is 0x{1:x4}", req.Index, BitConverter.ToUInt16(pduRes.OutputBuffer, 0));
                }
            }

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