]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - net/bluetooth/hci_event.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[karo-tx-linux.git] / net / bluetooth / hci_event.c
index a9a8e453817e1907d7478e538a0d05b2dd2db85d..186041866315a4e107de086df52142f39d6c6ee3 100644 (file)
@@ -837,43 +837,6 @@ static void hci_cc_read_local_amp_info(struct hci_dev *hdev,
        hdev->amp_max_flush_to = __le32_to_cpu(rp->max_flush_to);
 }
 
-static void hci_cc_read_local_amp_assoc(struct hci_dev *hdev,
-                                       struct sk_buff *skb)
-{
-       struct hci_rp_read_local_amp_assoc *rp = (void *) skb->data;
-       struct amp_assoc *assoc = &hdev->loc_assoc;
-       size_t rem_len, frag_len;
-
-       BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
-
-       if (rp->status)
-               goto a2mp_rsp;
-
-       frag_len = skb->len - sizeof(*rp);
-       rem_len = __le16_to_cpu(rp->rem_len);
-
-       if (rem_len > frag_len) {
-               BT_DBG("frag_len %zu rem_len %zu", frag_len, rem_len);
-
-               memcpy(assoc->data + assoc->offset, rp->frag, frag_len);
-               assoc->offset += frag_len;
-
-               /* Read other fragments */
-               amp_read_loc_assoc_frag(hdev, rp->phy_handle);
-
-               return;
-       }
-
-       memcpy(assoc->data + assoc->offset, rp->frag, rem_len);
-       assoc->len = assoc->offset + rem_len;
-       assoc->offset = 0;
-
-a2mp_rsp:
-       /* Send A2MP Rsp when all fragments are received */
-       a2mp_send_getampassoc_rsp(hdev, rp->status);
-       a2mp_send_create_phy_link_req(hdev, rp->status);
-}
-
 static void hci_cc_read_inq_rsp_tx_power(struct hci_dev *hdev,
                                         struct sk_buff *skb)
 {
@@ -1096,7 +1059,7 @@ static void hci_cc_le_set_adv_enable(struct hci_dev *hdev, struct sk_buff *skb)
 
                hci_dev_set_flag(hdev, HCI_LE_ADV);
 
-               conn = hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT);
+               conn = hci_lookup_le_connect(hdev);
                if (conn)
                        queue_delayed_work(hdev->workqueue,
                                           &conn->le_conn_timeout,
@@ -1406,20 +1369,6 @@ static void hci_cc_set_adv_param(struct hci_dev *hdev, struct sk_buff *skb)
        hci_dev_unlock(hdev);
 }
 
-static void hci_cc_write_remote_amp_assoc(struct hci_dev *hdev,
-                                         struct sk_buff *skb)
-{
-       struct hci_rp_write_remote_amp_assoc *rp = (void *) skb->data;
-
-       BT_DBG("%s status 0x%2.2x phy_handle 0x%2.2x",
-              hdev->name, rp->status, rp->phy_handle);
-
-       if (rp->status)
-               return;
-
-       amp_write_rem_assoc_continue(hdev, rp->phy_handle);
-}
-
 static void hci_cc_read_rssi(struct hci_dev *hdev, struct sk_buff *skb)
 {
        struct hci_rp_read_rssi *rp = (void *) skb->data;
@@ -1941,47 +1890,6 @@ static void hci_cs_disconnect(struct hci_dev *hdev, u8 status)
        hci_dev_unlock(hdev);
 }
 
