From: Bastien Nocera <hadess@hadess.net>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v4 1/6] adapter: Keep track of whether the adapter is rfkill'ed
Date: Wed, 31 Aug 2022 11:19:07 +0200 [thread overview]
Message-ID: <20220831091912.47894-1-hadess@hadess.net> (raw)
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.
---
src/adapter.c | 25 +++++++++++++++++++++++--
src/adapter.h | 1 +
src/rfkill.c | 8 ++++++--
3 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index b453e86a0..641db67f9 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;
}
@@ -2914,10 +2917,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));
@@ -7548,6 +7553,12 @@ int btd_cancel_authorization(guint id)
int btd_adapter_restore_powered(struct btd_adapter *adapter)
{
+ if (adapter->blocked) {
+ adapter->blocked = false;
+ g_dbus_emit_property_changed(dbus_conn, adapter->path,
+ ADAPTER_INTERFACE, "PowerState");
+ }
+
if (btd_adapter_get_powered(adapter))
return 0;
@@ -7556,6 +7567,16 @@ 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;
+ g_dbus_emit_property_changed(dbus_conn, adapter->path,
+ ADAPTER_INTERFACE, "PowerState");
+ }
+ return 0;
+}
+
void btd_adapter_register_pin_cb(struct btd_adapter *adapter,
btd_adapter_pin_cb_t cb)
{
diff --git a/src/adapter.h b/src/adapter.h
index b09044edd..332c0b239 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -143,6 +143,7 @@ guint btd_request_authorization_cable_configured(const bdaddr_t *src, const bdad
int btd_cancel_authorization(guint id);
int btd_adapter_restore_powered(struct btd_adapter *adapter);
+int btd_adapter_set_blocked(struct btd_adapter *adapter);
typedef ssize_t (*btd_adapter_pin_cb_t) (struct btd_adapter *adapter,
struct btd_device *dev, char *out, bool *display,
diff --git a/src/rfkill.c b/src/rfkill.c
index 2099c5ac5..93f8e0e12 100644
--- a/src/rfkill.c
+++ b/src/rfkill.c
@@ -61,6 +61,7 @@ static gboolean rfkill_event(GIOChannel *chan,
struct rfkill_event event = { 0 };
struct btd_adapter *adapter;
char sysname[PATH_MAX];
+ bool blocked = false;
ssize_t len;
int fd, id;
@@ -84,7 +85,7 @@ static gboolean rfkill_event(GIOChannel *chan,
event.soft, event.hard);
if (event.soft || event.hard)
- return TRUE;
+ blocked = true;
if (event.op != RFKILL_OP_CHANGE)
return TRUE;
@@ -122,7 +123,10 @@ static gboolean rfkill_event(GIOChannel *chan,
DBG("RFKILL unblock for hci%d", id);
- btd_adapter_restore_powered(adapter);
+ if (blocked)
+ btd_adapter_set_blocked(adapter);
+ else
+ btd_adapter_restore_powered(adapter);
return TRUE;
}
--
2.37.2
next reply other threads:[~2022-08-31 9:20 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-31 9:19 Bastien Nocera [this message]
2022-08-31 9:19 ` [PATCH BlueZ v4 2/6] adapter: Implement PowerState property Bastien Nocera
2022-08-31 20:03 ` Luiz Augusto von Dentz
2022-09-01 10:43 ` Bastien Nocera
2022-08-31 9:19 ` [PATCH BlueZ v4 3/6] client: Print the " Bastien Nocera
2022-08-31 9:19 ` [PATCH BlueZ v4 4/6] adapter-api: Add PowerState property documentation Bastien Nocera
2022-08-31 9:19 ` [PATCH BlueZ v4 5/6] adapter: Fix typo in function name Bastien Nocera
2022-08-31 9:19 ` [PATCH BlueZ v4 6/6] adapter: Remove experimental flag for PowerState Bastien Nocera
2022-08-31 9:23 ` Bastien Nocera
2022-08-31 10:23 ` [BlueZ,v4,1/6] adapter: Keep track of whether the adapter is rfkill'ed bluez.test.bot
2022-08-31 11:36 ` Bastien Nocera
2022-08-31 11:36 ` [PATCH BlueZ v4 1/6] " Bastien Nocera
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220831091912.47894-1-hadess@hadess.net \
--to=hadess@hadess.net \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox