TextRequestPDU.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 TextRequestPDU : ISCSIPDU
  14. {
  15. public bool Continue;
  16. public LUNStructure LUN;
  17. public uint TargetTransferTag;
  18. public uint CmdSN;
  19. public uint ExpStatSN;
  20. public string Text;
  21. public TextRequestPDU() : base()
  22. {
  23. OpCode = ISCSIOpCodeName.TextRequest;
  24. }
  25. public TextRequestPDU(byte[] buffer) : base(buffer)
  26. {
  27. Continue = (OpCodeSpecificHeader[0] & 0x40) != 0;
  28. LUN = new LUNStructure(LUNOrOpCodeSpecific, 0);
  29. TargetTransferTag = BigEndianConverter.ToUInt32(OpCodeSpecific, 0);
  30. CmdSN = BigEndianConverter.ToUInt32(OpCodeSpecific, 4);
  31. ExpStatSN = BigEndianConverter.ToUInt32(OpCodeSpecific, 8);
  32. Text = ASCIIEncoding.ASCII.GetString(Data);
  33. }
  34. public override byte[] GetBytes()
  35. {
  36. if (Continue)
  37. {
  38. OpCodeSpecificHeader[0] |= 0x40;
  39. }
  40. LUNOrOpCodeSpecific = LUN.GetBytes();
  41. Array.Copy(BigEndianConverter.GetBytes(TargetTransferTag), 0, OpCodeSpecific, 0, 4);
  42. Array.Copy(BigEndianConverter.GetBytes(CmdSN), 0, OpCodeSpecific, 4, 4);
  43. Array.Copy(BigEndianConverter.GetBytes(ExpStatSN), 0, OpCodeSpecific, 8, 4);
  44. Data = ASCIIEncoding.ASCII.GetBytes(Text);
  45. return base.GetBytes();
  46. }
  47. }
  48. }