ReadyToTransferPDU.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Copyright (C) 2012-2016 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. using Utilities;
  11. namespace ISCSI
  12. {
  13. public class ReadyToTransferPDU : ISCSIPDU
  14. {
  15. public LUNStructure LUN;
  16. public uint TargetTransferTag;
  17. public uint StatSN;
  18. public uint ExpCmdSN;
  19. public uint MaxCmdSN;
  20. public uint R2TSN;
  21. public uint BufferOffset;
  22. public uint DesiredDataTransferLength;
  23. public ReadyToTransferPDU()
  24. {
  25. OpCode = ISCSIOpCodeName.ReadyToTransfer;
  26. Final = true;
  27. }
  28. public ReadyToTransferPDU(byte[] buffer) : base(buffer)
  29. {
  30. LUN = new LUNStructure(LUNOrOpCodeSpecific, 0);
  31. TargetTransferTag = BigEndianConverter.ToUInt32(OpCodeSpecific, 0);
  32. StatSN = BigEndianConverter.ToUInt32(OpCodeSpecific, 4);
  33. ExpCmdSN = BigEndianConverter.ToUInt32(OpCodeSpecific, 8);
  34. MaxCmdSN = BigEndianConverter.ToUInt32(OpCodeSpecific, 12);
  35. R2TSN = BigEndianConverter.ToUInt32(OpCodeSpecific, 16);
  36. BufferOffset = BigEndianConverter.ToUInt32(OpCodeSpecific, 20);
  37. DesiredDataTransferLength = BigEndianConverter.ToUInt32(OpCodeSpecific, 24);
  38. }
  39. public override byte[] GetBytes()
  40. {
  41. LUNOrOpCodeSpecific = LUN.GetBytes();
  42. Array.Copy(BigEndianConverter.GetBytes(TargetTransferTag), 0, OpCodeSpecific, 0, 4);
  43. Array.Copy(BigEndianConverter.GetBytes(StatSN), 0, OpCodeSpecific, 4, 4);
  44. Array.Copy(BigEndianConverter.GetBytes(ExpCmdSN), 0, OpCodeSpecific, 8, 4);
  45. Array.Copy(BigEndianConverter.GetBytes(MaxCmdSN), 0, OpCodeSpecific, 12, 4);
  46. Array.Copy(BigEndianConverter.GetBytes(R2TSN), 0, OpCodeSpecific, 16, 4);
  47. Array.Copy(BigEndianConverter.GetBytes(BufferOffset), 0, OpCodeSpecific, 20, 4);
  48. Array.Copy(BigEndianConverter.GetBytes(DesiredDataTransferLength), 0, OpCodeSpecific, 24, 4);
  49. return base.GetBytes();
  50. }
  51. }
  52. }