ReactOS 0.4.15-dev-5666-gc548b97
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
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,
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),
92}
93
94/*
95 @implemented
96*/
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*/
143NTAPI
145 IN PIRP Irp,
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;
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
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
struct NameRec_ * Name
Definition: cdprocs.h:460
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
NTSTATUS KspReadMediaCategory(IN LPGUID Category, PKEY_VALUE_PARTIAL_INFORMATION *OutInformation)
Definition: connectivity.c:232
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
union node Node
Definition: types.h:1255
KSDDKAPI NTSTATUS NTAPI KsTopologyPropertyHandler(IN PIRP Irp, IN PKSPROPERTY Property, IN OUT PVOID Data, IN const KSTOPOLOGY *Topology)
Definition: topology.c:144
NTSTATUS NTAPI KspCreateObjectType(IN HANDLE ParentHandle, IN LPWSTR ObjectType, PVOID CreateParameters, UINT CreateParametersSize, IN ACCESS_MASK DesiredAccess, OUT PHANDLE NodeHandle)
Definition: topology.c:16
KSDDKAPI NTSTATUS NTAPI KsValidateTopologyNodeCreateRequest(IN PIRP Irp, IN PKSTOPOLOGY Topology, OUT PKSNODE_CREATE *OutNodeCreate)
Definition: topology.c:100
KSDDKAPI NTSTATUS NTAPI KsCreateTopologyNode(IN HANDLE ParentHandle, IN PKSNODE_CREATE NodeCreate, IN ACCESS_MASK DesiredAccess, OUT PHANDLE NodeHandle)
Definition: topology.c:80
#define KSPROPERTY_TYPE_GET
Definition: dmksctrl.h:42
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define NonPagedPool
Definition: env_spec_w32.h:307
#define FILE_OPEN
Definition: from_kernel.h:54
Status
Definition: gdiplustypes.h:25
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_OPENIF
Definition: winternl.h:229
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
_In_ PKSNODE_CREATE NodeCreate
Definition: ks.h:4546
_In_ PKSNODE_CREATE _In_ ACCESS_MASK _Out_ PHANDLE NodeHandle
Definition: ks.h:4548
#define GUID_NULL
Definition: ks.h:106
#define KSSTRING_TopologyNode
Definition: ks.h:52
@ KSPROPERTY_TOPOLOGY_CATEGORIES
Definition: ks.h:845
@ KSPROPERTY_TOPOLOGY_NAME
Definition: ks.h:848
@ KSPROPERTY_TOPOLOGY_NODES
Definition: ks.h:846
@ KSPROPERTY_TOPOLOGY_CONNECTIONS
Definition: ks.h:847
#define KSDDKAPI
Definition: ks.h:40
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
NTSTATUS KspCopyCreateRequest(IN PIRP Irp, IN LPWSTR ObjectClass, IN OUT PULONG Size, OUT PVOID *Result)
Definition: misc.c:50
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
unsigned int ULONG
Definition: retypes.h:1
ObjectType
Definition: metafile.c:81
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
unsigned int UINT
Definition: ndis.h:50
ULONG ACCESS_MASK
Definition: nt_native.h:40
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:3010
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
GUID * LPGUID
Definition: guiddef.h:81
#define STATUS_NOT_FOUND
Definition: shellext.h:72
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define DPRINT
Definition: sndvol32.h:71
ULONG Node
Definition: ks.h:2094
ULONG CreateFlags
Definition: ks.h:2093
Definition: ks.h:2074
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
#define MAXULONG
Definition: typedefs.h:251
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
#define OUT
Definition: typedefs.h:40
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
Definition: dlist.c:348
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ WDFOBJECT _In_ CONST GUID * Guid
Definition: wdfobject.h:762
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:235
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
#define IO_FORCE_ACCESS_CHECK
Definition: iotypes.h:540
#define IO_NO_PARAMETER_CHECKING
Definition: iotypes.h:541
@ CreateFileTypeNone
Definition: iotypes.h:535
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184