Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 6/8] Bluetooth: use l2cap_chan_set_err()
From: Gustavo Padovan @ 2012-10-07 23:19 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo Padovan
In-Reply-To: <1349651981-6251-1-git-send-email-gustavo@padovan.org>

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

l2cap_conn_unreliable() doesn't take the sk lock, so we need to take it
using l2cap_chan_set_err().

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

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 7914641..94b0e75 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1293,7 +1293,7 @@ static void l2cap_conn_unreliable(struct l2cap_conn *conn, int err)
 
 	list_for_each_entry(chan, &conn->chan_l, list) {
 		if (test_bit(FLAG_FORCE_RELIABLE, &chan->flags))
-			__l2cap_chan_set_err(chan, err);
+			l2cap_chan_set_err(chan, err);
 	}
 
 	mutex_unlock(&conn->chan_lock);
-- 
1.7.11.4


^ permalink raw reply related

* [PATCH 5/8] Bluetooth: Remove GFP_ATOMIC usage from l2cap_core.c
From: Gustavo Padovan @ 2012-10-07 23:19 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo Padovan
In-Reply-To: <1349651981-6251-1-git-send-email-gustavo@padovan.org>

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

Since we change the Bluetooth core to run in process context we don't need
to use GFP_ATOMIC in many of places we were using it. The we just replace
by GFP_KERNEL.

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

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 02a66fb..7914641 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -396,7 +396,7 @@ struct l2cap_chan *l2cap_chan_create(void)
 {
 	struct l2cap_chan *chan;
 
-	chan = kzalloc(sizeof(*chan), GFP_ATOMIC);
+	chan = kzalloc(sizeof(*chan), GFP_KERNEL);
 	if (!chan)
 		return NULL;
 
@@ -1378,7 +1378,7 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon, u8 status)
 	if (!hchan)
 		return NULL;
 
-	conn = kzalloc(sizeof(struct l2cap_conn), GFP_ATOMIC);
+	conn = kzalloc(sizeof(struct l2cap_conn), GFP_KERNEL);
 	if (!conn) {
 		hci_chan_del(hchan);
 		return NULL;
@@ -1830,9 +1830,9 @@ static void l2cap_ertm_resend(struct l2cap_chan *chan)
 			/* Cloned sk_buffs are read-only, so we need a
 			 * writeable copy
 			 */
-			tx_skb = skb_copy(skb, GFP_ATOMIC);
+			tx_skb = skb_copy(skb, GFP_KERNEL);
 		} else {
-			tx_skb = skb_clone(skb, GFP_ATOMIC);
+			tx_skb = skb_clone(skb, GFP_KERNEL);
 		}
 
 		if (!tx_skb) {
@@ -2578,7 +2578,7 @@ static void l2cap_raw_recv(struct l2cap_conn *conn, struct sk_buff *skb)
 		/* Don't send frame to the socket it came from */
 		if (skb->sk == sk)
 			continue;
-		nskb = skb_clone(skb, GFP_ATOMIC);
+		nskb = skb_clone(skb, GFP_KERNEL);
 		if (!nskb)
 			continue;
 
@@ -2604,7 +2604,7 @@ static struct sk_buff *l2cap_build_cmd(struct l2cap_conn *conn, u8 code,
 	len = L2CAP_HDR_SIZE + L2CAP_CMD_HDR_SIZE + dlen;
 	count = min_t(unsigned int, conn->mtu, len);
 
-	skb = bt_skb_alloc(count, GFP_ATOMIC);
+	skb = bt_skb_alloc(count, GFP_KERNEL);
 	if (!skb)
 		return NULL;
 
@@ -2634,7 +2634,7 @@ static struct sk_buff *l2cap_build_cmd(struct l2cap_conn *conn, u8 code,
 	while (len) {
 		count = min_t(unsigned int, conn->mtu, len);
 
-		*frag = bt_skb_alloc(count, GFP_ATOMIC);
+		*frag = bt_skb_alloc(count, GFP_KERNEL);
 		if (!*frag)
 			goto fail;
 
@@ -5612,7 +5612,7 @@ int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags)
 		}
 
 		/* Allocate skb for the complete frame (with header) */
-		conn->rx_skb = bt_skb_alloc(len, GFP_ATOMIC);
+		conn->rx_skb = bt_skb_alloc(len, GFP_KERNEL);
 		if (!conn->rx_skb)
 			goto drop;
 
-- 
1.7.11.4


^ permalink raw reply related

* [PATCH 4/8] Bluetooth: Add chan->ops->defer()
From: Gustavo Padovan @ 2012-10-07 23:19 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo Padovan
In-Reply-To: <1349651981-6251-1-git-send-email-gustavo@padovan.org>

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

When DEFER_SETUP is set defer() will trigger an authorization
request to the userspace.

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

diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index 7002f0d..eef7146 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -540,6 +540,7 @@ struct l2cap_ops {
 	void			(*state_change) (struct l2cap_chan *chan,
 						 int state);
 	void			(*ready) (struct l2cap_chan *chan);
+	void			(*defer) (struct l2cap_chan *chan);
 	struct sk_buff		*(*alloc_skb) (struct l2cap_chan *chan,
 					       unsigned long len, int nb);
 };
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 9e166ce..02a66fb 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1123,11 +1123,9 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
 				lock_sock(sk);
 				if (test_bit(BT_SK_DEFER_SETUP,
 					     &bt_sk(sk)->flags)) {
-					struct sock *parent = bt_sk(sk)->parent;
 					rsp.result = __constant_cpu_to_le16(L2CAP_CR_PEND);
 					rsp.status = __constant_cpu_to_le16(L2CAP_CS_AUTHOR_PEND);
-					if (parent)
-						parent->sk_data_ready(parent, 0);
+					chan->ops->defer(chan);
 
 				} else {
 					__l2cap_state_change(chan, BT_CONFIG);
@@ -3459,7 +3457,7 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn,
 				__l2cap_state_change(chan, BT_CONNECT2);
 				result = L2CAP_CR_PEND;
 				status = L2CAP_CS_AUTHOR_PEND;
-				parent->sk_data_ready(parent, 0);
+				chan->ops->defer(chan);
 			} else {
 				__l2cap_state_change(chan, BT_CONFIG);
 				result = L2CAP_CR_SUCCESS;
@@ -5520,11 +5518,9 @@ int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
 			if (!status) {
 				if (test_bit(BT_SK_DEFER_SETUP,
 					     &bt_sk(sk)->flags)) {
-					struct sock *parent = bt_sk(sk)->parent;
 					res = L2CAP_CR_PEND;
 					stat = L2CAP_CS_AUTHOR_PEND;
-					if (parent)
-						parent->sk_data_ready(parent, 0);
+					chan->ops->defer(chan);
 				} else {
 					__l2cap_state_change(chan, BT_CONFIG);
 					res = L2CAP_CR_SUCCESS;
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 0feb8f8..f0e4410 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -955,6 +955,7 @@ static struct l2cap_chan *l2cap_sock_new_connection_cb(struct l2cap_chan *chan)
 
 	bt_accept_enqueue(parent, sk);
 
+
 	release_sock(parent);
 
 	return l2cap_pi(sk)->chan;
@@ -1087,6 +1088,17 @@ static void l2cap_sock_ready_cb(struct l2cap_chan *chan)
 	release_sock(sk);
 }
 
+static void l2cap_sock_defer_cb(struct l2cap_chan *chan)
+{
+	struct sock *sk = chan->data;
+	struct sock *parent;
+
+	parent = bt_sk(sk)->parent;
+
+	if (parent)
+		parent->sk_data_ready(parent, 0);
+}
+
 static struct l2cap_ops l2cap_chan_ops = {
 	.name		= "L2CAP Socket Interface",
 	.new_connection	= l2cap_sock_new_connection_cb,
@@ -1095,6 +1107,7 @@ static struct l2cap_ops l2cap_chan_ops = {
 	.teardown	= l2cap_sock_teardown_cb,
 	.state_change	= l2cap_sock_state_change_cb,
 	.ready		= l2cap_sock_ready_cb,
+	.defer		= l2cap_sock_defer_cb,
 	.alloc_skb	= l2cap_sock_alloc_skb_cb,
 };
 
-- 
1.7.11.4


^ permalink raw reply related

* [PATCH 3/8] Bluetooth: Remove parent socket usage from l2cap_core.c
From: Gustavo Padovan @ 2012-10-07 23:19 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo Padovan
In-Reply-To: <1349651981-6251-1-git-send-email-gustavo@padovan.org>

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

We can lock the parent lock only inside the new_connection() call,
then we just use the l2cap_chan_lock() in core code.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 net/bluetooth/l2cap_core.c | 16 ++++++----------
 net/bluetooth/l2cap_sock.c |  9 ++++++++-
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index fc10d23..9e166ce 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1206,7 +1206,7 @@ static struct l2cap_chan *l2cap_global_chan_by_scid(int state, u16 cid,
 
 static void l2cap_le_conn_ready(struct l2cap_conn *conn)
 {
-	struct sock *parent, *sk;
+	struct sock *sk;
 	struct l2cap_chan *chan, *pchan;
 
 	BT_DBG("");
@@ -1217,9 +1217,7 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn)
 	if (!pchan)
 		return;
 
-	parent = pchan->sk;
-
-	lock_sock(parent);
+	l2cap_chan_lock(pchan);
 
 	chan = pchan->ops->new_connection(pchan);
 	if (!chan)
@@ -1238,7 +1236,7 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn)
 	l2cap_chan_ready(chan);
 
 clean:
-	release_sock(parent);
+	l2cap_chan_unlock(pchan);
 }
 
 static void l2cap_conn_ready(struct l2cap_conn *conn)
@@ -3402,7 +3400,7 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn,
 	struct l2cap_conn_req *req = (struct l2cap_conn_req *) data;
 	struct l2cap_conn_rsp rsp;
 	struct l2cap_chan *chan = NULL, *pchan;
-	struct sock *parent, *sk = NULL;
+	struct sock *sk = NULL;
 	int result, status = L2CAP_CS_NO_INFO;
 
 	u16 dcid = 0, scid = __le16_to_cpu(req->scid);
@@ -3417,10 +3415,8 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn,
 		goto sendresp;
 	}
 
-	parent = pchan->sk;
-
 	mutex_lock(&conn->chan_lock);
-	lock_sock(parent);
+	l2cap_chan_lock(pchan);
 
 	/* Check if the ACL is secure enough (if not SDP) */
 	if (psm != __constant_cpu_to_le16(L2CAP_PSM_SDP) &&
@@ -3481,7 +3477,7 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn,
 	}
 
 response:
-	release_sock(parent);
+	l2cap_chan_unlock(pchan);
 	mutex_unlock(&conn->chan_lock);
 
 sendresp:
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 50c38e0..0feb8f8 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -933,16 +933,21 @@ static struct l2cap_chan *l2cap_sock_new_connection_cb(struct l2cap_chan *chan)
 {
 	struct sock *sk, *parent = chan->data;
 
+	lock_sock(parent);
+
 	/* Check for backlog size */
 	if (sk_acceptq_is_full(parent)) {
 		BT_DBG("backlog full %d", parent->sk_ack_backlog);
+		release_sock(parent);
 		return NULL;
 	}
 
 	sk = l2cap_sock_alloc(sock_net(parent), NULL, BTPROTO_L2CAP,
 			      GFP_ATOMIC);
-	if (!sk)
+	if (!sk) {
+		release_sock(parent);
 		return NULL;
+	}
 
 	bt_sock_reclassify_lock(sk, BTPROTO_L2CAP);
 
@@ -950,6 +955,8 @@ static struct l2cap_chan *l2cap_sock_new_connection_cb(struct l2cap_chan *chan)
 
 	bt_accept_enqueue(parent, sk);
 
+	release_sock(parent);
+
 	return l2cap_pi(sk)->chan;
 }
 
-- 
1.7.11.4


^ permalink raw reply related

* [PATCH 2/8] Bluetooth: Move bt_accept_enqueue() to l2cap_sock.c
From: Gustavo Padovan @ 2012-10-07 23:19 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo Padovan
In-Reply-To: <1349651981-6251-1-git-send-email-gustavo@padovan.org>

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

This is move the parent socket usage to l2cap_sock.c

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

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 787e30a..fc10d23 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1233,8 +1233,6 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn)
 	bacpy(&bt_sk(sk)->src, conn->src);
 	bacpy(&bt_sk(sk)->dst, conn->dst);
 
-	bt_accept_enqueue(parent, sk);
-
 	l2cap_chan_add(conn, chan);
 
 	l2cap_chan_ready(chan);
@@ -3451,8 +3449,6 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn,
 	chan->psm  = psm;
 	chan->dcid = scid;
 
-	bt_accept_enqueue(parent, sk);
-
 	__l2cap_chan_add(conn, chan);
 
 	dcid = chan->scid;
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index dd593c9..50c38e0 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -948,6 +948,8 @@ static struct l2cap_chan *l2cap_sock_new_connection_cb(struct l2cap_chan *chan)
 
 	l2cap_sock_init(sk, parent);
 
+	bt_accept_enqueue(parent, sk);
+
 	return l2cap_pi(sk)->chan;
 }
 
-- 
1.7.11.4


^ permalink raw reply related

* [PATCH 1/8] Bluetooth: Fix L2CAP coding style
From: Gustavo Padovan @ 2012-10-07 23:19 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo Padovan

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

Follow the net subsystem coding style

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 net/bluetooth/l2cap_core.c | 315 ++++++++++++++++++++++++---------------------
 net/bluetooth/l2cap_sock.c |  62 +++++----
 2 files changed, 203 insertions(+), 174 deletions(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index d605bbf..787e30a 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -48,19 +48,20 @@ static LIST_HEAD(chan_list);
 static DEFINE_RWLOCK(chan_list_lock);
 
 static struct sk_buff *l2cap_build_cmd(struct l2cap_conn *conn,
-				u8 code, u8 ident, u16 dlen, void *data);
+				       u8 code, u8 ident, u16 dlen, void *data);
 static void l2cap_send_cmd(struct l2cap_conn *conn, u8 ident, u8 code, u16 len,
-								void *data);
+			   void *data);
 static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data);
 static void l2cap_send_disconn_req(struct l2cap_conn *conn,
 				   struct l2cap_chan *chan, int err);
 
 static void l2cap_tx(struct l2cap_chan *chan, struct l2cap_ctrl *control,
-		    struct sk_buff_head *skbs, u8 event);
+		     struct sk_buff_head *skbs, u8 event);
 
 /* ---- L2CAP channels ---- */
 
-static struct l2cap_chan *__l2cap_get_chan_by_dcid(struct l2cap_conn *conn, u16 cid)
+static struct l2cap_chan *__l2cap_get_chan_by_dcid(struct l2cap_conn *conn,
+						   u16 cid)
 {
 	struct l2cap_chan *c;
 
@@ -71,7 +72,8 @@ static struct l2cap_chan *__l2cap_get_chan_by_dcid(struct l2cap_conn *conn, u16
 	return NULL;
 }
 
-static struct l2cap_chan *__l2cap_get_chan_by_scid(struct l2cap_conn *conn, u16 cid)
+static struct l2cap_chan *__l2cap_get_chan_by_scid(struct l2cap_conn *conn,
+						   u16 cid)
 {
 	struct l2cap_chan *c;
 
@@ -84,7 +86,8 @@ static struct l2cap_chan *__l2cap_get_chan_by_scid(struct l2cap_conn *conn, u16
 
 /* Find channel with given SCID.
  * Returns locked channel. */
-static struct l2cap_chan *l2cap_get_chan_by_scid(struct l2cap_conn *conn, u16 cid)
+static struct l2cap_chan *l2cap_get_chan_by_scid(struct l2cap_conn *conn,
+						 u16 cid)
 {
 	struct l2cap_chan *c;
 
@@ -97,7 +100,8 @@ static struct l2cap_chan *l2cap_get_chan_by_scid(struct l2cap_conn *conn, u16 ci
 	return c;
 }
 
-static struct l2cap_chan *__l2cap_get_chan_by_ident(struct l2cap_conn *conn, u8 ident)
+static struct l2cap_chan *__l2cap_get_chan_by_ident(struct l2cap_conn *conn,
+						    u8 ident)
 {
 	struct l2cap_chan *c;
 
@@ -178,7 +182,7 @@ static u16 l2cap_alloc_cid(struct l2cap_conn *conn)
 static void __l2cap_state_change(struct l2cap_chan *chan, int state)
 {
 	BT_DBG("chan %p %s -> %s", chan, state_to_string(chan->state),
-						state_to_string(state));
+	       state_to_string(state));
 
 	chan->state = state;
 	chan->ops->state_change(chan, state);
@@ -361,7 +365,7 @@ static void l2cap_seq_list_append(struct l2cap_seq_list *seq_list, u16 seq)
 static void l2cap_chan_timeout(struct work_struct *work)
 {
 	struct l2cap_chan *chan = container_of(work, struct l2cap_chan,
-							chan_timer.work);
+					       chan_timer.work);
 	struct l2cap_conn *conn = chan->conn;
 	int reason;
 
@@ -373,7 +377,7 @@ static void l2cap_chan_timeout(struct work_struct *work)
 	if (chan->state == BT_CONNECTED || chan->state == BT_CONFIG)
 		reason = ECONNREFUSED;
 	else if (chan->state == BT_CONNECT &&
-					chan->sec_level != BT_SECURITY_SDP)
+		 chan->sec_level != BT_SECURITY_SDP)
 		reason = ECONNREFUSED;
 	else
 		reason = ETIMEDOUT;
@@ -573,8 +577,8 @@ void l2cap_chan_close(struct l2cap_chan *chan, int reason)
 	struct l2cap_conn *conn = chan->conn;
 	struct sock *sk = chan->sk;
 
-	BT_DBG("chan %p state %s sk %p", chan,
-					state_to_string(chan->state), sk);
+	BT_DBG("chan %p state %s sk %p", chan, state_to_string(chan->state),
+	       sk);
 
 	switch (chan->state) {
 	case BT_LISTEN:
@@ -585,7 +589,7 @@ void l2cap_chan_close(struct l2cap_chan *chan, int reason)
 	case BT_CONNECTED:
 	case BT_CONFIG:
 		if (chan->chan_type == L2CAP_CHAN_CONN_ORIENTED &&
-					conn->hcon->type == ACL_LINK) {
+		    conn->hcon->type == ACL_LINK) {
 			__set_chan_timer(chan, sk->sk_sndtimeo);
 			l2cap_send_disconn_req(conn, chan, reason);
 		} else
@@ -594,7 +598,7 @@ void l2cap_chan_close(struct l2cap_chan *chan, int reason)
 
 	case BT_CONNECT2:
 		if (chan->chan_type == L2CAP_CHAN_CONN_ORIENTED &&
-					conn->hcon->type == ACL_LINK) {
+		    conn->hcon->type == ACL_LINK) {
 			struct l2cap_conn_rsp rsp;
 			__u16 result;
 
@@ -609,7 +613,7 @@ void l2cap_chan_close(struct l2cap_chan *chan, int reason)
 			rsp.result = cpu_to_le16(result);
 			rsp.status = __constant_cpu_to_le16(L2CAP_CS_NO_INFO);
 			l2cap_send_cmd(conn, chan->ident, L2CAP_CONN_RSP,
-							sizeof(rsp), &rsp);
+				       sizeof(rsp), &rsp);
 		}
 
 		l2cap_chan_del(chan, reason);
@@ -691,7 +695,8 @@ static u8 l2cap_get_ident(struct l2cap_conn *conn)
 	return id;
 }
 
-static void l2cap_send_cmd(struct l2cap_conn *conn, u8 ident, u8 code, u16 len, void *data)
+static void l2cap_send_cmd(struct l2cap_conn *conn, u8 ident, u8 code, u16 len,
+			   void *data)
 {
 	struct sk_buff *skb = l2cap_build_cmd(conn, code, ident, len, data);
 	u8 flags;
@@ -718,10 +723,10 @@ static void l2cap_do_send(struct l2cap_chan *chan, struct sk_buff *skb)
 	u16 flags;
 
 	BT_DBG("chan %p, skb %p len %d priority %u", chan, skb, skb->len,
-							skb->priority);
+	       skb->priority);
 
 	if (!test_bit(FLAG_FLUSHABLE, &chan->flags) &&
-					lmp_no_flush_capable(hcon->hdev))
+	    lmp_no_flush_capable(hcon->hdev))
 		flags = ACL_START_NO_FLUSH;
 	else
 		flags = ACL_START;
@@ -1008,7 +1013,7 @@ static void l2cap_do_start(struct l2cap_chan *chan)
 			return;
 
 		if (l2cap_chan_check_security(chan) &&
-				__l2cap_no_conn_pending(chan)) {
+		    __l2cap_no_conn_pending(chan)) {
 			l2cap_start_connection(chan);
 		}
 	} else {
@@ -1020,8 +1025,8 @@ static void l2cap_do_start(struct l2cap_chan *chan)
 
 		schedule_delayed_work(&conn->info_timer, L2CAP_INFO_TIMEOUT);
 
-		l2cap_send_cmd(conn, conn->info_ident,
-					L2CAP_INFO_REQ, sizeof(req), &req);
+		l2cap_send_cmd(conn, conn->info_ident, L2CAP_INFO_REQ,
+			       sizeof(req), &req);
 	}
 }
 
