@@ -22,6 +22,7 @@
#include <sys/uio.h>
#include <fcntl.h>
#include <unistd.h>
+#include <dirent.h>
#include "lib/bluetooth.h"
#include "lib/hci.h"
@@ -32,6 +33,7 @@
#include "vhci.h"
#define DEBUGFS_PATH "/sys/kernel/debug/bluetooth"
+#define DEVCORE_PATH "/sys/class/devcoredump"
struct vhci {
enum btdev_type type;
@@ -267,3 +269,43 @@ int vhci_set_force_static_address(struct vhci *vhci, bool enable)
return vhci_debugfs_write(vhci, "force_static_address", &val,
sizeof(val));
}
+
+int vhci_force_devcd(struct vhci *vhci, void *data, size_t len)
+{
+ return vhci_debugfs_write(vhci, "force_devcoredump", data, len);
+}
+
+int vhci_read_devcd(struct vhci *vhci, void *buf, size_t size)
+{
+ DIR *dir;
+ struct dirent *entry;
+ char filename[PATH_MAX];
+ int fd;
+ int count;
+
+ dir = opendir(DEVCORE_PATH);
+ if (dir == NULL)
+ return -errno;
+
+ while ((entry = readdir(dir)) != NULL) {
+ if (strstr(entry->d_name, "devcd"))
+ break;
+ }
+
+ if (entry == NULL) {
+ closedir(dir);
+ return -ENOENT;
+ }
+
+ sprintf(filename, DEVCORE_PATH "/%s/data", entry->d_name);
+ fd = open(filename, O_RDONLY);
+ if (fd < 0) {
+ closedir(dir);
+ return -errno;
+ }
+
+ count = read(fd, buf, size);
+ close(fd);
+
+ return count;
+}
@@ -29,3 +29,5 @@ int vhci_set_msft_opcode(struct vhci *vhci, uint16_t opcode);
int vhci_set_aosp_capable(struct vhci *vhci, bool enable);
int vhci_set_emu_opcode(struct vhci *vhci, uint16_t opcode);
int vhci_set_force_static_address(struct vhci *vhci, bool enable);
+int vhci_force_devcd(struct vhci *vhci, void *data, size_t len);
+int vhci_read_devcd(struct vhci *vhci, void *buf, size_t size);