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.

986 lines
26 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. wmi.c
  5. Abstract
  6. Power handling
  7. Author:
  8. jsenior
  9. Environment:
  10. Kernel mode only
  11. Revision History:
  12. --*/
  13. #include "pch.h"
  14. #define WMI_WAIT_WAKE 0
  15. #define WMI_SEL_SUSP 0
  16. //
  17. // WMI System Call back functions
  18. //
  19. NTSTATUS
  20. HidpIrpMajorSystemControl (
  21. IN PHIDCLASS_DEVICE_EXTENSION HidClassExtension,
  22. IN PIRP Irp
  23. )
  24. /*++
  25. Routine Description
  26. We have just received a System Control IRP.
  27. Assume that this is a WMI IRP and
  28. call into the WMI system library and let it handle this IRP for us.
  29. --*/
  30. {
  31. NTSTATUS status;
  32. SYSCTL_IRP_DISPOSITION disposition;
  33. if (HidClassExtension->isClientPdo) {
  34. status = WmiSystemControl(&HidClassExtension->pdoExt.WmiLibInfo,
  35. HidClassExtension->pdoExt.pdo,
  36. Irp,
  37. &disposition);
  38. } else {
  39. status = WmiSystemControl(&HidClassExtension->fdoExt.WmiLibInfo,
  40. HidClassExtension->fdoExt.fdo,
  41. Irp,
  42. &disposition);
  43. }
  44. switch(disposition) {
  45. case IrpProcessed:
  46. //
  47. // This irp has been processed and may be completed or pending.
  48. //
  49. break;
  50. case IrpNotCompleted:
  51. //
  52. // This irp has not been completed, but has been fully processed.
  53. // we will complete it now
  54. //
  55. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  56. break;
  57. case IrpForward:
  58. case IrpNotWmi:
  59. //
  60. // This irp is either not a WMI irp or is a WMI irp targetted
  61. // at a device lower in the stack.
  62. //
  63. status = HidpIrpMajorDefault(HidClassExtension, Irp);
  64. break;
  65. default:
  66. //
  67. // We really should never get here, but if we do just forward....
  68. //
  69. ASSERT(FALSE);
  70. status = HidpIrpMajorDefault(HidClassExtension, Irp);
  71. break;
  72. }
  73. return status;
  74. }
  75. VOID
  76. HidpRemoteWakeComplete(
  77. IN PDEVICE_OBJECT DeviceObject,
  78. IN UCHAR MinorFunction,
  79. IN POWER_STATE PowerState,
  80. IN PVOID Context,
  81. IN PIO_STATUS_BLOCK IoStatus
  82. )
  83. /*++
  84. Routine Description:
  85. Catch the Wait wake Irp on its way back.
  86. Return Value:
  87. --*/
  88. {
  89. PDO_EXTENSION *pdoExt = Context;
  90. POWER_STATE powerState;
  91. NTSTATUS status;
  92. PHIDCLASS_WORK_ITEM_DATA itemData;
  93. ASSERT (MinorFunction == IRP_MN_WAIT_WAKE);
  94. //
  95. // PowerState.SystemState is undefined when the WW irp has been completed
  96. //
  97. // ASSERT (PowerState.SystemState == PowerSystemWorking);
  98. InterlockedExchangePointer(&pdoExt->remoteWakeIrp, NULL);
  99. switch (IoStatus->Status) {
  100. case STATUS_SUCCESS:
  101. DBGVERBOSE(("HidClass: Remote Wake irp was completed successfully.\n"));
  102. //
  103. // We do not need to request a set power to power up the device, since
  104. // hidclass does this for us.
  105. //
  106. /* powerState.DeviceState = PowerDeviceD0;
  107. status = PoRequestPowerIrp(
  108. pdoExt->PDO,
  109. IRP_MN_SET_POWER,
  110. powerState,
  111. NULL,
  112. NULL,
  113. NULL);*/
  114. //
  115. // We do not notify the system that a user is present because:
  116. // 1 Win9x doesn't do this and we must maintain compatibility with it
  117. // 2 The USB PIX4 motherboards sends a wait wake event every time the
  118. // machine wakes up, no matter if this device woke the machine or not
  119. //
  120. // If we incorrectly notify the system a user is present, the following
  121. // will occur:
  122. // 1 The monitor will be turned on
  123. // 2 We will prevent the machine from transitioning from standby
  124. // (to PowerSystemWorking) to hibernate
  125. //
  126. // If a user is truly present, we will receive input in the service
  127. // callback and we will notify the system at that time.
  128. //
  129. // PoSetSystemState (ES_USER_PRESENT);
  130. if (pdoExt->remoteWakeEnabled) {
  131. //
  132. // We cannot call CreateWaitWake from this completion routine,
  133. // as it is a paged function.
  134. //
  135. itemData = (PHIDCLASS_WORK_ITEM_DATA)
  136. ExAllocatePool (NonPagedPool, sizeof (HIDCLASS_WORK_ITEM_DATA));
  137. if (NULL != itemData) {
  138. itemData->Item = IoAllocateWorkItem(pdoExt->pdo);
  139. if (itemData->Item == NULL) {
  140. ExFreePool(itemData);
  141. DBGWARN (("Failed alloc work item -> no WW Irp."));
  142. } else {
  143. itemData->PdoExt = pdoExt;
  144. itemData->Irp = NULL;
  145. status = IoAcquireRemoveLock (&pdoExt->removeLock, itemData);
  146. if (NT_SUCCESS(status)) {
  147. IoQueueWorkItem (itemData->Item,
  148. HidpCreateRemoteWakeIrpWorker,
  149. DelayedWorkQueue,
  150. itemData);
  151. }
  152. else {
  153. //
  154. // The device has been removed
  155. //
  156. IoFreeWorkItem (itemData->Item);
  157. ExFreePool (itemData);
  158. }
  159. }
  160. } else {
  161. //
  162. // Well, we dropped the WaitWake.
  163. //
  164. DBGWARN (("Failed alloc pool -> no WW Irp."));
  165. }
  166. }
  167. // fall through to the break
  168. //
  169. // We get a remove. We will not (obviously) send another wait wake
  170. //
  171. case STATUS_CANCELLED:
  172. //
  173. // This status code will be returned if the device is put into a power state
  174. // in which we cannot wake the machine (hibernate is a good example). When
  175. // the device power state is returned to D0, we will attempt to rearm wait wake
  176. //
  177. case STATUS_POWER_STATE_INVALID:
  178. case STATUS_ACPI_POWER_REQUEST_FAILED:
  179. //
  180. // We failed the Irp because we already had one queued, or a lower driver in
  181. // the stack failed it. Either way, don't do anything.
  182. //
  183. case STATUS_INVALID_DEVICE_STATE:
  184. //
  185. // Somehow someway we got two WWs down to the lower stack.
  186. // Let's just don't worry about it.
  187. //
  188. case STATUS_DEVICE_BUSY:
  189. break;
  190. default:
  191. //
  192. // Something went wrong, disable the wait wake.
  193. //
  194. KdPrint(("KBDCLASS: wait wake irp failed with %x\n", IoStatus->Status));
  195. HidpToggleRemoteWake (pdoExt, FALSE);
  196. }
  197. }
  198. BOOLEAN
  199. HidpCheckRemoteWakeEnabled(
  200. IN PDO_EXTENSION *PdoExt
  201. )
  202. {
  203. KIRQL irql;
  204. BOOLEAN enabled;
  205. KeAcquireSpinLock (&PdoExt->remoteWakeSpinLock, &irql);
  206. enabled = PdoExt->remoteWakeEnabled;
  207. KeReleaseSpinLock (&PdoExt->remoteWakeSpinLock, irql);
  208. return enabled;
  209. }
  210. void
  211. HidpCreateRemoteWakeIrpWorker (
  212. IN PDEVICE_OBJECT DeviceObject,
  213. IN PHIDCLASS_WORK_ITEM_DATA ItemData
  214. )
  215. {
  216. PAGED_CODE ();
  217. HidpCreateRemoteWakeIrp (ItemData->PdoExt);
  218. IoReleaseRemoveLock (&ItemData->PdoExt->removeLock, ItemData);
  219. IoFreeWorkItem(ItemData->Item);
  220. ExFreePool (ItemData);
  221. }
  222. BOOLEAN
  223. HidpCreateRemoteWakeIrp (
  224. IN PDO_EXTENSION *PdoExt
  225. )
  226. /*++
  227. Routine Description:
  228. Catch the Wait wake Irp on its way back.
  229. Return Value:
  230. --*/
  231. {
  232. POWER_STATE powerState;
  233. BOOLEAN success = TRUE;
  234. NTSTATUS status;
  235. PIRP remoteWakeIrp;
  236. PAGED_CODE ();
  237. powerState.SystemState = PdoExt->deviceFdoExt->fdoExt.deviceCapabilities.SystemWake;
  238. status = PoRequestPowerIrp (PdoExt->pdo,
  239. IRP_MN_WAIT_WAKE,
  240. powerState,
  241. HidpRemoteWakeComplete,
  242. PdoExt,
  243. &PdoExt->remoteWakeIrp);
  244. if (status != STATUS_PENDING) {
  245. success = FALSE;
  246. }
  247. return success;
  248. }
  249. VOID
  250. HidpToggleRemoteWakeWorker(
  251. IN PDEVICE_OBJECT DeviceObject,
  252. PHIDCLASS_WORK_ITEM_DATA ItemData
  253. )
  254. /*++
  255. Routine Description:
  256. --*/
  257. {
  258. PDO_EXTENSION *pdoExt;
  259. PIRP remoteWakeIrp = NULL;
  260. KIRQL irql;
  261. BOOLEAN wwState = ItemData->RemoteWakeState ? TRUE : FALSE;
  262. BOOLEAN toggled = FALSE;
  263. //
  264. // Can't be paged b/c we are using spin locks
  265. //
  266. // PAGED_CODE ();
  267. pdoExt = ItemData->PdoExt;
  268. KeAcquireSpinLock (&pdoExt->remoteWakeSpinLock, &irql);
  269. if (wwState != pdoExt->remoteWakeEnabled) {
  270. toggled = TRUE;
  271. if (pdoExt->remoteWakeEnabled) {
  272. remoteWakeIrp = (PIRP)
  273. InterlockedExchangePointer (&pdoExt->remoteWakeIrp, NULL);
  274. }
  275. pdoExt->remoteWakeEnabled = wwState;
  276. }
  277. KeReleaseSpinLock (&pdoExt->remoteWakeSpinLock, irql);
  278. if (toggled) {
  279. UNICODE_STRING strEnable;
  280. HANDLE devInstRegKey;
  281. ULONG tmp = wwState;
  282. //
  283. // write the value out to the registry
  284. //
  285. if ((NT_SUCCESS(IoOpenDeviceRegistryKey (pdoExt->pdo,
  286. PLUGPLAY_REGKEY_DEVICE,
  287. STANDARD_RIGHTS_ALL,
  288. &devInstRegKey)))) {
  289. RtlInitUnicodeString (&strEnable, HIDCLASS_REMOTE_WAKE_ENABLE);
  290. ZwSetValueKey (devInstRegKey,
  291. &strEnable,
  292. 0,
  293. REG_DWORD,
  294. &tmp,
  295. sizeof(tmp));
  296. ZwClose (devInstRegKey);
  297. }
  298. }
  299. if (toggled && wwState) {
  300. //
  301. // wwState is our new state, so WW was just turned on
  302. //
  303. HidpCreateRemoteWakeIrp (pdoExt);
  304. }
  305. //
  306. // If we have an IRP, then WW has been toggled off, otherwise, if toggled is
  307. // TRUE, we need to save this in the reg and, perhaps, send down a new WW irp
  308. //
  309. if (remoteWakeIrp) {
  310. IoCancelIrp (remoteWakeIrp);
  311. }
  312. IoReleaseRemoveLock (&pdoExt->removeLock, HidpToggleRemoteWakeWorker);
  313. IoFreeWorkItem (ItemData->Item);
  314. ExFreePool (ItemData);
  315. }
  316. NTSTATUS
  317. HidpToggleRemoteWake(
  318. PDO_EXTENSION *PdoExt,
  319. BOOLEAN RemoteWakeState
  320. )
  321. {
  322. NTSTATUS status;
  323. PHIDCLASS_WORK_ITEM_DATA itemData;
  324. status = IoAcquireRemoveLock (&PdoExt->removeLock, HidpToggleRemoteWakeWorker);
  325. if (!NT_SUCCESS (status)) {
  326. //
  327. // Device has gone away, just silently exit
  328. //
  329. return status;
  330. }
  331. itemData = (PHIDCLASS_WORK_ITEM_DATA)
  332. ALLOCATEPOOL(NonPagedPool, sizeof(HIDCLASS_WORK_ITEM_DATA));
  333. if (itemData) {
  334. itemData->Item = IoAllocateWorkItem(PdoExt->pdo);
  335. if (itemData->Item == NULL) {
  336. IoReleaseRemoveLock (&PdoExt->removeLock, HidpToggleRemoteWakeWorker);
  337. }
  338. else {
  339. itemData->PdoExt = PdoExt;
  340. itemData->RemoteWakeState = RemoteWakeState;
  341. if (KeGetCurrentIrql() == PASSIVE_LEVEL) {
  342. //
  343. // We are safely at PASSIVE_LEVEL, call callback directly to perform
  344. // this operation immediately.
  345. //
  346. HidpToggleRemoteWakeWorker (PdoExt->pdo, itemData);
  347. } else {
  348. //
  349. // We are not at PASSIVE_LEVEL, so queue a workitem to handle this
  350. // at a later time.
  351. //
  352. IoQueueWorkItem (itemData->Item,
  353. HidpToggleRemoteWakeWorker,
  354. DelayedWorkQueue,
  355. itemData);
  356. }
  357. }
  358. }
  359. else {
  360. IoReleaseRemoveLock (&PdoExt->removeLock, HidpToggleRemoteWakeWorker);
  361. }
  362. return STATUS_SUCCESS;
  363. }
  364. VOID
  365. HidpToggleSelSuspWorker(
  366. IN PDEVICE_OBJECT DeviceObject,
  367. PIO_WORKITEM WorkItem
  368. )
  369. /*++
  370. Routine Description:
  371. --*/
  372. {
  373. FDO_EXTENSION *fdoExt;
  374. UNICODE_STRING strEnable;
  375. HANDLE devInstRegKey;
  376. ULONG tmp;
  377. fdoExt = &((PHIDCLASS_DEVICE_EXTENSION) DeviceObject->DeviceExtension)->fdoExt;
  378. //
  379. // write the value out to the registry
  380. //
  381. tmp = fdoExt->idleEnabled ? TRUE : FALSE;
  382. if ((NT_SUCCESS(IoOpenDeviceRegistryKey (fdoExt->collectionPdoExtensions[0]->hidExt.PhysicalDeviceObject,
  383. PLUGPLAY_REGKEY_DEVICE,
  384. STANDARD_RIGHTS_ALL,
  385. &devInstRegKey)))) {
  386. RtlInitUnicodeString (&strEnable, HIDCLASS_SELECTIVE_SUSPEND_ON);
  387. ZwSetValueKey (devInstRegKey,
  388. &strEnable,
  389. 0,
  390. REG_DWORD,
  391. &tmp,
  392. sizeof(tmp));
  393. ZwClose (devInstRegKey);
  394. }
  395. IoFreeWorkItem (WorkItem);
  396. }
  397. NTSTATUS
  398. HidpToggleSelSusp(
  399. FDO_EXTENSION *FdoExt,
  400. BOOLEAN SelSuspEnable
  401. )
  402. {
  403. PIO_WORKITEM workItem;
  404. BOOLEAN oldState;
  405. KIRQL oldIrql;
  406. KeAcquireSpinLock(&FdoExt->idleSpinLock,
  407. &oldIrql);
  408. oldState = FdoExt->idleEnabled;
  409. FdoExt->idleEnabled = SelSuspEnable;
  410. KeReleaseSpinLock(&FdoExt->idleSpinLock,
  411. oldIrql);
  412. if (oldState != SelSuspEnable) {
  413. if (!SelSuspEnable) {
  414. HidpCancelIdleNotification(FdoExt,
  415. FALSE);
  416. } else {
  417. HidpStartIdleTimeout(FdoExt,
  418. FALSE);
  419. }
  420. workItem = IoAllocateWorkItem(FdoExt->fdo);
  421. if(workItem) {
  422. if (KeGetCurrentIrql() == PASSIVE_LEVEL) {
  423. //
  424. // We are safely at PASSIVE_LEVEL, call callback directly to perform
  425. // this operation immediately.
  426. //
  427. HidpToggleSelSuspWorker (FdoExt->fdo, workItem);
  428. } else {
  429. //
  430. // We are not at PASSIVE_LEVEL, so queue a workitem to handle this
  431. // at a later time.
  432. //
  433. IoQueueWorkItem (workItem,
  434. HidpToggleSelSuspWorker,
  435. DelayedWorkQueue,
  436. workItem);
  437. }
  438. }
  439. }
  440. return STATUS_SUCCESS;
  441. }
  442. NTSTATUS
  443. HidpSetWmiDataItem(
  444. IN PDEVICE_OBJECT DeviceObject,
  445. IN PIRP Irp,
  446. IN ULONG GuidIndex,
  447. IN ULONG InstanceIndex,
  448. IN ULONG DataItemId,
  449. IN ULONG BufferSize,
  450. IN PUCHAR Buffer
  451. )
  452. /*++
  453. Routine Description:
  454. This routine is a callback into the driver to set for the contents of
  455. a data block. When the driver has finished filling the data block it
  456. must call ClassWmiCompleteRequest to complete the irp. The driver can
  457. return STATUS_PENDING if the irp cannot be completed immediately.
  458. Arguments:
  459. DeviceObject is the device whose data block is being queried
  460. Irp is the Irp that makes this request
  461. GuidIndex is the index into the list of guids provided when the
  462. device registered
  463. InstanceIndex is the index that denotes which instance of the data block
  464. is being queried.
  465. DataItemId has the id of the data item being set
  466. BufferSize has the size of the data item passed
  467. Buffer has the new values for the data item
  468. Return Value:
  469. status
  470. --*/
  471. {
  472. PHIDCLASS_DEVICE_EXTENSION classExt;
  473. NTSTATUS status;
  474. ULONG size = 0;
  475. PAGED_CODE ();
  476. classExt = (PHIDCLASS_DEVICE_EXTENSION) DeviceObject->DeviceExtension;
  477. if (classExt->isClientPdo) {
  478. switch(GuidIndex) {
  479. case WMI_WAIT_WAKE:
  480. size = sizeof(BOOLEAN);
  481. if (BufferSize < size) {
  482. status = STATUS_BUFFER_TOO_SMALL;
  483. break;
  484. } else if ((1 != DataItemId) || (0 != InstanceIndex)) {
  485. status = STATUS_INVALID_DEVICE_REQUEST;
  486. break;
  487. }
  488. status = HidpToggleRemoteWake (&classExt->pdoExt, *(PBOOLEAN) Buffer);
  489. break;
  490. default:
  491. status = STATUS_WMI_GUID_NOT_FOUND;
  492. }
  493. } else {
  494. switch(GuidIndex) {
  495. case WMI_SEL_SUSP:
  496. size = sizeof(BOOLEAN);
  497. if (BufferSize < size) {
  498. status = STATUS_BUFFER_TOO_SMALL;
  499. break;
  500. } else if ((1 != DataItemId) || (0 != InstanceIndex)) {
  501. status = STATUS_INVALID_DEVICE_REQUEST;
  502. break;
  503. }
  504. status = HidpToggleSelSusp (&classExt->fdoExt, *(PBOOLEAN) Buffer);
  505. break;
  506. default:
  507. status = STATUS_WMI_GUID_NOT_FOUND;
  508. }
  509. }
  510. status = WmiCompleteRequest (DeviceObject,
  511. Irp,
  512. status,
  513. size,
  514. IO_NO_INCREMENT);
  515. return status;
  516. }
  517. NTSTATUS
  518. HidpSetWmiDataBlock(
  519. IN PDEVICE_OBJECT DeviceObject,
  520. IN PIRP Irp,
  521. IN ULONG GuidIndex,
  522. IN ULONG InstanceIndex,
  523. IN ULONG BufferSize,
  524. IN PUCHAR Buffer
  525. )
  526. /*++
  527. Routine Description:
  528. This routine is a callback into the driver to set the contents of
  529. a data block. When the driver has finished filling the data block it
  530. must call ClassWmiCompleteRequest to complete the irp. The driver can
  531. return STATUS_PENDING if the irp cannot be completed immediately.
  532. Arguments:
  533. DeviceObject is the device whose data block is being queried
  534. Irp is the Irp that makes this request
  535. GuidIndex is the index into the list of guids provided when the
  536. device registered
  537. InstanceIndex is the index that denotes which instance of the data block
  538. is being queried.
  539. BufferSize has the size of the data block passed
  540. Buffer has the new values for the data block
  541. Return Value:
  542. status
  543. --*/
  544. {
  545. PHIDCLASS_DEVICE_EXTENSION classExt;
  546. NTSTATUS status;
  547. ULONG size = 0;
  548. PAGED_CODE ();
  549. classExt = (PHIDCLASS_DEVICE_EXTENSION) DeviceObject->DeviceExtension;
  550. if (classExt->isClientPdo) {
  551. switch(GuidIndex) {
  552. case WMI_WAIT_WAKE:
  553. size = sizeof(BOOLEAN);
  554. if (BufferSize < size) {
  555. status = STATUS_BUFFER_TOO_SMALL;
  556. break;
  557. } else if (0 != InstanceIndex) {
  558. status = STATUS_INVALID_DEVICE_REQUEST;
  559. break;
  560. }
  561. status = HidpToggleRemoteWake (&classExt->pdoExt, *(PBOOLEAN) Buffer);
  562. break;
  563. default:
  564. status = STATUS_WMI_GUID_NOT_FOUND;
  565. }
  566. } else {
  567. switch(GuidIndex) {
  568. case WMI_SEL_SUSP:
  569. size = sizeof(BOOLEAN);
  570. if (BufferSize < size) {
  571. status = STATUS_BUFFER_TOO_SMALL;
  572. break;
  573. } else if (0 != InstanceIndex) {
  574. status = STATUS_INVALID_DEVICE_REQUEST;
  575. break;
  576. }
  577. status = HidpToggleSelSusp (&classExt->fdoExt, *(PBOOLEAN) Buffer);
  578. break;
  579. default:
  580. status = STATUS_WMI_GUID_NOT_FOUND;
  581. }
  582. }
  583. status = WmiCompleteRequest (DeviceObject,
  584. Irp,
  585. status,
  586. size,
  587. IO_NO_INCREMENT);
  588. return status;
  589. }
  590. NTSTATUS
  591. HidpQueryWmiDataBlock(
  592. IN PDEVICE_OBJECT DeviceObject,
  593. IN PIRP Irp,
  594. IN ULONG GuidIndex,
  595. IN ULONG InstanceIndex,
  596. IN ULONG InstanceCount,
  597. IN OUT PULONG InstanceLengthArray,
  598. IN ULONG OutBufferSize,
  599. OUT PUCHAR Buffer
  600. )
  601. /*++
  602. Routine Description:
  603. This routine is a callback into the driver to query for the contents of
  604. a data block. When the driver has finished filling the data block it
  605. must call ClassWmiCompleteRequest to complete the irp. The driver can
  606. return STATUS_PENDING if the irp cannot be completed immediately.
  607. Arguments:
  608. DeviceObject is the device whose data block is being queried
  609. Irp is the Irp that makes this request
  610. GuidIndex is the index into the list of guids provided when the
  611. device registered
  612. InstanceIndex is the index that denotes which instance of the data block
  613. is being queried.
  614. InstanceCount is the number of instnaces expected to be returned for
  615. the data block.
  616. InstanceLengthArray is a pointer to an array of ULONG that returns the
  617. lengths of each instance of the data block. If this is NULL then
  618. there was not enough space in the output buffer to fufill the request
  619. so the irp should be completed with the buffer needed.
  620. BufferAvail on has the maximum size available to write the data
  621. block.
  622. Buffer on return is filled with the returned data block
  623. Return Value:
  624. status
  625. --*/
  626. {
  627. PHIDCLASS_DEVICE_EXTENSION classExt;
  628. NTSTATUS status;
  629. ULONG size = 0;
  630. PAGED_CODE ();
  631. classExt = (PHIDCLASS_DEVICE_EXTENSION) DeviceObject->DeviceExtension;
  632. if (classExt->isClientPdo) {
  633. switch (GuidIndex) {
  634. case WMI_WAIT_WAKE:
  635. //
  636. // Only registers 1 instance for this guid
  637. //
  638. if ((0 != InstanceIndex) || (1 != InstanceCount)) {
  639. status = STATUS_INVALID_DEVICE_REQUEST;
  640. break;
  641. }
  642. size = sizeof(BOOLEAN);
  643. if (OutBufferSize < size) {
  644. status = STATUS_BUFFER_TOO_SMALL;
  645. break;
  646. }
  647. *(PBOOLEAN) Buffer = classExt->pdoExt.remoteWakeEnabled;
  648. *InstanceLengthArray = size;
  649. status = STATUS_SUCCESS;
  650. break;
  651. default:
  652. status = STATUS_WMI_GUID_NOT_FOUND;
  653. }
  654. } else {
  655. switch(GuidIndex) {
  656. case WMI_SEL_SUSP:
  657. //
  658. // Only registers 1 instance for this guid
  659. //
  660. if ((0 != InstanceIndex) || (1 != InstanceCount)) {
  661. status = STATUS_INVALID_DEVICE_REQUEST;
  662. break;
  663. }
  664. size = sizeof(BOOLEAN);
  665. if (OutBufferSize < size) {
  666. status = STATUS_BUFFER_TOO_SMALL;
  667. break;
  668. }
  669. *(PBOOLEAN) Buffer = classExt->fdoExt.idleEnabled;
  670. *InstanceLengthArray = size;
  671. status = STATUS_SUCCESS;
  672. break;
  673. default:
  674. status = STATUS_WMI_GUID_NOT_FOUND;
  675. }
  676. }
  677. status = WmiCompleteRequest (DeviceObject,
  678. Irp,
  679. status,
  680. size,
  681. IO_NO_INCREMENT);
  682. return status;
  683. }
  684. NTSTATUS
  685. HidpQueryWmiRegInfo(
  686. IN PDEVICE_OBJECT DeviceObject,
  687. OUT ULONG *RegFlags,
  688. OUT PUNICODE_STRING InstanceName,
  689. OUT PUNICODE_STRING *RegistryPath,
  690. OUT PUNICODE_STRING MofResourceName,
  691. OUT PDEVICE_OBJECT *Pdo
  692. )
  693. /*++
  694. Routine Description:
  695. This routine is a callback into the driver to retrieve information about
  696. the guids being registered.
  697. Implementations of this routine may be in paged memory
  698. Arguments:
  699. DeviceObject is the device whose registration information is needed
  700. *RegFlags returns with a set of flags that describe all of the guids being
  701. registered for this device. If the device wants enable and disable
  702. collection callbacks before receiving queries for the registered
  703. guids then it should return the WMIREG_FLAG_EXPENSIVE flag. Also the
  704. returned flags may specify WMIREG_FLAG_INSTANCE_PDO in which case
  705. the instance name is determined from the PDO associated with the
  706. device object. Note that the PDO must have an associated devnode. If
  707. WMIREG_FLAG_INSTANCE_PDO is not set then Name must return a unique
  708. name for the device. These flags are ORed into the flags specified
  709. by the GUIDREGINFO for each guid.
  710. InstanceName returns with the instance name for the guids if
  711. WMIREG_FLAG_INSTANCE_PDO is not set in the returned *RegFlags. The
  712. caller will call ExFreePool with the buffer returned.
  713. *RegistryPath returns with the registry path of the driver. This is
  714. required
  715. *MofResourceName returns with the name of the MOF resource attached to
  716. the binary file. If the driver does not have a mof resource attached
  717. then this can be returned as NULL.
  718. *Pdo returns with the device object for the PDO associated with this
  719. device if the WMIREG_FLAG_INSTANCE_PDO flag is retured in
  720. *RegFlags.
  721. Return Value:
  722. status
  723. --*/
  724. {
  725. PHIDCLASS_DEVICE_EXTENSION classExt;
  726. PHIDCLASS_DRIVER_EXTENSION hidDriverExtension;
  727. PAGED_CODE ();
  728. classExt = (PHIDCLASS_DEVICE_EXTENSION) DeviceObject->DeviceExtension;
  729. if (classExt->isClientPdo) {
  730. hidDriverExtension = (PHIDCLASS_DRIVER_EXTENSION) RefDriverExt(classExt->pdoExt.pdo->DriverObject);
  731. ASSERT(hidDriverExtension);
  732. *RegFlags = WMIREG_FLAG_INSTANCE_PDO;
  733. *RegistryPath = &hidDriverExtension->RegistryPath;
  734. *Pdo = classExt->pdoExt.pdo;
  735. DerefDriverExt(classExt->pdoExt.pdo->DriverObject);
  736. } else {
  737. hidDriverExtension = classExt->fdoExt.driverExt;
  738. ASSERT(hidDriverExtension);
  739. *RegFlags = WMIREG_FLAG_INSTANCE_PDO;
  740. *RegistryPath = &hidDriverExtension->RegistryPath;
  741. *Pdo = classExt->hidExt.PhysicalDeviceObject;
  742. }
  743. return STATUS_SUCCESS;
  744. }