@@ -1041,7 +1046,8 @@ static inline int l2cap_mode_supported(__u8 mode, __u32 feat_mask)
 	}
 }
 
-static void l2cap_send_disconn_req(struct l2cap_conn *conn, struct l2cap_chan *chan, int err)
+static void l2cap_send_disconn_req(struct l2cap_conn *conn,
+				   struct l2cap_chan *chan, int err)
 {
 	struct sock *sk = chan->sk;
 	struct l2cap_disconn_req req;
@@ -1062,8 +1068,8 @@ static void l2cap_send_disconn_req(struct l2cap_conn *conn, struct l2cap_chan *c
 
 	req.dcid = cpu_to_le16(chan->dcid);
 	req.scid = cpu_to_le16(chan->scid);
-	l2cap_send_cmd(conn, l2cap_get_ident(conn),
-			L2CAP_DISCONN_REQ, sizeof(req), &req);
+	l2cap_send_cmd(conn, l2cap_get_ident(conn), L2CAP_DISCONN_REQ,
+		       sizeof(req), &req);
 
 	lock_sock(sk);
 	__l2cap_state_change(chan, BT_DISCONN);
@@ -1092,13 +1098,13 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
 
 		if (chan->state == BT_CONNECT) {
 			if (!l2cap_chan_check_security(chan) ||
-					!__l2cap_no_conn_pending(chan)) {
+			    !__l2cap_no_conn_pending(chan)) {
 				l2cap_chan_unlock(chan);
 				continue;
 			}
 
 			if (!l2cap_mode_supported(chan->mode, conn->feat_mask)
-					&& test_bit(CONF_STATE2_DEVICE,
+			    && test_bit(CONF_STATE2_DEVICE,
 					&chan->conf_state)) {
 				l2cap_chan_close(chan, ECONNRESET);
 				l2cap_chan_unlock(chan);
@@ -1135,17 +1141,17 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
 			}
 
 			l2cap_send_cmd(conn, chan->ident, L2CAP_CONN_RSP,
-							sizeof(rsp), &rsp);
+				       sizeof(rsp), &rsp);
 
 			if (test_bit(CONF_REQ_SENT, &chan->conf_state) ||
-					rsp.result != L2CAP_CR_SUCCESS) {
+			    rsp.result != L2CAP_CR_SUCCESS) {
 				l2cap_chan_unlock(chan);
 				continue;
 			}
 
 			set_bit(CONF_REQ_SENT, &chan->conf_state);
 			l2cap_send_cmd(conn, l2cap_get_ident(conn), L2CAP_CONF_REQ,
-						l2cap_build_conf_req(chan, buf), buf);
+				       l2cap_build_conf_req(chan, buf), buf);
 			chan->num_conf_req++;
 		}
 
@@ -1302,7 +1308,7 @@ static void l2cap_conn_unreliable(struct l2cap_conn *conn, int err)
 static void l2cap_info_timeout(struct work_struct *work)
 {
 	struct l2cap_conn *conn = container_of(work, struct l2cap_conn,
-							info_timer.work);
+					       info_timer.work);
 
 	conn->info_state |= L2CAP_INFO_FEAT_MASK_REQ_DONE;
 	conn->info_ident = 0;
@@ -1356,7 +1362,7 @@ static void l2cap_conn_del(struct hci_conn *hcon, int err)
 static void security_timeout(struct work_struct *work)
 {
 	struct l2cap_conn *conn = container_of(work, struct l2cap_conn,
-						security_timer.work);
+					       security_timer.work);
 
 	BT_DBG("conn %p", conn);
 
@@ -1496,7 +1502,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
 
 	/* PSM must be odd and lsb of upper byte must be 0 */
 	if ((__le16_to_cpu(psm) & 0x0101) != 0x0001 && !cid &&
-					chan->chan_type != L2CAP_CHAN_RAW) {
+	    chan->chan_type != L2CAP_CHAN_RAW) {
 		err = -EINVAL;
 		goto done;
 	}
@@ -1805,7 +1811,7 @@ static void l2cap_ertm_resend(struct l2cap_chan *chan)
 		skb = l2cap_ertm_seq_in_queue(&chan->tx_q, seq);
 		if (!skb) {
 			BT_DBG("Error: Can't retransmit seq %d, frame missing",
-				seq);
+			       seq);
 			continue;
 		}
 
@@ -1890,7 +1896,7 @@ static void l2cap_retransmit_all(struct l2cap_chan *chan,
 	if (chan->unacked_frames) {
 		skb_queue_walk(&chan->tx_q, skb) {
 			if (bt_cb(skb)->control.txseq == control->reqseq ||
-				skb == chan->tx_send_head)
+			    skb == chan->tx_send_head)
 				break;
 		}
 
@@ -2191,7 +2197,7 @@ static int l2cap_segment_sdu(struct l2cap_chan *chan,
 }
 
 int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len,
-								u32 priority)
+		    u32 priority)
 {
 	struct sk_buff *skb;
 	int err;
@@ -2653,7 +2659,8 @@ fail:
 	return NULL;
 }
 
-static inline int l2cap_get_conf_opt(void **ptr, int *type, int *olen, unsigned long *val)
+static inline int l2cap_get_conf_opt(void **ptr, int *type, int *olen,
+				     unsigned long *val)
 {
 	struct l2cap_conf_opt *opt = *ptr;
 	int len;
@@ -2744,7 +2751,7 @@ static void l2cap_add_opt_efs(void **ptr, struct l2cap_chan *chan)
 	}
 
 	l2cap_add_conf_opt(ptr, L2CAP_CONF_EFS, sizeof(efs),
-							(unsigned long) &efs);
+			   (unsigned long) &efs);
 }
 
 static void l2cap_ack_timeout(struct work_struct *work)
@@ -2833,13 +2840,13 @@ static inline bool __l2cap_efs_supported(struct l2cap_chan *chan)
 static inline void l2cap_txwin_setup(struct l2cap_chan *chan)
 {
 	if (chan->tx_win > L2CAP_DEFAULT_TX_WINDOW &&
-						__l2cap_ews_supported(chan)) {
+	    __l2cap_ews_supported(chan)) {
 		/* use extended control field */
 		set_bit(FLAG_EXT_CTRL, &chan->flags);
 		chan->tx_win_max = L2CAP_DEFAULT_EXT_WINDOW;
 	} else {
 		chan->tx_win = min_t(u16, chan->tx_win,
-						L2CAP_DEFAULT_TX_WINDOW);
+				     L2CAP_DEFAULT_TX_WINDOW);
 		chan->tx_win_max = L2CAP_DEFAULT_TX_WINDOW;
 	}
 	chan->ack_win = chan->tx_win;
@@ -2879,7 +2886,7 @@ done:
 	switch (chan->mode) {
 	case L2CAP_MODE_BASIC:
 		if (!(chan->conn->feat_mask & L2CAP_FEAT_ERTM) &&
-				!(chan->conn->feat_mask & L2CAP_FEAT_STREAMING))
+		    !(chan->conn->feat_mask & L2CAP_FEAT_STREAMING))
 			break;
 
 		rfc.mode            = L2CAP_MODE_BASIC;
@@ -2890,7 +2897,7 @@ done:
 		rfc.max_pdu_size    = 0;
 
 		l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC, sizeof(rfc),
-							(unsigned long) &rfc);
+				   (unsigned long) &rfc);
 		break;
 
 	case L2CAP_MODE_ERTM:
@@ -2900,18 +2907,17 @@ done:
 		rfc.monitor_timeout = 0;
 
 		size = min_t(u16, L2CAP_DEFAULT_MAX_PDU_SIZE, chan->conn->mtu -
-						L2CAP_EXT_HDR_SIZE -
-						L2CAP_SDULEN_SIZE -
-						L2CAP_FCS_SIZE);
+			     L2CAP_EXT_HDR_SIZE - L2CAP_SDULEN_SIZE -
+			     L2CAP_FCS_SIZE);
 		rfc.max_pdu_size = cpu_to_le16(size);
 
 		l2cap_txwin_setup(chan);
 
 		rfc.txwin_size = min_t(u16, chan->tx_win,
-						L2CAP_DEFAULT_TX_WINDOW);
+				       L2CAP_DEFAULT_TX_WINDOW);
 
 		l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC, sizeof(rfc),
-							(unsigned long) &rfc);
+				   (unsigned long) &rfc);
 
 		if (test_bit(FLAG_EFS_ENABLE, &chan->flags))
 			l2cap_add_opt_efs(&ptr, chan);
@@ -2920,14 +2926,14 @@ done:
 			break;
 
 		if (chan->fcs == L2CAP_FCS_NONE ||
-				test_bit(CONF_NO_FCS_RECV, &chan->conf_state)) {
+		    test_bit(CONF_NO_FCS_RECV, &chan->conf_state)) {
 			chan->fcs = L2CAP_FCS_NONE;
 			l2cap_add_conf_opt(&ptr, L2CAP_CONF_FCS, 1, chan->fcs);
 		}
 
 		if (test_bit(FLAG_EXT_CTRL, &chan->flags))
 			l2cap_add_conf_opt(&ptr, L2CAP_CONF_EWS, 2,
-								chan->tx_win);
+					   chan->tx_win);
 		break;
 
 	case L2CAP_MODE_STREAMING:
@@ -2939,13 +2945,12 @@ done:
 		rfc.monitor_timeout = 0;
 
 		size = min_t(u16, L2CAP_DEFAULT_MAX_PDU_SIZE, chan->conn->mtu -
-						L2CAP_EXT_HDR_SIZE -
-						L2CAP_SDULEN_SIZE -
-						L2CAP_FCS_SIZE);
+			     L2CAP_EXT_HDR_SIZE - L2CAP_SDULEN_SIZE -
+			     L2CAP_FCS_SIZE);
 		rfc.max_pdu_size = cpu_to_le16(size);
 
 		l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC, sizeof(rfc),
-							(unsigned long) &rfc);
+				   (unsigned long) &rfc);
 
 		if (test_bit(FLAG_EFS_ENABLE, &chan->flags))
 			l2cap_add_opt_efs(&ptr, chan);
@@ -2954,7 +2959,7 @@ done:
 			break;
 
 		if (chan->fcs == L2CAP_FCS_NONE ||
-				test_bit(CONF_NO_FCS_RECV, &chan->conf_state)) {
+		    test_bit(CONF_NO_FCS_RECV, &chan->conf_state)) {
 			chan->fcs = L2CAP_FCS_NONE;
 			l2cap_add_conf_opt(&ptr, L2CAP_CONF_FCS, 1, chan->fcs);
 		}
@@ -3046,7 +3051,7 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data)
 	case L2CAP_MODE_ERTM:
 		if (!test_bit(CONF_STATE2_DEVICE, &chan->conf_state)) {
 			chan->mode = l2cap_select_mode(rfc.mode,
-					chan->conn->feat_mask);
+						       chan->conn->feat_mask);
 			break;
 		}
 
@@ -3071,8 +3076,8 @@ done:
 		if (chan->num_conf_rsp == 1)
 			return -ECONNREFUSED;
 
-		l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC,
-					sizeof(rfc), (unsigned long) &rfc);
+		l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC, sizeof(rfc),
+				   (unsigned long) &rfc);
 	}
 
 	if (result == L2CAP_CONF_SUCCESS) {
@@ -3089,8 +3094,8 @@ done:
 
 		if (remote_efs) {
 			if (chan->local_stype != L2CAP_SERV_NOTRAFIC &&
-					efs.stype != L2CAP_SERV_NOTRAFIC &&
-					efs.stype != chan->local_stype) {
+			    efs.stype != L2CAP_SERV_NOTRAFIC &&
+			    efs.stype != chan->local_stype) {
 
 				result = L2CAP_CONF_UNACCEPT;
 
@@ -3098,8 +3103,8 @@ done:
 					return -ECONNREFUSED;
 
 				l2cap_add_conf_opt(&ptr, L2CAP_CONF_EFS,
-							sizeof(efs),
-							(unsigned long) &efs);
+						   sizeof(efs),
+						   (unsigned long) &efs);
 			} else {
 				/* Send PENDING Conf Rsp */
 				result = L2CAP_CONF_PENDING;
@@ -3122,10 +3127,8 @@ done:
 			chan->remote_max_tx = rfc.max_transmit;
 
 			size = min_t(u16, le16_to_cpu(rfc.max_pdu_size),
-						chan->conn->mtu -
-						L2CAP_EXT_HDR_SIZE -
-						L2CAP_SDULEN_SIZE -
-						L2CAP_FCS_SIZE);
+				     chan->conn->mtu - L2CAP_EXT_HDR_SIZE -
+				     L2CAP_SDULEN_SIZE - L2CAP_FCS_SIZE);
 			rfc.max_pdu_size = cpu_to_le16(size);
 			chan->remote_mps = size;
 
@@ -3137,36 +3140,35 @@ done:
 			set_bit(CONF_MODE_DONE, &chan->conf_state);
 
 			l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC,
-					sizeof(rfc), (unsigned long) &rfc);
+					   sizeof(rfc), (unsigned long) &rfc);
 
 			if (test_bit(FLAG_EFS_ENABLE, &chan->flags)) {
 				chan->remote_id = efs.id;
 				chan->remote_stype = efs.stype;
 				chan->remote_msdu = le16_to_cpu(efs.msdu);
 				chan->remote_flush_to =
-						le32_to_cpu(efs.flush_to);
+					le32_to_cpu(efs.flush_to);
 				chan->remote_acc_lat =
-						le32_to_cpu(efs.acc_lat);
+					le32_to_cpu(efs.acc_lat);
 				chan->remote_sdu_itime =
 					le32_to_cpu(efs.sdu_itime);
 				l2cap_add_conf_opt(&ptr, L2CAP_CONF_EFS,
-					sizeof(efs), (unsigned long) &efs);
+						   sizeof(efs),
+						   (unsigned long) &efs);
 			}
 			break;
 
 		case L2CAP_MODE_STREAMING:
 			size = min_t(u16, le16_to_cpu(rfc.max_pdu_size),
-						chan->conn->mtu -
-						L2CAP_EXT_HDR_SIZE -
-						L2CAP_SDULEN_SIZE -
-						L2CAP_FCS_SIZE);
+				     chan->conn->mtu - L2CAP_EXT_HDR_SIZE -
+				     L2CAP_SDULEN_SIZE - L2CAP_FCS_SIZE);
 			rfc.max_pdu_size = cpu_to_le16(size);
 			chan->remote_mps = size;
 
 			set_bit(CONF_MODE_DONE, &chan->conf_state);
 
-			l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC,
-					sizeof(rfc), (unsigned long) &rfc);
+			l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC, sizeof(rfc),
+					   (unsigned long) &rfc);
 
 			break;
 
@@ -3187,7 +3189,8 @@ done:
 	return ptr - data;
 }
 
-static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, void *data, u16 *result)
+static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
+				void *data, u16 *result)
 {
 	struct l2cap_conf_req *req = data;
 	void *ptr = req->data;
@@ -3214,7 +3217,7 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
 		case L2CAP_CONF_FLUSH_TO:
 			chan->flush_to = val;
 			l2cap_add_conf_opt(&ptr, L2CAP_CONF_FLUSH_TO,
-							2, chan->flush_to);
+					   2, chan->flush_to);
 			break;
 
 		case L2CAP_CONF_RFC:
@@ -3222,13 +3225,13 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
 				memcpy(&rfc, (void *)val, olen);
 
 			if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
-							rfc.mode != chan->mode)
+			    rfc.mode != chan->mode)
 				return -ECONNREFUSED;
 
 			chan->fcs = 0;
 
 			l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC,
-					sizeof(rfc), (unsigned long) &rfc);
+					   sizeof(rfc), (unsigned long) &rfc);
 			break;
 
 		case L2CAP_CONF_EWS:
@@ -3242,12 +3245,12 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
 				memcpy(&efs, (void *)val, olen);
 
 			if (chan->local_stype != L2CAP_SERV_NOTRAFIC &&
-					efs.stype != L2CAP_SERV_NOTRAFIC &&
-					efs.stype != chan->local_stype)
+			    efs.stype != L2CAP_SERV_NOTRAFIC &&
+			    efs.stype != chan->local_stype)
 				return -ECONNREFUSED;
 
-			l2cap_add_conf_opt(&ptr, L2CAP_CONF_EFS,
-					sizeof(efs), (unsigned long) &efs);
+			l2cap_add_conf_opt(&ptr, L2CAP_CONF_EFS, sizeof(efs),
+					   (unsigned long) &efs);
 			break;
 		}
 	}
@@ -3270,10 +3273,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
 			if (test_bit(FLAG_EFS_ENABLE, &chan->flags)) {
 				chan->local_msdu = le16_to_cpu(efs.msdu);
 				chan->local_sdu_itime =
-						le32_to_cpu(efs.sdu_itime);
+					le32_to_cpu(efs.sdu_itime);
 				chan->local_acc_lat = le32_to_cpu(efs.acc_lat);
 				chan->local_flush_to =
-						le32_to_cpu(efs.flush_to);
+					le32_to_cpu(efs.flush_to);
 			}
 			break;
 
@@ -3288,7 +3291,8 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
 	return ptr - data;
 }
 
-static int l2cap_build_conf_rsp(struct l2cap_chan *chan, void *data, u16 result, u16 flags)
+static int l2cap_build_conf_rsp(struct l2cap_chan *chan, void *data,
+				u16 result, u16 flags)
 {
 	struct l2cap_conf_rsp *rsp = data;
 	void *ptr = rsp->data;
@@ -3312,14 +3316,13 @@ void __l2cap_connect_rsp_defer(struct l2cap_chan *chan)
 	rsp.dcid   = cpu_to_le16(chan->scid);
 	rsp.result = __constant_cpu_to_le16(L2CAP_CR_SUCCESS);
 	rsp.status = __constant_cpu_to_le16(L2CAP_CS_NO_INFO);
-	l2cap_send_cmd(conn, chan->ident,
-				L2CAP_CONN_RSP, sizeof(rsp), &rsp);
+	l2cap_send_cmd(conn, chan->ident, L2CAP_CONN_RSP, sizeof(rsp), &rsp);
 
 	if (test_and_set_bit(CONF_REQ_SENT, &chan->conf_state))
 		return;
 
 	l2cap_send_cmd(conn, l2cap_get_ident(conn), L2CAP_CONF_REQ,
-			l2cap_build_conf_req(chan, buf), buf);
+		       l2cap_build_conf_req(chan, buf), buf);
 	chan->num_conf_req++;
 }
 
@@ -3374,7 +3377,8 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
 	}
 }
 
