xref: /reactos/sdk/include/psdk/batclass.h (revision c2c66aff)
1 /*
2  * batclass.h
3  *
4  * Battery class driver interface
5  *
6  * This file is part of the w32api package.
7  *
8  * Contributors:
9  *   Created by Casper S. Hornstrup <chorns@users.sourceforge.net>
10  *
11  * THIS SOFTWARE IS NOT COPYRIGHTED
12  *
13  * This source code is offered for use in the public domain. You may
14  * use, modify or distribute it freely.
15  *
16  * This code is distributed in the hope that it will be useful but
17  * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
18  * DISCLAIMED. This includes but is not limited to warranties of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20  *
21  */
22 
23 #pragma once
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 /* Battery device GUIDs */
30 
31 DEFINE_GUID(GUID_DEVICE_BATTERY,
32   0x72631e54L, 0x78A4, 0x11d0, 0xbc, 0xf7, 0x00, 0xaa, 0x00, 0xb7, 0xb3, 0x2a);
33 
34 #if (NTDDI_VERSION >= NTDDI_WINXP)
35 DEFINE_GUID(BATTERY_STATUS_WMI_GUID,
36   0xfc4670d1, 0xebbf, 0x416e, 0x87, 0xce, 0x37, 0x4a, 0x4e, 0xbc, 0x11, 0x1a);
37 DEFINE_GUID(BATTERY_RUNTIME_WMI_GUID,
38   0x535a3767, 0x1ac2, 0x49bc, 0xa0, 0x77, 0x3f, 0x7a, 0x02, 0xe4, 0x0a, 0xec);
39 DEFINE_GUID(BATTERY_TEMPERATURE_WMI_GUID,
40   0x1a52a14d, 0xadce, 0x4a44, 0x9a, 0x3e, 0xc8, 0xd8, 0xf1, 0x5f, 0xf2, 0xc2);
41 DEFINE_GUID(BATTERY_FULL_CHARGED_CAPACITY_WMI_GUID,
42   0x40b40565, 0x96f7, 0x4435, 0x86, 0x94, 0x97, 0xe0, 0xe4, 0x39, 0x59, 0x05);
43 DEFINE_GUID(BATTERY_CYCLE_COUNT_WMI_GUID,
44   0xef98db24, 0x0014, 0x4c25, 0xa5, 0x0b, 0xc7, 0x24, 0xae, 0x5c, 0xd3, 0x71);
45 DEFINE_GUID(BATTERY_STATIC_DATA_WMI_GUID,
46   0x05e1e463, 0xe4e2, 0x4ea9, 0x80, 0xcb, 0x9b, 0xd4, 0xb3, 0xca, 0x06, 0x55);
47 DEFINE_GUID(BATTERY_STATUS_CHANGE_WMI_GUID,
48   0xcddfa0c3, 0x7c5b, 0x4e43, 0xa0, 0x34, 0x05, 0x9f, 0xa5, 0xb8, 0x43, 0x64);
49 DEFINE_GUID(BATTERY_TAG_CHANGE_WMI_GUID,
50   0x5e1f6e19, 0x8786, 0x4d23, 0x94, 0xfc, 0x9e, 0x74, 0x6b, 0xd5, 0xd8, 0x88);
51 #endif /* (NTDDI_VERSION >= NTDDI_WINXP) */
52 
53 #ifndef _BATCLASS_
54 #define _BATCLASS_
55 
56 /* BATTERY_INFORMATION.Capabilities constants */
57 #define BATTERY_SET_CHARGE_SUPPORTED      0x00000001
58 #define BATTERY_SET_DISCHARGE_SUPPORTED   0x00000002
59 #define BATTERY_SET_RESUME_SUPPORTED      0x00000004
60 #define BATTERY_IS_SHORT_TERM             0x20000000
61 #define BATTERY_CAPACITY_RELATIVE         0x40000000
62 #define BATTERY_SYSTEM_BATTERY            0x80000000
63 
64 /* BATTERY_INFORMATION.Capacity constants */
65 #define BATTERY_UNKNOWN_CAPACITY          0xFFFFFFFF
66 
67 /* BatteryEstimatedTime constant */
68 #define BATTERY_UNKNOWN_TIME              0x80000000
69 
70 #define MAX_BATTERY_STRING_SIZE           128
71 
72 /* BATTERY_STATUS.PowerState flags */
73 #define BATTERY_POWER_ON_LINE             0x00000001
74 #define BATTERY_DISCHARGING               0x00000002
75 #define BATTERY_CHARGING                  0x00000004
76 #define BATTERY_CRITICAL                  0x00000008
77 
78 /* BATTERY_STATUS.Voltage constant */
79 #define BATTERY_UNKNOWN_VOLTAGE           0xFFFFFFFF
80 
81 /* BATTERY_STATUS.Rate constant */
82 #define BATTERY_UNKNOWN_RATE              0x80000000
83 
84 #define IOCTL_BATTERY_QUERY_TAG \
85   CTL_CODE(FILE_DEVICE_BATTERY, 0x10, METHOD_BUFFERED, FILE_READ_ACCESS)
86 #define IOCTL_BATTERY_QUERY_INFORMATION \
87   CTL_CODE(FILE_DEVICE_BATTERY, 0x11, METHOD_BUFFERED, FILE_READ_ACCESS)
88 #define IOCTL_BATTERY_SET_INFORMATION \
89   CTL_CODE(FILE_DEVICE_BATTERY, 0x12, METHOD_BUFFERED, FILE_WRITE_ACCESS)
90 #define IOCTL_BATTERY_QUERY_STATUS \
91   CTL_CODE(FILE_DEVICE_BATTERY, 0x13, METHOD_BUFFERED, FILE_READ_ACCESS)
92 
93 /* NTSTATUS possibly returned by BCLASS_QUERY_STATUS */
94 #define BATTERY_TAG_INVALID 0
95 
96 typedef enum _BATTERY_QUERY_INFORMATION_LEVEL {
97   BatteryInformation = 0,
98   BatteryGranularityInformation,
99   BatteryTemperature,
100   BatteryEstimatedTime,
101   BatteryDeviceName,
102   BatteryManufactureDate,
103   BatteryManufactureName,
104   BatteryUniqueID,
105   BatterySerialNumber
106 } BATTERY_QUERY_INFORMATION_LEVEL;
107 
108 typedef struct _BATTERY_QUERY_INFORMATION {
109   ULONG BatteryTag;
110   BATTERY_QUERY_INFORMATION_LEVEL InformationLevel;
111   LONG AtRate;
112 } BATTERY_QUERY_INFORMATION, *PBATTERY_QUERY_INFORMATION;
113 
114 typedef struct _BATTERY_INFORMATION {
115   ULONG Capabilities;
116   UCHAR Technology;
117   UCHAR Reserved[3];
118   UCHAR Chemistry[4];
119   ULONG DesignedCapacity;
120   ULONG FullChargedCapacity;
121   ULONG DefaultAlert1;
122   ULONG DefaultAlert2;
123   ULONG CriticalBias;
124   ULONG CycleCount;
125 } BATTERY_INFORMATION, *PBATTERY_INFORMATION;
126 
127 typedef struct _BATTERY_MANUFACTURE_DATE {
128   UCHAR Day;
129   UCHAR Month;
130   USHORT Year;
131 } BATTERY_MANUFACTURE_DATE, *PBATTERY_MANUFACTURE_DATE;
132 
133 typedef enum _BATTERY_SET_INFORMATION_LEVEL {
134   BatteryCriticalBias = 0,
135   BatteryCharge,
136   BatteryDischarge
137 } BATTERY_SET_INFORMATION_LEVEL;
138 
139 typedef struct _BATTERY_SET_INFORMATION {
140   ULONG BatteryTag;
141   BATTERY_SET_INFORMATION_LEVEL InformationLevel;
142   UCHAR Buffer[1];
143 } BATTERY_SET_INFORMATION, *PBATTERY_SET_INFORMATION;
144 
145 typedef struct _BATTERY_WAIT_STATUS {
146   ULONG BatteryTag;
147   ULONG Timeout;
148   ULONG PowerState;
149   ULONG LowCapacity;
150   ULONG HighCapacity;
151 } BATTERY_WAIT_STATUS, *PBATTERY_WAIT_STATUS;
152 
153 typedef struct _BATTERY_STATUS {
154   ULONG PowerState;
155   ULONG Capacity;
156   ULONG Voltage;
157   LONG Rate;
158 } BATTERY_STATUS, *PBATTERY_STATUS;
159 
160 #ifndef _WINDOWS_H
161 
162 /* BATTERY_MINIPORT_INFO.XxxVersion */
163 #define BATTERY_CLASS_MAJOR_VERSION       0x0001
164 #define BATTERY_CLASS_MINOR_VERSION       0x0000
165 
166 _Function_class_(BCLASS_QUERY_TAG_CALLBACK)
167 _IRQL_requires_same_
168 _IRQL_requires_max_(PASSIVE_LEVEL)
169 _Check_return_
170 typedef NTSTATUS
171 (NTAPI BCLASS_QUERY_TAG_CALLBACK)(
172   _In_ PVOID Context,
173   _Out_ PULONG BatteryTag);
174 typedef BCLASS_QUERY_TAG_CALLBACK *PBCLASS_QUERY_TAG_CALLBACK;
175 
176 _Function_class_(BCLASS_QUERY_INFORMATION_CALLBACK)
177 _IRQL_requires_same_
178 _IRQL_requires_max_(PASSIVE_LEVEL)
179 _Check_return_
180 typedef NTSTATUS
181 (NTAPI BCLASS_QUERY_INFORMATION_CALLBACK)(
182   _In_ PVOID Context,
183   _In_ ULONG BatteryTag,
184   _In_ BATTERY_QUERY_INFORMATION_LEVEL Level,
185   _In_ LONG AtRate,
186   _Out_writes_bytes_to_(BufferLength, *ReturnedLength) PVOID Buffer,
187   _In_ ULONG BufferLength,
188   _Out_ PULONG ReturnedLength);
189 typedef BCLASS_QUERY_INFORMATION_CALLBACK *PBCLASS_QUERY_INFORMATION_CALLBACK;
190 
191 _Function_class_(BCLASS_QUERY_STATUS_CALLBACK)
192 _IRQL_requires_same_
193 _IRQL_requires_max_(PASSIVE_LEVEL)
194 _Check_return_
195 typedef NTSTATUS
196 (NTAPI BCLASS_QUERY_STATUS_CALLBACK)(
197   _In_ PVOID Context,
198   _In_ ULONG BatteryTag,
199   _Out_ PBATTERY_STATUS BatteryStatus);
200 typedef BCLASS_QUERY_STATUS_CALLBACK *PBCLASS_QUERY_STATUS_CALLBACK;
201 
202 typedef struct _BATTERY_NOTIFY {
203   ULONG PowerState;
204   ULONG LowCapacity;
205   ULONG HighCapacity;
206 } BATTERY_NOTIFY, *PBATTERY_NOTIFY;
207 
208 _Function_class_(BCLASS_SET_STATUS_NOTIFY_CALLBACK)
209 _IRQL_requires_same_
210 _IRQL_requires_max_(PASSIVE_LEVEL)
211 _Check_return_
212 typedef NTSTATUS
213 (NTAPI BCLASS_SET_STATUS_NOTIFY_CALLBACK)(
214   _In_ PVOID Context,
215   _In_ ULONG BatteryTag,
216   _In_ PBATTERY_NOTIFY BatteryNotify);
217 typedef BCLASS_SET_STATUS_NOTIFY_CALLBACK *PBCLASS_SET_STATUS_NOTIFY_CALLBACK;
218 
219 _Function_class_(BCLASS_SET_INFORMATION_CALLBACK)
220 _IRQL_requires_same_
221 _IRQL_requires_max_(PASSIVE_LEVEL)
222 _Check_return_
223 typedef NTSTATUS
224 (NTAPI BCLASS_SET_INFORMATION_CALLBACK)(
225   _In_ PVOID Context,
226   _In_ ULONG BatteryTag,
227   _In_ BATTERY_SET_INFORMATION_LEVEL Level,
228   _In_opt_ PVOID Buffer);
229 typedef BCLASS_SET_INFORMATION_CALLBACK *PBCLASS_SET_INFORMATION_CALLBACK;
230 
231 _Function_class_(BCLASS_DISABLE_STATUS_NOTIFY_CALLBACK)
232 _IRQL_requires_same_
233 _IRQL_requires_max_(PASSIVE_LEVEL)
234 _Check_return_
235 typedef NTSTATUS
236 (NTAPI BCLASS_DISABLE_STATUS_NOTIFY_CALLBACK)(
237   _In_ PVOID Context);
238 typedef BCLASS_DISABLE_STATUS_NOTIFY_CALLBACK *PBCLASS_DISABLE_STATUS_NOTIFY_CALLBACK;
239 
240 typedef PBCLASS_QUERY_TAG_CALLBACK BCLASS_QUERY_TAG;
241 typedef PBCLASS_QUERY_INFORMATION_CALLBACK BCLASS_QUERY_INFORMATION;
242 typedef PBCLASS_QUERY_STATUS_CALLBACK BCLASS_QUERY_STATUS;
243 typedef PBCLASS_SET_STATUS_NOTIFY_CALLBACK BCLASS_SET_STATUS_NOTIFY;
244 typedef PBCLASS_SET_INFORMATION_CALLBACK BCLASS_SET_INFORMATION;
245 typedef PBCLASS_DISABLE_STATUS_NOTIFY_CALLBACK BCLASS_DISABLE_STATUS_NOTIFY;
246 
247 typedef struct _BATTERY_MINIPORT_INFO {
248   USHORT MajorVersion;
249   USHORT MinorVersion;
250   PVOID Context;
251   BCLASS_QUERY_TAG QueryTag;
252   BCLASS_QUERY_INFORMATION QueryInformation;
253   BCLASS_SET_INFORMATION SetInformation;
254   BCLASS_QUERY_STATUS QueryStatus;
255   BCLASS_SET_STATUS_NOTIFY SetStatusNotify;
256   BCLASS_DISABLE_STATUS_NOTIFY DisableStatusNotify;
257   PDEVICE_OBJECT Pdo;
258   PUNICODE_STRING DeviceName;
259 } BATTERY_MINIPORT_INFO, *PBATTERY_MINIPORT_INFO;
260 
261 #if (NTDDI_VERSION >= NTDDI_WINXP)
262 
263 typedef struct _BATTERY_WMI_STATUS {
264   ULONG Tag;
265   ULONG RemainingCapacity;
266   LONG ChargeRate;
267   LONG DischargeRate;
268   ULONG Voltage;
269   BOOLEAN PowerOnline;
270   BOOLEAN Charging;
271   BOOLEAN Discharging;
272   BOOLEAN Critical;
273 } BATTERY_WMI_STATUS, *PBATTERY_WMI_STATUS;
274 
275 typedef struct _BATTERY_WMI_RUNTIME {
276   ULONG Tag;
277   ULONG EstimatedRuntime;
278 } BATTERY_WMI_RUNTIME, *PBATTERY_WMI_RUNTIME;
279 
280 typedef struct _BATTERY_WMI_TEMPERATURE {
281   ULONG Tag;
282   ULONG Temperature;
283 } BATTERY_WMI_TEMPERATURE, *PBATTERY_WMI_TEMPERATURE;
284 
285 typedef struct _BATTERY_WMI_FULL_CHARGED_CAPACITY {
286   ULONG Tag;
287   ULONG FullChargedCapacity;
288 } BATTERY_WMI_FULL_CHARGED_CAPACITY, *PBATTERY_WMI_FULL_CHARGED_CAPACITY;
289 
290 typedef struct _BATTERY_WMI_CYCLE_COUNT {
291   ULONG Tag;
292   ULONG CycleCount;
293 } BATTERY_WMI_CYCLE_COUNT, *PBATTERY_WMI_CYCLE_COUNT;
294 
295 typedef struct _BATTERY_WMI_STATIC_DATA {
296   ULONG Tag;
297   WCHAR ManufactureDate[25];
298   BATTERY_REPORTING_SCALE Granularity [4];
299   ULONG Capabilities;
300   UCHAR Technology;
301   ULONG Chemistry;
302   ULONG DesignedCapacity;
303   ULONG DefaultAlert1;
304   ULONG DefaultAlert2;
305   ULONG CriticalBias;
306   WCHAR Strings[1];
307 } BATTERY_WMI_STATIC_DATA, *PBATTERY_WMI_STATIC_DATA;
308 
309 typedef struct _BATTERY_WMI_STATUS_CHANGE {
310   ULONG Tag;
311   BOOLEAN PowerOnline;
312   BOOLEAN Charging;
313   BOOLEAN Discharging;
314   BOOLEAN Critical;
315 } BATTERY_WMI_STATUS_CHANGE, *PBATTERY_WMI_STATUS_CHANGE;
316 
317 typedef struct _BATTERY_TAG_CHANGE {
318   ULONG Tag;
319 } BATTERY_TAG_CHANGE, *PBATTERY_TAG_CHANGE;
320 
321 #endif /* (NTDDI_VERSION >= NTDDI_WINXP) */
322 
323 #if defined(_BATTERYCLASS_)
324 #define BCLASSAPI
325 #else
326 #define BCLASSAPI DECLSPEC_IMPORT
327 #endif
328 
329 _IRQL_requires_max_(PASSIVE_LEVEL)
330 _Check_return_
331 BCLASSAPI
332 NTSTATUS
333 NTAPI
334 BatteryClassInitializeDevice(
335   _In_ PBATTERY_MINIPORT_INFO MiniportInfo,
336   _Out_ PVOID *ClassData);
337 
338 _IRQL_requires_max_(PASSIVE_LEVEL)
339 _Check_return_
340 BCLASSAPI
341 NTSTATUS
342 NTAPI
343 BatteryClassIoctl(
344   _In_ PVOID ClassData,
345   _Inout_ PIRP Irp);
346 
347 _IRQL_requires_max_(DISPATCH_LEVEL)
348 BCLASSAPI
349 NTSTATUS
350 NTAPI
351 BatteryClassStatusNotify(
352   _In_ PVOID ClassData);
353 
354 #if (NTDDI_VERSION >= NTDDI_WINXP)
355 
356 _IRQL_requires_max_(PASSIVE_LEVEL)
357 _Check_return_
358 BCLASSAPI
359 NTSTATUS
360 NTAPI
361 BatteryClassQueryWmiDataBlock(
362   _In_ PVOID ClassData,
363   _Inout_ PDEVICE_OBJECT DeviceObject,
364   _Inout_ PIRP Irp,
365   _In_ ULONG GuidIndex,
366   _Out_writes_(1) PULONG InstanceLengthArray,
367   _In_ ULONG OutBufferSize,
368   _Out_writes_bytes_opt_(OutBufferSize) PUCHAR Buffer);
369 
370 _IRQL_requires_max_(PASSIVE_LEVEL)
371 _Check_return_
372 BCLASSAPI
373 NTSTATUS
374 NTAPI
375 BatteryClassSystemControl(
376   _In_ PVOID ClassData,
377   _In_ PVOID WmiLibContext, /* PWMILIB_CONTEXT */
378   _In_ PDEVICE_OBJECT DeviceObject,
379   _Inout_ PIRP Irp,
380   _Out_ PVOID Disposition); /* PSYSCTL_IRP_DISPOSITION */
381 
382 #endif /* (NTDDI_VERSION >= NTDDI_WINXP) */
383 
384 _IRQL_requires_max_(PASSIVE_LEVEL)
385 BCLASSAPI
386 NTSTATUS
387 NTAPI
388 BatteryClassUnload(
389   _In_ PVOID ClassData);
390 
391 #endif /* _WINDOWS_H */
392 
393 #endif /* _BATCLASS_ */
394 
395 #ifdef __cplusplus
396 }
397 #endif
398