Commit 366a0336 authored by Johan Hedberg's avatar Johan Hedberg Committed by Gustavo F. Padovan

Bluetooth: Make pending_add return a pointer to the added entry

This makes it more convenient to do manipulations on the entry (needed
by later commits).
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@nokia.com>
Signed-off-by: default avatarGustavo F. Padovan <padovan@profusion.mobi>
parent b67afe7f
...@@ -219,14 +219,14 @@ static void mgmt_pending_free(struct pending_cmd *cmd) ...@@ -219,14 +219,14 @@ static void mgmt_pending_free(struct pending_cmd *cmd)
kfree(cmd); kfree(cmd);
} }
static int mgmt_pending_add(struct sock *sk, u16 opcode, int index, static struct pending_cmd *mgmt_pending_add(struct sock *sk, u16 opcode,
void *data, u16 len) u16 index, void *data, u16 len)
{ {
struct pending_cmd *cmd; struct pending_cmd *cmd;
cmd = kmalloc(sizeof(*cmd), GFP_ATOMIC); cmd = kmalloc(sizeof(*cmd), GFP_ATOMIC);
if (!cmd) if (!cmd)
return -ENOMEM; return NULL;
cmd->opcode = opcode; cmd->opcode = opcode;
cmd->index = index; cmd->index = index;
...@@ -234,7 +234,7 @@ static int mgmt_pending_add(struct sock *sk, u16 opcode, int index, ...@@ -234,7 +234,7 @@ static int mgmt_pending_add(struct sock *sk, u16 opcode, int index,
cmd->cmd = kmalloc(len, GFP_ATOMIC); cmd->cmd = kmalloc(len, GFP_ATOMIC);
if (!cmd->cmd) { if (!cmd->cmd) {
kfree(cmd); kfree(cmd);
return -ENOMEM; return NULL;
} }
memcpy(cmd->cmd, data, len); memcpy(cmd->cmd, data, len);
...@@ -244,7 +244,7 @@ static int mgmt_pending_add(struct sock *sk, u16 opcode, int index, ...@@ -244,7 +244,7 @@ static int mgmt_pending_add(struct sock *sk, u16 opcode, int index,
list_add(&cmd->list, &cmd_list); list_add(&cmd->list, &cmd_list);
return 0; return cmd;
} }
static void mgmt_pending_foreach(u16 opcode, int index, static void mgmt_pending_foreach(u16 opcode, int index,
...@@ -305,8 +305,9 @@ static int set_powered(struct sock *sk, unsigned char *data, u16 len) ...@@ -305,8 +305,9 @@ static int set_powered(struct sock *sk, unsigned char *data, u16 len)
{ {
struct mgmt_mode *cp; struct mgmt_mode *cp;
struct hci_dev *hdev; struct hci_dev *hdev;
struct pending_cmd *cmd;
u16 dev_id; u16 dev_id;
int ret, up; int err, up;
cp = (void *) data; cp = (void *) data;
dev_id = get_unaligned_le16(&cp->index); dev_id = get_unaligned_le16(&cp->index);
...@@ -321,36 +322,39 @@ static int set_powered(struct sock *sk, unsigned char *data, u16 len) ...@@ -321,36 +322,39 @@ static int set_powered(struct sock *sk, unsigned char *data, u16 len)
up = test_bit(HCI_UP, &hdev->flags); up = test_bit(HCI_UP, &hdev->flags);
if ((cp->val && up) || (!cp->val && !up)) { if ((cp->val && up) || (!cp->val && !up)) {
ret = cmd_status(sk, MGMT_OP_SET_POWERED, EALREADY); err = cmd_status(sk, MGMT_OP_SET_POWERED, EALREADY);
goto failed; goto failed;
} }
if (mgmt_pending_find(MGMT_OP_SET_POWERED, dev_id)) { if (mgmt_pending_find(MGMT_OP_SET_POWERED, dev_id)) {
ret = cmd_status(sk, MGMT_OP_SET_POWERED, EBUSY); err = cmd_status(sk, MGMT_OP_SET_POWERED, EBUSY);
goto failed; goto failed;
} }
ret = mgmt_pending_add(sk, MGMT_OP_SET_POWERED, dev_id, data, len); cmd = mgmt_pending_add(sk, MGMT_OP_SET_POWERED, dev_id, data, len);
if (ret < 0) if (!cmd) {
err = -ENOMEM;
goto failed; goto failed;
}
if (cp->val) if (cp->val)
queue_work(hdev->workqueue, &hdev->power_on); queue_work(hdev->workqueue, &hdev->power_on);
else else
queue_work(hdev->workqueue, &hdev->power_off); queue_work(hdev->workqueue, &hdev->power_off);
ret = 0; err = 0;
failed: failed:
hci_dev_unlock_bh(hdev); hci_dev_unlock_bh(hdev);
hci_dev_put(hdev); hci_dev_put(hdev);
return ret; return err;
} }
static int set_discoverable(struct sock *sk, unsigned char *data, u16 len) static int set_discoverable(struct sock *sk, unsigned char *data, u16 len)
{ {
struct mgmt_mode *cp; struct mgmt_mode *cp;
struct hci_dev *hdev; struct hci_dev *hdev;
struct pending_cmd *cmd;
u16 dev_id; u16 dev_id;
u8 scan; u8 scan;
int err; int err;
...@@ -383,9 +387,11 @@ static int set_discoverable(struct sock *sk, unsigned char *data, u16 len) ...@@ -383,9 +387,11 @@ static int set_discoverable(struct sock *sk, unsigned char *data, u16 len)
goto failed; goto failed;
} }
err = mgmt_pending_add(sk, MGMT_OP_SET_DISCOVERABLE, dev_id, data, len); cmd = mgmt_pending_add(sk, MGMT_OP_SET_DISCOVERABLE, dev_id, data, len);
if (err < 0) if (!cmd) {
err = -ENOMEM;
goto failed; goto failed;
}
scan = SCAN_PAGE; scan = SCAN_PAGE;
...@@ -407,6 +413,7 @@ static int set_connectable(struct sock *sk, unsigned char *data, u16 len) ...@@ -407,6 +413,7 @@ static int set_connectable(struct sock *sk, unsigned char *data, u16 len)
{ {
struct mgmt_mode *cp; struct mgmt_mode *cp;
struct hci_dev *hdev; struct hci_dev *hdev;
struct pending_cmd *cmd;
u16 dev_id; u16 dev_id;
u8 scan; u8 scan;
int err; int err;
...@@ -438,9 +445,11 @@ static int set_connectable(struct sock *sk, unsigned char *data, u16 len) ...@@ -438,9 +445,11 @@ static int set_connectable(struct sock *sk, unsigned char *data, u16 len)
goto failed; goto failed;
} }
err = mgmt_pending_add(sk, MGMT_OP_SET_CONNECTABLE, dev_id, data, len); cmd = mgmt_pending_add(sk, MGMT_OP_SET_CONNECTABLE, dev_id, data, len);
if (err < 0) if (!cmd) {
err = -ENOMEM;
goto failed; goto failed;
}
if (cp->val) if (cp->val)
scan = SCAN_PAGE; scan = SCAN_PAGE;
...@@ -828,6 +837,7 @@ static int disconnect(struct sock *sk, unsigned char *data, u16 len) ...@@ -828,6 +837,7 @@ static int disconnect(struct sock *sk, unsigned char *data, u16 len)
struct hci_dev *hdev; struct hci_dev *hdev;
struct mgmt_cp_disconnect *cp; struct mgmt_cp_disconnect *cp;
struct hci_cp_disconnect dc; struct hci_cp_disconnect dc;
struct pending_cmd *cmd;
struct hci_conn *conn; struct hci_conn *conn;
u16 dev_id; u16 dev_id;
int err; int err;
...@@ -859,9 +869,11 @@ static int disconnect(struct sock *sk, unsigned char *data, u16 len) ...@@ -859,9 +869,11 @@ static int disconnect(struct sock *sk, unsigned char *data, u16 len)
goto failed; goto failed;
} }
err = mgmt_pending_add(sk, MGMT_OP_DISCONNECT, dev_id, data, len); cmd = mgmt_pending_add(sk, MGMT_OP_DISCONNECT, dev_id, data, len);
if (err < 0) if (!cmd) {
err = -ENOMEM;
goto failed; goto failed;
}
put_unaligned_le16(conn->handle, &dc.handle); put_unaligned_le16(conn->handle, &dc.handle);
dc.reason = 0x13; /* Remote User Terminated Connection */ dc.reason = 0x13; /* Remote User Terminated Connection */
...@@ -938,6 +950,7 @@ static int pin_code_reply(struct sock *sk, unsigned char *data, u16 len) ...@@ -938,6 +950,7 @@ static int pin_code_reply(struct sock *sk, unsigned char *data, u16 len)
struct hci_dev *hdev; struct hci_dev *hdev;
struct mgmt_cp_pin_code_reply *cp; struct mgmt_cp_pin_code_reply *cp;
struct hci_cp_pin_code_reply reply; struct hci_cp_pin_code_reply reply;
struct pending_cmd *cmd;
u16 dev_id; u16 dev_id;
int err; int err;
...@@ -957,9 +970,11 @@ static int pin_code_reply(struct sock *sk, unsigned char *data, u16 len) ...@@ -957,9 +970,11 @@ static int pin_code_reply(struct sock *sk, unsigned char *data, u16 len)
goto failed; goto failed;
} }
err = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_REPLY, dev_id, data, len); cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_REPLY, dev_id, data, len);
if (err < 0) if (!cmd) {
err = -ENOMEM;
goto failed; goto failed;
}
bacpy(&reply.bdaddr, &cp->bdaddr); bacpy(&reply.bdaddr, &cp->bdaddr);
reply.pin_len = cp->pin_len; reply.pin_len = cp->pin_len;
...@@ -980,6 +995,7 @@ static int pin_code_neg_reply(struct sock *sk, unsigned char *data, u16 len) ...@@ -980,6 +995,7 @@ static int pin_code_neg_reply(struct sock *sk, unsigned char *data, 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;
struct pending_cmd *cmd;
u16 dev_id; u16 dev_id;
int err; int err;
...@@ -999,10 +1015,12 @@ static int pin_code_neg_reply(struct sock *sk, unsigned char *data, u16 len) ...@@ -999,10 +1015,12 @@ static int pin_code_neg_reply(struct sock *sk, unsigned char *data, u16 len)
goto failed; goto failed;
} }
err = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_NEG_REPLY, dev_id, cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_NEG_REPLY, dev_id,
data, len); data, len);
if (err < 0) if (!cmd) {
err = -ENOMEM;
goto failed; goto failed;
}
err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, sizeof(bdaddr_t), err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, sizeof(bdaddr_t),
&cp->bdaddr); &cp->bdaddr);
......
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