-static inline int l2cap_command_rej(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u8 *data)
+static inline int l2cap_command_rej(struct l2cap_conn *conn,
+				    struct l2cap_cmd_hdr *cmd, u8 *data)
 {
 	struct l2cap_cmd_rej_unk *rej = (struct l2cap_cmd_rej_unk *) data;
 
@@ -3382,7 +3386,7 @@ static inline int l2cap_command_rej(struct l2cap_conn *conn, struct l2cap_cmd_hd
 		return 0;
 
 	if ((conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_SENT) &&
-					cmd->ident == conn->info_ident) {
+	    cmd->ident == conn->info_ident) {
 		cancel_delayed_work(&conn->info_timer);
 
 		conn->info_state |= L2CAP_INFO_FEAT_MASK_REQ_DONE;
@@ -3394,7 +3398,8 @@ static inline int l2cap_command_rej(struct l2cap_conn *conn, struct l2cap_cmd_hd
 	return 0;
 }
 
-static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u8 *data)
+static inline int l2cap_connect_req(struct l2cap_conn *conn,
+				    struct l2cap_cmd_hdr *cmd, u8 *data)
 {
 	struct l2cap_conn_req *req = (struct l2cap_conn_req *) data;
 	struct l2cap_conn_rsp rsp;
@@ -3421,7 +3426,7 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd
 
 	/* Check if the ACL is secure enough (if not SDP) */
 	if (psm != __constant_cpu_to_le16(L2CAP_PSM_SDP) &&
-				!hci_conn_check_link_mode(conn->hcon)) {
+	    !hci_conn_check_link_mode(conn->hcon)) {
 		conn->disc_reason = HCI_ERROR_AUTH_FAILURE;
 		result = L2CAP_CR_SEC_BLOCK;
 		goto response;
@@ -3499,23 +3504,24 @@ sendresp:
 
 		schedule_delayed_work(&conn->info_timer, L2CAP_INFO_TIMEOUT);
 
-		l2cap_send_cmd(conn, conn->info_ident,
-					L2CAP_INFO_REQ, sizeof(info), &info);
+		l2cap_send_cmd(conn, conn->info_ident, L2CAP_INFO_REQ,
+			       sizeof(info), &info);
 	}
 
 	if (chan && !test_bit(CONF_REQ_SENT, &chan->conf_state) &&
-				result == L2CAP_CR_SUCCESS) {
+	    result == L2CAP_CR_SUCCESS) {
 		u8 buf[128];
 		set_bit(CONF_REQ_SENT, &chan->conf_state);
 		l2cap_send_cmd(conn, l2cap_get_ident(conn), L2CAP_CONF_REQ,
-					l2cap_build_conf_req(chan, buf), buf);
+			       l2cap_build_conf_req(chan, buf), buf);
 		chan->num_conf_req++;
 	}
 
 	return 0;
 }
 
-static inline int l2cap_connect_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u8 *data)
+static inline int l2cap_connect_rsp(struct l2cap_conn *conn,
+				    struct l2cap_cmd_hdr *cmd, u8 *data)
 {
 	struct l2cap_conn_rsp *rsp = (struct l2cap_conn_rsp *) data;
 	u16 scid, dcid, result, status;
@@ -3529,7 +3535,7 @@ static inline int l2cap_connect_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hd
 	status = __le16_to_cpu(rsp->status);
 
 	BT_DBG("dcid 0x%4.4x scid 0x%4.4x result 0x%2.2x status 0x%2.2x",
-						dcid, scid, result, status);
+	       dcid, scid, result, status);
 
 	mutex_lock(&conn->chan_lock);
 
@@ -3562,7 +3568,7 @@ static inline int l2cap_connect_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hd
 			break;
 
 		l2cap_send_cmd(conn, l2cap_get_ident(conn), L2CAP_CONF_REQ,
-					l2cap_build_conf_req(chan, req), req);
+			       l2cap_build_conf_req(chan, req), req);
 		chan->num_conf_req++;
 		break;
 
@@ -3610,7 +3616,9 @@ static void l2cap_send_efs_conf_rsp(struct l2cap_chan *chan, void *data,
 					    L2CAP_CONF_SUCCESS, flags), data);
 }
 
-static inline int l2cap_config_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data)
+static inline int l2cap_config_req(struct l2cap_conn *conn,
+				   struct l2cap_cmd_hdr *cmd, u16 cmd_len,
+				   u8 *data)
 {
 	struct l2cap_conf_req *req = (struct l2cap_conf_req *) data;
 	u16 dcid, flags;
@@ -3635,7 +3643,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr
 		rej.dcid = cpu_to_le16(chan->dcid);
 
 		l2cap_send_cmd(conn, cmd->ident, L2CAP_COMMAND_REJ,
-				sizeof(rej), &rej);
+			       sizeof(rej), &rej);
 		goto unlock;
 	}
 
@@ -3643,8 +3651,8 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr
 	len = cmd_len - sizeof(*req);
 	if (len < 0 || chan->conf_len + len > sizeof(chan->conf_req)) {
 		l2cap_send_cmd(conn, cmd->ident, L2CAP_CONF_RSP,
-				l2cap_build_conf_rsp(chan, rsp,
-					L2CAP_CONF_REJECT, flags), rsp);
+			       l2cap_build_conf_rsp(chan, rsp,
+			       L2CAP_CONF_REJECT, flags), rsp);
 		goto unlock;
 	}
 
@@ -3655,8 +3663,8 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr
 	if (flags & L2CAP_CONF_FLAG_CONTINUATION) {
 		/* Incomplete config. Send empty response. */
 		l2cap_send_cmd(conn, cmd->ident, L2CAP_CONF_RSP,
-				l2cap_build_conf_rsp(chan, rsp,
-					L2CAP_CONF_SUCCESS, flags), rsp);
+			       l2cap_build_conf_rsp(chan, rsp,
+			       L2CAP_CONF_SUCCESS, flags), rsp);
 		goto unlock;
 	}
 
@@ -3694,7 +3702,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr
 	if (!test_and_set_bit(CONF_REQ_SENT, &chan->conf_state)) {
 		u8 buf[64];
 		l2cap_send_cmd(conn, l2cap_get_ident(conn), L2CAP_CONF_REQ,
-					l2cap_build_conf_req(chan, buf), buf);
+			       l2cap_build_conf_req(chan, buf), buf);
 		chan->num_conf_req++;
 	}
 
@@ -3713,7 +3721,8 @@ unlock:
 	return err;
 }
 
-static inline int l2cap_config_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u8 *data)
+static inline int l2cap_config_rsp(struct l2cap_conn *conn,
+				   struct l2cap_cmd_hdr *cmd, u8 *data)
 {
 	struct l2cap_conf_rsp *rsp = (struct l2cap_conf_rsp *)data;
 	u16 scid, flags, result;
@@ -3745,7 +3754,7 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr
 			char buf[64];
 
 			len = l2cap_parse_conf_rsp(chan, rsp->data, len,
-								buf, &result);
+						   buf, &result);
 			if (len < 0) {
 				l2cap_send_disconn_req(conn, chan, ECONNRESET);
 				goto done;
@@ -3769,14 +3778,14 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr
 			/* throw out any old stored conf requests */
 			result = L2CAP_CONF_SUCCESS;
 			len = l2cap_parse_conf_rsp(chan, rsp->data, len,
-								req, &result);
+						   req, &result);
 			if (len < 0) {
 				l2cap_send_disconn_req(conn, chan, ECONNRESET);
 				goto done;
 			}
 
 			l2cap_send_cmd(conn, l2cap_get_ident(conn),
-						L2CAP_CONF_REQ, len, req);
+				       L2CAP_CONF_REQ, len, req);
 			chan->num_conf_req++;
 			if (result != L2CAP_CONF_SUCCESS)
 				goto done;
@@ -3814,7 +3823,8 @@ done:
 	return err;
 }
 
-static inline int l2cap_disconnect_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u8 *data)
+static inline int l2cap_disconnect_req(struct l2cap_conn *conn,
+				       struct l2cap_cmd_hdr *cmd, u8 *data)
 {
 	struct l2cap_disconn_req *req = (struct l2cap_disconn_req *) data;
 	struct l2cap_disconn_rsp rsp;
@@ -3860,7 +3870,8 @@ static inline int l2cap_disconnect_req(struct l2cap_conn *conn, struct l2cap_cmd
 	return 0;
 }
 
-static inline int l2cap_disconnect_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u8 *data)
+static inline int l2cap_disconnect_rsp(struct l2cap_conn *conn,
+				       struct l2cap_cmd_hdr *cmd, u8 *data)
 {
 	struct l2cap_disconn_rsp *rsp = (struct l2cap_disconn_rsp *) data;
 	u16 dcid, scid;
@@ -3894,7 +3905,8 @@ static inline int l2cap_disconnect_rsp(struct l2cap_conn *conn, struct l2cap_cmd
 	return 0;
 }
 
-static inline int l2cap_information_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u8 *data)
+static inline int l2cap_information_req(struct l2cap_conn *conn,
+					struct l2cap_cmd_hdr *cmd, u8 *data)
 {
 	struct l2cap_info_req *req = (struct l2cap_info_req *) data;
 	u16 type;
@@ -3911,14 +3923,14 @@ static inline int l2cap_information_req(struct l2cap_conn *conn, struct l2cap_cm
 		rsp->result = __constant_cpu_to_le16(L2CAP_IR_SUCCESS);
 		if (!disable_ertm)
 			feat_mask |= L2CAP_FEAT_ERTM | L2CAP_FEAT_STREAMING
-							 | L2CAP_FEAT_FCS;
+				| L2CAP_FEAT_FCS;
 		if (enable_hs)
 			feat_mask |= L2CAP_FEAT_EXT_FLOW
-						| L2CAP_FEAT_EXT_WINDOW;
+				| L2CAP_FEAT_EXT_WINDOW;
 
 		put_unaligned_le32(feat_mask, rsp->data);
-		l2cap_send_cmd(conn, cmd->ident,
-					L2CAP_INFO_RSP, sizeof(buf), buf);
+		l2cap_send_cmd(conn, cmd->ident, L2CAP_INFO_RSP, sizeof(buf),
+			       buf);
 	} else if (type == L2CAP_IT_FIXED_CHAN) {
 		u8 buf[12];
 		struct l2cap_info_rsp *rsp = (struct l2cap_info_rsp *) buf;
@@ -3931,20 +3943,21 @@ static inline int l2cap_information_req(struct l2cap_conn *conn, struct l2cap_cm
 		rsp->type   = __constant_cpu_to_le16(L2CAP_IT_FIXED_CHAN);
 		rsp->result = __constant_cpu_to_le16(L2CAP_IR_SUCCESS);
 		memcpy(rsp->data, l2cap_fixed_chan, sizeof(l2cap_fixed_chan));
-		l2cap_send_cmd(conn, cmd->ident,
-					L2CAP_INFO_RSP, sizeof(buf), buf);
+		l2cap_send_cmd(conn, cmd->ident, L2CAP_INFO_RSP, sizeof(buf),
+			       buf);
 	} else {
 		struct l2cap_info_rsp rsp;
 		rsp.type   = cpu_to_le16(type);
 		rsp.result = __constant_cpu_to_le16(L2CAP_IR_NOTSUPP);
-		l2cap_send_cmd(conn, cmd->ident,
-					L2CAP_INFO_RSP, sizeof(rsp), &rsp);
+		l2cap_send_cmd(conn, cmd->ident, L2CAP_INFO_RSP, sizeof(rsp),
+			       &rsp);
 	}
 
 	return 0;
 }
 
-static inline int l2cap_information_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd, u8 *data)
+static inline int l2cap_information_rsp(struct l2cap_conn *conn,
+					struct l2cap_cmd_hdr *cmd, u8 *data)
 {
 	struct l2cap_info_rsp *rsp = (struct l2cap_info_rsp *) data;
 	u16 type, result;
@@ -3956,7 +3969,7 @@ static inline int l2cap_information_rsp(struct l2cap_conn *conn, struct l2cap_cm
 
 	/* L2CAP Info req/rsp are unbound to channels, add extra checks */
 	if (cmd->ident != conn->info_ident ||
-			conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE)
+	    conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE)
 		return 0;
 
 	cancel_delayed_work(&conn->info_timer);
@@ -3981,7 +3994,7 @@ static inline int l2cap_information_rsp(struct l2cap_conn *conn, struct l2cap_cm
 			conn->info_ident = l2cap_get_ident(conn);
 
 			l2cap_send_cmd(conn, conn->info_ident,
-					L2CAP_INFO_REQ, sizeof(req), &req);
+				       L2CAP_INFO_REQ, sizeof(req), &req);
 		} else {
 			conn->info_state |= L2CAP_INFO_FEAT_MASK_REQ_DONE;
 			conn->info_ident = 0;
@@ -4003,8 +4016,8 @@ static inline int l2cap_information_rsp(struct l2cap_conn *conn, struct l2cap_cm
 }
 
 static inline int l2cap_create_channel_req(struct l2cap_conn *conn,
-					struct l2cap_cmd_hdr *cmd, u16 cmd_len,
-					void *data)
+					   struct l2cap_cmd_hdr *cmd,
+					   u16 cmd_len, void *data)
 {
 	struct l2cap_create_chan_req *req = data;
 	struct l2cap_create_chan_rsp rsp;
@@ -4034,7 +4047,8 @@ static inline int l2cap_create_channel_req(struct l2cap_conn *conn,
 }
 
 static inline int l2cap_create_channel_rsp(struct l2cap_conn *conn,
-					struct l2cap_cmd_hdr *cmd, void *data)
+					   struct l2cap_cmd_hdr *cmd,
+					   void *data)
 {
 	BT_DBG("conn %p", conn);
 
@@ -4167,7 +4181,7 @@ static inline int l2cap_move_channel_confirm_rsp(struct l2cap_conn *conn,
 }
 
 static inline int l2cap_check_conn_param(u16 min, u16 max, u16 latency,
-							u16 to_multiplier)
+					 u16 to_multiplier)
 {
 	u16 max_latency;
 
@@ -4188,7 +4202,8 @@ static inline int l2cap_check_conn_param(u16 min, u16 max, u16 latency,
 }
 
 static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn,
-					struct l2cap_cmd_hdr *cmd, u8 *data)
+					      struct l2cap_cmd_hdr *cmd,
+					      u8 *data)
 {
 	struct hci_conn *hcon = conn->hcon;
 	struct l2cap_conn_param_update_req *req;
@@ -4210,7 +4225,7 @@ static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn,
 	to_multiplier	= __le16_to_cpu(req->to_multiplier);
 
 	BT_DBG("min 0x%4.4x max 0x%4.4x latency: 0x%4.4x Timeout: 0x%4.4x",
-						min, max, latency, to_multiplier);
+	       min, max, latency, to_multiplier);
 
 	memset(&rsp, 0, sizeof(rsp));
 
@@ -4221,7 +4236,7 @@ static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn,
 		rsp.result = __constant_cpu_to_le16(L2CAP_CONN_PARAM_ACCEPTED);
 
 	l2cap_send_cmd(conn, cmd->ident, L2CAP_CONN_PARAM_UPDATE_RSP,
-							sizeof(rsp), &rsp);
+		       sizeof(rsp), &rsp);
 
 	if (!err)
 		hci_le_conn_update(hcon, min, max, latency, to_multiplier);
@@ -4230,7 +4245,8 @@ static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn,
 }
 
 static inline int l2cap_bredr_sig_cmd(struct l2cap_conn *conn,
-			struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data)
+				      struct l2cap_cmd_hdr *cmd, u16 cmd_len,
+				      u8 *data)
 {
 	int err = 0;
 
@@ -4312,7 +4328,7 @@ static inline int l2cap_bredr_sig_cmd(struct l2cap_conn *conn,
 }
 
 static inline int l2cap_le_sig_cmd(struct l2cap_conn *conn,
-					struct l2cap_cmd_hdr *cmd, u8 *data)
+				   struct l2cap_cmd_hdr *cmd, u8 *data)
 {
 	switch (cmd->code) {
 	case L2CAP_COMMAND_REJ:
@@ -4331,7 +4347,7 @@ static inline int l2cap_le_sig_cmd(struct l2cap_conn *conn,
 }
 
 static inline void l2cap_sig_channel(struct l2cap_conn *conn,
-							struct sk_buff *skb)
+				     struct sk_buff *skb)
 {
 	u8 *data = skb->data;
 	int len = skb->len;
@@ -4348,7 +4364,8 @@ static inline void l2cap_sig_channel(struct l2cap_conn *conn,
 
 		cmd_len = le16_to_cpu(cmd.len);
 
-		BT_DBG("code 0x%2.2x len %d id 0x%2.2x", cmd.code, cmd_len, cmd.ident);
+		BT_DBG("code 0x%2.2x len %d id 0x%2.2x", cmd.code, cmd_len,
+		       cmd.ident);
 
 		if (cmd_len > len || !cmd.ident) {
 			BT_DBG("corrupted command");
@@ -4367,7 +4384,8 @@ static inline void l2cap_sig_channel(struct l2cap_conn *conn,
 
 			/* FIXME: Map err to a valid reason */
 			rej.reason = __constant_cpu_to_le16(L2CAP_REJ_NOT_UNDERSTOOD);
-			l2cap_send_cmd(conn, cmd.ident, L2CAP_COMMAND_REJ, sizeof(rej), &rej);
+			l2cap_send_cmd(conn, cmd.ident, L2CAP_COMMAND_REJ,
+				       sizeof(rej), &rej);
 		}
 
 		data += cmd_len;
@@ -4432,8 +4450,8 @@ static void l2cap_send_i_or_rr_or_rnr(struct l2cap_chan *chan)
 	}
 }
 
-static void append_skb_frag(struct sk_buff *skb,
-			struct sk_buff *new_frag, struct sk_buff **last_frag)
+static void append_skb_frag(struct sk_buff *skb, struct sk_buff *new_frag,
+			    struct sk_buff **last_frag)
 {
 	/* skb->len reflects data in skb as well as all fragments
 	 * skb->data_len reflects only data in fragments
@@ -4682,7 +4700,7 @@ static u8 l2cap_classify_txseq(struct l2cap_chan *chan, u16 txseq)
 
 	if (chan->rx_state == L2CAP_RX_STATE_SREJ_SENT) {
 		if (__seq_offset(chan, txseq, chan->last_acked_seq) >=
-								chan->tx_win) {
+		    chan->tx_win) {
 			/* See notes below regarding "double poll" and
 			 * invalid packets.
 			 */
@@ -4723,8 +4741,7 @@ static u8 l2cap_classify_txseq(struct l2cap_chan *chan, u16 txseq)
 	}
 
 	if (__seq_offset(chan, txseq, chan->last_acked_seq) <
-		__seq_offset(chan, chan->expected_tx_seq,
-			     chan->last_acked_seq)){
+	    __seq_offset(chan, chan->expected_tx_seq, chan->last_acked_seq)) {
 		BT_DBG("Duplicate - expected_tx_seq later than txseq");
 		return L2CAP_TXSEQ_DUPLICATE;
 	}
@@ -5484,7 +5501,7 @@ int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
 		}
 
 		if (!status && (chan->state == BT_CONNECTED ||
-						chan->state == BT_CONFIG)) {
+				chan->state == BT_CONFIG)) {
 			struct sock *sk = chan->sk;
 
 			clear_bit(BT_SK_SUSPEND, &bt_sk(sk)->flags);
@@ -5535,7 +5552,7 @@ int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
 			rsp.result = cpu_to_le16(res);
 			rsp.status = cpu_to_le16(stat);
 			l2cap_send_cmd(conn, chan->ident, L2CAP_CONN_RSP,
-							sizeof(rsp), &rsp);
+				       sizeof(rsp), &rsp);
 
 			if (!test_bit(CONF_REQ_SENT, &chan->conf_state) &&
 			    res == L2CAP_CR_SUCCESS) {
@@ -5601,7 +5618,7 @@ int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags)
 
 		if (skb->len > len) {
 			BT_ERR("Frame is too long (len %d, expected len %d)",
-				skb->len, len);
+			       skb->len, len);
 			l2cap_conn_unreliable(conn, ECOMM);
 			goto drop;
 		}
@@ -5612,7 +5629,7 @@ int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags)
 			goto drop;
 
 		skb_copy_from_linear_data(skb, skb_put(conn->rx_skb, skb->len),
-								skb->len);
+					  skb->len);
 		conn->rx_len = len - skb->len;
 	} else {
 		BT_DBG("Cont: frag len %d (expecting %d)", skb->len, conn->rx_len);
@@ -5625,7 +5642,7 @@ int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags)
 
 		if (skb->len > conn->rx_len) {
 			BT_ERR("Fragment is too long (len %d, expected %d)",
-					skb->len, conn->rx_len);
+			       skb->len, conn->rx_len);
 			kfree_skb(conn->rx_skb);
 			conn->rx_skb = NULL;
 			conn->rx_len = 0;
