Пример #1
0
        public byte[] GetBytes(ulong lun, byte[] data, int offset, int count, bool isFinalData)
        {
            BasicHeaderSegment _basicHeader = new BasicHeaderSegment();

            _basicHeader.Immediate         = true;
            _basicHeader.OpCode            = OpCode.TextRequest;
            _basicHeader.FinalPdu          = isFinalData;
            _basicHeader.TotalAhsLength    = 0;
            _basicHeader.DataSegmentLength = count;
            _basicHeader.InitiatorTaskTag  = _connection.Session.CurrentTaskTag;

            _continue = !isFinalData;
            _lun      = lun;
            _commandSequenceNumber        = _connection.Session.CommandSequenceNumber;
            _expectedStatusSequenceNumber = _connection.ExpectedStatusSequenceNumber;

            byte[] buffer = new byte[Utilities.RoundUp(48 + count, 4)];
            _basicHeader.WriteTo(buffer, 0);
            buffer[1] |= (byte)(_continue ? 0x40 : 0x00);
            Utilities.WriteBytesBigEndian(lun, buffer, 8);
            Utilities.WriteBytesBigEndian(_targetTransferTag, buffer, 20);
            Utilities.WriteBytesBigEndian(_commandSequenceNumber, buffer, 24);
            Utilities.WriteBytesBigEndian(_expectedStatusSequenceNumber, buffer, 28);
            Array.Copy(data, offset, buffer, 48, count);
            return(buffer);
        }
Пример #2
0
        public byte[] GetBytes(ScsiCommand cmd, byte[] immediateData, int offset, int count, bool isFinalData, bool willRead, bool willWrite, uint expected)
        {
            BasicHeaderSegment _basicHeader = new BasicHeaderSegment();
            _basicHeader.Immediate = cmd.ImmediateDelivery;
            _basicHeader.OpCode = OpCode.ScsiCommand;
            _basicHeader.FinalPdu = isFinalData;
            _basicHeader.TotalAhsLength = 0;
            _basicHeader.DataSegmentLength = count;
            _basicHeader.InitiatorTaskTag = _connection.Session.CurrentTaskTag;

            byte[] buffer = new byte[48 + Utilities.RoundUp(count, 4)];
            _basicHeader.WriteTo(buffer, 0);
            buffer[1] = PackAttrByte(isFinalData, willRead, willWrite, cmd.TaskAttributes);
            Utilities.WriteBytesBigEndian(_lun, buffer, 8);
            Utilities.WriteBytesBigEndian(expected, buffer, 20);
            Utilities.WriteBytesBigEndian(_connection.Session.CommandSequenceNumber, buffer, 24);
            Utilities.WriteBytesBigEndian(_connection.ExpectedStatusSequenceNumber, buffer, 28);
            cmd.WriteTo(buffer, 32);

            if (immediateData != null && count != 0)
            {
                Array.Copy(immediateData, offset, buffer, 48, count);
            }

            return buffer;
        }
Пример #3
0
        public byte[] GetBytes(ulong lun, byte[] data, int offset, int count, bool isFinalData)
        {
            BasicHeaderSegment _basicHeader = new BasicHeaderSegment();
            _basicHeader.Immediate = true;
            _basicHeader.OpCode = OpCode.TextRequest;
            _basicHeader.FinalPdu = isFinalData;
            _basicHeader.TotalAhsLength = 0;
            _basicHeader.DataSegmentLength = count;
            _basicHeader.InitiatorTaskTag = _connection.Session.CurrentTaskTag;

            _continue = !isFinalData;
            _lun = lun;
            _commandSequenceNumber = _connection.Session.CommandSequenceNumber;
            _expectedStatusSequenceNumber = _connection.ExpectedStatusSequenceNumber;

            byte[] buffer = new byte[Utilities.RoundUp(48 + count, 4)];
            _basicHeader.WriteTo(buffer, 0);
            buffer[1] |= (byte)(_continue ? 0x40 : 0x00);
            Utilities.WriteBytesBigEndian(lun, buffer, 8);
            Utilities.WriteBytesBigEndian(_targetTransferTag, buffer, 20);
            Utilities.WriteBytesBigEndian(_commandSequenceNumber, buffer, 24);
            Utilities.WriteBytesBigEndian(_expectedStatusSequenceNumber, buffer, 28);
            Array.Copy(data, offset, buffer, 48, count);
            return buffer;
        }
