Pairing Apple Airpods as Headset

With Ubuntu 16.04 I've been attempting to pair by Apple airpods as a headset. They come up as headphones. They work fine as headphones, but I would like the microphone to be available

airpods pairing as headphones, not headset


I was helped by the instruction below.

  1. Set ControllerMode = bredr or ControllerMode = dual by editing /etc/bluetooth/main.conf file using sudo nano /etc/bluetooth/main.conf command (or another text editor of your choice)
  2. sudo /etc/init.d/bluetooth restart
  3. Try to pair again.

I was desperately searching on the websites, but I finally found this blog post which was really helpful to get familiar with a complementary Bluetooth stack. Here's the solution which I have changed and added to it according to my experience:

  1. Install bluez Bluetooth stack (like a full set of Bluetooth drivers which allows the Linux OS direct access to Bluetooth):

    sudo apt-get install 'bluez*'

  2. Optional: install Bluetooth manager, Blueman:

    sudo apt-get install blueman

  3. Load USB Bluetooth driver (Bluetooth dongle):

    modprobe btusb

  4. Restart bluetooth service:

    sudo systemctl restart bluetooth

  5. Add controller mode setting to be dual Bluetooth configuration /etc/bluetooth/main.conf change this mode to bredr or le in case you have problem with your AirPods:

    ControllerMode = dual

  6. Now try to pair your AirPods!

The source of the issue is that Ubuntu's Bluetooth driver doesn't cover AirPods' one.

My system specification:

  • Ubuntu 18.04.2 LTS
  • Mini Bluetooth 4.0 USB 2.0 CSR4.0 Dongle Adapter

UPDATE:

You might need to choose either dual or bredr for ControllerMode in step 5.

enter image description here


First, some words of context of what's might be going on for latest Ubuntu 21.04. Pulseaudio doesn't have complete/perfect support for HFP/HSP (the bluetooth standards for headset and headphones). Two options:

  • pipewire (replacement of pulseaudio) (ref https://askubuntu.com/a/1339908/170833 ) (you will get 16k quality on the microphone).
  • install ofono (a framework developed by Intel people) alongside your pulseaudio (original SO answer and article explaining similar thing ).

This guide will follow the both options, but don't do both (or both of them halfways). CHOOSE YOUR OWN ADVENTURE NOW.

Install latest Pipewire (and disable pulseaudio)

  1. install PPA with this commands:
sudo add-apt-repository ppa:pipewire-debian/pipewire-upstream
sudo apt-get update
  1. Install pipewire!
sudo apt install pipewire pipewire-pulse \
  pipewire-tests pipewire-locales gstreamer1.0-pipewire libspa-0.2-bluetooth \
  libspa-0.2-jack pipewire-audio-client-libraries
  1. Disable pulseaudio
sudo systemctl disable --global pulseaudio
  1. Enable pipewire
sudo systemctl enable --global pipewire-pulse
  1. Check pipewire is integrated checking the output of this command
$ pactl info | grep "Server Name"
Server Name: PulseAudio (on Pipewire 0.3.35)

At this point you should have a working audio system!

Modify pulseaudio with ofono and ofono-phonesim

First install some dependencies from a PPA:

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

Now, let's start with "the right stuff":

  1. Go ahead and edit /etc/pulse/default.pa and find the line load-module module-bluetooth-discover and change it to load-module module-bluetooth-discover headset=ofono (pro-tip use command sudoedit /etc/pulse/default.pa to edit files of the system)

  2. Edit the file /etc/dbus-1/system.d/ofono.conf and add this xml:

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

(not at the end, as that would produce a wrongly formatted XML)

  1. Edit the file /etc/ofono/phonesim.conf and put at the end of it:
[phonesim]
Driver=phonesim
Address=127.0.0.1
Port=12345
  1. Checkout the scripts that help ofono start it's simulated modem:
cd /tmp
git clone git://git.kernel.org/pub/scm/network/ofono/ofono.git
sudo mv ofono /opt
  1. Reboot your computer and pray to the old and the new gods.

  2. Create a file called $HOME/prepare_for_meeting.sh with this content:

#!/bin/bash

ofono-phonesim -p 12345 /usr/share/phonesim/default.xml &
sleep 5
/opt/ofono/test/enable-modem /phonesim
/opt/ofono/test/online-modem /phonesim

  1. TEST STEP. BYPASS IF YOU LIVE ON THE EDGE OF THE UNKNOWN ON EVERY MOMENT. Run this script to test if your are on the right path:
/opt/ofono/test/list-modems

You should see something along this:

[ /phonesim ]                                                                                         
Online = 0                                                                                        
Powered = 1                                                                                       
Lockdown = 0                                                                                      
Emergency = 0                                                                                     
Manufacturer = MeeGo                                                                              
Model = Synthetic Device                                                                          
Revision = REV1                                                                                   
Serial = 1234567890       
... continues with much more things ...

LAST STEP

Either if you followed the Pipewire or Ofono path, now you should have an audio system that can use "Headset Head Unit" protocol. Let's click it! (and yes, now is a good moment to pray to "Mary, Undoer of Knots")

Enter Settings -> Sound -> Output, select "Headset Head Unit (HSP/HFP)" and what you will see that on "Input" also changes.

airpods connected in HSP/HFP mode

Hopefully you enjoyed all this scripting and hacking in your machine! If things go sideways, remember to undo stuff so that your computer doesn't become bloated and full of random scripts from people on the internet (specially from me).