2012-06-14 23:03:52

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ 00/12] Store address type in BR/EDR and shared files

This patchset proposes new storage format (used currently in LE-only
files) in BR/EDR and shared files.

As the LE-only file changes _only_ occurred in the BlueZ 4.100 release,
the BlueZ 5.x release should contain the new storage format in BR/EDR and
shared files as well.

Do we also need to change BR/EDR-only files like profiles, sdp, linkkeys
and eir ?


Claudio Takahasi (1):
storage: Store address type in blocked file

Paulo Alcantara (11):
storage: Store address type in "names" file
storage: Store address type in aliases file
core: Fix reading from "aliases" and "names" file
storage: Store address type in "lastseen" file
storage: Store address type in "lastused" file
storage: Store address type in "profiles" file
storage: Store address type in "did" file
storage: Store address type in "linkkeys" file
storage: Store address type in "trusts" file
storage: Store address type in "eir" file
storage: Store address type in "sdp" file

input/device.c | 11 +-
src/adapter.c | 44 ++++++--
src/device.c | 54 +++++-----
src/event.c | 27 +++--
src/storage.c | 308 ++++++++++++++++++++++++++++++++++++++++----------------
src/storage.h | 61 +++++++----
6 files changed, 352 insertions(+), 153 deletions(-)

--
1.7.10.2



2012-06-14 23:04:04

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ 12/12] storage: Store address type in "sdp" file

---
input/device.c | 5 ++++-
src/device.c | 10 +++++++---
src/storage.c | 44 +++++++++++++++++++++++++++++++-------------
src/storage.h | 12 ++++++++----
4 files changed, 50 insertions(+), 21 deletions(-)

diff --git a/input/device.c b/input/device.c
index 62d44f7..b5b9d8a 100644
--- a/input/device.c
+++ b/input/device.c
@@ -594,6 +594,7 @@ static int hidp_add_connection(const struct input_device *idev,
struct hidp_connadd_req *req;
struct fake_hid *fake_hid;
struct fake_input *fake;
+ uint8_t bdaddr_type;
sdp_record_t *rec;
char src_addr[18], dst_addr[18];
GError *gerr = NULL;
@@ -608,7 +609,9 @@ static int hidp_add_connection(const struct input_device *idev,
ba2str(&idev->src, src_addr);
ba2str(&idev->dst, dst_addr);

- rec = fetch_record(src_addr, dst_addr, idev->handle);
+ bdaddr_type = device_get_addr_type(idev->device);
+
+ rec = fetch_record(src_addr, dst_addr, bdaddr_type, idev->handle);
if (!rec) {
error("Rejected connection from unknown device %s", dst_addr);
err = -EPERM;
diff --git a/src/device.c b/src/device.c
index 6d8e786..8bf5927 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1178,7 +1178,7 @@ static void device_remove_stored(struct btd_device *device)
device->bdaddr_type);
}

- delete_all_records(&src, &device->bdaddr);
+ delete_all_records(&src, &device->bdaddr, device->bdaddr_type);
delete_device_service(&src, &device->bdaddr, device->bdaddr_type);

if (device->blocked)
@@ -1403,7 +1403,8 @@ static void device_remove_drivers(struct btd_device *device, GSList *uuids)
if (!rec)
continue;

- delete_record(srcaddr, dstaddr, rec->handle);
+ delete_record(srcaddr, dstaddr, device->bdaddr_type,
+ rec->handle);

records = sdp_list_remove(records, rec);
sdp_record_free(rec);
@@ -1445,6 +1446,7 @@ static void update_services(struct browse_req *req, sdp_list_t *recs)
struct btd_adapter *adapter = device_get_adapter(device);
sdp_list_t *seq;
char srcaddr[18], dstaddr[18];
+ uint8_t bdaddr_type;
bdaddr_t src;

adapter_get_address(adapter, &src);
@@ -1511,7 +1513,9 @@ static void update_services(struct browse_req *req, sdp_list_t *recs)
continue;
}

- store_record(srcaddr, dstaddr, rec);
+ bdaddr_type = device_get_addr_type(device);
+
+ store_record(srcaddr, dstaddr, bdaddr_type, rec);

/* Copy record */
req->records = sdp_list_append(req->records,
diff --git a/src/storage.c b/src/storage.c
index 5148e58..ecc6559 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -894,9 +894,10 @@ int delete_entry(bdaddr_t *src, const char *storage, const char *key)
return err;
}

-int store_record(const gchar *src, const gchar *dst, sdp_record_t *rec)
+int store_record(const gchar *src, const gchar *dst, uint8_t bdaddr_type,
+ sdp_record_t *rec)
{
- char filename[PATH_MAX + 1], key[28];
+ char filename[PATH_MAX + 1], key[30];
sdp_buf_t buf;
int err, size, i;
char *str;
@@ -905,7 +906,8 @@ int store_record(const gchar *src, const gchar *dst, sdp_record_t *rec)

create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

- snprintf(key, sizeof(key), "%17s#%08X", dst, rec->handle);
+ snprintf(key, sizeof(key), "%17s#%hhu#%08X", dst, bdaddr_type,
+ rec->handle);

if (sdp_gen_record_pdu(rec, &buf) < 0)
return -1;
@@ -949,34 +951,49 @@ sdp_record_t *record_from_string(const gchar *str)


sdp_record_t *fetch_record(const gchar *src, const gchar *dst,
- const uint32_t handle)
+ uint8_t bdaddr_type, const uint32_t handle)
{
- char filename[PATH_MAX + 1], key[28], *str;
+ char filename[PATH_MAX + 1], old_key[28], key[30], *str;
sdp_record_t *rec;

create_name(filename, PATH_MAX, STORAGEDIR, src, "sdp");

- snprintf(key, sizeof(key), "%17s#%08X", dst, handle);
+ snprintf(key, sizeof(key), "%17s#%hhu#%08X", dst, bdaddr_type, handle);
+ snprintf(old_key, sizeof(old_key), "%17s#%08X", dst, handle);

str = textfile_get(filename, key);
- if (!str)
+ if (str != NULL)
+ goto done;
+
+ /* Try old format (address#handle) */
+ str = textfile_get(filename, old_key);
+ if (str == NULL)
return NULL;

+done:
rec = record_from_string(str);
free(str);

return rec;
}

-int delete_record(const gchar *src, const gchar *dst, const uint32_t handle)
+int delete_record(const gchar *src, const gchar *dst, uint8_t bdaddr_type,
+ const uint32_t handle)
{
- char filename[PATH_MAX + 1], key[28];
+ char filename[PATH_MAX + 1], old_key[28], key[30];
+ int err;

create_name(filename, PATH_MAX, STORAGEDIR, src, "sdp");

- snprintf(key, sizeof(key), "%17s#%08X", dst, handle);
+ snprintf(key, sizeof(key), "%17s#%hhu#%08X", dst, bdaddr_type, handle);
+ snprintf(old_key, sizeof(old_key), "%17s#%08X", dst, handle);

- return textfile_del(filename, key);
+ err = textfile_del(filename, key);
+ if (err < 0)
+ /* Try old format (address#handle) */
+ err = textfile_del(filename, key);
+
+ return err;
}

