diff options
| -rw-r--r-- | common/glib-helper.c | 36 | ||||
| -rw-r--r-- | src/adapter.c | 23 | ||||
| -rw-r--r-- | src/device.c | 8 | 
3 files changed, 44 insertions, 23 deletions
| diff --git a/common/glib-helper.c b/common/glib-helper.c index 17a8cb45..5296559d 100644 --- a/common/glib-helper.c +++ b/common/glib-helper.c @@ -25,6 +25,7 @@  #include <config.h>  #endif +#include <stdlib.h>  #include <errno.h>  #include <fcntl.h>  #include <unistd.h> @@ -498,15 +499,40 @@ uint16_t bt_name2class(const char *pattern)  	return 0;  } +static inline gboolean is_uuid128(const char *string) +{ +	return (strlen(string) == 36 && +			string[8] == '-' && +			string[13] == '-' && +			string[18] == '-' && +			string[23] == '-'); +} +  char *bt_name2string(const char *pattern)  {  	uuid_t uuid;  	uint16_t uuid16; +	int i; +	/* UUID 128 string format */ +	if (is_uuid128(pattern)) +		return g_strdup(pattern); + +	/* Friendly service name format */  	uuid16 = bt_name2class(pattern); -	if (!uuid16) -		return NULL; +	if (uuid16) +		goto proceed; + +	/* HEX format */ +	uuid16 = strtol(pattern, NULL, 16); +	for (i = 0; bt_services[i].class; i++) { +		if (bt_services[i].class == uuid16) +			goto proceed; +	} + +	return NULL; +proceed:  	sdp_uuid16_create(&uuid, uuid16);  	return bt_uuid2string(&uuid); @@ -517,11 +543,7 @@ int bt_string2uuid(uuid_t *uuid, const char *string)  	uint32_t data0, data4;  	uint16_t data1, data2, data3, data5; -	if (strlen(string) == 36 && -			string[8] == '-' && -			string[13] == '-' && -			string[18] == '-' && -			string[23] == '-' && +	if (is_uuid128(string) &&  			sscanf(string, "%08x-%04hx-%04hx-%04hx-%08x%04hx",  				&data0, &data1, &data2, &data3, &data4, &data5) == 6) {  		uint8_t val[16]; diff --git a/src/adapter.c b/src/adapter.c index b874e12a..0e68359f 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -953,6 +953,7 @@ struct btd_device *adapter_create_device(DBusConnection *conn,  				struct btd_adapter *adapter, const char *address)  {  	struct btd_device *device; +	const char *path;  	debug("adapter_create_device(%s)", address); @@ -964,6 +965,14 @@ struct btd_device *adapter_create_device(DBusConnection *conn,  	adapter->devices = g_slist_append(adapter->devices, device); +	path = device_get_path(device); +	g_dbus_emit_signal(conn, adapter->path, +			ADAPTER_INTERFACE, "DeviceCreated", +			DBUS_TYPE_OBJECT_PATH, &path, +			DBUS_TYPE_INVALID); + +	adapter_update_devices(adapter); +  	return device;  } @@ -1068,17 +1077,15 @@ void adapter_remove_device(DBusConnection *conn, struct btd_adapter *adapter,  	delete_entry(&adapter->bdaddr, "profiles", dstaddr);  	adapter->devices = g_slist_remove(adapter->devices, device); -	if (!device_is_temporary(device)) { +	if (!device_is_temporary(device))  		remove_bonding(conn, NULL, dstaddr, adapter); -		g_dbus_emit_signal(conn, adapter->path, -				ADAPTER_INTERFACE, -				"DeviceRemoved", -				DBUS_TYPE_OBJECT_PATH, &dev_path, -				DBUS_TYPE_INVALID); +	g_dbus_emit_signal(conn, adapter->path, +			ADAPTER_INTERFACE, "DeviceRemoved", +			DBUS_TYPE_OBJECT_PATH, &dev_path, +			DBUS_TYPE_INVALID); -		adapter_update_devices(adapter); -	} +	adapter_update_devices(adapter);  	agent = device_get_agent(device); diff --git a/src/device.c b/src/device.c index f8c5a3fd..20f46efc 100644 --- a/src/device.c +++ b/src/device.c @@ -1071,14 +1071,6 @@ proceed:  	/* Store the device's profiles in the filesystem */  	store_profiles(device); -	g_dbus_emit_signal(req->conn, adapter_get_path(device->adapter), -				ADAPTER_INTERFACE, "DeviceCreated", -				DBUS_TYPE_OBJECT_PATH, &device->path, -				DBUS_TYPE_INVALID); - -	/* Update device list */ -	adapter_update_devices(device->adapter); -  	if (!req->msg)  		goto cleanup; | 
