[PATCH v1 4/6] hfp_hf: Add initial file for external HFP

2013-01-15 Thread Claudio Takahasi
This patch adds the initial file to support external HFP profile and
BlueZ 5. hfp_bluez5 plugin will implement an external Bluetooth
profile compatible with BlueZ 5, and hfp plugin will keep the
compatibility with BlueZ 4. Both plugins can be enabled in the system.
---
 Makefile.am |  3 +++
 plugins/hfp_hf_bluez5.c | 42 ++
 2 files changed, 45 insertions(+)
 create mode 100644 plugins/hfp_hf_bluez5.c

diff --git a/Makefile.am b/Makefile.am
index 2f50673..6d92be1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -410,6 +410,9 @@ builtin_sources += plugins/sim900.c
 if BLUEZ5
 builtin_modules += bluez5
 builtin_sources += plugins/bluez5.c
+
+builtin_modules += hfp_bluez5
+builtin_sources += plugins/hfp_hf_bluez5.c
 endif
 
 if BLUEZ4
diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
new file mode 100644
index 000..779f05d
--- /dev/null
+++ b/plugins/hfp_hf_bluez5.c
@@ -0,0 +1,42 @@
+/*
+ *
+ *  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
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include config.h
+#endif
+
+#include glib.h
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include ofono/plugin.h
+#include ofono/log.h
+
+static int hfp_init(void)
+{
+   return 0;
+}
+
+static void hfp_exit(void)
+{
+}
+
+OFONO_PLUGIN_DEFINE(hfp_bluez5, External Hands-Free Profile Plugin, VERSION,
+   OFONO_PLUGIN_PRIORITY_DEFAULT, hfp_init, hfp_exit)
-- 
1.7.11.7

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v1 5/6] hfp_hf: Add hfp_driver

2013-01-15 Thread Claudio Takahasi
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 6d92be1..b8dc781 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -409,10 +409,10 @@ builtin_sources += plugins/sim900.c
 
 if BLUEZ5
 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
 
 if BLUEZ4
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 000..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 

[PATCH v1 0/6] HFP HF: External Profile

2013-01-15 Thread Claudio Takahasi
This is the first group of the patches which introduces the Handsfree
BlueZ external profile.

The following patches contain only initial files and basic structures
for the HFP HF plugin (since files and plugins names are one of the
controversial points).

Remaining HFP HF patches:
git://git.infradead.org/users/cktakahasi/ofono.git HF-20130115

Changes from v0:
* Append BlueZ version to hfp_hf* files
* --enable-bluez4 configure option

Claudio Takahasi (6):
  Makefile: Add configure option for BlueZ 4 and 5
  bluetooth: Add versioning information to BlueZ plugins
  bluetooth: Initial files for BlueZ 5
  hfp_hf: Add initial file for external HFP
  hfp_hf: Add hfp_driver
  hfp_hf: Add BlueZ Profile handler

 Makefile.am |  30 +-
 configure.ac|  24 +-
 dundee/bluetooth.c  |   2 +-
 plugins/bluetooth.c | 989 
 plugins/bluetooth.h |  84 
 plugins/bluez4.c| 989 
 plugins/bluez4.h|  84 
 plugins/bluez5.c| 145 +++
 plugins/bluez5.h|  31 ++
 plugins/dun_gw.c|   2 +-
 plugins/hfp_ag.c|   2 +-
 plugins/hfp_hf.c| 552 ---
 plugins/hfp_hf_bluez4.c | 552 +++
 plugins/hfp_hf_bluez5.c | 194 ++
 plugins/sap.c   |   2 +-
 plugins/telit.c |   2 +-
 16 files changed, 2036 insertions(+), 1648 deletions(-)
 delete mode 100644 plugins/bluetooth.c
 delete mode 100644 plugins/bluetooth.h
 create mode 100644 plugins/bluez4.c
 create mode 100644 plugins/bluez4.h
 create mode 100644 plugins/bluez5.c
 create mode 100644 plugins/bluez5.h
 delete mode 100644 plugins/hfp_hf.c
 create mode 100644 plugins/hfp_hf_bluez4.c
 create mode 100644 plugins/hfp_hf_bluez5.c

-- 
1.7.11.7

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v1 3/6] bluetooth: Initial files for BlueZ 5

2013-01-15 Thread Claudio Takahasi
This patch adds the file for Bluetooth(BlueZ 5) oFono plugin.
---
 Makefile.am  |  5 +
 plugins/bluez5.c | 33 +
 2 files changed, 38 insertions(+)
 create mode 100644 plugins/bluez5.c

diff --git a/Makefile.am b/Makefile.am
index 85824be..2f50673 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -407,6 +407,11 @@ builtin_sources += plugins/samsung.c
 builtin_modules += sim900
 builtin_sources += plugins/sim900.c
 
+if BLUEZ5
+builtin_modules += bluez5
+builtin_sources += plugins/bluez5.c
+endif
+
 if BLUEZ4
 builtin_modules += bluez4
 builtin_sources += plugins/bluez4.c plugins/bluez4.h
diff --git a/plugins/bluez5.c b/plugins/bluez5.c
new file mode 100644
index 000..335331c
--- /dev/null
+++ b/plugins/bluez5.c
@@ -0,0 +1,33 @@
+/*
+ *
+ *  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
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include config.h
+#endif
+
+#include glib.h
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include ofono/plugin.h
+#include ofono/log.h
+
+OFONO_PLUGIN_DEFINE(bluez5, BlueZ 5 Utils Plugin, VERSION,
+   OFONO_PLUGIN_PRIORITY_DEFAULT, NULL, NULL)
-- 
1.7.11.7

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v1 6/6] hfp_hf: Add BlueZ Profile handler

2013-01-15 Thread Claudio Takahasi
This patch declares the external HFP Profile handler. It contains the
initial implementation of the D-Bus Profile1 interface and methods
responsible for handling Bluetooth connections.
---
 plugins/bluez5.h|  2 ++
 plugins/hfp_hf_bluez5.c | 74 -
 2 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/plugins/bluez5.h b/plugins/bluez5.h
index 99bf896..01ecfe8 100644
--- a/plugins/bluez5.h
+++ b/plugins/bluez5.h
@@ -20,6 +20,8 @@
  */
 
 #defineBLUEZ_SERVICE org.bluez
