Linux bluetooth development
 help / color / mirror / Atom feed
* [RFC 12/16] Bluetooth: Use abstract chan->data in comparison
From: Gustavo Padovan @ 2012-12-12  4:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo Padovan
In-Reply-To: <1355285624-25811-1-git-send-email-gustavo@padovan.org>

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

If the L2CAP user is l2cap_sock.c chan->data is a pointer to the l2cap
socket so chan->sk and chan->data are the same thing. Then we can just
compare with chan->data instead.

Non-socket users will have skb->sk = NULL, thus this change does not
interfere in other users.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 net/bluetooth/l2cap_core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 934ac1b..92936db 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -2682,12 +2682,11 @@ static void l2cap_raw_recv(struct l2cap_conn *conn, struct sk_buff *skb)
 	mutex_lock(&conn->chan_lock);
 
 	list_for_each_entry(chan, &conn->chan_l, list) {
-		struct sock *sk = chan->sk;
 		if (chan->chan_type != L2CAP_CHAN_RAW)
 			continue;
 
 		/* Don't send frame to the socket it came from */
-		if (skb->sk == sk)
+		if (skb->sk && skb->sk == chan->data)
 			continue;
 		nskb = skb_clone(skb, GFP_KERNEL);
 		if (!nskb)
-- 
1.7.11.7


^ permalink raw reply related

* [RFC 13/16] Bluetooth: Move l2cap_wait_ack() to l2cap_sock.c
From: Gustavo Padovan @ 2012-12-12  4:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo Padovan
In-Reply-To: <1355285624-25811-1-git-send-email-gustavo@padovan.org>

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

The wait_ack code has a heavy dependency on the socket data structures
and, as of now, it won't be worthless change it to use non-socket
structures as the only user of such feature is a socket.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 include/net/bluetooth/l2cap.h |  3 ++-
 net/bluetooth/l2cap_core.c    | 32 --------------------------------
 net/bluetooth/l2cap_sock.c    | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 34 insertions(+), 33 deletions(-)

diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index b1cc286..9673ef4 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -758,6 +758,8 @@ static inline bool l2cap_clear_timer(struct l2cap_chan *chan,
 		msecs_to_jiffies(L2CAP_DEFAULT_ACK_TO));
 #define __clear_ack_timer(c) l2cap_clear_timer(c, &c->ack_timer)
 
+#define __missing_ack(c) (c->unacked_frames > 0 && c->conn)
+
 static inline int __seq_offset(struct l2cap_chan *chan, __u16 seq1, __u16 seq2)
 {
 	if (seq1 >= seq2)
@@ -794,7 +796,6 @@ int l2cap_init_sockets(void);
 void l2cap_cleanup_sockets(void);
 
 void __l2cap_connect_rsp_defer(struct l2cap_chan *chan);
-int __l2cap_wait_ack(struct sock *sk);
 
 int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm);
 int l2cap_add_scid(struct l2cap_chan *chan,  __u16 scid);
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 92936db..68faff8 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1711,38 +1711,6 @@ done:
 	return err;
 }
 
