aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth
diff options
context:
space:
mode:
authorMikel Astiz <mikel.astiz@bmw-carit.de>2014-04-08 08:21:31 -0400
committerJohan Hedberg <johan.hedberg@intel.com>2014-04-11 13:33:08 -0400
commitb7f94c880839e85917369fe9097f861008b8c00e (patch)
tree53520768f1b797f121e56665aa4f39003e1b3fa1 /net/bluetooth
parent5c5b93e4be2fb52dca055e32e235453aa172500b (diff)
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: Mikel Astiz <mikel.astiz@bmw-carit.de> Signed-off-by: Timo Mueller <timo.mueller@bmw-carit.de> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Diffstat (limited to 'net/bluetooth')
-rw-r--r--net/bluetooth/hci_event.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 84acc4aabc5f..08016683e8aa 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -3419,24 +3419,25 @@ unlock:
3419 3419
3420static u8 hci_get_auth_req(struct hci_conn *conn) 3420static u8 hci_get_auth_req(struct hci_conn *conn)
3421{ 3421{
3422 /* If remote requests dedicated bonding follow that lead */
3423 if (conn->remote_auth == HCI_AT_DEDICATED_BONDING ||
3424 conn->remote_auth == HCI_AT_DEDICATED_BONDING_MITM) {
3425 /* If both remote and local IO capabilities allow MITM
3426 * protection then require it, otherwise don't */
3427 if (conn->remote_cap == HCI_IO_NO_INPUT_OUTPUT ||
3428 conn->io_capability == HCI_IO_NO_INPUT_OUTPUT)
3429 return HCI_AT_DEDICATED_BONDING;
3430 else
3431 return HCI_AT_DEDICATED_BONDING_MITM;
3432 }
3433
3434 /* If remote requests no-bonding follow that lead */ 3422 /* If remote requests no-bonding follow that lead */
3435 if (conn->remote_auth == HCI_AT_NO_BONDING || 3423 if (conn->remote_auth == HCI_AT_NO_BONDING ||
3436 conn->remote_auth == HCI_AT_NO_BONDING_MITM) 3424 conn->remote_auth == HCI_AT_NO_BONDING_MITM)
3437 return conn->remote_auth | (conn->auth_type & 0x01); 3425 return conn->remote_auth | (conn->auth_type & 0x01);
3438 3426
3439 return conn->auth_type; 3427 /* For general bonding, use the given auth_type */
3428 if (conn->remote_auth == HCI_AT_GENERAL_BONDING ||
3429 conn->remote_auth == HCI_AT_GENERAL_BONDING_MITM)
3430 return conn->auth_type;
3431
3432 /* If both remote and local have enough IO capabilities, require
3433 * MITM protection
3434 */
3435 if (conn->remote_cap != HCI_IO_NO_INPUT_OUTPUT &&
3436 conn->io_capability != HCI_IO_NO_INPUT_OUTPUT)
3437 return conn->remote_auth | 0x01;
3438
3439 /* No MITM protection possible so remove requirement */
3440 return conn->remote_auth & ~0x01;
3440} 3441}
3441 3442
3442static void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb) 3443static 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 * to DisplayYesNo as it is not supported by BT spec. */ 3467 * to DisplayYesNo as it is not supported by BT spec. */
3467 cp.capability = (conn->io_capability == 0x04) ? 3468 cp.capability = (conn->io_capability == 0x04) ?
3468 HCI_IO_DISPLAY_YESNO : conn->io_capability; 3469 HCI_IO_DISPLAY_YESNO : conn->io_capability;
3469 conn->auth_type = hci_get_auth_req(conn); 3470
3470 cp.authentication = conn->auth_type; 3471 /* If we are initiators, there is no remote information yet */
3472 if (conn->remote_auth == 0xff) {
3473 cp.authentication = conn->auth_type;
3474 } else {
3475 conn->auth_type = hci_get_auth_req(conn);
3476 cp.authentication = conn->auth_type;
3477 }
3471 3478
3472 if (hci_find_remote_oob_data(hdev, &conn->dst) && 3479 if (hci_find_remote_oob_data(hdev, &conn->dst) &&
3473 (conn->out || test_bit(HCI_CONN_REMOTE_OOB, &conn->flags))) 3480 (conn->out || test_bit(HCI_CONN_REMOTE_OOB, &conn->flags)))