summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hcid/adapter.c121
-rw-r--r--hcid/dbus-hci.c86
-rw-r--r--hcid/device.c2
3 files changed, 190 insertions, 19 deletions
diff --git a/hcid/adapter.c b/hcid/adapter.c
index bd80023f..6bd17750 100644
--- a/hcid/adapter.c
+++ b/hcid/adapter.c
@@ -720,6 +720,37 @@ static DBusHandlerResult adapter_get_discoverable_to(DBusConnection *conn,
return send_message_and_unref(conn, reply);
}
+static void resolve_paths(DBusMessage *msg, char **old_path, char **new_path)
+{
+ const char *path = dbus_message_get_path(msg);
+
+ if (!path)
+ return;
+
+ if (old_path)
+ *old_path = NULL;
+
+ if (new_path)
+ *new_path = NULL;
+
+ /* old path calls */
+ if (g_str_has_prefix(path, BASE_PATH)) {
+ if (old_path)
+ *old_path = g_strdup(path);
+
+ if (hcid_dbus_use_experimental() && new_path)
+ *new_path = g_strdup(path + ADAPTER_PATH_INDEX);
+
+ return;
+ }
+
+ if (old_path)
+ *old_path = g_strconcat(BASE_PATH, path);
+
+ if (new_path)
+ *new_path = g_strdup(path);
+}
+
static DBusHandlerResult set_discoverable_timeout(DBusConnection *conn,
DBusMessage *msg,
uint32_t timeout,
@@ -728,6 +759,7 @@ static DBusHandlerResult set_discoverable_timeout(DBusConnection *conn,
struct adapter *adapter = data;
DBusMessage *reply;
bdaddr_t bdaddr;
+ char *old_path, *new_path;
reply = dbus_message_new_method_return(msg);
if (!reply)
@@ -748,19 +780,22 @@ static DBusHandlerResult set_discoverable_timeout(DBusConnection *conn,
str2ba(adapter->address, &bdaddr);
write_discoverable_timeout(&bdaddr, timeout);
- dbus_connection_emit_signal(conn, dbus_message_get_path(msg),
+ resolve_paths(msg, &old_path, &new_path);
+
+ dbus_connection_emit_signal(conn, old_path,
ADAPTER_INTERFACE,
"DiscoverableTimeoutChanged",
DBUS_TYPE_UINT32, &timeout,
DBUS_TYPE_INVALID);
- if (hcid_dbus_use_experimental()) {
- dbus_connection_emit_property_changed(conn,
- dbus_message_get_path(msg),
+ if (new_path) {
+ dbus_connection_emit_property_changed(conn, new_path,
ADAPTER_INTERFACE,
"DiscoverableTimeout",
DBUS_TYPE_UINT32, &timeout);
}
+ g_free(old_path);
+ g_free(new_path);
return send_message_and_unref(conn, reply);
}
@@ -1152,6 +1187,7 @@ static int set_name(DBusConnection *conn, DBusMessage *msg, const char *name,
DBusMessage *reply;
bdaddr_t bdaddr;
int ecode;
+ char *new_path;
if (!g_utf8_validate(name, -1, NULL)) {
error("Name change failed: the supplied name isn't valid UTF-8");
@@ -1174,14 +1210,16 @@ done:
if (!reply)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
- if (hcid_dbus_use_experimental()) {
- dbus_connection_emit_property_changed(conn,
- dbus_message_get_path(msg),
+ resolve_paths(msg, NULL, &new_path);
+
+ if (new_path) {
+ dbus_connection_emit_property_changed(conn, new_path,
ADAPTER_INTERFACE,
"Name", DBUS_TYPE_STRING,
&name);
}
+ g_free(new_path);
return send_message_and_unref(conn, reply);
}
@@ -1855,7 +1893,7 @@ static DBusHandlerResult adapter_set_remote_alias(DBusConnection *conn,
{
struct adapter *adapter = data;
DBusMessage *reply;
- char *alias, *addr;
+ char *alias, *addr, *old_path, *new_path;
bdaddr_t bdaddr;
int ecode;
@@ -1880,12 +1918,27 @@ static DBusHandlerResult adapter_set_remote_alias(DBusConnection *conn,
if (!reply)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
- dbus_connection_emit_signal(conn, dbus_message_get_path(msg),
+ resolve_paths(msg, &old_path, &new_path);
+
+ dbus_connection_emit_signal(conn, old_path,
ADAPTER_INTERFACE, "RemoteAliasChanged",
DBUS_TYPE_STRING, &addr,
DBUS_TYPE_STRING, &alias,
DBUS_TYPE_INVALID);
+ if (new_path) {
+ struct device *device;
+
+ device = adapter_get_device(adapter, addr);
+ if (device) {
+ dbus_connection_emit_property_changed(conn,
+ device->path, DEVICE_INTERFACE,
+ "Alias", DBUS_TYPE_STRING, &alias);
+ }
+ }
+
+ g_free(old_path);
+ g_free(new_path);
return send_message_and_unref(conn, reply);
}
@@ -2436,7 +2489,7 @@ static DBusHandlerResult adapter_remove_bonding(DBusConnection *conn,
GSList *l;
DBusMessage *reply;
char filename[PATH_MAX + 1];
- char *addr_ptr, *str;
+ char *addr_ptr, *str, *old_path, *new_path;
bdaddr_t bdaddr;
int dd;
@@ -2494,11 +2547,25 @@ static DBusHandlerResult adapter_remove_bonding(DBusConnection *conn,
}
}
+ resolve_paths(msg, &old_path, &new_path);
+
dbus_connection_emit_signal(conn, dbus_message_get_path(msg),
ADAPTER_INTERFACE, "BondingRemoved",
DBUS_TYPE_STRING, &addr_ptr,
DBUS_TYPE_INVALID);
+ if (new_path) {
+ struct device *device;
+ gboolean paired = FALSE;
+
+ device = adapter_get_device(adapter, addr_ptr);
+ if (device) {
+ dbus_connection_emit_property_changed(conn,
+ device->path, DEVICE_INTERFACE,
+ "Paired", DBUS_TYPE_BOOLEAN, &paired);
+ }
+ }
+
reply = dbus_message_new_method_return(msg);
hci_close_dev(dd);
@@ -3108,6 +3175,7 @@ static DBusHandlerResult adapter_set_trusted(DBusConnection *conn,
DBusMessage *reply;
bdaddr_t local;
const char *address;
+ char *old_path, *new_path;
if (!dbus_message_get_args(msg, NULL,
DBUS_TYPE_STRING, &address,
@@ -3125,11 +3193,25 @@ static DBusHandlerResult adapter_set_trusted(DBusConnection *conn,
write_trust(&local, address, GLOBAL_TRUST, TRUE);
- dbus_connection_emit_signal(conn, dbus_message_get_path(msg),
+ resolve_paths(msg, &old_path, &new_path);
+
+ dbus_connection_emit_signal(conn, old_path,
ADAPTER_INTERFACE, "TrustAdded",
DBUS_TYPE_STRING, &address,
DBUS_TYPE_INVALID);
+ if (new_path) {
+ struct device *device;
+ gboolean trust = TRUE;
+
+ device = adapter_get_device(adapter, address);
+ if (device) {
+ dbus_connection_emit_property_changed(conn,
+ device->path, DEVICE_INTERFACE,
+ "Trusted", DBUS_TYPE_BOOLEAN, &trust);
+ }
+ }
+
return send_message_and_unref(conn, reply);
}
@@ -3174,6 +3256,7 @@ static DBusHandlerResult adapter_remove_trust(DBusConnection *conn,
DBusMessage *reply;
const char *address;
bdaddr_t local;
+ char *old_path, *new_path;
if (!dbus_message_get_args(msg, NULL,
DBUS_TYPE_STRING, &address,
@@ -3191,11 +3274,25 @@ static DBusHandlerResult adapter_remove_trust(DBusConnection *conn,
write_trust(&local, address, GLOBAL_TRUST, FALSE);
- dbus_connection_emit_signal(conn, dbus_message_get_path(msg),
+ resolve_paths(msg, &old_path, &new_path);
+
+ dbus_connection_emit_signal(conn, old_path,
ADAPTER_INTERFACE, "TrustRemoved",
DBUS_TYPE_STRING, &address,
DBUS_TYPE_INVALID);
+ if (new_path) {
+ struct device *device;
+ gboolean trust = FALSE;
+
+ device = adapter_get_device(adapter, address);
+ if (device) {
+ dbus_connection_emit_property_changed(conn,
+ device->path, DEVICE_INTERFACE,
+ "Trusted", DBUS_TYPE_BOOLEAN, &trust);
+ }
+ }
+
return send_message_and_unref(conn, reply);
}
diff --git a/hcid/dbus-hci.c b/hcid/dbus-hci.c
index 2ae1e8c4..d3cb1855 100644
--- a/hcid/dbus-hci.c
+++ b/hcid/dbus-hci.c
@@ -768,8 +768,8 @@ int hcid_dbus_start_device(uint16_t id)
dbus_connection_emit_signal(connection, "/",
MANAGER_INTERFACE,
"DefaultAdapterChanged",
- DBUS_TYPE_OBJECT_PATH, &ptr,
- DBUS_TYPE_INVALID);
+ DBUS_TYPE_OBJECT_PATH, &ptr,
+ DBUS_TYPE_INVALID);
dbus_connection_emit_signal(connection, BASE_PATH,
MANAGER_INTERFACE,
@@ -1011,11 +1011,24 @@ void hcid_dbus_bonding_process_complete(bdaddr_t *local, bdaddr_t *peer,
adapter->pin_reqs = g_slist_remove(adapter->pin_reqs, l->data);
g_free(d);
- if (!status)
+ if (!status) {
send_adapter_signal(connection, adapter->dev_id,
"BondingCreated",
DBUS_TYPE_STRING, &paddr,
DBUS_TYPE_INVALID);
+
+ if (hcid_dbus_use_experimental()) {
+ struct device *device;
+ gboolean paired = TRUE;
+
+ device = adapter_get_device(adapter, paddr);
+ if (device) {
+ dbus_connection_emit_property_changed(connection,
+ device->path, DEVICE_INTERFACE,
+ "Paired", DBUS_TYPE_BOOLEAN, &paired);
+ }
+ }
+ }
}
release_passkey_agents(adapter, peer);
@@ -1617,7 +1630,7 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
name_status = NAME_SENT;
if (hcid_dbus_use_experimental()) {
- emit_device_found(path, paddr,
+ emit_device_found(path + ADAPTER_PATH_INDEX, paddr,
"Address", DBUS_TYPE_STRING, &paddr,
"Class", DBUS_TYPE_UINT32, &class,
"RSSI", DBUS_TYPE_INT16, &tmp_rssi,
@@ -1627,7 +1640,7 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
g_free(name);
} else if (hcid_dbus_use_experimental()) {
- emit_device_found(path, paddr,
+ emit_device_found(path + ADAPTER_PATH_INDEX, paddr,
"Address", DBUS_TYPE_STRING, &paddr,
"Class", DBUS_TYPE_UINT32, &class,
"RSSI", DBUS_TYPE_INT16, &tmp_rssi,
@@ -1663,6 +1676,29 @@ void hcid_dbus_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t class)
DBUS_TYPE_UINT32, &class,
DBUS_TYPE_INVALID);
+ if (hcid_dbus_use_experimental()) {
+ char path[MAX_PATH_LENGTH];
+ struct device *device;
+ struct adapter *adapter;
+ GSList *l;
+
+ snprintf(path, sizeof(path), "hci%d", id);
+
+ dbus_connection_get_object_user_data(connection, path,
+ (void *) &adapter);
+ if (!adapter)
+ return;
+
+ l = g_slist_find_custom(adapter->devices, paddr,
+ (GCompareFunc) device_address_cmp);
+ if (!l)
+ return;
+
+ device = l->data;
+ dbus_connection_emit_property_changed(connection,
+ device->path, DEVICE_INTERFACE,
+ "Class", DBUS_TYPE_UINT32, &class);
+ }
}
void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status,
@@ -1696,7 +1732,7 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status,
"RemoteNameFailed",
DBUS_TYPE_STRING, &paddr,
DBUS_TYPE_INVALID);
- else
+ else {
dbus_connection_emit_signal(connection, path,
ADAPTER_INTERFACE,
"RemoteNameUpdated",
@@ -1704,6 +1740,18 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID);
+ if (hcid_dbus_use_experimental()) {
+ struct device *device;
+
+ device = adapter_get_device(adapter, paddr);
+ if (device) {
+ dbus_connection_emit_property_changed(connection,
+ device->path, DEVICE_INTERFACE,
+ "Name", DBUS_TYPE_STRING, &name);
+ }
+ }
+ }
+
/* remove from remote name request list */
found_device_remove(&adapter->found_devices, peer);
@@ -1804,6 +1852,19 @@ void hcid_dbus_conn_complete(bdaddr_t *local, uint8_t status, uint16_t handle,
DBUS_TYPE_STRING, &paddr,
DBUS_TYPE_INVALID);
+ if (hcid_dbus_use_experimental()) {
+ struct device *device;
+ gboolean connected = TRUE;
+
+ device = adapter_get_device(adapter, paddr);
+ if (device) {
+ dbus_connection_emit_property_changed(connection,
+ device->path, DEVICE_INTERFACE,
+ "Connected", DBUS_TYPE_BOOLEAN,
+ &connected);
+ }
+ }
+
/* add in the active connetions list */
active_conn_append(&adapter->active_conn, peer, handle);
}
@@ -1907,6 +1968,19 @@ void hcid_dbus_disconn_complete(bdaddr_t *local, uint8_t status,
DBUS_TYPE_STRING, &paddr,
DBUS_TYPE_INVALID);
+ if (hcid_dbus_use_experimental()) {
+ struct device *device;
+ gboolean connected = FALSE;
+
+ device = adapter_get_device(adapter, paddr);
+ if (device) {
+ dbus_connection_emit_property_changed(connection,
+ device->path, DEVICE_INTERFACE,
+ "Connected", DBUS_TYPE_BOOLEAN,
+ &connected);
+ }
+ }
+
adapter->active_conn = g_slist_remove(adapter->active_conn, dev);
g_free(dev);
diff --git a/hcid/device.c b/hcid/device.c
index 7d48eb25..6d99fb45 100644
--- a/hcid/device.c
+++ b/hcid/device.c
@@ -994,7 +994,7 @@ struct device *device_create(DBusConnection *conn, struct adapter *adapter,
void device_destroy(struct device *device, DBusConnection *conn)
{
- debug("Removing device %s", device->path);
+ debug("Removing device %s", device->path);
dbus_connection_destroy_object_path(conn, device->path);
}