Skip to contentSkip to conversation

Bluetooth: Remove auth_type parameter from hci_connect_le()

PATCH In review [email protected] 2 participants 4 messages Jul 7, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Bluetooth: Remove auth_type parameter from hci_connect_le()

From: Johan Hedberg <[email protected]>

The auth_type value which gets assigned to hci_conn->auth_type is something that's only used for BR/EDR connections and is of no value for LE connections. It makes therefore little sense to pass it to the hci_connect_le() function. This patch removes the parameter from the function.

---
 include/net/bluetooth/hci_core.h | 3 +--
 net/bluetooth/hci_conn.c         | 5 +----
 net/bluetooth/hci_event.c        | 2 +-
 net/bluetooth/l2cap_core.c       | 6 ++----
 net/bluetooth/mgmt.c             | 3 +--
 5 files changed, 6 insertions(+), 13 deletions(-)
include/net/bluetooth/hci_core.h +1 -2
index 06039aae3010..8752ac674db1 100644
@@ -704,8 +704,7 @@ void hci_chan_list_flush(struct hci_conn *conn);
 struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle);
 
 struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
-				u8 dst_type, u8 sec_level, u8 auth_type,
-				u16 conn_timeout);
+				u8 dst_type, u8 sec_level, u16 conn_timeout);
 struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
 				 u8 sec_level, u8 auth_type);
 struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
net/bluetooth/hci_conn.c +1 -4
index faa032fcdaee..9323044f01cd 100644
@@ -700,8 +700,7 @@ static void hci_req_directed_advertising(struct hci_request *req,
 }
 
 struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
-				u8 dst_type, u8 sec_level, u8 auth_type,
-				u16 conn_timeout)
+				u8 dst_type, u8 sec_level, u16 conn_timeout)
 {
 	struct hci_conn_params *params;
 	struct hci_conn *conn;
@@ -721,7 +720,6 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
 	conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, dst);
 	if (conn) {
 		conn->pending_sec_level = sec_level;
-		conn->auth_type = auth_type;
 		goto done;
 	}
 
@@ -758,7 +756,6 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
 	conn->dst_type = dst_type;
 	conn->sec_level = BT_SECURITY_LOW;
 	conn->pending_sec_level = sec_level;
-	conn->auth_type = auth_type;
 	conn->conn_timeout = conn_timeout;
 
 	hci_req_init(&req, hdev);
net/bluetooth/hci_event.c +1 -1
index 84f4659f136e..ad39d9ad6fbc 100644
@@ -4254,7 +4254,7 @@ static void check_pending_le_conn(struct hci_dev *hdev, bdaddr_t *addr,
 
 connect:
 	conn = hci_connect_le(hdev, addr, addr_type, BT_SECURITY_LOW,
-			      HCI_AT_NO_BONDING, HCI_LE_AUTOCONN_TIMEOUT);
+			      HCI_LE_AUTOCONN_TIMEOUT);
 	if (!IS_ERR(conn))
 		return;
 
net/bluetooth/l2cap_core.c +2 -4
index a219276d9f92..3daab4588522 100644
@@ -7048,7 +7048,6 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
 	struct l2cap_conn *conn;
 	struct hci_conn *hcon;
 	struct hci_dev *hdev;
-	__u8 auth_type;
 	int err;
 
 	BT_DBG("%pMR -> %pMR (type %u) psm 0x%2.2x", &chan->src, dst,
@@ -7124,8 +7123,6 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
 	chan->psm = psm;
 	chan->dcid = cid;
 
-	auth_type = l2cap_get_auth_type(chan);
-
 	if (bdaddr_type_is_le(dst_type)) {
 		/* Convert from L2CAP channel address type to HCI address type
 		 */
@@ -7135,8 +7132,9 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
 			dst_type = ADDR_LE_DEV_RANDOM;
 
 		hcon = hci_connect_le(hdev, dst, dst_type, chan->sec_level,
-				      auth_type, HCI_LE_CONN_TIMEOUT);
+				      HCI_LE_CONN_TIMEOUT);
 	} else {
+		u8 auth_type = l2cap_get_auth_type(chan);
 		hcon = hci_connect_acl(hdev, dst, chan->sec_level, auth_type);
 	}
 
net/bluetooth/mgmt.c +1 -2
index ef675acbcfce..e7047de1ba11 100644
@@ -3118,8 +3118,7 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
 		hci_conn_params_add(hdev, &cp->addr.bdaddr, addr_type);
 
 		conn = hci_connect_le(hdev, &cp->addr.bdaddr, addr_type,
-				      sec_level, auth_type,
-				      HCI_LE_CONN_TIMEOUT);
+				      sec_level, HCI_LE_CONN_TIMEOUT);
 	}
 
 	if (IS_ERR(conn)) {
Signature · 1 line
1.9.3
#1 lore raw

PATCH 2/2 Bluetooth: Pass desired connection role to hci_connect_le()

From: Johan Hedberg <[email protected]>

If we have both LE scanning and advertising simultaneously enabled we need a way to tell hci_connect_le() in which role to initiate a connection. This patch adds a new parameter to the function to give it the necessary information. For auto-connect and mgmt_pair_device we always use master role, whereas for L2CAP users (in practice sockets) we use slave role whenever HCI_ADVERTISING is set and master role otherwise.

---
 include/net/bluetooth/hci_core.h | 3 ++-
 net/bluetooth/hci_conn.c         | 6 ++++--
 net/bluetooth/hci_event.c        | 3 ++-
 net/bluetooth/l2cap_core.c       | 6 +++++-
 net/bluetooth/mgmt.c             | 3 ++-
 5 files changed, 15 insertions(+), 6 deletions(-)
include/net/bluetooth/hci_core.h +2 -1
index 8752ac674db1..5701d15779dd 100644
@@ -704,7 +704,8 @@ void hci_chan_list_flush(struct hci_conn *conn);
 struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle);
 
 struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
