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.

864 lines
25 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: wmi.c
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "redbook.h"
  11. #include "ntddredb.h"
  12. #include "proto.h"
  13. #include "wmi.tmh"
  14. #ifdef ALLOC_PRAGMA
  15. #pragma alloc_text(PAGE, RedBookThreadWmiHandler)
  16. #pragma alloc_text(PAGE, RedBookWmiInit)
  17. #pragma alloc_text(PAGE, RedBookWmiQueryDataBlock)
  18. #pragma alloc_text(PAGE, RedBookWmiQueryRegInfo)
  19. #pragma alloc_text(PAGE, RedBookWmiSetDataBlock)
  20. #pragma alloc_text(PAGE, RedBookWmiSetDataItem)
  21. #pragma alloc_text(PAGE, RedBookWmiSystemControl)
  22. #pragma alloc_text(PAGE, RedBookWmiUninit)
  23. #endif // ALLOC_PRAGMA
  24. #define REDBOOK_STD_INDEX 0 // index into WMIGUIDREGINFO
  25. #define REDBOOK_PERF_INDEX 1 // index into WMIGUIDREGINFO
  26. WMIGUIDREGINFO RedBookWmiGuidList[] =
  27. {
  28. // GUID, # of data blocks, flags
  29. { &MSRedbook_DriverInformationGuid, 1, 0 }, // RedBook driver info
  30. { &MSRedbook_PerformanceGuid, 1, 0 } // some perf stuff also
  31. };
  32. /////////////////////////////////////////////////////////
  33. NTSTATUS
  34. RedBookWmiUninit(
  35. PREDBOOK_DEVICE_EXTENSION DeviceExtension
  36. )
  37. {
  38. NTSTATUS status = STATUS_SUCCESS;
  39. PAGED_CODE();
  40. if (DeviceExtension->WmiLibInitialized) {
  41. status = IoWMIRegistrationControl(DeviceExtension->SelfDeviceObject,
  42. WMIREG_ACTION_DEREGISTER);
  43. ASSERT(NT_SUCCESS(status)); // can not fail?
  44. DeviceExtension->WmiLibInitialized = 0;
  45. }
  46. return status;
  47. }
  48. NTSTATUS
  49. RedBookWmiInit(
  50. PREDBOOK_DEVICE_EXTENSION DeviceExtension
  51. )
  52. /*++
  53. Routine Description:
  54. Arguments:
  55. Return Value:
  56. --*/
  57. {
  58. NTSTATUS status;
  59. PAGED_CODE();
  60. if (DeviceExtension->WmiLibInitialized) {
  61. return STATUS_SUCCESS;
  62. }
  63. DeviceExtension->WmiLibInfo.GuidCount = sizeof(RedBookWmiGuidList) /
  64. sizeof(WMIGUIDREGINFO);
  65. ASSERT(DeviceExtension->WmiLibInfo.GuidCount > 0);
  66. DeviceExtension->WmiLibInfo.GuidList = RedBookWmiGuidList;
  67. DeviceExtension->WmiLibInfo.QueryWmiDataBlock = RedBookWmiQueryDataBlock;
  68. DeviceExtension->WmiLibInfo.QueryWmiRegInfo = RedBookWmiQueryRegInfo;
  69. DeviceExtension->WmiLibInfo.SetWmiDataBlock = RedBookWmiSetDataBlock;
  70. DeviceExtension->WmiLibInfo.SetWmiDataItem = RedBookWmiSetDataItem;
  71. DeviceExtension->WmiLibInfo.ExecuteWmiMethod = NULL;
  72. DeviceExtension->WmiLibInfo.WmiFunctionControl = NULL;
  73. status = IoWMIRegistrationControl(DeviceExtension->SelfDeviceObject,
  74. WMIREG_ACTION_REGISTER);
  75. if (!NT_SUCCESS(status)) {
  76. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWarning, "[redbook] "
  77. "WmiInit !! Failed [%#010lx]\n", status));
  78. } else {
  79. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  80. "WmiInit => Successfully registered\n"));
  81. DeviceExtension->WmiLibInitialized = 1;
  82. }
  83. return status;
  84. }
  85. NTSTATUS
  86. RedBookWmiQueryDataBlock (
  87. IN PDEVICE_OBJECT DeviceObject,
  88. IN PIRP Irp,
  89. IN ULONG GuidIndex,
  90. IN ULONG InstanceIndex,
  91. IN ULONG InstanceCount,
  92. IN OUT PULONG InstanceLengthArray,
  93. IN ULONG OutBufferSize,
  94. OUT PUCHAR Buffer
  95. )
  96. /*++
  97. Routine Description:
  98. This routine is a callback into the driver to query for the contents of
  99. a data block. When the driver has finished filling the data block it
  100. must call RedBookWmiCompleteRequest to complete the irp. The driver can
  101. return STATUS_PENDING if the irp cannot be completed immediately.
  102. Arguments:
  103. DeviceObject is the device whose data block is being queried
  104. Irp is the Irp that makes this request
  105. GuidIndex is the index into the list of guids provided when the
  106. device registered
  107. InstanceIndex is the instance within the GuidIndex to query
  108. InstanceCount is ???
  109. InstanceLengthArray is a pointer to an array of ULONG that returns
  110. the lengths of each instance of the data block. If this is NULL
  111. then there was not enough space in the output buffer to fulfill
  112. the request so the irp should be completed with the buffer needed.
  113. OutputBufferSize has the maximum size available to write the data
  114. block.
  115. Buffer on return is filled with the returned data block
  116. Return Value:
  117. status
  118. --*/
  119. {
  120. PREDBOOK_DEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
  121. NTSTATUS status;
  122. ULONG size = 0;
  123. PAGED_CODE();
  124. //
  125. // Only one instance per GUID
  126. //
  127. ASSERT( InstanceIndex == 0 );
  128. ASSERT( InstanceCount == 1 );
  129. switch (GuidIndex) {
  130. case REDBOOK_STD_INDEX: {
  131. if (InstanceIndex != 0) {
  132. status = STATUS_WMI_INSTANCE_NOT_FOUND;
  133. break;
  134. }
  135. //
  136. // Reject the request if not enough space alloc'd
  137. //
  138. if (OutBufferSize < sizeof(REDBOOK_WMI_STD_DATA)) {
  139. size = sizeof(REDBOOK_WMI_STD_DATA);
  140. status = STATUS_BUFFER_TOO_SMALL;
  141. break;
  142. }
  143. //
  144. // requests for wmi information can occur while
  145. // the system is playing audio. just copy the info
  146. //
  147. RtlCopyMemory( Buffer,
  148. &deviceExtension->WmiData,
  149. sizeof(REDBOOK_WMI_STD_DATA)
  150. );
  151. //
  152. // Set the size for each instance
  153. //
  154. InstanceLengthArray[InstanceIndex] = sizeof(REDBOOK_WMI_STD_DATA);
  155. size += sizeof(REDBOOK_WMI_STD_DATA);
  156. status = STATUS_SUCCESS;
  157. break;
  158. }
  159. case REDBOOK_PERF_INDEX: {
  160. if (InstanceIndex != 0) {
  161. status = STATUS_WMI_INSTANCE_NOT_FOUND;
  162. break;
  163. }
  164. //
  165. // reject the request if not enough space alloc'd
  166. //
  167. if (OutBufferSize < sizeof(REDBOOK_WMI_PERF_DATA)) {
  168. size = sizeof(REDBOOK_WMI_PERF_DATA);
  169. status = STATUS_BUFFER_TOO_SMALL;
  170. break;
  171. }
  172. //
  173. // Requests for wmi information can occur while
  174. // the system is playing audio. just copy the info
  175. //
  176. RedBookWmiCopyPerfInfo(deviceExtension, (PVOID)Buffer);
  177. //
  178. // set the size for each instance
  179. //
  180. InstanceLengthArray[InstanceIndex] = sizeof(REDBOOK_WMI_PERF_DATA);
  181. size += sizeof(REDBOOK_WMI_PERF_DATA);
  182. status = STATUS_SUCCESS;
  183. break;
  184. }
  185. default: {
  186. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  187. "WmiQueryDataBlock !! Invalid GUID [%#010lx]\n",
  188. GuidIndex));
  189. status = STATUS_WMI_GUID_NOT_FOUND;
  190. break;
  191. }
  192. }
  193. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  194. "WmiQueryDataBlock => internal status [%#010lx]\n",
  195. status));
  196. IoReleaseRemoveLock(&deviceExtension->RemoveLock, Irp);
  197. status = WmiCompleteRequest(DeviceObject,
  198. Irp,
  199. status,
  200. size,
  201. IO_CD_ROM_INCREMENT);
  202. if (!NT_SUCCESS(status)) {
  203. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  204. "WmiQueryDataBlock => IoWMICompleteRequest failed [%#010lx]\n",
  205. status));
  206. }
  207. return status;
  208. }
  209. NTSTATUS
  210. RedBookWmiSetDataBlock(
  211. IN PDEVICE_OBJECT DeviceObject,
  212. IN PIRP Irp,
  213. IN ULONG GuidIndex,
  214. IN ULONG InstanceIndex,
  215. IN ULONG BufferSize,
  216. IN PUCHAR Buffer
  217. )
  218. /*++
  219. Routine Description:
  220. This routine is a callback into the driver to set the contents of
  221. a data block.
  222. When the driver has finished filling the data block it must call
  223. IoWMICompleteRequest(???) to complete the irp.
  224. The driver can return STATUS_PENDING if the irp cannot be
  225. completed immediately.
  226. Arguments:
  227. DeviceObject - the device whose data block is being queried
  228. Irp - Irp that makes this request
  229. GuidIndex - index into the list of guids provided
  230. when the device registered
  231. InstanceIndex - the index that denotes which index of the
  232. data block is being set
  233. BufferSize - the size of the data block passed
  234. Buffer - the new values for the data block
  235. Return Value:
  236. status
  237. --*/
  238. {
  239. PREDBOOK_DEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
  240. ULONG size = 0;
  241. NTSTATUS status;
  242. PAGED_CODE();
  243. switch( GuidIndex ) {
  244. case REDBOOK_STD_INDEX: {
  245. REDBOOK_WMI_STD_DATA wmiData;
  246. ULONG state;
  247. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  248. "WmiSetDataBlock => Instance: [%#010lx] BuffSize: [%#010lx]\n",
  249. InstanceIndex, BufferSize));
  250. state = GetCdromState(deviceExtension);
  251. if (!TEST_FLAG(state, CD_STOPPED)) {
  252. status = STATUS_DEVICE_BUSY;
  253. break;
  254. }
  255. if (InstanceIndex != 0) {
  256. status = STATUS_WMI_INSTANCE_NOT_FOUND;
  257. break;
  258. }
  259. if ( BufferSize != sizeof(REDBOOK_WMI_STD_DATA) ) {
  260. status = STATUS_INFO_LENGTH_MISMATCH;
  261. break;
  262. }
  263. wmiData = *(PREDBOOK_WMI_STD_DATA)Buffer;
  264. //
  265. // verify the buffer contains valid information
  266. //
  267. if ( wmiData.NumberOfBuffers > REDBOOK_WMI_BUFFERS_MAX ||
  268. wmiData.NumberOfBuffers < REDBOOK_WMI_BUFFERS_MIN ) {
  269. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  270. "WmiSetDataBlock !! Invalid number of bufers [%#010lx]\n",
  271. wmiData.NumberOfBuffers));
  272. status = STATUS_WMI_SET_FAILURE;
  273. break;
  274. }
  275. if ( wmiData.SectorsPerRead > REDBOOK_WMI_SECTORS_MAX ||
  276. wmiData.SectorsPerRead < REDBOOK_WMI_SECTORS_MIN ||
  277. wmiData.SectorsPerRead > wmiData.MaximumSectorsPerRead ) {
  278. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  279. "WmiSetDataBlock !! Invalid number of sectors per read [%#010lx]\n",
  280. wmiData.SectorsPerRead));
  281. status = STATUS_WMI_SET_FAILURE;
  282. break;
  283. }
  284. if ( wmiData.PlayEnabled != TRUE &&
  285. wmiData.PlayEnabled != FALSE
  286. ) {
  287. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  288. "WmiSetDataBlock !! Invalid setting for play enabled [%#010lx]\n",
  289. wmiData.PlayEnabled));
  290. status = STATUS_WMI_SET_FAILURE;
  291. break;
  292. }
  293. deviceExtension->WmiData.NumberOfBuffers = wmiData.NumberOfBuffers;
  294. deviceExtension->WmiData.SectorsPerRead = wmiData.SectorsPerRead;
  295. deviceExtension->WmiData.PlayEnabled = wmiData.PlayEnabled;
  296. RedBookRegistryWrite(deviceExtension);
  297. status = STATUS_SUCCESS;
  298. break;
  299. }
  300. case REDBOOK_PERF_INDEX: {
  301. status = STATUS_WMI_READ_ONLY;
  302. break;
  303. }
  304. default: {
  305. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  306. "WmiSetDataBlock !! Invalid GuidIndex [%#010lx]\n",
  307. GuidIndex));
  308. status = STATUS_WMI_GUID_NOT_FOUND;
  309. break;
  310. }
  311. }
  312. IoReleaseRemoveLock( &deviceExtension->RemoveLock, Irp );
  313. status = WmiCompleteRequest( DeviceObject,
  314. Irp,
  315. status,
  316. sizeof(REDBOOK_WMI_STD_DATA),
  317. IO_CD_ROM_INCREMENT);
  318. return status;
  319. }
  320. NTSTATUS
  321. RedBookWmiSetDataItem(
  322. IN PDEVICE_OBJECT DeviceObject,
  323. IN PIRP Irp,
  324. IN ULONG GuidIndex,
  325. IN ULONG InstanceIndex,
  326. IN ULONG DataItemId,
  327. IN ULONG BufferSize,
  328. IN PUCHAR Buffer
  329. )
  330. /*++
  331. Routine Description:
  332. This routine is a callback into the driver to set the contents of
  333. a data block.
  334. ??? When the driver has finished filling the data block it
  335. must call ClassWmiCompleteRequest(???) to complete the irp.
  336. The driver can return STATUS_PENDING if the irp cannot be
  337. completed immediately.
  338. Arguments:
  339. DeviceObject - the device whose data block is being queried
  340. Irp - Irp that makes this request
  341. GuidIndex - index into the list of guids provided
  342. when the device registered
  343. DataItemId - Id of the data item being set
  344. BufferSize - the size of the data block passed
  345. Buffer - the new values for the data block
  346. Return Value:
  347. status
  348. --*/
  349. {
  350. PREDBOOK_DEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
  351. ULONG size = 0;
  352. NTSTATUS status;
  353. PAGED_CODE();
  354. switch( GuidIndex ) {
  355. case REDBOOK_STD_INDEX: {
  356. ULONG state;
  357. if (InstanceIndex != 0) {
  358. status = STATUS_WMI_INSTANCE_NOT_FOUND;
  359. break;
  360. }
  361. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  362. "WmiSetDataItem => Id: [%#010lx] Size: [%#010lx]\n",
  363. DataItemId, BufferSize));
  364. state = GetCdromState(deviceExtension);
  365. if (!TEST_FLAG(state, CD_STOPPED)) {
  366. status = STATUS_DEVICE_BUSY;
  367. break;
  368. }
  369. switch (DataItemId) {
  370. //
  371. // These are the only four settable items
  372. //
  373. case REDBOOK_WMI_NUMBER_OF_BUFFERS_ID:
  374. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  375. "WmiSetDataItem => Setting NumberOfBuffers\n"));
  376. if (BufferSize != REDBOOK_WMI_NUMBER_OF_BUFFERS_SIZE) {
  377. status = STATUS_WMI_SET_FAILURE;
  378. break;
  379. }
  380. deviceExtension->WmiData.NumberOfBuffers = *(PULONG32)Buffer;
  381. RedBookRegistryWrite(deviceExtension);
  382. status = STATUS_SUCCESS;
  383. break;
  384. case REDBOOK_WMI_SECTORS_PER_READ_ID:
  385. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  386. "WmiSetDataItem => Setting SectorsPerRead\n"));
  387. if (BufferSize != REDBOOK_WMI_SECTORS_PER_READ_SIZE) {
  388. status = STATUS_WMI_SET_FAILURE;
  389. break;
  390. }
  391. if (*(PULONG32)Buffer >
  392. deviceExtension->WmiData.MaximumSectorsPerRead) {
  393. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  394. "WmiSetDataBlock => Interface Card / "
  395. "CDROM combo does not support this size\n"));
  396. status = STATUS_DEVICE_BUSY;
  397. break;
  398. }
  399. deviceExtension->WmiData.SectorsPerRead = *(PULONG32)Buffer;
  400. RedBookRegistryWrite(deviceExtension);
  401. status = STATUS_SUCCESS;
  402. break;
  403. case REDBOOK_WMI_PLAY_ENABLED_ID:
  404. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  405. "WmiSetDataItem => Setting PlayEnabled\n"));
  406. if ( BufferSize != REDBOOK_WMI_PLAY_ENABLED_SIZE ) {
  407. status = STATUS_WMI_SET_FAILURE;
  408. break;
  409. }
  410. deviceExtension->WmiData.PlayEnabled = *(PBOOLEAN)Buffer;
  411. status = STATUS_SUCCESS;
  412. break;
  413. //
  414. // The remaining are invalid sets, as they are Read-Only values
  415. //
  416. case REDBOOK_WMI_SECTORS_PER_READ_MASK_ID:
  417. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  418. "WmiSetDataItem => Cannot set SectorsPerReadMask\n"));
  419. status = STATUS_WMI_READ_ONLY;
  420. break;
  421. case REDBOOK_WMI_CDDA_SUPPORTED_ID:
  422. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  423. "WmiSetDataItem => Cannot set Supported\n"));
  424. status = STATUS_WMI_READ_ONLY;
  425. break;
  426. case REDBOOK_WMI_CDDA_ACCURATE_ID:
  427. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  428. "WmiSetDataItem => Cannot set KnownGood\n"));
  429. status = STATUS_WMI_READ_ONLY;
  430. break;
  431. default:
  432. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  433. "WmiSetDataItem => Cannot set unknown "
  434. "id %#010lx\n", DataItemId));
  435. status = STATUS_WMI_ITEMID_NOT_FOUND;
  436. break;
  437. }
  438. //
  439. // the status is now correctly set.
  440. // what should size be?
  441. //
  442. size = 0;
  443. break;
  444. }
  445. case REDBOOK_PERF_INDEX: {
  446. if (InstanceIndex != 0) {
  447. status = STATUS_WMI_INSTANCE_NOT_FOUND;
  448. break;
  449. }
  450. status = STATUS_WMI_READ_ONLY;
  451. size = 0;
  452. break;
  453. }
  454. default: {
  455. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  456. "WmiSetDataItem !! Invalid GuidIndex: %#010lx\n",
  457. GuidIndex));
  458. status = STATUS_WMI_GUID_NOT_FOUND;
  459. size = 0;
  460. break;
  461. }
  462. }
  463. IoReleaseRemoveLock(&deviceExtension->RemoveLock, Irp);
  464. status = WmiCompleteRequest( DeviceObject,
  465. Irp,
  466. status,
  467. size,
  468. IO_CD_ROM_INCREMENT
  469. );
  470. return status;
  471. }
  472. NTSTATUS
  473. RedBookWmiSystemControl(
  474. IN PDEVICE_OBJECT DeviceObject,
  475. IN PIRP Irp
  476. )
  477. /*++
  478. Routine Description:
  479. System Control Irp
  480. Presume it is a WMI Irp and call into the WMI system to
  481. handle this IRP for us.
  482. --*/
  483. {
  484. PREDBOOK_DEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
  485. PREDBOOK_THREAD_WMI_DATA wmiData;
  486. NTSTATUS status;
  487. PAGED_CODE();
  488. status = IoAcquireRemoveLock(&deviceExtension->RemoveLock, Irp);
  489. if ( !NT_SUCCESS(status) ) {
  490. Irp->IoStatus.Information = 0;
  491. Irp->IoStatus.Status = status;
  492. IoCompleteRequest( Irp, IO_CD_ROM_INCREMENT );
  493. return status;
  494. }
  495. wmiData = ExAllocatePoolWithTag(NonPagedPool,
  496. sizeof(REDBOOK_THREAD_WMI_DATA),
  497. TAG_T_WMI);
  498. if (wmiData == NULL) {
  499. IoReleaseRemoveLock(&deviceExtension->RemoveLock, Irp);
  500. Irp->IoStatus.Information = 0;
  501. Irp->IoStatus.Status = STATUS_NO_MEMORY;
  502. IoCompleteRequest( Irp, IO_CD_ROM_INCREMENT );
  503. return STATUS_NO_MEMORY;
  504. }
  505. wmiData->Irp = Irp;
  506. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  507. "DispatchWmi => Queueing Irp %p\n", wmiData->Irp));
  508. //
  509. // queue them, allow thread to handle the request.
  510. //
  511. IoMarkIrpPending(Irp);
  512. ExInterlockedInsertTailList(&deviceExtension->Thread.WmiList,
  513. &wmiData->ListEntry,
  514. &deviceExtension->Thread.WmiLock);
  515. KeSetEvent(deviceExtension->Thread.Events[EVENT_WMI],
  516. IO_NO_INCREMENT, FALSE);
  517. return STATUS_PENDING;
  518. }
  519. VOID
  520. RedBookThreadWmiHandler(
  521. PREDBOOK_DEVICE_EXTENSION DeviceExtension,
  522. PLIST_ENTRY ListEntry
  523. )
  524. {
  525. SYSCTL_IRP_DISPOSITION disposition;
  526. PREDBOOK_THREAD_WMI_DATA wmiData;
  527. PIRP irp;
  528. NTSTATUS status;
  529. PAGED_CODE();
  530. VerifyCalledByThread(DeviceExtension);
  531. wmiData = CONTAINING_RECORD(ListEntry, REDBOOK_THREAD_WMI_DATA, ListEntry);
  532. irp = wmiData->Irp;
  533. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  534. "HandleWmi => Processing Irp %p\n", irp));
  535. ExFreePool(wmiData);
  536. wmiData = NULL;
  537. //
  538. // just process the irp now.
  539. //
  540. status = WmiSystemControl( &DeviceExtension->WmiLibInfo,
  541. DeviceExtension->SelfDeviceObject,
  542. irp,
  543. &disposition);
  544. switch ( disposition ) {
  545. case IrpProcessed: {
  546. //
  547. // this irp has been processed and may be completed or pending
  548. //
  549. break;
  550. }
  551. case IrpNotCompleted: {
  552. //
  553. // this irp has not been completed, but has been fully processed.
  554. // we will complete it now.
  555. //
  556. IoReleaseRemoveLock(&DeviceExtension->RemoveLock, irp);
  557. IoCompleteRequest(irp, IO_CD_ROM_INCREMENT);
  558. break;
  559. }
  560. case IrpNotWmi:
  561. case IrpForward: {
  562. //
  563. // this irp is either not a wmi irp or is a wmi irp targetted
  564. // at a device lower in the stack.
  565. //
  566. IoReleaseRemoveLock(&DeviceExtension->RemoveLock, irp);
  567. IoSkipCurrentIrpStackLocation(irp);
  568. IoCallDriver(DeviceExtension->TargetDeviceObject, irp);
  569. break;
  570. }
  571. default: {
  572. //
  573. // we should never really get here, but if we do, just forward...
  574. //
  575. ASSERT(!"[redbook] WmiSystemControl (unhandled case)");
  576. IoReleaseRemoveLock(&DeviceExtension->RemoveLock, irp);
  577. IoSkipCurrentIrpStackLocation(irp);
  578. IoCallDriver(DeviceExtension->TargetDeviceObject, irp);
  579. break;
  580. }
  581. }
  582. return;
  583. }
  584. NTSTATUS
  585. RedBookWmiQueryRegInfo(
  586. IN PDEVICE_OBJECT DeviceObject,
  587. OUT PULONG RegFlags,
  588. OUT PUNICODE_STRING InstanceName,
  589. OUT PUNICODE_STRING *RegistryPath,
  590. OUT PUNICODE_STRING MofResourceName,
  591. OUT PDEVICE_OBJECT *PhysicalDeviceObject
  592. )
  593. /*++
  594. Routine Description:
  595. This routine is a callback into the driver to retrieve the
  596. list of guids or data blocks that the driver wants to register
  597. with WMI. This routine may not pend or block.
  598. Arguments:
  599. DeviceObject - the device whose data block is being queried
  600. RegFlags - Returns with a set of flags that describe the guids
  601. registered for this device. If the device wants to enable
  602. and disable collection callbacks before receiving queries
  603. for the registered guids then it should return the
  604. WMIREG_FLAG_EXPENSIVE flag. Also the returned flags may
  605. specify WMIREG_FLAG_INSTANCE_PDO in which case the instance
  606. name is determined from the PDO associated with the device
  607. object. Note that the PDO must have an associated devnode.
  608. If WMIREG_FLAG_INSTANCE_PDO is not set then Name must return
  609. a unique name for the device.
  610. InstanceName - Returns with the instance name for the guids if
  611. WMIREG_FLAG_INSTANCE_PDO is not set in the returned RegFlags.
  612. The caller will call ExFreePool with the buffer returned.
  613. RegistryPath - Returns with the registry path of the driver
  614. MofResourceName - Returns with the name of the MOF resource attached
  615. to the binary file. If the driver does not have a mof resource
  616. attached then this can be returned as NULL.
  617. PhysicalDeviceObject - Returns with the device object for the PDO
  618. associated with this device if the WMI_REG_FLAG_INSTANCE_PDO
  619. flag is returned in RegFlags
  620. Return Value:
  621. status
  622. --*/
  623. {
  624. PREDBOOK_DEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
  625. PREDBOOK_DRIVER_EXTENSION driverExtension;
  626. PAGED_CODE();
  627. UNREFERENCED_PARAMETER(InstanceName);
  628. driverExtension = IoGetDriverObjectExtension(deviceExtension->DriverObject,
  629. REDBOOK_DRIVER_EXTENSION_ID);
  630. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  631. "WmiQueryRegInfo => driverExtension is [%p]\n",
  632. driverExtension));
  633. ASSERT(driverExtension);
  634. KdPrintEx((DPFLTR_REDBOOK_ID, RedbookDebugWmi, "[redbook] "
  635. "WmiQueryRegInfo => Registry Path = %ws\n",
  636. driverExtension->RegistryPath.Buffer));
  637. *RegFlags = WMIREG_FLAG_INSTANCE_PDO;
  638. *RegistryPath = &(driverExtension->RegistryPath);
  639. *PhysicalDeviceObject = deviceExtension->TargetPdo;
  640. return STATUS_SUCCESS;
  641. }
  642. VOID
  643. RedBookWmiCopyPerfInfo(
  644. IN PREDBOOK_DEVICE_EXTENSION DeviceExtension,
  645. OUT PREDBOOK_WMI_PERF_DATA Out
  646. )
  647. {
  648. KIRQL irql;
  649. //
  650. // cannot be paged due to spinlock, which allows copy of
  651. // the LARGE_INTEGERS without problems.
  652. //
  653. KeAcquireSpinLock( &DeviceExtension->WmiPerfLock, &irql );
  654. RtlCopyMemory( Out,
  655. &DeviceExtension->WmiPerf,
  656. sizeof(REDBOOK_WMI_PERF_DATA)
  657. );
  658. KeReleaseSpinLock( &DeviceExtension->WmiPerfLock, irql );
  659. //
  660. // now add InterlockedXxx() calls to safely get a couple of the items.
  661. //
  662. Out->StreamPausedCount =
  663. InterlockedCompareExchange(&DeviceExtension->WmiPerf.StreamPausedCount,0,0);
  664. //
  665. // finished.
  666. //
  667. return;
  668. }