aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/bluetooth/btmrvl_debugfs.c23
-rw-r--r--include/net/bluetooth/hci_core.h67
-rw-r--r--net/bluetooth/hci_core.c49
-rw-r--r--net/bluetooth/hci_event.c110
-rw-r--r--net/bluetooth/l2cap_core.c11
-rw-r--r--net/bluetooth/l2cap_sock.c3
-rw-r--r--net/bluetooth/mgmt.c489
-rw-r--r--net/bluetooth/smp.c30
8 files changed, 384 insertions, 398 deletions
diff --git a/drivers/bluetooth/btmrvl_debugfs.c b/drivers/bluetooth/btmrvl_debugfs.c
index 3497347e6dbb..6c20bbb54b71 100644
--- a/drivers/bluetooth/btmrvl_debugfs.c
+++ b/drivers/bluetooth/btmrvl_debugfs.c
@@ -401,28 +401,29 @@ void btmrvl_debugfs_init(struct hci_dev *hdev)
401 dbg->config_dir = debugfs_create_dir("config", hdev->debugfs); 401 dbg->config_dir = debugfs_create_dir("config", hdev->debugfs);
402 402
403 dbg->psmode = debugfs_create_file("psmode", 0644, dbg->config_dir, 403 dbg->psmode = debugfs_create_file("psmode", 0644, dbg->config_dir,
404 priv, &btmrvl_psmode_fops); 404 priv, &btmrvl_psmode_fops);
405 dbg->pscmd = debugfs_create_file("pscmd", 0644, dbg->config_dir, 405 dbg->pscmd = debugfs_create_file("pscmd", 0644, dbg->config_dir,
406 priv, &btmrvl_pscmd_fops); 406 priv, &btmrvl_pscmd_fops);
407 dbg->gpiogap = debugfs_create_file("gpiogap", 0644, dbg->config_dir, 407 dbg->gpiogap = debugfs_create_file("gpiogap", 0644, dbg->config_dir,
408 priv, &btmrvl_gpiogap_fops); 408 priv, &btmrvl_gpiogap_fops);
409 dbg->hsmode = debugfs_create_file("hsmode", 0644, dbg->config_dir, 409 dbg->hsmode = debugfs_create_file("hsmode", 0644, dbg->config_dir,
410 priv, &btmrvl_hsmode_fops); 410 priv, &btmrvl_hsmode_fops);
411 dbg->hscmd = debugfs_create_file("hscmd", 0644, dbg->config_dir, 411 dbg->hscmd = debugfs_create_file("hscmd", 0644, dbg->config_dir,
412 priv, &btmrvl_hscmd_fops); 412 priv, &btmrvl_hscmd_fops);
413 dbg->hscfgcmd = debugfs_create_file("hscfgcmd", 0644, dbg->config_dir, 413 dbg->hscfgcmd = debugfs_create_file("hscfgcmd", 0644, dbg->config_dir,
414 priv, &btmrvl_hscfgcmd_fops); 414 priv, &btmrvl_hscfgcmd_fops);
415 415
416 dbg->status_dir = debugfs_create_dir("status", hdev->debugfs); 416 dbg->status_dir = debugfs_create_dir("status", hdev->debugfs);
417 dbg->curpsmode = debugfs_create_file("curpsmode", 0444, 417 dbg->curpsmode = debugfs_create_file("curpsmode", 0444,
418 dbg->status_dir, priv, &btmrvl_curpsmode_fops); 418 dbg->status_dir, priv,
419 &btmrvl_curpsmode_fops);
419 dbg->psstate = debugfs_create_file("psstate", 0444, dbg->status_dir, 420 dbg->psstate = debugfs_create_file("psstate", 0444, dbg->status_dir,
420 priv, &btmrvl_psstate_fops); 421 priv, &btmrvl_psstate_fops);
421 dbg->hsstate = debugfs_create_file("hsstate", 0444, dbg->status_dir, 422 dbg->hsstate = debugfs_create_file("hsstate", 0444, dbg->status_dir,
422 priv, &btmrvl_hsstate_fops); 423 priv, &btmrvl_hsstate_fops);
423 dbg->txdnldready = debugfs_create_file("txdnldready", 0444, 424 dbg->txdnldready = debugfs_create_file("txdnldready", 0444,
424 dbg->status_dir, priv, 425 dbg->status_dir, priv,
425 &btmrvl_txdnldready_fops); 426 &btmrvl_txdnldready_fops);
426} 427}
427 428
428void btmrvl_debugfs_remove(struct hci_dev *hdev) 429void btmrvl_debugfs_remove(struct hci_dev *hdev)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index cbbf68a8510d..daefaac51131 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -398,16 +398,16 @@ static inline long inquiry_entry_age(struct inquiry_entry *e)
398} 398}
399 399
400struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, 400struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev,
401 bdaddr_t *bdaddr); 401 bdaddr_t *bdaddr);
402struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev, 402struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev,
403 bdaddr_t *bdaddr); 403 bdaddr_t *bdaddr);
404struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev, 404struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev,
405 bdaddr_t *bdaddr, 405 bdaddr_t *bdaddr,
406 int state); 406 int state);
407void hci_inquiry_cache_update_resolve(struct hci_dev *hdev, 407void hci_inquiry_cache_update_resolve(struct hci_dev *hdev,
408 struct inquiry_entry *ie); 408 struct inquiry_entry *ie);
409bool hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data, 409bool hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data,
410 bool name_known, bool *ssp); 410 bool name_known, bool *ssp);
411 411
412/* ----- HCI Connections ----- */ 412/* ----- HCI Connections ----- */
413enum { 413enum {
@@ -669,13 +669,13 @@ int hci_uuids_clear(struct hci_dev *hdev);
669int hci_link_keys_clear(struct hci_dev *hdev); 669int hci_link_keys_clear(struct hci_dev *hdev);
670struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr); 670struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
671int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key, 671int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key,
672 bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len); 672 bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len);
673struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8]); 673struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8]);
674int hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type, u8 type, 674int hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type, u8 type,
675 int new_key, u8 authenticated, u8 tk[16], 675 int new_key, u8 authenticated, u8 tk[16], u8 enc_size, u16 ediv,
676 u8 enc_size, u16 ediv, u8 rand[8]); 676 u8 rand[8]);
677struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, 677struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
678 u8 addr_type); 678 u8 addr_type);
679int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr); 679int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr);
680int hci_smp_ltks_clear(struct hci_dev *hdev); 680int hci_smp_ltks_clear(struct hci_dev *hdev);
681int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr); 681int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
@@ -931,7 +931,7 @@ static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type)
931} 931}
932 932
933static inline u16 eir_append_data(u8 *eir, u16 eir_len, u8 type, u8 *data, 933static inline u16 eir_append_data(u8 *eir, u16 eir_len, u8 type, u8 *data,
934 u8 data_len) 934 u8 data_len)
935{ 935{
936 eir[eir_len++] = sizeof(type) + data_len; 936 eir[eir_len++] = sizeof(type) + data_len;
937 eir[eir_len++] = type; 937 eir[eir_len++] = type;
@@ -978,50 +978,49 @@ int mgmt_discoverable(struct hci_dev *hdev, u8 discoverable);
978int mgmt_connectable(struct hci_dev *hdev, u8 connectable); 978int mgmt_connectable(struct hci_dev *hdev, u8 connectable);
979int mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status); 979int mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status);
980int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, 980int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
981 u8 persistent); 981 u8 persistent);
982int mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 982int mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
983 u8 addr_type, u32 flags, u8 *name, 983 u8 addr_type, u32 flags, u8 *name, u8 name_len,
984 u8 name_len, u8 *dev_class); 984 u8 *dev_class);
985int mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, 985int mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
986 u8 link_type, u8 addr_type); 986 u8 link_type, u8 addr_type);
987int mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, 987int mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr,
988 u8 link_type, u8 addr_type, u8 status); 988 u8 link_type, u8 addr_type, u8 status);
989int mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 989int mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
990 u8 addr_type, u8 status); 990 u8 addr_type, u8 status);
991int mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure); 991int mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure);
992int mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 992int mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
993 u8 status); 993 u8 status);
994int mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 994int mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
995 u8 status); 995 u8 status);
996int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr, 996int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
997 u8 link_type, u8 addr_type, __le32 value, 997 u8 link_type, u8 addr_type, __le32 value,
998 u8 confirm_hint); 998 u8 confirm_hint);
999int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 999int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
1000 u8 link_type, u8 addr_type, u8 status); 1000 u8 link_type, u8 addr_type, u8 status);
1001int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1001int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
1002 u8 link_type, u8 addr_type, u8 status); 1002 u8 link_type, u8 addr_type, u8 status);
1003int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr, 1003int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
1004 u8 link_type, u8 addr_type); 1004 u8 link_type, u8 addr_type);
1005int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1005int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
1006 u8 link_type, u8 addr_type, u8 status); 1006 u8 link_type, u8 addr_type, u8 status);
1007int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1007int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
1008 u8 link_type, u8 addr_type, u8 status); 1008 u8 link_type, u8 addr_type, u8 status);
1009int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 1009int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
1010 u8 addr_type, u8 status); 1010 u8 addr_type, u8 status);
1011int mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status); 1011int mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status);
1012int mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status); 1012int mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status);
1013int mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class, 1013int mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class,
1014 u8 status); 1014 u8 status);
1015int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status); 1015int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
1016int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash, 1016int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,
1017 u8 *randomizer, u8 status); 1017 u8 *randomizer, u8 status);
1018int mgmt_le_enable_complete(struct hci_dev *hdev, u8 enable, u8 status); 1018int mgmt_le_enable_complete(struct hci_dev *hdev, u8 enable, u8 status);
1019int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 1019int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
1020 u8 addr_type, u8 *dev_class, s8 rssi, 1020 u8 addr_type, u8 *dev_class, s8 rssi, u8 cfm_name,
1021 u8 cfm_name, u8 ssp, u8 *eir, 1021 u8 ssp, u8 *eir, u16 eir_len);
1022 u16 eir_len);
1023int mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 1022int mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
1024 u8 addr_type, s8 rssi, u8 *name, u8 name_len); 1023 u8 addr_type, s8 rssi, u8 *name, u8 name_len);
1025int mgmt_start_discovery_failed(struct hci_dev *hdev, u8 status); 1024int mgmt_start_discovery_failed(struct hci_dev *hdev, u8 status);
1026int mgmt_stop_discovery_failed(struct hci_dev *hdev, u8 status); 1025int mgmt_stop_discovery_failed(struct hci_dev *hdev, u8 status);
1027int mgmt_discovering(struct hci_dev *hdev, u8 discovering); 1026int mgmt_discovering(struct hci_dev *hdev, u8 discovering);
@@ -1071,6 +1070,6 @@ void hci_le_ltk_neg_reply(struct hci_conn *conn);
1071int hci_do_inquiry(struct hci_dev *hdev, u8 length); 1070int hci_do_inquiry(struct hci_dev *hdev, u8 length);
1072int hci_cancel_inquiry(struct hci_dev *hdev); 1071int hci_cancel_inquiry(struct hci_dev *hdev);
1073int hci_le_scan(struct hci_dev *hdev, u8 type, u16 interval, u16 window, 1072int hci_le_scan(struct hci_dev *hdev, u8 type, u16 interval, u16 window,
1074 int timeout); 1073 int timeout);
1075 1074
1076#endif /* __HCI_CORE_H */ 1075#endif /* __HCI_CORE_H */
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 661d65fc487b..59ec99eb739b 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -431,7 +431,7 @@ struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, bdaddr_t *b
431} 431}
432 432
433struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev, 433struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev,
434 bdaddr_t *bdaddr) 434 bdaddr_t *bdaddr)
435{ 435{
436 struct discovery_state *cache = &hdev->discovery; 436 struct discovery_state *cache = &hdev->discovery;
437 struct inquiry_entry *e; 437 struct inquiry_entry *e;
@@ -447,8 +447,8 @@ struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev,
447} 447}
448 448
449struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev, 449struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev,
450 bdaddr_t *bdaddr, 450 bdaddr_t *bdaddr,
451 int state) 451 int state)
452{ 452{
453 struct discovery_state *cache = &hdev->discovery; 453 struct discovery_state *cache = &hdev->discovery;
454 struct inquiry_entry *e; 454 struct inquiry_entry *e;
@@ -466,7 +466,7 @@ struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev,
466} 466}
467 467
468void hci_inquiry_cache_update_resolve(struct hci_dev *hdev, 468void hci_inquiry_cache_update_resolve(struct hci_dev *hdev,
469 struct inquiry_entry *ie) 469 struct inquiry_entry *ie)
470{ 470{
471 struct discovery_state *cache = &hdev->discovery; 471 struct discovery_state *cache = &hdev->discovery;
472 struct list_head *pos = &cache->resolve; 472 struct list_head *pos = &cache->resolve;
@@ -485,7 +485,7 @@ void hci_inquiry_cache_update_resolve(struct hci_dev *hdev,
485} 485}
486 486
487bool hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data, 487bool hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data,
488 bool name_known, bool *ssp) 488 bool name_known, bool *ssp)
489{ 489{
490 struct discovery_state *cache = &hdev->discovery; 490 struct discovery_state *cache = &hdev->discovery;
491 struct inquiry_entry *ie; 491 struct inquiry_entry *ie;
@@ -1264,7 +1264,7 @@ struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8])
1264EXPORT_SYMBOL(hci_find_ltk); 1264EXPORT_SYMBOL(hci_find_ltk);
1265 1265
1266struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, 1266struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
1267 u8 addr_type) 1267 u8 addr_type)
1268{ 1268{
1269 struct smp_ltk *k; 1269 struct smp_ltk *k;
1270 1270
@@ -1278,7 +1278,7 @@ struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
1278EXPORT_SYMBOL(hci_find_ltk_by_addr); 1278EXPORT_SYMBOL(hci_find_ltk_by_addr);
1279 1279
1280int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key, 1280int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key,
1281 bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len) 1281 bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len)
1282{ 1282{
1283 struct link_key *key, *old_key; 1283 struct link_key *key, *old_key;
1284 u8 old_key_type, persistent; 1284 u8 old_key_type, persistent;
@@ -1333,8 +1333,8 @@ int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key,
1333} 1333}
1334 1334
1335int hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type, u8 type, 1335int hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type, u8 type,
1336 int new_key, u8 authenticated, u8 tk[16], 1336 int new_key, u8 authenticated, u8 tk[16], u8 enc_size, u16
1337 u8 enc_size, u16 ediv, u8 rand[8]) 1337 ediv, u8 rand[8])
1338{ 1338{
1339 struct smp_ltk *key, *old_key; 1339 struct smp_ltk *key, *old_key;
1340 1340
@@ -1413,7 +1413,7 @@ static void hci_cmd_timer(unsigned long arg)
1413} 1413}
1414 1414
1415struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev, 1415struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev,
1416 bdaddr_t *bdaddr) 1416 bdaddr_t *bdaddr)
1417{ 1417{
1418 struct oob_data *data; 1418 struct oob_data *data;
1419 1419
@@ -1453,7 +1453,7 @@ int hci_remote_oob_data_clear(struct hci_dev *hdev)
1453} 1453}
1454 1454
1455int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash, 1455int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
1456 u8 *randomizer) 1456 u8 *randomizer)
1457{ 1457{
1458 struct oob_data *data; 1458 struct oob_data *data;
1459 1459
@@ -1476,8 +1476,7 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
1476 return 0; 1476 return 0;
1477} 1477}
1478 1478
1479struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, 1479struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, bdaddr_t *bdaddr)
1480 bdaddr_t *bdaddr)
1481{ 1480{
1482 struct bdaddr_list *b; 1481 struct bdaddr_list *b;
1483 1482
@@ -1545,7 +1544,7 @@ int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
1545static void hci_clear_adv_cache(struct work_struct *work) 1544static void hci_clear_adv_cache(struct work_struct *work)
1546{ 1545{
1547 struct hci_dev *hdev = container_of(work, struct hci_dev, 1546 struct hci_dev *hdev = container_of(work, struct hci_dev,
1548 adv_work.work); 1547 adv_work.work);
1549 1548
1550 hci_dev_lock(hdev); 1549 hci_dev_lock(hdev);
1551 1550
@@ -1588,11 +1587,7 @@ static inline int is_connectable_adv(u8 evt_type)
1588} 1587}
1589 1588
1590int hci_add_adv_entry(struct hci_dev *hdev, 1589int hci_add_adv_entry(struct hci_dev *hdev,
1591 struct hci_ev_le_advertising_info *ev) 1590 struct hci_ev_le_advertising_info *ev) { struct adv_entry *entry; if (!is_connectable_adv(ev->evt_type))
1592{
1593 struct adv_entry *entry;
1594
1595 if (!is_connectable_adv(ev->evt_type))
1596 return -EINVAL; 1591 return -EINVAL;
1597 1592
1598 /* Only new entries should be added to adv_entries. So, if 1593 /* Only new entries should be added to adv_entries. So, if
@@ -1639,7 +1634,7 @@ static void le_scan_enable_req(struct hci_dev *hdev, unsigned long opt)
1639} 1634}
1640 1635
1641static int hci_do_le_scan(struct hci_dev *hdev, u8 type, u16 interval, 1636static int hci_do_le_scan(struct hci_dev *hdev, u8 type, u16 interval,
1642 u16 window, int timeout) 1637 u16 window, int timeout)
1643{ 1638{
1644 long timeo = msecs_to_jiffies(3000); 1639 long timeo = msecs_to_jiffies(3000);
1645 struct le_scan_params param; 1640 struct le_scan_params param;
@@ -1657,7 +1652,7 @@ static int hci_do_le_scan(struct hci_dev *hdev, u8 type, u16 interval,
1657 hci_req_lock(hdev); 1652 hci_req_lock(hdev);
1658 1653
1659 err = __hci_request(hdev, le_scan_param_req, (unsigned long) &param, 1654 err = __hci_request(hdev, le_scan_param_req, (unsigned long) &param,
1660 timeo); 1655 timeo);
1661 if (!err) 1656 if (!err)
1662 err = __hci_request(hdev, le_scan_enable_req, 0, timeo); 1657 err = __hci_request(hdev, le_scan_enable_req, 0, timeo);
1663 1658
@@ -1667,7 +1662,7 @@ static int hci_do_le_scan(struct hci_dev *hdev, u8 type, u16 interval,
1667 return err; 1662 return err;
1668 1663
1669 schedule_delayed_work(&hdev->le_scan_disable, 1664 schedule_delayed_work(&hdev->le_scan_disable,
1670 msecs_to_jiffies(timeout)); 1665 msecs_to_jiffies(timeout));
1671 1666
1672 return 0; 1667 return 0;
1673} 1668}
@@ -1675,7 +1670,7 @@ static int hci_do_le_scan(struct hci_dev *hdev, u8 type, u16 interval,
1675static void le_scan_disable_work(struct work_struct *work) 1670static void le_scan_disable_work(struct work_struct *work)
1676{ 1671{
1677 struct hci_dev *hdev = container_of(work, struct hci_dev, 1672 struct hci_dev *hdev = container_of(work, struct hci_dev,
1678 le_scan_disable.work); 1673 le_scan_disable.work);
1679 struct hci_cp_le_set_scan_enable cp; 1674 struct hci_cp_le_set_scan_enable cp;
1680 1675
1681 BT_DBG("%s", hdev->name); 1676 BT_DBG("%s", hdev->name);
@@ -1692,12 +1687,12 @@ static void le_scan_work(struct work_struct *work)
1692 1687
1693 BT_DBG("%s", hdev->name); 1688 BT_DBG("%s", hdev->name);
1694 1689
1695 hci_do_le_scan(hdev, param->type, param->interval, 1690 hci_do_le_scan(hdev, param->type, param->interval, param->window,
1696 param->window, param->timeout); 1691 param->timeout);
1697} 1692}
1698 1693
1699int hci_le_scan(struct hci_dev *hdev, u8 type, u16 interval, u16 window, 1694int hci_le_scan(struct hci_dev *hdev, u8 type, u16 interval, u16 window,
1700 int timeout) 1695 int timeout)
1701{ 1696{
1702 struct le_scan_params *param = &hdev->le_scan_params; 1697 struct le_scan_params *param = &hdev->le_scan_params;
1703 1698
@@ -2558,7 +2553,7 @@ static inline void hci_sched_acl_pkt(struct hci_dev *hdev)
2558 skb = skb_dequeue(&chan->data_q); 2553 skb = skb_dequeue(&chan->data_q);
2559 2554
2560 hci_conn_enter_active_mode(chan->conn, 2555 hci_conn_enter_active_mode(chan->conn,
2561 bt_cb(skb)->force_active); 2556 bt_cb(skb)->force_active);
2562 2557
2563 hci_send_frame(skb); 2558 hci_send_frame(skb);
2564 hdev->acl_last_tx = jiffies; 2559 hdev->acl_last_tx = jiffies;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 6a817daf095b..badb7851d116 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -556,7 +556,7 @@ static void hci_setup(struct hci_dev *hdev)
556 if (test_bit(HCI_SSP_ENABLED, &hdev->dev_flags)) { 556 if (test_bit(HCI_SSP_ENABLED, &hdev->dev_flags)) {
557 u8 mode = 0x01; 557 u8 mode = 0x01;
558 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_MODE, 558 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_MODE,
559 sizeof(mode), &mode); 559 sizeof(mode), &mode);
560 } else { 560 } else {
561 struct hci_cp_write_eir cp; 561 struct hci_cp_write_eir cp;
562 562
@@ -577,14 +577,14 @@ static void hci_setup(struct hci_dev *hdev)
577 struct hci_cp_read_local_ext_features cp; 577 struct hci_cp_read_local_ext_features cp;
578 578
579 cp.page = 0x01; 579 cp.page = 0x01;
580 hci_send_cmd(hdev, HCI_OP_READ_LOCAL_EXT_FEATURES, 580 hci_send_cmd(hdev, HCI_OP_READ_LOCAL_EXT_FEATURES, sizeof(cp),
581 sizeof(cp), &cp); 581 &cp);
582 } 582 }
583 583
584 if (test_bit(HCI_LINK_SECURITY, &hdev->dev_flags)) { 584 if (test_bit(HCI_LINK_SECURITY, &hdev->dev_flags)) {
585 u8 enable = 1; 585 u8 enable = 1;
586 hci_send_cmd(hdev, HCI_OP_WRITE_AUTH_ENABLE, 586 hci_send_cmd(hdev, HCI_OP_WRITE_AUTH_ENABLE, sizeof(enable),
587 sizeof(enable), &enable); 587 &enable);
588 } 588 }
589} 589}
590 590
@@ -628,8 +628,8 @@ static void hci_setup_link_policy(struct hci_dev *hdev)
628 link_policy |= HCI_LP_PARK; 628 link_policy |= HCI_LP_PARK;
629 629
630 link_policy = cpu_to_le16(link_policy); 630 link_policy = cpu_to_le16(link_policy);
631 hci_send_cmd(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, 631 hci_send_cmd(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, sizeof(link_policy),
632 sizeof(link_policy), &link_policy); 632 &link_policy);
633} 633}
634 634
635static void hci_cc_read_local_commands(struct hci_dev *hdev, struct sk_buff *skb) 635static void hci_cc_read_local_commands(struct hci_dev *hdev, struct sk_buff *skb)
@@ -717,8 +717,8 @@ static void hci_set_le_support(struct hci_dev *hdev)
717 } 717 }
718 718
719 if (cp.le != !!(hdev->host_features[0] & LMP_HOST_LE)) 719 if (cp.le != !!(hdev->host_features[0] & LMP_HOST_LE))
720 hci_send_cmd(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, 720 hci_send_cmd(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, sizeof(cp),
721 sizeof(cp), &cp); 721 &cp);
722} 722}
723 723
724static void hci_cc_read_local_ext_features(struct hci_dev *hdev, 724static void hci_cc_read_local_ext_features(struct hci_dev *hdev,
@@ -976,8 +976,8 @@ static void hci_cc_user_confirm_reply(struct hci_dev *hdev, struct sk_buff *skb)
976 hci_dev_lock(hdev); 976 hci_dev_lock(hdev);
977 977
978 if (test_bit(HCI_MGMT, &hdev->dev_flags)) 978 if (test_bit(HCI_MGMT, &hdev->dev_flags))
979 mgmt_user_confirm_reply_complete(hdev, &rp->bdaddr, ACL_LINK, 979 mgmt_user_confirm_reply_complete(hdev, &rp->bdaddr, ACL_LINK, 0,
980 0, rp->status); 980 rp->status);
981 981
982 hci_dev_unlock(hdev); 982 hci_dev_unlock(hdev);
983} 983}
@@ -993,8 +993,7 @@ static void hci_cc_user_confirm_neg_reply(struct hci_dev *hdev,
993 993
994 if (test_bit(HCI_MGMT, &hdev->dev_flags)) 994 if (test_bit(HCI_MGMT, &hdev->dev_flags))
995 mgmt_user_confirm_neg_reply_complete(hdev, &rp->bdaddr, 995 mgmt_user_confirm_neg_reply_complete(hdev, &rp->bdaddr,
996 ACL_LINK, 0, 996 ACL_LINK, 0, rp->status);
997 rp->status);
998 997
999 hci_dev_unlock(hdev); 998 hci_dev_unlock(hdev);
1000} 999}
@@ -1009,7 +1008,7 @@ static void hci_cc_user_passkey_reply(struct hci_dev *hdev, struct sk_buff *skb)
1009 1008
1010 if (test_bit(HCI_MGMT, &hdev->dev_flags)) 1009 if (test_bit(HCI_MGMT, &hdev->dev_flags))
1011 mgmt_user_passkey_reply_complete(hdev, &rp->bdaddr, ACL_LINK, 1010 mgmt_user_passkey_reply_complete(hdev, &rp->bdaddr, ACL_LINK,
1012 0, rp->status); 1011 0, rp->status);
1013 1012
1014 hci_dev_unlock(hdev); 1013 hci_dev_unlock(hdev);
1015} 1014}
@@ -1025,8 +1024,7 @@ static void hci_cc_user_passkey_neg_reply(struct hci_dev *hdev,
1025 1024
1026 if (test_bit(HCI_MGMT, &hdev->dev_flags)) 1025 if (test_bit(HCI_MGMT, &hdev->dev_flags))
1027 mgmt_user_passkey_neg_reply_complete(hdev, &rp->bdaddr, 1026 mgmt_user_passkey_neg_reply_complete(hdev, &rp->bdaddr,
1028 ACL_LINK, 0, 1027 ACL_LINK, 0, rp->status);
1029 rp->status);
1030 1028
1031 hci_dev_unlock(hdev); 1029 hci_dev_unlock(hdev);
1032} 1030}
@@ -1337,7 +1335,7 @@ static int hci_outgoing_auth_needed(struct hci_dev *hdev,
1337} 1335}
1338 1336
1339static inline int hci_resolve_name(struct hci_dev *hdev, 1337static inline int hci_resolve_name(struct hci_dev *hdev,
1340 struct inquiry_entry *e) 1338 struct inquiry_entry *e)
1341{ 1339{
1342 struct hci_cp_remote_name_req cp; 1340 struct hci_cp_remote_name_req cp;
1343 1341
@@ -1369,14 +1367,14 @@ static bool hci_resolve_next_name(struct hci_dev *hdev)
1369} 1367}
1370 1368
1371static void hci_check_pending_name(struct hci_dev *hdev, struct hci_conn *conn, 1369static void hci_check_pending_name(struct hci_dev *hdev, struct hci_conn *conn,
1372 bdaddr_t *bdaddr, u8 *name, u8 name_len) 1370 bdaddr_t *bdaddr, u8 *name, u8 name_len)
1373{ 1371{
1374 struct discovery_state *discov = &hdev->discovery; 1372 struct discovery_state *discov = &hdev->discovery;
1375 struct inquiry_entry *e; 1373 struct inquiry_entry *e;
1376 1374
1377 if (conn && !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) 1375 if (conn && !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
1378 mgmt_device_connected(hdev, bdaddr, ACL_LINK, 0x00, 0, 1376 mgmt_device_connected(hdev, bdaddr, ACL_LINK, 0x00, 0, name,
1379 name, name_len, conn->dev_class); 1377 name_len, conn->dev_class);
1380 1378
1381 if (discov->state == DISCOVERY_STOPPED) 1379 if (discov->state == DISCOVERY_STOPPED)
1382 return; 1380 return;
@@ -1393,7 +1391,7 @@ static void hci_check_pending_name(struct hci_dev *hdev, struct hci_conn *conn,
1393 list_del(&e->list); 1391 list_del(&e->list);
1394 if (name) 1392 if (name)
1395 mgmt_remote_name(hdev, bdaddr, ACL_LINK, 0x00, 1393 mgmt_remote_name(hdev, bdaddr, ACL_LINK, 0x00,
1396 e->data.rssi, name, name_len); 1394 e->data.rssi, name, name_len);
1397 } 1395 }
1398 1396
1399 if (hci_resolve_next_name(hdev)) 1397 if (hci_resolve_next_name(hdev))
@@ -1602,7 +1600,7 @@ static void hci_cs_disconnect(struct hci_dev *hdev, u8 status)
1602 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); 1600 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1603 if (conn) 1601 if (conn)
1604 mgmt_disconnect_failed(hdev, &conn->dst, conn->type, 1602 mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
1605 conn->dst_type, status); 1603 conn->dst_type, status);
1606 1604
1607 hci_dev_unlock(hdev); 1605 hci_dev_unlock(hdev);
1608} 1606}
@@ -1718,8 +1716,8 @@ static inline void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *
1718 1716
1719 name_known = hci_inquiry_cache_update(hdev, &data, false, &ssp); 1717 name_known = hci_inquiry_cache_update(hdev, &data, false, &ssp);
1720 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00, 1718 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
1721 info->dev_class, 0, !name_known, ssp, 1719 info->dev_class, 0, !name_known, ssp, NULL,
1722 NULL, 0); 1720 0);
1723 } 1721 }
1724 1722
1725 hci_dev_unlock(hdev); 1723 hci_dev_unlock(hdev);
@@ -1770,7 +1768,7 @@ static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *s
1770 struct hci_cp_read_remote_features cp; 1768 struct hci_cp_read_remote_features cp;
1771 cp.handle = ev->handle; 1769 cp.handle = ev->handle;
1772 hci_send_cmd(hdev, HCI_OP_READ_REMOTE_FEATURES, 1770 hci_send_cmd(hdev, HCI_OP_READ_REMOTE_FEATURES,
1773 sizeof(cp), &cp); 1771 sizeof(cp), &cp);
1774 } 1772 }
1775 1773
1776 /* Set packet type for incoming connection */ 1774 /* Set packet type for incoming connection */
@@ -1778,14 +1776,14 @@ static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *s
1778 struct hci_cp_change_conn_ptype cp; 1776 struct hci_cp_change_conn_ptype cp;
1779 cp.handle = ev->handle; 1777 cp.handle = ev->handle;
1780 cp.pkt_type = cpu_to_le16(conn->pkt_type); 1778 cp.pkt_type = cpu_to_le16(conn->pkt_type);
1781 hci_send_cmd(hdev, HCI_OP_CHANGE_CONN_PTYPE, 1779 hci_send_cmd(hdev, HCI_OP_CHANGE_CONN_PTYPE, sizeof(cp),
1782 sizeof(cp), &cp); 1780 &cp);
1783 } 1781 }
1784 } else { 1782 } else {
1785 conn->state = BT_CLOSED; 1783 conn->state = BT_CLOSED;
1786 if (conn->type == ACL_LINK) 1784 if (conn->type == ACL_LINK)
1787 mgmt_connect_failed(hdev, &ev->bdaddr, conn->type, 1785 mgmt_connect_failed(hdev, &ev->bdaddr, conn->type,
1788 conn->dst_type, ev->status); 1786 conn->dst_type, ev->status);
1789 } 1787 }
1790 1788
1791 if (conn->type == ACL_LINK) 1789 if (conn->type == ACL_LINK)
@@ -1850,8 +1848,8 @@ static inline void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *sk
1850 else 1848 else
1851 cp.role = 0x01; /* Remain slave */ 1849 cp.role = 0x01; /* Remain slave */
1852 1850
1853 hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, 1851 hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, sizeof(cp),
1854 sizeof(cp), &cp); 1852 &cp);
1855 } else { 1853 } else {
1856 struct hci_cp_accept_sync_conn_req cp; 1854 struct hci_cp_accept_sync_conn_req cp;
1857 1855
@@ -1865,7 +1863,7 @@ static inline void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *sk
1865 cp.retrans_effort = 0xff; 1863 cp.retrans_effort = 0xff;
1866 1864
1867 hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ, 1865 hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ,
1868 sizeof(cp), &cp); 1866 sizeof(cp), &cp);
1869 } 1867 }
1870 } else { 1868 } else {
1871 /* Connection rejected */ 1869 /* Connection rejected */
@@ -1900,7 +1898,7 @@ static inline void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff
1900 conn->dst_type, ev->status); 1898 conn->dst_type, ev->status);
1901 else 1899 else
1902 mgmt_device_disconnected(hdev, &conn->dst, conn->type, 1900 mgmt_device_disconnected(hdev, &conn->dst, conn->type,
1903 conn->dst_type); 1901 conn->dst_type);
1904 } 1902 }
1905 1903
1906 if (ev->status == 0) { 1904 if (ev->status == 0) {
@@ -1935,7 +1933,7 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *s
1935 } 1933 }
1936 } else { 1934 } else {
1937 mgmt_auth_failed(hdev, &conn->dst, conn->type, conn->dst_type, 1935 mgmt_auth_failed(hdev, &conn->dst, conn->type, conn->dst_type,
1938 ev->status); 1936 ev->status);
1939 } 1937 }
1940 1938
1941 clear_bit(HCI_CONN_AUTH_PEND, &conn->flags); 1939 clear_bit(HCI_CONN_AUTH_PEND, &conn->flags);
@@ -1996,7 +1994,7 @@ static inline void hci_remote_name_evt(struct hci_dev *hdev, struct sk_buff *skb
1996 1994
1997 if (ev->status == 0) 1995 if (ev->status == 0)
1998 hci_check_pending_name(hdev, conn, &ev->bdaddr, ev->name, 1996 hci_check_pending_name(hdev, conn, &ev->bdaddr, ev->name,
1999 strnlen(ev->name, HCI_MAX_NAME_LENGTH)); 1997 strnlen(ev->name, HCI_MAX_NAME_LENGTH));
2000 else 1998 else
2001 hci_check_pending_name(hdev, conn, &ev->bdaddr, NULL, 0); 1999 hci_check_pending_name(hdev, conn, &ev->bdaddr, NULL, 0);
2002 2000
@@ -2111,8 +2109,8 @@ static inline void hci_remote_features_evt(struct hci_dev *hdev, struct sk_buff
2111 hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp); 2109 hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
2112 } else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) 2110 } else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
2113 mgmt_device_connected(hdev, &conn->dst, conn->type, 2111 mgmt_device_connected(hdev, &conn->dst, conn->type,
2114 conn->dst_type, 0, NULL, 0, 2112 conn->dst_type, 0, NULL, 0,
2115 conn->dev_class); 2113 conn->dev_class);
2116 2114
2117 if (!hci_outgoing_auth_needed(hdev, conn)) { 2115 if (!hci_outgoing_auth_needed(hdev, conn)) {
2118 conn->state = BT_CONNECTED; 2116 conn->state = BT_CONNECTED;
@@ -2524,7 +2522,7 @@ static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *s
2524} 2522}
2525 2523
2526static inline void hci_num_comp_blocks_evt(struct hci_dev *hdev, 2524static inline void hci_num_comp_blocks_evt(struct hci_dev *hdev,
2527 struct sk_buff *skb) 2525 struct sk_buff *skb)
2528{ 2526{
2529 struct hci_ev_num_comp_blocks *ev = (void *) skb->data; 2527 struct hci_ev_num_comp_blocks *ev = (void *) skb->data;
2530 int i; 2528 int i;
@@ -2816,10 +2814,10 @@ static inline void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, struct
2816 data.ssp_mode = 0x00; 2814 data.ssp_mode = 0x00;
2817 2815
2818 name_known = hci_inquiry_cache_update(hdev, &data, 2816 name_known = hci_inquiry_cache_update(hdev, &data,
2819 false, &ssp); 2817 false, &ssp);
2820 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00, 2818 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
2821 info->dev_class, info->rssi, 2819 info->dev_class, info->rssi,
2822 !name_known, ssp, NULL, 0); 2820 !name_known, ssp, NULL, 0);
2823 } 2821 }
2824 } else { 2822 } else {
2825 struct inquiry_info_with_rssi *info = (void *) (skb->data + 1); 2823 struct inquiry_info_with_rssi *info = (void *) (skb->data + 1);
@@ -2834,10 +2832,10 @@ static inline void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, struct
2834 data.rssi = info->rssi; 2832 data.rssi = info->rssi;
2835 data.ssp_mode = 0x00; 2833 data.ssp_mode = 0x00;
2836 name_known = hci_inquiry_cache_update(hdev, &data, 2834 name_known = hci_inquiry_cache_update(hdev, &data,
2837 false, &ssp); 2835 false, &ssp);
2838 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00, 2836 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
2839 info->dev_class, info->rssi, 2837 info->dev_class, info->rssi,
2840 !name_known, ssp, NULL, 0); 2838 !name_known, ssp, NULL, 0);
2841 } 2839 }
2842 } 2840 }
2843 2841
@@ -2879,8 +2877,8 @@ static inline void hci_remote_ext_features_evt(struct hci_dev *hdev, struct sk_b
2879 hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp); 2877 hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
2880 } else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) 2878 } else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
2881 mgmt_device_connected(hdev, &conn->dst, conn->type, 2879 mgmt_device_connected(hdev, &conn->dst, conn->type,
2882 conn->dst_type, 0, NULL, 0, 2880 conn->dst_type, 0, NULL, 0,
2883 conn->dev_class); 2881 conn->dev_class);
2884 2882
2885 if (!hci_outgoing_auth_needed(hdev, conn)) { 2883 if (!hci_outgoing_auth_needed(hdev, conn)) {
2886 conn->state = BT_CONNECTED; 2884 conn->state = BT_CONNECTED;
@@ -2986,17 +2984,16 @@ static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct
2986 2984
2987 if (test_bit(HCI_MGMT, &hdev->dev_flags)) 2985 if (test_bit(HCI_MGMT, &hdev->dev_flags))
2988 name_known = eir_has_data_type(info->data, 2986 name_known = eir_has_data_type(info->data,
2989 sizeof(info->data), 2987 sizeof(info->data),
2990 EIR_NAME_COMPLETE); 2988 EIR_NAME_COMPLETE);
2991 else 2989 else
2992 name_known = true; 2990 name_known = true;
2993 2991
2994 name_known = hci_inquiry_cache_update(hdev, &data, name_known, 2992 name_known = hci_inquiry_cache_update(hdev, &data, name_known,
2995 &ssp); 2993 &ssp);
2996 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00, 2994 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
2997 info->dev_class, info->rssi, 2995 info->dev_class, info->rssi, !name_known,
2998 !name_known, ssp, info->data, 2996 ssp, info->data, sizeof(info->data));
2999 sizeof(info->data));
3000 } 2997 }
3001 2998
3002 hci_dev_unlock(hdev); 2999 hci_dev_unlock(hdev);
@@ -3157,7 +3154,7 @@ static inline void hci_user_confirm_request_evt(struct hci_dev *hdev,
3157 3154
3158confirm: 3155confirm:
3159 mgmt_user_confirm_request(hdev, &ev->bdaddr, ACL_LINK, 0, ev->passkey, 3156 mgmt_user_confirm_request(hdev, &ev->bdaddr, ACL_LINK, 0, ev->passkey,
3160 confirm_hint); 3157 confirm_hint);
3161 3158
3162unlock: 3159unlock:
3163 hci_dev_unlock(hdev); 3160 hci_dev_unlock(hdev);
@@ -3198,7 +3195,7 @@ static inline void hci_simple_pair_complete_evt(struct hci_dev *hdev, struct sk_
3198 * the mgmt_auth_failed event */ 3195 * the mgmt_auth_failed event */
3199 if (!test_bit(HCI_CONN_AUTH_PEND, &conn->flags) && ev->status != 0) 3196 if (!test_bit(HCI_CONN_AUTH_PEND, &conn->flags) && ev->status != 0)
3200 mgmt_auth_failed(hdev, &conn->dst, conn->type, conn->dst_type, 3197 mgmt_auth_failed(hdev, &conn->dst, conn->type, conn->dst_type,
3201 ev->status); 3198 ev->status);
3202 3199
3203 hci_conn_put(conn); 3200 hci_conn_put(conn);
3204 3201
@@ -3223,7 +3220,7 @@ static inline void hci_remote_host_features_evt(struct hci_dev *hdev, struct sk_
3223} 3220}
3224 3221
3225static inline void hci_remote_oob_data_request_evt(struct hci_dev *hdev, 3222static inline void hci_remote_oob_data_request_evt(struct hci_dev *hdev,
3226 struct sk_buff *skb) 3223 struct sk_buff *skb)
3227{ 3224{
3228 struct hci_ev_remote_oob_data_request *ev = (void *) skb->data; 3225 struct hci_ev_remote_oob_data_request *ev = (void *) skb->data;
3229 struct oob_data *data; 3226 struct oob_data *data;
@@ -3289,7 +3286,7 @@ static inline void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff
3289 3286
3290 if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) 3287 if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
3291 mgmt_device_connected(hdev, &ev->bdaddr, conn->type, 3288 mgmt_device_connected(hdev, &ev->bdaddr, conn->type,
3292 conn->dst_type, 0, NULL, 0, NULL); 3289 conn->dst_type, 0, NULL, 0, NULL);
3293 3290
3294 conn->sec_level = BT_SECURITY_LOW; 3291 conn->sec_level = BT_SECURITY_LOW;
3295 conn->handle = __le16_to_cpu(ev->handle); 3292 conn->handle = __le16_to_cpu(ev->handle);
@@ -3320,8 +3317,7 @@ static inline void hci_le_adv_report_evt(struct hci_dev *hdev,
3320 3317
3321 rssi = ev->data[ev->length]; 3318 rssi = ev->data[ev->length];
3322 mgmt_device_found(hdev, &ev->bdaddr, LE_LINK, ev->bdaddr_type, 3319 mgmt_device_found(hdev, &ev->bdaddr, LE_LINK, ev->bdaddr_type,
3323 NULL, rssi, 0, 1, ev->data, 3320 NULL, rssi, 0, 1, ev->data, ev->length);
3324 ev->length);
3325 3321
3326 ptr += sizeof(*ev) + ev->length + 1; 3322 ptr += sizeof(*ev) + ev->length + 1;
3327 } 3323 }
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 0b1aabff8649..3e450f4a3125 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1546,7 +1546,9 @@ static void l2cap_send_srejtail(struct l2cap_chan *chan)
1546 l2cap_send_sframe(chan, control); 1546 l2cap_send_sframe(chan, control);
1547} 1547}
1548 1548
1549static inline int l2cap_skbuff_fromiovec(struct l2cap_chan *chan, struct msghdr *msg, int len, int count, struct sk_buff *skb) 1549static inline int l2cap_skbuff_fromiovec(struct l2cap_chan *chan,
1550 struct msghdr *msg, int len,
1551 int count, struct sk_buff *skb)
1550{ 1552{
1551 struct l2cap_conn *conn = chan->conn; 1553 struct l2cap_conn *conn = chan->conn;
1552 struct sk_buff **frag; 1554 struct sk_buff **frag;
@@ -1564,7 +1566,8 @@ static inline int l2cap_skbuff_fromiovec(struct l2cap_chan *chan, struct msghdr
1564 count = min_t(unsigned int, conn->mtu, len); 1566 count = min_t(unsigned int, conn->mtu, len);
1565 1567
1566 *frag = chan->ops->alloc_skb(chan, count, 1568 *frag = chan->ops->alloc_skb(chan, count,
1567 msg->msg_flags & MSG_DONTWAIT, &err); 1569 msg->msg_flags & MSG_DONTWAIT,
1570 &err);
1568 1571
1569 if (!*frag) 1572 if (!*frag)
1570 return err; 1573 return err;
@@ -1596,7 +1599,7 @@ static struct sk_buff *l2cap_create_connless_pdu(struct l2cap_chan *chan,
1596 count = min_t(unsigned int, (conn->mtu - hlen), len); 1599 count = min_t(unsigned int, (conn->mtu - hlen), len);
1597 1600
1598 skb = chan->ops->alloc_skb(chan, count + hlen, 1601 skb = chan->ops->alloc_skb(chan, count + hlen,
1599 msg->msg_flags & MSG_DONTWAIT, &err); 1602 msg->msg_flags & MSG_DONTWAIT, &err);
1600 1603
1601 if (!skb) 1604 if (!skb)
1602 return ERR_PTR(err); 1605 return ERR_PTR(err);
@@ -1631,7 +1634,7 @@ static struct sk_buff *l2cap_create_basic_pdu(struct l2cap_chan *chan,
1631 count = min_t(unsigned int, (conn->mtu - hlen), len); 1634 count = min_t(unsigned int, (conn->mtu - hlen), len);
1632 1635
1633 skb = chan->ops->alloc_skb(chan, count + hlen, 1636 skb = chan->ops->alloc_skb(chan, count + hlen,
1634 msg->msg_flags & MSG_DONTWAIT, &err); 1637 msg->msg_flags & MSG_DONTWAIT, &err);
1635 1638
1636 if (!skb) 1639 if (!skb)
1637 return ERR_PTR(err); 1640 return ERR_PTR(err);
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 3da56c5c1fc9..c4fe583b0af6 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -926,7 +926,8 @@ static void l2cap_sock_state_change_cb(void *data, int state)
926} 926}
927 927
928static struct sk_buff *l2cap_sock_alloc_skb_cb(struct l2cap_chan *chan, 928static struct sk_buff *l2cap_sock_alloc_skb_cb(struct l2cap_chan *chan,
929 unsigned long len, int nb, int *err) 929 unsigned long len, int nb,
930 int *err)
930{ 931{
931 struct sock *sk = chan->sk; 932 struct sock *sk = chan->sk;
932 933
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);
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 75937d73d8ae..8f56282c247d 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -264,7 +264,7 @@ static void smp_failure(struct l2cap_conn *conn, u8 reason, u8 send)
264 264
265 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->hcon->flags); 265 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->hcon->flags);
266 mgmt_auth_failed(conn->hcon->hdev, conn->dst, hcon->type, 266 mgmt_auth_failed(conn->hcon->hdev, conn->dst, hcon->type,
267 hcon->dst_type, reason); 267 hcon->dst_type, reason);
268 268
269 if (test_and_clear_bit(HCI_CONN_LE_SMP_PEND, &conn->hcon->flags)) { 269 if (test_and_clear_bit(HCI_CONN_LE_SMP_PEND, &conn->hcon->flags)) {
270 cancel_delayed_work_sync(&conn->security_timer); 270 cancel_delayed_work_sync(&conn->security_timer);
@@ -384,12 +384,11 @@ static void confirm_work(struct work_struct *work)
384 384
385 if (conn->hcon->out) 385 if (conn->hcon->out)
386 ret = smp_c1(tfm, smp->tk, smp->prnd, smp->preq, smp->prsp, 0, 386 ret = smp_c1(tfm, smp->tk, smp->prnd, smp->preq, smp->prsp, 0,
387 conn->src, conn->hcon->dst_type, conn->dst, 387 conn->src, conn->hcon->dst_type, conn->dst, res);
388 res);
389 else 388 else
390 ret = smp_c1(tfm, smp->tk, smp->prnd, smp->preq, smp->prsp, 389 ret = smp_c1(tfm, smp->tk, smp->prnd, smp->preq, smp->prsp,
391 conn->hcon->dst_type, conn->dst, 0, conn->src, 390 conn->hcon->dst_type, conn->dst, 0, conn->src,
392 res); 391 res);
393 if (ret) { 392 if (ret) {
394 reason = SMP_UNSPECIFIED; 393 reason = SMP_UNSPECIFIED;
395 goto error; 394 goto error;
@@ -424,12 +423,10 @@ static void random_work(struct work_struct *work)
424 423
425 if (hcon->out) 424 if (hcon->out)
426 ret = smp_c1(tfm, smp->tk, smp->rrnd, smp->preq, smp->prsp, 0, 425 ret = smp_c1(tfm, smp->tk, smp->rrnd, smp->preq, smp->prsp, 0,
427 conn->src, hcon->dst_type, conn->dst, 426 conn->src, hcon->dst_type, conn->dst, res);
428 res);
429 else 427 else
430 ret = smp_c1(tfm, smp->tk, smp->rrnd, smp->preq, smp->prsp, 428 ret = smp_c1(tfm, smp->tk, smp->rrnd, smp->preq, smp->prsp,
431 hcon->dst_type, conn->dst, 0, conn->src, 429 hcon->dst_type, conn->dst, 0, conn->src, res);
432 res);
433 if (ret) { 430 if (ret) {
434 reason = SMP_UNSPECIFIED; 431 reason = SMP_UNSPECIFIED;
435 goto error; 432 goto error;
@@ -454,7 +451,7 @@ static void random_work(struct work_struct *work)
454 swap128(key, stk); 451 swap128(key, stk);
455 452
456 memset(stk + smp->enc_key_size, 0, 453 memset(stk + smp->enc_key_size, 0,
457 SMP_MAX_ENC_KEY_SIZE - smp->enc_key_size); 454 SMP_MAX_ENC_KEY_SIZE - smp->enc_key_size);
458 455
459 if (test_and_set_bit(HCI_CONN_ENCRYPT_PEND, &hcon->flags)) { 456 if (test_and_set_bit(HCI_CONN_ENCRYPT_PEND, &hcon->flags)) {
460 reason = SMP_UNSPECIFIED; 457 reason = SMP_UNSPECIFIED;
@@ -480,8 +477,8 @@ static void random_work(struct work_struct *work)
480 SMP_MAX_ENC_KEY_SIZE - smp->enc_key_size); 477 SMP_MAX_ENC_KEY_SIZE - smp->enc_key_size);
481 478
482 hci_add_ltk(hcon->hdev, conn->dst, hcon->dst_type, 479 hci_add_ltk(hcon->hdev, conn->dst, hcon->dst_type,
483 HCI_SMP_STK_SLAVE, 0, 0, stk, 480 HCI_SMP_STK_SLAVE, 0, 0, stk, smp->enc_key_size,
484 smp->enc_key_size, ediv, rand); 481 ediv, rand);
485 } 482 }
486 483
487 return; 484 return;
@@ -829,8 +826,8 @@ static int smp_cmd_master_ident(struct l2cap_conn *conn, struct sk_buff *skb)
829 hci_dev_lock(hdev); 826 hci_dev_lock(hdev);
830 authenticated = (conn->hcon->sec_level == BT_SECURITY_HIGH); 827 authenticated = (conn->hcon->sec_level == BT_SECURITY_HIGH);
831 hci_add_ltk(conn->hcon->hdev, conn->dst, hcon->dst_type, 828 hci_add_ltk(conn->hcon->hdev, conn->dst, hcon->dst_type,
832 HCI_SMP_LTK, 1, authenticated, smp->tk, 829 HCI_SMP_LTK, 1, authenticated, smp->tk, smp->enc_key_size,
833 smp->enc_key_size, rp->ediv, rp->rand); 830 rp->ediv, rp->rand);
834 smp_distribute_keys(conn, 1); 831 smp_distribute_keys(conn, 1);
835 hci_dev_unlock(hdev); 832 hci_dev_unlock(hdev);
836 833
@@ -954,9 +951,8 @@ int smp_distribute_keys(struct l2cap_conn *conn, __u8 force)
954 951
955 authenticated = hcon->sec_level == BT_SECURITY_HIGH; 952 authenticated = hcon->sec_level == BT_SECURITY_HIGH;
956 hci_add_ltk(conn->hcon->hdev, conn->dst, hcon->dst_type, 953 hci_add_ltk(conn->hcon->hdev, conn->dst, hcon->dst_type,
957 HCI_SMP_LTK_SLAVE, 1, authenticated, 954 HCI_SMP_LTK_SLAVE, 1, authenticated,
958 enc.ltk, smp->enc_key_size, 955 enc.ltk, smp->enc_key_size, ediv, ident.rand);
959 ediv, ident.rand);
960 956
961 ident.ediv = cpu_to_le16(ediv); 957 ident.ediv = cpu_to_le16(ediv);
962 958