Bluetooth: Adding a configurable autoconnect timeout
authorAlain Michaud <alainm@chromium.org>
Mon, 29 Jun 2020 16:11:00 +0000 (16:11 +0000)
committerMarcel Holtmann <marcel@holtmann.org>
Tue, 7 Jul 2020 15:37:03 +0000 (17:37 +0200)
This patch adds a configurable LE autoconnect timeout.

Signed-off-by: Alain Michaud <alainm@chromium.org>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
include/net/bluetooth/hci_core.h
net/bluetooth/hci_core.c
net/bluetooth/hci_event.c
net/bluetooth/mgmt_config.c

index 836dc99..34ad5b2 100644 (file)
@@ -376,6 +376,7 @@ struct hci_dev {
        __u16           def_br_lsto;
        __u16           def_page_timeout;
        __u16           def_multi_adv_rotation_duration;
+       __u16           def_le_autoconnect_timeout;
 
        __u16           pkt_type;
        __u16           esco_type;
index 7959b85..e6bf3d9 100644 (file)
@@ -3569,6 +3569,7 @@ struct hci_dev *hci_alloc_dev(void)
        hdev->le_rx_def_phys = HCI_LE_SET_PHY_1M;
        hdev->le_num_of_adv_sets = HCI_MAX_ADV_INSTANCES;
        hdev->def_multi_adv_rotation_duration = HCI_DEFAULT_ADV_DURATION;
+       hdev->def_le_autoconnect_timeout = HCI_LE_AUTOCONN_TIMEOUT;
 
        hdev->rpa_timeout = HCI_DEFAULT_RPA_TIMEOUT;
        hdev->discov_interleaved_timeout = DISCOV_INTERLEAVED_TIMEOUT;
index e060fc9..03a0759 100644 (file)
@@ -5315,7 +5315,7 @@ static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev,
        }
 
        conn = hci_connect_le(hdev, addr, addr_type, BT_SECURITY_LOW,
-                             HCI_LE_AUTOCONN_TIMEOUT, HCI_ROLE_MASTER,
+                             hdev->def_le_autoconnect_timeout, HCI_ROLE_MASTER,
                              direct_rpa);
        if (!IS_ERR(conn)) {
                /* If HCI_AUTO_CONN_EXPLICIT is set, conn is already owned
index 8d01a8f..b30b571 100644 (file)
        { cpu_to_le16(hdev->_param_name_) } \
 }
 
+#define HDEV_PARAM_U16_JIFFIES_TO_MSECS(_param_code_, _param_name_) \
+{ \
+       { cpu_to_le16(_param_code_), sizeof(__u16) }, \
+       { cpu_to_le16(jiffies_to_msecs(hdev->_param_name_)) } \
+}
+
 int read_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data,
                           u16 data_len)
 {
@@ -59,6 +65,8 @@ int read_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data,
                HDEV_PARAM_U16(0x0018, le_conn_max_interval),
                HDEV_PARAM_U16(0x0019, le_conn_latency),
                HDEV_PARAM_U16(0x001a, le_supv_timeout),
+               HDEV_PARAM_U16_JIFFIES_TO_MSECS(0x001b,
+                                               def_le_autoconnect_timeout),
        };
        struct mgmt_rp_read_def_system_config *rp = (void *)params;
 
@@ -129,6 +137,7 @@ int set_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data,
                case 0x0018:
                case 0x0019:
                case 0x001a:
+               case 0x001b:
                        if (len != sizeof(u16)) {
                                bt_dev_warn(hdev, "invalid length %d, exp %zu for type %d",
                                            len, sizeof(u16), type);
@@ -238,6 +247,10 @@ int set_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data,
                case 0x0001a:
                        hdev->le_supv_timeout = TLV_GET_LE16(buffer);
                        break;
+               case 0x0001b:
+                       hdev->def_le_autoconnect_timeout =
+                                       msecs_to_jiffies(TLV_GET_LE16(buffer));
+                       break;
                default:
                        bt_dev_warn(hdev, "unsupported parameter %u", type);
                        break;