aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Guedes <andre.guedes@openbossa.org>2013-11-07 15:36:10 -0500
committerGustavo Padovan <gustavo.padovan@collabora.co.uk>2013-12-04 08:09:04 -0500
commit3846220b0df414816d00365cec559ff3c8b7c4bf (patch)
tree885feba756eed1a596f0c2d4ec68c67fb71561dc
parentabf54a506d06e0b3ba2c408040e647791af37937 (diff)
Bluetooth: Refactor hci_disconn_complete_evt
hci_disconn_complete_evt() logic is more complicated than what it should be, making it hard to follow and add new features. So this patch does some code refactoring by handling the error cases in the beginning of the function and by moving the main flow into the first level of function scope. No change is done in the event handling logic itself. Besides organizing this messy code, this patch makes easier to add code for handling LE auto connection (which will be added in a further patch). Signed-off-by: Andre Guedes <andre.guedes@openbossa.org> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
-rw-r--r--net/bluetooth/hci_event.c43
1 files changed, 21 insertions, 22 deletions
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index eb99a12948c5..5fb3df66c2cd 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1781,6 +1781,7 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1781 struct hci_ev_disconn_complete *ev = (void *) skb->data; 1781 struct hci_ev_disconn_complete *ev = (void *) skb->data;
1782 u8 reason = hci_to_mgmt_reason(ev->reason); 1782 u8 reason = hci_to_mgmt_reason(ev->reason);
1783 struct hci_conn *conn; 1783 struct hci_conn *conn;
1784 u8 type;
1784 1785
1785 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); 1786 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
1786 1787
@@ -1790,40 +1791,38 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1790 if (!conn) 1791 if (!conn)
1791 goto unlock; 1792 goto unlock;
1792 1793
1793 if (ev->status == 0)
1794 conn->state = BT_CLOSED;
1795
1796 if (ev->status) { 1794 if (ev->status) {
1797 mgmt_disconnect_failed(hdev, &conn->dst, conn->type, 1795 mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
1798 conn->dst_type, ev->status); 1796 conn->dst_type, ev->status);
1799 goto unlock; 1797 goto unlock;
1800 } 1798 }
1801 1799
1800 conn->state = BT_CLOSED;
1801
1802 if (test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) 1802 if (test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
1803 mgmt_device_disconnected(hdev, &conn->dst, conn->type, 1803 mgmt_device_disconnected(hdev, &conn->dst, conn->type,
1804 conn->dst_type, reason); 1804 conn->dst_type, reason);
1805 1805
1806 if (ev->status == 0) { 1806 if (conn->type == ACL_LINK && conn->flush_key)
1807 u8 type = conn->type; 1807 hci_remove_link_key(hdev, &conn->dst);
1808 1808
1809 if (type == ACL_LINK && conn->flush_key) 1809 type = conn->type;
1810 hci_remove_link_key(hdev, &conn->dst);
1811 hci_proto_disconn_cfm(conn, ev->reason);
1812 hci_conn_del(conn);
1813 1810
1814 /* Re-enable advertising if necessary, since it might 1811 hci_proto_disconn_cfm(conn, ev->reason);
1815 * have been disabled by the connection. From the 1812 hci_conn_del(conn);
1816 * HCI_LE_Set_Advertise_Enable command description in 1813
1817 * the core specification (v4.0): 1814 /* Re-enable advertising if necessary, since it might
1818 * "The Controller shall continue advertising until the Host 1815 * have been disabled by the connection. From the
1819 * issues an LE_Set_Advertise_Enable command with 1816 * HCI_LE_Set_Advertise_Enable command description in
1820 * Advertising_Enable set to 0x00 (Advertising is disabled) 1817 * the core specification (v4.0):
1821 * or until a connection is created or until the Advertising 1818 * "The Controller shall continue advertising until the Host
1822 * is timed out due to Directed Advertising." 1819 * issues an LE_Set_Advertise_Enable command with
1823 */ 1820 * Advertising_Enable set to 0x00 (Advertising is disabled)
1824 if (type == LE_LINK) 1821 * or until a connection is created or until the Advertising
1825 mgmt_reenable_advertising(hdev); 1822 * is timed out due to Directed Advertising."
1826 } 1823 */
1824 if (type == LE_LINK)
1825 mgmt_reenable_advertising(hdev);
1827 1826
1828unlock: 1827unlock:
1829 hci_dev_unlock(hdev); 1828 hci_dev_unlock(hdev);