client: Improve logging of GATT operations
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Wed, 13 Feb 2019 15:05:21 +0000 (17:05 +0200)
committerhimanshu <h.himanshu@samsung.com>
Tue, 11 Feb 2020 08:57:47 +0000 (14:27 +0530)
This prints the UUID along with attribute path and also print the
hexdump when payload is available.

Change-Id: If48e517894a93572f0e7a19a16fe58c85a3fbfb1
Signed-off-by: himanshu <h.himanshu@samsung.com>
client/gatt.c

index dee7c99..aaca5e0 100755 (executable)
@@ -847,8 +847,9 @@ static bool sock_read(struct io *io, void *user_data)
                return false;
 
        if (chrc)
-               bt_shell_printf("[" COLORED_CHG "] Attribute %s written:\n",
-                                                       chrc->path);
+               bt_shell_printf("[" COLORED_CHG "] Attribute %s (%s) "
+                               "written:\n", chrc->path,
+                               bt_uuidstr_to_str(chrc->uuid));
        else
                bt_shell_printf("[" COLORED_CHG "] %s Notification:\n",
                                g_dbus_proxy_get_path(notify_io.proxy));
@@ -2029,8 +2030,9 @@ static DBusMessage *chrc_read_value(DBusConnection *conn, DBusMessage *msg,
                                        "org.bluez.Error.InvalidArguments",
                                        NULL);
 
-       bt_shell_printf("ReadValue: %s offset %u link %s\n",
-                                       path_to_address(device), offset, link);
+       bt_shell_printf("[%s (%s)] ReadValue: %s offset %u link %s\n",
+                       chrc->path, bt_uuidstr_to_str(chrc->uuid),
+                       path_to_address(device), offset, link);
 
        if (chrc->proxy) {
                return proxy_read_value(chrc->proxy, msg, offset);
@@ -2139,7 +2141,8 @@ static void authorize_write_response(const char *input, void *user_data)
                goto error;
        }
 
-       bt_shell_printf("[" COLORED_CHG "] Attribute %s written" , chrc->path);
+       bt_shell_printf("[" COLORED_CHG "] Attribute %s (%s) written",
+                       chrc->path, bt_uuidstr_to_str(chrc->uuid));
 
        g_dbus_emit_property_changed(aad->conn, chrc->path, CHRC_INTERFACE,
                                                                "Value");
@@ -2205,7 +2208,7 @@ static DBusMessage *chrc_write_value(DBusConnection *conn, DBusMessage *msg,
        struct chrc *chrc = user_data;
        uint16_t offset = 0;
        bool prep_authorize = false;
-       char *device = NULL;
+       char *device = NULL, *link = NULL;
        DBusMessageIter iter;
        int value_len;
        uint8_t *value;
@@ -2218,10 +2221,17 @@ static DBusMessage *chrc_write_value(DBusConnection *conn, DBusMessage *msg,
                                "org.bluez.Error.InvalidArguments", NULL);
 
        dbus_message_iter_next(&iter);
-       if (parse_options(&iter, &offset, NULL, &device, NULL, &prep_authorize))
+       if (parse_options(&iter, &offset, NULL, &device, &link,
+                                               &prep_authorize))
                return g_dbus_create_error(msg,
                                "org.bluez.Error.InvalidArguments", NULL);
 
+       bt_shell_printf("[%s (%s)] WriteValue: %s offset %u link %s\n",
+                       chrc->path, bt_uuidstr_to_str(chrc->uuid),
+                       path_to_address(device), offset, link);
+
+       bt_shell_hexdump(value, value_len);
+
        if (chrc->proxy)
                return proxy_write_value(chrc->proxy, msg, value, value_len,
                                                                offset);
@@ -2255,7 +2265,8 @@ static DBusMessage *chrc_write_value(DBusConnection *conn, DBusMessage *msg,
                return g_dbus_create_error(msg,
                                "org.bluez.Error.InvalidValueLength", NULL);
 
-       bt_shell_printf("[" COLORED_CHG "] Attribute %s written" , chrc->path);
+       bt_shell_printf("[" COLORED_CHG "] Attribute %s (%s) written",
+                       chrc->path, bt_uuidstr_to_str(chrc->uuid));
 
        g_dbus_emit_property_changed(conn, chrc->path, CHRC_INTERFACE, "Value");
 
@@ -2392,8 +2403,10 @@ static void proxy_notify_reply(DBusMessage *message, void *user_data)
        g_dbus_send_reply(conn, data->msg, DBUS_TYPE_INVALID);
 
        data->chrc->notifying = data->enable;
-       bt_shell_printf("[" COLORED_CHG "] Attribute %s notifications %s\n",
+       bt_shell_printf("[" COLORED_CHG "] Attribute %s (%s) "
+                               "notifications %s\n",
                                data->chrc->path,
+                               bt_uuidstr_to_str(data->chrc->uuid),
                                data->enable ? "enabled" : "disabled");
        g_dbus_emit_property_changed(conn, data->chrc->path, CHRC_INTERFACE,
                                                        "Notifying");
@@ -2439,8 +2452,8 @@ static DBusMessage *chrc_start_notify(DBusConnection *conn, DBusMessage *msg,
                return proxy_notify(chrc, msg, true);
 
        chrc->notifying = true;
-       bt_shell_printf("[" COLORED_CHG "] Attribute %s notifications enabled",
-                                                       chrc->path);
+       bt_shell_printf("[" COLORED_CHG "] Attribute %s (%s) notifications "
+                       "enabled", chrc->path, bt_uuidstr_to_str(chrc->uuid));
        g_dbus_emit_property_changed(conn, chrc->path, CHRC_INTERFACE,
                                                        "Notifying");
 
@@ -2459,8 +2472,8 @@ static DBusMessage *chrc_stop_notify(DBusConnection *conn, DBusMessage *msg,
                return proxy_notify(chrc, msg, false);
 
        chrc->notifying = false;
-       bt_shell_printf("[" COLORED_CHG "] Attribute %s notifications disabled",
-                                                       chrc->path);
+       bt_shell_printf("[" COLORED_CHG "] Attribute %s (%s) notifications "
+                       "disabled", chrc->path, bt_uuidstr_to_str(chrc->uuid));
        g_dbus_emit_property_changed(conn, chrc->path, CHRC_INTERFACE,
                                                        "Notifying");
 
@@ -2472,7 +2485,8 @@ static DBusMessage *chrc_confirm(DBusConnection *conn, DBusMessage *msg,
 {
        struct chrc *chrc = user_data;
 
-       bt_shell_printf("Attribute %s indication confirm received", chrc->path);
+       bt_shell_printf("Attribute %s (%s) indication confirm received",
+                       chrc->path, bt_uuidstr_to_str(chrc->uuid));
 
        return dbus_message_new_method_return(msg);
 }
@@ -2653,7 +2667,8 @@ static DBusMessage *desc_read_value(DBusConnection *conn, DBusMessage *msg,
                                        "org.bluez.Error.InvalidArguments",
                                        NULL);
 
-       bt_shell_printf("ReadValue: %s offset %u link %s\n",
+       bt_shell_printf("[%s (%s)] ReadValue: %s offset %u link %s\n",
+                       desc->path, bt_uuidstr_to_str(desc->uuid),
                        path_to_address(device), offset, link);
 
        if (offset > desc->value_len)
@@ -2689,10 +2704,12 @@ static DBusMessage *desc_write_value(DBusConnection *conn, DBusMessage *msg,
                return g_dbus_create_error(msg,
                                "org.bluez.Error.InvalidValueLength", NULL);
 
-       bt_shell_printf("WriteValue: %s offset %u link %s\n",
+       bt_shell_printf("[%s (%s)] WriteValue: %s offset %u link %s\n",
+                       desc->path, bt_uuidstr_to_str(desc->uuid),
                        path_to_address(device), offset, link);
 
-       bt_shell_printf("[" COLORED_CHG "] Attribute %s written" , desc->path);
+       bt_shell_printf("[" COLORED_CHG "] Attribute %s (%s) written",
+                       desc->path, bt_uuidstr_to_str(desc->uuid));
 
        g_dbus_emit_property_changed(conn, desc->path, CHRC_INTERFACE, "Value");