Using Bluetooth Headset on Ubuntu

I switched to Linux on my main machine about two years ago and use the Ubuntu LTS (currently 20.04) version for my everyday work. In time of pandemic, the remote communication became vital, so I wanted to use my BT headset (Teufel Airy, Apple Airpods) for conferencing.

Apparently, the current version of PulseAudio has an open issue with using the headset not only in A2DP profile (that is headphone mode, mic disabled) but in the HSP/HFP profile (lower quality of the headphones, but enabled microphone).

You have to ask the correct question on Google to find a hint, how to build a workaround which can be found on askubuntu.com. I refer to this description as a primary guide and sum up the parts you need to perform here, giving additional hints how to improve this. Special thanks go to Lukas Taake helping me with the automation part.

Overview of steps to get it working

In order to get the headset working in a hands-free mode you will need to:

  • install ofono
  • configure PulseAudio
  • install and configure ofono-phonesim
  • configure services autostarts (my addition to the guide referenced above)

Install Ofono

To install ofono, just run on your console:

sudo apt install ofono

Configure PulseAudio

In /etc/pulse/default.pa find the place where module-bluetooth-discover is loaded and change it to

.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover headset=ofono
.endif

Add the user pulse to group bluetooth by executing:

sudo usermod -aG bluetooth pulse

Grant permission for PulseAudio to use ofono by editing the file /etc/dbus-1/system.d/ofono.conf and add the following block as the last policy:

<policy user="pulse">
<allow send_destination="org.ofono"/>
</policy>

Install and configure ofono-phonesim

Ofono requires a modem to work properly. For doing so, let install the ofono-phonesim by executing:

sudo apt install ofono-phonesim

To create a virtual modem, create a new file /etc/ofono/phonesim.conf with the following content:

[phonesim]
Driver=phonesim
Address=127.0.0.1
Port=12345

Feel free to pick a different port, if you can’t use the port 12345.

Manual mode

Now your system setup is completed for a manual usage. To use it you need to start ofono-phonesim and then restart the Bluetooth stack. To do so:

ofono-phonesim -p 12345 /usr/share/phonesim/default.xml &
sudo service ofono restart
/usr/share/ofono/scripts/enable-modem /phonesim
sudo service bluetooth restart

As a test, you can run /usr/share/ofono/scripts/list-modems and should see the phonesim modem initialized.

Now, open your Bluetooth settings (I use blueman but the Ubuntu built-in does it as well) connect your Bluetooth device and switch it to HSP/HFP Profile.

Automating setup

If your manual mode works, you are almost done. It is boring to execute the steps above every time, so I decided to tune my system startup since I need this feature every day.

Let’s start with phonesim. Create a systemd unit file /etc/systemd/system/phonesim.service with the following content. This will start phonesim on start of the system.

[Unit]
Description = Phonesim Control Daemon
After = network.target network-online.target dbus.service
Wants = network-online.target
Requires = dbus.service

[Service]
Type = simple
ExecStart = /usr/bin/ofono-phonesim -p 12345 /usr/share/phonesim/default.xml
Restart = on-abort
StartLimitInterval = 60
StartLimitBurst = 10

[Install]
WantedBy = multi-user.target

If you changed the port in your modem definition, please change it accordingly. Please make sure, the line ExecStart is joined (displayed badly above).

The next service is ofono. We need to tell systemd that ofono.service should depend on phonesim.service. To do so I copied the original unit definition to /etc/systemd/system/ofono.service and modified the content to:

[Unit]
Description=Telephony service
After = phonesim.service
Requires = phonesim.service


[Service]
Type=dbus
BusName=org.ofono
ExecStart=/usr/sbin/ofonod -n
StandardError=null

[Install]
WantedBy=multi-user.target

The last step is to enable the phonesim modem. To do so, create a new unit file /etc/systemd/system/ofono-enable-modem.service with the following content:

[Unit]
Description=Enables Phonesim Modem
After = ofono.service
Requires = ofono.service


[Service]
Type=oneshot
ExecStart=/usr/share/ofono/scripts/enable-modem /phonesim

[Install]
WantedBy=multi-user.target

This service will be run just after the ofono.service and enable our modem on boot.

Now, we need to make sure the provided services are activated on boot. Please reload your systemd and enable them by running:

sudo systemctl daemon-reload
sudo systemctl enable phonesim
sudo systemctl enable ofono
sudo systemctl enable ofono-modem

That’s it. Now reboot and check if the modem is connected directly after the boot by running /usr/share/ofono/scripts/list-modems. You should see something like this:

[/phonesim ]
Online = 0
Powered = 1
Lockdown = 0
Emergency = 0
Manufacturer = MeeGo
Model = Synthetic Device
Revision = REV1
Serial = 1234567890
Interfaces = org.ofono.SmartMessaging org.ofono.PushNotification org.ofono.MessageManager org.ofono.Phonebook org.ofono.TextTelephony org.ofono.RadioSettings org.ofono.CallForwarding org.ofono.SimToolkit org.ofono.SimAuthentication org.ofono.AllowedAccessPoints org.ofono.VoiceCallManager org.ofono.SimManager
Features = sms tty rat stk sim
Type = hardware
...

Happy conferencing…

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Simon Zambrovski

Simon Zambrovski

Senior IT-Consultant, BPM-Craftsman, Architect, Developer, Scrum Master, Writer, Coach