Diff between 5c6ef1c396ff998ba894f7ca856072ac9a8bc80e and 0c8e542c4d4076f7e1558289fabd27410a59475b

Changed Files

File Additions Deletions Status
client/advertising.c +73 -31 modified

Full Patch

diff --git a/client/advertising.c b/client/advertising.c
index a220d81..b9b9a73 100644
--- a/client/advertising.c
+++ b/client/advertising.c
@@ -108,6 +108,77 @@ static void register_setup(DBusMessageIter *iter, void *user_data)
 	dbus_message_iter_close_container(iter, &dict);
 }
 
+static void print_uuid(const char *uuid)
+{
+	const char *text;
+
+	text = bt_uuidstr_to_str(uuid);
+	if (text) {
+		char str[26];
+		unsigned int n;
+
+		str[sizeof(str) - 1] = '\0';
+
+		n = snprintf(str, sizeof(str), "%s", text);
+		if (n > sizeof(str) - 1) {
+			str[sizeof(str) - 2] = '.';
+			str[sizeof(str) - 3] = '.';
+			if (str[sizeof(str) - 4] == ' ')
+				str[sizeof(str) - 4] = '.';
+
+			n = sizeof(str) - 1;
+		}
+
+		bt_shell_printf("UUID: %s(%s)\n", str, uuid);
+	} else
+		bt_shell_printf("UUID: (%s)\n", uuid);
+}
+
+static void print_ad_uuids(void)
+{
+	char **uuid;
+
+	for (uuid = ad.uuids; uuid && *uuid; uuid++)
+		print_uuid(*uuid);
+}
+
+static void print_ad(void)
+{
+	print_ad_uuids();
+
+	if (ad.service.uuid) {
+		print_uuid(ad.service.uuid);
+		bt_shell_hexdump(ad.service.data.data, ad.service.data.len);
+	}
+
+	if (ad.manufacturer.data.len) {
+		bt_shell_printf("Manufacturer: %u\n", ad.manufacturer.id);
+		bt_shell_hexdump(ad.manufacturer.data.data,
+						ad.manufacturer.data.len);
+	}
+
+	bt_shell_printf("Tx Power: %s\n", ad.tx_power ? "on" : "off");
+
+	if (ad.local_name)
+		bt_shell_printf("LocalName: %s\n", ad.local_name);
+	else
+		bt_shell_printf("Name: %s\n", ad.name ? "on" : "off");
+
+	if (ad.local_appearance != UINT16_MAX)
+		bt_shell_printf("Appearance: %s (0x%04x)\n",
+					bt_appear_to_str(ad.local_appearance),
+					ad.local_appearance);
+	else
+		bt_shell_printf("Apperance: %s\n",
+					ad.appearance ? "on" : "off");
+
+	if (ad.duration)
+		bt_shell_printf("Duration: %u sec\n", ad.duration);
+
+	if (ad.timeout)
+		bt_shell_printf("Timeout: %u sec\n", ad.timeout);
+}
+
 static void register_reply(DBusMessage *message, void *user_data)
 {
 	DBusConnection *conn = user_data;
@@ -118,6 +189,7 @@ static void register_reply(DBusMessage *message, void *user_data)
 	if (dbus_set_error_from_message(&error, message) == FALSE) {
 		ad.registered = true;
 		bt_shell_printf("Advertising object registered\n");
+		print_ad();
 	} else {
 		bt_shell_printf("Failed to register advertisement: %s\n", error.name);
 		dbus_error_free(&error);
@@ -435,40 +507,10 @@ void ad_unregister(DBusConnection *conn, GDBusProxy *manager)
 	}
 }
 
-static void print_uuid(const char *uuid)
-{
-	const char *text;
-
-	text = bt_uuidstr_to_str(uuid);
-	if (text) {
-		char str[26];
-		unsigned int n;
-
-		str[sizeof(str) - 1] = '\0';
-
-		n = snprintf(str, sizeof(str), "%s", text);
-		if (n > sizeof(str) - 1) {
-			str[sizeof(str) - 2] = '.';
-			str[sizeof(str) - 3] = '.';
-			if (str[sizeof(str) - 4] == ' ')
-				str[sizeof(str) - 4] = '.';
-
-			n = sizeof(str) - 1;
-		}
-
-		bt_shell_printf("\tUUID: %s(%s)\n", str, uuid);
-	} else
-		bt_shell_printf("\tUUID: (%s)\n", uuid);
-}
-
 void ad_advertise_uuids(DBusConnection *conn, int argc, char *argv[])
 {
 	if (argc < 2 || !strlen(argv[1])) {
-		char **uuid;
-
-		for (uuid = ad.uuids; uuid && *uuid; uuid++)
-			print_uuid(*uuid);
-
+		print_ad_uuids();
 		return;
 	}