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.

576 lines
14 KiB

  1. /*++
  2. Copyright (c) 2002 Microsoft Corporation
  3. Module Name:
  4. bdlint.h
  5. Abstract:
  6. This module contains all of the internal efinitions for the BDLmetric device
  7. driver library.
  8. Environment:
  9. Kernel mode only.
  10. Notes:
  11. Revision History:
  12. - Created May 2002 by Reid Kuhn
  13. --*/
  14. #ifndef _BDLINT_
  15. #define _BDLINT_
  16. #include "bdl.h"
  17. #define BDL_ULONG_TAG ' LDB'
  18. #define BDLI_ULONG_TAG 'ILDB'
  19. #define BDL_LIST_ULONG_TAG 'LLDB'
  20. #define BIO_CONTROL_FLAG_ASYNCHRONOUS 0x00000001
  21. #define BIO_CONTROL_FLAG_READONLY 0x00000002
  22. #define CONTROL_CHANGE_POOL_SIZE 20
  23. #define SIZEOF_DOCHANNEL_INPUTBUFFER ((4 * sizeof(ULONG)) + sizeof(HANDLE) + sizeof(BDD_HANDLE))
  24. #define SIZEOF_GETCONTROL_INPUTBUFFER (sizeof(ULONG) * 3)
  25. #define SIZEOF_SETCONTROL_INPUTBUFFER (sizeof(ULONG) * 4)
  26. #define SIZEOF_CREATEHANDLEFROMDATA_INPUTBUFFER (sizeof(GUID) + (sizeof(ULONG) * 2))
  27. #define SIZEOF_CLOSEHANDLE_INPUTBUFFER (sizeof(BDD_HANDLE))
  28. #define SIZEOF_GETDATAFROMHANDLE_INPUTBUFFER (sizeof(BDD_HANDLE) + sizeof(ULONG))
  29. #define SIZEOF_REGISTERNOTIFY_INPUTBUFFER (sizeof(ULONG) * 4)
  30. #define SIZEOF_GETDEVICEINFO_OUTPUTBUFFER (sizeof(WCHAR[256]) + (sizeof(ULONG) * 6))
  31. #define SIZEOF_DOCHANNEL_OUTPUTBUFFER (sizeof(ULONG) + sizeof(BDD_HANDLE))
  32. #define SIZEOF_GETCONTROL_OUTPUTBUFFER (sizeof(ULONG))
  33. #define SIZEOF_CREATEHANDLEFROMDATA_OUTPUTBUFFER (sizeof(BDD_HANDLE))
  34. #define SIZEOF_GETDATAFROMHANDLE_OUTPUTBUFFER (sizeof(ULONG) * 2)
  35. #define SIZEOF_GETNOTIFICATION_OUTPUTBUFFER (sizeof(ULONG) * 4)
  36. NTSTATUS
  37. DriverEntry
  38. (
  39. IN PDRIVER_OBJECT DriverObject,
  40. IN PUNICODE_STRING RegistryPath
  41. );
  42. NTSTATUS
  43. BDLAddDevice
  44. (
  45. IN PDRIVER_OBJECT DriverObject,
  46. IN PDEVICE_OBJECT PhysicalDeviceObject
  47. );
  48. VOID
  49. BDLDriverUnload
  50. (
  51. IN PDRIVER_OBJECT pDriverObject
  52. );
  53. #pragma alloc_text(INIT, DriverEntry)
  54. #pragma alloc_text(PAGEABLE, BDLAddDevice)
  55. #pragma alloc_text(PAGEABLE, BDLDriverUnload)
  56. typedef struct _BDL_CHANNEL_SOURCE_LIST
  57. {
  58. GUID FormatGUID;
  59. ULONG MinSources;
  60. ULONG MaxSources;
  61. ULONG Flags;
  62. } BDL_CHANNEL_SOURCE_LIST;
  63. typedef struct _BDL_CONTROL
  64. {
  65. ULONG ControlId;
  66. INT32 NumericMinimum;
  67. INT32 NumericMaximum;
  68. ULONG NumericGranularity;
  69. ULONG NumericDivisor;
  70. ULONG Flags;
  71. } BDL_CONTROL;
  72. typedef struct _BDL_PRODUCT
  73. {
  74. ULONG Flags;
  75. } BDL_PRODUCT;
  76. typedef struct _BDL_CHANNEL
  77. {
  78. ULONG ChannelId;
  79. ULONG NumControls;
  80. BDL_CONTROL *rgControls;
  81. BOOLEAN fCancelable;
  82. ULONG NumSourceLists;
  83. BDL_CHANNEL_SOURCE_LIST *rgSourceLists;
  84. ULONG NumProducts;
  85. BDL_PRODUCT *rgProducts;
  86. } BDL_CHANNEL;
  87. typedef struct _BDL_COMPONENT
  88. {
  89. ULONG ComponentId;
  90. ULONG NumControls;
  91. BDL_CONTROL *rgControls;
  92. ULONG NumChannels;
  93. BDL_CHANNEL *rgChannels;
  94. } BDL_COMPONENT;
  95. typedef struct _BDL_DEVICE_CAPABILITIES
  96. {
  97. ULONG NumControls;
  98. BDL_CONTROL *rgControls;
  99. ULONG NumComponents;
  100. BDL_COMPONENT *rgComponents;
  101. } BDL_DEVICE_CAPABILITIES;
  102. typedef struct _BDL_IOCTL_CONTROL_CHANGE_ITEM
  103. {
  104. ULONG ComponentId;
  105. ULONG ChannelId;
  106. ULONG ControlId;
  107. ULONG Value;
  108. LIST_ENTRY ListEntry;
  109. } BDL_IOCTL_CONTROL_CHANGE_ITEM;
  110. typedef struct _BDL_ISR_CONTROL_CHANGE_ITEM
  111. {
  112. ULONG ComponentId;
  113. ULONG ChannelId;
  114. ULONG ControlId;
  115. ULONG Value;
  116. LIST_ENTRY ListEntry;
  117. BOOLEAN fUsed;
  118. } BDL_ISR_CONTROL_CHANGE_ITEM;
  119. typedef struct _BDL_CONTROL_CHANGE_REGISTRATION
  120. {
  121. ULONG ComponentId;
  122. ULONG ChannelId;
  123. ULONG ControlId;
  124. LIST_ENTRY ListEntry;
  125. } BDL_CONTROL_CHANGE_REGISTRATION;
  126. typedef struct _BDL_CONTROL_CHANGE_STRUCT
  127. {
  128. //
  129. // This lock protects all the members of this structure that
  130. // are accessed at ISR IRQL (DpcObject, ISRControlChangeQueue,
  131. // ISRirql, rgControlChangePool, StartTime, and NumCalls)
  132. //
  133. KSPIN_LOCK ISRControlChangeLock;
  134. //
  135. // DPC object used for DPC request
  136. //
  137. KDPC DpcObject;
  138. //
  139. // This is the list that holds the control changes which are
  140. // generated via ISR calls and the lock which protects it
  141. //
  142. LIST_ENTRY ISRControlChangeQueue;
  143. KIRQL ISRirql;
  144. //
  145. // Pre-allocated pool of items used in the ISRControlChangeQueue
  146. //
  147. BDL_ISR_CONTROL_CHANGE_ITEM rgControlChangePool[CONTROL_CHANGE_POOL_SIZE];
  148. //
  149. // These values are used to ensure the BDD doesn't call bdliControlChange
  150. // too often
  151. //
  152. LARGE_INTEGER StartTime;
  153. ULONG NumCalls;
  154. //
  155. // This lock protects all the members of this structure that
  156. // are accessed at DISPATCH IRQL (IOCTLControlChangeQueue, pIrp, and
  157. // ControlChangeRegistrationList)
  158. //
  159. KSPIN_LOCK ControlChangeLock;
  160. //
  161. // This is the list that holds the control changes which are
  162. // returned when the BDD_IOCTL_GETNOTIFICATION call is made
  163. //
  164. LIST_ENTRY IOCTLControlChangeQueue;
  165. //
  166. // This is the single outstanding BDD_IOCTL_GETNOTIFICATION IRP
  167. // used to retrieve asynchronous control changes.
  168. //
  169. PIRP pIrp;
  170. //
  171. // This is the list of registered controls
  172. //
  173. LIST_ENTRY ControlChangeRegistrationList;
  174. } BDL_CONTROL_CHANGE_STRUCT;
  175. typedef struct LIST_NODE_
  176. {
  177. void *pNext;
  178. BDD_DATA_HANDLE handle;
  179. } LIST_NODE, *PLIST_NODE;
  180. typedef struct HANDLELIST_
  181. {
  182. LIST_NODE *pHead;
  183. LIST_NODE *pTail;
  184. ULONG NumHandles;
  185. } HANDLELIST, *PHANDLELIST;
  186. typedef struct _BDL_DRIVER_EXTENSION
  187. {
  188. BDLI_BDDIFUNCTIONS bddiFunctions;
  189. BDLI_BDSIFUNCTIONS bdsiFunctions;
  190. } BDL_DRIVER_EXTENSION, *PBDL_DRIVER_EXTENSION;
  191. typedef struct _BDL_INTERNAL_DEVICE_EXTENSION
  192. {
  193. //
  194. // This is the portion of the BDL extension struct that
  195. // BDD writers have access to
  196. //
  197. BDL_DEVICEEXT BdlExtenstion;
  198. //
  199. // The driver object for this device
  200. //
  201. PBDL_DRIVER_EXTENSION pDriverExtension;
  202. //
  203. // Symbolic Link Name, created when the interface is registered
  204. //
  205. UNICODE_STRING SymbolicLinkName;
  206. //
  207. // mutual exclusion for this struct
  208. //
  209. KSPIN_LOCK SpinLock;
  210. //
  211. // Used to signal that the device is able to process requests
  212. //
  213. KEVENT DeviceStartedEvent;
  214. //
  215. // The current number of io-requests
  216. //
  217. ULONG IoCount;
  218. //
  219. // remove lock
  220. //
  221. IO_REMOVE_LOCK RemoveLock;
  222. //
  223. // Used to signal wether the device is open or not
  224. //
  225. LONG DeviceOpen;
  226. //
  227. // The BDL device specific capabilities
  228. //
  229. BDL_DEVICE_CAPABILITIES DeviceCapabilities;
  230. //
  231. // Holds the following:
  232. // 1) queued control changes generated from ISR calls
  233. // 2) queue of items to be returned via IOCTL calls
  234. // 3) list of controls which have been registered
  235. //
  236. BDL_CONTROL_CHANGE_STRUCT ControlChangeStruct;
  237. //
  238. // The current power state of the device
  239. //
  240. BDSI_POWERSTATE CurrentPowerState;
  241. //
  242. // This indicates whether BDLPnPStart() completed succesfully
  243. //
  244. BOOLEAN fStartSucceeded;
  245. //
  246. // This indicates that there has been a surprise removal
  247. //
  248. BOOLEAN fDeviceRemoved;
  249. //
  250. // This is the list of outstanding BDD Handles
  251. //
  252. KSPIN_LOCK HandleListLock;
  253. HANDLELIST HandleList;
  254. //
  255. // Device info
  256. //
  257. WCHAR wszSerialNumber[256];
  258. ULONG HWVersionMajor;
  259. ULONG HWVersionMinor;
  260. ULONG HWBuildNumber;
  261. ULONG BDDVersionMajor;
  262. ULONG BDDVersionMinor;
  263. ULONG BDDBuildNumber;
  264. } BDL_INTERNAL_DEVICE_EXTENSION, *PBDL_INTERNAL_DEVICE_EXTENSION;
  265. //
  266. // This function retrieves the device capabilities from the registry.
  267. //
  268. NTSTATUS
  269. BDLGetDeviceCapabilities
  270. (
  271. PDEVICE_OBJECT pPhysicalDeviceObject,
  272. PBDL_INTERNAL_DEVICE_EXTENSION pBDLExtension
  273. );
  274. //
  275. // This function free's up the memory allocated by BDLGetDevicesCapabilities
  276. //
  277. VOID
  278. BDLCleanupDeviceCapabilities
  279. (
  280. PBDL_INTERNAL_DEVICE_EXTENSION pBDLExtension
  281. );
  282. //
  283. // This function is used to call the lower lever driver when more processing
  284. // is required after the lower level driver is done with the IRP.
  285. //
  286. NTSTATUS
  287. BDLCallLowerLevelDriverAndWait
  288. (
  289. IN PDEVICE_OBJECT pAttachedDeviceObject,
  290. IN PIRP pIrp
  291. );
  292. //
  293. // These functions are used to manage the devices handle list
  294. //
  295. VOID
  296. BDLLockHandleList
  297. (
  298. IN PBDL_INTERNAL_DEVICE_EXTENSION pBDLExtension,
  299. OUT KIRQL *pirql
  300. );
  301. VOID
  302. BDLReleaseHandleList
  303. (
  304. IN PBDL_INTERNAL_DEVICE_EXTENSION pBDLExtension,
  305. IN KIRQL irql
  306. );
  307. VOID
  308. BDLInitializeHandleList
  309. (
  310. IN HANDLELIST *pList
  311. );
  312. NTSTATUS
  313. BDLAddHandleToList
  314. (
  315. IN HANDLELIST *pList,
  316. IN BDD_DATA_HANDLE handle
  317. );
  318. BOOLEAN
  319. BDLRemoveHandleFromList
  320. (
  321. IN HANDLELIST *pList,
  322. IN BDD_DATA_HANDLE handle
  323. );
  324. BOOLEAN
  325. BDLGetFirstHandle
  326. (
  327. IN HANDLELIST *pList,
  328. OUT BDD_DATA_HANDLE *phandle
  329. );
  330. BOOLEAN
  331. BDLValidateHandleIsInList
  332. (
  333. IN HANDLELIST *pList,
  334. IN BDD_DATA_HANDLE handle
  335. );
  336. //
  337. // All these functions are used for supporting BDL IOCTL calls
  338. //
  339. NTSTATUS
  340. BDLIOCTL_Startup
  341. (
  342. IN PBDL_INTERNAL_DEVICE_EXTENSION pBDLExtension,
  343. IN ULONG InpuBufferLength,
  344. IN ULONG OutputBufferLength,
  345. IN PVOID pBuffer,
  346. OUT ULONG *pOutputBufferUsed
  347. );
  348. NTSTATUS
  349. BDLIOCTL_Shutdown
  350. (
  351. IN PBDL_INTERNAL_DEVICE_EXTENSION pBDLExtension,
  352. IN ULONG InpuBufferLength,
  353. IN ULONG OutputBufferLength,
  354. IN PVOID pBuffer,
  355. OUT ULONG *pOutputBufferUsed
  356. );
  357. NTSTATUS
  358. BDLIOCTL_GetDeviceInfo
  359. (
  360. IN PBDL_INTERNAL_DEVICE_EXTENSION pBDLExtension,
  361. IN ULONG InpuBufferLength,
  362. IN ULONG OutputBufferLength,
  363. IN PVOID pBuffer,
  364. OUT ULONG *pOutputBufferUsed
  365. );
  366. NTSTATUS
  367. BDLIOCTL_DoChannel
  368. (
  369. IN PBDL_INTERNAL_DEVICE_EXTENSION pBDLExtension,
  370. IN ULONG InpuBufferLength,
  371. IN ULONG OutputBufferLength,
  372. IN PVOID pBuffer,
  373. OUT ULONG *pOutputBufferUsed
  374. );
  375. NTSTATUS
  376. BDLIOCTL_GetControl
  377. (
  378. IN PBDL_INTERNAL_DEVICE_EXTENSION pBDLExtension,
  379. IN ULONG InpuBufferLength,
  380. IN ULONG OutputBufferLength,
  381. IN PVOID pBuffer,
  382. OUT ULONG *pOutputBufferUsed
  383. );
  384. NTSTATUS
  385. BDLIOCTL_SetControl
  386. (
  387. IN PBDL_INTERNAL_DEVICE_EXTENSION pBDLExtension,
  388. IN ULONG InpuBufferLength,
  389. IN ULONG OutputBufferLength,
  390. IN PVOID pBuffer,
  391. OUT ULONG *pOutputBufferUsed
  392. );
  393. NTSTATUS
  394. BDLIOCTL_CreateHandleFromData
  395. (
  396. IN PBDL_INTERNAL_DEVICE_EXTENSION pBDLExtension,
  397. IN ULONG InpuBufferLength,
  398. IN ULONG OutputBufferLength,
  399. IN PVOID pBuffer,
  400. OUT ULONG *pOutputBufferUsed
  401. );
  402. NTSTATUS
  403. BDLIOCTL_CloseHandle
  404. (
  405. IN PBDL_INTERNAL_DEVICE_EXTENSION pBDLExtension,
  406. IN ULONG InpuBufferLength,
  407. IN ULONG OutputBufferLength,
  408. IN PVOID pBuffer,
  409. OUT ULONG *pOutputBufferUsed
  410. );
  411. NTSTATUS
  412. BDLIOCTL_GetDataFromHandle
  413. (
  414. IN PBDL_INTERNAL_DEVICE_EXTENSION pBDLExtension,
  415. IN ULONG InpuBufferLength,
  416. IN ULONG OutputBufferLength,
  417. IN PVOID pBuffer,
  418. OUT ULONG *pOutputBufferUsed
  419. );
  420. NTSTATUS
  421. BDLIOCTL_RegisterNotify
  422. (
  423. IN PBDL_INTERNAL_DEVICE_EXTENSION pBDLExtension,
  424. IN ULONG InpuBufferLength,
  425. IN ULONG OutputBufferLength,
  426. IN PVOID pBuffer,
  427. OUT ULONG *pOutputBufferUsed
  428. );
  429. NTSTATUS
  430. BDLIOCTL_GetNotification
  431. (
  432. IN PBDL_INTERNAL_DEVICE_EXTENSION pBDLExtension,
  433. IN ULONG InpuBufferLength,
  434. IN ULONG OutputBufferLength,
  435. IN PVOID pBuffer,
  436. IN PIRP pIrp,
  437. OUT ULONG *pOutputBufferUsed
  438. );
  439. VOID
  440. BDLCancelGetNotificationIRP
  441. (
  442. IN PBDL_INTERNAL_DEVICE_EXTENSION pBDLExtension
  443. );
  444. VOID
  445. BDLCleanupNotificationStruct
  446. (
  447. IN BDL_INTERNAL_DEVICE_EXTENSION *pBDLExtension
  448. );
  449. VOID
  450. BDLCleanupDataHandles
  451. (
  452. IN BDL_INTERNAL_DEVICE_EXTENSION *pBDLExtension
  453. );
  454. #endif