Adds HFP modem driver registration.
---
Makefile.am | 4 +-
plugins/bluez5.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++
plugins/bluez5.h | 29 +++++++++++++
plugins/hfp_hf_bluez5.c | 80 ++++++++++++++++++++++++++++++++++
4 files changed, 223 insertions(+), 2 deletions(-)
create mode 100644 plugins/bluez5.h
diff --git a/Makefile.am b/Makefile.am
index 072b386..ad12c0f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -435,10 +435,10 @@ builtin_cflags += @BLUEZ_CFLAGS@
builtin_libadd += @BLUEZ_LIBS@
else
builtin_modules += bluez5
-builtin_sources += plugins/bluez5.c
+builtin_sources += plugins/bluez5.c plugins/bluez5.h
builtin_modules += hfp_bluez5
-builtin_sources += plugins/hfp_hf_bluez5.c
+builtin_sources += plugins/hfp_hf_bluez5.c plugins/bluez5.h
endif
endif
endif
diff --git a/plugins/bluez5.c b/plugins/bluez5.c
index 335331c..84ba47d 100644
--- a/plugins/bluez5.c
+++ b/plugins/bluez5.c
@@ -23,11 +23,123 @@
#include <config.h>
#endif
+#include <errno.h>
#include <glib.h>
#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/dbus.h>
#include <ofono/plugin.h>
#include <ofono/log.h>
+#include <gdbus/gdbus.h>
+#include "bluez5.h"
+
+#define BLUEZ_PROFILE_MGMT_INTERFACE BLUEZ_SERVICE ".ProfileManager1"
+
+static void profile_register_cb(DBusPendingCall *call, gpointer user_data)
+{
+ DBusMessage *reply;
+ DBusError derr;
+
+ reply = dbus_pending_call_steal_reply(call);
+
+ dbus_error_init(&derr);
+
+ if (dbus_set_error_from_message(&derr, reply)) {
+ ofono_error("RegisterProfile() replied an error: %s, %s",
+ derr.name, derr.message);
+ dbus_error_free(&derr);
+ goto done;
+ }
+
+ DBG("");
+
+done:
+ dbus_message_unref(reply);
+}
+
+static void unregister_profile_cb(DBusPendingCall *call, gpointer user_data)
+{
+ DBusMessage *reply;
+ DBusError derr;
+
+ reply = dbus_pending_call_steal_reply(call);
+
+ dbus_error_init(&derr);
+
+ if (dbus_set_error_from_message(&derr, reply)) {
+ ofono_error("UnregisterProfile() replied an error: %s, %s",
+ derr.name, derr.message);
+ dbus_error_free(&derr);
+ goto done;
+ }
+
+ DBG("");
+
+done:
+ dbus_message_unref(reply);
+}
+
+int bluetooth_register_profile(DBusConnection *conn, const char *uuid,
+ const char *name, const char *object)
+{
+ DBusMessageIter iter, dict;
+ DBusPendingCall *c;
+ DBusMessage *msg;
+
+ DBG("Bluetooth: Registering %s (%s) profile", uuid, name);
+
+ msg = dbus_message_new_method_call(BLUEZ_SERVICE, "/org/bluez",
+ BLUEZ_PROFILE_MGMT_INTERFACE, "RegisterProfile");
+
+ dbus_message_iter_init_append(msg, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &object);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &uuid);
+
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &dict);
+ ofono_dbus_dict_append(&dict, "Name", DBUS_TYPE_STRING, &name);
+
+ dbus_message_iter_close_container(&iter, &dict);
+
+ if (!dbus_connection_send_with_reply(conn, msg, &c, -1)) {
+ ofono_error("Sending RegisterProfile failed");
+ dbus_message_unref(msg);
+ return -EIO;
+ }
+
+ dbus_pending_call_set_notify(c, profile_register_cb, NULL, NULL);
+ dbus_pending_call_unref(c);
+
+ dbus_message_unref(msg);
+
+ return 0;
+}
+
+void bluetooth_unregister_profile(DBusConnection *conn, const char *object)
+{
+ DBusMessageIter iter;
+ DBusPendingCall *c;
+ DBusMessage *msg;
+
+ DBG("Bluetooth: Unregistering profile %s", object);
+
+ msg = dbus_message_new_method_call(BLUEZ_SERVICE, "/org/bluez",
+ BLUEZ_PROFILE_MGMT_INTERFACE, "UnregisterProfile");
+
+ dbus_message_iter_init_append(msg, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &object);
+
+ if (!dbus_connection_send_with_reply(conn, msg, &c, -1)) {
+ ofono_error("Sending RegisterProfile failed");
+ dbus_message_unref(msg);
+ return;
+ }
+
+ dbus_pending_call_set_notify(c, unregister_profile_cb, NULL, NULL);
+ dbus_pending_call_unref(c);
+
+ dbus_message_unref(msg);
+}
+
OFONO_PLUGIN_DEFINE(bluez5, "BlueZ 5 Utils Plugin", VERSION,
OFONO_PLUGIN_PRIORITY_DEFAULT, NULL, NULL)
diff --git a/plugins/bluez5.h b/plugins/bluez5.h
new file mode 100644
index 0000000..99bf896
--- /dev/null
+++ b/plugins/bluez5.h
@@ -0,0 +1,29 @@
+/*
+ *
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#define BLUEZ_SERVICE "org.bluez"
+
+#define HFP_HS_UUID "0000111e-0000-1000-8000-00805f9b34fb"
+
+int bluetooth_register_profile(DBusConnection *conn, const char *uuid,
+ const char *name, const char *object);
+
+void bluetooth_unregister_profile(DBusConnection *conn, const char *object);
diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index 779f05d..0cd0d23 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -23,19 +23,99 @@
#include <config.h>
#endif
+#include <errno.h>
#include <glib.h>
#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/modem.h>
+#include <ofono/dbus.h>
#include <ofono/plugin.h>
#include <ofono/log.h>
+#include "bluez5.h"
+
+#ifndef DBUS_TYPE_UNIX_FD
+#define DBUS_TYPE_UNIX_FD -1
+#endif
+
+#define HFP_EXT_PROFILE_PATH "/bluetooth/profile/hfp_hf"
+
+static int hfp_probe(struct ofono_modem *modem)
+{
+ DBG("modem: %p", modem);
+
+ return 0;
+}
+
+static void hfp_remove(struct ofono_modem *modem)
+{
+ DBG("modem: %p", modem);
+}
+
+/* power up hardware */
+static int hfp_enable(struct ofono_modem *modem)
+{
+ DBG("%p", modem);
+
+ return 0;
+}
+
+static int hfp_disable(struct ofono_modem *modem)
+{
+ DBG("%p", modem);
+
+ return 0;
+}
+
+static void hfp_pre_sim(struct ofono_modem *modem)
+{
+ DBG("%p", modem);
+}
+
+static void hfp_post_sim(struct ofono_modem *modem)
+{
+ DBG("%p", modem);
+}
+
+static struct ofono_modem_driver hfp_driver = {
+ .name = "hfp",
+ .modem_type = OFONO_MODEM_TYPE_HFP,
+ .probe = hfp_probe,
+ .remove = hfp_remove,
+ .enable = hfp_enable,
+ .disable = hfp_disable,
+ .pre_sim = hfp_pre_sim,
+ .post_sim = hfp_post_sim,
+};
+
static int hfp_init(void)
{
+ DBusConnection *conn = ofono_dbus_get_connection();
+ int err;
+
+ if (DBUS_TYPE_UNIX_FD < 0)
+ return -EBADF;
+
+ err = ofono_modem_driver_register(&hfp_driver);
+ if (err < 0)
+ return err;
+
+ err = bluetooth_register_profile(conn, HFP_HS_UUID, "hfp_hf",
+ HFP_EXT_PROFILE_PATH);
+ if (err < 0) {
+ ofono_modem_driver_unregister(&hfp_driver);
+ return err;
+ }
+
return 0;
}
static void hfp_exit(void)
{
+ DBusConnection *conn = ofono_dbus_get_connection();
+
+ bluetooth_unregister_profile(conn, HFP_EXT_PROFILE_PATH);
+ ofono_modem_driver_unregister(&hfp_driver);
}
OFONO_PLUGIN_DEFINE(hfp_bluez5, "External Hands-Free Profile Plugin", VERSION,
--
1.7.11.7
_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono