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.

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