Skip to contentSkip to conversation

audio/hfp-hf: Add Operator name support

PATCH Superseded Frédéric Danis 3 participants 5 messages Dec 17, 2025 – Dec 18, 2025 Bluetooth drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 audio/hfp-hf: Add Operator name support

---
 profiles/audio/hfp-hf.c | 8 ++++++++
 1 file changed, 8 insertions(+)
profiles/audio/hfp-hf.c +8 -0
index d25cda389..384480c9e 100644
@@ -108,6 +108,13 @@ static void hfp_hf_update_indicator(enum hfp_indicator indicator, uint32_t val,
 	}
 }
 
+static void hfp_hf_update_operator(const char *operator_name, void *user_data)
+{
+	struct hfp_device *dev = user_data;
+
+	telephony_set_operator_name(dev->telephony, operator_name);
+}
+
 static void hfp_hf_session_ready_cb(enum hfp_result res, enum hfp_error cme_err,
 							void *user_data)
 {
@@ -125,6 +132,7 @@ static void hfp_hf_session_ready_cb(enum hfp_result res, enum hfp_error cme_err,
 static struct hfp_hf_callbacks hf_session_callbacks = {
 	.session_ready = hfp_hf_session_ready_cb,
 	.update_indicator = hfp_hf_update_indicator,
+	.update_operator = hfp_hf_update_operator,
 };
 
 static void hfp_disconnect_watch(void *user_data)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/3 audio/hfp-hf: Add simple call support

This allows to dial, hang-up, answer or reject a call.

---
 profiles/audio/hfp-hf.c | 184 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 184 insertions(+)
profiles/audio/hfp-hf.c +184 -0
index 384480c9e..81d5f4437 100644
@@ -36,6 +36,7 @@
 #include "src/btd.h"
 #include "src/dbus-common.h"
 #include "src/device.h"
+#include "src/error.h"
 #include "src/log.h"
 #include "src/plugin.h"
 #include "src/profile.h"
@@ -52,6 +53,7 @@ struct hfp_device {
 	uint16_t		version;
 	GIOChannel		*io;
 	struct hfp_hf		*hf;
+	GSList			*calls;
 };
 
 static void hfp_hf_debug(const char *str, void *user_data)
@@ -59,6 +61,33 @@ static void hfp_hf_debug(const char *str, void *user_data)
 	DBG_IDX(0xffff, "%s", str);
 }
 
+static enum call_state hfp_call_status_to_call_state(
+						enum hfp_call_status status)
+{
+	switch (status) {
+	case CALL_STATUS_ACTIVE: return CALL_STATE_ACTIVE; break;
+	case CALL_STATUS_HELD: return CALL_STATE_HELD; break;
+	case CALL_STATUS_DIALING: return CALL_STATE_DIALING; break;
+	case CALL_STATUS_ALERTING: return CALL_STATE_ALERTING; break;
+	case CALL_STATUS_INCOMING: return CALL_STATE_INCOMING; break;
+	case CALL_STATUS_WAITING: return CALL_STATE_WAITING; break;
+	case CALL_STATUS_RESPONSE_AND_HOLD:
+		return CALL_STATE_RESPONSE_AND_HOLD; break;
+	default:
+		DBG("Unknown hfp_call_status: %u", status);
+	}
+
+	return CALL_STATE_DISCONNECTED;
+}
+
+static int call_id_cmp(gconstpointer a, gconstpointer b)
+{
+	struct call *call = (struct call *) a;
+	uint16_t id = GPOINTER_TO_UINT(b);
+
+	return call->idx == id ? 0 : -1;
+}
+
 static void device_destroy(struct hfp_device *dev)
 {
 	DBG("%s", telephony_get_path(dev->telephony));
@@ -115,6 +144,42 @@ static void hfp_hf_update_operator(const char *operator_name, void *user_data)
 	telephony_set_operator_name(dev->telephony, operator_name);
 }
 
+static void hfp_hf_call_added(uint id, enum hfp_call_status status,
+							void *user_data)
+{
+	struct hfp_device *dev = user_data;
+	struct call *call;
+
+	call = telephony_new_call(dev->telephony, id,
+					hfp_call_status_to_call_state(status),
+					NULL);
+	if (telephony_call_register_interface(call)) {
+		telephony_free_call(call);
+		return;
+	}
+
+	dev->calls = g_slist_append(dev->calls, call);
+}
+
+static void hfp_hf_call_removed(uint id, void *user_data)
+{
+	struct hfp_device *dev = user_data;
+	GSList *match;
+	struct call *call;
+
+	match = g_slist_find_custom(dev->calls, GINT_TO_POINTER(id),
+							call_id_cmp);
+	if (!match) {
+		DBG("Unknown call id: %u", id);
+		return;
+	}
+	call = match->data;
+
+	telephony_call_set_state(call, CALL_STATE_DISCONNECTED);
+	dev->calls = g_slist_remove(dev->calls, call);
+	telephony_call_unregister_interface(call);
+}
+
 static void hfp_hf_session_ready_cb(enum hfp_result res, enum hfp_error cme_err,
 							void *user_data)
 {
@@ -129,10 +194,51 @@ static void hfp_hf_session_ready_cb(enum hfp_result res, enum hfp_error cme_err,
 	telephony_set_state(dev->telephony, CONNECTED);
 }
 
+static void hfp_hf_call_status_updated(uint id, enum hfp_call_status status,
+							void *user_data)
+{
+	struct hfp_device *dev = user_data;
+	GSList *match;
+	struct call *call;
+
+	match = g_slist_find_custom(dev->calls, GINT_TO_POINTER(id),
+							call_id_cmp);
+	if (!match) {
+		DBG("Unknown call id: %u", id);
+		return;
+	}
+	call = match->data;
+
+	telephony_call_set_state(call, hfp_call_status_to_call_state(status));
+}
+
+static void hfp_hf_call_line_id_updated(uint id, const char *number,
+							unsigned int type,
+							void *user_data)
+{
+	struct hfp_device *dev = user_data;
+	GSList *match;
+	struct call *call;
+
+	match = g_slist_find_custom(dev->calls, GINT_TO_POINTER(id),
+							call_id_cmp);
+	if (!match) {
+		DBG("Unknown call id: %u", id);
+		return;
+	}
+	call = match->data;
+
+	telephony_call_set_line_id(call, number);
+}
+
 static struct hfp_hf_callbacks hf_session_callbacks = {
 	.session_ready = hfp_hf_session_ready_cb,
 	.update_indicator = hfp_hf_update_indicator,
 	.update_operator = hfp_hf_update_operator,
+	.call_added = hfp_hf_call_added,
+	.call_removed = hfp_hf_call_removed,
+	.call_status_updated = hfp_hf_call_status_updated,
+	.call_line_id_updated = hfp_hf_call_line_id_updated,
 };
 
 static void hfp_disconnect_watch(void *user_data)
@@ -184,7 +290,85 @@ failed:
 	device_destroy(dev);
 }
 
+static void cmd_complete(enum hfp_result res, enum hfp_error cme_err,
+							void *user_data)
+{
+	DBusMessage *msg = user_data;
+
+	if (res != HFP_RESULT_OK) {
+		DBusMessage *reply;
+		const char *name = dbus_message_get_member(msg);
+
+		error("Command %s error: %d", name, res);
+		reply = g_dbus_create_error(msg, ERROR_INTERFACE
+					".Failed",
+					"Command %s failed: %d", name, res);
+		g_dbus_send_message(btd_get_dbus_connection(), reply);
+		dbus_message_unref(msg);
+		return;
+	}
+
+	g_dbus_send_reply(btd_get_dbus_connection(), msg, DBUS_TYPE_INVALID);
+	dbus_message_unref(msg);
+}
+
+static DBusMessage *dial(DBusConnection *conn, DBusMessage *msg,
+				void *profile_data)
+{
+	struct hfp_device *dev = profile_data;
+	const char *number;
+	bool ret;
+
+	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &number,
+					DBUS_TYPE_INVALID)) {
+		return btd_error_invalid_args(msg);
+	}
+
+	if (strncmp(number, URI_PREFIX, strlen(URI_PREFIX)) != 0)
+		return btd_error_invalid_args(msg);
+
+	ret = hfp_hf_dial(dev->hf, number + strlen(URI_PREFIX), cmd_complete,
+					dbus_message_ref(msg));
+	if (!ret)
+		return btd_error_failed(msg, "Dial command failed");
+
+	return NULL;
+}
+
+static DBusMessage *call_answer(DBusConnection *conn, DBusMessage *msg,
+				void *call_data)
+{
+	struct call *call = call_data;
+	struct hfp_device *dev = telephony_get_profile_data(call->device);
+	bool ret;
+
+	ret = hfp_hf_call_answer(dev->hf, call->idx, cmd_complete,
+					dbus_message_ref(msg));
+	if (!ret)
+		return btd_error_failed(msg, "Answer call command failed");
+
+	return NULL;
+}
+
+static DBusMessage *call_hangup(DBusConnection *conn, DBusMessage *msg,
+				void *call_data)
+{
+	struct call *call = call_data;
+	struct hfp_device *dev = telephony_get_profile_data(call->device);
+	bool ret;
+
+	ret = hfp_hf_call_hangup(dev->hf, call->idx, cmd_complete,
+					dbus_message_ref(msg));
+	if (!ret)
+		return btd_error_failed(msg, "Hangup call command failed");
+
+	return NULL;
+}
+
 struct telephony_callbacks hfp_callbacks = {
+	.dial = dial,
+	.call_answer = call_answer,
+	.call_hangup = call_hangup,
 };
 
 static int hfp_connect(struct btd_service *service)
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH BlueZ 2/3] audio/hfp-hf: Add simple call support

