diff options
-rw-r--r-- | src/dbus-hci.c | 16 | ||||
-rw-r--r-- | src/device.c | 38 | ||||
-rw-r--r-- | src/device.h | 1 |
3 files changed, 39 insertions, 16 deletions
diff --git a/src/dbus-hci.c b/src/dbus-hci.c index 5ced560f..d75ee2fc 100644 --- a/src/dbus-hci.c +++ b/src/dbus-hci.c @@ -869,20 +869,8 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status, NULL); } - if (device) { - char alias[248]; - const char *dev_path = device_get_path(device); - - emit_property_changed(connection, dev_path, - DEVICE_INTERFACE, "Name", - DBUS_TYPE_STRING, &name); - - if (read_device_alias(srcaddr, dstaddr, - alias, sizeof(alias)) < 1) - emit_property_changed(connection, dev_path, - DEVICE_INTERFACE, "Alias", - DBUS_TYPE_STRING, &name); - } + if (device) + device_set_name(device, name); proceed: /* remove from remote name request list */ diff --git a/src/device.c b/src/device.c index f193ccfd..8e83000f 100644 --- a/src/device.c +++ b/src/device.c @@ -87,6 +87,7 @@ struct authentication_req { struct btd_device { bdaddr_t bdaddr; gchar *path; + char name[248]; struct btd_adapter *adapter; GSList *uuids; GSList *drivers; /* List of driver_data */ @@ -254,8 +255,8 @@ static DBusMessage *get_properties(DBusConnection *conn, adapter_get_address(adapter, &src); ba2str(&src, srcaddr); - if (read_device_name(srcaddr, dstaddr, name) == 0) { - ptr = name; + if (device->name) { + ptr = device->name; dict_append_entry(&dict, "Name", DBUS_TYPE_STRING, &ptr); } @@ -621,6 +622,8 @@ struct btd_device *device_create(DBusConnection *conn, gchar *address_up; struct btd_device *device; const gchar *adapter_path = adapter_get_path(adapter); + bdaddr_t src; + char srcaddr[18]; device = g_try_malloc0(sizeof(struct btd_device)); if (device == NULL) @@ -642,12 +645,43 @@ struct btd_device *device_create(DBusConnection *conn, str2ba(address, &device->bdaddr); device->adapter = adapter; + adapter_get_address(adapter, &src); + ba2str(&src, srcaddr); + read_device_name(srcaddr, address, device->name); device->auth = 0xff; return device; } +void device_set_name(struct btd_device *device, const char *name) +{ + DBusConnection *conn = get_dbus_connection(); + char alias[248]; + char srcaddr[18], dstaddr[18]; + bdaddr_t src; + + if (strncmp(name, device->name, 248) == 0) + return; + + strncpy(device->name, name, 248); + + emit_property_changed(conn, device->path, + DEVICE_INTERFACE, "Name", + DBUS_TYPE_STRING, &name); + + adapter_get_address(device->adapter, &src); + ba2str(&src, srcaddr); + ba2str(&device->bdaddr, dstaddr); + + if (read_device_alias(srcaddr, dstaddr, alias, sizeof(alias)) == 0) + return; + + emit_property_changed(conn, device->path, + DEVICE_INTERFACE, "Alias", + DBUS_TYPE_STRING, &name); +} + static void device_remove_bonding(struct btd_device *device, DBusConnection *conn) { diff --git a/src/device.h b/src/device.h index c169c916..5c230b81 100644 --- a/src/device.h +++ b/src/device.h @@ -36,6 +36,7 @@ typedef enum { struct btd_device *device_create(DBusConnection *conn, struct btd_adapter *adapter, const gchar *address); +void device_set_name(struct btd_device *device, const char *name); void device_remove(struct btd_device *device, DBusConnection *conn, gboolean remove_stored); gint device_address_cmp(struct btd_device *device, const gchar *address); |