All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC v2 0/5] LE Connection
@ 2012-04-04 20:16 Andre Guedes
  2012-04-04 20:16 ` [RFC v2 1/5] Bluetooth: Add address type to struct sockaddr_l2 Andre Guedes
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Andre Guedes @ 2012-04-04 20:16 UTC (permalink / raw)
  To: linux-bluetooth

Hi all,

This RFC v2 series implements all comments from previous version sent last
week. It also implements the remaining kernel changes (step 4).

The main changes are:
1. Move and rename address type macros to bluetooth.h
2. Remove advertising cache code

Claudio is about to send the user-space RFC series (step 2). It basically
set the address type info for LE connect() calls. This RFC series and
Claudio's RFC series implement all four steps (described in previous cover
letter) which enable user-space informing the address type to kernel in order
to properly establish LE connections.

>From previous cover letter:
----- cut -----
In order to establish a LE connection, we need to know the address type
(public or random) from the remote device. Since this information was not
exposed to user-space and we were not sure about changing the Bluetooth ABI
at that time, we came up with a in-kernel solution to enable LE connections.

We store sensitive information (bdaddr and bdaddr_type) gathered from LE
advertising report events. Once we get a connection request from user-space,
we search the destination address in the advertising cache to get its type
and then start the connection establishment.

Nevertheless, today, the remote device address type is exposed to user-space
through management interface events. We can use this information to establish
LE connection and drop the advertising cache in kernel.

To achieve that, we may add the address type field to struct sockaddr_l2.
This new field would be used for LE connection only. BR/EDR sockets would just
ignore it. We wouldn't even need to set this field for BR/EDR sockets.

These changes would be taken in four steps:
1. Kernel: add address type info to struct sockaddr_l2
2. User-space: set the address type field for LE connections
3. Kernel: use address type info from user-space instead of checking
   advertising cache
4. Kernel: remove advertising cache code

This RFC series implements steps 1 and 3. User-space work is still under
development and we'll send a RFC soon. Step 4 would be started as soon as
we have steps 1, 2 and 3 done.
----- cut -----

BTW, this series depends on "[PATCH] Bluetooth: Remove MGMT_ADDR_INVALID macro"
already sent to the ML.

Regards,

Andre Guedes


Andre Guedes (5):
  Bluetooth: Add address type to struct sockaddr_l2
  Bluetooth: Move address type macros to bluetooth.h
  Bluetooth: Add dst_type parameter to hci_connect
  Bluetooth: Use address type info from User-space
  Bluetooth: Remove advertising cache

 include/net/bluetooth/bluetooth.h |    5 +++
 include/net/bluetooth/hci_core.h  |   27 ++++---------
 include/net/bluetooth/l2cap.h     |    3 +-
 net/bluetooth/hci_conn.c          |   12 ++----
 net/bluetooth/hci_core.c          |   75 -------------------------------------
 net/bluetooth/hci_event.c         |    7 ----
 net/bluetooth/l2cap_core.c        |   11 +++---
 net/bluetooth/l2cap_sock.c        |    2 +-
 net/bluetooth/mgmt.c              |   36 +++++++++---------
 net/bluetooth/sco.c               |    3 +-
 10 files changed, 45 insertions(+), 136 deletions(-)

-- 
1.7.9.4


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [RFC v2 1/5] Bluetooth: Add address type to struct sockaddr_l2
  2012-04-04 20:16 [RFC v2 0/5] LE Connection Andre Guedes
@ 2012-04-04 20:16 ` Andre Guedes
  2012-04-04 20:16 ` [RFC v2 2/5] Bluetooth: Move address type macros to bluetooth.h Andre Guedes
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Andre Guedes @ 2012-04-04 20:16 UTC (permalink / raw)
  To: linux-bluetooth

This patch adds the address type info to struct sockaddr_l2 so
user-space can inform the remote device address type required
to establish LE connections.

Soon, instead of looking the advertising cache up to discover the
address type, we'll use this address type info to establish LE
connections.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
 include/net/bluetooth/l2cap.h |    1 +
 1 file changed, 1 insertion(+)

diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index f6f0500..d14967e 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -57,6 +57,7 @@ struct sockaddr_l2 {
 	__le16		l2_psm;
 	bdaddr_t	l2_bdaddr;
 	__le16		l2_cid;
+	__u8		l2_bdaddr_type;
 };
 
 /* L2CAP socket options */
-- 
1.7.9.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC v2 2/5] Bluetooth: Move address type macros to bluetooth.h
  2012-04-04 20:16 [RFC v2 0/5] LE Connection Andre Guedes
  2012-04-04 20:16 ` [RFC v2 1/5] Bluetooth: Add address type to struct sockaddr_l2 Andre Guedes
@ 2012-04-04 20:16 ` Andre Guedes
  2012-04-04 20:16 ` [RFC v2 3/5] Bluetooth: Add dst_type parameter to hci_connect Andre Guedes
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Andre Guedes @ 2012-04-04 20:16 UTC (permalink / raw)
  To: linux-bluetooth

This patch moves address type macros to bluetooth.h since they will be
used by management interface and Bluetooth socket interface. It also
replaces the macro prefix MGMT_ADDR_ by BDADDR_.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
 include/net/bluetooth/bluetooth.h |    5 +++++
 include/net/bluetooth/hci_core.h  |   16 ++++++----------
 net/bluetooth/mgmt.c              |   28 ++++++++++++++--------------
 3 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index f2c8bdf..3fe927d 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -163,6 +163,11 @@ typedef struct {
 	__u8 b[6];
 } __packed bdaddr_t;
 
+/* BD Address type */
+#define BDADDR_BREDR		0x00
+#define BDADDR_LE_PUBLIC	0x01
+#define BDADDR_LE_RANDOM	0x02
+
 #define BDADDR_ANY   (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
 #define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}})
 
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index c0b232c..542fea2 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -964,16 +964,12 @@ void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb);
 void hci_sock_dev_event(struct hci_dev *hdev, int event);
 
 /* Management interface */
-#define MGMT_ADDR_BREDR			0x00
-#define MGMT_ADDR_LE_PUBLIC		0x01
-#define MGMT_ADDR_LE_RANDOM		0x02
-
-#define DISCOV_TYPE_BREDR		(BIT(MGMT_ADDR_BREDR))
-#define DISCOV_TYPE_LE			(BIT(MGMT_ADDR_LE_PUBLIC) | \
-						BIT(MGMT_ADDR_LE_RANDOM))
-#define DISCOV_TYPE_INTERLEAVED		(BIT(MGMT_ADDR_BREDR) | \
-						BIT(MGMT_ADDR_LE_PUBLIC) | \
-						BIT(MGMT_ADDR_LE_RANDOM))
+#define DISCOV_TYPE_BREDR		(BIT(BDADDR_BREDR))
+#define DISCOV_TYPE_LE			(BIT(BDADDR_LE_PUBLIC) | \
+						BIT(BDADDR_LE_RANDOM))
+#define DISCOV_TYPE_INTERLEAVED		(BIT(BDADDR_BREDR) | \
+						BIT(BDADDR_LE_PUBLIC) | \
+						BIT(BDADDR_LE_RANDOM))
 
 int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len);
 int mgmt_index_added(struct hci_dev *hdev);
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 4e7a01f..c6e70b6 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1532,7 +1532,7 @@ static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data,
 		goto unlock;
 	}
 
-	if (cp->addr.type == MGMT_ADDR_BREDR)
+	if (cp->addr.type == BDADDR_BREDR)
 		err = hci_remove_link_key(hdev, &cp->addr.bdaddr);
 	else
 		err = hci_remove_ltk(hdev, &cp->addr.bdaddr);
@@ -1544,7 +1544,7 @@ static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data,
 	}
 
 	if (cp->disconnect) {
-		if (cp->addr.type == MGMT_ADDR_BREDR)
+		if (cp->addr.type == BDADDR_BREDR)
 			conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK,
 							&cp->addr.bdaddr);
 		else
@@ -1604,7 +1604,7 @@ static int disconnect(struct sock *sk, struct hci_dev *hdev, void *data,
 		goto failed;
 	}
 
-	if (cp->addr.type == MGMT_ADDR_BREDR)
+	if (cp->addr.type == BDADDR_BREDR)
 		conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->addr.bdaddr);
 	else
 		conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->addr.bdaddr);
@@ -1639,16 +1639,16 @@ static u8 link_to_mgmt(u8 link_type, u8 addr_type)
 	case LE_LINK:
 		switch (addr_type) {
 		case ADDR_LE_DEV_PUBLIC:
-			return MGMT_ADDR_LE_PUBLIC;
+			return BDADDR_LE_PUBLIC;
 
 		default:
 			/* Fallback to LE Random address type */
-			return MGMT_ADDR_LE_RANDOM;
+			return BDADDR_LE_RANDOM;
 		}
 
 	default:
 		/* Fallback to BR/EDR type */
-		return MGMT_ADDR_BREDR;
+		return BDADDR_BREDR;
 	}
 }
 
@@ -1910,7 +1910,7 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
 	else
 		auth_type = HCI_AT_DEDICATED_BONDING_MITM;
 
-	if (cp->addr.type == MGMT_ADDR_BREDR)
+	if (cp->addr.type == BDADDR_BREDR)
 		conn = hci_connect(hdev, ACL_LINK, &cp->addr.bdaddr, sec_level,
 				   auth_type);
 	else
@@ -1943,7 +1943,7 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
 	}
 
 	/* For LE, just connecting isn't a proof that the pairing finished */
-	if (cp->addr.type == MGMT_ADDR_BREDR)
+	if (cp->addr.type == BDADDR_BREDR)
 		conn->connect_cfm_cb = pairing_complete_cb;
 
 	conn->security_cfm_cb = pairing_complete_cb;
