Merge tag 'docs-for-linus' of git://git.lwn.net/linux-2.6
[firefly-linux-kernel-4.4.55.git] / net / bluetooth / l2cap_core.c
index d04dc009573691cde515d1db82c13cbfd11a459f..6ba33f9631e8e5830374ab4e51720c493969c67c 100644 (file)
@@ -63,10 +63,10 @@ static void l2cap_send_disconn_req(struct l2cap_chan *chan, int err);
 static void l2cap_tx(struct l2cap_chan *chan, struct l2cap_ctrl *control,
                     struct sk_buff_head *skbs, u8 event);
 
-static inline __u8 bdaddr_type(struct hci_conn *hcon, __u8 type)
+static inline u8 bdaddr_type(u8 link_type, u8 bdaddr_type)
 {
-       if (hcon->type == LE_LINK) {
-               if (type == ADDR_LE_DEV_PUBLIC)
+       if (link_type == LE_LINK) {
+               if (bdaddr_type == ADDR_LE_DEV_PUBLIC)
                        return BDADDR_LE_PUBLIC;
                else
                        return BDADDR_LE_RANDOM;
@@ -75,6 +75,16 @@ static inline __u8 bdaddr_type(struct hci_conn *hcon, __u8 type)
        return BDADDR_BREDR;
 }
 
+static inline u8 bdaddr_src_type(struct hci_conn *hcon)
+{
+       return bdaddr_type(hcon->type, hcon->src_type);
+}
+
+static inline u8 bdaddr_dst_type(struct hci_conn *hcon)
+{
+       return bdaddr_type(hcon->type, hcon->dst_type);
+}
+
 /* ---- L2CAP channels ---- */
 
 static struct l2cap_chan *__l2cap_get_chan_by_dcid(struct l2cap_conn *conn,
@@ -646,7 +656,7 @@ static void l2cap_conn_update_id_addr(struct work_struct *work)
        list_for_each_entry(chan, &conn->chan_l, list) {
                l2cap_chan_lock(chan);
                bacpy(&chan->dst, &hcon->dst);
-               chan->dst_type = bdaddr_type(hcon, hcon->dst_type);
+               chan->dst_type = bdaddr_dst_type(hcon);
                l2cap_chan_unlock(chan);
        }
 
@@ -3790,8 +3800,8 @@ static struct l2cap_chan *l2cap_connect(struct l2cap_conn *conn,
 
        bacpy(&chan->src, &conn->hcon->src);
        bacpy(&chan->dst, &conn->hcon->dst);
-       chan->src_type = bdaddr_type(conn->hcon, conn->hcon->src_type);
-       chan->dst_type = bdaddr_type(conn->hcon, conn->hcon->dst_type);
+       chan->src_type = bdaddr_src_type(conn->hcon);
+       chan->dst_type = bdaddr_dst_type(conn->hcon);
        chan->psm  = psm;
        chan->dcid = scid;
        chan->local_amp_id = amp_id;
@@ -5441,8 +5451,8 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn,
 
        bacpy(&chan->src, &conn->hcon->src);
        bacpy(&chan->dst, &conn->hcon->dst);
-       chan->src_type = bdaddr_type(conn->hcon, conn->hcon->src_type);
-       chan->dst_type = bdaddr_type(conn->hcon, conn->hcon->dst_type);
+       chan->src_type = bdaddr_src_type(conn->hcon);
+       chan->dst_type = bdaddr_dst_type(conn->hcon);
        chan->psm  = psm;
        chan->dcid = scid;
        chan->omtu = mtu;
@@ -6881,7 +6891,7 @@ static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb)
         */
        if (hcon->type == LE_LINK &&
            hci_bdaddr_list_lookup(&hcon->hdev->blacklist, &hcon->dst,
-                                  bdaddr_type(hcon, hcon->dst_type))) {
+                                  bdaddr_dst_type(hcon))) {
                kfree_skb(skb);
                return;
        }
@@ -6968,7 +6978,7 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon)
 
        if (test_bit(HCI_LE_ENABLED, &hcon->hdev->dev_flags) &&
            (bredr_sc_enabled(hcon->hdev) ||
-            test_bit(HCI_FORCE_LESC, &hcon->hdev->dbg_flags)))
+            test_bit(HCI_FORCE_BREDR_SMP, &hcon->hdev->dbg_flags)))
                conn->local_fixed_chan |= L2CAP_FC_SMP_BREDR;
 
        mutex_init(&conn->ident_lock);
