Bluetooth Telephony Simulation in Linux

As part of flexing our muscles to build a robust Bluetooth Test Automation Framework, there was a need to emulate all the phone-related Bluetooth use cases on a Linux machine. One such use case is simulating telephony functions related to call management, like call initiation, termination, answering, and rejection.

This would also help us to test infotainment systems by simulating these various telephony functions from a Linux machine.

Overview

The Bluetooth application profile that corresponds to such telephony functionality is called Hands-Free Profile (HFP). This profile specifies the necessary AT commands for these telephony functions. Bluez does not implement the HFP profile, but rather other software components like PulseAudio and ofono implement the HFP profile. PulseAudio implements a basic HFP profile functionality that is used for Zoom and Google Meetings. PulseAudio does not support advanced telephony functions like call answer, hang-up, ringtones, busy tone, etc., so another package called ofono is used to simulate this functionality. ofono is often used when Linux is used in a product that has a real cellular modem.

ofono does the following tasks related to phone call management and the other telephony functions:

  1. Send and receive AT commands to/from the modem.

  2. Triggers the respective HFP-related commands during the telephony operations.

  3. Sends and receives the DBus messages to inform other relevant processes of the telephony status.

Since there is no real modem in a general-purpose Linux machine, the modem-related functionalities need to be simulated. For this purpose, there is a package ofono-phonesim which registers a dummy modem with the ofono service.

/static/images/article-phonesim/phonesim.png

Steps for Set-up in Ubuntu 22.0

Package Installation

  • ofono - Required for the telephony-related features like call management support.

  • ofono-phonesim - Simulates a modem for ofono

  • ofono-scripts - Scripts to send the relevant DBus messages for phone-related simulation.

  • Since ofono-phonesim is not available in the Ubuntu 22.0 apt repo, add the following repo source:

$ cat /etc/apt/sources.list.d/smoser-ubuntu-bluetooth-jammy.list
deb https://ppa.launchpadcontent.net/smoser/bluetooth/ubuntu/ impish main
  • Before installing ofono-phonesim, run sudo apt update.

Note: ofono can be set up either using the standard packages available in the Ubuntu repositories or by building the ofono-related packages and installing them locally. The latter approach can be used if the most recent package features are required. For building and installing ofono packages, refer to the link: Build and Install packages from source.

Configure ofono to use phonesim

$ cat /etc/ofono/phonesim.conf

[phonesim]
Driver=phonesim
Address=127.0.0.1
Port=12345
  • ofonod should be restarted using systemctl restart ofono command for the above configuration changes will take effect.

Start the phonesim simulator

$ /usr/bin/ofono-phonesim -p 12345 -gui /usr/share/phonesim/default.xml
  • The port specified using the -p option is used for sending the AT commands and receiving the dummy response.

  • The -gui option can be given if you want to a GUI interface for simulating Telephony functions.

Configure pulseaudio

-load-module module-bluetooth-discover
+load-module module-bluetooth-discover headset=ofono
  • Restart the pulseaudio and ofono service.

$ systemctl --user restart pulseaudio
$ systemctl restart ofono

Enable the dummy modem

  • Enable the modem using the enable-modem and online-modem scripts. Verify whether the modem is enabled using the list-modems script:

$ /usr/share/ofono/scripts/list-modems
$ /usr/share/ofono/scripts/enable-modem /phonesim
$ /usr/share/ofono/scripts/online-modem /phonesim
$ /usr/share/ofono/scripts/list-modems
  • enable-modem simulates powering on the dummy modem. This will also open a GUI phonesim interface if -gui option is provided.

  • online-modem simulates modem-ready for simulating telephony functions.

  • The above commands will set the corresponding DBus properties and make the org.ofono interfaces from the ofono process available in D-Bus.

Connect Bluetooth Headset

  • Now connect a Bluetooth headset before we start simulating calls.

  • The incoming call ringtone can be heard in the Bluetooth headset.

  • The outgoing call dial tone doesn’t seem to be simulated by ofono; hence, we can only view the calls using the list-calls script or the GUI.

