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.

519 lines
14 KiB

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