mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-11-16 08:44:38 +08:00
Move connection list fetching to hciops
This commit is contained in:
parent
885c513fdf
commit
f7b4b3fcd1
@ -915,6 +915,39 @@ static int hciops_unblock_device(int index, bdaddr_t *bdaddr)
|
||||
return err;
|
||||
}
|
||||
|
||||
static int hciops_get_conn_list(int index, GSList **conns)
|
||||
{
|
||||
struct hci_conn_list_req *cl;
|
||||
struct hci_conn_info *ci;
|
||||
int dd, err, i;
|
||||
|
||||
dd = hci_open_dev(index);
|
||||
if (dd < 0)
|
||||
return -errno;
|
||||
|
||||
cl = g_malloc0(10 * sizeof(*ci) + sizeof(*cl));
|
||||
|
||||
cl->dev_id = index;
|
||||
cl->conn_num = 10;
|
||||
ci = cl->conn_info;
|
||||
|
||||
if (ioctl(dd, HCIGETCONNLIST, cl) < 0) {
|
||||
err = -errno;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
err = 0;
|
||||
*conns = NULL;
|
||||
|
||||
for (i = 0; i < cl->conn_num; i++, ci++)
|
||||
*conns = g_slist_append(*conns, g_memdup(ci, sizeof(*ci)));
|
||||
|
||||
fail:
|
||||
hci_close_dev(dd);
|
||||
g_free(cl);
|
||||
return err;
|
||||
}
|
||||
|
||||
static struct btd_adapter_ops hci_ops = {
|
||||
.setup = hciops_setup,
|
||||
.cleanup = hciops_cleanup,
|
||||
@ -941,6 +974,7 @@ static struct btd_adapter_ops hci_ops = {
|
||||
.read_inq_tx_pwr = hciops_read_inq_tx_pwr,
|
||||
.block_device = hciops_block_device,
|
||||
.unblock_device = hciops_unblock_device,
|
||||
.get_conn_list = hciops_get_conn_list,
|
||||
};
|
||||
|
||||
static int hciops_init(void)
|
||||
|
@ -2119,27 +2119,18 @@ static void load_drivers(struct btd_adapter *adapter)
|
||||
|
||||
static void load_connections(struct btd_adapter *adapter)
|
||||
{
|
||||
struct hci_conn_list_req *cl = NULL;
|
||||
struct hci_conn_info *ci;
|
||||
int i, dd;
|
||||
GSList *l, *conns;
|
||||
int err;
|
||||
|
||||
dd = hci_open_dev(adapter->dev_id);
|
||||
if (dd < 0)
|
||||
return;
|
||||
|
||||
cl = g_malloc0(10 * sizeof(*ci) + sizeof(*cl));
|
||||
|
||||
cl->dev_id = adapter->dev_id;
|
||||
cl->conn_num = 10;
|
||||
ci = cl->conn_info;
|
||||
|
||||
if (ioctl(dd, HCIGETCONNLIST, cl) != 0) {
|
||||
g_free(cl);
|
||||
hci_close_dev(dd);
|
||||
err = adapter_ops->get_conn_list(adapter->dev_id, &conns);
|
||||
if (err < 0) {
|
||||
error("Unable to fetch existing connections: %s (%d)",
|
||||
strerror(-err), -err);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < cl->conn_num; i++, ci++) {
|
||||
for (l = conns; l != NULL; l = g_slist_next(l)) {
|
||||
struct hci_conn_info *ci = l->data;
|
||||
struct btd_device *device;
|
||||
char address[18];
|
||||
|
||||
@ -2149,8 +2140,8 @@ static void load_connections(struct btd_adapter *adapter)
|
||||
adapter_add_connection(adapter, device, ci->handle);
|
||||
}
|
||||
|
||||
g_free(cl);
|
||||
hci_close_dev(dd);
|
||||
g_slist_foreach(conns, (GFunc) g_free, NULL);
|
||||
g_slist_free(conns);
|
||||
}
|
||||
|
||||
static int get_discoverable_timeout(const char *src)
|
||||
|
@ -197,6 +197,7 @@ struct btd_adapter_ops {
|
||||
int (*read_inq_tx_pwr) (int index);
|
||||
int (*block_device) (int index, bdaddr_t *bdaddr);
|
||||
int (*unblock_device) (int index, bdaddr_t *bdaddr);
|
||||
int (*get_conn_list) (int index, GSList **conns);
|
||||
};
|
||||
|
||||
int btd_register_adapter_ops(struct btd_adapter_ops *btd_adapter_ops);
|
||||
|
Loading…
Reference in New Issue
Block a user