Skip to content

A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol

fix bluetooth crash for M5stick

Geofb878ffaecbb
diff --git a/src/Controllers/BluetoothController.cpp b/src/Controllers/BluetoothController.cpp
index 2d68a1ea..c2a20a00 100644
--- a/src/Controllers/BluetoothController.cpp
+++ b/src/Controllers/BluetoothController.cpp
@@ -19,27 +19,16 @@ Entry point for BT command
void BluetoothController::handleCommand(const TerminalCommand& cmd) {
const auto& root = cmd.getRoot();
- if (root == "scan") {
- handleScan();
- } else if (root == "pair") {
- handlePair(cmd);
- } else if (root == "spoof") {
- handleSpoof(cmd);
- } else if (root == "sniff") {
- handleSniff(cmd);
- } else if (root == "status") {
- handleStatus();
- } else if (root == "server") {
- handleServer(cmd);
- } else if (root == "keyboard") {
- handleKeyboard(cmd);
- } else if (root == "mouse") {
- handleMouse(cmd);
- } else if (root == "reset") {
- handleReset();
- } else {
- handleHelp();
- }
+ if (root == "scan") handleScan();
+ else if (root == "pair") handlePair(cmd);
+ else if (root == "spoof") handleSpoof(cmd);
+ else if (root == "sniff") handleSniff(cmd);
+ else if (root == "status") handleStatus();
+ else if (root == "server") handleServer(cmd);
+ else if (root == "keyboard") handleKeyboard(cmd);
+ else if (root == "mouse") handleMouse(cmd);
+ else if (root == "reset") handleReset();
+ else handleHelp();
}
/*
@@ -145,6 +134,11 @@ void BluetoothController::handleSniff(const TerminalCommand& cmd) {
Server
*/
void BluetoothController::handleServer(const TerminalCommand& cmd) {
+ #ifdef DEVICE_M5STICK
+ terminalView.println("Bluetooth Server: HID Not supported on M5Stick.");
+ return;
+ #endif
+
if (bluetoothService.getMode() == BluetoothMode::SERVER && bluetoothService.isConnected()) {
terminalView.println("Bluetooth Server: Already Started");
return;
@@ -156,7 +150,7 @@ void BluetoothController::handleServer(const TerminalCommand& cmd) {
}
terminalView.println("Bluetooth Server: Starting BLE HID server as \"" + name + "\"...");
- bluetoothService.begin(name);
+ bluetoothService.startServer(name);
terminalView.println("→ You can now pair from your phone or computer.");
}
@@ -252,7 +246,7 @@ void BluetoothController::handleSpoof(const TerminalCommand& cmd) {
Reset
*/
void BluetoothController::handleReset() {
- bluetoothService.end();
+ bluetoothService.stopServer();
terminalView.println("Bluetooth: Reset complete.");
}
@@ -260,7 +254,9 @@ void BluetoothController::handleReset() {
Config
*/
void BluetoothController::handleConfig() {
- // bluetoothService.init();
+ #ifdef DEVICE_M5STICK
+ bluetoothService.releaseBtClassic();
+ #endif
}
/*
diff --git a/src/Services/BluetoothService.cpp b/src/Services/BluetoothService.cpp
index 2d78c41a..3eb64fc3 100644
--- a/src/Services/BluetoothService.cpp
+++ b/src/Services/BluetoothService.cpp
@@ -24,8 +24,9 @@ public:
}
};
-void BluetoothService::begin(const std::string& deviceName) {
- end();
+void BluetoothService::startServer(const std::string& deviceName) {
+ stopServer();
+
delay(200);
BLEDevice::init(deviceName);
BLEServer* server = BLEDevice::createServer();
@@ -53,7 +54,7 @@ void BluetoothService::begin(const std::string& deviceName) {
connected = true;
}
-void BluetoothService::end() {
+void BluetoothService::stopServer() {
if (hid) {
delete hid;
hid = nullptr;
@@ -72,6 +73,10 @@ void BluetoothService::end() {
mode = BluetoothMode::NONE;
}
+void BluetoothService::releaseBtClassic() {
+ esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT);
+}
+
void BluetoothService::onConnect() {
connected = true;
}
@@ -172,12 +177,12 @@ void BluetoothService::switchToMode(BluetoothMode newMode) {
if (mode == newMode) return;
if (mode == BluetoothMode::SERVER || mode == BluetoothMode::CLIENT) {
- end();
+ stopServer();
}
- // Init pour le nouveau mode
+ // Init new mode
if (newMode == BluetoothMode::CLIENT || newMode == BluetoothMode::SERVER) {
- BLEDevice::init(""); // Peut être changé si tu veux des logs personnalisés
+ BLEDevice::init("");
}
mode = newMode;
diff --git a/src/Services/BluetoothService.h b/src/Services/BluetoothService.h
index be2f6127..b2be526e 100644
--- a/src/Services/BluetoothService.h
+++ b/src/Services/BluetoothService.h
@@ -7,8 +7,6 @@
#include "BLEHIDDevice.h"
#include "HIDTypes.h"
#include "Data/AsciiHid.h"
-// #include <esp_system.h> // pour esp_read_mac
-// #include <esp_mac.h> // pour ESP_MAC_BT
enum class BluetoothMode {
NONE,
@@ -42,8 +40,9 @@ public:
};
// begin / end server BT
- void begin(const std::string& deviceName = "Bus-Pirate-Blueooth");
- void end();
+ void startServer(const std::string& deviceName = "Bus-Pirate-Blueooth");
+ void stopServer();
+ void releaseBtClassic();
// Init client
void init(const std::string& deviceName = "Bus-Pirate-Bluetooth");