int main(int argc, char **argv) { _cleanup_close_ int fd = 0; const char *path; size_t page = 0, offset = 0; struct hidpp20_device *dev = NULL; struct hidpp_device base; struct hidpp20_onboard_profiles_info info = { 0 }; int rc; if (argc < 2 || argc > 4) { usage(); return 1; } path = argv[argc - 1]; fd = open(path, O_RDWR); if (fd < 0) error(1, errno, "Failed to open path %s", path); hidpp_device_init(&base, fd); dev = hidpp20_device_new(&base, 0xff); if (!dev) error(1, 0, "Failed to open %s as a HID++ 2.0 device", path); hidpp20_onboard_profiles_get_profiles_desc(dev, &info); if (argc == 2) rc = dump_everything(dev, info.sector_size); else { page = atoi(argv[1]); if (argc > 3) offset = atoi(argv[2]); rc = dump_page(dev, info.sector_size, 0, page, offset); } hidpp20_device_destroy(dev); return rc; }
static int hidpp20drv_probe(struct ratbag_device *device) { int rc; struct hidpp20drv_data *drv_data; struct hidpp_device base; struct hidpp20_device *dev; const char *prop; int device_idx = HIDPP_RECEIVER_IDX; int nread = 0; rc = ratbag_find_hidraw(device, hidpp20drv_test_hidraw); if (rc) return rc; drv_data = zalloc(sizeof(*drv_data)); ratbag_set_drv_data(device, drv_data); hidpp_device_init(&base, device->hidraw.fd); hidpp_device_set_log_handler(&base, hidpp20_log, HIDPP_LOG_PRIORITY_RAW, device); prop = ratbag_device_get_udev_property(device, "RATBAG_HIDPP20_INDEX"); if (prop) { sscanf(prop, "%d%n", &device_idx, &nread); if (!nread || (prop[nread]) != '\0' || device_idx < 0) { log_error(device->ratbag, "Error parsing RATBAG_HIDPP20_INDEX: '%s' for %s\n", prop, device->name); device_idx = HIDPP_RECEIVER_IDX; } } /* In the general case, 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 use 0xff as device index. * * If there is a special need like for G900, we can pass a * udev prop RATBAG_HIDPP20_INDEX. */ dev = hidpp20_device_new(&base, device_idx); if (!dev) { rc = -ENODEV; goto err; } drv_data->dev = dev; log_debug(device->ratbag, "'%s' is using protocol v%d.%d\n", ratbag_device_get_name(device), dev->proto_major, dev->proto_minor); /* add some defaults that will be overwritten by the device */ drv_data->num_profiles = 1; drv_data->num_resolutions = 1; drv_data->num_buttons = 8; rc = hidpp20drv_20_probe(device); if (rc) goto err; ratbag_device_init_profiles(device, drv_data->num_profiles, drv_data->num_resolutions, drv_data->num_buttons); return rc; err: hidpp20drv_remove(device); return rc; }