Commit 124f6e35 authored by Johan Hedberg's avatar Johan Hedberg

Bluetooth: Update and rename mgmt_remove_keys to mgmt_unpair_device

This patch renames the mgmt_remove_keys command to mgmt_unpair_device
and updates its parameters to match the latest API (specifically, it
adds an address type parameter to the command and its response).
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
Acked-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent 930fa4ae
...@@ -175,17 +175,7 @@ struct mgmt_cp_load_long_term_keys { ...@@ -175,17 +175,7 @@ struct mgmt_cp_load_long_term_keys {
struct mgmt_ltk_info keys[0]; struct mgmt_ltk_info keys[0];
} __packed; } __packed;
#define MGMT_OP_REMOVE_KEYS 0x0014 #define MGMT_OP_DISCONNECT 0x0014
struct mgmt_cp_remove_keys {
bdaddr_t bdaddr;
__u8 disconnect;
} __packed;
struct mgmt_rp_remove_keys {
bdaddr_t bdaddr;
__u8 status;
};
#define MGMT_OP_DISCONNECT 0x0015
struct mgmt_cp_disconnect { struct mgmt_cp_disconnect {
bdaddr_t bdaddr; bdaddr_t bdaddr;
} __packed; } __packed;
...@@ -194,13 +184,13 @@ struct mgmt_rp_disconnect { ...@@ -194,13 +184,13 @@ struct mgmt_rp_disconnect {
__u8 status; __u8 status;
} __packed; } __packed;
#define MGMT_OP_GET_CONNECTIONS 0x0016 #define MGMT_OP_GET_CONNECTIONS 0x0015
struct mgmt_rp_get_connections { struct mgmt_rp_get_connections {
__le16 conn_count; __le16 conn_count;
struct mgmt_addr_info addr[0]; struct mgmt_addr_info addr[0];
} __packed; } __packed;
#define MGMT_OP_PIN_CODE_REPLY 0x0017 #define MGMT_OP_PIN_CODE_REPLY 0x0016
struct mgmt_cp_pin_code_reply { struct mgmt_cp_pin_code_reply {
bdaddr_t bdaddr; bdaddr_t bdaddr;
__u8 pin_len; __u8 pin_len;
...@@ -211,17 +201,17 @@ struct mgmt_rp_pin_code_reply { ...@@ -211,17 +201,17 @@ struct mgmt_rp_pin_code_reply {
uint8_t status; uint8_t status;
} __packed; } __packed;
#define MGMT_OP_PIN_CODE_NEG_REPLY 0x0018 #define MGMT_OP_PIN_CODE_NEG_REPLY 0x0017
struct mgmt_cp_pin_code_neg_reply { struct mgmt_cp_pin_code_neg_reply {
bdaddr_t bdaddr; bdaddr_t bdaddr;
} __packed; } __packed;
#define MGMT_OP_SET_IO_CAPABILITY 0x0019 #define MGMT_OP_SET_IO_CAPABILITY 0x0018
struct mgmt_cp_set_io_capability { struct mgmt_cp_set_io_capability {
__u8 io_capability; __u8 io_capability;
} __packed; } __packed;
#define MGMT_OP_PAIR_DEVICE 0x001A #define MGMT_OP_PAIR_DEVICE 0x0019
struct mgmt_cp_pair_device { struct mgmt_cp_pair_device {
struct mgmt_addr_info addr; struct mgmt_addr_info addr;
__u8 io_cap; __u8 io_cap;
...@@ -231,7 +221,17 @@ struct mgmt_rp_pair_device { ...@@ -231,7 +221,17 @@ struct mgmt_rp_pair_device {
__u8 status; __u8 status;
} __packed; } __packed;
#define MGMT_OP_CANCEL_PAIR_DEVICE 0x001B #define MGMT_OP_CANCEL_PAIR_DEVICE 0x001A
#define MGMT_OP_UNPAIR_DEVICE 0x001B
struct mgmt_cp_unpair_device {
struct mgmt_addr_info addr;
__u8 disconnect;
} __packed;
struct mgmt_rp_unpair_device {
struct mgmt_addr_info addr;
__u8 status;
};
#define MGMT_OP_USER_CONFIRM_REPLY 0x001C #define MGMT_OP_USER_CONFIRM_REPLY 0x001C
struct mgmt_cp_user_confirm_reply { struct mgmt_cp_user_confirm_reply {
......
...@@ -1073,57 +1073,63 @@ static int load_link_keys(struct sock *sk, u16 index, void *data, u16 len) ...@@ -1073,57 +1073,63 @@ static int load_link_keys(struct sock *sk, u16 index, void *data, u16 len)
return 0; return 0;
} }
static int remove_keys(struct sock *sk, u16 index, void *data, u16 len) static int unpair_device(struct sock *sk, u16 index, void *data, u16 len)
{ {
struct hci_dev *hdev; struct hci_dev *hdev;
struct mgmt_cp_remove_keys *cp = data; struct mgmt_cp_unpair_device *cp = data;
struct mgmt_rp_remove_keys rp; struct mgmt_rp_unpair_device 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;
if (len != sizeof(*cp)) if (len != sizeof(*cp))
return cmd_status(sk, index, MGMT_OP_REMOVE_KEYS, return cmd_status(sk, index, MGMT_OP_UNPAIR_DEVICE,
MGMT_STATUS_INVALID_PARAMS); MGMT_STATUS_INVALID_PARAMS);
hdev = hci_dev_get(index); hdev = hci_dev_get(index);
if (!hdev) if (!hdev)
return cmd_status(sk, index, MGMT_OP_REMOVE_KEYS, return cmd_status(sk, index, MGMT_OP_UNPAIR_DEVICE,
MGMT_STATUS_INVALID_PARAMS); MGMT_STATUS_INVALID_PARAMS);
hci_dev_lock(hdev); hci_dev_lock(hdev);
memset(&rp, 0, sizeof(rp)); memset(&rp, 0, sizeof(rp));
bacpy(&rp.bdaddr, &cp->bdaddr); bacpy(&rp.addr.bdaddr, &cp->addr.bdaddr);
rp.addr.type = cp->addr.type;
rp.status = MGMT_STATUS_FAILED; rp.status = MGMT_STATUS_FAILED;
err = hci_remove_ltk(hdev, &cp->bdaddr); if (cp->addr.type == MGMT_ADDR_BREDR)
if (err < 0) { err = hci_remove_link_key(hdev, &cp->addr.bdaddr);
err = cmd_status(sk, index, MGMT_OP_REMOVE_KEYS, -err); else
goto unlock; err = hci_remove_ltk(hdev, &cp->addr.bdaddr);
}
err = hci_remove_link_key(hdev, &cp->bdaddr);
if (err < 0) { if (err < 0) {
rp.status = MGMT_STATUS_NOT_PAIRED; rp.status = MGMT_STATUS_NOT_PAIRED;
goto unlock; goto unlock;
} }
if (!test_bit(HCI_UP, &hdev->flags) || !cp->disconnect) { if (!test_bit(HCI_UP, &hdev->flags) || !cp->disconnect) {
err = cmd_complete(sk, index, MGMT_OP_REMOVE_KEYS, &rp, err = cmd_complete(sk, index, MGMT_OP_UNPAIR_DEVICE, &rp,
sizeof(rp)); sizeof(rp));
goto unlock; goto unlock;
} }
conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); if (cp->addr.type == MGMT_ADDR_BREDR)
conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK,
&cp->addr.bdaddr);
else
conn = hci_conn_hash_lookup_ba(hdev, LE_LINK,
&cp->addr.bdaddr);
if (!conn) { if (!conn) {
err = cmd_complete(sk, index, MGMT_OP_REMOVE_KEYS, &rp, err = cmd_complete(sk, index, MGMT_OP_UNPAIR_DEVICE, &rp,
sizeof(rp)); sizeof(rp));
goto unlock; goto unlock;
} }
cmd = mgmt_pending_add(sk, MGMT_OP_REMOVE_KEYS, hdev, cp, sizeof(*cp)); cmd = mgmt_pending_add(sk, MGMT_OP_UNPAIR_DEVICE, hdev, cp,
sizeof(*cp));
if (!cmd) { if (!cmd) {
err = -ENOMEM; err = -ENOMEM;
goto unlock; goto unlock;
...@@ -1137,7 +1143,7 @@ static int remove_keys(struct sock *sk, u16 index, void *data, u16 len) ...@@ -1137,7 +1143,7 @@ static int remove_keys(struct sock *sk, u16 index, void *data, u16 len)
unlock: unlock:
if (err < 0) if (err < 0)
err = cmd_complete(sk, index, MGMT_OP_REMOVE_KEYS, &rp, err = cmd_complete(sk, index, MGMT_OP_UNPAIR_DEVICE, &rp,
sizeof(rp)); sizeof(rp));
hci_dev_unlock(hdev); hci_dev_unlock(hdev);
hci_dev_put(hdev); hci_dev_put(hdev);
...@@ -2340,9 +2346,6 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen) ...@@ -2340,9 +2346,6 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
case MGMT_OP_LOAD_LINK_KEYS: case MGMT_OP_LOAD_LINK_KEYS:
err = load_link_keys(sk, index, cp, len); err = load_link_keys(sk, index, cp, len);
break; break;
case MGMT_OP_REMOVE_KEYS:
err = remove_keys(sk, index, cp, len);
break;
case MGMT_OP_DISCONNECT: case MGMT_OP_DISCONNECT:
err = disconnect(sk, index, cp, len); err = disconnect(sk, index, cp, len);
break; break;
...@@ -2364,6 +2367,9 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen) ...@@ -2364,6 +2367,9 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
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_UNPAIR_DEVICE:
err = unpair_device(sk, index, cp, len);
break;
case MGMT_OP_USER_CONFIRM_REPLY: case MGMT_OP_USER_CONFIRM_REPLY:
err = user_confirm_reply(sk, index, cp, len); err = user_confirm_reply(sk, index, cp, len);
break; break;
...@@ -2624,18 +2630,19 @@ static void disconnect_rsp(struct pending_cmd *cmd, void *data) ...@@ -2624,18 +2630,19 @@ static void disconnect_rsp(struct pending_cmd *cmd, void *data)
mgmt_pending_remove(cmd); mgmt_pending_remove(cmd);
} }
static void remove_keys_rsp(struct pending_cmd *cmd, void *data) static void unpair_device_rsp(struct pending_cmd *cmd, void *data)
{ {
u8 *status = data; u8 *status = data;
struct mgmt_cp_remove_keys *cp = cmd->param; struct mgmt_cp_unpair_device *cp = cmd->param;
struct mgmt_rp_remove_keys rp; struct mgmt_rp_unpair_device rp;
memset(&rp, 0, sizeof(rp)); memset(&rp, 0, sizeof(rp));
bacpy(&rp.bdaddr, &cp->bdaddr); bacpy(&rp.addr.bdaddr, &cp->addr.bdaddr);
rp.addr.type = cp->addr.type;
if (status != NULL) if (status != NULL)
rp.status = *status; rp.status = *status;
cmd_complete(cmd->sk, cmd->index, MGMT_OP_REMOVE_KEYS, &rp, cmd_complete(cmd->sk, cmd->index, MGMT_OP_UNPAIR_DEVICE, &rp,
sizeof(rp)); sizeof(rp));
mgmt_pending_remove(cmd); mgmt_pending_remove(cmd);
...@@ -2659,7 +2666,8 @@ int mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, ...@@ -2659,7 +2666,8 @@ int mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
if (sk) if (sk)
sock_put(sk); sock_put(sk);
mgmt_pending_foreach(MGMT_OP_REMOVE_KEYS, hdev, remove_keys_rsp, NULL); mgmt_pending_foreach(MGMT_OP_UNPAIR_DEVICE, hdev, unpair_device_rsp,
NULL);
return err; return err;
} }
......
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