From nobody Sun Feb 05 15:33:33 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4P8thY46dNz3kRfV; Sun, 5 Feb 2023 15:33:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4P8thY31BZz44DK; Sun, 5 Feb 2023 15:33:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675611213; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Mmz5dMP6QJUkXU9JFBL2pw7S/HdrEycN/xElSr8dgLI=; b=WM4DfYYUpGLCXOG7YosloIvJSv0V+zg1XHtooMTlPo+vFPb2o+1MeYzs5aap878D/TNufs 8e6ZuAaRKbG729viuJhi6ZbQARxb7zQx/2eMj7TwVjyDdtaKSRLhCPMJKNXWJpaa7Qflwo uoa9EkpCazGO4zcqcI5bIxhMZ/bLJm9umU388C7RViiy1j19u4Jt7YVtYnmRYZdGTCi6xB bfMkkoFwWY4cSIKS4BmPOwy84GJixXS+TVh9avWL/c7IqOpG98to0deU1irs90yJ3PGXFB 6QL3cC5C+v+bIeYpOmVt477IIMknGaY/L7E08na21KeRQVBnWCkUNcVah3AKBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675611213; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Mmz5dMP6QJUkXU9JFBL2pw7S/HdrEycN/xElSr8dgLI=; b=CsDPiCp4b/duaoDrV0d1bLED5fnbSLYUqdPOSSnvX5MwxSmRQmWP0kf25LwNoaQgZtpNNT GIA7w18+ISQA5UpGSbbdzHhV+DPkb0aqVMSBQUFLI1s4/D7MTF/W6/E6BRSssG9D2ibWeI UKuMlPB8eZGqAeS/cmJOq4thqfqvtXj1BXFfxx1FambKbZI7egFCqqSc+qZ4+ZxJ/5djMe CDk0sGVNcptN5xniE2RIbnghkL+GNeCHa2AGgkEHjsCGxnXwY2hvCIyduTIVSK7bULzstV W4eqpHKMPC4RT+TYmb+nCNIq1nfB1xA7TuQhYdSHFfESQPFzQvenH7giTIX6yQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675611213; a=rsa-sha256; cv=none; b=FcfIF2FKDj6CHCJOTdkROALr1PnangH81vUdF5u/eXw7yjmRo5CdGJaGxwsPZiQFT6jD/3 7qxViqqsUO4WbTImsuJhtnAKuygNrdWnd3T2J1HzaOaaVgwOddGKJkOatgRV+fDT82pEyS j6lg1rFKdQgqJHT+LgSn4k1NP0/w0CrvoLZ7hYgywRZ8eJhMvcNqh9k0gAyqzgGB3HdV6X H2SODmUEvSrCaVo3cP/rXZfNZkVJJwqwMLwNZ3lkAWwuY/CPYJXqUagFq+a2JQMm1xfHAP 024zVEA95VHSd8tUwHL58hffyq6HFpLL5vZgBdiyYGr3AtVm7aBrHhhC/sx8Hg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4P8thY1QJVz10W7; Sun, 5 Feb 2023 15:33:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 315FXXJO095757; Sun, 5 Feb 2023 15:33:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 315FXXMl095756; Sun, 5 Feb 2023 15:33:33 GMT (envelope-from git) Date: Sun, 5 Feb 2023 15:33:33 GMT Message-Id: <202302051533.315FXXMl095756@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vladimir Kondratyev Subject: git: 8d5fef85f007 - main - ietp(4): Load dummy HID report descriptor if mangled List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8d5fef85f007c81d15ea6de825a4462b3829ea16 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=8d5fef85f007c81d15ea6de825a4462b3829ea16 commit 8d5fef85f007c81d15ea6de825a4462b3829ea16 Author: Aymeric Wibo AuthorDate: 2023-02-05 15:32:08 +0000 Commit: Vladimir Kondratyev CommitDate: 2023-02-05 15:32:08 +0000 ietp(4): Load dummy HID report descriptor if mangled Some Elantech trackpads have a mangled HID report descriptor, which reads as having an incorrect input size (i.e. < IETP_REPORT_LEN_LO). If the input size is incorrect, load a dummy report descriptor. Reviewed by: wulf MFC after: 1 week Differential revision: https://reviews.freebsd.org/D38387 --- sys/dev/hid/ietp.c | 91 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 69 insertions(+), 22 deletions(-) diff --git a/sys/dev/hid/ietp.c b/sys/dev/hid/ietp.c index 6d0570c88e30..3381f76da630 100644 --- a/sys/dev/hid/ietp.c +++ b/sys/dev/hid/ietp.c @@ -118,7 +118,7 @@ struct ietp_softc { uint16_t trace_y; uint16_t res_x; /* dots per mm */ uint16_t res_y; - bool hi_precission; + bool hi_precision; bool is_clickpad; bool has_3buttons; }; @@ -132,9 +132,10 @@ static int ietp_attach(struct ietp_softc *); static int ietp_detach(struct ietp_softc *); static int32_t ietp_res2dpmm(uint8_t, bool); -static device_probe_t ietp_iic_probe; -static device_attach_t ietp_iic_attach; -static device_detach_t ietp_iic_detach; +static device_identify_t ietp_iic_identify; +static device_probe_t ietp_iic_probe; +static device_attach_t ietp_iic_attach; +static device_detach_t ietp_iic_detach; static device_resume_t ietp_iic_resume; static int ietp_iic_read_reg(device_t, uint16_t, size_t, void *); @@ -200,6 +201,17 @@ static const struct hid_device_id ietp_iic_devs[] = { IETP_IIC_DEV("ELAN1000"), }; +static uint8_t const ietp_dummy_rdesc[] = { + 0x05, HUP_GENERIC_DESKTOP, /* Usage Page (Generic Desktop Ctrls) */ + 0x09, HUG_MOUSE, /* Usage (Mouse) */ + 0xA1, 0x01, /* Collection (Application) */ + 0x09, 0x01, /* Usage (0x01) */ + 0x95, IETP_REPORT_LEN_LO, /* Report Count (IETP_REPORT_LEN_LO) */ + 0x75, 0x08, /* Report Size (8) */ + 0x81, 0x02, /* Input (Data,Var,Abs) */ + 0xC0, /* End Collection */ +}; + static const struct evdev_methods ietp_evdev_methods = { .ev_open = &ietp_ev_open, .ev_close = &ietp_ev_close, @@ -241,9 +253,9 @@ ietp_attach(struct ietp_softc *sc) int32_t minor, major; int error; - sc->report_id = sc->hi_precission ? + sc->report_id = sc->hi_precision ? IETP_REPORT_ID_HI : IETP_REPORT_ID_LO; - sc->report_len = sc->hi_precission ? + sc->report_len = sc->hi_precision ? IETP_REPORT_LEN_HI : IETP_REPORT_LEN_LO; /* Try to detect 3-rd button by relative mouse TLC */ @@ -334,15 +346,31 @@ ietp_intr(void *context, void *buf, hid_size_t len) int32_t x, y, w, h, wh; /* we seem to get 0 length reports sometimes, ignore them */ + if (len == 0) + return; + if (len != sc->report_len) { + DPRINTF("wrong report length (%d vs %d expected)", len, sc->report_len); + return; + } + report = buf; - if (*report != sc->report_id || len < sc->report_len) + if (*report != sc->report_id) return; + evdev_push_key(sc->evdev, BTN_LEFT, + report[IETP_TOUCH_INFO] & IETP_TOUCH_LMB); + evdev_push_key(sc->evdev, BTN_MIDDLE, + report[IETP_TOUCH_INFO] & IETP_TOUCH_MMB); + evdev_push_key(sc->evdev, BTN_RIGHT, + report[IETP_TOUCH_INFO] & IETP_TOUCH_RMB); + evdev_push_abs(sc->evdev, ABS_DISTANCE, + (report[IETP_HOVER_INFO] & 0x40) >> 6); + for (finger = 0, fdata = report + IETP_FINGER_DATA; finger < IETP_MAX_FINGERS; finger++, fdata += IETP_FINGER_DATA_LEN) { if ((report[IETP_TOUCH_INFO] & (1 << (finger + 3))) != 0) { - if (sc->hi_precission) { + if (sc->hi_precision) { x = fdata[0] << 8 | fdata[1]; y = fdata[2] << 8 | fdata[3]; wh = report[IETP_WH_DATA + finger]; @@ -379,28 +407,46 @@ ietp_intr(void *context, void *buf, hid_size_t len) } } - evdev_push_key(sc->evdev, BTN_LEFT, - report[IETP_TOUCH_INFO] & IETP_TOUCH_LMB); - evdev_push_key(sc->evdev, BTN_MIDDLE, - report[IETP_TOUCH_INFO] & IETP_TOUCH_MMB); - evdev_push_key(sc->evdev, BTN_RIGHT, - report[IETP_TOUCH_INFO] & IETP_TOUCH_RMB); - evdev_push_abs(sc->evdev, ABS_DISTANCE, - (report[IETP_HOVER_INFO] & 0x40) >> 6); - evdev_sync(sc->evdev); } static int32_t -ietp_res2dpmm(uint8_t res, bool hi_precission) +ietp_res2dpmm(uint8_t res, bool hi_precision) { int32_t dpi; - dpi = hi_precission ? 300 + res * 100 : 790 + res * 10; + dpi = hi_precision ? 300 + res * 100 : 790 + res * 10; return (dpi * 10 /254); } +static void +ietp_iic_identify(driver_t *driver, device_t parent) +{ + void *d_ptr; + hid_size_t d_len; + int isize; + uint8_t iid; + + if (HIDBUS_LOOKUP_ID(parent, ietp_iic_devs) == NULL) + return; + if (hid_get_report_descr(parent, &d_ptr, &d_len) != 0) + return; + + /* + * Some Elantech trackpads have a mangled HID report descriptor, which + * reads as having an incorrect input size (i.e. < IETP_REPORT_LEN_LO). + * If the input size is incorrect, load a dummy report descriptor. + */ + + isize = hid_report_size_max(d_ptr, d_len, hid_input, &iid); + if (isize >= IETP_REPORT_LEN_LO) + return; + + hid_set_report_descr(parent, ietp_dummy_rdesc, + sizeof(ietp_dummy_rdesc)); +} + static int ietp_iic_probe(device_t dev) { @@ -442,7 +488,7 @@ ietp_iic_attach(device_t dev) return (EIO); } pattern = buf == 0xFFFF ? 0 : buf8[1]; - sc->hi_precission = pattern >= 0x02; + sc->hi_precision = pattern >= 0x02; reg = pattern >= 0x01 ? IETP_IC_TYPE : IETP_OSM_VERSION; if (ietp_iic_read_reg(dev, reg, sizeof(buf), &buf) != 0) { @@ -492,8 +538,8 @@ ietp_iic_attach(device_t dev) return (EIO); } /* Conversion from internal format to dot per mm */ - sc->res_x = ietp_res2dpmm(buf8[0], sc->hi_precission); - sc->res_y = ietp_res2dpmm(buf8[1], sc->hi_precission); + sc->res_x = ietp_res2dpmm(buf8[0], sc->hi_precision); + sc->res_y = ietp_res2dpmm(buf8[1], sc->hi_precision); return (ietp_attach(sc)); } @@ -610,6 +656,7 @@ ietp_iic_write_reg(device_t dev, uint16_t reg, uint16_t val) } static device_method_t ietp_methods[] = { + DEVMETHOD(device_identify, ietp_iic_identify), DEVMETHOD(device_probe, ietp_iic_probe), DEVMETHOD(device_attach, ietp_iic_attach), DEVMETHOD(device_detach, ietp_iic_detach),