2015-09-14 16:58:30 +02:00
|
|
|
/*
|
|
|
|
* HID descriptor parsing
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Aric Stewart
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
#include "hid.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "wine/list.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(hid);
|
|
|
|
|
2015-10-06 23:20:51 +02:00
|
|
|
/* Flags that are defined in the document
|
|
|
|
"Device Class Definition for Human Interface Devices" */
|
2015-09-14 16:58:30 +02:00
|
|
|
enum {
|
2015-10-06 23:20:51 +02:00
|
|
|
INPUT_DATA_CONST = 0x01, /* Data (0) | Constant (1) */
|
|
|
|
INPUT_ARRAY_VAR = 0x02, /* Array (0) | Variable (1) */
|
|
|
|
INPUT_ABS_REL = 0x04, /* Absolute (0) | Relative (1) */
|
|
|
|
INPUT_WRAP = 0x08, /* No Wrap (0) | Wrap (1) */
|
|
|
|
INPUT_LINEAR = 0x10, /* Linear (0) | Non Linear (1) */
|
|
|
|
INPUT_PREFSTATE = 0x20, /* Preferred State (0) | No Preferred (1) */
|
|
|
|
INPUT_NULL = 0x40, /* No Null position (0) | Null state(1) */
|
|
|
|
INPUT_VOLATILE = 0x80, /* Non Volatile (0) | Volatile (1) */
|
|
|
|
INPUT_BITFIELD = 0x100 /* Bit Field (0) | Buffered Bytes (1) */
|
2015-09-14 16:58:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
TAG_TYPE_MAIN = 0x0,
|
|
|
|
TAG_TYPE_GLOBAL,
|
|
|
|
TAG_TYPE_LOCAL,
|
|
|
|
TAG_TYPE_RESERVED,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
TAG_MAIN_INPUT = 0x08,
|
|
|
|
TAG_MAIN_OUTPUT = 0x09,
|
|
|
|
TAG_MAIN_FEATURE = 0x0B,
|
|
|
|
TAG_MAIN_COLLECTION = 0x0A,
|
|
|
|
TAG_MAIN_END_COLLECTION = 0x0C
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
TAG_GLOBAL_USAGE_PAGE = 0x0,
|
|
|
|
TAG_GLOBAL_LOGICAL_MINIMUM,
|
|
|
|
TAG_GLOBAL_LOGICAL_MAXIMUM,
|
|
|
|
TAG_GLOBAL_PHYSICAL_MINIMUM,
|
|
|
|
TAG_GLOBAL_PHYSICAL_MAXIMUM,
|
|
|
|
TAG_GLOBAL_UNIT_EXPONENT,
|
|
|
|
TAG_GLOBAL_UNIT,
|
|
|
|
TAG_GLOBAL_REPORT_SIZE,
|
|
|
|
TAG_GLOBAL_REPORT_ID,
|
|
|
|
TAG_GLOBAL_REPORT_COUNT,
|
|
|
|
TAG_GLOBAL_PUSH,
|
|
|
|
TAG_GLOBAL_POP
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
TAG_LOCAL_USAGE = 0x0,
|
|
|
|
TAG_LOCAL_USAGE_MINIMUM,
|
|
|
|
TAG_LOCAL_USAGE_MAXIMUM,
|
|
|
|
TAG_LOCAL_DESIGNATOR_INDEX,
|
|
|
|
TAG_LOCAL_DESIGNATOR_MINIMUM,
|
|
|
|
TAG_LOCAL_DESIGNATOR_MAXIMUM,
|
|
|
|
TAG_LOCAL_STRING_INDEX,
|
|
|
|
TAG_LOCAL_STRING_MINIMUM,
|
|
|
|
TAG_LOCAL_STRING_MAXIMUM,
|
|
|
|
TAG_LOCAL_DELIMITER
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const char* const feature_string[] =
|
|
|
|
{ "Input", "Output", "Feature" };
|
|
|
|
|
|
|
|
struct caps {
|
|
|
|
USAGE UsagePage;
|
|
|
|
LONG LogicalMin;
|
|
|
|
LONG LogicalMax;
|
|
|
|
LONG PhysicalMin;
|
|
|
|
LONG PhysicalMax;
|
|
|
|
ULONG UnitsExp;
|
|
|
|
ULONG Units;
|
|
|
|
USHORT BitSize;
|
|
|
|
UCHAR ReportID;
|
|
|
|
USHORT ReportCount;
|
|
|
|
|
|
|
|
BOOLEAN IsRange;
|
|
|
|
BOOLEAN IsStringRange;
|
|
|
|
BOOLEAN IsDesignatorRange;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
USAGE UsageMin;
|
|
|
|
USAGE UsageMax;
|
|
|
|
USHORT StringMin;
|
|
|
|
USHORT StringMax;
|
|
|
|
USHORT DesignatorMin;
|
|
|
|
USHORT DesignatorMax;
|
|
|
|
} Range;
|
|
|
|
struct {
|
2019-05-13 12:34:12 +02:00
|
|
|
USHORT Usage;
|
2015-09-14 16:58:30 +02:00
|
|
|
USAGE Reserved1;
|
|
|
|
USHORT StringIndex;
|
|
|
|
USHORT Reserved2;
|
|
|
|
USHORT DesignatorIndex;
|
|
|
|
USHORT Reserved3;
|
|
|
|
} NotRange;
|
|
|
|
} DUMMYUNIONNAME;
|
|
|
|
|
|
|
|
int Delim;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct feature {
|
|
|
|
struct list entry;
|
|
|
|
struct caps caps;
|
|
|
|
|
|
|
|
HIDP_REPORT_TYPE type;
|
|
|
|
BOOLEAN isData;
|
|
|
|
BOOLEAN isArray;
|
|
|
|
BOOLEAN IsAbsolute;
|
|
|
|
BOOLEAN Wrap;
|
|
|
|
BOOLEAN Linear;
|
|
|
|
BOOLEAN prefState;
|
|
|
|
BOOLEAN HasNull;
|
|
|
|
BOOLEAN Volatile;
|
|
|
|
BOOLEAN BitField;
|
|
|
|
|
|
|
|
unsigned int index;
|
|
|
|
struct collection *collection;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* const collection_string[] = {
|
|
|
|
"Physical",
|
|
|
|
"Application",
|
|
|
|
"Logical",
|
|
|
|
"Report",
|
|
|
|
"Named Array",
|
|
|
|
"Usage Switch",
|
|
|
|
"Usage Modifier",
|
|
|
|
};
|
|
|
|
|
|
|
|
struct collection {
|
|
|
|
struct list entry;
|
|
|
|
struct caps caps;
|
|
|
|
unsigned int index;
|
|
|
|
unsigned int type;
|
|
|
|
struct collection *parent;
|
|
|
|
struct list features;
|
|
|
|
struct list collections;
|
|
|
|
};
|
|
|
|
|
2016-11-14 15:29:20 +01:00
|
|
|
struct caps_stack {
|
|
|
|
struct list entry;
|
|
|
|
struct caps caps;
|
|
|
|
};
|
|
|
|
|
2015-09-14 16:58:30 +02:00
|
|
|
static const char* debugstr_usages(struct caps *caps)
|
|
|
|
{
|
|
|
|
if (!caps->IsRange)
|
2019-05-13 12:34:12 +02:00
|
|
|
return wine_dbg_sprintf("[0x%x]", caps->u.NotRange.Usage);
|
2015-09-14 16:58:30 +02:00
|
|
|
else
|
|
|
|
return wine_dbg_sprintf("[0x%x - 0x%x]", caps->u.Range.UsageMin, caps->u.Range.UsageMax);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* debugstr_stringindex(struct caps *caps)
|
|
|
|
{
|
|
|
|
if (!caps->IsStringRange)
|
|
|
|
return wine_dbg_sprintf("%i", caps->u.NotRange.StringIndex);
|
|
|
|
else
|
|
|
|
return wine_dbg_sprintf("[%i - %i]", caps->u.Range.StringMin, caps->u.Range.StringMax);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* debugstr_designatorindex(struct caps *caps)
|
|
|
|
{
|
|
|
|
if (!caps->IsDesignatorRange)
|
|
|
|
return wine_dbg_sprintf("%i", caps->u.NotRange.DesignatorIndex);
|
|
|
|
else
|
|
|
|
return wine_dbg_sprintf("[%i - %i]", caps->u.Range.DesignatorMin, caps->u.Range.DesignatorMax);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void debugstr_caps(const char* type, struct caps *caps)
|
|
|
|
{
|
|
|
|
if (!caps)
|
|
|
|
return;
|
2019-05-13 12:33:56 +02:00
|
|
|
TRACE("(%s Caps: UsagePage 0x%x; LogicalMin %i; LogicalMax %i; PhysicalMin %i; "
|
|
|
|
"PhysicalMax %i; UnitsExp %i; Units %i; BitSize %i; ReportID %i; ReportCount %i; "
|
|
|
|
"Usage %s; StringIndex %s; DesignatorIndex %s; Delim %i;)\n",
|
2015-09-14 16:58:30 +02:00
|
|
|
type,
|
|
|
|
caps->UsagePage,
|
|
|
|
caps->LogicalMin,
|
|
|
|
caps->LogicalMax,
|
|
|
|
caps->PhysicalMin,
|
|
|
|
caps->PhysicalMax,
|
|
|
|
caps->UnitsExp,
|
|
|
|
caps->Units,
|
|
|
|
caps->BitSize,
|
|
|
|
caps->ReportID,
|
|
|
|
caps->ReportCount,
|
|
|
|
debugstr_usages(caps),
|
|
|
|
debugstr_stringindex(caps),
|
|
|
|
debugstr_designatorindex(caps),
|
|
|
|
caps->Delim);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void debug_feature(struct feature *feature)
|
|
|
|
{
|
|
|
|
if (!feature)
|
|
|
|
return;
|
|
|
|
TRACE("[Feature type %s [%i]; %s; %s; %s; %s; %s; %s; %s; %s; %s]\n",
|
|
|
|
feature_string[feature->type],
|
|
|
|
feature->index,
|
|
|
|
(feature->isData)?"Data":"Const",
|
|
|
|
(feature->isArray)?"Array":"Var",
|
|
|
|
(feature->IsAbsolute)?"Abs":"Rel",
|
|
|
|
(feature->Wrap)?"Wrap":"NoWrap",
|
|
|
|
(feature->Linear)?"Linear":"NonLinear",
|
|
|
|
(feature->prefState)?"PrefStat":"NoPrefState",
|
|
|
|
(feature->HasNull)?"HasNull":"NoNull",
|
|
|
|
(feature->Volatile)?"Volatile":"NonVolatile",
|
|
|
|
(feature->BitField)?"BitField":"Buffered");
|
|
|
|
|
|
|
|
debugstr_caps("Feature", &feature->caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void debug_collection(struct collection *collection)
|
|
|
|
{
|
|
|
|
struct feature *fentry;
|
|
|
|
struct collection *centry;
|
|
|
|
if (TRACE_ON(hid))
|
|
|
|
{
|
2019-05-13 12:33:56 +02:00
|
|
|
TRACE("START Collection %i <<< %s, parent: %p, %i features, %i collections\n",
|
|
|
|
collection->index, collection_string[collection->type], collection->parent,
|
|
|
|
list_count(&collection->features), list_count(&collection->collections));
|
2015-09-14 16:58:30 +02:00
|
|
|
debugstr_caps("Collection", &collection->caps);
|
2019-05-13 12:34:04 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(fentry, &collection->features, struct feature, entry)
|
2015-09-14 16:58:30 +02:00
|
|
|
debug_feature(fentry);
|
|
|
|
LIST_FOR_EACH_ENTRY(centry, &collection->collections, struct collection, entry)
|
|
|
|
debug_collection(centry);
|
|
|
|
TRACE(">>> END Collection %i\n", collection->index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void debug_print_button_cap(const CHAR * type, WINE_HID_ELEMENT *wine_element)
|
|
|
|
{
|
|
|
|
if (!wine_element->caps.button.IsRange)
|
|
|
|
TRACE("%s Button: 0x%x/0x%04x: ReportId %i, startBit %i/1\n" , type,
|
|
|
|
wine_element->caps.button.UsagePage,
|
|
|
|
wine_element->caps.button.u.NotRange.Usage,
|
|
|
|
wine_element->caps.value.ReportID,
|
|
|
|
wine_element->valueStartBit);
|
|
|
|
else
|
|
|
|
TRACE("%s Button: 0x%x/[0x%04x-0x%04x]: ReportId %i, startBit %i/%i\n" ,type,
|
|
|
|
wine_element->caps.button.UsagePage,
|
|
|
|
wine_element->caps.button.u.Range.UsageMin,
|
|
|
|
wine_element->caps.button.u.Range.UsageMax,
|
|
|
|
wine_element->caps.value.ReportID,
|
|
|
|
wine_element->valueStartBit,
|
|
|
|
wine_element->bitCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void debug_print_value_cap(const CHAR * type, WINE_HID_ELEMENT *wine_element)
|
|
|
|
{
|
|
|
|
TRACE("%s Value: 0x%x/0x%x: ReportId %i, IsAbsolute %i, HasNull %i, "
|
|
|
|
"Bit Size %i, ReportCount %i, UnitsExp %i, Units %i, "
|
|
|
|
"LogicalMin %i, Logical Max %i, PhysicalMin %i, "
|
|
|
|
"PhysicalMax %i -- StartBit %i/%i\n", type,
|
|
|
|
wine_element->caps.value.UsagePage,
|
|
|
|
wine_element->caps.value.u.NotRange.Usage,
|
|
|
|
wine_element->caps.value.ReportID,
|
|
|
|
wine_element->caps.value.IsAbsolute,
|
|
|
|
wine_element->caps.value.HasNull,
|
|
|
|
wine_element->caps.value.BitSize,
|
|
|
|
wine_element->caps.value.ReportCount,
|
|
|
|
wine_element->caps.value.UnitsExp,
|
|
|
|
wine_element->caps.value.Units,
|
|
|
|
wine_element->caps.value.LogicalMin,
|
|
|
|
wine_element->caps.value.LogicalMax,
|
|
|
|
wine_element->caps.value.PhysicalMin,
|
|
|
|
wine_element->caps.value.PhysicalMax,
|
|
|
|
wine_element->valueStartBit,
|
|
|
|
wine_element->bitCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void debug_print_element(const CHAR* type, WINE_HID_ELEMENT *wine_element)
|
|
|
|
{
|
|
|
|
if (wine_element->ElementType == ButtonElement)
|
|
|
|
debug_print_button_cap(type, wine_element);
|
|
|
|
else if (wine_element->ElementType == ValueElement)
|
|
|
|
debug_print_value_cap(type, wine_element);
|
|
|
|
else
|
|
|
|
TRACE("%s: UNKNOWN\n", type);
|
|
|
|
}
|
|
|
|
|
2019-05-13 12:33:56 +02:00
|
|
|
static void debug_print_report(const char* type, WINE_HIDP_PREPARSED_DATA *data,
|
|
|
|
WINE_HID_REPORT *report)
|
2015-09-14 16:58:30 +02:00
|
|
|
{
|
2019-05-13 12:33:56 +02:00
|
|
|
WINE_HID_ELEMENT *elem = HID_ELEMS(data);
|
2015-09-14 16:58:30 +02:00
|
|
|
unsigned int i;
|
2019-05-13 12:33:56 +02:00
|
|
|
TRACE("START Report %i <<< %s report : bitSize: %i elementCount: %i\n",
|
2015-09-14 16:58:30 +02:00
|
|
|
report->reportID,
|
|
|
|
type,
|
2019-05-13 12:33:56 +02:00
|
|
|
report->bitSize,
|
2015-09-14 16:58:30 +02:00
|
|
|
report->elementCount);
|
|
|
|
for (i = 0; i < report->elementCount; i++)
|
2019-05-13 12:33:56 +02:00
|
|
|
{
|
|
|
|
debug_print_element(type, &elem[report->elementIdx + i]);
|
|
|
|
}
|
2015-09-14 16:58:30 +02:00
|
|
|
TRACE(">>> END Report %i\n",report->reportID);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void debug_print_preparsed(WINE_HIDP_PREPARSED_DATA *data)
|
|
|
|
{
|
2019-05-13 12:33:56 +02:00
|
|
|
unsigned int i, end;
|
2015-09-14 16:58:30 +02:00
|
|
|
if (TRACE_ON(hid))
|
|
|
|
{
|
2019-05-13 12:33:56 +02:00
|
|
|
TRACE("START PREPARSED Data <<< dwSize: %i Usage: %i, UsagePage: %i, "
|
|
|
|
"InputReportByteLength: %i, tOutputReportByteLength: %i, "
|
|
|
|
"FeatureReportByteLength: %i, NumberLinkCollectionNodes: %i, "
|
|
|
|
"NumberInputButtonCaps: %i, NumberInputValueCaps: %i, "
|
|
|
|
"NumberInputDataIndices: %i, NumberOutputButtonCaps: %i, "
|
|
|
|
"NumberOutputValueCaps: %i, NumberOutputDataIndices: %i, "
|
|
|
|
"NumberFeatureButtonCaps: %i, NumberFeatureValueCaps: %i, "
|
|
|
|
"NumberFeatureDataIndices: %i, reportCount[HidP_Input]: %i, "
|
|
|
|
"reportCount[HidP_Output]: %i, reportCount[HidP_Feature]: %i, "
|
|
|
|
"elementOffset: %i\n",
|
2015-09-14 16:58:30 +02:00
|
|
|
data->dwSize,
|
|
|
|
data->caps.Usage,
|
|
|
|
data->caps.UsagePage,
|
|
|
|
data->caps.InputReportByteLength,
|
|
|
|
data->caps.OutputReportByteLength,
|
|
|
|
data->caps.FeatureReportByteLength,
|
|
|
|
data->caps.NumberLinkCollectionNodes,
|
|
|
|
data->caps.NumberInputButtonCaps,
|
|
|
|
data->caps.NumberInputValueCaps,
|
|
|
|
data->caps.NumberInputDataIndices,
|
|
|
|
data->caps.NumberOutputButtonCaps,
|
|
|
|
data->caps.NumberOutputValueCaps,
|
|
|
|
data->caps.NumberOutputDataIndices,
|
|
|
|
data->caps.NumberFeatureButtonCaps,
|
|
|
|
data->caps.NumberFeatureValueCaps,
|
|
|
|
data->caps.NumberFeatureDataIndices,
|
2019-05-13 12:33:56 +02:00
|
|
|
data->reportCount[HidP_Input],
|
|
|
|
data->reportCount[HidP_Output],
|
|
|
|
data->reportCount[HidP_Feature],
|
|
|
|
data->elementOffset);
|
|
|
|
|
|
|
|
end = data->reportCount[HidP_Input];
|
|
|
|
for (i = 0; i < end; i++)
|
2015-09-14 16:58:30 +02:00
|
|
|
{
|
2019-05-13 12:33:56 +02:00
|
|
|
debug_print_report("INPUT", data, &data->reports[i]);
|
2015-09-14 16:58:30 +02:00
|
|
|
}
|
2019-05-13 12:33:56 +02:00
|
|
|
end += data->reportCount[HidP_Output];
|
|
|
|
for (; i < end; i++)
|
2015-09-14 16:58:30 +02:00
|
|
|
{
|
2019-05-13 12:33:56 +02:00
|
|
|
debug_print_report("OUTPUT", data, &data->reports[i]);
|
2015-09-14 16:58:30 +02:00
|
|
|
}
|
2019-05-13 12:33:56 +02:00
|
|
|
end += data->reportCount[HidP_Feature];
|
|
|
|
for (i = 0; i < end; i++)
|
2015-09-14 16:58:30 +02:00
|
|
|
{
|
2019-05-13 12:33:56 +02:00
|
|
|
debug_print_report("FEATURE", data, &data->reports[i]);
|
2015-09-14 16:58:30 +02:00
|
|
|
}
|
|
|
|
TRACE(">>> END Preparsed Data\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-06 20:11:49 +01:00
|
|
|
static int getValue(int bsize, int source, BOOL allow_negative)
|
2015-09-14 16:58:30 +02:00
|
|
|
{
|
|
|
|
int mask = 0xff;
|
|
|
|
int negative = 0x80;
|
|
|
|
int outofrange = 0x100;
|
|
|
|
int value;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (bsize == 4)
|
|
|
|
return source;
|
|
|
|
|
|
|
|
for (i = 1; i < bsize; i++)
|
|
|
|
{
|
|
|
|
mask = (mask<<8) + 0xff;
|
|
|
|
negative = (negative<<8);
|
|
|
|
outofrange = (outofrange<<8);
|
|
|
|
}
|
|
|
|
value = (source&mask);
|
2016-12-06 20:11:49 +01:00
|
|
|
if (allow_negative && value&negative)
|
2015-09-14 16:58:30 +02:00
|
|
|
value = -1 * (outofrange - value);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2015-10-26 19:02:40 +01:00
|
|
|
static void parse_io_feature(unsigned int bSize, int itemVal, int bTag,
|
|
|
|
unsigned int *feature_index,
|
|
|
|
struct feature *feature)
|
2015-09-14 16:58:30 +02:00
|
|
|
{
|
2017-01-30 16:00:29 +01:00
|
|
|
if (bSize == 0)
|
2015-09-14 16:58:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-06 23:20:51 +02:00
|
|
|
feature->isData = ((itemVal & INPUT_DATA_CONST) == 0);
|
|
|
|
feature->isArray = ((itemVal & INPUT_ARRAY_VAR) == 0);
|
|
|
|
feature->IsAbsolute = ((itemVal & INPUT_ABS_REL) == 0);
|
|
|
|
feature->Wrap = ((itemVal & INPUT_WRAP) != 0);
|
|
|
|
feature->Linear = ((itemVal & INPUT_LINEAR) == 0);
|
|
|
|
feature->prefState = ((itemVal & INPUT_PREFSTATE) == 0);
|
|
|
|
feature->HasNull = ((itemVal & INPUT_NULL) != 0);
|
2015-09-14 16:58:30 +02:00
|
|
|
|
|
|
|
if (bTag != TAG_MAIN_INPUT)
|
|
|
|
{
|
2015-10-06 23:20:51 +02:00
|
|
|
feature->Volatile = ((itemVal & INPUT_VOLATILE) != 0);
|
2015-09-14 16:58:30 +02:00
|
|
|
}
|
|
|
|
if (bSize > 1)
|
|
|
|
{
|
2015-10-06 23:20:51 +02:00
|
|
|
feature->BitField = ((itemVal & INPUT_BITFIELD) == 0);
|
2015-09-14 16:58:30 +02:00
|
|
|
}
|
|
|
|
feature->index = *feature_index;
|
|
|
|
*feature_index = *feature_index + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-26 19:02:40 +01:00
|
|
|
static void parse_collection(unsigned int bSize, int itemVal,
|
|
|
|
struct collection *collection)
|
2015-09-14 16:58:30 +02:00
|
|
|
{
|
2017-11-01 17:41:37 +01:00
|
|
|
if (bSize)
|
|
|
|
{
|
2015-09-14 16:58:30 +02:00
|
|
|
collection->type = itemVal;
|
|
|
|
|
|
|
|
if (itemVal >= 0x07 && itemVal <= 0x7F) {
|
|
|
|
ERR(" (Reserved 0x%x )\n", itemVal);
|
|
|
|
}
|
|
|
|
else if (itemVal >= 0x80 && itemVal <= 0xFF) {
|
|
|
|
ERR(" (Vendor Defined 0x%x )\n", itemVal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void new_caps(struct caps *caps)
|
|
|
|
{
|
|
|
|
caps->IsRange = 0;
|
|
|
|
caps->IsStringRange = 0;
|
|
|
|
caps->IsDesignatorRange = 0;
|
2019-05-13 12:34:12 +02:00
|
|
|
caps->u.NotRange.Usage = 0;
|
2015-09-14 16:58:30 +02:00
|
|
|
}
|
|
|
|
|
2016-11-14 15:29:20 +01:00
|
|
|
static int parse_descriptor(BYTE *descriptor, unsigned int index, unsigned int length,
|
|
|
|
unsigned int *feature_index, unsigned int *collection_index,
|
|
|
|
struct collection *collection, struct caps *caps,
|
2019-05-13 12:34:04 +02:00
|
|
|
struct list *stack)
|
2015-09-14 16:58:30 +02:00
|
|
|
{
|
2019-05-13 12:34:12 +02:00
|
|
|
int usages_top = 0;
|
|
|
|
USAGE usages[256];
|
2015-09-14 16:58:30 +02:00
|
|
|
unsigned int i;
|
2019-05-13 12:34:12 +02:00
|
|
|
|
2015-09-14 16:58:30 +02:00
|
|
|
for (i = index; i < length;)
|
|
|
|
{
|
|
|
|
BYTE b0 = descriptor[i++];
|
|
|
|
int bSize = b0 & 0x03;
|
|
|
|
int bType = (b0 >> 2) & 0x03;
|
|
|
|
int bTag = (b0 >> 4) & 0x0F;
|
|
|
|
|
|
|
|
bSize = (bSize == 3) ? 4 : bSize;
|
|
|
|
if (bType == TAG_TYPE_RESERVED && bTag == 0x0F && bSize == 2 &&
|
|
|
|
i + 2 < length)
|
|
|
|
{
|
|
|
|
/* Long data items: Should be unused */
|
|
|
|
ERR("Long Data Item, should be unused\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int bSizeActual = 0;
|
|
|
|
int itemVal = 0;
|
|
|
|
unsigned int j;
|
|
|
|
|
|
|
|
for (j = 0; j < bSize; j++)
|
|
|
|
{
|
|
|
|
if (i + j < length)
|
|
|
|
{
|
|
|
|
itemVal += descriptor[i + j] << (8 * j);
|
|
|
|
bSizeActual++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TRACE(" 0x%x[%i], type %i , tag %i, size %i, val %i\n",b0,i-1,bType, bTag, bSize, itemVal );
|
|
|
|
|
|
|
|
if (bType == TAG_TYPE_MAIN)
|
|
|
|
{
|
|
|
|
struct feature *feature;
|
|
|
|
switch(bTag)
|
|
|
|
{
|
|
|
|
case TAG_MAIN_INPUT:
|
|
|
|
case TAG_MAIN_OUTPUT:
|
|
|
|
case TAG_MAIN_FEATURE:
|
2020-03-17 03:18:05 +01:00
|
|
|
for (j = 0; j < caps->ReportCount; j++)
|
2019-05-13 12:34:12 +02:00
|
|
|
{
|
|
|
|
feature = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*feature));
|
|
|
|
list_add_tail(&collection->features, &feature->entry);
|
|
|
|
if (bTag == TAG_MAIN_INPUT)
|
|
|
|
feature->type = HidP_Input;
|
|
|
|
else if (bTag == TAG_MAIN_OUTPUT)
|
|
|
|
feature->type = HidP_Output;
|
|
|
|
else
|
|
|
|
feature->type = HidP_Feature;
|
|
|
|
parse_io_feature(bSize, itemVal, bTag, feature_index, feature);
|
|
|
|
if (j < usages_top)
|
|
|
|
caps->u.NotRange.Usage = usages[j];
|
|
|
|
feature->caps = *caps;
|
|
|
|
feature->caps.ReportCount = 1;
|
|
|
|
feature->collection = collection;
|
|
|
|
if (j+1 >= usages_top)
|
2020-03-17 03:18:05 +01:00
|
|
|
{
|
|
|
|
feature->caps.ReportCount += caps->ReportCount - (j + 1);
|
2019-05-13 12:34:12 +02:00
|
|
|
break;
|
2020-03-17 03:18:05 +01:00
|
|
|
}
|
2019-05-13 12:34:12 +02:00
|
|
|
}
|
|
|
|
usages_top = 0;
|
2015-09-14 16:58:30 +02:00
|
|
|
new_caps(caps);
|
|
|
|
break;
|
|
|
|
case TAG_MAIN_COLLECTION:
|
|
|
|
{
|
|
|
|
struct collection *subcollection = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct collection));
|
|
|
|
list_add_tail(&collection->collections, &subcollection->entry);
|
|
|
|
subcollection->parent = collection;
|
|
|
|
/* Only set our collection once...
|
|
|
|
We do not properly handle composite devices yet. */
|
2019-05-13 12:34:12 +02:00
|
|
|
if (usages_top)
|
|
|
|
{
|
|
|
|
caps->u.NotRange.Usage = usages[usages_top-1];
|
|
|
|
usages_top = 0;
|
|
|
|
}
|
2015-09-14 16:58:30 +02:00
|
|
|
if (*collection_index == 0)
|
|
|
|
collection->caps = *caps;
|
|
|
|
subcollection->caps = *caps;
|
|
|
|
subcollection->index = *collection_index;
|
|
|
|
*collection_index = *collection_index + 1;
|
|
|
|
list_init(&subcollection->features);
|
|
|
|
list_init(&subcollection->collections);
|
|
|
|
new_caps(caps);
|
|
|
|
|
|
|
|
parse_collection(bSize, itemVal, subcollection);
|
|
|
|
|
2019-05-13 12:34:04 +02:00
|
|
|
i = parse_descriptor(descriptor, i+1, length, feature_index, collection_index, subcollection, caps, stack);
|
2015-09-14 16:58:30 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
case TAG_MAIN_END_COLLECTION:
|
|
|
|
return i;
|
|
|
|
default:
|
|
|
|
ERR("Unknown (bTag: 0x%x, bType: 0x%x)\n", bTag, bType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (bType == TAG_TYPE_GLOBAL)
|
|
|
|
{
|
|
|
|
switch(bTag)
|
|
|
|
{
|
|
|
|
case TAG_GLOBAL_USAGE_PAGE:
|
2016-12-06 20:11:49 +01:00
|
|
|
caps->UsagePage = getValue(bSize, itemVal, FALSE);
|
2015-09-14 16:58:30 +02:00
|
|
|
break;
|
|
|
|
case TAG_GLOBAL_LOGICAL_MINIMUM:
|
2016-12-06 20:11:49 +01:00
|
|
|
caps->LogicalMin = getValue(bSize, itemVal, TRUE);
|
2015-09-14 16:58:30 +02:00
|
|
|
break;
|
|
|
|
case TAG_GLOBAL_LOGICAL_MAXIMUM:
|
2016-12-06 20:11:49 +01:00
|
|
|
caps->LogicalMax = getValue(bSize, itemVal, TRUE);
|
2015-09-14 16:58:30 +02:00
|
|
|
break;
|
|
|
|
case TAG_GLOBAL_PHYSICAL_MINIMUM:
|
2016-12-06 20:11:49 +01:00
|
|
|
caps->PhysicalMin = getValue(bSize, itemVal, TRUE);
|
2015-09-14 16:58:30 +02:00
|
|
|
break;
|
|
|
|
case TAG_GLOBAL_PHYSICAL_MAXIMUM:
|
2016-12-06 20:11:49 +01:00
|
|
|
caps->PhysicalMax = getValue(bSize, itemVal, TRUE);
|
2015-09-14 16:58:30 +02:00
|
|
|
break;
|
|
|
|
case TAG_GLOBAL_UNIT_EXPONENT:
|
2016-12-06 20:11:49 +01:00
|
|
|
caps->UnitsExp = getValue(bSize, itemVal, TRUE);
|
2015-09-14 16:58:30 +02:00
|
|
|
break;
|
|
|
|
case TAG_GLOBAL_UNIT:
|
2016-12-06 20:11:49 +01:00
|
|
|
caps->Units = getValue(bSize, itemVal, TRUE);
|
2015-09-14 16:58:30 +02:00
|
|
|
break;
|
|
|
|
case TAG_GLOBAL_REPORT_SIZE:
|
2016-12-06 20:11:49 +01:00
|
|
|
caps->BitSize = getValue(bSize, itemVal, FALSE);
|
2015-09-14 16:58:30 +02:00
|
|
|
break;
|
|
|
|
case TAG_GLOBAL_REPORT_ID:
|
2016-12-06 20:11:49 +01:00
|
|
|
caps->ReportID = getValue(bSize, itemVal, FALSE);
|
2015-09-14 16:58:30 +02:00
|
|
|
break;
|
|
|
|
case TAG_GLOBAL_REPORT_COUNT:
|
2016-12-06 20:11:49 +01:00
|
|
|
caps->ReportCount = getValue(bSize, itemVal, FALSE);
|
2015-09-14 16:58:30 +02:00
|
|
|
break;
|
|
|
|
case TAG_GLOBAL_PUSH:
|
2016-11-14 15:29:20 +01:00
|
|
|
{
|
|
|
|
struct caps_stack *saved = HeapAlloc(GetProcessHeap(), 0, sizeof(*saved));
|
|
|
|
saved->caps = *caps;
|
|
|
|
TRACE("Push\n");
|
|
|
|
list_add_tail(stack, &saved->entry);
|
2015-09-14 16:58:30 +02:00
|
|
|
break;
|
2016-11-14 15:29:20 +01:00
|
|
|
}
|
2015-09-14 16:58:30 +02:00
|
|
|
case TAG_GLOBAL_POP:
|
2016-11-14 15:29:20 +01:00
|
|
|
{
|
|
|
|
struct list *tail;
|
|
|
|
struct caps_stack *saved;
|
|
|
|
TRACE("Pop\n");
|
|
|
|
tail = list_tail(stack);
|
|
|
|
if (tail)
|
|
|
|
{
|
|
|
|
saved = LIST_ENTRY(tail, struct caps_stack, entry);
|
|
|
|
*caps = saved->caps;
|
|
|
|
list_remove(tail);
|
|
|
|
HeapFree(GetProcessHeap(), 0, saved);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ERR("Pop but no stack!\n");
|
2015-09-14 16:58:30 +02:00
|
|
|
break;
|
2016-11-14 15:29:20 +01:00
|
|
|
}
|
2015-09-14 16:58:30 +02:00
|
|
|
default:
|
|
|
|
ERR("Unknown (bTag: 0x%x, bType: 0x%x)\n", bTag, bType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (bType == TAG_TYPE_LOCAL)
|
|
|
|
{
|
|
|
|
switch(bTag)
|
|
|
|
{
|
|
|
|
case TAG_LOCAL_USAGE:
|
2019-05-13 12:34:12 +02:00
|
|
|
if (usages_top == sizeof(usages))
|
2019-08-08 15:19:52 +02:00
|
|
|
ERR("More than 256 individual usages defined\n");
|
2015-09-14 16:58:30 +02:00
|
|
|
else
|
|
|
|
{
|
2019-05-13 12:34:12 +02:00
|
|
|
usages[usages_top++] = getValue(bSize, itemVal, FALSE);
|
2015-09-14 16:58:30 +02:00
|
|
|
caps->IsRange = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TAG_LOCAL_USAGE_MINIMUM:
|
2016-12-06 20:11:49 +01:00
|
|
|
caps->u.Range.UsageMin = getValue(bSize, itemVal, FALSE);
|
2015-09-14 16:58:30 +02:00
|
|
|
caps->IsRange = TRUE;
|
|
|
|
break;
|
|
|
|
case TAG_LOCAL_USAGE_MAXIMUM:
|
2016-12-06 20:11:49 +01:00
|
|
|
caps->u.Range.UsageMax = getValue(bSize, itemVal, FALSE);
|
2015-09-14 16:58:30 +02:00
|
|
|
caps->IsRange = TRUE;
|
|
|
|
break;
|
|
|
|
case TAG_LOCAL_DESIGNATOR_INDEX:
|
2016-12-06 20:11:49 +01:00
|
|
|
caps->u.NotRange.DesignatorIndex = getValue(bSize, itemVal, FALSE);
|
2015-09-14 16:58:30 +02:00
|
|
|
caps->IsDesignatorRange = FALSE;
|
|
|
|
break;
|
|
|
|
case TAG_LOCAL_DESIGNATOR_MINIMUM:
|
2016-12-06 20:11:49 +01:00
|
|
|
caps->u.Range.DesignatorMin = getValue(bSize, itemVal, FALSE);
|
2015-09-14 16:58:30 +02:00
|
|
|
caps->IsDesignatorRange = TRUE;
|
|
|
|
break;
|
|
|
|
case TAG_LOCAL_DESIGNATOR_MAXIMUM:
|
2016-12-06 20:11:49 +01:00
|
|
|
caps->u.Range.DesignatorMax = getValue(bSize, itemVal, FALSE);
|
2015-09-14 16:58:30 +02:00
|
|
|
caps->IsDesignatorRange = TRUE;
|
|
|
|
break;
|
|
|
|
case TAG_LOCAL_STRING_INDEX:
|
2016-12-06 20:11:49 +01:00
|
|
|
caps->u.NotRange.StringIndex = getValue(bSize, itemVal, FALSE);
|
2015-09-14 16:58:30 +02:00
|
|
|
caps->IsStringRange = FALSE;
|
|
|
|
break;
|
|
|
|
case TAG_LOCAL_STRING_MINIMUM:
|
2016-12-06 20:11:49 +01:00
|
|
|
caps->u.Range.StringMin = getValue(bSize, itemVal, FALSE);
|
2015-09-14 16:58:30 +02:00
|
|
|
caps->IsStringRange = TRUE;
|
|
|
|
break;
|
|
|
|
case TAG_LOCAL_STRING_MAXIMUM:
|
2016-12-06 20:11:49 +01:00
|
|
|
caps->u.Range.StringMax = getValue(bSize, itemVal, FALSE);
|
2015-09-14 16:58:30 +02:00
|
|
|
caps->IsStringRange = TRUE;
|
|
|
|
break;
|
|
|
|
case TAG_LOCAL_DELIMITER:
|
2016-12-06 20:11:49 +01:00
|
|
|
caps->Delim = getValue(bSize, itemVal, FALSE);
|
2015-09-14 16:58:30 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("Unknown (bTag: 0x%x, bType: 0x%x)\n", bTag, bType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ERR("Unknown (bTag: 0x%x, bType: 0x%x)\n", bTag, bType);
|
|
|
|
|
|
|
|
i += bSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2019-05-13 12:33:56 +02:00
|
|
|
static void build_elements(WINE_HID_REPORT *wine_report, WINE_HID_ELEMENT *elems,
|
|
|
|
struct feature* feature, USHORT *data_index)
|
2015-09-14 16:58:30 +02:00
|
|
|
{
|
2019-05-13 12:34:12 +02:00
|
|
|
WINE_HID_ELEMENT *wine_element = elems + wine_report->elementIdx + wine_report->elementCount;
|
2015-09-14 16:58:30 +02:00
|
|
|
|
|
|
|
if (!feature->isData)
|
|
|
|
{
|
2019-05-13 12:33:56 +02:00
|
|
|
wine_report->bitSize += feature->caps.BitSize * feature->caps.ReportCount;
|
2015-09-14 16:58:30 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-13 12:34:12 +02:00
|
|
|
wine_element->valueStartBit = wine_report->bitSize;
|
2021-01-21 17:11:13 +01:00
|
|
|
|
|
|
|
wine_element->bitCount = (feature->caps.BitSize * feature->caps.ReportCount);
|
|
|
|
wine_report->bitSize += wine_element->bitCount;
|
|
|
|
|
2019-05-13 12:34:12 +02:00
|
|
|
if (feature->caps.BitSize == 1)
|
2015-09-14 16:58:30 +02:00
|
|
|
{
|
2019-05-13 12:34:12 +02:00
|
|
|
wine_element->ElementType = ButtonElement;
|
|
|
|
wine_element->caps.button.UsagePage = feature->caps.UsagePage;
|
|
|
|
wine_element->caps.button.ReportID = feature->caps.ReportID;
|
|
|
|
wine_element->caps.button.BitField = feature->BitField;
|
|
|
|
wine_element->caps.button.LinkCollection = feature->collection->index;
|
|
|
|
wine_element->caps.button.LinkUsage = feature->collection->caps.u.NotRange.Usage;
|
|
|
|
wine_element->caps.button.LinkUsagePage = feature->collection->caps.UsagePage;
|
|
|
|
wine_element->caps.button.IsRange = feature->caps.IsRange;
|
|
|
|
wine_element->caps.button.IsStringRange = feature->caps.IsStringRange;
|
|
|
|
wine_element->caps.button.IsDesignatorRange = feature->caps.IsDesignatorRange;
|
|
|
|
wine_element->caps.button.IsAbsolute = feature->IsAbsolute;
|
|
|
|
if (wine_element->caps.button.IsRange)
|
2015-09-14 16:58:30 +02:00
|
|
|
{
|
2019-05-13 12:34:12 +02:00
|
|
|
wine_element->caps.button.u.Range.UsageMin = feature->caps.u.Range.UsageMin;
|
|
|
|
wine_element->caps.button.u.Range.UsageMax = feature->caps.u.Range.UsageMax;
|
|
|
|
wine_element->caps.button.u.Range.StringMin = feature->caps.u.Range.StringMin;
|
|
|
|
wine_element->caps.button.u.Range.StringMax = feature->caps.u.Range.StringMax;
|
|
|
|
wine_element->caps.button.u.Range.DesignatorMin = feature->caps.u.Range.DesignatorMin;
|
|
|
|
wine_element->caps.button.u.Range.DesignatorMax = feature->caps.u.Range.DesignatorMax;
|
|
|
|
wine_element->caps.button.u.Range.DataIndexMin = *data_index;
|
|
|
|
wine_element->caps.button.u.Range.DataIndexMax = *data_index + wine_element->bitCount - 1;
|
|
|
|
*data_index = *data_index + wine_element->bitCount;
|
2015-09-14 16:58:30 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-13 12:34:12 +02:00
|
|
|
wine_element->caps.button.u.NotRange.Usage = feature->caps.u.NotRange.Usage;
|
|
|
|
wine_element->caps.button.u.NotRange.Reserved1 = feature->caps.u.NotRange.Usage;
|
|
|
|
wine_element->caps.button.u.NotRange.StringIndex = feature->caps.u.NotRange.StringIndex;
|
|
|
|
wine_element->caps.button.u.NotRange.Reserved2 = feature->caps.u.NotRange.StringIndex;
|
|
|
|
wine_element->caps.button.u.NotRange.DesignatorIndex = feature->caps.u.NotRange.DesignatorIndex;
|
|
|
|
wine_element->caps.button.u.NotRange.Reserved3 = feature->caps.u.NotRange.DesignatorIndex;
|
|
|
|
wine_element->caps.button.u.NotRange.DataIndex = *data_index;
|
|
|
|
wine_element->caps.button.u.NotRange.Reserved4 = *data_index;
|
|
|
|
*data_index = *data_index + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wine_element->ElementType = ValueElement;
|
|
|
|
wine_element->caps.value.UsagePage = feature->caps.UsagePage;
|
|
|
|
wine_element->caps.value.ReportID = feature->caps.ReportID;
|
|
|
|
wine_element->caps.value.BitField = feature->BitField;
|
|
|
|
wine_element->caps.value.LinkCollection = feature->collection->index;
|
|
|
|
wine_element->caps.value.LinkUsage = feature->collection->caps.u.NotRange.Usage;
|
|
|
|
wine_element->caps.value.LinkUsagePage = feature->collection->caps.UsagePage;
|
|
|
|
wine_element->caps.value.IsRange = feature->caps.IsRange;
|
|
|
|
wine_element->caps.value.IsStringRange = feature->caps.IsStringRange;
|
|
|
|
wine_element->caps.value.IsDesignatorRange = feature->caps.IsDesignatorRange;
|
|
|
|
wine_element->caps.value.IsAbsolute = feature->IsAbsolute;
|
|
|
|
wine_element->caps.value.HasNull = feature->HasNull;
|
|
|
|
wine_element->caps.value.BitSize = feature->caps.BitSize;
|
|
|
|
wine_element->caps.value.ReportCount = feature->caps.ReportCount;
|
|
|
|
wine_element->caps.value.UnitsExp = feature->caps.UnitsExp;
|
|
|
|
wine_element->caps.value.Units = feature->caps.Units;
|
|
|
|
wine_element->caps.value.LogicalMin = feature->caps.LogicalMin;
|
|
|
|
wine_element->caps.value.LogicalMax = feature->caps.LogicalMax;
|
|
|
|
wine_element->caps.value.PhysicalMin = feature->caps.PhysicalMin;
|
|
|
|
wine_element->caps.value.PhysicalMax = feature->caps.PhysicalMax;
|
|
|
|
if (wine_element->caps.value.IsRange)
|
|
|
|
{
|
|
|
|
wine_element->caps.value.u.Range.UsageMin = feature->caps.u.Range.UsageMin;
|
|
|
|
wine_element->caps.value.u.Range.UsageMax = feature->caps.u.Range.UsageMax;
|
|
|
|
wine_element->caps.value.u.Range.StringMin = feature->caps.u.Range.StringMin;
|
|
|
|
wine_element->caps.value.u.Range.StringMax = feature->caps.u.Range.StringMax;
|
|
|
|
wine_element->caps.value.u.Range.DesignatorMin = feature->caps.u.Range.DesignatorMin;
|
|
|
|
wine_element->caps.value.u.Range.DesignatorMax = feature->caps.u.Range.DesignatorMax;
|
|
|
|
wine_element->caps.value.u.Range.DataIndexMin = *data_index;
|
|
|
|
wine_element->caps.value.u.Range.DataIndexMax = *data_index +
|
|
|
|
(wine_element->caps.value.u.Range.UsageMax -
|
|
|
|
wine_element->caps.value.u.Range.UsageMin);
|
|
|
|
*data_index = *data_index +
|
|
|
|
(wine_element->caps.value.u.Range.UsageMax -
|
|
|
|
wine_element->caps.value.u.Range.UsageMin) + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wine_element->caps.value.u.NotRange.Usage = feature->caps.u.NotRange.Usage;
|
|
|
|
wine_element->caps.value.u.NotRange.Reserved1 = feature->caps.u.NotRange.Usage;
|
|
|
|
wine_element->caps.value.u.NotRange.StringIndex = feature->caps.u.NotRange.StringIndex;
|
|
|
|
wine_element->caps.value.u.NotRange.Reserved2 = feature->caps.u.NotRange.StringIndex;
|
|
|
|
wine_element->caps.value.u.NotRange.DesignatorIndex = feature->caps.u.NotRange.DesignatorIndex;
|
|
|
|
wine_element->caps.value.u.NotRange.Reserved3 = feature->caps.u.NotRange.DesignatorIndex;
|
|
|
|
wine_element->caps.value.u.NotRange.DataIndex = *data_index;
|
|
|
|
wine_element->caps.value.u.NotRange.Reserved4 = *data_index;
|
|
|
|
*data_index = *data_index + 1;
|
2015-09-14 16:58:30 +02:00
|
|
|
}
|
|
|
|
}
|
2019-05-13 12:34:12 +02:00
|
|
|
wine_report->elementCount++;
|
2015-09-14 16:58:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void count_elements(struct feature* feature, USHORT *buttons, USHORT *values)
|
|
|
|
{
|
2019-05-13 12:34:12 +02:00
|
|
|
if (!feature->isData)
|
|
|
|
return;
|
|
|
|
|
2019-05-03 12:00:50 +02:00
|
|
|
if (feature->caps.BitSize == 1)
|
2019-05-13 12:34:12 +02:00
|
|
|
(*buttons)++;
|
2015-09-14 16:58:30 +02:00
|
|
|
else
|
2019-05-13 12:34:12 +02:00
|
|
|
(*values)++;
|
2015-09-14 16:58:30 +02:00
|
|
|
}
|
|
|
|
|
2019-05-13 12:33:56 +02:00
|
|
|
struct preparse_ctx
|
2015-09-14 16:58:30 +02:00
|
|
|
{
|
2019-05-13 12:33:56 +02:00
|
|
|
int report_count[3];
|
|
|
|
int elem_count;
|
|
|
|
int report_elem_count[3][256];
|
|
|
|
|
|
|
|
int elem_alloc;
|
|
|
|
BOOL report_created[3][256];
|
|
|
|
};
|
|
|
|
|
|
|
|
static void create_preparse_ctx(const struct collection *base, struct preparse_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct feature *f;
|
|
|
|
struct collection *c;
|
2015-09-14 16:58:30 +02:00
|
|
|
|
2019-05-13 12:34:04 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(f, &base->features, struct feature, entry)
|
2015-09-14 16:58:30 +02:00
|
|
|
{
|
2019-05-13 12:34:12 +02:00
|
|
|
ctx->elem_count++;
|
|
|
|
ctx->report_elem_count[f->type][f->caps.ReportID]++;
|
|
|
|
if (ctx->report_elem_count[f->type][f->caps.ReportID] != 1)
|
2019-05-13 12:33:56 +02:00
|
|
|
continue;
|
|
|
|
ctx->report_count[f->type]++;
|
|
|
|
}
|
2015-09-14 16:58:30 +02:00
|
|
|
|
2019-05-13 12:33:56 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(c, &base->collections, struct collection, entry)
|
|
|
|
create_preparse_ctx(c, ctx);
|
|
|
|
}
|
|
|
|
|
2020-02-11 19:13:46 +01:00
|
|
|
static void preparse_collection(const struct collection *root, const struct collection *base,
|
2019-05-13 12:33:56 +02:00
|
|
|
WINE_HIDP_PREPARSED_DATA *data, struct preparse_ctx *ctx)
|
|
|
|
{
|
|
|
|
WINE_HID_ELEMENT *elem = HID_ELEMS(data);
|
2020-02-11 19:13:46 +01:00
|
|
|
WINE_HID_LINK_COLLECTION_NODE *nodes = HID_NODES(data);
|
2019-05-13 12:33:56 +02:00
|
|
|
struct feature *f;
|
|
|
|
struct collection *c;
|
2020-02-11 19:13:46 +01:00
|
|
|
struct list *entry;
|
2019-05-13 12:33:56 +02:00
|
|
|
|
2019-05-13 12:34:04 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(f, &base->features, struct feature, entry)
|
2019-05-13 12:33:56 +02:00
|
|
|
{
|
|
|
|
WINE_HID_REPORT *report;
|
|
|
|
|
|
|
|
if (!ctx->report_created[f->type][f->caps.ReportID])
|
2015-09-14 16:58:30 +02:00
|
|
|
{
|
2019-05-13 12:33:56 +02:00
|
|
|
ctx->report_created[f->type][f->caps.ReportID] = TRUE;
|
|
|
|
data->reportIdx[f->type][f->caps.ReportID] = data->reportCount[f->type]++;
|
|
|
|
if (f->type > 0) data->reportIdx[f->type][f->caps.ReportID] += ctx->report_count[0];
|
|
|
|
if (f->type > 1) data->reportIdx[f->type][f->caps.ReportID] += ctx->report_count[1];
|
|
|
|
|
|
|
|
report = &data->reports[data->reportIdx[f->type][f->caps.ReportID]];
|
|
|
|
report->reportID = f->caps.ReportID;
|
|
|
|
/* Room for the reportID */
|
|
|
|
report->bitSize = 8;
|
|
|
|
report->elementIdx = ctx->elem_alloc;
|
|
|
|
ctx->elem_alloc += ctx->report_elem_count[f->type][f->caps.ReportID];
|
2015-09-14 16:58:30 +02:00
|
|
|
}
|
2019-05-13 12:33:56 +02:00
|
|
|
|
|
|
|
report = &data->reports[data->reportIdx[f->type][f->caps.ReportID]];
|
|
|
|
switch (f->type)
|
2015-09-14 16:58:30 +02:00
|
|
|
{
|
2019-05-13 12:33:56 +02:00
|
|
|
case HidP_Input:
|
|
|
|
build_elements(report, elem, f, &data->caps.NumberInputDataIndices);
|
|
|
|
count_elements(f, &data->caps.NumberInputButtonCaps, &data->caps.NumberInputValueCaps);
|
|
|
|
data->caps.InputReportByteLength =
|
|
|
|
max(data->caps.InputReportByteLength, (report->bitSize + 7) / 8);
|
|
|
|
break;
|
|
|
|
case HidP_Output:
|
|
|
|
build_elements(report, elem, f, &data->caps.NumberOutputDataIndices);
|
|
|
|
count_elements(f, &data->caps.NumberOutputButtonCaps, &data->caps.NumberOutputValueCaps);
|
|
|
|
data->caps.OutputReportByteLength =
|
|
|
|
max(data->caps.OutputReportByteLength, (report->bitSize + 7) / 8);
|
|
|
|
break;
|
|
|
|
case HidP_Feature:
|
|
|
|
build_elements(report, elem, f, &data->caps.NumberFeatureDataIndices);
|
|
|
|
count_elements(f, &data->caps.NumberFeatureButtonCaps, &data->caps.NumberFeatureValueCaps);
|
|
|
|
data->caps.FeatureReportByteLength =
|
|
|
|
max(data->caps.FeatureReportByteLength, (report->bitSize + 7) / 8);
|
|
|
|
break;
|
2015-09-14 16:58:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-11 19:13:46 +01:00
|
|
|
if (root != base)
|
|
|
|
{
|
|
|
|
nodes[base->index].LinkUsagePage = base->caps.UsagePage;
|
|
|
|
nodes[base->index].LinkUsage = base->caps.u.NotRange.Usage;
|
|
|
|
nodes[base->index].Parent = base->parent == root ? 0 : base->parent->index;
|
|
|
|
nodes[base->index].CollectionType = base->type;
|
|
|
|
nodes[base->index].IsAlias = 0;
|
|
|
|
|
|
|
|
if ((entry = list_head(&base->collections)))
|
|
|
|
nodes[base->index].FirstChild = LIST_ENTRY(entry, struct collection, entry)->index;
|
|
|
|
}
|
|
|
|
|
2019-05-13 12:33:56 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(c, &base->collections, struct collection, entry)
|
2020-02-11 19:13:46 +01:00
|
|
|
{
|
|
|
|
preparse_collection(root, c, data, ctx);
|
|
|
|
|
|
|
|
if ((entry = list_next(&base->collections, &c->entry)))
|
|
|
|
nodes[c->index].NextSibling = LIST_ENTRY(entry, struct collection, entry)->index;
|
|
|
|
if (root != base) nodes[base->index].NumberOfChildren++;
|
|
|
|
}
|
2019-05-13 12:33:56 +02:00
|
|
|
}
|
|
|
|
|
2020-02-11 19:13:46 +01:00
|
|
|
static WINE_HIDP_PREPARSED_DATA* build_PreparseData(struct collection *base_collection, unsigned int node_count)
|
2019-05-13 12:33:56 +02:00
|
|
|
{
|
|
|
|
WINE_HIDP_PREPARSED_DATA *data;
|
|
|
|
unsigned int report_count;
|
|
|
|
unsigned int size;
|
|
|
|
|
|
|
|
struct preparse_ctx ctx;
|
|
|
|
unsigned int element_off;
|
2020-02-11 19:13:46 +01:00
|
|
|
unsigned int nodes_offset;
|
2015-09-14 16:58:30 +02:00
|
|
|
|
2019-05-13 12:33:56 +02:00
|
|
|
memset(&ctx, 0, sizeof(ctx));
|
|
|
|
create_preparse_ctx(base_collection, &ctx);
|
2015-09-14 16:58:30 +02:00
|
|
|
|
2019-05-13 12:33:56 +02:00
|
|
|
report_count = ctx.report_count[HidP_Input] + ctx.report_count[HidP_Output]
|
|
|
|
+ ctx.report_count[HidP_Feature];
|
|
|
|
element_off = FIELD_OFFSET(WINE_HIDP_PREPARSED_DATA, reports[report_count]);
|
|
|
|
size = element_off + (ctx.elem_count * sizeof(WINE_HID_ELEMENT));
|
2015-09-14 16:58:30 +02:00
|
|
|
|
2020-02-11 19:13:46 +01:00
|
|
|
nodes_offset = size;
|
|
|
|
size += node_count * sizeof(WINE_HID_LINK_COLLECTION_NODE);
|
|
|
|
|
2015-09-14 16:58:30 +02:00
|
|
|
data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
|
|
|
|
data->magic = HID_MAGIC;
|
|
|
|
data->dwSize = size;
|
2019-05-13 12:34:12 +02:00
|
|
|
data->caps.Usage = base_collection->caps.u.NotRange.Usage;
|
2015-09-14 16:58:30 +02:00
|
|
|
data->caps.UsagePage = base_collection->caps.UsagePage;
|
2020-02-11 19:13:46 +01:00
|
|
|
data->caps.NumberLinkCollectionNodes = node_count;
|
2019-05-13 12:33:56 +02:00
|
|
|
data->elementOffset = element_off;
|
2020-02-11 19:13:46 +01:00
|
|
|
data->nodesOffset = nodes_offset;
|
2015-09-14 16:58:30 +02:00
|
|
|
|
2020-02-11 19:13:46 +01:00
|
|
|
preparse_collection(base_collection, base_collection, data, &ctx);
|
2015-09-14 16:58:30 +02:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_collection(struct collection *collection)
|
|
|
|
{
|
|
|
|
struct feature *fentry, *fnext;
|
|
|
|
struct collection *centry, *cnext;
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(centry, cnext, &collection->collections, struct collection, entry)
|
|
|
|
{
|
|
|
|
list_remove(¢ry->entry);
|
|
|
|
free_collection(centry);
|
|
|
|
}
|
2019-05-13 12:34:04 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(fentry, fnext, &collection->features, struct feature, entry)
|
2015-09-14 16:58:30 +02:00
|
|
|
{
|
2019-05-13 12:34:04 +02:00
|
|
|
list_remove(&fentry->entry);
|
2015-09-14 16:58:30 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, fentry);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, collection);
|
|
|
|
}
|
|
|
|
|
|
|
|
WINE_HIDP_PREPARSED_DATA* ParseDescriptor(BYTE *descriptor, unsigned int length)
|
|
|
|
{
|
|
|
|
WINE_HIDP_PREPARSED_DATA *data = NULL;
|
|
|
|
struct collection *base;
|
|
|
|
struct caps caps;
|
|
|
|
|
2016-11-14 15:29:20 +01:00
|
|
|
struct list caps_stack;
|
2015-09-14 16:58:30 +02:00
|
|
|
|
|
|
|
unsigned int feature_count = 0;
|
|
|
|
unsigned int cidx;
|
|
|
|
|
|
|
|
if (TRACE_ON(hid))
|
|
|
|
{
|
|
|
|
TRACE("Descriptor[%i]: ", length);
|
|
|
|
for (cidx = 0; cidx < length; cidx++)
|
2015-11-16 14:08:46 +01:00
|
|
|
{
|
2015-09-14 16:58:30 +02:00
|
|
|
TRACE("%x ",descriptor[cidx]);
|
2015-12-18 07:48:56 +01:00
|
|
|
if ((cidx+1) % 80 == 0)
|
2015-11-16 14:08:46 +01:00
|
|
|
TRACE("\n");
|
|
|
|
}
|
2015-09-14 16:58:30 +02:00
|
|
|
TRACE("\n");
|
|
|
|
}
|
|
|
|
|
2016-11-14 15:29:20 +01:00
|
|
|
list_init(&caps_stack);
|
2015-09-14 16:58:30 +02:00
|
|
|
|
|
|
|
base = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*base));
|
|
|
|
base->index = 1;
|
|
|
|
list_init(&base->features);
|
|
|
|
list_init(&base->collections);
|
|
|
|
memset(&caps, 0, sizeof(caps));
|
|
|
|
|
|
|
|
cidx = 0;
|
2019-05-13 12:34:04 +02:00
|
|
|
parse_descriptor(descriptor, 0, length, &feature_count, &cidx, base, &caps, &caps_stack);
|
2015-09-14 16:58:30 +02:00
|
|
|
|
|
|
|
debug_collection(base);
|
|
|
|
|
2016-11-14 15:29:20 +01:00
|
|
|
if (!list_empty(&caps_stack))
|
|
|
|
{
|
|
|
|
struct caps_stack *entry, *cursor;
|
|
|
|
ERR("%i unpopped device caps on the stack\n", list_count(&caps_stack));
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(entry, cursor, &caps_stack, struct caps_stack, entry)
|
|
|
|
{
|
|
|
|
list_remove(&entry->entry);
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-11 19:13:46 +01:00
|
|
|
data = build_PreparseData(base, cidx);
|
2019-05-13 12:33:56 +02:00
|
|
|
debug_print_preparsed(data);
|
2015-09-14 16:58:30 +02:00
|
|
|
free_collection(base);
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|