ReadyToTransferPDU.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 SCSI;
  11. using Utilities;
  12. namespace ISCSI
  13. {
  14. public class ReadyToTransferPDU : ISCSIPDU
  15. {
  16. public LUNStructure LUN;
  17. public uint TargetTransferTag;
  18. public uint StatSN;
  19. public uint ExpCmdSN;
  20. public uint MaxCmdSN;
  21. public uint R2TSN;
  22. public uint BufferOffset;
  23. public uint DesiredDataTransferLength;
  24. public ReadyToTransferPDU()
  25. {
  26. OpCode = ISCSIOpCodeName.ReadyToTransfer;
  27. Final = true;
  28. }
  29. public ReadyToTransferPDU(byte[] buffer, int offset) : base(buffer, offset)
  30. {
  31. LUN = new LUNStructure(LUNOrOpCodeSpecific, 0);
  32. TargetTransferTag = BigEndianConverter.ToUInt32(OpCodeSpecific, 0);
  33. StatSN = BigEndianConverter.ToUInt32(OpCodeSpecific, 4);
  34. ExpCmdSN = BigEndianConverter.ToUInt32(OpCodeSpecific, 8);
  35. MaxCmdSN = BigEndianConverter.ToUInt32(OpCodeSpecific, 12);
  36. R2TSN = BigEndianConverter.ToUInt32(OpCodeSpecific, 16);
  37. BufferOffset = BigEndianConverter.ToUInt32(OpCodeSpecific, 20);
  38. DesiredDataTransferLength = BigEndianConverter.ToUInt32(OpCodeSpecific, 24);
  39. }
  40. public override byte[] GetBytes()
  41. {
  42. LUNOrOpCodeSpecific = LUN.GetBytes();
  43. Array.Copy(BigEndianConverter.GetBytes(TargetTransferTag), 0, OpCodeSpecific, 0, 4);
  44. Array.Copy(BigEndianConverter.GetBytes(StatSN), 0, OpCodeSpecific, 4, 4);
  45. Array.Copy(BigEndianConverter.GetBytes(ExpCmdSN), 0, OpCodeSpecific, 8, 4);
  46. Array.Copy(BigEndianConverter.GetBytes(MaxCmdSN), 0, OpCodeSpecific, 12, 4);
  47. Array.Copy(BigEndianConverter.GetBytes(R2TSN), 0, OpCodeSpecific, 16, 4);
  48. Array.Copy(BigEndianConverter.GetBytes(BufferOffset), 0, OpCodeSpecific, 20, 4);
  49. Array.Copy(BigEndianConverter.GetBytes(DesiredDataTransferLength), 0, OpCodeSpecific, 24, 4);
  50. return base.GetBytes();
  51. }
  52. }
  53. }