Skip to content

Commit 3ca44c1

Browse files
Vudentzholtmann
authored andcommitted
Bluetooth: Consolidate encryption handling in hci_encrypt_cfm
This makes hci_encrypt_cfm calls hci_connect_cfm in case the connection state is BT_CONFIG so callers don't have to check the state. Signed-off-by: Luiz Augusto von Dentz <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent a228f7a commit 3ca44c1

File tree

2 files changed

+21
-27
lines changed

2 files changed

+21
-27
lines changed

include/net/bluetooth/hci_core.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,10 +1381,26 @@ static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status)
13811381
conn->security_cfm_cb(conn, status);
13821382
}
13831383

1384-
static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status,
1385-
__u8 encrypt)
1384+
static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status)
13861385
{
13871386
struct hci_cb *cb;
1387+
__u8 encrypt;
1388+
1389+
if (conn->state == BT_CONFIG) {
1390+
if (status)
1391+
conn->state = BT_CONNECTED;
1392+
1393+
hci_connect_cfm(conn, status);
1394+
hci_conn_drop(conn);
1395+
return;
1396+
}
1397+
1398+
if (!test_bit(HCI_CONN_ENCRYPT, &conn->flags))
1399+
encrypt = 0x00;
1400+
else if (test_bit(HCI_CONN_AES_CCM, &conn->flags))
1401+
encrypt = 0x02;
1402+
else
1403+
encrypt = 0x01;
13881404

13891405
if (conn->sec_level == BT_SECURITY_SDP)
13901406
conn->sec_level = BT_SECURITY_LOW;

net/bluetooth/hci_event.c

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,7 +2931,7 @@ static void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
29312931
&cp);
29322932
} else {
29332933
clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags);
2934-
hci_encrypt_cfm(conn, ev->status, 0x00);
2934+
hci_encrypt_cfm(conn, ev->status);
29352935
}
29362936
}
29372937

@@ -3016,22 +3016,7 @@ static void read_enc_key_size_complete(struct hci_dev *hdev, u8 status,
30163016
conn->enc_key_size = rp->key_size;
30173017
}
30183018

3019-
if (conn->state == BT_CONFIG) {
3020-
conn->state = BT_CONNECTED;
3021-
hci_connect_cfm(conn, 0);
3022-
hci_conn_drop(conn);
3023-
} else {
3024-
u8 encrypt;
3025-
3026-
if (!test_bit(HCI_CONN_ENCRYPT, &conn->flags))
3027-
encrypt = 0x00;
3028-
else if (test_bit(HCI_CONN_AES_CCM, &conn->flags))
3029-
encrypt = 0x02;
3030-
else
3031-
encrypt = 0x01;
3032-
3033-
hci_encrypt_cfm(conn, 0, encrypt);
3034-
}
3019+
hci_encrypt_cfm(conn, 0);
30353020

30363021
unlock:
30373022
hci_dev_unlock(hdev);
@@ -3149,14 +3134,7 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
31493134
}
31503135

31513136
notify:
3152-
if (conn->state == BT_CONFIG) {
3153-
if (!ev->status)
3154-
conn->state = BT_CONNECTED;
3155-
3156-
hci_connect_cfm(conn, ev->status);
3157-
hci_conn_drop(conn);
3158-
} else
3159-
hci_encrypt_cfm(conn, ev->status, ev->encrypt);
3137+
hci_encrypt_cfm(conn, ev->status);
31603138

31613139
unlock:
31623140
hci_dev_unlock(hdev);

0 commit comments

Comments
 (0)