Fix: add BLE state cleanup to ducky_typer functions - #2669
Conversation
Added cleanup function for BLE state management in ducky_typer.
Added cleanup function for ducky_typer BLE operations.
Removed unnecessary cleanup of BLE state on exit in multiple functions.
Removed unnecessary comments and cleaned up the code for better readability. Adjusted some logic for handling BLE connections and key inputs.
Refactor ibeacon function to avoid reinitializing BLE stack and improve advertising logic.
Refactor ibeacon function to use BLEDevice::init() and adjust advertising logic.
Refactor cleanupDuckyBLE to delete hid_ble and log the action.
|
This needs fixing but im running into a struggle here...if i fix this this way its better but still a bit sloppy...and it messes up with ibeacon somehow that as soon as we start it kicks us back to main menu...just like it used to do a while ago. So for now ill close this and try to think on a new solution eventually . |
|
We have all year bro , lick some sun have some good food and just chill the
solutions will arise themselves when the sun is shining in the correct ways
... Ancient Visdome needs ancient days to progress as time is not
something real... Ahh man i missed my linux so bad i havent used it for 2
years becous ei had to beat the TAO with theyr windows ........ just joking
but anyhow have a great day looking forward to see more of ur projects this
year next year all years.. Vato Loco esse.. :p We go in together we go out
together... Peace A
nd to everyone dont stop do ur thang.. We will have a colloboration one day
where we gather all the HS etc and make a databsae and aso the programmers
here with Mr NinjaJr and all of them we will progress to the furtest
exxtend possible and since the programmers are in reality the creators (as
shown in matrix THE ARCHITECTS. thats them=) så we have no limitws no
rules no boundaries just happy thougts and children who plays and laugh in
the sun while having safe secure thougts.... Thats the real goal of the
soul... Ok i got my coffe now i can chill again lol anyhow have a great day
everyone !! =) DO UR THANG !!!! And remember to allways use Firewall_streeeT
…On Mon, Jul 20, 2026 at 1:16 AM Ninja-jr ***@***.***> wrote:
*Ninja-jr* left a comment (BruceDevices/firmware#2669)
<#2669 (comment)>
This needs fixing but im running into a struggle here...if i fix this this
way its better but still a bit sloppy...and it messes up with ibeacon
somehow that as soon as we start it kicks us back to main menu...just like
it used to do a while ago.
So for now ill close this and try to think on a new solution eventually .
—
Reply to this email directly, view it on GitHub
<#2669?email_source=notifications&email_token=BLDL6BR75EQIYNVVY2XZGOL5FVJGPA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMBRG43TIOBYGEYKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#issuecomment-5017748810>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BLDL6BX5VT2OAWYIZLTKJ3L5FVJGPAVCNFSNUABFKJSXA33TNF2G64TZHM3TSNJRGY3DSNRRHNEXG43VMU5TIOJSGM2DGNRRGM32C5QC>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/BLDL6BQFLGPAEWCZQQBZMVL5FVJGPA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMBRG43TIOBYGEYKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSVGM33PORSXEX3JN5ZQ>
and Android
<https://github.com/notifications/mobile/android/BLDL6BSQYEDTHIPJ5WRRC5T5FVJGPA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMBRG43TIOBYGEYKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ>.
Download it today!
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
--
Kind Regards
C.R
May Prosperity allways be with us!!
|
|
Thanks alot. Well i just cant see an issue when I use the firmware and not try to sort it...but its true when we start running in circles is better to take a step back, get some rest enjoy life and eventually we or someone will find the solutions. Im sure its not that big of a deal but I couldn't fetch it yet. |
Refactor Ducky Typer code to optimize memory usage by storing large command structures in PROGMEM. Update command parsing and handling to improve performance and reduce heap fragmentation.
Updated cleanupDuckyBLE and ducky_startKb functions for better RAM management and clearer logging. Refactored key_input function to improve string handling and command parsing.
Refactored BLE iBeacon functionality to ensure proper button handling and stack initialization/deinitialization. Added necessary includes and improved readability.
Refactor BLE initialization and scanning logic for improved memory management and error handling.
Made various fixes throughout the code to ensure proper initialization and handling of BLE state and attacks.
|
@bmorcelli i think we can merge this if you think the code is ok. It sorts out the errors on a subsequent connection on another module that error out even with the latest beta. Also made some memory optimization to avoid getting low ram warnings on some devices that then forced the user to turn off wifi in order to subsequently use other ble functions. It now does the checks and if low memory for ble then frees up DMA memory by disconnecting from wifi and rechecks. If still low only then it shows the low ram warning. This is as much as i can do for now to get it all working as its supposed to. You can check it and eventually merge if you think the fixes are good. |
|
I used a Cardputer ADV to test Probably need to work on the BLEKeyboard destructor (which does not exist) or uses ble_hid->end(); before deleting it here maybe it is keeping an old notifier or something that is not being rebuilt/reconfigured between reconections |
Updated cleanupDuckyBLE to optionally perform a full cleanup. Enhanced BLE stack management during cleanup and initialization processes.
Noted and i'm trying to handle that then. To me it seemed ok the first time but when i read your message and i tested on a cardputer adv aswell (yes it came through after all so now i can actually test) it behaved as you described to im trying to tackle that now |
Refactor cleanupDuckyBLE function for clarity and efficiency.
|
I'm trying a new approach, some things in the line of some issues had tried but some new ones to see if i can get it to work. Thing is as is on the beta it just can't stay that way and that's why im trying to get this fixed so we get mostly done with the ble functions for a while |
Updated comments for clarity and consistency regarding function IDs and BLE initialization. Improved safety checks during BLE cleanup and initialization.
Refactor BLE cleanup and HID instance management.
Added extern declaration for active BLE instance.
Added support for a BLE HID instance and updated cleanup logic.
Refactor cleanup functions for BLE HID instances to ensure proper deinitialization and safety. Implement double cleanup with delays to handle lingering instances and prevent memory leaks.
Added a new function for safe cleanup of DuckyBLE instances with a cooling delay.
Removed unused Bluetooth headers from ducky_typer.cpp
|
Really couldn't get this to work as intended...reduced the errors to virtually zero but still can't find a way to get this to work after we leave the first function and try to use a different one...tried many options and ways but till now couldn't seem to find the right way to do this |
|
Fixed, tested and working.. merging now 😉 |
|
Yup that sorted it all out. You sorted what got me stuck all this time @bmorcelli great job. Good thing in the middle of this is with all my attempts we actually achieved services separation...each one has its own service which makes each less dependent on others...if one gets broken it shall not affect others and hardcoding the device name instead of trying to fetch it from the config file is a good call i think so all in all i dont regret spending 2 blank nights on this 😜 |
This PR adds a shared cleanup function (cleanupDuckyBLE()) to properly reset BLE state when exiting BLE Keyboard, Media Commands, and iBeacon functions in ducky_typer.cpp.
It sorts out the remaining issues i detected on the ble modules.
Problem
When using BLE Keyboard, Media Commands, or iBeacon, the BLE stack was left in a dirty state after exiting. This caused subsequent BLE features to fail with "Resource busy" or "Already connected" errors.
Solution
· Added cleanupDuckyBLE() function inside ducky_typer.cpp
· Function stops advertising, cleans clients, resets flags
· Does NOT deinitialize BLE stack (shared resource)
· Called on exit from:
· ducky_keyboard() (BLE Keyboard)
· MediaCommands() (Media Commands)
· iBeacon (via inline cleanup)
Why This Approach
· Keeps fix isolated to the problem modules
· Does not touch working ble_common code
· Preserves scan results for menu display
· Minimal flash impact