aboutsummaryrefslogtreecommitdiffstats
path: root/src/storage.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/storage.c')
-rw-r--r--src/storage.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/storage.c b/src/storage.c
index 793d8b6c..8762d589 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -61,17 +61,28 @@ static inline int create_filename(char *buf, size_t size,
return create_name(buf, size, STORAGEDIR, addr, name);
}
-int read_device_alias(const char *src, const char *dst, char *alias, size_t size)
+int read_device_alias(const char *src, const char *dst, uint8_t bdaddr_type,
+ char *alias, size_t size)
{
char filename[PATH_MAX + 1], *tmp;
+ char key[20];
int err;
create_name(filename, PATH_MAX, STORAGEDIR, src, "aliases");
+ /* New format: address#type */
+ snprintf(key, sizeof(key), "%17s#%hhu", dst, bdaddr_type);
+
+ tmp = textfile_get(filename, key);
+ if (tmp)
+ goto done;
+
+ /* Old format: address only */
tmp = textfile_get(filename, dst);
if (!tmp)
return -ENXIO;
+done:
err = snprintf(alias, size, "%s", tmp);
free(tmp);
@@ -79,15 +90,20 @@ int read_device_alias(const char *src, const char *dst, char *alias, size_t size
return err < 0 ? -EIO : 0;
}
-int write_device_alias(const char *src, const char *dst, const char *alias)
+int write_device_alias(const char *src, const char *dst, uint8_t bdaddr_type,
+ const char *alias)
{
char filename[PATH_MAX + 1];
+ char key[20];
create_name(filename, PATH_MAX, STORAGEDIR, src, "aliases");
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- return textfile_put(filename, dst, alias);
+ /* New format: address#type */
+ snprintf(key, sizeof(key), "%17s#%hhu", dst, bdaddr_type);
+
+ return textfile_put(filename, key, alias);
}
int write_discoverable_timeout(bdaddr_t *bdaddr, int timeout)