aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2016-11-12 10:03:07 -0500
committerMarcel Holtmann <marcel@holtmann.org>2016-11-22 16:50:46 -0500
commit39385cb5f3274735b03ed1f8e7ff517b02a0beed (patch)
tree3c6ec16600b7ec16f3b019bbbdae493de90eefb0
parentc9b8af1330198ae241cd545e1f040019010d44d9 (diff)
Bluetooth: Fix using the correct source address type
The hci_get_route() API is used to look up local HCI devices, however so far it has been incapable of dealing with anything else than the public address of HCI devices. This completely breaks with LE-only HCI devices that do not come with a public address, but use a static random address instead. This patch exteds the hci_get_route() API with a src_type parameter that's used for comparing with the right address of each HCI device. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
-rw-r--r--include/net/bluetooth/hci_core.h2
-rw-r--r--net/bluetooth/6lowpan.c4
-rw-r--r--net/bluetooth/hci_conn.c26
-rw-r--r--net/bluetooth/l2cap_core.c2
-rw-r--r--net/bluetooth/rfcomm/tty.c2
-rw-r--r--net/bluetooth/sco.c2
6 files changed, 30 insertions, 8 deletions
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index f00bf667ec33..554671c81f4a 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1018,7 +1018,7 @@ static inline void hci_set_drvdata(struct hci_dev *hdev, void *data)
1018} 1018}
1019 1019
1020struct hci_dev *hci_dev_get(int index); 1020struct hci_dev *hci_dev_get(int index);
1021struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src); 1021struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src, u8 src_type);
1022 1022
1023struct hci_dev *hci_alloc_dev(void); 1023struct hci_dev *hci_alloc_dev(void);
1024void hci_free_dev(struct hci_dev *hdev); 1024void hci_free_dev(struct hci_dev *hdev);
diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
index d020299baba4..1904a93f47d5 100644
--- a/net/bluetooth/6lowpan.c
+++ b/net/bluetooth/6lowpan.c
@@ -1090,7 +1090,6 @@ static int get_l2cap_conn(char *buf, bdaddr_t *addr, u8 *addr_type,
1090{ 1090{
1091 struct hci_conn *hcon; 1091 struct hci_conn *hcon;
1092 struct hci_dev *hdev; 1092 struct hci_dev *hdev;
1093 bdaddr_t *src = BDADDR_ANY;
1094 int n; 1093 int n;
1095 1094
1096 n = sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx %hhu", 1095 n = sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx %hhu",
@@ -1101,7 +1100,8 @@ static int get_l2cap_conn(char *buf, bdaddr_t *addr, u8 *addr_type,
1101 if (n < 7) 1100 if (n < 7)
1102 return -EINVAL; 1101 return -EINVAL;
1103 1102
1104 hdev = hci_get_route(addr, src); 1103 /* The LE_PUBLIC address type is ignored because of BDADDR_ANY */
1104 hdev = hci_get_route(addr, BDADDR_ANY, BDADDR_LE_PUBLIC);
1105 if (!hdev) 1105 if (!hdev)
1106 return -ENOENT; 1106 return -ENOENT;
1107 1107
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 3809617aa98d..dc59eae54717 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -613,7 +613,7 @@ int hci_conn_del(struct hci_conn *conn)
613 return 0; 613 return 0;
614} 614}
615 615
616struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src) 616struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src, uint8_t src_type)
617{ 617{
618 int use_src = bacmp(src, BDADDR_ANY); 618 int use_src = bacmp(src, BDADDR_ANY);
619 struct hci_dev *hdev = NULL, *d; 619 struct hci_dev *hdev = NULL, *d;
@@ -634,7 +634,29 @@ struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src)
634 */ 634 */
635 635
636 if (use_src) { 636 if (use_src) {
637 if (!bacmp(&d->bdaddr, src)) { 637 bdaddr_t id_addr;
638 u8 id_addr_type;
639
640 if (src_type == BDADDR_BREDR) {
641 if (!lmp_bredr_capable(d))
642 continue;
643 bacpy(&id_addr, &d->bdaddr);
644 id_addr_type = BDADDR_BREDR;
645 } else {
646 if (!lmp_le_capable(d))
647 continue;
648
649 hci_copy_identity_address(d, &id_addr,
650 &id_addr_type);
651
652 /* Convert from HCI to three-value type */
653 if (id_addr_type == ADDR_LE_DEV_PUBLIC)
654 id_addr_type = BDADDR_LE_PUBLIC;
655 else
656 id_addr_type = BDADDR_LE_RANDOM;
657 }
658
659 if (!bacmp(&id_addr, src) && id_addr_type == src_type) {
638 hdev = d; break; 660 hdev = d; break;
639 } 661 }
640 } else { 662 } else {
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index d4cad29b033f..577f1c01454a 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -7060,7 +7060,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
7060 BT_DBG("%pMR -> %pMR (type %u) psm 0x%2.2x", &chan->src, dst, 7060 BT_DBG("%pMR -> %pMR (type %u) psm 0x%2.2x", &chan->src, dst,
7061 dst_type, __le16_to_cpu(psm)); 7061 dst_type, __le16_to_cpu(psm));
7062 7062
7063 hdev = hci_get_route(dst, &chan->src); 7063 hdev = hci_get_route(dst, &chan->src, chan->src_type);
7064 if (!hdev) 7064 if (!hdev)
7065 return -EHOSTUNREACH; 7065 return -EHOSTUNREACH;
7066 7066
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index 8e385a0ae60e..2f2cb5e27cdd 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -178,7 +178,7 @@ static void rfcomm_reparent_device(struct rfcomm_dev *dev)
178 struct hci_dev *hdev; 178 struct hci_dev *hdev;
179 struct hci_conn *conn; 179 struct hci_conn *conn;
180 180
181 hdev = hci_get_route(&dev->dst, &dev->src); 181 hdev = hci_get_route(&dev->dst, &dev->src, BDADDR_BREDR);
182 if (!hdev) 182 if (!hdev)
183 return; 183 return;
184 184
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index f52bcbf2e58c..3125ce670c2f 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -219,7 +219,7 @@ static int sco_connect(struct sock *sk)
219 219
220 BT_DBG("%pMR -> %pMR", &sco_pi(sk)->src, &sco_pi(sk)->dst); 220 BT_DBG("%pMR -> %pMR", &sco_pi(sk)->src, &sco_pi(sk)->dst);
221 221
222 hdev = hci_get_route(&sco_pi(sk)->dst, &sco_pi(sk)->src); 222 hdev = hci_get_route(&sco_pi(sk)->dst, &sco_pi(sk)->src, BDADDR_BREDR);
223 if (!hdev) 223 if (!hdev)
224 return -EHOSTUNREACH; 224 return -EHOSTUNREACH;
225 225