Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1370386rwb; Fri, 7 Oct 2022 11:34:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5INQob5wo367rUt0hNhiwAri5MKB9O3p+LtL4P/xCE4Llc9M/WV1DhgfxrHvk4iFrAnFhu X-Received: by 2002:a17:906:ee89:b0:73d:70c5:1a4e with SMTP id wt9-20020a170906ee8900b0073d70c51a4emr4963239ejb.683.1665167697898; Fri, 07 Oct 2022 11:34:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665167697; cv=none; d=google.com; s=arc-20160816; b=JGX8e+ikSE6WOv+Ktzrg3yIVFwwxVJULqeMDLuMcKrBGsKW7SlHEY09CfF+x0TWQ/b T4y+EhOwyM1AdHaYjJL8JX53jHocbV4gxXrX1RPD1y+x42PjK5aGFwibeMddLtRl9AFq +ynwZpqgyi5ivCfcNtE81F6WSsDuoNAmUPb1kJ5dthe6ojbnN2vmTxF4VFVxeKnlTPIv 4t8bZzqQtrU+YCgJ48SSiOPG8sr3i5Rr+GySpvyhKWeMMmcg9HDZzlx4HibfmJyX2YI0 d4TfZnNFxBz0tFSAS5H3hF5IwcK3xjIgpygZe7upOWNfXz8Rckvr+E1xswtqITqkh+pA Vemg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=649AzI6L0fJ64vMhOS94Kp4axxpb/XKD3MPfodRM8Aw=; b=Zn2LDVppL46VrAo1Ksx1F61fpPdH4T50hwU7e8VJp/Gc+CJHB7NNgXiOH9uJ9cockZ jHvpVelNwq1FwBK7I4Bp1AetoUU0+HlJl0HWWb5x58o7lRLchu9iumA1lZYhQ2TlI040 jTXVxia8i8GeBKsPfYuGM9BKyyiOLHqthCqD5EcTf/x3RT2CUWRkJXaRrJQQsA1dYSab MrQp9hsLqz4CtoufFq0wFZcMtLVxzJL+E0wYcKMZMwGzn+EmbOLia81sZtXOZCcQ8ne9 SMGhalJWWhroXnFAXVPabIEGIxs5L2+BrkExYDHu8WvNSMw9zffzhPM9XvyMbCnV7Zpx CAjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fyOuqPoV; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e11-20020a17090658cb00b00741a19c2151si2586101ejs.625.2022.10.07.11.34.31; Fri, 07 Oct 2022 11:34:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fyOuqPoV; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229539AbiJGSea (ORCPT + 99 others); Fri, 7 Oct 2022 14:34:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbiJGSe3 (ORCPT ); Fri, 7 Oct 2022 14:34:29 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B59773BC59 for ; Fri, 7 Oct 2022 11:34:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665167668; x=1696703668; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=tKlm9F7hAK5IstbcuPpLC0qmukg7SZj7Q/CjhkYE0ek=; b=fyOuqPoV/XS15huyg7WaVtlFdhEINhFNz9zwuCSw4Zp1AQ02YETUK45J iumpQ+zAHzQiimEtkQLS5WvkWIlzfvUZgKkw+CpKp9LL/OawSkUcELttY tcDbScLJc9i8pxL7ut3fOltZqC8yqMccDP6FFMQcJJjBSBjxGwj73eObQ D9WI+bzbUYPHTP6vvbVVjiLC4ZtcmDokP9HwQWb+6OU1cztROjPflrO/u RNpjfe1I/Tnv/QLqMyLHOF4yR3g4xKWb0vkPsnIRuz3cr7C0x6pxcVorH veC+90PzmN0xr5SgfXe2Wq6uL/n8tMozaCzZ7wJVw1a6T9te8bZT1LqY0 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10493"; a="390099865" X-IronPort-AV: E=Sophos;i="5.95,167,1661842800"; d="scan'208";a="390099865" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2022 11:34:28 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10493"; a="627542683" X-IronPort-AV: E=Sophos;i="5.95,167,1661842800"; d="scan'208";a="627542683" Received: from msislam-mobl1.amr.corp.intel.com (HELO bgi1-mobl2.amr.corp.intel.com) ([10.212.13.154]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2022 11:34:28 -0700 From: Brian Gix To: linux-bluetooth@vger.kernel.org Cc: luiz.dentz@gmail.com, brian.gix@intel.com Subject: [PATCH v2] Bluetooth: Call HCI cmd to set random addr during MGMT call Date: Fri, 7 Oct 2022 11:34:20 -0700 Message-Id: <20221007183420.797070-1-brian.gix@intel.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org 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 --- 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(-) diff --git a/include/net/bluetooth/hci_sync.h b/include/net/bluetooth/hci_sync.h index 17f5a4c32f36..24864672d12c 100644 --- a/include/net/bluetooth/hci_sync.h +++ b/include/net/bluetooth/hci_sync.h @@ -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, diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 76c3107c9f91..e1e3658a6e19 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -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 diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index a92e7e485feb..990ab0f6414a 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -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_free(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_new(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_free(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; -- 2.37.3