summaryrefslogtreecommitdiff
path: root/emulator
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2021-07-09 16:34:47 -0700
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2021-07-14 11:37:20 -0700
commit8f30f0837db994473f58a4196831d9993c0fa260 (patch)
tree5446d7b20bffeb118642eac562a28a46a0442a7b /emulator
parenta12c96c2b9fe05a2b514311bc2c4b5f4883fd070 (diff)
downloadbluez-8f30f0837db994473f58a4196831d9993c0fa260.tar.gz
btdev: Add proper checks for own_addr_type for extended advertising
own_addr_type 0x01 and 0x03 shall check that a random address has properly been set and in case of 0x03 the resolving list actually contains the irk of the identity address: BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 4, Part E page 2596 'If the advertising set's Own_Address_Type parameter is set to 0x01 and the random address for the advertising set has not been initialized, the Controller shall return the error code Invalid HCI Command Parameters (0x12).' BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 4, Part E page 2597 'If the advertising set's Own_Address_Type parameter is set to 0x03, the controller's resolving list did not contain a matching entry, and the random address for the advertising set has not been initialized, the Controller shall return the error code Invalid HCI Command Parameters (0x12).'
Diffstat (limited to 'emulator')
-rw-r--r--emulator/btdev.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/emulator/btdev.c b/emulator/btdev.c
index a7fda2c89..90b3d9f31 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -4519,6 +4519,20 @@ static bool ext_adv_timeout(void *user_data)
return false;
}
+static struct btdev_rl *rl_find(struct btdev *dev, uint8_t type, uint8_t *addr)
+{
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(dev->le_rl); i++) {
+ struct btdev_rl *rl = &dev->le_rl[i];
+
+ if (RL_ADDR_EQUAL(rl, type, addr))
+ return rl;
+ }
+
+ return NULL;
+}
+
static int cmd_set_ext_adv_enable(struct btdev *dev, const void *data,
uint8_t len)
{
@@ -4542,6 +4556,7 @@ static int cmd_set_ext_adv_enable(struct btdev *dev, const void *data,
for (i = 0; i < cmd->num_of_sets; i++) {
const struct bt_hci_cmd_ext_adv_set *eas;
struct le_ext_adv *ext_adv;
+ bool random_addr;
eas = data + sizeof(*cmd) + (sizeof(*eas) * i);
@@ -4557,6 +4572,35 @@ static int cmd_set_ext_adv_enable(struct btdev *dev, const void *data,
goto exit_complete;
}
+ random_addr = bacmp((bdaddr_t *)ext_adv->random_addr,
+ BDADDR_ANY);
+
+ /* If the advertising set's Own_Address_Type parameter
+ * is set to 0x01 and the random address for
+ * the advertising set has not been initialized, the
+ * Controller shall return the error code Invalid HCI
+ * Command Parameters (0x12).
+ */
+ if (ext_adv->own_addr_type == 0x01 && !random_addr) {
+ status = BT_HCI_ERR_INVALID_PARAMETERS;
+ goto exit_complete;
+ }
+
+ /* If the advertising set's Own_Address_Type parameter is set
+ * to 0x03, the controller's resolving list did not contain a
+ * matching entry, and the random address for the advertising
+ * set has not been initialized, the Controller shall return the
+ * error code Invalid HCI Command Parameters (0x12).
+ */
+ if (ext_adv->own_addr_type == 0x03 && !random_addr) {
+ if (!dev->le_rl_enable ||
+ !rl_find(dev, ext_adv->direct_addr_type,
+ ext_adv->direct_addr)) {
+ status = BT_HCI_ERR_INVALID_PARAMETERS;
+ goto exit_complete;
+ }
+ }
+
ext_adv->enable = cmd->enable;
if (!cmd->enable)