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.

1787 lines
79 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. HIDPI.H
  5. Abstract:
  6. Public Interface to the HID parsing library.
  7. Environment:
  8. Kernel & user mode
  9. --*/
  10. #ifndef __HIDPI_H__
  11. #define __HIDPI_H__
  12. #include <pshpack4.h>
  13. // Please include "hidsdi.h" to use the user space (dll / parser)
  14. // Please include "hidpddi.h" to use the kernel space parser
  15. //
  16. // Special Link collection values for using the query functions
  17. //
  18. // Root collection references the collection at the base of the link
  19. // collection tree.
  20. // Unspecifies, references all collections in the link collection tree.
  21. //
  22. #define HIDP_LINK_COLLECTION_ROOT ((USHORT) -1)
  23. #define HIDP_LINK_COLLECTION_UNSPECIFIED ((USHORT) 0)
  24. typedef enum _HIDP_REPORT_TYPE
  25. {
  26. HidP_Input,
  27. HidP_Output,
  28. HidP_Feature
  29. } HIDP_REPORT_TYPE;
  30. typedef struct _USAGE_AND_PAGE
  31. {
  32. USAGE Usage;
  33. USAGE UsagePage;
  34. } USAGE_AND_PAGE, *PUSAGE_AND_PAGE;
  35. #define HidP_IsSameUsageAndPage(u1, u2) ((* (PULONG) &u1) == (* (PULONG) &u2))
  36. typedef struct _HIDP_BUTTON_CAPS
  37. {
  38. USAGE UsagePage;
  39. UCHAR ReportID;
  40. BOOLEAN IsAlias;
  41. USHORT BitField;
  42. USHORT LinkCollection; // A unique internal index pointer
  43. USAGE LinkUsage;
  44. USAGE LinkUsagePage;
  45. BOOLEAN IsRange;
  46. BOOLEAN IsStringRange;
  47. BOOLEAN IsDesignatorRange;
  48. BOOLEAN IsAbsolute;
  49. ULONG Reserved[10];
  50. union {
  51. struct {
  52. USAGE UsageMin, UsageMax;
  53. USHORT StringMin, StringMax;
  54. USHORT DesignatorMin, DesignatorMax;
  55. USHORT DataIndexMin, DataIndexMax;
  56. } Range;
  57. struct {
  58. USAGE Usage, Reserved1;
  59. USHORT StringIndex, Reserved2;
  60. USHORT DesignatorIndex, Reserved3;
  61. USHORT DataIndex, Reserved4;
  62. } NotRange;
  63. };
  64. } HIDP_BUTTON_CAPS, *PHIDP_BUTTON_CAPS;
  65. typedef struct _HIDP_VALUE_CAPS
  66. {
  67. USAGE UsagePage;
  68. UCHAR ReportID;
  69. BOOLEAN IsAlias;
  70. USHORT BitField;
  71. USHORT LinkCollection; // A unique internal index pointer
  72. USAGE LinkUsage;
  73. USAGE LinkUsagePage;
  74. BOOLEAN IsRange;
  75. BOOLEAN IsStringRange;
  76. BOOLEAN IsDesignatorRange;
  77. BOOLEAN IsAbsolute;
  78. BOOLEAN HasNull; // Does this channel have a null report union
  79. UCHAR Reserved;
  80. USHORT BitSize; // How many bits are devoted to this value?
  81. USHORT ReportCount; // See Note below. Usually set to 1.
  82. USHORT Reserved2[5];
  83. ULONG UnitsExp;
  84. ULONG Units;
  85. LONG LogicalMin, LogicalMax;
  86. LONG PhysicalMin, PhysicalMax;
  87. union {
  88. struct {
  89. USAGE UsageMin, UsageMax;
  90. USHORT StringMin, StringMax;
  91. USHORT DesignatorMin, DesignatorMax;
  92. USHORT DataIndexMin, DataIndexMax;
  93. } Range;
  94. struct {
  95. USAGE Usage, Reserved1;
  96. USHORT StringIndex, Reserved2;
  97. USHORT DesignatorIndex, Reserved3;
  98. USHORT DataIndex, Reserved4;
  99. } NotRange;
  100. };
  101. } HIDP_VALUE_CAPS, *PHIDP_VALUE_CAPS;
  102. //
  103. // Notes:
  104. //
  105. // ReportCount: When a report descriptor declares an Input, Output, or
  106. // Feature main item with fewer usage declarations than the report count, then
  107. // the last usage applies to all remaining unspecified count in that main item.
  108. // (As an example you might have data that required many fields to describe,
  109. // possibly buffered bytes.) In this case, only one value cap structure is
  110. // allocated for these associtated fields, all with the same usage, and Report
  111. // Count reflects the number of fields involved. Normally ReportCount is 1.
  112. // To access all of the fields in such a value structure would require using
  113. // HidP_GetUsageValueArray and HidP_SetUsageValueArray. HidP_GetUsageValue/
  114. // HidP_SetScaledUsageValue will also work, however, these functions will only
  115. // work with the first field of the structure.
  116. //
  117. //
  118. // The link collection tree consists of an array of LINK_COLLECTION_NODES
  119. // where the index into this array is the same as the collection number.
  120. //
  121. // Given a collection A which contains a subcollection B, A is defined to be
  122. // the parent B, and B is defined to be the child.
  123. //
  124. // Given collections A, B, and C where B and C are children of A, and B was
  125. // encountered before C in the report descriptor, B is defined as a sibling of
  126. // C. (This implies, of course, that if B is a sibling of C, then C is NOT a
  127. // sibling of B).
  128. //
  129. // B is defined as the NextSibling of C if and only if there exists NO
  130. // child collection of A, call it D, such that B is a sibling of D and D
  131. // is a sibling of C.
  132. //
  133. // E is defined to be the FirstChild of A if and only if for all children of A,
  134. // F, that are not equivalent to E, F is a sibling of E.
  135. // (This implies, of course, that the does not exist a child of A, call it G,
  136. // where E is a sibling of G). In other words the first sibling is the last
  137. // link collection found in the list.
  138. //
  139. // In other words, if a collection B is defined within the definition of another
  140. // collection A, B becomes a child of A. All collections with the same parent
  141. // are considered siblings. The FirstChild of the parent collection, A, will be
  142. // last collection defined that has A as a parent. The order of sibling pointers
  143. // is similarly determined. When a collection B is defined, it becomes the
  144. // FirstChild of it's parent collection. The previously defined FirstChild of the
  145. // parent collection becomes the NextSibling of the new collection. As new
  146. // collections with the same parent are discovered, the chain of sibling is built.
  147. //
  148. // With that in mind, the following describes conclusively a data structure
  149. // that provides direct traversal up, down, and accross the link collection
  150. // tree.
  151. //
  152. //
  153. typedef struct _HIDP_LINK_COLLECTION_NODE
  154. {
  155. USAGE LinkUsage;
  156. USAGE LinkUsagePage;
  157. USHORT Parent;
  158. USHORT NumberOfChildren;
  159. USHORT NextSibling;
  160. USHORT FirstChild;
  161. ULONG CollectionType: 8; // As defined in 6.2.2.6 of HID spec
  162. ULONG IsAlias : 1; // This link node is an allias of the next link node.
  163. ULONG Reserved: 23;
  164. PVOID UserContext; // The user can hang his coat here.
  165. } HIDP_LINK_COLLECTION_NODE, *PHIDP_LINK_COLLECTION_NODE;
  166. //
  167. // When a link collection is described by a delimiter, alias link collection
  168. // nodes are created. (One for each usage within the delimiter).
  169. // The parser assigns each capability description listed above only one
  170. // link collection.
  171. //
  172. // If a control is defined within a collection defined by
  173. // delimited usages, then that control is said to be within multiple link
  174. // collections, one for each usage within the open and close delimiter tokens.
  175. // Such multiple link collecions are said to be aliases. The first N-1 such
  176. // collections, listed in the link collection node array, have their IsAlias
  177. // bit set. The last such link collection is the link collection index used
  178. // in the capabilities described above.
  179. // Clients wishing to set a control in an aliased collection, should walk the
  180. // collection array once for each time they see the IsAlias flag set, and use
  181. // the last link collection as the index for the below accessor functions.
  182. //
  183. // NB: if IsAlias is set, then NextSibling should be one more than the current
  184. // link collection node index.
  185. //
  186. typedef PUCHAR PHIDP_REPORT_DESCRIPTOR;
  187. typedef struct _HIDP_PREPARSED_DATA * PHIDP_PREPARSED_DATA;
  188. typedef struct _HIDP_CAPS
  189. {
  190. USAGE Usage;
  191. USAGE UsagePage;
  192. USHORT InputReportByteLength;
  193. USHORT OutputReportByteLength;
  194. USHORT FeatureReportByteLength;
  195. USHORT Reserved[17];
  196. USHORT NumberLinkCollectionNodes;
  197. USHORT NumberInputButtonCaps;
  198. USHORT NumberInputValueCaps;
  199. USHORT NumberInputDataIndices;
  200. USHORT NumberOutputButtonCaps;
  201. USHORT NumberOutputValueCaps;
  202. USHORT NumberOutputDataIndices;
  203. USHORT NumberFeatureButtonCaps;
  204. USHORT NumberFeatureValueCaps;
  205. USHORT NumberFeatureDataIndices;
  206. } HIDP_CAPS, *PHIDP_CAPS;
  207. typedef struct _HIDP_DATA
  208. {
  209. USHORT DataIndex;
  210. USHORT Reserved;
  211. union {
  212. ULONG RawValue; // for values
  213. BOOLEAN On; // for buttons MUST BE TRUE for buttons.
  214. };
  215. } HIDP_DATA, *PHIDP_DATA;
  216. //
  217. // The HIDP_DATA structure is used with HidP_GetData and HidP_SetData
  218. // functions.
  219. //
  220. // The parser contiguously assigns every control (button or value) in a hid
  221. // device a unique data index from zero to NumberXXXDataIndices -1 , inclusive.
  222. // This value is found in the HIDP_BUTTON_CAPS and HIDP_VALUE_CAPS structures.
  223. //
  224. // Most clients will find the Get/Set Buttons / Value accessor functions
  225. // sufficient to their needs, as they will allow the clients to access the
  226. // data known to them while ignoring the other controls.
  227. //
  228. // More complex clients, which actually read the Button / Value Caps, and which
  229. // do a value add service to these routines (EG Direct Input), will need to
  230. // access all the data in the device without interest in the individual usage
  231. // or link collection location. These are the clients that will find
  232. // HidP_Data useful.
  233. //
  234. typedef struct _HIDP_UNKNOWN_TOKEN
  235. {
  236. UCHAR Token;
  237. UCHAR Reserved[3];
  238. ULONG BitField;
  239. } HIDP_UNKNOWN_TOKEN, *PHIDP_UNKNOWN_TOKEN;
  240. typedef struct _HIDP_EXTENDED_ATTRIBUTES
  241. {
  242. UCHAR NumGlobalUnknowns;
  243. UCHAR Reserved [3];
  244. PHIDP_UNKNOWN_TOKEN GlobalUnknowns;
  245. // ... Additional attributes
  246. ULONG Data [1]; // variableLength DO NOT ACCESS THIS FIELD
  247. } HIDP_EXTENDED_ATTRIBUTES, *PHIDP_EXTENDED_ATTRIBUTES;
  248. NTSTATUS __stdcall
  249. HidP_GetCaps (
  250. IN PHIDP_PREPARSED_DATA PreparsedData,
  251. OUT PHIDP_CAPS Capabilities
  252. );
  253. /*++
  254. Routine Description:
  255. Returns a list of capabilities of a given hid device as described by its
  256. preparsed data.
  257. Arguments:
  258. PreparsedData The preparsed data returned from HIDCLASS.
  259. Capabilities a HIDP_CAPS structure
  260. Return Value:
  261. HIDP_STATUS_SUCCESS
  262. HIDP_STATUS_INVALID_PREPARSED_DATA
  263. --*/
  264. NTSTATUS __stdcall
  265. HidP_GetLinkCollectionNodes (
  266. OUT PHIDP_LINK_COLLECTION_NODE LinkCollectionNodes,
  267. IN OUT PULONG LinkCollectionNodesLength,
  268. IN PHIDP_PREPARSED_DATA PreparsedData
  269. );
  270. /*++
  271. Routine Description:
  272. Return a list of PHIDP_LINK_COLLECTION_NODEs used to describe the link
  273. collection tree of this hid device. See the above description of
  274. struct _HIDP_LINK_COLLECTION_NODE.
  275. Arguments:
  276. LinkCollectionNodes - a caller allocated array into which
  277. HidP_GetLinkCollectionNodes will store the information
  278. LinKCollectionNodesLength - the caller sets this value to the length of the
  279. the array in terms of number of elements.
  280. HidP_GetLinkCollectionNodes sets this value to the actual
  281. number of elements set. The total number of nodes required to
  282. describe this HID device can be found in the
  283. NumberLinkCollectionNodes field in the HIDP_CAPS structure.
  284. --*/
  285. NTSTATUS __stdcall
  286. HidP_GetButtonCaps (
  287. IN HIDP_REPORT_TYPE ReportType,
  288. OUT PHIDP_BUTTON_CAPS ButtonCaps,
  289. IN OUT PUSHORT ButtonCapsLength,
  290. IN PHIDP_PREPARSED_DATA PreparsedData
  291. );
  292. #define HidP_GetButtonCaps(_Type_, _Caps_, _Len_, _Data_) \
  293. HidP_GetSpecificButtonCaps (_Type_, 0, 0, 0, _Caps_, _Len_, _Data_)
  294. NTSTATUS __stdcall
  295. HidP_GetSpecificButtonCaps (
  296. IN HIDP_REPORT_TYPE ReportType,
  297. IN USAGE UsagePage, // Optional (0 => ignore)
  298. IN USHORT LinkCollection, // Optional (0 => ignore)
  299. IN USAGE Usage, // Optional (0 => ignore)
  300. OUT PHIDP_BUTTON_CAPS ButtonCaps,
  301. IN OUT PUSHORT ButtonCapsLength,
  302. IN PHIDP_PREPARSED_DATA PreparsedData
  303. );
  304. /*++
  305. Description:
  306. HidP_GetButtonCaps returns all the buttons (binary values) that are a part
  307. of the given report type for the Hid device represented by the given
  308. preparsed data.
  309. Parameters:
  310. ReportType One of HidP_Input, HidP_Output, or HidP_Feature.
  311. UsagePage A usage page value used to limit the button caps returned to
  312. those on a given usage page. If set to 0, this parameter is
  313. ignored. Can be used with LinkCollection and Usage parameters
  314. to further limit the number of button caps structures returned.
  315. LinkCollection HIDP_LINK_COLLECTION node array index used to limit the
  316. button caps returned to those buttons in a given link
  317. collection. If set to 0, this parameter is
  318. ignored. Can be used with UsagePage and Usage parameters
  319. to further limit the number of button caps structures
  320. returned.
  321. Usage A usage value used to limit the button caps returned to those
  322. with the specified usage value. If set to 0, this parameter
  323. is ignored. Can be used with LinkCollection and UsagePage
  324. parameters to further limit the number of button caps
  325. structures returned.
  326. ButtonCaps A _HIDP_BUTTON_CAPS array containing information about all the
  327. binary values in the given report. This buffer is provided by
  328. the caller.
  329. ButtonLength As input, this parameter specifies the length of the
  330. ButtonCaps parameter (array) in number of array elements.
  331. As output, this value is set to indicate how many of those
  332. array elements were filled in by the function. The maximum number of
  333. button caps that can be returned is found in the HIDP_CAPS
  334. structure. If HIDP_STATUS_BUFFER_TOO_SMALL is returned,
  335. this value contains the number of array elements needed to
  336. successfully complete the request.
  337. PreparsedData The preparsed data returned from HIDCLASS.
  338. Return Value
  339. HidP_GetSpecificButtonCaps returns the following error codes:
  340. HIDP_STATUS_SUCCESS.
  341. HIDP_STATUS_INVALID_REPORT_TYPE
  342. HIDP_STATUS_INVALID_PREPARSED_DATA
  343. HIDP_STATUS_BUFFER_TOO_SMALL (all given entries however have been filled in)
  344. HIDP_STATUS_USAGE_NOT_FOUND
  345. --*/
  346. NTSTATUS __stdcall
  347. HidP_GetValueCaps (
  348. IN HIDP_REPORT_TYPE ReportType,
  349. OUT PHIDP_VALUE_CAPS ValueCaps,
  350. IN OUT PUSHORT ValueCapsLength,
  351. IN PHIDP_PREPARSED_DATA PreparsedData
  352. );
  353. #define HidP_GetValueCaps(_Type_, _Caps_, _Len_, _Data_) \
  354. HidP_GetSpecificValueCaps (_Type_, 0, 0, 0, _Caps_, _Len_, _Data_)
  355. NTSTATUS __stdcall
  356. HidP_GetSpecificValueCaps (
  357. IN HIDP_REPORT_TYPE ReportType,
  358. IN USAGE UsagePage, // Optional (0 => ignore)
  359. IN USHORT LinkCollection, // Optional (0 => ignore)
  360. IN USAGE Usage, // Optional (0 => ignore)
  361. OUT PHIDP_VALUE_CAPS ValueCaps,
  362. IN OUT PUSHORT ValueCapsLength,
  363. IN PHIDP_PREPARSED_DATA PreparsedData
  364. );
  365. /*++
  366. Description:
  367. HidP_GetValueCaps returns all the values (non-binary) that are a part
  368. of the given report type for the Hid device represented by the given
  369. preparsed data.
  370. Parameters:
  371. ReportType One of HidP_Input, HidP_Output, or HidP_Feature.
  372. UsagePage A usage page value used to limit the value caps returned to
  373. those on a given usage page. If set to 0, this parameter is
  374. ignored. Can be used with LinkCollection and Usage parameters
  375. to further limit the number of value caps structures returned.
  376. LinkCollection HIDP_LINK_COLLECTION node array index used to limit the
  377. value caps returned to those buttons in a given link
  378. collection. If set to 0, this parameter is
  379. ignored. Can be used with UsagePage and Usage parameters
  380. to further limit the number of value caps structures
  381. returned.
  382. Usage A usage value used to limit the value caps returned to those
  383. with the specified usage value. If set to 0, this parameter
  384. is ignored. Can be used with LinkCollection and UsagePage
  385. parameters to further limit the number of value caps
  386. structures returned.
  387. ValueCaps A _HIDP_VALUE_CAPS array containing information about all the
  388. non-binary values in the given report. This buffer is provided
  389. by the caller.
  390. ValueLength As input, this parameter specifies the length of the ValueCaps
  391. parameter (array) in number of array elements. As output,
  392. this value is set to indicate how many of those array elements
  393. were filled in by the function. The maximum number of
  394. value caps that can be returned is found in the HIDP_CAPS
  395. structure. If HIDP_STATUS_BUFFER_TOO_SMALL is returned,
  396. this value contains the number of array elements needed to
  397. successfully complete the request.
  398. PreparsedData The preparsed data returned from HIDCLASS.
  399. Return Value
  400. HidP_GetValueCaps returns the following error codes:
  401. HIDP_STATUS_SUCCESS.
  402. HIDP_STATUS_INVALID_REPORT_TYPE
  403. HIDP_STATUS_INVALID_PREPARSED_DATA
  404. HIDP_STATUS_BUFFER_TOO_SMALL (all given entries however have been filled in)
  405. HIDP_STATUS_USAGE_NOT_FOUND
  406. --*/
  407. NTSTATUS __stdcall
  408. HidP_GetExtendedAttributes (
  409. IN HIDP_REPORT_TYPE ReportType,
  410. IN USHORT DataIndex,
  411. IN PHIDP_PREPARSED_DATA PreparsedData,
  412. OUT PHIDP_EXTENDED_ATTRIBUTES Attributes,
  413. IN OUT PULONG LengthAttributes
  414. );
  415. /*++
  416. Description:
  417. Given a data index from the value or button capabilities of a given control
  418. return any extended attributes for the control if any exist.
  419. Parameters:
  420. ReportType One of HidP_Input, HidP_Output, or HidP_Feature.
  421. DataIndex The data index for the given control, found in the capabilities
  422. structure for that control
  423. PreparsedData The preparsed data returned from HIDCLASS.
  424. Attributes Pointer to a buffer into which the extended attribute data will
  425. be copied.
  426. LengthAttributes Length of the given buffer in bytes.
  427. Return Value
  428. HIDP_STATUS_SUCCESS
  429. HIDP_STATUS_DATA_INDEX_NOT_FOUND
  430. --*/
  431. NTSTATUS __stdcall
  432. HidP_InitializeReportForID (
  433. IN HIDP_REPORT_TYPE ReportType,
  434. IN UCHAR ReportID,
  435. IN PHIDP_PREPARSED_DATA PreparsedData,
  436. IN OUT PCHAR Report,
  437. IN ULONG ReportLength
  438. );
  439. /*++
  440. Routine Description:
  441. Initialize a report based on the given report ID.
  442. Parameters:
  443. ReportType One of HidP_Input, HidP_Output, or HidP_Feature.
  444. PreparasedData Preparsed data structure returned by HIDCLASS
  445. Report Buffer which to set the data into.
  446. ReportLength Length of Report...Report should be at least as long as the
  447. value indicated in the HIDP_CAPS structure for the device and
  448. the corresponding ReportType
  449. Return Value
  450. HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid.
  451. HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid
  452. HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not equal
  453. to the length specified in HIDP_CAPS
  454. structure for the given ReportType
  455. HIDP_STATUS_REPORT_DOES_NOT_EXIST -- if there are no reports on this device
  456. for the given ReportType
  457. --*/
  458. NTSTATUS __stdcall
  459. HidP_SetData (
  460. IN HIDP_REPORT_TYPE ReportType,
  461. IN PHIDP_DATA DataList,
  462. IN OUT PULONG DataLength,
  463. IN PHIDP_PREPARSED_DATA PreparsedData,
  464. IN OUT PCHAR Report,
  465. IN ULONG ReportLength
  466. );
  467. /*++
  468. Routine Description:
  469. Please Note: Since usage value arrays deal with multiple fields for
  470. for one usage value, they cannot be used with HidP_SetData
  471. and HidP_GetData. In this case,
  472. HIDP_STATUS_IS_USAGE_VALUE_ARRAY will be returned.
  473. Parameters:
  474. ReportType One of HidP_Input, HidP_Output, or HidP_Feature.
  475. DataList Array of HIDP_DATA structures that contains the data values
  476. that are to be set into the given report
  477. DataLength As input, length in array elements of DataList. As output,
  478. contains the number of data elements set on successful
  479. completion or an index into the DataList array to identify
  480. the faulting HIDP_DATA value if an error code is returned.
  481. PreparasedData Preparsed data structure returned by HIDCLASS
  482. Report Buffer which to set the data into.
  483. ReportLength Length of Report...Report should be at least as long as the
  484. value indicated in the HIDP_CAPS structure for the device and
  485. the corresponding ReportType
  486. Return Value
  487. HidP_SetData returns the following error codes. The report packet will
  488. have all the data set up until the HIDP_DATA structure that caused the
  489. error. DataLength, in the error case, will return this problem index.
  490. HIDP_STATUS_SUCCESS -- upon successful insertion of all data
  491. into the report packet.
  492. HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid.
  493. HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid
  494. HIDP_STATUS_DATA_INDEX_NOT_FOUND -- if a HIDP_DATA structure referenced a
  495. data index that does not exist for this
  496. device's ReportType
  497. HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not equal
  498. to the length specified in HIDP_CAPS
  499. structure for the given ReportType
  500. HIDP_STATUS_REPORT_DOES_NOT_EXIST -- if there are no reports on this device
  501. for the given ReportType
  502. HIDP_STATUS_IS_USAGE_VALUE_ARRAY -- if one of the HIDP_DATA structures
  503. references a usage value array.
  504. DataLength will contain the index into
  505. the array that was invalid
  506. HIDP_STATUS_BUTTON_NOT_PRESSED -- if a HIDP_DATA structure attempted
  507. to unset a button that was not already
  508. set in the Report
  509. HIDP_STATUS_INCOMPATIBLE_REPORT_ID -- a HIDP_DATA structure was found with
  510. a valid index value but is contained
  511. in a different report than the one
  512. currently being processed
  513. HIDP_STATUS_BUFFER_TOO_SMALL -- if there are not enough entries in
  514. a given Main Array Item to report all
  515. buttons that have been requested to be
  516. set
  517. --*/
  518. NTSTATUS __stdcall
  519. HidP_GetData (
  520. IN HIDP_REPORT_TYPE ReportType,
  521. OUT PHIDP_DATA DataList,
  522. IN OUT PULONG DataLength,
  523. IN PHIDP_PREPARSED_DATA PreparsedData,
  524. IN PCHAR Report,
  525. IN ULONG ReportLength
  526. );
  527. /*++
  528. Routine Description:
  529. Please Note: For obvious reasons HidP_SetData and HidP_GetData will not
  530. access UsageValueArrays.
  531. Parameters:
  532. ReportType One of HidP_Input, HidP_Output, or HidP_Feature.
  533. DataList Array of HIDP_DATA structures that will receive the data
  534. values that are set in the given report
  535. DataLength As input, length in array elements of DataList. As output,
  536. contains the number of data elements that were successfully
  537. set by HidP_GetData. The maximum size necessary for DataList
  538. can be determined by calling HidP_MaxDataListLength
  539. PreparasedData Preparsed data structure returned by HIDCLASS
  540. Report Buffer which to set the data into.
  541. ReportLength Length of Report...Report should be at least as long as the
  542. value indicated in the HIDP_CAPS structure for the device and
  543. the corresponding ReportType
  544. Return Value
  545. HidP_GetData returns the following error codes.
  546. HIDP_STATUS_SUCCESS -- upon successful retrieval of all data
  547. from the report packet.
  548. HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid.
  549. HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid
  550. HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not equal
  551. to the length specified in HIDP_CAPS
  552. structure for the given ReportType
  553. HIDP_STATUS_REPORT_DOES_NOT_EXIST -- if there are no reports on this device
  554. for the given ReportType
  555. HIDP_STATUS_BUFFER_TOO_SMALL -- if there are not enough array entries in
  556. DataList to store all the indice values
  557. in the given report. DataLength will
  558. contain the number of array entries
  559. required to hold all data
  560. --*/
  561. ULONG __stdcall
  562. HidP_MaxDataListLength (
  563. IN HIDP_REPORT_TYPE ReportType,
  564. IN PHIDP_PREPARSED_DATA PreparsedData
  565. );
  566. /*++
  567. Routine Description:
  568. This function returns the maximum length of HIDP_DATA elements that
  569. HidP_GetData could return for the given report type.
  570. Parameters:
  571. ReportType One of HidP_Input, HidP_Output or HidP_Feature.
  572. PreparsedData Preparsed data structure returned by HIDCLASS
  573. Return Value:
  574. The length of the data list array required for the HidP_GetData function
  575. call. If an error occurs (either HIDP_STATUS_INVALID_REPORT_TYPE or
  576. HIDP_STATUS_INVALID_PREPARSED_DATA), this function returns 0.
  577. --*/
  578. #define HidP_SetButtons(Rty, Up, Lco, ULi, ULe, Ppd, Rep, Rle) \
  579. HidP_SetUsages(Rty, Up, Lco, ULi, ULe, Ppd, Rep, Rle)
  580. NTSTATUS __stdcall
  581. HidP_SetUsages (
  582. IN HIDP_REPORT_TYPE ReportType,
  583. IN USAGE UsagePage,
  584. IN USHORT LinkCollection, // Optional
  585. IN PUSAGE UsageList,
  586. IN OUT PULONG UsageLength,
  587. IN PHIDP_PREPARSED_DATA PreparsedData,
  588. IN OUT PCHAR Report,
  589. IN ULONG ReportLength
  590. );
  591. /*++
  592. Routine Description:
  593. This function sets binary values (buttons) in a report. Given an
  594. initialized packet of correct length, it modifies the report packet so that
  595. each element in the given list of usages has been set in the report packet.
  596. For example, in an output report with 5 LEDs, each with a given usage,
  597. an application could turn on any subset of these lights by placing their
  598. usages in any order into the usage array (UsageList). HidP_SetUsages would,
  599. in turn, set the appropriate bit or add the corresponding byte into the
  600. HID Main Array Item.
  601. A properly initialized Report packet is one of the correct byte length,
  602. and all zeros.
  603. NOTE: A packet that has already been set with a call to a HidP_Set routine
  604. can also be passed in. This routine then sets processes the UsageList
  605. in the same fashion but verifies that the ReportID already set in
  606. Report matches the report ID for the given usages.
  607. Parameters:
  608. ReportType One of HidP_Input, HidP_Output or HidP_Feature.
  609. UsagePage All of the usages in the usage array, which HidP_SetUsages will
  610. set in the report, refer to this same usage page.
  611. If a client wishes to set usages in a report for multiple
  612. usage pages then that client needs to make multiple calls to
  613. HidP_SetUsages for each of the usage pages.
  614. UsageList A usage array containing the usages that HidP_SetUsages will set in
  615. the report packet.
  616. UsageLength The length of the given usage array in array elements.
  617. The parser will set this value to the position in the usage
  618. array where it stopped processing. If successful, UsageLength
  619. will be unchanged. In any error condition, this parameter
  620. reflects how many of the usages in the usage list have
  621. actually been set by the parser. This is useful for finding
  622. the usage in the list which caused the error.
  623. PreparsedData The preparsed data recevied from HIDCLASS
  624. Report The report packet.
  625. ReportLength Length of the given report packet...Must be equal to the
  626. value reported in the HIDP_CAPS structure for the device
  627. and corresponding report type.
  628. Return Value
  629. HidP_SetUsages returns the following error codes. On error, the report packet
  630. will be correct up until the usage element that caused the error.
  631. HIDP_STATUS_SUCCESS -- upon successful insertion of all usages
  632. into the report packet.
  633. HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid.
  634. HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid
  635. HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not
  636. equal to the length specified in
  637. the HIDP_CAPS structure for the given
  638. ReportType
  639. HIDP_STATUS_REPORT_DOES_NOT_EXIST -- if there are no reports on this device
  640. for the given ReportType
  641. HIDP_STATUS_INCOMPATIBLE_REPORT_ID -- if a usage was found that exists in a
  642. different report. If the report is
  643. zero-initialized on entry the first
  644. usage in the list will determine which
  645. report ID is used. Otherwise, the
  646. parser will verify that usage matches
  647. the passed in report's ID
  648. HIDP_STATUS_USAGE_NOT_FOUND -- if the usage does not exist for any
  649. report (no matter what the report ID)
  650. for the given report type.
  651. HIDP_STATUS_BUFFER_TOO_SMALL -- if there are not enough entries in a
  652. given Main Array Item to list all of
  653. the given usages. The caller needs
  654. to split his request into more than
  655. one call
  656. --*/
  657. #define HidP_UnsetButtons(Rty, Up, Lco, ULi, ULe, Ppd, Rep, Rle) \
  658. HidP_UnsetUsages(Rty, Up, Lco, ULi, ULe, Ppd, Rep, Rle)
  659. NTSTATUS __stdcall
  660. HidP_UnsetUsages (
  661. IN HIDP_REPORT_TYPE ReportType,
  662. IN USAGE UsagePage,
  663. IN USHORT LinkCollection, // Optional
  664. IN PUSAGE UsageList,
  665. IN OUT PULONG UsageLength,
  666. IN PHIDP_PREPARSED_DATA PreparsedData,
  667. IN OUT PCHAR Report,
  668. IN ULONG ReportLength
  669. );
  670. /*++
  671. Routine Description:
  672. This function unsets (turns off) binary values (buttons) in the report. Given
  673. an initialized packet of correct length, it modifies the report packet so
  674. that each element in the given list of usages has been unset in the
  675. report packet.
  676. This function is the "undo" operation for SetUsages. If the given usage
  677. is not already set in the Report, it will return an error code of
  678. HIDP_STATUS_BUTTON_NOT_PRESSED. If the button is pressed, HidP_UnsetUsages
  679. will unset the appropriate bit or remove the corresponding index value from
  680. the HID Main Array Item.
  681. A properly initialized Report packet is one of the correct byte length,
  682. and all zeros..
  683. NOTE: A packet that has already been set with a call to a HidP_Set routine
  684. can also be passed in. This routine then processes the UsageList
  685. in the same fashion but verifies that the ReportID already set in
  686. Report matches the report ID for the given usages.
  687. Parameters:
  688. ReportType One of HidP_Input, HidP_Output or HidP_Feature.
  689. UsagePage All of the usages in the usage array, which HidP_UnsetUsages will
  690. unset in the report, refer to this same usage page.
  691. If a client wishes to unset usages in a report for multiple
  692. usage pages then that client needs to make multiple calls to
  693. HidP_UnsetUsages for each of the usage pages.
  694. UsageList A usage array containing the usages that HidP_UnsetUsages will
  695. unset in the report packet.
  696. UsageLength The length of the given usage array in array elements.
  697. The parser will set this value to the position in the usage
  698. array where it stopped processing. If successful, UsageLength
  699. will be unchanged. In any error condition, this parameter
  700. reflects how many of the usages in the usage list have
  701. actually been unset by the parser. This is useful for finding
  702. the usage in the list which caused the error.
  703. PreparsedData The preparsed data recevied from HIDCLASS
  704. Report The report packet.
  705. ReportLength Length of the given report packet...Must be equal to the
  706. value reported in the HIDP_CAPS structure for the device
  707. and corresponding report type.
  708. Return Value
  709. HidP_UnsetUsages returns the following error codes. On error, the report
  710. packet will be correct up until the usage element that caused the error.
  711. HIDP_STATUS_SUCCESS -- upon successful "unsetting" of all usages
  712. in the report packet.
  713. HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid.
  714. HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid
  715. HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not
  716. equal to the length specified in
  717. the HIDP_CAPS structure for the given
  718. ReportType
  719. HIDP_STATUS_REPORT_DOES_NOT_EXIST -- if there are no reports on this device
  720. for the given ReportType
  721. HIDP_STATUS_INCOMPATIBLE_REPORT_ID -- if a usage was found that exists in a
  722. different report. If the report is
  723. zero-initialized on entry the first
  724. usage in the list will determine which
  725. report ID is used. Otherwise, the
  726. parser will verify that usage matches
  727. the passed in report's ID
  728. HIDP_STATUS_USAGE_NOT_FOUND -- if the usage does not exist for any
  729. report (no matter what the report ID)
  730. for the given report type.
  731. HIDP_STATUS_BUTTON_NOT_PRESSED -- if a usage corresponds to a button that
  732. is not already set in the given report
  733. --*/
  734. #define HidP_GetButtons(Rty, UPa, LCo, ULi, ULe, Ppd, Rep, RLe) \
  735. HidP_GetUsages(Rty, UPa, LCo, ULi, ULe, Ppd, Rep, RLe)
  736. NTSTATUS __stdcall
  737. HidP_GetUsages (
  738. IN HIDP_REPORT_TYPE ReportType,
  739. IN USAGE UsagePage,
  740. IN USHORT LinkCollection, // Optional
  741. OUT USAGE * UsageList,
  742. IN OUT ULONG * UsageLength,
  743. IN PHIDP_PREPARSED_DATA PreparsedData,
  744. IN PCHAR Report,
  745. IN ULONG ReportLength
  746. );
  747. /*++
  748. Routine Description:
  749. This function returns the binary values (buttons) that are set in a HID
  750. report. Given a report packet of correct length, it searches the report
  751. packet for each usage for the given usage page and returns them in the
  752. usage list.
  753. Parameters:
  754. ReportType One of HidP_Input, HidP_Output or HidP_Feature.
  755. UsagePage All of the usages in the usage list, which HidP_GetUsages will
  756. retrieve in the report, refer to this same usage page.
  757. If the client wishes to get usages in a packet for multiple
  758. usage pages then that client needs to make multiple calls
  759. to HidP_GetUsages.
  760. LinkCollection An optional value which can limit which usages are returned
  761. in the UsageList to those usages that exist in a specific
  762. LinkCollection. A non-zero value indicates the index into
  763. the HIDP_LINK_COLLECITON_NODE list returned by
  764. HidP_GetLinkCollectionNodes of the link collection the
  765. usage should belong to. A value of 0 indicates this
  766. should value be ignored.
  767. UsageList The usage array that will contain all the usages found in
  768. the report packet.
  769. UsageLength The length of the given usage array in array elements.
  770. On input, this value describes the length of the usage list.
  771. On output, HidP_GetUsages sets this value to the number of
  772. usages that was found. Use HidP_MaxUsageListLength to
  773. determine the maximum length needed to return all the usages
  774. that a given report packet may contain.
  775. PreparsedData Preparsed data structure returned by HIDCLASS
  776. Report The report packet.
  777. ReportLength Length (in bytes) of the given report packet
  778. Return Value
  779. HidP_GetUsages returns the following error codes:
  780. HIDP_STATUS_SUCCESS -- upon successfully retrieving all the
  781. usages from the report packet
  782. HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid.
  783. HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid
  784. HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not
  785. equal to the length specified in
  786. the HIDP_CAPS structure for the given
  787. ReportType
  788. HIDP_STATUS_REPORT_DOES_NOT_EXIST -- if there are no reports on this device
  789. for the given ReportType
  790. HIDP_STATUS_BUFFER_TOO_SMALL -- if the UsageList is not big enough to
  791. hold all the usages found in the report
  792. packet. If this is returned, the buffer
  793. will contain UsageLength number of
  794. usages. Use HidP_MaxUsageListLength to
  795. find the maximum length needed
  796. HIDP_STATUS_INCOMPATIBLE_REPORT_ID -- if no usages were found but usages
  797. that match the UsagePage and
  798. LinkCollection specified could be found
  799. in a report with a different report ID
  800. HIDP_STATUS_USAGE_NOT_FOUND -- if there are no usages in a reports for
  801. the device and ReportType that match the
  802. UsagePage and LinkCollection that were
  803. specified
  804. --*/
  805. #define HidP_GetButtonsEx(Rty, LCo, BLi, ULe, Ppd, Rep, RLe) \
  806. HidP_GetUsagesEx(Rty, LCo, BLi, ULe, Ppd, Rep, RLe)
  807. NTSTATUS __stdcall
  808. HidP_GetUsagesEx (
  809. IN HIDP_REPORT_TYPE ReportType,
  810. IN USHORT LinkCollection, // Optional
  811. OUT PUSAGE_AND_PAGE ButtonList,
  812. IN OUT ULONG * UsageLength,
  813. IN PHIDP_PREPARSED_DATA PreparsedData,
  814. IN PCHAR Report,
  815. IN ULONG ReportLength
  816. );
  817. /*++
  818. Routine Description:
  819. This function returns the binary values (buttons) in a HID report.
  820. Given a report packet of correct length, it searches the report packet
  821. for all buttons and returns the UsagePage and Usage for each of the buttons
  822. it finds.
  823. Parameters:
  824. ReportType One of HidP_Input, HidP_Output or HidP_Feature.
  825. LinkCollection An optional value which can limit which usages are returned
  826. in the ButtonList to those usages that exist in a specific
  827. LinkCollection. A non-zero value indicates the index into
  828. the HIDP_LINK_COLLECITON_NODE list returned by
  829. HidP_GetLinkCollectionNodes of the link collection the
  830. usage should belong to. A value of 0 indicates this
  831. should value be ignored.
  832. ButtonList An array of USAGE_AND_PAGE structures describing all the
  833. buttons currently ``down'' in the device.
  834. UsageLength The length of the given array in terms of elements.
  835. On input, this value describes the length of the list. On
  836. output, HidP_GetUsagesEx sets this value to the number of
  837. usages that were found. Use HidP_MaxUsageListLength to
  838. determine the maximum length needed to return all the usages
  839. that a given report packet may contain.
  840. PreparsedData Preparsed data returned by HIDCLASS
  841. Report The report packet.
  842. ReportLength Length (in bytes) of the given report packet.
  843. Return Value
  844. HidP_GetUsagesEx returns the following error codes:
  845. HIDP_STATUS_SUCCESS -- upon successfully retrieving all the
  846. usages from the report packet
  847. HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid.
  848. HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid
  849. HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not
  850. equal to the length specified in
  851. the HIDP_CAPS structure for the given
  852. ReportType
  853. HIDP_STATUS_REPORT_DOES_NOT_EXIST -- if there are no reports on this device
  854. for the given ReportType
  855. HIDP_STATUS_BUFFER_TOO_SMALL -- if ButtonList is not big enough to
  856. hold all the usages found in the report
  857. packet. If this is returned, the buffer
  858. will contain UsageLength number of
  859. usages. Use HidP_MaxUsageListLength to
  860. find the maximum length needed
  861. HIDP_STATUS_INCOMPATIBLE_REPORT_ID -- if no usages were found but usages
  862. that match the specified LinkCollection
  863. exist in report with a different report
  864. ID.
  865. HIDP_STATUS_USAGE_NOT_FOUND -- if there are no usages in any reports that
  866. match the LinkCollection parameter
  867. --*/
  868. #define HidP_GetButtonListLength(RTy, UPa, Ppd) \
  869. HidP_GetUsageListLength(Rty, UPa, Ppd)
  870. ULONG __stdcall
  871. HidP_MaxUsageListLength (
  872. IN HIDP_REPORT_TYPE ReportType,
  873. IN USAGE UsagePage, // Optional
  874. IN PHIDP_PREPARSED_DATA PreparsedData
  875. );
  876. /*++
  877. Routine Description:
  878. This function returns the maximum number of usages that a call to
  879. HidP_GetUsages or HidP_GetUsagesEx could return for a given HID report.
  880. If calling for number of usages returned by HidP_GetUsagesEx, use 0 as
  881. the UsagePage value.
  882. Parameters:
  883. ReportType One of HidP_Input, HidP_Output or HidP_Feature.
  884. UsagePage Specifies the optional UsagePage to query for. If 0, will
  885. return all the maximum number of usage values that could be
  886. returned for a given ReportType. If non-zero, will return
  887. the maximum number of usages that would be returned for the
  888. ReportType with the given UsagePage.
  889. PreparsedData Preparsed data returned from HIDCLASS
  890. Return Value:
  891. The length of the usage list array required for the HidP_GetUsages or
  892. HidP_GetUsagesEx function call. If an error occurs (such as
  893. HIDP_STATUS_INVALID_REPORT_TYPE or HIDP_INVALID_PREPARSED_DATA, this
  894. returns 0.
  895. --*/
  896. NTSTATUS __stdcall
  897. HidP_SetUsageValue (
  898. IN HIDP_REPORT_TYPE ReportType,
  899. IN USAGE UsagePage,
  900. IN USHORT LinkCollection, // Optional
  901. IN USAGE Usage,
  902. IN ULONG UsageValue,
  903. IN PHIDP_PREPARSED_DATA PreparsedData,
  904. IN OUT PCHAR Report,
  905. IN ULONG ReportLength
  906. );
  907. /*++
  908. Description:
  909. HidP_SetUsageValue inserts a value into the HID Report Packet in the field
  910. corresponding to the given usage page and usage. HidP_SetUsageValue
  911. casts this value to the appropriate bit length. If a report packet
  912. contains two different fields with the same Usage and UsagePage,
  913. they can be distinguished with the optional LinkCollection field value.
  914. Using this function sets the raw value into the report packet with
  915. no checking done as to whether it actually falls within the logical
  916. minimum/logical maximum range. Use HidP_SetScaledUsageValue for this...
  917. NOTE: Although the UsageValue parameter is a ULONG, any casting that is
  918. done will preserve or sign-extend the value. The value being set
  919. should be considered a LONG value and will be treated as such by
  920. this function.
  921. Parameters:
  922. ReportType One of HidP_Output or HidP_Feature.
  923. UsagePage The usage page to which the given usage refers.
  924. LinkCollection (Optional) This value can be used to differentiate
  925. between two fields that may have the same
  926. UsagePage and Usage but exist in different
  927. collections. If the link collection value
  928. is zero, this function will set the first field
  929. it finds that matches the usage page and
  930. usage.
  931. Usage The usage whose value HidP_SetUsageValue will set.
  932. UsageValue The raw value to set in the report buffer. This value must be within
  933. the logical range or if a NULL value this value should be the
  934. most negative value that can be represented by the number of bits
  935. for this field.
  936. PreparsedData The preparsed data returned for HIDCLASS
  937. Report The report packet.
  938. ReportLength Length (in bytes) of the given report packet.
  939. Return Value:
  940. HidP_SetUsageValue returns the following error codes:
  941. HIDP_STATUS_SUCCESS -- upon successfully setting the value
  942. in the report packet
  943. HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid.
  944. HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid
  945. HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not
  946. equal to the length specified in
  947. the HIDP_CAPS structure for the given
  948. ReportType
  949. HIDP_STATUS_REPORT_DOES_NOT_EXIST -- if there are no reports on this device
  950. for the given ReportType
  951. HIDP_STATUS_INCOMPATIBLE_REPORT_ID -- the specified usage page, usage and
  952. link collection exist but exists in
  953. a report with a different report ID
  954. than the report being passed in. To
  955. set this value, call HidP_SetUsageValue
  956. again with a zero-initizialed report
  957. packet
  958. HIDP_STATUS_USAGE_NOT_FOUND -- if the usage page, usage, and link
  959. collection combination does not exist
  960. in any reports for this ReportType
  961. --*/
  962. NTSTATUS __stdcall
  963. HidP_SetScaledUsageValue (
  964. IN HIDP_REPORT_TYPE ReportType,
  965. IN USAGE UsagePage,
  966. IN USHORT LinkCollection, // Optional
  967. IN USAGE Usage,
  968. IN LONG UsageValue,
  969. IN PHIDP_PREPARSED_DATA PreparsedData,
  970. IN OUT PCHAR Report,
  971. IN ULONG ReportLength
  972. );
  973. /*++
  974. Description:
  975. HidP_SetScaledUsageValue inserts the UsageValue into the HID report packet
  976. in the field corresponding to the given usage page and usage. If a report
  977. packet contains two different fields with the same Usage and UsagePage,
  978. they can be distinguished with the optional LinkCollection field value.
  979. If the specified field has a defined physical range, this function converts
  980. the physical value specified to the corresponding logical value for the
  981. report. If a physical value does not exist, the function will verify that
  982. the value specified falls within the logical range and set according.
  983. If the range checking fails but the field has NULL values, the function will
  984. set the field to the defined NULL value (most negative number possible) and
  985. return HIDP_STATUS_NULL. In other words, use this function to set NULL
  986. values for a given field by passing in a value that falls outside the
  987. physical range if it is defined or the logical range otherwise.
  988. If the field does not support NULL values, an out of range error will be
  989. returned instead.
  990. Parameters:
  991. ReportType One of HidP_Output or HidP_Feature.
  992. UsagePage The usage page to which the given usage refers.
  993. LinkCollection (Optional) This value can be used to differentiate
  994. between two fields that may have the same
  995. UsagePage and Usage but exist in different
  996. collections. If the link collection value
  997. is zero, this function will set the first field
  998. it finds that matches the usage page and
  999. usage.
  1000. Usage The usage whose value HidP_SetScaledUsageValue will set.
  1001. UsageValue The value to set in the report buffer. See the routine
  1002. description above for the different interpretations of this
  1003. value
  1004. PreparsedData The preparsed data returned from HIDCLASS
  1005. Report The report packet.
  1006. ReportLength Length (in bytes) of the given report packet.
  1007. Return Value:
  1008. HidP_SetScaledUsageValue returns the following error codes:
  1009. HIDP_STATUS_SUCCESS -- upon successfully setting the value
  1010. in the report packet
  1011. HIDP_STATUS_NULL -- upon successfully setting the value
  1012. in the report packet as a NULL value
  1013. HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid.
  1014. HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid
  1015. HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not
  1016. equal to the length specified in
  1017. the HIDP_CAPS structure for the given
  1018. ReportType
  1019. HIDP_STATUS_VALUE_OUT_OF_RANGE -- if the value specified failed to fall
  1020. within the physical range if it exists
  1021. or within the logical range otherwise
  1022. and the field specified by the usage
  1023. does not allow NULL values
  1024. HIDP_STATUS_BAD_LOG_PHY_VALUES -- if the field has a physical range but
  1025. either the logical range is invalid
  1026. (max <= min) or the physical range is
  1027. invalid
  1028. HIDP_STATUS_INCOMPATIBLE_REPORT_ID -- the specified usage page, usage and
  1029. link collection exist but exists in
  1030. a report with a different report ID
  1031. than the report being passed in. To
  1032. set this value, call
  1033. HidP_SetScaledUsageValue again with
  1034. a zero-initialized report packet
  1035. HIDP_STATUS_USAGE_NOT_FOUND -- if the usage page, usage, and link
  1036. collection combination does not exist
  1037. in any reports for this ReportType
  1038. --*/
  1039. NTSTATUS __stdcall
  1040. HidP_SetUsageValueArray (
  1041. IN HIDP_REPORT_TYPE ReportType,
  1042. IN USAGE UsagePage,
  1043. IN USHORT LinkCollection, // Optional
  1044. IN USAGE Usage,
  1045. IN PCHAR UsageValue,
  1046. IN USHORT UsageValueByteLength,
  1047. IN PHIDP_PREPARSED_DATA PreparsedData,
  1048. OUT PCHAR Report,
  1049. IN ULONG ReportLength
  1050. );
  1051. /*++
  1052. Routine Descripton:
  1053. A usage value array occurs when the last usage in the list of usages
  1054. describing a main item must be repeated because there are less usages defined
  1055. than there are report counts declared for the given main item. In this case
  1056. a single value cap is allocated for that usage and the report count of that
  1057. value cap is set to reflect the number of fields to which that usage refers.
  1058. HidP_SetUsageValueArray sets the raw bits for that usage which spans
  1059. more than one field in a report.
  1060. NOTE: This function currently does not support value arrays where the
  1061. ReportSize for each of the fields in the array is not a multiple
  1062. of 8 bits.
  1063. The UsageValue buffer should have the values set as they would appear
  1064. in the report buffer. If this function supported non 8-bit multiples
  1065. for the ReportSize then caller should format the input buffer so that
  1066. each new value begins at the bit immediately following the last bit
  1067. of the previous value
  1068. Parameters:
  1069. ReportType One of HidP_Output or HidP_Feature.
  1070. UsagePage The usage page to which the given usage refers.
  1071. LinkCollection (Optional) This value can be used to differentiate
  1072. between two fields that may have the same
  1073. UsagePage and Usage but exist in different
  1074. collections. If the link collection value
  1075. is zero, this function will set the first field
  1076. it finds that matches the usage page and
  1077. usage.
  1078. Usage The usage whose value array HidP_SetUsageValueArray will set.
  1079. UsageValue The buffer with the values to set into the value array.
  1080. The number of BITS required is found by multiplying the
  1081. BitSize and ReportCount fields of the Value Cap for this
  1082. control. The least significant bit of this control found in the
  1083. given report will be placed in the least significan bit location
  1084. of the array given (little-endian format), regardless of whether
  1085. or not the field is byte alligned or if the BitSize is a multiple
  1086. of sizeof (CHAR).
  1087. See the above note for current implementation limitations.
  1088. UsageValueByteLength Length of the UsageValue buffer (in bytes)
  1089. PreparsedData The preparsed data returned from HIDCLASS
  1090. Report The report packet.
  1091. ReportLength Length (in bytes) of the given report packet.
  1092. Return Value:
  1093. HIDP_STATUS_SUCCESS -- upon successfully setting the value
  1094. array in the report packet
  1095. HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid.
  1096. HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid
  1097. HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not
  1098. equal to the length specified in
  1099. the HIDP_CAPS structure for the given
  1100. ReportType
  1101. HIDP_STATUS_REPORT_DOES_NOT_EXIST -- if there are no reports on this device
  1102. for the given ReportType
  1103. HIDP_STATUS_NOT_VALUE_ARRAY -- if the control specified is not a
  1104. value array -- a value array will have
  1105. a ReportCount field in the
  1106. HIDP_VALUE_CAPS structure that is > 1
  1107. Use HidP_SetUsageValue instead
  1108. HIDP_STATUS_BUFFER_TOO_SMALL -- if the size of the passed in buffer with
  1109. the values to set is too small (ie. has
  1110. fewer values than the number of fields in
  1111. the array
  1112. HIDP_STATUS_NOT_IMPLEMENTED -- if the usage value array has field sizes
  1113. that are not multiples of 8 bits, this
  1114. error code is returned since the function
  1115. currently does not handle setting into
  1116. such arrays.
  1117. HIDP_STATUS_INCOMPATIBLE_REPORT_ID -- the specified usage page, usage and
  1118. link collection exist but exists in
  1119. a report with a different report ID
  1120. than the report being passed in. To
  1121. set this value, call
  1122. HidP_SetUsageValueArray again with
  1123. a zero-initialized report packet
  1124. HIDP_STATUS_USAGE_NOT_FOUND -- if the usage page, usage, and link
  1125. collection combination does not exist
  1126. in any reports for this ReportType
  1127. --*/
  1128. NTSTATUS __stdcall
  1129. HidP_GetUsageValue (
  1130. IN HIDP_REPORT_TYPE ReportType,
  1131. IN USAGE UsagePage,
  1132. IN USHORT LinkCollection, // Optional
  1133. IN USAGE Usage,
  1134. OUT PULONG UsageValue,
  1135. IN PHIDP_PREPARSED_DATA PreparsedData,
  1136. IN PCHAR Report,
  1137. IN ULONG ReportLength
  1138. );
  1139. /*
  1140. Description
  1141. HidP_GetUsageValue retrieves the value from the HID Report for the usage
  1142. specified by the combination of usage page, usage and link collection.
  1143. If a report packet contains two different fields with the same
  1144. Usage and UsagePage, they can be distinguished with the optional
  1145. LinkCollection field value.
  1146. Parameters:
  1147. ReportType One of HidP_Input or HidP_Feature.
  1148. UsagePage The usage page to which the given usage refers.
  1149. LinkCollection (Optional) This value can be used to differentiate
  1150. between two fields that may have the same
  1151. UsagePage and Usage but exist in different
  1152. collections. If the link collection value
  1153. is zero, this function will set the first field
  1154. it finds that matches the usage page and
  1155. usage.
  1156. Usage The usage whose value HidP_GetUsageValue will retrieve
  1157. UsageValue The raw value that is set for the specified field in the report
  1158. buffer. This value will either fall within the logical range
  1159. or if NULL values are allowed, a number outside the range to
  1160. indicate a NULL
  1161. PreparsedData The preparsed data returned for HIDCLASS
  1162. Report The report packet.
  1163. ReportLength Length (in bytes) of the given report packet.
  1164. Return Value:
  1165. HidP_GetUsageValue returns the following error codes:
  1166. HIDP_STATUS_SUCCESS -- upon successfully retrieving the value
  1167. from the report packet
  1168. HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid.
  1169. HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid
  1170. HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not
  1171. equal to the length specified in
  1172. the HIDP_CAPS structure for the given
  1173. ReportType
  1174. HIDP_STATUS_REPORT_DOES_NOT_EXIST -- if there are no reports on this device
  1175. for the given ReportType
  1176. HIDP_STATUS_INCOMPATIBLE_REPORT_ID -- the specified usage page, usage and
  1177. link collection exist but exists in
  1178. a report with a different report ID
  1179. than the report being passed in. To
  1180. set this value, call HidP_GetUsageValue
  1181. again with a different report packet
  1182. HIDP_STATUS_USAGE_NOT_FOUND -- if the usage page, usage, and link
  1183. collection combination does not exist
  1184. in any reports for this ReportType
  1185. --*/
  1186. NTSTATUS __stdcall
  1187. HidP_GetScaledUsageValue (
  1188. IN HIDP_REPORT_TYPE ReportType,
  1189. IN USAGE UsagePage,
  1190. IN USHORT LinkCollection, // Optional
  1191. IN USAGE Usage,
  1192. OUT PLONG UsageValue,
  1193. IN PHIDP_PREPARSED_DATA PreparsedData,
  1194. IN PCHAR Report,
  1195. IN ULONG ReportLength
  1196. );
  1197. /*++
  1198. Description
  1199. HidP_GetScaledUsageValue retrieves a UsageValue from the HID report packet
  1200. in the field corresponding to the given usage page and usage. If a report
  1201. packet contains two different fields with the same Usage and UsagePage,
  1202. they can be distinguished with the optional LinkCollection field value.
  1203. If the specified field has a defined physical range, this function converts
  1204. the logical value that exists in the report packet to the corresponding
  1205. physical value. If a physical range does not exist, the function will
  1206. return the logical value. This function will check to verify that the
  1207. logical value in the report falls within the declared logical range.
  1208. When doing the conversion between logical and physical values, this
  1209. function assumes a linear extrapolation between the physical max/min and
  1210. the logical max/min. (Where logical is the values reported by the device
  1211. and physical is the value returned by this function). If the data field
  1212. size is less than 32 bits, then HidP_GetScaledUsageValue will sign extend
  1213. the value to 32 bits.
  1214. If the range checking fails but the field has NULL values, the function
  1215. will set UsageValue to 0 and return HIDP_STATUS_NULL. Otherwise, it
  1216. returns a HIDP_STATUS_OUT_OF_RANGE error.
  1217. Parameters:
  1218. ReportType One of HidP_Output or HidP_Feature.
  1219. UsagePage The usage page to which the given usage refers.
  1220. LinkCollection (Optional) This value can be used to differentiate
  1221. between two fields that may have the same
  1222. UsagePage and Usage but exist in different
  1223. collections. If the link collection value
  1224. is zero, this function will retrieve the first
  1225. field it finds that matches the usage page
  1226. and usage.
  1227. Usage The usage whose value HidP_GetScaledUsageValue will retrieve
  1228. UsageValue The value retrieved from the report buffer. See the routine
  1229. description above for the different interpretations of this
  1230. value
  1231. PreparsedData The preparsed data returned from HIDCLASS
  1232. Report The report packet.
  1233. ReportLength Length (in bytes) of the given report packet.
  1234. Return Value:
  1235. HidP_GetScaledUsageValue returns the following error codes:
  1236. HIDP_STATUS_SUCCESS -- upon successfully retrieving the value
  1237. from the report packet
  1238. HIDP_STATUS_NULL -- if the report packet had a NULL value
  1239. set
  1240. HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid.
  1241. HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid
  1242. HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not
  1243. equal to the length specified in
  1244. the HIDP_CAPS structure for the given
  1245. ReportType
  1246. HIDP_STATUS_VALUE_OUT_OF_RANGE -- if the value retrieved from the packet
  1247. falls outside the logical range and
  1248. the field does not support NULL values
  1249. HIDP_STATUS_BAD_LOG_PHY_VALUES -- if the field has a physical range but
  1250. either the logical range is invalid
  1251. (max <= min) or the physical range is
  1252. invalid
  1253. HIDP_STATUS_INCOMPATIBLE_REPORT_ID -- the specified usage page, usage and
  1254. link collection exist but exists in
  1255. a report with a different report ID
  1256. than the report being passed in. To
  1257. set this value, call
  1258. HidP_GetScaledUsageValue with a
  1259. different report packet
  1260. HIDP_STATUS_USAGE_NOT_FOUND -- if the usage page, usage, and link
  1261. collection combination does not exist
  1262. in any reports for this ReportType
  1263. --*/
  1264. NTSTATUS __stdcall
  1265. HidP_GetUsageValueArray (
  1266. IN HIDP_REPORT_TYPE ReportType,
  1267. IN USAGE UsagePage,
  1268. IN USHORT LinkCollection, // Optional
  1269. IN USAGE Usage,
  1270. OUT PCHAR UsageValue,
  1271. IN USHORT UsageValueByteLength,
  1272. IN PHIDP_PREPARSED_DATA PreparsedData,
  1273. IN PCHAR Report,
  1274. IN ULONG ReportLength
  1275. );
  1276. /*++
  1277. Routine Descripton:
  1278. A usage value array occurs when the last usage in the list of usages
  1279. describing a main item must be repeated because there are less usages defined
  1280. than there are report counts declared for the given main item. In this case
  1281. a single value cap is allocated for that usage and the report count of that
  1282. value cap is set to reflect the number of fields to which that usage refers.
  1283. HidP_GetUsageValueArray returns the raw bits for that usage which spans
  1284. more than one field in a report.
  1285. NOTE: This function currently does not support value arrays where the
  1286. ReportSize for each of the fields in the array is not a multiple
  1287. of 8 bits.
  1288. The UsageValue buffer will have the raw values as they are set
  1289. in the report packet.
  1290. Parameters:
  1291. ReportType One of HidP_Input, HidP_Output or HidP_Feature.
  1292. UsagePage The usage page to which the given usage refers.
  1293. LinkCollection (Optional) This value can be used to differentiate
  1294. between two fields that may have the same
  1295. UsagePage and Usage but exist in different
  1296. collections. If the link collection value
  1297. is zero, this function will set the first field
  1298. it finds that matches the usage page and
  1299. usage.
  1300. Usage The usage whose value HidP_GetUsageValueArray will retreive.
  1301. UsageValue A pointer to an array of characters where the value will be
  1302. placed. The number of BITS required is found by multiplying the
  1303. BitSize and ReportCount fields of the Value Cap for this
  1304. control. The least significant bit of this control found in the
  1305. given report will be placed in the least significant bit location
  1306. of the buffer (little-endian format), regardless of whether
  1307. or not the field is byte aligned or if the BitSize is a multiple
  1308. of sizeof (CHAR).
  1309. See note above about current implementation limitations
  1310. UsageValueByteLength
  1311. the length of the given UsageValue buffer.
  1312. PreparsedData The preparsed data returned by the HIDCLASS
  1313. Report The report packet.
  1314. ReportLength Length of the given report packet.
  1315. Return Value:
  1316. HIDP_STATUS_SUCCESS -- upon successfully retrieving the value
  1317. from the report packet
  1318. HIDP_STATUS_INVALID_REPORT_TYPE -- if ReportType is not valid.
  1319. HIDP_STATUS_INVALID_PREPARSED_DATA -- if PreparsedData is not valid
  1320. HIDP_STATUS_INVALID_REPORT_LENGTH -- the length of the report packet is not
  1321. equal to the length specified in
  1322. the HIDP_CAPS structure for the given
  1323. ReportType
  1324. HIDP_STATUS_NOT_VALUE_ARRAY -- if the control specified is not a
  1325. value array -- a value array will have
  1326. a ReportCount field in the
  1327. HIDP_VALUE_CAPS structure that is > 1
  1328. Use HidP_GetUsageValue instead
  1329. HIDP_STATUS_BUFFER_TOO_SMALL -- if the size of the passed in buffer in
  1330. which to return the array is too small
  1331. (ie. has fewer values than the number of
  1332. fields in the array
  1333. HIDP_STATUS_NOT_IMPLEMENTED -- if the usage value array has field sizes
  1334. that are not multiples of 8 bits, this
  1335. error code is returned since the function
  1336. currently does not handle getting values
  1337. from such arrays.
  1338. HIDP_STATUS_INCOMPATIBLE_REPORT_ID -- the specified usage page, usage and
  1339. link collection exist but exists in
  1340. a report with a different report ID
  1341. than the report being passed in. To
  1342. set this value, call
  1343. HidP_GetUsageValueArray with a
  1344. different report packet
  1345. HIDP_STATUS_USAGE_NOT_FOUND -- if the usage page, usage, and link
  1346. collection combination does not exist
  1347. in any reports for this ReportType
  1348. --*/
  1349. NTSTATUS __stdcall
  1350. HidP_UsageListDifference (
  1351. IN PUSAGE PreviousUsageList,
  1352. IN PUSAGE CurrentUsageList,
  1353. OUT PUSAGE BreakUsageList,
  1354. OUT PUSAGE MakeUsageList,
  1355. IN ULONG UsageListLength
  1356. );
  1357. /*++
  1358. Routine Description:
  1359. This function will return the difference between a two lists of usages
  1360. (as might be returned from HidP_GetUsages), In other words, it will return
  1361. return a list of usages that are in the current list but not the previous
  1362. list as well as a list of usages that are in the previous list but not
  1363. the current list.
  1364. Parameters:
  1365. PreviousUsageList The list of usages before.
  1366. CurrentUsageList The list of usages now.
  1367. BreakUsageList Previous - Current.
  1368. MakeUsageList Current - Previous.
  1369. UsageListLength Represents the length of the usage lists in array
  1370. elements. If comparing two lists with a differing
  1371. number of array elements, this value should be
  1372. the size of the larger of the two lists. Any
  1373. zero found with a list indicates an early termination
  1374. of the list and any usages found after the first zero
  1375. will be ignored.
  1376. --*/
  1377. NTSTATUS __stdcall
  1378. HidP_UsageAndPageListDifference (
  1379. IN PUSAGE_AND_PAGE PreviousUsageList,
  1380. IN PUSAGE_AND_PAGE CurrentUsageList,
  1381. OUT PUSAGE_AND_PAGE BreakUsageList,
  1382. OUT PUSAGE_AND_PAGE MakeUsageList,
  1383. IN ULONG UsageListLength
  1384. );
  1385. //
  1386. // Produce Make or Break Codes
  1387. //
  1388. typedef enum _HIDP_KEYBOARD_DIRECTION {
  1389. HidP_Keyboard_Break,
  1390. HidP_Keyboard_Make
  1391. } HIDP_KEYBOARD_DIRECTION;
  1392. //
  1393. // A bitmap of the current shift state of the keyboard when using the
  1394. // below keyboard usages to i8042 translation function.
  1395. //
  1396. typedef struct _HIDP_KEYBOARD_MODIFIER_STATE {
  1397. union {
  1398. struct {
  1399. ULONG LeftControl: 1;
  1400. ULONG LeftShift: 1;
  1401. ULONG LeftAlt: 1;
  1402. ULONG LeftGUI: 1;
  1403. ULONG RightControl: 1;
  1404. ULONG RightShift: 1;
  1405. ULONG RightAlt: 1;
  1406. ULONG RigthGUI: 1;
  1407. ULONG CapsLock: 1;
  1408. ULONG ScollLock: 1;
  1409. ULONG NumLock: 1;
  1410. ULONG Reserved: 21;
  1411. };
  1412. ULONG ul;
  1413. };
  1414. } HIDP_KEYBOARD_MODIFIER_STATE, * PHIDP_KEYBOARD_MODIFIER_STATE;
  1415. //
  1416. // A call back function to give the i8042 scan codes to the caller of
  1417. // the below translation function.
  1418. //
  1419. typedef BOOLEAN (* PHIDP_INSERT_SCANCODES) (
  1420. IN PVOID Context, // Some caller supplied context.
  1421. IN PCHAR NewScanCodes, // A list of i8042 scan codes.
  1422. IN ULONG Length // the length of the scan codes.
  1423. );
  1424. NTSTATUS __stdcall
  1425. HidP_TranslateUsageAndPagesToI8042ScanCodes (
  1426. IN PUSAGE_AND_PAGE ChangedUsageList,
  1427. IN ULONG UsageListLength,
  1428. IN HIDP_KEYBOARD_DIRECTION KeyAction,
  1429. IN OUT PHIDP_KEYBOARD_MODIFIER_STATE ModifierState,
  1430. IN PHIDP_INSERT_SCANCODES InsertCodesProcedure,
  1431. IN PVOID InsertCodesContext
  1432. );
  1433. /*++
  1434. Routine Description:
  1435. Parameters:
  1436. --*/
  1437. NTSTATUS __stdcall
  1438. HidP_TranslateUsagesToI8042ScanCodes (
  1439. IN PUSAGE ChangedUsageList,
  1440. IN ULONG UsageListLength,
  1441. IN HIDP_KEYBOARD_DIRECTION KeyAction,
  1442. IN OUT PHIDP_KEYBOARD_MODIFIER_STATE ModifierState,
  1443. IN PHIDP_INSERT_SCANCODES InsertCodesProcedure,
  1444. IN PVOID InsertCodesContext
  1445. );
  1446. /*++
  1447. Routine Description:
  1448. Parameters:
  1449. --*/
  1450. //
  1451. // Define NT Status codes with Facility Code of FACILITY_HID_ERROR_CODE
  1452. //
  1453. // FACILITY_HID_ERROR_CODE defined in ntstatus.h
  1454. #ifndef FACILITY_HID_ERROR_CODE
  1455. #define FACILITY_HID_ERROR_CODE 0x11
  1456. #endif
  1457. #define HIDP_ERROR_CODES(SEV, CODE) \
  1458. ((NTSTATUS) (((SEV) << 28) | (FACILITY_HID_ERROR_CODE << 16) | (CODE)))
  1459. #define HIDP_STATUS_SUCCESS (HIDP_ERROR_CODES(0x0,0))
  1460. #define HIDP_STATUS_NULL (HIDP_ERROR_CODES(0x8,1))
  1461. #define HIDP_STATUS_INVALID_PREPARSED_DATA (HIDP_ERROR_CODES(0xC,1))
  1462. #define HIDP_STATUS_INVALID_REPORT_TYPE (HIDP_ERROR_CODES(0xC,2))
  1463. #define HIDP_STATUS_INVALID_REPORT_LENGTH (HIDP_ERROR_CODES(0xC,3))
  1464. #define HIDP_STATUS_USAGE_NOT_FOUND (HIDP_ERROR_CODES(0xC,4))
  1465. #define HIDP_STATUS_VALUE_OUT_OF_RANGE (HIDP_ERROR_CODES(0xC,5))
  1466. #define HIDP_STATUS_BAD_LOG_PHY_VALUES (HIDP_ERROR_CODES(0xC,6))
  1467. #define HIDP_STATUS_BUFFER_TOO_SMALL (HIDP_ERROR_CODES(0xC,7))
  1468. #define HIDP_STATUS_INTERNAL_ERROR (HIDP_ERROR_CODES(0xC,8))
  1469. #define HIDP_STATUS_I8042_TRANS_UNKNOWN (HIDP_ERROR_CODES(0xC,9))
  1470. #define HIDP_STATUS_INCOMPATIBLE_REPORT_ID (HIDP_ERROR_CODES(0xC,0xA))
  1471. #define HIDP_STATUS_NOT_VALUE_ARRAY (HIDP_ERROR_CODES(0xC,0xB))
  1472. #define HIDP_STATUS_IS_VALUE_ARRAY (HIDP_ERROR_CODES(0xC,0xC))
  1473. #define HIDP_STATUS_DATA_INDEX_NOT_FOUND (HIDP_ERROR_CODES(0xC,0xD))
  1474. #define HIDP_STATUS_DATA_INDEX_OUT_OF_RANGE (HIDP_ERROR_CODES(0xC,0xE))
  1475. #define HIDP_STATUS_BUTTON_NOT_PRESSED (HIDP_ERROR_CODES(0xC,0xF))
  1476. #define HIDP_STATUS_REPORT_DOES_NOT_EXIST (HIDP_ERROR_CODES(0xC,0x10))
  1477. #define HIDP_STATUS_NOT_IMPLEMENTED (HIDP_ERROR_CODES(0xC,0x20))
  1478. //
  1479. // We blundered this status code.
  1480. //
  1481. #define HIDP_STATUS_I8242_TRANS_UNKNOWN HIDP_STATUS_I8042_TRANS_UNKNOWN
  1482. #include <poppack.h>
  1483. #endif