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.

578 lines
18 KiB

  1. /*++
  2. Copyright (c) 2002 Microsoft Corporation
  3. Module Name:
  4. bdl.h
  5. Abstract:
  6. This module contains all definitions for the biometric device driver library.
  7. Environment:
  8. Kernel mode only.
  9. Notes:
  10. Revision History:
  11. - Created May 2002 by Reid Kuhn
  12. --*/
  13. #ifndef _BDL_
  14. #define _BDL_
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include <initguid.h>
  19. DEFINE_GUID(BiometricDeviceGuid, 0x83970EB2, 0x86F6, 0x4F3A, 0xB5,0xF4,0xC6,0x05,0xAA,0x49,0x63,0xE1);
  20. typedef PVOID BDD_DATA_HANDLE;
  21. #define BIO_BUFFER_TOO_SMALL 1L
  22. #define BIO_ITEMTYPE_HANDLE 0x00000001
  23. #define BIO_ITEMTYPE_BLOCK 0x00000002
  24. //
  25. ///////////////////////////////////////////////////////////////////////////////
  26. //
  27. // Device Action IOCTLs
  28. //
  29. #define BIO_CTL_CODE(code) CTL_CODE(FILE_DEVICE_BIOMETRIC, \
  30. (code), \
  31. METHOD_BUFFERED, \
  32. FILE_ANY_ACCESS)
  33. #define BDD_IOCTL_STARTUP BIO_CTL_CODE(1)
  34. #define BDD_IOCTL_SHUTDOWN BIO_CTL_CODE(2)
  35. #define BDD_IOCTL_GETDEVICEINFO BIO_CTL_CODE(3)
  36. #define BDD_IOCTL_DOCHANNEL BIO_CTL_CODE(4)
  37. #define BDD_IOCTL_GETCONTROL BIO_CTL_CODE(5)
  38. #define BDD_IOCTL_SETCONTROL BIO_CTL_CODE(6)
  39. #define BDD_IOCTL_CREATEHANDLEFROMDATA BIO_CTL_CODE(7)
  40. #define BDD_IOCTL_CLOSEHANDLE BIO_CTL_CODE(8)
  41. #define BDD_IOCTL_GETDATAFROMHANDLE BIO_CTL_CODE(9)
  42. #define BDD_IOCTL_REGISTERNOTIFY BIO_CTL_CODE(10)
  43. #define BDD_IOCTL_GETNOTIFICATION BIO_CTL_CODE(11)
  44. /////////////////////////////////////////////////////////////////////////////////////////
  45. //
  46. // These structures and typedefs are used when making BDSI calls
  47. //
  48. typedef struct _BDSI_ADDDEVICE
  49. {
  50. IN ULONG Size;
  51. IN PDEVICE_OBJECT pPhysicalDeviceObject;
  52. OUT PVOID pvBDDExtension;
  53. } BDSI_ADDDEVICE, *PBDSI_ADDDEVICE;
  54. typedef struct _BDSI_INITIALIZERESOURCES
  55. {
  56. IN ULONG Size;
  57. IN PCM_RESOURCE_LIST pAllocatedResources;
  58. IN PCM_RESOURCE_LIST pAllocatedResourcesTranslated;
  59. OUT WCHAR wszSerialNumber[256];
  60. OUT ULONG HWVersionMajor;
  61. OUT ULONG HWVersionMinor;
  62. OUT ULONG HWBuildNumber;
  63. OUT ULONG BDDVersionMajor;
  64. OUT ULONG BDDVersionMinor;
  65. OUT ULONG BDDBuildNumber;
  66. } BDSI_INITIALIZERESOURCES, *PBDSI_INITIALIZERESOURCES;
  67. typedef struct _BDSI_DRIVERUNLOAD
  68. {
  69. IN ULONG Size;
  70. IN PIRP pIrp;
  71. } BDSI_DRIVERUNLOAD, *PBDSI_DRIVERUNLOAD;
  72. typedef enum _BDSI_POWERSTATE
  73. {
  74. Off = 0,
  75. Low = 1,
  76. On = 2
  77. }BDSI_POWERSTATE, *PBDSI_POWERSTATE;
  78. typedef struct _BDSI_SETPOWERSTATE
  79. {
  80. IN ULONG Size;
  81. IN BDSI_POWERSTATE PowerState;
  82. } BDSI_SETPOWERSTATE, *PBDSI_SETPOWERSTATE;
  83. /////////////////////////////////////////////////////////////////////////////////////////
  84. //
  85. // These structures and typedefs are used when making BDDI calls
  86. //
  87. typedef struct _BDDI_ITEM
  88. {
  89. ULONG Type;
  90. union _BDDI_ITEM_DATA
  91. {
  92. BDD_DATA_HANDLE Handle;
  93. struct _BDDI_ITEM_DATA_BLOCK
  94. {
  95. ULONG cBuffer;
  96. PUCHAR pBuffer;
  97. } Block;
  98. } Data;
  99. } BDDI_ITEM, *PBDDI_ITEM;
  100. typedef PBDDI_ITEM BDD_HANDLE;
  101. typedef struct _BDDI_SOURCELIST
  102. {
  103. ULONG NumSources;
  104. PBDDI_ITEM *rgpSources;
  105. } BDDI_SOURCELIST, *PBDDI_SOURCELIST;
  106. typedef struct _BDDI_PARAMS_REGISTERNOTIFY
  107. {
  108. IN ULONG Size;
  109. IN BOOLEAN fRegister;
  110. IN ULONG ComponentId;
  111. IN ULONG ChannelId;
  112. IN ULONG ControlId;
  113. } BDDI_PARAMS_REGISTERNOTIFY, *PBDDI_PARAMS_REGISTERNOTIFY;
  114. typedef struct _BDDI_PARAMS_DOCHANNEL
  115. {
  116. IN ULONG Size;
  117. IN ULONG ComponentId;
  118. IN ULONG ChannelId;
  119. IN PKEVENT CancelEvent;
  120. IN BDDI_SOURCELIST *rgSourceLists;
  121. IN OUT BDD_DATA_HANDLE hStateData;
  122. OUT PBDDI_ITEM *rgpProducts;
  123. OUT ULONG BIOReturnCode;
  124. } BDDI_PARAMS_DOCHANNEL, *PBDDI_PARAMS_DOCHANNEL;
  125. typedef struct _BDDI_PARAMS_GETCONTROL
  126. {
  127. IN ULONG Size;
  128. IN ULONG ComponentId;
  129. IN ULONG ChannelId;
  130. IN ULONG ControlId;
  131. OUT INT32 Value;
  132. OUT WCHAR wszString[256];
  133. } BDDI_PARAMS_GETCONTROL, *PBDDI_PARAMS_GETCONTROL;
  134. typedef struct _BDDI_PARAMS_SETCONTROL
  135. {
  136. IN ULONG Size;
  137. IN ULONG ComponentId;
  138. IN ULONG ChannelId;
  139. IN ULONG ControlId;
  140. IN INT32 Value;
  141. IN WCHAR wszString[256];
  142. } BDDI_PARAMS_SETCONTROL, *PBDDI_PARAMS_SETCONTROL;
  143. typedef struct _BDDI_PARAMS_CREATEHANDLE_FROMDATA
  144. {
  145. IN ULONG Size;
  146. IN GUID guidFormatId;
  147. IN ULONG cBuffer;
  148. IN PUCHAR pBuffer;
  149. OUT BDD_DATA_HANDLE hData;
  150. } BDDI_PARAMS_CREATEHANDLE_FROMDATA, *PBDDI_PARAMS_CREATEHANDLE_FROMDATA;
  151. typedef struct _BDDI_PARAMS_CLOSEHANDLE
  152. {
  153. IN ULONG Size;
  154. IN BDD_DATA_HANDLE hData;
  155. } BDDI_PARAMS_CLOSEHANDLE, *PBDDI_PARAMS_CLOSEHANDLE;
  156. typedef struct _BDDI_PARAMS_GETDATA_FROMHANDLE
  157. {
  158. IN ULONG Size;
  159. IN BDD_DATA_HANDLE hData;
  160. IN OUT ULONG cBuffer;
  161. IN OUT PUCHAR pBuffer;
  162. OUT ULONG BIOReturnCode;
  163. } BDDI_PARAMS_GETDATA_FROMHANDLE, *PBDDI_PARAMS_GETDATA_FROMHANDLE;
  164. /////////////////////////////////////////////////////////////////////////////////////////
  165. //
  166. // These strucutres and typedefs are used to pass pointers to the BDD's BDDI functions
  167. // when calling bdliInitialize
  168. //
  169. typedef NTSTATUS FN_BDDI_REGISTERNOTIFY (PBDL_DEVICEEXT, PBDDI_PARAMS_REGISTERNOTIFY);
  170. typedef FN_BDDI_REGISTERNOTIFY *PFN_BDDI_REGISTERNOTIFY;
  171. typedef NTSTATUS FN_BDDI_DOCHANNEL (PBDL_DEVICEEXT, PBDDI_PARAMS_DOCHANNEL);
  172. typedef FN_BDDI_DOCHANNEL *PFN_BDDI_DOCHANNEL;
  173. typedef NTSTATUS FN_BDDI_GETCONTROL (PBDL_DEVICEEXT, PBDDI_PARAMS_GETCONTROL);
  174. typedef FN_BDDI_GETCONTROL *PFN_BDDI_GETCONTROL;
  175. typedef NTSTATUS FN_BDDI_SETCONTROL (PBDL_DEVICEEXT, PBDDI_PARAMS_SETCONTROL);
  176. typedef FN_BDDI_SETCONTROL *PFN_BDDI_SETCONTROL;
  177. typedef NTSTATUS FN_BDDI_CREATEHANDLE_FROMDATA (PBDL_DEVICEEXT, PBDDI_PARAMS_CREATEHANDLE_FROMDATA);
  178. typedef FN_BDDI_CREATEHANDLE_FROMDATA *PFN_BDDI_CREATEHANDLE_FROMDATA;
  179. typedef NTSTATUS FN_BDDI_CLOSEHANDLE (PBDL_DEVICEEXT, PBDDI_PARAMS_CLOSEHANDLE);
  180. typedef FN_BDDI_CLOSEHANDLE *PFN_BDDI_CLOSEHANDLE;
  181. typedef NTSTATUS FN_BDDI_GETDATA_FROMHANDLE (PBDL_DEVICEEXT, PBDDI_PARAMS_GETDATA_FROMHANDLE);
  182. typedef FN_BDDI_GETDATA_FROMHANDLE *PFN_BDDI_GETDATA_FROMHANDLE;
  183. typedef struct _BDLI_BDDIFUNCTIONS
  184. {
  185. ULONG Size;
  186. PFN_BDDI_REGISTERNOTIFY pfbddiRegisterNotify;
  187. PFN_BDDI_DOCHANNEL pfbddiDoChannel;
  188. PFN_BDDI_GETCONTROL pfbddiGetControl;
  189. PFN_BDDI_SETCONTROL pfbddiSetControl;
  190. PFN_BDDI_CREATEHANDLE_FROMDATA pfbddiCreateHandleFromData;
  191. PFN_BDDI_CLOSEHANDLE pfbddiCloseHandle;
  192. PFN_BDDI_GETDATA_FROMHANDLE pfbddiGetDataFromHandle;
  193. } BDLI_BDDIFUNCTIONS, *PBDLI_BDDIFUNCTIONS;
  194. /////////////////////////////////////////////////////////////////////////////////////////
  195. //
  196. // These strucutres and typedefs are used to pass pointers to the BDD's BDSI functions
  197. // when calling bdliInitialize
  198. //
  199. typedef NTSTATUS FN_BDSI_ADDDEVICE (PBDL_DEVICEEXT, PBDSI_ADDDEVICE);
  200. typedef FN_BDSI_ADDDEVICE *PFN_BDSI_ADDDEVICE;
  201. typedef NTSTATUS FN_BDSI_REMOVEDEVICE (PBDL_DEVICEEXT);
  202. typedef FN_BDSI_REMOVEDEVICE *PFN_BDSI_REMOVEDEVICE;
  203. typedef NTSTATUS FN_BDSI_INITIALIZERESOURCES (PBDL_DEVICEEXT, PBDSI_INITIALIZERESOURCES);
  204. typedef FN_BDSI_INITIALIZERESOURCES *PFN_BDSI_INITIALIZERESOURCES;
  205. typedef NTSTATUS FN_BDSI_RELEASERESOURCES (PBDL_DEVICEEXT);
  206. typedef FN_BDSI_RELEASERESOURCES *PFN_BDSI_RELEASERESOURCES;
  207. typedef NTSTATUS FN_BDSI_STARTUP (PBDL_DEVICEEXT);
  208. typedef FN_BDSI_STARTUP *PFN_BDSI_STARTUP;
  209. typedef NTSTATUS FN_BDSI_SHUTDOWN (PBDL_DEVICEEXT);
  210. typedef FN_BDSI_SHUTDOWN *PFN_BDSI_SHUTDOWN;
  211. typedef NTSTATUS FN_BDSI_DRIVERUNLOAD (PBDL_DEVICEEXT, PBDSI_DRIVERUNLOAD);
  212. typedef FN_BDSI_DRIVERUNLOAD *PFN_BDSI_DRIVERUNLOAD;
  213. typedef NTSTATUS FN_BDSI_SETPOWERSTATE (PBDL_DEVICEEXT, PBDSI_SETPOWERSTATE);
  214. typedef FN_BDSI_SETPOWERSTATE *PFN_BDSI_SETPOWERSTATE;
  215. typedef struct _BDLI_BDSIFUNCTIONS
  216. {
  217. ULONG Size;
  218. PFN_BDSI_ADDDEVICE pfbdsiAddDevice;
  219. PFN_BDSI_REMOVEDEVICE pfbdsiRemoveDevice;
  220. PFN_BDSI_INITIALIZERESOURCES pfbdsiInitializeResources;
  221. PFN_BDSI_RELEASERESOURCES pfbdsiReleaseResources;
  222. PFN_BDSI_STARTUP pfbdsiStartup;
  223. PFN_BDSI_SHUTDOWN pfbdsiShutdown;
  224. PFN_BDSI_DRIVERUNLOAD pfbdsiDriverUnload;
  225. PFN_BDSI_SETPOWERSTATE pfbdsiSetPowerState;
  226. } BDLI_BDSIFUNCTIONS, *PBDLI_BDSIFUNCTIONS;
  227. typedef struct _BDL_DEVICEEXT
  228. {
  229. //
  230. // size of this struct
  231. //
  232. ULONG Size;
  233. //
  234. // The device object that we are attached to
  235. //
  236. PDEVICE_OBJECT pAttachedDeviceObject;
  237. //
  238. // The BDD's extension
  239. //
  240. PVOID pvBDDExtension;
  241. } BDL_DEVICEEXT, *PBDL_DEVICEEXT;
  242. /////////////////////////////////////////////////////////////////////////////////////////
  243. //
  244. // These functions are exported by the BDL
  245. //
  246. //
  247. // bdliInitialize()
  248. //
  249. // Called in response to the BDD receiving its DriverEntry call. This lets the BDL
  250. // know that a new BDD has been loaded and allows the BDL to initialize its state so that
  251. // it can manage the newly loaded BDD.
  252. //
  253. // The bdliInitialize call will set the appropriate fields in the DRIVER_OBJECT so that
  254. // the BDL will receive all the necessary callbacks from the system for PNP events,
  255. // Power events, and general driver functionality. The BDL will then forward calls that
  256. // require hardware support to the BDD that called bdliInitialize (it will do so using
  257. // the BDDI and BDSI APIs). A BDD must call the bdliInitialize call during its
  258. // DriverEntry function.
  259. //
  260. // PARAMETERS:
  261. // DriverObject This must be the DRIVER_OBJECT pointer that was passed into the
  262. // BDD's DriverEntry call.
  263. // RegistryPath This must be the UNICODE_STRING pointer that was passed into the
  264. // BDD's DriverEntry call.
  265. // pBDDIFunctions Pointer to a BDLI_BDDIFUNCTIONS structure that is filled in with the
  266. // entry points that the BDD exports to support the BDDI API set. The
  267. // pointers themselves are copied by the BDL, as opposed to saving the
  268. // pBDDIFunctions pointer, so the memory pointed to by pBDDIFunctions
  269. // need not remain accessible after the bdliInitialize call.
  270. // pBDSIFunctions Pointer to a BDLI_BDSIFUNCTIONS structure that is filled in with
  271. // the entry points that the BDD exports to support the BDSI API set.
  272. // The pointers themselves are copied by the BDL, as opposed to saving
  273. // the pBDSIFunctions pointer, so the memory pointed to by
  274. // pBDSIFunctions need not remain accessible after the bdliInitialize
  275. // call.
  276. // Flags Unused. Must be 0.
  277. // pReserved Unused. Must be NULL.
  278. //
  279. // RETURNS:
  280. // STATUS_SUCCESS If the bdliInitialize call succeeded
  281. //
  282. NTSTATUS
  283. bdliInitialize
  284. (
  285. IN PDRIVER_OBJECT DriverObject,
  286. IN PUNICODE_STRING RegistryPath,
  287. IN PBDLI_BDDIFUNCTIONS pBDDIFunctions,
  288. IN PBDLI_BDSIFUNCTIONS pBDSIFunctions,
  289. IN ULONG Flags,
  290. IN PVOID pReserved
  291. );
  292. //
  293. // bdliAlloc()
  294. //
  295. // Allocates memory that can be returned to the BDL.
  296. //
  297. // The BDD must always use this function to allocate memory that it will return to the
  298. // BDL as an OUT parameter of a BDDI call. Once memory has been returned to the BDL,
  299. // it will be owned and managed exclusively by the BDL and must not be further referenced
  300. // by the BDD. (Each BDDI call that requires the use of bdliAlloc will note it).
  301. //
  302. // PARAMETERS:
  303. // pBDLExt Pointer to the BDL_DEVICEEXT structure that was passed into the
  304. // bdsiAddDevice call.
  305. // cBytes The number of bytes to allocate.
  306. // Flags Unused. Must be 0.
  307. //
  308. // RETURNS:
  309. // Returns a pointer to the allocated memory, or NULL if the function fails.
  310. //
  311. void *
  312. bdliAlloc
  313. (
  314. IN PBDL_DEVICEEXT pBDLExt,
  315. IN ULONG cBytes,
  316. IN ULONG Flags
  317. );
  318. //
  319. // bdliFree()
  320. //
  321. // Frees memory allocated by bdliAlloc.
  322. //
  323. // Memory allocated by bdliAlloc is almost always passed to the BDL as a channel product
  324. // (as a BLOCK-type item) and subsequently freed by the BDL. However, if an error
  325. // occurs while processing a channel, the BDD may need to call bdliFree to free memory it
  326. // previous allocated via bdliAlloc.
  327. //
  328. // PARAMETERS:
  329. // pvBlock Block of memory passed in by the BDL.
  330. //
  331. // RETURNS:
  332. // No return value.
  333. //
  334. void
  335. bdliFree
  336. (
  337. IN PVOID pvBlock
  338. );
  339. //
  340. // bdliLogError()
  341. //
  342. // Writes an error to the event log.
  343. //
  344. // Provides a simple mechanism for BDD writers to write errors to the system event log
  345. // without the overhead of registering with the event logging subsystem.
  346. //
  347. // PARAMETERS:
  348. // pObject If the error being logged is device specific then this must be a
  349. // pointer to the BDL_DEVICEEXT structure that was passed into the
  350. // bdsiAddDevice call when the device was added. If the error being
  351. // logged is a general BDD error, then this must be same DRIVER_OBJECT
  352. // structure pointer that was passed into the DriverEntry call of the
  353. // BDD when the driver was loaded.
  354. // ErrorCode Error code of the function logging the error.
  355. // Insertion An insertion string to be written to the event log. Your message file
  356. // must have a place holder for the insertion. For example, "serial port
  357. // %2 is either not available or used by another device". In this
  358. // example, %2 will be replaced by the insertion string. Note that %1 is
  359. // reserved for the file name.
  360. // cDumpData The number of bytes pointed to by pDumpData.
  361. // pDumpData A data block to be displayed in the data window of the event log.
  362. // This may be NULL if the caller does not wish to display any dump data.
  363. // Flags Unused. Must be 0.
  364. // pReserved Unused. Must be NULL.
  365. //
  366. // RETURNS:
  367. // STATUS_SUCCESS If the bdliLogError call succeeded
  368. //
  369. NTSTATUS
  370. bdliLogError
  371. (
  372. IN PVOID pObject,
  373. IN NTSTATUS ErrorCode,
  374. IN PUNICODE_STRING Insertion,
  375. IN ULONG cDumpData,
  376. IN PUCHAR pDumpData,
  377. IN ULONG Flags,
  378. IN PVOID pReserved
  379. );
  380. //
  381. // bdliControlChange()
  382. //
  383. // This function allows BDDs to asynchronously return the values of its controls.
  384. //
  385. // bdliControlChange is generally called by the BDD in response to one of its controls
  386. // changing a value. Specifically, it is most often used in the case of a sensor
  387. // control that has changed from 0 to 1 indicating that a source is present and a sample
  388. // can be taken.
  389. //
  390. // PARAMETERS:
  391. // pBDLExt Pointer to the BDL_DEVICEEXT structure that was passed into the
  392. // bdsiAddDevice call.
  393. // ComponentId Specifies either the Component ID of the component in which the
  394. // control or the control's parent channel resides, or '0' to indicate
  395. // that dwControlId refers to a device control.
  396. // ChannelId If dwComponentId is not '0', dwChannelId specifies either the Channel
  397. // ID of the channel in which the control resides, or '0' to indicate
  398. // that dwControlId refers to a component control.Ignored if
  399. // dwComponentId is '0'.
  400. // ControlId ControlId of the changed control.
  401. // Value Specifies the new value for the control .
  402. // Flags Unused. Must be 0.
  403. // pReserved Unused. Must be NULL.
  404. //
  405. // RETURNS:
  406. // STATUS_SUCCESS If the bdliControlChange call succeeded
  407. //
  408. NTSTATUS
  409. bdliControlChange
  410. (
  411. IN PBDL_DEVICEEXT pBDLExt,
  412. IN ULONG ComponentId,
  413. IN ULONG ChannelId,
  414. IN ULONG ControlId,
  415. IN ULONG Value,
  416. IN ULONG Flags,
  417. IN PVOID pReserved
  418. );
  419. //
  420. // These functions and defines can be used for debugging purposes
  421. //
  422. #define BDL_DEBUG_TRACE ((ULONG) 0x00000001)
  423. #define BDL_DEBUG_ERROR ((ULONG) 0x00000002)
  424. #define BDL_DEBUG_ASSERT ((ULONG) 0x00000004)
  425. ULONG
  426. BDLGetDebugLevel();
  427. #if DBG
  428. #define BDLDebug(LEVEL, STRING) \
  429. { \
  430. if (LEVEL & BDL_DEBUG_TRACE & BDLGetDebugLevel()) \
  431. KdPrint(STRING); \
  432. if (LEVEL & BDL_DEBUG_ERROR & BDLGetDebugLevel()) \
  433. KdPrint(STRING);\
  434. if (BDLGetDebugLevel() & BDL_DEBUG_ASSERT) \
  435. _asm int 3 \
  436. }
  437. #else
  438. #define BDLDebug(LEVEL, STRING)
  439. #endif
  440. #ifdef __cplusplus
  441. }
  442. #endif
  443. #endif