Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: f5ad4ffceba0 ("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>

authored by

Pauli Virtanen and committed by
Luiz Augusto von Dentz
b454505b 3b78f509

+24 -4
+24 -4
net/bluetooth/6lowpan.c
··· 957 957 } 958 958 959 959 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) 961 961 { 962 962 struct hci_conn *hcon; 963 963 struct hci_dev *hdev; 964 + int le_addr_type; 964 965 int n; 965 966 966 967 n = sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx %hhu", ··· 972 971 if (n < 7) 973 972 return -EINVAL; 974 973 974 + if (disconnect) { 975 + /* The "disconnect" debugfs command has used different address 976 + * type constants than "connect" since 2015. Let's retain that 977 + * for now even though it's obviously buggy... 978 + */ 979 + *addr_type += 1; 980 + } 981 + 982 + switch (*addr_type) { 983 + case BDADDR_LE_PUBLIC: 984 + le_addr_type = ADDR_LE_DEV_PUBLIC; 985 + break; 986 + case BDADDR_LE_RANDOM: 987 + le_addr_type = ADDR_LE_DEV_RANDOM; 988 + break; 989 + default: 990 + return -EINVAL; 991 + } 992 + 975 993 /* The LE_PUBLIC address type is ignored because of BDADDR_ANY */ 976 994 hdev = hci_get_route(addr, BDADDR_ANY, BDADDR_LE_PUBLIC); 977 995 if (!hdev) 978 996 return -ENOENT; 979 997 980 998 hci_dev_lock(hdev); 981 - hcon = hci_conn_hash_lookup_le(hdev, addr, *addr_type); 999 + hcon = hci_conn_hash_lookup_le(hdev, addr, le_addr_type); 982 1000 hci_dev_unlock(hdev); 983 1001 hci_dev_put(hdev); 984 1002 ··· 1124 1104 buf[buf_size] = '\0'; 1125 1105 1126 1106 if (memcmp(buf, "connect ", 8) == 0) { 1127 - ret = get_l2cap_conn(&buf[8], &addr, &addr_type, &conn); 1107 + ret = get_l2cap_conn(&buf[8], &addr, &addr_type, &conn, false); 1128 1108 if (ret == -EINVAL) 1129 1109 return ret; 1130 1110 ··· 1161 1141 } 1162 1142 1163 1143 if (memcmp(buf, "disconnect ", 11) == 0) { 1164 - ret = get_l2cap_conn(&buf[11], &addr, &addr_type, &conn); 1144 + ret = get_l2cap_conn(&buf[11], &addr, &addr_type, &conn, true); 1165 1145 if (ret < 0) 1166 1146 return ret; 1167 1147