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.

647 lines
16 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. sSWmi.c
  5. Abstract:
  6. Environment:
  7. Kernel mode
  8. Notes:
  9. Copyright (c) 2000 Microsoft Corporation.
  10. All Rights Reserved.
  11. --*/
  12. #include "selSusp.h"
  13. #include "sSPwr.h"
  14. #include "sSPnP.h"
  15. #include "sSDevCtr.h"
  16. #include "sSWmi.h"
  17. #include "sSUsr.h"
  18. #define MOFRESOURCENAME L"MofResourceName"
  19. #define WMI_SELECT_SUSPEND_DRIVER_INFORMATION 0
  20. DEFINE_GUID (SELECT_SUSPEND_WMI_STD_DATA_GUID,
  21. 0xBBA21300, 0x6DD3, 0x11d2, 0xB8, 0x44, 0x00, 0xC0, 0x4F, 0xAD, 0x51, 0x71);
  22. WMIGUIDREGINFO SSWmiGuidList[1] = { {
  23. &SELECT_SUSPEND_WMI_STD_DATA_GUID, 1, 0 // driver information
  24. }
  25. };
  26. NTSTATUS
  27. SSWmiRegistration(
  28. IN OUT PDEVICE_EXTENSION DeviceExtension
  29. )
  30. /*++
  31. Routine Description:
  32. Registers with WMI as a data provider for this
  33. instance of the device
  34. Arguments:
  35. Return Value:
  36. --*/
  37. {
  38. NTSTATUS ntStatus;
  39. PAGED_CODE();
  40. DeviceExtension->WmiLibInfo.GuidCount =
  41. sizeof (SSWmiGuidList) / sizeof (WMIGUIDREGINFO);
  42. DeviceExtension->WmiLibInfo.GuidList = SSWmiGuidList;
  43. DeviceExtension->WmiLibInfo.QueryWmiRegInfo = SSQueryWmiRegInfo;
  44. DeviceExtension->WmiLibInfo.QueryWmiDataBlock = SSQueryWmiDataBlock;
  45. DeviceExtension->WmiLibInfo.SetWmiDataBlock = SSSetWmiDataBlock;
  46. DeviceExtension->WmiLibInfo.SetWmiDataItem = SSSetWmiDataItem;
  47. DeviceExtension->WmiLibInfo.ExecuteWmiMethod = NULL;
  48. DeviceExtension->WmiLibInfo.WmiFunctionControl = NULL;
  49. //
  50. // Register with WMI
  51. //
  52. ntStatus = IoWMIRegistrationControl(DeviceExtension->FunctionalDeviceObject,
  53. WMIREG_ACTION_REGISTER);
  54. return ntStatus;
  55. }
  56. NTSTATUS
  57. SSWmiDeRegistration(
  58. IN OUT PDEVICE_EXTENSION DeviceExtension
  59. )
  60. /*++
  61. Routine Description:
  62. Inform WMI to remove this DeviceObject from its
  63. list of providers. This function also
  64. decrements the reference count of the deviceobject.
  65. Arguments:
  66. Return Value:
  67. --*/
  68. {
  69. PAGED_CODE();
  70. return IoWMIRegistrationControl(DeviceExtension->FunctionalDeviceObject,
  71. WMIREG_ACTION_DEREGISTER);
  72. }
  73. NTSTATUS
  74. SS_DispatchSysCtrl(
  75. IN PDEVICE_OBJECT DeviceObject,
  76. IN PIRP Irp
  77. )
  78. /*++
  79. Routine Description:
  80. Arguments:
  81. Return Value:
  82. --*/
  83. {
  84. PDEVICE_EXTENSION deviceExtension;
  85. SYSCTL_IRP_DISPOSITION disposition;
  86. NTSTATUS ntStatus;
  87. PIO_STACK_LOCATION irpStack;
  88. PAGED_CODE();
  89. irpStack = IoGetCurrentIrpStackLocation (Irp);
  90. deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  91. SSDbgPrint(3, (WMIMinorFunctionString(irpStack->MinorFunction)));
  92. if(Removed == deviceExtension->DeviceState) {
  93. ntStatus = STATUS_DELETE_PENDING;
  94. Irp->IoStatus.Status = ntStatus;
  95. Irp->IoStatus.Information = 0;
  96. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  97. return ntStatus;
  98. }
  99. SSDbgPrint(3, ("SS_DispatchSysCtrl::"));
  100. SSIoIncrement(deviceExtension);
  101. ntStatus = WmiSystemControl(&deviceExtension->WmiLibInfo,
  102. DeviceObject,
  103. Irp,
  104. &disposition);
  105. switch(disposition) {
  106. case IrpProcessed:
  107. {
  108. //
  109. // This irp has been processed and may be completed or pending.
  110. //
  111. break;
  112. }
  113. case IrpNotCompleted:
  114. {
  115. //
  116. // This irp has not been completed, but has been fully processed.
  117. // we will complete it now
  118. //
  119. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  120. break;
  121. }
  122. case IrpForward:
  123. case IrpNotWmi:
  124. {
  125. //
  126. // This irp is either not a WMI irp or is a WMI irp targeted
  127. // at a device lower in the stack.
  128. //
  129. IoSkipCurrentIrpStackLocation (Irp);
  130. ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject,
  131. Irp);
  132. break;
  133. }
  134. default:
  135. {
  136. //
  137. // We really should never get here, but if we do just forward....
  138. //
  139. ASSERT(FALSE);
  140. IoSkipCurrentIrpStackLocation (Irp);
  141. ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject,
  142. Irp);
  143. break;
  144. }
  145. }
  146. SSDbgPrint(3, ("SS_DispatchSysCtrl::"));
  147. SSIoDecrement(deviceExtension);
  148. return ntStatus;
  149. }
  150. NTSTATUS
  151. SSQueryWmiRegInfo(
  152. IN PDEVICE_OBJECT DeviceObject,
  153. OUT ULONG *RegFlags,
  154. OUT PUNICODE_STRING InstanceName,
  155. OUT PUNICODE_STRING *RegistryPath,
  156. OUT PUNICODE_STRING MofResourceName,
  157. OUT PDEVICE_OBJECT *Pdo
  158. )
  159. /*++
  160. Routine Description:
  161. This routine is a callback into the driver to retrieve the list of
  162. guids or data blocks that the driver wants to register with WMI. This
  163. routine may not pend or block. Driver should NOT call
  164. WmiCompleteRequest.
  165. Arguments:
  166. DeviceObject is the device whose data block is being queried
  167. *RegFlags returns with a set of flags that describe the guids being
  168. registered for this device. If the device wants enable and disable
  169. collection callbacks before receiving queries for the registered
  170. guids then it should return the WMIREG_FLAG_EXPENSIVE flag. Also the
  171. returned flags may specify WMIREG_FLAG_INSTANCE_PDO in which case
  172. the instance name is determined from the PDO associated with the
  173. device object. Note that the PDO must have an associated devnode. If
  174. WMIREG_FLAG_INSTANCE_PDO is not set then Name must return a unique
  175. name for the device.
  176. InstanceName returns with the instance name for the guids if
  177. WMIREG_FLAG_INSTANCE_PDO is not set in the returned *RegFlags. The
  178. caller will call ExFreePool with the buffer returned.
  179. *RegistryPath returns with the registry path of the driver
  180. *MofResourceName returns with the name of the MOF resource attached to
  181. the binary file. If the driver does not have a mof resource attached
  182. then this can be returned as NULL.
  183. *Pdo returns with the device object for the PDO associated with this
  184. device if the WMIREG_FLAG_INSTANCE_PDO flag is returned in
  185. *RegFlags.
  186. Return Value:
  187. status
  188. --*/
  189. {
  190. PDEVICE_EXTENSION deviceExtension;
  191. PAGED_CODE();
  192. SSDbgPrint(3, ("SSQueryWmiRegInfo - begins\n"));
  193. deviceExtension = DeviceObject->DeviceExtension;
  194. *RegFlags = WMIREG_FLAG_INSTANCE_PDO;
  195. *RegistryPath = &Globals.SSRegistryPath;
  196. *Pdo = deviceExtension->PhysicalDeviceObject;
  197. RtlInitUnicodeString(MofResourceName, MOFRESOURCENAME);
  198. SSDbgPrint(3, ("SSQueryWmiRegInfo - ends\n"));
  199. return STATUS_SUCCESS;
  200. }
  201. NTSTATUS
  202. SSQueryWmiDataBlock(
  203. IN PDEVICE_OBJECT DeviceObject,
  204. IN PIRP Irp,
  205. IN ULONG GuidIndex,
  206. IN ULONG InstanceIndex,
  207. IN ULONG InstanceCount,
  208. IN OUT PULONG InstanceLengthArray,
  209. IN ULONG OutBufferSize,
  210. OUT PUCHAR Buffer
  211. )
  212. /*++
  213. Routine Description:
  214. This routine is a callback into the driver to query for the contents of
  215. a data block. When the driver has finished filling the data block it
  216. must call WmiCompleteRequest to complete the irp. The driver can
  217. return STATUS_PENDING if the irp cannot be completed immediately.
  218. Arguments:
  219. DeviceObject is the device whose data block is being queried
  220. Irp is the Irp that makes this request
  221. GuidIndex is the index into the list of guids provided when the
  222. device registered
  223. InstanceIndex is the index that denotes which instance of the data block
  224. is being queried.
  225. InstanceCount is the number of instances expected to be returned for
  226. the data block.
  227. InstanceLengthArray is a pointer to an array of ULONG that returns the
  228. lengths of each instance of the data block. If this is NULL then
  229. there was not enough space in the output buffer to fulfill the request
  230. so the irp should be completed with the buffer needed.
  231. OutBufferSize has the maximum size available to write the data
  232. block.
  233. Buffer on return is filled with the returned data block
  234. Return Value:
  235. status
  236. --*/
  237. {
  238. PDEVICE_EXTENSION deviceExtension;
  239. NTSTATUS ntStatus;
  240. ULONG size;
  241. WCHAR modelName[] = L"Aishverya\0\0";
  242. USHORT modelNameLen;
  243. PAGED_CODE();
  244. SSDbgPrint(3, ("SSQueryWmiDataBlock - begins\n"));
  245. size = 0;
  246. modelNameLen = (wcslen(modelName) + 1) * sizeof(WCHAR);
  247. //
  248. // Only ever registers 1 instance per guid
  249. //
  250. ASSERT((InstanceIndex == 0) &&
  251. (InstanceCount == 1));
  252. deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  253. switch (GuidIndex) {
  254. case WMI_SELECT_SUSPEND_DRIVER_INFORMATION:
  255. size = sizeof(ULONG) + modelNameLen + sizeof(USHORT);
  256. if (OutBufferSize < size ) {
  257. SSDbgPrint(3, ("OutBuffer too small\n"));
  258. ntStatus = STATUS_BUFFER_TOO_SMALL;
  259. break;
  260. }
  261. * (PULONG) Buffer = DebugLevel;
  262. Buffer += sizeof(ULONG);
  263. //
  264. // put length of string ahead of string
  265. //
  266. *((PUSHORT)Buffer) = modelNameLen;
  267. Buffer = (PUCHAR)Buffer + sizeof(USHORT);
  268. RtlCopyBytes((PVOID)Buffer, (PVOID)modelName, modelNameLen);
  269. *InstanceLengthArray = size ;
  270. ntStatus = STATUS_SUCCESS;
  271. break;
  272. default:
  273. ntStatus = STATUS_WMI_GUID_NOT_FOUND;
  274. }
  275. ntStatus = WmiCompleteRequest(DeviceObject,
  276. Irp,
  277. ntStatus,
  278. size,
  279. IO_NO_INCREMENT);
  280. SSDbgPrint(3, ("SSQueryWmiDataBlock - ends\n"));
  281. return ntStatus;
  282. }
  283. NTSTATUS
  284. SSSetWmiDataItem(
  285. IN PDEVICE_OBJECT DeviceObject,
  286. IN PIRP Irp,
  287. IN ULONG GuidIndex,
  288. IN ULONG InstanceIndex,
  289. IN ULONG DataItemId,
  290. IN ULONG BufferSize,
  291. IN PUCHAR Buffer
  292. )
  293. /*++
  294. Routine Description:
  295. This routine is a callback into the driver to set for the contents of
  296. a data block. When the driver has finished filling the data block it
  297. must call WmiCompleteRequest to complete the irp. The driver can
  298. return STATUS_PENDING if the irp cannot be completed immediately.
  299. Arguments:
  300. DeviceObject is the device whose data block is being queried
  301. Irp is the Irp that makes this request
  302. GuidIndex is the index into the list of guids provided when the
  303. device registered
  304. InstanceIndex is the index that denotes which instance of the data block
  305. is being queried.
  306. DataItemId has the id of the data item being set
  307. BufferSize has the size of the data item passed
  308. Buffer has the new values for the data item
  309. Return Value:
  310. status
  311. --*/
  312. {
  313. PDEVICE_EXTENSION deviceExtension;
  314. NTSTATUS ntStatus;
  315. ULONG info;
  316. PAGED_CODE();
  317. SSDbgPrint(3, ("SSSetWmiDataItem - begins\n"));
  318. deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  319. info = 0;
  320. switch(GuidIndex) {
  321. case WMI_SELECT_SUSPEND_DRIVER_INFORMATION:
  322. if(DataItemId == 1) {
  323. if(BufferSize == sizeof(ULONG)) {
  324. DebugLevel = *((PULONG)Buffer);
  325. ntStatus = STATUS_SUCCESS;
  326. info = sizeof(ULONG);
  327. }
  328. else {
  329. ntStatus = STATUS_INFO_LENGTH_MISMATCH;
  330. }
  331. }
  332. else {
  333. ntStatus = STATUS_WMI_READ_ONLY;
  334. }
  335. break;
  336. default:
  337. ntStatus = STATUS_WMI_GUID_NOT_FOUND;
  338. }
  339. ntStatus = WmiCompleteRequest(DeviceObject,
  340. Irp,
  341. ntStatus,
  342. info,
  343. IO_NO_INCREMENT);
  344. SSDbgPrint(3, ("SSSetWmiDataItem - ends\n"));
  345. return ntStatus;
  346. }
  347. NTSTATUS
  348. SSSetWmiDataBlock(
  349. IN PDEVICE_OBJECT DeviceObject,
  350. IN PIRP Irp,
  351. IN ULONG GuidIndex,
  352. IN ULONG InstanceIndex,
  353. IN ULONG BufferSize,
  354. IN PUCHAR Buffer
  355. )
  356. /*++
  357. Routine Description:
  358. This routine is a callback into the driver to set the contents of
  359. a data block. When the driver has finished filling the data block it
  360. must call WmiCompleteRequest to complete the irp. The driver can
  361. return STATUS_PENDING if the irp cannot be completed immediately.
  362. Arguments:
  363. DeviceObject is the device whose data block is being queried
  364. Irp is the Irp that makes this request
  365. GuidIndex is the index into the list of guids provided when the
  366. device registered
  367. InstanceIndex is the index that denotes which instance of the data block
  368. is being queried.
  369. BufferSize has the size of the data block passed
  370. Buffer has the new values for the data block
  371. Return Value:
  372. status
  373. --*/
  374. {
  375. PDEVICE_EXTENSION deviceExtension;
  376. NTSTATUS ntStatus;
  377. ULONG info;
  378. PAGED_CODE();
  379. deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  380. info = 0;
  381. SSDbgPrint(3, ("SSSetWmiDataBlock - begins\n"));
  382. switch(GuidIndex) {
  383. case WMI_SELECT_SUSPEND_DRIVER_INFORMATION:
  384. if(BufferSize == sizeof(ULONG)) {
  385. DebugLevel = *(PULONG) Buffer;
  386. ntStatus = STATUS_SUCCESS;
  387. info = sizeof(ULONG);
  388. }
  389. else {
  390. ntStatus = STATUS_INFO_LENGTH_MISMATCH;
  391. }
  392. break;
  393. default:
  394. ntStatus = STATUS_WMI_GUID_NOT_FOUND;
  395. }
  396. ntStatus = WmiCompleteRequest(DeviceObject,
  397. Irp,
  398. ntStatus,
  399. info,
  400. IO_NO_INCREMENT);
  401. SSDbgPrint(3, ("SSSetWmiDataBlock - ends\n"));
  402. return ntStatus;
  403. }
  404. PCHAR
  405. WMIMinorFunctionString (
  406. UCHAR MinorFunction
  407. )
  408. /*++
  409. Routine Description:
  410. Arguments:
  411. Return Value:
  412. --*/
  413. {
  414. switch (MinorFunction) {
  415. case IRP_MN_CHANGE_SINGLE_INSTANCE:
  416. return "IRP_MN_CHANGE_SINGLE_INSTANCE\n";
  417. case IRP_MN_CHANGE_SINGLE_ITEM:
  418. return "IRP_MN_CHANGE_SINGLE_ITEM\n";
  419. case IRP_MN_DISABLE_COLLECTION:
  420. return "IRP_MN_DISABLE_COLLECTION\n";
  421. case IRP_MN_DISABLE_EVENTS:
  422. return "IRP_MN_DISABLE_EVENTS\n";
  423. case IRP_MN_ENABLE_COLLECTION:
  424. return "IRP_MN_ENABLE_COLLECTION\n";
  425. case IRP_MN_ENABLE_EVENTS:
  426. return "IRP_MN_ENABLE_EVENTS\n";
  427. case IRP_MN_EXECUTE_METHOD:
  428. return "IRP_MN_EXECUTE_METHOD\n";
  429. case IRP_MN_QUERY_ALL_DATA:
  430. return "IRP_MN_QUERY_ALL_DATA\n";
  431. case IRP_MN_QUERY_SINGLE_INSTANCE:
  432. return "IRP_MN_QUERY_SINGLE_INSTANCE\n";
  433. case IRP_MN_REGINFO:
  434. return "IRP_MN_REGINFO\n";
  435. default:
  436. return "IRP_MN_?????\n";
  437. }
  438. }