-				u8 dst_type, u8 sec_level, u16 conn_timeout);
+				u8 dst_type, u8 sec_level, u16 conn_timeout,
+				bool master);
 struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
 				 u8 sec_level, u8 auth_type);
 struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
net/bluetooth/hci_conn.c +4 -2
index 9323044f01cd..16fd55da9c1d 100644
@@ -700,7 +700,8 @@ static void hci_req_directed_advertising(struct hci_request *req,
 }
 
 struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
-				u8 dst_type, u8 sec_level, u16 conn_timeout)
+				u8 dst_type, u8 sec_level, u16 conn_timeout,
+				bool master)
 {
 	struct hci_conn_params *params;
 	struct hci_conn *conn;
@@ -760,7 +761,8 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
 
 	hci_req_init(&req, hdev);
 
-	if (test_bit(HCI_ADVERTISING, &hdev->dev_flags)) {
+	/* If requested to connect as slave use directed advertising */
+	if (!master) {
 		hci_req_directed_advertising(&req, conn);
 		goto create_conn;
 	}
net/bluetooth/hci_event.c +2 -1
index ad39d9ad6fbc..a6816498b0b9 100644
@@ -4253,8 +4253,9 @@ static void check_pending_le_conn(struct hci_dev *hdev, bdaddr_t *addr,
 		return;
 
 connect:
+	/* Request connection in master = true role */
 	conn = hci_connect_le(hdev, addr, addr_type, BT_SECURITY_LOW,
-			      HCI_LE_AUTOCONN_TIMEOUT);
+			      HCI_LE_AUTOCONN_TIMEOUT, true);
 	if (!IS_ERR(conn))
 		return;
 
net/bluetooth/l2cap_core.c +5 -1
index 3daab4588522..bf379a379fa0 100644
@@ -7124,6 +7124,8 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
 	chan->dcid = cid;
 
 	if (bdaddr_type_is_le(dst_type)) {
+		bool master;
+
 		/* Convert from L2CAP channel address type to HCI address type
 		 */
 		if (dst_type == BDADDR_LE_PUBLIC)
@@ -7131,8 +7133,10 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
 		else
 			dst_type = ADDR_LE_DEV_RANDOM;
 
+		master = !test_bit(HCI_ADVERTISING, &hdev->dev_flags);
+
 		hcon = hci_connect_le(hdev, dst, dst_type, chan->sec_level,
-				      HCI_LE_CONN_TIMEOUT);
+				      HCI_LE_CONN_TIMEOUT, master);
 	} else {
 		u8 auth_type = l2cap_get_auth_type(chan);
 		hcon = hci_connect_acl(hdev, dst, chan->sec_level, auth_type);
net/bluetooth/mgmt.c +2 -1
index e7047de1ba11..b391e2fef4b6 100644
@@ -3117,8 +3117,9 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
 		 */
 		hci_conn_params_add(hdev, &cp->addr.bdaddr, addr_type);
 
+		/* Request a connection with master = true role */
 		conn = hci_connect_le(hdev, &cp->addr.bdaddr, addr_type,
-				      sec_level, HCI_LE_CONN_TIMEOUT);
+				      sec_level, HCI_LE_CONN_TIMEOUT, true);
 	}
 
 	if (IS_ERR(conn)) {
Signature · 1 line
1.9.3
maintainer
#2 lore raw

Re: [PATCH 2/2] Bluetooth: Pass desired connection role to hci_connect_le()

Hi Johan,

Quoted 8 lines

If we have both LE scanning and advertising simultaneously enabled we need a way to tell hci_connect_le() in which role to initiate a connection. This patch adds a new parameter to the function to give it the necessary information. For auto-connect and mgmt_pair_device we always use master role, whereas for L2CAP users (in practice sockets) we use slave role whenever HCI_ADVERTISING is set and master role otherwise.

Quoted 8 lines

---

include/net/bluetooth/hci_core.h | 3 ++-
net/bluetooth/hci_conn.c         | 6 ++++--
net/bluetooth/hci_event.c        | 3 ++-
net/bluetooth/l2cap_core.c       | 6 +++++-
net/bluetooth/mgmt.c             | 3 ++-
5 files changed, 15 insertions(+), 6 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel

maintainer
#3 lore raw
In reply to [email protected]

Hi Johan,

Quoted 6 lines

The auth_type value which gets assigned to hci_conn->auth_type is something that's only used for BR/EDR connections and is of no value for LE connections. It makes therefore little sense to pass it to the hci_connect_le() function. This patch removes the parameter from the function.

Quoted 8 lines

---

include/net/bluetooth/hci_core.h | 3 +--
net/bluetooth/hci_conn.c         | 5 +----
net/bluetooth/hci_event.c        | 2 +-
net/bluetooth/l2cap_core.c       | 6 ++----
net/bluetooth/mgmt.c             | 3 +--
5 files changed, 6 insertions(+), 13 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel