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.

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