LogoutRequestPDU.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 LogoutRequestPDU : ISCSIPDU
  14. {
  15. public LogoutReasonCode ReasonCode;
  16. public ushort CID;
  17. public uint CmdSN;
  18. public uint ExpStatSN;
  19. public LogoutRequestPDU() : base()
  20. {
  21. OpCode = ISCSIOpCodeName.LogoutRequest;
  22. Final = true;
  23. }
  24. public LogoutRequestPDU(byte[] buffer, int offset) : base(buffer, offset)
  25. {
  26. ReasonCode = (LogoutReasonCode)(OpCodeSpecificHeader[0] & 0x7F);
  27. CID = BigEndianConverter.ToUInt16(OpCodeSpecific, 0);
  28. CmdSN = BigEndianConverter.ToUInt32(OpCodeSpecific, 4);
  29. ExpStatSN = BigEndianConverter.ToUInt32(OpCodeSpecific, 8);
  30. }
  31. public override byte[] GetBytes()
  32. {
  33. OpCodeSpecificHeader[0] = (byte)ReasonCode; // Final bit will be added by base.GetBytes()
  34. BigEndianWriter.WriteUInt16(OpCodeSpecific, 0, CID);
  35. BigEndianWriter.WriteUInt32(OpCodeSpecific, 4, CmdSN);
  36. BigEndianWriter.WriteUInt32(OpCodeSpecific, 8, ExpStatSN);
  37. return base.GetBytes();
  38. }
  39. }
  40. }