[ISAPNP] Implement querying bus information
authorDmitry Borisov <di.sean@protonmail.com>
Thu, 4 Mar 2021 12:47:34 +0000 (18:47 +0600)
committerDmitry Borisov <di.sean@protonmail.com>
Sun, 20 Jun 2021 13:24:25 +0000 (19:24 +0600)
drivers/bus/isapnp/isapnp.c
drivers/bus/isapnp/isapnp.h
drivers/bus/isapnp/pdo.c

index daa53f6..c477fec 100644 (file)
@@ -683,6 +683,7 @@ IsaAddDevice(
     PDEVICE_OBJECT Fdo;
     PISAPNP_FDO_EXTENSION FdoExt;
     NTSTATUS Status;
+    static ULONG BusNumber = 0;
 
     PAGED_CODE();
 
@@ -708,6 +709,7 @@ IsaAddDevice(
     FdoExt->Common.IsFdo = TRUE;
     FdoExt->Common.State = dsStopped;
     FdoExt->DriverObject = DriverObject;
+    FdoExt->BusNumber = BusNumber++;
     FdoExt->Pdo = PhysicalDeviceObject;
     FdoExt->Ldo = IoAttachDeviceToDeviceStack(Fdo,
                                               PhysicalDeviceObject);
index d22037b..4eb7fb4 100644 (file)
@@ -14,6 +14,9 @@
 #include <section_attribs.h>
 #include "isapnphw.h"
 
+#include <initguid.h>
+#include <wdmguid.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -73,6 +76,7 @@ typedef struct _ISAPNP_FDO_EXTENSION
     PDEVICE_OBJECT Ldo;
     PDEVICE_OBJECT Pdo;
     PDEVICE_OBJECT ReadPortPdo;
+    ULONG BusNumber;
     KEVENT DeviceSyncEvent;
     LIST_ENTRY DeviceListHead;
     ULONG DeviceCount;
index 1227f7c..1fae349 100644 (file)
@@ -483,6 +483,31 @@ IsaPdoRepeatRequest(
     return STATUS_PENDING;
 }
 
+static
+CODE_SEG("PAGE")
+NTSTATUS
+IsaPdoQueryBusInformation(
+    _In_ PISAPNP_PDO_EXTENSION PdoExt,
+    _Inout_ PIRP Irp)
+{
+    PPNP_BUS_INFORMATION BusInformation;
+
+    PAGED_CODE();
+
+    BusInformation = ExAllocatePoolWithTag(PagedPool,
+                                           sizeof(PNP_BUS_INFORMATION),
+                                           TAG_ISAPNP);
+    if (!BusInformation)
+        return STATUS_INSUFFICIENT_RESOURCES;
+
+    BusInformation->BusTypeGuid = GUID_BUS_TYPE_ISAPNP;
+    BusInformation->LegacyBusType = Isa;
+    BusInformation->BusNumber = PdoExt->FdoExt->BusNumber;
+
+    Irp->IoStatus.Information = (ULONG_PTR)BusInformation;
+    return STATUS_SUCCESS;
+}
+
 CODE_SEG("PAGE")
 NTSTATUS
 IsaPdoPnp(
@@ -544,6 +569,10 @@ IsaPdoPnp(
                 Status = IsaReadPortQueryId(Irp, IrpSp);
             break;
 
+        case IRP_MN_QUERY_BUS_INFORMATION:
+            Status = IsaPdoQueryBusInformation(PdoExt, Irp);
+            break;
+
         case IRP_MN_QUERY_REMOVE_DEVICE:
         case IRP_MN_REMOVE_DEVICE:
         case IRP_MN_CANCEL_REMOVE_DEVICE:
@@ -559,7 +588,6 @@ IsaPdoPnp(
         case IRP_MN_WRITE_CONFIG:
         case IRP_MN_EJECT:
         case IRP_MN_SET_LOCK:
-        case IRP_MN_QUERY_BUS_INFORMATION:
         case IRP_MN_DEVICE_USAGE_NOTIFICATION:
             return IsaPdoRepeatRequest(PdoExt, Irp, TRUE);