summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hcid/adapter.c22
-rw-r--r--hcid/adapter.h2
-rw-r--r--hcid/dbus-api.txt6
-rw-r--r--hcid/hcid.h1
-rw-r--r--hcid/storage.c21
5 files changed, 49 insertions, 3 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);
diff --git a/hcid/adapter.h b/hcid/adapter.h
index 6ffc6bcc..dc70119b 100644
--- a/hcid/adapter.h
+++ b/hcid/adapter.h
@@ -115,6 +115,8 @@ const char *minor_class_str(uint32_t class);
const char *mode2str(uint8_t mode);
+uint8_t str2mode(const char *addr, const char *mode);
+
GSList *service_classes_str(uint32_t class);
int pending_remote_name_cancel(struct adapter *adapter);
diff --git a/hcid/dbus-api.txt b/hcid/dbus-api.txt
index de604302..9a29916d 100644
--- a/hcid/dbus-api.txt
+++ b/hcid/dbus-api.txt
@@ -380,7 +380,11 @@ Methods dict GetInfo()
void SetMode(string mode)
Sets mode of the adapter. See GetMode for valid strings
- for the mode parameter.
+ for the mode parameter. In addition to the valid strings
+ for GetMode, this method also supports a special
+ parameter value "on" which will change the mode to the
+ previous non-off mode (or do nothing if the current
+ mode isn't "off").
Possible errors: org.bluez.Error.NoSuchAdapter
org.bluez.Error.Failed
diff --git a/hcid/hcid.h b/hcid/hcid.h
index b096d264..4da1bdb7 100644
--- a/hcid/hcid.h
+++ b/hcid/hcid.h
@@ -182,6 +182,7 @@ int write_discoverable_timeout(bdaddr_t *bdaddr, int timeout);
int read_discoverable_timeout(bdaddr_t *bdaddr, int *timeout);
int write_device_mode(bdaddr_t *bdaddr, const char *mode);
int read_device_mode(bdaddr_t *bdaddr, char *mode, int length);
+int read_on_mode(bdaddr_t *bdaddr, char *mode, int length);
int write_local_name(bdaddr_t *bdaddr, char *name);
int read_local_name(bdaddr_t *bdaddr, char *name);
int write_local_class(bdaddr_t *bdaddr, uint8_t *class);
diff --git a/hcid/storage.c b/hcid/storage.c
index 68f3470c..f2254cc3 100644
--- a/hcid/storage.c
+++ b/hcid/storage.c
@@ -94,6 +94,9 @@ int write_device_mode(bdaddr_t *bdaddr, const char *mode)
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if (strcmp(mode, "off") != 0)
+ textfile_put(filename, "on", mode);
+
return textfile_put(filename, "mode", mode);
}
@@ -115,6 +118,24 @@ int read_device_mode(bdaddr_t *bdaddr, char *mode, int length)
return 0;
}
+int read_on_mode(bdaddr_t *bdaddr, char *mode, int length)
+{
+ char filename[PATH_MAX + 1], *str;
+
+ create_filename(filename, PATH_MAX, bdaddr, "config");
+
+ str = textfile_get(filename, "on");
+ if (!str)
+ return -ENOENT;
+
+ strncpy(mode, str, length);
+ mode[length - 1] = '\0';
+
+ free(str);
+
+ return 0;
+}
+
int write_local_name(bdaddr_t *bdaddr, char *name)
{
char filename[PATH_MAX + 1], str[249];