1
0
forked from drath/libratbag

hidpp10: use 0x00 to talk to all devices, skip receiver handling

The kernel overwrites the device ID with the correct one for our device, so we
can just use 0x00 for all devices and skip the search for the unifying
receiver hidraw device.

Since we're not talking to the receiver anymore, we can/have to drop the
pairing information queries and the related info. Since we weren't using this
anyway it's not a big loss.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer
2015-08-27 11:42:48 +10:00
parent 25aeaa68d6
commit 2fbf156403
2 changed files with 17 additions and 101 deletions

View File

@@ -143,82 +143,6 @@ hidpp10drv_write_profile(struct ratbag_profile *profile)
return -1;
}
static bool
hidpp10drv_is_unifying_receiver(struct ratbag_device *device)
{
struct udev_device *hidraw;
struct input_id id;
const char *product;
int rc;
hidraw = device->udev_hidraw;
/* Note: PRODUCT on the hid device is missing the bustype! */
product = udev_prop_value(hidraw, "PRODUCT");
rc = sscanf(product, "%hx/%hx/%hx", &id.vendor, &id.product, &id.version);
if (rc != 3)
return false;
if (id.vendor == USB_VENDOR_ID_LOGITECH &&
(id.product == 0xc52b || id.product == 0xc532))
return true;
return false;
}
static int
hidpp10drv_find_unifying_hidraw(struct ratbag_device *device)
{
struct udev_device *receiver, *hid, *hidraw;
struct udev *udev;
struct udev_enumerate *e;
struct udev_list_entry *entry;
hidraw = device->udev_hidraw;
/* the receiver device is two up */
hid = udev_device_get_parent_with_subsystem_devtype(hidraw, "hid", NULL);
receiver = udev_device_get_parent_with_subsystem_devtype(hid, "hid", NULL);
if (!receiver)
return -1; /* should not happen */
udev = udev_device_get_udev(hidraw);
e = udev_enumerate_new(udev);
udev_enumerate_add_match_subsystem(e, "hidraw");
udev_enumerate_add_match_parent(e, receiver);
udev_enumerate_scan_devices(e);
udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
const char *path, *sysname;
path = udev_list_entry_get_name(entry);
hidraw = udev_device_new_from_syspath(udev, path);
if (!hidraw)
continue;
sysname = udev_device_get_sysname(hidraw);
if (!strneq("hidraw", sysname, 6)) {
udev_device_unref(hidraw);
continue;
}
/* The receiver has multiple hidraw devices, we only want
* the one where the direct parent is the receiver */
hid = udev_device_get_parent_with_subsystem_devtype(hidraw, "hid", NULL);
if (!streq(udev_device_get_syspath(hid), udev_device_get_syspath(receiver)))
continue;
ratbag_device_set_hidraw_device(device, hidraw);
udev_device_unref(hidraw);
goto out;
}
out:
udev_enumerate_unref(e);
return 0;
}
static int
hidpp10drv_fill_from_profile(struct ratbag_device *device, struct hidpp10_device *dev)
{
@@ -244,13 +168,6 @@ hidpp10drv_probe(struct ratbag_device *device, const struct ratbag_id id)
int rc;
struct hidpp10drv_data *drv_data;
struct hidpp10_device *dev;
bool is_unifying_receiver;
/* check if the device is a unifying receiver first so we can update
* the hidraw path before we open it */
is_unifying_receiver = hidpp10drv_is_unifying_receiver(device);
if (is_unifying_receiver)
hidpp10drv_find_unifying_hidraw(device);
rc = ratbag_open_hidraw(device);
if (rc) {
@@ -268,10 +185,12 @@ hidpp10drv_probe(struct ratbag_device *device, const struct ratbag_id id)
goto err;
}
if (is_unifying_receiver)
dev = hidpp10_device_new_from_wpid(device, id.id.product);
else
dev = hidpp10_device_new_from_idx(device, WIRED_DEVICE_IDX);
/* We can treat all devices as wired devices here. If we talk to the
* correct hidraw device the kernel adjusts the device index for us,
* so even for unifying receiver devices we can just 0x00 as device
* index.
*/
dev = hidpp10_device_new_from_idx(device, WIRED_DEVICE_IDX);
if (!dev) {
log_error(device->ratbag,

View File

@@ -101,7 +101,6 @@ hidpp10_request_command(struct hidpp10_device *dev, union hidpp10_message *msg)
struct ratbag *ratbag = device->ratbag;
union hidpp10_message read_buffer;
union hidpp10_message expected_header;
union hidpp10_message expected_error_recv = ERROR_MSG(msg, RECEIVER_IDX);
union hidpp10_message expected_error_dev = ERROR_MSG(msg, msg->msg.device_idx);
int ret;
uint8_t hidpp_err = 0;
@@ -125,7 +124,6 @@ hidpp10_request_command(struct hidpp10_device *dev, union hidpp10_message *msg)
log_buf_debug(ratbag, "sending: ", msg->data, SHORT_MESSAGE_LENGTH);
log_buf_debug(ratbag, " expected_header: ", expected_header.data, SHORT_MESSAGE_LENGTH);
log_buf_debug(ratbag, " expected_error_recv: ", expected_error_recv.data, SHORT_MESSAGE_LENGTH);
log_buf_debug(ratbag, " expected_error_dev: ", expected_error_dev.data, SHORT_MESSAGE_LENGTH);
/* Send the message to the Device */
@@ -139,14 +137,23 @@ hidpp10_request_command(struct hidpp10_device *dev, union hidpp10_message *msg)
*/
do {
ret = ratbag_hidraw_read_input_report(device, read_buffer.data, LONG_MESSAGE_LENGTH);
/* Overwrite the return device index with ours. The kernel
* sets our device index on write, but gives us the real
* device index on reply. Overwrite it with our index so the
* messages are easier to check and compare.
*/
read_buffer.msg.device_idx = msg->msg.device_idx;
log_buf_debug(ratbag, " *** received: ", read_buffer.data, ret);
/* actual answer */
if (!memcmp(read_buffer.data, expected_header.data, 4))
break;
/* error */
if (!memcmp(read_buffer.data, expected_error_recv.data, 5) ||
!memcmp(read_buffer.data, expected_error_dev.data, 5)) {
if (!memcmp(read_buffer.data, expected_error_dev.data, 5)) {
hidpp_err = read_buffer.msg.parameters[1];
log_debug(ratbag,
" HID++ error from the %s (%d): %s (%02x)\n",
@@ -907,20 +914,10 @@ void hidpp10_list_devices(struct ratbag_device *device) {
static int
hidpp10_get_device_info(struct hidpp10_device *dev)
{
size_t name_size = sizeof(dev->name);
uint8_t f1, f2;
uint8_t reflect;
int i;
hidpp10_get_pairing_information(dev,
&dev->report_interval,
&dev->wpid,
&dev->device_type);
hidpp10_get_pairing_information_device_name(dev,
dev->name,
&name_size);
hidpp10_get_firmare_information(dev, &dev->fw_major, &dev->fw_minor, &dev->build);
hidpp10_get_individual_features(dev, &f1, &f2);
hidpp10_get_hidpp_notifications(dev, &f1, &f2);