Browse Source

API: Added SCSITarget.OnUnitSerialNumberInquiry event

Tal Aloni 8 years ago
parent
commit
bb4b665fbd

+ 1 - 0
ISCSI/ISCSI.csproj

@@ -84,6 +84,7 @@
     <Compile Include="ISCSI.Server\TargetEventArgs\TextRequestArgs.cs" />
     <Compile Include="ISCSI.Server\TargetList.cs" />
     <Compile Include="ISCSI.Server\TargetResponseHelper.cs" />
+    <Compile Include="SCSITarget\InquiryEventArgs\UnitSerialNumberInquiryEventArgs.cs" />
     <Compile Include="SCSI\Enums\AddressingMethod.cs" />
     <Compile Include="SCSI\Enums\ModePageCodeName.cs" />
     <Compile Include="SCSI\Enums\SCSIOpCodeName.cs" />

+ 27 - 0
ISCSI/SCSITarget/InquiryEventArgs/UnitSerialNumberInquiryEventArgs.cs

@@ -0,0 +1,27 @@
+/* Copyright (C) 2016 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
+ * 
+ * You can redistribute this program and/or modify it under the terms of
+ * the GNU Lesser Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ */
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace SCSI
+{
+    public class UnitSerialNumberInquiryEventArgs : EventArgs
+    {
+        public LUNStructure LUN;
+        /// <summary>
+        /// Can be altered by the event subscriber
+        /// </summary>
+        public UnitSerialNumberVPDPage Page;
+
+        public UnitSerialNumberInquiryEventArgs(LUNStructure lun, UnitSerialNumberVPDPage page)
+        {
+            LUN = lun;
+            Page = page;
+        }
+    }
+}

+ 12 - 0
ISCSI/SCSITarget/SCSITarget.cs

@@ -29,6 +29,8 @@ namespace SCSI
 
         public event EventHandler<StandardInquiryEventArgs> OnStandardInquiry;
 
+        public event EventHandler<UnitSerialNumberInquiryEventArgs> OnUnitSerialNumberInquiry;
+
         public event EventHandler<DeviceIdentificationInquiryEventArgs> OnDeviceIdentificationInquiry;
 
         public SCSITarget()
@@ -78,6 +80,16 @@ namespace SCSI
             }
         }
 
+        public void NotifyUnitSerialNumberInquiry(object sender, UnitSerialNumberInquiryEventArgs args)
+        {
+            // To be thread-safe we must capture the delegate reference first
+            EventHandler<UnitSerialNumberInquiryEventArgs> handler = OnUnitSerialNumberInquiry;
+            if (handler != null)
+            {
+                handler(sender, args);
+            }
+        }
+
         public void NotifyDeviceIdentificationInquiry(object sender, DeviceIdentificationInquiryEventArgs args)
         {
             // To be thread-safe we must capture the delegate reference first

+ 1 - 0
ISCSI/SCSITarget/VirtualSCSITarget.cs

@@ -175,6 +175,7 @@ namespace SCSI
                             // Microsoft iSCSI Target uses values such as "34E5A6FC-3ACC-452D-AEDA-6EE2EFF20FB4"
                             ulong serialNumber = 0;
                             page.ProductSerialNumber = serialNumber.ToString("00000000");
+                            NotifyUnitSerialNumberInquiry(this, new UnitSerialNumberInquiryEventArgs(lun, page));
                             response = page.GetBytes();
                             break;
                         }