Call Simulation

  • For outgoing calls, use the dial-number script available in /usr/share/ofono/scripts/ directory.

/static/images/article-phonesim/outgoing-gui.png
  • Use GUI for simulating incoming calls.

/static/images/article-phonesim/incoming-gui.png
  • Simulating incoming calls without GUI can be done by dialing specific numbers mentioned in the /usr/share/phonesim/default.xml file using the dial-number script.

HFP Profile

  • There are two modes: Audio Gateway (AG) mode and Hands-Free (HF) mode.

  • The mobile phone acts in AG mode, whereas the Bluetooth headset is configured in HF mode.

  • Two communication paths are used in HFP: Service Level Connection (SLC) and Synchronous Connection (SCO).

  • A serial-port emulated protocol called RFCOMM is used between the AG and the HF. This is used for exchanging AT commands for control operations. This connection is generic across various Bluetooth profiles and works over a low-level ACL (Asynchronous Connection-oriented Logical) protocol. The presence of this ACL link can be checked using the following command:

$ hcitool con
Connections:
        > ACL 41:42:A8:3B:A0:6B handle 3840 state 5 lm PERIPHERAL
  • For a pair of HF and AG devices, a single Service-Level Connection (SLC) is established. This is required for the various control operations related to call management and uses RFCOMM as the transport protocol.

  • The SCO connection is handled by PulseAudio. By default, PulseAudio sets the hands-free Bluetooth headset in A2DP (Bluetooth profile for high-quality audio) mode. This can be verified using the command below:

$ pactl list cards
....
....
        Profiles:
                a2dp_sink: High Fidelity Playback (A2DP Sink) (sinks: 1, sources: 0, priority: 40, available: yes)
                handsfree_head_unit: Handsfree Head Unit (HFP) (sinks: 1, sources: 1, priority: 30, available: yes)
                off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
        Active Profile: a2dp_sink
....
....
  • Change the PulseAudio headset mode to HFP using the below command.

# Syntax: pactl set-card-profile <card-name> <profile-name>
$ pactl set-card-profile bluez_card.41_42_A8_3B_A0_6B handsfree_head_unit
  • After changing the PulseAudio profile to HFP, the pactl list cards command should show the following output:

        Profiles:
                a2dp_sink: High Fidelity Playback (A2DP Sink) (sinks: 1, sources: 0, priority: 40, available: yes)
                handsfree_head_unit: Handsfree Head Unit (HFP) (sinks: 1, sources: 1, priority: 30, available: yes)
                off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
        Active Profile: handsfree_head_unit
  • Also the SCO link connection should be listed now:

$ hcitool con
Connections:
        > ACL 41:42:A8:3B:A0:6B handle 256 state 1 lm CENTRAL AUTH ENCRYPT
        < eSCO 41:42:A8:3B:A0:6B handle 257 state 1 lm CENTRAL
  • During a Bluetooth headset call, the SCO link carries the voice, while an ACL link may be used concurrently for control commands (e.g., volume adjustment).

  • Actual voice transfer during a call is not supported by phonesim, so it is not possible to test the SCO link established.

  • The following screenshot shows the Bluetooth HFP-related frames captured by Wireshark during incoming and outgoing calls:

/static/images/article-phonesim/wireshark.png

Conclusion

This article has shown how basic call management functions related to HFP can be tested using ofono and phonesim tools. These scenarios can be automated using the ofono scripts and can be used for functional and stress testing in infotainment systems.

For OEMs and Tier-1 suppliers building infotainment and connected vehicle systems, this simulation framework delivers major advantages: faster validation cycles, broader test coverage, and reduced development costs. We extend this foundation to provide custom Bluetooth automation frameworks, test solutions, and validation services. Looking to accelerate your Bluetooth telephony or infotainment testing? To get started, reach out to sales@zilogic.com.