summaryrefslogtreecommitdiff
path: root/client/advertising.c
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2018-01-19 11:12:09 -0200
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2018-01-19 11:44:09 -0200
commit0c8e542c4d4076f7e1558289fabd27410a59475b (patch)
tree8073e07a5891c4a7beb40d011dfd2ac22a7a607c /client/advertising.c
parent5c6ef1c396ff998ba894f7ca856072ac9a8bc80e (diff)
downloadbluez-0c8e542c4d4076f7e1558289fabd27410a59475b.tar.gz
client: Print advertising details
Print advertising details when active.
Diffstat (limited to 'client/advertising.c')
-rw-r--r--client/advertising.c104
1 files changed, 73 insertions, 31 deletions
diff --git a/client/advertising.c b/client/advertising.c
index a220d813b..b9b9a7371 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;
}