提交 d7556e20 编写于 作者: W Waldemar Rymarkiewicz 提交者: Gustavo F. Padovan

Bluetooth: Refactor hci_auth_complete_evt function

Replace if(conn) with if(!conn) checking to avoid too many nested statements
Signed-off-by: NWaldemar Rymarkiewicz <waldemar.rymarkiewicz@tieto.com>
Signed-off-by: NGustavo F. Padovan <padovan@profusion.mobi>
上级 19f8def0
...@@ -1487,59 +1487,58 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *s ...@@ -1487,59 +1487,58 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *s
hci_dev_lock(hdev); hci_dev_lock(hdev);
conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
if (conn) { if (!conn)
if (!ev->status) { goto unlock;
if (!(conn->ssp_mode > 0 && hdev->ssp_mode > 0) &&
test_bit(HCI_CONN_REAUTH_PEND, if (!ev->status) {
&conn->pend)) { if (!(conn->ssp_mode > 0 && hdev->ssp_mode > 0) &&
BT_INFO("re-auth of legacy device is not" test_bit(HCI_CONN_REAUTH_PEND, &conn->pend)) {
"possible."); BT_INFO("re-auth of legacy device is not possible.");
} else {
conn->link_mode |= HCI_LM_AUTH;
conn->sec_level = conn->pending_sec_level;
}
} else { } else {
mgmt_auth_failed(hdev->id, &conn->dst, ev->status); conn->link_mode |= HCI_LM_AUTH;
conn->sec_level = conn->pending_sec_level;
} }
} else {
mgmt_auth_failed(hdev->id, &conn->dst, ev->status);
}
clear_bit(HCI_CONN_AUTH_PEND, &conn->pend); clear_bit(HCI_CONN_AUTH_PEND, &conn->pend);
clear_bit(HCI_CONN_REAUTH_PEND, &conn->pend); clear_bit(HCI_CONN_REAUTH_PEND, &conn->pend);
if (conn->state == BT_CONFIG) { if (conn->state == BT_CONFIG) {
if (!ev->status && hdev->ssp_mode > 0 && if (!ev->status && hdev->ssp_mode > 0 && conn->ssp_mode > 0) {
conn->ssp_mode > 0) { 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; hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp),
hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, &cp);
sizeof(cp), &cp);
} else {
conn->state = BT_CONNECTED;
hci_proto_connect_cfm(conn, ev->status);
hci_conn_put(conn);
}
} else { } else {
hci_auth_cfm(conn, ev->status); conn->state = BT_CONNECTED;
hci_proto_connect_cfm(conn, ev->status);
hci_conn_hold(conn);
conn->disc_timeout = HCI_DISCONN_TIMEOUT;
hci_conn_put(conn); hci_conn_put(conn);
} }
} else {
hci_auth_cfm(conn, ev->status);
if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend)) { hci_conn_hold(conn);
if (!ev->status) { conn->disc_timeout = HCI_DISCONN_TIMEOUT;
struct hci_cp_set_conn_encrypt cp; hci_conn_put(conn);
cp.handle = ev->handle; }
cp.encrypt = 0x01;
hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend)) {
sizeof(cp), &cp); if (!ev->status) {
} else { struct hci_cp_set_conn_encrypt cp;
clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend); cp.handle = ev->handle;
hci_encrypt_cfm(conn, ev->status, 0x00); cp.encrypt = 0x01;
} hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp),
&cp);
} else {
clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend);
hci_encrypt_cfm(conn, ev->status, 0x00);
} }
} }
unlock:
hci_dev_unlock(hdev); hci_dev_unlock(hdev);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册