Hi Frederic,

Quoted 19 lines · Frédéric Danis

This allows to dial, hang-up, answer or reject a call.

---
 profiles/audio/hfp-hf.c | 184 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 184 insertions(+)
profiles/audio/hfp-hf.c +1 -0
index 384480c9e..81d5f4437 100644
@@ -36,6 +36,7 @@
 #include "src/btd.h"
 #include "src/dbus-common.h"
 #include "src/device.h"
+#include "src/error.h"
 #include "src/log.h"
 #include "src/plugin.h"
 #include "src/profile.h"

profiles/audio/hfp-hf.c struct hfp_device { · line 56

Quoted 4 lines
profiles/audio/hfp-hf.c +1 -0
@@ -52,6 +53,7 @@ struct hfp_device {
        uint16_t                version;
        GIOChannel              *io;
        struct hfp_hf           *hf;
+       GSList                  *calls;

Use struct queue instead of GSList.

Quoted 222 lines
profiles/audio/hfp-hf.c +182 -1
 };
 
 static void hfp_hf_debug(const char *str, void *user_data)
@@ -59,6 +61,33 @@ static void hfp_hf_debug(const char *str, void *user_data)
        DBG_IDX(0xffff, "%s", str);
 }
 
+static enum call_state hfp_call_status_to_call_state(
+                                               enum hfp_call_status status)
+{
+       switch (status) {
+       case CALL_STATUS_ACTIVE: return CALL_STATE_ACTIVE; break;
+       case CALL_STATUS_HELD: return CALL_STATE_HELD; break;
+       case CALL_STATUS_DIALING: return CALL_STATE_DIALING; break;
+       case CALL_STATUS_ALERTING: return CALL_STATE_ALERTING; break;
+       case CALL_STATUS_INCOMING: return CALL_STATE_INCOMING; break;
+       case CALL_STATUS_WAITING: return CALL_STATE_WAITING; break;
+       case CALL_STATUS_RESPONSE_AND_HOLD:
+               return CALL_STATE_RESPONSE_AND_HOLD; break;
+       default:
+               DBG("Unknown hfp_call_status: %u", status);
+       }
+
+       return CALL_STATE_DISCONNECTED;
+}
+
+static int call_id_cmp(gconstpointer a, gconstpointer b)
+{
+       struct call *call = (struct call *) a;
+       uint16_t id = GPOINTER_TO_UINT(b);
+
+       return call->idx == id ? 0 : -1;
+}
+
 static void device_destroy(struct hfp_device *dev)
 {
        DBG("%s", telephony_get_path(dev->telephony));
@@ -115,6 +144,42 @@ static void hfp_hf_update_operator(const char *operator_name, void *user_data)
        telephony_set_operator_name(dev->telephony, operator_name);
 }
 
