Bluetooth: convert hci_update_adv_data to hci_sync
authorBrian Gix <brian.gix@intel.com>
Fri, 5 Aug 2022 23:42:35 +0000 (16:42 -0700)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Thu, 25 Aug 2022 23:20:30 +0000 (16:20 -0700)
hci_update_adv_data() is called from hci_event and hci_core due to
events from the controller. The prior function used the deprecated
hci_request method, and the new one uses 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_core.c
net/bluetooth/hci_event.c
net/bluetooth/hci_request.c
net/bluetooth/hci_request.h
net/bluetooth/hci_sync.c

index b6b975c2ed3ebf8f1e3544fafdab56123e2e1e55..17f5a4c32f36ee1bfeff1b0bf5950e132bf218bb 100644 (file)
@@ -61,6 +61,7 @@ int hci_update_random_address_sync(struct hci_dev *hdev, bool require_privacy,
 
 int hci_update_scan_rsp_data_sync(struct hci_dev *hdev, u8 instance);
 int hci_update_adv_data_sync(struct hci_dev *hdev, u8 instance);
+int hci_update_adv_data(struct hci_dev *hdev, u8 instance);
 int hci_schedule_adv_instance_sync(struct hci_dev *hdev, u8 instance,
                                   bool force);
 
index b3a5a3cc937202bf94d4d4c1619d7b07e4437d45..9d2c33f6b0655affe00497a2c2b966c73d0ccf7d 100644 (file)
@@ -714,7 +714,7 @@ static void hci_update_passive_scan_state(struct hci_dev *hdev, u8 scan)
                hci_dev_set_flag(hdev, HCI_BREDR_ENABLED);
 
                if (hci_dev_test_flag(hdev, HCI_LE_ENABLED))
-                       hci_req_update_adv_data(hdev, hdev->cur_adv_instance);
+                       hci_update_adv_data(hdev, hdev->cur_adv_instance);
 
                mgmt_new_settings(hdev);
        }
index 485c814cf44aa04123d57a428a6e1a4d6de946a4..395c6479456f5b9d74b89f8eeb11079059287c5f 100644 (file)
@@ -2152,7 +2152,7 @@ static u8 hci_cc_set_ext_adv_param(struct hci_dev *hdev, void *data,
                        adv_instance->tx_power = rp->tx_power;
        }
        /* Update adv data as tx power is known now */
-       hci_req_update_adv_data(hdev, cp->handle);
+       hci_update_adv_data(hdev, cp->handle);
 
        hci_dev_unlock(hdev);
 
index b9875224ac7bcb35c1a5bab291238936336e72d7..2e19a271d7a1c338b9c2972e4fee172969ebcd81 100644 (file)
@@ -829,70 +829,6 @@ void hci_req_add_le_passive_scan(struct hci_request *req)
                           addr_resolv);
 }
 
-static void __hci_req_update_adv_data(struct hci_request *req, u8 instance)
-{
-       struct hci_dev *hdev = req->hdev;
-       u8 len;
-
-       if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED))
-               return;
-
-       if (ext_adv_capable(hdev)) {
-               struct {
-                       struct hci_cp_le_set_ext_adv_data cp;
-                       u8 data[HCI_MAX_EXT_AD_LENGTH];
-               } pdu;
-
-               memset(&pdu, 0, sizeof(pdu));
-
-               len = eir_create_adv_data(hdev, instance, pdu.data);
-
-               /* There's nothing to do if the data hasn't changed */
-               if (hdev->adv_data_len == len &&
-                   memcmp(pdu.data, hdev->adv_data, len) == 0)
-                       return;
-
-               memcpy(hdev->adv_data, pdu.data, len);
-               hdev->adv_data_len = len;
-
-               pdu.cp.length = len;
-               pdu.cp.handle = instance;
-               pdu.cp.operation = LE_SET_ADV_DATA_OP_COMPLETE;
-               pdu.cp.frag_pref = LE_SET_ADV_DATA_NO_FRAG;
-
-               hci_req_add(req, HCI_OP_LE_SET_EXT_ADV_DATA,
-                           sizeof(pdu.cp) + len, &pdu.cp);
-       } else {
-               struct hci_cp_le_set_adv_data cp;
-
-               memset(&cp, 0, sizeof(cp));
-
-               len = eir_create_adv_data(hdev, instance, cp.data);
-
-               /* There's nothing to do if the data hasn't changed */
-               if (hdev->adv_data_len == len &&
-                   memcmp(cp.data, hdev->adv_data, len) == 0)
-                       return;
-
-               memcpy(hdev->adv_data, cp.data, sizeof(cp.data));
-               hdev->adv_data_len = len;
-
-               cp.length = len;
-
-               hci_req_add(req, HCI_OP_LE_SET_ADV_DATA, sizeof(cp), &cp);
-       }
-}
-
-int hci_req_update_adv_data(struct hci_dev *hdev, u8 instance)
-{
-       struct hci_request req;
-
-       hci_req_init(&req, hdev);
-       __hci_req_update_adv_data(&req, instance);
-
-       return hci_req_run(&req, NULL);
-}
-
 static int hci_req_add_le_interleaved_scan(struct hci_request *req,
                                           unsigned long opt)
 {
index c7185ad77c6e01a11a8ecaef24637f1fc530bf75..7e1de871fca4fdd3201190d346c67523c8643974 100644 (file)
@@ -73,8 +73,6 @@ 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_abort_conn(struct hci_conn *conn, u8 reason);
 void hci_request_setup(struct hci_dev *hdev);
 void hci_request_cancel_all(struct hci_dev *hdev);
index 46eb535ff466b34c20729582c78bfa8adfe0d90c..6de2ad73099575703772336e008372c0bd2b2f72 100644 (file)
@@ -6065,3 +6065,23 @@ int hci_get_random_address(struct hci_dev *hdev, bool require_privacy,
 
        return 0;
 }
+
+static int _update_adv_data_sync(struct hci_dev *hdev, void *data)
+{
+       u8 instance = *(u8 *)data;
+
+       kfree(data);
+
+       return hci_update_adv_data_sync(hdev, instance);
+}
+
+int hci_update_adv_data(struct hci_dev *hdev, u8 instance)
+{
+       u8 *inst_ptr = kmalloc(1, GFP_KERNEL);
+
+       if (!inst_ptr)
+               return -ENOMEM;
+
+       *inst_ptr = instance;
+       return hci_cmd_sync_queue(hdev, _update_adv_data_sync, inst_ptr, NULL);
+}