ReactOS 0.4.15-dev-7942-gd23573b
fdo.c File Reference
#include "serenum.h"
#include <debug.h>
Include dependency graph for fdo.c:

Go to the source code of this file.

Functions

NTSTATUS NTAPI SerenumAddDevice (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT Pdo)
 
static NTSTATUS NTAPI SerenumFdoStartDevice (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
static NTSTATUS SerenumFdoQueryBusRelations (IN PDEVICE_OBJECT DeviceObject, OUT PDEVICE_RELATIONS *pDeviceRelations)
 
NTSTATUS SerenumFdoPnp (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 

Function Documentation

◆ SerenumAddDevice()

NTSTATUS NTAPI SerenumAddDevice ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  Pdo 
)

Definition at line 15 of file fdo.c.

18{
20 PFDO_DEVICE_EXTENSION DeviceExtension;
22
23 TRACE_(SERENUM, "SerenumAddDevice called. Pdo = %p\n", Pdo);
24
25 /* Create new device object */
28 NULL,
31 FALSE,
32 &Fdo);
33 if (!NT_SUCCESS(Status))
34 {
35 WARN_(SERENUM, "IoCreateDevice() failed with status 0x%08lx\n", Status);
36 return Status;
37 }
38 DeviceExtension = (PFDO_DEVICE_EXTENSION)Fdo->DeviceExtension;
39 RtlZeroMemory(DeviceExtension, sizeof(FDO_DEVICE_EXTENSION));
40
41 /* Register device interface */
43 Pdo,
44 &GUID_DEVINTERFACE_SERENUM_BUS_ENUMERATOR,
45 NULL,
46 &DeviceExtension->SerenumInterfaceName);
47 if (!NT_SUCCESS(Status))
48 {
49 WARN_(SERENUM, "IoRegisterDeviceInterface() failed with status 0x%08lx\n", Status);
51 return Status;
52 }
53
54 DeviceExtension->Common.IsFDO = TRUE;
55 DeviceExtension->Common.PnpState = dsStopped;
56 DeviceExtension->Pdo = Pdo;
57 IoInitializeRemoveLock(&DeviceExtension->RemoveLock, SERENUM_TAG, 0, 0);
59 if (!NT_SUCCESS(Status))
60 {
61 WARN_(SERENUM, "IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status);
63 return Status;
64 }
65 if (DeviceExtension->LowerDevice->Flags & DO_POWER_PAGABLE)
66 Fdo->Flags |= DO_POWER_PAGABLE;
67 if (DeviceExtension->LowerDevice->Flags & DO_BUFFERED_IO)
68 Fdo->Flags |= DO_BUFFERED_IO;
69 if (DeviceExtension->LowerDevice->Flags & DO_DIRECT_IO)
70 Fdo->Flags |= DO_DIRECT_IO;
71 Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
72
73 return STATUS_SUCCESS;
74}
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define TRACE_(x)
Definition: compat.h:76
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
Status
Definition: gdiplustypes.h:25
@ dsStopped
Definition: isapnp.h:34
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
NTSTATUS NTAPI IoAttachDeviceToDeviceStackSafe(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice, IN OUT PDEVICE_OBJECT *AttachedToDeviceObject)
Definition: device.c:980
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
#define FILE_DEVICE_BUS_EXTENDER
Definition: winioctl.h:148
#define WARN_(ch,...)
Definition: debug.h:157
#define SERENUM_TAG
Definition: serenum.h:58
#define STATUS_SUCCESS
Definition: shellext.h:65
UNICODE_STRING SerenumInterfaceName
Definition: serenum.h:39
PDEVICE_OBJECT LowerDevice
Definition: i8042prt.h:130
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:84
IO_REMOVE_LOCK RemoveLock
Definition: serenum.h:37
PDEVICE_OBJECT Pdo
Definition: i8042prt.h:128
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_ WDFDRIVER _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT Pdo
Definition: wdfminiport.h:72
#define IoInitializeRemoveLock(Lock, AllocateTag, MaxLockedMinutes, HighWatermark)
Definition: iofuncs.h:2833
#define DO_POWER_PAGABLE

◆ SerenumFdoPnp()

NTSTATUS SerenumFdoPnp ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 152 of file fdo.c.

