ReactOS 0.4.15-dev-8096-ga0eec98
driver.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for driver.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

KSDDKAPI PKSDEVICE NTAPI KsGetDeviceForDeviceObject (IN PDEVICE_OBJECT FunctionalDeviceObject)
 
KSDDKAPI PKSDEVICE NTAPI KsGetDevice (IN PVOID Object)
 
KSDDKAPI NTSTATUS NTAPI KsCreateDevice (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject, IN const KSDEVICE_DESCRIPTOR *Descriptor OPTIONAL, IN ULONG ExtensionSize OPTIONAL, OUT PKSDEVICE *Device OPTIONAL)
 
KSDDKAPI NTSTATUS NTAPI KsAddDevice (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
 
KSDDKAPI NTSTATUS NTAPI KsInitializeDriver (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath, IN const KSDEVICE_DESCRIPTOR *Descriptor OPTIONAL)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file driver.c.

Function Documentation

◆ KsAddDevice()

KSDDKAPI NTSTATUS NTAPI KsAddDevice ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  PhysicalDeviceObject 
)

Definition at line 129 of file driver.c.

132{
133 PKS_DRIVER_EXTENSION DriverObjectExtension;
134 const KSDEVICE_DESCRIPTOR *Descriptor = NULL;
135
136 /* get stored driver object extension */
137
139
140 if (DriverObjectExtension)
141 {
142 /* get the stored descriptor see KsInitializeDriver */
143 Descriptor = DriverObjectExtension->Descriptor;
144 }
145
147}
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1157
#define NULL
Definition: types.h:112
KSDDKAPI NTSTATUS NTAPI KsInitializeDriver(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath, IN const KSDEVICE_DESCRIPTOR *Descriptor OPTIONAL)
Definition: driver.c:155
KSDDKAPI NTSTATUS NTAPI KsCreateDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject, IN const KSDEVICE_DESCRIPTOR *Descriptor OPTIONAL, IN ULONG ExtensionSize OPTIONAL, OUT PKSDEVICE *Device OPTIONAL)
Definition: driver.c:65
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1904
const KSDEVICE_DESCRIPTOR * Descriptor
Definition: kstypes.h:10
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342

Referenced by KsInitializeDriver().

◆ KsCreateDevice()

KSDDKAPI NTSTATUS NTAPI KsCreateDevice ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  PhysicalDeviceObject,
IN const KSDEVICE_DESCRIPTOR *Descriptor  OPTIONAL,
IN ULONG ExtensionSize  OPTIONAL,
OUT PKSDEVICE *Device  OPTIONAL 
)

Definition at line 65 of file driver.c.

71{
74 PDEVICE_OBJECT OldHighestDeviceObject;
75 if (!ExtensionSize)
77
78 DPRINT("KsCreateDevice Descriptor %p ExtensionSize %lu\n", Descriptor, ExtensionSize);
79
81 if (!NT_SUCCESS(Status))
82 return Status;
83
85 if (OldHighestDeviceObject)
86 {
88 }
89 else
90 {
92 }
93
94 /* check if all succeeded */
95 if (!NT_SUCCESS(Status))
96 {
97 if (OldHighestDeviceObject)
98 IoDetachDevice(OldHighestDeviceObject);
99
101 return Status;
102 }
103
104 /* set device flags */
106 FunctionalDeviceObject->Flags &= ~ DO_DEVICE_INITIALIZING;
107
108 if (Device)
109 {
110 /* get PKSDEVICE struct */
112
113 if (ExtensionSize > sizeof(KSDEVICE_HEADER))
114 {
115 /* caller needs a device extension */
116 (*Device)->Context = (PVOID)((ULONG_PTR)FunctionalDeviceObject->DeviceExtension + sizeof(KSDEVICE_HEADER));
117 }
118 }
119
120 return Status;
121}
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
KSDDKAPI NTSTATUS NTAPI KsInitializeDevice(IN PDEVICE_OBJECT FunctionalDeviceObject, IN PDEVICE_OBJECT PhysicalDeviceObject, IN PDEVICE_OBJECT NextDeviceObject, IN const KSDEVICE_DESCRIPTOR *Descriptor OPTIONAL)
Definition: device.c:653
KSDDKAPI PKSDEVICE NTAPI KsGetDeviceForDeviceObject(IN PDEVICE_OBJECT FunctionalDeviceObject)
Definition: driver.c:20
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
Status
Definition: gdiplustypes.h:25
PVOID KSDEVICE_HEADER
Definition: ks.h:1007
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT * FunctionalDeviceObject
Definition: ndis.h:4641
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
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
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define STATUS_DEVICE_REMOVED
Definition: ntstatus.h:809
#define FILE_DEVICE_KS
Definition: winioctl.h:153
WORD ExtensionSize
Definition: apisets.c:17
#define DPRINT
Definition: sndvol32.h:73
PVOID DeviceExtension
Definition: env_spec_w32.h:418
void * PVOID
Definition: typedefs.h:50
uint32_t ULONG_PTR
Definition: typedefs.h:65
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
#define DO_POWER_PAGABLE

Referenced by KsAddDevice().

◆ KsGetDevice()

