[PATCH] Bluetooth: Override status if local user rejects pairing

Subsystems: bluetooth subsystem, the rest

STALE5154d

3 messages, 2 authors, 2012-07-05 · open the first message on its own page

[PATCH] Bluetooth: Override status if local user rejects pairing

From: Jaganath Kanakkassery <hidden>
Date: 2012-07-05 12:11:25

In case if ssp is failed, user cannot differentiate from the status
whether failure is caused by local rejection or remote rejection
because authentication failure is coming in both the cases.

This patch overrides the status from controller with "pin or key missing"
in case of local rejection. In legacy pairing already contoller gives
this error.

This patch will be useful if user can take some action based on local
or remote rejection

Signed-off-by: Jaganath Kanakkassery <redacted>
---
 include/net/bluetooth/hci_core.h |    4 +++-
 net/bluetooth/hci_event.c        |    4 ++--
 net/bluetooth/mgmt.c             |   13 +++++++++++--
 net/bluetooth/smp.c              |    2 +-
 4 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 475b8c0..bbb295f 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -312,6 +312,8 @@ struct hci_conn {
 	__u16		disc_timeout;
 	unsigned long	flags;
 
+	bool		auth_rejected;
+
 	__u8		remote_cap;
 	__u8		remote_auth;
 	bool		flush_key;
@@ -1036,7 +1038,7 @@ int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
 int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
 					 u8 link_type, u8 addr_type, u8 status);
 int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
-		     u8 addr_type, u8 status);
+		     u8 addr_type, u8 status, bool auth_rejected);
 int mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status);
 int mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status);
 int mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class,
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 1ba929c..d5b4655 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1948,7 +1948,7 @@ static void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
 		}
 	} else {
 		mgmt_auth_failed(hdev, &conn->dst, conn->type, conn->dst_type,
-				 ev->status);
+				 ev->status, conn->auth_rejected);
 	}
 
 	clear_bit(HCI_CONN_AUTH_PEND, &conn->flags);
@@ -3281,7 +3281,7 @@ static void hci_simple_pair_complete_evt(struct hci_dev *hdev,
 	 * the mgmt_auth_failed event */
 	if (!test_bit(HCI_CONN_AUTH_PEND, &conn->flags) && ev->status != 0)
 		mgmt_auth_failed(hdev, &conn->dst, conn->type, conn->dst_type,
-				 ev->status);
+				 ev->status, conn->auth_rejected);
 
 	hci_conn_put(conn);
 
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index e83368f..cd7fb2b 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -2045,6 +2045,10 @@ static int user_pairing_resp(struct sock *sk, struct hci_dev *hdev,
 		goto done;
 	}
 
+	if (hci_op == HCI_OP_USER_CONFIRM_NEG_REPLY ||
+				hci_op == HCI_OP_USER_PASSKEY_NEG_REPLY)
+		conn->auth_rejected = true;
+
 	if (type == BDADDR_LE_PUBLIC || type == BDADDR_LE_RANDOM) {
 		/* Continue with pairing via SMP */
 		err = smp_user_confirm_reply(conn, mgmt_op, passkey);
@@ -3271,13 +3275,18 @@ int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
 }
 
 int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
