4 * Copyright (C) 2006 Kevin Koltzau
5 * Copyright (C) 2015 Aric Stewart
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/debug.h"
27 #define WIN32_NO_STATUS
36 #include "ddk/hidclass.h"
37 #include "ddk/hidsdi.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(hid
);
41 static BOOL
sync_ioctl(HANDLE file
, DWORD code
, void *in_buf
, DWORD in_len
, void *out_buf
, DWORD out_len
)
47 ovl
.hEvent
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
48 ret
= DeviceIoControl(file
, code
, in_buf
, in_len
, out_buf
, out_len
, &ret_len
, &ovl
);
49 if (!ret
&& GetLastError() == ERROR_IO_PENDING
)
50 ret
= GetOverlappedResult(file
, &ovl
, &ret_len
, TRUE
);
51 CloseHandle(ovl
.hEvent
);
55 BOOLEAN WINAPI
HidD_FreePreparsedData(PHIDP_PREPARSED_DATA PreparsedData
)
57 TRACE("(%p)\n", PreparsedData
);
58 HeapFree(GetProcessHeap(), 0, PreparsedData
);
62 BOOLEAN WINAPI
HidD_GetAttributes(HANDLE HidDeviceObject
, PHIDD_ATTRIBUTES Attr
)
64 HID_COLLECTION_INFORMATION info
;
67 TRACE("(%p %p)\n", HidDeviceObject
, Attr
);
69 ret
= sync_ioctl(HidDeviceObject
, IOCTL_HID_GET_COLLECTION_INFORMATION
, NULL
, 0, &info
, sizeof(HID_COLLECTION_INFORMATION
));
73 Attr
->Size
= sizeof(HIDD_ATTRIBUTES
);
74 Attr
->VendorID
= info
.VendorID
;
75 Attr
->ProductID
= info
.ProductID
;
76 Attr
->VersionNumber
= info
.VersionNumber
;
81 BOOLEAN WINAPI
HidD_GetFeature(HANDLE HidDeviceObject
, PVOID ReportBuffer
, ULONG ReportBufferLength
)
83 TRACE("(%p %p %u)\n", HidDeviceObject
, ReportBuffer
, ReportBufferLength
);
84 return sync_ioctl(HidDeviceObject
, IOCTL_HID_GET_FEATURE
, NULL
, 0, ReportBuffer
, ReportBufferLength
);
87 void WINAPI
HidD_GetHidGuid(LPGUID guid
)
89 TRACE("(%p)\n", guid
);
90 *guid
= GUID_DEVINTERFACE_HID
;
93 BOOLEAN WINAPI
HidD_GetInputReport(HANDLE HidDeviceObject
, PVOID ReportBuffer
, ULONG ReportBufferLength
)
95 TRACE("(%p %p %u)\n", HidDeviceObject
, ReportBuffer
, ReportBufferLength
);
96 return sync_ioctl(HidDeviceObject
, IOCTL_HID_GET_INPUT_REPORT
, NULL
, 0, ReportBuffer
, ReportBufferLength
);
99 BOOLEAN WINAPI
HidD_GetManufacturerString(HANDLE HidDeviceObject
, PVOID Buffer
, ULONG BufferLength
)
101 TRACE("(%p %p %u)\n", HidDeviceObject
, Buffer
, BufferLength
);
102 return sync_ioctl(HidDeviceObject
, IOCTL_HID_GET_MANUFACTURER_STRING
, NULL
, 0, Buffer
, BufferLength
);
105 BOOLEAN WINAPI
HidD_GetNumInputBuffers(HANDLE HidDeviceObject
, ULONG
*NumberBuffers
)
107 TRACE("(%p %p)\n", HidDeviceObject
, NumberBuffers
);
108 return sync_ioctl(HidDeviceObject
, IOCTL_GET_NUM_DEVICE_INPUT_BUFFERS
, NULL
, 0, NumberBuffers
, sizeof(*NumberBuffers
));
111 BOOLEAN WINAPI
HidD_SetFeature(HANDLE HidDeviceObject
, PVOID ReportBuffer
, ULONG ReportBufferLength
)
113 TRACE("(%p %p %u)\n", HidDeviceObject
, ReportBuffer
, ReportBufferLength
);
114 return sync_ioctl(HidDeviceObject
, IOCTL_HID_SET_FEATURE
, ReportBuffer
, ReportBufferLength
, NULL
, 0);
117 BOOLEAN WINAPI
HidD_SetNumInputBuffers(HANDLE HidDeviceObject
, ULONG NumberBuffers
)
119 TRACE("(%p %i)\n", HidDeviceObject
, NumberBuffers
);
120 return sync_ioctl(HidDeviceObject
, IOCTL_SET_NUM_DEVICE_INPUT_BUFFERS
, &NumberBuffers
, sizeof(NumberBuffers
), NULL
, 0);
123 BOOLEAN WINAPI
HidD_GetProductString(HANDLE HidDeviceObject
, PVOID Buffer
, ULONG BufferLength
)
125 TRACE("(%p %p %u)\n", HidDeviceObject
, Buffer
, BufferLength
);
126 return sync_ioctl(HidDeviceObject
, IOCTL_HID_GET_PRODUCT_STRING
, NULL
, 0, Buffer
, BufferLength
);
129 BOOLEAN WINAPI
HidD_GetSerialNumberString(HANDLE HidDeviceObject
, PVOID Buffer
, ULONG BufferLength
)
131 TRACE("(%p %p %u)\n", HidDeviceObject
, Buffer
, BufferLength
);
132 return sync_ioctl(HidDeviceObject
, IOCTL_HID_GET_SERIALNUMBER_STRING
, NULL
, 0, Buffer
, BufferLength
);
135 BOOLEAN WINAPI
HidD_GetPreparsedData(HANDLE HidDeviceObject
, PHIDP_PREPARSED_DATA
*PreparsedData
)
137 HID_COLLECTION_INFORMATION info
;
138 PHIDP_PREPARSED_DATA data
;
140 TRACE("(%p %p)\n", HidDeviceObject
, PreparsedData
);
142 if (!sync_ioctl(HidDeviceObject
, IOCTL_HID_GET_COLLECTION_INFORMATION
, NULL
, 0, &info
, sizeof(info
)))
145 if (!(data
= HeapAlloc(GetProcessHeap(), 0, info
.DescriptorSize
))) return FALSE
;
147 if (!sync_ioctl(HidDeviceObject
, IOCTL_HID_GET_COLLECTION_DESCRIPTOR
, NULL
, 0, data
, info
.DescriptorSize
))
149 HeapFree( GetProcessHeap(), 0, data
);
152 *PreparsedData
= data
;
156 BOOLEAN WINAPI
HidD_SetOutputReport(HANDLE HidDeviceObject
, void *ReportBuffer
, ULONG ReportBufferLength
)
158 TRACE("(%p %p %u)\n", HidDeviceObject
, ReportBuffer
, ReportBufferLength
);
159 return sync_ioctl(HidDeviceObject
, IOCTL_HID_SET_OUTPUT_REPORT
, ReportBuffer
, ReportBufferLength
, NULL
, 0);
162 BOOLEAN WINAPI
HidD_GetIndexedString(HANDLE file
, ULONG index
, void *buffer
, ULONG length
)
164 TRACE("file %p, index %u, buffer %p, length %u.\n", file
, index
, buffer
, length
);
165 return sync_ioctl(file
, IOCTL_HID_GET_INDEXED_STRING
, &index
, sizeof(index
), buffer
, length
);
168 BOOLEAN WINAPI
HidD_FlushQueue(HANDLE file
)
170 TRACE("file %p.\n", file
);
171 return sync_ioctl(file
, IOCTL_HID_FLUSH_QUEUE
, NULL
, 0, NULL
, 0);