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>
36 HINSTANCE hDllInstance
;
38 /* device interface GUID for HIDClass devices */
39 const GUID HidClassGuid
= {0x4D1E55B2, 0xF16F, 0x11CF, {0x88,0xCB,0x00,0x11,0x11,0x00,0x00,0x30}};
42 DllMain(HINSTANCE hinstDLL
,
48 case DLL_PROCESS_ATTACH
:
49 hDllInstance
= hinstDLL
;
52 case DLL_THREAD_ATTACH
:
55 case DLL_THREAD_DETACH
:
58 case DLL_PROCESS_DETACH
:
66 * HidD_FlushQueue EXPORTED
72 HidD_FlushQueue(IN HANDLE HidDeviceObject
)
75 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_FLUSH_QUEUE
,
83 * HidD_FreePreparsedData EXPORTED
89 HidD_FreePreparsedData(IN PHIDP_PREPARSED_DATA PreparsedData
)
91 return (LocalFree((HLOCAL
)PreparsedData
) == NULL
);
96 * HidD_GetAttributes EXPORTED
102 HidD_GetAttributes(IN HANDLE HidDeviceObject
,
103 OUT PHIDD_ATTRIBUTES Attributes
)
105 HID_COLLECTION_INFORMATION hci
;
108 if(!DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_COLLECTION_INFORMATION
,
110 &hci
, sizeof(HID_COLLECTION_INFORMATION
),
116 /* copy the fields */
117 Attributes
->Size
= sizeof(HIDD_ATTRIBUTES
);
118 Attributes
->VendorID
= hci
.VendorID
;
119 Attributes
->ProductID
= hci
.ProductID
;
120 Attributes
->VersionNumber
= hci
.VersionNumber
;
127 * HidP_GetButtonCaps EXPORTED
133 HidP_GetButtonCaps(IN HIDP_REPORT_TYPE ReportType
,
134 OUT PHIDP_BUTTON_CAPS ButtonCaps
,
135 IN OUT PUSHORT ButtonCapsLength
,
136 IN PHIDP_PREPARSED_DATA PreparsedData
)
138 return HidP_GetSpecificButtonCaps(ReportType
, 0, 0, 0, ButtonCaps
,
139 ButtonCapsLength
, PreparsedData
);
144 * HidD_GetFeature EXPORTED
150 HidD_GetFeature(IN HANDLE HidDeviceObject
,
151 OUT PVOID ReportBuffer
,
152 IN ULONG ReportBufferLength
)
155 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_FEATURE
,
157 ReportBuffer
, ReportBufferLength
,
163 * HidD_GetHidGuid EXPORTED
169 HidD_GetHidGuid(OUT LPGUID HidGuid
)
171 *HidGuid
= HidClassGuid
;
176 * HidD_GetInputReport EXPORTED
182 HidD_GetInputReport(IN HANDLE HidDeviceObject
,
183 IN OUT PVOID ReportBuffer
,
184 IN ULONG ReportBufferLength
)
187 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_INPUT_REPORT
,
189 ReportBuffer
, ReportBufferLength
,
195 * HidD_GetManufacturerString EXPORTED
201 HidD_GetManufacturerString(IN HANDLE HidDeviceObject
,
203 IN ULONG BufferLength
)
206 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_MANUFACTURER_STRING
,
208 Buffer
, BufferLength
,
214 * HidD_GetNumInputBuffers EXPORTED
220 HidD_GetNumInputBuffers(IN HANDLE HidDeviceObject
,
221 OUT PULONG NumberBuffers
)
224 return DeviceIoControl(HidDeviceObject
, IOCTL_GET_NUM_DEVICE_INPUT_BUFFERS
,
226 NumberBuffers
, sizeof(ULONG
),
232 * HidD_GetPhysicalDescriptor EXPORTED
238 HidD_GetPhysicalDescriptor(IN HANDLE HidDeviceObject
,
240 IN ULONG BufferLength
)
243 return DeviceIoControl(HidDeviceObject
, IOCTL_GET_PHYSICAL_DESCRIPTOR
,
245 Buffer
, BufferLength
,
251 * HidD_GetPreparsedData EXPORTED
257 HidD_GetPreparsedData(IN HANDLE HidDeviceObject
,
258 OUT PHIDP_PREPARSED_DATA
*PreparsedData
)
260 HID_COLLECTION_INFORMATION hci
;
264 if(PreparsedData
== NULL
)
269 if(!DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_COLLECTION_INFORMATION
,
271 &hci
, sizeof(HID_COLLECTION_INFORMATION
),
277 *PreparsedData
= LocalAlloc(LHND
, hci
.DescriptorSize
);
278 if(*PreparsedData
== NULL
)
280 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
284 Ret
= DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_COLLECTION_DESCRIPTOR
,
286 *PreparsedData
, hci
.DescriptorSize
,
291 /* FIXME - Free the buffer in case we failed to get the descriptor? */
292 LocalFree((HLOCAL
)*PreparsedData
);
297 /* should we truncate the memory in case RetLen < hci.DescriptorSize? */
306 * HidD_GetProductString EXPORTED
312 HidD_GetProductString(IN HANDLE HidDeviceObject
,
314 IN ULONG BufferLength
)
317 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_PRODUCT_STRING
,
319 Buffer
, BufferLength
,
325 * HidD_GetSerialNumberString EXPORTED
331 HidD_GetSerialNumberString(IN HANDLE HidDeviceObject
,
333 IN ULONG BufferLength
)
336 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_SERIALNUMBER_STRING
,
338 Buffer
, BufferLength
,
344 * HidP_GetValueCaps EXPORTED
350 HidP_GetValueCaps(IN HIDP_REPORT_TYPE ReportType
,
351 OUT PHIDP_VALUE_CAPS ValueCaps
,
352 IN OUT PUSHORT ValueCapsLength
,
353 IN PHIDP_PREPARSED_DATA PreparsedData
)
355 return HidP_GetSpecificValueCaps(ReportType
, 0, 0, 0, ValueCaps
,
356 ValueCapsLength
, PreparsedData
);
361 * HidD_Hello EXPORTED
363 * Undocumented easter egg function. It fills the buffer with "Hello\n"
364 * and returns number of bytes filled in (lstrlen(Buffer) + 1 == 7)
366 * Bugs: - doesn't check Buffer for NULL
367 * - always returns 7 even if BufferLength < 7 but doesn't produce a buffer overflow
373 HidD_Hello(OUT PCHAR Buffer
,
374 IN ULONG BufferLength
)
376 const CHAR HelloString
[] = "Hello\n";
380 memcpy(Buffer
, HelloString
, min(sizeof(HelloString
), BufferLength
));
383 return sizeof(HelloString
);
388 * HidD_SetFeature EXPORTED
394 HidD_SetFeature(IN HANDLE HidDeviceObject
,
395 IN PVOID ReportBuffer
,
396 IN ULONG ReportBufferLength
)
399 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_SET_FEATURE
,
400 ReportBuffer
, ReportBufferLength
,
407 * HidD_SetNumInputBuffers EXPORTED
413 HidD_SetNumInputBuffers(IN HANDLE HidDeviceObject
,
414 IN ULONG NumberBuffers
)
417 return DeviceIoControl(HidDeviceObject
, IOCTL_SET_NUM_DEVICE_INPUT_BUFFERS
,
418 &NumberBuffers
, sizeof(ULONG
),
425 * HidD_SetOutputReport EXPORTED
431 HidD_SetOutputReport(IN HANDLE HidDeviceObject
,
432 IN PVOID ReportBuffer
,
433 IN ULONG ReportBufferLength
)
436 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_SET_OUTPUT_REPORT
,
437 ReportBuffer
, ReportBufferLength
,
443 * HidD_GetIndexedString EXPORTED
449 HidD_GetIndexedString(IN HANDLE HidDeviceObject
,
450 IN ULONG StringIndex
,
452 IN ULONG BufferLength
)
455 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_INDEXED_STRING
,
456 &StringIndex
, sizeof(ULONG
),
457 Buffer
, BufferLength
,
462 * HidD_GetMsGenreDescriptor EXPORTED
468 HidD_GetMsGenreDescriptor(IN HANDLE HidDeviceObject
,
470 IN ULONG BufferLength
)
473 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_MS_GENRE_DESCRIPTOR
,
475 Buffer
, BufferLength
,
480 * HidD_GetConfiguration EXPORTED
486 HidD_GetConfiguration(IN HANDLE HidDeviceObject
,
487 OUT PHIDD_CONFIGURATION Configuration
,
488 IN ULONG ConfigurationLength
)
492 Configuration
->cookie
= (PVOID
)HidD_GetConfiguration
;
494 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_DRIVER_CONFIG
,
496 &Configuration
->size
, ConfigurationLength
- sizeof(ULONG
),
497 (PULONG
)&Configuration
->cookie
, NULL
) != 0;
501 * HidD_SetConfiguration EXPORTED
507 HidD_SetConfiguration(IN HANDLE HidDeviceObject
,
508 IN PHIDD_CONFIGURATION Configuration
,
509 IN ULONG ConfigurationLength
)
513 if (Configuration
->cookie
== (PVOID
)HidD_GetConfiguration
)
515 Ret
= DeviceIoControl(HidDeviceObject
, IOCTL_HID_SET_DRIVER_CONFIG
,
517 (PVOID
)&Configuration
->size
, ConfigurationLength
- sizeof(ULONG
),
518 (PULONG
)&Configuration
->cookie
, NULL
) != 0;
522 SetLastError(ERROR_INVALID_PARAMETER
);
529 * HidP_GetUsagesEx EXPORTED
535 HidP_GetUsagesEx(IN HIDP_REPORT_TYPE ReportType
,
536 IN USHORT LinkCollection
,
537 OUT PUSAGE_AND_PAGE ButtonList
,
538 IN OUT ULONG
*UsageLength
,
539 IN PHIDP_PREPARSED_DATA PreparsedData
,
541 IN ULONG ReportLength
)
543 return HidP_GetUsages(ReportType
, ButtonList
->UsagePage
, LinkCollection
, &ButtonList
->Usage
, UsageLength
, PreparsedData
, Report
, ReportLength
);