This patchset contains the remaining changes for the new storage format
used (bdaddr#type) on storage for LE-only files.
Note also that the BlueZ 4.x will only contain this new storage format
for LE-only files, whereas BlueZ 5.x will contain this new storage format
for all files (BR/EDR and LE).
Claudio Takahasi (2):
storage: Rename characteristic to characteristics
storage: Rename primary file to primaries
Paulo Alcantara (7):
storage: Store address type in "characteristics"
storage: Store address type in "appearance" file
storage: Store address type in "ccc" file
storage: Store address type in "longtermkeys" file
core: Fix creating device from "longtermkeys" file
storage: Store address type in "attributes" file
storage: Rename appearance file to appearances
attrib/client.c | 31 +++++++++++------
src/adapter.c | 36 +++++++++++--------
src/attrib-server.c | 19 +++++++---
src/device.c | 36 ++++++++++++++-----
src/device.h | 1 +
src/event.c | 6 ++--
src/storage.c | 94 +++++++++++++++++++++++++++------------------------
src/storage.h | 27 +++++++++------
8 files changed, 151 insertions(+), 99 deletions(-)
--
1.7.7.6
Hi Paulo,
On Sat, May 26, 2012, Paulo Alcantara wrote:
> This patchset contains the remaining changes for the new storage format
> used (bdaddr#type) on storage for LE-only files.
>
> Note also that the BlueZ 4.x will only contain this new storage format
> for LE-only files, whereas BlueZ 5.x will contain this new storage format
> for all files (BR/EDR and LE).
>
>
> Claudio Takahasi (2):
> storage: Rename characteristic to characteristics
> storage: Rename primary file to primaries
>
> Paulo Alcantara (7):
> storage: Store address type in "characteristics"
> storage: Store address type in "appearance" file
> storage: Store address type in "ccc" file
> storage: Store address type in "longtermkeys" file
> core: Fix creating device from "longtermkeys" file
> storage: Store address type in "attributes" file
> storage: Rename appearance file to appearances
>
> attrib/client.c | 31 +++++++++++------
> src/adapter.c | 36 +++++++++++--------
> src/attrib-server.c | 19 +++++++---
> src/device.c | 36 ++++++++++++++-----
> src/device.h | 1 +
> src/event.c | 6 ++--
> src/storage.c | 94 +++++++++++++++++++++++++++------------------------
> src/storage.h | 27 +++++++++------
> 8 files changed, 151 insertions(+), 99 deletions(-)
All patches in this set have been applied. Thanks.
Johan
From: Claudio Takahasi <[email protected]>
This patch renames the "primary" file to "primaries" to be more suitable
with its content.
---
src/adapter.c | 6 +++---
src/storage.c | 6 +++---
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 1d9ee6c..6e04faf 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1935,7 +1935,7 @@ static GSList *string_to_primary_list(char *str)
return l;
}
-static void create_stored_device_from_primary(char *key, char *value,
+static void create_stored_device_from_primaries(char *key, char *value,
void *user_data)
{
struct btd_adapter *adapter = user_data;
@@ -1994,8 +1994,8 @@ static void load_devices(struct btd_adapter *adapter)
textfile_foreach(filename, create_stored_device_from_profiles,
adapter);
- create_name(filename, PATH_MAX, STORAGEDIR, srcaddr, "primary");
- textfile_foreach(filename, create_stored_device_from_primary,
+ create_name(filename, PATH_MAX, STORAGEDIR, srcaddr, "primaries");
+ textfile_foreach(filename, create_stored_device_from_primaries,
adapter);
create_name(filename, PATH_MAX, STORAGEDIR, srcaddr, "linkkeys");
diff --git a/src/storage.c b/src/storage.c
index 9a47d29..722abde 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -1169,7 +1169,7 @@ int write_device_services(const bdaddr_t *sba, const bdaddr_t *dba,
{
char filename[PATH_MAX + 1], key[20];
- create_filename(filename, PATH_MAX, sba, "primary");
+ create_filename(filename, PATH_MAX, sba, "primaries");
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
@@ -1231,7 +1231,7 @@ int delete_device_service(const bdaddr_t *sba, const bdaddr_t *dba,
create_filename(filename, PATH_MAX, sba, "ccc");
delete_by_pattern(filename, key);
- create_filename(filename, PATH_MAX, sba, "primary");
+ create_filename(filename, PATH_MAX, sba, "primaries");
return textfile_del(filename, key);
}
@@ -1241,7 +1241,7 @@ char *read_device_services(const bdaddr_t *sba, const bdaddr_t *dba,
{
char filename[PATH_MAX + 1], key[20];
- create_filename(filename, PATH_MAX, sba, "primary");
+ create_filename(filename, PATH_MAX, sba, "primaries");
ba2str(dba, key);
sprintf(&key[17], "#%hhu", bdaddr_type);
--
1.7.7.6
From: Claudio Takahasi <[email protected]>
This patch renames the "characteristic" file to "characteristics" to be
more suitable with its content.
---
src/storage.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/storage.c b/src/storage.c
index cbbf8f6..9a47d29 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -1220,7 +1220,7 @@ int delete_device_service(const bdaddr_t *sba, const bdaddr_t *dba,
sprintf(&key[17], "#%hhu", bdaddr_type);
/* Deleting all characteristics of a given key */
- create_filename(filename, PATH_MAX, sba, "characteristic");
+ create_filename(filename, PATH_MAX, sba, "characteristics");
delete_by_pattern(filename, key);
/* Deleting all attributes values of a given key */
@@ -1255,7 +1255,7 @@ int write_device_characteristics(const bdaddr_t *sba, const bdaddr_t *dba,
{
char filename[PATH_MAX + 1], addr[18], key[25];
- create_filename(filename, PATH_MAX, sba, "characteristic");
+ create_filename(filename, PATH_MAX, sba, "characteristics");
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
@@ -1270,7 +1270,7 @@ char *read_device_characteristics(const bdaddr_t *sba, const bdaddr_t *dba,
{
char filename[PATH_MAX + 1], addr[18], key[25];
- create_filename(filename, PATH_MAX, sba, "characteristic");
+ create_filename(filename, PATH_MAX, sba, "characteristics");
ba2str(dba, addr);
snprintf(key, sizeof(key), "%17s#%hhu#%04X", addr, bdaddr_type, handle);
--
1.7.7.6
Addressing types can be either BR/EDR, BLE public or BLE random so the
entries in the "attributes" 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.
---
attrib/client.c | 6 +++++-
src/storage.c | 12 ++++--------
src/storage.h | 3 ++-
3 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/attrib/client.c b/attrib/client.c
index 8aa2800..7aefd96 100644
--- a/attrib/client.c
+++ b/attrib/client.c
@@ -635,7 +635,9 @@ static GSList *load_characteristics(struct gatt_service *gatt, uint16_t start)
static void store_attribute(struct gatt_service *gatt, uint16_t handle,
uint16_t type, uint8_t *value, gsize len)
{
+ struct btd_device *device = gatt->dev;
bdaddr_t sba, dba;
+ uint8_t bdaddr_type;
bt_uuid_t uuid;
char *str, *tmp;
guint i;
@@ -652,7 +654,9 @@ static void store_attribute(struct gatt_service *gatt, uint16_t handle,
gatt_get_address(gatt, &sba, &dba, NULL);
- write_device_attribute(&sba, &dba, handle, str);
+ bdaddr_type = device_get_addr_type(device);
+
+ write_device_attribute(&sba, &dba, bdaddr_type, handle, str);
g_free(str);
}
diff --git a/src/storage.c b/src/storage.c
index f8e9679..cbbf8f6 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -1223,14 +1223,10 @@ int delete_device_service(const bdaddr_t *sba, const bdaddr_t *dba,
create_filename(filename, PATH_MAX, sba, "characteristic");
delete_by_pattern(filename, key);
- key[17] = '\0';
-
/* Deleting all attributes values of a given key */
create_filename(filename, PATH_MAX, sba, "attributes");
delete_by_pattern(filename, key);
- sprintf(&key[17], "#%hhu", bdaddr_type);
-
/* Deleting all CCC values of a given key */
create_filename(filename, PATH_MAX, sba, "ccc");
delete_by_pattern(filename, key);
@@ -1283,17 +1279,17 @@ char *read_device_characteristics(const bdaddr_t *sba, const bdaddr_t *dba,
}
int write_device_attribute(const bdaddr_t *sba, const bdaddr_t *dba,
- uint16_t handle, const char *chars)
+ uint8_t bdaddr_type, uint16_t handle,
+ const char *chars)
{
- char filename[PATH_MAX + 1], addr[18], key[23];
+ char filename[PATH_MAX + 1], addr[18], key[25];
create_filename(filename, PATH_MAX, sba, "attributes");
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
ba2str(dba, addr);
-
- snprintf(key, sizeof(key), "%17s#%04X", addr, handle);
+ snprintf(key, sizeof(key), "%17s#%hhu#%04X", addr, bdaddr_type, handle);
return textfile_put(filename, key, chars);
}
diff --git a/src/storage.h b/src/storage.h
index 69ade35..c541807 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -89,7 +89,8 @@ int write_device_characteristics(const bdaddr_t *sba, const bdaddr_t *dba,
char *read_device_characteristics(const bdaddr_t *sba, const bdaddr_t *dba,
uint8_t bdaddr_type, uint16_t handle);
int write_device_attribute(const bdaddr_t *sba, const bdaddr_t *dba,
- uint16_t handle, const char *chars);
+ uint8_t bdaddr_type, uint16_t handle,
+ const char *chars);
int read_device_attributes(const bdaddr_t *sba, textfile_cb func, void *data);
int read_device_ccc(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
uint16_t handle, uint16_t *value);
--
1.7.7.6
This patch renames the "appearance" file to "appearances" to be more
suitable with its content.
---
src/storage.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/storage.c b/src/storage.c
index 722abde..7d65fe1 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -286,7 +286,7 @@ int read_remote_appearance(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
{
char filename[PATH_MAX + 1], key[20], *str;
- create_filename(filename, PATH_MAX, local, "appearance");
+ create_filename(filename, PATH_MAX, local, "appearances");
ba2str(peer, key);
sprintf(&key[17], "#%hhu", bdaddr_type);
@@ -310,7 +310,7 @@ int write_remote_appearance(bdaddr_t *local, bdaddr_t *peer,
{
char filename[PATH_MAX + 1], key[20], str[7];
- create_filename(filename, PATH_MAX, local, "appearance");
+ create_filename(filename, PATH_MAX, local, "appearances");
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
--
1.7.7.6
Addressing types can be either BR/EDR, BLE public or BLE random so the
entries in the "longtermkeys" 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.
---
src/device.c | 25 +++++++++++++++++--------
src/event.c | 6 +++---
src/storage.c | 16 ++++++++++------
src/storage.h | 5 +++--
4 files changed, 33 insertions(+), 19 deletions(-)
diff --git a/src/device.c b/src/device.c
index a01a524..0961ff6 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1088,7 +1088,8 @@ struct btd_device *device_create(DBusConnection *conn,
device_set_bonded(device, TRUE);
}
- if (device_is_le(device) && has_longtermkeys(&src, &device->bdaddr)) {
+ if (device_is_le(device) && has_longtermkeys(&src, &device->bdaddr,
+ device->bdaddr_type)) {
device_set_paired(device, TRUE);
device_set_bonded(device, TRUE);
}
@@ -1152,23 +1153,31 @@ uint16_t btd_device_get_version(struct btd_device *device)
static void device_remove_stored(struct btd_device *device)
{
bdaddr_t src;
- char addr[18];
+ char key[20];
DBusConnection *conn = get_dbus_connection();
adapter_get_address(device->adapter, &src);
- ba2str(&device->bdaddr, addr);
+ ba2str(&device->bdaddr, key);
+
+ /* key: address only */
+ delete_entry(&src, "profiles", key);
+ delete_entry(&src, "trusts", key);
if (device_is_bonded(device)) {
- delete_entry(&src, "linkkeys", addr);
- delete_entry(&src, "aliases", addr);
- delete_entry(&src, "longtermkeys", addr);
+ 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);
device->paired = FALSE;
btd_adapter_remove_bonding(device->adapter, &device->bdaddr,
device->bdaddr_type);
}
- delete_entry(&src, "profiles", addr);
- delete_entry(&src, "trusts", addr);
+
delete_all_records(&src, &device->bdaddr);
delete_device_service(&src, &device->bdaddr, device->bdaddr_type);
diff --git a/src/event.c b/src/event.c
index 8ecb942..ec5926f 100644
--- a/src/event.c
+++ b/src/event.c
@@ -380,8 +380,8 @@ static int store_longtermkey(bdaddr_t *local, bdaddr_t *peer,
newkey = g_string_new(val);
g_free(val);
- g_string_append_printf(newkey, " %d %d %d %d %d ", bdaddr_type,
- authenticated, master, enc_size, ediv);
+ g_string_append_printf(newkey, " %d %d %d %d ", authenticated, master,
+ enc_size, ediv);
str = buf2str(rand, 8);
if (str == NULL) {
@@ -392,7 +392,7 @@ static int store_longtermkey(bdaddr_t *local, bdaddr_t *peer,
newkey = g_string_append(newkey, str);
g_free(str);
- err = write_longtermkeys(local, peer, newkey->str);
+ err = write_longtermkeys(local, peer, bdaddr_type, newkey->str);
g_string_free(newkey, TRUE);
diff --git a/src/storage.c b/src/storage.c
index 3cde9c1..f8e9679 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -1362,9 +1362,10 @@ void delete_device_ccc(bdaddr_t *local, bdaddr_t *peer)
delete_by_pattern(filename, addr);
}
-int write_longtermkeys(bdaddr_t *local, bdaddr_t *peer, const char *key)
+int write_longtermkeys(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
+ const char *key)
{
- char filename[PATH_MAX + 1], addr[18];
+ char filename[PATH_MAX + 1], addr[20];
if (!key)
return -EINVAL;
@@ -1374,18 +1375,21 @@ int write_longtermkeys(bdaddr_t *local, bdaddr_t *peer, const char *key)
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
ba2str(peer, addr);
+ sprintf(&addr[17], "#%hhu", bdaddr_type);
+
return textfile_put(filename, addr, key);
}
-gboolean has_longtermkeys(bdaddr_t *local, bdaddr_t *peer)
+gboolean has_longtermkeys(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type)
{
- char filename[PATH_MAX + 1], addr[18], *str;
+ char filename[PATH_MAX + 1], key[20], *str;
create_filename(filename, PATH_MAX, local, "longtermkeys");
- ba2str(peer, addr);
+ ba2str(peer, key);
+ sprintf(&key[17], "#%hhu", bdaddr_type);
- str = textfile_caseget(filename, addr);
+ str = textfile_caseget(filename, key);
if (str) {
free(str);
return TRUE;
diff --git a/src/storage.h b/src/storage.h
index b6d24e9..69ade35 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -96,7 +96,8 @@ int read_device_ccc(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
int write_device_ccc(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
uint16_t handle, uint16_t value);
void delete_device_ccc(bdaddr_t *local, bdaddr_t *peer);
-int write_longtermkeys(bdaddr_t *local, bdaddr_t *peer, const char *key);
-gboolean has_longtermkeys(bdaddr_t *local, bdaddr_t *peer);
+int write_longtermkeys(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
+ const char *key);
+gboolean has_longtermkeys(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type);
#define PNP_UUID "00001200-0000-1000-8000-00805f9b34fb"
--
1.7.7.6
---
src/adapter.c | 26 ++++++++++++++++----------
1 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 1542e06..1d9ee6c 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1787,7 +1787,8 @@ static struct link_key_info *get_key_info(const char *addr, const char *value)
return info;
}
-static struct smp_ltk_info *get_ltk_info(const char *addr, const char *value)
+static struct smp_ltk_info *get_ltk_info(const char *addr, uint8_t bdaddr_type,
+ const char *value)
{
struct smp_ltk_info *ltk;
char *ptr;
@@ -1802,14 +1803,15 @@ static struct smp_ltk_info *get_ltk_info(const char *addr, const char *value)
str2ba(addr, <k->bdaddr);
+ ltk->bdaddr_type = bdaddr_type;
+
str2buf(value, ltk->val, sizeof(ltk->val));
ptr = (char *) value + 2 * sizeof(ltk->val) + 1;
- ret = sscanf(ptr, " %hhd %hhd %hhd %hhd %hd %n",
- (uint8_t *) <k->bdaddr_type,
- <k->authenticated, <k->master,
- <k->enc_size, <k->ediv, &i);
+ ret = sscanf(ptr, " %hhd %hhd %hhd %hd %n",
+ <k->authenticated, <k->master, <k->enc_size,
+ <k->ediv, &i);
if (ret < 2) {
g_free(ltk);
return NULL;
@@ -1851,26 +1853,30 @@ static void create_stored_device_from_ltks(char *key, char *value,
struct btd_adapter *adapter = keys->adapter;
struct btd_device *device;
struct smp_ltk_info *info;
- char srcaddr[18];
+ char address[18], srcaddr[18];
+ uint8_t bdaddr_type;
bdaddr_t src;
- info = get_ltk_info(key, value);
+ if (sscanf(key, "%17s#%hhu", address, &bdaddr_type) < 2)
+ return;
+
+ info = get_ltk_info(address, bdaddr_type, value);
if (info == NULL)
return;
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;
adapter_get_address(adapter, &src);
ba2str(&src, srcaddr);
- if (g_strcmp0(srcaddr, key) == 0)
+ if (g_strcmp0(srcaddr, address) == 0)
return;
- device = device_create(connection, adapter, key, info->bdaddr_type);
+ device = device_create(connection, adapter, address, bdaddr_type);
if (device) {
device_set_temporary(device, FALSE);
adapter->devices = g_slist_append(adapter->devices, device);
--
1.7.7.6
Addressing types can be either BR/EDR, BLE public or BLE random so
the entries in the "ccc" 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.
---
src/attrib-server.c | 19 ++++++++++++++-----
src/device.c | 5 +++++
src/device.h | 1 +
src/storage.c | 20 ++++++++++----------
src/storage.h | 8 ++++----
5 files changed, 34 insertions(+), 19 deletions(-)
diff --git a/src/attrib-server.c b/src/attrib-server.c
index 21b1501..3291e2d 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -737,6 +737,7 @@ static uint16_t read_value(struct gatt_channel *channel, uint16_t handle,
uint8_t status;
GList *l;
uint16_t cccval;
+ uint8_t bdaddr_type;
guint h = handle;
l = g_list_find_custom(channel->server->database,
@@ -747,9 +748,11 @@ static uint16_t read_value(struct gatt_channel *channel, uint16_t handle,
a = l->data;
+ bdaddr_type = device_get_addr_type(channel->device);
+
if (bt_uuid_cmp(&ccc_uuid, &a->uuid) == 0 &&
- read_device_ccc(&channel->src, &channel->dst,
- handle, &cccval) == 0) {
+ read_device_ccc(&channel->src, &channel->dst, bdaddr_type,
+ handle, &cccval) == 0) {
uint8_t config[2];
att_put_u16(cccval, config);
@@ -775,6 +778,7 @@ static uint16_t read_blob(struct gatt_channel *channel, uint16_t handle,
uint8_t status;
GList *l;
uint16_t cccval;
+ uint8_t bdaddr_type;
guint h = handle;
l = g_list_find_custom(channel->server->database,
@@ -789,9 +793,11 @@ static uint16_t read_blob(struct gatt_channel *channel, uint16_t handle,
return enc_error_resp(ATT_OP_READ_BLOB_REQ, handle,
ATT_ECODE_INVALID_OFFSET, pdu, len);
+ bdaddr_type = device_get_addr_type(channel->device);
+
if (bt_uuid_cmp(&ccc_uuid, &a->uuid) == 0 &&
- read_device_ccc(&channel->src, &channel->dst,
- handle, &cccval) == 0) {
+ read_device_ccc(&channel->src, &channel->dst, bdaddr_type,
+ handle, &cccval) == 0) {
uint8_t config[2];
att_put_u16(cccval, config);
@@ -847,7 +853,10 @@ static uint16_t write_value(struct gatt_channel *channel, uint16_t handle,
}
} else {
uint16_t cccval = att_get_u16(value);
- write_device_ccc(&channel->src, &channel->dst, handle, cccval);
+ uint8_t bdaddr_type = device_get_addr_type(channel->device);
+
+ write_device_ccc(&channel->src, &channel->dst, bdaddr_type,
+ handle, cccval);
}
return enc_write_resp(pdu, len);
diff --git a/src/device.c b/src/device.c
index eb015ec..a01a524 100644
--- a/src/device.c
+++ b/src/device.c
@@ -2205,6 +2205,11 @@ void device_set_addr_type(struct btd_device *device, uint8_t bdaddr_type)
device->bdaddr_type = bdaddr_type;
}
+uint8_t device_get_addr_type(struct btd_device *device)
+{
+ return device->bdaddr_type;
+}
+
const gchar *device_get_path(struct btd_device *device)
{
if (!device)
diff --git a/src/device.h b/src/device.h
index 51140c7..26e17f7 100644
--- a/src/device.h
+++ b/src/device.h
@@ -62,6 +62,7 @@ struct btd_adapter *device_get_adapter(struct btd_device *device);
void device_get_address(struct btd_device *device, bdaddr_t *bdaddr,
uint8_t *bdaddr_type);
void device_set_addr_type(struct btd_device *device, uint8_t bdaddr_type);
+uint8_t device_get_addr_type(struct btd_device *device);
const gchar *device_get_path(struct btd_device *device);
struct agent *device_get_agent(struct btd_device *device);
gboolean device_is_bredr(struct btd_device *device);
diff --git a/src/storage.c b/src/storage.c
index ab9b1ed..3cde9c1 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -1229,12 +1229,12 @@ int delete_device_service(const bdaddr_t *sba, const bdaddr_t *dba,
create_filename(filename, PATH_MAX, sba, "attributes");
delete_by_pattern(filename, key);
+ sprintf(&key[17], "#%hhu", bdaddr_type);
+
/* Deleting all CCC values of a given key */
create_filename(filename, PATH_MAX, sba, "ccc");
delete_by_pattern(filename, key);
- sprintf(&key[17], "#%hhu", bdaddr_type);
-
create_filename(filename, PATH_MAX, sba, "primary");
return textfile_del(filename, key);
@@ -1307,10 +1307,10 @@ int read_device_attributes(const bdaddr_t *sba, textfile_cb func, void *data)
return textfile_foreach(filename, func, data);
}
-int read_device_ccc(bdaddr_t *local, bdaddr_t *peer, uint16_t handle,
- uint16_t *value)
+int read_device_ccc(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
+ uint16_t handle, uint16_t *value)
{
- char filename[PATH_MAX + 1], addr[18], key[23];
+ char filename[PATH_MAX + 1], addr[18], key[25];
char *str;
unsigned int config;
int err = 0;
@@ -1318,7 +1318,7 @@ int read_device_ccc(bdaddr_t *local, bdaddr_t *peer, uint16_t handle,
create_filename(filename, PATH_MAX, local, "ccc");
ba2str(peer, addr);
- snprintf(key, sizeof(key), "%17s#%04X", addr, handle);
+ snprintf(key, sizeof(key), "%17s#%hhu#%04X", addr, bdaddr_type, handle);
str = textfile_caseget(filename, key);
if (str == NULL)
@@ -1334,18 +1334,18 @@ int read_device_ccc(bdaddr_t *local, bdaddr_t *peer, uint16_t handle,
return err;
}
-int write_device_ccc(bdaddr_t *local, bdaddr_t *peer, uint16_t handle,
- uint16_t value)
+int write_device_ccc(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
+ uint16_t handle, uint16_t value)
{
- char filename[PATH_MAX + 1], addr[18], key[23], config[5];
+ char filename[PATH_MAX + 1], addr[18], key[25], config[5];
create_filename(filename, PATH_MAX, local, "ccc");
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
ba2str(peer, addr);
+ snprintf(key, sizeof(key), "%17s#%hhu#%04X", addr, bdaddr_type, handle);
- snprintf(key, sizeof(key), "%17s#%04X", addr, handle);
snprintf(config, sizeof(config), "%04X", value);
return textfile_put(filename, key, config);
diff --git a/src/storage.h b/src/storage.h
index db33b43..b6d24e9 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -91,10 +91,10 @@ char *read_device_characteristics(const bdaddr_t *sba, const bdaddr_t *dba,
int write_device_attribute(const bdaddr_t *sba, const bdaddr_t *dba,
uint16_t handle, const char *chars);
int read_device_attributes(const bdaddr_t *sba, textfile_cb func, void *data);
-int read_device_ccc(bdaddr_t *local, bdaddr_t *peer, uint16_t handle,
- uint16_t *value);
-int write_device_ccc(bdaddr_t *local, bdaddr_t *peer, uint16_t handle,
- uint16_t value);
+int read_device_ccc(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
+ uint16_t handle, uint16_t *value);
+int write_device_ccc(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
+ uint16_t handle, uint16_t value);
void delete_device_ccc(bdaddr_t *local, bdaddr_t *peer);
int write_longtermkeys(bdaddr_t *local, bdaddr_t *peer, const char *key);
gboolean has_longtermkeys(bdaddr_t *local, bdaddr_t *peer);
--
1.7.7.6
BLE addressing types can be either public or random so the entries in
the "appearance" file did not contain enough information to distinguish
which addressing type it's supposed to be (LE public or LE random).
Appearance is an information related to BLE device only. Entries will
now contain both BLE address number and BLE address type as a single key
in every entry in the file.
---
src/adapter.c | 4 ++--
src/device.c | 6 ++++--
src/storage.c | 19 +++++++++++--------
src/storage.h | 6 ++++--
4 files changed, 21 insertions(+), 14 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index c6904a1..1542e06 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2731,7 +2731,7 @@ void adapter_emit_device_found(struct btd_adapter *adapter,
dev->legacy = FALSE;
if (read_remote_appearance(&adapter->bdaddr, &dev->bdaddr,
- &app) == 0)
+ dev->bdaddr_type, &app) == 0)
icon = gap_appearance_to_icon(app);
else
icon = NULL;
@@ -2870,7 +2870,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
write_remote_class(&adapter->bdaddr, bdaddr, dev_class);
if (eir_data.appearance != 0)
- write_remote_appearance(&adapter->bdaddr, bdaddr,
+ write_remote_appearance(&adapter->bdaddr, bdaddr, bdaddr_type,
eir_data.appearance);
if (eir_data.name != NULL && eir_data.name_complete)
diff --git a/src/device.c b/src/device.c
index 7cdd025..eb015ec 100644
--- a/src/device.c
+++ b/src/device.c
@@ -373,7 +373,8 @@ static DBusMessage *get_properties(DBusConnection *conn,
icon = class_to_icon(class);
dict_append_entry(&dict, "Class", DBUS_TYPE_UINT32, &class);
- } else if (read_remote_appearance(&src, &device->bdaddr, &app) == 0)
+ } else if (read_remote_appearance(&src, &device->bdaddr,
+ device->bdaddr_type, &app) == 0)
/* Appearance */
icon = gap_appearance_to_icon(app);
@@ -1851,7 +1852,8 @@ static void appearance_cb(guint8 status, const guint8 *pdu, guint16 plen,
app = att_get_u16(atval);
adapter_get_address(adapter, &src);
- write_remote_appearance(&src, &device->bdaddr, app);
+ write_remote_appearance(&src, &device->bdaddr, device->bdaddr_type,
+ app);
done:
att_data_list_free(list);
diff --git a/src/storage.c b/src/storage.c
index b783be0..ab9b1ed 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -281,16 +281,17 @@ int read_local_class(bdaddr_t *bdaddr, uint8_t *class)
return 0;
}
-int read_remote_appearance(bdaddr_t *local, bdaddr_t *peer,
+int read_remote_appearance(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
uint16_t *appearance)
{
- char filename[PATH_MAX + 1], addr[18], *str;
+ char filename[PATH_MAX + 1], key[20], *str;
create_filename(filename, PATH_MAX, local, "appearance");
- ba2str(peer, addr);
+ ba2str(peer, key);
+ sprintf(&key[17], "#%hhu", bdaddr_type);
- str = textfile_get(filename, addr);
+ str = textfile_get(filename, key);
if (!str)
return -ENOENT;
@@ -305,18 +306,20 @@ int read_remote_appearance(bdaddr_t *local, bdaddr_t *peer,
}
int write_remote_appearance(bdaddr_t *local, bdaddr_t *peer,
- uint16_t appearance)
+ uint8_t bdaddr_type, uint16_t appearance)
{
- char filename[PATH_MAX + 1], addr[18], str[7];
+ char filename[PATH_MAX + 1], key[20], str[7];
create_filename(filename, PATH_MAX, local, "appearance");
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- ba2str(peer, addr);
+ ba2str(peer, key);
+ sprintf(&key[17], "#%hhu", bdaddr_type);
+
sprintf(str, "0x%4.4x", appearance);
- return textfile_put(filename, addr, str);
+ return textfile_put(filename, key, str);
}
int write_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t class)
diff --git a/src/storage.h b/src/storage.h
index c3be64a..db33b43 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -36,8 +36,10 @@ int write_local_name(bdaddr_t *bdaddr, const char *name);
int read_local_name(bdaddr_t *bdaddr, char *name);
int write_local_class(bdaddr_t *bdaddr, uint8_t *class);
int read_local_class(bdaddr_t *bdaddr, uint8_t *class);
-int write_remote_appearance(bdaddr_t *local, bdaddr_t *peer, uint16_t appearance);
-int read_remote_appearance(bdaddr_t *local, bdaddr_t *peer, uint16_t *appearance);
+int write_remote_appearance(bdaddr_t *local, bdaddr_t *peer,
+ uint8_t bdaddr_type, uint16_t appearance);
+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);
--
1.7.7.6
GATT can use BR/EDR or BLE as transport. Addressing types can be either
BR/EDR, BLE public or BLE random so the entries in the "characteristics"
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.
---
attrib/client.c | 25 +++++++++++++++----------
src/storage.c | 19 +++++++++++--------
src/storage.h | 5 +++--
3 files changed, 29 insertions(+), 20 deletions(-)
diff --git a/attrib/client.c b/attrib/client.c
index 8fbc1cc..8aa2800 100644
--- a/attrib/client.c
+++ b/attrib/client.c
@@ -155,15 +155,15 @@ static void remove_attio(struct gatt_service *gatt)
}
}
-static void gatt_get_address(struct gatt_service *gatt,
- bdaddr_t *sba, bdaddr_t *dba)
+static void gatt_get_address(struct gatt_service *gatt, bdaddr_t *sba,
+ bdaddr_t *dba, uint8_t *bdaddr_type)
{
struct btd_device *device = gatt->dev;
struct btd_adapter *adapter;
adapter = device_get_adapter(device);
adapter_get_address(adapter, sba);
- device_get_address(device, dba, NULL);
+ device_get_address(device, dba, bdaddr_type);
}
static int characteristic_handle_cmp(gconstpointer a, gconstpointer b)
@@ -548,13 +548,15 @@ static char *characteristic_list_to_string(GSList *chars)
}
static void store_characteristics(const bdaddr_t *sba, const bdaddr_t *dba,
- uint16_t start, GSList *chars)
+ uint8_t bdaddr_type, uint16_t start,
+ GSList *chars)
{
char *characteristics;
characteristics = characteristic_list_to_string(chars);
- write_device_characteristics(sba, dba, start, characteristics);
+ write_device_characteristics(sba, dba, bdaddr_type, start,
+ characteristics);
g_free(characteristics);
}
@@ -614,11 +616,12 @@ static GSList *load_characteristics(struct gatt_service *gatt, uint16_t start)
{
GSList *chrs_list;
bdaddr_t sba, dba;
+ uint8_t bdaddr_type;
char *str;
- gatt_get_address(gatt, &sba, &dba);
+ gatt_get_address(gatt, &sba, &dba, &bdaddr_type);
- str = read_device_characteristics(&sba, &dba, start);
+ str = read_device_characteristics(&sba, &dba, bdaddr_type, start);
if (str == NULL)
return NULL;
@@ -647,7 +650,7 @@ static void store_attribute(struct gatt_service *gatt, uint16_t handle,
for (i = 0, tmp = str + MAX_LEN_UUID_STR; i < len; i++, tmp += 2)
sprintf(tmp, "%02X", value[i]);
- gatt_get_address(gatt, &sba, &dba);
+ gatt_get_address(gatt, &sba, &dba, NULL);
write_device_attribute(&sba, &dba, handle, str);
@@ -886,6 +889,7 @@ static void char_discovered_cb(GSList *characteristics, guint8 status,
uint16_t *previous_end = NULL;
GSList *l;
bdaddr_t sba, dba;
+ uint8_t bdaddr_type;
if (status != 0) {
const char *str = att_ecode2str(status);
@@ -924,8 +928,9 @@ static void char_discovered_cb(GSList *characteristics, guint8 status,
if (previous_end)
*previous_end = prim->range.end;
- gatt_get_address(gatt, &sba, &dba);
- store_characteristics(&sba, &dba, prim->range.start, gatt->chars);
+ gatt_get_address(gatt, &sba, &dba, &bdaddr_type);
+ store_characteristics(&sba, &dba, bdaddr_type, prim->range.start,
+ gatt->chars);
g_slist_foreach(gatt->chars, update_all_chars, gatt);
diff --git a/src/storage.c b/src/storage.c
index a91ee2d..b783be0 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -1212,12 +1212,16 @@ int delete_device_service(const bdaddr_t *sba, const bdaddr_t *dba,
char filename[PATH_MAX + 1], key[20];
memset(key, 0, sizeof(key));
+
ba2str(dba, key);
+ sprintf(&key[17], "#%hhu", bdaddr_type);
/* Deleting all characteristics of a given key */
create_filename(filename, PATH_MAX, sba, "characteristic");
delete_by_pattern(filename, key);
+ key[17] = '\0';
+
/* Deleting all attributes values of a given key */
create_filename(filename, PATH_MAX, sba, "attributes");
delete_by_pattern(filename, key);
@@ -1247,31 +1251,30 @@ char *read_device_services(const bdaddr_t *sba, const bdaddr_t *dba,
}
int write_device_characteristics(const bdaddr_t *sba, const bdaddr_t *dba,
- uint16_t handle, const char *chars)
+ uint8_t bdaddr_type, uint16_t handle,
+ const char *chars)
{
- char filename[PATH_MAX + 1], addr[18], key[23];
+ char filename[PATH_MAX + 1], addr[18], key[25];
create_filename(filename, PATH_MAX, sba, "characteristic");
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
ba2str(dba, addr);
-
- snprintf(key, sizeof(key), "%17s#%04X", addr, handle);
+ snprintf(key, sizeof(key), "%17s#%hhu#%04X", addr, bdaddr_type, handle);
return textfile_put(filename, key, chars);
}
char *read_device_characteristics(const bdaddr_t *sba, const bdaddr_t *dba,
- uint16_t handle)
+ uint8_t bdaddr_type, uint16_t handle)
{
- char filename[PATH_MAX + 1], addr[18], key[23];
+ char filename[PATH_MAX + 1], addr[18], key[25];
create_filename(filename, PATH_MAX, sba, "characteristic");
ba2str(dba, addr);
-
- snprintf(key, sizeof(key), "%17s#%04X", addr, handle);
+ snprintf(key, sizeof(key), "%17s#%hhu#%04X", addr, bdaddr_type, handle);
return textfile_caseget(filename, key);
}
diff --git a/src/storage.h b/src/storage.h
index d00976f..c3be64a 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -82,9 +82,10 @@ int delete_device_service(const bdaddr_t *sba, const bdaddr_t *dba,
char *read_device_services(const bdaddr_t *sba, const bdaddr_t *dba,
uint8_t bdaddr_type);
int write_device_characteristics(const bdaddr_t *sba, const bdaddr_t *dba,
- uint16_t handle, const char *chars);
+ uint8_t bdaddr_type, uint16_t handle,
+ const char *chars);
char *read_device_characteristics(const bdaddr_t *sba, const bdaddr_t *dba,
- uint16_t handle);
+ uint8_t bdaddr_type, uint16_t handle);
int write_device_attribute(const bdaddr_t *sba, const bdaddr_t *dba,
uint16_t handle, const char *chars);
int read_device_attributes(const bdaddr_t *sba, textfile_cb func, void *data);
--
1.7.7.6