+#define BLUEZ_PROFILE_INTERFACEBLUEZ_SERVICE .Profile1
+#define BLUEZ_ERROR_INTERFACE  BLUEZ_SERVICE .Error
 
 #define HFP_HS_UUID111e--1000-8000-00805f9b34fb
 
diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index 0cd0d23..e024838 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -26,6 +26,8 @@
 #include errno.h
 #include glib.h
 
+#include gdbus.h
+
 #define OFONO_API_SUBJECT_TO_CHANGE
 #include ofono/modem.h
 #include ofono/dbus.h
@@ -88,6 +90,59 @@ static struct ofono_modem_driver hfp_driver = {
.post_sim   = hfp_post_sim,
 };
 
+static DBusMessage *profile_new_connection(DBusConnection *conn,
+   DBusMessage *msg, void *user_data)
+{
+   DBG(Profile handler NewConnection);
+
+   return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+   .NotImplemented,
+   Implementation not provided);
+}
+
+static DBusMessage *profile_release(DBusConnection *conn,
+   DBusMessage *msg, void *user_data)
+{
+   DBG(Profile handler Release);
+
+   return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+   .NotImplemented,
+   Implementation not provided);
+}
+
+static DBusMessage *profile_cancel(DBusConnection *conn,
+   DBusMessage *msg, void *user_data)
+{
+   DBG(Profile handler Cancel);
+
+   return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+   .NotImplemented,
+   Implementation not provided);
+}
+
+static DBusMessage *profile_disconnection(DBusConnection *conn,
+   DBusMessage *msg, void *user_data)
+{
+   DBG(Profile handler RequestDisconnection);
+
+   return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+   .NotImplemented,
+   Implementation not provided);
+}
+
+static const GDBusMethodTable profile_methods[] = {
+   { GDBUS_ASYNC_METHOD(NewConnection,
+   GDBUS_ARGS({ device, o}, { fd, h},
+   { fd_properties, a{sv} }),
+   NULL, profile_new_connection) },
+   { GDBUS_METHOD(Release, NULL, NULL, profile_release) },
+   { GDBUS_METHOD(Cancel, NULL, NULL, profile_cancel) },
+   { GDBUS_METHOD(RequestDisconnection,
+   GDBUS_ARGS({device, o}), NULL,
+   profile_disconnection) },
+   { }
+};
+
 static int hfp_init(void)
 {
DBusConnection *conn = ofono_dbus_get_connection();
@@ -96,13 +151,28 @@ static int hfp_init(void)
if (DBUS_TYPE_UNIX_FD  0)
return -EBADF;
 
+   /* Registers External Profile handler */
+   if (!g_dbus_register_interface(conn, HFP_EXT_PROFILE_PATH,
+   BLUEZ_PROFILE_INTERFACE,
+   profile_methods, NULL,
+   NULL, NULL, NULL)) {
+   ofono_error(Register Profile interface failed: %s,
+   HFP_EXT_PROFILE_PATH);
+   return -EIO;
+   }
+
err = ofono_modem_driver_register(hfp_driver);
-   if (err  0)
+   if (err  0) {
+   g_dbus_unregister_interface(conn, HFP_EXT_PROFILE_PATH,
+   BLUEZ_PROFILE_INTERFACE);
return err;
+   }
 
err = bluetooth_register_profile(conn, HFP_HS_UUID, hfp_hf,
HFP_EXT_PROFILE_PATH);
if (err  0) {
+   g_dbus_unregister_interface(conn, HFP_EXT_PROFILE_PATH,
+   BLUEZ_PROFILE_INTERFACE);
ofono_modem_driver_unregister(hfp_driver);
return err;
}
@@ -115,6 +185,8 @@ static void hfp_exit(void)
DBusConnection *conn = ofono_dbus_get_connection();
 
bluetooth_unregister_profile(conn, HFP_EXT_PROFILE_PATH);
+   g_dbus_unregister_interface(conn, HFP_EXT_PROFILE_PATH,
+   BLUEZ_PROFILE_INTERFACE);
 

Re: [PATCH v1 1/6] Makefile: Add configure option for BlueZ 4 and 5

2013-01-15 Thread Marcel Holtmann
Hi Claudio,

 BlueZ 5 is the default option. If --enable-bluez4 is provided, oFono
 plugins based on BlueZ 4 are enabled prior to BlueZ 5.
 --disable-bluetooth configure option disables BlueZ 5 and BlueZ 4
 plugins.
 ---
  Makefile.am  |  4 +++-
  configure.ac | 24 
  2 files changed, 19 insertions(+), 9 deletions(-)
 
 diff --git a/Makefile.am b/Makefile.am
 index 0d2ba9f..811a3f5 100644
 --- a/Makefile.am
 +++ b/Makefile.am
 @@ -407,7 +407,7 @@ builtin_sources += plugins/samsung.c
  builtin_modules += sim900
  builtin_sources += plugins/sim900.c
  
 -if BLUETOOTH
 +if BLUEZ4
  builtin_modules += bluetooth
  builtin_sources += plugins/bluetooth.c plugins/bluetooth.h
  
 @@ -742,6 +742,7 @@ tools_stktest_LDADD = @GLIB_LIBS@ @DBUS_LIBS@
  endif
  endif
  
 +if BLUEZ4
  if DUNDEE
  sbin_PROGRAMS += dundee/dundee
  
 @@ -759,6 +760,7 @@ if SYSTEMD
  systemdunit_DATA += dundee/dundee.service
  endif
  endif
 +endif
  
  endif
  
 diff --git a/configure.ac b/configure.ac
 index 450352b..47b0600 100644
 --- a/configure.ac
 +++ b/configure.ac
 @@ -173,15 +173,23 @@ AC_ARG_ENABLE(qmimodem, 
 AC_HELP_STRING([--disable-qmimodem],
  AM_CONDITIONAL(QMIMODEM, test ${enable_qmimodem} != no)
  
  AC_ARG_ENABLE(bluetooth, AC_HELP_STRING([--disable-bluetooth],
 - [disable Bluetooth modem support]),
 - [enable_bluetooth=${enableval}])
 -if (test ${enable_bluetooth} != no); then
 - PKG_CHECK_MODULES(BLUEZ, bluez = 4.99, dummy=yes,
 - AC_MSG_ERROR(Bluetooth library = 4.99 is required))
 + [disable BlueZ 4 and BlueZ 5 plugins support]),
 + [enable_bluez5=${enableval}])
 +
 +AC_ARG_ENABLE(bluez4, AC_HELP_STRING([--enable-bluez4],
 + [enable BlueZ 4 plugins support prior to BlueZ 
 5]),
 + [enable_bluez4=${enableval}])
 +
 +if (test ${enable_bluez4} = yes); then
 + PKG_CHECK_MODULES(BLUEZ, bluez = 4.99 bluez  5,
 +   enable_bluez4=yes enable_bluez5=no,
 +   AC_MSG_ERROR(Bluetooth library = 4.99 and  5 is 
 required))
 + AC_SUBST(BLUEZ_CFLAGS)
 + AC_SUBST(BLUEZ_LIBS)
  fi
 -AC_SUBST(BLUEZ_CFLAGS)
 -AC_SUBST(BLUEZ_LIBS)
 -AM_CONDITIONAL(BLUETOOTH, test ${enable_bluetooth} != no)
 +
 +AM_CONDITIONAL(BLUEZ4, test ${enable_bluez4} = yes)
 +AM_CONDITIONAL(BLUEZ5, test ${enable_bluez5} != no  test 
 ${enable_bluez4} != yes)

can we keep BLUETOOTH conditional for overall Bluetooth enabled/disabled
and just make BLUEZ4 the if-else statement for selecting which one.

Regards

Marcel


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono