2015-02-11 11:31:40

by Lukasz Rymanowski

[permalink] [raw]
Subject: [PATCH v2 1/3] Bluetooth: Do not allow LE connection if LE is not enabled

Kernel gives possibility to enable/disable LE host support.
There is flag HCI_LE_ENABLED which is set when this support is enabled
and some parts of the code checks this flag e.g. SMP
However it is still possible to make LE connection if LE Host support is
disabled, what might be confused for remote device.
This patch makes sure that kernel will not send HCI LE Create Connection
if LE HOST support is not enabled.

Signed-off-by: Lukasz Rymanowski <[email protected]>
---
net/bluetooth/hci_conn.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index c9b8fa5..409c05e 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -733,6 +733,14 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
struct hci_request req;
int err;

+ /* Let's make sure that le is enabled.*/
+ if (!test_bit(HCI_LE_ENABLED, &hdev->dev_flags)) {
+ if (lmp_le_capable(hdev))
+ return ERR_PTR(-ECONNREFUSED);
+
+ return ERR_PTR(-EOPNOTSUPP);
+ }
+
/* Some devices send ATT messages as soon as the physical link is
* established. To be able to handle these ATT messages, the user-
* space first establishes the connection and then starts the pairing
--
1.8.4



2015-02-12 21:03:25

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] Bluetooth: Do not allow LE connection if LE is not enabled

Hi Lukasz,

On Wed, Feb 11, 2015, Lukasz Rymanowski wrote:
> Kernel gives possibility to enable/disable LE host support.
> There is flag HCI_LE_ENABLED which is set when this support is enabled
> and some parts of the code checks this flag e.g. SMP
> However it is still possible to make LE connection if LE Host support is
> disabled, what might be confused for remote device.
> This patch makes sure that kernel will not send HCI LE Create Connection
> if LE HOST support is not enabled.
>
> Signed-off-by: Lukasz Rymanowski <[email protected]>
> ---
> net/bluetooth/hci_conn.c | 8 ++++++++
> 1 file changed, 8 insertions(+)

All three patches in this set have been applied to bluetooth-next.
Thanks.

Johan

2015-02-11 11:31:42

by Lukasz Rymanowski

[permalink] [raw]
Subject: [PATCH v2 3/3] Bluetooth: Enhance error codes pair device command

If user space is trying to pair on not enabled transport
MGMT_STATUS_REJECT will be returned.

If user space is trying to pair on transport which controller does not
support, MGMT_STATUS_NOT_SUPPORTED will be returned.

Having separate error code for that scenario might be useful for
debugging at least.

Signed-off-by: Lukasz Rymanowski <[email protected]>
---
net/bluetooth/mgmt.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 9ec5390..1b528de 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -3249,6 +3249,10 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,

if (PTR_ERR(conn) == -EBUSY)
status = MGMT_STATUS_BUSY;
+ else if (PTR_ERR(conn) == -EOPNOTSUPP)
+ status = MGMT_STATUS_NOT_SUPPORTED;
+ else if (PTR_ERR(conn) == -ECONNREFUSED)
+ status = MGMT_STATUS_REJECTED;
else
status = MGMT_STATUS_CONNECT_FAILED;

--
1.8.4


2015-02-11 11:31:41

by Lukasz Rymanowski

[permalink] [raw]
Subject: [PATCH v2 2/3] Bluetooth: Improve error handling in connect acl

With this patch -EOPNOTSUPP will be returned by hci_connect_acl for LE
only controllers. If it is dual device with disabled BREDR -ECONNREFUSED
will be returned

Signed-off-by: Lukasz Rymanowski <[email protected]>
---
net/bluetooth/hci_conn.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 409c05e..e3263b6 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -864,8 +864,12 @@ struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
{
struct hci_conn *acl;

- if (!test_bit(HCI_BREDR_ENABLED, &hdev->dev_flags))
+ if (!test_bit(HCI_BREDR_ENABLED, &hdev->dev_flags)) {
+ if (lmp_bredr_capable(hdev))
+ return ERR_PTR(-ECONNREFUSED);
+
return ERR_PTR(-EOPNOTSUPP);
+ }

acl = hci_conn_hash_lookup_ba(hdev, ACL_LINK, dst);
if (!acl) {
--
1.8.4