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.

421 lines
11 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. WMI.C
  5. Abstract:
  6. This module contains the init code for the i8042 to hid converter.
  7. Environment:
  8. Kernel mode
  9. Revision History:
  10. Jan-98 : created by Kenneth D. Ray
  11. --*/
  12. #include "mouhid.h"
  13. #include <wmistr.h>
  14. #ifdef ALLOC_PRAGMA
  15. #pragma alloc_text(PAGE,MouHid_SystemControl)
  16. #pragma alloc_text(PAGE,MouHid_SetWmiDataItem)
  17. #pragma alloc_text(PAGE,MouHid_SetWmiDataBlock)
  18. #pragma alloc_text(PAGE,MouHid_QueryWmiDataBlock)
  19. #pragma alloc_text(PAGE,MouHid_QueryWmiRegInfo)
  20. #endif
  21. #define WMI_PORT_DRIVER_INFORMATION 0
  22. GUID MouHid_PointerPortGuid = POINTER_PORT_WMI_STD_DATA_GUID;
  23. WMIGUIDREGINFO MouHid_WmiGuidList[1] =
  24. {
  25. {
  26. &MouHid_PointerPortGuid, 1, 0 // Pointer Port driver information
  27. }
  28. };
  29. NTSTATUS
  30. MouHid_SystemControl (
  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
  38. call into the WMI system library and let 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. MouHid_SetWmiDataItem(
  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 set for the contents of
  103. a data block. When the driver has finished filling the data block it
  104. must call ClassWmiCompleteRequest to complete the irp. The driver can
  105. return STATUS_PENDING if the irp cannot be completed immediately.
  106. Arguments:
  107. DeviceObject is the device whose data block is being queried
  108. Irp is the Irp that makes this request
  109. GuidIndex is the index into the list of guids provided when the
  110. device registered
  111. InstanceIndex is the index that denotes which instance of the data block
  112. is being queried.
  113. DataItemId has the id of the data item being set
  114. BufferSize has the size of the data item passed
  115. Buffer has the new values for the data item
  116. Return Value:
  117. status
  118. --*/
  119. {
  120. PDEVICE_EXTENSION deviceExtension;
  121. NTSTATUS status;
  122. deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  123. switch(GuidIndex) {
  124. case WMI_PORT_DRIVER_INFORMATION:
  125. status = STATUS_WMI_READ_ONLY;
  126. break;
  127. default:
  128. status = STATUS_WMI_GUID_NOT_FOUND;
  129. }
  130. status = WmiCompleteRequest( DeviceObject,
  131. Irp,
  132. status,
  133. 0,
  134. IO_NO_INCREMENT);
  135. return status;
  136. }
  137. NTSTATUS
  138. MouHid_SetWmiDataBlock(
  139. IN PDEVICE_OBJECT DeviceObject,
  140. IN PIRP Irp,
  141. IN ULONG GuidIndex,
  142. IN ULONG InstanceIndex,
  143. IN ULONG BufferSize,
  144. IN PUCHAR Buffer
  145. )
  146. /*++
  147. Routine Description:
  148. This routine is a callback into the driver to set the contents of
  149. a data block. When the driver has finished filling the data block it
  150. must call ClassWmiCompleteRequest to complete the irp. The driver can
  151. return STATUS_PENDING if the irp cannot be completed immediately.
  152. Arguments:
  153. DeviceObject is the device whose data block is being queried
  154. Irp is the Irp that makes this request
  155. GuidIndex is the index into the list of guids provided when the
  156. device registered
  157. InstanceIndex is the index that denotes which instance of the data block
  158. is being queried.
  159. BufferSize has the size of the data block passed
  160. Buffer has the new values for the data block
  161. Return Value:
  162. status
  163. --*/
  164. {
  165. PDEVICE_EXTENSION deviceExtension;
  166. NTSTATUS status;
  167. deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  168. switch(GuidIndex) {
  169. case WMI_PORT_DRIVER_INFORMATION:
  170. status = STATUS_WMI_READ_ONLY;
  171. break;
  172. default:
  173. status = STATUS_WMI_GUID_NOT_FOUND;
  174. }
  175. status = WmiCompleteRequest( DeviceObject,
  176. Irp,
  177. status,
  178. 0,
  179. IO_NO_INCREMENT);
  180. return(status);
  181. }
  182. NTSTATUS
  183. MouHid_QueryWmiDataBlock(
  184. IN PDEVICE_OBJECT DeviceObject,
  185. IN PIRP Irp,
  186. IN ULONG GuidIndex,
  187. IN ULONG InstanceIndex,
  188. IN ULONG InstanceCount,
  189. IN OUT PULONG InstanceLengthArray,
  190. IN ULONG OutBufferSize,
  191. OUT PUCHAR Buffer
  192. )
  193. /*++
  194. Routine Description:
  195. This routine is a callback into the driver to query for the contents of
  196. a data block. When the driver has finished filling the data block it
  197. must call ClassWmiCompleteRequest to complete the irp. The driver can
  198. return STATUS_PENDING if the irp cannot be completed immediately.
  199. Arguments:
  200. DeviceObject is the device whose data block is being queried
  201. Irp is the Irp that makes this request
  202. GuidIndex is the index into the list of guids provided when the
  203. device registered
  204. InstanceIndex is the index that denotes which instance of the data block
  205. is being queried.
  206. InstanceCount is the number of instnaces expected to be returned for
  207. the data block.
  208. InstanceLengthArray is a pointer to an array of ULONG that returns the
  209. lengths of each instance of the data block. If this is NULL then
  210. there was not enough space in the output buffer to fufill the request
  211. so the irp should be completed with the buffer needed.
  212. BufferAvail on has the maximum size available to write the data
  213. block.
  214. Buffer on return is filled with the returned data block
  215. Return Value:
  216. status
  217. --*/
  218. {
  219. PDEVICE_EXTENSION deviceExtension;
  220. POINTER_PORT_WMI_STD_DATA data;
  221. NTSTATUS status;
  222. ULONG size = 0;
  223. //
  224. // Only ever registers 1 instance per guid
  225. ASSERT((InstanceIndex == 0) &&
  226. (InstanceCount == 1));
  227. deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  228. switch (GuidIndex) {
  229. case WMI_PORT_DRIVER_INFORMATION:
  230. size = sizeof (data);
  231. if (OutBufferSize < size) {
  232. status = STATUS_BUFFER_TOO_SMALL;
  233. break;
  234. }
  235. RtlZeroMemory(&data,
  236. size
  237. );
  238. data.ConnectorType = POINTER_PORT_WMI_STD_USB;
  239. data.DataQueueSize = deviceExtension->Attributes.InputDataQueueLength;
  240. data.ErrorCount = 0;
  241. data.Buttons = deviceExtension->Attributes.NumberOfButtons;
  242. * (PPOINTER_PORT_WMI_STD_DATA) Buffer = data;
  243. *InstanceLengthArray = size;
  244. status = STATUS_SUCCESS;
  245. break;
  246. default:
  247. status = STATUS_WMI_GUID_NOT_FOUND;
  248. }
  249. status = WmiCompleteRequest( DeviceObject,
  250. Irp,
  251. status,
  252. size,
  253. IO_NO_INCREMENT);
  254. return status;
  255. }
  256. NTSTATUS
  257. MouHid_QueryWmiRegInfo(
  258. IN PDEVICE_OBJECT DeviceObject,
  259. OUT ULONG *RegFlags,
  260. OUT PUNICODE_STRING InstanceName,
  261. OUT PUNICODE_STRING *RegistryPath,
  262. OUT PUNICODE_STRING MofResourceName,
  263. OUT PDEVICE_OBJECT *Pdo
  264. )
  265. /*++
  266. Routine Description:
  267. This routine is a callback into the driver to retrieve the list of
  268. guids or data blocks that the driver wants to register with WMI. This
  269. routine may not pend or block. Driver should NOT call
  270. ClassWmiCompleteRequest.
  271. Arguments:
  272. DeviceObject is the device whose data block is being queried
  273. *RegFlags returns with a set of flags that describe the guids being
  274. registered for this device. If the device wants enable and disable
  275. collection callbacks before receiving queries for the registered
  276. guids then it should return the WMIREG_FLAG_EXPENSIVE flag. Also the
  277. returned flags may specify WMIREG_FLAG_INSTANCE_PDO in which case
  278. the instance name is determined from the PDO associated with the
  279. device object. Note that the PDO must have an associated devnode. If
  280. WMIREG_FLAG_INSTANCE_PDO is not set then Name must return a unique
  281. name for the device.
  282. InstanceName returns with the instance name for the guids if
  283. WMIREG_FLAG_INSTANCE_PDO is not set in the returned *RegFlags. The
  284. caller will call ExFreePool with the buffer returned.
  285. *RegistryPath returns with the registry path of the driver
  286. *MofResourceName returns with the name of the MOF resource attached to
  287. the binary file. If the driver does not have a mof resource attached
  288. then this can be returned as NULL.
  289. *Pdo returns with the device object for the PDO associated with this
  290. device if the WMIREG_FLAG_INSTANCE_PDO flag is retured in
  291. *RegFlags.
  292. Return Value:
  293. status
  294. --*/
  295. {
  296. PDEVICE_EXTENSION deviceExtension;
  297. deviceExtension = DeviceObject->DeviceExtension;
  298. *RegFlags = WMIREG_FLAG_INSTANCE_PDO;
  299. *RegistryPath = &Globals.RegistryPath;
  300. *Pdo = deviceExtension->PDO;
  301. return STATUS_SUCCESS;
  302. }