linux/net/bluetooth
Mikhail Gavrilov c1cec2bbbe Bluetooth: mgmt: Translate HCI reason in Device Disconnected event
MGMT_EV_DEVICE_DISCONNECTED carries a reason field which is defined to
be one of MGMT_DEV_DISCONN_* (0x00..0x05). hci_disconn_complete_evt()
converts the HCI error with hci_to_mgmt_reason(), but two other paths
pass the raw HCI error straight through:

  hci_cs_disconnect()   -> cp->reason
  mgmt_connect_failed() -> status

The latter is reached whenever the adapter is powered off or suspended:
hci_disconnect_all_sync() aborts every link with
HCI_ERROR_REMOTE_POWER_OFF, hci_disconnect_sync() deliberately does not
wait for HCI_EV_DISCONN_COMPLETE for that reason, so that
hci_abort_conn_sync() finishes the connection off through
hci_conn_failed() instead.

As a result userspace sees an out of range reason:

  @ MGMT Event: Device Disconnected (0x000c) plen 8
        BR/EDR Address: 8C:A9:6F:2C:51:46
        Reason: Reserved (0x15)

  bluetoothd: btd_bearer_disconnected() Unknown disconnection value: 21
  bluetoothd: device_disconnected() Unknown disconnection value: 21

Export hci_to_mgmt_reason() and use it in both places, so that a power
off is reported as MGMT_DEV_DISCONN_REMOTE rather than as the raw
HCI_ERROR_REMOTE_POWER_OFF (0x15).

Fixes: d47da6bd4c ("Bluetooth: hci_core: Fix sending MGMT_EV_CONNECT_FAILED")
Fixes: 182ee45da0 ("Bluetooth: hci_sync: Rework hci_suspend_notifier")
Signed-off-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2026-07-13 10:10:13 -04:00
..
bnep Bluetooth: bnep: pin L2CAP connection during netdev registration 2026-07-06 10:46:57 -04:00
hidp Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
rfcomm Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
6lowpan.c Bluetooth: L2CAP: Fix use-after-free in l2cap_sock_new_connection_cb() 2026-07-06 10:46:58 -04:00
af_bluetooth.c Bluetooth: fix UAF in bt_accept_dequeue() 2026-07-06 10:46:57 -04:00
aosp.c Bluetooth: aosp: Fix typo in comment 2025-07-23 10:30:18 -04:00
aosp.h Bluetooth: aosp: Support AOSP Bluetooth Quality Report 2021-11-02 19:37:52 +01:00
coredump.c Bluetooth: hci_devcd_dump: fix out-of-bounds via dev_coredumpv 2025-07-23 10:33:57 -04:00
ecdh_helper.c Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
ecdh_helper.h Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
eir.c Bluetooth: eir: Fix stack OOB write when prepending the Flags AD 2026-06-11 14:24:40 -04:00
eir.h Bluetooth: eir: Fix possible crashes on eir_create_adv_data 2025-06-11 16:29:22 -04:00
hci_codec.c Bluetooth: hci: validate codec capability element length 2026-06-11 14:24:41 -04:00
hci_codec.h Bluetooth: Add support for Read Local Supported Codecs V2 2021-09-07 14:09:18 -07:00
hci_conn.c Bluetooth: hci_conn: Fix null ptr deref in hci_abort_conn() 2026-07-06 10:46:57 -04:00
hci_core.c Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
hci_debugfs.c Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
hci_debugfs.h Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
hci_drv.c Bluetooth: Introduce HCI Driver protocol 2025-05-21 10:28:07 -04:00
hci_event.c Bluetooth: mgmt: Translate HCI reason in Device Disconnected event 2026-07-13 10:10:13 -04:00
hci_sock.c Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
hci_sync.c Bluetooth: hci_sync: hold hdev->lock for hci_conn_params lookups 2026-07-13 10:09:31 -04:00
hci_sysfs.c Bluetooth: fix memory leak in error path of hci_alloc_dev() 2026-06-03 11:22:28 -04:00
iso.c Bluetooth: ISO: fix malformed ISO_END/CONT handling 2026-07-06 10:46:58 -04:00
Kconfig Bluetooth: SMP: Use AES-CMAC library API 2026-06-11 14:24:38 -04:00
l2cap_core.c Bluetooth: L2CAP: fix tx ident leak for commands without a response 2026-07-06 10:46:58 -04:00
l2cap_sock.c Bluetooth: L2CAP: Fix use-after-free in l2cap_sock_new_connection_cb() 2026-07-06 10:46:58 -04:00
leds.c Bluetooth: Use led_set_brightness() in LED trigger activate() callback 2024-09-10 13:06:11 -04:00
leds.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
lib.c Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
Makefile net: remove ISDN subsystem and Bluetooth CMTP 2026-04-23 10:24:02 -07:00
mgmt_config.c Bluetooth: mgmt: Add idle_timeout to configurable system parameters 2026-01-29 13:24:22 -05:00
mgmt_config.h Bluetooth: mgmt: Add commands for runtime configuration 2020-06-18 13:11:03 +03:00
mgmt_util.c Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
mgmt_util.h Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
mgmt.c Bluetooth: mgmt: Translate HCI reason in Device Disconnected event 2026-07-13 10:10:13 -04:00
msft.c Bluetooth: MGMT: Fix adv monitor add failure cleanup 2026-07-06 10:46:57 -04:00
msft.h Bluetooth: msft: fix slab-use-after-free in msft_do_close() 2024-05-03 13:05:28 -04:00
sco.c Bluetooth: sco: Fix a race condition in sco_sock_timeout() 2026-07-06 10:46:57 -04:00
selftest.c Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
selftest.h Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00
smp.c Bluetooth: L2CAP: Fix use-after-free in l2cap_sock_new_connection_cb() 2026-07-06 10:46:58 -04:00
smp.h Bluetooth: Add SPDX id lines to some source files 2026-06-11 14:24:41 -04:00