Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
b5d8c12
Implement cleanupDuckyBLE for BLE state management
Ninja-jr Jul 19, 2026
2ae411c
Add cleanupDuckyBLE function for BLE cleanup
Ninja-jr Jul 19, 2026
569d8b3
Update ducky_typer.h
Ninja-jr Jul 19, 2026
83a5837
Refactor BLE cleanup logic in ducky_typer.cpp
Ninja-jr Jul 19, 2026
046a779
Add BLE common header inclusion in ducky_typer.cpp
Ninja-jr Jul 19, 2026
69eb7be
Refactor ducky_typer.cpp for clarity and efficiency
Ninja-jr Jul 19, 2026
6c0bb90
Fix preprocessor directive closing in ducky_typer.cpp
Ninja-jr Jul 19, 2026
e02203a
Update ducky_typer.h
Ninja-jr Jul 19, 2026
4f79f2e
Refactor ibeacon function for better BLE handling
Ninja-jr Jul 19, 2026
54e2128
Refactor ibeacon function to use NimBLEAdvertising
Ninja-jr Jul 19, 2026
e1ca2d8
Refactor iBeacon function to use existing BLE stack
Ninja-jr Jul 19, 2026
c7411bd
Update ibeacon function for BLE initialization and advertising
Ninja-jr Jul 19, 2026
94bb3a5
Fix function definition for spamMenu
Ninja-jr Jul 19, 2026
9ae0997
Improve cleanupDuckyBLE function
Ninja-jr Jul 19, 2026
237da6f
Optimize memory usage in ducky_typer.cpp
Ninja-jr Jul 21, 2026
31aad83
Refactor BLE cleanup and command handling functions
Ninja-jr Jul 21, 2026
f0d73ab
Refactor BLE cleanup and initialization process
Ninja-jr Jul 21, 2026
a25b5ef
Refactor BLE stack management in ducky_typer.cpp
Ninja-jr Jul 21, 2026
43d3b7d
Refactor BLE iBeacon handling and initialization
Ninja-jr Jul 21, 2026
a84654b
Refactor BLE initialization and scanning logic
Ninja-jr Jul 21, 2026
8badb08
Update BLE_Suite.cpp with fixes
Ninja-jr Jul 21, 2026
e3af8d2
Refactor BLE cleanup and initialization code
Ninja-jr Jul 21, 2026
6be86b5
Improve BLE memory check and WiFi handling
Ninja-jr Jul 21, 2026
239ae9d
Refactor BLE cleanup and initialization logic
Ninja-jr Jul 21, 2026
0707eaa
Improve cleanupDuckyBLE function implementation
Ninja-jr Jul 21, 2026
447b3a1
Refactor BLE cleanup and initialization functions
Ninja-jr Jul 21, 2026
6215573
Add functionId parameter to ducky_startKb function
Ninja-jr Jul 21, 2026
83c8e97
Refactor BLE function IDs to use integers directly
Ninja-jr Jul 21, 2026
c261b25
Refactor BLE handling and update comments
Ninja-jr Jul 21, 2026
678b76e
Update BLE cleanup function to handle multiple HID types
Ninja-jr Jul 21, 2026
94c047f
Update ducky_typer.h
Ninja-jr Jul 21, 2026
3e75a17
Update ducky_typer.h
Ninja-jr Jul 21, 2026
17b2438
Declare hid_ble for active BLE instance
Ninja-jr Jul 21, 2026
2680c2a
Introduce BLE HID instance management
Ninja-jr Jul 21, 2026
20a491d
Refactor BLE cleanup process for safety and efficiency
Ninja-jr Jul 21, 2026
c86c965
Add safeCleanupDuckyBLE function for DuckyBLE
Ninja-jr Jul 21, 2026
c825535
Fix header guard in ducky_typer.h
Ninja-jr Jul 21, 2026
8eb678b
Add function-specific MAC addresses for Logitech devices
Ninja-jr Jul 21, 2026
4990de6
Refactor MAC address setting for BLE
Ninja-jr Jul 21, 2026
e4d1cc8
Remove unused Bluetooth includes
Ninja-jr Jul 21, 2026
5076d89
fix reconnection
bmorcelli Jul 22, 2026
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
23 changes: 11 additions & 12 deletions lib/Bad_Usb_Lib/BleKeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,9 @@ void BleKeyboard::end(void) {
for (j = 0; j < i; j++) pServer->disconnect(pServer->getPeerInfo(i).getConnHandle());
}
delete hid;
#if defined(CONFIG_IDF_TARGET_ESP32C5)
esp_bt_controller_deinit();
#else
BLEDevice::deinit();
#endif
hid = nullptr;

BLEDevice::deinit(true);
this->connected = false;
}