@@ -5634,7 +5651,7 @@ int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags)
 		}
 
 		skb_copy_from_linear_data(skb, skb_put(conn->rx_skb, skb->len),
-								skb->len);
+					  skb->len);
 		conn->rx_len -= skb->len;
 
 		if (!conn->rx_len) {
@@ -5693,8 +5710,8 @@ int __init l2cap_init(void)
 		return err;
 
 	if (bt_debugfs) {
-		l2cap_debugfs = debugfs_create_file("l2cap", 0444,
-					bt_debugfs, NULL, &l2cap_debugfs_fops);
+		l2cap_debugfs = debugfs_create_file("l2cap", 0444, bt_debugfs,
+						    NULL, &l2cap_debugfs_fops);
 		if (!l2cap_debugfs)
 			BT_ERR("Failed to create L2CAP debug file");
 	}
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index a71c408..dd593c9 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -40,7 +40,8 @@ static struct bt_sock_list l2cap_sk_list = {
 
 static const struct proto_ops l2cap_sock_ops;
 static void l2cap_sock_init(struct sock *sk, struct sock *parent);
-static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, int proto, gfp_t prio);
+static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock,
+				     int proto, gfp_t prio);
 
 static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
 {
@@ -106,7 +107,8 @@ done:
 	return err;
 }
 
-static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr, int alen, int flags)
+static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr,
+			      int alen, int flags)
 {
 	struct sock *sk = sock->sk;
 	struct l2cap_chan *chan = l2cap_pi(sk)->chan;
@@ -134,7 +136,7 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr, int al
 	lock_sock(sk);
 
 	err = bt_sock_wait_state(sk, BT_CONNECTED,
-			sock_sndtimeo(sk, flags & O_NONBLOCK));
+				 sock_sndtimeo(sk, flags & O_NONBLOCK));
 
 	release_sock(sk);
 
@@ -185,7 +187,8 @@ done:
 	return err;
 }
 
-static int l2cap_sock_accept(struct socket *sock, struct socket *newsock, int flags)
+static int l2cap_sock_accept(struct socket *sock, struct socket *newsock,
+			     int flags)
 {
 	DECLARE_WAITQUEUE(wait, current);
 	struct sock *sk = sock->sk, *nsk;
@@ -241,7 +244,8 @@ done:
 	return err;
 }
 
-static int l2cap_sock_getname(struct socket *sock, struct sockaddr *addr, int *len, int peer)
+static int l2cap_sock_getname(struct socket *sock, struct sockaddr *addr,
+			      int *len, int peer)
 {
 	struct sockaddr_l2 *la = (struct sockaddr_l2 *) addr;
 	struct sock *sk = sock->sk;
@@ -265,7 +269,8 @@ static int l2cap_sock_getname(struct socket *sock, struct sockaddr *addr, int *l
 	return 0;
 }
 
-static int l2cap_sock_getsockopt_old(struct socket *sock, int optname, char __user *optval, int __user *optlen)
+static int l2cap_sock_getsockopt_old(struct socket *sock, int optname,
+				     char __user *optval, int __user *optlen)
 {
 	struct sock *sk = sock->sk;
 	struct l2cap_chan *chan = l2cap_pi(sk)->chan;
@@ -308,7 +313,7 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname, char __us
 			break;
 		case BT_SECURITY_HIGH:
 			opt = L2CAP_LM_AUTH | L2CAP_LM_ENCRYPT |
-							L2CAP_LM_SECURE;
+			      L2CAP_LM_SECURE;
 			break;
 		default:
 			opt = 0;
@@ -352,7 +357,8 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname, char __us
 	return err;
 }
 
-static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, char __user *optval, int __user *optlen)
+static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname,
+				 char __user *optval, int __user *optlen)
 {
 	struct sock *sk = sock->sk;
 	struct l2cap_chan *chan = l2cap_pi(sk)->chan;
@@ -376,7 +382,7 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, ch
 	switch (optname) {
 	case BT_SECURITY:
 		if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED &&
-					chan->chan_type != L2CAP_CHAN_RAW) {
+		    chan->chan_type != L2CAP_CHAN_RAW) {
 			err = -EINVAL;
 			break;
 		}
@@ -411,14 +417,14 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, ch
 
 	case BT_FLUSHABLE:
 		if (put_user(test_bit(FLAG_FLUSHABLE, &chan->flags),
-						(u32 __user *) optval))
+			     (u32 __user *) optval))
 			err = -EFAULT;
 
 		break;
 
 	case BT_POWER:
 		if (sk->sk_type != SOCK_SEQPACKET && sk->sk_type != SOCK_STREAM
-				&& sk->sk_type != SOCK_RAW) {
+		    && sk->sk_type != SOCK_RAW) {
 			err = -EINVAL;
 			break;
 		}
@@ -466,7 +472,8 @@ static bool l2cap_valid_mtu(struct l2cap_chan *chan, u16 mtu)
 	return true;
 }
 
-static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __user *optval, unsigned int optlen)
+static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
+				     char __user *optval, unsigned int optlen)
 {
 	struct sock *sk = sock->sk;
 	struct l2cap_chan *chan = l2cap_pi(sk)->chan;
@@ -564,7 +571,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
 	return err;
 }
 
-static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen)
+static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
+				 char __user *optval, unsigned int optlen)
 {
 	struct sock *sk = sock->sk;
 	struct l2cap_chan *chan = l2cap_pi(sk)->chan;
@@ -587,7 +595,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
 	switch (optname) {
 	case BT_SECURITY:
 		if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED &&
-					chan->chan_type != L2CAP_CHAN_RAW) {
+		    chan->chan_type != L2CAP_CHAN_RAW) {
 			err = -EINVAL;
 			break;
 		}
@@ -601,7 +609,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
 		}
 
 		if (sec.level < BT_SECURITY_LOW ||
-					sec.level > BT_SECURITY_HIGH) {
+		    sec.level > BT_SECURITY_HIGH) {
 			err = -EINVAL;
 			break;
 		}
@@ -627,7 +635,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
 
 		/* or for ACL link */
 		} else if ((sk->sk_state == BT_CONNECT2 &&
-			   test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) ||
+			    test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) ||
 			   sk->sk_state == BT_CONNECTED) {
 			if (!l2cap_chan_check_security(chan))
 				set_bit(BT_SK_SUSPEND, &bt_sk(sk)->flags);
@@ -684,7 +692,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
 
 	case BT_POWER:
 		if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED &&
-					chan->chan_type != L2CAP_CHAN_RAW) {
+		    chan->chan_type != L2CAP_CHAN_RAW) {
 			err = -EINVAL;
 			break;
 		}
@@ -720,7 +728,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
 		}
 
 		if (chan->mode != L2CAP_MODE_ERTM &&
-				chan->mode != L2CAP_MODE_STREAMING) {
+		    chan->mode != L2CAP_MODE_STREAMING) {
 			err = -EOPNOTSUPP;
 			break;
 		}
@@ -737,7 +745,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
 	return err;
 }
 
-static int l2cap_sock_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, size_t len)
+static int l2cap_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
+			      struct msghdr *msg, size_t len)
 {
 	struct sock *sk = sock->sk;
 	struct l2cap_chan *chan = l2cap_pi(sk)->chan;
@@ -762,7 +771,8 @@ static int l2cap_sock_sendmsg(struct kiocb *iocb, struct socket *sock, struct ms
 	return err;
 }
 
-static int l2cap_sock_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, size_t len, int flags)
+static int l2cap_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
+			      struct msghdr *msg, size_t len, int flags)
 {
 	struct sock *sk = sock->sk;
 	struct l2cap_pinfo *pi = l2cap_pi(sk);
@@ -866,7 +876,7 @@ static int l2cap_sock_shutdown(struct socket *sock, int how)
 
 		if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime)
 			err = bt_sock_wait_state(sk, BT_CLOSED,
-							sk->sk_lingertime);
+						 sk->sk_lingertime);
 	}
 
 	if (!err && sk->sk_err)
@@ -930,7 +940,7 @@ static struct l2cap_chan *l2cap_sock_new_connection_cb(struct l2cap_chan *chan)
 	}
 
 	sk = l2cap_sock_alloc(sock_net(parent), NULL, BTPROTO_L2CAP,
-								GFP_ATOMIC);
+			      GFP_ATOMIC);
 	if (!sk)
 		return NULL;
 
@@ -1159,7 +1169,8 @@ static struct proto l2cap_proto = {
 	.obj_size	= sizeof(struct l2cap_pinfo)
 };
 
-static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, int proto, gfp_t prio)
+static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock,
+				     int proto, gfp_t prio)
 {
 	struct sock *sk;
 	struct l2cap_chan *chan;
@@ -1204,7 +1215,7 @@ static int l2cap_sock_create(struct net *net, struct socket *sock, int protocol,
 	sock->state = SS_UNCONNECTED;
 
 	if (sock->type != SOCK_SEQPACKET && sock->type != SOCK_STREAM &&
-			sock->type != SOCK_DGRAM && sock->type != SOCK_RAW)
+	    sock->type != SOCK_DGRAM && sock->type != SOCK_RAW)
 		return -ESOCKTNOSUPPORT;
 
 	if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
@@ -1261,7 +1272,8 @@ int __init l2cap_init_sockets(void)
 		goto error;
 	}
 
-	err = bt_procfs_init(THIS_MODULE, &init_net, "l2cap", &l2cap_sk_list, NULL);
+	err = bt_procfs_init(THIS_MODULE, &init_net, "l2cap", &l2cap_sk_list,
+			     NULL);
 	if (err < 0) {
 		BT_ERR("Failed to create L2CAP proc file");
 		bt_sock_unregister(BTPROTO_L2CAP);
-- 
1.7.11.4


^ permalink raw reply related

* [PATCH -v2 6/6] bt tool: add cmd 'adapter'
From: Gustavo Padovan @ 2012-10-07 22:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo Padovan
In-Reply-To: <1349650197-18751-1-git-send-email-gustavo@padovan.org>

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

'bt adapter' sets adapter properties Powered, Name, Pairable,
PairableTimeout, Discoverable, DiscoverableTimeout.
---
 client/main.c | 185 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 178 insertions(+), 7 deletions(-)

diff --git a/client/main.c b/client/main.c
index aeb47e4..115d7ed 100644
--- a/client/main.c
+++ b/client/main.c
@@ -74,6 +74,12 @@ struct cmd_struct {
 	GSourceFunc	fn;
 };
 
+struct subcmd_methods {
+	const char	*subcmd;
+	const char	*dbus_name;
+	int		dbus_type;
+};
+
 struct find_adapter_cb_data {
 	GSourceFunc		fn;
 	struct cmd_param	*param;
@@ -94,15 +100,22 @@ static void show_help()
 	printf("usage: %s [-i interface] <command> [<args>]\n"
 	"\n"
 	"options:\n"
-	"	-i <hci dev>, --interface <hci dev>	HCI device\n"
-	"	--help					This help\n"
-	"	--version				Version\n"
+	"	-i <dev>, --interface <dev>	HCI device\n"
+	"	--help				This help\n"
+	"	--version			Version\n"
 	"\n"
 	"commands:\n"
-	"	discover				Scan for devices\n"
-	"	pair <device address>			Start pairing\n"
-	"	agent					Run BlueZ agent\n"
-	"	remove					Remove a paired device\n"
+	"	discove				Scan for devices\n"
+	"	pair <device address>		Start pairing\n"
+	"	agent				Run BlueZ agent\n"
+	"	remove				Remove a paired device\n"
+	"	adapter\n"
+	"		powered			Set adapter's powered state\n"
+	"		name			Set adapter's name\n"
+	"		discoverable		Set adapter's discoverable state\n"
+	"		discoverabletimeout	Set adapter's discoverable timeout\n"
+	"		pairable		Set adapter's pairable state\n"
+	"		pairabletimeout		Set adapter's pairable timeout\n"
 							"\n", program_name);
 
 	if(mainloop != NULL)
@@ -283,6 +296,67 @@ static gboolean send_with_reply_and_set_notify(DBusMessage *msg,
 	return TRUE;
 }
 
+static void bluetooth_property_append_basic(DBusMessageIter *iter,
+					const char *key, int type, void *val)
+{
+	DBusMessageIter value;
+	const char *signature;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &key);
+
+	switch (type) {
+	case DBUS_TYPE_BOOLEAN:
+		signature = DBUS_TYPE_BOOLEAN_AS_STRING;
+		break;
+	case DBUS_TYPE_STRING:
+		signature = DBUS_TYPE_STRING_AS_STRING;
+		break;
+	case DBUS_TYPE_UINT32:
+		signature = DBUS_TYPE_UINT32_AS_STRING;
+		break;
+	default:
+		signature = DBUS_TYPE_VARIANT_AS_STRING;
+		break;
+	}
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
+							signature, &value);
+	dbus_message_iter_append_basic(&value, type, val);
+	dbus_message_iter_close_container(iter, &value);
+}
+
+static gboolean bluetooth_append_args(DBusMessage *msg,
+					struct subcmd_methods *m, char *param)
+{
+	DBusMessageIter iter;
+	unsigned int value;
+
+	dbus_message_iter_init_append(msg, &iter);
+
+	switch (m->dbus_type) {
+	case DBUS_TYPE_STRING:
+		bluetooth_property_append_basic(&iter, m->dbus_name,
+							m->dbus_type, &param);
+	case DBUS_TYPE_UINT32:
+		value = atol(param);
+		bluetooth_property_append_basic(&iter, m->dbus_name,
+						m->dbus_type, &value);
+	case DBUS_TYPE_BOOLEAN:
+		if (g_str_equal(param, "yes"))
+			value = TRUE;
+		else if (g_str_equal(param, "no"))
+			value = FALSE;
+		else
+			return FALSE;
+
+		bluetooth_property_append_basic(&iter, m->dbus_name,
+						m->dbus_type, &value);
+		break;
+	}
+
+	return TRUE;
+}
+
 static DBusMessage *agent_request_confirmation(DBusConnection *conn,
 						DBusMessage *msg, void *data)
 {
@@ -829,6 +903,42 @@ static void find_device_reply(DBusPendingCall *pending, void *user_data)
 	dbus_pending_call_unref(pending);
 }
 
+static void set_property_reply(DBusPendingCall *pending, void *user_data)
+{
+	DBusMessage *reply;
+	DBusError err;
+
+	if (!pending)
+		return;
+
+	dbus_pending_call_ref(pending);
+
+	reply = dbus_pending_call_steal_reply(pending);
+	if (!reply) {
+		ERR("Failed to find SetProperty() reply");
+		exit(1);
+	}
+
+	dbus_error_init(&err);
+	if (!dbus_message_get_args(reply, &err, DBUS_TYPE_INVALID)) {
+		if (dbus_error_is_set(&err)) {
+			ERR("Failed to set property: %s", err.message);
+			dbus_error_free(&err);
+		}
+		exit(1);
+	}
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		ERR("SetProperty() failed");
+		exit(1);
+	}
+
+	dbus_message_unref(reply);
+	dbus_pending_call_unref(pending);
+
+	g_main_loop_quit(mainloop);
+}
+
 /* Listen for Bluetooth devices broadcasting their availability, then display
  * the results */
 static gboolean cmd_discover(gpointer data)
@@ -964,6 +1074,66 @@ static gboolean cmd_remove(gpointer data)
 	return retval;
 }
 
+static struct subcmd_methods adapter_m[] = {
+	{ "powered",		 "Powered",		DBUS_TYPE_BOOLEAN},
+	{ "name",                "Name",		DBUS_TYPE_STRING},
+	{ "discoverable",        "Discoverable",	DBUS_TYPE_BOOLEAN},
+	{ "discoverabletimeout", "DiscoverableTimeout",	DBUS_TYPE_UINT32},
+	{ "pairable",	         "Pairable",		DBUS_TYPE_BOOLEAN},
+	{ "pairabletimeout",     "PairableTimeout",	DBUS_TYPE_UINT32},
+	{  NULL,                 NULL,                  DBUS_TYPE_INVALID},
+};
+
+static gboolean cmd_adapter(gpointer data)
+{
+	struct cmd_param *p = data;
+	char *subcmd, *param;
+	struct subcmd_methods *m;
+	DBusMessage *msg;
+	int i;
+
+	subcmd = p->argv[0];
+	p->argc--;
+	if (!subcmd) {
+		ERR("%s: missing command paramenter", program_name);
+		show_help();
+		exit(1);
+	}
+
+	param = p->argv[1];
+
+	for (i = 0; i < ARRAY_SIZE(adapter_m); i++) {
+		m = adapter_m+i;
+		if (!m->subcmd) {
+			ERR("%s: command not found", program_name);
+			show_help();
+			exit(1);
+		}
+
+		if (g_str_equal(m->subcmd, subcmd))
+			break;
+	}
+
+	if (!(msg = create_method_call(p->path, BLUEZ_ADAPTER, "SetProperty")))
+		return FALSE;
+
+	if (!bluetooth_append_args(msg, m, param)) {
+		ERR("%s: parameter not understood", program_name);
+		show_help();
+		exit(1);
+	}
+
+	if (!send_with_reply_and_set_notify(msg, set_property_reply, NULL,
+									NULL)) {
+		ERR("Not enough memory for message send");
+		return FALSE;
+	}
+
+	dbus_message_unref(msg);
+
+	return FALSE;
+}
+
 static void run_func(const char *adapter_path, GSourceFunc fn,
 							struct cmd_param *param)
 {
@@ -1096,6 +1266,7 @@ static struct cmd_struct commands[] = {
 	{ "pair", cmd_pair},
 	{ "agent", cmd_agent},
 	{ "remove", cmd_remove},
+	{ "adapter", cmd_adapter},
 };
 
 /* Returns FALSE in case the command could not be parsed. Any failures during
-- 
1.7.11.4


^ permalink raw reply related

* [PATCH -v2 5/6] bt tool: add cmd 'remove'
From: Gustavo Padovan @ 2012-10-07 22:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Travis Reitter
In-Reply-To: <1349650197-18751-1-git-send-email-gustavo@padovan.org>

From: Travis Reitter <travis.reitter@collabora.co.uk>

'bt remove <device address>' will remove a previous paired device
---
 client/main.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 136 insertions(+)

diff --git a/client/main.c b/client/main.c
index 11d26c5..aeb47e4 100644
--- a/client/main.c
+++ b/client/main.c
@@ -102,6 +102,7 @@ static void show_help()
 	"	discover				Scan for devices\n"
 	"	pair <device address>			Start pairing\n"
 	"	agent					Run BlueZ agent\n"
+	"	remove					Remove a paired device\n"
 							"\n", program_name);
 
 	if(mainloop != NULL)
@@ -740,6 +741,94 @@ static gboolean stop_discovery_cb(gpointer data)
 	return FALSE;
 }
 
+/* Handle the D-Bus method reply for RemoveDevice. See comments on
+ * get_adapter_reply() for more details */
+static void remove_device_reply(DBusPendingCall *pending, void *user_data)
+{
+	const char *device_path = user_data;
+	DBusMessage *reply;
+
+	reply = dbus_pending_call_steal_reply(pending);
+	if (!reply) {
+		ERR("Failed to get RemoveDevice reply");
+		exit(1);
+	}
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		ERR("Remove device failed.");
+		exit(1);
+	}
+
+	printf("Device %s successfully removed.\n", device_path);
+	g_main_loop_quit(mainloop);
+}
+
+static int remove_device(DBusConnection *conn, const char *adapter_path,
+							const char *device_path)
+{
+	DBusMessage *msg;
+	int retval = 0;
+
+	if (!(msg = create_method_call(adapter_path, BLUEZ_ADAPTER,
+							"RemoveDevice")))
+		return -1;
+
+	dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH, &device_path,
+							DBUS_TYPE_INVALID);
+
+	if (!send_with_reply_and_set_notify(msg, remove_device_reply,
+						g_strdup(device_path), g_free))
+		retval = -1;
+
+	dbus_message_unref(msg);
+
+	return retval;
+}
+
+/* Handle the D-Bus method reply for FindDevice. See comments on
+ * get_adapter_reply() for more details */
+static void find_device_reply(DBusPendingCall *pending, void *user_data)
+{
+	const char *adapter_path = user_data;
+	DBusMessage *reply;
+	const char *device_path;
+
+	if (!pending)
+		return;
+
+	dbus_pending_call_ref(pending);
+
+	reply = dbus_pending_call_steal_reply(pending);
+	if (!reply) {
+		ERR("Failed to get FindDevice() reply");
+		exit(1);
+	}
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		ERR("Failed to find device.");
+		exit(1);
+	} else {
+		struct DBusError err;
+		dbus_error_init(&err);
+
+		if (!dbus_message_get_args(reply, &err,
+					DBUS_TYPE_OBJECT_PATH, &device_path,
+					DBUS_TYPE_INVALID)) {
+			if (dbus_error_is_set(&err)) {
+				ERR("Failed to find device %s", err.message);
+				dbus_error_free(&err);
+			}
+			exit(1);
+		}
+	}
+
+	if (remove_device(conn, adapter_path, device_path) < 0)
+		exit(1);
+
+	dbus_message_unref(reply);
+	dbus_pending_call_unref(pending);
+}
+
 /* Listen for Bluetooth devices broadcasting their availability, then display
  * the results */
 static gboolean cmd_discover(gpointer data)
