Skip to content

Commit

Permalink
Fix hid_get_manufacturer_string/hid_get_product_string/hid_get_serial…
Browse files Browse the repository at this point in the history
…_number_string fro BLE devices
  • Loading branch information
DJm00n committed Jul 26, 2021
1 parent 4d18a8a commit 2be8820
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions windows/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ struct hid_device_ {
char *read_buf;
OVERLAPPED ol;
OVERLAPPED write_ol;
struct hid_device_info* device_info;
};

static hid_device *new_hid_device()
Expand All @@ -204,6 +205,7 @@ static hid_device *new_hid_device()
dev->ol.hEvent = CreateEvent(NULL, FALSE, FALSE /*initial state f=nonsignaled*/, NULL);
memset(&dev->write_ol, 0, sizeof(dev->write_ol));
dev->write_ol.hEvent = CreateEvent(NULL, FALSE, FALSE /*inital state f=nonsignaled*/, NULL);
dev->device_info = NULL;

return dev;
}
Expand All @@ -217,6 +219,7 @@ static void free_hid_device(hid_device *dev)
free(dev->write_buf);
free(dev->feature_buf);
free(dev->read_buf);
free(dev->device_info);
free(dev);
}

Expand Down Expand Up @@ -863,6 +866,8 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path)

dev->read_buf = (char*) malloc(dev->input_report_length);

dev->device_info = hid_get_device_info(path, dev->device_handle);

return dev;

err_pp_data:
Expand Down Expand Up @@ -1161,39 +1166,30 @@ void HID_API_EXPORT HID_API_CALL hid_close(hid_device *dev)

int HID_API_EXPORT_CALL HID_API_CALL hid_get_manufacturer_string(hid_device *dev, wchar_t *string, size_t maxlen)
{
BOOL res;

res = HidD_GetManufacturerString(dev->device_handle, string, sizeof(wchar_t) * (DWORD) MIN(maxlen, MAX_STRING_WCHARS));
if (!res) {
register_error(dev, "HidD_GetManufacturerString");
if (!dev->device_info)
return -1;
}

wcsncpy(string, dev->device_info->manufacturer_string, maxlen);

return 0;
}

int HID_API_EXPORT_CALL HID_API_CALL hid_get_product_string(hid_device *dev, wchar_t *string, size_t maxlen)
{
BOOL res;

res = HidD_GetProductString(dev->device_handle, string, sizeof(wchar_t) * (DWORD) MIN(maxlen, MAX_STRING_WCHARS));
if (!res) {
register_error(dev, "HidD_GetProductString");
if (!dev->device_info)
return -1;
}

wcsncpy(string, dev->device_info->product_string, maxlen);

return 0;
}

int HID_API_EXPORT_CALL HID_API_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *string, size_t maxlen)
{
BOOL res;

res = HidD_GetSerialNumberString(dev->device_handle, string, sizeof(wchar_t) * (DWORD) MIN(maxlen, MAX_STRING_WCHARS));
if (!res) {
register_error(dev, "HidD_GetSerialNumberString");
if (!dev->device_info)
return -1;
}

wcsncpy(string, dev->device_info->serial_number, maxlen);

return 0;
}
Expand Down

0 comments on commit 2be8820

Please sign in to comment.