TextResponsePDU.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 TextResponsePDU : ISCSIPDU
  14. {
  15. public bool Continue;
  16. public LUNStructure LUN;
  17. public uint TargetTransferTag;
  18. public uint StatSN;
  19. public uint ExpCmdSN;
  20. public uint MaxCmdSN;
  21. public string Text;
  22. public TextResponsePDU() : base()
  23. {
  24. OpCode = ISCSIOpCodeName.TextResponse;
  25. }
  26. public TextResponsePDU(byte[] buffer) : base(buffer)
  27. {
  28. Continue = (OpCodeSpecificHeader[0] & 0x40) != 0;
  29. LUN = new LUNStructure(LUNOrOpCodeSpecific, 0);
  30. TargetTransferTag = BigEndianConverter.ToUInt32(OpCodeSpecific, 0);
  31. StatSN = BigEndianConverter.ToUInt32(OpCodeSpecific, 4);
  32. ExpCmdSN = BigEndianConverter.ToUInt32(OpCodeSpecific, 8);
  33. MaxCmdSN = BigEndianConverter.ToUInt32(OpCodeSpecific, 12);
  34. Text = ASCIIEncoding.ASCII.GetString(Data);
  35. }
  36. public override byte[] GetBytes()
  37. {
  38. if (Continue)
  39. {
  40. OpCodeSpecificHeader[0] |= 0x40;
  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. Data = ASCIIEncoding.ASCII.GetBytes(Text);
  48. return base.GetBytes();
  49. }
  50. }
  51. }