ServerResponseHelper.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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.Server
  12. {
  13. internal class ServerResponseHelper
  14. {
  15. internal static NOPInPDU GetNOPResponsePDU(NOPOutPDU request)
  16. {
  17. NOPInPDU response = new NOPInPDU();
  18. response.Data = request.Data;
  19. // When a target receives the NOP-Out with a valid Initiator Task Tag (not the reserved value 0xffffffff),
  20. // it MUST respond with a NOP-In with the same Initiator Task Tag that was provided in the NOP-Out request.
  21. // For such a response, the Target Transfer Tag MUST be 0xffffffff
  22. response.InitiatorTaskTag = request.InitiatorTaskTag;
  23. response.TargetTransferTag = 0xFFFFFFFF;
  24. return response;
  25. }
  26. internal static TextResponsePDU GetTextResponsePDU(TextRequestPDU request, List<ISCSITarget> targets)
  27. {
  28. TextResponsePDU response = new TextResponsePDU();
  29. response.Final = true;
  30. response.InitiatorTaskTag = request.InitiatorTaskTag;
  31. KeyValuePairList<string, string> entries = new KeyValuePairList<string, string>();
  32. foreach (ISCSITarget target in targets)
  33. {
  34. entries.Add("TargetName", target.TargetName);
  35. }
  36. response.Text = KeyValuePairUtils.ToNullDelimitedString(entries);
  37. return response;
  38. }
  39. internal static LogoutResponsePDU GetLogoutResponsePDU(LogoutRequestPDU request)
  40. {
  41. LogoutResponsePDU response = new LogoutResponsePDU();
  42. response.Response = LogoutResponse.ClosedSuccessfully;
  43. response.Final = true;
  44. response.InitiatorTaskTag = request.InitiatorTaskTag;
  45. return response;
  46. }
  47. }
  48. }