1c2c66affSColin Finck /*
2c2c66affSColin Finck * PROJECT: ReactOS Composite Battery Driver
3c2c66affSColin Finck * LICENSE: BSD - See COPYING.ARM in the top level directory
4c2c66affSColin Finck * FILE: boot/drivers/bus/acpi/compbatt/compmisc.c
5c2c66affSColin Finck * PURPOSE: Miscellaneous Support Routines
6c2c66affSColin Finck * PROGRAMMERS: ReactOS Portable Systems Group
7c2c66affSColin Finck */
8c2c66affSColin Finck
9c2c66affSColin Finck /* INCLUDES *******************************************************************/
10c2c66affSColin Finck
11c2c66affSColin Finck #include "compbatt.h"
12c2c66affSColin Finck
13c2c66affSColin Finck /* FUNCTIONS ******************************************************************/
14c2c66affSColin Finck
15c2c66affSColin Finck NTSTATUS
16c2c66affSColin Finck NTAPI
BatteryIoctl(IN ULONG IoControlCode,IN PDEVICE_OBJECT DeviceObject,IN PVOID InputBuffer,IN ULONG InputBufferLength,IN PVOID OutputBuffer,IN ULONG OutputBufferLength,IN BOOLEAN InternalDeviceIoControl)17c2c66affSColin Finck BatteryIoctl(IN ULONG IoControlCode,
18c2c66affSColin Finck IN PDEVICE_OBJECT DeviceObject,
19c2c66affSColin Finck IN PVOID InputBuffer,
20c2c66affSColin Finck IN ULONG InputBufferLength,
21c2c66affSColin Finck IN PVOID OutputBuffer,
22c2c66affSColin Finck IN ULONG OutputBufferLength,
23c2c66affSColin Finck IN BOOLEAN InternalDeviceIoControl)
24c2c66affSColin Finck {
25c2c66affSColin Finck IO_STATUS_BLOCK IoStatusBlock;
26c2c66affSColin Finck KEVENT Event;
27c2c66affSColin Finck NTSTATUS Status;
28c2c66affSColin Finck PIRP Irp;
29c2c66affSColin Finck PAGED_CODE();
30c2c66affSColin Finck if (CompBattDebug & 0x100) DbgPrint("CompBatt: ENTERING BatteryIoctl\n");
31c2c66affSColin Finck
32c2c66affSColin Finck /* Initialize the event and IRP */
33c2c66affSColin Finck KeInitializeEvent(&Event, SynchronizationEvent, 0);
34c2c66affSColin Finck Irp = IoBuildDeviceIoControlRequest(IoControlCode,
35c2c66affSColin Finck DeviceObject,
36c2c66affSColin Finck InputBuffer,
37c2c66affSColin Finck InputBufferLength,
38c2c66affSColin Finck OutputBuffer,
39c2c66affSColin Finck OutputBufferLength,
40c2c66affSColin Finck InternalDeviceIoControl,
41c2c66affSColin Finck &Event,
42c2c66affSColin Finck &IoStatusBlock);
43c2c66affSColin Finck if (Irp)
44c2c66affSColin Finck {
45c2c66affSColin Finck /* Call the class driver miniport */
46c2c66affSColin Finck Status = IoCallDriver(DeviceObject, Irp);
47c2c66affSColin Finck if (Status == STATUS_PENDING)
48c2c66affSColin Finck {
49c2c66affSColin Finck /* Wait for result */
50c2c66affSColin Finck KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
51c2c66affSColin Finck Status = IoStatusBlock.Status;
52c2c66affSColin Finck }
53c2c66affSColin Finck
54c2c66affSColin Finck /* Print failure */
55c2c66affSColin Finck if (!(NT_SUCCESS(Status)) && (CompBattDebug & 8))
56c2c66affSColin Finck DbgPrint("BatteryIoctl: Irp failed - %x\n", Status);
57c2c66affSColin Finck
58c2c66affSColin Finck /* Done */
59c2c66affSColin Finck if (CompBattDebug & 0x100) DbgPrint("CompBatt: EXITING BatteryIoctl\n");
60c2c66affSColin Finck }
61c2c66affSColin Finck else
62c2c66affSColin Finck {
63c2c66affSColin Finck /* Out of memory */
64c2c66affSColin Finck if (CompBattDebug & 8) DbgPrint("BatteryIoctl: couldn't create Irp\n");
65c2c66affSColin Finck Status = STATUS_INSUFFICIENT_RESOURCES;
66c2c66affSColin Finck }
67c2c66affSColin Finck
68c2c66affSColin Finck /* Return status */
69c2c66affSColin Finck return Status;
70c2c66affSColin Finck }
71c2c66affSColin Finck
72c2c66affSColin Finck NTSTATUS
73c2c66affSColin Finck NTAPI
CompBattGetDeviceObjectPointer(IN PUNICODE_STRING DeviceName,IN ACCESS_MASK DesiredAccess,OUT PFILE_OBJECT * FileObject,OUT PDEVICE_OBJECT * DeviceObject)74c2c66affSColin Finck CompBattGetDeviceObjectPointer(IN PUNICODE_STRING DeviceName,
75c2c66affSColin Finck IN ACCESS_MASK DesiredAccess,
76c2c66affSColin Finck OUT PFILE_OBJECT *FileObject,
77c2c66affSColin Finck OUT PDEVICE_OBJECT *DeviceObject)
78c2c66affSColin Finck {
79c2c66affSColin Finck NTSTATUS Status;
80c2c66affSColin Finck OBJECT_ATTRIBUTES ObjectAttributes;
81c2c66affSColin Finck IO_STATUS_BLOCK IoStatusBlock;
82c2c66affSColin Finck PFILE_OBJECT LocalFileObject;
83c2c66affSColin Finck HANDLE DeviceHandle;
84c2c66affSColin Finck PAGED_CODE();
85c2c66affSColin Finck
86c2c66affSColin Finck /* Open a file object handle to the device */
87*33714797SSerge Gautherie InitializeObjectAttributes(&ObjectAttributes,
88*33714797SSerge Gautherie DeviceName,
89*33714797SSerge Gautherie OBJ_KERNEL_HANDLE,
90*33714797SSerge Gautherie NULL,
91*33714797SSerge Gautherie NULL);
92c2c66affSColin Finck Status = ZwCreateFile(&DeviceHandle,
93c2c66affSColin Finck DesiredAccess,
94c2c66affSColin Finck &ObjectAttributes,
95c2c66affSColin Finck &IoStatusBlock,
96c2c66affSColin Finck NULL,
97c2c66affSColin Finck 0,
98c2c66affSColin Finck FILE_SHARE_READ | FILE_SHARE_WRITE,
99c2c66affSColin Finck FILE_OPEN,
100c2c66affSColin Finck 0,
101c2c66affSColin Finck NULL,
102c2c66affSColin Finck 0);
103c2c66affSColin Finck if (NT_SUCCESS(Status))
104c2c66affSColin Finck {
105c2c66affSColin Finck /* Reference the file object */
106c2c66affSColin Finck Status = ObReferenceObjectByHandle(DeviceHandle,
107c2c66affSColin Finck 0,
108c2c66affSColin Finck *IoFileObjectType,
109c2c66affSColin Finck KernelMode,
110c2c66affSColin Finck (PVOID)&LocalFileObject,
111c2c66affSColin Finck NULL);
112c2c66affSColin Finck if (NT_SUCCESS(Status))
113c2c66affSColin Finck {
114c2c66affSColin Finck /* Return the FO and the associated DO */
115c2c66affSColin Finck *FileObject = LocalFileObject;
116c2c66affSColin Finck *DeviceObject = IoGetRelatedDeviceObject(LocalFileObject);
117c2c66affSColin Finck }
118c2c66affSColin Finck
119c2c66affSColin Finck /* Close the handle */
120c2c66affSColin Finck ZwClose(DeviceHandle);
121c2c66affSColin Finck }
122c2c66affSColin Finck
123c2c66affSColin Finck /* Return status */
124c2c66affSColin Finck return Status;
125c2c66affSColin Finck }
126c2c66affSColin Finck
127c2c66affSColin Finck /* EOF */
128