aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2012-05-11 18:30:51 -0300
committerPaulo Alcantara <paulo.alcantara@openbossa.org>2012-05-22 01:14:03 -0300
commit0b17ce57481014d292f3c070f612c1a3731929a1 (patch)
treeb47b87928cc10f93f4344467f13c83ec364af495
parentbb0534e1da02812665174ab0a345bf4fd128c253 (diff)
downloadbluez-0b17ce57481014d292f3c070f612c1a3731929a1.tar.gz
bluez-0b17ce57481014d292f3c070f612c1a3731929a1.tar.xz
bluez-0b17ce57481014d292f3c070f612c1a3731929a1.zip
storage: Store address type in blocked file
-rw-r--r--src/device.c6
-rw-r--r--src/storage.c46
-rw-r--r--src/storage.h5
3 files changed, 42 insertions, 15 deletions
diff --git a/src/device.c b/src/device.c
index aeedf90a..91101aaf 100644
--- a/src/device.c
+++ b/src/device.c
@@ -547,7 +547,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);
@@ -579,7 +579,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);
@@ -1082,7 +1082,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 8762d589..461e7991 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -1180,38 +1180,64 @@ 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);
+ memset(key, 0, sizeof(key));
- str = textfile_caseget(filename, addr);
+ /* New format: address#type */
+ ba2str(remote, key);
+ sprintf(&key[17], "#%hhu", bdaddr_type);
+
+ str = textfile_caseget(filename, key);
+ if (str)
+ goto done;
+
+ /* Old format: address only */
+ key[17] = '\0';
+
+ str = textfile_caseget(filename, key);
if (!str)
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];
+ int err;
create_filename(filename, PATH_MAX, local, "blocked");
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- ba2str(remote, addr);
+ memset(key, 0, sizeof(key));
- if (blocked == FALSE)
- return textfile_casedel(filename, addr);
+ /* New format: address#type */
+ ba2str(remote, key);
+ sprintf(&key[17], "#%hhu", bdaddr_type);
+
+ if (blocked == FALSE) {
+ err = textfile_casedel(filename, key);
+ if (err < 0) {
+ /* Old format: address only */
+ key[17] = '\0';
- return textfile_caseput(filename, addr, "");
+ err = textfile_casedel(filename, key);
+ }
+ } else
+ err = textfile_caseput(filename, key, "");
+
+ return err;
}
int write_device_services(const bdaddr_t *sba, const bdaddr_t *dba,
diff --git a/src/storage.h b/src/storage.h
index 666fad00..53491d9c 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);