summaryrefslogtreecommitdiffstats
path: root/net/bluetooth/mgmt.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/bluetooth/mgmt.c')
-rw-r--r--net/bluetooth/mgmt.c489
1 files changed, 242 insertions, 247 deletions
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 4ca009268afb..7fcff8887131 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -234,7 +234,7 @@ static int cmd_status(struct sock *sk, u16 index, u16 cmd, u8 status)
234} 234}
235 235
236static int cmd_complete(struct sock *sk, u16 index, u16 cmd, u8 status, 236static int cmd_complete(struct sock *sk, u16 index, u16 cmd, u8 status,
237 void *rp, size_t rp_len) 237 void *rp, size_t rp_len)
238{ 238{
239 struct sk_buff *skb; 239 struct sk_buff *skb;
240 struct mgmt_hdr *hdr; 240 struct mgmt_hdr *hdr;
@@ -267,8 +267,8 @@ static int cmd_complete(struct sock *sk, u16 index, u16 cmd, u8 status,
267 return err; 267 return err;
268} 268}
269 269
270static int read_version(struct sock *sk, struct hci_dev *hdev, 270static int read_version(struct sock *sk, struct hci_dev *hdev, void *data,
271 void *data, u16 data_len) 271 u16 data_len)
272{ 272{
273 struct mgmt_rp_read_version rp; 273 struct mgmt_rp_read_version rp;
274 274
@@ -278,11 +278,11 @@ static int read_version(struct sock *sk, struct hci_dev *hdev,
278 put_unaligned_le16(MGMT_REVISION, &rp.revision); 278 put_unaligned_le16(MGMT_REVISION, &rp.revision);
279 279
280 return cmd_complete(sk, MGMT_INDEX_NONE, MGMT_OP_READ_VERSION, 0, &rp, 280 return cmd_complete(sk, MGMT_INDEX_NONE, MGMT_OP_READ_VERSION, 0, &rp,
281 sizeof(rp)); 281 sizeof(rp));
282} 282}
283 283
284static int read_commands(struct sock *sk, struct hci_dev *hdev, 284static int read_commands(struct sock *sk, struct hci_dev *hdev, void *data,
285 void *data, u16 data_len) 285 u16 data_len)
286{ 286{
287 struct mgmt_rp_read_commands *rp; 287 struct mgmt_rp_read_commands *rp;
288 u16 num_commands = ARRAY_SIZE(mgmt_commands); 288 u16 num_commands = ARRAY_SIZE(mgmt_commands);
@@ -309,14 +309,14 @@ static int read_commands(struct sock *sk, struct hci_dev *hdev,
309 put_unaligned_le16(mgmt_events[i], opcode); 309 put_unaligned_le16(mgmt_events[i], opcode);
310 310
311 err = cmd_complete(sk, MGMT_INDEX_NONE, MGMT_OP_READ_COMMANDS, 0, rp, 311 err = cmd_complete(sk, MGMT_INDEX_NONE, MGMT_OP_READ_COMMANDS, 0, rp,
312 rp_size); 312 rp_size);
313 kfree(rp); 313 kfree(rp);
314 314
315 return err; 315 return err;
316} 316}
317 317
318static int read_index_list(struct sock *sk, struct hci_dev *hdev, 318static int read_index_list(struct sock *sk, struct hci_dev *hdev, void *data,
319 void *data, u16 data_len) 319 u16 data_len)
320{ 320{
321 struct mgmt_rp_read_index_list *rp; 321 struct mgmt_rp_read_index_list *rp;
322 struct list_head *p; 322 struct list_head *p;
@@ -355,7 +355,7 @@ static int read_index_list(struct sock *sk, struct hci_dev *hdev,
355 read_unlock(&hci_dev_list_lock); 355 read_unlock(&hci_dev_list_lock);
356 356
357 err = cmd_complete(sk, MGMT_INDEX_NONE, MGMT_OP_READ_INDEX_LIST, 0, rp, 357 err = cmd_complete(sk, MGMT_INDEX_NONE, MGMT_OP_READ_INDEX_LIST, 0, rp,
358 rp_len); 358 rp_len);
359 359
360 kfree(rp); 360 kfree(rp);
361 361
@@ -600,7 +600,7 @@ static int update_class(struct hci_dev *hdev)
600static void service_cache_off(struct work_struct *work) 600static void service_cache_off(struct work_struct *work)
601{ 601{
602 struct hci_dev *hdev = container_of(work, struct hci_dev, 602 struct hci_dev *hdev = container_of(work, struct hci_dev,
603 service_cache.work); 603 service_cache.work);
604 604
605 if (!test_and_clear_bit(HCI_SERVICE_CACHE, &hdev->dev_flags)) 605 if (!test_and_clear_bit(HCI_SERVICE_CACHE, &hdev->dev_flags))
606 return; 606 return;
@@ -629,7 +629,7 @@ static void mgmt_init_hdev(struct sock *sk, struct hci_dev *hdev)
629} 629}
630 630
631static int read_controller_info(struct sock *sk, struct hci_dev *hdev, 631static int read_controller_info(struct sock *sk, struct hci_dev *hdev,
632 void *data, u16 data_len) 632 void *data, u16 data_len)
633{ 633{
634 struct mgmt_rp_read_info rp; 634 struct mgmt_rp_read_info rp;
635 635
@@ -656,7 +656,7 @@ static int read_controller_info(struct sock *sk, struct hci_dev *hdev,
656 hci_dev_unlock(hdev); 656 hci_dev_unlock(hdev);
657 657
658 return cmd_complete(sk, hdev->id, MGMT_OP_READ_INFO, 0, &rp, 658 return cmd_complete(sk, hdev->id, MGMT_OP_READ_INFO, 0, &rp,
659 sizeof(rp)); 659 sizeof(rp));
660} 660}
661 661
662static void mgmt_pending_free(struct pending_cmd *cmd) 662static void mgmt_pending_free(struct pending_cmd *cmd)
@@ -667,8 +667,8 @@ static void mgmt_pending_free(struct pending_cmd *cmd)
667} 667}
668 668
669static struct pending_cmd *mgmt_pending_add(struct sock *sk, u16 opcode, 669static struct pending_cmd *mgmt_pending_add(struct sock *sk, u16 opcode,
670 struct hci_dev *hdev, 670 struct hci_dev *hdev, void *data,
671 void *data, u16 len) 671 u16 len)
672{ 672{
673 struct pending_cmd *cmd; 673 struct pending_cmd *cmd;
674 674
@@ -697,8 +697,8 @@ static struct pending_cmd *mgmt_pending_add(struct sock *sk, u16 opcode,
697} 697}
698 698
699static void mgmt_pending_foreach(u16 opcode, struct hci_dev *hdev, 699static void mgmt_pending_foreach(u16 opcode, struct hci_dev *hdev,
700 void (*cb)(struct pending_cmd *cmd, void *data), 700 void (*cb)(struct pending_cmd *cmd, void *data),
701 void *data) 701 void *data)
702{ 702{
703 struct list_head *p, *n; 703 struct list_head *p, *n;
704 704
@@ -737,11 +737,11 @@ static int send_settings_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev)
737 __le32 settings = cpu_to_le32(get_current_settings(hdev)); 737 __le32 settings = cpu_to_le32(get_current_settings(hdev));
738 738
739 return cmd_complete(sk, hdev->id, opcode, 0, &settings, 739 return cmd_complete(sk, hdev->id, opcode, 0, &settings,
740 sizeof(settings)); 740 sizeof(settings));
741} 741}
742 742
743static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data, 743static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data,
744 u16 len) 744 u16 len)
745{ 745{
746 struct mgmt_mode *cp = data; 746 struct mgmt_mode *cp = data;
747 struct pending_cmd *cmd; 747 struct pending_cmd *cmd;
@@ -768,7 +768,7 @@ static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data,
768 768
769 if (mgmt_pending_find(MGMT_OP_SET_POWERED, hdev)) { 769 if (mgmt_pending_find(MGMT_OP_SET_POWERED, hdev)) {
770 err = cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, 770 err = cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED,
771 MGMT_STATUS_BUSY); 771 MGMT_STATUS_BUSY);
772 goto failed; 772 goto failed;
773 } 773 }
774 774
@@ -790,8 +790,8 @@ failed:
790 return err; 790 return err;
791} 791}
792 792
793static int mgmt_event(u16 event, struct hci_dev *hdev, void *data, 793static int mgmt_event(u16 event, struct hci_dev *hdev, void *data, u16 data_len,
794 u16 data_len, struct sock *skip_sk) 794 struct sock *skip_sk)
795{ 795{
796 struct sk_buff *skb; 796 struct sk_buff *skb;
797 struct mgmt_hdr *hdr; 797 struct mgmt_hdr *hdr;
@@ -830,7 +830,7 @@ static int new_settings(struct hci_dev *hdev, struct sock *skip)
830} 830}
831 831
832static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data, 832static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data,
833 u16 len) 833 u16 len)
834{ 834{
835 struct mgmt_cp_set_discoverable *cp = data; 835 struct mgmt_cp_set_discoverable *cp = data;
836 struct pending_cmd *cmd; 836 struct pending_cmd *cmd;
@@ -843,26 +843,26 @@ static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data,
843 timeout = get_unaligned_le16(&cp->timeout); 843 timeout = get_unaligned_le16(&cp->timeout);
844 if (!cp->val && timeout > 0) 844 if (!cp->val && timeout > 0)
845 return cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, 845 return cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE,
846 MGMT_STATUS_INVALID_PARAMS); 846 MGMT_STATUS_INVALID_PARAMS);
847 847
848 hci_dev_lock(hdev); 848 hci_dev_lock(hdev);
849 849
850 if (!hdev_is_powered(hdev) && timeout > 0) { 850 if (!hdev_is_powered(hdev) && timeout > 0) {
851 err = cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, 851 err = cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE,
852 MGMT_STATUS_NOT_POWERED); 852 MGMT_STATUS_NOT_POWERED);
853 goto failed; 853 goto failed;
854 } 854 }
855 855
856 if (mgmt_pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) || 856 if (mgmt_pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) ||
857 mgmt_pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) { 857 mgmt_pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) {
858 err = cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, 858 err = cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE,
859 MGMT_STATUS_BUSY); 859 MGMT_STATUS_BUSY);
860 goto failed; 860 goto failed;
861 } 861 }
862 862
863 if (!test_bit(HCI_CONNECTABLE, &hdev->dev_flags)) { 863 if (!test_bit(HCI_CONNECTABLE, &hdev->dev_flags)) {
864 err = cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, 864 err = cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE,
865 MGMT_STATUS_REJECTED); 865 MGMT_STATUS_REJECTED);
866 goto failed; 866 goto failed;
867 } 867 }
868 868
@@ -926,7 +926,7 @@ failed:
926} 926}
927 927
928static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data, 928static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data,
929 u16 len) 929 u16 len)
930{ 930{
931 struct mgmt_mode *cp = data; 931 struct mgmt_mode *cp = data;
932 struct pending_cmd *cmd; 932 struct pending_cmd *cmd;
@@ -963,7 +963,7 @@ static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data,
963 if (mgmt_pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) || 963 if (mgmt_pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) ||
964 mgmt_pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) { 964 mgmt_pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) {
965 err = cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, 965 err = cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE,
966 MGMT_STATUS_BUSY); 966 MGMT_STATUS_BUSY);
967 goto failed; 967 goto failed;
968 } 968 }
969 969
@@ -998,7 +998,7 @@ failed:
998} 998}
999 999
1000static int set_pairable(struct sock *sk, struct hci_dev *hdev, void *data, 1000static int set_pairable(struct sock *sk, struct hci_dev *hdev, void *data,
1001 u16 len) 1001 u16 len)
1002{ 1002{
1003 struct mgmt_mode *cp = data; 1003 struct mgmt_mode *cp = data;
1004 int err; 1004 int err;
@@ -1023,8 +1023,8 @@ failed:
1023 return err; 1023 return err;
1024} 1024}
1025 1025
1026static int set_link_security(struct sock *sk, struct hci_dev *hdev, 1026static int set_link_security(struct sock *sk, struct hci_dev *hdev, void *data,
1027 void *data, u16 len) 1027 u16 len)
1028{ 1028{
1029 struct mgmt_mode *cp = data; 1029 struct mgmt_mode *cp = data;
1030 struct pending_cmd *cmd; 1030 struct pending_cmd *cmd;
@@ -1056,7 +1056,7 @@ static int set_link_security(struct sock *sk, struct hci_dev *hdev,
1056 1056
1057 if (mgmt_pending_find(MGMT_OP_SET_LINK_SECURITY, hdev)) { 1057 if (mgmt_pending_find(MGMT_OP_SET_LINK_SECURITY, hdev)) {
1058 err = cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, 1058 err = cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY,
1059 MGMT_STATUS_BUSY); 1059 MGMT_STATUS_BUSY);
1060 goto failed; 1060 goto failed;
1061 } 1061 }
1062 1062
@@ -1097,7 +1097,7 @@ static int set_ssp(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
1097 1097
1098 if (!(hdev->features[6] & LMP_SIMPLE_PAIR)) { 1098 if (!(hdev->features[6] & LMP_SIMPLE_PAIR)) {
1099 err = cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, 1099 err = cmd_status(sk, hdev->id, MGMT_OP_SET_SSP,
1100 MGMT_STATUS_NOT_SUPPORTED); 1100 MGMT_STATUS_NOT_SUPPORTED);
1101 goto failed; 1101 goto failed;
1102 } 1102 }
1103 1103
@@ -1122,8 +1122,8 @@ static int set_ssp(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
1122 } 1122 }
1123 1123
1124 if (mgmt_pending_find(MGMT_OP_SET_SSP, hdev)) { 1124 if (mgmt_pending_find(MGMT_OP_SET_SSP, hdev)) {
1125 err = cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, 1125 err = cmd_status(sk, hdev->id, MGMT_OP_SET_SSP,
1126 MGMT_STATUS_BUSY); 1126 MGMT_STATUS_BUSY);
1127 goto failed; 1127 goto failed;
1128 } 1128 }
1129 1129
@@ -1157,7 +1157,7 @@ static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
1157 1157
1158 if (!enable_hs) 1158 if (!enable_hs)
1159 return cmd_status(sk, hdev->id, MGMT_OP_SET_HS, 1159 return cmd_status(sk, hdev->id, MGMT_OP_SET_HS,
1160 MGMT_STATUS_NOT_SUPPORTED); 1160 MGMT_STATUS_NOT_SUPPORTED);
1161 1161
1162 if (cp->val) 1162 if (cp->val)
1163 set_bit(HCI_HS_ENABLED, &hdev->dev_flags); 1163 set_bit(HCI_HS_ENABLED, &hdev->dev_flags);
@@ -1181,7 +1181,7 @@ static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
1181 1181
1182 if (!enable_le || !(hdev->features[4] & LMP_LE)) { 1182 if (!enable_le || !(hdev->features[4] & LMP_LE)) {
1183 err = cmd_status(sk, hdev->id, MGMT_OP_SET_LE, 1183 err = cmd_status(sk, hdev->id, MGMT_OP_SET_LE,
1184 MGMT_STATUS_NOT_SUPPORTED); 1184 MGMT_STATUS_NOT_SUPPORTED);
1185 goto unlock; 1185 goto unlock;
1186 } 1186 }
1187 1187
@@ -1208,7 +1208,7 @@ static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
1208 1208
1209 if (mgmt_pending_find(MGMT_OP_SET_LE, hdev)) { 1209 if (mgmt_pending_find(MGMT_OP_SET_LE, hdev)) {
1210 err = cmd_status(sk, hdev->id, MGMT_OP_SET_LE, 1210 err = cmd_status(sk, hdev->id, MGMT_OP_SET_LE,
1211 MGMT_STATUS_BUSY); 1211 MGMT_STATUS_BUSY);
1212 goto unlock; 1212 goto unlock;
1213 } 1213 }
1214 1214
@@ -1225,8 +1225,8 @@ static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
1225 hci_cp.simul = !!(hdev->features[6] & LMP_SIMUL_LE_BR); 1225 hci_cp.simul = !!(hdev->features[6] & LMP_SIMUL_LE_BR);
1226 } 1226 }
1227 1227
1228 err = hci_send_cmd(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, 1228 err = hci_send_cmd(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, sizeof(hci_cp),
1229 sizeof(hci_cp), &hci_cp); 1229 &hci_cp);
1230 if (err < 0) { 1230 if (err < 0) {
1231 mgmt_pending_remove(cmd); 1231 mgmt_pending_remove(cmd);
1232 goto unlock; 1232 goto unlock;
@@ -1250,7 +1250,7 @@ static int add_uuid(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
1250 1250
1251 if (test_bit(HCI_PENDING_CLASS, &hdev->dev_flags)) { 1251 if (test_bit(HCI_PENDING_CLASS, &hdev->dev_flags)) {
1252 err = cmd_status(sk, hdev->id, MGMT_OP_ADD_UUID, 1252 err = cmd_status(sk, hdev->id, MGMT_OP_ADD_UUID,
1253 MGMT_STATUS_BUSY); 1253 MGMT_STATUS_BUSY);
1254 goto failed; 1254 goto failed;
1255 } 1255 }
1256 1256
@@ -1275,7 +1275,7 @@ static int add_uuid(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
1275 1275
1276 if (!test_bit(HCI_PENDING_CLASS, &hdev->dev_flags)) { 1276 if (!test_bit(HCI_PENDING_CLASS, &hdev->dev_flags)) {
1277 err = cmd_complete(sk, hdev->id, MGMT_OP_ADD_UUID, 0, 1277 err = cmd_complete(sk, hdev->id, MGMT_OP_ADD_UUID, 0,
1278 hdev->dev_class, 3); 1278 hdev->dev_class, 3);
1279 goto failed; 1279 goto failed;
1280 } 1280 }
1281 1281
@@ -1318,7 +1318,7 @@ static int remove_uuid(struct sock *sk, struct hci_dev *hdev, void *data,
1318 1318
1319 if (test_bit(HCI_PENDING_CLASS, &hdev->dev_flags)) { 1319 if (test_bit(HCI_PENDING_CLASS, &hdev->dev_flags)) {
1320 err = cmd_status(sk, hdev->id, MGMT_OP_REMOVE_UUID, 1320 err = cmd_status(sk, hdev->id, MGMT_OP_REMOVE_UUID,
1321 MGMT_STATUS_BUSY); 1321 MGMT_STATUS_BUSY);
1322 goto unlock; 1322 goto unlock;
1323 } 1323 }
1324 1324
@@ -1327,7 +1327,7 @@ static int remove_uuid(struct sock *sk, struct hci_dev *hdev, void *data,
1327 1327
1328 if (enable_service_cache(hdev)) { 1328 if (enable_service_cache(hdev)) {
1329 err = cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_UUID, 1329 err = cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_UUID,
1330 0, hdev->dev_class, 3); 1330 0, hdev->dev_class, 3);
1331 goto unlock; 1331 goto unlock;
1332 } 1332 }
1333 1333
@@ -1348,7 +1348,7 @@ static int remove_uuid(struct sock *sk, struct hci_dev *hdev, void *data,
1348 1348
1349 if (found == 0) { 1349 if (found == 0) {
1350 err = cmd_status(sk, hdev->id, MGMT_OP_REMOVE_UUID, 1350 err = cmd_status(sk, hdev->id, MGMT_OP_REMOVE_UUID,
1351 MGMT_STATUS_INVALID_PARAMS); 1351 MGMT_STATUS_INVALID_PARAMS);
1352 goto unlock; 1352 goto unlock;
1353 } 1353 }
1354 1354
@@ -1363,7 +1363,7 @@ update_class:
1363 1363
1364 if (!test_bit(HCI_PENDING_CLASS, &hdev->dev_flags)) { 1364 if (!test_bit(HCI_PENDING_CLASS, &hdev->dev_flags)) {
1365 err = cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_UUID, 0, 1365 err = cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_UUID, 0,
1366 hdev->dev_class, 3); 1366 hdev->dev_class, 3);
1367 goto unlock; 1367 goto unlock;
1368 } 1368 }
1369 1369
@@ -1379,7 +1379,7 @@ unlock:
1379} 1379}
1380 1380
1381static int set_dev_class(struct sock *sk, struct hci_dev *hdev, void *data, 1381static int set_dev_class(struct sock *sk, struct hci_dev *hdev, void *data,
1382 u16 len) 1382 u16 len)
1383{ 1383{
1384 struct mgmt_cp_set_dev_class *cp = data; 1384 struct mgmt_cp_set_dev_class *cp = data;
1385 struct pending_cmd *cmd; 1385 struct pending_cmd *cmd;
@@ -1391,7 +1391,7 @@ static int set_dev_class(struct sock *sk, struct hci_dev *hdev, void *data,
1391 1391
1392 if (test_bit(HCI_PENDING_CLASS, &hdev->dev_flags)) { 1392 if (test_bit(HCI_PENDING_CLASS, &hdev->dev_flags)) {
1393 err = cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, 1393 err = cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS,
1394 MGMT_STATUS_BUSY); 1394 MGMT_STATUS_BUSY);
1395 goto unlock; 1395 goto unlock;
1396 } 1396 }
1397 1397
@@ -1400,7 +1400,7 @@ static int set_dev_class(struct sock *sk, struct hci_dev *hdev, void *data,
1400 1400
1401 if (!hdev_is_powered(hdev)) { 1401 if (!hdev_is_powered(hdev)) {
1402 err = cmd_complete(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, 0, 1402 err = cmd_complete(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, 0,
1403 hdev->dev_class, 3); 1403 hdev->dev_class, 3);
1404 goto unlock; 1404 goto unlock;
1405 } 1405 }
1406 1406
@@ -1417,7 +1417,7 @@ static int set_dev_class(struct sock *sk, struct hci_dev *hdev, void *data,
1417 1417
1418 if (!test_bit(HCI_PENDING_CLASS, &hdev->dev_flags)) { 1418 if (!test_bit(HCI_PENDING_CLASS, &hdev->dev_flags)) {
1419 err = cmd_complete(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, 0, 1419 err = cmd_complete(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, 0,
1420 hdev->dev_class, 3); 1420 hdev->dev_class, 3);
1421 goto unlock; 1421 goto unlock;
1422 } 1422 }
1423 1423
@@ -1447,7 +1447,7 @@ static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data,
1447 BT_ERR("load_link_keys: expected %u bytes, got %u bytes", 1447 BT_ERR("load_link_keys: expected %u bytes, got %u bytes",
1448 len, expected_len); 1448 len, expected_len);
1449 return cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, 1449 return cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS,
1450 MGMT_STATUS_INVALID_PARAMS); 1450 MGMT_STATUS_INVALID_PARAMS);
1451 } 1451 }
1452 1452
1453 BT_DBG("%s debug_keys %u key_count %u", hdev->name, cp->debug_keys, 1453 BT_DBG("%s debug_keys %u key_count %u", hdev->name, cp->debug_keys,
@@ -1468,7 +1468,7 @@ static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data,
1468 struct mgmt_link_key_info *key = &cp->keys[i]; 1468 struct mgmt_link_key_info *key = &cp->keys[i];
1469 1469
1470 hci_add_link_key(hdev, NULL, 0, &key->addr.bdaddr, key->val, 1470 hci_add_link_key(hdev, NULL, 0, &key->addr.bdaddr, key->val,
1471 key->type, key->pin_len); 1471 key->type, key->pin_len);
1472 } 1472 }
1473 1473
1474 cmd_complete(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, 0, NULL, 0); 1474 cmd_complete(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, 0, NULL, 0);
@@ -1479,7 +1479,7 @@ static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data,
1479} 1479}
1480 1480
1481static int device_unpaired(struct hci_dev *hdev, bdaddr_t *bdaddr, 1481static int device_unpaired(struct hci_dev *hdev, bdaddr_t *bdaddr,
1482 u8 addr_type, struct sock *skip_sk) 1482 u8 addr_type, struct sock *skip_sk)
1483{ 1483{
1484 struct mgmt_ev_device_unpaired ev; 1484 struct mgmt_ev_device_unpaired ev;
1485 1485
@@ -1487,11 +1487,11 @@ static int device_unpaired(struct hci_dev *hdev, bdaddr_t *bdaddr,
1487 ev.addr.type = addr_type; 1487 ev.addr.type = addr_type;
1488 1488
1489 return mgmt_event(MGMT_EV_DEVICE_UNPAIRED, hdev, &ev, sizeof(ev), 1489 return mgmt_event(MGMT_EV_DEVICE_UNPAIRED, hdev, &ev, sizeof(ev),
1490 skip_sk); 1490 skip_sk);
1491} 1491}
1492 1492
1493static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data, 1493static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data,
1494 u16 len) 1494 u16 len)
1495{ 1495{
1496 struct mgmt_cp_unpair_device *cp = data; 1496 struct mgmt_cp_unpair_device *cp = data;
1497 struct mgmt_rp_unpair_device rp; 1497 struct mgmt_rp_unpair_device rp;
@@ -1508,8 +1508,7 @@ static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data,
1508 1508
1509 if (!hdev_is_powered(hdev)) { 1509 if (!hdev_is_powered(hdev)) {
1510 err = cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, 1510 err = cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE,
1511 MGMT_STATUS_NOT_POWERED, 1511 MGMT_STATUS_NOT_POWERED, &rp, sizeof(rp));
1512 &rp, sizeof(rp));
1513 goto unlock; 1512 goto unlock;
1514 } 1513 }
1515 1514
@@ -1520,8 +1519,7 @@ static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data,
1520 1519
1521 if (err < 0) { 1520 if (err < 0) {
1522 err = cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, 1521 err = cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE,
1523 MGMT_STATUS_NOT_PAIRED, 1522 MGMT_STATUS_NOT_PAIRED, &rp, sizeof(rp));
1524 &rp, sizeof(rp));
1525 goto unlock; 1523 goto unlock;
1526 } 1524 }
1527 1525
@@ -1538,13 +1536,13 @@ static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data,
1538 1536
1539 if (!conn) { 1537 if (!conn) {
1540 err = cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, 0, 1538 err = cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, 0,
1541 &rp, sizeof(rp)); 1539 &rp, sizeof(rp));
1542 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, sk); 1540 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, sk);
1543 goto unlock; 1541 goto unlock;
1544 } 1542 }
1545 1543
1546 cmd = mgmt_pending_add(sk, MGMT_OP_UNPAIR_DEVICE, hdev, cp, 1544 cmd = mgmt_pending_add(sk, MGMT_OP_UNPAIR_DEVICE, hdev, cp,
1547 sizeof(*cp)); 1545 sizeof(*cp));
1548 if (!cmd) { 1546 if (!cmd) {
1549 err = -ENOMEM; 1547 err = -ENOMEM;
1550 goto unlock; 1548 goto unlock;
@@ -1562,7 +1560,7 @@ unlock:
1562} 1560}
1563 1561
1564static int disconnect(struct sock *sk, struct hci_dev *hdev, void *data, 1562static int disconnect(struct sock *sk, struct hci_dev *hdev, void *data,
1565 u16 len) 1563 u16 len)
1566{ 1564{
1567 struct mgmt_cp_disconnect *cp = data; 1565 struct mgmt_cp_disconnect *cp = data;
1568 struct hci_cp_disconnect dc; 1566 struct hci_cp_disconnect dc;
@@ -1576,13 +1574,13 @@ static int disconnect(struct sock *sk, struct hci_dev *hdev, void *data,
1576 1574
1577 if (!test_bit(HCI_UP, &hdev->flags)) { 1575 if (!test_bit(HCI_UP, &hdev->flags)) {
1578 err = cmd_status(sk, hdev->id, MGMT_OP_DISCONNECT, 1576 err = cmd_status(sk, hdev->id, MGMT_OP_DISCONNECT,
1579 MGMT_STATUS_NOT_POWERED); 1577 MGMT_STATUS_NOT_POWERED);
1580 goto failed; 1578 goto failed;
1581 } 1579 }
1582 1580
1583 if (mgmt_pending_find(MGMT_OP_DISCONNECT, hdev)) { 1581 if (mgmt_pending_find(MGMT_OP_DISCONNECT, hdev)) {
1584 err = cmd_status(sk, hdev->id, MGMT_OP_DISCONNECT, 1582 err = cmd_status(sk, hdev->id, MGMT_OP_DISCONNECT,
1585 MGMT_STATUS_BUSY); 1583 MGMT_STATUS_BUSY);
1586 goto failed; 1584 goto failed;
1587 } 1585 }
1588 1586
@@ -1593,7 +1591,7 @@ static int disconnect(struct sock *sk, struct hci_dev *hdev, void *data,
1593 1591
1594 if (!conn) { 1592 if (!conn) {
1595 err = cmd_status(sk, hdev->id, MGMT_OP_DISCONNECT, 1593 err = cmd_status(sk, hdev->id, MGMT_OP_DISCONNECT,
1596 MGMT_STATUS_NOT_CONNECTED); 1594 MGMT_STATUS_NOT_CONNECTED);
1597 goto failed; 1595 goto failed;
1598 } 1596 }
1599 1597
@@ -1634,8 +1632,8 @@ static u8 link_to_mgmt(u8 link_type, u8 addr_type)
1634 } 1632 }
1635} 1633}
1636 1634
1637static int get_connections(struct sock *sk, struct hci_dev *hdev, 1635static int get_connections(struct sock *sk, struct hci_dev *hdev, void *data,
1638 void *data, u16 data_len) 1636 u16 data_len)
1639{ 1637{
1640 struct mgmt_rp_get_connections *rp; 1638 struct mgmt_rp_get_connections *rp;
1641 struct hci_conn *c; 1639 struct hci_conn *c;
@@ -1649,7 +1647,7 @@ static int get_connections(struct sock *sk, struct hci_dev *hdev,
1649 1647
1650 if (!hdev_is_powered(hdev)) { 1648 if (!hdev_is_powered(hdev)) {
1651 err = cmd_status(sk, hdev->id, MGMT_OP_GET_CONNECTIONS, 1649 err = cmd_status(sk, hdev->id, MGMT_OP_GET_CONNECTIONS,
1652 MGMT_STATUS_NOT_POWERED); 1650 MGMT_STATUS_NOT_POWERED);
1653 goto unlock; 1651 goto unlock;
1654 } 1652 }
1655 1653
@@ -1683,7 +1681,7 @@ static int get_connections(struct sock *sk, struct hci_dev *hdev,
1683 rp_len = sizeof(*rp) + (i * sizeof(struct mgmt_addr_info)); 1681 rp_len = sizeof(*rp) + (i * sizeof(struct mgmt_addr_info));
1684 1682
1685 err = cmd_complete(sk, hdev->id, MGMT_OP_GET_CONNECTIONS, 0, rp, 1683 err = cmd_complete(sk, hdev->id, MGMT_OP_GET_CONNECTIONS, 0, rp,
1686 rp_len); 1684 rp_len);
1687 1685
1688 kfree(rp); 1686 kfree(rp);
1689 1687
@@ -1693,18 +1691,18 @@ unlock:
1693} 1691}
1694 1692
1695static int send_pin_code_neg_reply(struct sock *sk, struct hci_dev *hdev, 1693static int send_pin_code_neg_reply(struct sock *sk, struct hci_dev *hdev,
1696 struct mgmt_cp_pin_code_neg_reply *cp) 1694 struct mgmt_cp_pin_code_neg_reply *cp)
1697{ 1695{
1698 struct pending_cmd *cmd; 1696 struct pending_cmd *cmd;
1699 int err; 1697 int err;
1700 1698
1701 cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_NEG_REPLY, hdev, cp, 1699 cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_NEG_REPLY, hdev, cp,
1702 sizeof(*cp)); 1700 sizeof(*cp));
1703 if (!cmd) 1701 if (!cmd)
1704 return -ENOMEM; 1702 return -ENOMEM;
1705 1703
1706 err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, 1704 err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY,
1707 sizeof(cp->addr.bdaddr), &cp->addr.bdaddr); 1705 sizeof(cp->addr.bdaddr), &cp->addr.bdaddr);
1708 if (err < 0) 1706 if (err < 0)
1709 mgmt_pending_remove(cmd); 1707 mgmt_pending_remove(cmd);
1710 1708
@@ -1712,7 +1710,7 @@ static int send_pin_code_neg_reply(struct sock *sk, struct hci_dev *hdev,
1712} 1710}
1713 1711
1714static int pin_code_reply(struct sock *sk, struct hci_dev *hdev, void *data, 1712static int pin_code_reply(struct sock *sk, struct hci_dev *hdev, void *data,
1715 u16 len) 1713 u16 len)
1716{ 1714{
1717 struct hci_conn *conn; 1715 struct hci_conn *conn;
1718 struct mgmt_cp_pin_code_reply *cp = data; 1716 struct mgmt_cp_pin_code_reply *cp = data;
@@ -1726,14 +1724,14 @@ static int pin_code_reply(struct sock *sk, struct hci_dev *hdev, void *data,
1726 1724
1727 if (!hdev_is_powered(hdev)) { 1725 if (!hdev_is_powered(hdev)) {
1728 err = cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, 1726 err = cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY,
1729 MGMT_STATUS_NOT_POWERED); 1727 MGMT_STATUS_NOT_POWERED);
1730 goto failed; 1728 goto failed;
1731 } 1729 }
1732 1730
1733 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->addr.bdaddr); 1731 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->addr.bdaddr);
1734 if (!conn) { 1732 if (!conn) {
1735 err = cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, 1733 err = cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY,
1736 MGMT_STATUS_NOT_CONNECTED); 1734 MGMT_STATUS_NOT_CONNECTED);
1737 goto failed; 1735 goto failed;
1738 } 1736 }
1739 1737
@@ -1747,7 +1745,7 @@ static int pin_code_reply(struct sock *sk, struct hci_dev *hdev, void *data,
1747 err = send_pin_code_neg_reply(sk, hdev, &ncp); 1745 err = send_pin_code_neg_reply(sk, hdev, &ncp);
1748 if (err >= 0) 1746 if (err >= 0)
1749 err = cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, 1747 err = cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY,
1750 MGMT_STATUS_INVALID_PARAMS); 1748 MGMT_STATUS_INVALID_PARAMS);
1751 1749
1752 goto failed; 1750 goto failed;
1753 } 1751 }
@@ -1772,7 +1770,7 @@ failed:
1772} 1770}
1773 1771
1774static int pin_code_neg_reply(struct sock *sk, struct hci_dev *hdev, 1772static int pin_code_neg_reply(struct sock *sk, struct hci_dev *hdev,
1775 void *data, u16 len) 1773 void *data, u16 len)
1776{ 1774{
1777 struct mgmt_cp_pin_code_neg_reply *cp = data; 1775 struct mgmt_cp_pin_code_neg_reply *cp = data;
1778 int err; 1776 int err;
@@ -1783,7 +1781,7 @@ static int pin_code_neg_reply(struct sock *sk, struct hci_dev *hdev,
1783 1781
1784 if (!hdev_is_powered(hdev)) { 1782 if (!hdev_is_powered(hdev)) {
1785 err = cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_NEG_REPLY, 1783 err = cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_NEG_REPLY,
1786 MGMT_STATUS_NOT_POWERED); 1784 MGMT_STATUS_NOT_POWERED);
1787 goto failed; 1785 goto failed;
1788 } 1786 }
1789 1787
@@ -1794,8 +1792,8 @@ failed:
1794 return err; 1792 return err;
1795} 1793}
1796 1794
1797static int set_io_capability(struct sock *sk, struct hci_dev *hdev, 1795static int set_io_capability(struct sock *sk, struct hci_dev *hdev, void *data,
1798 void *data, u16 len) 1796 u16 len)
1799{ 1797{
1800 struct mgmt_cp_set_io_capability *cp = data; 1798 struct mgmt_cp_set_io_capability *cp = data;
1801 1799
@@ -1810,8 +1808,8 @@ static int set_io_capability(struct sock *sk, struct hci_dev *hdev,
1810 1808
1811 hci_dev_unlock(hdev); 1809 hci_dev_unlock(hdev);
1812 1810
1813 return cmd_complete(sk, hdev->id, MGMT_OP_SET_IO_CAPABILITY, 0, 1811 return cmd_complete(sk, hdev->id, MGMT_OP_SET_IO_CAPABILITY, 0, NULL,
1814 NULL, 0); 1812 0);
1815} 1813}
1816 1814
1817static inline struct pending_cmd *find_pairing(struct hci_conn *conn) 1815static inline struct pending_cmd *find_pairing(struct hci_conn *conn)
@@ -1841,7 +1839,7 @@ static void pairing_complete(struct pending_cmd *cmd, u8 status)
1841 rp.addr.type = link_to_mgmt(conn->type, conn->dst_type); 1839 rp.addr.type = link_to_mgmt(conn->type, conn->dst_type);
1842 1840
1843 cmd_complete(cmd->sk, cmd->index, MGMT_OP_PAIR_DEVICE, status, 1841 cmd_complete(cmd->sk, cmd->index, MGMT_OP_PAIR_DEVICE, status,
1844 &rp, sizeof(rp)); 1842 &rp, sizeof(rp));
1845 1843
1846 /* So we don't get further callbacks for this connection */ 1844 /* So we don't get further callbacks for this connection */
1847 conn->connect_cfm_cb = NULL; 1845 conn->connect_cfm_cb = NULL;
@@ -1867,7 +1865,7 @@ static void pairing_complete_cb(struct hci_conn *conn, u8 status)
1867} 1865}
1868 1866
1869static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data, 1867static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
1870 u16 len) 1868 u16 len)
1871{ 1869{
1872 struct mgmt_cp_pair_device *cp = data; 1870 struct mgmt_cp_pair_device *cp = data;
1873 struct mgmt_rp_pair_device rp; 1871 struct mgmt_rp_pair_device rp;
@@ -1882,7 +1880,7 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
1882 1880
1883 if (!hdev_is_powered(hdev)) { 1881 if (!hdev_is_powered(hdev)) {
1884 err = cmd_status(sk, hdev->id, MGMT_OP_PAIR_DEVICE, 1882 err = cmd_status(sk, hdev->id, MGMT_OP_PAIR_DEVICE,
1885 MGMT_STATUS_NOT_POWERED); 1883 MGMT_STATUS_NOT_POWERED);
1886 goto unlock; 1884 goto unlock;
1887 } 1885 }
1888 1886
@@ -1894,10 +1892,10 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
1894 1892
1895 if (cp->addr.type == MGMT_ADDR_BREDR) 1893 if (cp->addr.type == MGMT_ADDR_BREDR)
1896 conn = hci_connect(hdev, ACL_LINK, &cp->addr.bdaddr, sec_level, 1894 conn = hci_connect(hdev, ACL_LINK, &cp->addr.bdaddr, sec_level,
1897 auth_type); 1895 auth_type);
1898 else 1896 else
1899 conn = hci_connect(hdev, LE_LINK, &cp->addr.bdaddr, sec_level, 1897 conn = hci_connect(hdev, LE_LINK, &cp->addr.bdaddr, sec_level,
1900 auth_type); 1898 auth_type);
1901 1899
1902 memset(&rp, 0, sizeof(rp)); 1900 memset(&rp, 0, sizeof(rp));
1903 bacpy(&rp.addr.bdaddr, &cp->addr.bdaddr); 1901 bacpy(&rp.addr.bdaddr, &cp->addr.bdaddr);
@@ -1905,15 +1903,15 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
1905 1903
1906 if (IS_ERR(conn)) { 1904 if (IS_ERR(conn)) {
1907 err = cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, 1905 err = cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE,
1908 MGMT_STATUS_CONNECT_FAILED, 1906 MGMT_STATUS_CONNECT_FAILED, &rp,
1909 &rp, sizeof(rp)); 1907 sizeof(rp));
1910 goto unlock; 1908 goto unlock;
1911 } 1909 }
1912 1910
1913 if (conn->connect_cfm_cb) { 1911 if (conn->connect_cfm_cb) {
1914 hci_conn_put(conn); 1912 hci_conn_put(conn);
1915 err = cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, 1913 err = cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE,
1916 MGMT_STATUS_BUSY, &rp, sizeof(rp)); 1914 MGMT_STATUS_BUSY, &rp, sizeof(rp));
1917 goto unlock; 1915 goto unlock;
1918 } 1916 }
1919 1917
@@ -1944,8 +1942,8 @@ unlock:
1944 return err; 1942 return err;
1945} 1943}
1946 1944
1947static int cancel_pair_device(struct sock *sk, struct hci_dev *hdev, 1945static int cancel_pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
1948 void *data, u16 len) 1946 u16 len)
1949{ 1947{
1950 struct mgmt_addr_info *addr = data; 1948 struct mgmt_addr_info *addr = data;
1951 struct pending_cmd *cmd; 1949 struct pending_cmd *cmd;
@@ -1958,14 +1956,14 @@ static int cancel_pair_device(struct sock *sk, struct hci_dev *hdev,
1958 1956
1959 if (!hdev_is_powered(hdev)) { 1957 if (!hdev_is_powered(hdev)) {
1960 err = cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, 1958 err = cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE,
1961 MGMT_STATUS_NOT_POWERED); 1959 MGMT_STATUS_NOT_POWERED);
1962 goto unlock; 1960 goto unlock;
1963 } 1961 }
1964 1962
1965 cmd = mgmt_pending_find(MGMT_OP_PAIR_DEVICE, hdev); 1963 cmd = mgmt_pending_find(MGMT_OP_PAIR_DEVICE, hdev);
1966 if (!cmd) { 1964 if (!cmd) {
1967 err = cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, 1965 err = cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE,
1968 MGMT_STATUS_INVALID_PARAMS); 1966 MGMT_STATUS_INVALID_PARAMS);
1969 goto unlock; 1967 goto unlock;
1970 } 1968 }
1971 1969
@@ -1973,22 +1971,22 @@ static int cancel_pair_device(struct sock *sk, struct hci_dev *hdev,
1973 1971
1974 if (bacmp(&addr->bdaddr, &conn->dst) != 0) { 1972 if (bacmp(&addr->bdaddr, &conn->dst) != 0) {
1975 err = cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, 1973 err = cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE,
1976 MGMT_STATUS_INVALID_PARAMS); 1974 MGMT_STATUS_INVALID_PARAMS);
1977 goto unlock; 1975 goto unlock;
1978 } 1976 }
1979 1977
1980 pairing_complete(cmd, MGMT_STATUS_CANCELLED); 1978 pairing_complete(cmd, MGMT_STATUS_CANCELLED);
1981 1979
1982 err = cmd_complete(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, 0, 1980 err = cmd_complete(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, 0,
1983 addr, sizeof(*addr)); 1981 addr, sizeof(*addr));
1984unlock: 1982unlock:
1985 hci_dev_unlock(hdev); 1983 hci_dev_unlock(hdev);
1986 return err; 1984 return err;
1987} 1985}
1988 1986
1989static int user_pairing_resp(struct sock *sk, struct hci_dev *hdev, 1987static int user_pairing_resp(struct sock *sk, struct hci_dev *hdev,
1990 bdaddr_t *bdaddr, u8 type, u16 mgmt_op, 1988 bdaddr_t *bdaddr, u8 type, u16 mgmt_op,
1991 u16 hci_op, __le32 passkey) 1989 u16 hci_op, __le32 passkey)
1992{ 1990{
1993 struct pending_cmd *cmd; 1991 struct pending_cmd *cmd;
1994 struct hci_conn *conn; 1992 struct hci_conn *conn;
@@ -1998,7 +1996,7 @@ static int user_pairing_resp(struct sock *sk, struct hci_dev *hdev,
1998 1996
1999 if (!hdev_is_powered(hdev)) { 1997 if (!hdev_is_powered(hdev)) {
2000 err = cmd_status(sk, hdev->id, mgmt_op, 1998 err = cmd_status(sk, hdev->id, mgmt_op,
2001 MGMT_STATUS_NOT_POWERED); 1999 MGMT_STATUS_NOT_POWERED);
2002 goto done; 2000 goto done;
2003 } 2001 }
2004 2002
@@ -2009,7 +2007,7 @@ static int user_pairing_resp(struct sock *sk, struct hci_dev *hdev,
2009 2007
2010 if (!conn) { 2008 if (!conn) {
2011 err = cmd_status(sk, hdev->id, mgmt_op, 2009 err = cmd_status(sk, hdev->id, mgmt_op,
2012 MGMT_STATUS_NOT_CONNECTED); 2010 MGMT_STATUS_NOT_CONNECTED);
2013 goto done; 2011 goto done;
2014 } 2012 }
2015 2013
@@ -2019,10 +2017,10 @@ static int user_pairing_resp(struct sock *sk, struct hci_dev *hdev,
2019 2017
2020 if (!err) 2018 if (!err)
2021 err = cmd_status(sk, hdev->id, mgmt_op, 2019 err = cmd_status(sk, hdev->id, mgmt_op,
2022 MGMT_STATUS_SUCCESS); 2020 MGMT_STATUS_SUCCESS);
2023 else 2021 else
2024 err = cmd_status(sk, hdev->id, mgmt_op, 2022 err = cmd_status(sk, hdev->id, mgmt_op,
2025 MGMT_STATUS_FAILED); 2023 MGMT_STATUS_FAILED);
2026 2024
2027 goto done; 2025 goto done;
2028 } 2026 }
@@ -2051,8 +2049,8 @@ done:
2051 return err; 2049 return err;
2052} 2050}
2053 2051
2054static int user_confirm_reply(struct sock *sk, struct hci_dev *hdev, 2052static int user_confirm_reply(struct sock *sk, struct hci_dev *hdev, void *data,
2055 void *data, u16 len) 2053 u16 len)
2056{ 2054{
2057 struct mgmt_cp_user_confirm_reply *cp = data; 2055 struct mgmt_cp_user_confirm_reply *cp = data;
2058 2056
@@ -2060,48 +2058,47 @@ static int user_confirm_reply(struct sock *sk, struct hci_dev *hdev,
2060 2058
2061 if (len != sizeof(*cp)) 2059 if (len != sizeof(*cp))
2062 return cmd_status(sk, hdev->id, MGMT_OP_USER_CONFIRM_REPLY, 2060 return cmd_status(sk, hdev->id, MGMT_OP_USER_CONFIRM_REPLY,
2063 MGMT_STATUS_INVALID_PARAMS); 2061 MGMT_STATUS_INVALID_PARAMS);
2064 2062
2065 return user_pairing_resp(sk, hdev, &cp->addr.bdaddr, cp->addr.type, 2063 return user_pairing_resp(sk, hdev, &cp->addr.bdaddr, cp->addr.type,
2066 MGMT_OP_USER_CONFIRM_REPLY, 2064 MGMT_OP_USER_CONFIRM_REPLY,
2067 HCI_OP_USER_CONFIRM_REPLY, 0); 2065 HCI_OP_USER_CONFIRM_REPLY, 0);
2068} 2066}
2069 2067
2070static int user_confirm_neg_reply(struct sock *sk, struct hci_dev *hdev, 2068static int user_confirm_neg_reply(struct sock *sk, struct hci_dev *hdev,
2071 void *data, u16 len) 2069 void *data, u16 len)
2072{ 2070{
2073 struct mgmt_cp_user_confirm_neg_reply *cp = data; 2071 struct mgmt_cp_user_confirm_neg_reply *cp = data;
2074 2072
2075 BT_DBG(""); 2073 BT_DBG("");
2076 2074
2077 return user_pairing_resp(sk, hdev, &cp->addr.bdaddr, cp->addr.type, 2075 return user_pairing_resp(sk, hdev, &cp->addr.bdaddr, cp->addr.type,
2078 MGMT_OP_USER_CONFIRM_NEG_REPLY, 2076 MGMT_OP_USER_CONFIRM_NEG_REPLY,
2079 HCI_OP_USER_CONFIRM_NEG_REPLY, 0); 2077 HCI_OP_USER_CONFIRM_NEG_REPLY, 0);
2080} 2078}
2081 2079
2082static int user_passkey_reply(struct sock *sk, struct hci_dev *hdev, 2080static int user_passkey_reply(struct sock *sk, struct hci_dev *hdev, void *data,
2083 void *data, u16 len) 2081 u16 len)
2084{ 2082{
2085 struct mgmt_cp_user_passkey_reply *cp = data; 2083 struct mgmt_cp_user_passkey_reply *cp = data;
2086 2084
2087 BT_DBG(""); 2085 BT_DBG("");
2088 2086
2089 return user_pairing_resp(sk, hdev, &cp->addr.bdaddr, cp->addr.type, 2087 return user_pairing_resp(sk, hdev, &cp->addr.bdaddr, cp->addr.type,
2090 MGMT_OP_USER_PASSKEY_REPLY, 2088 MGMT_OP_USER_PASSKEY_REPLY,
2091 HCI_OP_USER_PASSKEY_REPLY, 2089 HCI_OP_USER_PASSKEY_REPLY, cp->passkey);
2092 cp->passkey);
2093} 2090}
2094 2091
2095static int user_passkey_neg_reply(struct sock *sk, struct hci_dev *hdev, 2092static int user_passkey_neg_reply(struct sock *sk, struct hci_dev *hdev,
2096 void *data, u16 len) 2093 void *data, u16 len)
2097{ 2094{
2098 struct mgmt_cp_user_passkey_neg_reply *cp = data; 2095 struct mgmt_cp_user_passkey_neg_reply *cp = data;
2099 2096
2100 BT_DBG(""); 2097 BT_DBG("");
2101 2098
2102 return user_pairing_resp(sk, hdev, &cp->addr.bdaddr, cp->addr.type, 2099 return user_pairing_resp(sk, hdev, &cp->addr.bdaddr, cp->addr.type,
2103 MGMT_OP_USER_PASSKEY_NEG_REPLY, 2100 MGMT_OP_USER_PASSKEY_NEG_REPLY,
2104 HCI_OP_USER_PASSKEY_NEG_REPLY, 0); 2101 HCI_OP_USER_PASSKEY_NEG_REPLY, 0);
2105} 2102}
2106 2103
2107static int update_name(struct hci_dev *hdev, const char *name) 2104static int update_name(struct hci_dev *hdev, const char *name)
@@ -2114,7 +2111,7 @@ static int update_name(struct hci_dev *hdev, const char *name)
2114} 2111}
2115 2112
2116static int set_local_name(struct sock *sk, struct hci_dev *hdev, void *data, 2113static int set_local_name(struct sock *sk, struct hci_dev *hdev, void *data,
2117 u16 len) 2114 u16 len)
2118{ 2115{
2119 struct mgmt_cp_set_local_name *cp = data; 2116 struct mgmt_cp_set_local_name *cp = data;
2120 struct pending_cmd *cmd; 2117 struct pending_cmd *cmd;
@@ -2130,12 +2127,12 @@ static int set_local_name(struct sock *sk, struct hci_dev *hdev, void *data,
2130 memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name)); 2127 memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name));
2131 2128
2132 err = cmd_complete(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, 2129 err = cmd_complete(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0,
2133 data, len); 2130 data, len);
2134 if (err < 0) 2131 if (err < 0)
2135 goto failed; 2132 goto failed;
2136 2133
2137 err = mgmt_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, data, len, 2134 err = mgmt_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, data, len,
2138 sk); 2135 sk);
2139 2136
2140 goto failed; 2137 goto failed;
2141 } 2138 }
@@ -2156,7 +2153,7 @@ failed:
2156} 2153}
2157 2154
2158static int read_local_oob_data(struct sock *sk, struct hci_dev *hdev, 2155static int read_local_oob_data(struct sock *sk, struct hci_dev *hdev,
2159 void *data, u16 data_len) 2156 void *data, u16 data_len)
2160{ 2157{
2161 struct pending_cmd *cmd; 2158 struct pending_cmd *cmd;
2162 int err; 2159 int err;
@@ -2167,19 +2164,19 @@ static int read_local_oob_data(struct sock *sk, struct hci_dev *hdev,
2167 2164
2168 if (!hdev_is_powered(hdev)) { 2165 if (!hdev_is_powered(hdev)) {
2169 err = cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, 2166 err = cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA,
2170 MGMT_STATUS_NOT_POWERED); 2167 MGMT_STATUS_NOT_POWERED);
2171 goto unlock; 2168 goto unlock;
2172 } 2169 }
2173 2170
2174 if (!(hdev->features[6] & LMP_SIMPLE_PAIR)) { 2171 if (!(hdev->features[6] & LMP_SIMPLE_PAIR)) {
2175 err = cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, 2172 err = cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA,
2176 MGMT_STATUS_NOT_SUPPORTED); 2173 MGMT_STATUS_NOT_SUPPORTED);
2177 goto unlock; 2174 goto unlock;
2178 } 2175 }
2179 2176
2180 if (mgmt_pending_find(MGMT_OP_READ_LOCAL_OOB_DATA, hdev)) { 2177 if (mgmt_pending_find(MGMT_OP_READ_LOCAL_OOB_DATA, hdev)) {
2181 err = cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, 2178 err = cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA,
2182 MGMT_STATUS_BUSY); 2179 MGMT_STATUS_BUSY);
2183 goto unlock; 2180 goto unlock;
2184 } 2181 }
2185 2182
@@ -2199,7 +2196,7 @@ unlock:
2199} 2196}
2200 2197
2201static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev, 2198static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev,
2202 void *data, u16 len) 2199 void *data, u16 len)
2203{ 2200{
2204 struct mgmt_cp_add_remote_oob_data *cp = data; 2201 struct mgmt_cp_add_remote_oob_data *cp = data;
2205 u8 status; 2202 u8 status;
@@ -2211,20 +2208,20 @@ static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev,
2211 2208
2212 if (!hdev_is_powered(hdev)) { 2209 if (!hdev_is_powered(hdev)) {
2213 err = cmd_complete(sk, hdev->id, MGMT_OP_ADD_REMOTE_OOB_DATA, 2210 err = cmd_complete(sk, hdev->id, MGMT_OP_ADD_REMOTE_OOB_DATA,
2214 MGMT_STATUS_NOT_POWERED, 2211 MGMT_STATUS_NOT_POWERED, &cp->addr,
2215 &cp->addr, sizeof(cp->addr)); 2212 sizeof(cp->addr));
2216 goto unlock; 2213 goto unlock;
2217 } 2214 }
2218 2215
2219 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr, cp->hash, 2216 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr, cp->hash,
2220 cp->randomizer); 2217 cp->randomizer);
2221 if (err < 0) 2218 if (err < 0)
2222 status = MGMT_STATUS_FAILED; 2219 status = MGMT_STATUS_FAILED;
2223 else 2220 else
2224 status = 0; 2221 status = 0;
2225 2222
2226 err = cmd_complete(sk, hdev->id, MGMT_OP_ADD_REMOTE_OOB_DATA, status, 2223 err = cmd_complete(sk, hdev->id, MGMT_OP_ADD_REMOTE_OOB_DATA, status,
2227 &cp->addr, sizeof(cp->addr)); 2224 &cp->addr, sizeof(cp->addr));
2228 2225
2229unlock: 2226unlock:
2230 hci_dev_unlock(hdev); 2227 hci_dev_unlock(hdev);
@@ -2244,9 +2241,9 @@ static int remove_remote_oob_data(struct sock *sk, struct hci_dev *hdev,
2244 2241
2245 if (!hdev_is_powered(hdev)) { 2242 if (!hdev_is_powered(hdev)) {
2246 err = cmd_complete(sk, hdev->id, 2243 err = cmd_complete(sk, hdev->id,
2247 MGMT_OP_REMOVE_REMOTE_OOB_DATA, 2244 MGMT_OP_REMOVE_REMOTE_OOB_DATA,
2248 MGMT_STATUS_NOT_POWERED, 2245 MGMT_STATUS_NOT_POWERED, &cp->addr,
2249 &cp->addr, sizeof(cp->addr)); 2246 sizeof(cp->addr));
2250 goto unlock; 2247 goto unlock;
2251 } 2248 }
2252 2249
@@ -2257,7 +2254,7 @@ static int remove_remote_oob_data(struct sock *sk, struct hci_dev *hdev,
2257 status = 0; 2254 status = 0;
2258 2255
2259 err = cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_REMOTE_OOB_DATA, 2256 err = cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_REMOTE_OOB_DATA,
2260 status, &cp->addr, sizeof(cp->addr)); 2257 status, &cp->addr, sizeof(cp->addr));
2261 2258
2262unlock: 2259unlock:
2263 hci_dev_unlock(hdev); 2260 hci_dev_unlock(hdev);
@@ -2282,7 +2279,7 @@ int mgmt_interleaved_discovery(struct hci_dev *hdev)
2282} 2279}
2283 2280
2284static int start_discovery(struct sock *sk, struct hci_dev *hdev, 2281static int start_discovery(struct sock *sk, struct hci_dev *hdev,
2285 void *data, u16 len) 2282 void *data, u16 len)
2286{ 2283{
2287 struct mgmt_cp_start_discovery *cp = data; 2284 struct mgmt_cp_start_discovery *cp = data;
2288 struct pending_cmd *cmd; 2285 struct pending_cmd *cmd;
@@ -2294,13 +2291,13 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
2294 2291
2295 if (!hdev_is_powered(hdev)) { 2292 if (!hdev_is_powered(hdev)) {
2296 err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY, 2293 err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY,
2297 MGMT_STATUS_NOT_POWERED); 2294 MGMT_STATUS_NOT_POWERED);
2298 goto failed; 2295 goto failed;
2299 } 2296 }
2300 2297
2301 if (hdev->discovery.state != DISCOVERY_STOPPED) { 2298 if (hdev->discovery.state != DISCOVERY_STOPPED) {
2302 err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY, 2299 err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY,
2303 MGMT_STATUS_BUSY); 2300 MGMT_STATUS_BUSY);
2304 goto failed; 2301 goto failed;
2305 } 2302 }
2306 2303
@@ -2323,7 +2320,7 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
2323 case DISCOV_TYPE_LE: 2320 case DISCOV_TYPE_LE:
2324 if (lmp_host_le_capable(hdev)) 2321 if (lmp_host_le_capable(hdev))
2325 err = hci_le_scan(hdev, LE_SCAN_TYPE, LE_SCAN_INT, 2322 err = hci_le_scan(hdev, LE_SCAN_TYPE, LE_SCAN_INT,
2326 LE_SCAN_WIN, LE_SCAN_TIMEOUT_LE_ONLY); 2323 LE_SCAN_WIN, LE_SCAN_TIMEOUT_LE_ONLY);
2327 else 2324 else
2328 err = -ENOTSUPP; 2325 err = -ENOTSUPP;
2329 break; 2326 break;
@@ -2331,7 +2328,8 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
2331 case DISCOV_TYPE_INTERLEAVED: 2328 case DISCOV_TYPE_INTERLEAVED:
2332 if (lmp_host_le_capable(hdev) && lmp_bredr_capable(hdev)) 2329 if (lmp_host_le_capable(hdev) && lmp_bredr_capable(hdev))
2333 err = hci_le_scan(hdev, LE_SCAN_TYPE, LE_SCAN_INT, 2330 err = hci_le_scan(hdev, LE_SCAN_TYPE, LE_SCAN_INT,
2334 LE_SCAN_WIN, LE_SCAN_TIMEOUT_BREDR_LE); 2331 LE_SCAN_WIN,
2332 LE_SCAN_TIMEOUT_BREDR_LE);
2335 else 2333 else
2336 err = -ENOTSUPP; 2334 err = -ENOTSUPP;
2337 break; 2335 break;
@@ -2351,7 +2349,7 @@ failed:
2351} 2349}
2352 2350
2353static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data, 2351static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data,
2354 u16 len) 2352 u16 len)
2355{ 2353{
2356 struct mgmt_cp_stop_discovery *mgmt_cp = data; 2354 struct mgmt_cp_stop_discovery *mgmt_cp = data;
2357 struct pending_cmd *cmd; 2355 struct pending_cmd *cmd;
@@ -2365,15 +2363,15 @@ static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data,
2365 2363
2366 if (!hci_discovery_active(hdev)) { 2364 if (!hci_discovery_active(hdev)) {
2367 err = cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, 2365 err = cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY,
2368 MGMT_STATUS_REJECTED, 2366 MGMT_STATUS_REJECTED, &mgmt_cp->type,
2369 &mgmt_cp->type, sizeof(mgmt_cp->type)); 2367 sizeof(mgmt_cp->type));
2370 goto unlock; 2368 goto unlock;
2371 } 2369 }
2372 2370
2373 if (hdev->discovery.type != mgmt_cp->type) { 2371 if (hdev->discovery.type != mgmt_cp->type) {
2374 err = cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, 2372 err = cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY,
2375 MGMT_STATUS_INVALID_PARAMS, 2373 MGMT_STATUS_INVALID_PARAMS, &mgmt_cp->type,
2376 &mgmt_cp->type, sizeof(mgmt_cp->type)); 2374 sizeof(mgmt_cp->type));
2377 goto unlock; 2375 goto unlock;
2378 } 2376 }
2379 2377
@@ -2396,14 +2394,14 @@ static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data,
2396 if (!e) { 2394 if (!e) {
2397 mgmt_pending_remove(cmd); 2395 mgmt_pending_remove(cmd);
2398 err = cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, 0, 2396 err = cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, 0,
2399 &mgmt_cp->type, sizeof(mgmt_cp->type)); 2397 &mgmt_cp->type, sizeof(mgmt_cp->type));
2400 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); 2398 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
2401 goto unlock; 2399 goto unlock;
2402 } 2400 }
2403 2401
2404 bacpy(&cp.bdaddr, &e->data.bdaddr); 2402 bacpy(&cp.bdaddr, &e->data.bdaddr);
2405 err = hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ_CANCEL, 2403 err = hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ_CANCEL, sizeof(cp),
2406 sizeof(cp), &cp); 2404 &cp);
2407 if (err < 0) 2405 if (err < 0)
2408 mgmt_pending_remove(cmd); 2406 mgmt_pending_remove(cmd);
2409 else 2407 else
@@ -2415,7 +2413,7 @@ unlock:
2415} 2413}
2416 2414
2417static int confirm_name(struct sock *sk, struct hci_dev *hdev, void *data, 2415static int confirm_name(struct sock *sk, struct hci_dev *hdev, void *data,
2418 u16 len) 2416 u16 len)
2419{ 2417{
2420 struct mgmt_cp_confirm_name *cp = data; 2418 struct mgmt_cp_confirm_name *cp = data;
2421 struct inquiry_entry *e; 2419 struct inquiry_entry *e;
@@ -2427,14 +2425,14 @@ static int confirm_name(struct sock *sk, struct hci_dev *hdev, void *data,
2427 2425
2428 if (!hci_discovery_active(hdev)) { 2426 if (!hci_discovery_active(hdev)) {
2429 err = cmd_status(sk, hdev->id, MGMT_OP_CONFIRM_NAME, 2427 err = cmd_status(sk, hdev->id, MGMT_OP_CONFIRM_NAME,
2430 MGMT_STATUS_FAILED); 2428 MGMT_STATUS_FAILED);
2431 goto failed; 2429 goto failed;
2432 } 2430 }
2433 2431
2434 e = hci_inquiry_cache_lookup_unknown(hdev, &cp->addr.bdaddr); 2432 e = hci_inquiry_cache_lookup_unknown(hdev, &cp->addr.bdaddr);
2435 if (!e) { 2433 if (!e) {
2436 err = cmd_status(sk, hdev->id, MGMT_OP_CONFIRM_NAME, 2434 err = cmd_status(sk, hdev->id, MGMT_OP_CONFIRM_NAME,
2437 MGMT_STATUS_INVALID_PARAMS); 2435 MGMT_STATUS_INVALID_PARAMS);
2438 goto failed; 2436 goto failed;
2439 } 2437 }
2440 2438
@@ -2454,7 +2452,7 @@ failed:
2454} 2452}
2455 2453
2456static int block_device(struct sock *sk, struct hci_dev *hdev, void *data, 2454static int block_device(struct sock *sk, struct hci_dev *hdev, void *data,
2457 u16 len) 2455 u16 len)
2458{ 2456{
2459 struct mgmt_cp_block_device *cp = data; 2457 struct mgmt_cp_block_device *cp = data;
2460 u8 status; 2458 u8 status;
@@ -2471,7 +2469,7 @@ static int block_device(struct sock *sk, struct hci_dev *hdev, void *data,
2471 status = 0; 2469 status = 0;
2472 2470
2473 err = cmd_complete(sk, hdev->id, MGMT_OP_BLOCK_DEVICE, status, 2471 err = cmd_complete(sk, hdev->id, MGMT_OP_BLOCK_DEVICE, status,
2474 &cp->addr, sizeof(cp->addr)); 2472 &cp->addr, sizeof(cp->addr));
2475 2473
2476 hci_dev_unlock(hdev); 2474 hci_dev_unlock(hdev);
2477 2475
@@ -2479,7 +2477,7 @@ static int block_device(struct sock *sk, struct hci_dev *hdev, void *data,
2479} 2477}
2480 2478
2481static int unblock_device(struct sock *sk, struct hci_dev *hdev, void *data, 2479static int unblock_device(struct sock *sk, struct hci_dev *hdev, void *data,
2482 u16 len) 2480 u16 len)
2483{ 2481{
2484 struct mgmt_cp_unblock_device *cp = data; 2482 struct mgmt_cp_unblock_device *cp = data;
2485 u8 status; 2483 u8 status;
@@ -2496,7 +2494,7 @@ static int unblock_device(struct sock *sk, struct hci_dev *hdev, void *data,
2496 status = 0; 2494 status = 0;
2497 2495
2498 err = cmd_complete(sk, hdev->id, MGMT_OP_UNBLOCK_DEVICE, status, 2496 err = cmd_complete(sk, hdev->id, MGMT_OP_UNBLOCK_DEVICE, status,
2499 &cp->addr, sizeof(cp->addr)); 2497 &cp->addr, sizeof(cp->addr));
2500 2498
2501 hci_dev_unlock(hdev); 2499 hci_dev_unlock(hdev);
2502 2500
@@ -2504,7 +2502,7 @@ static int unblock_device(struct sock *sk, struct hci_dev *hdev, void *data,
2504} 2502}
2505 2503
2506static int set_fast_connectable(struct sock *sk, struct hci_dev *hdev, 2504static int set_fast_connectable(struct sock *sk, struct hci_dev *hdev,
2507 void *data, u16 len) 2505 void *data, u16 len)
2508{ 2506{
2509 struct mgmt_mode *cp = data; 2507 struct mgmt_mode *cp = data;
2510 struct hci_cp_write_page_scan_activity acp; 2508 struct hci_cp_write_page_scan_activity acp;
@@ -2515,11 +2513,11 @@ static int set_fast_connectable(struct sock *sk, struct hci_dev *hdev,
2515 2513
2516 if (!hdev_is_powered(hdev)) 2514 if (!hdev_is_powered(hdev))
2517 return cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, 2515 return cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE,
2518 MGMT_STATUS_NOT_POWERED); 2516 MGMT_STATUS_NOT_POWERED);
2519 2517
2520 if (!test_bit(HCI_CONNECTABLE, &hdev->dev_flags)) 2518 if (!test_bit(HCI_CONNECTABLE, &hdev->dev_flags))
2521 return cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, 2519 return cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE,
2522 MGMT_STATUS_REJECTED); 2520 MGMT_STATUS_REJECTED);
2523 2521
2524 hci_dev_lock(hdev); 2522 hci_dev_lock(hdev);
2525 2523
@@ -2533,30 +2531,30 @@ static int set_fast_connectable(struct sock *sk, struct hci_dev *hdev,
2533 2531
2534 acp.window = 0x0012; /* default 11.25 msec page scan window */ 2532 acp.window = 0x0012; /* default 11.25 msec page scan window */
2535 2533
2536 err = hci_send_cmd(hdev, HCI_OP_WRITE_PAGE_SCAN_ACTIVITY, 2534 err = hci_send_cmd(hdev, HCI_OP_WRITE_PAGE_SCAN_ACTIVITY, sizeof(acp),
2537 sizeof(acp), &acp); 2535 &acp);
2538 if (err < 0) { 2536 if (err < 0) {
2539 err = cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, 2537 err = cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE,
2540 MGMT_STATUS_FAILED); 2538 MGMT_STATUS_FAILED);
2541 goto done; 2539 goto done;
2542 } 2540 }
2543 2541
2544 err = hci_send_cmd(hdev, HCI_OP_WRITE_PAGE_SCAN_TYPE, 1, &type); 2542 err = hci_send_cmd(hdev, HCI_OP_WRITE_PAGE_SCAN_TYPE, 1, &type);
2545 if (err < 0) { 2543 if (err < 0) {
2546 err = cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, 2544 err = cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE,
2547 MGMT_STATUS_FAILED); 2545 MGMT_STATUS_FAILED);
2548 goto done; 2546 goto done;
2549 } 2547 }
2550 2548
2551 err = cmd_complete(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, 0, 2549 err = cmd_complete(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, 0,
2552 NULL, 0); 2550 NULL, 0);
2553done: 2551done:
2554 hci_dev_unlock(hdev); 2552 hci_dev_unlock(hdev);
2555 return err; 2553 return err;
2556} 2554}
2557 2555
2558static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev, 2556static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev,
2559 void *cp_data, u16 len) 2557 void *cp_data, u16 len)
2560{ 2558{
2561 struct mgmt_cp_load_long_term_keys *cp = cp_data; 2559 struct mgmt_cp_load_long_term_keys *cp = cp_data;
2562 u16 key_count, expected_len; 2560 u16 key_count, expected_len;
@@ -2570,7 +2568,7 @@ static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev,
2570 BT_ERR("load_keys: expected %u bytes, got %u bytes", 2568 BT_ERR("load_keys: expected %u bytes, got %u bytes",
2571 len, expected_len); 2569 len, expected_len);
2572 return cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, 2570 return cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS,
2573 EINVAL); 2571 EINVAL);
2574 } 2572 }
2575 2573
2576 BT_DBG("%s key_count %u", hdev->name, key_count); 2574 BT_DBG("%s key_count %u", hdev->name, key_count);
@@ -2589,8 +2587,8 @@ static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev,
2589 type = HCI_SMP_LTK_SLAVE; 2587 type = HCI_SMP_LTK_SLAVE;
2590 2588
2591 hci_add_ltk(hdev, &key->addr.bdaddr, key->addr.type, 2589 hci_add_ltk(hdev, &key->addr.bdaddr, key->addr.type,
2592 type, 0, key->authenticated, key->val, 2590 type, 0, key->authenticated, key->val,
2593 key->enc_size, key->ediv, key->rand); 2591 key->enc_size, key->ediv, key->rand);
2594 } 2592 }
2595 2593
2596 hci_dev_unlock(hdev); 2594 hci_dev_unlock(hdev);
@@ -2599,8 +2597,8 @@ static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev,
2599} 2597}
2600 2598
2601struct mgmt_handler { 2599struct mgmt_handler {
2602 int (*func) (struct sock *sk, struct hci_dev *hdev, 2600 int (*func) (struct sock *sk, struct hci_dev *hdev, void *data,
2603 void *data, u16 data_len); 2601 u16 data_len);
2604 bool var_len; 2602 bool var_len;
2605 size_t data_len; 2603 size_t data_len;
2606} mgmt_handlers[] = { 2604} mgmt_handlers[] = {
@@ -2685,7 +2683,7 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
2685 hdev = hci_dev_get(index); 2683 hdev = hci_dev_get(index);
2686 if (!hdev) { 2684 if (!hdev) {
2687 err = cmd_status(sk, index, opcode, 2685 err = cmd_status(sk, index, opcode,
2688 MGMT_STATUS_INVALID_INDEX); 2686 MGMT_STATUS_INVALID_INDEX);
2689 goto done; 2687 goto done;
2690 } 2688 }
2691 } 2689 }
@@ -2694,14 +2692,14 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
2694 mgmt_handlers[opcode].func == NULL) { 2692 mgmt_handlers[opcode].func == NULL) {
2695 BT_DBG("Unknown op %u", opcode); 2693 BT_DBG("Unknown op %u", opcode);
2696 err = cmd_status(sk, index, opcode, 2694 err = cmd_status(sk, index, opcode,
2697 MGMT_STATUS_UNKNOWN_COMMAND); 2695 MGMT_STATUS_UNKNOWN_COMMAND);
2698 goto done; 2696 goto done;
2699 } 2697 }
2700 2698
2701 if ((hdev && opcode < MGMT_OP_READ_INFO) || 2699 if ((hdev && opcode < MGMT_OP_READ_INFO) ||
2702 (!hdev && opcode >= MGMT_OP_READ_INFO)) { 2700 (!hdev && opcode >= MGMT_OP_READ_INFO)) {
2703 err = cmd_status(sk, index, opcode, 2701 err = cmd_status(sk, index, opcode,
2704 MGMT_STATUS_INVALID_INDEX); 2702 MGMT_STATUS_INVALID_INDEX);
2705 goto done; 2703 goto done;
2706 } 2704 }
2707 2705
@@ -2710,7 +2708,7 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
2710 if ((handler->var_len && len < handler->data_len) || 2708 if ((handler->var_len && len < handler->data_len) ||
2711 (!handler->var_len && len != handler->data_len)) { 2709 (!handler->var_len && len != handler->data_len)) {
2712 err = cmd_status(sk, index, opcode, 2710 err = cmd_status(sk, index, opcode,
2713 MGMT_STATUS_INVALID_PARAMS); 2711 MGMT_STATUS_INVALID_PARAMS);
2714 goto done; 2712 goto done;
2715 } 2713 }
2716 2714
@@ -2829,7 +2827,7 @@ int mgmt_discoverable(struct hci_dev *hdev, u8 discoverable)
2829 } 2827 }
2830 2828
2831 mgmt_pending_foreach(MGMT_OP_SET_DISCOVERABLE, hdev, settings_rsp, 2829 mgmt_pending_foreach(MGMT_OP_SET_DISCOVERABLE, hdev, settings_rsp,
2832 &match); 2830 &match);
2833 2831
2834 if (changed) 2832 if (changed)
2835 err = new_settings(hdev, match.sk); 2833 err = new_settings(hdev, match.sk);
@@ -2855,7 +2853,7 @@ int mgmt_connectable(struct hci_dev *hdev, u8 connectable)
2855 } 2853 }
2856 2854
2857 mgmt_pending_foreach(MGMT_OP_SET_CONNECTABLE, hdev, settings_rsp, 2855 mgmt_pending_foreach(MGMT_OP_SET_CONNECTABLE, hdev, settings_rsp,
2858 &match); 2856 &match);
2859 2857
2860 if (changed) 2858 if (changed)
2861 err = new_settings(hdev, match.sk); 2859 err = new_settings(hdev, match.sk);
@@ -2872,17 +2870,16 @@ int mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status)
2872 2870
2873 if (scan & SCAN_PAGE) 2871 if (scan & SCAN_PAGE)
2874 mgmt_pending_foreach(MGMT_OP_SET_CONNECTABLE, hdev, 2872 mgmt_pending_foreach(MGMT_OP_SET_CONNECTABLE, hdev,
2875 cmd_status_rsp, &mgmt_err); 2873 cmd_status_rsp, &mgmt_err);
2876 2874
2877 if (scan & SCAN_INQUIRY) 2875 if (scan & SCAN_INQUIRY)
2878 mgmt_pending_foreach(MGMT_OP_SET_DISCOVERABLE, hdev, 2876 mgmt_pending_foreach(MGMT_OP_SET_DISCOVERABLE, hdev,
2879 cmd_status_rsp, &mgmt_err); 2877 cmd_status_rsp, &mgmt_err);
2880 2878
2881 return 0; 2879 return 0;
2882} 2880}
2883 2881
2884int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, 2882int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, u8 persistent)
2885 u8 persistent)
2886{ 2883{
2887 struct mgmt_ev_new_link_key ev; 2884 struct mgmt_ev_new_link_key ev;
2888 2885
@@ -2917,13 +2914,13 @@ int mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, u8 persistent)
2917 memcpy(ev.key.rand, key->rand, sizeof(key->rand)); 2914 memcpy(ev.key.rand, key->rand, sizeof(key->rand));
2918 memcpy(ev.key.val, key->val, sizeof(key->val)); 2915 memcpy(ev.key.val, key->val, sizeof(key->val));
2919 2916
2920 return mgmt_event(MGMT_EV_NEW_LONG_TERM_KEY, hdev, 2917 return mgmt_event(MGMT_EV_NEW_LONG_TERM_KEY, hdev, &ev, sizeof(ev),
2921 &ev, sizeof(ev), NULL); 2918 NULL);
2922} 2919}
2923 2920
2924int mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 2921int mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
2925 u8 addr_type, u32 flags, u8 *name, 2922 u8 addr_type, u32 flags, u8 *name, u8 name_len,
2926 u8 name_len, u8 *dev_class) 2923 u8 *dev_class)
2927{ 2924{
2928 char buf[512]; 2925 char buf[512];
2929 struct mgmt_ev_device_connected *ev = (void *) buf; 2926 struct mgmt_ev_device_connected *ev = (void *) buf;
@@ -2936,16 +2933,16 @@ int mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
2936 2933
2937 if (name_len > 0) 2934 if (name_len > 0)
2938 eir_len = eir_append_data(ev->eir, 0, EIR_NAME_COMPLETE, 2935 eir_len = eir_append_data(ev->eir, 0, EIR_NAME_COMPLETE,
2939 name, name_len); 2936 name, name_len);
2940 2937
2941 if (dev_class && memcmp(dev_class, "\0\0\0", 3) != 0) 2938 if (dev_class && memcmp(dev_class, "\0\0\0", 3) != 0)
2942 eir_len = eir_append_data(&ev->eir[eir_len], eir_len, 2939 eir_len = eir_append_data(&ev->eir[eir_len], eir_len,
2943 EIR_CLASS_OF_DEV, dev_class, 3); 2940 EIR_CLASS_OF_DEV, dev_class, 3);
2944 2941
2945 put_unaligned_le16(eir_len, &ev->eir_len); 2942 put_unaligned_le16(eir_len, &ev->eir_len);
2946 2943
2947 return mgmt_event(MGMT_EV_DEVICE_CONNECTED, hdev, buf, 2944 return mgmt_event(MGMT_EV_DEVICE_CONNECTED, hdev, buf,
2948 sizeof(*ev) + eir_len, NULL); 2945 sizeof(*ev) + eir_len, NULL);
2949} 2946}
2950 2947
2951static void disconnect_rsp(struct pending_cmd *cmd, void *data) 2948static void disconnect_rsp(struct pending_cmd *cmd, void *data)
@@ -2958,7 +2955,7 @@ static void disconnect_rsp(struct pending_cmd *cmd, void *data)
2958 rp.addr.type = cp->addr.type; 2955 rp.addr.type = cp->addr.type;
2959 2956
2960 cmd_complete(cmd->sk, cmd->index, MGMT_OP_DISCONNECT, 0, &rp, 2957 cmd_complete(cmd->sk, cmd->index, MGMT_OP_DISCONNECT, 0, &rp,
2961 sizeof(rp)); 2958 sizeof(rp));
2962 2959
2963 *sk = cmd->sk; 2960 *sk = cmd->sk;
2964 sock_hold(*sk); 2961 sock_hold(*sk);
@@ -2984,7 +2981,7 @@ static void unpair_device_rsp(struct pending_cmd *cmd, void *data)
2984} 2981}
2985 2982
2986int mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, 2983int mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
2987 u8 link_type, u8 addr_type) 2984 u8 link_type, u8 addr_type)
2988{ 2985{
2989 struct mgmt_addr_info ev; 2986 struct mgmt_addr_info ev;
2990 struct sock *sk = NULL; 2987 struct sock *sk = NULL;
@@ -2996,19 +2993,19 @@ int mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
2996 ev.type = link_to_mgmt(link_type, addr_type); 2993 ev.type = link_to_mgmt(link_type, addr_type);
2997 2994
2998 err = mgmt_event(MGMT_EV_DEVICE_DISCONNECTED, hdev, &ev, sizeof(ev), 2995 err = mgmt_event(MGMT_EV_DEVICE_DISCONNECTED, hdev, &ev, sizeof(ev),
2999 sk); 2996 sk);
3000 2997
3001 if (sk) 2998 if (sk)
3002 sock_put(sk); 2999 sock_put(sk);
3003 3000
3004 mgmt_pending_foreach(MGMT_OP_UNPAIR_DEVICE, hdev, unpair_device_rsp, 3001 mgmt_pending_foreach(MGMT_OP_UNPAIR_DEVICE, hdev, unpair_device_rsp,
3005 hdev); 3002 hdev);
3006 3003
3007 return err; 3004 return err;
3008} 3005}
3009 3006
3010int mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, 3007int mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr,
3011 u8 link_type, u8 addr_type, u8 status) 3008 u8 link_type, u8 addr_type, u8 status)
3012{ 3009{
3013 struct mgmt_rp_disconnect rp; 3010 struct mgmt_rp_disconnect rp;
3014 struct pending_cmd *cmd; 3011 struct pending_cmd *cmd;
@@ -3022,7 +3019,7 @@ int mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr,
3022 rp.addr.type = link_to_mgmt(link_type, addr_type); 3019 rp.addr.type = link_to_mgmt(link_type, addr_type);
3023 3020
3024 err = cmd_complete(cmd->sk, cmd->index, MGMT_OP_DISCONNECT, 3021 err = cmd_complete(cmd->sk, cmd->index, MGMT_OP_DISCONNECT,
3025 mgmt_status(status), &rp, sizeof(rp)); 3022 mgmt_status(status), &rp, sizeof(rp));
3026 3023
3027 mgmt_pending_remove(cmd); 3024 mgmt_pending_remove(cmd);
3028 3025
@@ -3032,7 +3029,7 @@ int mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr,
3032} 3029}
3033 3030
3034int mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 3031int mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
3035 u8 addr_type, u8 status) 3032 u8 addr_type, u8 status)
3036{ 3033{
3037 struct mgmt_ev_connect_failed ev; 3034 struct mgmt_ev_connect_failed ev;
3038 3035
@@ -3052,11 +3049,11 @@ int mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure)
3052 ev.secure = secure; 3049 ev.secure = secure;
3053 3050
3054 return mgmt_event(MGMT_EV_PIN_CODE_REQUEST, hdev, &ev, sizeof(ev), 3051 return mgmt_event(MGMT_EV_PIN_CODE_REQUEST, hdev, &ev, sizeof(ev),
3055 NULL); 3052 NULL);
3056} 3053}
3057 3054
3058int mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 3055int mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
3059 u8 status) 3056 u8 status)
3060{ 3057{
3061 struct pending_cmd *cmd; 3058 struct pending_cmd *cmd;
3062 struct mgmt_rp_pin_code_reply rp; 3059 struct mgmt_rp_pin_code_reply rp;
@@ -3070,7 +3067,7 @@ int mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
3070 rp.addr.type = MGMT_ADDR_BREDR; 3067 rp.addr.type = MGMT_ADDR_BREDR;
3071 3068
3072 err = cmd_complete(cmd->sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, 3069 err = cmd_complete(cmd->sk, hdev->id, MGMT_OP_PIN_CODE_REPLY,
3073 mgmt_status(status), &rp, sizeof(rp)); 3070 mgmt_status(status), &rp, sizeof(rp));
3074 3071
3075 mgmt_pending_remove(cmd); 3072 mgmt_pending_remove(cmd);
3076 3073
@@ -3078,7 +3075,7 @@ int mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
3078} 3075}
3079 3076
3080int mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 3077int mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
3081 u8 status) 3078 u8 status)
3082{ 3079{
3083 struct pending_cmd *cmd; 3080 struct pending_cmd *cmd;
3084 struct mgmt_rp_pin_code_reply rp; 3081 struct mgmt_rp_pin_code_reply rp;
@@ -3092,7 +3089,7 @@ int mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
3092 rp.addr.type = MGMT_ADDR_BREDR; 3089 rp.addr.type = MGMT_ADDR_BREDR;
3093 3090
3094 err = cmd_complete(cmd->sk, hdev->id, MGMT_OP_PIN_CODE_NEG_REPLY, 3091 err = cmd_complete(cmd->sk, hdev->id, MGMT_OP_PIN_CODE_NEG_REPLY,
3095 mgmt_status(status), &rp, sizeof(rp)); 3092 mgmt_status(status), &rp, sizeof(rp));
3096 3093
3097 mgmt_pending_remove(cmd); 3094 mgmt_pending_remove(cmd);
3098 3095
@@ -3100,8 +3097,8 @@ int mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
3100} 3097}
3101 3098
3102int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr, 3099int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
3103 u8 link_type, u8 addr_type, __le32 value, 3100 u8 link_type, u8 addr_type, __le32 value,
3104 u8 confirm_hint) 3101 u8 confirm_hint)
3105{ 3102{
3106 struct mgmt_ev_user_confirm_request ev; 3103 struct mgmt_ev_user_confirm_request ev;
3107 3104
@@ -3113,7 +3110,7 @@ int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
3113 put_unaligned_le32(value, &ev.value); 3110 put_unaligned_le32(value, &ev.value);
3114 3111
3115 return mgmt_event(MGMT_EV_USER_CONFIRM_REQUEST, hdev, &ev, sizeof(ev), 3112 return mgmt_event(MGMT_EV_USER_CONFIRM_REQUEST, hdev, &ev, sizeof(ev),
3116 NULL); 3113 NULL);
3117} 3114}
3118 3115
3119int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr, 3116int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
@@ -3127,7 +3124,7 @@ int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
3127 ev.addr.type = link_to_mgmt(link_type, addr_type); 3124 ev.addr.type = link_to_mgmt(link_type, addr_type);
3128 3125
3129 return mgmt_event(MGMT_EV_USER_PASSKEY_REQUEST, hdev, &ev, sizeof(ev), 3126 return mgmt_event(MGMT_EV_USER_PASSKEY_REQUEST, hdev, &ev, sizeof(ev),
3130 NULL); 3127 NULL);
3131} 3128}
3132 3129
3133static int user_pairing_resp_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 3130static int user_pairing_resp_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
@@ -3145,7 +3142,7 @@ static int user_pairing_resp_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
3145 bacpy(&rp.addr.bdaddr, bdaddr); 3142 bacpy(&rp.addr.bdaddr, bdaddr);
3146 rp.addr.type = link_to_mgmt(link_type, addr_type); 3143 rp.addr.type = link_to_mgmt(link_type, addr_type);
3147 err = cmd_complete(cmd->sk, hdev->id, opcode, mgmt_status(status), 3144 err = cmd_complete(cmd->sk, hdev->id, opcode, mgmt_status(status),
3148 &rp, sizeof(rp)); 3145 &rp, sizeof(rp));
3149 3146
3150 mgmt_pending_remove(cmd); 3147 mgmt_pending_remove(cmd);
3151 3148
@@ -3153,35 +3150,35 @@ static int user_pairing_resp_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
3153} 3150}
3154 3151
3155int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 3152int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
3156 u8 link_type, u8 addr_type, u8 status) 3153 u8 link_type, u8 addr_type, u8 status)
3157{ 3154{
3158 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, 3155 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type,
3159 status, MGMT_OP_USER_CONFIRM_REPLY); 3156 status, MGMT_OP_USER_CONFIRM_REPLY);
3160} 3157}
3161 3158
3162int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 3159int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
3163 u8 link_type, u8 addr_type, u8 status) 3160 u8 link_type, u8 addr_type, u8 status)
3164{ 3161{
3165 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, 3162 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type,
3166 status, MGMT_OP_USER_CONFIRM_NEG_REPLY); 3163 status, MGMT_OP_USER_CONFIRM_NEG_REPLY);
3167} 3164}
3168 3165
3169int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 3166int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
3170 u8 link_type, u8 addr_type, u8 status) 3167 u8 link_type, u8 addr_type, u8 status)
3171{ 3168{
3172 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, 3169 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type,
3173 status, MGMT_OP_USER_PASSKEY_REPLY); 3170 status, MGMT_OP_USER_PASSKEY_REPLY);
3174} 3171}
3175 3172
3176int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 3173int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
3177 u8 link_type, u8 addr_type, u8 status) 3174 u8 link_type, u8 addr_type, u8 status)
3178{ 3175{
3179 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, 3176 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type,
3180 status, MGMT_OP_USER_PASSKEY_NEG_REPLY); 3177 status, MGMT_OP_USER_PASSKEY_NEG_REPLY);
3181} 3178}
3182 3179
3183int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 3180int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
3184 u8 addr_type, u8 status) 3181 u8 addr_type, u8 status)
3185{ 3182{
3186 struct mgmt_ev_auth_failed ev; 3183 struct mgmt_ev_auth_failed ev;
3187 3184
@@ -3201,7 +3198,7 @@ int mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status)
3201 if (status) { 3198 if (status) {
3202 u8 mgmt_err = mgmt_status(status); 3199 u8 mgmt_err = mgmt_status(status);
3203 mgmt_pending_foreach(MGMT_OP_SET_LINK_SECURITY, hdev, 3200 mgmt_pending_foreach(MGMT_OP_SET_LINK_SECURITY, hdev,
3204 cmd_status_rsp, &mgmt_err); 3201 cmd_status_rsp, &mgmt_err);
3205 return 0; 3202 return 0;
3206 } 3203 }
3207 3204
@@ -3214,7 +3211,7 @@ int mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status)
3214 } 3211 }
3215 3212
3216 mgmt_pending_foreach(MGMT_OP_SET_LINK_SECURITY, hdev, settings_rsp, 3213 mgmt_pending_foreach(MGMT_OP_SET_LINK_SECURITY, hdev, settings_rsp,
3217 &match); 3214 &match);
3218 3215
3219 if (changed) 3216 if (changed)
3220 err = new_settings(hdev, match.sk); 3217 err = new_settings(hdev, match.sk);
@@ -3249,11 +3246,11 @@ int mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status)
3249 u8 mgmt_err = mgmt_status(status); 3246 u8 mgmt_err = mgmt_status(status);
3250 3247
3251 if (enable && test_and_clear_bit(HCI_SSP_ENABLED, 3248 if (enable && test_and_clear_bit(HCI_SSP_ENABLED,
3252 &hdev->dev_flags)) 3249 &hdev->dev_flags))
3253 err = new_settings(hdev, NULL); 3250 err = new_settings(hdev, NULL);
3254 3251
3255 mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, 3252 mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, cmd_status_rsp,
3256 cmd_status_rsp, &mgmt_err); 3253 &mgmt_err);
3257 3254
3258 return err; 3255 return err;
3259 } 3256 }
@@ -3287,7 +3284,7 @@ static void class_rsp(struct pending_cmd *cmd, void *data)
3287 struct cmd_lookup *match = data; 3284 struct cmd_lookup *match = data;
3288 3285
3289 cmd_complete(cmd->sk, cmd->index, cmd->opcode, match->mgmt_status, 3286 cmd_complete(cmd->sk, cmd->index, cmd->opcode, match->mgmt_status,
3290 match->hdev->dev_class, 3); 3287 match->hdev->dev_class, 3);
3291 3288
3292 list_del(&cmd->list); 3289 list_del(&cmd->list);
3293 3290
@@ -3300,7 +3297,7 @@ static void class_rsp(struct pending_cmd *cmd, void *data)
3300} 3297}
3301 3298
3302int mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class, 3299int mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class,
3303 u8 status) 3300 u8 status)
3304{ 3301{
3305 struct cmd_lookup match = { NULL, hdev, mgmt_status(status) }; 3302 struct cmd_lookup match = { NULL, hdev, mgmt_status(status) };
3306 int err = 0; 3303 int err = 0;
@@ -3312,8 +3309,8 @@ int mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class,
3312 mgmt_pending_foreach(MGMT_OP_REMOVE_UUID, hdev, class_rsp, &match); 3309 mgmt_pending_foreach(MGMT_OP_REMOVE_UUID, hdev, class_rsp, &match);
3313 3310
3314 if (!status) 3311 if (!status)
3315 err = mgmt_event(MGMT_EV_CLASS_OF_DEV_CHANGED, hdev, 3312 err = mgmt_event(MGMT_EV_CLASS_OF_DEV_CHANGED, hdev, dev_class,
3316 dev_class, 3, NULL); 3313 3, NULL);
3317 3314
3318 if (match.sk) 3315 if (match.sk)
3319 sock_put(match.sk); 3316 sock_put(match.sk);
@@ -3347,19 +3344,19 @@ int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status)
3347 3344
3348 if (status) { 3345 if (status) {
3349 err = cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 3346 err = cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME,
3350 mgmt_status(status)); 3347 mgmt_status(status));
3351 goto failed; 3348 goto failed;
3352 } 3349 }
3353 3350
3354 err = cmd_complete(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, &ev, 3351 err = cmd_complete(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, &ev,
3355 sizeof(ev)); 3352 sizeof(ev));
3356 if (err < 0) 3353 if (err < 0)
3357 goto failed; 3354 goto failed;
3358 3355
3359send_event: 3356send_event:
3360 if (changed) 3357 if (changed)
3361 err = mgmt_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, &ev, 3358 err = mgmt_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, &ev,
3362 sizeof(ev), cmd ? cmd->sk : NULL); 3359 sizeof(ev), cmd ? cmd->sk : NULL);
3363 3360
3364 update_eir(hdev); 3361 update_eir(hdev);
3365 3362
@@ -3370,7 +3367,7 @@ failed:
3370} 3367}
3371 3368
3372int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash, 3369int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,
3373 u8 *randomizer, u8 status) 3370 u8 *randomizer, u8 status)
3374{ 3371{
3375 struct pending_cmd *cmd; 3372 struct pending_cmd *cmd;
3376 int err; 3373 int err;
@@ -3382,9 +3379,8 @@ int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,
3382 return -ENOENT; 3379 return -ENOENT;
3383 3380
3384 if (status) { 3381 if (status) {
3385 err = cmd_status(cmd->sk, hdev->id, 3382 err = cmd_status(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA,
3386 MGMT_OP_READ_LOCAL_OOB_DATA, 3383 mgmt_status(status));
3387 mgmt_status(status));
3388 } else { 3384 } else {
3389 struct mgmt_rp_read_local_oob_data rp; 3385 struct mgmt_rp_read_local_oob_data rp;
3390 3386
@@ -3392,8 +3388,8 @@ int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,
3392 memcpy(rp.randomizer, randomizer, sizeof(rp.randomizer)); 3388 memcpy(rp.randomizer, randomizer, sizeof(rp.randomizer));
3393 3389
3394 err = cmd_complete(cmd->sk, hdev->id, 3390 err = cmd_complete(cmd->sk, hdev->id,
3395 MGMT_OP_READ_LOCAL_OOB_DATA, 3391 MGMT_OP_READ_LOCAL_OOB_DATA, 0, &rp,
3396 0, &rp, sizeof(rp)); 3392 sizeof(rp));
3397 } 3393 }
3398 3394
3399 mgmt_pending_remove(cmd); 3395 mgmt_pending_remove(cmd);
@@ -3411,11 +3407,11 @@ int mgmt_le_enable_complete(struct hci_dev *hdev, u8 enable, u8 status)
3411 u8 mgmt_err = mgmt_status(status); 3407 u8 mgmt_err = mgmt_status(status);
3412 3408
3413 if (enable && test_and_clear_bit(HCI_LE_ENABLED, 3409 if (enable && test_and_clear_bit(HCI_LE_ENABLED,
3414 &hdev->dev_flags)) 3410 &hdev->dev_flags))
3415 err = new_settings(hdev, NULL); 3411 err = new_settings(hdev, NULL);
3416 3412
3417 mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, 3413 mgmt_pending_foreach(MGMT_OP_SET_LE, hdev,
3418 cmd_status_rsp, &mgmt_err); 3414 cmd_status_rsp, &mgmt_err);
3419 3415
3420 return err; 3416 return err;
3421 } 3417 }
@@ -3440,8 +3436,8 @@ int mgmt_le_enable_complete(struct hci_dev *hdev, u8 enable, u8 status)
3440} 3436}
3441 3437
3442int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 3438int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
3443 u8 addr_type, u8 *dev_class, s8 rssi, 3439 u8 addr_type, u8 *dev_class, s8 rssi, u8 cfm_name, u8
3444 u8 cfm_name, u8 ssp, u8 *eir, u16 eir_len) 3440 ssp, u8 *eir, u16 eir_len)
3445{ 3441{
3446 char buf[512]; 3442 char buf[512];
3447 struct mgmt_ev_device_found *ev = (void *) buf; 3443 struct mgmt_ev_device_found *ev = (void *) buf;
@@ -3466,7 +3462,7 @@ int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
3466 3462
3467 if (dev_class && !eir_has_data_type(ev->eir, eir_len, EIR_CLASS_OF_DEV)) 3463 if (dev_class && !eir_has_data_type(ev->eir, eir_len, EIR_CLASS_OF_DEV))
3468 eir_len = eir_append_data(ev->eir, eir_len, EIR_CLASS_OF_DEV, 3464 eir_len = eir_append_data(ev->eir, eir_len, EIR_CLASS_OF_DEV,
3469 dev_class, 3); 3465 dev_class, 3);
3470 3466
3471 put_unaligned_le16(eir_len, &ev->eir_len); 3467 put_unaligned_le16(eir_len, &ev->eir_len);
3472 3468
@@ -3476,7 +3472,7 @@ int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
3476} 3472}
3477 3473
3478int mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 3474int mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
3479 u8 addr_type, s8 rssi, u8 *name, u8 name_len) 3475 u8 addr_type, s8 rssi, u8 *name, u8 name_len)
3480{ 3476{
3481 struct mgmt_ev_device_found *ev; 3477 struct mgmt_ev_device_found *ev;
3482 char buf[sizeof(*ev) + HCI_MAX_NAME_LENGTH + 2]; 3478 char buf[sizeof(*ev) + HCI_MAX_NAME_LENGTH + 2];
@@ -3491,12 +3487,12 @@ int mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
3491 ev->rssi = rssi; 3487 ev->rssi = rssi;
3492 3488
3493 eir_len = eir_append_data(ev->eir, 0, EIR_NAME_COMPLETE, name, 3489 eir_len = eir_append_data(ev->eir, 0, EIR_NAME_COMPLETE, name,
3494 name_len); 3490 name_len);
3495 3491
3496 put_unaligned_le16(eir_len, &ev->eir_len); 3492 put_unaligned_le16(eir_len, &ev->eir_len);
3497 3493
3498 return mgmt_event(MGMT_EV_DEVICE_FOUND, hdev, ev, 3494 return mgmt_event(MGMT_EV_DEVICE_FOUND, hdev, ev,
3499 sizeof(*ev) + eir_len, NULL); 3495 sizeof(*ev) + eir_len, NULL);
3500} 3496}
3501 3497
3502int mgmt_start_discovery_failed(struct hci_dev *hdev, u8 status) 3498int mgmt_start_discovery_failed(struct hci_dev *hdev, u8 status)
@@ -3514,7 +3510,7 @@ int mgmt_start_discovery_failed(struct hci_dev *hdev, u8 status)
3514 type = hdev->discovery.type; 3510 type = hdev->discovery.type;
3515 3511
3516 err = cmd_complete(cmd->sk, hdev->id, cmd->opcode, mgmt_status(status), 3512 err = cmd_complete(cmd->sk, hdev->id, cmd->opcode, mgmt_status(status),
3517 &type, sizeof(type)); 3513 &type, sizeof(type));
3518 mgmt_pending_remove(cmd); 3514 mgmt_pending_remove(cmd);
3519 3515
3520 return err; 3516 return err;
@@ -3530,8 +3526,7 @@ int mgmt_stop_discovery_failed(struct hci_dev *hdev, u8 status)
3530 return -ENOENT; 3526 return -ENOENT;
3531 3527
3532 err = cmd_complete(cmd->sk, hdev->id, cmd->opcode, mgmt_status(status), 3528 err = cmd_complete(cmd->sk, hdev->id, cmd->opcode, mgmt_status(status),
3533 &hdev->discovery.type, 3529 &hdev->discovery.type, sizeof(hdev->discovery.type));
3534 sizeof(hdev->discovery.type));
3535 mgmt_pending_remove(cmd); 3530 mgmt_pending_remove(cmd);
3536 3531
3537 return err; 3532 return err;
@@ -3552,8 +3547,8 @@ int mgmt_discovering(struct hci_dev *hdev, u8 discovering)
3552 if (cmd != NULL) { 3547 if (cmd != NULL) {
3553 u8 type = hdev->discovery.type; 3548 u8 type = hdev->discovery.type;
3554 3549
3555 cmd_complete(cmd->sk, hdev->id, cmd->opcode, 0, 3550 cmd_complete(cmd->sk, hdev->id, cmd->opcode, 0, &type,
3556 &type, sizeof(type)); 3551 sizeof(type));
3557 mgmt_pending_remove(cmd); 3552 mgmt_pending_remove(cmd);
3558 } 3553 }
3559 3554
@@ -3575,7 +3570,7 @@ int mgmt_device_blocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
3575 ev.addr.type = type; 3570 ev.addr.type = type;
3576 3571
3577 return mgmt_event(MGMT_EV_DEVICE_BLOCKED, hdev, &ev, sizeof(ev), 3572 return mgmt_event(MGMT_EV_DEVICE_BLOCKED, hdev, &ev, sizeof(ev),
3578 cmd ? cmd->sk : NULL); 3573 cmd ? cmd->sk : NULL);
3579} 3574}
3580 3575
3581int mgmt_device_unblocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type) 3576int mgmt_device_unblocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
@@ -3589,7 +3584,7 @@ int mgmt_device_unblocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
3589 ev.addr.type = type; 3584 ev.addr.type = type;
3590 3585
3591 return mgmt_event(MGMT_EV_DEVICE_UNBLOCKED, hdev, &ev, sizeof(ev), 3586 return mgmt_event(MGMT_EV_DEVICE_UNBLOCKED, hdev, &ev, sizeof(ev),
3592 cmd ? cmd->sk : NULL); 3587 cmd ? cmd->sk : NULL);
3593} 3588}
3594 3589
3595module_param(enable_hs, bool, 0644); 3590module_param(enable_hs, bool, 0644);