-static void hci_cs_create_phylink(struct hci_dev *hdev, u8 status)
-{
-       struct hci_cp_create_phy_link *cp;
-
-       BT_DBG("%s status 0x%2.2x", hdev->name, status);
-
-       cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_PHY_LINK);
-       if (!cp)
-               return;
-
-       hci_dev_lock(hdev);
-
-       if (status) {
-               struct hci_conn *hcon;
-
-               hcon = hci_conn_hash_lookup_handle(hdev, cp->phy_handle);
-               if (hcon)
-                       hci_conn_del(hcon);
-       } else {
-               amp_write_remote_assoc(hdev, cp->phy_handle);
-       }
-
-       hci_dev_unlock(hdev);
-}
-
-static void hci_cs_accept_phylink(struct hci_dev *hdev, u8 status)
-{
-       struct hci_cp_accept_phy_link *cp;
-
-       BT_DBG("%s status 0x%2.2x", hdev->name, status);
-
-       if (status)
-               return;
-
-       cp = hci_sent_cmd_data(hdev, HCI_OP_ACCEPT_PHY_LINK);
-       if (!cp)
-               return;
-
-       amp_write_remote_assoc(hdev, cp->phy_handle);
-}
-
 static void hci_cs_le_create_conn(struct hci_dev *hdev, u8 status)
 {
        struct hci_cp_le_create_conn *cp;
@@ -2995,10 +2903,6 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb,
                hci_cc_read_clock(hdev, skb);
                break;
 
-       case HCI_OP_READ_LOCAL_AMP_ASSOC:
-               hci_cc_read_local_amp_assoc(hdev, skb);
-               break;
-
        case HCI_OP_READ_INQ_RSP_TX_POWER:
                hci_cc_read_inq_rsp_tx_power(hdev, skb);
                break;
@@ -3103,10 +3007,6 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb,
                hci_cc_set_adv_param(hdev, skb);
                break;
 
-       case HCI_OP_WRITE_REMOTE_AMP_ASSOC:
-               hci_cc_write_remote_amp_assoc(hdev, skb);
-               break;
-
        case HCI_OP_READ_RSSI:
                hci_cc_read_rssi(hdev, skb);
                break;
@@ -3190,14 +3090,6 @@ static void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb,
                hci_cs_setup_sync_conn(hdev, ev->status);
                break;
 
-       case HCI_OP_CREATE_PHY_LINK:
-               hci_cs_create_phylink(hdev, ev->status);
-               break;
-
-       case HCI_OP_ACCEPT_PHY_LINK:
-               hci_cs_accept_phylink(hdev, ev->status);
-               break;
-
        case HCI_OP_SNIFF_MODE:
                hci_cs_sniff_mode(hdev, ev->status);
                break;
@@ -3834,17 +3726,25 @@ static void hci_sync_conn_complete_evt(struct hci_dev *hdev,
                if (ev->link_type == ESCO_LINK)
                        goto unlock;
 
+               /* When the link type in the event indicates SCO connection
+                * and lookup of the connection object fails, then check
+                * if an eSCO connection object exists.
+                *
+                * The core limits the synchronous connections to either
+                * SCO or eSCO. The eSCO connection is preferred and tried
+                * to be setup first and until successfully established,
+                * the link type will be hinted as eSCO.
+                */
                conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr);
                if (!conn)
                        goto unlock;
-
-               conn->type = SCO_LINK;
        }
 
        switch (ev->status) {
        case 0x00:
                conn->handle = __le16_to_cpu(ev->handle);
                conn->state  = BT_CONNECTED;
+               conn->type   = ev->link_type;
 
                hci_debugfs_create_conn(conn);
                hci_conn_add_sysfs(conn);
@@ -4555,7 +4455,7 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
         */
        hci_dev_clear_flag(hdev, HCI_LE_ADV);
 
-       conn = hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT);
+       conn = hci_lookup_le_connect(hdev);
        if (!conn) {
                conn = hci_conn_add(hdev, LE_LINK, &ev->bdaddr, ev->role);
                if (!conn) {
@@ -4748,42 +4648,49 @@ static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev,
        /* If we're not connectable only connect devices that we have in
         * our pend_le_conns list.
         */
-       params = hci_pend_le_action_lookup(&hdev->pend_le_conns,
-                                          addr, addr_type);
+       params = hci_explicit_connect_lookup(hdev, addr, addr_type);
+
        if (!params)
                return NULL;
 
-       switch (params->auto_connect) {
-       case HCI_AUTO_CONN_DIRECT:
-               /* Only devices advertising with ADV_DIRECT_IND are
-                * triggering a connection attempt. This is allowing
-                * incoming connections from slave devices.
-                */
-               if (adv_type != LE_ADV_DIRECT_IND)
+       if (!params->explicit_connect) {
+               switch (params->auto_connect) {
+               case HCI_AUTO_CONN_DIRECT:
+                       /* Only devices advertising with ADV_DIRECT_IND are
+                        * triggering a connection attempt. This is allowing
+                        * incoming connections from slave devices.
+                        */
+                       if (adv_type != LE_ADV_DIRECT_IND)
+                               return NULL;
+                       break;
+               case HCI_AUTO_CONN_ALWAYS:
+                       /* Devices advertising with ADV_IND or ADV_DIRECT_IND
+                        * are triggering a connection attempt. This means
+                        * that incoming connectioms from slave device are
+                        * accepted and also outgoing connections to slave
+                        * devices are established when found.
+                        */
+                       break;
+               default:
                        return NULL;
-               break;
-       case HCI_AUTO_CONN_ALWAYS:
-               /* Devices advertising with ADV_IND or ADV_DIRECT_IND
-                * are triggering a connection attempt. This means
-                * that incoming connectioms from slave device are
-                * accepted and also outgoing connections to slave
-                * devices are established when found.
-                */
-               break;
-       default:
-               return NULL;
+               }
        }
 
        conn = hci_connect_le(hdev, addr, addr_type, BT_SECURITY_LOW,
                              HCI_LE_AUTOCONN_TIMEOUT, HCI_ROLE_MASTER);
        if (!IS_ERR(conn)) {
-               /* Store the pointer since we don't really have any
+               /* If HCI_AUTO_CONN_EXPLICIT is set, conn is already owned
+                * by higher layer that tried to connect, if no then
+                * store the pointer since we don't really have any
                 * other owner of the object besides the params that
                 * triggered it. This way we can abort the connection if
                 * the parameters get removed and keep the reference
                 * count consistent once the connection is established.
                 */
-               params->conn = hci_conn_get(conn);
+
+               if (!params->explicit_connect)
+                       params->conn = hci_conn_get(conn);
+
                return conn;
        }