mirror of
https://github.com/libratbag/libratbag.git
synced 2026-11-07 23:23:52 +01:00
drv-hidpp**: check if the device accepts the HID++ reports
Removes the broken pipe on invalid nodes Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
This commit is contained in:
@@ -208,6 +208,11 @@ hidpp10drv_probe(struct ratbag_device *device, const struct ratbag_id id)
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!ratbag_hidraw_has_report(device, REPORT_ID_SHORT)) {
|
||||
ratbag_close_hidraw(device);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
drv_data = zalloc(sizeof(*drv_data));
|
||||
|
||||
/* We can treat all devices as wired devices here. If we talk to the
|
||||
|
||||
@@ -446,6 +446,11 @@ hidpp20drv_probe(struct ratbag_device *device, const struct ratbag_id id)
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (!ratbag_hidraw_has_report(device, REPORT_ID_LONG)) {
|
||||
ratbag_close_hidraw(device);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
drv_data = zalloc(sizeof(*drv_data));
|
||||
ratbag_set_drv_data(device, drv_data);
|
||||
|
||||
|
||||
@@ -137,6 +137,19 @@ err:
|
||||
return -errno;
|
||||
}
|
||||
|
||||
int
|
||||
ratbag_hidraw_has_report(struct ratbag_device *device, uint8_t report_id)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < device->hidraw.num_report_ids; i++) {
|
||||
if (device->hidraw.report_ids[i] == report_id)
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
ratbag_close_hidraw(struct ratbag_device *device)
|
||||
{
|
||||
|
||||
@@ -96,4 +96,15 @@ int ratbag_hidraw_output_report(struct ratbag_device *device, uint8_t *buf, size
|
||||
*/
|
||||
int ratbag_hidraw_read_input_report(struct ratbag_device *device, uint8_t *buf, size_t len);
|
||||
|
||||
/**
|
||||
* Tells if a given device has the specified report ID.
|
||||
*
|
||||
* @param device the ratbag device which hidraw node is opened
|
||||
* @param report_id the report ID we inquire about
|
||||
*
|
||||
* @return 1 if the device has the given report id, 0 otherwise
|
||||
*/
|
||||
int
|
||||
ratbag_hidraw_has_report(struct ratbag_device *device, uint8_t report_id);
|
||||
|
||||
#endif /* LIBRATBAG_HIDRAW_H */
|
||||
|
||||
Reference in New Issue
Block a user