hid: Implement HidP_GetButtonCaps.
[wine.git] / dlls / hid / hidp.c
blob47864fae6d1dd5656144c33c035a1cb117dea42e
1 /*
2 * Human Input Devices
4 * Copyright (C) 2015 Aric Stewart
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #include <stdarg.h>
25 #define NONAMELESSUNION
26 #define WIN32_NO_STATUS
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winternl.h"
30 #include "winioctl.h"
31 #include "ddk/wdm.h"
33 #include "hidusage.h"
34 #include "ddk/hidpi.h"
35 #include "parse.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(hidp);
40 NTSTATUS WINAPI HidP_GetButtonCaps(HIDP_REPORT_TYPE ReportType, PHIDP_BUTTON_CAPS ButtonCaps,
41 PUSHORT ButtonCapsLength, PHIDP_PREPARSED_DATA PreparsedData)
43 PWINE_HIDP_PREPARSED_DATA data = (PWINE_HIDP_PREPARSED_DATA)PreparsedData;
44 WINE_HID_REPORT *report = NULL;
45 USHORT b_count = 0, r_count = 0;
46 int i,j,u;
48 TRACE("(%i, %p, %p, %p)\n",ReportType, ButtonCaps, ButtonCapsLength, PreparsedData);
50 if (data->magic != HID_MAGIC)
51 return HIDP_STATUS_INVALID_PREPARSED_DATA;
53 switch(ReportType)
55 case HidP_Input:
56 b_count = data->caps.NumberInputButtonCaps;
57 r_count = data->dwInputReportCount;
58 report = HID_INPUT_REPORTS(data);
59 break;
60 case HidP_Output:
61 b_count = data->caps.NumberOutputButtonCaps;
62 r_count = data->dwOutputReportCount;
63 report = HID_OUTPUT_REPORTS(data);
64 break;
65 case HidP_Feature:
66 b_count = data->caps.NumberFeatureButtonCaps;
67 r_count = data->dwFeatureReportCount;
68 report = HID_FEATURE_REPORTS(data);
69 break;
70 default:
71 return HIDP_STATUS_INVALID_REPORT_TYPE;
74 if (!r_count || !b_count || !report)
76 *ButtonCapsLength = 0;
77 return HIDP_STATUS_SUCCESS;
80 b_count = min(b_count, *ButtonCapsLength);
82 u = 0;
83 for (j = 0; j < r_count && u < b_count; j++)
85 for (i = 0; i < report->elementCount && u < b_count; i++)
87 if (report->Elements[i].ElementType == ButtonElement)
88 ButtonCaps[u++] = report->Elements[i].caps.button;
90 report = HID_NEXT_REPORT(data, report);
93 *ButtonCapsLength = b_count;
94 return HIDP_STATUS_SUCCESS;
98 NTSTATUS WINAPI HidP_GetCaps(PHIDP_PREPARSED_DATA PreparsedData,
99 PHIDP_CAPS Capabilities)
101 PWINE_HIDP_PREPARSED_DATA data = (PWINE_HIDP_PREPARSED_DATA)PreparsedData;
103 TRACE("(%p, %p)\n",PreparsedData, Capabilities);
105 if (data->magic != HID_MAGIC)
106 return HIDP_STATUS_INVALID_PREPARSED_DATA;
108 *Capabilities = data->caps;
110 return HIDP_STATUS_SUCCESS;