@@ -2020,7 +2020,7 @@ static int user_pairing_resp(struct sock *sk, struct hci_dev *hdev,
 		goto done;
 	}
 
-	if (type == MGMT_ADDR_BREDR)
+	if (type == BDADDR_BREDR)
 		conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, bdaddr);
 	else
 		conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, bdaddr);
@@ -2031,7 +2031,7 @@ static int user_pairing_resp(struct sock *sk, struct hci_dev *hdev,
 		goto done;
 	}
 
-	if (type == MGMT_ADDR_LE_PUBLIC || type == MGMT_ADDR_LE_RANDOM) {
+	if (type == BDADDR_LE_PUBLIC || type == BDADDR_LE_RANDOM) {
 		/* Continue with pairing via SMP */
 		err = smp_user_confirm_reply(conn, mgmt_op, passkey);
 
@@ -2962,7 +2962,7 @@ int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, u8 persistent)
 
 	ev.store_hint = persistent;
 	bacpy(&ev.key.addr.bdaddr, &key->bdaddr);
-	ev.key.addr.type = MGMT_ADDR_BREDR;
+	ev.key.addr.type = BDADDR_BREDR;
 	ev.key.type = key->type;
 	memcpy(ev.key.val, key->val, 16);
 	ev.key.pin_len = key->pin_len;
@@ -3120,7 +3120,7 @@ int mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure)
 	struct mgmt_ev_pin_code_request ev;
 
 	bacpy(&ev.addr.bdaddr, bdaddr);
-	ev.addr.type = MGMT_ADDR_BREDR;
+	ev.addr.type = BDADDR_BREDR;
 	ev.secure = secure;
 
 	return mgmt_event(MGMT_EV_PIN_CODE_REQUEST, hdev, &ev, sizeof(ev),
@@ -3139,7 +3139,7 @@ int mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
 		return -ENOENT;
 
 	bacpy(&rp.addr.bdaddr, bdaddr);
-	rp.addr.type = MGMT_ADDR_BREDR;
+	rp.addr.type = BDADDR_BREDR;
 
 	err = cmd_complete(cmd->sk, hdev->id, MGMT_OP_PIN_CODE_REPLY,
 			   mgmt_status(status), &rp, sizeof(rp));
@@ -3161,7 +3161,7 @@ int mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
 		return -ENOENT;
 
 	bacpy(&rp.addr.bdaddr, bdaddr);
-	rp.addr.type = MGMT_ADDR_BREDR;
+	rp.addr.type = BDADDR_BREDR;
 
 	err = cmd_complete(cmd->sk, hdev->id, MGMT_OP_PIN_CODE_NEG_REPLY,
 			   mgmt_status(status), &rp, sizeof(rp));
-- 
1.7.9.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC v2 3/5] Bluetooth: Add dst_type parameter to hci_connect
  2012-04-04 20:16 [RFC v2 0/5] LE Connection Andre Guedes
  2012-04-04 20:16 ` [RFC v2 1/5] Bluetooth: Add address type to struct sockaddr_l2 Andre Guedes
  2012-04-04 20:16 ` [RFC v2 2/5] Bluetooth: Move address type macros to bluetooth.h Andre Guedes
@ 2012-04-04 20:16 ` Andre Guedes
  2012-04-05 10:22   ` Johan Hedberg
  2012-04-04 20:16 ` [RFC v2 4/5] Bluetooth: Use address type info from User-space Andre Guedes
  2012-04-04 20:16 ` [RFC v2 5/5] Bluetooth: Remove advertising cache Andre Guedes
  4 siblings, 1 reply; 11+ messages in thread
From: Andre Guedes @ 2012-04-04 20:16 UTC (permalink / raw)
  To: linux-bluetooth

This patch adds the dst_type parameter to hci_connect function.
Instead of searching the address type in advertising cache, we
use the dst_type parameter to establish LE connections.

The dst_type is ignored for BR/EDR connection establishment.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
 include/net/bluetooth/hci_core.h |    2 +-
 net/bluetooth/hci_conn.c         |   12 ++++--------
 net/bluetooth/l2cap_core.c       |    4 ++--
 net/bluetooth/mgmt.c             |    8 ++++----
 net/bluetooth/sco.c              |    3 ++-
 5 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 542fea2..9083a95 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -574,7 +574,7 @@ int hci_chan_del(struct hci_chan *chan);
 void hci_chan_list_flush(struct hci_conn *conn);
 
 struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
-						__u8 sec_level, __u8 auth_type);
+				__u8 dst_type, __u8 sec_level, __u8 auth_type);
 int hci_conn_check_link_mode(struct hci_conn *conn);
 int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level);
 int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type);
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 947172b..4975a76 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -514,7 +514,8 @@ EXPORT_SYMBOL(hci_get_route);
 
 /* Create SCO, ACL or LE connection.
  * Device _must_ be locked */
-struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8 sec_level, __u8 auth_type)
+struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
+				__u8 dst_type, __u8 sec_level, __u8 auth_type)
 {
 	struct hci_conn *acl;
 	struct hci_conn *sco;
@@ -523,21 +524,16 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8
 	BT_DBG("%s dst %s", hdev->name, batostr(dst));
 
 	if (type == LE_LINK) {
-		struct adv_entry *entry;
-
 		le = hci_conn_hash_lookup_ba(hdev, LE_LINK, dst);
 		if (le)
 			return ERR_PTR(-EBUSY);
 
-		entry = hci_find_adv_entry(hdev, dst);
-		if (!entry)
-			return ERR_PTR(-EHOSTUNREACH);
-
 		le = hci_conn_add(hdev, LE_LINK, dst);
 		if (!le)
 			return ERR_PTR(-ENOMEM);
 
-		le->dst_type = entry->bdaddr_type;
+		le->dst_type = (dst_type == BDADDR_LE_PUBLIC) ?
+				ADDR_LE_DEV_PUBLIC : ADDR_LE_DEV_RANDOM;
 
 		hci_le_connect(le);
 
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 3caff27..6090bad 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1216,10 +1216,10 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, bdaddr_t *d
 	auth_type = l2cap_get_auth_type(chan);
 
 	if (chan->dcid == L2CAP_CID_LE_DATA)
-		hcon = hci_connect(hdev, LE_LINK, dst,
+		hcon = hci_connect(hdev, LE_LINK, dst, BDADDR_LE_RANDOM,
 					chan->sec_level, auth_type);
 	else
-		hcon = hci_connect(hdev, ACL_LINK, dst,
+		hcon = hci_connect(hdev, ACL_LINK, dst, BDADDR_BREDR,
 					chan->sec_level, auth_type);
 
 	if (IS_ERR(hcon)) {
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index c6e70b6..b637aad 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1911,11 +1911,11 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
 		auth_type = HCI_AT_DEDICATED_BONDING_MITM;
 
 	if (cp->addr.type == BDADDR_BREDR)
-		conn = hci_connect(hdev, ACL_LINK, &cp->addr.bdaddr, sec_level,
-				   auth_type);
+		conn = hci_connect(hdev, ACL_LINK, &cp->addr.bdaddr,
+					cp->addr.type, sec_level, auth_type);
 	else
-		conn = hci_connect(hdev, LE_LINK, &cp->addr.bdaddr, sec_level,
-				   auth_type);
+		conn = hci_connect(hdev, LE_LINK, &cp->addr.bdaddr,
+					cp->addr.type, sec_level, auth_type);
 
 	memset(&rp, 0, sizeof(rp));
 	bacpy(&rp.addr.bdaddr, &cp->addr.bdaddr);
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 8bf26d1..c17a022 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -196,7 +196,8 @@ static int sco_connect(struct sock *sk)
 	else
 		type = SCO_LINK;
 
-	hcon = hci_connect(hdev, type, dst, BT_SECURITY_LOW, HCI_AT_NO_BONDING);
+	hcon = hci_connect(hdev, type, dst, BDADDR_BREDR, BT_SECURITY_LOW,
+				HCI_AT_NO_BONDING);
 	if (IS_ERR(hcon)) {
 		err = PTR_ERR(hcon);
 		goto done;
-- 
1.7.9.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC v2 4/5] Bluetooth: Use address type info from User-space
  2012-04-04 20:16 [RFC v2 0/5] LE Connection Andre Guedes
                   ` (2 preceding siblings ...)
  2012-04-04 20:16 ` [RFC v2 3/5] Bluetooth: Add dst_type parameter to hci_connect Andre Guedes
@ 2012-04-04 20:16 ` Andre Guedes
  2012-04-05 10:23   ` Johan Hedberg
  2012-04-04 20:16 ` [RFC v2 5/5] Bluetooth: Remove advertising cache Andre Guedes
  4 siblings, 1 reply; 11+ messages in thread
From: Andre Guedes @ 2012-04-04 20:16 UTC (permalink / raw)
  To: linux-bluetooth

In order to establish a LE connection we need the address type
information. User-space already pass this information to kernel
through struct sockaddr_l2.

This patch adds the dst_type parameter to l2cap_chan_connect so we
are able to pass the address type info from user-space down to
hci_conn layer.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
 include/net/bluetooth/l2cap.h |    2 +-
 net/bluetooth/l2cap_core.c    |   11 ++++++-----
 net/bluetooth/l2cap_sock.c    |    2 +-
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index d14967e..165f530 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -911,7 +911,7 @@ struct l2cap_chan *l2cap_chan_create(void);
 void l2cap_chan_close(struct l2cap_chan *chan, int reason);
 void l2cap_chan_destroy(struct l2cap_chan *chan);
 int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
-								bdaddr_t *dst);
+			bdaddr_t *dst, u8 dst_type);
 int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len,
 								u32 priority);
 void l2cap_chan_busy(struct l2cap_chan *chan, int busy);
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 6090bad..df21e9d 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1131,7 +1131,8 @@ static struct l2cap_chan *l2cap_global_chan_by_psm(int state, __le16 psm, bdaddr
 	return c1;
 }
 
-int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, bdaddr_t *dst)
+int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
+			bdaddr_t *dst, u8 dst_type)
 {
 	struct sock *sk = chan->sk;
 	bdaddr_t *src = &bt_sk(sk)->src;
@@ -1141,8 +1142,8 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, bdaddr_t *d
 	__u8 auth_type;
 	int err;
 
-	BT_DBG("%s -> %s psm 0x%2.2x", batostr(src), batostr(dst),
-						__le16_to_cpu(chan->psm));
+	BT_DBG("%s -> %s (type %u) psm 0x%2.2x", batostr(src), batostr(dst),
+		dst_type, __le16_to_cpu(chan->psm));
 
 	hdev = hci_get_route(dst, src);
 	if (!hdev)
@@ -1216,10 +1217,10 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, bdaddr_t *d
 	auth_type = l2cap_get_auth_type(chan);
 
 	if (chan->dcid == L2CAP_CID_LE_DATA)
-		hcon = hci_connect(hdev, LE_LINK, dst, BDADDR_LE_RANDOM,
+		hcon = hci_connect(hdev, LE_LINK, dst, dst_type,
 					chan->sec_level, auth_type);
 	else
-		hcon = hci_connect(hdev, ACL_LINK, dst, BDADDR_BREDR,
+		hcon = hci_connect(hdev, ACL_LINK, dst, dst_type,
 					chan->sec_level, auth_type);
 
 	if (IS_ERR(hcon)) {
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 1d3e9c3..2bd5725 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -124,7 +124,7 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr, int al
 		return -EINVAL;
 
 	err = l2cap_chan_connect(chan, la.l2_psm, __le16_to_cpu(la.l2_cid),
-				&la.l2_bdaddr);
+				&la.l2_bdaddr, la.l2_bdaddr_type);
 	if (err)
 		return err;
 
-- 
1.7.9.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC v2 5/5] Bluetooth: Remove advertising cache
  2012-04-04 20:16 [RFC v2 0/5] LE Connection Andre Guedes
                   ` (3 preceding siblings ...)
  2012-04-04 20:16 ` [RFC v2 4/5] Bluetooth: Use address type info from User-space Andre Guedes
@ 2012-04-04 20:16 ` Andre Guedes
  4 siblings, 0 replies; 11+ messages in thread
From: Andre Guedes @ 2012-04-04 20:16 UTC (permalink / raw)
  To: linux-bluetooth

User-space pass the remote device address type to kernel through
struct sockaddr_l2 what makes the advertising useless. This patch
removes all advertising cache code.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
 include/net/bluetooth/hci_core.h |    9 -----
 net/bluetooth/hci_core.c         |   75 --------------------------------------
 net/bluetooth/hci_event.c        |    7 ----
 3 files changed, 91 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 9083a95..b79099a 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -255,9 +255,6 @@ struct hci_dev {
 
 	struct list_head	remote_oob_data;
 
-	struct list_head	adv_entries;
-	struct delayed_work	adv_work;
-
 	struct hci_dev_stats	stat;
 
 	struct sk_buff_head	driver_init;
@@ -691,12 +688,6 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
 								u8 *randomizer);
 int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr);
 
-#define ADV_CLEAR_TIMEOUT (3*60*HZ) /* Three minutes */
-int hci_adv_entries_clear(struct hci_dev *hdev);
-struct adv_entry *hci_find_adv_entry(struct hci_dev *hdev, bdaddr_t *bdaddr);
-int hci_add_adv_entry(struct hci_dev *hdev,
-					struct hci_ev_le_advertising_info *ev);
-
 void hci_del_off_timer(struct hci_dev *hdev);
 
 void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 286f3fc..6111de9 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1547,75 +1547,6 @@ int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
 	return mgmt_device_unblocked(hdev, bdaddr, type);
 }
 
-static void hci_clear_adv_cache(struct work_struct *work)
-{
-	struct hci_dev *hdev = container_of(work, struct hci_dev,
-					    adv_work.work);
-
-	hci_dev_lock(hdev);
-
-	hci_adv_entries_clear(hdev);
-
-	hci_dev_unlock(hdev);
-}
-
-int hci_adv_entries_clear(struct hci_dev *hdev)
-{
-	struct adv_entry *entry, *tmp;
-
-	list_for_each_entry_safe(entry, tmp, &hdev->adv_entries, list) {
-		list_del(&entry->list);
-		kfree(entry);
-	}
-
-	BT_DBG("%s adv cache cleared", hdev->name);
-
-	return 0;
-}
-
-struct adv_entry *hci_find_adv_entry(struct hci_dev *hdev, bdaddr_t *bdaddr)
-{
-	struct adv_entry *entry;
-
-	list_for_each_entry(entry, &hdev->adv_entries, list)
-		if (bacmp(bdaddr, &entry->bdaddr) == 0)
-			return entry;
-
-	return NULL;
-}
-
-static inline int is_connectable_adv(u8 evt_type)
-{
-	if (evt_type == ADV_IND || evt_type == ADV_DIRECT_IND)
-		return 1;
-
-	return 0;
-}
-
-int hci_add_adv_entry(struct hci_dev *hdev,
-					struct hci_ev_le_advertising_info *ev) { struct adv_entry *entry; if (!is_connectable_adv(ev->evt_type))
-		return -EINVAL;
-
-	/* Only new entries should be added to adv_entries. So, if
-	 * bdaddr was found, don't add it. */
-	if (hci_find_adv_entry(hdev, &ev->bdaddr))
-		return 0;
-
-	entry = kzalloc(sizeof(*entry), GFP_KERNEL);
-	if (!entry)
-		return -ENOMEM;
-
-	bacpy(&entry->bdaddr, &ev->bdaddr);
-	entry->bdaddr_type = ev->bdaddr_type;
-
-	list_add(&entry->list, &hdev->adv_entries);
-
-	BT_DBG("%s adv entry added: address %s type %u", hdev->name,
-				batostr(&entry->bdaddr), entry->bdaddr_type);
-
-	return 0;
-}
-
 static void le_scan_param_req(struct hci_dev *hdev, unsigned long opt)
 {
 	struct le_scan_params *param =  (struct le_scan_params *) opt;
@@ -1809,9 +1740,6 @@ int hci_register_dev(struct hci_dev *hdev)
 
 	INIT_LIST_HEAD(&hdev->remote_oob_data);
 
-	INIT_LIST_HEAD(&hdev->adv_entries);
-
-	INIT_DELAYED_WORK(&hdev->adv_work, hci_clear_adv_cache);
 	INIT_WORK(&hdev->power_on, hci_power_on);
 	INIT_DELAYED_WORK(&hdev->power_off, hci_power_off);
 
@@ -1905,8 +1833,6 @@ void hci_unregister_dev(struct hci_dev *hdev)
 
 	hci_del_sysfs(hdev);
 
-	cancel_delayed_work_sync(&hdev->adv_work);
-
 	destroy_workqueue(hdev->workqueue);
 
 	hci_dev_lock(hdev);
@@ -1915,7 +1841,6 @@ void hci_unregister_dev(struct hci_dev *hdev)
 	hci_link_keys_clear(hdev);
 	hci_smp_ltks_clear(hdev);
 	hci_remote_oob_data_clear(hdev);
-	hci_adv_entries_clear(hdev);
 	hci_dev_unlock(hdev);
 
 	hci_dev_put(hdev);
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 7325300..f78524f 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1101,10 +1101,7 @@ static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,
 
 		set_bit(HCI_LE_SCAN, &hdev->dev_flags);
 
-		cancel_delayed_work_sync(&hdev->adv_work);
-
 		hci_dev_lock(hdev);
-		hci_adv_entries_clear(hdev);
 		hci_discovery_set_state(hdev, DISCOVERY_FINDING);
 		hci_dev_unlock(hdev);
 		break;
@@ -1119,8 +1116,6 @@ static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,
 
 		clear_bit(HCI_LE_SCAN, &hdev->dev_flags);
 
-		schedule_delayed_work(&hdev->adv_work, ADV_CLEAR_TIMEOUT);
-
 		if (hdev->discovery.type == DISCOV_TYPE_INTERLEAVED &&
 				hdev->discovery.state == DISCOVERY_FINDING) {
 			mgmt_interleaved_discovery(hdev);
@@ -3349,8 +3344,6 @@ static inline void hci_le_adv_report_evt(struct hci_dev *hdev,
 	while (num_reports--) {
 		struct hci_ev_le_advertising_info *ev = ptr;
 
-		hci_add_adv_entry(hdev, ev);
-
 		rssi = ev->data[ev->length];
 		mgmt_device_found(hdev, &ev->bdaddr, LE_LINK, ev->bdaddr_type,
 				  NULL, rssi, 0, 1, ev->data, ev->length);
-- 
1.7.9.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [RFC v2 3/5] Bluetooth: Add dst_type parameter to hci_connect
  2012-04-04 20:16 ` [RFC v2 3/5] Bluetooth: Add dst_type parameter to hci_connect Andre Guedes
@ 2012-04-05 10:22   ` Johan Hedberg
  2012-04-05 11:17     ` Anderson Lizardo
  2012-04-05 14:04     ` Andre Guedes
  0 siblings, 2 replies; 11+ messages in thread
From: Johan Hedberg @ 2012-04-05 10:22 UTC (permalink / raw)
  To: Andre Guedes; +Cc: linux-bluetooth

Hi Andre,

On Wed, Apr 04, 2012, Andre Guedes wrote:
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index 542fea2..9083a95 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -574,7 +574,7 @@ int hci_chan_del(struct hci_chan *chan);
>  void hci_chan_list_flush(struct hci_conn *conn);
>  
>  struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
> -						__u8 sec_level, __u8 auth_type);
> +				__u8 dst_type, __u8 sec_level, __u8 auth_type);

It seems like you're not using the "new" style of aligning with the
opening parenthesis here.

> --- a/net/bluetooth/mgmt.c
> +++ b/net/bluetooth/mgmt.c
> @@ -1911,11 +1911,11 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
>  		auth_type = HCI_AT_DEDICATED_BONDING_MITM;
>  
>  	if (cp->addr.type == BDADDR_BREDR)
> -		conn = hci_connect(hdev, ACL_LINK, &cp->addr.bdaddr, sec_level,
> -				   auth_type);
> +		conn = hci_connect(hdev, ACL_LINK, &cp->addr.bdaddr,
> +					cp->addr.type, sec_level, auth_type);
>  	else
> -		conn = hci_connect(hdev, LE_LINK, &cp->addr.bdaddr, sec_level,
> -				   auth_type);
> +		conn = hci_connect(hdev, LE_LINK, &cp->addr.bdaddr,
> +					cp->addr.type, sec_level, auth_type);

Same issue with the above two cases.

> --- a/net/bluetooth/sco.c
> +++ b/net/bluetooth/sco.c
> @@ -196,7 +196,8 @@ static int sco_connect(struct sock *sk)
>  	else
>  		type = SCO_LINK;
>  
> -	hcon = hci_connect(hdev, type, dst, BT_SECURITY_LOW, HCI_AT_NO_BONDING);
> +	hcon = hci_connect(hdev, type, dst, BDADDR_BREDR, BT_SECURITY_LOW,
> +				HCI_AT_NO_BONDING);

And here as well.

Johan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC v2 4/5] Bluetooth: Use address type info from User-space
  2012-04-04 20:16 ` [RFC v2 4/5] Bluetooth: Use address type info from User-space Andre Guedes
@ 2012-04-05 10:23   ` Johan Hedberg
  0 siblings, 0 replies; 11+ messages in thread
From: Johan Hedberg @ 2012-04-05 10:23 UTC (permalink / raw)
  To: Andre Guedes; +Cc: linux-bluetooth

Hi Andre,

On Wed, Apr 04, 2012, Andre Guedes wrote:
>  	err = l2cap_chan_connect(chan, la.l2_psm, __le16_to_cpu(la.l2_cid),
> -				&la.l2_bdaddr);
> +				&la.l2_bdaddr, la.l2_bdaddr_type);

Same alignment issue here. Since you're modifying the line you might as
well fix the alignment too.

Johan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC v2 3/5] Bluetooth: Add dst_type parameter to hci_connect
  2012-04-05 10:22   ` Johan Hedberg
@ 2012-04-05 11:17     ` Anderson Lizardo
  2012-04-05 11:31       ` Johan Hedberg
  2012-04-05 14:04     ` Andre Guedes
  1 sibling, 1 reply; 11+ messages in thread
From: Anderson Lizardo @ 2012-04-05 11:17 UTC (permalink / raw)
  To: Andre Guedes, linux-bluetooth

Hi Johan,

On Thu, Apr 5, 2012 at 6:22 AM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
> Hi Andre,
>
> On Wed, Apr 04, 2012, Andre Guedes wrote:
>> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
>> index 542fea2..9083a95 100644
>> --- a/include/net/bluetooth/hci_core.h
>> +++ b/include/net/bluetooth/hci_core.h
>> @@ -574,7 +574,7 @@ int hci_chan_del(struct hci_chan *chan);
>>  void hci_chan_list_flush(struct hci_conn *conn);
>>
>>  struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
>> -                                             __u8 sec_level, __u8 auth_type);
>> +                             __u8 dst_type, __u8 sec_level, __u8 auth_type);
>
> It seems like you're not using the "new" style of aligning with the
> opening parenthesis here.

