forked from Minki/linux
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>
This commit is contained in:
parent
435a13d839
commit
912b42ef05
@ -439,6 +439,7 @@ struct hci_chan {
|
||||
|
||||
struct hci_conn_params {
|
||||
struct list_head list;
|
||||
struct list_head pend_le_conn;
|
||||
|
||||
bdaddr_t addr;
|
||||
u8 addr_type;
|
||||
@ -867,10 +868,10 @@ void hci_conn_params_clear_all(struct hci_dev *hdev);
|
||||
void hci_conn_params_clear_disabled(struct hci_dev *hdev);
|
||||
void hci_conn_params_clear_enabled(struct hci_dev *hdev);
|
||||
|
||||
struct bdaddr_list *hci_pend_le_conn_lookup(struct hci_dev *hdev,
|
||||
bdaddr_t *addr, u8 addr_type);
|
||||
void hci_pend_le_conn_add(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type);
|
||||
void hci_pend_le_conn_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type);
|
||||
struct hci_conn_params *hci_pend_le_conn_lookup(struct hci_dev *hdev,
|
||||
bdaddr_t *addr, u8 addr_type);
|
||||
void hci_pend_le_conn_add(struct hci_dev *hdev, struct hci_conn_params *params);
|
||||
void hci_pend_le_conn_del(struct hci_dev *hdev, struct hci_conn_params *params);
|
||||
void hci_pend_le_conns_clear(struct hci_dev *hdev);
|
||||
|
||||
void hci_update_background_scan(struct hci_dev *hdev);
|
||||
|
@ -3427,73 +3427,46 @@ static bool is_connected(struct hci_dev *hdev, bdaddr_t *addr, u8 type)
|
||||
}
|
||||
|
||||
/* This function requires the caller holds hdev->lock */
|
||||
struct bdaddr_list *hci_pend_le_conn_lookup(struct hci_dev *hdev,
|
||||
bdaddr_t *addr, u8 addr_type)
|
||||
struct hci_conn_params *hci_pend_le_conn_lookup(struct hci_dev *hdev,
|
||||
bdaddr_t *addr, u8 addr_type)
|
||||
{
|
||||
struct bdaddr_list *entry;
|
||||
struct hci_conn_params *param;
|
||||
|
||||
list_for_each_entry(entry, &hdev->pend_le_conns, list) {
|
||||
if (bacmp(&entry->bdaddr, addr) == 0 &&
|
||||
entry->bdaddr_type == addr_type)
|
||||
return entry;
|
||||
list_for_each_entry(param, &hdev->pend_le_conns, pend_le_conn) {
|
||||
if (bacmp(¶m->addr, addr) == 0 &&
|
||||
param->addr_type == addr_type)
|
||||
return param;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* This function requires the caller holds hdev->lock */
|
||||
void hci_pend_le_conn_add(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type)
|
||||
void hci_pend_le_conn_add(struct hci_dev *hdev, struct hci_conn_params *params)
|
||||
{
|
||||
struct bdaddr_list *entry;
|
||||
list_del_init(¶ms->pend_le_conn);
|
||||
list_add(¶ms->pend_le_conn, &hdev->pend_le_conns);
|
||||
|
||||
entry = hci_pend_le_conn_lookup(hdev, addr, addr_type);
|
||||
if (entry)
|
||||
goto done;
|
||||
BT_DBG("addr %pMR (type %u)", ¶ms->addr, params->addr_type);
|
||||
|
||||
entry = kzalloc(sizeof(*entry), GFP_KERNEL);
|
||||
if (!entry) {
|
||||
BT_ERR("Out of memory");
|
||||
return;
|
||||
}
|
||||
|
||||
bacpy(&entry->bdaddr, addr);
|
||||
entry->bdaddr_type = addr_type;
|
||||
|
||||
list_add(&entry->list, &hdev->pend_le_conns);
|
||||
|
||||
BT_DBG("addr %pMR (type %u)", addr, addr_type);
|
||||
|
||||
done:
|
||||
hci_update_background_scan(hdev);
|
||||
}
|
||||
|
||||
/* This function requires the caller holds hdev->lock */
|
||||
void hci_pend_le_conn_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type)
|
||||
void hci_pend_le_conn_del(struct hci_dev *hdev, struct hci_conn_params *params)
|
||||
{
|
||||
struct bdaddr_list *entry;
|
||||
list_del_init(¶ms->pend_le_conn);
|
||||
|
||||
entry = hci_pend_le_conn_lookup(hdev, addr, addr_type);
|
||||
if (!entry)
|
||||
goto done;
|
||||
BT_DBG("addr %pMR (type %u)", ¶ms->addr, params->addr_type);
|
||||
|
||||
list_del(&entry->list);
|
||||
kfree(entry);
|
||||
|
||||
BT_DBG("addr %pMR (type %u)", addr, addr_type);
|
||||
|
||||
done:
|
||||
hci_update_background_scan(hdev);
|
||||
}
|
||||
|
||||
/* This function requires the caller holds hdev->lock */
|
||||
void hci_pend_le_conns_clear(struct hci_dev *hdev)
|
||||
{
|
||||
struct bdaddr_list *entry, *tmp;
|
||||
|
||||
list_for_each_entry_safe(entry, tmp, &hdev->pend_le_conns, list) {
|
||||
list_del(&entry->list);
|
||||
kfree(entry);
|
||||
}
|
||||
while (!list_empty(&hdev->pend_le_conns))
|
||||
list_del_init(hdev->pend_le_conns.next);
|
||||
|
||||
BT_DBG("All LE pending connections cleared");
|
||||
|
||||
@ -3523,6 +3496,7 @@ struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev,
|
||||
params->addr_type = addr_type;
|
||||
|
||||
list_add(¶ms->list, &hdev->le_conn_params);
|
||||
INIT_LIST_HEAD(¶ms->pend_le_conn);
|
||||
|
||||
params->conn_min_interval = hdev->le_conn_min_interval;
|
||||
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,
|
||||
switch (auto_connect) {
|
||||
case HCI_AUTO_CONN_DISABLED:
|
||||
case HCI_AUTO_CONN_LINK_LOSS:
|
||||
hci_pend_le_conn_del(hdev, addr, addr_type);
|
||||
hci_pend_le_conn_del(hdev, params);
|
||||
break;
|
||||
case HCI_AUTO_CONN_REPORT:
|
||||
if (params->auto_connect != HCI_AUTO_CONN_REPORT)
|
||||
hdev->pend_le_reports++;
|
||||
hci_pend_le_conn_del(hdev, addr, addr_type);
|
||||
hci_pend_le_conn_del(hdev, params);
|
||||
break;
|
||||
case HCI_AUTO_CONN_ALWAYS:
|
||||
if (!is_connected(hdev, addr, addr_type))
|
||||
hci_pend_le_conn_add(hdev, addr, addr_type);
|
||||
hci_pend_le_conn_add(hdev, params);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -3585,7 +3559,7 @@ void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type)
|
||||
if (params->auto_connect == HCI_AUTO_CONN_REPORT)
|
||||
hdev->pend_le_reports--;
|
||||
|
||||
hci_pend_le_conn_del(hdev, addr, addr_type);
|
||||
hci_pend_le_conn_del(hdev, params);
|
||||
|
||||
list_del(¶ms->list);
|
||||
kfree(params);
|
||||
|
@ -2209,7 +2209,7 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
|
||||
/* Fall through */
|
||||
|
||||
case HCI_AUTO_CONN_ALWAYS:
|
||||
hci_pend_le_conn_add(hdev, &conn->dst, conn->dst_type);
|
||||
hci_pend_le_conn_add(hdev, params);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -4036,6 +4036,7 @@ static void hci_disconn_phylink_complete_evt(struct hci_dev *hdev,
|
||||
static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
|
||||
{
|
||||
struct hci_ev_le_conn_complete *ev = (void *) skb->data;
|
||||
struct hci_conn_params *params;
|
||||
struct hci_conn *conn;
|
||||
struct smp_irk *irk;
|
||||
u8 addr_type;
|
||||
@ -4152,7 +4153,9 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
|
||||
|
||||
hci_proto_connect_cfm(conn, ev->status);
|
||||
|
||||
hci_pend_le_conn_del(hdev, &conn->dst, conn->dst_type);
|
||||
params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type);
|
||||
if (params)
|
||||
hci_pend_le_conn_del(hdev, params);
|
||||
|
||||
unlock:
|
||||
hci_dev_unlock(hdev);
|
||||
|
@ -5201,7 +5201,7 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev,
|
||||
if (params->auto_connect == HCI_AUTO_CONN_REPORT)
|
||||
hdev->pend_le_reports--;
|
||||
|
||||
hci_pend_le_conn_del(hdev, &cp->addr.bdaddr, addr_type);
|
||||
hci_pend_le_conn_del(hdev, params);
|
||||
list_del(¶ms->list);
|
||||
kfree(params);
|
||||
|
||||
@ -5514,7 +5514,7 @@ static void restart_le_auto_conns(struct hci_dev *hdev)
|
||||
|
||||
list_for_each_entry(p, &hdev->le_conn_params, list) {
|
||||
if (p->auto_connect == HCI_AUTO_CONN_ALWAYS) {
|
||||
hci_pend_le_conn_add(hdev, &p->addr, p->addr_type);
|
||||
hci_pend_le_conn_add(hdev, p);
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user