浏览代码

Bluetooth: Remove only enabled entries with Remove Device command

The Remove Device mgmt command is supposed to undo what the Add Device
command does. An entry added by Add Device cannot have the
HCI_AUTO_CONN_DISABLED auto_connect value, so we should treat this as an
invalid entry to remove. This patch adds the necessary pieces to the
Remove Device command handler so that it only removes entries which were
added by Add Device.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Johan Hedberg 11 年之前
父节点
当前提交
c71593dd34
共有 1 个文件被更改,包括 21 次插入2 次删除
  1. 21 2
      net/bluetooth/mgmt.c

+ 21 - 2
net/bluetooth/mgmt.c

@@ -5079,6 +5079,7 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev,
 	hci_dev_lock(hdev);
 	hci_dev_lock(hdev);
 
 
 	if (bacmp(&cp->addr.bdaddr, BDADDR_ANY)) {
 	if (bacmp(&cp->addr.bdaddr, BDADDR_ANY)) {
+		struct hci_conn_params *params;
 		u8 addr_type;
 		u8 addr_type;
 
 
 		if (!bdaddr_type_is_le(cp->addr.type)) {
 		if (!bdaddr_type_is_le(cp->addr.type)) {
@@ -5093,7 +5094,25 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev,
 		else
 		else
 			addr_type = ADDR_LE_DEV_RANDOM;
 			addr_type = ADDR_LE_DEV_RANDOM;
 
 
-		hci_conn_params_del(hdev, &cp->addr.bdaddr, addr_type);
+		params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr,
+						addr_type);
+		if (!params) {
+			err = cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE,
+					   MGMT_STATUS_INVALID_PARAMS,
+					   &cp->addr, sizeof(cp->addr));
+			goto unlock;
+		}
+
+		if (params->auto_connect == HCI_AUTO_CONN_DISABLED) {
+			err = cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE,
+					   MGMT_STATUS_INVALID_PARAMS,
+					   &cp->addr, sizeof(cp->addr));
+			goto unlock;
+		}
+
+		hci_pend_le_conn_del(hdev, &cp->addr.bdaddr, addr_type);
+		list_del(&params->list);
+		kfree(params);
 
 
 		device_removed(sk, hdev, &cp->addr.bdaddr, cp->addr.type);
 		device_removed(sk, hdev, &cp->addr.bdaddr, cp->addr.type);
 	} else {
 	} else {
@@ -5104,7 +5123,7 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev,
 			goto unlock;
 			goto unlock;
 		}
 		}
 
 
-		hci_conn_params_clear_all(hdev);
+		hci_conn_params_clear_enabled(hdev);
 	}
 	}
 
 
 	err = cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE,
 	err = cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE,