Skip to content

Linux, Guides, Productivity

Setting up Airpods Pro on Ubuntu 20.04

Posted on:February 27, 2021 at 04:20 PM
 at 3 min read

If you have apple airpods or airpods pro, and sometimes want to use it with your Ubuntu machines, follow this guide! If you try to pair airpods without doing any of these steps, most likely the pairing process will never complete.

This is a compilation of ideas from few askubuntu posts.1 2

To enable pairing of airpods, you will need to update the ControllerMode to bredr from the default value of dual. This can be done by editing the file /etc/bluetooth/main.conf. Then restart the Bluetooth service using sudo /etc/init.d/bluetooth restart command.

You should be able to pair your airpods now and use it as headphones!

Enabling Airpods as MicrophoneSection titled Enabling Airpods as Microphone

In order to have airpods work as microphones, you will need to enable HSP/HFP profile. However, Pulseaudio by default only supports HSP. In order to make HSP/HFP work, you have to enable HFP on pulseaudio which needs ofono. Here are steps to enable HFP on pulseaudio using ofono on Ubuntu 20.04.

  1. Install ofono using: sudo apt install ofono

  2. Configure pulseaudio to use ofono:

    Goto /etc/pulse/default.pa, find the line load-module module-bluetooth-discover and change it to load-module module-bluetooth-discover headset=ofono.

    Add the user pulse to group bluetooth to grant the permission: sudo usermod -aG bluetooth pulse

    VERY IMPORTANT: To grant the permission, add the following code snippets to /etc/dbus-1/system.d/ofono.conf (before </busconfig>):

    <policy user="pulse">
    <allow send_destination="org.ofono"/>
    </policy>
    Copied
  3. In order to make ofono work, you have to provide a modem to it! You can install a modem emulator called phonesim (implemented by ofono) to make it work:

    install ofono-phonesim:

    sudo add-apt-repository ppa:smoser/bluetooth
    sudo apt-get update
    sudo apt-get install ofono-phonesim
    Copied

    Configure phonesim by adding the following lines to /etc/ofono/phonesim.conf:

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

    Now, restart ofono service as:

    sudo systemctl restart ofono.service
    Copied

    Now you will need to define and enable few services to start the ofono-phonesim as service.

    To run ofono-phonesim -p 12345 /usr/share/phonesim/default.xml on startup as a systemd unit, create the file /etc/systemd/system/ofono-phonesim.service(as root) with the following contents:

    [Unit]
    Description=Run ofono-phonesim in the background
    
    [Service]
    
    ExecStart=ofono-phonesim -p 12345 /usr/share/phonesim/default.xml
    Type=simple
    RemainAfterExit=yes
    
    [Install]
    
    WantedBy=multi-user.target
    Copied

    After ofono-phonesim runs, you’ll need to also enable and put the phonesim modem online.

    You will first need to use this githup repo:

    As pointed in comments below, you might need a particular git commit for it to work the way it worked for me. The particular commit that I used the commit b3682c6bab99cbe301fa9bf4a2416c3f730d8bfd from the repo.

    cd /tmp
    git clone git://git.kernel.org/pub/scm/network/ofono/ofono.git
    git checkout 	b3682c6bab99cbe301fa9bf4a2416c3f730d8bfd
    sudo mv ofono /opt/
    Copied

    Now you can enable and make phonesim modem online by creating another systemd unit file that depends on the above ofono-phonesim systemd unit. Put the following contents in /etc/systemd/system/phonesim-enable-modem.service:

    [Unit]
    Description=Enable and online phonesim modem
    Requires=ofono-phonesim.service
    
    [Service]
    
    ExecStart=/opt/ofono/test/enable-modem /phonesim
    ExecStart=/opt/ofono/test/online-modem /phonesim
    Type=oneshot
    RemainAfterExit=yes
    
    [Install]
    
    WantedBy=multi-user.target
    Copied

    Then run the following commands to run both daemons:

    sudo systemctl daemon-reload
    sudo systemctl enable ofono-phonesim.service
    sudo systemctl enable phonesim-enable-modem.service
    sudo service phonesim-enable-modem start
    Copied

    Check if the service is running with

    sudo service phonesim-enable-modem status
    Copied

Finally, restart pulseaudio with pulseaudio -k.

Now you should be able to switch to HSP/HFP profile for airpods and use it as an input device / microphones.

ReferencesSection titled References

FootnotesSection titled Footnotes

  1. Bluetooth Mode

  2. Ofono Instructions

COMMENTS


RELATED POSTS | Linux, Guides, Productivity