summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2008-12-22 15:08:36 +0200
committerJohan Hedberg <johan.hedberg@nokia.com>2008-12-22 15:08:36 +0200
commit26b23c817fbc00e6d4af1bcd7f1ef2db2819d9ff (patch)
tree01135151fe78a4bb5548842b7550fe1dfd72e0e4
parentf463bec3023ba2b9eb44f2f72f21fdb66a06c826 (diff)
Implement RememberPowered config option
-rw-r--r--src/adapter.c8
-rw-r--r--src/hcid.h1
-rw-r--r--src/main.c9
-rw-r--r--src/main.conf3
4 files changed, 19 insertions, 2 deletions
diff --git a/src/adapter.c b/src/adapter.c
index 360f76d2..5eaf729a 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2530,8 +2530,12 @@ static int adapter_up(struct btd_adapter *adapter, int dd)
if (read_device_pairable(&adapter->bdaddr, &adapter->pairable) < 0)
adapter->pairable = TRUE;
- /* Set scan mode */
- if (read_device_mode(srcaddr, mode, sizeof(mode)) < 0) {
+ if (!adapter->initialized && !main_opts.remember_powered) {
+ if (main_opts.mode == MODE_OFF)
+ strcpy(mode, "off");
+ else
+ strcpy(mode, "connectable");
+ } else if (read_device_mode(srcaddr, mode, sizeof(mode)) < 0) {
if (!adapter->initialized && main_opts.mode == MODE_OFF)
strcpy(mode, "off");
else
diff --git a/src/hcid.h b/src/hcid.h
index 90e31f0d..988205da 100644
--- a/src/hcid.h
+++ b/src/hcid.h
@@ -55,6 +55,7 @@ struct main_opts {
uint32_t pairto;
uint16_t link_mode;
uint16_t link_policy;
+ gboolean remember_powered;
uint8_t scan;
uint8_t mode;
diff --git a/src/main.c b/src/main.c
index 2af5606d..ce8493c3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -175,6 +175,14 @@ static void parse_config(GKeyFile *config)
} else if (boolean == FALSE)
main_opts.mode = MODE_OFF;
+ boolean = g_key_file_get_boolean(config, "General",
+ "RememberPowered", &err);
+ if (err) {
+ debug("%s", err->message);
+ g_clear_error(&err);
+ } else if (boolean == FALSE)
+ main_opts.remember_powered = boolean;
+
str = g_key_file_get_string(config, "General", "DeviceID", &err);
if (err) {
debug("%s", err->message);
@@ -532,6 +540,7 @@ static void init_defaults(void)
main_opts.mode = MODE_CONNECTABLE;
main_opts.name = g_strdup("BlueZ");
main_opts.discovto = HCID_DEFAULT_DISCOVERABLE_TIMEOUT;
+ main_opts.remember_powered = TRUE;
if (gethostname(main_opts.host_name, sizeof(main_opts.host_name) - 1) < 0)
strcpy(main_opts.host_name, "noname");
diff --git a/src/main.conf b/src/main.conf
index a7bb0e40..5d49c7b3 100644
--- a/src/main.conf
+++ b/src/main.conf
@@ -34,6 +34,9 @@ DiscoverSchedulerInterval = 0
# SetProperty(Powered, ...) hasn't been called yet. Defaults to true
InitiallyPowered = true
+# Remember the previously stored Powered state when initializing adapters
+RememberPowered = true
+
# Use vendor, product and version information for DID profile support.
# The values are separated by ":" and VID, PID and version.
#DeviceID = 1234:5678:abcd