TextRequestPDU.cs 1.8 KB

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