About this alignment, should it be done with spaces when necessary
(i.e. when using just tabs does not align)?

I think I have missed discussions about this (maybe because I don't
follow LKML closely).

Regards,
-- 
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC v2 3/5] Bluetooth: Add dst_type parameter to hci_connect
  2012-04-05 11:17     ` Anderson Lizardo
@ 2012-04-05 11:31       ` Johan Hedberg
  0 siblings, 0 replies; 11+ messages in thread
From: Johan Hedberg @ 2012-04-05 11:31 UTC (permalink / raw)
  To: Anderson Lizardo; +Cc: Andre Guedes, linux-bluetooth

Hi Lizardo,

On Thu, Apr 05, 2012, Anderson Lizardo wrote:
> Hi Johan,
> 
> On Thu, Apr 5, 2012 at 6:22 AM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
> > Hi Andre,
> >
> > On Wed, Apr 04, 2012, Andre Guedes wrote:
> >> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> >> index 542fea2..9083a95 100644
> >> --- a/include/net/bluetooth/hci_core.h
> >> +++ b/include/net/bluetooth/hci_core.h
> >> @@ -574,7 +574,7 @@ int hci_chan_del(struct hci_chan *chan);
> >>  void hci_chan_list_flush(struct hci_conn *conn);
> >>
> >>  struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
> >> -                                             __u8 sec_level, __u8 auth_type);
> >> +                             __u8 dst_type, __u8 sec_level, __u8 auth_type);
> >
> > It seems like you're not using the "new" style of aligning with the
> > opening parenthesis here.
> 
> About this alignment, should it be done with spaces when necessary
> (i.e. when using just tabs does not align)?

Yes, use as many tabs as you can and then add spaces until you align
with the opening parenthesis.

> I think I have missed discussions about this (maybe because I don't
> follow LKML closely).

IIRC it was on the linux-wireless[1] and netdev[2] lists. Essentially
the net maintainer said he'd refuse our pull requests if we don't follow
this new style (even though the old style is what our subsystem has used
from the very beginning and it doesn't violate the CodingStyle
document).

Johan

[1] https://lkml.org/lkml/2012/2/21/299
[2] http://www.spinics.net/lists/netdev/msg190606.html

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC v2 3/5] Bluetooth: Add dst_type parameter to hci_connect
  2012-04-05 10:22   ` Johan Hedberg
  2012-04-05 11:17     ` Anderson Lizardo
@ 2012-04-05 14:04     ` Andre Guedes
  1 sibling, 0 replies; 11+ messages in thread
From: Andre Guedes @ 2012-04-05 14:04 UTC (permalink / raw)
  To: Andre Guedes, linux-bluetooth

Hi Johan,

On Thu, Apr 5, 2012 at 7:22 AM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
> Hi Andre,
>
> On Wed, Apr 04, 2012, Andre Guedes wrote:
>> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
>> index 542fea2..9083a95 100644
>> --- a/include/net/bluetooth/hci_core.h
>> +++ b/include/net/bluetooth/hci_core.h
>> @@ -574,7 +574,7 @@ int hci_chan_del(struct hci_chan *chan);
>>  void hci_chan_list_flush(struct hci_conn *conn);
>>
>>  struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
>> -                                             __u8 sec_level, __u8 auth_type);
>> +                             __u8 dst_type, __u8 sec_level, __u8 auth_type);
>
> It seems like you're not using the "new" style of aligning with the
> opening parenthesis here.
>
>> --- a/net/bluetooth/mgmt.c
>> +++ b/net/bluetooth/mgmt.c
>> @@ -1911,11 +1911,11 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
>>               auth_type = HCI_AT_DEDICATED_BONDING_MITM;
>>
>>       if (cp->addr.type == BDADDR_BREDR)
>> -             conn = hci_connect(hdev, ACL_LINK, &cp->addr.bdaddr, sec_level,
>> -                                auth_type);
>> +             conn = hci_connect(hdev, ACL_LINK, &cp->addr.bdaddr,
>> +                                     cp->addr.type, sec_level, auth_type);
>>       else
>> -             conn = hci_connect(hdev, LE_LINK, &cp->addr.bdaddr, sec_level,
>> -                                auth_type);
>> +             conn = hci_connect(hdev, LE_LINK, &cp->addr.bdaddr,
>> +                                     cp->addr.type, sec_level, auth_type);
>
> Same issue with the above two cases.
>
>> --- a/net/bluetooth/sco.c
>> +++ b/net/bluetooth/sco.c
>> @@ -196,7 +196,8 @@ static int sco_connect(struct sock *sk)
>>       else
>>               type = SCO_LINK;
>>
>> -     hcon = hci_connect(hdev, type, dst, BT_SECURITY_LOW, HCI_AT_NO_BONDING);
>> +     hcon = hci_connect(hdev, type, dst, BDADDR_BREDR, BT_SECURITY_LOW,
>> +                             HCI_AT_NO_BONDING);
>
> And here as well.

I'll fix all aligning style issues from this series and send a new version.

Thanks,

Andre

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-04-05 14:04 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-04 20:16 [RFC v2 0/5] LE Connection Andre Guedes
2012-04-04 20:16 ` [RFC v2 1/5] Bluetooth: Add address type to struct sockaddr_l2 Andre Guedes
2012-04-04 20:16 ` [RFC v2 2/5] Bluetooth: Move address type macros to bluetooth.h Andre Guedes
2012-04-04 20:16 ` [RFC v2 3/5] Bluetooth: Add dst_type parameter to hci_connect Andre Guedes
2012-04-05 10:22   ` Johan Hedberg
2012-04-05 11:17     ` Anderson Lizardo
2012-04-05 11:31       ` Johan Hedberg
2012-04-05 14:04     ` Andre Guedes
2012-04-04 20:16 ` [RFC v2 4/5] Bluetooth: Use address type info from User-space Andre Guedes
2012-04-05 10:23   ` Johan Hedberg
2012-04-04 20:16 ` [RFC v2 5/5] Bluetooth: Remove advertising cache Andre Guedes

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.