From 0f849abb1b090257370225a0d6bfa4b2d4871ca5 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 16 Jul 2021 13:27:16 -0700 Subject: [PATCH] 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).' --- emulator/btdev.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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)); -- 2.47.3