Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

424 lines
9.9 KiB

  1. #include <stdlib.h>
  2. #include <wtypes.h>
  3. #include "initguid.h"
  4. #include "hidclass.h"
  5. #include "hidsdi.h"
  6. #include "hiddll.h"
  7. #include <winioctl.h>
  8. //
  9. // __cdecl main (int argc, char *argv[])
  10. // {
  11. // return 0;
  12. // }
  13. //
  14. int HidD_Hello (char * buff, int len)
  15. {
  16. CHAR ret[] = "Hello\n";
  17. ULONG length = (sizeof (ret) < len) ? sizeof (ret) : len;
  18. memcpy (buff, ret, length);
  19. return sizeof (ret);
  20. }
  21. void __stdcall
  22. HidD_GetHidGuid (
  23. OUT LPGUID HidGuid
  24. )
  25. /*++
  26. Routine Description:
  27. Please see hidsdi.h for explination
  28. Notes:
  29. --*/
  30. {
  31. memcpy (HidGuid, &(GUID_CLASS_INPUT), sizeof (struct _GUID));
  32. *HidGuid = (GUID_CLASS_INPUT);
  33. }
  34. BOOLEAN __stdcall
  35. HidD_GetPreparsedData (
  36. IN HANDLE HidDeviceObject,
  37. OUT PHIDP_PREPARSED_DATA * PreparsedData
  38. )
  39. /*++
  40. Routine Description:
  41. please see hidsdi.h for explination
  42. Notes:
  43. --*/
  44. {
  45. HID_COLLECTION_INFORMATION info;
  46. ULONG bytes;
  47. PULONG buffer;
  48. if (! DeviceIoControl (HidDeviceObject,
  49. IOCTL_HID_GET_COLLECTION_INFORMATION,
  50. 0, 0,
  51. &info, sizeof (info),
  52. &bytes, NULL)) {
  53. return FALSE;
  54. }
  55. buffer = (PULONG) malloc ( info.DescriptorSize
  56. + (ALLOCATION_SHIFT * sizeof (ULONG)));
  57. if (!buffer)
  58. {
  59. SetLastError (ERROR_NOT_ENOUGH_MEMORY);
  60. return FALSE;
  61. }
  62. *buffer = RANDOM_DATA;
  63. *PreparsedData = (PHIDP_PREPARSED_DATA) (buffer + ALLOCATION_SHIFT);
  64. return DeviceIoControl (HidDeviceObject,
  65. IOCTL_HID_GET_COLLECTION_DESCRIPTOR,
  66. 0, 0,
  67. *PreparsedData, info.DescriptorSize,
  68. &bytes, NULL) != FALSE;
  69. }
  70. BOOLEAN __stdcall
  71. HidD_GetAttributes (
  72. IN HANDLE HidDeviceObject,
  73. OUT PHIDD_ATTRIBUTES Attributes
  74. )
  75. /*++
  76. Routine Description:
  77. Please see hidsdi.h for explination
  78. --*/
  79. {
  80. HID_COLLECTION_INFORMATION info;
  81. ULONG bytes;
  82. if (! DeviceIoControl (HidDeviceObject,
  83. IOCTL_HID_GET_COLLECTION_INFORMATION,
  84. 0, 0,
  85. &info, sizeof (info),
  86. &bytes, NULL)) {
  87. return FALSE;
  88. }
  89. Attributes->Size = sizeof (HIDD_ATTRIBUTES);
  90. Attributes->VendorID = info.VendorID;
  91. Attributes->ProductID = info.ProductID;
  92. Attributes->VersionNumber = info.VersionNumber;
  93. return TRUE;
  94. }
  95. BOOLEAN __stdcall
  96. HidD_FreePreparsedData (
  97. IN PHIDP_PREPARSED_DATA PreparsedData
  98. )
  99. /*++
  100. Routine Description:
  101. please see hidsdi.h for explination
  102. Notes:
  103. --*/
  104. {
  105. PULONG buffer;
  106. buffer = (PULONG) PreparsedData - ALLOCATION_SHIFT;
  107. if (RANDOM_DATA != *buffer) {
  108. return FALSE;
  109. }
  110. LocalFree (buffer);
  111. return TRUE;
  112. }
  113. BOOLEAN __stdcall
  114. HidD_FlushQueue (
  115. IN HANDLE HidDeviceObject
  116. )
  117. /*++
  118. Routine Description:
  119. Please see hidsdi.h for explination
  120. Notes:
  121. --*/
  122. {
  123. ULONG bytes;
  124. return DeviceIoControl (HidDeviceObject,
  125. IOCTL_HID_FLUSH_QUEUE,
  126. 0, 0,
  127. 0, 0,
  128. &bytes, NULL) != FALSE;
  129. }
  130. BOOLEAN __stdcall
  131. HidD_GetConfiguration (
  132. IN HANDLE HidDeviceObject,
  133. OUT PHIDD_CONFIGURATION Configuration,
  134. IN ULONG ConfigurationLength
  135. )
  136. /*++
  137. Routine Description:
  138. Please see hidsdi.h for explination
  139. Notes:
  140. We place a goo at the top so that we can enforce the must get before set
  141. rule.
  142. --*/
  143. {
  144. ULONG bytes;
  145. Configuration->cookie = &HidD_GetConfiguration;
  146. return DeviceIoControl (HidDeviceObject,
  147. IOCTL_HID_GET_DRIVER_CONFIG,
  148. 0,0,
  149. &Configuration->size,
  150. (ConfigurationLength - 4),
  151. &bytes, NULL) != FALSE;
  152. }
  153. BOOLEAN __stdcall
  154. HidD_SetConfiguration (
  155. IN HANDLE HidDeviceObject,
  156. OUT PHIDD_CONFIGURATION Configuration,
  157. IN ULONG ConfigurationLength
  158. )
  159. /*++
  160. Routine Description:
  161. Please see hidsdi.h for explanation
  162. Notes:
  163. We place a goo at the top so that we can enforce the must get before set
  164. rule.
  165. --*/
  166. {
  167. ULONG bytes;
  168. if (Configuration->cookie != &HidD_GetConfiguration) {
  169. SetLastError(ERROR_INVALID_PARAMETER);
  170. return FALSE;
  171. }
  172. return DeviceIoControl (HidDeviceObject,
  173. IOCTL_HID_SET_DRIVER_CONFIG,
  174. 0,0,
  175. &Configuration->size, (ConfigurationLength - 4),
  176. &bytes, NULL) != FALSE;
  177. }
  178. STDAPI_(BOOL)
  179. Entry32(HINSTANCE hinst, DWORD dwReason, LPVOID lpReserved)
  180. {
  181. switch (dwReason) {
  182. default: return TRUE;
  183. }
  184. }
  185. BOOLEAN __stdcall
  186. DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID lpReserved)
  187. {
  188. switch (dwReason)
  189. {
  190. default: return TRUE;
  191. }
  192. }
  193. BOOLEAN __stdcall
  194. HidD_GetNumInputBuffers (
  195. IN HANDLE HidDeviceObject,
  196. OUT PULONG NumberBuffers) // Number of hid packets actually retained
  197. {
  198. ULONG bytes;
  199. return DeviceIoControl (HidDeviceObject,
  200. IOCTL_GET_NUM_DEVICE_INPUT_BUFFERS,
  201. NULL, 0,
  202. NumberBuffers, sizeof (ULONG),
  203. &bytes, NULL) != FALSE;
  204. }
  205. BOOLEAN __stdcall
  206. HidD_SetNumInputBuffers (
  207. IN HANDLE HidDeviceObject,
  208. OUT ULONG NumberBuffers) // Number of hid packets actually retained
  209. {
  210. ULONG bytes;
  211. return DeviceIoControl (HidDeviceObject,
  212. IOCTL_SET_NUM_DEVICE_INPUT_BUFFERS,
  213. &NumberBuffers, sizeof (ULONG),
  214. NULL, 0,
  215. &bytes, NULL) != FALSE;
  216. }
  217. BOOLEAN __stdcall
  218. HidD_GetSerialNumberString (
  219. IN HANDLE HidDeviceObject,
  220. OUT PVOID Buffer,
  221. IN ULONG BufferLength
  222. )
  223. {
  224. ULONG bytes;
  225. return DeviceIoControl (HidDeviceObject,
  226. IOCTL_HID_GET_SERIALNUMBER_STRING,
  227. 0, 0,
  228. Buffer, BufferLength,
  229. &bytes, NULL) != FALSE;
  230. }
  231. BOOLEAN __stdcall
  232. HidD_GetManufacturerString (
  233. IN HANDLE HidDeviceObject,
  234. OUT PVOID Buffer,
  235. IN ULONG BufferLength
  236. )
  237. {
  238. ULONG bytes;
  239. return DeviceIoControl (HidDeviceObject,
  240. IOCTL_HID_GET_MANUFACTURER_STRING,
  241. 0, 0,
  242. Buffer, BufferLength,
  243. &bytes, NULL) != FALSE;
  244. }
  245. BOOLEAN __stdcall
  246. HidD_GetProductString (
  247. IN HANDLE HidDeviceObject,
  248. OUT PVOID Buffer,
  249. IN ULONG BufferLength
  250. )
  251. {
  252. ULONG bytes;
  253. return DeviceIoControl (HidDeviceObject,
  254. IOCTL_HID_GET_PRODUCT_STRING,
  255. 0, 0,
  256. Buffer, BufferLength,
  257. &bytes, NULL) != FALSE;
  258. }
  259. BOOLEAN __stdcall
  260. HidD_GetIndexedString (
  261. IN HANDLE HidDeviceObject,
  262. IN ULONG StringIndex,
  263. OUT PVOID Buffer,
  264. IN ULONG BufferLength
  265. )
  266. {
  267. ULONG bytes;
  268. return DeviceIoControl (HidDeviceObject,
  269. IOCTL_HID_GET_INDEXED_STRING,
  270. &StringIndex, sizeof (ULONG),
  271. Buffer, BufferLength,
  272. &bytes, NULL) != FALSE;
  273. }
  274. BOOLEAN __stdcall
  275. HidD_GetPhysicalDescriptor (
  276. IN HANDLE HidDeviceObject,
  277. OUT PVOID ReportBuffer,
  278. IN ULONG ReportBufferLength
  279. )
  280. {
  281. ULONG bytes;
  282. return DeviceIoControl (HidDeviceObject,
  283. IOCTL_GET_PHYSICAL_DESCRIPTOR,
  284. 0, 0,
  285. ReportBuffer, ReportBufferLength,
  286. &bytes, NULL) != FALSE;
  287. }
  288. BOOLEAN __stdcall
  289. HidD_GetFeature (
  290. IN HANDLE HidDeviceObject,
  291. OUT PVOID ReportBuffer,
  292. IN ULONG ReportBufferLength
  293. )
  294. {
  295. ULONG bytes;
  296. return DeviceIoControl (HidDeviceObject,
  297. IOCTL_HID_GET_FEATURE,
  298. 0, 0,
  299. ReportBuffer, ReportBufferLength,
  300. &bytes, NULL) != FALSE;
  301. }
  302. BOOLEAN __stdcall
  303. HidD_SetFeature (
  304. IN HANDLE HidDeviceObject,
  305. IN PVOID ReportBuffer,
  306. IN ULONG ReportBufferLength
  307. )
  308. {
  309. ULONG bytes;
  310. return DeviceIoControl (HidDeviceObject,
  311. IOCTL_HID_SET_FEATURE,
  312. ReportBuffer, ReportBufferLength,
  313. 0, 0,
  314. &bytes, NULL) != FALSE;
  315. }
  316. BOOLEAN __stdcall
  317. HidD_GetInputReport (
  318. IN HANDLE HidDeviceObject,
  319. OUT PVOID ReportBuffer,
  320. IN ULONG ReportBufferLength
  321. )
  322. {
  323. ULONG bytes;
  324. return DeviceIoControl (HidDeviceObject,
  325. IOCTL_HID_GET_INPUT_REPORT,
  326. 0, 0,
  327. ReportBuffer, ReportBufferLength,
  328. &bytes, NULL) != FALSE;
  329. }
  330. BOOLEAN __stdcall
  331. HidD_SetOutputReport (
  332. IN HANDLE HidDeviceObject,
  333. IN PVOID ReportBuffer,
  334. IN ULONG ReportBufferLength
  335. )
  336. {
  337. ULONG bytes;
  338. return DeviceIoControl (HidDeviceObject,
  339. IOCTL_HID_SET_OUTPUT_REPORT,
  340. ReportBuffer, ReportBufferLength,
  341. 0, 0,
  342. &bytes, NULL) != FALSE;
  343. }
  344. BOOLEAN __stdcall
  345. HidD_GetMsGenreDescriptor (
  346. IN HANDLE HidDeviceObject,
  347. OUT PVOID ReportBuffer,
  348. IN ULONG ReportBufferLength
  349. )
  350. {
  351. ULONG bytes;
  352. return DeviceIoControl (HidDeviceObject,
  353. IOCTL_HID_GET_MS_GENRE_DESCRIPTOR,
  354. 0, 0,
  355. ReportBuffer, ReportBufferLength,
  356. &bytes, NULL) != FALSE;
  357. }