@@ -829,6 +918,52 @@ static gboolean cmd_agent(gpointer data)
 	return FALSE;
 }
 
+/* Remove a pairing with a given Bluetooth device */
+static gboolean cmd_remove(gpointer data)
+{
+	struct cmd_param *param = data;
+	char *device_addr;
+	DBusMessage *msg;
+	gboolean retval = FALSE;
+
+	device_addr = param->argv[0];
+	if (!device_addr) {
+		ERR("%s: missing device address paramenter", program_name);
+		show_help();
+		exit(1);
+	}
+
+	/* Register a D-Bus interface for our agent to handle our removal
+	 * request */
+	if (!g_dbus_register_interface(conn, "/tool/agent", BLUEZ_AGENT,
+					agent_methods, NULL, NULL, NULL,
+									NULL)) {
+		ERR("Adapter interface init failed for path %s", param->path);
+		return FALSE;
+	}
+
+	device_addr = param->argv[0];
+
+	if (!(msg = create_method_call(param->path, BLUEZ_ADAPTER,
+								"FindDevice")))
+		return FALSE;
+
+	dbus_message_append_args(msg, DBUS_TYPE_STRING, &device_addr,
+							DBUS_TYPE_INVALID);
+
+	/* Set up our notify function and provide it both the extra data it
+	 * requires and another function to free this data when our notify
+	 * function is done with it */
+	if (!send_with_reply_and_set_notify(msg, find_device_reply,
+							g_strdup(param->path),
+							g_free))
+		retval = FALSE;
+
+	dbus_message_unref(msg);
+
+	return retval;
+}
+
 static void run_func(const char *adapter_path, GSourceFunc fn,
 							struct cmd_param *param)
 {
@@ -960,6 +1095,7 @@ static struct cmd_struct commands[] = {
 	{ "discover", cmd_discover},
 	{ "pair", cmd_pair},
 	{ "agent", cmd_agent},
+	{ "remove", cmd_remove},
 };
 
 /* Returns FALSE in case the command could not be parsed. Any failures during
-- 
1.7.11.4


^ permalink raw reply related

* [PATCH -v2 4/6] bt tool: add cmd 'pair'
From: Gustavo Padovan @ 2012-10-07 22:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Travis Reitter
In-Reply-To: <1349650197-18751-1-git-send-email-gustavo@padovan.org>

From: Travis Reitter <travis.reitter@collabora.co.uk>

'bt pair <device address>' starts a pairing procedure with a remote
device.
---
 client/main.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)

diff --git a/client/main.c b/client/main.c
index 6035eda..11d26c5 100644
--- a/client/main.c
+++ b/client/main.c
@@ -575,6 +575,65 @@ static int register_agent(DBusConnection *conn, const char *adapter_path,
 	return 0;
 }
 
+/* Handle the D-Bus method reply for CreatePairedDevice. See comments on
+ * get_adapter_reply() for more details */
+static void create_paired_device_reply(DBusPendingCall *pending,
+								void *user_data)
+{
+	const char *device = user_data;
+	const char *device_path;
+	DBusMessage *reply;
+	DBusError err;
+
+	reply = dbus_pending_call_steal_reply(pending);
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		ERR("Pairing Failed.");
+		exit(1);
+	}
+
+	dbus_error_init(&err);
+	if (!dbus_message_get_args(reply, &err, DBUS_TYPE_OBJECT_PATH,
+					&device_path, DBUS_TYPE_INVALID)) {
+		if (dbus_error_is_set(&err)) {
+			ERR("Paring failed: %s", err.message);
+			dbus_error_free(&err);
+		}
+		exit(1);
+	}
+
+	printf("Device %s successfully paired.\n", device);
+	g_main_loop_quit(mainloop);
+}
+
+static int create_paired_device(DBusConnection *conn, const char *adapter_path,
+						const char *agent_path,
+						const char *capabilities,
+						const char *device)
+{
+	DBusMessage *msg;
+	int retval = 0;
+
+	if (!(msg = create_method_call(adapter_path, BLUEZ_ADAPTER,
+							"CreatePairedDevice")))
+		return -1;
+
+	dbus_message_append_args(msg, DBUS_TYPE_STRING, &device,
+					DBUS_TYPE_OBJECT_PATH, &agent_path,
+					DBUS_TYPE_STRING, &capabilities,
+					DBUS_TYPE_INVALID);
+
+	if (!send_with_reply_and_set_notify(msg, create_paired_device_reply,
+						g_strdup(device), g_free))
+		retval = -1;
+
+	dbus_message_unref(msg);
+
+	exit_on_release = FALSE;
+
+	return retval;
+}
+
 /* This is the table of methods that our agent supports, including their name,
  * and arguments (including their D-Bus types). See the D-Bus documentation for
  * details on the type notation */
@@ -726,6 +785,29 @@ static gboolean cmd_discover(gpointer data)
 	return FALSE;
 }
 
+/* Pair (connect) our Bluetooth adapter with an external Bluetooth device */
+static gboolean cmd_pair(gpointer data)
+{
+	struct cmd_param *param = data;
+	char *device;
+
+	if (!g_dbus_register_interface(conn, "/tool/agent", BLUEZ_AGENT,
+					agent_methods, NULL, NULL, NULL,
+									NULL)) {
+		ERR("Adapter interface init failed on path %s", param->path);
+		return FALSE;
+	}
+
+	device = param->argv[0];
+
+	if (create_paired_device(conn, param->path, "/tool/agent",
+						"DisplayYesNo", device) < 0) {
+		exit(1);
+	}
+
+	return FALSE;
+}
+
 /* Register this program as an agent itself, to handle other BlueZ clients'
  * requests */
 static gboolean cmd_agent(gpointer data)
@@ -876,6 +958,7 @@ static void bluetoothd_disconnect(DBusConnection *conn, void *user_data)
 
 static struct cmd_struct commands[] = {
 	{ "discover", cmd_discover},
+	{ "pair", cmd_pair},
 	{ "agent", cmd_agent},
 };
 
-- 
1.7.11.4


^ permalink raw reply related

* [PATCH -v2 3/6] bt tool: add cmd 'agent'
From: Gustavo Padovan @ 2012-10-07 22:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo Padovan
In-Reply-To: <1349650197-18751-1-git-send-email-gustavo@padovan.org>

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

'bt agent' command register a agent in BlueZ that will loop waiting for
pairing and incoming connection requests.
---
 client/main.c | 352 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 352 insertions(+)

diff --git a/client/main.c b/client/main.c
index 48521fd..6035eda 100644
--- a/client/main.c
+++ b/client/main.c
@@ -82,6 +82,8 @@ struct find_adapter_cb_data {
 static GMainLoop *mainloop = NULL;
 static gchar *program_name = NULL;
 
+static gboolean exit_on_release = TRUE;
+
 static bdaddr_t bdaddr;
 static DBusConnection *conn;
 
@@ -280,6 +282,334 @@ static gboolean send_with_reply_and_set_notify(DBusMessage *msg,
 	return TRUE;
 }
 
+static DBusMessage *agent_request_confirmation(DBusConnection *conn,
+						DBusMessage *msg, void *data)
+{
+	DBusMessage *reply;
+	const char *path;
+	unsigned int passkey;
+	char conf[16];
+	int ret;
+
+	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+						DBUS_TYPE_UINT32, &passkey,
+						DBUS_TYPE_INVALID)) {
+		ERR("Invalid arguments for RequestConfirmation method");
+		reply = dbus_message_new_error(msg,
+					BLUEZ_ERROR".InvalidArguments", "");
+		goto send;
+	}
+
+	printf("Pairing request confirmation for %s.\n"
+		"Confirm the passkey %6.6d (yes/no): ", path, passkey);
+	ret = scanf("%3s", conf);
+	if (!ret)
+		return NULL;
+
+	if (g_str_equal(conf, "yes"))
+		reply = dbus_message_new_method_return(msg);
+	else
+		reply = dbus_message_new_error(msg, BLUEZ_ERROR".Rejected",
+						"Passkey doesn't match");
+
+	if (!reply) {
+		ERR("Can't create reply message");
+		return NULL;
+	}
+
+send:
+	dbus_connection_send(conn, reply, NULL);
+
+	dbus_message_unref(reply);
+
+	return NULL;
+}
+
+static DBusMessage *agent_request_pincode(DBusConnection *conn,
+						DBusMessage *msg, void *data)
+{
+	DBusMessage *reply;
+	const char *path;
+	char pin[64];
+	char *str;
+	int ret;
+
+	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+						DBUS_TYPE_INVALID)) {
+		ERR("Invalid arguments for RequestPinCode method");
+		reply = dbus_message_new_error(msg,
+					BLUEZ_ERROR".InvalidArguments", "");
+		goto send;
+	}
+
+	printf("Pairing request for  %s.\nType the PIN code: ", path);
+	ret = scanf("%s", pin);
+	if (!ret)
+		return NULL;
+
+	if (!(reply = dbus_message_new_method_return(msg))) {
+		ERR("Not enough memory to construct message");
+		return NULL;
+	}
+
+	str = pin;
+	dbus_message_append_args(reply, DBUS_TYPE_STRING, &str,
+							DBUS_TYPE_INVALID);
+
+send:
+	dbus_connection_send(conn, reply, NULL);
+
+	dbus_message_unref(reply);
+
+	return NULL;
+}
+
+static DBusMessage *agent_request_passkey(DBusConnection *conn,
+						DBusMessage *msg, void *data)
+{
+	DBusMessage *reply;
+	const char *path;
+	unsigned int passkey;
+	int ret;
+
+	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+						DBUS_TYPE_INVALID)) {
+		ERR("Invalid arguments for RequestPasskey method");
+		reply = dbus_message_new_error(msg,
+					BLUEZ_ERROR".InvalidArguments", "");
+		goto send;
+	}
+
+	printf("Pairing request for  %s.\nType the Passkey: ", path);
+	ret = scanf("%u", &passkey);
+	if (!ret)
+		return NULL;
+
+	reply = dbus_message_new_method_return(msg);
+
+	dbus_message_append_args(reply, DBUS_TYPE_STRING, passkey,
+							DBUS_TYPE_INVALID);
+
+send:
+	if (!dbus_connection_send(conn, reply, NULL))
+		ERR("Not enough memory to send message");
+
+	dbus_message_unref(reply);
+
+	return NULL;
+}
+
+static DBusMessage *agent_authorize(DBusConnection *conn, DBusMessage *msg,
+								void *data)
+{
+	DBusMessage *reply;
+	const char *path, *uuid;
+	char conf[16];
+	int ret;
+
+	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+						DBUS_TYPE_STRING, &uuid,
+						DBUS_TYPE_INVALID)) {
+		ERR("Invalid arguments for Authorize method");
+		reply = dbus_message_new_error(msg,
+					BLUEZ_ERROR".InvalidArguments", "");
+		goto send;
+	}
+
+	printf("Incoming connection request for %s (%s).\n"
+		"Authorize (yes/no): ", path, uuid);
+	ret = scanf("%3s", conf);
+	if (!ret)
+		return NULL;
+
+	if (g_str_equal(conf, "yes"))
+		reply = dbus_message_new_method_return(msg);
+	else
+		reply = dbus_message_new_error(msg, BLUEZ_ERROR".Rejected",
+						"Connection Rejected");
+
+	if (!reply) {
+		ERR("Can't create reply message");
+		return NULL;
+	}
+
+send:
+	dbus_connection_send(conn, reply, NULL);
+
+	dbus_message_unref(reply);
+
+	return NULL;
+}
+
+static DBusMessage *agent_confirm_mode_change(DBusConnection *conn,
+						DBusMessage *msg, void *data)
+{
+	DBusMessage *reply;
+	const char *mode;
+	char conf[16];
+	int ret;
+
+	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &mode,
+							DBUS_TYPE_INVALID)) {
+		ERR("Invalid arguments for ConfirmModeChange");
+		reply = dbus_message_new_error(msg,
+					BLUEZ_ERROR".InvalidArguments", "");
+		goto send;
+	}
+
+	printf("Authorize mode change to %s (yes/no): ", mode);
+	ret = scanf("%3s", conf);
+	if (!ret)
+		return NULL;
+
+	if (g_str_equal(conf, "yes"))
+		reply = dbus_message_new_method_return(msg);
+	else
+		reply = dbus_message_new_error(msg, BLUEZ_ERROR".Rejected",
+						"Mode Change Rejected");
+
+	if (!reply) {
+		ERR("Can't create reply message");
+		return NULL;
+	}
+
+send:
+	dbus_connection_send(conn, reply, NULL);
+
+	dbus_message_unref(reply);
+
+	return NULL;
+}
+
+static DBusMessage *agent_cancel(DBusConnection *conn, DBusMessage *msg,
+								void *data)
+{
+	DBusMessage *reply;
+
+	printf("Request canceled\n");
+
+	reply = dbus_message_new_method_return(msg);
+	if (!reply) {
+		ERR("Can't create reply message");
+		return NULL;
+	}
+
+	dbus_connection_send(conn, reply, NULL);
+
+	dbus_message_unref(reply);
+
+	g_main_loop_quit(mainloop);
+
+	return NULL;
+}
+
+static DBusMessage *agent_release(DBusConnection *conn, DBusMessage *msg,
+								void *data)
+{
+	DBusMessage *reply;
+
+	printf("Agent released\n");
+
+	reply = dbus_message_new_method_return(msg);
+	if (!reply) {
+		ERR("Can't create reply message");
+		return NULL;
+	}
+
+	dbus_connection_send(conn, reply, NULL);
+
+	dbus_message_unref(reply);
+
+	/* Only exit the mainloop in case there are no other D-Bus methods, such
+	 * as CreatePairedDevice, pending */
+	if (exit_on_release)
+		g_main_loop_quit(mainloop);
+
+	return NULL;
+}
+
+/* Handle the D-Bus method reply for RegisterAgent. See comments on
+ * get_adapter_reply() for more details */
+static void register_agent_reply(DBusPendingCall *pending, void *user_data)
+{
+	DBusMessage *reply;
+
+	reply = dbus_pending_call_steal_reply(pending);
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		ERR("Agent Registration failed.");
+		exit(1);
+	}
+
+	printf("Agent registered\n");
+}
+
+static int register_agent(DBusConnection *conn, const char *adapter_path,
+						const char *agent_path,
+						const char *capabilities)
+{
+	dbus_bool_t success;
+	DBusMessage *msg;
+	DBusPendingCall *pending;
+
+	if (!(msg = create_method_call(adapter_path, BLUEZ_ADAPTER,
+							"RegisterAgent")))
+		return -1;
+
+	dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH, &agent_path,
+					DBUS_TYPE_STRING, &capabilities,
+					DBUS_TYPE_INVALID);
+
+	success = dbus_connection_send_with_reply(conn, msg, &pending, -1);
+	if (pending)
+		dbus_pending_call_set_notify(pending, register_agent_reply,
+								NULL, NULL);
+
+	dbus_message_unref(msg);
+
+	if (!success) {
+		ERR("Not enough memory for message send");
+		return -1;
+	}
+
+	return 0;
+}
+
+/* This is the table of methods that our agent supports, including their name,
+ * and arguments (including their D-Bus types). See the D-Bus documentation for
+ * details on the type notation */
+static const GDBusMethodTable agent_methods[] = {
+	{ GDBUS_ASYNC_METHOD("RequestConfirmation",
+			GDBUS_ARGS({ "device", "o" }, { "passkey", "u" }),
+			NULL,
+			agent_request_confirmation) },
+	{ GDBUS_ASYNC_METHOD("RequestPinCode",
+			GDBUS_ARGS({ "device", "o" }),
+			GDBUS_ARGS({"pincode", "s"}),
+			agent_request_pincode) },
+	{ GDBUS_ASYNC_METHOD("RequestPasskey",
+			GDBUS_ARGS({ "device", "o" }),
+			GDBUS_ARGS({"passkey", "u"}),
+			agent_request_passkey) },
+	{ GDBUS_ASYNC_METHOD("Authorize",
+			GDBUS_ARGS({ "device", "o" }, { "uuid", "s" }),
+			NULL,
+			agent_authorize) },
+	{ GDBUS_ASYNC_METHOD("ConfirmModeChange",
+			GDBUS_ARGS( { "mode", "s" }),
+			NULL,
+			agent_confirm_mode_change) },
+	{ GDBUS_ASYNC_METHOD("Cancel",
+			NULL,
+			NULL,
+			agent_cancel) },
+	{ GDBUS_ASYNC_METHOD("Release",
+			NULL,
+			NULL,
+			agent_release) },
+	{ }
+};
+
 /* Handle BlueZ's DeviceFound signal */
 static gboolean device_found(DBusConnection *conn, DBusMessage *message,
 							void *user_data)
@@ -396,6 +726,27 @@ static gboolean cmd_discover(gpointer data)
 	return FALSE;
 }
 
+/* Register this program as an agent itself, to handle other BlueZ clients'
+ * requests */
+static gboolean cmd_agent(gpointer data)
+{
+	struct cmd_param *param = data;
+
+	if (!g_dbus_register_interface(conn, "/tool/agent", BLUEZ_AGENT,
+					agent_methods, NULL, NULL, NULL,
+									NULL)) {
+		ERR("Agent interface init failed");
+		return FALSE;
+	}
+
+	if (register_agent(conn, param->path, "/tool/agent", "DisplayYesNo")
+									< 0) {
+		exit(1);
+	}
+
+	return FALSE;
+}
+
 static void run_func(const char *adapter_path, GSourceFunc fn,
 							struct cmd_param *param)
 {
@@ -525,6 +876,7 @@ static void bluetoothd_disconnect(DBusConnection *conn, void *user_data)
 
 static struct cmd_struct commands[] = {
 	{ "discover", cmd_discover},
+	{ "agent", cmd_agent},
 };
 
 /* Returns FALSE in case the command could not be parsed. Any failures during
-- 
1.7.11.4


^ permalink raw reply related

* [PATCH -v2 2/6] bt tool: add cmd 'discover'
From: Gustavo Padovan @ 2012-10-07 22:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Travis Reitter
In-Reply-To: <1349650197-18751-1-git-send-email-gustavo@padovan.org>

From: Travis Reitter <travis.reitter@collabora.co.uk>

 $ bt discover

will start a discovery for devices nearby and display them. We display
the device when we receive its first Device Found signal. If the
DeviceFound signal doesn't contains the device's name it will not be
displayed.

Steal bluetooth_parse_properties() from oFono code.
---
 client/main.c | 242 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 241 insertions(+), 1 deletion(-)

diff --git a/client/main.c b/client/main.c
index 4edc255..48521fd 100644
--- a/client/main.c
+++ b/client/main.c
@@ -5,6 +5,7 @@
  *  Copyright (C) 2004-2010  Marcel Holtmann <marcel@holtmann.org>
  *  Copyright (C) 2011 Bruno Dilly <bdilly@profusion.mobi>
  *  Copyright (C) 2011 Gustavo Padovan <gustavo@padovan.org>
+ *  Copyright (C) 2011 Intel Corporation. All rights reserved.
  *  Copyright (C) 2012 Collabora Limited.
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -84,6 +85,8 @@ static gchar *program_name = NULL;
 static bdaddr_t bdaddr;
 static DBusConnection *conn;
 
+static GHashTable *device_addrs = NULL;
+
 static void show_help()
 {
 	printf("usage: %s [-i interface] <command> [<args>]\n"
@@ -115,6 +118,127 @@ static struct find_adapter_cb_data *find_adapter_cb_data_new(GSourceFunc fn,
 	return cb_data;
 }
 
+static void parse_bool(DBusMessageIter *iter, gpointer user_data)
+{
+	gboolean *boolean = user_data;
+	int arg_type = dbus_message_iter_get_arg_type(iter);
+
+	if (arg_type != DBUS_TYPE_BOOLEAN)
+		return;
+
+	dbus_message_iter_get_basic(iter, boolean);
+}
+
+static void parse_string(DBusMessageIter *iter, gpointer user_data)
+{
+	char **str = user_data;
+	int arg_type = dbus_message_iter_get_arg_type(iter);
+
+	if (arg_type != DBUS_TYPE_OBJECT_PATH && arg_type != DBUS_TYPE_STRING)
+		return;
+
+	dbus_message_iter_get_basic(iter, str);
+}
+
+typedef void (*PropertyHandler)(DBusMessageIter *iter, gpointer user_data);
+
+struct property_handler {
+	const char *property;
+	PropertyHandler callback;
+	gpointer user_data;
+};
+
+static gint property_handler_compare(gconstpointer a, gconstpointer b)
+{
+	const struct property_handler *handler = a;
+	const char *property = b;
+
+	return strcmp(handler->property, property);
+}
+
+/* Demarshall the content of a D-Bus message reply for a given property.
+ *
+ * After the first argument, all arguments must be triplets of:
+ *
+ *   const char* property_name,
+ *   void (parse_func*) (DBusMessageIter *iter, gpointer user_data),
+ *   void** result,
+ *
+ * result must be large enough to store the type of data corresponding to
+ * property_name.
+ *
+ * Finally, a NULL must be appended as the last argument.
+ */
+static void bluetooth_parse_properties(DBusMessage *reply,
+						const char *property, ...)
+{
+	va_list args;
+	GSList *prop_handlers = NULL;
+	DBusMessageIter array, dict;
+
+	va_start(args, property);
+
+	while (property != NULL) {
+		struct property_handler *handler = g_new0(struct property_handler, 1);
+
+		handler->property = property;
+		handler->callback = va_arg(args, PropertyHandler);
+		handler->user_data = va_arg(args, gpointer);
+
+		property = va_arg(args, const char *);
+
+		prop_handlers = g_slist_prepend(prop_handlers, handler);
+	}
+
+	va_end(args);
+
+	if (dbus_message_iter_init(reply, &array) == FALSE)
+		goto done;
+
+	if (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRING)
+		dbus_message_iter_next(&array);
+
+	if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
+		goto done;
+
+	dbus_message_iter_recurse(&array, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key;
+		GSList *l;
+
+		dbus_message_iter_recurse(&dict, &entry);
+
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
+			goto done;
+
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
+			goto done;
+
+		dbus_message_iter_recurse(&entry, &value);
+
+		l = g_slist_find_custom(prop_handlers, key,
+					property_handler_compare);
+
+		if (l) {
+			struct property_handler *handler = l->data;
+
+			handler->callback(&value, handler->user_data);
+		}
+
+		dbus_message_iter_next(&dict);
+	}
+
+done:
+	g_slist_foreach(prop_handlers, (GFunc) g_free, NULL);
+	g_slist_free(prop_handlers);
+}
+
 static DBusMessage* create_method_call(const char *adapter_path,
 							const char *interface,
 							const char *method_name)
@@ -156,6 +280,122 @@ static gboolean send_with_reply_and_set_notify(DBusMessage *msg,
 	return TRUE;
 }
 
+/* Handle BlueZ's DeviceFound signal */
+static gboolean device_found(DBusConnection *conn, DBusMessage *message,
+							void *user_data)
+{
+	const char *alias = NULL;
+	const char *address = NULL;
+	gboolean paired, trusted;
+	DBusMessageIter array;
+
+	if (dbus_message_iter_init(message, &array) == FALSE)
+		return TRUE;
+
+	if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_STRING)
+		return TRUE;
+
+	bluetooth_parse_properties(message, "Alias", parse_string, &alias,
+				"Address", parse_string, &address,
+				"Paired", parse_bool, &paired,
+				"Trusted", parse_bool, &trusted,
+				NULL);
+
+	/* Only list new devices if we have not yet listed them. BlueZ will emit
+	 * this signal multiple times for the same device because it may receive
+	 * additional information from the device in subsequent transmissions */
+	if (!g_hash_table_contains(device_addrs, address)) {
+		gint alias_len;
+		const char *alias_status_gap = " ";
+
+		/* Make sure everything aligns under each header; this assumes
+		 * 8-character tabs and 17-character BT address */
+		alias_len = (alias == NULL ? 0 : strlen(alias));
+		if (FALSE) { }
+		else if (alias_len < 3)
+			alias_status_gap = "\t\t\t\t";
+		else if (alias_len < 11)
+			alias_status_gap = "\t\t\t";
+		else if (alias_len < 19)
+			alias_status_gap = "\t\t";
+		else
+			alias_status_gap = "\t";
+
+		g_hash_table_insert(device_addrs, g_strdup (address), NULL);
+		printf("%s    %s%s%s%s\n", address, alias, alias_status_gap,
+						paired ? "paired": "unpaired",
+						trusted ? ", trusted" : "");
+	}
+
+	return TRUE;
+}
+
+static void stop_discovery_reply(DBusPendingCall *pending, void *user_data)
+{
+	/* Once we're done discovering and displaying devices, exit gracefully
+	 */
+	g_main_loop_quit(mainloop);
+}
+
+static gboolean stop_discovery_cb(gpointer data)
+{
+	const char *path = data;
+	DBusMessage *msg;
+
+	if (!(msg = create_method_call(path, BLUEZ_ADAPTER, "StopDiscovery")))
+		return FALSE;
+	send_with_reply_and_set_notify(msg, stop_discovery_reply, NULL, NULL);
+
+	dbus_message_unref(msg);
+
+	return FALSE;
+}
+
+/* Listen for Bluetooth devices broadcasting their availability, then display
+ * the results */
+static gboolean cmd_discover(gpointer data)
+{
+	struct cmd_param *param = data;
+	dbus_bool_t success;
+	DBusMessage *msg;
+
+	/* We may recieve multiple messages for each device, because BlueZ
+	 * notifies us any time it gets additional information for a given
+	 * device, we need to prevent printing duplicate information.
+	 *
+	 * So, we use this hash table as a (unique) set to avoid displaying
+	 * information about a single device more than once. */
+	device_addrs = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
+									NULL);
+
+	g_dbus_add_signal_watch(conn, BLUEZ_SERVICE, NULL, BLUEZ_ADAPTER,
+				"DeviceFound", device_found, NULL, NULL);
+
+	if (!(msg = create_method_call(param->path, BLUEZ_ADAPTER,
+							"StartDiscovery")))
+		return FALSE;
+
+	printf("Device Address       Name\t\t\tStatus\n");
+	printf("--------------       ----\t\t\t------\n");
+
+	/* Send the message without registering a notify function. This means we
+	 * won't recieve indication of any errors (which may be acceptable in
+	 * certain instances, such as when discovering visible devices) */
+	success = dbus_connection_send(conn, msg, NULL);
+
+	/* We can't know for sure when we've heard back from all Bluetooth
+	 * devices within range, so we need to wait some number of seconds and
+	 * print details as they come in */
+	if (success)
+		g_timeout_add_seconds(12, stop_discovery_cb, param->path);
+	else
+		ERR("Not enough memory to send message");
+
+	dbus_message_unref(msg);
+
+	return FALSE;
+}
+
 static void run_func(const char *adapter_path, GSourceFunc fn,
 							struct cmd_param *param)
 {
@@ -284,7 +524,7 @@ static void bluetoothd_disconnect(DBusConnection *conn, void *user_data)
 }
 
 static struct cmd_struct commands[] = {
-	{ NULL, NULL},
+	{ "discover", cmd_discover},
 };
 
 /* Returns FALSE in case the command could not be parsed. Any failures during
-- 
1.7.11.4


^ permalink raw reply related

* [PATCH -v2 1/6] bt tool: initial tool handling
From: Gustavo Padovan @ 2012-10-07 22:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo Padovan

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

All core code to using this tool is here, the nexts steps will add
commands like 'discover' 'pair' 'agent', etc.
---
 Makefile.am   |   8 ++
 acinclude.m4  |   6 +
 client/main.c | 421 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 435 insertions(+)
 create mode 100644 client/main.c

diff --git a/Makefile.am b/Makefile.am
index 3b08f9a..2b0bdc5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -431,6 +431,14 @@ else
 unit_tests =
 endif
 
+if CLIENT
+client_bt_SOURCES = $(gdbus_sources) client/main.c
+
+client_bt_LDADD = lib/libbluetooth-private.la @DBUS_LIBS@ @GLIB_LIBS@
+
+bin_PROGRAMS += client/bt
+endif
+
 TESTS = $(unit_tests)
 
 pkgconfigdir = $(libdir)/pkgconfig
diff --git a/acinclude.m4 b/acinclude.m4
index 4bac3f0..d9fd6ce 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -190,6 +190,7 @@ AC_DEFUN([AC_ARG_BLUEZ], [
 	wiimote_enable=no
 	gatt_enable=no
 	neard_enable=no
+	client_enable=yes
 
 	AC_ARG_ENABLE(optimization, AC_HELP_STRING([--disable-optimization], [disable code optimization]), [
 		optimization_enable=${enableval}
@@ -303,6 +304,10 @@ AC_DEFUN([AC_ARG_BLUEZ], [
 	AC_ARG_ENABLE(neard, AC_HELP_STRING([--enable-neard], [compile with neard plugin]), [
 		neard_enable=${enableval}
 	])
+	AC_ARG_ENABLE(tools, AC_HELP_STRING([--enable-client], [install BlueZ client]), [
+		client_enable=${enableval}
+	])
+
 
 	misc_cflags=""
 	misc_ldflags=""
@@ -356,4 +361,5 @@ AC_DEFUN([AC_ARG_BLUEZ], [
 	AM_CONDITIONAL(GATTMODULES, test "${gatt_enable}" = "yes")
 	AM_CONDITIONAL(HOGPLUGIN, test "${gatt_enable}" = "yes" && test "${input_enable}" = "yes")
 	AM_CONDITIONAL(NEARDPLUGIN, test "${neard_enable}" = "yes")
+	AM_CONDITIONAL(CLIENT, test "${client_enable}" = "yes")
 ])
diff --git a/client/main.c b/client/main.c
new file mode 100644
index 0000000..4edc255
--- /dev/null
+++ b/client/main.c
@@ -0,0 +1,421 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2004-2010  Marcel Holtmann <marcel@holtmann.org>
+ *  Copyright (C) 2011 Bruno Dilly <bdilly@profusion.mobi>
+ *  Copyright (C) 2011 Gustavo Padovan <gustavo@padovan.org>
+ *  Copyright (C) 2012 Collabora Limited.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+/*
+ * This code is meant, in part, to be a working example of a BlueZ client
+ * written in C.
+ *
+ * If you are new to BlueZ, we recommend you read the code breadth-first,
+ * starting with main(). The function and variable names should be fairly
+ * self-explanatory, with comments filling in details along the way.
+ *
+ * You will also want to reference the BlueZ D-Bus API, which is documented in
+ * /doc of this soruce tree, and the libdbus API, documented here:
+ *
+ *   http://dbus.freedesktop.org/doc/api/html/index.html
+ */
+
+#include <config.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <glib.h>
+
+#include <dbus/dbus.h>
+#include <gdbus.h>
+
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/hci.h>
+#include <bluetooth/hci_lib.h>
+
+#define BLUEZ_SERVICE	"org.bluez"
+#define BLUEZ_MANAGER	"org.bluez.Manager"
+#define BLUEZ_ADAPTER	"org.bluez.Adapter"
+#define BLUEZ_AGENT	"org.bluez.Agent"
+#define BLUEZ_ERROR	"org.bluez.Error"
+
+#define ARRAY_SIZE(x) (int)(sizeof(x)/sizeof(x[0]))
+
+#define ERR(fmt, ...)	fprintf(stderr, fmt "\n", ##__VA_ARGS__)
+
+struct cmd_param {
+	char	*path;
+	int	argc;
+	char	**argv;
+};
+
+struct cmd_struct {
+	const char	*cmd;
+	GSourceFunc	fn;
+};
+
+struct find_adapter_cb_data {
+	GSourceFunc		fn;
+	struct cmd_param	*param;
+};
+
+static GMainLoop *mainloop = NULL;
+static gchar *program_name = NULL;
+
+static bdaddr_t bdaddr;
+static DBusConnection *conn;
+
+static void show_help()
+{
+	printf("usage: %s [-i interface] <command> [<args>]\n"
+	"\n"
+	"options:\n"
+	"	-i <hci dev>, --interface <hci dev>	HCI device\n"
+	"	--help					This help\n"
+	"	--version				Version\n"
+	"\n"
+	"commands:\n"
+	"	discover				Scan for devices\n"
+	"	pair <device address>			Start pairing\n"
+	"	agent					Run BlueZ agent\n"
+							"\n", program_name);
+
+	if(mainloop != NULL)
+		g_main_loop_quit(mainloop);
+}
+
+static struct find_adapter_cb_data *find_adapter_cb_data_new(GSourceFunc fn,
+							struct cmd_param *param)
+{
+	struct find_adapter_cb_data *cb_data;
+
+	cb_data = g_new0(struct find_adapter_cb_data, 1);
+	cb_data->fn = fn;
+	cb_data->param = param;
+
+	return cb_data;
+}
+
+static DBusMessage* create_method_call(const char *adapter_path,
+							const char *interface,
+							const char *method_name)
+{
+	DBusMessage *msg;
+
+	msg = dbus_message_new_method_call(BLUEZ_SERVICE, adapter_path,
+						interface, method_name);
+	if (msg == NULL)
+		ERR("Can't allocate new method call");
+
+	return msg;
+}
+
+/* Utility function to call a D-Bus method and register a notify function to
+ * handle the reply */
+static gboolean send_with_reply_and_set_notify(DBusMessage *msg,
+				DBusPendingCallNotifyFunction notify_func,
+				gpointer user_data,
+				DBusFreeFunction user_data_free)
+{
+	DBusPendingCall *pending;
+	dbus_bool_t success;
+
+	success = dbus_connection_send_with_reply(conn, msg, &pending, -1);
+	if (pending) {
+		dbus_pending_call_set_notify(pending, notify_func, user_data,
+								user_data_free);
+	} else {
+		ERR("D-Bus connection lost before message could be sent");
+		return FALSE;
+	}
+
+	if (!success) {
+		ERR("Not enough memory to send D-Bus message");
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+static void run_func(const char *adapter_path, GSourceFunc fn,
+							struct cmd_param *param)
+{
+	param->path = strdup(adapter_path);
+
+	/* track timeout source */
+	g_timeout_add(50, fn, param);
+}
+
+/* Handle the D-Bus method reply for FindAdapter or DefaultAdapter */
+static void get_adapter_reply(DBusPendingCall *pending, void *user_data)
+{
+	struct find_adapter_cb_data *cb_data = user_data;
+	DBusMessage *reply;
+	const char *adapter_path;
+
+	if (!pending)
+		return;
+
+	/* We must ensure that this object remains alive while we need it and
+	 * objects it references (such as the reply) */
+	dbus_pending_call_ref(pending);
+
+	/* By "stealing" the reply, we are accepting responsibility to
+	 * unreference it below. Otherwise, its memory will be leaked */
+	reply = dbus_pending_call_steal_reply(pending);
+	if (!reply) {
+		ERR("FindAdapter() failed.");
+		exit(1);
+	}
+
+	/* Ensure that the reply does not indicate an error */
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		ERR("FindAdapter() failed");
+		exit(1);
+	} else {
+		struct DBusError err;
+		dbus_error_init(&err);
+
+		if (!dbus_message_get_args(reply, &err,
+					DBUS_TYPE_OBJECT_PATH, &adapter_path,
+					DBUS_TYPE_INVALID)) {
+			/* Ensure that there was not an error retrieving the
+			 * reply arguments */
+			if (dbus_error_is_set(&err)) {
+				ERR("FindAdapter() failed: %s", err.message);
+				dbus_error_free(&err);
+			} else {
+				ERR("FindAdapter() failed.");
+			}
+			exit(1);
+		}
+	}
+
+	/* In case we successfully retrieved the adapter object, execute our
+	 * core command using its path */
+	if (adapter_path != NULL && strlen(adapter_path) > 0) {
+		run_func(adapter_path, cb_data->fn, cb_data->param);
+	} else {
+		ERR("No such adapter");
+		exit(1);
+	}
+
+	/* Drop our references to these objects to avoid memory leaks */
+	dbus_message_unref(reply);
+	dbus_pending_call_unref(pending);
+}
+
+/* Looks up the adapter D-Bus object which corresponds to the Bluetooth device
+ * we will use (whether the user specified one or we fall back to the default.
+ *
+ * Once we have that object, we execute the core command. */
+static void get_adapter_and_run_func(GSourceFunc fn, struct cmd_param *param)
+{
+	DBusMessage *msg;
+	char *bt_str = NULL;
+	const char *method_name = NULL;
+	gpointer user_data;
+
+	/* The bacmp(), ba2str(), and other Bluetooth address utilities are
+	 * defined in bluetooth.h, in this source tree */
+	if (!bacmp(&bdaddr, BDADDR_ANY)) {
+		method_name = "DefaultAdapter";
+	} else {
+		method_name = "FindAdapter";
+
+		/* Allocate a string large enough for the biggest BT address */
+		bt_str = g_new(char, 18);
+		ba2str(&bdaddr, bt_str);
+	}
+
+	/* Create a new D-Bus method call */
+	if (!(msg = create_method_call("/", BLUEZ_MANAGER, method_name)))
+		exit(1);
+
+	/* In case we're making the FindAdapter D-Bus method call, we need to
+	 * append a method argument */
+	if (bt_str != NULL)
+		dbus_message_append_args(msg, DBUS_TYPE_STRING, &bt_str,
+							DBUS_TYPE_INVALID);
+
+	/* Finally, we need to asynchronously send and receive a response for
+	 * the D-Bus method call. This function does not block at all. Instead,
+	 * the GMainLoop will continue iterating until we get a response, which
+	 * will be passed to the notify function we specify here.
+	 *
+	 * We use only async D-Bus messaging because some of these D-Bus methods
+	 * could potentially take several seconds to complete, In the meantime,
+	 * if we were blocking, our application would be unresponsive and look
+	 * as if it (or * even the entire system upon which it is running) had
+	 * frozen. */
+	user_data = find_adapter_cb_data_new(fn, param);
+	if (!send_with_reply_and_set_notify(msg,  get_adapter_reply, user_data,
+									g_free))
+		exit(1);
+
+	dbus_message_unref(msg);
+}
+
+static void bluetoothd_disconnect(DBusConnection *conn, void *user_data)
+{
+	g_main_loop_quit(mainloop);
+
+	printf("Bluetooth daemon exited.\n");
+
+}
+
+static struct cmd_struct commands[] = {
+	{ NULL, NULL},
+};
+
+/* Returns FALSE in case the command could not be parsed. Any failures during
+ * execution will be handled later */
+static gboolean run_argv(int argc, char **argv)
+{
+	const char *cmd = argv[0];
+	struct cmd_param *param;
+	int i;
+
+	if (argc > 1 && g_str_equal(argv[1], "--help"))
+		cmd = "help";
+
+	for (i = 0; i < ARRAY_SIZE(commands); i++) {
+		struct cmd_struct *p = commands+i;
+		if (cmd == NULL || !g_str_equal(p->cmd, cmd))
+			continue;
+
+		param = malloc(sizeof(*param));
+		if (!param)
+			exit(1);
+
+		/* skip over the name of this program itself */
+		argc--;
+		argv++;
+
+		param->argc = argc;
+		param->argv = argv;
+
+		get_adapter_and_run_func(p->fn, param);
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
+static gboolean handle_options(int *argc, char ***argv)
+{
+	gboolean terminal_opt = FALSE;
+
+	bacpy(&bdaddr, BDADDR_ANY);
+
+	while (*argc > 0) {
+		const char *cmd = (*argv)[0];
+		if (cmd != NULL && cmd[0] != '-')
+			break;
+
+		if (g_str_equal(cmd, "--help") ||
+						g_str_equal(cmd, "--version")) {
+			terminal_opt = TRUE;
+			break;
+		}
+
+		/*
+		 * Check remaining flags.
+		 */
+		if(g_str_equal(cmd, "-i") || g_str_equal(cmd, "--interface")) {
+			const char *iface;
+			(*argv)++;
+			(*argc)--;
+			iface = (*argv)[0];
+			if (!strncasecmp(iface, "hci", 3))
+				hci_devba(atoi(iface + 3), &bdaddr);
+			else
+				str2ba(iface, &bdaddr);
+		}
+
+		(*argv)++;
+		(*argc)--;
+	}
+
+	return terminal_opt;
+}
+
+int main(int argc, char **argv)
+{
+	DBusError err;
+	gboolean terminal_opt;
+
+	program_name = g_strdup(argv[0]);
+
+	argv++;
+	argc--;
+	terminal_opt = handle_options(&argc, &argv);
+
+	if (terminal_opt) {
+		if (g_str_equal(argv[0], "--help"))
+			show_help();
+		else if (g_str_equal(argv[0], "--version"))
+			printf("%s\n", VERSION);
+
+		exit(0);
+	}
+
+	mainloop = g_main_loop_new(NULL, FALSE);
+
+	/* This structure must be initialized before it can be used */
+	dbus_error_init(&err);
+
+	/* Set up our connection to the D-Bus system bus, which we will use
+	 * throughout this code.
+	 *
+	 * NOTE: the "g_dbus" namespace used in this file is due to BlueZ's
+	 * internal "gdbus" D-Bus client library (included by gdbus.h), which is
+	 * not to be confused with libgio's D-Bus client functionality with the
+	 * same namespace (which would be included by gio.h) */
+	conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &err);
+	if (!conn) {
+		if (dbus_error_is_set(&err)) {
+			ERR("Can't connect to system bus: %s", err.message);
+			dbus_error_free(&err);
+		} else {
+			ERR("Can't connect to system bus");
+		}
+
+		exit(1);
+	}
+
+	/* Run the command given in the command line */
+	if (!run_argv(argc, argv)) {
+		ERR("%s: command not understood.", program_name);
+		show_help();
+		exit(1);
+	}
+
+	/* Set up handler in case the bluetooth daemon exits and it disappears
+	 * from the bus */
+	g_dbus_add_service_watch(conn, BLUEZ_SERVICE, NULL,
+					bluetoothd_disconnect, NULL, NULL);
+
+	g_main_loop_run(mainloop);
+
+	return 0;
+}
-- 
1.7.11.4


^ permalink raw reply related

* Re: [PATCHv1 7/7] Bluetooth: Adjust L2CAP Max PDU size for AMP packets
From: Gustavo Padovan @ 2012-10-07 22:25 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1349445419-16788-7-git-send-email-Andrei.Emeltchenko.news@gmail.com>

Hi Andrei,

* Andrei Emeltchenko <Andrei.Emeltchenko.news@gmail.com> [2012-10-05 16:56:58 +0300]:

> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> 
> Maximum PDU size is defined by new BT Spec as 1492 octets.
> 
> Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> ---
>  include/net/bluetooth/l2cap.h |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Patches 2 to 7 were applied to bluetooth-next. Thanks.

	Gustavo

^ permalink raw reply

* Re: [PATCHv1 1/7] Bluetooth: L2CAP: Fix using default Flush Timeout for EFS
From: Gustavo Padovan @ 2012-10-07 21:48 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1349445419-16788-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

Hi Andrei,

* Andrei Emeltchenko <Andrei.Emeltchenko.news@gmail.com> [2012-10-05 16:56:52 +0300]:

> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> 
> There are two Flush Timeouts: one is old Flush Timeot Option
> which is 2 octets and the second is Flush Timeout inside EFS
> which is 4 octets long.
> 
> Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> ---
>  include/net/bluetooth/l2cap.h |    3 ++-
>  net/bluetooth/l2cap_core.c    |   10 ++++++----
>  2 files changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
> index ab58b81..83fb9c7 100644
> --- a/include/net/bluetooth/l2cap.h
> +++ b/include/net/bluetooth/l2cap.h
> @@ -32,7 +32,8 @@
>  /* L2CAP defaults */
>  #define L2CAP_DEFAULT_MTU		672
>  #define L2CAP_DEFAULT_MIN_MTU		48
> -#define L2CAP_DEFAULT_FLUSH_TO		0xffff
> +#define L2CAP_DEFAULT_FLUSH_TO		0xFFFF
> +#define L2CAP_EFS_DEFAULT_FLUSH_TO	0xFFFFFFFF
>  #define L2CAP_DEFAULT_TX_WINDOW		63
>  #define L2CAP_DEFAULT_EXT_WINDOW	0x3FFF
>  #define L2CAP_DEFAULT_MAX_TX		3
> diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
> index b4e707b..ab6853d 100644
> --- a/net/bluetooth/l2cap_core.c
> +++ b/net/bluetooth/l2cap_core.c
> @@ -504,7 +504,7 @@ void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)
>  	chan->local_msdu	= L2CAP_DEFAULT_MAX_SDU_SIZE;
>  	chan->local_sdu_itime	= L2CAP_DEFAULT_SDU_ITIME;
>  	chan->local_acc_lat	= L2CAP_DEFAULT_ACC_LAT;
> -	chan->local_flush_to	= L2CAP_DEFAULT_FLUSH_TO;
> +	chan->local_flush_to	= L2CAP_EFS_DEFAULT_FLUSH_TO;
>  
>  	l2cap_chan_hold(chan);
>  
> @@ -2714,8 +2714,10 @@ static void l2cap_add_opt_efs(void **ptr, struct l2cap_chan *chan)
>  		efs.stype	= chan->local_stype;
>  		efs.msdu	= cpu_to_le16(chan->local_msdu);
>  		efs.sdu_itime	= cpu_to_le32(chan->local_sdu_itime);
> -		efs.acc_lat	= __constant_cpu_to_le32(L2CAP_DEFAULT_ACC_LAT);
> -		efs.flush_to	= __constant_cpu_to_le32(L2CAP_DEFAULT_FLUSH_TO);
> +		efs.acc_lat	=
> +			__constant_cpu_to_le32(L2CAP_DEFAULT_ACC_LAT);
> +		efs.flush_to	=
> +			__constant_cpu_to_le32(L2CAP_EFS_DEFAULT_FLUSH_TO);

Just let these lines go over 80 columns.

	Gustavo

^ permalink raw reply

* Re: [PATCH] net, bluetooth: don't attempt to free a channel that wasn't created
From: Gustavo Padovan @ 2012-10-07 21:41 UTC (permalink / raw)
  To: Sasha Levin
  Cc: Andrei Emeltchenko, marcel, johan.hedberg, davem, davej,
	linux-kernel, linux-bluetooth, netdev
In-Reply-To: <506EF827.3060100@oracle.com>

Hi Sasha,

* Sasha Levin <sasha.levin@oracle.com> [2012-10-05 11:09:27 -0400]:

> On 10/05/2012 06:22 AM, Andrei Emeltchenko wrote:
> > Hi Sasha,
> > 
> > On Thu, Oct 04, 2012 at 07:59:57PM -0400, Sasha Levin wrote:
> >> We may currently attempt to free a channel which wasn't created due to
> >> an error in the initialization path, this would cause a NULL ptr deref.
> > 
> > Please put oops dump here.
> 
> [   12.919073] BUG: unable to handle kernel NULL pointer dereference at 0000000000000010
> [   12.919131] IP: [<ffffffff836645c4>] l2cap_chan_put+0x34/0x50
> [   12.919135] PGD 0
> [   12.919138] Oops: 0002 [#1] PREEMPT SMP DEBUG_PAGEALLOC
> [   12.919193] Dumping ftrace buffer:
> [   12.919242]    (ftrace buffer empty)
> [   12.919314] Modules linked in:
> [   12.919318] CPU 1
> [   12.919319] Pid: 6210, comm: krfcommd Tainted: G        W    3.6.0-next-20121004-sasha-00005-gb010653-dirty #30
> [   12.919374] RIP: 0010:[<ffffffff836645c4>]  [<ffffffff836645c4>] l2cap_chan_put+0x34/0x50
> [   12.919377] RSP: 0000:ffff880066933c38  EFLAGS: 00010246
> [   12.919378] RAX: ffffffff8366c780 RBX: 0000000000000000 RCX: 6666666666666667
> [   12.919379] RDX: 0000000000000fa0 RSI: ffffffff84d3f79e RDI: 0000000000000010
> [   12.919381] RBP: ffff880066933c48 R08: ffffffff859989f8 R09: 0000000000000001
> [   12.919382] R10: 0000000000000000 R11: 7fffffffffffffff R12: 0000000000000000
> [   12.919383] R13: ffff88009b00a200 R14: ffff88009b00a200 R15: 0000000000000001
> [   12.919385] FS:  0000000000000000(0000) GS:ffff880033600000(0000) knlGS:0000000000000000
> [   12.919437] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> [   12.919440] CR2: 0000000000000010 CR3: 0000000005026000 CR4: 00000000000406e0
> [   12.919446] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> [   12.919451] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
> [   12.919504] Process krfcommd (pid: 6210, threadinfo ffff880066932000, task ffff880065c4b000)
> [   12.919506] Stack:
> [   12.919510]  ffff88009b00a200 ffff880032084000 ffff880066933c68 ffffffff8366c7bc
> [   12.919513]  7fffffffffffffff ffff880032084000 ffff880066933c98 ffffffff833ae0ae
> [   12.919516]  ffff880066933ca8 0000000000000000 0000000000000000 ffff88009b00a200
> [   12.919517] Call Trace:
> [   12.919522]  [<ffffffff8366c7bc>] l2cap_sock_destruct+0x3c/0x80
> [   12.919527]  [<ffffffff833ae0ae>] __sk_free+0x1e/0x1f0
> [   12.919530]  [<ffffffff833ae2f7>] sk_free+0x17/0x20
> [   12.919585]  [<ffffffff8366ca4e>] l2cap_sock_alloc.constprop.5+0x9e/0xd0
> [   12.919591]  [<ffffffff8366cb9e>] l2cap_sock_create+0x7e/0x100
> [   12.919652]  [<ffffffff83a4f32a>] ? _raw_read_lock+0x6a/0x80
> [   12.919658]  [<ffffffff836402c4>] ? bt_sock_create+0x74/0x110
> [   12.919660]  [<ffffffff83640308>] bt_sock_create+0xb8/0x110
> [   12.919664]  [<ffffffff833aa232>] __sock_create+0x282/0x3b0
> [   12.919720]  [<ffffffff833aa0b0>] ? __sock_create+0x100/0x3b0
> [   12.919725]  [<ffffffff836785b0>] ? rfcomm_process_sessions+0x17e0/0x17e0
> [   12.919779]  [<ffffffff833aa37f>] sock_create_kern+0x1f/0x30
> [   12.919784]  [<ffffffff83675714>] rfcomm_l2sock_create+0x44/0x70
> [   12.919787]  [<ffffffff836785b0>] ? rfcomm_process_sessions+0x17e0/0x17e0
> [   12.919790]  [<ffffffff836785fe>] rfcomm_run+0x4e/0x1f0
> [   12.919846]  [<ffffffff836785b0>] ? rfcomm_process_sessions+0x17e0/0x17e0
> [   12.919852]  [<ffffffff81138ee3>] kthread+0xe3/0xf0
> [   12.919908]  [<ffffffff8117b12e>] ? put_lock_stats.isra.14+0xe/0x40
> [   12.919914]  [<ffffffff81138e00>] ? flush_kthread_work+0x1f0/0x1f0
> [   12.919968]  [<ffffffff83a5077c>] ret_from_fork+0x7c/0x90
> [   12.919973]  [<ffffffff81138e00>] ? flush_kthread_work+0x1f0/0x1f0
> [   12.920161] Code: 83 ec 08 f6 05 ff 58 44 02 04 74 1b 8b 4f 10 48 89 fa 48 c7 c6 d9 d7 d4 84 48 c7 c7 80 9e aa 85 31 c0 e8 80
> ac 3a fe 48 8d 7b 10 <f0> 83 6b 10 01 0f 94 c0 84 c0 74 05 e8 8b e0 ff ff 48 83 c4 08
> [   12.920165] RIP  [<ffffffff836645c4>] l2cap_chan_put+0x34/0x50
> [   12.920166]  RSP <ffff880066933c38>
> [   12.920167] CR2: 0000000000000010
> [   12.920417] ---[ end trace 5a9114e8a158ab84 ]---

Can you append the crash output to the commit message and resend this patch? 

	Gustavo

^ permalink raw reply

* Re: [PATCH BlueZ 1/9] gdbus: Remove connection from g_dbus_remove_watch
From: Luiz Augusto von Dentz @ 2012-10-06 15:09 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1349530857.27233.45.camel@aeonflux>

Hi Marcel,

On Sat, Oct 6, 2012 at 4:40 PM, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Luiz,
>
>> The connection is not really needed since the list of listeners is
>> global not per connection, besides it is more convenient this way as
>> only the id is needed.
>
> they are not global, they are per connection. That we do not fully
> implement this correctly is another story. That should be fixed here.

Not sure if Im following you, the point here is that the caller only
need to store the id because the data that the id refer to already
store the connection as context. Btw let me paste what
g_dbus_remove_watch does:

	for (ldata = listeners; ldata; ldata = ldata->next) {
		data = ldata->data;

		cb = filter_data_find_callback(data, id);
		if (cb) {
			filter_data_remove_callback(data, cb);
			return TRUE;
		}
	}

So as per current implementation the listeners are global, you can
argue it is not very efficient and can cause extra iteration if there
are more connections but overall this seems to pay off to avoid having
the caller to manage connection. Btw this is the same approach glib
uses regarding io watches, they are global so you don't have to store
the GIOChannel together with the id to be able to remove them as the
g_source_remove only takes the id.

-- 
Luiz Augusto von Dentz

^ permalink raw reply

* Re: [PATCH 2/4] client: Add Message.SetProperty and Message.GetProperties implementation.
From: Venkateswaran, Srinivasa Ragavan @ 2012-10-06 13:54 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Srinivasa Ragavan
In-Reply-To: <1349531535-706-3-git-send-email-srinivasa.ragavan.venkateswaran@intel.com>

On Sat, Oct 6, 2012 at 7:22 PM, Srinivasa Ragavan
<srinivasa.ragavan.venkateswaran@intel.com> wrote:
> ---
>  client/map.c |  190 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 190 insertions(+)
>
Argh, got flushed from my outbox, when I was sending a different
patch. This is already applied. Please ignore this patch.

-Srini.
> diff --git a/client/map.c b/client/map.c
> index e78cd68..fc2d874 100644
> --- a/client/map.c
> +++ b/client/map.c
> @@ -28,6 +28,7 @@
>  #include <string.h>
>  #include <stdio.h>
>  #include <glib.h>
> +#include <glib/gstdio.h>
>  #include <gdbus.h>
>
>  #include <gobex-apparam.h>
> @@ -78,6 +79,10 @@ static const char * const filter_list[] = {
>  #define FILTER_BIT_MAX 15
>  #define FILTER_ALL     0xFF
>
> +#define STATUS_READ 0
> +#define STATUS_DELETE 1
> +#define FILLER_BYTE 0x30
> +
>  struct map_data {
>         struct obc_session *session;
>         DBusMessage *msg;
> @@ -104,6 +109,7 @@ struct map_msg {
>         uint64_t size;
>         char *status;
>         uint8_t flags;
> +       DBusMessage *msg;
>  };
>
>  struct map_parser {
> @@ -412,6 +418,183 @@ fail:
>         return reply;
>  }
>
> +static void set_message_status_cb(struct obc_session *session,
> +                                               struct obc_transfer *transfer,
> +                                               GError *err, void *user_data)
> +{
> +       struct map_msg *msg = user_data;
> +       DBusMessage *reply;
> +
> +       if (err != NULL) {
> +               reply = g_dbus_create_error(msg->msg,
> +                                               ERROR_INTERFACE ".Failed",
> +                                               "%s", err->message);
> +               goto done;
> +       }
> +
> +       reply = dbus_message_new_method_return(msg->msg);
> +       if (reply == NULL) {
> +               reply = g_dbus_create_error(msg->msg,
> +                                               ERROR_INTERFACE ".Failed",
> +                                               "%s", err->message);
> +       }
> +
> +done:
> +       g_dbus_send_message(conn, reply);
> +       dbus_message_unref(msg->msg);
> +       msg->msg = NULL;
> +}
> +
> +static DBusMessage *map_msg_set_property(DBusConnection *connection,
> +                                               DBusMessage *message,
> +                                               void *user_data)
> +{
> +       struct map_msg *msg = user_data;
> +       struct obc_transfer *transfer;
> +       char *property;
> +       gboolean status;
> +       GError *err = NULL;
> +       DBusMessage *reply;
> +       GObexApparam *apparam;
> +       char contents[2];
> +       int op;
> +       DBusMessageIter args, variant;
> +
> +       dbus_message_iter_init(message, &args);
> +       if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_STRING)
> +               return g_dbus_create_error(message,
> +                               ERROR_INTERFACE ".InvalidArguments", NULL);
> +
> +       dbus_message_iter_get_basic(&args, &property);
> +       dbus_message_iter_next(&args);
> +       if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_VARIANT)
> +               return g_dbus_create_error(message,
> +                               ERROR_INTERFACE ".InvalidArguments", NULL);
> +
> +       dbus_message_iter_recurse(&args, &variant);
> +       if (dbus_message_iter_get_arg_type(&variant) != DBUS_TYPE_BOOLEAN)
> +               return g_dbus_create_error(message,
> +                               ERROR_INTERFACE ".InvalidArguments", NULL);
> +
> +       dbus_message_iter_get_basic(&variant, &status);
> +
> +       /* MAP supports modifying only these two properties. */
> +       if (property && strcasecmp(property, "Read") == 0) {
> +               op = STATUS_READ;
> +               if (status)
> +                       msg->flags |= MAP_MSG_FLAG_READ;
> +               else
> +                       msg->flags &= ~MAP_MSG_FLAG_READ;
> +       } else if (property && strcasecmp(property, "Deleted") == 0)
> +               op = STATUS_DELETE;
> +       else {
> +               return g_dbus_create_error(message,
> +                               ERROR_INTERFACE ".InvalidArguments", NULL);
> +       }
> +
> +       contents[0] = FILLER_BYTE;
> +       contents[1] = '\0';
> +
> +       transfer = obc_transfer_put("x-bt/messageStatus", msg->handle, NULL,
> +                                                       contents,
> +                                                       sizeof(contents), &err);
> +       if (transfer == NULL)
> +               goto fail;
> +
> +       apparam = g_obex_apparam_set_uint8(NULL, MAP_AP_STATUSINDICATOR,
> +                                                               op);
> +       apparam = g_obex_apparam_set_uint8(apparam, MAP_AP_STATUSVALUE,
> +                                                               status);
> +       obc_transfer_set_apparam(transfer, apparam);
> +
> +       if (!obc_session_queue(msg->data->session, transfer,
> +                           set_message_status_cb, msg, &err))
> +               goto fail;
> +
> +       msg->msg = dbus_message_ref(message);
> +       return NULL;
> +
> +fail:
> +       reply = g_dbus_create_error(message, ERROR_INTERFACE ".Failed", "%s",
> +                                                               err->message);
> +       g_error_free(err);
> +       return reply;
> +}
> +
> +static DBusMessage *map_msg_get_properties(DBusConnection *connection,
> +                                          DBusMessage *message,
> +                                          void *user_data)
> +{
> +       struct map_msg *msg = user_data;
> +       GError *err = NULL;
> +       DBusMessage *reply;
> +       DBusMessageIter iter, data_array;
> +       gboolean flag;
> +
> +       reply = dbus_message_new_method_return(message);
> +       if (reply == NULL) {
> +               reply = g_dbus_create_error(message,
> +                                               ERROR_INTERFACE ".Failed",
> +                                               NULL);
> +               goto done;
> +       }
> +
> +       dbus_message_iter_init_append(reply, &iter);
> +       dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
> +                                       DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
> +                                       DBUS_TYPE_STRING_AS_STRING
> +                                       DBUS_TYPE_VARIANT_AS_STRING
> +                                       DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
> +                                       &data_array);
> +
> +
> +       obex_dbus_dict_append(&data_array, "Subject",
> +                             DBUS_TYPE_STRING, &msg->subject);
> +       obex_dbus_dict_append(&data_array, "Timestamp",
> +                             DBUS_TYPE_STRING, &msg->timestamp);
> +       obex_dbus_dict_append(&data_array, "Sender",
> +                             DBUS_TYPE_STRING, &msg->sender);
> +       obex_dbus_dict_append(&data_array, "SenderAddress",
> +                             DBUS_TYPE_STRING, &msg->sender_address);
> +       obex_dbus_dict_append(&data_array, "ReplyTo",
> +                             DBUS_TYPE_STRING, &msg->replyto);
> +       obex_dbus_dict_append(&data_array, "Recipient",
> +                             DBUS_TYPE_STRING, &msg->recipient);
> +       obex_dbus_dict_append(&data_array, "RecipientAddress",
> +                             DBUS_TYPE_STRING, &msg->recipient_address);
> +       obex_dbus_dict_append(&data_array, "Type",
> +                             DBUS_TYPE_STRING, &msg->type);
> +       obex_dbus_dict_append(&data_array, "Status",
> +                             DBUS_TYPE_STRING, &msg->status);
> +       obex_dbus_dict_append(&data_array, "Size",
> +                             DBUS_TYPE_UINT64, &msg->size);
> +
> +       flag = (msg->flags & MAP_MSG_FLAG_PRIORITY) != 0;
> +       obex_dbus_dict_append(&data_array, "Priority",
> +                             DBUS_TYPE_BOOLEAN, &flag);
> +
> +       flag = (msg->flags & MAP_MSG_FLAG_READ) != 0;
> +       obex_dbus_dict_append(&data_array, "Read",
> +                             DBUS_TYPE_BOOLEAN, &flag);
> +
> +       flag = (msg->flags & MAP_MSG_FLAG_SENT) != 0;
> +       obex_dbus_dict_append(&data_array, "Sent",
> +                             DBUS_TYPE_BOOLEAN, &flag);
> +
> +       flag = (msg->flags & MAP_MSG_FLAG_PROTECTED) != 0;
> +       obex_dbus_dict_append(&data_array, "Protected",
> +                             DBUS_TYPE_BOOLEAN, &flag);
> +
> +       dbus_message_iter_close_container(&iter, &data_array);
> +
> +
> +done:
> +       if (err)
> +               g_error_free(err);
> +
> +       return reply;
> +}
> +
>  static const GDBusMethodTable map_msg_methods[] = {
>         { GDBUS_METHOD("Get",
>                         GDBUS_ARGS({ "targetfile", "s" },
> @@ -419,6 +602,13 @@ static const GDBusMethodTable map_msg_methods[] = {
>                         GDBUS_ARGS({ "transfer", "o" },
>                                                 { "properties", "a{sv}" }),
>                         map_msg_get) },
> +       { GDBUS_METHOD("GetProperties",
> +                       NULL,
> +                       GDBUS_ARGS({ "properties", "a{sv}" }),
> +                       map_msg_get_properties) },
> +       { GDBUS_ASYNC_METHOD("SetProperty",
> +                       GDBUS_ARGS({ "property", "sv" }), NULL,
> +                       map_msg_set_property) },
>         { }
>  };
>
> --
> 1.7.10.4
>

^ permalink raw reply

* Re: [PATCH 1/4] client: Update the file offset to the beginning after writing to the file
From: Venkateswaran, Srinivasa Ragavan @ 2012-10-06 13:54 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Srinivasa Ragavan
In-Reply-To: <1349531535-706-2-git-send-email-srinivasa.ragavan.venkateswaran@intel.com>

On Sat, Oct 6, 2012 at 7:22 PM, Srinivasa Ragavan
<srinivasa.ragavan.venkateswaran@intel.com> wrote:
> When the transfer file is opened in O_RDWR mode, just after the contents are
> written to the file, the file offset has to be set to the beginning of the
> file. If not subsequent read fails. This patch fixes this.

Argh, got flushed from my outbox, when I was sending a different
patch. This is already applied. Please ignore this patch.

-Srini.
> ---
>  client/transfer.c |    1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/client/transfer.c b/client/transfer.c
> index fbcafc8..cac3884 100644
> --- a/client/transfer.c
> +++ b/client/transfer.c
> @@ -426,6 +426,7 @@ struct obc_transfer *obc_transfer_put(const char *type, const char *name,
>                                         "Writing all contents to file failed");
>                         goto fail;
>                 }
> +               lseek(transfer->fd, 0, SEEK_SET);
>         } else {
>                 if (!transfer_open(transfer, O_RDONLY, 0, err))
>                         goto fail;
> --
> 1.7.10.4
>

^ permalink raw reply

* [PATCH 3/3] test: Update map-client to include UpdateInbox.
From: Srinivasa Ragavan @ 2012-10-06 13:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Srinivasa Ragavan
In-Reply-To: <1349531535-706-1-git-send-email-srinivasa.ragavan.venkateswaran@intel.com>

---
 test/map-client |    7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/test/map-client b/test/map-client
index e8c42e3..756ebb8 100755
--- a/test/map-client
+++ b/test/map-client
@@ -51,6 +51,8 @@ def parse_options():
 			help="Deletes the message from the folder")
 	parser.add_option("--mark-undeleted", action="store", dest="mark_msg_undeleted",
 			help="Undeletes the message")
+	parser.add_option("-u", "--update-inbox", action="store_true", dest="update_inbox",
+			help="Checks for new mails")
 
 	return parser.parse_args()
 
@@ -145,6 +147,9 @@ class MapClient:
 		msg = dbus.Interface(obj, "org.bluez.obex.Message")
 		msg.SetProperty (prop, flag);
 
+	def update_inbox(self):
+		self.map.UpdateInbox()
+
 
 if  __name__ == '__main__':
 
@@ -196,5 +201,7 @@ if  __name__ == '__main__':
 	if options.mark_msg_undeleted is not None:
 		map_client.set_message_property(options.mark_msg_undeleted, "Deleted", False)
 
+	if options.update_inbox:
+		map_client.update_inbox()
 
 	mainloop.run()
-- 
1.7.10.4


^ permalink raw reply related

* [PATCH 2/3] client-doc: Add documentation for UpdateInbox
From: Srinivasa Ragavan @ 2012-10-06 13:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Srinivasa Ragavan
In-Reply-To: <1349531535-706-1-git-send-email-srinivasa.ragavan.venkateswaran@intel.com>

---
 doc/client-api.txt |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/doc/client-api.txt b/doc/client-api.txt
index e680427..1222ff3 100644
--- a/doc/client-api.txt
+++ b/doc/client-api.txt
@@ -460,6 +460,11 @@ Methods		void SetFolder(string name)
 
 					Message protected flag
 
+		void UpdateInbox(void)
+
+			Requests the MSE to update its inbox.
+
+
 Filter:		uint16 Offset:
 
 			Offset of the first item, default is 0
-- 
1.7.10.4


^ permalink raw reply related

* [PATCH 2/4] client: Add Message.SetProperty and Message.GetProperties implementation.
From: Srinivasa Ragavan @ 2012-10-06 13:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Srinivasa Ragavan
In-Reply-To: <1349531535-706-1-git-send-email-srinivasa.ragavan.venkateswaran@intel.com>

---
 client/map.c |  190 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 190 insertions(+)

diff --git a/client/map.c b/client/map.c
index e78cd68..fc2d874 100644
--- a/client/map.c
+++ b/client/map.c
@@ -28,6 +28,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <glib.h>
+#include <glib/gstdio.h>
 #include <gdbus.h>
 
 #include <gobex-apparam.h>
@@ -78,6 +79,10 @@ static const char * const filter_list[] = {
 #define FILTER_BIT_MAX	15
 #define FILTER_ALL	0xFF
 
+#define STATUS_READ 0
+#define STATUS_DELETE 1
+#define FILLER_BYTE 0x30
+
 struct map_data {
 	struct obc_session *session;
 	DBusMessage *msg;
@@ -104,6 +109,7 @@ struct map_msg {
 	uint64_t size;
 	char *status;
 	uint8_t flags;
+	DBusMessage *msg;
 };
 
 struct map_parser {
@@ -412,6 +418,183 @@ fail:
 	return reply;
 }
 
+static void set_message_status_cb(struct obc_session *session,
+						struct obc_transfer *transfer,
+						GError *err, void *user_data)
+{
+	struct map_msg *msg = user_data;
+	DBusMessage *reply;
+
+	if (err != NULL) {
+		reply = g_dbus_create_error(msg->msg,
+						ERROR_INTERFACE ".Failed",
+						"%s", err->message);
+		goto done;
+	}
+
+	reply = dbus_message_new_method_return(msg->msg);
+	if (reply == NULL) {
+		reply = g_dbus_create_error(msg->msg,
+						ERROR_INTERFACE ".Failed",
+						"%s", err->message);
+	}
+
+done:
+	g_dbus_send_message(conn, reply);
+	dbus_message_unref(msg->msg);
+	msg->msg = NULL;
+}
+
+static DBusMessage *map_msg_set_property(DBusConnection *connection,
+						DBusMessage *message,
+						void *user_data)
+{
+	struct map_msg *msg = user_data;
+	struct obc_transfer *transfer;
+	char *property;
+	gboolean status;
+	GError *err = NULL;
+	DBusMessage *reply;
+	GObexApparam *apparam;
+	char contents[2];
+	int op;
+	DBusMessageIter args, variant;
+
+	dbus_message_iter_init(message, &args);
+	if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_STRING)
+		return g_dbus_create_error(message,
+				ERROR_INTERFACE ".InvalidArguments", NULL);
+
+	dbus_message_iter_get_basic(&args, &property);
+	dbus_message_iter_next(&args);
+	if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_VARIANT)
+		return g_dbus_create_error(message,
+				ERROR_INTERFACE ".InvalidArguments", NULL);
+
+	dbus_message_iter_recurse(&args, &variant);
+	if (dbus_message_iter_get_arg_type(&variant) != DBUS_TYPE_BOOLEAN)
+		return g_dbus_create_error(message,
+				ERROR_INTERFACE ".InvalidArguments", NULL);
+
+	dbus_message_iter_get_basic(&variant, &status);
+
+	/* MAP supports modifying only these two properties. */
+	if (property && strcasecmp(property, "Read") == 0) {
+		op = STATUS_READ;
+		if (status)
+			msg->flags |= MAP_MSG_FLAG_READ;
+		else
+			msg->flags &= ~MAP_MSG_FLAG_READ;
+	} else if (property && strcasecmp(property, "Deleted") == 0)
+		op = STATUS_DELETE;
+	else {
+		return g_dbus_create_error(message,
+				ERROR_INTERFACE ".InvalidArguments", NULL);
+	}
+
+	contents[0] = FILLER_BYTE;
+	contents[1] = '\0';
+
+	transfer = obc_transfer_put("x-bt/messageStatus", msg->handle, NULL,
+							contents,
+							sizeof(contents), &err);
+	if (transfer == NULL)
+		goto fail;
+
+	apparam = g_obex_apparam_set_uint8(NULL, MAP_AP_STATUSINDICATOR,
+								op);
+	apparam = g_obex_apparam_set_uint8(apparam, MAP_AP_STATUSVALUE,
+								status);
+	obc_transfer_set_apparam(transfer, apparam);
+
+	if (!obc_session_queue(msg->data->session, transfer,
+			    set_message_status_cb, msg, &err))
+		goto fail;
+
+	msg->msg = dbus_message_ref(message);
+	return NULL;
+
+fail:
+	reply = g_dbus_create_error(message, ERROR_INTERFACE ".Failed", "%s",
+								err->message);
+	g_error_free(err);
+	return reply;
+}
+
+static DBusMessage *map_msg_get_properties(DBusConnection *connection,
+					   DBusMessage *message,
+					   void *user_data)
+{
+	struct map_msg *msg = user_data;
+	GError *err = NULL;
+	DBusMessage *reply;
+	DBusMessageIter iter, data_array;
+	gboolean flag;
+
+	reply = dbus_message_new_method_return(message);
+	if (reply == NULL) {
+		reply = g_dbus_create_error(message,
+						ERROR_INTERFACE ".Failed",
+						NULL);
+		goto done;
+	}
+
+	dbus_message_iter_init_append(reply, &iter);
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+					DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+					DBUS_TYPE_STRING_AS_STRING
+					DBUS_TYPE_VARIANT_AS_STRING
+					DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+					&data_array);
+
+
+	obex_dbus_dict_append(&data_array, "Subject",
+			      DBUS_TYPE_STRING, &msg->subject);
+	obex_dbus_dict_append(&data_array, "Timestamp",
+			      DBUS_TYPE_STRING, &msg->timestamp);
+	obex_dbus_dict_append(&data_array, "Sender",
+			      DBUS_TYPE_STRING, &msg->sender);
+	obex_dbus_dict_append(&data_array, "SenderAddress",
+			      DBUS_TYPE_STRING,	&msg->sender_address);
+	obex_dbus_dict_append(&data_array, "ReplyTo",
+			      DBUS_TYPE_STRING, &msg->replyto);
+	obex_dbus_dict_append(&data_array, "Recipient",
+			      DBUS_TYPE_STRING, &msg->recipient);
+	obex_dbus_dict_append(&data_array, "RecipientAddress",
+			      DBUS_TYPE_STRING,	&msg->recipient_address);
+	obex_dbus_dict_append(&data_array, "Type",
+			      DBUS_TYPE_STRING, &msg->type);
+	obex_dbus_dict_append(&data_array, "Status",
+			      DBUS_TYPE_STRING, &msg->status);
+	obex_dbus_dict_append(&data_array, "Size",
+			      DBUS_TYPE_UINT64, &msg->size);
+
+	flag = (msg->flags & MAP_MSG_FLAG_PRIORITY) != 0;
+	obex_dbus_dict_append(&data_array, "Priority",
+			      DBUS_TYPE_BOOLEAN, &flag);
+
+	flag = (msg->flags & MAP_MSG_FLAG_READ) != 0;
+	obex_dbus_dict_append(&data_array, "Read",
+			      DBUS_TYPE_BOOLEAN, &flag);
+
+	flag = (msg->flags & MAP_MSG_FLAG_SENT) != 0;
+	obex_dbus_dict_append(&data_array, "Sent",
+			      DBUS_TYPE_BOOLEAN, &flag);
+
+	flag = (msg->flags & MAP_MSG_FLAG_PROTECTED) != 0;
+	obex_dbus_dict_append(&data_array, "Protected",
+			      DBUS_TYPE_BOOLEAN, &flag);
+
+	dbus_message_iter_close_container(&iter, &data_array);
+
+
+done:
+	if (err)
+		g_error_free(err);
+
+	return reply;
+}
+
 static const GDBusMethodTable map_msg_methods[] = {
 	{ GDBUS_METHOD("Get",
 			GDBUS_ARGS({ "targetfile", "s" },
@@ -419,6 +602,13 @@ static const GDBusMethodTable map_msg_methods[] = {
 			GDBUS_ARGS({ "transfer", "o" },
 						{ "properties", "a{sv}" }),
 			map_msg_get) },
+	{ GDBUS_METHOD("GetProperties",
+			NULL,
+			GDBUS_ARGS({ "properties", "a{sv}" }),
+			map_msg_get_properties) },
+	{ GDBUS_ASYNC_METHOD("SetProperty",
+			GDBUS_ARGS({ "property", "sv" }), NULL,
+			map_msg_set_property) },
 	{ }
 };
 
-- 
1.7.10.4


^ permalink raw reply related

* [PATCH 1/4] client: Update the file offset to the beginning after writing to the file
From: Srinivasa Ragavan @ 2012-10-06 13:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Srinivasa Ragavan
In-Reply-To: <1349531535-706-1-git-send-email-srinivasa.ragavan.venkateswaran@intel.com>

When the transfer file is opened in O_RDWR mode, just after the contents are
written to the file, the file offset has to be set to the beginning of the
file. If not subsequent read fails. This patch fixes this.
---
 client/transfer.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/client/transfer.c b/client/transfer.c
index fbcafc8..cac3884 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -426,6 +426,7 @@ struct obc_transfer *obc_transfer_put(const char *type, const char *name,
 					"Writing all contents to file failed");
 			goto fail;
 		}
+		lseek(transfer->fd, 0, SEEK_SET);
 	} else {
 		if (!transfer_open(transfer, O_RDONLY, 0, err))
 			goto fail;
-- 
1.7.10.4


^ permalink raw reply related

* [PATCH 1/3] client: Add implementation for UpdateInbox
From: Srinivasa Ragavan @ 2012-10-06 13:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Srinivasa Ragavan

---
 client/map.c |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/client/map.c b/client/map.c
index 290eaae..c0a5bfc 100644
--- a/client/map.c
+++ b/client/map.c
@@ -1242,6 +1242,60 @@ static DBusMessage *map_list_filter_fields(DBusConnection *connection,
 	return reply;
 }
 
+static void update_inbox_cb(struct obc_session *session,
+			 struct obc_transfer *transfer,
+			 GError *err, void *user_data)
+{
+	struct map_data *map = user_data;
+	DBusMessage *reply;
+
+	if (err != NULL) {
+		reply = g_dbus_create_error(map->msg,
+						ERROR_INTERFACE ".Failed",
+						"%s", err->message);
+		goto done;
+	}
+
+	reply = dbus_message_new_method_return(map->msg);
+
+done:
+	g_dbus_send_message(conn, reply);
+	dbus_message_unref(map->msg);
+}
+
+static DBusMessage *map_update_inbox(DBusConnection *connection,
+				  DBusMessage *message, void *user_data)
+{
+	struct map_data *map = user_data;
+	DBusMessage *reply;
+	char contents[2];
+	struct obc_transfer *transfer;
+	GError *err = NULL;
+
+	contents[0] = FILLER_BYTE;
+	contents[1] = '\0';
+
+	transfer = obc_transfer_put("x-bt/MAP-messageUpdate", NULL, NULL,
+							contents,
+							sizeof(contents), &err);
+	if (transfer == NULL)
+		goto fail;
+
+	if (!obc_session_queue(map->session, transfer,
+			       update_inbox_cb, map, &err))
+		goto fail;
+
+	map->msg = dbus_message_ref(message);
+
+	return NULL;
+
+fail:
+	reply = g_dbus_create_error(message, ERROR_INTERFACE ".Failed", "%s",
+								err->message);
+	g_error_free(err);
+	return reply;
+}
+
 static const GDBusMethodTable map_methods[] = {
 	{ GDBUS_ASYNC_METHOD("SetFolder",
 				GDBUS_ARGS({ "name", "s" }), NULL,
@@ -1258,6 +1312,10 @@ static const GDBusMethodTable map_methods[] = {
 			NULL,
 			GDBUS_ARGS({ "fields", "as" }),
 			map_list_filter_fields) },
+	{ GDBUS_ASYNC_METHOD("UpdateInbox",
+			NULL,
+			NULL,
+			map_update_inbox) },
 	{ }
 };
 
-- 
1.7.10.4


^ permalink raw reply related

* Re: [PATCH BlueZ 1/9] gdbus: Remove connection from g_dbus_remove_watch
From: Marcel Holtmann @ 2012-10-06 13:40 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <1349472050-25928-1-git-send-email-luiz.dentz@gmail.com>

Hi Luiz,

> The connection is not really needed since the list of listeners is
> global not per connection, besides it is more convenient this way as
> only the id is needed.

they are not global, they are per connection. That we do not fully
implement this correctly is another story. That should be fixed here.

Regards

Marcel



^ permalink raw reply

* Re: [PATCH BlueZ 1/6] gdbus: Fix up Properties.Set() code path
From: Johan Hedberg @ 2012-10-06  7:43 UTC (permalink / raw)
  To: Lucas De Marchi; +Cc: linux-bluetooth, Lucas De Marchi
In-Reply-To: <1349507448-9595-1-git-send-email-lucas.demarchi@profusion.mobi>

Hi Lucas,

On Sat, Oct 06, 2012, Lucas De Marchi wrote:
> Minor fixes to make setter actually work:
> 
> 	- Add propdata in pending_property_set
> 	- Break loop when we are removing propdata from list and we
> 	  found it
> 	- in_args and out_args were swapped
> 	- interface and method name arguments were swapped
> ---
>  gdbus/object.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)

All patches from this set have been applied. Thanks.

Johan

^ permalink raw reply


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