aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaulo Alcantara <paulo.alcantara@openbossa.org>2012-05-10 16:40:39 -0300
committerPaulo Alcantara <paulo.alcantara@openbossa.org>2012-05-22 00:41:58 -0300
commit00c9d1cd4ca1e3e8eaf0c1226c0c8fc48fa0dabe (patch)
tree3dec8053a374f32e63ef9e2089d1f33d67328c55
parent6510f97bf14b056a878eec3b57fad506453cc537 (diff)
downloadbluez-00c9d1cd4ca1e3e8eaf0c1226c0c8fc48fa0dabe.tar.gz
bluez-00c9d1cd4ca1e3e8eaf0c1226c0c8fc48fa0dabe.tar.xz
bluez-00c9d1cd4ca1e3e8eaf0c1226c0c8fc48fa0dabe.zip
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.
-rw-r--r--input/device.c6
-rw-r--r--src/adapter.c29
-rw-r--r--src/device.c3
-rw-r--r--src/event.c7
-rw-r--r--src/storage.c34
-rw-r--r--src/storage.h6
6 files changed, 65 insertions, 20 deletions
diff --git a/input/device.c b/input/device.c
index 77e77b3f..44ee1004 100644
--- a/input/device.c
+++ b/input/device.c
@@ -1084,10 +1084,11 @@ static struct input_device *input_device_new(DBusConnection *conn,
struct btd_adapter *adapter = device_get_adapter(device);
struct input_device *idev;
char name[249], src_addr[18], dst_addr[18];
+ uint8_t bdaddr_type;
idev = g_new0(struct input_device, 1);
adapter_get_address(adapter, &idev->src);
- device_get_address(device, &idev->dst, NULL);
+ device_get_address(device, &idev->dst, &bdaddr_type);
idev->device = btd_device_ref(device);
idev->path = g_strdup(path);
idev->conn = dbus_connection_ref(conn);
@@ -1096,7 +1097,8 @@ static struct input_device *input_device_new(DBusConnection *conn,
ba2str(&idev->src, src_addr);
ba2str(&idev->dst, dst_addr);
- if (read_device_name(src_addr, dst_addr, name) == 0)
+
+ if (read_device_name(src_addr, dst_addr, bdaddr_type, name) == 0)
idev->name = g_strdup(name);
if (g_dbus_register_interface(conn, idev->path, INPUT_DEVICE_INTERFACE,
diff --git a/src/adapter.c b/src/adapter.c
index 5acfdb8d..1165fb2a 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2838,16 +2838,29 @@ static gboolean pairing_is_legacy(bdaddr_t *local, bdaddr_t *peer,
return TRUE;
}
-static char *read_stored_data(bdaddr_t *local, bdaddr_t *peer, const char *file)
+static char *read_stored_data(bdaddr_t *local, bdaddr_t *peer,
+ uint8_t bdaddr_type, const char *file)
{
- char local_addr[18], peer_addr[18], filename[PATH_MAX + 1];
+ char local_addr[18], key[20], filename[PATH_MAX + 1], *str;
ba2str(local, local_addr);
- ba2str(peer, peer_addr);
create_name(filename, PATH_MAX, STORAGEDIR, local_addr, file);
- return textfile_get(filename, peer_addr);
+ memset(key, 0, sizeof(key));
+
+ /* New format: address#type */
+ ba2str(peer, key);
+ sprintf(&key[17], "#%hhu", bdaddr_type);
+
+ str = textfile_get(filename, key);
+ if (str != NULL)
+ return str;
+
+ /* Old format: address only */
+ key[17] = '\0';
+
+ return textfile_get(filename, key);
}
void adapter_update_found_devices(struct btd_adapter *adapter,
@@ -2879,7 +2892,8 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
eir_data.appearance);
if (eir_data.name != NULL && eir_data.name_complete)
- write_device_name(&adapter->bdaddr, bdaddr, eir_data.name);
+ write_device_name(&adapter->bdaddr, bdaddr, bdaddr_type,
+ eir_data.name);
dev = adapter_search_found_devices(adapter, bdaddr);
if (dev) {
@@ -2904,7 +2918,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
/* New device in the discovery session */
- name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
+ name = read_stored_data(&adapter->bdaddr, bdaddr, bdaddr_type, "names");
if (bdaddr_type == BDADDR_BREDR) {
legacy = pairing_is_legacy(&adapter->bdaddr, bdaddr, data,
@@ -2924,7 +2938,8 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
adapter_ops->confirm_name(adapter->dev_id, bdaddr, bdaddr_type,
name_known);
- alias = read_stored_data(&adapter->bdaddr, bdaddr, "aliases");
+ alias = read_stored_data(&adapter->bdaddr, bdaddr, bdaddr_type,
+ "aliases");
dev = found_device_new(bdaddr, bdaddr_type, name, alias, dev_class,
legacy, eir_data.flags);
diff --git a/src/device.c b/src/device.c
index 3a744c23..768ff31c 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1075,7 +1075,8 @@ struct btd_device *device_create(DBusConnection *conn,
device->bdaddr_type = bdaddr_type;
adapter_get_address(adapter, &src);
ba2str(&src, srcaddr);
- read_device_name(srcaddr, address, device->name);
+
+ read_device_name(srcaddr, address, bdaddr_type, device->name);
if (read_device_alias(srcaddr, address, alias, sizeof(alias)) == 0)
device->alias = g_strdup(alias);
device->trusted = read_trust(&src, address, GLOBAL_TRUST);
diff --git a/src/event.c b/src/event.c
index 8ecb942b..e453e134 100644
--- a/src/event.c
+++ b/src/event.c
@@ -319,6 +319,7 @@ void btd_event_remote_name(bdaddr_t *local, bdaddr_t *peer, char *name)
{
struct btd_adapter *adapter;
struct btd_device *device;
+ uint8_t bdaddr_type;
struct remote_dev_info *dev_info;
if (!g_utf8_validate(name, -1, NULL)) {
@@ -333,11 +334,15 @@ void btd_event_remote_name(bdaddr_t *local, bdaddr_t *peer, char *name)
g_strstrip(name);
}
- write_device_name(local, peer, name);
+
if (!get_adapter_and_device(local, peer, &adapter, &device, FALSE))
return;
+ bdaddr_type = device_get_addr_type(device);
+
+ write_device_name(local, peer, bdaddr_type, name);
+
dev_info = adapter_search_found_devices(adapter, peer);
if (dev_info) {
g_free(dev_info->name);
diff --git a/src/storage.c b/src/storage.c
index 77c3fa4e..793d8b6c 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -372,9 +372,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 bdaddr_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));
@@ -388,21 +389,40 @@ 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);
+ memset(key, 0, sizeof(key));
+
+ /* New format: address#type */
+ ba2str(peer, key);
+ sprintf(&key[17], "#%hhu", bdaddr_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 bdaddr_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);
+ memset(key, 0, sizeof(key));
+
+ /* New format: address#type */
+ snprintf(key, sizeof(key), "%17s#%hhu", dst, bdaddr_type);
+
+ str = textfile_get(filename, key);
+ if (str != NULL)
+ goto done;
+
+ /* Old format: address only */
+ key[17] = '\0';
+
+ str = textfile_get(filename, key);
if (!str)
return -ENOENT;
+done:
len = strlen(str);
if (len > HCI_MAX_NAME_LENGTH)
str[HCI_MAX_NAME_LENGTH] = '\0';
diff --git a/src/storage.h b/src/storage.h
index 5660fcfd..52b44dc7 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -42,8 +42,10 @@ int read_remote_appearance(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
uint16_t *appearance);
int write_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t class);
int read_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t *class);
-int write_device_name(bdaddr_t *local, bdaddr_t *peer, char *name);
-int read_device_name(const char *src, const char *dst, char *name);
+int write_device_name(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
+ char *name);
+int read_device_name(const char *src, const char *dst, uint8_t bdaddr_type,
+ char *name);
int write_remote_eir(bdaddr_t *local, bdaddr_t *peer, uint8_t *data,
uint8_t data_len);
int read_remote_eir(bdaddr_t *local, bdaddr_t *peer, uint8_t *data);