diff --git a/CMakeLists.txt b/CMakeLists.txt index 115a7a68b..9283ecdf8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -628,7 +628,7 @@ elseif(FreeBSD) src/detection/lm/lm_linux.c src/detection/icons/icons_linux.c src/detection/initsystem/initsystem_linux.c - src/detection/keyboard/keyboard_nosupport.c + src/detection/keyboard/keyboard_bsd.c src/detection/libc/libc_bsd.c src/detection/loadavg/loadavg_bsd.c src/detection/locale/locale_linux.c @@ -636,7 +636,7 @@ elseif(FreeBSD) src/detection/gamepad/gamepad_bsd.c src/detection/media/media_linux.c src/detection/memory/memory_bsd.c - src/detection/mouse/mouse_nosupport.c + src/detection/mouse/mouse_bsd.c src/detection/netio/netio_bsd.c src/detection/opengl/opengl_linux.c src/detection/os/os_linux.c diff --git a/src/detection/keyboard/keyboard_bsd.c b/src/detection/keyboard/keyboard_bsd.c new file mode 100644 index 000000000..c1be06aa4 --- /dev/null +++ b/src/detection/keyboard/keyboard_bsd.c @@ -0,0 +1,47 @@ +#include "keyboard.h" +#include "common/io/io.h" + +#include +#include +#include +#include + +#define MAX_UHID_JOYS 64 + +const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */) +{ + char path[16]; + for (int i = 0; i < MAX_UHID_JOYS; i++) + { + snprintf(path, sizeof(path), "/dev/uhid%d", i); + FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC); + if (fd < 0) continue; + + report_desc_t repDesc = hid_get_report_desc(fd); + if (!repDesc) continue; + + int reportId = hid_get_report_id(fd); + + struct hid_data* hData = hid_start_parse(repDesc, 0, reportId); + if (hData) + { + struct hid_item hItem; + while (hid_get_item(hData, &hItem) > 0) + { + if (HID_PAGE(hItem.usage) != 1 || HID_USAGE(hItem.usage) != 6) continue; + + struct usb_device_info di; + if (ioctl(fd, USB_GET_DEVICEINFO, &di) != -1) + { + FFKeyboardDevice* device = (FFKeyboardDevice*) ffListAdd(devices); + ffStrbufInitS(&device->serial, di.udi_serial); + ffStrbufInitS(&device->name, di.udi_product); + } + } + } + + hid_dispose_report_desc(repDesc); + } + + return NULL; +} diff --git a/src/detection/mouse/mouse_bsd.c b/src/detection/mouse/mouse_bsd.c new file mode 100644 index 000000000..ec978974b --- /dev/null +++ b/src/detection/mouse/mouse_bsd.c @@ -0,0 +1,47 @@ +#include "mouse.h" +#include "common/io/io.h" + +#include +#include +#include +#include + +#define MAX_UHID_JOYS 64 + +const char* ffDetectMouse(FFlist* devices /* List of FFMouseDevice */) +{ + char path[16]; + for (int i = 0; i < MAX_UHID_JOYS; i++) + { + snprintf(path, sizeof(path), "/dev/uhid%d", i); + FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC); + if (fd < 0) continue; + + report_desc_t repDesc = hid_get_report_desc(fd); + if (!repDesc) continue; + + int reportId = hid_get_report_id(fd); + + struct hid_data* hData = hid_start_parse(repDesc, 0, reportId); + if (hData) + { + struct hid_item hItem; + while (hid_get_item(hData, &hItem) > 0) + { + if (HID_PAGE(hItem.usage) != 1 || HID_USAGE(hItem.usage) != 2) continue; + + struct usb_device_info di; + if (ioctl(fd, USB_GET_DEVICEINFO, &di) != -1) + { + FFMouseDevice* device = (FFMouseDevice*) ffListAdd(devices); + ffStrbufInitS(&device->serial, di.udi_serial); + ffStrbufInitS(&device->name, di.udi_product); + } + } + } + + hid_dispose_report_desc(repDesc); + } + + return NULL; +}