From 39e14580e9ae8ced9bda2b619b21348b159bf36e Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Fri, 11 Dec 2020 13:48:00 +0100 Subject: [PATCH] Bluetooth: controller: Validate disconnect reason in disconnect command Validate the disconnect reason in the disconnect command, according to the the core specification. 7.1.6 Disconnect command: Authentication Failure error code (0x05), Other End Terminated Connec- tion error codes (0x13 to 0x15), Unsupported Remote Feature error code (0x1A), Pairing with Unit Key Not Supported error code (0x29) and Unac- ceptable Connection Parameters error code (0x3B). Signed-off-by: Joakim Andersson --- subsys/bluetooth/controller/ll_sw/ull_conn.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn.c b/subsys/bluetooth/controller/ll_sw/ull_conn.c index 1e5e4a03fac..23356502b4a 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn.c @@ -410,10 +410,30 @@ uint8_t ll_chm_get(uint16_t handle, uint8_t *chm) return 0; } +static bool is_valid_disconnect_reason(uint8_t reason) +{ + switch (reason) { + case BT_HCI_ERR_AUTH_FAIL: + case BT_HCI_ERR_REMOTE_USER_TERM_CONN: + case BT_HCI_ERR_REMOTE_LOW_RESOURCES: + case BT_HCI_ERR_REMOTE_POWER_OFF: + case BT_HCI_ERR_UNSUPP_REMOTE_FEATURE: + case BT_HCI_ERR_PAIRING_NOT_SUPPORTED: + case BT_HCI_ERR_UNACCEPT_CONN_PARAM: + return true; + default: + return false; + } +} + uint8_t ll_terminate_ind_send(uint16_t handle, uint8_t reason) { struct ll_conn *conn; + if (!is_valid_disconnect_reason(reason)) { + return BT_HCI_ERR_INVALID_PARAM; + } + conn = ll_connected_get(handle); if (!conn) { return BT_HCI_ERR_UNKNOWN_CONN_ID;