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.

505 lines
16 KiB

  1. /*++ BUILD Version: 0001 // Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. ntpnpapi.h
  5. Abstract:
  6. This module contains the user APIs for NT Plug and Play, along
  7. with any public data structures needed to call these APIs.
  8. This module should be included by including "nt.h".
  9. Author:
  10. Lonny McMichael (lonnym) 02/06/1995
  11. Revision History:
  12. --*/
  13. #ifndef _NTPNPAPI_
  14. #define _NTPNPAPI_
  15. #if _MSC_VER > 1000
  16. #pragma once
  17. #endif
  18. #include <cfg.h>
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. //
  23. // Define the NtPlugPlayControl Classes
  24. //
  25. typedef enum _PLUGPLAY_EVENT_CATEGORY {
  26. HardwareProfileChangeEvent,
  27. TargetDeviceChangeEvent,
  28. DeviceClassChangeEvent,
  29. CustomDeviceEvent,
  30. DeviceInstallEvent,
  31. DeviceArrivalEvent,
  32. PowerEvent,
  33. VetoEvent,
  34. BlockedDriverEvent,
  35. MaxPlugEventCategory
  36. } PLUGPLAY_EVENT_CATEGORY, *PPLUGPLAY_EVENT_CATEGORY;
  37. typedef struct _PLUGPLAY_EVENT_BLOCK {
  38. //
  39. // Common event data
  40. //
  41. GUID EventGuid;
  42. PLUGPLAY_EVENT_CATEGORY EventCategory;
  43. PULONG Result;
  44. ULONG Flags;
  45. ULONG TotalSize;
  46. PVOID DeviceObject;
  47. union {
  48. struct {
  49. GUID ClassGuid;
  50. WCHAR SymbolicLinkName[1];
  51. } DeviceClass;
  52. struct {
  53. WCHAR DeviceIds[1];
  54. } TargetDevice;
  55. struct {
  56. WCHAR DeviceId[1];
  57. } InstallDevice;
  58. struct {
  59. PVOID NotificationStructure;
  60. WCHAR DeviceIds[1];
  61. } CustomNotification;
  62. struct {
  63. PVOID Notification;
  64. } ProfileNotification;
  65. struct {
  66. ULONG NotificationCode;
  67. ULONG NotificationData;
  68. } PowerNotification;
  69. struct {
  70. PNP_VETO_TYPE VetoType;
  71. WCHAR DeviceIdVetoNameBuffer[1]; // DeviceId<NULL>VetoName<NULL><NULL>
  72. } VetoNotification;
  73. struct {
  74. GUID BlockedDriverGuid;
  75. } BlockedDriverNotification;
  76. } u;
  77. } PLUGPLAY_EVENT_BLOCK, *PPLUGPLAY_EVENT_BLOCK;
  78. //
  79. //Define the Target Structure for PNP Notifications
  80. //
  81. typedef struct _PLUGPLAY_NOTIFY_HDR {
  82. USHORT Version;
  83. USHORT Size;
  84. GUID Event;
  85. } PLUGPLAY_NOTIFY_HDR, *PPLUGPLAY_NOTIFY_HDR;
  86. //
  87. // Define the custom notification for the u-mode
  88. // receipient of ReportTargetDeviceChange.
  89. // The following structure header is used for all other (i.e., 3rd-party)
  90. // target device change events. The structure accommodates both a
  91. // variable-length binary data buffer, and a variable-length unicode text
  92. // buffer. The header must indicate where the text buffer begins, so that
  93. // the data can be delivered in the appropriate format (ANSI or Unicode)
  94. // to user-mode recipients (i.e., that have registered for handle-based
  95. // notification via RegisterDeviceNotification).
  96. //
  97. typedef struct _PLUGPLAY_CUSTOM_NOTIFICATION {
  98. PLUGPLAY_NOTIFY_HDR HeaderInfo;
  99. //
  100. // Event-specific data
  101. //
  102. PVOID FileObject; // This field must be set to NULL by callers of
  103. // IoReportTargetDeviceChange. Clients that
  104. // have registered for target device change
  105. // notification on the affected PDO will be
  106. // called with this field set to the file object
  107. // they specified during registration.
  108. //
  109. LONG NameBufferOffset; // offset (in bytes) from beginning of
  110. // CustomDataBuffer where text begins (-1 if none)
  111. //
  112. UCHAR CustomDataBuffer[1]; // variable-length buffer, containing (optionally)
  113. // a binary data at the start of the buffer,
  114. // followed by an optional unicode text buffer
  115. // (word-aligned).
  116. //
  117. } PLUGPLAY_CUSTOM_NOTIFICATION, *PPLUGPLAY_CUSTOM_NOTIFICATION;
  118. //
  119. // Define an Asynchronous Procedure Call for PnP event notification
  120. //
  121. typedef
  122. VOID
  123. (*PPLUGPLAY_APC_ROUTINE) (
  124. IN PVOID PnPContext,
  125. IN NTSTATUS Status,
  126. IN PPLUGPLAY_EVENT_BLOCK PnPEvent
  127. );
  128. //
  129. // Define the NtPlugPlayControl Classes
  130. //
  131. typedef enum _PLUGPLAY_CONTROL_CLASS {
  132. PlugPlayControlEnumerateDevice,
  133. PlugPlayControlRegisterNewDevice,
  134. PlugPlayControlDeregisterDevice,
  135. PlugPlayControlInitializeDevice,
  136. PlugPlayControlStartDevice,
  137. PlugPlayControlUnlockDevice,
  138. PlugPlayControlQueryAndRemoveDevice,
  139. PlugPlayControlUserResponse,
  140. PlugPlayControlGenerateLegacyDevice,
  141. PlugPlayControlGetInterfaceDeviceList,
  142. PlugPlayControlProperty,
  143. PlugPlayControlDeviceClassAssociation,
  144. PlugPlayControlGetRelatedDevice,
  145. PlugPlayControlGetInterfaceDeviceAlias,
  146. PlugPlayControlDeviceStatus,
  147. PlugPlayControlGetDeviceDepth,
  148. PlugPlayControlQueryDeviceRelations,
  149. PlugPlayControlTargetDeviceRelation,
  150. PlugPlayControlQueryConflictList,
  151. PlugPlayControlRetrieveDock,
  152. PlugPlayControlResetDevice,
  153. PlugPlayControlHaltDevice,
  154. PlugPlayControlGetBlockedDriverList,
  155. MaxPlugPlayControl
  156. } PLUGPLAY_CONTROL_CLASS, *PPLUGPLAY_CONTROL_CLASS;
  157. //
  158. // Define a device control structure for
  159. // PlugPlayControlEnumerateDevice
  160. // PlugPlayControlRegisterNewDevice
  161. // PlugPlayControlDeregisterDevice
  162. // PlugPlayControlInitializeDevice
  163. // PlugPlayControlStartDevice
  164. // PlugPlayControlUnlockDevice
  165. // PlugPlayControlRetrieveDock
  166. // PlugPlayControlResetDevice
  167. // PlugPlayControlHaltDevice
  168. //
  169. typedef struct _PLUGPLAY_CONTROL_DEVICE_CONTROL_DATA {
  170. UNICODE_STRING DeviceInstance;
  171. ULONG Flags;
  172. } PLUGPLAY_CONTROL_DEVICE_CONTROL_DATA, *PPLUGPLAY_CONTROL_DEVICE_CONTROL_DATA;
  173. //
  174. // Control flags for PlugPlayControlEnumerateDevice
  175. //
  176. #define PNP_ENUMERATE_DEVICE_ONLY 0x00000001
  177. #define PNP_ENUMERATE_ASYNCHRONOUS 0x00000002
  178. //
  179. // Control flags for PlugPlayControlHaltDevice
  180. //
  181. #define PNP_HALT_ALLOW_NONDISABLEABLE_DEVICES 0x00000001
  182. //
  183. // Define control structure for
  184. // PlugPlayControlQueryAndRemoveDevice
  185. //
  186. typedef struct _PLUGPLAY_CONTROL_QUERY_AND_REMOVE_DATA {
  187. UNICODE_STRING DeviceInstance;
  188. ULONG Flags;
  189. PNP_VETO_TYPE VetoType;
  190. LPWSTR VetoName;
  191. ULONG VetoNameLength; // length in characters
  192. } PLUGPLAY_CONTROL_QUERY_AND_REMOVE_DATA, *PPLUGPLAY_CONTROL_QUERY_AND_REMOVE_DATA;
  193. //
  194. // Values for Flags in PLUGPLAY_CONTROL_QUERY_AND_REMOVE_DATA
  195. //
  196. #define PNP_QUERY_AND_REMOVE_NO_RESTART 0x00000001
  197. #define PNP_QUERY_AND_REMOVE_DISABLE 0x00000002
  198. #define PNP_QUERY_AND_REMOVE_UNINSTALL 0x00000004
  199. #define PNP_QUERY_AND_REMOVE_EJECT_DEVICE 0x00000008
  200. //
  201. // Define control structure for
  202. // PlugPlayControlUserResponse
  203. //
  204. typedef struct _PLUGPLAY_CONTROL_USER_RESPONSE_DATA {
  205. ULONG Response;
  206. PNP_VETO_TYPE VetoType;
  207. LPWSTR VetoName;
  208. ULONG VetoNameLength; // length in characters
  209. } PLUGPLAY_CONTROL_USER_RESPONSE_DATA, *PPLUGPLAY_CONTROL_USER_RESPONSE_DATA;
  210. //
  211. // Define control structure for
  212. // PlugPlayControlGenerateLegacyDevice
  213. //
  214. typedef struct _PLUGPLAY_CONTROL_LEGACY_DEVGEN_DATA {
  215. UNICODE_STRING ServiceName;
  216. LPWSTR DeviceInstance;
  217. ULONG DeviceInstanceLength;
  218. } PLUGPLAY_CONTROL_LEGACY_DEVGEN_DATA, *PPLUGPLAY_CONTROL_LEGACY_DEVGEN_DATA;
  219. //
  220. // Define control structure for
  221. // PlugPlayControlGetInterfaceDeviceList
  222. //
  223. typedef struct _PLUGPLAY_CONTROL_INTERFACE_LIST_DATA {
  224. UNICODE_STRING DeviceInstance;
  225. GUID *InterfaceGuid;
  226. PWSTR InterfaceList;
  227. ULONG InterfaceListSize;
  228. ULONG Flags;
  229. } PLUGPLAY_CONTROL_INTERFACE_LIST_DATA, *PPLUGPLAY_CONTROL_INTERFACE_LIST_DATA;
  230. //
  231. // Define control structure for
  232. // PlugPlayControlProperty
  233. //
  234. typedef struct _PLUGPLAY_CONTROL_PROPERTY_DATA {
  235. UNICODE_STRING DeviceInstance;
  236. ULONG PropertyType;
  237. PVOID Buffer;
  238. ULONG BufferSize;
  239. } PLUGPLAY_CONTROL_PROPERTY_DATA, *PPLUGPLAY_CONTROL_PROPERTY_DATA;
  240. //
  241. // Values for PropertyType in PLUGPLAY_CONTROL_PROPERTY_DATA
  242. //
  243. #define PNP_PROPERTY_PDONAME 0x00000001
  244. #define PNP_PROPERTY_BUSTYPEGUID 0x00000002
  245. #define PNP_PROPERTY_LEGACYBUSTYPE 0x00000003
  246. #define PNP_PROPERTY_BUSNUMBER 0x00000004
  247. #define PNP_PROPERTY_POWER_DATA 0x00000005
  248. #define PNP_PROPERTY_REMOVAL_POLICY 0x00000006
  249. #define PNP_PROPERTY_REMOVAL_POLICY_OVERRIDE 0x00000007
  250. #define PNP_PROPERTY_ADDRESS 0x00000008
  251. #define PNP_PROPERTY_REMOVAL_POLICY_HARDWARE_DEFAULT 0x0000000A
  252. #define PNP_PROPERTY_INSTALL_STATE 0x0000000B
  253. //
  254. // Define control structure for
  255. // PlugPlayControlDeviceClassAssociation
  256. //
  257. typedef struct _PLUGPLAY_CONTROL_CLASS_ASSOCIATION_DATA {
  258. UNICODE_STRING DeviceInstance;
  259. GUID *InterfaceGuid;
  260. UNICODE_STRING Reference; // OPTIONAL
  261. BOOLEAN Register; // TRUE if registering, FALSE if unregistering
  262. LPWSTR SymLink;
  263. ULONG SymLinkLength;
  264. } PLUGPLAY_CONTROL_CLASS_ASSOCIATION_DATA, *PPLUGPLAY_CONTROL_CLASS_ASSOCIATION_DATA;
  265. //
  266. // Define control structure for
  267. // PlugPlayControlGetRelatedDevice
  268. //
  269. typedef struct _PLUGPLAY_CONTROL_RELATED_DEVICE_DATA {
  270. UNICODE_STRING TargetDeviceInstance;
  271. ULONG Relation;
  272. LPWSTR RelatedDeviceInstance;
  273. ULONG RelatedDeviceInstanceLength;
  274. } PLUGPLAY_CONTROL_RELATED_DEVICE_DATA, *PPLUGPLAY_CONTROL_RELATED_DEVICE_DATA;
  275. //
  276. // Values for Relation in PLUGPLAY_CONTROL_RELATED_DEVICE_DATA
  277. //
  278. #define PNP_RELATION_PARENT 0x00000001
  279. #define PNP_RELATION_CHILD 0x00000002
  280. #define PNP_RELATION_SIBLING 0x00000003
  281. //
  282. // Define control structure for
  283. // PlugPlayControlGetInterfaceDeviceAlias
  284. //
  285. typedef struct _PLUGPLAY_CONTROL_INTERFACE_ALIAS_DATA {
  286. UNICODE_STRING SymbolicLinkName;
  287. GUID *AliasClassGuid;
  288. LPWSTR AliasSymbolicLinkName;
  289. ULONG AliasSymbolicLinkNameLength; // length in characters, incl. terminating NULL
  290. } PLUGPLAY_CONTROL_INTERFACE_ALIAS_DATA, *PPLUGPLAY_CONTROL_INTERFACE_ALIAS_DATA;
  291. //
  292. // Define control structure for
  293. // PlugPlayControlGetDeviceStatus
  294. //
  295. typedef struct _PLUGPLAY_CONTROL_STATUS_DATA {
  296. UNICODE_STRING DeviceInstance;
  297. ULONG Operation;
  298. ULONG DeviceStatus;
  299. ULONG DeviceProblem;
  300. } PLUGPLAY_CONTROL_STATUS_DATA, *PPLUGPLAY_CONTROL_STATUS_DATA;
  301. //
  302. // Values for Operation in PLUGPLAY_CONTROL_STATUS_DATA
  303. //
  304. #define PNP_GET_STATUS 0x00000000
  305. #define PNP_SET_STATUS 0x00000001
  306. #define PNP_CLEAR_STATUS 0x00000002
  307. //
  308. // Define control structure for
  309. // PlugPlayControlGetDeviceDepth
  310. //
  311. typedef struct _PLUGPLAY_CONTROL_DEPTH_DATA {
  312. UNICODE_STRING DeviceInstance;
  313. ULONG DeviceDepth;
  314. } PLUGPLAY_CONTROL_DEPTH_DATA, *PPLUGPLAY_CONTROL_DEPTH_DATA;
  315. //
  316. // Define control structure for
  317. // PlugPlayControlQueryDeviceRelations
  318. //
  319. typedef enum _PNP_QUERY_RELATION {
  320. PnpQueryEjectRelations,
  321. PnpQueryRemovalRelations,
  322. PnpQueryPowerRelations,
  323. PnpQueryBusRelations,
  324. MaxPnpQueryRelations
  325. } PNP_QUERY_RELATION, *PPNP_QUERY_RELATION;
  326. typedef struct _PLUGPLAY_CONTROL_DEVICE_RELATIONS_DATA {
  327. UNICODE_STRING DeviceInstance;
  328. PNP_QUERY_RELATION Operation;
  329. ULONG BufferLength; // length in characters, incl. double terminating NULL
  330. LPWSTR Buffer;
  331. } PLUGPLAY_CONTROL_DEVICE_RELATIONS_DATA, *PPLUGPLAY_CONTROL_DEVICE_RELATIONS_DATA;
  332. //
  333. // Define control structure for
  334. // PlugPlayControlTargetDeviceRelation
  335. //
  336. typedef struct _PLUGPLAY_CONTROL_TARGET_RELATION_DATA {
  337. HANDLE UserFileHandle;
  338. NTSTATUS Status;
  339. ULONG DeviceInstanceLen;
  340. LPWSTR DeviceInstance;
  341. } PLUGPLAY_CONTROL_TARGET_RELATION_DATA, *PPLUGPLAY_CONTROL_TARGET_RELATION_DATA;
  342. //
  343. // Define control structure for
  344. // PlugPlayControlQueryInstallList
  345. //
  346. typedef struct _PLUGPLAY_CONTROL_INSTALL_DATA {
  347. ULONG BufferLength; // length in characters, incl. double terminating NULL
  348. LPWSTR Buffer;
  349. } PLUGPLAY_CONTROL_INSTALL_DATA, *PPLUGPLAY_CONTROL_INSTALL_DATA;
  350. //
  351. // Define control structure for
  352. // PlugPlayControlRetrieveDock
  353. //
  354. typedef struct _PLUGPLAY_CONTROL_RETRIEVE_DOCK_DATA {
  355. ULONG DeviceInstanceLength;
  356. LPWSTR DeviceInstance;
  357. } PLUGPLAY_CONTROL_RETRIEVE_DOCK_DATA, *PPLUGPLAY_CONTROL_RETRIEVE_DOCK_DATA;
  358. //
  359. // Structures used by conflict detection
  360. // PlugPlayControlQueryConflictList
  361. //
  362. // PLUGPLAY_CONTROL_CONFLICT_LIST
  363. // is a header, followed by array of PLUGPLAY_CONTROL_CONFLICT_ENTRY,
  364. // followed immediately by PLUGPLAY_CONTROL_CONFLICT_STRINGS
  365. // DeviceType is translated between UserMode and KernelMode
  366. //
  367. typedef struct _PLUGPLAY_CONTROL_CONFLICT_ENTRY {
  368. ULONG DeviceInstance; // offset to NULL-terminated string for device instance in DeviceInstanceStrings
  369. ULONG DeviceFlags; // for passing flags back regarding the device
  370. ULONG ResourceType; // type of range that the conflict is with
  371. ULONGLONG ResourceStart; // start of conflicting address-range
  372. ULONGLONG ResourceEnd; // end of conflicting address-range
  373. ULONG ResourceFlags; // for passing flags back regarding the conflicting resource
  374. } PLUGPLAY_CONTROL_CONFLICT_ENTRY, *PPLUGPLAY_CONTROL_CONFLICT_ENTRY;
  375. #define PNP_CE_LEGACY_DRIVER (0x00000001) // DeviceFlags: DeviceInstance reports back legacy driver name
  376. #define PNP_CE_ROOT_OWNED (0x00000002) // DeviceFlags: Root owned device
  377. #define PNP_CE_TRANSLATE_FAILED (0x00000004) // DeviceFlags: Translation of resource failed, resource range not available for use
  378. typedef struct _PLUGPLAY_CONTROL_CONFLICT_STRINGS {
  379. ULONG NullDeviceInstance; // must be (ULONG)(-1) - exists immediately after ConflictsListed * PLUGPLAY_CONTROL_CONFLICT_ENTRY
  380. WCHAR DeviceInstanceStrings[1]; // first device instance string
  381. } PLUGPLAY_CONTROL_CONFLICT_STRINGS, *PPLUGPLAY_CONTROL_CONFLICT_STRINGS;
  382. typedef struct _PLUGPLAY_CONTROL_CONFLICT_LIST {
  383. ULONG Reserved1; // used by Win2k CfgMgr32
  384. ULONG Reserved2; // used by Win2k CfgMgr32
  385. ULONG ConflictsCounted; // number of conflicts that have been determined
  386. ULONG ConflictsListed; // number of conflicts in this list
  387. ULONG RequiredBufferSize; // filled with buffer size required to report all conflicts
  388. PLUGPLAY_CONTROL_CONFLICT_ENTRY ConflictEntry[1]; // each listed entry
  389. } PLUGPLAY_CONTROL_CONFLICT_LIST, *PPLUGPLAY_CONTROL_CONFLICT_LIST;
  390. typedef struct _PLUGPLAY_CONTROL_CONFLICT_DATA {
  391. UNICODE_STRING DeviceInstance; // device we're querying conflicts for
  392. PCM_RESOURCE_LIST ResourceList; // resource list containing a single resource
  393. ULONG ResourceListSize; // size of resource-list buffer
  394. PPLUGPLAY_CONTROL_CONFLICT_LIST ConflictBuffer; // buffer for return list
  395. ULONG ConflictBufferSize; // length of buffer
  396. ULONG Flags; // Incoming flags
  397. NTSTATUS Status; // return status
  398. } PLUGPLAY_CONTROL_CONFLICT_DATA, *PPLUGPLAY_CONTROL_CONFLICT_DATA;
  399. //
  400. // Define control structure for
  401. // PlugPlayControlGetBlockedDriverList
  402. //
  403. typedef struct _PLUGPLAY_CONTROL_BLOCKED_DRIVER_DATA {
  404. ULONG Flags;
  405. ULONG BufferLength; // size of buffer in bytes
  406. PVOID Buffer;
  407. } PLUGPLAY_CONTROL_BLOCKED_DRIVER_DATA, *PPLUGPLAY_CONTROL_BLOCKED_DRIVER_DATA;
  408. //
  409. // Plug and Play user APIs
  410. //
  411. NTSYSCALLAPI
  412. NTSTATUS
  413. NTAPI
  414. NtGetPlugPlayEvent(
  415. IN HANDLE EventHandle,
  416. IN PVOID Context OPTIONAL,
  417. OUT PPLUGPLAY_EVENT_BLOCK EventBlock,
  418. IN ULONG EventBufferLength
  419. );
  420. NTSYSCALLAPI
  421. NTSTATUS
  422. NTAPI
  423. NtPlugPlayControl(
  424. IN PLUGPLAY_CONTROL_CLASS PnPControlClass,
  425. IN OUT PVOID PnPControlData,
  426. IN ULONG PnPControlDataLength
  427. );
  428. #ifdef __cplusplus
  429. }
  430. #endif
  431. #endif // _NTPNPAPI_