Exemplo n.º 1
0
        public Channel(ByteArraySegment bas)
        {
            bas.Length = valueLength;
            value      = BigEndianBitConverter.Big.ToInt32(bas.ActualBytes(), 0, true);

            quality     = new Quality(bas.EncapsulatedBytes(qualityLength));
            bas.Length += qualityLength;
        }
Exemplo n.º 2
0
        public TagFiled(ByteArraySegment bas)
        {
            // set Length not ready
            Code = -1;
            int len = 1;

            bas.Length = len;
            byte tag = bas.ActualBytes()[0];

            Type          = (TagType)(tag & TAG_TYPE_MASK);
            IsConstructed = Convert.ToBoolean(tag & CONSTRUCTED_MASK);

            Code = tag & TAG_CODE_MASK;

            /*
             * When Code == TAG_CODE_MASK, the tag is more
             * than 1 byte, and the first byte change to a leading
             * byte.
             */
            if (Code == MAX_SINGLE_OCTET_TAG_CODE)
            {
                int  code = 0;
                byte succeedOctet;
                bool hasNextOctet = false;
                do
                {
                    code <<= 7;
                    bas.Length++;
                    succeedOctet = bas.EncapsulatedBytes(bas.Length - 1).ActualBytes()[0];
                    code        |= succeedOctet;
                    // If the highest bit == 0, it's the last succeed octet
                    hasNextOctet = Convert.ToBoolean(succeedOctet >> LAST_SUCCEED_OCTET_BIT);
                } while (hasNextOctet);
                Code = code;
            }

            bas.Length = this.BytesCount;
            RawBytes   = bas.ActualBytes();
        }
Exemplo n.º 3
0
        public CotpPacket(ByteArraySegment bas, Packet parent)
        {
            this.ParentPacket = parent;
            header            = bas;

            header.Length = BigEndianBitConverter.Big.ToInt8(new ByteArraySegment(bas.Bytes, bas.Offset, 1).ActualBytes(), 0) +
                            CotpFileds.LengthLength;
            byte num_eot = header.ActualBytes()[CotpFileds.LengthLength + CotpFileds.PduTypeLength];

            this.Type = (TpduType)(BigEndianBitConverter.Big.ToInt8(header.ActualBytes(), 1));
            switch (Type)
            {
            case TpduType.ConnectioinRequest:
                break;

            case TpduType.ConnectionConfirm:
                break;

            case TpduType.DataTransfer:
                TpduNumber   = num_eot & TPDU_NUM_MASK;
                LastDataUnit = Convert.ToBoolean(num_eot >> LAST_DU_BIT);
                break;

            case TpduType.DisconnectionRequest:
                break;

            case TpduType.ExpectedDataTransfer:
                break;

            default:
                break;
            }

            var payload = header.EncapsulatedBytes();

            payloadPacketOrData = new PacketOrByteArraySegment();
            payloadPacketOrData.TheByteArraySegment = payload;
        }
Exemplo n.º 4
0
        /// <summary>
        ///  For a frame with normal TPKT start and segments appended.
        /// </summary>
        /// <param name="payload">Actual payload of this frame</param>
        /// <param name="length">The length that TPKT header indicate(header itself is exclude)</param>
        private void BuildSegments(ByteArraySegment payload, int length)
        {
            HasSegments = true;

            // Let the length of original TKPT payload without segments
            // be input param length which indicate the TPKT's payload length.
            int segLen = payload.Length - length;

            payload.Length = length;

            if (segLen > 0)
            {
                ByteArraySegment segs = payload.EncapsulatedBytes();
                // The rest segments may be the next TPKT beginning which includes TPKT header.
                //  var potentialHeader = segs;// new ByteArraySegment(segs);
                //segs.Length = TpktFileds.TpktHeaderLength;
                // segs may contain multiple TPKT segments
                byte[] headerRawBytes = segs.ActualBytes().Take(TpktFileds.HeaderLength).ToArray();

                TcpPacketType type = (TcpPacketType)(BigEndianBitConverter.Big.ToInt16(headerRawBytes, 0));
                switch (type)
                {
                case TcpPacketType.Tpkt:
                    // LastSegment = false;
                    int tpktLen = BigEndianBitConverter.Big.ToInt16(headerRawBytes,
                                                                    TpktFileds.ReservedLength + TpktFileds.VersionLength
                                                                    );
                    BuildSegments(segs, tpktLen, segLen);
                    break;

                default:
                    break;
                }
            }
            else
            {
                ByteArraySegment segs = new ByteArraySegment(payload.Bytes);
                BuildSegments(segs, this.Length, segs.Length);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// For a frame with leading segment.
        /// </summary>
        /// <param name="segs">The segment without the leading segments</param>
        private void BuildSegments(ByteArraySegment segs, bool referFileds)
        {
            HasSegments = true;
            TcpPacketType type;
            int           segLen = segs.Length;

            if (referFileds)
            {
                segs.Length = fileds.LeadingSegmentLength;
                TpktSegments.Add(new TpktSegment(this.header.ActualBytes(), false));   // possible some refactoring here
                segs = segs.EncapsulatedBytes();
                // refresh the length value
                segLen = segs.Length;   // When succssor's payload has only one segment, it will crash. see X.X.0.115 No.7322, 7325
            }
            if (segLen > 0)
            {
                byte[] potentialHeader = segs.ActualBytes().Take(TpktFileds.HeaderLength).ToArray();
                type = (TcpPacketType)(BigEndianBitConverter.Big.ToInt16(potentialHeader, 0));
                switch (type)
                {
                case TcpPacketType.Tpkt:
                    int tpktLen = BigEndianBitConverter.Big.ToInt16(potentialHeader,
                                                                    TpktFileds.ReservedLength + TpktFileds.VersionLength
                                                                    );
                    // refresh the length value
                    //    segs.Length = segLen;
                    BuildSegments(segs, tpktLen, segLen);
                    break;

                default:
                    break;
                }
            }
            else
            {
                LastSegment = true;
            }
        }
Exemplo n.º 6
0
 public Quality(ByteArraySegment bas) : this(bas.ActualBytes())
 {
 }