summaryrefslogtreecommitdiffstats
path: root/hcid
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2006-07-26 12:36:19 +0000
committerMarcel Holtmann <marcel@holtmann.org>2006-07-26 12:36:19 +0000
commit312e3ea913578a40d78635d5702bedd655501445 (patch)
tree25d0795d8a0a00c248a34bc0cfe793b6da83f77f /hcid
parentab13e6cdba9c3f58f6772560ab86f5ce4578d5ff (diff)
Fix the other missing storage functions
Diffstat (limited to 'hcid')
-rw-r--r--hcid/dbus-adapter.c4
-rw-r--r--hcid/hcid.h4
-rw-r--r--hcid/main.c11
-rw-r--r--hcid/storage.c44
4 files changed, 26 insertions, 37 deletions
diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c
index ac0b7bc4..5dc36d43 100644
--- a/hcid/dbus-adapter.c
+++ b/hcid/dbus-adapter.c
@@ -464,6 +464,7 @@ static DBusHandlerResult handle_dev_set_discoverable_to_req(DBusConnection *conn
DBusMessage *reply;
DBusError err;
uint32_t timeout;
+ bdaddr_t bdaddr;
dbus_error_init(&err);
dbus_message_get_args(msg, &err,
@@ -490,7 +491,8 @@ static DBusHandlerResult handle_dev_set_discoverable_to_req(DBusConnection *conn
dbus_data->discoverable_timeout = timeout;
- write_discoverable_timeout(dbus_data->address, timeout);
+ str2ba(dbus_data->address, &bdaddr);
+ write_discoverable_timeout(&bdaddr, timeout);
return send_reply_and_unref(conn, reply);
}
diff --git a/hcid/hcid.h b/hcid/hcid.h
index cbaa6048..6f5b493e 100644
--- a/hcid/hcid.h
+++ b/hcid/hcid.h
@@ -180,8 +180,8 @@ int set_device_alias(uint16_t dev_id, const bdaddr_t *bdaddr, const char *alias)
int get_encryption_key_size(uint16_t dev_id, const bdaddr_t *baddr);
-int write_discoverable_timeout(const char *address, int timeout);
-int read_discoverable_timeout(const char *address, int *timeout);
+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 write_local_name(bdaddr_t *bdaddr, char *name);
diff --git a/hcid/main.c b/hcid/main.c
index 4dcf2510..78c42208 100644
--- a/hcid/main.c
+++ b/hcid/main.c
@@ -151,9 +151,9 @@ static struct device_opts *get_device_opts(int sock, int hdev)
int get_discoverable_timeout(int hdev)
{
int sock, timeout;
- char address[18];
struct device_opts *device_opts = NULL;
struct hci_dev_info di;
+ char addr[18];
if (hdev < 0)
return HCID_DEFAULT_DISCOVERABLE_TIMEOUT;
@@ -163,19 +163,18 @@ int get_discoverable_timeout(int hdev)
goto no_address;
di.dev_id = hdev;
- if (!ioctl(sock, HCIGETDEVINFO, (void *) &di))
- ba2str(&di.bdaddr, address);
- else {
+ if (ioctl(sock, HCIGETDEVINFO, (void *) &di) < 0) {
close(sock);
goto no_address;
}
close(sock);
- if (!read_discoverable_timeout(address, &timeout))
+ if (read_discoverable_timeout(&di.bdaddr, &timeout) == 0)
return timeout;
- device_opts = find_device_opts(address);
+ ba2str(&di.bdaddr, addr);
+ device_opts = find_device_opts(addr);
no_address:
if (!device_opts) {
diff --git a/hcid/storage.c b/hcid/storage.c
index 1d16fe41..ee927a78 100644
--- a/hcid/storage.c
+++ b/hcid/storage.c
@@ -52,24 +52,24 @@ static int create_filename(char *buf, size_t size, bdaddr_t *bdaddr, char *name)
return snprintf(buf, size, "%s/%s/%s", STORAGEDIR, addr, name);
}
-int write_discoverable_timeout(const char *address, int timeout)
+int write_discoverable_timeout(bdaddr_t *bdaddr, int timeout)
{
char filename[PATH_MAX + 1], str[32];
snprintf(str, sizeof(str), "%d", timeout);
- snprintf(filename, PATH_MAX, "%s/%s/config", STORAGEDIR, address);
+ create_filename(filename, PATH_MAX, bdaddr, "config");
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
return textfile_put(filename, "discovto", str);
}
-int read_discoverable_timeout(const char *address, int *timeout)
+int read_discoverable_timeout(bdaddr_t *bdaddr, int *timeout)
{
char filename[PATH_MAX + 1], *str;
- snprintf(filename, PATH_MAX, "%s/%s/config", STORAGEDIR, address);
+ create_filename(filename, PATH_MAX, bdaddr, "config");
str = textfile_get(filename, "discovto");
if (!str)
@@ -193,8 +193,7 @@ int write_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t class)
{
char filename[PATH_MAX + 1], addr[18], str[9];
- ba2str(local, addr);
- snprintf(filename, PATH_MAX, "%s/%s/classes", STORAGEDIR, addr);
+ create_filename(filename, PATH_MAX, local, "classes");
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
@@ -208,8 +207,7 @@ int read_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t *class)
{
char filename[PATH_MAX + 1], addr[18], *str;
- ba2str(local, addr);
- snprintf(filename, PATH_MAX, "%s/%s/classes", STORAGEDIR, addr);
+ create_filename(filename, PATH_MAX, local, "classes");
ba2str(peer, addr);
@@ -239,8 +237,7 @@ int write_device_name(bdaddr_t *local, bdaddr_t *peer, char *name)
else
str[i] = name[i];
- ba2str(local, addr);
- snprintf(filename, PATH_MAX, "%s/%s/names", STORAGEDIR, addr);
+ create_filename(filename, PATH_MAX, local, "names");
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
@@ -253,8 +250,7 @@ int read_device_name(bdaddr_t *local, bdaddr_t *peer, char *name)
char filename[PATH_MAX + 1], addr[18], *str;
int len;
- ba2str(local, addr);
- snprintf(filename, PATH_MAX, "%s/%s/names", STORAGEDIR, addr);
+ create_filename(filename, PATH_MAX, local, "names");
ba2str(peer, addr);
str = textfile_get(filename, addr);
@@ -278,8 +274,7 @@ int write_version_info(bdaddr_t *local, bdaddr_t *peer, uint16_t manufacturer, u
memset(str, 0, sizeof(str));
sprintf(str, "%d %d %d", manufacturer, lmp_ver, lmp_subver);
- ba2str(local, addr);
- snprintf(filename, PATH_MAX, "%s/%s/manufacturers", STORAGEDIR, addr);
+ create_filename(filename, PATH_MAX, local, "manufacturers");
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
@@ -296,8 +291,7 @@ int write_features_info(bdaddr_t *local, bdaddr_t *peer, unsigned char *features
for (i = 0; i < 8; i++)
sprintf(str + (i * 2), "%2.2X", features[i]);
- ba2str(local, addr);
- snprintf(filename, PATH_MAX, "%s/%s/features", STORAGEDIR, addr);
+ create_filename(filename, PATH_MAX, local, "features");
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
@@ -312,8 +306,7 @@ int write_lastseen_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm)
memset(str, 0, sizeof(str));
strftime(str, sizeof(str), "%Y-%m-%d %H:%M:%S %Z", tm);
- ba2str(local, addr);
- snprintf(filename, PATH_MAX, "%s/%s/lastseen", STORAGEDIR, addr);
+ create_filename(filename, PATH_MAX, local, "lastseen");
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
@@ -328,8 +321,7 @@ int write_lastused_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm)
memset(str, 0, sizeof(str));
strftime(str, sizeof(str), "%Y-%m-%d %H:%M:%S %Z", tm);
- ba2str(local, addr);
- snprintf(filename, PATH_MAX, "%s/%s/lastused", STORAGEDIR, addr);
+ create_filename(filename, PATH_MAX, local, "lastused");
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
@@ -347,8 +339,7 @@ int write_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, int type
sprintf(str + (i * 2), "%2.2X", key[i]);
sprintf(str + 32, " %d %d", type, length);
- ba2str(local, addr);
- snprintf(filename, PATH_MAX, "%s/%s/linkkeys", STORAGEDIR, addr);
+ create_filename(filename, PATH_MAX, local, "linkkeys");
create_file(filename, S_IRUSR | S_IWUSR);
@@ -371,8 +362,7 @@ int read_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key)
char filename[PATH_MAX + 1], addr[18], tmp[3], *str;
int i;
- ba2str(local, addr);
- snprintf(filename, PATH_MAX, "%s/%s/linkkeys", STORAGEDIR, addr);
+ create_filename(filename, PATH_MAX, local, "linkkeys");
ba2str(peer, addr);
str = textfile_get(filename, addr);
@@ -395,8 +385,7 @@ int read_pin_length(bdaddr_t *local, bdaddr_t *peer)
char filename[PATH_MAX + 1], addr[18], *str;
int len;
- ba2str(local, addr);
- snprintf(filename, PATH_MAX, "%s/%s/linkkeys", STORAGEDIR, addr);
+ create_filename(filename, PATH_MAX, local, "linkkeys");
ba2str(peer, addr);
str = textfile_get(filename, addr);
@@ -420,8 +409,7 @@ int read_pin_code(bdaddr_t *local, bdaddr_t *peer, char *pin)
char filename[PATH_MAX + 1], addr[18], *str;
int len;
- ba2str(local, addr);
- snprintf(filename, PATH_MAX, "%s/%s/pincodes", STORAGEDIR, addr);
+ create_filename(filename, PATH_MAX, local, "pincodes");
ba2str(peer, addr);
str = textfile_get(filename, addr);