Expand Down Expand Up @@ -242,12 +240,13 @@ void BleKeyboard::set_version(uint16_t version) { this->version = version; }
// full, made worse by reducing CONFIG_BT_NIMBLE_MSYS_*_BLOCK_COUNT). If untreated,
// the key is silently dropped. Retry while yielding 1 tick for the host to drain.
// Kept local because this library is self-contained (does not depend on src/).
static bool bleKbNotifyRetry(BLECharacteristic *chr, uint8_t retries = 8) {

static bool bleKbNotifyRetry(BLECharacteristic *chr, const uint8_t *value, size_t len, uint8_t retries = 8) {
if (chr == nullptr) return false;
if (chr->notify()) return true;
if (chr->notify(value, len)) return true;
for (uint8_t i = 0; i < retries; i++) {
vTaskDelay(1);
if (chr->notify()) return true;
if (chr->notify(value, len)) return true;
}
return false;
}
Expand All @@ -260,7 +259,7 @@ void BleKeyboard::sendReport(KeyReport *keys) {
#endif
{
this->inputKeyboard->setValue((uint8_t *)keys, sizeof(KeyReport));
bleKbNotifyRetry(this->inputKeyboard);
bleKbNotifyRetry(this->inputKeyboard, (uint8_t *)keys, sizeof(KeyReport));
#if defined(USE_NIMBLE)
// vTaskDelay(delayTicks);
this->delay_ms(_delay_ms);
Expand All @@ -276,7 +275,7 @@ void BleKeyboard::sendReport(MediaKeyReport *keys) {
#endif
{
this->inputMediaKeys->setValue((uint8_t *)keys, sizeof(MediaKeyReport));
bleKbNotifyRetry(this->inputMediaKeys);
bleKbNotifyRetry(this->inputMediaKeys, (uint8_t *)keys, sizeof(MediaKeyReport));
#if defined(USE_NIMBLE)
// vTaskDelay(delayTicks);
this->delay_ms(_delay_ms);
Expand Down Expand Up @@ -434,11 +433,11 @@ size_t BleKeyboard::write(const uint8_t *buffer, size_t size) {
}
#ifdef NIMBLE_V2_PLUS
void BleKeyboard::ServerCallbacks::onConnect(NimBLEServer *pServer, NimBLEConnInfo &connInfo) {
// BleKeyboard::connected = true;
parent->connected = true;
Serial.println("BRUCE KEYBOARD: lib connected");
}
void BleKeyboard::ServerCallbacks::onDisconnect(NimBLEServer *pServer, NimBLEConnInfo &connInfo, int reason) {
// BleKeyboard::connected = true;
parent->connected = false;
Serial.println("BRUCE KEYBOARD: lib disconnected");
}
void BleKeyboard::ServerCallbacks::onAuthenticationComplete(NimBLEConnInfo &connInfo) {
Expand Down
7 changes: 1 addition & 6 deletions src/core/menu_items/BleMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@ void BleMenu::optionsMenu() {
#if !defined(LITE_VERSION)
if (BLEConnected) {
options.push_back({"Disconnect", [=]() {
#if defined(CONFIG_IDF_TARGET_ESP32C5)
esp_bt_controller_deinit();
#else
BLEDevice::deinit();
#endif
BLEDevice::deinit();
BLEConnected = false;
delete hid_ble;
hid_ble = nullptr;
if (_Ask_for_restart == 1) _Ask_for_restart = 2;
}});
}
#endif
Expand Down
32 changes: 31 additions & 1 deletion src/core/radio_mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
#include <esp_heap_caps.h>
#include <stddef.h>
#include "core/wifi/wifi_common.h"
#include <WiFi.h>

// Largest contiguous DMA-capable internal block, in bytes. This is the number
// that gates Wi-Fi/BLE controller init.
Expand All @@ -36,7 +38,35 @@ static inline bool radioHasMemForWifi() {

static inline bool radioHasMemForBle() {
// return true; // uncomment to disable it
return radioLargestDmaBlock() >= RADIO_BLE_MIN_DMA_BLOCK;

// First check if we have enough DMA memory
if (radioLargestDmaBlock() >= RADIO_BLE_MIN_DMA_BLOCK) {
return true;
}

// Not enough DMA memory - try to free WiFi
Serial.println("[RAM] Low contiguous DMA memory for BLE, attempting to free WiFi...");

// Disconnect WiFi if active
if (WiFi.getMode() != WIFI_MODE_NULL || wifiConnected) {
wifiDisconnect();
delay(200);
#ifdef WIFI_DEINIT_ON_DISCONNECT
WiFi.mode(WIFI_OFF);
#endif
delay(300);
}

// Recheck after freeing WiFi
if (radioLargestDmaBlock() >= RADIO_BLE_MIN_DMA_BLOCK) {
Serial.printf("[RAM] WiFi freed, DMA block: %d bytes\n", radioLargestDmaBlock());
return true;
}

// Still not enough - return false, caller shows error
Serial.printf("[RAM] Still only %d bytes DMA block, minimum %d needed\n",
radioLargestDmaBlock(), RADIO_BLE_MIN_DMA_BLOCK);
return false;
}

#endif // __RADIO_MEM_H__
Loading
Loading