static int saitek_raw_event(struct hid_device *hdev, struct hid_report *report, u8 *raw_data, int size) { struct saitek_sc *ssc = hid_get_drvdata(hdev); if (ssc->quirks & SAITEK_RELEASE_MODE_RAT7 && size == 7) { /* R.A.T.7 uses bits 13, 14, 15 for the mode */ int mode = -1; if (raw_data[1] & 0x01) mode = 0; else if (raw_data[1] & 0x02) mode = 1; else if (raw_data[1] & 0x04) mode = 2; /* clear mode bits */ raw_data[1] &= ~0x07; if (mode != ssc->mode) { hid_dbg(hdev, "entered mode %d\n", mode); if (ssc->mode != -1) { /* use bit 13 as the mode button */ raw_data[1] |= 0x04; } ssc->mode = mode; } } else if (ssc->quirks & SAITEK_RELEASE_MODE_MMO7 && size == 8) { /* M.M.O.7 uses bits 8, 22, 23 for the mode */ int mode = -1; if (raw_data[1] & 0x80) mode = 0; else if (raw_data[2] & 0x01) mode = 1; else if (raw_data[2] & 0x02) mode = 2; /* clear mode bits */ raw_data[1] &= ~0x80; raw_data[2] &= ~0x03; if (mode != ssc->mode) { hid_dbg(hdev, "entered mode %d\n", mode); if (ssc->mode != -1) { /* use bit 8 as the mode button, bits 22 * and 23 do not represent buttons * according to the HID report descriptor */ raw_data[1] |= 0x80; } ssc->mode = mode; } } return 0; }
int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev, u32 usage_id, struct hid_sensor_common *st) { struct hid_sensor_hub_attribute_info timestamp; s32 value; int ret; hid_sensor_get_reporting_interval(hsdev, usage_id, st); sensor_hub_input_get_attribute_info(hsdev, HID_FEATURE_REPORT, usage_id, HID_USAGE_SENSOR_PROP_REPORT_STATE, &st->report_state); sensor_hub_input_get_attribute_info(hsdev, HID_FEATURE_REPORT, usage_id, HID_USAGE_SENSOR_PROY_POWER_STATE, &st->power_state); sensor_hub_input_get_attribute_info(hsdev, HID_FEATURE_REPORT, usage_id, HID_USAGE_SENSOR_PROP_SENSITIVITY_ABS, &st->sensitivity); st->raw_hystersis = -1; sensor_hub_input_get_attribute_info(hsdev, HID_INPUT_REPORT, usage_id, HID_USAGE_SENSOR_TIME_TIMESTAMP, ×tamp); if (timestamp.index >= 0 && timestamp.report_id) { int val0, val1; hid_sensor_format_scale(HID_USAGE_SENSOR_TIME_TIMESTAMP, ×tamp, &val0, &val1); st->timestamp_ns_scale = val0; } else st->timestamp_ns_scale = 1000000000; hid_sensor_get_report_latency_info(hsdev, usage_id, st); hid_dbg(hsdev->hdev, "common attributes: %x:%x, %x:%x, %x:%x %x:%x %x:%x\n", st->poll.index, st->poll.report_id, st->report_state.index, st->report_state.report_id, st->power_state.index, st->power_state.report_id, st->sensitivity.index, st->sensitivity.report_id, timestamp.index, timestamp.report_id); ret = sensor_hub_get_feature(hsdev, st->power_state.report_id, st->power_state.index, sizeof(value), &value); if (ret < 0) return ret; if (value < 0) return -EINVAL; return 0; }
int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev, u32 usage_id, struct hid_sensor_iio_common *st) { sensor_hub_input_get_attribute_info(hsdev, HID_FEATURE_REPORT, usage_id, HID_USAGE_SENSOR_PROP_REPORT_INTERVAL, &st->poll); sensor_hub_input_get_attribute_info(hsdev, HID_FEATURE_REPORT, usage_id, HID_USAGE_SENSOR_PROP_REPORT_STATE, &st->report_state); sensor_hub_input_get_attribute_info(hsdev, HID_FEATURE_REPORT, usage_id, HID_USAGE_SENSOR_PROY_POWER_STATE, &st->power_state); sensor_hub_input_get_attribute_info(hsdev, HID_FEATURE_REPORT, usage_id, HID_USAGE_SENSOR_PROP_SENSITIVITY_ABS, &st->sensitivity); hid_dbg(hsdev->hdev, "common attributes: %x:%x, %x:%x, %x:%x %x:%x\n", st->poll.index, st->poll.report_id, st->report_state.index, st->report_state.report_id, st->power_state.index, st->power_state.report_id, st->sensitivity.index, st->sensitivity.report_id); return 0; }
static int valve_sc_raw_event(struct hid_device *hdev, struct hid_report *report, u8 *raw_data, int size) { struct valve_sc_device *sc = hid_get_drvdata (hdev); struct input_dev *input = sc->input; if (sc->parse_raw_report && size == 64) { switch (raw_data[SC_OFFSET_TYPE]) { case 0x01: /* Input events */ if (raw_data[SC_OFFSET_LENGTH] != 60) hid_warn(hdev, "Wrong input event length.\n"); if (input) valve_sc_parse_input_events(sc, raw_data); break; case 0x03: /* Connection events */ if (raw_data[SC_OFFSET_LENGTH] != 1) hid_warn(hdev, "Wrong connection event length.\n"); switch (raw_data[4]) { case 0x01: /* Disconnected device */ hid_dbg(hdev, "Disconnected event\n"); if (sc->connected) { sc->connected = false; schedule_work(&sc->disconnect_work); } break; case 0x02: /* Connected device */ hid_dbg(hdev, "Connected event\n"); if (!sc->connected) { sc->connected = true; schedule_work(&sc->connect_work); } break; case 0x03: /* Paired device*/ default: break; } break; default: break; } } return 0; }
static void hid_sensor_get_report_latency_info(struct hid_sensor_hub_device *hsdev, u32 usage_id, struct hid_sensor_common *st) { sensor_hub_input_get_attribute_info(hsdev, HID_FEATURE_REPORT, usage_id, HID_USAGE_SENSOR_PROP_REPORT_LATENCY, &st->report_latency); hid_dbg(hsdev->hdev, "Report latency attributes: %x:%x\n", st->report_latency.index, st->report_latency.report_id); }
static int blink1_send_command(struct blink1_data *data, u8 buf[BLINK1_CMD_SIZE]) { int ret; hid_dbg(data->hdev, "command: %d%c%.2x%.2x%.2x%.2x%.2x%.2x%.2x\n", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8]); ret = data->hdev->hid_output_raw_report(data->hdev, buf, BLINK1_CMD_SIZE, HID_FEATURE_REPORT); return ret < 0 ? ret : 0; }
static int lenovo_probe_cptkbd(struct hid_device *hdev) { int ret; struct lenovo_drvdata_cptkbd *cptkbd_data; /* All the custom action happens on the USBMOUSE device for USB */ if (hdev->product == USB_DEVICE_ID_LENOVO_CUSBKBD && hdev->type != HID_TYPE_USBMOUSE) { hid_dbg(hdev, "Ignoring keyboard half of device\n"); return 0; } cptkbd_data = devm_kzalloc(&hdev->dev, sizeof(*cptkbd_data), GFP_KERNEL); if (cptkbd_data == NULL) { hid_err(hdev, "can't alloc keyboard descriptor\n"); return -ENOMEM; } hid_set_drvdata(hdev, cptkbd_data); /* * Tell the keyboard a driver understands it, and turn F7, F9, F11 into * regular keys */ ret = lenovo_send_cmd_cptkbd(hdev, 0x01, 0x03); if (ret) hid_warn(hdev, "Failed to switch F7/9/11 mode: %d\n", ret); /* Switch middle button to native mode */ ret = lenovo_send_cmd_cptkbd(hdev, 0x09, 0x01); if (ret) hid_warn(hdev, "Failed to switch middle button: %d\n", ret); /* Set keyboard settings to known state */ cptkbd_data->middlebutton_state = 0; cptkbd_data->fn_lock = true; cptkbd_data->sensitivity = 0x05; lenovo_features_set_cptkbd(hdev); ret = sysfs_create_group(&hdev->dev.kobj, &lenovo_attr_group_cptkbd); if (ret) hid_warn(hdev, "Could not create sysfs group: %d\n", ret); return 0; }
int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev, u32 usage_id, struct hid_sensor_common *st) { sensor_hub_input_get_attribute_info(hsdev, HID_FEATURE_REPORT, usage_id, HID_USAGE_SENSOR_PROP_REPORT_INTERVAL, &st->poll); /* Default unit of measure is milliseconds */ if (st->poll.units == 0) st->poll.units = HID_USAGE_SENSOR_UNITS_MILLISECOND; sensor_hub_input_get_attribute_info(hsdev, HID_FEATURE_REPORT, usage_id, HID_USAGE_SENSOR_PROP_REPORT_STATE, &st->report_state); sensor_hub_input_get_attribute_info(hsdev, HID_FEATURE_REPORT, usage_id, HID_USAGE_SENSOR_PROT_POWER_STATE, &st->power_state); sensor_hub_input_get_attribute_info(hsdev, HID_FEATURE_REPORT, usage_id, HID_USAGE_SENSOR_PROP_SENSITIVITY_ABS, &st->sensitivity); sensor_hub_input_get_attribute_info(hsdev, HID_FEATURE_REPORT, usage_id, HID_USAGE_SENSOR_PROP_SENSOR_CONNECTION_TYPE, &st->conn_type); hid_dbg(hsdev->hdev, "common attributes: %x:%x, %x:%x, %x:%x %x:%x %x:%x\n", st->poll.index, st->poll.report_id, st->report_state.index, st->report_state.report_id, st->power_state.index, st->power_state.report_id, st->sensitivity.index, st->sensitivity.report_id, st->conn_type.index, st->conn_type.report_id); return 0; }
static int u2fzero_rng_read(struct hwrng *rng, void *data, size_t max, bool wait) { struct u2fzero_device *dev = container_of(rng, struct u2fzero_device, hwrng); struct u2f_hid_report req = { .report_type = 0, .msg.cid = CID_BROADCAST, .msg.init = { .cmd = U2F_CUSTOM_GET_RNG, .bcnth = 0, .bcntl = 0, .data = {0}, } }; struct u2f_hid_msg resp; int ret; size_t actual_length; if (!dev->present) { hid_dbg(dev->hdev, "device not present"); return 0; } ret = u2fzero_recv(dev, &req, &resp); if (ret < 0) return 0; /* only take the minimum amount of data it is safe to take */ actual_length = min3((size_t)ret - offsetof(struct u2f_hid_msg, init.data), U2F_HID_MSG_LEN(resp), max); memcpy(data, resp.init.data, actual_length); return actual_length; }