xref: /reactos/ntoskrnl/wmi/wmi.c (revision d18634c0)
1 /*
2  * PROJECT:         ReactOS Kernel
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * FILE:            ntoskrnl/wmi/wmi.c
5  * PURPOSE:         I/O Windows Management Instrumentation (WMI) Support
6  * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
7  */
8 
9 /* INCLUDES *****************************************************************/
10 
11 #include <ntoskrnl.h>
12 #define INITGUID
13 #include <wmiguid.h>
14 #include <wmidata.h>
15 #include <wmistr.h>
16 
17 #include "wmip.h"
18 
19 #define NDEBUG
20 #include <debug.h>
21 
22 typedef PVOID PWMI_LOGGER_INFORMATION; // FIXME
23 
24 typedef enum _WMI_CLOCK_TYPE
25 {
26     WMICT_DEFAULT,
27     WMICT_SYSTEMTIME,
28     WMICT_PERFCOUNTER,
29     WMICT_PROCESS,
30     WMICT_THREAD,
31     WMICT_CPUCYCLE
32 } WMI_CLOCK_TYPE;
33 
34 /* FUNCTIONS *****************************************************************/
35 
36 BOOLEAN
37 NTAPI
WmiInitialize(VOID)38 WmiInitialize(
39     VOID)
40 {
41     UNICODE_STRING DriverName = RTL_CONSTANT_STRING(L"\\Driver\\WMIxWDM");
42     NTSTATUS Status;
43 
44     /* Initialize the GUID object type */
45     Status = WmipInitializeGuidObjectType();
46     if (!NT_SUCCESS(Status))
47     {
48         DPRINT1("WmipInitializeGuidObjectType() failed: 0x%lx\n", Status);
49         return FALSE;
50     }
51 
52     /* Create the WMI driver */
53     Status = IoCreateDriver(&DriverName, WmipDriverEntry);
54     if (!NT_SUCCESS(Status))
55     {
56         DPRINT1("Failed to create WMI driver: 0x%lx\n", Status);
57         return FALSE;
58     }
59 
60     return TRUE;
61 }
62 
63 /*
64  * @unimplemented
65  */
66 NTSTATUS
67 NTAPI
IoWMIRegistrationControl(IN PDEVICE_OBJECT DeviceObject,IN ULONG Action)68 IoWMIRegistrationControl(IN PDEVICE_OBJECT DeviceObject,
69                          IN ULONG Action)
70 {
71     DPRINT("IoWMIRegistrationControl() called for DO %p, requesting %lu action, returning success\n",
72         DeviceObject, Action);
73 
74     return STATUS_SUCCESS;
75 }
76 
77 /*
78  * @unimplemented
79  */
80 NTSTATUS
81 NTAPI
IoWMIAllocateInstanceIds(IN GUID * Guid,IN ULONG InstanceCount,OUT ULONG * FirstInstanceId)82 IoWMIAllocateInstanceIds(IN GUID *Guid,
83                          IN ULONG InstanceCount,
84                          OUT ULONG *FirstInstanceId)
85 {
86     UNIMPLEMENTED;
87     return STATUS_NOT_IMPLEMENTED;
88 }
89 
90 /*
91  * @unimplemented
92  */
93 NTSTATUS
94 NTAPI
IoWMISuggestInstanceName(IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL,IN PUNICODE_STRING SymbolicLinkName OPTIONAL,IN BOOLEAN CombineNames,OUT PUNICODE_STRING SuggestedInstanceName)95 IoWMISuggestInstanceName(IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL,
96                          IN PUNICODE_STRING SymbolicLinkName OPTIONAL,
97                          IN BOOLEAN CombineNames,
98                          OUT PUNICODE_STRING SuggestedInstanceName)
99 {
100     UNIMPLEMENTED;
101     return STATUS_NOT_IMPLEMENTED;
102 }
103 
104 /*
105  * @unimplemented
106  */
107 NTSTATUS
108 NTAPI
IoWMIWriteEvent(_Inout_ PVOID WnodeEventItem)109 IoWMIWriteEvent(_Inout_ PVOID WnodeEventItem)
110 {
111     PWNODE_HEADER Header = WnodeEventItem;
112 
113     if(!Header)
114     {
115         DPRINT1("Got NULL Item!\n");
116         return STATUS_INVALID_PARAMETER;
117     }
118 
119     DPRINT1("IoWMIWriteEvent() called for WnodeEventItem %p (Flags = 0x%08lx), returning success\n",
120             WnodeEventItem, Header->Flags);
121 
122     if (Header->Flags & WNODE_FLAG_TRACED_GUID)
123     {
124         // Never free WnodeEventItem in this case.
125         DPRINT("IoWMIWriteEvent(): Flags has WNODE_FLAG_TRACED_GUID\n");
126         return STATUS_SUCCESS;
127     }
128 
129     /* Free the buffer if we are returning success */
130     ExFreePool(WnodeEventItem);
131 
132     return STATUS_SUCCESS;
133 }
134 
135 /*
136  * @unimplemented
137  */
138 NTSTATUS
139 NTAPI
IoWMIOpenBlock(_In_ LPCGUID DataBlockGuid,_In_ ULONG DesiredAccess,_Out_ PVOID * DataBlockObject)140 IoWMIOpenBlock(
141     _In_ LPCGUID DataBlockGuid,
142     _In_ ULONG DesiredAccess,
143     _Out_ PVOID *DataBlockObject)
144 {
145     HANDLE GuidObjectHandle;
146     NTSTATUS Status;
147 
148     /* Open the GIOD object */
149     Status = WmipOpenGuidObject(DataBlockGuid,
150                                 DesiredAccess,
151                                 KernelMode,
152                                 &GuidObjectHandle,
153                                 DataBlockObject);
154     if (!NT_SUCCESS(Status))
155     {
156         DPRINT1("WmipOpenGuidObject failed: 0x%lx\n", Status);
157         return Status;
158     }
159 
160 
161     return STATUS_SUCCESS;
162 }
163 
164 /*
165  * @unimplemented
166  */
167 NTSTATUS
168 NTAPI
IoWMIQueryAllData(IN PVOID DataBlockObject,IN OUT ULONG * InOutBufferSize,OUT PVOID OutBuffer)169 IoWMIQueryAllData(
170     IN PVOID DataBlockObject,
171     IN OUT ULONG *InOutBufferSize,
172     OUT PVOID OutBuffer)
173 {
174     PWMIP_GUID_OBJECT GuidObject;
175     NTSTATUS Status;
176 
177 
178     Status = ObReferenceObjectByPointer(DataBlockObject,
179                                         WMIGUID_QUERY,
180                                         WmipGuidObjectType,
181                                         KernelMode);
182     if (!NT_SUCCESS(Status))
183     {
184         return Status;
185     }
186 
187     GuidObject = DataBlockObject;
188 
189     /* Huge HACK! */
190     if (IsEqualGUID(&GuidObject->Guid, &MSSmBios_RawSMBiosTables_GUID))
191     {
192         Status = WmipQueryRawSMBiosTables(InOutBufferSize, OutBuffer);
193     }
194     else
195     {
196         Status = STATUS_NOT_SUPPORTED;
197     }
198 
199     ObDereferenceObject(DataBlockObject);
200 
201     return Status;
202 }
203 
204 /*
205  * @unimplemented
206  */
207 NTSTATUS
208 NTAPI
IoWMIQueryAllDataMultiple(IN PVOID * DataBlockObjectList,IN ULONG ObjectCount,IN OUT ULONG * InOutBufferSize,OUT PVOID OutBuffer)209 IoWMIQueryAllDataMultiple(IN PVOID *DataBlockObjectList,
210                           IN ULONG ObjectCount,
211                           IN OUT ULONG *InOutBufferSize,
212                           OUT PVOID OutBuffer)
213 {
214     UNIMPLEMENTED;
215     return STATUS_NOT_IMPLEMENTED;
216 }
217 
218 /*
219  * @unimplemented
220  */
221 NTSTATUS
222 NTAPI
IoWMIQuerySingleInstance(IN PVOID DataBlockObject,IN PUNICODE_STRING InstanceName,IN OUT ULONG * InOutBufferSize,OUT PVOID OutBuffer)223 IoWMIQuerySingleInstance(IN PVOID DataBlockObject,
224                          IN PUNICODE_STRING InstanceName,
225                          IN OUT ULONG *InOutBufferSize,
226                          OUT PVOID OutBuffer)
227 {
228     UNIMPLEMENTED;
229     return STATUS_NOT_IMPLEMENTED;
230 }
231 
232 /*
233  * @unimplemented
234  */
235 NTSTATUS
236 NTAPI
IoWMIQuerySingleInstanceMultiple(IN PVOID * DataBlockObjectList,IN PUNICODE_STRING InstanceNames,IN ULONG ObjectCount,IN OUT ULONG * InOutBufferSize,OUT PVOID OutBuffer)237 IoWMIQuerySingleInstanceMultiple(IN PVOID *DataBlockObjectList,
238                                  IN PUNICODE_STRING InstanceNames,
239                                  IN ULONG ObjectCount,
240                                  IN OUT ULONG *InOutBufferSize,
241                                  OUT PVOID OutBuffer)
242 {
243     UNIMPLEMENTED;
244     return STATUS_NOT_IMPLEMENTED;
245 }
246 
247 /*
248  * @unimplemented
249  */
250 NTSTATUS
251 NTAPI
IoWMISetSingleInstance(IN PVOID DataBlockObject,IN PUNICODE_STRING InstanceName,IN ULONG Version,IN ULONG ValueBufferSize,IN PVOID ValueBuffer)252 IoWMISetSingleInstance(IN PVOID DataBlockObject,
253                        IN PUNICODE_STRING InstanceName,
254                        IN ULONG Version,
255                        IN ULONG ValueBufferSize,
256                        IN PVOID ValueBuffer)
257 {
258     UNIMPLEMENTED;
259     return STATUS_NOT_IMPLEMENTED;
260 }
261 
262 /*
263  * @unimplemented
264  */
265 NTSTATUS
266 NTAPI
IoWMISetSingleItem(IN PVOID DataBlockObject,IN PUNICODE_STRING InstanceName,IN ULONG DataItemId,IN ULONG Version,IN ULONG ValueBufferSize,IN PVOID ValueBuffer)267 IoWMISetSingleItem(IN PVOID DataBlockObject,
268                    IN PUNICODE_STRING InstanceName,
269                    IN ULONG DataItemId,
270                    IN ULONG Version,
271                    IN ULONG ValueBufferSize,
272                    IN PVOID ValueBuffer)
273 {
274     UNIMPLEMENTED;
275     return STATUS_NOT_IMPLEMENTED;
276 }
277 
278 /*
279  * @unimplemented
280  */
281 NTSTATUS
282 NTAPI
IoWMIExecuteMethod(IN PVOID DataBlockObject,IN PUNICODE_STRING InstanceName,IN ULONG MethodId,IN ULONG InBufferSize,IN OUT PULONG OutBufferSize,IN OUT PUCHAR InOutBuffer)283 IoWMIExecuteMethod(IN PVOID DataBlockObject,
284                    IN PUNICODE_STRING InstanceName,
285                    IN ULONG MethodId,
286                    IN ULONG InBufferSize,
287                    IN OUT PULONG OutBufferSize,
288                    IN OUT PUCHAR InOutBuffer)
289 {
290     UNIMPLEMENTED;
291     return STATUS_NOT_IMPLEMENTED;
292 }
293 
294 /*
295  * @unimplemented
296  */
297 NTSTATUS
298 NTAPI
IoWMISetNotificationCallback(IN PVOID Object,IN WMI_NOTIFICATION_CALLBACK Callback,IN PVOID Context)299 IoWMISetNotificationCallback(IN PVOID Object,
300                              IN WMI_NOTIFICATION_CALLBACK Callback,
301                              IN PVOID Context)
302 {
303     UNIMPLEMENTED;
304     return STATUS_NOT_IMPLEMENTED;
305 }
306 
307 /*
308  * @unimplemented
309  */
310 NTSTATUS
311 NTAPI
IoWMIHandleToInstanceName(IN PVOID DataBlockObject,IN HANDLE FileHandle,OUT PUNICODE_STRING InstanceName)312 IoWMIHandleToInstanceName(IN PVOID DataBlockObject,
313                           IN HANDLE FileHandle,
314                           OUT PUNICODE_STRING InstanceName)
315 {
316     UNIMPLEMENTED;
317     return STATUS_NOT_IMPLEMENTED;
318 }
319 
320 /*
321  * @unimplemented
322  */
323 NTSTATUS
324 NTAPI
IoWMIDeviceObjectToInstanceName(IN PVOID DataBlockObject,IN PDEVICE_OBJECT DeviceObject,OUT PUNICODE_STRING InstanceName)325 IoWMIDeviceObjectToInstanceName(IN PVOID DataBlockObject,
326                                 IN PDEVICE_OBJECT DeviceObject,
327                                 OUT PUNICODE_STRING InstanceName)
328 {
329     UNIMPLEMENTED;
330     return STATUS_NOT_IMPLEMENTED;
331 }
332 
333 /*
334  * @unimplemented
335  */
336 NTSTATUS
337 NTAPI
WmiQueryTraceInformation(IN TRACE_INFORMATION_CLASS TraceInformationClass,OUT PVOID TraceInformation,IN ULONG TraceInformationLength,OUT PULONG RequiredLength OPTIONAL,IN PVOID Buffer OPTIONAL)338 WmiQueryTraceInformation(IN TRACE_INFORMATION_CLASS TraceInformationClass,
339                          OUT PVOID TraceInformation,
340                          IN ULONG TraceInformationLength,
341                          OUT PULONG RequiredLength OPTIONAL,
342                          IN PVOID Buffer OPTIONAL)
343 {
344     UNIMPLEMENTED;
345     return STATUS_NOT_IMPLEMENTED;
346 }
347 
348 /*
349  * @unimplemented
350  */
351 NTSTATUS
352 __cdecl
WmiTraceMessage(IN TRACEHANDLE LoggerHandle,IN ULONG MessageFlags,IN LPGUID MessageGuid,IN USHORT MessageNumber,IN...)353 WmiTraceMessage(IN TRACEHANDLE LoggerHandle,
354                 IN ULONG MessageFlags,
355                 IN LPGUID MessageGuid,
356                 IN USHORT MessageNumber,
357                 IN ...)
358 {
359     UNIMPLEMENTED;
360     return STATUS_NOT_IMPLEMENTED;
361 }
362 
363 /*
364  * @unimplemented
365  */
366 NTSTATUS
367 NTAPI
WmiTraceMessageVa(IN TRACEHANDLE LoggerHandle,IN ULONG MessageFlags,IN LPGUID MessageGuid,IN USHORT MessageNumber,IN va_list MessageArgList)368 WmiTraceMessageVa(IN TRACEHANDLE LoggerHandle,
369                   IN ULONG MessageFlags,
370                   IN LPGUID MessageGuid,
371                   IN USHORT MessageNumber,
372                   IN va_list MessageArgList)
373 {
374     UNIMPLEMENTED;
375     return STATUS_NOT_IMPLEMENTED;
376 }
377 
378 NTSTATUS
379 NTAPI
WmiFlushTrace(IN OUT PWMI_LOGGER_INFORMATION LoggerInfo)380 WmiFlushTrace(IN OUT PWMI_LOGGER_INFORMATION LoggerInfo)
381 {
382     UNIMPLEMENTED;
383     return STATUS_NOT_IMPLEMENTED;
384 }
385 
386 LONG64
387 FASTCALL
WmiGetClock(IN WMI_CLOCK_TYPE ClockType,IN PVOID Context)388 WmiGetClock(IN WMI_CLOCK_TYPE ClockType,
389             IN PVOID Context)
390 {
391     UNIMPLEMENTED;
392     return STATUS_NOT_IMPLEMENTED;
393 }
394 
395 NTSTATUS
396 NTAPI
WmiQueryTrace(IN OUT PWMI_LOGGER_INFORMATION LoggerInfo)397 WmiQueryTrace(IN OUT PWMI_LOGGER_INFORMATION LoggerInfo)
398 {
399     UNIMPLEMENTED;
400     return STATUS_NOT_IMPLEMENTED;
401 }
402 
403 NTSTATUS
404 NTAPI
WmiStartTrace(IN OUT PWMI_LOGGER_INFORMATION LoggerInfo)405 WmiStartTrace(IN OUT PWMI_LOGGER_INFORMATION LoggerInfo)
406 {
407     UNIMPLEMENTED;
408     return STATUS_NOT_IMPLEMENTED;
409 }
410 
411 NTSTATUS
412 NTAPI
WmiStopTrace(IN PWMI_LOGGER_INFORMATION LoggerInfo)413 WmiStopTrace(IN PWMI_LOGGER_INFORMATION LoggerInfo)
414 {
415     UNIMPLEMENTED;
416     return STATUS_NOT_IMPLEMENTED;
417 }
418 
419 NTSTATUS
420 FASTCALL
WmiTraceFastEvent(IN PWNODE_HEADER Wnode)421 WmiTraceFastEvent(IN PWNODE_HEADER Wnode)
422 {
423     UNIMPLEMENTED;
424     return STATUS_NOT_IMPLEMENTED;
425 }
426 
427 NTSTATUS
428 NTAPI
WmiUpdateTrace(IN OUT PWMI_LOGGER_INFORMATION LoggerInfo)429 WmiUpdateTrace(IN OUT PWMI_LOGGER_INFORMATION LoggerInfo)
430 {
431     UNIMPLEMENTED;
432     return STATUS_NOT_IMPLEMENTED;
433 }
434 
435 /*
436  * @unimplemented
437  */
438 NTSTATUS
439 NTAPI
NtTraceEvent(IN ULONG TraceHandle,IN ULONG Flags,IN ULONG TraceHeaderLength,IN struct _EVENT_TRACE_HEADER * TraceHeader)440 NtTraceEvent(IN ULONG TraceHandle,
441              IN ULONG Flags,
442              IN ULONG TraceHeaderLength,
443              IN struct _EVENT_TRACE_HEADER* TraceHeader)
444 {
445     UNIMPLEMENTED;
446     return STATUS_NOT_IMPLEMENTED;
447 }
448 
449 /*Eof*/
450