Skip to content

Commit

Permalink
Bluetooth: Host: Map HCI cmd disallowed to errno
Browse files Browse the repository at this point in the history
Make `bt_hci_cmd_send_sync` return `-EACCES` when receiving
`BT_HCI_ERR_CMD_DISALLOWED`.

Update some tests that were expecting `-EIO` when
getting `BT_HCI_ERR_CMD_DISALLOWED`.

Add a warning in `set_random_address` when getting that new error. This
is done in case someone try to set a new random address while legacy
advertising, scanning or initiating is enabled. This is illegal behavior
according to the Core Spec (see Vol 4, Part E 7.8.4).

Signed-off-by: Théo Battrel <[email protected]>
  • Loading branch information
theob-pro authored and jhedberg committed May 10, 2024
1 parent 2c6306d commit 76559f2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions subsys/bluetooth/host/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ int bt_hci_cmd_send_sync(uint16_t opcode, struct net_buf *buf,
return -ENOMEM;
case BT_HCI_ERR_INVALID_PARAM:
return -EINVAL;
case BT_HCI_ERR_CMD_DISALLOWED:
return -EACCES;
default:
return -EIO;
}
Expand Down
9 changes: 9 additions & 0 deletions subsys/bluetooth/host/id.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ static int set_random_address(const bt_addr_t *addr)

err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_SET_RANDOM_ADDRESS, buf, NULL);
if (err) {
if (err == -EACCES) {
/* If we are here we probably tried to set a random
* address while a legacy advertising, scanning or
* initiating is enabled, this is illegal.
*
* See Core Spec @ Vol 4, Part E 7.8.4
*/
LOG_WRN("cmd disallowed");
}
return err;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ ZTEST(test_hci_set_conn_cte_rx_params_with_conn_set,
int err;

err = send_conn_cte_req_enable(g_conn_handle, &g_data, true);
zassert_equal(err, -EIO,
zassert_equal(err, -EACCES,
"Unexpected error value for CTE request enable before set rx params");
}

Expand All @@ -109,7 +109,7 @@ ZTEST(test_hci_set_conn_cte_rx_params_with_rx_param_set,
g_data.cte_request_interval = REQUEST_INTERVAL_TOO_LOW;

err = send_conn_cte_req_enable(g_conn_handle, &g_data, true);
zassert_equal(err, -EIO,
zassert_equal(err, -EACCES,
"Unexpected error value for CTE request enable with too short request"
" interval");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ZTEST(test_set_cl_cte_tx_enable, test_set_cl_cte_tx_enable_cte_params_not_set)

/* test logic */
err = send_set_cl_cte_tx_enable(g_adv->handle, g_adv->flags, true);
zassert_equal(err, -EIO, "Unexpected error value for enable CTE before "
zassert_equal(err, -EACCES, "Unexpected error value for enable CTE before "
"CTE params set");

/* clean up */
Expand All @@ -90,7 +90,7 @@ ZTEST(test_set_cl_cte_tx_enable, test_set_cl_cte_tx_enable_per_adv_coded_phy)

/* test logic */
err = send_set_cl_cte_tx_enable(g_adv->handle, g_adv->flags, true);
zassert_equal(err, -EIO, "Unexpected error value for enable CTE for "
zassert_equal(err, -EACCES, "Unexpected error value for enable CTE for "
"coded PHY");

/* clean up */
Expand Down Expand Up @@ -151,7 +151,7 @@ ZTEST(test_set_cl_cte_tx_enable, test_set_cl_cte_tx_disable_when_no_CTE_enabled)

/* test logic */
err = send_set_cl_cte_tx_enable(g_adv->handle, g_adv->flags, false);
zassert_equal(err, -EIO, "Unexpected error value for disable CTE "
zassert_equal(err, -EACCES, "Unexpected error value for disable CTE "
"before CTE enable");

/* clean up */
Expand Down

0 comments on commit 76559f2

Please sign in to comment.