summaryrefslogtreecommitdiff
path: root/emulator
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2021-07-16 13:27:16 -0700
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2021-07-19 14:16:16 -0700
commit0f849abb1b090257370225a0d6bfa4b2d4871ca5 (patch)
tree3342f3dfbb1483bb2e6f3ebfdc4fda1b7800a87a /emulator
parent0356d2a4c690bbd50c307cf795ccc047accd3d65 (diff)
downloadbluez-0f849abb1b090257370225a0d6bfa4b2d4871ca5.tar.gz
btdev: Fix not checking conditions for LE Set Random Address
The spec says LE Set Random Address cannot be used when scan is enabled or with legacy advertising: BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 4, Part E page 2480 'If the Host issues this command when any of advertising (created using legacy advertising commands), scanning, or initiating are enabled, the Controller shall return the error code Command Disallowed (0x0C).'
Diffstat (limited to 'emulator')
-rw-r--r--emulator/btdev.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/emulator/btdev.c b/emulator/btdev.c
index 7f4386e80..c9ec22ebe 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -2998,8 +2998,21 @@ static int cmd_set_random_address(struct btdev *dev, const void *data,
const struct bt_hci_cmd_le_set_random_address *cmd = data;
uint8_t status;
+ /* If the Host issues this command when any of advertising
+ * (created using legacy advertising commands), scanning, or initiating
+ * are enabled, the Controller shall return the error code
+ * Command Disallowed (0x0C).
+ */
+ if (dev->le_scan_enable || (dev->le_adv_enable &&
+ queue_isempty(dev->le_ext_adv))) {
+ status = BT_HCI_ERR_COMMAND_DISALLOWED;
+ goto done;
+ }
+
memcpy(dev->random_addr, cmd->addr, 6);
status = BT_HCI_ERR_SUCCESS;
+
+done:
cmd_complete(dev, BT_HCI_CMD_LE_SET_RANDOM_ADDRESS, &status,
sizeof(status));