aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2014-07-03 12:33:49 -0400
committerMarcel Holtmann <marcel@holtmann.org>2014-07-03 12:45:08 -0400
commit912b42ef05a1e9f72a82c21d678a29c5055045d5 (patch)
treee0dc92cbed6b9bb10e9cb465ba9110234050c190 /net
parent435a13d839abe8c8b9ebe1be635d1ab8f7352f56 (diff)
Bluetooth: Use hci_conn_params in pend_le_conns
Since the connection parameters are always a basis for adding entries to hdev->pend_le_conns (so far of type bdaddr_list) it's simpler and more efficient to have the parameters themselves be the entries in the pend_le_conns list. We do this by adding another list_head to the hci_conn_params struct. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net')
-rw-r--r--net/bluetooth/hci_core.c68
-rw-r--r--net/bluetooth/hci_event.c7
-rw-r--r--net/bluetooth/mgmt.c4
3 files changed, 28 insertions, 51 deletions
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 41cc64429ea1..8882a6cd2876 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -3427,73 +3427,46 @@ static bool is_connected(struct hci_dev *hdev, bdaddr_t *addr, u8 type)
3427} 3427}
3428 3428
3429/* This function requires the caller holds hdev->lock */ 3429/* This function requires the caller holds hdev->lock */
3430struct bdaddr_list *hci_pend_le_conn_lookup(struct hci_dev *hdev, 3430struct hci_conn_params *hci_pend_le_conn_lookup(struct hci_dev *hdev,
3431 bdaddr_t *addr, u8 addr_type) 3431 bdaddr_t *addr, u8 addr_type)
3432{ 3432{
3433 struct bdaddr_list *entry; 3433 struct hci_conn_params *param;
3434 3434
3435 list_for_each_entry(entry, &hdev->pend_le_conns, list) { 3435 list_for_each_entry(param, &hdev->pend_le_conns, pend_le_conn) {
3436 if (bacmp(&entry->bdaddr, addr) == 0 && 3436 if (bacmp(&param->addr, addr) == 0 &&
3437 entry->bdaddr_type == addr_type) 3437 param->addr_type == addr_type)
3438 return entry; 3438 return param;
3439 } 3439 }
3440 3440
3441 return NULL; 3441 return NULL;
3442} 3442}
3443 3443
3444/* This function requires the caller holds hdev->lock */ 3444/* This function requires the caller holds hdev->lock */
3445void hci_pend_le_conn_add(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type) 3445void hci_pend_le_conn_add(struct hci_dev *hdev, struct hci_conn_params *params)
3446{ 3446{
3447 struct bdaddr_list *entry; 3447 list_del_init(&params->pend_le_conn);
3448 3448 list_add(&params->pend_le_conn, &hdev->pend_le_conns);
3449 entry = hci_pend_le_conn_lookup(hdev, addr, addr_type);
3450 if (entry)
3451 goto done;
3452
3453 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
3454 if (!entry) {
3455 BT_ERR("Out of memory");
3456 return;
3457 }
3458 3449
3459 bacpy(&entry->bdaddr, addr); 3450 BT_DBG("addr %pMR (type %u)", &params->addr, params->addr_type);
3460 entry->bdaddr_type = addr_type;
3461
3462 list_add(&entry->list, &hdev->pend_le_conns);
3463
3464 BT_DBG("addr %pMR (type %u)", addr, addr_type);
3465 3451
3466done:
3467 hci_update_background_scan(hdev); 3452 hci_update_background_scan(hdev);
3468} 3453}
3469 3454
3470/* This function requires the caller holds hdev->lock */ 3455/* This function requires the caller holds hdev->lock */
3471void hci_pend_le_conn_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type) 3456void hci_pend_le_conn_del(struct hci_dev *hdev, struct hci_conn_params *params)
3472{ 3457{
3473 struct bdaddr_list *entry; 3458 list_del_init(&params->pend_le_conn);
3474
3475 entry = hci_pend_le_conn_lookup(hdev, addr, addr_type);
3476 if (!entry)
3477 goto done;
3478
3479 list_del(&entry->list);
3480 kfree(entry);
3481 3459
3482 BT_DBG("addr %pMR (type %u)", addr, addr_type); 3460 BT_DBG("addr %pMR (type %u)", &params->addr, params->addr_type);
3483 3461
3484done:
3485 hci_update_background_scan(hdev); 3462 hci_update_background_scan(hdev);
3486} 3463}
3487 3464
3488/* This function requires the caller holds hdev->lock */ 3465/* This function requires the caller holds hdev->lock */
3489void hci_pend_le_conns_clear(struct hci_dev *hdev) 3466void hci_pend_le_conns_clear(struct hci_dev *hdev)
3490{ 3467{
3491 struct bdaddr_list *entry, *tmp; 3468 while (!list_empty(&hdev->pend_le_conns))
3492 3469 list_del_init(hdev->pend_le_conns.next);
3493 list_for_each_entry_safe(entry, tmp, &hdev->pend_le_conns, list) {
3494 list_del(&entry->list);
3495 kfree(entry);
3496 }
3497 3470
3498 BT_DBG("All LE pending connections cleared"); 3471 BT_DBG("All LE pending connections cleared");
3499 3472
@@ -3523,6 +3496,7 @@ struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev,
3523 params->addr_type = addr_type; 3496 params->addr_type = addr_type;
3524 3497
3525 list_add(&params->list, &hdev->le_conn_params); 3498 list_add(&params->list, &hdev->le_conn_params);
3499 INIT_LIST_HEAD(&params->pend_le_conn);
3526 3500
3527 params->conn_min_interval = hdev->le_conn_min_interval; 3501 params->conn_min_interval = hdev->le_conn_min_interval;
3528 params->conn_max_interval = hdev->le_conn_max_interval; 3502 params->conn_max_interval = hdev->le_conn_max_interval;
@@ -3552,16 +3526,16 @@ int hci_conn_params_set(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type,
3552 switch (auto_connect) { 3526 switch (auto_connect) {
3553 case HCI_AUTO_CONN_DISABLED: 3527 case HCI_AUTO_CONN_DISABLED:
3554 case HCI_AUTO_CONN_LINK_LOSS: 3528 case HCI_AUTO_CONN_LINK_LOSS:
3555 hci_pend_le_conn_del(hdev, addr, addr_type); 3529 hci_pend_le_conn_del(hdev, params);
3556 break; 3530 break;
3557 case HCI_AUTO_CONN_REPORT: 3531 case HCI_AUTO_CONN_REPORT:
3558 if (params->auto_connect != HCI_AUTO_CONN_REPORT) 3532 if (params->auto_connect != HCI_AUTO_CONN_REPORT)
3559 hdev->pend_le_reports++; 3533 hdev->pend_le_reports++;
3560 hci_pend_le_conn_del(hdev, addr, addr_type); 3534 hci_pend_le_conn_del(hdev, params);
3561 break; 3535 break;
3562 case HCI_AUTO_CONN_ALWAYS: 3536 case HCI_AUTO_CONN_ALWAYS:
3563 if (!is_connected(hdev, addr, addr_type)) 3537 if (!is_connected(hdev, addr, addr_type))
3564 hci_pend_le_conn_add(hdev, addr, addr_type); 3538 hci_pend_le_conn_add(hdev, params);
3565 break; 3539 break;
3566 } 3540 }
3567 3541
@@ -3585,7 +3559,7 @@ void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type)
3585 if (params->auto_connect == HCI_AUTO_CONN_REPORT) 3559 if (params->auto_connect == HCI_AUTO_CONN_REPORT)
3586 hdev->pend_le_reports--; 3560 hdev->pend_le_reports--;
3587 3561
3588 hci_pend_le_conn_del(hdev, addr, addr_type); 3562 hci_pend_le_conn_del(hdev, params);
3589 3563
3590 list_del(&params->list); 3564 list_del(&params->list);
3591 kfree(params); 3565 kfree(params);
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 643c5a8d4050..4ebfcedd9ae7 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -2209,7 +2209,7 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
2209 /* Fall through */ 2209 /* Fall through */
2210 2210
2211 case HCI_AUTO_CONN_ALWAYS: 2211 case HCI_AUTO_CONN_ALWAYS:
2212 hci_pend_le_conn_add(hdev, &conn->dst, conn->dst_type); 2212 hci_pend_le_conn_add(hdev, params);
2213 break; 2213 break;
2214 2214
2215 default: 2215 default:
@@ -4036,6 +4036,7 @@ static void hci_disconn_phylink_complete_evt(struct hci_dev *hdev,
4036static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 4036static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
4037{ 4037{
4038 struct hci_ev_le_conn_complete *ev = (void *) skb->data; 4038 struct hci_ev_le_conn_complete *ev = (void *) skb->data;
4039 struct hci_conn_params *params;
4039 struct hci_conn *conn; 4040 struct hci_conn *conn;
4040 struct smp_irk *irk; 4041 struct smp_irk *irk;
4041 u8 addr_type; 4042 u8 addr_type;
@@ -4152,7 +4153,9 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
4152 4153
4153 hci_proto_connect_cfm(conn, ev->status); 4154 hci_proto_connect_cfm(conn, ev->status);
4154 4155
4155 hci_pend_le_conn_del(hdev, &conn->dst, conn->dst_type); 4156 params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type);
4157 if (params)
4158 hci_pend_le_conn_del(hdev, params);
4156 4159
4157unlock: 4160unlock:
4158 hci_dev_unlock(hdev); 4161 hci_dev_unlock(hdev);
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 02a4d31fee30..59ca4057955c 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -5201,7 +5201,7 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev,
5201 if (params->auto_connect == HCI_AUTO_CONN_REPORT) 5201 if (params->auto_connect == HCI_AUTO_CONN_REPORT)
5202 hdev->pend_le_reports--; 5202 hdev->pend_le_reports--;
5203 5203
5204 hci_pend_le_conn_del(hdev, &cp->addr.bdaddr, addr_type); 5204 hci_pend_le_conn_del(hdev, params);
5205 list_del(&params->list); 5205 list_del(&params->list);
5206 kfree(params); 5206 kfree(params);
5207 5207
@@ -5514,7 +5514,7 @@ static void restart_le_auto_conns(struct hci_dev *hdev)
5514 5514
5515 list_for_each_entry(p, &hdev->le_conn_params, list) { 5515 list_for_each_entry(p, &hdev->le_conn_params, list) {
5516 if (p->auto_connect == HCI_AUTO_CONN_ALWAYS) { 5516 if (p->auto_connect == HCI_AUTO_CONN_ALWAYS) {
5517 hci_pend_le_conn_add(hdev, &p->addr, p->addr_type); 5517 hci_pend_le_conn_add(hdev, p);
5518 added = true; 5518 added = true;
5519 } 5519 }
5520 } 5520 }