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; }
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; }
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); }
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; }
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; }