diff options
Diffstat (limited to 'net/bluetooth/hci_request.c')
-rw-r--r-- | net/bluetooth/hci_request.c | 49 |
1 files changed, 35 insertions, 14 deletions
diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c index b0e23dfc5c34..c8135680c43e 100644 --- a/net/bluetooth/hci_request.c +++ b/net/bluetooth/hci_request.c | |||
@@ -971,14 +971,14 @@ void __hci_req_enable_advertising(struct hci_request *req) | |||
971 | hci_req_add(req, HCI_OP_LE_SET_ADV_ENABLE, sizeof(enable), &enable); | 971 | hci_req_add(req, HCI_OP_LE_SET_ADV_ENABLE, sizeof(enable), &enable); |
972 | } | 972 | } |
973 | 973 | ||
974 | static u8 create_default_scan_rsp_data(struct hci_dev *hdev, u8 *ptr) | 974 | static u8 append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len) |
975 | { | 975 | { |
976 | u8 ad_len = 0; | ||
977 | size_t name_len; | 976 | size_t name_len; |
977 | int max_len; | ||
978 | 978 | ||
979 | max_len = HCI_MAX_AD_LENGTH - ad_len - 2; | ||
979 | name_len = strlen(hdev->dev_name); | 980 | name_len = strlen(hdev->dev_name); |
980 | if (name_len > 0) { | 981 | if (name_len > 0 && max_len > 0) { |
981 | size_t max_len = HCI_MAX_AD_LENGTH - ad_len - 2; | ||
982 | 982 | ||
983 | if (name_len > max_len) { | 983 | if (name_len > max_len) { |
984 | name_len = max_len; | 984 | name_len = max_len; |
@@ -997,22 +997,42 @@ static u8 create_default_scan_rsp_data(struct hci_dev *hdev, u8 *ptr) | |||
997 | return ad_len; | 997 | return ad_len; |
998 | } | 998 | } |
999 | 999 | ||
1000 | static u8 create_default_scan_rsp_data(struct hci_dev *hdev, u8 *ptr) | ||
1001 | { | ||
1002 | return append_local_name(hdev, ptr, 0); | ||
1003 | } | ||
1004 | |||
1000 | static u8 create_instance_scan_rsp_data(struct hci_dev *hdev, u8 instance, | 1005 | static u8 create_instance_scan_rsp_data(struct hci_dev *hdev, u8 instance, |
1001 | u8 *ptr) | 1006 | u8 *ptr) |
1002 | { | 1007 | { |
1003 | struct adv_info *adv_instance; | 1008 | struct adv_info *adv_instance; |
1009 | u32 instance_flags; | ||
1010 | u8 scan_rsp_len = 0; | ||
1004 | 1011 | ||
1005 | adv_instance = hci_find_adv_instance(hdev, instance); | 1012 | adv_instance = hci_find_adv_instance(hdev, instance); |
1006 | if (!adv_instance) | 1013 | if (!adv_instance) |
1007 | return 0; | 1014 | return 0; |
1008 | 1015 | ||
1009 | /* TODO: Set the appropriate entries based on advertising instance flags | 1016 | instance_flags = adv_instance->flags; |
1010 | * here once flags other than 0 are supported. | 1017 | |
1011 | */ | 1018 | if ((instance_flags & MGMT_ADV_FLAG_APPEARANCE) && hdev->appearance) { |
1019 | ptr[0] = 3; | ||
1020 | ptr[1] = EIR_APPEARANCE; | ||
1021 | put_unaligned_le16(hdev->appearance, ptr + 2); | ||
1022 | scan_rsp_len += 4; | ||
1023 | ptr += 4; | ||
1024 | } | ||
1025 | |||
1012 | memcpy(ptr, adv_instance->scan_rsp_data, | 1026 | memcpy(ptr, adv_instance->scan_rsp_data, |
1013 | adv_instance->scan_rsp_len); | 1027 | adv_instance->scan_rsp_len); |
1014 | 1028 | ||
1015 | return adv_instance->scan_rsp_len; | 1029 | scan_rsp_len += adv_instance->scan_rsp_len; |
1030 | ptr += adv_instance->scan_rsp_len; | ||
1031 | |||
1032 | if (instance_flags & MGMT_ADV_FLAG_LOCAL_NAME) | ||
1033 | scan_rsp_len = append_local_name(hdev, ptr, scan_rsp_len); | ||
1034 | |||
1035 | return scan_rsp_len; | ||
1016 | } | 1036 | } |
1017 | 1037 | ||
1018 | void __hci_req_update_scan_rsp_data(struct hci_request *req, u8 instance) | 1038 | void __hci_req_update_scan_rsp_data(struct hci_request *req, u8 instance) |
@@ -1194,7 +1214,7 @@ static void adv_timeout_expire(struct work_struct *work) | |||
1194 | 1214 | ||
1195 | hci_req_init(&req, hdev); | 1215 | hci_req_init(&req, hdev); |
1196 | 1216 | ||
1197 | hci_req_clear_adv_instance(hdev, &req, instance, false); | 1217 | hci_req_clear_adv_instance(hdev, NULL, &req, instance, false); |
1198 | 1218 | ||
1199 | if (list_empty(&hdev->adv_instances)) | 1219 | if (list_empty(&hdev->adv_instances)) |
1200 | __hci_req_disable_advertising(&req); | 1220 | __hci_req_disable_advertising(&req); |
@@ -1284,8 +1304,9 @@ static void cancel_adv_timeout(struct hci_dev *hdev) | |||
1284 | * setting. | 1304 | * setting. |
1285 | * - force == false: Only instances that have a timeout will be removed. | 1305 | * - force == false: Only instances that have a timeout will be removed. |
1286 | */ | 1306 | */ |
1287 | void hci_req_clear_adv_instance(struct hci_dev *hdev, struct hci_request *req, | 1307 | void hci_req_clear_adv_instance(struct hci_dev *hdev, struct sock *sk, |
1288 | u8 instance, bool force) | 1308 | struct hci_request *req, u8 instance, |
1309 | bool force) | ||
1289 | { | 1310 | { |
1290 | struct adv_info *adv_instance, *n, *next_instance = NULL; | 1311 | struct adv_info *adv_instance, *n, *next_instance = NULL; |
1291 | int err; | 1312 | int err; |
@@ -1311,7 +1332,7 @@ void hci_req_clear_adv_instance(struct hci_dev *hdev, struct hci_request *req, | |||
1311 | rem_inst = adv_instance->instance; | 1332 | rem_inst = adv_instance->instance; |
1312 | err = hci_remove_adv_instance(hdev, rem_inst); | 1333 | err = hci_remove_adv_instance(hdev, rem_inst); |
1313 | if (!err) | 1334 | if (!err) |
1314 | mgmt_advertising_removed(NULL, hdev, rem_inst); | 1335 | mgmt_advertising_removed(sk, hdev, rem_inst); |
1315 | } | 1336 | } |
1316 | } else { | 1337 | } else { |
1317 | adv_instance = hci_find_adv_instance(hdev, instance); | 1338 | adv_instance = hci_find_adv_instance(hdev, instance); |
@@ -1325,7 +1346,7 @@ void hci_req_clear_adv_instance(struct hci_dev *hdev, struct hci_request *req, | |||
1325 | 1346 | ||
1326 | err = hci_remove_adv_instance(hdev, instance); | 1347 | err = hci_remove_adv_instance(hdev, instance); |
1327 | if (!err) | 1348 | if (!err) |
1328 | mgmt_advertising_removed(NULL, hdev, instance); | 1349 | mgmt_advertising_removed(sk, hdev, instance); |
1329 | } | 1350 | } |
1330 | } | 1351 | } |
1331 | 1352 | ||
@@ -1716,7 +1737,7 @@ void __hci_abort_conn(struct hci_request *req, struct hci_conn *conn, | |||
1716 | * function. To be safe hard-code one of the | 1737 | * function. To be safe hard-code one of the |
1717 | * values that's suitable for SCO. | 1738 | * values that's suitable for SCO. |
1718 | */ | 1739 | */ |
1719 | rej.reason = HCI_ERROR_REMOTE_LOW_RESOURCES; | 1740 | rej.reason = HCI_ERROR_REJ_LIMITED_RESOURCES; |
1720 | 1741 | ||
1721 | hci_req_add(req, HCI_OP_REJECT_SYNC_CONN_REQ, | 1742 | hci_req_add(req, HCI_OP_REJECT_SYNC_CONN_REQ, |
1722 | sizeof(rej), &rej); | 1743 | sizeof(rej), &rej); |