+static void hfp_hf_call_added(uint id, enum hfp_call_status status,
+                                                       void *user_data)
+{
+       struct hfp_device *dev = user_data;
+       struct call *call;
+
+       call = telephony_new_call(dev->telephony, id,
+                                       hfp_call_status_to_call_state(status),
+                                       NULL);
+       if (telephony_call_register_interface(call)) {
+               telephony_free_call(call);
+               return;
+       }
+
+       dev->calls = g_slist_append(dev->calls, call);
+}
+
+static void hfp_hf_call_removed(uint id, void *user_data)
+{
+       struct hfp_device *dev = user_data;
+       GSList *match;
+       struct call *call;
+
+       match = g_slist_find_custom(dev->calls, GINT_TO_POINTER(id),
+                                                       call_id_cmp);
+       if (!match) {
+               DBG("Unknown call id: %u", id);
+               return;
+       }
+       call = match->data;
+
+       telephony_call_set_state(call, CALL_STATE_DISCONNECTED);
+       dev->calls = g_slist_remove(dev->calls, call);
+       telephony_call_unregister_interface(call);
+}
+
 static void hfp_hf_session_ready_cb(enum hfp_result res, enum hfp_error cme_err,
                                                        void *user_data)
 {
@@ -129,10 +194,51 @@ static void hfp_hf_session_ready_cb(enum hfp_result res, enum hfp_error cme_err,
        telephony_set_state(dev->telephony, CONNECTED);
 }
 
+static void hfp_hf_call_status_updated(uint id, enum hfp_call_status status,
+                                                       void *user_data)
+{
+       struct hfp_device *dev = user_data;
+       GSList *match;
+       struct call *call;
+
+       match = g_slist_find_custom(dev->calls, GINT_TO_POINTER(id),
+                                                       call_id_cmp);
+       if (!match) {
+               DBG("Unknown call id: %u", id);
+               return;
+       }
+       call = match->data;
+
+       telephony_call_set_state(call, hfp_call_status_to_call_state(status));
+}
+
+static void hfp_hf_call_line_id_updated(uint id, const char *number,
+                                                       unsigned int type,
+                                                       void *user_data)
+{
+       struct hfp_device *dev = user_data;
+       GSList *match;
+       struct call *call;
+
+       match = g_slist_find_custom(dev->calls, GINT_TO_POINTER(id),
+                                                       call_id_cmp);
+       if (!match) {
+               DBG("Unknown call id: %u", id);
+               return;
+       }
+       call = match->data;
+
+       telephony_call_set_line_id(call, number);
+}
+
 static struct hfp_hf_callbacks hf_session_callbacks = {
        .session_ready = hfp_hf_session_ready_cb,
        .update_indicator = hfp_hf_update_indicator,
        .update_operator = hfp_hf_update_operator,
+       .call_added = hfp_hf_call_added,
+       .call_removed = hfp_hf_call_removed,
+       .call_status_updated = hfp_hf_call_status_updated,
+       .call_line_id_updated = hfp_hf_call_line_id_updated,
 };
 
 static void hfp_disconnect_watch(void *user_data)
@@ -184,7 +290,85 @@ failed:
        device_destroy(dev);
 }
 
