static int hidpp10_get_device_info(int fd, struct unifying_device *dev) { unsigned idx = dev->index; union hidpp10_message pairing_information = CMD_PAIRING_INFORMATION(idx, DEVICE_PAIRING_INFORMATION); union hidpp10_message device_name = CMD_PAIRING_INFORMATION(idx, DEVICE_NAME); union hidpp10_message firmware_information = CMD_DEVICE_FIRMWARE_INFORMATION(idx, FIRMWARE_INFO_ITEM_FW_NAME_AND_VERSION(1)); union hidpp10_message build_information = CMD_DEVICE_FIRMWARE_INFORMATION(idx, FIRMWARE_INFO_ITEM_FW_BUILD_NUMBER(1)); int name_size; int res, i; res = hidpp10_request_command(fd, &pairing_information); if (res) return -1; dev->report_interval = pairing_information.msg.string[2]; dev->wpid = (pairing_information.msg.string[3] << 8) | pairing_information.msg.string[4]; dev->device_type = pairing_information.msg.string[7]; res = hidpp10_request_command(fd, &device_name); if (res) return -1; name_size = device_name.msg.string[1]; memcpy(dev->name, &device_name.msg.string[2], sizeof(device_name.msg.string)); dev->name[MIN(name_size, sizeof(dev->name) - 1)] = '\0'; /* * This may fail on some devices * => we can not retrieve their FW version through HID++ 1.0. */ res = hidpp10_request_command(fd, &firmware_information); if (res) return 0; dev->fw_major = firmware_information.msg.string[1]; dev->fw_minor = firmware_information.msg.string[2]; res = hidpp10_request_command(fd, &build_information); if (res) return 0; dev->build = (build_information.msg.string[1] << 8) | build_information.msg.string[2]; return 0; }
int hidpp10_get_pairing_information_device_name(struct hidpp10_device *dev, char *name, size_t *name_size) { unsigned int idx = dev->index; union hidpp10_message device_name = CMD_PAIRING_INFORMATION(idx, DEVICE_NAME); int res; log_raw(dev->ratbag_device->ratbag, "Fetching device name\n"); res = hidpp10_request_command(dev, &device_name); if (res) return -1; *name_size = min(*name_size, device_name.msg.string[1]); strncpy_safe(name, (char*)&device_name.msg.string[2], *name_size); return 0; }
int hidpp10_get_pairing_information(struct hidpp10_device *dev, uint8_t *report_interval, uint16_t *wpid, uint8_t *device_type) { unsigned int idx = dev->index; union hidpp10_message pairing_information = CMD_PAIRING_INFORMATION(idx, DEVICE_PAIRING_INFORMATION); int res; log_raw(dev->ratbag_device->ratbag, "Fetching pairing information\n"); res = hidpp10_request_command(dev, &pairing_information); if (res) return -1; *report_interval = pairing_information.msg.string[2]; *wpid = hidpp10_get_unaligned_u16(&pairing_information.msg.string[3]); *device_type = pairing_information.msg.string[7]; return 0; }