-		     u8 addr_type, u8 status)
+		     u8 addr_type, u8 status, bool auth_rejected)
 {
 	struct mgmt_ev_auth_failed ev;
 
 	bacpy(&ev.addr.bdaddr, bdaddr);
 	ev.addr.type = link_to_bdaddr(link_type, addr_type);
-	ev.status = mgmt_status(status);
+
+	/* Override status if local device rejected pairing */
+	if (auth_rejected == true)
+		ev.status = MGMT_STATUS_NOT_PAIRED;
+	else
+		ev.status = mgmt_status(status);
 
 	return mgmt_event(MGMT_EV_AUTH_FAILED, hdev, &ev, sizeof(ev), NULL);
 }
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 16ef0dc..3c04313 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -265,7 +265,7 @@ static void smp_failure(struct l2cap_conn *conn, u8 reason, u8 send)
 
 	clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->hcon->flags);
 	mgmt_auth_failed(conn->hcon->hdev, conn->dst, hcon->type,
-			 hcon->dst_type, reason);
+			 hcon->dst_type, reason, hcon->auth_rejected);
 
 	if (test_and_clear_bit(HCI_CONN_LE_SMP_PEND, &conn->hcon->flags)) {
 		cancel_delayed_work_sync(&conn->security_timer);
-- 
1.7.1

Re: [PATCH] Bluetooth: Override status if local user rejects pairing

From: Johan Hedberg <hidden>
Date: 2012-07-05 12:37:31

Hi Jaganath,

On Thu, Jul 05, 2012, Jaganath Kanakkassery wrote:
In case if ssp is failed, user cannot differentiate from the status
whether failure is caused by local rejection or remote rejection
because authentication failure is coming in both the cases.

This patch overrides the status from controller with "pin or key missing"
in case of local rejection. In legacy pairing already contoller gives
this error.

This patch will be useful if user can take some action based on local
or remote rejection

Signed-off-by: Jaganath Kanakkassery <redacted>
---
--snip--
+	/* Override status if local device rejected pairing */
+	if (auth_rejected == true)
+		ev.status = MGMT_STATUS_NOT_PAIRED;
+	else
+		ev.status = mgmt_status(status);
You're not returning "pin or key missing" (which sounds like an HCI
error) but MGMT_STATUS_NOT_PAIRED. Please be honest about this in your
commit message. However, I don't think this is a very intuitive error
code for a local rejection. Could you just use MGMT_STATUS_REJECTED for
it? I think you'll get "pin or key missing" also if the remote side
rejects so I don't think that's a good HCI error to derive the needed
mgmt error from.

Johan

Re: [PATCH] Bluetooth: Override status if local user rejects pairing

From: Jaganath <hidden>
Date: 2012-07-05 13:13:34

Hi Johan,

--------------------------------------------------
From: "Johan Hedberg" <redacted>
Sent: Thursday, July 05, 2012 6:07 PM
To: "Jaganath Kanakkassery" <redacted>
Cc: <redacted>
Subject: Re: [PATCH] Bluetooth: Override status if local user rejects 
pairing
Hi Jaganath,

On Thu, Jul 05, 2012, Jaganath Kanakkassery wrote:
quoted
In case if ssp is failed, user cannot differentiate from the status
whether failure is caused by local rejection or remote rejection
because authentication failure is coming in both the cases.

This patch overrides the status from controller with "pin or key missing"
in case of local rejection. In legacy pairing already contoller gives
this error.

This patch will be useful if user can take some action based on local
or remote rejection

Signed-off-by: Jaganath Kanakkassery <redacted>
---
--snip--
quoted
+ /* Override status if local device rejected pairing */
+ if (auth_rejected == true)
+ ev.status = MGMT_STATUS_NOT_PAIRED;
+ else
+ ev.status = mgmt_status(status);
You're not returning "pin or key missing" (which sounds like an HCI
error) but MGMT_STATUS_NOT_PAIRED. Please be honest about this in your
In mgmt_status_table MGMT_STATUS_NOT_PAIRED is defined as
"pin or key missing" which is an hci error code.  That is why I used that.
In legacy pairing local rejection we are getting this error where as if
remote rejected "pairing not allowed" is coming. So I thought of
reusing this error.
commit message. However, I don't think this is a very intuitive error
code for a local rejection. Could you just use MGMT_STATUS_REJECTED for
it? I think you'll get "pin or key missing" also if the remote side
rejects so I don't think that's a good HCI error to derive the needed
mgmt error from.
Sounds good to me to not use existing error since it will be dependent on 
the
controller.  I will do it and raise patch

Thanks
Jaganath 
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help