+static void cmd_complete(enum hfp_result res, enum hfp_error cme_err,
+                                                       void *user_data)
+{
+       DBusMessage *msg = user_data;
+
+       if (res != HFP_RESULT_OK) {
+               DBusMessage *reply;
+               const char *name = dbus_message_get_member(msg);
+
+               error("Command %s error: %d", name, res);
+               reply = g_dbus_create_error(msg, ERROR_INTERFACE
+                                       ".Failed",
+                                       "Command %s failed: %d", name, res);
+               g_dbus_send_message(btd_get_dbus_connection(), reply);
+               dbus_message_unref(msg);
+               return;
+       }
+
+       g_dbus_send_reply(btd_get_dbus_connection(), msg, DBUS_TYPE_INVALID);
+       dbus_message_unref(msg);
+}
+
+static DBusMessage *dial(DBusConnection *conn, DBusMessage *msg,
+                               void *profile_data)
+{
+       struct hfp_device *dev = profile_data;
+       const char *number;
+       bool ret;
+
+       if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &number,
+                                       DBUS_TYPE_INVALID)) {
+               return btd_error_invalid_args(msg);
+       }
+
+       if (strncmp(number, URI_PREFIX, strlen(URI_PREFIX)) != 0)
+               return btd_error_invalid_args(msg);
+
+       ret = hfp_hf_dial(dev->hf, number + strlen(URI_PREFIX), cmd_complete,
+                                       dbus_message_ref(msg));
+       if (!ret)
+               return btd_error_failed(msg, "Dial command failed");
+
+       return NULL;
+}
+
+static DBusMessage *call_answer(DBusConnection *conn, DBusMessage *msg,
+                               void *call_data)
+{
+       struct call *call = call_data;
+       struct hfp_device *dev = telephony_get_profile_data(call->device);
+       bool ret;
+
+       ret = hfp_hf_call_answer(dev->hf, call->idx, cmd_complete,
+                                       dbus_message_ref(msg));
+       if (!ret)
+               return btd_error_failed(msg, "Answer call command failed");
+
+       return NULL;
+}
+
+static DBusMessage *call_hangup(DBusConnection *conn, DBusMessage *msg,
+                               void *call_data)
+{
+       struct call *call = call_data;
+       struct hfp_device *dev = telephony_get_profile_data(call->device);
+       bool ret;
+
+       ret = hfp_hf_call_hangup(dev->hf, call->idx, cmd_complete,
+                                       dbus_message_ref(msg));
+       if (!ret)
+               return btd_error_failed(msg, "Hangup call command failed");
+
+       return NULL;
+}
+
 struct telephony_callbacks hfp_callbacks = {
+       .dial = dial,
+       .call_answer = call_answer,
+       .call_hangup = call_hangup,
 };
 
 static int hfp_connect(struct btd_service *service)
