* [PATCH 09/18] Remove GATT information when the device is removed
From: Vinicius Costa Gomes @ 2010-12-21 21:26 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Vinicius Costa Gomes
In-Reply-To: <1292966800-6264-1-git-send-email-vinicius.gomes@openbossa.org>
This adds a way to remove the information about the device type and its
primary services when the device is going to be removed from the permanent
storage.
---
src/device.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/src/device.c b/src/device.c
index 627db8f..f123288 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1024,6 +1024,8 @@ static void device_remove_stored(struct btd_device *device)
device_remove_bonding(device);
delete_entry(&src, "profiles", addr);
delete_entry(&src, "trusts", addr);
+ delete_entry(&src, "types", addr);
+ delete_entry(&src, "primary", addr);
delete_all_records(&src, &device->bdaddr);
delete_device_service(&src, &device->bdaddr);
--
1.7.3.4
^ permalink raw reply related
* [PATCH 08/18] Add a way to retrieve ATT primary services
From: Vinicius Costa Gomes @ 2010-12-21 21:26 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Vinicius Costa Gomes
In-Reply-To: <1292966800-6264-1-git-send-email-vinicius.gomes@openbossa.org>
As the primary services were discovered by the core bluetoothd, we need
a way to export that information.
The service discovery uses the same primary list as the device, there's no
need to free that list when the discovery finishes. That list will be removed
when the device is free'd.
---
src/adapter.c | 6 +++---
src/device.c | 15 +++++++++++++++
src/device.h | 3 +++
src/glib-helper.c | 1 -
4 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 3d5fafc..e48f1fd 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1994,14 +1994,14 @@ static void create_stored_device_from_primary(char *key, char *value,
for (l = services, uuids = NULL; l; l = l->next) {
struct att_primary *prim = l->data;
uuids = g_slist_append(uuids, prim->uuid);
+
+ device_add_primary(device, prim);
}
device_probe_drivers(device, uuids);
- g_slist_free(uuids);
-
- g_slist_foreach(services, (GFunc) att_primary_free, NULL);
g_slist_free(services);
+ g_slist_free(uuids);
}
static void load_devices(struct btd_adapter *adapter)
diff --git a/src/device.c b/src/device.c
index d67f804..627db8f 100644
--- a/src/device.c
+++ b/src/device.c
@@ -115,6 +115,7 @@ struct btd_device {
struct btd_adapter *adapter;
GSList *uuids;
GSList *services; /* Primary services path */
+ GSList *primaries; /* List of primary services */
GSList *drivers; /* List of driver_data */
GSList *watches; /* List of disconnect_data */
gboolean temporary;
@@ -209,6 +210,9 @@ static void device_free(gpointer user_data)
g_slist_foreach(device->uuids, (GFunc) g_free, NULL);
g_slist_free(device->uuids);
+ g_slist_foreach(device->primaries, (GFunc) att_primary_free, NULL);
+ g_slist_free(device->primaries);
+
if (device->tmp_records)
sdp_list_free(device->tmp_records,
(sdp_free_func_t) sdp_record_free);
@@ -1571,6 +1575,7 @@ static void primary_cb(GSList *services, int err, gpointer user_data)
for (l = services; l; l = l->next) {
struct att_primary *prim = l->data;
uuids = g_slist_append(uuids, prim->uuid);
+ device_add_primary(device, prim);
}
device_probe_drivers(device, uuids);
@@ -2383,6 +2388,16 @@ void device_add_service(struct btd_device *device, const char *path)
device->services = g_slist_append(device->services, g_strdup(path));
}
+void device_add_primary(struct btd_device *device, struct att_primary *prim)
+{
+ device->primaries = g_slist_append(device->primaries, prim);
+}
+
+GSList *btd_device_get_primaries(struct btd_device *device)
+{
+ return device->primaries;
+}
+
void btd_device_add_uuid(struct btd_device *device, const char *uuid)
{
GSList *uuid_list;
diff --git a/src/device.h b/src/device.h
index 7820636..0bd6fff 100644
--- a/src/device.h
+++ b/src/device.h
@@ -25,6 +25,7 @@
#define DEVICE_INTERFACE "org.bluez.Device"
struct btd_device;
+struct att_primary;
typedef enum {
AUTH_TYPE_PINCODE,
@@ -53,7 +54,9 @@ int device_browse(struct btd_device *device, DBusConnection *conn,
void device_probe_drivers(struct btd_device *device, GSList *profiles);
const sdp_record_t *btd_device_get_record(struct btd_device *device,
const char *uuid);
+GSList *btd_device_get_primaries(struct btd_device *device);
void device_add_service(struct btd_device *device, const char *path);
+void device_add_primary(struct btd_device *device, struct att_primary *prim);
void btd_device_add_uuid(struct btd_device *device, const char *uuid);
struct btd_adapter *device_get_adapter(struct btd_device *device);
void device_get_address(struct btd_device *device, bdaddr_t *bdaddr);
diff --git a/src/glib-helper.c b/src/glib-helper.c
index 4bd6a50..648dd62 100644
--- a/src/glib-helper.c
+++ b/src/glib-helper.c
@@ -75,7 +75,6 @@ static void gattrib_context_free(struct gattrib_context *ctxt)
if (ctxt->destroy)
ctxt->destroy(ctxt->user_data);
- g_slist_foreach(ctxt->primaries, (GFunc) att_primary_free, NULL);
g_slist_free(ctxt->primaries);
g_attrib_unref(ctxt->attrib);
if (ctxt->io) {
--
1.7.3.4
^ permalink raw reply related
* [PATCH 07/18] Add support for creating devices from stored primary services
From: Vinicius Costa Gomes @ 2010-12-21 21:26 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Vinicius Costa Gomes
In-Reply-To: <1292966800-6264-1-git-send-email-vinicius.gomes@openbossa.org>
>From what we can retrieve from storage we are able to create the devices
and probe the device drivers.
---
src/adapter.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 77 insertions(+), 0 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 9c57bea..3d5fafc 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -55,6 +55,7 @@
#include "glib-helper.h"
#include "agent.h"
#include "storage.h"
+#include "att.h"
/* Flags Descriptions */
#define EIR_LIM_DISC 0x01 /* LE Limited Discoverable Mode */
@@ -1931,6 +1932,78 @@ static void create_stored_device_from_types(char *key, char *value,
}
}
+static GSList *string_to_primary_list(char *str)
+{
+ GSList *l = NULL;
+ char **services;
+ int i;
+
+ if (str == NULL)
+ return NULL;
+
+ services = g_strsplit(str, " ", 0);
+ if (services == NULL)
+ return NULL;
+
+ for (i = 0; services[i]; i++) {
+ struct att_primary *prim;
+ int ret;
+
+ prim = g_new0(struct att_primary, 1);
+
+ ret = sscanf(services[i], "%04hX#%04hX#%s", &prim->start,
+ &prim->end, prim->uuid);
+
+ if (ret < 3) {
+ att_primary_free(prim);
+ continue;
+ }
+
+ l = g_slist_append(l, prim);
+ }
+
+ g_strfreev(services);
+
+ return l;
+}
+
+static void create_stored_device_from_primary(char *key, char *value,
+ void *user_data)
+{
+ struct btd_adapter *adapter = user_data;
+ struct btd_device *device;
+ GSList *services, *uuids, *l;
+
+ l = g_slist_find_custom(adapter->devices,
+ key, (GCompareFunc) device_address_cmp);
+ if (l)
+ device = l->data;
+ else {
+ device = device_create(connection, adapter, key, DEVICE_TYPE_BREDR);
+ if (!device)
+ return;
+
+ device_set_temporary(device, FALSE);
+ adapter->devices = g_slist_append(adapter->devices, device);
+ }
+
+ services = string_to_primary_list(value);
+ if (services == NULL)
+ return;
+
+ for (l = services, uuids = NULL; l; l = l->next) {
+ struct att_primary *prim = l->data;
+ uuids = g_slist_append(uuids, prim->uuid);
+ }
+
+ device_probe_drivers(device, uuids);
+
+ g_slist_free(uuids);
+
+ g_slist_foreach(services, (GFunc) att_primary_free, NULL);
+ g_slist_free(services);
+}
+
static void load_devices(struct btd_adapter *adapter)
{
char filename[PATH_MAX + 1];
@@ -1944,6 +2017,10 @@ 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,
+ adapter);
+
create_name(filename, PATH_MAX, STORAGEDIR, srcaddr, "linkkeys");
textfile_foreach(filename, create_stored_device_from_linkkeys, &keys);
--
1.7.3.4
^ permalink raw reply related
* [PATCH 06/18] Add support for creating devices from stored types
From: Vinicius Costa Gomes @ 2010-12-21 21:26 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Vinicius Costa Gomes
In-Reply-To: <1292966800-6264-1-git-send-email-vinicius.gomes@openbossa.org>
This adds a way to restore devices from their types.
---
src/adapter.c | 28 ++++++++++++++++++++++++++++
src/device.c | 8 ++++++++
src/device.h | 1 +
3 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index ea81722..9c57bea 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1906,6 +1906,31 @@ static void create_stored_device_from_blocked(char *key, char *value,
}
}
+static void create_stored_device_from_types(char *key, char *value,
+ void *user_data)
+{
+ GSList *l;
+ struct btd_adapter *adapter = user_data;
+ struct btd_device *device;
+ uint8_t type;
+
+ type = strtol(value, NULL, 16);
+
+ l = g_slist_find_custom(adapter->devices,
+ key, (GCompareFunc) device_address_cmp);
+ if (l) {
+ device = l->data;
+ device_set_type(device, type);
+ return;
+ }
+
+ device = device_create(connection, adapter, key, type);
+ if (device) {
+ device_set_temporary(device, FALSE);
+ adapter->devices = g_slist_append(adapter->devices, device);
+ }
+}
+
static void load_devices(struct btd_adapter *adapter)
{
char filename[PATH_MAX + 1];
@@ -1933,6 +1958,9 @@ static void load_devices(struct btd_adapter *adapter)
create_name(filename, PATH_MAX, STORAGEDIR, srcaddr, "blocked");
textfile_foreach(filename, create_stored_device_from_blocked, adapter);
+
+ create_name(filename, PATH_MAX, STORAGEDIR, srcaddr, "types");
+ textfile_foreach(filename, create_stored_device_from_types, adapter);
}
int btd_adapter_block_address(struct btd_adapter *adapter, bdaddr_t *bdaddr)
diff --git a/src/device.c b/src/device.c
index ca2c5bc..d67f804 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1767,6 +1767,14 @@ uint8_t device_get_auth(struct btd_device *device)
return device->auth;
}
+void device_set_type(struct btd_device *device, device_type_t type)
+{
+ if (!device)
+ return;
+
+ device->type = type;
+}
+
static gboolean start_discovery(gpointer user_data)
{
struct btd_device *device = user_data;
diff --git a/src/device.h b/src/device.h
index 74b968c..7820636 100644
--- a/src/device.h
+++ b/src/device.h
@@ -66,6 +66,7 @@ gboolean device_is_trusted(struct btd_device *device);
void device_set_paired(struct btd_device *device, gboolean paired);
void device_set_temporary(struct btd_device *device, gboolean temporary);
void device_set_cap(struct btd_device *device, uint8_t cap);
+void device_set_type(struct btd_device *device, device_type_t type);
uint8_t device_get_cap(struct btd_device *device);
void device_set_auth(struct btd_device *device, uint8_t auth);
uint8_t device_get_auth(struct btd_device *device);
--
1.7.3.4
^ permalink raw reply related
* [PATCH 05/18] Add support for storing the device type
From: Vinicius Costa Gomes @ 2010-12-21 21:26 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Vinicius Costa Gomes
In-Reply-To: <1292966800-6264-1-git-send-email-vinicius.gomes@openbossa.org>
When the service discovery (SDP or GATT) is finished, write the device
type so it can be retrieved from storage when needed.
---
src/device.c | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/src/device.c b/src/device.c
index 4bf9b52..ca2c5bc 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1463,8 +1463,16 @@ send_reply:
}
cleanup:
- if (!device->temporary)
+ if (!device->temporary) {
+ bdaddr_t sba, dba;
+
+ adapter_get_address(device->adapter, &sba);
+ device_get_address(device, &dba);
+
store_profiles(device);
+ write_device_type(&sba, &dba, device->type);
+ }
+
device->browse = NULL;
browse_request_free(req);
}
@@ -1575,6 +1583,7 @@ static void primary_cb(GSList *services, int err, gpointer user_data)
adapter_get_address(adapter, &sba);
device_get_address(device, &dba);
+ write_device_type(&sba, &dba, device->type);
write_device_services(&sba, &dba, str);
g_free(str);
--
1.7.3.4
^ permalink raw reply related
* [PATCH 04/18] Add a way to store the remote device type
From: Vinicius Costa Gomes @ 2010-12-21 21:26 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Vinicius Costa Gomes
In-Reply-To: <1292966800-6264-1-git-send-email-vinicius.gomes@openbossa.org>
Because we need to know the device type (LE, Basic Rate or Dual Mode)
to be able to fully restore the device from storage, we have to store
and load this information to permanent storage.
Note: due to "device_type_t" usage in storage.h, some header includes
needed to be reordered in files which include storage.h.
---
input/device.c | 4 ++--
plugins/hciops.c | 2 +-
serial/port.c | 2 ++
src/storage.c | 40 ++++++++++++++++++++++++++++++++++++++++
src/storage.h | 3 +++
5 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/input/device.c b/input/device.c
index d735028..8a17966 100644
--- a/input/device.c
+++ b/input/device.c
@@ -46,11 +46,11 @@
#include "textfile.h"
#include "uinput.h"
-#include "../src/storage.h"
#include "../src/adapter.h"
+#include "../src/device.h"
+#include "../src/storage.h"
#include "../src/manager.h"
#include "../src/dbus-common.h"
-#include "../src/device.h"
#include "device.h"
#include "error.h"
diff --git a/plugins/hciops.c b/plugins/hciops.c
index 131df1a..43e3d93 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -41,11 +41,11 @@
#include "hcid.h"
#include "sdpd.h"
#include "adapter.h"
+#include "device.h"
#include "plugin.h"
#include "log.h"
#include "storage.h"
#include "event.h"
-#include "device.h"
#include "manager.h"
static int child_pipe[2] = { -1, -1 };
diff --git a/serial/port.c b/serial/port.c
index 233e317..7d56faa 100644
--- a/serial/port.c
+++ b/serial/port.c
@@ -53,6 +53,8 @@
#include "error.h"
#include "manager.h"
+#include "adapter.h"
+#include "device.h"
#include "storage.h"
#include "port.h"
diff --git a/src/storage.c b/src/storage.c
index 06b36f1..fb6e401 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -45,6 +45,8 @@
#include <bluetooth/sdp_lib.h>
#include "textfile.h"
+#include "adapter.h"
+#include "device.h"
#include "glib-helper.h"
#include "storage.h"
@@ -1391,3 +1393,41 @@ int read_device_attributes(const bdaddr_t *sba, textfile_cb func, void *data)
return textfile_foreach(filename, func, data);
}
+
+int write_device_type(const bdaddr_t *sba, const bdaddr_t *dba,
+ device_type_t type)
+{
+ char filename[PATH_MAX + 1], addr[18], chars[3];
+
+ create_filename(filename, PATH_MAX, sba, "types");
+
+ create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+ ba2str(dba, addr);
+
+ snprintf(chars, sizeof(chars), "%2.2X", type);
+
+ return textfile_put(filename, addr, chars);
+}
+
+device_type_t read_device_type(const bdaddr_t *sba, const bdaddr_t *dba)
+{
+ char filename[PATH_MAX + 1], addr[18], *chars;
+ device_type_t type;
+
+ create_filename(filename, PATH_MAX, sba, "types");
+
+ create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+ ba2str(dba, addr);
+
+ chars = textfile_caseget(filename, addr);
+ if (chars == NULL)
+ return DEVICE_TYPE_UNKNOWN;
+
+ type = strtol(chars, NULL, 16);
+
+ free(chars);
+
+ return type;
+}
diff --git a/src/storage.h b/src/storage.h
index c7e342c..f36cefb 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -91,6 +91,9 @@ 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 write_device_type(const bdaddr_t *sba, const bdaddr_t *dba,
+ device_type_t type);
+device_type_t read_device_type(const bdaddr_t *sba, const bdaddr_t *dba);
#define PNP_UUID "00001200-0000-1000-8000-00805f9b34fb"
--
1.7.3.4
^ permalink raw reply related
* [PATCH 03/18] Move primary service storage to device.c
From: Vinicius Costa Gomes @ 2010-12-21 21:26 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Sheldon Demario
In-Reply-To: <1292966800-6264-1-git-send-email-vinicius.gomes@openbossa.org>
From: Sheldon Demario <sheldon.demario@openbossa.org>
Discover All Primary Services has beed moved to device.c in order
to follow a similar approach of BR/EDR service records.
---
attrib/att.c | 5 +++++
attrib/att.h | 7 +++++++
attrib/client.c | 41 -----------------------------------------
attrib/gattrib.c | 1 +
src/device.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
src/glib-helper.c | 24 ++++++++++++++++--------
6 files changed, 72 insertions(+), 50 deletions(-)
diff --git a/attrib/att.c b/attrib/att.c
index f8dbc02..6c2d799 100644
--- a/attrib/att.c
+++ b/attrib/att.c
@@ -78,6 +78,11 @@ const char *att_ecode2str(uint8_t status)
}
}
+void att_primary_free(struct att_primary *prim)
+{
+ g_free(prim);
+}
+
void att_data_list_free(struct att_data_list *list)
{
int i;
diff --git a/attrib/att.h b/attrib/att.h
index 0b8612e..17124d7 100644
--- a/attrib/att.h
+++ b/attrib/att.h
@@ -137,6 +137,12 @@ struct att_range {
uint16_t end;
};
+struct att_primary {
+ char uuid[MAX_LEN_UUID_STR + 1];
+ uint16_t start;
+ uint16_t end;
+};
+
/* These functions do byte conversion */
static inline uint8_t att_get_u8(const void *ptr)
{
@@ -172,6 +178,7 @@ static inline void att_put_u32(uint16_t src, void *dst)
}
void att_data_list_free(struct att_data_list *list);
+void att_primary_free(struct att_primary *prim);
const char *att_ecode2str(uint8_t status);
uint16_t enc_read_by_grp_req(uint16_t start, uint16_t end, uuid_t *uuid,
diff --git a/attrib/client.c b/attrib/client.c
index 69e4fb8..00d0bbc 100644
--- a/attrib/client.c
+++ b/attrib/client.c
@@ -1086,35 +1086,6 @@ static void load_attribute_data(char *key, char *value, void *data)
chr->format = attr_data_from_string(value + MAX_LEN_UUID_STR);
}
-static char *primary_list_to_string(GSList *primary_list)
-{
- GString *services;
- GSList *l;
-
- services = g_string_new(NULL);
-
- for (l = primary_list; l; l = l->next) {
- struct primary *primary = l->data;
- uuid_t *uuid128;
- char service[64];
- char uuidstr[MAX_LEN_UUID_STR];
-
- memset(service, 0, sizeof(service));
-
- uuid128 = sdp_uuid_to_uuid128(&primary->uuid);
- sdp_uuid2strn(uuid128, uuidstr, MAX_LEN_UUID_STR);
-
- bt_free(uuid128);
-
- snprintf(service, sizeof(service), "%04X#%04X#%s ",
- primary->start, primary->end, uuidstr);
-
- services = g_string_append(services, service);
- }
-
- return g_string_free(services, FALSE);
-}
-
static GSList *string_to_primary_list(struct gatt_service *gatt,
const char *str)
{
@@ -1158,17 +1129,6 @@ static GSList *string_to_primary_list(struct gatt_service *gatt,
return l;
}
-static void store_primary_services(struct gatt_service *gatt)
-{
- char *services;
-
- services = primary_list_to_string(gatt->primary);
-
- write_device_services(&gatt->sba, &gatt->dba, services);
-
- g_free(services);
-}
-
static gboolean load_primary_services(struct gatt_service *gatt)
{
GSList *primary_list;
@@ -1225,7 +1185,6 @@ static void primary_cb(guint8 status, const guint8 *pdu, guint16 plen,
if (gatt->primary == NULL)
goto done;
- store_primary_services(gatt);
register_primary(gatt);
g_slist_foreach(gatt->primary, discover_all_char, gatt);
diff --git a/attrib/gattrib.c b/attrib/gattrib.c
index eace01b..9268001 100644
--- a/attrib/gattrib.c
+++ b/attrib/gattrib.c
@@ -30,6 +30,7 @@
#include <bluetooth/bluetooth.h>
#include <bluetooth/sdp.h>
+#include <bluetooth/sdp_lib.h>
#include "att.h"
#include "btio.h"
diff --git a/src/device.c b/src/device.c
index c306e43..4bf9b52 100644
--- a/src/device.c
+++ b/src/device.c
@@ -45,6 +45,7 @@
#include "log.h"
#include "textfile.h"
+#include "att.h"
#include "hcid.h"
#include "adapter.h"
#include "device.h"
@@ -1518,10 +1519,36 @@ static void init_browse(struct browse_req *req, gboolean reverse)
l->data);
}
+static char *primary_list_to_string(GSList *primary_list)
+{
+ GString *services;
+ GSList *l;
+
+ services = g_string_new(NULL);
+
+ for (l = primary_list; l; l = l->next) {
+ struct att_primary *primary = l->data;
+ char service[64];
+
+ memset(service, 0, sizeof(service));
+
+ snprintf(service, sizeof(service), "%04X#%04X#%s ",
+ primary->start, primary->end, primary->uuid);
+
+ services = g_string_append(services, service);
+ }
+
+ return g_string_free(services, FALSE);
+}
+
static void primary_cb(GSList *services, int err, gpointer user_data)
{
struct browse_req *req = user_data;
struct btd_device *device = req->device;
+ struct btd_adapter *adapter = device->adapter;
+ GSList *l, *uuids = NULL;
+ bdaddr_t dba, sba;
+ char *str;
if (err) {
DBusMessage *reply;
@@ -1532,10 +1559,25 @@ static void primary_cb(GSList *services, int err, gpointer user_data)
services_changed(device);
device_set_temporary(device, FALSE);
- device_probe_drivers(device, services);
+
+ for (l = services; l; l = l->next) {
+ struct att_primary *prim = l->data;
+ uuids = g_slist_append(uuids, prim->uuid);
+ }
+
+ device_probe_drivers(device, uuids);
+ g_slist_free(uuids);
create_device_reply(device, req);
+ str = primary_list_to_string(services);
+
+ adapter_get_address(adapter, &sba);
+ device_get_address(device, &dba);
+
+ write_device_services(&sba, &dba, str);
+ g_free(str);
+
done:
device->browse = NULL;
browse_request_free(req);
diff --git a/src/glib-helper.c b/src/glib-helper.c
index bf39a83..4bd6a50 100644
--- a/src/glib-helper.c
+++ b/src/glib-helper.c
@@ -55,7 +55,7 @@ struct gattrib_context {
bt_primary_t cb;
bt_destroy_t destroy;
gpointer user_data;
- GSList *uuids;
+ GSList *primaries;
};
static GSList *gattrib_list = NULL;
@@ -75,8 +75,8 @@ static void gattrib_context_free(struct gattrib_context *ctxt)
if (ctxt->destroy)
ctxt->destroy(ctxt->user_data);
- g_slist_foreach(ctxt->uuids, (GFunc) g_free, NULL);
- g_slist_free(ctxt->uuids);
+ g_slist_foreach(ctxt->primaries, (GFunc) att_primary_free, NULL);
+ g_slist_free(ctxt->primaries);
g_attrib_unref(ctxt->attrib);
if (ctxt->io) {
g_io_channel_unref(ctxt->io);
@@ -439,7 +439,7 @@ static void primary_cb(guint8 status, const guint8 *pdu, guint16 plen,
struct gattrib_context *ctxt = user_data;
struct att_data_list *list;
unsigned int i, err;
- uint16_t end;
+ uint16_t start, end;
if (status == ATT_ECODE_ATTR_NOT_FOUND) {
err = 0;
@@ -459,9 +459,10 @@ static void primary_cb(guint8 status, const guint8 *pdu, guint16 plen,
for (i = 0, end = 0; i < list->num; i++) {
const uint8_t *data = list->data[i];
- char *prim;
+ struct att_primary *primary;
uuid_t u128, u16;
+ start = att_get_u16(&data[0]);
end = att_get_u16(&data[2]);
if (list->len == 6) {
@@ -475,8 +476,15 @@ static void primary_cb(guint8 status, const guint8 *pdu, guint16 plen,
/* Skipping invalid data */
continue;
- prim = bt_uuid2string(&u128);
- ctxt->uuids = g_slist_append(ctxt->uuids, prim);
+ primary = g_try_new0(struct att_primary, 1);
+ if (!primary) {
+ err = -ENOMEM;
+ goto done;
+ }
+ primary->start = start;
+ primary->end = end;
+ sdp_uuid2strn(&u128, primary->uuid, sizeof(primary->uuid));
+ ctxt->primaries = g_slist_append(ctxt->primaries, primary);
}
att_data_list_free(list);
@@ -489,7 +497,7 @@ static void primary_cb(guint8 status, const guint8 *pdu, guint16 plen,
}
done:
- ctxt->cb(ctxt->uuids, err, ctxt->user_data);
+ ctxt->cb(ctxt->primaries, err, ctxt->user_data);
gattrib_context_free(ctxt);
}
--
1.7.3.4
^ permalink raw reply related
* [PATCH 02/18] Fix memory leaks in the attrib-server
From: Vinicius Costa Gomes @ 2010-12-21 21:26 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Vinicius Costa Gomes
In-Reply-To: <1292966800-6264-1-git-send-email-vinicius.gomes@openbossa.org>
---
src/attrib-server.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/src/attrib-server.c b/src/attrib-server.c
index 18759e7..cbc01ee 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -724,6 +724,7 @@ static void connect_event(GIOChannel *io, GError *err, void *user_data)
channel->attrib = g_attrib_new(io);
channel->mtu = ATT_DEFAULT_MTU;
+ g_io_channel_unref(io);
channel->id = g_attrib_register(channel->attrib, GATTRIB_ALL_EVENTS,
channel_handler, channel, NULL);
@@ -803,6 +804,11 @@ failed:
g_io_channel_unref(l2cap_io);
l2cap_io = NULL;
+ if (le_io) {
+ g_io_channel_unref(le_io);
+ le_io = NULL;
+ }
+
return -1;
}
--
1.7.3.4
^ permalink raw reply related
* [PATCH 01/18] Fix attrib plugin deregistration
From: Vinicius Costa Gomes @ 2010-12-21 21:26 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Vinicius Costa Gomes
In-Reply-To: <1292966800-6264-1-git-send-email-vinicius.gomes@openbossa.org>
As the comparison method used for find what to de-register was
wrong, it was causing the btd_device reference that the attrib
plugin was keeping never to be dropped.
---
attrib/client.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/attrib/client.c b/attrib/client.c
index 8e96af4..69e4fb8 100644
--- a/attrib/client.c
+++ b/attrib/client.c
@@ -167,7 +167,7 @@ static int gatt_dev_cmp(gconstpointer a, gconstpointer b)
const struct gatt_service *gatt = a;
const struct btd_device *dev = b;
- return gatt->dev == dev;
+ return gatt->dev != dev;
}
static int characteristic_handle_cmp(gconstpointer a, gconstpointer b)
--
1.7.3.4
^ permalink raw reply related
* [PATCH 00/18] Making GATT a first class citizen
From: Vinicius Costa Gomes @ 2010-12-21 21:26 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Vinicius Costa Gomes
Hi,
These are the first steps in the direction of making GATT a first
class citizen in Bluez.
For this, the first step is to move the primary service discovery
procedure to the core bluetoothd. For that we needed to move a lot of
code around, and add a few features, for example, we now are able to
store the remote device type and restore it from storage, it is useful
when deciding which medium should be used for service discovery.
While doing this, I noticed something that could cause some confusion:
in the Attribute API, both the Device Service hierarchy
([prefix]/{hci0}/{device0}/{service0}) and the Device Characteristic
([prefix]/{hci0}/{device0}/{service0}/{characteristic0}) have the same
Interface name (org.bluez.Characteristic). Is that on purpose?
Cheers,
--
Sheldon Demario (1):
Move primary service storage to device.c
Vinicius Costa Gomes (17):
Fix attrib plugin deregistration
Fix memory leaks in the attrib-server
Add a way to store the remote device type
Add support for storing the device type
Add support for creating devices from stored types
Add support for creating devices from stored primary services
Add a way to retrieve ATT primary services
Remove GATT information when the device is removed
Add the btd_ prefix to device_add_service
Remove duplicated code for discovering GATT services
Clean up the primary service DBus registration
Add support for making LE connections to GATT client
Add a Discover method to the GATT Client
Remove GetCharacteristics DBus method
Add support for adding services to the Services property
Add GetProperties method the Service Interface
Add a "services" command to test-device
attrib/att.c | 5 +
attrib/att.h | 7 +
attrib/client.c | 449 ++++++++++-----------------------------------------
attrib/gattrib.c | 1 +
input/device.c | 4 +-
plugins/hciops.c | 2 +-
serial/port.c | 2 +
src/adapter.c | 105 ++++++++++++
src/attrib-server.c | 6 +
src/device.c | 82 +++++++++-
src/device.h | 6 +-
src/glib-helper.c | 23 ++-
src/storage.c | 40 +++++
src/storage.h | 3 +
test/test-device | 13 ++
15 files changed, 366 insertions(+), 382 deletions(-)
--
1.7.3.4
^ permalink raw reply
* [PATCH v5] Bluetooth: Fix __hci_request synchronization for hci_open_dev
From: johan.hedberg @ 2010-12-21 21:01 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@nokia.com>
The initialization function used by hci_open_dev (hci_init_req) sends
many different HCI commands. The __hci_request function should only
return when all of these commands have completed (or a timeout occurs).
Several of these commands cause hci_req_complete to be called which
causes __hci_request to return prematurely.
This patch fixes the issue by adding a new hdev->req_last_cmd variable
which is set during the initialization procedure. The hci_req_complete
function will no longer mark the request as complete until the command
matching hdev->req_last_cmd completes.
Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
---
v5: comment added for req_last_cmd check as well as empty line added to
hci_init_req as requested
include/net/bluetooth/hci_core.h | 3 ++-
net/bluetooth/hci_core.c | 15 ++++++++++++---
net/bluetooth/hci_event.c | 33 +++++++++++++++++++++++----------
3 files changed, 37 insertions(+), 14 deletions(-)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 3786ee8..a29feb0 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -129,6 +129,7 @@ struct hci_dev {
wait_queue_head_t req_wait_q;
__u32 req_status;
__u32 req_result;
+ __u16 req_last_cmd;
struct inquiry_cache inq_cache;
struct hci_conn_hash conn_hash;
@@ -693,6 +694,6 @@ struct hci_sec_filter {
#define hci_req_lock(d) mutex_lock(&d->req_lock)
#define hci_req_unlock(d) mutex_unlock(&d->req_lock)
-void hci_req_complete(struct hci_dev *hdev, int result);
+void hci_req_complete(struct hci_dev *hdev, __u16 cmd, int result);
#endif /* __HCI_CORE_H */
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 1a4ec97..8b602d8 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -91,9 +91,16 @@ static void hci_notify(struct hci_dev *hdev, int event)
/* ---- HCI requests ---- */
-void hci_req_complete(struct hci_dev *hdev, int result)
+void hci_req_complete(struct hci_dev *hdev, __u16 cmd, int result)
{
- BT_DBG("%s result 0x%2.2x", hdev->name, result);
+ BT_DBG("%s command 0x%04x result 0x%2.2x", hdev->name, cmd, result);
+
+ /* If the request has set req_last_cmd (typical for multi-HCI
+ * command requests) check if the completed command matches
+ * this, and if not just return. Single HCI command requests
+ * typically leave req_last_cmd as 0 */
+ if (hdev->req_last_cmd && cmd != hdev->req_last_cmd)
+ return;
if (hdev->req_status == HCI_REQ_PEND) {
hdev->req_result = result;
@@ -149,7 +156,7 @@ static int __hci_request(struct hci_dev *hdev, void (*req)(struct hci_dev *hdev,
break;
}
- hdev->req_status = hdev->req_result = 0;
+ hdev->req_last_cmd = hdev->req_status = hdev->req_result = 0;
BT_DBG("%s end: err %d", hdev->name, err);
@@ -252,6 +259,8 @@ static void hci_init_req(struct hci_dev *hdev, unsigned long opt)
/* Connection accept timeout ~20 secs */
param = cpu_to_le16(0x7d00);
hci_send_cmd(hdev, HCI_OP_WRITE_CA_TIMEOUT, 2, ¶m);
+
+ hdev->req_last_cmd = HCI_OP_WRITE_CA_TIMEOUT;
}
static void hci_scan_req(struct hci_dev *hdev, unsigned long opt)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 8923b36..3810017 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -58,7 +58,7 @@ static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb)
clear_bit(HCI_INQUIRY, &hdev->flags);
- hci_req_complete(hdev, status);
+ hci_req_complete(hdev, HCI_OP_INQUIRY_CANCEL, status);
hci_conn_check_pending(hdev);
}
@@ -174,7 +174,7 @@ static void hci_cc_write_def_link_policy(struct hci_dev *hdev, struct sk_buff *s
if (!status)
hdev->link_policy = get_unaligned_le16(sent);
- hci_req_complete(hdev, status);
+ hci_req_complete(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, status);
}
static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
@@ -183,7 +183,7 @@ static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
BT_DBG("%s status 0x%x", hdev->name, status);
- hci_req_complete(hdev, status);
+ hci_req_complete(hdev, HCI_OP_RESET, status);
}
static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
@@ -235,7 +235,7 @@ static void hci_cc_write_auth_enable(struct hci_dev *hdev, struct sk_buff *skb)
clear_bit(HCI_AUTH, &hdev->flags);
}
- hci_req_complete(hdev, status);
+ hci_req_complete(hdev, HCI_OP_WRITE_AUTH_ENABLE, status);
}
static void hci_cc_write_encrypt_mode(struct hci_dev *hdev, struct sk_buff *skb)
@@ -258,7 +258,7 @@ static void hci_cc_write_encrypt_mode(struct hci_dev *hdev, struct sk_buff *skb)
clear_bit(HCI_ENCRYPT, &hdev->flags);
}
- hci_req_complete(hdev, status);
+ hci_req_complete(hdev, HCI_OP_WRITE_ENCRYPT_MODE, status);
}
static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb)
@@ -285,7 +285,7 @@ static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb)
set_bit(HCI_PSCAN, &hdev->flags);
}
- hci_req_complete(hdev, status);
+ hci_req_complete(hdev, HCI_OP_WRITE_SCAN_ENABLE, status);
}
static void hci_cc_read_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb)
@@ -383,7 +383,7 @@ static void hci_cc_host_buffer_size(struct hci_dev *hdev, struct sk_buff *skb)
BT_DBG("%s status 0x%x", hdev->name, status);
- hci_req_complete(hdev, status);
+ hci_req_complete(hdev, HCI_OP_HOST_BUFFER_SIZE, status);
}
static void hci_cc_read_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb)
@@ -536,7 +536,16 @@ static void hci_cc_read_bd_addr(struct hci_dev *hdev, struct sk_buff *skb)
if (!rp->status)
bacpy(&hdev->bdaddr, &rp->bdaddr);
- hci_req_complete(hdev, rp->status);
+ hci_req_complete(hdev, HCI_OP_READ_BD_ADDR, rp->status);
+}
+
+static void hci_cc_write_ca_timeout(struct hci_dev *hdev, struct sk_buff *skb)
+{
+ __u8 status = *((__u8 *) skb->data);
+
+ BT_DBG("%s status 0x%x", hdev->name, status);
+
+ hci_req_complete(hdev, HCI_OP_WRITE_CA_TIMEOUT, status);
}
static inline void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
@@ -544,7 +553,7 @@ static inline void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
BT_DBG("%s status 0x%x", hdev->name, status);
if (status) {
- hci_req_complete(hdev, status);
+ hci_req_complete(hdev, HCI_OP_INQUIRY, status);
hci_conn_check_pending(hdev);
} else
@@ -871,7 +880,7 @@ static inline void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff
clear_bit(HCI_INQUIRY, &hdev->flags);
- hci_req_complete(hdev, status);
+ hci_req_complete(hdev, HCI_OP_INQUIRY, status);
hci_conn_check_pending(hdev);
}
@@ -1379,6 +1388,10 @@ static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *sk
hci_cc_read_bd_addr(hdev, skb);
break;
+ case HCI_OP_WRITE_CA_TIMEOUT:
+ hci_cc_write_ca_timeout(hdev, skb);
+ break;
+
default:
BT_DBG("%s opcode 0x%x", hdev->name, opcode);
break;
--
1.7.2.3
^ permalink raw reply related
* Re: [RFC] LE General Discovery Procedure
From: Brian Gix @ 2010-12-21 20:24 UTC (permalink / raw)
To: Claudio Takahasi; +Cc: BlueZ development
In-Reply-To: <AANLkTi=px0CQY+W9PqrjMHZGQ6RdXgbd-iQo=K8AA_H6@mail.gmail.com>
Hi Claudio,
On Tue, 2010-12-21 at 17:12 -0300, Claudio Takahasi wrote:
> Hi folks,
>
[snip]
> We may need to represent the Broadcaster devices creating a D-Bus
> device object, it is still unclear to me at the moment. So I have
> three suggestions(I prefer the first):
> 1. Report Peripheral and Broadcaster using DeviceFound() signal and
> add an property to identify the role. eg: Broadcaster=false/true
I also prefer this solution. The higher layer app or entity should then
filter out any devices that it is not interested in, and should be
examining the properties of all the devices reported to it. Along with
a Broadcaster property, there should be other properties that indicate
other details such as Pubic/Private addresses, etc.
> 2. Ignore the Broadcaster devices. Means that it will not be possible
> to call CreateDevice for these devices.
Don't like this idea, because at some point BlueZ we be used in a device
which *will* need to be aware of the existence of Broadcaster devices.
And the CreateDevice paradigm is probably to best way to represent these
remote devices.
> 3. Add a config option to change the discovery behavior to ignore
> Broadcaster devices. For qualification test only.
Not a good idea. At the end of the day, a device should be qualifiable
regardless of it's configuration.
>
> If we choose the first, for qualification test I guess it will be
> enough to add an extra filter to ignore the broadcaster devices in the
> BlueZ test script.
I agree.
>
> Regards,
> Claudio
--
Brian Gix
bgix@codeaurora.org
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
^ permalink raw reply
* [RFC] LE General Discovery Procedure
From: Claudio Takahasi @ 2010-12-21 20:12 UTC (permalink / raw)
To: BlueZ development
Hi folks,
I'd like to receive opinions of how we should implement the General
Discovery procedure aligned to UI/API and Bluetooth Qualification.
The current implementation reports all found devices using the D-Bus
signal DeviceFound(), Flags AD Type is ignored at the moment, meaning
that Broadcaster and Peripheral are reported.
>From Bluetooth SPEC: General Discovery Procedure - page 1704
"The Host shall check for the Flags AD type in the advertising data.
If the Flags AD type is present and either the LE General Discoverable
Mode flag is set to one or the LE Limited Discoverable Mode flag is
set to one then the Host shall consider the device as a discovered
device, otherwise the advertising data shall be ignored."
GAP Test Requirement document says that "General Discovery Procedure
Does not find Broadcast device"
We may need to represent the Broadcaster devices creating a D-Bus
device object, it is still unclear to me at the moment. So I have
three suggestions(I prefer the first):
1. Report Peripheral and Broadcaster using DeviceFound() signal and
add an property to identify the role. eg: Broadcaster=false/true
2. Ignore the Broadcaster devices. Means that it will not be possible
to call CreateDevice for these devices.
3. Add a config option to change the discovery behavior to ignore
Broadcaster devices. For qualification test only.
If we choose the first, for qualification test I guess it will be
enough to add an extra filter to ignore the broadcaster devices in the
BlueZ test script.
Regards,
Claudio
^ permalink raw reply
* Re: [RFC 0/1] Implement Compound (Multi-step) GATT Procedure Support
From: Brian Gix @ 2010-12-21 19:50 UTC (permalink / raw)
To: Claudio Takahasi; +Cc: vinicius.gomes, linux-bluetooth
In-Reply-To: <AANLkTin8BHWOhpnv36ncteMNRfXwU81r17owAAaixiD-@mail.gmail.com>
Hi Caudio,
On Tue, 2010-12-21 at 16:25 -0300, Claudio Takahasi wrote:
> Hi Brian,
>
> On Tue, Dec 21, 2010 at 2:25 PM, Brian Gix <bgix@codeaurora.org> wrote:
> > Hi Claudio & Vinicius,
> >
> >
> > On Fri, 2010-12-17 at 14:48 -0800, Brian Gix wrote:
> >> The following two proposed patches implement a method for correctly
> >> staging GATT procedures that require multiple ATT req/resp exchanges.
> >
> > If you guys get a chance, could you consider this proposed change
> > to gattrib.[ch] and the subsequent change to gatt.c? It differs from my
> > initial proposed patch which subverted the gattrib queuing mechanism. It
> > now lets each ATT command run to completion. It also fixes the memory
> > leak potential that Vinicius spotted. I think it is important that you
> > give it at least a cursory look, because you guys know more about bluez
> > GATT than anyone else here at this point. Otherwise, I will resubmit
> > this version as a patch request. -- thx
> >
>
> ok. We can review your patches.
> Could you please send patches to change gatttool to support this new feature?
> How are you testing it? Do you have a modified BlueZ attribute server
> or another GATT server?
There are no changes required to gatttool. The implemented high level
function is still to read an attribute, and the function works the same
if the remote attribute is shorter than 22 octets, and will be "long"
only if the first response indicates a remote attribute of 22 octets or
longer. (accounting for the one octet for the response hdr)
I am testing this against against the internal Qualcomm GATT server,
which has been tested at the past two UPFs. This is also the same stack
which I hope to use to pre-vet the SM changes you are leading, prior to
the UPF in Las Vegas.
As my next task, I could implement the capability to support long reads
in the BlueZ GATT server. (likely followed by long writes in both the
GATT client and server of BlueZ)
>
> Claudio
Thanks,
--
Brian Gix
bgix@codeaurora.org
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
^ permalink raw reply
* Re: [RFC 0/1] Implement Compound (Multi-step) GATT Procedure Support
From: Claudio Takahasi @ 2010-12-21 19:25 UTC (permalink / raw)
To: Brian Gix; +Cc: vinicius.gomes, linux-bluetooth
In-Reply-To: <1292952355.14993.9.camel@sealablnx02.qualcomm.com>
Hi Brian,
On Tue, Dec 21, 2010 at 2:25 PM, Brian Gix <bgix@codeaurora.org> wrote:
> Hi Claudio & Vinicius,
>
>
> On Fri, 2010-12-17 at 14:48 -0800, Brian Gix wrote:
>> The following two proposed patches implement a method for correctly
>> staging GATT procedures that require multiple ATT req/resp exchanges.
>
> If you guys get a chance, could you consider this proposed change
> to gattrib.[ch] and the subsequent change to gatt.c? It differs from my
> initial proposed patch which subverted the gattrib queuing mechanism. It
> now lets each ATT command run to completion. It also fixes the memory
> leak potential that Vinicius spotted. I think it is important that you
> give it at least a cursory look, because you guys know more about bluez
> GATT than anyone else here at this point. Otherwise, I will resubmit
> this version as a patch request. -- thx
>
ok. We can review your patches.
Could you please send patches to change gatttool to support this new feature?
How are you testing it? Do you have a modified BlueZ attribute server
or another GATT server?
Claudio
^ permalink raw reply
* Re: [PATCH] sbc: detect when bitpool has changed
From: Brian Gix @ 2010-12-21 18:02 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <1292950724-4918-1-git-send-email-luiz.dentz@gmail.com>
Hello Luiz,
On Tue, 2010-12-21 at 18:58 +0200, Luiz Augusto von Dentz wrote:
> From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com>
>
> ---
> sbc/sbc.c | 8 +++++---
> 1 files changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/sbc/sbc.c b/sbc/sbc.c
> index a6391ae..b3a7a09 100644
> --- a/sbc/sbc.c
> +++ b/sbc/sbc.c
> @@ -965,7 +965,8 @@ ssize_t sbc_decode(sbc_t *sbc, const void *input, size_t input_len,
>
> framelen = sbc_unpack_frame(input, &priv->frame, input_len);
>
> - if (!priv->init) {
> + /* init if no previous frame was encode or bitpool has changed */
> + if (!priv->init || priv->frame.bitpool != sbc->bitpool) {
> sbc_decoder_init(&priv->dec_state, &priv->frame);
> priv->init = 1;
I don't think it is a good idea to reinitialize the SBC decoder if a
change in bitpool size is detected.
The A2DP and AVDTP specifications do not allow most of the parameters to
change from one frame to the next (mode, channels, subbands, blocks,
allocation, frequency) but explicitly DO allow changes in bitpool size
midstream. This allows for Variable Bit Rate (VBR) streaming, and adds
efficiency to the over-the-air link with no quality loss. Also, the
space required for decoding does not change just because the bitpool has
changed, so re-initialization should not be required.
The only things that should be different from one SBC frame to the next
is the bitpool of course, and the framelen. That said, if a bitpool
change is detected the only thing within that "IF" block that should be
updated is:
sbc->bitpool
If any of the other afore mentioned parameters change, the stream should
be terminated.
>
> @@ -1035,7 +1036,8 @@ ssize_t sbc_encode(sbc_t *sbc, const void *input, size_t input_len,
> if (written)
> *written = 0;
>
> - if (!priv->init) {
> + /* init if no previous frame was encode or bitpool has changed */
> + if (!priv->init || priv->frame.bitpool != sbc->bitpool) {
> priv->frame.frequency = sbc->frequency;
> priv->frame.mode = sbc->mode;
> priv->frame.channels = sbc->mode == SBC_MODE_MONO ? 1 : 2;
Same basic comment here, although it is perfectly allowable for the
Encoder to not support VBR. However if the Encoder does change the
bitpool, then the list of fields that need to be updated are:
priv->frame.bitpool
priv->frame.length
But again, the sbc_encoder_init should *not* be re-run. I would pull
those two variables out of that IF block, and set them in their own IF
block either directly before or directly after the !priv->init IF block.
> @@ -1120,7 +1122,7 @@ size_t sbc_get_frame_length(sbc_t *sbc)
> struct sbc_priv *priv;
>
> priv = sbc->priv;
> - if (priv->init)
> + if (priv->init && priv->frame.bitpool == sbc->bitpool)
> return priv->frame.length;
>
> subbands = sbc->subbands ? 8 : 4;
This is a valid change, because bitpool changes do indeed change the
frame.length.
--
Brian Gix
bgix@codeaurora.org
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
^ permalink raw reply
* AVRCP connect failing with Interop headset-Buffalo
From: roystonr @ 2010-12-21 17:35 UTC (permalink / raw)
To: linux-bluetooth
Cc: Luiz Augusto von Dentz, Johan Hedberg, roystonr, rshaffer,
skrovvid
Hi,
During Interop testing with Buffalo headset (supporting A2DP+AVRCP), its
observed that the A2DP connection is failing.
>From the sniffer logs, its observed that the DUT (Device under test)
issues avrcp_connect even before the l2cap connections for avdtp transport
and signaling are completed. Its also observed from the sniffer logs that
the remote side hasnt responded to one of the DUTs l2cap connection
request, before the DUT initiates the avrcp_connect.
As an experiment, by modifying the CONTROL_CONNECT_TIMEOUT (in device.c)
value from 2 to 5 seconds this issue with the mentioned headset is
avoided.
To my understanding, CONTROL_CONNECT_TIMEOUT controls the interval at
which the avrcp_connect is initiated from the DUT i.e. if the stream setup
is active then the timer is kicked in to delay the DUT side avrcp_connect.
Though by increasing the CONTROL_CONNECT_TIMEOUT value, this issue with
the headset under test is avoided. The ideal way would be to trigger the
DUT initiated avrcp_connect only after the l2cap connections are
completed. Correct me if my understanding is wrong.
Kindly provide reference as to how to control the DUT initiated
avrcp_connect only after ensuring that the l2cap connections are
completed. Or is it safe to the modify CONTROL_CONNECT_TIMEOUT value as
mentioned above.
Regards,
Royston Rodrigues.
"Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum."
^ permalink raw reply
* Re: [RFC 0/1] Implement Compound (Multi-step) GATT Procedure Support
From: Brian Gix @ 2010-12-21 17:25 UTC (permalink / raw)
To: claudio.takahasi, vinicius.gomes; +Cc: linux-bluetooth
In-Reply-To: <1292626132-30029-1-git-send-email-bgix@codeaurora.org>
Hi Claudio & Vinicius,
On Fri, 2010-12-17 at 14:48 -0800, Brian Gix wrote:
> The following two proposed patches implement a method for correctly
> staging GATT procedures that require multiple ATT req/resp exchanges.
If you guys get a chance, could you consider this proposed change
to gattrib.[ch] and the subsequent change to gatt.c? It differs from my
initial proposed patch which subverted the gattrib queuing mechanism. It
now lets each ATT command run to completion. It also fixes the memory
leak potential that Vinicius spotted. I think it is important that you
give it at least a cursory look, because you guys know more about bluez
GATT than anyone else here at this point. Otherwise, I will resubmit
this version as a patch request. -- thx
>
> The first RFC / PATCH is gattrib.[ch], which allows the caller to specify
> a gboolean indicating that the command being queued is Compound
> (even if the procedure ends up being single/atomic) and a queue ID
> number, which allows the caller to cancel the GATT procedure at any
> stage of the transaction.
>
> IF -
> The ATT opcode being queued is specified as compound, the resulting response
> will not cause the next item in the queue to be sent until *after* the
> response has been forwarded to the caller via the response callback.
>
> IF -
> The ATT opcode being queued is *not* compound, the resulting response
> will service the pkt queue immediately (legacy functionality).
>
> IF -
> The ID passed to g_attrib_send_seq is ZERO, the command pkt will
> be added to the TAIL of the queue, and a new ID assigned to it.
> (Legacy functionality)
>
> IF -
> The ID passed to g_attrib_send_seq is NON-ZERO, the command pkt
> will be added to the HEAD of the queue, causing it to be the next
> pkt sent to the remote device. The NON-ZERO ID is also then able
> to cancel the command.
>
>
> The second RFC / PATCH is to gatt.c. It modifies the existing gatt_read_char()
> function to recognize the need for a compound Read procedure, and implements
> it as a READ_REQ + READ_BLOB_REQ + READ_BLOB_REQ ...<etc> as needed, using
> the g_attrib_send_seq() logic from the first RFC / PATCH.
>
^ permalink raw reply
* [PATCH] sbc: detect when bitpool has changed
From: Luiz Augusto von Dentz @ 2010-12-21 16:58 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com>
---
sbc/sbc.c | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/sbc/sbc.c b/sbc/sbc.c
index a6391ae..b3a7a09 100644
--- a/sbc/sbc.c
+++ b/sbc/sbc.c
@@ -965,7 +965,8 @@ ssize_t sbc_decode(sbc_t *sbc, const void *input, size_t input_len,
framelen = sbc_unpack_frame(input, &priv->frame, input_len);
- if (!priv->init) {
+ /* init if no previous frame was encode or bitpool has changed */
+ if (!priv->init || priv->frame.bitpool != sbc->bitpool) {
sbc_decoder_init(&priv->dec_state, &priv->frame);
priv->init = 1;
@@ -1035,7 +1036,8 @@ ssize_t sbc_encode(sbc_t *sbc, const void *input, size_t input_len,
if (written)
*written = 0;
- if (!priv->init) {
+ /* init if no previous frame was encode or bitpool has changed */
+ if (!priv->init || priv->frame.bitpool != sbc->bitpool) {
priv->frame.frequency = sbc->frequency;
priv->frame.mode = sbc->mode;
priv->frame.channels = sbc->mode == SBC_MODE_MONO ? 1 : 2;
@@ -1120,7 +1122,7 @@ size_t sbc_get_frame_length(sbc_t *sbc)
struct sbc_priv *priv;
priv = sbc->priv;
- if (priv->init)
+ if (priv->init && priv->frame.bitpool == sbc->bitpool)
return priv->frame.length;
subbands = sbc->subbands ? 8 : 4;
--
1.7.1
^ permalink raw reply related
* RE: problem to disconnect with bluez-test
From: Goubert, TonyX @ 2010-12-21 15:57 UTC (permalink / raw)
To: Johan Hedberg; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <20101221092421.GA17157@jh-x301>
Hi Johan,
Thank you for your answer.
Yes, in fact, I want to use the test scripts in bluez to disconnect a device.
Well, I download the latest version of bluez (Bluez-4.82) and I have not find the command 'disconnect' in the script 'test-device'.
There are : list, create, remove, ... no disconnect.
> I just went ahead and pushed a patch for it upstream.
Can you give me your patch?
BR
--
Tony Goubert
tonyx.goubert@intel.com
-----Original Message-----
From: linux-bluetooth-owner@vger.kernel.org [mailto:linux-bluetooth-owner@vger.kernel.org] On Behalf Of Johan Hedberg
Sent: Tuesday, December 21, 2010 10:24 AM
To: Goubert, TonyX
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: problem to disconnect with bluez-test
Hi Tony,
On Tue, Dec 21, 2010, Goubert, TonyX wrote:
> I have paired a handset with a laptop by using 'simple-agent'
> bluez-test script BUT I can't disconnect it when I use the bluez
> stack.
I suppose you mean you can't disconnect it using the test scripts that
come with BlueZ (since I'm sure you *can* disconnect it with BlueZ as
long as you use the D-Bus interface directly).
> I can remove it (./test-device remove xx:xx:xx:xx:xx:xx) but I
> want to be able to connect/disconnect/connect...
The Device.Disconnect method is indeed something that should be added to
the test-device script. I just went ahead and pushed a patch for it
upstream.
> [root@localhost test]# ./test-device disconnect xx:xx:xx:xx:xx:xx
> Unknown command
This command should work with latest git now.
Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris,
92196 Meudon Cedex, France
Registration Number: 302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
^ permalink raw reply
* [PATCH] Configure HFP/HSP endpoints if headset interface is already connected
From: Luiz Augusto von Dentz @ 2010-12-21 15:43 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com>
HFP/HSP can be connected when registering an endpoint which is different
than on a2dp where the sep cannot be configured already since it wasn't
available before.
---
audio/media.c | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/audio/media.c b/audio/media.c
index b28bb33..97a60a1 100644
--- a/audio/media.c
+++ b/audio/media.c
@@ -42,6 +42,7 @@
#include "transport.h"
#include "a2dp.h"
#include "headset.h"
+#include "manager.h"
#ifndef DBUS_TYPE_UNIX_FD
#define DBUS_TYPE_UNIX_FD -1
@@ -200,10 +201,18 @@ static struct media_endpoint *media_endpoint_create(struct media_adapter *adapte
if (endpoint->sep == NULL)
goto failed;
} else if (strcasecmp(uuid, HFP_AG_UUID) == 0 ||
- g_strcmp0(uuid, HSP_AG_UUID) == 0)
+ g_strcmp0(uuid, HSP_AG_UUID) == 0) {
+ struct audio_device *dev;
+
endpoint->hs_watch = headset_add_state_cb(headset_state_changed,
endpoint);
- else
+ dev = manager_find_device(NULL, &adapter->src, BDADDR_ANY,
+ AUDIO_HEADSET_INTERFACE, TRUE);
+ if (dev)
+ media_endpoint_set_configuration(endpoint, dev, NULL,
+ 0, headset_setconf_cb,
+ dev);
+ } else
goto failed;
endpoint->watch = g_dbus_add_disconnect_watch(adapter->conn, sender,
--
1.7.1
^ permalink raw reply related
* Re: [PATCH v4] Bluetooth: Fix __hci_request synchronization for hci_open_dev
From: Marcel Holtmann @ 2010-12-21 15:06 UTC (permalink / raw)
To: Johan Hedberg; +Cc: linux-bluetooth
In-Reply-To: <20101221150258.GA25824@jh-x301>
Hi Johan,
> > And actually hci_init_req is not the only function where you would need
> > to add hdev->req_last_cmd entries. There are hci_reset_req and some
> > others. Without that, the rest of your patch makes hci_req_complete a
> > non functional operation.
>
> Actually no, if req_last_cmd is 0 (which it is in all cases except
> hci_init_req) then the comparison is not done:
>
> > + if (hdev->req_last_cmd && cmd != hdev->req_last_cmd)
> > + return;
>
> I did this to keep the patch simple and to not have to change all the
> single HCI command cases. I.e. only multi-HCI command requests need to
> set this variable.
not a huge fan of this, but if you put a comment on top then I could be
convinced ;)
Regards
Marcel
^ permalink raw reply
* Re: [PATCH v4] Bluetooth: Fix __hci_request synchronization for hci_open_dev
From: Johan Hedberg @ 2010-12-21 15:02 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1292942802.2658.49.camel@aeonflux>
Hi Marcel,
On Tue, Dec 21, 2010, Marcel Holtmann wrote:
> just for style consistency add an empty line before this command.
Sure.
> And actually hci_init_req is not the only function where you would need
> to add hdev->req_last_cmd entries. There are hci_reset_req and some
> others. Without that, the rest of your patch makes hci_req_complete a
> non functional operation.
Actually no, if req_last_cmd is 0 (which it is in all cases except
hci_init_req) then the comparison is not done:
> + if (hdev->req_last_cmd && cmd != hdev->req_last_cmd)
> + return;
I did this to keep the patch simple and to not have to change all the
single HCI command cases. I.e. only multi-HCI command requests need to
set this variable.
Johan
^ permalink raw reply
* Re: [PATCH v4] Bluetooth: Fix __hci_request synchronization for hci_open_dev
From: Marcel Holtmann @ 2010-12-21 14:46 UTC (permalink / raw)
To: johan.hedberg; +Cc: linux-bluetooth
In-Reply-To: <1292590111-6564-1-git-send-email-johan.hedberg@gmail.com>
Hi Johan,
> The initialization function used by hci_open_dev (hci_init_req) sends
> many different HCI commands. The __hci_request function should only
> return when all of these commands have completed (or a timeout occurs).
> Several of these commands cause hci_req_complete to be called which
> causes __hci_request to return prematurely.
>
> This patch fixes the issue by adding a new hdev->req_last_cmd variable
> which is set during the initialization procedure. The hci_req_complete
> function will no longer mark the request as complete until the command
> matching hdev->req_last_cmd completes.
>
> Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
> ---
> v4: Use __u16 instead of int for req_last_cmd
>
> include/net/bluetooth/hci_core.h | 3 ++-
> net/bluetooth/hci_core.c | 10 +++++++---
> net/bluetooth/hci_event.c | 33 +++++++++++++++++++++++----------
> 3 files changed, 32 insertions(+), 14 deletions(-)
>
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index 3786ee8..a29feb0 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -129,6 +129,7 @@ struct hci_dev {
> wait_queue_head_t req_wait_q;
> __u32 req_status;
> __u32 req_result;
> + __u16 req_last_cmd;
>
> struct inquiry_cache inq_cache;
> struct hci_conn_hash conn_hash;
> @@ -693,6 +694,6 @@ struct hci_sec_filter {
> #define hci_req_lock(d) mutex_lock(&d->req_lock)
> #define hci_req_unlock(d) mutex_unlock(&d->req_lock)
>
> -void hci_req_complete(struct hci_dev *hdev, int result);
> +void hci_req_complete(struct hci_dev *hdev, __u16 cmd, int result);
>
> #endif /* __HCI_CORE_H */
> diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> index 1a4ec97..787c8df 100644
> --- a/net/bluetooth/hci_core.c
> +++ b/net/bluetooth/hci_core.c
> @@ -91,9 +91,12 @@ static void hci_notify(struct hci_dev *hdev, int event)
>
> /* ---- HCI requests ---- */
>
> -void hci_req_complete(struct hci_dev *hdev, int result)
> +void hci_req_complete(struct hci_dev *hdev, __u16 cmd, int result)
> {
> - BT_DBG("%s result 0x%2.2x", hdev->name, result);
> + BT_DBG("%s command 0x%04x result 0x%2.2x", hdev->name, cmd, result);
> +
> + if (hdev->req_last_cmd && cmd != hdev->req_last_cmd)
> + return;
>
> if (hdev->req_status == HCI_REQ_PEND) {
> hdev->req_result = result;
> @@ -149,7 +152,7 @@ static int __hci_request(struct hci_dev *hdev, void (*req)(struct hci_dev *hdev,
> break;
> }
>
> - hdev->req_status = hdev->req_result = 0;
> + hdev->req_last_cmd = hdev->req_status = hdev->req_result = 0;
>
> BT_DBG("%s end: err %d", hdev->name, err);
>
> @@ -252,6 +255,7 @@ static void hci_init_req(struct hci_dev *hdev, unsigned long opt)
> /* Connection accept timeout ~20 secs */
> param = cpu_to_le16(0x7d00);
> hci_send_cmd(hdev, HCI_OP_WRITE_CA_TIMEOUT, 2, ¶m);
> + hdev->req_last_cmd = HCI_OP_WRITE_CA_TIMEOUT;
just for style consistency add an empty line before this command.
And actually hci_init_req is not the only function where you would need
to add hdev->req_last_cmd entries. There are hci_reset_req and some
others. Without that, the rest of your patch makes hci_req_complete a
non functional operation.
Regards
Marcel
^ permalink raw reply
* [PATCH v4 2/5] Change CreatePairedDevice to support LE devices
From: Sheldon Demario @ 2010-12-21 14:34 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Sheldon Demario
In-Reply-To: <20101221084243.GA14108@jh-x301>
CreatePairedDevice implements now the same behaviour of CreateDevice,
triggering Discover All Primary Services when needed. SMP negotiation
starts when the link is established. LE capable kernel is required to
test this method properly.
Limitation: For dual mode devices, Discover All Primary Services is not
being executed after SDP search if GATT record is found.
---
src/adapter.c | 102 +++++++++++++++++++++++++++++++++++++----------------
src/device.c | 89 ++++++++++++++++++++++++----------------------
src/device.h | 5 ++-
src/glib-helper.c | 12 +++++-
src/glib-helper.h | 1 +
5 files changed, 132 insertions(+), 77 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index cf3566d..82f55ef 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1510,15 +1510,48 @@ static gboolean event_is_connectable(uint8_t type)
}
}
+static struct btd_device *create_device_internal(DBusConnection *conn,
+ struct btd_adapter *adapter,
+ const gchar *address,
+ gboolean force, int *err)
+{
+ struct remote_dev_info *dev, match;
+ struct btd_device *device;
+ device_type_t type;
+
+ memset(&match, 0, sizeof(struct remote_dev_info));
+ str2ba(address, &match.bdaddr);
+ match.name_status = NAME_ANY;
+
+ dev = adapter_search_found_devices(adapter, &match);
+ if (dev && dev->flags)
+ type = flags2type(dev->flags);
+ else
+ type = DEVICE_TYPE_BREDR;
+
+ if (!force && type == DEVICE_TYPE_LE &&
+ !event_is_connectable(dev->evt_type)) {
+ if (err)
+ *err = -ENOTCONN;
+
+ return NULL;
+ }
+
+ device = adapter_create_device(conn, adapter, address, type);
+ if (!device && err)
+ *err = -ENOMEM;
+
+ return device;
+}
+
static DBusMessage *create_device(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct btd_adapter *adapter = data;
struct btd_device *device;
- struct remote_dev_info *dev, match;
const gchar *address;
+ DBusMessage *reply;
int err;
- device_type_t type;
if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address,
DBUS_TYPE_INVALID) == FALSE)
@@ -1535,41 +1568,36 @@ static DBusMessage *create_device(DBusConnection *conn,
DBG("%s", address);
- memset(&match, 0, sizeof(struct remote_dev_info));
- str2ba(address, &match.bdaddr);
- match.name_status = NAME_ANY;
+ device = create_device_internal(conn, adapter, address, TRUE, &err);
+ if (!device)
+ goto failed;
- dev = adapter_search_found_devices(adapter, &match);
- if (dev && dev->flags)
- type = flags2type(dev->flags);
+ if (device_get_type(device) != DEVICE_TYPE_LE)
+ err = device_browse_sdp(device, conn, msg, NULL, FALSE);
else
- type = DEVICE_TYPE_BREDR;
+ err = device_browse_primary(device, conn, msg, FALSE);
- device = adapter_create_device(conn, adapter, address, type);
- if (!device)
- return NULL;
+ if (err < 0) {
+ adapter_remove_device(conn, adapter, device, TRUE);
+ return btd_error_failed(msg, strerror(-err));
+ }
- if (type == DEVICE_TYPE_LE && !event_is_connectable(dev->evt_type)) {
+ return NULL;
+
+failed:
+ if (err == -ENOTCONN) {
/* Device is not connectable */
const char *path = device_get_path(device);
- DBusMessage *reply;
reply = dbus_message_new_method_return(msg);
dbus_message_append_args(reply,
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID);
-
- return reply;
- }
-
- err = device_browse(device, conn, msg, NULL, FALSE);
- if (err < 0) {
- adapter_remove_device(conn, adapter, device, TRUE);
- return btd_error_failed(msg, strerror(-err));
- }
+ DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_INVALID);
+ } else
+ reply = btd_error_failed(msg, strerror(-err));
- return NULL;
+ return reply;
}
static uint8_t parse_io_capability(const char *capability)
@@ -1594,6 +1622,7 @@ static DBusMessage *create_paired_device(DBusConnection *conn,
struct btd_device *device;
const gchar *address, *agent_path, *capability, *sender;
uint8_t cap;
+ int err;
if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address,
DBUS_TYPE_OBJECT_PATH, &agent_path,
@@ -1618,12 +1647,23 @@ static DBusMessage *create_paired_device(DBusConnection *conn,
if (cap == IO_CAPABILITY_INVALID)
return btd_error_invalid_args(msg);
- device = adapter_get_device(conn, adapter, address);
- if (!device)
- return btd_error_failed(msg,
- "Unable to create a new device object");
+ device = adapter_find_device(adapter, address);
+ if (!device) {
+ device = create_device_internal(conn, adapter, address,
+ FALSE, &err);
+ if (!device)
+ return btd_error_failed(msg, strerror(-err));
+ }
+
+ if (device_get_type(device) != DEVICE_TYPE_LE)
+ return device_create_bonding(device, conn, msg,
+ agent_path, cap);
- return device_create_bonding(device, conn, msg, agent_path, cap);
+ err = device_browse_primary(device, conn, msg, TRUE);
+ if (err < 0)
+ return btd_error_failed(msg, strerror(-err));
+
+ return NULL;
}
static gint device_path_cmp(struct btd_device *device, const gchar *path)
diff --git a/src/device.c b/src/device.c
index bef8e71..87a6647 100644
--- a/src/device.c
+++ b/src/device.c
@@ -583,7 +583,7 @@ static DBusMessage *discover_services(DBusConnection *conn,
return btd_error_invalid_args(msg);
if (strlen(pattern) == 0) {
- err = device_browse(device, conn, msg, NULL, FALSE);
+ err = device_browse_sdp(device, conn, msg, NULL, FALSE);
if (err < 0)
goto fail;
} else {
@@ -594,7 +594,7 @@ static DBusMessage *discover_services(DBusConnection *conn,
sdp_uuid128_to_uuid(&uuid);
- err = device_browse(device, conn, msg, &uuid, FALSE);
+ err = device_browse_sdp(device, conn, msg, &uuid, FALSE);
if (err < 0)
goto fail;
}
@@ -985,6 +985,11 @@ void device_get_name(struct btd_device *device, char *name, size_t len)
strncpy(name, device->name, len);
}
+device_type_t device_get_type(struct btd_device *device)
+{
+ return device->type;
+}
+
void device_remove_bonding(struct btd_device *device)
{
char filename[PATH_MAX + 1];
@@ -1537,41 +1542,62 @@ done:
browse_request_free(req);
}
-static struct browse_req *browse_primary(struct btd_device *device, int *err)
+int device_browse_primary(struct btd_device *device, DBusConnection *conn,
+ DBusMessage *msg, gboolean secure)
{
struct btd_adapter *adapter = device->adapter;
struct browse_req *req;
bdaddr_t src;
- int ret;
+ int err;
+
+ if (device->browse)
+ return -EBUSY;
req = g_new0(struct browse_req, 1);
req->device = btd_device_ref(device);
adapter_get_address(adapter, &src);
- ret = bt_discover_primary(&src, &device->bdaddr, -1, primary_cb, req,
- NULL);
-
- if (ret < 0) {
+ err = bt_discover_primary(&src, &device->bdaddr, -1, primary_cb, req,
+ secure, NULL);
+ if (err < 0) {
browse_request_free(req);
- if (err)
- *err = ret;
+ return err;
+ }
- return NULL;
+ if (conn == NULL)
+ conn = get_dbus_connection();
+
+ req->conn = dbus_connection_ref(conn);
+ device->browse = req;
+
+ if (msg) {
+ const char *sender = dbus_message_get_sender(msg);
+
+ req->msg = dbus_message_ref(msg);
+ /* Track the request owner to cancel it
+ * automatically if the owner exits */
+ req->listener_id = g_dbus_add_disconnect_watch(conn,
+ sender,
+ discover_services_req_exit,
+ req, NULL);
}
- return req;
+ return err;
}
-static struct browse_req *browse_sdp(struct btd_device *device, uuid_t *search,
- gboolean reverse, int *err)
+int device_browse_sdp(struct btd_device *device, DBusConnection *conn,
+ DBusMessage *msg, uuid_t *search, gboolean reverse)
{
struct btd_adapter *adapter = device->adapter;
struct browse_req *req;
bt_callback_t cb;
bdaddr_t src;
uuid_t uuid;
- int ret;
+ int err;
+
+ if (device->browse)
+ return -EBUSY;
adapter_get_address(adapter, &src);
@@ -1586,34 +1612,11 @@ static struct browse_req *browse_sdp(struct btd_device *device, uuid_t *search,
cb = browse_cb;
}
- ret = bt_search_service(&src, &device->bdaddr, &uuid, cb, req, NULL);
- if (ret < 0) {
+ err = bt_search_service(&src, &device->bdaddr, &uuid, cb, req, NULL);
+ if (err < 0) {
browse_request_free(req);
- if (err)
- *err = ret;
-
- return NULL;
- }
-
- return req;
-}
-
-int device_browse(struct btd_device *device, DBusConnection *conn,
- DBusMessage *msg, uuid_t *search, gboolean reverse)
-{
- struct browse_req *req;
- int err = 0;
-
- if (device->browse)
- return -EBUSY;
-
- if (device->type == DEVICE_TYPE_LE)
- req = browse_primary(device, &err);
- else
- req = browse_sdp(device, search, reverse, &err);
-
- if (req == NULL)
return err;
+ }
if (conn == NULL)
conn = get_dbus_connection();
@@ -1716,7 +1719,7 @@ static gboolean start_discovery(gpointer user_data)
{
struct btd_device *device = user_data;
- device_browse(device, NULL, NULL, NULL, TRUE);
+ device_browse_sdp(device, NULL, NULL, NULL, TRUE);
device->discov_timer = 0;
@@ -2053,7 +2056,7 @@ void device_bonding_complete(struct btd_device *device, uint8_t status)
device->discov_timer = 0;
}
- device_browse(device, bonding->conn, bonding->msg,
+ device_browse_sdp(device, bonding->conn, bonding->msg,
NULL, FALSE);
bonding_request_free(bonding);
diff --git a/src/device.h b/src/device.h
index 74b968c..9c645df 100644
--- a/src/device.h
+++ b/src/device.h
@@ -46,9 +46,12 @@ struct btd_device *device_create(DBusConnection *conn,
const gchar *address, device_type_t type);
void device_set_name(struct btd_device *device, const char *name);
void device_get_name(struct btd_device *device, char *name, size_t len);
+device_type_t device_get_type(struct btd_device *device);
void device_remove(struct btd_device *device, gboolean remove_stored);
gint device_address_cmp(struct btd_device *device, const gchar *address);
-int device_browse(struct btd_device *device, DBusConnection *conn,
+int device_browse_primary(struct btd_device *device, DBusConnection *conn,
+ DBusMessage *msg, gboolean secure);
+int device_browse_sdp(struct btd_device *device, DBusConnection *conn,
DBusMessage *msg, uuid_t *search, gboolean reverse);
void device_probe_drivers(struct btd_device *device, GSList *profiles);
const sdp_record_t *btd_device_get_record(struct btd_device *device,
diff --git a/src/glib-helper.c b/src/glib-helper.c
index c440e60..459a21c 100644
--- a/src/glib-helper.c
+++ b/src/glib-helper.c
@@ -520,9 +520,11 @@ static void connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)
int bt_discover_primary(const bdaddr_t *src, const bdaddr_t *dst, int psm,
bt_primary_t cb, void *user_data,
+ gboolean secure,
bt_destroy_t destroy)
{
struct gattrib_context *ctxt;
+ BtIOSecLevel sec_level;
GIOChannel *io;
GError *gerr = NULL;
@@ -536,19 +538,25 @@ int bt_discover_primary(const bdaddr_t *src, const bdaddr_t *dst, int psm,
ctxt->cb = cb;
ctxt->destroy = destroy;
+ if (secure == TRUE)
+ sec_level = BT_IO_SEC_HIGH;
+ else
+ sec_level = BT_IO_SEC_LOW;
+
+
if (psm < 0)
io = bt_io_connect(BT_IO_L2CAP, connect_cb, ctxt, NULL, &gerr,
BT_IO_OPT_SOURCE_BDADDR, src,
BT_IO_OPT_DEST_BDADDR, dst,
BT_IO_OPT_CID, GATT_CID,
- BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
+ BT_IO_OPT_SEC_LEVEL, sec_level,
BT_IO_OPT_INVALID);
else
io = bt_io_connect(BT_IO_L2CAP, connect_cb, ctxt, NULL, &gerr,
BT_IO_OPT_SOURCE_BDADDR, src,
BT_IO_OPT_DEST_BDADDR, dst,
BT_IO_OPT_PSM, psm,
- BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
+ BT_IO_OPT_SEC_LEVEL, sec_level,
BT_IO_OPT_INVALID);
if (io == NULL) {
diff --git a/src/glib-helper.h b/src/glib-helper.h
index 10718bb..17739cf 100644
--- a/src/glib-helper.h
+++ b/src/glib-helper.h
@@ -35,6 +35,7 @@ int bt_cancel_discovery(const bdaddr_t *src, const bdaddr_t *dst);
int bt_discover_primary(const bdaddr_t *src, const bdaddr_t *dst, int psm,
bt_primary_t cb, void *user_data,
+ gboolean secure,
bt_destroy_t destroy);
gchar *bt_uuid2string(uuid_t *uuid);
--
1.7.3.2
^ permalink raw reply related
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