All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Frédéric Danis" <frederic.danis@collabora.com>
To: linux-bluetooth@vger.kernel.org
Subject: [RFC BlueZ v2 03/27] audio/telephony: Add skeleton for HFP profile
Date: Fri, 27 Jun 2025 16:51:12 +0200	[thread overview]
Message-ID: <20250627145136.421853-4-frederic.danis@collabora.com> (raw)
In-Reply-To: <20250627145136.421853-1-frederic.danis@collabora.com>

---
 Makefile.plugins        |   5 +
 configure.ac            |   7 ++
 profiles/audio/hfp-hf.c | 216 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 228 insertions(+)
 create mode 100644 profiles/audio/hfp-hf.c

diff --git a/Makefile.plugins b/Makefile.plugins
index bae4363d0..66e8033e4 100644
--- a/Makefile.plugins
+++ b/Makefile.plugins
@@ -150,3 +150,8 @@ if ASHA
 builtin_modules += asha
 builtin_sources += profiles/audio/asha.h profiles/audio/asha.c
 endif
+
+if HFP
+builtin_modules += hfp
+builtin_sources += profiles/audio/telephony.c profiles/audio/hfp-hf.c
+endif
diff --git a/configure.ac b/configure.ac
index 07aeb46ca..247e1c928 100644
--- a/configure.ac
+++ b/configure.ac
@@ -238,6 +238,13 @@ if test "${enable_asha}" != "no"; then
 	AC_DEFINE(HAVE_ASHA, 1, [Define to 1 if you have ASHA support.])
 fi
 
+AC_ARG_ENABLE(hfp, AS_HELP_STRING([--disable-hfp],
+		[disable HFP support]), [enable_hfp=${enableval}])
+AM_CONDITIONAL(HFP, test "${enable_hfp}" != "no")
+if test "${enable_hfp}" != "no"; then
+	AC_DEFINE(HAVE_HFP, 1, [Define to 1 if you have HFP support.])
+fi
+
 AC_ARG_ENABLE(tools, AS_HELP_STRING([--disable-tools],
 		[disable Bluetooth tools]), [enable_tools=${enableval}])
 AM_CONDITIONAL(TOOLS, test "${enable_tools}" != "no")
diff --git a/profiles/audio/hfp-hf.c b/profiles/audio/hfp-hf.c
new file mode 100644
index 000000000..f049ee5f7
--- /dev/null
+++ b/profiles/audio/hfp-hf.c
@@ -0,0 +1,216 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2014  Intel Corporation. All rights reserved.
+ *  Copyright © 2025 Collabora Ltd.
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#define _GNU_SOURCE
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <limits.h>
+
+#include <stdint.h>
+
+#include <glib.h>
+
+#include "lib/bluetooth.h"
+#include "bluetooth/sdp.h"
+#include "bluetooth/sdp_lib.h"
+#include "lib/uuid.h"
+
+#include "gdbus/gdbus.h"
+
+#include "btio/btio.h"
+#include "src/adapter.h"
+#include "src/btd.h"
+#include "src/dbus-common.h"
+#include "src/device.h"
+#include "src/log.h"
+#include "src/plugin.h"
+#include "src/profile.h"
+#include "src/service.h"
+
+#include "telephony.h"
+
+struct hfp_device {
+	struct telephony	*telephony;
+	uint16_t		version;
+	GIOChannel		*io;
+};
+
+static void device_destroy(struct hfp_device *dev)
+{
+	DBG("%s", telephony_get_path(dev->telephony));
+
+	if (dev->io) {
+		g_io_channel_unref(dev->io);
+		dev->io = NULL;
+	}
+
+	telephony_unregister_interface(dev->telephony);
+}
+
+static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
+{
+	struct hfp_device *dev = user_data;
+	struct btd_service *service = telephony_get_service(dev->telephony);
+
+	DBG("");
+
+	if (err) {
+		error("%s", err->message);
+		goto failed;
+	}
+
+	g_io_channel_set_close_on_unref(chan, FALSE);
+
+	btd_service_connecting_complete(service, 0);
+
+	return;
+
+failed:
+	g_io_channel_shutdown(chan, TRUE, NULL);
+	device_destroy(dev);
+}
+
+struct telephony_callbacks hfp_callbacks = {
+};
+
+static int hfp_connect(struct btd_service *service)
+{
+	struct hfp_device *dev;
+	struct btd_profile *p;
+	const sdp_record_t *rec;
+	sdp_list_t *list, *protos;
+	sdp_profile_desc_t *desc;
+	int channel;
+	bdaddr_t src, dst;
+	GError *err = NULL;
+
+	DBG("");
+
+	dev = btd_service_get_user_data(service);
+
+	p = btd_service_get_profile(service);
+	rec = btd_device_get_record(telephony_get_device(dev->telephony),
+					p->remote_uuid);
+	if (!rec)
+		return -EIO;
+
+	if (sdp_get_profile_descs(rec, &list) == 0) {
+		desc = list->data;
+		dev->version = desc->version;
+	}
+	sdp_list_free(list, free);
+
+	if (sdp_get_access_protos(rec, &protos) < 0) {
+		error("unable to get access protocols from record");
+		return -EIO;
+	}
+
+	channel = sdp_get_proto_port(protos, RFCOMM_UUID);
+	sdp_list_foreach(protos, (sdp_list_func_t) sdp_list_free, NULL);
+	sdp_list_free(protos, NULL);
+	if (channel <= 0) {
+		error("unable to get RFCOMM channel from record");
+		return -EIO;
+	}
+
+	src = telephony_get_src(dev->telephony);
+	dst = telephony_get_dst(dev->telephony);
+	dev->io = bt_io_connect(connect_cb, dev,
+		NULL, &err,
+		BT_IO_OPT_SOURCE_BDADDR, &src,
+		BT_IO_OPT_DEST_BDADDR, &dst,
+		BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
+		BT_IO_OPT_CHANNEL, channel,
+		BT_IO_OPT_INVALID);
+	if (dev->io == NULL) {
+		error("unable to start connection");
+		return -EIO;
+	}
+
+	return telephony_register_interface(dev->telephony);
+}
+
+static int hfp_disconnect(struct btd_service *service)
+{
+	DBG("");
+
+	btd_service_disconnecting_complete(service, 0);
+
+	return 0;
+}
+
+static int hfp_probe(struct btd_service *service)
+{
+	struct btd_device *device = btd_service_get_device(service);
+	const char *path = device_get_path(device);
+	struct hfp_device *dev;
+
+	DBG("%s", path);
+
+	dev = g_new0(struct hfp_device, 1);
+	if (!dev)
+		return -EINVAL;
+
+	dev->telephony = telephony_new(service, dev, &hfp_callbacks);
+	btd_service_set_user_data(service, dev);
+
+	return 0;
+}
+
+static void hfp_remove(struct btd_service *service)
+{
+	struct btd_device *device = btd_service_get_device(service);
+	const char *path = device_get_path(device);
+	struct hfp_device *dev;
+
+	DBG("%s", path);
+
+	dev = btd_service_get_user_data(service);
+
+	telephony_free(dev->telephony);
+	g_free(dev);
+}
+
+static struct btd_profile hfp_hf_profile = {
+	.name		= "hfp",
+	.priority	= BTD_PROFILE_PRIORITY_MEDIUM,
+
+	.remote_uuid	= HFP_AG_UUID,
+	.device_probe	= hfp_probe,
+	.device_remove	= hfp_remove,
+
+	.auto_connect	= true,
+	.connect	= hfp_connect,
+	.disconnect	= hfp_disconnect,
+
+	.experimental	= true,
+};
+
+static int hfp_init(void)
+{
+	btd_profile_register(&hfp_hf_profile);
+
+	return 0;
+}
+
+static void hfp_exit(void)
+{
+	btd_profile_unregister(&hfp_hf_profile);
+}
+
+BLUETOOTH_PLUGIN_DEFINE(hfp, VERSION, BLUETOOTH_PLUGIN_PRIORITY_DEFAULT,
+		hfp_init, hfp_exit)
-- 
2.43.0


  parent reply	other threads:[~2025-06-27 14:51 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-27 14:51 [RFC BlueZ v2 00/27] New Telephony interface for HSP, HFP and CCP Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 01/27] doc: Add new telephony related profiles interfaces Frédéric Danis
