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.

583 lines
15 KiB

  1. /*++
  2. Copyright (c) 1990-1999 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. RDP remote port driver.
  8. Environment:
  9. Kernel mode
  10. Revision History :
  11. 02/12/99 - Initial Revision based on pnpi8042 driver
  12. --*/
  13. #include <precomp.h>
  14. #pragma hdrstop
  15. #include <wmistr.h>
  16. #include "ptdrvcom.h"
  17. #ifdef ALLOC_PRAGMA
  18. #pragma alloc_text(PAGE, PtInitWmi)
  19. #pragma alloc_text(PAGE, PtSystemControl)
  20. #pragma alloc_text(PAGE, PtSetWmiDataItem)
  21. #pragma alloc_text(PAGE, PtSetWmiDataBlock)
  22. #pragma alloc_text(PAGE, PtKeyboardQueryWmiDataBlock)
  23. #pragma alloc_text(PAGE, PtMouseQueryWmiDataBlock)
  24. #pragma alloc_text(PAGE, PtQueryWmiRegInfo)
  25. #endif
  26. #define WMI_KEYBOARD_PORT_INFORMATION 0
  27. #define WMI_MOUSE_PORT_INFORMATION 0
  28. GUID KbKeyboardPortGuid = KEYBOARD_PORT_WMI_STD_DATA_GUID;
  29. WMIGUIDREGINFO KbWmiGuidList[1] =
  30. {
  31. { &KbKeyboardPortGuid, 1, 0 } // Keyboard Port driver information
  32. };
  33. GUID MouPointerPortGuid = POINTER_PORT_WMI_STD_DATA_GUID;
  34. WMIGUIDREGINFO MouWmiGuidList[1] =
  35. {
  36. { &MouPointerPortGuid, 1, 0 } // Pointer Port driver information
  37. };
  38. NTSTATUS
  39. PtInitWmi(
  40. PCOMMON_DATA CommonData
  41. )
  42. /*++
  43. Routine Description:
  44. Initializes the WmiLibInfo data structure for the device represented by
  45. CommonData
  46. Arguments:
  47. CommonData - the device
  48. Return Value:
  49. status from IoWMIRegistrationControl
  50. --*/
  51. {
  52. PAGED_CODE();
  53. if (CommonData->IsKeyboard) {
  54. CommonData->WmiLibInfo.GuidCount = sizeof(KbWmiGuidList) /
  55. sizeof(WMIGUIDREGINFO);
  56. CommonData->WmiLibInfo.GuidList = KbWmiGuidList;
  57. CommonData->WmiLibInfo.QueryWmiDataBlock = PtKeyboardQueryWmiDataBlock;
  58. }
  59. else {
  60. CommonData->WmiLibInfo.GuidCount = sizeof(MouWmiGuidList) /
  61. sizeof(WMIGUIDREGINFO);
  62. CommonData->WmiLibInfo.GuidList = MouWmiGuidList;
  63. CommonData->WmiLibInfo.QueryWmiDataBlock = PtMouseQueryWmiDataBlock;
  64. }
  65. CommonData->WmiLibInfo.QueryWmiRegInfo = PtQueryWmiRegInfo;
  66. CommonData->WmiLibInfo.SetWmiDataBlock = PtSetWmiDataBlock;
  67. CommonData->WmiLibInfo.SetWmiDataItem = PtSetWmiDataItem;
  68. CommonData->WmiLibInfo.ExecuteWmiMethod = NULL;
  69. CommonData->WmiLibInfo.WmiFunctionControl = NULL;
  70. return IoWMIRegistrationControl(CommonData->Self,
  71. WMIREG_ACTION_REGISTER
  72. );
  73. }
  74. NTSTATUS
  75. PtSystemControl(
  76. IN PDEVICE_OBJECT DeviceObject,
  77. IN PIRP Irp
  78. )
  79. /*++
  80. Routine Description
  81. We have just received a System Control IRP.
  82. Assume that this is a WMI IRP and call into the WMI system library and let
  83. it handle this IRP for us.
  84. --*/
  85. {
  86. PCOMMON_DATA commonData;
  87. SYSCTL_IRP_DISPOSITION disposition;
  88. NTSTATUS status;
  89. PAGED_CODE();
  90. commonData = (PCOMMON_DATA) DeviceObject->DeviceExtension;
  91. status = WmiSystemControl(&commonData->WmiLibInfo,
  92. DeviceObject,
  93. Irp,
  94. &disposition
  95. );
  96. switch(disposition) {
  97. case IrpProcessed:
  98. //
  99. // This irp has been processed and may be completed or pending.
  100. //
  101. break;
  102. case IrpNotCompleted:
  103. //
  104. // This irp has not been completed, but has been fully processed.
  105. // we will complete it now
  106. //
  107. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  108. break;
  109. case IrpForward:
  110. case IrpNotWmi:
  111. //
  112. // This irp is either not a WMI irp or is a WMI irp targetted
  113. // at a device lower in the stack.
  114. //
  115. IoSkipCurrentIrpStackLocation(Irp);
  116. status = IoCallDriver(commonData->TopOfStack, Irp);
  117. break;
  118. default:
  119. //
  120. // We really should never get here, but if we do just forward....
  121. //
  122. ASSERT(FALSE);
  123. IoSkipCurrentIrpStackLocation(Irp);
  124. status = IoCallDriver(commonData->TopOfStack, Irp);
  125. break;
  126. }
  127. return status;
  128. }
  129. //
  130. // WMI System Call back functions
  131. //
  132. NTSTATUS
  133. PtSetWmiDataItem(
  134. IN PDEVICE_OBJECT DeviceObject,
  135. IN PIRP Irp,
  136. IN ULONG GuidIndex,
  137. IN ULONG InstanceIndex,
  138. IN ULONG DataItemId,
  139. IN ULONG BufferSize,
  140. IN PUCHAR Buffer
  141. )
  142. /*++
  143. Routine Description:
  144. This routine is a callback into the driver to set for the contents of
  145. a data block. When the driver has finished filling the data block it
  146. must call ClassWmiCompleteRequest to complete the irp. The driver can
  147. return STATUS_PENDING if the irp cannot be completed immediately.
  148. Arguments:
  149. DeviceObject is the device whose data block is being queried
  150. Irp is the Irp that makes this request
  151. GuidIndex is the index into the list of guids provided when the
  152. device registered
  153. InstanceIndex is the index that denotes which instance of the data block
  154. is being queried.
  155. DataItemId has the id of the data item being set
  156. BufferSize has the size of the data item passed
  157. Buffer has the new values for the data item
  158. Return Value:
  159. status
  160. --*/
  161. {
  162. PCOMMON_DATA commonData;
  163. NTSTATUS status;
  164. PAGED_CODE();
  165. commonData = (PCOMMON_DATA) DeviceObject->DeviceExtension;
  166. switch(GuidIndex) {
  167. case WMI_KEYBOARD_PORT_INFORMATION:
  168. // case WMI_MOUSE_PORT_INFORMATION: // they are the same index
  169. status = STATUS_WMI_READ_ONLY;
  170. break;
  171. default:
  172. status = STATUS_WMI_GUID_NOT_FOUND;
  173. break;
  174. }
  175. return WmiCompleteRequest(DeviceObject,
  176. Irp,
  177. status,
  178. 0,
  179. IO_NO_INCREMENT
  180. );
  181. }
  182. NTSTATUS
  183. PtSetWmiDataBlock(
  184. IN PDEVICE_OBJECT DeviceObject,
  185. IN PIRP Irp,
  186. IN ULONG GuidIndex,
  187. IN ULONG InstanceIndex,
  188. IN ULONG BufferSize,
  189. IN PUCHAR Buffer
  190. )
  191. /*++
  192. Routine Description:
  193. This routine is a callback into the driver to set the contents of
  194. a data block. When the driver has finished filling the data block it
  195. must call ClassWmiCompleteRequest to complete the irp. The driver can
  196. return STATUS_PENDING if the irp cannot be completed immediately.
  197. Arguments:
  198. DeviceObject is the device whose data block is being queried
  199. Irp is the Irp that makes this request
  200. GuidIndex is the index into the list of guids provided when the
  201. device registered
  202. InstanceIndex is the index that denotes which instance of the data block
  203. is being queried.
  204. BufferSize has the size of the data block passed
  205. Buffer has the new values for the data block
  206. Return Value:
  207. status
  208. --*/
  209. {
  210. PCOMMON_DATA commonData;
  211. NTSTATUS status;
  212. PAGED_CODE();
  213. commonData = (PCOMMON_DATA) DeviceObject->DeviceExtension;
  214. switch (GuidIndex) {
  215. case WMI_KEYBOARD_PORT_INFORMATION:
  216. // case WMI_MOUSE_PORT_INFORMATION: // they are the same index
  217. status = STATUS_WMI_READ_ONLY;
  218. break;
  219. default:
  220. status = STATUS_WMI_GUID_NOT_FOUND;
  221. }
  222. return WmiCompleteRequest(DeviceObject,
  223. Irp,
  224. status,
  225. 0,
  226. IO_NO_INCREMENT
  227. );
  228. }
  229. NTSTATUS
  230. PtKeyboardQueryWmiDataBlock(
  231. IN PDEVICE_OBJECT DeviceObject,
  232. IN PIRP Irp,
  233. IN ULONG GuidIndex,
  234. IN ULONG InstanceIndex,
  235. IN ULONG InstanceCount,
  236. IN OUT PULONG InstanceLengthArray,
  237. IN ULONG OutBufferSize,
  238. OUT PUCHAR Buffer
  239. )
  240. /*++
  241. Routine Description:
  242. This routine is a callback into the driver to query for the contents of
  243. a data block. When the driver has finished filling the data block it
  244. must call ClassWmiCompleteRequest to complete the irp. The driver can
  245. return STATUS_PENDING if the irp cannot be completed immediately.
  246. Arguments:
  247. DeviceObject is the device whose data block is being queried
  248. Irp is the Irp that makes this request
  249. GuidIndex is the index into the list of guids provided when the
  250. device registered
  251. InstanceIndex is the index that denotes which instance of the data block
  252. is being queried.
  253. InstanceCount is the number of instnaces expected to be returned for
  254. the data block.
  255. InstanceLengthArray is a pointer to an array of ULONG that returns the
  256. lengths of each instance of the data block. If this is NULL then
  257. there was not enough space in the output buffer to fufill the request
  258. so the irp should be completed with the buffer needed.
  259. BufferAvail on has the maximum size available to write the data
  260. block.
  261. Buffer on return is filled with the returned data block
  262. Return Value:
  263. status
  264. --*/
  265. {
  266. NTSTATUS status;
  267. ULONG size = sizeof(KEYBOARD_PORT_WMI_STD_DATA);
  268. KEYBOARD_PORT_WMI_STD_DATA kbData;
  269. PAGED_CODE();
  270. ASSERT(InstanceIndex == 0 && InstanceCount == 1);
  271. switch (GuidIndex) {
  272. case WMI_KEYBOARD_PORT_INFORMATION:
  273. if (OutBufferSize < size) {
  274. status = STATUS_BUFFER_TOO_SMALL;
  275. break;
  276. }
  277. RtlZeroMemory(&kbData,
  278. size
  279. );
  280. kbData.ConnectorType = KEYBOARD_PORT_WMI_STD_I8042;
  281. kbData.DataQueueSize = 1;
  282. kbData.ErrorCount = 0;
  283. kbData.FunctionKeys = KEYBOARD_NUM_FUNCTION_KEYS;
  284. kbData.Indicators = KEYBOARD_NUM_INDICATORS;
  285. *(PKEYBOARD_PORT_WMI_STD_DATA) Buffer = kbData;
  286. *InstanceLengthArray = size;
  287. status = STATUS_SUCCESS;
  288. break;
  289. default:
  290. status = STATUS_WMI_GUID_NOT_FOUND;
  291. break;
  292. }
  293. return WmiCompleteRequest(DeviceObject,
  294. Irp,
  295. status,
  296. size,
  297. IO_NO_INCREMENT
  298. );
  299. }
  300. NTSTATUS
  301. PtMouseQueryWmiDataBlock(
  302. IN PDEVICE_OBJECT DeviceObject,
  303. IN PIRP Irp,
  304. IN ULONG GuidIndex,
  305. IN ULONG InstanceIndex,
  306. IN ULONG InstanceCount,
  307. IN OUT PULONG InstanceLengthArray,
  308. IN ULONG OutBufferSize,
  309. OUT PUCHAR Buffer
  310. )
  311. /*++
  312. Routine Description:
  313. This routine is a callback into the driver to query for the contents of
  314. a data block. When the driver has finished filling the data block it
  315. must call ClassWmiCompleteRequest to complete the irp. The driver can
  316. return STATUS_PENDING if the irp cannot be completed immediately.
  317. Arguments:
  318. DeviceObject is the device whose data block is being queried
  319. Irp is the Irp that makes this request
  320. GuidIndex is the index into the list of guids provided when the
  321. device registered
  322. InstanceIndex is the index that denotes which instance of the data block
  323. is being queried.
  324. InstanceCount is the number of instnaces expected to be returned for
  325. the data block.
  326. InstanceLengthArray is a pointer to an array of ULONG that returns the
  327. lengths of each instance of the data block. If this is NULL then
  328. there was not enough space in the output buffer to fufill the request
  329. so the irp should be completed with the buffer needed.
  330. BufferAvail on has the maximum size available to write the data
  331. block.
  332. Buffer on return is filled with the returned data block
  333. Return Value:
  334. status
  335. --*/
  336. {
  337. NTSTATUS status;
  338. ULONG size = sizeof(POINTER_PORT_WMI_STD_DATA);
  339. POINTER_PORT_WMI_STD_DATA mouData;
  340. PAGED_CODE();
  341. //
  342. // Only ever registers 1 instance per guid
  343. //
  344. ASSERT(InstanceIndex == 0 && InstanceCount == 1);
  345. switch (GuidIndex) {
  346. case WMI_MOUSE_PORT_INFORMATION:
  347. if (OutBufferSize < size) {
  348. status = STATUS_BUFFER_TOO_SMALL;
  349. break;
  350. }
  351. RtlZeroMemory(&mouData,
  352. size
  353. );
  354. mouData.ConnectorType = POINTER_PORT_WMI_STD_I8042;
  355. mouData.DataQueueSize = 0;
  356. //
  357. // We always claim to be a 3 button (wheel) mouse
  358. //
  359. mouData.Buttons = MOUSE_NUM_BUTTONS;
  360. mouData.ErrorCount = 0;
  361. mouData.HardwareType = POINTER_PORT_WMI_STD_MOUSE;
  362. *(PPOINTER_PORT_WMI_STD_DATA) Buffer = mouData;
  363. *InstanceLengthArray = size;
  364. status = STATUS_SUCCESS;
  365. break;
  366. default:
  367. status = STATUS_WMI_GUID_NOT_FOUND;
  368. break;
  369. }
  370. return WmiCompleteRequest(DeviceObject,
  371. Irp,
  372. status,
  373. size,
  374. IO_NO_INCREMENT
  375. );
  376. }
  377. NTSTATUS
  378. PtQueryWmiRegInfo(
  379. IN PDEVICE_OBJECT DeviceObject,
  380. OUT PULONG RegFlags,
  381. OUT PUNICODE_STRING InstanceName,
  382. OUT PUNICODE_STRING *RegistryPath,
  383. OUT PUNICODE_STRING MofResourceName,
  384. OUT PDEVICE_OBJECT *Pdo
  385. )
  386. /*++
  387. Routine Description:
  388. This routine is a callback into the driver to retrieve information about
  389. the guids being registered.
  390. Implementations of this routine may be in paged memory
  391. Arguments:
  392. DeviceObject is the device whose registration information is needed
  393. *RegFlags returns with a set of flags that describe all of the guids being
  394. registered for this device. If the device wants enable and disable
  395. collection callbacks before receiving queries for the registered
  396. guids then it should return the WMIREG_FLAG_EXPENSIVE flag. Also the
  397. returned flags may specify WMIREG_FLAG_INSTANCE_PDO in which case
  398. the instance name is determined from the PDO associated with the
  399. device object. Note that the PDO must have an associated devnode. If
  400. WMIREG_FLAG_INSTANCE_PDO is not set then Name must return a unique
  401. name for the device. These flags are ORed into the flags specified
  402. by the GUIDREGINFO for each guid.
  403. InstanceName returns with the instance name for the guids if
  404. WMIREG_FLAG_INSTANCE_PDO is not set in the returned *RegFlags. The
  405. caller will call ExFreePool with the buffer returned.
  406. *RegistryPath returns with the registry path of the driver. This is
  407. required
  408. *MofResourceName returns with the name of the MOF resource attached to
  409. the binary file. If the driver does not have a mof resource attached
  410. then this can be returned as NULL.
  411. *Pdo returns with the device object for the PDO associated with this
  412. device if the WMIREG_FLAG_INSTANCE_PDO flag is retured in
  413. *RegFlags.
  414. Return Value:
  415. status
  416. --*/
  417. {
  418. PCOMMON_DATA commonData;
  419. PAGED_CODE();
  420. commonData = (PCOMMON_DATA) DeviceObject->DeviceExtension;
  421. *RegFlags = WMIREG_FLAG_INSTANCE_PDO;
  422. *RegistryPath = &Globals.RegistryPath;
  423. *Pdo = commonData->PDO;
  424. return STATUS_SUCCESS;
  425. }