From: Luiz Augusto von Dentz <luiz.dentz-von@xxxxxxxxx> When changing from/to limited discoverable or discoverable it won't change the scan mode thus causing set_mode_complete to not be called. --- src/adapter.c | 49 +++++++++++++++++++++++++++++++++---------------- 1 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index e5f7730..b5e73b7 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -584,25 +584,41 @@ 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) { + /* Limited to Discoverable and vice-versa doesn't cause any + change to scan mode */ + if (g_str_equal(modestr, mode2str(adapter->mode)) == TRUE) { + DBusMessage *reply; + + reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID); + + g_dbus_send_message(connection, reply); + } 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; return 0; } -static DBusMessage *set_powered(DBusConnection *conn, DBusMessage *msg, - gboolean powered, void *data) +static DBusMessage *set_discoverable(DBusConnection *conn, DBusMessage *msg, + gboolean discoverable, void *data) { struct btd_adapter *adapter = data; uint8_t mode; int err; - mode = powered ? get_mode(&adapter->bdaddr, "on") : MODE_OFF; + mode = discoverable ? MODE_DISCOVERABLE : MODE_CONNECTABLE; + + if (mode == MODE_DISCOVERABLE && adapter->pairable && + adapter->discov_timeout > 0 && + adapter->discov_timeout <= 60) + mode = MODE_LIMITED; if (mode == adapter->mode) return dbus_message_new_method_return(msg); @@ -614,19 +630,20 @@ static DBusMessage *set_powered(DBusConnection *conn, DBusMessage *msg, return NULL; } -static DBusMessage *set_discoverable(DBusConnection *conn, DBusMessage *msg, - gboolean discoverable, void *data) +static DBusMessage *set_powered(DBusConnection *conn, DBusMessage *msg, + gboolean powered, void *data) { struct btd_adapter *adapter = data; uint8_t mode; int err; - mode = discoverable ? MODE_DISCOVERABLE : MODE_CONNECTABLE; + if (powered) { + mode = get_mode(&adapter->bdaddr, "on"); + return set_discoverable(conn, msg, mode == MODE_DISCOVERABLE, + data); + } - if (mode == MODE_DISCOVERABLE && adapter->pairable && - adapter->discov_timeout > 0 && - adapter->discov_timeout <= 60) - mode = MODE_LIMITED; + mode = MODE_OFF; if (mode == adapter->mode) return dbus_message_new_method_return(msg); @@ -635,7 +652,7 @@ static DBusMessage *set_discoverable(DBusConnection *conn, DBusMessage *msg, if (err < 0) return failed_strerror(msg, -err); - return 0; + return NULL; } static DBusMessage *set_pairable(DBusConnection *conn, DBusMessage *msg, -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html