diff --git a/programs/src/btbonds/main.cpp b/programs/src/btbonds/main.cpp new file mode 100644 index 0000000..8e05550 --- /dev/null +++ b/programs/src/btbonds/main.cpp @@ -0,0 +1,36 @@ +/* + * main.cpp + * uses the bt_bonds syscall to output a list of paired (bonded) Bluetooth devices. + * Copyright (c) 2026 Daniel Hammer +*/ +#include +#include + +const char* addr_to_string(char* str, uint8_t* bdAddr) { + snprintf(str, 18, "%02x:%02x:%02x:%02x:%02x:%02x", + bdAddr[0], bdAddr[1], bdAddr[2], bdAddr[3], bdAddr[4], bdAddr[5] + ); + + return (const char*)str; +} + +extern "C" void _start() { + montauk::abi::BtBondInfo devices[64] = { }; + int n = montauk::bt_bonds(devices, 64); + + if (n <= 0) { + montauk::print("No paired Bluetooth devices.\n"); + montauk::exit(0); + } + + montauk::print(" MAC addr.\n"); + + for (int i = 0; i < n; i++) { + char macAddrString[18] = {}; + addr_to_string(macAddrString, devices[i].bdAddr); + + printf(" %-17s\n", macAddrString); + } + + montauk::exit(0); +}