From 6b9921107e0346f0fc6f5475b0dea17f65dc94ce Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Sun, 19 Dec 2010 16:50:27 +0200 Subject: [PATCH] Get rid of unneeded btd_adapter_get_conn_handle function --- health/mcap_sync.c | 10 ++++---- plugins/hciops.c | 68 +++++++++++++++++++++++++++++------------------------- plugins/mgmtops.c | 13 +++-------- src/adapter.c | 16 ++----------- src/adapter.h | 7 ++---- 5 files changed, 48 insertions(+), 66 deletions(-) diff --git a/health/mcap_sync.c b/health/mcap_sync.c index a7f6adb45..6f903448a 100644 --- a/health/mcap_sync.c +++ b/health/mcap_sync.c @@ -246,7 +246,7 @@ static gboolean valid_btclock(uint32_t btclk) static gboolean read_btclock(struct mcap_mcl *mcl, uint32_t *btclock, uint16_t *btaccuracy) { - int ret, handle, which = 1; + int which = 1; struct btd_adapter *adapter; adapter = manager_find_adapter(&mcl->mi->src); @@ -254,13 +254,11 @@ static gboolean read_btclock(struct mcap_mcl *mcl, uint32_t *btclock, if (!adapter) return FALSE; - if (btd_adapter_get_conn_handle(adapter, &mcl->addr, &handle)) + if (btd_adapter_read_clock(adapter, &mcl->addr, which, 1000, + btclock, btaccuracy) < 0) return FALSE; - ret = btd_adapter_read_clock(adapter, handle, which, 1000, btclock, - btaccuracy); - - return ret < 0 ? FALSE : TRUE; + return TRUE; } static gboolean read_btclock_retry(struct mcap_mcl *mcl, uint32_t *btclock, diff --git a/plugins/hciops.c b/plugins/hciops.c index 65b7422dc..62c6684f3 100644 --- a/plugins/hciops.c +++ b/plugins/hciops.c @@ -613,6 +613,33 @@ static inline int get_bdaddr(int index, uint16_t handle, bdaddr_t *dba) return -ENOENT; } +static int get_handle(int index, const bdaddr_t *bdaddr, uint16_t *handle) +{ + struct dev_info *dev = &devs[index]; + struct hci_conn_info_req *cr; + char addr[18]; + int err; + + ba2str(bdaddr, addr); + DBG("hci%d dba %s", index, addr); + + cr = g_malloc0(sizeof(*cr) + sizeof(struct hci_conn_info)); + bacpy(&cr->bdaddr, bdaddr); + cr->type = ACL_LINK; + + if (ioctl(dev->sk, HCIGETCONNINFO, (unsigned long) cr) < 0) { + err = -errno; + goto fail; + } + + err = 0; + *handle = cr->conn_info->handle; + +fail: + g_free(cr); + return err; +} + /* Link Key handling */ static void link_key_request(int index, bdaddr_t *dba) @@ -2704,14 +2731,21 @@ static int hciops_fast_connectable(int index, gboolean enable) return 0; } -static int hciops_read_clock(int index, uint16_t handle, int which, +static int hciops_read_clock(int index, bdaddr_t *bdaddr, int which, int timeout, uint32_t *clock, uint16_t *accuracy) { struct dev_info *dev = &devs[index]; + uint16_t handle = 0; + char addr[18]; + int ret; - DBG("hci%d handle %d which %d timeout %d", index, handle, which, - timeout); + ba2str(bdaddr, addr); + DBG("hci%d addr %s which %d timeout %d", index, addr, which, timeout); + + ret = get_handle(index, bdaddr, &handle); + if (ret < 0) + return ret; if (hci_read_clock(dev->sk, htobs(handle), which, clock, accuracy, timeout) < 0) @@ -2720,33 +2754,6 @@ static int hciops_read_clock(int index, uint16_t handle, int which, return 0; } -static int hciops_conn_handle(int index, const bdaddr_t *bdaddr, int *handle) -{ - struct dev_info *dev = &devs[index]; - struct hci_conn_info_req *cr; - char addr[18]; - int err; - - ba2str(bdaddr, addr); - DBG("hci%d dba %s", index, addr); - - cr = g_malloc0(sizeof(*cr) + sizeof(struct hci_conn_info)); - bacpy(&cr->bdaddr, bdaddr); - cr->type = ACL_LINK; - - if (ioctl(dev->sk, HCIGETCONNINFO, (unsigned long) cr) < 0) { - err = -errno; - goto fail; - } - - err = 0; - *handle = cr->conn_info->handle; - -fail: - g_free(cr); - return err; -} - static int hciops_read_bdaddr(int index, bdaddr_t *bdaddr) { struct dev_info *dev = &devs[index]; @@ -3212,7 +3219,6 @@ static struct btd_adapter_ops hci_ops = { .set_dev_class = hciops_set_dev_class, .set_fast_connectable = hciops_fast_connectable, .read_clock = hciops_read_clock, - .get_conn_handle = hciops_conn_handle, .read_bdaddr = hciops_read_bdaddr, .block_device = hciops_block_device, .unblock_device = hciops_unblock_device, diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c index c72885959..e640fa708 100644 --- a/plugins/mgmtops.c +++ b/plugins/mgmtops.c @@ -580,20 +580,14 @@ static int mgmt_fast_connectable(int index, gboolean enable) return -ENOSYS; } -static int mgmt_read_clock(int index, uint16_t handle, int which, int timeout, +static int mgmt_read_clock(int index, bdaddr_t *bdaddr, int which, int timeout, uint32_t *clock, uint16_t *accuracy) { - DBG("index %d handle %d which %d timeout %d", index, handle, - which, timeout); - return -ENOSYS; -} - -static int mgmt_conn_handle(int index, const bdaddr_t *bdaddr, int *handle) -{ char addr[18]; ba2str(bdaddr, addr); - DBG("index %d addr %s", index, addr); + DBG("index %d addr %s which %d timeout %d", index, addr, which, + timeout); return -ENOSYS; } @@ -807,7 +801,6 @@ static struct btd_adapter_ops mgmt_ops = { .set_dev_class = mgmt_set_dev_class, .set_fast_connectable = mgmt_fast_connectable, .read_clock = mgmt_read_clock, - .get_conn_handle = mgmt_conn_handle, .read_bdaddr = mgmt_read_bdaddr, .block_device = mgmt_block_device, .unblock_device = mgmt_unblock_device, diff --git a/src/adapter.c b/src/adapter.c index 4038efb6b..669a0acc0 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -3307,7 +3307,7 @@ int btd_adapter_set_fast_connectable(struct btd_adapter *adapter, return adapter_ops->set_fast_connectable(adapter->dev_id, enable); } -int btd_adapter_read_clock(struct btd_adapter *adapter, uint16_t handle, +int btd_adapter_read_clock(struct btd_adapter *adapter, bdaddr_t *bdaddr, int which, int timeout, uint32_t *clock, uint16_t *accuracy) { @@ -3317,22 +3317,10 @@ int btd_adapter_read_clock(struct btd_adapter *adapter, uint16_t handle, if (!adapter->up) return -EINVAL; - return adapter_ops->read_clock(adapter->dev_id, handle, which, + return adapter_ops->read_clock(adapter->dev_id, bdaddr, which, timeout, clock, accuracy); } -int btd_adapter_get_conn_handle(struct btd_adapter *adapter, - const bdaddr_t *bdaddr, int *handle) -{ - if (!adapter_ops) - return -EINVAL; - - if (!adapter->up) - return -EINVAL; - - return adapter_ops->get_conn_handle(adapter->dev_id, bdaddr, handle); -} - int btd_adapter_disconnect_device(struct btd_adapter *adapter, uint16_t handle) { return adapter_ops->disconnect(adapter->dev_id, handle); diff --git a/src/adapter.h b/src/adapter.h index ec3b21d5e..a3900889f 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -215,9 +215,8 @@ struct btd_adapter_ops { int (*set_name) (int index, const char *name); int (*set_dev_class) (int index, uint8_t major, uint8_t minor); int (*set_fast_connectable) (int index, gboolean enable); - int (*read_clock) (int index, uint16_t handle, int which, int timeout, + int (*read_clock) (int index, bdaddr_t *bdaddr, int which, int timeout, uint32_t *clock, uint16_t *accuracy); - int (*get_conn_handle) (int index, const bdaddr_t *bdaddr, int *handle); int (*read_bdaddr) (int index, bdaddr_t *bdaddr); int (*block_device) (int index, bdaddr_t *bdaddr); int (*unblock_device) (int index, bdaddr_t *bdaddr); @@ -260,11 +259,9 @@ void btd_adapter_unregister_powered_callback(struct btd_adapter *adapter, int btd_adapter_set_fast_connectable(struct btd_adapter *adapter, gboolean enable); -int btd_adapter_read_clock(struct btd_adapter *adapter, uint16_t handle, +int btd_adapter_read_clock(struct btd_adapter *adapter, bdaddr_t *bdaddr, int which, int timeout, uint32_t *clock, uint16_t *accuracy); -int btd_adapter_get_conn_handle(struct btd_adapter *adapter, - const bdaddr_t *bdaddr, int *handle); int btd_adapter_block_address(struct btd_adapter *adapter, bdaddr_t *bdaddr); int btd_adapter_unblock_address(struct btd_adapter *adapter, bdaddr_t *bdaddr); -- 2.11.0