struct record_list {
@@ -999,7 +1016,8 @@ static void create_stored_records_from_keys(char *key, char *value,
rec_list->recs = sdp_list_append(rec_list->recs, rec);
}

-void delete_all_records(const bdaddr_t *src, const bdaddr_t *dst)
+void delete_all_records(const bdaddr_t *src, const bdaddr_t *dst,
+ uint8_t bdaddr_type)
{
sdp_list_t *records, *seq;
char srcaddr[18], dstaddr[18];
@@ -1011,7 +1029,7 @@ void delete_all_records(const bdaddr_t *src, const bdaddr_t *dst)

for (seq = records; seq; seq = seq->next) {
sdp_record_t *rec = seq->data;
- delete_record(srcaddr, dstaddr, rec->handle);
+ delete_record(srcaddr, dstaddr, bdaddr_type, rec->handle);
}

if (records)
diff --git a/src/storage.h b/src/storage.h
index 34cd662..f4e8c67 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -71,11 +71,15 @@ int write_trust(const char *src, const char *addr, uint8_t bdaddr_type,
int write_device_profiles(bdaddr_t *src, bdaddr_t *dst, uint8_t bdaddr_type,
const char *profiles);
int delete_entry(bdaddr_t *src, const char *storage, const char *key);
-int store_record(const gchar *src, const gchar *dst, sdp_record_t *rec);
+int store_record(const gchar *src, const gchar *dst, uint8_t bdaddr_type,
+ sdp_record_t *rec);
sdp_record_t *record_from_string(const gchar *str);
-sdp_record_t *fetch_record(const gchar *src, const gchar *dst, const uint32_t handle);
-int delete_record(const gchar *src, const gchar *dst, const uint32_t handle);
-void delete_all_records(const bdaddr_t *src, const bdaddr_t *dst);
+sdp_record_t *fetch_record(const gchar *src, const gchar *dst,
+ uint8_t bdaddr_type, const uint32_t handle);
+int delete_record(const gchar *src, const gchar *dst, uint8_t bdaddr_type,
+ const uint32_t handle);
+void delete_all_records(const bdaddr_t *src, const bdaddr_t *dst,
+ uint8_t bdaddr_type);
sdp_list_t *read_records(const bdaddr_t *src, const bdaddr_t *dst);
sdp_record_t *find_record_in_list(sdp_list_t *recs, const char *uuid);
int store_device_id(const gchar *src, const gchar *dst, uint8_t bdaddr_type,
--
1.7.10.2


2012-06-14 23:04:03

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ 11/12] storage: Store address type in "eir" file

---
src/event.c | 2 +-
src/storage.c | 30 +++++++++++++++++++++---------
src/storage.h | 7 ++++---
3 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/src/event.c b/src/event.c
index cf3a989..90c57e6 100644
--- a/src/event.c
+++ b/src/event.c
@@ -270,7 +270,7 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type
update_lastseen(local, peer, bdaddr_type);

if (data)
- write_remote_eir(local, peer, data, data_len);
+ write_remote_eir(local, peer, bdaddr_type, data, data_len);

adapter_update_found_devices(adapter, peer, bdaddr_type, rssi,
confirm_name, data, data_len);
diff --git a/src/storage.c b/src/storage.c
index 58c94e2..5148e58 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -430,10 +430,10 @@ done:
return 0;
}

-int write_remote_eir(bdaddr_t *local, bdaddr_t *peer, uint8_t *data,
- uint8_t data_len)
+int write_remote_eir(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
+ uint8_t *data, uint8_t data_len)
{
- char filename[PATH_MAX + 1], addr[18], str[481];
+ char filename[PATH_MAX + 1], key[20], str[481];
int i;

memset(str, 0, sizeof(str));
@@ -444,23 +444,35 @@ int write_remote_eir(bdaddr_t *local, bdaddr_t *peer, uint8_t *data,

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", bdaddr_type);
+
+ return textfile_put(filename, key, str);
}

-int read_remote_eir(bdaddr_t *local, bdaddr_t *peer, uint8_t *data)
+int read_remote_eir(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
+ uint8_t *data)
{
- char filename[PATH_MAX + 1], addr[18], *str;
+ char filename[PATH_MAX + 1], key[18], *str;
int i;

create_filename(filename, PATH_MAX, local, "eir");

- ba2str(peer, addr);
+ ba2str(peer, key);
+ sprintf(&key[17], "#%hhu", bdaddr_type);

- str = textfile_get(filename, addr);
+ 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)
return -ENOENT;

+done:
if (!data) {
free(str);
return 0;
diff --git a/src/storage.h b/src/storage.h
index e540e1b..34cd662 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -48,9 +48,10 @@ 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);
+int write_remote_eir(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
+ uint8_t *data, uint8_t data_len);
+int read_remote_eir(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
+ uint8_t *data);
int write_version_info(bdaddr_t *local, bdaddr_t *peer, uint16_t manufacturer, uint8_t lmp_ver, uint16_t lmp_subver);
int write_features_info(bdaddr_t *local, bdaddr_t *peer, unsigned char *page1, unsigned char *page2);
int read_remote_features(bdaddr_t *local, bdaddr_t *peer, unsigned char *page1, unsigned char *page2);
--
1.7.10.2


2012-06-14 23:04:02

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ 10/12] storage: Store address type in "trusts" file

---
src/device.c | 6 ++++--
src/storage.c | 41 ++++++++++++++++++++++++++++++-----------
src/storage.h | 6 ++++--
3 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/src/device.c b/src/device.c
index d879aa2..6d8e786 100644
--- a/src/device.c
+++ b/src/device.c
@@ -487,7 +487,8 @@ static DBusMessage *set_trust(DBusConnection *conn, DBusMessage *msg,
ba2str(&src, srcaddr);
ba2str(&device->bdaddr, dstaddr);

- err = write_trust(srcaddr, dstaddr, GLOBAL_TRUST, value);
+ err = write_trust(srcaddr, dstaddr, device->bdaddr_type, GLOBAL_TRUST,
+ value);
if (err < 0)
return btd_error_failed(msg, strerror(-err));

@@ -1078,7 +1079,8 @@ struct btd_device *device_create(DBusConnection *conn,
if (read_device_alias(srcaddr, address, bdaddr_type, alias,
sizeof(alias)) == 0)
device->alias = g_strdup(alias);
- device->trusted = read_trust(&src, address, GLOBAL_TRUST);
+ device->trusted = read_trust(&src, address, device->bdaddr_type,
+ GLOBAL_TRUST);

if (read_blocked(&src, &device->bdaddr, device->bdaddr_type))
device_block(conn, device, FALSE);
diff --git a/src/storage.c b/src/storage.c
index c9ff96b..58c94e2 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -748,10 +748,10 @@ static char *service_list_to_string(GSList *services)
return g_strdup(str);
}

-int write_trust(const char *src, const char *addr, const char *service,
- gboolean trust)
+int write_trust(const char *src, const char *addr, uint8_t bdaddr_type,
+ const char *service, gboolean trust)
{
- char filename[PATH_MAX + 1], *str;
+ char filename[PATH_MAX + 1], key[20], *str;
GSList *services = NULL, *match;
gboolean trusted;
int ret;
@@ -760,8 +760,15 @@ int write_trust(const char *src, const char *addr, const char *service,

create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

- str = textfile_caseget(filename, addr);
- if (str)
+ snprintf(key, sizeof(key), "%17s#%hhu", addr, bdaddr_type);
+
+ str = textfile_caseget(filename, key);
+ if (str == NULL) {
+ /* Try old format (address only) */
+ str = textfile_caseget(filename, addr);
+ if (str)
+ services = service_string_to_list(str);
+ } else
services = service_string_to_list(str);

match = g_slist_find_custom(services, service, (GCompareFunc) strcmp);
@@ -780,11 +787,14 @@ int write_trust(const char *src, const char *addr, const char *service,
services = g_slist_remove(services, match->data);

/* Remove the entry if the last trusted service was removed */
- if (!trust && !services)
- ret = textfile_casedel(filename, addr);
- else {
+ if (!trust && !services) {
+ ret = textfile_casedel(filename, key);
+ if (ret < 0)
+ /* Try old format (address only) */
+ ret = textfile_casedel(filename, addr);
+ } else {
char *new_str = service_list_to_string(services);
- ret = textfile_caseput(filename, addr, new_str);
+ ret = textfile_caseput(filename, key, new_str);
g_free(new_str);
}

@@ -795,18 +805,27 @@ int write_trust(const char *src, const char *addr, const char *service,
return ret;
}

-gboolean read_trust(const bdaddr_t *local, const char *addr, const char *service)
+gboolean read_trust(const bdaddr_t *local, const char *addr, uint8_t bdaddr_type,
+ const char *service)
{
- char filename[PATH_MAX + 1], *str;
+ char filename[PATH_MAX + 1], key[20], *str;
GSList *services;
gboolean ret;

create_filename(filename, PATH_MAX, local, "trusts");

+ snprintf(key, sizeof(key), "%17s#%hhu", addr, bdaddr_type);
+
+ str = textfile_caseget(filename, key);
+ if (str != NULL)
+ goto done;
+
+ /* Try old format (address only) */
str = textfile_caseget(filename, addr);
if (!str)
return FALSE;

+done:
services = service_string_to_list(str);

if (g_slist_find_custom(services, service, (GCompareFunc) strcmp))
diff --git a/src/storage.h b/src/storage.h
index 8ddd495..e540e1b 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -63,8 +63,10 @@ int write_link_key(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
int read_link_key(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
unsigned char *key, uint8_t *type);
ssize_t read_pin_code(bdaddr_t *local, bdaddr_t *peer, char *pin);
-gboolean read_trust(const bdaddr_t *local, const char *addr, const char *service);
-int write_trust(const char *src, const char *addr, const char *service, gboolean trust);
+gboolean read_trust(const bdaddr_t *local, const char *addr, uint8_t bdaddr_type,
+ const char *service);
+int write_trust(const char *src, const char *addr, uint8_t bdaddr_type,
+ const char *service, gboolean trust);
int write_device_profiles(bdaddr_t *src, bdaddr_t *dst, uint8_t bdaddr_type,
const char *profiles);
int delete_entry(bdaddr_t *src, const char *storage, const char *key);
--
1.7.10.2


2012-06-14 23:04:01

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ 09/12] storage: Store address type in "linkkeys" file

---
src/adapter.c | 9 +++++++--
src/device.c | 3 ++-
src/event.c | 6 +++++-
src/storage.c | 21 +++++++++++++++++----
src/storage.h | 6 ++++--
5 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index b16fd78..29a85e3 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1831,20 +1831,25 @@ static struct smp_ltk_info *get_ltk_info(const char *addr, uint8_t bdaddr_type,
static void create_stored_device_from_linkkeys(char *key, char *value,
void *user_data)
{
+ char address[18];
+ uint8_t bdaddr_type;
struct adapter_keys *keys = user_data;
struct btd_adapter *adapter = keys->adapter;
struct btd_device *device;
struct link_key_info *info;

+ if (sscanf(key, "%17s#%hhu", address, &bdaddr_type) < 2)
+ bdaddr_type = BDADDR_BREDR;
+
info = get_key_info(key, value);
if (info)
keys->keys = g_slist_append(keys->keys, info);

- if (g_slist_find_custom(adapter->devices, key,
+ if (g_slist_find_custom(adapter->devices, address,
(GCompareFunc) device_address_cmp))
return;

- device = device_create(connection, adapter, key, BDADDR_BREDR);
+ device = device_create(connection, adapter, address, bdaddr_type);
if (device) {
device_set_temporary(device, FALSE);
adapter->devices = g_slist_append(adapter->devices, device);
diff --git a/src/device.c b/src/device.c
index b606a0d..d879aa2 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1083,7 +1083,8 @@ struct btd_device *device_create(DBusConnection *conn,
if (read_blocked(&src, &device->bdaddr, device->bdaddr_type))
device_block(conn, device, FALSE);

- if (read_link_key(&src, &device->bdaddr, NULL, NULL) == 0) {
+ if (read_link_key(&src, &device->bdaddr, device->bdaddr_type, NULL,
+ NULL) == 0) {
device_set_paired(device, TRUE);
device_set_bonded(device, TRUE);
}
diff --git a/src/event.c b/src/event.c
index afbf646..cf3a989 100644
--- a/src/event.c
+++ b/src/event.c
@@ -408,6 +408,7 @@ int btd_event_link_key_notify(bdaddr_t *local, bdaddr_t *peer,
{
struct btd_adapter *adapter;
struct btd_device *device;
+ uint8_t bdaddr_type;
int ret;

if (!get_adapter_and_device(local, peer, &adapter, &device, TRUE))
@@ -415,7 +416,10 @@ int btd_event_link_key_notify(bdaddr_t *local, bdaddr_t *peer,

DBG("storing link key of type 0x%02x", key_type);

- ret = write_link_key(local, peer, key, key_type, pin_length);
+ bdaddr_type = device_get_addr_type(device);
+
+ ret = write_link_key(local, peer, bdaddr_type, key, key_type,
+ pin_length);

if (ret == 0) {
device_set_bonded(device, TRUE);
diff --git a/src/storage.c b/src/storage.c
index f8d527a..c9ff96b 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -608,9 +608,10 @@ int write_lastused_info(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
return textfile_put(filename, key, str);
}

-int write_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t type, int length)
+int write_link_key(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
+ unsigned char *key, uint8_t type, int length)
{
- char filename[PATH_MAX + 1], addr[18], str[38];
+ char filename[PATH_MAX + 1], addr[20], str[38];
int i;

memset(str, 0, sizeof(str));
@@ -623,6 +624,7 @@ int write_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t
create_file(filename, S_IRUSR | S_IWUSR);

ba2str(peer, addr);
+ sprintf(&addr[17], "#%hhu", bdaddr_type);

if (length < 0) {
char *tmp = textfile_get(filename, addr);
@@ -636,18 +638,29 @@ int write_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t
return textfile_put(filename, addr, str);
}

-int read_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t *type)
+int read_link_key(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
+ unsigned char *key, uint8_t *type)
{
- char filename[PATH_MAX + 1], addr[18], tmp[3], *str;
+ char filename[PATH_MAX + 1], addr[20], tmp[3], *str;
int i;

create_filename(filename, PATH_MAX, local, "linkkeys");

ba2str(peer, addr);
+ sprintf(&addr[17], "#%hhu", bdaddr_type);
+
+ str = textfile_get(filename, addr);
+ if (str != NULL)
+ goto done;
+
+ /* Try old format (address only) */
+ addr[17] = '\0';
+
str = textfile_get(filename, addr);
if (!str)
return -ENOENT;

+done:
if (!key) {
free(str);
return 0;
diff --git a/src/storage.h b/src/storage.h
index c7750ac..8ddd495 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -58,8 +58,10 @@ int write_lastseen_info(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
struct tm *tm);
int write_lastused_info(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
struct tm *tm);
-int write_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t type, int length);
-int read_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t *type);
+int write_link_key(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
+ unsigned char *key, uint8_t type, int length);
+int read_link_key(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
+ unsigned char *key, uint8_t *type);
ssize_t read_pin_code(bdaddr_t *local, bdaddr_t *peer, char *pin);
gboolean read_trust(const bdaddr_t *local, const char *addr, const char *service);
int write_trust(const char *src, const char *addr, const char *service, gboolean trust);
--
1.7.10.2


2012-06-14 23:03:58

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ 06/12] storage: Store address type in "lastused" file

---
src/event.c | 6 +++---
src/storage.c | 11 +++++++----
src/storage.h | 3 ++-
3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/event.c b/src/event.c
index 2c3c966..afbf646 100644
--- a/src/event.c
+++ b/src/event.c
@@ -244,7 +244,7 @@ static void update_lastseen(bdaddr_t *sba, bdaddr_t *dba, uint8_t bdaddr_type)
write_lastseen_info(sba, dba, bdaddr_type, tm);
}

-static void update_lastused(bdaddr_t *sba, bdaddr_t *dba)
+static void update_lastused(bdaddr_t *sba, bdaddr_t *dba, uint8_t bdaddr_type)
{
time_t t;
struct tm *tm;
@@ -252,7 +252,7 @@ static void update_lastused(bdaddr_t *sba, bdaddr_t *dba)
t = time(NULL);
tm = gmtime(&t);

- write_lastused_info(sba, dba, tm);
+ write_lastused_info(sba, dba, bdaddr_type, tm);
}

void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
@@ -460,7 +460,7 @@ void btd_event_conn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_typ
if (!get_adapter_and_device(local, peer, &adapter, &device, TRUE))
return;

- update_lastused(local, peer);
+ update_lastused(local, peer, bdaddr_type);

if (dev_class != NULL) {
uint32_t class = dev_class[0] | (dev_class[1] << 8) |
diff --git a/src/storage.c b/src/storage.c
index 21f7333..7c435b9 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -590,9 +590,10 @@ int write_lastseen_info(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
return textfile_put(filename, key, str);
}

-int write_lastused_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm)
+int write_lastused_info(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
+ struct tm *tm)
{
- char filename[PATH_MAX + 1], addr[18], str[24];
+ char filename[PATH_MAX + 1], key[20], str[24];

memset(str, 0, sizeof(str));
strftime(str, sizeof(str), "%Y-%m-%d %H:%M:%S %Z", tm);
@@ -601,8 +602,10 @@ int write_lastused_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm)

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", bdaddr_type);
+
+ return textfile_put(filename, key, str);
}

int write_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t type, int length)
diff --git a/src/storage.h b/src/storage.h
index 68ddac9..64bc200 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -56,7 +56,8 @@ int write_features_info(bdaddr_t *local, bdaddr_t *peer, unsigned char *page1, u
int read_remote_features(bdaddr_t *local, bdaddr_t *peer, unsigned char *page1, unsigned char *page2);
int write_lastseen_info(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
struct tm *tm);
-int write_lastused_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm);
+int write_lastused_info(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
+ struct tm *tm);
int write_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t type, int length);
int read_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t *type);
ssize_t read_pin_code(bdaddr_t *local, bdaddr_t *peer, char *pin);
--
1.7.10.2


2012-06-14 23:04:00

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ 08/12] storage: Store address type in "did" file

---
src/device.c | 7 ++++---
src/storage.c | 33 +++++++++++++++++++++++----------
src/storage.h | 4 ++--
3 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/src/device.c b/src/device.c
index 685db89..b606a0d 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1094,8 +1094,8 @@ struct btd_device *device_create(DBusConnection *conn,
device_set_bonded(device, TRUE);
}

- if (read_device_id(srcaddr, address, NULL, &vendor, &product, &version)
- == 0) {
+ if (read_device_id(srcaddr, address, bdaddr_type, NULL, &vendor,
+ &product, &version) == 0) {
device_set_vendor(device, vendor);
device_set_product(device, product);
device_set_version(device, version);
@@ -1496,7 +1496,8 @@ static void update_services(struct browse_req *req, sdp_list_t *recs)
device_set_version(device, version);

if (source || vendor || product || version)
- store_device_id(srcaddr, dstaddr, source,
+ store_device_id(srcaddr, dstaddr,
+ device->bdaddr_type, source,
vendor, product, version);
}

diff --git a/src/storage.c b/src/storage.c
index c475a40..f8d527a 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -1021,35 +1021,46 @@ sdp_record_t *find_record_in_list(sdp_list_t *recs, const char *uuid)
return NULL;
}

-int store_device_id(const gchar *src, const gchar *dst,
+int store_device_id(const gchar *src, const gchar *dst, uint8_t bdaddr_type,
const uint16_t source, const uint16_t vendor,
const uint16_t product, const uint16_t version)
{
- char filename[PATH_MAX + 1], str[20];
+ char filename[PATH_MAX + 1], key[20], str[20];

create_name(filename, PATH_MAX, STORAGEDIR, src, "did");

create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

+ snprintf(key, sizeof(key), "%17s#%hhu", dst, bdaddr_type);
+
snprintf(str, sizeof(str), "%04X %04X %04X %04X", source,
vendor, product, version);

- return textfile_put(filename, dst, str);
+ return textfile_put(filename, key, str);
}

static int read_device_id_from_did(const gchar *src, const gchar *dst,
- uint16_t *source, uint16_t *vendor,
- uint16_t *product, uint16_t *version)
+ uint8_t bdaddr_type, uint16_t *source,
+ uint16_t *vendor, uint16_t *product,
+ uint16_t *version)
{
char filename[PATH_MAX + 1];
- char *str, *vendor_str, *product_str, *version_str;
+ char key[20], *str, *vendor_str, *product_str, *version_str;

create_name(filename, PATH_MAX, STORAGEDIR, src, "did");

+ snprintf(key, sizeof(key), "%17s#%hhu", dst, bdaddr_type);
+
+ str = textfile_get(filename, key);
+ if (str != NULL)
+ goto done;
+
+ /* Try old format (address only) */
str = textfile_get(filename, dst);
if (!str)
return -ENOENT;

+done:
vendor_str = strchr(str, ' ');
if (!vendor_str) {
free(str);
@@ -1086,7 +1097,7 @@ static int read_device_id_from_did(const gchar *src, const gchar *dst,
}

int read_device_id(const gchar *srcaddr, const gchar *dstaddr,
- uint16_t *source, uint16_t *vendor,
+ uint8_t bdaddr_type, uint16_t *source, uint16_t *vendor,
uint16_t *product, uint16_t *version)
{
uint16_t lsource, lvendor, lproduct, lversion;
@@ -1095,8 +1106,9 @@ int read_device_id(const gchar *srcaddr, const gchar *dstaddr,
bdaddr_t src, dst;
int err;

- err = read_device_id_from_did(srcaddr, dstaddr, &lsource,
- vendor, product, version);
+ err = read_device_id_from_did(srcaddr, dstaddr, bdaddr_type, &lsource,
+ vendor, product,
+ version);
if (!err) {
if (lsource == 0xffff)
err = -ENOENT;
@@ -1141,7 +1153,8 @@ int read_device_id(const gchar *srcaddr, const gchar *dstaddr,
lversion = 0x0000;
}

- store_device_id(srcaddr, dstaddr, lsource, lvendor, lproduct, lversion);
+ store_device_id(srcaddr, dstaddr, lsource, bdaddr_type, lvendor,
+ lproduct, lversion);

if (err)
return err;
diff --git a/src/storage.h b/src/storage.h
index 0ac7c03..c7750ac 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -73,10 +73,10 @@ int delete_record(const gchar *src, const gchar *dst, const uint32_t handle);
void delete_all_records(const bdaddr_t *src, const bdaddr_t *dst);
sdp_list_t *read_records(const bdaddr_t *src, const bdaddr_t *dst);
sdp_record_t *find_record_in_list(sdp_list_t *recs, const char *uuid);
-int store_device_id(const gchar *src, const gchar *dst,
+int store_device_id(const gchar *src, const gchar *dst, uint8_t bdaddr_type,
const uint16_t source, const uint16_t vendor,
const uint16_t product, const uint16_t version);
-int read_device_id(const gchar *src, const gchar *dst,
+int read_device_id(const gchar *src, const gchar *dst, uint8_t bdaddr_type,
uint16_t *source, uint16_t *vendor,
uint16_t *product, uint16_t *version);
int write_device_pairable(bdaddr_t *local, gboolean mode);
--
1.7.10.2


2012-06-14 23:03:57

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ 05/12] storage: Store address type in "lastseen" file

---
src/event.c | 6 +++---
src/storage.c | 11 +++++++----
src/storage.h | 3 ++-
3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/event.c b/src/event.c
index 327625d..2c3c966 100644
--- a/src/event.c
+++ b/src/event.c
@@ -233,7 +233,7 @@ void btd_event_simple_pairing_complete(bdaddr_t *local, bdaddr_t *peer,
device_simple_pairing_complete(device, status);
}

-static void update_lastseen(bdaddr_t *sba, bdaddr_t *dba)
+static void update_lastseen(bdaddr_t *sba, bdaddr_t *dba, uint8_t bdaddr_type)
{
time_t t;
struct tm *tm;
@@ -241,7 +241,7 @@ static void update_lastseen(bdaddr_t *sba, bdaddr_t *dba)
t = time(NULL);
tm = gmtime(&t);

- write_lastseen_info(sba, dba, tm);
+ write_lastseen_info(sba, dba, bdaddr_type, tm);
}

static void update_lastused(bdaddr_t *sba, bdaddr_t *dba)
@@ -267,7 +267,7 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type
return;
}

- update_lastseen(local, peer);
+ update_lastseen(local, peer, bdaddr_type);

if (data)
write_remote_eir(local, peer, data, data_len);
diff --git a/src/storage.c b/src/storage.c
index fe863ef..21f7333 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -572,9 +572,10 @@ int read_remote_features(bdaddr_t *local, bdaddr_t *peer,
return err;
}

-int write_lastseen_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm)
+int write_lastseen_info(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
+ struct tm *tm)
{
- char filename[PATH_MAX + 1], addr[18], str[24];
+ char filename[PATH_MAX + 1], key[20], str[24];

memset(str, 0, sizeof(str));
strftime(str, sizeof(str), "%Y-%m-%d %H:%M:%S %Z", tm);
@@ -583,8 +584,10 @@ int write_lastseen_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm)

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", bdaddr_type);
+
+ return textfile_put(filename, key, str);
}

int write_lastused_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm)
diff --git a/src/storage.h b/src/storage.h
index 6d022c8..68ddac9 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -54,7 +54,8 @@ int read_remote_eir(bdaddr_t *local, bdaddr_t *peer, uint8_t *data);
int write_version_info(bdaddr_t *local, bdaddr_t *peer, uint16_t manufacturer, uint8_t lmp_ver, uint16_t lmp_subver);
int write_features_info(bdaddr_t *local, bdaddr_t *peer, unsigned char *page1, unsigned char *page2);
int read_remote_features(bdaddr_t *local, bdaddr_t *peer, unsigned char *page1, unsigned char *page2);
-int write_lastseen_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm);
+int write_lastseen_info(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
+ struct tm *tm);
int write_lastused_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm);
int write_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t type, int length);
int read_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t *type);
--
1.7.10.2


2012-06-14 23:03:59

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ 07/12] storage: Store address type in "profiles" file

---
src/adapter.c | 9 +++++++--
src/device.c | 5 +++--
src/storage.c | 11 +++++++----
src/storage.h | 3 ++-
4 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 266142f..b16fd78 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1712,15 +1712,20 @@ static const GDBusSignalTable adapter_signals[] = {
static void create_stored_device_from_profiles(char *key, char *value,
void *user_data)
{
+ char address[18];
+ uint8_t bdaddr_type;
struct btd_adapter *adapter = user_data;
GSList *list, *uuids = bt_string2list(value);
struct btd_device *device;

+ if (sscanf(key, "%17s#%hhu", address, &bdaddr_type) < 2)
+ bdaddr_type = BDADDR_BREDR;
+
if (g_slist_find_custom(adapter->devices,
- key, (GCompareFunc) device_address_cmp))
+ address, (GCompareFunc) device_address_cmp))
return;

- device = device_create(connection, adapter, key, BDADDR_BREDR);
+ device = device_create(connection, adapter, address, bdaddr_type);
if (!device)
return;

diff --git a/src/device.c b/src/device.c
index c61cfc9..685db89 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1539,12 +1539,13 @@ static void store_profiles(struct btd_device *device)
adapter_get_address(adapter, &src);

if (!device->uuids) {
- write_device_profiles(&src, &device->bdaddr, "");
+ write_device_profiles(&src, &device->bdaddr,
+ device->bdaddr_type, "");
return;
}

str = bt_list2string(device->uuids);
- write_device_profiles(&src, &device->bdaddr, str);
+ write_device_profiles(&src, &device->bdaddr, device->bdaddr_type, str);
g_free(str);
}

diff --git a/src/storage.c b/src/storage.c
index 7c435b9..c475a40 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -807,9 +807,10 @@ gboolean read_trust(const bdaddr_t *local, const char *addr, const char *service
return ret;
}

-int write_device_profiles(bdaddr_t *src, bdaddr_t *dst, const char *profiles)
+int write_device_profiles(bdaddr_t *src, bdaddr_t *dst, uint8_t bdaddr_type,
+ const char *profiles)
{
- char filename[PATH_MAX + 1], addr[18];
+ char filename[PATH_MAX + 1], key[20];

if (!profiles)
return -EINVAL;
@@ -818,8 +819,10 @@ int write_device_profiles(bdaddr_t *src, bdaddr_t *dst, const char *profiles)

create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

- ba2str(dst, addr);
- return textfile_put(filename, addr, profiles);
+ ba2str(dst, key);
+ sprintf(&key[17], "#%hhu", bdaddr_type);
+
+ return textfile_put(filename, key, profiles);
}

int delete_entry(bdaddr_t *src, const char *storage, const char *key)
diff --git a/src/storage.h b/src/storage.h
index 64bc200..0ac7c03 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -63,7 +63,8 @@ int read_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t *
ssize_t read_pin_code(bdaddr_t *local, bdaddr_t *peer, char *pin);
gboolean read_trust(const bdaddr_t *local, const char *addr, const char *service);
int write_trust(const char *src, const char *addr, const char *service, gboolean trust);
-int write_device_profiles(bdaddr_t *src, bdaddr_t *dst, const char *profiles);
+int write_device_profiles(bdaddr_t *src, bdaddr_t *dst, uint8_t bdaddr_type,
+ const char *profiles);
int delete_entry(bdaddr_t *src, const char *storage, const char *key);
int store_record(const gchar *src, const gchar *dst, sdp_record_t *rec);
sdp_record_t *record_from_string(const gchar *str);
--
1.7.10.2


2012-06-14 23:03:56

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ 04/12] storage: Store address type in blocked file

From: Claudio Takahasi <[email protected]>

---
src/device.c | 6 +++---
src/storage.c | 30 ++++++++++++++++++++----------
src/storage.h | 5 +++--
3 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/src/device.c b/src/device.c
index 9a22b21..c61cfc9 100644
--- a/src/device.c
+++ b/src/device.c
@@ -545,7 +545,7 @@ int device_block(DBusConnection *conn, struct btd_device *device,

adapter_get_address(device->adapter, &src);

- err = write_blocked(&src, &device->bdaddr, TRUE);
+ err = write_blocked(&src, &device->bdaddr, device->bdaddr_type, TRUE);
if (err < 0)
error("write_blocked(): %s (%d)", strerror(-err), -err);

@@ -577,7 +577,7 @@ int device_unblock(DBusConnection *conn, struct btd_device *device,

adapter_get_address(device->adapter, &src);

- err = write_blocked(&src, &device->bdaddr, FALSE);
+ err = write_blocked(&src, &device->bdaddr, device->bdaddr_type, FALSE);
if (err < 0)
error("write_blocked(): %s (%d)", strerror(-err), -err);

@@ -1080,7 +1080,7 @@ struct btd_device *device_create(DBusConnection *conn,
device->alias = g_strdup(alias);
device->trusted = read_trust(&src, address, GLOBAL_TRUST);

- if (read_blocked(&src, &device->bdaddr))
+ if (read_blocked(&src, &device->bdaddr, device->bdaddr_type))
device_block(conn, device, FALSE);

if (read_link_key(&src, &device->bdaddr, NULL, NULL) == 0) {
diff --git a/src/storage.c b/src/storage.c
index 36b1d0a..fe863ef 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -1177,38 +1177,48 @@ int read_device_pairable(bdaddr_t *bdaddr, gboolean *mode)
return 0;
}

-gboolean read_blocked(const bdaddr_t *local, const bdaddr_t *remote)
+gboolean read_blocked(const bdaddr_t *local, const bdaddr_t *remote,
+ uint8_t bdaddr_type)
{
- char filename[PATH_MAX + 1], *str, addr[18];
+ char filename[PATH_MAX + 1], *str, key[20];

create_filename(filename, PATH_MAX, local, "blocked");

- ba2str(remote, addr);
+ ba2str(remote, key);
+ sprintf(&key[17], "#%hhu", bdaddr_type);

- str = textfile_caseget(filename, addr);
- if (!str)
+ str = textfile_caseget(filename, key);
+ if (str != NULL)
+ goto done;
+
+ /* Try old format (address only) */
+ key[17] = '\0';
+ str = textfile_caseget(filename, key);
+ if (str == NULL)
return FALSE;

+done:
free(str);

return TRUE;
}

int write_blocked(const bdaddr_t *local, const bdaddr_t *remote,
- gboolean blocked)
+ uint8_t bdaddr_type, gboolean blocked)
{
- char filename[PATH_MAX + 1], addr[18];
+ char filename[PATH_MAX + 1], key[20];

create_filename(filename, PATH_MAX, local, "blocked");

create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

- ba2str(remote, addr);
+ ba2str(remote, key);
+ sprintf(&key[17], "#%hhu", bdaddr_type);

if (blocked == FALSE)
- return textfile_casedel(filename, addr);
+ return textfile_casedel(filename, key);

- return textfile_caseput(filename, addr, "");
+ return textfile_caseput(filename, key, "");
}

int write_device_services(const bdaddr_t *sba, const bdaddr_t *dba,
diff --git a/src/storage.h b/src/storage.h
index 43f2f21..6d022c8 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -78,9 +78,10 @@ int read_device_id(const gchar *src, const gchar *dst,
uint16_t *product, uint16_t *version);
int write_device_pairable(bdaddr_t *local, gboolean mode);
int read_device_pairable(bdaddr_t *local, gboolean *mode);
-gboolean read_blocked(const bdaddr_t *local, const bdaddr_t *remote);
+gboolean read_blocked(const bdaddr_t *local, const bdaddr_t *remote,
+ uint8_t bdaddr_type);
int write_blocked(const bdaddr_t *local, const bdaddr_t *remote,
- gboolean blocked);
+ uint8_t bdaddr_type, gboolean blocked);
int write_device_services(const bdaddr_t *sba, const bdaddr_t *dba,
uint8_t bdaddr_type, const char *services);
int delete_device_service(const bdaddr_t *sba, const bdaddr_t *dba,
--
1.7.10.2


2012-06-14 23:03:55

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ 03/12] core: Fix reading from "aliases" and "names" file

---
src/adapter.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index baa28e8..266142f 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2839,16 +2839,26 @@ 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);
+ ba2str(peer, key);
+ sprintf(&key[17], "#%hhu", bdaddr_type);
+
+ str = textfile_get(filename, key);
+ if (str != NULL)
+ return str;
+
+ /* Try old format (address only) */
+ key[17] = '\0';
+
+ return textfile_get(filename, key);
}

void adapter_update_found_devices(struct btd_adapter *adapter,
@@ -2906,7 +2916,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,
@@ -2926,7 +2936,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);
--
1.7.10.2


2012-06-14 23:03:54

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ 02/12] storage: Store address type in aliases file

---
src/device.c | 14 ++++++--------
src/storage.c | 46 +++++++++++++++++++++++++++++++++++++++-------
src/storage.h | 6 ++++--
3 files changed, 49 insertions(+), 17 deletions(-)

diff --git a/src/device.c b/src/device.c
index 09518f3..9a22b21 100644
--- a/src/device.c
+++ b/src/device.c
@@ -456,8 +456,8 @@ static DBusMessage *set_alias(DBusConnection *conn, DBusMessage *msg,
ba2str(&device->bdaddr, dstaddr);

/* Remove alias if empty string */
- err = write_device_alias(srcaddr, dstaddr,
- g_str_equal(alias, "") ? NULL : alias);
+ err = write_device_alias(srcaddr, dstaddr, device->bdaddr_type,
+ g_str_equal(alias, "") ? NULL : alias);
if (err < 0)
return btd_error_failed(msg, strerror(-err));

@@ -1075,7 +1075,8 @@ struct btd_device *device_create(DBusConnection *conn,
ba2str(&src, srcaddr);

read_device_name(srcaddr, address, bdaddr_type, device->name);
- if (read_device_alias(srcaddr, address, alias, sizeof(alias)) == 0)
+ if (read_device_alias(srcaddr, address, bdaddr_type, alias,
+ sizeof(alias)) == 0)
device->alias = g_strdup(alias);
device->trusted = read_trust(&src, address, GLOBAL_TRUST);

@@ -1156,19 +1157,16 @@ static void device_remove_stored(struct btd_device *device)
DBusConnection *conn = get_dbus_connection();

adapter_get_address(device->adapter, &src);
+
ba2str(&device->bdaddr, key);
+ sprintf(&key[17], "#%hhu", device->bdaddr_type);

- /* key: address only */
delete_entry(&src, "profiles", key);
delete_entry(&src, "trusts", key);

if (device_is_bonded(device)) {
delete_entry(&src, "linkkeys", key);
delete_entry(&src, "aliases", key);
-
- /* key: address#type */
- sprintf(&key[17], "#%hhu", device->bdaddr_type);
-
delete_entry(&src, "longtermkeys", key);

device_set_bonded(device, FALSE);
diff --git a/src/storage.c b/src/storage.c
index efdc5b0..36b1d0a 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -62,17 +62,29 @@ 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");

- tmp = textfile_get(filename, dst);
- if (!tmp)
+ snprintf(key, sizeof(key), "%17s#%hhu", dst, bdaddr_type);
+
+ tmp = textfile_get(filename, key);
+ if (tmp != NULL)
+ goto done;
+
+ /* Try old format (address only) */
+ key[17] = '\0';
+
+ tmp = textfile_get(filename, key);
+ if (tmp == NULL)
return -ENXIO;

+done:
err = snprintf(alias, size, "%s", tmp);

free(tmp);
@@ -80,15 +92,19 @@ 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);
+ snprintf(key, sizeof(key), "%17s#%hhu", dst, bdaddr_type);
+
+ return textfile_put(filename, key, alias);
}

int write_discoverable_timeout(bdaddr_t *bdaddr, int timeout)
@@ -802,11 +818,27 @@ int write_device_profiles(bdaddr_t *src, bdaddr_t *dst, const char *profiles)

int delete_entry(bdaddr_t *src, const char *storage, const char *key)
{
- char filename[PATH_MAX + 1];
+ char filename[PATH_MAX + 1], *str;
+ int err;
+
+ str = g_malloc0(strlen(key) + 1);
+
+ /* key: address#type */
+ memcpy(str, key, strlen(key));

create_filename(filename, PATH_MAX, src, storage);

- return textfile_del(filename, key);
+ err = textfile_del(filename, str);
+ if (err < 0) {
+ /* Try old format (address only) */
+ str[17] = '\0';
+
+ err = textfile_del(filename, str);
+ }
+
+ g_free(str);
+
+ return err;
}

int store_record(const gchar *src, const gchar *dst, sdp_record_t *rec)
diff --git a/src/storage.h b/src/storage.h
index 015a2a6..43f2f21 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -23,8 +23,10 @@

#include "textfile.h"

-int read_device_alias(const char *src, const char *dst, char *alias, size_t size);
-int write_device_alias(const char *src, const char *dst, const char *alias);
+int read_device_alias(const char *src, const char *dst, uint8_t bdaddr_type,
+ char *alias, size_t size);
+int write_device_alias(const char *src, const char *dst, uint8_t bdaddr_type,
+ const char *alias);
int write_discoverable_timeout(bdaddr_t *bdaddr, int timeout);
int read_discoverable_timeout(const char *src, int *timeout);
int write_pairable_timeout(bdaddr_t *bdaddr, int timeout);
--
1.7.10.2


2012-06-14 23:03:53

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ 01/12] 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.
---
input/device.c | 6 ++++--
src/adapter.c | 3 ++-
src/device.c | 3 ++-
src/event.c | 7 +++++--
src/storage.c | 30 ++++++++++++++++++++++--------
src/storage.h | 6 ++++--
6 files changed, 39 insertions(+), 16 deletions(-)

diff --git a/input/device.c b/input/device.c
index 0e3f4a9..62d44f7 100644
--- a/input/device.c
+++ b/input/device.c
@@ -1085,10 +1085,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);
@@ -1097,7 +1098,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 6e04faf..baa28e8 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2880,7 +2880,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) {
diff --git a/src/device.c b/src/device.c
index c210bcb..09518f3 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1073,7 +1073,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 ec5926f..327625d 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,13 @@ 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 17e8001..efdc5b0 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 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));
@@ -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", 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);
- if (!str)
+ snprintf(key, sizeof(key), "%17s#%hhu", dst, bdaddr_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';
diff --git a/src/storage.h b/src/storage.h
index cc00e97..015a2a6 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);
--
1.7.10.2


2012-07-05 21:15:29

by Paulo Alcantara

[permalink] [raw]
Subject: Re: [PATCH BlueZ v2 02/12] storage: Store address type in "aliases" file

Hi Johan,

From: Johan Hedberg <[email protected]>
Date: Thu, 5 Jul 2012 13:41:42 +0300

> This looks dangerous to me. Even though the only users of delete_entry()
> use addresses as the key values there's nothing about the naming of this
> function that suggests that it's only usable for key values with a very
> specific format compared to what the rest of storage.c is designed to
> support (arbitrary key values).

Agreed.

> Either the function name and/or the "key" parameter name needs to be
> changed to make this restricted use clear or then the error handling of
> old keys should be pushed to the caller side (device.c).

Ok. I think we can do something like this too:

int delete_entry(bdaddr_t *src, const char *storage, bdaddr_t *dst,
uint8_t dst_type)
{
...
...
}

So, we're going to remove an entry from a given destinate address rather than
from a very specific key format, then we can treat old and new key formats
within it.

What do you think about this ?


Paulo

2012-07-05 10:41:42

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH BlueZ v2 02/12] storage: Store address type in "aliases" file

Hi Paulo,

On Tue, Jul 03, 2012, Paulo Alcantara wrote:
> int delete_entry(bdaddr_t *src, const char *storage, const char *key)
> {
> - char filename[PATH_MAX + 1];
> + char filename[PATH_MAX + 1], old_key[18];
> + int err;
> +
> + memset(old_key, 0, sizeof(old_key));
> + memcpy(old_key, key, sizeof(old_key) - 1);
>
> create_filename(filename, PATH_MAX, src, storage);
>
> - return textfile_del(filename, key);
> + /* key: address#type */
> + err = textfile_del(filename, key);
> + if (err < 0)
> + /* old_key: address only */
> + err = textfile_del(filename, old_key);
> +
> + return err;
> }

This looks dangerous to me. Even though the only users of delete_entry()
use addresses as the key values there's nothing about the naming of this
function that suggests that it's only usable for key values with a very
specific format compared to what the rest of storage.c is designed to
support (arbitrary key values).

Either the function name and/or the "key" parameter name needs to be
changed to make this restricted use clear or then the error handling of
old keys should be pushed to the caller side (device.c).

Johan

2012-07-03 20:32:15

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ v2 12/12] storage: Store address type in "sdp" file

---
input/device.c | 5 ++++-
src/device.c | 10 +++++++---
src/storage.c | 44 +++++++++++++++++++++++++++++++-------------
src/storage.h | 12 ++++++++----
4 files changed, 50 insertions(+), 21 deletions(-)

diff --git a/input/device.c b/input/device.c
index cf4bfc4..fd34ca9 100644
--- a/input/device.c
+++ b/input/device.c
@@ -604,6 +604,7 @@ static int hidp_add_connection(const struct input_device *idev,
struct hidp_connadd_req *req;
struct fake_hid *fake_hid;
struct fake_input *fake;
+ uint8_t dst_type;
sdp_record_t *rec;
char src_addr[18], dst_addr[18];
GError *gerr = NULL;
@@ -618,7 +619,9 @@ static int hidp_add_connection(const struct input_device *idev,
ba2str(&idev->src, src_addr);
ba2str(&idev->dst, dst_addr);

- rec = fetch_record(src_addr, dst_addr, idev->handle);
+ dst_type = device_get_addr_type(idev->device);
+
+ rec = fetch_record(src_addr, dst_addr, dst_type, idev->handle);
if (!rec) {
error("Rejected connection from unknown device %s", dst_addr);
err = -EPERM;
diff --git a/src/device.c b/src/device.c
index 6d8e786..6374f06 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1178,7 +1178,7 @@ static void device_remove_stored(struct btd_device *device)
device->bdaddr_type);
}

- delete_all_records(&src, &device->bdaddr);
+ delete_all_records(&src, &device->bdaddr, device->bdaddr_type);
delete_device_service(&src, &device->bdaddr, device->bdaddr_type);

if (device->blocked)
@@ -1403,7 +1403,8 @@ static void device_remove_drivers(struct btd_device *device, GSList *uuids)
if (!rec)
continue;

- delete_record(srcaddr, dstaddr, rec->handle);
+ delete_record(srcaddr, dstaddr, device->bdaddr_type,
+ rec->handle);

records = sdp_list_remove(records, rec);
sdp_record_free(rec);
@@ -1445,6 +1446,7 @@ static void update_services(struct browse_req *req, sdp_list_t *recs)
struct btd_adapter *adapter = device_get_adapter(device);
sdp_list_t *seq;
char srcaddr[18], dstaddr[18];
+ uint8_t dst_type;
bdaddr_t src;

adapter_get_address(adapter, &src);
@@ -1511,7 +1513,9 @@ static void update_services(struct browse_req *req, sdp_list_t *recs)
continue;
}

- store_record(srcaddr, dstaddr, rec);
+ dst_type = device_get_addr_type(device);
+
+ store_record(srcaddr, dstaddr, dst_type, rec);

/* Copy record */
req->records = sdp_list_append(req->records,
diff --git a/src/storage.c b/src/storage.c
index 0cd6c42..928f14f 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -888,9 +888,10 @@ int delete_entry(bdaddr_t *src, const char *storage, const char *key)
return err;
}

-int store_record(const gchar *src, const gchar *dst, sdp_record_t *rec)
+int store_record(const gchar *src, const gchar *dst, uint8_t dst_type,
+ sdp_record_t *rec)
{
- char filename[PATH_MAX + 1], key[28];
+ char filename[PATH_MAX + 1], key[30];
sdp_buf_t buf;
int err, size, i;
char *str;
@@ -899,7 +900,8 @@ int store_record(const gchar *src, const gchar *dst, sdp_record_t *rec)

create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

- snprintf(key, sizeof(key), "%17s#%08X", dst, rec->handle);
+ snprintf(key, sizeof(key), "%17s#%hhu#%08X", dst, dst_type,
+ rec->handle);

if (sdp_gen_record_pdu(rec, &buf) < 0)
return -1;
@@ -943,34 +945,49 @@ sdp_record_t *record_from_string(const gchar *str)


sdp_record_t *fetch_record(const gchar *src, const gchar *dst,
- const uint32_t handle)
+ uint8_t dst_type, const uint32_t handle)
{
- char filename[PATH_MAX + 1], key[28], *str;
+ char filename[PATH_MAX + 1], old_key[28], key[30], *str;
sdp_record_t *rec;

create_name(filename, PATH_MAX, STORAGEDIR, src, "sdp");

- snprintf(key, sizeof(key), "%17s#%08X", dst, handle);
+ snprintf(key, sizeof(key), "%17s#%hhu#%08X", dst, dst_type, handle);
+ snprintf(old_key, sizeof(old_key), "%17s#%08X", dst, handle);

str = textfile_get(filename, key);
- if (!str)
+ if (str != NULL)
+ goto done;
+
+ /* Try old format (address#handle) */
+ str = textfile_get(filename, old_key);
+ if (str == NULL)
return NULL;

+done:
rec = record_from_string(str);
free(str);

return rec;
}

-int delete_record(const gchar *src, const gchar *dst, const uint32_t handle)
+int delete_record(const gchar *src, const gchar *dst, uint8_t dst_type,
+ const uint32_t handle)
{
- char filename[PATH_MAX + 1], key[28];
+ char filename[PATH_MAX + 1], old_key[28], key[30];
+ int err;

create_name(filename, PATH_MAX, STORAGEDIR, src, "sdp");

- snprintf(key, sizeof(key), "%17s#%08X", dst, handle);
+ snprintf(key, sizeof(key), "%17s#%hhu#%08X", dst, dst_type, handle);
+ snprintf(old_key, sizeof(old_key), "%17s#%08X", dst, handle);

- return textfile_del(filename, key);
+ err = textfile_del(filename, key);
+ if (err < 0)
+ /* Try old format (address#handle) */
+ err = textfile_del(filename, key);
+
+ return err;
}

struct record_list {
@@ -993,7 +1010,8 @@ static void create_stored_records_from_keys(char *key, char *value,
rec_list->recs = sdp_list_append(rec_list->recs, rec);
}

-void delete_all_records(const bdaddr_t *src, const bdaddr_t *dst)
+void delete_all_records(const bdaddr_t *src, const bdaddr_t *dst,
+ uint8_t dst_type)
{
sdp_list_t *records, *seq;
char srcaddr[18], dstaddr[18];
@@ -1005,7 +1023,7 @@ void delete_all_records(const bdaddr_t *src, const bdaddr_t *dst)

for (seq = records; seq; seq = seq->next) {
sdp_record_t *rec = seq->data;
- delete_record(srcaddr, dstaddr, rec->handle);
+ delete_record(srcaddr, dstaddr, dst_type, rec->handle);
}

if (records)
diff --git a/src/storage.h b/src/storage.h
index f982818..dcd2572 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -71,11 +71,15 @@ int write_trust(const char *src, const char *addr, uint8_t addr_type,
int write_device_profiles(bdaddr_t *src, bdaddr_t *dst, uint8_t dst_type,
const char *profiles);
int delete_entry(bdaddr_t *src, const char *storage, const char *key);
-int store_record(const gchar *src, const gchar *dst, sdp_record_t *rec);
+int store_record(const gchar *src, const gchar *dst, uint8_t dst_type,
+ sdp_record_t *rec);
sdp_record_t *record_from_string(const gchar *str);
-sdp_record_t *fetch_record(const gchar *src, const gchar *dst, const uint32_t handle);
-int delete_record(const gchar *src, const gchar *dst, const uint32_t handle);
-void delete_all_records(const bdaddr_t *src, const bdaddr_t *dst);
+sdp_record_t *fetch_record(const gchar *src, const gchar *dst,
+ uint8_t dst_type, const uint32_t handle);
+int delete_record(const gchar *src, const gchar *dst, uint8_t dst_type,
+ const uint32_t handle);
+void delete_all_records(const bdaddr_t *src, const bdaddr_t *dst,
+ uint8_t dst_type);
sdp_list_t *read_records(const bdaddr_t *src, const bdaddr_t *dst);
sdp_record_t *find_record_in_list(sdp_list_t *recs, const char *uuid);
int store_device_id(const gchar *src, const gchar *dst, uint8_t dst_type,
--
1.7.9.5


2012-07-03 20:32:14

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ v2 11/12] storage: Store address type in "eir" file

---
src/event.c | 2 +-
src/storage.c | 30 +++++++++++++++++++++---------
src/storage.h | 7 ++++---
3 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/src/event.c b/src/event.c
index 002639f..1586293 100644
--- a/src/event.c
+++ b/src/event.c
@@ -270,7 +270,7 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type
update_lastseen(local, peer, bdaddr_type);

if (data)
- write_remote_eir(local, peer, data, data_len);
+ write_remote_eir(local, peer, bdaddr_type, data, data_len);

adapter_update_found_devices(adapter, peer, bdaddr_type, rssi,
confirm_name, data, data_len);
diff --git a/src/storage.c b/src/storage.c
index 96af0e4..0cd6c42 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -430,10 +430,10 @@ done:
return 0;
}

-int write_remote_eir(bdaddr_t *local, bdaddr_t *peer, uint8_t *data,
- uint8_t data_len)
+int write_remote_eir(bdaddr_t *local, bdaddr_t *peer, uint8_t peer_type,
+ uint8_t *data, uint8_t data_len)
{
- char filename[PATH_MAX + 1], addr[18], str[481];
+ char filename[PATH_MAX + 1], key[20], str[481];
int i;

memset(str, 0, sizeof(str));
@@ -444,23 +444,35 @@ int write_remote_eir(bdaddr_t *local, bdaddr_t *peer, uint8_t *data,

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_remote_eir(bdaddr_t *local, bdaddr_t *peer, uint8_t *data)
+int read_remote_eir(bdaddr_t *local, bdaddr_t *peer, uint8_t peer_type,
+ uint8_t *data)
{
- char filename[PATH_MAX + 1], addr[18], *str;
+ char filename[PATH_MAX + 1], key[18], *str;
int i;

create_filename(filename, PATH_MAX, local, "eir");

- ba2str(peer, addr);
+ ba2str(peer, key);
+ sprintf(&key[17], "#%hhu", peer_type);

- str = textfile_get(filename, addr);
+ 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)
return -ENOENT;

+done:
if (!data) {
free(str);
return 0;
diff --git a/src/storage.h b/src/storage.h
index 72c752f..f982818 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -48,9 +48,10 @@ int write_device_name(bdaddr_t *local, bdaddr_t *peer, uint8_t peer_type,
char *name);
int read_device_name(const char *src, const char *dst, uint8_t dst_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);
+int write_remote_eir(bdaddr_t *local, bdaddr_t *peer, uint8_t peer_type,
+ uint8_t *data, uint8_t data_len);
+int read_remote_eir(bdaddr_t *local, bdaddr_t *peer, uint8_t peer_type,
+ uint8_t *data);
int write_version_info(bdaddr_t *local, bdaddr_t *peer, uint16_t manufacturer, uint8_t lmp_ver, uint16_t lmp_subver);
int write_features_info(bdaddr_t *local, bdaddr_t *peer, unsigned char *page1, unsigned char *page2);
int read_remote_features(bdaddr_t *local, bdaddr_t *peer, unsigned char *page1, unsigned char *page2);
--
1.7.9.5


2012-07-03 20:32:13

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ v2 10/12] storage: Store address type in "trusts" file

---
src/device.c | 6 ++++--
src/storage.c | 41 ++++++++++++++++++++++++++++++-----------
src/storage.h | 6 ++++--
3 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/src/device.c b/src/device.c
index d879aa2..6d8e786 100644
--- a/src/device.c
+++ b/src/device.c
@@ -487,7 +487,8 @@ static DBusMessage *set_trust(DBusConnection *conn, DBusMessage *msg,
ba2str(&src, srcaddr);
ba2str(&device->bdaddr, dstaddr);

- err = write_trust(srcaddr, dstaddr, GLOBAL_TRUST, value);
+ err = write_trust(srcaddr, dstaddr, device->bdaddr_type, GLOBAL_TRUST,
+ value);
if (err < 0)
return btd_error_failed(msg, strerror(-err));

@@ -1078,7 +1079,8 @@ struct btd_device *device_create(DBusConnection *conn,
if (read_device_alias(srcaddr, address, bdaddr_type, alias,
sizeof(alias)) == 0)
device->alias = g_strdup(alias);
- device->trusted = read_trust(&src, address, GLOBAL_TRUST);
+ device->trusted = read_trust(&src, address, device->bdaddr_type,
+ GLOBAL_TRUST);

if (read_blocked(&src, &device->bdaddr, device->bdaddr_type))
device_block(conn, device, FALSE);
diff --git a/src/storage.c b/src/storage.c
index 0be071d..96af0e4 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -748,10 +748,10 @@ static char *service_list_to_string(GSList *services)
return g_strdup(str);
}

-int write_trust(const char *src, const char *addr, const char *service,
- gboolean trust)
+int write_trust(const char *src, const char *addr, uint8_t addr_type,
+ const char *service, gboolean trust)
{
- char filename[PATH_MAX + 1], *str;
+ char filename[PATH_MAX + 1], key[20], *str;
GSList *services = NULL, *match;
gboolean trusted;
int ret;
@@ -760,8 +760,15 @@ int write_trust(const char *src, const char *addr, const char *service,

create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

- str = textfile_caseget(filename, addr);
- if (str)
+ snprintf(key, sizeof(key), "%17s#%hhu", addr, addr_type);
+
+ str = textfile_caseget(filename, key);
+ if (str == NULL) {
+ /* Try old format (address only) */
+ str = textfile_caseget(filename, addr);
+ if (str)
+ services = service_string_to_list(str);
+ } else
services = service_string_to_list(str);

match = g_slist_find_custom(services, service, (GCompareFunc) strcmp);
@@ -780,11 +787,14 @@ int write_trust(const char *src, const char *addr, const char *service,
services = g_slist_remove(services, match->data);

/* Remove the entry if the last trusted service was removed */
- if (!trust && !services)
- ret = textfile_casedel(filename, addr);
- else {
+ if (!trust && !services) {
+ ret = textfile_casedel(filename, key);
+ if (ret < 0)
+ /* Try old format (address only) */
+ ret = textfile_casedel(filename, addr);
+ } else {
char *new_str = service_list_to_string(services);
- ret = textfile_caseput(filename, addr, new_str);
+ ret = textfile_caseput(filename, key, new_str);
g_free(new_str);
}

@@ -795,18 +805,27 @@ int write_trust(const char *src, const char *addr, const char *service,
return ret;
}

-gboolean read_trust(const bdaddr_t *local, const char *addr, const char *service)
+gboolean read_trust(const bdaddr_t *local, const char *addr, uint8_t addr_type,
+ const char *service)
{
- char filename[PATH_MAX + 1], *str;
+ char filename[PATH_MAX + 1], key[20], *str;
GSList *services;
gboolean ret;

create_filename(filename, PATH_MAX, local, "trusts");

+ snprintf(key, sizeof(key), "%17s#%hhu", addr, addr_type);
+
+ str = textfile_caseget(filename, key);
+ if (str != NULL)
+ goto done;
+
+ /* Try old format (address only) */
str = textfile_caseget(filename, addr);
if (!str)
return FALSE;

+done:
services = service_string_to_list(str);

if (g_slist_find_custom(services, service, (GCompareFunc) strcmp))
diff --git a/src/storage.h b/src/storage.h
index 6fb9a2f..72c752f 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -63,8 +63,10 @@ int write_link_key(bdaddr_t *local, bdaddr_t *peer, uint8_t peer_type,
int read_link_key(bdaddr_t *local, bdaddr_t *peer, uint8_t peer_type,
unsigned char *key, uint8_t *type);
ssize_t read_pin_code(bdaddr_t *local, bdaddr_t *peer, char *pin);
-gboolean read_trust(const bdaddr_t *local, const char *addr, const char *service);
-int write_trust(const char *src, const char *addr, const char *service, gboolean trust);
+gboolean read_trust(const bdaddr_t *local, const char *addr, uint8_t addr_type,
+ const char *service);
+int write_trust(const char *src, const char *addr, uint8_t addr_type,
+ const char *service, gboolean trust);
int write_device_profiles(bdaddr_t *src, bdaddr_t *dst, uint8_t dst_type,
const char *profiles);
int delete_entry(bdaddr_t *src, const char *storage, const char *key);
--
1.7.9.5


2012-07-03 20:32:12

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ v2 09/12] storage: Store address type in "linkkeys" file

---
src/adapter.c | 9 +++++++--
src/device.c | 3 ++-
src/event.c | 6 +++++-
src/storage.c | 21 +++++++++++++++++----
src/storage.h | 6 ++++--
5 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 32412a8..f9075aa 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1831,20 +1831,25 @@ static struct smp_ltk_info *get_ltk_info(const char *addr, uint8_t bdaddr_type,
static void create_stored_device_from_linkkeys(char *key, char *value,
void *user_data)
{
+ char address[18];
+ uint8_t bdaddr_type;
struct adapter_keys *keys = user_data;
struct btd_adapter *adapter = keys->adapter;
struct btd_device *device;
struct link_key_info *info;

+ if (sscanf(key, "%17s#%hhu", address, &bdaddr_type) < 2)
+ bdaddr_type = BDADDR_BREDR;
+
info = get_key_info(key, value);
if (info)
keys->keys = g_slist_append(keys->keys, info);

- if (g_slist_find_custom(adapter->devices, key,
+ if (g_slist_find_custom(adapter->devices, address,
(GCompareFunc) device_address_cmp))
return;

- device = device_create(connection, adapter, key, BDADDR_BREDR);
+ device = device_create(connection, adapter, address, bdaddr_type);
if (device) {
device_set_temporary(device, FALSE);
adapter->devices = g_slist_append(adapter->devices, device);
diff --git a/src/device.c b/src/device.c
index b606a0d..d879aa2 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1083,7 +1083,8 @@ struct btd_device *device_create(DBusConnection *conn,
if (read_blocked(&src, &device->bdaddr, device->bdaddr_type))
device_block(conn, device, FALSE);

- if (read_link_key(&src, &device->bdaddr, NULL, NULL) == 0) {
+ if (read_link_key(&src, &device->bdaddr, device->bdaddr_type, NULL,
+ NULL) == 0) {
device_set_paired(device, TRUE);
device_set_bonded(device, TRUE);
}
diff --git a/src/event.c b/src/event.c
index 9168013..002639f 100644
--- a/src/event.c
+++ b/src/event.c
@@ -408,6 +408,7 @@ int btd_event_link_key_notify(bdaddr_t *local, bdaddr_t *peer,
{
struct btd_adapter *adapter;
struct btd_device *device;
+ uint8_t peer_type;
int ret;

if (!get_adapter_and_device(local, peer, &adapter, &device, TRUE))
@@ -415,7 +416,10 @@ int btd_event_link_key_notify(bdaddr_t *local, bdaddr_t *peer,

DBG("storing link key of type 0x%02x", key_type);

- ret = write_link_key(local, peer, key, key_type, pin_length);
+ peer_type = device_get_addr_type(device);
+
+ ret = write_link_key(local, peer, peer_type, key, key_type,
+ pin_length);

if (ret == 0) {
device_set_bonded(device, TRUE);
diff --git a/src/storage.c b/src/storage.c
index ee35b13..0be071d 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -608,9 +608,10 @@ int write_lastused_info(bdaddr_t *local, bdaddr_t *peer, uint8_t peer_type,
return textfile_put(filename, key, str);
}

-int write_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t type, int length)
+int write_link_key(bdaddr_t *local, bdaddr_t *peer, uint8_t peer_type,
+ unsigned char *key, uint8_t type, int length)
{
- char filename[PATH_MAX + 1], addr[18], str[38];
+ char filename[PATH_MAX + 1], addr[20], str[38];
int i;

memset(str, 0, sizeof(str));
@@ -623,6 +624,7 @@ int write_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t
create_file(filename, S_IRUSR | S_IWUSR);

ba2str(peer, addr);
+ sprintf(&addr[17], "#%hhu", peer_type);

if (length < 0) {
char *tmp = textfile_get(filename, addr);
@@ -636,18 +638,29 @@ int write_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t
return textfile_put(filename, addr, str);
}

-int read_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t *type)
+int read_link_key(bdaddr_t *local, bdaddr_t *peer, uint8_t peer_type,
+ unsigned char *key, uint8_t *type)
{
- char filename[PATH_MAX + 1], addr[18], tmp[3], *str;
+ char filename[PATH_MAX + 1], addr[20], tmp[3], *str;
int i;

create_filename(filename, PATH_MAX, local, "linkkeys");

ba2str(peer, addr);
+ sprintf(&addr[17], "#%hhu", peer_type);
+
+ str = textfile_get(filename, addr);
+ if (str != NULL)
+ goto done;
+
+ /* Try old format (address only) */
+ addr[17] = '\0';
+
str = textfile_get(filename, addr);
if (!str)
return -ENOENT;

+done:
if (!key) {
free(str);
return 0;
diff --git a/src/storage.h b/src/storage.h
index 7455be5..6fb9a2f 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -58,8 +58,10 @@ int write_lastseen_info(bdaddr_t *local, bdaddr_t *peer, uint8_t peer_type,
struct tm *tm);
int write_lastused_info(bdaddr_t *local, bdaddr_t *peer, uint8_t peer_type,
struct tm *tm);
-int write_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t type, int length);
-int read_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t *type);
+int write_link_key(bdaddr_t *local, bdaddr_t *peer, uint8_t peer_type,
+ unsigned char *key, uint8_t type, int length);
+int read_link_key(bdaddr_t *local, bdaddr_t *peer, uint8_t peer_type,
+ unsigned char *key, uint8_t *type);
ssize_t read_pin_code(bdaddr_t *local, bdaddr_t *peer, char *pin);
gboolean read_trust(const bdaddr_t *local, const char *addr, const char *service);
int write_trust(const char *src, const char *addr, const char *service, gboolean trust);
--
1.7.9.5


2012-07-03 20:32:11

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ v2 08/12] storage: Store address type in "did" file

---
src/device.c | 7 ++++---
src/storage.c | 33 +++++++++++++++++++++++----------
src/storage.h | 4 ++--
3 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/src/device.c b/src/device.c
index 685db89..b606a0d 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1094,8 +1094,8 @@ struct btd_device *device_create(DBusConnection *conn,
device_set_bonded(device, TRUE);
}

- if (read_device_id(srcaddr, address, NULL, &vendor, &product, &version)
- == 0) {
+ if (read_device_id(srcaddr, address, bdaddr_type, NULL, &vendor,
+ &product, &version) == 0) {
device_set_vendor(device, vendor);
device_set_product(device, product);
device_set_version(device, version);
@@ -1496,7 +1496,8 @@ static void update_services(struct browse_req *req, sdp_list_t *recs)
device_set_version(device, version);

if (source || vendor || product || version)
- store_device_id(srcaddr, dstaddr, source,
+ store_device_id(srcaddr, dstaddr,
+ device->bdaddr_type, source,
vendor, product, version);
}

diff --git a/src/storage.c b/src/storage.c
index f7a573f..ee35b13 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -1015,35 +1015,46 @@ sdp_record_t *find_record_in_list(sdp_list_t *recs, const char *uuid)
return NULL;
}

-int store_device_id(const gchar *src, const gchar *dst,
+int store_device_id(const gchar *src, const gchar *dst, uint8_t dst_type,
const uint16_t source, const uint16_t vendor,
const uint16_t product, const uint16_t version)
{
- char filename[PATH_MAX + 1], str[20];
+ char filename[PATH_MAX + 1], key[20], str[20];

create_name(filename, PATH_MAX, STORAGEDIR, src, "did");

create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

+ snprintf(key, sizeof(key), "%17s#%hhu", dst, dst_type);
+
snprintf(str, sizeof(str), "%04X %04X %04X %04X", source,
vendor, product, version);

- return textfile_put(filename, dst, str);
+ return textfile_put(filename, key, str);
}

static int read_device_id_from_did(const gchar *src, const gchar *dst,
- uint16_t *source, uint16_t *vendor,
- uint16_t *product, uint16_t *version)
+ uint8_t dst_type, uint16_t *source,
+ uint16_t *vendor, uint16_t *product,
+ uint16_t *version)
{
char filename[PATH_MAX + 1];
- char *str, *vendor_str, *product_str, *version_str;
+ char key[20], *str, *vendor_str, *product_str, *version_str;

create_name(filename, PATH_MAX, STORAGEDIR, src, "did");

+ snprintf(key, sizeof(key), "%17s#%hhu", dst, dst_type);
+
+ str = textfile_get(filename, key);
+ if (str != NULL)
+ goto done;
+
+ /* Try old format (address only) */
str = textfile_get(filename, dst);
if (!str)
return -ENOENT;

+done:
vendor_str = strchr(str, ' ');
if (!vendor_str) {
free(str);
@@ -1080,7 +1091,7 @@ static int read_device_id_from_did(const gchar *src, const gchar *dst,
}

int read_device_id(const gchar *srcaddr, const gchar *dstaddr,
- uint16_t *source, uint16_t *vendor,
+ uint8_t dst_type, uint16_t *source, uint16_t *vendor,
uint16_t *product, uint16_t *version)
{
uint16_t lsource, lvendor, lproduct, lversion;
@@ -1089,8 +1100,9 @@ int read_device_id(const gchar *srcaddr, const gchar *dstaddr,
bdaddr_t src, dst;
int err;

- err = read_device_id_from_did(srcaddr, dstaddr, &lsource,
- vendor, product, version);
+ err = read_device_id_from_did(srcaddr, dstaddr, dst_type, &lsource,
+ vendor, product,
+ version);
if (!err) {
if (lsource == 0xffff)
err = -ENOENT;
@@ -1135,7 +1147,8 @@ int read_device_id(const gchar *srcaddr, const gchar *dstaddr,
lversion = 0x0000;
}

- store_device_id(srcaddr, dstaddr, lsource, lvendor, lproduct, lversion);
+ store_device_id(srcaddr, dstaddr, dst_type, lsource, lvendor,
+ lproduct, lversion);

if (err)
return err;
diff --git a/src/storage.h b/src/storage.h
index a196f04..7455be5 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -73,10 +73,10 @@ int delete_record(const gchar *src, const gchar *dst, const uint32_t handle);
void delete_all_records(const bdaddr_t *src, const bdaddr_t *dst);
sdp_list_t *read_records(const bdaddr_t *src, const bdaddr_t *dst);
sdp_record_t *find_record_in_list(sdp_list_t *recs, const char *uuid);
-int store_device_id(const gchar *src, const gchar *dst,
+int store_device_id(const gchar *src, const gchar *dst, uint8_t dst_type,
const uint16_t source, const uint16_t vendor,
const uint16_t product, const uint16_t version);
-int read_device_id(const gchar *src, const gchar *dst,
+int read_device_id(const gchar *src, const gchar *dst, uint8_t dst_type,
uint16_t *source, uint16_t *vendor,
uint16_t *product, uint16_t *version);
int write_device_pairable(bdaddr_t *local, gboolean mode);
--
1.7.9.5


2012-07-03 20:32:10

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ v2 07/12] storage: Store address type in "profiles" file

---
src/adapter.c | 9 +++++++--
src/device.c | 5 +++--
src/storage.c | 11 +++++++----
src/storage.h | 3 ++-
4 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index f6095ed..32412a8 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1712,15 +1712,20 @@ static const GDBusSignalTable adapter_signals[] = {
static void create_stored_device_from_profiles(char *key, char *value,
void *user_data)
{
+ char address[18];
+ uint8_t bdaddr_type;
struct btd_adapter *adapter = user_data;
GSList *list, *uuids = bt_string2list(value);
struct btd_device *device;

+ if (sscanf(key, "%17s#%hhu", address, &bdaddr_type) < 2)
+ bdaddr_type = BDADDR_BREDR;
+
if (g_slist_find_custom(adapter->devices,
- key, (GCompareFunc) device_address_cmp))
+ address, (GCompareFunc) device_address_cmp))
return;

- device = device_create(connection, adapter, key, BDADDR_BREDR);
+ device = device_create(connection, adapter, address, bdaddr_type);
if (!device)
return;

diff --git a/src/device.c b/src/device.c
index c61cfc9..685db89 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1539,12 +1539,13 @@ static void store_profiles(struct btd_device *device)
adapter_get_address(adapter, &src);

if (!device->uuids) {
- write_device_profiles(&src, &device->bdaddr, "");
+ write_device_profiles(&src, &device->bdaddr,
+ device->bdaddr_type, "");
return;
}

str = bt_list2string(device->uuids);
- write_device_profiles(&src, &device->bdaddr, str);
+ write_device_profiles(&src, &device->bdaddr, device->bdaddr_type, str);
g_free(str);
}

diff --git a/src/storage.c b/src/storage.c
index 8776cb8..f7a573f 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -807,9 +807,10 @@ gboolean read_trust(const bdaddr_t *local, const char *addr, const char *service
return ret;
}

-int write_device_profiles(bdaddr_t *src, bdaddr_t *dst, const char *profiles)
+int write_device_profiles(bdaddr_t *src, bdaddr_t *dst, uint8_t dst_type,
+ const char *profiles)
{
- char filename[PATH_MAX + 1], addr[18];
+ char filename[PATH_MAX + 1], key[20];

if (!profiles)
return -EINVAL;
@@ -818,8 +819,10 @@ int write_device_profiles(bdaddr_t *src, bdaddr_t *dst, const char *profiles)

create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

- ba2str(dst, addr);
- return textfile_put(filename, addr, profiles);
+ ba2str(dst, key);
+ sprintf(&key[17], "#%hhu", dst_type);
+
+ return textfile_put(filename, key, profiles);
}

int delete_entry(bdaddr_t *src, const char *storage, const char *key)
diff --git a/src/storage.h b/src/storage.h
index f56726c..a196f04 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -63,7 +63,8 @@ int read_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t *
ssize_t read_pin_code(bdaddr_t *local, bdaddr_t *peer, char *pin);
gboolean read_trust(const bdaddr_t *local, const char *addr, const char *service);
int write_trust(const char *src, const char *addr, const char *service, gboolean trust);
-int write_device_profiles(bdaddr_t *src, bdaddr_t *dst, const char *profiles);
+int write_device_profiles(bdaddr_t *src, bdaddr_t *dst, uint8_t dst_type,
+ const char *profiles);
int delete_entry(bdaddr_t *src, const char *storage, const char *key);
int store_record(const gchar *src, const gchar *dst, sdp_record_t *rec);
sdp_record_t *record_from_string(const gchar *str);
--
1.7.9.5


2012-07-03 20:32:09

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ v2 06/12] storage: Store address type in "lastused" file

---
src/event.c | 6 +++---
src/storage.c | 11 +++++++----
src/storage.h | 3 ++-
3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/event.c b/src/event.c
index 12eb9d9..9168013 100644
--- a/src/event.c
+++ b/src/event.c
@@ -244,7 +244,7 @@ static void update_lastseen(bdaddr_t *sba, bdaddr_t *dba, uint8_t dba_type)
write_lastseen_info(sba, dba, dba_type, tm);
}

-static void update_lastused(bdaddr_t *sba, bdaddr_t *dba)
+static void update_lastused(bdaddr_t *sba, bdaddr_t *dba, uint8_t dba_type)
{
time_t t;
struct tm *tm;
@@ -252,7 +252,7 @@ static void update_lastused(bdaddr_t *sba, bdaddr_t *dba)
t = time(NULL);
tm = gmtime(&t);

- write_lastused_info(sba, dba, tm);
+ write_lastused_info(sba, dba, dba_type, tm);
}

void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
@@ -460,7 +460,7 @@ void btd_event_conn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_typ
if (!get_adapter_and_device(local, peer, &adapter, &device, TRUE))
return;

- update_lastused(local, peer);
+ update_lastused(local, peer, bdaddr_type);

if (dev_class != NULL) {
uint32_t class = dev_class[0] | (dev_class[1] << 8) |
diff --git a/src/storage.c b/src/storage.c
index e0be45b..8776cb8 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -590,9 +590,10 @@ int write_lastseen_info(bdaddr_t *local, bdaddr_t *peer, uint8_t peer_type,
return textfile_put(filename, key, str);
}

-int write_lastused_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm)
+int write_lastused_info(bdaddr_t *local, bdaddr_t *peer, uint8_t peer_type,
+ struct tm *tm)
{
- char filename[PATH_MAX + 1], addr[18], str[24];
+ char filename[PATH_MAX + 1], key[20], str[24];

memset(str, 0, sizeof(str));
strftime(str, sizeof(str), "%Y-%m-%d %H:%M:%S %Z", tm);
@@ -601,8 +602,10 @@ int write_lastused_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm)

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 write_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t type, int length)
diff --git a/src/storage.h b/src/storage.h
index a5816f6..f56726c 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -56,7 +56,8 @@ int write_features_info(bdaddr_t *local, bdaddr_t *peer, unsigned char *page1, u
int read_remote_features(bdaddr_t *local, bdaddr_t *peer, unsigned char *page1, unsigned char *page2);
int write_lastseen_info(bdaddr_t *local, bdaddr_t *peer, uint8_t peer_type,
struct tm *tm);
-int write_lastused_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm);
+int write_lastused_info(bdaddr_t *local, bdaddr_t *peer, uint8_t peer_type,
+ struct tm *tm);
int write_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t type, int length);
int read_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t *type);
ssize_t read_pin_code(bdaddr_t *local, bdaddr_t *peer, char *pin);
--
1.7.9.5


2012-07-03 20:32:08

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ v2 05/12] storage: Store address type in "lastseen" file

---
src/event.c | 6 +++---
src/storage.c | 11 +++++++----
src/storage.h | 3 ++-
3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/event.c b/src/event.c
index 17fc250..12eb9d9 100644
--- a/src/event.c
+++ b/src/event.c
@@ -233,7 +233,7 @@ void btd_event_simple_pairing_complete(bdaddr_t *local, bdaddr_t *peer,
device_simple_pairing_complete(device, status);
}

-static void update_lastseen(bdaddr_t *sba, bdaddr_t *dba)
+static void update_lastseen(bdaddr_t *sba, bdaddr_t *dba, uint8_t dba_type)
{
time_t t;
struct tm *tm;
@@ -241,7 +241,7 @@ static void update_lastseen(bdaddr_t *sba, bdaddr_t *dba)
t = time(NULL);
tm = gmtime(&t);

- write_lastseen_info(sba, dba, tm);
+ write_lastseen_info(sba, dba, dba_type, tm);
}

static void update_lastused(bdaddr_t *sba, bdaddr_t *dba)
@@ -267,7 +267,7 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type
return;
}

- update_lastseen(local, peer);
+ update_lastseen(local, peer, bdaddr_type);

if (data)
write_remote_eir(local, peer, data, data_len);
diff --git a/src/storage.c b/src/storage.c
index 5e1e940..e0be45b 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -572,9 +572,10 @@ int read_remote_features(bdaddr_t *local, bdaddr_t *peer,
return err;
}

-int write_lastseen_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm)
+int write_lastseen_info(bdaddr_t *local, bdaddr_t *peer, uint8_t peer_type,
+ struct tm *tm)
{
- char filename[PATH_MAX + 1], addr[18], str[24];
+ char filename[PATH_MAX + 1], key[20], str[24];

memset(str, 0, sizeof(str));
strftime(str, sizeof(str), "%Y-%m-%d %H:%M:%S %Z", tm);
@@ -583,8 +584,10 @@ int write_lastseen_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm)

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 write_lastused_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm)
diff --git a/src/storage.h b/src/storage.h
index e105913..a5816f6 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -54,7 +54,8 @@ int read_remote_eir(bdaddr_t *local, bdaddr_t *peer, uint8_t *data);
int write_version_info(bdaddr_t *local, bdaddr_t *peer, uint16_t manufacturer, uint8_t lmp_ver, uint16_t lmp_subver);
int write_features_info(bdaddr_t *local, bdaddr_t *peer, unsigned char *page1, unsigned char *page2);
int read_remote_features(bdaddr_t *local, bdaddr_t *peer, unsigned char *page1, unsigned char *page2);
-int write_lastseen_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm);
+int write_lastseen_info(bdaddr_t *local, bdaddr_t *peer, uint8_t peer_type,
+ struct tm *tm);
int write_lastused_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm);
int write_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t type, int length);
int read_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t *type);
--
1.7.9.5


2012-07-03 20:32:07

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ v2 04/12] storage: Store address type in "blocked" file

From: Claudio Takahasi <[email protected]>

---
src/device.c | 6 +++---
src/storage.c | 31 +++++++++++++++++++++----------
src/storage.h | 5 +++--
3 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/src/device.c b/src/device.c
index 9a22b21..c61cfc9 100644
--- a/src/device.c
+++ b/src/device.c
@@ -545,7 +545,7 @@ int device_block(DBusConnection *conn, struct btd_device *device,

adapter_get_address(device->adapter, &src);

- err = write_blocked(&src, &device->bdaddr, TRUE);
+ err = write_blocked(&src, &device->bdaddr, device->bdaddr_type, TRUE);
if (err < 0)
error("write_blocked(): %s (%d)", strerror(-err), -err);

@@ -577,7 +577,7 @@ int device_unblock(DBusConnection *conn, struct btd_device *device,

adapter_get_address(device->adapter, &src);

- err = write_blocked(&src, &device->bdaddr, FALSE);
+ err = write_blocked(&src, &device->bdaddr, device->bdaddr_type, FALSE);
if (err < 0)
error("write_blocked(): %s (%d)", strerror(-err), -err);

@@ -1080,7 +1080,7 @@ struct btd_device *device_create(DBusConnection *conn,
device->alias = g_strdup(alias);
device->trusted = read_trust(&src, address, GLOBAL_TRUST);

- if (read_blocked(&src, &device->bdaddr))
+ if (read_blocked(&src, &device->bdaddr, device->bdaddr_type))
device_block(conn, device, FALSE);

if (read_link_key(&src, &device->bdaddr, NULL, NULL) == 0) {
diff --git a/src/storage.c b/src/storage.c
index a57326b..5e1e940 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -1171,38 +1171,49 @@ int read_device_pairable(bdaddr_t *bdaddr, gboolean *mode)
return 0;
}

-gboolean read_blocked(const bdaddr_t *local, const bdaddr_t *remote)
+gboolean read_blocked(const bdaddr_t *local, const bdaddr_t *remote,
+ uint8_t remote_type)
{
- char filename[PATH_MAX + 1], *str, addr[18];
+ char filename[PATH_MAX + 1], *str, key[20];

create_filename(filename, PATH_MAX, local, "blocked");

- ba2str(remote, addr);
+ ba2str(remote, key);
+ sprintf(&key[17], "#%hhu", remote_type);

- str = textfile_caseget(filename, addr);
- if (!str)
+ str = textfile_caseget(filename, key);
+ if (str != NULL)
+ goto done;
+
+ /* Try old format (address only) */
+ key[17] = '\0';
+
+ str = textfile_caseget(filename, key);
+ if (str == NULL)
return FALSE;

+done:
free(str);

return TRUE;
}

int write_blocked(const bdaddr_t *local, const bdaddr_t *remote,
- gboolean blocked)
+ uint8_t remote_type, gboolean blocked)
{
- char filename[PATH_MAX + 1], addr[18];
+ char filename[PATH_MAX + 1], key[20];

create_filename(filename, PATH_MAX, local, "blocked");

create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

- ba2str(remote, addr);
+ ba2str(remote, key);
+ sprintf(&key[17], "#%hhu", remote_type);

if (blocked == FALSE)
- return textfile_casedel(filename, addr);
+ return textfile_casedel(filename, key);

- return textfile_caseput(filename, addr, "");
+ return textfile_caseput(filename, key, "");
}

int write_device_services(const bdaddr_t *sba, const bdaddr_t *dba,
diff --git a/src/storage.h b/src/storage.h
index 4ca3058..e105913 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -78,9 +78,10 @@ int read_device_id(const gchar *src, const gchar *dst,
uint16_t *product, uint16_t *version);
int write_device_pairable(bdaddr_t *local, gboolean mode);
int read_device_pairable(bdaddr_t *local, gboolean *mode);
-gboolean read_blocked(const bdaddr_t *local, const bdaddr_t *remote);
+gboolean read_blocked(const bdaddr_t *local, const bdaddr_t *remote,
+ uint8_t remote_type);
int write_blocked(const bdaddr_t *local, const bdaddr_t *remote,
- gboolean blocked);
+ uint8_t remote_type, gboolean blocked);
int write_device_services(const bdaddr_t *sba, const bdaddr_t *dba,
uint8_t bdaddr_type, const char *services);
int delete_device_service(const bdaddr_t *sba, const bdaddr_t *dba,
--
1.7.9.5


2012-07-03 20:32:06

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ v2 03/12] core: Fix reading from "aliases" and "names" file

---
src/adapter.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 800515d..f6095ed 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2839,16 +2839,26 @@ 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 peer_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);
+ ba2str(peer, key);
+ sprintf(&key[17], "#%hhu", peer_type);
+
+ str = textfile_get(filename, key);
+ if (str != NULL)
+ return str;
+
+ /* Try old format (address only) */
+ key[17] = '\0';
+
+ return textfile_get(filename, key);
}

void adapter_update_found_devices(struct btd_adapter *adapter,
@@ -2906,7 +2916,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,
@@ -2926,7 +2936,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);
--
1.7.9.5


2012-07-03 20:32:05

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ v2 02/12] storage: Store address type in "aliases" file

---
src/device.c | 14 ++++++--------
src/storage.c | 40 +++++++++++++++++++++++++++++++++-------
src/storage.h | 6 ++++--
3 files changed, 43 insertions(+), 17 deletions(-)

diff --git a/src/device.c b/src/device.c
index 09518f3..9a22b21 100644
--- a/src/device.c
+++ b/src/device.c
@@ -456,8 +456,8 @@ static DBusMessage *set_alias(DBusConnection *conn, DBusMessage *msg,
ba2str(&device->bdaddr, dstaddr);

/* Remove alias if empty string */
- err = write_device_alias(srcaddr, dstaddr,
- g_str_equal(alias, "") ? NULL : alias);
+ err = write_device_alias(srcaddr, dstaddr, device->bdaddr_type,
+ g_str_equal(alias, "") ? NULL : alias);
if (err < 0)
return btd_error_failed(msg, strerror(-err));

@@ -1075,7 +1075,8 @@ struct btd_device *device_create(DBusConnection *conn,
ba2str(&src, srcaddr);

read_device_name(srcaddr, address, bdaddr_type, device->name);
- if (read_device_alias(srcaddr, address, alias, sizeof(alias)) == 0)
+ if (read_device_alias(srcaddr, address, bdaddr_type, alias,
+ sizeof(alias)) == 0)
device->alias = g_strdup(alias);
device->trusted = read_trust(&src, address, GLOBAL_TRUST);

@@ -1156,19 +1157,16 @@ static void device_remove_stored(struct btd_device *device)
DBusConnection *conn = get_dbus_connection();

adapter_get_address(device->adapter, &src);
+
ba2str(&device->bdaddr, key);
+ sprintf(&key[17], "#%hhu", device->bdaddr_type);

- /* key: address only */
delete_entry(&src, "profiles", key);
delete_entry(&src, "trusts", key);

if (device_is_bonded(device)) {
delete_entry(&src, "linkkeys", key);
delete_entry(&src, "aliases", key);
-
- /* key: address#type */
- sprintf(&key[17], "#%hhu", device->bdaddr_type);
-
delete_entry(&src, "longtermkeys", key);

device_set_bonded(device, FALSE);
diff --git a/src/storage.c b/src/storage.c
index 9289e07..a57326b 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -62,17 +62,29 @@ 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 dst_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");

- tmp = textfile_get(filename, dst);
- if (!tmp)
+ snprintf(key, sizeof(key), "%17s#%hhu", dst, dst_type);
+
+ tmp = textfile_get(filename, key);
+ if (tmp != NULL)
+ goto done;
+
+ /* Try old format (address only) */
+ key[17] = '\0';
+
+ tmp = textfile_get(filename, key);
+ if (tmp == NULL)
return -ENXIO;

+done:
err = snprintf(alias, size, "%s", tmp);

free(tmp);
@@ -80,15 +92,19 @@ 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 dst_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);
+ snprintf(key, sizeof(key), "%17s#%hhu", dst, dst_type);
+
+ return textfile_put(filename, key, alias);
}

int write_discoverable_timeout(bdaddr_t *bdaddr, int timeout)
@@ -802,11 +818,21 @@ int write_device_profiles(bdaddr_t *src, bdaddr_t *dst, const char *profiles)

int delete_entry(bdaddr_t *src, const char *storage, const char *key)
{
- char filename[PATH_MAX + 1];
+ char filename[PATH_MAX + 1], old_key[18];
+ int err;
+
+ memset(old_key, 0, sizeof(old_key));
+ memcpy(old_key, key, sizeof(old_key) - 1);

create_filename(filename, PATH_MAX, src, storage);

- return textfile_del(filename, key);
+ /* key: address#type */
+ err = textfile_del(filename, key);
+ if (err < 0)
+ /* old_key: address only */
+ err = textfile_del(filename, old_key);
+
+ return err;
}

int store_record(const gchar *src, const gchar *dst, sdp_record_t *rec)
diff --git a/src/storage.h b/src/storage.h
index 07de39f..4ca3058 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -23,8 +23,10 @@

#include "textfile.h"

-int read_device_alias(const char *src, const char *dst, char *alias, size_t size);
-int write_device_alias(const char *src, const char *dst, const char *alias);
+int read_device_alias(const char *src, const char *dst, uint8_t dst_type,
+ char *alias, size_t size);
+int write_device_alias(const char *src, const char *dst, uint8_t dst_type,
+ const char *alias);
int write_discoverable_timeout(bdaddr_t *bdaddr, int timeout);
int read_discoverable_timeout(const char *src, int *timeout);
int write_pairable_timeout(bdaddr_t *bdaddr, int timeout);
--
1.7.9.5


2012-07-03 20:32:04

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ v2 01/12] 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.
---
input/device.c | 6 ++++--
src/adapter.c | 3 ++-
src/device.c | 3 ++-
src/event.c | 7 +++++--
src/storage.c | 30 ++++++++++++++++++++++--------
src/storage.h | 6 ++++--
6 files changed, 39 insertions(+), 16 deletions(-)

diff --git a/input/device.c b/input/device.c
index 09a9a39..cf4bfc4 100644
--- a/input/device.c
+++ b/input/device.c
@@ -1096,10 +1096,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 dst_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, &dst_type);
idev->device = btd_device_ref(device);
idev->path = g_strdup(path);
idev->conn = dbus_connection_ref(conn);
@@ -1108,7 +1109,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, dst_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 f922876..800515d 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2880,7 +2880,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) {
diff --git a/src/device.c b/src/device.c
index c210bcb..09518f3 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1073,7 +1073,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 ec5926f..17fc250 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 peer_type;
struct remote_dev_info *dev_info;

if (!g_utf8_validate(name, -1, NULL)) {
@@ -333,11 +334,13 @@ 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;

+ peer_type = device_get_addr_type(device);
+
+ write_device_name(local, peer, peer_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 17e8001..9289e07 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';
diff --git a/src/storage.h b/src/storage.h
index cc00e97..07de39f 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 peer_type,
+ char *name);
+int read_device_name(const char *src, const char *dst, uint8_t dst_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);
--
1.7.9.5


2012-07-03 20:32:03

by Paulo Alcantara

[permalink] [raw]
Subject: [PATCH BlueZ v2 00/12] Store address type in BR/EDR and shared files

This patchset proposes new storage format (used currently in LE-only
files) in BR/EDR and shared files.

As the LE-only file changes _only_ occurred in the BlueZ 4.100 release,
the BlueZ 5.x release should contain the new storage format in BR/EDR and
shared files as well.

Do we also need to change BR/EDR-only files like profiles, sdp, linkkeys
and eir ?

v2's changes:
- Do not use "bdaddr_type" for naming variables that are used to
store address types at all, since there are places where both
source and destinate addresses are specified, thus making the code
more readable.

Claudio Takahasi (1):
storage: Store address type in "blocked" file

Paulo Alcantara (11):
storage: Store address type in "names" file
storage: Store address type in "aliases" file
core: Fix reading from "aliases" and "names" file
storage: Store address type in "lastseen" file
storage: Store address type in "lastused" file
storage: Store address type in "profiles" file
storage: Store address type in "did" file
storage: Store address type in "linkkeys" file
storage: Store address type in "trusts" file
storage: Store address type in "eir" file
storage: Store address type in "sdp" file

input/device.c | 11 +-
src/adapter.c | 44 ++++++--
src/device.c | 54 +++++-----
src/event.c | 27 +++--
src/storage.c | 303 ++++++++++++++++++++++++++++++++++++++++----------------
src/storage.h | 61 ++++++++----
6 files changed, 347 insertions(+), 153 deletions(-)

--
1.7.9.5


2012-07-02 16:26:20

by Paulo Alcantara

[permalink] [raw]
Subject: Re: [PATCH BlueZ 01/12] storage: Store address type in "names" file

From: Johan Hedberg <[email protected]>
Date: Mon, 2 Jul 2012 14:25:50 +0300

> Hi Paulo,
>
> On Thu, Jun 14, 2012, Paulo Alcantara wrote:
> > + 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);
>
> I think it'd be clearer to call this dst_type (since it matches dst_addr
> and not src_addr). Could you also change this in all other places the
> variable naming occurs in your patches.

Yeah, indeed. I'll send a v2 of this patchset with the proposed changes.

Thanks!


Paulo

2012-07-02 11:25:50

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH BlueZ 01/12] storage: Store address type in "names" file

Hi Paulo,

On Thu, Jun 14, 2012, Paulo Alcantara wrote:
> + 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);

I think it'd be clearer to call this dst_type (since it matches dst_addr
and not src_addr). Could you also change this in all other places the
variable naming occurs in your patches.

Johan