-int __l2cap_wait_ack(struct sock *sk)
-{
-	struct l2cap_chan *chan = l2cap_pi(sk)->chan;
-	DECLARE_WAITQUEUE(wait, current);
-	int err = 0;
-	int timeo = HZ/5;
-
-	add_wait_queue(sk_sleep(sk), &wait);
-	set_current_state(TASK_INTERRUPTIBLE);
-	while (chan->unacked_frames > 0 && chan->conn) {
-		if (!timeo)
-			timeo = HZ/5;
-
-		if (signal_pending(current)) {
-			err = sock_intr_errno(timeo);
-			break;
-		}
-
-		release_sock(sk);
-		timeo = schedule_timeout(timeo);
-		lock_sock(sk);
-		set_current_state(TASK_INTERRUPTIBLE);
-
-		err = sock_error(sk);
-		if (err)
-			break;
-	}
-	set_current_state(TASK_RUNNING);
-	remove_wait_queue(sk_sleep(sk), &wait);
-	return err;
-}
-
 static void l2cap_monitor_timeout(struct work_struct *work)
 {
 	struct l2cap_chan *chan = container_of(work, struct l2cap_chan,
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index e4fcbde..51fbc98 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -853,6 +853,38 @@ static void l2cap_sock_kill(struct sock *sk)
 	sock_put(sk);
 }
 
+static int __l2cap_wait_ack(struct sock *sk)
+{
+	struct l2cap_chan *chan = l2cap_pi(sk)->chan;
+	DECLARE_WAITQUEUE(wait, current);
+	int err = 0;
+	int timeo = HZ/5;
+
+	add_wait_queue(sk_sleep(sk), &wait);
+	set_current_state(TASK_INTERRUPTIBLE);
+	while (__missing_ack(chan)) {
+		if (!timeo)
+			timeo = HZ/5;
+
+		if (signal_pending(current)) {
+			err = sock_intr_errno(timeo);
+			break;
+		}
+
+		release_sock(sk);
+		timeo = schedule_timeout(timeo);
+		lock_sock(sk);
+		set_current_state(TASK_INTERRUPTIBLE);
+
+		err = sock_error(sk);
+		if (err)
+			break;
+	}
+	set_current_state(TASK_RUNNING);
+	remove_wait_queue(sk_sleep(sk), &wait);
+	return err;
+}
+
 static int l2cap_sock_shutdown(struct socket *sock, int how)
 {
 	struct sock *sk = sock->sk;
-- 
1.7.11.7


^ permalink raw reply related

* [RFC 14/16] Bluetooth: Create l2cap->ops->resume()
From: Gustavo Padovan @ 2012-12-12  4:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo Padovan
In-Reply-To: <1355285624-25811-1-git-send-email-gustavo@padovan.org>

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

resume() will isolate the code the code to get a socket back from the
suspended state when a security elevation happens.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 include/net/bluetooth/l2cap.h |  5 +++++
 net/bluetooth/a2mp.c          |  1 +
 net/bluetooth/l2cap_core.c    |  6 +-----
 net/bluetooth/l2cap_sock.c    | 13 +++++++++++++
 4 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index 9673ef4..04dd8cd 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -556,6 +556,7 @@ struct l2cap_ops {
 	void			(*defer) (struct l2cap_chan *chan);
 	struct sk_buff		*(*alloc_skb) (struct l2cap_chan *chan,
 					       unsigned long len, int nb);
+	void			(*resume) (struct l2cap_chan *chan);
 };
 
 struct l2cap_conn {
@@ -790,6 +791,10 @@ static inline void l2cap_chan_no_defer(struct l2cap_chan *chan)
 {
 }
 
+static inline void l2cap_chan_no_resume(struct l2cap_chan *chan)
+{
+}
+
 extern bool disable_ertm;
 
 int l2cap_init_sockets(void);
diff --git a/net/bluetooth/a2mp.c b/net/bluetooth/a2mp.c
index 2b6faae..23265d9 100644
--- a/net/bluetooth/a2mp.c
+++ b/net/bluetooth/a2mp.c
@@ -700,6 +700,7 @@ static struct l2cap_ops a2mp_chan_ops = {
 	.teardown = l2cap_chan_no_teardown,
 	.ready = l2cap_chan_no_ready,
 	.defer = l2cap_chan_no_defer,
+	.resume = l2cap_chan_no_resume,
 };
 
 static struct l2cap_chan *a2mp_chan_open(struct l2cap_conn *conn, bool locked)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 68faff8..a294422 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -6320,11 +6320,7 @@ int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
 
 		if (!status && (chan->state == BT_CONNECTED ||
 				chan->state == BT_CONFIG)) {
-			struct sock *sk = chan->sk;
-
-			clear_bit(BT_SK_SUSPEND, &bt_sk(sk)->flags);
-			sk->sk_state_change(sk);
-
+			chan->ops->resume(chan);
 			l2cap_check_encryption(chan, encrypt);
 			l2cap_chan_unlock(chan);
 			continue;
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 51fbc98..f89e558 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -1146,6 +1146,18 @@ static void l2cap_sock_defer_cb(struct l2cap_chan *chan)
 	release_sock(sk);
 }
 
+static void l2cap_sock_resume_cb(struct l2cap_chan *chan)
+{
+	struct sock *sk = chan->data;
+
+	lock_sock(sk);
+
+	clear_bit(BT_SK_SUSPEND, &bt_sk(sk)->flags);
+	sk->sk_state_change(sk);
+
+	release_sock(sk);
+}
+
 static struct l2cap_ops l2cap_chan_ops = {
 	.name		= "L2CAP Socket Interface",
 	.new_connection	= l2cap_sock_new_connection_cb,
@@ -1156,6 +1168,7 @@ static struct l2cap_ops l2cap_chan_ops = {
 	.ready		= l2cap_sock_ready_cb,
 	.defer		= l2cap_sock_defer_cb,
 	.alloc_skb	= l2cap_sock_alloc_skb_cb,
+	.resume		= l2cap_sock_resume_cb,
 };
 
 static void l2cap_sock_destruct(struct sock *sk)
-- 
1.7.11.7


^ permalink raw reply related

* [RFC 15/16] Bluetooth: Create l2cap->ops->set_shutdown()
From: Gustavo Padovan @ 2012-12-12  4:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo Padovan
In-Reply-To: <1355285624-25811-1-git-send-email-gustavo@padovan.org>

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Isolates the code that sets the socket shutdown mask. This is the last
commit to remove the socket usage from l2cap_core.c

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 include/net/bluetooth/l2cap.h |  5 +++++
 net/bluetooth/a2mp.c          |  1 +
 net/bluetooth/l2cap_core.c    |  7 +------
 net/bluetooth/l2cap_sock.c    | 10 ++++++++++
 4 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index 04dd8cd..b6bfbbd 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -557,6 +557,7 @@ struct l2cap_ops {
 	struct sk_buff		*(*alloc_skb) (struct l2cap_chan *chan,
 					       unsigned long len, int nb);
 	void			(*resume) (struct l2cap_chan *chan);
+	void			(*set_shutdown) (struct l2cap_chan *chan);
 };
 
 struct l2cap_conn {
@@ -795,6 +796,10 @@ static inline void l2cap_chan_no_resume(struct l2cap_chan *chan)
 {
 }
 
+static inline void l2cap_chan_no_set_shutdown(struct l2cap_chan *chan)
+{
+}
+
 extern bool disable_ertm;
 
 int l2cap_init_sockets(void);
diff --git a/net/bluetooth/a2mp.c b/net/bluetooth/a2mp.c
index 23265d9..a4286b2 100644
--- a/net/bluetooth/a2mp.c
+++ b/net/bluetooth/a2mp.c
@@ -701,6 +701,7 @@ static struct l2cap_ops a2mp_chan_ops = {
 	.ready = l2cap_chan_no_ready,
 	.defer = l2cap_chan_no_defer,
 	.resume = l2cap_chan_no_resume,
+	.set_shutdown = l2cap_chan_no_set_shutdown,
 };
 
 static struct l2cap_chan *a2mp_chan_open(struct l2cap_conn *conn, bool locked)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index a294422..7d3fed1 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -3978,7 +3978,6 @@ static inline int l2cap_disconnect_req(struct l2cap_conn *conn,
 	struct l2cap_disconn_rsp rsp;
 	u16 dcid, scid;
 	struct l2cap_chan *chan;
-	struct sock *sk;
 
 	scid = __le16_to_cpu(req->scid);
 	dcid = __le16_to_cpu(req->dcid);
@@ -3995,15 +3994,11 @@ static inline int l2cap_disconnect_req(struct l2cap_conn *conn,
 
 	l2cap_chan_lock(chan);
 
-	sk = chan->sk;
-
 	rsp.dcid = cpu_to_le16(chan->scid);
 	rsp.scid = cpu_to_le16(chan->dcid);
 	l2cap_send_cmd(conn, cmd->ident, L2CAP_DISCONN_RSP, sizeof(rsp), &rsp);
 
-	lock_sock(sk);
-	sk->sk_shutdown = SHUTDOWN_MASK;
-	release_sock(sk);
+	chan->ops->set_shutdown(chan);
 
 	l2cap_chan_hold(chan);
 	l2cap_chan_del(chan, ECONNRESET);
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index f89e558..1f80b9b 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -1158,6 +1158,15 @@ static void l2cap_sock_resume_cb(struct l2cap_chan *chan)
 	release_sock(sk);
 }
 
+static void l2cap_sock_set_shutdown_cb(struct l2cap_chan *chan)
+{
+	struct sock *sk = chan->data;
+
+	lock_sock(sk);
+	sk->sk_shutdown = SHUTDOWN_MASK;
+	release_sock(sk);
+}
+
 static struct l2cap_ops l2cap_chan_ops = {
 	.name		= "L2CAP Socket Interface",
 	.new_connection	= l2cap_sock_new_connection_cb,
@@ -1169,6 +1178,7 @@ static struct l2cap_ops l2cap_chan_ops = {
 	.defer		= l2cap_sock_defer_cb,
 	.alloc_skb	= l2cap_sock_alloc_skb_cb,
 	.resume		= l2cap_sock_resume_cb,
+	.set_shutdown	= l2cap_sock_set_shutdown_cb,
 };
 
 static void l2cap_sock_destruct(struct sock *sk)
-- 
1.7.11.7


^ permalink raw reply related

* [RFC 16/16] Bluetooth: Remove sk member from struct l2cap_chan
From: Gustavo Padovan @ 2012-12-12  4:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo Padovan
In-Reply-To: <1355285624-25811-1-git-send-email-gustavo@padovan.org>

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Now that the removal of socket usage from l2cap_core.c is done we can
remove sk from struct l2cap_chan since we do not use it anywhere anymore.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 include/net/bluetooth/l2cap.h | 2 --
 net/bluetooth/l2cap_sock.c    | 5 ++---
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index b6bfbbd..2d18bcb 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -433,8 +433,6 @@ struct l2cap_seq_list {
 #define L2CAP_SEQ_LIST_TAIL	0x8000
 
 struct l2cap_chan {
-	struct sock *sk;
-
 	bdaddr_t	src;
 	bdaddr_t	dst;
 
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 1f80b9b..82b7d0a 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -1100,11 +1100,12 @@ static void l2cap_sock_state_change_cb(struct l2cap_chan *chan, int state, int e
 static struct sk_buff *l2cap_sock_alloc_skb_cb(struct l2cap_chan *chan,
 					       unsigned long len, int nb)
 {
+	struct sock *sk = chan->data;
 	struct sk_buff *skb;
 	int err;
 
 	l2cap_chan_unlock(chan);
-	skb = bt_skb_send_alloc(chan->sk, len, nb, &err);
+	skb = bt_skb_send_alloc(sk, len, nb, &err);
 	l2cap_chan_lock(chan);
 
 	if (!skb)
@@ -1292,8 +1293,6 @@ static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock,
 
 	l2cap_chan_hold(chan);
 
-	chan->sk = sk;
-
 	l2cap_pi(sk)->chan = chan;
 
 	return sk;
-- 
1.7.11.7


^ permalink raw reply related

* Re: [BLE] org.bluez.Device1.Connect() returns org.bluez.Error.NotAvailable
From: Johan Hedberg @ 2012-12-12  7:52 UTC (permalink / raw)
  To: Ting Chou; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <ADCBF04BB97EBF4AAE65663F8478B61CA99E65AB92@Luna.iaSolution.net>

Hi Ting,

On Wed, Dec 12, 2012, Ting Chou wrote:
> I Found
> -------
> 
> - I checked /var/log/syslog and src/device.c, and found connect_profiles() is
>   called twice at the first time calling org.bluez.Device.Connect():
> 
>   - 1st time
>     dev->svc_resolved==FALSE, device_resolve_svc() is invoked.
> 
>   - 2nd time
>     dev->svc_resolved==TRUE
>     In the for loop of iterating device profiles, there're two profiles:
> 
>       a) p->auto_connect==FALSE, p->name==deviceinfo, p->local_uuid==NULL
>       b) p->auto_connect==FALSE, p->name==Health Thermometer GATT driver, p->local_uuid==NULL
> 
>     Since none of them have auto_connect TRUE, dev->pending==NULL, and
>     btd_error_not_available() is called.
> 
> - I tried org.bluez.Device1.ConnectProfile() as well, but since all the profiles
>   have local_uuid NULL, find_connectable_profile() return NULL and
>   btd_error_invalid_args() is called.

It's not actually local_uuid that is so important but that p->connect is
set. Also, it'd make much more sense to pass the remote UUID to
ConnectProfile than the local one and we'll still do this change before
releasing 5.0. The main thing that needs to be done before that is to
convert profile->remote_uuids list to a single profile->remote_uuid
which is a bit of work since some profiles still declare multiple UUIDs.

So far no LE profile is hooked up to Device.Connect and I'm not sure
exactly how that should be done since LE device are connected through
the general connection establishment procedure which requires scanning
first. Since we already have Device.Pair doing the same as
CreatePairedDevice in BlueZ 4 (and this should work btw, did you try
it?) maybe Device.Connect should be roughly the same for LE devices as
Adapter.CreateDevice is in BlueZ 4? For BR/EDR devices it already serves
this purpose. The main question is what should be done if Device.Connect
is called subsequent times as bluetoothd should anyway already be doing
passive scanning and trying to connect to devices that have supported
profiles.

Johan

^ permalink raw reply

* Re: [RFC 12/16] Bluetooth: Use abstract chan->data in comparison
From: Andrei Emeltchenko @ 2012-12-12  8:20 UTC (permalink / raw)
  To: Gustavo Padovan; +Cc: linux-bluetooth, Gustavo Padovan
In-Reply-To: <1355285624-25811-13-git-send-email-gustavo@padovan.org>

Hi Gustavo,

On Wed, Dec 12, 2012 at 02:13:40AM -0200, Gustavo Padovan wrote:
> From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> 
> If the L2CAP user is l2cap_sock.c chan->data is a pointer to the l2cap
> socket so chan->sk and chan->data are the same thing. Then we can just
> compare with chan->data instead.
> 
> Non-socket users will have skb->sk = NULL, thus this change does not
> interfere in other users.
> 
> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> ---
>  net/bluetooth/l2cap_core.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
> index 934ac1b..92936db 100644
> --- a/net/bluetooth/l2cap_core.c
> +++ b/net/bluetooth/l2cap_core.c
> @@ -2682,12 +2682,11 @@ static void l2cap_raw_recv(struct l2cap_conn *conn, struct sk_buff *skb)
>  	mutex_lock(&conn->chan_lock);
>  
>  	list_for_each_entry(chan, &conn->chan_l, list) {
> -		struct sock *sk = chan->sk;
>  		if (chan->chan_type != L2CAP_CHAN_RAW)
>  			continue;
>  
>  		/* Don't send frame to the socket it came from */
> -		if (skb->sk == sk)
> +		if (skb->sk && skb->sk == chan->data)

In the other patch you delete chan->sk pointer and then we have only
chan->data which points to sk. What is the reason for that? This would
confuse people reading chan->data guessing what the hell is this.

I really think we can leave chan->sk if it is needed and it is better to
remove chan->data.

Best regards 
Andrei Emeltchenko 


^ permalink raw reply

* [PATCH] storage: Remove not used functions
From: Frédéric Danis @ 2012-12-12  8:41 UTC (permalink / raw)
  To: linux-bluetooth

Those functions are no more used with new storage architecture.
---
 src/storage.c |  590 ---------------------------------------------------------
 src/storage.h |   43 -----
 2 files changed, 633 deletions(-)

diff --git a/src/storage.c b/src/storage.c
index ac66021..5798ccd 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -65,64 +65,6 @@ static inline int create_filename(char *buf, size_t size,
 	return create_name(buf, size, STORAGEDIR, addr, name);
 }
 
-int read_device_alias(const char *src, const char *dst, uint8_t dst_type,
-						char *alias, size_t size)
-{
-	char filename[PATH_MAX + 1], *tmp;
-	char key[20];
-	int err;
-
-	create_name(filename, PATH_MAX, STORAGEDIR, src, "aliases");
-
-	snprintf(key, sizeof(key), "%17s#%hhu", dst, dst_type);
-
-	tmp = textfile_get(filename, key);
-	if (tmp != NULL)
-		goto done;
-
-	/* Try old format (address only) */
-	key[17] = '\0';
-
-	tmp = textfile_get(filename, key);
-	if (tmp == NULL)
-		return -ENXIO;
-
-done:
-	err = snprintf(alias, size, "%s", tmp);
-
-	free(tmp);
-
-	return err < 0 ? -EIO : 0;
-}
-
-int write_device_alias(const char *src, const char *dst, uint8_t dst_type,
-							const char *alias)
-{
-	char filename[PATH_MAX + 1];
-	char key[20];
-
-	create_name(filename, PATH_MAX, STORAGEDIR, src, "aliases");
-
-	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-
-	snprintf(key, sizeof(key), "%17s#%hhu", dst, dst_type);
-
-	return textfile_put(filename, key, alias);
-}
-
-int write_discoverable_timeout(const bdaddr_t *bdaddr, int timeout)
-{
-	char filename[PATH_MAX + 1], str[32];
-
-	snprintf(str, sizeof(str), "%d", timeout);
-
-	create_filename(filename, PATH_MAX, bdaddr, "config");
-
-	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-
-	return textfile_put(filename, "discovto", str);
-}
-
 int read_discoverable_timeout(const char *src, int *timeout)
 {
 	char filename[PATH_MAX + 1], *str;
@@ -143,19 +85,6 @@ int read_discoverable_timeout(const char *src, int *timeout)
 	return 0;
 }
 
-int write_pairable_timeout(const bdaddr_t *bdaddr, int timeout)
-{
-	char filename[PATH_MAX + 1], str[32];
-
-	snprintf(str, sizeof(str), "%d", timeout);
-
-	create_filename(filename, PATH_MAX, bdaddr, "config");
-
-	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-
-	return textfile_put(filename, "pairto", str);
-}
-
 int read_pairable_timeout(const char *src, int *timeout)
 {
 	char filename[PATH_MAX + 1], *str;
@@ -176,20 +105,6 @@ int read_pairable_timeout(const char *src, int *timeout)
 	return 0;
 }
 
-int write_device_mode(const bdaddr_t *bdaddr, const char *mode)
-{
-	char filename[PATH_MAX + 1];
-
-	create_filename(filename, PATH_MAX, bdaddr, "config");
-
-	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-
-	if (strcmp(mode, "off") != 0)
-		textfile_put(filename, "onmode", mode);
-
-	return textfile_put(filename, "mode", mode);
-}
-
 int read_device_mode(const char *src, char *mode, int length)
 {
 	char filename[PATH_MAX + 1], *str;
@@ -226,25 +141,6 @@ int read_on_mode(const char *src, char *mode, int length)
 	return 0;
 }
 
-int write_local_name(const bdaddr_t *bdaddr, const char *name)
-{
-	char filename[PATH_MAX + 1], str[249];
-	int i;
-
-	memset(str, 0, sizeof(str));
-	for (i = 0; i < 248 && name[i]; i++)
-		if ((unsigned char) name[i] < 32 || name[i] == 127)
-			str[i] = '.';
-		else
-			str[i] = name[i];
-
-	create_filename(filename, PATH_MAX, bdaddr, "config");
-
-	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-
-	return textfile_put(filename, "name", str);
-}
-
 int read_local_name(const bdaddr_t *bdaddr, char *name)
 {
 	char filename[PATH_MAX + 1], *str;
@@ -266,19 +162,6 @@ int read_local_name(const bdaddr_t *bdaddr, char *name)
 	return 0;
 }
 
-int write_local_class(const bdaddr_t *bdaddr, uint8_t *class)
-{
-	char filename[PATH_MAX + 1], str[9];
-
-	sprintf(str, "0x%2.2x%2.2x%2.2x", class[2], class[1], class[0]);
-
-	create_filename(filename, PATH_MAX, bdaddr, "config");
-
-	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-
-	return textfile_put(filename, "class", str);
-}
-
 int read_local_class(const bdaddr_t *bdaddr, uint8_t *class)
 {
 	char filename[PATH_MAX + 1], tmp[3], *str;
@@ -342,117 +225,6 @@ int write_remote_appearance(const bdaddr_t *local, const bdaddr_t *peer,
 	return textfile_put(filename, key, str);
 }
 
-int write_remote_class(const bdaddr_t *local, const bdaddr_t *peer,
-								uint32_t class)
-{
-	char filename[PATH_MAX + 1], addr[18], str[9];
-
-	create_filename(filename, PATH_MAX, local, "classes");
-
-	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-
-	ba2str(peer, addr);
-	sprintf(str, "0x%6.6x", class);
-
-	return textfile_put(filename, addr, str);
-}
-
-int read_remote_class(const bdaddr_t *local, const bdaddr_t *peer,
-							uint32_t *class)
-{
-	char filename[PATH_MAX + 1], addr[18], *str;
-
-	create_filename(filename, PATH_MAX, local, "classes");
-
-	ba2str(peer, addr);
-
-	str = textfile_get(filename, addr);
-	if (!str)
-		return -ENOENT;
-
-	if (sscanf(str, "%x", class) != 1) {
-		free(str);
-		return -ENOENT;
-	}
-
-	free(str);
-
-	return 0;
-}
-
-int write_device_name(const bdaddr_t *local, const bdaddr_t *peer,
-					uint8_t peer_type, const char *name)
-{
-	char filename[PATH_MAX + 1], key[20], str[HCI_MAX_NAME_LENGTH + 1];
-	int i;
-
-	memset(str, 0, sizeof(str));
-	for (i = 0; i < HCI_MAX_NAME_LENGTH && name[i]; i++)
-		if ((unsigned char) name[i] < 32 || name[i] == 127)
-			str[i] = '.';
-		else
-			str[i] = name[i];
-
-	create_filename(filename, PATH_MAX, local, "names");
-
-	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-
-	ba2str(peer, key);
-	sprintf(&key[17], "#%hhu", peer_type);
-
-	return textfile_put(filename, key, str);
-}
-
-int read_device_name(const char *src, const char *dst, uint8_t dst_type,
-								char *name)
-{
-	char filename[PATH_MAX + 1], *str, key[20];
-	int len;
-
-	create_name(filename, PATH_MAX, STORAGEDIR, src, "names");
-
-	snprintf(key, sizeof(key), "%17s#%hhu", dst, dst_type);
-
-	str = textfile_get(filename, key);
-	if (str != NULL)
-		goto done;
-
-	/* Try old format (address only) */
-	key[17] = '\0';
-
-	str = textfile_get(filename, key);
-	if (str == NULL)
-		return -ENOENT;
-
-done:
-	len = strlen(str);
-	if (len > HCI_MAX_NAME_LENGTH)
-		str[HCI_MAX_NAME_LENGTH] = '\0';
-	strcpy(name, str);
-
-	free(str);
-
-	return 0;
-}
-
-int write_lastseen_info(const bdaddr_t *local, const bdaddr_t *peer,
-					uint8_t peer_type, struct tm *tm)
-{
-	char filename[PATH_MAX + 1], key[20], str[24];
-
-	memset(str, 0, sizeof(str));
-	strftime(str, sizeof(str), "%Y-%m-%d %H:%M:%S %Z", tm);
-
-	create_filename(filename, PATH_MAX, local, "lastseen");
-
-	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-
-	ba2str(peer, key);
-	sprintf(&key[17], "#%hhu", peer_type);
-
-	return textfile_put(filename, key, str);
-}
-
 int write_lastused_info(const bdaddr_t *local, const bdaddr_t *peer,
 					uint8_t peer_type, struct tm *tm)
 {
@@ -471,82 +243,6 @@ int write_lastused_info(const bdaddr_t *local, const bdaddr_t *peer,
 	return textfile_put(filename, key, str);
 }
 
-int write_link_key(const bdaddr_t *local, const bdaddr_t *peer,
-					uint8_t peer_type, unsigned char *key,
-					uint8_t type, int length)
-{
-	char filename[PATH_MAX + 1], addr[20], str[38];
-	int i;
-
-	memset(str, 0, sizeof(str));
-	for (i = 0; i < 16; i++)
-		sprintf(str + (i * 2), "%2.2X", key[i]);
-	sprintf(str + 32, " %d %d", type, length);
-
-	create_filename(filename, PATH_MAX, local, "linkkeys");
-
-	create_file(filename, S_IRUSR | S_IWUSR);
-
-	ba2str(peer, addr);
-	sprintf(&addr[17], "#%hhu", peer_type);
-
-	if (length < 0) {
-		char *tmp = textfile_get(filename, addr);
-		if (tmp) {
-			if (strlen(tmp) > 34)
-				memcpy(str + 34, tmp + 34, 3);
-			free(tmp);
-		}
-	}
-
-	return textfile_put(filename, addr, str);
-}
-
-int read_link_key(const bdaddr_t *local, const bdaddr_t *peer,
-					uint8_t peer_type, unsigned char *key,
-					uint8_t *type)
-{
-	char filename[PATH_MAX + 1], addr[20], tmp[3], *str;
-	int i;
-
-	create_filename(filename, PATH_MAX, local, "linkkeys");
-
-	ba2str(peer, addr);
-	sprintf(&addr[17], "#%hhu", peer_type);
-
-	str = textfile_get(filename, addr);
-	if (str != NULL)
-		goto done;
-
-	/* Try old format (address only) */
-	addr[17] = '\0';
-
-	str = textfile_get(filename, addr);
-	if (!str)
-		return -ENOENT;
-
-done:
-	if (!key) {
-		free(str);
-		return 0;
-	}
-
-	memset(tmp, 0, sizeof(tmp));
-	for (i = 0; i < 16; i++) {
-		memcpy(tmp, str + (i * 2), 2);
-		key[i] = (uint8_t) strtol(tmp, NULL, 16);
-	}
-
-	if (type) {
-		memcpy(tmp, str + 33, 2);
-		*type = (uint8_t) strtol(tmp, NULL, 10);
-	}
-
-	free(str);
-
-	return 0;
-}
-
 ssize_t read_pin_code(const bdaddr_t *local, const bdaddr_t *peer, char *pin)
 {
 	char filename[PATH_MAX + 1], addr[18], *str;
@@ -567,49 +263,6 @@ ssize_t read_pin_code(const bdaddr_t *local, const bdaddr_t *peer, char *pin)
 	return len;
 }
 
-int write_trust(const char *src, const char *addr, uint8_t addr_type,
-							gboolean trust)
-{
-	char filename[PATH_MAX + 1], key[20];
-
-	create_name(filename, PATH_MAX, STORAGEDIR, src, "trusts");
-
-	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-
-	snprintf(key, sizeof(key), "%17s#%hhu", addr, addr_type);
-
-	if (trust == FALSE)
-		return textfile_casedel(filename, key);
-
-	return textfile_caseput(filename, key, GLOBAL_TRUST);
-}
-
-gboolean read_trust(const bdaddr_t *local, const char *addr, uint8_t addr_type)
-{
-	char filename[PATH_MAX + 1], key[20], *str;
-	gboolean ret;
-
-	create_filename(filename, PATH_MAX, local, "trusts");
-
-	snprintf(key, sizeof(key), "%17s#%hhu", addr, addr_type);
-
-	str = textfile_caseget(filename, key);
-	if (str == NULL)
-		/* Try old format (address only) */
-		str = textfile_caseget(filename, addr);
-
-	if (str == NULL)
-		return FALSE;
-
-	if (strcmp(str, GLOBAL_TRUST) == 0)
-		ret = TRUE;
-	else
-		ret = FALSE;
-
-	free(str);
-	return ret;
-}
-
 int write_device_profiles(const bdaddr_t *src, const bdaddr_t *dst,
 					uint8_t dst_type, const char *profiles)
 {
@@ -847,167 +500,6 @@ sdp_record_t *find_record_in_list(sdp_list_t *recs, const char *uuid)
 	return NULL;
 }
 
-int store_device_id(const gchar *src, const gchar *dst, uint8_t dst_type,
-				const uint16_t source, const uint16_t vendor,
-				const uint16_t product, const uint16_t version)
-{
-	char filename[PATH_MAX + 1], key[20], str[20];
-
-	create_name(filename, PATH_MAX, STORAGEDIR, src, "did");
-
-	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-
-	snprintf(key, sizeof(key), "%17s#%hhu", dst, dst_type);
-
-	snprintf(str, sizeof(str), "%04X %04X %04X %04X", source,
-						vendor, product, version);
-
-	return textfile_put(filename, key, str);
-}
-
-static int read_device_id_from_did(const gchar *src, const gchar *dst,
-				   uint8_t dst_type, uint16_t *source,
-				   uint16_t *vendor, uint16_t *product,
-							uint16_t *version)
-{
-	char filename[PATH_MAX + 1];
-	char key[20], *str, *vendor_str, *product_str, *version_str;
-
-	create_name(filename, PATH_MAX, STORAGEDIR, src, "did");
-
-	snprintf(key, sizeof(key), "%17s#%hhu", dst, dst_type);
-
-	str = textfile_get(filename, key);
-	if (str != NULL)
-		goto done;
-
-	/* Try old format (address only) */
-	str = textfile_get(filename, dst);
-	if (!str)
-		return -ENOENT;
-
-done:
-	vendor_str = strchr(str, ' ');
-	if (!vendor_str) {
-		free(str);
-		return -ENOENT;
-	}
-	*(vendor_str++) = 0;
-
-	product_str = strchr(vendor_str, ' ');
-	if (!product_str) {
-		free(str);
-		return -ENOENT;
-	}
-	*(product_str++) = 0;
-
-	version_str = strchr(product_str, ' ');
-	if (!version_str) {
-		free(str);
-		return -ENOENT;
-	}
-	*(version_str++) = 0;
-
-	if (source)
-		*source = (uint16_t) strtol(str, NULL, 16);
-	if (vendor)
-		*vendor = (uint16_t) strtol(vendor_str, NULL, 16);
-	if (product)
-		*product = (uint16_t) strtol(product_str, NULL, 16);
-	if (version)
-		*version = (uint16_t) strtol(version_str, NULL, 16);
-
-	free(str);
-
-	return 0;
-}
-
-int read_device_id(const gchar *srcaddr, const gchar *dstaddr,
-		   uint8_t dst_type, uint16_t *source, uint16_t *vendor,
-					uint16_t *product, uint16_t *version)
-{
-	uint16_t lsource, lvendor, lproduct, lversion;
-	sdp_list_t *recs;
-	sdp_record_t *rec;
-	bdaddr_t src, dst;
-	int err;
-
-	err = read_device_id_from_did(srcaddr, dstaddr, dst_type, &lsource,
-								vendor, product,
-								version);
-	if (!err) {
-		if (lsource == 0xffff)
-			err = -ENOENT;
-
-		return err;
-	}
-
-	str2ba(srcaddr, &src);
-	str2ba(dstaddr, &dst);
-
-	recs = read_records(&src, &dst);
-	rec = find_record_in_list(recs, PNP_UUID);
-
-	if (rec) {
-		sdp_data_t *pdlist;
-
-		pdlist = sdp_data_get(rec, SDP_ATTR_VENDOR_ID_SOURCE);
-		lsource = pdlist ? pdlist->val.uint16 : 0x0000;
-
-		pdlist = sdp_data_get(rec, SDP_ATTR_VENDOR_ID);
-		lvendor = pdlist ? pdlist->val.uint16 : 0x0000;
-
-		pdlist = sdp_data_get(rec, SDP_ATTR_PRODUCT_ID);
-		lproduct = pdlist ? pdlist->val.uint16 : 0x0000;
-
-		pdlist = sdp_data_get(rec, SDP_ATTR_VERSION);
-		lversion = pdlist ? pdlist->val.uint16 : 0x0000;
-
-		err = 0;
-	}
-
-	sdp_list_free(recs, (sdp_free_func_t)sdp_record_free);
-
-	if (err) {
-		/* FIXME: We should try EIR data if we have it, too */
-
-		/* If we don't have the data, we don't want to go through the
-		 * above search every time. */
-		lsource = 0xffff;
-		lvendor = 0x0000;
-		lproduct = 0x0000;
-		lversion = 0x0000;
-	}
-
-	store_device_id(srcaddr, dstaddr, dst_type, lsource, lvendor,
-							lproduct, lversion);
-
-	if (err)
-		return err;
-
-	if (source)
-		*source = lsource;
-	if (vendor)
-		*vendor = lvendor;
-	if (product)
-		*product = lproduct;
-	if (version)
-		*version = lversion;
-
-	return 0;
-}
-
-int write_device_pairable(const bdaddr_t *bdaddr, gboolean mode)
-{
-	char filename[PATH_MAX + 1];
-
-	create_filename(filename, PATH_MAX, bdaddr, "config");
-
-	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-
-	return textfile_put(filename, "pairable", mode ? "yes" : "no");
-}
-
 int read_device_pairable(const bdaddr_t *bdaddr, gboolean *mode)
 {
 	char filename[PATH_MAX + 1], *str;
@@ -1025,51 +517,6 @@ int read_device_pairable(const bdaddr_t *bdaddr, gboolean *mode)
 	return 0;
 }
 
-gboolean read_blocked(const bdaddr_t *local, const bdaddr_t *remote,
-							uint8_t remote_type)
-{
-	char filename[PATH_MAX + 1], *str, key[20];
-
-	create_filename(filename, PATH_MAX, local, "blocked");
-
-	ba2str(remote, key);
-	sprintf(&key[17], "#%hhu", remote_type);
-
-	str = textfile_caseget(filename, key);
-	if (str != NULL)
-		goto done;
-
-	/* Try old format (address only) */
-	key[17] = '\0';
-
-	str = textfile_caseget(filename, key);
-	if (str == NULL)
-		return FALSE;
-
-done:
-	free(str);
-
-	return TRUE;
-}
-
-int write_blocked(const bdaddr_t *local, const bdaddr_t *remote,
-				uint8_t remote_type, gboolean blocked)
-{
-	char filename[PATH_MAX + 1], key[20];
-
-	create_filename(filename, PATH_MAX, local, "blocked");
-
-	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-
-	ba2str(remote, key);
-	sprintf(&key[17], "#%hhu", remote_type);
-
-	if (blocked == FALSE)
-		return textfile_casedel(filename, key);
-
-	return textfile_caseput(filename, key, "");
-}
-
 int write_device_services(const bdaddr_t *sba, const bdaddr_t *dba,
 			  uint8_t bdaddr_type, const char *services)
 {
@@ -1265,40 +712,3 @@ void delete_device_ccc(const bdaddr_t *local, const bdaddr_t *peer)
 	create_filename(filename, PATH_MAX, local, "ccc");
 	delete_by_pattern(filename, addr);
 }
-
-int write_longtermkeys(const bdaddr_t *local, const bdaddr_t *peer,
-					uint8_t bdaddr_type, const char *key)
-{
-	char filename[PATH_MAX + 1], addr[20];
-
-	if (!key)
-		return -EINVAL;
-
-	create_filename(filename, PATH_MAX, local, "longtermkeys");
-
-	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-
-	ba2str(peer, addr);
-	sprintf(&addr[17], "#%hhu", bdaddr_type);
-
-	return textfile_put(filename, addr, key);
-}
-
-gboolean has_longtermkeys(const bdaddr_t *local, const bdaddr_t *peer,
-							uint8_t bdaddr_type)
-{
-	char filename[PATH_MAX + 1], key[20], *str;
-
-	create_filename(filename, PATH_MAX, local, "longtermkeys");
-
-	ba2str(peer, key);
-	sprintf(&key[17], "#%hhu", bdaddr_type);
-
-	str = textfile_caseget(filename, key);
-	if (str) {
-		free(str);
-		return TRUE;
-	}
-
-	return FALSE;
-}
diff --git a/src/storage.h b/src/storage.h
index e334828..c8ae6b0 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -23,47 +23,19 @@
 
 #include "textfile.h"
 
-int read_device_alias(const char *src, const char *dst, uint8_t dst_type,
-						char *alias, size_t size);
-int write_device_alias(const char *src, const char *dst, uint8_t dst_type,
-							const char *alias);
-int write_discoverable_timeout(const bdaddr_t *bdaddr, int timeout);
 int read_discoverable_timeout(const char *src, int *timeout);
-int write_pairable_timeout(const bdaddr_t *bdaddr, int timeout);
 int read_pairable_timeout(const char *src, int *timeout);
-int write_device_mode(const bdaddr_t *bdaddr, const char *mode);
 int read_device_mode(const char *src, char *mode, int length);
 int read_on_mode(const char *src, char *mode, int length);
-int write_local_name(const bdaddr_t *bdaddr, const char *name);
 int read_local_name(const bdaddr_t *bdaddr, char *name);
-int write_local_class(const bdaddr_t *bdaddr, uint8_t *class);
 int read_local_class(const bdaddr_t *bdaddr, uint8_t *class);
 int write_remote_appearance(const bdaddr_t *local, const bdaddr_t *peer,
 				uint8_t bdaddr_type, uint16_t appearance);
 int read_remote_appearance(const bdaddr_t *local, const bdaddr_t *peer,
 				uint8_t bdaddr_type, uint16_t *appearance);
-int write_remote_class(const bdaddr_t *local, const bdaddr_t *peer,
-							uint32_t class);
-int read_remote_class(const bdaddr_t *local, const bdaddr_t *peer,
-							uint32_t *class);
-int write_device_name(const bdaddr_t *local, const bdaddr_t *peer,
-					uint8_t peer_type, const char *name);
-int read_device_name(const char *src, const char *dst, uint8_t dst_type,
-								char *name);
-int write_lastseen_info(const bdaddr_t *local, const bdaddr_t *peer,
-					uint8_t peer_type, struct tm *tm);
 int write_lastused_info(const bdaddr_t *local, const bdaddr_t *peer,
 					uint8_t peer_type, struct tm *tm);
-int write_link_key(const bdaddr_t *local, const bdaddr_t *peer,
-					uint8_t peer_type, unsigned char *key,
-					uint8_t type, int length);
-int read_link_key(const bdaddr_t *local, const bdaddr_t *peer,
-			uint8_t peer_type, unsigned char *key, uint8_t *type);
 ssize_t read_pin_code(const bdaddr_t *local, const bdaddr_t *peer, char *pin);
-gboolean read_trust(const bdaddr_t *local, const char *addr,
-						uint8_t addr_type);
-int write_trust(const char *src, const char *addr, uint8_t addr_type,
-							gboolean trust);
 int write_device_profiles(const bdaddr_t *src, const bdaddr_t *dst,
 				uint8_t dst_type, const char *profiles);
 int delete_entry(const bdaddr_t *src, const char *storage, const bdaddr_t *dst,
@@ -79,18 +51,7 @@ void delete_all_records(const bdaddr_t *src, const bdaddr_t *dst,
 							uint8_t dst_type);
 sdp_list_t *read_records(const bdaddr_t *src, const bdaddr_t *dst);
 sdp_record_t *find_record_in_list(sdp_list_t *recs, const char *uuid);
-int store_device_id(const gchar *src, const gchar *dst, uint8_t dst_type,
-				const uint16_t source, const uint16_t vendor,
-				const uint16_t product, const uint16_t version);
-int read_device_id(const gchar *src, const gchar *dst, uint8_t dst_type,
-					uint16_t *source, uint16_t *vendor,
-					uint16_t *product, uint16_t *version);
-int write_device_pairable(const bdaddr_t *local, gboolean mode);
 int read_device_pairable(const bdaddr_t *local, gboolean *mode);
-gboolean read_blocked(const bdaddr_t *local, const bdaddr_t *remote,
-							uint8_t remote_type);
-int write_blocked(const bdaddr_t *local, const bdaddr_t *remote,
-				uint8_t remote_type, gboolean blocked);
 int write_device_services(const bdaddr_t *sba, const bdaddr_t *dba,
 				uint8_t bdaddr_type, const char *services);
 int delete_device_service(const bdaddr_t *sba, const bdaddr_t *dba,
@@ -112,7 +73,3 @@ int write_device_ccc(const bdaddr_t *local, const bdaddr_t *peer,
 					uint8_t bdaddr_type, uint16_t handle,
 					uint16_t value);
 void delete_device_ccc(const bdaddr_t *local, const bdaddr_t *peer);
-int write_longtermkeys(const bdaddr_t *local, const bdaddr_t *peer,
-					uint8_t bdaddr_type, const char *key);
-gboolean has_longtermkeys(const bdaddr_t *local, const bdaddr_t *peer,
-							uint8_t bdaddr_type);
-- 
1.7.9.5


^ permalink raw reply related

* Re: [PATCH] storage: Remove not used functions
From: Johan Hedberg @ 2012-12-12  8:57 UTC (permalink / raw)
  To: Frédéric Danis; +Cc: linux-bluetooth
In-Reply-To: <1355301688-30095-1-git-send-email-frederic.danis@linux.intel.com>

Hi Frédéric,

On Wed, Dec 12, 2012, Frédéric Danis wrote:
> Those functions are no more used with new storage architecture.
> ---
>  src/storage.c |  590 ---------------------------------------------------------
>  src/storage.h |   43 -----
>  2 files changed, 633 deletions(-)

Applied. Thanks.

Johan

^ permalink raw reply

* RE: [BLE] org.bluez.Device1.Connect() returns org.bluez.Error.NotAvailable
From: Ting Chou @ 2012-12-12  9:10 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <20121212075201.GA14256@x220>

Hello Johan,

> -----Original Message-----
> From: Johan Hedberg [mailto:johan.hedberg@gmail.com]
> Sent: Wednesday, December 12, 2012 3:52 PM
> To: Ting Chou
> Cc: linux-bluetooth@vger.kernel.org
> Subject: Re: [BLE] org.bluez.Device1.Connect() returns
> org.bluez.Error.NotAvailable
> 
> Hi Ting,
> 
> On Wed, Dec 12, 2012, Ting Chou wrote:
> > I Found
> > -------
> >
> > - I checked /var/log/syslog and src/device.c, and found
> connect_profiles() is
> >   called twice at the first time calling org.bluez.Device.Connect():
> >
> >   - 1st time
> >     dev->svc_resolved==FALSE, device_resolve_svc() is invoked.
> >
> >   - 2nd time
> >     dev->svc_resolved==TRUE
> >     In the for loop of iterating device profiles, there're two
> profiles:
> >
> >       a) p->auto_connect==FALSE, p->name==deviceinfo, p-
> >local_uuid==NULL
> >       b) p->auto_connect==FALSE, p->name==Health Thermometer GATT
> > driver, p->local_uuid==NULL
> >
> >     Since none of them have auto_connect TRUE, dev->pending==NULL,
> and
> >     btd_error_not_available() is called.
> >
> > - I tried org.bluez.Device1.ConnectProfile() as well, but since all
> the profiles
> >   have local_uuid NULL, find_connectable_profile() return NULL and
> >   btd_error_invalid_args() is called.
> 
> It's not actually local_uuid that is so important but that p->connect
> is set. Also, it'd make much more sense to pass the remote UUID to
> ConnectProfile than the local one and we'll still do this change before
> releasing 5.0. The main thing that needs to be done before that is to
> convert profile->remote_uuids list to a single profile->remote_uuid
> which is a bit of work since some profiles still declare multiple UUIDs.
> 
> So far no LE profile is hooked up to Device.Connect and I'm not sure
> exactly how that should be done since LE device are connected through
> the general connection establishment procedure which requires scanning
> first. Since we already have Device.Pair doing the same as
> CreatePairedDevice in BlueZ 4 (and this should work btw, did you try
> it?) maybe Device.Connect should be roughly the same for LE devices as
> Adapter.CreateDevice is in BlueZ 4? For BR/EDR devices it already
> serves this purpose. The main question is what should be done if
> Device.Connect is called subsequent times as bluetoothd should anyway
> already be doing passive scanning and trying to connect to devices that
> have supported profiles.
> 
> Johan

I tried Device.Pair, it does connect to the LE device like the first call to
Device.Connect, but:

- I can't unpair the device (CancelPairing can't do this).

- If I Device.Disconnect after Device.Pair, then I can't connect to the device
  again by either Device.Connect or Device.Pair:
  - Device1.Connect
    Error org.bluez.Error.NotAvailable: Operation currently not available
  - Device1.Pair
    Error org.bluez.Error.AlreadyExists: Already Exists

I still can't connect to the LE device once I disconnect it.

Thanks,
Ting

^ permalink raw reply

* Re: [BLE] org.bluez.Device1.Connect() returns org.bluez.Error.NotAvailable
From: Johan Hedberg @ 2012-12-12  9:25 UTC (permalink / raw)
  To: Ting Chou; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <ADCBF04BB97EBF4AAE65663F8478B61CA99E65ABCC@Luna.iaSolution.net>

Hi Ting,

On Wed, Dec 12, 2012, Ting Chou wrote:
> I tried Device.Pair, it does connect to the LE device like the first call to
> Device.Connect, but:
> 
> - I can't unpair the device (CancelPairing can't do this).

There's no "unpair" method. You'd need to call Adapter.RemoveDevice to
do it.

> - If I Device.Disconnect after Device.Pair, then I can't connect to the device
>   again by either Device.Connect or Device.Pair:
>   - Device1.Connect
>     Error org.bluez.Error.NotAvailable: Operation currently not available
>   - Device1.Pair
>     Error org.bluez.Error.AlreadyExists: Already Exists
> 
> I still can't connect to the LE device once I disconnect it.

That means that the profiles that are supposed to be supported with this
device are not calling either device_set_auto_connect() or
btd_device_add_attio_callback(). Both of those functions should cause
bluetoothd to start doing passive scanning and try to connect to the
device. Btw, which kernel version are you using. IIRC you'll need
something like 3.5 or newer for LE passive scanning to work.

Johan

^ permalink raw reply

* RE: [BLE] org.bluez.Device1.Connect() returns org.bluez.Error.NotAvailable
From: Ting Chou @ 2012-12-12  9:47 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <20121212092537.GA5371@x220>

Hello Johan,

> -----Original Message-----
> From: Johan Hedberg [mailto:johan.hedberg@gmail.com]
> Sent: Wednesday, December 12, 2012 5:26 PM
> To: Ting Chou
> Cc: linux-bluetooth@vger.kernel.org
> Subject: Re: [BLE] org.bluez.Device1.Connect() returns
> org.bluez.Error.NotAvailable
> 
> Hi Ting,
> 
> On Wed, Dec 12, 2012, Ting Chou wrote:
> > I tried Device.Pair, it does connect to the LE device like the first
> > call to Device.Connect, but:
> >
> > - I can't unpair the device (CancelPairing can't do this).
> 
> There's no "unpair" method. You'd need to call Adapter.RemoveDevice to
> do it.
> 
> > - If I Device.Disconnect after Device.Pair, then I can't connect to
> the device
> >   again by either Device.Connect or Device.Pair:
> >   - Device1.Connect
> >     Error org.bluez.Error.NotAvailable: Operation currently not
> available
> >   - Device1.Pair
> >     Error org.bluez.Error.AlreadyExists: Already Exists
> >
> > I still can't connect to the LE device once I disconnect it.
> 
> That means that the profiles that are supposed to be supported with
> this device are not calling either device_set_auto_connect() or
> btd_device_add_attio_callback(). Both of those functions should cause
> bluetoothd to start doing passive scanning and try to connect to the
> device. Btw, which kernel version are you using. IIRC you'll need
> something like 3.5 or newer for LE passive scanning to work.
> 

I tried to let btd_device_add_attio_callback() get called by

  Characterisitc.DiscoverCharacteristics()

But still the Device1.Connect() after Device1.Disconnect() does not establish
the connection. connect_profiles() returns btd_error_not_available() since
!dev->pending:

  ting@user-OptiPlex-755:~/w/bluez$ sudo dbus-send --system --dest=org.bluez --type=method_call --print-reply /org/bluez/hci0/dev_00_07_80_4C_5F_17 org.bluez.Device1.Connect
  Error org.bluez.Error.NotAvailable: Operation currently not available

  ting@user-OptiPlex-755:~/w/bluez$ sudo dbus-send --system --dest=org.bluez --type=method_call --print-reply /org/bluez/hci0/dev_00_07_80_4C_5F_17/service000d  org.bluez.Characteristic.DiscoverCharacteristics
  method return sender=:1.1992 -> dest=:1.1997 reply_serial=2
     array [
        object path "/org/bluez/hci0/dev_00_07_80_4C_5F_17/service000d/characteristic000f"
     ]

  ting@user-OptiPlex-755:~/w/bluez$ sudo dbus-send --system --dest=org.bluez --type=method_call --print-reply /org/bluez/hci0/dev_00_07_80_4C_5F_17 org.bluez.Device1.Disconnect
  method return sender=:1.1992 -> dest=:1.1998 reply_serial=2

  ting@user-OptiPlex-755:~/w/bluez$ sudo dbus-send --system --dest=org.bluez --type=method_call --print-reply /org/bluez/hci0/dev_00_07_80_4C_5F_17 org.bluez.Device1.Connect
  Error org.bluez.Error.NotAvailable: Operation currently not available

The kernel I'm using:

  ting@user-OptiPlex-755:~/w/bluez$ uname -a
  Linux user-OptiPlex-755 3.6.6-030606-generic #201211050512 SMP Mon Nov 5 10:20:03 UTC 2012 i686 i686 i686 GNU/Linux

Thank you,
Ting

^ permalink raw reply

* Re: [BLE] org.bluez.Device1.Connect() returns org.bluez.Error.NotAvailable
From: Johan Hedberg @ 2012-12-12 10:07 UTC (permalink / raw)
  To: Ting Chou; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <ADCBF04BB97EBF4AAE65663F8478B61CA99E65ABDA@Luna.iaSolution.net>

Hi Ting,

On Wed, Dec 12, 2012, Ting Chou wrote:
> > That means that the profiles that are supposed to be supported with
> > this device are not calling either device_set_auto_connect() or
> > btd_device_add_attio_callback(). Both of those functions should cause
> > bluetoothd to start doing passive scanning and try to connect to the
> > device. Btw, which kernel version are you using. IIRC you'll need
> > something like 3.5 or newer for LE passive scanning to work.
> > 
> 
> I tried to let btd_device_add_attio_callback() get called by
> 
>   Characterisitc.DiscoverCharacteristics()

I thought you said some internally supported profiles get detected? Why
then do you need to use the ATT D-Bus interface? FWIW, since
attrib/client.c implementation doesn't match what's documented and since
there hasn't been anyone stepping up to update the code to use D-Bus
properties we'll probably not have the entire Characteristic D-Bus
interface in the 5.0 release. Instead, there's a plan to have a more
comprehensive and generic GATT D-Bus API for both peripheral and central
roles, which will probably land in 5.1 or one of the subsequent
releases.

> But still the Device1.Connect() after Device1.Disconnect() does not establish
> the connection. connect_profiles() returns btd_error_not_available() since
> !dev->pending:

It seems you've misunderstood this part. If the functions I mentioned
are used correctly you will not need to use Device.Connect at all.
Instead bluetoothd will start doing passive scanning and automatically
establish a connection to any device doing connectable advertising.

Johan

^ permalink raw reply

* RE: [BLE] org.bluez.Device1.Connect() returns org.bluez.Error.NotAvailable
From: Ting Chou @ 2012-12-12 10:21 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <20121212100737.GA6620@x220>

Hello Johan,

> -----Original Message-----
> From: Johan Hedberg [mailto:johan.hedberg@gmail.com]
> Sent: Wednesday, December 12, 2012 6:08 PM
> To: Ting Chou
> Cc: linux-bluetooth@vger.kernel.org
> Subject: Re: [BLE] org.bluez.Device1.Connect() returns
> org.bluez.Error.NotAvailable
> 
> Hi Ting,
> 
> On Wed, Dec 12, 2012, Ting Chou wrote:
> > > That means that the profiles that are supposed to be supported with
> > > this device are not calling either device_set_auto_connect() or
> > > btd_device_add_attio_callback(). Both of those functions should
> > > cause bluetoothd to start doing passive scanning and try to connect
> > > to the device. Btw, which kernel version are you using. IIRC you'll
> > > need something like 3.5 or newer for LE passive scanning to work.
> > >
> >
> > I tried to let btd_device_add_attio_callback() get called by
> >
> >   Characterisitc.DiscoverCharacteristics()
> 
> I thought you said some internally supported profiles get detected? Why
> then do you need to use the ATT D-Bus interface? FWIW, since
> attrib/client.c implementation doesn't match what's documented and
> since there hasn't been anyone stepping up to update the code to use D-
> Bus properties we'll probably not have the entire Characteristic D-Bus
> interface in the 5.0 release. Instead, there's a plan to have a more
> comprehensive and generic GATT D-Bus API for both peripheral and
> central roles, which will probably land in 5.1 or one of the subsequent
> releases.
> 
> > But still the Device1.Connect() after Device1.Disconnect() does not
> > establish the connection. connect_profiles() returns
> > btd_error_not_available() since
> > !dev->pending:
> 
> It seems you've misunderstood this part. If the functions I mentioned
> are used correctly you will not need to use Device.Connect at all.
> Instead bluetoothd will start doing passive scanning and automatically
> establish a connection to any device doing connectable advertising.
> 

Do you mean once a LE device with internally supported profiles is discovered,
it will be connected automatically? Which means I cannot connect manually, at
the timing I prefer?

Since with my BT 4.0 dongle, Adpater.StartDiscovery discover also LE devices, I
thought I should use Device.Connect to connect to the device.

Thanks,
Ting


^ permalink raw reply

* [PATCH 00/16] audio: Use device/adapter reference instead of bdaddr_t
From: Szymon Janc @ 2012-12-12 10:27 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

This remove use of bdaddr_t in favour of using references to struct btd_adapter
and struct btd_device.

note:
This patch triggers a bug introduced when a2dp was splitted into two
btd_profile resulting in a2dp_unregister() is never called (so adapter
ref is not dropped properly). This is not fixed in this patch set.

Szymon Janc (16):
  a2dp: Remove bogus '\' at the end of line
  a2dp: Remove useless return
  a2dp: Remove not used macros definitions
  a2dp: Convert sink/source register to accept btd_adapter
  a2dp: Convert a2dp_unregister to accept btd_adapter
  media: Convert register/unregister to accept btd_adapter
  a2dp: Convert a2dp_add_sep to accept struct btd_adapter
  avdtp: Use refs to adapter and device instead of bdaddr_t
  a2dp: Use btd_adapter ref in a2dp_server instead of bdaddr_t
  avrcp: Convert to accept btd_adapter instead of bdaddr_t
  avctp: Convert register/unregister to accept btd_adapter
  avdtp: Replace avdtp_get_peers with adapter and device getters
  audio: Use manager_get_device to get device object
  audio: Make manager_get_device accept btd_device
  audio: Simplify manager_find_device
  avctp: Remove double looking for audio device

 profiles/audio/a2dp.c    |  75 +++++++++++---------------
 profiles/audio/a2dp.h    |   8 +--
 profiles/audio/avctp.c   |  96 +++++++++++++++-------------------
 profiles/audio/avctp.h   |   4 +-
 profiles/audio/avdtp.c   | 119 ++++++++++++++++++------------------------
 profiles/audio/avdtp.h   |  10 ++--
 profiles/audio/avrcp.c   |  37 ++++++-------
 profiles/audio/avrcp.h   |   6 +--
 profiles/audio/manager.c | 133 +++++++++--------------------------------------
 profiles/audio/manager.h |  17 +-----
 profiles/audio/media.c   |  35 ++++++-------
 profiles/audio/media.h   |   4 +-
 profiles/audio/sink.c    |   5 +-
 profiles/audio/source.c  |   5 +-
 14 files changed, 206 insertions(+), 348 deletions(-)

-- 
1.8.0


^ permalink raw reply

* [PATCH 01/16] a2dp: Remove bogus '\' at the end of line
From: Szymon Janc @ 2012-12-12 10:27 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>

---
 profiles/audio/a2dp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index 177f653..8e9f626 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -1337,7 +1337,7 @@ struct a2dp_sep *a2dp_add_sep(const bdaddr_t *src, uint8_t type,
 	}
 
 	if (add_record_to_server(&server->src, record) < 0) {
-		error("Unable to register A2DP service record");\
+		error("Unable to register A2DP service record");
 		sdp_record_free(record);
 		avdtp_unregister_sep(sep->lsep);
 		g_free(sep);
-- 
1.8.0


^ permalink raw reply related

* [PATCH 02/16] a2dp: Remove useless return
From: Szymon Janc @ 2012-12-12 10:27 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>

This code does nothing.
---
 profiles/audio/a2dp.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index 8e9f626..aef998a 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -1257,9 +1257,6 @@ void a2dp_unregister(const bdaddr_t *src)
 		remove_record_from_server(server->sink_record_id);
 
 	g_free(server);
-
-	if (servers)
-		return;
 }
 
 struct a2dp_sep *a2dp_add_sep(const bdaddr_t *src, uint8_t type,
-- 
1.8.0


^ permalink raw reply related

* [PATCH 03/16] a2dp: Remove not used macros definitions
From: Szymon Janc @ 2012-12-12 10:27 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>

MIN and MAX macros are not used.
---
 profiles/audio/a2dp.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index aef998a..ac5c513 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -52,14 +52,6 @@
 #define SUSPEND_TIMEOUT 5
 #define RECONFIGURE_TIMEOUT 500
 
-#ifndef MIN
-# define MIN(x, y) ((x) < (y) ? (x) : (y))
-#endif
-
-#ifndef MAX
-# define MAX(x, y) ((x) > (y) ? (x) : (y))
-#endif
-
 struct a2dp_sep {
 	struct a2dp_server *server;
 	struct a2dp_endpoint *endpoint;
-- 
1.8.0


^ permalink raw reply related

* [PATCH 04/16] a2dp: Convert sink/source register to accept btd_adapter
From: Szymon Janc @ 2012-12-12 10:27 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>

Pass btd_adapter directly or use getters to get needed data from
adapter object.
---
 profiles/audio/a2dp.c    | 14 ++++++++------
 profiles/audio/a2dp.h    |  4 ++--
 profiles/audio/manager.c |  4 ++--
 profiles/audio/sink.c    |  5 +++--
 profiles/audio/source.c  |  5 +++--
 5 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index ac5c513..eeecb43 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -37,6 +37,8 @@
 #include <bluetooth/sdp.h>
 #include <bluetooth/sdp_lib.h>
 
+#include "../src/adapter.h"
+
 #include "log.h"
 #include "device.h"
 #include "manager.h"
@@ -1179,15 +1181,15 @@ static struct a2dp_server *a2dp_server_register(const bdaddr_t *src,
 	return server;
 }
 
-int a2dp_source_register(const bdaddr_t *src, GKeyFile *config)
+int a2dp_source_register(struct btd_adapter *adapter, GKeyFile *config)
 {
 	struct a2dp_server *server;
 
-	server = find_server(servers, src);
+	server = find_server(servers, adapter_get_address(adapter));
 	if (server != NULL)
 		goto done;
 
-	server = a2dp_server_register(src, config);
+	server = a2dp_server_register(adapter_get_address(adapter), config);
 	if (server == NULL)
 		return -EPROTONOSUPPORT;
 
@@ -1197,15 +1199,15 @@ done:
 	return 0;
 }
 
-int a2dp_sink_register(const bdaddr_t *src, GKeyFile *config)
+int a2dp_sink_register(struct btd_adapter *adapter, GKeyFile *config)
 {
 	struct a2dp_server *server;
 
-	server = find_server(servers, src);
+	server = find_server(servers, adapter_get_address(adapter));
 	if (server != NULL)
 		goto done;
 
-	server = a2dp_server_register(src, config);
+	server = a2dp_server_register(adapter_get_address(adapter), config);
 	if (server == NULL)
 		return -EPROTONOSUPPORT;
 
diff --git a/profiles/audio/a2dp.h b/profiles/audio/a2dp.h
index ded1060..827d5cc 100644
--- a/profiles/audio/a2dp.h
+++ b/profiles/audio/a2dp.h
@@ -64,8 +64,8 @@ typedef void (*a2dp_stream_cb_t) (struct avdtp *session,
 					struct avdtp_error *err,
 					void *user_data);
 
-int a2dp_source_register(const bdaddr_t *src, GKeyFile *config);
-int a2dp_sink_register(const bdaddr_t *src, GKeyFile *config);
+int a2dp_source_register(struct btd_adapter *adapter, GKeyFile *config);
+int a2dp_sink_register(struct btd_adapter *adapter, GKeyFile *config);
 void a2dp_unregister(const bdaddr_t *src);
 
 struct a2dp_sep *a2dp_add_sep(const bdaddr_t *src, uint8_t type,
diff --git a/profiles/audio/manager.c b/profiles/audio/manager.c
index 7025868..b355281 100644
--- a/profiles/audio/manager.c
+++ b/profiles/audio/manager.c
@@ -351,7 +351,7 @@ static int a2dp_source_server_probe(struct btd_profile *p,
 
 	audio_adapter_unref(adp); /* Referenced by a2dp server */
 
-	return a2dp_source_register(adapter_get_address(adapter), config);
+	return a2dp_source_register(adapter, config);
 }
 
 static int a2dp_sink_server_probe(struct btd_profile *p,
@@ -368,7 +368,7 @@ static int a2dp_sink_server_probe(struct btd_profile *p,
 
 	audio_adapter_unref(adp); /* Referenced by a2dp server */
 
-	return a2dp_sink_register(adapter_get_address(adapter), config);
+	return a2dp_sink_register(adapter, config);
 }
 
 static int avrcp_server_probe(struct btd_profile *p,
diff --git a/profiles/audio/sink.c b/profiles/audio/sink.c
index 62ec601..a3d9b1f 100644
--- a/profiles/audio/sink.c
+++ b/profiles/audio/sink.c
@@ -39,6 +39,9 @@
 
 #include "log.h"
 
+#include "../src/adapter.h"
+#include "../src/device.h"
+
 #include "device.h"
 #include "avdtp.h"
 #include "media.h"
@@ -46,8 +49,6 @@
 #include "error.h"
 #include "sink.h"
 #include "dbus-common.h"
-#include "../src/adapter.h"
-#include "../src/device.h"
 
 #define STREAM_SETUP_RETRY_TIMER 2
 
diff --git a/profiles/audio/source.c b/profiles/audio/source.c
index ef6cf7a..efd6946 100644
--- a/profiles/audio/source.c
+++ b/profiles/audio/source.c
@@ -40,6 +40,9 @@
 
 #include "log.h"
 
+#include "../src/adapter.h"
+#include "../src/device.h"
+
 #include "device.h"
 #include "avdtp.h"
 #include "media.h"
@@ -48,8 +51,6 @@
 #include "manager.h"
 #include "source.h"
 #include "dbus-common.h"
-#include "../src/adapter.h"
-#include "../src/device.h"
 
 #define STREAM_SETUP_RETRY_TIMER 2
 
-- 
1.8.0


^ permalink raw reply related

* [PATCH 05/16] a2dp: Convert a2dp_unregister to accept btd_adapter
From: Szymon Janc @ 2012-12-12 10:27 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>

Pass btd_adapter directly or use getters to get needed data from
adapter object.
---
 profiles/audio/a2dp.c | 6 +++---
 profiles/audio/a2dp.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index eeecb43..c145ca4 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -1228,11 +1228,11 @@ static void a2dp_unregister_sep(struct a2dp_sep *sep)
 	g_free(sep);
 }
 
-void a2dp_unregister(const bdaddr_t *src)
+void a2dp_unregister(struct btd_adapter *adapter)
 {
 	struct a2dp_server *server;
 
-	server = find_server(servers, src);
+	server = find_server(servers, adapter_get_address(adapter));
 	if (!server)
 		return;
 
@@ -1240,7 +1240,7 @@ void a2dp_unregister(const bdaddr_t *src)
 	g_slist_free_full(server->sources,
 					(GDestroyNotify) a2dp_unregister_sep);
 
-	avdtp_exit(src);
+	avdtp_exit(adapter_get_address(adapter));
 
 	servers = g_slist_remove(servers, server);
 
diff --git a/profiles/audio/a2dp.h b/profiles/audio/a2dp.h
index 827d5cc..f45e40d 100644
--- a/profiles/audio/a2dp.h
+++ b/profiles/audio/a2dp.h
@@ -66,7 +66,7 @@ typedef void (*a2dp_stream_cb_t) (struct avdtp *session,
 
 int a2dp_source_register(struct btd_adapter *adapter, GKeyFile *config);
 int a2dp_sink_register(struct btd_adapter *adapter, GKeyFile *config);
-void a2dp_unregister(const bdaddr_t *src);
+void a2dp_unregister(struct btd_adapter *adapter);
 
 struct a2dp_sep *a2dp_add_sep(const bdaddr_t *src, uint8_t type,
 				uint8_t codec, gboolean delay_reporting,
-- 
1.8.0


^ permalink raw reply related

* [PATCH 06/16] media: Convert register/unregister to accept btd_adapter
From: Szymon Janc @ 2012-12-12 10:27 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>

Keep reference to passed btd_adapter and use it to get adapter address
and path.
---
 profiles/audio/manager.c | 10 ++++------
 profiles/audio/media.c   | 44 ++++++++++++++++++++++++++------------------
 profiles/audio/media.h   |  4 ++--
 3 files changed, 32 insertions(+), 26 deletions(-)

diff --git a/profiles/audio/manager.c b/profiles/audio/manager.c
index b355281..d4c52a6 100644
--- a/profiles/audio/manager.c
+++ b/profiles/audio/manager.c
@@ -410,16 +410,15 @@ static void avrcp_server_remove(struct btd_profile *p,
 static int media_server_probe(struct btd_adapter *adapter)
 {
 	struct audio_adapter *adp;
-	const gchar *path = adapter_get_path(adapter);
 	int err;
 
-	DBG("path %s", path);
+	DBG("path %s", adapter_get_path(adapter));
 
 	adp = audio_adapter_get(adapter);
 	if (!adp)
 		return -EINVAL;
 
-	err = media_register(path, adapter_get_address(adapter));
+	err = media_register(adapter);
 	if (err < 0)
 		audio_adapter_unref(adp);
 
@@ -429,15 +428,14 @@ static int media_server_probe(struct btd_adapter *adapter)
 static void media_server_remove(struct btd_adapter *adapter)
 {
 	struct audio_adapter *adp;
-	const gchar *path = adapter_get_path(adapter);
 
-	DBG("path %s", path);
+	DBG("path %s", adapter_get_path(adapter));
 
 	adp = find_adapter(adapters, adapter);
 	if (!adp)
 		return;
 
-	media_unregister(path);
+	media_unregister(adapter);
 	audio_adapter_unref(adp);
 }
 
diff --git a/profiles/audio/media.c b/profiles/audio/media.c
index 0839f69..c18dc4e 100644
--- a/profiles/audio/media.c
+++ b/profiles/audio/media.c
@@ -57,8 +57,7 @@
 #define REQUEST_TIMEOUT (3 * 1000)		/* 3 seconds */
 
 struct media_adapter {
-	bdaddr_t		src;		/* Adapter address */
-	char			*path;		/* Adapter path */
+	struct btd_adapter	*btd_adapter;
 	GSList			*endpoints;	/* Endpoints list */
 	GSList			*players;	/* Players list */
 };
@@ -553,7 +552,11 @@ static gboolean endpoint_init_a2dp_source(struct media_endpoint *endpoint,
 						gboolean delay_reporting,
 						int *err)
 {
-	endpoint->sep = a2dp_add_sep(&endpoint->adapter->src,
+	const bdaddr_t *src;
+
+	src = adapter_get_address(endpoint->adapter->btd_adapter);
+
+	endpoint->sep = a2dp_add_sep(src,
 					AVDTP_SEP_TYPE_SOURCE, endpoint->codec,
 					delay_reporting, &a2dp_endpoint,
 					endpoint, a2dp_destroy_endpoint, err);
@@ -567,7 +570,11 @@ static gboolean endpoint_init_a2dp_sink(struct media_endpoint *endpoint,
 						gboolean delay_reporting,
 						int *err)
 {
-	endpoint->sep = a2dp_add_sep(&endpoint->adapter->src,
+	const bdaddr_t *src;
+
+	src = adapter_get_address(endpoint->adapter->btd_adapter);
+
+	endpoint->sep = a2dp_add_sep(src,
 					AVDTP_SEP_TYPE_SINK, endpoint->codec,
 					delay_reporting, &a2dp_endpoint,
 					endpoint, a2dp_destroy_endpoint, err);
@@ -608,10 +615,8 @@ static bool endpoint_properties_exists(const char *uuid,
 						void *user_data)
 {
 	struct media_adapter *adapter = user_data;
-	struct btd_adapter *btd_adapter = device_get_adapter(dev);
-	const bdaddr_t *src = adapter_get_address(btd_adapter);
 
-	if (bacmp(&adapter->src, src) != 0)
+	if (adapter->btd_adapter != device_get_adapter(dev))
 		return false;
 
 	if (media_adapter_find_endpoint(adapter, NULL, NULL, uuid) == NULL)
@@ -1444,8 +1449,9 @@ static struct media_player *media_player_create(struct media_adapter *adapter,
 						"TrackChanged",
 						track_changed,
 						mp, NULL);
-	mp->player = avrcp_register_player(&adapter->src, &player_cb, mp,
-						media_player_free);
+	mp->player = avrcp_register_player(adapter_get_address(adapter->btd_adapter),
+							&player_cb, mp,
+							media_player_free);
 	if (!mp->player) {
 		if (err)
 			*err = -EPROTONOSUPPORT;
@@ -1558,23 +1564,24 @@ static void path_free(void *data)
 
 	adapters = g_slist_remove(adapters, adapter);
 
-	g_free(adapter->path);
+	btd_adapter_unref(adapter->btd_adapter);
 	g_free(adapter);
 }
 
-int media_register(const char *path, const bdaddr_t *src)
+int media_register(struct btd_adapter *btd_adapter)
 {
 	struct media_adapter *adapter;
 
 	adapter = g_new0(struct media_adapter, 1);
-	bacpy(&adapter->src, src);
-	adapter->path = g_strdup(path);
+	adapter->btd_adapter = btd_adapter_ref(btd_adapter);
 
 	if (!g_dbus_register_interface(btd_get_dbus_connection(),
-					path, MEDIA_INTERFACE,
+					adapter_get_path(btd_adapter),
+					MEDIA_INTERFACE,
 					media_methods, NULL, NULL,
 					adapter, path_free)) {
-		error("D-Bus failed to register %s path", path);
+		error("D-Bus failed to register %s path",
+						adapter_get_path(btd_adapter));
 		path_free(adapter);
 		return -1;
 	}
@@ -1584,16 +1591,17 @@ int media_register(const char *path, const bdaddr_t *src)
 	return 0;
 }
 
-void media_unregister(const char *path)
+void media_unregister(struct btd_adapter *btd_adapter)
 {
 	GSList *l;
 
 	for (l = adapters; l; l = l->next) {
 		struct media_adapter *adapter = l->data;
 
-		if (g_strcmp0(path, adapter->path) == 0) {
+		if (adapter->btd_adapter == btd_adapter) {
 			g_dbus_unregister_interface(btd_get_dbus_connection(),
-						path, MEDIA_INTERFACE);
+						adapter_get_path(btd_adapter),
+						MEDIA_INTERFACE);
 			return;
 		}
 	}
diff --git a/profiles/audio/media.h b/profiles/audio/media.h
index 82b9694..dd630d4 100644
--- a/profiles/audio/media.h
+++ b/profiles/audio/media.h
@@ -27,8 +27,8 @@ struct media_endpoint;
 typedef void (*media_endpoint_cb_t) (struct media_endpoint *endpoint,
 					void *ret, int size, void *user_data);
 
-int media_register(const char *path, const bdaddr_t *src);
-void media_unregister(const char *path);
+int media_register(struct btd_adapter *btd_adapter);
+void media_unregister(struct btd_adapter *btd_adapter);
 
 struct a2dp_sep *media_endpoint_get_sep(struct media_endpoint *endpoint);
 const char *media_endpoint_get_uuid(struct media_endpoint *endpoint);
-- 
1.8.0


^ permalink raw reply related

* [PATCH 07/16] a2dp: Convert a2dp_add_sep to accept struct btd_adapter
From: Szymon Janc @ 2012-12-12 10:27 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>

Pass btd_adapter directly or use getters to get needed data from
adapter object.
---
 profiles/audio/a2dp.c  |  4 ++--
 profiles/audio/a2dp.h  |  2 +-
 profiles/audio/media.c | 12 ++----------
 3 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index c145ca4..51119b7 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -1253,7 +1253,7 @@ void a2dp_unregister(struct btd_adapter *adapter)
 	g_free(server);
 }
 
-struct a2dp_sep *a2dp_add_sep(const bdaddr_t *src, uint8_t type,
+struct a2dp_sep *a2dp_add_sep(struct btd_adapter *adapter, uint8_t type,
 				uint8_t codec, gboolean delay_reporting,
 				struct a2dp_endpoint *endpoint,
 				void *user_data, GDestroyNotify destroy,
@@ -1265,7 +1265,7 @@ struct a2dp_sep *a2dp_add_sep(const bdaddr_t *src, uint8_t type,
 	uint32_t *record_id;
 	sdp_record_t *record;
 
-	server = find_server(servers, src);
+	server = find_server(servers, adapter_get_address(adapter));
 	if (server == NULL) {
 		if (err)
 			*err = -EPROTONOSUPPORT;
diff --git a/profiles/audio/a2dp.h b/profiles/audio/a2dp.h
index f45e40d..dab9195 100644
--- a/profiles/audio/a2dp.h
+++ b/profiles/audio/a2dp.h
@@ -68,7 +68,7 @@ int a2dp_source_register(struct btd_adapter *adapter, GKeyFile *config);
 int a2dp_sink_register(struct btd_adapter *adapter, GKeyFile *config);
 void a2dp_unregister(struct btd_adapter *adapter);
 
-struct a2dp_sep *a2dp_add_sep(const bdaddr_t *src, uint8_t type,
+struct a2dp_sep *a2dp_add_sep(struct btd_adapter *adapter, uint8_t type,
 				uint8_t codec, gboolean delay_reporting,
 				struct a2dp_endpoint *endpoint,
 				void *user_data, GDestroyNotify destroy,
diff --git a/profiles/audio/media.c b/profiles/audio/media.c
index c18dc4e..905538e 100644
--- a/profiles/audio/media.c
+++ b/profiles/audio/media.c
@@ -552,11 +552,7 @@ static gboolean endpoint_init_a2dp_source(struct media_endpoint *endpoint,
 						gboolean delay_reporting,
 						int *err)
 {
-	const bdaddr_t *src;
-
-	src = adapter_get_address(endpoint->adapter->btd_adapter);
-
-	endpoint->sep = a2dp_add_sep(src,
+	endpoint->sep = a2dp_add_sep(endpoint->adapter->btd_adapter,
 					AVDTP_SEP_TYPE_SOURCE, endpoint->codec,
 					delay_reporting, &a2dp_endpoint,
 					endpoint, a2dp_destroy_endpoint, err);
@@ -570,11 +566,7 @@ static gboolean endpoint_init_a2dp_sink(struct media_endpoint *endpoint,
 						gboolean delay_reporting,
 						int *err)
 {
-	const bdaddr_t *src;
-
-	src = adapter_get_address(endpoint->adapter->btd_adapter);
-
-	endpoint->sep = a2dp_add_sep(src,
+	endpoint->sep = a2dp_add_sep(endpoint->adapter->btd_adapter,
 					AVDTP_SEP_TYPE_SINK, endpoint->codec,
 					delay_reporting, &a2dp_endpoint,
 					endpoint, a2dp_destroy_endpoint, err);
-- 
1.8.0


^ permalink raw reply related

* [PATCH 08/16] avdtp: Use refs to adapter and device instead of bdaddr_t
From: Szymon Janc @ 2012-12-12 10:28 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>

Use local refs to device and adapter object instead of addresses.
This allows a2dp code to pass adapter object instead of address
and minimise need for finding adapter again with manager API.
---
 profiles/audio/a2dp.c  |  14 +++----
 profiles/audio/avdtp.c | 101 +++++++++++++++++++++----------------------------
 profiles/audio/avdtp.h |   7 ++--
 3 files changed, 54 insertions(+), 68 deletions(-)

diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index 51119b7..593fbf6 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -1160,7 +1160,7 @@ static struct a2dp_server *find_server(GSList *list, const bdaddr_t *src)
 	return NULL;
 }
 
-static struct a2dp_server *a2dp_server_register(const bdaddr_t *src,
+static struct a2dp_server *a2dp_server_register(struct btd_adapter *adapter,
 							GKeyFile *config)
 {
 	struct a2dp_server *server;
@@ -1168,14 +1168,14 @@ static struct a2dp_server *a2dp_server_register(const bdaddr_t *src,
 
 	server = g_new0(struct a2dp_server, 1);
 
-	av_err = avdtp_init(src, config);
+	av_err = avdtp_init(adapter, config);
 	if (av_err < 0) {
 		DBG("AVDTP not registered");
 		g_free(server);
 		return NULL;
 	}
 
-	bacpy(&server->src, src);
+	bacpy(&server->src, adapter_get_address(adapter));
 	servers = g_slist_append(servers, server);
 
 	return server;
@@ -1189,7 +1189,7 @@ int a2dp_source_register(struct btd_adapter *adapter, GKeyFile *config)
 	if (server != NULL)
 		goto done;
 
-	server = a2dp_server_register(adapter_get_address(adapter), config);
+	server = a2dp_server_register(adapter, config);
 	if (server == NULL)
 		return -EPROTONOSUPPORT;
 
@@ -1207,7 +1207,7 @@ int a2dp_sink_register(struct btd_adapter *adapter, GKeyFile *config)
 	if (server != NULL)
 		goto done;
 
-	server = a2dp_server_register(adapter_get_address(adapter), config);
+	server = a2dp_server_register(adapter, config);
 	if (server == NULL)
 		return -EPROTONOSUPPORT;
 
@@ -1240,7 +1240,7 @@ void a2dp_unregister(struct btd_adapter *adapter)
 	g_slist_free_full(server->sources,
 					(GDestroyNotify) a2dp_unregister_sep);
 
-	avdtp_exit(adapter_get_address(adapter));
+	avdtp_exit(adapter);
 
 	servers = g_slist_remove(servers, server);
 
@@ -1286,7 +1286,7 @@ struct a2dp_sep *a2dp_add_sep(struct btd_adapter *adapter, uint8_t type,
 
 	sep = g_new0(struct a2dp_sep, 1);
 
-	sep->lsep = avdtp_register_sep(&server->src, type,
+	sep->lsep = avdtp_register_sep(adapter, type,
 					AVDTP_MEDIA_TYPE_AUDIO, codec,
 					delay_reporting, &endpoint_ind,
 					&cfm, sep);
diff --git a/profiles/audio/avdtp.c b/profiles/audio/avdtp.c
index 1d6c71e..20fdf25 100644
--- a/profiles/audio/avdtp.c
+++ b/profiles/audio/avdtp.c
@@ -330,7 +330,7 @@ struct avdtp_remote_sep {
 };
 
 struct avdtp_server {
-	bdaddr_t src;
+	struct btd_adapter *adapter;
 	GIOChannel *io;
 	GSList *seps;
 	GSList *sessions;
@@ -391,7 +391,7 @@ struct avdtp {
 	uint16_t version;
 
 	struct avdtp_server *server;
-	bdaddr_t dst;
+	struct btd_device *device;
 
 	avdtp_session_state_t state;
 
@@ -454,12 +454,12 @@ static void avdtp_sep_set_state(struct avdtp *session,
 				avdtp_state_t state);
 static void auth_cb(DBusError *derr, void *user_data);
 
-static struct avdtp_server *find_server(GSList *list, const bdaddr_t *src)
+static struct avdtp_server *find_server(GSList *list, struct btd_adapter *a)
 {
 	for (; list; list = list->next) {
 		struct avdtp_server *server = list->data;
 
-		if (bacmp(&server->src, src) == 0)
+		if (server->adapter == a)
 			return server;
 	}
 
@@ -1157,7 +1157,9 @@ static gboolean disconnect_timeout(gpointer user_data)
 
 	stream_setup = session->stream_setup;
 	session->stream_setup = FALSE;
-	dev = manager_get_device(&session->server->src, &session->dst, FALSE);
+	dev = manager_get_device(adapter_get_address(session->server->adapter),
+					device_get_address(session->device),
+					FALSE);
 
 	if (dev && dev->sink && stream_setup)
 		sink_setup_stream(dev->sink, session);
@@ -1189,7 +1191,7 @@ static void connection_lost(struct avdtp *session, int err)
 	struct avdtp_server *server = session->server;
 	char address[18];
 
-	ba2str(&session->dst, address);
+	ba2str(device_get_address(session->device), address);
 	DBG("Disconnected from %s", address);
 
 	if (err != EACCES)
@@ -1206,6 +1208,7 @@ static void connection_lost(struct avdtp *session, int err)
 		return;
 
 	server->sessions = g_slist_remove(server->sessions, session);
+	btd_device_unref(session->device);
 	avdtp_free(session);
 }
 
@@ -2273,15 +2276,13 @@ failed:
 	return FALSE;
 }
 
-static struct avdtp *find_session(GSList *list, const bdaddr_t *dst)
+static struct avdtp *find_session(GSList *list, struct btd_device *device)
 {
 	for (; list != NULL; list = g_slist_next(list)) {
 		struct avdtp *s = list->data;
 
-		if (bacmp(dst, &s->dst))
-			continue;
-
-		return s;
+		if (s->device == device)
+			return s;
 	}
 
 	return NULL;
@@ -2289,26 +2290,14 @@ static struct avdtp *find_session(GSList *list, const bdaddr_t *dst)
 
 static uint16_t get_version(struct avdtp *session)
 {
-	struct btd_adapter *adapter;
-	struct btd_device *device;
 	const sdp_record_t *rec;
 	sdp_list_t *protos;
 	sdp_data_t *proto_desc;
-	char addr[18];
 	uint16_t ver = 0x0100;
 
-	adapter = manager_find_adapter(&session->server->src);
-	if (!adapter)
-		return ver;
-
-	ba2str(&session->dst, addr);
-	device = adapter_find_device(adapter, addr);
-	if (!device)
-		return ver;
-
-	rec = btd_device_get_record(device, A2DP_SINK_UUID);
+	rec = btd_device_get_record(session->device, A2DP_SINK_UUID);
 	if (!rec)
-		rec = btd_device_get_record(device, A2DP_SOURCE_UUID);
+		rec = btd_device_get_record(session->device, A2DP_SOURCE_UUID);
 
 	if (!rec)
 		return ver;
@@ -2326,19 +2315,16 @@ static uint16_t get_version(struct avdtp *session)
 	return ver;
 }
 
-static struct avdtp *avdtp_get_internal(const bdaddr_t *src, const bdaddr_t *dst)
+static struct avdtp *avdtp_get_internal(struct btd_device *device)
 {
 	struct avdtp_server *server;
 	struct avdtp *session;
 
-	assert(src != NULL);
-	assert(dst != NULL);
-
-	server = find_server(servers, src);
+	server = find_server(servers, device_get_adapter(device));
 	if (server == NULL)
 		return NULL;
 
-	session = find_session(server->sessions, dst);
+	session = find_session(server->sessions, device);
 	if (session) {
 		if (session->pending_auth)
 			return NULL;
@@ -2349,7 +2335,7 @@ static struct avdtp *avdtp_get_internal(const bdaddr_t *src, const bdaddr_t *dst
 	session = g_new0(struct avdtp, 1);
 
 	session->server = server;
-	bacpy(&session->dst, dst);
+	session->device = btd_device_ref(device);
 	/* We don't use avdtp_set_state() here since this isn't a state change
 	 * but just setting of the initial state */
 	session->state = AVDTP_SESSION_STATE_DISCONNECTED;
@@ -2364,13 +2350,8 @@ static struct avdtp *avdtp_get_internal(const bdaddr_t *src, const bdaddr_t *dst
 struct avdtp *avdtp_get(struct audio_device *device)
 {
 	struct avdtp *session;
-	const bdaddr_t *src;
-	const bdaddr_t *dst;
 
-	src = adapter_get_address(device_get_adapter(device->btd_dev));
-	dst = device_get_address(device->btd_dev);
-
-	session = avdtp_get_internal(src, dst);
+	session = avdtp_get_internal(device->btd_dev);
 
 	if (!session)
 		return NULL;
@@ -2403,7 +2384,7 @@ static void avdtp_connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
 		goto failed;
 	}
 
-	ba2str(&session->dst, address);
+	ba2str(device_get_address(session->device), address);
 	DBG("AVDTP: connected %s channel to %s",
 			session->pending_open ? "transport" : "signaling",
 			address);
@@ -2487,6 +2468,7 @@ static void avdtp_confirm_cb(GIOChannel *chan, gpointer data)
 	char address[18];
 	bdaddr_t src, dst;
 	GError *err = NULL;
+	struct btd_device *device;
 
 	bt_io_get(chan, &err,
 			BT_IO_OPT_SOURCE_BDADDR, &src,
@@ -2501,7 +2483,11 @@ static void avdtp_confirm_cb(GIOChannel *chan, gpointer data)
 
 	DBG("AVDTP: incoming connect from %s", address);
 
-	session = avdtp_get_internal(&src, &dst);
+	device = adapter_find_device(manager_find_adapter(&src), address);
+	if (!device)
+		goto drop;
+
+	session = avdtp_get_internal(device);
 	if (!session)
 		goto drop;
 
@@ -2565,8 +2551,10 @@ static GIOChannel *l2cap_connect(struct avdtp *session)
 
 	io = bt_io_connect(avdtp_connect_cb, session,
 				NULL, &err,
-				BT_IO_OPT_SOURCE_BDADDR, &session->server->src,
-				BT_IO_OPT_DEST_BDADDR, &session->dst,
+				BT_IO_OPT_SOURCE_BDADDR,
+				adapter_get_address(session->server->adapter),
+				BT_IO_OPT_DEST_BDADDR,
+				device_get_address(session->device),
 				BT_IO_OPT_PSM, AVDTP_PSM,
 				BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
 				BT_IO_OPT_INVALID);
@@ -3201,17 +3189,12 @@ gboolean avdtp_is_connected(struct audio_device *device)
 {
 	struct avdtp_server *server;
 	struct avdtp *session;
-	const bdaddr_t *src;
-	const bdaddr_t *dst;
-
-	src = adapter_get_address(device_get_adapter(device->btd_dev));
-	dst = device_get_address(device->btd_dev);
 
-	server = find_server(servers, src);
+	server = find_server(servers, device_get_adapter(device->btd_dev));
 	if (!server)
 		return FALSE;
 
-	session = find_session(server->sessions, dst);
+	session = find_session(server->sessions, device->btd_dev);
 	if (!session)
 		return FALSE;
 
@@ -3732,7 +3715,8 @@ int avdtp_delay_report(struct avdtp *session, struct avdtp_stream *stream,
 							&req, sizeof(req));
 }
 
-struct avdtp_local_sep *avdtp_register_sep(const bdaddr_t *src, uint8_t type,
+struct avdtp_local_sep *avdtp_register_sep(struct btd_adapter *adapter,
+						uint8_t type,
 						uint8_t media_type,
 						uint8_t codec_type,
 						gboolean delay_reporting,
@@ -3743,7 +3727,7 @@ struct avdtp_local_sep *avdtp_register_sep(const bdaddr_t *src, uint8_t type,
 	struct avdtp_server *server;
 	struct avdtp_local_sep *sep;
 
-	server = find_server(servers, src);
+	server = find_server(servers, adapter);
 	if (!server)
 		return NULL;
 
@@ -3864,12 +3848,12 @@ avdtp_state_t avdtp_sep_get_state(struct avdtp_local_sep *sep)
 void avdtp_get_peers(struct avdtp *session, bdaddr_t *src, bdaddr_t *dst)
 {
 	if (src)
-		bacpy(src, &session->server->src);
+		bacpy(src, adapter_get_address(session->server->adapter));
 	if (dst)
-		bacpy(dst, &session->dst);
+		bacpy(dst, device_get_address(session->device));
 }
 
-int avdtp_init(const bdaddr_t *src, GKeyFile *config)
+int avdtp_init(struct btd_adapter *adapter, GKeyFile *config)
 {
 	GError *err = NULL;
 	gboolean tmp, master = TRUE;
@@ -3889,24 +3873,24 @@ int avdtp_init(const bdaddr_t *src, GKeyFile *config)
 proceed:
 	server = g_new0(struct avdtp_server, 1);
 
-	server->io = avdtp_server_socket(src, master);
+	server->io = avdtp_server_socket(adapter_get_address(adapter), master);
 	if (!server->io) {
 		g_free(server);
 		return -1;
 	}
 
-	bacpy(&server->src, src);
+	server->adapter = btd_adapter_ref(adapter);
 
 	servers = g_slist_append(servers, server);
 
 	return 0;
 }
 
-void avdtp_exit(const bdaddr_t *src)
+void avdtp_exit(struct btd_adapter *adapter)
 {
 	struct avdtp_server *server;
 
-	server = find_server(servers, src);
+	server = find_server(servers, adapter);
 	if (!server)
 		return;
 
@@ -3916,6 +3900,7 @@ void avdtp_exit(const bdaddr_t *src)
 
 	g_io_channel_shutdown(server->io, TRUE, NULL);
 	g_io_channel_unref(server->io);
+	btd_adapter_unref(server->adapter);
 	g_free(server);
 }
 
diff --git a/profiles/audio/avdtp.h b/profiles/audio/avdtp.h
index e014623..dbdf8f4 100644
--- a/profiles/audio/avdtp.h
+++ b/profiles/audio/avdtp.h
@@ -282,7 +282,8 @@ int avdtp_abort(struct avdtp *session, struct avdtp_stream *stream);
 int avdtp_delay_report(struct avdtp *session, struct avdtp_stream *stream,
 							uint16_t delay);
 
-struct avdtp_local_sep *avdtp_register_sep(const bdaddr_t *src, uint8_t type,
+struct avdtp_local_sep *avdtp_register_sep(struct btd_adapter *adapter,
+						uint8_t type,
 						uint8_t media_type,
 						uint8_t codec_type,
 						gboolean delay_reporting,
@@ -309,5 +310,5 @@ void avdtp_get_peers(struct avdtp *session, bdaddr_t *src, bdaddr_t *dst);
 gboolean avdtp_stream_setup_active(struct avdtp *session);
 void avdtp_set_device_disconnect(struct avdtp *session, gboolean dev_dc);
 
-int avdtp_init(const bdaddr_t *src, GKeyFile *config);
-void avdtp_exit(const bdaddr_t *src);
+int avdtp_init(struct btd_adapter *adapter, GKeyFile *config);
+void avdtp_exit(struct btd_adapter *adapter);
-- 
1.8.0


^ permalink raw reply related

* [PATCH 09/16] a2dp: Use btd_adapter ref in a2dp_server instead of bdaddr_t
From: Szymon Janc @ 2012-12-12 10:28 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355308088-9080-1-git-send-email-szymon.janc@tieto.com>

Use local refs to device and adapter object instead of addresses.
This allows a2dp code to pass adapter object instead of address.
---
 profiles/audio/a2dp.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index 593fbf6..da54717 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -48,6 +48,7 @@
 #include "a2dp.h"
 #include "a2dp-codecs.h"
 #include "sdpd.h"
+#include "../src/manager.h"
 
 /* The duration that streams without users are allowed to stay in
  * STREAMING state. */
@@ -98,7 +99,7 @@ struct a2dp_setup {
 };
 
 struct a2dp_server {
-	bdaddr_t src;
+	struct btd_adapter *adapter;
 	GSList *sinks;
 	GSList *sources;
 	uint32_t source_record_id;
@@ -1147,13 +1148,13 @@ static sdp_record_t *a2dp_record(uint8_t type)
 	return record;
 }
 
-static struct a2dp_server *find_server(GSList *list, const bdaddr_t *src)
+static struct a2dp_server *find_server(GSList *list, struct btd_adapter *a)
 {
 
 	for (; list; list = list->next) {
 		struct a2dp_server *server = list->data;
 
-		if (bacmp(&server->src, src) == 0)
+		if (server->adapter == a)
 			return server;
 	}
 
@@ -1175,7 +1176,7 @@ static struct a2dp_server *a2dp_server_register(struct btd_adapter *adapter,
 		return NULL;
 	}
 
-	bacpy(&server->src, adapter_get_address(adapter));
+	server->adapter = btd_adapter_ref(adapter);
 	servers = g_slist_append(servers, server);
 
 	return server;
@@ -1185,7 +1186,7 @@ int a2dp_source_register(struct btd_adapter *adapter, GKeyFile *config)
 {
 	struct a2dp_server *server;
 
-	server = find_server(servers, adapter_get_address(adapter));
+	server = find_server(servers, adapter);
 	if (server != NULL)
 		goto done;
 
@@ -1203,7 +1204,7 @@ int a2dp_sink_register(struct btd_adapter *adapter, GKeyFile *config)
 {
 	struct a2dp_server *server;
 
-	server = find_server(servers, adapter_get_address(adapter));
+	server = find_server(servers, adapter);
 	if (server != NULL)
 		goto done;
 
@@ -1232,7 +1233,7 @@ void a2dp_unregister(struct btd_adapter *adapter)
 {
 	struct a2dp_server *server;
 
-	server = find_server(servers, adapter_get_address(adapter));
+	server = find_server(servers, adapter);
 	if (!server)
 		return;
 
@@ -1250,6 +1251,7 @@ void a2dp_unregister(struct btd_adapter *adapter)
 	if (server->sink_record_id)
 		remove_record_from_server(server->sink_record_id);
 
+	btd_adapter_unref(server->adapter);
 	g_free(server);
 }
 
@@ -1265,7 +1267,7 @@ struct a2dp_sep *a2dp_add_sep(struct btd_adapter *adapter, uint8_t type,
 	uint32_t *record_id;
 	sdp_record_t *record;
 
-	server = find_server(servers, adapter_get_address(adapter));
+	server = find_server(servers, adapter);
 	if (server == NULL) {
 		if (err)
 			*err = -EPROTONOSUPPORT;
@@ -1327,7 +1329,8 @@ struct a2dp_sep *a2dp_add_sep(struct btd_adapter *adapter, uint8_t type,
 		return NULL;
 	}
 
-	if (add_record_to_server(&server->src, record) < 0) {
+	if (add_record_to_server(adapter_get_address(server->adapter),
+								record) < 0) {
 		error("Unable to register A2DP service record");
 		sdp_record_free(record);
 		avdtp_unregister_sep(sep->lsep);
@@ -1492,7 +1495,7 @@ static struct a2dp_sep *a2dp_select_sep(struct avdtp *session, uint8_t type,
 	bdaddr_t src;
 
 	avdtp_get_peers(session, &src, NULL);
-	server = find_server(servers, &src);
+	server = find_server(servers, manager_find_adapter(&src));
 	if (!server)
 		return NULL;
 
@@ -1571,7 +1574,7 @@ unsigned int a2dp_config(struct avdtp *session, struct a2dp_sep *sep,
 	bdaddr_t src;
 
 	avdtp_get_peers(session, &src, NULL);
-	server = find_server(servers, &src);
+	server = find_server(servers, manager_find_adapter(&src));
 	if (!server)
 		return 0;
 
@@ -1888,7 +1891,7 @@ struct a2dp_sep *a2dp_get_sep(struct avdtp *session,
 	for (l = servers; l; l = l->next) {
 		server = l->data;
 
-		if (bacmp(&src, &server->src) == 0)
+		if (bacmp(&src, adapter_get_address(server->adapter)) == 0)
 			break;
 	}
 
-- 
1.8.0


^ permalink raw reply related

* [PATCH 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


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox