Commit 650f726d authored by Vinicius Costa Gomes's avatar Vinicius Costa Gomes Committed by Johan Hedberg

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: default avatarVinicius Costa Gomes <vinicius.gomes@openbossa.org>
Acked-by: default avatarMarcel Holtmann <marcel@holtmann.org>
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
parent 37305cf6
...@@ -611,15 +611,13 @@ static int send_settings_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev) ...@@ -611,15 +611,13 @@ static int send_settings_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev)
return cmd_complete(sk, hdev->id, opcode, &settings, sizeof(settings)); return cmd_complete(sk, hdev->id, opcode, &settings, sizeof(settings));
} }
static int set_powered(struct sock *sk, u16 index, unsigned char *data, u16 len) static int set_powered(struct sock *sk, u16 index, void *data, u16 len)
{ {
struct mgmt_mode *cp; struct mgmt_mode *cp = data;
struct hci_dev *hdev; struct hci_dev *hdev;
struct pending_cmd *cmd; struct pending_cmd *cmd;
int err, up; int err, up;
cp = (void *) data;
BT_DBG("request for hci%u", index); BT_DBG("request for hci%u", index);
if (len != sizeof(*cp)) if (len != sizeof(*cp))
...@@ -664,17 +662,14 @@ static int set_powered(struct sock *sk, u16 index, unsigned char *data, u16 len) ...@@ -664,17 +662,14 @@ static int set_powered(struct sock *sk, u16 index, unsigned char *data, u16 len)
return err; return err;
} }
static int set_discoverable(struct sock *sk, u16 index, unsigned char *data, static int set_discoverable(struct sock *sk, u16 index, void *data, u16 len)
u16 len)
{ {
struct mgmt_cp_set_discoverable *cp; struct mgmt_cp_set_discoverable *cp = data;
struct hci_dev *hdev; struct hci_dev *hdev;
struct pending_cmd *cmd; struct pending_cmd *cmd;
u8 scan; u8 scan;
int err; int err;
cp = (void *) data;
BT_DBG("request for hci%u", index); BT_DBG("request for hci%u", index);
if (len != sizeof(*cp)) if (len != sizeof(*cp))
...@@ -734,17 +729,14 @@ static int set_discoverable(struct sock *sk, u16 index, unsigned char *data, ...@@ -734,17 +729,14 @@ static int set_discoverable(struct sock *sk, u16 index, unsigned char *data,
return err; return err;
} }
static int set_connectable(struct sock *sk, u16 index, unsigned char *data, static int set_connectable(struct sock *sk, u16 index, void *data, u16 len)
u16 len)
{ {
struct mgmt_mode *cp; struct mgmt_mode *cp = data;
struct hci_dev *hdev; struct hci_dev *hdev;
struct pending_cmd *cmd; struct pending_cmd *cmd;
u8 scan; u8 scan;
int err; int err;
cp = (void *) data;
BT_DBG("request for hci%u", index); BT_DBG("request for hci%u", index);
if (len != sizeof(*cp)) if (len != sizeof(*cp))
...@@ -827,16 +819,13 @@ static int mgmt_event(u16 event, struct hci_dev *hdev, void *data, ...@@ -827,16 +819,13 @@ static int mgmt_event(u16 event, struct hci_dev *hdev, void *data,
return 0; return 0;
} }
static int set_pairable(struct sock *sk, u16 index, unsigned char *data, static int set_pairable(struct sock *sk, u16 index, void *data, u16 len)
u16 len)
{ {
struct mgmt_mode *cp; struct mgmt_mode *cp = data;
struct hci_dev *hdev; struct hci_dev *hdev;
__le32 ev; __le32 ev;
int err; int err;
cp = (void *) data;
BT_DBG("request for hci%u", index); BT_DBG("request for hci%u", index);
if (len != sizeof(*cp)) if (len != sizeof(*cp))
...@@ -870,15 +859,13 @@ static int set_pairable(struct sock *sk, u16 index, unsigned char *data, ...@@ -870,15 +859,13 @@ static int set_pairable(struct sock *sk, u16 index, unsigned char *data,
return err; return err;
} }
static int add_uuid(struct sock *sk, u16 index, unsigned char *data, u16 len) static int add_uuid(struct sock *sk, u16 index, void *data, u16 len)
{ {
struct mgmt_cp_add_uuid *cp; struct mgmt_cp_add_uuid *cp = data;
struct hci_dev *hdev; struct hci_dev *hdev;
struct bt_uuid *uuid; struct bt_uuid *uuid;
int err; int err;
cp = (void *) data;
BT_DBG("request for hci%u", index); BT_DBG("request for hci%u", index);
if (len != sizeof(*cp)) if (len != sizeof(*cp))
...@@ -920,16 +907,14 @@ static int add_uuid(struct sock *sk, u16 index, unsigned char *data, u16 len) ...@@ -920,16 +907,14 @@ static int add_uuid(struct sock *sk, u16 index, unsigned char *data, u16 len)
return err; return err;
} }
static int remove_uuid(struct sock *sk, u16 index, unsigned char *data, u16 len) static int remove_uuid(struct sock *sk, u16 index, void *data, u16 len)
{ {
struct mgmt_cp_remove_uuid *cp = data;
struct list_head *p, *n; struct list_head *p, *n;
struct mgmt_cp_remove_uuid *cp;
struct hci_dev *hdev; struct hci_dev *hdev;
u8 bt_uuid_any[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; u8 bt_uuid_any[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int err, found; int err, found;
cp = (void *) data;
BT_DBG("request for hci%u", index); BT_DBG("request for hci%u", index);
if (len != sizeof(*cp)) if (len != sizeof(*cp))
...@@ -983,15 +968,12 @@ static int remove_uuid(struct sock *sk, u16 index, unsigned char *data, u16 len) ...@@ -983,15 +968,12 @@ static int remove_uuid(struct sock *sk, u16 index, unsigned char *data, u16 len)
return err; return err;
} }
static int set_dev_class(struct sock *sk, u16 index, unsigned char *data, static int set_dev_class(struct sock *sk, u16 index, void *data, u16 len)
u16 len)
{ {
struct hci_dev *hdev; struct hci_dev *hdev;
struct mgmt_cp_set_dev_class *cp; struct mgmt_cp_set_dev_class *cp = data;
int err; int err;
cp = (void *) data;
BT_DBG("request for hci%u", index); BT_DBG("request for hci%u", index);
if (len != sizeof(*cp)) if (len != sizeof(*cp))
...@@ -1026,16 +1008,13 @@ static int set_dev_class(struct sock *sk, u16 index, unsigned char *data, ...@@ -1026,16 +1008,13 @@ static int set_dev_class(struct sock *sk, u16 index, unsigned char *data,
return err; return err;
} }
static int load_link_keys(struct sock *sk, u16 index, unsigned char *data, static int load_link_keys(struct sock *sk, u16 index, void *data, u16 len)
u16 len)
{ {
struct hci_dev *hdev; struct hci_dev *hdev;
struct mgmt_cp_load_link_keys *cp; struct mgmt_cp_load_link_keys *cp = data;
u16 key_count, expected_len; u16 key_count, expected_len;
int i; int i;
cp = (void *) data;
if (len < sizeof(*cp)) if (len < sizeof(*cp))
return cmd_status(sk, index, MGMT_OP_LOAD_LINK_KEYS, return cmd_status(sk, index, MGMT_OP_LOAD_LINK_KEYS,
MGMT_STATUS_INVALID_PARAMS); MGMT_STATUS_INVALID_PARAMS);
...@@ -1085,19 +1064,16 @@ static int load_link_keys(struct sock *sk, u16 index, unsigned char *data, ...@@ -1085,19 +1064,16 @@ static int load_link_keys(struct sock *sk, u16 index, unsigned char *data,
return 0; return 0;
} }
static int remove_keys(struct sock *sk, u16 index, unsigned char *data, static int remove_keys(struct sock *sk, u16 index, void *data, u16 len)
u16 len)
{ {
struct hci_dev *hdev; struct hci_dev *hdev;
struct mgmt_cp_remove_keys *cp; struct mgmt_cp_remove_keys *cp = data;
struct mgmt_rp_remove_keys rp; struct mgmt_rp_remove_keys rp;
struct hci_cp_disconnect dc; struct hci_cp_disconnect dc;
struct pending_cmd *cmd; struct pending_cmd *cmd;
struct hci_conn *conn; struct hci_conn *conn;
int err; int err;
cp = (void *) data;
if (len != sizeof(*cp)) if (len != sizeof(*cp))
return cmd_status(sk, index, MGMT_OP_REMOVE_KEYS, return cmd_status(sk, index, MGMT_OP_REMOVE_KEYS,
MGMT_STATUS_INVALID_PARAMS); MGMT_STATUS_INVALID_PARAMS);
...@@ -1154,10 +1130,10 @@ static int remove_keys(struct sock *sk, u16 index, unsigned char *data, ...@@ -1154,10 +1130,10 @@ static int remove_keys(struct sock *sk, u16 index, unsigned char *data,
return err; return err;
} }
static int disconnect(struct sock *sk, u16 index, unsigned char *data, u16 len) static int disconnect(struct sock *sk, u16 index, void *data, u16 len)
{ {
struct hci_dev *hdev; struct hci_dev *hdev;
struct mgmt_cp_disconnect *cp; struct mgmt_cp_disconnect *cp = data;
struct hci_cp_disconnect dc; struct hci_cp_disconnect dc;
struct pending_cmd *cmd; struct pending_cmd *cmd;
struct hci_conn *conn; struct hci_conn *conn;
...@@ -1165,8 +1141,6 @@ static int disconnect(struct sock *sk, u16 index, unsigned char *data, u16 len) ...@@ -1165,8 +1141,6 @@ static int disconnect(struct sock *sk, u16 index, unsigned char *data, u16 len)
BT_DBG(""); BT_DBG("");
cp = (void *) data;
if (len != sizeof(*cp)) if (len != sizeof(*cp))
return cmd_status(sk, index, MGMT_OP_DISCONNECT, return cmd_status(sk, index, MGMT_OP_DISCONNECT,
MGMT_STATUS_INVALID_PARAMS); MGMT_STATUS_INVALID_PARAMS);
...@@ -1314,12 +1288,11 @@ static int send_pin_code_neg_reply(struct sock *sk, u16 index, ...@@ -1314,12 +1288,11 @@ static int send_pin_code_neg_reply(struct sock *sk, u16 index,
return err; return err;
} }
static int pin_code_reply(struct sock *sk, u16 index, unsigned char *data, static int pin_code_reply(struct sock *sk, u16 index, void *data, u16 len)
u16 len)
{ {
struct hci_dev *hdev; struct hci_dev *hdev;
struct hci_conn *conn; struct hci_conn *conn;
struct mgmt_cp_pin_code_reply *cp; struct mgmt_cp_pin_code_reply *cp = data;
struct mgmt_cp_pin_code_neg_reply ncp; struct mgmt_cp_pin_code_neg_reply ncp;
struct hci_cp_pin_code_reply reply; struct hci_cp_pin_code_reply reply;
struct pending_cmd *cmd; struct pending_cmd *cmd;
...@@ -1327,8 +1300,6 @@ static int pin_code_reply(struct sock *sk, u16 index, unsigned char *data, ...@@ -1327,8 +1300,6 @@ static int pin_code_reply(struct sock *sk, u16 index, unsigned char *data,
BT_DBG(""); BT_DBG("");
cp = (void *) data;
if (len != sizeof(*cp)) if (len != sizeof(*cp))
return cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY, return cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY,
MGMT_STATUS_INVALID_PARAMS); MGMT_STATUS_INVALID_PARAMS);
...@@ -1366,7 +1337,8 @@ static int pin_code_reply(struct sock *sk, u16 index, unsigned char *data, ...@@ -1366,7 +1337,8 @@ static int pin_code_reply(struct sock *sk, u16 index, unsigned char *data,
goto failed; goto failed;
} }
cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_REPLY, hdev, data, len); cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_REPLY, hdev, data,
len);
if (!cmd) { if (!cmd) {
err = -ENOMEM; err = -ENOMEM;
goto failed; goto failed;
...@@ -1387,17 +1359,14 @@ static int pin_code_reply(struct sock *sk, u16 index, unsigned char *data, ...@@ -1387,17 +1359,14 @@ static int pin_code_reply(struct sock *sk, u16 index, unsigned char *data,
return err; return err;
} }
static int pin_code_neg_reply(struct sock *sk, u16 index, unsigned char *data, static int pin_code_neg_reply(struct sock *sk, u16 index, void *data, u16 len)
u16 len)
{ {
struct hci_dev *hdev; struct hci_dev *hdev;
struct mgmt_cp_pin_code_neg_reply *cp; struct mgmt_cp_pin_code_neg_reply *cp = data;
int err; int err;
BT_DBG(""); BT_DBG("");
cp = (void *) data;
if (len != sizeof(*cp)) if (len != sizeof(*cp))
return cmd_status(sk, index, MGMT_OP_PIN_CODE_NEG_REPLY, return cmd_status(sk, index, MGMT_OP_PIN_CODE_NEG_REPLY,
MGMT_STATUS_INVALID_PARAMS); MGMT_STATUS_INVALID_PARAMS);
...@@ -1424,16 +1393,13 @@ static int pin_code_neg_reply(struct sock *sk, u16 index, unsigned char *data, ...@@ -1424,16 +1393,13 @@ static int pin_code_neg_reply(struct sock *sk, u16 index, unsigned char *data,
return err; return err;
} }
static int set_io_capability(struct sock *sk, u16 index, unsigned char *data, static int set_io_capability(struct sock *sk, u16 index, void *data, u16 len)
u16 len)
{ {
struct hci_dev *hdev; struct hci_dev *hdev;
struct mgmt_cp_set_io_capability *cp; struct mgmt_cp_set_io_capability *cp = data;
BT_DBG(""); BT_DBG("");
cp = (void *) data;
if (len != sizeof(*cp)) if (len != sizeof(*cp))
return cmd_status(sk, index, MGMT_OP_SET_IO_CAPABILITY, return cmd_status(sk, index, MGMT_OP_SET_IO_CAPABILITY,
MGMT_STATUS_INVALID_PARAMS); MGMT_STATUS_INVALID_PARAMS);
...@@ -1508,10 +1474,10 @@ static void pairing_complete_cb(struct hci_conn *conn, u8 status) ...@@ -1508,10 +1474,10 @@ static void pairing_complete_cb(struct hci_conn *conn, u8 status)
pairing_complete(cmd, status); pairing_complete(cmd, status);
} }
static int pair_device(struct sock *sk, u16 index, unsigned char *data, u16 len) static int pair_device(struct sock *sk, u16 index, void *data, u16 len)
{ {
struct hci_dev *hdev; struct hci_dev *hdev;
struct mgmt_cp_pair_device *cp; struct mgmt_cp_pair_device *cp = data;
struct mgmt_rp_pair_device rp; struct mgmt_rp_pair_device rp;
struct pending_cmd *cmd; struct pending_cmd *cmd;
u8 sec_level, auth_type; u8 sec_level, auth_type;
...@@ -1520,8 +1486,6 @@ static int pair_device(struct sock *sk, u16 index, unsigned char *data, u16 len) ...@@ -1520,8 +1486,6 @@ static int pair_device(struct sock *sk, u16 index, unsigned char *data, u16 len)
BT_DBG(""); BT_DBG("");
cp = (void *) data;
if (len != sizeof(*cp)) if (len != sizeof(*cp))
return cmd_status(sk, index, MGMT_OP_PAIR_DEVICE, return cmd_status(sk, index, MGMT_OP_PAIR_DEVICE,
MGMT_STATUS_INVALID_PARAMS); MGMT_STATUS_INVALID_PARAMS);
...@@ -1721,7 +1685,7 @@ static int user_pairing_resp(struct sock *sk, u16 index, bdaddr_t *bdaddr, ...@@ -1721,7 +1685,7 @@ static int user_pairing_resp(struct sock *sk, u16 index, bdaddr_t *bdaddr,
static int user_confirm_reply(struct sock *sk, u16 index, void *data, u16 len) static int user_confirm_reply(struct sock *sk, u16 index, void *data, u16 len)
{ {
struct mgmt_cp_user_confirm_reply *cp = (void *) data; struct mgmt_cp_user_confirm_reply *cp = data;
BT_DBG(""); BT_DBG("");
...@@ -1752,7 +1716,7 @@ static int user_confirm_neg_reply(struct sock *sk, u16 index, void *data, ...@@ -1752,7 +1716,7 @@ static int user_confirm_neg_reply(struct sock *sk, u16 index, void *data,
static int user_passkey_reply(struct sock *sk, u16 index, void *data, u16 len) static int user_passkey_reply(struct sock *sk, u16 index, void *data, u16 len)
{ {
struct mgmt_cp_user_passkey_reply *cp = (void *) data; struct mgmt_cp_user_passkey_reply *cp = data;
BT_DBG(""); BT_DBG("");
...@@ -1768,7 +1732,7 @@ static int user_passkey_reply(struct sock *sk, u16 index, void *data, u16 len) ...@@ -1768,7 +1732,7 @@ static int user_passkey_reply(struct sock *sk, u16 index, void *data, u16 len)
static int user_passkey_neg_reply(struct sock *sk, u16 index, void *data, static int user_passkey_neg_reply(struct sock *sk, u16 index, void *data,
u16 len) u16 len)
{ {
struct mgmt_cp_user_passkey_neg_reply *cp = (void *) data; struct mgmt_cp_user_passkey_neg_reply *cp = data;
BT_DBG(""); BT_DBG("");
...@@ -1781,10 +1745,10 @@ static int user_passkey_neg_reply(struct sock *sk, u16 index, void *data, ...@@ -1781,10 +1745,10 @@ static int user_passkey_neg_reply(struct sock *sk, u16 index, void *data,
HCI_OP_USER_PASSKEY_NEG_REPLY, 0); HCI_OP_USER_PASSKEY_NEG_REPLY, 0);
} }
static int set_local_name(struct sock *sk, u16 index, unsigned char *data, static int set_local_name(struct sock *sk, u16 index, void *data,
u16 len) u16 len)
{ {
struct mgmt_cp_set_local_name *mgmt_cp = (void *) data; struct mgmt_cp_set_local_name *mgmt_cp = data;
struct hci_cp_write_local_name hci_cp; struct hci_cp_write_local_name hci_cp;
struct hci_dev *hdev; struct hci_dev *hdev;
struct pending_cmd *cmd; struct pending_cmd *cmd;
...@@ -1803,7 +1767,8 @@ static int set_local_name(struct sock *sk, u16 index, unsigned char *data, ...@@ -1803,7 +1767,8 @@ static int set_local_name(struct sock *sk, u16 index, unsigned char *data,
hci_dev_lock(hdev); hci_dev_lock(hdev);
cmd = mgmt_pending_add(sk, MGMT_OP_SET_LOCAL_NAME, hdev, data, len); cmd = mgmt_pending_add(sk, MGMT_OP_SET_LOCAL_NAME, hdev, data,
len);
if (!cmd) { if (!cmd) {
err = -ENOMEM; err = -ENOMEM;
goto failed; goto failed;
...@@ -1872,11 +1837,11 @@ static int read_local_oob_data(struct sock *sk, u16 index) ...@@ -1872,11 +1837,11 @@ static int read_local_oob_data(struct sock *sk, u16 index)
return err; return err;
} }
static int add_remote_oob_data(struct sock *sk, u16 index, unsigned char *data, static int add_remote_oob_data(struct sock *sk, u16 index, void *data,
u16 len) u16 len)
{ {
struct hci_dev *hdev; struct hci_dev *hdev;
struct mgmt_cp_add_remote_oob_data *cp = (void *) data; struct mgmt_cp_add_remote_oob_data *cp = data;
int err; int err;
BT_DBG("hci%u ", index); BT_DBG("hci%u ", index);
...@@ -1908,10 +1873,10 @@ static int add_remote_oob_data(struct sock *sk, u16 index, unsigned char *data, ...@@ -1908,10 +1873,10 @@ static int add_remote_oob_data(struct sock *sk, u16 index, unsigned char *data,
} }
static int remove_remote_oob_data(struct sock *sk, u16 index, static int remove_remote_oob_data(struct sock *sk, u16 index,
unsigned char *data, u16 len) void *data, u16 len)
{ {
struct hci_dev *hdev; struct hci_dev *hdev;
struct mgmt_cp_remove_remote_oob_data *cp = (void *) data; struct mgmt_cp_remove_remote_oob_data *cp = data;
int err; int err;
BT_DBG("hci%u ", index); BT_DBG("hci%u ", index);
...@@ -1942,9 +1907,9 @@ static int remove_remote_oob_data(struct sock *sk, u16 index, ...@@ -1942,9 +1907,9 @@ static int remove_remote_oob_data(struct sock *sk, u16 index,
} }
static int start_discovery(struct sock *sk, u16 index, static int start_discovery(struct sock *sk, u16 index,
unsigned char *data, u16 len) void *data, u16 len)
{ {
struct mgmt_cp_start_discovery *cp = (void *) data; struct mgmt_cp_start_discovery *cp = data;
struct pending_cmd *cmd; struct pending_cmd *cmd;
struct hci_dev *hdev; struct hci_dev *hdev;
int err; int err;
...@@ -2054,10 +2019,9 @@ static int stop_discovery(struct sock *sk, u16 index) ...@@ -2054,10 +2019,9 @@ static int stop_discovery(struct sock *sk, u16 index)
return err; return err;
} }
static int confirm_name(struct sock *sk, u16 index, unsigned char *data, static int confirm_name(struct sock *sk, u16 index, void *data, u16 len)
u16 len)
{ {
struct mgmt_cp_confirm_name *cp = (void *) data; struct mgmt_cp_confirm_name *cp = data;
struct inquiry_entry *e; struct inquiry_entry *e;
struct hci_dev *hdev; struct hci_dev *hdev;
int err; int err;
...@@ -2104,11 +2068,10 @@ static int confirm_name(struct sock *sk, u16 index, unsigned char *data, ...@@ -2104,11 +2068,10 @@ static int confirm_name(struct sock *sk, u16 index, unsigned char *data,
return err; return err;
} }
static int block_device(struct sock *sk, u16 index, unsigned char *data, static int block_device(struct sock *sk, u16 index, void *data, u16 len)
u16 len)
{ {
struct hci_dev *hdev; struct hci_dev *hdev;
struct mgmt_cp_block_device *cp = (void *) data; struct mgmt_cp_block_device *cp = data;
int err; int err;
BT_DBG("hci%u", index); BT_DBG("hci%u", index);
...@@ -2138,11 +2101,10 @@ static int block_device(struct sock *sk, u16 index, unsigned char *data, ...@@ -2138,11 +2101,10 @@ static int block_device(struct sock *sk, u16 index, unsigned char *data,
return err; return err;
} }
static int unblock_device(struct sock *sk, u16 index, unsigned char *data, static int unblock_device(struct sock *sk, u16 index, void *data, u16 len)
u16 len)
{ {
struct hci_dev *hdev; struct hci_dev *hdev;
struct mgmt_cp_unblock_device *cp = (void *) data; struct mgmt_cp_unblock_device *cp = data;
int err; int err;
BT_DBG("hci%u", index); BT_DBG("hci%u", index);
...@@ -2174,10 +2136,10 @@ static int unblock_device(struct sock *sk, u16 index, unsigned char *data, ...@@ -2174,10 +2136,10 @@ static int unblock_device(struct sock *sk, u16 index, unsigned char *data,
} }
static int set_fast_connectable(struct sock *sk, u16 index, static int set_fast_connectable(struct sock *sk, u16 index,
unsigned char *data, u16 len) void *data, u16 len)
{ {
struct hci_dev *hdev; struct hci_dev *hdev;
struct mgmt_mode *cp = (void *) data; struct mgmt_mode *cp = data;
struct hci_cp_write_page_scan_activity acp; struct hci_cp_write_page_scan_activity acp;
u8 type; u8 type;
int err; int err;
...@@ -2231,7 +2193,8 @@ static int set_fast_connectable(struct sock *sk, u16 index, ...@@ -2231,7 +2193,8 @@ static int set_fast_connectable(struct sock *sk, u16 index,
int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen) int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
{ {
unsigned char *buf; void *buf;
u8 *cp;
struct mgmt_hdr *hdr; struct mgmt_hdr *hdr;
u16 opcode, index, len; u16 opcode, index, len;
int err; int err;
...@@ -2250,7 +2213,7 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen) ...@@ -2250,7 +2213,7 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
goto done; goto done;
} }
hdr = (struct mgmt_hdr *) buf; hdr = buf;
opcode = get_unaligned_le16(&hdr->opcode); opcode = get_unaligned_le16(&hdr->opcode);
index = get_unaligned_le16(&hdr->index); index = get_unaligned_le16(&hdr->index);
len = get_unaligned_le16(&hdr->len); len = get_unaligned_le16(&hdr->len);
...@@ -2260,6 +2223,8 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen) ...@@ -2260,6 +2223,8 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
goto done; goto done;
} }
cp = buf + sizeof(*hdr);
switch (opcode) { switch (opcode) {
case MGMT_OP_READ_VERSION: case MGMT_OP_READ_VERSION:
err = read_version(sk); err = read_version(sk);
...@@ -2271,98 +2236,94 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen) ...@@ -2271,98 +2236,94 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
err = read_controller_info(sk, index); err = read_controller_info(sk, index);
break; break;
case MGMT_OP_SET_POWERED: case MGMT_OP_SET_POWERED:
err = set_powered(sk, index, buf + sizeof(*hdr), len); err = set_powered(sk, index, cp, len);
break; break;
case MGMT_OP_SET_DISCOVERABLE: case MGMT_OP_SET_DISCOVERABLE:
err = set_discoverable(sk, index, buf + sizeof(*hdr), len); err = set_discoverable(sk, index, cp, len);
break; break;
case MGMT_OP_SET_CONNECTABLE: case MGMT_OP_SET_CONNECTABLE:
err = set_connectable(sk, index, buf + sizeof(*hdr), len); err = set_connectable(sk, index, cp, len);
break; break;
case MGMT_OP_SET_FAST_CONNECTABLE: case MGMT_OP_SET_FAST_CONNECTABLE:
err = set_fast_connectable(sk, index, buf + sizeof(*hdr), err = set_fast_connectable(sk, index, cp, len);
len);
break; break;
case MGMT_OP_SET_PAIRABLE: case MGMT_OP_SET_PAIRABLE:
err = set_pairable(sk, index, buf + sizeof(*hdr), len); err = set_pairable(sk, index, cp, len);
break; break;
case MGMT_OP_ADD_UUID: case MGMT_OP_ADD_UUID:
err = add_uuid(sk, index, buf + sizeof(*hdr), len); err = add_uuid(sk, index, cp, len);
break; break;
case MGMT_OP_REMOVE_UUID: case MGMT_OP_REMOVE_UUID:
err = remove_uuid(sk, index, buf + sizeof(*hdr), len); err = remove_uuid(sk, index, cp, len);
break; break;
case MGMT_OP_SET_DEV_CLASS: case MGMT_OP_SET_DEV_CLASS:
err = set_dev_class(sk, index, buf + sizeof(*hdr), len); err = set_dev_class(sk, index, cp, len);
break; break;
case MGMT_OP_LOAD_LINK_KEYS: case MGMT_OP_LOAD_LINK_KEYS:
err = load_link_keys(sk, index, buf + sizeof(*hdr), len); err = load_link_keys(sk, index, cp, len);
break; break;
case MGMT_OP_REMOVE_KEYS: case MGMT_OP_REMOVE_KEYS:
err = remove_keys(sk, index, buf + sizeof(*hdr), len); err = remove_keys(sk, index, cp, len);
break; break;
case MGMT_OP_DISCONNECT: case MGMT_OP_DISCONNECT:
err = disconnect(sk, index, buf + sizeof(*hdr), len); err = disconnect(sk, index, cp, len);
break; break;
case MGMT_OP_GET_CONNECTIONS: case MGMT_OP_GET_CONNECTIONS:
err = get_connections(sk, index); err = get_connections(sk, index);
break; break;
case MGMT_OP_PIN_CODE_REPLY: case MGMT_OP_PIN_CODE_REPLY:
err = pin_code_reply(sk, index, buf + sizeof(*hdr), len); err = pin_code_reply(sk, index, cp, len);
break; break;
case MGMT_OP_PIN_CODE_NEG_REPLY: case MGMT_OP_PIN_CODE_NEG_REPLY:
err = pin_code_neg_reply(sk, index, buf + sizeof(*hdr), len); err = pin_code_neg_reply(sk, index, cp, len);
break; break;
case MGMT_OP_SET_IO_CAPABILITY: case MGMT_OP_SET_IO_CAPABILITY:
err = set_io_capability(sk, index, buf + sizeof(*hdr), len); err = set_io_capability(sk, index, cp, len);
break; break;
case MGMT_OP_PAIR_DEVICE: case MGMT_OP_PAIR_DEVICE:
err = pair_device(sk, index, buf + sizeof(*hdr), len); err = pair_device(sk, index, cp, len);
break; break;
case MGMT_OP_CANCEL_PAIR_DEVICE: case MGMT_OP_CANCEL_PAIR_DEVICE:
err = cancel_pair_device(sk, index, buf + sizeof(*hdr), len); err = cancel_pair_device(sk, index, buf + sizeof(*hdr), len);
break; break;
case MGMT_OP_USER_CONFIRM_REPLY: case MGMT_OP_USER_CONFIRM_REPLY:
err = user_confirm_reply(sk, index, buf + sizeof(*hdr), len); err = user_confirm_reply(sk, index, cp, len);
break; break;
case MGMT_OP_USER_CONFIRM_NEG_REPLY: case MGMT_OP_USER_CONFIRM_NEG_REPLY:
err = user_confirm_neg_reply(sk, index, buf + sizeof(*hdr), err = user_confirm_neg_reply(sk, index, cp, len);
len);
break; break;
case MGMT_OP_USER_PASSKEY_REPLY: case MGMT_OP_USER_PASSKEY_REPLY:
err = user_passkey_reply(sk, index, buf + sizeof(*hdr), len); err = user_passkey_reply(sk, index, cp, len);
break; break;
case MGMT_OP_USER_PASSKEY_NEG_REPLY: case MGMT_OP_USER_PASSKEY_NEG_REPLY:
err = user_passkey_neg_reply(sk, index, buf + sizeof(*hdr), err = user_passkey_neg_reply(sk, index, cp, len);
len);
break; break;
case MGMT_OP_SET_LOCAL_NAME: case MGMT_OP_SET_LOCAL_NAME:
err = set_local_name(sk, index, buf + sizeof(*hdr), len); err = set_local_name(sk, index, cp, len);
break; break;
case MGMT_OP_READ_LOCAL_OOB_DATA: case MGMT_OP_READ_LOCAL_OOB_DATA:
err = read_local_oob_data(sk, index); err = read_local_oob_data(sk, index);
break; break;
case MGMT_OP_ADD_REMOTE_OOB_DATA: case MGMT_OP_ADD_REMOTE_OOB_DATA:
err = add_remote_oob_data(sk, index, buf + sizeof(*hdr), len); err = add_remote_oob_data(sk, index, cp, len);
break; break;
case MGMT_OP_REMOVE_REMOTE_OOB_DATA: case MGMT_OP_REMOVE_REMOTE_OOB_DATA:
err = remove_remote_oob_data(sk, index, buf + sizeof(*hdr), err = remove_remote_oob_data(sk, index, cp, len);
len);
break; break;
case MGMT_OP_START_DISCOVERY: case MGMT_OP_START_DISCOVERY:
err = start_discovery(sk, index, buf + sizeof(*hdr), len); err = start_discovery(sk, index, cp, len);
break; break;
case MGMT_OP_STOP_DISCOVERY: case MGMT_OP_STOP_DISCOVERY:
err = stop_discovery(sk, index); err = stop_discovery(sk, index);
break; break;
case MGMT_OP_CONFIRM_NAME: case MGMT_OP_CONFIRM_NAME:
err = confirm_name(sk, index, buf + sizeof(*hdr), len); err = confirm_name(sk, index, cp, len);
break; break;
case MGMT_OP_BLOCK_DEVICE: case MGMT_OP_BLOCK_DEVICE:
err = block_device(sk, index, buf + sizeof(*hdr), len); err = block_device(sk, index, cp, len);
break; break;
case MGMT_OP_UNBLOCK_DEVICE: case MGMT_OP_UNBLOCK_DEVICE:
err = unblock_device(sk, index, buf + sizeof(*hdr), len); err = unblock_device(sk, index, cp, len);
break; break;
default: default:
BT_DBG("Unknown op %u", opcode); BT_DBG("Unknown op %u", opcode);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment