PDUHelper.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. namespace ISCSI.Client
  11. {
  12. public class PDUHelper
  13. {
  14. public static uint? GetStatSN(ISCSIPDU pdu)
  15. {
  16. if (pdu is NOPInPDU)
  17. {
  18. return ((NOPInPDU)pdu).StatSN;
  19. }
  20. else if (pdu is SCSIResponsePDU)
  21. {
  22. return ((SCSIResponsePDU)pdu).StatSN;
  23. }
  24. else if (pdu is LoginResponsePDU)
  25. {
  26. return ((LoginResponsePDU)pdu).StatSN;
  27. }
  28. else if (pdu is TextResponsePDU)
  29. {
  30. return ((TextResponsePDU)pdu).StatSN;
  31. }
  32. else if (pdu is SCSIDataInPDU && ((SCSIDataInPDU)pdu).StatusPresent) // RFC 3720: StatSN [..] only have meaningful content if the S bit is set to 1
  33. {
  34. return ((SCSIDataInPDU)pdu).StatSN;
  35. }
  36. else if (pdu is LogoutResponsePDU)
  37. {
  38. return ((LogoutResponsePDU)pdu).StatSN;
  39. }
  40. else if (pdu is ReadyToTransferPDU)
  41. {
  42. return ((ReadyToTransferPDU)pdu).StatSN;
  43. }
  44. else if (pdu is RejectPDU)
  45. {
  46. return ((RejectPDU)pdu).StatSN;
  47. }
  48. return null;
  49. }
  50. public static void SetExpStatSN(ISCSIPDU pdu, uint expStatSN)
  51. {
  52. if (pdu is NOPOutPDU)
  53. {
  54. ((NOPOutPDU)pdu).ExpStatSN = expStatSN;
  55. }
  56. else if (pdu is SCSICommandPDU)
  57. {
  58. ((SCSICommandPDU)pdu).ExpStatSN = expStatSN;
  59. }
  60. else if (pdu is LoginRequestPDU)
  61. {
  62. ((LoginRequestPDU)pdu).ExpStatSN = expStatSN;
  63. }
  64. else if (pdu is TextRequestPDU)
  65. {
  66. ((TextRequestPDU)pdu).ExpStatSN = expStatSN;
  67. }
  68. else if (pdu is SCSIDataOutPDU)
  69. {
  70. ((SCSIDataOutPDU)pdu).ExpStatSN = expStatSN;
  71. }
  72. else if (pdu is LogoutRequestPDU)
  73. {
  74. ((LogoutRequestPDU)pdu).ExpStatSN = expStatSN;
  75. }
  76. }
  77. }
  78. }