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.

494 lines
13 KiB

  1. /*++ BUILD Version: 0000 // Increment this if a change has global effects
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. wmilib.h
  5. Abstract:
  6. This module contains the internal structure definitions and APIs used by
  7. the WMILIB helper functions
  8. Author:
  9. AlanWar
  10. Revision History:
  11. --*/
  12. #ifndef _WMILIB_
  13. #define _WMILIB_
  14. #if defined (_MSC_VER) && (_MSC_VER >= 1020)
  15. #pragma once
  16. #endif
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. //
  21. // This defines a guid to be registered with WMI. Memory for this structure
  22. // may be Paged.
  23. typedef struct
  24. {
  25. LPCGUID Guid; // Guid to registered
  26. ULONG InstanceCount; // Count of Instances of Datablock
  27. ULONG Flags; // Additional flags (see WMIREGINFO in wmistr.h)
  28. } WMIGUIDREGINFO, *PWMIGUIDREGINFO;
  29. typedef
  30. NTSTATUS
  31. (*PWMI_QUERY_REGINFO) (
  32. IN PDEVICE_OBJECT DeviceObject,
  33. OUT PULONG RegFlags,
  34. OUT PUNICODE_STRING InstanceName,
  35. OUT PUNICODE_STRING *RegistryPath,
  36. OUT PUNICODE_STRING MofResourceName,
  37. OUT PDEVICE_OBJECT *Pdo
  38. );
  39. /*++
  40. Routine Description:
  41. This routine is a callback into the driver to retrieve information about
  42. the guids being registered.
  43. Implementations of this routine may be in paged memory
  44. Arguments:
  45. DeviceObject is the device whose registration information is needed
  46. *RegFlags returns with a set of flags that describe all of the guids being
  47. registered for this device. If the device wants enable and disable
  48. collection callbacks before receiving queries for the registered
  49. guids then it should return the WMIREG_FLAG_EXPENSIVE flag. Also the
  50. returned flags may specify WMIREG_FLAG_INSTANCE_PDO in which case
  51. the instance name is determined from the PDO associated with the
  52. device object. Note that the PDO must have an associated devnode. If
  53. WMIREG_FLAG_INSTANCE_PDO is not set then Name must return a unique
  54. name for the device. These flags are ORed into the flags specified
  55. by the GUIDREGINFO for each guid.
  56. InstanceName returns with the instance name for the guids if
  57. WMIREG_FLAG_INSTANCE_PDO is not set in the returned *RegFlags. The
  58. caller will call ExFreePool with the buffer returned.
  59. *RegistryPath returns with the registry path of the driver. This is
  60. required
  61. MofResourceName returns with the name of the MOF resource attached to
  62. the binary file. If the driver does not have a mof resource attached
  63. then this can be returned unmodified. If a value is returned then
  64. it is NOT freed.
  65. *Pdo returns with the device object for the PDO associated with this
  66. device if the WMIREG_FLAG_INSTANCE_PDO flag is retured in
  67. *RegFlags.
  68. Return Value:
  69. status
  70. --*/
  71. typedef
  72. NTSTATUS
  73. (*PWMI_QUERY_DATABLOCK) (
  74. IN PDEVICE_OBJECT DeviceObject,
  75. IN PIRP Irp,
  76. IN ULONG GuidIndex,
  77. IN ULONG InstanceIndex,
  78. IN ULONG InstanceCount,
  79. IN OUT PULONG InstanceLengthArray,
  80. IN ULONG BufferAvail,
  81. OUT PUCHAR Buffer
  82. );
  83. /*++
  84. Routine Description:
  85. This routine is a callback into the driver to query for the contents of
  86. one or more instances of a data block. When the driver has finished
  87. filling the
  88. data block it must call WmiCompleteRequest to complete the irp. The
  89. driver can return STATUS_PENDING if the irp cannot be completed
  90. immediately.
  91. Implementations of this routine may be in paged memory
  92. Arguments:
  93. DeviceObject is the device whose data block is being queried
  94. Irp is the Irp that makes this request
  95. GuidIndex is the index into the list of guids provided when the
  96. device registered
  97. InstanceIndex is the index that denotes which instance of the data block
  98. is being queried.
  99. InstanceCount is the number of instnaces expected to be returned for
  100. the data block.
  101. InstanceLengthArray is a pointer to an array of ULONG that returns the
  102. lengths of each instance of the data block. If this is NULL then
  103. there was not enough space in the output buffer to fufill the request
  104. so the irp should be completed with the buffer needed.
  105. BufferAvail on entry has the maximum size available to write the data
  106. blocks.
  107. Buffer on return is filled with the returned data blocks. Note that each
  108. instance of the data block must be aligned on a 8 byte boundry. If
  109. this is NULL then there was not enough space in the output buffer
  110. to fufill the request so the irp should be completed with the buffer
  111. needed.
  112. Return Value:
  113. status
  114. --*/
  115. typedef
  116. NTSTATUS
  117. (*PWMI_SET_DATABLOCK) (
  118. IN PDEVICE_OBJECT DeviceObject,
  119. IN PIRP Irp,
  120. IN ULONG GuidIndex,
  121. IN ULONG InstanceIndex,
  122. IN ULONG BufferSize,
  123. IN PUCHAR Buffer
  124. );
  125. /*++
  126. Routine Description:
  127. This routine is a callback into the driver to query for the contents of
  128. a data block. When the driver has finished filling the data block it
  129. must call WmiCompleteRequest to complete the irp. The driver can
  130. return STATUS_PENDING if the irp cannot be completed immediately.
  131. Implementations of this routine may be in paged memory
  132. Arguments:
  133. DeviceObject is the device whose data block is being queried
  134. Irp is the Irp that makes this request
  135. GuidIndex is the index into the list of guids provided when the
  136. device registered
  137. InstanceIndex is the index that denotes which instance of the data block
  138. is being set.
  139. BufferSize has the size of the data block passed
  140. Buffer has the new values for the data block
  141. Return Value:
  142. status
  143. --*/
  144. typedef
  145. NTSTATUS
  146. (*PWMI_SET_DATAITEM) (
  147. IN PDEVICE_OBJECT DeviceObject,
  148. IN PIRP Irp,
  149. IN ULONG GuidIndex,
  150. IN ULONG InstanceIndex,
  151. IN ULONG DataItemId,
  152. IN ULONG BufferSize,
  153. IN PUCHAR Buffer
  154. );
  155. /*++
  156. Routine Description:
  157. This routine is a callback into the driver to query for the contents of
  158. a data block. When the driver has finished filling the data block it
  159. must call WmiCompleteRequest to complete the irp. The driver can
  160. return STATUS_PENDING if the irp cannot be completed immediately.
  161. Implementations of this routine may be in paged memory
  162. Arguments:
  163. DeviceObject is the device whose data block is being queried
  164. Irp is the Irp that makes this request
  165. GuidIndex is the index into the list of guids provided when the
  166. device registered
  167. InstanceIndex is the index that denotes which instance of the data block
  168. is being set.
  169. DataItemId has the id of the data item being set
  170. BufferSize has the size of the data item passed
  171. Buffer has the new values for the data item
  172. Return Value:
  173. status
  174. --*/
  175. typedef
  176. NTSTATUS
  177. (*PWMI_EXECUTE_METHOD) (
  178. IN PDEVICE_OBJECT DeviceObject,
  179. IN PIRP Irp,
  180. IN ULONG GuidIndex,
  181. IN ULONG InstanceIndex,
  182. IN ULONG MethodId,
  183. IN ULONG InBufferSize,
  184. IN ULONG OutBufferSize,
  185. IN OUT PUCHAR Buffer
  186. );
  187. /*++
  188. Routine Description:
  189. This routine is a callback into the driver to execute a method. When the
  190. driver has finished filling the data block it must call
  191. WmiCompleteRequest to complete the irp. The driver can
  192. return STATUS_PENDING if the irp cannot be completed immediately.
  193. Implementations of this routine may be in paged memory
  194. Arguments:
  195. DeviceObject is the device whose data block is being queried
  196. Irp is the Irp that makes this request
  197. GuidIndex is the index into the list of guids provided when the
  198. device registered
  199. InstanceIndex is the index that denotes which instance of the data block
  200. is being called.
  201. MethodId has the id of the method being called
  202. InBufferSize has the size of the data block passed in as the input to
  203. the method.
  204. OutBufferSize on entry has the maximum size available to write the
  205. returned data block.
  206. Buffer on entry has the input data block and on return has the output
  207. output data block.
  208. Return Value:
  209. status
  210. --*/
  211. typedef enum
  212. {
  213. WmiEventControl, // Enable or disable an event
  214. WmiDataBlockControl // Enable or disable data block collection
  215. } WMIENABLEDISABLECONTROL;
  216. typedef
  217. NTSTATUS
  218. (*PWMI_FUNCTION_CONTROL) (
  219. IN PDEVICE_OBJECT DeviceObject,
  220. IN PIRP Irp,
  221. IN ULONG GuidIndex,
  222. IN WMIENABLEDISABLECONTROL Function,
  223. IN BOOLEAN Enable
  224. );
  225. /*++
  226. Routine Description:
  227. This routine is a callback into the driver to enabled or disable event
  228. generation or data block collection. A device should only expect a
  229. single enable when the first event or data consumer enables events or
  230. data collection and a single disable when the last event or data
  231. consumer disables events or data collection. Data blocks will only
  232. receive collection enable/disable if they were registered as requiring
  233. it.
  234. Implementations of this routine may be in paged memory
  235. Arguments:
  236. DeviceObject is the device whose data block is being queried
  237. GuidIndex is the index into the list of guids provided when the
  238. device registered
  239. Function specifies which functionality is being enabled or disabled
  240. Enable is TRUE then the function is being enabled else disabled
  241. Return Value:
  242. status
  243. --*/
  244. //
  245. // This structure supplies context information for WMILIB to process the
  246. // WMI irps. Memory for this structure may be paged.
  247. typedef struct _WMILIB_CONTEXT
  248. {
  249. //
  250. // WMI data block guid registration info
  251. ULONG GuidCount;
  252. PWMIGUIDREGINFO GuidList;
  253. //
  254. // WMI functionality callbacks
  255. PWMI_QUERY_REGINFO QueryWmiRegInfo;
  256. PWMI_QUERY_DATABLOCK QueryWmiDataBlock;
  257. PWMI_SET_DATABLOCK SetWmiDataBlock;
  258. PWMI_SET_DATAITEM SetWmiDataItem;
  259. PWMI_EXECUTE_METHOD ExecuteWmiMethod;
  260. PWMI_FUNCTION_CONTROL WmiFunctionControl;
  261. } WMILIB_CONTEXT, *PWMILIB_CONTEXT;
  262. NTSTATUS
  263. WmiCompleteRequest(
  264. IN PDEVICE_OBJECT DeviceObject,
  265. IN PIRP Irp,
  266. IN NTSTATUS Status,
  267. IN ULONG BufferUsed,
  268. IN CCHAR PriorityBoost
  269. );
  270. /*++
  271. Routine Description:
  272. This routine will do the work of completing a WMI irp. Depending upon the
  273. the WMI request this routine will fixup the returned WNODE appropriately.
  274. This may be called at DPC level
  275. Arguments:
  276. DeviceObject - Supplies a pointer to the device object for this request.
  277. Irp - Supplies the Irp making the request.
  278. Status has the return status code for the IRP
  279. BufferUsed has the number of bytes needed by the device to return the
  280. data requested in any query. In the case that the buffer passed to
  281. the device is too small this has the number of bytes needed for the
  282. return data. If the buffer passed is large enough then this has the
  283. number of bytes actually used by the device.
  284. PriorityBoost is the value used for the IoCompleteRequest call.
  285. Return Value:
  286. status
  287. --*/
  288. typedef enum
  289. {
  290. IrpProcessed, // Irp was processed and possibly completed
  291. IrpNotCompleted, // Irp was process and NOT completed
  292. IrpNotWmi, // Irp is not a WMI irp
  293. IrpForward // Irp is wmi irp, but targeted at another device object
  294. } SYSCTL_IRP_DISPOSITION, *PSYSCTL_IRP_DISPOSITION;
  295. NTSTATUS
  296. WmiSystemControl(
  297. IN PWMILIB_CONTEXT WmiLibInfo,
  298. IN PDEVICE_OBJECT DeviceObject,
  299. IN PIRP Irp,
  300. OUT PSYSCTL_IRP_DISPOSITION IrpDisposition
  301. );
  302. /*++
  303. Routine Description:
  304. Dispatch helper routine for IRP_MJ_SYSTEM_CONTROL. This routine will
  305. determine if the irp passed contains a WMI request and if so process it
  306. by invoking the appropriate callback in the WMILIB structure.
  307. This routine may only be called at passive level
  308. Arguments:
  309. WmiLibInfo has the WMI information control block
  310. DeviceObject - Supplies a pointer to the device object for this request.
  311. Irp - Supplies the Irp making the request.
  312. IrpDisposition - Returns a value that specifies how the irp was handled.
  313. Return Value:
  314. status
  315. --*/
  316. NTSTATUS
  317. WmiFireEvent(
  318. IN PDEVICE_OBJECT DeviceObject,
  319. IN LPGUID Guid,
  320. IN ULONG InstanceIndex,
  321. IN ULONG EventDataSize,
  322. IN PVOID EventData
  323. );
  324. /*++
  325. Routine Description:
  326. This routine will fire a WMI event using the data buffer passed. This
  327. routine may be called at or below DPC level
  328. Arguments:
  329. DeviceObject - Supplies a pointer to the device object for this event
  330. Guid is pointer to the GUID that represents the event
  331. InstanceIndex is the index of the instance of the event
  332. EventDataSize is the number of bytes of data that is being fired with
  333. with the event
  334. EventData is the data that is fired with the events. This may be NULL
  335. if there is no data associated with the event
  336. Return Value:
  337. status
  338. --*/
  339. #ifdef __cplusplus
  340. }
  341. #endif
  342. #endif