Bug 98770

Summary: kernel: Elantech 3320KD-3100 Touchpad behind [ASUS T300CHI DOCKING] Bluetooth not recognised
Product: Wayland Reporter: Tj <0.freedesktop>
Component: libinputAssignee: Wayland bug list <wayland-bugs>
Status: RESOLVED NOTOURBUG QA Contact:
Severity: normal    
Priority: medium CC: benjamin.tissoires, coffeebush, er453r, peter.hutterer, vitek.vlasenko
Version: 1.2.x   
Hardware: All   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: xinput --list-props
/proc/bus/input/devices
evtest
xev
xmodmap -pp
dmesg v4.9rc4 T300CHI
hid-recorder log
hid-asus-fte patch to recognise Bluetooth Touchpad
hid-recorder log using asus-fte (multitouch events detected!)
wireshark logs of bluetooth communication with and without the ASUS driver
4.15 ketnel pinch interaction

Description Tj 2016-11-18 20:50:24 UTC
Created attachment 128059 [details]
xinput --list-props

This may affect other systems where manufacturers present a device ID different to the underlying chipset.

In this case an Asus Transformer Book T300 CHI [0] Intel-based 2-in-1 (Tablet/Notebook) with a Bluetooth-connected docking keyboard/touchpad.

The touchpad is only recognised as a basic mouse device. It is actually an ElanTech SmartPad [1] that supports scroll regions and multi-touch.

The docking unit only provides a Bluetooth link (it has a micro-USB charging port only).

It presents as "ASUS T300CHI DOCKING" with keyboard and mouse.

I opened the keyboard dock and found the actual chipset is the Elantech 3320KD-3100.

The installed OS is Kubuntu 16.04 with the latest Linux mainline kernel (currently using 4.9rc4) and Debian/Ubuntu libinput10 (libinput-1.2.3-1ubutu1).

I've taken a brief look at the libinput source code and wonder if a udev hwdb quirk to recognise this as an Elantech device might be all that is needed?

There is also a separate Synaptics Touchscreen on the tablet (which has the same problem that will be addressed in a separate bug report).

In the attached logs from evtest and xev I tested the left and right buttons, moving right/left and up/down, border-scrolling and then at the end multi-finger gestures (none of which resulted in data).

49503.162379] input: ASUS T300CHI DOCKING as /devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4:1.0/bluetooth/hci0/hci0:256/0005:0B05:8502.004D/input/input68
[49503.162731] hid-generic 0005:0B05:8502.004D: input,hidraw0: BLUETOOTH HID v0.01 Keyboard [ASUS T300CHI DOCKING] on 34:02:86:fc:ad:59

$ xinput --list
⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ ASUS T300CHI DOCKING                      id=11   [slave  pointer  (2)]
⎜   ↳ SYNAPTICS Synaptics Touch Digitizer V04   id=13   [slave  pointer  (2)]
⎜   ↳ SYNAPTICS Synaptics Touch Digitizer V04 Pen       id=14   [slave  pointer  (2)]
⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Power Button                              id=6    [slave  keyboard (3)]
    ↳ Asus Wireless Radio Control               id=7    [slave  keyboard (3)]
    ↳ Video Bus                                 id=8    [slave  keyboard (3)]
    ↳ Sleep Button                              id=9    [slave  keyboard (3)]
    ↳ USB2.0 HD UVC WebCam                      id=12   [slave  keyboard (3)]
    ↳ Asus WMI hotkeys                          id=15   [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=16   [slave  keyboard (3)]
    ↳ ASUS T300CHI DOCKING                      id=17   [slave  keyboard (3)]

[0] https://www.asus.com/2-in-1-PCs/ASUS_Transformer_Book_T300_Chi/
[1] http://www.emc.com.tw/eng/tpn_sp_fun.asp
Comment 1 Tj 2016-11-18 20:51:06 UTC
Created attachment 128060 [details]
/proc/bus/input/devices
Comment 2 Tj 2016-11-18 20:52:02 UTC
Created attachment 128061 [details]
evtest
Comment 3 Tj 2016-11-18 20:52:27 UTC
Created attachment 128062 [details]
xev
Comment 4 Tj 2016-11-18 20:53:03 UTC
Created attachment 128063 [details]
xmodmap -pp
Comment 5 Tj 2016-11-18 20:58:48 UTC
I previously reported a Linux kernel bug [0] " ELAN 3320KD-3100 'Smart-Pad' not supported (in Asus T300CHI) "

[0] https://bugzilla.kernel.org/show_bug.cgi?id=117601
Comment 6 Peter Hutterer 2016-11-20 00:00:01 UTC
(In reply to Tj from comment #0)
> I've taken a brief look at the libinput source code and wonder if a udev
> hwdb quirk to recognise this as an Elantech device might be all that is
> needed?

nope, the hwdb quirks are generally for userspace only. In this case the problem is that the kernel doesn't send the right sequence to initialize the touchpad and this isn't something we can fix in userspace. Until that's done, there isn't much we can do in libinput. The same would likely be true for the touchscreen too.

I'll leave this bug open for Benjamin if he wants to track it here but this is something that should be tracked in the kernel bugzilla.
Comment 7 Benjamin Tissoires 2016-11-21 08:52:12 UTC
Could you attach a full dmesg of 4.9-rcX?
Also, could you attach the full output of hid-recorder (http://bentiss.github.io/hid-replay-docs/) when touching the touchpad a little bit so I can have an idea of what is in the firmware?

I don't have big hopes on this bug because if there is nothing obvious in the hid-recorder log, that means the touchpad is using a proprietary mode under Windows. And we would need someone to reverse engineer it if this were the case.
Comment 8 Tj 2016-11-21 09:47:47 UTC
Created attachment 128095 [details]
dmesg v4.9rc4 T300CHI

Thanks for the response. Logs being attached now.

As for the reverse engineering I have started on that (done a lot of it in the last 10 years!) but I may need some guidance on the specifics of what to look for with regard to how input sub-systems work at the low level.

I'm currently annotating the ACPI DSDT in case there are some Device/Methods which might give some additional clues (as you'll notice acpi_osi= is used here and causes several devices to show up that don't with a default OSI).

I also have the Windows Asus/Elan Tech Touchpad driver installer package extracted and am looking at it (basically AsusHID.sys) - will have more time to do some decent IDA analysis with it later.

I'm guessing work needs to be done on the kernel driver side and have been getting familiar with the drivers/input/mouse/asus-* code in case some additions to the WMI device probes is where we need to start.
Comment 9 Tj 2016-11-21 09:48:19 UTC
Created attachment 128096 [details]
hid-recorder log
Comment 10 Benjamin Tissoires 2016-11-21 10:05:03 UTC
(In reply to Tj from comment #8)
> I'm currently annotating the ACPI DSDT in case there are some Device/Methods
> which might give some additional clues (as you'll notice acpi_osi= is used
> here and causes several devices to show up that don't with a default OSI).

The DSDT won't be of any help here. It's a bluetooth keyboard, so everything happens in the bluetooth and HID communication.

> 
> I also have the Windows Asus/Elan Tech Touchpad driver installer package
> extracted and am looking at it (basically AsusHID.sys) - will have more time
> to do some decent IDA analysis with it later.

No need to reverse engineer the source. You just need to dump the early traces of the bluetooth communication when the Windows driver starts talking to the device.

> 
> I'm guessing work needs to be done on the kernel driver side and have been
> getting familiar with the drivers/input/mouse/asus-* code in case some
> additions to the WMI device probes is where we need to start.

One thing that might be worth having a look at is if the current WIP driver for some Asus touchpads wouldn't work for you.
The WIP is https://github.com/vlasenko/hid-asus-fte-dkms and the similarities between your descriptor and this driver are big. The original kernel bug is https://bugzilla.kernel.org/show_bug.cgi?id=120181

However, we would need to enhance the driver a little bit or your keyboard will get disabled once the driver is started :)

So you might want to have a look first at their user space driver: https://github.com/redmcg/FTE1001
This might tell us if your touchpad is compatible and if you need to get involved in the development process of hid-asus.
Comment 11 Tj 2016-11-21 11:44:44 UTC
Thanks, Reverse engineering is required since there is no Windows installation on the PC (unless another user with a dual-boot comes along).

I'll play about with the FTE driver now.
Comment 12 Victor Vlasenko 2016-11-21 12:18:37 UTC
I believe we are working on the similar device here:
- kernel space driver
https://github.com/vlasenko/hid-asus-fte-dkms
- user space driver
https://github.com/redmcg/FTE1001
- magic packet searching
https://github.com/vlasenko/zenbook-touchpad-i2c
- protocol sniffing
https://github.com/ain101/drivers-input-touchscreen-FTS_driver/blob/master/doc/sniff/logic%20analyzer/win%20boot%20after%20grub%202.csv

Yeah, that's what we attempted first - to reverse engineer AsusHID.sys from Asus Smart Gesture drivers, without much success though. But then Frederik Wenigwieser has soldered logic analyzer and sniffed communication between Window driver and TouchPad device. Which has opened us the possibility to find "magic" packet used to switch TouchPad from Mouse-mode to MultiTouch mode:

static int asus_start_multitouch(struct hid_device *hdev) {
	unsigned char buf[] = { FEATURE_REPORT_ID, 0x00, 0x03, 0x01, 0x00 };
	int ret = hid_hw_raw_request(hdev, FEATURE_REPORT_ID, buf, sizeof(buf),
			HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
	if (ret != sizeof(buf)) {
		hid_err(hdev, "Failed to start multitouch: %d\n", ret);
		return ret;
	}

	return 0;
}

I wonder whether this packet works for your device to start sending multi-touch events. I guess the simplest way to find this out is to try Brendan McGrath userspace driver, with minor changes:
https://github.com/redmcg/FTE1001

Regards,
Victor

(In reply to Tj from comment #8)
> Created attachment 128095 [details]
> dmesg v4.9rc4 T300CHI
> 
> Thanks for the response. Logs being attached now.
> 
> As for the reverse engineering I have started on that (done a lot of it in
> the last 10 years!) but I may need some guidance on the specifics of what to
> look for with regard to how input sub-systems work at the low level.
> 
> I'm currently annotating the ACPI DSDT in case there are some Device/Methods
> which might give some additional clues (as you'll notice acpi_osi= is used
> here and causes several devices to show up that don't with a default OSI).
> 
> I also have the Windows Asus/Elan Tech Touchpad driver installer package
> extracted and am looking at it (basically AsusHID.sys) - will have more time
> to do some decent IDA analysis with it later.
> 
> I'm guessing work needs to be done on the kernel driver side and have been
> getting familiar with the drivers/input/mouse/asus-* code in case some
> additions to the WMI device probes is where we need to start.
Comment 13 Tj 2016-11-21 13:09:36 UTC
Created attachment 128103 [details] [review]
hid-asus-fte patch to recognise Bluetooth Touchpad

The attached patch at least allows hid-asus-fte to recognise the ASUS T300CHI DOCKING device although it fails to initialise it. I'm not surprised at that though as this is an 'ElanTech' device, not FocalTech.

It may be the ElanTech needs its own version of the driver.

[12214.139968] hid-asus-fte 0005:0B05:8502.0015: unknown main item tag 0x0
[12214.140048] input: Asus FTE TouchPad as /devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4:1.0/bluetooth/hci0/hci0:512/0005:0B05:8502.0015/input/input50
[12214.140536] hid-asus-fte 0005:0B05:8502.0015: input,hidraw0: BLUETOOTH HID v0.01 Keyboard [ASUS T300CHI DOCKING] on 34:02:86:fc:ad:59
Comment 14 Benjamin Tissoires 2016-11-21 13:19:09 UTC
(In reply to Tj from comment #13)
> Created attachment 128103 [details] [review] [review]
> hid-asus-fte patch to recognise Bluetooth Touchpad
> 
> The attached patch at least allows hid-asus-fte to recognise the ASUS
> T300CHI DOCKING device although it fails to initialise it. I'm not surprised
> at that though as this is an 'ElanTech' device, not FocalTech.

Thanks for testing it. The keyboard is expected to not be working because the current hid-asus-fte simply ignores everything but the multitouch touchpad reports.

Could you attach a hid-recorder output of the touch events once hid-asus-fte is in use? This way, we will be able to see if the device switches to multitouch or stick to single touch.

> 
> It may be the ElanTech needs its own version of the driver.
> 
> [12214.139968] hid-asus-fte 0005:0B05:8502.0015: unknown main item tag 0x0

That's expected for bluetooth devices.

> [12214.140048] input: Asus FTE TouchPad as
> /devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4:1.0/bluetooth/hci0/hci0:512/
> 0005:0B05:8502.0015/input/input50
> [12214.140536] hid-asus-fte 0005:0B05:8502.0015: input,hidraw0: BLUETOOTH
> HID v0.01 Keyboard [ASUS T300CHI DOCKING] on 34:02:86:fc:ad:59

Seems like the driver binds correctly.
Comment 15 Tj 2016-11-21 13:37:20 UTC
Created attachment 128104 [details]
hid-recorder log using asus-fte (multitouch events detected!)

Looks like something useful is happening because I believe I see multitouch events in the hid-recorder log.

The events correspond to:

Left button press and release
Right button press and release
Slide left and right (one finger)
Slide up and down (one finger)
Slide left and right (two fingers)
Slide up and down (two fingers)
Slide left and right (three fingers)
Slide up and down (three fingers)
Slide left and right (four fingers)
Slide up and down (four fingers)
Comment 16 Tj 2016-11-21 13:38:36 UTC
Forgot to mention I tried the FTE1001 userspace driver but didn't seem to get any response. Not sure what I was supposed to expect but ensured it was linked to the correct /dev/hidraw? node, etc.
Comment 17 Benjamin Tissoires 2016-11-21 13:55:54 UTC
Good news, you won't need to install Windows or try to reverse engineer the Windows blob. As you can see on the hid-recorder, the incoming reports are different from what they used to be. Which means, we successfully switch to the hid-multitouch reporting mode:

The reports used to be of size 5 on the report ID 0x06, and they are now of size 15 on the report ID 0x5D.

The current WIP also uses the report ID 0x5d, meaning that the chip in the other Asus is the same (or that Asus politely asked Elan to conform to their protocol).

The actual data differs a little bit, and this is why the driver is not working directly. Your device reports 15 bytes while the I2C one reports 28.
Also yours reports only 3 bytes per touch, while the I2C one reports 5: it reports pressure and does palm detection in addition to X and Y. Yours might report only X and Y.

It looks like Victor and the others are really reactive and I think I'll let them integrate your device in their code. Please raise an issue on https://github.com/vlasenko/hid-asus-fte-dkms, and attach the latest hid-recorder logs so they can find a way to integrate your device into their driver.

I'll keep around to give advice when they are needed.
Comment 18 Tj 2016-11-21 14:00:03 UTC
Thanks Benjamin.

I'm already hacking on the asus-fte driver to handle this Asus/ElanTech device in addition to the FTE. Once I have it working I'll raise an issue and send Victor a pull request.

Many thanks for your rapid and very helpful responses; it is such a pleasure after the frequent frustrations of dealing with closed-source and closed minds!
Comment 19 redmcg 2016-11-22 00:05:34 UTC
I found another driver already in the kernel tree which is using the report ID 0x5D
for multi-touch support. It is an ElanTech driver: drivers/input/mouse/elan_i2c_core.c

But the format of the 0x5D report in this driver is slightly different to the one we're using in the hid-asus-fte-dkms driver. However:
- the first byte of the report; and
- the first three bytes of information for each contact

appears to be the consistent across all three devices (defining just the x and y locations).

As Benjamin has pointed out - it looks like your driver supports 4 contacts and each contact uses just the first three bytes of information for each contact.
Comment 20 Tj 2016-11-22 01:20:19 UTC
I did look at the elan_i2c_core.c and related code earlier. It does seem to differ significantly from the Asus devices, and I noticed it has Asus-specific detection functions to apparently deal with differences in firmwares.

I've re-factored the asus-fte module with per-device data structures to contain all the values that were hard-coded. Tomorrow I shall tweak the Elan-specific values to try to get the OS responding to the input events properly.
Comment 21 MDarweash 2017-02-17 13:47:56 UTC
Anyhope ?

i've searched a lot regarding this problem :) 

i hope @TJ finds a way :)
Comment 22 Tj 2017-02-17 14:19:00 UTC
Unfortunately I've not had time to complete the modifications and additions since my last comment. I keep meaning to (it's a real pain not having the functionality). I'll try to put a block of time aside in the next month to focus on it and get my head back into the code.
Comment 23 MDarweash 2017-02-25 18:10:35 UTC
(In reply to Tj from comment #22)
> Unfortunately I've not had time to complete the modifications and additions
> since my last comment. I keep meaning to (it's a real pain not having the
> functionality). I'll try to put a block of time aside in the next month to
> focus on it and get my head back into the code.

Great... waiting for you to save our live :)
Comment 24 Luca 2017-07-22 15:29:54 UTC
Hi, any update? According to TJ's comment he was able to put the touchpad in multitouch status, but nothing happened after that and I haven't been able to reproduce his steps. Any way to contribute?
Comment 25 woodo 2017-07-30 01:21:27 UTC
I have similar issues about the Asus T300CHI touchpad with no scrolling functionality. I am usinf Ubuntu 16.04 and still have windows 10 installed. Anything I can help contribute to although my skills are basic?
Comment 26 er453r 2018-01-31 14:46:34 UTC
Created attachment 137089 [details]
wireshark logs of bluetooth communication with and without the ASUS driver
Comment 27 er453r 2018-01-31 14:48:14 UTC
I did some more digging, and confirmed that the Asus driver sends additional commands to the device on Windows to enable the multitouch capabilities.

I've also did a packet dump on windows of the device communications with the OS (without ASUS driver, with ASUS driver, and then testing gesture and mouse commands).

I can confirm that the driver indeed sends additional commands. I've tried sending them by hand to the device descriptor but it did not trigger the mutlitouch events :/

Attaching the bluetooth dump, maybe this will help someone.
Comment 28 er453r 2018-02-07 10:26:54 UTC
I can confirm that the touchpad multitouch works since the 4.15 kernel (installed from here http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.15/)! No blacklisting nesesery. Tested with Ubuntu 16.04.

For more advanced gestures you can additionally use this https://github.com/bulletmark/libinput-gestures (also tested, works)

Sadly, no fluid pinch-to-zoom gesture (only works as a button press simulation, but I don't think any linux touchpad has this)
Comment 29 Peter Hutterer 2018-02-07 22:43:13 UTC
(In reply to er453r from comment #28)
> Sadly, no fluid pinch-to-zoom gesture (only works as a button press
> simulation, but I don't think any linux touchpad has this)

It's available in the wayland stack but not Xorg. GNOME on Wayland + GTK apps should support pinch-to-zoom. And if you run libinput debug-events on the commandline you'll find that the pinch gestures should be detected - the libinput-gestures tool hooks on top of it after all.

That aside, can you please attach an evemu-record of a pinch interaction. Good to have for the archives here, thanks.
Comment 30 er453r 2018-02-08 20:47:12 UTC
Created attachment 137235 [details]
4.15 ketnel pinch interaction
Comment 31 er453r 2018-02-08 20:50:15 UTC
Added the log, most of it are pinching interactions.

And you where right, libinput debug-events indeed correctly show the gesture as pinch, only no xorg app supports it.

I've looked how is pinch-to-zoom handled from the screen digitizer (which works correctly in xorg apps - Chromimium for example) - but it only emits multiple touch events, which are probably then interpreted by the apps as pinching gesture.
Comment 32 woodo 2018-02-09 23:43:42 UTC
I upgraded distributions to 17.10. still only has basic touchpad functionality. However 17.10 works much better generally with t300chi.
Comment 33 Peter Hutterer 2018-03-06 04:35:49 UTC
Closing this bug, there isn't much we can do for the userspace, afaict from comment 31 at least the libinput bits work correctly.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.