ReactOS  0.4.14-dev-114-gc8cbd56
topology.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/ksfilter/ks/topoology.c
5  * PURPOSE: KS Allocator functions
6  * PROGRAMMER: Johannes Anderwald
7  */
8 
9 #include "precomp.h"
10 
11 #define NDEBUG
12 #include <debug.h>
13 
15 NTAPI
17  IN HANDLE ParentHandle,
19  PVOID CreateParameters,
20  UINT CreateParametersSize,
23 {
28 
29  /* calculate request length */
30  Name.Length = 0;
31  Name.MaximumLength = (USHORT)(wcslen(ObjectType) * sizeof(WCHAR) + CreateParametersSize + 1 * sizeof(WCHAR));
32  Name.MaximumLength += sizeof(WCHAR);
33  /* acquire request buffer */
34  Name.Buffer = AllocateItem(NonPagedPool, Name.MaximumLength);
35  /* check for success */
36  if (!Name.Buffer)
37  {
38  /* insufficient resources */
40  }
41 
42  /* build a request which looks like {ObjectClass}\CreateParameters
43  * For pins the parent is the reference string used in registration
44  * For clocks it is full path for pin\{ClockGuid}\ClockCreateParams
45  */
48  /* append create parameters */
49  RtlMoveMemory(Name.Buffer + (Name.Length / sizeof(WCHAR)), CreateParameters, CreateParametersSize);
50  Name.Length += CreateParametersSize;
51  Name.Buffer[Name.Length / 2] = L'\0';
52 
54  /* create the instance */
59  NULL,
60  0,
61  0,
62  FILE_OPEN,
63  0,
64  NULL,
65  0,
67  NULL,
69 
70  /* free request buffer */
71  FreeItem(Name.Buffer);
72  return Status;
73 }
74 
75 
76 /*
77  @implemented
78 */
81  IN HANDLE ParentHandle,
85 {
86  return KspCreateObjectType(ParentHandle,
89  sizeof(KSNODE_CREATE),
91  NodeHandle);
92 }
93 
94 /*
95  @implemented
96 */
99 NTAPI
101  IN PIRP Irp,
102  IN PKSTOPOLOGY Topology,
103  OUT PKSNODE_CREATE* OutNodeCreate)
104 {
106  ULONG Size;
108 
109  /* did the caller miss the topology */
110  if (!Topology)
112 
113  /* set create param size */
114  Size = sizeof(KSNODE_CREATE);
115 
116  /* fetch create parameters */
119  &Size,
120  (PVOID*)&NodeCreate);
121 
122  if (!NT_SUCCESS(Status))
123  return Status;
124 
125  if (NodeCreate->CreateFlags != 0 || (NodeCreate->Node >= Topology->TopologyNodesCount && NodeCreate->Node != MAXULONG))
126  {
127  /* invalid node create */
129  return STATUS_UNSUCCESSFUL;
130  }
131 
132  /* store result */
133  *OutNodeCreate = NodeCreate;
134 
135  return Status;
136 }
137 
138 /*
139  @implemented
140 */
141 KSDDKAPI
142 NTSTATUS
143 NTAPI
145  IN PIRP Irp,
147  IN OUT PVOID Data,
148  IN const KSTOPOLOGY* Topology)
149 {
150  KSP_NODE * Node;
151  PIO_STACK_LOCATION IoStack;
154  LPGUID Guid;
155 
157 
158  DPRINT("KsTopologyPropertyHandler Irp %p Property %p Data %p Topology %p OutputLength %lu PropertyId %lu\n", Irp, Property, Data, Topology, IoStack->Parameters.DeviceIoControl.OutputBufferLength, Property->Id);
159 
160  if (Property->Flags != KSPROPERTY_TYPE_GET)
161  {
162  Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
163  Irp->IoStatus.Information = 0;
164  return STATUS_NOT_IMPLEMENTED;
165  }
166 
167  switch(Property->Id)
168  {
170  return KsHandleSizedListQuery(Irp, Topology->CategoriesCount, sizeof(GUID), Topology->Categories);
171 
173  return KsHandleSizedListQuery(Irp, Topology->TopologyNodesCount, sizeof(GUID), Topology->TopologyNodes);
174 
176  return KsHandleSizedListQuery(Irp, Topology->TopologyConnectionsCount, sizeof(KSTOPOLOGY_CONNECTION), Topology->TopologyConnections);
177 
179  Node = (KSP_NODE*)Property;
180 
181  /* check for invalid node id */
182  if (Node->NodeId >= Topology->TopologyNodesCount)
183  {
184  /* invalid node id */
185  Irp->IoStatus.Information = 0;
187  break;
188  }
189 
190  /* check if there is a name supplied */
191  if (!IsEqualGUIDAligned(&Topology->TopologyNodesNames[Node->NodeId], &GUID_NULL))
192  {
193  /* node name has been supplied */
194  Guid = (LPGUID)&Topology->TopologyNodesNames[Node->NodeId];
195  }
196  else
197  {
198  /* fallback to topology node type */
199  Guid = (LPGUID)&Topology->TopologyNodes[Node->NodeId];
200  }
201 
202  /* read topology node name */
203  Status = KspReadMediaCategory(Guid, &KeyInfo);
204  if (!NT_SUCCESS(Status))
205  {
206  Irp->IoStatus.Information = 0;
207  break;
208  }
209 
210  /* store result size */
211  Irp->IoStatus.Information = KeyInfo->DataLength + sizeof(WCHAR);
212 
213  /* check for buffer overflow */
214  if (KeyInfo->DataLength + sizeof(WCHAR) > IoStack->Parameters.DeviceIoControl.OutputBufferLength)
215  {
216  /* buffer too small */
218  FreeItem(KeyInfo);
219  break;
220  }
221 
222  /* copy result buffer */
223  RtlMoveMemory(Irp->AssociatedIrp.SystemBuffer, &KeyInfo->Data, KeyInfo->DataLength);
224 
225  /* zero terminate it */
226  ((LPWSTR)Irp->AssociatedIrp.SystemBuffer)[KeyInfo->DataLength / sizeof(WCHAR)] = L'\0';
227 
228  /* free key info */
229  FreeItem(KeyInfo);
230 
231  break;
232  default:
233  Irp->IoStatus.Information = 0;
235  }
236 
237  Irp->IoStatus.Status = Status;
238  return Status;
239 }
240 
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
ObjectType
Definition: metafile.c:80
#define IN
Definition: typedefs.h:38
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define IO_FORCE_ACCESS_CHECK
Definition: iotypes.h:508
KSDDKAPI NTSTATUS NTAPI KsCreateTopologyNode(IN HANDLE ParentHandle, IN PKSNODE_CREATE NodeCreate, IN ACCESS_MASK DesiredAccess, OUT PHANDLE NodeHandle)
Definition: topology.c:80
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
NTSTATUS NTAPI KspCreateObjectType(IN HANDLE ParentHandle, IN LPWSTR ObjectType, PVOID CreateParameters, UINT CreateParametersSize, IN ACCESS_MASK DesiredAccess, OUT PHANDLE NodeHandle)
Definition: topology.c:16
_In_ PKSNODE_CREATE NodeCreate
Definition: ks.h:4546
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
LONG NTSTATUS
Definition: precomp.h:26
KSDDKAPI NTSTATUS NTAPI KsHandleSizedListQuery(IN PIRP Irp, IN ULONG DataItemsCount, IN ULONG DataItemSize, IN const VOID *DataItems)
Definition: connectivity.c:774
KSDDKAPI NTSTATUS NTAPI KsValidateTopologyNodeCreateRequest(IN PIRP Irp, IN PKSTOPOLOGY Topology, OUT PKSNODE_CREATE *OutNodeCreate)
Definition: topology.c:100
NTSTATUS KspReadMediaCategory(IN LPGUID Category, PKEY_VALUE_PARTIAL_INFORMATION *OutInformation)
Definition: connectivity.c:232
_In_ PKSNODE_CREATE _In_ ACCESS_MASK _Out_ PHANDLE NodeHandle
Definition: ks.h:4546
#define KSDDKAPI
Definition: ks.h:40
#define KSPROPERTY_TYPE_GET
Definition: dmksctrl.h:42
NTSTATUS KspCopyCreateRequest(IN PIRP Irp, IN LPWSTR ObjectClass, IN OUT PULONG Size, OUT PVOID *Result)
Definition: misc.c:101
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:233
#define OBJ_OPENIF
Definition: winternl.h:229
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define IO_NO_PARAMETER_CHECKING
Definition: iotypes.h:509
union node Node
Definition: types.h:1255
struct NameRec_ * Name
Definition: cdprocs.h:464
static GUID * Guid
Definition: apphelp.c:93
smooth NULL
Definition: ftsmooth.c:416
Definition: ks.h:2074
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define STATUS_NOT_FOUND
Definition: shellext.h:67
ULONG Node
Definition: ks.h:2094
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
KSDDKAPI NTSTATUS NTAPI KsTopologyPropertyHandler(IN PIRP Irp, IN PKSPROPERTY Property, IN OUT PVOID Data, IN const KSTOPOLOGY *Topology)
Definition: topology.c:144
static const WCHAR L[]
Definition: oid.c:1250
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:414
#define GUID_NULL
Definition: ks.h:106
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
#define MAXULONG
Definition: typedefs.h:250
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:61
unsigned short USHORT
Definition: pedump.c:61
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
unsigned int UINT
Definition: ndis.h:50
#define KSSTRING_TopologyNode
Definition: ks.h:52
NTSTATUS NTAPI IoCreateFile(OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER AllocationSize OPTIONAL, IN ULONG FileAttributes, IN ULONG ShareAccess, IN ULONG Disposition, IN ULONG CreateOptions, IN PVOID EaBuffer OPTIONAL, IN ULONG EaLength, IN CREATE_FILE_TYPE CreateFileType, IN PVOID ExtraCreateParameters OPTIONAL, IN ULONG Options)
Definition: file.c:3009
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
WCHAR * LPWSTR
Definition: xmlstorage.h:184
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
ULONG CreateFlags
Definition: ks.h:2093
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
ULONG ACCESS_MASK
Definition: nt_native.h:40
Definition: dlist.c:348
GUID * LPGUID
Definition: guiddef.h:81