aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/mgmt.c
diff options
context:
space:
mode:
authorVinicius Costa Gomes <vinicius.gomes@openbossa.org>2012-02-02 19:07:59 -0500
committerJohan Hedberg <johan.hedberg@intel.com>2012-02-13 10:01:32 -0500
commit650f726d16a3f25153d785b531516f6e90d2014f (patch)
tree606cc339e2b3f8f2633ed1503b73dc53212f780c /net/bluetooth/mgmt.c
parent37305cf649689a4d2341dd6fd89b091c6007f9ba (diff)
Bluetooth: Fix doing some useless casts when receiving MGMT commands
Every command handler of mgmt does a cast to the command structure so it can properly interpreted. So we can avoid that cast if we make those functions receive a void * directly. Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@openbossa.org> Acked-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Diffstat (limited to 'net/bluetooth/mgmt.c')
-rw-r--r--net/bluetooth/mgmt.c205
1 files changed, 83 insertions, 122 deletions
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 00ab083749eb..ad8986276848 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -611,15 +611,13 @@ static int send_settings_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev)
611 return cmd_complete(sk, hdev->id, opcode, &settings, sizeof(settings)); 611 return cmd_complete(sk, hdev->id, opcode, &settings, sizeof(settings));
612} 612}
613 613
614static int set_powered(struct sock *sk, u16 index, unsigned char *data, u16 len) 614static int set_powered(struct sock *sk, u16 index, void *data, u16 len)
615{ 615{
616 struct mgmt_mode *cp; 616 struct mgmt_mode *cp = data;
617 struct hci_dev *hdev; 617 struct hci_dev *hdev;
618 struct pending_cmd *cmd; 618 struct pending_cmd *cmd;
619 int err, up; 619 int err, up;
620 620
621 cp = (void *) data;
622
623 BT_DBG("request for hci%u", index); 621 BT_DBG("request for hci%u", index);
624 622
625 if (len != sizeof(*cp)) 623 if (len != sizeof(*cp))
@@ -664,17 +662,14 @@ failed:
664 return err; 662 return err;
665} 663}
666 664
667static int set_discoverable(struct sock *sk, u16 index, unsigned char *data, 665static int set_discoverable(struct sock *sk, u16 index, void *data, u16 len)
668 u16 len)
669{ 666{
670 struct mgmt_cp_set_discoverable *cp; 667 struct mgmt_cp_set_discoverable *cp = data;
671 struct hci_dev *hdev; 668 struct hci_dev *hdev;
672 struct pending_cmd *cmd; 669 struct pending_cmd *cmd;
673 u8 scan; 670 u8 scan;
674 int err; 671 int err;
675 672
676 cp = (void *) data;
677
678 BT_DBG("request for hci%u", index); 673 BT_DBG("request for hci%u", index);
679 674
680 if (len != sizeof(*cp)) 675 if (len != sizeof(*cp))
@@ -734,17 +729,14 @@ failed:
734 return err; 729 return err;
735} 730}
736 731
737static int set_connectable(struct sock *sk, u16 index, unsigned char *data, 732static int set_connectable(struct sock *sk, u16 index, void *data, u16 len)
738 u16 len)
739{ 733{
740 struct mgmt_mode *cp; 734 struct mgmt_mode *cp = data;
741 struct hci_dev *hdev; 735 struct hci_dev *hdev;
742 struct pending_cmd *cmd; 736 struct pending_cmd *cmd;
743 u8 scan; 737 u8 scan;
744 int err; 738 int err;
745 739
746 cp = (void *) data;
747
748 BT_DBG("request for hci%u", index); 740 BT_DBG("request for hci%u", index);
749 741
750 if (len != sizeof(*cp)) 742 if (len != sizeof(*cp))
@@ -827,16 +819,13 @@ static int mgmt_event(u16 event, struct hci_dev *hdev, void *data,
827 return 0; 819 return 0;
828} 820}
829 821
830static int set_pairable(struct sock *sk, u16 index, unsigned char *data, 822static int set_pairable(struct sock *sk, u16 index, void *data, u16 len)
831 u16 len)
832{ 823{
833 struct mgmt_mode *cp; 824 struct mgmt_mode *cp = data;
834 struct hci_dev *hdev; 825 struct hci_dev *hdev;
835 __le32 ev; 826 __le32 ev;
836 int err; 827 int err;
837 828
838 cp = (void *) data;
839
840 BT_DBG("request for hci%u", index); 829 BT_DBG("request for hci%u", index);
841 830
842 if (len != sizeof(*cp)) 831 if (len != sizeof(*cp))
@@ -870,15 +859,13 @@ failed:
870 return err; 859 return err;
871} 860}
872 861
873static int add_uuid(struct sock *sk, u16 index, unsigned char *data, u16 len) 862static int add_uuid(struct sock *sk, u16 index, void *data, u16 len)
874{ 863{
875 struct mgmt_cp_add_uuid *cp; 864 struct mgmt_cp_add_uuid *cp = data;
876 struct hci_dev *hdev; 865 struct hci_dev *hdev;
877 struct bt_uuid *uuid; 866 struct bt_uuid *uuid;
878 int err; 867 int err;
879 868
880 cp = (void *) data;
881
882 BT_DBG("request for hci%u", index); 869 BT_DBG("request for hci%u", index);
883 870
884 if (len != sizeof(*cp)) 871 if (len != sizeof(*cp))
@@ -920,16 +907,14 @@ failed:
920 return err; 907 return err;
921} 908}
922 909
923static int remove_uuid(struct sock *sk, u16 index, unsigned char *data, u16 len) 910static int remove_uuid(struct sock *sk, u16 index, void *data, u16 len)
924{ 911{
912 struct mgmt_cp_remove_uuid *cp = data;
925 struct list_head *p, *n; 913 struct list_head *p, *n;
926 struct mgmt_cp_remove_uuid *cp;
927 struct hci_dev *hdev; 914 struct hci_dev *hdev;
928 u8 bt_uuid_any[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 915 u8 bt_uuid_any[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
929 int err, found; 916 int err, found;
930 917
931 cp = (void *) data;
932
933 BT_DBG("request for hci%u", index); 918 BT_DBG("request for hci%u", index);
934 919
935 if (len != sizeof(*cp)) 920 if (len != sizeof(*cp))
@@ -983,15 +968,12 @@ unlock:
983 return err; 968 return err;
984} 969}
985 970
986static int set_dev_class(struct sock *sk, u16 index, unsigned char *data, 971static int set_dev_class(struct sock *sk, u16 index, void *data, u16 len)
987 u16 len)
988{ 972{
989 struct hci_dev *hdev; 973 struct hci_dev *hdev;
990 struct mgmt_cp_set_dev_class *cp; 974 struct mgmt_cp_set_dev_class *cp = data;
991 int err; 975 int err;
992 976
993 cp = (void *) data;
994
995 BT_DBG("request for hci%u", index); 977 BT_DBG("request for hci%u", index);
996 978
997 if (len != sizeof(*cp)) 979 if (len != sizeof(*cp))
@@ -1026,16 +1008,13 @@ static int set_dev_class(struct sock *sk, u16 index, unsigned char *data,
1026 return err; 1008 return err;
1027} 1009}
1028 1010
1029static int load_link_keys(struct sock *sk, u16 index, unsigned char *data, 1011static int load_link_keys(struct sock *sk, u16 index, void *data, u16 len)
1030 u16 len)
1031{ 1012{
1032 struct hci_dev *hdev; 1013 struct hci_dev *hdev;
1033 struct mgmt_cp_load_link_keys *cp; 1014 struct mgmt_cp_load_link_keys *cp = data;
1034 u16 key_count, expected_len; 1015 u16 key_count, expected_len;
1035 int i; 1016 int i;
1036 1017
1037 cp = (void *) data;
1038
1039 if (len < sizeof(*cp)) 1018 if (len < sizeof(*cp))
1040 return cmd_status(sk, index, MGMT_OP_LOAD_LINK_KEYS, 1019 return cmd_status(sk, index, MGMT_OP_LOAD_LINK_KEYS,
1041 MGMT_STATUS_INVALID_PARAMS); 1020 MGMT_STATUS_INVALID_PARAMS);
@@ -1085,19 +1064,16 @@ static int load_link_keys(struct sock *sk, u16 index, unsigned char *data,
1085 return 0; 1064 return 0;
1086} 1065}
1087 1066
1088static int remove_keys(struct sock *sk, u16 index, unsigned char *data, 1067static int remove_keys(struct sock *sk, u16 index, void *data, u16 len)
1089 u16 len)
1090{ 1068{
1091 struct hci_dev *hdev; 1069 struct hci_dev *hdev;
1092 struct mgmt_cp_remove_keys *cp; 1070 struct mgmt_cp_remove_keys *cp = data;
1093 struct mgmt_rp_remove_keys rp; 1071 struct mgmt_rp_remove_keys rp;
1094 struct hci_cp_disconnect dc; 1072 struct hci_cp_disconnect dc;
1095 struct pending_cmd *cmd; 1073 struct pending_cmd *cmd;
1096 struct hci_conn *conn; 1074 struct hci_conn *conn;
1097 int err; 1075 int err;
1098 1076
1099 cp = (void *) data;
1100
1101 if (len != sizeof(*cp)) 1077 if (len != sizeof(*cp))
1102 return cmd_status(sk, index, MGMT_OP_REMOVE_KEYS, 1078 return cmd_status(sk, index, MGMT_OP_REMOVE_KEYS,
1103 MGMT_STATUS_INVALID_PARAMS); 1079 MGMT_STATUS_INVALID_PARAMS);
@@ -1154,10 +1130,10 @@ unlock:
1154 return err; 1130 return err;
1155} 1131}
1156 1132
1157static int disconnect(struct sock *sk, u16 index, unsigned char *data, u16 len) 1133static int disconnect(struct sock *sk, u16 index, void *data, u16 len)
1158{ 1134{
1159 struct hci_dev *hdev; 1135 struct hci_dev *hdev;
1160 struct mgmt_cp_disconnect *cp; 1136 struct mgmt_cp_disconnect *cp = data;
1161 struct hci_cp_disconnect dc; 1137 struct hci_cp_disconnect dc;
1162 struct pending_cmd *cmd; 1138 struct pending_cmd *cmd;
1163 struct hci_conn *conn; 1139 struct hci_conn *conn;
@@ -1165,8 +1141,6 @@ static int disconnect(struct sock *sk, u16 index, unsigned char *data, u16 len)
1165 1141
1166 BT_DBG(""); 1142 BT_DBG("");
1167 1143
1168 cp = (void *) data;
1169
1170 if (len != sizeof(*cp)) 1144 if (len != sizeof(*cp))
1171 return cmd_status(sk, index, MGMT_OP_DISCONNECT, 1145 return cmd_status(sk, index, MGMT_OP_DISCONNECT,
1172 MGMT_STATUS_INVALID_PARAMS); 1146 MGMT_STATUS_INVALID_PARAMS);
@@ -1314,12 +1288,11 @@ static int send_pin_code_neg_reply(struct sock *sk, u16 index,
1314 return err; 1288 return err;
1315} 1289}
1316 1290
1317static int pin_code_reply(struct sock *sk, u16 index, unsigned char *data, 1291static int pin_code_reply(struct sock *sk, u16 index, void *data, u16 len)
1318 u16 len)
1319{ 1292{
1320 struct hci_dev *hdev; 1293 struct hci_dev *hdev;
1321 struct hci_conn *conn; 1294 struct hci_conn *conn;
1322 struct mgmt_cp_pin_code_reply *cp; 1295 struct mgmt_cp_pin_code_reply *cp = data;
1323 struct mgmt_cp_pin_code_neg_reply ncp; 1296 struct mgmt_cp_pin_code_neg_reply ncp;
1324 struct hci_cp_pin_code_reply reply; 1297 struct hci_cp_pin_code_reply reply;
1325 struct pending_cmd *cmd; 1298 struct pending_cmd *cmd;
@@ -1327,8 +1300,6 @@ static int pin_code_reply(struct sock *sk, u16 index, unsigned char *data,
1327 1300
1328 BT_DBG(""); 1301 BT_DBG("");
1329 1302
1330 cp = (void *) data;
1331
1332 if (len != sizeof(*cp)) 1303 if (len != sizeof(*cp))
1333 return cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY, 1304 return cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY,
1334 MGMT_STATUS_INVALID_PARAMS); 1305 MGMT_STATUS_INVALID_PARAMS);
@@ -1366,7 +1337,8 @@ static int pin_code_reply(struct sock *sk, u16 index, unsigned char *data,
1366 goto failed; 1337 goto failed;
1367 } 1338 }
1368 1339
1369 cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_REPLY, hdev, data, len); 1340 cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_REPLY, hdev, data,
1341 len);
1370 if (!cmd) { 1342 if (!cmd) {
1371 err = -ENOMEM; 1343 err = -ENOMEM;
1372 goto failed; 1344 goto failed;
@@ -1387,17 +1359,14 @@ failed:
1387 return err; 1359 return err;
1388} 1360}
1389 1361
1390static int pin_code_neg_reply(struct sock *sk, u16 index, unsigned char *data, 1362static int pin_code_neg_reply(struct sock *sk, u16 index, void *data, u16 len)
1391 u16 len)
1392{ 1363{
1393 struct hci_dev *hdev; 1364 struct hci_dev *hdev;
1394 struct mgmt_cp_pin_code_neg_reply *cp; 1365 struct mgmt_cp_pin_code_neg_reply *cp = data;
1395 int err; 1366 int err;
1396 1367
1397 BT_DBG(""); 1368 BT_DBG("");
1398 1369
1399 cp = (void *) data;
1400
1401 if (len != sizeof(*cp)) 1370 if (len != sizeof(*cp))
1402 return cmd_status(sk, index, MGMT_OP_PIN_CODE_NEG_REPLY, 1371 return cmd_status(sk, index, MGMT_OP_PIN_CODE_NEG_REPLY,
1403 MGMT_STATUS_INVALID_PARAMS); 1372 MGMT_STATUS_INVALID_PARAMS);
@@ -1424,16 +1393,13 @@ failed:
1424 return err; 1393 return err;
1425} 1394}
1426 1395
1427static int set_io_capability(struct sock *sk, u16 index, unsigned char *data, 1396static int set_io_capability(struct sock *sk, u16 index, void *data, u16 len)
1428 u16 len)
1429{ 1397{
1430 struct hci_dev *hdev; 1398 struct hci_dev *hdev;
1431 struct mgmt_cp_set_io_capability *cp; 1399 struct mgmt_cp_set_io_capability *cp = data;
1432 1400
1433 BT_DBG(""); 1401 BT_DBG("");
1434 1402
1435 cp = (void *) data;
1436
1437 if (len != sizeof(*cp)) 1403 if (len != sizeof(*cp))
1438 return cmd_status(sk, index, MGMT_OP_SET_IO_CAPABILITY, 1404 return cmd_status(sk, index, MGMT_OP_SET_IO_CAPABILITY,
1439 MGMT_STATUS_INVALID_PARAMS); 1405 MGMT_STATUS_INVALID_PARAMS);
@@ -1508,10 +1474,10 @@ static void pairing_complete_cb(struct hci_conn *conn, u8 status)
1508 pairing_complete(cmd, status); 1474 pairing_complete(cmd, status);
1509} 1475}
1510 1476
1511static int pair_device(struct sock *sk, u16 index, unsigned char *data, u16 len) 1477static int pair_device(struct sock *sk, u16 index, void *data, u16 len)
1512{ 1478{
1513 struct hci_dev *hdev; 1479 struct hci_dev *hdev;
1514 struct mgmt_cp_pair_device *cp; 1480 struct mgmt_cp_pair_device *cp = data;
1515 struct mgmt_rp_pair_device rp; 1481 struct mgmt_rp_pair_device rp;
1516 struct pending_cmd *cmd; 1482 struct pending_cmd *cmd;
1517 u8 sec_level, auth_type; 1483 u8 sec_level, auth_type;
@@ -1520,8 +1486,6 @@ static int pair_device(struct sock *sk, u16 index, unsigned char *data, u16 len)
1520 1486
1521 BT_DBG(""); 1487 BT_DBG("");
1522 1488
1523 cp = (void *) data;
1524
1525 if (len != sizeof(*cp)) 1489 if (len != sizeof(*cp))
1526 return cmd_status(sk, index, MGMT_OP_PAIR_DEVICE, 1490 return cmd_status(sk, index, MGMT_OP_PAIR_DEVICE,
1527 MGMT_STATUS_INVALID_PARAMS); 1491 MGMT_STATUS_INVALID_PARAMS);
@@ -1721,7 +1685,7 @@ done:
1721 1685
1722static int user_confirm_reply(struct sock *sk, u16 index, void *data, u16 len) 1686static int user_confirm_reply(struct sock *sk, u16 index, void *data, u16 len)
1723{ 1687{
1724 struct mgmt_cp_user_confirm_reply *cp = (void *) data; 1688 struct mgmt_cp_user_confirm_reply *cp = data;
1725 1689
1726 BT_DBG(""); 1690 BT_DBG("");
1727 1691
@@ -1752,7 +1716,7 @@ static int user_confirm_neg_reply(struct sock *sk, u16 index, void *data,
1752 1716
1753static int user_passkey_reply(struct sock *sk, u16 index, void *data, u16 len) 1717static int user_passkey_reply(struct sock *sk, u16 index, void *data, u16 len)
1754{ 1718{
1755 struct mgmt_cp_user_passkey_reply *cp = (void *) data; 1719 struct mgmt_cp_user_passkey_reply *cp = data;
1756 1720
1757 BT_DBG(""); 1721 BT_DBG("");
1758 1722
@@ -1768,7 +1732,7 @@ static int user_passkey_reply(struct sock *sk, u16 index, void *data, u16 len)
1768static int user_passkey_neg_reply(struct sock *sk, u16 index, void *data, 1732static int user_passkey_neg_reply(struct sock *sk, u16 index, void *data,
1769 u16 len) 1733 u16 len)
1770{ 1734{
1771 struct mgmt_cp_user_passkey_neg_reply *cp = (void *) data; 1735 struct mgmt_cp_user_passkey_neg_reply *cp = data;
1772 1736
1773 BT_DBG(""); 1737 BT_DBG("");
1774 1738
@@ -1781,10 +1745,10 @@ static int user_passkey_neg_reply(struct sock *sk, u16 index, void *data,
1781 HCI_OP_USER_PASSKEY_NEG_REPLY, 0); 1745 HCI_OP_USER_PASSKEY_NEG_REPLY, 0);
1782} 1746}
1783 1747
1784static int set_local_name(struct sock *sk, u16 index, unsigned char *data, 1748static int set_local_name(struct sock *sk, u16 index, void *data,
1785 u16 len) 1749 u16 len)
1786{ 1750{
1787 struct mgmt_cp_set_local_name *mgmt_cp = (void *) data; 1751 struct mgmt_cp_set_local_name *mgmt_cp = data;
1788 struct hci_cp_write_local_name hci_cp; 1752 struct hci_cp_write_local_name hci_cp;
1789 struct hci_dev *hdev; 1753 struct hci_dev *hdev;
1790 struct pending_cmd *cmd; 1754 struct pending_cmd *cmd;
@@ -1803,7 +1767,8 @@ static int set_local_name(struct sock *sk, u16 index, unsigned char *data,
1803 1767
1804 hci_dev_lock(hdev); 1768 hci_dev_lock(hdev);
1805 1769
1806 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LOCAL_NAME, hdev, data, len); 1770 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LOCAL_NAME, hdev, data,
1771 len);
1807 if (!cmd) { 1772 if (!cmd) {
1808 err = -ENOMEM; 1773 err = -ENOMEM;
1809 goto failed; 1774 goto failed;
@@ -1872,11 +1837,11 @@ unlock:
1872 return err; 1837 return err;
1873} 1838}
1874 1839
1875static int add_remote_oob_data(struct sock *sk, u16 index, unsigned char *data, 1840static int add_remote_oob_data(struct sock *sk, u16 index, void *data,
1876 u16 len) 1841 u16 len)
1877{ 1842{
1878 struct hci_dev *hdev; 1843 struct hci_dev *hdev;
1879 struct mgmt_cp_add_remote_oob_data *cp = (void *) data; 1844 struct mgmt_cp_add_remote_oob_data *cp = data;
1880 int err; 1845 int err;
1881 1846
1882 BT_DBG("hci%u ", index); 1847 BT_DBG("hci%u ", index);
@@ -1908,10 +1873,10 @@ static int add_remote_oob_data(struct sock *sk, u16 index, unsigned char *data,
1908} 1873}
1909 1874
1910static int remove_remote_oob_data(struct sock *sk, u16 index, 1875static int remove_remote_oob_data(struct sock *sk, u16 index,
1911 unsigned char *data, u16 len) 1876 void *data, u16 len)
1912{ 1877{
1913 struct hci_dev *hdev; 1878 struct hci_dev *hdev;
1914 struct mgmt_cp_remove_remote_oob_data *cp = (void *) data; 1879 struct mgmt_cp_remove_remote_oob_data *cp = data;
1915 int err; 1880 int err;
1916 1881
1917 BT_DBG("hci%u ", index); 1882 BT_DBG("hci%u ", index);
@@ -1942,9 +1907,9 @@ static int remove_remote_oob_data(struct sock *sk, u16 index,
1942} 1907}
1943 1908
1944static int start_discovery(struct sock *sk, u16 index, 1909static int start_discovery(struct sock *sk, u16 index,
1945 unsigned char *data, u16 len) 1910 void *data, u16 len)
1946{ 1911{
1947 struct mgmt_cp_start_discovery *cp = (void *) data; 1912 struct mgmt_cp_start_discovery *cp = data;
1948 struct pending_cmd *cmd; 1913 struct pending_cmd *cmd;
1949 struct hci_dev *hdev; 1914 struct hci_dev *hdev;
1950 int err; 1915 int err;
@@ -2054,10 +2019,9 @@ unlock:
2054 return err; 2019 return err;
2055} 2020}
2056 2021
2057static int confirm_name(struct sock *sk, u16 index, unsigned char *data, 2022static int confirm_name(struct sock *sk, u16 index, void *data, u16 len)
2058 u16 len)
2059{ 2023{
2060 struct mgmt_cp_confirm_name *cp = (void *) data; 2024 struct mgmt_cp_confirm_name *cp = data;
2061 struct inquiry_entry *e; 2025 struct inquiry_entry *e;
2062 struct hci_dev *hdev; 2026 struct hci_dev *hdev;
2063 int err; 2027 int err;
@@ -2104,11 +2068,10 @@ failed:
2104 return err; 2068 return err;
2105} 2069}
2106 2070
2107static int block_device(struct sock *sk, u16 index, unsigned char *data, 2071static int block_device(struct sock *sk, u16 index, void *data, u16 len)
2108 u16 len)
2109{ 2072{
2110 struct hci_dev *hdev; 2073 struct hci_dev *hdev;
2111 struct mgmt_cp_block_device *cp = (void *) data; 2074 struct mgmt_cp_block_device *cp = data;
2112 int err; 2075 int err;
2113 2076
2114 BT_DBG("hci%u", index); 2077 BT_DBG("hci%u", index);
@@ -2138,11 +2101,10 @@ static int block_device(struct sock *sk, u16 index, unsigned char *data,
2138 return err; 2101 return err;
2139} 2102}
2140 2103
2141static int unblock_device(struct sock *sk, u16 index, unsigned char *data, 2104static int unblock_device(struct sock *sk, u16 index, void *data, u16 len)
2142 u16 len)
2143{ 2105{
2144 struct hci_dev *hdev; 2106 struct hci_dev *hdev;
2145 struct mgmt_cp_unblock_device *cp = (void *) data; 2107 struct mgmt_cp_unblock_device *cp = data;
2146 int err; 2108 int err;
2147 2109
2148 BT_DBG("hci%u", index); 2110 BT_DBG("hci%u", index);
@@ -2174,10 +2136,10 @@ static int unblock_device(struct sock *sk, u16 index, unsigned char *data,
2174} 2136}
2175 2137
2176static int set_fast_connectable(struct sock *sk, u16 index, 2138static int set_fast_connectable(struct sock *sk, u16 index,
2177 unsigned char *data, u16 len) 2139 void *data, u16 len)
2178{ 2140{
2179 struct hci_dev *hdev; 2141 struct hci_dev *hdev;
2180 struct mgmt_mode *cp = (void *) data; 2142 struct mgmt_mode *cp = data;
2181 struct hci_cp_write_page_scan_activity acp; 2143 struct hci_cp_write_page_scan_activity acp;
2182 u8 type; 2144 u8 type;
2183 int err; 2145 int err;
@@ -2231,7 +2193,8 @@ done:
2231 2193
2232int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen) 2194int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
2233{ 2195{
2234 unsigned char *buf; 2196 void *buf;
2197 u8 *cp;
2235 struct mgmt_hdr *hdr; 2198 struct mgmt_hdr *hdr;
2236 u16 opcode, index, len; 2199 u16 opcode, index, len;
2237 int err; 2200 int err;
@@ -2250,7 +2213,7 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
2250 goto done; 2213 goto done;
2251 } 2214 }
2252 2215
2253 hdr = (struct mgmt_hdr *) buf; 2216 hdr = buf;
2254 opcode = get_unaligned_le16(&hdr->opcode); 2217 opcode = get_unaligned_le16(&hdr->opcode);
2255 index = get_unaligned_le16(&hdr->index); 2218 index = get_unaligned_le16(&hdr->index);
2256 len = get_unaligned_le16(&hdr->len); 2219 len = get_unaligned_le16(&hdr->len);
@@ -2260,6 +2223,8 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
2260 goto done; 2223 goto done;
2261 } 2224 }
2262 2225
2226 cp = buf + sizeof(*hdr);
2227
2263 switch (opcode) { 2228 switch (opcode) {
2264 case MGMT_OP_READ_VERSION: 2229 case MGMT_OP_READ_VERSION:
2265 err = read_version(sk); 2230 err = read_version(sk);
@@ -2271,98 +2236,94 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
2271 err = read_controller_info(sk, index); 2236 err = read_controller_info(sk, index);
2272 break; 2237 break;
2273 case MGMT_OP_SET_POWERED: 2238 case MGMT_OP_SET_POWERED:
2274 err = set_powered(sk, index, buf + sizeof(*hdr), len); 2239 err = set_powered(sk, index, cp, len);
2275 break; 2240 break;
2276 case MGMT_OP_SET_DISCOVERABLE: 2241 case MGMT_OP_SET_DISCOVERABLE:
2277 err = set_discoverable(sk, index, buf + sizeof(*hdr), len); 2242 err = set_discoverable(sk, index, cp, len);
2278 break; 2243 break;
2279 case MGMT_OP_SET_CONNECTABLE: 2244 case MGMT_OP_SET_CONNECTABLE:
2280 err = set_connectable(sk, index, buf + sizeof(*hdr), len); 2245 err = set_connectable(sk, index, cp, len);
2281 break; 2246 break;
2282 case MGMT_OP_SET_FAST_CONNECTABLE: 2247 case MGMT_OP_SET_FAST_CONNECTABLE:
2283 err = set_fast_connectable(sk, index, buf + sizeof(*hdr), 2248 err = set_fast_connectable(sk, index, cp, len);
2284 len);
2285 break; 2249 break;
2286 case MGMT_OP_SET_PAIRABLE: 2250 case MGMT_OP_SET_PAIRABLE:
2287 err = set_pairable(sk, index, buf + sizeof(*hdr), len); 2251 err = set_pairable(sk, index, cp, len);
2288 break; 2252 break;
2289 case MGMT_OP_ADD_UUID: 2253 case MGMT_OP_ADD_UUID:
2290 err = add_uuid(sk, index, buf + sizeof(*hdr), len); 2254 err = add_uuid(sk, index, cp, len);
2291 break; 2255 break;
2292 case MGMT_OP_REMOVE_UUID: 2256 case MGMT_OP_REMOVE_UUID:
2293 err = remove_uuid(sk, index, buf + sizeof(*hdr), len); 2257 err = remove_uuid(sk, index, cp, len);
2294 break; 2258 break;
2295 case MGMT_OP_SET_DEV_CLASS: 2259 case MGMT_OP_SET_DEV_CLASS:
2296 err = set_dev_class(sk, index, buf + sizeof(*hdr), len); 2260 err = set_dev_class(sk, index, cp, len);
2297 break; 2261 break;
2298 case MGMT_OP_LOAD_LINK_KEYS: 2262 case MGMT_OP_LOAD_LINK_KEYS:
2299 err = load_link_keys(sk, index, buf + sizeof(*hdr), len); 2263 err = load_link_keys(sk, index, cp, len);
2300 break; 2264 break;
2301 case MGMT_OP_REMOVE_KEYS: 2265 case MGMT_OP_REMOVE_KEYS:
2302 err = remove_keys(sk, index, buf + sizeof(*hdr), len); 2266 err = remove_keys(sk, index, cp, len);
2303 break; 2267 break;
2304 case MGMT_OP_DISCONNECT: 2268 case MGMT_OP_DISCONNECT:
2305 err = disconnect(sk, index, buf + sizeof(*hdr), len); 2269 err = disconnect(sk, index, cp, len);
2306 break; 2270 break;
2307 case MGMT_OP_GET_CONNECTIONS: 2271 case MGMT_OP_GET_CONNECTIONS:
2308 err = get_connections(sk, index); 2272 err = get_connections(sk, index);
2309 break; 2273 break;
2310 case MGMT_OP_PIN_CODE_REPLY: 2274 case MGMT_OP_PIN_CODE_REPLY:
2311 err = pin_code_reply(sk, index, buf + sizeof(*hdr), len); 2275 err = pin_code_reply(sk, index, cp, len);
2312 break; 2276 break;
2313 case MGMT_OP_PIN_CODE_NEG_REPLY: 2277 case MGMT_OP_PIN_CODE_NEG_REPLY:
2314 err = pin_code_neg_reply(sk, index, buf + sizeof(*hdr), len); 2278 err = pin_code_neg_reply(sk, index, cp, len);
2315 break; 2279 break;
2316 case MGMT_OP_SET_IO_CAPABILITY: 2280 case MGMT_OP_SET_IO_CAPABILITY:
2317 err = set_io_capability(sk, index, buf + sizeof(*hdr), len); 2281 err = set_io_capability(sk, index, cp, len);
2318 break; 2282 break;
2319 case MGMT_OP_PAIR_DEVICE: 2283 case MGMT_OP_PAIR_DEVICE:
2320 err = pair_device(sk, index, buf + sizeof(*hdr), len); 2284 err = pair_device(sk, index, cp, len);
2321 break; 2285 break;
2322 case MGMT_OP_CANCEL_PAIR_DEVICE: 2286 case MGMT_OP_CANCEL_PAIR_DEVICE:
2323 err = cancel_pair_device(sk, index, buf + sizeof(*hdr), len); 2287 err = cancel_pair_device(sk, index, buf + sizeof(*hdr), len);
2324 break; 2288 break;
2325 case MGMT_OP_USER_CONFIRM_REPLY: 2289 case MGMT_OP_USER_CONFIRM_REPLY:
2326 err = user_confirm_reply(sk, index, buf + sizeof(*hdr), len); 2290 err = user_confirm_reply(sk, index, cp, len);
2327 break; 2291 break;
2328 case MGMT_OP_USER_CONFIRM_NEG_REPLY: 2292 case MGMT_OP_USER_CONFIRM_NEG_REPLY:
2329 err = user_confirm_neg_reply(sk, index, buf + sizeof(*hdr), 2293 err = user_confirm_neg_reply(sk, index, cp, len);
2330 len);
2331 break; 2294 break;
2332 case MGMT_OP_USER_PASSKEY_REPLY: 2295 case MGMT_OP_USER_PASSKEY_REPLY:
2333 err = user_passkey_reply(sk, index, buf + sizeof(*hdr), len); 2296 err = user_passkey_reply(sk, index, cp, len);
2334 break; 2297 break;
2335 case MGMT_OP_USER_PASSKEY_NEG_REPLY: 2298 case MGMT_OP_USER_PASSKEY_NEG_REPLY:
2336 err = user_passkey_neg_reply(sk, index, buf + sizeof(*hdr), 2299 err = user_passkey_neg_reply(sk, index, cp, len);
2337 len);
2338 break; 2300 break;
2339 case MGMT_OP_SET_LOCAL_NAME: 2301 case MGMT_OP_SET_LOCAL_NAME:
2340 err = set_local_name(sk, index, buf + sizeof(*hdr), len); 2302 err = set_local_name(sk, index, cp, len);
2341 break; 2303 break;
2342 case MGMT_OP_READ_LOCAL_OOB_DATA: 2304 case MGMT_OP_READ_LOCAL_OOB_DATA:
2343 err = read_local_oob_data(sk, index); 2305 err = read_local_oob_data(sk, index);
2344 break; 2306 break;
2345 case MGMT_OP_ADD_REMOTE_OOB_DATA: 2307 case MGMT_OP_ADD_REMOTE_OOB_DATA:
2346 err = add_remote_oob_data(sk, index, buf + sizeof(*hdr), len); 2308 err = add_remote_oob_data(sk, index, cp, len);
2347 break; 2309 break;
2348 case MGMT_OP_REMOVE_REMOTE_OOB_DATA: 2310 case MGMT_OP_REMOVE_REMOTE_OOB_DATA:
2349 err = remove_remote_oob_data(sk, index, buf + sizeof(*hdr), 2311 err = remove_remote_oob_data(sk, index, cp, len);
2350 len);
2351 break; 2312 break;
2352 case MGMT_OP_START_DISCOVERY: 2313 case MGMT_OP_START_DISCOVERY:
2353 err = start_discovery(sk, index, buf + sizeof(*hdr), len); 2314 err = start_discovery(sk, index, cp, len);
2354 break; 2315 break;
2355 case MGMT_OP_STOP_DISCOVERY: 2316 case MGMT_OP_STOP_DISCOVERY:
2356 err = stop_discovery(sk, index); 2317 err = stop_discovery(sk, index);
2357 break; 2318 break;
2358 case MGMT_OP_CONFIRM_NAME: 2319 case MGMT_OP_CONFIRM_NAME:
2359 err = confirm_name(sk, index, buf + sizeof(*hdr), len); 2320 err = confirm_name(sk, index, cp, len);
2360 break; 2321 break;
2361 case MGMT_OP_BLOCK_DEVICE: 2322 case MGMT_OP_BLOCK_DEVICE:
2362 err = block_device(sk, index, buf + sizeof(*hdr), len); 2323 err = block_device(sk, index, cp, len);
2363 break; 2324 break;
2364 case MGMT_OP_UNBLOCK_DEVICE: 2325 case MGMT_OP_UNBLOCK_DEVICE:
2365 err = unblock_device(sk, index, buf + sizeof(*hdr), len); 2326 err = unblock_device(sk, index, cp, len);
2366 break; 2327 break;
2367 default: 2328 default:
2368 BT_DBG("Unknown op %u", opcode); 2329 BT_DBG("Unknown op %u", opcode);