diff options
author | Johan Hedberg <johan.hedberg@nokia.com> | 2009-07-31 15:47:19 +0300 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2009-07-31 15:53:23 +0300 |
commit | 59fb9c144f76db70761864fa3b0d1b9d4e61affd (patch) | |
tree | 339dffa41ec30b1b25f40f28221ba7fdbe2c57fe /src | |
parent | fec239062b9126f2092c4d77233ab987ac3b0336 (diff) |
Add functions for RFKILL and offline mode
This patch adds a couple of helper functions that are needed to cleanly
implement RFKILL and offline mode support.
Diffstat (limited to 'src')
-rw-r--r-- | src/adapter.c | 32 | ||||
-rw-r--r-- | src/adapter.h | 2 | ||||
-rw-r--r-- | src/manager.c | 14 | ||||
-rw-r--r-- | src/manager.h | 2 |
4 files changed, 49 insertions, 1 deletions
diff --git a/src/adapter.c b/src/adapter.c index 06640e75..908b6a77 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -3001,6 +3001,38 @@ gboolean adapter_powering_down(struct btd_adapter *adapter) return adapter->off_requested; } +int btd_adapter_restore_powered(struct btd_adapter *adapter) +{ + char mode[14], address[18]; + + if (!adapter_ops) + return -EINVAL; + + if (!main_opts.remember_powered) + return -EINVAL; + + if (adapter->up) + return 0; + + ba2str(&adapter->bdaddr, address); + if (read_device_mode(address, mode, sizeof(mode)) == 0 && + g_str_equal(mode, "off")) + return 0; + + return adapter_ops->set_powered(adapter->dev_id, TRUE); +} + +int btd_adapter_switch_offline(struct btd_adapter *adapter) +{ + if (!adapter_ops) + return -EINVAL; + + if (!adapter->up) + return 0; + + return adapter_ops->set_powered(adapter->dev_id, FALSE); +} + int btd_register_adapter_ops(struct btd_adapter_ops *btd_adapter_ops) { /* Already registered */ diff --git a/src/adapter.h b/src/adapter.h index 1c00564d..5ad9ceb4 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -159,6 +159,8 @@ void btd_adapter_any_release_path(void); gboolean adapter_is_pairable(struct btd_adapter *adapter); gboolean adapter_powering_down(struct btd_adapter *adapter); +int btd_adapter_restore_powered(struct btd_adapter *adapter); +int btd_adapter_switch_offline(struct btd_adapter *adapter); struct btd_adapter_ops { int (*setup) (void); diff --git a/src/manager.c b/src/manager.c index bfa00dd6..3cf914d1 100644 --- a/src/manager.c +++ b/src/manager.c @@ -518,3 +518,17 @@ void manager_set_default_adapter(int id) DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); } + +void btd_manager_set_offline(gboolean offline) +{ + GSList *l; + + for (l = adapters; l != NULL; l = g_slist_next(l)) { + struct btd_adapter *adapter = l->data; + + if (offline) + btd_adapter_switch_offline(adapter); + else + btd_adapter_restore_powered(adapter); + } +} diff --git a/src/manager.h b/src/manager.h index ec074e9c..94635740 100644 --- a/src/manager.h +++ b/src/manager.h @@ -45,4 +45,4 @@ int manager_get_default_adapter(); void manager_set_default_adapter(int id); void manager_update_svc(const bdaddr_t *bdaddr, uint8_t svc); int manager_get_adapter_class(uint16_t dev_id, uint8_t *cls); - +void btd_manager_set_offline(gboolean offline); |