1

I try to connect my Ubuntu 23.10 with an LG C2 TV to then output the sound from LG to Ubuntu; the same works fine with my iPhone which then plays some music through my Ubuntu attached speakers. I use bluetoothctl:

devices Paired
Device 20:28:BC:81:F8:D9 [LG] webOS TV OLED55C22LB
connect 20:28:BC:81:F8:D9
Attempting to connect to 20:28:BC:81:F8:D9
[CHG] Device 20:28:BC:81:F8:D9 Connected: yes
Connection successful
[CHG] Device 20:28:BC:81:F8:D9 ServicesResolved: yes

but then I can't see in the LG's "Bluetooth Device" menu my Ubuntu as a speaker.
What should I do to solve this?

Actually, for iPhone to output audio to Bluetooth, I had first to specify that the Bluetooth connection's target (i.e. computer) is a speaker.

PS: I use pipewire, pipewire-pulse and wireplumber which work fine

info 20:28:BC:81:F8:D9
Device 20:28:BC:81:F8:D9 (public)
        Name: LG TV[[LG] webOS TV OLED55C22LB
        Alias: LG TV[[LG] webOS TV OLED55C22LB
        Class: 0x0008243c (533564)
        Icon: audio-card
        Paired: yes
        Bonded: yes
        Trusted: yes
        Blocked: no
        Connected: yes
        LegacyPairing: no
        UUID: Audio Source              (0000110a-0000-1000-8000-00805f9b34fb)
        UUID: Audio Sink                (0000110b-0000-1000-8000-00805f9b34fb)
        UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
        UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
        UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
        UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
        UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
        UUID: LG Electronics            (0000feb9-0000-1000-8000-00805f9b34fb)
        Modalias: bluetooth:v0046p1200d1436
        ManufacturerData Key: 0x00c4 (196)
        ManufacturerData Value:
  02 34 15 13 17 fd 80                             .4.....
Adrian
  • 527
  • Have you tried https://askubuntu.com/q/1172000/1004020 ? What do you mean "from LG to Ubuntu"? – Daniel T Feb 20 '24 at 20:20
  • "output the sound from LG to Ubuntu" - I mean the LG TV should pass the audio to/toward the computer running Ubuntu (aka the TV-produced sound will pass through the computer and will play on the speakers attached to the computer).

    https://askubuntu.com/q/1172000/1004020 seems to solve another problem.

    – Adrian Feb 21 '24 at 12:30
  • 2
  • It seems an old solution whose details don't work completely on 23.10, i.e. pactl command finds no bluez source whilst the suggested alternative gdbus call fails; additionally I use pipewire but not pulseaudio. But the most important is the fact that many say they do nothing to have audio running over Bluetooth through Ubuntu - this is what I also experience but sadly, only with my iPhone. – Adrian Feb 21 '24 at 20:34
  • I'm on Kubuntu 23.10 and it works out-of-the-box. All I needed to do was enable discoverable on my Ubuntu, forget all devices on Ubuntu and Android, then initiate the pairing from Android to Ubuntu. I'm listening to the music working as I write this – Daniel T Feb 22 '24 at 02:13
  • I too use Kubuntu 23.10 and it works out-of-the-box but only with my phone but not with the TV. Are you listening music over bluetooth from a TV? – Adrian Feb 22 '24 at 23:29
  • I don't have a TV test. Have you tried disabling all other BlueZ profiles or enabling multi-profile? – Daniel T Feb 22 '24 at 23:37
  • 1
    Have you tried sudo hciconfig hci0 class 0x00240414 ? – Daniel T Feb 23 '24 at 06:40
  • UPDATE: actually, for iPhone to output audio to Bluetooth, I had first to specify that the Bluetooth connection's target (i.e. computer) is a speaker. I can't do this on TV because it doesn't even see the computer as a Bluetooth connection. – Adrian Feb 23 '24 at 14:31
  • I just tried sudo hciconfig hci0 class 0x00240414 and my TV is at least listing my PC allowing me to try connecting to it but the connection from the TV side fails while in bluetoothctl it shows [CHG] Device 20:28:BC:81:F8:D9 Connected: yes; but after a while (probably when the TV gives up), it shows [CHG] Device 20:28:BC:81:F8:D9 Connected: no again. – Adrian Feb 23 '24 at 16:52
  • @DanielT, it worked! I restarted the computer and tried again, this time while running bluetoothctl with the user I was logged directly in Ubuntu - I initially run it with another one connected through ssh. I noticed a notification window asking to allow LG to connect, I agreed and it worked. Many thanks! – Adrian Feb 23 '24 at 17:19
  • I tried to permanently change the Bluetooth class to Class = 0x240414 in /etc/bluetooth/main.conf using https://askubuntu.com/questions/439088/how-to-change-bluetooth-device-class but it didn't work completely (only the name, if set, is changed as specified) - the class changed to another than '0x240414' but also different than the initial, not working one - in the end, the Bluetooth connection still works despite the fact that the class is not exactly the one set. hciconfig -a | grep -i 'class' reports Device Class: Audio/Video, Loudspeaker. – Adrian Feb 23 '24 at 19:28
  • @DanielT, I invite you to write a post with the suggestion you made to accept your solution. – Adrian Feb 23 '24 at 19:31
  • I will write an answer once I finish debugging /etc/bluetooth/main.conf – Daniel T Feb 23 '24 at 19:59
  • Basically, the solution for me was setting the Bluetooth class you suggested. – Adrian Feb 25 '24 at 17:45
  • I just resorted to posting the hciconfig workaround and adding a sleep in ExecStartPre. It is taking way too much debugging to get /etc/bluetooth/main.conf to respect the service class 0x24 part, and perhaps that could be a later edit – Daniel T Feb 25 '24 at 22:36

1 Answers1

2

We can set the device class manually:

  1. Paste the following into /etc/systemd/system/bluetooth-class-askubuntu-1504191-1004020.service :

    [Unit]
    Description=Set Bluetooth device class to be a speaker
    After=bluetooth.service
    

    [Service]

    bluetooth.service reports ready before it sets the wrong class, so wait.

    ExecStartPre=/bin/sleep 5 ExecStart=/bin/hciconfig hci0 class 0x240414 Type=oneshot

    [Install] WantedBy=bluetooth.service

  2. sudo systemctl enable --now bluetooth-class-askubuntu-1504191-1004020.service

If we examine the new device class, we will see that it means its Service class is Rendering and Audio, its Major device class is Audio/Video, and its Minor service class is Loudspeaker. I extracted the numbers from my Logitech Bluetooth speaker, so this will your computer pretend to be the same.

The normal setting is 0x7C010C, which means its Service class is Rendering, Capturing, Object Transfer, Audio, and Telephony, its Major device class is Computer, and its Minor service class is Laptop. Your LG TV will skip devices of computer class and only show devices of class speaker:

In practice, most Bluetooth clients scan their surroundings in two successive steps: they first look for all bluetooth devices around them and find out their "class". You can do this on Linux with the hcitool scan command. Then, they use SDP in order to check if a device in a given class offers the type of service that they want.

This means that the hcid.conf "class" parameter needs to be set up properly if particular services are running on the host, such as "PAN", or "OBEX Obect Push", etc: in general a device looking for a service such as "Network Access Point" will only scan for this service on devices containing "Networking" in their major service class.

Setting Class = 0x240414 in /etc/bluetooth/main.conf doesn't work because it doesn't set all the bits. Devices vary in how much they care. Android doesn't care at all, and TVs might need some or all of the bits set properly. When I edited that file, only the major/minor part being 0x0414 got somewhat respected, and this is only after I disabled all the profiles (which also add their own bits to the class) in the bluetooth.service command line parameters. bluetoothd does not support setting the service class 0x24 as its struct mgmt_cp_set_dev_class doesn't include a variable for that.

Daniel T
  • 4,594