Commit aa64a8b5 authored by Johan Hedberg's avatar Johan Hedberg

Bluetooth: Add a convenience function to check for SSP enabled

It's a very common test to see if both the local and the remote device
have SSP enabled. By creating a simple function to test this we can
shorten many if-statements in the code.
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
Acked-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent 84bde9d6
...@@ -411,6 +411,13 @@ enum { ...@@ -411,6 +411,13 @@ enum {
HCI_CONN_REMOTE_OOB, HCI_CONN_REMOTE_OOB,
}; };
static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
{
struct hci_dev *hdev = conn->hdev;
return (test_bit(HCI_SSP_ENABLED, &hdev->flags) &&
test_bit(HCI_CONN_SSP_ENABLED, &conn->flags));
}
static inline void hci_conn_hash_init(struct hci_dev *hdev) static inline void hci_conn_hash_init(struct hci_dev *hdev)
{ {
struct hci_conn_hash *h = &hdev->conn_hash; struct hci_conn_hash *h = &hdev->conn_hash;
......
...@@ -608,9 +608,7 @@ int hci_conn_check_link_mode(struct hci_conn *conn) ...@@ -608,9 +608,7 @@ int hci_conn_check_link_mode(struct hci_conn *conn)
{ {
BT_DBG("conn %p", conn); BT_DBG("conn %p", conn);
if (test_bit(HCI_CONN_SSP_ENABLED, &conn->flags) && if (hci_conn_ssp_enabled(conn) && !(conn->link_mode & HCI_LM_ENCRYPT))
test_bit(HCI_SSP_ENABLED, &conn->hdev->dev_flags) &&
!(conn->link_mode & HCI_LM_ENCRYPT))
return 0; return 0;
return 1; return 1;
...@@ -672,9 +670,7 @@ int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type) ...@@ -672,9 +670,7 @@ int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type)
/* For non 2.1 devices and low security level we don't need the link /* For non 2.1 devices and low security level we don't need the link
key. */ key. */
if (sec_level == BT_SECURITY_LOW && if (sec_level == BT_SECURITY_LOW && !hci_conn_ssp_enabled(conn))
(!test_bit(HCI_CONN_SSP_ENABLED, &conn->flags) ||
!test_bit(HCI_SSP_ENABLED, &conn->hdev->dev_flags)))
return 1; return 1;
/* For other security levels we need the link key. */ /* For other security levels we need the link key. */
......
...@@ -1270,8 +1270,7 @@ static int hci_outgoing_auth_needed(struct hci_dev *hdev, ...@@ -1270,8 +1270,7 @@ static int hci_outgoing_auth_needed(struct hci_dev *hdev,
/* Only request authentication for SSP connections or non-SSP /* Only request authentication for SSP connections or non-SSP
* devices with sec_level HIGH or if MITM protection is requested */ * devices with sec_level HIGH or if MITM protection is requested */
if (!(test_bit(HCI_SSP_ENABLED, &hdev->dev_flags) && if (!hci_conn_ssp_enabled(conn) &&
test_bit(HCI_CONN_SSP_ENABLED, &conn->flags)) &&
conn->pending_sec_level != BT_SECURITY_HIGH && conn->pending_sec_level != BT_SECURITY_HIGH &&
!(conn->auth_type & 0x01)) !(conn->auth_type & 0x01))
return 0; return 0;
...@@ -1845,9 +1844,8 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *s ...@@ -1845,9 +1844,8 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *s
goto unlock; goto unlock;
if (!ev->status) { if (!ev->status) {
if (!(test_bit(HCI_CONN_SSP_ENABLED, &conn->flags) && if (!hci_conn_ssp_enabled(conn) &&
test_bit(HCI_SSP_ENABLED, &hdev->dev_flags)) && test_bit(HCI_CONN_REAUTH_PEND, &conn->flags)) {
test_bit(HCI_CONN_REAUTH_PEND, &conn->flags)) {
BT_INFO("re-auth of legacy device is not possible."); BT_INFO("re-auth of legacy device is not possible.");
} else { } else {
conn->link_mode |= HCI_LM_AUTH; conn->link_mode |= HCI_LM_AUTH;
...@@ -1861,9 +1859,7 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *s ...@@ -1861,9 +1859,7 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *s
clear_bit(HCI_CONN_REAUTH_PEND, &conn->flags); clear_bit(HCI_CONN_REAUTH_PEND, &conn->flags);
if (conn->state == BT_CONFIG) { if (conn->state == BT_CONFIG) {
if (!ev->status && if (!ev->status && hci_conn_ssp_enabled(conn)) {
test_bit(HCI_SSP_ENABLED, &hdev->dev_flags) &&
test_bit(HCI_CONN_SSP_ENABLED, &conn->flags)) {
struct hci_cp_set_conn_encrypt cp; struct hci_cp_set_conn_encrypt cp;
cp.handle = ev->handle; cp.handle = ev->handle;
cp.encrypt = 0x01; cp.encrypt = 0x01;
......
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