emulator/hciemu: Add debug support
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Thu, 29 Oct 2020 21:45:55 +0000 (14:45 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:33 +0000 (19:08 +0530)
This adds bthost_set_debug which can be used to debug internals of
hciemu.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
emulator/hciemu.c
emulator/hciemu.h

index c0e3570..9045cd5 100755 (executable)
@@ -44,6 +44,10 @@ struct hciemu {
        guint client_source;
        struct queue *post_command_hooks;
        char bdaddr_str[18];
+
+       hciemu_debug_func_t debug_callback;
+       hciemu_destroy_func_t debug_destroy;
+       void *debug_data;
 };
 
 struct hciemu_command_hook {
@@ -384,6 +388,50 @@ void hciemu_unref(struct hciemu *hciemu)
        free(hciemu);
 }
 
+static void bthost_debug(const char *str, void *user_data)
+{
+       struct hciemu *hciemu = user_data;
+
+       util_debug(hciemu->debug_callback, hciemu->debug_data,
+                                       "bthost: %s", str);
+}
+
+static void btdev_master_debug(const char *str, void *user_data)
+{
+       struct hciemu *hciemu = user_data;
+
+       util_debug(hciemu->debug_callback, hciemu->debug_data,
+                                       "btdev: %s", str);
+}
+
+static void btdev_client_debug(const char *str, void *user_data)
+{
+       struct hciemu *hciemu = user_data;
+
+       util_debug(hciemu->debug_callback, hciemu->debug_data,
+                                       "btdev[bthost]: %s", str);
+}
+
+bool hciemu_set_debug(struct hciemu *hciemu, hciemu_debug_func_t callback,
+                       void *user_data, hciemu_destroy_func_t destroy)
+{
+       if (!hciemu)
+               return false;
+
+       if (hciemu->debug_destroy)
+               hciemu->debug_destroy(hciemu->debug_data);
+
+       hciemu->debug_callback = callback;
+       hciemu->debug_destroy = destroy;
+       hciemu->debug_data = user_data;
+
+       btdev_set_debug(hciemu->master_dev, btdev_master_debug, hciemu, NULL);
+       btdev_set_debug(hciemu->client_dev, btdev_client_debug, hciemu, NULL);
+       bthost_set_debug(hciemu->host_stack, bthost_debug, hciemu, NULL);
+
+       return true;
+}
+
 const char *hciemu_get_address(struct hciemu *hciemu)
 {
        const uint8_t *addr;
index c8ec80d..d070827 100755 (executable)
@@ -34,6 +34,11 @@ struct hciemu *hciemu_new(enum hciemu_type type);
 struct hciemu *hciemu_ref(struct hciemu *hciemu);
 void hciemu_unref(struct hciemu *hciemu);
 
+typedef void (*hciemu_debug_func_t)(const char *str, void *user_data);
+typedef void (*hciemu_destroy_func_t)(void *user_data);
+bool hciemu_set_debug(struct hciemu *hciemu, hciemu_debug_func_t callback,
+                       void *user_data, hciemu_destroy_func_t destroy);
+
 struct bthost *hciemu_client_get_host(struct hciemu *hciemu);
 
 const char *hciemu_get_address(struct hciemu *hciemu);