Skip to content

Commit b454505

Browse files
pvVudentz
authored andcommitted
Bluetooth: 6lowpan: fix BDADDR_LE vs ADDR_LE_DEV address type confusion
Bluetooth 6lowpan.c confuses BDADDR_LE and ADDR_LE_DEV address types, e.g. debugfs "connect" command takes the former, and "disconnect" and "connect" to already connected device take the latter. This is due to using same value both for l2cap_chan_connect and hci_conn_hash_lookup_le which take different dst_type values. Fix address type passed to hci_conn_hash_lookup_le(). Retain the debugfs API difference between "connect" and "disconnect" commands since it's been like this since 2015 and nobody apparently complained. Fixes: f5ad4ff ("Bluetooth: 6lowpan: Use hci_conn_hash_lookup_le() when possible") Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de> Signed-off-by: Pauli Virtanen <pav@iki.fi> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
1 parent 3b78f50 commit b454505

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

net/bluetooth/6lowpan.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -957,10 +957,11 @@ static struct l2cap_chan *bt_6lowpan_listen(void)
957957
}
958958

959959
static int get_l2cap_conn(char *buf, bdaddr_t *addr, u8 *addr_type,
960-
struct l2cap_conn **conn)
960+
struct l2cap_conn **conn, bool disconnect)
961961
{
962962
struct hci_conn *hcon;
963963
struct hci_dev *hdev;
964+
int le_addr_type;
964965
int n;
965966

966967
n = sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx %hhu",
@@ -971,13 +972,32 @@ static int get_l2cap_conn(char *buf, bdaddr_t *addr, u8 *addr_type,
971972
if (n < 7)
972973
return -EINVAL;
973974

975+
if (disconnect) {
976+
/* The "disconnect" debugfs command has used different address
977+
* type constants than "connect" since 2015. Let's retain that
978+
* for now even though it's obviously buggy...
979+
*/
980+
*addr_type += 1;
981+
}
982+
983+
switch (*addr_type) {
984+
case BDADDR_LE_PUBLIC:
985+
le_addr_type = ADDR_LE_DEV_PUBLIC;
986+
break;
987+
case BDADDR_LE_RANDOM:
988+
le_addr_type = ADDR_LE_DEV_RANDOM;
989+
break;
990+
default:
991+
return -EINVAL;
992+
}
993+
974994
/* The LE_PUBLIC address type is ignored because of BDADDR_ANY */
975995
hdev = hci_get_route(addr, BDADDR_ANY, BDADDR_LE_PUBLIC);
976996
if (!hdev)
977997
return -ENOENT;
978998

979999
hci_dev_lock(hdev);
980-
hcon = hci_conn_hash_lookup_le(hdev, addr, *addr_type);
1000+
hcon = hci_conn_hash_lookup_le(hdev, addr, le_addr_type);
9811001
hci_dev_unlock(hdev);
9821002
hci_dev_put(hdev);
9831003

@@ -1104,7 +1124,7 @@ static ssize_t lowpan_control_write(struct file *fp,
11041124
buf[buf_size] = '\0';
11051125

11061126
if (memcmp(buf, "connect ", 8) == 0) {
1107-
ret = get_l2cap_conn(&buf[8], &addr, &addr_type, &conn);
1127+
ret = get_l2cap_conn(&buf[8], &addr, &addr_type, &conn, false);
11081128
if (ret == -EINVAL)
11091129
return ret;
11101130

@@ -1141,7 +1161,7 @@ static ssize_t lowpan_control_write(struct file *fp,
11411161
}
11421162

11431163
if (memcmp(buf, "disconnect ", 11) == 0) {
1144-
ret = get_l2cap_conn(&buf[11], &addr, &addr_type, &conn);
1164+
ret = get_l2cap_conn(&buf[11], &addr, &addr_type, &conn, true);
11451165
if (ret < 0)
11461166
return ret;
11471167

0 commit comments

Comments
 (0)