Merge tag 'arm64-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64...
[firefly-linux-kernel-4.4.55.git] / net / bluetooth / l2cap_core.c
index 6ba33f9631e8e5830374ab4e51720c493969c67c..dad419782a1280bbff079c4978578f0be54e37a3 100644 (file)
@@ -292,7 +292,7 @@ static struct sk_buff *l2cap_ertm_seq_in_queue(struct sk_buff_head *head,
        struct sk_buff *skb;
 
        skb_queue_walk(head, skb) {
-               if (bt_cb(skb)->control.txseq == seq)
+               if (bt_cb(skb)->l2cap.txseq == seq)
                        return skb;
        }
 
@@ -954,11 +954,11 @@ static inline void __unpack_control(struct l2cap_chan *chan,
 {
        if (test_bit(FLAG_EXT_CTRL, &chan->flags)) {
                __unpack_extended_control(get_unaligned_le32(skb->data),
-                                         &bt_cb(skb)->control);
+                                         &bt_cb(skb)->l2cap);
                skb_pull(skb, L2CAP_EXT_CTRL_SIZE);
        } else {
                __unpack_enhanced_control(get_unaligned_le16(skb->data),
-                                         &bt_cb(skb)->control);
+                                         &bt_cb(skb)->l2cap);
                skb_pull(skb, L2CAP_ENH_CTRL_SIZE);
        }
 }
@@ -1200,8 +1200,8 @@ static void l2cap_move_setup(struct l2cap_chan *chan)
 
        chan->retry_count = 0;
        skb_queue_walk(&chan->tx_q, skb) {
-               if (bt_cb(skb)->control.retries)
-                       bt_cb(skb)->control.retries = 1;
+               if (bt_cb(skb)->l2cap.retries)
+                       bt_cb(skb)->l2cap.retries = 1;
                else
                        break;
        }
