vhci: Add functions to interface with debugfs
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Fri, 15 Oct 2021 00:25:04 +0000 (17:25 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:37 +0000 (19:08 +0530)
This adds functions that can be used to set debugfs options.

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

index 0c0ebde..f281873 100755 (executable)
@@ -46,8 +46,6 @@
 #define ISO_HANDLE 257
 #define SCO_HANDLE 257
 
-#define DEBUGFS_PATH "/sys/kernel/debug/bluetooth"
-
 struct hook {
        btdev_hook_func handler;
        void *user_data;
@@ -141,6 +139,7 @@ struct btdev {
        uint8_t  le_states[8];
        const struct btdev_cmd *cmds;
        uint16_t msft_opcode;
+       bool aosp_capable;
 
        uint16_t default_link_policy;
        uint8_t  event_mask[8];
@@ -6677,3 +6676,23 @@ bool btdev_del_hook(struct btdev *btdev, enum btdev_hook_type type,
 
        return false;
 }
+
+int btdev_set_msft_opcode(struct btdev *btdev, uint16_t opcode)
+{
+       if (!btdev)
+               return -EINVAL;
+
+       btdev->msft_opcode = opcode;
+
+       return 0;
+}
+
+int btdev_set_aosp_capable(struct btdev *btdev, bool enable)
+{
+       if (!btdev)
+               return -EINVAL;
+
+       btdev->aosp_capable = enable;
+
+       return 0;
+}
index f7cba14..412bfd1 100755 (executable)
@@ -93,3 +93,6 @@ int btdev_add_hook(struct btdev *btdev, enum btdev_hook_type type,
 
 bool btdev_del_hook(struct btdev *btdev, enum btdev_hook_type type,
                                                        uint16_t opcode);
+
+int btdev_set_msft_opcode(struct btdev *btdev, uint16_t opcode);
+int btdev_set_aosp_capable(struct btdev *btdev, bool enable);
index 97fbcb8..f8560e0 100755 (executable)
@@ -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"
 #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));
+}
index 0554121..a601d39 100755 (executable)
@@ -22,3 +22,8 @@ struct vhci *vhci_open(uint8_t type);
 void vhci_close(struct vhci *vhci);
 
 struct btdev *vhci_get_btdev(struct vhci *vhci);
+
+int vhci_set_force_suspend(struct vhci *vhci, bool enable);
+int vhci_set_force_wakeup(struct vhci *vhci, bool enable);
+int vhci_set_msft_opcode(struct vhci *vhci, uint16_t opcode);
+int vhci_set_aosp_capable(struct vhci *vhci, bool enable);