diff --git a/windows/hid.c b/windows/hid.c index 343cdb7c0..05237fc94 100644 --- a/windows/hid.c +++ b/windows/hid.c @@ -460,7 +460,7 @@ static void hid_internal_get_usb_info(struct hid_device_info* dev, DEVINST dev_n { wchar_t *device_id = NULL, *hardware_ids = NULL; - device_id = hid_internal_get_devnode_property(dev_node, &DEVPKEY_Device_InstanceId, DEVPROP_TYPE_STRING); + device_id = (wchar_t *)hid_internal_get_devnode_property(dev_node, &DEVPKEY_Device_InstanceId, DEVPROP_TYPE_STRING); if (!device_id) goto end; @@ -478,7 +478,7 @@ static void hid_internal_get_usb_info(struct hid_device_info* dev, DEVINST dev_n } /* Get the hardware ids from devnode */ - hardware_ids = hid_internal_get_devnode_property(dev_node, &DEVPKEY_Device_HardwareIds, DEVPROP_TYPE_STRING_LIST); + hardware_ids = (wchar_t *)hid_internal_get_devnode_property(dev_node, &DEVPKEY_Device_HardwareIds, DEVPROP_TYPE_STRING_LIST); if (!hardware_ids) goto end; @@ -509,7 +509,7 @@ static void hid_internal_get_usb_info(struct hid_device_info* dev, DEVINST dev_n /* Try to get USB device manufacturer string if not provided by HidD_GetManufacturerString. */ if (wcslen(dev->manufacturer_string) == 0) { - wchar_t* manufacturer_string = hid_internal_get_devnode_property(dev_node, &DEVPKEY_Device_Manufacturer, DEVPROP_TYPE_STRING); + wchar_t* manufacturer_string = (wchar_t *)hid_internal_get_devnode_property(dev_node, &DEVPKEY_Device_Manufacturer, DEVPROP_TYPE_STRING); if (manufacturer_string) { free(dev->manufacturer_string); dev->manufacturer_string = manufacturer_string; @@ -529,7 +529,7 @@ static void hid_internal_get_usb_info(struct hid_device_info* dev, DEVINST dev_n /* Get the device id of the USB device. */ free(device_id); - device_id = hid_internal_get_devnode_property(usb_dev_node, &DEVPKEY_Device_InstanceId, DEVPROP_TYPE_STRING); + device_id = (wchar_t *)hid_internal_get_devnode_property(usb_dev_node, &DEVPKEY_Device_InstanceId, DEVPROP_TYPE_STRING); if (!device_id) goto end; @@ -568,7 +568,7 @@ static void hid_internal_get_ble_info(struct hid_device_info* dev, DEVINST dev_n { if (wcslen(dev->manufacturer_string) == 0) { /* Manufacturer Name String (UUID: 0x2A29) */ - wchar_t* manufacturer_string = hid_internal_get_devnode_property(dev_node, (const DEVPROPKEY*)&PKEY_DeviceInterface_Bluetooth_Manufacturer, DEVPROP_TYPE_STRING); + wchar_t* manufacturer_string = (wchar_t *)hid_internal_get_devnode_property(dev_node, (const DEVPROPKEY*)&PKEY_DeviceInterface_Bluetooth_Manufacturer, DEVPROP_TYPE_STRING); if (manufacturer_string) { free(dev->manufacturer_string); dev->manufacturer_string = manufacturer_string; @@ -577,7 +577,7 @@ static void hid_internal_get_ble_info(struct hid_device_info* dev, DEVINST dev_n if (wcslen(dev->serial_number) == 0) { /* Serial Number String (UUID: 0x2A25) */ - wchar_t* serial_number = hid_internal_get_devnode_property(dev_node, (const DEVPROPKEY*)&PKEY_DeviceInterface_Bluetooth_DeviceAddress, DEVPROP_TYPE_STRING); + wchar_t* serial_number = (wchar_t *)hid_internal_get_devnode_property(dev_node, (const DEVPROPKEY*)&PKEY_DeviceInterface_Bluetooth_DeviceAddress, DEVPROP_TYPE_STRING); if (serial_number) { free(dev->serial_number); dev->serial_number = serial_number; @@ -586,13 +586,13 @@ static void hid_internal_get_ble_info(struct hid_device_info* dev, DEVINST dev_n if (wcslen(dev->product_string) == 0) { /* Model Number String (UUID: 0x2A24) */ - wchar_t* product_string = hid_internal_get_devnode_property(dev_node, (const DEVPROPKEY*)&PKEY_DeviceInterface_Bluetooth_ModelNumber, DEVPROP_TYPE_STRING); + wchar_t* product_string = (wchar_t *)hid_internal_get_devnode_property(dev_node, (const DEVPROPKEY*)&PKEY_DeviceInterface_Bluetooth_ModelNumber, DEVPROP_TYPE_STRING); if (!product_string) { DEVINST parent_dev_node = 0; /* Fallback: Get devnode grandparent to reach out Bluetooth LE device node */ if (CM_Get_Parent(&parent_dev_node, dev_node, 0) == CR_SUCCESS) { /* Device Name (UUID: 0x2A00) */ - product_string = hid_internal_get_devnode_property(parent_dev_node, &DEVPKEY_NAME, DEVPROP_TYPE_STRING); + product_string = (wchar_t *)hid_internal_get_devnode_property(parent_dev_node, &DEVPKEY_NAME, DEVPROP_TYPE_STRING); } } @@ -621,7 +621,7 @@ static hid_internal_detect_bus_type_result hid_internal_detect_bus_type(const wc hid_internal_detect_bus_type_result result = { 0 }; /* Get the device id from interface path */ - device_id = hid_internal_get_device_interface_property(interface_path, &DEVPKEY_Device_InstanceId, DEVPROP_TYPE_STRING); + device_id = (wchar_t *)hid_internal_get_device_interface_property(interface_path, &DEVPKEY_Device_InstanceId, DEVPROP_TYPE_STRING); if (!device_id) goto end; @@ -636,7 +636,7 @@ static hid_internal_detect_bus_type_result hid_internal_detect_bus_type(const wc goto end; /* Get the compatible ids from parent devnode */ - compatible_ids = hid_internal_get_devnode_property(dev_node, &DEVPKEY_Device_CompatibleIds, DEVPROP_TYPE_STRING_LIST); + compatible_ids = (wchar_t *)hid_internal_get_devnode_property(dev_node, &DEVPKEY_Device_CompatibleIds, DEVPROP_TYPE_STRING_LIST); if (!compatible_ids) goto end; @@ -1515,7 +1515,7 @@ int HID_API_EXPORT_CALL hid_winapi_get_container_id(hid_device *dev, GUID *conta } /* Get the device id from interface path */ - device_id = hid_internal_get_device_interface_property(interface_path, &DEVPKEY_Device_InstanceId, DEVPROP_TYPE_STRING); + device_id = (wchar_t *)hid_internal_get_device_interface_property(interface_path, &DEVPKEY_Device_InstanceId, DEVPROP_TYPE_STRING); if (!device_id) { register_string_error(dev, L"Failed to get device interface property InstanceId"); goto end; diff --git a/windows/hidapi_descriptor_reconstruct.c b/windows/hidapi_descriptor_reconstruct.c index e47d3a0c7..04f5ee7b2 100644 --- a/windows/hidapi_descriptor_reconstruct.c +++ b/windows/hidapi_descriptor_reconstruct.c @@ -140,7 +140,7 @@ static struct rd_main_item_node * rd_append_main_item_node(int first_bit, int la list = &(*list)->next; } - new_list_node = malloc(sizeof(*new_list_node)); // Create new list entry + new_list_node = (struct rd_main_item_node *)malloc(sizeof(*new_list_node)); // Create new list entry new_list_node->FirstBit = first_bit; new_list_node->LastBit = last_bit; new_list_node->TypeOfNode = type_of_node; @@ -203,13 +203,13 @@ int hid_winapi_descriptor_reconstruct_pp_data(void *preparsed_data, unsigned cha // Allocate memory and initialize lookup table rd_bit_range ****coll_bit_range; - coll_bit_range = malloc(pp_data->NumberLinkCollectionNodes * sizeof(*coll_bit_range)); + coll_bit_range = (rd_bit_range ****)malloc(pp_data->NumberLinkCollectionNodes * sizeof(*coll_bit_range)); for (USHORT collection_node_idx = 0; collection_node_idx < pp_data->NumberLinkCollectionNodes; collection_node_idx++) { - coll_bit_range[collection_node_idx] = malloc(256 * sizeof(*coll_bit_range[0])); // 256 possible report IDs (incl. 0x00) + coll_bit_range[collection_node_idx] = (rd_bit_range ***)malloc(256 * sizeof(*coll_bit_range[0])); // 256 possible report IDs (incl. 0x00) for (int reportid_idx = 0; reportid_idx < 256; reportid_idx++) { - coll_bit_range[collection_node_idx][reportid_idx] = malloc(NUM_OF_HIDP_REPORT_TYPES * sizeof(*coll_bit_range[0][0])); - for (HIDP_REPORT_TYPE rt_idx = 0; rt_idx < NUM_OF_HIDP_REPORT_TYPES; rt_idx++) { - coll_bit_range[collection_node_idx][reportid_idx][rt_idx] = malloc(sizeof(rd_bit_range)); + coll_bit_range[collection_node_idx][reportid_idx] = (rd_bit_range **)malloc(NUM_OF_HIDP_REPORT_TYPES * sizeof(*coll_bit_range[0][0])); + for (int rt_idx = 0; rt_idx < NUM_OF_HIDP_REPORT_TYPES; rt_idx++) { + coll_bit_range[collection_node_idx][reportid_idx][rt_idx] = (rd_bit_range *)malloc(sizeof(rd_bit_range)); coll_bit_range[collection_node_idx][reportid_idx][rt_idx]->FirstBit = -1; coll_bit_range[collection_node_idx][reportid_idx][rt_idx]->LastBit = -1; } @@ -217,7 +217,7 @@ int hid_winapi_descriptor_reconstruct_pp_data(void *preparsed_data, unsigned cha } // Fill the lookup table where caps exist - for (HIDP_REPORT_TYPE rt_idx = 0; rt_idx < NUM_OF_HIDP_REPORT_TYPES; rt_idx++) { + for (int rt_idx = 0; rt_idx < NUM_OF_HIDP_REPORT_TYPES; rt_idx++) { for (USHORT caps_idx = pp_data->caps_info[rt_idx].FirstCap; caps_idx < pp_data->caps_info[rt_idx].LastCap; caps_idx++) { int first_bit, last_bit; first_bit = (pp_data->caps[caps_idx].BytePosition - 1) * 8 @@ -241,8 +241,8 @@ int hid_winapi_descriptor_reconstruct_pp_data(void *preparsed_data, unsigned cha // coll_number_of_direct_childs[COLLECTION_INDEX] // ************************************************************************* int max_coll_level = 0; - int *coll_levels = malloc(pp_data->NumberLinkCollectionNodes * sizeof(coll_levels[0])); - int *coll_number_of_direct_childs = malloc(pp_data->NumberLinkCollectionNodes * sizeof(coll_number_of_direct_childs[0])); + int *coll_levels = (int *)malloc(pp_data->NumberLinkCollectionNodes * sizeof(coll_levels[0])); + int *coll_number_of_direct_childs = (int *)malloc(pp_data->NumberLinkCollectionNodes * sizeof(coll_number_of_direct_childs[0])); for (USHORT collection_node_idx = 0; collection_node_idx < pp_data->NumberLinkCollectionNodes; collection_node_idx++) { coll_levels[collection_node_idx] = -1; coll_number_of_direct_childs[collection_node_idx] = 0; @@ -286,7 +286,7 @@ int hid_winapi_descriptor_reconstruct_pp_data(void *preparsed_data, unsigned cha USHORT child_idx = link_collection_nodes[collection_node_idx].FirstChild; while (child_idx) { for (int reportid_idx = 0; reportid_idx < 256; reportid_idx++) { - for (HIDP_REPORT_TYPE rt_idx = 0; rt_idx < NUM_OF_HIDP_REPORT_TYPES; rt_idx++) { + for (int rt_idx = 0; rt_idx < NUM_OF_HIDP_REPORT_TYPES; rt_idx++) { // Merge bit range from childs if ((coll_bit_range[child_idx][reportid_idx][rt_idx]->FirstBit != -1) && (coll_bit_range[collection_node_idx][reportid_idx][rt_idx]->FirstBit > coll_bit_range[child_idx][reportid_idx][rt_idx]->FirstBit)) { @@ -307,11 +307,9 @@ int hid_winapi_descriptor_reconstruct_pp_data(void *preparsed_data, unsigned cha // Determine child collection order of the whole hierarchy, based on previously determined bit ranges // and store it this index coll_child_order[COLLECTION_INDEX][DIRECT_CHILD_INDEX] // ************************************************************************************************** - USHORT **coll_child_order; - coll_child_order = malloc(pp_data->NumberLinkCollectionNodes * sizeof(*coll_child_order)); + USHORT **coll_child_order = (USHORT **)malloc(pp_data->NumberLinkCollectionNodes * sizeof(*coll_child_order)); { - BOOLEAN *coll_parsed_flag; - coll_parsed_flag = malloc(pp_data->NumberLinkCollectionNodes * sizeof(coll_parsed_flag[0])); + BOOLEAN *coll_parsed_flag = (BOOLEAN *)malloc(pp_data->NumberLinkCollectionNodes * sizeof(coll_parsed_flag[0])); for (USHORT collection_node_idx = 0; collection_node_idx < pp_data->NumberLinkCollectionNodes; collection_node_idx++) { coll_parsed_flag[collection_node_idx] = FALSE; } @@ -321,7 +319,7 @@ int hid_winapi_descriptor_reconstruct_pp_data(void *preparsed_data, unsigned cha if ((coll_number_of_direct_childs[collection_node_idx] != 0) && (coll_parsed_flag[link_collection_nodes[collection_node_idx].FirstChild] == FALSE)) { coll_parsed_flag[link_collection_nodes[collection_node_idx].FirstChild] = TRUE; - coll_child_order[collection_node_idx] = malloc((coll_number_of_direct_childs[collection_node_idx]) * sizeof(*coll_child_order[0])); + coll_child_order[collection_node_idx] = (USHORT *)malloc((coll_number_of_direct_childs[collection_node_idx]) * sizeof(*coll_child_order[0])); { // Create list of child collection indices @@ -339,7 +337,7 @@ int hid_winapi_descriptor_reconstruct_pp_data(void *preparsed_data, unsigned cha if (coll_number_of_direct_childs[collection_node_idx] > 1) { // Sort child collections indices by bit positions - for (HIDP_REPORT_TYPE rt_idx = 0; rt_idx < NUM_OF_HIDP_REPORT_TYPES; rt_idx++) { + for (int rt_idx = 0; rt_idx < NUM_OF_HIDP_REPORT_TYPES; rt_idx++) { for (int reportid_idx = 0; reportid_idx < 256; reportid_idx++) { for (int child_idx = 1; child_idx < coll_number_of_direct_childs[collection_node_idx]; child_idx++) { // since the coll_bit_range array is not sorted, we need to reference the collection index in @@ -380,10 +378,10 @@ int hid_winapi_descriptor_reconstruct_pp_data(void *preparsed_data, unsigned cha // *************************************************************************************** struct rd_main_item_node *main_item_list = NULL; // List root // Lookup table to find the Collection items in the list by index - struct rd_main_item_node **coll_begin_lookup = malloc(pp_data->NumberLinkCollectionNodes * sizeof(*coll_begin_lookup)); - struct rd_main_item_node **coll_end_lookup = malloc(pp_data->NumberLinkCollectionNodes * sizeof(*coll_end_lookup)); + struct rd_main_item_node **coll_begin_lookup = (struct rd_main_item_node **)malloc(pp_data->NumberLinkCollectionNodes * sizeof(*coll_begin_lookup)); + struct rd_main_item_node **coll_end_lookup = (struct rd_main_item_node **)malloc(pp_data->NumberLinkCollectionNodes * sizeof(*coll_end_lookup)); { - int *coll_last_written_child = malloc(pp_data->NumberLinkCollectionNodes * sizeof(coll_last_written_child[0])); + int *coll_last_written_child = (int *)malloc(pp_data->NumberLinkCollectionNodes * sizeof(coll_last_written_child[0])); for (USHORT collection_node_idx = 0; collection_node_idx < pp_data->NumberLinkCollectionNodes; collection_node_idx++) { coll_last_written_child[collection_node_idx] = -1; } @@ -467,7 +465,7 @@ int hid_winapi_descriptor_reconstruct_pp_data(void *preparsed_data, unsigned cha // Inserted Input/Output/Feature main items into the main_item_list // in order of reconstructed bit positions // **************************************************************** - for (HIDP_REPORT_TYPE rt_idx = 0; rt_idx < NUM_OF_HIDP_REPORT_TYPES; rt_idx++) { + for (int rt_idx = 0; rt_idx < NUM_OF_HIDP_REPORT_TYPES; rt_idx++) { // Add all value caps to node list struct rd_main_item_node *firstDelimiterNode = NULL; struct rd_main_item_node *delimiterCloseNode = NULL; @@ -530,7 +528,7 @@ int hid_winapi_descriptor_reconstruct_pp_data(void *preparsed_data, unsigned cha { int last_bit_position[NUM_OF_HIDP_REPORT_TYPES][256]; struct rd_main_item_node *last_report_item_lookup[NUM_OF_HIDP_REPORT_TYPES][256]; - for (HIDP_REPORT_TYPE rt_idx = 0; rt_idx < NUM_OF_HIDP_REPORT_TYPES; rt_idx++) { + for (int rt_idx = 0; rt_idx < NUM_OF_HIDP_REPORT_TYPES; rt_idx++) { for (int reportid_idx = 0; reportid_idx < 256; reportid_idx++) { last_bit_position[rt_idx][reportid_idx] = -1; last_report_item_lookup[rt_idx][reportid_idx] = NULL; @@ -570,7 +568,7 @@ int hid_winapi_descriptor_reconstruct_pp_data(void *preparsed_data, unsigned cha } // Add 8 bit padding at each report end - for (HIDP_REPORT_TYPE rt_idx = 0; rt_idx < NUM_OF_HIDP_REPORT_TYPES; rt_idx++) { + for (int rt_idx = 0; rt_idx < NUM_OF_HIDP_REPORT_TYPES; rt_idx++) { for (int reportid_idx = 0; reportid_idx < 256; reportid_idx++) { if (last_bit_position[rt_idx][reportid_idx] != -1) { int padding = 8 - ((last_bit_position[rt_idx][reportid_idx] + 1) % 8); @@ -588,7 +586,7 @@ int hid_winapi_descriptor_reconstruct_pp_data(void *preparsed_data, unsigned cha } // Add full byte padding at the end of the report descriptor (only reconstructable, for devices without Report IDs) - for (HIDP_REPORT_TYPE rt_idx = 0; rt_idx < NUM_OF_HIDP_REPORT_TYPES; rt_idx++) { + for (int rt_idx = 0; rt_idx < NUM_OF_HIDP_REPORT_TYPES; rt_idx++) { if (!devicehasReportIDs && pp_data->caps_info[rt_idx].NumberOfCaps > 0 && pp_data->caps_info[rt_idx].ReportByteLength > 0) { // ReportID 0 means this device uses not Report IDs // => Maximum one report per type possible, so we can take the size from the buffer size for the report type @@ -1010,7 +1008,7 @@ int hid_winapi_descriptor_reconstruct_pp_data(void *preparsed_data, unsigned cha // Free multidimensionable array: coll_child_order[COLLECTION_INDEX][DIRECT_CHILD_INDEX] for (USHORT collection_node_idx = 0; collection_node_idx < pp_data->NumberLinkCollectionNodes; collection_node_idx++) { for (int reportid_idx = 0; reportid_idx < 256; reportid_idx++) { - for (HIDP_REPORT_TYPE rt_idx = 0; rt_idx < NUM_OF_HIDP_REPORT_TYPES; rt_idx++) { + for (int rt_idx = 0; rt_idx < NUM_OF_HIDP_REPORT_TYPES; rt_idx++) { free(coll_bit_range[collection_node_idx][reportid_idx][rt_idx]); } free(coll_bit_range[collection_node_idx][reportid_idx]); diff --git a/windows/hidapi_hidclass.h b/windows/hidapi_hidclass.h index 13bd6f22b..4ad98eabb 100644 --- a/windows/hidapi_hidclass.h +++ b/windows/hidapi_hidclass.h @@ -29,6 +29,24 @@ /* This part of the header mimics hidclass.h, but only what is used by HIDAPI */ +#ifndef FILE_DEVICE_KEYBOARD +#define FILE_DEVICE_KEYBOARD 0x0000000b +#endif + +#ifndef METHOD_OUT_DIRECT +#define METHOD_OUT_DIRECT 2 +#endif + +#ifndef FILE_ANY_ACCESS +#define FILE_ANY_ACCESS 0 +#endif + +#ifndef CTL_CODE +#define CTL_CODE( DeviceType, Function, Method, Access ) ( \ + ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \ +) +#endif + #define HID_OUT_CTL_CODE(id) CTL_CODE(FILE_DEVICE_KEYBOARD, (id), METHOD_OUT_DIRECT, FILE_ANY_ACCESS) #define IOCTL_HID_GET_FEATURE HID_OUT_CTL_CODE(100) #define IOCTL_HID_GET_INPUT_REPORT HID_OUT_CTL_CODE(104)