/// <summary> /// Method to send RDPRFX raw data. /// </summary> /// <param name="surfStreamCmd">TS_SURFCMD_STREAM_SURF_BITS to be send.</param> private void SendSurfaceCmd_StreamSurfBits(TS_SURFCMD_STREAM_SURF_BITS surfStreamCmd) { if (rdpbcgrAdapter != null) { rdpbcgrAdapter.SendStreamSurfaceBitsCommand(surfStreamCmd); } else if (this.rdpbcgrServerStack != null && this.rdpbcgrSessionContext != null) { //TS_FRAME_MARKER frameMakerCmdBegin = new TS_FRAME_MARKER(); //frameMakerCmdBegin.cmdType = cmdType_Values.CMDTYPE_FRAME_MARKER; //frameMakerCmdBegin.frameAction = frameAction_Values.SURFACECMD_FRAMEACTION_BEGIN; //frameMakerCmdBegin.frameId = frameIndex; //TS_FRAME_MARKER frameMakerCmdEnd = new TS_FRAME_MARKER(); //frameMakerCmdEnd.cmdType = cmdType_Values.CMDTYPE_FRAME_MARKER; //frameMakerCmdEnd.frameAction = frameAction_Values.SURFACECMD_FRAMEACTION_END; //frameMakerCmdEnd.frameId = frameIndex++; TS_FP_SURFCMDS surfCmds = new TS_FP_SURFCMDS(); surfCmds.updateHeader = (byte)(((int)updateCode_Values.FASTPATH_UPDATETYPE_SURFCMDS & 0x0f) | (((int)fragmentation_Value.FASTPATH_FRAGMENT_SINGLE) << 4) | ((int)compressedType_Values.None << 6)); surfCmds.compressionFlags = compressedType_Values.None; surfCmds.size = (ushort)(8 + 8 + 22 + surfStreamCmd.bitmapData.bitmapDataLength);//size of TS_SURFCMD_STREAM_SURF_BITS; surfCmds.surfaceCommands = new TS_SURFCMD[1]; surfCmds.surfaceCommands[0] = surfStreamCmd; TS_FP_UPDATE_PDU fpOutput; TS_FP_UPDATE[] updates = new TS_FP_UPDATE[1]; updates[0] = surfCmds; fpOutput = rdpbcgrServerStack.CreateFastPathUpdatePdu(rdpbcgrSessionContext, updates); rdpbcgrServerStack.SendPdu(rdpbcgrSessionContext, fpOutput); } }
/// <summary> /// Establish a MultiTransport Connection /// </summary> private void EstablishTransportConnection() { // Send the Server Initial multitransport byte[] securityCookie = new byte[16]; Random rnd = new Random(); rnd.NextBytes(securityCookie); Server_Initiate_Multitransport_Request_PDU requestPDU = rdpbcgrServer.CreateServerInitiateMultitransportRequestPDU(serverSessionContext, ++multitransportId, transportProtocol, securityCookie); rdpbcgrServer.SendPdu(serverSessionContext, requestPDU); //Create RDP-UDP Connection CreateRdpeudpServer(this.serverSessionContext); TransportMode transMode = TransportMode.Reliable; if (transportProtocol == Multitransport_Protocol_value.INITITATE_REQUEST_PROTOCOL_UDPFECL) { transMode = TransportMode.Lossy; } rdpeudpSocket = rdpeudpServer.Accept(((IPEndPoint)serverSessionContext.Identity).Address, transMode, timeout); if (rdpeudpSocket == null) { if (rdpeudpServer != null && rdpeudpServer.Running) { rdpeudpServer.Dispose(); } throw new NotSupportedException("RDPEMT Server create rdpedupSocket failed."); } rdpemtServer = new RdpemtServer(rdpeudpSocket, rdpbcgrServer.AuthCertificate, true); rdpemtServer.Received += ReceivedBytes; uint receivedRequestId; byte[] receivedCookie; if (!rdpemtServer.ExpectConnect(timeout, out receivedRequestId, out receivedCookie)) { throw new ProtocolViolationException("RDPEMT Server Expect Connection failed"); } if (receivedRequestId != multitransportId || receivedCookie == null || receivedCookie.Length != 16) { throw new ProtocolViolationException("RDPEMT Server received a connection with un-expected request id or Cookie is null (or cookie's length is not 16)!"); } for (int i = 0; i < receivedCookie.Length; i++) { if (receivedCookie[i] != securityCookie[i]) { throw new ProtocolViolationException("RDPEMT Server received a connection with un-correct cookie!"); } } }
/// <summary> /// Method to send RDPRFX raw data. /// </summary> /// <param name="surfStreamCmd">TS_SURFCMD_STREAM_SURF_BITS to be send.</param> private void SendSurfaceCmd_StreamSurfBits(TS_SURFCMD_STREAM_SURF_BITS surfStreamCmd) { if (rdpbcgrAdapter != null) { rdpbcgrAdapter.SendStreamSurfaceBitsCommand(surfStreamCmd); } else if (this.rdpbcgrServerStack != null && this.rdpbcgrSessionContext != null) { //TS_FRAME_MARKER frameMakerCmdBegin = new TS_FRAME_MARKER(); //frameMakerCmdBegin.cmdType = cmdType_Values.CMDTYPE_FRAME_MARKER; //frameMakerCmdBegin.frameAction = frameAction_Values.SURFACECMD_FRAMEACTION_BEGIN; //frameMakerCmdBegin.frameId = frameIndex; //TS_FRAME_MARKER frameMakerCmdEnd = new TS_FRAME_MARKER(); //frameMakerCmdEnd.cmdType = cmdType_Values.CMDTYPE_FRAME_MARKER; //frameMakerCmdEnd.frameAction = frameAction_Values.SURFACECMD_FRAMEACTION_END; //frameMakerCmdEnd.frameId = frameIndex++; TS_FP_SURFCMDS surfCmds = new TS_FP_SURFCMDS(); surfCmds.updateHeader = new nested_TS_FP_UPDATE_updateHeader(updateCode_Values.FASTPATH_UPDATETYPE_SURFCMDS); surfCmds.AssignUpdateDataAndSize(); surfCmds.surfaceCommands = new TS_SURFCMD[1]; surfCmds.surfaceCommands[0] = surfStreamCmd; TS_FP_UPDATE_PDU fpOutput; TS_FP_UPDATE[] updates = new TS_FP_UPDATE[1]; updates[0] = surfCmds; surfCmds.updateData = surfCmds.EncodeBody(); fpOutput = rdpbcgrServerStack.CreateFastPathUpdatePdu(rdpbcgrSessionContext, updates); rdpbcgrServerStack.SendPdu(rdpbcgrSessionContext, fpOutput); } }
/// <summary> /// Send a packet /// </summary> /// <param name="packet"></param> private void SendPdu(RdpbcgrServerPdu packet) { rdpbcgrServerStack.SendPdu(sessionContext, packet); }