Can't change profile to HSP for Bluetooth headset

Sad story,
Seems that your bluetooth card has not a fully compatible driver with bluez or whatever as mine :(.

I solved following this guide and building two stupid scripts

Getting ready

Install ofono

sudo apt install ofono

Config pulseaudio to use ofono:

  • Goto /etc/pulse/default.pa find the line load-module module-bluetooth-discover and change it in load-module module-bluetooth-discover headset=ofono.
  • Add the user pulse to group bluetooth to grant the permission: sudo usermod -aG bluetooth pulse (probably it's already correct)
  • VERY IMPORTANT: To grant the permission, add this to /etc/dbus-1/system.d/ofono.conf (add this before </busconfig>):
    <policy user="pulse">
      <allow send_destination="org.ofono"/>
    </policy>
    

Provide phonesim to ofono.
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 (in some distros it is called phonesim). in Ubuntu 18.04 (for Ubuntu 20.04 follow this link):
 sudo apt install ofono-phonesim
  • Configure phonesim by adding the following lines to /etc/ofono/phonesim.conf:
[phonesim]
Driver=phonesim
Address=127.0.0.1
Port=12345
  • Restart ofono:
sudo systemctl restart ofono.service
  • Clone ofono repository (contains useful scripts)
git clone git://git.kernel.org/pub/scm/network/ofono/ofono.git destination/path

Then, every time you want to enable hfp/hsp:

ofono-phonesim -p 12345 /usr/share/phonesim/default.xml &

then use

path/to/cloned/repo/test/enable-modem /phonesim

then restart pulseaudio with

pulseaudio --kill && pulseaudio --start

Now you should see a microphone device.

When you want to go back to a2dp:

path/to/cloned/repo/test/disable-modem /phonesim

then restart pulseaudio with

pulseaudio --kill && pulseaudio --start

eventually restart pulseeffects with

pulseeffects --quit && pulseeffects &

Lately i'm not using this because it's not always working, and so using a jack is faster.

Hope it helps :)

edit: Added getting ready section edit 2: Added git clone step


I don't have enough reputation to comment, so put this as an answer.

Lately i'm not using this because it's not always working, and so using a jack is faster.

After removing headset=ofono from load-module module-bluetooth-discover headset=ofono and restarting pulseaudio the speakers work again with microphone in Ubuntu 20.04.

E: Unable to locate package ofono-phonesim

See answer here: Failed to change profile to headset_head_unit.