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.

486 lines
14 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. wmi.c
  5. Abstract:
  6. This module contains the code that handles the wmi IRPs for the
  7. serial driver.
  8. Environment:
  9. Kernel mode
  10. Revision History :
  11. --*/
  12. #include "precomp.h"
  13. #include <wmistr.h>
  14. NTSTATUS
  15. SerialSystemControlDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
  16. NTSTATUS
  17. SerialTossWMIRequest(IN PDEVICE_OBJECT PDevObj, IN PIRP PIrp,
  18. IN ULONG GuidIndex);
  19. NTSTATUS
  20. SerialSetWmiDataItem(IN PDEVICE_OBJECT PDevObj, IN PIRP PIrp,
  21. IN ULONG GuidIndex, IN ULONG InstanceIndex,
  22. IN ULONG DataItemId,
  23. IN ULONG BufferSize, IN PUCHAR PBuffer);
  24. NTSTATUS
  25. SerialSetWmiDataBlock(IN PDEVICE_OBJECT PDevObj, IN PIRP PIrp,
  26. IN ULONG GuidIndex, IN ULONG InstanceIndex,
  27. IN ULONG BufferSize,
  28. IN PUCHAR PBuffer);
  29. NTSTATUS
  30. SerialQueryWmiDataBlock(IN PDEVICE_OBJECT PDevObj, IN PIRP PIrp,
  31. IN ULONG GuidIndex,
  32. IN ULONG InstanceIndex,
  33. IN ULONG InstanceCount,
  34. IN OUT PULONG InstanceLengthArray,
  35. IN ULONG OutBufferSize,
  36. OUT PUCHAR PBuffer);
  37. NTSTATUS
  38. SerialQueryWmiRegInfo(IN PDEVICE_OBJECT PDevObj, OUT PULONG PRegFlags,
  39. OUT PUNICODE_STRING PInstanceName,
  40. OUT PUNICODE_STRING *PRegistryPath,
  41. OUT PUNICODE_STRING MofResourceName,
  42. OUT PDEVICE_OBJECT *Pdo);
  43. #ifdef ALLOC_PRAGMA
  44. #pragma alloc_text(PAGESRP0, SerialSystemControlDispatch)
  45. #pragma alloc_text(PAGESRP0, SerialTossWMIRequest)
  46. #pragma alloc_text(PAGESRP0, SerialSetWmiDataItem)
  47. #pragma alloc_text(PAGESRP0, SerialSetWmiDataBlock)
  48. #pragma alloc_text(PAGESRP0, SerialQueryWmiDataBlock)
  49. #pragma alloc_text(PAGESRP0, SerialQueryWmiRegInfo)
  50. #endif
  51. NTSTATUS
  52. SerialSystemControlDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
  53. {
  54. SYSCTL_IRP_DISPOSITION disposition;
  55. NTSTATUS status;
  56. PSERIAL_DEVICE_EXTENSION pDevExt
  57. = (PSERIAL_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
  58. PAGED_CODE();
  59. status = WmiSystemControl( &pDevExt->WmiLibInfo,
  60. DeviceObject,
  61. Irp,
  62. &disposition);
  63. switch(disposition)
  64. {
  65. case IrpProcessed:
  66. {
  67. //
  68. // This irp has been processed and may be completed or pending.
  69. break;
  70. }
  71. case IrpNotCompleted:
  72. {
  73. //
  74. // This irp has not been completed, but has been fully processed.
  75. // we will complete it now
  76. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  77. break;
  78. }
  79. case IrpForward:
  80. case IrpNotWmi:
  81. {
  82. //
  83. // This irp is either not a WMI irp or is a WMI irp targetted
  84. // at a device lower in the stack.
  85. IoSkipCurrentIrpStackLocation(Irp);
  86. status = IoCallDriver(pDevExt->LowerDeviceObject, Irp);
  87. break;
  88. }
  89. default:
  90. {
  91. //
  92. // We really should never get here, but if we do just forward....
  93. ASSERT(FALSE);
  94. IoSkipCurrentIrpStackLocation(Irp);
  95. status = IoCallDriver(pDevExt->LowerDeviceObject, Irp);
  96. break;
  97. }
  98. }
  99. return(status);
  100. }
  101. #define WMI_SERIAL_PORT_NAME_INFORMATION 0
  102. #define WMI_SERIAL_PORT_COMM_INFORMATION 1
  103. #define WMI_SERIAL_PORT_HW_INFORMATION 2
  104. #define WMI_SERIAL_PORT_PERF_INFORMATION 3
  105. GUID SerialPortNameGuid = SERIAL_PORT_WMI_NAME_GUID;
  106. GUID SerialPortCommGuid = SERIAL_PORT_WMI_COMM_GUID;
  107. GUID SerialPortHWGuid = SERIAL_PORT_WMI_HW_GUID;
  108. GUID SerailPortPerfGuid = SERIAL_PORT_WMI_PERF_GUID;
  109. WMIGUIDREGINFO SerialWmiGuidList[4] =
  110. {
  111. { &SerialPortNameGuid, 1, 0 },
  112. { &SerialPortCommGuid, 1, 0 },
  113. { &SerialPortHWGuid, 1, 0 },
  114. { &SerailPortPerfGuid, 1, 0 }
  115. };
  116. //
  117. // WMI System Call back functions
  118. //
  119. NTSTATUS
  120. SerialTossWMIRequest(IN PDEVICE_OBJECT PDevObj, IN PIRP PIrp,
  121. IN ULONG GuidIndex)
  122. {
  123. PSERIAL_DEVICE_EXTENSION pDevExt;
  124. NTSTATUS status;
  125. PAGED_CODE();
  126. pDevExt = (PSERIAL_DEVICE_EXTENSION)PDevObj->DeviceExtension;
  127. switch (GuidIndex) {
  128. case WMI_SERIAL_PORT_NAME_INFORMATION:
  129. case WMI_SERIAL_PORT_COMM_INFORMATION:
  130. case WMI_SERIAL_PORT_HW_INFORMATION:
  131. case WMI_SERIAL_PORT_PERF_INFORMATION:
  132. status = STATUS_INVALID_DEVICE_REQUEST;
  133. break;
  134. default:
  135. status = STATUS_WMI_GUID_NOT_FOUND;
  136. break;
  137. }
  138. status = WmiCompleteRequest(PDevObj, PIrp,
  139. status, 0, IO_NO_INCREMENT);
  140. return status;
  141. }
  142. NTSTATUS
  143. SerialSetWmiDataItem(IN PDEVICE_OBJECT PDevObj, IN PIRP PIrp,
  144. IN ULONG GuidIndex, IN ULONG InstanceIndex,
  145. IN ULONG DataItemId,
  146. IN ULONG BufferSize, IN PUCHAR PBuffer)
  147. /*++
  148. Routine Description:
  149. This routine is a callback into the driver to set for the contents of
  150. a data block. When the driver has finished filling the data block it
  151. must call ClassWmiCompleteRequest to complete the irp. The driver can
  152. return STATUS_PENDING if the irp cannot be completed immediately.
  153. Arguments:
  154. PDevObj is the device whose data block is being queried
  155. PIrp is the Irp that makes this request
  156. GuidIndex is the index into the list of guids provided when the
  157. device registered
  158. InstanceIndex is the index that denotes which instance of the data block
  159. is being queried.
  160. DataItemId has the id of the data item being set
  161. BufferSize has the size of the data item passed
  162. PBuffer has the new values for the data item
  163. Return Value:
  164. status
  165. --*/
  166. {
  167. PAGED_CODE();
  168. //
  169. // Toss this request -- we don't support anything for it
  170. //
  171. return SerialTossWMIRequest(PDevObj, PIrp, GuidIndex);
  172. }
  173. NTSTATUS
  174. SerialSetWmiDataBlock(IN PDEVICE_OBJECT PDevObj, IN PIRP PIrp,
  175. IN ULONG GuidIndex, IN ULONG InstanceIndex,
  176. IN ULONG BufferSize,
  177. IN PUCHAR PBuffer)
  178. /*++
  179. Routine Description:
  180. This routine is a callback into the driver to set the contents of
  181. a data block. When the driver has finished filling the data block it
  182. must call ClassWmiCompleteRequest to complete the irp. The driver can
  183. return STATUS_PENDING if the irp cannot be completed immediately.
  184. Arguments:
  185. PDevObj is the device whose data block is being queried
  186. PIrp is the Irp that makes this request
  187. GuidIndex is the index into the list of guids provided when the
  188. device registered
  189. InstanceIndex is the index that denotes which instance of the data block
  190. is being queried.
  191. BufferSize has the size of the data block passed
  192. PBuffer has the new values for the data block
  193. Return Value:
  194. status
  195. --*/
  196. {
  197. PAGED_CODE();
  198. //
  199. // Toss this request -- we don't support anything for it
  200. //
  201. return SerialTossWMIRequest(PDevObj, PIrp, GuidIndex);
  202. }
  203. NTSTATUS
  204. SerialQueryWmiDataBlock(IN PDEVICE_OBJECT PDevObj, IN PIRP PIrp,
  205. IN ULONG GuidIndex,
  206. IN ULONG InstanceIndex,
  207. IN ULONG InstanceCount,
  208. IN OUT PULONG InstanceLengthArray,
  209. IN ULONG OutBufferSize,
  210. OUT PUCHAR PBuffer)
  211. /*++
  212. Routine Description:
  213. This routine is a callback into the driver to query for the contents of
  214. a data block. When the driver has finished filling the data block it
  215. must call ClassWmiCompleteRequest to complete the irp. The driver can
  216. return STATUS_PENDING if the irp cannot be completed immediately.
  217. Arguments:
  218. PDevObj is the device whose data block is being queried
  219. PIrp is the Irp that makes this request
  220. GuidIndex is the index into the list of guids provided when the
  221. device registered
  222. InstanceIndex is the index that denotes which instance of the data block
  223. is being queried.
  224. InstanceCount is the number of instnaces expected to be returned for
  225. the data block.
  226. InstanceLengthArray is a pointer to an array of ULONG that returns the
  227. lengths of each instance of the data block. If this is NULL then
  228. there was not enough space in the output buffer to fufill the request
  229. so the irp should be completed with the buffer needed.
  230. BufferAvail on has the maximum size available to write the data
  231. block.
  232. PBuffer on return is filled with the returned data block
  233. Return Value:
  234. status
  235. --*/
  236. {
  237. NTSTATUS status;
  238. ULONG size = 0;
  239. PSERIAL_DEVICE_EXTENSION pDevExt
  240. = (PSERIAL_DEVICE_EXTENSION)PDevObj->DeviceExtension;
  241. PAGED_CODE();
  242. switch (GuidIndex) {
  243. case WMI_SERIAL_PORT_NAME_INFORMATION:
  244. size = pDevExt->WmiIdentifier.Length;
  245. if (OutBufferSize < (size + sizeof(USHORT))) {
  246. status = STATUS_BUFFER_TOO_SMALL;
  247. break;
  248. }
  249. if (pDevExt->WmiIdentifier.Buffer == NULL) {
  250. status = STATUS_INSUFFICIENT_RESOURCES;
  251. break;
  252. }
  253. //
  254. // First, copy the string over containing our identifier
  255. //
  256. *(USHORT *)PBuffer = (USHORT)size;
  257. (UCHAR *)PBuffer += sizeof(USHORT);
  258. RtlCopyMemory(PBuffer, pDevExt->WmiIdentifier.Buffer, size);
  259. //
  260. // Increment total size to include the WORD containing our len
  261. //
  262. size += sizeof(USHORT);
  263. *InstanceLengthArray = size;
  264. status = STATUS_SUCCESS;
  265. break;
  266. case WMI_SERIAL_PORT_COMM_INFORMATION:
  267. size = sizeof(SERIAL_WMI_COMM_DATA);
  268. if (OutBufferSize < size) {
  269. status = STATUS_BUFFER_TOO_SMALL;
  270. break;
  271. }
  272. *InstanceLengthArray = size;
  273. *(PSERIAL_WMI_COMM_DATA)PBuffer = pDevExt->WmiCommData;
  274. status = STATUS_SUCCESS;
  275. break;
  276. case WMI_SERIAL_PORT_HW_INFORMATION:
  277. size = sizeof(SERIAL_WMI_HW_DATA);
  278. if (OutBufferSize < size) {
  279. status = STATUS_BUFFER_TOO_SMALL;
  280. break;
  281. }
  282. *InstanceLengthArray = size;
  283. *(PSERIAL_WMI_HW_DATA)PBuffer = pDevExt->WmiHwData;
  284. status = STATUS_SUCCESS;
  285. break;
  286. case WMI_SERIAL_PORT_PERF_INFORMATION:
  287. size = sizeof(SERIAL_WMI_PERF_DATA);
  288. if (OutBufferSize < size) {
  289. status = STATUS_BUFFER_TOO_SMALL;
  290. break;
  291. }
  292. *InstanceLengthArray = size;
  293. *(PSERIAL_WMI_PERF_DATA)PBuffer = pDevExt->WmiPerfData;
  294. status = STATUS_SUCCESS;
  295. break;
  296. default:
  297. status = STATUS_WMI_GUID_NOT_FOUND;
  298. break;
  299. }
  300. status = WmiCompleteRequest( PDevObj, PIrp,
  301. status, size, IO_NO_INCREMENT);
  302. return status;
  303. }
  304. NTSTATUS
  305. SerialQueryWmiRegInfo(IN PDEVICE_OBJECT PDevObj, OUT PULONG PRegFlags,
  306. OUT PUNICODE_STRING PInstanceName,
  307. OUT PUNICODE_STRING *PRegistryPath,
  308. OUT PUNICODE_STRING MofResourceName,
  309. OUT PDEVICE_OBJECT *Pdo)
  310. /*++
  311. Routine Description:
  312. This routine is a callback into the driver to retrieve information about
  313. the guids being registered.
  314. Implementations of this routine may be in paged memory
  315. Arguments:
  316. DeviceObject is the device whose registration information is needed
  317. *RegFlags returns with a set of flags that describe all of the guids being
  318. registered for this device. If the device wants enable and disable
  319. collection callbacks before receiving queries for the registered
  320. guids then it should return the WMIREG_FLAG_EXPENSIVE flag. Also the
  321. returned flags may specify WMIREG_FLAG_INSTANCE_PDO in which case
  322. the instance name is determined from the PDO associated with the
  323. device object. Note that the PDO must have an associated devnode. If
  324. WMIREG_FLAG_INSTANCE_PDO is not set then Name must return a unique
  325. name for the device. These flags are ORed into the flags specified
  326. by the GUIDREGINFO for each guid.
  327. InstanceName returns with the instance name for the guids if
  328. WMIREG_FLAG_INSTANCE_PDO is not set in the returned *RegFlags. The
  329. caller will call ExFreePool with the buffer returned.
  330. *RegistryPath returns with the registry path of the driver. This is
  331. required
  332. *MofResourceName returns with the name of the MOF resource attached to
  333. the binary file. If the driver does not have a mof resource attached
  334. then this can be returned as NULL.
  335. *Pdo returns with the device object for the PDO associated with this
  336. device if the WMIREG_FLAG_INSTANCE_PDO flag is retured in
  337. *RegFlags.
  338. Return Value:
  339. status
  340. --*/
  341. {
  342. PSERIAL_DEVICE_EXTENSION pDevExt
  343. = (PSERIAL_DEVICE_EXTENSION)PDevObj->DeviceExtension;
  344. PAGED_CODE();
  345. *PRegFlags = WMIREG_FLAG_INSTANCE_PDO;
  346. *PRegistryPath = &Driver.RegPath;
  347. //*PRegistryPath = &SerialGlobals.RegistryPath;
  348. *Pdo = pDevExt->Pdo;
  349. return STATUS_SUCCESS;
  350. }