diff options
author | Paulo Alcantara <paulo.alcantara@openbossa.org> | 2012-07-03 17:32:04 -0300 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@intel.com> | 2012-07-05 13:33:21 +0300 |
commit | 981691c976f2f3569ccd0996d368544b2a4bb1e2 (patch) | |
tree | 077af2a52d8600ced1000b0f206dbad8c9794381 /src/storage.c | |
parent | a0f543f0eb8ee35f5cfac3b86f0a88e3f01809ff (diff) | |
download | bluez-981691c976f2f3569ccd0996d368544b2a4bb1e2.tar.gz |
storage: Store address type in "names" file
"names" file is shared between BR/EDR and BLE. Addressing types can be
either BR/EDR, BLE public or BLE random so the entries in the "names"
file did not contain enough information to distinguish which addressing
type it's supposed to be. Entries will now contain both address number,
and address type as a single key in every entry in the file.
Diffstat (limited to 'src/storage.c')
-rw-r--r-- | src/storage.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/storage.c b/src/storage.c index 17e80016c..9289e079c 100644 --- a/src/storage.c +++ b/src/storage.c @@ -359,9 +359,10 @@ int read_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t *class) return 0; } -int write_device_name(bdaddr_t *local, bdaddr_t *peer, char *name) +int write_device_name(bdaddr_t *local, bdaddr_t *peer, uint8_t peer_type, + char *name) { - char filename[PATH_MAX + 1], addr[18], str[HCI_MAX_NAME_LENGTH + 1]; + char filename[PATH_MAX + 1], key[20], str[HCI_MAX_NAME_LENGTH + 1]; int i; memset(str, 0, sizeof(str)); @@ -375,21 +376,34 @@ int write_device_name(bdaddr_t *local, bdaddr_t *peer, char *name) create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - ba2str(peer, addr); - return textfile_put(filename, addr, str); + ba2str(peer, key); + sprintf(&key[17], "#%hhu", peer_type); + + return textfile_put(filename, key, str); } -int read_device_name(const char *src, const char *dst, char *name) +int read_device_name(const char *src, const char *dst, uint8_t dst_type, + char *name) { - char filename[PATH_MAX + 1], *str; + char filename[PATH_MAX + 1], *str, key[20]; int len; create_name(filename, PATH_MAX, STORAGEDIR, src, "names"); - str = textfile_get(filename, dst); - if (!str) + snprintf(key, sizeof(key), "%17s#%hhu", dst, dst_type); + + str = textfile_get(filename, key); + if (str != NULL) + goto done; + + /* Try old format (address only) */ + key[17] = '\0'; + + str = textfile_get(filename, key); + if (str == NULL) return -ENOENT; +done: len = strlen(str); if (len > HCI_MAX_NAME_LENGTH) str[HCI_MAX_NAME_LENGTH] = '\0'; |