aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2014-06-30 06:34:39 -0400
committerMarcel Holtmann <marcel@holtmann.org>2014-07-03 11:42:51 -0400
commitbf5b3c8be07905c242bb7f751dcb890b94c22d93 (patch)
treed51b8f325a1b0b0043ea309cd748bd9f546f2377 /net
parentf1649577a6c20410335dbb4765e74e51fd5df585 (diff)
Bluetooth: Provide function to create and set connection parameters
In some cases it is useful to not overwrite connection parametes and instead just create default ones if they don't exist. This function does exactly that. hci_conn_params_add will allow to create new default connection parameters. hci_conn_params_set will set the values and also create new parameters if they don't exist. Signed-off-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Diffstat (limited to 'net')
-rw-r--r--net/bluetooth/hci_core.c36
-rw-r--r--net/bluetooth/mgmt.c5
2 files changed, 39 insertions, 2 deletions
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 6c28687c9286..adea7de95633 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -3472,7 +3472,41 @@ void hci_pend_le_conns_clear(struct hci_dev *hdev)
3472} 3472}
3473 3473
3474/* This function requires the caller holds hdev->lock */ 3474/* This function requires the caller holds hdev->lock */
3475int hci_conn_params_add(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type, 3475int hci_conn_params_add(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type)
3476{
3477 struct hci_conn_params *params;
3478
3479 if (!is_identity_address(addr, addr_type))
3480 return -EINVAL;
3481
3482 params = hci_conn_params_lookup(hdev, addr, addr_type);
3483 if (params)
3484 return 0;
3485
3486 params = kzalloc(sizeof(*params), GFP_KERNEL);
3487 if (!params) {
3488 BT_ERR("Out of memory");
3489 return -ENOMEM;
3490 }
3491
3492 bacpy(&params->addr, addr);
3493 params->addr_type = addr_type;
3494
3495 list_add(&params->list, &hdev->le_conn_params);
3496
3497 params->conn_min_interval = hdev->le_conn_min_interval;
3498 params->conn_max_interval = hdev->le_conn_max_interval;
3499 params->conn_latency = hdev->le_conn_latency;
3500 params->supervision_timeout = hdev->le_supv_timeout;
3501 params->auto_connect = HCI_AUTO_CONN_DISABLED;
3502
3503 BT_DBG("addr %pMR (type %u)", addr, addr_type);
3504
3505 return 0;
3506}
3507
3508/* This function requires the caller holds hdev->lock */
3509int hci_conn_params_set(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type,
3476 u8 auto_connect, u16 conn_min_interval, 3510 u8 auto_connect, u16 conn_min_interval,
3477 u16 conn_max_interval) 3511 u16 conn_max_interval)
3478{ 3512{
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index d83197f9e727..e30d0ebb5018 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -5014,7 +5014,10 @@ static int add_device(struct sock *sk, struct hci_dev *hdev,
5014 else 5014 else
5015 auto_conn = HCI_AUTO_CONN_DISABLED; 5015 auto_conn = HCI_AUTO_CONN_DISABLED;
5016 5016
5017 if (hci_conn_params_add(hdev, &cp->addr.bdaddr, addr_type, auto_conn, 5017 /* If the connection parameters don't exist for this device,
5018 * they will be created and configured with defaults.
5019 */
5020 if (hci_conn_params_set(hdev, &cp->addr.bdaddr, addr_type, auto_conn,
5018 hdev->le_conn_min_interval, 5021 hdev->le_conn_min_interval,
5019 hdev->le_conn_max_interval) < 0) { 5022 hdev->le_conn_max_interval) < 0) {
5020 err = cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, 5023 err = cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE,