Leaked source code of windows server 2003
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.

409 lines
11 KiB

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