| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#ifndef HIDAPI_DESCRIPTOR_RECONSTRUCT_H__ |
| 20 |
#define HIDAPI_DESCRIPTOR_RECONSTRUCT_H__ |
| 21 |
|
| 22 |
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) |
| 23 |
|
| 24 |
|
| 25 |
#define _CRT_SECURE_NO_WARNINGS |
| 26 |
#endif |
| 27 |
|
| 28 |
#include "hidapi_winapi.h" |
| 29 |
|
| 30 |
#ifdef _MSC_VER |
| 31 |
#pragma warning(push) |
| 32 |
#pragma warning(disable: 4200) |
| 33 |
#pragma warning(disable: 4201) |
| 34 |
#pragma warning(disable: 4214) |
| 35 |
#endif |
| 36 |
|
| 37 |
#include <windows.h> |
| 38 |
|
| 39 |
#include "hidapi_hidsdi.h" |
| 40 |
#include <assert.h> |
| 41 |
|
| 42 |
#define NUM_OF_HIDP_REPORT_TYPES 3 |
| 43 |
|
| 44 |
typedef enum rd_items_ { |
| 45 |
rd_main_input = 0x80, |
| 46 |
rd_main_output = 0x90, |
| 47 |
rd_main_feature = 0xB0, |
| 48 |
rd_main_collection = 0xA0, |
| 49 |
rd_main_collection_end = 0xC0, |
| 50 |
rd_global_usage_page = 0x04, |
| 51 |
rd_global_logical_minimum = 0x14, |
| 52 |
rd_global_logical_maximum = 0x24, |
| 53 |
rd_global_physical_minimum = 0x34, |
| 54 |
rd_global_physical_maximum = 0x44, |
| 55 |
rd_global_unit_exponent = 0x54, |
| 56 |
rd_global_unit = 0x64, |
| 57 |
rd_global_report_size = 0x74, |
| 58 |
rd_global_report_id = 0x84, |
| 59 |
rd_global_report_count = 0x94, |
| 60 |
rd_global_push = 0xA4, |
| 61 |
rd_global_pop = 0xB4, |
| 62 |
rd_local_usage = 0x08, |
| 63 |
rd_local_usage_minimum = 0x18, |
| 64 |
rd_local_usage_maximum = 0x28, |
| 65 |
rd_local_designator_index = 0x38, |
| 66 |
rd_local_designator_minimum = 0x48, |
| 67 |
rd_local_designator_maximum = 0x58, |
| 68 |
rd_local_string = 0x78, |
| 69 |
rd_local_string_minimum = 0x88, |
| 70 |
rd_local_string_maximum = 0x98, |
| 71 |
rd_local_delimiter = 0xA8 |
| 72 |
} rd_items; |
| 73 |
|
| 74 |
typedef enum rd_main_items_ { |
| 75 |
rd_input = HidP_Input, |
| 76 |
rd_output = HidP_Output, |
| 77 |
rd_feature = HidP_Feature, |
| 78 |
rd_collection, |
| 79 |
rd_collection_end, |
| 80 |
rd_delimiter_open, |
| 81 |
rd_delimiter_usage, |
| 82 |
rd_delimiter_close, |
| 83 |
} rd_main_items; |
| 84 |
|
| 85 |
typedef struct rd_bit_range_ { |
| 86 |
int FirstBit; |
| 87 |
int LastBit; |
| 88 |
} rd_bit_range; |
| 89 |
|
| 90 |
typedef enum rd_item_node_type_ { |
| 91 |
rd_item_node_cap, |
| 92 |
rd_item_node_padding, |
| 93 |
rd_item_node_collection, |
| 94 |
} rd_node_type; |
| 95 |
|
| 96 |
struct rd_main_item_node { |
| 97 |
int FirstBit; |
| 98 |
int LastBit; |
| 99 |
rd_node_type TypeOfNode; |
| 100 |
|
| 101 |
|
| 102 |
int CapsIndex; |
| 103 |
int CollectionIndex; |
| 104 |
rd_main_items MainItemType; |
| 105 |
unsigned char ReportID; |
| 106 |
struct rd_main_item_node* next; |
| 107 |
}; |
| 108 |
|
| 109 |
typedef struct hid_pp_caps_info_ { |
| 110 |
USHORT FirstCap; |
| 111 |
USHORT NumberOfCaps; |
| 112 |
USHORT LastCap; |
| 113 |
USHORT ReportByteLength; |
| 114 |
} hid_pp_caps_info, *phid_pp_caps_info; |
| 115 |
|
| 116 |
typedef struct hid_pp_link_collection_node_ { |
| 117 |
USAGE LinkUsage; |
| 118 |
USAGE LinkUsagePage; |
| 119 |
USHORT Parent; |
| 120 |
USHORT NumberOfChildren; |
| 121 |
USHORT NextSibling; |
| 122 |
USHORT FirstChild; |
| 123 |
ULONG CollectionType : 8; |
| 124 |
ULONG IsAlias : 1; |
| 125 |
ULONG Reserved : 23; |
| 126 |
|
| 127 |
} hid_pp_link_collection_node, *phid_pp_link_collection_node; |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
static_assert(sizeof(struct hid_pp_link_collection_node_) == 16, |
| 134 |
"Size of struct hid_pp_link_collection_node_ not as expected. This might break binary compatibility"); |
| 135 |
|
| 136 |
typedef struct hidp_unknown_token_ { |
| 137 |
UCHAR Token; |
| 138 |
UCHAR Reserved[3]; |
| 139 |
ULONG BitField; |
| 140 |
} hidp_unknown_token, * phidp_unknown_token; |
| 141 |
|
| 142 |
typedef struct hid_pp_cap_ { |
| 143 |
USAGE UsagePage; |
| 144 |
UCHAR ReportID; |
| 145 |
UCHAR BitPosition; |
| 146 |
USHORT ReportSize; |
| 147 |
USHORT ReportCount; |
| 148 |
USHORT BytePosition; |
| 149 |
USHORT BitCount; |
| 150 |
ULONG BitField; |
| 151 |
USHORT NextBytePosition; |
| 152 |
USHORT LinkCollection; |
| 153 |
USAGE LinkUsagePage; |
| 154 |
USAGE LinkUsage; |
| 155 |
|
| 156 |
|
| 157 |
BOOLEAN IsMultipleItemsForArray:1; |
| 158 |
|
| 159 |
BOOLEAN IsPadding:1; |
| 160 |
BOOLEAN IsButtonCap:1; |
| 161 |
BOOLEAN IsAbsolute:1; |
| 162 |
BOOLEAN IsRange:1; |
| 163 |
BOOLEAN IsAlias:1; |
| 164 |
BOOLEAN IsStringRange:1; |
| 165 |
BOOLEAN IsDesignatorRange:1; |
| 166 |
|
| 167 |
BOOLEAN Reserved1[3]; |
| 168 |
|
| 169 |
hidp_unknown_token UnknownTokens[4]; |
| 170 |
|
| 171 |
union { |
| 172 |
struct { |
| 173 |
USAGE UsageMin; |
| 174 |
USAGE UsageMax; |
| 175 |
USHORT StringMin; |
| 176 |
USHORT StringMax; |
| 177 |
USHORT DesignatorMin; |
| 178 |
USHORT DesignatorMax; |
| 179 |
USHORT DataIndexMin; |
| 180 |
USHORT DataIndexMax; |
| 181 |
} Range; |
| 182 |
struct { |
| 183 |
USAGE Usage; |
| 184 |
USAGE Reserved1; |
| 185 |
USHORT StringIndex; |
| 186 |
USHORT Reserved2; |
| 187 |
USHORT DesignatorIndex; |
| 188 |
USHORT Reserved3; |
| 189 |
USHORT DataIndex; |
| 190 |
USHORT Reserved4; |
| 191 |
} NotRange; |
| 192 |
}; |
| 193 |
union { |
| 194 |
struct { |
| 195 |
LONG LogicalMin; |
| 196 |
LONG LogicalMax; |
| 197 |
} Button; |
| 198 |
struct { |
| 199 |
BOOLEAN HasNull; |
| 200 |
UCHAR Reserved4[3]; |
| 201 |
LONG LogicalMin; |
| 202 |
LONG LogicalMax; |
| 203 |
LONG PhysicalMin; |
| 204 |
LONG PhysicalMax; |
| 205 |
} NotButton; |
| 206 |
}; |
| 207 |
ULONG Units; |
| 208 |
ULONG UnitsExp; |
| 209 |
|
| 210 |
} hid_pp_cap, *phid_pp_cap; |
| 211 |
|
| 212 |
typedef struct hidp_preparsed_data_ { |
| 213 |
UCHAR MagicKey[8]; |
| 214 |
USAGE Usage; |
| 215 |
USAGE UsagePage; |
| 216 |
USHORT Reserved[2]; |
| 217 |
|
| 218 |
|
| 219 |
hid_pp_caps_info caps_info[3]; |
| 220 |
|
| 221 |
USHORT FirstByteOfLinkCollectionArray; |
| 222 |
USHORT NumberLinkCollectionNodes; |
| 223 |
|
| 224 |
#ifndef _MSC_VER |
| 225 |
|
| 226 |
|
| 227 |
union { |
| 228 |
#pragma GCC diagnostic push |
| 229 |
#pragma GCC diagnostic ignored "-Wpedantic" |
| 230 |
hid_pp_cap caps[0]; |
| 231 |
hid_pp_link_collection_node LinkCollectionArray[0]; |
| 232 |
#pragma GCC diagnostic pop |
| 233 |
}; |
| 234 |
#else |
| 235 |
union { |
| 236 |
hid_pp_cap caps[]; |
| 237 |
hid_pp_link_collection_node LinkCollectionArray[]; |
| 238 |
}; |
| 239 |
#endif |
| 240 |
|
| 241 |
} hidp_preparsed_data; |
| 242 |
|
| 243 |
#ifdef _MSC_VER |
| 244 |
#pragma warning(pop) |
| 245 |
#endif |
| 246 |
|
| 247 |
#endif |