diff options
-rw-r--r-- | hcid/dbus-adapter.c | 12 | ||||
-rw-r--r-- | hcid/dbus.c | 39 | ||||
-rw-r--r-- | hcid/dbus.h | 6 | ||||
-rw-r--r-- | hcid/security.c | 18 |
4 files changed, 29 insertions, 46 deletions
diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c index c0da1d1a..7a995e83 100644 --- a/hcid/dbus-adapter.c +++ b/hcid/dbus-adapter.c @@ -123,8 +123,7 @@ static struct bonding_request_info *bonding_request_new(bdaddr_t *peer) memset(bonding, 0, sizeof(*bonding)); - bonding->bdaddr = malloc(sizeof(*bonding->bdaddr)); - bacpy(bonding->bdaddr, peer); + bacpy(&bonding->bdaddr, peer); return bonding; } @@ -487,7 +486,7 @@ static DBusHandlerResult handle_dev_list_connections_req(DBusConnection *conn, D bdaddr_t tmp; struct active_conn_info *dev = l->data; - baswap(&tmp, dev->bdaddr); peer_addr = batostr(&tmp); + baswap(&tmp, &dev->bdaddr); peer_addr = batostr(&tmp); dbus_message_iter_append_basic(&array_iter, DBUS_TYPE_STRING, &peer_addr); bt_free(peer_addr); @@ -1572,8 +1571,7 @@ static DBusHandlerResult handle_dev_cancel_bonding_req(DBusConnection *conn, DBu str2ba(peer_addr, &peer_bdaddr); /* check if there is a pending bonding request */ - if ((!dbus_data->bonding) || - (memcmp(dbus_data->bonding->bdaddr, &peer_bdaddr, sizeof(bdaddr_t)))) { + if (!dbus_data->bonding || bacmp(&dbus_data->bonding->bdaddr, &peer_bdaddr)) { error("No bonding request pending."); return error_unknown_address(conn, msg); } @@ -1597,7 +1595,7 @@ static DBusHandlerResult handle_dev_cancel_bonding_req(DBusConnection *conn, DBu memset(&cp, 0, sizeof(cp)); memset(&rp, 0, sizeof(rp)); - bacpy(&cp.bdaddr, dbus_data->bonding->bdaddr); + bacpy(&cp.bdaddr, &dbus_data->bonding->bdaddr); rq.ogf = OGF_LINK_CTL; rq.ocf = OCF_CREATE_CONN_CANCEL; @@ -1992,7 +1990,7 @@ static DBusHandlerResult handle_dev_cancel_discovery_req(DBusConnection *conn, D /* get the first element */ dev = (struct discovered_dev_info *) (dbus_data->disc_devices)->data; - bacpy(&cp.bdaddr, dev->bdaddr); + bacpy(&cp.bdaddr, &dev->bdaddr); rq.ocf = OCF_REMOTE_NAME_REQ_CANCEL; rq.cparam = &cp; diff --git a/hcid/dbus.c b/hcid/dbus.c index 2c159ead..413f6853 100644 --- a/hcid/dbus.c +++ b/hcid/dbus.c @@ -102,16 +102,13 @@ void disc_device_info_free(void *data, void *user_data) { struct discovered_dev_info *dev = data; - if (dev) { - free(dev->bdaddr); + if (dev) free(dev); - } } void bonding_request_free(struct bonding_request_info *dev ) { if (dev) { - free(dev->bdaddr); if (dev->rq) dbus_message_unref(dev->rq); if (dev->cancel) @@ -124,10 +121,8 @@ static void active_conn_info_free(void *data, void *user_data) { struct active_conn_info *dev = data; - if (dev) { - free(dev->bdaddr); + if (dev) free(dev); - } } static int disc_device_find_by_bdaddr(const void *data, const void *user_data) @@ -135,10 +130,7 @@ static int disc_device_find_by_bdaddr(const void *data, const void *user_data) const struct discovered_dev_info *dev = data; const bdaddr_t *bdaddr = user_data; - if (memcmp(dev->bdaddr, bdaddr, sizeof(*bdaddr)) == 0) - return 0; - - return -1; + return bacmp(&dev->bdaddr, bdaddr); } static int disc_device_find_by_name_status(const void *data, const void *user_data) @@ -172,11 +164,11 @@ int disc_device_append(struct slist **list, bdaddr_t *bdaddr, name_status_t name return -1; memset(dev, 0, sizeof(*dev)); - dev->bdaddr = malloc(sizeof(*dev->bdaddr)); - bacpy(dev->bdaddr, bdaddr); + bacpy(&dev->bdaddr, bdaddr); dev->name_status = name_status; *list = slist_append(*list, dev); + return 0; } @@ -191,7 +183,6 @@ static int disc_device_remove(struct slist **list, bdaddr_t *bdaddr) if (l) { dev = l->data; *list = slist_remove(*list, dev); - free(dev->bdaddr); free(dev); ret_val = 0; } @@ -204,10 +195,7 @@ int active_conn_find_by_bdaddr(const void *data, const void *user_data) const struct active_conn_info *con = data; const bdaddr_t *bdaddr = user_data; - if (memcmp(con->bdaddr, bdaddr, sizeof(*bdaddr)) == 0) - return 0; - - return -1; + return bacmp(&con->bdaddr, bdaddr); } static int active_conn_find_by_handle(const void *data, const void *user_data) @@ -230,8 +218,7 @@ static int active_conn_append(struct slist **list, bdaddr_t *bdaddr, uint16_t ha return -1; memset(dev, 0 , sizeof(*dev)); - dev->bdaddr = malloc(sizeof(*dev->bdaddr)); - bacpy(dev->bdaddr, bdaddr); + bacpy(&dev->bdaddr, bdaddr); dev->handle = handle; *list = slist_append(*list, dev); @@ -249,7 +236,6 @@ static int active_conn_remove(struct slist **list, uint16_t *handle) if (l) { dev = l->data; *list = slist_remove(*list, dev); - free(dev->bdaddr); free(dev); ret_val = 0; } @@ -752,7 +738,7 @@ void hcid_dbus_create_conn_cancel(bdaddr_t *local, void *ptr) if (!pdata->bonding) goto failed; - if (memcmp(pdata->bonding->bdaddr, &ret->bdaddr, sizeof(bdaddr_t))) + if (bacmp(&pdata->bonding->bdaddr, &ret->bdaddr)) goto failed; if (!ret->status) { @@ -854,10 +840,10 @@ int disc_device_req_name(struct hci_dbus_data *dbus_data) req_sent = 1; memset(&cp, 0, sizeof(cp)); - bacpy(&cp.bdaddr, dev->bdaddr); + bacpy(&cp.bdaddr, &dev->bdaddr); cp.pscan_rep_mode = 0x02; - baswap(&tmp, dev->bdaddr); peer_addr = batostr(&tmp); + baswap(&tmp, &dev->bdaddr); peer_addr = batostr(&tmp); if (hci_send_req(dd, &rq, 100) < 0) { error("Unable to send the HCI remote name request: %s (%d)", @@ -884,7 +870,6 @@ int disc_device_req_name(struct hci_dbus_data *dbus_data) if (!req_sent) { /* remove the element from the list */ dbus_data->disc_devices = slist_remove(dbus_data->disc_devices, dev); - free(dev->bdaddr); free(dev); /* get the next element */ @@ -1199,7 +1184,7 @@ void hcid_dbus_conn_complete(bdaddr_t *local, uint8_t status, uint16_t handle, b if (!pdata->bonding) goto done; /* skip */ - if (memcmp(pdata->bonding->bdaddr, peer, sizeof(bdaddr_t))) + if (bacmp(&pdata->bonding->bdaddr, peer)) goto done; /* skip */ if (status) { @@ -1289,7 +1274,7 @@ void hcid_dbus_disconn_complete(bdaddr_t *local, uint8_t status, uint16_t handle dev = l->data; /* add in the active connetions list */ - baswap(&tmp, dev->bdaddr); peer_addr = batostr(&tmp); + baswap(&tmp, &dev->bdaddr); peer_addr = batostr(&tmp); /* Sent the remote device disconnected signal */ message = dbus_message_new_signal(path, ADAPTER_INTERFACE, "RemoteDeviceDisconnected"); diff --git a/hcid/dbus.h b/hcid/dbus.h index da2d3af0..57a258ef 100644 --- a/hcid/dbus.h +++ b/hcid/dbus.h @@ -88,19 +88,19 @@ typedef enum { } name_status_t; struct discovered_dev_info { - bdaddr_t *bdaddr; + bdaddr_t bdaddr; name_status_t name_status; }; struct bonding_request_info { - bdaddr_t *bdaddr; + bdaddr_t bdaddr; DBusMessage *rq; DBusMessage *cancel; int disconnect; /* disconnect after finish */ }; struct active_conn_info { - bdaddr_t *bdaddr; + bdaddr_t bdaddr; uint16_t handle; }; diff --git a/hcid/security.c b/hcid/security.c index d2d7ac1e..dabbded0 100644 --- a/hcid/security.c +++ b/hcid/security.c @@ -111,6 +111,7 @@ static int hci_req_find_by_dev(const void *data, const void *user_data) static int check_pending_hci_req(int dev) { + struct hci_req_data *data; struct slist *l; if (!hci_req_queue) @@ -118,20 +119,19 @@ static int check_pending_hci_req(int dev) l = slist_find(hci_req_queue, &dev, hci_req_find_by_dev); - if (l) { - struct hci_req_data *data = l->data; + if (!l) + return -1; - hci_send_cmd(dev, data->ogf, data->ocf, data->clen, data->cparam); + data = l->data; - hci_req_queue = slist_remove(hci_req_queue, data); + hci_send_cmd(dev, data->ogf, data->ocf, data->clen, data->cparam); - free(data->cparam); - free(data); + hci_req_queue = slist_remove(hci_req_queue, data); - return 0; - } + free(data->cparam); + free(data); - return -1; + return 0; } static inline int get_bdaddr(int dev, bdaddr_t *sba, uint16_t handle, bdaddr_t *dba) |