ReactOS  0.4.14-dev-315-gbb6fece
filter.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS Kernel Streaming
4  * FILE: drivers/wdm/audio/legacy/stream/filter.c
5  * PURPOSE: filter instance handling
6  * PROGRAMMER: Johannes Anderwald
7  */
8 
9 
10 #include "stream.h"
11 
12 
14 NTAPI
17  IN PIRP Irp)
18 {
20 
21  Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
22  Irp->IoStatus.Information = 0;
25 }
26 
27 
29 NTAPI
32  PIRP Irp)
33 {
34  DPRINT1("FilterDispatch Called\n");
35 
36  Irp->IoStatus.Status = STATUS_SUCCESS;
37  Irp->IoStatus.Information = 0;
39  return STATUS_SUCCESS;
40 }
41 
42 
44 NTAPI
47  PIRP Irp)
48 {
50  PSTREAM_DEVICE_EXTENSION DeviceExtension;
51  HW_STREAM_REQUEST_BLOCK_EXT RequestBlock;
52 
53  /* Get device extension */
55 
57  {
58  /* driver supports only one instance */
59  if (DeviceExtension->InstanceCount)
60  {
61  /* there is already one instance open */
62  return STATUS_UNSUCCESSFUL;
63  }
64  }
65  else
66  {
67  /* driver supports more than one filter instance */
68  RtlZeroMemory(&RequestBlock, sizeof(HW_STREAM_REQUEST_BLOCK_EXT));
69 
70  /* set up request block */
72  RequestBlock.Block.HwDeviceExtension = DeviceExtension->DeviceExtension;
73  RequestBlock.Block.Irp = Irp;
75 
76  /*FIXME SYNCHRONIZATION */
77 
78  /* Send the request */
79  DeviceExtension->DriverExtension->Data.HwReceivePacket((PHW_STREAM_REQUEST_BLOCK)&RequestBlock);
80  if (RequestBlock.Block.Status == STATUS_PENDING)
81  {
82  /* Wait for the request */
83  KeWaitForSingleObject(&RequestBlock.Event, Executive, KernelMode, FALSE, NULL);
84  }
85  }
86 
87  /* Increment total instance count */
88  InterlockedDecrement(&DeviceExtension->InstanceCount);
89 
90  Irp->IoStatus.Status = Status;
91  Irp->IoStatus.Information = 0;
93  return Status;
94 }
95 
96 static KSDISPATCH_TABLE DispatchTable =
97 {
103  NULL,
104  NULL,
105  NULL,
106  NULL,
107  NULL
108 };
109 
110 VOID
112  IN PSTREAM_DEVICE_EXTENSION DeviceExtension)
113 {
114  ULONG Index;
115  PHW_STREAM_INFORMATION StreamInformation;
118 
119  /* Sanity check */
120  ASSERT(DeviceExtension->StreamDescriptor);
121  ASSERT(DeviceExtension->StreamDescriptorSize);
122 
123  /* Loop all stream descriptors and register device interfaces */
124  StreamInformation = (PHW_STREAM_INFORMATION)&DeviceExtension->StreamDescriptor->StreamInfo;
125 
126  for(Index = 0; DeviceExtension->StreamDescriptor->StreamHeader.NumberOfStreams; Index++)
127  {
128  if (StreamInformation->Category)
129  {
130  /* Register device interface */
131  Status = IoRegisterDeviceInterface(DeviceExtension->PhysicalDeviceObject,
132  StreamInformation->Category,
133  NULL, /* see CORE-4218 and r42457 */
134  &SymbolicLink);
135 
136  if (NT_SUCCESS(Status))
137  {
138  /* Activate device interface */
140  /* Release Symbolic Link */
142  }
143  }
144  StreamInformation = (PHW_STREAM_INFORMATION) (ULONG_PTR)StreamInformation + DeviceExtension->StreamDescriptor->StreamHeader.SizeOfHwStreamInformation;
145  }
146 
147 }
148 
149 NTSTATUS
152  IN PIRP Irp)
153 {
155  PSTREAM_DEVICE_EXTENSION DeviceExtension;
156  KSOBJECT_HEADER ObjectHeader;
157  PKSOBJECT_CREATE_ITEM CreateItem;
158  PIO_STACK_LOCATION IoStack;
159  HW_STREAM_REQUEST_BLOCK_EXT RequestBlock;
160  PVOID HwInstanceExtension = NULL;
161 
162  /* Get device extension */
164 
166  {
167  /* driver supports only one instance */
168  if (DeviceExtension->InstanceCount)
169  {
170  /* there is already one instance open */
171  return STATUS_UNSUCCESSFUL;
172  }
173  }
174  else
175  {
176  /* driver supports more than one filter instance */
177  RtlZeroMemory(&RequestBlock, sizeof(HW_STREAM_REQUEST_BLOCK_EXT));
178 
179  /* allocate instance extension */
180  HwInstanceExtension = ExAllocatePool(NonPagedPool, DeviceExtension->DriverExtension->Data.FilterInstanceExtensionSize);
181  if (!HwInstanceExtension)
182  {
183  /* Not enough memory */
185  }
186 
187  /* Zero instance extension */
188  RtlZeroMemory(HwInstanceExtension, DeviceExtension->DriverExtension->Data.FilterInstanceExtensionSize);
189 
190  /* set up request block */
191  RequestBlock.Block.Command = SRB_OPEN_DEVICE_INSTANCE;
192  RequestBlock.Block.HwDeviceExtension = DeviceExtension->DeviceExtension;
193  RequestBlock.Block.Irp = Irp;
194  RequestBlock.Block.HwInstanceExtension = HwInstanceExtension;
196 
197  /*FIXME SYNCHRONIZATION */
198 
199  /* Send the request */
200  DeviceExtension->DriverExtension->Data.HwReceivePacket((PHW_STREAM_REQUEST_BLOCK)&RequestBlock);
201  if (RequestBlock.Block.Status == STATUS_PENDING)
202  {
203  /* Wait for the request */
204  KeWaitForSingleObject(&RequestBlock.Event, Executive, KernelMode, FALSE, NULL);
205  }
206  /* Check for success */
207  if (!NT_SUCCESS(RequestBlock.Block.Status))
208  {
209  /* Resource is not available */
210  ExFreePool(HwInstanceExtension);
211  return RequestBlock.Block.Status;
212  }
213  }
214 
215  /* Allocate create item */
216  CreateItem = ExAllocatePool(NonPagedPool, sizeof(KSOBJECT_CREATE_ITEM));
217  if (!CreateItem)
218  {
219  /* not enough memory */
221  }
222 
223  /* Zero create item */
224  RtlZeroMemory(CreateItem, sizeof(KSOBJECT_CREATE_ITEM));
225  /* Initialize createitem */
226  RtlInitUnicodeString(&CreateItem->ObjectClass, KSSTRING_Pin);
227  CreateItem->Create = StreamClassCreatePin;
228 
229  /* Get current irp stack location */
231  /* Create Ks streaming object header */
232  Status = KsAllocateObjectHeader(&ObjectHeader, 1, CreateItem, Irp, &DispatchTable);
233  if (!NT_SUCCESS(Status))
234  {
235  /* Failed to create header */
236  ExFreePool(CreateItem);
237  if (HwInstanceExtension)
238  {
239  /* free instance buffer */
240  ExFreePool(HwInstanceExtension);
241  }
242  return Status;
243  }
244 
245  /* Store instance buffer in file object context */
246  IoStack->FileObject->FsContext2 = HwInstanceExtension;
247 
248  /* Increment total instance count */
249  InterlockedIncrement(&DeviceExtension->InstanceCount);
250 
251  /* Register device stream interfaces */
252  RegisterDeviceInterfaces(DeviceExtension);
253 
254  /* Return result */
255  return Status;
256 
257 }
258 
259 NTSTATUS
260 NTAPI
263  IN PIRP Irp)
264 {
266  DPRINT1("StreamClassCreateFilter Called\n");
267 
268  /* Init filter */
270 
271  Irp->IoStatus.Status = Status;
272  Irp->IoStatus.Information = 0;
274  return Status;
275 }
276 
277 
278 
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
ULONG FilterInstanceExtensionSize
Definition: strmini.h:362
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NTSTATUS NTAPI StreamClassCreateFilter(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: filter.c:261
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
_In_ PIRP Irp
Definition: csq.h:116
#define KSSTRING_Pin
Definition: ks.h:48
HW_INITIALIZATION_DATA Data
Definition: stream.h:13
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI FilterDispatch_fnClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: filter.c:45
static KSDISPATCH_TABLE DispatchTable
Definition: filter.c:96
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
uint32_t ULONG_PTR
Definition: typedefs.h:63
NTSTATUS NTAPI FilterDispatch_fnDeviceIoControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: filter.c:30
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
NTSTATUS InitializeFilterWithKs(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: filter.c:150
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
struct _HW_STREAM_INFORMATION * PHW_STREAM_INFORMATION
KSDDKAPI NTSTATUS NTAPI KsDispatchInvalidDeviceRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1156
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
static const UCHAR Index[8]
Definition: usbohci.c:18
struct STREAM_DEVICE_EXTENSION * PSTREAM_DEVICE_EXTENSION
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
HW_STREAM_REQUEST_BLOCK Block
Definition: stream.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
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 KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define InterlockedIncrement
Definition: armddk.h:53
#define DPRINT1
Definition: precomp.h:8
VOID RegisterDeviceInterfaces(IN PSTREAM_DEVICE_EXTENSION DeviceExtension)
Definition: filter.c:111
NTSTATUS NTAPI StreamClassCreatePin(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: filter.c:15
KSDDKAPI NTSTATUS NTAPI KsAllocateObjectHeader(OUT KSOBJECT_HEADER *Header, IN ULONG ItemsCount, IN PKSOBJECT_CREATE_ITEM ItemsList OPTIONAL, IN PIRP Irp, IN KSDISPATCH_TABLE *Table)
Definition: api.c:610
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define UNIMPLEMENTED
Definition: debug.h:114
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
PSTREAM_CLASS_DRIVER_EXTENSION DriverExtension
Definition: stream.h:44
SRB_COMMAND Command
Definition: strmini.h:224
return STATUS_SUCCESS
Definition: btrfs.c:2938
PHW_RECEIVE_DEVICE_SRB HwReceivePacket
Definition: strmini.h:356
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
static const WCHAR SymbolicLink[]
Definition: interface.c:31