| 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 | #ifndef __BATCLASS_H | 
 
 
 
 
 | 24 | #define __BATCLASS_H | 
 
 
 
 
 | 25 |  | 
 
 
 
 
 | 26 | #if __GNUC__ >=3 | 
 
 
 
 
 | 27 | #pragma GCC system_header | 
 
 
 
 
 | 28 | #endif | 
 
 
 
 
 | 29 |  | 
 
 
 
 
 | 30 | #ifdef __cplusplus | 
 
 
 
 
 | 31 | extern "C" { | 
 
 
 
 
 | 32 | #endif | 
 
 
 
 
 | 33 |  | 
 
 
 
 
 | 34 | #include "ntddk.h" | 
 
 
 
 
 | 35 |  | 
 
 
 
 
 | 36 | #if defined(_BATTERYCLASS_) | 
 
 
 
 
 | 37 | #define BCLASSAPI DECLSPEC_EXPORT | 
 
 
 
 
 | 38 | #else | 
 
 
 
 
 | 39 | #define BCLASSAPI DECLSPEC_IMPORT | 
 
 
 
 
 | 40 | #endif | 
 
 
 
 
 | 41 |  | 
 
 
 
 
 | 42 |  | 
 
 
 
 
 | 43 | /* Battery device GUIDs */ | 
 
 
 
 
 | 44 |  | 
 
 
 
 
 | 45 | DEFINE_GUID(GUID_DEVICE_BATTERY, | 
 
 
 
 
 | 46 | 0x72631e54L, 0x78A4, 0x11d0, 0xbc, 0xf7, 0x00, 0xaa, 0x00, 0xb7, 0xb3, 0x2a); | 
 
 
 
 
 | 47 |  | 
 
 
 
 
 | 48 | DEFINE_GUID(BATTERY_STATUS_WMI_GUID, | 
 
 
 
 
 | 49 | 0xfc4670d1, 0xebbf, 0x416e, 0x87, 0xce, 0x37, 0x4a, 0x4e, 0xbc, 0x11, 0x1a); | 
 
 
 
 
 | 50 |  | 
 
 
 
 
 | 51 | DEFINE_GUID(BATTERY_RUNTIME_WMI_GUID, | 
 
 
 
 
 | 52 | 0x535a3767, 0x1ac2, 0x49bc, 0xa0, 0x77, 0x3f, 0x7a, 0x02, 0xe4, 0x0a, 0xec); | 
 
 
 
 
 | 53 |  | 
 
 
 
 
 | 54 | DEFINE_GUID(BATTERY_TEMPERATURE_WMI_GUID, | 
 
 
 
 
 | 55 | 0x1a52a14d, 0xadce, 0x4a44, 0x9a, 0x3e, 0xc8, 0xd8, 0xf1, 0x5f, 0xf2, 0xc2); | 
 
 
 
 
 | 56 |  | 
 
 
 
 
 | 57 | DEFINE_GUID(BATTERY_FULL_CHARGED_CAPACITY_WMI_GUID, | 
 
 
 
 
 | 58 | 0x40b40565, 0x96f7, 0x4435, 0x86, 0x94, 0x97, 0xe0, 0xe4, 0x39, 0x59, 0x05); | 
 
 
 
 
 | 59 |  | 
 
 
 
 
 | 60 | DEFINE_GUID(BATTERY_CYCLE_COUNT_WMI_GUID, | 
 
 
 
 
 | 61 | 0xef98db24, 0x0014, 0x4c25, 0xa5, 0x0b, 0xc7, 0x24, 0xae, 0x5c, 0xd3, 0x71); | 
 
 
 
 
 | 62 |  | 
 
 
 
 
 | 63 | DEFINE_GUID(BATTERY_STATIC_DATA_WMI_GUID, | 
 
 
 
 
 | 64 | 0x05e1e463, 0xe4e2, 0x4ea9, 0x80, 0xcb, 0x9b, 0xd4, 0xb3, 0xca, 0x06, 0x55); | 
 
 
 
 
 | 65 |  | 
 
 
 
 
 | 66 | DEFINE_GUID(BATTERY_STATUS_CHANGE_WMI_GUID, | 
 
 
 
 
 | 67 | 0xcddfa0c3, 0x7c5b, 0x4e43, 0xa0, 0x34, 0x05, 0x9f, 0xa5, 0xb8, 0x43, 0x64); | 
 
 
 
 
 | 68 |  | 
 
 
 
 
 | 69 | DEFINE_GUID(BATTERY_TAG_CHANGE_WMI_GUID, | 
 
 
 
 
 | 70 | 0x5e1f6e19, 0x8786, 0x4d23, 0x94, 0xfc, 0x9e, 0x74, 0x6b, 0xd5, 0xd8, 0x88); | 
 
 
 
 
 | 71 |  | 
 
 
 
 
 | 72 |  | 
 
 
 
 
 | 73 | /* BATTERY_INFORMATION.Capabilities constants */ | 
 
 
 
 
 | 74 | #define BATTERY_SET_CHARGE_SUPPORTED      0x00000001 | 
 
 
 
 
 | 75 | #define BATTERY_SET_DISCHARGE_SUPPORTED   0x00000002 | 
 
 
 
 
 | 76 | #define BATTERY_SET_RESUME_SUPPORTED      0x00000004 | 
 
 
 
 
 | 77 | #define BATTERY_IS_SHORT_TERM             0x20000000 | 
 
 
 
 
 | 78 | #define BATTERY_CAPACITY_RELATIVE         0x40000000 | 
 
 
 
 
 | 79 | #define BATTERY_SYSTEM_BATTERY            0x80000000 | 
 
 
 
 
 | 80 |  | 
 
 
 
 
 | 81 | typedef struct _BATTERY_INFORMATION { | 
 
 
 
 
 | 82 | ULONG  Capabilities; | 
 
 
 
 
 | 83 | UCHAR  Technology; | 
 
 
 
 
 | 84 | UCHAR  Reserved[3]; | 
 
 
 
 
 | 85 | UCHAR  Chemistry[4]; | 
 
 
 
 
 | 86 | ULONG  DesignedCapacity; | 
 
 
 
 
 | 87 | ULONG  FullChargedCapacity; | 
 
 
 
 
 | 88 | ULONG  DefaultAlert1; | 
 
 
 
 
 | 89 | ULONG  DefaultAlert2; | 
 
 
 
 
 | 90 | ULONG  CriticalBias; | 
 
 
 
 
 | 91 | ULONG  CycleCount; | 
 
 
 
 
 | 92 | } BATTERY_INFORMATION, *PBATTERY_INFORMATION; | 
 
 
 
 
 | 93 |  | 
 
 
 
 
 | 94 | typedef struct _BATTERY_MANUFACTURE_DATE { | 
 
 
 
 
 | 95 | UCHAR  Day; | 
 
 
 
 
 | 96 | UCHAR  Month; | 
 
 
 
 
 | 97 | USHORT  Year; | 
 
 
 
 
 | 98 | } BATTERY_MANUFACTURE_DATE, *PBATTERY_MANUFACTURE_DATE; | 
 
 
 
 
 | 99 |  | 
 
 
 
 
 | 100 | typedef struct _BATTERY_NOTIFY { | 
 
 
 
 
 | 101 | ULONG  PowerState; | 
 
 
 
 
 | 102 | ULONG  LowCapacity; | 
 
 
 
 
 | 103 | ULONG  HighCapacity; | 
 
 
 
 
 | 104 | } BATTERY_NOTIFY, *PBATTERY_NOTIFY; | 
 
 
 
 
 | 105 |  | 
 
 
 
 
 | 106 | /* BATTERY_STATUS.PowerState flags */ | 
 
 
 
 
 | 107 | #define BATTERY_POWER_ON_LINE             0x00000001 | 
 
 
 
 
 | 108 | #define BATTERY_DISCHARGING               0x00000002 | 
 
 
 
 
 | 109 | #define BATTERY_CHARGING                  0x00000004 | 
 
 
 
 
 | 110 | #define BATTERY_CRITICAL                  0x00000008 | 
 
 
 
 
 | 111 |  | 
 
 
 
 
 | 112 | /* BATTERY_STATUS.Voltage constant */ | 
 
 
 
 
 | 113 | #define BATTERY_UNKNOWN_VOLTAGE           0xFFFFFFFF | 
 
 
 
 
 | 114 |  | 
 
 
 
 
 | 115 | /* BATTERY_STATUS.Rate constant */ | 
 
 
 
 
 | 116 | #define BATTERY_UNKNOWN_RATE              0x80000000 | 
 
 
 
 
 | 117 |  | 
 
 
 
 
 | 118 | typedef struct _BATTERY_STATUS { | 
 
 
 
 
 | 119 | ULONG  PowerState; | 
 
 
 
 
 | 120 | ULONG  Capacity; | 
 
 
 
 
 | 121 | ULONG  Voltage; | 
 
 
 
 
 | 122 | LONG  Rate; | 
 
 
 
 
 | 123 | } BATTERY_STATUS, *PBATTERY_STATUS; | 
 
 
 
 
 | 124 |  | 
 
 
 
 
 | 125 | /* BATTERY_INFORMATION.Capacity constants */ | 
 
 
 
 
 | 126 | #define BATTERY_UNKNOWN_CAPACITY          0xFFFFFFFF | 
 
 
 
 
 | 127 |  | 
 
 
 
 
 | 128 | typedef enum _BATTERY_QUERY_INFORMATION_LEVEL { | 
 
 
 
 
 | 129 | BatteryInformation = 0, | 
 
 
 
 
 | 130 | BatteryGranularityInformation, | 
 
 
 
 
 | 131 | BatteryTemperature, | 
 
 
 
 
 | 132 | BatteryEstimatedTime, | 
 
 
 
 
 | 133 | BatteryDeviceName, | 
 
 
 
 
 | 134 | BatteryManufactureDate, | 
 
 
 
 
 | 135 | BatteryManufactureName, | 
 
 
 
 
 | 136 | BatteryUniqueID, | 
 
 
 
 
 | 137 | BatterySerialNumber | 
 
 
 
 
 | 138 | } BATTERY_QUERY_INFORMATION_LEVEL; | 
 
 
 
 
 | 139 |  | 
 
 
 
 
 | 140 | /* BatteryEstimatedTime constant */ | 
 
 
 
 
 | 141 | #define BATTERY_UNKNOWN_TIME              0x80000000 | 
 
 
 
 
 | 142 |  | 
 
 
 
 
 | 143 | /* NTSTATUS possibly returned by BCLASS_QUERY_STATUS */ | 
 
 
 
 
 | 144 | #define BATTERY_TAG_INVALID 0 | 
 
 
 
 
 | 145 |  | 
 
 
 
 
 | 146 | typedef struct _BATTERY_QUERY_INFORMATION { | 
 
 
 
 
 | 147 | ULONG  BatteryTag; | 
 
 
 
 
 | 148 | BATTERY_QUERY_INFORMATION_LEVEL  InformationLevel; | 
 
 
 
 
 | 149 | LONG  AtRate; | 
 
 
 
 
 | 150 | } BATTERY_QUERY_INFORMATION, *PBATTERY_QUERY_INFORMATION; | 
 
 
 
 
 | 151 |  | 
 
 
 
 
 | 152 | typedef enum _BATTERY_SET_INFORMATION_LEVEL { | 
 
 
 
 
 | 153 | BatteryCriticalBias = 0, | 
 
 
 
 
 | 154 | BatteryCharge, | 
 
 
 
 
 | 155 | BatteryDischarge | 
 
 
 
 
 | 156 | } BATTERY_SET_INFORMATION_LEVEL; | 
 
 
 
 
 | 157 |  | 
 
 
 
 
 | 158 | #define MAX_BATTERY_STRING_SIZE           128 | 
 
 
 
 
 | 159 |  | 
 
 
 
 
 | 160 | typedef struct _BATTERY_SET_INFORMATION { | 
 
 
 
 
 | 161 | ULONG  BatteryTag; | 
 
 
 
 
 | 162 | BATTERY_SET_INFORMATION_LEVEL  InformationLevel; | 
 
 
 
 
 | 163 | UCHAR  Buffer[1]; | 
 
 
 
 
 | 164 | } BATTERY_SET_INFORMATION, *PBATTERY_SET_INFORMATION; | 
 
 
 
 
 | 165 |  | 
 
 
 
 
 | 166 | typedef struct _BATTERY_WAIT_STATUS { | 
 
 
 
 
 | 167 | ULONG  BatteryTag; | 
 
 
 
 
 | 168 | ULONG  Timeout; | 
 
 
 
 
 | 169 | ULONG  PowerState; | 
 
 
 
 
 | 170 | ULONG  LowCapacity; | 
 
 
 
 
 | 171 | ULONG  HighCapacity; | 
 
 
 
 
 | 172 | } BATTERY_WAIT_STATUS, *PBATTERY_WAIT_STATUS; | 
 
 
 
 
 | 173 |  | 
 
 
 
 
 | 174 |  | 
 
 
 
 
 | 175 | #define IOCTL_BATTERY_QUERY_TAG \ | 
 
 
 
 
 | 176 | CTL_CODE(FILE_DEVICE_BATTERY, 0x10, METHOD_BUFFERED, FILE_READ_ACCESS) | 
 
 
 
 
 | 177 |  | 
 
 
 
 
 | 178 | #define IOCTL_BATTERY_QUERY_INFORMATION \ | 
 
 
 
 
 | 179 | CTL_CODE(FILE_DEVICE_BATTERY, 0x11, METHOD_BUFFERED, FILE_READ_ACCESS) | 
 
 
 
 
 | 180 |  | 
 
 
 
 
 | 181 | #define IOCTL_BATTERY_SET_INFORMATION \ | 
 
 
 
 
 | 182 | CTL_CODE(FILE_DEVICE_BATTERY, 0x12, METHOD_BUFFERED, FILE_WRITE_ACCESS) | 
 
 
 
 
 | 183 |  | 
 
 
 
 
 | 184 | #define IOCTL_BATTERY_QUERY_STATUS \ | 
 
 
 
 
 | 185 | CTL_CODE(FILE_DEVICE_BATTERY, 0x13, METHOD_BUFFERED, FILE_READ_ACCESS) | 
 
 
 
 
 | 186 |  | 
 
 
 
 
 | 187 |  | 
 
 
 
 
 | 188 | typedef NTSTATUS DDKAPI | 
 
 
 
 
 | 189 | (*BCLASS_DISABLE_STATUS_NOTIFY)( | 
 
 
 
 
 | 190 | /*IN*/ PVOID  Context); | 
 
 
 
 
 | 191 |  | 
 
 
 
 
 | 192 | typedef NTSTATUS DDKAPI | 
 
 
 
 
 | 193 | (*BCLASS_QUERY_INFORMATION)( | 
 
 
 
 
 | 194 | /*IN*/ PVOID  Context, | 
 
 
 
 
 | 195 | /*IN*/ ULONG  BatteryTag, | 
 
 
 
 
 | 196 | /*IN*/ BATTERY_QUERY_INFORMATION_LEVEL  Level, | 
 
 
 
 
 | 197 | /*IN*/ LONG  AtRate  /*OPTIONAL*/, | 
 
 
 
 
 | 198 | /*OUT*/ PVOID  Buffer, | 
 
 
 
 
 | 199 | /*IN*/ ULONG  BufferLength, | 
 
 
 
 
 | 200 | /*OUT*/ PULONG  ReturnedLength); | 
 
 
 
 
 | 201 |  | 
 
 
 
 
 | 202 | typedef NTSTATUS DDKAPI | 
 
 
 
 
 | 203 | (*BCLASS_QUERY_STATUS)( | 
 
 
 
 
 | 204 | /*IN*/ PVOID  Context, | 
 
 
 
 
 | 205 | /*IN*/ ULONG  BatteryTag, | 
 
 
 
 
 | 206 | /*OUT*/ PBATTERY_STATUS  BatteryStatus); | 
 
 
 
 
 | 207 |  | 
 
 
 
 
 | 208 | typedef NTSTATUS DDKAPI | 
 
 
 
 
 | 209 | (*BCLASS_QUERY_TAG)( | 
 
 
 
 
 | 210 | /*IN*/ PVOID  Context, | 
 
 
 
 
 | 211 | /*OUT*/ PULONG  BatteryTag); | 
 
 
 
 
 | 212 |  | 
 
 
 
 
 | 213 | typedef NTSTATUS DDKAPI | 
 
 
 
 
 | 214 | (*BCLASS_SET_INFORMATION)( | 
 
 
 
 
 | 215 | /*IN*/ PVOID  Context, | 
 
 
 
 
 | 216 | /*IN*/ ULONG  BatteryTag, | 
 
 
 
 
 | 217 | /*IN*/ BATTERY_SET_INFORMATION_LEVEL  Level, | 
 
 
 
 
 | 218 | /*IN*/ PVOID  Buffer  /*OPTIONAL*/); | 
 
 
 
 
 | 219 |  | 
 
 
 
 
 | 220 | typedef NTSTATUS DDKAPI | 
 
 
 
 
 | 221 | (*BCLASS_SET_STATUS_NOTIFY)( | 
 
 
 
 
 | 222 | /*IN*/ PVOID  Context, | 
 
 
 
 
 | 223 | /*IN*/ ULONG  BatteryTag, | 
 
 
 
 
 | 224 | /*IN*/ PBATTERY_NOTIFY  BatteryNotify); | 
 
 
 
 
 | 225 |  | 
 
 
 
 
 | 226 |  | 
 
 
 
 
 | 227 | typedef struct _BATTERY_MINIPORT_INFO { | 
 
 
 
 
 | 228 | USHORT  MajorVersion; | 
 
 
 
 
 | 229 | USHORT  MinorVersion; | 
 
 
 
 
 | 230 | PVOID  Context; | 
 
 
 
 
 | 231 | BCLASS_QUERY_TAG  QueryTag; | 
 
 
 
 
 | 232 | BCLASS_QUERY_INFORMATION  QueryInformation; | 
 
 
 
 
 | 233 | BCLASS_SET_INFORMATION  SetInformation; | 
 
 
 
 
 | 234 | BCLASS_QUERY_STATUS  QueryStatus; | 
 
 
 
 
 | 235 | BCLASS_SET_STATUS_NOTIFY  SetStatusNotify; | 
 
 
 
 
 | 236 | BCLASS_DISABLE_STATUS_NOTIFY  DisableStatusNotify; | 
 
 
 
 
 | 237 | PDEVICE_OBJECT  Pdo; | 
 
 
 
 
 | 238 | PUNICODE_STRING  DeviceName; | 
 
 
 
 
 | 239 | } BATTERY_MINIPORT_INFO, *PBATTERY_MINIPORT_INFO; | 
 
 
 
 
 | 240 |  | 
 
 
 
 
 | 241 | /* BATTERY_MINIPORT_INFO.XxxVersion */ | 
 
 
 
 
 | 242 | #define BATTERY_CLASS_MAJOR_VERSION       0x0001 | 
 
 
 
 
 | 243 | #define BATTERY_CLASS_MINOR_VERSION       0x0000 | 
 
 
 
 
 | 244 |  | 
 
 
 
 
 | 245 |  | 
 
 
 
 
 | 246 | BCLASSAPI | 
 
 
 
 
 | 247 | NTSTATUS | 
 
 
 
 
 | 248 | DDKAPI | 
 
 
 
 
 | 249 | BatteryClassInitializeDevice( | 
 
 
 
 
 | 250 | /*IN*/ PBATTERY_MINIPORT_INFO  MiniportInfo, | 
 
 
 
 
 | 251 | /*IN*/ PVOID  *ClassData); | 
 
 
 
 
 | 252 |  | 
 
 
 
 
 | 253 | BCLASSAPI | 
 
 
 
 
 | 254 | NTSTATUS | 
 
 
 
 
 | 255 | DDKAPI | 
 
 
 
 
 | 256 | BatteryClassIoctl( | 
 
 
 
 
 | 257 | /*IN*/ PVOID  ClassData, | 
 
 
 
 
 | 258 | /*IN*/ PIRP  Irp); | 
 
 
 
 
 | 259 |  | 
 
 
 
 
 | 260 | BCLASSAPI | 
 
 
 
 
 | 261 | NTSTATUS | 
 
 
 
 
 | 262 | DDKAPI | 
 
 
 
 
 | 263 | BatteryClassQueryWmiDataBlock( | 
 
 
 
 
 | 264 | /*IN*/ PVOID  ClassData, | 
 
 
 
 
 | 265 | /*IN*/ PDEVICE_OBJECT  DeviceObject, | 
 
 
 
 
 | 266 | /*IN*/ PIRP  Irp, | 
 
 
 
 
 | 267 | /*IN*/ ULONG  GuidIndex, | 
 
 
 
 
 | 268 | /*IN OUT*/ PULONG  InstanceLengthArray, | 
 
 
 
 
 | 269 | /*IN*/ ULONG  OutBufferSize, | 
 
 
 
 
 | 270 | /*OUT*/ PUCHAR  Buffer); | 
 
 
 
 
 | 271 |  | 
 
 
 
 
 | 272 | BCLASSAPI | 
 
 
 
 
 | 273 | NTSTATUS | 
 
 
 
 
 | 274 | DDKAPI | 
 
 
 
 
 | 275 | BatteryClassStatusNotify( | 
 
 
 
 
 | 276 | /*IN*/ PVOID  ClassData); | 
 
 
 
 
 | 277 |  | 
 
 
 
 
 | 278 | BCLASSAPI | 
 
 
 
 
 | 279 | NTSTATUS | 
 
 
 
 
 | 280 | DDKAPI | 
 
 
 
 
 | 281 | BatteryClassSystemControl( | 
 
 
 
 
 | 282 | /*IN*/ PVOID  ClassData, | 
 
 
 
 
 | 283 | /*IN*/ PWMILIB_CONTEXT  WmiLibContext, | 
 
 
 
 
 | 284 | /*IN*/ PDEVICE_OBJECT  DeviceObject, | 
 
 
 
 
 | 285 | /*IN*/ PIRP  Irp, | 
 
 
 
 
 | 286 | /*OUT*/ PSYSCTL_IRP_DISPOSITION  Disposition); | 
 
 
 
 
 | 287 |  | 
 
 
 
 
 | 288 | BCLASSAPI | 
 
 
 
 
 | 289 | NTSTATUS | 
 
 
 
 
 | 290 | DDKAPI | 
 
 
 
 
 | 291 | BatteryClassUnload( | 
 
 
 
 
 | 292 | /*IN*/ PVOID  ClassData); | 
 
 
 
 
 | 293 |  | 
 
 
 
 
 | 294 | #ifdef __cplusplus | 
 
 
 
 
 | 295 | } | 
 
 
 
 
 | 296 | #endif | 
 
 
 
 
 | 297 |  | 
 
 
 
 
 | 298 | #endif /* __BATCLASS_H */ |