btdev: Fix not checking conditions for LE Set Random Address
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Fri, 16 Jul 2021 20:27:16 +0000 (13:27 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:36 +0000 (19:08 +0530)
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).'

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
emulator/btdev.c

index 7f4386e..c9ec22e 100755 (executable)
@@ -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));