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.

510 lines
15 KiB

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