MCPcopy Create free account
hub / github.com/MeisApps/pcbu-desktop / ScanDevices

Method ScanDevices

common/src/platform/BluetoothHelper.Linux.cpp:24–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22void BluetoothHelper::StopScan() {}
23
24std::vector<BluetoothDevice> BluetoothHelper::ScanDevices() {
25 int dev_id = hci_get_route(nullptr);
26 int sock = hci_open_dev(dev_id);
27 if(dev_id < 0 || sock < 0)
28 return {};
29
30 int len = 8;
31 int max_rsp = 255;
32 auto ii = (inquiry_info *)malloc(max_rsp * sizeof(inquiry_info));
33 int num_rsp = hci_inquiry(dev_id, len, max_rsp, nullptr, &ii, IREQ_CACHE_FLUSH);
34 if(num_rsp <= 0) {
35 spdlog::error("hci_inquiry() failed.");
36 free(ii);
37 close(sock);
38 return {};
39 }
40
41 std::vector<BluetoothDevice> result{};
42 for(int i = 0; i < num_rsp; i++) {
43 char addr[18]{};
44 char name[248]{};
45 ba2str(&(ii + i)->bdaddr, addr);
46 memset(name, 0, sizeof(name));
47 if(hci_read_remote_name(sock, &(ii + i)->bdaddr, sizeof(name), name, 0) < 0)
48 strcpy(name, "Unknown device");
49 result.push_back({name, addr});
50 }
51 free(ii);
52 close(sock);
53 return result;
54}
55
56bool BluetoothHelper::PairDevice(const BluetoothDevice &device) {
57 return true;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected