ohmu
·
2026-10-15
1#include "bluetooth.h"
2#include "common/debug.h"
3
4#define L2CAP_SOCKET_CHECKED
5#include <bluetooth.h>
6
7static int enumDev([[maybe_unused]] int sockfd, struct bt_devinfo const* dev, FFlist* devices) {
8 FFBluetoothResult* device = FF_LIST_ADD(FFBluetoothResult, *devices);
9 ffStrbufInitS(&device->name,
10#if __FreeBSD__
11 bt_devremote_name_gen(dev->devname, &dev->bdaddr)
12#else
13 dev->devname
14#endif
15 );
16 ffStrbufInitS(&device->address, bt_ntoa(&dev->bdaddr, nullptr));
17 ffStrbufUpperCase(&device->address);
18 ffStrbufInit(&device->type);
19 device->deviceType = FF_BLUETOOTH_DEVICE_TYPE_CLASSIC_BIT; // Netgraph only carries the BR/EDR stack
20 device->battery = 0;
21 device->signalQuality = -DBL_MAX;
22 device->connected = true;
23 return 0;
24}
25
26const char* ffDetectBluetooth(FFBluetoothOptions* options, FFlist* devices /* FFBluetoothResult */) {
27 // Netgraph carries the BR/EDR stack and nothing else, so there is no second function to dispatch
28 // to here: a Low Energy-only configuration simply has nothing to walk.
29 if (!(options->showType & FF_BLUETOOTH_DEVICE_TYPE_CLASSIC_BIT)) {
30 return nullptr;
31 }
32
33 // struct hostent* ent = bt_gethostent();
34 if (bt_devenum((void*) enumDev, devices) < 0) {
35 FF_DEBUG("bt_devenum() failed");
36 return "bt_devenum() failed";
37 }
38
39 return nullptr;
40}