Revert "Bluetooth: Store advertising handle so it can be re-enabled"
[platform/kernel/linux-rpi.git] / net / bluetooth / hci_event.c
index 354a7d2..0fdf91a 100644 (file)
@@ -2009,12 +2009,22 @@ static u8 hci_cc_le_read_def_data_len(struct hci_dev *hdev, void *data,
 
        bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
 
+#ifdef TIZEN_BT
+       hci_dev_lock(hdev);
+#else
        if (rp->status)
                return rp->status;
+#endif
 
        hdev->le_def_tx_len = le16_to_cpu(rp->tx_len);
        hdev->le_def_tx_time = le16_to_cpu(rp->tx_time);
 
+#ifdef TIZEN_BT
+       mgmt_le_read_host_suggested_data_length_complete(hdev, rp->status);
+
+       hci_dev_unlock(hdev);
+#endif
+
        return rp->status;
 }
 
@@ -2027,16 +2037,29 @@ static u8 hci_cc_le_write_def_data_len(struct hci_dev *hdev, void *data,
        bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
 
        if (rp->status)
+#ifndef TIZEN_BT
                return rp->status;
+#else
+               goto unblock;
+#endif
 
        sent = hci_sent_cmd_data(hdev, HCI_OP_LE_WRITE_DEF_DATA_LEN);
        if (!sent)
+#ifndef TIZEN_BT
                return rp->status;
+#else
+               goto unblock;
+#endif
 
        hdev->le_def_tx_len = le16_to_cpu(sent->tx_len);
        hdev->le_def_tx_time = le16_to_cpu(sent->tx_time);
 
        return rp->status;
+#ifdef TIZEN_BT
+unblock:
+       mgmt_le_write_host_suggested_data_length_complete(hdev, rp->status);
+       return rp->status;
+#endif
 }
 
 static u8 hci_cc_le_add_to_resolv_list(struct hci_dev *hdev, void *data,
@@ -2360,6 +2383,32 @@ static void hci_vendor_specific_evt(struct hci_dev *hdev, void *data,
                break;
        }
 }
+
+static void hci_le_data_length_changed_complete_evt(struct hci_dev *hdev,
+                                                   void *data,
+                                                   struct sk_buff *skb)
+{
+       struct hci_ev_le_data_len_change *ev = (void *)skb->data;
+       struct hci_conn *conn;
+
+       BT_DBG("%s status", hdev->name);
+
+       hci_dev_lock(hdev);
+
+       conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
+       if (conn) {
+               conn->tx_len = le16_to_cpu(ev->tx_len);
+               conn->tx_time = le16_to_cpu(ev->tx_time);
+               conn->rx_len = le16_to_cpu(ev->rx_len);
+               conn->rx_time = le16_to_cpu(ev->rx_time);
+
+               mgmt_le_data_length_change_complete(hdev, &conn->dst,
+                                           conn->tx_len, conn->tx_time,
+                                           conn->rx_len, conn->rx_time);
+       }
+
+       hci_dev_unlock(hdev);
+}
 #endif
 
 static u8 hci_cc_read_rssi(struct hci_dev *hdev, void *data,
@@ -2933,13 +2982,12 @@ static void hci_cs_disconnect(struct hci_dev *hdev, u8 status)
                goto unlock;
 
        if (status) {
+               u8 type = conn->type;
                mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
                                       conn->dst_type, status);
 
-               if (conn->type == LE_LINK && conn->role == HCI_ROLE_SLAVE) {
-                       hdev->cur_adv_instance = conn->adv_instance;
+               if (type == LE_LINK)
                        hci_enable_advertising(hdev);
-               }
 
                /* Inform sockets conn is gone before we delete it */
                hci_disconn_cfm(conn, HCI_ERROR_UNSPECIFIED);
@@ -3565,6 +3613,7 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, void *data,
        struct hci_conn_params *params;
        struct hci_conn *conn;
        bool mgmt_connected;
+       u8 type;
 
        bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
 
@@ -3618,8 +3667,10 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, void *data,
                        break;
                }
        }
