Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 123abc08 authored by Johan Hedberg's avatar Johan Hedberg Committed by Marcel Holtmann
Browse files

Bluetooth: Refactor ioctl scan state update to its own function



With subsequent patches we'll also need to update the discoverable
state. As the code grows bigger it's better to move this out from the
switch statement into its own function.

Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent 031547d8
Loading
Loading
Loading
Loading
+22 −13
Original line number Diff line number Diff line
@@ -2655,6 +2655,26 @@ int hci_dev_reset_stat(__u16 dev)
	return ret;
}

static void hci_update_scan_state(struct hci_dev *hdev, u8 scan)
{
	bool conn_changed;

	BT_DBG("%s scan 0x%02x", hdev->name, scan);

	if ((scan & SCAN_PAGE))
		conn_changed = !test_and_set_bit(HCI_CONNECTABLE,
						 &hdev->dev_flags);
	else
		conn_changed = test_and_clear_bit(HCI_CONNECTABLE,
						  &hdev->dev_flags);

	if (!test_bit(HCI_MGMT, &hdev->dev_flags))
		return;

	if (conn_changed)
		mgmt_new_settings(hdev);
}

int hci_dev_cmd(unsigned int cmd, void __user *arg)
{
	struct hci_dev *hdev;
@@ -2719,19 +2739,8 @@ int hci_dev_cmd(unsigned int cmd, void __user *arg)
		/* Ensure that the connectable state gets correctly
		 * modified as this was a non-mgmt change.
		 */
		if (!err) {
			bool changed;

			if ((dr.dev_opt & SCAN_PAGE))
				changed = !test_and_set_bit(HCI_CONNECTABLE,
							    &hdev->dev_flags);
			else
				changed = test_and_clear_bit(HCI_CONNECTABLE,
							     &hdev->dev_flags);

			if (changed && test_bit(HCI_MGMT, &hdev->dev_flags))
				mgmt_new_settings(hdev);
		}
		if (!err)
			hci_update_scan_state(hdev, dr.dev_opt);
		break;

	case HCISETLINKPOL: