TextResponsePDU.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 TextResponsePDU : ISCSIPDU
  15. {
  16. public bool Continue;
  17. public LUNStructure LUN;
  18. public uint TargetTransferTag;
  19. public uint StatSN;
  20. public uint ExpCmdSN;
  21. public uint MaxCmdSN;
  22. public string Text = String.Empty;
  23. public TextResponsePDU() : base()
  24. {
  25. OpCode = ISCSIOpCodeName.TextResponse;
  26. }
  27. public TextResponsePDU(byte[] buffer, int offset) : base(buffer, offset)
  28. {
  29. Continue = (OpCodeSpecificHeader[0] & 0x40) != 0;
  30. LUN = new LUNStructure(LUNOrOpCodeSpecific, 0);
  31. TargetTransferTag = BigEndianConverter.ToUInt32(OpCodeSpecific, 0);
  32. StatSN = BigEndianConverter.ToUInt32(OpCodeSpecific, 4);
  33. ExpCmdSN = BigEndianConverter.ToUInt32(OpCodeSpecific, 8);
  34. MaxCmdSN = BigEndianConverter.ToUInt32(OpCodeSpecific, 12);
  35. Text = ASCIIEncoding.ASCII.GetString(Data);
  36. }
  37. public override byte[] GetBytes()
  38. {
  39. if (Continue)
  40. {
  41. OpCodeSpecificHeader[0] |= 0x40;
  42. }
  43. LUNOrOpCodeSpecific = LUN.GetBytes();
  44. BigEndianWriter.WriteUInt32(OpCodeSpecific, 0, TargetTransferTag);
  45. BigEndianWriter.WriteUInt32(OpCodeSpecific, 4, StatSN);
  46. BigEndianWriter.WriteUInt32(OpCodeSpecific, 8, ExpCmdSN);
  47. BigEndianWriter.WriteUInt32(OpCodeSpecific, 12, MaxCmdSN);
  48. Data = ASCIIEncoding.ASCII.GetBytes(Text);
  49. return base.GetBytes();
  50. }
  51. public KeyValuePairList<string, string> TextParameters
  52. {
  53. set
  54. {
  55. Text = KeyValuePairUtils.ToNullDelimitedString(value);
  56. }
  57. }
  58. }
  59. }