Пример #4
0
        public byte[] GetBytes(ScsiCommand cmd, byte[] immediateData, int offset, int count, bool isFinalData, bool willRead, bool willWrite, uint expected)
        {
            BasicHeaderSegment _basicHeader = new BasicHeaderSegment();

            _basicHeader.Immediate         = cmd.ImmediateDelivery;
            _basicHeader.OpCode            = OpCode.ScsiCommand;
            _basicHeader.FinalPdu          = isFinalData;
            _basicHeader.TotalAhsLength    = 0;
            _basicHeader.DataSegmentLength = count;
            _basicHeader.InitiatorTaskTag  = _connection.Session.CurrentTaskTag;

            byte[] buffer = new byte[48 + Utilities.RoundUp(count, 4)];
            _basicHeader.WriteTo(buffer, 0);
            buffer[1] = PackAttrByte(isFinalData, willRead, willWrite, cmd.TaskAttributes);
            Utilities.WriteBytesBigEndian(_lun, buffer, 8);
            Utilities.WriteBytesBigEndian(expected, buffer, 20);
            Utilities.WriteBytesBigEndian(_connection.Session.CommandSequenceNumber, buffer, 24);
            Utilities.WriteBytesBigEndian(_connection.ExpectedStatusSequenceNumber, buffer, 28);
            cmd.WriteTo(buffer, 32);

            if (immediateData != null && count != 0)
            {
                Array.Copy(immediateData, offset, buffer, 48, count);
            }

            return(buffer);
        }
Пример #5
0
        public byte[] GetBytes(byte[] data, int offset, int count, bool isFinalData, int dataSeqNumber, uint bufferOffset, uint targetTransferTag)
        {
            BasicHeaderSegment _basicHeader = new BasicHeaderSegment();
            _basicHeader.Immediate = false;
            _basicHeader.OpCode = OpCode.ScsiDataOut;
            _basicHeader.FinalPdu = isFinalData;
            _basicHeader.TotalAhsLength = 0;
            _basicHeader.DataSegmentLength = count;
            _basicHeader.InitiatorTaskTag = _connection.Session.CurrentTaskTag;

            byte[] buffer = new byte[48 + Utilities.RoundUp(count, 4)];
            _basicHeader.WriteTo(buffer, 0);
            buffer[1] = (byte)(isFinalData ? 0x80 : 0x00);
            Utilities.WriteBytesBigEndian(_lun, buffer, 8);
            Utilities.WriteBytesBigEndian(targetTransferTag, buffer, 20);
            Utilities.WriteBytesBigEndian(_connection.ExpectedStatusSequenceNumber, buffer, 28);
            Utilities.WriteBytesBigEndian(dataSeqNumber, buffer, 36);
            Utilities.WriteBytesBigEndian(bufferOffset, buffer, 40);

            Array.Copy(data, offset, buffer, 48, count);

            return buffer;
        }
Пример #6
0
        public byte[] GetBytes(byte[] data, int offset, int count, bool isFinalData)
        {
            _basicHeader = new BasicHeaderSegment();
            _basicHeader.Immediate = true;
            _basicHeader.OpCode = OpCode.LoginRequest;
            _basicHeader.FinalPdu = isFinalData;
            _basicHeader.TotalAhsLength = 0;
            _basicHeader.DataSegmentLength = count;
            _basicHeader.InitiatorTaskTag = _connection.Session.CurrentTaskTag;

            _transit = isFinalData;
            _continue = !isFinalData;
            _currentStage = _connection.CurrentLoginStage;
            if (_transit)
            {
                _nextStage = _connection.NextLoginStage;
            }

            _connectionId = _connection.Id;
            _commandSequenceNumber = _connection.Session.CommandSequenceNumber;
            _expectedStatusSequenceNumber = _connection.ExpectedStatusSequenceNumber;

            byte[] buffer = new byte[Utilities.RoundUp(48 + count, 4)];
            _basicHeader.WriteTo(buffer, 0);
            buffer[1] = PackState();
            buffer[2] = 0; // Max Version
            buffer[3] = 0; // Min Version
            Utilities.WriteBytesBigEndian(_connection.Session.InitiatorSessionId, buffer, 8);
            Utilities.WriteBytesBigEndian(IsidQualifier, buffer, 12);
            Utilities.WriteBytesBigEndian(_connection.Session.TargetSessionId, buffer, 14);
            Utilities.WriteBytesBigEndian(_connectionId, buffer, 20);
            Utilities.WriteBytesBigEndian(_commandSequenceNumber, buffer, 24);
            Utilities.WriteBytesBigEndian(_expectedStatusSequenceNumber, buffer, 28);
            Array.Copy(data, offset, buffer, 48, count);
            return buffer;
        }
