Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/core/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ void BruceConfig::fromFile(bool checkFS) {
// Deserialize the JSON document
JsonDocument jsonDoc;
if (deserializeJson(jsonDoc, file)) {
Serial.println("Failed to read config file, using default configuration");
Serial.printf(
"Failed to read config file %s on %s (invalid JSON or read error), using default configuration\n",
filepath,
fs == &LittleFS ? "LittleFS" : "SD"
);
file.close();
return;
}
file.close();
Expand Down
2 changes: 2 additions & 0 deletions src/core/menu_items/BleMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "core/utils.h"
#include "modules/badusb_ble/ducky_typer.h"
#include "modules/ble/ble_common.h"
#include "modules/ble/ble_glasses.h"
#include "modules/ble/ble_ninebot.h"
#include "modules/ble/ble_spam.h"
#if !defined(LITE_VERSION)
Expand All @@ -27,6 +28,7 @@ void BleMenu::optionsMenu() {
#if !defined(LITE_VERSION)
options.push_back({"Media Cmds", [=]() { MediaCommands(hid_ble, true); }});
options.push_back({"BLE Scan", ble_scan});
options.push_back({"Glasses Detect", ble_glasses_detector});
options.push_back({"iBeacon", [=]() {
ibeacon("Bruce", "e4c159a0-8c82-11e6-bdf4-0800200c9a66", 0x004C);
}});
Expand Down
26 changes: 14 additions & 12 deletions src/core/menu_items/ConfigMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ void ConfigMenu::optionsMenu() {
void ConfigMenu::displayUIMenu() {
while (true) {
std::vector<Option> localOptions = {
{"Brightness", [this]() { setBrightnessMenu(); } },
{"Dim Time", [this]() { setDimmerTimeMenu(); } },
{"Orientation", [this]() { lambdaHelper(gsetRotation, true)(); }},
{"Menu Layout", [this]() { setMainMenuStyleMenu(); } },
{"UI Color", [this]() { setUIColor(); } },
{"UI Theme", [this]() { setTheme(); } },
{"Brightness", [this]() { setBrightnessMenu(); } },
{"Dim Time", [this]() { setDimmerTimeMenu(); } },
{"Orientation", [this]() { lambdaHelper(gsetRotation, true)(); }},
{"Menu Layout", [this]() { setMainMenuStyleMenu(); } },
{"UI Color", [this]() { setUIColor(); } },
{"UI Theme", [this]() { setTheme(); } },
#if defined(HAS_RESISTIVE_TOUCH)
{"Calibrate Touch", []() { calibrateTouch(); } },
{"Calibrate Touch", []() { calibrateTouch(); } },
#endif
{"Back", []() {} },
{"Back", []() {} },
};

int selected = loopOptions(localOptions, MENU_TYPE_SUBMENU, "Display & UI");
Expand Down Expand Up @@ -132,11 +132,11 @@ void ConfigMenu::audioMenu() {
std::vector<Option> localOptions = {
#if !defined(LITE_VERSION)
{String("Sound: ") + (bruceConfig.soundEnabled ? "ON" : "OFF"),
[this]() {
[this]() {
// Toggle sound setting
bruceConfig.soundEnabled = !bruceConfig.soundEnabled;
bruceConfig.saveFile();
} },
} },
#if defined(HAS_SPEAKER)
{"Sound Volume", [this]() { setSoundVolume(); }},
#endif // HAS_SPEAKER
Expand Down Expand Up @@ -174,7 +174,9 @@ void ConfigMenu::systemMenu() {
{"Startup App", [this]() { setStartupApp(); } },
{"Hide/Show Apps", [this]() { mainMenu.hideAppsMenu(); }},
{"Clock", [this]() { setClock(); } },
{String("Keyboard Language: ") + bruceConfig.keyboardLang, [this]() { setKeyboardLanguage(); } },
{String("Keyboard Layout:") + bruceConfig.keyboardLang, [this]() { setKeyboardLanguage(); } },
// {String("Keyboard Language:") + bruceConfig.keyboardLang, [this]() {
// setKeyboardLanguage(); } },
{"Advanced", [this]() { advancedMenu(); } },
{"Back", []() {} },
};
Expand Down Expand Up @@ -313,7 +315,7 @@ void ConfigMenu::pinsMenu() {
#if defined(HAS_SPEAKER)
{"Speaker Pins", []() { setSpeakerPinsMenu(bruceConfigPins.speaker_bus); }},
#else
{"Buzzer Pin", []() { setBuzzerPinMenu(); } },
{"Buzzer Pin", []() { setBuzzerPinMenu(); }},
#endif
#if defined(HAS_MICROPHONE)
{"Mic Pins", []() { setMicPinsMenu(bruceConfigPins.mic_bus); } },
Expand Down
6 changes: 6 additions & 0 deletions src/core/menu_items/RFMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
#include "core/settings.h"
#include "core/utils.h"
#include "modules/rf/record.h"
#include "modules/rf/rf_analyze.h"
#include "modules/rf/rf_bruteforce.h"
#include "modules/rf/rf_jammer.h"
#include "modules/rf/rf_listen.h"
#include "modules/rf/rf_remote_analyzer.h"
#include "modules/rf/rf_rolling.h"
#include "modules/rf/rf_scan.h"
#include "modules/rf/rf_send.h"
#include "modules/rf/rf_spectrum.h"
Expand All @@ -26,10 +29,13 @@ void RFMenu::optionsMenu() {
{"RSSI Spectrum", rf_CC1101_rssi }, // @Pirata
{"SquareWave Spec", rf_SquareWave }, // @Pirata
{"Spectogram", rf_waterfall }, // dev_eclipse
{"Remote Analyzer", rf_remote_analyzer }, // ProtoPirate remote analyzer (peak find + AM/FM)
{"Analyze", rf_analyze }, // auto classify modulation + decode
#if defined(RF_LISTEN_H)
{"Listen", rf_listen }, // dev_eclipse
#endif
{"Bruteforce", rf_bruteforce }, // dev_eclipse
{"Rolling Code", rf_rolling_code }, // rolling-code analyzer
{"Jammer", [=]() { RFJammer(true); } },
#endif
{"Config", [this]() { configMenu(); }},
Expand Down
236 changes: 236 additions & 0 deletions src/modules/ble/ble_glasses.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
#include "ble_glasses.h"

#include "ble_common.h"
#include "core/display.h"
#include "core/mykeyboard.h"
#include <NimBLEDevice.h>

namespace {

// Confidence levels for a match.
constexpr uint8_t CONF_HIGH = 3;
constexpr uint8_t CONF_MED = 2;
constexpr uint8_t CONF_LOW = 1;

struct GlassesMatch {
String name;
String address;
int rssi = 0;
String vendor;
uint8_t confidence = 0;
};

// Bluetooth SIG company (manufacturer) IDs used by smart-glasses makers.
struct CompanyEntry {
uint16_t id;
const char *label;
};
const CompanyEntry kCompanies[] = {
{0x01AB, "Meta Platforms"},
{0x058E, "Meta Technologies"},
{0x0D53, "Luxottica (Ray-Ban/Oakley)"},
{0x03C2, "Snap (Spectacles)"},
{0x05D6, "Jieli (Rogbird/ViewPro)"},
};

// Plaintext product names broadcast during pairing (lowercased substrings).
const char *kNameHints[] = {
"ray-ban", "rayban", "oakley", "spectacles", "heycyan", "visionpro",
"meta view", "meta", "stories", "echo frames", "vuzix", "rokid",
"xreal", "nreal", "smart glasses",
};

const char *companyLabel(uint16_t id) {
for (const auto &c : kCompanies)
if (c.id == id) return c.label;
return nullptr;
}

// Lowercase copy of a std::string (ASCII only).
String lower(const std::string &s) {
String out;
out.reserve(s.size());
for (unsigned char c : s)
if (c >= 'A' && c <= 'Z') out += (char)(c + 32);
else out += (char)c;
return out;
}

bool contains(const String &hay, const char *needle) { return hay.indexOf(needle) >= 0; }

// Truncate a string to fit `maxChars`, appending "..." when clipped.
String fit(const String &s, int maxChars) {
if (maxChars < 4) return s.substring(0, maxChars);
if ((int)s.length() <= maxChars) return s;
return s.substring(0, maxChars - 3) + "...";
}

// Try to match a single advertised device as smart glasses.
bool matchDevice(const NimBLEAdvertisedDevice *dev, GlassesMatch &out) {
if (!dev) return false;

const String name = lower(dev->getName());
uint16_t company = 0;
bool hasCompany = false;

if (dev->haveManufacturerData()) {
const std::string md = dev->getManufacturerData();
if (md.size() >= 2) {
company = (uint8_t)md[0] | ((uint8_t)md[1] << 8);
hasCompany = true;
// Meta camera glasses embed an ASCII tag right after the company id.
const String tag = lower(md.substr(2));
if (contains(tag, "meta_rb_glass")) {
out.vendor = "Meta Ray-Ban";
out.confidence = CONF_HIGH;
}
}
}

// Highest confidence: a registered smart-glasses company ID.
if (out.confidence < CONF_HIGH && hasCompany) {
const char *label = companyLabel(company);
if (label) {
out.vendor = label;
out.confidence = CONF_HIGH;
}
}

// Fixed service UUIDs (Google/Eddystone on Meta frames, HeyCyan SDK).
if (out.confidence < CONF_HIGH) {
if (dev->isAdvertisingService(NimBLEUUID("FEAA")) ||
dev->isAdvertisingService(NimBLEUUID("7905fff0-b5ce-4e99-a40f-4b1e122d00d0"))) {
out.vendor = "Smart glasses (UUID)";
out.confidence = CONF_MED;
}
}

// Plaintext name match (easy to spoof, so lower confidence).
if (out.confidence < CONF_MED) {
for (const char *hint : kNameHints) {
if (contains(name, hint)) {
out.vendor = String("Name: ") + hint;
out.confidence = CONF_LOW;
break;
}
}
}

if (out.confidence == 0) return false;

out.name = dev->getName().empty() ? String("<no name>") : String(dev->getName().c_str());
out.address = dev->getAddress().toString().c_str();
out.rssi = dev->getRSSI();
return true;
}

const char *confLabel(uint8_t c) {
if (c >= CONF_HIGH) return "HIGH";
if (c >= CONF_MED) return "MED";
return "LOW";
}

int textMaxChars() {
const int w = tftWidth - 2 * BORDER_PAD_X;
const int cw = LW * FP;
return (w / cw) - 1;
}

void drawResult(const std::vector<GlassesMatch> &matches, bool scanning) {
drawMainBorderWithTitle("Glasses Detector");
const int x = BORDER_PAD_X;
const int lh = LH * FP + 6;
int y = BORDER_PAD_Y + FM * LH + 6;
const int maxChars = textMaxChars();
tft.setTextSize(FP);

if (matches.empty()) {
tft.setTextColor(bruceConfig.priColor, bruceConfig.bgColor);
tft.drawString(scanning ? "Scanning..." : "Scanning... none found", x, y, 1);
} else {
tft.setTextColor(TFT_RED, bruceConfig.bgColor);
tft.drawString(fit(String("! ") + matches.size() + " possible glasses", maxChars), x, y, 1);
y += lh + 2;

const size_t max = matches.size() > 5 ? 5 : matches.size();
for (size_t i = 0; i < max; i++) {
const auto &m = matches[i];
if (y + lh > tftHeight - 14) break;
tft.setTextColor(bruceConfig.priColor, bruceConfig.bgColor);
tft.drawString(fit(m.name, maxChars), x, y, 1);
y += lh;
tft.setTextColor(blendColors(bruceConfig.bgColor, bruceConfig.priColor, 170), bruceConfig.bgColor);
tft.drawString(
fit(String(m.vendor) + " " + m.rssi + "dBm [" + confLabel(m.confidence) + "]", maxChars),
x, y, 1
);
y += lh + 2;
}
}

tft.setTextColor(blendColors(bruceConfig.bgColor, bruceConfig.priColor, 150), bruceConfig.bgColor);
tft.drawString(fit("[SEL] menu [ESC] back", maxChars), x, tftHeight - LH * FP - 8, 1);
}

} // namespace

void ble_glasses_detector() {
#if !defined(LITE_VERSION)
if (!ble_scan_setup() || pBLEScan == nullptr) {
displayError("Failed to init BLE scan");
return;
}

// No-PSRAM board: keep the retained device set small. Duplicate reports are
// irrelevant for detection and are the main source of RAM churn.
pBLEScan->setDuplicateFilter(true);

bool exit = false;
std::vector<GlassesMatch> matches;

while (!exit) {
// One full scan (same flow as ble_scan), then wait for input instead of
// tight-looping the radio — that's what exhausted the heap before.
matches.clear();
drawResult(matches, true); // "Scanning..."

pBLEScan->clearResults();
BLEScanResults found = pBLEScan->getResults(scanTime * 1000, false);

const int count = found.getCount();
for (int i = 0; i < count; i++) {
GlassesMatch m;
if (matchDevice(found.getDevice(i), m)) matches.push_back(m);
}

drawResult(matches, false);
if (!matches.empty() && bruceConfigPins.buzzer > 0)
tone((uint8_t)bruceConfigPins.buzzer, 2000, 80);

// Block on user input so we don't keep allocating scan results.
bool rescan = false;
while (!rescan && !exit) {
if (check(SelPress)) {
int action = 0;
options = {
{"Rescan", [&]() { action = 0; }},
{"Back to menu", [&]() { action = 1; }},
};
loopOptions(options, MENU_TYPE_SUBMENU, "Glasses Detector");
options.clear();
if (action == 1) exit = true;
else rescan = true;
}
if (check(EscPress)) exit = true;
vTaskDelay(pdMS_TO_TICKS(20));
}
}

if (pBLEScan) pBLEScan->stop();
stopBLEStack();
returnToMenu = true;
#else
displayError("Not available on Launcher version");
#endif
}
24 changes: 24 additions & 0 deletions src/modules/ble/ble_glasses.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
#ifndef __BLE_GLASSES_H__
#define __BLE_GLASSES_H__

// Scans for camera-equipped smart glasses (Meta Ray-Ban, Oakley Meta, Snap
// Spectacles, and similar) by matching their BLE advertisement fingerprints:
// Bluetooth SIG manufacturer (company) IDs, the "META_RB_GLASS" manufacturer
// data string, known product names, and fixed service UUIDs.
//
// Fingerprints sourced from public research (ZuckOff, yj_nearbyglasses):
// - 0x01AB Meta Platforms, Inc. (formerly Facebook)
// - 0x058E Meta Platforms Technologies, LLC
// - 0x0D53 Luxottica Group S.p.A (manufactures Meta Ray-Bans/Oakley)
// - 0x03C2 Snapchat, Inc. (Snap Spectacles)
// - 0x05D6 Zhuhai Jieli Technology Co (Rogbird VisionPro / Rollme VistaView)
// - 0xFEAA Google/Eddystone service UUID (seen on Meta frames)
// - 7905FFF0-B5CE-4E99-A40F-4B1E122D00D0 HeyCyan smart-glasses SDK UUID
//
// Detection is heuristic: a match means "camera-capable hardware of a known
// maker is in BLE range", NOT that recording is happening. False positives
// are possible (e.g. a VR headset from the same vendor).
void ble_glasses_detector();

#endif
Loading