@@ -1244,6 +1244,13 @@ static void l2cap_move_done(struct l2cap_chan *chan)
 
 static void l2cap_chan_ready(struct l2cap_chan *chan)
 {
+       /* The channel may have already been flagged as connected in
+        * case of receiving data before the L2CAP info req/rsp
+        * procedure is complete.
+        */
+       if (chan->state == BT_CONNECTED)
+               return;
+
        /* This clears all conf flags, including CONF_NOT_COMPLETE */
        chan->conf_state = 0;
        __clear_chan_timer(chan);
@@ -1839,8 +1846,8 @@ static void l2cap_streaming_send(struct l2cap_chan *chan,
 
                skb = skb_dequeue(&chan->tx_q);
 
-               bt_cb(skb)->control.retries = 1;
-               control = &bt_cb(skb)->control;
+               bt_cb(skb)->l2cap.retries = 1;
+               control = &bt_cb(skb)->l2cap;
 
                control->reqseq = 0;
                control->txseq = chan->next_tx_seq;
@@ -1884,8 +1891,8 @@ static int l2cap_ertm_send(struct l2cap_chan *chan)
 
                skb = chan->tx_send_head;
 
-               bt_cb(skb)->control.retries = 1;
-               control = &bt_cb(skb)->control;
+               bt_cb(skb)->l2cap.retries = 1;
+               control = &bt_cb(skb)->l2cap;
 
                if (test_and_clear_bit(CONN_SEND_FBIT, &chan->conn_state))
                        control->final = 1;
@@ -1956,11 +1963,11 @@ static void l2cap_ertm_resend(struct l2cap_chan *chan)
                        continue;
                }
 
-               bt_cb(skb)->control.retries++;
-               control = bt_cb(skb)->control;
+               bt_cb(skb)->l2cap.retries++;
+               control = bt_cb(skb)->l2cap;
 
                if (chan->max_tx != 0 &&
-                   bt_cb(skb)->control.retries > chan->max_tx) {
+                   bt_cb(skb)->l2cap.retries > chan->max_tx) {
                        BT_DBG("Retry limit exceeded (%d)", chan->max_tx);
                        l2cap_send_disconn_req(chan, ECONNRESET);
                        l2cap_seq_list_clear(&chan->retrans_list);
@@ -2038,7 +2045,7 @@ static void l2cap_retransmit_all(struct l2cap_chan *chan,
 
        if (chan->unacked_frames) {
                skb_queue_walk(&chan->tx_q, skb) {
-                       if (bt_cb(skb)->control.txseq == control->reqseq ||
+                       if (bt_cb(skb)->l2cap.txseq == control->reqseq ||
                            skb == chan->tx_send_head)
                                break;
                }
@@ -2048,7 +2055,7 @@ static void l2cap_retransmit_all(struct l2cap_chan *chan,
                                break;
 
                        l2cap_seq_list_append(&chan->retrans_list,
-                                             bt_cb(skb)->control.txseq);
+                                             bt_cb(skb)->l2cap.txseq);
                }
 
                l2cap_ertm_resend(chan);
@@ -2260,8 +2267,8 @@ static struct sk_buff *l2cap_create_iframe_pdu(struct l2cap_chan *chan,
                return ERR_PTR(err);
        }
 
-       bt_cb(skb)->control.fcs = chan->fcs;
-       bt_cb(skb)->control.retries = 0;
+       bt_cb(skb)->l2cap.fcs = chan->fcs;
+       bt_cb(skb)->l2cap.retries = 0;
        return skb;
 }
 
@@ -2314,7 +2321,7 @@ static int l2cap_segment_sdu(struct l2cap_chan *chan,
                        return PTR_ERR(skb);
                }
 
-               bt_cb(skb)->control.sar = sar;
+               bt_cb(skb)->l2cap.sar = sar;
                __skb_queue_tail(seg_queue, skb);
 
                len -= pdu_len;
@@ -2849,7 +2856,7 @@ static void l2cap_raw_recv(struct l2cap_conn *conn, struct sk_buff *skb)
                        continue;
 
                /* Don't send frame to the channel it came from */
-               if (bt_cb(skb)->chan == chan)
+               if (bt_cb(skb)->l2cap.chan == chan)
                        continue;
 
                nskb = skb_clone(skb, GFP_KERNEL);
@@ -3893,7 +3900,7 @@ static int l2cap_connect_req(struct l2cap_conn *conn,
                return -EPROTO;
 
        hci_dev_lock(hdev);
-       if (test_bit(HCI_MGMT, &hdev->dev_flags) &&
+       if (hci_dev_test_flag(hdev, HCI_MGMT) &&
            !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &hcon->flags))
                mgmt_device_connected(hdev, hcon, 0, NULL, 0);
        hci_dev_unlock(hdev);
@@ -5911,7 +5918,7 @@ static int l2cap_rx_queued_iframes(struct l2cap_chan *chan)
 
                skb_unlink(skb, &chan->srej_q);
                chan->buffer_seq = __next_seq(chan, chan->buffer_seq);
-               err = l2cap_reassemble_sdu(chan, skb, &bt_cb(skb)->control);
+               err = l2cap_reassemble_sdu(chan, skb, &bt_cb(skb)->l2cap);
                if (err)
                        break;
        }
@@ -5945,7 +5952,7 @@ static void l2cap_handle_srej(struct l2cap_chan *chan,
                return;
        }
 
-       if (chan->max_tx != 0 && bt_cb(skb)->control.retries >= chan->max_tx) {
+       if (chan->max_tx != 0 && bt_cb(skb)->l2cap.retries >= chan->max_tx) {
                BT_DBG("Retry limit exceeded (%d)", chan->max_tx);
                l2cap_send_disconn_req(chan, ECONNRESET);
                return;
@@ -5998,7 +6005,7 @@ static void l2cap_handle_rej(struct l2cap_chan *chan,
        skb = l2cap_ertm_seq_in_queue(&chan->tx_q, control->reqseq);
 
        if (chan->max_tx && skb &&
-           bt_cb(skb)->control.retries >= chan->max_tx) {
+           bt_cb(skb)->l2cap.retries >= chan->max_tx) {
                BT_DBG("Retry limit exceeded (%d)", chan->max_tx);
                l2cap_send_disconn_req(chan, ECONNRESET);
                return;
@@ -6558,7 +6565,7 @@ static int l2cap_stream_rx(struct l2cap_chan *chan, struct l2cap_ctrl *control,
 
 static int l2cap_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb)
 {
-       struct l2cap_ctrl *control = &bt_cb(skb)->control;
+       struct l2cap_ctrl *control = &bt_cb(skb)->l2cap;
        u16 len;
        u8 event;
 
@@ -6785,6 +6792,13 @@ static void l2cap_data_channel(struct l2cap_conn *conn, u16 cid,
 
        BT_DBG("chan %p, len %d", chan, skb->len);
 
+       /* If we receive data on a fixed channel before the info req/rsp
+        * procdure is done simply assume that the channel is supported
+        * and mark it as ready.
+        */
+       if (chan->chan_type == L2CAP_CHAN_FIXED)
+               l2cap_chan_ready(chan);
+
        if (chan->state != BT_CONNECTED)
                goto drop;
 
@@ -6850,8 +6864,8 @@ static void l2cap_conless_channel(struct l2cap_conn *conn, __le16 psm,
                goto drop;
 
        /* Store remote BD_ADDR and PSM for msg_name */
-       bacpy(&bt_cb(skb)->bdaddr, &hcon->dst);
-       bt_cb(skb)->psm = psm;
+       bacpy(&bt_cb(skb)->l2cap.bdaddr, &hcon->dst);
+       bt_cb(skb)->l2cap.psm = psm;
 
        if (!chan->ops->recv(chan, skb)) {
                l2cap_chan_put(chan);
@@ -6973,12 +6987,12 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon)
        conn->local_fixed_chan = L2CAP_FC_SIG_BREDR | L2CAP_FC_CONNLESS;
 
        if (hcon->type == ACL_LINK &&
-           test_bit(HCI_HS_ENABLED, &hcon->hdev->dev_flags))
+           hci_dev_test_flag(hcon->hdev, HCI_HS_ENABLED))
                conn->local_fixed_chan |= L2CAP_FC_A2MP;
 
-       if (test_bit(HCI_LE_ENABLED, &hcon->hdev->dev_flags) &&
+       if (hci_dev_test_flag(hcon->hdev, HCI_LE_ENABLED) &&
            (bredr_sc_enabled(hcon->hdev) ||
-            test_bit(HCI_FORCE_BREDR_SMP, &hcon->hdev->dbg_flags)))
+            hci_dev_test_flag(hcon->hdev, HCI_FORCE_BREDR_SMP)))
                conn->local_fixed_chan |= L2CAP_FC_SMP_BREDR;
 
        mutex_init(&conn->ident_lock);
@@ -7098,7 +7112,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
                else
                        dst_type = ADDR_LE_DEV_RANDOM;
 
-               if (test_bit(HCI_ADVERTISING, &hdev->dev_flags))
+               if (hci_dev_test_flag(hdev, HCI_ADVERTISING))
                        role = HCI_ROLE_SLAVE;
                else
                        role = HCI_ROLE_MASTER;
@@ -7238,13 +7252,16 @@ static struct l2cap_chan *l2cap_global_fixed_chan(struct l2cap_chan *c,
        return NULL;
 }
 
-void l2cap_connect_cfm(struct hci_conn *hcon, u8 status)
+static void l2cap_connect_cfm(struct hci_conn *hcon, u8 status)
 {
        struct hci_dev *hdev = hcon->hdev;
        struct l2cap_conn *conn;
        struct l2cap_chan *pchan;
        u8 dst_type;
 
+       if (hcon->type != ACL_LINK && hcon->type != LE_LINK)
+               return;
+
        BT_DBG("hcon %p bdaddr %pMR status %d", hcon, &hcon->dst, status);
 
        if (status) {
@@ -7307,8 +7324,11 @@ int l2cap_disconn_ind(struct hci_conn *hcon)
        return conn->disc_reason;
 }
 
-void l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason)
+static void l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason)
 {
+       if (hcon->type != ACL_LINK && hcon->type != LE_LINK)
+               return;
+
        BT_DBG("hcon %p reason %d", hcon, reason);
 
        l2cap_conn_del(hcon, bt_to_errno(reason));
@@ -7331,13 +7351,13 @@ static inline void l2cap_check_encryption(struct l2cap_chan *chan, u8 encrypt)
        }
 }
 
-int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
+static void l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
 {
        struct l2cap_conn *conn = hcon->l2cap_data;
        struct l2cap_chan *chan;
 
        if (!conn)
-               return 0;
+               return;
 
        BT_DBG("conn %p status 0x%2.2x encrypt %u", conn, status, encrypt);
 
@@ -7420,8 +7440,6 @@ int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
        }
 
        mutex_unlock(&conn->chan_lock);
-
-       return 0;
 }
 
 int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags)
@@ -7529,6 +7547,13 @@ drop:
        return 0;
 }
 
+static struct hci_cb l2cap_cb = {
+       .name           = "L2CAP",
+       .connect_cfm    = l2cap_connect_cfm,
+       .disconn_cfm    = l2cap_disconn_cfm,
+       .security_cfm   = l2cap_security_cfm,
+};
+
 static int l2cap_debugfs_show(struct seq_file *f, void *p)
 {
        struct l2cap_chan *c;
@@ -7570,6 +7595,8 @@ int __init l2cap_init(void)
        if (err < 0)
                return err;
 
+       hci_register_cb(&l2cap_cb);
+
        if (IS_ERR_OR_NULL(bt_debugfs))
                return 0;
 
@@ -7587,6 +7614,7 @@ int __init l2cap_init(void)
 void l2cap_exit(void)
 {
        debugfs_remove(l2cap_debugfs);
+       hci_unregister_cb(&l2cap_cb);
        l2cap_cleanup_sockets();
 }