summaryrefslogtreecommitdiffstats
path: root/hcid/adapter.c
diff options
context:
space:
mode:
Diffstat (limited to 'hcid/adapter.c')
-rw-r--r--hcid/adapter.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/hcid/adapter.c b/hcid/adapter.c
index cddffcde..496d13d3 100644
--- a/hcid/adapter.c
+++ b/hcid/adapter.c
@@ -248,7 +248,20 @@ const char *mode2str(uint8_t mode)
}
}
-uint8_t str2mode(const char *mode)
+static uint8_t on_mode(const char *addr)
+{
+ char mode[14];
+ bdaddr_t sba;
+
+ str2ba(addr, &sba);
+
+ if (read_on_mode(&sba, mode, sizeof(mode)) < 0)
+ return MODE_CONNECTABLE;
+
+ return str2mode(addr, mode);
+}
+
+uint8_t str2mode(const char *addr, const char *mode)
{
if (strcasecmp("off", mode) == 0)
return MODE_OFF;
@@ -258,6 +271,8 @@ uint8_t str2mode(const char *mode)
return MODE_DISCOVERABLE;
else if (strcasecmp("limited", mode) == 0)
return MODE_LIMITED;
+ else if (strcasecmp("on", mode) == 0)
+ return on_mode(addr);
else
return MODE_UNKNOWN;
}
@@ -531,7 +546,7 @@ static DBusHandlerResult adapter_set_mode(DBusConnection *conn,
if (!mode)
return error_invalid_arguments(conn, msg);
- new_mode = str2mode(mode);
+ new_mode = str2mode(adapter->address, mode);
switch(new_mode) {
case MODE_OFF:
scan_enable = SCAN_DISABLED;
@@ -547,6 +562,9 @@ static DBusHandlerResult adapter_set_mode(DBusConnection *conn,
return error_invalid_arguments(conn, msg);
}
+ /* Do reverse resolution in case of "on" mode */
+ mode = mode2str(new_mode);
+
dd = hci_open_dev(adapter->dev_id);
if (dd < 0)
return error_no_such_adapter(conn, msg);