Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

276 lines
5.8 KiB

  1. #ifndef _HIDBATT_H
  2. #define _HIDBATT_H
  3. /*
  4. * title: hidpwr.h
  5. *
  6. * purpose: header for wdm kernel client interface between HID class and power class
  7. *
  8. */
  9. extern "C"
  10. {
  11. #include <ntddk.h>
  12. #include <batclass.h>
  13. #include <hidpddi.h>
  14. #include <hidclass.h>
  15. }
  16. #define BOOL BOOLEAN
  17. #define BYTE unsigned char
  18. #define PBYTE unsigned char *
  19. extern "C"
  20. {
  21. #include "hid.h"
  22. //#include "hidport.h"
  23. }
  24. #include "drvclass.h"
  25. #include "ckhid.h"
  26. #include "cbattery.h"
  27. #include "devext.h"
  28. extern USHORT gusInstance;
  29. extern USHORT gBatteryTag;
  30. //
  31. // Debug
  32. //
  33. #if DBG
  34. extern ULONG HidBattDebug;
  35. extern USHORT HidBreakFlag;
  36. #define HidBattPrint(l,m) if(l & HidBattDebug) DbgPrint m
  37. #define HIDDebugBreak(l) if((l & HidBreakFlag) ) DbgBreakPoint()
  38. #else
  39. #define HidBattPrint(l,m)
  40. #define HIDDebugBreak(l)
  41. #endif
  42. #define HidBattTag 'HtaB'
  43. #define PrintIoctl(ioctlCode) \
  44. DbgPrint( "DevType %x, Access %x, Function %x, Method %x\n", \
  45. (ioctlCode >> 16), \
  46. ((ioctlCode & 0xc0) >> 12), \
  47. ((ioctlCode & 0x1fc) >> 2), \
  48. (ioctlCode & 0x03) \
  49. )
  50. #define MGE_VENDOR_ID 0x0463
  51. #define APC_VENDOR_ID 0x051D // per Jurang Huang
  52. #define HIDBATT_LOW 0x00000001
  53. #define HIDBATT_NOTE 0x00000002
  54. #define HIDBATT_WARN 0x00000004
  55. #define HIDBATT_ERROR_ONLY 0x00000008
  56. #define HIDBATT_ERROR (HIDBATT_ERROR_ONLY | HIDBATT_WARN)
  57. #define HIDBATT_POWER 0x00000010
  58. #define HIDBATT_PNP 0x00000020
  59. #define HIDBATT_HID_EXE 0x00000040
  60. #define HIDBATT_DATA 0x00000100
  61. #define HIDBATT_TRACE 0x00000200
  62. #define HIDBATT_DEBUG 0x80000000
  63. #define HIDBATT_PRINT_ALWAYS 0xffffffff
  64. #define HIDBATT_PRINT_NEVER 0x0
  65. #define HIDBATT_BREAK_DEBUG 0x0001
  66. #define HIDBATT_BREAK_FULL 0X0002
  67. #define HIDBATT_BREAK_ALWAYS 0xffff
  68. #define HIDBATT_BREAK_NEVER 0x0000
  69. typedef struct {
  70. ULONG Granularity;
  71. ULONG Capacity;
  72. } BATTERY_REMAINING_SCALE, *PBATTERY_REMAINING_SCALE;
  73. //
  74. // Use the IoSkipCurrentIrpStackLocation routine because the we
  75. // don't need to change arguments, or a completion routine
  76. //
  77. #define HidBattCallLowerDriver(Status, DeviceObject, Irp) { \
  78. IoSkipCurrentIrpStackLocation(Irp); \
  79. Status = IoCallDriver(DeviceObject,Irp); \
  80. }
  81. #define GetTid() PsGetCurrentThread()
  82. //
  83. // Prototypes
  84. //
  85. NTSTATUS DoIoctl(
  86. PDEVICE_OBJECT pDev,
  87. ULONG ulIOCTL,
  88. PVOID pInputBuffer,
  89. ULONG ulInputBufferLength,
  90. PVOID pOutputBuffer,
  91. ULONG ulOutputBufferLength,
  92. CHidDevice * pHidDevice);
  93. PHID_DEVICE
  94. SetupHidData(
  95. PHIDP_PREPARSED_DATA pPreparsedData,
  96. PHIDP_CAPS pCaps,
  97. PHIDP_LINK_COLLECTION_NODE pLinkNodes);
  98. ULONG CentiAmpSecsToMilliWattHours(ULONG Amps,ULONG Volts);
  99. ULONG milliWattHoursToCentiAmpSecs(ULONG mwHours, ULONG Volts);
  100. // convert a given value from one exponent to another
  101. ULONG CorrectExponent(ULONG ulBaseValue, SHORT sCurrExponent, SHORT sTargetExponent);
  102. extern "C"
  103. {
  104. NTSTATUS
  105. DriverEntry(
  106. IN PDRIVER_OBJECT DriverObject,
  107. IN PUNICODE_STRING RegistryPath
  108. );
  109. NTSTATUS
  110. HidBattOpen(
  111. IN PDEVICE_OBJECT DeviceObject,
  112. IN PIRP Irp
  113. );
  114. NTSTATUS
  115. HidBattClose(
  116. IN PDEVICE_OBJECT DeviceObject,
  117. IN PIRP Irp
  118. );
  119. NTSTATUS
  120. HidBattIoCompletion(
  121. IN PDEVICE_OBJECT pDeviceObject,
  122. IN PIRP pIrp,
  123. IN PVOID pdoIoCompletedEvent
  124. );
  125. NTSTATUS
  126. HidBattInitializeDevice(
  127. IN PDEVICE_OBJECT DeviceObject,
  128. IN PIRP Irp
  129. );
  130. NTSTATUS
  131. HidBattStopDevice(
  132. IN PDEVICE_OBJECT DeviceObject,
  133. IN PIRP Irp
  134. );
  135. NTSTATUS
  136. HidBattIoControl(
  137. IN PDEVICE_OBJECT DeviceObject,
  138. IN PIRP Irp
  139. );
  140. VOID
  141. HidBattUnload(
  142. IN PDRIVER_OBJECT DriverObject
  143. );
  144. NTSTATUS
  145. HidBattSynchronousRequest (
  146. IN PDEVICE_OBJECT DeviceObject,
  147. IN PIRP Irp,
  148. IN PVOID Context
  149. );
  150. VOID
  151. HidBattAlarm (
  152. IN PVOID Context,
  153. IN UCHAR Address,
  154. IN USHORT Data
  155. );
  156. NTSTATUS
  157. HidBattPnpDispatch(
  158. IN PDEVICE_OBJECT DeviceObject,
  159. IN PIRP Irp
  160. );
  161. NTSTATUS
  162. HidBattPowerDispatch(
  163. IN PDEVICE_OBJECT DeviceObject,
  164. IN PIRP Irp
  165. );
  166. NTSTATUS
  167. HidBattAddDevice(
  168. IN PDRIVER_OBJECT DriverObject,
  169. IN PDEVICE_OBJECT Pdo
  170. );
  171. NTSTATUS
  172. HidBattQueryTag (
  173. IN PVOID Context,
  174. OUT PULONG BatteryTag
  175. );
  176. NTSTATUS
  177. HidBattSetStatusNotify (
  178. IN PVOID Context,
  179. IN ULONG BatteryTag,
  180. IN PBATTERY_NOTIFY BatteryNotify
  181. );
  182. NTSTATUS
  183. HidBattDisableStatusNotify (
  184. IN PVOID Context
  185. );
  186. NTSTATUS
  187. HidBattQueryStatus (
  188. IN PVOID Context,
  189. IN ULONG BatteryTag,
  190. OUT PBATTERY_STATUS BatteryStatus
  191. );
  192. NTSTATUS
  193. HidBattSetInformation (
  194. IN PVOID Context,
  195. IN ULONG BatteryTag,
  196. IN BATTERY_SET_INFORMATION_LEVEL Level,
  197. IN PVOID Buffer OPTIONAL
  198. );
  199. VOID
  200. HidBattNotifyHandler (
  201. IN PVOID Context,
  202. IN CUsage * pUsage
  203. );
  204. VOID
  205. HidBattPowerNotifyHandler (
  206. IN PVOID Context,
  207. IN ULONG NotifyValue
  208. );
  209. NTSTATUS
  210. HidBattQueryInformation (
  211. IN PVOID Context,
  212. IN ULONG BatteryTag,
  213. IN BATTERY_QUERY_INFORMATION_LEVEL Level,
  214. IN LONG AtRate OPTIONAL,
  215. OUT PVOID Buffer,
  216. IN ULONG BufferLength,
  217. OUT PULONG ReturnedLength
  218. );
  219. } // extern "C"
  220. #endif // hidbatt_h