* Re: [BLE] org.bluez.Device1.Connect() returns org.bluez.Error.NotAvailable
From: Anderson Lizardo @ 2012-12-12 12:20 UTC (permalink / raw)
To: Ting Chou; +Cc: Johan Hedberg, linux-bluetooth@vger.kernel.org
In-Reply-To: <ADCBF04BB97EBF4AAE65663F8478B61CA99E65ABFC@Luna.iaSolution.net>
Hi Ting,
On Wed, Dec 12, 2012 at 7:30 AM, Ting Chou <Ting.Chou@iasolution.net> wrote:
> Hi Anderson,
>
>> -----Original Message-----
>> From: Anderson Lizardo [mailto:anderson.lizardo@openbossa.org]
>> Sent: Wednesday, December 12, 2012 6:53 PM
>> To: Ting Chou
>> Cc: Johan Hedberg; linux-bluetooth@vger.kernel.org
>> Subject: Re: [BLE] org.bluez.Device1.Connect() returns
>> org.bluez.Error.NotAvailable
>>
>> 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.
>>
>
> Does this mean the "User selects a device to connect" in Figure 9.6 (Page 1715,
> Flow chart for a device performing the general connection establishment
> procedure) is not needed for supported devices?
This image is incorrect, and is fixed on ESR06 (see correct image on
page 29 of that document). There is no user interaction for GCEP.
>> 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.
>>
>
> I'm not sure if I understand correctly. But do you mean the GCEP you mentioned
> above is applied while "reconnecting" to a supported device?
Yes, all GAP connection procedures are applicable for re-connection.
There is no "reconnection" procedure as per GAP (as far as I know).
But note that each GATT profile can specify reconnection procedures in
case of disconnection due to link loss (most of those that I read have
this). For instance, in HTP:
"5.2.4 Link Loss Reconnection Procedure
When a connection is terminated due to link loss, a Collector should attempt to
reconnect to the Thermometer using any of the GAP connection procedures with the
parameters in Table 5.2."
This is what BlueZ is doing for profiles implemented internally,
except that the parameters we use are not the ones recommended on the
profile specs (that could be implemented in future, but for now GCEP
uses fixed connection parameters).
Best Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
^ permalink raw reply
* [PATCH BlueZ] obex-client: Remove calls to org.bluez.Manager and org.bluez.Adapter
From: Luiz Augusto von Dentz @ 2012-12-12 12:16 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
With BlueZ 5 this API no longer exist or have changed.
---
obexd/client/bluetooth.c | 199 +----------------------------------------------
1 file changed, 2 insertions(+), 197 deletions(-)
diff --git a/obexd/client/bluetooth.c b/obexd/client/bluetooth.c
index 293eb8f..e453b68 100644
--- a/obexd/client/bluetooth.c
+++ b/obexd/client/bluetooth.c
@@ -41,11 +41,6 @@
#include "transport.h"
#include "bluetooth.h"
-#define BT_BUS_NAME "org.bluez"
-#define BT_PATH "/"
-#define BT_ADAPTER_IFACE "org.bluez.Adapter"
-#define BT_MANAGER_IFACE "org.bluez.Manager"
-
#define BT_RX_MTU 32767
#define BT_TX_MTU 32767
@@ -56,11 +51,8 @@ struct bluetooth_session {
bdaddr_t src;
bdaddr_t dst;
uint16_t port;
- DBusConnection *conn; /* system bus connection */
sdp_session_t *sdp;
GIOChannel *io;
- GSList *pending_calls;
- char *adapter;
char *service;
obc_transport_func func;
void *user_data;
@@ -73,66 +65,8 @@ static GQuark obc_bt_error_quark(void)
return g_quark_from_static_string("obc-bluetooth-error-quark");
}
-static int send_method_call(struct bluetooth_session *session,
- const char *path,
- const char *interface,
- const char *method,
- DBusPendingCallNotifyFunction cb,
- int type, ...)
-{
- DBusMessage *msg;
- DBusPendingCall *call;
- va_list args;
-
- msg = dbus_message_new_method_call(BT_BUS_NAME, path, interface,
- method);
- if (!msg) {
- error("Unable to allocate new D-Bus %s message", method);
- return -ENOMEM;
- }
-
- va_start(args, type);
-
- if (!dbus_message_append_args_valist(msg, type, args)) {
- dbus_message_unref(msg);
- va_end(args);
- return -EINVAL;
- }
-
- va_end(args);
-
- if (!cb) {
- g_dbus_send_message(session->conn, msg);
- return 0;
- }
-
- if (!dbus_connection_send_with_reply(session->conn, msg, &call, -1)) {
- error("Sending %s failed", method);
- dbus_message_unref(msg);
- return -EIO;
- }
-
- dbus_pending_call_set_notify(call, cb, session, NULL);
-
- session->pending_calls = g_slist_prepend(session->pending_calls, call);
-
- dbus_message_unref(msg);
-
- return 0;
-}
-
-static void finalize_call(DBusPendingCall *call)
-{
- if (!dbus_pending_call_get_completed(call))
- dbus_pending_call_cancel(call);
-
- dbus_pending_call_unref(call);
-}
-
static void session_destroy(struct bluetooth_session *session)
{
- GSList *l;
-
DBG("%p", session);
if (g_slist_find(sessions, session) == NULL)
@@ -140,21 +74,6 @@ static void session_destroy(struct bluetooth_session *session)
sessions = g_slist_remove(sessions, session);
- if (session->adapter)
- send_method_call(session, session->adapter, BT_ADAPTER_IFACE,
- "ReleaseSession", NULL,
- DBUS_TYPE_INVALID);
-
- l = session->pending_calls;
-
- while (l) {
- DBusPendingCall *call = l->data;
- l = l->next;
-
- session->pending_calls = g_slist_remove(session->pending_calls, call);
- finalize_call(call);
- }
-
if (session->io != NULL) {
g_io_channel_shutdown(session->io, TRUE, NULL);
g_io_channel_unref(session->io);
@@ -163,11 +82,7 @@ static void session_destroy(struct bluetooth_session *session)
if (session->sdp)
sdp_close(session->sdp);
- if (session->conn)
- dbus_connection_unref(session->conn);
-
g_free(session->service);
- g_free(session->adapter);
g_free(session);
}
@@ -458,111 +373,6 @@ static int session_connect(struct bluetooth_session *session)
return err;
}
-static void adapter_reply(DBusPendingCall *call, void *user_data)
-{
- struct bluetooth_session *session = user_data;
- DBusError err;
- DBusMessage *reply;
- GError *gerr = NULL;
-
- reply = dbus_pending_call_steal_reply(call);
-
- session->pending_calls = g_slist_remove(session->pending_calls, call);
- finalize_call(call);
-
- dbus_error_init(&err);
- if (dbus_set_error_from_message(&err, reply)) {
- error("manager replied with an error: %s, %s",
- err.name, err.message);
- dbus_error_free(&err);
-
- goto failed;
- }
-
- if (session_connect(session) == 0)
- goto proceed;
-
-failed:
- g_set_error(&gerr, OBC_BT_ERROR, -EINVAL,
- "Unable to request session");
- if (session->func)
- session->func(session->io, gerr, session->user_data);
- g_clear_error(&gerr);
-
- session_destroy(session);
-
-proceed:
- dbus_message_unref(reply);
-}
-
-static int request_session(struct bluetooth_session *session, const char *adapter)
-{
- session->adapter = g_strdup(adapter);
- return send_method_call(session, adapter, BT_ADAPTER_IFACE,
- "RequestSession", adapter_reply,
- DBUS_TYPE_INVALID);
-}
-
-static void manager_reply(DBusPendingCall *call, void *user_data)
-{
- struct bluetooth_session *session = user_data;
- DBusError err;
- DBusMessage *reply;
- char *adapter;
- GError *gerr = NULL;
-
- reply = dbus_pending_call_steal_reply(call);
-
- session->pending_calls = g_slist_remove(session->pending_calls, call);
- finalize_call(call);
-
- dbus_error_init(&err);
- if (dbus_set_error_from_message(&err, reply)) {
- error("manager replied with an error: %s, %s",
- err.name, err.message);
- dbus_error_free(&err);
-
- goto failed;
- }
-
- if (!dbus_message_get_args(reply, NULL,
- DBUS_TYPE_OBJECT_PATH, &adapter,
- DBUS_TYPE_INVALID))
- goto failed;
-
- DBG("adapter path %s", adapter);
-
- if (request_session(session, adapter) == 0)
- goto proceed;
-
-failed:
- g_set_error(&gerr, OBC_BT_ERROR, -EINVAL, "No adapter found");
- if (session->func)
- session->func(session->io, gerr, session->user_data);
- g_clear_error(&gerr);
-
- session_destroy(session);
-
-proceed:
- dbus_message_unref(reply);
-}
-
-static int find_adapter(struct bluetooth_session *session, const char *source)
-{
- if (source == NULL) {
- bacpy(&session->src, BDADDR_ANY);
- return send_method_call(session, BT_PATH, BT_MANAGER_IFACE,
- "DefaultAdapter", manager_reply,
- DBUS_TYPE_INVALID);
- }
-
- str2ba(source, &session->src);
- return send_method_call(session, BT_PATH, BT_MANAGER_IFACE,
- "FindAdapter", manager_reply,
- DBUS_TYPE_STRING, &source,
- DBUS_TYPE_INVALID);
-}
-
static guint bluetooth_connect(const char *source, const char *destination,
const char *service, uint16_t port,
obc_transport_func func, void *user_data)
@@ -584,16 +394,11 @@ static guint bluetooth_connect(const char *source, const char *destination,
session->port = port;
session->user_data = user_data;
- session->conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, NULL);
- if (session->conn == NULL) {
- g_free(session);
- return 0;
- }
-
session->service = g_strdup(service);
str2ba(destination, &session->dst);
+ str2ba(source, &session->src);
- if (find_adapter(session, source) < 0) {
+ if (session_connect(session) < 0) {
g_free(session);
return 0;
}
--
1.7.11.7
^ permalink raw reply related
* Re: [PATCH BlueZ 01/11] obexd: Port bluetooth plugin to use external profile support
From: Johan Hedberg @ 2012-12-12 12:02 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <1355313136-7891-1-git-send-email-luiz.dentz@gmail.com>
Hi Luiz,
On Wed, Dec 12, 2012, Luiz Augusto von Dentz wrote:
> This changes obexd to use ProfileManager.RegisterProfile
> ---
> obexd/plugins/bluetooth.c | 696 ++++++++++++++--------------------------------
> 1 file changed, 212 insertions(+), 484 deletions(-)
All patches in this set have been applied. I also removed the service
plugin in the same go as now all known users of it are gone.
Johan
^ permalink raw reply
* [PATCH BlueZ 11/11] irmc: Remove record details
From: Luiz Augusto von Dentz @ 2012-12-12 11:52 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355313136-7891-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Standart service records are already supported by bluetoothd
---
obexd/plugins/irmc.c | 49 -------------------------------------------------
1 file changed, 49 deletions(-)
diff --git a/obexd/plugins/irmc.c b/obexd/plugins/irmc.c
index c9c3521..d343977 100644
--- a/obexd/plugins/irmc.c
+++ b/obexd/plugins/irmc.c
@@ -46,52 +46,6 @@
#include "filesystem.h"
#include "manager.h"
-#define IRMC_CHANNEL 14
-
-#define IRMC_RECORD "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \
-<record> \
- <attribute id=\"0x0001\"> \
- <sequence> \
- <uuid value=\"0x1104\"/> \
- </sequence> \
- </attribute> \
- \
- <attribute id=\"0x0004\"> \
- <sequence> \
- <sequence> \
- <uuid value=\"0x0100\"/> \
- </sequence> \
- <sequence> \
- <uuid value=\"0x0003\"/> \
- <uint8 value=\"%u\" name=\"channel\"/> \
- </sequence> \
- <sequence> \
- <uuid value=\"0x0008\"/> \
- </sequence> \
- </sequence> \
- </attribute> \
- \
- <attribute id=\"0x0009\"> \
- <sequence> \
- <sequence> \
- <uuid value=\"0x1104\"/> \
- <uint16 value=\"0x0100\" name=\"version\"/> \
- </sequence> \
- </sequence> \
- </attribute> \
- \
- <attribute id=\"0x0100\"> \
- <text value=\"%s\" name=\"name\"/> \
- </attribute> \
- \
- <attribute id=\"0x0301\"> \
- <sequence> \
- <uint8 value=\"0x01\"/> \
- </sequence> \
- </attribute> \
-</record>"
-
-
struct aparam_header {
uint8_t tag;
uint8_t len;
@@ -488,9 +442,6 @@ static struct obex_mime_type_driver irmc_driver = {
static struct obex_service_driver irmc = {
.name = "IRMC Sync server",
.service = OBEX_IRMC,
- .channel = IRMC_CHANNEL,
- .secure = TRUE,
- .record = IRMC_RECORD,
.target = IRMC_TARGET,
.target_size = IRMC_TARGET_SIZE,
.connect = irmc_connect,
--
1.7.11.7
^ permalink raw reply related
* [PATCH BlueZ 10/11] mas: Remove record details
From: Luiz Augusto von Dentz @ 2012-12-12 11:52 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355313136-7891-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Standart service records are already supported by bluetoothd
---
obexd/plugins/mas.c | 51 ---------------------------------------------------
1 file changed, 51 deletions(-)
diff --git a/obexd/plugins/mas.c b/obexd/plugins/mas.c
index 1b18059..3270edd 100644
--- a/obexd/plugins/mas.c
+++ b/obexd/plugins/mas.c
@@ -49,54 +49,6 @@
#define READ_STATUS_REQ 0
#define DELETE_STATUS_REQ 1
-/* Channel number according to bluez doc/assigned-numbers.txt */
-#define MAS_CHANNEL 16
-
-#define MAS_RECORD "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \
-<record> \
- <attribute id=\"0x0001\"> \
- <sequence> \
- <uuid value=\"0x1132\"/> \
- </sequence> \
- </attribute> \
- \
- <attribute id=\"0x0004\"> \
- <sequence> \
- <sequence> \
- <uuid value=\"0x0100\"/> \
- </sequence> \
- <sequence> \
- <uuid value=\"0x0003\"/> \
- <uint8 value=\"%u\" name=\"channel\"/> \
- </sequence> \
- <sequence> \
- <uuid value=\"0x0008\"/> \
- </sequence> \
- </sequence> \
- </attribute> \
- \
- <attribute id=\"0x0009\"> \
- <sequence> \
- <sequence> \
- <uuid value=\"0x1134\"/> \
- <uint16 value=\"0x0100\" name=\"version\"/> \
- </sequence> \
- </sequence> \
- </attribute> \
- \
- <attribute id=\"0x0100\"> \
- <text value=\"%s\" name=\"name\"/> \
- </attribute> \
- \
- <attribute id=\"0x0315\"> \
- <uint8 value=\"0x00\"/> \
- </attribute> \
- \
- <attribute id=\"0x0316\"> \
- <uint8 value=\"0x0F\"/> \
- </attribute> \
-</record>"
-
#define XML_DECL "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
/* Building blocks for x-obex/folder-listing */
@@ -764,9 +716,6 @@ static int any_close(void *obj)
static struct obex_service_driver mas = {
.name = "Message Access server",
.service = OBEX_MAS,
- .channel = MAS_CHANNEL,
- .secure = TRUE,
- .record = MAS_RECORD,
.target = MAS_TARGET,
.target_size = TARGET_SIZE,
.connect = mas_connect,
--
1.7.11.7
^ permalink raw reply related
* [PATCH BlueZ 09/11] pbap: Remove record details
From: Luiz Augusto von Dentz @ 2012-12-12 11:52 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355313136-7891-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Standart service records are already supported by bluetoothd
---
obexd/plugins/pbap.c | 46 ----------------------------------------------
1 file changed, 46 deletions(-)
diff --git a/obexd/plugins/pbap.c b/obexd/plugins/pbap.c
index 4d4f0b8..4740188 100644
--- a/obexd/plugins/pbap.c
+++ b/obexd/plugins/pbap.c
@@ -65,49 +65,6 @@
#define PHONEBOOKSIZE_TAG 0X08
#define NEWMISSEDCALLS_TAG 0X09
-#define PBAP_CHANNEL 15
-
-#define PBAP_RECORD "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \
-<record> \
- <attribute id=\"0x0001\"> \
- <sequence> \
- <uuid value=\"0x112f\"/> \
- </sequence> \
- </attribute> \
- \
- <attribute id=\"0x0004\"> \
- <sequence> \
- <sequence> \
- <uuid value=\"0x0100\"/> \
- </sequence> \
- <sequence> \
- <uuid value=\"0x0003\"/> \
- <uint8 value=\"%u\" name=\"channel\"/> \
- </sequence> \
- <sequence> \
- <uuid value=\"0x0008\"/> \
- </sequence> \
- </sequence> \
- </attribute> \
- \
- <attribute id=\"0x0009\"> \
- <sequence> \
- <sequence> \
- <uuid value=\"0x1130\"/> \
- <uint16 value=\"0x0100\" name=\"version\"/> \
- </sequence> \
- </sequence> \
- </attribute> \
- \
- <attribute id=\"0x0100\"> \
- <text value=\"%s\" name=\"name\"/> \
- </attribute> \
- \
- <attribute id=\"0x0314\"> \
- <uint8 value=\"0x01\"/> \
- </attribute> \
-</record>"
-
struct cache {
gboolean valid;
uint32_t index;
@@ -664,9 +621,6 @@ static int pbap_chkput(struct obex_session *os, void *user_data)
static struct obex_service_driver pbap = {
.name = "Phonebook Access server",
.service = OBEX_PBAP,
- .channel = PBAP_CHANNEL,
- .secure = TRUE,
- .record = PBAP_RECORD,
.target = PBAP_TARGET,
.target_size = TARGET_SIZE,
.connect = pbap_connect,
--
1.7.11.7
^ permalink raw reply related
* [PATCH BlueZ 08/11] ftp: Remove record details
From: Luiz Augusto von Dentz @ 2012-12-12 11:52 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355313136-7891-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Standart service records are already supported by bluetoothd
---
obexd/plugins/ftp.c | 45 ---------------------------------------------
1 file changed, 45 deletions(-)
diff --git a/obexd/plugins/ftp.c b/obexd/plugins/ftp.c
index ff4b761..d53774d 100644
--- a/obexd/plugins/ftp.c
+++ b/obexd/plugins/ftp.c
@@ -53,47 +53,6 @@
#define LST_TYPE "x-obex/folder-listing"
#define CAP_TYPE "x-obex/capability"
-#define FTP_CHANNEL 10
-#define FTP_RECORD "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \
-<record> \
- <attribute id=\"0x0001\"> \
- <sequence> \
- <uuid value=\"0x1106\"/> \
- </sequence> \
- </attribute> \
- \
- <attribute id=\"0x0004\"> \
- <sequence> \
- <sequence> \
- <uuid value=\"0x0100\"/> \
- </sequence> \
- <sequence> \
- <uuid value=\"0x0003\"/> \
- <uint8 value=\"%u\" name=\"channel\"/> \
- </sequence> \
- <sequence> \
- <uuid value=\"0x0008\"/> \
- </sequence> \
- </sequence> \
- </attribute> \
- \
- <attribute id=\"0x0009\"> \
- <sequence> \
- <sequence> \
- <uuid value=\"0x1106\"/> \
- <uint16 value=\"0x0102\" name=\"version\"/> \
- </sequence> \
- </sequence> \
- </attribute> \
- \
- <attribute id=\"0x0100\"> \
- <text value=\"%s\" name=\"name\"/> \
- </attribute> \
- <attribute id=\"0x0200\"> \
- <uint16 value=\"%u\" name=\"psm\"/> \
- </attribute> \
-</record>"
-
static const uint8_t FTP_TARGET[TARGET_SIZE] = {
0xF9, 0xEC, 0x7B, 0xC4, 0x95, 0x3C, 0x11, 0xD2,
0x98, 0x4E, 0x52, 0x54, 0x00, 0xDC, 0x9E, 0x09 };
@@ -519,10 +478,6 @@ void ftp_disconnect(struct obex_session *os, void *user_data)
static struct obex_service_driver ftp = {
.name = "File Transfer server",
.service = OBEX_FTP,
- .channel = FTP_CHANNEL,
- .port = OBEX_PORT_RANDOM,
- .secure = TRUE,
- .record = FTP_RECORD,
.target = FTP_TARGET,
.target_size = TARGET_SIZE,
.connect = ftp_connect,
--
1.7.11.7
^ permalink raw reply related
* [PATCH BlueZ 07/11] opp: Remove record details
From: Luiz Augusto von Dentz @ 2012-12-12 11:52 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355313136-7891-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Standart service records are already supported by bluetoothd
---
obexd/plugins/opp.c | 56 -----------------------------------------------------
1 file changed, 56 deletions(-)
diff --git a/obexd/plugins/opp.c b/obexd/plugins/opp.c
index c7ddc63..faa4437 100644
--- a/obexd/plugins/opp.c
+++ b/obexd/plugins/opp.c
@@ -44,59 +44,6 @@
#define VCARD_TYPE "text/x-vcard"
#define VCARD_FILE CONFIGDIR "/vcard.vcf"
-#define OPP_CHANNEL 9
-#define OPP_RECORD "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \
-<record> \
- <attribute id=\"0x0001\"> \
- <sequence> \
- <uuid value=\"0x1105\"/> \
- </sequence> \
- </attribute> \
- \
- <attribute id=\"0x0004\"> \
- <sequence> \
- <sequence> \
- <uuid value=\"0x0100\"/> \
- </sequence> \
- <sequence> \
- <uuid value=\"0x0003\"/> \
- <uint8 value=\"%u\" name=\"channel\"/> \
- </sequence> \
- <sequence> \
- <uuid value=\"0x0008\"/> \
- </sequence> \
- </sequence> \
- </attribute> \
- \
- <attribute id=\"0x0009\"> \
- <sequence> \
- <sequence> \
- <uuid value=\"0x1105\"/> \
- <uint16 value=\"0x0102\" name=\"version\"/> \
- </sequence> \
- </sequence> \
- </attribute> \
- \
- <attribute id=\"0x0100\"> \
- <text value=\"%s\" name=\"name\"/> \
- </attribute> \
- \
- <attribute id=\"0x0303\"> \
- <sequence> \
- <uint8 value=\"0x01\"/> \
- <uint8 value=\"0x02\"/> \
- <uint8 value=\"0x03\"/> \
- <uint8 value=\"0x04\"/> \
- <uint8 value=\"0x05\"/> \
- <uint8 value=\"0x06\"/> \
- <uint8 value=\"0xff\"/> \
- </sequence> \
- </attribute> \
- <attribute id=\"0x0200\"> \
- <uint16 value=\"%u\" name=\"psm\"/> \
- </attribute> \
-</record>"
-
static void *opp_connect(struct obex_session *os, int *err)
{
manager_register_transfer(os);
@@ -219,9 +166,6 @@ static void opp_reset(struct obex_session *os, void *user_data)
static struct obex_service_driver driver = {
.name = "Object Push server",
.service = OBEX_OPP,
- .channel = OPP_CHANNEL,
- .port = OBEX_PORT_RANDOM,
- .record = OPP_RECORD,
.connect = opp_connect,
.progress = opp_progress,
.disconnect = opp_disconnect,
--
1.7.11.7
^ permalink raw reply related
* [PATCH BlueZ 06/11] obexd: Add support for custom records
From: Luiz Augusto von Dentz @ 2012-12-12 11:52 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355313136-7891-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Services such as pcsuite and syncml use custom records not defined by
Bluetooth SIG so they have to be registered using ServiceRecord entry.
---
obexd/plugins/bluetooth.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/obexd/plugins/bluetooth.c b/obexd/plugins/bluetooth.c
index 8a9e190..cbc42f3 100644
--- a/obexd/plugins/bluetooth.c
+++ b/obexd/plugins/bluetooth.c
@@ -253,6 +253,7 @@ static int register_profile(struct bluetooth_profile *profile)
DBusMessageIter iter, opt;
DBusPendingCall *call;
dbus_bool_t auto_connect = FALSE;
+ char *xml;
int ret = 0;
profile->path = g_strconcat("/org/bluez/obex/", profile->uuid, NULL);
@@ -286,6 +287,20 @@ static int register_profile(struct bluetooth_profile *profile)
&opt);
dict_append_entry(&opt, "AutoConnect", DBUS_TYPE_BOOLEAN,
&auto_connect);
+ if (profile->driver->record) {
+ if (profile->driver->port != 0)
+ xml = g_markup_printf_escaped(profile->driver->record,
+ profile->driver->channel,
+ profile->driver->name,
+ profile->driver->port);
+ else
+ xml = g_markup_printf_escaped(profile->driver->record,
+ profile->driver->channel,
+ profile->driver->name);
+ dict_append_entry(&opt, "ServiceRecord", DBUS_TYPE_STRING,
+ &xml);
+ g_free(xml);
+ }
dbus_message_iter_close_container(&iter, &opt);
if (!dbus_connection_send_with_reply(connection, msg, &call, -1)) {
@@ -314,6 +329,10 @@ static const char *service2uuid(uint16_t service)
return OBEX_PSE_UUID;
case OBEX_IRMC:
return OBEX_SYNC_UUID;
+ case OBEX_PCSUITE:
+ return "00005005-0000-1000-8000-0002ee000001";
+ case OBEX_SYNCEVOLUTION:
+ return "00000002-0000-1000-8000-0002ee000002";
case OBEX_MAS:
return OBEX_MAS_UUID;
}
--
1.7.11.7
^ permalink raw reply related
* [PATCH BlueZ 05/11] obexd: Enable support SYNC profile
From: Luiz Augusto von Dentz @ 2012-12-12 11:52 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355313136-7891-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
obexd/plugins/bluetooth.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/obexd/plugins/bluetooth.c b/obexd/plugins/bluetooth.c
index 65bcad1..8a9e190 100644
--- a/obexd/plugins/bluetooth.c
+++ b/obexd/plugins/bluetooth.c
@@ -312,6 +312,8 @@ static const char *service2uuid(uint16_t service)
return OBEX_FTP_UUID;
case OBEX_PBAP:
return OBEX_PSE_UUID;
+ case OBEX_IRMC:
+ return OBEX_SYNC_UUID;
case OBEX_MAS:
return OBEX_MAS_UUID;
}
--
1.7.11.7
^ permalink raw reply related
* [PATCH BlueZ 04/11] obexd: Enable support for MAS profile
From: Luiz Augusto von Dentz @ 2012-12-12 11:52 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355313136-7891-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
obexd/plugins/bluetooth.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/obexd/plugins/bluetooth.c b/obexd/plugins/bluetooth.c
index fc88a1e..65bcad1 100644
--- a/obexd/plugins/bluetooth.c
+++ b/obexd/plugins/bluetooth.c
@@ -312,6 +312,8 @@ static const char *service2uuid(uint16_t service)
return OBEX_FTP_UUID;
case OBEX_PBAP:
return OBEX_PSE_UUID;
+ case OBEX_MAS:
+ return OBEX_MAS_UUID;
}
return NULL;
--
1.7.11.7
^ permalink raw reply related
* [PATCH BlueZ 03/11] core: Add SYNC record
From: Luiz Augusto von Dentz @ 2012-12-12 11:52 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355313136-7891-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This adds SYNC record to detault settings
---
src/profile.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/src/profile.c b/src/profile.c
index a3dd372..53d32b6 100644
--- a/src/profile.c
+++ b/src/profile.c
@@ -436,6 +436,46 @@
</attribute> \
</record>"
+#define SYNC_RECORD \
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \
+ <record> \
+ <attribute id=\"0x0001\"> \
+ <sequence> \
+ <uuid value=\"0x1104\"/> \
+ </sequence> \
+ </attribute> \
+ <attribute id=\"0x0004\"> \
+ <sequence> \
+ <sequence> \
+ <uuid value=\"0x0100\"/> \
+ </sequence> \
+ <sequence> \
+ <uuid value=\"0x0003\"/> \
+ <uint8 value=\"0x%02x\"/> \
+ </sequence> \
+ <sequence> \
+ <uuid value=\"0x0008\"/> \
+ </sequence> \
+ </sequence> \
+ </attribute> \
+ <attribute id=\"0x0009\"> \
+ <sequence> \
+ <sequence> \
+ <uuid value=\"0x1104\"/> \
+ <uint16 value=\"0x%04x\" /> \
+ </sequence> \
+ </sequence> \
+ </attribute> \
+ <attribute id=\"0x0100\"> \
+ <text value=\"%s\"/> \
+ </attribute> \
+ <attribute id=\"0x0301\"> \
+ <sequence> \
+ <uint8 value=\"0x01\"/> \
+ </sequence> \
+ </attribute> \
+ </record>"
+
#define GENERIC_RECORD \
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \
<record> \
@@ -1618,6 +1658,13 @@ static char *get_mas_record(struct ext_profile *ext, struct ext_io *l2cap,
ext->name);
}
+static char *get_sync_record(struct ext_profile *ext, struct ext_io *l2cap,
+ struct ext_io *rfcomm)
+{
+ return g_strdup_printf(SYNC_RECORD, rfcomm->chan, ext->version,
+ ext->name);
+}
+
static char *get_opp_record(struct ext_profile *ext, struct ext_io *l2cap,
struct ext_io *rfcomm)
{
@@ -1777,6 +1824,8 @@ static struct default_settings {
.uuid = OBEX_SYNC_UUID,
.name = "Synchronization",
.channel = SYNC_DEFAULT_CHANNEL,
+ .get_record = get_sync_record,
+ .version = 0x0100,
}, {
.uuid = OBEX_PSE_UUID,
.name = "Phone Book Access",
--
1.7.11.7
^ permalink raw reply related
* [PATCH BlueZ 02/11] core: Add MAS record
From: Luiz Augusto von Dentz @ 2012-12-12 11:52 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1355313136-7891-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This adds MAS record to detault settings
---
src/profile.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/src/profile.c b/src/profile.c
index fba894c..a3dd372 100644
--- a/src/profile.c
+++ b/src/profile.c
@@ -395,6 +395,47 @@
</attribute> \
</record>"
+#define MAS_RECORD \
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \
+ <record> \
+ <attribute id=\"0x0001\"> \
+ <sequence> \
+ <uuid value=\"0x1132\"/> \
+ </sequence> \
+ </attribute> \
+ <attribute id=\"0x0004\"> \
+ <sequence> \
+ <sequence> \
+ <uuid value=\"0x0100\"/> \
+ </sequence> \
+ <sequence> \
+ <uuid value=\"0x0003\"/> \
+ <uint8 value=\"0x%02x\"/> \
+ </sequence> \
+ <sequence> \
+ <uuid value=\"0x0008\"/> \
+ </sequence> \
+ </sequence> \
+ </attribute> \
+ <attribute id=\"0x0009\"> \
+ <sequence> \
+ <sequence> \
+ <uuid value=\"0x1134\"/> \
+ <uint16 value=\"0x%04x\" /> \
+ </sequence> \
+ </sequence> \
+ </attribute> \
+ <attribute id=\"0x0100\"> \
+ <text value=\"%s\"/> \
+ </attribute> \
+ <attribute id=\"0x0315\"> \
+ <uint8 value=\"0x00\"/> \
+ </attribute> \
+ <attribute id=\"0x0316\"> \
+ <uint8 value=\"0x0F\"/> \
+ </attribute> \
+ </record>"
+
#define GENERIC_RECORD \
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \
<record> \
@@ -1570,6 +1611,13 @@ static char *get_pse_record(struct ext_profile *ext, struct ext_io *l2cap,
ext->name);
}
+static char *get_mas_record(struct ext_profile *ext, struct ext_io *l2cap,
+ struct ext_io *rfcomm)
+{
+ return g_strdup_printf(MAS_RECORD, rfcomm->chan, ext->version,
+ ext->name);
+}
+
static char *get_opp_record(struct ext_profile *ext, struct ext_io *l2cap,
struct ext_io *rfcomm)
{
@@ -1745,6 +1793,8 @@ static struct default_settings {
.uuid = OBEX_MAS_UUID,
.name = "Message Access",
.channel = MAS_DEFAULT_CHANNEL,
+ .get_record = get_mas_record,
+ .version = 0x0100
}, {
.uuid = OBEX_MNS_UUID,
.name = "Message Notification",
--
1.7.11.7
^ permalink raw reply related
* [PATCH BlueZ 01/11] obexd: Port bluetooth plugin to use external profile support
From: Luiz Augusto von Dentz @ 2012-12-12 11:52 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This changes obexd to use ProfileManager.RegisterProfile
---
obexd/plugins/bluetooth.c | 696 ++++++++++++++--------------------------------
1 file changed, 212 insertions(+), 484 deletions(-)
diff --git a/obexd/plugins/bluetooth.c b/obexd/plugins/bluetooth.c
index 1448d0e..fc88a1e 100644
--- a/obexd/plugins/bluetooth.c
+++ b/obexd/plugins/bluetooth.c
@@ -43,270 +43,33 @@
#include "transport.h"
#include "service.h"
#include "log.h"
+#include "uuid.h"
#define BT_RX_MTU 32767
#define BT_TX_MTU 32767
-#define TIMEOUT 60*1000 /* Timeout for user response (miliseconds) */
-
-struct pending_request {
- DBusPendingCall *call;
- struct bluetooth_service *service;
- char *adapter_path;
- char address[18];
- unsigned int watch;
- GIOChannel *io;
-};
-
-struct bluetooth_service {
+struct bluetooth_profile {
struct obex_server *server;
struct obex_service_driver *driver;
- uint32_t handle;
+ char *uuid;
+ char *path;
};
-struct adapter_any {
- char *path; /* Adapter ANY path */
- GSList *services; /* List of services to register records */
-};
+static GSList *profiles = NULL;
static DBusConnection *connection = NULL;
-static struct adapter_any *any = NULL;
-
-static void add_record_reply(DBusPendingCall *call, void *user_data)
-{
- struct bluetooth_service *service = user_data;
- DBusMessage *reply = dbus_pending_call_steal_reply(call);
- DBusError derr;
- uint32_t handle;
-
- dbus_error_init(&derr);
- if (dbus_set_error_from_message(&derr, reply)) {
- error("bluetooth: Replied with an error: %s, %s",
- derr.name, derr.message);
- dbus_error_free(&derr);
- handle = 0;
- } else {
- dbus_message_get_args(reply, NULL,
- DBUS_TYPE_UINT32, &handle,
- DBUS_TYPE_INVALID);
-
- service->handle = handle;
-
- DBG("Registered: %s, handle: 0x%x",
- service->driver->name, service->handle);
- }
-
- dbus_message_unref(reply);
-}
-
-static int add_record(const char *path, const char *xml,
- struct bluetooth_service *service)
-{
- DBusMessage *msg;
- DBusPendingCall *call;
- int ret = 0;
-
- msg = dbus_message_new_method_call("org.bluez", path,
- "org.bluez.Service", "AddRecord");
-
- dbus_message_append_args(msg, DBUS_TYPE_STRING, &xml,
- DBUS_TYPE_INVALID);
-
- if (dbus_connection_send_with_reply(connection,
- msg, &call, -1) == FALSE) {
- ret = -1;
- goto failed;
- }
-
- dbus_pending_call_set_notify(call, add_record_reply, service, NULL);
- dbus_pending_call_unref(call);
-
-failed:
- dbus_message_unref(msg);
- return ret;
-}
-
-static struct bluetooth_service *find_service(
- struct obex_service_driver *driver)
-{
- GSList *l;
-
- for (l = any->services; l; l = l->next) {
- struct bluetooth_service *service = l->data;
-
- if (service->driver == driver)
- return service;
- }
-
- return NULL;
-}
-
-static void register_record(struct obex_server *server)
-{
- const GSList *l;
-
- if (connection == NULL)
- return;
-
- for (l = server->drivers; l; l = l->next) {
- struct obex_service_driver *driver = l->data;
- struct bluetooth_service *service;
- char *xml;
-
- service = find_service(driver);
- if (service == NULL) {
- service = g_new0(struct bluetooth_service, 1);
- service->driver = driver;
- service->server = server;
- any->services = g_slist_append(any->services, service);
- }
-
- /* Service already has a record registered */
- if (service->handle != 0)
- continue;
-
- /* Adapter ANY is not available yet: Add record later */
- if (any->path == NULL)
- continue;
-
- if (driver->port != 0)
- xml = g_markup_printf_escaped(driver->record,
- driver->channel,
- driver->name,
- driver->port);
- else
- xml = g_markup_printf_escaped(driver->record,
- driver->channel,
- driver->name);
-
- add_record(any->path, xml, service);
- g_free(xml);
- }
-}
-
-static void find_adapter_any_reply(DBusPendingCall *call, void *user_data)
-{
- DBusMessage *reply = dbus_pending_call_steal_reply(call);
- const char *path;
- GSList *l;
- DBusError derr;
-
- dbus_error_init(&derr);
- if (dbus_set_error_from_message(&derr, reply)) {
- error("bluetooth: Replied with an error: %s, %s",
- derr.name, derr.message);
- dbus_error_free(&derr);
- goto done;
- }
-
- dbus_message_get_args(reply, NULL,
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID);
- any->path = g_strdup(path);
-
- for (l = any->services; l; l = l->next) {
- struct bluetooth_service *service = l->data;
- struct obex_service_driver *driver = service->driver;
- char *xml;
-
- if (driver->port != 0)
- xml = g_markup_printf_escaped(driver->record,
- driver->channel,
- driver->name,
- driver->port);
- else
- xml = g_markup_printf_escaped(driver->record,
- driver->channel,
- driver->name);
-
- add_record(any->path, xml, service);
- g_free(xml);
- }
-
-done:
- dbus_message_unref(reply);
-}
-
-static DBusPendingCall *find_adapter(const char *pattern,
- DBusPendingCallNotifyFunction function,
- void *user_data)
-{
- DBusMessage *msg;
- DBusPendingCall *call;
-
- DBG("FindAdapter(%s)", pattern);
-
- msg = dbus_message_new_method_call("org.bluez", "/",
- "org.bluez.Manager", "FindAdapter");
- if (!msg)
- return NULL;
-
- dbus_message_append_args(msg, DBUS_TYPE_STRING, &pattern,
- DBUS_TYPE_INVALID);
-
- if (!dbus_connection_send_with_reply(connection, msg, &call, -1)) {
- dbus_message_unref(msg);
- return NULL;
- }
-
- dbus_pending_call_set_notify(call, function, user_data, NULL);
-
- dbus_message_unref(msg);
-
- return call;
-}
-
-static void name_acquired(DBusConnection *conn, void *user_data)
-{
- DBusPendingCall *call;
-
- call = find_adapter("any", find_adapter_any_reply, NULL);
- if (call)
- dbus_pending_call_unref(call);
-}
-
-static void name_released(DBusConnection *conn, void *user_data)
-{
- GSList *l;
-
- /* reset handles so the services got register next time */
- for (l = any->services; l; l = l->next) {
- struct bluetooth_service *service = l->data;
-
- service->handle = 0;
- }
-
- g_free(any->path);
- any->path = NULL;
-
-}
-
-static void service_cancel(struct pending_request *pending)
-{
- DBusMessage *msg;
-
- msg = dbus_message_new_method_call("org.bluez",
- pending->adapter_path,
- "org.bluez.Service",
- "CancelAuthorization");
-
- g_dbus_send_message(connection, msg);
-}
-static void pending_request_free(struct pending_request *pending)
+static DBusMessage *profile_release(DBusConnection *conn, DBusMessage *msg,
+ void *data)
{
- if (pending->call)
- dbus_pending_call_unref(pending->call);
- g_io_channel_unref(pending->io);
- g_free(pending->adapter_path);
- g_free(pending);
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
static void connect_event(GIOChannel *io, GError *err, void *user_data)
{
int sk = g_io_channel_unix_get_fd(io);
- struct bluetooth_service *service = user_data;
- struct obex_server *server = service->server;
+ struct bluetooth_profile *profile = user_data;
+ struct obex_server *server = profile->server;
int type;
int omtu = BT_TX_MTU;
int imtu = BT_RX_MTU;
@@ -340,281 +103,257 @@ drop:
return;
}
-static void service_reply(DBusPendingCall *call, void *user_data)
+static DBusMessage *profile_new_connection(DBusConnection *conn,
+ DBusMessage *msg, void *data)
{
- struct pending_request *pending = user_data;
- GIOChannel *io = pending->io;
- struct bluetooth_service *service = pending->service;
- DBusMessage *reply = dbus_pending_call_steal_reply(call);
- DBusError derr;
- GError *err = NULL;
+ DBusMessageIter args;
+ const char *device;
+ int fd;
+ GIOChannel *io;
- dbus_error_init(&derr);
- if (dbus_set_error_from_message(&derr, reply)) {
- error("bluetooth: RequestAuthorization error: %s, %s",
- derr.name, derr.message);
+ dbus_message_iter_init(msg, &args);
- if (dbus_error_has_name(&derr, DBUS_ERROR_NO_REPLY))
- service_cancel(pending);
+ if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_OBJECT_PATH)
+ return g_dbus_create_error(msg,
+ "org.bluez.Error.InvalidArguments",
+ "Invalid arguments in method call");
- dbus_error_free(&derr);
- g_io_channel_shutdown(io, TRUE, NULL);
- goto done;
- }
+ dbus_message_iter_get_basic(&args, &device);
- DBG("RequestAuthorization succeeded");
+ dbus_message_iter_next(&args);
- if (!bt_io_accept(io, connect_event, service, NULL, &err)) {
- error("%s", err->message);
- g_error_free(err);
- g_io_channel_shutdown(io, TRUE, NULL);
- }
+ if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_UNIX_FD)
+ return g_dbus_create_error(msg,
+ "org.bluez.Error.InvalidArguments",
+ "Invalid arguments in method call");
-done:
- g_source_remove(pending->watch);
- pending_request_free(pending);
- dbus_message_unref(reply);
-}
+ dbus_message_iter_get_basic(&args, &fd);
-static gboolean service_error(GIOChannel *io, GIOCondition cond,
- void *user_data)
-{
- struct pending_request *pending = user_data;
+ io = g_io_channel_unix_new(fd);
+ if (io == NULL)
+ return g_dbus_create_error(msg,
+ "org.bluez.Error.InvalidArguments",
+ "Invalid arguments in method call");
- service_cancel(pending);
+ DBG("device %s", device);
- dbus_pending_call_cancel(pending->call);
+ connect_event(io, NULL, data);
- pending_request_free(pending);
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
- return FALSE;
+static DBusMessage *profile_request_disconnection(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
-static void find_adapter_reply(DBusPendingCall *call, void *user_data)
+static DBusMessage *profile_cancel(DBusConnection *conn,
+ DBusMessage *msg, void *data)
{
- struct pending_request *pending = user_data;
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static const GDBusMethodTable profile_methods[] = {
+ { GDBUS_METHOD("Release",
+ NULL, NULL,
+ profile_release) },
+ { GDBUS_METHOD("NewConnection",
+ GDBUS_ARGS({ "device", "o" }, { "fd", "h" },
+ { "options", "a{sv}" }), NULL,
+ profile_new_connection) },
+ { GDBUS_METHOD("RequestDisconnection",
+ GDBUS_ARGS({ "device", "o" }), NULL,
+ profile_request_disconnection) },
+ { GDBUS_METHOD("Cancel",
+ NULL, NULL,
+ profile_cancel) },
+ { }
+};
+
+static void register_profile_reply(DBusPendingCall *call, void *user_data)
+{
+ struct bluetooth_profile *profile = user_data;
DBusMessage *reply = dbus_pending_call_steal_reply(call);
- DBusMessage *msg;
- DBusPendingCall *pcall;
- const char *path, *paddr = pending->address;
DBusError derr;
+ GError *err = NULL;
dbus_error_init(&derr);
- if (dbus_set_error_from_message(&derr, reply)) {
- error("Replied with an error: %s, %s",
- derr.name, derr.message);
- dbus_error_free(&derr);
- goto failed;
+ if (!dbus_set_error_from_message(&derr, reply)) {
+ DBG("Profile %s registered", profile->path);
+ goto done;
}
- dbus_message_get_args(reply, NULL,
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID);
+ g_free(profile->path);
+ profile->path = NULL;
- DBG("FindAdapter -> %s", path);
- pending->adapter_path = g_strdup(path);
+ error("bluetooth: RequestProfile error: %s, %s", derr.name,
+ derr.message);
+ dbus_error_free(&derr);
+done:
dbus_message_unref(reply);
+}
- msg = dbus_message_new_method_call("org.bluez", path,
- "org.bluez.Service", "RequestAuthorization");
-
- dbus_message_append_args(msg, DBUS_TYPE_STRING, &paddr,
- DBUS_TYPE_UINT32, &pending->service->handle,
- DBUS_TYPE_INVALID);
-
- if (!dbus_connection_send_with_reply(connection,
- msg, &pcall, TIMEOUT)) {
- dbus_message_unref(msg);
- goto failed;
- }
+static void unregister_profile(struct bluetooth_profile *profile)
+{
+ g_dbus_unregister_interface(connection, profile->path,
+ "org.bluez.Profile1");
+ g_free(profile->path);
+ profile->path = NULL;
+}
- dbus_message_unref(msg);
+static void profile_free(void *data)
+{
+ struct bluetooth_profile *profile = data;
- DBG("RequestAuthorization(%s, %x)", paddr,
- pending->service->handle);
+ if (profile->path != NULL)
+ unregister_profile(profile);
- if (!dbus_pending_call_set_notify(pcall, service_reply, pending,
- NULL)) {
- dbus_pending_call_unref(pcall);
- goto failed;
- }
+ g_free(profile->uuid);
+ g_free(profile);
+}
- dbus_pending_call_unref(pending->call);
- pending->call = pcall;
+static void append_variant(DBusMessageIter *iter, int type, void *val)
+{
+ DBusMessageIter value;
+ char sig[2] = { type, '\0' };
- /* Catches errors before authorization response comes */
- pending->watch = g_io_add_watch(pending->io,
- G_IO_HUP | G_IO_ERR | G_IO_NVAL,
- service_error, pending);
+ dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, sig, &value);
- return;
+ dbus_message_iter_append_basic(&value, type, val);
-failed:
- g_io_channel_shutdown(pending->io, TRUE, NULL);
- pending_request_free(pending);
+ dbus_message_iter_close_container(iter, &value);
}
-static int request_service_authorization(struct bluetooth_service *service,
- GIOChannel *io,
- const char *source,
- const char *address)
-{
- struct pending_request *pending;
- if (connection == NULL || any->path == NULL)
- return -1;
+void dict_append_entry(DBusMessageIter *dict,
+ const char *key, int type, void *val)
+{
+ DBusMessageIter entry;
- pending = g_new0(struct pending_request, 1);
- pending->call = find_adapter(source, find_adapter_reply, pending);
- if (!pending->call) {
- g_free(pending);
- return -ENOMEM;
+ if (type == DBUS_TYPE_STRING) {
+ const char *str = *((const char **) val);
+ if (str == NULL)
+ return;
}
- pending->service = service;
- pending->io = g_io_channel_ref(io);
- memcpy(pending->address, address, sizeof(pending->address));
+ dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
+ NULL, &entry);
- return 0;
+ dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
+
+ append_variant(&entry, type, val);
+
+ dbus_message_iter_close_container(dict, &entry);
}
-static void confirm_connection(GIOChannel *io, const char *source,
- const char *address, void *user_data)
+static int register_profile(struct bluetooth_profile *profile)
{
+ DBusMessage *msg;
+ DBusMessageIter iter, opt;
+ DBusPendingCall *call;
+ dbus_bool_t auto_connect = FALSE;
+ int ret = 0;
- struct obex_service_driver *driver = user_data;
- struct bluetooth_service *service;
- GError *err = NULL;
+ profile->path = g_strconcat("/org/bluez/obex/", profile->uuid, NULL);
+ g_strdelimit(profile->path, "-", '_');
- service = find_service(driver);
- if (service == NULL) {
- error("bluetooth: Unable to find service");
- goto drop;
+ if (!g_dbus_register_interface(connection, profile->path,
+ "org.bluez.Profile1", profile_methods,
+ NULL, NULL,
+ profile, NULL)) {
+ error("D-Bus failed to register %s", profile->path);
+ g_free(profile->path);
+ profile->path = NULL;
+ return -1;
}
- if (driver->secure) {
- if (request_service_authorization(service, io, source,
- address) < 0)
- goto drop;
+ msg = dbus_message_new_method_call("org.bluez", "/org/bluez",
+ "org.bluez.ProfileManager1",
+ "RegisterProfile");
+
+ dbus_message_iter_init_append(msg, &iter);
+
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
+ &profile->path);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,
+ &profile->uuid);
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+ DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+ DBUS_TYPE_STRING_AS_STRING
+ DBUS_TYPE_VARIANT_AS_STRING
+ DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+ &opt);
+ dict_append_entry(&opt, "AutoConnect", DBUS_TYPE_BOOLEAN,
+ &auto_connect);
+ dbus_message_iter_close_container(&iter, &opt);
- return;
- }
-
- if (!bt_io_accept(io, connect_event, service, NULL, &err)) {
- error("%s", err->message);
- g_error_free(err);
- goto drop;
+ if (!dbus_connection_send_with_reply(connection, msg, &call, -1)) {
+ ret = -1;
+ unregister_profile(profile);
+ goto failed;
}
- return;
+ dbus_pending_call_set_notify(call, register_profile_reply, profile,
+ NULL);
+ dbus_pending_call_unref(call);
-drop:
- g_io_channel_shutdown(io, TRUE, NULL);
+failed:
+ dbus_message_unref(msg);
+ return ret;
}
-static void confirm_rfcomm(GIOChannel *io, void *user_data)
+static const char *service2uuid(uint16_t service)
{
- GError *err = NULL;
- char source[18];
- char address[18];
- uint8_t channel;
-
- bt_io_get(io, &err,
- BT_IO_OPT_SOURCE, source,
- BT_IO_OPT_DEST, address,
- BT_IO_OPT_CHANNEL, &channel,
- BT_IO_OPT_INVALID);
- if (err) {
- error("%s", err->message);
- g_error_free(err);
- g_io_channel_shutdown(io, TRUE, NULL);
- return;
+ switch (service) {
+ case OBEX_OPP:
+ return OBEX_OPP_UUID;
+ case OBEX_FTP:
+ return OBEX_FTP_UUID;
+ case OBEX_PBAP:
+ return OBEX_PSE_UUID;
}
- info("bluetooth: New connection from: %s, channel %u", address,
- channel);
-
- confirm_connection(io, source, address, user_data);
+ return NULL;
}
-static void confirm_l2cap(GIOChannel *io, void *user_data)
+static void name_acquired(DBusConnection *conn, void *user_data)
{
- GError *err = NULL;
- char source[18];
- char address[18];
- uint16_t psm;
-
- bt_io_get(io, &err,
- BT_IO_OPT_SOURCE, source,
- BT_IO_OPT_DEST, address,
- BT_IO_OPT_PSM, &psm,
- BT_IO_OPT_INVALID);
- if (err) {
- error("%s", err->message);
- g_error_free(err);
- g_io_channel_shutdown(io, TRUE, NULL);
- return;
- }
+ GSList *l;
- info("bluetooth: New connection from: %s, psm %u", address, psm);
+ DBG("org.bluez appeared");
- confirm_connection(io, source, address, user_data);
+ for (l = profiles; l; l = l->next) {
+ struct bluetooth_profile *profile = l->data;
+ const char *uuid;
+
+ if (profile->path != NULL)
+ continue;
+
+ if (register_profile(profile) < 0) {
+ error("bluetooth: Failed to register profile %s",
+ profile->path);
+ g_free(profile->path);
+ profile->path = NULL;
+ }
+ }
}
-static GSList *start(struct obex_server *server,
- struct obex_service_driver *service)
+static void name_released(DBusConnection *conn, void *user_data)
{
- BtIOSecLevel sec_level;
- GSList *l = NULL;
- GIOChannel *io;
- GError *err = NULL;
- uint16_t psm;
-
- if (service->secure == TRUE)
- sec_level = BT_IO_SEC_MEDIUM;
- else
- sec_level = BT_IO_SEC_LOW;
-
- io = bt_io_listen(NULL, confirm_rfcomm,
- service, NULL, &err,
- BT_IO_OPT_CHANNEL, service->channel,
- BT_IO_OPT_SEC_LEVEL, sec_level,
- BT_IO_OPT_INVALID);
- if (io == NULL) {
- error("bluetooth: unable to listen in channel %d: %s",
- service->channel, err->message);
- g_error_free(err);
- } else {
- l = g_slist_prepend(l, io);
- DBG("listening on channel %d", service->channel);
- }
+ GSList *l;
- if (service->port == 0)
- return l;
-
- psm = service->port == OBEX_PORT_RANDOM ? 0 : service->port;
-
- io = bt_io_listen(NULL, confirm_l2cap,
- service, NULL, &err,
- BT_IO_OPT_PSM, psm,
- BT_IO_OPT_MODE, BT_IO_MODE_ERTM,
- BT_IO_OPT_OMTU, BT_TX_MTU,
- BT_IO_OPT_IMTU, BT_RX_MTU,
- BT_IO_OPT_SEC_LEVEL, sec_level,
- BT_IO_OPT_INVALID);
- if (io == NULL) {
- error("bluetooth: unable to listen in psm %d: %s",
- service->port, err->message);
- g_error_free(err);
- service->port = 0;
- } else {
- l = g_slist_prepend(l, io);
- bt_io_get(io, &err, BT_IO_OPT_PSM, &service->port,
- BT_IO_OPT_INVALID);
- DBG("listening on psm %d", service->port);
- }
+ DBG("org.bluez disappered");
+
+ for (l = profiles; l; l = l->next) {
+ struct bluetooth_profile *profile = l->data;
+ const char *uuid;
- return l;
+ if (profile->path == NULL)
+ continue;
+
+ unregister_profile(profile);
+ }
}
static void *bluetooth_start(struct obex_server *server, int *err)
@@ -623,34 +362,29 @@ static void *bluetooth_start(struct obex_server *server, int *err)
const GSList *l;
for (l = server->drivers; l; l = l->next) {
- struct obex_service_driver *service = l->data;
- GSList *l;
+ struct obex_service_driver *driver = l->data;
+ struct bluetooth_profile *profile;
+ const char *uuid;
- l = start(server, service);
- if (l == NULL)
+ uuid = service2uuid(driver->service);
+ if (uuid == NULL)
continue;
- ios = g_slist_concat(ios, l);
- }
-
- register_record(server);
-
- return ios;
-}
+ profile = g_new0(struct bluetooth_profile, 1);
+ profile->driver = driver;
+ profile->server = server;
+ profile->uuid = g_strdup(uuid);
-static void stop(gpointer data)
-{
- GIOChannel *io = data;
+ profiles = g_slist_prepend(profiles, profile);
+ }
- g_io_channel_shutdown(io, TRUE, NULL);
- g_io_channel_unref(io);
+ return profiles;
}
static void bluetooth_stop(void *data)
{
- GSList *ios = data;
-
- g_slist_free_full(ios, stop);
+ g_slist_free_full(profiles, profile_free);
+ profiles = NULL;
}
static int bluetooth_getpeername(GIOChannel *io, char **name)
@@ -682,8 +416,6 @@ static unsigned int listener_id = 0;
static int bluetooth_init(void)
{
- any = g_new0(struct adapter_any, 1);
-
connection = g_dbus_setup_private(DBUS_BUS_SYSTEM, NULL, NULL);
if (connection == NULL)
return -EPERM;
@@ -698,11 +430,7 @@ static void bluetooth_exit(void)
{
g_dbus_remove_watch(connection, listener_id);
- if (any) {
- g_slist_free_full(any->services, g_free);
- g_free(any->path);
- g_free(any);
- }
+ g_slist_free_full(profiles, profile_free);
if (connection)
dbus_connection_unref(connection);
--
1.7.11.7
^ permalink raw reply related
* RE: [BLE] org.bluez.Device1.Connect() returns org.bluez.Error.NotAvailable
From: Ting Chou @ 2012-12-12 11:30 UTC (permalink / raw)
To: Anderson Lizardo; +Cc: Johan Hedberg, linux-bluetooth@vger.kernel.org
In-Reply-To: <CAJdJm_Nb-W=ua7aUr7O578jJwLDGaC2-uC=vv0P2zdZOaXWUPg@mail.gmail.com>
Hi Anderson,
> -----Original Message-----
> From: Anderson Lizardo [mailto:anderson.lizardo@openbossa.org]
> Sent: Wednesday, December 12, 2012 6:53 PM
> To: Ting Chou
> Cc: Johan Hedberg; linux-bluetooth@vger.kernel.org
> Subject: Re: [BLE] org.bluez.Device1.Connect() returns
> org.bluez.Error.NotAvailable
>
> 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.
>
Does this mean the "User selects a device to connect" in Figure 9.6 (Page 1715,
Flow chart for a device performing the general connection establishment
procedure) is not needed for supported devices?
> 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.
>
I'm not sure if I understand correctly. But do you mean the GCEP you mentioned
above is applied while "reconnecting" to a supported device?
Thanks,
Ting
^ permalink raw reply
* 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
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