summaryrefslogtreecommitdiff
path: root/src/adapter.c
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2022-09-01 13:07:14 +0200
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2022-09-01 11:43:35 -0700
commitabf5ba6b80add53a4617ffdd06ac2102095347c2 (patch)
tree2a673e17e51a980b451c24d95d3d7f36ee85f0d5 /src/adapter.c
parent49b8c5901584eab77af40f8ad19779747b4506d6 (diff)
downloadbluez-abf5ba6b80add53a4617ffdd06ac2102095347c2.tar.gz
adapter: Keep track of whether the adapter is rfkill'ed
Instead of only replying to D-Bus requests with an error saying the adapter is blocked, keep track of the rfkill being enabled or disabled so we know the rfkill state of the adapter at all times.
Diffstat (limited to 'src/adapter.c')
-rw-r--r--src/adapter.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/adapter.c b/src/adapter.c
index 51b099dae..7c11a688d 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -250,6 +250,7 @@ struct btd_adapter {
uint32_t dev_class; /* controller class of device */
char *name; /* controller device name */
char *short_name; /* controller short name */
+ bool blocked; /* whether rfkill is enabled */
uint32_t supported_settings; /* controller supported settings */
uint32_t pending_settings; /* pending controller settings */
uint32_t current_settings; /* current controller settings */
@@ -654,6 +655,8 @@ static void set_mode_complete(uint8_t status, uint16_t length,
if (status != MGMT_STATUS_SUCCESS) {
btd_error(adapter->dev_id, "Failed to set mode: %s (0x%02x)",
mgmt_errstr(status), status);
+ if (status == MGMT_STATUS_RFKILLED)
+ adapter->blocked = true;
adapter->pending_settings &= ~data->setting;
return;
}
@@ -2947,10 +2950,12 @@ static void property_set_mode_complete(uint8_t status, uint16_t length,
btd_error(adapter->dev_id, "Failed to set mode: %s (0x%02x)",
mgmt_errstr(status), status);
- if (status == MGMT_STATUS_RFKILLED)
+ if (status == MGMT_STATUS_RFKILLED) {
dbus_err = ERROR_INTERFACE ".Blocked";
- else
+ adapter->blocked = true;
+ } else {
dbus_err = ERROR_INTERFACE ".Failed";
+ }
g_dbus_pending_property_error(data->id, dbus_err,
mgmt_errstr(status));
@@ -6681,6 +6686,7 @@ static void load_config(struct btd_adapter *adapter)
static struct btd_adapter *btd_adapter_new(uint16_t index)
{
struct btd_adapter *adapter;
+ int blocked;
adapter = g_try_new0(struct btd_adapter, 1);
if (!adapter)
@@ -6689,6 +6695,9 @@ static struct btd_adapter *btd_adapter_new(uint16_t index)
adapter->dev_id = index;
adapter->mgmt = mgmt_ref(mgmt_primary);
adapter->pincode_requested = false;
+ blocked = rfkill_get_blocked(index);
+ if (blocked > 0)
+ adapter->blocked = true;
/*
* Setup default configuration values. These are either adapter
@@ -6714,6 +6723,8 @@ static struct btd_adapter *btd_adapter_new(uint16_t index)
DBG("Modalias: %s", adapter->modalias);
DBG("Discoverable timeout: %u seconds", adapter->discoverable_timeout);
DBG("Pairable timeout: %u seconds", adapter->pairable_timeout);
+ if (blocked > 0)
+ DBG("Blocked: yes");
adapter->auths = g_queue_new();
adapter->exps = queue_new();
@@ -7581,6 +7592,9 @@ int btd_cancel_authorization(guint id)
int btd_adapter_restore_powered(struct btd_adapter *adapter)
{
+ if (adapter->blocked)
+ adapter->blocked = false;
+
if (btd_adapter_get_powered(adapter))
return 0;
@@ -7589,6 +7603,13 @@ int btd_adapter_restore_powered(struct btd_adapter *adapter)
return 0;
}
+int btd_adapter_set_blocked(struct btd_adapter *adapter)
+{
+ if (!adapter->blocked)
+ adapter->blocked = true;
+ return 0;
+}
+
void btd_adapter_register_pin_cb(struct btd_adapter *adapter,
btd_adapter_pin_cb_t cb)
{