* [PATCH 1/22] Move find_session in adapter.c @ 2011-02-28 11:28 Dmitriy Paliy 2011-02-28 11:28 ` [PATCH 2/2] Fix response on adapter RequestSession method Dmitriy Paliy 0 siblings, 1 reply; 4+ messages in thread From: Dmitriy Paliy @ 2011-02-28 11:28 UTC (permalink / raw) To: linux-bluetooth, luiz.dentz; +Cc: Dmitriy Paliy find_session is moved to be before set_mode, to avoid declaration of prototype. It is used in the subsequent patch. --- src/adapter.c | 28 ++++++++++++++-------------- 1 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index 2e11832..49a23ec 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(GSList *list, const char *sender) +{ + GSList *l; + + for (l = list; l; l = l->next) { + struct session_req *req = l->data; + + if (g_str_equal(req->owner, sender)) + return req; + } + + return NULL; +} + static int set_mode(struct btd_adapter *adapter, uint8_t new_mode, DBusMessage *msg) { @@ -620,20 +634,6 @@ static void adapter_set_pairable_timeout(struct btd_adapter *adapter, adapter); } -static struct session_req *find_session(GSList *list, const char *sender) -{ - GSList *l; - - for (l = list; l; l = l->next) { - struct session_req *req = l->data; - - if (g_str_equal(req->owner, sender)) - return req; - } - - return NULL; -} - static uint8_t get_needed_mode(struct btd_adapter *adapter, uint8_t mode) { GSList *l; -- 1.7.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] Fix response on adapter RequestSession method 2011-02-28 11:28 [PATCH 1/22] Move find_session in adapter.c Dmitriy Paliy @ 2011-02-28 11:28 ` Dmitriy Paliy 0 siblings, 0 replies; 4+ messages in thread From: Dmitriy Paliy @ 2011-02-28 11:28 UTC (permalink / raw) To: linux-bluetooth, luiz.dentz; +Cc: Dmitriy Paliy Fixes response on adapter RequestSession method to be sent after mode is changed. 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 powered off. --- src/adapter.c | 45 ++++++++++++++++++++++++++++++++++++--------- 1 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index 49a23ec..5cdb371 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -510,11 +510,19 @@ 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) { + const char *sender = dbus_message_get_sender(msg); + struct session_req *req; + + req = find_session(adapter->mode_sessions, sender); + 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,17 +803,31 @@ static void confirm_mode_cb(struct agent *agent, DBusError *derr, void *data) return; } - err = set_mode(req->adapter, req->mode, NULL); - if (err < 0) + err = set_mode(req->adapter, req->mode, req->msg); + if (err < 0) { reply = btd_error_failed(req->msg, strerror(-err)); - else + goto proceed; + } + + if (!req->adapter->pending_mode) { reply = dbus_message_new_method_return(req->msg); + goto proceed; + } + + goto done; +proceed: + /* + * Send reply immidiately 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; +done: if (!find_session(req->adapter->mode_sessions, req->owner)) session_unref(req); } @@ -2485,7 +2507,12 @@ static void set_mode_complete(struct btd_adapter *adapter) if (strcmp(dbus_message_get_member(msg), "SetProperty") == 0) adapter->global_mode = adapter->mode; - reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID); + + if (strcmp(dbus_message_get_member(msg), + "RequestSession") == 0) + reply = dbus_message_new_method_return(msg); + else + reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID); } g_dbus_send_message(connection, reply); -- 1.7.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 0/2 v2] Fix response on adapter RequestSession method @ 2011-02-28 11:34 Dmitriy Paliy 2011-02-28 11:34 ` [PATCH 2/2] " Dmitriy Paliy 0 siblings, 1 reply; 4+ messages in thread From: Dmitriy Paliy @ 2011-02-28 11:34 UTC (permalink / raw) To: linux-bluetooth, luiz.dentz Hi, These patches are resent due to wrong enumeration in previous submission. BR, Dmitriy ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] Fix response on adapter RequestSession method 2011-02-28 11:34 [PATCH 0/2 v2] " Dmitriy Paliy @ 2011-02-28 11:34 ` Dmitriy Paliy 2011-02-28 13:31 ` Luiz Augusto von Dentz 0 siblings, 1 reply; 4+ messages in thread From: Dmitriy Paliy @ 2011-02-28 11:34 UTC (permalink / raw) To: linux-bluetooth, luiz.dentz; +Cc: Dmitriy Paliy Fixes response on adapter RequestSession method to be sent after mode is changed. 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 powered off. --- src/adapter.c | 45 ++++++++++++++++++++++++++++++++++++--------- 1 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index 49a23ec..5cdb371 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -510,11 +510,19 @@ 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) { + const char *sender = dbus_message_get_sender(msg); + struct session_req *req; + + req = find_session(adapter->mode_sessions, sender); + 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,17 +803,31 @@ static void confirm_mode_cb(struct agent *agent, DBusError *derr, void *data) return; } - err = set_mode(req->adapter, req->mode, NULL); - if (err < 0) + err = set_mode(req->adapter, req->mode, req->msg); + if (err < 0) { reply = btd_error_failed(req->msg, strerror(-err)); - else + goto proceed; + } + + if (!req->adapter->pending_mode) { reply = dbus_message_new_method_return(req->msg); + goto proceed; + } + + goto done; +proceed: + /* + * Send reply immidiately 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; +done: if (!find_session(req->adapter->mode_sessions, req->owner)) session_unref(req); } @@ -2485,7 +2507,12 @@ static void set_mode_complete(struct btd_adapter *adapter) if (strcmp(dbus_message_get_member(msg), "SetProperty") == 0) adapter->global_mode = adapter->mode; - reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID); + + if (strcmp(dbus_message_get_member(msg), + "RequestSession") == 0) + reply = dbus_message_new_method_return(msg); + else + reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID); } g_dbus_send_message(connection, reply); -- 1.7.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] Fix response on adapter RequestSession method 2011-02-28 11:34 ` [PATCH 2/2] " Dmitriy Paliy @ 2011-02-28 13:31 ` Luiz Augusto von Dentz 0 siblings, 0 replies; 4+ messages in thread From: Luiz Augusto von Dentz @ 2011-02-28 13:31 UTC (permalink / raw) To: Dmitriy Paliy; +Cc: linux-bluetooth Hi Dmitry, On Mon, Feb 28, 2011 at 8:34 AM, Dmitriy Paliy <dmitriy.paliy@nokia.com> wrote: > Fixes response on adapter RequestSession method to be sent after mode is > changed. 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 > powered off. > --- > src/adapter.c | 45 ++++++++++++++++++++++++++++++++++++--------- > 1 files changed, 36 insertions(+), 9 deletions(-) > > diff --git a/src/adapter.c b/src/adapter.c > index 49a23ec..5cdb371 100644 > --- a/src/adapter.c > +++ b/src/adapter.c > @@ -510,11 +510,19 @@ 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) { > + const char *sender = dbus_message_get_sender(msg); > + struct session_req *req; > + > + req = find_session(adapter->mode_sessions, sender); > + 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); Im afraid this is wrong, we should get a session which refer to the same message not only to the same sender, otherwise we can only reply to the first message that creates the session but the same sender can call another method in meantime which would not be replied. > + } else > /* Nothing to reply just write the new mode */ > adapter->mode = new_mode; > > @@ -795,17 +803,31 @@ static void confirm_mode_cb(struct agent *agent, DBusError *derr, void *data) > return; > } > > - err = set_mode(req->adapter, req->mode, NULL); > - if (err < 0) > + err = set_mode(req->adapter, req->mode, req->msg); > + if (err < 0) { > reply = btd_error_failed(req->msg, strerror(-err)); > - else > + goto proceed; > + } > + > + if (!req->adapter->pending_mode) { > reply = dbus_message_new_method_return(req->msg); > + goto proceed; > + } > + > + goto done; > > +proceed: > + /* > + * Send reply immidiately 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; > > +done: > if (!find_session(req->adapter->mode_sessions, req->owner)) > session_unref(req); > } > @@ -2485,7 +2507,12 @@ static void set_mode_complete(struct btd_adapter *adapter) > if (strcmp(dbus_message_get_member(msg), > "SetProperty") == 0) > adapter->global_mode = adapter->mode; > - reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID); > + > + if (strcmp(dbus_message_get_member(msg), > + "RequestSession") == 0) > + reply = dbus_message_new_method_return(msg); > + else > + reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID); Do we really need this? Afaik g_dbus_create_reply do call dbus_message_new_method_return internally, so perhaps the if clause for RequestSession is not really necessary since the else clause is already generating the very same reply. > } > > g_dbus_send_message(connection, reply); > -- > 1.7.1 > > -- Luiz Augusto von Dentz Computer Engineer ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-02-28 13:31 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-02-28 11:28 [PATCH 1/22] Move find_session in adapter.c Dmitriy Paliy 2011-02-28 11:28 ` [PATCH 2/2] Fix response on adapter RequestSession method Dmitriy Paliy -- strict thread matches above, loose matches on Subject: below -- 2011-02-28 11:34 [PATCH 0/2 v2] " Dmitriy Paliy 2011-02-28 11:34 ` [PATCH 2/2] " Dmitriy Paliy 2011-02-28 13:31 ` Luiz Augusto von Dentz
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox