Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IDEA] Bluetooth HID manager #20

Open
1 of 2 tasks
mariotaku opened this issue Dec 26, 2021 · 20 comments
Open
1 of 2 tasks

[IDEA] Bluetooth HID manager #20

mariotaku opened this issue Dec 26, 2021 · 20 comments
Labels
idea App idea

Comments

@mariotaku
Copy link
Member

Please read conditions below carefully, and don't delete this part. Invalid issues will be closed.

  • No apps related to piracy or intellectual property infringement is allowed.
  • We can't guarantee if the app will be developed by anyone.
  • We encourage you to develop the app by yourself. This would be a great contribution to webOS homebrew community.
  • I understand conditions above
  • (Optional) I'd like to develop this app by myself

Issue content starts below this line


webOS has com.webos.service.bluetooth2 service that seems to have capability to pair & connect to HID devices, down to webOS 4. While they only provide pairing to their official keyboards, and only supports game controllers on webOS 6, we can consider to utilize such API to pair & connect in older OS versions.

@mariotaku mariotaku added the idea App idea label Dec 26, 2021
@Informatic
Copy link
Member

Informatic commented Dec 26, 2021

Two cents after looking at com.webos.service.bluetooth on webOS 3.x / K3LP (I think bluetooth-related feature support may be bluetooth chipset/otaid-related...):

  • Seems like it has some support for PS4 controllers - I do not have one to test on, nor do I have any Bluetooth Classic game controllers to try hacking on it. (BLE controller are not supported)
  • Bluetooth keyboards support is a little weird - they check for device name (understandable), but also that keyboard (and bluetooth software as well) does not support (pin-based) pairing.

Here's a quick ezinject payload I used to persuade btmngr to pair with non-LG keyboard (defaulting to pin 0000) - seems like it managed to pair and connect, but no key events were forwarded to the system. Not sure if it was the issue of my crappy keyboard I had laying around, or some actual bug. Leaving for anyone willing to take it up.
https://gist.github.com/Informatic/bec4c216188149ee16bf17cddfebe297 (← unless you are interested in low-level binary reverse engineering that is probably not for you)

@Dystopian
Copy link

webOS 5 successfully works with bluetooth gamepads (I tested EXEQ and Gamesir T4 Pro) - at least they works in RetroArch.

Bluetooth mouse connects successfully but doesn't control cursor until I connect/disconnect USB mouse/keyboard. Then it works quite good until BT mouse goes sleep mode after being inactive some time. Anyway USB mouse/keyboard connecting/disconnecting revives BT mouse. Looks like there should be some udev configs/scripts for it.

Bluetooth keyboard with dynamic PIN code doesn't even pair in my tests, it just ends with The operation failed for an unspecified or generic reason error.

@Informatic
Copy link
Member

PS4 controller pairs correctly, shows up in /proc/bus/input/devices but does not emit any events on /dev/input/ devices...

luna-send -i 'luna://com.webos.service.bluetooth/service/enable' '{"service":"hid_sony"}'
luna-send -i 'luna://com.webos.service.bluetooth/gap/findDevices' '{"deviceClass":5,"seconds":10,"subscribe":true}'
luna-send -i 'luna://com.webos.service.bluetooth/service/connect' '{"service":"hid","address":"f4:93:9f:XX:XX:XX","subscribe":true}'

@Informatic
Copy link
Member

Informatic commented Jan 7, 2022

Huh, after a reboot just connect seemed to work correctly. Events don't arrive in retroarch or moonlight tv (not sure if it supports controller in the UI) but /dev/input/js3 definitely returns some events when cat'ed.

Tested with a quick input parser I made some time ago, seems to correctly report axes and buttons:
https://gist.github.com/6457773a20a14a5ba6f47d3d2351c991

@stephank
Copy link

stephank commented Jan 16, 2022

@Informatic Your steps worked for me, also on webOS 3, and a similar issue where events didn't arrive on initial pairing. I then turned off my dualshock 4 (holding the PS button 10 seconds), then back on, and events started arriving on /dev/input/event6. (Did not have to connect again or pair a second time.)

Retroarch is also picking these up correctly for me (with sdl2), not sure why that's not working for you.

How did you discover the payload format of the bluetooth service methods? (This may be obvious, but I'm new to webOS. Could only find ls-monitor so far.)

EDIT: Just now noticed that ls-monitor without args literally monitors the bus and captures all method calls including payloads. I was only ever doing -l or -i with it, derp.

@Informatic
Copy link
Member

I sat down in ghidra and started looking at the bluetooth daemon. (/usr/sbin/btmngr) Also simultaneously looked through settings app (/usr/palm/applications/com.palm.app.settings) which uses parts of these endpoints for bluetooth audio devices.

I've documented all the relevant com.webos.service.bluetooth endoints here, if anyone wanted to implement this: https://www.webosbrew.org/pages/luna-service-comwebosservicebluetooth.html

The initial pairing quirk could be alleviated by just sending a disconnect call + asking a user to connect the device back again.

I am still experiencing some weird RetroArch controller numbering issues. No idea.

@czak
Copy link

czak commented Jan 20, 2022

Just an FYI from me:
I was also able to pair a DS4 using the luna-send commands (thanks!!).
The controller now connect to the TV automatically.
RetroArch works correctly with the controller for me.
Using the input-dump.py, the DS4 events show up at /dev/input/event6.

This is shaping up to be a very promising platform :)
Thanks for all your work!

@Informatic
Copy link
Member

Which webOS TV Version are you on?

The most accurate version info you can get is via this command:

grep -h -E '"(hardware_id|core_os_release|product_id|webos_manufacturing_version|board_type)"' /var/run/nyx/*

@czak
Copy link

czak commented Jan 20, 2022

Which webOS TV Version are you on?

    "board_type": "M16P_DVB",
    "hardware_id": "HE_DTV_W17H_AFADABAA",
    "product_id": "OLED55B7V-Z",
    "core_os_release": "3.9.0-62709",
    "webos_manufacturing_version": "06.00.25",

One thought regarding DS4 problems:
I had two separate DS4s misbehave in various ways (e.g. they would work on PS4 but not on PSTV, or they worked on Linux but only via USB). I eventually concluded they were fakes. I finally bought one from a proper shop, in a proper Sony box and now it works with everything and everywhere and pairs like crazy.
It might not apply to you, but if you have even 1% suspicion, I'd suggest trying a different one.

(And to clarify - the "suspected fakes" were bought from legitimate local sellers online. Physically impossible to tell the difference IMO.)

@Dystopian
Copy link

Dystopian commented Jan 20, 2022

webOS 5 commands to connect BT controllers:

  1. start discovery luna-send -n 1 -f luna://com.webos.service.bluetooth2/adapter/startDiscovery '{ }'
  2. activate sync on gamepad
  3. view discovered devices luna-send -i -f luna://com.webos.service.bluetooth2/device/getStatus '{}', find your gamepad and its MAC-address (like "address": "00:13:87:65:ce:12",)
  4. pair with gamepad luna-send -i -f luna://com.webos.service.bluetooth2/adapter/pair '{ "address": "00:13:87:65:ce:12", "subscribe":true }'. Repeat until "returnValue": true
  5. connect to gamepad luna-send -i -f luna://com.webos.service.bluetooth2/hid/connect '{"address":"00:13:87:65:ce:12"}'

@sachinpatl
Copy link

Can we prioritise this by funding few bucks, I'm dying to connect my controller to my TV.

@sachinpatl
Copy link

webOS 5 commands to connect BT controllers:

  1. start discovery luna-send -n 1 -f luna://com.webos.service.bluetooth2/adapter/startDiscovery '{ }'
  2. activate sync on gamepad
  3. view discovered devices luna-send -i -f luna://com.webos.service.bluetooth2/device/getStatus '{}', find your gamepad and its MAC-address (like "address": "00:13:87:65:ce:12",)
  4. pair with gamepad luna-send -i -f luna://com.webos.service.bluetooth2/adapter/pair '{ "address": "00:13:87:65:ce:12", "subscribe":true }'. Repeat until "returnValue": true
  5. connect to gamepad luna-send -i -f luna://com.webos.service.bluetooth2/hid/connect '{"address":"00:13:87:65:ce:12"}'

Can we send this over webos device manager?

@Informatic
Copy link
Member

If by Device Manager you mean - https://github.com/webosbrew/dev-manager-desktop then yes - just open the "Terminal" tab and enter the commands there.

@sachinpatl
Copy link

If by Device Manager you mean - https://github.com/webosbrew/dev-manager-desktop then yes - just open the "Terminal" tab and enter the commands there.

Sadly I'm getting permission denied error when trying to run commands on terminal. Looks like only permissions I have is to basic ls, cd, cat etc commands.

This could be a bad place to ask the question but you guys can redirect me to some thread or documentation page using which I can get the permissions sorted.

I am new to the webos community and don't even know where to look for the content, google is not so helpful with webos queries.

@Informatic
Copy link
Member

If you are not rooted you can try replacing luna-send with luna-send-pub in these commands and check if it works.

@sachinpatl
Copy link

My controller is going out of pairing mode, can someone tell me how vi editor works or how can I use device manager to upload a script. I am trying to put this in a shell script.

@manny8975
Copy link

Managed to connect a PS4 controller using the above (pub version) commands provided by @Dystopian to use the game streaming client moonlight, thanks! I do have an issue where if the TV is powered off or put into standby and then started back up, the controller connects to the TV again but input is not registered. Each power cylce I have to unpair, re-pair and reconnect.
Anyone have any idea why this could be? I've tried a couple of things:
Put the controller into pairing mode and then send connect command from the TV (after a power cycle) - input not registered but controller connects.
After successful connect and input registers on moonlight, turned the controller off (hold PS button for ~10s) and then press once so it automatically reconnects - works as expected.

TV information:
"board_type": "K6LP_DVB",
"hardware_id": "HE_DTV_W20P_AFADABAA",
"product_id": "65NANO796NE",
"core_os_release": "5.3.1-29",
"webos_manufacturing_version": "04.30.90",

@Superd22
Copy link

Superd22 commented Aug 6, 2022

Just to avoid inadvertently stepping on anyone's toes:
I have started working on a GUI for this at https://github.com/Superd22/webos-gamepad.

(the repo's called gamepad because it was my main focus before finding this issue, but I do intend on supporting connecting to any Bluetooth devices)

@sachinpatl
Copy link

Just to avoid inadvertently stepping on anyone's toes: I have started working on a GUI for this at https://github.com/Superd22/webos-gamepad.

(the repo's called gamepad because it was my main focus before finding this issue, but I do intend on supporting connecting to any Bluetooth devices)

That's such a good news to here man. Thankyou so much for this.

@mariotaku
Copy link
Member Author

Just to avoid inadvertently stepping on anyone's toes:
I have started working on a GUI for this at https://github.com/Superd22/webos-gamepad.

(the repo's called gamepad because it was my main focus before finding this issue, but I do intend on supporting connecting to any Bluetooth devices)

This is beyond awesome. Please let me know when you're ready to publish it to apps repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea App idea
Projects
None yet
Development

No branches or pull requests

8 participants