diff options
author | Johan Hedberg <johan.hedberg@intel.com> | 2015-11-30 04:21:45 -0500 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2015-12-09 18:51:50 -0500 |
commit | cab054ab47fa3fdf1c597a9874363680bfdab33e (patch) | |
tree | 66de00bdcdbf62da735338ae63cd340d60035cc1 /net/bluetooth/hci_request.c | |
parent | d6b7e2cddb72a87c2597af43ba9f5f2b03a2208b (diff) |
Bluetooth: Clean up current advertising instance tracking
We can simplify a lot of code by making sure hdev->cur_adv_instance is
always up-to-date. This allows e.g. the removal of the
get_current_adv_instance() helper function and the special
HCI_ADV_CURRENT value. This patch also makes selecting instance 0x00
explicit in the various calls where advertising instances aren't
enabled, e.g. when HCI_ADVERTISING is set or we've just finished
enabling LE.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/bluetooth/hci_request.c')
-rw-r--r-- | net/bluetooth/hci_request.c | 68 |
1 files changed, 15 insertions, 53 deletions
diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c index 14db777a6bb1..9997c31ef987 100644 --- a/net/bluetooth/hci_request.c +++ b/net/bluetooth/hci_request.c | |||
@@ -815,23 +815,9 @@ void hci_req_add_le_passive_scan(struct hci_request *req) | |||
815 | &enable_cp); | 815 | &enable_cp); |
816 | } | 816 | } |
817 | 817 | ||
818 | static u8 get_current_adv_instance(struct hci_dev *hdev) | ||
819 | { | ||
820 | /* The "Set Advertising" setting supersedes the "Add Advertising" | ||
821 | * setting. Here we set the advertising data based on which | ||
822 | * setting was set. When neither apply, default to the global settings, | ||
823 | * represented by instance "0". | ||
824 | */ | ||
825 | if (!list_empty(&hdev->adv_instances) && | ||
826 | !hci_dev_test_flag(hdev, HCI_ADVERTISING)) | ||
827 | return hdev->cur_adv_instance; | ||
828 | |||
829 | return 0x00; | ||
830 | } | ||
831 | |||
832 | static u8 get_cur_adv_instance_scan_rsp_len(struct hci_dev *hdev) | 818 | static u8 get_cur_adv_instance_scan_rsp_len(struct hci_dev *hdev) |
833 | { | 819 | { |
834 | u8 instance = get_current_adv_instance(hdev); | 820 | u8 instance = hdev->cur_adv_instance; |
835 | struct adv_info *adv_instance; | 821 | struct adv_info *adv_instance; |
836 | 822 | ||
837 | /* Ignore instance 0 */ | 823 | /* Ignore instance 0 */ |
@@ -890,7 +876,6 @@ void __hci_req_enable_advertising(struct hci_request *req) | |||
890 | struct hci_cp_le_set_adv_param cp; | 876 | struct hci_cp_le_set_adv_param cp; |
891 | u8 own_addr_type, enable = 0x01; | 877 | u8 own_addr_type, enable = 0x01; |
892 | bool connectable; | 878 | bool connectable; |
893 | u8 instance; | ||
894 | u32 flags; | 879 | u32 flags; |
895 | 880 | ||
896 | if (hci_conn_num(hdev, LE_LINK) > 0) | 881 | if (hci_conn_num(hdev, LE_LINK) > 0) |
@@ -906,8 +891,7 @@ void __hci_req_enable_advertising(struct hci_request *req) | |||
906 | */ | 891 | */ |
907 | hci_dev_clear_flag(hdev, HCI_LE_ADV); | 892 | hci_dev_clear_flag(hdev, HCI_LE_ADV); |
908 | 893 | ||
909 | instance = get_current_adv_instance(hdev); | 894 | flags = get_adv_instance_flags(hdev, hdev->cur_adv_instance); |
910 | flags = get_adv_instance_flags(hdev, instance); | ||
911 | 895 | ||
912 | /* If the "connectable" instance flag was not set, then choose between | 896 | /* If the "connectable" instance flag was not set, then choose between |
913 | * ADV_IND and ADV_NONCONN_IND based on the global connectable setting. | 897 | * ADV_IND and ADV_NONCONN_IND based on the global connectable setting. |
@@ -985,7 +969,7 @@ static u8 create_instance_scan_rsp_data(struct hci_dev *hdev, u8 instance, | |||
985 | return adv_instance->scan_rsp_len; | 969 | return adv_instance->scan_rsp_len; |
986 | } | 970 | } |
987 | 971 | ||
988 | static void update_inst_scan_rsp_data(struct hci_request *req, u8 instance) | 972 | void __hci_req_update_scan_rsp_data(struct hci_request *req, u8 instance) |
989 | { | 973 | { |
990 | struct hci_dev *hdev = req->hdev; | 974 | struct hci_dev *hdev = req->hdev; |
991 | struct hci_cp_le_set_scan_rsp_data cp; | 975 | struct hci_cp_le_set_scan_rsp_data cp; |
@@ -1013,14 +997,6 @@ static void update_inst_scan_rsp_data(struct hci_request *req, u8 instance) | |||
1013 | hci_req_add(req, HCI_OP_LE_SET_SCAN_RSP_DATA, sizeof(cp), &cp); | 997 | hci_req_add(req, HCI_OP_LE_SET_SCAN_RSP_DATA, sizeof(cp), &cp); |
1014 | } | 998 | } |
1015 | 999 | ||
1016 | void __hci_req_update_scan_rsp_data(struct hci_request *req, int instance) | ||
1017 | { | ||
1018 | if (instance == HCI_ADV_CURRENT) | ||
1019 | instance = get_current_adv_instance(req->hdev); | ||
1020 | |||
1021 | update_inst_scan_rsp_data(req, instance); | ||
1022 | } | ||
1023 | |||
1024 | static u8 create_instance_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr) | 1000 | static u8 create_instance_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr) |
1025 | { | 1001 | { |
1026 | struct adv_info *adv_instance = NULL; | 1002 | struct adv_info *adv_instance = NULL; |
@@ -1089,7 +1065,7 @@ static u8 create_instance_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr) | |||
1089 | return ad_len; | 1065 | return ad_len; |
1090 | } | 1066 | } |
1091 | 1067 | ||
1092 | static void update_inst_adv_data(struct hci_request *req, u8 instance) | 1068 | void __hci_req_update_adv_data(struct hci_request *req, u8 instance) |
1093 | { | 1069 | { |
1094 | struct hci_dev *hdev = req->hdev; | 1070 | struct hci_dev *hdev = req->hdev; |
1095 | struct hci_cp_le_set_adv_data cp; | 1071 | struct hci_cp_le_set_adv_data cp; |
@@ -1115,15 +1091,7 @@ static void update_inst_adv_data(struct hci_request *req, u8 instance) | |||
1115 | hci_req_add(req, HCI_OP_LE_SET_ADV_DATA, sizeof(cp), &cp); | 1091 | hci_req_add(req, HCI_OP_LE_SET_ADV_DATA, sizeof(cp), &cp); |
1116 | } | 1092 | } |
1117 | 1093 | ||
1118 | void __hci_req_update_adv_data(struct hci_request *req, int instance) | 1094 | int hci_req_update_adv_data(struct hci_dev *hdev, u8 instance) |
1119 | { | ||
1120 | if (instance == HCI_ADV_CURRENT) | ||
1121 | instance = get_current_adv_instance(req->hdev); | ||
1122 | |||
1123 | update_inst_adv_data(req, instance); | ||
1124 | } | ||
1125 | |||
1126 | int hci_req_update_adv_data(struct hci_dev *hdev, int instance) | ||
1127 | { | 1095 | { |
1128 | struct hci_request req; | 1096 | struct hci_request req; |
1129 | 1097 | ||
@@ -1141,21 +1109,19 @@ static void adv_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode) | |||
1141 | void hci_req_reenable_advertising(struct hci_dev *hdev) | 1109 | void hci_req_reenable_advertising(struct hci_dev *hdev) |
1142 | { | 1110 | { |
1143 | struct hci_request req; | 1111 | struct hci_request req; |
1144 | u8 instance; | ||
1145 | 1112 | ||
1146 | if (!hci_dev_test_flag(hdev, HCI_ADVERTISING) && | 1113 | if (!hci_dev_test_flag(hdev, HCI_ADVERTISING) && |
1147 | list_empty(&hdev->adv_instances)) | 1114 | list_empty(&hdev->adv_instances)) |
1148 | return; | 1115 | return; |
1149 | 1116 | ||
1150 | instance = get_current_adv_instance(hdev); | ||
1151 | |||
1152 | hci_req_init(&req, hdev); | 1117 | hci_req_init(&req, hdev); |
1153 | 1118 | ||
1154 | if (instance) { | 1119 | if (hdev->cur_adv_instance) { |
1155 | __hci_req_schedule_adv_instance(&req, instance, true); | 1120 | __hci_req_schedule_adv_instance(&req, hdev->cur_adv_instance, |
1121 | true); | ||
1156 | } else { | 1122 | } else { |
1157 | __hci_req_update_adv_data(&req, HCI_ADV_CURRENT); | 1123 | __hci_req_update_adv_data(&req, 0x00); |
1158 | __hci_req_update_scan_rsp_data(&req, HCI_ADV_CURRENT); | 1124 | __hci_req_update_scan_rsp_data(&req, 0x00); |
1159 | __hci_req_enable_advertising(&req); | 1125 | __hci_req_enable_advertising(&req); |
1160 | } | 1126 | } |
1161 | 1127 | ||
@@ -1176,7 +1142,7 @@ static void adv_timeout_expire(struct work_struct *work) | |||
1176 | 1142 | ||
1177 | hdev->adv_instance_timeout = 0; | 1143 | hdev->adv_instance_timeout = 0; |
1178 | 1144 | ||
1179 | instance = get_current_adv_instance(hdev); | 1145 | instance = hdev->cur_adv_instance; |
1180 | if (instance == 0x00) | 1146 | if (instance == 0x00) |
1181 | goto unlock; | 1147 | goto unlock; |
1182 | 1148 | ||
@@ -1246,8 +1212,8 @@ int __hci_req_schedule_adv_instance(struct hci_request *req, u8 instance, | |||
1246 | return 0; | 1212 | return 0; |
1247 | 1213 | ||
1248 | hdev->cur_adv_instance = instance; | 1214 | hdev->cur_adv_instance = instance; |
1249 | __hci_req_update_adv_data(req, HCI_ADV_CURRENT); | 1215 | __hci_req_update_adv_data(req, instance); |
1250 | __hci_req_update_scan_rsp_data(req, HCI_ADV_CURRENT); | 1216 | __hci_req_update_scan_rsp_data(req, instance); |
1251 | __hci_req_enable_advertising(req); | 1217 | __hci_req_enable_advertising(req); |
1252 | 1218 | ||
1253 | return 0; | 1219 | return 0; |
@@ -1301,7 +1267,6 @@ void hci_req_clear_adv_instance(struct hci_dev *hdev, struct hci_request *req, | |||
1301 | if (!err) | 1267 | if (!err) |
1302 | mgmt_advertising_removed(NULL, hdev, rem_inst); | 1268 | mgmt_advertising_removed(NULL, hdev, rem_inst); |
1303 | } | 1269 | } |
1304 | hdev->cur_adv_instance = 0x00; | ||
1305 | } else { | 1270 | } else { |
1306 | adv_instance = hci_find_adv_instance(hdev, instance); | 1271 | adv_instance = hci_find_adv_instance(hdev, instance); |
1307 | 1272 | ||
@@ -1318,9 +1283,6 @@ void hci_req_clear_adv_instance(struct hci_dev *hdev, struct hci_request *req, | |||
1318 | } | 1283 | } |
1319 | } | 1284 | } |
1320 | 1285 | ||
1321 | if (list_empty(&hdev->adv_instances)) | ||
1322 | hdev->cur_adv_instance = 0x00; | ||
1323 | |||
1324 | if (!req || !hdev_is_powered(hdev) || | 1286 | if (!req || !hdev_is_powered(hdev) || |
1325 | hci_dev_test_flag(hdev, HCI_ADVERTISING)) | 1287 | hci_dev_test_flag(hdev, HCI_ADVERTISING)) |
1326 | return; | 1288 | return; |
@@ -1518,7 +1480,7 @@ static int connectable_update(struct hci_request *req, unsigned long opt) | |||
1518 | * advertising flags. | 1480 | * advertising flags. |
1519 | */ | 1481 | */ |
1520 | if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) | 1482 | if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) |
1521 | __hci_req_update_adv_data(req, HCI_ADV_CURRENT); | 1483 | __hci_req_update_adv_data(req, hdev->cur_adv_instance); |
1522 | 1484 | ||
1523 | /* Update the advertising parameters if necessary */ | 1485 | /* Update the advertising parameters if necessary */ |
1524 | if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || | 1486 | if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || |
@@ -1627,7 +1589,7 @@ static int discoverable_update(struct hci_request *req, unsigned long opt) | |||
1627 | * only update AD if advertising was enabled using Set Advertising. | 1589 | * only update AD if advertising was enabled using Set Advertising. |
1628 | */ | 1590 | */ |
1629 | if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) | 1591 | if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) |
1630 | __hci_req_update_adv_data(req, HCI_ADV_CURRENT); | 1592 | __hci_req_update_adv_data(req, 0x00); |
1631 | 1593 | ||
1632 | hci_dev_unlock(hdev); | 1594 | hci_dev_unlock(hdev); |
1633 | 1595 | ||