2 * ReactOS Hid User Library
3 * Copyright (C) 2004-2005 ReactOS Team
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * PROJECT: ReactOS Hid User Library
22 * PURPOSE: ReactOS Hid User Library
23 * PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
30 HINSTANCE hDllInstance
;
32 /* device interface GUID for HIDClass devices */
33 const GUID HidClassGuid
= {0x4D1E55B2, 0xF16F, 0x11CF, {0x88,0xCB,0x00,0x11,0x11,0x00,0x00,0x30}};
36 DllMain(HINSTANCE hinstDLL
,
42 case DLL_PROCESS_ATTACH
:
43 hDllInstance
= hinstDLL
;
46 case DLL_THREAD_ATTACH
:
49 case DLL_THREAD_DETACH
:
52 case DLL_PROCESS_DETACH
:
60 * HidD_FlushQueue EXPORTED
66 HidD_FlushQueue(IN HANDLE HidDeviceObject
)
69 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_FLUSH_QUEUE
,
77 * HidD_FreePreparsedData EXPORTED
83 HidD_FreePreparsedData(IN PHIDP_PREPARSED_DATA PreparsedData
)
85 return (LocalFree((HLOCAL
)PreparsedData
) == NULL
);
90 * HidD_GetAttributes EXPORTED
96 HidD_GetAttributes(IN HANDLE HidDeviceObject
,
97 OUT PHIDD_ATTRIBUTES Attributes
)
99 HID_COLLECTION_INFORMATION hci
;
102 if(!DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_COLLECTION_INFORMATION
,
104 &hci
, sizeof(HID_COLLECTION_INFORMATION
),
110 /* copy the fields */
111 Attributes
->Size
= sizeof(HIDD_ATTRIBUTES
);
112 Attributes
->VendorID
= hci
.VendorID
;
113 Attributes
->ProductID
= hci
.ProductID
;
114 Attributes
->VersionNumber
= hci
.VersionNumber
;
121 * HidP_GetButtonCaps EXPORTED
127 HidP_GetButtonCaps(IN HIDP_REPORT_TYPE ReportType
,
128 OUT PHIDP_BUTTON_CAPS ButtonCaps
,
129 IN OUT PUSHORT ButtonCapsLength
,
130 IN PHIDP_PREPARSED_DATA PreparsedData
)
132 return HidP_GetSpecificButtonCaps(ReportType
, 0, 0, 0, ButtonCaps
,
133 ButtonCapsLength
, PreparsedData
);
138 * HidD_GetFeature EXPORTED
144 HidD_GetFeature(IN HANDLE HidDeviceObject
,
145 OUT PVOID ReportBuffer
,
146 IN ULONG ReportBufferLength
)
149 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_FEATURE
,
151 ReportBuffer
, ReportBufferLength
,
157 * HidD_GetHidGuid EXPORTED
163 HidD_GetHidGuid(OUT LPGUID HidGuid
)
165 *HidGuid
= HidClassGuid
;
170 * HidD_GetInputReport EXPORTED
176 HidD_GetInputReport(IN HANDLE HidDeviceObject
,
177 IN OUT PVOID ReportBuffer
,
178 IN ULONG ReportBufferLength
)
181 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_INPUT_REPORT
,
183 ReportBuffer
, ReportBufferLength
,
189 * HidD_GetManufacturerString EXPORTED
195 HidD_GetManufacturerString(IN HANDLE HidDeviceObject
,
197 IN ULONG BufferLength
)
200 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_MANUFACTURER_STRING
,
202 Buffer
, BufferLength
,
208 * HidD_GetNumInputBuffers EXPORTED
214 HidD_GetNumInputBuffers(IN HANDLE HidDeviceObject
,
215 OUT PULONG NumberBuffers
)
218 return DeviceIoControl(HidDeviceObject
, IOCTL_GET_NUM_DEVICE_INPUT_BUFFERS
,
220 NumberBuffers
, sizeof(ULONG
),
226 * HidD_GetPhysicalDescriptor EXPORTED
232 HidD_GetPhysicalDescriptor(IN HANDLE HidDeviceObject
,
234 IN ULONG BufferLength
)
237 return DeviceIoControl(HidDeviceObject
, IOCTL_GET_PHYSICAL_DESCRIPTOR
,
239 Buffer
, BufferLength
,
245 * HidD_GetPreparsedData EXPORTED
251 HidD_GetPreparsedData(IN HANDLE HidDeviceObject
,
252 OUT PHIDP_PREPARSED_DATA
*PreparsedData
)
254 HID_COLLECTION_INFORMATION hci
;
258 if(PreparsedData
== NULL
)
263 if(!DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_COLLECTION_INFORMATION
,
265 &hci
, sizeof(HID_COLLECTION_INFORMATION
),
271 *PreparsedData
= LocalAlloc(LHND
, hci
.DescriptorSize
);
272 if(*PreparsedData
== NULL
)
274 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
278 Ret
= DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_COLLECTION_DESCRIPTOR
,
280 *PreparsedData
, hci
.DescriptorSize
,
285 /* FIXME - Free the buffer in case we failed to get the descriptor? */
286 LocalFree((HLOCAL
)*PreparsedData
);
291 /* should we truncate the memory in case RetLen < hci.DescriptorSize? */
300 * HidD_GetProductString EXPORTED
306 HidD_GetProductString(IN HANDLE HidDeviceObject
,
308 IN ULONG BufferLength
)
311 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_PRODUCT_STRING
,
313 Buffer
, BufferLength
,
319 * HidD_GetSerialNumberString EXPORTED
325 HidD_GetSerialNumberString(IN HANDLE HidDeviceObject
,
327 IN ULONG BufferLength
)
330 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_SERIALNUMBER_STRING
,
332 Buffer
, BufferLength
,
338 * HidP_GetValueCaps EXPORTED
344 HidP_GetValueCaps(IN HIDP_REPORT_TYPE ReportType
,
345 OUT PHIDP_VALUE_CAPS ValueCaps
,
346 IN OUT PUSHORT ValueCapsLength
,
347 IN PHIDP_PREPARSED_DATA PreparsedData
)
349 return HidP_GetSpecificValueCaps(ReportType
, 0, 0, 0, ValueCaps
,
350 ValueCapsLength
, PreparsedData
);
355 * HidD_Hello EXPORTED
357 * Undocumented easter egg function. It fills the buffer with "Hello\n"
358 * and returns number of bytes filled in (lstrlen(Buffer) + 1 == 7)
360 * Bugs: - doesn't check Buffer for NULL
361 * - always returns 7 even if BufferLength < 7 but doesn't produce a buffer overflow
367 HidD_Hello(OUT PCHAR Buffer
,
368 IN ULONG BufferLength
)
370 const CHAR HelloString
[] = "Hello\n";
374 memcpy(Buffer
, HelloString
, min(sizeof(HelloString
), BufferLength
));
377 return sizeof(HelloString
);
382 * HidD_SetFeature EXPORTED
388 HidD_SetFeature(IN HANDLE HidDeviceObject
,
389 IN PVOID ReportBuffer
,
390 IN ULONG ReportBufferLength
)
393 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_SET_FEATURE
,
394 ReportBuffer
, ReportBufferLength
,
401 * HidD_SetNumInputBuffers EXPORTED
407 HidD_SetNumInputBuffers(IN HANDLE HidDeviceObject
,
408 IN ULONG NumberBuffers
)
411 return DeviceIoControl(HidDeviceObject
, IOCTL_SET_NUM_DEVICE_INPUT_BUFFERS
,
412 &NumberBuffers
, sizeof(ULONG
),
419 * HidD_SetOutputReport EXPORTED
425 HidD_SetOutputReport(IN HANDLE HidDeviceObject
,
426 IN PVOID ReportBuffer
,
427 IN ULONG ReportBufferLength
)
430 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_SET_OUTPUT_REPORT
,
431 ReportBuffer
, ReportBufferLength
,
437 * HidD_GetIndexedString EXPORTED
443 HidD_GetIndexedString(IN HANDLE HidDeviceObject
,
444 IN ULONG StringIndex
,
446 IN ULONG BufferLength
)
449 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_INDEXED_STRING
,
450 &StringIndex
, sizeof(ULONG
),
451 Buffer
, BufferLength
,
456 * HidD_GetMsGenreDescriptor EXPORTED
462 HidD_GetMsGenreDescriptor(IN HANDLE HidDeviceObject
,
464 IN ULONG BufferLength
)
467 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_MS_GENRE_DESCRIPTOR
,
469 Buffer
, BufferLength
,
474 * HidD_GetConfiguration EXPORTED
480 HidD_GetConfiguration(IN HANDLE HidDeviceObject
,
481 OUT PHIDD_CONFIGURATION Configuration
,
482 IN ULONG ConfigurationLength
)
486 Configuration
->cookie
= (PVOID
)HidD_GetConfiguration
;
488 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_DRIVER_CONFIG
,
490 &Configuration
->size
, ConfigurationLength
- sizeof(ULONG
),
491 (PULONG
)&Configuration
->cookie
, NULL
) != 0;
495 * HidD_SetConfiguration EXPORTED
501 HidD_SetConfiguration(IN HANDLE HidDeviceObject
,
502 IN PHIDD_CONFIGURATION Configuration
,
503 IN ULONG ConfigurationLength
)
507 if (Configuration
->cookie
== (PVOID
)HidD_GetConfiguration
)
509 Ret
= DeviceIoControl(HidDeviceObject
, IOCTL_HID_SET_DRIVER_CONFIG
,
511 (PVOID
)&Configuration
->size
, ConfigurationLength
- sizeof(ULONG
),
512 (PULONG
)&Configuration
->cookie
, NULL
) != 0;
516 SetLastError(ERROR_INVALID_PARAMETER
);
523 * HidP_GetUsagesEx EXPORTED
529 HidP_GetUsagesEx(IN HIDP_REPORT_TYPE ReportType
,
530 IN USHORT LinkCollection
,
531 OUT PUSAGE_AND_PAGE ButtonList
,
532 IN OUT ULONG
*UsageLength
,
533 IN PHIDP_PREPARSED_DATA PreparsedData
,
535 IN ULONG ReportLength
)
537 return HidP_GetUsages(ReportType
, ButtonList
->UsagePage
, LinkCollection
, &ButtonList
->Usage
, UsageLength
, PreparsedData
, Report
, ReportLength
);