diff options
author | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2021-10-14 17:25:04 -0700 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2021-10-18 13:04:27 -0700 |
commit | 016084253bbdb1be81c5aef7d446f3c13bb4e823 (patch) | |
tree | cf25e4b0041bddb535be2297837ca91e416231fd /emulator/vhci.c | |
parent | 135f5d82586b42d7f68d04f97254702a3fb514f9 (diff) | |
download | bluez-016084253bbdb1be81c5aef7d446f3c13bb4e823.tar.gz |
vhci: Add functions to interface with debugfs
This adds functions that can be used to set debugfs options.
Diffstat (limited to 'emulator/vhci.c')
-rw-r--r-- | emulator/vhci.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/emulator/vhci.c b/emulator/vhci.c index 97fbcb8c4..f8560e0c5 100644 --- a/emulator/vhci.c +++ b/emulator/vhci.c @@ -20,6 +20,8 @@ #include <stdlib.h> #include <string.h> #include <sys/uio.h> +#include <fcntl.h> +#include <unistd.h> #include "lib/bluetooth.h" #include "lib/hci.h" @@ -29,8 +31,11 @@ #include "btdev.h" #include "vhci.h" +#define DEBUGFS_PATH "/sys/kernel/debug/bluetooth" + struct vhci { enum btdev_type type; + uint16_t index; struct io *io; struct btdev *btdev; }; @@ -140,6 +145,7 @@ struct vhci *vhci_open(uint8_t type) memset(vhci, 0, sizeof(*vhci)); vhci->type = type; + vhci->index = rsp.index; vhci->io = io_new(fd); io_set_close_on_destroy(vhci->io, true); @@ -175,3 +181,63 @@ struct btdev *vhci_get_btdev(struct vhci *vhci) return vhci->btdev; } + +static int vhci_debugfs_write(struct vhci *vhci, char *option, void *data, + size_t len) +{ + char path[64]; + int fd, err; + size_t n; + + if (!vhci) + return -EINVAL; + + memset(path, 0, sizeof(path)); + sprintf(path, DEBUGFS_PATH "/hci%d/%s", vhci->index, option); + + fd = open(path, O_RDWR); + if (fd < 0) + return -errno; + + n = write(fd, data, len); + if (n == len) + err = 0; + else + err = -errno; + + close(fd); + + return err; +} + +int vhci_set_force_suspend(struct vhci *vhci, bool enable) +{ + char val; + + val = (enable) ? 'Y' : 'N'; + + return vhci_debugfs_write(vhci, "force_suspend", &val, sizeof(val)); +} + +int vhci_set_force_wakeup(struct vhci *vhci, bool enable) +{ + char val; + + val = (enable) ? 'Y' : 'N'; + + return vhci_debugfs_write(vhci, "force_wakeup", &val, sizeof(val)); +} + +int vhci_set_msft_opcode(struct vhci *vhci, uint16_t opcode) +{ + return vhci_debugfs_write(vhci, "msft_opcode", &opcode, sizeof(opcode)); +} + +int vhci_set_aosp_capable(struct vhci *vhci, bool enable) +{ + char val; + + val = (enable) ? 'Y' : 'N'; + + return vhci_debugfs_write(vhci, "aosp_capable", &val, sizeof(val)); +} |