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 <joakim.andersson@nordicsemi.no>
This commit is contained in:
Joakim Andersson 2020-12-11 13:48:00 +01:00 committed by Carles Cufí
commit 39e14580e9

View file

@ -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;