2025-06-27 16:15   ` New Telephony interface for HSP, HFP and CCP bluez.test.bot
2025-07-02 17:38   ` [RFC BlueZ v2 01/27] doc: Add new telephony related profiles interfaces Luiz Augusto von Dentz
2025-06-27 14:51 ` [RFC BlueZ v2 02/27] audio/telephony: Add shared interfaces implementation Frédéric Danis
2025-06-27 14:51 ` Frédéric Danis [this message]
2025-06-27 14:51 ` [RFC BlueZ v2 04/27] audio/hfp-hf: Add HFP SLC connection and event support Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 05/27] audio/hfp-hf: Add dial support Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 06/27] audio/hfp-hf: Add hangup all calls support Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 07/27] audio/hfp-hf: Add answer a specific call support Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 08/27] client/telephony: Add new submenu Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 09/27] audio/hfp-hf: Remove call interface during profile disconnection Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 10/27] audio/hfp-hf: Create existing call during SLC phase Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 11/27] audio/telephony: Add hangup_active and hangup_held functions Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 12/27] audio/hfp-hf: Add hangup_active and hangup_held support Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 13/27] client/telephony: " Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 14/27] audio/hfp-hf: Add SendTones support Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 15/27] client/telephony: " Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 16/27] doc: Make telephony docs more generic Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 17/27] client/telephony: Remove IncomingLine Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 18/27] audio/telephony: " Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 19/27] audio/hfp-hf: Add HFP HF server and SDP record Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 20/27] audio/hfp-hf: Add operator name support Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 21/27] audio/telephony: Add call line identication property support Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 22/27] audio/hfp-hf: Add call line idenfication support Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 23/27] audio/hfp-hf: Disable NREC during connection setup Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 24/27] audio/hfp-hf: Enable waiting call if supported by remote AG Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 25/27] audio/hfp-hf: Enable extended error " Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 26/27] audio/telephony: Add call multiparty property support Frédéric Danis
2025-06-27 14:51 ` [RFC BlueZ v2 27/27] audio/hfp-hf: Enable enhanced call status if supported by remote AG Frédéric Danis
2025-07-02 17:50 ` [RFC BlueZ v2 00/27] New Telephony interface for HSP, HFP and CCP Luiz Augusto von Dentz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250627145136.421853-4-frederic.danis@collabora.com \
    --to=frederic.danis@collabora.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.