@@ -7123,7 +7133,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
 
        /* Update source addr of the socket */
        bacpy(&chan->src, &hcon->src);
-       chan->src_type = bdaddr_type(hcon, hcon->src_type);
+       chan->src_type = bdaddr_src_type(hcon);
 
        __l2cap_chan_add(conn, chan);
 
@@ -7197,8 +7207,10 @@ int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr)
  * global list (by passing NULL as first parameter).
  */
 static struct l2cap_chan *l2cap_global_fixed_chan(struct l2cap_chan *c,
-                                                 bdaddr_t *src, u8 link_type)
+                                                 struct hci_conn *hcon)
 {
+       u8 src_type = bdaddr_src_type(hcon);
+
        read_lock(&chan_list_lock);
 
        if (c)
@@ -7211,11 +7223,9 @@ static struct l2cap_chan *l2cap_global_fixed_chan(struct l2cap_chan *c,
                        continue;
                if (c->state != BT_LISTEN)
                        continue;
-               if (bacmp(&c->src, src) && bacmp(&c->src, BDADDR_ANY))
+               if (bacmp(&c->src, &hcon->src) && bacmp(&c->src, BDADDR_ANY))
                        continue;
-               if (link_type == ACL_LINK && c->src_type != BDADDR_BREDR)
-                       continue;
-               if (link_type == LE_LINK && c->src_type == BDADDR_BREDR)
+               if (src_type != c->src_type)
                        continue;
 
                l2cap_chan_hold(c);
@@ -7246,7 +7256,7 @@ void l2cap_connect_cfm(struct hci_conn *hcon, u8 status)
        if (!conn)
                return;
 
-       dst_type = bdaddr_type(hcon, hcon->dst_type);
+       dst_type = bdaddr_dst_type(hcon);
 
        /* If device is blocked, do not create channels for it */
        if (hci_bdaddr_list_lookup(&hdev->blacklist, &hcon->dst, dst_type))
@@ -7257,7 +7267,7 @@ void l2cap_connect_cfm(struct hci_conn *hcon, u8 status)
         * we left off, because the list lock would prevent calling the
         * potentially sleeping l2cap_chan_lock() function.
         */
-       pchan = l2cap_global_fixed_chan(NULL, &hdev->bdaddr, hcon->type);
+       pchan = l2cap_global_fixed_chan(NULL, hcon);
        while (pchan) {
                struct l2cap_chan *chan, *next;
 
@@ -7270,7 +7280,7 @@ void l2cap_connect_cfm(struct hci_conn *hcon, u8 status)
                if (chan) {
                        bacpy(&chan->src, &hcon->src);
                        bacpy(&chan->dst, &hcon->dst);
-                       chan->src_type = bdaddr_type(hcon, hcon->src_type);
+                       chan->src_type = bdaddr_src_type(hcon);
                        chan->dst_type = dst_type;
 
                        __l2cap_chan_add(conn, chan);
@@ -7278,8 +7288,7 @@ void l2cap_connect_cfm(struct hci_conn *hcon, u8 status)
 
                l2cap_chan_unlock(pchan);
 next:
-               next = l2cap_global_fixed_chan(pchan, &hdev->bdaddr,
-                                              hcon->type);
+               next = l2cap_global_fixed_chan(pchan, hcon);
                l2cap_chan_put(pchan);
                pchan = next;
        }
@@ -7527,8 +7536,8 @@ static int l2cap_debugfs_show(struct seq_file *f, void *p)
        read_lock(&chan_list_lock);
 
        list_for_each_entry(c, &chan_list, global_l) {
-               seq_printf(f, "%pMR %pMR %d %d 0x%4.4x 0x%4.4x %d %d %d %d\n",
-                          &c->src, &c->dst,
+               seq_printf(f, "%pMR (%u) %pMR (%u) %d %d 0x%4.4x 0x%4.4x %d %d %d %d\n",
+                          &c->src, c->src_type, &c->dst, c->dst_type,
                           c->state, __le16_to_cpu(c->psm),
                           c->scid, c->dcid, c->imtu, c->omtu,
                           c->sec_level, c->mode);