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.

608 lines
17 KiB

  1. /*++
  2. Copyright (c) 1990-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. i8042prt driver.
  8. Environment:
  9. Kernel mode
  10. Revision History :
  11. --*/
  12. #include <initguid.h>
  13. #include "i8042prt.h"
  14. #include <wmistr.h>
  15. #ifdef ALLOC_PRAGMA
  16. #pragma alloc_text(PAGE, I8xInitWmi)
  17. #pragma alloc_text(PAGE, I8xSystemControl)
  18. #pragma alloc_text(PAGE, I8xSetWmiDataItem)
  19. #pragma alloc_text(PAGE, I8xSetWmiDataBlock)
  20. #pragma alloc_text(PAGE, I8xKeyboardQueryWmiDataBlock)
  21. #pragma alloc_text(PAGE, I8xMouseQueryWmiDataBlock)
  22. #pragma alloc_text(PAGE, I8xQueryWmiRegInfo)
  23. #endif
  24. #define WMI_KEYBOARD_PORT_INFORMATION 0
  25. #define WMI_KEYBOARD_PORT_EXTENDED_ID 1
  26. #define WMI_MOUSE_PORT_INFORMATION 0
  27. GUID KbKeyboardPortGuid = KEYBOARD_PORT_WMI_STD_DATA_GUID;
  28. WMIGUIDREGINFO KbWmiGuidList[] =
  29. {
  30. { &MSKeyboard_PortInformation_GUID, 1, 0 }, // Keyboard Port driver information
  31. { &MSKeyboard_ExtendedID_GUID, 1, 0 },
  32. };
  33. GUID MouPointerPortGuid = POINTER_PORT_WMI_STD_DATA_GUID;
  34. WMIGUIDREGINFO MouWmiGuidList[] =
  35. {
  36. { &MouPointerPortGuid, 1, 0 } // Pointer Port driver information
  37. };
  38. NTSTATUS
  39. I8xInitWmi(
  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 = I8xKeyboardQueryWmiDataBlock;
  58. }
  59. else {
  60. CommonData->WmiLibInfo.GuidCount = sizeof(MouWmiGuidList) /
  61. sizeof(WMIGUIDREGINFO);
  62. CommonData->WmiLibInfo.GuidList = MouWmiGuidList;
  63. CommonData->WmiLibInfo.QueryWmiDataBlock = I8xMouseQueryWmiDataBlock;
  64. }
  65. CommonData->WmiLibInfo.QueryWmiRegInfo = I8xQueryWmiRegInfo;
  66. CommonData->WmiLibInfo.SetWmiDataBlock = I8xSetWmiDataBlock;
  67. CommonData->WmiLibInfo.SetWmiDataItem = I8xSetWmiDataItem;
  68. CommonData->WmiLibInfo.ExecuteWmiMethod = NULL;
  69. CommonData->WmiLibInfo.WmiFunctionControl = NULL;
  70. return IoWMIRegistrationControl(CommonData->Self,
  71. WMIREG_ACTION_REGISTER
  72. );
  73. }
  74. NTSTATUS
  75. I8xSystemControl(
  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. I8xSetWmiDataItem(
  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_KEYBOARD_PORT_EXTENDED_ID:
  169. // case WMI_MOUSE_PORT_INFORMATION: // they are the same index
  170. status = STATUS_WMI_READ_ONLY;
  171. break;
  172. default:
  173. status = STATUS_WMI_GUID_NOT_FOUND;
  174. break;
  175. }
  176. return WmiCompleteRequest(DeviceObject,
  177. Irp,
  178. status,
  179. 0,
  180. IO_NO_INCREMENT
  181. );
  182. }
  183. NTSTATUS
  184. I8xSetWmiDataBlock(
  185. IN PDEVICE_OBJECT DeviceObject,
  186. IN PIRP Irp,
  187. IN ULONG GuidIndex,
  188. IN ULONG InstanceIndex,
  189. IN ULONG BufferSize,
  190. IN PUCHAR Buffer
  191. )
  192. /*++
  193. Routine Description:
  194. This routine is a callback into the driver to set 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. InstanceIndex is the index that denotes which instance of the data block
  204. is being queried.
  205. BufferSize has the size of the data block passed
  206. Buffer has the new values for the data block
  207. Return Value:
  208. status
  209. --*/
  210. {
  211. PCOMMON_DATA commonData;
  212. NTSTATUS status;
  213. PAGED_CODE();
  214. commonData = (PCOMMON_DATA) DeviceObject->DeviceExtension;
  215. switch (GuidIndex) {
  216. case WMI_KEYBOARD_PORT_INFORMATION:
  217. case WMI_KEYBOARD_PORT_EXTENDED_ID:
  218. // case WMI_MOUSE_PORT_INFORMATION: // they are the same index
  219. status = STATUS_WMI_READ_ONLY;
  220. break;
  221. default:
  222. status = STATUS_WMI_GUID_NOT_FOUND;
  223. }
  224. return WmiCompleteRequest(DeviceObject,
  225. Irp,
  226. status,
  227. 0,
  228. IO_NO_INCREMENT
  229. );
  230. }
  231. NTSTATUS
  232. I8xKeyboardQueryWmiDataBlock(
  233. IN PDEVICE_OBJECT DeviceObject,
  234. IN PIRP Irp,
  235. IN ULONG GuidIndex,
  236. IN ULONG InstanceIndex,
  237. IN ULONG InstanceCount,
  238. IN OUT PULONG InstanceLengthArray,
  239. IN ULONG OutBufferSize,
  240. OUT PUCHAR Buffer
  241. )
  242. /*++
  243. Routine Description:
  244. This routine is a callback into the driver to query for the contents of
  245. a data block. When the driver has finished filling the data block it
  246. must call ClassWmiCompleteRequest to complete the irp. The driver can
  247. return STATUS_PENDING if the irp cannot be completed immediately.
  248. Arguments:
  249. DeviceObject is the device whose data block is being queried
  250. Irp is the Irp that makes this request
  251. GuidIndex is the index into the list of guids provided when the
  252. device registered
  253. InstanceIndex is the index that denotes which instance of the data block
  254. is being queried.
  255. InstanceCount is the number of instnaces expected to be returned for
  256. the data block.
  257. InstanceLengthArray is a pointer to an array of ULONG that returns the
  258. lengths of each instance of the data block. If this is NULL then
  259. there was not enough space in the output buffer to fufill the request
  260. so the irp should be completed with the buffer needed.
  261. BufferAvail on has the maximum size available to write the data
  262. block.
  263. Buffer on return is filled with the returned data block
  264. Return Value:
  265. status
  266. --*/
  267. {
  268. NTSTATUS status;
  269. ULONG size;
  270. KEYBOARD_PORT_WMI_STD_DATA kbData;
  271. PPORT_KEYBOARD_EXTENSION kbExtension;
  272. PKEYBOARD_ATTRIBUTES attributes;
  273. PAGED_CODE();
  274. ASSERT(InstanceIndex == 0 && InstanceCount == 1);
  275. kbExtension = (PPORT_KEYBOARD_EXTENSION) DeviceObject->DeviceExtension;
  276. size = 0;
  277. switch (GuidIndex) {
  278. case WMI_KEYBOARD_PORT_INFORMATION:
  279. size = sizeof(KEYBOARD_PORT_WMI_STD_DATA);
  280. attributes = &kbExtension->KeyboardAttributes;
  281. if (OutBufferSize < size) {
  282. status = STATUS_BUFFER_TOO_SMALL;
  283. break;
  284. }
  285. RtlZeroMemory(&kbData,
  286. size
  287. );
  288. kbData.ConnectorType = KEYBOARD_PORT_WMI_STD_I8042;
  289. kbData.DataQueueSize = attributes->InputDataQueueLength /
  290. sizeof(KEYBOARD_INPUT_DATA);
  291. kbData.ErrorCount = 0;
  292. kbData.FunctionKeys = attributes->NumberOfFunctionKeys;
  293. kbData.Indicators = attributes->NumberOfIndicators;
  294. *(PKEYBOARD_PORT_WMI_STD_DATA) Buffer = kbData;
  295. *InstanceLengthArray = size;
  296. status = STATUS_SUCCESS;
  297. break;
  298. case WMI_KEYBOARD_PORT_EXTENDED_ID:
  299. size = sizeof(KEYBOARD_ID_EX);
  300. if (OutBufferSize < size) {
  301. status = STATUS_BUFFER_TOO_SMALL;
  302. break;
  303. }
  304. *(PKEYBOARD_ID_EX) Buffer = kbExtension->KeyboardIdentifierEx;
  305. *InstanceLengthArray = sizeof(KEYBOARD_ID_EX);
  306. status = STATUS_SUCCESS;
  307. break;
  308. default:
  309. status = STATUS_WMI_GUID_NOT_FOUND;
  310. break;
  311. }
  312. return WmiCompleteRequest(DeviceObject,
  313. Irp,
  314. status,
  315. size,
  316. IO_NO_INCREMENT
  317. );
  318. }
  319. NTSTATUS
  320. I8xMouseQueryWmiDataBlock(
  321. IN PDEVICE_OBJECT DeviceObject,
  322. IN PIRP Irp,
  323. IN ULONG GuidIndex,
  324. IN ULONG InstanceIndex,
  325. IN ULONG InstanceCount,
  326. IN OUT PULONG InstanceLengthArray,
  327. IN ULONG OutBufferSize,
  328. OUT PUCHAR Buffer
  329. )
  330. /*++
  331. Routine Description:
  332. This routine is a callback into the driver to query for the contents of
  333. a data block. When the driver has finished filling the data block it
  334. must call ClassWmiCompleteRequest to complete the irp. The driver can
  335. return STATUS_PENDING if the irp cannot be completed immediately.
  336. Arguments:
  337. DeviceObject is the device whose data block is being queried
  338. Irp is the Irp that makes this request
  339. GuidIndex is the index into the list of guids provided when the
  340. device registered
  341. InstanceIndex is the index that denotes which instance of the data block
  342. is being queried.
  343. InstanceCount is the number of instnaces expected to be returned for
  344. the data block.
  345. InstanceLengthArray is a pointer to an array of ULONG that returns the
  346. lengths of each instance of the data block. If this is NULL then
  347. there was not enough space in the output buffer to fufill the request
  348. so the irp should be completed with the buffer needed.
  349. BufferAvail on has the maximum size available to write the data
  350. block.
  351. Buffer on return is filled with the returned data block
  352. Return Value:
  353. status
  354. --*/
  355. {
  356. NTSTATUS status;
  357. ULONG size = sizeof(POINTER_PORT_WMI_STD_DATA);
  358. POINTER_PORT_WMI_STD_DATA mouData;
  359. PPORT_MOUSE_EXTENSION mouseExtension;
  360. PMOUSE_ATTRIBUTES attributes;
  361. PAGED_CODE();
  362. //
  363. // Only ever registers 1 instance per guid
  364. //
  365. ASSERT(InstanceIndex == 0 && InstanceCount == 1);
  366. mouseExtension = (PPORT_MOUSE_EXTENSION) DeviceObject->DeviceExtension;
  367. switch (GuidIndex) {
  368. case WMI_MOUSE_PORT_INFORMATION:
  369. attributes = &mouseExtension->MouseAttributes;
  370. if (OutBufferSize < size) {
  371. status = STATUS_BUFFER_TOO_SMALL;
  372. break;
  373. }
  374. RtlZeroMemory(&mouData,
  375. size
  376. );
  377. mouData.ConnectorType = POINTER_PORT_WMI_STD_I8042;
  378. mouData.DataQueueSize = attributes->InputDataQueueLength /
  379. sizeof(MOUSE_INPUT_DATA);
  380. mouData.Buttons = attributes->NumberOfButtons;
  381. mouData.ErrorCount = 0;
  382. mouData.HardwareType = POINTER_PORT_WMI_STD_MOUSE;
  383. *(PPOINTER_PORT_WMI_STD_DATA) Buffer = mouData;
  384. *InstanceLengthArray = size;
  385. status = STATUS_SUCCESS;
  386. break;
  387. default:
  388. status = STATUS_WMI_GUID_NOT_FOUND;
  389. break;
  390. }
  391. return WmiCompleteRequest(DeviceObject,
  392. Irp,
  393. status,
  394. size,
  395. IO_NO_INCREMENT
  396. );
  397. }
  398. NTSTATUS
  399. I8xQueryWmiRegInfo(
  400. IN PDEVICE_OBJECT DeviceObject,
  401. OUT PULONG RegFlags,
  402. OUT PUNICODE_STRING InstanceName,
  403. OUT PUNICODE_STRING *RegistryPath,
  404. OUT PUNICODE_STRING MofResourceName,
  405. OUT PDEVICE_OBJECT *Pdo
  406. )
  407. /*++
  408. Routine Description:
  409. This routine is a callback into the driver to retrieve information about
  410. the guids being registered.
  411. Implementations of this routine may be in paged memory
  412. Arguments:
  413. DeviceObject is the device whose registration information is needed
  414. *RegFlags returns with a set of flags that describe all of the guids being
  415. registered for this device. If the device wants enable and disable
  416. collection callbacks before receiving queries for the registered
  417. guids then it should return the WMIREG_FLAG_EXPENSIVE flag. Also the
  418. returned flags may specify WMIREG_FLAG_INSTANCE_PDO in which case
  419. the instance name is determined from the PDO associated with the
  420. device object. Note that the PDO must have an associated devnode. If
  421. WMIREG_FLAG_INSTANCE_PDO is not set then Name must return a unique
  422. name for the device. These flags are ORed into the flags specified
  423. by the GUIDREGINFO for each guid.
  424. InstanceName returns with the instance name for the guids if
  425. WMIREG_FLAG_INSTANCE_PDO is not set in the returned *RegFlags. The
  426. caller will call ExFreePool with the buffer returned.
  427. *RegistryPath returns with the registry path of the driver. This is
  428. required
  429. *MofResourceName returns with the name of the MOF resource attached to
  430. the binary file. If the driver does not have a mof resource attached
  431. then this can be returned as NULL.
  432. *Pdo returns with the device object for the PDO associated with this
  433. device if the WMIREG_FLAG_INSTANCE_PDO flag is retured in
  434. *RegFlags.
  435. Return Value:
  436. status
  437. --*/
  438. {
  439. PCOMMON_DATA commonData;
  440. PAGED_CODE();
  441. commonData = (PCOMMON_DATA) DeviceObject->DeviceExtension;
  442. *RegFlags = WMIREG_FLAG_INSTANCE_PDO;
  443. *RegistryPath = &Globals.RegistryPath;
  444. *Pdo = commonData->PDO;
  445. return STATUS_SUCCESS;
  446. }