diff options
author | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2006-10-04 19:11:04 +0000 |
---|---|---|
committer | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2006-10-04 19:11:04 +0000 |
commit | 646a24a13d9ec1acffc52d7c8dba0efed1d2da1a (patch) | |
tree | f3eb80e65c168235c38f1291e446a09a5411ad9f /hcid | |
parent | 4b3a8ada4a341ebb9468a207fa892a71746da502 (diff) |
cleanup:renamed hci_dbus_data to adapter
Diffstat (limited to 'hcid')
-rw-r--r-- | hcid/dbus-adapter.c | 396 | ||||
-rw-r--r-- | hcid/dbus-rfcomm.c | 42 | ||||
-rw-r--r-- | hcid/dbus-sdp.c | 42 | ||||
-rw-r--r-- | hcid/dbus-security.c | 30 | ||||
-rw-r--r-- | hcid/dbus-test.c | 12 | ||||
-rw-r--r-- | hcid/dbus.c | 640 | ||||
-rw-r--r-- | hcid/dbus.h | 20 |
7 files changed, 591 insertions, 591 deletions
diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c index fbb913d3..34eaffc2 100644 --- a/hcid/dbus-adapter.c +++ b/hcid/dbus-adapter.c @@ -165,7 +165,7 @@ static const char *toy_minor_cls[] = { "game" }; -int pending_remote_name_cancel(struct hci_dbus_data *pdata) +int pending_remote_name_cancel(struct adapter *adapter) { struct discovered_dev_info *dev, match; struct slist *l; @@ -176,11 +176,11 @@ int pending_remote_name_cancel(struct hci_dbus_data *pdata) bacpy(&match.bdaddr, BDADDR_ANY); match.name_status = NAME_REQUESTED; - l = slist_find(pdata->disc_devices, &match, (cmp_func_t) disc_device_find); + l = slist_find(adapter->disc_devices, &match, (cmp_func_t) disc_device_find); if (!l) /* no pending request */ return 0; - dd = hci_open_dev(pdata->dev_id); + dd = hci_open_dev(adapter->dev_id); if (dd < 0) return -ENODEV; @@ -192,9 +192,9 @@ int pending_remote_name_cancel(struct hci_dbus_data *pdata) } /* free discovered devices list */ - slist_foreach(pdata->disc_devices, (slist_func_t) free, NULL); - slist_free(pdata->disc_devices); - pdata->disc_devices = NULL; + slist_foreach(adapter->disc_devices, (slist_func_t) free, NULL); + slist_free(adapter->disc_devices); + adapter->disc_devices = NULL; hci_close_dev(dd); return err; @@ -222,8 +222,8 @@ static struct bonding_request_info *bonding_request_new(bdaddr_t *peer, DBusConn static DBusHandlerResult handle_dev_get_address_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; - const char *paddr = dbus_data->address; + struct adapter *adapter = data; + const char *paddr = adapter->address; DBusMessage *reply; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) @@ -241,7 +241,7 @@ static DBusHandlerResult handle_dev_get_address_req(DBusConnection *conn, DBusMe static DBusHandlerResult handle_dev_get_version_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply; char str[20], *str_ptr = str; int err; @@ -249,7 +249,7 @@ static DBusHandlerResult handle_dev_get_version_req(DBusConnection *conn, DBusMe if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) return error_invalid_arguments(conn, msg); - err = get_device_version(dbus_data->dev_id, str, sizeof(str)); + err = get_device_version(adapter->dev_id, str, sizeof(str)); if (err < 0) return error_failed(conn, msg, -err); @@ -265,7 +265,7 @@ static DBusHandlerResult handle_dev_get_version_req(DBusConnection *conn, DBusMe static DBusHandlerResult handle_dev_get_revision_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply; char str[64], *str_ptr = str; int err; @@ -273,7 +273,7 @@ static DBusHandlerResult handle_dev_get_revision_req(DBusConnection *conn, DBusM if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) return error_invalid_arguments(conn, msg); - err = get_device_revision(dbus_data->dev_id, str, sizeof(str)); + err = get_device_revision(adapter->dev_id, str, sizeof(str)); if (err < 0) return error_failed(conn, msg, -err); @@ -289,7 +289,7 @@ static DBusHandlerResult handle_dev_get_revision_req(DBusConnection *conn, DBusM static DBusHandlerResult handle_dev_get_manufacturer_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply; char str[64], *str_ptr = str; int err; @@ -297,7 +297,7 @@ static DBusHandlerResult handle_dev_get_manufacturer_req(DBusConnection *conn, D if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) return error_invalid_arguments(conn, msg); - err = get_device_manufacturer(dbus_data->dev_id, str, sizeof(str)); + err = get_device_manufacturer(adapter->dev_id, str, sizeof(str)); if (err < 0) return error_failed(conn, msg, -err); @@ -313,7 +313,7 @@ static DBusHandlerResult handle_dev_get_manufacturer_req(DBusConnection *conn, D static DBusHandlerResult handle_dev_get_company_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply; char str[64], *str_ptr = str; int err; @@ -321,7 +321,7 @@ static DBusHandlerResult handle_dev_get_company_req(DBusConnection *conn, DBusMe if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) return error_invalid_arguments(conn, msg); - err = get_device_company(dbus_data->dev_id, str, sizeof(str)); + err = get_device_company(adapter->dev_id, str, sizeof(str)); if (err < 0) return error_failed(conn, msg, -err); @@ -337,9 +337,9 @@ static DBusHandlerResult handle_dev_get_company_req(DBusConnection *conn, DBusMe static DBusHandlerResult handle_dev_get_mode_req(DBusConnection *conn, DBusMessage *msg, void *data) { - const struct hci_dbus_data *dbus_data = data; + const struct adapter *adapter = data; DBusMessage *reply = NULL; - const uint8_t hci_mode = dbus_data->mode; + const uint8_t hci_mode = adapter->mode; const char *scan_mode; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) @@ -374,12 +374,12 @@ static DBusHandlerResult handle_dev_get_mode_req(DBusConnection *conn, DBusMessa static DBusHandlerResult handle_dev_set_mode_req(DBusConnection *conn, DBusMessage *msg, void *data) { - const struct hci_dbus_data *dbus_data = data; + const struct adapter *adapter = data; DBusMessage *reply; DBusError err; const char* scan_mode; uint8_t hci_mode; - const uint8_t current_mode = dbus_data->mode; + const uint8_t current_mode = adapter->mode; int dd; dbus_error_init(&err); @@ -405,25 +405,25 @@ static DBusHandlerResult handle_dev_set_mode_req(DBusConnection *conn, DBusMessa else return error_invalid_arguments(conn, msg); - dd = hci_open_dev(dbus_data->dev_id); + dd = hci_open_dev(adapter->dev_id); if (dd < 0) return error_no_such_adapter(conn, msg); - if (!dbus_data->up) { + if (!adapter->up) { bdaddr_t local; - str2ba(dbus_data->address, &local); + str2ba(adapter->address, &local); /* The new value will be loaded when the adapter comes UP */ write_device_mode(&local, scan_mode); /* Start HCI device */ - if (ioctl(dd, HCIDEVUP, dbus_data->dev_id) == 0) + if (ioctl(dd, HCIDEVUP, adapter->dev_id) == 0) goto done; /* on success */ if (errno != EALREADY) { int err = errno; error("Can't init device hci%d: %s (%d)\n", - dbus_data->dev_id, strerror(errno), errno); + adapter->dev_id, strerror(errno), errno); hci_close_dev(dd); return error_failed(conn, msg, err); @@ -471,7 +471,7 @@ done: static DBusHandlerResult handle_dev_get_discoverable_to_req(DBusConnection *conn, DBusMessage *msg, void *data) { - const struct hci_dbus_data *dbus_data = data; + const struct adapter *adapter = data; DBusMessage *reply; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) @@ -481,7 +481,7 @@ static DBusHandlerResult handle_dev_get_discoverable_to_req(DBusConnection *conn if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; - dbus_message_append_args(reply, DBUS_TYPE_UINT32, &dbus_data->discoverable_timeout, + dbus_message_append_args(reply, DBUS_TYPE_UINT32, &adapter->discoverable_timeout, DBUS_TYPE_INVALID); return send_reply_and_unref(conn, reply); @@ -489,13 +489,13 @@ static DBusHandlerResult handle_dev_get_discoverable_to_req(DBusConnection *conn static DBusHandlerResult handle_dev_set_discoverable_to_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply; DBusError err; uint32_t timeout; bdaddr_t bdaddr; - if (!dbus_data->up) + if (!adapter->up) return error_not_ready(conn, msg); dbus_error_init(&err); @@ -513,17 +513,17 @@ static DBusHandlerResult handle_dev_set_discoverable_to_req(DBusConnection *conn if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; - if (dbus_data->timeout_id) { - g_timeout_remove(dbus_data->timeout_id); - dbus_data->timeout_id = 0; + if (adapter->timeout_id) { + g_timeout_remove(adapter->timeout_id); + adapter->timeout_id = 0; } - if ((timeout != 0) && (dbus_data->mode & SCAN_INQUIRY)) - dbus_data->timeout_id = g_timeout_add(timeout * 1000, discoverable_timeout_handler, dbus_data); + if ((timeout != 0) && (adapter->mode & SCAN_INQUIRY)) + adapter->timeout_id = g_timeout_add(timeout * 1000, discoverable_timeout_handler, adapter); - dbus_data->discoverable_timeout = timeout; + adapter->discoverable_timeout = timeout; - str2ba(dbus_data->address, &bdaddr); + str2ba(adapter->address, &bdaddr); write_discoverable_timeout(&bdaddr, timeout); return send_reply_and_unref(conn, reply); @@ -531,9 +531,9 @@ static DBusHandlerResult handle_dev_set_discoverable_to_req(DBusConnection *conn static DBusHandlerResult handle_dev_is_connectable_req(DBusConnection *conn, DBusMessage *msg, void *data) { - const struct hci_dbus_data *dbus_data = data; + const struct adapter *adapter = data; DBusMessage *reply; - const uint8_t hci_mode = dbus_data->mode; + const uint8_t hci_mode = adapter->mode; dbus_bool_t connectable = FALSE; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) @@ -554,9 +554,9 @@ static DBusHandlerResult handle_dev_is_connectable_req(DBusConnection *conn, DBu static DBusHandlerResult handle_dev_is_discoverable_req(DBusConnection *conn, DBusMessage *msg, void *data) { - const struct hci_dbus_data *dbus_data = data; + const struct adapter *adapter = data; DBusMessage *reply; - const uint8_t hci_mode = dbus_data->mode; + const uint8_t hci_mode = adapter->mode; dbus_bool_t discoverable = FALSE; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) @@ -581,8 +581,8 @@ static DBusHandlerResult handle_dev_is_connected_req(DBusConnection *conn, DBusM DBusError err; dbus_bool_t connected = FALSE; - struct hci_dbus_data *dbus_data = data; - struct slist *l = dbus_data->active_conn; + struct adapter *adapter = data; + struct slist *l = adapter->active_conn; const char *peer_addr; bdaddr_t peer_bdaddr; @@ -622,8 +622,8 @@ static DBusHandlerResult handle_dev_list_connections_req(DBusConnection *conn, D DBusMessage *reply; DBusMessageIter iter; DBusMessageIter array_iter; - struct hci_dbus_data *dbus_data = data; - struct slist *l = dbus_data->active_conn; + struct adapter *adapter = data; + struct slist *l = adapter->active_conn; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) return error_invalid_arguments(conn, msg); @@ -656,7 +656,7 @@ static DBusHandlerResult handle_dev_list_connections_req(DBusConnection *conn, D static DBusHandlerResult handle_dev_get_major_class_req(DBusConnection *conn, DBusMessage *msg, void *data) { - const struct hci_dbus_data *dbus_data = data; + const struct adapter *adapter = data; DBusMessage *reply; const char *str_ptr = "computer"; uint8_t cls[3]; @@ -669,14 +669,14 @@ static DBusHandlerResult handle_dev_get_major_class_req(DBusConnection *conn, DB if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; - dd = hci_open_dev(dbus_data->dev_id); + dd = hci_open_dev(adapter->dev_id); if (dd < 0) return error_no_such_adapter(conn, msg); if (hci_read_class_of_dev(dd, cls, 1000) < 0) { int err = errno; error("Can't read class of device on hci%d: %s(%d)", - dbus_data->dev_id, strerror(errno), errno); + adapter->dev_id, strerror(errno), errno); hci_close_dev(dd); return error_failed(conn, msg, err); } @@ -695,7 +695,7 @@ static DBusHandlerResult handle_dev_get_major_class_req(DBusConnection *conn, DB static DBusHandlerResult handle_dev_list_minor_classes_req(DBusConnection *conn, DBusMessage *msg, void *data) { - const struct hci_dbus_data *dbus_data = data; + const struct adapter *adapter = data; DBusMessage *reply = NULL; DBusMessageIter iter; DBusMessageIter array_iter; @@ -704,20 +704,20 @@ static DBusHandlerResult handle_dev_list_minor_classes_req(DBusConnection *conn, uint8_t major_class; int dd, size, i; - if (!dbus_data->up) + if (!adapter->up) return error_not_ready(conn, msg); if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) return error_invalid_arguments(conn, msg); - dd = hci_open_dev(dbus_data->dev_id); + dd = hci_open_dev(adapter->dev_id); if (dd < 0) return error_no_such_adapter(conn, msg); if (hci_read_class_of_dev(dd, cls, 1000) < 0) { int err = errno; error("Can't read class of device on hci%d: %s(%d)", - dbus_data->dev_id, strerror(errno), errno); + adapter->dev_id, strerror(errno), errno); hci_close_dev(dd); return error_failed(conn, msg, err); } @@ -756,27 +756,27 @@ static DBusHandlerResult handle_dev_list_minor_classes_req(DBusConnection *conn, static DBusHandlerResult handle_dev_get_minor_class_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply; const char *str_ptr = ""; uint8_t cls[3]; uint8_t minor_class; int dd; - if (!dbus_data->up) + if (!adapter->up) return error_not_ready(conn, msg); if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) return error_invalid_arguments(conn, msg); - dd = hci_open_dev(dbus_data->dev_id); + dd = hci_open_dev(adapter->dev_id); if (dd < 0) return error_no_such_adapter(conn, msg); if (hci_read_class_of_dev(dd, cls, 1000) < 0) { int err = errno; error("Can't read class of device on hci%d: %s(%d)", - dbus_data->dev_id, strerror(errno), errno); + adapter->dev_id, strerror(errno), errno); hci_close_dev(dd); return error_failed(conn, msg, err); } @@ -808,7 +808,7 @@ failed: static DBusHandlerResult handle_dev_set_minor_class_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply, *signal; DBusError err; bdaddr_t bdaddr; @@ -817,7 +817,7 @@ static DBusHandlerResult handle_dev_set_minor_class_req(DBusConnection *conn, DB uint32_t dev_class = 0xFFFFFFFF; int i, dd; - if (!dbus_data->up) + if (!adapter->up) return error_not_ready(conn, msg); dbus_error_init(&err); @@ -834,14 +834,14 @@ static DBusHandlerResult handle_dev_set_minor_class_req(DBusConnection *conn, DB if (!minor) return error_invalid_arguments(conn, msg); - dd = hci_open_dev(dbus_data->dev_id); + dd = hci_open_dev(adapter->dev_id); if (dd < 0) return error_no_such_adapter(conn, msg); if (hci_read_class_of_dev(dd, cls, 1000) < 0) { int err = errno; error("Can't read class of device on hci%d: %s(%d)", - dbus_data->dev_id, strerror(errno), errno); + adapter->dev_id, strerror(errno), errno); hci_close_dev(dd); return error_failed(conn, msg, err); } @@ -867,19 +867,19 @@ static DBusHandlerResult handle_dev_set_minor_class_req(DBusConnection *conn, DB /* set the service class and major class */ dev_class |= (cls[2] << 16) | (cls[1] << 8); - hci_devba(dbus_data->dev_id, &bdaddr); + hci_devba(adapter->dev_id, &bdaddr); write_local_class(&bdaddr, cls); if (hci_write_class_of_dev(dd, dev_class, 2000) < 0) { int err = errno; error("Can't write class of device on hci%d: %s(%d)", - dbus_data->dev_id, strerror(errno), errno); + adapter->dev_id, strerror(errno), errno); hci_close_dev(dd); return error_failed(conn, msg, err); } - signal = dev_signal_factory(dbus_data->dev_id, "MinorClassChanged", + signal = dev_signal_factory(adapter->dev_id, "MinorClassChanged", DBUS_TYPE_STRING, &minor, DBUS_TYPE_INVALID); send_reply_and_unref(conn, signal); @@ -893,7 +893,7 @@ static DBusHandlerResult handle_dev_set_minor_class_req(DBusConnection *conn, DB static DBusHandlerResult handle_dev_get_service_classes_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply; DBusMessageIter iter; DBusMessageIter array_iter; @@ -901,20 +901,20 @@ static DBusHandlerResult handle_dev_get_service_classes_req(DBusConnection *conn uint8_t cls[3]; int dd, i; - if (!dbus_data->up) + if (!adapter->up) return error_not_ready(conn, msg); if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) return error_invalid_arguments(conn, msg); - dd = hci_open_dev(dbus_data->dev_id); + dd = hci_open_dev(adapter->dev_id); if (dd < 0) return error_no_such_adapter(conn, msg); if (hci_read_class_of_dev(dd, cls, 1000) < 0) { int err = errno; error("Can't read class of device on hci%d: %s(%d)", - dbus_data->dev_id, strerror(errno), errno); + adapter->dev_id, strerror(errno), errno); hci_close_dev(dd); return error_failed(conn, msg, err); } @@ -943,7 +943,7 @@ static DBusHandlerResult handle_dev_get_service_classes_req(DBusConnection *conn static DBusHandlerResult handle_dev_get_name_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply; char str[249], *str_ptr = str; int err; @@ -952,14 +952,14 @@ static DBusHandlerResult handle_dev_get_name_req(DBusConnection *conn, DBusMessa if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) return error_invalid_arguments(conn, msg); - str2ba(dbus_data->address, &ba); + str2ba(adapter->address, &ba); err = read_local_name(&ba, str); if (err < 0) { - if (!dbus_data->up) + if (!adapter->up) return error_not_ready(conn, msg); - err = get_device_name(dbus_data->dev_id, str, sizeof(str)); + err = get_device_name(adapter->dev_id, str, sizeof(str)); if (err < 0) return error_failed(conn, msg, -err); } @@ -976,14 +976,14 @@ static DBusHandlerResult handle_dev_get_name_req(DBusConnection *conn, DBusMessa static DBusHandlerResult handle_dev_set_name_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply; DBusError err; bdaddr_t bdaddr; char *str_ptr; int ecode; - if (!dbus_data->up) + if (!adapter->up) return error_not_ready(conn, msg); dbus_error_init(&err); @@ -1002,11 +1002,11 @@ static DBusHandlerResult handle_dev_set_name_req(DBusConnection *conn, DBusMessa return error_invalid_arguments(conn, msg); } - hci_devba(dbus_data->dev_id, &bdaddr); + hci_devba(adapter->dev_id, &bdaddr); write_local_name(&bdaddr, str_ptr); - ecode = set_device_name(dbus_data->dev_id, str_ptr); + ecode = set_device_name(adapter->dev_id, str_ptr); if (ecode < 0) return error_failed(conn, msg, -ecode); @@ -1029,7 +1029,7 @@ static DBusHandlerResult handle_dev_get_remote_svc_handles(DBusConnection *conn, static DBusHandlerResult handle_dev_get_remote_version_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply; DBusError err; char filename[PATH_MAX + 1]; @@ -1056,7 +1056,7 @@ static DBusHandlerResult handle_dev_get_remote_version_req(DBusConnection *conn, if (check_address(addr_ptr) < 0) return error_invalid_arguments(conn, msg); - create_name(filename, PATH_MAX, STORAGEDIR, dbus_data->address, "manufacturers"); + create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "manufacturers"); str = textfile_caseget(filename, addr_ptr); if (!str) @@ -1075,7 +1075,7 @@ static DBusHandlerResult handle_dev_get_remote_version_req(DBusConnection *conn, /* default value */ snprintf(info, 64, "Bluetooth %s", str_ver); - create_name(filename, PATH_MAX, STORAGEDIR, dbus_data->address, "features"); + create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "features"); str = textfile_caseget(filename, addr_ptr); if (!str) @@ -1105,7 +1105,7 @@ failed: static DBusHandlerResult handle_dev_get_remote_revision_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply; DBusError err; char filename[PATH_MAX + 1]; @@ -1134,7 +1134,7 @@ static DBusHandlerResult handle_dev_get_remote_revision_req(DBusConnection *conn if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; - create_name(filename, PATH_MAX, STORAGEDIR, dbus_data->address, "manufacturers"); + create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "manufacturers"); str = textfile_caseget(filename, addr_ptr); if (!str) @@ -1153,7 +1153,7 @@ static DBusHandlerResult handle_dev_get_remote_revision_req(DBusConnection *conn static DBusHandlerResult handle_dev_get_remote_manufacturer_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply; DBusError err; char filename[PATH_MAX + 1]; @@ -1177,7 +1177,7 @@ static DBusHandlerResult handle_dev_get_remote_manufacturer_req(DBusConnection * if (check_address(addr_ptr) < 0) return error_invalid_arguments(conn, msg); - create_name(filename, PATH_MAX, STORAGEDIR, dbus_data->address, "manufacturers"); + create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "manufacturers"); str = textfile_caseget(filename, addr_ptr); if (!str) @@ -1239,7 +1239,7 @@ static DBusHandlerResult handle_dev_get_remote_company_req(DBusConnection *conn, static int get_remote_class(DBusConnection *conn, DBusMessage *msg, void *data, uint32_t *class) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; char *addr_peer; DBusError err; bdaddr_t local, peer; @@ -1263,7 +1263,7 @@ static int get_remote_class(DBusConnection *conn, DBusMessage *msg, void *data, } str2ba(addr_peer, &peer); - str2ba(dbus_data->address, &local); + str2ba(adapter->address, &local); ecode = read_remote_class(&local, &peer, class); if (ecode < 0) { @@ -1371,7 +1371,7 @@ static DBusHandlerResult handle_dev_get_remote_class_req(DBusConnection *conn, D static DBusHandlerResult handle_dev_get_remote_name_req(DBusConnection *conn, DBusMessage *msg, void *data) { char filename[PATH_MAX + 1]; - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply = NULL; DBusError err; const char *peer_addr; @@ -1393,7 +1393,7 @@ static DBusHandlerResult handle_dev_get_remote_name_req(DBusConnection *conn, DB return error_invalid_arguments(conn, msg); /* check if it is in the cache */ - create_name(filename, PATH_MAX, STORAGEDIR, dbus_data->address, "names"); + create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "names"); str = textfile_caseget(filename, peer_addr); @@ -1412,26 +1412,26 @@ static DBusHandlerResult handle_dev_get_remote_name_req(DBusConnection *conn, DB return send_reply_and_unref(conn, reply); } - if (!dbus_data->up) + if (!adapter->up) return error_not_ready(conn, msg); /* put the request name in the queue to resolve name */ str2ba(peer_addr, &peer_bdaddr); - disc_device_append(&dbus_data->disc_devices, &peer_bdaddr, NAME_REQUIRED); + disc_device_append(&adapter->disc_devices, &peer_bdaddr, NAME_REQUIRED); /* * if there is a discover process running, just queue the request. * Otherwise, send the HCI cmd to get the remote name */ - if (!(dbus_data->disc_active || dbus_data->pdisc_active)) - disc_device_req_name(dbus_data); + if (!(adapter->disc_active || adapter->pdisc_active)) + disc_device_req_name(adapter); return error_request_deferred(conn, msg); } static DBusHandlerResult handle_dev_get_remote_alias_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply; DBusError err; char str[249], *str_ptr = str, *addr_ptr; @@ -1454,7 +1454,7 @@ static DBusHandlerResult handle_dev_get_remote_alias_req(DBusConnection *conn, D str2ba(addr_ptr, &bdaddr); - ecode = get_device_alias(dbus_data->dev_id, &bdaddr, str, sizeof(str)); + ecode = get_device_alias(adapter->dev_id, &bdaddr, str, sizeof(str)); if (ecode < 0) return error_not_available(conn, msg); @@ -1470,7 +1470,7 @@ static DBusHandlerResult handle_dev_get_remote_alias_req(DBusConnection *conn, D static DBusHandlerResult handle_dev_set_remote_alias_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply, *signal; DBusError err; char *alias, *addr; @@ -1496,7 +1496,7 @@ static DBusHandlerResult handle_dev_set_remote_alias_req(DBusConnection *conn, D str2ba(addr, &bdaddr); - ecode = set_device_alias(dbus_data->dev_id, &bdaddr, alias); + ecode = set_device_alias(adapter->dev_id, &bdaddr, alias); if (ecode < 0) return error_failed(conn, msg, -ecode); @@ -1504,7 +1504,7 @@ static DBusHandlerResult handle_dev_set_remote_alias_req(DBusConnection *conn, D if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; - signal = dev_signal_factory(dbus_data->dev_id, "RemoteAliasChanged", + signal = dev_signal_factory(adapter->dev_id, "RemoteAliasChanged", DBUS_TYPE_STRING, &addr, DBUS_TYPE_STRING, &alias, DBUS_TYPE_INVALID); @@ -1515,7 +1515,7 @@ static DBusHandlerResult handle_dev_set_remote_alias_req(DBusConnection *conn, D static DBusHandlerResult handle_dev_clear_remote_alias_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply, *signal; DBusError err; char *addr_ptr; @@ -1540,11 +1540,11 @@ static DBusHandlerResult handle_dev_clear_remote_alias_req(DBusConnection *conn, str2ba(addr_ptr, &bdaddr); - ecode = get_device_alias(dbus_data->dev_id, &bdaddr, NULL, 0); + ecode = get_device_alias(adapter->dev_id, &bdaddr, NULL, 0); if (ecode == -ENXIO) had_alias = 0; - ecode = set_device_alias(dbus_data->dev_id, &bdaddr, NULL); + ecode = set_device_alias(adapter->dev_id, &bdaddr, NULL); if (ecode < 0) return error_failed(conn, msg, -ecode); @@ -1553,7 +1553,7 @@ static DBusHandlerResult handle_dev_clear_remote_alias_req(DBusConnection *conn, return DBUS_HANDLER_RESULT_NEED_MEMORY; if (had_alias) { - signal = dev_signal_factory(dbus_data->dev_id, "RemoteAliasCleared", + signal = dev_signal_factory(adapter->dev_id, "RemoteAliasCleared", DBUS_TYPE_STRING, &addr_ptr, DBUS_TYPE_INVALID); send_reply_and_unref(conn, signal); @@ -1564,7 +1564,7 @@ static DBusHandlerResult handle_dev_clear_remote_alias_req(DBusConnection *conn, static DBusHandlerResult handle_dev_last_seen_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply; DBusError err; char filename[PATH_MAX + 1]; @@ -1584,7 +1584,7 @@ static DBusHandlerResult handle_dev_last_seen_req(DBusConnection *conn, DBusMess if (check_address(addr_ptr) < 0) return error_invalid_arguments(conn, msg); - create_name(filename, PATH_MAX, STORAGEDIR, dbus_data->address, "lastseen"); + create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastseen"); str = textfile_caseget(filename, addr_ptr); if (!str) @@ -1606,7 +1606,7 @@ static DBusHandlerResult handle_dev_last_seen_req(DBusConnection *conn, DBusMess static DBusHandlerResult handle_dev_last_used_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply; DBusError err; char filename[PATH_MAX + 1]; @@ -1626,7 +1626,7 @@ static DBusHandlerResult handle_dev_last_used_req(DBusConnection *conn, DBusMess if (check_address(addr_ptr) < 0) return error_invalid_arguments(conn, msg); - create_name(filename, PATH_MAX, STORAGEDIR, dbus_data->address, "lastused"); + create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastused"); str = textfile_caseget(filename, addr_ptr); if (!str) @@ -1651,15 +1651,15 @@ static DBusHandlerResult handle_dev_disconnect_remote_device_req(DBusConnection DBusMessage *reply; DBusError err; - struct hci_dbus_data *dbus_data = data; - struct slist *l = dbus_data->active_conn; + struct adapter *adapter = data; + struct slist *l = adapter->active_conn; const char *peer_addr; bdaddr_t peer_bdaddr; int dd; struct active_conn_info *dev; - if (!dbus_data->up) + if (!adapter->up) return error_not_ready(conn, msg); dbus_error_init(&err); @@ -1684,7 +1684,7 @@ static DBusHandlerResult handle_dev_disconnect_remote_device_req(DBusConnection dev = l->data; - dd = hci_open_dev(dbus_data->dev_id); + dd = hci_open_dev(adapter->dev_id); if (dd < 0) return error_no_such_adapter(conn, msg); @@ -1720,7 +1720,7 @@ static void reply_authentication_failure(struct bonding_request_info *bonding) } static gboolean create_bonding_conn_complete(GIOChannel *io, GIOCondition cond, - struct hci_dbus_data *pdata) + struct adapter *adapter) { struct hci_request rq; auth_requested_cp cp; @@ -1729,7 +1729,7 @@ static gboolean create_bonding_conn_complete(GIOChannel *io, GIOCondition cond, socklen_t len; int sk, dd, ret; - if (!pdata->bonding) { + if (!adapter->bonding) { /* If we come here it implies a bug somewhere */ debug("create_bonding_conn_complete: no pending bonding!"); g_io_channel_close(io); @@ -1738,17 +1738,17 @@ static gboolean create_bonding_conn_complete(GIOChannel *io, GIOCondition cond, } if (cond & G_IO_NVAL) { - error_authentication_canceled(pdata->bonding->conn, pdata->bonding->rq); + error_authentication_canceled(adapter->bonding->conn, adapter->bonding->rq); goto cleanup; } if (cond & (G_IO_HUP | G_IO_ERR)) { debug("Hangup or error on bonding IO channel"); - if (!pdata->bonding->auth_active) - error_connection_attempt_failed(pdata->bonding->conn, pdata->bonding->rq, ENETDOWN); + if (!adapter->bonding->auth_active) + error_connection_attempt_failed(adapter->bonding->conn, adapter->bonding->rq, ENETDOWN); else - reply_authentication_failure(pdata->bonding); + reply_authentication_failure(adapter->bonding); goto failed; } @@ -1758,28 +1758,28 @@ static gboolean create_bonding_conn_complete(GIOChannel *io, GIOCondition cond, len = sizeof(ret); if (getsockopt(sk, SOL_SOCKET, SO_ERROR, &ret, &len) < 0) { error("Can't get socket error: %s (%d)", strerror(errno), errno); - error_failed(pdata->bonding->conn, pdata->bonding->rq, errno); + error_failed(adapter->bonding->conn, adapter->bonding->rq, errno); goto failed; } if (ret != 0) { - if (pdata->bonding->auth_active) - reply_authentication_failure(pdata->bonding); + if (adapter->bonding->auth_active) + reply_authentication_failure(adapter->bonding); else - error_connection_attempt_failed(pdata->bonding->conn, pdata->bonding->rq, ret); + error_connection_attempt_failed(adapter->bonding->conn, adapter->bonding->rq, ret); goto failed; } len = sizeof(cinfo); if (getsockopt(sk, SOL_L2CAP, L2CAP_CONNINFO, &cinfo, &len) < 0) { error("Can't get connection info: %s (%d)", strerror(errno), errno); - error_failed(pdata->bonding->conn, pdata->bonding->rq, errno); + error_failed(adapter->bonding->conn, adapter->bonding->rq, errno); goto failed; } - dd = hci_open_dev(pdata->dev_id); + dd = hci_open_dev(adapter->dev_id); if (dd < 0) { - error_no_such_adapter(pdata->bonding->conn, pdata->bonding->rq); + error_no_such_adapter(adapter->bonding->conn, adapter->bonding->rq); goto failed; } @@ -1800,7 +1800,7 @@ static gboolean create_bonding_conn_complete(GIOChannel *io, GIOCondition cond, if (hci_send_req(dd, &rq, 500) < 0) { error("Unable to send HCI request: %s (%d)", strerror(errno), errno); - error_failed(pdata->bonding->conn, pdata->bonding->rq, errno); + error_failed(adapter->bonding->conn, adapter->bonding->rq, errno); hci_close_dev(dd); goto failed; } @@ -1808,18 +1808,18 @@ static gboolean create_bonding_conn_complete(GIOChannel *io, GIOCondition cond, if (rp.status) { error("HCI_Authentication_Requested failed with status 0x%02x", rp.status); - error_failed(pdata->bonding->conn, pdata->bonding->rq, bt_error(rp.status)); + error_failed(adapter->bonding->conn, adapter->bonding->rq, bt_error(rp.status)); hci_close_dev(dd); goto failed; } hci_close_dev(dd); - pdata->bonding->auth_active = 1; + adapter->bonding->auth_active = 1; - pdata->bonding->io_id = g_io_add_watch(io, G_IO_NVAL | G_IO_HUP | G_IO_ERR, + adapter->bonding->io_id = g_io_add_watch(io, G_IO_NVAL | G_IO_HUP | G_IO_ERR, (GIOFunc) create_bonding_conn_complete, - pdata); + adapter); return FALSE; @@ -1827,11 +1827,11 @@ failed: g_io_channel_close(io); cleanup: - name_listener_remove(pdata->bonding->conn, dbus_message_get_sender(pdata->bonding->rq), - (name_cb_t) create_bond_req_exit, pdata); + name_listener_remove(adapter->bonding->conn, dbus_message_get_sender(adapter->bonding->rq), + (name_cb_t) create_bond_req_exit, adapter); - bonding_request_free(pdata->bonding); - pdata->bonding = NULL; + bonding_request_free(adapter->bonding); + adapter->bonding = NULL; return FALSE; } @@ -1841,11 +1841,11 @@ static DBusHandlerResult handle_dev_create_bonding_req(DBusConnection *conn, DBu char filename[PATH_MAX + 1]; DBusError err; char *str, *peer_addr = NULL; - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; bdaddr_t peer_bdaddr; int sk; - if (!dbus_data->up) + if (!adapter->up) return error_not_ready(conn, msg); dbus_error_init(&err); @@ -1865,19 +1865,19 @@ static DBusHandlerResult handle_dev_create_bonding_req(DBusConnection *conn, DBu str2ba(peer_addr, &peer_bdaddr); /* check if there is a pending discover: requested by D-Bus/non clients */ - if (dbus_data->disc_active || (dbus_data->pdisc_active && !dbus_data->pinq_idle)) + if (adapter->disc_active || (adapter->pdisc_active && !adapter->pinq_idle)) return error_discover_in_progress(conn, msg); - pending_remote_name_cancel(dbus_data); + pending_remote_name_cancel(adapter); - if (dbus_data->bonding) + if (adapter->bonding) return error_bonding_in_progress(conn, msg); - if (slist_find(dbus_data->pin_reqs, &peer_bdaddr, pin_req_cmp)) + if (slist_find(adapter->pin_reqs, &peer_bdaddr, pin_req_cmp)) return error_bonding_in_progress(conn, msg); /* check if a link key already exists */ - create_name(filename, PATH_MAX, STORAGEDIR, dbus_data->address, "linkkeys"); + create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "linkkeys"); str = textfile_caseget(filename, peer_addr); if (str) { @@ -1885,38 +1885,38 @@ static DBusHandlerResult handle_dev_create_bonding_req(DBusConnection *conn, DBu return error_bonding_already_exists(conn, msg); } - sk = l2raw_connect(dbus_data->address, &peer_bdaddr); + sk = l2raw_connect(adapter->address, &peer_bdaddr); if (sk < 0) return error_connection_attempt_failed(conn, msg, 0); - dbus_data->bonding = bonding_request_new(&peer_bdaddr, conn, msg); - if (!dbus_data->bonding) { + adapter->bonding = bonding_request_new(&peer_bdaddr, conn, msg); + if (!adapter->bonding) { close(sk); return DBUS_HANDLER_RESULT_NEED_MEMORY; } - dbus_data->bonding->io = g_io_channel_unix_new(sk); - dbus_data->bonding->io_id = g_io_add_watch(dbus_data->bonding->io, + adapter->bonding->io = g_io_channel_unix_new(sk); + adapter->bonding->io_id = g_io_add_watch(adapter->bonding->io, G_IO_OUT | G_IO_NVAL | G_IO_HUP | G_IO_ERR, (GIOFunc) create_bonding_conn_complete, - dbus_data); + adapter); name_listener_add(conn, dbus_message_get_sender(msg), - (name_cb_t) create_bond_req_exit, dbus_data); + (name_cb_t) create_bond_req_exit, adapter); return DBUS_HANDLER_RESULT_HANDLED; } static DBusHandlerResult handle_dev_cancel_bonding_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply; DBusError err; bdaddr_t peer_bdaddr; const char *peer_addr; struct slist *l; - if (!dbus_data->up) + if (!adapter->up) return error_not_ready(conn, msg); dbus_error_init(&err); @@ -1935,15 +1935,15 @@ static DBusHandlerResult handle_dev_cancel_bonding_req(DBusConnection *conn, DBu str2ba(peer_addr, &peer_bdaddr); - if (!dbus_data->bonding || bacmp(&dbus_data->bonding->bdaddr, &peer_bdaddr)) + if (!adapter->bonding || bacmp(&adapter->bonding->bdaddr, &peer_bdaddr)) return error_bonding_not_in_progress(conn, msg); - if (strcmp(dbus_message_get_sender(dbus_data->bonding->rq), dbus_message_get_sender(msg))) + if (strcmp(dbus_message_get_sender(adapter->bonding->rq), dbus_message_get_sender(msg))) return error_not_authorized(conn, msg); - dbus_data->bonding->cancel = 1; + adapter->bonding->cancel = 1; - l = slist_find(dbus_data->pin_reqs, &peer_bdaddr, pin_req_cmp); + l = slist_find(adapter->pin_reqs, &peer_bdaddr, pin_req_cmp); if (l) { struct pending_pin_info *pin_req = l->data; @@ -1953,13 +1953,13 @@ static DBusHandlerResult handle_dev_cancel_bonding_req(DBusConnection *conn, DBu * was already replied it doesn't make sense cancel the * remote passkey: return not authorized. */ - g_io_channel_close(dbus_data->bonding->io); + g_io_channel_close(adapter->bonding->io); return error_not_authorized(conn, msg); } else { - int dd = hci_open_dev(dbus_data->dev_id); + int dd = hci_open_dev(adapter->dev_id); if (dd < 0) { error("Can't open hci%d: %s (%d)", - dbus_data->dev_id, strerror(errno), errno); + adapter->dev_id, strerror(errno), errno); return DBUS_HANDLER_RESULT_HANDLED; } @@ -1968,11 +1968,11 @@ static DBusHandlerResult handle_dev_cancel_bonding_req(DBusConnection *conn, DBu hci_close_dev(dd); } - dbus_data->pin_reqs = slist_remove(dbus_data->pin_reqs, pin_req); + adapter->pin_reqs = slist_remove(adapter->pin_reqs, pin_req); free(pin_req); } - g_io_channel_close(dbus_data->bonding->io); + g_io_channel_close(adapter->bonding->io); reply = dbus_message_new_method_return(msg); send_reply_and_unref(conn, reply); @@ -1982,7 +1982,7 @@ static DBusHandlerResult handle_dev_cancel_bonding_req(DBusConnection *conn, DBu static DBusHandlerResult handle_dev_remove_bonding_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; struct slist *l; DBusMessage *reply; DBusMessage *signal; @@ -1992,7 +1992,7 @@ static DBusHandlerResult handle_dev_remove_bonding_req(DBusConnection *conn, DBu bdaddr_t bdaddr; int dd; - if (!dbus_data->up) + if (!adapter->up) return error_not_ready(conn, msg); dbus_error_init(&err); @@ -2009,11 +2009,11 @@ static DBusHandlerResult handle_dev_remove_bonding_req(DBusConnection *conn, DBu if (check_address(addr_ptr) < 0) return error_invalid_arguments(conn, msg); - dd = hci_open_dev(dbus_data->dev_id); + dd = hci_open_dev(adapter->dev_id); if (dd < 0) return error_no_such_adapter(conn, msg); - create_name(filename, PATH_MAX, STORAGEDIR, dbus_data->address, "linkkeys"); + create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "linkkeys"); /* textfile_del doesn't return an error when the key is not found */ str = textfile_caseget(filename, addr_ptr); @@ -2037,7 +2037,7 @@ static DBusHandlerResult handle_dev_remove_bonding_req(DBusConnection *conn, DBu hci_delete_stored_link_key(dd, &bdaddr, 0, 1000); /* find the connection */ - l = slist_find(dbus_data->active_conn, &bdaddr, active_conn_find_by_bdaddr); + l = slist_find(adapter->active_conn, &bdaddr, active_conn_find_by_bdaddr); if (l) { struct active_conn_info *con = l->data; /* Send the HCI disconnect command */ @@ -2050,7 +2050,7 @@ static DBusHandlerResult handle_dev_remove_bonding_req(DBusConnection *conn, DBu } /* FIXME: which condition must be verified before send the signal */ - signal = dev_signal_factory(dbus_data->dev_id, "BondingRemoved", + signal = dev_signal_factory(adapter->dev_id, "BondingRemoved", DBUS_TYPE_STRING, &addr_ptr, DBUS_TYPE_INVALID); send_reply_and_unref(conn, signal); @@ -2064,7 +2064,7 @@ static DBusHandlerResult handle_dev_remove_bonding_req(DBusConnection *conn, DBu static DBusHandlerResult handle_dev_has_bonding_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply; DBusError err; char filename[PATH_MAX + 1]; @@ -2085,7 +2085,7 @@ static DBusHandlerResult handle_dev_has_bonding_req(DBusConnection *conn, DBusMe if (check_address(addr_ptr) < 0) return error_invalid_arguments(conn, msg); - create_name(filename, PATH_MAX, STORAGEDIR, dbus_data->address, "linkkeys"); + create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "linkkeys"); str = textfile_caseget(filename, addr_ptr); if (str) { @@ -2110,7 +2110,7 @@ static void list_bondings_do_append(char *key, char *value, void *data) static DBusHandlerResult handle_dev_list_bondings_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessageIter iter; DBusMessageIter array_iter; DBusMessage *reply; @@ -2119,7 +2119,7 @@ static DBusHandlerResult handle_dev_list_bondings_req(DBusConnection *conn, DBus if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) return error_invalid_arguments(conn, msg); - create_name(filename, PATH_MAX, STORAGEDIR, dbus_data->address, "linkkeys"); + create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "linkkeys"); reply = dbus_message_new_method_return(msg); @@ -2137,7 +2137,7 @@ static DBusHandlerResult handle_dev_list_bondings_req(DBusConnection *conn, DBus static DBusHandlerResult handle_dev_get_pin_code_length_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply; DBusError err; bdaddr_t local, peer; @@ -2159,7 +2159,7 @@ static DBusHandlerResult handle_dev_get_pin_code_length_req(DBusConnection *conn if (check_address(addr_ptr) < 0) return error_invalid_arguments(conn, msg); - str2ba(dbus_data->address, &local); + str2ba(adapter->address, &local); str2ba(addr_ptr, &peer); @@ -2179,7 +2179,7 @@ static DBusHandlerResult handle_dev_get_pin_code_length_req(DBusConnection *conn static DBusHandlerResult handle_dev_get_encryption_key_size_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply; DBusError err; bdaddr_t bdaddr; @@ -2203,7 +2203,7 @@ static DBusHandlerResult handle_dev_get_encryption_key_size_req(DBusConnection * str2ba(addr_ptr, &bdaddr); - val = get_encryption_key_size(dbus_data->dev_id, &bdaddr); + val = get_encryption_key_size(adapter->dev_id, &bdaddr); if (val < 0) return error_failed(conn, msg, -val); @@ -2222,23 +2222,23 @@ static DBusHandlerResult handle_dev_start_periodic_req(DBusConnection *conn, DBu DBusMessage *reply; periodic_inquiry_cp cp; struct hci_request rq; - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; uint8_t lap[3] = { 0x33, 0x8b, 0x9e }; uint8_t status; int dd; - if (!dbus_data->up) + if (!adapter->up) return error_not_ready(conn, msg); if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) return error_invalid_arguments(conn, msg); - if (dbus_data->disc_active || dbus_data->pdisc_active) + if (adapter->disc_active || adapter->pdisc_active) return error_discover_in_progress(conn, msg); - pending_remote_name_cancel(dbus_data); + pending_remote_name_cancel(adapter); - dd = hci_open_dev(dbus_data->dev_id); + dd = hci_open_dev(adapter->dev_id); if (dd < 0) return error_no_such_adapter(conn, msg); @@ -2272,8 +2272,8 @@ static DBusHandlerResult handle_dev_start_periodic_req(DBusConnection *conn, DBu return error_failed(conn, msg, bt_error(status)); } - dbus_data->pdiscovery_requestor = strdup(dbus_message_get_sender(msg)); - dbus_data->discover_type = PERIODIC_INQUIRY | RESOLVE_NAME; + adapter->pdiscovery_requestor = strdup(dbus_message_get_sender(msg)); + adapter->discover_type = PERIODIC_INQUIRY | RESOLVE_NAME; reply = dbus_message_new_method_return(msg); @@ -2281,7 +2281,7 @@ static DBusHandlerResult handle_dev_start_periodic_req(DBusConnection *conn, DBu /* track the request owner to cancel it automatically if the owner exits */ name_listener_add(conn, dbus_message_get_sender(msg), - (name_cb_t) periodic_discover_req_exit, dbus_data); + (name_cb_t) periodic_discover_req_exit, adapter); return send_reply_and_unref(conn, reply); } @@ -2289,23 +2289,23 @@ static DBusHandlerResult handle_dev_start_periodic_req(DBusConnection *conn, DBu static DBusHandlerResult handle_dev_stop_periodic_req(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessage *reply; - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; int err; - if (!dbus_data->up) + if (!adapter->up) return error_not_ready(conn, msg); if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) return error_invalid_arguments(conn, msg); - if (!dbus_data->pdisc_active) + if (!adapter->pdisc_active) return error_not_authorized(conn, msg); /* * Cleanup the discovered devices list and send the cmd to exit * from periodic inquiry mode or cancel remote name request. */ - err = cancel_periodic_discovery(dbus_data); + err = cancel_periodic_discovery(adapter); if (err < 0) { if (err == -ENODEV) return error_no_such_adapter(conn, msg); @@ -2320,8 +2320,8 @@ static DBusHandlerResult handle_dev_stop_periodic_req(DBusConnection *conn, DBus static DBusHandlerResult handle_dev_is_periodic_req(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessage *reply; - struct hci_dbus_data *dbus_data = data; - dbus_bool_t active = dbus_data->pdisc_active; + struct adapter *adapter = data; + dbus_bool_t active = adapter->pdisc_active; reply = dbus_message_new_method_return(msg); if (!reply) @@ -2340,25 +2340,25 @@ static DBusHandlerResult handle_dev_discover_devices_req(DBusConnection *conn, D inquiry_cp cp; evt_cmd_status rp; struct hci_request rq; - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; uint8_t lap[3] = { 0x33, 0x8b, 0x9e }; int dd; - if (!dbus_data->up) + if (!adapter->up) return error_not_ready(conn, msg); if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) return error_invalid_arguments(conn, msg); - if (dbus_data->disc_active) + if (adapter->disc_active) return error_discover_in_progress(conn, msg); - pending_remote_name_cancel(dbus_data); + pending_remote_name_cancel(adapter); - if (dbus_data->bonding) + if (adapter->bonding) return error_bonding_in_progress(conn, msg); - dd = hci_open_dev(dbus_data->dev_id); + dd = hci_open_dev(adapter->dev_id); if (dd < 0) return error_no_such_adapter(conn, msg); @@ -2392,11 +2392,11 @@ static DBusHandlerResult handle_dev_discover_devices_req(DBusConnection *conn, D method = dbus_message_get_member(msg); if (strcmp("DiscoverDevicesWithoutNameResolving", method) == 0) - dbus_data->discover_type |= STD_INQUIRY; + adapter->discover_type |= STD_INQUIRY; else - dbus_data->discover_type |= (STD_INQUIRY | RESOLVE_NAME); + adapter->discover_type |= (STD_INQUIRY | RESOLVE_NAME); - dbus_data->discovery_requestor = strdup(dbus_message_get_sender(msg)); + adapter->discovery_requestor = strdup(dbus_message_get_sender(msg)); reply = dbus_message_new_method_return(msg); @@ -2404,36 +2404,36 @@ static DBusHandlerResult handle_dev_discover_devices_req(DBusConnection *conn, D /* track the request owner to cancel it automatically if the owner exits */ name_listener_add(conn, dbus_message_get_sender(msg), - (name_cb_t) discover_devices_req_exit, dbus_data); + (name_cb_t) discover_devices_req_exit, adapter); return send_reply_and_unref(conn, reply); } static DBusHandlerResult handle_dev_cancel_discovery_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; int err; - if (!dbus_data->up) + if (!adapter->up) return error_not_ready(conn, msg); if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) return error_invalid_arguments(conn, msg); /* is there discover pending? or discovery cancel was requested previously */ - if (!dbus_data->disc_active || dbus_data->discovery_cancel) + if (!adapter->disc_active || adapter->discovery_cancel) return error_not_authorized(conn, msg); /* only the discover requestor can cancel the inquiry process */ - if (!dbus_data->discovery_requestor || - strcmp(dbus_data->discovery_requestor, dbus_message_get_sender(msg))) + if (!adapter->discovery_requestor || + strcmp(adapter->discovery_requestor, dbus_message_get_sender(msg))) return error_not_authorized(conn, msg); /* * Cleanup the discovered devices list and send the cmd * to cancel inquiry or cancel remote name request */ - err = cancel_discovery(dbus_data); + err = cancel_discovery(adapter); if (err < 0) { if (err == -ENODEV) return error_no_such_adapter(conn, msg); @@ -2442,7 +2442,7 @@ static DBusHandlerResult handle_dev_cancel_discovery_req(DBusConnection *conn, D } /* Reply before send DiscoveryCompleted */ - dbus_data->discovery_cancel = dbus_message_ref(msg); + adapter->discovery_cancel = dbus_message_ref(msg); return DBUS_HANDLER_RESULT_HANDLED; } diff --git a/hcid/dbus-rfcomm.c b/hcid/dbus-rfcomm.c index e413851c..97e9836f 100644 --- a/hcid/dbus-rfcomm.c +++ b/hcid/dbus-rfcomm.c @@ -570,14 +570,14 @@ typedef struct { DBusMessage *msg; char *dst; char *svc; - struct hci_dbus_data *dbus_data; + struct adapter *adapter; } rfcomm_continue_data_t; static rfcomm_continue_data_t *rfcomm_continue_data_new(DBusConnection *conn, DBusMessage *msg, const char *dst, const char *svc, - struct hci_dbus_data *dbus_data) + struct adapter *adapter) { rfcomm_continue_data_t *new; @@ -600,7 +600,7 @@ static rfcomm_continue_data_t *rfcomm_continue_data_new(DBusConnection *conn, new->conn = dbus_connection_ref(conn); new->msg = dbus_message_ref(msg); - new->dbus_data = dbus_data; + new->adapter = adapter; return new; } @@ -641,7 +641,7 @@ static void rfcomm_conn_req_continue(sdp_record_t *rec, void *data, int err) goto failed; } - hci_devba(cdata->dbus_data->dev_id, &bdaddr); + hci_devba(cdata->adapter->dev_id, &bdaddr); if (rfcomm_connect(cdata->conn, cdata->msg, &bdaddr, cdata->dst, cdata->svc, ch, &conn_err) < 0) error_failed(cdata->conn, cdata->msg, conn_err); @@ -653,7 +653,7 @@ failed: static DBusHandlerResult rfcomm_connect_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; rfcomm_continue_data_t *cdata; uint32_t handle; uuid_t uuid; @@ -667,15 +667,15 @@ static DBusHandlerResult rfcomm_connect_req(DBusConnection *conn, DBUS_TYPE_INVALID)) return error_invalid_arguments(conn, msg); - cdata = rfcomm_continue_data_new(conn, msg, dst, string, dbus_data); + cdata = rfcomm_continue_data_new(conn, msg, dst, string, adapter); if (!cdata) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (str2uuid(&uuid, string) == 0) - err = get_record_with_uuid(conn, msg, dbus_data->dev_id, dst, + err = get_record_with_uuid(conn, msg, adapter->dev_id, dst, &uuid, rfcomm_conn_req_continue, cdata); else if ((handle = strtol(string, NULL, 0))) - err = get_record_with_handle(conn, msg, dbus_data->dev_id, dst, + err = get_record_with_handle(conn, msg, adapter->dev_id, dst, handle, rfcomm_conn_req_continue, cdata); else { rfcomm_continue_data_free(cdata); @@ -728,9 +728,9 @@ static DBusHandlerResult rfcomm_connect_by_ch_req(DBusConnection *conn, const char *dst; uint8_t ch; int err; - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; - hci_devba(dbus_data->dev_id, &bdaddr); + hci_devba(adapter->dev_id, &bdaddr); if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &dst, @@ -836,7 +836,7 @@ static void rfcomm_bind_req_continue(sdp_record_t *rec, void *data, int err) goto failed; } - hci_devba(cdata->dbus_data->dev_id, &bdaddr); + hci_devba(cdata->adapter->dev_id, &bdaddr); node = rfcomm_bind(&bdaddr, cdata->dst, ch, cdata->conn, dbus_message_get_sender(cdata->msg), &bind_err); @@ -879,7 +879,7 @@ failed: static DBusHandlerResult rfcomm_bind_req(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; rfcomm_continue_data_t *cdata; uint32_t handle; uuid_t uuid; @@ -893,15 +893,15 @@ static DBusHandlerResult rfcomm_bind_req(DBusConnection *conn, DBUS_TYPE_INVALID)) return error_invalid_arguments(conn, msg); - cdata = rfcomm_continue_data_new(conn, msg, dst, string, dbus_data); + cdata = rfcomm_continue_data_new(conn, msg, dst, string, adapter); if (!cdata) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (str2uuid(&uuid, string) == 0) - err = get_record_with_uuid(conn, msg, dbus_data->dev_id, dst, + err = get_record_with_uuid(conn, msg, adapter->dev_id, dst, &uuid, rfcomm_bind_req_continue, cdata); else if ((handle = strtol(string, NULL, 0))) - err = get_record_with_handle(conn, msg, dbus_data->dev_id, dst, + err = get_record_with_handle(conn, msg, adapter->dev_id, dst, handle, rfcomm_bind_req_continue, cdata); else { rfcomm_continue_data_free(cdata); @@ -927,10 +927,10 @@ static DBusHandlerResult rfcomm_bind_by_ch_req(DBusConnection *conn, uint8_t ch; int err; const char *dst, *name; - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; struct rfcomm_node *node = NULL; - hci_devba(dbus_data->dev_id, &bdaddr); + hci_devba(adapter->dev_id, &bdaddr); if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &dst, @@ -1008,10 +1008,10 @@ static DBusHandlerResult rfcomm_list_bindings_req(DBusConnection *conn, bdaddr_t bdaddr; DBusMessage *reply; DBusMessageIter iter, sub; - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; struct slist *l; - hci_devba(dbus_data->dev_id, &bdaddr); + hci_devba(adapter->dev_id, &bdaddr); reply = dbus_message_new_method_return(msg); if (!reply) @@ -1066,7 +1066,7 @@ static struct service_data rfcomm_services[] = { DBusHandlerResult handle_rfcomm_method(DBusConnection *conn, DBusMessage *msg, void *data) { - const struct hci_dbus_data *pdata = data; + const struct adapter *adapter = data; service_handler_func_t handler; if (!hcid_dbus_use_experimental()) @@ -1077,7 +1077,7 @@ DBusHandlerResult handle_rfcomm_method(DBusConnection *conn, DBusMessage *msg, return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } - if (!pdata->up) + if (!adapter->up) return error_not_ready(conn, msg); /* Initialize the RFCOMM control socket if has not yet been done */ diff --git a/hcid/dbus-sdp.c b/hcid/dbus-sdp.c index adbe1895..70d54347 100644 --- a/hcid/dbus-sdp.c +++ b/hcid/dbus-sdp.c @@ -466,7 +466,7 @@ static inline void get_record_data_call_cb(get_record_data_t *d, d->cb(rec, d->data, err); } -static void owner_exited(const char *owner, struct hci_dbus_data *dbus_data) +static void owner_exited(const char *owner, struct adapter *adapter) { struct slist *lp, *next, *lr; struct service_provider *p; @@ -486,7 +486,7 @@ static void owner_exited(const char *owner, struct hci_dbus_data *dbus_data) * Unregister all service records related to this owner. * One owner can use multiple local adapter(provider) */ - str2ba(dbus_data->address, &sba); + str2ba(adapter->address, &sba); for (lr = p->lrec; lr; lr = lr->next) { struct service_record *r = lr->data; if (sdp_service_unregister(&sba, r->record, &err) < 0) @@ -896,7 +896,7 @@ fail: DBusHandlerResult get_remote_svc_rec(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; const char *dst; uint32_t handle; int err = 0; @@ -910,7 +910,7 @@ DBusHandlerResult get_remote_svc_rec(DBusConnection *conn, DBusMessage *msg, voi if (find_pending_connect(dst)) return error_service_search_in_progress(conn, msg); - if (!connect_request(conn, msg, dbus_data->dev_id, + if (!connect_request(conn, msg, adapter->dev_id, dst, remote_svc_rec_conn_cb, &err)) { error("Search request failed: %s (%d)", strerror(err), err); return error_failed(conn, msg, err); @@ -959,7 +959,7 @@ fail: DBusHandlerResult get_remote_svc_handles(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; const char *dst, *svc; int err = 0; uuid_t uuid; @@ -981,7 +981,7 @@ DBusHandlerResult get_remote_svc_handles(DBusConnection *conn, DBusMessage *msg, if (find_pending_connect(dst)) return error_service_search_in_progress(conn, msg); - if (!connect_request(conn, msg, dbus_data->dev_id, + if (!connect_request(conn, msg, adapter->dev_id, dst, remote_svc_handles_conn_cb, &err)) { error("Search request failed: %s (%d)", strerror(err), err); return error_failed(conn, msg, err); @@ -1020,7 +1020,7 @@ fail: static DBusHandlerResult get_identifiers(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; const char *dst; int err = 0; @@ -1033,7 +1033,7 @@ static DBusHandlerResult get_identifiers(DBusConnection *conn, if (find_pending_connect(dst)) return error_service_search_in_progress(conn, msg); - if (!connect_request(conn, msg, dbus_data->dev_id, + if (!connect_request(conn, msg, adapter->dev_id, dst, get_identifiers_conn_cb, &err)) { error("Search request failed: %s (%d)", strerror(err), err); return error_failed(conn, msg, err); @@ -1080,7 +1080,7 @@ fail: static DBusHandlerResult get_identifiers_by_service(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; DBusMessage *reply; DBusMessageIter iter, array_iter; struct slist *lp; @@ -1158,7 +1158,7 @@ search_request: if (find_pending_connect(dst)) return error_service_search_in_progress(conn, msg); - if (!connect_request(conn, msg, dbus_data->dev_id, + if (!connect_request(conn, msg, adapter->dev_id, dst, get_identifiers_by_service_conn_cb, &err)) { error("Search request failed: %s (%d)", strerror(err), err); return error_failed(conn, msg, err); @@ -1332,7 +1332,7 @@ static DBusHandlerResult get_name(DBusConnection *conn, static DBusHandlerResult register_rfcomm(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; struct service_provider psearch; DBusMessage *reply; sdp_record_t *rec; @@ -1355,7 +1355,7 @@ static DBusHandlerResult register_rfcomm(DBusConnection *conn, if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; - str2ba(dbus_data->address, &sba); + str2ba(adapter->address, &sba); /* register service */ if (!(rec = sdp_service_register(name, &sba, channel, &err))) { dbus_message_unref(reply); @@ -1371,11 +1371,11 @@ static DBusHandlerResult register_rfcomm(DBusConnection *conn, psearch.owner = (char *) owner; if (!slist_find(sdp_cache, &psearch, service_provider_cmp)) - name_listener_add(conn, owner, (name_cb_t) owner_exited, dbus_data); + name_listener_add(conn, owner, (name_cb_t) owner_exited, adapter); /* add record in the cache */ - sdp_cache_append(owner, dbus_data->address, rec); - snprintf(identifier, MAX_IDENTIFIER_LEN, "%s/0x%x", dbus_data->address, rec->handle); + sdp_cache_append(owner, adapter->address, rec); + snprintf(identifier, MAX_IDENTIFIER_LEN, "%s/0x%x", adapter->address, rec->handle); dbus_message_append_args(reply, DBUS_TYPE_STRING, &ptr, DBUS_TYPE_INVALID); @@ -1387,7 +1387,7 @@ static DBusHandlerResult unregister_rfcomm(DBusConnection *conn, DBusMessage *msg, void *data) { char address[18]; - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; struct service_provider *p, psearch; struct service_record rsearch, *r; sdp_record_t record; @@ -1409,7 +1409,7 @@ static DBusHandlerResult unregister_rfcomm(DBusConnection *conn, return error_invalid_arguments(conn, msg); /* check if the local adapter match */ - if (strcmp(address, dbus_data->address)) + if (strcmp(address, adapter->address)) return error_not_authorized(conn, msg); memset(&psearch, 0, sizeof(psearch)); @@ -1434,7 +1434,7 @@ static DBusHandlerResult unregister_rfcomm(DBusConnection *conn, return DBUS_HANDLER_RESULT_NEED_MEMORY; r = lr->data; - str2ba(dbus_data->address, &sba); + str2ba(adapter->address, &sba); if (sdp_service_unregister(&sba, r->record, &err) < 0) error("service unregister error: %s (%d)", strerror(err), err); else @@ -1454,7 +1454,7 @@ static DBusHandlerResult unregister_rfcomm(DBusConnection *conn, /* Only remove the D-Bus unique name listener if there are no more record using this name */ if (!slist_find(sdp_cache, &psearch, service_provider_cmp)) - name_listener_remove(conn, owner, (name_cb_t) owner_exited, dbus_data); + name_listener_remove(conn, owner, (name_cb_t) owner_exited, adapter); return send_reply_and_unref(conn, reply); } @@ -1471,13 +1471,13 @@ static struct service_data sdp_services[] = { DBusHandlerResult handle_sdp_method(DBusConnection *conn, DBusMessage *msg, void *data) { - const struct hci_dbus_data *pdata = data; + const struct adapter *adapter = data; service_handler_func_t handler; if (!hcid_dbus_use_experimental()) return error_unknown_method(conn, msg); - if (!pdata->up) + if (!adapter->up) return error_not_ready(conn, msg); handler = find_service_handler(sdp_services, msg); diff --git a/hcid/dbus-security.c b/hcid/dbus-security.c index b1e249df..dc92a8cf 100644 --- a/hcid/dbus-security.c +++ b/hcid/dbus-security.c @@ -83,7 +83,7 @@ static void passkey_agent_free(struct passkey_agent *agent) free(agent); } -static void agent_exited(const char *name, struct hci_dbus_data *adapter) +static void agent_exited(const char *name, struct adapter *adapter) { struct slist *cur, *next; @@ -106,12 +106,12 @@ static void agent_exited(const char *name, struct hci_dbus_data *adapter) static gboolean agent_timeout(struct passkey_agent *agent) { - struct hci_dbus_data *pdata = agent->pdata; + struct adapter *adapter = agent->adapter; debug("Passkey Agent at %s, %s timed out", agent->name, agent->path); - if (pdata) - pdata->passkey_agents = slist_remove(pdata->passkey_agents, agent); + if (adapter) + adapter->passkey_agents = slist_remove(adapter->passkey_agents, agent); agent->timeout = 0; @@ -136,7 +136,7 @@ static void default_agent_exited(const char *name, void *data) default_agent = NULL; } -static struct passkey_agent *passkey_agent_new(struct hci_dbus_data *pdata, DBusConnection *conn, +static struct passkey_agent *passkey_agent_new(struct adapter *adapter, DBusConnection *conn, const char *name, const char *path, const char *addr) { @@ -148,7 +148,7 @@ static struct passkey_agent *passkey_agent_new(struct hci_dbus_data *pdata, DBus memset(agent, 0, sizeof(struct passkey_agent)); - agent->pdata = pdata; + agent->adapter = adapter; agent->name = strdup(name); if (!agent->name) @@ -210,7 +210,7 @@ static DBusHandlerResult register_agent(DBusConnection *conn, DBusMessage *msg, void *data) { struct passkey_agent *agent, ref; - struct hci_dbus_data *adapter; + struct adapter *adapter; DBusMessage *reply; const char *path, *addr; @@ -263,7 +263,7 @@ static DBusHandlerResult register_agent(DBusConnection *conn, static DBusHandlerResult unregister_agent(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *adapter; + struct adapter *adapter; struct slist *match; struct passkey_agent ref, *agent; DBusMessage *reply; @@ -457,7 +457,7 @@ done: free(req); if (agent != default_agent) { - agent->pdata->passkey_agents = slist_remove(agent->pdata->passkey_agents, + agent->adapter->passkey_agents = slist_remove(agent->adapter->passkey_agents, agent); passkey_agent_free(agent); } @@ -551,7 +551,7 @@ int handle_passkey_request(DBusConnection *conn, int dev, const char *path, bdaddr_t *sba, bdaddr_t *dba) { struct passkey_agent *agent = default_agent; - struct hci_dbus_data *adapter = NULL; + struct adapter *adapter = NULL; struct slist *l; char addr[18]; void *data; @@ -636,9 +636,9 @@ static void release_agent(struct passkey_agent *agent) /* Only remove the name listener if there are no more agents for this name */ memset(&ref, 0, sizeof(ref)); ref.name = agent->name; - if (!slist_find(agent->pdata->passkey_agents, &ref, (cmp_func_t) agent_cmp)) + if (!slist_find(agent->adapter->passkey_agents, &ref, (cmp_func_t) agent_cmp)) name_listener_remove(agent->conn, ref.name, - (name_cb_t) agent_exited, agent->pdata); + (name_cb_t) agent_exited, agent->adapter); } } @@ -651,11 +651,11 @@ void release_default_agent(void) default_agent = NULL; } -void release_passkey_agents(struct hci_dbus_data *pdata, bdaddr_t *bda) +void release_passkey_agents(struct adapter *adapter, bdaddr_t *bda) { struct slist *l, *next; - for (l = pdata->passkey_agents; l != NULL; l = next) { + for (l = adapter->passkey_agents; l != NULL; l = next) { struct passkey_agent *agent = l->data; next = l->next; @@ -666,7 +666,7 @@ void release_passkey_agents(struct hci_dbus_data *pdata, bdaddr_t *bda) continue; } - pdata->passkey_agents = slist_remove(pdata->passkey_agents, agent); + adapter->passkey_agents = slist_remove(adapter->passkey_agents, agent); passkey_agent_free(agent); } } diff --git a/hcid/dbus-test.c b/hcid/dbus-test.c index c74adf54..fe1ce717 100644 --- a/hcid/dbus-test.c +++ b/hcid/dbus-test.c @@ -325,7 +325,7 @@ static DBusHandlerResult audit_remote_device(DBusConnection *conn, bdaddr_t dba; const char *address; struct audit *audit; - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; dbus_error_init(&err); dbus_message_get_args(msg, &err, @@ -343,15 +343,15 @@ static DBusHandlerResult audit_remote_device(DBusConnection *conn, str2ba(address, &dba); /* check if there is a pending discover: requested by D-Bus/non clients */ - if (dbus_data->disc_active || (dbus_data->pdisc_active && !dbus_data->pinq_idle)) + if (adapter->disc_active || (adapter->pdisc_active && !adapter->pinq_idle)) return error_discover_in_progress(conn, msg); - pending_remote_name_cancel(dbus_data); + pending_remote_name_cancel(adapter); - if (dbus_data->bonding) + if (adapter->bonding) return error_bonding_in_progress(conn, msg); - if (slist_find(dbus_data->pin_reqs, &dba, pin_req_cmp)) + if (slist_find(adapter->pin_reqs, &dba, pin_req_cmp)) return error_bonding_in_progress(conn, msg); reply = dbus_message_new_method_return(msg); @@ -367,7 +367,7 @@ static DBusHandlerResult audit_remote_device(DBusConnection *conn, if (!audit_in_progress()) { int sk; - sk = l2raw_connect(dbus_data->address, &dba); + sk = l2raw_connect(adapter->address, &dba); if (sk < 0) { audit_free(audit); dbus_message_unref(reply); diff --git a/hcid/dbus.c b/hcid/dbus.c index 5e05ae50..e840ad64 100644 --- a/hcid/dbus.c +++ b/hcid/dbus.c @@ -342,17 +342,17 @@ static DBusHandlerResult hci_dbus_signal_filter(DBusConnection *conn, DBusMessag static int register_dbus_path(const char *path, uint16_t dev_id, const DBusObjectPathVTable *pvtable, gboolean fallback) { - struct hci_dbus_data *data; + struct adapter *data; info("Register path:%s fallback:%d", path, fallback); - data = malloc(sizeof(struct hci_dbus_data)); + data = malloc(sizeof(struct adapter)); if (!data) { error("Failed to alloc memory to DBUS path register data (%s)", path); return -1; } - memset(data, 0, sizeof(struct hci_dbus_data)); + memset(data, 0, sizeof(struct adapter)); data->dev_id = dev_id; @@ -373,34 +373,34 @@ static int register_dbus_path(const char *path, uint16_t dev_id, return 0; } -static void reply_pending_requests(const char *path, struct hci_dbus_data *pdata) +static void reply_pending_requests(const char *path, struct adapter *adapter) { DBusMessage *message; - if (!path || !pdata) + if (!path || !adapter) return; /* pending bonding */ - if (pdata->bonding) { - error_authentication_canceled(connection, pdata->bonding->rq); - name_listener_remove(connection, dbus_message_get_sender(pdata->bonding->rq), - (name_cb_t) create_bond_req_exit, pdata); - if (pdata->bonding->io_id) - g_io_remove_watch(pdata->bonding->io_id); - g_io_channel_close(pdata->bonding->io); - bonding_request_free(pdata->bonding); - pdata->bonding = NULL; + if (adapter->bonding) { + error_authentication_canceled(connection, adapter->bonding->rq); + name_listener_remove(connection, dbus_message_get_sender(adapter->bonding->rq), + (name_cb_t) create_bond_req_exit, adapter); + if (adapter->bonding->io_id) + g_io_remove_watch(adapter->bonding->io_id); + g_io_channel_close(adapter->bonding->io); + bonding_request_free(adapter->bonding); + adapter->bonding = NULL; } /* If there is a pending reply for discovery cancel */ - if (pdata->discovery_cancel) { - message = dbus_message_new_method_return(pdata->discovery_cancel); + if (adapter->discovery_cancel) { + message = dbus_message_new_method_return(adapter->discovery_cancel); send_reply_and_unref(connection, message); - dbus_message_unref(pdata->discovery_cancel); - pdata->discovery_cancel = NULL; + dbus_message_unref(adapter->discovery_cancel); + adapter->discovery_cancel = NULL; } - if (pdata->disc_active) { + if (adapter->disc_active) { /* Send discovery completed signal if there isn't name * to resolve */ message = dbus_message_new_signal(path, ADAPTER_INTERFACE, @@ -408,11 +408,11 @@ static void reply_pending_requests(const char *path, struct hci_dbus_data *pdata send_reply_and_unref(connection, message); /* Cancel inquiry initiated by D-Bus client */ - if (pdata->discovery_requestor) - cancel_discovery(pdata); + if (adapter->discovery_requestor) + cancel_discovery(adapter); } - if (pdata->pdisc_active) { + if (adapter->pdisc_active) { /* Send periodic discovery stopped signal exit or stop * the device */ message = dbus_message_new_signal(path, ADAPTER_INTERFACE, @@ -420,71 +420,71 @@ static void reply_pending_requests(const char *path, struct hci_dbus_data *pdata send_reply_and_unref(connection, message); /* Stop periodic inquiry initiated by D-Bus client */ - if (pdata->pdiscovery_requestor) - cancel_periodic_discovery(pdata); + if (adapter->pdiscovery_requestor) + cancel_periodic_discovery(adapter); } } static int unregister_dbus_path(const char *path) { - struct hci_dbus_data *pdata; + struct adapter *adapter; info("Unregister path:%s", path); - if (dbus_connection_get_object_path_data(connection, path, (void *) &pdata) && pdata) { + if (dbus_connection_get_object_path_data(connection, path, (void *) &adapter) && adapter) { /* check pending requests */ - reply_pending_requests(path, pdata); + reply_pending_requests(path, adapter); - cancel_passkey_agent_requests(pdata->passkey_agents, path, NULL); + cancel_passkey_agent_requests(adapter->passkey_agents, path, NULL); - release_passkey_agents(pdata, NULL); + release_passkey_agents(adapter, NULL); - if (pdata->discovery_requestor) { + if (adapter->discovery_requestor) { name_listener_remove(connection, - pdata->discovery_requestor, - (name_cb_t) discover_devices_req_exit, pdata); - free(pdata->discovery_requestor); - pdata->discovery_requestor = NULL; + adapter->discovery_requestor, + (name_cb_t) discover_devices_req_exit, adapter); + free(adapter->discovery_requestor); + adapter->discovery_requestor = NULL; } - if (pdata->pdiscovery_requestor) { + if (adapter->pdiscovery_requestor) { name_listener_remove(connection, - pdata->pdiscovery_requestor, - (name_cb_t) periodic_discover_req_exit, pdata); - free(pdata->pdiscovery_requestor); - pdata->pdiscovery_requestor = NULL; + adapter->pdiscovery_requestor, + (name_cb_t) periodic_discover_req_exit, adapter); + free(adapter->pdiscovery_requestor); + adapter->pdiscovery_requestor = NULL; } - if (pdata->disc_devices) { - slist_foreach(pdata->disc_devices, + if (adapter->disc_devices) { + slist_foreach(adapter->disc_devices, (slist_func_t) free, NULL); - slist_free(pdata->disc_devices); - pdata->disc_devices = NULL; + slist_free(adapter->disc_devices); + adapter->disc_devices = NULL; } - if (pdata->oor_devices) { - slist_foreach(pdata->oor_devices, + if (adapter->oor_devices) { + slist_foreach(adapter->oor_devices, (slist_func_t) free, NULL); - slist_free(pdata->oor_devices); - pdata->oor_devices = NULL; + slist_free(adapter->oor_devices); + adapter->oor_devices = NULL; } - if (pdata->pin_reqs) { - slist_foreach(pdata->pin_reqs, + if (adapter->pin_reqs) { + slist_foreach(adapter->pin_reqs, (slist_func_t) free, NULL); - slist_free(pdata->pin_reqs); - pdata->pin_reqs = NULL; + slist_free(adapter->pin_reqs); + adapter->pin_reqs = NULL; } - if (pdata->active_conn) { - slist_foreach(pdata->active_conn, + if (adapter->active_conn) { + slist_foreach(adapter->active_conn, (slist_func_t) free, NULL); - slist_free(pdata->active_conn); - pdata->active_conn = NULL; + slist_free(adapter->active_conn); + adapter->active_conn = NULL; } - free (pdata); + free (adapter); } if (!dbus_connection_unregister_object_path (connection, path)) { @@ -571,7 +571,7 @@ int hcid_dbus_start_device(uint16_t id) read_scan_enable_rp rp; struct hci_dev_info di; struct hci_request rq; - struct hci_dbus_data* pdata; + struct adapter* adapter; struct hci_conn_list_req *cl = NULL; struct hci_conn_info *ci; @@ -609,25 +609,25 @@ int hcid_dbus_start_device(uint16_t id) } } - if (!dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { + if (!dbus_connection_get_object_path_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); goto failed; } if (hci_test_bit(HCI_INQUIRY, &di.flags)) - pdata->disc_active = 1; + adapter->disc_active = 1; else - pdata->disc_active = 0; + adapter->disc_active = 0; - pdata->mode = rp.enable; /* Keep the current scan status */ - pdata->up = 1; - pdata->discoverable_timeout = get_discoverable_timeout(id); - pdata->discover_type = DISCOVER_TYPE_NONE; + adapter->mode = rp.enable; /* Keep the current scan status */ + adapter->up = 1; + adapter->discoverable_timeout = get_discoverable_timeout(id); + adapter->discover_type = DISCOVER_TYPE_NONE; /* * Get the adapter Bluetooth address */ - err = get_device_address(pdata->dev_id, pdata->address, sizeof(pdata->address)); + err = get_device_address(adapter->dev_id, adapter->address, sizeof(adapter->address)); if (err < 0) goto failed; @@ -651,7 +651,7 @@ int hcid_dbus_start_device(uint16_t id) } for (i = 0; i < cl->conn_num; i++, ci++) - active_conn_append(&pdata->active_conn, + active_conn_append(&adapter->active_conn, &ci->bdaddr, ci->handle); ret = 0; @@ -672,80 +672,80 @@ failed: int hcid_dbus_stop_device(uint16_t id) { char path[MAX_PATH_LENGTH]; - struct hci_dbus_data *pdata; + struct adapter *adapter; const char *scan_mode = MODE_OFF; DBusMessage *message; snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (!dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { + if (!dbus_connection_get_object_path_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); return -1; } /* cancel pending timeout */ - if (pdata->timeout_id) { - g_timeout_remove(pdata->timeout_id); - pdata->timeout_id = 0; + if (adapter->timeout_id) { + g_timeout_remove(adapter->timeout_id); + adapter->timeout_id = 0; } /* check pending requests */ - reply_pending_requests(path, pdata); + reply_pending_requests(path, adapter); - message = dev_signal_factory(pdata->dev_id, "ModeChanged", + message = dev_signal_factory(adapter->dev_id, "ModeChanged", DBUS_TYPE_STRING, &scan_mode, DBUS_TYPE_INVALID); send_reply_and_unref(connection, message); - cancel_passkey_agent_requests(pdata->passkey_agents, path, NULL); + cancel_passkey_agent_requests(adapter->passkey_agents, path, NULL); - release_passkey_agents(pdata, NULL); + release_passkey_agents(adapter, NULL); - if (pdata->discovery_requestor) { - name_listener_remove(connection, pdata->discovery_requestor, - (name_cb_t) discover_devices_req_exit, pdata); - free(pdata->discovery_requestor); - pdata->discovery_requestor = NULL; + if (adapter->discovery_requestor) { + name_listener_remove(connection, adapter->discovery_requestor, + (name_cb_t) discover_devices_req_exit, adapter); + free(adapter->discovery_requestor); + adapter->discovery_requestor = NULL; } - if (pdata->pdiscovery_requestor) { - name_listener_remove(connection, pdata->pdiscovery_requestor, - (name_cb_t) periodic_discover_req_exit, pdata); - free(pdata->pdiscovery_requestor); - pdata->pdiscovery_requestor = NULL; + if (adapter->pdiscovery_requestor) { + name_listener_remove(connection, adapter->pdiscovery_requestor, + (name_cb_t) periodic_discover_req_exit, adapter); + free(adapter->pdiscovery_requestor); + adapter->pdiscovery_requestor = NULL; } - if (pdata->disc_devices) { - slist_foreach(pdata->disc_devices, (slist_func_t) free, NULL); - slist_free(pdata->disc_devices); - pdata->disc_devices = NULL; + if (adapter->disc_devices) { + slist_foreach(adapter->disc_devices, (slist_func_t) free, NULL); + slist_free(adapter->disc_devices); + adapter->disc_devices = NULL; } - if (pdata->oor_devices) { - slist_foreach(pdata->oor_devices, (slist_func_t) free, NULL); - slist_free(pdata->oor_devices); - pdata->oor_devices = NULL; + if (adapter->oor_devices) { + slist_foreach(adapter->oor_devices, (slist_func_t) free, NULL); + slist_free(adapter->oor_devices); + adapter->oor_devices = NULL; } - if (pdata->pin_reqs) { - slist_foreach(pdata->pin_reqs, (slist_func_t) free, NULL); - slist_free(pdata->pin_reqs); - pdata->pin_reqs = NULL; + if (adapter->pin_reqs) { + slist_foreach(adapter->pin_reqs, (slist_func_t) free, NULL); + slist_free(adapter->pin_reqs); + adapter->pin_reqs = NULL; } - if (pdata->active_conn) { - slist_foreach(pdata->active_conn, (slist_func_t) free, NULL); - slist_free(pdata->active_conn); - pdata->active_conn = NULL; + if (adapter->active_conn) { + slist_foreach(adapter->active_conn, (slist_func_t) free, NULL); + slist_free(adapter->active_conn); + adapter->active_conn = NULL; } - pdata->up = 0; - pdata->mode = SCAN_DISABLED; - pdata->disc_active = 0; - pdata->pdisc_active = 0; - pdata->pinq_idle = 0; - pdata->discover_type = DISCOVER_TYPE_NONE; + adapter->up = 0; + adapter->mode = SCAN_DISABLED; + adapter->disc_active = 0; + adapter->pdisc_active = 0; + adapter->pinq_idle = 0; + adapter->discover_type = DISCOVER_TYPE_NONE; return 0; } @@ -761,14 +761,14 @@ int pin_req_cmp(const void *p1, const void *p2) void hcid_dbus_pending_pin_req_add(bdaddr_t *sba, bdaddr_t *dba) { char path[MAX_PATH_LENGTH], addr[18]; - struct hci_dbus_data *pdata; + struct adapter *adapter; struct pending_pin_info *info; ba2str(sba, addr); snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, hci_devid(addr)); - if (!dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { + if (!dbus_connection_get_object_path_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); return; } @@ -781,10 +781,10 @@ void hcid_dbus_pending_pin_req_add(bdaddr_t *sba, bdaddr_t *dba) memset(info, 0, sizeof(struct pending_pin_info)); bacpy(&info->bdaddr, dba); - pdata->pin_reqs = slist_append(pdata->pin_reqs, info); + adapter->pin_reqs = slist_append(adapter->pin_reqs, info); - if (pdata->bonding && !bacmp(dba, &pdata->bonding->bdaddr)) - pdata->bonding->auth_active = 1; + if (adapter->bonding && !bacmp(dba, &adapter->bonding->bdaddr)) + adapter->bonding->auth_active = 1; } int hcid_dbus_request_pin(int dev, bdaddr_t *sba, struct hci_conn_info *ci) @@ -800,7 +800,7 @@ int hcid_dbus_request_pin(int dev, bdaddr_t *sba, struct hci_conn_info *ci) void hcid_dbus_bonding_process_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t status) { - struct hci_dbus_data *pdata; + struct adapter *adapter; DBusMessage *message; char *local_addr, *peer_addr; struct slist *l; @@ -820,50 +820,50 @@ void hcid_dbus_bonding_process_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); /* create the authentication reply */ - if (!dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { + if (!dbus_connection_get_object_path_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); goto failed; } if (status) - cancel_passkey_agent_requests(pdata->passkey_agents, path, peer); + cancel_passkey_agent_requests(adapter->passkey_agents, path, peer); - l = slist_find(pdata->pin_reqs, peer, pin_req_cmp); + l = slist_find(adapter->pin_reqs, peer, pin_req_cmp); if (l) { void *d = l->data; - pdata->pin_reqs = slist_remove(pdata->pin_reqs, l->data); + adapter->pin_reqs = slist_remove(adapter->pin_reqs, l->data); free(d); if (!status) { - message = dev_signal_factory(pdata->dev_id, "BondingCreated", + message = dev_signal_factory(adapter->dev_id, "BondingCreated", DBUS_TYPE_STRING, &peer_addr, DBUS_TYPE_INVALID); send_reply_and_unref(connection, message); } } - release_passkey_agents(pdata, peer); + release_passkey_agents(adapter, peer); - if (!pdata->bonding || bacmp(&pdata->bonding->bdaddr, peer)) + if (!adapter->bonding || bacmp(&adapter->bonding->bdaddr, peer)) goto failed; /* skip: no bonding req pending */ - if (pdata->bonding->cancel) { + if (adapter->bonding->cancel) { /* reply authentication canceled */ - error_authentication_canceled(connection, pdata->bonding->rq); + error_authentication_canceled(connection, adapter->bonding->rq); } else { /* reply authentication success or an error */ - message = new_authentication_return(pdata->bonding->rq, status); + message = new_authentication_return(adapter->bonding->rq, status); send_reply_and_unref(connection, message); } - name_listener_remove(connection, dbus_message_get_sender(pdata->bonding->rq), - (name_cb_t) create_bond_req_exit, pdata); + name_listener_remove(connection, dbus_message_get_sender(adapter->bonding->rq), + (name_cb_t) create_bond_req_exit, adapter); - if (pdata->bonding->io_id) - g_io_remove_watch(pdata->bonding->io_id); - g_io_channel_close(pdata->bonding->io); - bonding_request_free(pdata->bonding); - pdata->bonding = NULL; + if (adapter->bonding->io_id) + g_io_remove_watch(adapter->bonding->io_id); + g_io_channel_close(adapter->bonding->io); + bonding_request_free(adapter->bonding); + adapter->bonding = NULL; failed: bt_free(local_addr); @@ -872,7 +872,7 @@ failed: void hcid_dbus_inquiry_start(bdaddr_t *local) { - struct hci_dbus_data *pdata; + struct adapter *adapter; DBusMessage *message; char path[MAX_PATH_LENGTH]; char *local_addr; @@ -889,21 +889,21 @@ void hcid_dbus_inquiry_start(bdaddr_t *local) snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { - pdata->disc_active = 1; + if (dbus_connection_get_object_path_data(connection, path, (void *) &adapter)) { + adapter->disc_active = 1; /* * Cancel pending remote name request and clean the device list * when inquiry is supported in periodic inquiry idle state. */ - if (pdata->pdisc_active) - pending_remote_name_cancel(pdata); + if (adapter->pdisc_active) + pending_remote_name_cancel(adapter); /* Disable name resolution for non D-Bus clients */ - if (!pdata->discovery_requestor) - pdata->discover_type &= ~RESOLVE_NAME; + if (!adapter->discovery_requestor) + adapter->discover_type &= ~RESOLVE_NAME; } - message = dev_signal_factory(pdata->dev_id, "DiscoveryStarted", + message = dev_signal_factory(adapter->dev_id, "DiscoveryStarted", DBUS_TYPE_INVALID); send_reply_and_unref(connection, message); @@ -912,7 +912,7 @@ failed: bt_free(local_addr); } -int disc_device_req_name(struct hci_dbus_data *dbus_data) +int disc_device_req_name(struct adapter *adapter) { struct hci_request rq; evt_cmd_status rp; @@ -922,19 +922,19 @@ int disc_device_req_name(struct hci_dbus_data *dbus_data) int dd, req_sent = 0; /* get the next remote address */ - if (!dbus_data->disc_devices) + if (!adapter->disc_devices) return -ENODATA; memset(&match, 0, sizeof(struct discovered_dev_info)); bacpy(&match.bdaddr, BDADDR_ANY); match.name_status = NAME_REQUIRED; - l = slist_find(dbus_data->disc_devices, &match, + l = slist_find(adapter->disc_devices, &match, (cmp_func_t) disc_device_find); if (!l) return -ENODATA; - dd = hci_open_dev(dbus_data->dev_id); + dd = hci_open_dev(adapter->dev_id); if (dd < 0) return -errno; @@ -966,7 +966,7 @@ int disc_device_req_name(struct hci_dbus_data *dbus_data) if (hci_send_req(dd, &rq, 500) < 0) { error("Unable to send the HCI remote name request: %s (%d)", strerror(errno), errno); - failed_signal = dev_signal_factory(dbus_data->dev_id, + failed_signal = dev_signal_factory(adapter->dev_id, "RemoteNameFailed", DBUS_TYPE_STRING, &peer_addr, DBUS_TYPE_INVALID); @@ -974,7 +974,7 @@ int disc_device_req_name(struct hci_dbus_data *dbus_data) if (rp.status) { error("Remote name request failed with status 0x%02x", rp.status); - failed_signal = dev_signal_factory(dbus_data->dev_id, + failed_signal = dev_signal_factory(adapter->dev_id, "RemoteNameFailed", DBUS_TYPE_STRING, &peer_addr, DBUS_TYPE_INVALID); @@ -992,11 +992,11 @@ int disc_device_req_name(struct hci_dbus_data *dbus_data) /* if failed, request the next element */ /* remove the element from the list */ - dbus_data->disc_devices = slist_remove(dbus_data->disc_devices, dev); + adapter->disc_devices = slist_remove(adapter->disc_devices, dev); free(dev); /* get the next element */ - l = slist_find(dbus_data->disc_devices, &match, + l = slist_find(adapter->disc_devices, &match, (cmp_func_t) disc_device_find); } while (l); @@ -1031,7 +1031,7 @@ static void send_out_of_range(const char *path, struct slist *l) void hcid_dbus_inquiry_complete(bdaddr_t *local) { DBusMessage *message; - struct hci_dbus_data *pdata; + struct adapter *adapter; struct slist *l; char path[MAX_PATH_LENGTH]; char *local_addr; @@ -1049,36 +1049,36 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local) snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (!dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { + if (!dbus_connection_get_object_path_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); goto done; } /* Out of range verification */ - if (pdata->pdisc_active && !pdata->disc_active) { - send_out_of_range(path, pdata->oor_devices); + if (adapter->pdisc_active && !adapter->disc_active) { + send_out_of_range(path, adapter->oor_devices); - slist_foreach(pdata->oor_devices, (slist_func_t) free, NULL); - slist_free(pdata->oor_devices); - pdata->oor_devices = NULL; + slist_foreach(adapter->oor_devices, (slist_func_t) free, NULL); + slist_free(adapter->oor_devices); + adapter->oor_devices = NULL; - l = pdata->disc_devices; + l = adapter->disc_devices; while (l) { dev = l->data; baswap(&tmp, &dev->bdaddr); - pdata->oor_devices = slist_append(pdata->oor_devices, batostr(&tmp)); + adapter->oor_devices = slist_append(adapter->oor_devices, batostr(&tmp)); l = l->next; } } - pdata->pinq_idle = 1; + adapter->pinq_idle = 1; /* * Enable resolution again: standard inquiry can be * received in the periodic inquiry idle state. */ - if (pdata->pdiscovery_requestor) - pdata->discover_type |= RESOLVE_NAME; + if (adapter->pdiscovery_requestor) + adapter->discover_type |= RESOLVE_NAME; /* * The following scenarios can happen: @@ -1092,38 +1092,38 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local) * Keep in mind that non D-Bus requests can arrive. */ - if (!disc_device_req_name(pdata)) + if (!disc_device_req_name(adapter)) goto done; /* skip - there is name to resolve */ - if (pdata->disc_active) { + if (adapter->disc_active) { message = dbus_message_new_signal(path, ADAPTER_INTERFACE, "DiscoveryCompleted"); send_reply_and_unref(connection, message); - pdata->disc_active = 0; + adapter->disc_active = 0; } /* free discovered devices list */ - slist_foreach(pdata->disc_devices, (slist_func_t) free, NULL); - slist_free(pdata->disc_devices); - pdata->disc_devices = NULL; + slist_foreach(adapter->disc_devices, (slist_func_t) free, NULL); + slist_free(adapter->disc_devices); + adapter->disc_devices = NULL; - if (pdata->discovery_requestor) { - name_listener_remove(connection, pdata->discovery_requestor, - (name_cb_t) discover_devices_req_exit, pdata); - free(pdata->discovery_requestor); - pdata->discovery_requestor = NULL; + if (adapter->discovery_requestor) { + name_listener_remove(connection, adapter->discovery_requestor, + (name_cb_t) discover_devices_req_exit, adapter); + free(adapter->discovery_requestor); + adapter->discovery_requestor = NULL; /* If there is a pending reply for discovery cancel */ - if (pdata->discovery_cancel) { - message = dbus_message_new_method_return(pdata->discovery_cancel); + if (adapter->discovery_cancel) { + message = dbus_message_new_method_return(adapter->discovery_cancel); send_reply_and_unref(connection, message); - dbus_message_unref(pdata->discovery_cancel); - pdata->discovery_cancel = NULL; + dbus_message_unref(adapter->discovery_cancel); + adapter->discovery_cancel = NULL; } /* reset the discover type for standard inquiry only */ - pdata->discover_type &= ~STD_INQUIRY; + adapter->discover_type &= ~STD_INQUIRY; } done: @@ -1132,7 +1132,7 @@ done: void hcid_dbus_periodic_inquiry_start(bdaddr_t *local, uint8_t status) { - struct hci_dbus_data *pdata; + struct adapter *adapter; DBusMessage *message; char path[MAX_PATH_LENGTH]; char *local_addr; @@ -1153,12 +1153,12 @@ void hcid_dbus_periodic_inquiry_start(bdaddr_t *local, uint8_t status) snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { - pdata->pdisc_active = 1; + if (dbus_connection_get_object_path_data(connection, path, (void *) &adapter)) { + adapter->pdisc_active = 1; /* Disable name resolution for non D-Bus clients */ - if (!pdata->pdiscovery_requestor) - pdata->discover_type &= ~RESOLVE_NAME; + if (!adapter->pdiscovery_requestor) + adapter->discover_type &= ~RESOLVE_NAME; } message = dbus_message_new_signal(path, ADAPTER_INTERFACE, @@ -1172,7 +1172,7 @@ failed: void hcid_dbus_periodic_inquiry_exit(bdaddr_t *local, uint8_t status) { DBusMessage *message; - struct hci_dbus_data *pdata; + struct adapter *adapter; char path[MAX_PATH_LENGTH]; char *local_addr; bdaddr_t tmp; @@ -1192,39 +1192,39 @@ void hcid_dbus_periodic_inquiry_exit(bdaddr_t *local, uint8_t status) snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (!dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { + if (!dbus_connection_get_object_path_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); goto done; } /* reset the discover type to be able to handle D-Bus and non D-Bus requests */ - pdata->pdisc_active = 0; - pdata->discover_type &= ~(PERIODIC_INQUIRY | RESOLVE_NAME); + adapter->pdisc_active = 0; + adapter->discover_type &= ~(PERIODIC_INQUIRY | RESOLVE_NAME); /* free discovered devices list */ - slist_foreach(pdata->disc_devices, (slist_func_t) free, NULL); - slist_free(pdata->disc_devices); - pdata->disc_devices = NULL; + slist_foreach(adapter->disc_devices, (slist_func_t) free, NULL); + slist_free(adapter->disc_devices); + adapter->disc_devices = NULL; /* free out of range devices list */ - slist_foreach(pdata->oor_devices, (slist_func_t) free, NULL); - slist_free(pdata->oor_devices); - pdata->oor_devices = NULL; + slist_foreach(adapter->oor_devices, (slist_func_t) free, NULL); + slist_free(adapter->oor_devices); + adapter->oor_devices = NULL; - if (pdata->pdiscovery_requestor) { - name_listener_remove(connection, pdata->pdiscovery_requestor, - (name_cb_t) periodic_discover_req_exit, pdata); - free(pdata->pdiscovery_requestor); - pdata->pdiscovery_requestor = NULL; + if (adapter->pdiscovery_requestor) { + name_listener_remove(connection, adapter->pdiscovery_requestor, + (name_cb_t) periodic_discover_req_exit, adapter); + free(adapter->pdiscovery_requestor); + adapter->pdiscovery_requestor = NULL; } /* workaround: inquiry completed is not sent when exiting from periodic inquiry */ - if (pdata->disc_active) { + if (adapter->disc_active) { message = dbus_message_new_signal(path, ADAPTER_INTERFACE, "DiscoveryCompleted"); send_reply_and_unref(connection, message); - pdata->disc_active = 0; + adapter->disc_active = 0; } /* Send discovery completed signal if there isn't name to resolve */ @@ -1260,7 +1260,7 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class, i DBusMessage *signal_device; DBusMessage *signal_name; char path[MAX_PATH_LENGTH]; - struct hci_dbus_data *pdata; + struct adapter *adapter; struct slist *l; struct discovered_dev_info match; char *local_addr, *peer_addr, *name, *tmp_name; @@ -1282,7 +1282,7 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class, i snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (!dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { + if (!dbus_connection_get_object_path_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); goto done; } @@ -1293,21 +1293,21 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class, i * workaround to identify situation when the daemon started and * a standard inquiry or periodic inquiry was already running */ - if (!pdata->disc_active && !pdata->pdisc_active) - pdata->pdisc_active = 1; + if (!adapter->disc_active && !adapter->pdisc_active) + adapter->pdisc_active = 1; /* reset the idle flag when the inquiry complete event arrives */ - if (pdata->pdisc_active) { - pdata->pinq_idle = 0; + if (adapter->pdisc_active) { + adapter->pinq_idle = 0; /* Out of range list update */ - l = slist_find(pdata->oor_devices, peer_addr, (cmp_func_t) strcmp); + l = slist_find(adapter->oor_devices, peer_addr, (cmp_func_t) strcmp); if (l) - pdata->oor_devices = slist_remove(pdata->oor_devices, l->data); + adapter->oor_devices = slist_remove(adapter->oor_devices, l->data); } /* send the device found signal */ - signal_device = dev_signal_factory(pdata->dev_id, "RemoteDeviceFound", + signal_device = dev_signal_factory(adapter->dev_id, "RemoteDeviceFound", DBUS_TYPE_STRING, &peer_addr, DBUS_TYPE_UINT32, &tmp_class, DBUS_TYPE_INT16, &tmp_rssi, @@ -1319,12 +1319,12 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class, i bacpy(&match.bdaddr, peer); match.name_status = NAME_SENT; /* if found: don't sent the name again */ - l = slist_find(pdata->disc_devices, &match, (cmp_func_t) disc_device_find); + l = slist_find(adapter->disc_devices, &match, (cmp_func_t) disc_device_find); if (l) goto done; /* the inquiry result can be triggered by NON D-Bus client */ - if (pdata->discover_type & RESOLVE_NAME) + if (adapter->discover_type & RESOLVE_NAME) name_status = NAME_REQUIRED; else name_status = NAME_NOT_REQUIRED; @@ -1351,7 +1351,7 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class, i } if (name) { - signal_name = dev_signal_factory(pdata->dev_id, "RemoteNameUpdated", + signal_name = dev_signal_factory(adapter->dev_id, "RemoteNameUpdated", DBUS_TYPE_STRING, &peer_addr, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID); @@ -1364,7 +1364,7 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class, i } /* add in the list to track name sent/pending */ - disc_device_append(&pdata->disc_devices, peer, name_status); + disc_device_append(&adapter->disc_devices, peer, name_status); done: bt_free(local_addr); @@ -1373,7 +1373,7 @@ done: void hcid_dbus_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t class) { - struct hci_dbus_data *pdata; + struct adapter *adapter; DBusMessage *message; char path[MAX_PATH_LENGTH]; char *local_addr, *peer_addr; @@ -1397,10 +1397,10 @@ void hcid_dbus_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t class) snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) + if (dbus_connection_get_object_path_data(connection, path, (void *) &adapter)) goto failed; - message = dev_signal_factory(pdata->dev_id, "RemoteClassUpdated", + message = dev_signal_factory(adapter->dev_id, "RemoteClassUpdated", DBUS_TYPE_STRING, &peer_addr, DBUS_TYPE_UINT32, &tmp_class, DBUS_TYPE_INVALID); @@ -1414,7 +1414,7 @@ failed: void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status, char *name) { - struct hci_dbus_data *pdata; + struct adapter *adapter; DBusMessage *message; char path[MAX_PATH_LENGTH]; char *local_addr, *peer_addr; @@ -1432,18 +1432,18 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status, char snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (!dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { + if (!dbus_connection_get_object_path_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); goto done; } if (status) - message = dev_signal_factory(pdata->dev_id, + message = dev_signal_factory(adapter->dev_id, "RemoteNameFailed", DBUS_TYPE_STRING, &peer_addr, DBUS_TYPE_INVALID); else - message = dev_signal_factory(pdata->dev_id, + message = dev_signal_factory(adapter->dev_id, "RemoteNameUpdated", DBUS_TYPE_STRING, &peer_addr, DBUS_TYPE_STRING, &name, @@ -1452,46 +1452,46 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status, char send_reply_and_unref(connection, message); /* remove from remote name request list */ - disc_device_remove(&pdata->disc_devices, peer); + disc_device_remove(&adapter->disc_devices, peer); /* check if there is more devices to request names */ - if (!disc_device_req_name(pdata)) + if (!disc_device_req_name(adapter)) goto done; /* skip if a new request has been sent */ /* free discovered devices list */ - slist_foreach(pdata->disc_devices, (slist_func_t) free, NULL); - slist_free(pdata->disc_devices); - pdata->disc_devices = NULL; + slist_foreach(adapter->disc_devices, (slist_func_t) free, NULL); + slist_free(adapter->disc_devices); + adapter->disc_devices = NULL; /* * The discovery completed signal must be sent only for discover * devices request WITH name resolving */ - if (pdata->discovery_requestor) { - name_listener_remove(connection, pdata->discovery_requestor, - (name_cb_t) discover_devices_req_exit, pdata); - free(pdata->discovery_requestor); - pdata->discovery_requestor = NULL; + if (adapter->discovery_requestor) { + name_listener_remove(connection, adapter->discovery_requestor, + (name_cb_t) discover_devices_req_exit, adapter); + free(adapter->discovery_requestor); + adapter->discovery_requestor = NULL; /* If there is a pending reply for discovery cancel */ - if (pdata->discovery_cancel) { - message = dbus_message_new_method_return(pdata->discovery_cancel); + if (adapter->discovery_cancel) { + message = dbus_message_new_method_return(adapter->discovery_cancel); send_reply_and_unref(connection, message); - dbus_message_unref(pdata->discovery_cancel); - pdata->discovery_cancel = NULL; + dbus_message_unref(adapter->discovery_cancel); + adapter->discovery_cancel = NULL; } /* Disable name resolution for non D-Bus clients */ - if (!pdata->pdiscovery_requestor) - pdata->discover_type &= ~RESOLVE_NAME; + if (!adapter->pdiscovery_requestor) + adapter->discover_type &= ~RESOLVE_NAME; } - if (pdata->disc_active) { + if (adapter->disc_active) { message = dbus_message_new_signal(path, ADAPTER_INTERFACE, "DiscoveryCompleted"); send_reply_and_unref(connection, message); - pdata->disc_active = 0; + adapter->disc_active = 0; } done: @@ -1503,7 +1503,7 @@ void hcid_dbus_conn_complete(bdaddr_t *local, uint8_t status, uint16_t handle, b { char path[MAX_PATH_LENGTH]; DBusMessage *message; - struct hci_dbus_data *pdata; + struct adapter *adapter; char *local_addr, *peer_addr; bdaddr_t tmp; int id; @@ -1519,7 +1519,7 @@ void hcid_dbus_conn_complete(bdaddr_t *local, uint8_t status, uint16_t handle, b snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (!dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { + if (!dbus_connection_get_object_path_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); goto done; } @@ -1527,28 +1527,28 @@ void hcid_dbus_conn_complete(bdaddr_t *local, uint8_t status, uint16_t handle, b if (status) { struct slist *l; - cancel_passkey_agent_requests(pdata->passkey_agents, path, peer); - release_passkey_agents(pdata, peer); + cancel_passkey_agent_requests(adapter->passkey_agents, path, peer); + release_passkey_agents(adapter, peer); - l = slist_find(pdata->pin_reqs, peer, pin_req_cmp); + l = slist_find(adapter->pin_reqs, peer, pin_req_cmp); if (l) { struct pending_pin_req *p = l->data; - pdata->pin_reqs = slist_remove(pdata->pin_reqs, p); + adapter->pin_reqs = slist_remove(adapter->pin_reqs, p); free(p); } - if (pdata->bonding) - pdata->bonding->hci_status = status; + if (adapter->bonding) + adapter->bonding->hci_status = status; } else { /* Sent the remote device connected signal */ - message = dev_signal_factory(pdata->dev_id, "RemoteDeviceConnected", + message = dev_signal_factory(adapter->dev_id, "RemoteDeviceConnected", DBUS_TYPE_STRING, &peer_addr, DBUS_TYPE_INVALID); send_reply_and_unref(connection, message); /* add in the active connetions list */ - active_conn_append(&pdata->active_conn, peer, handle); + active_conn_append(&adapter->active_conn, peer, handle); } done: @@ -1559,7 +1559,7 @@ done: void hcid_dbus_disconn_complete(bdaddr_t *local, uint8_t status, uint16_t handle, uint8_t reason) { char path[MAX_PATH_LENGTH]; - struct hci_dbus_data *pdata; + struct adapter *adapter; struct active_conn_info *dev; DBusMessage *message; struct slist *l; @@ -1582,12 +1582,12 @@ void hcid_dbus_disconn_complete(bdaddr_t *local, uint8_t status, uint16_t handle snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (!dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { + if (!dbus_connection_get_object_path_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); goto failed; } - l = slist_find(pdata->active_conn, &handle, active_conn_find_by_handle); + l = slist_find(adapter->active_conn, &handle, active_conn_find_by_handle); if (!l) goto failed; @@ -1597,44 +1597,44 @@ void hcid_dbus_disconn_complete(bdaddr_t *local, uint8_t status, uint16_t handle baswap(&tmp, &dev->bdaddr); peer_addr = batostr(&tmp); /* clean pending HCI cmds */ - hci_req_queue_remove(pdata->dev_id, &dev->bdaddr); + hci_req_queue_remove(adapter->dev_id, &dev->bdaddr); /* Cancel D-Bus/non D-Bus requests */ - cancel_passkey_agent_requests(pdata->passkey_agents, path, &dev->bdaddr); - release_passkey_agents(pdata, &dev->bdaddr); + cancel_passkey_agent_requests(adapter->passkey_agents, path, &dev->bdaddr); + release_passkey_agents(adapter, &dev->bdaddr); - l = slist_find(pdata->pin_reqs, &dev->bdaddr, pin_req_cmp); + l = slist_find(adapter->pin_reqs, &dev->bdaddr, pin_req_cmp); if (l) { struct pending_pin_req *p = l->data; - pdata->pin_reqs = slist_remove(pdata->pin_reqs, p); + adapter->pin_reqs = slist_remove(adapter->pin_reqs, p); free(p); } /* Check if there is a pending CreateBonding request */ - if (pdata->bonding && (bacmp(&pdata->bonding->bdaddr, &dev->bdaddr) == 0)) { - if (pdata->bonding->cancel) { + if (adapter->bonding && (bacmp(&adapter->bonding->bdaddr, &dev->bdaddr) == 0)) { + if (adapter->bonding->cancel) { /* reply authentication canceled */ - error_authentication_canceled(connection, pdata->bonding->rq); + error_authentication_canceled(connection, adapter->bonding->rq); } else { - message = new_authentication_return(pdata->bonding->rq, HCI_AUTHENTICATION_FAILURE); + message = new_authentication_return(adapter->bonding->rq, HCI_AUTHENTICATION_FAILURE); send_reply_and_unref(connection, message); } - name_listener_remove(connection, dbus_message_get_sender(pdata->bonding->rq), - (name_cb_t) create_bond_req_exit, pdata); - if (pdata->bonding->io_id) - g_io_remove_watch(pdata->bonding->io_id); - g_io_channel_close(pdata->bonding->io); - bonding_request_free(pdata->bonding); - pdata->bonding = NULL; + name_listener_remove(connection, dbus_message_get_sender(adapter->bonding->rq), + (name_cb_t) create_bond_req_exit, adapter); + if (adapter->bonding->io_id) + g_io_remove_watch(adapter->bonding->io_id); + g_io_channel_close(adapter->bonding->io); + bonding_request_free(adapter->bonding); + adapter->bonding = NULL; } /* Sent the remote device disconnected signal */ - message = dev_signal_factory(pdata->dev_id, "RemoteDeviceDisconnected", + message = dev_signal_factory(adapter->dev_id, "RemoteDeviceDisconnected", DBUS_TYPE_STRING, &peer_addr, DBUS_TYPE_INVALID); send_reply_and_unref(connection, message); - active_conn_remove(&pdata->active_conn, &handle); + active_conn_remove(&adapter->active_conn, &handle); failed: if (peer_addr) @@ -1882,18 +1882,18 @@ done: gboolean discoverable_timeout_handler(void *data) { - struct hci_dbus_data *dbus_data = data; + struct adapter *adapter = data; struct hci_request rq; int dd; - uint8_t hci_mode = dbus_data->mode; + uint8_t hci_mode = adapter->mode; uint8_t status = 0; gboolean retval = TRUE; hci_mode &= ~SCAN_INQUIRY; - dd = hci_open_dev(dbus_data->dev_id); + dd = hci_open_dev(adapter->dev_id); if (dd < 0) { - error("HCI device open failed: hci%d", dbus_data->dev_id); + error("HCI device open failed: hci%d", adapter->dev_id); return TRUE; } @@ -1908,7 +1908,7 @@ gboolean discoverable_timeout_handler(void *data) if (hci_send_req(dd, &rq, 1000) < 0) { error("Sending write scan enable command to hci%d failed: %s (%d)", - dbus_data->dev_id, strerror(errno), errno); + adapter->dev_id, strerror(errno), errno); goto failed; } if (status) { @@ -1916,7 +1916,7 @@ gboolean discoverable_timeout_handler(void *data) goto failed; } - dbus_data->timeout_id = 0; + adapter->timeout_id = 0; retval = FALSE; failed: @@ -2077,7 +2077,7 @@ failed: void hcid_dbus_setscan_enable_complete(bdaddr_t *local) { DBusMessage *message; - struct hci_dbus_data *pdata; + struct adapter *adapter; char *local_addr; char path[MAX_PATH_LENGTH]; bdaddr_t tmp; @@ -2120,17 +2120,17 @@ void hcid_dbus_setscan_enable_complete(bdaddr_t *local) goto failed; } - if (!dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { + if (!dbus_connection_get_object_path_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); goto failed; } /* update the current scan mode value */ - pdata->mode = rp.enable; + adapter->mode = rp.enable; - if (pdata->timeout_id) { - g_timeout_remove(pdata->timeout_id); - pdata->timeout_id = 0; + if (adapter->timeout_id) { + g_timeout_remove(adapter->timeout_id); + adapter->timeout_id = 0; } switch (rp.enable) { @@ -2142,15 +2142,15 @@ void hcid_dbus_setscan_enable_complete(bdaddr_t *local) break; case (SCAN_PAGE | SCAN_INQUIRY): scan_mode = MODE_DISCOVERABLE; - if (pdata->discoverable_timeout != 0) - pdata->timeout_id = g_timeout_add(pdata->discoverable_timeout * 1000, - discoverable_timeout_handler, pdata); + if (adapter->discoverable_timeout != 0) + adapter->timeout_id = g_timeout_add(adapter->discoverable_timeout * 1000, + discoverable_timeout_handler, adapter); break; case SCAN_INQUIRY: /* Address the scenario where another app changed the scan mode */ - if (pdata->discoverable_timeout != 0) - pdata->timeout_id = g_timeout_add(pdata->discoverable_timeout * 1000, - discoverable_timeout_handler, pdata); + if (adapter->discoverable_timeout != 0) + adapter->timeout_id = g_timeout_add(adapter->discoverable_timeout * 1000, + discoverable_timeout_handler, adapter); /* ignore, this event should not be sent*/ default: /* ignore, reserved */ @@ -2159,7 +2159,7 @@ void hcid_dbus_setscan_enable_complete(bdaddr_t *local) write_device_mode(local, scan_mode); - message = dev_signal_factory(pdata->dev_id, "ModeChanged", + message = dev_signal_factory(adapter->dev_id, "ModeChanged", DBUS_TYPE_STRING, &scan_mode, DBUS_TYPE_INVALID); send_reply_and_unref(connection, message); @@ -2179,7 +2179,7 @@ void hcid_dbus_pin_code_reply(bdaddr_t *local, void *ptr) bdaddr_t bdaddr; } __attribute__ ((packed)) ret_pin_code_req_reply; - struct hci_dbus_data *pdata; + struct adapter *adapter; char *local_addr; ret_pin_code_req_reply *ret = ptr + EVT_CMD_COMPLETE_SIZE; struct slist *l; @@ -2196,12 +2196,12 @@ void hcid_dbus_pin_code_reply(bdaddr_t *local, void *ptr) snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (!dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { + if (!dbus_connection_get_object_path_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); goto failed; } - l = slist_find(pdata->pin_reqs, &ret->bdaddr, pin_req_cmp); + l = slist_find(adapter->pin_reqs, &ret->bdaddr, pin_req_cmp); if (l) { struct pending_pin_info *p = l->data; p->replied = 1; @@ -2211,45 +2211,45 @@ failed: bt_free(local_addr); } -void create_bond_req_exit(const char *name, struct hci_dbus_data *pdata) +void create_bond_req_exit(const char *name, struct adapter *adapter) { char path[MAX_PATH_LENGTH]; struct slist *l; - snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, pdata->dev_id); + snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, adapter->dev_id); debug("CreateConnection requestor at %s exited before bonding was completed", name); - cancel_passkey_agent_requests(pdata->passkey_agents, path, &pdata->bonding->bdaddr); - release_passkey_agents(pdata, &pdata->bonding->bdaddr); + cancel_passkey_agent_requests(adapter->passkey_agents, path, &adapter->bonding->bdaddr); + release_passkey_agents(adapter, &adapter->bonding->bdaddr); - l = slist_find(pdata->pin_reqs, &pdata->bonding->bdaddr, pin_req_cmp); + l = slist_find(adapter->pin_reqs, &adapter->bonding->bdaddr, pin_req_cmp); if (l) { struct pending_pin_info *p = l->data; if (!p->replied) { int dd; - dd = hci_open_dev(pdata->dev_id); + dd = hci_open_dev(adapter->dev_id); if (dd >= 0) { hci_send_cmd(dd, OGF_LINK_CTL, OCF_PIN_CODE_NEG_REPLY, - 6, &pdata->bonding->bdaddr); + 6, &adapter->bonding->bdaddr); hci_close_dev(dd); } } - pdata->pin_reqs = slist_remove(pdata->pin_reqs, p); + adapter->pin_reqs = slist_remove(adapter->pin_reqs, p); free(p); } - g_io_channel_close(pdata->bonding->io); - if (pdata->bonding->io_id) - g_io_remove_watch(pdata->bonding->io_id); - bonding_request_free(pdata->bonding); - pdata->bonding = NULL; + g_io_channel_close(adapter->bonding->io); + if (adapter->bonding->io_id) + g_io_remove_watch(adapter->bonding->io_id); + bonding_request_free(adapter->bonding); + adapter->bonding = NULL; } -void discover_devices_req_exit(const char *name, struct hci_dbus_data *pdata) +void discover_devices_req_exit(const char *name, struct adapter *adapter) { debug("DiscoverDevices requestor at %s exited before the operation finished", name); @@ -2258,7 +2258,7 @@ void discover_devices_req_exit(const char *name, struct hci_dbus_data *pdata) * cancel inquiry or cancel remote name request. The return * can be ignored. */ - cancel_discovery(pdata); + cancel_discovery(adapter); } static int inquiry_cancel(int dd, int to) @@ -2314,16 +2314,16 @@ static int remote_name_cancel(int dd, bdaddr_t *dba, int to) return 0; } -int cancel_discovery(struct hci_dbus_data *pdata) +int cancel_discovery(struct adapter *adapter) { struct discovered_dev_info *dev, match; struct slist *l; int dd, err = 0; - if (!pdata->disc_active) + if (!adapter->disc_active) goto cleanup; - dd = hci_open_dev(pdata->dev_id); + dd = hci_open_dev(adapter->dev_id); if (dd < 0) { err = -ENODEV; goto cleanup; @@ -2337,7 +2337,7 @@ int cancel_discovery(struct hci_dbus_data *pdata) bacpy(&match.bdaddr, BDADDR_ANY); match.name_status = NAME_REQUESTED; - l = slist_find(pdata->disc_devices, &match, + l = slist_find(adapter->disc_devices, &match, (cmp_func_t) disc_device_find); if (l) { dev = l->data; @@ -2361,18 +2361,18 @@ cleanup: * Reset discovery_requestor and discover_state in the remote name * request event handler or in the inquiry complete handler. */ - slist_foreach(pdata->disc_devices, (slist_func_t) free, NULL); - slist_free(pdata->disc_devices); - pdata->disc_devices = NULL; + slist_foreach(adapter->disc_devices, (slist_func_t) free, NULL); + slist_free(adapter->disc_devices); + adapter->disc_devices = NULL; /* Disable name resolution for non D-Bus clients */ - if (!pdata->pdiscovery_requestor) - pdata->discover_type &= ~RESOLVE_NAME; + if (!adapter->pdiscovery_requestor) + adapter->discover_type &= ~RESOLVE_NAME; return err; } -void periodic_discover_req_exit(const char *name, struct hci_dbus_data *pdata) +void periodic_discover_req_exit(const char *name, struct adapter *adapter) { debug("Periodic Discover requestor at %s exited before the operation finishes", name); @@ -2381,7 +2381,7 @@ void periodic_discover_req_exit(const char *name, struct hci_dbus_data *pdata) * or cancel remote name request. The return value can be ignored. */ - cancel_periodic_discovery(pdata); + cancel_periodic_discovery(adapter); } static int periodic_inquiry_exit(int dd, int to) @@ -2407,16 +2407,16 @@ static int periodic_inquiry_exit(int dd, int to) return 0; } -int cancel_periodic_discovery(struct hci_dbus_data *pdata) +int cancel_periodic_discovery(struct adapter *adapter) { struct discovered_dev_info *dev, match; struct slist *l; int dd, err = 0; - if (!pdata->pdisc_active) + if (!adapter->pdisc_active) goto cleanup; - dd = hci_open_dev(pdata->dev_id); + dd = hci_open_dev(adapter->dev_id); if (dd < 0) { err = -ENODEV; goto cleanup; @@ -2426,7 +2426,7 @@ int cancel_periodic_discovery(struct hci_dbus_data *pdata) bacpy(&match.bdaddr, BDADDR_ANY); match.name_status = NAME_REQUESTED; - l = slist_find(pdata->disc_devices, &match, (cmp_func_t) disc_device_find); + l = slist_find(adapter->disc_devices, &match, (cmp_func_t) disc_device_find); if (l) { dev = l->data; if (remote_name_cancel(dd, &dev->bdaddr, 1000) < 0) { @@ -2447,9 +2447,9 @@ cleanup: * Reset pdiscovery_requestor and pdisc_active is done when the * cmd complete event for exit periodic inquiry mode cmd arrives. */ - slist_foreach(pdata->disc_devices, (slist_func_t) free, NULL); - slist_free(pdata->disc_devices); - pdata->disc_devices = NULL; + slist_foreach(adapter->disc_devices, (slist_func_t) free, NULL); + slist_free(adapter->disc_devices); + adapter->disc_devices = NULL; return err; } diff --git a/hcid/dbus.h b/hcid/dbus.h index 16951e3b..c000131d 100644 --- a/hcid/dbus.h +++ b/hcid/dbus.h @@ -105,7 +105,7 @@ struct active_conn_info { uint16_t handle; }; -struct hci_dbus_data { +struct adapter { uint16_t dev_id; int up; char address[18]; /* adapter Bluetooth Address */ @@ -128,7 +128,7 @@ struct hci_dbus_data { }; struct passkey_agent { - struct hci_dbus_data *pdata; + struct adapter *adapter; DBusConnection *conn; char *addr; char *name; @@ -222,16 +222,16 @@ DBusHandlerResult simple_introspect(DBusConnection *conn, DBusMessage *msg, void service_handler_func_t find_service_handler(struct service_data *services, DBusMessage *msg); int str2uuid(uuid_t *uuid, const char *string); -void create_bond_req_exit(const char *name, struct hci_dbus_data *pdata); -void discover_devices_req_exit(const char *name, struct hci_dbus_data *pdata); -int cancel_discovery(struct hci_dbus_data *pdata); -void periodic_discover_req_exit(const char *name, struct hci_dbus_data *pdata); -int cancel_periodic_discovery(struct hci_dbus_data *pdata); -int pending_remote_name_cancel(struct hci_dbus_data *pdata); +void create_bond_req_exit(const char *name, struct adapter *adapter); +void discover_devices_req_exit(const char *name, struct adapter *adapter); +int cancel_discovery(struct adapter *adapter); +void periodic_discover_req_exit(const char *name, struct adapter *adapter); +int cancel_periodic_discovery(struct adapter *adapter); +int pending_remote_name_cancel(struct adapter *adapter); int handle_passkey_request(DBusConnection *conn, int dev, const char *path, bdaddr_t *sba, bdaddr_t *dba); void release_default_agent(void); -void release_passkey_agents(struct hci_dbus_data *pdata, bdaddr_t *bda); +void release_passkey_agents(struct adapter *adapter, bdaddr_t *bda); void cancel_passkey_agent_requests(struct slist *agents, const char *path, bdaddr_t *dba); static inline DBusHandlerResult send_reply_and_unref(DBusConnection *conn, DBusMessage *reply) @@ -250,7 +250,7 @@ void bonding_request_free(struct bonding_request_info *dev); int pin_req_cmp(const void *p1, const void *p2); int disc_device_find(const struct discovered_dev_info *d1, const struct discovered_dev_info *d2); int disc_device_append(struct slist **list, bdaddr_t *bdaddr, name_status_t name_status); -int disc_device_req_name(struct hci_dbus_data *dbus_data); +int disc_device_req_name(struct adapter *dbus_data); int discoverable_timeout_handler(void *data); |