TextRequestPDU.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 = String.Empty;
  22. public TextRequestPDU() : base()
  23. {
  24. OpCode = ISCSIOpCodeName.TextRequest;
  25. }
  26. public TextRequestPDU(byte[] buffer, int offset) : base(buffer, offset)
  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. BigEndianWriter.WriteUInt32(OpCodeSpecific, 0, TargetTransferTag);
  43. BigEndianWriter.WriteUInt32(OpCodeSpecific, 4, CmdSN);
  44. BigEndianWriter.WriteUInt32(OpCodeSpecific, 8, ExpStatSN);
  45. Data = ASCIIEncoding.ASCII.GetBytes(Text);
  46. return base.GetBytes();
  47. }
  48. public KeyValuePairList<string, string> TextParameters
  49. {
  50. set
  51. {
  52. Text = KeyValuePairUtils.ToNullDelimitedString(value);
  53. }
  54. }
  55. }
  56. }