Getting Apple Airpods working on Debian 11

Posted on

Lately, I completed an arc from Pop!_OS, back to Debian, over to Arch, over to Manjaro, and finally settling back down onto Debian 11.3. The move from Manjaro to Debian 11 has been a bit more painful than I’d have liked because Manjaro let’s me run bleeding edge kernels, drivers, and system tools. Debian is a bit more stable though. Honestly, the only thing I really missed was not being able to use my Airpods for meetings when I’m on my laptop instead of at my desk where I have a more robust audio setup.

I started down the path of searching the community and I found a ton of information on making this work, but most of it was Ubuntu specific and that unfortunately doesn’t always transfer cleanly back to the mother distro. Further, the information was pretty spread out and you had to trace through a lot of feedback to figure out what was going on. Lastly, I saw a couple of opportunities to enhance/improve the work of others.

In this post I’m going to walk you through what worked in my specific case, on my specific distro. Like those that documented this before me, I can’t possibly cover all of the alterations between distros, desktop environments, and hardware.

Credit Where Credit is Due

Here are some of the sources I found the most correct/complete information. I am likely going to repeat some of what they have, but I wanted to make sure I linked over to their original works and I will try and call out all of the differences. It was just to hard to provide a “diff” so please forgive the light plagiarism.

Brief Overview

We are going to do the following.

  • Install ofono
  • Install ofono-phonesim
  • Configure systemd services to start/stop the above

This sounds easy, but it isn’t. Most of the time with Linux you’re dealing with officially packaged software that does a decent job of giving you a working configuration out of the box.

Install and configure ofono

This is the easy part, and doesn’t vary much from the Setting up Airpods Pro on Ubuntu 20.04 article.

sudo apt update
sudo apt install ofono
sudo usermod -aG bluetooth pulse

The referenced article says you need to modify /etc/pulse/default.pa but I found the defaults worked just fine

Open /etc/dbus-1/system.d/ofono.conf and add the following:

<busconfig>
  <!-- default stuff -->

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

  <!-- default stuff -->
</busconfig>

For reference, my complete file looks like the following:

<!-- This configuration file specifies the required security policies
     for oFono core daemon to work. -->

<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>

  <!-- ../system.conf have denied everything, so we just punch some holes -->

  <policy user="root">
    <allow own="org.ofono"/>
    <allow send_destination="org.ofono"/>
    <allow send_interface="org.ofono.SimToolkitAgent"/>
    <allow send_interface="org.ofono.PushNotificationAgent"/>
    <allow send_interface="org.ofono.SmartMessagingAgent"/>
    <allow send_interface="org.ofono.PositioningRequestAgent"/>
    <allow send_interface="org.ofono.HandsfreeAudioAgent"/>
    <allow send_interface="org.ofono.NetworkMonitorAgent"/>
    <allow send_interface="org.ofono.intel.LteCoexistenceAgent"/>
  </policy>

  <policy at_console="true">
    <allow send_destination="org.ofono"/>
  </policy>

  <policy context="default">
    <deny send_destination="org.ofono"/>
  </policy>

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

</busconfig>

Install and configure ofono-phonesim

With ofono installed you next need to supply a modem.

This is where we have to do some work, because we can’t simply use the Ubuntu PPA from the original article.

Throughout this section you will need the details from the Technical details about this PPA section from here.

I will show all commands with the values that were valid at the time I wrote this, but you may need to change them if you check against the PPA page.

Install some pre-requisites:

sudo apt install devscripts build-essential software-properties-common

Add the signing key to your system:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B59D5F1597A504B7E2306DCA0620BBCF03683F77

Create the list file using the deb-src URL by adding the following to /etc/apt/sources.list.d/smoser-ubuntu-bluetooth-focal.list:

deb-src http://ppa.launchpad.net/smoser/bluetooth/ubuntu focal main

NOTE: If you want to try a different Ubuntu release instead of focal make sure you consult the mapping

At this point you should be able to run sudo apt update and not see any errors.

As noted above and in the referenced docs, we need to build a Debian package and can’t use what is in the PPA directly.

I try and stay organized:

mkdir -p ~/ppa/pkg-ofono-phonesim
cd ~/ppa/pkg-ofono-phonesim

apt source -t focal --build ofono-phonesim

Now you should have a .deb file in the current directory so you can just install it:

sudo apt install qtbase5-dev qtdeclarative5-dev
sudo dpkg -i ofono-phonesim_1.21-16-gadf231a8-0smoser0_amd64.deb

NOTE: The first command installs some dependencies, the second may need to be different for you so check your local directory for a similarly named package.

Create a file called /etc/ofono/phonesim.conf with the following contents:

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

Create systemd Services to Manage ofono and ofono-phonesim

This is where we introduct what I think are a few improvements.

You will want to grab some official scripts from ofono:

sudo git clone git://git.kernel.org/pub/scm/network/ofono/ofono.git /opt/ofono

In addition, grab some scripts I wrote that make this all work better:

git clone https://github.com/davidnewman/control-phonesim.git ~/github.com/davidnewman/control-phonesim

Follow the instructions in the README.md file to set that up.

Create a file called /etc/systemd/system/ofono-phonesim.service with the following contents:

[Unit]
Description=Run ofono-phonesim in the background
Requires=ofono.service
After=ofono.service

[Service]
ExecStart=ofono-phonesim -p 12345 /usr/share/phonesim/default.xml
Type=simple
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

NOTE: The After= makes sure this doesn’t start until after ofono

Create a file called /etc/systemd/system/phonesim-enable-modem.service with the following contents:

[Unit]
Description=Enable and online phonesim modem
Requires=ofono-phonesim.service
After=ofono-phonesim.service

[Service]
ExecStart=/usr/local/bin/control-phonesim start
Type=oneshot
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

In this case, we are using our control-phonesim script to manage the service, and we are waiting for ofono-phonesim to start.

Giving it a Test

At this point you should be able to just restart your computer and your Airpods should work (including switch back and forth between A2DP and HSP/HFP modes).

If you don’t want to restart, then you can do this:

sudo systemctl start phonesim-enable-modem
systemctl --user restart pulseaudio

Now try your headphones.

Summary

That is a lot of work just to get a pair of headphones working. The results are also not stellar. You’re only going to get mono output in HSP/HFP mode while A2DP sounds pretty good but doesn’t allow you to use your microphone. It’s kind of a partial failure in any case. I can say that on Manjaro, with an updated kernel, my Airpods worked rather well with no configuration on my part. I can only assume that future iterations of Debian will support them the same way. For now though, I have working headphones.