Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 0/1 v3] Fix response on adapter RequestSession method
@ 2011-03-02  8:24 Dmitriy Paliy
  2011-03-02  8:24 ` [PATCH " Dmitriy Paliy
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitriy Paliy @ 2011-03-02  8:24 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz, anderson.lizardo

Hi,

This is modified version of submission with version 2. Here comments
of Anderson Lizardo are taken into account. Thanks to him for thorough
review.

BR,
Dmitriy


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

* [PATCH v3] Fix response on adapter RequestSession method
  2011-03-02  8:24 [PATCH 0/1 v3] Fix response on adapter RequestSession method Dmitriy Paliy
@ 2011-03-02  8:24 ` Dmitriy Paliy
  2011-03-04 18:34   ` Johan Hedberg
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitriy Paliy @ 2011-03-02  8:24 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz, anderson.lizardo; +Cc: Dmitriy Paliy

Fixes response on adapter RequestSession method to be sent after mode is
changed, if such is necessary. More specifically, change of power off mode
to power on is in question.

Currenty response is sent when mode change is confirmed by agent, not by
response from controller. Such may lead to failed CreateDevice method if
it is called quickly enough after RequestSession when controller is in
powered off state.

New session is not created if there is already a session for such D-Bus
message.
---
 src/adapter.c |   52 +++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 2e11832..b119fd1 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -452,6 +452,20 @@ static int adapter_set_mode(struct btd_adapter *adapter, uint8_t mode)
 	return 0;
 }
 
+static struct session_req *find_session_by_msg(GSList *list, const DBusMessage *msg)
+{
+	GSList *l;
+
+	for (l = list; l; l = l->next) {
+		struct session_req *req = l->data;
+
+		if (req->msg == msg)
+			return req;
+	}
+
+	return NULL;
+}
+
 static int set_mode(struct btd_adapter *adapter, uint8_t new_mode,
 			DBusMessage *msg)
 {
@@ -496,11 +510,18 @@ done:
 
 	DBG("%s", modestr);
 
-	if (msg != NULL)
-		/* Wait for mode change to reply */
-		adapter->pending_mode = create_session(adapter, connection,
-							msg, new_mode, NULL);
-	else
+	if (msg != NULL) {
+		struct session_req *req;
+
+		req = find_session_by_msg(adapter->mode_sessions, msg);
+		if (req) {
+			adapter->pending_mode = req;
+			session_ref(req);
+		} else
+			/* Wait for mode change to reply */
+			adapter->pending_mode = create_session(adapter,
+					connection, msg, new_mode, NULL);
+	} else
 		/* Nothing to reply just write the new mode */
 		adapter->mode = new_mode;
 
@@ -795,16 +816,25 @@ static void confirm_mode_cb(struct agent *agent, DBusError *derr, void *data)
 		return;
 	}
 
-	err = set_mode(req->adapter, req->mode, NULL);
+	err = set_mode(req->adapter, req->mode, req->msg);
 	if (err < 0)
 		reply = btd_error_failed(req->msg, strerror(-err));
-	else
+	else if (!req->adapter->pending_mode)
 		reply = dbus_message_new_method_return(req->msg);
+	else
+		reply = NULL;
 
-	g_dbus_send_message(req->conn, reply);
+	if (reply) {
+		/*
+		 * Send reply immediately only if there was an error changing
+		 * mode, or change is not needed. Otherwise, reply is sent in
+		 * set_mode_complete.
+		 */
+		g_dbus_send_message(req->conn, reply);
 
-	dbus_message_unref(req->msg);
-	req->msg = NULL;
+		dbus_message_unref(req->msg);
+		req->msg = NULL;
+	}
 
 	if (!find_session(req->adapter->mode_sessions, req->owner))
 		session_unref(req);
-- 
1.7.1


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

* Re: [PATCH v3] Fix response on adapter RequestSession method
  2011-03-02  8:24 ` [PATCH " Dmitriy Paliy
@ 2011-03-04 18:34   ` Johan Hedberg
  0 siblings, 0 replies; 3+ messages in thread
From: Johan Hedberg @ 2011-03-04 18:34 UTC (permalink / raw)
  To: Dmitriy Paliy; +Cc: linux-bluetooth, luiz.dentz, anderson.lizardo

Hi Dmitriy,

On Wed, Mar 02, 2011, Dmitriy Paliy wrote:
> Fixes response on adapter RequestSession method to be sent after mode
> is changed, if such is necessary. More specifically, change of power
> off mode to power on is in question.
> 
> Currently response is sent when mode change is confirmed by agent, not
> by response from controller. Such may lead to failed CreateDevice
> method if it is called quickly enough after RequestSession when
> controller is in powered off state.
> 
> New session is not created if there is already a session for such
> D-Bus message.
> ---
>  src/adapter.c |   52 +++++++++++++++++++++++++++++++++++++++++-----------
>  1 files changed, 41 insertions(+), 11 deletions(-)

Pushed upstream. Thanks.

Johan

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

end of thread, other threads:[~2011-03-04 18:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-02  8:24 [PATCH 0/1 v3] Fix response on adapter RequestSession method Dmitriy Paliy
2011-03-02  8:24 ` [PATCH " Dmitriy Paliy
2011-03-04 18:34   ` Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox