From 621a4144ece57d328bef38365035cb474d71b490 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Wed, 7 Feb 2018 11:02:24 +0100 Subject: [PATCH] advertising: Configure discoverable flag based on adapter settings Until now advertising as peripheral was always setting General Discoverable flag set. With this patch this is set based on adapter discoverable setting. Change-Id: Ic4db27d37f94ab6a99250f919d9e9432cfa40886 Signed-off-by: Amit Purwar --- src/adapter.c | 9 +++++++++ src/adapter.h | 1 + src/advertising.c | 14 ++++++++++++-- src/advertising.h | 1 + 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index f9dca5f..94f69b6 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -927,6 +927,7 @@ static void settings_changed(struct btd_adapter *adapter, uint32_t settings) g_dbus_emit_property_changed(dbus_conn, adapter->path, ADAPTER_INTERFACE, "Discoverable"); store_adapter_info(adapter); + btd_adv_manager_refresh(adapter->adv_manager); } if (changed_mask & MGMT_SETTING_BONDABLE) { @@ -8478,6 +8479,14 @@ bool btd_adapter_get_connectable(struct btd_adapter *adapter) return false; } +bool btd_adapter_get_discoverable(struct btd_adapter *adapter) +{ + if (adapter->current_settings & MGMT_SETTING_DISCOVERABLE) + return true; + + return false; +} + struct btd_gatt_database *btd_adapter_get_database(struct btd_adapter *adapter) { if (!adapter) diff --git a/src/adapter.h b/src/adapter.h index b7e9e70..fefbfac 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -145,6 +145,7 @@ void adapter_foreach(adapter_cb func, gpointer user_data); bool btd_adapter_get_pairable(struct btd_adapter *adapter); bool btd_adapter_get_powered(struct btd_adapter *adapter); bool btd_adapter_get_connectable(struct btd_adapter *adapter); +bool btd_adapter_get_discoverable(struct btd_adapter *adapter); struct btd_gatt_database *btd_adapter_get_database(struct btd_adapter *adapter); diff --git a/src/advertising.c b/src/advertising.c index 0705220..8545534 100644 --- a/src/advertising.c +++ b/src/advertising.c @@ -622,8 +622,12 @@ static int refresh_adv(struct btd_adv_client *client, mgmt_request_func_t func) DBG("Refreshing advertisement: %s", client->path); - if (client->type == AD_TYPE_PERIPHERAL) - flags = MGMT_ADV_FLAG_CONNECTABLE | MGMT_ADV_FLAG_DISCOV; + if (client->type == AD_TYPE_PERIPHERAL) { + flags = MGMT_ADV_FLAG_CONNECTABLE; + + if (btd_adapter_get_discoverable(client->manager->adapter)) + flags |= MGMT_ADV_FLAG_DISCOV; + } flags |= client->flags; @@ -1107,3 +1111,9 @@ void btd_adv_manager_destroy(struct btd_adv_manager *manager) manager_destroy(manager); } + +void btd_adv_manager_refresh(struct btd_adv_manager *manager) +{ + queue_foreach(manager->clients, (queue_foreach_func_t)refresh_adv, + NULL); +} diff --git a/src/advertising.h b/src/advertising.h index b783cf0..d98c4b8 100755 --- a/src/advertising.h +++ b/src/advertising.h @@ -22,3 +22,4 @@ struct btd_adv_manager; struct btd_adv_manager *btd_adv_manager_new(struct btd_adapter *adapter); void btd_adv_manager_destroy(struct btd_adv_manager *manager); +void btd_adv_manager_refresh(struct btd_adv_manager *manager); -- 2.7.4