diff --git a/src/driver-hidpp10.c b/src/driver-hidpp10.c index d45d3a3c..5754f7ef 100644 --- a/src/driver-hidpp10.c +++ b/src/driver-hidpp10.c @@ -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 diff --git a/src/driver-hidpp20.c b/src/driver-hidpp20.c index d55f9cd5..3823ea95 100644 --- a/src/driver-hidpp20.c +++ b/src/driver-hidpp20.c @@ -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); diff --git a/src/libratbag-hidraw.c b/src/libratbag-hidraw.c index 32bf638a..0b5b16a2 100644 --- a/src/libratbag-hidraw.c +++ b/src/libratbag-hidraw.c @@ -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) { diff --git a/src/libratbag-hidraw.h b/src/libratbag-hidraw.h index ac03596e..80d2e24c 100644 --- a/src/libratbag-hidraw.h +++ b/src/libratbag-hidraw.h @@ -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 */