Skip to content

Commit

Permalink
hidraw: Add support for HID over I2C and uhid devices (#166)
Browse files Browse the repository at this point in the history
- uhid USB, Bluetooth (standard) and I2C now enumerating
  * USB uhid support was added by removing the udev USB endpoint check;
- HID over I2C was excluded before (likely because it didn't exist when
  hidraw was developed);
  • Loading branch information
haata authored Nov 23, 2020
1 parent d9471d4 commit ffb50af
Showing 1 changed file with 50 additions and 40 deletions.
90 changes: 50 additions & 40 deletions linux/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,27 +506,8 @@ static int get_device_string(hid_device *dev, enum device_string_id key, wchar_t
&serial_number_utf8,
&product_name_utf8);

if (bus_type == BUS_BLUETOOTH) {
switch (key) {
case DEVICE_STRING_MANUFACTURER:
wcsncpy(string, L"", maxlen);
ret = 0;
break;
case DEVICE_STRING_PRODUCT:
retm = mbstowcs(string, product_name_utf8, maxlen);
ret = (retm == (size_t)-1)? -1: 0;
break;
case DEVICE_STRING_SERIAL:
retm = mbstowcs(string, serial_number_utf8, maxlen);
ret = (retm == (size_t)-1)? -1: 0;
break;
case DEVICE_STRING_COUNT:
default:
ret = -1;
break;
}
}
else {
/* Standard USB device */
if (bus_type == BUS_USB) {
/* This is a USB device. Find its parent USB Device node. */
parent = udev_device_get_parent_with_subsystem_devtype(
udev_dev,
Expand All @@ -548,10 +529,40 @@ static int get_device_string(hid_device *dev, enum device_string_id key, wchar_t
/* Convert the string from UTF-8 to wchar_t */
retm = mbstowcs(string, str, maxlen);
ret = (retm == (size_t)-1)? -1: 0;
goto end;
}

/* USB information parsed */
goto end;
}
else {
/* Correctly handled below */
}
}

/* USB information not available (uhid) or another type of HID bus */
switch (bus_type) {
case BUS_BLUETOOTH:
case BUS_I2C:
case BUS_USB:
switch (key) {
case DEVICE_STRING_MANUFACTURER:
wcsncpy(string, L"", maxlen);
ret = 0;
break;
case DEVICE_STRING_PRODUCT:
retm = mbstowcs(string, product_name_utf8, maxlen);
ret = (retm == (size_t)-1)? -1: 0;
break;
case DEVICE_STRING_SERIAL:
retm = mbstowcs(string, serial_number_utf8, maxlen);
ret = (retm == (size_t)-1)? -1: 0;
break;
case DEVICE_STRING_COUNT:
default:
ret = -1;
break;
}
}
}
}

Expand Down Expand Up @@ -669,9 +680,15 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
goto next;
}

if (bus_type != BUS_USB && bus_type != BUS_BLUETOOTH) {
/* We only know how to handle USB and BT devices. */
goto next;
/* Filter out unhandled devices right away */
switch (bus_type) {
case BUS_BLUETOOTH:
case BUS_I2C:
case BUS_USB:
break;

default:
goto next;
}

/* Check the VID/PID against the arguments */
Expand Down Expand Up @@ -720,22 +737,14 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
"usb",
"usb_device");

/* uhid USB devices
Since this is a virtual hid interface, no USB information will
be available. */
if (!usb_dev) {
/* Free this device */
free(cur_dev->serial_number);
free(cur_dev->path);
free(cur_dev);

/* Take it off the device list. */
if (prev_dev) {
prev_dev->next = NULL;
cur_dev = prev_dev;
}
else {
cur_dev = root = NULL;
}

goto next;
/* Manufacturer and Product strings */
cur_dev->manufacturer_string = wcsdup(L"");
cur_dev->product_string = utf8_to_wchar_t(product_name_utf8);
break;
}

/* Manufacturer and Product strings */
Expand All @@ -759,6 +768,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
break;

case BUS_BLUETOOTH:
case BUS_I2C:
/* Manufacturer and Product strings */
cur_dev->manufacturer_string = wcsdup(L"");
cur_dev->product_string = utf8_to_wchar_t(product_name_utf8);
Expand Down

0 comments on commit ffb50af

Please sign in to comment.