Commit 3846220b authored by Andre Guedes's avatar Andre Guedes Committed by Gustavo Padovan

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: default avatarAndre Guedes <andre.guedes@openbossa.org>
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
parent abf54a50
...@@ -1781,6 +1781,7 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -1781,6 +1781,7 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
struct hci_ev_disconn_complete *ev = (void *) skb->data; struct hci_ev_disconn_complete *ev = (void *) skb->data;
u8 reason = hci_to_mgmt_reason(ev->reason); u8 reason = hci_to_mgmt_reason(ev->reason);
struct hci_conn *conn; struct hci_conn *conn;
u8 type;
BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
...@@ -1790,40 +1791,38 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -1790,40 +1791,38 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
if (!conn) if (!conn)
goto unlock; goto unlock;
if (ev->status == 0)
conn->state = BT_CLOSED;
if (ev->status) { if (ev->status) {
mgmt_disconnect_failed(hdev, &conn->dst, conn->type, mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
conn->dst_type, ev->status); conn->dst_type, ev->status);
goto unlock; goto unlock;
} }
conn->state = BT_CLOSED;
if (test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) if (test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
mgmt_device_disconnected(hdev, &conn->dst, conn->type, mgmt_device_disconnected(hdev, &conn->dst, conn->type,
conn->dst_type, reason); conn->dst_type, reason);
if (ev->status == 0) { if (conn->type == ACL_LINK && conn->flush_key)
u8 type = conn->type; hci_remove_link_key(hdev, &conn->dst);
if (type == ACL_LINK && conn->flush_key) type = conn->type;
hci_remove_link_key(hdev, &conn->dst);
hci_proto_disconn_cfm(conn, ev->reason);
hci_conn_del(conn);
/* Re-enable advertising if necessary, since it might hci_proto_disconn_cfm(conn, ev->reason);
* have been disabled by the connection. From the hci_conn_del(conn);
* HCI_LE_Set_Advertise_Enable command description in
* the core specification (v4.0): /* Re-enable advertising if necessary, since it might
* "The Controller shall continue advertising until the Host * have been disabled by the connection. From the
* issues an LE_Set_Advertise_Enable command with * HCI_LE_Set_Advertise_Enable command description in
* Advertising_Enable set to 0x00 (Advertising is disabled) * the core specification (v4.0):
* or until a connection is created or until the Advertising * "The Controller shall continue advertising until the Host
* is timed out due to Directed Advertising." * issues an LE_Set_Advertise_Enable command with
*/ * Advertising_Enable set to 0x00 (Advertising is disabled)
if (type == LE_LINK) * or until a connection is created or until the Advertising
mgmt_reenable_advertising(hdev); * is timed out due to Directed Advertising."
} */
if (type == LE_LINK)
mgmt_reenable_advertising(hdev);
unlock: 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