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.

648 lines
16 KiB

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