--

2.43.0

Signature · 1 line
Luiz Augusto von Dentz
#3 lore raw

PATCH 3/3 audio/hfp-hf: Add in-band ringtone flag support

In reply to Frédéric Danis

This flags is set by remote phone when it wants to play the ringtone through the audio channel.

---
 profiles/audio/hfp-hf.c | 8 ++++++++
 1 file changed, 8 insertions(+)
profiles/audio/hfp-hf.c +8 -0
index 81d5f4437..3c4218da3 100644
@@ -137,6 +137,13 @@ static void hfp_hf_update_indicator(enum hfp_indicator indicator, uint32_t val,
 	}
 }
 
+static void hfp_hf_update_inband_ring(bool enabled, void *user_data)
+{
+	struct hfp_device *dev = user_data;
+
+	telephony_set_inband_ringtone(dev->telephony, enabled);
+}
+
 static void hfp_hf_update_operator(const char *operator_name, void *user_data)
 {
 	struct hfp_device *dev = user_data;
@@ -235,6 +242,7 @@ static struct hfp_hf_callbacks hf_session_callbacks = {
 	.session_ready = hfp_hf_session_ready_cb,
 	.update_indicator = hfp_hf_update_indicator,
 	.update_operator = hfp_hf_update_operator,
+	.update_inband_ring = hfp_hf_update_inband_ring,
 	.call_added = hfp_hf_call_added,
 	.call_removed = hfp_hf_call_removed,
 	.call_status_updated = hfp_hf_call_status_updated,
Signature · 1 line
2.43.0
#4 lore raw
In reply to Frédéric Danis

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1034282

---Test result---

Test Summary:

CheckPatch                    PENDING   0.28 seconds
GitLint                       PENDING   0.52 seconds
BuildEll                      PASS      20.07 seconds
BluezMake                     PASS      636.11 seconds
MakeCheck                     PASS      21.62 seconds
MakeDistcheck                 PASS      242.05 seconds
CheckValgrind                 PASS      300.83 seconds
CheckSmatch                   PASS      347.94 seconds
bluezmakeextell               PASS      181.95 seconds
IncrementalBuild              PENDING   0.39 seconds
ScanBuild                     PASS      1019.08 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:

---
Regards,
Linux Bluetooth