+       type = conn->type;
 
        hci_disconn_cfm(conn, ev->reason);
+       hci_conn_del(conn);
 
        /* Re-enable advertising if necessary, since it might
         * have been disabled by the connection. From the
@@ -3631,12 +3682,10 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, void *data,
         * or until a connection is created or until the Advertising
         * is timed out due to Directed Advertising."
         */
-       if (conn->type == LE_LINK && conn->role == HCI_ROLE_SLAVE) {
-               hdev->cur_adv_instance = conn->adv_instance;
+
+       if (type == LE_LINK)
                hci_enable_advertising(hdev);
-       }
 
-       hci_conn_del(conn);
 
 #ifdef TIZEN_BT
        if (conn->type == ACL_LINK && !hci_conn_num(hdev, ACL_LINK)) {
@@ -6207,13 +6256,6 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status,
        conn->sec_level = BT_SECURITY_LOW;
        conn->state = BT_CONFIG;
 
-       /* Store current advertising instance as connection advertising instance
-        * when sotfware rotation is in use so it can be re-enabled when
-        * disconnected.
-        */
-       if (!ext_adv_capable(hdev))
-               conn->adv_instance = hdev->cur_adv_instance;
-
        conn->le_conn_interval = interval;
        conn->le_conn_latency = latency;
        conn->le_supv_timeout = supervision_timeout;
@@ -6294,7 +6336,7 @@ static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, void *data,
 {
        struct hci_evt_le_ext_adv_set_term *ev = data;
        struct hci_conn *conn;
-       struct adv_info *adv, *n;
+       struct adv_info *n;
 
        bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
 
@@ -6312,9 +6354,10 @@ static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, void *data,
 
        hci_dev_lock(hdev);
 
-       adv = hci_find_adv_instance(hdev, ev->handle);
 
        if (ev->status) {
+               struct adv_info *adv;
+               adv = hci_find_adv_instance(hdev, ev->handle);
                if (!adv)
                        goto unlock;
 
@@ -6332,15 +6375,9 @@ static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, void *data,
                goto unlock;
        }
 
-       if (adv)
-               adv->enabled = false;
-
        conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->conn_handle));
        if (conn) {
-               /* Store handle in the connection so the correct advertising
-                * instance can be re-enabled when disconnected.
-                */
-               conn->adv_instance = ev->handle;
+               struct adv_info *adv_instance;
 
                if (hdev->adv_addr_type != ADDR_LE_DEV_RANDOM ||
                    bacmp(&conn->resp_addr, BDADDR_ANY))
@@ -6351,8 +6388,9 @@ static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, void *data,
                        goto unlock;
                }
 
-               if (adv)
-                       bacpy(&conn->resp_addr, &adv->random_addr);
+               adv_instance = hci_find_adv_instance(hdev, ev->handle);
+               if (adv_instance)
+                       bacpy(&conn->resp_addr, &adv_instance->random_addr);
        }
 
 unlock:
@@ -7517,6 +7555,12 @@ static const struct hci_le_ev {
        HCI_LE_EV(HCI_EV_LE_REMOTE_CONN_PARAM_REQ,
                  hci_le_remote_conn_param_req_evt,
                  sizeof(struct hci_ev_le_remote_conn_param_req)),
+#ifdef TIZEN_BT
+       /* [0x07 = HCI_EV_LE_DATA_LEN_CHANGE] */
+       HCI_LE_EV(HCI_EV_LE_DATA_LEN_CHANGE,
+                 hci_le_data_length_changed_complete_evt,
+                 sizeof(struct hci_ev_le_data_len_change)),
+#endif
        /* [0x0a = HCI_EV_LE_ENHANCED_CONN_COMPLETE] */
        HCI_LE_EV(HCI_EV_LE_ENHANCED_CONN_COMPLETE,
                  hci_le_enh_conn_complete_evt,