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.

210 lines
6.0 KiB

  1. #ifndef _CKHID_H
  2. #define _CKHID_H
  3. /*
  4. * title: hidpwr.h
  5. *
  6. * purpose: header for wdm kernel hid interface class
  7. *
  8. */
  9. #define READABLE 0x01
  10. #define WRITEABLE 0x02
  11. #define UsagePowerPage 0x84
  12. #define UsageUPS 0x04
  13. // objectification of hid class structures
  14. #define FeatureType 0x01
  15. #define InputType 0x02
  16. #define OutputType 0x03
  17. class CTypeMask {
  18. public:
  19. int GetReportType() { return ReportType; };
  20. bool IsWriteable() { return bWriteable;};
  21. bool IsString() { return bIsString;};
  22. bool IsVolatile() { return bVolatile;};
  23. bool IsNumber() { return bIsNumber;};
  24. bool IsAlertable() { return bAlertable;};
  25. void SetIsWriteable() { bWriteable = 1; };
  26. void SetAlertable() { bAlertable = 1; };
  27. void SetIsString() { bIsString = 1;};
  28. void SetIsNumber() { bIsNumber = 1;};
  29. void SetVolatile() { bVolatile = 1;};
  30. void SetReportType(int iType) { ReportType = iType;};
  31. CTypeMask();
  32. protected:
  33. unsigned ReportType : 2;
  34. unsigned bWriteable : 1;
  35. unsigned bIsString : 1;
  36. unsigned bIsNumber : 1;
  37. unsigned bAlertable : 1;
  38. unsigned bVolatile : 1;
  39. unsigned Pad : 1;
  40. };
  41. typedef enum {
  42. eFeatureValue = 1,
  43. eFeatureButton,
  44. eInputValue,
  45. eInputButton,
  46. eOutputValue,
  47. eOutputButton
  48. } eHidType;
  49. // forward declarations
  50. class CCollectionArray;
  51. class CHidDevice;
  52. class CUsage;
  53. class CProperties {
  54. public:
  55. LONG m_Unit;
  56. SHORT m_UnitExponent;
  57. LONG m_LogicalMin;
  58. LONG m_LogicalMax;
  59. USHORT m_LinkCollection;
  60. USHORT m_ReportID;
  61. USHORT m_Usage;
  62. USHORT m_UsagePage;
  63. CTypeMask * m_pType; // feature, input, or output, writeable, alertable, etc.
  64. // methods
  65. CProperties(CUsage *);
  66. ~CProperties();
  67. };
  68. class CUsage {
  69. public: // public members
  70. CProperties * m_pProperties;
  71. HIDP_BUTTON_CAPS * m_pButtonCaps;
  72. HIDP_VALUE_CAPS * m_pValueCaps;
  73. eHidType m_eType;
  74. union
  75. {
  76. ULONG m_Value;
  77. char * m_String;
  78. };
  79. CHidDevice * m_pHidDevice;
  80. public: // public methods
  81. CUsage();
  82. ~CUsage();
  83. bool GetValue();
  84. NTSTATUS GetString(char * pBuffer,USHORT usBuffLen,PULONG BytesReturned);
  85. void SetCapabilities();
  86. bool SetValue(ULONG);
  87. short GetExponent();
  88. ULONG GetUnit();
  89. };
  90. class CUsagePath {
  91. public: // public members
  92. USAGE m_UsagePage;
  93. USAGE m_UsageNumber;
  94. CUsage * m_pUsage;
  95. CUsagePath * m_pNextEntry;
  96. public: // public methods
  97. CUsagePath(USAGE UsagePage, USAGE UsageID, CUsage * pUsage = NULL);
  98. ~CUsagePath();
  99. };
  100. class CUsageArray {
  101. public: // members
  102. CUsage ** m_pUsages;
  103. USHORT m_UsageCount;
  104. public: // methods
  105. CUsageArray();
  106. ~CUsageArray();
  107. void AddUsage(CUsage * pNewUsage);
  108. };
  109. class CCollection {
  110. public: // public methods
  111. USAGE m_CollectionID;
  112. USAGE m_UsagePage;
  113. CUsageArray * m_UsageArray;
  114. CCollectionArray * m_CollectionArray;
  115. USHORT m_NodeIndex;
  116. CHidDevice * m_HidDevice;
  117. public: // methods and constructors
  118. CCollection(PHIDP_LINK_COLLECTION_NODE TheNodes, USHORT usNodeCount,USHORT usParentIndex);
  119. ~CCollection();
  120. void InitUsages(CHidDevice *);
  121. CUsagePath * FindIndexedUsage(USHORT *pCurrIndex, USHORT TargetIndex);
  122. };
  123. class CCollectionArray {
  124. public: // members
  125. CCollection ** m_pCollections;
  126. USHORT m_CollectionCount;
  127. public: // methods
  128. CCollectionArray(PHIDP_LINK_COLLECTION_NODE TheNodes, USHORT usNodeCount,SHORT sParentIndex);
  129. ~CCollectionArray();
  130. };
  131. #define MAXREPORTID 256
  132. typedef void (*EVENT_HANDLER)(
  133. IN PVOID Context,
  134. IN CUsage * pUsage
  135. );
  136. // prototypes for callbacks and completion routines used by CHidDevice class
  137. void _stdcall ReadThread(PVOID);
  138. NTSTATUS _stdcall ReadCompletionRoutine(
  139. PDEVICE_OBJECT,
  140. PIRP,
  141. PVOID);
  142. class CHidDevice
  143. {
  144. public:
  145. PHID_DEVICE m_pHidDevice;
  146. PDEVICE_OBJECT m_pDeviceObject;
  147. PDEVICE_OBJECT m_pLowerDeviceObject;
  148. PDEVICE_OBJECT m_pOpenedDeviceObject;
  149. USHORT m_UsagePage;
  150. USHORT m_UsageID;
  151. CCollectionArray * m_CollectionArray;
  152. CUsageArray * m_InputUsageArrays[MAXREPORTID]; // allowing for 10 input reports
  153. PBYTE m_pReadBuffer;
  154. PBYTE m_FeatureBuffer[MAXREPORTID];
  155. PVOID m_pThreadObject;
  156. KEVENT m_kReadEvent;
  157. KEVENT m_kAbortEvent;
  158. PHIDP_PREPARSED_DATA m_pPreparsedData;
  159. PHIDP_CAPS m_pCaps;
  160. EVENT_HANDLER m_pEventHandler;
  161. PVOID m_pEventContext;
  162. PFILE_OBJECT m_pFCB; // file control block for hid class read/write i/o
  163. PIRP m_pReadIrp;
  164. private:
  165. HANDLE m_hEventMutex;
  166. PBYTE m_InputBuffer;
  167. USHORT m_ReportIdArray[MAXREPORTID];
  168. public:
  169. CHidDevice();
  170. ~CHidDevice();
  171. bool OpenHidDevice(PDEVICE_OBJECT pDeviceObject);
  172. CUsage * FindUsage(CUsagePath * Path, USHORT usType);
  173. NTSTATUS ActivateInput();
  174. USHORT GetIndexFromReportId(USHORT ReportId);
  175. USHORT AssignIndexToReportId(USHORT ReportId);
  176. private:
  177. };
  178. #endif // CKHID_H