* [PATCH v3 BlueZ 12/12] storage: Store address type in "sdp" file
From: Vinicius Costa Gomes @ 2012-07-27 19:43 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Paulo Alcantara
In-Reply-To: <1343418203-15335-1-git-send-email-vinicius.gomes@openbossa.org>
From: Paulo Alcantara <paulo.alcantara@openbossa.org>
---
profiles/input/device.c | 5 ++++-
src/device.c | 12 ++++++++----
src/storage.c | 49 ++++++++++++++++++++++++++++++++++-------------
src/storage.h | 12 ++++++++----
4 files changed, 56 insertions(+), 22 deletions(-)
diff --git a/profiles/input/device.c b/profiles/input/device.c
index 829ca03..ed178b4 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -599,6 +599,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;
@@ -613,7 +614,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 4ff37e6..1718726 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1176,8 +1176,8 @@ static void device_remove_stored(struct btd_device *device)
btd_adapter_remove_bonding(device->adapter, &dst, dst_type);
}
- delete_all_records(&src, &device->bdaddr);
- delete_device_service(&src, &device->bdaddr, device->bdaddr_type);
+ delete_all_records(&src, &dst, dst_type);
+ delete_device_service(&src, &dst, dst_type);
if (device->blocked)
device_unblock(conn, device, TRUE, FALSE);
@@ -1401,7 +1401,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);
@@ -1443,6 +1444,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);
@@ -1509,7 +1511,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 9e0ea12..c50e920 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -894,9 +894,10 @@ int delete_entry(bdaddr_t *src, const char *storage, bdaddr_t *dst,
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;
@@ -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, dst_type,
+ rec->handle);
if (sdp_gen_record_pdu(rec, &buf) < 0)
return -1;
@@ -949,34 +951,54 @@ 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, ret;
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 = 0;
+ ret = textfile_del(filename, key);
+ if (ret)
+ err = ret;
+
+ /* Try old format (address#handle) */
+ ret = textfile_del(filename, old_key);
+ if (ret)
+ err = ret;
+
+ return err;
}
struct record_list {
@@ -999,7 +1021,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];
@@ -1011,7 +1034,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 b8cdb3c..c4f13dd 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -72,11 +72,15 @@ 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, bdaddr_t *dst,
uint8_t dst_type);
-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.10.4
^ permalink raw reply related
* [PATCH v3 BlueZ 11/12] storage: Store address type in "eir" file
From: Vinicius Costa Gomes @ 2012-07-27 19:43 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Paulo Alcantara
In-Reply-To: <1343418203-15335-1-git-send-email-vinicius.gomes@openbossa.org>
From: Paulo Alcantara <paulo.alcantara@openbossa.org>
---
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 f28ffac..9e0ea12 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 56fb14e..b8cdb3c 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.10.4
^ permalink raw reply related
* [PATCH v3 BlueZ 10/12] storage: Store address type in "trusts" file
From: Vinicius Costa Gomes @ 2012-07-27 19:43 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Paulo Alcantara
In-Reply-To: <1343418203-15335-1-git-send-email-vinicius.gomes@openbossa.org>
From: Paulo Alcantara <paulo.alcantara@openbossa.org>
---
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 3dd443f..4ff37e6 100644
--- a/src/device.c
+++ b/src/device.c
@@ -488,7 +488,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));
@@ -1079,7 +1080,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 adaa26f..f28ffac 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 44fd87f..56fb14e 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, bdaddr_t *dst,
--
1.7.10.4
^ permalink raw reply related
* [PATCH v3 BlueZ 09/12] storage: Store address type in "linkkeys" file
From: Vinicius Costa Gomes @ 2012-07-27 19:43 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Paulo Alcantara
In-Reply-To: <1343418203-15335-1-git-send-email-vinicius.gomes@openbossa.org>
From: Paulo Alcantara <paulo.alcantara@openbossa.org>
---
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 c88a275..3b11268 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1793,20 +1793,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 d9218ce..3dd443f 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1084,7 +1084,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 864f2fd..adaa26f 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 f766193..44fd87f 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.10.4
^ permalink raw reply related
* [PATCH v3 BlueZ 08/12] storage: Store address type in "did" file
From: Vinicius Costa Gomes @ 2012-07-27 19:43 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Paulo Alcantara
In-Reply-To: <1343418203-15335-1-git-send-email-vinicius.gomes@openbossa.org>
From: Paulo Alcantara <paulo.alcantara@openbossa.org>
---
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 d6bceaf..d9218ce 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1095,8 +1095,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);
@@ -1494,7 +1494,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 05fb0a8..864f2fd 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 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);
@@ -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 dst_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, dst_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, dst_type, lsource, lvendor,
+ lproduct, lversion);
if (err)
return err;
diff --git a/src/storage.h b/src/storage.h
index 6af2475..f766193 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -74,10 +74,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.10.4
^ permalink raw reply related
* [PATCH v3 BlueZ 07/12] storage: Store address type in "profiles" file
From: Vinicius Costa Gomes @ 2012-07-27 19:43 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Paulo Alcantara
In-Reply-To: <1343418203-15335-1-git-send-email-vinicius.gomes@openbossa.org>
From: Paulo Alcantara <paulo.alcantara@openbossa.org>
---
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 0394ec0..c88a275 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1674,15 +1674,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 1b35d4b..d6bceaf 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1537,12 +1537,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 c10f9ae..05fb0a8 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, bdaddr_t *dst,
diff --git a/src/storage.h b/src/storage.h
index cd7b161..6af2475 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, bdaddr_t *dst,
uint8_t dst_type);
int store_record(const gchar *src, const gchar *dst, sdp_record_t *rec);
--
1.7.10.4
^ permalink raw reply related
* [PATCH v3 BlueZ 06/12] storage: Store address type in "lastused" file
From: Vinicius Costa Gomes @ 2012-07-27 19:43 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Paulo Alcantara
In-Reply-To: <1343418203-15335-1-git-send-email-vinicius.gomes@openbossa.org>
From: Paulo Alcantara <paulo.alcantara@openbossa.org>
---
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 89c28e0..c10f9ae 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 f54812b..cd7b161 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.10.4
^ permalink raw reply related
* [PATCH v3 BlueZ 05/12] storage: Store address type in "lastseen" file
From: Vinicius Costa Gomes @ 2012-07-27 19:43 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Paulo Alcantara
In-Reply-To: <1343418203-15335-1-git-send-email-vinicius.gomes@openbossa.org>
From: Paulo Alcantara <paulo.alcantara@openbossa.org>
---
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 252b383..89c28e0 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 3231fec..f54812b 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.10.4
^ permalink raw reply related
* [PATCH v3 BlueZ 04/12] storage: Store address type in "blocked" file
From: Vinicius Costa Gomes @ 2012-07-27 19:43 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
In-Reply-To: <1343418203-15335-1-git-send-email-vinicius.gomes@openbossa.org>
From: Claudio Takahasi <claudio.takahasi@openbossa.org>
---
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 d4d4d90..1b35d4b 100644
--- a/src/device.c
+++ b/src/device.c
@@ -546,7 +546,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);
@@ -578,7 +578,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);
@@ -1081,7 +1081,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 df876b4..252b383 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -1177,38 +1177,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 2291390..3231fec 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -79,9 +79,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.10.4
^ permalink raw reply related
* [PATCH v3 BlueZ 03/12] core: Fix reading from "aliases" and "names" file
From: Vinicius Costa Gomes @ 2012-07-27 19:43 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Paulo Alcantara
In-Reply-To: <1343418203-15335-1-git-send-email-vinicius.gomes@openbossa.org>
From: Paulo Alcantara <paulo.alcantara@openbossa.org>
---
src/adapter.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 8820e27..0394ec0 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2801,16 +2801,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,
@@ -2868,7 +2878,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,
@@ -2888,7 +2898,8 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
mgmt_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.4
^ permalink raw reply related
* [PATCH v3 BlueZ 02/12] storage: Store address type in "aliases" file
From: Vinicius Costa Gomes @ 2012-07-27 19:43 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Paulo Alcantara
In-Reply-To: <1343418203-15335-1-git-send-email-vinicius.gomes@openbossa.org>
From: Paulo Alcantara <paulo.alcantara@openbossa.org>
---
src/device.c | 7 ++++---
src/storage.c | 26 +++++++++++++++++++++-----
src/storage.h | 6 ++++--
3 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/src/device.c b/src/device.c
index 28d8a13..d4d4d90 100644
--- a/src/device.c
+++ b/src/device.c
@@ -457,8 +457,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));
@@ -1076,7 +1076,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);
diff --git a/src/storage.c b/src/storage.c
index 7a3010d..df876b4 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)
diff --git a/src/storage.h b/src/storage.h
index c5fabd1..2291390 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.10.4
^ permalink raw reply related
* [PATCH v3 BlueZ 01/12] storage: Make it clear that delete_entry only works for addresses
From: Vinicius Costa Gomes @ 2012-07-27 19:43 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Vinicius Costa Gomes
In-Reply-To: <1343418203-15335-1-git-send-email-vinicius.gomes@openbossa.org>
Also, delete_entry should try to erase both addresses styles, with and
without address type, if not we may find some leftovers from deleted
devices.
---
src/device.c | 24 +++++++++---------------
src/storage.c | 22 +++++++++++++++++++---
src/storage.h | 3 ++-
3 files changed, 30 insertions(+), 19 deletions(-)
diff --git a/src/device.c b/src/device.c
index cd571f7..28d8a13 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1152,30 +1152,24 @@ uint16_t btd_device_get_version(struct btd_device *device)
static void device_remove_stored(struct btd_device *device)
{
- bdaddr_t src;
- char key[20];
+ bdaddr_t src, dst;
+ uint8_t dst_type;
DBusConnection *conn = get_dbus_connection();
adapter_get_address(device->adapter, &src);
- ba2str(&device->bdaddr, key);
+ device_get_address(device, &dst, &dst_type);
- /* key: address only */
- delete_entry(&src, "profiles", key);
- delete_entry(&src, "trusts", key);
+ delete_entry(&src, "profiles", &dst, dst_type);
+ delete_entry(&src, "trusts", &dst, dst_type);
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);
+ delete_entry(&src, "linkkeys", &dst, dst_type);
+ delete_entry(&src, "aliases", &dst, dst_type);
+ delete_entry(&src, "longtermkeys", &dst, dst_type);
device_set_bonded(device, FALSE);
device->paired = FALSE;
- btd_adapter_remove_bonding(device->adapter, &device->bdaddr,
- device->bdaddr_type);
+ btd_adapter_remove_bonding(device->adapter, &dst, dst_type);
}
delete_all_records(&src, &device->bdaddr);
diff --git a/src/storage.c b/src/storage.c
index 9289e07..7a3010d 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -800,13 +800,29 @@ int write_device_profiles(bdaddr_t *src, bdaddr_t *dst, const char *profiles)
return textfile_put(filename, addr, profiles);
}
-int delete_entry(bdaddr_t *src, const char *storage, const char *key)
+int delete_entry(bdaddr_t *src, const char *storage, bdaddr_t *dst,
+ uint8_t dst_type)
{
- char filename[PATH_MAX + 1];
+ char filename[PATH_MAX + 1], key[20];
+ int err, ret;
+
+ ba2str(dst, key);
+ sprintf(&key[17], "#%hhu", dst_type);
create_filename(filename, PATH_MAX, src, storage);
- return textfile_del(filename, key);
+ err = 0;
+ ret = textfile_del(filename, key);
+ if (ret)
+ err = ret;
+
+ /* Trying without address type */
+ key[17] = '\0';
+ ret = textfile_del(filename, key);
+ if (ret)
+ err = ret;
+
+ 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..c5fabd1 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -60,7 +60,8 @@ 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 delete_entry(bdaddr_t *src, const char *storage, const char *key);
+int delete_entry(bdaddr_t *src, const char *storage, bdaddr_t *dst,
+ uint8_t dst_type);
int store_record(const gchar *src, const gchar *dst, 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);
--
1.7.10.4
^ permalink raw reply related
* [PATCH v3 BlueZ 00/12] Store address type in BR/EDR and shared files
From: Vinicius Costa Gomes @ 2012-07-27 19:43 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Vinicius Costa Gomes
Hi,
Just an updated version of the storage patches that Paulo Alcantara sent some
time ago.
Changes from last version:
* delete_entry now has address and address type parameters;
* When removing entries, we also remove the entries that have the old format
(without address type);
Cheers,
Claudio Takahasi (1):
storage: Store address type in "blocked" file
Paulo Alcantara (10):
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
Vinicius Costa Gomes (1):
storage: Make it clear that delete_entry only works for addresses
profiles/input/device.c | 5 +-
src/adapter.c | 41 +++++--
src/device.c | 70 ++++++------
src/event.c | 20 ++--
src/storage.c | 286 ++++++++++++++++++++++++++++++++++-------------
src/storage.h | 58 ++++++----
6 files changed, 330 insertions(+), 150 deletions(-)
--
1.7.10.4
^ permalink raw reply
* [PATCH] Bluetooth: debug: Correct the PSM printing
From: Syam Sidhardhan @ 2012-07-27 18:21 UTC (permalink / raw)
To: linux-bluetooth; +Cc: jaganath.k, Syam Sidhardhan
In-Reply-To: <1343413282-8901-1-git-send-email-s.syam@samsung.com>
Earlier we were printing chan->psm before assigning any value.
Signed-off-by: Syam Sidhardhan <s.syam@samsung.com>
---
net/bluetooth/l2cap_core.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index bedc960..0912a63 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1447,7 +1447,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
int err;
BT_DBG("%s -> %s (type %u) psm 0x%2.2x", batostr(src), batostr(dst),
- dst_type, __le16_to_cpu(chan->psm));
+ dst_type, __le16_to_cpu(psm));
hdev = hci_get_route(dst, src);
if (!hdev)
--
1.7.4.1
^ permalink raw reply related
* [PATCH] Bluetooth: Use kref for l2cap channel reference counting
From: Syam Sidhardhan @ 2012-07-27 18:21 UTC (permalink / raw)
To: linux-bluetooth; +Cc: jaganath.k, Syam Sidhardhan
This patch changes the struct l2cap_chan and associated code to use
kref api for object refcounting and freeing.
Suggested-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Jaganath Kanakkassery <jaganath.k@samsung.com>
Signed-off-by: Syam Sidhardhan <s.syam@samsung.com>
---
include/net/bluetooth/l2cap.h | 3 +--
net/bluetooth/l2cap_core.c | 15 ++++++++-------
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index d206296..7ed8e35 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -433,11 +433,10 @@ struct l2cap_chan {
struct sock *sk;
struct l2cap_conn *conn;
+ struct kref kref;
__u8 state;
- atomic_t refcnt;
-
__le16 psm;
__u16 dcid;
__u16 scid;
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 6dde7c5..bedc960 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -406,7 +406,7 @@ struct l2cap_chan *l2cap_chan_create(void)
chan->state = BT_OPEN;
- atomic_set(&chan->refcnt, 1);
+ kref_init(&chan->kref);
/* This flag is cleared in l2cap_chan_ready() */
set_bit(CONF_NOT_COMPLETE, &chan->conf_state);
@@ -416,8 +416,10 @@ struct l2cap_chan *l2cap_chan_create(void)
return chan;
}
-static void l2cap_chan_destroy(struct l2cap_chan *chan)
+static void l2cap_chan_destroy(struct kref *kref)
{
+ struct l2cap_chan *chan = container_of(kref, struct l2cap_chan, kref);
+
BT_DBG("chan %p", chan);
write_lock(&chan_list_lock);
@@ -429,17 +431,16 @@ static void l2cap_chan_destroy(struct l2cap_chan *chan)
void l2cap_chan_hold(struct l2cap_chan *c)
{
- BT_DBG("chan %p orig refcnt %d", c, atomic_read(&c->refcnt));
+ BT_DBG("chan %p orig refcnt %d", c, atomic_read(&c->kref.refcount));
- atomic_inc(&c->refcnt);
+ kref_get(&c->kref);
}
void l2cap_chan_put(struct l2cap_chan *c)
{
- BT_DBG("chan %p orig refcnt %d", c, atomic_read(&c->refcnt));
+ BT_DBG("chan %p orig refcnt %d", c, atomic_read(&c->kref.refcount));
- if (atomic_dec_and_test(&c->refcnt))
- l2cap_chan_destroy(c);
+ kref_put(&c->kref, l2cap_chan_destroy);
}
void l2cap_chan_set_defaults(struct l2cap_chan *chan)
--
1.7.4.1
^ permalink raw reply related
* [PATCH 7/7] Bluetooth: Refactor in hci_le_conn_complete_evt
From: Andre Guedes @ 2012-07-27 18:10 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1343412616-25641-1-git-send-email-andre.guedes@openbossa.org>
This patch moves the hci_conn check to begining of hci_le_conn_
complete_evt in order to improve code's readability and better
error handling.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
net/bluetooth/hci_event.c | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 92522b4..32e21ad 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -3334,19 +3334,6 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
hci_dev_lock(hdev);
conn = hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT);
-
- if (ev->status) {
- if (!conn)
- goto unlock;
-
- mgmt_connect_failed(hdev, &conn->dst, conn->type,
- conn->dst_type, ev->status);
- hci_proto_connect_cfm(conn, ev->status);
- conn->state = BT_CLOSED;
- hci_conn_del(conn);
- goto unlock;
- }
-
if (!conn) {
conn = hci_conn_add(hdev, LE_LINK, &ev->bdaddr);
if (!conn) {
@@ -3362,6 +3349,15 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
}
}
+ if (ev->status) {
+ mgmt_connect_failed(hdev, &conn->dst, conn->type,
+ conn->dst_type, ev->status);
+ hci_proto_connect_cfm(conn, ev->status);
+ conn->state = BT_CLOSED;
+ hci_conn_del(conn);
+ goto unlock;
+ }
+
if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
mgmt_device_connected(hdev, &ev->bdaddr, conn->type,
conn->dst_type, 0, NULL, 0, NULL);
--
1.7.11.2
^ permalink raw reply related
* [PATCH 6/7] Bluetooth: Lookup hci_conn in hci_le_conn_complete_evt
From: Andre Guedes @ 2012-07-27 18:10 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1343412616-25641-1-git-send-email-andre.guedes@openbossa.org>
This patch does a trivial code refactoring in hci_conn lookup in
hci_le_conn_complete_evt. It performs the hci_conn lookup at the
begining of the function since it is used by both flows (error
and success).
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
net/bluetooth/hci_event.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 8dc1f0f..92522b4 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -3333,8 +3333,9 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
hci_dev_lock(hdev);
+ conn = hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT);
+
if (ev->status) {
- conn = hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT);
if (!conn)
goto unlock;
@@ -3346,7 +3347,6 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
goto unlock;
}
- conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &ev->bdaddr);
if (!conn) {
conn = hci_conn_add(hdev, LE_LINK, &ev->bdaddr);
if (!conn) {
--
1.7.11.2
^ permalink raw reply related
* [PATCH 5/7] Bluetooth: Find hci_conn by BT_CONNECT state
From: Andre Guedes @ 2012-07-27 18:10 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1343412616-25641-1-git-send-email-andre.guedes@openbossa.org>
This patch changes hci_cs_le_create_conn to perform hci_conn lookup
by state instead of bdaddr.
Since we can have only one LE connection in BT_CONNECT state, we can
perform LE hci_conn lookup by state. This way, we don't rely on
hci_sent_cmd_data helper to find the hci_conn object.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
net/bluetooth/hci_event.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index c0aa9f4..8dc1f0f 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1614,29 +1614,24 @@ static void hci_cs_disconnect(struct hci_dev *hdev, u8 status)
static void hci_cs_le_create_conn(struct hci_dev *hdev, __u8 status)
{
- struct hci_cp_le_create_conn *cp;
struct hci_conn *conn;
BT_DBG("%s status 0x%2.2x", hdev->name, status);
- cp = hci_sent_cmd_data(hdev, HCI_OP_LE_CREATE_CONN);
- if (!cp)
- return;
-
if (status) {
hci_dev_lock(hdev);
- conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->peer_addr);
+ conn = hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT);
if (!conn) {
hci_dev_unlock(hdev);
return;
}
- BT_DBG("%s bdaddr %s conn %p", hdev->name, batostr(&cp->peer_addr),
+ BT_DBG("%s bdaddr %s conn %p", hdev->name, batostr(&conn->dst),
conn);
conn->state = BT_CLOSED;
- mgmt_connect_failed(hdev, &cp->peer_addr, conn->type,
+ mgmt_connect_failed(hdev, &conn->dst, conn->type,
conn->dst_type, status);
hci_proto_connect_cfm(conn, status);
hci_conn_del(conn);
--
1.7.11.2
^ permalink raw reply related
* [PATCH 4/7] Bluetooth: Refactor hci_cs_le_create_conn
From: Andre Guedes @ 2012-07-27 18:10 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1343412616-25641-1-git-send-email-andre.guedes@openbossa.org>
This patch does some code refactoring in hci_cs_le_create_conn
function. The hci_conn object is only needed in case of failure,
therefore hdev locking and hci_conn lookup were moved to
if-statement scope.
Also, the conn->state check was removed since we should always
close the connection if it fails.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
net/bluetooth/hci_event.c | 30 ++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 27064be..c0aa9f4 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1623,24 +1623,26 @@ static void hci_cs_le_create_conn(struct hci_dev *hdev, __u8 status)
if (!cp)
return;
- hci_dev_lock(hdev);
+ if (status) {
+ hci_dev_lock(hdev);
- conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->peer_addr);
+ conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->peer_addr);
+ if (!conn) {
+ hci_dev_unlock(hdev);
+ return;
+ }
- BT_DBG("%s bdaddr %s conn %p", hdev->name, batostr(&cp->peer_addr),
- conn);
+ BT_DBG("%s bdaddr %s conn %p", hdev->name, batostr(&cp->peer_addr),
+ conn);
- if (status) {
- if (conn && conn->state == BT_CONNECT) {
- conn->state = BT_CLOSED;
- mgmt_connect_failed(hdev, &cp->peer_addr, conn->type,
- conn->dst_type, status);
- hci_proto_connect_cfm(conn, status);
- hci_conn_del(conn);
- }
- }
+ conn->state = BT_CLOSED;
+ mgmt_connect_failed(hdev, &cp->peer_addr, conn->type,
+ conn->dst_type, status);
+ hci_proto_connect_cfm(conn, status);
+ hci_conn_del(conn);
- hci_dev_unlock(hdev);
+ hci_dev_unlock(hdev);
+ }
}
static void hci_cs_le_start_enc(struct hci_dev *hdev, u8 status)
--
1.7.11.2
^ permalink raw reply related
* [PATCH 3/7] Bluetooth: Remove unneeded code
From: Andre Guedes @ 2012-07-27 18:10 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1343412616-25641-1-git-send-email-andre.guedes@openbossa.org>
This patch removes some unneeded code from hci_cs_le_create_conn.
If the hci_conn is not found, it means this LE connection attempt
was triggered by a thrid-party tool (e.g. hcitool). We should not
create this new hci_conn in LE Create Connection command status
event since it is already properly handled in LE Connection
Complete event.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
net/bluetooth/hci_event.c | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 8b13ccc..27064be 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1638,16 +1638,6 @@ static void hci_cs_le_create_conn(struct hci_dev *hdev, __u8 status)
hci_proto_connect_cfm(conn, status);
hci_conn_del(conn);
}
- } else {
- if (!conn) {
- conn = hci_conn_add(hdev, LE_LINK, &cp->peer_addr);
- if (conn) {
- conn->dst_type = cp->peer_addr_type;
- conn->out = true;
- } else {
- BT_ERR("No memory for new connection");
- }
- }
}
hci_dev_unlock(hdev);
--
1.7.11.2
^ permalink raw reply related
* [PATCH 2/7] Bluetooth: Fix hci_le_conn_complete_evt
From: Andre Guedes @ 2012-07-27 18:10 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1343412616-25641-1-git-send-email-andre.guedes@openbossa.org>
We need to check the 'Role' parameter from the LE Connection
Complete Event in order to properly set 'out' and 'link_mode'
fields from hci_conn structure.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
include/net/bluetooth/hci.h | 2 ++
net/bluetooth/hci_event.c | 5 +++++
2 files changed, 7 insertions(+)
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 7f19556..23cf413 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -1304,6 +1304,8 @@ struct hci_ev_num_comp_blocks {
} __packed;
/* Low energy meta events */
+#define LE_CONN_ROLE_MASTER 0x00
+
#define HCI_EV_LE_CONN_COMPLETE 0x01
struct hci_ev_le_conn_complete {
__u8 status;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index e89d7f2..8b13ccc 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -3368,6 +3368,11 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
}
conn->dst_type = ev->bdaddr_type;
+
+ if (ev->role == LE_CONN_ROLE_MASTER) {
+ conn->out = true;
+ conn->link_mode |= HCI_LM_MASTER;
+ }
}
if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
--
1.7.11.2
^ permalink raw reply related
* [PATCH 1/7] Bluetooth: Trivial refactoring
From: Andre Guedes @ 2012-07-27 18:10 UTC (permalink / raw)
To: linux-bluetooth
This patch replaces the unlock-and-return statements by the goto
statement.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
net/bluetooth/hci_event.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 0386e1e..e89d7f2 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -3364,8 +3364,7 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
conn = hci_conn_add(hdev, LE_LINK, &ev->bdaddr);
if (!conn) {
BT_ERR("No memory for new connection");
- hci_dev_unlock(hdev);
- return;
+ goto unlock;
}
conn->dst_type = ev->bdaddr_type;
--
1.7.11.2
^ permalink raw reply related
* Re: [RFCv0 06/21] Bluetooth: Channel move request handling
From: Mat Martineau @ 2012-07-27 16:54 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth, gustavo, pkrystad
In-Reply-To: <20120726135924.GC2686@aemeltch-MOBL1>
Hi Andrei -
On Thu, 26 Jul 2012, Andrei Emeltchenko wrote:
> Hi Mat,
>
> On Wed, Jul 25, 2012 at 04:50:58PM -0700, Mat Martineau wrote:
>
> ...
>
>> static void l2cap_chan_ready(struct l2cap_chan *chan)
>> {
>> @@ -4117,7 +4148,67 @@ static inline int l2cap_move_channel_req(struct l2cap_conn *conn,
>>
>> chan = l2cap_get_chan_by_dcid(conn, icid);
>>
>> - /* Placeholder: Always refuse */
>> + if (!chan)
>> + goto send_move_response;
>> +
>> + if (chan->scid < L2CAP_CID_DYN_START || (chan->mode != L2CAP_MODE_ERTM
>> + && chan->mode != L2CAP_MODE_STREAMING))
>
> I think if we add here line below the code would be more understandable
> and following the same style.
> "result = L2CAP_MR_NOT_ALLOWED;"
>
Ok.
>> + goto send_move_response;
>> +
>> + if (chan->chan_id == req->dest_amp_id) {
>> + result = L2CAP_MR_SAME_ID;
>> + goto send_move_response;
>> + }
>> +
>> + if (req->dest_amp_id) {
>> + struct hci_dev *hdev;
>> + hdev = hci_dev_get(req->dest_amp_id);
>> + if (!hdev || !test_bit(HCI_UP, &hdev->flags)) {
>
> Again here we shall check dev_type.
>
Right.
>> + if (hdev)
>> + hci_dev_put(hdev);
>> +
>> + result = L2CAP_MR_BAD_ID;
>> + goto send_move_response;
>> + }
>> + hci_dev_put(hdev);
>> + }
>> +
>> + if (((chan->move_state != L2CAP_MOVE_STABLE &&
>> + chan->move_state != L2CAP_MOVE_WAIT_PREPARE) ||
>> + chan->move_role != L2CAP_MOVE_ROLE_NONE) &&
>> + bacmp(conn->src, conn->dst) > 0) {
>> + result = L2CAP_MR_COLLISION;
>> + goto send_move_response;
>> + }
>> +
>> + if (chan->chan_policy == BT_CHANNEL_POLICY_BREDR_ONLY) {
>> + result = L2CAP_MR_NOT_ALLOWED;
>> + goto send_move_response;
>> + }
>> +
>> + chan->move_cmd_ident = cmd->ident;
>
> BTW: Why do we handle ident in a special way for channel move?
At the time I wrote the code, I thought that chan->ident was only used
to store idents of sent requests, not received requests. But it does
look like it is also used for storing received idents for use in
sending responses. chan->ident could be used as long as move
collisions are handled correctly (where a move request is received
when a move response is expected).
--
Mat Martineau
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
^ permalink raw reply
* Re: [PATCH] bluetooth.h: fix compile issue when using in C++
From: W. Trevor King @ 2012-07-27 16:38 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1330953167.3457.13.camel@pohly-mobl1.fritz.box>
[-- Attachment #1: Type: text/plain, Size: 1065 bytes --]
On Mon, Mar 05, 2012 at 01:12:47PM -0000, Patrick Ohly wrote:
> From: Patrick Ohly <patrick.ohly@intel.com>
> Date: Mon, 16 Jan 2012 10:58:44 +0100
> Subject: [PATCH] bluetooth.h: fix typecast and typeof compile issue when used
> in C++
>
> …
>
> Another issue in combination with -std=c++0x is the use of typeof,
> which is not a standard C++ feature and thus gets rejected in strict
> mode.
>
> This patch keeps the "struct __attribute__((packed))" magic and merely
> changes the typecast so that it works in C and C++. typeof gets replaced
> with __typeof__.
This patch seems to have never made it into bluez, and I just bumped
into the typeof/__typeof__ issue again today. I could not find any
comments in the mailing list explaining if or why the patch was
rejected, so perhaps it just fell through the cracks?
Is there any chance of getting it accepted?
Cheers,
Trevor
--
This email may be signed or encrypted with GnuPG (http://www.gnupg.org).
For more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply
* Re: [PATCH 0/2] obexd: Fix bug in irmc phonebook and prevent to reintroduce it
From: Luiz Augusto von Dentz @ 2012-07-27 15:07 UTC (permalink / raw)
To: Harald Schmitt; +Cc: linux-bluetooth
In-Reply-To: <CABBYNZ+9qc4v3kW1gLVo4SHb924z+WXT8V8wTFAvW3hT6gZhYQ@mail.gmail.com>
Hi Harald,
On Fri, Jul 27, 2012 at 4:40 PM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> Hi Harald,
>
> On Wed, Jul 25, 2012 at 6:03 PM, Harald Schmitt <linux@hschmitt.de> wrote:
>
>>> While the backend indeed take an absolute path this doesnt mean we
>>> have to send as absolute path, not to mention it is not compatible
>>> with mimetypes which is what TYPE header describes, even in case of
>>> PBAP it is wrong to send absolute path in SETPATH.
>>
>> Patch 1/2 only changes the way phonebook_pull is called (with absolute
>> path). It has nothing changed about the path resolution/interpretation
>> that is asked from the client. Sorry for my bad explanations.
>
> Yep, only now I realized that this is not the client side, so it is
> probably fine.
>
>>>
>>> To avoid this problems we send relative although we do accept
>>> absolute, but to avoid problems with stack interpreting absolute path
>>> as not valid as OBEX spec state we always send relative paths.
>>
>> In fact irmc implementation at the moment only accepts relative paths
>> and I did not change this.
>
> No problem, I will make it less strict to follow PBAP in another patch.
>
>>>
>>>> The patch 1/2 fixes irmc to query phonebook implementation for the well
>>>> known absolute path. This was changed in pbap.c with the patch you
>>>> stated, but forgot to change in irmc.c.
>>>> Patch 2/2 just replaces the well-known phonebook paths which
>>>> phoenbook-ebook.c and phonebook-tracker.c support with constants.
>>>
>>> Im fine with converting to constants, it is more the sending of
>>> absolute path that Im not comfortable because of the potential
>>> interoperability problems it could cause.
>>
>> I probably used the wrong term "well known" what I meant by well known
>> are the paths that phonebook-tracker and phonebook-ebook knows that it
>> should fetch the contacts, etc. and these are absolute paths. It is not
>> about the "well known" paths from the pbap spec
>
> No problem, I should have looked what the code was doing before
> drawing any conclusion, anyway I will apply this patches asap.
Patches are now pushed upstream, thanks.
--
Luiz Augusto von Dentz
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox