Commit ccd556fe authored by Johan Hedberg's avatar Johan Hedberg Committed by Gustavo F. Padovan

Bluetooth: Simplify remote features callback function logic

The current remote and remote extended features event callbacks logic
can be made simpler by using a label and goto statements instead of the
current multiple levels of nested if statements.
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@nokia.com>
Signed-off-by: default avatarGustavo F. Padovan <padovan@profusion.mobi>
parent 17f490bc
...@@ -1162,33 +1162,33 @@ static inline void hci_remote_features_evt(struct hci_dev *hdev, struct sk_buff ...@@ -1162,33 +1162,33 @@ static inline void hci_remote_features_evt(struct hci_dev *hdev, struct sk_buff
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;
memcpy(conn->features, ev->features, 8);
if (conn->state == BT_CONFIG) { if (!ev->status)
if (!ev->status && lmp_ssp_capable(hdev) && memcpy(conn->features, ev->features, 8);
lmp_ssp_capable(conn)) {
struct hci_cp_read_remote_ext_features cp; if (conn->state != BT_CONFIG)
cp.handle = ev->handle; goto unlock;
cp.page = 0x01;
hci_send_cmd(hdev, if (!ev->status && lmp_ssp_capable(hdev) && lmp_ssp_capable(conn)) {
HCI_OP_READ_REMOTE_EXT_FEATURES, struct hci_cp_read_remote_ext_features cp;
sizeof(cp), &cp); cp.handle = ev->handle;
} else if (!ev->status && conn->out && cp.page = 0x01;
conn->sec_level == BT_SECURITY_HIGH) { hci_send_cmd(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES,
struct hci_cp_auth_requested cp;
cp.handle = ev->handle;
hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED,
sizeof(cp), &cp); sizeof(cp), &cp);
} else { } else if (!ev->status && conn->out &&
conn->state = BT_CONNECTED; conn->sec_level == BT_SECURITY_HIGH) {
hci_proto_connect_cfm(conn, ev->status); struct hci_cp_auth_requested cp;
hci_conn_put(conn); cp.handle = ev->handle;
} hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp);
} } else {
conn->state = BT_CONNECTED;
hci_proto_connect_cfm(conn, ev->status);
hci_conn_put(conn);
} }
unlock:
hci_dev_unlock(hdev); hci_dev_unlock(hdev);
} }
...@@ -1646,32 +1646,35 @@ static inline void hci_remote_ext_features_evt(struct hci_dev *hdev, struct sk_b ...@@ -1646,32 +1646,35 @@ static inline void hci_remote_ext_features_evt(struct hci_dev *hdev, struct sk_b
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 && ev->page == 0x01) { goto unlock;
struct inquiry_entry *ie;
if ((ie = hci_inquiry_cache_lookup(hdev, &conn->dst))) if (!ev->status && ev->page == 0x01) {
ie->data.ssp_mode = (ev->features[0] & 0x01); struct inquiry_entry *ie;
conn->ssp_mode = (ev->features[0] & 0x01); if ((ie = hci_inquiry_cache_lookup(hdev, &conn->dst)))
} ie->data.ssp_mode = (ev->features[0] & 0x01);
if (conn->state == BT_CONFIG) { conn->ssp_mode = (ev->features[0] & 0x01);
if (!ev->status && hdev->ssp_mode > 0 && }
conn->ssp_mode > 0 && conn->out &&
conn->sec_level != BT_SECURITY_SDP) { if (conn->state != BT_CONFIG)
struct hci_cp_auth_requested cp; goto unlock;
cp.handle = ev->handle;
hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, if (!ev->status && hdev->ssp_mode > 0 &&
sizeof(cp), &cp); conn->ssp_mode > 0 && conn->out &&
} else { conn->sec_level != BT_SECURITY_SDP) {
conn->state = BT_CONNECTED; struct hci_cp_auth_requested cp;
hci_proto_connect_cfm(conn, ev->status); cp.handle = ev->handle;
hci_conn_put(conn); hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED,
} sizeof(cp), &cp);
} } else {
conn->state = BT_CONNECTED;
hci_proto_connect_cfm(conn, ev->status);
hci_conn_put(conn);
} }
unlock:
hci_dev_unlock(hdev); hci_dev_unlock(hdev);
} }
......
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