aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth
diff options
context:
space:
mode:
authorJaganath Kanakkassery <jaganath.k.os@gmail.com>2018-07-06 07:35:30 -0400
committerMarcel Holtmann <marcel@holtmann.org>2018-07-06 16:45:56 -0400
commitd12fb05643f9b48134c7650f5a03f9729aacfde4 (patch)
treef7d081d1afaacff46696688e65907fe4d0c7ec8c /net/bluetooth
parentc215e9397b00b3045a668120ed7dbd89f2866e74 (diff)
Bluetooth: Introduce helpers for le conn status and complete
This is done so that the helpers can be used for extended conn implementation which will be done in subsequent patch. Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/bluetooth')
-rw-r--r--net/bluetooth/hci_event.c110
1 files changed, 65 insertions, 45 deletions
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 6c6fd4f55f23..14e42e157de9 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1971,55 +1971,63 @@ static void hci_cs_disconnect(struct hci_dev *hdev, u8 status)
1971 hci_dev_unlock(hdev); 1971 hci_dev_unlock(hdev);
1972} 1972}
1973 1973
1974static void hci_cs_le_create_conn(struct hci_dev *hdev, u8 status) 1974static void cs_le_create_conn(struct hci_dev *hdev, bdaddr_t *peer_addr,
1975 u8 peer_addr_type, u8 own_address_type,
1976 u8 filter_policy)
1975{ 1977{
1976 struct hci_cp_le_create_conn *cp;
1977 struct hci_conn *conn; 1978 struct hci_conn *conn;
1978 1979
1979 BT_DBG("%s status 0x%2.2x", hdev->name, status); 1980 conn = hci_conn_hash_lookup_le(hdev, peer_addr,
1980 1981 peer_addr_type);
1981 /* All connection failure handling is taken care of by the
1982 * hci_le_conn_failed function which is triggered by the HCI
1983 * request completion callbacks used for connecting.
1984 */
1985 if (status)
1986 return;
1987
1988 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_CREATE_CONN);
1989 if (!cp)
1990 return;
1991
1992 hci_dev_lock(hdev);
1993
1994 conn = hci_conn_hash_lookup_le(hdev, &cp->peer_addr,
1995 cp->peer_addr_type);
1996 if (!conn) 1982 if (!conn)
1997 goto unlock; 1983 return;
1998 1984
1999 /* Store the initiator and responder address information which 1985 /* Store the initiator and responder address information which
2000 * is needed for SMP. These values will not change during the 1986 * is needed for SMP. These values will not change during the
2001 * lifetime of the connection. 1987 * lifetime of the connection.
2002 */ 1988 */
2003 conn->init_addr_type = cp->own_address_type; 1989 conn->init_addr_type = own_address_type;
2004 if (cp->own_address_type == ADDR_LE_DEV_RANDOM) 1990 if (own_address_type == ADDR_LE_DEV_RANDOM)
2005 bacpy(&conn->init_addr, &hdev->random_addr); 1991 bacpy(&conn->init_addr, &hdev->random_addr);
2006 else 1992 else
2007 bacpy(&conn->init_addr, &hdev->bdaddr); 1993 bacpy(&conn->init_addr, &hdev->bdaddr);
2008 1994
2009 conn->resp_addr_type = cp->peer_addr_type; 1995 conn->resp_addr_type = peer_addr_type;
2010 bacpy(&conn->resp_addr, &cp->peer_addr); 1996 bacpy(&conn->resp_addr, peer_addr);
2011 1997
2012 /* We don't want the connection attempt to stick around 1998 /* We don't want the connection attempt to stick around
2013 * indefinitely since LE doesn't have a page timeout concept 1999 * indefinitely since LE doesn't have a page timeout concept
2014 * like BR/EDR. Set a timer for any connection that doesn't use 2000 * like BR/EDR. Set a timer for any connection that doesn't use
2015 * the white list for connecting. 2001 * the white list for connecting.
2016 */ 2002 */
2017 if (cp->filter_policy == HCI_LE_USE_PEER_ADDR) 2003 if (filter_policy == HCI_LE_USE_PEER_ADDR)
2018 queue_delayed_work(conn->hdev->workqueue, 2004 queue_delayed_work(conn->hdev->workqueue,
2019 &conn->le_conn_timeout, 2005 &conn->le_conn_timeout,
2020 conn->conn_timeout); 2006 conn->conn_timeout);
2007}
2008
2009static void hci_cs_le_create_conn(struct hci_dev *hdev, u8 status)
2010{
2011 struct hci_cp_le_create_conn *cp;
2012
2013 BT_DBG("%s status 0x%2.2x", hdev->name, status);
2014
2015 /* All connection failure handling is taken care of by the
2016 * hci_le_conn_failed function which is triggered by the HCI
2017 * request completion callbacks used for connecting.
2018 */
2019 if (status)
2020 return;
2021
2022 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_CREATE_CONN);
2023 if (!cp)
2024 return;
2025
2026 hci_dev_lock(hdev);
2027
2028 cs_le_create_conn(hdev, &cp->peer_addr, cp->peer_addr_type,
2029 cp->own_address_type, cp->filter_policy);
2021 2030
2022unlock:
2023 hci_dev_unlock(hdev); 2031 hci_dev_unlock(hdev);
2024} 2032}
2025 2033
@@ -4551,16 +4559,15 @@ static void hci_disconn_phylink_complete_evt(struct hci_dev *hdev,
4551} 4559}
4552#endif 4560#endif
4553 4561
4554static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 4562static void le_conn_complete_evt(struct hci_dev *hdev, u8 status,
4563 bdaddr_t *bdaddr, u8 bdaddr_type, u8 role, u16 handle,
4564 u16 interval, u16 latency, u16 supervision_timeout)
4555{ 4565{
4556 struct hci_ev_le_conn_complete *ev = (void *) skb->data;
4557 struct hci_conn_params *params; 4566 struct hci_conn_params *params;
4558 struct hci_conn *conn; 4567 struct hci_conn *conn;
4559 struct smp_irk *irk; 4568 struct smp_irk *irk;
4560 u8 addr_type; 4569 u8 addr_type;
4561 4570
4562 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
4563
4564 hci_dev_lock(hdev); 4571 hci_dev_lock(hdev);
4565 4572
4566 /* All controllers implicitly stop advertising in the event of a 4573 /* All controllers implicitly stop advertising in the event of a
@@ -4570,13 +4577,13 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
4570 4577
4571 conn = hci_lookup_le_connect(hdev); 4578 conn = hci_lookup_le_connect(hdev);
4572 if (!conn) { 4579 if (!conn) {
4573 conn = hci_conn_add(hdev, LE_LINK, &ev->bdaddr, ev->role); 4580 conn = hci_conn_add(hdev, LE_LINK, bdaddr, role);
4574 if (!conn) { 4581 if (!conn) {
4575 bt_dev_err(hdev, "no memory for new connection"); 4582 bt_dev_err(hdev, "no memory for new connection");
4576 goto unlock; 4583 goto unlock;
4577 } 4584 }
4578 4585
4579 conn->dst_type = ev->bdaddr_type; 4586 conn->dst_type = bdaddr_type;
4580 4587
4581 /* If we didn't have a hci_conn object previously 4588 /* If we didn't have a hci_conn object previously
4582 * but we're in master role this must be something 4589 * but we're in master role this must be something
@@ -4587,8 +4594,8 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
4587 * initiator address based on the HCI_PRIVACY flag. 4594 * initiator address based on the HCI_PRIVACY flag.
4588 */ 4595 */
4589 if (conn->out) { 4596 if (conn->out) {
4590 conn->resp_addr_type = ev->bdaddr_type; 4597 conn->resp_addr_type = bdaddr_type;
4591 bacpy(&conn->resp_addr, &ev->bdaddr); 4598 bacpy(&conn->resp_addr, bdaddr);
4592 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) { 4599 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) {
4593 conn->init_addr_type = ADDR_LE_DEV_RANDOM; 4600 conn->init_addr_type = ADDR_LE_DEV_RANDOM;
4594 bacpy(&conn->init_addr, &hdev->rpa); 4601 bacpy(&conn->init_addr, &hdev->rpa);
@@ -4612,8 +4619,8 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
4612 else 4619 else
4613 bacpy(&conn->resp_addr, &hdev->bdaddr); 4620 bacpy(&conn->resp_addr, &hdev->bdaddr);
4614 4621
4615 conn->init_addr_type = ev->bdaddr_type; 4622 conn->init_addr_type = bdaddr_type;
4616 bacpy(&conn->init_addr, &ev->bdaddr); 4623 bacpy(&conn->init_addr, bdaddr);
4617 4624
4618 /* For incoming connections, set the default minimum 4625 /* For incoming connections, set the default minimum
4619 * and maximum connection interval. They will be used 4626 * and maximum connection interval. They will be used
@@ -4639,8 +4646,8 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
4639 conn->dst_type = irk->addr_type; 4646 conn->dst_type = irk->addr_type;
4640 } 4647 }
4641 4648
4642 if (ev->status) { 4649 if (status) {
4643 hci_le_conn_failed(conn, ev->status); 4650 hci_le_conn_failed(conn, status);
4644 goto unlock; 4651 goto unlock;
4645 } 4652 }
4646 4653
@@ -4659,17 +4666,17 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
4659 mgmt_device_connected(hdev, conn, 0, NULL, 0); 4666 mgmt_device_connected(hdev, conn, 0, NULL, 0);
4660 4667
4661 conn->sec_level = BT_SECURITY_LOW; 4668 conn->sec_level = BT_SECURITY_LOW;
4662 conn->handle = __le16_to_cpu(ev->handle); 4669 conn->handle = handle;
4663 conn->state = BT_CONFIG; 4670 conn->state = BT_CONFIG;
4664 4671
4665 conn->le_conn_interval = le16_to_cpu(ev->interval); 4672 conn->le_conn_interval = interval;
4666 conn->le_conn_latency = le16_to_cpu(ev->latency); 4673 conn->le_conn_latency = latency;
4667 conn->le_supv_timeout = le16_to_cpu(ev->supervision_timeout); 4674 conn->le_supv_timeout = supervision_timeout;
4668 4675
4669 hci_debugfs_create_conn(conn); 4676 hci_debugfs_create_conn(conn);
4670 hci_conn_add_sysfs(conn); 4677 hci_conn_add_sysfs(conn);
4671 4678
4672 if (!ev->status) { 4679 if (!status) {
4673 /* The remote features procedure is defined for master 4680 /* The remote features procedure is defined for master
4674 * role only. So only in case of an initiated connection 4681 * role only. So only in case of an initiated connection
4675 * request the remote features. 4682 * request the remote features.
@@ -4691,10 +4698,10 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
4691 hci_conn_hold(conn); 4698 hci_conn_hold(conn);
4692 } else { 4699 } else {
4693 conn->state = BT_CONNECTED; 4700 conn->state = BT_CONNECTED;
4694 hci_connect_cfm(conn, ev->status); 4701 hci_connect_cfm(conn, status);
4695 } 4702 }
4696 } else { 4703 } else {
4697 hci_connect_cfm(conn, ev->status); 4704 hci_connect_cfm(conn, status);
4698 } 4705 }
4699 4706
4700 params = hci_pend_le_action_lookup(&hdev->pend_le_conns, &conn->dst, 4707 params = hci_pend_le_action_lookup(&hdev->pend_le_conns, &conn->dst,
@@ -4713,6 +4720,19 @@ unlock:
4713 hci_dev_unlock(hdev); 4720 hci_dev_unlock(hdev);
4714} 4721}
4715 4722
4723static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
4724{
4725 struct hci_ev_le_conn_complete *ev = (void *) skb->data;
4726
4727 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
4728
4729 le_conn_complete_evt(hdev, ev->status, &ev->bdaddr, ev->bdaddr_type,
4730 ev->role, le16_to_cpu(ev->handle),
4731 le16_to_cpu(ev->interval),
4732 le16_to_cpu(ev->latency),
4733 le16_to_cpu(ev->supervision_timeout));
4734}
4735
4716static void hci_le_conn_update_complete_evt(struct hci_dev *hdev, 4736static void hci_le_conn_update_complete_evt(struct hci_dev *hdev,
4717 struct sk_buff *skb) 4737 struct sk_buff *skb)
4718{ 4738{