aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/hci_conn.c
diff options
context:
space:
mode:
authorAndre Guedes <andre.guedes@openbossa.org>2013-10-08 07:21:18 -0400
committerMarcel Holtmann <marcel@holtmann.org>2013-10-10 04:30:18 -0400
commit620ad5219c0f0aa43731b2fd8fd9efac78c10deb (patch)
tree94effbfda02b0322f6c9655f698b3dd92571005f /net/bluetooth/hci_conn.c
parent1d399ae5c74619c841fa13834c4f79506aaf6957 (diff)
Bluetooth: Refactor hci_connect_le
This patch does some code refactoring in hci_connect_le() by moving the exception code into if statements and letting the main flow in first level of function scope. It also adds extra comments to improve the code readability. Signed-off-by: Andre Guedes <andre.guedes@openbossa.org> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/bluetooth/hci_conn.c')
-rw-r--r--net/bluetooth/hci_conn.c51
1 files changed, 33 insertions, 18 deletions
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 1800b50558e4..dedd1ea5dd4c 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -594,32 +594,47 @@ static struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
594 if (test_bit(HCI_ADVERTISING, &hdev->flags)) 594 if (test_bit(HCI_ADVERTISING, &hdev->flags))
595 return ERR_PTR(-ENOTSUPP); 595 return ERR_PTR(-ENOTSUPP);
596 596
597 /* Some devices send ATT messages as soon as the physical link is
598 * established. To be able to handle these ATT messages, the user-
599 * space first establishes the connection and then starts the pairing
600 * process.
601 *
602 * So if a hci_conn object already exists for the following connection
603 * attempt, we simply update pending_sec_level and auth_type fields
604 * and return the object found.
605 */
597 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, dst); 606 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, dst);
598 if (!conn) { 607 if (conn) {
599 conn = hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT); 608 conn->pending_sec_level = sec_level;
600 if (conn) 609 conn->auth_type = auth_type;
601 return ERR_PTR(-EBUSY); 610 goto done;
602 611 }
603 conn = hci_conn_add(hdev, LE_LINK, dst);
604 if (!conn)
605 return ERR_PTR(-ENOMEM);
606 612
607 conn->dst_type = bdaddr_to_le(dst_type); 613 /* Since the controller supports only one LE connection attempt at a
608 conn->state = BT_CONNECT; 614 * time, we return -EBUSY if there is any connection attempt running.
609 conn->out = true; 615 */
610 conn->link_mode |= HCI_LM_MASTER; 616 conn = hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT);
611 conn->sec_level = BT_SECURITY_LOW; 617 if (conn)
618 return ERR_PTR(-EBUSY);
612 619
613 err = hci_create_le_conn(conn); 620 conn = hci_conn_add(hdev, LE_LINK, dst);
614 if (err) 621 if (!conn)
615 return ERR_PTR(err); 622 return ERR_PTR(-ENOMEM);
616 }
617 623
624 conn->dst_type = bdaddr_to_le(dst_type);
625 conn->state = BT_CONNECT;
626 conn->out = true;
627 conn->link_mode |= HCI_LM_MASTER;
628 conn->sec_level = BT_SECURITY_LOW;
618 conn->pending_sec_level = sec_level; 629 conn->pending_sec_level = sec_level;
619 conn->auth_type = auth_type; 630 conn->auth_type = auth_type;
620 631
621 hci_conn_hold(conn); 632 err = hci_create_le_conn(conn);
633 if (err)
634 return ERR_PTR(err);
622 635
636done:
637 hci_conn_hold(conn);
623 return conn; 638 return conn;
624} 639}
625 640