diff options
author | Johan Hedberg <johan.hedberg@nokia.com> | 2006-04-19 16:39:48 +0000 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2006-04-19 16:39:48 +0000 |
commit | 66ee11f572972796398b5cb541398ee754cc0995 (patch) | |
tree | 13a3254f51bc1b1480c0cd3f82766dac245a5a65 /hcid/storage.c | |
parent | 9575f385006817d43cdd5bacadd0b37f2e02bc9a (diff) | |
download | bluez-66ee11f572972796398b5cb541398ee754cc0995.tar.gz |
Store device mode settings
Diffstat (limited to 'hcid/storage.c')
-rw-r--r-- | hcid/storage.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/hcid/storage.c b/hcid/storage.c index e3781278d..f6475134f 100644 --- a/hcid/storage.c +++ b/hcid/storage.c @@ -43,6 +43,70 @@ #include "textfile.h" #include "hcid.h" +int write_discoverable_timeout(const char *address, 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_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) +{ + char filename[PATH_MAX + 1], *str; + + snprintf(filename, PATH_MAX, "%s/%s/config", STORAGEDIR, address); + + str = textfile_get(filename, "discovto"); + if (!str) + return -ENOENT; + + if (sscanf(str, "%d", timeout) != 1) { + free(str); + return -ENOENT; + } + + free(str); + + return 0; +} + +int write_device_mode(bdaddr_t *bdaddr, const char *mode) +{ + char filename[PATH_MAX + 1], addr[18]; + + ba2str(bdaddr, addr); + snprintf(filename, PATH_MAX, "%s/%s/config", STORAGEDIR, addr); + + create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + + return textfile_put(filename, "mode", mode); +} + +int read_device_mode(bdaddr_t *bdaddr, char *mode, int length) +{ + char filename[PATH_MAX + 1], addr[18], *str; + + ba2str(bdaddr, addr); + snprintf(filename, PATH_MAX, "%s/%s/config", STORAGEDIR, addr); + + str = textfile_get(filename, "mode"); + 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], addr[18], str[249]; |