KSDDKAPI PKSDEVICE NTAPI KsGetDevice ( IN PVOID  Object)

Definition at line 37 of file driver.c.

39{
41
42 DPRINT("KsGetDevice Type %lu KsDevice %p\n", BasicHeader->Type, BasicHeader->KsDevice);
43
44 ASSERT(BasicHeader->Type == KsObjectTypeFilterFactory || BasicHeader->Type == KsObjectTypeFilter || BasicHeader->Type == KsObjectTypePin);
45 ASSERT(BasicHeader->KsDevice);
46 ASSERT(BasicHeader->KsDevice->Descriptor);
47 ASSERT(BasicHeader->KsDevice->Bag);
48 ASSERT(BasicHeader->KsDevice->Context);
49 ASSERT(BasicHeader->KsDevice->FunctionalDeviceObject);
50 ASSERT(BasicHeader->KsDevice->PhysicalDeviceObject);
51 ASSERT(BasicHeader->KsDevice->NextDeviceObject);
52 ASSERT(BasicHeader->KsDevice->Started);
53 ASSERT(BasicHeader->KsDevice->SystemPowerState == PowerSystemWorking);
54 ASSERT(BasicHeader->KsDevice->DevicePowerState == PowerDeviceD0);
55
56 return BasicHeader->KsDevice;
57}
@ KsObjectTypeFilter
Definition: ks.h:1210
@ KsObjectTypePin
Definition: ks.h:1211
@ KsObjectTypeFilterFactory
Definition: ks.h:1209
struct KSBASIC_HEADER * PKSBASIC_HEADER
#define ASSERT(a)
Definition: mode.c:44
@ PowerSystemWorking
Definition: ntpoapi.h:36
@ PowerDeviceD0
Definition: ntpoapi.h:49
PKSDEVICE KsDevice
Definition: kstypes.h:57
KSOBJECTTYPE Type
Definition: kstypes.h:56
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object

◆ KsGetDeviceForDeviceObject()

KSDDKAPI PKSDEVICE NTAPI KsGetDeviceForDeviceObject ( IN PDEVICE_OBJECT  FunctionalDeviceObject)

Definition at line 20 of file driver.c.

22{
23 PDEVICE_EXTENSION DeviceExtension;
24
25 /* get device extension */
27
28 return &DeviceExtension->DeviceHeader->KsDevice;
29}
struct _BEEP_DEVICE_EXTENSION * PDEVICE_EXTENSION

Referenced by KsCreateDevice().

◆ KsInitializeDriver()

KSDDKAPI NTSTATUS NTAPI KsInitializeDriver ( IN PDRIVER_OBJECT  DriverObject,
IN PUNICODE_STRING  RegistryPath,
IN const KSDEVICE_DESCRIPTOR *Descriptor  OPTIONAL 
)

Definition at line 155 of file driver.c.

160{
161 PKS_DRIVER_EXTENSION DriverObjectExtension;
163
164 DPRINT("KsInitializeDriver\n");
165
166 if (Descriptor)
167 {
169 if (NT_SUCCESS(Status))
170 {
171 DriverObjectExtension->Descriptor = Descriptor;
172 }
173 }
174
175 /* sanity check */
177
178 if (!NT_SUCCESS(Status))
179 return Status;
180
181 /* Setting our IRP handlers */
183 DriverObject->MajorFunction[IRP_MJ_PNP] = IKsDevice_Pnp;
184 DriverObject->MajorFunction[IRP_MJ_POWER] = IKsDevice_Power;
186
187 /* The driver unload routine */
188 DriverObject->DriverUnload = KsNullDriverUnload;
189
190 /* The driver-supplied AddDevice */
191 DriverObject->DriverExtension->AddDevice = KsAddDevice;
192
193 /* KS handles these */
194 DPRINT1("KsInitializeDriver Setting KS function handlers\n");
197
198
199 return STATUS_SUCCESS;
200}
#define DPRINT1
Definition: precomp.h:8
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
KSDDKAPI NTSTATUS NTAPI KsDefaultForwardIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: api.c:227
NTSTATUS NTAPI IKsDevice_Power(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: device.c:549
NTSTATUS NTAPI IKsDevice_Create(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: device.c:566
NTSTATUS NTAPI IKsDevice_Pnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: device.c:409
KSDDKAPI NTSTATUS NTAPI KsAddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
Definition: driver.c:129
KSDDKAPI NTSTATUS NTAPI KsSetMajorFunctionHandler(IN PDRIVER_OBJECT DriverObject, IN ULONG MajorFunction)
Definition: irp.c:2050
KSDDKAPI VOID NTAPI KsNullDriverUnload(IN PDRIVER_OBJECT DriverObject)
Definition: irp.c:1178
NTSTATUS NTAPI IoAllocateDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress, IN ULONG DriverObjectExtensionSize, OUT PVOID *DriverObjectExtension)
Definition: driver.c:1826
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_SUCCESS
Definition: shellext.h:65
#define IRP_MJ_SYSTEM_CONTROL
#define IRP_MJ_POWER

Referenced by DriverEntry(), KsAddDevice(), and KsInitializeDriver().