Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Bluetooth: convert hci_update_adv_data to hci_sync

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>

authored by

Brian Gix and committed by
Luiz Augusto von Dentz
651cd3d6 3fe318ee

+23 -68
+1
include/net/bluetooth/hci_sync.h
··· 61 61 62 62 int hci_update_scan_rsp_data_sync(struct hci_dev *hdev, u8 instance); 63 63 int hci_update_adv_data_sync(struct hci_dev *hdev, u8 instance); 64 + int hci_update_adv_data(struct hci_dev *hdev, u8 instance); 64 65 int hci_schedule_adv_instance_sync(struct hci_dev *hdev, u8 instance, 65 66 bool force); 66 67
+1 -1
net/bluetooth/hci_core.c
··· 714 714 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED); 715 715 716 716 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) 717 - hci_req_update_adv_data(hdev, hdev->cur_adv_instance); 717 + hci_update_adv_data(hdev, hdev->cur_adv_instance); 718 718 719 719 mgmt_new_settings(hdev); 720 720 }
+1 -1
net/bluetooth/hci_event.c
··· 2152 2152 adv_instance->tx_power = rp->tx_power; 2153 2153 } 2154 2154 /* Update adv data as tx power is known now */ 2155 - hci_req_update_adv_data(hdev, cp->handle); 2155 + hci_update_adv_data(hdev, cp->handle); 2156 2156 2157 2157 hci_dev_unlock(hdev); 2158 2158
-64
net/bluetooth/hci_request.c
··· 829 829 addr_resolv); 830 830 } 831 831 832 - static void __hci_req_update_adv_data(struct hci_request *req, u8 instance) 833 - { 834 - struct hci_dev *hdev = req->hdev; 835 - u8 len; 836 - 837 - if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) 838 - return; 839 - 840 - if (ext_adv_capable(hdev)) { 841 - struct { 842 - struct hci_cp_le_set_ext_adv_data cp; 843 - u8 data[HCI_MAX_EXT_AD_LENGTH]; 844 - } pdu; 845 - 846 - memset(&pdu, 0, sizeof(pdu)); 847 - 848 - len = eir_create_adv_data(hdev, instance, pdu.data); 849 - 850 - /* There's nothing to do if the data hasn't changed */ 851 - if (hdev->adv_data_len == len && 852 - memcmp(pdu.data, hdev->adv_data, len) == 0) 853 - return; 854 - 855 - memcpy(hdev->adv_data, pdu.data, len); 856 - hdev->adv_data_len = len; 857 - 858 - pdu.cp.length = len; 859 - pdu.cp.handle = instance; 860 - pdu.cp.operation = LE_SET_ADV_DATA_OP_COMPLETE; 861 - pdu.cp.frag_pref = LE_SET_ADV_DATA_NO_FRAG; 862 - 863 - hci_req_add(req, HCI_OP_LE_SET_EXT_ADV_DATA, 864 - sizeof(pdu.cp) + len, &pdu.cp); 865 - } else { 866 - struct hci_cp_le_set_adv_data cp; 867 - 868 - memset(&cp, 0, sizeof(cp)); 869 - 870 - len = eir_create_adv_data(hdev, instance, cp.data); 871 - 872 - /* There's nothing to do if the data hasn't changed */ 873 - if (hdev->adv_data_len == len && 874 - memcmp(cp.data, hdev->adv_data, len) == 0) 875 - return; 876 - 877 - memcpy(hdev->adv_data, cp.data, sizeof(cp.data)); 878 - hdev->adv_data_len = len; 879 - 880 - cp.length = len; 881 - 882 - hci_req_add(req, HCI_OP_LE_SET_ADV_DATA, sizeof(cp), &cp); 883 - } 884 - } 885 - 886 - int hci_req_update_adv_data(struct hci_dev *hdev, u8 instance) 887 - { 888 - struct hci_request req; 889 - 890 - hci_req_init(&req, hdev); 891 - __hci_req_update_adv_data(&req, instance); 892 - 893 - return hci_req_run(&req, NULL); 894 - } 895 - 896 832 static int hci_req_add_le_interleaved_scan(struct hci_request *req, 897 833 unsigned long opt) 898 834 {
-2
net/bluetooth/hci_request.h
··· 73 73 74 74 void hci_req_prepare_suspend(struct hci_dev *hdev, enum suspended_state next); 75 75 76 - int hci_req_update_adv_data(struct hci_dev *hdev, u8 instance); 77 - 78 76 int hci_abort_conn(struct hci_conn *conn, u8 reason); 79 77 void hci_request_setup(struct hci_dev *hdev); 80 78 void hci_request_cancel_all(struct hci_dev *hdev);
+20
net/bluetooth/hci_sync.c
··· 6065 6065 6066 6066 return 0; 6067 6067 } 6068 + 6069 + static int _update_adv_data_sync(struct hci_dev *hdev, void *data) 6070 + { 6071 + u8 instance = *(u8 *)data; 6072 + 6073 + kfree(data); 6074 + 6075 + return hci_update_adv_data_sync(hdev, instance); 6076 + } 6077 + 6078 + int hci_update_adv_data(struct hci_dev *hdev, u8 instance) 6079 + { 6080 + u8 *inst_ptr = kmalloc(1, GFP_KERNEL); 6081 + 6082 + if (!inst_ptr) 6083 + return -ENOMEM; 6084 + 6085 + *inst_ptr = instance; 6086 + return hci_cmd_sync_queue(hdev, _update_adv_data_sync, inst_ptr, NULL); 6087 + }