/// <summary>
        /// Decode MCS Connect Initial PDU with GCC Conference Create Initial
        /// </summary>
        /// <param name="data">data to be parsed</param>
        /// <returns>Decoded MCS Connect Initial PDU with GCC Conference Create Initial</returns>
        public StackPacket DecodeMcsConnectInitialPDU(byte[] data)
        {
            // initialize
            int currentIndex = 0;
            Client_MCS_Connect_Initial_Pdu_with_GCC_Conference_Create_Request pdu =
                new Client_MCS_Connect_Initial_Pdu_with_GCC_Conference_Create_Request();

            // McsConnectResponse: TpktHeader
            pdu.tpktHeader = ParseTpktHeader(data, ref currentIndex);

            // McsConnectResponse: X224
            pdu.x224Data = ParseX224Data(data, ref currentIndex);

            // T125 Data: decode McsConnectResponse
            int t125DataLength = data.Length - currentIndex;
            if (t125DataLength <= 0)
            {
                throw new FormatException(ConstValue.ERROR_MESSAGE_DATA_INDEX_OUT_OF_RANGE);
            }
            byte[] t125Data = new byte[t125DataLength];
            Array.Copy(data, currentIndex, t125Data, 0, t125Data.Length);
            Connect_Initial mcsConnectInitial = new Connect_Initial();
            Asn1DecodingBuffer decodeBuffer = new Asn1DecodingBuffer(t125Data);
            mcsConnectInitial.BerDecode(decodeBuffer);

            // McsConnectResponse:result
            pdu.mcsCi.targetParameters.maxChannelIds = (long)mcsConnectInitial.targetParameters.maxChannelIds.Value;
            pdu.mcsCi.targetParameters.maxHeight = (long)mcsConnectInitial.targetParameters.maxHeight.Value;
            pdu.mcsCi.targetParameters.maxMcsPduSize = (long)mcsConnectInitial.targetParameters.maxMCSPDUsize.Value;
            pdu.mcsCi.targetParameters.maxTokenIds = (long)mcsConnectInitial.targetParameters.maxTokenIds.Value;
            pdu.mcsCi.targetParameters.maxUserIds = (long)mcsConnectInitial.targetParameters.maxUserIds.Value;
            pdu.mcsCi.targetParameters.minThroughput = (long)mcsConnectInitial.targetParameters.minThroughput.Value;
            pdu.mcsCi.targetParameters.numPriorities = (long)mcsConnectInitial.targetParameters.numPriorities.Value;
            pdu.mcsCi.targetParameters.protocolVersion = (long)mcsConnectInitial.targetParameters.protocolVersion.Value;

            pdu.mcsCi.minimumParameters.maxChannelIds = (long)mcsConnectInitial.minimumParameters.maxChannelIds.Value;
            pdu.mcsCi.minimumParameters.maxHeight = (long)mcsConnectInitial.minimumParameters.maxHeight.Value;
            pdu.mcsCi.minimumParameters.maxMcsPduSize = (long)mcsConnectInitial.minimumParameters.maxMCSPDUsize.Value;
            pdu.mcsCi.minimumParameters.maxTokenIds = (long)mcsConnectInitial.minimumParameters.maxTokenIds.Value;
            pdu.mcsCi.minimumParameters.maxUserIds = (long)mcsConnectInitial.minimumParameters.maxUserIds.Value;
            pdu.mcsCi.minimumParameters.minThroughput = (long)mcsConnectInitial.minimumParameters.minThroughput.Value;
            pdu.mcsCi.minimumParameters.numPriorities = (long)mcsConnectInitial.minimumParameters.numPriorities.Value;
            pdu.mcsCi.minimumParameters.protocolVersion = (long)mcsConnectInitial.minimumParameters.protocolVersion.Value;

            pdu.mcsCi.maximumParameters.maxChannelIds = (long)mcsConnectInitial.maximumParameters.maxChannelIds.Value;
            pdu.mcsCi.maximumParameters.maxHeight = (long)mcsConnectInitial.maximumParameters.maxHeight.Value;
            pdu.mcsCi.maximumParameters.maxMcsPduSize = (long)mcsConnectInitial.maximumParameters.maxMCSPDUsize.Value;
            pdu.mcsCi.maximumParameters.maxTokenIds = (long)mcsConnectInitial.maximumParameters.maxTokenIds.Value;
            pdu.mcsCi.maximumParameters.maxUserIds = (long)mcsConnectInitial.maximumParameters.maxUserIds.Value;
            pdu.mcsCi.maximumParameters.minThroughput = (long)mcsConnectInitial.maximumParameters.minThroughput.Value;
            pdu.mcsCi.maximumParameters.numPriorities = (long)mcsConnectInitial.maximumParameters.numPriorities.Value;
            pdu.mcsCi.maximumParameters.protocolVersion = (long)mcsConnectInitial.maximumParameters.protocolVersion.Value;

            // T125 User Data: get McsConnectResponse's user data
            //byte[] userData = new byte[mcsConnectInitial.userData.Length];
            //Stream mscInput = mcsConnectInitial.userData.toInputStream();
            //mscInput.Read(userData, 0, userData.Length);
            byte[] userData = mcsConnectInitial.userData.ByteArrayValue;

            // T125 User Data: decode McsConnectResponse's user data
            Asn1DecodingBuffer connectDataBuffer = new Asn1DecodingBuffer(userData);
            ConnectData connectData = new ConnectData();
            connectData.PerDecode(connectDataBuffer);

            // Gcc Data: get Gcc data
            int gccDataLength = userData.Length - ConstValue.GCC_CCI_DATA_OFFSET;
            if (gccDataLength <= 0)
            {
                throw new FormatException(ConstValue.ERROR_MESSAGE_DATA_INDEX_OUT_OF_RANGE);
            }
            byte[] gccData = new byte[gccDataLength];
            Array.Copy(userData, ConstValue.GCC_CCI_DATA_OFFSET, gccData, 0, gccData.Length);

            // Gcc Data: decode Gcc data
            ConnectGCCPDU gccPdu = new ConnectGCCPDU();
            Asn1DecodingBuffer gccPduBuffer = new Asn1DecodingBuffer(gccData);
            gccPdu.PerDecode(gccPduBuffer);

            // McsConnectResponse: H221Key
            ConferenceCreateRequest conferenceRequest = (ConferenceCreateRequest)gccPdu.GetData();
            H221NonStandardIdentifier identifier =
                (H221NonStandardIdentifier)conferenceRequest.userData.Elements[0].key.GetData();
            pdu.mcsCi.gccPdu.h221Key = Encoding.ASCII.GetString(identifier.ByteArrayValue);

            // Gcc User Data: get Gcc user data
            byte[] gccUserData = conferenceRequest.userData.Elements[0].value.ByteArrayValue;

            // Reset current index
            currentIndex = 0;
            while (currentIndex < gccUserData.Length)
            {
                // Peek data type
                int tempIndex = currentIndex;
                int orgIndex = currentIndex;
                TS_UD_HEADER_type_Values type =
                    (TS_UD_HEADER_type_Values)ParseUInt16(gccUserData, ref tempIndex, false);
                ushort userDataLength = ParseUInt16(gccUserData, ref tempIndex, false);

                // Parse data by type
                switch (type)
                {
                    case TS_UD_HEADER_type_Values.CS_CORE:
                        pdu.mcsCi.gccPdu.clientCoreData = ParseTsUdCsCore(gccUserData, ref currentIndex, userDataLength);
                        break;

                    case TS_UD_HEADER_type_Values.CS_NET:
                        pdu.mcsCi.gccPdu.clientNetworkData = ParseTsUdCsNet(gccUserData, ref currentIndex);
                        break;

                    case TS_UD_HEADER_type_Values.CS_SECURITY:
                        pdu.mcsCi.gccPdu.clientSecurityData = ParseTsUdCsSec(gccUserData, ref currentIndex);
                        break;

                    case TS_UD_HEADER_type_Values.CS_CLUSTER:
                        pdu.mcsCi.gccPdu.clientClusterData = ParseTsUdCsCluster(gccUserData, ref currentIndex);
                        break;

                    case TS_UD_HEADER_type_Values.CS_MONITOR:
                        pdu.mcsCi.gccPdu.clientMonitorData = ParseTsUdCsMon(gccUserData, ref currentIndex);
                        break;

                    case TS_UD_HEADER_type_Values.CS_MCS_MSGCHANNEL:
                        pdu.mcsCi.gccPdu.clientMessageChannelData = ParseTsUdCsMcsMsgChannel(gccUserData, ref currentIndex);
                        break;

                    case TS_UD_HEADER_type_Values.CS_MULTITRANSPORT:
                        pdu.mcsCi.gccPdu.clientMultitransportChannelData = ParseTsUdCsMultiTransport(gccUserData, ref currentIndex);
                        break;

                    case TS_UD_HEADER_type_Values.CS_MONITOR_EX:
                        pdu.mcsCi.gccPdu.clientMonitorExtendedData = ParseTsUdCsMonitorEX(gccUserData, ref currentIndex);
                        break;

                    default:
                        break;
                    //throw new FormatException(ConstValue.ERROR_MESSAGE_ENUM_UNRECOGNIZED);
                }
                currentIndex = orgIndex + userDataLength;
            }

            // Check if data length exceeded expectation
            VerifyDataLength(gccUserData.Length, currentIndex, ConstValue.ERROR_MESSAGE_DATA_LENGTH_EXCEEDED);
            return pdu;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Encode this structure into byte array.
        /// </summary>
        /// <returns>The byte array of the structure.</returns>
        public override byte[] ToBytes()
        {
            List<byte> totalBuffer = new List<byte>();
            RdpbcgrEncoder.EncodeStructure(totalBuffer, tpktHeader);
            RdpbcgrEncoder.EncodeStructure(totalBuffer, x224Data);

            if (mcsCi != null)
            {
                byte[] gccData = EncodeGccData(mcsCi.gccPdu);

                #region Filling MCS Connect Initial PDU
                Connect_Initial connectInitial = new Connect_Initial();
                connectInitial.calledDomainSelector = new Asn1OctetString(mcsCi.calledDomainSelector);
                connectInitial.callingDomainSelector = new Asn1OctetString(mcsCi.callingDomainSelector);
                connectInitial.upwardFlag = new Asn1Boolean(mcsCi.upwardFlag);

                connectInitial.targetParameters = new DomainParameters(new Asn1Integer(mcsCi.targetParameters.maxChannelIds),
                                                                       new Asn1Integer(mcsCi.targetParameters.maxUserIds),
                                                                       new Asn1Integer(mcsCi.targetParameters.maxTokenIds),
                                                                       new Asn1Integer(mcsCi.targetParameters.numPriorities),
                                                                       new Asn1Integer(mcsCi.targetParameters.minThroughput),
                                                                       new Asn1Integer(mcsCi.targetParameters.maxHeight),
                                                                       new Asn1Integer(mcsCi.targetParameters.maxMcsPduSize),
                                                                       new Asn1Integer(mcsCi.targetParameters.protocolVersion));

                connectInitial.minimumParameters = new DomainParameters(new Asn1Integer(mcsCi.minimumParameters.maxChannelIds),
                                                                        new Asn1Integer(mcsCi.minimumParameters.maxUserIds),
                                                                        new Asn1Integer(mcsCi.minimumParameters.maxTokenIds),
                                                                        new Asn1Integer(mcsCi.minimumParameters.numPriorities),
                                                                        new Asn1Integer(mcsCi.minimumParameters.minThroughput),
                                                                        new Asn1Integer(mcsCi.minimumParameters.maxHeight),
                                                                        new Asn1Integer(mcsCi.minimumParameters.maxMcsPduSize),
                                                                        new Asn1Integer(mcsCi.minimumParameters.protocolVersion));

                connectInitial.maximumParameters = new DomainParameters(new Asn1Integer(mcsCi.maximumParameters.maxChannelIds),
                                                                        new Asn1Integer(mcsCi.maximumParameters.maxUserIds),
                                                                        new Asn1Integer(mcsCi.maximumParameters.maxTokenIds),
                                                                        new Asn1Integer(mcsCi.maximumParameters.numPriorities),
                                                                        new Asn1Integer(mcsCi.maximumParameters.minThroughput),
                                                                        new Asn1Integer(mcsCi.maximumParameters.maxHeight),
                                                                        new Asn1Integer(mcsCi.maximumParameters.maxMcsPduSize),
                                                                        new Asn1Integer(mcsCi.maximumParameters.protocolVersion));

                connectInitial.userData = new Asn1OctetString(gccData);
                #endregion Filling MCS Connect Initial PDU

                #region Encode MCS Connect Initial PDU
                Asn1BerEncodingBuffer berEncodeBuffer = new Asn1BerEncodingBuffer();
                connectInitial.BerEncode(berEncodeBuffer);
                #endregion MCS Connect Initial PDU

                if (berEncodeBuffer.Data != null)
                {
                    RdpbcgrEncoder.EncodeBytes(totalBuffer, berEncodeBuffer.Data);
                }
            }

            return RdpbcgrUtility.ToBytes(totalBuffer);
        }