All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] bluez5: Rename BlueZ Profile registration functions
@ 2013-02-01 23:33 Vinicius Costa Gomes
  2013-02-01 23:33 ` [PATCH 2/4] bluez5: Add support for Connecting/Disconnecting per UUID Vinicius Costa Gomes
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Vinicius Costa Gomes @ 2013-02-01 23:33 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3314 bytes --]

From: Claudio Takahasi <claudio.takahasi@openbossa.org>

This patch renames external profile registration functions replacing the
prefix from 'bluetooth_' to 'bt_' in order to follow the name convention
adopted for bluez5 functions.
---
 plugins/bluez5.c        | 4 ++--
 plugins/bluez5.h        | 4 ++--
 plugins/hfp_ag_bluez5.c | 4 ++--
 plugins/hfp_hf_bluez5.c | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/plugins/bluez5.c b/plugins/bluez5.c
index d5c566e..c505e71 100644
--- a/plugins/bluez5.c
+++ b/plugins/bluez5.c
@@ -101,7 +101,7 @@ done:
 	dbus_message_unref(reply);
 }
 
-int bluetooth_register_profile(DBusConnection *conn, const char *uuid,
+int bt_register_profile(DBusConnection *conn, const char *uuid,
 					const char *name, const char *object)
 {
 	DBusMessageIter iter, dict;
@@ -136,7 +136,7 @@ int bluetooth_register_profile(DBusConnection *conn, const char *uuid,
 	return 0;
 }
 
-void bluetooth_unregister_profile(DBusConnection *conn, const char *object)
+void bt_unregister_profile(DBusConnection *conn, const char *object)
 {
 	DBusMessageIter iter;
 	DBusPendingCall *c;
diff --git a/plugins/bluez5.h b/plugins/bluez5.h
index cdbfe72..16245eb 100644
--- a/plugins/bluez5.h
+++ b/plugins/bluez5.h
@@ -69,7 +69,7 @@ int bt_ba2str(const bdaddr_t *ba, char *str);
 
 int bt_bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2);
 
-int bluetooth_register_profile(DBusConnection *conn, const char *uuid,
+int bt_register_profile(DBusConnection *conn, const char *uuid,
 					const char *name, const char *object);
 
-void bluetooth_unregister_profile(DBusConnection *conn, const char *object);
+void bt_unregister_profile(DBusConnection *conn, const char *object);
diff --git a/plugins/hfp_ag_bluez5.c b/plugins/hfp_ag_bluez5.c
index 80dd601..03a46fb 100644
--- a/plugins/hfp_ag_bluez5.c
+++ b/plugins/hfp_ag_bluez5.c
@@ -163,7 +163,7 @@ static void sim_state_watch(enum ofono_sim_state new_state, void *data)
 		if (modems != NULL)
 			return;
 
-		bluetooth_unregister_profile(conn, HFP_AG_EXT_PROFILE_PATH);
+		bt_unregister_profile(conn, HFP_AG_EXT_PROFILE_PATH);
 
 		return;
 	}
@@ -176,7 +176,7 @@ static void sim_state_watch(enum ofono_sim_state new_state, void *data)
 	if (modems->next != NULL)
 		return;
 
-	bluetooth_register_profile(conn, HFP_AG_UUID, "hfp_ag",
+	bt_register_profile(conn, HFP_AG_UUID, "hfp_ag",
 						HFP_AG_EXT_PROFILE_PATH);
 }
 
diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index 2f4a89e..cd3f9a6 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -429,7 +429,7 @@ static void connect_handler(DBusConnection *conn, void *user_data)
 {
 	DBG("Registering External Profile handler ...");
 
-	bluetooth_register_profile(conn, HFP_HS_UUID, "hfp_hf",
+	bt_register_profile(conn, HFP_HS_UUID, "hfp_hf",
 						HFP_EXT_PROFILE_PATH);
 }
 
@@ -606,7 +606,7 @@ static void hfp_exit(void)
 {
 	DBusConnection *conn = ofono_dbus_get_connection();
 
-	bluetooth_unregister_profile(conn, HFP_EXT_PROFILE_PATH);
+	bt_unregister_profile(conn, HFP_EXT_PROFILE_PATH);
 	g_dbus_unregister_interface(conn, HFP_EXT_PROFILE_PATH,
 						BLUEZ_PROFILE_INTERFACE);
 	ofono_modem_driver_unregister(&hfp_driver);
-- 
1.8.1.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] bluez5: Add support for Connecting/Disconnecting per UUID
  2013-02-01 23:33 [PATCH 1/4] bluez5: Rename BlueZ Profile registration functions Vinicius Costa Gomes
@ 2013-02-01 23:33 ` Vinicius Costa Gomes
  2013-02-01 23:33 ` [PATCH 3/4] hfp_hf_bluez5: Add Profile RequestDisconnection Vinicius Costa Gomes
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Vinicius Costa Gomes @ 2013-02-01 23:33 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3944 bytes --]

This adds supports for sending the ConnectProfile() and
DisconnectProfile() messages for the org.bluez.Device1 interface.
---
 plugins/bluez5.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 plugins/bluez5.h | 10 ++++++
 2 files changed, 102 insertions(+)

diff --git a/plugins/bluez5.c b/plugins/bluez5.c
index c505e71..f2cd4bb 100644
--- a/plugins/bluez5.c
+++ b/plugins/bluez5.c
@@ -41,6 +41,12 @@
 
 #define BLUEZ_PROFILE_MGMT_INTERFACE   BLUEZ_SERVICE ".ProfileManager1"
 
+struct finish_callback {
+	bt_finish_cb cb;
+	gpointer user_data;
+	char *member;
+};
+
 void bt_bacpy(bdaddr_t *dst, const bdaddr_t *src)
 {
 	memcpy(dst, src, sizeof(bdaddr_t));
@@ -162,5 +168,91 @@ void bt_unregister_profile(DBusConnection *conn, const char *object)
 	dbus_message_unref(msg);
 }
 
+static void finish_profile_cb(DBusPendingCall *call, gpointer user_data)
+{
+	struct finish_callback *callback = user_data;
+	DBusMessage *reply;
+	DBusError derr;
+	gboolean success;
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	dbus_error_init(&derr);
+
+	success = TRUE;
+
+	if (dbus_set_error_from_message(&derr, reply)) {
+		success = FALSE;
+
+		ofono_error("%s() replied an error: %s, %s", callback->member,
+						derr.name, derr.message);
+		dbus_error_free(&derr);
+	}
+
+	if (callback->cb)
+		callback->cb(success, callback->user_data);
+
+	dbus_message_unref(reply);
+}
+
+static void finish_callback_free(void *data)
+{
+	struct finish_callback *callback = data;
+
+	g_free(callback->member);
+	g_free(callback);
+}
+
+static void device_send_message(DBusConnection *conn, const char *device,
+				const char *member, const char *uuid,
+				bt_finish_cb cb, gpointer user_data)
+{
+	struct finish_callback *callback;
+	DBusMessageIter iter;
+	DBusPendingCall *c;
+	DBusMessage *msg;
+
+	DBG("Bluetooth: sending %s for %s on %s", member, uuid, device);
+
+	msg = dbus_message_new_method_call(BLUEZ_SERVICE, device,
+				BLUEZ_DEVICE_INTERFACE, member);
+
+	dbus_message_iter_init_append(msg, &iter);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &uuid);
+
+	if (!dbus_connection_send_with_reply(conn, msg, &c, -1)) {
+		ofono_error("Sending %s failed", member);
+		dbus_message_unref(msg);
+		return;
+	}
+
+	callback = g_new0(struct finish_callback, 1);
+	callback->cb = cb;
+	callback->user_data = user_data;
+	callback->member = g_strdup(dbus_message_get_member(msg));
+
+	dbus_pending_call_set_notify(c, finish_profile_cb, callback,
+							finish_callback_free);
+	dbus_pending_call_unref(c);
+
+	dbus_message_unref(msg);
+}
+
+void bt_connect_profile(DBusConnection *conn,
+				const char *device, const char *uuid,
+				bt_finish_cb cb, gpointer user_data)
+{
+	device_send_message(conn, device, "ConnectProfile", uuid,
+							cb, user_data);
+}
+
+void bt_disconnect_profile(DBusConnection *conn,
+				const char *device, const char *uuid,
+				bt_finish_cb cb, gpointer user_data)
+{
+	device_send_message(conn, device, "DisconnectProfile", uuid,
+							cb, user_data);
+}
+
 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
index 16245eb..3155901 100644
--- a/plugins/bluez5.h
+++ b/plugins/bluez5.h
@@ -73,3 +73,13 @@ int bt_register_profile(DBusConnection *conn, const char *uuid,
 					const char *name, const char *object);
 
 void bt_unregister_profile(DBusConnection *conn, const char *object);
+
+typedef void (*bt_finish_cb)(gboolean success, gpointer user_data);
+
+void bt_connect_profile(DBusConnection *conn,
+				const char *device, const char *uuid,
+				bt_finish_cb cb, gpointer user_data);
+
+void bt_disconnect_profile(DBusConnection *conn,
+				const char *device, const char *uuid,
+				bt_finish_cb cb, gpointer user_data);
-- 
1.8.1.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] hfp_hf_bluez5: Add Profile RequestDisconnection
  2013-02-01 23:33 [PATCH 1/4] bluez5: Rename BlueZ Profile registration functions Vinicius Costa Gomes
  2013-02-01 23:33 ` [PATCH 2/4] bluez5: Add support for Connecting/Disconnecting per UUID Vinicius Costa Gomes
@ 2013-02-01 23:33 ` Vinicius Costa Gomes
  2013-02-01 23:33 ` [PATCH 4/4] hfp_hf_bluez5: Add support for Enabling/Disabling the modem Vinicius Costa Gomes
  2013-02-14 14:53 ` [PATCH 1/4] bluez5: Rename BlueZ Profile registration functions Denis Kenzior
  3 siblings, 0 replies; 5+ messages in thread
From: Vinicius Costa Gomes @ 2013-02-01 23:33 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1795 bytes --]

From: Claudio Takahasi <claudio.takahasi@openbossa.org>

This patch implements RequestDisconnection method of the Profile1
interface. This method gets called when the profile gets disconnected.
The profile implementation needs to cleanup the resources related to
the informed device.
---
 plugins/hfp_hf_bluez5.c | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index cd3f9a6..0d6bdd9 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -340,11 +340,40 @@ static DBusMessage *profile_cancel(DBusConnection *conn,
 static DBusMessage *profile_disconnection(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
+	struct ofono_modem *modem;
+	struct hfp *hfp;
+	const char *device;
+	struct hfp_slc_info *info;
+	DBusMessageIter entry;
+
 	DBG("Profile handler RequestDisconnection");
 
-	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
-					".NotImplemented",
-					"Implementation not provided");
+	if (dbus_message_iter_init(msg, &entry) == FALSE)
+		goto error;
+
+	if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_OBJECT_PATH)
+		goto error;
+
+	dbus_message_iter_get_basic(&entry, &device);
+
+	modem = g_hash_table_lookup(modem_hash, device);
+	if (modem == NULL)
+		goto error;
+
+	ofono_modem_set_powered(modem, FALSE);
+
+	hfp = ofono_modem_get_data(modem);
+	info = &hfp->info;
+
+	g_at_chat_unref(info->chat);
+	info->chat = NULL;
+
+	return dbus_message_new_method_return(msg);
+
+error:
+	return g_dbus_create_error(msg,
+			BLUEZ_ERROR_INTERFACE ".Rejected",
+			"Invalid arguments in method call");
 }
 
 static const GDBusMethodTable profile_methods[] = {
-- 
1.8.1.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] hfp_hf_bluez5: Add support for Enabling/Disabling the modem
  2013-02-01 23:33 [PATCH 1/4] bluez5: Rename BlueZ Profile registration functions Vinicius Costa Gomes
  2013-02-01 23:33 ` [PATCH 2/4] bluez5: Add support for Connecting/Disconnecting per UUID Vinicius Costa Gomes
  2013-02-01 23:33 ` [PATCH 3/4] hfp_hf_bluez5: Add Profile RequestDisconnection Vinicius Costa Gomes
@ 2013-02-01 23:33 ` Vinicius Costa Gomes
  2013-02-14 14:53 ` [PATCH 1/4] bluez5: Rename BlueZ Profile registration functions Denis Kenzior
  3 siblings, 0 replies; 5+ messages in thread
From: Vinicius Costa Gomes @ 2013-02-01 23:33 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2242 bytes --]

Now that we have the support for sending the correct messages
to BlueZ, we are able to dynamically power up/down the HFP modem.

We add another property to the modem to be able to get the D-Bus
object path that represents the remote device.
---
 plugins/hfp_hf_bluez5.c | 39 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index 0d6bdd9..de580f2 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -180,6 +180,7 @@ static struct ofono_modem *modem_register(const char *device,
 		return NULL;
 
 	ofono_modem_set_string(modem, "Remote", device_address);
+	ofono_modem_set_string(modem, "DevicePath", device);
 
 	ofono_modem_set_name(modem, alias);
 	ofono_modem_register(modem);
@@ -219,19 +220,53 @@ static void hfp_remove(struct ofono_modem *modem)
 	ofono_modem_set_data(modem, NULL);
 }
 
+static void connect_cb(gboolean success, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+
+	if (success)
+		return;
+
+	ofono_modem_set_powered(modem, FALSE);
+}
+
 /* power up hardware */
 static int hfp_enable(struct ofono_modem *modem)
 {
+	const char *path;
+
 	DBG("%p", modem);
 
-	return 0;
+	path = ofono_modem_get_string(modem, "DevicePath");
+
+	/*
+	 * We call Device1.ConnectProfile() with our UUID, and we hope for the
+	 * NewConnection() method to be called, if ConnectProfile() fails we
+	 * force the modem to powered off
+	 */
+	bt_connect_profile(ofono_dbus_get_connection(), path, HFP_AG_UUID,
+							connect_cb, modem);
+
+	return -EINPROGRESS;
 }
 
 static int hfp_disable(struct ofono_modem *modem)
 {
+	const char *path;
+
 	DBG("%p", modem);
 
-	return 0;
+	path = ofono_modem_get_string(modem, "DevicePath");
+
+	/*
+	 * We call Device1.DisconnectProfile() for the connection to be
+	 * dropped, which will cause the profile RequestDisconnection() method
+	 * to be called which will bring the modem down
+	 */
+	bt_disconnect_profile(ofono_dbus_get_connection(), path, HFP_AG_UUID,
+							NULL, NULL);
+
+	return -EINPROGRESS;
 }
 
 static void hfp_pre_sim(struct ofono_modem *modem)
-- 
1.8.1.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/4] bluez5: Rename BlueZ Profile registration functions
  2013-02-01 23:33 [PATCH 1/4] bluez5: Rename BlueZ Profile registration functions Vinicius Costa Gomes
                   ` (2 preceding siblings ...)
  2013-02-01 23:33 ` [PATCH 4/4] hfp_hf_bluez5: Add support for Enabling/Disabling the modem Vinicius Costa Gomes
@ 2013-02-14 14:53 ` Denis Kenzior
  3 siblings, 0 replies; 5+ messages in thread
From: Denis Kenzior @ 2013-02-14 14:53 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 600 bytes --]

Hi Vinicius,

On 02/01/2013 05:33 PM, Vinicius Costa Gomes wrote:
> From: Claudio Takahasi<claudio.takahasi@openbossa.org>
>
> This patch renames external profile registration functions replacing the
> prefix from 'bluetooth_' to 'bt_' in order to follow the name convention
> adopted for bluez5 functions.
> ---
>   plugins/bluez5.c        | 4 ++--
>   plugins/bluez5.h        | 4 ++--
>   plugins/hfp_ag_bluez5.c | 4 ++--
>   plugins/hfp_hf_bluez5.c | 4 ++--
>   4 files changed, 8 insertions(+), 8 deletions(-)
>

All four patches have been applied, thanks.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-02-14 14:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-01 23:33 [PATCH 1/4] bluez5: Rename BlueZ Profile registration functions Vinicius Costa Gomes
2013-02-01 23:33 ` [PATCH 2/4] bluez5: Add support for Connecting/Disconnecting per UUID Vinicius Costa Gomes
2013-02-01 23:33 ` [PATCH 3/4] hfp_hf_bluez5: Add Profile RequestDisconnection Vinicius Costa Gomes
2013-02-01 23:33 ` [PATCH 4/4] hfp_hf_bluez5: Add support for Enabling/Disabling the modem Vinicius Costa Gomes
2013-02-14 14:53 ` [PATCH 1/4] bluez5: Rename BlueZ Profile registration functions Denis Kenzior

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.