Example #1
0
        public void Parse(byte[] headerData, int headerOffset, byte[] bodyData)
        {
            Header = new BasicHeaderSegment();
            Header.ReadFrom(headerData, headerOffset);

            if (Header.OpCode != OpCode.ScsiDataIn)
            {
                throw new InvalidProtocolException("Invalid opcode in response, expected " + OpCode.ScsiDataIn + " was " +
                                                   Header.OpCode);
            }

            UnpackFlags(headerData[headerOffset + 1]);
            if (StatusPresent)
            {
                Status = (ScsiStatus)headerData[headerOffset + 3];
            }

            Lun = EndianUtilities.ToUInt64BigEndian(headerData, headerOffset + 8);
            TargetTransferTag             = EndianUtilities.ToUInt32BigEndian(headerData, headerOffset + 20);
            StatusSequenceNumber          = EndianUtilities.ToUInt32BigEndian(headerData, headerOffset + 24);
            ExpectedCommandSequenceNumber = EndianUtilities.ToUInt32BigEndian(headerData, headerOffset + 28);
            MaxCommandSequenceNumber      = EndianUtilities.ToUInt32BigEndian(headerData, headerOffset + 32);
            DataSequenceNumber            = EndianUtilities.ToUInt32BigEndian(headerData, headerOffset + 36);
            BufferOffset  = EndianUtilities.ToUInt32BigEndian(headerData, headerOffset + 40);
            ResidualCount = EndianUtilities.ToUInt32BigEndian(headerData, headerOffset + 44);

            ReadData = bodyData;
        }
Example #2
0
        public void Parse(byte[] headerData, int headerOffset, byte[] bodyData)
        {
            BasicHeaderSegment _headerSegment = new BasicHeaderSegment();

            _headerSegment.ReadFrom(headerData, headerOffset);

            if (_headerSegment.OpCode != OpCode.LoginResponse)
            {
                throw new InvalidProtocolException("Invalid opcode in response, expected " + OpCode.LoginResponse +
                                                   " was " + _headerSegment.OpCode);
            }

            UnpackState(headerData[headerOffset + 1]);
            MaxVersion                    = headerData[headerOffset + 2];
            ActiveVersion                 = headerData[headerOffset + 3];
            TargetSessionId               = Utilities.ToUInt16BigEndian(headerData, headerOffset + 14);
            StatusPresent                 = true;
            StatusSequenceNumber          = Utilities.ToUInt32BigEndian(headerData, headerOffset + 24);
            ExpectedCommandSequenceNumber = Utilities.ToUInt32BigEndian(headerData, headerOffset + 28);
            MaxCommandSequenceNumber      = Utilities.ToUInt32BigEndian(headerData, headerOffset + 32);
            StatusClass                   = headerData[headerOffset + 36];
            StatusCode                    = (LoginStatusCode)Utilities.ToUInt16BigEndian(headerData, headerOffset + 36);

            TextData = bodyData;
        }
Example #3
0
        public void Parse(byte[] headerData, int headerOffset)
        {
            Header = new BasicHeaderSegment();
            Header.ReadFrom(headerData, headerOffset);

            if (Header.OpCode != OpCode.Reject)
            {
                throw new InvalidProtocolException("Invalid opcode in response, expected " + OpCode.Reject + " was " +
                                                   Header.OpCode);
            }

            Reason = (RejectReason)headerData[headerOffset + 2];
            StatusSequenceNumber          = Utilities.ToUInt32BigEndian(headerData, headerOffset + 24);
            ExpectedCommandSequenceNumber = Utilities.ToUInt32BigEndian(headerData, headerOffset + 28);
            MaxCommandSequenceNumber      = Utilities.ToUInt32BigEndian(headerData, headerOffset + 32);
            DataSequenceNumber            = Utilities.ToUInt32BigEndian(headerData, headerOffset + 36);
        }
Example #4
0
        public void Parse(byte[] headerData, int headerOffset)
        {
            BasicHeaderSegment _headerSegment = new BasicHeaderSegment();

            _headerSegment.ReadFrom(headerData, headerOffset);

            if (_headerSegment.OpCode != OpCode.LogoutResponse)
            {
                throw new InvalidProtocolException("Invalid opcode in response, expected " + OpCode.LogoutResponse +
                                                   " was " + _headerSegment.OpCode);
            }

            Response                      = (LogoutResponseCode)headerData[headerOffset + 2];
            StatusSequenceNumber          = EndianUtilities.ToUInt32BigEndian(headerData, headerOffset + 24);
            ExpectedCommandSequenceNumber = EndianUtilities.ToUInt32BigEndian(headerData, headerOffset + 28);
            MaxCommandSequenceNumber      = EndianUtilities.ToUInt32BigEndian(headerData, headerOffset + 32);
            Time2Wait                     = EndianUtilities.ToUInt16BigEndian(headerData, headerOffset + 40);
            Time2Retain                   = EndianUtilities.ToUInt16BigEndian(headerData, headerOffset + 42);
        }
Example #5
0
        public void Parse(byte[] headerData, int headerOffset, byte[] bodyData)
        {
            BasicHeaderSegment _headerSegment = new BasicHeaderSegment();

            _headerSegment.ReadFrom(headerData, headerOffset);

            if (_headerSegment.OpCode != OpCode.TextResponse)
            {
                throw new InvalidProtocolException("Invalid opcode in response, expected " + OpCode.TextResponse +
                                                   " was " + _headerSegment.OpCode);
            }

            Continue                      = (headerData[headerOffset + 1] & 0x40) != 0;
            _lun                          = Utilities.ToUInt64BigEndian(headerData, headerOffset + 8);
            _targetTransferTag            = Utilities.ToUInt32BigEndian(headerData, headerOffset + 20);
            StatusSequenceNumber          = Utilities.ToUInt32BigEndian(headerData, headerOffset + 24);
            ExpectedCommandSequenceNumber = Utilities.ToUInt32BigEndian(headerData, headerOffset + 28);
            MaxCommandSequenceNumber      = Utilities.ToUInt32BigEndian(headerData, headerOffset + 32);

            TextData = bodyData;
        }
Example #6
0
        public void Parse(byte[] headerData, int headerOffset)
        {
            Header = new BasicHeaderSegment();
            Header.ReadFrom(headerData, headerOffset);

            if (Header.OpCode != OpCode.ScsiResponse)
            {
                throw new InvalidProtocolException("Invalid opcode in response, expected " + OpCode.ScsiResponse +
                                                   " was " + Header.OpCode);
            }

            ResponseCode                  = headerData[headerOffset + 2];
            StatusPresent                 = true;
            Status                        = (ScsiStatus)headerData[headerOffset + 3];
            StatusSequenceNumber          = EndianUtilities.ToUInt32BigEndian(headerData, headerOffset + 24);
            ExpectedCommandSequenceNumber = EndianUtilities.ToUInt32BigEndian(headerData, headerOffset + 28);
            MaxCommandSequenceNumber      = EndianUtilities.ToUInt32BigEndian(headerData, headerOffset + 32);
            ExpectedDataSequenceNumber    = EndianUtilities.ToUInt32BigEndian(headerData, headerOffset + 36);
            BidiReadResidualCount         = EndianUtilities.ToUInt32BigEndian(headerData, headerOffset + 40);
            ResidualCount                 = EndianUtilities.ToUInt32BigEndian(headerData, headerOffset + 44);
        }
        public static ProtocolDataUnit ReadFrom(Stream stream, bool headerDigestEnabled, bool dataDigestEnabled)
        {
            int numRead = 0;

            byte[] headerData = Utilities.ReadFully(stream, 48);
            numRead += 48;

            byte[] contentData = null;

            if (headerDigestEnabled)
            {
                uint digest = ReadDigest(stream);
                numRead += 4;
            }

            BasicHeaderSegment bhs = new BasicHeaderSegment();

            bhs.ReadFrom(headerData, 0);

            if (bhs.DataSegmentLength > 0)
            {
                contentData = Utilities.ReadFully(stream, bhs.DataSegmentLength);
                numRead    += bhs.DataSegmentLength;

                if (dataDigestEnabled)
                {
                    uint digest = ReadDigest(stream);
                    numRead += 4;
                }
            }

            int rem = 4 - numRead % 4;

            if (rem != 4)
            {
                Utilities.ReadFully(stream, rem);
            }

            return(new ProtocolDataUnit(headerData, contentData));
        }
Example #8
0
        public void Parse(byte[] headerData, int headerOffset)
        {
            StatusPresent = false;

            Header = new BasicHeaderSegment();
            Header.ReadFrom(headerData, headerOffset);

            if (Header.OpCode != OpCode.ReadyToTransfer)
            {
                throw new InvalidProtocolException("Invalid opcode in response, expected " + OpCode.ReadyToTransfer +
                                                   " was " + Header.OpCode);
            }

            Lun = Utilities.ToUInt64BigEndian(headerData, headerOffset + 8);
            TargetTransferTag             = Utilities.ToUInt32BigEndian(headerData, headerOffset + 20);
            StatusSequenceNumber          = Utilities.ToUInt32BigEndian(headerData, headerOffset + 24);
            ExpectedCommandSequenceNumber = Utilities.ToUInt32BigEndian(headerData, headerOffset + 28);
            MaxCommandSequenceNumber      = Utilities.ToUInt32BigEndian(headerData, headerOffset + 32);
            ReadyToTransferSequenceNumber = Utilities.ToUInt32BigEndian(headerData, headerOffset + 36);
            BufferOffset          = Utilities.ToUInt32BigEndian(headerData, headerOffset + 40);
            DesiredTransferLength = Utilities.ToUInt32BigEndian(headerData, headerOffset + 44);
        }
        public static ProtocolDataUnit ReadFrom(Stream stream, bool headerDigestEnabled, bool dataDigestEnabled)
        {
            int numRead = 0;

            byte[] headerData = Utilities.ReadFully(stream, 48);
            numRead += 48;

            byte[] contentData = null;

            if (headerDigestEnabled)
            {
                uint digest = ReadDigest(stream);
                numRead += 4;
            }

            BasicHeaderSegment bhs = new BasicHeaderSegment();
            bhs.ReadFrom(headerData, 0);

            if (bhs.DataSegmentLength > 0)
            {
                contentData = Utilities.ReadFully(stream, bhs.DataSegmentLength);
                numRead += bhs.DataSegmentLength;

                if (dataDigestEnabled)
                {
                    uint digest = ReadDigest(stream);
                    numRead += 4;
                }
            }

            int rem = 4 - (numRead % 4);
            if (rem != 4)
            {
                Utilities.ReadFully(stream, rem);
            }

            return new ProtocolDataUnit(headerData, contentData);
        }