From d6028370e7659d647633b2832b68984a211d8db0 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Thu, 26 Dec 2024 15:34:17 +0800 Subject: [PATCH] Bluetooth (FreeBSD): add support (not tested) --- CMakeLists.txt | 3 ++- src/detection/bluetooth/bluetooth_bsd.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/detection/bluetooth/bluetooth_bsd.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 71c0e886e..6c510adaf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -617,7 +617,7 @@ elseif(FreeBSD) src/common/sysctl.c src/detection/battery/battery_bsd.c src/detection/bios/bios_bsd.c - src/detection/bluetooth/bluetooth_nosupport.c + src/detection/bluetooth/bluetooth_bsd.c src/detection/bluetoothradio/bluetoothradio_nosupport.c src/detection/board/board_bsd.c src/detection/bootmgr/bootmgr_bsd.c @@ -1468,6 +1468,7 @@ elseif(FreeBSD) target_link_libraries(libfastfetch PRIVATE "m" PRIVATE "usbhid" + PRIVATE "bluetooth" ) if(NOT DragonFly) target_link_libraries(libfastfetch diff --git a/src/detection/bluetooth/bluetooth_bsd.c b/src/detection/bluetooth/bluetooth_bsd.c new file mode 100644 index 000000000..117675dad --- /dev/null +++ b/src/detection/bluetooth/bluetooth_bsd.c @@ -0,0 +1,25 @@ +#include "bluetooth.h" + +#define L2CAP_SOCKET_CHECKED +#include + +static int enumDev(FF_MAYBE_UNUSED int sockfd, struct bt_devinfo const* dev, FFlist* devices) +{ + FFBluetoothResult* device = ffListAdd(devices); + ffStrbufInitS(&device->name, bt_devremote_name_gen(dev->devname, &dev->bdaddr)); + ffStrbufInitS(&device->address, bt_ntoa(&dev->bdaddr, NULL)); + ffStrbufUpperCase(&device->address); + ffStrbufInit(&device->type); + device->battery = 0; + device->connected = true; + return 0; +} + +const char* ffDetectBluetooth(FF_MAYBE_UNUSED FFBluetoothOptions* options, FF_MAYBE_UNUSED FFlist* devices /* FFBluetoothResult */) +{ + // struct hostent* ent = bt_gethostent(); + if (bt_devenum((void*) enumDev, devices) < 0) + return "bt_devenum() failed"; + + return 0; +}