* Re: [BLE] org.bluez.Device1.Connect() returns org.bluez.Error.NotAvailable
From: Anderson Lizardo @ 2012-12-12 10:58 UTC (permalink / raw)
To: Ting Chou, linux-bluetooth@vger.kernel.org
In-Reply-To: <20121212103614.GA7669@x220>
Hi Johan,
On Wed, Dec 12, 2012 at 6:36 AM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
> I agree that Device.Connect should at least work on devices that have
> been discovered but on whom we haven't completed service discovery yet.
> This would be analogous to the old Adapter.CreateDevice and it'd allow
> us to implement proper support for devices not supporting SMP (i.e.
> devices you can't call Device.Pair on). What remains to be discussed is
> whether Device.Connect is useful for LE devices in some more extended
> sense. Maybe it could at least force calling device_set_auto_connect().
On that matter, I would suggest (although I didn't spent much time
thinking on the consequences) that Device.Connect should add device to
auto connect list, and Device.Disconnect should disconnect current
connection and remove device from autoconnect list.
For devices which have services implemented inside BlueZ (e.g. HTP),
I'm not sure this is a good idea, because these profiles explicitely
state on their spec what should happen in case of disconnection, so it
is better to have BlueZ handle this for them (IMHO).
Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
^ permalink raw reply
* Re: [BLE] org.bluez.Device1.Connect() returns org.bluez.Error.NotAvailable
From: Anderson Lizardo @ 2012-12-12 10:53 UTC (permalink / raw)
To: Ting Chou; +Cc: Johan Hedberg, linux-bluetooth@vger.kernel.org
In-Reply-To: <ADCBF04BB97EBF4AAE65663F8478B61CA99E65ABED@Luna.iaSolution.net>
Hi Ting,
On Wed, Dec 12, 2012 at 6:21 AM, Ting Chou <Ting.Chou@iasolution.net> wrote:
> Do you mean once a LE device with internally supported profiles is discovered,
> it will be connected automatically? Which means I cannot connect manually, at
> the timing I prefer?
>
> Since with my BT 4.0 dongle, Adpater.StartDiscovery discover also LE devices, I
> thought I should use Device.Connect to connect to the device.
According to the General Connection Establishment procedure (GCEP, see
Core spec page 1716 for details), the host shall start scanning and:
"When the Host discovers a device to which the Host may attempt to connect,
the Host shall stop the scanning, and initiate a connection using the
direct con-
nection establishment procedure."
That's exactly what BlueZ does for LE devices. For paired devices
whose profile is supported internally by BlueZ (e.g. a LE
thermometer), the GCEP will keep trying to connect to them, where
"connect" means using LE active/passive scan, followed by the
procedure above.
For unsupported devices, IIRC there will be not attempt to keep
re-connecting to it (or even keep the connection up after service
discovery). This should be addressed by the generic GATT API in
attrib/client.c, but the current implementation has several
limitations and is not implementing a consistent API, therefore it
will probably be removed for first BlueZ 5.0 release, and a
replacement (which should probably address reconnection for
external/proprietary GATT services) will be implemented.
Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
^ permalink raw reply
* Re: [BLE] org.bluez.Device1.Connect() returns org.bluez.Error.NotAvailable
From: Johan Hedberg @ 2012-12-12 10:36 UTC (permalink / raw)
To: Ting Chou; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <ADCBF04BB97EBF4AAE65663F8478B61CA99E65ABED@Luna.iaSolution.net>
Hi Ting,
On Wed, Dec 12, 2012, Ting Chou wrote:
> Do you mean once a LE device with internally supported profiles is
> discovered, it will be connected automatically? Which means I cannot
> connect manually, at the timing I prefer?
Correct. In many ways one could consider the peripheral (advertising
device) to be the one that "initiates" the connection by starting to do
connectable advertising. We are merely reacting to this "request" by
sending a HCI_LE_Create_Connection command.
> Since with my BT 4.0 dongle, Adpater.StartDiscovery discover also LE
> devices, I thought I should use Device.Connect to connect to the
> device.
I agree that Device.Connect should at least work on devices that have
been discovered but on whom we haven't completed service discovery yet.
This would be analogous to the old Adapter.CreateDevice and it'd allow
us to implement proper support for devices not supporting SMP (i.e.
devices you can't call Device.Pair on). What remains to be discussed is
whether Device.Connect is useful for LE devices in some more extended
sense. Maybe it could at least force calling device_set_auto_connect().
Johan
^ permalink raw reply
* [PATCH 16/16] avctp: Remove double looking for audio device
From: Szymon Janc @ 2012-12-12 10:28 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>
There is no need to double call for manager_get_audio_device with
toggled create flag. manager_get_audio_device with create set to true
will only create new audio device if matching one was not found.
---
profiles/audio/avctp.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/profiles/audio/avctp.c b/profiles/audio/avctp.c
index 8ffbf43..013c587 100644
--- a/profiles/audio/avctp.c
+++ b/profiles/audio/avctp.c
@@ -1132,14 +1132,10 @@ static void avctp_confirm_cb(GIOChannel *chan, gpointer data)
if (session == NULL)
return;
- dev = manager_get_audio_device(device, FALSE);
+ dev = manager_get_audio_device(device, TRUE);
if (!dev) {
- dev = manager_get_audio_device(device, TRUE);
- if (!dev) {
- error("Unable to get audio device object for %s",
- address);
- goto drop;
- }
+ error("Unable to get audio device object for %s", address);
+ goto drop;
}
if (dev->control == NULL) {
--
1.8.0
^ permalink raw reply related
* [PATCH 15/16] audio: Simplify manager_find_device
From: Szymon Janc @ 2012-12-12 10:28 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>
Now that audio_device and other audio structures holds references to
btd_device and not addresses or paths there is no need for complex
find function.
---
profiles/audio/manager.c | 70 +++++-------------------------------------------
1 file changed, 6 insertions(+), 64 deletions(-)
diff --git a/profiles/audio/manager.c b/profiles/audio/manager.c
index adc4e77..9ab1be2 100644
--- a/profiles/audio/manager.c
+++ b/profiles/audio/manager.c
@@ -102,80 +102,25 @@ static struct audio_device *get_audio_dev(struct btd_device *device)
return manager_get_audio_device(device, TRUE);
}
-static GSList *manager_find_devices(const char *path,
- const bdaddr_t *src,
- const bdaddr_t *dst,
- const char *interface,
- gboolean connected)
+static struct audio_device *manager_find_device(struct btd_device *device)
{
- GSList *result = NULL;
GSList *l;
for (l = devices; l != NULL; l = l->next) {
struct audio_device *dev = l->data;
- const bdaddr_t *dev_src;
- const bdaddr_t *dev_dst;
- dev_src = adapter_get_address(device_get_adapter(dev->btd_dev));
- dev_dst = device_get_address(dev->btd_dev);
-
- if ((path && (strcmp(path, "")) &&
- strcmp(device_get_path(dev->btd_dev), path)))
- continue;
-
- if ((src && bacmp(src, BDADDR_ANY)) && bacmp(dev_src, src))
- continue;
-
- if ((dst && bacmp(dst, BDADDR_ANY)) && bacmp(dev_dst, dst))
- continue;
-
- if (interface && !strcmp(AUDIO_SINK_INTERFACE, interface)
- && !dev->sink)
- continue;
-
- if (interface && !strcmp(AUDIO_SOURCE_INTERFACE, interface)
- && !dev->source)
- continue;
-
- if (interface && !strcmp(AUDIO_CONTROL_INTERFACE, interface)
- && !dev->control)
- continue;
-
- if (connected && !audio_device_is_active(dev, interface))
- continue;
-
- result = g_slist_append(result, dev);
+ if (dev->btd_dev == device)
+ return dev;
}
- return result;
-}
-
-static struct audio_device *manager_find_device(const char *path,
- const bdaddr_t *src,
- const bdaddr_t *dst,
- const char *interface,
- gboolean connected)
-{
- struct audio_device *result;
- GSList *l;
-
- l = manager_find_devices(path, src, dst, interface, connected);
- if (l == NULL)
- return NULL;
-
- result = l->data;
- g_slist_free(l);
- return result;
+ return NULL;
}
static void audio_remove(struct btd_profile *p, struct btd_device *device)
{
struct audio_device *dev;
- const char *path;
-
- path = device_get_path(device);
- dev = manager_find_device(path, NULL, NULL, NULL, FALSE);
+ dev = manager_find_device(device);
if (dev == NULL)
return;
@@ -645,11 +590,8 @@ struct audio_device *manager_get_audio_device(struct btd_device *device,
gboolean create)
{
struct audio_device *dev;
- struct btd_adapter *adapter = device_get_adapter(device);
- dev = manager_find_device(NULL, adapter_get_address(adapter),
- device_get_address(device), NULL,
- FALSE);
+ dev = manager_find_device(device);
if (dev)
return dev;
--
1.8.0
^ permalink raw reply related
* [PATCH 14/16] audio: Make manager_get_device accept btd_device
From: Szymon Janc @ 2012-12-12 10:28 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>
Also rename manager_get_device to manager_get_audio_device to better
mark what this function do.
---
profiles/audio/a2dp.c | 8 +-------
profiles/audio/avctp.c | 14 ++++----------
profiles/audio/avdtp.c | 18 +++++-------------
profiles/audio/manager.c | 35 +++++++----------------------------
profiles/audio/manager.h | 5 ++---
5 files changed, 19 insertions(+), 61 deletions(-)
diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index c812d45..4c74652 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -48,8 +48,6 @@
#include "a2dp.h"
#include "a2dp-codecs.h"
#include "sdpd.h"
-#include "../src/manager.h"
-#include "../src/device.h"
/* The duration that streams without users are allowed to stay in
* STREAMING state. */
@@ -124,11 +122,7 @@ static struct a2dp_setup *setup_ref(struct a2dp_setup *setup)
static struct audio_device *a2dp_get_dev(struct avdtp *session)
{
- struct btd_adapter *adapter = avdtp_get_adapter(session);
- struct btd_device *device = avdtp_get_device(session);
-
- return manager_get_device(adapter_get_address(adapter),
- device_get_address(device), FALSE);
+ return manager_get_audio_device(avdtp_get_device(session), FALSE);
}
static struct a2dp_setup *setup_new(struct avdtp *session)
diff --git a/profiles/audio/avctp.c b/profiles/audio/avctp.c
index e56885a..8ffbf43 100644
--- a/profiles/audio/avctp.c
+++ b/profiles/audio/avctp.c
@@ -448,9 +448,7 @@ static void avctp_set_state(struct avctp *session, avctp_state_t new_state)
struct audio_device *dev;
avctp_state_t old_state = session->state;
- dev = manager_get_device(adapter_get_address(session->server->adapter),
- device_get_address(session->device),
- FALSE);
+ dev = manager_get_audio_device(session->device, FALSE);
if (dev == NULL) {
error("%s(): No matching audio device", __func__);
return;
@@ -842,9 +840,7 @@ static void init_uinput(struct avctp *session)
struct audio_device *dev;
char address[18], name[248 + 1];
- dev = manager_get_device(adapter_get_address(session->server->adapter),
- device_get_address(session->device),
- FALSE);
+ dev = manager_get_audio_device(session->device, FALSE);
device_get_name(dev->btd_dev, name, sizeof(name));
if (g_str_equal(name, "Nokia CK-20W")) {
@@ -855,7 +851,6 @@ static void init_uinput(struct avctp *session)
}
ba2str(device_get_address(session->device), address);
-
session->uinput = uinput_create(address);
if (session->uinput < 0)
error("AVRCP: failed to init uinput for %s", address);
@@ -1137,10 +1132,9 @@ static void avctp_confirm_cb(GIOChannel *chan, gpointer data)
if (session == NULL)
return;
- dev = manager_get_device(&src, device_get_address(device), FALSE);
+ dev = manager_get_audio_device(device, FALSE);
if (!dev) {
- dev = manager_get_device(&src, device_get_address(device),
- TRUE);
+ dev = manager_get_audio_device(device, TRUE);
if (!dev) {
error("Unable to get audio device object for %s",
address);
diff --git a/profiles/audio/avdtp.c b/profiles/audio/avdtp.c
index 690294c..aca7e62 100644
--- a/profiles/audio/avdtp.c
+++ b/profiles/audio/avdtp.c
@@ -715,13 +715,10 @@ static void avdtp_set_state(struct avdtp *session,
GSList *l;
struct audio_device *dev;
avdtp_session_state_t old_state = session->state;
- struct btd_adapter *adapter = avdtp_get_adapter(session);
- struct btd_device *device = avdtp_get_device(session);
session->state = new_state;
- dev = manager_get_device(adapter_get_address(adapter),
- device_get_address(device), FALSE);
+ dev = manager_get_audio_device(avdtp_get_device(session), FALSE);
if (dev == NULL) {
error("%s(): No matching audio device", __func__);
return;
@@ -1158,9 +1155,7 @@ static gboolean disconnect_timeout(gpointer user_data)
stream_setup = session->stream_setup;
session->stream_setup = FALSE;
- dev = manager_get_device(adapter_get_address(session->server->adapter),
- device_get_address(session->device),
- FALSE);
+ dev = manager_get_audio_device(session->device, FALSE);
if (dev && dev->sink && stream_setup)
sink_setup_stream(dev->sink, session);
@@ -1458,8 +1453,6 @@ static gboolean avdtp_setconf_cmd(struct avdtp *session, uint8_t transaction,
uint8_t err, category = 0x00;
struct audio_device *dev;
GSList *l;
- struct btd_adapter *adapter = avdtp_get_adapter(session);
- struct btd_device *device = avdtp_get_device(session);
if (size < sizeof(struct setconf_req)) {
error("Too short getcap request");
@@ -1477,8 +1470,7 @@ static gboolean avdtp_setconf_cmd(struct avdtp *session, uint8_t transaction,
goto failed;
}
- dev = manager_get_device(adapter_get_address(adapter),
- device_get_address(device), FALSE);
+ dev = manager_get_audio_device(avdtp_get_device(session), FALSE);
if (!dev) {
error("Unable to get a audio device object");
err = AVDTP_BAD_STATE;
@@ -2515,9 +2507,9 @@ static void avdtp_confirm_cb(GIOChannel *chan, gpointer data)
goto drop;
}
- dev = manager_get_device(&src, &dst, FALSE);
+ dev = manager_get_audio_device(device, FALSE);
if (!dev) {
- dev = manager_get_device(&src, &dst, TRUE);
+ dev = manager_get_audio_device(device, TRUE);
if (!dev) {
error("Unable to get audio device object for %s",
address);
diff --git a/profiles/audio/manager.c b/profiles/audio/manager.c
index b3d4a68..adc4e77 100644
--- a/profiles/audio/manager.c
+++ b/profiles/audio/manager.c
@@ -99,10 +99,7 @@ static struct audio_adapter *find_adapter(GSList *list,
static struct audio_device *get_audio_dev(struct btd_device *device)
{
- struct btd_adapter *adapter = device_get_adapter(device);
-
- return manager_get_device(adapter_get_address(adapter),
- device_get_address(device), TRUE);
+ return manager_get_audio_device(device, TRUE);
}
static GSList *manager_find_devices(const char *path,
@@ -644,39 +641,21 @@ void audio_manager_exit(void)
btd_unregister_adapter_driver(&media_driver);
}
-struct audio_device *manager_get_device(const bdaddr_t *src,
- const bdaddr_t *dst,
- gboolean create)
+struct audio_device *manager_get_audio_device(struct btd_device *device,
+ gboolean create)
{
struct audio_device *dev;
- struct btd_adapter *adapter;
- struct btd_device *device;
- char addr[18];
+ struct btd_adapter *adapter = device_get_adapter(device);
- dev = manager_find_device(NULL, src, dst, NULL, FALSE);
+ dev = manager_find_device(NULL, adapter_get_address(adapter),
+ device_get_address(device), NULL,
+ FALSE);
if (dev)
return dev;
if (!create)
return NULL;
- ba2str(src, addr);
-
- adapter = manager_find_adapter(src);
- if (!adapter) {
- error("Unable to get a btd_adapter object for %s",
- addr);
- return NULL;
- }
-
- ba2str(dst, addr);
-
- device = adapter_get_device(adapter, addr, BDADDR_BREDR);
- if (!device) {
- error("Unable to get btd_device object for %s", addr);
- return NULL;
- }
-
dev = audio_device_register(device);
if (!dev)
return NULL;
diff --git a/profiles/audio/manager.h b/profiles/audio/manager.h
index f352a67..2567e46 100644
--- a/profiles/audio/manager.h
+++ b/profiles/audio/manager.h
@@ -37,9 +37,8 @@ void audio_source_disconnected(struct btd_device *dev, int err);
int audio_manager_init(GKeyFile *config);
void audio_manager_exit(void);
-struct audio_device *manager_get_device(const bdaddr_t *src,
- const bdaddr_t *dst,
- gboolean create);
+struct audio_device *manager_get_audio_device(struct btd_device *device,
+ gboolean create);
/* TRUE to enable fast connectable and FALSE to disable fast connectable for all
* audio adapters. */
--
1.8.0
^ permalink raw reply related
* [PATCH 13/16] audio: Use manager_get_device to get device object
From: Szymon Janc @ 2012-12-12 10:28 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>
manager_get_device is a simple wrapper for manager_find_device
and can be used instead making manager API simpler.
manager_find_device{s} are no longer used outside of manager.c and
can be made static.
---
profiles/audio/a2dp.c | 5 +-
profiles/audio/manager.c | 132 +++++++++++++++++++++++------------------------
profiles/audio/manager.h | 12 -----
3 files changed, 68 insertions(+), 81 deletions(-)
diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index f8e0f19..c812d45 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -127,9 +127,8 @@ static struct audio_device *a2dp_get_dev(struct avdtp *session)
struct btd_adapter *adapter = avdtp_get_adapter(session);
struct btd_device *device = avdtp_get_device(session);
- return manager_find_device(NULL, adapter_get_address(adapter),
- device_get_address(device), NULL,
- FALSE);
+ return manager_get_device(adapter_get_address(adapter),
+ device_get_address(device), FALSE);
}
static struct a2dp_setup *setup_new(struct avdtp *session)
diff --git a/profiles/audio/manager.c b/profiles/audio/manager.c
index b2e4841..b3d4a68 100644
--- a/profiles/audio/manager.c
+++ b/profiles/audio/manager.c
@@ -105,6 +105,72 @@ static struct audio_device *get_audio_dev(struct btd_device *device)
device_get_address(device), TRUE);
}
+static GSList *manager_find_devices(const char *path,
+ const bdaddr_t *src,
+ const bdaddr_t *dst,
+ const char *interface,
+ gboolean connected)
+{
+ GSList *result = NULL;
+ GSList *l;
+
+ for (l = devices; l != NULL; l = l->next) {
+ struct audio_device *dev = l->data;
+ const bdaddr_t *dev_src;
+ const bdaddr_t *dev_dst;
+
+ dev_src = adapter_get_address(device_get_adapter(dev->btd_dev));
+ dev_dst = device_get_address(dev->btd_dev);
+
+ if ((path && (strcmp(path, "")) &&
+ strcmp(device_get_path(dev->btd_dev), path)))
+ continue;
+
+ if ((src && bacmp(src, BDADDR_ANY)) && bacmp(dev_src, src))
+ continue;
+
+ if ((dst && bacmp(dst, BDADDR_ANY)) && bacmp(dev_dst, dst))
+ continue;
+
+ if (interface && !strcmp(AUDIO_SINK_INTERFACE, interface)
+ && !dev->sink)
+ continue;
+
+ if (interface && !strcmp(AUDIO_SOURCE_INTERFACE, interface)
+ && !dev->source)
+ continue;
+
+ if (interface && !strcmp(AUDIO_CONTROL_INTERFACE, interface)
+ && !dev->control)
+ continue;
+
+ if (connected && !audio_device_is_active(dev, interface))
+ continue;
+
+ result = g_slist_append(result, dev);
+ }
+
+ return result;
+}
+
+static struct audio_device *manager_find_device(const char *path,
+ const bdaddr_t *src,
+ const bdaddr_t *dst,
+ const char *interface,
+ gboolean connected)
+{
+ struct audio_device *result;
+ GSList *l;
+
+ l = manager_find_devices(path, src, dst, interface, connected);
+ if (l == NULL)
+ return NULL;
+
+ result = l->data;
+ g_slist_free(l);
+ return result;
+}
+
static void audio_remove(struct btd_profile *p, struct btd_device *device)
{
struct audio_device *dev;
@@ -578,72 +644,6 @@ void audio_manager_exit(void)
btd_unregister_adapter_driver(&media_driver);
}
-GSList *manager_find_devices(const char *path,
- const bdaddr_t *src,
- const bdaddr_t *dst,
- const char *interface,
- gboolean connected)
-{
- GSList *result = NULL;
- GSList *l;
-
- for (l = devices; l != NULL; l = l->next) {
- struct audio_device *dev = l->data;
- const bdaddr_t *dev_src;
- const bdaddr_t *dev_dst;
-
- dev_src = adapter_get_address(device_get_adapter(dev->btd_dev));
- dev_dst = device_get_address(dev->btd_dev);
-
- if ((path && (strcmp(path, "")) &&
- strcmp(device_get_path(dev->btd_dev), path)))
- continue;
-
- if ((src && bacmp(src, BDADDR_ANY)) && bacmp(dev_src, src))
- continue;
-
- if ((dst && bacmp(dst, BDADDR_ANY)) && bacmp(dev_dst, dst))
- continue;
-
- if (interface && !strcmp(AUDIO_SINK_INTERFACE, interface)
- && !dev->sink)
- continue;
-
- if (interface && !strcmp(AUDIO_SOURCE_INTERFACE, interface)
- && !dev->source)
- continue;
-
- if (interface && !strcmp(AUDIO_CONTROL_INTERFACE, interface)
- && !dev->control)
- continue;
-
- if (connected && !audio_device_is_active(dev, interface))
- continue;
-
- result = g_slist_append(result, dev);
- }
-
- return result;
-}
-
-struct audio_device *manager_find_device(const char *path,
- const bdaddr_t *src,
- const bdaddr_t *dst,
- const char *interface,
- gboolean connected)
-{
- struct audio_device *result;
- GSList *l;
-
- l = manager_find_devices(path, src, dst, interface, connected);
- if (l == NULL)
- return NULL;
-
- result = l->data;
- g_slist_free(l);
- return result;
-}
-
struct audio_device *manager_get_device(const bdaddr_t *src,
const bdaddr_t *dst,
gboolean create)
diff --git a/profiles/audio/manager.h b/profiles/audio/manager.h
index 75c1308..f352a67 100644
--- a/profiles/audio/manager.h
+++ b/profiles/audio/manager.h
@@ -37,18 +37,6 @@ void audio_source_disconnected(struct btd_device *dev, int err);
int audio_manager_init(GKeyFile *config);
void audio_manager_exit(void);
-struct audio_device *manager_find_device(const char *path,
- const bdaddr_t *src,
- const bdaddr_t *dst,
- const char *interface,
- gboolean connected);
-
-GSList *manager_find_devices(const char *path,
- const bdaddr_t *src,
- const bdaddr_t *dst,
- const char *interface,
- gboolean connected);
-
struct audio_device *manager_get_device(const bdaddr_t *src,
const bdaddr_t *dst,
gboolean create);
--
1.8.0
^ permalink raw reply related
* [PATCH 12/16] avdtp: Replace avdtp_get_peers with adapter and device getters
From: Szymon Janc @ 2012-12-12 10:28 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>
This will allow to directly pass adapter or device object instead
of looking for them with addresses later on.
---
profiles/audio/a2dp.c | 24 ++++++++++--------------
profiles/audio/avdtp.c | 26 +++++++++++++++-----------
profiles/audio/avdtp.h | 3 ++-
3 files changed, 27 insertions(+), 26 deletions(-)
diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index da54717..f8e0f19 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -49,6 +49,7 @@
#include "a2dp-codecs.h"
#include "sdpd.h"
#include "../src/manager.h"
+#include "../src/device.h"
/* The duration that streams without users are allowed to stay in
* STREAMING state. */
@@ -123,11 +124,12 @@ static struct a2dp_setup *setup_ref(struct a2dp_setup *setup)
static struct audio_device *a2dp_get_dev(struct avdtp *session)
{
- bdaddr_t src, dst;
+ struct btd_adapter *adapter = avdtp_get_adapter(session);
+ struct btd_device *device = avdtp_get_device(session);
- avdtp_get_peers(session, &src, &dst);
-
- return manager_find_device(NULL, &src, &dst, NULL, FALSE);
+ return manager_find_device(NULL, adapter_get_address(adapter),
+ device_get_address(device), NULL,
+ FALSE);
}
static struct a2dp_setup *setup_new(struct avdtp *session)
@@ -1492,10 +1494,8 @@ static struct a2dp_sep *a2dp_select_sep(struct avdtp *session, uint8_t type,
struct a2dp_server *server;
struct a2dp_sep *sep;
GSList *l;
- bdaddr_t src;
- avdtp_get_peers(session, &src, NULL);
- server = find_server(servers, manager_find_adapter(&src));
+ server = find_server(servers, avdtp_get_adapter(session));
if (!server)
return NULL;
@@ -1571,10 +1571,8 @@ unsigned int a2dp_config(struct avdtp *session, struct a2dp_sep *sep,
struct avdtp_service_capability *cap;
struct avdtp_media_codec_capability *codec_cap = NULL;
int posix_err;
- bdaddr_t src;
- avdtp_get_peers(session, &src, NULL);
- server = find_server(servers, manager_find_adapter(&src));
+ server = find_server(servers, avdtp_get_adapter(session));
if (!server)
return 0;
@@ -1883,15 +1881,13 @@ struct a2dp_sep *a2dp_get_sep(struct avdtp *session,
struct avdtp_stream *stream)
{
struct a2dp_server *server;
- bdaddr_t src, dst;
+ struct btd_adapter *adapter = avdtp_get_adapter(session);
GSList *l;
- avdtp_get_peers(session, &src, &dst);
-
for (l = servers; l; l = l->next) {
server = l->data;
- if (bacmp(&src, adapter_get_address(server->adapter)) == 0)
+ if (server->adapter == adapter)
break;
}
diff --git a/profiles/audio/avdtp.c b/profiles/audio/avdtp.c
index 20fdf25..690294c 100644
--- a/profiles/audio/avdtp.c
+++ b/profiles/audio/avdtp.c
@@ -714,13 +714,14 @@ static void avdtp_set_state(struct avdtp *session,
{
GSList *l;
struct audio_device *dev;
- bdaddr_t src, dst;
avdtp_session_state_t old_state = session->state;
+ struct btd_adapter *adapter = avdtp_get_adapter(session);
+ struct btd_device *device = avdtp_get_device(session);
session->state = new_state;
- avdtp_get_peers(session, &src, &dst);
- dev = manager_get_device(&src, &dst, FALSE);
+ dev = manager_get_device(adapter_get_address(adapter),
+ device_get_address(device), FALSE);
if (dev == NULL) {
error("%s(): No matching audio device", __func__);
return;
@@ -1456,8 +1457,9 @@ static gboolean avdtp_setconf_cmd(struct avdtp *session, uint8_t transaction,
struct avdtp_stream *stream;
uint8_t err, category = 0x00;
struct audio_device *dev;
- bdaddr_t src, dst;
GSList *l;
+ struct btd_adapter *adapter = avdtp_get_adapter(session);
+ struct btd_device *device = avdtp_get_device(session);
if (size < sizeof(struct setconf_req)) {
error("Too short getcap request");
@@ -1475,8 +1477,8 @@ static gboolean avdtp_setconf_cmd(struct avdtp *session, uint8_t transaction,
goto failed;
}
- avdtp_get_peers(session, &src, &dst);
- dev = manager_get_device(&src, &dst, FALSE);
+ dev = manager_get_device(adapter_get_address(adapter),
+ device_get_address(device), FALSE);
if (!dev) {
error("Unable to get a audio device object");
err = AVDTP_BAD_STATE;
@@ -3845,12 +3847,14 @@ avdtp_state_t avdtp_sep_get_state(struct avdtp_local_sep *sep)
return sep->state;
}
-void avdtp_get_peers(struct avdtp *session, bdaddr_t *src, bdaddr_t *dst)
+struct btd_adapter *avdtp_get_adapter(struct avdtp *session)
+{
+ return session->server->adapter;
+}
+
+struct btd_device *avdtp_get_device(struct avdtp *session)
{
- if (src)
- bacpy(src, adapter_get_address(session->server->adapter));
- if (dst)
- bacpy(dst, device_get_address(session->device));
+ return session->device;
}
int avdtp_init(struct btd_adapter *adapter, GKeyFile *config)
diff --git a/profiles/audio/avdtp.h b/profiles/audio/avdtp.h
index dbdf8f4..8f0d7e6 100644
--- a/profiles/audio/avdtp.h
+++ b/profiles/audio/avdtp.h
@@ -305,7 +305,8 @@ uint8_t avdtp_error_category(struct avdtp_error *err);
int avdtp_error_error_code(struct avdtp_error *err);
int avdtp_error_posix_errno(struct avdtp_error *err);
-void avdtp_get_peers(struct avdtp *session, bdaddr_t *src, bdaddr_t *dst);
+struct btd_adapter *avdtp_get_adapter(struct avdtp *session);
+struct btd_device *avdtp_get_device(struct avdtp *session);
gboolean avdtp_stream_setup_active(struct avdtp *session);
void avdtp_set_device_disconnect(struct avdtp *session, gboolean dev_dc);
--
1.8.0
^ permalink raw reply related
* [PATCH 11/16] avctp: Convert register/unregister to accept btd_adapter
From: Szymon Janc @ 2012-12-12 10:28 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>
Use btd_adapter and btd_device refs instead of source and destination
bdaddr_t.
---
profiles/audio/avctp.c | 94 +++++++++++++++++++++++++-------------------------
profiles/audio/avctp.h | 4 +--
profiles/audio/avrcp.c | 4 +--
3 files changed, 51 insertions(+), 51 deletions(-)
diff --git a/profiles/audio/avctp.c b/profiles/audio/avctp.c
index e7dba37..e56885a 100644
--- a/profiles/audio/avctp.c
+++ b/profiles/audio/avctp.c
@@ -49,6 +49,7 @@
#include "adapter.h"
#include "../src/device.h"
+#include "../src/manager.h"
#include "log.h"
#include "error.h"
@@ -119,7 +120,7 @@ struct avctp_state_callback {
};
struct avctp_server {
- bdaddr_t src;
+ struct btd_adapter *adapter;
GIOChannel *control_io;
GIOChannel *browsing_io;
GSList *sessions;
@@ -169,7 +170,7 @@ struct key_pressed {
struct avctp {
struct avctp_server *server;
- bdaddr_t dst;
+ struct btd_device *device;
avctp_state_t state;
@@ -427,7 +428,7 @@ static void avctp_disconnected(struct avctp *session)
if (session->uinput >= 0) {
char address[18];
- ba2str(&session->dst, address);
+ ba2str(device_get_address(session->device), address);
DBG("AVCTP: closing uinput for %s", address);
ioctl(session->uinput, UI_DEV_DESTROY);
@@ -437,6 +438,7 @@ static void avctp_disconnected(struct avctp *session)
server = session->server;
server->sessions = g_slist_remove(server->sessions, session);
+ btd_device_unref(session->device);
g_free(session);
}
@@ -446,7 +448,9 @@ static void avctp_set_state(struct avctp *session, avctp_state_t new_state)
struct audio_device *dev;
avctp_state_t old_state = session->state;
- dev = manager_get_device(&session->server->src, &session->dst, FALSE);
+ dev = manager_get_device(adapter_get_address(session->server->adapter),
+ device_get_address(session->device),
+ FALSE);
if (dev == NULL) {
error("%s(): No matching audio device", __func__);
return;
@@ -838,7 +842,9 @@ static void init_uinput(struct avctp *session)
struct audio_device *dev;
char address[18], name[248 + 1];
- dev = manager_get_device(&session->server->src, &session->dst, FALSE);
+ dev = manager_get_device(adapter_get_address(session->server->adapter),
+ device_get_address(session->device),
+ FALSE);
device_get_name(dev->btd_dev, name, sizeof(name));
if (g_str_equal(name, "Nokia CK-20W")) {
@@ -848,7 +854,7 @@ static void init_uinput(struct avctp *session)
session->key_quirks[AVC_PAUSE] |= QUIRK_NO_RELEASE;
}
- ba2str(&session->dst, address);
+ ba2str(device_get_address(session->device), address);
session->uinput = uinput_create(address);
if (session->uinput < 0)
@@ -998,53 +1004,47 @@ static void auth_cb(DBusError *derr, void *user_data)
}
}
-static struct avctp_server *find_server(GSList *list, const bdaddr_t *src)
+static struct avctp_server *find_server(GSList *list, struct btd_adapter *a)
{
for (; list; list = list->next) {
struct avctp_server *server = list->data;
- if (bacmp(&server->src, src) == 0)
+ if (server->adapter == a)
return server;
}
return NULL;
}
-static struct avctp *find_session(GSList *list, const bdaddr_t *dst)
+static struct avctp *find_session(GSList *list, struct btd_device *device)
{
for (; list != NULL; list = g_slist_next(list)) {
struct avctp *s = list->data;
- if (bacmp(dst, &s->dst))
- continue;
-
- return s;
+ if (s->device == device)
+ return s;
}
return NULL;
}
-static struct avctp *avctp_get_internal(const bdaddr_t *src,
- const bdaddr_t *dst)
+static struct avctp *avctp_get_internal(struct btd_device *device)
{
struct avctp_server *server;
struct avctp *session;
- assert(src != NULL);
- assert(dst != NULL);
-
- server = find_server(servers, src);
+ server = find_server(servers, device_get_adapter(device));
if (server == NULL)
return NULL;
- session = find_session(server->sessions, dst);
+ session = find_session(server->sessions, device);
if (session)
return session;
session = g_new0(struct avctp, 1);
session->server = server;
- bacpy(&session->dst, dst);
+ session->device = btd_device_ref(device);
session->state = AVCTP_STATE_DISCONNECTED;
server->sessions = g_slist_append(server->sessions, session);
@@ -1110,13 +1110,13 @@ static void avctp_confirm_cb(GIOChannel *chan, gpointer data)
struct avctp *session;
struct audio_device *dev;
char address[18];
- bdaddr_t src, dst;
+ bdaddr_t src;
GError *err = NULL;
uint16_t psm;
+ struct btd_device *device;
bt_io_get(chan, &err,
BT_IO_OPT_SOURCE_BDADDR, &src,
- BT_IO_OPT_DEST_BDADDR, &dst,
BT_IO_OPT_DEST, address,
BT_IO_OPT_PSM, &psm,
BT_IO_OPT_INVALID);
@@ -1129,13 +1129,18 @@ static void avctp_confirm_cb(GIOChannel *chan, gpointer data)
DBG("AVCTP: incoming connect from %s", address);
- session = avctp_get_internal(&src, &dst);
+ device = adapter_find_device(manager_find_adapter(&src), address);
+ if (!device)
+ return;
+
+ session = avctp_get_internal(device);
if (session == NULL)
return;
- dev = manager_get_device(&src, &dst, FALSE);
+ dev = manager_get_device(&src, device_get_address(device), FALSE);
if (!dev) {
- dev = manager_get_device(&src, &dst, TRUE);
+ dev = manager_get_device(&src, device_get_address(device),
+ TRUE);
if (!dev) {
error("Unable to get audio device object for %s",
address);
@@ -1187,9 +1192,10 @@ static GIOChannel *avctp_server_socket(const bdaddr_t *src, gboolean master,
return io;
}
-int avctp_register(const bdaddr_t *src, gboolean master)
+int avctp_register(struct btd_adapter *adapter, gboolean master)
{
struct avctp_server *server;
+ const bdaddr_t *src = adapter_get_address(adapter);
server = g_new0(struct avctp_server, 1);
@@ -1211,18 +1217,18 @@ int avctp_register(const bdaddr_t *src, gboolean master)
return -1;
}
- bacpy(&server->src, src);
+ server->adapter = btd_adapter_ref(adapter);
servers = g_slist_append(servers, server);
return 0;
}
-void avctp_unregister(const bdaddr_t *src)
+void avctp_unregister(struct btd_adapter *adapter)
{
struct avctp_server *server;
- server = find_server(servers, src);
+ server = find_server(servers, adapter);
if (!server)
return;
@@ -1237,6 +1243,7 @@ void avctp_unregister(const bdaddr_t *src)
g_io_channel_shutdown(server->control_io, TRUE, NULL);
g_io_channel_unref(server->control_io);
+ btd_adapter_unref(server->adapter);
g_free(server);
}
@@ -1605,13 +1612,8 @@ struct avctp *avctp_connect(struct audio_device *device)
struct avctp *session;
GError *err = NULL;
GIOChannel *io;
- const bdaddr_t *src;
- const bdaddr_t *dst;
- src = adapter_get_address(device_get_adapter(device->btd_dev));
- dst = device_get_address(device->btd_dev);
-
- session = avctp_get_internal(src, dst);
+ session = avctp_get_internal(device->btd_dev);
if (!session)
return NULL;
@@ -1621,8 +1623,10 @@ struct avctp *avctp_connect(struct audio_device *device)
avctp_set_state(session, AVCTP_STATE_CONNECTING);
io = bt_io_connect(avctp_connect_cb, session, NULL, &err,
- BT_IO_OPT_SOURCE_BDADDR, &session->server->src,
- BT_IO_OPT_DEST_BDADDR, &session->dst,
+ BT_IO_OPT_SOURCE_BDADDR,
+ adapter_get_address(session->server->adapter),
+ BT_IO_OPT_DEST_BDADDR,
+ device_get_address(session->device),
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
BT_IO_OPT_PSM, AVCTP_CONTROL_PSM,
BT_IO_OPT_INVALID);
@@ -1651,8 +1655,10 @@ int avctp_connect_browsing(struct avctp *session)
return 0;
io = bt_io_connect(avctp_connect_browsing_cb, session, NULL, &err,
- BT_IO_OPT_SOURCE_BDADDR, &session->server->src,
- BT_IO_OPT_DEST_BDADDR, &session->dst,
+ BT_IO_OPT_SOURCE_BDADDR,
+ adapter_get_address(session->server->adapter),
+ BT_IO_OPT_DEST_BDADDR,
+ device_get_address(session->device),
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
BT_IO_OPT_PSM, AVCTP_BROWSING_PSM,
BT_IO_OPT_MODE, L2CAP_MODE_ERTM,
@@ -1679,11 +1685,5 @@ void avctp_disconnect(struct avctp *session)
struct avctp *avctp_get(struct audio_device *device)
{
- const bdaddr_t *src;
- const bdaddr_t *dst;
-
- src = adapter_get_address(device_get_adapter(device->btd_dev));
- dst = device_get_address(device->btd_dev);
-
- return avctp_get_internal(src, dst);
+ return avctp_get_internal(device->btd_dev);
}
diff --git a/profiles/audio/avctp.h b/profiles/audio/avctp.h
index 2597e6e..c25a3b3 100644
--- a/profiles/audio/avctp.h
+++ b/profiles/audio/avctp.h
@@ -90,8 +90,8 @@ typedef size_t (*avctp_browsing_pdu_cb) (struct avctp *session,
unsigned int avctp_add_state_cb(avctp_state_cb cb, void *user_data);
gboolean avctp_remove_state_cb(unsigned int id);
-int avctp_register(const bdaddr_t *src, gboolean master);
-void avctp_unregister(const bdaddr_t *src);
+int avctp_register(struct btd_adapter *adapter, gboolean master);
+void avctp_unregister(struct btd_adapter *adapter);
struct avctp *avctp_connect(struct audio_device *device);
struct avctp *avctp_get(struct audio_device *device);
diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index 668cd87..4e3d31d 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -2321,7 +2321,7 @@ int avrcp_register(struct btd_adapter *adapter, GKeyFile *config)
}
server->ct_record_id = record->handle;
- if (avctp_register(adapter_get_address(adapter), master) < 0) {
+ if (avctp_register(adapter, master) < 0) {
remove_record_from_server(server->ct_record_id);
remove_record_from_server(server->tg_record_id);
g_free(server);
@@ -2354,7 +2354,7 @@ void avrcp_unregister(struct btd_adapter *adapter)
remove_record_from_server(server->ct_record_id);
remove_record_from_server(server->tg_record_id);
- avctp_unregister(adapter_get_address(server->adapter));
+ avctp_unregister(server->adapter);
btd_adapter_unref(server->adapter);
g_free(server);
--
1.8.0
^ permalink raw reply related
* [PATCH 10/16] avrcp: Convert to accept btd_adapter instead of bdaddr_t
From: Szymon Janc @ 2012-12-12 10:28 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>
This makes avrcp code use reference to btd_adapter structure instead
of adapter source address.
---
profiles/audio/avrcp.c | 37 ++++++++++++++++---------------------
profiles/audio/avrcp.h | 6 +++---
profiles/audio/manager.c | 4 ++--
profiles/audio/media.c | 5 ++---
4 files changed, 23 insertions(+), 29 deletions(-)
diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index 3ab7d35..668cd87 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -159,7 +159,7 @@ struct avrcp_browsing_header {
#define AVRCP_BROWSING_HEADER_LENGTH 3
struct avrcp_server {
- bdaddr_t src;
+ struct btd_adapter *adapter;
uint32_t tg_record_id;
uint32_t ct_record_id;
GSList *players;
@@ -1536,12 +1536,12 @@ size_t avrcp_handle_vendor_reject(uint8_t *code, uint8_t *operands)
return AVRCP_HEADER_LENGTH + 1;
}
-static struct avrcp_server *find_server(GSList *list, const bdaddr_t *src)
+static struct avrcp_server *find_server(GSList *list, struct btd_adapter *a)
{
for (; list; list = list->next) {
struct avrcp_server *server = list->data;
- if (bacmp(&server->src, src) == 0)
+ if (server->adapter == a)
return server;
}
@@ -2217,11 +2217,8 @@ static void state_changed(struct audio_device *dev, avctp_state_t old_state,
{
struct avrcp_server *server;
struct avrcp *session;
- const bdaddr_t *src;
- src = adapter_get_address(device_get_adapter(dev->btd_dev));
-
- server = find_server(servers, src);
+ server = find_server(servers, device_get_adapter(dev->btd_dev));
if (!server)
return;
@@ -2275,7 +2272,7 @@ void avrcp_disconnect(struct audio_device *dev)
avctp_disconnect(session);
}
-int avrcp_register(const bdaddr_t *src, GKeyFile *config)
+int avrcp_register(struct btd_adapter *adapter, GKeyFile *config)
{
sdp_record_t *record;
gboolean tmp, master = TRUE;
@@ -2301,7 +2298,7 @@ int avrcp_register(const bdaddr_t *src, GKeyFile *config)
return -1;
}
- if (add_record_to_server(src, record) < 0) {
+ if (add_record_to_server(adapter_get_address(adapter), record) < 0) {
error("Unable to register AVRCP target service record");
g_free(server);
sdp_record_free(record);
@@ -2316,7 +2313,7 @@ int avrcp_register(const bdaddr_t *src, GKeyFile *config)
return -1;
}
- if (add_record_to_server(src, record) < 0) {
+ if (add_record_to_server(adapter_get_address(adapter), record) < 0) {
error("Unable to register AVRCP service record");
sdp_record_free(record);
g_free(server);
@@ -2324,14 +2321,14 @@ int avrcp_register(const bdaddr_t *src, GKeyFile *config)
}
server->ct_record_id = record->handle;
- if (avctp_register(src, master) < 0) {
+ if (avctp_register(adapter_get_address(adapter), master) < 0) {
remove_record_from_server(server->ct_record_id);
remove_record_from_server(server->tg_record_id);
g_free(server);
return -1;
}
- bacpy(&server->src, src);
+ server->adapter = btd_adapter_ref(adapter);
servers = g_slist_append(servers, server);
@@ -2341,11 +2338,11 @@ int avrcp_register(const bdaddr_t *src, GKeyFile *config)
return 0;
}
-void avrcp_unregister(const bdaddr_t *src)
+void avrcp_unregister(struct btd_adapter *adapter)
{
struct avrcp_server *server;
- server = find_server(servers, src);
+ server = find_server(servers, adapter);
if (!server)
return;
@@ -2357,7 +2354,8 @@ void avrcp_unregister(const bdaddr_t *src)
remove_record_from_server(server->ct_record_id);
remove_record_from_server(server->tg_record_id);
- avctp_unregister(&server->src);
+ avctp_unregister(adapter_get_address(server->adapter));
+ btd_adapter_unref(server->adapter);
g_free(server);
if (servers)
@@ -2369,7 +2367,7 @@ void avrcp_unregister(const bdaddr_t *src)
}
}
-struct avrcp_player *avrcp_register_player(const bdaddr_t *src,
+struct avrcp_player *avrcp_register_player(struct btd_adapter *adapter,
struct avrcp_player_cb *cb,
void *user_data,
GDestroyNotify destroy)
@@ -2378,7 +2376,7 @@ struct avrcp_player *avrcp_register_player(const bdaddr_t *src,
struct avrcp_player *player;
GSList *l;
- server = find_server(servers, src);
+ server = find_server(servers, adapter);
if (!server)
return NULL;
@@ -2448,11 +2446,8 @@ int avrcp_set_volume(struct audio_device *dev, uint8_t volume)
struct avrcp *session;
uint8_t buf[AVRCP_HEADER_LENGTH + 1];
struct avrcp_header *pdu = (void *) buf;
- const bdaddr_t *src;
-
- src = adapter_get_address(device_get_adapter(dev->btd_dev));
- server = find_server(servers, src);
+ server = find_server(servers, device_get_adapter(dev->btd_dev));
if (server == NULL)
return -EINVAL;
diff --git a/profiles/audio/avrcp.h b/profiles/audio/avrcp.h
index e607fb1..b2c0d61 100644
--- a/profiles/audio/avrcp.h
+++ b/profiles/audio/avrcp.h
@@ -92,14 +92,14 @@ struct avrcp_player_cb {
void *user_data);
};
-int avrcp_register(const bdaddr_t *src, GKeyFile *config);
-void avrcp_unregister(const bdaddr_t *src);
+int avrcp_register(struct btd_adapter *adapter, GKeyFile *config);
+void avrcp_unregister(struct btd_adapter *adapter);
gboolean avrcp_connect(struct audio_device *dev);
void avrcp_disconnect(struct audio_device *dev);
int avrcp_set_volume(struct audio_device *dev, uint8_t volume);
-struct avrcp_player *avrcp_register_player(const bdaddr_t *src,
+struct avrcp_player *avrcp_register_player(struct btd_adapter *adapter,
struct avrcp_player_cb *cb,
void *user_data,
GDestroyNotify destroy);
diff --git a/profiles/audio/manager.c b/profiles/audio/manager.c
index d4c52a6..b2e4841 100644
--- a/profiles/audio/manager.c
+++ b/profiles/audio/manager.c
@@ -384,7 +384,7 @@ static int avrcp_server_probe(struct btd_profile *p,
if (!adp)
return -EINVAL;
- err = avrcp_register(adapter_get_address(adapter), config);
+ err = avrcp_register(adapter, config);
if (err < 0)
audio_adapter_unref(adp);
@@ -403,7 +403,7 @@ static void avrcp_server_remove(struct btd_profile *p,
if (!adp)
return;
- avrcp_unregister(adapter_get_address(adapter));
+ avrcp_unregister(adapter);
audio_adapter_unref(adp);
}
diff --git a/profiles/audio/media.c b/profiles/audio/media.c
index 905538e..37eb809 100644
--- a/profiles/audio/media.c
+++ b/profiles/audio/media.c
@@ -1441,9 +1441,8 @@ static struct media_player *media_player_create(struct media_adapter *adapter,
"TrackChanged",
track_changed,
mp, NULL);
- mp->player = avrcp_register_player(adapter_get_address(adapter->btd_adapter),
- &player_cb, mp,
- media_player_free);
+ mp->player = avrcp_register_player(adapter->btd_adapter, &player_cb,
+ mp, media_player_free);
if (!mp->player) {
if (err)
*err = -EPROTONOSUPPORT;
--
1.8.0
^ permalink raw reply related
* [PATCH 09/16] a2dp: Use btd_adapter ref in a2dp_server instead of bdaddr_t
From: Szymon Janc @ 2012-12-12 10:28 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>
Use local refs to device and adapter object instead of addresses.
This allows a2dp code to pass adapter object instead of address.
---
profiles/audio/a2dp.c | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index 593fbf6..da54717 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -48,6 +48,7 @@
#include "a2dp.h"
#include "a2dp-codecs.h"
#include "sdpd.h"
+#include "../src/manager.h"
/* The duration that streams without users are allowed to stay in
* STREAMING state. */
@@ -98,7 +99,7 @@ struct a2dp_setup {
};
struct a2dp_server {
- bdaddr_t src;
+ struct btd_adapter *adapter;
GSList *sinks;
GSList *sources;
uint32_t source_record_id;
@@ -1147,13 +1148,13 @@ static sdp_record_t *a2dp_record(uint8_t type)
return record;
}
-static struct a2dp_server *find_server(GSList *list, const bdaddr_t *src)
+static struct a2dp_server *find_server(GSList *list, struct btd_adapter *a)
{
for (; list; list = list->next) {
struct a2dp_server *server = list->data;
- if (bacmp(&server->src, src) == 0)
+ if (server->adapter == a)
return server;
}
@@ -1175,7 +1176,7 @@ static struct a2dp_server *a2dp_server_register(struct btd_adapter *adapter,
return NULL;
}
- bacpy(&server->src, adapter_get_address(adapter));
+ server->adapter = btd_adapter_ref(adapter);
servers = g_slist_append(servers, server);
return server;
@@ -1185,7 +1186,7 @@ int a2dp_source_register(struct btd_adapter *adapter, GKeyFile *config)
{
struct a2dp_server *server;
- server = find_server(servers, adapter_get_address(adapter));
+ server = find_server(servers, adapter);
if (server != NULL)
goto done;
@@ -1203,7 +1204,7 @@ int a2dp_sink_register(struct btd_adapter *adapter, GKeyFile *config)
{
struct a2dp_server *server;
- server = find_server(servers, adapter_get_address(adapter));
+ server = find_server(servers, adapter);
if (server != NULL)
goto done;
@@ -1232,7 +1233,7 @@ void a2dp_unregister(struct btd_adapter *adapter)
{
struct a2dp_server *server;
- server = find_server(servers, adapter_get_address(adapter));
+ server = find_server(servers, adapter);
if (!server)
return;
@@ -1250,6 +1251,7 @@ void a2dp_unregister(struct btd_adapter *adapter)
if (server->sink_record_id)
remove_record_from_server(server->sink_record_id);
+ btd_adapter_unref(server->adapter);
g_free(server);
}
@@ -1265,7 +1267,7 @@ struct a2dp_sep *a2dp_add_sep(struct btd_adapter *adapter, uint8_t type,
uint32_t *record_id;
sdp_record_t *record;
- server = find_server(servers, adapter_get_address(adapter));
+ server = find_server(servers, adapter);
if (server == NULL) {
if (err)
*err = -EPROTONOSUPPORT;
@@ -1327,7 +1329,8 @@ struct a2dp_sep *a2dp_add_sep(struct btd_adapter *adapter, uint8_t type,
return NULL;
}
- if (add_record_to_server(&server->src, record) < 0) {
+ if (add_record_to_server(adapter_get_address(server->adapter),
+ record) < 0) {
error("Unable to register A2DP service record");
sdp_record_free(record);
avdtp_unregister_sep(sep->lsep);
@@ -1492,7 +1495,7 @@ static struct a2dp_sep *a2dp_select_sep(struct avdtp *session, uint8_t type,
bdaddr_t src;
avdtp_get_peers(session, &src, NULL);
- server = find_server(servers, &src);
+ server = find_server(servers, manager_find_adapter(&src));
if (!server)
return NULL;
@@ -1571,7 +1574,7 @@ unsigned int a2dp_config(struct avdtp *session, struct a2dp_sep *sep,
bdaddr_t src;
avdtp_get_peers(session, &src, NULL);
- server = find_server(servers, &src);
+ server = find_server(servers, manager_find_adapter(&src));
if (!server)
return 0;
@@ -1888,7 +1891,7 @@ struct a2dp_sep *a2dp_get_sep(struct avdtp *session,
for (l = servers; l; l = l->next) {
server = l->data;
- if (bacmp(&src, &server->src) == 0)
+ if (bacmp(&src, adapter_get_address(server->adapter)) == 0)
break;
}
--
1.8.0
^ permalink raw reply related
* [PATCH 08/16] avdtp: Use refs to adapter and device instead of bdaddr_t
From: Szymon Janc @ 2012-12-12 10:28 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>
Use local refs to device and adapter object instead of addresses.
This allows a2dp code to pass adapter object instead of address
and minimise need for finding adapter again with manager API.
---
profiles/audio/a2dp.c | 14 +++----
profiles/audio/avdtp.c | 101 +++++++++++++++++++++----------------------------
profiles/audio/avdtp.h | 7 ++--
3 files changed, 54 insertions(+), 68 deletions(-)
diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index 51119b7..593fbf6 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -1160,7 +1160,7 @@ static struct a2dp_server *find_server(GSList *list, const bdaddr_t *src)
return NULL;
}
-static struct a2dp_server *a2dp_server_register(const bdaddr_t *src,
+static struct a2dp_server *a2dp_server_register(struct btd_adapter *adapter,
GKeyFile *config)
{
struct a2dp_server *server;
@@ -1168,14 +1168,14 @@ static struct a2dp_server *a2dp_server_register(const bdaddr_t *src,
server = g_new0(struct a2dp_server, 1);
- av_err = avdtp_init(src, config);
+ av_err = avdtp_init(adapter, config);
if (av_err < 0) {
DBG("AVDTP not registered");
g_free(server);
return NULL;
}
- bacpy(&server->src, src);
+ bacpy(&server->src, adapter_get_address(adapter));
servers = g_slist_append(servers, server);
return server;
@@ -1189,7 +1189,7 @@ int a2dp_source_register(struct btd_adapter *adapter, GKeyFile *config)
if (server != NULL)
goto done;
- server = a2dp_server_register(adapter_get_address(adapter), config);
+ server = a2dp_server_register(adapter, config);
if (server == NULL)
return -EPROTONOSUPPORT;
@@ -1207,7 +1207,7 @@ int a2dp_sink_register(struct btd_adapter *adapter, GKeyFile *config)
if (server != NULL)
goto done;
- server = a2dp_server_register(adapter_get_address(adapter), config);
+ server = a2dp_server_register(adapter, config);
if (server == NULL)
return -EPROTONOSUPPORT;
@@ -1240,7 +1240,7 @@ void a2dp_unregister(struct btd_adapter *adapter)
g_slist_free_full(server->sources,
(GDestroyNotify) a2dp_unregister_sep);
- avdtp_exit(adapter_get_address(adapter));
+ avdtp_exit(adapter);
servers = g_slist_remove(servers, server);
@@ -1286,7 +1286,7 @@ struct a2dp_sep *a2dp_add_sep(struct btd_adapter *adapter, uint8_t type,
sep = g_new0(struct a2dp_sep, 1);
- sep->lsep = avdtp_register_sep(&server->src, type,
+ sep->lsep = avdtp_register_sep(adapter, type,
AVDTP_MEDIA_TYPE_AUDIO, codec,
delay_reporting, &endpoint_ind,
&cfm, sep);
diff --git a/profiles/audio/avdtp.c b/profiles/audio/avdtp.c
index 1d6c71e..20fdf25 100644
--- a/profiles/audio/avdtp.c
+++ b/profiles/audio/avdtp.c
@@ -330,7 +330,7 @@ struct avdtp_remote_sep {
};
struct avdtp_server {
- bdaddr_t src;
+ struct btd_adapter *adapter;
GIOChannel *io;
GSList *seps;
GSList *sessions;
@@ -391,7 +391,7 @@ struct avdtp {
uint16_t version;
struct avdtp_server *server;
- bdaddr_t dst;
+ struct btd_device *device;
avdtp_session_state_t state;
@@ -454,12 +454,12 @@ static void avdtp_sep_set_state(struct avdtp *session,
avdtp_state_t state);
static void auth_cb(DBusError *derr, void *user_data);
-static struct avdtp_server *find_server(GSList *list, const bdaddr_t *src)
+static struct avdtp_server *find_server(GSList *list, struct btd_adapter *a)
{
for (; list; list = list->next) {
struct avdtp_server *server = list->data;
- if (bacmp(&server->src, src) == 0)
+ if (server->adapter == a)
return server;
}
@@ -1157,7 +1157,9 @@ static gboolean disconnect_timeout(gpointer user_data)
stream_setup = session->stream_setup;
session->stream_setup = FALSE;
- dev = manager_get_device(&session->server->src, &session->dst, FALSE);
+ dev = manager_get_device(adapter_get_address(session->server->adapter),
+ device_get_address(session->device),
+ FALSE);
if (dev && dev->sink && stream_setup)
sink_setup_stream(dev->sink, session);
@@ -1189,7 +1191,7 @@ static void connection_lost(struct avdtp *session, int err)
struct avdtp_server *server = session->server;
char address[18];
- ba2str(&session->dst, address);
+ ba2str(device_get_address(session->device), address);
DBG("Disconnected from %s", address);
if (err != EACCES)
@@ -1206,6 +1208,7 @@ static void connection_lost(struct avdtp *session, int err)
return;
server->sessions = g_slist_remove(server->sessions, session);
+ btd_device_unref(session->device);
avdtp_free(session);
}
@@ -2273,15 +2276,13 @@ failed:
return FALSE;
}
-static struct avdtp *find_session(GSList *list, const bdaddr_t *dst)
+static struct avdtp *find_session(GSList *list, struct btd_device *device)
{
for (; list != NULL; list = g_slist_next(list)) {
struct avdtp *s = list->data;
- if (bacmp(dst, &s->dst))
- continue;
-
- return s;
+ if (s->device == device)
+ return s;
}
return NULL;
@@ -2289,26 +2290,14 @@ static struct avdtp *find_session(GSList *list, const bdaddr_t *dst)
static uint16_t get_version(struct avdtp *session)
{
- struct btd_adapter *adapter;
- struct btd_device *device;
const sdp_record_t *rec;
sdp_list_t *protos;
sdp_data_t *proto_desc;
- char addr[18];
uint16_t ver = 0x0100;
- adapter = manager_find_adapter(&session->server->src);
- if (!adapter)
- return ver;
-
- ba2str(&session->dst, addr);
- device = adapter_find_device(adapter, addr);
- if (!device)
- return ver;
-
- rec = btd_device_get_record(device, A2DP_SINK_UUID);
+ rec = btd_device_get_record(session->device, A2DP_SINK_UUID);
if (!rec)
- rec = btd_device_get_record(device, A2DP_SOURCE_UUID);
+ rec = btd_device_get_record(session->device, A2DP_SOURCE_UUID);
if (!rec)
return ver;
@@ -2326,19 +2315,16 @@ static uint16_t get_version(struct avdtp *session)
return ver;
}
-static struct avdtp *avdtp_get_internal(const bdaddr_t *src, const bdaddr_t *dst)
+static struct avdtp *avdtp_get_internal(struct btd_device *device)
{
struct avdtp_server *server;
struct avdtp *session;
- assert(src != NULL);
- assert(dst != NULL);
-
- server = find_server(servers, src);
+ server = find_server(servers, device_get_adapter(device));
if (server == NULL)
return NULL;
- session = find_session(server->sessions, dst);
+ session = find_session(server->sessions, device);
if (session) {
if (session->pending_auth)
return NULL;
@@ -2349,7 +2335,7 @@ static struct avdtp *avdtp_get_internal(const bdaddr_t *src, const bdaddr_t *dst
session = g_new0(struct avdtp, 1);
session->server = server;
- bacpy(&session->dst, dst);
+ session->device = btd_device_ref(device);
/* We don't use avdtp_set_state() here since this isn't a state change
* but just setting of the initial state */
session->state = AVDTP_SESSION_STATE_DISCONNECTED;
@@ -2364,13 +2350,8 @@ static struct avdtp *avdtp_get_internal(const bdaddr_t *src, const bdaddr_t *dst
struct avdtp *avdtp_get(struct audio_device *device)
{
struct avdtp *session;
- const bdaddr_t *src;
- const bdaddr_t *dst;
- src = adapter_get_address(device_get_adapter(device->btd_dev));
- dst = device_get_address(device->btd_dev);
-
- session = avdtp_get_internal(src, dst);
+ session = avdtp_get_internal(device->btd_dev);
if (!session)
return NULL;
@@ -2403,7 +2384,7 @@ static void avdtp_connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
goto failed;
}
- ba2str(&session->dst, address);
+ ba2str(device_get_address(session->device), address);
DBG("AVDTP: connected %s channel to %s",
session->pending_open ? "transport" : "signaling",
address);
@@ -2487,6 +2468,7 @@ static void avdtp_confirm_cb(GIOChannel *chan, gpointer data)
char address[18];
bdaddr_t src, dst;
GError *err = NULL;
+ struct btd_device *device;
bt_io_get(chan, &err,
BT_IO_OPT_SOURCE_BDADDR, &src,
@@ -2501,7 +2483,11 @@ static void avdtp_confirm_cb(GIOChannel *chan, gpointer data)
DBG("AVDTP: incoming connect from %s", address);
- session = avdtp_get_internal(&src, &dst);
+ device = adapter_find_device(manager_find_adapter(&src), address);
+ if (!device)
+ goto drop;
+
+ session = avdtp_get_internal(device);
if (!session)
goto drop;
@@ -2565,8 +2551,10 @@ static GIOChannel *l2cap_connect(struct avdtp *session)
io = bt_io_connect(avdtp_connect_cb, session,
NULL, &err,
- BT_IO_OPT_SOURCE_BDADDR, &session->server->src,
- BT_IO_OPT_DEST_BDADDR, &session->dst,
+ BT_IO_OPT_SOURCE_BDADDR,
+ adapter_get_address(session->server->adapter),
+ BT_IO_OPT_DEST_BDADDR,
+ device_get_address(session->device),
BT_IO_OPT_PSM, AVDTP_PSM,
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
BT_IO_OPT_INVALID);
@@ -3201,17 +3189,12 @@ gboolean avdtp_is_connected(struct audio_device *device)
{
struct avdtp_server *server;
struct avdtp *session;
- const bdaddr_t *src;
- const bdaddr_t *dst;
-
- src = adapter_get_address(device_get_adapter(device->btd_dev));
- dst = device_get_address(device->btd_dev);
- server = find_server(servers, src);
+ server = find_server(servers, device_get_adapter(device->btd_dev));
if (!server)
return FALSE;
- session = find_session(server->sessions, dst);
+ session = find_session(server->sessions, device->btd_dev);
if (!session)
return FALSE;
@@ -3732,7 +3715,8 @@ int avdtp_delay_report(struct avdtp *session, struct avdtp_stream *stream,
&req, sizeof(req));
}
-struct avdtp_local_sep *avdtp_register_sep(const bdaddr_t *src, uint8_t type,
+struct avdtp_local_sep *avdtp_register_sep(struct btd_adapter *adapter,
+ uint8_t type,
uint8_t media_type,
uint8_t codec_type,
gboolean delay_reporting,
@@ -3743,7 +3727,7 @@ struct avdtp_local_sep *avdtp_register_sep(const bdaddr_t *src, uint8_t type,
struct avdtp_server *server;
struct avdtp_local_sep *sep;
- server = find_server(servers, src);
+ server = find_server(servers, adapter);
if (!server)
return NULL;
@@ -3864,12 +3848,12 @@ avdtp_state_t avdtp_sep_get_state(struct avdtp_local_sep *sep)
void avdtp_get_peers(struct avdtp *session, bdaddr_t *src, bdaddr_t *dst)
{
if (src)
- bacpy(src, &session->server->src);
+ bacpy(src, adapter_get_address(session->server->adapter));
if (dst)
- bacpy(dst, &session->dst);
+ bacpy(dst, device_get_address(session->device));
}
-int avdtp_init(const bdaddr_t *src, GKeyFile *config)
+int avdtp_init(struct btd_adapter *adapter, GKeyFile *config)
{
GError *err = NULL;
gboolean tmp, master = TRUE;
@@ -3889,24 +3873,24 @@ int avdtp_init(const bdaddr_t *src, GKeyFile *config)
proceed:
server = g_new0(struct avdtp_server, 1);
- server->io = avdtp_server_socket(src, master);
+ server->io = avdtp_server_socket(adapter_get_address(adapter), master);
if (!server->io) {
g_free(server);
return -1;
}
- bacpy(&server->src, src);
+ server->adapter = btd_adapter_ref(adapter);
servers = g_slist_append(servers, server);
return 0;
}
-void avdtp_exit(const bdaddr_t *src)
+void avdtp_exit(struct btd_adapter *adapter)
{
struct avdtp_server *server;
- server = find_server(servers, src);
+ server = find_server(servers, adapter);
if (!server)
return;
@@ -3916,6 +3900,7 @@ void avdtp_exit(const bdaddr_t *src)
g_io_channel_shutdown(server->io, TRUE, NULL);
g_io_channel_unref(server->io);
+ btd_adapter_unref(server->adapter);
g_free(server);
}
diff --git a/profiles/audio/avdtp.h b/profiles/audio/avdtp.h
index e014623..dbdf8f4 100644
--- a/profiles/audio/avdtp.h
+++ b/profiles/audio/avdtp.h
@@ -282,7 +282,8 @@ int avdtp_abort(struct avdtp *session, struct avdtp_stream *stream);
int avdtp_delay_report(struct avdtp *session, struct avdtp_stream *stream,
uint16_t delay);
-struct avdtp_local_sep *avdtp_register_sep(const bdaddr_t *src, uint8_t type,
+struct avdtp_local_sep *avdtp_register_sep(struct btd_adapter *adapter,
+ uint8_t type,
uint8_t media_type,
uint8_t codec_type,
gboolean delay_reporting,
@@ -309,5 +310,5 @@ void avdtp_get_peers(struct avdtp *session, bdaddr_t *src, bdaddr_t *dst);
gboolean avdtp_stream_setup_active(struct avdtp *session);
void avdtp_set_device_disconnect(struct avdtp *session, gboolean dev_dc);
-int avdtp_init(const bdaddr_t *src, GKeyFile *config);
-void avdtp_exit(const bdaddr_t *src);
+int avdtp_init(struct btd_adapter *adapter, GKeyFile *config);
+void avdtp_exit(struct btd_adapter *adapter);
--
1.8.0
^ permalink raw reply related
* [PATCH 07/16] a2dp: Convert a2dp_add_sep to accept struct btd_adapter
From: Szymon Janc @ 2012-12-12 10:27 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>
Pass btd_adapter directly or use getters to get needed data from
adapter object.
---
profiles/audio/a2dp.c | 4 ++--
profiles/audio/a2dp.h | 2 +-
profiles/audio/media.c | 12 ++----------
3 files changed, 5 insertions(+), 13 deletions(-)
diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index c145ca4..51119b7 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -1253,7 +1253,7 @@ void a2dp_unregister(struct btd_adapter *adapter)
g_free(server);
}
-struct a2dp_sep *a2dp_add_sep(const bdaddr_t *src, uint8_t type,
+struct a2dp_sep *a2dp_add_sep(struct btd_adapter *adapter, uint8_t type,
uint8_t codec, gboolean delay_reporting,
struct a2dp_endpoint *endpoint,
void *user_data, GDestroyNotify destroy,
@@ -1265,7 +1265,7 @@ struct a2dp_sep *a2dp_add_sep(const bdaddr_t *src, uint8_t type,
uint32_t *record_id;
sdp_record_t *record;
- server = find_server(servers, src);
+ server = find_server(servers, adapter_get_address(adapter));
if (server == NULL) {
if (err)
*err = -EPROTONOSUPPORT;
diff --git a/profiles/audio/a2dp.h b/profiles/audio/a2dp.h
index f45e40d..dab9195 100644
--- a/profiles/audio/a2dp.h
+++ b/profiles/audio/a2dp.h
@@ -68,7 +68,7 @@ int a2dp_source_register(struct btd_adapter *adapter, GKeyFile *config);
int a2dp_sink_register(struct btd_adapter *adapter, GKeyFile *config);
void a2dp_unregister(struct btd_adapter *adapter);
-struct a2dp_sep *a2dp_add_sep(const bdaddr_t *src, uint8_t type,
+struct a2dp_sep *a2dp_add_sep(struct btd_adapter *adapter, uint8_t type,
uint8_t codec, gboolean delay_reporting,
struct a2dp_endpoint *endpoint,
void *user_data, GDestroyNotify destroy,
diff --git a/profiles/audio/media.c b/profiles/audio/media.c
index c18dc4e..905538e 100644
--- a/profiles/audio/media.c
+++ b/profiles/audio/media.c
@@ -552,11 +552,7 @@ static gboolean endpoint_init_a2dp_source(struct media_endpoint *endpoint,
gboolean delay_reporting,
int *err)
{
- const bdaddr_t *src;
-
- src = adapter_get_address(endpoint->adapter->btd_adapter);
-
- endpoint->sep = a2dp_add_sep(src,
+ endpoint->sep = a2dp_add_sep(endpoint->adapter->btd_adapter,
AVDTP_SEP_TYPE_SOURCE, endpoint->codec,
delay_reporting, &a2dp_endpoint,
endpoint, a2dp_destroy_endpoint, err);
@@ -570,11 +566,7 @@ static gboolean endpoint_init_a2dp_sink(struct media_endpoint *endpoint,
gboolean delay_reporting,
int *err)
{
- const bdaddr_t *src;
-
- src = adapter_get_address(endpoint->adapter->btd_adapter);
-
- endpoint->sep = a2dp_add_sep(src,
+ endpoint->sep = a2dp_add_sep(endpoint->adapter->btd_adapter,
AVDTP_SEP_TYPE_SINK, endpoint->codec,
delay_reporting, &a2dp_endpoint,
endpoint, a2dp_destroy_endpoint, err);
--
1.8.0
^ permalink raw reply related
* [PATCH 06/16] media: Convert register/unregister to accept btd_adapter
From: Szymon Janc @ 2012-12-12 10:27 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>
Keep reference to passed btd_adapter and use it to get adapter address
and path.
---
profiles/audio/manager.c | 10 ++++------
profiles/audio/media.c | 44 ++++++++++++++++++++++++++------------------
profiles/audio/media.h | 4 ++--
3 files changed, 32 insertions(+), 26 deletions(-)
diff --git a/profiles/audio/manager.c b/profiles/audio/manager.c
index b355281..d4c52a6 100644
--- a/profiles/audio/manager.c
+++ b/profiles/audio/manager.c
@@ -410,16 +410,15 @@ static void avrcp_server_remove(struct btd_profile *p,
static int media_server_probe(struct btd_adapter *adapter)
{
struct audio_adapter *adp;
- const gchar *path = adapter_get_path(adapter);
int err;
- DBG("path %s", path);
+ DBG("path %s", adapter_get_path(adapter));
adp = audio_adapter_get(adapter);
if (!adp)
return -EINVAL;
- err = media_register(path, adapter_get_address(adapter));
+ err = media_register(adapter);
if (err < 0)
audio_adapter_unref(adp);
@@ -429,15 +428,14 @@ static int media_server_probe(struct btd_adapter *adapter)
static void media_server_remove(struct btd_adapter *adapter)
{
struct audio_adapter *adp;
- const gchar *path = adapter_get_path(adapter);
- DBG("path %s", path);
+ DBG("path %s", adapter_get_path(adapter));
adp = find_adapter(adapters, adapter);
if (!adp)
return;
- media_unregister(path);
+ media_unregister(adapter);
audio_adapter_unref(adp);
}
diff --git a/profiles/audio/media.c b/profiles/audio/media.c
index 0839f69..c18dc4e 100644
--- a/profiles/audio/media.c
+++ b/profiles/audio/media.c
@@ -57,8 +57,7 @@
#define REQUEST_TIMEOUT (3 * 1000) /* 3 seconds */
struct media_adapter {
- bdaddr_t src; /* Adapter address */
- char *path; /* Adapter path */
+ struct btd_adapter *btd_adapter;
GSList *endpoints; /* Endpoints list */
GSList *players; /* Players list */
};
@@ -553,7 +552,11 @@ static gboolean endpoint_init_a2dp_source(struct media_endpoint *endpoint,
gboolean delay_reporting,
int *err)
{
- endpoint->sep = a2dp_add_sep(&endpoint->adapter->src,
+ const bdaddr_t *src;
+
+ src = adapter_get_address(endpoint->adapter->btd_adapter);
+
+ endpoint->sep = a2dp_add_sep(src,
AVDTP_SEP_TYPE_SOURCE, endpoint->codec,
delay_reporting, &a2dp_endpoint,
endpoint, a2dp_destroy_endpoint, err);
@@ -567,7 +570,11 @@ static gboolean endpoint_init_a2dp_sink(struct media_endpoint *endpoint,
gboolean delay_reporting,
int *err)
{
- endpoint->sep = a2dp_add_sep(&endpoint->adapter->src,
+ const bdaddr_t *src;
+
+ src = adapter_get_address(endpoint->adapter->btd_adapter);
+
+ endpoint->sep = a2dp_add_sep(src,
AVDTP_SEP_TYPE_SINK, endpoint->codec,
delay_reporting, &a2dp_endpoint,
endpoint, a2dp_destroy_endpoint, err);
@@ -608,10 +615,8 @@ static bool endpoint_properties_exists(const char *uuid,
void *user_data)
{
struct media_adapter *adapter = user_data;
- struct btd_adapter *btd_adapter = device_get_adapter(dev);
- const bdaddr_t *src = adapter_get_address(btd_adapter);
- if (bacmp(&adapter->src, src) != 0)
+ if (adapter->btd_adapter != device_get_adapter(dev))
return false;
if (media_adapter_find_endpoint(adapter, NULL, NULL, uuid) == NULL)
@@ -1444,8 +1449,9 @@ static struct media_player *media_player_create(struct media_adapter *adapter,
"TrackChanged",
track_changed,
mp, NULL);
- mp->player = avrcp_register_player(&adapter->src, &player_cb, mp,
- media_player_free);
+ mp->player = avrcp_register_player(adapter_get_address(adapter->btd_adapter),
+ &player_cb, mp,
+ media_player_free);
if (!mp->player) {
if (err)
*err = -EPROTONOSUPPORT;
@@ -1558,23 +1564,24 @@ static void path_free(void *data)
adapters = g_slist_remove(adapters, adapter);
- g_free(adapter->path);
+ btd_adapter_unref(adapter->btd_adapter);
g_free(adapter);
}
-int media_register(const char *path, const bdaddr_t *src)
+int media_register(struct btd_adapter *btd_adapter)
{
struct media_adapter *adapter;
adapter = g_new0(struct media_adapter, 1);
- bacpy(&adapter->src, src);
- adapter->path = g_strdup(path);
+ adapter->btd_adapter = btd_adapter_ref(btd_adapter);
if (!g_dbus_register_interface(btd_get_dbus_connection(),
- path, MEDIA_INTERFACE,
+ adapter_get_path(btd_adapter),
+ MEDIA_INTERFACE,
media_methods, NULL, NULL,
adapter, path_free)) {
- error("D-Bus failed to register %s path", path);
+ error("D-Bus failed to register %s path",
+ adapter_get_path(btd_adapter));
path_free(adapter);
return -1;
}
@@ -1584,16 +1591,17 @@ int media_register(const char *path, const bdaddr_t *src)
return 0;
}
-void media_unregister(const char *path)
+void media_unregister(struct btd_adapter *btd_adapter)
{
GSList *l;
for (l = adapters; l; l = l->next) {
struct media_adapter *adapter = l->data;
- if (g_strcmp0(path, adapter->path) == 0) {
+ if (adapter->btd_adapter == btd_adapter) {
g_dbus_unregister_interface(btd_get_dbus_connection(),
- path, MEDIA_INTERFACE);
+ adapter_get_path(btd_adapter),
+ MEDIA_INTERFACE);
return;
}
}
diff --git a/profiles/audio/media.h b/profiles/audio/media.h
index 82b9694..dd630d4 100644
--- a/profiles/audio/media.h
+++ b/profiles/audio/media.h
@@ -27,8 +27,8 @@ struct media_endpoint;
typedef void (*media_endpoint_cb_t) (struct media_endpoint *endpoint,
void *ret, int size, void *user_data);
-int media_register(const char *path, const bdaddr_t *src);
-void media_unregister(const char *path);
+int media_register(struct btd_adapter *btd_adapter);
+void media_unregister(struct btd_adapter *btd_adapter);
struct a2dp_sep *media_endpoint_get_sep(struct media_endpoint *endpoint);
const char *media_endpoint_get_uuid(struct media_endpoint *endpoint);
--
1.8.0
^ permalink raw reply related
* [PATCH 05/16] a2dp: Convert a2dp_unregister to accept btd_adapter
From: Szymon Janc @ 2012-12-12 10:27 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>
Pass btd_adapter directly or use getters to get needed data from
adapter object.
---
profiles/audio/a2dp.c | 6 +++---
profiles/audio/a2dp.h | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index eeecb43..c145ca4 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -1228,11 +1228,11 @@ static void a2dp_unregister_sep(struct a2dp_sep *sep)
g_free(sep);
}
-void a2dp_unregister(const bdaddr_t *src)
+void a2dp_unregister(struct btd_adapter *adapter)
{
struct a2dp_server *server;
- server = find_server(servers, src);
+ server = find_server(servers, adapter_get_address(adapter));
if (!server)
return;
@@ -1240,7 +1240,7 @@ void a2dp_unregister(const bdaddr_t *src)
g_slist_free_full(server->sources,
(GDestroyNotify) a2dp_unregister_sep);
- avdtp_exit(src);
+ avdtp_exit(adapter_get_address(adapter));
servers = g_slist_remove(servers, server);
diff --git a/profiles/audio/a2dp.h b/profiles/audio/a2dp.h
index 827d5cc..f45e40d 100644
--- a/profiles/audio/a2dp.h
+++ b/profiles/audio/a2dp.h
@@ -66,7 +66,7 @@ typedef void (*a2dp_stream_cb_t) (struct avdtp *session,
int a2dp_source_register(struct btd_adapter *adapter, GKeyFile *config);
int a2dp_sink_register(struct btd_adapter *adapter, GKeyFile *config);
-void a2dp_unregister(const bdaddr_t *src);
+void a2dp_unregister(struct btd_adapter *adapter);
struct a2dp_sep *a2dp_add_sep(const bdaddr_t *src, uint8_t type,
uint8_t codec, gboolean delay_reporting,
--
1.8.0
^ permalink raw reply related
* [PATCH 04/16] a2dp: Convert sink/source register to accept btd_adapter
From: Szymon Janc @ 2012-12-12 10:27 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>
Pass btd_adapter directly or use getters to get needed data from
adapter object.
---
profiles/audio/a2dp.c | 14 ++++++++------
profiles/audio/a2dp.h | 4 ++--
profiles/audio/manager.c | 4 ++--
profiles/audio/sink.c | 5 +++--
profiles/audio/source.c | 5 +++--
5 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index ac5c513..eeecb43 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -37,6 +37,8 @@
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>
+#include "../src/adapter.h"
+
#include "log.h"
#include "device.h"
#include "manager.h"
@@ -1179,15 +1181,15 @@ static struct a2dp_server *a2dp_server_register(const bdaddr_t *src,
return server;
}
-int a2dp_source_register(const bdaddr_t *src, GKeyFile *config)
+int a2dp_source_register(struct btd_adapter *adapter, GKeyFile *config)
{
struct a2dp_server *server;
- server = find_server(servers, src);
+ server = find_server(servers, adapter_get_address(adapter));
if (server != NULL)
goto done;
- server = a2dp_server_register(src, config);
+ server = a2dp_server_register(adapter_get_address(adapter), config);
if (server == NULL)
return -EPROTONOSUPPORT;
@@ -1197,15 +1199,15 @@ done:
return 0;
}
-int a2dp_sink_register(const bdaddr_t *src, GKeyFile *config)
+int a2dp_sink_register(struct btd_adapter *adapter, GKeyFile *config)
{
struct a2dp_server *server;
- server = find_server(servers, src);
+ server = find_server(servers, adapter_get_address(adapter));
if (server != NULL)
goto done;
- server = a2dp_server_register(src, config);
+ server = a2dp_server_register(adapter_get_address(adapter), config);
if (server == NULL)
return -EPROTONOSUPPORT;
diff --git a/profiles/audio/a2dp.h b/profiles/audio/a2dp.h
index ded1060..827d5cc 100644
--- a/profiles/audio/a2dp.h
+++ b/profiles/audio/a2dp.h
@@ -64,8 +64,8 @@ typedef void (*a2dp_stream_cb_t) (struct avdtp *session,
struct avdtp_error *err,
void *user_data);
-int a2dp_source_register(const bdaddr_t *src, GKeyFile *config);
-int a2dp_sink_register(const bdaddr_t *src, GKeyFile *config);
+int a2dp_source_register(struct btd_adapter *adapter, GKeyFile *config);
+int a2dp_sink_register(struct btd_adapter *adapter, GKeyFile *config);
void a2dp_unregister(const bdaddr_t *src);
struct a2dp_sep *a2dp_add_sep(const bdaddr_t *src, uint8_t type,
diff --git a/profiles/audio/manager.c b/profiles/audio/manager.c
index 7025868..b355281 100644
--- a/profiles/audio/manager.c
+++ b/profiles/audio/manager.c
@@ -351,7 +351,7 @@ static int a2dp_source_server_probe(struct btd_profile *p,
audio_adapter_unref(adp); /* Referenced by a2dp server */
- return a2dp_source_register(adapter_get_address(adapter), config);
+ return a2dp_source_register(adapter, config);
}
static int a2dp_sink_server_probe(struct btd_profile *p,
@@ -368,7 +368,7 @@ static int a2dp_sink_server_probe(struct btd_profile *p,
audio_adapter_unref(adp); /* Referenced by a2dp server */
- return a2dp_sink_register(adapter_get_address(adapter), config);
+ return a2dp_sink_register(adapter, config);
}
static int avrcp_server_probe(struct btd_profile *p,
diff --git a/profiles/audio/sink.c b/profiles/audio/sink.c
index 62ec601..a3d9b1f 100644
--- a/profiles/audio/sink.c
+++ b/profiles/audio/sink.c
@@ -39,6 +39,9 @@
#include "log.h"
+#include "../src/adapter.h"
+#include "../src/device.h"
+
#include "device.h"
#include "avdtp.h"
#include "media.h"
@@ -46,8 +49,6 @@
#include "error.h"
#include "sink.h"
#include "dbus-common.h"
-#include "../src/adapter.h"
-#include "../src/device.h"
#define STREAM_SETUP_RETRY_TIMER 2
diff --git a/profiles/audio/source.c b/profiles/audio/source.c
index ef6cf7a..efd6946 100644
--- a/profiles/audio/source.c
+++ b/profiles/audio/source.c
@@ -40,6 +40,9 @@
#include "log.h"
+#include "../src/adapter.h"
+#include "../src/device.h"
+
#include "device.h"
#include "avdtp.h"
#include "media.h"
@@ -48,8 +51,6 @@
#include "manager.h"
#include "source.h"
#include "dbus-common.h"
-#include "../src/adapter.h"
-#include "../src/device.h"
#define STREAM_SETUP_RETRY_TIMER 2
--
1.8.0
^ permalink raw reply related
* [PATCH 03/16] a2dp: Remove not used macros definitions
From: Szymon Janc @ 2012-12-12 10:27 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>
MIN and MAX macros are not used.
---
profiles/audio/a2dp.c | 8 --------
1 file changed, 8 deletions(-)
diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index aef998a..ac5c513 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -52,14 +52,6 @@
#define SUSPEND_TIMEOUT 5
#define RECONFIGURE_TIMEOUT 500
-#ifndef MIN
-# define MIN(x, y) ((x) < (y) ? (x) : (y))
-#endif
-
-#ifndef MAX
-# define MAX(x, y) ((x) > (y) ? (x) : (y))
-#endif
-
struct a2dp_sep {
struct a2dp_server *server;
struct a2dp_endpoint *endpoint;
--
1.8.0
^ permalink raw reply related
* [PATCH 02/16] a2dp: Remove useless return
From: Szymon Janc @ 2012-12-12 10:27 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>
This code does nothing.
---
profiles/audio/a2dp.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index 8e9f626..aef998a 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -1257,9 +1257,6 @@ void a2dp_unregister(const bdaddr_t *src)
remove_record_from_server(server->sink_record_id);
g_free(server);
-
- if (servers)
- return;
}
struct a2dp_sep *a2dp_add_sep(const bdaddr_t *src, uint8_t type,
--
1.8.0
^ permalink raw reply related
* [PATCH 01/16] a2dp: Remove bogus '\' at the end of line
From: Szymon Janc @ 2012-12-12 10:27 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>
---
profiles/audio/a2dp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index 177f653..8e9f626 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -1337,7 +1337,7 @@ struct a2dp_sep *a2dp_add_sep(const bdaddr_t *src, uint8_t type,
}
if (add_record_to_server(&server->src, record) < 0) {
- error("Unable to register A2DP service record");\
+ error("Unable to register A2DP service record");
sdp_record_free(record);
avdtp_unregister_sep(sep->lsep);
g_free(sep);
--
1.8.0
^ permalink raw reply related
* [PATCH 00/16] audio: Use device/adapter reference instead of bdaddr_t
From: Szymon Janc @ 2012-12-12 10:27 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This remove use of bdaddr_t in favour of using references to struct btd_adapter
and struct btd_device.
note:
This patch triggers a bug introduced when a2dp was splitted into two
btd_profile resulting in a2dp_unregister() is never called (so adapter
ref is not dropped properly). This is not fixed in this patch set.
Szymon Janc (16):
a2dp: Remove bogus '\' at the end of line
a2dp: Remove useless return
a2dp: Remove not used macros definitions
a2dp: Convert sink/source register to accept btd_adapter
a2dp: Convert a2dp_unregister to accept btd_adapter
media: Convert register/unregister to accept btd_adapter
a2dp: Convert a2dp_add_sep to accept struct btd_adapter
avdtp: Use refs to adapter and device instead of bdaddr_t
a2dp: Use btd_adapter ref in a2dp_server instead of bdaddr_t
avrcp: Convert to accept btd_adapter instead of bdaddr_t
avctp: Convert register/unregister to accept btd_adapter
avdtp: Replace avdtp_get_peers with adapter and device getters
audio: Use manager_get_device to get device object
audio: Make manager_get_device accept btd_device
audio: Simplify manager_find_device
avctp: Remove double looking for audio device
profiles/audio/a2dp.c | 75 +++++++++++---------------
profiles/audio/a2dp.h | 8 +--
profiles/audio/avctp.c | 96 +++++++++++++++-------------------
profiles/audio/avctp.h | 4 +-
profiles/audio/avdtp.c | 119 ++++++++++++++++++------------------------
profiles/audio/avdtp.h | 10 ++--
profiles/audio/avrcp.c | 37 ++++++-------
profiles/audio/avrcp.h | 6 +--
profiles/audio/manager.c | 133 +++++++++--------------------------------------
profiles/audio/manager.h | 17 +-----
profiles/audio/media.c | 35 ++++++-------
profiles/audio/media.h | 4 +-
profiles/audio/sink.c | 5 +-
profiles/audio/source.c | 5 +-
14 files changed, 206 insertions(+), 348 deletions(-)
--
1.8.0
^ permalink raw reply
* RE: [BLE] org.bluez.Device1.Connect() returns org.bluez.Error.NotAvailable
From: Ting Chou @ 2012-12-12 10:21 UTC (permalink / raw)
To: Johan Hedberg; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <20121212100737.GA6620@x220>
Hello Johan,
> -----Original Message-----
> From: Johan Hedberg [mailto:johan.hedberg@gmail.com]
> Sent: Wednesday, December 12, 2012 6:08 PM
> To: Ting Chou
> Cc: linux-bluetooth@vger.kernel.org
> Subject: Re: [BLE] org.bluez.Device1.Connect() returns
> org.bluez.Error.NotAvailable
>
> Hi Ting,
>
> On Wed, Dec 12, 2012, Ting Chou wrote:
> > > That means that the profiles that are supposed to be supported with
> > > this device are not calling either device_set_auto_connect() or
> > > btd_device_add_attio_callback(). Both of those functions should
> > > cause bluetoothd to start doing passive scanning and try to connect
> > > to the device. Btw, which kernel version are you using. IIRC you'll
> > > need something like 3.5 or newer for LE passive scanning to work.
> > >
> >
> > I tried to let btd_device_add_attio_callback() get called by
> >
> > Characterisitc.DiscoverCharacteristics()
>
> I thought you said some internally supported profiles get detected? Why
> then do you need to use the ATT D-Bus interface? FWIW, since
> attrib/client.c implementation doesn't match what's documented and
> since there hasn't been anyone stepping up to update the code to use D-
> Bus properties we'll probably not have the entire Characteristic D-Bus
> interface in the 5.0 release. Instead, there's a plan to have a more
> comprehensive and generic GATT D-Bus API for both peripheral and
> central roles, which will probably land in 5.1 or one of the subsequent
> releases.
>
> > But still the Device1.Connect() after Device1.Disconnect() does not
> > establish the connection. connect_profiles() returns
> > btd_error_not_available() since
> > !dev->pending:
>
> It seems you've misunderstood this part. If the functions I mentioned
> are used correctly you will not need to use Device.Connect at all.
> Instead bluetoothd will start doing passive scanning and automatically
> establish a connection to any device doing connectable advertising.
>
Do you mean once a LE device with internally supported profiles is discovered,
it will be connected automatically? Which means I cannot connect manually, at
the timing I prefer?
Since with my BT 4.0 dongle, Adpater.StartDiscovery discover also LE devices, I
thought I should use Device.Connect to connect to the device.
Thanks,
Ting
^ permalink raw reply
* Re: [BLE] org.bluez.Device1.Connect() returns org.bluez.Error.NotAvailable
From: Johan Hedberg @ 2012-12-12 10:07 UTC (permalink / raw)
To: Ting Chou; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <ADCBF04BB97EBF4AAE65663F8478B61CA99E65ABDA@Luna.iaSolution.net>
Hi Ting,
On Wed, Dec 12, 2012, Ting Chou wrote:
> > That means that the profiles that are supposed to be supported with
> > this device are not calling either device_set_auto_connect() or
> > btd_device_add_attio_callback(). Both of those functions should cause
> > bluetoothd to start doing passive scanning and try to connect to the
> > device. Btw, which kernel version are you using. IIRC you'll need
> > something like 3.5 or newer for LE passive scanning to work.
> >
>
> I tried to let btd_device_add_attio_callback() get called by
>
> Characterisitc.DiscoverCharacteristics()
I thought you said some internally supported profiles get detected? Why
then do you need to use the ATT D-Bus interface? FWIW, since
attrib/client.c implementation doesn't match what's documented and since
there hasn't been anyone stepping up to update the code to use D-Bus
properties we'll probably not have the entire Characteristic D-Bus
interface in the 5.0 release. Instead, there's a plan to have a more
comprehensive and generic GATT D-Bus API for both peripheral and central
roles, which will probably land in 5.1 or one of the subsequent
releases.
> But still the Device1.Connect() after Device1.Disconnect() does not establish
> the connection. connect_profiles() returns btd_error_not_available() since
> !dev->pending:
It seems you've misunderstood this part. If the functions I mentioned
are used correctly you will not need to use Device.Connect at all.
Instead bluetoothd will start doing passive scanning and automatically
establish a connection to any device doing connectable advertising.
Johan
^ permalink raw reply
* RE: [BLE] org.bluez.Device1.Connect() returns org.bluez.Error.NotAvailable
From: Ting Chou @ 2012-12-12 9:47 UTC (permalink / raw)
To: Johan Hedberg; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <20121212092537.GA5371@x220>
Hello Johan,
> -----Original Message-----
> From: Johan Hedberg [mailto:johan.hedberg@gmail.com]
> Sent: Wednesday, December 12, 2012 5:26 PM
> To: Ting Chou
> Cc: linux-bluetooth@vger.kernel.org
> Subject: Re: [BLE] org.bluez.Device1.Connect() returns
> org.bluez.Error.NotAvailable
>
> Hi Ting,
>
> On Wed, Dec 12, 2012, Ting Chou wrote:
> > I tried Device.Pair, it does connect to the LE device like the first
> > call to Device.Connect, but:
> >
> > - I can't unpair the device (CancelPairing can't do this).
>
> There's no "unpair" method. You'd need to call Adapter.RemoveDevice to
> do it.
>
> > - If I Device.Disconnect after Device.Pair, then I can't connect to
> the device
> > again by either Device.Connect or Device.Pair:
> > - Device1.Connect
> > Error org.bluez.Error.NotAvailable: Operation currently not
> available
> > - Device1.Pair
> > Error org.bluez.Error.AlreadyExists: Already Exists
> >
> > I still can't connect to the LE device once I disconnect it.
>
> That means that the profiles that are supposed to be supported with
> this device are not calling either device_set_auto_connect() or
> btd_device_add_attio_callback(). Both of those functions should cause
> bluetoothd to start doing passive scanning and try to connect to the
> device. Btw, which kernel version are you using. IIRC you'll need
> something like 3.5 or newer for LE passive scanning to work.
>
I tried to let btd_device_add_attio_callback() get called by
Characterisitc.DiscoverCharacteristics()
But still the Device1.Connect() after Device1.Disconnect() does not establish
the connection. connect_profiles() returns btd_error_not_available() since
!dev->pending:
ting@user-OptiPlex-755:~/w/bluez$ sudo dbus-send --system --dest=org.bluez --type=method_call --print-reply /org/bluez/hci0/dev_00_07_80_4C_5F_17 org.bluez.Device1.Connect
Error org.bluez.Error.NotAvailable: Operation currently not available
ting@user-OptiPlex-755:~/w/bluez$ sudo dbus-send --system --dest=org.bluez --type=method_call --print-reply /org/bluez/hci0/dev_00_07_80_4C_5F_17/service000d org.bluez.Characteristic.DiscoverCharacteristics
method return sender=:1.1992 -> dest=:1.1997 reply_serial=2
array [
object path "/org/bluez/hci0/dev_00_07_80_4C_5F_17/service000d/characteristic000f"
]
ting@user-OptiPlex-755:~/w/bluez$ sudo dbus-send --system --dest=org.bluez --type=method_call --print-reply /org/bluez/hci0/dev_00_07_80_4C_5F_17 org.bluez.Device1.Disconnect
method return sender=:1.1992 -> dest=:1.1998 reply_serial=2
ting@user-OptiPlex-755:~/w/bluez$ sudo dbus-send --system --dest=org.bluez --type=method_call --print-reply /org/bluez/hci0/dev_00_07_80_4C_5F_17 org.bluez.Device1.Connect
Error org.bluez.Error.NotAvailable: Operation currently not available
The kernel I'm using:
ting@user-OptiPlex-755:~/w/bluez$ uname -a
Linux user-OptiPlex-755 3.6.6-030606-generic #201211050512 SMP Mon Nov 5 10:20:03 UTC 2012 i686 i686 i686 GNU/Linux
Thank you,
Ting
^ permalink raw reply
* Re: [BLE] org.bluez.Device1.Connect() returns org.bluez.Error.NotAvailable
From: Johan Hedberg @ 2012-12-12 9:25 UTC (permalink / raw)
To: Ting Chou; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <ADCBF04BB97EBF4AAE65663F8478B61CA99E65ABCC@Luna.iaSolution.net>
Hi Ting,
On Wed, Dec 12, 2012, Ting Chou wrote:
> I tried Device.Pair, it does connect to the LE device like the first call to
> Device.Connect, but:
>
> - I can't unpair the device (CancelPairing can't do this).
There's no "unpair" method. You'd need to call Adapter.RemoveDevice to
do it.
> - If I Device.Disconnect after Device.Pair, then I can't connect to the device
> again by either Device.Connect or Device.Pair:
> - Device1.Connect
> Error org.bluez.Error.NotAvailable: Operation currently not available
> - Device1.Pair
> Error org.bluez.Error.AlreadyExists: Already Exists
>
> I still can't connect to the LE device once I disconnect it.
That means that the profiles that are supposed to be supported with this
device are not calling either device_set_auto_connect() or
btd_device_add_attio_callback(). Both of those functions should cause
bluetoothd to start doing passive scanning and try to connect to the
device. Btw, which kernel version are you using. IIRC you'll need
something like 3.5 or newer for LE passive scanning to work.
Johan
^ permalink raw reply
* RE: [BLE] org.bluez.Device1.Connect() returns org.bluez.Error.NotAvailable
From: Ting Chou @ 2012-12-12 9:10 UTC (permalink / raw)
To: Johan Hedberg; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <20121212075201.GA14256@x220>
Hello Johan,
> -----Original Message-----
> From: Johan Hedberg [mailto:johan.hedberg@gmail.com]
> Sent: Wednesday, December 12, 2012 3:52 PM
> To: Ting Chou
> Cc: linux-bluetooth@vger.kernel.org
> Subject: Re: [BLE] org.bluez.Device1.Connect() returns
> org.bluez.Error.NotAvailable
>
> Hi Ting,
>
> On Wed, Dec 12, 2012, Ting Chou wrote:
> > I Found
> > -------
> >
> > - I checked /var/log/syslog and src/device.c, and found
> connect_profiles() is
> > called twice at the first time calling org.bluez.Device.Connect():
> >
> > - 1st time
> > dev->svc_resolved==FALSE, device_resolve_svc() is invoked.
> >
> > - 2nd time
> > dev->svc_resolved==TRUE
> > In the for loop of iterating device profiles, there're two
> profiles:
> >
> > a) p->auto_connect==FALSE, p->name==deviceinfo, p-
> >local_uuid==NULL
> > b) p->auto_connect==FALSE, p->name==Health Thermometer GATT
> > driver, p->local_uuid==NULL
> >
> > Since none of them have auto_connect TRUE, dev->pending==NULL,
> and
> > btd_error_not_available() is called.
> >
> > - I tried org.bluez.Device1.ConnectProfile() as well, but since all
> the profiles
> > have local_uuid NULL, find_connectable_profile() return NULL and
> > btd_error_invalid_args() is called.
>
> It's not actually local_uuid that is so important but that p->connect
> is set. Also, it'd make much more sense to pass the remote UUID to
> ConnectProfile than the local one and we'll still do this change before
> releasing 5.0. The main thing that needs to be done before that is to
> convert profile->remote_uuids list to a single profile->remote_uuid
> which is a bit of work since some profiles still declare multiple UUIDs.
>
> So far no LE profile is hooked up to Device.Connect and I'm not sure
> exactly how that should be done since LE device are connected through
> the general connection establishment procedure which requires scanning
> first. Since we already have Device.Pair doing the same as
> CreatePairedDevice in BlueZ 4 (and this should work btw, did you try
> it?) maybe Device.Connect should be roughly the same for LE devices as
> Adapter.CreateDevice is in BlueZ 4? For BR/EDR devices it already
> serves this purpose. The main question is what should be done if
> Device.Connect is called subsequent times as bluetoothd should anyway
> already be doing passive scanning and trying to connect to devices that
> have supported profiles.
>
> Johan
I tried Device.Pair, it does connect to the LE device like the first call to
Device.Connect, but:
- I can't unpair the device (CancelPairing can't do this).
- If I Device.Disconnect after Device.Pair, then I can't connect to the device
again by either Device.Connect or Device.Pair:
- Device1.Connect
Error org.bluez.Error.NotAvailable: Operation currently not available
- Device1.Pair
Error org.bluez.Error.AlreadyExists: Already Exists
I still can't connect to the LE device once I disconnect it.
Thanks,
Ting
^ 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