Пример #7
0
        public byte[] GetBytes(byte[] data, int offset, int count, bool isFinalData, int dataSeqNumber, uint bufferOffset, uint targetTransferTag)
        {
            BasicHeaderSegment _basicHeader = new BasicHeaderSegment();

            _basicHeader.Immediate         = false;
            _basicHeader.OpCode            = OpCode.ScsiDataOut;
            _basicHeader.FinalPdu          = isFinalData;
            _basicHeader.TotalAhsLength    = 0;
            _basicHeader.DataSegmentLength = count;
            _basicHeader.InitiatorTaskTag  = _connection.Session.CurrentTaskTag;

            byte[] buffer = new byte[48 + Utilities.RoundUp(count, 4)];
            _basicHeader.WriteTo(buffer, 0);
            buffer[1] = (byte)(isFinalData ? 0x80 : 0x00);
            Utilities.WriteBytesBigEndian(_lun, buffer, 8);
            Utilities.WriteBytesBigEndian(targetTransferTag, buffer, 20);
            Utilities.WriteBytesBigEndian(_connection.ExpectedStatusSequenceNumber, buffer, 28);
            Utilities.WriteBytesBigEndian(dataSeqNumber, buffer, 36);
            Utilities.WriteBytesBigEndian(bufferOffset, buffer, 40);

            Array.Copy(data, offset, buffer, 48, count);

            return(buffer);
        }
Пример #8
0
        public byte[] GetBytes(byte[] data, int offset, int count, bool isFinalData)
        {
            _basicHeader                   = new BasicHeaderSegment();
            _basicHeader.Immediate         = true;
            _basicHeader.OpCode            = OpCode.LoginRequest;
            _basicHeader.FinalPdu          = isFinalData;
            _basicHeader.TotalAhsLength    = 0;
            _basicHeader.DataSegmentLength = count;
            _basicHeader.InitiatorTaskTag  = _connection.Session.CurrentTaskTag;

            _transit      = isFinalData;
            _continue     = !isFinalData;
            _currentStage = _connection.CurrentLoginStage;
            if (_transit)
            {
                _nextStage = _connection.NextLoginStage;
            }

            _connectionId                 = _connection.Id;
            _commandSequenceNumber        = _connection.Session.CommandSequenceNumber;
            _expectedStatusSequenceNumber = _connection.ExpectedStatusSequenceNumber;

            byte[] buffer = new byte[Utilities.RoundUp(48 + count, 4)];
            _basicHeader.WriteTo(buffer, 0);
            buffer[1] = PackState();
            buffer[2] = 0; // Max Version
            buffer[3] = 0; // Min Version
            Utilities.WriteBytesBigEndian(_connection.Session.InitiatorSessionId, buffer, 8);
            Utilities.WriteBytesBigEndian(IsidQualifier, buffer, 12);
            Utilities.WriteBytesBigEndian(_connection.Session.TargetSessionId, buffer, 14);
            Utilities.WriteBytesBigEndian(_connectionId, buffer, 20);
            Utilities.WriteBytesBigEndian(_commandSequenceNumber, buffer, 24);
            Utilities.WriteBytesBigEndian(_expectedStatusSequenceNumber, buffer, 28);
            Array.Copy(data, offset, buffer, 48, count);
            return(buffer);
        }