@@ -90,6 +90,7 @@ int hci_read_clock_sync(struct hci_dev *hdev, struct hci_cp_read_clock *cp);
int hci_write_fast_connectable_sync(struct hci_dev *hdev, bool enable);
int hci_update_scan_sync(struct hci_dev *hdev);
int hci_update_scan(struct hci_dev *hdev);
+int hci_set_random_addr_sync(struct hci_dev *hdev, bdaddr_t *rpa);
int hci_write_le_host_supported_sync(struct hci_dev *hdev, u8 le, u8 simul);
int hci_remove_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance,
@@ -839,7 +839,7 @@ static bool adv_use_rpa(struct hci_dev *hdev, uint32_t flags)
return true;
}
-static int hci_set_random_addr_sync(struct hci_dev *hdev, bdaddr_t *rpa)
+int hci_set_random_addr_sync(struct hci_dev *hdev, bdaddr_t *rpa)
{
/* If we're advertising or initiating an LE connection we can't
* go ahead and change the random address at this time. This is
@@ -6501,10 +6501,28 @@ static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data,
return err;
}
+static int set_addr_sync(struct hci_dev *hdev, void *data)
+{
+ struct mgmt_pending_cmd *cmd = data;
+ struct mgmt_cp_set_static_address *cp = cmd->param;
+
+ return hci_set_random_addr_sync(hdev, &cp->bdaddr);
+}
+
+static void set_addr_complete(struct hci_dev *hdev, void *data, int err)
+{
+ struct mgmt_pending_cmd *cmd = data;
+
+ mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS,
+ mgmt_status(err));
+ mgmt_pending_remove(cmd);
+}
+
static int set_static_address(struct sock *sk, struct hci_dev *hdev,
void *data, u16 len)
{
struct mgmt_cp_set_static_address *cp = data;
+ struct mgmt_pending_cmd *cmd = data;
int err;
bt_dev_dbg(hdev, "sock %p", sk);
@@ -6534,6 +6552,23 @@ static int set_static_address(struct sock *sk, struct hci_dev *hdev,
bacpy(&hdev->static_addr, &cp->bdaddr);
+ cmd = mgmt_pending_add(sk, MGMT_OP_SET_STATIC_ADDRESS, hdev, data, len);
+ if (!cmd)
+ err = -ENOMEM;
+ else
+ err = hci_cmd_sync_queue(hdev, set_addr_sync, cmd,
+ set_addr_complete);
+
+ if (err < 0) {
+ if (cmd)
+ mgmt_pending_remove(cmd);
+
+ mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS,
+ mgmt_status(err));
+
+ goto unlock;
+ }
+
err = send_settings_rsp(sk, MGMT_OP_SET_STATIC_ADDRESS, hdev);
if (err < 0)
goto unlock;
The call to MGMT_OP_SET_STATIC_ADDRESS saved the requested address in the hdev structure, but never wrote that address out to the controller. This adds call to hci_set_random_addr_sync() after it has been validated. Signed-off-by: Brian Gix <brian.gix@intel.com> --- include/net/bluetooth/hci_sync.h | 1 + net/bluetooth/hci_sync.c | 2 +- net/bluetooth/mgmt.c | 35 ++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-)