155{
161
163 MinorFunction = Stack->MinorFunction;
164
165 switch (MinorFunction)
166 {
167 /* FIXME: do all these minor functions
168 IRP_MN_QUERY_REMOVE_DEVICE 0x1
169 IRP_MN_REMOVE_DEVICE 0x2
170 IRP_MN_CANCEL_REMOVE_DEVICE 0x3
171 IRP_MN_STOP_DEVICE 0x4
172 IRP_MN_QUERY_STOP_DEVICE 0x5
173 IRP_MN_CANCEL_STOP_DEVICE 0x6
174 IRP_MN_QUERY_DEVICE_RELATIONS / RemovalRelations (optional) 0x7
175 IRP_MN_QUERY_INTERFACE (optional) 0x8
176 IRP_MN_QUERY_CAPABILITIES (optional) 0x9
177 IRP_MN_QUERY_PNP_DEVICE_STATE (optional) 0x14
178 IRP_MN_DEVICE_USAGE_NOTIFICATION (required or optional) 0x16
179 IRP_MN_SURPRISE_REMOVAL 0x17
180 */
181 case IRP_MN_START_DEVICE: /* 0x0 */
182 {
183 TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_START_DEVICE\n");
184 /* Call lower driver */
185 FdoExtension = DeviceObject->DeviceExtension;
187
188 if (IoForwardIrpSynchronously(FdoExtension->LowerDevice, Irp))
189 {
190 Status = Irp->IoStatus.Status;
191 if (NT_SUCCESS(Status))
192 {
194 }
195 }
196
197 break;
198 }
199 case IRP_MN_QUERY_DEVICE_RELATIONS: /* 0x7 */
200 {
201 switch (Stack->Parameters.QueryDeviceRelations.Type)
202 {
203 case BusRelations:
204 {
205 PDEVICE_RELATIONS DeviceRelations = NULL;
206 TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / BusRelations\n");
208 Information = (ULONG_PTR)DeviceRelations;
209 break;
210 }
211 default:
212 TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / Unknown type 0x%lx\n",
213 Stack->Parameters.QueryDeviceRelations.Type);
215 }
216 break;
217 }
219 {
220 TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n");
222 }
223 default:
224 {
225 TRACE_(SERENUM, "IRP_MJ_PNP / unknown minor function 0x%lx\n", MinorFunction);
227 }
228 }
229
230 Irp->IoStatus.Information = Information;
231 Irp->IoStatus.Status = Status;
233 return Status;
234}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
_In_ PIRP Irp
Definition: csq.h:116
#define ULONG_PTR
Definition: config.h:101
@ FdoExtension
Definition: precomp.h:48
DRIVER_DISPATCH ForwardIrpAndForget
Definition: i8042prt.h:341
#define IoCompleteRequest
Definition: irp.c:1240
BOOLEAN NTAPI IoForwardIrpSynchronously(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1625
static NTSTATUS SerenumFdoQueryBusRelations(IN PDEVICE_OBJECT DeviceObject, OUT PDEVICE_RELATIONS *pDeviceRelations)
Definition: fdo.c:102
static NTSTATUS NTAPI SerenumFdoStartDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.c:77
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ UCHAR _In_ UCHAR MinorFunction
Definition: wdfdevice.h:1699
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1049
@ BusRelations
Definition: iotypes.h:2152
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MN_START_DEVICE
#define IRP_MN_FILTER_RESOURCE_REQUIREMENTS
#define IRP_MN_QUERY_DEVICE_RELATIONS

Referenced by SerenumPnp().

◆ SerenumFdoQueryBusRelations()

static NTSTATUS SerenumFdoQueryBusRelations ( IN PDEVICE_OBJECT  DeviceObject,
OUT PDEVICE_RELATIONS pDeviceRelations 
)
static

Definition at line 102 of file fdo.c.

105{
106 PFDO_DEVICE_EXTENSION DeviceExtension;
107 PDEVICE_RELATIONS DeviceRelations;
108 ULONG NumPDO;
109 ULONG i;
111
112 DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
113 ASSERT(DeviceExtension->Common.IsFDO);
114
115 /* Do enumeration if needed */
116 if (!(DeviceExtension->Flags & FLAG_ENUMERATION_DONE))
117 {
118 ASSERT(DeviceExtension->AttachedPdo == NULL);
119 /* Detect plug-and-play devices */
122 {
123 /* Detect legacy devices */
127 }
128 DeviceExtension->Flags |= FLAG_ENUMERATION_DONE;
129 }
130 NumPDO = (DeviceExtension->AttachedPdo != NULL ? 1 : 0);
131
132 DeviceRelations = (PDEVICE_RELATIONS)ExAllocatePoolWithTag(
133 PagedPool,
134 sizeof(DEVICE_RELATIONS) + sizeof(PDEVICE_OBJECT) * (NumPDO - 1),
136 if (!DeviceRelations)
138
139 /* Fill returned structure */
140 DeviceRelations->Count = NumPDO;
141 for (i = 0; i < NumPDO; i++)
142 {
143 ObReferenceObject(DeviceExtension->AttachedPdo);
144 DeviceRelations->Objects[i] = DeviceExtension->AttachedPdo;
145 }
146
147 *pDeviceRelations = DeviceRelations;
148 return Status;
149}
NTSTATUS SerenumDetectPnpDevice(IN PDEVICE_OBJECT DeviceObject, IN PDEVICE_OBJECT LowerDevice)
Definition: detect.c:223
NTSTATUS SerenumDetectLegacyDevice(IN PDEVICE_OBJECT DeviceObject, IN PDEVICE_OBJECT LowerDevice)
Definition: detect.c:444
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
struct _DEVICE_OBJECT * PDEVICE_OBJECT
#define PagedPool
Definition: env_spec_w32.h:308
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ASSERT(a)
Definition: mode.c:44
#define FLAG_ENUMERATION_DONE
Definition: serenum.h:61
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2163
PDEVICE_OBJECT AttachedPdo[2]
Definition: parport.h:44
#define STATUS_DEVICE_NOT_CONNECTED
Definition: udferr_usr.h:160
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
struct _DEVICE_RELATIONS * PDEVICE_RELATIONS
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by SerenumFdoPnp().

◆ SerenumFdoStartDevice()

static NTSTATUS NTAPI SerenumFdoStartDevice ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)
static

Definition at line 77 of file fdo.c.

80{
81 PFDO_DEVICE_EXTENSION DeviceExtension;
83
84 TRACE_(SERENUM, "SerenumFdoStartDevice() called\n");
85 DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
86
87 ASSERT(DeviceExtension->Common.PnpState == dsStopped);
88
90 if (!NT_SUCCESS(Status))
91 {
92 WARN_(SERENUM, "IoSetDeviceInterfaceState() failed with status 0x%08lx\n", Status);
93 return Status;
94 }
95
96 DeviceExtension->Common.PnpState = dsStarted;
97
98 return STATUS_SUCCESS;
99}
@ dsStarted
Definition: isapnp.h:35
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311

Referenced by SerenumFdoPnp().