diff options
author | Samuel Ortiz <sameo@linux.intel.com> | 2013-04-10 12:14:33 +0200 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2013-04-11 13:52:48 +0200 |
commit | a823ea893207e4b24c693f6e2bd5921bac87f17b (patch) | |
tree | 794f6ee3871824e68f8ca00edd574823def48cc7 | |
parent | bfe0cf68f9afb05cf39df6824ccf4175ed1c3008 (diff) | |
download | neard-a823ea893207e4b24c693f6e2bd5921bac87f17b.tar.gz neard-a823ea893207e4b24c693f6e2bd5921bac87f17b.tar.bz2 neard-a823ea893207e4b24c693f6e2bd5921bac87f17b.zip |
main.conf: Add DefaultPowered configuration
DefaultPowered is a boolean and will force neard into turning any detected
adapter on when set to TRUE.
-rw-r--r-- | doc/neard.conf.5 | 4 | ||||
-rw-r--r-- | src/adapter.c | 9 | ||||
-rw-r--r-- | src/main.c | 10 | ||||
-rw-r--r-- | src/main.conf | 4 |
4 files changed, 27 insertions, 0 deletions
diff --git a/doc/neard.conf.5 b/doc/neard.conf.5 index e883b8b..3f19cf3 100644 --- a/doc/neard.conf.5 +++ b/doc/neard.conf.5 @@ -35,5 +35,9 @@ This section is the only mandatory section of the configuration file. .B ConstantPoll=\fPtrue|false\fP Enable constant polling. Default is false. Constant polling will force neard into starting a new polling cycle whenever a target or a device are lost. +.TP +.B DefaultPowered=\fPtrue|false\fP +Automatically turn an adapter on when being discovered. +Default value is false. .SH "SEE ALSO" .BR neard (8) diff --git a/src/adapter.c b/src/adapter.c index 91a4bec..c3785c6 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -597,6 +597,7 @@ struct near_adapter *__near_adapter_create(uint32_t idx, const char *name, uint32_t protocols, near_bool_t powered) { struct near_adapter *adapter; + near_bool_t powered_setting; adapter = g_try_malloc0(sizeof(struct near_adapter)); if (adapter == NULL) @@ -607,6 +608,14 @@ struct near_adapter *__near_adapter_create(uint32_t idx, g_free(adapter); return NULL; } + + powered_setting = near_setting_get_bool("DefaultPowered"); + if (powered_setting == TRUE && powered == FALSE && + !__near_netlink_adapter_enable(adapter->idx, powered_setting)) + powered = TRUE; + + DBG("Powered %d", powered); + adapter->idx = idx; adapter->protocols = protocols; adapter->powered = powered; @@ -35,8 +35,10 @@ static struct { near_bool_t constant_poll; + near_bool_t default_powered; } near_settings = { .constant_poll = FALSE, + .default_powered = FALSE, }; static GKeyFile *load_config(const char *file) @@ -77,6 +79,11 @@ static void parse_config(GKeyFile *config) if (error == NULL) near_settings.constant_poll = boolean; + boolean = g_key_file_get_boolean(config, "General", + "DefaultPowered", &error); + if (error == NULL) + near_settings.default_powered = boolean; + g_clear_error(&error); } @@ -141,6 +148,9 @@ near_bool_t near_setting_get_bool(const char *key) if (g_str_equal(key, "ConstantPoll") == TRUE) return near_settings.constant_poll; + if (g_str_equal(key, "DefaultPowered") == TRUE) + return near_settings.default_powered; + return FALSE; } diff --git a/src/main.conf b/src/main.conf index 65b6ac3..ccaa871 100644 --- a/src/main.conf +++ b/src/main.conf @@ -5,3 +5,7 @@ # polling loop whenever a tag or a device is no longer # in the RF field. ConstantPoll = true + +# Automatically turn an adapter on when being discovered. +# Default value is false. +DefaultPowered = true |