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.

433 lines
12 KiB

  1. /*++
  2. Copyright (c) 1997, 98 Microsoft Corporation
  3. Module Name:
  4. wmi.c
  5. Abstract:
  6. This module contains the code that handles the wmi IRPs for the
  7. inport driver.
  8. Author:
  9. Initial writing, Doron J. Holan, 09-Feb-1998
  10. Environment:
  11. Kernel mode
  12. Revision History :
  13. --*/
  14. #include "inport.h"
  15. #include <wmistr.h>
  16. #ifdef ALLOC_PRAGMA
  17. #pragma alloc_text(PAGE, InportSystemControl)
  18. #pragma alloc_text(PAGE, InportSetWmiDataItem)
  19. #pragma alloc_text(PAGE, InportSetWmiDataBlock)
  20. #pragma alloc_text(PAGE, InportQueryWmiDataBlock)
  21. #pragma alloc_text(PAGE, InportQueryWmiRegInfo)
  22. #endif
  23. #define WMI_MOUSE_PORT_INFORMATION 0
  24. GUID Inport_PointerPortGuid = POINTER_PORT_WMI_STD_DATA_GUID;
  25. WMIGUIDREGINFO WmiGuidList[1] =
  26. {
  27. { &Inport_PointerPortGuid, 1, 0 } // Pointer Port driver information
  28. };
  29. NTSTATUS
  30. InportSystemControl(
  31. IN PDEVICE_OBJECT DeviceObject,
  32. IN PIRP Irp
  33. )
  34. /*++
  35. Routine Description
  36. We have just received a System Control IRP.
  37. Assume that this is a WMI IRP and call into the WMI system library and let
  38. it handle this IRP for us.
  39. --*/
  40. {
  41. PDEVICE_EXTENSION deviceExtension;
  42. SYSCTL_IRP_DISPOSITION disposition;
  43. NTSTATUS status;
  44. deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  45. status = WmiSystemControl(&deviceExtension->WmiLibInfo,
  46. DeviceObject,
  47. Irp,
  48. &disposition);
  49. switch(disposition)
  50. {
  51. case IrpProcessed:
  52. {
  53. //
  54. // This irp has been processed and may be completed or pending.
  55. break;
  56. }
  57. case IrpNotCompleted:
  58. {
  59. //
  60. // This irp has not been completed, but has been fully processed.
  61. // we will complete it now
  62. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  63. break;
  64. }
  65. case IrpForward:
  66. case IrpNotWmi:
  67. {
  68. //
  69. // This irp is either not a WMI irp or is a WMI irp targetted
  70. // at a device lower in the stack.
  71. IoSkipCurrentIrpStackLocation (Irp);
  72. status = IoCallDriver (deviceExtension->TopOfStack, Irp);
  73. break;
  74. }
  75. default:
  76. {
  77. //
  78. // We really should never get here, but if we do just forward....
  79. ASSERT(FALSE);
  80. IoSkipCurrentIrpStackLocation (Irp);
  81. status = IoCallDriver (deviceExtension->TopOfStack, Irp);
  82. break;
  83. }
  84. }
  85. return(status);
  86. }
  87. //
  88. // WMI System Call back functions
  89. //
  90. NTSTATUS
  91. InportSetWmiDataItem(
  92. IN PDEVICE_OBJECT DeviceObject,
  93. IN PIRP Irp,
  94. IN ULONG GuidIndex,
  95. IN ULONG InstanceIndex,
  96. IN ULONG DataItemId,
  97. IN ULONG BufferSize,
  98. IN PUCHAR Buffer
  99. )
  100. /*++
  101. Routine Description:
  102. This routine is a callback into the driver to query for the contents of
  103. a data block. When the driver has finished filling the data block it
  104. must call WmiCompleteRequest to complete the irp. The driver can
  105. return STATUS_PENDING if the irp cannot be completed immediately.
  106. Implementations of this routine may be in paged memory
  107. Arguments:
  108. DeviceObject is the device whose data block is being queried
  109. Irp is the Irp that makes this request
  110. GuidIndex is the index into the list of guids provided when the
  111. device registered
  112. InstanceIndex is the index that denotes which instance of the data block
  113. is being set.
  114. DataItemId has the id of the data item being set
  115. BufferSize has the size of the data item passed
  116. Buffer has the new values for the data item
  117. Return Value:
  118. status
  119. --*/
  120. {
  121. PDEVICE_EXTENSION deviceExtension;
  122. NTSTATUS status;
  123. deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  124. switch(GuidIndex) {
  125. case WMI_MOUSE_PORT_INFORMATION:
  126. status = STATUS_WMI_READ_ONLY;
  127. break;
  128. default:
  129. status = STATUS_WMI_GUID_NOT_FOUND;
  130. break;
  131. }
  132. status = WmiCompleteRequest(DeviceObject,
  133. Irp,
  134. status,
  135. 0,
  136. IO_NO_INCREMENT
  137. );
  138. return status;
  139. }
  140. NTSTATUS
  141. InportSetWmiDataBlock(
  142. IN PDEVICE_OBJECT DeviceObject,
  143. IN PIRP Irp,
  144. IN ULONG GuidIndex,
  145. IN ULONG InstanceIndex,
  146. IN ULONG BufferSize,
  147. IN PUCHAR Buffer
  148. )
  149. /*++
  150. Routine Description:
  151. This routine is a callback into the driver to query for the contents of
  152. a data block. When the driver has finished filling the data block it
  153. must call WmiCompleteRequest to complete the irp. The driver can
  154. return STATUS_PENDING if the irp cannot be completed immediately.
  155. Implementations of this routine may be in paged memory
  156. Arguments:
  157. DeviceObject is the device whose data block is being queried
  158. Irp is the Irp that makes this request
  159. GuidIndex is the index into the list of guids provided when the
  160. device registered
  161. InstanceIndex is the index that denotes which instance of the data block
  162. is being set.
  163. BufferSize has the size of the data block passed
  164. Buffer has the new values for the data block
  165. Return Value:
  166. status
  167. --*/
  168. {
  169. PDEVICE_EXTENSION deviceExtension;
  170. NTSTATUS status;
  171. deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  172. switch (GuidIndex) {
  173. case WMI_MOUSE_PORT_INFORMATION:
  174. status = STATUS_WMI_READ_ONLY;
  175. break;
  176. default:
  177. status = STATUS_WMI_GUID_NOT_FOUND;
  178. }
  179. status = WmiCompleteRequest(DeviceObject,
  180. Irp,
  181. status,
  182. 0,
  183. IO_NO_INCREMENT
  184. );
  185. return status;
  186. }
  187. NTSTATUS
  188. InportQueryWmiDataBlock(
  189. IN PDEVICE_OBJECT DeviceObject,
  190. IN PIRP Irp,
  191. IN ULONG GuidIndex,
  192. IN ULONG InstanceIndex,
  193. IN ULONG InstanceCount,
  194. IN OUT PULONG InstanceLengthArray,
  195. IN ULONG BufferAvail,
  196. OUT PUCHAR Buffer
  197. )
  198. /*++
  199. Routine Description:
  200. This routine is a callback into the driver to query for the contents of
  201. one or more instances of a data block. When the driver has finished
  202. filling the
  203. data block it must call WmiCompleteRequest to complete the irp. The
  204. driver can return STATUS_PENDING if the irp cannot be completed
  205. immediately.
  206. Implementations of this routine may be in paged memory
  207. Arguments:
  208. DeviceObject is the device whose data block is being queried
  209. Irp is the Irp that makes this request
  210. GuidIndex is the index into the list of guids provided when the
  211. device registered
  212. InstanceIndex is the index that denotes which instance of the data block
  213. is being queried.
  214. InstanceCount is the number of instnaces expected to be returned for
  215. the data block.
  216. InstanceLengthArray is a pointer to an array of ULONG that returns the
  217. lengths of each instance of the data block. If this is NULL then
  218. there was not enough space in the output buffer to fufill the request
  219. so the irp should be completed with the buffer needed.
  220. BufferAvail on entry has the maximum size available to write the data
  221. blocks.
  222. Buffer on return is filled with the returned data blocks. Note that each
  223. instance of the data block must be aligned on a 8 byte boundry. If
  224. this is NULL then there was not enough space in the output buffer
  225. to fufill the request so the irp should be completed with the buffer
  226. needed.
  227. Return Value:
  228. status
  229. --*/
  230. {
  231. NTSTATUS status;
  232. ULONG size = sizeof(POINTER_PORT_WMI_STD_DATA);
  233. POINTER_PORT_WMI_STD_DATA mouData;
  234. PDEVICE_EXTENSION deviceExtension;
  235. PMOUSE_ATTRIBUTES attributes;
  236. deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  237. switch (GuidIndex) {
  238. case WMI_MOUSE_PORT_INFORMATION:
  239. attributes = &deviceExtension->Configuration.MouseAttributes;
  240. if (BufferAvail < size) {
  241. status = STATUS_BUFFER_TOO_SMALL;
  242. break;
  243. }
  244. *InstanceLengthArray = size;
  245. RtlZeroMemory(&mouData,
  246. size
  247. );
  248. mouData.ConnectorType = POINTER_PORT_WMI_STD_I8042;
  249. mouData.DataQueueSize = attributes->InputDataQueueLength /
  250. sizeof(MOUSE_INPUT_DATA);
  251. mouData.Buttons = attributes->NumberOfButtons;
  252. mouData.ErrorCount = 0;
  253. mouData.HardwareType = POINTER_PORT_WMI_STD_MOUSE;
  254. *(PPOINTER_PORT_WMI_STD_DATA) Buffer = mouData;
  255. status = STATUS_SUCCESS;
  256. break;
  257. default:
  258. status = STATUS_WMI_GUID_NOT_FOUND;
  259. break;
  260. }
  261. status = WmiCompleteRequest(DeviceObject,
  262. Irp,
  263. status,
  264. size,
  265. IO_NO_INCREMENT
  266. );
  267. return status;
  268. }
  269. NTSTATUS
  270. InportQueryWmiRegInfo(
  271. IN PDEVICE_OBJECT DeviceObject,
  272. OUT PULONG RegFlags,
  273. OUT PUNICODE_STRING InstanceName,
  274. OUT PUNICODE_STRING *RegistryPath,
  275. OUT PUNICODE_STRING MofResourceName,
  276. OUT PDEVICE_OBJECT *Pdo
  277. )
  278. /*++
  279. Routine Description:
  280. This routine is a callback into the driver to retrieve information about
  281. the guids being registered.
  282. Implementations of this routine may be in paged memory
  283. Arguments:
  284. DeviceObject is the device whose registration information is needed
  285. *RegFlags returns with a set of flags that describe all of the guids being
  286. registered for this device. If the device wants enable and disable
  287. collection callbacks before receiving queries for the registered
  288. guids then it should return the WMIREG_FLAG_EXPENSIVE flag. Also the
  289. returned flags may specify WMIREG_FLAG_INSTANCE_PDO in which case
  290. the instance name is determined from the PDO associated with the
  291. device object. Note that the PDO must have an associated devnode. If
  292. WMIREG_FLAG_INSTANCE_PDO is not set then Name must return a unique
  293. name for the device. These flags are ORed into the flags specified
  294. by the GUIDREGINFO for each guid.
  295. InstanceName returns with the instance name for the guids if
  296. WMIREG_FLAG_INSTANCE_PDO is not set in the returned *RegFlags. The
  297. caller will call ExFreePool with the buffer returned.
  298. *RegistryPath returns with the registry path of the driver. This is
  299. required
  300. *MofResourceName returns with the name of the MOF resource attached to
  301. the binary file. If the driver does not have a mof resource attached
  302. then this can be returned as NULL.
  303. *Pdo returns with the device object for the PDO associated with this
  304. device if the WMIREG_FLAG_INSTANCE_PDO flag is retured in
  305. *RegFlags.
  306. Return Value:
  307. status
  308. --*/
  309. {
  310. PDEVICE_EXTENSION deviceExtension;
  311. deviceExtension = DeviceObject->DeviceExtension;
  312. *RegFlags = WMIREG_FLAG_INSTANCE_PDO;
  313. *RegistryPath = &Globals.RegistryPath;
  314. *Pdo = deviceExtension->PDO;
  315. return STATUS_SUCCESS;
  316. }