1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel Streaming
4 * FILE: drivers/wdm/audio/backpln/portcls/dispatcher.c
5 * PURPOSE: portcls generic dispatcher
6 * PROGRAMMER: Johannes Anderwald
7 */
8
9 #include "private.hpp"
10
11 #define NDEBUG
12 #include <debug.h>
13
14 NTSTATUS
15 NTAPI
Dispatch_fnDeviceIoControl(PDEVICE_OBJECT DeviceObject,PIRP Irp)16 Dispatch_fnDeviceIoControl(
17 PDEVICE_OBJECT DeviceObject,
18 PIRP Irp)
19 {
20 PIO_STACK_LOCATION IoStack;
21 PDISPATCH_CONTEXT DispatchContext;
22
23 // get current irp stack
24 IoStack = IoGetCurrentIrpStackLocation(Irp);
25
26 // get dispatch context
27 DispatchContext = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
28
29 // let IrpTarget handle request
30 return DispatchContext->Target->DeviceIoControl(DeviceObject, Irp);
31 }
32
33 NTSTATUS
34 NTAPI
Dispatch_fnRead(PDEVICE_OBJECT DeviceObject,PIRP Irp)35 Dispatch_fnRead(
36 PDEVICE_OBJECT DeviceObject,
37 PIRP Irp)
38 {
39 PIO_STACK_LOCATION IoStack;
40 PDISPATCH_CONTEXT DispatchContext;
41
42 // get current irp stack
43 IoStack = IoGetCurrentIrpStackLocation(Irp);
44
45 // get dispatch context
46 DispatchContext = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
47
48 // let IrpTarget handle request
49 return DispatchContext->Target->Read(DeviceObject, Irp);
50 }
51
52 NTSTATUS
53 NTAPI
Dispatch_fnWrite(PDEVICE_OBJECT DeviceObject,PIRP Irp)54 Dispatch_fnWrite(
55 PDEVICE_OBJECT DeviceObject,
56 PIRP Irp)
57 {
58 PIO_STACK_LOCATION IoStack;
59 PDISPATCH_CONTEXT DispatchContext;
60
61 // get current irp stack
62 IoStack = IoGetCurrentIrpStackLocation(Irp);
63
64 // get dispatch context
65 DispatchContext = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
66
67 // let IrpTarget handle request
68 return DispatchContext->Target->Write(DeviceObject, Irp);
69 }
70
71 NTSTATUS
72 NTAPI
Dispatch_fnFlush(PDEVICE_OBJECT DeviceObject,PIRP Irp)73 Dispatch_fnFlush(
74 PDEVICE_OBJECT DeviceObject,
75 PIRP Irp)
76 {
77 PIO_STACK_LOCATION IoStack;
78 PDISPATCH_CONTEXT DispatchContext;
79
80 // get current irp stack
81 IoStack = IoGetCurrentIrpStackLocation(Irp);
82
83 // get dispatch context
84 DispatchContext = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
85
86 // let IrpTarget handle request
87 return DispatchContext->Target->Flush(DeviceObject, Irp);
88 }
89
90 NTSTATUS
91 NTAPI
Dispatch_fnClose(PDEVICE_OBJECT DeviceObject,PIRP Irp)92 Dispatch_fnClose(
93 PDEVICE_OBJECT DeviceObject,
94 PIRP Irp)
95 {
96 PIO_STACK_LOCATION IoStack;
97 PDISPATCH_CONTEXT DispatchContext;
98 NTSTATUS Status;
99
100 // get current irp stack
101 IoStack = IoGetCurrentIrpStackLocation(Irp);
102 // get dispatch context
103 DispatchContext = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
104
105 // let IrpTarget handle request
106 Status = DispatchContext->Target->Close(DeviceObject, Irp);
107
108 if (NT_SUCCESS(Status))
109 {
110 KsFreeObjectHeader(DispatchContext->ObjectHeader);
111 FreeItem(DispatchContext, TAG_PORTCLASS);
112 }
113 // done
114 return Status;
115 }
116
117 NTSTATUS
118 NTAPI
Dispatch_fnQuerySecurity(PDEVICE_OBJECT DeviceObject,PIRP Irp)119 Dispatch_fnQuerySecurity(
120 PDEVICE_OBJECT DeviceObject,
121 PIRP Irp)
122 {
123 PIO_STACK_LOCATION IoStack;
124 PDISPATCH_CONTEXT DispatchContext;
125
126 // get current irp stack
127 IoStack = IoGetCurrentIrpStackLocation(Irp);
128
129 // get dispatch context
130 DispatchContext = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
131
132 // let IrpTarget handle request
133 return DispatchContext->Target->QuerySecurity(DeviceObject, Irp);
134 }
135
136 NTSTATUS
137 NTAPI
Dispatch_fnSetSecurity(PDEVICE_OBJECT DeviceObject,PIRP Irp)138 Dispatch_fnSetSecurity(
139 PDEVICE_OBJECT DeviceObject,
140 PIRP Irp)
141 {
142 PIO_STACK_LOCATION IoStack;
143 PDISPATCH_CONTEXT DispatchContext;
144
145 // get current irp stack
146 IoStack = IoGetCurrentIrpStackLocation(Irp);
147
148 // get dispatch context
149 DispatchContext = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
150
151 // let IrpTarget handle request
152 return DispatchContext->Target->SetSecurity(DeviceObject, Irp);
153 }
154
155 BOOLEAN
156 NTAPI
Dispatch_fnFastDeviceIoControl(PFILE_OBJECT FileObject,BOOLEAN Wait,PVOID InputBuffer,ULONG InputBufferLength,PVOID OutputBuffer,ULONG OutputBufferLength,ULONG IoControlCode,PIO_STATUS_BLOCK IoStatus,PDEVICE_OBJECT DeviceObject)157 Dispatch_fnFastDeviceIoControl(
158 PFILE_OBJECT FileObject,
159 BOOLEAN Wait,
160 PVOID InputBuffer,
161 ULONG InputBufferLength,
162 PVOID OutputBuffer,
163 ULONG OutputBufferLength,
164 ULONG IoControlCode,
165 PIO_STATUS_BLOCK IoStatus,
166 PDEVICE_OBJECT DeviceObject)
167 {
168 PDISPATCH_CONTEXT DispatchContext;
169
170 // get dispatch context
171 DispatchContext = (PDISPATCH_CONTEXT)FileObject->FsContext;
172
173 // let IrpTarget handle request
174 return DispatchContext->Target->FastDeviceIoControl(FileObject, Wait, InputBuffer, InputBufferLength, OutputBuffer, OutputBufferLength, IoControlCode, IoStatus, DeviceObject);
175 }
176
177 BOOLEAN
178 NTAPI
Dispatch_fnFastRead(PFILE_OBJECT FileObject,PLARGE_INTEGER FileOffset,ULONG Length,BOOLEAN Wait,ULONG LockKey,PVOID Buffer,PIO_STATUS_BLOCK IoStatus,PDEVICE_OBJECT DeviceObject)179 Dispatch_fnFastRead(
180 PFILE_OBJECT FileObject,
181 PLARGE_INTEGER FileOffset,
182 ULONG Length,
183 BOOLEAN Wait,
184 ULONG LockKey,
185 PVOID Buffer,
186 PIO_STATUS_BLOCK IoStatus,
187 PDEVICE_OBJECT DeviceObject)
188 {
189 PDISPATCH_CONTEXT DispatchContext;
190
191 // get dispatch context
192 DispatchContext = (PDISPATCH_CONTEXT)FileObject->FsContext;
193
194 // let IrpTarget handle request
195 return DispatchContext->Target->FastRead(FileObject, FileOffset, Length, Wait, LockKey, Buffer, IoStatus, DeviceObject);
196 }
197
198 BOOLEAN
199 NTAPI
Dispatch_fnFastWrite(PFILE_OBJECT FileObject,PLARGE_INTEGER FileOffset,ULONG Length,BOOLEAN Wait,ULONG LockKey,PVOID Buffer,PIO_STATUS_BLOCK IoStatus,PDEVICE_OBJECT DeviceObject)200 Dispatch_fnFastWrite(
201 PFILE_OBJECT FileObject,
202 PLARGE_INTEGER FileOffset,
203 ULONG Length,
204 BOOLEAN Wait,
205 ULONG LockKey,
206 PVOID Buffer,
207 PIO_STATUS_BLOCK IoStatus,
208 PDEVICE_OBJECT DeviceObject)
209 {
210 PDISPATCH_CONTEXT DispatchContext;
211
212 // get dispatch context
213 DispatchContext = (PDISPATCH_CONTEXT)FileObject->FsContext;
214 // let IrpTarget handle request
215 return DispatchContext->Target->FastWrite(FileObject, FileOffset, Length, Wait, LockKey, Buffer, IoStatus, DeviceObject);
216 }
217
218 static KSDISPATCH_TABLE DispatchTable =
219 {
220 Dispatch_fnDeviceIoControl,
221 Dispatch_fnRead,
222 Dispatch_fnWrite,
223 Dispatch_fnFlush,
224 Dispatch_fnClose,
225 Dispatch_fnQuerySecurity,
226 Dispatch_fnSetSecurity,
227 Dispatch_fnFastDeviceIoControl,
228 Dispatch_fnFastRead,
229 Dispatch_fnFastWrite,
230 };
231
232 NTSTATUS
233 NTAPI
NewDispatchObject(IN PIRP Irp,IN IIrpTarget * Target,IN ULONG CreateItemCount,IN PKSOBJECT_CREATE_ITEM CreateItem)234 NewDispatchObject(
235 IN PIRP Irp,
236 IN IIrpTarget * Target,
237 IN ULONG CreateItemCount,
238 IN PKSOBJECT_CREATE_ITEM CreateItem)
239 {
240 NTSTATUS Status;
241 KSOBJECT_HEADER ObjectHeader;
242 PIO_STACK_LOCATION IoStack;
243 PDISPATCH_CONTEXT DispatchContext;
244
245 // get current irp stack location
246 IoStack = IoGetCurrentIrpStackLocation(Irp);
247
248 DispatchContext = (PDISPATCH_CONTEXT)AllocateItem(NonPagedPool, sizeof(DISPATCH_CONTEXT), TAG_PORTCLASS);
249 if (!DispatchContext)
250 return STATUS_INSUFFICIENT_RESOURCES;
251
252 // allocate object header
253 Status = KsAllocateObjectHeader(&ObjectHeader, CreateItemCount, CreateItem, Irp, &DispatchTable);
254
255 if (!NT_SUCCESS(Status))
256 {
257 // free dispatch context
258 FreeItem(DispatchContext, TAG_PORTCLASS);
259 // done
260 return Status;
261 }
262
263 // initialize dispatch context
264 DispatchContext->ObjectHeader = ObjectHeader;
265 DispatchContext->Target = Target;
266 DispatchContext->CreateItem = CreateItem;
267
268 // store dispatch context
269 IoStack->FileObject->FsContext = DispatchContext;
270
271 DPRINT("KsAllocateObjectHeader result %x Target %p Context %p\n", Status, Target, DispatchContext);
272 return Status;
273 }
274