Bluetooth: Add dst_type parameter to hci_connect
authorAndre Guedes <andre.guedes@openbossa.org>
Wed, 25 Apr 2012 00:02:54 +0000 (21:02 -0300)
committerGustavo Padovan <gustavo@padovan.org>
Wed, 9 May 2012 04:40:45 +0000 (01:40 -0300)
This patch adds the dst_type parameter to hci_connect function.
Instead of searching the address type in advertising cache, we
use the dst_type parameter to establish LE connections.

The dst_type is ignored for BR/EDR connection establishment.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Acked-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
include/net/bluetooth/hci_core.h
net/bluetooth/hci_conn.c
net/bluetooth/l2cap_core.c
net/bluetooth/mgmt.c
net/bluetooth/sco.c

index 7e7fe3f221fb6aa718e2b0ce569bf9dccee4689f..e69a9eed082c97a946d4dabd52a97f10d9274344 100644 (file)
@@ -575,7 +575,7 @@ int hci_chan_del(struct hci_chan *chan);
 void hci_chan_list_flush(struct hci_conn *conn);
 
 struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
-                                               __u8 sec_level, __u8 auth_type);
+                            __u8 dst_type, __u8 sec_level, __u8 auth_type);
 int hci_conn_check_link_mode(struct hci_conn *conn);
 int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level);
 int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type);
index 8f352cd1745a60cc574e2848442ac04785ac54bc..a3ee1a929a6cff8a32fc0a7ac88bcf0859f118da 100644 (file)
@@ -513,7 +513,8 @@ EXPORT_SYMBOL(hci_get_route);
 
 /* Create SCO, ACL or LE connection.
  * Device _must_ be locked */
-struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8 sec_level, __u8 auth_type)
+struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
+                            __u8 dst_type, __u8 sec_level, __u8 auth_type)
 {
        struct hci_conn *acl;
        struct hci_conn *sco;
@@ -522,19 +523,13 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8
        BT_DBG("%s dst %s", hdev->name, batostr(dst));
 
        if (type == LE_LINK) {
-               struct adv_entry *entry = NULL;
-
                le = hci_conn_hash_lookup_ba(hdev, LE_LINK, dst);
                if (!le) {
-                       entry = hci_find_adv_entry(hdev, dst);
-                       if (!entry)
-                               return ERR_PTR(-EHOSTUNREACH);
-
                        le = hci_conn_add(hdev, LE_LINK, dst);
                        if (!le)
                                return ERR_PTR(-ENOMEM);
 
-                       le->dst_type = entry->bdaddr_type;
+                       le->dst_type = bdaddr_to_le(dst_type);
                        hci_le_connect(le);
                }
 
index 97af2b4f62389a070c6a02c45ca1ee070b4afc64..61af06d35335bb0210e974b4fed697bd1969fe6c 100644 (file)
@@ -1479,11 +1479,11 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, bdaddr_t *d
        auth_type = l2cap_get_auth_type(chan);
 
        if (chan->dcid == L2CAP_CID_LE_DATA)
-               hcon = hci_connect(hdev, LE_LINK, dst,
-                                       chan->sec_level, auth_type);
+               hcon = hci_connect(hdev, LE_LINK, dst, BDADDR_LE_RANDOM,
+                                  chan->sec_level, auth_type);
        else
-               hcon = hci_connect(hdev, ACL_LINK, dst,
-                                       chan->sec_level, auth_type);
+               hcon = hci_connect(hdev, ACL_LINK, dst, BDADDR_BREDR,
+                                  chan->sec_level, auth_type);
 
        if (IS_ERR(hcon)) {
                err = PTR_ERR(hcon);
index 4e26c25858171366c3e92877091cd0b998734374..9038118d37a3f32c5d42340fec49c91189a90283 100644 (file)
@@ -1903,11 +1903,11 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
                auth_type = HCI_AT_DEDICATED_BONDING_MITM;
 
        if (cp->addr.type == BDADDR_BREDR)
-               conn = hci_connect(hdev, ACL_LINK, &cp->addr.bdaddr, sec_level,
-                                  auth_type);
+               conn = hci_connect(hdev, ACL_LINK, &cp->addr.bdaddr,
+                                  cp->addr.type, sec_level, auth_type);
        else
-               conn = hci_connect(hdev, LE_LINK, &cp->addr.bdaddr, sec_level,
-                                  auth_type);
+               conn = hci_connect(hdev, LE_LINK, &cp->addr.bdaddr,
+                                  cp->addr.type, sec_level, auth_type);
 
        memset(&rp, 0, sizeof(rp));
        bacpy(&rp.addr.bdaddr, &cp->addr.bdaddr);
index bf1af0b1497ef725564f5a3e206fe36680c3c753..cbdd313659a78f3bf9133d10ee01e487fd2d9053 100644 (file)
@@ -193,7 +193,8 @@ static int sco_connect(struct sock *sk)
        else
                type = SCO_LINK;
 
-       hcon = hci_connect(hdev, type, dst, BT_SECURITY_LOW, HCI_AT_NO_BONDING);
+       hcon = hci_connect(hdev, type, dst, BDADDR_BREDR, BT_SECURITY_LOW,
+                          HCI_AT_NO_BONDING);
        if (IS_ERR(hcon)) {
                err = PTR_ERR(hcon);
                goto done;