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.

418 lines
10 KiB

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