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.

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