예제 #1
0
        /// <summary>
        ///  Constructor. Initialize member variables.
        /// </summary>
        /// <param name="transportConfig">Provides the transport parameters.</param>
        /// <param name="decodePacketCallback">Callback of decoding packet.</param>
        /// <param name="certificate">X509 certificate.</param>
        public RdpbcgrServerTransportStack(
            RdpbcgrServer rdpbcgrServer,
            RdpcbgrServerTransportConfig transportConfig,
            DecodePacketCallback decodePacketCallback,
            X509Certificate2 certificate)
        {
            this.rdpbcgrServer = rdpbcgrServer;
            this.config        = transportConfig;
            if (this.config == null)
            {
                throw new System.InvalidCastException("TcpServerTransport needs SocketTransportConfig.");
            }

            this.decoder     = decodePacketCallback;
            this.packetQueue = new QueueManager();
            this.listenSock  = new Socket(transportConfig.LocalIpAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            this.listenSock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            this.streamType = transportConfig.StreamType;
            IPEndPoint endPoint = new IPEndPoint(config.LocalIpAddress, config.LocalIpPort);

            this.listenSock.Bind(endPoint);
            this.listenSock.Listen(config.MaxConnections);
            this.acceptThread     = new Thread(new ThreadStart(AcceptLoop));
            this.receivingStreams = new Dictionary <Socket, RdpbcgrReceiveThread>();
            this.cert             = certificate;
        }
예제 #2
0
        /// <summary>
        /// Create a new thread to receive the data from remote host.
        /// </summary>
        /// <param name="packetQueueManager">Store all event packets generated in receiving loop.</param>
        /// <param name="decodePacketCallback">Callback of packet decode.</param>
        /// <param name="stream">The stream used to receive data.</param>
        /// <param name="bufferSize">Buffer size used in receiving data.</param>
        public RdpbcgrReceiveThread(
            object endPoint,
            QueueManager packetQueueManager,
            DecodePacketCallback decodePacketCallback,
            Stream stream,
            int bufferSize,
            RdpbcgrServer rdpbcgrServer)
        {
            if (packetQueueManager == null)
            {
                throw new ArgumentNullException("packetQueueManager");
            }

            if (decodePacketCallback == null)
            {
                throw new ArgumentNullException("decodePacketCallback");
            }

            // Initialize variable.
            this.endPointIdentity = endPoint;
            this.packetQueue      = packetQueueManager;
            this.decoder          = decodePacketCallback;
            this.receiveStream    = stream;
            this.maxBufferSize    = bufferSize;
            this.rdpbcgrServer    = rdpbcgrServer;
            this.receivingThread  = new Thread((new ThreadStart(ReceiveLoop)));
        }
 /// <summary>
 /// Accept an existing RDP session which established outside.
 /// </summary>
 /// <param name="rdpbcgrServer">RdpbcgrServer object.</param>
 /// <param name="serverContext">RdpbcgrServerSessionContext object.</param>
 public void Accept(RdpbcgrServer rdpbcgrServer, RdpbcgrServerSessionContext serverContext)
 {
     this.rdpbcgrAdapter        = Site.GetAdapter <IRdpbcgrAdapter>();
     this.rdpbcgrServerStack    = rdpbcgrServer;
     this.rdpbcgrSessionContext = serverContext;
     this.rdpbcgrAdapter.TS_FRAME_ACKNOWLEDGE_PDUReceived += new TS_FRAME_ACKNOWLEDGE_PDUHandler(this.VerifyTS_FRAME_ACKNOWLEDGE_PDU);
 }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="connectedRdpServer"></param>
        /// <param name="context"></param>
        /// <param name="transportType"></param>
        public Rdpemt_DVCServerTransport(RdpbcgrServer connectedRdpServer, RdpbcgrServerSessionContext context, DynamicVC_TransportType transportType)
        {
            this.serverSessionContext = context;
            this.rdpbcgrServer        = connectedRdpServer;
            this.transportProtocol    = Multitransport_Protocol_value.INITITATE_REQUEST_PROTOCOL_UDPFECR;
            if (transportType == DynamicVC_TransportType.RDP_UDP_Lossy)
            {
                this.transportProtocol = Multitransport_Protocol_value.INITITATE_REQUEST_PROTOCOL_UDPFECL;
            }

            if (!serverSessionContext.IsClientMultitransportChannelDataRecieved)
            {
                throw new NotSupportedException("This RDP connection doesn't support multiple transport!");
            }

            try
            {
                EstablishTransportConnection();
            }
            catch (Exception)
            {
                // Ensure resource can be released properly if exception occurred in Constructor
                Dispose();
                // Not suppress the exception, transfer the error to test result.
                throw;
            }

            decoder    = new ServerDecodingPduBuilder();
            pduBuilder = new PduBuilder();
        }
 /// <summary>
 /// Wait for connection.
 /// </summary>
 public void Accept()
 {
     this.rdpbcgrAdapter = Site.GetAdapter<IRdpbcgrAdapter>();
     this.rdpbcgrServerStack = this.rdpbcgrAdapter.ServerStack;
     this.rdpbcgrSessionContext = this.rdpbcgrAdapter.SessionContext;
     this.rdpbcgrAdapter.TS_FRAME_ACKNOWLEDGE_PDUReceived += new TS_FRAME_ACKNOWLEDGE_PDUHandler(this.VerifyTS_FRAME_ACKNOWLEDGE_PDU);
 }
        /// <summary>
        /// Establish a RDP connection to detect RDP feature
        /// </summary>
        /// <returns></returns>
        public bool DetectRDPFeature()
        {
            // Establish a RDP connection with RDP client
            try
            {
                DetectorUtil.WriteLog("Establish RDP connection with SUT...");

                StartRDPListening();
                triggerClientRDPConnect(detectInfo.TriggerMethod);
                EstablishRDPConnection();
                // Set RDP Version
                SetRdpVersion();

                CheckSupportedFeatures();

                CheckSupportedProtocols();
            }
            catch (Exception e)
            {
                DetectorUtil.WriteLog("Exception occured when establishing RDP connection: " + e.Message);
                DetectorUtil.WriteLog("" + e.StackTrace);
                if (e.InnerException != null)
                {
                    DetectorUtil.WriteLog("**" + e.InnerException.Message);
                    DetectorUtil.WriteLog("**" + e.InnerException.StackTrace);
                }
                DetectorUtil.WriteLog("Failed", false, LogStyle.StepFailed);
                return(false);
            }
            finally
            {
                // Trigger client to close the RDP connection
                TriggerClientDisconnectAll(detectInfo.TriggerMethod);

                if (this.rdpedycServer != null)
                {
                    this.rdpedycServer.Dispose();
                    this.rdpedycServer = null;
                }
                if (this.rdpbcgrServerStack != null)
                {
                    this.rdpbcgrServerStack.Dispose();
                    this.rdpbcgrServerStack = null;
                }
            }

            // Notify the UI for establishing RDP connection successfully.
            DetectorUtil.WriteLog("Passed", false, LogStyle.StepPassed);



            return(true);
        }
 /// <summary>
 /// Dispose
 /// </summary>
 public void Dispose()
 {
     if (this.rdpedycServer != null)
     {
         this.rdpedycServer.Dispose();
         this.rdpedycServer = null;
     }
     if (this.rdpbcgrServerStack != null)
     {
         this.rdpbcgrServerStack.Dispose();
         this.rdpbcgrServerStack = null;
     }
 }
예제 #8
0
        /// <summary>
        ///  Constructor. Initialize member variables.
        /// </summary>
        /// <param name="transportConfig">Provides the transport parameters.</param>
        /// <param name="decodePacketCallback">Callback of decoding packet.</param>
        public RdpbcgrServerTransportStack(
            RdpbcgrServer rdpbcgrServer,
            RdpcbgrServerTransportConfig transportConfig,
            DecodePacketCallback decodePacketCallback)
        {
            this.rdpbcgrServer = rdpbcgrServer;
            this.config        = transportConfig;
            if (this.config == null)
            {
                throw new System.InvalidCastException("TcpServerTransport needs SocketTransportConfig.");
            }

            this.decoder     = decodePacketCallback;
            this.packetQueue = new QueueManager();

            this.receivingStreams = new Dictionary <Socket, RdpbcgrReceiveThread>();
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="server"></param>
        /// <param name="context"></param>
        public RdpedycServer(RdpbcgrServer server, RdpbcgrServerSessionContext context, bool autoCloseChannel = true)
        {
            this.rdpbcgrServer = server;
            this.sessionContext = context;
            transportDic = new Dictionary<DynamicVC_TransportType, IDVCTransport>();
            unprocessedDVCPacketBuffer = new List<UnprocessedDVCPDUInfo>();
            Rdpbcgr_DVCServerTransport transport = new Rdpbcgr_DVCServerTransport(context);

            channelDicbyId = new Dictionary<uint, DynamicVirtualChannel>();

            pduBuilder = new PduBuilder();

            transport.Received += ProcessPacketFromTCP;
            transportDic.Add(DynamicVC_TransportType.RDP_TCP, transport);

            this.autoCloseChannel = autoCloseChannel;
        }
예제 #10
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="server"></param>
        /// <param name="context"></param>
        public RdpedycServer(RdpbcgrServer server, RdpbcgrServerSessionContext context, bool autoCloseChannel = true)
        {
            this.rdpbcgrServer         = server;
            this.sessionContext        = context;
            transportDic               = new Dictionary <DynamicVC_TransportType, IDVCTransport>();
            unprocessedDVCPacketBuffer = new List <UnprocessedDVCPDUInfo>();
            Rdpbcgr_DVCServerTransport transport = new Rdpbcgr_DVCServerTransport(context);

            channelDicbyId = new Dictionary <uint, DynamicVirtualChannel>();

            pduBuilder = new PduBuilder();

            transport.Received += ProcessPacketFromTCP;
            transportDic.Add(DynamicVC_TransportType.RDP_TCP, transport);

            this.autoCloseChannel = autoCloseChannel;
        }
        /// <summary>
        /// Start RDP connection.
        /// </summary>
        private void StartRDPConnection(bool useRDPEncryption = false)
        {
            if (useRDPEncryption)
            {
                //if force RDP encryption
                selectedProtocol  = selectedProtocols_Values.PROTOCOL_RDP_FLAG;
                enMethod          = EncryptionMethods.ENCRYPTION_METHOD_128BIT;
                enLevel           = EncryptionLevel.ENCRYPTION_LEVEL_LOW;
                transportProtocol = EncryptedProtocol.Rdp;
            }

            int port = ConstValue.TEST_PORT;

            rdpbcgrServer = new RdpbcgrServer(port, transportProtocol);

            //Start RDP listening.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Starting RDP listening with transport protocol: {0}", transportProtocol.ToString());
            this.rdpbcgrAdapter.StartRDPListening(transportProtocol);


            #region Trigger client to connect
            //Trigger client to connect.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Triggering SUT to initiate a RDP connection to server.");
            triggerClientRDPConnect(transportProtocol);
            #endregion

            #region RDPBCGR Connection

            //Waiting for the transport level connection request.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting the transport layer connection request.");
            this.rdpbcgrAdapter.ExpectTransportConnection(RDPSessionType.Normal);


            //Waiting for the RDP connection sequence.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Establishing RDP connection.");
            this.rdpbcgrAdapter.EstablishRDPConnection(selectedProtocol, enMethod, enLevel, true, false, rdpServerVersion, true);

            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server Save Session Info PDU to SUT to notify user has logged on.");
            this.rdpbcgrAdapter.ServerSaveSessionInfo(LogonNotificationType.UserLoggedOn, ErrorNotificationType_Values.LOGON_FAILED_OTHER);

            #endregion
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="connectedRdpServer"></param>
        /// <param name="context"></param>
        /// <param name="transportType"></param>
        public Rdpemt_DVCServerTransport(RdpbcgrServer connectedRdpServer, RdpbcgrServerSessionContext context, DynamicVC_TransportType transportType)
        {
            this.serverSessionContext = context;
            this.rdpbcgrServer = connectedRdpServer;
            this.transportProtocol = Multitransport_Protocol_value.INITITATE_REQUEST_PROTOCOL_UDPFECR;
            if (transportType == DynamicVC_TransportType.RDP_UDP_Lossy)
            {
                this.transportProtocol = Multitransport_Protocol_value.INITITATE_REQUEST_PROTOCOL_UDPFECL;
            }

            if (!serverSessionContext.IsClientMultitransportChannelDataRecieved)
            {
                throw new NotSupportedException("This RDP connection doesn't support multiple transport!");
            }

            EstablishTransportConnection();

            decoder = new ServerDecodingPduBuilder();
            pduBuilder = new PduBuilder();
        }
예제 #13
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="connectedRdpServer"></param>
        /// <param name="context"></param>
        /// <param name="transportType"></param>
        public Rdpemt_DVCServerTransport(RdpbcgrServer connectedRdpServer, RdpbcgrServerSessionContext context, DynamicVC_TransportType transportType)
        {
            this.serverSessionContext = context;
            this.rdpbcgrServer        = connectedRdpServer;
            this.transportProtocol    = Multitransport_Protocol_value.INITITATE_REQUEST_PROTOCOL_UDPFECR;
            if (transportType == DynamicVC_TransportType.RDP_UDP_Lossy)
            {
                this.transportProtocol = Multitransport_Protocol_value.INITITATE_REQUEST_PROTOCOL_UDPFECL;
            }

            if (!serverSessionContext.IsClientMultitransportChannelDataRecieved)
            {
                throw new NotSupportedException("This RDP connection doesn't support multiple transport!");
            }

            EstablishTransportConnection();

            decoder    = new ServerDecodingPduBuilder();
            pduBuilder = new PduBuilder();
        }
        /// <summary>
        /// Create a new thread to receive the data from remote host.
        /// </summary>
        /// <param name="packetQueueManager">Store all event packets generated in receiving loop.</param>
        /// <param name="decodePacketCallback">Callback of packet decode.</param>
        /// <param name="stream">The stream used to receive data.</param>
        /// <param name="bufferSize">Buffer size used in receiving data.</param>
        public RdpbcgrReceiveThread(
            object endPoint,
            QueueManager packetQueueManager,
            DecodePacketCallback decodePacketCallback,
            Stream stream,
            int bufferSize,
            RdpbcgrServer rdpbcgrServer)
        {
            if (packetQueueManager == null)
            {
                throw new ArgumentNullException("packetQueueManager");
            }

            if (decodePacketCallback == null)
            {
                throw new ArgumentNullException("decodePacketCallback");
            }

            // Initialize variable.
            this.endPointIdentity = endPoint;
            this.packetQueue = packetQueueManager;
            this.decoder = decodePacketCallback;
            this.receiveStream = stream;
            this.maxBufferSize = bufferSize;
            this.rdpbcgrServer = rdpbcgrServer;
            this.receivingThread = new Thread((new ThreadStart(ReceiveLoop)));
        }
        /// <summary>
        ///  Constructor. Initialize member variables.
        /// </summary>
        /// <param name="transportConfig">Provides the transport parameters.</param>
        /// <param name="decodePacketCallback">Callback of decoding packet.</param>
        /// <param name="certificate">X509 certificate.</param>
        public RdpbcgrServerTransportStack(
            RdpbcgrServer rdpbcgrServer,
            RdpcbgrServerTransportConfig transportConfig,
            DecodePacketCallback decodePacketCallback,
            X509Certificate2 certificate)
        {
            this.rdpbcgrServer = rdpbcgrServer;
            this.config = transportConfig;
            if (this.config == null)
            {
                throw new System.InvalidCastException("TcpServerTransport needs SocketTransportConfig.");
            }

            this.decoder = decodePacketCallback;
            this.packetQueue = new QueueManager();
            this.listenSock = new Socket(transportConfig.LocalIpAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            this.streamType = transportConfig.StreamType;
            IPEndPoint endPoint = new IPEndPoint(config.LocalIpAddress, config.LocalIpPort);
            this.listenSock.Bind(endPoint);
            this.listenSock.Listen(config.MaxConnections);
            this.acceptThread = new Thread(new ThreadStart(AcceptLoop));
            this.receivingStreams = new Dictionary<Socket, RdpbcgrReceiveThread>();
            this.cert = certificate;
        }
예제 #16
0
        /// <summary>
        /// Start RDP connection.
        /// </summary>
        private void StartRDPConnection(bool useRDPEncryption = false, bool isSoftSync = false, bool isUDPPreferred = false)
        {
            if (useRDPEncryption)
            {
                //if force RDP encryption
                selectedProtocol  = selectedProtocols_Values.PROTOCOL_RDP_FLAG;
                enMethod          = EncryptionMethods.ENCRYPTION_METHOD_128BIT;
                enLevel           = EncryptionLevel.ENCRYPTION_LEVEL_LOW;
                transportProtocol = EncryptedProtocol.Rdp;
            }

            int port = ConstValue.TEST_PORT;

            rdpbcgrServer = new RdpbcgrServer(port, transportProtocol);

            //Start RDP listening.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Starting RDP listening with transport protocol: {0}", transportProtocol.ToString());
            this.rdpbcgrAdapter.StartRDPListening(transportProtocol);


            #region Trigger client to connect
            //Trigger client to connect.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Triggering SUT to initiate a RDP connection to server.");
            triggerClientRDPConnect(transportProtocol);
            #endregion

            #region RDPBCGR Connection

            //Waiting for the transport level connection request.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting the transport layer connection request.");
            this.rdpbcgrAdapter.ExpectTransportConnection(RDPSessionType.Normal);


            //Waiting for the RDP connection sequence.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Establishing RDP connection.");
            MULTITRANSPORT_TYPE_FLAGS flags = MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDPFECL | MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDPFECR;

            if (isUDPPreferred)
            {
                flags |= MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDP_PREFERRED;
            }

            if (isSoftSync)
            {
                flags |= MULTITRANSPORT_TYPE_FLAGS.SOFTSYNC_TCP_TO_UDP;
            }

            this.rdpbcgrAdapter.EstablishRDPConnection(
                selectedProtocol,
                enMethod,
                enLevel,
                true,
                false,
                rdpServerVersion,
                flags,
                false,
                false);

            if (isSoftSync)
            {
                Site.Assert.IsTrue(this.rdpbcgrAdapter.SessionContext.MultitransportTypeFlagsInMCSConnectIntialPdu.HasFlag(MULTITRANSPORT_TYPE_FLAGS.SOFTSYNC_TCP_TO_UDP),
                                   "Client Should support Soft-Sync, flags: {0}",
                                   this.rdpbcgrAdapter.SessionContext.MultitransportTypeFlagsInMCSConnectIntialPdu);
            }

            if (isUDPPreferred)
            {
                Site.Assert.IsTrue(this.rdpbcgrAdapter.SessionContext.MultitransportTypeFlagsInMCSConnectIntialPdu.HasFlag(MULTITRANSPORT_TYPE_FLAGS.SOFTSYNC_TCP_TO_UDP) &&
                                   this.rdpbcgrAdapter.SessionContext.MultitransportTypeFlagsInMCSConnectIntialPdu.HasFlag(MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDP_PREFERRED),
                                   "Client Should support SOFTSYNC_TCP_TO_UDP and TRANSPORTTYPE_UDP_PREFERRED, flags: {0}",
                                   this.rdpbcgrAdapter.SessionContext.MultitransportTypeFlagsInMCSConnectIntialPdu);
            }

            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server Save Session Info PDU to SUT to notify user has logged on.");
            this.rdpbcgrAdapter.ServerSaveSessionInfo(LogonNotificationType.UserLoggedOn, ErrorNotificationType_Values.LOGON_FAILED_OTHER);

            #endregion
        }
 /// <summary>
 /// The constructor.
 /// </summary>
 /// <param name="rdpbcgrServer">The server.</param>
 public RdpbcgrServerDecoder(RdpbcgrServer rdpbcgrServer)
 {
     this.server = rdpbcgrServer;
 }
        /// <summary>
        /// Establish a RDP connection to detect RDP feature
        /// </summary>
        /// <returns></returns>
        public bool DetectRDPFeature()
        {
            // Establish a RDP connection with RDP client
            try
            {
                StartRDPListening();
                triggerClientRDPConnect(detectInfo.TriggerMethod);
                EstablishRDPConnection();
            }
            catch (Exception e)
            {
                DetectorUtil.WriteLog("Exception occured when establishing RDP connection: " + e.Message);
                DetectorUtil.WriteLog("" + e.StackTrace);
                if (e.InnerException != null)
                {
                    DetectorUtil.WriteLog("**" + e.InnerException.Message);
                    DetectorUtil.WriteLog("**" + e.InnerException.StackTrace);
                }
                DetectorUtil.WriteLog("Failed", false, LogStyle.StepFailed);
                return(false);
            }

            // Notify the UI for establishing RDP connection successfully.
            DetectorUtil.WriteLog("Passed", false, LogStyle.StepPassed);

            // Set result according to messages during connection
            if (mscConnectionInitialPDU.mcsCi.gccPdu.clientCoreData != null && mscConnectionInitialPDU.mcsCi.gccPdu.clientCoreData.earlyCapabilityFlags != null)
            {
                detectInfo.IsSupportNetcharAutoDetect = ((mscConnectionInitialPDU.mcsCi.gccPdu.clientCoreData.earlyCapabilityFlags.actualData & (ushort)earlyCapabilityFlags_Values.RNS_UD_CS_SUPPORT_NETWORK_AUTODETECT)
                                                         == (ushort)earlyCapabilityFlags_Values.RNS_UD_CS_SUPPORT_NETWORK_AUTODETECT);

                detectInfo.IsSupportHeartbeatPdu = ((mscConnectionInitialPDU.mcsCi.gccPdu.clientCoreData.earlyCapabilityFlags.actualData & (ushort)earlyCapabilityFlags_Values.RNS_UD_CS_SUPPORT_HEARTBEAT_PDU)
                                                    == (ushort)earlyCapabilityFlags_Values.RNS_UD_CS_SUPPORT_HEARTBEAT_PDU);
            }
            else
            {
                detectInfo.IsSupportNetcharAutoDetect = false;
                detectInfo.IsSupportHeartbeatPdu      = false;
            }

            // Trigger client to close the RDP connection
            TriggerClientDisconnectAll(detectInfo.TriggerMethod);

            if (detectInfo.IsSupportStaticVirtualChannel != null && detectInfo.IsSupportStaticVirtualChannel.Value)
            {
                detectInfo.IsSupportRDPEUDP = true;
            }
            else
            {
                detectInfo.IsSupportRDPEUDP = false;
            }
            // Notify the UI for detecting protocol supported finished
            DetectorUtil.WriteLog("Passed", false, LogStyle.StepPassed);

            if (this.rdpedycServer != null)
            {
                this.rdpedycServer.Dispose();
                this.rdpedycServer = null;
            }
            if (this.rdpbcgrServerStack != null)
            {
                this.rdpbcgrServerStack.Dispose();
                this.rdpbcgrServerStack = null;
            }

            return(true);
        }
 /// <summary>
 /// Start RDP listening.
 /// </summary>
 private void StartRDPListening()
 {
     rdpbcgrServerStack = new RdpbcgrServer(port, encryptedProtocol, null);
     rdpbcgrServerStack.Start(IPAddress.Any);
 }
        /// <summary>
        /// Start RDP connection.
        /// </summary>
        private void StartRDPConnection(bool useRDPEncryption = false, bool isSoftSync = false, bool isUDPPreferred = false)
        {
            if (useRDPEncryption)
            {
                //if force RDP encryption
                selectedProtocol = selectedProtocols_Values.PROTOCOL_RDP_FLAG;
                enMethod = EncryptionMethods.ENCRYPTION_METHOD_128BIT;
                enLevel = EncryptionLevel.ENCRYPTION_LEVEL_LOW;
                transportProtocol = EncryptedProtocol.Rdp;
            }

            int port = ConstValue.TEST_PORT;
            rdpbcgrServer = new RdpbcgrServer(port, transportProtocol);

            //Start RDP listening.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Starting RDP listening with transport protocol: {0}", transportProtocol.ToString());
            this.rdpbcgrAdapter.StartRDPListening(transportProtocol);

            #region Trigger client to connect
            //Trigger client to connect.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Triggering SUT to initiate a RDP connection to server.");
            triggerClientRDPConnect(transportProtocol);
            #endregion

            #region RDPBCGR Connection

            //Waiting for the transport level connection request.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting the transport layer connection request.");
            this.rdpbcgrAdapter.ExpectTransportConnection(RDPSessionType.Normal);

            //Waiting for the RDP connection sequence.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Establishing RDP connection.");
            MULTITRANSPORT_TYPE_FLAGS flags = MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDPFECL | MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDPFECR;

            if (isUDPPreferred)
            {
                flags |= MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDP_PREFERRED;
            }

            if (isSoftSync)
            {
                flags |= MULTITRANSPORT_TYPE_FLAGS.SOFTSYNC_TCP_TO_UDP;
            }

            this.rdpbcgrAdapter.EstablishRDPConnection(
                selectedProtocol,
                enMethod,
                enLevel,
                true,
                false,
                rdpServerVersion,
                flags,
                false,
                false);

            if (isSoftSync)
            {
                Site.Assert.IsTrue(this.rdpbcgrAdapter.SessionContext.MultitransportTypeFlagsInMCSConnectIntialPdu.HasFlag(MULTITRANSPORT_TYPE_FLAGS.SOFTSYNC_TCP_TO_UDP),
                   "Client Should support Soft-Sync, flags: {0}",
                   this.rdpbcgrAdapter.SessionContext.MultitransportTypeFlagsInMCSConnectIntialPdu);
            }

            if (isUDPPreferred)
            {
                Site.Assert.IsTrue(this.rdpbcgrAdapter.SessionContext.MultitransportTypeFlagsInMCSConnectIntialPdu.HasFlag(MULTITRANSPORT_TYPE_FLAGS.SOFTSYNC_TCP_TO_UDP)
                    && this.rdpbcgrAdapter.SessionContext.MultitransportTypeFlagsInMCSConnectIntialPdu.HasFlag(MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDP_PREFERRED),
                   "Client Should support SOFTSYNC_TCP_TO_UDP and TRANSPORTTYPE_UDP_PREFERRED, flags: {0}",
                   this.rdpbcgrAdapter.SessionContext.MultitransportTypeFlagsInMCSConnectIntialPdu);
            }

            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server Save Session Info PDU to SUT to notify user has logged on.");
            this.rdpbcgrAdapter.ServerSaveSessionInfo(LogonNotificationType.UserLoggedOn, ErrorNotificationType_Values.LOGON_FAILED_OTHER);

            #endregion
        }
        /// <summary>
        /// Establish a RDP connection to detect RDP feature
        /// </summary>
        /// <returns></returns>
        public bool DetectRDPFeature()
        {
            // Establish a RDP connection with RDP client
            try
            {
                StartRDPListening();
                triggerClientRDPConnect(detectInfo.TriggerMethod);
                EstablishRDPConnection();
            }
            catch (Exception e)
            {
                DetectorUtil.WriteLog("Exception occured when establishing RDP connection: " + e.Message);
                DetectorUtil.WriteLog("" + e.StackTrace);
                if (e.InnerException != null)
                {
                    DetectorUtil.WriteLog("**" + e.InnerException.Message);
                    DetectorUtil.WriteLog("**" + e.InnerException.StackTrace);
                }
                DetectorUtil.WriteLog("Failed", false, LogStyle.StepFailed);
                return(false);
            }

            // Notify the UI for establishing RDP connection successfully.
            DetectorUtil.WriteLog("Passed", false, LogStyle.StepPassed);

            // Set result according to messages during connection
            if (mscConnectionInitialPDU.mcsCi.gccPdu.clientCoreData != null && mscConnectionInitialPDU.mcsCi.gccPdu.clientCoreData.earlyCapabilityFlags != null)
            {
                detectInfo.IsSupportNetcharAutoDetect = ((mscConnectionInitialPDU.mcsCi.gccPdu.clientCoreData.earlyCapabilityFlags.actualData & (ushort)earlyCapabilityFlags_Values.RNS_UD_CS_SUPPORT_NETWORK_AUTODETECT)
                                                         == (ushort)earlyCapabilityFlags_Values.RNS_UD_CS_SUPPORT_NETWORK_AUTODETECT);

                detectInfo.IsSupportRDPEGFX = ((mscConnectionInitialPDU.mcsCi.gccPdu.clientCoreData.earlyCapabilityFlags.actualData & (ushort)earlyCapabilityFlags_Values.RNS_UD_CS_SUPPORT_DYNVC_GFX_PROTOCOL)
                                               == (ushort)earlyCapabilityFlags_Values.RNS_UD_CS_SUPPORT_DYNVC_GFX_PROTOCOL);

                detectInfo.IsSupportHeartbeatPdu = ((mscConnectionInitialPDU.mcsCi.gccPdu.clientCoreData.earlyCapabilityFlags.actualData & (ushort)earlyCapabilityFlags_Values.RNS_UD_CS_SUPPORT_HEARTBEAT_PDU)
                                                    == (ushort)earlyCapabilityFlags_Values.RNS_UD_CS_SUPPORT_HEARTBEAT_PDU);
            }
            else
            {
                detectInfo.IsSupportNetcharAutoDetect = false;
                detectInfo.IsSupportRDPEGFX           = false;
                detectInfo.IsSupportHeartbeatPdu      = false;
            }

            if (mscConnectionInitialPDU.mcsCi.gccPdu.clientMultitransportChannelData != null)
            {
                detectInfo.IsSupportTransportTypeUdpFECR = (mscConnectionInitialPDU.mcsCi.gccPdu.clientMultitransportChannelData.flags.HasFlag(MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDPFECR));
                detectInfo.IsSupportTransportTypeUdpFECL = (mscConnectionInitialPDU.mcsCi.gccPdu.clientMultitransportChannelData.flags.HasFlag(MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDPFECL));
            }
            else
            {
                detectInfo.IsSupportTransportTypeUdpFECR = false;
                detectInfo.IsSupportTransportTypeUdpFECL = false;
            }

            if (mscConnectionInitialPDU.mcsCi.gccPdu.clientClusterData != null)
            {
                detectInfo.IsSupportServerRedirection = (mscConnectionInitialPDU.mcsCi.gccPdu.clientClusterData.Flags.HasFlag(Flags_Values.REDIRECTION_SUPPORTED));
            }
            else
            {
                detectInfo.IsSupportServerRedirection = false;
            }

            if (mscConnectionInitialPDU.mcsCi.gccPdu.clientNetworkData != null && mscConnectionInitialPDU.mcsCi.gccPdu.clientNetworkData.channelCount > 0)
            {
                detectInfo.IsSupportStaticVirtualChannel = true;
            }
            else
            {
                detectInfo.IsSupportStaticVirtualChannel = false;
            }

            TS_GENERAL_CAPABILITYSET generalCapSet = (TS_GENERAL_CAPABILITYSET)this.clientCapSet.FindCapSet(capabilitySetType_Values.CAPSTYPE_GENERAL);

            if (generalCapSet.extraFlags.HasFlag(extraFlags_Values.AUTORECONNECT_SUPPORTED))
            {
                detectInfo.IsSupportAutoReconnect = true;
            }
            else
            {
                detectInfo.IsSupportAutoReconnect = false;
            }

            detectInfo.IsSupportRDPRFX = false;
            ITsCapsSet codecCapSet = this.clientCapSet.FindCapSet(capabilitySetType_Values.CAPSETTYPE_BITMAP_CODECS);

            if (codecCapSet != null)
            {
                foreach (TS_BITMAPCODEC codec in ((TS_BITMAPCODECS_CAPABILITYSET)codecCapSet).supportedBitmapCodecs.bitmapCodecArray)
                {
                    if (is_REMOTEFX_CODEC_GUID(codec.codecGUID))
                    {
                        detectInfo.IsSupportRDPRFX = true;
                        break;
                    }
                }
            }
            if (detectInfo.IsSupportRDPRFX.Value)
            {
                ITsCapsSet surfcmdCapSet = this.clientCapSet.FindCapSet(capabilitySetType_Values.CAPSETTYPE_SURFACE_COMMANDS);
                if (!((TS_SURFCMDS_CAPABILITYSET)surfcmdCapSet).cmdFlags.HasFlag(CmdFlags_Values.SURFCMDS_STREAMSURFACEBITS))
                {
                    detectInfo.IsSupportRDPRFX = false;
                }
            }
            // Notify the UI for detecting feature finished
            DetectorUtil.WriteLog("Passed", false, LogStyle.StepPassed);
            detectInfo.IsSupportRDPEFS = false;
            if (mscConnectionInitialPDU.mcsCi.gccPdu.clientNetworkData != null && mscConnectionInitialPDU.mcsCi.gccPdu.clientNetworkData.channelCount > 0)
            {
                List <CHANNEL_DEF> channels = mscConnectionInitialPDU.mcsCi.gccPdu.clientNetworkData.channelDefArray;
                foreach (CHANNEL_DEF channel in channels)
                {
                    if (channel.name.ToUpper().Contains("RDPDR"))
                    {
                        detectInfo.IsSupportRDPEFS = true;
                        break;
                    }
                }
            }

            // Create Dynamic Virtual Channels to detect protocols supported
            detectInfo.IsSupportRDPEDISP = (CreateEDYCChannel(RDPDetector.RdpedispChannelName));

            if (detectInfo.IsSupportRDPEGFX != null && detectInfo.IsSupportRDPEGFX.Value)
            {
                detectInfo.IsSupportRDPEGFX = CreateEDYCChannel(RDPDetector.RdpegfxChannelName);
            }

            detectInfo.IsSupportRDPEI = (CreateEDYCChannel(RDPDetector.rdpeiChannelName));

            detectInfo.IsSupportRDPEUSB = (CreateEDYCChannel(RDPDetector.RdpeusbChannelName));

            detectInfo.IsSupportRDPEVOR = (CreateEDYCChannel(RDPDetector.RdpegtChannelName) &&
                                           CreateEDYCChannel(RDPDetector.RdpevorControlChannelName) &&
                                           CreateEDYCChannel(RDPDetector.RdpevorDataChannelName));

            // Trigger client to close the RDP connection
            TriggerClientDisconnectAll(detectInfo.TriggerMethod);

            if (detectInfo.IsSupportStaticVirtualChannel != null && detectInfo.IsSupportStaticVirtualChannel.Value &&
                ((detectInfo.IsSupportTransportTypeUdpFECR != null && detectInfo.IsSupportTransportTypeUdpFECR.Value) ||
                 (detectInfo.IsSupportTransportTypeUdpFECL != null && detectInfo.IsSupportTransportTypeUdpFECL.Value)))
            {
                detectInfo.IsSupportRDPEMT  = true;
                detectInfo.IsSupportRDPEUDP = true;
            }
            else
            {
                detectInfo.IsSupportRDPEMT  = false;
                detectInfo.IsSupportRDPEUDP = false;
            }
            // Notify the UI for detecting protocol supported finished
            DetectorUtil.WriteLog("Passed", false, LogStyle.StepPassed);

            if (this.rdpedycServer != null)
            {
                this.rdpedycServer.Dispose();
                this.rdpedycServer = null;
            }
            if (this.rdpbcgrServerStack != null)
            {
                this.rdpbcgrServerStack.Dispose();
                this.rdpbcgrServerStack = null;
            }

            return(true);
        }
        /// <summary>
        /// Start RDP connection.
        /// </summary>
        private void StartRDPConnection(bool useRDPEncryption = false)
        {
            if (useRDPEncryption)
            {
                //if force RDP encryption
                selectedProtocol = selectedProtocols_Values.PROTOCOL_RDP_FLAG;
                enMethod = EncryptionMethods.ENCRYPTION_METHOD_128BIT;
                enLevel = EncryptionLevel.ENCRYPTION_LEVEL_LOW;
                transportProtocol = EncryptedProtocol.Rdp;
            }

            int port = ConstValue.TEST_PORT;
            rdpbcgrServer = new RdpbcgrServer(port, transportProtocol);

            //Start RDP listening.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Starting RDP listening with transport protocol: {0}", transportProtocol.ToString());
            this.rdpbcgrAdapter.StartRDPListening(transportProtocol);

            #region Trigger client to connect
            //Trigger client to connect.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Triggering SUT to initiate a RDP connection to server.");
            triggerClientRDPConnect(transportProtocol);
            #endregion

            #region RDPBCGR Connection

            //Waiting for the transport level connection request.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting the transport layer connection request.");
            this.rdpbcgrAdapter.ExpectTransportConnection(RDPSessionType.Normal);

            //Waiting for the RDP connection sequence.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Establishing RDP connection.");
            this.rdpbcgrAdapter.EstablishRDPConnection(selectedProtocol, enMethod, enLevel, true, false, rdpServerVersion, true);

            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server Save Session Info PDU to SUT to notify user has logged on.");
            this.rdpbcgrAdapter.ServerSaveSessionInfo(LogonNotificationType.UserLoggedOn, ErrorNotificationType_Values.LOGON_FAILED_OTHER);

            #endregion
        }