linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 6/7] vhci: Add functions to interface with debugfs
Date: Thu, 14 Oct 2021 22:09:28 -0700	[thread overview]
Message-ID: <20211015050929.3130100-6-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20211015050929.3130100-1-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds functions that can be used to set debugfs options.
---
 emulator/btdev.c |  23 +++++++++-
 emulator/btdev.h |   3 ++
 emulator/vhci.c  | 108 +++++++++++++++++++++++++++++++++++++++++++++++
 emulator/vhci.h  |   5 +++
 4 files changed, 137 insertions(+), 2 deletions(-)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index 0c0ebde40..f28187362 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -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;
+}
diff --git a/emulator/btdev.h b/emulator/btdev.h
index f7cba149a..412bfd158 100644
--- a/emulator/btdev.h
+++ b/emulator/btdev.h
@@ -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);
diff --git a/emulator/vhci.c b/emulator/vhci.c
index 97fbcb8c4..e016a1ac5 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,105 @@ struct btdev *vhci_get_btdev(struct vhci *vhci)
 
 	return vhci->btdev;
 }
+
+static int vhci_debugfs_open(struct vhci *vhci, char *option)
+{
+	char path[64];
+
+	if (!vhci)
+		return -EINVAL;
+
+	memset(path, 0, sizeof(path));
+	sprintf(path, DEBUGFS_PATH "/hci%d/%s", vhci->index, option);
+
+	return open(path, O_RDWR);
+}
+
+int vhci_set_force_suspend(struct vhci *vhci, bool enable)
+{
+	int fd, err;
+	char val;
+
+	fd = vhci_debugfs_open(vhci, "force_suspend");
+	if (fd < 0)
+		return -errno;
+
+	val = (enable) ? 'Y' : 'N';
+
+	err = write(fd, &val, sizeof(val));
+	if (err < 0) {
+		err = -errno;
+		goto done;
+	}
+
+done:
+	close(fd);
+	return err;
+}
+
+int vhci_set_force_wakeup(struct vhci *vhci, bool enable)
+{
+	int fd, err;
+	char val;
+
+	fd = vhci_debugfs_open(vhci, "force_wakeup");
+	if (fd < 0)
+		return -errno;
+
+	val = (enable) ? 'Y' : 'N';
+
+	err = write(fd, &val, sizeof(val));
+	if (err < 0) {
+		err = -errno;
+		goto done;
+	}
+
+done:
+	close(fd);
+	return err;
+}
+
+int vhci_set_msft_opcode(struct vhci *vhci, uint16_t opcode)
+{
+	int fd, err;
+
+	fd = vhci_debugfs_open(vhci, "msft_opcode");
+	if (fd < 0)
+		return -errno;
+
+	err = write(fd, &opcode, sizeof(opcode));
+	if (err < 0) {
+		err = -errno;
+		goto done;
+	}
+
+	btdev_set_msft_opcode(vhci->btdev, opcode);
+
+done:
+	close(fd);
+	return err;
+}
+
+int vhci_set_aosp_capable(struct vhci *vhci, bool enable)
+{
+	int fd, err;
+	char val;
+
+	fd = vhci_debugfs_open(vhci, "aosp_capable");
+	if (fd < 0)
+		return -errno;
+
+	val = (enable) ? 'Y' : 'N';
+
+	err = write(fd, &val, sizeof(val));
+	if (err < 0) {
+		err = -errno;
+		goto done;
+	}
+
+	btdev_set_aosp_capable(vhci->btdev, enable);
+
+done:
+	close(fd);
+	return err;
+}
diff --git a/emulator/vhci.h b/emulator/vhci.h
index 0554121e8..a601d3934 100644
--- a/emulator/vhci.h
+++ b/emulator/vhci.h
@@ -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);
-- 
2.31.1


  parent reply	other threads:[~2021-10-15  5:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-15  5:09 [PATCH BlueZ 1/7] monitor: Add packet definitions for MSFT extension Luiz Augusto von Dentz
2021-10-15  5:09 ` [PATCH BlueZ 2/7] monitor: Make use of MSFT packet definitions Luiz Augusto von Dentz
2021-10-15  5:09 ` [PATCH BlueZ 3/7] vhci: Read the controller index Luiz Augusto von Dentz
2021-10-15  5:09 ` [PATCH BlueZ 4/7] vhci: Use io.h instead of mainloop.h Luiz Augusto von Dentz
2021-10-15  5:09 ` [PATCH BlueZ 5/7] hciemu: Use vhci_open to instanciate a vhci btdev Luiz Augusto von Dentz
2021-10-15  5:09 ` Luiz Augusto von Dentz [this message]
2021-10-15  5:09 ` [PATCH BlueZ 7/7] mgmt-tester: Make use of vhci_set_force_suspend/vhci_set_force_wakeup Luiz Augusto von Dentz
2021-10-15  5:36 ` [BlueZ,1/7] monitor: Add packet definitions for MSFT extension bluez.test.bot
2021-10-15 20:10   ` Luiz Augusto von Dentz
     [not found] ` <CAGPPCLDFYFeiwfiyRX=6PquYYQ-Fp_LpN4Gw2745jyWzQKEBRQ@mail.gmail.com>
2021-10-18 16:24   ` [PATCH BlueZ 1/7] " Luiz Augusto von Dentz
2021-10-18 20:05     ` Luiz Augusto von Dentz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211015050929.3130100-6-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --subject='Re: [PATCH BlueZ 6/7] vhci: Add functions to interface with debugfs' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).