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.

74 lines
4.1 KiB

  1. This directory contains a sample PnP upper filter driver whose only
  2. purpose is to provide WMI data blocks. Typically driver writers will copy the
  3. sample code into their own driver and make any minor modifications so that the
  4. WMI data blocks are always available when the driver is loaded. Alternatively
  5. WmiSamp can be left as a filter driver if WMI data blocks should only be made
  6. available when the filter driver is loaded. Drivers that link to classpnp.sys
  7. should use a similar library that is part of classpnp.
  8. WMI enabling a driver with the sample code consists of doing 5 things:
  9. 1. Determining what data needs to be provided and organize it into data blocks
  10. that contain related data items. For example packets sent and bytes sent
  11. could be part of a single data block while transmit errors could be part
  12. of a data block that contains other error counts. Determine if the device
  13. needs notifications of when to enable and disable collections in the case
  14. of data blocks that impose a performance hit to collect.
  15. 2. Write a Managed Object Format (.mof) file that describes the data blocks.
  16. In doing this the driver writer will need to run the guidgen tool to
  17. create globally unique guids that are assigned to the data blocks. Guidgen
  18. *MUST* be run so that no two data blocks will have the same guid. Reference
  19. the .bmf file (.bmf files are created when mof files are compiled by the
  20. mofcomp tool) in the driver's .rc file so that the .bmf file data is
  21. included as a resource of the driver's .sys file. WmiLib hardcodes the
  22. resource name as MofResourceName.
  23. 3. Build the GUIDREGINFO structure with the guids for the data blocks defined
  24. in the .mof file. If the device wants to be notified of when to start and
  25. stop collection of a data block the WMIREG_FLAG_EXPENSIVE flag should be
  26. set for the data block in the GUIDREGINFO structure.
  27. 4. Implement the 6 WMI function callback routines and reference them in a
  28. WMI_INFO structure.
  29. The sample code supports does not support more than one instance of a
  30. data block for each device, that is a single device object can only supply
  31. one instance of a data block. Drivers that create multiple device objects
  32. will supply multiple instances for a data block (ie, 1 data block per device
  33. object).
  34. The sample code does not support dynamic instance names. Instance names
  35. are statically defined when device registers with WMI. The PQUERY_WMI_REGINFO
  36. callback allows the device to specify a unique instance name for the device or
  37. the PDO for the device. If the PDO is specified then WMI will translate it to
  38. the device instance name and use that as the unique instance name.
  39. All data blocks registered for a device will use the same instance name.
  40. That is different data blocks for a device object cannot specify different
  41. instance names.
  42. The sample code can be extended to overcome these limitations if the need
  43. arises, however this sample code should be sufficient for most applications.
  44. All WMI callback functions that pass the irp as a parameter are
  45. responsible to call WmiLibCompleteRequest when the request has been satisfied
  46. so that the IRP can be completed. If the WMI callback function cannot
  47. complete the request immediately it can mark the irp pending and return
  48. STATUS_PENDING, but it must call WmiLibComnpleteRequest when the request
  49. actually finishes.
  50. The sample code uses a simple linear search to determine the guid index
  51. for any guid passed. If a driver provides a long list of guids then
  52. WmiLibFindGuid may need to be updated to use a better searching mechanism.
  53. WmiLib counts on a number of fields being present in the device extension
  54. in order for it to process the WMI requests. See Wmilib.h for their
  55. description.
  56. Finally the sample code uses a static global variable to store the
  57. values for the data block. This is not quite correct since each device object
  58. will typically have its own set of data that composes its instance of a
  59. data block. Really the global variable should be part of the device extension,
  60. however I did not want to confuse the device extension with extra stuff.