Bluetooth: move hci_get_random_address() to hci_sync
authorBrian Gix <brian.gix@intel.com>
Fri, 5 Aug 2022 23:42:34 +0000 (16:42 -0700)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Thu, 25 Aug 2022 23:20:11 +0000 (16:20 -0700)
This function has no dependencies on the deprecated hci_request
mechanism, so has been moved unchanged to hci_sync.c

Signed-off-by: Brian Gix <brian.gix@intel.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
include/net/bluetooth/hci_sync.h
net/bluetooth/hci_request.c
net/bluetooth/hci_request.h
net/bluetooth/hci_sync.c

index aea950440b9dad27809e389bb5a4350cf6f333cd..b6b975c2ed3ebf8f1e3544fafdab56123e2e1e55 100644 (file)
@@ -16,6 +16,7 @@ struct hci_cmd_sync_work_entry {
        hci_cmd_sync_work_destroy_t destroy;
 };
 
+struct adv_info;
 /* Function with sync suffix shall not be called with hdev->lock held as they
  * wait the command to complete and in the meantime an event could be received
  * which could attempt to acquire hdev->lock causing a deadlock.
@@ -51,6 +52,10 @@ int hci_update_class_sync(struct hci_dev *hdev);
 int hci_update_name_sync(struct hci_dev *hdev);
 int hci_write_ssp_mode_sync(struct hci_dev *hdev, u8 mode);
 
+int hci_get_random_address(struct hci_dev *hdev, bool require_privacy,
+                          bool use_rpa, struct adv_info *adv_instance,
+                          u8 *own_addr_type, bdaddr_t *rand_addr);
+
 int hci_update_random_address_sync(struct hci_dev *hdev, bool require_privacy,
                                   bool rpa, u8 *own_addr_type);
 
index 685dc0f983b78798d80b7e8a7a7ef7840e1bd97e..b9875224ac7bcb35c1a5bab291238936336e72d7 100644 (file)
@@ -650,6 +650,96 @@ static inline bool hci_is_le_conn_scanning(struct hci_dev *hdev)
        return false;
 }
 
+static void set_random_addr(struct hci_request *req, bdaddr_t *rpa);
+static int hci_update_random_address(struct hci_request *req,
+                                    bool require_privacy, bool use_rpa,
+                                    u8 *own_addr_type)
+{
+       struct hci_dev *hdev = req->hdev;
+       int err;
+
+       /* If privacy is enabled use a resolvable private address. If
+        * current RPA has expired or there is something else than
+        * the current RPA in use, then generate a new one.
+        */
+       if (use_rpa) {
+               /* If Controller supports LL Privacy use own address type is
+                * 0x03
+                */
+               if (use_ll_privacy(hdev))
+                       *own_addr_type = ADDR_LE_DEV_RANDOM_RESOLVED;
+               else
+                       *own_addr_type = ADDR_LE_DEV_RANDOM;
+
+               if (rpa_valid(hdev))
+                       return 0;
+
+               err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa);
+               if (err < 0) {
+                       bt_dev_err(hdev, "failed to generate new RPA");
+                       return err;
+               }
+
+               set_random_addr(req, &hdev->rpa);
+
+               return 0;
+       }
+
+       /* In case of required privacy without resolvable private address,
+        * use an non-resolvable private address. This is useful for active
+        * scanning and non-connectable advertising.
+        */
+       if (require_privacy) {
+               bdaddr_t nrpa;
+
+               while (true) {
+                       /* The non-resolvable private address is generated
+                        * from random six bytes with the two most significant
+                        * bits cleared.
+                        */
+                       get_random_bytes(&nrpa, 6);
+                       nrpa.b[5] &= 0x3f;
+
+                       /* The non-resolvable private address shall not be
+                        * equal to the public address.
+                        */
+                       if (bacmp(&hdev->bdaddr, &nrpa))
+                               break;
+               }
+
+               *own_addr_type = ADDR_LE_DEV_RANDOM;
+               set_random_addr(req, &nrpa);
+               return 0;
+       }
+
+       /* If forcing static address is in use or there is no public
+        * address use the static address as random address (but skip
+        * the HCI command if the current random address is already the
+        * static one.
+        *
+        * In case BR/EDR has been disabled on a dual-mode controller
+        * and a static address has been configured, then use that
+        * address instead of the public BR/EDR address.
+        */
+       if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) ||
+           !bacmp(&hdev->bdaddr, BDADDR_ANY) ||
+           (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) &&
+            bacmp(&hdev->static_addr, BDADDR_ANY))) {
+               *own_addr_type = ADDR_LE_DEV_RANDOM;
+               if (bacmp(&hdev->static_addr, &hdev->random_addr))
+                       hci_req_add(req, HCI_OP_LE_SET_RANDOM_ADDR, 6,
+                                   &hdev->static_addr);
+               return 0;
+       }
+
+       /* Neither privacy nor static address is being used so use a
+        * public address.
+        */
+       *own_addr_type = ADDR_LE_DEV_PUBLIC;
+
+       return 0;
+}
+
 /* Ensure to call hci_req_add_le_scan_disable() first to disable the
  * controller based address resolution to be able to reconfigure
  * resolving list.
@@ -859,79 +949,6 @@ static void interleave_scan_work(struct work_struct *work)
                                   &hdev->interleave_scan, timeout);
 }
 
-int hci_get_random_address(struct hci_dev *hdev, bool require_privacy,
-                          bool use_rpa, struct adv_info *adv_instance,
-                          u8 *own_addr_type, bdaddr_t *rand_addr)
-{
-       int err;
-
-       bacpy(rand_addr, BDADDR_ANY);
-
-       /* If privacy is enabled use a resolvable private address. If
-        * current RPA has expired then generate a new one.
-        */
-       if (use_rpa) {
-               /* If Controller supports LL Privacy use own address type is
-                * 0x03
-                */
-               if (use_ll_privacy(hdev))
-                       *own_addr_type = ADDR_LE_DEV_RANDOM_RESOLVED;
-               else
-                       *own_addr_type = ADDR_LE_DEV_RANDOM;
-
-               if (adv_instance) {
-                       if (adv_rpa_valid(adv_instance))
-                               return 0;
-               } else {
-                       if (rpa_valid(hdev))
-                               return 0;
-               }
-
-               err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa);
-               if (err < 0) {
-                       bt_dev_err(hdev, "failed to generate new RPA");
-                       return err;
-               }
-
-               bacpy(rand_addr, &hdev->rpa);
-
-               return 0;
-       }
-
-       /* In case of required privacy without resolvable private address,
-        * use an non-resolvable private address. This is useful for
-        * non-connectable advertising.
-        */
-       if (require_privacy) {
-               bdaddr_t nrpa;
-
-               while (true) {
-                       /* The non-resolvable private address is generated
-                        * from random six bytes with the two most significant
-                        * bits cleared.
-                        */
-                       get_random_bytes(&nrpa, 6);
-                       nrpa.b[5] &= 0x3f;
-
-                       /* The non-resolvable private address shall not be
-                        * equal to the public address.
-                        */
-                       if (bacmp(&hdev->bdaddr, &nrpa))
-                               break;
-               }
-
-               *own_addr_type = ADDR_LE_DEV_RANDOM;
-               bacpy(rand_addr, &nrpa);
-
-               return 0;
-       }
-
-       /* No privacy so use a public address. */
-       *own_addr_type = ADDR_LE_DEV_PUBLIC;
-
-       return 0;
-}
-
 static void set_random_addr(struct hci_request *req, bdaddr_t *rpa)
 {
        struct hci_dev *hdev = req->hdev;
@@ -956,96 +973,8 @@ static void set_random_addr(struct hci_request *req, bdaddr_t *rpa)
        hci_req_add(req, HCI_OP_LE_SET_RANDOM_ADDR, 6, rpa);
 }
 
-int hci_update_random_address(struct hci_request *req, bool require_privacy,
-                             bool use_rpa, u8 *own_addr_type)
-{
-       struct hci_dev *hdev = req->hdev;
-       int err;
-
-       /* If privacy is enabled use a resolvable private address. If
-        * current RPA has expired or there is something else than
-        * the current RPA in use, then generate a new one.
-        */
-       if (use_rpa) {
-               /* If Controller supports LL Privacy use own address type is
-                * 0x03
-                */
-               if (use_ll_privacy(hdev))
-                       *own_addr_type = ADDR_LE_DEV_RANDOM_RESOLVED;
-               else
-                       *own_addr_type = ADDR_LE_DEV_RANDOM;
-
-               if (rpa_valid(hdev))
-                       return 0;
-
-               err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa);
-               if (err < 0) {
-                       bt_dev_err(hdev, "failed to generate new RPA");
-                       return err;
-               }
-
-               set_random_addr(req, &hdev->rpa);
-
-               return 0;
-       }
-
-       /* In case of required privacy without resolvable private address,
-        * use an non-resolvable private address. This is useful for active
-        * scanning and non-connectable advertising.
-        */
-       if (require_privacy) {
-               bdaddr_t nrpa;
-
-               while (true) {
-                       /* The non-resolvable private address is generated
-                        * from random six bytes with the two most significant
-                        * bits cleared.
-                        */
-                       get_random_bytes(&nrpa, 6);
-                       nrpa.b[5] &= 0x3f;
-
-                       /* The non-resolvable private address shall not be
-                        * equal to the public address.
-                        */
-                       if (bacmp(&hdev->bdaddr, &nrpa))
-                               break;
-               }
-
-               *own_addr_type = ADDR_LE_DEV_RANDOM;
-               set_random_addr(req, &nrpa);
-               return 0;
-       }
-
-       /* If forcing static address is in use or there is no public
-        * address use the static address as random address (but skip
-        * the HCI command if the current random address is already the
-        * static one.
-        *
-        * In case BR/EDR has been disabled on a dual-mode controller
-        * and a static address has been configured, then use that
-        * address instead of the public BR/EDR address.
-        */
-       if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) ||
-           !bacmp(&hdev->bdaddr, BDADDR_ANY) ||
-           (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) &&
-            bacmp(&hdev->static_addr, BDADDR_ANY))) {
-               *own_addr_type = ADDR_LE_DEV_RANDOM;
-               if (bacmp(&hdev->static_addr, &hdev->random_addr))
-                       hci_req_add(req, HCI_OP_LE_SET_RANDOM_ADDR, 6,
-                                   &hdev->static_addr);
-               return 0;
-       }
-
-       /* Neither privacy nor static address is being used so use a
-        * public address.
-        */
-       *own_addr_type = ADDR_LE_DEV_PUBLIC;
-
-       return 0;
-}
-
-void __hci_abort_conn(struct hci_request *req, struct hci_conn *conn,
-                     u8 reason)
+static void __hci_abort_conn(struct hci_request *req, struct hci_conn *conn,
+                            u8 reason)
 {
        switch (conn->state) {
        case BT_CONNECTED:
index 55205cc9f28194d1f5a61917648a4008abc90dd4..c7185ad77c6e01a11a8ecaef24637f1fc530bf75 100644 (file)
@@ -74,16 +74,7 @@ void hci_req_add_le_passive_scan(struct hci_request *req);
 void hci_req_prepare_suspend(struct hci_dev *hdev, enum suspended_state next);
 
 int hci_req_update_adv_data(struct hci_dev *hdev, u8 instance);
-int hci_get_random_address(struct hci_dev *hdev, bool require_privacy,
-                          bool use_rpa, struct adv_info *adv_instance,
-                          u8 *own_addr_type, bdaddr_t *rand_addr);
-
-int hci_update_random_address(struct hci_request *req, bool require_privacy,
-                             bool use_rpa, u8 *own_addr_type);
 
 int hci_abort_conn(struct hci_conn *conn, u8 reason);
-void __hci_abort_conn(struct hci_request *req, struct hci_conn *conn,
-                     u8 reason);
-
 void hci_request_setup(struct hci_dev *hdev);
 void hci_request_cancel_all(struct hci_dev *hdev);
index bc993dd2383df62ea9f6d6d5831b1217a22bbce5..46eb535ff466b34c20729582c78bfa8adfe0d90c 100644 (file)
@@ -5992,3 +5992,76 @@ int hci_le_pa_terminate_sync(struct hci_dev *hdev, u16 handle)
        return __hci_cmd_sync_status(hdev, HCI_OP_LE_PA_TERM_SYNC,
                                     sizeof(cp), &cp, HCI_CMD_TIMEOUT);
 }
+
+int hci_get_random_address(struct hci_dev *hdev, bool require_privacy,
+                          bool use_rpa, struct adv_info *adv_instance,
+                          u8 *own_addr_type, bdaddr_t *rand_addr)
+{
+       int err;
+
+       bacpy(rand_addr, BDADDR_ANY);
+
+       /* If privacy is enabled use a resolvable private address. If
+        * current RPA has expired then generate a new one.
+        */
+       if (use_rpa) {
+               /* If Controller supports LL Privacy use own address type is
+                * 0x03
+                */
+               if (use_ll_privacy(hdev))
+                       *own_addr_type = ADDR_LE_DEV_RANDOM_RESOLVED;
+               else
+                       *own_addr_type = ADDR_LE_DEV_RANDOM;
+
+               if (adv_instance) {
+                       if (adv_rpa_valid(adv_instance))
+                               return 0;
+               } else {
+                       if (rpa_valid(hdev))
+                               return 0;
+               }
+
+               err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa);
+               if (err < 0) {
+                       bt_dev_err(hdev, "failed to generate new RPA");
+                       return err;
+               }
+
+               bacpy(rand_addr, &hdev->rpa);
+
+               return 0;
+       }
+
+       /* In case of required privacy without resolvable private address,
+        * use an non-resolvable private address. This is useful for
+        * non-connectable advertising.
+        */
+       if (require_privacy) {
+               bdaddr_t nrpa;
+
+               while (true) {
+                       /* The non-resolvable private address is generated
+                        * from random six bytes with the two most significant
+                        * bits cleared.
+                        */
+                       get_random_bytes(&nrpa, 6);
+                       nrpa.b[5] &= 0x3f;
+
+                       /* The non-resolvable private address shall not be
+                        * equal to the public address.
+                        */
+                       if (bacmp(&hdev->bdaddr, &nrpa))
+                               break;
+               }
+
+               *own_addr_type = ADDR_LE_DEV_RANDOM;
+               bacpy(rand_addr, &nrpa);
+
+               return 0;
+       }
+
+       /* No privacy so use a public address. */
+       *own_addr_type = ADDR_LE_DEV_PUBLIC;
+
+       return 0;
+}