Commit b7f94c88 authored by Mikel Astiz's avatar Mikel Astiz Committed by Johan Hedberg

Bluetooth: Refactor hci_get_auth_req()

Refactor the code without changing its behavior by handling the
no-bonding cases first followed by General Bonding.
Signed-off-by: default avatarMikel Astiz <mikel.astiz@bmw-carit.de>
Signed-off-by: default avatarTimo Mueller <timo.mueller@bmw-carit.de>
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
parent 5c5b93e4
...@@ -3419,24 +3419,25 @@ static void hci_key_refresh_complete_evt(struct hci_dev *hdev, ...@@ -3419,24 +3419,25 @@ static void hci_key_refresh_complete_evt(struct hci_dev *hdev,
static u8 hci_get_auth_req(struct hci_conn *conn) static u8 hci_get_auth_req(struct hci_conn *conn)
{ {
/* If remote requests dedicated bonding follow that lead */
if (conn->remote_auth == HCI_AT_DEDICATED_BONDING ||
conn->remote_auth == HCI_AT_DEDICATED_BONDING_MITM) {
/* If both remote and local IO capabilities allow MITM
* protection then require it, otherwise don't */
if (conn->remote_cap == HCI_IO_NO_INPUT_OUTPUT ||
conn->io_capability == HCI_IO_NO_INPUT_OUTPUT)
return HCI_AT_DEDICATED_BONDING;
else
return HCI_AT_DEDICATED_BONDING_MITM;
}
/* If remote requests no-bonding follow that lead */ /* If remote requests no-bonding follow that lead */
if (conn->remote_auth == HCI_AT_NO_BONDING || if (conn->remote_auth == HCI_AT_NO_BONDING ||
conn->remote_auth == HCI_AT_NO_BONDING_MITM) conn->remote_auth == HCI_AT_NO_BONDING_MITM)
return conn->remote_auth | (conn->auth_type & 0x01); return conn->remote_auth | (conn->auth_type & 0x01);
/* For general bonding, use the given auth_type */
if (conn->remote_auth == HCI_AT_GENERAL_BONDING ||
conn->remote_auth == HCI_AT_GENERAL_BONDING_MITM)
return conn->auth_type; return conn->auth_type;
/* If both remote and local have enough IO capabilities, require
* MITM protection
*/
if (conn->remote_cap != HCI_IO_NO_INPUT_OUTPUT &&
conn->io_capability != HCI_IO_NO_INPUT_OUTPUT)
return conn->remote_auth | 0x01;
/* No MITM protection possible so remove requirement */
return conn->remote_auth & ~0x01;
} }
static void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb) static void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
...@@ -3466,8 +3467,14 @@ static void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -3466,8 +3467,14 @@ static void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
* to DisplayYesNo as it is not supported by BT spec. */ * to DisplayYesNo as it is not supported by BT spec. */
cp.capability = (conn->io_capability == 0x04) ? cp.capability = (conn->io_capability == 0x04) ?
HCI_IO_DISPLAY_YESNO : conn->io_capability; HCI_IO_DISPLAY_YESNO : conn->io_capability;
/* If we are initiators, there is no remote information yet */
if (conn->remote_auth == 0xff) {
cp.authentication = conn->auth_type;
} else {
conn->auth_type = hci_get_auth_req(conn); conn->auth_type = hci_get_auth_req(conn);
cp.authentication = conn->auth_type; cp.authentication = conn->auth_type;
}
if (hci_find_remote_oob_data(hdev, &conn->dst) && if (hci_find_remote_oob_data(hdev, &conn->dst) &&
(conn->out || test_bit(HCI_CONN_REMOTE_OOB, &conn->flags))) (conn->out || test_bit(HCI_CONN_REMOTE_OOB, &conn->flags)))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment