Bluetooth: Fail gracefully if device doesn't support pairing
Subsystems (2)
v2 cover Bluetooth: Fail gracefully if device doesn't support pairing
This has grown from the original RFC patch [1] after Marcel pointed out that mgmt_auth_failed() should be taking a MGMT_STATUS_ value instead of an HCI error code.
The aim of the series is to allow us to fail gracefully when we detect a device does not support pairing. Since it is impossible to tell whether a device supports pairing or not without attempting to pair with it, we must handle the "pairing not support" error specially and avoid dropping the connection in this case.
Converting the other mgmt function that take a status code to map from HCI to MGMT_STATUS_ in the caller is left for a future series.
A corresponding bluetoothd change is needed to allow clients to detect that pairing has failed because it is not supported by the device; I will send a patch for this once the kernel change is accepted. Existing versions of bluetoothd will return a generic "Authentication Failed" error as they do now.
[1] https://www.spinics.net/lists/linux-bluetooth/msg70600.html
John Keeping (3):
Bluetooth: make mgmt_status() public
Bluetooth: pass MGMT_STATUS_* into mgmt_auth_failed()
Bluetooth: SMP: Fail gracefully if device doesn't support pairing
include/net/bluetooth/hci_core.h | 4 +++- net/bluetooth/hci_event.c | 4 ++-- net/bluetooth/mgmt.c | 9 ++++----- net/bluetooth/smp.c | 23 ++++++++++++++++++++--- 4 files changed, 29 insertions(+), 11 deletions(-)
Signature · 1 line
2.12.2.648.g6730d8bc62.dirty
PATCH v2 1/3 Bluetooth: make mgmt_status() public
This function maps from HCI status codes to MGMT_STATUS_ values. We want to change the management function interface to take a MGMT_STATUS_ value rather than an HCI status so as to provide greater flexibility for errors that do not result from HCI commands, which will involve moving this mapping from mgmt.c into the callers.
--- include/net/bluetooth/hci_core.h | 2 ++ net/bluetooth/mgmt.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
include/net/bluetooth/hci_core.h +2 -0
@@ -1457,6 +1457,8 @@ void hci_mgmt_chan_unregister(struct hci_mgmt_chan *c);#define DISCOV_BREDR_INQUIRY_LEN 0x08#define DISCOV_LE_RESTART_DELAY msecs_to_jiffies(200)/* msec */ +u8 mgmt_status (u8 hci_status); +void mgmt_fill_version_info (void *ver);int mgmt_new_settings (struct hci_dev *hdev);void mgmt_index_added (struct hci_dev *hdev);
net/bluetooth/mgmt.c +1 -1
@@ -239,7 +239,7 @@ static u8 mgmt_status_table[] = { MGMT_STATUS_CONNECT_FAILED, /* MAC Connection Failed */ }; -static u8 mgmt_status (u8 hci_status) +u8 mgmt_status (u8 hci_status) {if (hci_status <ARRAY_SIZE (mgmt_status_table))return mgmt_status_table[hci_status];
Signature · 1 line
2.12.2.648.g6730d8bc62.dirty
PATCH v2 2/3 Bluetooth: pass MGMT_STATUS_* into mgmt_auth_failed()
In reply to John KeepingMove the mapping from HCI status to MGMT_STATUS_ into the caller. The next patch will handle a case for which no suitable HCI status exists.
--- include/net/bluetooth/hci_core.h | 2 +- net/bluetooth/hci_event.c | 4 ++-- net/bluetooth/mgmt.c | 7 +++---- net/bluetooth/smp.c | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-)
include/net/bluetooth/hci_core.h +1 -1
@@ -1498,7 +1498,7 @@ int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,int mgmt_user_passkey_notify (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type,u8 addr_type,u32 passkey,u8 entered); -void mgmt_auth_failed (struct hci_conn *conn,u8 status); +void mgmt_auth_failed (struct hci_conn *conn,u8 mgmt_status);void mgmt_auth_enable_complete (struct hci_dev *hdev,u8 status);void mgmt_ssp_enable_complete (struct hci_dev *hdev,u8 enable,u8 status); void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class,
net/bluetooth/hci_event.c +2 -2
@@ -2440,7 +2440,7 @@ static void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)if (ev->status ==HCI_ERROR_PIN_OR_KEY_MISSING )set_bit (HCI_CONN_AUTH_FAILURE , &conn->flags); -mgmt_auth_failed (conn, ev->status); +mgmt_auth_failed (conn,mgmt_status (ev->status)); }clear_bit (HCI_CONN_AUTH_PEND , &conn->flags);
@@ -4232,7 +4232,7 @@ static void hci_simple_pair_complete_evt(struct hci_dev *hdev,* event gets always produced as initiator and is also mapped to * the mgmt_auth_failed event */ if (!test_bit (HCI_CONN_AUTH_PEND , &conn->flags) && ev->status) -mgmt_auth_failed (conn, ev->status); +mgmt_auth_failed (conn,mgmt_status (ev->status));hci_conn_drop (conn);
net/bluetooth/mgmt.c +3 -4
@@ -7142,15 +7142,14 @@ int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr,return mgmt_event (MGMT_EV_PASSKEY_NOTIFY , hdev, &ev,sizeof (ev),NULL ); } -void mgmt_auth_failed (struct hci_conn *conn,u8 hci_status) +void mgmt_auth_failed (struct hci_conn *conn,u8 mgmt_status) {struct mgmt_ev_auth_failed ev;struct mgmt_pending_cmd *cmd; -u8 status =mgmt_status (hci_status);bacpy (&ev.addr.bdaddr, &conn->dst); ev.addr.type =link_to_bdaddr (conn->type, conn->dst_type); - ev.status = status; + ev.status = mgmt_status; cmd =find_pairing (conn);
@@ -7158,7 +7157,7 @@ void mgmt_auth_failed(struct hci_conn *conn, u8 hci_status) cmd ? cmd->sk : NULL);if (cmd) { - cmd->cmd_complete (cmd, status); + cmd->cmd_complete (cmd, mgmt_status);mgmt_pending_remove (cmd); } }
net/bluetooth/smp.c +1 -1
@@ -813,7 +813,7 @@ static void smp_failure(struct l2cap_conn *conn, u8 reason)smp_send_cmd (conn,SMP_CMD_PAIRING_FAIL ,sizeof (reason), &reason); -mgmt_auth_failed (hcon,HCI_ERROR_AUTH_FAILURE ); +mgmt_auth_failed (hcon,MGMT_STATUS_AUTH_FAILED );if (chan->data)smp_chan_destroy (conn);
Signature · 1 line
2.12.2.648.g6730d8bc62.dirty
PATCH v2 3/3 Bluetooth: SMP: Fail gracefully if device doesn't support pairing
In reply to John KeepingIf a device does not support pairing, we have no way of knowing this except by trying and seeing if it returns a "pairing not supported" error.
Handle this response specially so that we don't drop the connection when an attempt at pairing fails because the device doesn't support pairing. Also pass a specific failure value back to userspace to allow detection of this case as distinct from an authentication failure during pairing.
--- net/bluetooth/smp.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
net/bluetooth/smp.c +20 -3
@@ -813,7 +813,10 @@ static void smp_failure(struct l2cap_conn *conn, u8 reason)smp_send_cmd (conn,SMP_CMD_PAIRING_FAIL ,sizeof (reason), &reason); -mgmt_auth_failed (hcon,MGMT_STATUS_AUTH_FAILED ); +if (reason ==SMP_PAIRING_NOTSUPP ) +mgmt_auth_failed (hcon,MGMT_STATUS_NOT_SUPPORTED ); +else +mgmt_auth_failed (hcon,MGMT_STATUS_AUTH_FAILED );if (chan->data)smp_chan_destroy (conn);
@@ -1866,6 +1869,17 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb)return 0 ; } +static u8 smp_cmd_pairing_fail (struct l2cap_conn *conn,struct sk_buff *skb) +{ +struct smp_cmd_pairing_fail *rsp = (void *) skb->data; + +if (skb->len <sizeof (*rsp)) +return SMP_INVALID_PARAMS ; + +skb_pull (skb,sizeof (*rsp)); +return rsp->reason; +} +static u8 sc_send_public_key (struct smp_chan *smp) {struct hci_dev *hdev = smp->conn->hcon->hdev;
@@ -2864,8 +2878,11 @@ static int smp_sig_channel(struct l2cap_chan *chan, struct sk_buff *skb)break ;case SMP_CMD_PAIRING_FAIL : -smp_failure (conn,0 ); - err = -EPERM ; + reason =smp_cmd_pairing_fail (conn, skb); +if (reason !=SMP_PAIRING_NOTSUPP ) { +smp_failure (conn,0 ); + err = -EPERM ; + }break ;case SMP_CMD_PAIRING_RSP :
Signature · 1 line
2.12.2.648.g6730d8bc62.dirty