diff options
author | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2020-10-29 14:45:55 -0700 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2020-11-02 10:18:48 -0800 |
commit | 2bef85afdf43e653aacf58ebde279778524c18aa (patch) | |
tree | d461d6c876eee6a5cb2de0d8cf75eaf45a0feb65 /emulator/hciemu.c | |
parent | 3b572018a1304623c09bbaf73546c0dfe159ea36 (diff) | |
download | bluez-2bef85afdf43e653aacf58ebde279778524c18aa.tar.gz |
emulator/hciemu: Add debug support
This adds bthost_set_debug which can be used to debug internals of
hciemu.
Diffstat (limited to 'emulator/hciemu.c')
-rw-r--r-- | emulator/hciemu.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/emulator/hciemu.c b/emulator/hciemu.c index fa8905ed7..fd6029deb 100644 --- a/emulator/hciemu.c +++ b/emulator/hciemu.c @@ -45,6 +45,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 { @@ -385,6 +389,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; |